重构侧边栏菜单基类,修复bug

This commit is contained in:
ALIENJACK\alien 2025-01-07 20:11:11 +08:00
parent e2da8ce405
commit 2bd16a9125
13 changed files with 82 additions and 56 deletions

View File

@ -1,4 +1,4 @@
using AxibugEmuOnline.Client.ClientCore; using AxibugEmuOnline.Client.ClientCore;
using AxibugEmuOnline.Client.UI; using AxibugEmuOnline.Client.UI;
using DG.Tweening; using DG.Tweening;
using DG.Tweening.Core; using DG.Tweening.Core;
@ -9,7 +9,7 @@ using UnityEngine;
namespace AxibugEmuOnline.Client namespace AxibugEmuOnline.Client
{ {
/// <summary> /// <summary>
/// ąłž°ŃŐÉŤÉčÖĂUI /// 背景颜色设置UI
/// </summary> /// </summary>
public class UI_BgSettingItem_Color : MenuItem, IVirtualItem public class UI_BgSettingItem_Color : MenuItem, IVirtualItem
{ {
@ -34,7 +34,7 @@ namespace AxibugEmuOnline.Client
var color = Datacontext.CurrentColor; var color = Datacontext.CurrentColor;
Icon.GetMaterial().SetColor("_Color1", color.color1); Icon.GetMaterial().SetColor("_Color1", color.color1);
Icon.GetMaterial().SetColor("_Color2", color.color2); Icon.GetMaterial().SetColor("_Color2", color.color2);
SetBaseInfo("Ö÷ĚâÉŤ", "ÉčÖĂÖ÷ĚâÉŤ", color.Name); SetBaseInfo("主题色", "设置主题色", color.Name);
} }
public void SetDependencyProperty(object data) public void SetDependencyProperty(object data)
@ -58,8 +58,9 @@ namespace AxibugEmuOnline.Client
public class ColorOption : ExecuteMenu public class ColorOption : ExecuteMenu
{ {
public XMBColor Color; public XMBColor Color;
public override string Name => Color.Name;
public ColorOption(XMBColor color) : base(color.Name) public ColorOption(XMBColor color)
{ {
Color = color; Color = color;
} }

View File

@ -70,7 +70,9 @@ namespace AxibugEmuOnline.Client
{ {
private Filter m_filter; private Filter m_filter;
public Opt_CreatePreset(Filter filter) : base("创建滤镜预设", Resources.LoadAll<Sprite>("Icons/XMB-Icons/misc")[0]) public override string Name => "创建滤镜预设";
public override Sprite Icon => Resources.LoadAll<Sprite>("Icons/XMB-Icons/misc")[0];
public Opt_CreatePreset(Filter filter)
{ {
m_filter = filter; m_filter = filter;
} }
@ -101,7 +103,9 @@ namespace AxibugEmuOnline.Client
private OptionUI_MenuItem m_ui; private OptionUI_MenuItem m_ui;
private List<OptionMenu> m_menu; private List<OptionMenu> m_menu;
public Opt_Presets(Filter filter, FilterPreset preset) : base(preset.Name, null) public override string Name => m_preset.Name;
public Opt_Presets(Filter filter, FilterPreset preset)
{ {
m_filter = filter; m_filter = filter;
m_preset = preset; m_preset = preset;
@ -151,8 +155,8 @@ namespace AxibugEmuOnline.Client
public override bool Visible => m_param.ValueType.IsEnum || m_param.ValueType == typeof(float); public override bool Visible => m_param.ValueType.IsEnum || m_param.ValueType == typeof(float);
public override string Name => m_param.Name;
public Opt_ParamEditor(Filter filter, FilterEffect.EditableParamerter editParam, FilterPreset preset) public Opt_ParamEditor(Filter filter, FilterEffect.EditableParamerter editParam, FilterPreset preset)
: base(editParam.Name)
{ {
m_filter = filter; m_filter = filter;
m_param = editParam; m_param = editParam;
@ -179,8 +183,9 @@ namespace AxibugEmuOnline.Client
{ {
private Filter m_filter; private Filter m_filter;
private FilterPreset m_preset; private FilterPreset m_preset;
public override string Name => "删除预设";
public Opt_Delete(Filter filter, FilterPreset preset) : base("删除预设", null) public Opt_Delete(Filter filter, FilterPreset preset)
{ {
m_filter = filter; m_filter = filter;
m_preset = preset; m_preset = preset;

View File

@ -24,6 +24,8 @@ namespace AxibugEmuOnline.Client
public int Index { get; set; } public int Index { get; set; }
public bool IsFav { get; }
private RomLib m_romlib => App.nesRomLib; private RomLib m_romlib => App.nesRomLib;
private RomFile m_romfile; private RomFile m_romfile;

View File

@ -68,8 +68,9 @@ namespace AxibugEmuOnline.Client
public class OptMenu_Search : ExecuteMenu public class OptMenu_Search : ExecuteMenu
{ {
private RomListMenuItem m_romListUI; private RomListMenuItem m_romListUI;
public override string Name => "搜索";
public OptMenu_Search(RomListMenuItem romListUI, Sprite icon = null) : base("搜索", icon) public OptMenu_Search(RomListMenuItem romListUI)
{ {
m_romListUI = romListUI; m_romListUI = romListUI;
} }
@ -90,9 +91,10 @@ namespace AxibugEmuOnline.Client
{ {
private RomListMenuItem m_ui; private RomListMenuItem m_ui;
public override string Name => "显示全部";
public override bool Visible => !string.IsNullOrWhiteSpace(m_ui.SearchKey); public override bool Visible => !string.IsNullOrWhiteSpace(m_ui.SearchKey);
public OptMenu_ShowAll(RomListMenuItem romListUI, Sprite icon = null) : base("显示全部", icon) public OptMenu_ShowAll(RomListMenuItem romListUI)
{ {
m_ui = romListUI; m_ui = romListUI;
} }
@ -103,5 +105,30 @@ namespace AxibugEmuOnline.Client
m_ui.RefreshUI(); m_ui.RefreshUI();
} }
} }
public class OptMenu_Fav : ExecuteMenu
{
private RomListMenuItem m_romListUI;
private ThirdMenuRoot m_romListSub;
public override string Name
{
get
{
var isFav = (m_romListSub.GetItemUIByIndex(m_romListSub.SelectIndex) as RomItem).IsFav;
return isFav ? "收藏" : "取消收藏";
}
}
public OptMenu_Fav(RomListMenuItem romListUI)
{
m_romListUI = romListUI;
m_romListSub = m_romListUI.SubMenuItemGroup as ThirdMenuRoot;
}
public override void OnExcute(OptionUI optionUI, ref bool cancelHide)
{
}
}
} }
} }

View File

@ -8,8 +8,9 @@ namespace AxibugEmuOnline.Client
public class InGameUI_FilterSetting : ExpandMenu public class InGameUI_FilterSetting : ExpandMenu
{ {
private InGameUI m_gameUI; private InGameUI m_gameUI;
public override string Name => "滤镜";
public InGameUI_FilterSetting(InGameUI gameUI) : base("滤镜", null) public InGameUI_FilterSetting(InGameUI gameUI)
{ {
m_gameUI = gameUI; m_gameUI = gameUI;
} }
@ -26,12 +27,11 @@ namespace AxibugEmuOnline.Client
{ {
private RomFile m_rom; private RomFile m_rom;
public override string Name => "取消滤镜";
public override bool IsApplied => App.settings.Filter.GetFilterSetting(m_rom).filter == null; public override bool IsApplied => App.settings.Filter.GetFilterSetting(m_rom).filter == null;
public FilterNone(RomFile rom) : base("取消滤镜", null) public FilterNone(RomFile rom)
{ {
m_rom = rom; m_rom = rom;
var currentFilterSetting = App.settings.Filter.GetFilterSetting(m_rom);
} }
public override void OnExcute(OptionUI optionUI, ref bool cancelHide) public override void OnExcute(OptionUI optionUI, ref bool cancelHide)
@ -58,8 +58,8 @@ namespace AxibugEmuOnline.Client
return false; return false;
} }
} }
public override string Name => m_filter.Name;
public FilterMenu(RomFile rom, Filter filter) : base(filter.Name, null) public FilterMenu(RomFile rom, Filter filter)
{ {
m_filter = filter; m_filter = filter;
m_presetsMenuItems = new List<OptionMenu> { new FilterPresetMenu(rom, m_filter, m_filter.DefaultPreset) }; m_presetsMenuItems = new List<OptionMenu> { new FilterPresetMenu(rom, m_filter, m_filter.DefaultPreset) };
@ -87,8 +87,8 @@ namespace AxibugEmuOnline.Client
} }
} }
public override string Name => m_preset.Name;
public FilterPresetMenu(RomFile rom, Filter filter, FilterPreset preset) : base(preset.Name, null) public FilterPresetMenu(RomFile rom, Filter filter, FilterPreset preset)
{ {
m_preset = preset; m_preset = preset;
m_rom = rom; m_rom = rom;

View File

@ -1,14 +1,12 @@
using AxibugEmuOnline.Client.ClientCore; namespace AxibugEmuOnline.Client
using System.Diagnostics;
namespace AxibugEmuOnline.Client
{ {
public class InGameUI_LoadState : ExecuteMenu public class InGameUI_LoadState : ExecuteMenu
{ {
private InGameUI m_gameUI; private InGameUI m_gameUI;
public override bool Visible => !m_gameUI.IsNetPlay; public override bool Visible => !m_gameUI.IsNetPlay;
public override string Name => "读取快照";
public InGameUI_LoadState(InGameUI gameUI) : base("뗍혤우亮", null) public InGameUI_LoadState(InGameUI gameUI)
{ {
m_gameUI = gameUI; m_gameUI = gameUI;
} }
@ -18,12 +16,9 @@ namespace AxibugEmuOnline.Client
if (m_gameUI.IsNetPlay) return; if (m_gameUI.IsNetPlay) return;
object state = m_gameUI.GetQuickState(); object state = m_gameUI.GetQuickState();
Stopwatch sw = Stopwatch.StartNew();
if (state != null) if (state != null)
{ {
m_gameUI.Core.LoadState(state); m_gameUI.Core.LoadState(state);
sw.Stop();
App.log.Info($"{m_gameUI.RomFile.Platform}====>우亮속潼봬珂:{sw.Elapsed.TotalMilliseconds}ms");
} }
} }
} }

View File

@ -1,11 +1,11 @@
namespace AxibugEmuOnline.Client namespace AxibugEmuOnline.Client
{ {
public class InGameUI_QuitGame : ExecuteMenu public class InGameUI_QuitGame : ExecuteMenu
{ {
private InGameUI m_gameUI; private InGameUI m_gameUI;
public override string Name => "退出";
public InGameUI_QuitGame(InGameUI gameUI)
public InGameUI_QuitGame(InGameUI gameUI) : base("退出", null)
{ {
m_gameUI = gameUI; m_gameUI = gameUI;
} }

View File

@ -1,14 +1,14 @@
using AxibugEmuOnline.Client.ClientCore; using AxibugEmuOnline.Client.ClientCore;
namespace AxibugEmuOnline.Client namespace AxibugEmuOnline.Client
{ {
public class InGameUI_Reset : ExecuteMenu public class InGameUI_Reset : ExecuteMenu
{ {
private InGameUI m_gameUI; private InGameUI m_gameUI;
public override string Name => "复位";
public override bool Visible => !m_gameUI.IsNetPlay || App.roomMgr.IsHost; public override bool Visible => !m_gameUI.IsNetPlay || App.roomMgr.IsHost;
public InGameUI_Reset(InGameUI gameUI) : base("复位", null) public InGameUI_Reset(InGameUI gameUI)
{ {
m_gameUI = gameUI; m_gameUI = gameUI;
} }

View File

@ -1,4 +1,4 @@
using AxibugEmuOnline.Client.ClientCore; using AxibugEmuOnline.Client.ClientCore;
using System.Diagnostics; using System.Diagnostics;
namespace AxibugEmuOnline.Client namespace AxibugEmuOnline.Client
@ -8,8 +8,9 @@ namespace AxibugEmuOnline.Client
private InGameUI m_gameUI; private InGameUI m_gameUI;
public override bool Visible => !m_gameUI.IsNetPlay; public override bool Visible => !m_gameUI.IsNetPlay;
public override string Name => "保存快照";
public InGameUI_SaveState(InGameUI gameUI) : base("괏닸우亮", null) public InGameUI_SaveState(InGameUI gameUI)
{ {
m_gameUI = gameUI; m_gameUI = gameUI;
} }
@ -23,7 +24,7 @@ namespace AxibugEmuOnline.Client
m_gameUI.SaveQuickState(state); m_gameUI.SaveQuickState(state);
sw.Stop(); sw.Stop();
App.log.Info($"{m_gameUI.RomFile.Platform}====>삿혤우亮봬珂:{sw.Elapsed.TotalMilliseconds}ms"); App.log.Info($"{m_gameUI.RomFile.Platform}====>获取快照耗时:{sw.Elapsed.TotalMilliseconds}ms");
} }
} }
} }

View File

@ -8,8 +8,8 @@ namespace AxibugEmuOnline.Client
public class InGameUI_Scaler : ExpandMenu public class InGameUI_Scaler : ExpandMenu
{ {
private List<OptionMenu> m_subMenus = new List<OptionMenu>(); private List<OptionMenu> m_subMenus = new List<OptionMenu>();
public override string Name => "屏幕比例";
public InGameUI_Scaler(InGameUI inGameUI) : base("屏幕比例", null) public InGameUI_Scaler(InGameUI inGameUI)
{ {
m_subMenus.Add(new Scale(inGameUI, null)); m_subMenus.Add(new Scale(inGameUI, null));
foreach (EnumScalerMode scaleModeValue in Enum.GetValues(typeof(EnumScalerMode))) foreach (EnumScalerMode scaleModeValue in Enum.GetValues(typeof(EnumScalerMode)))
@ -48,8 +48,8 @@ namespace AxibugEmuOnline.Client
else return false; else return false;
} }
} }
public override string Name => ModeToName(m_mode);
public Scale(InGameUI inGameUI, EnumScalerMode? mode) : base(ModeToName(mode), null) public Scale(InGameUI inGameUI, EnumScalerMode? mode)
{ {
m_mode = mode; m_mode = mode;
m_gameUI = inGameUI; m_gameUI = inGameUI;

View File

@ -42,7 +42,7 @@ namespace AxibugEmuOnline.Client
if (m_selectIndex == -1) SelectIndex = 0; if (m_selectIndex == -1) SelectIndex = 0;
} }
protected virtual MenuItem GetItemUIByIndex(int index) public virtual MenuItem GetItemUIByIndex(int index)
{ {
return m_runtimeMenuUI[SelectIndex]; return m_runtimeMenuUI[SelectIndex];
} }

View File

@ -37,16 +37,18 @@ namespace AxibugEmuOnline.Client
var gap = value - m_selectIndex; var gap = value - m_selectIndex;
var temp = value;
while (!m_runtimeMenuItems[value].Visible) while (!m_runtimeMenuItems[value].Visible)
{ {
var temp = value;
if (gap > 0) if (gap > 0)
{ {
temp++; temp++;
if (temp >= m_runtimeMenuItems.Count) return;
} }
else else
{ {
temp--; temp--;
if (temp < 0) return;
} }
if (temp >= 0 && temp < m_runtimeMenuItems.Count) if (temp >= 0 && temp < m_runtimeMenuItems.Count)
@ -386,7 +388,6 @@ namespace AxibugEmuOnline.Client
{ {
/// <summary> 设置这个值以控制菜单中显示"已应用"标记 </summary> /// <summary> 设置这个值以控制菜单中显示"已应用"标记 </summary>
public virtual bool IsApplied { get; } public virtual bool IsApplied { get; }
protected ExecuteMenu(string name, Sprite icon = null) : base(name, icon) { }
public abstract void OnExcute(OptionUI optionUI, ref bool cancelHide); public abstract void OnExcute(OptionUI optionUI, ref bool cancelHide);
} }
@ -396,7 +397,7 @@ namespace AxibugEmuOnline.Client
/// </summary> /// </summary>
public abstract class ExpandMenu : ExecuteMenu public abstract class ExpandMenu : ExecuteMenu
{ {
protected ExpandMenu(string name, Sprite icon = null) : base(name, icon) { } protected ExpandMenu() : base() { }
public sealed override void OnExcute(OptionUI optionUI, ref bool cancelHide) public sealed override void OnExcute(OptionUI optionUI, ref bool cancelHide)
{ {
@ -411,7 +412,7 @@ namespace AxibugEmuOnline.Client
/// </summary> /// </summary>
public abstract class ValueSetMenu : OptionMenu public abstract class ValueSetMenu : OptionMenu
{ {
protected ValueSetMenu(string name) : base(name) { } protected ValueSetMenu() : base() { }
public abstract Type ValueType { get; } public abstract Type ValueType { get; }
public abstract object ValueRaw { get; } public abstract object ValueRaw { get; }
@ -423,17 +424,11 @@ namespace AxibugEmuOnline.Client
/// <summary> 不要直接继承这个类 </summary> /// <summary> 不要直接继承这个类 </summary>
public abstract class OptionMenu public abstract class OptionMenu
{ {
public string Name { get; protected set; } public abstract string Name { get; }
public Sprite Icon { get; protected set; } public virtual Sprite Icon { get; }
public virtual bool Visible => true; public virtual bool Visible => true;
public virtual bool Enable => true; public virtual bool Enable => true;
protected OptionMenu(string name, Sprite icon = null)
{
Name = name;
Icon = icon;
}
public virtual void OnFocus() { } public virtual void OnFocus() { }
public virtual void OnShow(OptionUI_MenuItem ui) { } public virtual void OnShow(OptionUI_MenuItem ui) { }
public virtual void OnHide() { } public virtual void OnHide() { }

View File

@ -45,7 +45,7 @@ namespace AxibugEmuOnline.Client
SelectIndex = selectIndex; SelectIndex = selectIndex;
} }
protected override MenuItem GetItemUIByIndex(int index) public override MenuItem GetItemUIByIndex(int index)
{ {
return itemGroup.GetItemUIByDataIndex(index)?.GetComponent<MenuItem>(); return itemGroup.GetItemUIByDataIndex(index)?.GetComponent<MenuItem>();
} }