(client) feat:健康给予,路径优化,结算界面,商店界面 (#60)

Co-authored-by: m0_75251201 <m0_75251201@noreply.gitcode.com>
Reviewed-on: http://47.107.252.169:3000/Roguelite-Game-Developing-Team/Gen_Hack-and-Slash-Roguelite/pulls/60
This commit is contained in:
2025-10-10 14:08:23 +08:00
parent 9a797479ff
commit 16b49f3d3a
1900 changed files with 114053 additions and 34157 deletions

View File

@@ -1,8 +1,13 @@
using System;
using Base;
using Data; // 确保 Data 命名空间包含 DefBase, CharacterDef, MonsterDef, BuildingDef, ItemDef, EventDef
using Data;
using Managers;
using Prefab;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using Utils;
// 确保 Data 命名空间包含 DefBase, CharacterDef, MonsterDef, BuildingDef, ItemDef, EventDef
namespace UI
{
@@ -12,10 +17,10 @@ namespace UI
public EntityPlacementUI entityPlacementUI;
public Prefab.TextPrefab textTemplate;
public Prefab.ButtonPrefab buttonTemplate;
public TextPrefab textTemplate;
public ButtonPrefab buttonTemplate;
private void Start()
{
Init();
@@ -25,10 +30,16 @@ namespace UI
{
if (Setting.Instance.CurrentSettings.developerMode)
base.Show();
else
UIInputControl.Instance.Hide(this);
}
private void Init()
{
var layoutGroup = menuContent.GetComponent<GridLayoutGroup>();
if (layoutGroup)
layoutGroup.enabled = false;
InitReloadGameButton();
InitEvent();
InitStory();
@@ -37,8 +48,15 @@ namespace UI
InitBuilding();
InitItem();
InitWeapon();
if (layoutGroup)
{
layoutGroup.enabled = true;
LayoutRebuilder.ForceRebuildLayoutImmediate(menuContent.GetComponent<RectTransform>());
}
}
private void InitReloadGameButton()
{
var button = InstantiatePrefab(buttonTemplate, menuContent.transform);
@@ -47,19 +65,20 @@ namespace UI
}
/// <summary>
/// 通用的初始化定义按钮的方法。
/// 通用的初始化定义按钮的方法。
/// </summary>
/// <typeparam name="TDef">定义的类型,必须继承自 Data.DefBase。</typeparam>
/// <param name="titleLabel">菜单部分的标题。</param>
/// <param name="noDefMessage">当没有定义时显示的提示信息。</param>
/// <param name="buttonTextSelector">用于从 TDef 获取按钮显示文本的函数。</param>
/// <param name="buttonAction">点击按钮时执行的动作,传入对应的 TDef 对象。</param>
private void InitDefineButtons<TDef>(string titleLabel, string noDefMessage, System.Func<TDef, string> buttonTextSelector, System.Action<TDef> buttonAction) where TDef : Define
private void InitDefineButtons<TDef>(string titleLabel, string noDefMessage,
Func<TDef, string> buttonTextSelector, Action<TDef> buttonAction) where TDef : Define
{
var title = InstantiatePrefab(textTemplate, menuContent.transform);
title.Label = titleLabel;
var defList = Managers.DefineManager.Instance.QueryDefinesByType<TDef>();
var defList = DefineManager.Instance.QueryDefinesByType<TDef>();
if (defList == null || defList.Length == 0)
{
var noDefTitle = InstantiatePrefab(textTemplate, menuContent.transform);
@@ -85,19 +104,16 @@ namespace UI
"事件菜单",
"未定义任何事件",
def => string.IsNullOrEmpty(def.label) ? def.defName : def.label,
eventDef => { Managers.EventManager.Instance.Action(eventDef.defName); });
eventDef => { EventManager.Instance.Action(eventDef.defName); });
}
private void InitStory()
{
InitDefineButtons<StoryDef>(
"据泵菜单",
"剧本菜单",
"未定义任何剧本",
def => string.IsNullOrEmpty(def.label) ? def.defName : def.label,
eventDef =>
{
Managers.EventManager.Instance.PlayStory(eventDef.defName);
});
eventDef => { EventManager.Instance.PlayStory(eventDef.defName); });
}
private void InitCharacter()
@@ -135,6 +151,7 @@ namespace UI
def => def.label,
GeneratePickupCallback);
}
private void InitWeapon()
{
InitDefineButtons<WeaponDef>(
@@ -146,7 +163,7 @@ namespace UI
/// <summary>
/// 通用的实例化函数,返回实例化的预制件脚本组件。
/// 通用的实例化函数,返回实例化的预制件脚本组件。
/// </summary>
/// <typeparam name="T">预制件脚本的类型</typeparam>
/// <param name="prefab">要实例化的预制件</param>
@@ -167,61 +184,67 @@ namespace UI
var instantiatedComponent = instance.GetComponent<T>();
if (instantiatedComponent == null)
{
Debug.LogError($"Failed to get component of type {typeof(T).Name} from the instantiated prefab!");
}
return instantiatedComponent;
}
private void GenerateEntityCallback(EntityDef entityDef)
{
if(entityDef==null)
if (entityDef == null)
return;
entityPlacementUI.currentAction = () =>
{
Managers.EntityManager.Instance.GenerateCharacterEntity(Program.Instance.FocusedDimensionId, entityDef, Utils.MousePosition.GetWorldPosition());
EntityManager.Instance.GenerateCharacterEntity(Program.Instance.FocusedDimensionId, entityDef,
MousePosition.GetWorldPosition());
};
entityPlacementUI.Prompt = $"当前生成器:\n名称{entityDef.label}\n描述{entityDef.description}";
entityPlacementUI.snapEnabled = false;
UIInputControl.Instance.Show(entityPlacementUI);
}
private void GenerateMonsterEntityCallback(MonsterDef monsterDef)
{
if(monsterDef==null)
if (monsterDef == null)
return;
entityPlacementUI.currentAction = () =>
{
Managers.EntityManager.Instance.GenerateMonsterEntity(Program.Instance.FocusedDimensionId, monsterDef, Utils.MousePosition.GetWorldPosition());
EntityManager.Instance.GenerateMonsterEntity(Program.Instance.FocusedDimensionId, monsterDef,
MousePosition.GetWorldPosition());
};
entityPlacementUI.Prompt = $"当前生成器:\n名称{monsterDef.label}\n描述{monsterDef.description}";
entityPlacementUI.snapEnabled = false;
UIInputControl.Instance.Show(entityPlacementUI);
}
private void GenerateBuildingCallback(BuildingDef def)
{
if(def==null)
if (def == null)
return;
entityPlacementUI.currentAction = () =>
{
Managers.EntityManager.Instance.GenerateBuildingEntity(Program.Instance.FocusedDimensionId, def, Utils.MousePosition.GetSnappedWorldPosition());
EntityManager.Instance.GenerateBuildingEntity(Program.Instance.FocusedDimensionId, def,
MousePosition.GetSnappedWorldPosition());
};
entityPlacementUI.Prompt = $"当前生成器:\n名称{def.label}\n描述{def.description}";
entityPlacementUI.snapEnabled = true;
UIInputControl.Instance.Show(entityPlacementUI);
}
private void GeneratePickupCallback(ItemDef itemDef)
{
if(itemDef==null)
if (itemDef == null)
return;
entityPlacementUI.currentAction = () =>
{
Managers.EntityManager.Instance.GeneratePickupEntity(Program.Instance.FocusedDimensionId, itemDef, Utils.MousePosition.GetWorldPosition());
EntityManager.Instance.GeneratePickupEntity(Program.Instance.FocusedDimensionId, itemDef,
MousePosition.GetWorldPosition());
};
entityPlacementUI.Prompt = $"当前生成器:\n名称{itemDef.label}\n描述{itemDef.description}";
entityPlacementUI.snapEnabled = false;
UIInputControl.Instance.Show(entityPlacementUI);
}
public static void HotReload()
{
UIInputControl.Instance.HideAll();
@@ -229,4 +252,4 @@ namespace UI
SceneManager.LoadScene(0);
}
}
}
}