205 lines
7.6 KiB
C#
205 lines
7.6 KiB
C#
using BrewMonster.Assets.PerfectWorld.Scripts.UI.GamePlay;
|
|
using BrewMonster.UI;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using BrewMonster.Network;
|
|
using Unity.VisualScripting;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace BrewMonster
|
|
{
|
|
public class DlgAssignSub : AUIDialog
|
|
{
|
|
private readonly SortedSet<int> m_skills = new();
|
|
[SerializeField] private Transform ptSkillContainer;
|
|
[SerializeField] private Transform psSkillContainer;
|
|
[SerializeField] private List<AUIToggleSkillAssign> psSkillSlotList;
|
|
[SerializeField] private List<AUIToggleSkillAssign> ptSkillSlotList;
|
|
|
|
private int _otherSkillIndex;
|
|
|
|
public override void Awake()
|
|
{
|
|
base.Awake();
|
|
SetUp();
|
|
}
|
|
|
|
public override void OnDisable()
|
|
{
|
|
UnsubscribeAssignEvents();
|
|
UnhookAssignSkillToggles();
|
|
base.OnDisable();
|
|
}
|
|
|
|
private void SetUp()
|
|
{
|
|
LoadChildToList(ptSkillContainer, ptSkillSlotList);
|
|
LoadChildToList(psSkillContainer, psSkillSlotList);
|
|
}
|
|
private void LoadChildToList(Transform parentTF, List<AUIToggleSkillAssign> slotList)
|
|
{
|
|
foreach (Transform child in parentTF)
|
|
{
|
|
AUIToggleSkillAssign img = child.GetComponent<AUIToggleSkillAssign>();
|
|
if (img != null)
|
|
{
|
|
slotList.Add(img);
|
|
}
|
|
}
|
|
}
|
|
public override void OnEnable()
|
|
{
|
|
base.OnEnable();
|
|
UpdateView();
|
|
SubscribeAssignEvents();
|
|
HookAssignSkillToggles();
|
|
_otherSkillIndex = 0;
|
|
}
|
|
|
|
private void SubscribeAssignEvents()
|
|
{
|
|
EventBus.Unsubscribe<OnAssignSkillEvent>(OnAssignSkillBusEvent);
|
|
EventBus.Subscribe<OnAssignSkillEvent>(OnAssignSkillBusEvent);
|
|
}
|
|
|
|
private void UnsubscribeAssignEvents()
|
|
{
|
|
EventBus.Unsubscribe<OnAssignSkillEvent>(OnAssignSkillBusEvent);
|
|
}
|
|
|
|
private void HookAssignSkillToggles()
|
|
{
|
|
UnhookAssignSkillToggles();
|
|
foreach (var slot in ptSkillSlotList)
|
|
{
|
|
if (slot == null) continue;
|
|
var assign = slot.GetComponent<AUIToggleSkillAssign>();
|
|
if (assign != null)
|
|
assign.OnAssignToggleChanged += OnSkillAssignToggleChanged;
|
|
}
|
|
foreach (var slot in psSkillSlotList)
|
|
{
|
|
if (slot == null) continue;
|
|
var assign = slot.GetComponent<AUIToggleSkillAssign>();
|
|
if (assign != null)
|
|
assign.OnAssignToggleChanged += OnSkillAssignToggleChanged;
|
|
}
|
|
}
|
|
|
|
private void UnhookAssignSkillToggles()
|
|
{
|
|
foreach (var slot in ptSkillSlotList)
|
|
{
|
|
if (slot == null) continue;
|
|
var assign = slot.GetComponent<AUIToggleSkillAssign>();
|
|
if (assign != null)
|
|
assign.OnAssignToggleChanged -= OnSkillAssignToggleChanged;
|
|
}
|
|
foreach (var slot in psSkillSlotList)
|
|
{
|
|
if (slot == null) continue;
|
|
var assign = slot.GetComponent<AUIToggleSkillAssign>();
|
|
if (assign != null)
|
|
assign.OnAssignToggleChanged -= OnSkillAssignToggleChanged;
|
|
}
|
|
}
|
|
|
|
private void OnSkillAssignToggleChanged(bool isOn, int skillId)
|
|
{
|
|
EventBus.Publish(new AssignSkillSelectionChangedEvent(skillId, isOn));
|
|
}
|
|
|
|
private void OnAssignSkillBusEvent(OnAssignSkillEvent @event)
|
|
{
|
|
foreach (var slot in ptSkillSlotList)
|
|
{
|
|
if (slot == null) continue;
|
|
var assign = slot.GetComponent<AUIToggleSkillAssign>();
|
|
if (assign == null) continue;
|
|
if (assign.GetSkillIdForAssign() != @event.skillID)
|
|
continue;
|
|
assign.UncheckAfterAssign();
|
|
return;
|
|
}
|
|
}
|
|
|
|
private void UpdateView()
|
|
{
|
|
m_skills.Clear();
|
|
|
|
CECHostPlayer pHost = GetHostPlayer();
|
|
int i = 0;
|
|
int activeImgPicIndex = 1;
|
|
int passiveImgPicIndex = 1;
|
|
int positiveSkillNum = pHost.GetPositiveSkillNum();
|
|
int equipSkillNum = pHost.GetEquipSkillNum();
|
|
int passiveSkillNum = pHost.GetPassiveSkillNum();
|
|
for (i = 0; i < positiveSkillNum; i++)
|
|
{
|
|
var processSkill = pHost.GetPositiveSkillByIndex(i);
|
|
var processSkillID = processSkill.GetSkillID();
|
|
if (ptSkillSlotList.Count <= i)
|
|
{
|
|
var newSkillSlot = Instantiate(ptSkillSlotList[0], ptSkillContainer);
|
|
newSkillSlot.name = $"Item_{processSkillID}";
|
|
ptSkillSlotList.Add(newSkillSlot);
|
|
}
|
|
SetImage(processSkill, ptSkillSlotList[i]);
|
|
ptSkillSlotList[i].transform.GetChild(0).gameObject.SetActive(true);
|
|
ptSkillSlotList[i].SetSkillID(processSkillID);
|
|
m_skills.Add(processSkillID);
|
|
}
|
|
|
|
ShowSkillGrp();
|
|
// for (i = 0; i < passiveSkillNum; i++)
|
|
// {
|
|
// if (psSkillSlotList.Count <= i)
|
|
// {
|
|
// psSkillSlotList.Add(Instantiate(psSkillSlotList[0], psSkillContainer));
|
|
// }
|
|
// psSkillSlotList[i].transform.GetChild(i).gameObject.SetActive(true);
|
|
// SetImage(pHost.GetPassiveSkillByIndex(i), psSkillSlotList[i]);
|
|
// m_skills.Add(pHost.GetPassiveSkillByIndex(i).GetSkillID());
|
|
// }
|
|
}
|
|
private void ShowSkillGrp()
|
|
{
|
|
_otherSkillIndex = 0;
|
|
EC_VIDEO_SETTING setting = EC_Game.GetConfigs().GetVideoSettings();
|
|
for (int groupIndex = 0; groupIndex < setting.comboSkill.Length; groupIndex++)
|
|
{
|
|
var skill = setting.comboSkill[groupIndex];
|
|
if (skill.nIcon > 0)
|
|
{
|
|
if (psSkillSlotList.Count <= _otherSkillIndex)
|
|
{
|
|
psSkillSlotList.Add(Instantiate(psSkillSlotList[0], psSkillContainer));
|
|
}
|
|
psSkillSlotList[_otherSkillIndex].transform.GetChild(0).gameObject.SetActive(true);
|
|
//todo: temporary use default icon: 爱你
|
|
GetGameUIMan().SetCover(psSkillSlotList[_otherSkillIndex],"爱你", EC_GAMEUI_ICONS.ICONS_SKILLGRP);
|
|
// Encode combo group as negative id so assign flow can reuse AssignSkillSelectionChangedEvent.
|
|
// Real skill ids are positive, so this does not clash.
|
|
psSkillSlotList[_otherSkillIndex].SetSkillID(-(groupIndex + 1));
|
|
// m_skills.Add(pHost.GetPassiveSkillByIndex(i).GetSkillID());
|
|
_otherSkillIndex++;
|
|
}
|
|
}
|
|
}
|
|
private void SetImage(CECSkill cECSkill, AUIToggleSkillAssign learnedSkillUI)
|
|
{
|
|
if(cECSkill == null)
|
|
{
|
|
BMLogger.LogError("CDlgSkillSubPool::SetImage cECSkill is null");
|
|
return;
|
|
}
|
|
var slot = GetGameUIMan().SetCover(learnedSkillUI, cECSkill.GetIconFile(), EC_GAMEUI_ICONS.ICONS_SKILL);
|
|
if (slot is AUIImagePicture picture)
|
|
{
|
|
picture.SetSkillId(cECSkill.GetSkillID());
|
|
}
|
|
}
|
|
}
|
|
}
|