master #40

Merged
sin365 merged 4 commits from Alienjack/AxibugEmuOnline:master into master 2024-11-07 19:42:15 +08:00
5 changed files with 42 additions and 8 deletions
Showing only changes of commit 88313eee6b - Show all commits

View File

@ -6,6 +6,8 @@ namespace AxibugEmuOnline.Client
{ {
public interface IEmuCore public interface IEmuCore
{ {
GameObject gameObject { get; }
object GetState(); object GetState();
byte[] GetStateBytes(); byte[] GetStateBytes();
void LoadState(object state); void LoadState(object state);
@ -13,5 +15,6 @@ namespace AxibugEmuOnline.Client
void Pause(); void Pause();
void Resume(); void Resume();
void SetupScheme(); void SetupScheme();
void StartGame(RomFile romFile);
} }
} }

View File

@ -1,4 +1,5 @@
using AxibugEmuOnline.Client.ClientCore; using AxibugEmuOnline.Client.ClientCore;
using MyNes.Core;
using UnityEngine; using UnityEngine;
namespace AxibugEmuOnline.Client.Manager namespace AxibugEmuOnline.Client.Manager
@ -6,6 +7,7 @@ namespace AxibugEmuOnline.Client.Manager
public class AppEmu public class AppEmu
{ {
private GameObject m_emuInstance; private GameObject m_emuInstance;
private IEmuCore m_emuCore;
public void BeginGame(RomFile romFile) public void BeginGame(RomFile romFile)
{ {
@ -14,14 +16,17 @@ namespace AxibugEmuOnline.Client.Manager
switch (romFile.Platform) switch (romFile.Platform)
{ {
case EnumPlatform.NES: case EnumPlatform.NES:
var nesEmu = GameObject.Instantiate(Resources.Load<GameObject>("NES/NesEmulator")).GetComponent<NesEmulator>(); m_emuCore = GameObject.Instantiate(Resources.Load<GameObject>("NES/NesEmulator")).GetComponent<IEmuCore>();
m_emuInstance = nesEmu.gameObject;
nesEmu.StartGame(romFile);
LaunchUI.Instance.HideMainMenu();
InGameUI.Instance.Show(romFile, nesEmu);
break; break;
} }
m_emuInstance = m_emuCore.gameObject;
m_emuCore.StartGame(romFile);
LaunchUI.Instance.HideMainMenu();
InGameUI.Instance.Show(romFile, m_emuCore);
m_emuCore.SetupScheme();
} }
public void StopGame() public void StopGame()
@ -32,6 +37,8 @@ namespace AxibugEmuOnline.Client.Manager
InGameUI.Instance.Hide(); InGameUI.Instance.Hide();
LaunchUI.Instance.ShowMainMenu(); LaunchUI.Instance.ShowMainMenu();
ControlScheme.Current = ControlSchemeSetts.Normal;
} }
} }
} }

View File

@ -74,8 +74,12 @@ namespace AxibugEmuOnline.Client
} }
} }
//键位映射表需要在按键响应的堆栈结束后处理,防止迭代器修改问题
if (m_waitMapperSetting != null) if (m_waitMapperSetting != null)
{
m_keyMapper = m_waitMapperSetting; m_keyMapper = m_waitMapperSetting;
m_waitMapperSetting = null;
}
} }
private Dictionary<KeyCode, EnumCommand> m_waitMapperSetting = null; private Dictionary<KeyCode, EnumCommand> m_waitMapperSetting = null;

View File

@ -12,7 +12,7 @@ namespace AxibugEmuOnline.Client
public override bool Enable => gameObject.activeInHierarchy; public override bool Enable => gameObject.activeInHierarchy;
/// <summary> 指示该游戏实例是否处于联网模式 </summary> /// <summary> 指示该游戏实例是否处于联网模式 </summary>
public bool IsOnline => App.roomMgr.RoomState > AxibugProtobuf.RoomGameState.OnlyHost; public bool IsOnline => App.user.IsLoggedIn ? App.roomMgr.RoomState > AxibugProtobuf.RoomGameState.OnlyHost : false;
private RomFile m_rom; private RomFile m_rom;
public IEmuCore Core { get; private set; } public IEmuCore Core { get; private set; }
@ -57,6 +57,7 @@ namespace AxibugEmuOnline.Client
public void Show(RomFile currentRom, IEmuCore core) public void Show(RomFile currentRom, IEmuCore core)
{ {
m_state = null;//清空游戏快照
CommandDispatcher.Instance.RegistController(this); CommandDispatcher.Instance.RegistController(this);
m_rom = currentRom; m_rom = currentRom;
@ -69,6 +70,7 @@ namespace AxibugEmuOnline.Client
} }
Eventer.Instance.RegisterEvent<int>(EEvent.OnRoomWaitStepChange, OnServerStepUpdate); Eventer.Instance.RegisterEvent<int>(EEvent.OnRoomWaitStepChange, OnServerStepUpdate);
OptionUI.Instance.OnHide += PopMenu_OnHide;
gameObject.SetActiveEx(true); gameObject.SetActiveEx(true);
} }
@ -82,13 +84,27 @@ namespace AxibugEmuOnline.Client
{ {
CommandDispatcher.Instance.UnRegistController(this); CommandDispatcher.Instance.UnRegistController(this);
OptionUI.Instance.OnHide -= PopMenu_OnHide;
gameObject.SetActiveEx(false); gameObject.SetActiveEx(false);
} }
protected override void OnCmdOptionMenu() protected override void OnCmdOptionMenu()
{ {
OptionUI.Instance.Pop(menus); OptionUI.Instance.Pop(menus);
if (!IsOnline)//单人模式暂停模拟器
{
Core.Pause();
} }
}
//菜单关闭时候
private void PopMenu_OnHide()
{
if (!IsOnline)//单人模式恢复模拟器的暂停
Core.Resume();
}
public void QuitGame() public void QuitGame()
{ {

View File

@ -24,6 +24,8 @@ namespace AxibugEmuOnline.Client
private bool m_bPoped = false; private bool m_bPoped = false;
private List<OptionUI_MenuItem> m_runtimeMenuItems = new List<OptionUI_MenuItem>(); private List<OptionUI_MenuItem> m_runtimeMenuItems = new List<OptionUI_MenuItem>();
public event Action OnHide;
private int m_selectIndex = -1; private int m_selectIndex = -1;
public int SelectIndex public int SelectIndex
{ {
@ -178,6 +180,8 @@ namespace AxibugEmuOnline.Client
m_bPoped = false; m_bPoped = false;
ControlScheme.Current = m_lastCS; ControlScheme.Current = m_lastCS;
OnHide?.Invoke();
} }
} }