using GeometryTD.CustomEvent; using TMPro; using UnityEngine; using UnityEngine.UI; using UnityGameFramework.Runtime; namespace GeometryTD.UI { public class RepoForm : UGuiForm { [SerializeField] private CombineArea _combineArea; [SerializeField] private CompArea _compArea; [SerializeField] private SellArea _sellArea; [SerializeField] private ParticipantArea _participantArea; [SerializeField] private TMP_Text _goldText; [SerializeField] private CommonButton _sellModeButton; [SerializeField] private TMP_Text _sellModeButtonText; public void RefreshUI(RepoFormContext context) { if (context == null) { return; } RefreshGoldText(context.GoldText); RefreshStateUI(context); _combineArea?.OnInit(context.CombineAreaContext); _compArea?.OnInit(context.CompAreaContext); _sellArea?.OnInit(context.SellAreaContext); _participantArea?.OnInit(context.ParticipantAreaContext); if (_combineArea != null) { _combineArea.gameObject.SetActive(context.ShowCombineArea); _combineArea.SetInteractionEnabled(context.State == RepoFormState.Assemble); } if (_sellArea != null) { _sellArea.gameObject.SetActive(context.ShowSellArea); } _participantArea?.SetInteractionEnabled(context.State == RepoFormState.Assemble); } public void RefreshGoldText(string goldText) { if (_goldText != null) { _goldText.text = goldText ?? string.Empty; } } public bool TryAssignItemToCombineArea(RepoItemContext itemContext) { if (_combineArea == null) { return false; } return _combineArea.TryAssignItem(itemContext); } public bool TryClearCombineSlot(int slotIndex, out long removedItemId) { removedItemId = 0; if (_combineArea == null) { return false; } return _combineArea.TryClearSlot(slotIndex, out removedItemId); } public void SetRepoItemSelected(long itemId, bool isSelected) { _compArea?.SetItemSelected(itemId, isSelected); } public void RefreshParticipantArea(ParticipantAreaContext context) { _participantArea?.OnInit(context); } protected override void OnOpen(object userData) { base.OnOpen(userData); if (userData is RepoFormContext context) { RefreshUI(context); return; } Log.Warning("RepoForm requires RepoFormContext as userData."); } protected override void OnClose(bool isShutdown, object userData) { if (_goldText != null) { _goldText.text = string.Empty; } _combineArea?.OnReset(); _compArea?.OnReset(); _sellArea?.OnReset(); _participantArea?.OnReset(); base.OnClose(isShutdown, userData); } public void OnReturnButtonClick() { GameEntry.Event.Fire(this, RepoFormReturnEventArgs.Create()); } public void OnSellModeButtonClick() { GameEntry.Event.Fire(this, RepoSellModeToggleRequestedEventArgs.Create()); } private void RefreshStateUI(RepoFormContext context) { if (_sellModeButton != null) { _sellModeButton.gameObject.SetActive(context != null && context.ShowSellModeButton); } if (_sellModeButtonText != null) { _sellModeButtonText.text = context?.SellModeButtonText ?? "出售模式"; } } } }