214 lines
8.3 KiB
C#
214 lines
8.3 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 _currentSlotWidget;
|
|
private SkillSlotWidget _currentSkillToAsign;
|
|
|
|
private EC_VIDEO_SETTING Setting => EC_Game.GetConfigs().GetVideoSettings();
|
|
|
|
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()
|
|
{
|
|
_currentSkillToAsign = null;
|
|
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);
|
|
|
|
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);
|
|
_currentSlotWidget = null;
|
|
_btnNormalAttack.OnClickedSkillSlot -= OnSelectedSkillToAsign;
|
|
_btnLoopAttack.OnClickedSkillSlot -= OnSelectedSkillToAsign;
|
|
}
|
|
|
|
private 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));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
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);
|
|
_currentSlotWidget = slotWidget;
|
|
if (IsEmptyComboSlot(slotWidget.GetSlotIndex))
|
|
{
|
|
ShowComboInDetail(Setting.comboSkill[_currentSlotWidget.GetSlotIndex].idSkill);
|
|
}
|
|
}
|
|
public void ShowSetUpContent(bool setActive)
|
|
{
|
|
_contentSetUpCombo.SetActive(setActive);
|
|
}
|
|
private void OnClickedEditComboBtn()
|
|
{
|
|
OnClickedEditCombo?.Invoke();
|
|
if(_currentSlotWidget == null || Setting.comboSkill == null) return;
|
|
ShowSetUpContent(true);
|
|
ShowComboInDetail(Setting.comboSkill[_currentSlotWidget.GetSlotIndex].idSkill);
|
|
}
|
|
private void OnClickedConfirmComboBtn()
|
|
{
|
|
OnClickedConfirmCombo?.Invoke();
|
|
}
|
|
private void OnClickedAssignSkillBtn(SkillSlotWidget slotWidget)
|
|
{
|
|
OnClickedAssignSkill?.Invoke(slotWidget);
|
|
if(_currentSkillToAsign!=null)
|
|
{
|
|
SetSkillToCurrentCombo(slotWidget.GetSlotIndex, (short)_currentSkillToAsign.SkillId, out var setting);
|
|
EC_Game.GetConfigs().SetVideoSettings(setting);
|
|
//Show(false);
|
|
CECUIManager.Instance.m_pDlgSkillSubOther.UpdateComboSkill();
|
|
EC_Game.GetGameRun().SaveConfigsToServer();
|
|
}
|
|
}
|
|
|
|
public bool SetSkillToCurrentCombo(int slotIndex, short skillId, out EC_VIDEO_SETTING result)
|
|
{
|
|
result = EC_Game.GetConfigs().GetVideoSettings();
|
|
if(_currentSlotWidget == null) return false;
|
|
EC_VIDEO_SETTING setting = EC_Game.GetConfigs().GetVideoSettings();
|
|
setting.comboSkill[_currentSlotWidget.GetSlotIndex].idSkill[slotIndex] = skillId;
|
|
ShowComboInDetail(setting.comboSkill[_currentSlotWidget.GetSlotIndex].idSkill);
|
|
result = setting;
|
|
return true;
|
|
}
|
|
private void OnSelectedSkillToAsign(SkillSlotWidget skillSlotWidget)
|
|
{
|
|
_currentSkillToAsign = skillSlotWidget;
|
|
}
|
|
}
|
|
}
|