using System; using GeometryTD.CustomUtility; using GeometryTD.Definition; using UnityEngine; namespace GeometryTD.UI { public partial class RewardSelectFormController { private static RewardSelectFormContext BuildContext(RewardSelectFormRawData rawData) { if (rawData == null) { return null; } return new RewardSelectFormContext { TipText = string.IsNullOrWhiteSpace(rawData.TipText) ? "Select one reward" : rawData.TipText, RefreshButtonText = BuildRefreshButtonText(rawData.RefreshCost, rawData.CanRefresh), CanRefresh = rawData.CanRefresh, CanGiveUp = rawData.CanGiveUp, RewardItems = BuildRewardItemContexts(rawData.RewardItems) }; } private static string BuildRefreshButtonText(int refreshCost, bool canRefresh) { if (!canRefresh) { return "Refreshed"; } if (refreshCost <= 0) { return "Refresh"; } return $"Refresh -{refreshCost}"; } private static RewardItemContext[] BuildRewardItemContexts(RewardSelectItemRawData[] rawItems) { if (rawItems == null || rawItems.Length <= 0) { return Array.Empty(); } RewardItemContext[] contexts = new RewardItemContext[rawItems.Length]; for (int i = 0; i < rawItems.Length; i++) { RewardSelectItemRawData rawItem = rawItems[i]; if (rawItem == null) { continue; } contexts[i] = new RewardItemContext { Index = i, IconArea = new IconAreaContext { ComponentSlotType = rawItem.SlotType, Icon = rawItem.Icon, Rarity = rawItem.Rarity, Color = ResolveIconColor(rawItem.SourceItem) }, Title = rawItem.Title ?? string.Empty, TypeText = ResolveTypeText(rawItem.TypeText, rawItem.SlotType), Description = BuildDescription(rawItem), Tags = BuildTagContexts(rawItem), }; } return contexts; } private static string BuildDescription(RewardSelectItemRawData rawItem) { string baseDescription = rawItem.Description; string tagDescription = TagDisplayUtility.BuildTagDescriptionText(rawItem.Tags); if (string.IsNullOrWhiteSpace(tagDescription)) { return baseDescription; } if (string.IsNullOrWhiteSpace(baseDescription)) { return tagDescription; } return $"{baseDescription}\n{tagDescription}"; } private static Color ResolveIconColor(TowerCompItemData sourceItem) { if (sourceItem == null) { return Color.white; } return IconColorGenerator.GenerateForComponent(sourceItem); } private static string ResolveTypeText(string typeText, TowerCompSlotType slotType) { if (!string.IsNullOrWhiteSpace(typeText)) { return typeText; } return slotType switch { TowerCompSlotType.Muzzle => "Muzzle Component", TowerCompSlotType.Bearing => "Bearing Component", TowerCompSlotType.Base => "Base Component", TowerCompSlotType.Accessory => "Accessory", _ => "Component" }; } private static TagItemContext[] BuildTagContexts(RewardSelectItemRawData rawItem) { string[] tagTexts = TagDisplayUtility.BuildTagTexts(rawItem?.Tags); if (tagTexts == null || tagTexts.Length <= 0) { return 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; } } }