122 lines
3.7 KiB
C#
122 lines
3.7 KiB
C#
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 = BuildDescription(rawData),
|
|
Price = rawData.Price,
|
|
ScreenPosition = rawData.ScreenPosition,
|
|
Tags = BuildTags(rawData)
|
|
};
|
|
}
|
|
|
|
private static string BuildDescription(ItemDescFormRawData rawData)
|
|
{
|
|
string baseDescription = rawData?.Description ?? string.Empty;
|
|
string tagDescription = rawData?.TagRuntimes != null && rawData.TagRuntimes.Length > 0
|
|
? TagDisplayUtility.BuildTagDescriptionText(rawData.TagRuntimes)
|
|
: TagDisplayUtility.BuildTagDescriptionText(rawData?.Tags);
|
|
if (string.IsNullOrWhiteSpace(tagDescription))
|
|
{
|
|
return baseDescription;
|
|
}
|
|
|
|
if (string.IsNullOrWhiteSpace(baseDescription))
|
|
{
|
|
return tagDescription;
|
|
}
|
|
|
|
return $"{baseDescription}\n{tagDescription}";
|
|
}
|
|
|
|
private static TagItemContext[] BuildTags(ItemDescFormRawData rawData)
|
|
{
|
|
string[] tagTexts = rawData?.TagRuntimes != null && rawData.TagRuntimes.Length > 0
|
|
? TagDisplayUtility.BuildTagTexts(rawData.TagRuntimes)
|
|
: rawData?.Tags != null
|
|
? TagDisplayUtility.BuildTagTexts(rawData.Tags)
|
|
: null;
|
|
|
|
if (tagTexts == null || tagTexts.Length <= 0)
|
|
{
|
|
return System.Array.Empty<TagItemContext>();
|
|
}
|
|
|
|
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.");
|
|
}
|
|
}
|
|
}
|
|
}
|