Files
test/Assets/PerfectWorld/Scripts/UI/SkillUI/DlgAssignSlots.cs
2026-03-24 10:53:05 +07:00

487 lines
22 KiB
C#

//#define Applyforalicense
using BrewMonster.Assets.PerfectWorld.Scripts.UI.GamePlay;
using BrewMonster.Network;
using BrewMonster.Scripts;
using BrewMonster.Scripts.Managers;
using BrewMonster.Scripts.Skills;
using BrewMonster.UI;
using CSNetwork.GPDataType;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;
using static BrewMonster.PET_EGG_ESSENCE;
namespace BrewMonster
{
public class DlgAssignSlots : AUIDialog
{
//[SerializeField] List<Image> m_aSkillImage = new List<Image>();
//[SerializeField] List<Button> m_aSkillButton = new List<Button>();
public const int MAX_SKILL_GROUP = 4;
[SerializeField] List<AUIToggle> AUIImagePictureList = new List<AUIToggle>();
[SerializeField] Toggle[] toggleGroup = new Toggle[MAX_SKILL_GROUP];
[SerializeField] Button acceptButton;
public int m_nCurPanel1 = 1;
public int m_nCurPanel2 = 1;
int currentListIndex = 0;
int currentOffsetIndex = 0;
int currentSelectedSlotIndex = -1;
CECSkill assignedSkill = null;
private bool _subscribed;
/// <summary>
/// Apply for a license remove later
/// </summary>
/// <returns></returns>
// public int m_nCurPanel1 = 1;
// public int m_nCurPanel2 = 1;
public bool m_bShowAll1 = false;
public bool m_bShowAll2 = false;
public int m_nDisplayPanels1 = 0;
public int m_nDisplayPanels2 = 0;
[ContextMenu("SwitchShowSkillShortcut")]
public void SwitchShowSkillShortcut(int panelIndex)
{
currentListIndex = panelIndex;
UpdateShortcuts();
}
public override void Awake()
{
SwitchShowSkillShortcut(0);
}
public override void OnEnable()
{
UnSubscribeEvents();
SubscribeEvents();
currentListIndex = 0;
CreateCacheData();
UpdateShortcuts();
}
public override void OnDisable()
{
UnSubscribeEvents();
}
public void OnDestroy()
{
UnSubscribeEvents();
}
private List<CECShortcutSet> a_pSCS = new List<CECShortcutSet>();
public bool CreateCacheData()
{
int nCurPanel9 = GetCurPanel1();
int nCurPanel8 = GetCurPanel2();
CECHostPlayer pHost = EC_Game.GetGameRun().GetHostPlayer();
if (pHost == null)
return false;
a_pSCS = new List<CECShortcutSet>();
var a_pSCSTemp = new List<CECShortcutSet>();
var a_pszPanel = new List<string>();
GetQuickBarNameAndSC(pHost, a_pszPanel, a_pSCSTemp, nCurPanel9, nCurPanel8);
foreach (var item in a_pSCSTemp)
{
var temp = item.Clone();
a_pSCS.Add(temp);
}
return true;
}
public void CreateSkillShortcut()
{
// Debug.Log("HoangDev: CreateSkillShortcut: " + currentSelectedSlotIndex + " : " + assignedSkill.GetSkillID());
//CECShortcutSet pSCS = CECGameRun.Instance.GetHostPlayer().GetShortcutSet1(0);
a_pSCS[currentListIndex].CreateSkillShortcut(currentSelectedSlotIndex, assignedSkill);
EventBus.Publish(new OnAssignSkillEvent(assignedSkill.GetSkillID(), currentSelectedSlotIndex));
currentSelectedSlotIndex = -1;
assignedSkill = null;
}
public bool UpdateShortcuts()
{
CECShortcut pSC;
CECSCSkill pSCSkill;
AUIImagePictureBase pCell;
CECSkill pSkill = new CECSkill(-1, -1);
if (a_pSCS == null || a_pSCS.Count < 2)
return false;
if(currentListIndex >= a_pSCS.Count )
{
currentListIndex = 0;
}
// currentOffsetIndex = 0;
// for(int i = 0; i < currentListIndex; i++)
// {
// if(i == currentListIndex)
// {
// break;
// }
// currentOffsetIndex += a_pSCS[i].GetShortcutNum();
// }
int nSlots = Mathf.Min(a_pSCS[currentListIndex].GetShortcutNum(), AUIImagePictureList.Count);
for (int j = 0; j < nSlots; j++)
{
pCell = AUIImagePictureList[j];
pCell.SetSlotIndex(j);
if (pCell == null || !pCell.gameObject.activeInHierarchy)
continue;
pSC = a_pSCS[currentListIndex].GetShortcut(j);
if (pSC != null)
{
if (pSC.GetType() == (int)CECShortcut.ShortcutType.SCT_SKILL)
{
pSCSkill = (CECSCSkill)pSC;
pSkill = pSCSkill.GetSkill();
if (false/*m_bDelGoblinSkillSC && GNET::ElementSkill::IsGoblinSkill(pSkill->GetSkillID())*/)
{
/* a_pSCS[i]->SetShortcut(j, NULL);
pSC = NULL;*/
}
}
/*else if (pSC->GetType() == CECShortcut::SCT_ITEM)
{
iIconFile = CECGameUIMan::ICONS_INVENTORY;
pCell->SetColor(A3DCOLORRGB(255, 255, 255));
pSCItem = (CECSCItem*)pSC;
pIvtr = GetHostPlayer()->GetPack(pSCItem->GetInventory());
pItem = pIvtr->GetItem(pSCItem->GetIvtrSlot());
if (pItem && pItem->GetCoolTime(&nMax) > 0)
{
pClock->SetProgressRange(0, nMax);
pClock->SetProgressPos(nMax - pItem->GetCoolTime());
pClock->SetColor(A3DCOLORRGBA(0, 0, 0, 128));
}
if (pSCItem->GetInventory() == IVTRTYPE_EQUIPPACK)
pCell->SetColor(A3DCOLORRGBA(128, 128, 255, 128));
}
else if (pSC->GetType() == CECShortcut::SCT_PET)
{
pSCPet = (CECSCPet*)pSC;
CECPetData* pPet = pPetCorral->GetPetData(pSCPet->GetPetIndex());
iIconFile = CECGameUIMan::ICONS_INVENTORY;
pCell->SetColor(A3DCOLORRGB(255, 255, 255));
if (pPet)
{
// dead combat pet
if ((pPet->GetClass() == GP_PET_CLASS_COMBAT || pPet->GetClass() == GP_PET_CLASS_EVOLUTION) && pPet->GetHPFactor() == 0.0f)
{
pCell->SetColor(A3DCOLORRGB(128, 128, 128));
}
// current active pet
else if (pSCPet->IsActivePet())
{
pCell->SetColor(A3DCOLORRGB(255, 255, 0));
}
}
}
else if (pSC->GetType() == CECShortcut::SCT_AUTOFASHION)
{
iIconFile = CECGameUIMan::ICONS_SUITE;
fashionCoolTime = pHost->GetCoolTime(GP_CT_EQUIP_FASHION_ITEM, &fashionCoolTimeMax);
pCell->SetColor(A3DCOLORRGB(255, 255, 255));
if (fashionCoolTimeMax > 0)
{
pClock->SetProgressRange(0, fashionCoolTimeMax);
pClock->SetProgressPos(fashionCoolTimeMax - fashionCoolTime);
pClock->SetColor(A3DCOLORRGBA(0, 0, 0, 175));
}
}
else
{
iIconFile = CECGameUIMan::ICONS_ACTION;
if (pSC->GetType() == CECShortcut::SCT_COMMAND)
{
CECSCCommand* pCommandSC = (CECSCCommand*)pSC;
if (GetHostPlayer()->IsInvisible())
{
if (pCommandSC->GetCommandID() == CECSCCommand::CMD_STARTTRADE ||
pCommandSC->GetCommandID() == CECSCCommand::CMD_SELLBOOTH ||
pCommandSC->GetCommandID() == CECSCCommand::CMD_BINDBUDDY)
{
pCell->SetColor(A3DCOLORRGB(128, 128, 128));
}
else
{
pCell->SetColor(A3DCOLORRGB(255, 255, 255));
}
}
else
{
pCell->SetColor(A3DCOLORRGB(255, 255, 255));
}
}
if (pSC->GetCoolTime(&nMax) > 0)
{
pClock->SetProgressRange(0, nMax);
pClock->SetProgressPos(nMax - pSC->GetCoolTime());
pClock->SetColor(A3DCOLORRGBA(0, 0, 0, 128));
}
}*/
else if (pSC.GetType() == (int)CECShortcut.ShortcutType.SCT_ITEM)
{
pCell.SetColor(new Color(1f, 1f, 1f));
CECSCItem pSCItem = (CECSCItem)pSC;
EC_Inventory pIvtr = EC_Game.GetGameRun().GetHostPlayer().GetPack(pSCItem.GetInventory());
EC_IvtrItem pItem = pIvtr?.GetItem(pSCItem.GetIvtrSlot());
//if (pSCItem.GetInventory == InventoryConst.IVTRTYPE_EQUIPPACK)
//{
// pCell.SetColor(new Color(128, 128, 255, 128));
//}
if (pItem != null)
{
string itemIcon = pItem.GetIconFile();
GetGameUIMan().SetCover(pCell, itemIcon, EC_GAMEUI_ICONS.ICONS_INVENTORY);
}
}
else if (pSC.GetType() == (int)CECShortcut.ShortcutType.SCT_AUTOFASHION)
{
pCell.SetColor(new Color(1f, 1f, 1f));
}
else
{
if (pSC.GetType() == (int)CECShortcut.ShortcutType.SCT_COMMAND)
{
CECSCCommand pCommandSC = (CECSCCommand)pSC;
if (EC_Game.GetGameRun().GetHostPlayer().IsInvisible())
{
if (pCommandSC.GetCommandID() == (int)CECSCCommand.CommandID.CMD_STARTTRADE ||
pCommandSC.GetCommandID() == (int)CECSCCommand.CommandID.CMD_SELLBOOTH ||
pCommandSC.GetCommandID() == (int)CECSCCommand.CommandID.CMD_BINDBUDDY)
{
pCell.SetColor(new Color(128, 128, 128, 255));
}
else
{
pCell.SetColor(new Color(1f, 1f, 1f));
}
}
else
{
pCell.SetColor(new Color(1f, 1f, 1f));
}
}
string cmdIcon = pSC.GetIconFile();
GetGameUIMan().SetCover(pCell, cmdIcon, EC_GAMEUI_ICONS.ICONS_ACTION);
}
if (pSC != null)
{
if (pCell.GetDataPtr() == pSC)
{
continue;
}
pCell.SetDataPtr(pSC);
if (pSC.GetType() == (int)CECShortcut.ShortcutType.SCT_SKILLGRP)
{
EC_VIDEO_SETTING setting = EC_Game.GetConfigs().GetVideoSettings();
/* pCell.SetCover(GetGameUIMan()->m_pA2DSpriteIcons[CECGameUIMan::ICONS_SKILLGRP],
setting.comboSkill[((CECSCSkillGrp)pSC).GetGroupIndex()].nIcon + 1);
setting.comboSkill[((CECSCSkillGrp)pSC).GetGroupIndex()].nIcon + 1;*/
// fix later now haven't skill group icon yet
GetGameUIMan().SetCover(pCell, "unknown", EC_GAMEUI_ICONS.ICONS_SKILL);
}
else
{
if (pSkill != null)
{
pCell.gameObject.SetActive(true);
//BMLogger.Log("HoangDev: QuickBar Set Skill Icon: " + (uint)pSkill.GetSkillID() + " : " + ElementSkill.GetIcon((uint)pSkill.GetSkillID()));
var nameskill = ElementSkill.GetIcon((uint)pSkill.GetSkillID());
GetGameUIMan().SetCover(pCell, nameskill, EC_GAMEUI_ICONS.ICONS_SKILL);
}
/* af_GetFileTitle(pSC->GetIconFile(), strFile);
strFile.MakeLower();
pCell->SetCover(GetGameUIMan()->m_pA2DSpriteIcons[iIconFile],
GetGameUIMan()->m_IconMap[iIconFile][strFile]); */
}
}
}
else
{
pCell.Clear();
}
}
return true;
}
private void GetQuickBarNameAndSC(CECHostPlayer pHost, List<string> pszPanel, List<CECShortcutSet> pSCS, int panel9, int panel8)
{
string dlgName;
dlgName = $"Win_Quickbar{Shortcut.SIZE_HOSTSCSET1}Ha";
pszPanel.Add(dlgName);
for (int i = 0; i < (int)Shortcut.NUM_HOSTSCSETS1; i++)
{
dlgName = $"Win_Quickbar{(int)Shortcut.SIZE_HOSTSCSET1}Hb_{i + 1}";
pSCS?.Add(pHost.GetShortcutSet1(i));
pszPanel.Add(dlgName);
}
/*// ----- Quickbar 1 Vertical A -----
dlgName = $"Win_Quickbar{(int)Shortcut.SIZE_HOSTSCSET1}Va";
pszPanel.Add(dlgName);
for (int i = 0; i < (int)Shortcut.NUM_HOSTSCSETS1; i++)
{
dlgName = $"Win_Quickbar{(int)Shortcut.SIZE_HOSTSCSET1}Vb_{i + 1}";
pSCS?.Add(pHost.GetShortcutSet1(i));
pszPanel.Add(dlgName);
}*/
// ----- Quickbar 2 Horizontal A -----
dlgName = $"Win_Quickbar{(int)Shortcut.SIZE_HOSTSCSET2}Ha";
pszPanel.Add(dlgName);
for (int i = 0; i < (int)Shortcut.NUM_HOSTSCSETS2; i++)
{
dlgName = $"Win_Quickbar{(int)Shortcut.SIZE_HOSTSCSET2}Hb_{i + 1}";
pSCS?.Add(pHost.GetShortcutSet2(i));
pszPanel.Add(dlgName);
}
/* // ----- Quickbar 2 Vertical A -----
dlgName = $"Win_Quickbar{(int)Shortcut.SIZE_HOSTSCSET2}Va";
pszPanel.Add(dlgName);
for (int i = 0; i < (int)Shortcut.NUM_HOSTSCSETS2; i++)
{
dlgName = $"Win_Quickbar{(int)Shortcut.SIZE_HOSTSCSET2}Vb_{i + 1}";
pSCS?.Add(pHost.GetShortcutSet2(i));
pszPanel.Add(dlgName);
}*/
}
public int GetCurPanel1()
{
return m_nCurPanel1;
}
public int GetCurPanel2()
{
return m_nCurPanel2;
}
public void OnOpenAssignSlotEvent(OpenAssignSlotEvent obj)
{
currentSelectedSlotIndex = obj.slotIndex;
Debug.Log($"HoangDev: OnOpenAssignSlotEvent: assignedSkillIsNull={(assignedSkill == null)} slotIndex={currentSelectedSlotIndex}");
if (assignedSkill != null)
{
CreateSkillShortcut();
Debug.Log($"HoangDev: OnOpenAssignSlotEvent: After CreateSkillShortcut: assignedSkillIsNull={(assignedSkill == null)} slotIndex={currentSelectedSlotIndex}");
}
}
public void OnOpenAssignSkillEvent(OpenAssignSkillEvent obj)
{
assignedSkill = CECGameRun.Instance.GetHostPlayer().GetPositiveSkillByID(obj.skillID);
Debug.Log($"HoangDev: OnOpenAssignSkillEvent: skillID={obj.skillID} currentSelectedSlotIndex={currentSelectedSlotIndex}");
if (currentSelectedSlotIndex != -1)
{
CreateSkillShortcut();
Debug.Log($"HoangDev: OnOpenAssignSkillEvent: AfterCreateSkillShortcut: assignedSkillIsNull={(assignedSkill == null)} slotIndex={currentSelectedSlotIndex}");
}
}
public void OnCloseAssignSlotEvent(CloseAssignSlotEvent obj)
{
currentSelectedSlotIndex = -1;
}
public void OnCloseAssignSkillEvent(CloseAssignSkillEvent obj)
{
assignedSkill = null;
}
private void UnSubscribeEvents()
{
acceptButton.onClick.RemoveListener(AcceptSkillChange);
EventBus.Unsubscribe<OpenAssignSlotEvent>(OnOpenAssignSlotEvent);
EventBus.Unsubscribe<OpenAssignSkillEvent>(OnOpenAssignSkillEvent);
EventBus.Unsubscribe<CloseAssignSlotEvent>(OnCloseAssignSlotEvent);
EventBus.Unsubscribe<CloseAssignSkillEvent>(OnCloseAssignSkillEvent);
for(int i = 0; i < MAX_SKILL_GROUP; i++)
{
toggleGroup[i].onValueChanged.RemoveAllListeners();
}
}
private void SubscribeEvents()
{
acceptButton.onClick.AddListener(AcceptSkillChange);
EventBus.Subscribe<OpenAssignSlotEvent>(OnOpenAssignSlotEvent);
EventBus.Subscribe<OpenAssignSkillEvent>(OnOpenAssignSkillEvent);
EventBus.Subscribe<CloseAssignSlotEvent>(OnCloseAssignSlotEvent);
EventBus.Subscribe<CloseAssignSkillEvent>(OnCloseAssignSkillEvent);
for(int i = 0; i < MAX_SKILL_GROUP; i++)
{
int capturedIndex = i; // avoid closure capturing loop variable
if (toggleGroup[capturedIndex] == null) continue;
toggleGroup[capturedIndex].onValueChanged.AddListener((bool value) => OnToggleValueChanged(capturedIndex, value));
}
}
private void OnToggleValueChanged(int index, bool value)
{
if (index < 0 || index >= MAX_SKILL_GROUP) return;
if(value)
{
SwitchShowSkillShortcut(index);
}
}
public void AcceptSkillChange()
{
int nCurPanel9 = GetCurPanel1();
int nCurPanel8 = GetCurPanel2();
CECHostPlayer pHost = EC_Game.GetGameRun().GetHostPlayer();
if (pHost == null) return;
var real_pSCS = new List<CECShortcutSet>();
var a_pszPanel = new List<string>();
GetQuickBarNameAndSC(pHost, a_pszPanel, real_pSCS, nCurPanel9, nCurPanel8);
if (a_pSCS == null || a_pSCS.Count == 0 || real_pSCS == null || real_pSCS.Count == 0)
return;
int setCount = Mathf.Min(a_pSCS.Count, real_pSCS.Count);
for (int i = 0; i < setCount; i++)
{
CECShortcutSet cachedSet = a_pSCS[i];
CECShortcutSet realSet = real_pSCS[i];
if (cachedSet == null || realSet == null)
continue;
int slotCount = Mathf.Min(cachedSet.GetShortcutNum(), realSet.GetShortcutNum());
for (int j = 0; j < slotCount; j++)
{
CECShortcut cachedSC = cachedSet.GetShortcut(j);
if (cachedSC == null)
{
realSet.SetShortcut(j, null);
continue;
}
if (cachedSC.GetType() == (int)CECShortcut.ShortcutType.SCT_SKILL)
{
CECSkill skill = (cachedSC as CECSCSkill)?.GetSkill();
if (skill != null)
realSet.CreateSkillShortcut(j, skill);
else
realSet.SetShortcut(j, null);
}
else
{
// Mirror cached shortcut as-is (including null), for non-skill types.
realSet.SetShortcut(j, cachedSC);
}
}
}
EC_Game.GetGameRun().SaveConfigsToServer();
CECUIManager.Instance?.UpdateSkillRelatedUI();
}
}
}