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

View File

@ -70,7 +70,9 @@ namespace AxibugEmuOnline.Client
{
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;
}
@ -101,7 +103,9 @@ namespace AxibugEmuOnline.Client
private OptionUI_MenuItem m_ui;
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_preset = preset;
@ -151,8 +155,8 @@ namespace AxibugEmuOnline.Client
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)
: base(editParam.Name)
{
m_filter = filter;
m_param = editParam;
@ -179,8 +183,9 @@ namespace AxibugEmuOnline.Client
{
private Filter m_filter;
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_preset = preset;

View File

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

View File

@ -68,8 +68,9 @@ namespace AxibugEmuOnline.Client
public class OptMenu_Search : ExecuteMenu
{
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;
}
@ -90,9 +91,10 @@ namespace AxibugEmuOnline.Client
{
private RomListMenuItem m_ui;
public override string Name => "显示全部";
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;
}
@ -103,5 +105,30 @@ namespace AxibugEmuOnline.Client
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
{
private InGameUI m_gameUI;
public override string Name => "滤镜";
public InGameUI_FilterSetting(InGameUI gameUI) : base("滤镜", null)
public InGameUI_FilterSetting(InGameUI gameUI)
{
m_gameUI = gameUI;
}
@ -26,12 +27,11 @@ namespace AxibugEmuOnline.Client
{
private RomFile m_rom;
public override string Name => "取消滤镜";
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;
var currentFilterSetting = App.settings.Filter.GetFilterSetting(m_rom);
}
public override void OnExcute(OptionUI optionUI, ref bool cancelHide)
@ -58,8 +58,8 @@ namespace AxibugEmuOnline.Client
return false;
}
}
public FilterMenu(RomFile rom, Filter filter) : base(filter.Name, null)
public override string Name => m_filter.Name;
public FilterMenu(RomFile rom, Filter filter)
{
m_filter = filter;
m_presetsMenuItems = new List<OptionMenu> { new FilterPresetMenu(rom, m_filter, m_filter.DefaultPreset) };
@ -87,8 +87,8 @@ namespace AxibugEmuOnline.Client
}
}
public FilterPresetMenu(RomFile rom, Filter filter, FilterPreset preset) : base(preset.Name, null)
public override string Name => m_preset.Name;
public FilterPresetMenu(RomFile rom, Filter filter, FilterPreset preset)
{
m_preset = preset;
m_rom = rom;

View File

@ -1,14 +1,12 @@
using AxibugEmuOnline.Client.ClientCore;
using System.Diagnostics;
namespace AxibugEmuOnline.Client
namespace AxibugEmuOnline.Client
{
public class InGameUI_LoadState : ExecuteMenu
{
private InGameUI m_gameUI;
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;
}
@ -18,12 +16,9 @@ namespace AxibugEmuOnline.Client
if (m_gameUI.IsNetPlay) return;
object state = m_gameUI.GetQuickState();
Stopwatch sw = Stopwatch.StartNew();
if (state != null)
{
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
{
private InGameUI m_gameUI;
public override string Name => "退出";
public InGameUI_QuitGame(InGameUI gameUI) : base("退出", null)
public InGameUI_QuitGame(InGameUI gameUI)
{
m_gameUI = gameUI;
}

View File

@ -1,14 +1,14 @@
using AxibugEmuOnline.Client.ClientCore;
using AxibugEmuOnline.Client.ClientCore;
namespace AxibugEmuOnline.Client
{
public class InGameUI_Reset : ExecuteMenu
{
private InGameUI m_gameUI;
public override string Name => "复位";
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;
}

View File

@ -1,4 +1,4 @@
using AxibugEmuOnline.Client.ClientCore;
using AxibugEmuOnline.Client.ClientCore;
using System.Diagnostics;
namespace AxibugEmuOnline.Client
@ -8,8 +8,9 @@ namespace AxibugEmuOnline.Client
private InGameUI m_gameUI;
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;
}
@ -23,7 +24,7 @@ namespace AxibugEmuOnline.Client
m_gameUI.SaveQuickState(state);
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
{
private List<OptionMenu> m_subMenus = new List<OptionMenu>();
public InGameUI_Scaler(InGameUI inGameUI) : base("屏幕比例", null)
public override string Name => "屏幕比例";
public InGameUI_Scaler(InGameUI inGameUI)
{
m_subMenus.Add(new Scale(inGameUI, null));
foreach (EnumScalerMode scaleModeValue in Enum.GetValues(typeof(EnumScalerMode)))
@ -48,8 +48,8 @@ namespace AxibugEmuOnline.Client
else return false;
}
}
public Scale(InGameUI inGameUI, EnumScalerMode? mode) : base(ModeToName(mode), null)
public override string Name => ModeToName(m_mode);
public Scale(InGameUI inGameUI, EnumScalerMode? mode)
{
m_mode = mode;
m_gameUI = inGameUI;

View File

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

View File

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

View File

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