280 lines
11 KiB
C#
280 lines
11 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using BrewMonster.Assets.PerfectWorld.Scripts.UI.GamePlay;
|
|
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;
|
|
public const string DefaultComboIcon = "爱你";
|
|
|
|
[SerializeField] private List<SkillSlotWidget> _combosList;
|
|
[SerializeField] private Button _btnEditCombo;
|
|
[SerializeField] private Button _btnDeleteCombo;
|
|
[SerializeField] private SkillSlotWidget _btnNormalAttack;
|
|
[SerializeField] private SkillSlotWidget _btnLoopAttack;
|
|
|
|
[Header("SetUpCombo")]
|
|
[SerializeField] private GameObject _contentSetUpCombo;
|
|
[SerializeField] private Image _imgCurrentCombo;
|
|
[SerializeField] private List<SkillSlotWidget> _detailCombosList;
|
|
[SerializeField] private Button _btnConfirmCombo;
|
|
|
|
private SkillSlotWidget _currentComboSlotWidget;
|
|
private SkillSlotWidget _currentSkillToAssign;
|
|
private EC_VIDEO_SETTING _currentComboSetting;
|
|
|
|
private EC_VIDEO_SETTING Setting => EC_Game.GetConfigs().GetVideoSettings();
|
|
public EC_VIDEO_SETTING CurrentComboSetting => _currentComboSetting;
|
|
|
|
public event Action<SkillSlotWidget> OnClickedSkillSlot;
|
|
public event Action OnClickedEditCombo;
|
|
public event Action<SkillSlotWidget> OnClickedAssignSkill; // click to asign skill to combo
|
|
public event Action OnClickedConfirmCombo;
|
|
|
|
public CECGameUIMan GetGameUIMan()
|
|
{
|
|
return EC_Game.GetGameRun().GetUIManager().GetInGameUIMan();
|
|
}
|
|
private void OnEnable()
|
|
{
|
|
_currentSkillToAssign = null;
|
|
ShowCurrentCombos();
|
|
for (var index = 0; index < _combosList.Count; index++)
|
|
{
|
|
var slotWidget = _combosList[index];
|
|
slotWidget.SetSlotIndex(index);
|
|
slotWidget.OnClickedSkillSlot += OnClickedSkillSlotBtn;
|
|
slotWidget.SetFocusFrame(false);
|
|
}
|
|
|
|
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);
|
|
_btnDeleteCombo.onClick.AddListener(OnClickedDeleteComboBtn);
|
|
|
|
_btnEditCombo.interactable = false;
|
|
_btnDeleteCombo.interactable = false;
|
|
|
|
GetGameUIMan().SetCover(_btnNormalAttack ,$"{Mathf.Abs(NormalAttackId)}", EC_GAMEUI_ICONS.ICONS_SKILLGRP);
|
|
GetGameUIMan().SetCover(_btnLoopAttack ,$"{Mathf.Abs(LoopAttackId)}", EC_GAMEUI_ICONS.ICONS_SKILLGRP);
|
|
_btnNormalAttack.OnClickedSkillSlot += OnSelectedSkillToAsign;
|
|
_btnLoopAttack.OnClickedSkillSlot += OnSelectedSkillToAsign;
|
|
_btnNormalAttack.SetSkillId(NormalAttackId);
|
|
_btnLoopAttack.SetSkillId(LoopAttackId);
|
|
}
|
|
|
|
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);
|
|
_btnDeleteCombo.onClick.RemoveListener(OnClickedDeleteComboBtn);
|
|
if (_currentComboSlotWidget != null)
|
|
{
|
|
_currentComboSlotWidget.SetFocusFrame(false);
|
|
}
|
|
_currentComboSlotWidget = null;
|
|
if (_currentSkillToAssign != null)
|
|
{
|
|
_currentSkillToAssign.SetFocusFrame(false);
|
|
}
|
|
_currentSkillToAssign = null;
|
|
_btnNormalAttack.OnClickedSkillSlot -= OnSelectedSkillToAsign;
|
|
_btnLoopAttack.OnClickedSkillSlot -= OnSelectedSkillToAsign;
|
|
}
|
|
|
|
public void ShowCurrentCombos()
|
|
{
|
|
// setting.comboSkill[GetData() - 1].nIcon = (byte)m_nIcon;
|
|
if (Setting.comboSkill == null || _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(GetGameUIMan().GetIcon(DefaultComboIcon, EC_GAMEUI_ICONS.ICONS_SKILLGRP));
|
|
}
|
|
else
|
|
{
|
|
_combosList[i].Clear();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void ShowComboInDetail(short[] idSkills)
|
|
{
|
|
_imgCurrentCombo.sprite =GetGameUIMan().GetIcon(DefaultComboIcon, EC_GAMEUI_ICONS.ICONS_SKILLGRP);
|
|
for (int i = 0; i < idSkills.Length; i++)
|
|
{
|
|
if (idSkills[i] == 0)
|
|
{
|
|
_detailCombosList[i].Clear();
|
|
continue;
|
|
}
|
|
var nameskill = ElementSkill.GetIcon((uint)idSkills[i]);
|
|
AUIImagePictureBase slot;
|
|
if (idSkills[i] == NormalAttackId || idSkills[i] == LoopAttackId)
|
|
{
|
|
slot = GetGameUIMan().SetCover(_detailCombosList[i] ,$"{Mathf.Abs(idSkills[i])}", EC_GAMEUI_ICONS.ICONS_SKILLGRP);
|
|
}
|
|
else
|
|
{
|
|
slot = GetGameUIMan().SetCover(_detailCombosList[i] ,nameskill, EC_GAMEUI_ICONS.ICONS_SKILL);
|
|
}
|
|
|
|
if (slot is AUIImagePicture picture)
|
|
{
|
|
picture.SetSkillId(idSkills[i]);
|
|
}
|
|
}
|
|
}
|
|
|
|
public bool IsEmptyComboSlot(int comboIndex)
|
|
{
|
|
if (Setting.comboSkill==null || comboIndex >= Setting.comboSkill.Length)
|
|
{
|
|
BMLogger.LogError("Combo list size mismatch");
|
|
return false;
|
|
}
|
|
return IsAnEmptyCombo(Setting.comboSkill[comboIndex].idSkill);
|
|
}
|
|
private bool IsAnEmptyCombo(short[] idSkills)
|
|
{
|
|
foreach (var id in idSkills)
|
|
{
|
|
if (id !=0)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
private void OnClickedSkillSlotBtn(SkillSlotWidget slotWidget)
|
|
{
|
|
OnClickedSkillSlot?.Invoke(slotWidget);
|
|
if (_currentComboSlotWidget != null && _currentComboSlotWidget != slotWidget)
|
|
{
|
|
_currentComboSlotWidget.SetFocusFrame(false);
|
|
}
|
|
_currentComboSlotWidget = slotWidget;
|
|
_currentComboSlotWidget.SetFocusFrame(true);
|
|
var isEmptySlot = IsEmptyComboSlot(_currentComboSlotWidget.GetSlotIndex);
|
|
ShowSetUpContent(isEmptySlot);
|
|
_btnDeleteCombo.interactable = !isEmptySlot;
|
|
_btnEditCombo.interactable = !isEmptySlot;
|
|
if (IsEmptyComboSlot(slotWidget.GetSlotIndex))
|
|
{
|
|
ShowComboInDetail(Setting.comboSkill[_currentComboSlotWidget.GetSlotIndex].idSkill);
|
|
}
|
|
}
|
|
public void ShowSetUpContent(bool setActive)
|
|
{
|
|
_contentSetUpCombo.SetActive(setActive);
|
|
if (!setActive)
|
|
{
|
|
if (_currentSkillToAssign != null)
|
|
{
|
|
_currentSkillToAssign.SetFocusFrame(false);
|
|
}
|
|
_currentSkillToAssign = null;
|
|
}
|
|
}
|
|
private void OnClickedEditComboBtn()
|
|
{
|
|
OnClickedEditCombo?.Invoke();
|
|
if(_currentComboSlotWidget == null || Setting.comboSkill == null) return;
|
|
ShowSetUpContent(true);
|
|
ShowComboInDetail(Setting.comboSkill[_currentComboSlotWidget.GetSlotIndex].idSkill);
|
|
}
|
|
private void OnClickedDeleteComboBtn()
|
|
{
|
|
if (_currentComboSlotWidget == null)
|
|
{
|
|
BMLogger.LogError("_currentComboSlotWidget null");
|
|
return;
|
|
}
|
|
EC_VIDEO_SETTING setting = EC_Game.GetConfigs().GetVideoSettings();
|
|
setting.comboSkill[_currentComboSlotWidget.GetSlotIndex].nIcon = 0;
|
|
for (var index = 0;
|
|
index < setting.comboSkill[_currentComboSlotWidget.GetSlotIndex].idSkill.Length;
|
|
index++)
|
|
{
|
|
setting.comboSkill[_currentComboSlotWidget.GetSlotIndex].idSkill[index] = 0;
|
|
}
|
|
|
|
_currentComboSetting = setting;
|
|
EC_Game.GetConfigs().SetVideoSettings(_currentComboSetting);
|
|
//Show(false);
|
|
CECUIManager.Instance.m_pDlgSkillSubOther.UpdateComboSkill();
|
|
EC_Game.GetGameRun().SaveConfigsToServer();
|
|
ShowSetUpContent(false);
|
|
ShowCurrentCombos();
|
|
}
|
|
private void OnClickedConfirmComboBtn()
|
|
{
|
|
OnClickedConfirmCombo?.Invoke();
|
|
}
|
|
private void OnClickedAssignSkillBtn(SkillSlotWidget slotWidget)
|
|
{
|
|
OnClickedAssignSkill?.Invoke(slotWidget);
|
|
if(_currentSkillToAssign!=null)
|
|
{
|
|
SetSkillToCurrentCombo(slotWidget.GetSlotIndex, (short)_currentSkillToAssign.SkillId);
|
|
EC_Game.GetConfigs().SetVideoSettings(_currentComboSetting);
|
|
//Show(false);
|
|
CECUIManager.Instance.m_pDlgSkillSubOther.UpdateComboSkill();
|
|
EC_Game.GetGameRun().SaveConfigsToServer();
|
|
}
|
|
}
|
|
|
|
public bool SetSkillToCurrentCombo(int slotIndex, short skillId)
|
|
{
|
|
if(_currentComboSlotWidget == null) return false;
|
|
EC_VIDEO_SETTING setting = EC_Game.GetConfigs().GetVideoSettings();
|
|
setting.comboSkill[_currentComboSlotWidget.GetSlotIndex].nIcon = 1;
|
|
setting.comboSkill[_currentComboSlotWidget.GetSlotIndex].idSkill[slotIndex] = skillId;
|
|
ShowComboInDetail(setting.comboSkill[_currentComboSlotWidget.GetSlotIndex].idSkill);
|
|
_currentComboSetting = setting;
|
|
return true;
|
|
}
|
|
private void OnSelectedSkillToAsign(SkillSlotWidget skillSlotWidget)
|
|
{
|
|
if (_currentSkillToAssign != null && _currentSkillToAssign != skillSlotWidget)
|
|
{
|
|
_currentSkillToAssign.SetFocusFrame(false);
|
|
}
|
|
_currentSkillToAssign = skillSlotWidget;
|
|
_currentSkillToAssign.SetFocusFrame(true);
|
|
}
|
|
}
|
|
}
|