AxibugEmuOnline/AxibugEmuOnline.Client/Assets/Script/UI/InGameUI/InGameUI.cs

129 lines
3.5 KiB
C#
Raw Normal View History

2024-09-14 15:32:29 +08:00
using AxibugEmuOnline.Client.ClientCore;
2024-09-14 17:22:01 +08:00
using AxibugEmuOnline.Client.Event;
using System.Collections.Generic;
namespace AxibugEmuOnline.Client
{
public class InGameUI : CommandExecuter
{
public static InGameUI Instance { get; private set; }
public RomFile RomFile => m_rom;
public override bool Enable => gameObject.activeInHierarchy;
2024-09-14 15:32:29 +08:00
2024-11-08 11:49:33 +08:00
/// <summary> ָʾ<D6B8><CABE><EFBFBD><EFBFBD>Ϸʵ<CFB7><CAB5><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ </summary>
public bool IsNetPlay
{
get
{
if (!App.user.IsLoggedIn) return false;
if (App.roomMgr.mineRoomMiniInfo == null) return false;
if (App.roomMgr.RoomState <= AxibugProtobuf.RoomGameState.OnlyHost) return false;
return true;
}
}
2024-09-14 15:32:29 +08:00
private RomFile m_rom;
2024-09-23 18:15:34 +08:00
public IEmuCore Core { get; private set; }
2024-09-13 17:39:48 +08:00
private object m_state;
2024-09-14 15:32:29 +08:00
private List<OptionMenu> menus = new List<OptionMenu>();
2024-09-14 17:22:01 +08:00
private StepPerformer m_stepPerformer;
protected override void Awake()
{
Instance = this;
gameObject.SetActiveEx(false);
2024-09-14 17:22:01 +08:00
m_stepPerformer = new StepPerformer(this);
2024-09-14 15:32:29 +08:00
menus.Add(new InGameUI_SaveState(this));
menus.Add(new InGameUI_LoadState(this));
menus.Add(new InGameUI_QuitGame(this));
2024-09-14 17:22:01 +08:00
base.Awake();
}
private void OnDestroy()
{
Instance = null;
}
2024-09-13 17:39:48 +08:00
/// <summary> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٿ<EFBFBD><D9BF><EFBFBD> </summary>
public void SaveQuickState(object state)
{
m_state = state;
}
/// <summary>
/// <20><>ȡ<EFBFBD><C8A1><EFBFBD>ٿ<EFBFBD><D9BF><EFBFBD>
/// </summary>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
2024-09-23 18:15:34 +08:00
public object GetQuickState()
2024-09-13 17:39:48 +08:00
{
2024-09-23 18:15:34 +08:00
return m_state;
2024-09-13 17:39:48 +08:00
}
2024-09-23 18:15:34 +08:00
public void Show(RomFile currentRom, IEmuCore core)
{
m_state = null;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϸ<EFBFBD><CFB7><EFBFBD><EFBFBD>
CommandDispatcher.Instance.RegistController(this);
m_rom = currentRom;
2024-09-23 18:15:34 +08:00
Core = core;
2024-09-14 17:22:01 +08:00
m_stepPerformer.Reset();
2024-09-13 17:39:48 +08:00
2024-11-11 10:48:30 +08:00
if (App.user.IsLoggedIn && !App.roomMgr.InRoom)
2024-09-14 15:56:15 +08:00
{
App.roomMgr.SendCreateRoom(m_rom.ID, 0, m_rom.Hash);
}
2024-09-14 17:22:01 +08:00
Eventer.Instance.RegisterEvent<int>(EEvent.OnRoomWaitStepChange, OnServerStepUpdate);
OptionUI.Instance.OnHide += PopMenu_OnHide;
2024-09-14 17:22:01 +08:00
gameObject.SetActiveEx(true);
}
2024-09-14 17:22:01 +08:00
private void OnServerStepUpdate(int step)
{
m_stepPerformer.Perform(step);
}
public void Hide()
{
CommandDispatcher.Instance.UnRegistController(this);
OptionUI.Instance.OnHide -= PopMenu_OnHide;
gameObject.SetActiveEx(false);
}
protected override void OnCmdOptionMenu()
{
2024-09-14 15:32:29 +08:00
OptionUI.Instance.Pop(menus);
2024-11-08 11:49:33 +08:00
if (!IsNetPlay)//<2F><><EFBFBD><EFBFBD>ģʽ<C4A3><CABD>ͣģ<CDA3><C4A3><EFBFBD><EFBFBD>
{
Core.Pause();
}
2024-09-14 15:32:29 +08:00
}
//<2F>˵<EFBFBD><CBB5>ر<EFBFBD>ʱ<EFBFBD><CAB1>
private void PopMenu_OnHide()
{
2024-11-08 11:49:33 +08:00
if (!IsNetPlay)//<2F><><EFBFBD><EFBFBD>ģʽ<C4A3>ָ<EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͣ
Core.Resume();
}
2024-09-14 15:32:29 +08:00
public void QuitGame()
{
2024-09-14 17:22:01 +08:00
Eventer.Instance.UnregisterEvent<int>(EEvent.OnRoomWaitStepChange, OnServerStepUpdate);
2024-09-14 15:56:15 +08:00
App.roomMgr.SendLeavnRoom();
2024-09-14 15:32:29 +08:00
App.emu.StopGame();
2024-09-23 18:15:34 +08:00
ControlScheme.Current = ControlSchemeSetts.Normal;
}
}
}