迭代centermessageUI 和 cityupgradeUI

This commit is contained in:
kawagiri 2025-08-22 20:21:24 +08:00
parent 653797096f
commit 74c84f3bcf
15 changed files with 576 additions and 59 deletions

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 7b4e15b435b4f244ca61a3c95d21b241
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -729,6 +729,7 @@ GameObject:
- component: {fileID: 179623703747832089}
- component: {fileID: 1664363060810930500}
- component: {fileID: 5427348556757225811}
- component: {fileID: 6766434932280331124}
m_Layer: 5
m_Name: Explorer
m_TagString: Untagged
@ -892,6 +893,34 @@ MonoBehaviour:
GridMiscActionType: 0
SkillType: 0
TechType: 0
--- !u!114 &6766434932280331124
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1955999733545505482}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fc3fe06d78ddc52449aa4356fa3bf08b, type: 3}
m_Name:
m_EditorClassIdentifier:
_choiceId:
ActionType: 7
WonderType: 0
ResourceType: 0
FeatureType: 0
TerrainType: 0
UnitType: 0
GiantType: 0
UnitLevel: 0
Vegetation: 0
UnitActionType: 0
CityLevelUpActionType: 1
GridMiscActionType: 0
SkillType: 0
TechType: 0
DescriptionText: {fileID: 0}
--- !u!1 &2352317997463004223
GameObject:
m_ObjectHideFlags: 0
@ -907,6 +936,7 @@ GameObject:
- component: {fileID: 8293559020770323045}
- component: {fileID: 7905373770668785787}
- component: {fileID: 8022617277733720869}
- component: {fileID: 5239625121579663611}
m_Layer: 5
m_Name: Workshop
m_TagString: Untagged
@ -1073,6 +1103,34 @@ MonoBehaviour:
GridMiscActionType: 0
SkillType: 0
TechType: 0
--- !u!114 &5239625121579663611
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2352317997463004223}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fc3fe06d78ddc52449aa4356fa3bf08b, type: 3}
m_Name:
m_EditorClassIdentifier:
_choiceId:
ActionType: 7
WonderType: 0
ResourceType: 0
FeatureType: 0
TerrainType: 0
UnitType: 0
GiantType: 0
UnitLevel: 0
Vegetation: 0
UnitActionType: 0
CityLevelUpActionType: 2
GridMiscActionType: 0
SkillType: 0
TechType: 0
DescriptionText: {fileID: 0}
--- !u!1 &2440790000169401958
GameObject:
m_ObjectHideFlags: 0
@ -1088,7 +1146,7 @@ GameObject:
- component: {fileID: 6899856380688153074}
- component: {fileID: 4576469804986340307}
- component: {fileID: 946540800059744040}
- component: {fileID: 1210238557538825679}
- component: {fileID: 1212099728357589053}
m_Layer: 5
m_Name: UIInteractionCityUpgrade
m_TagString: Untagged
@ -1214,7 +1272,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
_Animator: {fileID: 4576469804986340307}
_ActionOnDisable: 0
--- !u!114 &1210238557538825679
--- !u!114 &1212099728357589053
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
@ -1223,11 +1281,20 @@ MonoBehaviour:
m_GameObject: {fileID: 2440790000169401958}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 0ad50f81b1d25c441943c37a89ba23f6, type: 3}
m_Script: {fileID: 11500000, guid: 4f24574c90e45f541b975ffb75bbe24a, type: 3}
m_Name:
m_EditorClassIdentifier:
_Animator: {fileID: 4576469804986340307}
_ActionOnDisable: 0
_showAnimationClip: {fileID: 0}
_hideAnimationClip: {fileID: 0}
AllItems:
- {fileID: 5239625121579663611}
- {fileID: 6766434932280331124}
- {fileID: 8758969514097255503}
- {fileID: 5915624091061072728}
- {fileID: 3861199511113104094}
- {fileID: 7270620588349160400}
- {fileID: 4746585983808587810}
- {fileID: 1370386261222199616}
--- !u!1 &2777827650609384085
GameObject:
m_ObjectHideFlags: 0
@ -1318,6 +1385,7 @@ GameObject:
- component: {fileID: 171814781602569886}
- component: {fileID: 2815935363887086481}
- component: {fileID: 6000320917261842701}
- component: {fileID: 1370386261222199616}
m_Layer: 5
m_Name: Territory
m_TagString: Untagged
@ -1481,6 +1549,34 @@ MonoBehaviour:
GridMiscActionType: 0
SkillType: 0
TechType: 0
--- !u!114 &1370386261222199616
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3090026573267593533}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fc3fe06d78ddc52449aa4356fa3bf08b, type: 3}
m_Name:
m_EditorClassIdentifier:
_choiceId:
ActionType: 7
WonderType: 0
ResourceType: 0
FeatureType: 0
TerrainType: 0
UnitType: 0
GiantType: 0
UnitLevel: 0
Vegetation: 0
UnitActionType: 0
CityLevelUpActionType: 5
GridMiscActionType: 0
SkillType: 0
TechType: 0
DescriptionText: {fileID: 0}
--- !u!1 &3807881421756270137
GameObject:
m_ObjectHideFlags: 0
@ -2471,6 +2567,7 @@ GameObject:
- component: {fileID: 732495215277873303}
- component: {fileID: 8201888774438323051}
- component: {fileID: 6890372612214105382}
- component: {fileID: 8758969514097255503}
m_Layer: 5
m_Name: Park
m_TagString: Untagged
@ -2639,6 +2736,34 @@ MonoBehaviour:
GridMiscActionType: 0
SkillType: 0
TechType: 0
--- !u!114 &8758969514097255503
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5305844991861064726}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fc3fe06d78ddc52449aa4356fa3bf08b, type: 3}
m_Name:
m_EditorClassIdentifier:
_choiceId:
ActionType: 7
WonderType: 0
ResourceType: 0
FeatureType: 0
TerrainType: 0
UnitType: 0
GiantType: 0
UnitLevel: 0
Vegetation: 0
UnitActionType: 0
CityLevelUpActionType: 7
GridMiscActionType: 0
SkillType: 0
TechType: 0
DescriptionText: {fileID: 0}
--- !u!1 &5556378023473229278
GameObject:
m_ObjectHideFlags: 0
@ -3614,6 +3739,7 @@ GameObject:
- component: {fileID: 2047256478195873090}
- component: {fileID: 1606591893298160763}
- component: {fileID: 5600175531664866408}
- component: {fileID: 5915624091061072728}
m_Layer: 5
m_Name: Giant
m_TagString: Untagged
@ -3777,6 +3903,34 @@ MonoBehaviour:
GridMiscActionType: 0
SkillType: 0
TechType: 0
--- !u!114 &5915624091061072728
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6856249948862058663}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fc3fe06d78ddc52449aa4356fa3bf08b, type: 3}
m_Name:
m_EditorClassIdentifier:
_choiceId:
ActionType: 7
WonderType: 0
ResourceType: 0
FeatureType: 0
TerrainType: 0
UnitType: 0
GiantType: 0
UnitLevel: 0
Vegetation: 0
UnitActionType: 0
CityLevelUpActionType: 8
GridMiscActionType: 0
SkillType: 0
TechType: 0
DescriptionText: {fileID: 0}
--- !u!1 &7142802923757097043
GameObject:
m_ObjectHideFlags: 0
@ -4241,6 +4395,7 @@ GameObject:
- component: {fileID: 7097354990372682421}
- component: {fileID: 422609080679572455}
- component: {fileID: 5827356047747904015}
- component: {fileID: 4746585983808587810}
m_Layer: 5
m_Name: Population
m_TagString: Untagged
@ -4404,6 +4559,34 @@ MonoBehaviour:
GridMiscActionType: 0
SkillType: 0
TechType: 0
--- !u!114 &4746585983808587810
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7801732432218806299}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fc3fe06d78ddc52449aa4356fa3bf08b, type: 3}
m_Name:
m_EditorClassIdentifier:
_choiceId:
ActionType: 7
WonderType: 0
ResourceType: 0
FeatureType: 0
TerrainType: 0
UnitType: 0
GiantType: 0
UnitLevel: 0
Vegetation: 0
UnitActionType: 0
CityLevelUpActionType: 6
GridMiscActionType: 0
SkillType: 0
TechType: 0
DescriptionText: {fileID: 0}
--- !u!1 &7815426397817380702
GameObject:
m_ObjectHideFlags: 0
@ -4569,6 +4752,7 @@ GameObject:
- component: {fileID: 6674180198033275682}
- component: {fileID: 2277877380993687416}
- component: {fileID: 8008190361801103705}
- component: {fileID: 7270620588349160400}
m_Layer: 5
m_Name: Stars
m_TagString: Untagged
@ -4732,6 +4916,34 @@ MonoBehaviour:
GridMiscActionType: 0
SkillType: 0
TechType: 0
--- !u!114 &7270620588349160400
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8518822767993783989}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fc3fe06d78ddc52449aa4356fa3bf08b, type: 3}
m_Name:
m_EditorClassIdentifier:
_choiceId:
ActionType: 7
WonderType: 0
ResourceType: 0
FeatureType: 0
TerrainType: 0
UnitType: 0
GiantType: 0
UnitLevel: 0
Vegetation: 0
UnitActionType: 0
CityLevelUpActionType: 4
GridMiscActionType: 0
SkillType: 0
TechType: 0
DescriptionText: {fileID: 0}
--- !u!1 &8567245617163683120
GameObject:
m_ObjectHideFlags: 0
@ -4822,6 +5034,7 @@ GameObject:
- component: {fileID: 4040704959155090658}
- component: {fileID: 8920159512992411734}
- component: {fileID: 4914894038503928918}
- component: {fileID: 3861199511113104094}
m_Layer: 5
m_Name: Wall
m_TagString: Untagged
@ -4985,6 +5198,34 @@ MonoBehaviour:
GridMiscActionType: 0
SkillType: 0
TechType: 0
--- !u!114 &3861199511113104094
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8853954931205301936}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fc3fe06d78ddc52449aa4356fa3bf08b, type: 3}
m_Name:
m_EditorClassIdentifier:
_choiceId:
ActionType: 7
WonderType: 0
ResourceType: 0
FeatureType: 0
TerrainType: 0
UnitType: 0
GiantType: 0
UnitLevel: 0
Vegetation: 0
UnitActionType: 0
CityLevelUpActionType: 3
GridMiscActionType: 0
SkillType: 0
TechType: 0
DescriptionText: {fileID: 0}
--- !u!1 &8869998957290082949
GameObject:
m_ObjectHideFlags: 0

