using GeometryTD.CustomEvent; using TMPro; using UnityEngine; using UnityGameFramework.Runtime; namespace GeometryTD.UI { public class RepoForm : UGuiForm { [SerializeField] private CombineArea _combineArea; [SerializeField] private CompArea _compArea; [SerializeField] private ParticipantArea _participantArea; [SerializeField] private TMP_Text _goldText; public void RefreshUI(RepoFormContext context) { if (context == null) { return; } RefreshGoldText(context.GoldText); _combineArea?.OnInit(context.CombineAreaContext); _compArea?.OnInit(context.CompAreaContext); _participantArea?.OnInit(context.ParticipantAreaContext); } 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(); _participantArea?.OnReset(); base.OnClose(isShutdown, userData); } public void OnReturnButtonClick() { GameEntry.Event.Fire(this, RepoFormReturnEventArgs.Create()); } } }