using GameFramework.Event; using GeometryTD.CustomUtility; using GeometryTD.Definition; using UnityGameFramework.Runtime; namespace GeometryTD.UI { public class ItemDescFormController : UIFormControllerCommonBase< ItemDescFormContext, ItemDescForm> { protected override UIFormType UIFormTypeId => UIFormType.ItemDescForm; protected override void RefreshUI(ItemDescForm form, ItemDescFormContext context) { form.RefreshUI(context); } protected override void CloseLoadedFormDirect(ItemDescForm form) { GameEntry.UI.CloseUIForm(form); } private static ItemDescFormContext BuildContext(ItemDescFormRawData rawData) { if (rawData == null) { return null; } return new ItemDescFormContext { Title = rawData.Title, TypeText = rawData.TypeText, Description = rawData.Description, Price = rawData.Price, TargetPos = rawData.TargetPos, Tags = BuildTags(rawData) }; } private static TagItemContext[] BuildTags(ItemDescFormRawData rawData) { string[] tagTexts = rawData?.TagTexts; if ((tagTexts == null || tagTexts.Length <= 0) && rawData?.Tags != null) { tagTexts = TagDisplayUtility.BuildTagTexts(rawData.Tags); } if (tagTexts == null || tagTexts.Length <= 0) { return System.Array.Empty(); } TagItemContext[] contexts = new TagItemContext[tagTexts.Length]; for (int i = 0; i < tagTexts.Length; i++) { contexts[i] = new TagItemContext { TagName = tagTexts[i] ?? string.Empty }; } return contexts; } public int? OpenUI(ItemDescFormRawData rawData) { ItemDescFormContext context = BuildContext(rawData); return OpenUIInternal(context); } public override int? OpenUI(object userData = null) { if (userData is ItemDescFormContext context) { return OpenUIInternal(context); } if (userData is ItemDescFormRawData rawData) { return OpenUI(rawData); } if (userData != null) { Log.Warning("ItemDescFormController.OpenUI() userData type is invalid."); return null; } return OpenUIInternal(Context); } public override void BindUseCase(IUIUseCase useCase) { if (!(useCase is ItemDescFormUseCase)) { Log.Error("ItemDescForm.BindUseCase() useCase is invalid."); } } } }