diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Filter/FilterManager.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Filter/FilterManager.cs index 054185a..bc28153 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Filter/FilterManager.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Filter/FilterManager.cs @@ -6,384 +6,397 @@ using UnityEngine; using static AxibugEmuOnline.Client.FilterEffect; namespace AxibugEmuOnline.Client -{ - public class FilterManager - { - private List m_filters; - private Dictionary m_filterPlatforms = new Dictionary(); - private AlphaWraper m_previewFilterWraper; - FilterRomSetting m_filterRomSetting; - /// - /// 滤镜列表 - /// - public IReadOnlyList Filters => m_filters; - - public FilterManager(CanvasGroup filterPreview, CanvasGroup mainBg) - { - m_filters = new List - { - new Filter(new FixingPixelArtGrille()), - new Filter(new LCDPostEffect()), - new Filter(new MattiasCRT()), - }; - var json = PlayerPrefs.GetString(nameof(FilterRomSetting)); - m_filterRomSetting = JsonUtility.FromJson(json) ?? new FilterRomSetting(); - - m_previewFilterWraper = new AlphaWraper(mainBg, filterPreview, false); - ShutDownFilterPreview(); - ShutDownFilter(); - } - - private RenderTexture result = null; - public Texture ExecuteFilterRender(Texture src) - { - if (result == null) - result = RenderTexture.GetTemporary(Screen.width, Screen.height); - else if (result.width != Screen.width || result.height != Screen.height) - { - RenderTexture.ReleaseTemporary(result); - result = RenderTexture.GetTemporary(Screen.width, Screen.height); - } - - bool anyFilterEnable = false; - foreach (var filter in Filters) - { - if (!filter.m_setting.Enable.GetValue()) continue; - filter.m_setting.Render(src, result); - anyFilterEnable = true; - } - - if (anyFilterEnable) - return result; - else - return src; - } - - /// 关闭滤镜预览 - public void ShutDownFilterPreview() - { - m_previewFilterWraper.On = false; - } - - /// 开启滤镜预览 - public void EnableFilterPreview() - { - m_previewFilterWraper.On = true; - } - - /// - /// 打开滤镜 - /// - /// - public void EnableFilter(Filter filter) - { - foreach (var selfFiler in Filters) - { - if (selfFiler != filter) selfFiler.m_setting.Enable.Override(false); - else selfFiler.m_setting.Enable.Override(true); - } - } - - /// - /// 关闭滤镜效果 - /// - public void ShutDownFilter() - { - //关闭所有后处理效果 - foreach (var filter in Filters) - filter.m_setting.Enable.Override(false); - } - - /// - /// 为指定rom设置滤镜以及滤镜的预设 - /// - /// rom对象 - /// 滤镜 - /// 滤镜预设 - public void SetupFilter(RomFile rom, Filter filter, FilterPreset preset) - { - m_filterRomSetting.Setup(rom, filter, preset); - - string json = m_filterRomSetting.ToJson(); - PlayerPrefs.SetString(nameof(FilterRomSetting), json); - } - - /// - /// 获得指定rom配置的滤镜设置 - /// - /// rom对象 - /// 此元组任意内任意成员都有可能为空 - public GetFilterSetting_result GetFilterSetting(RomFile rom) - { - var value = m_filterRomSetting.Get(rom); - Filter filter = null; - FilterPreset preset = null; - - //filter = Filters.FirstOrDefault(f => f.Name == value.filterName); - //if (filter != null) - //{ - // string presetName = value.presetName; - // preset = filter.Presets.FirstOrDefault(p => p.Name == presetName); - //} - - filter = Filters.FirstOrDefault(f => f.Name == value.Item1); - if (filter != null) - { - string presetName = value.Item2; - preset = filter.Presets.FirstOrDefault(p => p.Name == presetName); - } - - return new GetFilterSetting_result() - { - filter = filter, - preset = preset - }; - } - - public struct GetFilterSetting_result - { - public Filter filter; - public FilterPreset preset; - } - - public class Filter - { - public string Name => m_setting.Name; - public IReadOnlyCollection Paramerters => m_setting.EditableParam; - /// 滤镜预设 - public List Presets = new List(); - /// 滤镜默认预设 - public FilterPreset DefaultPreset = new FilterPreset("DEFAULT"); - - internal FilterEffect m_setting; - - public Filter(FilterEffect setting) - { - m_setting = setting; - - loadPresets(); - } - - private void loadPresets() - { - var json = PlayerPrefs.GetString($"Filter_{Name}_PresetList", string.Empty); - var loadedPresets = JsonUtility.FromJson(json); - if (loadedPresets == null) return; - else Presets = loadedPresets.presets; - } - - public void SavePresets() - { - var json = JsonUtility.ToJson(new FilterPresetList(Presets)); - PlayerPrefs.SetString($"Filter_{Name}_PresetList", json); - } - - public MsgBool CreatePreset(string presetName, out FilterPreset newPreset) - { - newPreset = null; - if (string.IsNullOrWhiteSpace(presetName)) return "名称不能为空"; - if (Presets.Count(p => p.Name == presetName) != 0) return "名称重复"; - - newPreset = new FilterPreset(presetName); - Presets.Add(newPreset); - - SavePresets(); - - return true; - } - - public void RemovePreset(FilterPreset preset) - { - if (!Presets.Remove(preset)) return; - SavePresets(); - - EventInvoker.RaiseFilterPresetRemoved(this, preset); - } - - public void ResetPreset() - { - foreach (var param in Paramerters) - { - param.ResetToDefault(); - } - } - - public void ApplyPreset(FilterPreset preset) - { - foreach (var param in Paramerters) - { - var value = preset.GetParamValue(param.Name, param.ValueType); - if (value == null) - param.ResetToDefault(); - else - param.Apply(value); - } - - } - - - } - - [Serializable] - private class FilterPresetList - { - public List presets; - - public FilterPresetList(List presets) - { - this.presets = presets; - foreach (var preset in presets) - { - preset.ReadyForJson(); - } - } - } - - [Serializable] - public class FilterPreset - { - [SerializeField] - public string Name; - [SerializeField] - private List m_paramName = new List(); - [SerializeField] - private List m_valueJson = new List(); - - private bool m_cacheReady = false; - private Dictionary m_paramName2ValueJson; - public FilterPreset(string presetName) - { - Name = presetName; - } - - public void ReadyForJson() - { - prepareCache(); - - m_paramName = m_paramName2ValueJson.Keys.ToList(); - m_valueJson = m_paramName2ValueJson.Values.ToList(); - } - - public string GetParamValueJson(string paramName) - { - prepareCache(); - string value; - m_paramName2ValueJson.TryGetValue(paramName, out value); - return value; - } - - public object GetParamValue(string paramName, Type valueType) - { - var rawStr = GetParamValueJson(paramName); - if (rawStr == null) return null; - - if (valueType == typeof(float)) - { - float floatVal; - float.TryParse(rawStr, out floatVal); - return floatVal; - } - else if (valueType.IsEnum) - { - var names = Enum.GetNames(valueType); - var values = Enum.GetValues(valueType); - - for (int i = 0; i < names.Length; i++) - { - if (names[i].Equals(rawStr)) - { - return values.GetValue(i); - } - } - return null; - } - else - { - App.log.Error($"尚未支持的滤镜参数类型{valueType}"); - return null; - } - } - - public void SetParamValue(string paramName, Type valueType, object value) - { - prepareCache(); - m_paramName2ValueJson[paramName] = value.ToString(); - } - - private void prepareCache() - { - if (m_cacheReady) return; - - m_paramName2ValueJson = new Dictionary(); - for (int i = 0; i < m_paramName.Count; i++) - { - m_paramName2ValueJson[m_paramName[i]] = m_valueJson[i]; - } - - m_cacheReady = true; - } - } - - [Serializable] - public class FilterRomSetting - { - [SerializeField] - private List m_romID; - [SerializeField] - private List m_items; - - bool m_cacheReady = false; - Dictionary m_cache; - - public void Setup(RomFile rom, Filter filter, FilterPreset preset) - { - prepareCache(); - - if (filter == null) - m_cache.Remove(rom.ID); - else - m_cache[rom.ID] = new Item { FilterName = filter.Name, PresetName = preset != null ? preset.Name : null }; - } - - public string ToJson() - { - prepareCache(); - m_romID = m_cache.Keys.ToList(); - m_items = m_cache.Values.ToList(); - - return JsonUtility.ToJson(this); - } - - public ValueTuple Get(RomFile rom) - { - prepareCache(); - - Item item; - m_cache.TryGetValue(rom.ID, out item); - return new ValueTuple(item.FilterName, item.PresetName); - } - - private void prepareCache() - { - if (m_cacheReady) return; - - if (m_items == null) m_items = new List(); - if (m_romID == null) m_romID = new List(); - m_cache = new Dictionary(); - for (int i = 0; i < m_romID.Count && i < m_items.Count; i++) - { - m_cache[m_romID[i]] = m_items[i]; - } - - m_cacheReady = true; - } - - [Serializable] - struct Item - { - public string FilterName; - public string PresetName; - } - } - } +{ + public class FilterManager + { + private List m_filters; + private Dictionary m_filterPlatforms = new Dictionary(); + private AlphaWraper m_previewFilterWraper; + FilterRomSetting m_filterRomSetting; + /// + /// 滤镜列表 + /// + public IReadOnlyList Filters => m_filters; + + public FilterManager(CanvasGroup filterPreview, CanvasGroup mainBg) + { +#if UNITY_PSP2 + m_filters = new List(); + m_filterRomSetting = new FilterRomSetting(); + m_previewFilterWraper = new AlphaWraper(mainBg, filterPreview, false); + return; +#endif + + m_filters = new List + { + new Filter(new FixingPixelArtGrille()), + new Filter(new LCDPostEffect()), + new Filter(new MattiasCRT()), + }; + var json = PlayerPrefs.GetString(nameof(FilterRomSetting)); + m_filterRomSetting = JsonUtility.FromJson(json) ?? new FilterRomSetting(); + + m_previewFilterWraper = new AlphaWraper(mainBg, filterPreview, false); + ShutDownFilterPreview(); + ShutDownFilter(); + } + + private RenderTexture result = null; + public Texture ExecuteFilterRender(Texture src) + { + if (result == null) + { + //result = RenderTexture.GetTemporary(Screen.width, Screen.height); + result = Initer.instance.renderTest; + } + else if (result.width != Screen.width || result.height != Screen.height) + { + //RenderTexture.ReleaseTemporary(result); + //result = RenderTexture.GetTemporary(Screen.width, Screen.height); + result = Initer.instance.renderTest; + } + + + + bool anyFilterEnable = false; + foreach (var filter in Filters) + { + if (!filter.m_setting.Enable.GetValue()) continue; + filter.m_setting.Render(src, result); + anyFilterEnable = true; + } + + if (anyFilterEnable) + return result; + else + return src; + } + + /// 关闭滤镜预览 + public void ShutDownFilterPreview() + { + m_previewFilterWraper.On = false; + } + + /// 开启滤镜预览 + public void EnableFilterPreview() + { + m_previewFilterWraper.On = true; + } + + /// + /// 打开滤镜 + /// + /// + public void EnableFilter(Filter filter) + { + foreach (var selfFiler in Filters) + { + if (selfFiler != filter) selfFiler.m_setting.Enable.Override(false); + else selfFiler.m_setting.Enable.Override(true); + } + } + + /// + /// 关闭滤镜效果 + /// + public void ShutDownFilter() + { + //关闭所有后处理效果 + foreach (var filter in Filters) + filter.m_setting.Enable.Override(false); + } + + /// + /// 为指定rom设置滤镜以及滤镜的预设 + /// + /// rom对象 + /// 滤镜 + /// 滤镜预设 + public void SetupFilter(RomFile rom, Filter filter, FilterPreset preset) + { + m_filterRomSetting.Setup(rom, filter, preset); + + string json = m_filterRomSetting.ToJson(); + PlayerPrefs.SetString(nameof(FilterRomSetting), json); + } + + /// + /// 获得指定rom配置的滤镜设置 + /// + /// rom对象 + /// 此元组任意内任意成员都有可能为空 + public GetFilterSetting_result GetFilterSetting(RomFile rom) + { + var value = m_filterRomSetting.Get(rom); + Filter filter = null; + FilterPreset preset = null; + + //filter = Filters.FirstOrDefault(f => f.Name == value.filterName); + //if (filter != null) + //{ + // string presetName = value.presetName; + // preset = filter.Presets.FirstOrDefault(p => p.Name == presetName); + //} + + filter = Filters.FirstOrDefault(f => f.Name == value.Item1); + if (filter != null) + { + string presetName = value.Item2; + preset = filter.Presets.FirstOrDefault(p => p.Name == presetName); + } + + return new GetFilterSetting_result() + { + filter = filter, + preset = preset + }; + } + + public struct GetFilterSetting_result + { + public Filter filter; + public FilterPreset preset; + } + + public class Filter + { + public string Name => m_setting.Name; + public IReadOnlyCollection Paramerters => m_setting.EditableParam; + /// 滤镜预设 + public List Presets = new List(); + /// 滤镜默认预设 + public FilterPreset DefaultPreset = new FilterPreset("DEFAULT"); + + internal FilterEffect m_setting; + + public Filter(FilterEffect setting) + { + m_setting = setting; + + loadPresets(); + } + + private void loadPresets() + { + var json = PlayerPrefs.GetString($"Filter_{Name}_PresetList", string.Empty); + var loadedPresets = JsonUtility.FromJson(json); + if (loadedPresets == null) return; + else Presets = loadedPresets.presets; + } + + public void SavePresets() + { + var json = JsonUtility.ToJson(new FilterPresetList(Presets)); + PlayerPrefs.SetString($"Filter_{Name}_PresetList", json); + } + + public MsgBool CreatePreset(string presetName, out FilterPreset newPreset) + { + newPreset = null; + if (string.IsNullOrWhiteSpace(presetName)) return "名称不能为空"; + if (Presets.Count(p => p.Name == presetName) != 0) return "名称重复"; + + newPreset = new FilterPreset(presetName); + Presets.Add(newPreset); + + SavePresets(); + + return true; + } + + public void RemovePreset(FilterPreset preset) + { + if (!Presets.Remove(preset)) return; + SavePresets(); + + EventInvoker.RaiseFilterPresetRemoved(this, preset); + } + + public void ResetPreset() + { + foreach (var param in Paramerters) + { + param.ResetToDefault(); + } + } + + public void ApplyPreset(FilterPreset preset) + { + foreach (var param in Paramerters) + { + var value = preset.GetParamValue(param.Name, param.ValueType); + if (value == null) + param.ResetToDefault(); + else + param.Apply(value); + } + + } + + + } + + [Serializable] + private class FilterPresetList + { + public List presets; + + public FilterPresetList(List presets) + { + this.presets = presets; + foreach (var preset in presets) + { + preset.ReadyForJson(); + } + } + } + + [Serializable] + public class FilterPreset + { + [SerializeField] + public string Name; + [SerializeField] + private List m_paramName = new List(); + [SerializeField] + private List m_valueJson = new List(); + + private bool m_cacheReady = false; + private Dictionary m_paramName2ValueJson; + public FilterPreset(string presetName) + { + Name = presetName; + } + + public void ReadyForJson() + { + prepareCache(); + + m_paramName = m_paramName2ValueJson.Keys.ToList(); + m_valueJson = m_paramName2ValueJson.Values.ToList(); + } + + public string GetParamValueJson(string paramName) + { + prepareCache(); + string value; + m_paramName2ValueJson.TryGetValue(paramName, out value); + return value; + } + + public object GetParamValue(string paramName, Type valueType) + { + var rawStr = GetParamValueJson(paramName); + if (rawStr == null) return null; + + if (valueType == typeof(float)) + { + float floatVal; + float.TryParse(rawStr, out floatVal); + return floatVal; + } + else if (valueType.IsEnum) + { + var names = Enum.GetNames(valueType); + var values = Enum.GetValues(valueType); + + for (int i = 0; i < names.Length; i++) + { + if (names[i].Equals(rawStr)) + { + return values.GetValue(i); + } + } + return null; + } + else + { + App.log.Error($"尚未支持的滤镜参数类型{valueType}"); + return null; + } + } + + public void SetParamValue(string paramName, Type valueType, object value) + { + prepareCache(); + m_paramName2ValueJson[paramName] = value.ToString(); + } + + private void prepareCache() + { + if (m_cacheReady) return; + + m_paramName2ValueJson = new Dictionary(); + for (int i = 0; i < m_paramName.Count; i++) + { + m_paramName2ValueJson[m_paramName[i]] = m_valueJson[i]; + } + + m_cacheReady = true; + } + } + + [Serializable] + public class FilterRomSetting + { + [SerializeField] + private List m_romID; + [SerializeField] + private List m_items; + + bool m_cacheReady = false; + Dictionary m_cache; + + public void Setup(RomFile rom, Filter filter, FilterPreset preset) + { + prepareCache(); + + if (filter == null) + m_cache.Remove(rom.ID); + else + m_cache[rom.ID] = new Item { FilterName = filter.Name, PresetName = preset != null ? preset.Name : null }; + } + + public string ToJson() + { + prepareCache(); + m_romID = m_cache.Keys.ToList(); + m_items = m_cache.Values.ToList(); + + return JsonUtility.ToJson(this); + } + + public ValueTuple Get(RomFile rom) + { + prepareCache(); + + Item item; + m_cache.TryGetValue(rom.ID, out item); + return new ValueTuple(item.FilterName, item.PresetName); + } + + private void prepareCache() + { + if (m_cacheReady) return; + + if (m_items == null) m_items = new List(); + if (m_romID == null) m_romID = new List(); + m_cache = new Dictionary(); + for (int i = 0; i < m_romID.Count && i < m_items.Count; i++) + { + m_cache[m_romID[i]] = m_items[i]; + } + + m_cacheReady = true; + } + + [Serializable] + struct Item + { + public string FilterName; + public string PresetName; + } + } + } } diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/HttpAPI.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/HttpAPI.cs index d59566a..a0b35c0 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/HttpAPI.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/HttpAPI.cs @@ -2,6 +2,7 @@ using AxibugEmuOnline.Client.ClientCore; using System; using System.Collections; using System.Collections.Generic; +using System.Text; using UnityEngine; using UnityEngine.Networking; @@ -14,7 +15,27 @@ namespace AxibugEmuOnline.Client public delegate void GetRomListAPI(Action callback, int page, int pageSize = 10); public delegate void SearchRomListAPI(Action callback, string searchKey, int page, int pageSize = 10); + public static string UrlEncode(string str) + { + StringBuilder sb = new StringBuilder(); + foreach (char c in str) + { + if ((c >= '0' && c <= '9') || + (c >= 'a' && c <= 'z') || + (c >= 'A' && c <= 'Z') || + c == '-' || c == '_' || c == '.' || c == '!' || c == '~' || c == '*' || c == '\'' || c == '(' || c == ')') + { + sb.Append(c); + } + else + { + sb.Append('%').Append(((int)c).ToString("X2")); + } + } + + return sb.ToString(); + } public void GetNesRomList(Action callback, int page, int pageSize = 10) { App.StartCoroutine(GetNesRomListFlow(page, pageSize, callback)); @@ -26,6 +47,13 @@ namespace AxibugEmuOnline.Client } private IEnumerator SearchNesRomListFlow(string searchKey, int page, int pageSize, Action callback) { + //避免特殊字符和个别文字编码问题 + byte[] gb2312Bytes = Encoding.Default.GetBytes(searchKey); + byte[] utf8Bytes = Encoding.Convert(Encoding.Default, Encoding.UTF8, gb2312Bytes); + // 将UTF-8编码的字节数组转换回字符串(此时是UTF-8编码的字符串) + string utf8String = Encoding.UTF8.GetString(utf8Bytes); + searchKey = UrlEncode(utf8String); + App.log.Info($"search->{utf8String} ->{searchKey}"); AxiHttpProxy.SendWebRequestProxy request = AxiHttpProxy.Get($"{WebSiteApi}/NesRomList?Page={page}&PageSize={pageSize}&SearchKey={searchKey}"); yield return request.SendWebRequest; diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/PSVita/SonyVitaCommonDialog.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/PSVita/SonyVitaCommonDialog.cs index dd8420d..dc1a0a8 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/PSVita/SonyVitaCommonDialog.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/PSVita/SonyVitaCommonDialog.cs @@ -18,9 +18,11 @@ public class SonyVitaCommonDialog : MonoBehaviour Sony.Vita.Dialog.Ime.ImeDialogParams info = new Sony.Vita.Dialog.Ime.ImeDialogParams(); // Set supported languages, 'or' flags together or set to 0 to support all languages. - info.supportedLanguages = Sony.Vita.Dialog.Ime.FlagsSupportedLanguages.LANGUAGE_JAPANESE | + info.supportedLanguages = Sony.Vita.Dialog.Ime.FlagsSupportedLanguages.LANGUAGE_SIMPLIFIED_CHINESE | + Sony.Vita.Dialog.Ime.FlagsSupportedLanguages.LANGUAGE_JAPANESE | Sony.Vita.Dialog.Ime.FlagsSupportedLanguages.LANGUAGE_ENGLISH_GB | - Sony.Vita.Dialog.Ime.FlagsSupportedLanguages.LANGUAGE_DANISH; + Sony.Vita.Dialog.Ime.FlagsSupportedLanguages.LANGUAGE_TRADITIONAL_CHINESE; + info.languagesForced = true; info.type = Sony.Vita.Dialog.Ime.EnumImeDialogType.TYPE_DEFAULT; diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/OverlayUI/OverlayManager.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/OverlayUI/OverlayManager.cs index 0f62a3b..8ea6da9 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/OverlayUI/OverlayManager.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/OverlayUI/OverlayManager.cs @@ -23,7 +23,7 @@ namespace AxibugEmuOnline.Client public static void Input(Action callback, string placeHolder, string defaultText) { -#if UNITY_PSP2 +#if UNITY_PSP2 && !UNITY_EDITOR App.sonyVitaCommonDialog.ShowPSVitaIME(callback, placeHolder, defaultText); #else s_ins.m_InputUI.Show(new ValueTuple, string, string>(callback, placeHolder, defaultText));