补全 UI 设计
- `ItemDescForm` 道具详细信息面板,目前还未添加 DescText 内容的赋值 - `RepoForm` 道具入槽逻辑调整,为了适应 `ItemDescForm` 的点击打开逻辑,点击道具自动匹配槽位改成拖动道具到相应槽位 - 添加了一系列图片素材
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using GeometryTD.CustomEvent;
|
||||
using GeometryTD.Definition;
|
||||
using GameFramework.Event;
|
||||
using GeometryTD.CustomUtility;
|
||||
using UnityEngine;
|
||||
using UnityGameFramework.Runtime;
|
||||
|
||||
namespace GeometryTD.UI
|
||||
@@ -10,6 +13,14 @@ namespace GeometryTD.UI
|
||||
{
|
||||
private RepoFormUseCase _useCase;
|
||||
private readonly Dictionary<long, RepoItemContext> _itemContextMap = new Dictionary<long, RepoItemContext>();
|
||||
private readonly Dictionary<long, ItemDescSeed> _itemDescSeedMap = new Dictionary<long, ItemDescSeed>();
|
||||
|
||||
private sealed class ItemDescSeed
|
||||
{
|
||||
public string Title;
|
||||
public string TypeText;
|
||||
public TagType[] Tags;
|
||||
}
|
||||
|
||||
protected override UIFormType UIFormTypeId => UIFormType.RepoForm;
|
||||
|
||||
@@ -20,14 +31,18 @@ namespace GeometryTD.UI
|
||||
|
||||
protected override void SubscribeCustomEvents()
|
||||
{
|
||||
GameEntry.Event.Subscribe(RepoItemSelectedEventArgs.EventId, OnRepoItemSelected);
|
||||
GameEntry.Event.Subscribe(RepoItemDetailRequestedEventArgs.EventId, OnRepoItemDetailRequested);
|
||||
GameEntry.Event.Subscribe(RepoItemDragEndedEventArgs.EventId, OnRepoItemDragEnded);
|
||||
GameEntry.Event.Subscribe(CombineSlotClickedEventArgs.EventId, OnCombineSlotClicked);
|
||||
GameEntry.Event.Subscribe(RepoFormReturnEventArgs.EventId, OnRepoFormReturn);
|
||||
}
|
||||
|
||||
protected override void UnsubscribeCustomEvents()
|
||||
{
|
||||
GameEntry.Event.Unsubscribe(RepoItemSelectedEventArgs.EventId, OnRepoItemSelected);
|
||||
GameEntry.Event.Unsubscribe(RepoItemDetailRequestedEventArgs.EventId, OnRepoItemDetailRequested);
|
||||
GameEntry.Event.Unsubscribe(RepoItemDragEndedEventArgs.EventId, OnRepoItemDragEnded);
|
||||
GameEntry.Event.Unsubscribe(CombineSlotClickedEventArgs.EventId, OnCombineSlotClicked);
|
||||
GameEntry.Event.Unsubscribe(RepoFormReturnEventArgs.EventId, OnRepoFormReturn);
|
||||
}
|
||||
|
||||
public override int? OpenUI(object userData = null)
|
||||
@@ -78,6 +93,7 @@ namespace GeometryTD.UI
|
||||
private RepoFormContext BuildContext(RepoFormRawData rawData)
|
||||
{
|
||||
_itemContextMap.Clear();
|
||||
_itemDescSeedMap.Clear();
|
||||
if (rawData?.Inventory == null)
|
||||
{
|
||||
return null;
|
||||
@@ -87,57 +103,82 @@ namespace GeometryTD.UI
|
||||
|
||||
if (rawData.Inventory.Towers != null)
|
||||
{
|
||||
foreach (var tower in rawData.Inventory.Towers)
|
||||
foreach (DefenseTowerItemData tower in rawData.Inventory.Towers)
|
||||
{
|
||||
if (tower == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
AddItemContext(items, new RepoItemContext
|
||||
{
|
||||
Title = $"[Tower] {tower.Name} ({tower.Rarity})",
|
||||
InstanceId = tower.InstanceId,
|
||||
CanDrag = true,
|
||||
ComponentSlotType = TowerCompSlotType.None,
|
||||
IconAreaContext = BuildIconAreaContext(tower.Rarity)
|
||||
IconAreaContext = BuildIconAreaContext(tower)
|
||||
});
|
||||
AddItemDescSeed(tower.InstanceId, tower.Name, "Tower",
|
||||
tower.Stats != null ? tower.Stats.Tags : null);
|
||||
}
|
||||
}
|
||||
|
||||
if (rawData.Inventory.MuzzleComponents != null)
|
||||
{
|
||||
foreach (var item in rawData.Inventory.MuzzleComponents)
|
||||
foreach (MuzzleCompItemData item in rawData.Inventory.MuzzleComponents)
|
||||
{
|
||||
if (item == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
AddItemContext(items, new RepoItemContext
|
||||
{
|
||||
Title = $"[Muzzle] {item.Name} ({item.Rarity})",
|
||||
InstanceId = item.InstanceId,
|
||||
CanDrag = true,
|
||||
ComponentSlotType = TowerCompSlotType.Muzzle,
|
||||
IconAreaContext = BuildIconAreaContext(item.Rarity)
|
||||
IconAreaContext = BuildIconAreaContext(item)
|
||||
});
|
||||
AddItemDescSeed(item.InstanceId, item.Name, BuildComponentTypeText(item.SlotType), item.Tags);
|
||||
}
|
||||
}
|
||||
|
||||
if (rawData.Inventory.BearingComponents != null)
|
||||
{
|
||||
foreach (var item in rawData.Inventory.BearingComponents)
|
||||
foreach (BearingCompItemData item in rawData.Inventory.BearingComponents)
|
||||
{
|
||||
if (item == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
AddItemContext(items, new RepoItemContext
|
||||
{
|
||||
Title = $"[Bearing] {item.Name} ({item.Rarity})",
|
||||
InstanceId = item.InstanceId,
|
||||
CanDrag = true,
|
||||
ComponentSlotType = TowerCompSlotType.Bearing,
|
||||
IconAreaContext = BuildIconAreaContext(item.Rarity)
|
||||
IconAreaContext = BuildIconAreaContext(item)
|
||||
});
|
||||
AddItemDescSeed(item.InstanceId, item.Name, BuildComponentTypeText(item.SlotType), item.Tags);
|
||||
}
|
||||
}
|
||||
|
||||
if (rawData.Inventory.BaseComponents != null)
|
||||
{
|
||||
foreach (var item in rawData.Inventory.BaseComponents)
|
||||
foreach (BaseCompItemData item in rawData.Inventory.BaseComponents)
|
||||
{
|
||||
if (item == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
AddItemContext(items, new RepoItemContext
|
||||
{
|
||||
Title = $"[Base] {item.Name} ({item.Rarity})",
|
||||
InstanceId = item.InstanceId,
|
||||
CanDrag = true,
|
||||
ComponentSlotType = TowerCompSlotType.Base,
|
||||
IconAreaContext = BuildIconAreaContext(item.Rarity)
|
||||
IconAreaContext = BuildIconAreaContext(item)
|
||||
});
|
||||
AddItemDescSeed(item.InstanceId, item.Name, BuildComponentTypeText(item.SlotType), item.Tags);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -162,36 +203,139 @@ namespace GeometryTD.UI
|
||||
_itemContextMap[itemContext.InstanceId] = itemContext;
|
||||
}
|
||||
|
||||
private static IconAreaContext BuildIconAreaContext(RarityType rarity)
|
||||
private void AddItemDescSeed(long itemId, string title, string typeText, TagType[] tags)
|
||||
{
|
||||
if (itemId <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_itemDescSeedMap[itemId] = new ItemDescSeed
|
||||
{
|
||||
Title = string.IsNullOrWhiteSpace(title) ? $"Item {itemId}" : title,
|
||||
TypeText = typeText ?? string.Empty,
|
||||
Tags = CloneTags(tags)
|
||||
};
|
||||
}
|
||||
|
||||
private static TagType[] CloneTags(TagType[] tags)
|
||||
{
|
||||
return tags != null ? (TagType[])tags.Clone() : Array.Empty<TagType>();
|
||||
}
|
||||
|
||||
private static string BuildComponentTypeText(TowerCompSlotType slotType)
|
||||
{
|
||||
return slotType switch
|
||||
{
|
||||
TowerCompSlotType.Muzzle => "Muzzle Component",
|
||||
TowerCompSlotType.Bearing => "Bearing Component",
|
||||
TowerCompSlotType.Base => "Base Component",
|
||||
TowerCompSlotType.Accessory => "Accessory",
|
||||
_ => "Component"
|
||||
};
|
||||
}
|
||||
|
||||
private static IconAreaContext BuildIconAreaContext(DefenseTowerItemData tower)
|
||||
{
|
||||
if (tower == null)
|
||||
{
|
||||
return new IconAreaContext
|
||||
{
|
||||
ComponentSlotType = TowerCompSlotType.None,
|
||||
Rarity = RarityType.None,
|
||||
Color = Color.white,
|
||||
Icon = null
|
||||
};
|
||||
}
|
||||
|
||||
return new IconAreaContext
|
||||
{
|
||||
Rarity = rarity,
|
||||
ComponentSlotType = TowerCompSlotType.None,
|
||||
Rarity = tower.Rarity,
|
||||
Color = IconColorGenerator.GenerateForTower(tower),
|
||||
Icon = null
|
||||
};
|
||||
}
|
||||
|
||||
private void OnRepoItemSelected(object sender, GameEventArgs e)
|
||||
private static IconAreaContext BuildIconAreaContext(TowerCompItemData item)
|
||||
{
|
||||
if (!(e is RepoItemSelectedEventArgs args))
|
||||
if (item == null)
|
||||
{
|
||||
return new IconAreaContext
|
||||
{
|
||||
ComponentSlotType = TowerCompSlotType.None,
|
||||
Rarity = RarityType.None,
|
||||
Color = Color.white,
|
||||
Icon = null
|
||||
};
|
||||
}
|
||||
|
||||
return new IconAreaContext
|
||||
{
|
||||
ComponentSlotType = item.SlotType,
|
||||
Rarity = item.Rarity,
|
||||
Color = IconColorGenerator.GenerateForComponent(item),
|
||||
Icon = null
|
||||
};
|
||||
}
|
||||
|
||||
#region Event Handlers
|
||||
|
||||
private void OnRepoItemDetailRequested(object sender, GameEventArgs e)
|
||||
{
|
||||
if (!IsEventFromCurrentForm(sender))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (Form == null || !_itemContextMap.TryGetValue(args.ItemId, out RepoItemContext itemContext))
|
||||
if (!(e is RepoItemDetailRequestedEventArgs args))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
bool assigned = Form.TryAssignItemToCombineArea(itemContext);
|
||||
if (assigned)
|
||||
if (!_itemDescSeedMap.TryGetValue(args.ItemId, out ItemDescSeed seed))
|
||||
{
|
||||
Form.SetRepoItemSelected(args.ItemId, true);
|
||||
return;
|
||||
}
|
||||
|
||||
GameEntry.UIRouter.OpenUI(UIFormType.ItemDescForm, new ItemDescFormRawData
|
||||
{
|
||||
Title = seed.Title,
|
||||
TypeText = seed.TypeText,
|
||||
Description = string.Empty,
|
||||
Price = 0,
|
||||
TargetPos = args.TargetPos,
|
||||
Tags = CloneTags(seed.Tags)
|
||||
});
|
||||
}
|
||||
|
||||
private void OnRepoItemDragEnded(object sender, GameEventArgs e)
|
||||
{
|
||||
if (!IsEventFromCurrentForm(sender))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(e is RepoItemDragEndedEventArgs args))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (Form == null || !_itemContextMap.ContainsKey(args.ItemId))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Form.SetRepoItemSelected(args.ItemId, args.Assigned);
|
||||
}
|
||||
|
||||
private void OnCombineSlotClicked(object sender, GameEventArgs e)
|
||||
{
|
||||
if (!IsEventFromCurrentForm(sender))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(e is CombineSlotClickedEventArgs args))
|
||||
{
|
||||
return;
|
||||
@@ -207,5 +351,43 @@ namespace GeometryTD.UI
|
||||
Form.SetRepoItemSelected(removedItemId, false);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnRepoFormReturn(object sender, GameEventArgs e)
|
||||
{
|
||||
if (!IsEventFromCurrentForm(sender) || !(e is RepoFormReturnEventArgs))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (Form == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this.CloseUI();
|
||||
}
|
||||
|
||||
private bool IsEventFromCurrentForm(object sender)
|
||||
{
|
||||
if (Form == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ReferenceEquals(sender, Form))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (sender is Component component)
|
||||
{
|
||||
RepoForm ownerForm = component.GetComponentInParent<RepoForm>();
|
||||
return ownerForm == Form;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user