159 lines
5.7 KiB
C#
159 lines
5.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using BrewMonster.Network;
|
|
using BrewMonster.Scripts.Skills;
|
|
using BrewMonster.UI;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace BrewMonster
|
|
{
|
|
public class SkillSetUpComboWidget : MonoBehaviour
|
|
{
|
|
public const int NormalAttackId = -1;
|
|
public const int LoopAttackId = -2;
|
|
|
|
[SerializeField] private List<SkillSlotWidget> _combosList;
|
|
[SerializeField] private Button _btnEditCombo;
|
|
[SerializeField] private Button _btnDeleteCombo;
|
|
|
|
[Header("SetUpCombo")]
|
|
[SerializeField] private GameObject _contentSetUpCombo;
|
|
[SerializeField] private Image _imgCurrentCombo;
|
|
[SerializeField] private List<SkillSlotWidget> _detailCombosList;
|
|
[SerializeField] private Button _btnConfirmCombo;
|
|
|
|
private SkillSlotWidget _currentSlotWidget;
|
|
public event Action<SkillSlotWidget> OnClickedSkillSlot;
|
|
public event Action OnClickedEditCombo;
|
|
public event Action<SkillSlotWidget> OnClickedAssignSkill; // click to asign skill to combo
|
|
public event Action OnClickedDeleteCombo;
|
|
public event Action OnClickedConfirmCombo;
|
|
|
|
public CECGameUIMan GetGameUIMan()
|
|
{
|
|
return EC_Game.GetGameRun().GetUIManager().GetInGameUIMan();
|
|
}
|
|
private void OnEnable()
|
|
{
|
|
ShowCurrentCombos();
|
|
for (var index = 0; index < _combosList.Count; index++)
|
|
{
|
|
var slotWidget = _combosList[index];
|
|
slotWidget.SetSlotIndex(index);
|
|
slotWidget.OnClickedSkillSlot += OnClickedSkillSlotBtn;
|
|
}
|
|
|
|
for (var index = 0; index < _detailCombosList.Count; index++)
|
|
{
|
|
var slotWidget = _detailCombosList[index];
|
|
slotWidget.SetSlotIndex(index);
|
|
slotWidget.OnClickedSkillSlot += OnClickedAssignSkillBtn;
|
|
}
|
|
|
|
_btnEditCombo.onClick.AddListener(OnClickedEditComboBtn);
|
|
_btnConfirmCombo.onClick.AddListener(OnClickedConfirmComboBtn);
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
foreach (var slotWidget in _combosList)
|
|
{
|
|
slotWidget.OnClickedSkillSlot -= OnClickedSkillSlotBtn;
|
|
}
|
|
foreach (var slotWidget in _detailCombosList)
|
|
{
|
|
slotWidget.OnClickedSkillSlot -= OnClickedAssignSkillBtn;
|
|
}
|
|
_btnEditCombo.onClick.RemoveListener(OnClickedEditComboBtn);
|
|
_btnConfirmCombo.onClick.RemoveListener(OnClickedConfirmComboBtn);
|
|
_currentSlotWidget = null;
|
|
}
|
|
|
|
private void ShowCurrentCombos()
|
|
{
|
|
var m_nIcon = 1;
|
|
EC_VIDEO_SETTING setting = EC_Game.GetConfigs().GetVideoSettings();
|
|
// setting.comboSkill[GetData() - 1].nIcon = (byte)m_nIcon;
|
|
if (_combosList.Count != setting.comboSkill.Length)
|
|
{
|
|
BMLogger.LogError("Combo list size mismatch");
|
|
return;
|
|
}
|
|
for (int i = 0; i < setting.comboSkill.Length; i++)
|
|
{
|
|
// m_IconMap[(byte)iCONS_TYPE].Item2.FirstOrDefault(s => s.name == nameImage)
|
|
if (setting.comboSkill[i].idSkill.Length > 0)
|
|
{
|
|
if (IsAnEmptyCombo(setting.comboSkill[i].idSkill))
|
|
{
|
|
_combosList[i].SetImage(null);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void ShowComboInDetail(short[] idSkills)
|
|
{
|
|
for (int i = 0; i < idSkills.Length; i++)
|
|
{
|
|
var nameskill = ElementSkill.GetIcon((uint)idSkills[i]);
|
|
if (idSkills[i] == NormalAttackId || idSkills[i] == LoopAttackId)
|
|
{
|
|
GetGameUIMan().SetCover(_detailCombosList[i] ,$"{Mathf.Abs(idSkills[i])}", EC_GAMEUI_ICONS.ICONS_SKILLGRP);
|
|
}
|
|
else
|
|
{
|
|
GetGameUIMan().SetCover(_detailCombosList[i] ,nameskill, EC_GAMEUI_ICONS.ICONS_SKILL);
|
|
}
|
|
}
|
|
}
|
|
|
|
private bool IsAnEmptyCombo(short[] idSkills)
|
|
{
|
|
bool isValid = false;
|
|
foreach (var id in idSkills)
|
|
{
|
|
if (id !=0)
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
return isValid;
|
|
}
|
|
|
|
private void OnClickedSkillSlotBtn(SkillSlotWidget slotWidget)
|
|
{
|
|
OnClickedSkillSlot?.Invoke(slotWidget);
|
|
_currentSlotWidget = slotWidget;
|
|
}
|
|
public void ShowSetUpContent(bool setActive)
|
|
{
|
|
_contentSetUpCombo.SetActive(setActive);
|
|
}
|
|
private void OnClickedEditComboBtn()
|
|
{
|
|
OnClickedEditCombo?.Invoke();
|
|
if(_currentSlotWidget == null) return;
|
|
EC_VIDEO_SETTING setting = EC_Game.GetConfigs().GetVideoSettings();
|
|
ShowComboInDetail(setting.comboSkill[_currentSlotWidget.GetSlotIndex].idSkill);
|
|
}
|
|
private void OnClickedConfirmComboBtn()
|
|
{
|
|
OnClickedConfirmCombo?.Invoke();
|
|
}
|
|
private void OnClickedAssignSkillBtn(SkillSlotWidget slotWidget)
|
|
{
|
|
OnClickedAssignSkill?.Invoke(slotWidget);
|
|
}
|
|
|
|
public void SetSkillToCurrentCombo(int slotIndex, short skillId)
|
|
{
|
|
if(_currentSlotWidget == null) return;
|
|
EC_VIDEO_SETTING setting = EC_Game.GetConfigs().GetVideoSettings();
|
|
setting.comboSkill[_currentSlotWidget.GetSlotIndex].idSkill[slotIndex] = skillId;
|
|
ShowComboInDetail(setting.comboSkill[_currentSlotWidget.GetSlotIndex].idSkill);
|
|
}
|
|
}
|
|
}
|