psv中文输入,PSV暂时屏蔽滤镜,httpapi搜索处理部分

This commit is contained in:
sin365 2024-12-26 02:22:56 +08:00
parent fca038e67d
commit 62fbb6e11b
4 changed files with 426 additions and 383 deletions

View File

@ -6,384 +6,397 @@ using UnityEngine;
using static AxibugEmuOnline.Client.FilterEffect; using static AxibugEmuOnline.Client.FilterEffect;
namespace AxibugEmuOnline.Client namespace AxibugEmuOnline.Client
{ {
public class FilterManager public class FilterManager
{ {
private List<Filter> m_filters; private List<Filter> m_filters;
private Dictionary<EnumPlatform, Filter> m_filterPlatforms = new Dictionary<EnumPlatform, Filter>(); private Dictionary<EnumPlatform, Filter> m_filterPlatforms = new Dictionary<EnumPlatform, Filter>();
private AlphaWraper m_previewFilterWraper; private AlphaWraper m_previewFilterWraper;
FilterRomSetting m_filterRomSetting; FilterRomSetting m_filterRomSetting;
/// <summary> /// <summary>
/// 滤镜列表 /// 滤镜列表
/// </summary> /// </summary>
public IReadOnlyList<Filter> Filters => m_filters; public IReadOnlyList<Filter> Filters => m_filters;
public FilterManager(CanvasGroup filterPreview, CanvasGroup mainBg) public FilterManager(CanvasGroup filterPreview, CanvasGroup mainBg)
{ {
m_filters = new List<Filter> #if UNITY_PSP2
{ m_filters = new List<Filter>();
new Filter(new FixingPixelArtGrille()), m_filterRomSetting = new FilterRomSetting();
new Filter(new LCDPostEffect()), m_previewFilterWraper = new AlphaWraper(mainBg, filterPreview, false);
new Filter(new MattiasCRT()), return;
}; #endif
var json = PlayerPrefs.GetString(nameof(FilterRomSetting));
m_filterRomSetting = JsonUtility.FromJson<FilterRomSetting>(json) ?? new FilterRomSetting(); m_filters = new List<Filter>
{
m_previewFilterWraper = new AlphaWraper(mainBg, filterPreview, false); new Filter(new FixingPixelArtGrille()),
ShutDownFilterPreview(); new Filter(new LCDPostEffect()),
ShutDownFilter(); new Filter(new MattiasCRT()),
} };
var json = PlayerPrefs.GetString(nameof(FilterRomSetting));
private RenderTexture result = null; m_filterRomSetting = JsonUtility.FromJson<FilterRomSetting>(json) ?? new FilterRomSetting();
public Texture ExecuteFilterRender(Texture src)
{ m_previewFilterWraper = new AlphaWraper(mainBg, filterPreview, false);
if (result == null) ShutDownFilterPreview();
result = RenderTexture.GetTemporary(Screen.width, Screen.height); ShutDownFilter();
else if (result.width != Screen.width || result.height != Screen.height) }
{
RenderTexture.ReleaseTemporary(result); private RenderTexture result = null;
result = RenderTexture.GetTemporary(Screen.width, Screen.height); public Texture ExecuteFilterRender(Texture src)
} {
if (result == null)
bool anyFilterEnable = false; {
foreach (var filter in Filters) //result = RenderTexture.GetTemporary(Screen.width, Screen.height);
{ result = Initer.instance.renderTest;
if (!filter.m_setting.Enable.GetValue()) continue; }
filter.m_setting.Render(src, result); else if (result.width != Screen.width || result.height != Screen.height)
anyFilterEnable = true; {
} //RenderTexture.ReleaseTemporary(result);
//result = RenderTexture.GetTemporary(Screen.width, Screen.height);
if (anyFilterEnable) result = Initer.instance.renderTest;
return result; }
else
return src;
}
bool anyFilterEnable = false;
/// <summary> 关闭滤镜预览 </summary> foreach (var filter in Filters)
public void ShutDownFilterPreview() {
{ if (!filter.m_setting.Enable.GetValue()) continue;
m_previewFilterWraper.On = false; filter.m_setting.Render(src, result);
} anyFilterEnable = true;
}
/// <summary> 开启滤镜预览 </summary>
public void EnableFilterPreview() if (anyFilterEnable)
{ return result;
m_previewFilterWraper.On = true; else
} return src;
}
/// <summary>
/// 打开滤镜 /// <summary> 关闭滤镜预览 </summary>
/// </summary> public void ShutDownFilterPreview()
/// <param name="filter"></param> {
public void EnableFilter(Filter filter) m_previewFilterWraper.On = false;
{ }
foreach (var selfFiler in Filters)
{ /// <summary> 开启滤镜预览 </summary>
if (selfFiler != filter) selfFiler.m_setting.Enable.Override(false); public void EnableFilterPreview()
else selfFiler.m_setting.Enable.Override(true); {
} m_previewFilterWraper.On = true;
} }
/// <summary> /// <summary>
/// 关闭滤镜效果 /// 打开滤镜
/// </summary> /// </summary>
public void ShutDownFilter() /// <param name="filter"></param>
{ public void EnableFilter(Filter filter)
//关闭所有后处理效果 {
foreach (var filter in Filters) foreach (var selfFiler in Filters)
filter.m_setting.Enable.Override(false); {
} if (selfFiler != filter) selfFiler.m_setting.Enable.Override(false);
else selfFiler.m_setting.Enable.Override(true);
/// <summary> }
/// 为指定rom设置滤镜以及滤镜的预设 }
/// </summary>
/// <param name="rom">rom对象</param> /// <summary>
/// <param name="filter">滤镜</param> /// 关闭滤镜效果
/// <param name="preset">滤镜预设</param> /// </summary>
public void SetupFilter(RomFile rom, Filter filter, FilterPreset preset) public void ShutDownFilter()
{ {
m_filterRomSetting.Setup(rom, filter, preset); //关闭所有后处理效果
foreach (var filter in Filters)
string json = m_filterRomSetting.ToJson(); filter.m_setting.Enable.Override(false);
PlayerPrefs.SetString(nameof(FilterRomSetting), json); }
}
/// <summary>
/// <summary> /// 为指定rom设置滤镜以及滤镜的预设
/// 获得指定rom配置的滤镜设置 /// </summary>
/// </summary> /// <param name="rom">rom对象</param>
/// <param name="rom">rom对象</param> /// <param name="filter">滤镜</param>
/// <returns>此元组任意内任意成员都有可能为空</returns> /// <param name="preset">滤镜预设</param>
public GetFilterSetting_result GetFilterSetting(RomFile rom) public void SetupFilter(RomFile rom, Filter filter, FilterPreset preset)
{ {
var value = m_filterRomSetting.Get(rom); m_filterRomSetting.Setup(rom, filter, preset);
Filter filter = null;
FilterPreset preset = null; string json = m_filterRomSetting.ToJson();
PlayerPrefs.SetString(nameof(FilterRomSetting), json);
//filter = Filters.FirstOrDefault(f => f.Name == value.filterName); }
//if (filter != null)
//{ /// <summary>
// string presetName = value.presetName; /// 获得指定rom配置的滤镜设置
// preset = filter.Presets.FirstOrDefault(p => p.Name == presetName); /// </summary>
//} /// <param name="rom">rom对象</param>
/// <returns>此元组任意内任意成员都有可能为空</returns>
filter = Filters.FirstOrDefault(f => f.Name == value.Item1); public GetFilterSetting_result GetFilterSetting(RomFile rom)
if (filter != null) {
{ var value = m_filterRomSetting.Get(rom);
string presetName = value.Item2; Filter filter = null;
preset = filter.Presets.FirstOrDefault(p => p.Name == presetName); FilterPreset preset = null;
}
//filter = Filters.FirstOrDefault(f => f.Name == value.filterName);
return new GetFilterSetting_result() //if (filter != null)
{ //{
filter = filter, // string presetName = value.presetName;
preset = preset // preset = filter.Presets.FirstOrDefault(p => p.Name == presetName);
}; //}
}
filter = Filters.FirstOrDefault(f => f.Name == value.Item1);
public struct GetFilterSetting_result if (filter != null)
{ {
public Filter filter; string presetName = value.Item2;
public FilterPreset preset; preset = filter.Presets.FirstOrDefault(p => p.Name == presetName);
} }
public class Filter return new GetFilterSetting_result()
{ {
public string Name => m_setting.Name; filter = filter,
public IReadOnlyCollection<EditableParamerter> Paramerters => m_setting.EditableParam; preset = preset
/// <summary> 滤镜预设 </summary> };
public List<FilterPreset> Presets = new List<FilterPreset>(); }
/// <summary> 滤镜默认预设 </summary>
public FilterPreset DefaultPreset = new FilterPreset("DEFAULT"); public struct GetFilterSetting_result
{
internal FilterEffect m_setting; public Filter filter;
public FilterPreset preset;
public Filter(FilterEffect setting) }
{
m_setting = setting; public class Filter
{
loadPresets(); public string Name => m_setting.Name;
} public IReadOnlyCollection<EditableParamerter> Paramerters => m_setting.EditableParam;
/// <summary> 滤镜预设 </summary>
private void loadPresets() public List<FilterPreset> Presets = new List<FilterPreset>();
{ /// <summary> 滤镜默认预设 </summary>
var json = PlayerPrefs.GetString($"Filter_{Name}_PresetList", string.Empty); public FilterPreset DefaultPreset = new FilterPreset("DEFAULT");
var loadedPresets = JsonUtility.FromJson<FilterPresetList>(json);
if (loadedPresets == null) return; internal FilterEffect m_setting;
else Presets = loadedPresets.presets;
} public Filter(FilterEffect setting)
{
public void SavePresets() m_setting = setting;
{
var json = JsonUtility.ToJson(new FilterPresetList(Presets)); loadPresets();
PlayerPrefs.SetString($"Filter_{Name}_PresetList", json); }
}
private void loadPresets()
public MsgBool CreatePreset(string presetName, out FilterPreset newPreset) {
{ var json = PlayerPrefs.GetString($"Filter_{Name}_PresetList", string.Empty);
newPreset = null; var loadedPresets = JsonUtility.FromJson<FilterPresetList>(json);
if (string.IsNullOrWhiteSpace(presetName)) return "名称不能为空"; if (loadedPresets == null) return;
if (Presets.Count(p => p.Name == presetName) != 0) return "名称重复"; else Presets = loadedPresets.presets;
}
newPreset = new FilterPreset(presetName);
Presets.Add(newPreset); public void SavePresets()
{
SavePresets(); var json = JsonUtility.ToJson(new FilterPresetList(Presets));
PlayerPrefs.SetString($"Filter_{Name}_PresetList", json);
return true; }
}
public MsgBool CreatePreset(string presetName, out FilterPreset newPreset)
public void RemovePreset(FilterPreset preset) {
{ newPreset = null;
if (!Presets.Remove(preset)) return; if (string.IsNullOrWhiteSpace(presetName)) return "名称不能为空";
SavePresets(); if (Presets.Count(p => p.Name == presetName) != 0) return "名称重复";
EventInvoker.RaiseFilterPresetRemoved(this, preset); newPreset = new FilterPreset(presetName);
} Presets.Add(newPreset);
public void ResetPreset() SavePresets();
{
foreach (var param in Paramerters) return true;
{ }
param.ResetToDefault();
} public void RemovePreset(FilterPreset preset)
} {
if (!Presets.Remove(preset)) return;
public void ApplyPreset(FilterPreset preset) SavePresets();
{
foreach (var param in Paramerters) EventInvoker.RaiseFilterPresetRemoved(this, preset);
{ }
var value = preset.GetParamValue(param.Name, param.ValueType);
if (value == null) public void ResetPreset()
param.ResetToDefault(); {
else foreach (var param in Paramerters)
param.Apply(value); {
} param.ResetToDefault();
}
} }
public void ApplyPreset(FilterPreset preset)
} {
foreach (var param in Paramerters)
[Serializable] {
private class FilterPresetList var value = preset.GetParamValue(param.Name, param.ValueType);
{ if (value == null)
public List<FilterPreset> presets; param.ResetToDefault();
else
public FilterPresetList(List<FilterPreset> presets) param.Apply(value);
{ }
this.presets = presets;
foreach (var preset in presets) }
{
preset.ReadyForJson();
} }
}
} [Serializable]
private class FilterPresetList
[Serializable] {
public class FilterPreset public List<FilterPreset> presets;
{
[SerializeField] public FilterPresetList(List<FilterPreset> presets)
public string Name; {
[SerializeField] this.presets = presets;
private List<string> m_paramName = new List<string>(); foreach (var preset in presets)
[SerializeField] {
private List<string> m_valueJson = new List<string>(); preset.ReadyForJson();
}
private bool m_cacheReady = false; }
private Dictionary<string, string> m_paramName2ValueJson; }
public FilterPreset(string presetName)
{ [Serializable]
Name = presetName; public class FilterPreset
} {
[SerializeField]
public void ReadyForJson() public string Name;
{ [SerializeField]
prepareCache(); private List<string> m_paramName = new List<string>();
[SerializeField]
m_paramName = m_paramName2ValueJson.Keys.ToList(); private List<string> m_valueJson = new List<string>();
m_valueJson = m_paramName2ValueJson.Values.ToList();
} private bool m_cacheReady = false;
private Dictionary<string, string> m_paramName2ValueJson;
public string GetParamValueJson(string paramName) public FilterPreset(string presetName)
{ {
prepareCache(); Name = presetName;
string value; }
m_paramName2ValueJson.TryGetValue(paramName, out value);
return value; public void ReadyForJson()
} {
prepareCache();
public object GetParamValue(string paramName, Type valueType)
{ m_paramName = m_paramName2ValueJson.Keys.ToList();
var rawStr = GetParamValueJson(paramName); m_valueJson = m_paramName2ValueJson.Values.ToList();
if (rawStr == null) return null; }
if (valueType == typeof(float)) public string GetParamValueJson(string paramName)
{ {
float floatVal; prepareCache();
float.TryParse(rawStr, out floatVal); string value;
return floatVal; m_paramName2ValueJson.TryGetValue(paramName, out value);
} return value;
else if (valueType.IsEnum) }
{
var names = Enum.GetNames(valueType); public object GetParamValue(string paramName, Type valueType)
var values = Enum.GetValues(valueType); {
var rawStr = GetParamValueJson(paramName);
for (int i = 0; i < names.Length; i++) if (rawStr == null) return null;
{
if (names[i].Equals(rawStr)) if (valueType == typeof(float))
{ {
return values.GetValue(i); float floatVal;
} float.TryParse(rawStr, out floatVal);
} return floatVal;
return null; }
} else if (valueType.IsEnum)
else {
{ var names = Enum.GetNames(valueType);
App.log.Error($"尚未支持的滤镜参数类型{valueType}"); var values = Enum.GetValues(valueType);
return null;
} for (int i = 0; i < names.Length; i++)
} {
if (names[i].Equals(rawStr))
public void SetParamValue(string paramName, Type valueType, object value) {
{ return values.GetValue(i);
prepareCache(); }
m_paramName2ValueJson[paramName] = value.ToString(); }
} return null;
}
private void prepareCache() else
{ {
if (m_cacheReady) return; App.log.Error($"尚未支持的滤镜参数类型{valueType}");
return null;
m_paramName2ValueJson = new Dictionary<string, string>(); }
for (int i = 0; i < m_paramName.Count; i++) }
{
m_paramName2ValueJson[m_paramName[i]] = m_valueJson[i]; public void SetParamValue(string paramName, Type valueType, object value)
} {
prepareCache();
m_cacheReady = true; m_paramName2ValueJson[paramName] = value.ToString();
} }
}
private void prepareCache()
[Serializable] {
public class FilterRomSetting if (m_cacheReady) return;
{
[SerializeField] m_paramName2ValueJson = new Dictionary<string, string>();
private List<int> m_romID; for (int i = 0; i < m_paramName.Count; i++)
[SerializeField] {
private List<Item> m_items; m_paramName2ValueJson[m_paramName[i]] = m_valueJson[i];
}
bool m_cacheReady = false;
Dictionary<int, Item> m_cache; m_cacheReady = true;
}
public void Setup(RomFile rom, Filter filter, FilterPreset preset) }
{
prepareCache(); [Serializable]
public class FilterRomSetting
if (filter == null) {
m_cache.Remove(rom.ID); [SerializeField]
else private List<int> m_romID;
m_cache[rom.ID] = new Item { FilterName = filter.Name, PresetName = preset != null ? preset.Name : null }; [SerializeField]
} private List<Item> m_items;
public string ToJson() bool m_cacheReady = false;
{ Dictionary<int, Item> m_cache;
prepareCache();
m_romID = m_cache.Keys.ToList(); public void Setup(RomFile rom, Filter filter, FilterPreset preset)
m_items = m_cache.Values.ToList(); {
prepareCache();
return JsonUtility.ToJson(this);
} if (filter == null)
m_cache.Remove(rom.ID);
public ValueTuple<string, string> Get(RomFile rom) else
{ m_cache[rom.ID] = new Item { FilterName = filter.Name, PresetName = preset != null ? preset.Name : null };
prepareCache(); }
Item item; public string ToJson()
m_cache.TryGetValue(rom.ID, out item); {
return new ValueTuple<string, string>(item.FilterName, item.PresetName); prepareCache();
} m_romID = m_cache.Keys.ToList();
m_items = m_cache.Values.ToList();
private void prepareCache()
{ return JsonUtility.ToJson(this);
if (m_cacheReady) return; }
if (m_items == null) m_items = new List<Item>(); public ValueTuple<string, string> Get(RomFile rom)
if (m_romID == null) m_romID = new List<int>(); {
m_cache = new Dictionary<int, Item>(); prepareCache();
for (int i = 0; i < m_romID.Count && i < m_items.Count; i++)
{ Item item;
m_cache[m_romID[i]] = m_items[i]; m_cache.TryGetValue(rom.ID, out item);
} return new ValueTuple<string, string>(item.FilterName, item.PresetName);
}
m_cacheReady = true;
} private void prepareCache()
{
[Serializable] if (m_cacheReady) return;
struct Item
{ if (m_items == null) m_items = new List<Item>();
public string FilterName; if (m_romID == null) m_romID = new List<int>();
public string PresetName; m_cache = new Dictionary<int, Item>();
} 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;
}
}
}
} }

View File

@ -2,6 +2,7 @@ using AxibugEmuOnline.Client.ClientCore;
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text;
using UnityEngine; using UnityEngine;
using UnityEngine.Networking; using UnityEngine.Networking;
@ -14,7 +15,27 @@ namespace AxibugEmuOnline.Client
public delegate void GetRomListAPI(Action<Resp_GameList> callback, int page, int pageSize = 10); public delegate void GetRomListAPI(Action<Resp_GameList> callback, int page, int pageSize = 10);
public delegate void SearchRomListAPI(Action<Resp_GameList> callback, string searchKey, int page, int pageSize = 10); public delegate void SearchRomListAPI(Action<Resp_GameList> 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<Resp_GameList> callback, int page, int pageSize = 10) public void GetNesRomList(Action<Resp_GameList> callback, int page, int pageSize = 10)
{ {
App.StartCoroutine(GetNesRomListFlow(page, pageSize, callback)); App.StartCoroutine(GetNesRomListFlow(page, pageSize, callback));
@ -26,6 +47,13 @@ namespace AxibugEmuOnline.Client
} }
private IEnumerator SearchNesRomListFlow(string searchKey, int page, int pageSize, Action<Resp_GameList> callback) private IEnumerator SearchNesRomListFlow(string searchKey, int page, int pageSize, Action<Resp_GameList> 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}"); AxiHttpProxy.SendWebRequestProxy request = AxiHttpProxy.Get($"{WebSiteApi}/NesRomList?Page={page}&PageSize={pageSize}&SearchKey={searchKey}");
yield return request.SendWebRequest; yield return request.SendWebRequest;

View File

@ -18,9 +18,11 @@ public class SonyVitaCommonDialog : MonoBehaviour
Sony.Vita.Dialog.Ime.ImeDialogParams info = new Sony.Vita.Dialog.Ime.ImeDialogParams(); 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. // 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_ENGLISH_GB |
Sony.Vita.Dialog.Ime.FlagsSupportedLanguages.LANGUAGE_DANISH; Sony.Vita.Dialog.Ime.FlagsSupportedLanguages.LANGUAGE_TRADITIONAL_CHINESE;
info.languagesForced = true; info.languagesForced = true;
info.type = Sony.Vita.Dialog.Ime.EnumImeDialogType.TYPE_DEFAULT; info.type = Sony.Vita.Dialog.Ime.EnumImeDialogType.TYPE_DEFAULT;

View File

@ -23,7 +23,7 @@ namespace AxibugEmuOnline.Client
public static void Input(Action<string> callback, string placeHolder, string defaultText) public static void Input(Action<string> callback, string placeHolder, string defaultText)
{ {
#if UNITY_PSP2 #if UNITY_PSP2 && !UNITY_EDITOR
App.sonyVitaCommonDialog.ShowPSVitaIME(callback, placeHolder, defaultText); App.sonyVitaCommonDialog.ShowPSVitaIME(callback, placeHolder, defaultText);
#else #else
s_ins.m_InputUI.Show(new ValueTuple<Action<string>, string, string>(callback, placeHolder, defaultText)); s_ins.m_InputUI.Show(new ValueTuple<Action<string>, string, string>(callback, placeHolder, defaultText));