159 lines
5.5 KiB
C#
159 lines
5.5 KiB
C#
using BrewMonster.Assets.PerfectWorld.Scripts.UI.GamePlay;
|
|
using BrewMonster.Network;
|
|
using BrewMonster.UI;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
namespace BrewMonster
|
|
{
|
|
public class CDlgSkillSubAction : MonoBehaviour
|
|
{
|
|
[SerializeField] List<ActionInfo> m_aActionInfo = new List<ActionInfo>();
|
|
[SerializeField] Transform orderContain;
|
|
[SerializeField] AUIImagePicture orderTemplate;
|
|
[SerializeField] AUIImagePicture actionTemplate;
|
|
[SerializeField] Transform actionContain;
|
|
|
|
private void Awake()
|
|
{
|
|
if (orderContain == null)
|
|
{
|
|
BMLogger.LogError("CDlgSkillSubAction: orderContain is not assigned!");
|
|
return;
|
|
}
|
|
;
|
|
if (actionContain == null)
|
|
{
|
|
BMLogger.LogError("CDlgSkillSubAction: actionContain is not assigned!");
|
|
return;
|
|
}
|
|
|
|
Init();
|
|
}
|
|
private void OnEnable()
|
|
{
|
|
OnShowDialog();
|
|
|
|
}
|
|
public void Init()
|
|
{
|
|
int[] objCount = { 8, 2, 2, 27 };
|
|
|
|
for (int i = 0; i < 3; i++)
|
|
{
|
|
for (int j = 0; j < objCount[i]; j++)
|
|
{
|
|
var orderTP = Instantiate(orderTemplate, orderContain);
|
|
orderTP.gameObject.SetActive(true);
|
|
SetupActionClickHandler(orderTP);
|
|
m_aActionInfo.Add(new ActionInfo
|
|
{
|
|
image = orderTP,
|
|
pLabel = orderTP.GetComponentInChildren<TextMeshProUGUI>()
|
|
});
|
|
|
|
}
|
|
}
|
|
for (int j = 0; j < 27; j++)
|
|
{
|
|
var actionTP = Instantiate(actionTemplate, actionContain);
|
|
actionTP.gameObject.SetActive(true);
|
|
|
|
// Set up click handler for action items / 为动作项设置点击处理程序
|
|
SetupActionClickHandler(actionTP);
|
|
|
|
m_aActionInfo.Add(new ActionInfo
|
|
{
|
|
image = actionTP,
|
|
pLabel = actionTP.GetComponentInChildren<TextMeshProUGUI>()
|
|
});
|
|
}
|
|
//force refresh layout orderContain anc actionContain
|
|
//then refresh layout of this gameobject
|
|
}
|
|
public void OnShowDialog()
|
|
{
|
|
AUIImagePicture pImage;
|
|
TextMeshProUGUI pLabel;
|
|
CECShortcut pSCThis;
|
|
string strFile = "";
|
|
var gameUIMan = CECUIManager.Instance.GetInGameUIMan();
|
|
|
|
CECGameRun pGameRun = CECGameRun.Instance;
|
|
int[] objCount = { 8, 2, 2, 27 };
|
|
CECShortcutSet[] a_pSC =
|
|
{
|
|
pGameRun.GetGenCmdShortcuts(),
|
|
pGameRun.GetTeamCmdShortcuts(),
|
|
pGameRun.GetTradeCmdShortcuts(),
|
|
pGameRun.GetPoseCmdShortcuts()
|
|
};
|
|
int count = 0;
|
|
for (int i = 0; i < a_pSC.Length; i++)
|
|
{
|
|
for (int j = 0; j < objCount[i]; j++)
|
|
{
|
|
pImage = m_aActionInfo[count].image;
|
|
pLabel = m_aActionInfo[count].pLabel;
|
|
|
|
if (!pImage) break;
|
|
|
|
if (j < a_pSC[i].GetShortcutNum())
|
|
{
|
|
pSCThis = a_pSC[i].GetShortcut(j);
|
|
pImage.SetDataPtr(pSCThis, "ptr_CECShortcut");
|
|
|
|
strFile = pSCThis.GetIconFile();
|
|
gameUIMan.SetCover(pImage, strFile, EC_GAMEUI_ICONS.ICONS_ACTION);
|
|
|
|
pLabel.SetText(pSCThis.GetDesc());
|
|
}
|
|
else
|
|
{
|
|
/* pImage->Show(false);
|
|
pLabel->Show(false);*/
|
|
}
|
|
count++;
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Set up click handler for action items, similar to wave hand logic / 为动作项设置点击处理程序,类似于挥手逻辑
|
|
/// </summary>
|
|
private void SetupActionClickHandler(AUIImagePicture actionImage)
|
|
{
|
|
if (actionImage == null) return;
|
|
|
|
Debug.Log($"CDlgSkillSubAction::SetupActionClickHandler():: Setting up click handler for action item: {actionImage.name}");
|
|
// Get the button component / 获取按钮组件
|
|
var button = actionImage.GetComponentInChildren<UnityEngine.UI.Button>();
|
|
if (button == null)
|
|
return;
|
|
|
|
// Remove existing listeners and add our custom handler / 移除现有监听器并添加我们的自定义处理程序
|
|
button.onClick.RemoveAllListeners();
|
|
button.onClick.AddListener(() => OnActionClicked(actionImage));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Handle action icon click, similar to wave hand logic / 处理动作图标点击,类似于挥手逻辑
|
|
/// </summary>
|
|
private void OnActionClicked(AUIImagePicture actionImage)
|
|
{
|
|
if (actionImage == null) return;
|
|
Debug.Log("OnActionClicked: " + actionImage.name);
|
|
// Get the shortcut from the action image / 从动作图像获取快捷方式
|
|
actionImage.Execute();
|
|
}
|
|
|
|
[Serializable]
|
|
public struct ActionInfo
|
|
{
|
|
public AUIImagePicture image;
|
|
public TextMeshProUGUI pLabel;
|
|
}
|
|
}
|
|
}
|