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

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