chore: 去除部分已不再使用的UI代码

This commit is contained in:
2026-07-17 14:22:33 +08:00
parent e20b499492
commit 2dcfeec938
20 changed files with 7 additions and 417 deletions
-8
View File
@@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 5010337b422cfa74ea2d2939e762693e
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
-65
View File
@@ -1,65 +0,0 @@
using System;
using AibisDream.Utility;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Localization.Components;
namespace AibisDream
{
/// <summary>
/// 表单项父类
/// </summary>
public abstract class AbsFormItem : MonoBehaviour
{
#region
public string prop;
public string label;
public abstract FieldType FieldType { get; }
#endregion
#region
private LocalizeStringEvent _labelRef;
public UnityEvent<string, string> OnValueChanged;
#endregion
private void Awake()
{
InitItem();
}
/// <summary>
/// 初始化FormItem
/// </summary>
private void InitItem()
{
// label设置
_labelRef = transform.Find("Label").GetComponent<LocalizeStringEvent>();
_labelRef.SetTable(ConstRef.UITextTable);
_labelRef.SetEntry(label);
// field设置
InitField();
}
protected abstract void InitField();
public abstract void SetValue(string value);
}
public enum FieldType
{
Input,
Slider,
Select,
Dropdown
}
[Serializable]
public struct UIFormOption
{
public string prop;
public string label;
}
}
@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: dd06484c1f627d249ad5a16558c9cdb9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
-32
View File
@@ -1,32 +0,0 @@
using TMPro;
namespace AibisDream
{
public class DropdownItem : AbsFormItem
{
public override FieldType FieldType => FieldType.Dropdown;
private TMP_Dropdown _dropdown;
protected override void InitField()
{
// 获取索引
_dropdown = GetComponentInChildren<TMP_Dropdown>(true);
// 注册事件
_dropdown.onValueChanged.AddListener(OnSelectChanged);
}
public override void SetValue(string value)
{
var target = _dropdown.options.FindIndex(item => item.text == value);
_dropdown.value = target;
}
private void OnSelectChanged(int value)
{
// 序号转字符串
var strValue = _dropdown.options[value].text;
OnValueChanged?.Invoke(prop, strValue);
}
}
}
@@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 39f0dc8bcf2641458cf3f8726add30f9
timeCreated: 1744702543
-15
View File
@@ -1,15 +0,0 @@
namespace AibisDream
{
/// <summary>
/// 表单接口。
/// 表单Root主要承担数据逻辑功能
/// 1. 修改表单数据时对应改动
/// 2. 从配置文件读取表单数据对应改动
/// 3. 表单初始化
/// </summary>
public interface IUIForm
{
public void OnItemChanged(string propName, string value);
public void UpdateForm();
}
}
-3
View File
@@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 7e80043371ab4923944ceda3823424b9
timeCreated: 1744619745
-68
View File
@@ -1,68 +0,0 @@
using System;
using AibisDream.Utility;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace AibisDream
{
public class LanguageItem : AbsFormItem
{
public override FieldType FieldType => FieldType.Select;
#region
private TMP_Text _showText;
private Button _leftBtn;
private Button _rightBtn;
#endregion
#region
[Header("可选项")]
public UIFormOption[] options;
private int _curIdx;
#endregion
protected override void InitField()
{
var field = transform.Find("Field");
_showText = field.Find("ShowText").GetComponent<TMP_Text>();
_leftBtn = field.Find("Left Btn").GetComponent<Button>();
_rightBtn = field.Find("Right Btn").GetComponent<Button>();
_leftBtn.onClick.AddListener(LeftRoll);
_rightBtn.onClick.AddListener(RightRoll);
}
public override void SetValue(string value)
{
var idx = Array.FindIndex(options, item => item.prop == value);
if (idx < 0)
{
Debug.LogError($"{prop} setting value error");
}
_curIdx = idx;
_showText.text = options[idx].label;
}
private void LeftRoll()
{
_curIdx = CommonUtil.LoopStep(_curIdx, 0, options.Length - 1);
_showText.text = options[_curIdx].label;
OnValueChanged?.Invoke(prop, options[_curIdx].prop);
}
private void RightRoll()
{
_curIdx = CommonUtil.LoopStep(_curIdx, 0, options.Length - 1, -1);
_showText.text = options[_curIdx].label;
OnValueChanged?.Invoke(prop, options[_curIdx].prop);
}
}
}
@@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: ae7f07f0b7da4a119b731f409ebbfeda
timeCreated: 1745478466
-51
View File
@@ -1,51 +0,0 @@
using UnityEngine;
namespace AibisDream
{
public class SettingForm : MonoBehaviour, IUIForm
{
#region
private AbsFormItem[] _formItems;
#endregion
public void Init()
{
// 获取索引
_formItems = GetComponentsInChildren<AbsFormItem>();
UpdateForm();
// 绑定变化
foreach (var formItem in _formItems)
{
formItem.OnValueChanged.AddListener(OnItemChanged);
}
}
public void UnInit()
{
// 绑定变化
foreach (var formItem in _formItems)
{
formItem.OnValueChanged.RemoveAllListeners();
}
}
public void OnItemChanged(string propName, string value)
{
SettingLoader.Instance.Write(propName, value);
}
public void UpdateForm()
{
var settingDict = SettingLoader.Instance.ReadAll();
foreach (var formItem in _formItems)
{
if (settingDict.TryGetValue(formItem.prop, out var value))
{
formItem.SetValue(value);
}
}
}
}
}
@@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 6564f6671e32475c981a8c3c1ca63ffd
timeCreated: 1744622926
-79
View File
@@ -1,79 +0,0 @@
using System.Linq;
using AibisDream.SaveSystem;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace AibisDream.UI
{
public class SavesPanel : MonoBehaviour, IUIPanel
{
public bool IsOpen => gameObject.activeSelf;
public bool IsCloseable => true;
#region
public Button buttonPrefab;
public Transform buttonParent;
#endregion
#region
public void Show()
{
InitLevelBtn();
gameObject.SetActive(true);
RegisterButton();
}
public void Hide()
{
gameObject.SetActive(false);
UnRegisterButton();
}
private void RegisterButton()
{
var returnBtn = transform.Find("Return").GetComponent<Button>();
returnBtn.onClick.AddListener(() => UIManager.Instance.HidePanel<SavesPanel>());
}
private void UnRegisterButton()
{
var returnBtn = transform.Find("Return").GetComponent<Button>();
returnBtn.onClick.RemoveAllListeners();
}
#endregion
private void InitLevelBtn()
{
// 清空旧按钮
foreach (Transform child in buttonParent)
{
Destroy(child.gameObject);
}
var slots = SlotManager.GetSlotViewModels()
.Where(slot => !slot.IsEmpty)
.OrderByDescending(slot => slot.SavedAt)
.ToArray();
foreach (var slot in slots)
{
var button = Instantiate(buttonPrefab, buttonParent);
var label = string.IsNullOrEmpty(slot.SceneSoName)
? $"Slot {slot.SlotIndex}"
: slot.SceneSoName;
button.GetComponentInChildren<TMP_Text>().text = label;
var slotIndex = slot.SlotIndex;
button.onClick.AddListener(() => OnSlotSelected(slotIndex));
}
}
private void OnSlotSelected(int slotIndex)
{
gameObject.SetActive(false);
GameManager.Instance.StartWithSlot(slotIndex);
}
}
}
@@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: bdd86c19be1449ca9e2783eb714fb8ff
timeCreated: 1745572533
-62
View File
@@ -1,62 +0,0 @@
using System.Linq;
using AibisDream.SaveSystem;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace AibisDream
{
public class SaveFileUIController : MonoBehaviour
{
#region
public Button buttonPrefab;
public Transform buttonParent;
public Button returnButton;
#endregion
private void Start()
{
returnButton.onClick.AddListener(HideSaveFileUI);
}
public void ShowSaveFileUI()
{
// 清空旧按钮
foreach (Transform child in buttonParent)
{
Destroy(child.gameObject);
}
var slots = SlotManager.GetSlotViewModels()
.Where(slot => !slot.IsEmpty)
.OrderByDescending(slot => slot.SavedAt)
.ToArray();
foreach (var slot in slots)
{
var button = Instantiate(buttonPrefab, buttonParent);
var label = string.IsNullOrEmpty(slot.SceneSoName)
? $"Slot {slot.SlotIndex}"
: slot.SceneSoName;
button.GetComponentInChildren<TMP_Text>().text = label;
var slotIndex = slot.SlotIndex;
button.onClick.AddListener(() => OnSlotSelected(slotIndex));
}
gameObject.SetActive(true);
}
private void OnSlotSelected(int slotIndex)
{
gameObject.SetActive(false);
GameManager.Instance.StartWithSlot(slotIndex);
}
private void HideSaveFileUI()
{
gameObject.SetActive(false);
}
}
}
@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: a351e509c8dd5944f9e6406f59ea5c0b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -205,4 +205,11 @@ namespace AibisDream.UI
Application.Quit();
}
}
[Serializable]
public struct UIFormOption
{
public string prop;
public string label;
}
}