177 lines
5.1 KiB
C#
177 lines
5.1 KiB
C#
using System;
|
|
using BrewMonster.Network;
|
|
using BrewMonster.UI;
|
|
using UnityEngine;
|
|
|
|
namespace BrewMonster
|
|
{
|
|
public class AUIToggleAssignSlot : AUIToggle
|
|
{
|
|
public const string DefaultComboIcon = "爱你";
|
|
public event Action<bool, int> OnSetSlot;
|
|
private int _skillGroupIndex = -1;
|
|
private readonly System.Collections.Generic.List<int> _skillGroupIndexes = new();
|
|
|
|
public override void Awake()
|
|
{
|
|
UnSubscribeEvents();
|
|
SubscribeEvents();
|
|
return;
|
|
}
|
|
public void OnDestroy()
|
|
{
|
|
UnSubscribeEvents();
|
|
}
|
|
private void UnSubscribeEvents()
|
|
{
|
|
uiToggle.onValueChanged.RemoveAllListeners();
|
|
}
|
|
private void SubscribeEvents()
|
|
{
|
|
uiToggle.onValueChanged.AddListener(OnToggleValueChanged);
|
|
}
|
|
private void OnToggleValueChanged(bool isOn)
|
|
{
|
|
OnSetSlot?.Invoke(isOn, slotIndex);
|
|
}
|
|
|
|
public int GetSlotIndexForAssign() => slotIndex;
|
|
public int GetSkillGroupIndexForAssign() => _skillGroupIndex;
|
|
public System.Collections.Generic.IReadOnlyList<int> GetSkillGroupIndexesForAssign() => _skillGroupIndexes;
|
|
|
|
public void SetSkillGroupIndexForAssign(int groupIndex)
|
|
{
|
|
_skillGroupIndex = groupIndex;
|
|
_skillGroupIndexes.Clear();
|
|
if (groupIndex >= 0)
|
|
{
|
|
_skillGroupIndexes.Add(groupIndex);
|
|
}
|
|
}
|
|
|
|
public bool SetSkillGroupIconForAssign(int groupIndex, int nIcon)
|
|
{
|
|
return SetSkillGroupIconsForAssign(new[] { groupIndex }, groupIndex);
|
|
}
|
|
|
|
public bool SetSkillGroupIconsForAssign(System.Collections.Generic.IReadOnlyList<int> groupIndexes, int preferredGroupIndex = -1)
|
|
{
|
|
_skillGroupIndexes.Clear();
|
|
if (groupIndexes == null || groupIndexes.Count == 0)
|
|
{
|
|
Clear();
|
|
return false;
|
|
}
|
|
|
|
foreach (int groupIndex in groupIndexes)
|
|
{
|
|
if (groupIndex >= 0 && !_skillGroupIndexes.Contains(groupIndex))
|
|
{
|
|
_skillGroupIndexes.Add(groupIndex);
|
|
}
|
|
}
|
|
|
|
if (_skillGroupIndexes.Count == 0)
|
|
{
|
|
Clear();
|
|
return false;
|
|
}
|
|
|
|
int startIdx = 0;
|
|
if (preferredGroupIndex >= 0)
|
|
{
|
|
int idx = _skillGroupIndexes.IndexOf(preferredGroupIndex);
|
|
if (idx >= 0)
|
|
{
|
|
startIdx = idx;
|
|
}
|
|
}
|
|
|
|
EC_VIDEO_SETTING? setting = EC_Game.GetConfigs()?.GetVideoSettings();
|
|
if (!setting.HasValue || setting.Value.comboSkill == null)
|
|
{
|
|
Clear();
|
|
return false;
|
|
}
|
|
|
|
var comboSkills = setting.Value.comboSkill;
|
|
|
|
for (int i = 0; i < _skillGroupIndexes.Count; i++)
|
|
{
|
|
int groupIndex = _skillGroupIndexes[(startIdx + i) % _skillGroupIndexes.Count];
|
|
if (groupIndex < 0 || groupIndex >= comboSkills.Length)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
if (TrySetDefaultSkillGroupIcon())
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
Clear();
|
|
return false;
|
|
}
|
|
|
|
private bool TrySetDefaultSkillGroupIcon()
|
|
{
|
|
var uiMan = EC_Game.GetGameRun()?.GetUIManager()?.GetInGameUIMan();
|
|
if (uiMan == null)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
var icon = uiMan.GetIcon(DefaultComboIcon, EC_GAMEUI_ICONS.ICONS_SKILLGRP);
|
|
if (icon == null)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
SetImage(icon);
|
|
return true;
|
|
}
|
|
|
|
private bool TrySetSkillGroupIconByNIcon(int groupIndex, int nIcon)
|
|
{
|
|
_skillGroupIndex = groupIndex;
|
|
if (nIcon <= 0)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
var uiMan = EC_Game.GetGameRun()?.GetUIManager()?.GetInGameUIMan();
|
|
if (uiMan == null)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
// C++ mapping uses nIcon + 1 for skill group icon index.
|
|
string iconName = (nIcon + 1).ToString();
|
|
var icon = uiMan.GetIcon(iconName, EC_GAMEUI_ICONS.ICONS_SKILLGRP);
|
|
if (icon == null)
|
|
{
|
|
iconName = nIcon.ToString();
|
|
icon = uiMan.GetIcon(iconName, EC_GAMEUI_ICONS.ICONS_SKILLGRP);
|
|
}
|
|
if (icon == null)
|
|
{
|
|
iconName = DefaultComboIcon;
|
|
icon = uiMan.GetIcon(iconName, EC_GAMEUI_ICONS.ICONS_SKILLGRP);
|
|
}
|
|
if (icon == null)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
SetImage(icon);
|
|
return true;
|
|
}
|
|
|
|
public void UncheckAfterAssign()
|
|
{
|
|
uiToggle.isOn = false;
|
|
}
|
|
}
|
|
}
|