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 m_aActionInfo = new List(); [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(); } private 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() }); } } 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() }); } //force refresh layout orderContain anc actionContain //then refresh layout of this gameobject } private 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++; } } } /// /// Set up click handler for action items, similar to wave hand logic / 为动作项设置点击处理程序,类似于挥手逻辑 /// 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(); if (button == null) return; // Remove existing listeners and add our custom handler / 移除现有监听器并添加我们的自定义处理程序 button.onClick.RemoveAllListeners(); button.onClick.AddListener(() => OnActionClicked(actionImage)); } /// /// Handle action icon click, similar to wave hand logic / 处理动作图标点击,类似于挥手逻辑 /// 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; } } }