View File

@ -1,19 +1,19 @@
using Logic.Action;
using UI.HintUI;
using UnityEngine;
namespace TH1_Core.Events
{
//---------------------------------------- Hint 相关的事件 -----------------------------
public struct ShowHintEvent
{
// CHANGED: 不再直接传递文本,而是传递一个数据提供者
public HintDataProvider DataProvider;
public Vector2 Position;
}
public struct HideHintEvent { }
//Hint的母对象消失的时候自身也消失
public struct HintTriggerDisabledEvent
{
/// <summary>
@ -22,7 +22,7 @@ namespace TH1_Core.Events
/// </summary>
public HintDataProvider DataProvider;
}
//---------------------------------------- UIAnnounce 相关的时间 -----------------------------
//---------------------------------------- UIAnnounce 相关的事件 -----------------------------
public enum UIAnnounceMajorEventType
{
@ -40,7 +40,18 @@ namespace TH1_Core.Events
public int Param2;
}
public struct ShowUIInteractionCityUpgrade
{
//Param1 = cid Param2 = cityLevel
public int CityId;
public int CityLevel;
}
public struct ChoiceUIInteractionCityUpgrade
{
public int CityId;
public CommonActionId ChoiceActionId;
}
public class UIEvents
{

View File

@ -81,7 +81,7 @@ namespace TH1_Core.Managers
TopBarUI = new TopBarUI(_main,_mapData);
BottomInfoUI = new BottomInfoUI(_main,_mapData);
BottomBarUI = new BottomBarUI(_main);
CenterMessageUI = new CenterMessageUI(_main,_mapData);
//CenterMessageUI = new CenterMessageUI(_main,_mapData);
TechTreeUI = new TechTreeUI();
CityUpgradeActionUI = new CityUpgradeActionUI(_main,_mapData);
DebugUI = new DebugUI(_main,_mapData);
@ -92,7 +92,7 @@ namespace TH1_Core.Managers
{
if(_gameInitReady)
{
CenterMessageUI.Update();
//CenterMessageUI.Update();
CityUpgradeActionUI.Update();
BottomBarUI.Update();
BottomInfoUI.Update();

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: dd92d4982fb9be644968c2135c2f5c63
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,94 @@
// 文件位置建议: Assets/Scripts/TH1_UI/Controller/UIAnnounceMajorEventController.cs
using Logic.Action;
using TH1_Core.Events;
using TH1_Core.Managers;
using TH1_UI.Controller.Base;
using TH1_UI.View.Interaction;
using UnityEngine;
// 确保这里引用了View脚本的命名空间
namespace TH1_UI.Controller.Interaction
{
/// <summary>
/// 重大事件公告界面的控制器。
/// 它的职责是处理玩家相遇、玩家被消灭之类的宣告
/// </summary>
public class UIInteractionCityUpgradeController : ViewController<UIInteractionCityUpgradeView> // 泛型参数是对应的View脚本
{
/// <summary>
/// ✅ 【新增】一个空的构造函数,以满足 ViewControllerManager._CreateView 的 new() 泛型约束。
/// </summary>
public UIInteractionCityUpgradeController() { }
protected override void RegisterEventCallback()
{
base.RegisterEventCallback();
if (WindowScript != null)
{
WindowScript.OnChoiceMade += _OnChoiceMadeHandler;
}
}
protected override void UnregisterEventCallback()
{
if (WindowScript != null)
{
WindowScript.OnChoiceMade -= _OnChoiceMadeHandler;
}
base.UnregisterEventCallback();
}
protected override void OnOpen()
{
base.OnOpen();
// 检查暂存的参数是否存在且类型正确
if (_openParameter is ShowUIInteractionCityUpgrade evt)
{
// 使用接收到的数据设置UI内容
if (WindowScript != null)
{
//Param1 = cid Param2 = cityLv
WindowScript.SetContent(evt.CityId, evt.CityLevel);
}
}
else
{
// 如果没有参数或参数类型不符,可以提供默认内容或打印警告
Debug.LogWarning("[UIAnnounceMajorEventController] Opened without valid parameters.");
if (WindowScript != null)
{
//WindowScript.SetContent("警告", "内容未提供");
}
}
}
private void _OnChoiceMadeHandler(CommonActionId choiceId)
{
if (WindowScript != null)
{
var eventData = new ChoiceUIInteractionCityUpgrade
{
CityId = WindowScript.CurrentCityID,
// 🔄 [修改] 字段赋值
ChoiceActionId = choiceId
};
EventManager.Publish(eventData);
// 🔄 [修改] 更新日志输出
Debug.Log($"玩家对城市 {eventData.CityId} 做出了选择, 选项ID: {eventData.ChoiceActionId}. 事件已发布。");
}
Close();
}
void _OnBtnCloseClick()
{
Close();
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4a64f4cef039fcd46bd4a0974fbf81b9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -10,5 +10,6 @@ namespace TH1_UI.Core
// ✅ 【新增】为新的UI添加资源名常量
public static readonly string ViewAnnounceMajorEvent = "UIAnnounceMajorEvent";
public static readonly string ViewInteractionCityUpgrade = "UIInteractionCityUpgrade";
}
}

View File

@ -3,6 +3,8 @@
using System.Collections.Generic;
using TH1_UI.Controller.Announce;
using TH1_UI.Controller.Base;
using TH1_UI.Controller.Interaction;
using TH1_UI.View.Announce;
namespace TH1_UI.Core
{
@ -20,7 +22,8 @@ namespace TH1_UI.Core
//public static UIBlankTouchArea BlankTouchArea { get { return _blankTouchArea; } }
public static Dictionary<string, IViewControllerInterface> ViewDict => _viewDict;
// ✅【新增】1. 添加新UI的公共静态属性保持风格统一
public static UIAnnounceMajorEventController UIAnnounceMajorEventController { get { return _announceMajorEventView; } }
public static UIAnnounceMajorEventController UIAnnounceMajorEventController { get { return _announceMajorEventController; } }
public static UIInteractionCityUpgradeController UIInterationCityUpgradeController { get { return _interactionCityUpgradeController; } }
//
// ================================================= Announce ================================================================
@ -47,22 +50,23 @@ namespace TH1_UI.Core
//
//DebugLogManager.Instance.OnOpenDebugViewCallback = _OnOpenDebugView;
}
//
//创建所有view contorller实例
static void _CreateAllViewControllers()
{
// ✅【新增】3. 在创建列表里按照你的项目风格创建新的Controller实例
// ================================================= Announce ================================================================
_announceMajorEventView = _CreateView<UIAnnounceMajorEventController>("Announce", UIResourceName.ViewAnnounceMajorEvent, ViewDestroyDomain.None);
_announceMajorEventController = _CreateView<UIAnnounceMajorEventController>("Announce", UIResourceName.ViewAnnounceMajorEvent, ViewDestroyDomain.None);
// ================================================= Interaction ================================================================
_interactionCityUpgradeController = _CreateView<UIInteractionCityUpgradeController>("Interaction", UIResourceName.ViewInteractionCityUpgrade, ViewDestroyDomain.None);
// ================================================= Other ================================================================
//_adventureView = _CreateView<AdventureViewController>("UIAdv", UIResourceName.View_Adventure, ViewDestroyDomain.Adventure | ViewDestroyDomain.Battle | ViewDestroyDomain.Home);
//_flowerSelectView = _CreateView<AdvFlowerSelectViewController>("UIAdv", UIResourceName.View_AdvFlowerSelect, ViewDestroyDomain.Battle | ViewDestroyDomain.Home);
// ================================================= 通用 ================================================================
//_comSkipView = _CreateView<ComSkipViewController>("Common", UIResourceName.View_ComSkipView, ViewDestroyDomain.Battle | ViewDestroyDomain.Home);
}
@ -141,54 +145,16 @@ namespace TH1_UI.Core
pair.Value.Destroy();
}
}
//
/*
public static void LateUpdate()
{
if (Input.touchCount > 0)
{
Touch touch = Input.GetTouch(Input.touchCount - 1);
if(touch.phase == TouchPhase.Began)
{
_touchDownTimmer = Time.realtimeSinceStartup;
}
else if (touch.phase == TouchPhase.Ended)
{
if(_touchDownTimmer > 0 && Time.realtimeSinceStartup-_touchDownTimmer <= VALUE_TouchClickDuration)
{
UITouchInstance.Instance.Start(touch.position);
}
GlobalEventManager.Instance.Invoke(EventID.OnTouchEnd, new Vector3(touch.position.x, touch.position.y, 0));
_touchDownTimmer = 0;
}
}
else
{
if (Input.GetMouseButtonDown(0))
{
_touchDownTimmer = Time.realtimeSinceStartup;
}
else if (Input.GetMouseButtonUp(0))
{
if (_touchDownTimmer > 0 && Time.realtimeSinceStartup - _touchDownTimmer <= VALUE_TouchClickDuration)
{
UITouchInstance.Instance.Start(Input.mousePosition);
}
GlobalEventManager.Instance.Invoke(EventID.OnTouchEnd, Input.mousePosition);
_touchDownTimmer = 0;
}
}
}*/
//
public static void End()
{
//DebugLogManager.Instance.OnOpenDebugViewCallback = null;
}
// ✅【新增】2. 添加新UI的私有静态字段
private static UIAnnounceMajorEventController _announceMajorEventView = null;
private static UIAnnounceMajorEventController _announceMajorEventController = null;
private static UIInteractionCityUpgradeController _interactionCityUpgradeController = null;
static Dictionary<string, IViewControllerInterface> _viewDict = new Dictionary<string, IViewControllerInterface>();
/*
static UIBlankTouchArea _blankTouchArea;

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 611bc901d88bc8d469d786a34496e4dd
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,61 @@
// 文件位置: Assets/Scripts/TH1_UI/View/Announce/UIInteractionCityUpgradeItem.cs
using System;
using Logic.Action;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
// ✅ [新增] 引用 CommonActionId 的命名空间
namespace TH1_UI.View.Interaction
{
[RequireComponent(typeof(Button))]
public class UIInteractionCityUpgradeItem : MonoBehaviour
{
[Header("配置")]
[Tooltip("在Editor中设置此选项的唯一ID")]
// 🔄 [修改] 类型从 int 改为 CommonActionId命名从 _choiceID 改为 _choiceId
[SerializeField] private CommonActionId _choiceId;
[Header("组件引用")]
public TextMeshProUGUI DescriptionText;
private Button _button;
// 🔄 [修改] Action的泛型参数改为 CommonActionId
private Action<CommonActionId> _onClickCallback;
// 🔄 [修改] 公共属性的类型和命名
public CommonActionId ChoiceId => _choiceId;
private void Awake()
{
_button = GetComponent<Button>();
_button.onClick.AddListener(HandleClick);
}
/// <summary>
/// 初始化这个选项按钮
/// </summary>
// 🔄 [修改] 回调参数的类型改为 Action<CommonActionId>
public void Setup(string description, Action<CommonActionId> onClickCallback)
{
_onClickCallback = onClickCallback;
if (DescriptionText != null)
{
DescriptionText.text = description;
}
}
private void HandleClick()
{
// 🔄 [修改] 调用回调时传入自身的 _choiceId
_onClickCallback?.Invoke(_choiceId);
}
private void OnDestroy()
{
_button.onClick.RemoveListener(HandleClick);
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: fc3fe06d78ddc52449aa4356fa3bf08b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,86 @@
using System;
using System.Collections.Generic;
using Logic.Action;
using RuntimeData;
using TH1_UI.View.Announce;
using UnityEngine;
namespace TH1_UI.View.Interaction
{
public class UIInteractionCityUpgradeView : Base.View
{
[Header("Interaction Items")]
[Tooltip("在Editor中将预制件内所有预置的Item拖拽到这里")]
public List<UIInteractionCityUpgradeItem> AllItems;
//当选择了一个选项item后执行的action
public Action<CommonActionId> OnChoiceMade;
public int CurrentCityID { get; private set; }
private Material _grayScaleMat;
private Dictionary<CommonActionId, UIInteractionCityUpgradeItem> _itemMap;
public ViDelegateAssisstant.Dele OnItemClick;
protected override void InitStart()
{
base.InitStart();
//step #2 建立actionId到每一个item选项所挂在的脚本的关联
if (AllItems == null) return;
_itemMap = new Dictionary<CommonActionId, UIInteractionCityUpgradeItem>();
foreach (var item in AllItems)
_itemMap.TryAdd(item.ChoiceId, item);
}
public void SetContent(int cid, int cityLevel)
{
CurrentCityID = cid;
//step #1 获取当前citylevel所有可能得选项
var validChoices = GetValidChoices(cid, cityLevel);
//step #2 将可能得选项显示true没有的选项显示false
foreach (var item in AllItems)
{
item.gameObject.SetActive(validChoices.TryGetValue(item.ChoiceId,out var _));
}
}
private HashSet<CommonActionId> GetValidChoices(int cid, int level)
{
var ret = new HashSet<CommonActionId>();
var dict = ActionLogicFactory.GetActionLogicDict();
foreach (var actionId in dict.Keys)
{
if (actionId.ActionType != CommonActionType.CityLevelUpAction) continue;
switch (actionId.CityLevelUpActionType)
{
case CityLevelUpActionType.Explorer: if (level == 2) ret.Add(actionId); break;
case CityLevelUpActionType.Workshop: if (level == 2) ret.Add(actionId); break;
case CityLevelUpActionType.CityWall: if (level == 3) ret.Add(actionId); break;
case CityLevelUpActionType.CityWealth: if (level == 3) ret.Add(actionId); break;
case CityLevelUpActionType.Expand: if (level == 4) ret.Add(actionId); break;
case CityLevelUpActionType.Population: if (level == 4) ret.Add(actionId); break;
case CityLevelUpActionType.Park: if (level > 4) ret.Add(actionId); break;
case CityLevelUpActionType.BigGuy: if (level > 4) ret.Add(actionId); break;
}
}
return ret;
}
/// <summary>
/// 当任何一个选项按钮被点击时所有Item都指向此回调
/// </summary>
// 🔄 [修改] 参数类型和命名
private void HandleItemClicked(CommonActionId choiceId)
{
OnChoiceMade?.Invoke(choiceId);
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4f24574c90e45f541b975ffb75bbe24a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: