using BrewMonster.Assets.PerfectWorld.Scripts.UI.GamePlay; using BrewMonster.UI; using System; using System.Collections.Generic; using BrewMonster.Network; using UnityEngine; using UnityEngine.UI; namespace BrewMonster { public class CDlgSkillSubPool : AUIDialog { private readonly SortedSet m_skills = new(); [SerializeField] private Transform ptSkillContainer; [SerializeField] private Transform psSkillContainer; [SerializeField] private List psSkillSlotList; [SerializeField] private List ptSkillSlotList; [SerializeField] private SkillSetUpComboWidget _skillSetUpComboWidget; private AUIImagePicture _currentSelectSkill; private SkillSlotWidget _currentSelectComboSlot; public override void Awake() { base.Awake(); SetUp(); } public override void OnEnable() { _currentSelectSkill = null; UpdateView(); _skillSetUpComboWidget.ShowSetUpContent(false); _skillSetUpComboWidget.OnClickedSkillSlot += OnClickedSkillSlot; _skillSetUpComboWidget.OnClickedAssignSkill += OnClickedAssignSkill; _skillSetUpComboWidget.OnClickedConfirmCombo += OnClickedConfirmCombo; _skillSetUpComboWidget.OnClickedSpecialAction += OnClickedSpecialAction; foreach (var skill in ptSkillSlotList) { if (skill is LearnedSkillUI skillUI) { skillUI.OnClickedSkill += OnClickedSkill; } } } public override void OnDisable() { _currentSelectComboSlot = null; if (_currentSelectSkill is LearnedSkillUI learnedOnClose) { learnedOnClose.SetFocusFrame(false); } base.OnDisable(); _skillSetUpComboWidget.OnClickedSkillSlot -= OnClickedSkillSlot; _skillSetUpComboWidget.OnClickedAssignSkill -= OnClickedAssignSkill; _skillSetUpComboWidget.OnClickedConfirmCombo -= OnClickedConfirmCombo; _skillSetUpComboWidget.OnClickedSpecialAction -= OnClickedSpecialAction; foreach (var skill in ptSkillSlotList) { if (skill is LearnedSkillUI skillUI) { skillUI.OnClickedSkill -= OnClickedSkill; } } } private void OnClickedSpecialAction() { if (_currentSelectSkill is LearnedSkillUI learned) { learned.SetFocusFrame(false); } _currentSelectSkill = null; } private void OnDestroy() { foreach (var skill in ptSkillSlotList) { if (skill is LearnedSkillUI skillUI) { skillUI.OnClickedSkill -= OnClickedSkill; } } } private void SetUp() { LoadChildToList(ptSkillContainer, ptSkillSlotList); LoadChildToList(psSkillContainer, psSkillSlotList); } private void LoadChildToList(Transform parentTF, List slotList) { foreach (Transform child in parentTF) { AUIImagePicture img = child.GetComponent(); if (img != null) { slotList.Add(img); } } } private void OnClickedSkill(AUIImagePicture imagePicture) { if (_currentSelectSkill is LearnedSkillUI previousLearned) { previousLearned.SetFocusFrame(false); } _currentSelectSkill = imagePicture; if (_currentSelectSkill is LearnedSkillUI currentLearned) { currentLearned.SetFocusFrame(true); } if (_skillSetUpComboWidget.CurrentSkillToAssign != null) { _skillSetUpComboWidget.CurrentSkillToAssign.SetFocusFrame(false); } } private void UpdateView() { m_skills.Clear(); CECHostPlayer pHost = GetHostPlayer(); int i = 0; int positiveSkillNum = pHost.GetPositiveSkillNum(); int passiveSkillNum = pHost.GetPassiveSkillNum(); for (i = 0; i < positiveSkillNum; i++) { if (ptSkillSlotList.Count <= i) { ptSkillSlotList.Add(Instantiate(ptSkillSlotList[0], ptSkillContainer)); } ptSkillSlotList[i].transform.GetChild(0).gameObject.SetActive(true); SetImage(pHost.GetPositiveSkillByIndex(i), ptSkillSlotList[i]); m_skills.Add(pHost.GetPositiveSkillByIndex(i).GetSkillID()); } // for (i = 0; i < passiveSkillNum; i++) // { // if (psSkillSlotList.Count <= i) // { // psSkillSlotList.Add(Instantiate(psSkillSlotList[0], psSkillContainer)); // } // psSkillSlotList[i].transform.GetChild(0).gameObject.SetActive(true); // EC_VIDEO_SETTING setting = EC_Game.GetConfigs().GetVideoSettings(); // var setting.comboSkill[((CECSCSkillGrp*)pSC)->GetGroupIndex()].nIcon + 1 // GetGameUIMan().SetCover(psSkillSlotList[i], "unknown", EC_GAMEUI_ICONS.ICONS_SKILL); // // pCell->SetCover(GetGameUIMan()->m_pA2DSpriteIcons[CECGameUIMan::ICONS_SKILLGRP], // // ); // SetImage(pHost.GetPassiveSkillByIndex(i), psSkillSlotList[i]); // m_skills.Add(pHost.GetPassiveSkillByIndex(i).GetSkillID()); // } } private void SetImage(CECSkill cECSkill, AUIImagePicture learnedSkillUI) { if(cECSkill == null) { BMLogger.LogError("CDlgSkillSubPool::SetImage cECSkill is null"); return; } BMLogger.Log($"CDlgSkillSubPool::SetImage SkillID={cECSkill.GetSkillID()} SkillName={cECSkill.GetName()} IconFile={cECSkill.GetIconFile()}"); var slot = GetGameUIMan().SetCover(learnedSkillUI, cECSkill.GetIconFile(), EC_GAMEUI_ICONS.ICONS_SKILL); if (slot is AUIImagePicture picture) { picture.SetSkillId(cECSkill.GetSkillID()); } } private void OnClickedSkillSlot(SkillSlotWidget skillSlot) { _currentSelectComboSlot = skillSlot; // _skillSetUpComboWidget.ShowSetUpContent(true); // allow show edit to create if (_skillSetUpComboWidget.IsEmptyComboSlot(skillSlot.GetSlotIndex)) { _skillSetUpComboWidget.ShowSetUpContent(true); } } private void OnClickedConfirmCombo() { _skillSetUpComboWidget.ShowCurrentCombos(); if (_currentSelectComboSlot != null && _skillSetUpComboWidget.CurrentComboSetting.comboSkill[_currentSelectComboSlot.GetSlotIndex].idSkill == null) { BMLogger.LogError("Null to set combo skill"); return; } EC_Game.GetConfigs().SetVideoSettings(_skillSetUpComboWidget.CurrentComboSetting); CECUIManager.Instance.m_pDlgSkillSubOther.UpdateComboSkill(); EC_Game.GetGameRun().SaveConfigsToServer(); } //assign skill from list in the left ui private void OnClickedAssignSkill(SkillSlotWidget slotWidget) { if(_currentSelectSkill != null && _currentSelectSkill is LearnedSkillUI skillUI) { // _skillSetUpComboWidget.CurrentSkillToAssign = null; _skillSetUpComboWidget.IsSelectFromListSkill= true; _skillSetUpComboWidget.SetSkillToCurrentCombo(slotWidget.GetSlotIndex, (short)skillUI.SkillId); } } } }