diff --git a/AxibugEmuOnline.Client/Assets/Resources/IMPORTENT.prefab b/AxibugEmuOnline.Client/Assets/Resources/IMPORTENT.prefab index 91a5bc69..daddb18a 100644 --- a/AxibugEmuOnline.Client/Assets/Resources/IMPORTENT.prefab +++ b/AxibugEmuOnline.Client/Assets/Resources/IMPORTENT.prefab @@ -97,6 +97,7 @@ RectTransform: m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: + - {fileID: 6774190055201401942} - {fileID: 7813729344275964042} - {fileID: 4804966765082268001} m_Father: {fileID: 5169543666820693527} @@ -492,6 +493,81 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 4471d8231d16ba3469228e09d4cb3a81, type: 3} m_Name: m_EditorClassIdentifier: +--- !u!1 &8553047206489589253 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 6774190055201401942} + - component: {fileID: 3110729603451971289} + - component: {fileID: 454445332755738332} + m_Layer: 5 + m_Name: black + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &6774190055201401942 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 8553047206489589253} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 8545038260809852605} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0, y: 0} + m_AnchorMax: {x: 1, y: 1} + m_AnchoredPosition: {x: 0, y: 0} + m_SizeDelta: {x: 0, y: 0} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!222 &3110729603451971289 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 8553047206489589253} + m_CullTransparentMesh: 1 +--- !u!114 &454445332755738332 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 8553047206489589253} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 0, g: 0, b: 0, a: 1} + m_RaycastTarget: 1 + m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} + m_Maskable: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_Sprite: {fileID: 0} + m_Type: 0 + m_PreserveAspect: 0 + m_FillCenter: 1 + m_FillMethod: 4 + m_FillAmount: 1 + m_FillClockwise: 1 + m_FillOrigin: 0 + m_UseSpriteMesh: 0 + m_PixelsPerUnitMultiplier: 1 --- !u!1 &9087746359628224422 GameObject: m_ObjectHideFlags: 0 diff --git a/AxibugEmuOnline.Client/Assets/Resources/NES/NesEmulator.prefab b/AxibugEmuOnline.Client/Assets/Resources/NES/NesEmulator.prefab index 53110e49..11326206 100644 --- a/AxibugEmuOnline.Client/Assets/Resources/NES/NesEmulator.prefab +++ b/AxibugEmuOnline.Client/Assets/Resources/NES/NesEmulator.prefab @@ -143,6 +143,81 @@ AudioSource: m_PreInfinity: 2 m_PostInfinity: 2 m_RotationOrder: 4 +--- !u!1 &1832378132020391456 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 8057614414535643033} + - component: {fileID: 377334483991090399} + - component: {fileID: 4271988797887364570} + m_Layer: 5 + m_Name: bg + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &8057614414535643033 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1832378132020391456} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 4232056520494431727} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0.5, y: 0.5} + m_AnchorMax: {x: 0.5, y: 0.5} + m_AnchoredPosition: {x: 0, y: 0} + m_SizeDelta: {x: 100, y: 100} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!222 &377334483991090399 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1832378132020391456} + m_CullTransparentMesh: 1 +--- !u!114 &4271988797887364570 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1832378132020391456} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 0, g: 0, b: 0, a: 1} + m_RaycastTarget: 1 + m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} + m_Maskable: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_Sprite: {fileID: 0} + m_Type: 0 + m_PreserveAspect: 0 + m_FillCenter: 1 + m_FillMethod: 4 + m_FillAmount: 1 + m_FillClockwise: 1 + m_FillOrigin: 0 + m_UseSpriteMesh: 0 + m_PixelsPerUnitMultiplier: 1 --- !u!1 &3297772745682094737 GameObject: m_ObjectHideFlags: 0 @@ -346,6 +421,7 @@ RectTransform: m_LocalScale: {x: 0, y: 0, z: 0} m_ConstrainProportionsScale: 0 m_Children: + - {fileID: 8057614414535643033} - {fileID: 4232056521759880275} - {fileID: 1038087993597378172} m_Father: {fileID: 4232056521131536011} diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/App.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/App.cs index 412c1bfd..56f3a4d3 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/App.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/App.cs @@ -45,7 +45,7 @@ namespace AxibugEmuOnline.Client.ClientCore #else public static string PersistentDataPath => Application.persistentDataPath; #endif - public static void Init(Initer initer, bool isTest = false, string testSrvIP = "") + public static void Init( bool isTest = false, string testSrvIP = "") { //其他平台必要的初始化 if (UnityEngine.Application.platform == RuntimePlatform.PSP2) @@ -53,7 +53,7 @@ namespace AxibugEmuOnline.Client.ClientCore PSP2Init(); } - settings = new AppSettings(initer); + settings = new AppSettings(); log = new LogManager(); LogManager.OnLog += OnNoSugarNetLog; @@ -64,7 +64,7 @@ namespace AxibugEmuOnline.Client.ClientCore emu = new AppEmu(); //netgame = new AppNetGame(); httpAPI = new HttpAPI(); - nesRomLib = new RomLib(EnumPlatform.NES); + nesRomLib = new RomLib(EnumSupportEmuPlatform.NES); CacheMgr = new CacheManager(); roomMgr = new AppRoom(); share = new AppShare(); diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/IEmuCore.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/IEmuCore.cs index e277e091..c23d826f 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/IEmuCore.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/IEmuCore.cs @@ -17,9 +17,8 @@ namespace AxibugEmuOnline.Client void DoReset(); IControllerSetuper GetControllerSetuper(); - EnumPlatform Platform { get; } + EnumSupportEmuPlatform Platform { get; } uint Frame { get; } - Vector2Int GetRawResolution(); } public static class IEnumCoreTool diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Initer.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Initer.cs index 2917756d..1a03268c 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Initer.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Initer.cs @@ -5,15 +5,15 @@ namespace AxibugEmuOnline.Client { public class Initer : MonoBehaviour { - public CanvasGroup FilterPreview => m_refs.FilterPreview; - public CanvasGroup XMBBg => m_refs.XMBBg; + static GlobalRef m_refs; + public static CanvasGroup FilterPreview => m_refs.FilterPreview; + public static CanvasGroup XMBBg => m_refs.XMBBg; public static string dev_UUID; [SerializeField] GameObject IMPORTENT; - GlobalRef m_refs; #if UNITY_EDITOR public bool bTest = false; @@ -21,16 +21,21 @@ namespace AxibugEmuOnline.Client #endif private void Awake() - { - m_refs = Instantiate(IMPORTENT, transform).GetComponent(); - + { #if UNITY_EDITOR - App.Init(this, bTest, mTestSrvIP); + App.Init(bTest, mTestSrvIP); #else App.Init(this); #endif dev_UUID = SystemInfo.deviceUniqueIdentifier; + m_refs = Instantiate(IMPORTENT, transform).GetComponent(); + } + + private void Start() + { + App.settings.Filter.ShutDownFilterPreview(); + App.settings.Filter.ShutDownFilter(); } } } diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppEmu.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppEmu.cs index 57b779f8..5bed4b24 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppEmu.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppEmu.cs @@ -31,7 +31,7 @@ namespace AxibugEmuOnline.Client.Manager if (!m_emuCore.IsNull()) StopGame(); var roomInfo = App.roomMgr.mineRoomMiniInfo; - roomInfo.FetchRomFileInRoomInfo(EnumPlatform.NES, (_, romFile) => + roomInfo.FetchRomFileInRoomInfo(EnumSupportEmuPlatform.NES, (_, romFile) => { if (!romFile.RomReady) //这个rom并没有下载,所以取消进入房间 { @@ -51,7 +51,7 @@ namespace AxibugEmuOnline.Client.Manager switch (romFile.Platform) { - case EnumPlatform.NES: + case EnumSupportEmuPlatform.NES: m_emuCore = GameObject.Instantiate(Resources.Load("NES/NesEmulator")).GetComponent(); break; } diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppSettings/AppSettings.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppSettings/AppSettings.cs index d96fdf14..785b02d2 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppSettings/AppSettings.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppSettings/AppSettings.cs @@ -1,6 +1,4 @@ -using static AxibugEmuOnline.Client.FilterManager; - -namespace AxibugEmuOnline.Client +namespace AxibugEmuOnline.Client { public class AppSettings { @@ -8,11 +6,14 @@ namespace AxibugEmuOnline.Client public BgColorSettings BgColor { get; private set; } /// 滤镜设置 public FilterManager Filter { get; private set; } + /// 画面比例设置 + public ScreenScaler ScreenScaler { get; private set; } - public AppSettings(Initer initer) + public AppSettings() { BgColor = new BgColorSettings(); - Filter = new FilterManager(initer.FilterPreview, initer.XMBBg); + Filter = new FilterManager(); + ScreenScaler = new ScreenScaler(); } } } diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppSettings/Filter/FilterManager.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppSettings/Filter/FilterManager.cs index 5d963e71..79b038d3 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppSettings/Filter/FilterManager.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppSettings/Filter/FilterManager.cs @@ -1,4 +1,5 @@ using AxibugEmuOnline.Client.ClientCore; +using Sony.Vita.Dialog; using System; using System.Collections.Generic; using System.Linq; @@ -12,7 +13,8 @@ namespace AxibugEmuOnline.Client public class FilterManager { private List m_filters; - private Dictionary m_filterPlatforms = new Dictionary(); + private Dictionary m_filterPlatforms = new Dictionary(); + private AlphaWraper m_previewFilterWraper; FilterRomSetting m_filterRomSetting; /// @@ -20,15 +22,11 @@ namespace AxibugEmuOnline.Client /// public IReadOnlyList Filters => m_filters; - public FilterManager(CanvasGroup filterPreview, CanvasGroup mainBg) + public FilterManager() { loadFilters(); var json = PlayerPrefs.GetString(nameof(FilterRomSetting)); m_filterRomSetting = JsonUtility.FromJson(json) ?? new FilterRomSetting(); - - m_previewFilterWraper = new AlphaWraper(mainBg, filterPreview, false); - ShutDownFilterPreview(); - ShutDownFilter(); } private void loadFilters() @@ -99,8 +97,8 @@ namespace AxibugEmuOnline.Client Vector2 topRight = RectTransformUtility.WorldToScreenPoint(rawImage.canvas.worldCamera, corners[2]); // 计算宽度和高度 - float width = topRight.x - bottomLeft.x; - float height = topRight.y - bottomLeft.y; + float width = Mathf.Abs(topRight.x - bottomLeft.x); + float height = Mathf.Abs(topRight.y - bottomLeft.y); return new Vector2(width, height); } @@ -109,12 +107,14 @@ namespace AxibugEmuOnline.Client /// 关闭滤镜预览 public void ShutDownFilterPreview() { + if (m_previewFilterWraper == null) m_previewFilterWraper = new AlphaWraper(Initer.XMBBg, Initer.FilterPreview, false); m_previewFilterWraper.On = false; } /// 开启滤镜预览 public void EnableFilterPreview() { + if (m_previewFilterWraper == null) m_previewFilterWraper = new AlphaWraper(Initer.XMBBg, Initer.FilterPreview, false); m_previewFilterWraper.On = true; } diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppSettings/Filter/UIFilterPreviewer.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppSettings/Filter/UIFilterPreviewer.cs index bca21e7b..c5189791 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppSettings/Filter/UIFilterPreviewer.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppSettings/Filter/UIFilterPreviewer.cs @@ -16,6 +16,7 @@ public class UIFilterPreviewer : MonoBehaviour private void Update() { + App.settings.ScreenScaler.CalcScale(m_rawImg); App.settings.Filter.ExecuteFilterRender(m_src, m_rawImg); } } diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppSettings/ScreenScaler.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppSettings/ScreenScaler.cs new file mode 100644 index 00000000..065712f1 --- /dev/null +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppSettings/ScreenScaler.cs @@ -0,0 +1,112 @@ +using System; +using UnityEngine; +using UnityEngine.UI; + +namespace AxibugEmuOnline.Client +{ + /// + /// 实现模拟器输出画面的比例调整类 + /// + public class ScreenScaler + { + /// + /// 全局设置的缩放模式 + /// + public EnumScalerMode GlobalMode + { + get => (EnumScalerMode)PlayerPrefs.GetInt($"{nameof(ScreenScaler)}.GlobalMode", 0); + set => PlayerPrefs.SetInt($"{nameof(ScreenScaler)}.GlobalMode", (int)value); + } + + /// + /// 获得指定平台设置的缩放模式 + /// + /// + /// + public EnumScalerMode GetMode(EnumSupportEmuPlatform platform) + { + int setVal = PlayerPrefs.GetInt($"{nameof(ScreenScaler)}.PlatMode.{platform}", -1); + if (setVal == -1) + return GlobalMode; + else + return (EnumScalerMode)setVal; + } + + /// + /// 根据缩放模式设置UI的缩放 + /// + /// + /// 不指定模拟器平台时,使用全局设置的缩放模式 + public void CalcScale(RawImage rawImg, EnumSupportEmuPlatform? platform = null) + { + var targetMode = platform == null ? GlobalMode : GetMode(platform.Value); + var resolution = GetRawResolution(platform == null ? EnumSupportEmuPlatform.NES : platform.Value); + var canvasRect = (rawImg.canvas.transform as RectTransform).rect; + switch (targetMode) + { + case EnumScalerMode.Raw: + { + float width = resolution.x / rawImg.canvas.pixelRect.width * canvasRect.width; + float height = resolution.y / rawImg.canvas.pixelRect.height * canvasRect.height; + rawImg.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, width); + rawImg.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, height); + } + break; + case EnumScalerMode.Fix: + { + bool stretchWidth = rawImg.canvas.pixelRect.width <= rawImg.canvas.pixelRect.height; + //bool stretchWidth = Mathf.Abs(resolution.x - rawImg.canvas.pixelRect.width) <= Mathf.Abs(resolution.y - rawImg.canvas.pixelRect.height); + if (stretchWidth) + { + var needWidth = rawImg.canvas.pixelRect.width; + var factor = needWidth / resolution.x; + resolution.x = (int)needWidth; + resolution.y = (int)(resolution.y * factor); + } + else + { + var needHeight = rawImg.canvas.pixelRect.height; + var factor = needHeight / resolution.y; + resolution.y = (int)needHeight; + resolution.x = (int)(resolution.x * factor); + } + + float width = resolution.x / rawImg.canvas.pixelRect.width * canvasRect.width; + float height = resolution.y / rawImg.canvas.pixelRect.height * canvasRect.height; + rawImg.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, width); + rawImg.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, height); + } + break; + case EnumScalerMode.FullScreen: + { + rawImg.rectTransform.pivot = new Vector2(0.5f, 0.5f); + rawImg.rectTransform.anchorMin = new Vector2(0, 0); + rawImg.rectTransform.anchorMax = new Vector2(1, 1); + rawImg.rectTransform.sizeDelta = new Vector2(0, 0); + rawImg.rectTransform.anchoredPosition = new Vector2(0, 0); + } + break; + } + } + + public Vector2Int GetRawResolution(EnumSupportEmuPlatform platform) + { + switch (platform) + { + case EnumSupportEmuPlatform.NES: return new Vector2Int(256, 240); + default: return new Vector2Int(256, 240); + } + } + + /// 缩放模式 + public enum EnumScalerMode + { + /// 全屏 + FullScreen, + /// 适应 + Fix, + /// 原始 + Raw + }; + } +} diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppSettings/ScreenScaler.cs.meta b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppSettings/ScreenScaler.cs.meta new file mode 100644 index 00000000..de29c857 --- /dev/null +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppSettings/ScreenScaler.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 8341bf735cdfe6e49b3fa43b9a42d711 \ No newline at end of file diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/RomLib/EnumPlatform.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/RomLib/EnumPlatform.cs index 25bbe2be..a588b658 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/RomLib/EnumPlatform.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/RomLib/EnumPlatform.cs @@ -1,6 +1,6 @@ namespace AxibugEmuOnline.Client { - public enum EnumPlatform + public enum EnumSupportEmuPlatform { NES } diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/RomLib/RomFile.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/RomLib/RomFile.cs index d39c5769..1142b32a 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/RomLib/RomFile.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/RomLib/RomFile.cs @@ -1,4 +1,4 @@ -using AxibugEmuOnline.Client.ClientCore; +using AxibugEmuOnline.Client.ClientCore; using ICSharpCode.SharpZipLib.Zip; using System; using System.Collections; @@ -13,7 +13,7 @@ namespace AxibugEmuOnline.Client { private HttpAPI.Resp_RomInfo webData; private bool hasLocalFile; - private EnumPlatform platform; + private EnumSupportEmuPlatform platform; //private UnityWebRequest downloadRequest; private AxiHttpProxy.SendDownLoadProxy downloadRequest; @@ -36,7 +36,7 @@ namespace AxibugEmuOnline.Client public float Progress => IsDownloading ? downloadRequest.downloadHandler.DownLoadPr : 0; - public EnumPlatform Platform => platform; + public EnumSupportEmuPlatform Platform => platform; /// 指示该Rom信息是否已填充 public bool InfoReady => webData != null; /// 唯一标识 @@ -61,7 +61,7 @@ namespace AxibugEmuOnline.Client public event Action OnDownloadOver; public event Action OnInfoFilled; - public RomFile(EnumPlatform platform, int index, int insidePage) + public RomFile(EnumSupportEmuPlatform platform, int index, int insidePage) { this.platform = platform; Index = index; @@ -181,7 +181,7 @@ namespace AxibugEmuOnline.Client } private RomFile() { } - public static RomFile CreateExistRom(EnumPlatform platform, string fileName) + public static RomFile CreateExistRom(EnumSupportEmuPlatform platform, string fileName) { var res = new RomFile(); res.IsUserRom = true; diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/RomLib/RomLib.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/RomLib/RomLib.cs index ecde27f7..c17e92fe 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/RomLib/RomLib.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/RomLib/RomLib.cs @@ -19,14 +19,14 @@ namespace AxibugEmuOnline.Client private Dictionary nesRomFileNameMapper = new Dictionary(); private HttpAPI.GetRomListAPI m_romGetFunc; private HttpAPI.SearchRomListAPI m_romSearchFunc; - private EnumPlatform m_platform; + private EnumSupportEmuPlatform m_platform; - public RomLib(EnumPlatform platform) + public RomLib(EnumSupportEmuPlatform platform) { m_platform = platform; switch (platform) { - case EnumPlatform.NES: + case EnumSupportEmuPlatform.NES: m_romGetFunc = App.httpAPI.GetNesRomList; m_romSearchFunc = App.httpAPI.SearchNesRomList; break; diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/NesEmulator/NesEmulator.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/NesEmulator/NesEmulator.cs index a2487238..f6483667 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/NesEmulator/NesEmulator.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/NesEmulator/NesEmulator.cs @@ -52,12 +52,13 @@ namespace AxibugEmuOnline.Client var screenBuffer = NesCore.ppu.GetScreenPtr(); VideoProvider.SetDrawData(screenBuffer); - } - + } + + VideoProvider.ApplyScreenScaler(); VideoProvider.ApplyFilterEffect(); } - public EnumPlatform Platform => EnumPlatform.NES; + public EnumSupportEmuPlatform Platform => EnumSupportEmuPlatform.NES; private CoreSupporter m_coreSupporter; /// /// 指定ROM开始游戏 @@ -217,10 +218,5 @@ namespace AxibugEmuOnline.Client { return ControllerMapper; } - - public Vector2Int GetRawResolution() - { - return new Vector2Int(256, 240); - } } } \ No newline at end of file diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/NesEmulator/VideoProvider.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/NesEmulator/VideoProvider.cs index ed83eb80..c4faca6f 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/NesEmulator/VideoProvider.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/NesEmulator/VideoProvider.cs @@ -82,6 +82,11 @@ namespace AxibugEmuOnline.Client App.settings.Filter.ExecuteFilterRender(rt_gpu, Image); } + public void ApplyScreenScaler() + { + App.settings.ScreenScaler.CalcScale(Image, EnumSupportEmuPlatform.NES); + } + private unsafe void PrepareUI(uint* screenData) { if (GPUTurbo) diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/BgSettingsUI/ScreenScalerListMenuItem.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/BgSettingsUI/ScreenScalerListMenuItem.cs index 3d224175..8c706642 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/BgSettingsUI/ScreenScalerListMenuItem.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/BgSettingsUI/ScreenScalerListMenuItem.cs @@ -6,17 +6,6 @@ namespace AxibugEmuOnline.Client { public class ScreenScalerListMenuItem : VirtualSubMenuItem { - /// 缩放模式 - public enum EnumScalerMode - { - /// 全屏 - FullScreen, - /// 适应 - Fix, - /// 原始 - Raw - }; - public override bool OnEnterItem() { App.settings.Filter.EnableFilterPreview(); @@ -34,7 +23,7 @@ namespace AxibugEmuOnline.Client protected override void GetVirtualListDatas(Action datas) { List list = new List(); - foreach (var enumValue in Enum.GetValues(typeof(EnumScalerMode))) list.Add(enumValue); + foreach (var enumValue in Enum.GetValues(typeof(ScreenScaler.EnumScalerMode))) list.Add(enumValue); datas.Invoke(list); } } diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/BgSettingsUI/UI_ScalerModeItem.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/BgSettingsUI/UI_ScalerModeItem.cs index a8eb8ba2..094c8453 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/BgSettingsUI/UI_ScalerModeItem.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/BgSettingsUI/UI_ScalerModeItem.cs @@ -1,4 +1,5 @@ -using AxibugEmuOnline.Client.UI; +using AxibugEmuOnline.Client.ClientCore; +using AxibugEmuOnline.Client.UI; namespace AxibugEmuOnline.Client { @@ -8,27 +9,26 @@ namespace AxibugEmuOnline.Client public class UI_ScalerModeItem : MenuItem, IVirtualItem { public int Index { get; set; } - public ScreenScalerListMenuItem.EnumScalerMode Datacontext { get; private set; } + public ScreenScaler.EnumScalerMode Datacontext { get; private set; } public void SetData(object data) { - Datacontext = (ScreenScalerListMenuItem.EnumScalerMode)data; + Datacontext = (ScreenScaler.EnumScalerMode)data; UpdateView(); } private void UpdateView() { - switch (Datacontext) { - case ScreenScalerListMenuItem.EnumScalerMode.FullScreen: + case ScreenScaler.EnumScalerMode.FullScreen: SetBaseInfo("全屏", "模拟器输出画面将拉伸到全屏", null); break; - case ScreenScalerListMenuItem.EnumScalerMode.Raw: + case ScreenScaler.EnumScalerMode.Raw: SetBaseInfo("原始尺寸", "将保持模拟器输出画面的原始分辨率", null); break; - case ScreenScalerListMenuItem.EnumScalerMode.Fix: + case ScreenScaler.EnumScalerMode.Fix: SetBaseInfo("适应", "在保持原始画面比例的情况下适配到全屏", null); break; } @@ -37,6 +37,12 @@ namespace AxibugEmuOnline.Client public void SetDependencyProperty(object data) { SetSelectState(data is ThirdMenuRoot && ((ThirdMenuRoot)data).SelectIndex == Index); + + if (m_select) + { + App.settings.Filter.EnableFilterPreview(); + App.settings.ScreenScaler.GlobalMode = Datacontext; + } } public void Release() { } diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/GamesUI/RomListMenuItem.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/GamesUI/RomListMenuItem.cs index 10309e6b..e9c91f5a 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/GamesUI/RomListMenuItem.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/GamesUI/RomListMenuItem.cs @@ -8,7 +8,7 @@ namespace AxibugEmuOnline.Client public class RomListMenuItem : VirtualSubMenuItem { [SerializeField] - protected EnumPlatform Platform; + protected EnumSupportEmuPlatform Platform; private RomLib RomLib { @@ -16,7 +16,7 @@ namespace AxibugEmuOnline.Client { switch (Platform) { - case EnumPlatform.NES: + case EnumSupportEmuPlatform.NES: return App.nesRomLib; default: throw new System.NotImplementedException($"未实现的平台 {Platform}"); diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/MenuItem.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/MenuItem.cs index f1db7062..e1deee62 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/MenuItem.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/MenuItem.cs @@ -1,4 +1,4 @@ -using DG.Tweening; +using DG.Tweening; using DG.Tweening.Core; using DG.Tweening.Plugins.Options; using UnityEngine; diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/RoomUI/RoomItem.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/RoomUI/RoomItem.cs index 541a5175..6842aed6 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/RoomUI/RoomItem.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/RoomUI/RoomItem.cs @@ -86,7 +86,7 @@ namespace AxibugEmuOnline.Client SetBaseInfo("--", $"{hostNick}的房间", $"{cur}/{max}"); SetIcon(null); - roomInfo.FetchRomFileInRoomInfo(EnumPlatform.NES, (room, romFile) => + roomInfo.FetchRomFileInRoomInfo(EnumSupportEmuPlatform.NES, (room, romFile) => { if (room.RoomID != RoomID) return; diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Utility.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Utility.cs index f8f76b12..8ad14e0e 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Utility.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Utility.cs @@ -1,4 +1,4 @@ -using AxibugEmuOnline.Client.ClientCore; +using AxibugEmuOnline.Client.ClientCore; using AxibugProtobuf; using System; using System.Collections.Generic; @@ -34,7 +34,7 @@ namespace AxibugEmuOnline.Client } private static Dictionary s_RomFileCahcesInRoomInfo = new Dictionary(); - public static void FetchRomFileInRoomInfo(this Protobuf_Room_MiniInfo roomInfo, EnumPlatform platform, Action callback) + public static void FetchRomFileInRoomInfo(this Protobuf_Room_MiniInfo roomInfo, EnumSupportEmuPlatform platform, Action callback) { RomFile romFile; @@ -45,10 +45,10 @@ namespace AxibugEmuOnline.Client } switch (platform) { - case EnumPlatform.NES: + case EnumSupportEmuPlatform.NES: App.StartCoroutine(App.httpAPI.GetNesRomInfo(roomInfo.GameRomID, (romWebData) => { - RomFile _romFile = new RomFile(EnumPlatform.NES, 0, 0); + RomFile _romFile = new RomFile(EnumSupportEmuPlatform.NES, 0, 0); _romFile.SetWebData(romWebData); s_RomFileCahcesInRoomInfo[roomInfo.GameRomID] = _romFile;