97 Commits

Author SHA1 Message Date
b45cf9cba7 Fix incorrect layout width for tabs on enable. 2023-11-12 01:05:06 +08:00
28234d9587 Replace menu scene in build settings. 2023-11-11 11:57:09 +08:00
1803e1dee7 Implement the new settings browser. 2023-11-11 11:56:36 +08:00
166478e4bb Implement browser tabs. 2023-11-11 11:54:52 +08:00
c05b771425 Add description property to property adapter. 2023-11-11 11:42:05 +08:00
9db2ded366 Rename render distance settings. 2023-11-11 11:40:48 +08:00
9aed79f599 Rearrange the categories of the settings. 2023-11-11 11:39:53 +08:00
221887e447 Code cleanup. 2023-11-10 15:01:44 +08:00
36013d4e47 Update Cryville.Common.Reflection. 2023-11-10 15:00:38 +08:00
cf8dda1ea2 Add animations for browser item tile. 2023-11-10 15:00:14 +08:00
0f4aec4355 Implement drafted new UI. 2023-11-10 14:59:28 +08:00
ddf738ee27 Pull down IPathedResourceManager. Reconstruct resource browser. 2023-11-10 14:57:52 +08:00
bd834cff4a Add tweener and state tweener. 2023-11-10 14:51:14 +08:00
adf5019e2a Add null check for some UI components. 2023-11-10 14:50:15 +08:00
a19a3d9b81 Remove use of animator in UI. 2023-11-10 14:48:17 +08:00
b50f771d6e Clean up hardcoded UI paths. 2023-11-10 14:45:23 +08:00
8089e724f9 Add single layout group. 2023-11-10 14:35:02 +08:00
18f9fbea60 Add safe area. 2023-11-10 14:34:47 +08:00
6ea487ff13 Import new UI assets. 2023-11-10 14:34:01 +08:00
a83b16c829 Remove UIElements package. 2023-11-10 14:33:07 +08:00
b48bd7b8ba Code cleanup. 2023-11-10 14:32:28 +08:00
b56722b2d1 Add vertical mode for ImageSliced3. 2023-11-07 16:17:41 +08:00
5854801a53 Fix UI pattern for AspectRatioLayoutElement. 2023-11-07 15:53:16 +08:00
668f46d260 Prevents matching the fallback script twice. 2023-11-03 00:26:37 +08:00
b672889008 Update fallback script. 2023-11-03 00:25:49 +08:00
08a12097a4 Forces one font instance per full name. 2023-11-03 00:24:25 +08:00
7535ce04f5 Update docs. 2023-11-02 12:16:55 +08:00
bede668e73 Update UnsafeIL. 2023-11-02 12:16:48 +08:00
c2c28518ba Exclude Discord Game SDK from Android builds. 2023-11-02 12:16:33 +08:00
bfa1423f64 Import Cryville.Culture in favor of ScriptUtils. 2023-11-02 12:15:38 +08:00
395c094890 Discard unused docs. 2023-11-02 12:11:41 +08:00
a284edd130 Add debug logs about environment and fonts. 2023-11-01 01:02:55 +08:00
b57959b4bf Update Cryville.Audio. 2023-11-01 01:01:13 +08:00
724cb10bc1 Import Cryville.Interop.Java. 2023-11-01 00:59:09 +08:00
97e759f57d Adjust the progress report from prehandler. 2023-10-08 01:00:12 +08:00
3ce8ad72ed Add dialogs for audio engine initialization error. 2023-10-08 00:58:43 +08:00
c23d79e3f5 Emits a warning on text frame not found. 2023-10-08 00:53:12 +08:00
71294db3c1 Optimize GC and performance for MonoPInvokeCallback. 2023-09-25 17:09:27 +08:00
825818679c Rearrange platform specific plugins. 2023-09-25 10:52:16 +08:00
84acb2c12d Add suppressions for plugins. 2023-09-25 09:33:10 +08:00
9c034c0f7b Code cleanup for font table. 2023-09-17 20:26:31 +08:00
aa7452aead Draft virtual player strategy. (Amend) 2023-08-24 23:45:57 +08:00
f86562b2f2 Draft virtual player strategy. 2023-08-24 23:44:13 +08:00
8fa2bd1e81 Code structure cleanup. (2) 2023-08-24 16:18:16 +08:00
1f58390298 Code structure cleanup. 2023-08-24 15:47:34 +08:00
e40c98ae1b Update project version. 2023-08-15 21:01:19 +08:00
642a9563ba Fix conditional compilation for Android. 2023-08-15 21:01:00 +08:00
4a1fa48352 Fix incomplete ruleset config displayed on config initialization. 2023-08-15 19:16:16 +08:00
4dc0767e91 Typo fix. 2023-08-11 01:24:01 +08:00
9e82c04898 Fix event priority. 2023-08-07 13:56:17 +08:00
0776eca49d Implement custom ruleset config. (Amend) 2023-08-07 13:55:57 +08:00
af01fb2119 Fix the handle of the slider disappearing permanently after an abnormal range is assigned. 2023-08-02 17:30:20 +08:00
9044631fe7 Implement custom ruleset config. (2) 2023-08-02 17:28:55 +08:00
3b22d4fce3 Fix potential constant flag toggled off incorrectly while optimizing. 2023-08-02 17:25:49 +08:00
5393ff1451 Code cleanup with the implementation of property store. 2023-08-02 17:20:45 +08:00
e34a9cc868 Implement custom ruleset config. 2023-07-31 15:15:07 +08:00
440581261e Add contextual function precision. 2023-07-31 15:14:06 +08:00
b78e99c59c Reconstruct property sources and operators to generic types. 2023-07-31 15:12:41 +08:00
3db8f61e3b Decouple the usage of PDT evaluator of chart player. 2023-07-28 14:13:49 +08:00
8b64165fb7 Fix incorrect layout of popup in camera canvas mode. 2023-07-28 14:10:03 +08:00
799b1e12da Code cleanup. 2023-07-28 13:33:23 +08:00
957270c41a Code cleanup. 2023-07-28 12:17:03 +08:00
bc51a45df8 Rewrite property panel to adapt to ruleset config. 2023-07-27 22:07:20 +08:00
9b091a0084 Rename constraint types to avoid ambiguity. 2023-07-27 22:06:15 +08:00
98e35fc6f6 Distinguish stepped sliders by applying a tint to them. 2023-07-27 16:22:22 +08:00
d83f447e82 Fix number slider not working in camera canvas mode. 2023-07-27 16:21:27 +08:00
898885b116 Scene cleanup. 2023-07-27 16:04:42 +08:00
fd05f6c1dd Add contextual function range. 2023-07-27 16:00:22 +08:00
86da71f2cb Draft config definition. 2023-07-27 15:59:56 +08:00
ba2f1d4858 Fix attempt to save config when failed to load. 2023-07-27 15:31:47 +08:00
3687a70aec Import Android Apk Patch. 2023-07-25 22:12:17 +08:00
8da54093aa Code cleanup. 2023-07-14 23:49:27 +08:00
b057ea8074 Fix the game hanging on close. 2023-07-14 23:48:13 +08:00
e7bc9d0294 Code cleanup. 2023-07-12 23:26:36 +08:00
08de91b04d Implement updater for Windows. 2023-07-12 23:26:26 +08:00
ea70fbb051 Improve exception handling for update checker. 2023-07-12 23:25:15 +08:00
cee6a08240 Refactor some judge variables to hit variables. (Amend) 2023-07-12 23:12:55 +08:00
f04b9cfb75 Refactor some judge variables to hit variables. 2023-07-12 23:08:29 +08:00
1dcbc03829 Code cleanup. 2023-07-11 00:03:47 +08:00
d89423caf5 Code cleanup for network module. 2023-07-11 00:02:14 +08:00
c9b348dd4f Fix Discord timestamp not reset on pause and resume. 2023-07-11 00:01:15 +08:00
636f45f03f Fix dialog layout. 2023-07-04 11:13:46 +08:00
7fce9591a9 Fix crash on opening a URL on Android. 2023-07-04 11:13:28 +08:00
f65e4f1900 Cleanup network module. 2023-07-04 11:12:27 +08:00
a4d0e3867a Code cleanup. 2023-07-03 01:11:04 +08:00
83b9c27e94 Implement opening external package link. 2023-07-03 01:10:45 +08:00
864ea91be0 Implement update checker. 2023-06-22 13:23:24 +08:00
ea02fc22bd Pull down UnityNetworkTask. 2023-06-22 13:23:03 +08:00
60cc763cd0 Fix the active network task not re-enqueued when suspended. 2023-06-22 13:22:23 +08:00
8955b69cdf Fix active inputs not cleaned up while batching. 2023-06-22 13:21:01 +08:00
a7aff4d625 Code cleanup. 2023-06-22 13:18:34 +08:00
22cb8f0cb4 Implement dialog. 2023-06-22 13:15:25 +08:00
db07ace927 Code cleanup. 2023-06-13 18:13:23 +08:00
094c3fe2a3 Add contextual variable judge_delta_time. 2023-06-13 18:13:09 +08:00
cc156e0d81 Fix certain non-interactable UI blocking interaction. 2023-06-06 21:28:17 +08:00
9833052849 Improve the ordering logic for applicable input handlers in input config. 2023-06-06 21:27:33 +08:00
a6a0ac3f9e Fix memory leak during collapsing in PDT. 2023-06-06 21:13:36 +08:00
451 changed files with 36710 additions and 4652 deletions

View File

@@ -3,12 +3,12 @@ using System;
namespace Cryville.Common.ComponentModel {
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
public class RangeAttribute : Attribute {
public RangeAttribute(float min, float max) {
public RangeAttribute(double min, double max) {
Min = min;
Max = max;
}
public float Min { get; set; }
public float Max { get; set; }
public double Min { get; set; }
public double Max { get; set; }
}
}

View File

@@ -3,9 +3,9 @@ using System;
namespace Cryville.Common.ComponentModel {
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
public class StepAttribute : Attribute {
public StepAttribute(float step) {
public StepAttribute(double step) {
Step = step;
}
public float Step { get; set; }
public double Step { get; set; }
}
}

View File

@@ -1,37 +0,0 @@
using System;
using System.Collections;
using System.Collections.Generic;
namespace Cryville.Common.Culture {
public static class ScriptUtils {
public static string[] Scripts = new string[] { "adlm", "afak", "aghb", "ahom", "arab", "aran", "armi", "armn", "avst", "bali", "bamu", "bass", "batk", "beng", "bhks", "blis", "bopo", "brah", "brai", "bugi", "buhd", "cakm", "cans", "cari", "cham", "cher", "chrs", "cirt", "copt", "cpmn", "cprt", "cyrl", "cyrs", "deva", "diak", "dogr", "dsrt", "dupl", "egyd", "egyh", "egyp", "elba", "elym", "ethi", "geok", "geor", "glag", "gong", "gonm", "goth", "gran", "grek", "gujr", "guru", "hanb", "hang", "hani", "hano", "hans", "hant", "hatr", "hebr", "hira", "hluw", "hmng", "hmnp", "hrkt", "hung", "inds", "ital", "jamo", "java", "jpan", "jurc", "kali", "kana", "khar", "khmr", "khoj", "kitl", "kits", "knda", "kore", "kpel", "kthi", "lana", "laoo", "latf", "latg", "latn", "leke", "lepc", "limb", "lina", "linb", "lisu", "loma", "lyci", "lydi", "mahj", "maka", "mand", "mani", "marc", "maya", "medf", "mend", "merc", "mero", "mlym", "modi", "mong", "moon", "mroo", "mtei", "mult", "mymr", "nand", "narb", "nbat", "newa", "nkdb", "nkgb", "nkoo", "nshu", "ogam", "olck", "orkh", "orya", "osge", "osma", "ougr", "palm", "pauc", "pcun", "pelm", "perm", "phag", "phli", "phlp", "phlv", "phnx", "piqd", "plrd", "prti", "psin", "qaaa", "qaai", "qabx", "ranj", "rjng", "rohg", "roro", "runr", "samr", "sara", "sarb", "saur", "sgnw", "shaw", "shrd", "shui", "sidd", "sind", "sinh", "sogd", "sogo", "sora", "soyo", "sund", "sylo", "syrc", "syre", "syrj", "syrn", "tagb", "takr", "tale", "talu", "taml", "tang", "tavt", "telu", "teng", "tfng", "tglg", "thaa", "thai", "tibt", "tirh", "toto", "ugar", "vaii", "visp", "wara", "wcho", "wole", "xpeo", "xsux", "yezi", "yiii", "zanb", "zinh", "zmth", "zsye", "zsym", "zxxx", "zyyy", "zzzz", };
public static string UltimateFallbackScript = "zyyy";
public static Dictionary<string, string[]> FallbackScriptMap = new Dictionary<string, string[]> {
{ "aran", new string[] { "arab" } }, { "cyrs", new string[] { "cyrl" } },
{ "hanb", new string[] { "hant", "bopo" } }, { "hans", new string[] { "hani" } }, { "hant", new string[] { "hani" } },
{ "hrkt", new string[] { "hira", "kana" } }, { "jpan", new string[] { "hani", "hira", "kana" } },
{ "jamo", new string[] { "hang" } }, { "kore", new string[] { "hang", "hani" } },
{ "latf", new string[] { "latn" } }, { "latg", new string[] { "latn" } },
{ "syre", new string[] { "syrc" } }, { "syrj", new string[] { "syrc" } }, { "syrn", new string[] { "syrc" } },
{ "zsye", new string[] { "zsym" } },
};
public static void FillKeysWithScripts(IDictionary dict, Func<object> value) {
foreach (var s in Scripts) dict.Add(s, value());
}
public static IEnumerable<string> EnumerateFallbackScripts(string script) {
if (string.IsNullOrEmpty(script)) throw new ArgumentNullException("script");
script = script.ToLower();
if (script == UltimateFallbackScript) {
yield return null;
yield break;
}
string[] fblist;
if (FallbackScriptMap.TryGetValue(script, out fblist)) {
foreach (var fb in fblist) {
yield return fb;
}
}
else yield return UltimateFallbackScript;
}
}
}

View File

@@ -1,27 +1,30 @@
using Cryville.Common.Logging;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace Cryville.Common.Font {
public abstract class FontManager {
public IReadOnlyDictionary<string, IReadOnlyCollection<Typeface>> MapFullNameToTypeface { get; private set; }
public IReadOnlyDictionary<string, Typeface> MapFullNameToTypeface { get; private set; }
public IReadOnlyDictionary<string, IReadOnlyCollection<Typeface>> MapNameToTypefaces { get; private set; }
public FontManager() {
var map1 = new Dictionary<string, List<Typeface>>();
var map1 = new Dictionary<string, Typeface>();
var map2 = new Dictionary<string, List<Typeface>>();
foreach (var f in EnumerateAllTypefaces()) {
List<Typeface> set1;
if (!map1.TryGetValue(f.FullName, out set1)) {
map1.Add(f.FullName, set1 = new List<Typeface>());
if (!map1.ContainsKey(f.FullName)) {
map1.Add(f.FullName, f);
}
else {
Logger.Log("main", 3, "UI", "Discarding a font with a duplicate full name {0}", f.FullName);
continue;
}
set1.Add(f);
List<Typeface> set2;
if (!map2.TryGetValue(f.FamilyName, out set2)) {
map2.Add(f.FamilyName, set2 = new List<Typeface>());
}
set2.Add(f);
}
MapFullNameToTypeface = map1.ToDictionary(i => i.Key, i => (IReadOnlyCollection<Typeface>)i.Value);
MapFullNameToTypeface = map1;
MapNameToTypefaces = map2.ToDictionary(i => i.Key, i => (IReadOnlyCollection<Typeface>)i.Value);
}
protected abstract IEnumerable<Typeface> EnumerateAllTypefaces();

View File

@@ -1,4 +1,5 @@
using Cryville.Common.Culture;
using Cryville.Common.Logging;
using Cryville.Culture;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -6,323 +7,339 @@ using System.Linq;
namespace Cryville.Common.Font {
public abstract class FontMatcher {
protected FontManager Manager { get; private set; }
public FontMatcher(FontManager manafer) { Manager = manafer; }
public abstract IEnumerable<Typeface> MatchScript(string script = null, bool distinctFamily = false);
public FontMatcher(FontManager manager) { Manager = manager; }
public abstract IEnumerable<Typeface> MatchLanguage(LanguageId lang, bool distinctFamily = false);
}
public class FallbackListFontMatcher : FontMatcher {
readonly LanguageMatching _matcher;
static readonly string UltimateFallbackScript = "zzzz";
public Dictionary<string, List<string>> MapScriptToTypefaces = new Dictionary<string, List<string>>();
public void LoadDefaultWindowsFallbackList() {
if (Environment.OSVersion.Platform != PlatformID.Win32NT) return;
MapScriptToTypefaces.Clear();
ScriptUtils.FillKeysWithScripts(MapScriptToTypefaces, () => new List<string>());
public static Dictionary<string, List<string>> GetDefaultWindowsFallbackMap() {
var map = new Dictionary<string, List<string>>(StringComparer.OrdinalIgnoreCase);
FillKeysWithScripts(map, () => new List<string>());
// Reference: https://github.com/chromium/chromium/blob/main/third_party/blink/renderer/platform/fonts/win/font_fallback_win.cc
MapScriptToTypefaces["zyyy"].Insert(0, "SimSun"); // Custom
MapScriptToTypefaces["zyyy"].Insert(0, "SimHei"); // Custom
MapScriptToTypefaces["zyyy"].Insert(0, "Microsoft YaHei"); // Custom
MapScriptToTypefaces["zyyy"].Insert(0, "Arial");
MapScriptToTypefaces["zyyy"].Insert(0, "Times New Roman");
MapScriptToTypefaces["zyyy"].Insert(0, "Segoe UI"); // Custom
MapScriptToTypefaces["arab"].Insert(0, "Tahoma");
MapScriptToTypefaces["cyrl"].Insert(0, "Times New Roman");
MapScriptToTypefaces["grek"].Insert(0, "Times New Roman");
MapScriptToTypefaces["hebr"].Insert(0, "David");
MapScriptToTypefaces["jpan"].Insert(0, "MS PGothic");
MapScriptToTypefaces["latn"].Insert(0, "Times New Roman");
MapScriptToTypefaces["hans"].Insert(0, "SimSun");
MapScriptToTypefaces["hans"].Insert(0, "SimHei"); // Custom
MapScriptToTypefaces["thai"].Insert(0, "Tahoma");
MapScriptToTypefaces["hans"].Insert(0, "PMingLiU");
map[UltimateFallbackScript].Insert(0, "SimSun"); // Custom
map[UltimateFallbackScript].Insert(0, "SimHei"); // Custom
map[UltimateFallbackScript].Insert(0, "Microsoft YaHei"); // Custom
map[UltimateFallbackScript].Insert(0, "Arial");
map[UltimateFallbackScript].Insert(0, "Times New Roman");
map[UltimateFallbackScript].Insert(0, "Segoe UI"); // Custom
map["arab"].Insert(0, "Tahoma");
map["cyrl"].Insert(0, "Times New Roman");
map["grek"].Insert(0, "Times New Roman");
map["hebr"].Insert(0, "David");
map["jpan"].Insert(0, "MS PGothic");
map["latn"].Insert(0, "Times New Roman");
map["hans"].Insert(0, "SimSun");
map["hans"].Insert(0, "SimHei"); // Custom
map["thai"].Insert(0, "Tahoma");
map["hans"].Insert(0, "PMingLiU");
// Reference: https://learn.microsoft.com/en-us/globalization/input/font-support
var ver = Environment.OSVersion.Version;
if (ver >= new Version(5, 0)) { // Windows 2000
MapScriptToTypefaces["armn"].Insert(0, "Sylfaen");
MapScriptToTypefaces["deva"].Insert(0, "Mangal");
MapScriptToTypefaces["geor"].Insert(0, "Sylfaen");
MapScriptToTypefaces["taml"].Insert(0, "Latha");
map["armn"].Insert(0, "Sylfaen");
map["deva"].Insert(0, "Mangal");
map["geor"].Insert(0, "Sylfaen");
map["taml"].Insert(0, "Latha");
}
if (ver >= new Version(5, 1)) { // Windows XP
MapScriptToTypefaces["gujr"].Insert(0, "Shruti");
MapScriptToTypefaces["guru"].Insert(0, "Raavi");
MapScriptToTypefaces["knda"].Insert(0, "Tunga");
MapScriptToTypefaces["syrc"].Insert(0, "Estrangelo Edessa");
MapScriptToTypefaces["telu"].Insert(0, "Gautami");
MapScriptToTypefaces["thaa"].Insert(0, "MV Boli");
map["gujr"].Insert(0, "Shruti");
map["guru"].Insert(0, "Raavi");
map["knda"].Insert(0, "Tunga");
map["syrc"].Insert(0, "Estrangelo Edessa");
map["telu"].Insert(0, "Gautami");
map["thaa"].Insert(0, "MV Boli");
// SP2
MapScriptToTypefaces["beng"].Insert(0, "Vrinda");
MapScriptToTypefaces["mlym"].Insert(0, "Kartika");
map["beng"].Insert(0, "Vrinda");
map["mlym"].Insert(0, "Kartika");
}
if (ver >= new Version(6, 0)) { // Windows Vista
MapScriptToTypefaces["cans"].Insert(0, "Euphemia");
MapScriptToTypefaces["cher"].Insert(0, "Plantagenet");
MapScriptToTypefaces["ethi"].Insert(0, "Nyala");
MapScriptToTypefaces["khmr"].Insert(0, "DaunPenh MoolBoran");
MapScriptToTypefaces["laoo"].Insert(0, "DokChampa");
MapScriptToTypefaces["mong"].Insert(0, "Mongolian Baiti");
MapScriptToTypefaces["orya"].Insert(0, "Kalinga");
MapScriptToTypefaces["sinh"].Insert(0, "Iskoola Pota");
MapScriptToTypefaces["tibt"].Insert(0, "Microsoft Himalaya");
MapScriptToTypefaces["yiii"].Insert(0, "Microsoft Yi Baiti");
MapScriptToTypefaces["arab"].Insert(0, "Segoe UI");
MapScriptToTypefaces["cyrl"].Insert(0, "Segoe UI");
MapScriptToTypefaces["grek"].Insert(0, "Segoe UI");
MapScriptToTypefaces["latn"].Insert(0, "Segoe UI");
MapScriptToTypefaces["hans"].Add("SimSun-ExtB");
MapScriptToTypefaces["hant"].Add("MingLiU-ExtB");
MapScriptToTypefaces["hant"].Add("MingLiU_HKSCS-ExtB");
MapScriptToTypefaces["arab"].Add("Microsoft Uighur");
MapScriptToTypefaces["zmth"].Insert(0, "Cambria Math");
map["cans"].Insert(0, "Euphemia");
map["cher"].Insert(0, "Plantagenet");
map["ethi"].Insert(0, "Nyala");
map["khmr"].Insert(0, "DaunPenh MoolBoran");
map["laoo"].Insert(0, "DokChampa");
map["mong"].Insert(0, "Mongolian Baiti");
map["orya"].Insert(0, "Kalinga");
map["sinh"].Insert(0, "Iskoola Pota");
map["tibt"].Insert(0, "Microsoft Himalaya");
map["yiii"].Insert(0, "Microsoft Yi Baiti");
map["arab"].Insert(0, "Segoe UI");
map["cyrl"].Insert(0, "Segoe UI");
map["grek"].Insert(0, "Segoe UI");
map["latn"].Insert(0, "Segoe UI");
map["hans"].Add("SimSun-ExtB");
map["hant"].Add("MingLiU-ExtB");
map["hant"].Add("MingLiU_HKSCS-ExtB");
map["arab"].Add("Microsoft Uighur");
map["zmth"].Insert(0, "Cambria Math");
// Reference: https://en.wikipedia.org/wiki/List_of_CJK_fonts
MapScriptToTypefaces["jpan"].Insert(0, "Meiryo");
MapScriptToTypefaces["hans"].Insert(0, "Microsoft YaHei");
map["jpan"].Insert(0, "Meiryo");
map["hans"].Insert(0, "Microsoft YaHei");
}
if (ver >= new Version(6, 1)) { // Windows 7
MapScriptToTypefaces["brai"].Insert(0, "Segoe UI Symbol");
MapScriptToTypefaces["dsrt"].Insert(0, "Segoe UI Symbol");
MapScriptToTypefaces["talu"].Insert(0, "Microsoft New Tai Lue");
MapScriptToTypefaces["ogam"].Insert(0, "Segoe UI Symbol");
MapScriptToTypefaces["osma"].Insert(0, "Ebrima");
MapScriptToTypefaces["phag"].Insert(0, "Microsoft PhagsPa");
MapScriptToTypefaces["runr"].Insert(0, "Segoe UI Symbol");
MapScriptToTypefaces["zsym"].Insert(0, "Segoe UI Symbol");
MapScriptToTypefaces["tale"].Insert(0, "Microsoft Tai Le");
MapScriptToTypefaces["tfng"].Insert(0, "Ebrima");
MapScriptToTypefaces["vaii"].Insert(0, "Ebrima");
map["brai"].Insert(0, "Segoe UI Symbol");
map["dsrt"].Insert(0, "Segoe UI Symbol");
map["talu"].Insert(0, "Microsoft New Tai Lue");
map["ogam"].Insert(0, "Segoe UI Symbol");
map["osma"].Insert(0, "Ebrima");
map["phag"].Insert(0, "Microsoft PhagsPa");
map["runr"].Insert(0, "Segoe UI Symbol");
map["zsym"].Insert(0, "Segoe UI Symbol");
map["tale"].Insert(0, "Microsoft Tai Le");
map["tfng"].Insert(0, "Ebrima");
map["vaii"].Insert(0, "Ebrima");
}
if (ver >= new Version(6, 2)) { // Windows 8
MapScriptToTypefaces["glag"].Insert(0, "Segoe UI Symbol");
MapScriptToTypefaces["goth"].Insert(0, "Segoe UI Symbol");
MapScriptToTypefaces["hang"].Add("Malgun Gothic");
MapScriptToTypefaces["ital"].Insert(0, "Segoe UI Symbol");
MapScriptToTypefaces["lisu"].Insert(0, "Segoe UI");
MapScriptToTypefaces["mymr"].Insert(0, "Myanmar Text");
MapScriptToTypefaces["nkoo"].Insert(0, "Ebrima");
MapScriptToTypefaces["orkh"].Insert(0, "Segoe UI Symbol");
MapScriptToTypefaces["ethi"].Insert(0, "Ebrima");
MapScriptToTypefaces["cans"].Insert(0, "Gadugi");
MapScriptToTypefaces["hant"].Insert(0, "Microsoft JhengHei UI");
MapScriptToTypefaces["hans"].Insert(0, "Microsoft YaHei UI");
MapScriptToTypefaces["beng"].Insert(0, "Nirmala UI");
MapScriptToTypefaces["deva"].Insert(0, "Nirmala UI");
MapScriptToTypefaces["gujr"].Insert(0, "Nirmala UI");
MapScriptToTypefaces["guru"].Insert(0, "Nirmala UI"); // NOT DOCUMENTED, UNVERIFIED
MapScriptToTypefaces["knda"].Insert(0, "Nirmala UI"); // NOT DOCUMENTED, UNVERIFIED
MapScriptToTypefaces["mlym"].Insert(0, "Nirmala UI");
MapScriptToTypefaces["orya"].Insert(0, "Nirmala UI");
MapScriptToTypefaces["sinh"].Insert(0, "Nirmala UI"); // NOT DOCUMENTED, UNVERIFIED
MapScriptToTypefaces["taml"].Insert(0, "Nirmala UI"); // NOT DOCUMENTED, UNVERIFIED
MapScriptToTypefaces["telu"].Insert(0, "Nirmala UI");
MapScriptToTypefaces["armn"].Insert(0, "Segoe UI");
MapScriptToTypefaces["geor"].Insert(0, "Segoe UI");
MapScriptToTypefaces["hebr"].Insert(0, "Segoe UI");
map["glag"].Insert(0, "Segoe UI Symbol");
map["goth"].Insert(0, "Segoe UI Symbol");
map["hang"].Add("Malgun Gothic");
map["ital"].Insert(0, "Segoe UI Symbol");
map["lisu"].Insert(0, "Segoe UI");
map["mymr"].Insert(0, "Myanmar Text");
map["nkoo"].Insert(0, "Ebrima");
map["orkh"].Insert(0, "Segoe UI Symbol");
map["ethi"].Insert(0, "Ebrima");
map["cans"].Insert(0, "Gadugi");
map["hant"].Insert(0, "Microsoft JhengHei UI");
map["hans"].Insert(0, "Microsoft YaHei UI");
map["beng"].Insert(0, "Nirmala UI");
map["deva"].Insert(0, "Nirmala UI");
map["gujr"].Insert(0, "Nirmala UI");
map["guru"].Insert(0, "Nirmala UI"); // NOT DOCUMENTED, UNVERIFIED
map["knda"].Insert(0, "Nirmala UI"); // NOT DOCUMENTED, UNVERIFIED
map["mlym"].Insert(0, "Nirmala UI");
map["orya"].Insert(0, "Nirmala UI");
map["sinh"].Insert(0, "Nirmala UI"); // NOT DOCUMENTED, UNVERIFIED
map["taml"].Insert(0, "Nirmala UI"); // NOT DOCUMENTED, UNVERIFIED
map["telu"].Insert(0, "Nirmala UI");
map["armn"].Insert(0, "Segoe UI");
map["geor"].Insert(0, "Segoe UI");
map["hebr"].Insert(0, "Segoe UI");
}
if (ver >= new Version(6, 3)) { // Windows 8.1
MapScriptToTypefaces["bugi"].Insert(0, "Leelawadee UI");
MapScriptToTypefaces["copt"].Insert(0, "Segoe UI Symbol");
MapScriptToTypefaces["java"].Insert(0, "Javanese Text");
MapScriptToTypefaces["merc"].Insert(0, "Segoe UI Symbol");
MapScriptToTypefaces["olck"].Insert(0, "Nirmala UI");
MapScriptToTypefaces["sora"].Insert(0, "Nirmala UI");
MapScriptToTypefaces["khmr"].Insert(0, "Leelawadee UI");
MapScriptToTypefaces["laoo"].Insert(0, "Leelawadee UI");
MapScriptToTypefaces["thai"].Insert(0, "Leelawadee UI");
MapScriptToTypefaces["zsye"].Insert(0, "Segoe UI Emoji");
map["bugi"].Insert(0, "Leelawadee UI");
map["copt"].Insert(0, "Segoe UI Symbol");
map["java"].Insert(0, "Javanese Text");
map["merc"].Insert(0, "Segoe UI Symbol");
map["olck"].Insert(0, "Nirmala UI");
map["sora"].Insert(0, "Nirmala UI");
map["khmr"].Insert(0, "Leelawadee UI");
map["laoo"].Insert(0, "Leelawadee UI");
map["thai"].Insert(0, "Leelawadee UI");
map["zsye"].Insert(0, "Segoe UI Emoji");
}
if (ver >= new Version(10, 0)) { // Windows 10
MapScriptToTypefaces["brah"].Insert(0, "Segoe UI Historic");
MapScriptToTypefaces["cari"].Insert(0, "Segoe UI Historic");
MapScriptToTypefaces["cprt"].Insert(0, "Segoe UI Historic");
MapScriptToTypefaces["egyp"].Insert(0, "Segoe UI Historic");
MapScriptToTypefaces["armi"].Insert(0, "Segoe UI Historic");
MapScriptToTypefaces["phli"].Insert(0, "Segoe UI Historic");
MapScriptToTypefaces["prti"].Insert(0, "Segoe UI Historic");
MapScriptToTypefaces["khar"].Insert(0, "Segoe UI Historic");
MapScriptToTypefaces["lyci"].Insert(0, "Segoe UI Historic");
MapScriptToTypefaces["lydi"].Insert(0, "Segoe UI Historic");
MapScriptToTypefaces["phnx"].Insert(0, "Segoe UI Historic");
MapScriptToTypefaces["xpeo"].Insert(0, "Segoe UI Historic");
MapScriptToTypefaces["sarb"].Insert(0, "Segoe UI Historic");
MapScriptToTypefaces["shaw"].Insert(0, "Segoe UI Historic");
MapScriptToTypefaces["xsux"].Insert(0, "Segoe UI Historic");
MapScriptToTypefaces["ugar"].Insert(0, "Segoe UI Historic");
map["brah"].Insert(0, "Segoe UI Historic");
map["cari"].Insert(0, "Segoe UI Historic");
map["cprt"].Insert(0, "Segoe UI Historic");
map["egyp"].Insert(0, "Segoe UI Historic");
map["armi"].Insert(0, "Segoe UI Historic");
map["phli"].Insert(0, "Segoe UI Historic");
map["prti"].Insert(0, "Segoe UI Historic");
map["khar"].Insert(0, "Segoe UI Historic");
map["lyci"].Insert(0, "Segoe UI Historic");
map["lydi"].Insert(0, "Segoe UI Historic");
map["phnx"].Insert(0, "Segoe UI Historic");
map["xpeo"].Insert(0, "Segoe UI Historic");
map["sarb"].Insert(0, "Segoe UI Historic");
map["shaw"].Insert(0, "Segoe UI Historic");
map["xsux"].Insert(0, "Segoe UI Historic");
map["ugar"].Insert(0, "Segoe UI Historic");
// Segoe UI Symbol -> Segoe UI Historic
MapScriptToTypefaces["glag"].Insert(0, "Segoe UI Historic");
MapScriptToTypefaces["goth"].Insert(0, "Segoe UI Historic");
MapScriptToTypefaces["merc"].Insert(0, "Segoe UI Historic");
MapScriptToTypefaces["ogam"].Insert(0, "Segoe UI Historic");
MapScriptToTypefaces["ital"].Insert(0, "Segoe UI Historic");
MapScriptToTypefaces["orkh"].Insert(0, "Segoe UI Historic");
MapScriptToTypefaces["runr"].Insert(0, "Segoe UI Historic");
map["glag"].Insert(0, "Segoe UI Historic");
map["goth"].Insert(0, "Segoe UI Historic");
map["merc"].Insert(0, "Segoe UI Historic");
map["ogam"].Insert(0, "Segoe UI Historic");
map["ital"].Insert(0, "Segoe UI Historic");
map["orkh"].Insert(0, "Segoe UI Historic");
map["runr"].Insert(0, "Segoe UI Historic");
//
MapScriptToTypefaces["jpan"].Insert(0, "Yu Gothic UI");
MapScriptToTypefaces["zsym"].Add("Segoe MDL2 Assets");
map["jpan"].Insert(0, "Yu Gothic UI");
map["zsym"].Add("Segoe MDL2 Assets");
}
return map;
}
public static Dictionary<string, List<string>> GetDefaultAndroidFallbackMap() {
var map = new Dictionary<string, List<string>>(StringComparer.OrdinalIgnoreCase);
FillKeysWithScripts(map, () => new List<string>());
map[UltimateFallbackScript].Insert(0, "Noto Sans CJK TC"); // TODO Modify default fallback
map[UltimateFallbackScript].Insert(0, "Noto Sans CJK JP");
map[UltimateFallbackScript].Insert(0, "Noto Sans CJK SC");
map[UltimateFallbackScript].Insert(0, "Roboto");
map["zsye"].Insert(0, "Noto Color Emoji");
map["zsye"].Add("Noto Color Emoji Flags");
map["arab"].Insert(0, "Noto Naskh Arabic");
map["adlm"].Insert(0, "Noto Sans Adlam");
map["ahom"].Insert(0, "Noto Sans Ahom");
map["hluw"].Insert(0, "Noto Sans Anatolian Hieroglyphs");
map["armn"].Insert(0, "Noto Sans Armenian");
map["avst"].Insert(0, "Noto Sans Avestan");
map["bali"].Insert(0, "Noto Sans Balinese");
map["bamu"].Insert(0, "Noto Sans Bamum");
map["bass"].Insert(0, "Noto Sans Bassa Vah");
map["batk"].Insert(0, "Noto Sans Batak");
map["beng"].Insert(0, "Noto Sans Bengali");
map["bhks"].Insert(0, "Noto Sans Bhaiksuki");
map["brah"].Insert(0, "Noto Sans Brahmi");
map["bugi"].Insert(0, "Noto Sans Buginese");
map["buhd"].Insert(0, "Noto Sans Buhid");
map["jpan"].Insert(0, "Noto Sans CJK JP");
map["kore"].Insert(0, "Noto Sans CJK KR");
map["hans"].Insert(0, "Noto Sans CJK SC");
map["hant"].Insert(0, "Noto Sans CJK TC");
map["hant"].Add("Noto Sans CJK HK");
map["cans"].Insert(0, "Noto Sans Canadian Aboriginal");
map["cari"].Insert(0, "Noto Sans Carian");
map["cakm"].Insert(0, "Noto Sans Chakma");
map["cham"].Insert(0, "Noto Sans Cham");
map["cher"].Insert(0, "Noto Sans Cherokee");
map["copt"].Insert(0, "Noto Sans Coptic");
map["xsux"].Insert(0, "Noto Sans Cuneiform");
map["cprt"].Insert(0, "Noto Sans Cypriot");
map["dsrt"].Insert(0, "Noto Sans Deseret");
map["deva"].Insert(0, "Noto Sans Devanagari");
map["egyp"].Insert(0, "Noto Sans Egyptian Hieroglyphs");
map["elba"].Insert(0, "Noto Sans Elbasan");
map["ethi"].Insert(0, "Noto Sans Ethiopic");
map["geor"].Insert(0, "Noto Sans Georgian");
map["glag"].Insert(0, "Noto Sans Glagolitic");
map["goth"].Insert(0, "Noto Sans Gothic");
map["gran"].Insert(0, "Noto Sans Grantha");
map["gujr"].Insert(0, "Noto Sans Gujarati");
map["gong"].Insert(0, "Noto Sans Gunjala Gondi");
map["guru"].Insert(0, "Noto Sans Gurmukhi");
map["rohg"].Insert(0, "Noto Sans Hanifi Rohingya");
map["hano"].Insert(0, "Noto Sans Hanunoo");
map["hatr"].Insert(0, "Noto Sans Hatran");
map["hebr"].Insert(0, "Noto Sans Hebrew");
map["armi"].Insert(0, "Noto Sans Imperial Aramaic");
map["phli"].Insert(0, "Noto Sans Inscriptional Pahlavi");
map["prti"].Insert(0, "Noto Sans Inscriptional Parthian");
map["java"].Insert(0, "Noto Sans Javanese");
map["kthi"].Insert(0, "Noto Sans Kaithi");
map["knda"].Insert(0, "Noto Sans Kannada");
map["kali"].Insert(0, "Noto Sans KayahLi");
map["khar"].Insert(0, "Noto Sans Kharoshthi");
map["khmr"].Insert(0, "Noto Sans Khmer");
map["khoj"].Insert(0, "Noto Sans Khojki");
map["laoo"].Insert(0, "Noto Sans Lao");
map["lepc"].Insert(0, "Noto Sans Lepcha");
map["limb"].Insert(0, "Noto Sans Limbu");
map["lina"].Insert(0, "Noto Sans Linear A");
map["linb"].Insert(0, "Noto Sans Linear B");
map["lisu"].Insert(0, "Noto Sans Lisu");
map["lyci"].Insert(0, "Noto Sans Lycian");
map["lydi"].Insert(0, "Noto Sans Lydian");
map["mlym"].Insert(0, "Noto Sans Malayalam");
map["mand"].Insert(0, "Noto Sans Mandiac");
map["mani"].Insert(0, "Noto Sans Manichaean");
map["marc"].Insert(0, "Noto Sans Marchen");
map["gonm"].Insert(0, "Noto Sans Masaram Gondi");
map["medf"].Insert(0, "Noto Sans Medefaidrin");
map["mtei"].Insert(0, "Noto Sans Meetei Mayek");
map["merc"].Insert(0, "Noto Sans Meroitic");
map["mero"].Insert(0, "Noto Sans Meroitic");
map["plrd"].Insert(0, "Noto Sans Miao");
map["modi"].Insert(0, "Noto Sans Modi");
map["mong"].Insert(0, "Noto Sans Mongolian");
map["mroo"].Insert(0, "Noto Sans Mro");
map["mult"].Insert(0, "Noto Sans Multani");
map["mymr"].Insert(0, "Noto Sans Myanmar");
map["nkoo"].Insert(0, "Noto Sans Nko");
map["nbat"].Insert(0, "Noto Sans Nabataean");
map["talu"].Insert(0, "Noto Sans New Tai Lue");
map["newa"].Insert(0, "Noto Sans Newa");
map["ogam"].Insert(0, "Noto Sans Ogham");
map["olck"].Insert(0, "Noto Sans Ol Chiki");
map["ital"].Insert(0, "Noto Sans Old Italian");
map["narb"].Insert(0, "Noto Sans Old North Arabian");
map["perm"].Insert(0, "Noto Sans Old Permic");
map["xpeo"].Insert(0, "Noto Sans Old Persian");
map["sarb"].Insert(0, "Noto Sans Old South Arabian");
map["orkh"].Insert(0, "Noto Sans Old Turkic");
map["orya"].Insert(0, "Noto Sans Oriya");
map["osge"].Insert(0, "Noto Sans Osage");
map["osma"].Insert(0, "Noto Sans Osmanya");
map["hmng"].Insert(0, "Noto Sans Pahawh Hmong");
map["palm"].Insert(0, "Noto Sans Palmyrene");
map["pauc"].Insert(0, "Noto Sans Pau Cin Hau");
map["phag"].Insert(0, "Noto Sans Phags Pa");
map["phnx"].Insert(0, "Noto Sans Phoenician");
map["rjng"].Insert(0, "Noto Sans Rejang");
map["runr"].Insert(0, "Noto Sans Runic");
map["samr"].Insert(0, "Noto Sans Samaritan");
map["saur"].Insert(0, "Noto Sans Saurashtra");
map["shrd"].Insert(0, "Noto Sans Sharada");
map["shaw"].Insert(0, "Noto Sans Shavian");
map["sinh"].Insert(0, "Noto Sans Sinhala");
map["sora"].Insert(0, "Noto Sans Sora Sompeng");
map["soyo"].Insert(0, "Noto Sans Soyombo");
map["sund"].Insert(0, "Noto Sans Sundanese");
map["sylo"].Insert(0, "Noto Sans Syloti Nagri");
map["zsym"].Insert(0, "Noto Sans Symbols");
map["syrc"].Add("Noto Sans Syriac Eastern");
map["syrc"].Add("Noto Sans Syriac Western");
map["syrc"].Add("Noto Sans Syriac Estrangela");
map["tglg"].Insert(0, "Noto Sans Tagalog");
map["tagb"].Insert(0, "Noto Sans Tagbanwa");
map["tale"].Insert(0, "Noto Sans Tai Le");
map["lana"].Insert(0, "Noto Sans Tai Tham");
map["tavt"].Insert(0, "Noto Sans Tai Viet");
map["takr"].Insert(0, "Noto Sans Takri");
map["taml"].Insert(0, "Noto Sans Tamil");
map["telu"].Insert(0, "Noto Sans Telugu");
map["thaa"].Insert(0, "Noto Sans Thaana");
map["thai"].Insert(0, "Noto Sans Thai");
map["tfng"].Insert(0, "Noto Sans Tifinagh");
map["ugar"].Insert(0, "Noto Sans Ugaritic");
map["vaii"].Insert(0, "Noto Sans Vai");
map["wcho"].Insert(0, "Noto Sans Wancho");
map["wara"].Insert(0, "Noto Sans Warang Citi");
map["yiii"].Insert(0, "Noto Sans Yi");
return map;
}
static void FillKeysWithScripts<T>(IDictionary<string, T> map, Func<T> value) {
foreach (var s in IdValidity.Enumerate("script")) map.Add(s, value());
}
public FallbackListFontMatcher(LanguageMatching matcher, FontManager manager) : base(manager) {
_matcher = matcher;
}
public override IEnumerable<Typeface> MatchLanguage(LanguageId lang, bool distinctFamily = false) {
var supported = MapScriptToTypefaces.Keys.Select(i => new LanguageId(i)).ToList();
bool flag = false;
while (_matcher.Match(lang, supported, out var match, out var distance)) {
if (distance > 40) break;
Logger.Log("main", 0, "UI", "Matching fonts for language {0}, distance = {1}", match, distance);
if (match.Script.Equals(UltimateFallbackScript, StringComparison.OrdinalIgnoreCase)) {
flag = true;
}
var candidates = MapScriptToTypefaces[match.Script];
foreach (var typeface in EnumerateTypefaces(candidates, distinctFamily)) {
yield return typeface;
}
supported.Remove(match);
}
if (flag) yield break;
Logger.Log("main", 0, "UI", "Matching fallback fonts");
foreach (var typeface in EnumerateTypefaces(MapScriptToTypefaces[UltimateFallbackScript], distinctFamily)) {
yield return typeface;
}
}
public void LoadDefaultAndroidFallbackList() {
if (Environment.OSVersion.Platform != PlatformID.Unix) return;
MapScriptToTypefaces.Clear();
ScriptUtils.FillKeysWithScripts(MapScriptToTypefaces, () => new List<string>());
MapScriptToTypefaces["zyyy"].Insert(0, "Noto Sans CJK TC"); // TODO Modify default fallback
MapScriptToTypefaces["zyyy"].Insert(0, "Noto Sans CJK JP");
MapScriptToTypefaces["zyyy"].Insert(0, "Noto Sans CJK SC");
MapScriptToTypefaces["zyyy"].Insert(0, "Roboto");
MapScriptToTypefaces["zsye"].Insert(0, "Noto Color Emoji");
MapScriptToTypefaces["zsye"].Add("Noto Color Emoji Flags");
MapScriptToTypefaces["arab"].Insert(0, "Noto Naskh Arabic");
MapScriptToTypefaces["adlm"].Insert(0, "Noto Sans Adlam");
MapScriptToTypefaces["ahom"].Insert(0, "Noto Sans Ahom");
MapScriptToTypefaces["hluw"].Insert(0, "Noto Sans Anatolian Hieroglyphs");
MapScriptToTypefaces["armn"].Insert(0, "Noto Sans Armenian");
MapScriptToTypefaces["avst"].Insert(0, "Noto Sans Avestan");
MapScriptToTypefaces["bali"].Insert(0, "Noto Sans Balinese");
MapScriptToTypefaces["bamu"].Insert(0, "Noto Sans Bamum");
MapScriptToTypefaces["bass"].Insert(0, "Noto Sans Bassa Vah");
MapScriptToTypefaces["batk"].Insert(0, "Noto Sans Batak");
MapScriptToTypefaces["beng"].Insert(0, "Noto Sans Bengali");
MapScriptToTypefaces["bhks"].Insert(0, "Noto Sans Bhaiksuki");
MapScriptToTypefaces["brah"].Insert(0, "Noto Sans Brahmi");
MapScriptToTypefaces["bugi"].Insert(0, "Noto Sans Buginese");
MapScriptToTypefaces["buhd"].Insert(0, "Noto Sans Buhid");
MapScriptToTypefaces["jpan"].Insert(0, "Noto Sans CJK JP");
MapScriptToTypefaces["kore"].Insert(0, "Noto Sans CJK KR");
MapScriptToTypefaces["hans"].Insert(0, "Noto Sans CJK SC");
MapScriptToTypefaces["hant"].Insert(0, "Noto Sans CJK TC");
MapScriptToTypefaces["hant"].Add("Noto Sans CJK HK");
MapScriptToTypefaces["cans"].Insert(0, "Noto Sans Canadian Aboriginal");
MapScriptToTypefaces["cari"].Insert(0, "Noto Sans Carian");
MapScriptToTypefaces["cakm"].Insert(0, "Noto Sans Chakma");
MapScriptToTypefaces["cham"].Insert(0, "Noto Sans Cham");
MapScriptToTypefaces["cher"].Insert(0, "Noto Sans Cherokee");
MapScriptToTypefaces["copt"].Insert(0, "Noto Sans Coptic");
MapScriptToTypefaces["xsux"].Insert(0, "Noto Sans Cuneiform");
MapScriptToTypefaces["cprt"].Insert(0, "Noto Sans Cypriot");
MapScriptToTypefaces["dsrt"].Insert(0, "Noto Sans Deseret");
MapScriptToTypefaces["deva"].Insert(0, "Noto Sans Devanagari");
MapScriptToTypefaces["egyp"].Insert(0, "Noto Sans Egyptian Hieroglyphs");
MapScriptToTypefaces["elba"].Insert(0, "Noto Sans Elbasan");
MapScriptToTypefaces["ethi"].Insert(0, "Noto Sans Ethiopic");
MapScriptToTypefaces["geor"].Insert(0, "Noto Sans Georgian");
MapScriptToTypefaces["glag"].Insert(0, "Noto Sans Glagolitic");
MapScriptToTypefaces["goth"].Insert(0, "Noto Sans Gothic");
MapScriptToTypefaces["gran"].Insert(0, "Noto Sans Grantha");
MapScriptToTypefaces["gujr"].Insert(0, "Noto Sans Gujarati");
MapScriptToTypefaces["gong"].Insert(0, "Noto Sans Gunjala Gondi");
MapScriptToTypefaces["guru"].Insert(0, "Noto Sans Gurmukhi");
MapScriptToTypefaces["rohg"].Insert(0, "Noto Sans Hanifi Rohingya");
MapScriptToTypefaces["hano"].Insert(0, "Noto Sans Hanunoo");
MapScriptToTypefaces["hatr"].Insert(0, "Noto Sans Hatran");
MapScriptToTypefaces["hebr"].Insert(0, "Noto Sans Hebrew");
MapScriptToTypefaces["armi"].Insert(0, "Noto Sans Imperial Aramaic");
MapScriptToTypefaces["phli"].Insert(0, "Noto Sans Inscriptional Pahlavi");
MapScriptToTypefaces["prti"].Insert(0, "Noto Sans Inscriptional Parthian");
MapScriptToTypefaces["java"].Insert(0, "Noto Sans Javanese");
MapScriptToTypefaces["kthi"].Insert(0, "Noto Sans Kaithi");
MapScriptToTypefaces["knda"].Insert(0, "Noto Sans Kannada");
MapScriptToTypefaces["kali"].Insert(0, "Noto Sans KayahLi");
MapScriptToTypefaces["khar"].Insert(0, "Noto Sans Kharoshthi");
MapScriptToTypefaces["khmr"].Insert(0, "Noto Sans Khmer");
MapScriptToTypefaces["khoj"].Insert(0, "Noto Sans Khojki");
MapScriptToTypefaces["laoo"].Insert(0, "Noto Sans Lao");
MapScriptToTypefaces["lepc"].Insert(0, "Noto Sans Lepcha");
MapScriptToTypefaces["limb"].Insert(0, "Noto Sans Limbu");
MapScriptToTypefaces["lina"].Insert(0, "Noto Sans Linear A");
MapScriptToTypefaces["linb"].Insert(0, "Noto Sans Linear B");
MapScriptToTypefaces["lisu"].Insert(0, "Noto Sans Lisu");
MapScriptToTypefaces["lyci"].Insert(0, "Noto Sans Lycian");
MapScriptToTypefaces["lydi"].Insert(0, "Noto Sans Lydian");
MapScriptToTypefaces["mlym"].Insert(0, "Noto Sans Malayalam");
MapScriptToTypefaces["mand"].Insert(0, "Noto Sans Mandiac");
MapScriptToTypefaces["mani"].Insert(0, "Noto Sans Manichaean");
MapScriptToTypefaces["marc"].Insert(0, "Noto Sans Marchen");
MapScriptToTypefaces["gonm"].Insert(0, "Noto Sans Masaram Gondi");
MapScriptToTypefaces["medf"].Insert(0, "Noto Sans Medefaidrin");
MapScriptToTypefaces["mtei"].Insert(0, "Noto Sans Meetei Mayek");
MapScriptToTypefaces["merc"].Insert(0, "Noto Sans Meroitic");
MapScriptToTypefaces["mero"].Insert(0, "Noto Sans Meroitic");
MapScriptToTypefaces["plrd"].Insert(0, "Noto Sans Miao");
MapScriptToTypefaces["modi"].Insert(0, "Noto Sans Modi");
MapScriptToTypefaces["mong"].Insert(0, "Noto Sans Mongolian");
MapScriptToTypefaces["mroo"].Insert(0, "Noto Sans Mro");
MapScriptToTypefaces["mult"].Insert(0, "Noto Sans Multani");
MapScriptToTypefaces["mymr"].Insert(0, "Noto Sans Myanmar");
MapScriptToTypefaces["nkoo"].Insert(0, "Noto Sans Nko");
MapScriptToTypefaces["nbat"].Insert(0, "Noto Sans Nabataean");
MapScriptToTypefaces["talu"].Insert(0, "Noto Sans New Tai Lue");
MapScriptToTypefaces["newa"].Insert(0, "Noto Sans Newa");
MapScriptToTypefaces["ogam"].Insert(0, "Noto Sans Ogham");
MapScriptToTypefaces["olck"].Insert(0, "Noto Sans Ol Chiki");
MapScriptToTypefaces["ital"].Insert(0, "Noto Sans Old Italian");
MapScriptToTypefaces["narb"].Insert(0, "Noto Sans Old North Arabian");
MapScriptToTypefaces["perm"].Insert(0, "Noto Sans Old Permic");
MapScriptToTypefaces["xpeo"].Insert(0, "Noto Sans Old Persian");
MapScriptToTypefaces["sarb"].Insert(0, "Noto Sans Old South Arabian");
MapScriptToTypefaces["orkh"].Insert(0, "Noto Sans Old Turkic");
MapScriptToTypefaces["orya"].Insert(0, "Noto Sans Oriya");
MapScriptToTypefaces["osge"].Insert(0, "Noto Sans Osage");
MapScriptToTypefaces["osma"].Insert(0, "Noto Sans Osmanya");
MapScriptToTypefaces["hmng"].Insert(0, "Noto Sans Pahawh Hmong");
MapScriptToTypefaces["palm"].Insert(0, "Noto Sans Palmyrene");
MapScriptToTypefaces["pauc"].Insert(0, "Noto Sans Pau Cin Hau");
MapScriptToTypefaces["phag"].Insert(0, "Noto Sans Phags Pa");
MapScriptToTypefaces["phnx"].Insert(0, "Noto Sans Phoenician");
MapScriptToTypefaces["rjng"].Insert(0, "Noto Sans Rejang");
MapScriptToTypefaces["runr"].Insert(0, "Noto Sans Runic");
MapScriptToTypefaces["samr"].Insert(0, "Noto Sans Samaritan");
MapScriptToTypefaces["saur"].Insert(0, "Noto Sans Saurashtra");
MapScriptToTypefaces["shrd"].Insert(0, "Noto Sans Sharada");
MapScriptToTypefaces["shaw"].Insert(0, "Noto Sans Shavian");
MapScriptToTypefaces["sinh"].Insert(0, "Noto Sans Sinhala");
MapScriptToTypefaces["sora"].Insert(0, "Noto Sans Sora Sompeng");
MapScriptToTypefaces["soyo"].Insert(0, "Noto Sans Soyombo");
MapScriptToTypefaces["sund"].Insert(0, "Noto Sans Sundanese");
MapScriptToTypefaces["sylo"].Insert(0, "Noto Sans Syloti Nagri");
MapScriptToTypefaces["zsym"].Insert(0, "Noto Sans Symbols");
MapScriptToTypefaces["syrn"].Insert(0, "Noto Sans Syriac Eastern");
MapScriptToTypefaces["syre"].Insert(0, "Noto Sans Syriac Estrangela");
MapScriptToTypefaces["syrj"].Insert(0, "Noto Sans Syriac Western");
MapScriptToTypefaces["tglg"].Insert(0, "Noto Sans Tagalog");
MapScriptToTypefaces["tagb"].Insert(0, "Noto Sans Tagbanwa");
MapScriptToTypefaces["tale"].Insert(0, "Noto Sans Tai Le");
MapScriptToTypefaces["lana"].Insert(0, "Noto Sans Tai Tham");
MapScriptToTypefaces["tavt"].Insert(0, "Noto Sans Tai Viet");
MapScriptToTypefaces["takr"].Insert(0, "Noto Sans Takri");
MapScriptToTypefaces["taml"].Insert(0, "Noto Sans Tamil");
MapScriptToTypefaces["telu"].Insert(0, "Noto Sans Telugu");
MapScriptToTypefaces["thaa"].Insert(0, "Noto Sans Thaana");
MapScriptToTypefaces["thai"].Insert(0, "Noto Sans Thai");
MapScriptToTypefaces["tfng"].Insert(0, "Noto Sans Tifinagh");
MapScriptToTypefaces["ugar"].Insert(0, "Noto Sans Ugaritic");
MapScriptToTypefaces["vaii"].Insert(0, "Noto Sans Vai");
MapScriptToTypefaces["wcho"].Insert(0, "Noto Sans Wancho");
MapScriptToTypefaces["wara"].Insert(0, "Noto Sans Warang Citi");
MapScriptToTypefaces["yiii"].Insert(0, "Noto Sans Yi");
}
public FallbackListFontMatcher(FontManager manager) : base(manager) { }
public override IEnumerable<Typeface> MatchScript(string script = null, bool distinctFamily = false) {
if (string.IsNullOrEmpty(script)) script = ScriptUtils.UltimateFallbackScript;
List<string> candidates;
IEnumerable<string> candidateScripts = new string[] { script };
while (candidateScripts != null) {
foreach (var candidateScript in candidateScripts) {
if (MapScriptToTypefaces.TryGetValue(candidateScript, out candidates)) {
foreach (var candidate in candidates) {
IReadOnlyCollection<Typeface> typefaces1;
if (Manager.MapFullNameToTypeface.TryGetValue(candidate, out typefaces1)) {
foreach (var typeface in typefaces1) {
yield return typeface;
}
}
if (distinctFamily) continue;
IReadOnlyCollection<Typeface> typefaces2;
if (Manager.MapNameToTypefaces.TryGetValue(candidate, out typefaces2)) {
foreach (var typeface in typefaces2) {
if (typefaces1.Contains(typeface)) continue;
yield return typeface;
}
}
}
IEnumerable<Typeface> EnumerateTypefaces(List<string> candidates, bool distinctFamily) {
foreach (var candidate in candidates) {
if (Manager.MapFullNameToTypeface.TryGetValue(candidate, out var typeface1)) {
yield return typeface1;
}
if (distinctFamily) continue;
IReadOnlyCollection<Typeface> typefaces2;
if (Manager.MapNameToTypefaces.TryGetValue(candidate, out typefaces2)) {
foreach (var typeface in typefaces2) {
if (typeface1 == typeface) continue;
yield return typeface;
}
}
candidateScripts = ScriptUtils.EnumerateFallbackScripts(script);
}
}
}

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.IO;
using System.Text;
#pragma warning disable IDE0049
namespace Cryville.Common.Font {
public abstract class FontTable<T> {
protected UInt32 Offset { get; private set; }
@@ -25,14 +26,17 @@ namespace Cryville.Common.Font {
readonly UInt16 minorVersion;
readonly UInt32 numFonts;
readonly List<UInt32> tableDirectoryOffsets = new List<UInt32>();
#pragma warning disable IDE0052 // Reserved
readonly String dsigTag;
readonly UInt32 dsigLength;
readonly UInt32 dsigOffset;
#pragma warning restore IDE0052 // Reserved
public TTCHeader(BinaryReader reader, UInt32 offset) : base(reader, offset) {
ttcTag = reader.ReadTag();
if (ttcTag != "ttcf") throw new NotImplementedException();
if (ttcTag != "ttcf") throw new NotSupportedException();
majorVersion = reader.ReadUInt16();
minorVersion = reader.ReadUInt16();
if (minorVersion != 0) throw new NotSupportedException();
numFonts = reader.ReadUInt32();
for (UInt32 i = 0; i < numFonts; i++) tableDirectoryOffsets.Add(reader.ReadUInt32());
if (majorVersion == 2) {
@@ -52,12 +56,16 @@ namespace Cryville.Common.Font {
public sealed class TableDirectory : FontTable<TableRecord, object> {
readonly UInt32 sfntVersion;
readonly UInt16 numTables;
#pragma warning disable IDE0052 // Reserved
readonly UInt16 searchRange;
readonly UInt16 entrySelector;
readonly UInt16 rangeShift;
#pragma warning restore IDE0052 // Reserved
readonly List<TableRecord> tableRecords = new List<TableRecord>();
public TableDirectory(BinaryReader reader, UInt32 offset) : base(reader, offset) {
sfntVersion = reader.ReadUInt32();
if (sfntVersion != 0x00010000 && sfntVersion != 0x4F54544F &&
sfntVersion != 0x74727565 && sfntVersion != 0x74797031) throw new NotSupportedException();
numTables = reader.ReadUInt16();
searchRange = reader.ReadUInt16();
entrySelector = reader.ReadUInt16();
@@ -99,48 +107,63 @@ namespace Cryville.Common.Font {
count = reader.ReadUInt16();
storageOffset = reader.ReadUInt16();
for (UInt16 i = 0; i < count; i++)
nameRecord.Add(new NameRecord {
platformID = reader.ReadUInt16(),
encodingID = reader.ReadUInt16(),
languageID = reader.ReadUInt16(),
nameID = (NameID)reader.ReadUInt16(),
length = reader.ReadUInt16(),
stringOffset = reader.ReadUInt16(),
});
nameRecord.Add(new NameRecord(
reader.ReadUInt16(),
reader.ReadUInt16(),
reader.ReadUInt16(),
(NameID)reader.ReadUInt16(),
reader.ReadUInt16(),
reader.ReadUInt16()
));
if (version == 1) {
langTagCount = reader.ReadUInt16();
for (UInt16 i = 0; i < langTagCount; i++)
langTagRecord.Add(new LangTagRecord {
length = reader.ReadUInt16(),
langTagOffset = reader.ReadUInt16(),
});
langTagRecord.Add(new LangTagRecord(
reader.ReadUInt16(),
reader.ReadUInt16()
));
}
foreach (var i in nameRecord)
i.Load(reader, offset + storageOffset);
if (version == 1) {
foreach (var i in langTagRecord)
i.Load(reader, offset + storageOffset);
}
UInt32 origin = (UInt32)reader.BaseStream.Position;
for (int i = 0; i < nameRecord.Count; i++) nameRecord[i] = nameRecord[i].Load(reader, origin);
for (int i = 0; i < langTagRecord.Count; i++) langTagRecord[i] = langTagRecord[i].Load(reader, origin);
}
public sealed override IReadOnlyList<NameRecord> GetItems() {
return nameRecord;
}
}
public struct NameRecord {
public UInt16 platformID;
public UInt16 encodingID;
public UInt16 languageID;
public NameID nameID;
public UInt16 length;
public UInt16 stringOffset;
public String value { get; private set; }
public NameRecord Load(BinaryReader reader, UInt32 origin) {
reader.BaseStream.Position = origin + stringOffset;
public class NameRecord {
public UInt16 PlatformID { get; private set; }
public UInt16 EncodingID { get; private set; }
public UInt16 LanguageID { get; private set; }
public NameID NameID { get; private set; }
public UInt16 Length { get; private set; }
public UInt16 StringOffset { get; private set; }
public String Value { get; private set; }
public NameRecord(UInt16 platformID, UInt16 encodingID, UInt16 languageID, NameID nameID, UInt16 length, UInt16 stringOffset) {
PlatformID = platformID;
EncodingID = encodingID;
LanguageID = languageID;
NameID = nameID;
Length = length;
StringOffset = stringOffset;
}
public void Load(BinaryReader reader, UInt32 origin) {
reader.BaseStream.Position = origin + StringOffset;
Encoding encoding;
switch (platformID) {
case 0: encoding = Encoding.BigEndianUnicode; break;
case 3: encoding = Encoding.BigEndianUnicode; break;
default: return this;
try {
switch (PlatformID) {
case 0: encoding = Encoding.BigEndianUnicode; break;
case 1: encoding = Encoding.GetEncoding(10000 + EncodingID); break;
case 3: encoding = Encoding.BigEndianUnicode; break;
default: return;
}
}
value = encoding.GetString(reader.ReadBytes(length));
return this;
catch (NotSupportedException) { return; }
catch (ArgumentException) { return; }
Value = encoding.GetString(reader.ReadBytes(Length));
}
}
public enum NameID : UInt16 {
@@ -171,47 +194,58 @@ namespace Cryville.Common.Font {
DarkBackgroundPalette = 24,
VariationsPostScriptNamePrefix = 25,
}
public struct LangTagRecord {
public UInt16 length;
public UInt16 langTagOffset;
public String value { get; private set; }
public LangTagRecord Load(BinaryReader reader, UInt32 origin) {
reader.BaseStream.Position = origin + langTagOffset;
value = Encoding.BigEndianUnicode.GetString(reader.ReadBytes(length));
return this;
public class LangTagRecord {
public UInt16 Length { get; private set; }
public UInt16 LangTagOffset { get; private set; }
public String Value { get; private set; }
public LangTagRecord(UInt16 length, UInt16 langTagOffset) {
Length = length;
LangTagOffset = langTagOffset;
}
public void Load(BinaryReader reader, UInt32 origin) {
reader.BaseStream.Position = origin + LangTagOffset;
Value = Encoding.BigEndianUnicode.GetString(reader.ReadBytes(Length));
}
}
public sealed class MetaTable : FontTable<DataMap> {
readonly UInt32 version;
#pragma warning disable IDE0052 // Reserved
readonly UInt32 flags;
#pragma warning restore IDE0052 // Reserved
readonly UInt32 dataMapCount;
readonly List<DataMap> dataMaps = new List<DataMap>();
public MetaTable(BinaryReader reader, UInt32 offset) : base(reader, offset) {
version = reader.ReadUInt32();
if (version != 1) throw new NotSupportedException();
flags = reader.ReadUInt32();
reader.ReadUInt32();
dataMapCount = reader.ReadUInt32();
for (UInt32 i = 0; i < dataMapCount; i++)
dataMaps.Add(new DataMap {
tag = reader.ReadTag(),
dataOffset = reader.ReadUInt32(),
dataLength = reader.ReadUInt32(),
});
for (int i = 0; i < dataMaps.Count; i++) dataMaps[i] = dataMaps[i].Load(reader, offset);
dataMaps.Add(new DataMap (
reader.ReadTag(),
reader.ReadUInt32(),
reader.ReadUInt32()
));
foreach (var i in dataMaps)
i.Load(reader, offset);
}
public sealed override IReadOnlyList<DataMap> GetItems() {
return dataMaps;
}
}
public struct DataMap {
public String tag;
public UInt32 dataOffset;
public UInt32 dataLength;
public String value { get; private set; }
public DataMap Load(BinaryReader reader, UInt32 origin) {
reader.BaseStream.Position = origin + dataOffset;
value = Encoding.ASCII.GetString(reader.ReadBytes((int)dataLength));
return this;
public class DataMap {
public String Tag { get; private set; }
public UInt32 DataOffset { get; private set; }
public UInt32 DataLength { get; private set; }
public String Value { get; private set; }
public DataMap(String tag, UInt32 dataOffset, UInt32 dataLength) {
Tag = tag;
DataOffset = dataOffset;
DataLength = dataLength;
}
public void Load(BinaryReader reader, UInt32 origin) {
reader.BaseStream.Position = origin + DataOffset;
Value = Encoding.ASCII.GetString(reader.ReadBytes((int)DataLength));
}
}
public static class BinaryReaderExtensions {

View File

@@ -23,9 +23,9 @@ namespace Cryville.Common.Font {
protected override void GetName(BinaryReader reader) {
var dir = new TableDirectory(reader, (uint)reader.BaseStream.Position);
var nameTable = (NameTable)dir.GetSubTable((from i in dir.GetItems() where i.tableTag == "name" select i).Single());
FamilyName = (from i in nameTable.GetItems() where i.nameID == NameID.FontFamilyName && i.value != null select i.value).First();
SubfamilyName = (from i in nameTable.GetItems() where i.nameID == NameID.FontSubfamilyName && i.value != null select i.value).First();
FullName = (from i in nameTable.GetItems() where i.nameID == NameID.FullFontName && i.value != null select i.value).First();
FamilyName = (from i in nameTable.GetItems() where i.NameID == NameID.FontFamilyName && i.Value != null select i.Value).First();
SubfamilyName = (from i in nameTable.GetItems() where i.NameID == NameID.FontSubfamilyName && i.Value != null select i.Value).First();
FullName = (from i in nameTable.GetItems() where i.NameID == NameID.FullFontName && i.Value != null select i.Value).First();
}
}
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 520554ce9a8205b4b91e0ff2b8011673
guid: 1a624371d4108614b9cdc4acca1499e2
folderAsset: yes
DefaultImporter:
externalObjects: {}

View File

@@ -4,12 +4,11 @@ using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net.Sockets;
using System.Text;
namespace Cryville.Common.Network {
public class HttpClient {
namespace Cryville.Common.Network.Http11 {
public class Http11Client : IDisposable {
private readonly string _directHost;
protected string DirectHost { get { return _directHost; } }
@@ -19,29 +18,17 @@ namespace Cryville.Common.Network {
readonly Uri _baseUri;
readonly int origPort;
protected string Version = "HTTP/1.1";
protected const string Version = "HTTP/1.1";
protected TcpClient TcpClient { get; private set; }
protected Stream RawTcpStream {
get {
return TcpClient.GetStream();
}
}
protected virtual Stream Stream {
get {
return TcpClient.GetStream();
}
}
protected virtual string WindowsProxyProtocolName {
get {
return "http";
}
}
protected Stream RawTcpStream { get { return TcpClient.GetStream(); } }
protected virtual Stream Stream { get { return TcpClient.GetStream(); } }
protected virtual string WindowsProxyProtocolName { get { return "http"; } }
private readonly bool _proxied = false;
public Dictionary<string, string> Headers { get; set; }
public HttpClient(Uri baseUri, int port = 80) {
public Http11Client(Uri baseUri, int port = 80) {
_directHost = baseUri.Host;
_directPort = port;
_baseUri = baseUri;
@@ -61,18 +48,29 @@ namespace Cryville.Common.Network {
public virtual void Close() {
TcpClient.Close();
}
public HttpResponse Request(string method, Uri uri, string body = null, Encoding encoding = null) {
public void Dispose() {
Dispose(true);
GC.SuppressFinalize(this);
}
public virtual void Dispose(bool disposing) {
if (disposing) {
Close();
}
}
public Http11Response Request(string method, Uri uri, string body = null, Encoding encoding = null) {
string struri = GetUri(uri).PathAndQuery;
return Request(Stream, method, struri, body, encoding);
}
public HttpResponse Request(Stream stream, string method, string uri, string body = null, Encoding encoding = null) {
var headers = new Dictionary<string, string>();
Http11Response Request(Stream stream, string method, string uri, string body = null, Encoding encoding = null) {
var headers = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
foreach (var h in Headers)
headers.Add(h.Key, h.Value);
headers["Host"] = _baseUri.Host;
byte[] payload = new byte[0];
byte[] payload = null;
if (body != null) {
if (encoding == null)
encoding = Encoding.UTF8;
@@ -80,22 +78,24 @@ namespace Cryville.Common.Network {
headers.Add("Content-Encoding", encoding.EncodingName);
headers.Add("Content-Length", payload.Length.ToString(CultureInfo.InvariantCulture));
}
string request_line = string.Format(
"{0} {1} {2}\r\n", method, uri, Version
);
string header_fields = string.Concat((
from h in headers select h.Key + ":" + h.Value + "\r\n"
).ToArray());
byte[] buffer0 = Encoding.ASCII.GetBytes(string.Format(
"{0}{1}\r\n", request_line, header_fields
));
byte[] buffer1 = new byte[buffer0.Length + payload.Length];
Array.Copy(buffer0, buffer1, buffer0.Length);
Array.Copy(payload, 0, buffer1, buffer0.Length, payload.Length);
Logger.Log("main", 0, "Network", Encoding.UTF8.GetString(buffer1));
stream.Write(buffer1, 0, buffer1.Length);
stream.Flush();
var response = new HttpResponse(stream);
using (var writer = new StreamWriter(stream, Encoding.ASCII, 1024, true)) {
writer.Write(method);
writer.Write(' ');
writer.Write(uri);
writer.Write(' ');
writer.Write(Version);
writer.Write("\r\n");
foreach (var header in headers) {
writer.Write(header.Key);
writer.Write(':');
writer.Write(header.Value);
writer.Write("\r\n");
}
writer.Write("\r\n");
if (payload != null) writer.Write(payload);
writer.Flush();
}
var response = new Http11Response(stream);
Logger.Log("main", 0, "Network", "{0}", response);
return response;
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: ae9dab8f520fadc4194032f523ca87c1
guid: 5a795e416e54c69418de1a3c27a88932
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -1,31 +1,41 @@
using Cryville.Common.Logging;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace Cryville.Common.Network {
public class HttpResponse {
namespace Cryville.Common.Network.Http11 {
public class Http11Response : IDisposable {
static readonly char[] spchar = new char[]{ ' ' };
public string HttpVersion { get; private set; }
public string StatusCode { get; private set; }
public string ReasonPhase { get; private set; }
public Dictionary<string, string> Headers { get; private set; }
public HttpResponseStream MessageBody { get; private set; }
internal HttpResponse(Stream stream) {
public Http11ResponseStream MessageBody { get; private set; }
internal Http11Response(Stream stream) {
var reader = new BinaryReader(stream, Encoding.ASCII);
var statu_line = ReadLine(reader).Split(spchar, 3);
HttpVersion = statu_line[0];
StatusCode = statu_line[1];
ReasonPhase = statu_line[2];
Logger.Log("main", 0, "Network", "Receive Response: {0} {1} {2}", HttpVersion, StatusCode, ReasonPhase);
Headers = new Dictionary<string, string>();
Headers = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
while (ParseHeader(reader, Headers)) ;
if (Headers.ContainsKey("content-length")) {
int length = int.Parse(Headers["content-length"]);
MessageBody = new HttpResponseBlockStream(reader, length);
MessageBody = new Http11ResponseBlockStream(reader, length);
}
else if (Headers.ContainsKey("transfer-encoding") && Headers["transfer-encoding"] == "chunked") {
MessageBody = new HttpResponseChunkedStream(reader);
MessageBody = new Http11ResponseChunkedStream(reader);
}
}
public void Dispose() {
Dispose(true);
GC.SuppressFinalize(this);
}
public virtual void Dispose(bool disposing) {
if (disposing) {
MessageBody.Dispose();
}
}
@@ -37,12 +47,11 @@ namespace Cryville.Common.Network {
// TODO Multiline header
var header = ReadLine(reader);
if (header == "") return false;
var s = header.Split(':');
var s = header.Split(':', 2);
string field_name = s[0].Trim().ToLower();
string field_value = s[1].Trim();
if (headers.ContainsKey(field_name)) headers[field_name] += "," + field_value;
else headers.Add(field_name, field_value);
Logger.Log("main", 0, "Network", "Receive Header {0}: {1}", field_name, field_value);
return true;
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 9653d5e145f2866439a0fcd1b27f49c4
guid: 71234dd1c93d47b4893750686b2333a3
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -1,12 +1,11 @@
using Cryville.Common.Logging;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
namespace Cryville.Common.Network {
public abstract class HttpResponseStream : Stream {
namespace Cryville.Common.Network.Http11 {
public abstract class Http11ResponseStream : Stream {
public override bool CanRead { get { return true; } }
public override bool CanSeek { get { return false; } }
@@ -37,11 +36,11 @@ namespace Cryville.Common.Network {
}
}
internal sealed class HttpResponseBlockStream : HttpResponseStream {
internal sealed class Http11ResponseBlockStream : Http11ResponseStream {
readonly BinaryReader _reader;
readonly int _length;
int _pos = 0;
internal HttpResponseBlockStream(BinaryReader reader, int length) {
internal Http11ResponseBlockStream(BinaryReader reader, int length) {
_reader = reader;
_length = length;
}
@@ -51,7 +50,6 @@ namespace Cryville.Common.Network {
if (recv_len == 0) return 0;
while (recv < recv_len) {
recv += _reader.Read(buffer, offset + recv, count - recv);
Logger.Log("main", 0, "Network", "Message body received: {0}/{1}/{2}", recv, recv_len, _length);
}
_pos += recv_len;
return recv_len;
@@ -63,36 +61,34 @@ namespace Cryville.Common.Network {
}
}
internal sealed class HttpResponseChunkedStream : HttpResponseStream {
internal sealed class Http11ResponseChunkedStream : Http11ResponseStream {
readonly BinaryReader _reader;
byte[] _chunk = null;
int _pos = 0;
internal HttpResponseChunkedStream(BinaryReader reader) {
internal Http11ResponseChunkedStream(BinaryReader reader) {
_reader = reader;
ReadChunk();
}
public void ReadChunk() {
if (_chunk != null && _chunk.Length == 0) return;
string[] chunkHeader = HttpResponse.ReadLine(_reader).Split(';');
// int chunkSize = Array.IndexOf(LEN, chunkHeader[0].ToLower()[0]);
int chunkSize = int.Parse(chunkHeader[0], NumberStyles.HexNumber);
if (chunkSize == -1)
string[] chunkHeader = Http11Response.ReadLine(_reader).Split(';');
int chunkSize;
if (!int.TryParse(chunkHeader[0], NumberStyles.HexNumber, CultureInfo.InvariantCulture, out chunkSize))
throw new IOException("Corrupted chunk received");
if (chunkSize == 0) {
_chunk = new byte[0];
// TODO TE Header, now just discard
var headers = new Dictionary<string, string>();
while (HttpResponse.ParseHeader(_reader, headers)) ;
while (Http11Response.ParseHeader(_reader, headers)) ;
return;
}
_chunk = new byte[chunkSize];
int recv = 0;
while (recv < chunkSize) {
recv += _reader.Read(_chunk, recv, chunkSize - recv);
Logger.Log("main", 0, "Network", "Message chunk received: {0}/{1}", recv, chunkSize);
}
_pos = 0;
if (HttpResponse.ReadLine(_reader) != "")
if (Http11Response.ReadLine(_reader) != "")
throw new IOException("Corrupted chunk received");
}
public override int Read(byte[] buffer, int offset, int count) {

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 49a8d5b9869e5bb42bafbe71f84fecc5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,8 +1,8 @@
using System;
using System.IO;
namespace Cryville.Common.Network {
public class HttpsClient : HttpClient {
namespace Cryville.Common.Network.Http11 {
public class Https11Client : Http11Client {
readonly TlsClient _tlsClient;
protected override Stream Stream {
@@ -16,7 +16,7 @@ namespace Cryville.Common.Network {
}
}
public HttpsClient(Uri baseUri) : base(baseUri, 443) {
public Https11Client(Uri baseUri) : base(baseUri, 443) {
_tlsClient = new TlsClient(RawTcpStream, baseUri.Host);
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c5c233e6228ce204fa1a9724c48ac8fe
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,12 +0,0 @@
fileFormatVersion: 2
guid: 5ea931bf5488011468f3d1243a038874
timeCreated: 1622589817
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,12 +0,0 @@
fileFormatVersion: 2
guid: 07e8215a93e3eb1418685009f0c58dcd
timeCreated: 1622596274
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,12 +0,0 @@
fileFormatVersion: 2
guid: f191de447a708da4f9d230e6545ce0a6
timeCreated: 1635470462
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,12 +0,0 @@
fileFormatVersion: 2
guid: 9b35290e0e147a342acc29a20c8fceaf
timeCreated: 1622503538
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,8 +1,8 @@
using Cryville.Common.Logging;
using Org.BouncyCastle.Security;
using Org.BouncyCastle.Tls;
using Org.BouncyCastle.Tls.Crypto;
using Org.BouncyCastle.Tls.Crypto.Impl.BC;
using System;
using System.Collections;
using System.IO;
using System.Linq;
@@ -10,7 +10,7 @@ using System.Text;
using BcTlsClient = Org.BouncyCastle.Tls.TlsClient;
namespace Cryville.Common.Network {
public class TlsClient {
public class TlsClient : IDisposable {
readonly TlsClientProtocol _protocol;
readonly BcTlsClient _tlsClient;
public Stream Stream { get; private set; }
@@ -28,6 +28,17 @@ namespace Cryville.Common.Network {
_protocol.Close();
}
public void Dispose() {
Dispose(true);
GC.SuppressFinalize(this);
}
public virtual void Dispose(bool disposing) {
if (disposing) {
Close();
}
}
private class InternalTlsClient : DefaultTlsClient {
readonly string _host;
@@ -72,20 +83,6 @@ namespace Cryville.Common.Network {
public override TlsAuthentication GetAuthentication() {
return new NullTlsAuthentication();
}
public override void NotifyAlertReceived(short alertLevel, short alertDescription) {
Logger.Log("main", 0, "Network/TLS", "TLS Alert {0} {1}", alertLevel, alertDescription);
}
public override void NotifyServerVersion(ProtocolVersion serverVersion) {
base.NotifyServerVersion(serverVersion);
Logger.Log("main", 0, "Network/TLS", "NotifyServerVersion {0}", serverVersion);
}
public override void NotifySelectedCipherSuite(int selectedCipherSuite) {
base.NotifySelectedCipherSuite(selectedCipherSuite);
Logger.Log("main", 0, "Network/TLS", "NotifySelectedCipherSuite {0}", selectedCipherSuite);
}
}
private class NullTlsAuthentication : TlsAuthentication {

View File

@@ -24,8 +24,8 @@ namespace Cryville.Common.Pdt {
/// <param name="exp">The expression to evaluate.</param>
/// <returns>Whether the evaluaton succeeded.</returns>
public bool Evaluate(PdtOperator target, PdtExpression exp) {
var prevFrameCount = _framecount;
try {
var prevFrameCount = _framecount;
_revokepttconst = false;
for (var ip = exp.Instructions.First; ip != null; ip = ip.Next)
ip.Value.Execute(this, ref ip);
@@ -33,12 +33,14 @@ namespace Cryville.Common.Pdt {
exp.IsConstant = exp.IsPotentialConstant = !_revokepttconst;
}
var ret = Operate(target, _framecount - prevFrameCount, true);
for (var i = prevFrameCount; i < _framecount; i++) DiscardStack();
return ret;
}
catch (Exception ex) {
throw new EvaluationFailureException(exp, ex);
}
finally {
for (var i = prevFrameCount; i < _framecount; i++) DiscardStack();
}
}
/// <summary>
/// Optimizes an expression by merging its instructions.
@@ -133,10 +135,7 @@ namespace Cryville.Common.Pdt {
for (var ins = il.First; ins != null; ins = ins.Next) {
if (!(ins.Value is PdtInstruction.PushConstant)) {
exp.IsConstant = false;
}
else if (!(ins.Value is PdtInstruction.PushVariable)) {
exp.IsPotentialConstant = false;
return;
break;
}
}
}
@@ -205,7 +204,7 @@ namespace Cryville.Common.Pdt {
var frame = _stack[--_framecount];
if (frame.Type == PdtInternalType.Error) {
_framecount -= pc - i - 1;
_stack[_framecount++] = new StackFrame { Type = PdtInternalType.Error, Offset = _goffset, Length = 0 };
_stack[_framecount++] = new StackFrame { Type = PdtInternalType.Error, Offset = -1, Length = 0 };
return false;
}
op.LoadOperand(new PdtVariableMemory(frame.Type, pmem + frame.Offset, frame.Length));
@@ -218,13 +217,15 @@ namespace Cryville.Common.Pdt {
internal unsafe void Collapse(int name, ref LinkedListNode<PdtInstruction> self, LinkedListNode<PdtInstruction> target) {
fixed (byte* pmem = _mem) {
var frame = _stack[--_framecount];
_goffset -= frame.Length;
if (frame.Type == PdtInternalType.Error) {
_stack[_framecount++] = new StackFrame { Type = PdtInternalType.Error, Offset = _goffset, Length = 0 };
_stack[_framecount++] = new StackFrame { Type = PdtInternalType.Error, Offset = -1, Length = 0 };
self = target;
return;
}
if (Collapse(name, new PdtVariableMemory(frame.Type, pmem + frame.Offset, frame.Length))) {
_framecount++;
_goffset += frame.Length;
self = target;
}
}

View File

@@ -0,0 +1,95 @@
using System;
namespace Cryville.Common {
public class PropertyTweener<T> {
readonly Func<T> _getter;
readonly Action<T> _setter;
readonly Tweener<T> _tweener;
public PropertyTweener(Func<T> getter, Action<T> setter, Tweener<T> tweener) {
_getter = getter;
_setter = setter;
_tweener = tweener;
var initialValue = getter();
_tweener.Start(initialValue, initialValue, float.Epsilon);
}
public PropertyTweener<T> Start(T endValue, float duration) {
_tweener.Start(_getter(), endValue, duration);
return this;
}
public void Advance(float deltaTime) {
if (!_tweener.Advance(deltaTime, out var value)) return;
_setter(value);
}
}
public delegate T Addition<T>(T a, T b);
public delegate T Multiplication<T>(float k, T b);
public delegate float EasingFunction(float t);
public class Tweener<T> {
readonly Addition<T> _addition;
readonly Multiplication<T> _multiplication;
public Tweener(Addition<T> addition, Multiplication<T> multiplication) {
_addition = addition;
_multiplication = multiplication;
}
public EasingFunction EasingFunction { get; set; } = EasingFunctions.Linear;
public Tweener<T> With(EasingFunction easing) {
EasingFunction = easing;
return this;
}
T _startValue = default;
T _endValue = default;
float _duration = float.Epsilon;
float _time;
bool _endOfTween;
public Tweener<T> Start(T startValue, T endValue, float duration) {
_startValue = startValue;
_endValue = endValue;
_duration = duration;
_time = 0;
_endOfTween = false;
return this;
}
public bool Advance(float deltaTime, out T value) {
if (_endOfTween) {
value = _endValue;
return false;
}
if (_time >= _duration) {
value = _endValue;
_endOfTween = true;
return true;
}
_time += deltaTime;
var ratio = EasingFunction(System.Math.Clamp(_time / _duration, 0, 1));
value = _addition(_multiplication(1 - ratio, _startValue), _multiplication(ratio, _endValue));
return true;
}
public Tweener<object> Boxed() {
return new Tweener<object>((a, b) => _addition((T)a, (T)b), (k, v) => _multiplication(k, (T)v));
}
}
public static class Tweeners {
public static Tweener<byte> Byte => new((a, b) => (byte)(a + b), (k, v) => (byte)(k * v));
public static Tweener<sbyte> SByte => new((a, b) => (sbyte)(a + b), (k, v) => (sbyte)(k * v));
public static Tweener<short> Int16 => new((a, b) => (short)(a + b), (k, v) => (short)(k * v));
public static Tweener<ushort> UInt16 => new((a, b) => (ushort)(a + b), (k, v) => (ushort)(k * v));
public static Tweener<int> Int32 => new((a, b) => a + b, (k, v) => (int)(k * v));
public static Tweener<uint> UInt32 => new((a, b) => a + b, (k, v) => (uint)(k * v));
public static Tweener<long> Int64 => new((a, b) => a + b, (k, v) => (long)(k * v));
public static Tweener<ulong> UInt64 => new((a, b) => a + b, (k, v) => (ulong)(k * v));
public static Tweener<IntPtr> IntPtr => new((a, b) => new IntPtr((long)a + (long)b), (k, v) => new IntPtr((long)(k * (long)v)));
public static Tweener<UIntPtr> UIntPtr => new((a, b) => new UIntPtr((ulong)a + (ulong)b), (k, v) => new UIntPtr((ulong)(k * (ulong)v)));
public static Tweener<float> Float => new((a, b) => a + b, (k, v) => k * v);
public static Tweener<double> Double => new((a, b) => a + b, (k, v) => k * v);
}
public static class EasingFunctions {
public static float Linear(float x) => x;
public static float InQuad(float x) => x * x;
public static float InCubic(float x) => x * x * x;
public static float InSine(float x) => 1 - OutSine(1 - x);
public static float OutQuad(float x) => 1 - InQuad(1 - x);
public static float OutCubic(float x) => 1 - InCubic(1 - x);
public static float OutSine(float x) => MathF.Sin(x * MathF.PI / 2);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0b4037ba4138aae47b8da984f30b4db9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -57,6 +57,7 @@ namespace Cryville.Common.Unity {
suspended = true;
if (currentNetworkTask != null) {
currentNetworkTask.Cancel();
networkTasks.Enqueue(currentNetworkTask);
currentNetworkTask = null;
}
}
@@ -91,15 +92,6 @@ namespace Cryville.Common.Unity {
/// A network task.
/// </summary>
public abstract class NetworkTask {
protected NetworkTask(string uri) {
Uri = uri;
}
/// <summary>
/// The URI of the resource.
/// </summary>
public string Uri { get; private set; }
/// <summary>
/// Whether the task is cancelled.
/// </summary>
@@ -108,40 +100,56 @@ namespace Cryville.Common.Unity {
/// <summary>
/// Cancels the task.
/// </summary>
public virtual void Cancel() {
public void Cancel() {
Cancelled = true;
OnCancel();
}
protected virtual void OnCancel() { }
#if UNITY_5_4_OR_NEWER
protected UnityWebRequest www;
/// <summary>
/// Starts the task.
/// </summary>
public virtual void Start() {
www = new UnityWebRequest(Uri);
www.SendWebRequest();
}
public abstract void Start();
/// <summary>
/// Gets whether the task is done.
/// </summary>
/// <returns>Whether the task is done.</returns>
public virtual bool Done() {
public abstract bool Done();
}
/// <summary>
/// A Unity network task.
/// </summary>
public abstract class UnityNetworkTask : NetworkTask {
protected UnityNetworkTask(string uri) {
Uri = uri;
}
/// <summary>
/// The URI of the resource.
/// </summary>
public string Uri { get; private set; }
#if UNITY_5_4_OR_NEWER
protected UnityWebRequest www;
/// <inheritdoc />
public override void Start() {
www = new UnityWebRequest(Uri);
www.SendWebRequest();
}
/// <inheritdoc />
public override bool Done() {
if (!www.isDone) return false;
return true;
}
#else
protected WWW www;
/// <summary>
/// Starts the task.
/// </summary>
/// <inheritdoc />
public virtual void Start() {
www = new WWW(Uri);
}
/// <summary>
/// Gets whether the task is done.
/// </summary>
/// <returns>Whether the task is done.</returns>
/// <inheritdoc />
public virtual bool Done() {
if (!www.isDone) return false;
return true;
@@ -149,9 +157,9 @@ namespace Cryville.Common.Unity {
#endif
}
/// <summary>
/// A <see cref="NetworkTask" /> that loads a texture.
/// A <see cref="UnityNetworkTask" /> that loads a texture.
/// </summary>
public class LoadTextureTask : NetworkTask {
public class LoadTextureTask : UnityNetworkTask {
/// <summary>
/// Creates an instance of the <see cref="LoadTextureTask" /> class.
/// </summary>

View File

@@ -0,0 +1,50 @@
#if UNITY_EDITOR
using System;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using UnityEditor;
namespace Cryville.Common.Unity {
[InitializeOnLoad]
public class ScopedThreadAttacherInjector {
static readonly Encoding _encoding = new UTF8Encoding(false, true);
static string _filePath;
static string _oldSrc;
static ScopedThreadAttacherInjector() {
BuildPlayerWindow.RegisterBuildPlayerHandler(opt => HandlePlayerBuild(opt));
}
static void HandlePlayerBuild(BuildPlayerOptions opt) {
try {
OnPreprocessBuild();
BuildPlayerWindow.DefaultBuildMethods.BuildPlayer(opt);
}
finally {
OnPostprocessBuild();
}
}
static void OnPreprocessBuild() {
var il2cppRoot = Environment.GetEnvironmentVariable("UNITY_IL2CPP_PATH");
if (string.IsNullOrEmpty(il2cppRoot)) {
_filePath = string.Empty;
return;
}
_filePath = Path.Combine(il2cppRoot, "libil2cpp", "vm", "ScopedThreadAttacher.cpp");
if (!File.Exists(_filePath)) {
_filePath = string.Empty;
return;
}
_oldSrc = File.ReadAllText(_filePath, _encoding);
File.WriteAllText(_filePath, Regex.Replace(_oldSrc, @"~\s*?ScopedThreadAttacher\s*?\(\s*?\)\s*?\{.*\}", "~ScopedThreadAttacher(){}", RegexOptions.Singleline), _encoding);
}
static void OnPostprocessBuild() {
if (string.IsNullOrEmpty(_filePath)) return;
File.WriteAllText(_filePath, _oldSrc, _encoding);
}
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2322d8e9250e9e6469826361223dfdda
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,181 @@
using Cryville.Common.Reflection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using UnityEngine;
namespace Cryville.Common.Unity {
public class StateTweener : MonoBehaviour {
[SerializeField]
State[] m_states;
[Serializable]
struct State {
[SerializeField]
public string Name;
[SerializeField]
public AttributeState[] Attributes;
}
[Serializable]
struct AttributeState {
[SerializeField]
public AttributeBinding Attribute;
[SerializeField]
public string Value;
}
[Serializable]
struct AttributeBinding : IEquatable<AttributeBinding> {
[SerializeField]
public Component Component;
[SerializeField]
public string Attribute;
public bool Equals(AttributeBinding other) {
return Component.Equals(other.Component) && Attribute.Equals(other.Attribute);
}
public override bool Equals(object obj) {
return obj is AttributeBinding && Equals((AttributeBinding)obj);
}
public override int GetHashCode() {
return Component.GetHashCode() ^ Attribute.GetHashCode();
}
}
[SerializeField]
StateTweener[] m_children;
readonly List<string> _statePriority = new List<string>();
readonly Dictionary<AttributeBinding, object> _defaults = new Dictionary<AttributeBinding, object>();
readonly Dictionary<AttributeBinding, PropertyTweener<object>> _tweeners = new Dictionary<AttributeBinding, PropertyTweener<object>>();
readonly Dictionary<string, Dictionary<AttributeBinding, object>> _runtimeStates = new Dictionary<string, Dictionary<AttributeBinding, object>>();
void Awake() {
var types = new Dictionary<AttributeBinding, Type>();
foreach (var state in m_states) {
Dictionary<AttributeBinding, object> attrs;
_statePriority.Add(state.Name);
_runtimeStates.Add(state.Name, attrs = new Dictionary<AttributeBinding, object>());
foreach (var attr in state.Attributes) {
var binding = attr.Attribute;
if (!types.TryGetValue(binding, out var type)) {
var comp = binding.Component;
var ctype = comp.GetType();
var path = binding.Attribute.Split('.');
var propName = path[0];
var prop = ctype.GetMember(propName, MemberTypes.Field | MemberTypes.Property, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static).Single();
var gvd = FieldLikeHelper.GetGetValueDelegate(prop);
var svd = FieldLikeHelper.GetSetValueDelegate(prop);
Func<object> getter;
Action<object> setter;
if (path.Length == 1) {
type = FieldLikeHelper.GetMemberType(prop);
getter = () => gvd(comp);
setter = v => svd(comp, v);
}
else if (path.Length == 2) {
var propType = FieldLikeHelper.GetMemberType(prop);
var subPropName = path[1];
var subProp = propType.GetMember(subPropName, MemberTypes.Field | MemberTypes.Property, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static).Single();
type = FieldLikeHelper.GetMemberType(subProp);
var gsvd = FieldLikeHelper.GetGetValueDelegate(subProp);
getter = () => gsvd(gvd(comp));
var ssvd = FieldLikeHelper.GetSetValueDelegate(subProp);
setter = v => {
object obj = gvd(comp);
ssvd(obj, v);
svd(comp, obj);
};
}
else {
throw new FormatException("Invalid attribute path.");
}
_tweeners.Add(binding, CreateTweener(type, getter, setter));
_defaults.Add(binding, getter());
types.Add(binding, type);
}
attrs.Add(binding, Convert.ChangeType(attr.Value, type));
}
}
foreach (var def in _defaults) {
foreach (var state in _runtimeStates) {
if (!state.Value.ContainsKey(def.Key)) {
state.Value.Add(def.Key, def.Value);
}
}
}
_spcmp = new StatePriorityComparer(this);
}
PropertyTweener<object> CreateTweener(Type type, Func<object> getter, Action<object> setter) {
if (type == typeof(byte)) return new PropertyTweener<object>(getter, setter, Tweeners.Byte.Boxed());
else if (type == typeof(sbyte)) return new PropertyTweener<object>(getter, setter, Tweeners.SByte.Boxed());
else if (type == typeof(short)) return new PropertyTweener<object>(getter, setter, Tweeners.Int16.Boxed());
else if (type == typeof(ushort)) return new PropertyTweener<object>(getter, setter, Tweeners.UInt16.Boxed());
else if (type == typeof(int)) return new PropertyTweener<object>(getter, setter, Tweeners.Int32.Boxed());
else if (type == typeof(uint)) return new PropertyTweener<object>(getter, setter, Tweeners.UInt32.Boxed());
else if (type == typeof(long)) return new PropertyTweener<object>(getter, setter, Tweeners.Int64.Boxed());
else if (type == typeof(ulong)) return new PropertyTweener<object>(getter, setter, Tweeners.UInt64.Boxed());
else if (type == typeof(IntPtr)) return new PropertyTweener<object>(getter, setter, Tweeners.IntPtr.Boxed());
else if (type == typeof(UIntPtr)) return new PropertyTweener<object>(getter, setter, Tweeners.UIntPtr.Boxed());
else if (type == typeof(float)) return new PropertyTweener<object>(getter, setter, Tweeners.Float.Boxed());
else if (type == typeof(double)) return new PropertyTweener<object>(getter, setter, Tweeners.Double.Boxed());
else throw new NotSupportedException("Property type not supported.");
}
void Update() {
foreach (var tweener in _tweeners) tweener.Value.Advance(Time.deltaTime);
}
readonly List<string> m_cState = new List<string>();
public IReadOnlyList<string> CurrentState => m_cState;
public void ClearState(float transitionDuration = float.Epsilon) {
foreach (var child in m_children) child.ClearState(transitionDuration);
m_cState.Clear();
foreach (var tweener in _tweeners) {
tweener.Value.Start(_defaults[tweener.Key], transitionDuration);
}
}
public void EnterState(string state, float transitionDuration = float.Epsilon) {
if (_runtimeStates.TryGetValue(state, out var rs)) {
int index = m_cState.BinarySearch(state, _spcmp);
if (index < 0) {
index = ~index;
m_cState.Insert(index, state);
}
if (index == m_cState.Count - 1) {
foreach (var s in rs) {
_tweeners[s.Key].Start(s.Value, transitionDuration);
}
}
}
foreach (var child in m_children) child.EnterState(state, transitionDuration);
}
public void ExitState(string state, float transitionDuration = float.Epsilon) {
foreach (var child in m_children) child.ExitState(state, transitionDuration);
if (!_runtimeStates.ContainsKey(state)) return;
int index = m_cState.BinarySearch(state, _spcmp);
if (index < 0) return;
m_cState.RemoveAt(index);
if (index < m_cState.Count) return;
var attrs = m_cState.Count == 0 ? _defaults : _runtimeStates[m_cState[m_cState.Count - 1]];
foreach (var tweener in _tweeners) {
tweener.Value.Start(attrs[tweener.Key], transitionDuration);
}
}
StatePriorityComparer _spcmp;
class StatePriorityComparer : IComparer<string> {
readonly StateTweener _self;
public StatePriorityComparer(StateTweener self) {
_self = self;
}
public int Compare(string x, string y) {
return _self._statePriority.IndexOf(x).CompareTo(_self._statePriority.IndexOf(y));
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d605791cb18d88e4fb0ab6f794361eee
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -6,6 +6,7 @@ namespace Cryville.Common.Unity.UI {
/// <summary>
/// A <see cref="ILayoutElement" /> that takes the length of one axis to compute the preferred length of the other axis with respect to a aspect ratio.
/// </summary>
[ExecuteAlways]
public class AspectRatioLayoutElement : UIBehaviour, ILayoutElement {
[SerializeField]
[Tooltip("The aspect ratio. Width divided by height.")]
@@ -35,32 +36,27 @@ namespace Cryville.Common.Unity.UI {
SetDirty();
}
private void SetDirty() {
if (!IsActive()) return;
LayoutRebuilder.MarkLayoutForRebuild(transform as RectTransform);
}
/// <inheritdoc />
public float minWidth {
get {
return m_isVertical ? 0 : (transform as RectTransform).rect.height * m_aspectRatio;
return m_isVertical ? -1 : (transform as RectTransform).rect.height * m_aspectRatio;
}
}
/// <inheritdoc />
public float preferredWidth { get { return minWidth; } }
/// <inheritdoc />
public float flexibleWidth { get { return 0; } }
public float flexibleWidth { get { return -1; } }
/// <inheritdoc />
public float minHeight {
get {
return m_isVertical ? (transform as RectTransform).rect.width / m_aspectRatio : 0;
return m_isVertical ? (transform as RectTransform).rect.width / m_aspectRatio : -1;
}
}
/// <inheritdoc />
public float preferredHeight { get { return minHeight; } }
/// <inheritdoc />
public float flexibleHeight { get { return 0; } }
public float flexibleHeight { get { return -1; } }
/// <inheritdoc />
public int layoutPriority { get { return 1; } }
@@ -71,34 +67,44 @@ namespace Cryville.Common.Unity.UI {
/// <inheritdoc />
public void CalculateLayoutInputVertical() { }
protected override void OnDidApplyAnimationProperties() {
base.OnDidApplyAnimationProperties();
SetDirty();
}
protected override void OnDisable() {
SetDirty();
base.OnDisable();
}
protected override void OnEnable() {
base.OnEnable();
SetDirty();
}
protected override void OnRectTransformDimensionsChange() {
base.OnRectTransformDimensionsChange();
protected override void OnBeforeTransformParentChanged() {
base.OnBeforeTransformParentChanged();
SetDirty();
}
protected override void OnTransformParentChanged() {
base.OnTransformParentChanged();
SetDirty();
}
// Overriding fails compiler
new void OnValidate() {
protected override void OnDidApplyAnimationProperties() {
base.OnDidApplyAnimationProperties();
SetDirty();
}
protected override void OnValidate() {
base.OnValidate();
SetDirty();
}
protected override void OnDisable() {
SetDirty();
base.OnDisable();
}
protected override void OnRectTransformDimensionsChange() {
base.OnRectTransformDimensionsChange();
SetDirty();
}
bool _delayedSetDirty;
private void SetDirty() {
if (!IsActive()) return;
if (CanvasUpdateRegistry.IsRebuildingLayout()) _delayedSetDirty = true;
else LayoutRebuilder.MarkLayoutForRebuild(transform as RectTransform);
}
void Update() {
if (!_delayedSetDirty) return;
_delayedSetDirty = false;
LayoutRebuilder.MarkLayoutForRebuild(transform as RectTransform);
}
}
}

View File

@@ -56,38 +56,28 @@ namespace Cryville.Common.Unity.UI {
set { m_compact = value; }
}
[SerializeField]
[Tooltip("Whether the sprite is vertical.")]
private bool m_isVertical;
/// <summary>
/// Whether the sprite is vertical.
/// </summary>
public bool IsVertical {
get { return m_isVertical; }
set { m_isVertical = value; }
}
public override Texture mainTexture {
get { return Sprite == null ? s_WhiteTexture : Sprite.texture; }
}
void GetCornerLength(int axis, int corner, Vector4 uv, out float length, out float uvLength) {
float border = Sprite.border[(corner << 1) | axis];
float sizeRatio = border / (axis == 0 ? Sprite.rect.height : Sprite.rect.width);
length = sizeRatio * (axis == 0 ? rectTransform.rect.height : rectTransform.rect.width);
uvLength = (uv[(axis ^ 1) | 2] - uv[axis ^ 1]) * (border / (axis == 0 ? Sprite.rect.width : Sprite.rect.height));
}
protected override void OnPopulateMesh(VertexHelper vh) {
float actualWidth = rectTransform.rect.width;
Vector4 uv = DataUtility.GetOuterUV(Sprite);
float cornerLeftSizeRatio = Sprite.border.x / Sprite.rect.height;
float actualLeftCornerWidth = cornerLeftSizeRatio * rectTransform.rect.height;
float actualLeftUVWidth = (uv.w - uv.y) * (Sprite.border.x / Sprite.rect.width);
float cornerRightSizeRatio = Sprite.border.z / Sprite.rect.height;
float actualRightCornerWidth = cornerRightSizeRatio * rectTransform.rect.height;
float actualRightUVWidth = (uv.w - uv.y) * (Sprite.border.z / Sprite.rect.width);
float actualTotalCornerWidth = actualLeftCornerWidth + actualRightCornerWidth;
Vector2 corner1 = new Vector2(0f, 0f);
Vector2 corner2 = new Vector2(1f, 1f);
corner1.x -= rectTransform.pivot.x;
corner1.y -= rectTransform.pivot.y;
corner2.x -= rectTransform.pivot.x;
corner2.y -= rectTransform.pivot.y;
corner1.x *= actualWidth;
corner1.y *= rectTransform.rect.height;
corner2.x *= actualWidth;
corner2.y *= rectTransform.rect.height;
if (Sprite == null) {
throw new UnityException("No sprite");
}
@@ -95,51 +85,87 @@ namespace Cryville.Common.Unity.UI {
throw new UnityException("No sprite border");
}
int axis = IsVertical ? 1 : 0;
float actualLength = axis == 0 ? rectTransform.rect.width : rectTransform.rect.height;
Vector4 uv = DataUtility.GetOuterUV(Sprite);
GetCornerLength(axis, 0, uv, out var actualStartCornerLength, out var actualStartUVWidth);
GetCornerLength(axis, 1, uv, out var actualEndCornerLength, out var actualEndUVLength);
float actualTotalCornerLength = actualStartCornerLength + actualEndCornerLength;
float w3, w4, w5, w6;
if (actualTotalCornerWidth > actualWidth) {
if (actualTotalCornerLength > actualLength) {
switch (Compact) {
case CompactMode.SqueezeBoth:
w3 = w4 = actualLeftCornerWidth / actualTotalCornerWidth * actualWidth;
w5 = w6 = actualRightCornerWidth / actualTotalCornerWidth * actualWidth;
w3 = w4 = actualStartCornerLength / actualTotalCornerLength * actualLength;
w5 = w6 = actualEndCornerLength / actualTotalCornerLength * actualLength;
break;
case CompactMode.SqueezeLeft:
w3 = w4 = actualWidth - actualRightCornerWidth;
w5 = w6 = actualRightCornerWidth;
w3 = w4 = actualLength - actualEndCornerLength;
w5 = w6 = actualEndCornerLength;
break;
case CompactMode.SqueezeRight:
w3 = w4 = actualLeftCornerWidth;
w5 = w6 = actualWidth - actualLeftCornerWidth;
w3 = w4 = actualStartCornerLength;
w5 = w6 = actualLength - actualStartCornerLength;
break;
case CompactMode.DiagonalLeft:
w3 = actualLeftCornerWidth;
w4 = actualWidth - actualRightCornerWidth;
w5 = actualWidth - actualLeftCornerWidth;
w6 = actualRightCornerWidth;
w3 = actualStartCornerLength;
w4 = actualLength - actualEndCornerLength;
w5 = actualLength - actualStartCornerLength;
w6 = actualEndCornerLength;
break;
case CompactMode.DiagonalRight:
w3 = actualWidth - actualRightCornerWidth;
w4 = actualLeftCornerWidth;
w5 = actualRightCornerWidth;
w6 = actualWidth - actualLeftCornerWidth;
w3 = actualLength - actualEndCornerLength;
w4 = actualStartCornerLength;
w5 = actualEndCornerLength;
w6 = actualLength - actualStartCornerLength;
break;
default:
throw new ArgumentOutOfRangeException("Compact");
}
}
else {
w3 = w4 = actualLeftCornerWidth;
w5 = w6 = actualRightCornerWidth;
w3 = w4 = actualStartCornerLength;
w5 = w6 = actualEndCornerLength;
}
Vector2 corner1 = Vector2.zero;
Vector2 corner2 = Vector2.one;
corner1.x -= rectTransform.pivot[axis];
corner1.y -= rectTransform.pivot[axis ^ 1];
corner2.x -= rectTransform.pivot[axis];
corner2.y -= rectTransform.pivot[axis ^ 1];
corner1.x *= actualLength;
corner1.y *= axis == 0 ? rectTransform.rect.height : rectTransform.rect.width;
corner2.x *= actualLength;
corner2.y *= axis == 0 ? rectTransform.rect.height : rectTransform.rect.width;
vh.Clear();
vh.AddVert(new Vector3(corner1.x, corner2.y), color, new Vector2(uv.x, uv.w));
vh.AddVert(new Vector3(corner1.x, corner1.y), color, new Vector2(uv.x, uv.y));
vh.AddVert(new Vector3(corner1.x + w3, corner2.y), color, new Vector2(uv.x + actualLeftUVWidth, uv.w));
vh.AddVert(new Vector3(corner1.x + w4, corner1.y), color, new Vector2(uv.x + actualLeftUVWidth, uv.y));
vh.AddVert(new Vector3(corner2.x - w5, corner2.y), color, new Vector2(uv.z - actualRightUVWidth, uv.w));
vh.AddVert(new Vector3(corner2.x - w6, corner1.y), color, new Vector2(uv.z - actualRightUVWidth, uv.y));
vh.AddVert(new Vector3(corner2.x, corner2.y), color, new Vector2(uv.z, uv.w));
vh.AddVert(new Vector3(corner2.x, corner1.y), color, new Vector2(uv.z, uv.y));
if (axis == 0) {
vh.AddVert(new Vector3(corner1.x, corner2.y), color, new Vector2(uv.x, uv.w));
vh.AddVert(new Vector3(corner1.x, corner1.y), color, new Vector2(uv.x, uv.y));
vh.AddVert(new Vector3(corner1.x + w3, corner2.y), color, new Vector2(uv.x + actualStartUVWidth, uv.w));
vh.AddVert(new Vector3(corner1.x + w4, corner1.y), color, new Vector2(uv.x + actualStartUVWidth, uv.y));
vh.AddVert(new Vector3(corner2.x - w5, corner2.y), color, new Vector2(uv.z - actualEndUVLength, uv.w));
vh.AddVert(new Vector3(corner2.x - w6, corner1.y), color, new Vector2(uv.z - actualEndUVLength, uv.y));
vh.AddVert(new Vector3(corner2.x, corner2.y), color, new Vector2(uv.z, uv.w));
vh.AddVert(new Vector3(corner2.x, corner1.y), color, new Vector2(uv.z, uv.y));
}
else {
vh.AddVert(new Vector3(corner1.y, corner1.x), color, new Vector2(uv.x, uv.w));
vh.AddVert(new Vector3(corner2.y, corner1.x), color, new Vector2(uv.z, uv.w));
vh.AddVert(new Vector3(corner1.y, corner1.x + w4), color, new Vector2(uv.x, uv.w - actualStartUVWidth));
vh.AddVert(new Vector3(corner2.y, corner1.x + w3), color, new Vector2(uv.z, uv.w - actualStartUVWidth));
vh.AddVert(new Vector3(corner1.y, corner2.x - w6), color, new Vector2(uv.x, uv.y + actualEndUVLength));
vh.AddVert(new Vector3(corner2.y, corner2.x - w5), color, new Vector2(uv.z, uv.y + actualEndUVLength));
vh.AddVert(new Vector3(corner1.y, corner2.x), color, new Vector2(uv.x, uv.y));
vh.AddVert(new Vector3(corner2.y, corner2.x), color, new Vector2(uv.z, uv.y));
}
if (((int)Compact & 0x1) == 0) {
vh.AddTriangle(2, 1, 0);

View File

@@ -0,0 +1,38 @@
using UnityEngine;
using UnityEngine.EventSystems;
namespace Cryville.Common.Unity.UI {
[ExecuteAlways]
[RequireComponent(typeof(RectTransform))]
public class SafeArea : UIBehaviour {
bool _delayedUpdate;
protected override void OnValidate() {
_delayedUpdate = true;
}
void Update() {
if (_delayedUpdate) {
_delayedUpdate = false;
UpdateRect();
}
}
protected override void OnRectTransformDimensionsChange() {
base.OnRectTransformDimensionsChange();
UpdateRect();
}
protected override void OnTransformParentChanged() {
base.OnTransformParentChanged();
UpdateRect();
}
void UpdateRect() {
var safeArea = Screen.safeArea;
var rectTransform = transform as RectTransform;
var canvas = GetComponentInParent<Canvas>(true).transform as RectTransform;
RectTransformUtility.ScreenPointToLocalPointInRectangle(canvas, new Vector2(safeArea.xMin, safeArea.yMin), Camera.main, out var pt1);
RectTransformUtility.ScreenPointToLocalPointInRectangle(canvas, new Vector2(safeArea.xMax, safeArea.yMax), Camera.main, out var pt2);
var result = Rect.MinMaxRect(pt1.x, pt1.y, pt2.x, pt2.y);
rectTransform.anchoredPosition = result.center;
rectTransform.sizeDelta = result.size;
rectTransform.anchorMin = rectTransform.anchorMax = rectTransform.pivot = new Vector2(0.5f, 0.5f);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 112824c0b55202c4f9c779de7574b5fd
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -134,9 +134,13 @@ namespace Cryville.Common.Unity.UI {
private void OnFrameUpdate() {
if (!initialized) return;
if (lines != null) for (int i = 0; i < lines.Length; i++)
if (lines[i] != null) foreach (GameObject c in lines[i])
GameObject.Destroy(c);
if (lines != null) {
for (int i = 0; i < lines.Length; i++) {
if (lines[i] != null) {
foreach (GameObject c in lines[i]) Destroy(c);
}
}
}
lines = new GameObject[VisibleLines][];
refl = new int[VisibleLines];
for (int i = 0; i < refl.Length; i++) refl[i] = i;
@@ -153,8 +157,9 @@ namespace Cryville.Common.Unity.UI {
private void ResetLines() {
for (int i = 0; i < lines.Length; i++) {
if (lines[i] != null) foreach (GameObject c in lines[i])
GameObject.Destroy(c);
if (lines[i] != null) {
foreach (GameObject c in lines[i]) Destroy(c);
}
lines[i] = new GameObject[LineItemCount];
GenerateLine(i, refl[i]);
}
@@ -200,7 +205,7 @@ namespace Cryville.Common.Unity.UI {
void GenerateLine(int index, int line) {
for (int j = 0; j < LineItemCount; j++) {
var child = GameObject.Instantiate(m_itemTemplate, transform, false);
var child = Instantiate(m_itemTemplate, transform, false);
lines[index][j] = child;
}
LoadLine(index, line);

View File

@@ -0,0 +1,94 @@
using UnityEngine;
using UnityEngine.UI;
namespace Cryville.Common.Unity.UI {
[AddComponentMenu("Layout/Single Layout Group")]
[ExecuteAlways]
public class SingleLayoutGroup : LayoutGroup {
[SerializeField]
protected bool m_ChildForceExpandWidth = true;
[SerializeField]
protected bool m_ChildForceExpandHeight = true;
[SerializeField]
protected bool m_ChildControlWidth = true;
[SerializeField]
protected bool m_ChildControlHeight = true;
[SerializeField]
protected bool m_ChildScaleWidth;
[SerializeField]
protected bool m_ChildScaleHeight;
public override void CalculateLayoutInputHorizontal() {
base.CalculateLayoutInputHorizontal();
CalcAlongAxis(0);
}
public override void CalculateLayoutInputVertical() { CalcAlongAxis(1); }
public override void SetLayoutHorizontal() { SetChildrenAlongAxis(0); }
public override void SetLayoutVertical() { SetChildrenAlongAxis(1); }
protected void CalcAlongAxis(int axis) {
float combinedPadding = (axis == 0) ? padding.horizontal : padding.vertical;
bool controlSize = (axis == 0) ? m_ChildControlWidth : m_ChildControlHeight;
bool useScale = (axis == 0) ? m_ChildScaleWidth : m_ChildScaleHeight;
bool childForceExpandSize = (axis == 0) ? m_ChildForceExpandWidth : m_ChildForceExpandHeight;
float totalMin = combinedPadding;
float totalPreferred = combinedPadding;
float totalFlexible = 0f;
RectTransform child = rectChildren[0];
GetChildSizes(child, axis, controlSize, childForceExpandSize, out var min, out var preferred, out var flexible);
if (useScale) {
float scaleFactor = child.localScale[axis];
min *= scaleFactor;
preferred *= scaleFactor;
flexible *= scaleFactor;
}
totalMin = Mathf.Max(min + combinedPadding, totalMin);
totalPreferred = Mathf.Max(preferred + combinedPadding, totalPreferred);
totalFlexible = Mathf.Max(flexible, totalFlexible);
totalPreferred = Mathf.Max(totalMin, totalPreferred);
SetLayoutInputForAxis(totalMin, totalPreferred, totalFlexible, axis);
}
protected void SetChildrenAlongAxis(int axis) {
float size = rectTransform.rect.size[axis];
bool controlSize = (axis == 0) ? m_ChildControlWidth : m_ChildControlHeight;
bool useScale = (axis == 0) ? m_ChildScaleWidth : m_ChildScaleHeight;
bool childForceExpandSize = (axis == 0) ? m_ChildForceExpandWidth : m_ChildForceExpandHeight;
float alignmentOnAxis = GetAlignmentOnAxis(axis);
float innerSize = size - ((axis == 0) ? padding.horizontal : padding.vertical);
RectTransform child = rectChildren[0];
GetChildSizes(child, axis, controlSize, childForceExpandSize, out var min2, out var preferred2, out var flexible2);
float scaleFactor2 = useScale ? child.localScale[axis] : 1f;
float requiredSpace = Mathf.Clamp(innerSize, min2, (flexible2 > 0f) ? size : preferred2);
float startOffset = GetStartOffset(axis, requiredSpace * scaleFactor2);
if (controlSize) {
SetChildAlongAxisWithScale(child, axis, startOffset, requiredSpace, scaleFactor2);
}
else {
float offsetInCell2 = (requiredSpace - child.sizeDelta[axis]) * alignmentOnAxis;
SetChildAlongAxisWithScale(child, axis, startOffset + offsetInCell2, scaleFactor2);
}
}
void GetChildSizes(RectTransform child, int axis, bool controlSize, bool childForceExpand, out float min, out float preferred, out float flexible) {
if (!controlSize) {
min = child.sizeDelta[axis];
preferred = min;
flexible = 0f;
}
else {
min = LayoutUtility.GetMinSize(child, axis);
preferred = LayoutUtility.GetPreferredSize(child, axis);
flexible = LayoutUtility.GetFlexibleSize(child, axis);
}
if (childForceExpand) {
flexible = Mathf.Max(flexible, 1f);
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5d03df0bb58478e42935bbdf633a4aa4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,11 +1,14 @@
using Cryville.Common.Font;
using Cryville.Culture;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Reflection;
using TMPro;
using UnityEngine;
using UnityEngine.TextCore.LowLevel;
using UnityEngine.TextCore.Text;
using Logger = Cryville.Common.Logging.Logger;
namespace Cryville.Common.Unity.UI {
[RequireComponent(typeof(TextMeshProUGUI))]
@@ -22,19 +25,21 @@ namespace Cryville.Common.Unity.UI {
if (FontMatcher == null) return;
_text = GetComponent<TextMeshProUGUI>();
if (_font == null) {
foreach (var typeface in FontMatcher.MatchScript(null, true)) {
foreach (var typeface in FontMatcher.MatchLanguage(new LanguageId(CultureInfo.CurrentCulture.Name), true)) {
try {
var ifont = CreateFontAsset(typeface.File.FullName, typeface.IndexInFile);
if (m_shader) ifont.material.shader = m_shader;
else if (DefaultShader) ifont.material.shader = DefaultShader;
if (_font == null) {
_font = ifont;
Logger.Log("main", 1, "UI", "Using main font: {0}", typeface.FullName);
if (MaxFallbackCount <= 0) break;
}
else {
if (_font.fallbackFontAssetTable == null)
_font.fallbackFontAssetTable = new List<FontAsset>();
_font.fallbackFontAssetTable.Add(ifont);
Logger.Log("main", 1, "UI", "Using fallback font #{0}: {1}", _font.fallbackFontAssetTable.Count, typeface.FullName);
if (_font.fallbackFontAssetTable.Count >= MaxFallbackCount) break;
}
}

View File

@@ -0,0 +1,26 @@
namespace Cryville.Common.Unity {
public static class UrlOpener {
public static void Open(string url) {
#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
System.Diagnostics.Process.Start(url);
#elif UNITY_ANDROID
using (var clazz = new UnityEngine.AndroidJavaClass("world.cryville.common.unity.UrlOpener")) {
clazz.CallStatic("open", url);
}
#else
#error Unknown platform.
#endif
}
public static void OpenThreaded(string url) {
#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
Open(url);
#elif UNITY_ANDROID
UnityEngine.AndroidJNI.AttachCurrentThread();
Open(url);
UnityEngine.AndroidJNI.DetachCurrentThread();
#else
#error Unknown platform.
#endif
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c827ee181de8c51499777e5a822981b8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,17 @@
package world.cryville.common.unity;
import android.content.Intent;
import android.net.Uri;
import com.unity3d.player.UnityPlayer;
import com.unity3d.player.UnityPlayerActivity;
public final class UrlOpener {
private UrlOpener() { }
static UnityPlayerActivity activity;
public static void open(String url) {
if (activity == null) activity = (UnityPlayerActivity)UnityPlayer.currentActivity;
activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
}
}

View File

@@ -0,0 +1,32 @@
fileFormatVersion: 2
guid: e2d08ba79acb0564b9802b57dbc2f8d3
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Android: Android
second:
enabled: 1
settings: {}
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,4 +1,5 @@
using Cryville.Common.Collections.Specialized;
using Cryville.Crtr.Skin;
using UnityEngine;
namespace Cryville.Crtr {

View File

@@ -1,12 +0,0 @@
fileFormatVersion: 2
guid: cfa7de3f6f944914d9999fcfda245f97
timeCreated: 1637552994
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,53 +0,0 @@
using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace Cryville.Crtr.Browsing {
internal class BrowserItemTile : BrowserItem {
#pragma warning disable IDE0044
[SerializeField]
private Sprite m_iconPlaceholder;
#pragma warning restore IDE0044
private bool _dir;
private Image _icon;
private TMP_Text _title;
private TMP_Text _desc;
#pragma warning disable IDE0051
void Awake() {
_icon = transform.Find("__content__/Icon").GetComponent<Image>();
_title = transform.Find("__content__/Texts/Title/__text__").GetComponent<TMP_Text>();
_desc = transform.Find("__content__/Texts/Description/__text__").GetComponent<TMP_Text>();
}
void OnDestroy() {
if (meta.Icon != null) meta.Icon.Cancel();
if (_icon.sprite != null && _icon.sprite != m_iconPlaceholder) {
Texture2D.Destroy(_icon.sprite.texture);
Sprite.Destroy(_icon.sprite);
}
}
#pragma warning restore IDE0051
internal override void Load(int id, ResourceItemMeta item) {
OnDestroy();
base.Load(id, item);
_dir = meta.IsDirectory;
_icon.sprite = m_iconPlaceholder;
if (meta.Icon != null) meta.Icon.Destination = DisplayCover;
_title.text = meta.Name;
_desc.text = string.Format("{0}\n{1}", meta.DescriptionMain, meta.DescriptionSub);
}
private void DisplayCover(bool succeeded, Texture2D tex) {
if (succeeded) {
_icon.sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), Vector2.zero, 160, 0, SpriteMeshType.FullRect);
}
}
public void OnClick() {
if (Id == null) return;
ResourceBrowser resourceBrowser = GetComponentInParent<ResourceBrowser>();
if (_dir) resourceBrowser.OnDirectoryItemClicked(Id.Value);
else resourceBrowser.OnObjectItemClicked(Id.Value);
}
}
}

View File

@@ -1,12 +0,0 @@
fileFormatVersion: 2
guid: b38d66b3e6e5d94438c72f855c4efff9
timeCreated: 1637554149
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,10 @@
using Cryville.Common;
using Cryville.Crtr.Extension;
using UnityEngine;
namespace Cryville.Crtr.Browsing {
public struct ChartDetail {
public AsyncDelivery<Texture2D> Cover { get; set; }
public ChartMeta Meta { get; set; }
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5f9870328bccefa4d8d4f6d5e3cef591
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,67 +0,0 @@
using Cryville.Common;
using System;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace Cryville.Crtr.Browsing {
public class DetailPanel : ResourceBrowserUnit {
#pragma warning disable IDE0044
[SerializeField]
private Sprite m_coverPlaceholder;
#pragma warning restore IDE0044
int _id;
ChartDetail _data;
GameObject _placeholder;
GameObject _outerContent;
Transform _content;
Image _cover;
TMP_Text _title;
TMP_Text _desc;
protected override void Awake() {
base.Awake();
_placeholder = transform.Find("__placeholder__").gameObject;
_outerContent = transform.Find("__content__").gameObject;
_content = _outerContent.transform.Find("__content__");
_cover = _content.Find("Cover").GetComponent<Image>();
_title = _content.Find("Texts/Title").GetComponent<TMP_Text>();
_desc = _content.Find("Texts/Description").GetComponent<TMP_Text>();
}
void OnDestroy() {
if (_data.Cover != null) _data.Cover.Cancel();
if (_cover.sprite != null && _cover.sprite != m_coverPlaceholder) {
Texture2D.Destroy(_cover.sprite.texture);
Sprite.Destroy(_cover.sprite);
}
}
public void Load(int id, ChartDetail data) {
_id = id;
_placeholder.SetActive(false);
_outerContent.SetActive(true);
OnDestroy();
_data = data;
_cover.sprite = m_coverPlaceholder;
if (data.Cover != null) data.Cover.Destination = DisplayCover;
var meta = data.Meta;
_title.text = string.Format("{0}\n{1}", meta.song.name, meta.name);
_desc.text = string.Format(
"Music artist: {0}\nCharter: {1}\nLength: {2}\nNote Count: {3}",
meta.song.author, meta.author,
TimeSpan.FromSeconds(meta.length).ToString(3), meta.note_count
);
}
private void DisplayCover(bool succeeded, Texture2D tex) {
if (succeeded) {
_cover.sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), Vector2.zero, 160, 0, SpriteMeshType.FullRect);
}
}
public void OnPlay() {
Master.Open(_id, _data);
}
public void OnConfig() {
Master.OpenConfig(_id, _data);
}
}
}

View File

@@ -1,12 +0,0 @@
fileFormatVersion: 2
guid: 477e04b1ed5b60e48886fb76081245c5
timeCreated: 1637722157
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,11 +1,10 @@
using System;
using System.Collections.Generic;
namespace Cryville.Crtr.Browsing {
public interface IResourceManager<T> {
string[] CurrentDirectory { get; }
int ChangeDirectory(string[] dir);
int OpenDirectory(int id);
int ReturnToDirectory(int id);
int ItemCount { get; }
ResourceItemMeta GetItemMeta(int id);
T GetItemDetail(int id);
string GetItemPath(int id);
@@ -13,5 +12,13 @@ namespace Cryville.Crtr.Browsing {
bool ImportItemFrom(string path);
string[] GetSupportedFormats();
IReadOnlyDictionary<string, string> GetPresetPaths();
event Action ItemChanged;
}
public interface IPathedResourceManager<T> : IResourceManager<T> {
string[] CurrentDirectory { get; }
void ChangeDirectory(string[] dir);
void OpenDirectory(int id);
void ReturnToDirectory(int id);
}
}

View File

@@ -3,6 +3,7 @@ using Cryville.Common.Unity;
using Cryville.Crtr.Extension;
using Cryville.Crtr.Extensions;
using Cryville.Crtr.Extensions.Umg;
using Cryville.Crtr.UI;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
@@ -12,14 +13,17 @@ using UnityEngine;
using Logger = Cryville.Common.Logging.Logger;
namespace Cryville.Crtr.Browsing {
internal class LegacyResourceManager : IResourceManager<ChartDetail> {
internal class LegacyResourceManager : IPathedResourceManager<ChartDetail> {
private readonly string _rootPath;
private DirectoryInfo cd;
private DirectoryInfo[] items = new DirectoryInfo[0];
public string[] CurrentDirectory { get; private set; }
public int ItemCount { get { return items.Length; } }
static bool _init;
public event Action ItemChanged;
public LegacyResourceManager(string rootPath) {
_rootPath = rootPath;
if (!_init) {
@@ -28,24 +32,24 @@ namespace Cryville.Crtr.Browsing {
}
}
public int ChangeDirectory(string[] dir) {
public void ChangeDirectory(string[] dir) {
CurrentDirectory = dir;
cd = new DirectoryInfo(_rootPath + "/charts/" + string.Join("/", dir));
items = cd.GetDirectories();
return items.Length;
ItemChanged?.Invoke();
}
public int OpenDirectory(int id) {
public void OpenDirectory(int id) {
string[] nd = new string[CurrentDirectory.Length + 1];
Array.Copy(CurrentDirectory, nd, CurrentDirectory.Length);
nd[CurrentDirectory.Length] = items[id].Name;
return ChangeDirectory(nd);
ChangeDirectory(nd);
}
public int ReturnToDirectory(int id) {
public void ReturnToDirectory(int id) {
string[] nd = new string[id + 1];
Array.Copy(CurrentDirectory, nd, id + 1);
return ChangeDirectory(nd);
ChangeDirectory(nd);
}
public ResourceItemMeta GetItemMeta(int id) {
@@ -66,7 +70,7 @@ namespace Cryville.Crtr.Browsing {
var coverFile = item.GetFiles(meta.cover);
if (coverFile.Length > 0) {
cover = new AsyncDelivery<Texture2D>();
var task = new LoadTextureTask(Game.FileProtocolPrefix + coverFile[0].FullName, cover.Deliver);
var task = new LoadTextureTask(PlatformConfig.FileProtocolPrefix + coverFile[0].FullName, cover.Deliver);
cover.CancelSource = task.Cancel;
Game.NetworkTaskWorker.SubmitNetworkTask(task);
}
@@ -93,7 +97,7 @@ namespace Cryville.Crtr.Browsing {
var coverFile = item.GetFiles(meta.cover);
if (coverFile.Length > 0) {
cover = new AsyncDelivery<Texture2D>();
var task = new LoadTextureTask(Game.FileProtocolPrefix + coverFile[0].FullName, cover.Deliver);
var task = new LoadTextureTask(PlatformConfig.FileProtocolPrefix + coverFile[0].FullName, cover.Deliver);
cover.CancelSource = task.Cancel;
Game.NetworkTaskWorker.SubmitNetworkTask(task);
}

View File

@@ -1,150 +0,0 @@
using System;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
namespace Cryville.Crtr.Browsing {
public class PVPNumber : PropertyValuePanel {
double m_value;
public override object Value {
get {
float s_value = GetDisplayValue();
return IntegerMode ? (int)s_value : (object)s_value;
}
set {
if (value is double) m_value = (double)value;
else m_value = IntegerMode ? (int)value : (double)(float)value;
float s_value = GetDisplayValue();
m_text.text = s_value.ToString();
if (Range != null && MaxStep == 0) {
SetRatio((float)(m_value - Range.Value.x) / (Range.Value.y - Range.Value.x));
}
}
}
float GetDisplayValue() {
double s_value = m_value;
if (Precision > 0)
s_value = Math.Round(s_value / Precision) * Precision;
if (IntegerMode)
s_value = Math.Round(s_value);
return (float)s_value;
}
public bool IntegerMode { get; set; }
public bool LogarithmicMode { get; set; }
public float MaxStep { get; set; }
public double Precision { get; set; }
public Vector2? Range { get; set; }
[SerializeField]
EventTrigger m_ctn;
[SerializeField]
RectTransform m_handleArea;
[SerializeField]
RectTransform m_handle;
[SerializeField]
Text m_text;
#pragma warning disable IDE0051
void Start() {
var ev = new EventTrigger.Entry { eventID = EventTriggerType.InitializePotentialDrag };
ev.callback.AddListener(e => OnInitializePotentialDrag((PointerEventData)e));
m_ctn.triggers.Add(ev);
ev = new EventTrigger.Entry { eventID = EventTriggerType.Drag };
ev.callback.AddListener(e => OnDrag((PointerEventData)e));
m_ctn.triggers.Add(ev);
ev = new EventTrigger.Entry { eventID = EventTriggerType.EndDrag };
ev.callback.AddListener(e => OnEndDrag((PointerEventData)e));
m_ctn.triggers.Add(ev);
ev = new EventTrigger.Entry { eventID = EventTriggerType.PointerClick };
ev.callback.AddListener(e => OnPointerClick((PointerEventData)e));
m_ctn.triggers.Add(ev);
if (MaxStep != 0) SetRatio(0.5f);
}
void Update() {
if (use && MaxStep != 0) {
SetRatio(GetRatioFromPos(pp));
SetValueFromPos(pp);
}
}
void OnRectTransformDimensionsChange() {
m_handleArea.sizeDelta = new Vector2(m_handle.rect.height - m_handle.rect.width, 0);
}
#pragma warning restore IDE0051
Vector2 pp;
bool use, nouse;
public void OnInitializePotentialDrag(PointerEventData eventData) {
eventData.useDragThreshold = false;
pp = eventData.position;
}
public void OnDrag(PointerEventData eventData) {
if (nouse) return;
if (!use) {
var delta = eventData.position - pp;
float dx = Mathf.Abs(delta.x), dy = Mathf.Abs(delta.y);
if (dx > dy) use = true;
else if (dx < dy) nouse = true;
}
if (use) {
pp = eventData.position;
if (MaxStep == 0) SetValueFromPos(eventData.position);
eventData.Use();
}
}
public void OnEndDrag(PointerEventData eventData) {
if (!nouse) {
SetValueFromPos(eventData.position);
Callback(Value);
if (MaxStep != 0) SetRatio(0.5f);
eventData.Use();
use = false;
}
nouse = false;
}
public void OnPointerClick(PointerEventData eventData) {
SetValueFromPos(eventData.position);
Callback(Value);
eventData.Use();
}
float GetRatioFromPos(Vector2 pos) {
Vector2 lp;
if (RectTransformUtility.ScreenPointToLocalPointInRectangle(m_handleArea, pos, null, out lp)) {
lp -= m_handleArea.rect.position;
return Mathf.Clamp01(lp.x / m_handleArea.rect.width);
}
return float.NegativeInfinity;
}
void SetValueFromPos(Vector2 pos) {
double ratio = GetRatioFromPos(pos);
double result;
if (MaxStep == 0) {
if (LogarithmicMode) throw new NotImplementedException();
else result = (1 - ratio) * Range.Value.x + ratio * Range.Value.y;
}
else {
double delta = (ratio > 0.5 ? 1 : -1) * Math.Pow((ratio - 0.5f) * 2, 2) * MaxStep * Time.deltaTime;
if (LogarithmicMode) result = Math.Pow(Math.E, Math.Log(m_value) + delta);
else result = m_value + delta;
}
if (Range != null) {
if (result < Range.Value.x) result = Range.Value.x;
else if (result > Range.Value.y) result = Range.Value.y;
}
Value = result;
}
void SetRatio(float ratio) {
m_handle.anchorMin = new Vector2(ratio, m_handle.anchorMin.y);
m_handle.anchorMax = new Vector2(ratio, m_handle.anchorMax.y);
}
}
}

View File

@@ -1,12 +0,0 @@
fileFormatVersion: 2
guid: 5d443a346e9a19d4eabbb0fa9ec7016f
timeCreated: 1637566071
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,51 +0,0 @@
using System.Collections.Generic;
using System.Reflection;
using UnityEngine;
using UnityEngine.UI;
namespace Cryville.Crtr.Browsing {
public class PropertyCategoryPanel : MonoBehaviour {
[SerializeField]
private GameObject m_propertyPrefab;
Text _nameLabel = null;
string _name;
public string Name {
get { return _name; }
set { _name = value; UpdateName(); }
}
bool _collapsed = false;
public bool Collapsed {
get { return _collapsed; }
set { _collapsed = value; UpdateName(); }
}
#pragma warning disable IDE0051
void Awake() {
_nameLabel = transform.Find("Name/__text__").GetComponent<Text>();
transform.Find("Name").GetComponent<Button>().onClick.AddListener(ToggleCollapsed);
}
#pragma warning restore IDE0051
public void Load(string name, IEnumerable<PropertyInfo> props, object target) {
Name = name.ToUpper();
foreach (var prop in props) {
var obj = GameObject.Instantiate<GameObject>(m_propertyPrefab, transform, false);
obj.GetComponent<PropertyPanel>().Load(prop, target);
}
}
void ToggleCollapsed() {
Collapsed = !Collapsed;
for (int i = 1; i < transform.childCount; i++) {
transform.GetChild(i).gameObject.SetActive(!Collapsed);
}
}
private void UpdateName() {
_nameLabel.text = (Collapsed ? "+ " : "- ") + Name;
}
}
}

View File

@@ -1,12 +0,0 @@
fileFormatVersion: 2
guid: 3a13b7ea14b96e54ea8a7e6ba1275281
timeCreated: 1638435211
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,76 +0,0 @@
using Cryville.Common.ComponentModel;
using System.Reflection;
using UnityEngine;
using UnityEngine.UI;
using RangeAttribute = Cryville.Common.ComponentModel.RangeAttribute;
namespace Cryville.Crtr.Browsing {
public class PropertyPanel : MonoBehaviour {
[SerializeField]
GameObject m_bool;
[SerializeField]
GameObject m_number;
[SerializeField]
GameObject m_string;
PropertyInfo _property;
object _target;
Text _key;
Transform _valueContainer;
PropertyValuePanel _value;
#pragma warning disable IDE0051
void Awake() {
_key = transform.Find("Key").GetComponent<Text>();
_valueContainer = transform.Find("Value");
}
#pragma warning restore IDE0051
public void Load(PropertyInfo prop, object target) {
_target = target;
_property = prop;
_key.text = prop.Name;
GameObject vp;
if (prop.PropertyType == typeof(bool)) vp = m_bool;
else if (prop.PropertyType == typeof(float) || prop.PropertyType == typeof(int)) vp = m_number;
else if (prop.PropertyType == typeof(string)) vp = m_string;
else return;
_value = GameObject.Instantiate(vp, _valueContainer, false).GetComponent<PropertyValuePanel>();
if (_value is PVPNumber) {
var t = (PVPNumber)_value;
t.IntegerMode = prop.PropertyType == typeof(int);
var attr = prop.GetCustomAttributes(typeof(RangeAttribute), true);
if (attr.Length > 0) {
var u = (RangeAttribute)attr[0];
t.Range = new Vector2(u.Min, u.Max);
}
attr = prop.GetCustomAttributes(typeof(PrecisionAttribute), true);
if (attr.Length > 0) {
var u = (PrecisionAttribute)attr[0];
t.Precision = u.Precision;
}
attr = prop.GetCustomAttributes(typeof(StepAttribute), true);
if (attr.Length > 0) {
var u = (StepAttribute)attr[0];
t.MaxStep = u.Step;
}
attr = prop.GetCustomAttributes(typeof(LogarithmicScaleAttribute), true);
if (attr.Length > 0) {
t.LogarithmicMode = true;
}
}
_value.Callback = SetValueToObject;
GetValueFromObject();
}
void GetValueFromObject() {
_value.Value = _property.GetValue(_target, null);
}
void SetValueToObject(object value) {
_property.SetValue(_target, value, null);
GetValueFromObject();
}
}
}

View File

@@ -1,12 +0,0 @@
fileFormatVersion: 2
guid: bcca29fea992ac24698a213f0e2baedc
timeCreated: 1638435590
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,9 +0,0 @@
using System;
using UnityEngine;
namespace Cryville.Crtr.Browsing {
public abstract class PropertyValuePanel : MonoBehaviour {
public Action<object> Callback { protected get; set; }
public abstract object Value { get; set; }
}
}

View File

@@ -1,77 +0,0 @@
using Cryville.Common.Unity;
using Cryville.Common.Unity.UI;
using System;
using UnityEngine;
using UnityEngine.UI;
namespace Cryville.Crtr.Browsing {
public class ResourceBrowser : ResourceBrowserUnit {
public IResourceManager<ChartDetail> ResourceManager;
public ScrollableItemGrid PathContainer;
public ScrollableItemGrid ItemContainer;
FileDialog _dialog;
protected void Start() {
PathContainer.LoadItem = LoadPathPart;
ItemContainer.LoadItem = LoadItem;
ItemContainer.ItemCount = ResourceManager.ChangeDirectory(new string[] { "" });
PathContainer.ItemCount = ResourceManager.CurrentDirectory.Length;
_dialog = GameObject.Instantiate(Resources.Load<GameObject>("Common/FileDialog")).GetComponent<FileDialog>();
_dialog.gameObject.SetActive(false);
_dialog.Filter = ResourceManager.GetSupportedFormats();
_dialog.PresetPaths = ResourceManager.GetPresetPaths();
_dialog.OnClose += OnAddDialogClosed;
}
private bool LoadPathPart(int id, GameObject obj) {
var item = ResourceManager.CurrentDirectory[id];
obj.GetComponent<PathPart>().Load(id, item);
return true;
}
private bool LoadItem(int id, GameObject obj) {
var bi = obj.GetComponent<BrowserItem>();
try {
var item = ResourceManager.GetItemMeta(id);
bi.Load(id, item);
}
catch (Exception) {
bi.Load(id, new ResourceItemMeta { Name = "<color=#ff0000>Invalid resource</color>" });
}
return true;
}
public void OnDirectoryItemClicked(int id) {
ItemContainer.ItemCount = ResourceManager.OpenDirectory(id);
PathContainer.ItemCount = ResourceManager.CurrentDirectory.Length;
if (PathContainer.ItemCount >= PathContainer.VisibleLines - 1)
PathContainer.GetComponentInParent<ScrollRect>().velocity = new Vector2(-Screen.width, 0);
}
public void OnObjectItemClicked(int id) {
Master.ShowDetail(id, ResourceManager.GetItemDetail(id));
}
public void OnPathClicked(int id) {
ItemContainer.ItemCount = ResourceManager.ReturnToDirectory(id);
PathContainer.ItemCount = ResourceManager.CurrentDirectory.Length;
}
public void OnAddButtonClicked() {
_dialog.Show();
}
private void OnAddDialogClosed() {
if (_dialog.FileName == null) return;
if (ResourceManager.ImportItemFrom(_dialog.FileName)) {
Popup.Create("Import succeeded");
OnPathClicked(ResourceManager.CurrentDirectory.Length - 1);
}
else {
Popup.Create("Import failed");
}
}
}
}

View File

@@ -1,12 +0,0 @@
fileFormatVersion: 2
guid: c6b4df13dea0e4a469d7e54e7e8fb428
timeCreated: 1637234060
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,97 +0,0 @@
using Cryville.Common;
using Cryville.Common.Unity.UI;
using Cryville.Crtr.Config;
using Cryville.Crtr.Extension;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
namespace Cryville.Crtr.Browsing {
public class ResourceBrowserMaster : MonoBehaviour {
[SerializeField]
private Button m_playButton;
[SerializeField]
private Button m_configButton;
[SerializeField]
private ConfigPanelMaster m_configPanel;
private DockLayoutGroup _group;
public ResourceBrowser MainBrowser { get; private set; }
private DetailPanel _detailPanel;
readonly List<ResourceBrowserUnit> _units = new List<ResourceBrowserUnit>();
#pragma warning disable IDE0051
void Awake() {
_group = GetComponent<DockLayoutGroup>();
MainBrowser = transform.GetChild(0).GetComponent<ResourceBrowser>();
MainBrowser.ResourceManager = new LegacyResourceManager(Settings.Default.GameDataPath);
_detailPanel = transform.GetChild(1).GetComponent<DetailPanel>();
_units.Add(MainBrowser);
_units.Add(_detailPanel);
}
int _slideDest = 0;
void Update() {
var cv = _group.SlideIndex;
_group.SlideIndex = (cv - _slideDest) * 0.86f + _slideDest;
}
#pragma warning restore IDE0051
public void ShowDetail(int id, ChartDetail detail) {
SlideIntoView(1);
_detailPanel.Load(id, detail);
m_playButton.gameObject.SetActive(true);
m_configButton.gameObject.SetActive(true);
}
/*[Obsolete]
public void ShowSettings(int id, ChartDetail detail) {
SlideIntoView(2);
_settingsPanel.Load(id, detail);
}*/
public bool Back() {
if (_slideDest == 0) return false;
SlideIntoView(_slideDest - 1);
return true;
}
private void SlideIntoView(int v) {
v = Mathf.Clamp(v, 0, _units.Count - 1);
var cv = _group.SlideIndex;
if (cv < v) _slideDest = v - 1;
else _slideDest = v;
_units[_slideDest].SlideToLeft();
_units[_slideDest + 1].SlideToRight();
}
public void Open(int id, ChartDetail detail) {
SetDataSettings(id, detail);
#if UNITY_5_3_OR_NEWER
SceneManager.LoadScene("Play", LoadSceneMode.Additive);
#else
Application.LoadLevelAdditive("Play");
#endif
GameObject.Find("/Master").GetComponent<Master>().HideMenu();
#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
DiscordController.Instance.SetPlaying(string.Format("{0} - {1}", detail.Meta.song.name, detail.Meta.name), detail.Meta.length);
#endif
}
public void OpenConfig(int id, ChartDetail detail) {
SetDataSettings(id, detail);
}
void SetDataSettings(int id, ChartDetail detail) {
Settings.Default.LoadRuleset = detail.Meta.ruleset + "/.umgr";
Settings.Default.LoadRulesetConfig = detail.Meta.ruleset + ".json";
Settings.Default.LoadChart = MainBrowser.ResourceManager.GetItemPath(id);
}
}
public struct ChartDetail {
public AsyncDelivery<Texture2D> Cover { get; set; }
public ChartMeta Meta { get; set; }
}
}

View File

@@ -1,12 +0,0 @@
fileFormatVersion: 2
guid: 256d7d3efda1f9b4c882eb42e608cc8e
timeCreated: 1638414803
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,12 +0,0 @@
fileFormatVersion: 2
guid: a69c80e5f3e7bd04485bc3afc5826584
timeCreated: 1638415083
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -2,15 +2,6 @@ using Cryville.Common;
using UnityEngine;
namespace Cryville.Crtr.Browsing {
internal abstract class BrowserItem : MonoBehaviour {
public int? Id { get; private set; }
protected ResourceItemMeta meta;
internal virtual void Load(int id, ResourceItemMeta item) {
Id = id;
meta = item;
}
}
public struct ResourceItemMeta {
public bool IsDirectory { get; set; }
public AsyncDelivery<Texture2D> Icon { get; set; }

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f535064222dd08c4f8e52d6e9144079a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ba8a8b6df16a9714f9785aba6adc0427
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,18 @@
using UnityEngine;
namespace Cryville.Crtr.Browsing.UI {
internal abstract class BrowserItem : MonoBehaviour {
public int? Id { get; private set; }
protected ResourceItemMeta meta;
internal void Load(int id, ResourceItemMeta item, bool selected) {
OnReset();
Id = id;
meta = item;
OnLoad(selected);
}
protected abstract void OnReset();
protected abstract void OnLoad(bool selected);
internal virtual void OnSelect() { }
internal virtual void OnDeselect() { }
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c3cee963751f1ee4c9792c8c8983f51d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,77 @@
using Cryville.Common.Unity;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
namespace Cryville.Crtr.Browsing.UI {
internal class BrowserItemTile : BrowserItem, IPointerClickHandler, IPointerEnterHandler, IPointerExitHandler {
#pragma warning disable IDE0044
[SerializeField]
Sprite m_iconPlaceholder;
#pragma warning restore IDE0044
bool _dir;
[SerializeField]
Image m_icon;
[SerializeField]
TMP_Text m_title;
[SerializeField]
TMP_Text m_desc;
StateTweener _tweener;
void Awake() {
_tweener = GetComponent<StateTweener>();
}
void OnDestroy() {
OnReset();
}
protected override void OnReset() {
if (meta.Icon != null) meta.Icon.Cancel();
if (m_icon.sprite != null && m_icon.sprite != m_iconPlaceholder) {
Destroy(m_icon.sprite.texture);
Destroy(m_icon.sprite);
}
_tweener.ClearState();
}
protected override void OnLoad(bool selected) {
_dir = meta.IsDirectory;
m_icon.sprite = m_iconPlaceholder;
if (meta.Icon != null) meta.Icon.Destination = DisplayCover;
m_title.text = meta.Name;
m_desc.text = string.Format("{0}\n{1}", meta.DescriptionMain, meta.DescriptionSub);
if (selected) _tweener.EnterState("Selected");
}
private void DisplayCover(bool succeeded, Texture2D tex) {
if (succeeded) {
m_icon.sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), Vector2.zero, 160, 0, SpriteMeshType.FullRect);
}
}
public void OnClick() {
if (Id == null) return;
var resourceBrowser = GetComponentInParent<PathedResourceBrowser>();
if (_dir) resourceBrowser.OnDirectoryItemClicked(Id.Value);
else resourceBrowser.OnObjectItemClicked(Id.Value);
}
public void OnPointerClick(PointerEventData eventData) {
OnClick();
}
public void OnPointerEnter(PointerEventData eventData) {
_tweener.EnterState("Hovered", 0.1f);
}
public void OnPointerExit(PointerEventData eventData) {
_tweener.ExitState("Hovered", 0.1f);
}
internal override void OnSelect() {
base.OnSelect();
_tweener.EnterState("Selected", 0.1f);
}
internal override void OnDeselect() {
base.OnDeselect();
_tweener.ExitState("Selected", 0.1f);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 18dcb7d928c649f46bda005527fb6a17
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,55 @@
using System;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
namespace Cryville.Crtr.Browsing.UI {
[RequireComponent(typeof(BrowserTabLayout))]
[RequireComponent(typeof(CanvasGroup))]
internal class BrowserTab : MonoBehaviour, IPointerClickHandler {
[SerializeField]
Image m_icon;
[SerializeField]
TextMeshProUGUI m_text;
[SerializeField]
float m_deselectedAlpha = 0.6f;
public event Action<BrowserTab> Clicked;
public Sprite Icon {
get { return m_icon.sprite; }
set { m_icon.sprite = value; }
}
public string Text {
get { return m_text.text; }
set { m_text.text = value; }
}
bool m_selected;
public bool Selected {
get { return m_selected; }
set {
if (m_selected == value) return;
m_selected = value;
UpdateSelected();
}
}
void UpdateSelected() {
_group.alpha = Selected ? 1 : m_deselectedAlpha;
_layout.Selected = Selected;
}
CanvasGroup _group;
BrowserTabLayout _layout;
void Awake() {
_group = GetComponent<CanvasGroup>();
_layout = GetComponent<BrowserTabLayout>();
UpdateSelected();
}
public void OnPointerClick(PointerEventData eventData) {
Clicked?.Invoke(this);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 62b498b3519eb364cb6683512b28400a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,104 @@
using Cryville.Common;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
namespace Cryville.Crtr.Browsing.UI {
[ExecuteAlways]
internal class BrowserTabLayout : UIBehaviour, ILayoutElement {
[SerializeField]
float m_minWidth = 150;
public float MinWidth {
get { return m_minWidth; }
set {
if (m_minWidth == value) return;
m_minWidth = value;
UpdateTweener();
}
}
float GetTargetLayoutMinWidth() {
var width = MinWidth;
if (Selected) {
var preferredWidth = LayoutUtility.GetPreferredWidth(transform as RectTransform);
if (preferredWidth > width) width = preferredWidth;
}
return width;
}
float m_layoutMinWidth = -1;
float ILayoutElement.minWidth { get { return m_layoutMinWidth; } }
void UpdateLayoutMinWidth(float value) {
if (m_layoutMinWidth == value) return;
m_layoutMinWidth = value;
SetDirty();
}
public float preferredWidth { get { return -1; } }
public float flexibleWidth { get { return -1; } }
public float minHeight { get { return -1; } }
public float preferredHeight { get { return -1; } }
public float flexibleHeight { get { return -1; } }
public int layoutPriority { get { return 1; } }
bool m_selected;
public bool Selected {
get { return m_selected; }
set {
if (m_selected == value) return;
m_selected = value;
UpdateTweener();
}
}
[SerializeField]
float m_tweenDuration = 0.2f;
PropertyTweener<float> _tweener;
void UpdateTweener() {
_tweener.Start(GetTargetLayoutMinWidth(), m_tweenDuration);
}
void Update() {
_tweener.Advance(Time.deltaTime);
}
public void CalculateLayoutInputHorizontal() { }
public void CalculateLayoutInputVertical() { }
protected override void OnEnable() {
base.OnEnable();
m_layoutMinWidth = GetTargetLayoutMinWidth();
if (_tweener == null)
_tweener = new PropertyTweener<float>(
() => m_layoutMinWidth,
v => UpdateLayoutMinWidth(v),
Tweeners.Float.With(EasingFunctions.OutQuad)
);
SetDirty();
}
protected override void OnBeforeTransformParentChanged() {
base.OnBeforeTransformParentChanged();
SetDirty();
}
protected override void OnTransformParentChanged() {
base.OnTransformParentChanged();
SetDirty();
}
protected override void OnDidApplyAnimationProperties() {
base.OnDidApplyAnimationProperties();
SetDirty();
}
protected override void OnValidate() {
base.OnValidate();
SetDirty();
}
protected override void OnDisable() {
SetDirty();
base.OnDisable();
}
void SetDirty() {
if (!IsActive()) return;
LayoutRebuilder.MarkLayoutForRebuild(transform as RectTransform);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5160f264c834b9c4dbe5875accab32a8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,65 @@
using Cryville.Common;
using System;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace Cryville.Crtr.Browsing.UI {
public class DetailPanel : MonoBehaviour {
[SerializeField]
Sprite m_coverPlaceholder;
[SerializeField]
GameObject m_placeholder;
[SerializeField]
GameObject m_content;
[SerializeField]
Image m_cover;
[SerializeField]
TMP_Text m_title;
[SerializeField]
TMP_Text m_desc;
ResourceBrowserMaster _master;
int _id;
ChartDetail _data;
void Awake() {
_master = GetComponentInParent<ResourceBrowserMaster>();
}
void OnDestroy() {
if (_data.Cover != null) _data.Cover.Cancel();
if (m_cover.sprite != null && m_cover.sprite != m_coverPlaceholder) {
Destroy(m_cover.sprite.texture);
Destroy(m_cover.sprite);
}
}
public void Load(int id, ChartDetail data) {
_id = id;
m_placeholder.SetActive(false);
m_content.SetActive(true);
OnDestroy();
_data = data;
m_cover.sprite = m_coverPlaceholder;
if (data.Cover != null) data.Cover.Destination = DisplayCover;
var meta = data.Meta;
m_title.text = string.Format("{0}\n{1}", meta.song.name, meta.name);
m_desc.text = string.Format(
"Music artist: {0}\nCharter: {1}\nLength: {2}\nNote Count: {3}",
meta.song.author, meta.author,
TimeSpan.FromSeconds(meta.length).ToString(3), meta.note_count
);
}
private void DisplayCover(bool succeeded, Texture2D tex) {
if (succeeded) {
m_cover.sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), Vector2.zero, 160, 0, SpriteMeshType.FullRect);
}
}
public void OnPlay() {
_master.Open(_id, _data);
}
public void OnConfig() {
_master.OpenConfig(_id, _data);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9bdcc04cb1961dd4e9483dbf6c6d6f8b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,7 +1,7 @@
using UnityEngine;
using UnityEngine.UI;
namespace Cryville.Crtr.Browsing {
namespace Cryville.Crtr.Browsing.UI {
internal class PathPart : MonoBehaviour {
private int _id;
private Text _exp;
@@ -21,7 +21,7 @@ namespace Cryville.Crtr.Browsing {
else return exp;
}
public void OnClick() {
GetComponentInParent<ResourceBrowser>().OnPathClicked(_id);
GetComponentInParent<PathedResourceBrowser>().OnPathClicked(_id);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 961fa71cc64cc2a4b88adfc5a1aad216
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,83 @@
using Cryville.Common.Unity;
using Cryville.Common.Unity.UI;
using Cryville.Crtr.UI;
using System;
using System.Collections.Generic;
using UnityEngine;
namespace Cryville.Crtr.Browsing.UI {
public class PathedResourceBrowser : ResourceBrowser {
public IPathedResourceManager<ChartDetail> ResourceManager;
public ScrollableItemGrid ItemContainer;
readonly HashSet<int> _selectedItems = new HashSet<int>();
readonly Dictionary<int, BrowserItem> _items = new Dictionary<int, BrowserItem>();
FileDialog _dialog;
protected virtual void Start() {
ItemContainer.LoadItem = LoadItem;
ResourceManager.ItemChanged += OnItemChanged;
ResourceManager.ChangeDirectory(new string[] { "" });
InitDialog();
}
protected void InitDialog() {
_dialog = Instantiate(Resources.Load<GameObject>("Common/FileDialog")).GetComponent<FileDialog>();
_dialog.gameObject.SetActive(false);
_dialog.Filter = ResourceManager.GetSupportedFormats();
_dialog.PresetPaths = ResourceManager.GetPresetPaths();
_dialog.OnClose += OnAddDialogClosed;
}
void OnItemChanged() {
ItemContainer.ItemCount = ResourceManager.ItemCount;
_selectedItems.Clear();
_items.Clear();
}
private bool LoadItem(int id, GameObject obj) {
var bi = obj.GetComponent<BrowserItem>();
_items[id] = bi;
try {
var item = ResourceManager.GetItemMeta(id);
bi.Load(id, item, _selectedItems.Contains(id));
}
catch (Exception) {
bi.Load(id, new ResourceItemMeta { Name = "<color=#ff0000>Invalid resource</color>" }, _selectedItems.Contains(id));
}
return true;
}
public virtual void OnDirectoryItemClicked(int id) {
ResourceManager.OpenDirectory(id);
}
public void OnObjectItemClicked(int id) {
foreach (var item in _selectedItems) _items[item].OnDeselect();
_selectedItems.Clear();
_items[id].OnSelect();
_selectedItems.Add(id);
Master.ShowDetail(id, ResourceManager.GetItemDetail(id));
}
public void OnPathClicked(int id) {
ResourceManager.ReturnToDirectory(id);
}
public void OnAddButtonClicked() {
_dialog.Show();
}
private void OnAddDialogClosed() {
if (_dialog.FileName == null) return;
if (ResourceManager.ImportItemFrom(_dialog.FileName)) {
Popup.Create("Import succeeded");
OnPathClicked(ResourceManager.CurrentDirectory.Length - 1);
}
else {
Popup.Create("Import failed");
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f3c17bb298cf2294dad4b675c7290b2a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,12 +1,14 @@
using UnityEngine;
namespace Cryville.Crtr.Browsing {
public abstract class ResourceBrowserUnit : MonoBehaviour {
namespace Cryville.Crtr.Browsing.UI {
public abstract class ResourceBrowser : MonoBehaviour {
[SerializeField]
Sprite m_icon;
public Sprite Icon { get { return m_icon; } }
protected ResourceBrowserMaster Master { get; private set; }
protected virtual void Awake() {
Master = GetComponentInParent<ResourceBrowserMaster>();
}
public virtual void SlideToLeft() { }
public virtual void SlideToRight() { }
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8d8141a90dc49f741b382e7abbf0a9c8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,95 @@
using Cryville.Crtr.Config.UI;
using Cryville.Crtr.UI;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
namespace Cryville.Crtr.Browsing.UI {
public class ResourceBrowserMaster : MonoBehaviour {
[SerializeField]
Button m_playButton;
[SerializeField]
Button m_configButton;
[SerializeField]
ConfigPanelMaster m_configPanel;
[SerializeField]
Transform m_tabContainer;
[SerializeField]
GameObject m_tabPrefab;
[SerializeField]
PathedResourceBrowser m_mainBrowser;
[SerializeField]
SettingsBrowser m_settingsBrowser;
[SerializeField]
DetailPanel m_detailPanel;
BrowserTab _currentTab;
readonly Dictionary<BrowserTab, ResourceBrowser> _tabs = new Dictionary<BrowserTab, ResourceBrowser>();
void Awake() {
m_mainBrowser.ResourceManager = new LegacyResourceManager(Settings.Default.GameDataPath);
OnTabClicked(AddTab("Local", m_mainBrowser));
AddTab("Settings", m_settingsBrowser);
}
BrowserTab AddTab(string name, ResourceBrowser browser) {
var tab = Instantiate(m_tabPrefab, m_tabContainer, false).GetComponent<BrowserTab>();
tab.Icon = browser.Icon;
tab.Text = name;
tab.Clicked += OnTabClicked;
_tabs.Add(tab, browser);
return tab;
}
void OnTabClicked(BrowserTab tab) {
if (tab == _currentTab) return;
if (_currentTab != null) {
_currentTab.Selected = false;
_tabs[_currentTab].gameObject.SetActive(false);
}
_currentTab = tab;
if (_currentTab != null) {
_currentTab.Selected = true;
_tabs[_currentTab].gameObject.SetActive(true);
}
}
public void ShowDetail(int id, ChartDetail detail) {
// SlideIntoView(1);
m_detailPanel.Load(id, detail);
m_playButton.gameObject.SetActive(true);
m_configButton.gameObject.SetActive(true);
}
public bool Back() {
// if (_slideDest == 0) return false;
// SlideIntoView(_slideDest - 1);
return true;
}
public void Open(int id, ChartDetail detail) {
SetDataSettings(id, detail);
#if UNITY_5_3_OR_NEWER
SceneManager.LoadScene("Play", LoadSceneMode.Additive);
#else
Application.LoadLevelAdditive("Play");
#endif
GameObject.Find("/Master").GetComponent<Master>().HideMenu();
#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
DiscordController.Instance.SetPlaying(string.Format("{0} - {1}", detail.Meta.song.name, detail.Meta.name), detail.Meta.length);
#endif
}
public void OpenConfig(int id, ChartDetail detail) {
SetDataSettings(id, detail);
}
void SetDataSettings(int id, ChartDetail detail) {
Settings.Default.LoadRuleset = detail.Meta.ruleset + "/.umgr";
Settings.Default.LoadRulesetConfig = detail.Meta.ruleset + ".json";
Settings.Default.LoadChart = m_mainBrowser.ResourceManager.GetItemPath(id);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1c6c8bc301408004a904079721302722
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,11 @@
using Cryville.Crtr.Config;
using Cryville.Crtr.Config.UI;
namespace Cryville.Crtr.Browsing.UI {
internal class SettingsBrowser : ResourceBrowser {
protected override void Awake() {
base.Awake();
GetComponent<PropertyMasterPanel>().Adapter = new DefaultPropertyMasterAdapter(Settings.Default);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8523c789afb6adb48ac62a48f7decf0f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,10 +1,10 @@
using Cryville.Crtr.Components;
using Cryville.Crtr.Skin.Components;
using System;
using System.Collections.Generic;
using UnityEngine;
namespace Cryville.Crtr {
public static class GenericResources {
public static class BuiltinResources {
public static Dictionary<string, Type> Components
= new Dictionary<string, Type>();
public static Dictionary<string, Shader> Shaders

View File

@@ -1,6 +1,7 @@
using Cryville.Common;
using Cryville.Common.Collections.Specialized;
using Cryville.Common.Pdt;
using Cryville.Crtr.Ruleset;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
@@ -215,11 +216,11 @@ namespace Cryville.Crtr {
default: return base.GetEventsOfType(type);
}
}
public override int Priority { get { return 10; } }
public override int Priority { get { return 12; } }
}
public class Track : EventContainer {
public override int Priority { get { return 10; } }
public override int Priority { get { return 14; } }
}
public class Motion : ChartEvent {

View File

@@ -66,7 +66,7 @@ namespace Cryville.Crtr {
if (comps[i] == "") comps[i] = "0";
}
_itor.SetSource(string.Format("({0});", string.Join(',', comps)));
ChartPlayer.etor.Evaluate(_vecop, _itor.GetExp());
PdtEvaluator.Instance.Evaluate(_vecop, _itor.GetExp());
return _vecbuf;
}
}
@@ -99,18 +99,18 @@ namespace Cryville.Crtr {
var exp = _itor.GetExp();
switch (c) {
case '@':
ChartPlayer.etor.Evaluate(_vecop, exp);
PdtEvaluator.Instance.Evaluate(_vecop, exp);
node.Time = new Vec1(_vecbuf);
break;
case '~':
ChartPlayer.etor.Evaluate(_vecop, exp);
PdtEvaluator.Instance.Evaluate(_vecop, exp);
node.EndTime = new Vec1(_vecbuf);
break;
case '^':
node.Transition = exp;
break;
case ':':
ChartPlayer.etor.Evaluate(_vecop, exp);
PdtEvaluator.Instance.Evaluate(_vecop, exp);
node.Value = Vector.Construct(ChartPlayer.motionRegistry[name].Type, _vecbuf);
break;
default:

View File

@@ -1,9 +1,10 @@
#define BUILD
using Cryville.Common;
using Cryville.Common.Buffers;
using Cryville.Crtr.Config;
using Cryville.Crtr.Event;
using Cryville.Crtr.Ruleset;
using Cryville.Crtr.Skin;
using Cryville.Crtr.UI;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
@@ -24,9 +25,9 @@ namespace Cryville.Crtr {
public class ChartPlayer : MonoBehaviour {
#region Fields
Chart chart;
Skin skin;
SkinDefinition skin;
public static PdtSkin pskin;
Ruleset ruleset;
RulesetDefinition ruleset;
PdtRuleset pruleset;
Dictionary<string, Texture2D> texs;
public static Dictionary<string, SpriteFrame> frames;
@@ -62,8 +63,6 @@ namespace Cryville.Crtr {
public static float sv = 16f;
public static Dictionary<Identifier, MotionRegistry> motionRegistry;
public static PdtEvaluator etor;
#endregion
#region MonoBehaviour
@@ -75,14 +74,13 @@ namespace Cryville.Crtr {
logs = logobj.GetComponent<TextMeshProUGUI>();
if (!initialized) {
Game.Init();
GenericResources.LoadDefault();
BuiltinResources.LoadDefault();
initialized = true;
}
OnSettingsUpdate();
status = GameObject.Find("Status").GetComponent<TextMeshProUGUI>();
#if BUILD
try {
Play();
}
@@ -91,7 +89,6 @@ namespace Cryville.Crtr {
Popup.CreateException(ex);
ReturnToMenu();
}
#endif
// Camera.main.RenderToCubemap();
}
@@ -186,9 +183,7 @@ namespace Cryville.Crtr {
Logger.Log("main", 4, "Load/MainThread", "Load failed");
loadThread = null;
Popup.CreateException(threadException);
#if BUILD
ReturnToMenu();
#endif
}
else if (texloaddone) {
if (texLoader == null) Stop();
@@ -273,12 +268,12 @@ namespace Cryville.Crtr {
"\nStates: c{0} / b{1}",
cbus.ActiveStateCount, bbus.ActiveStateCount
);
var aTime = Game.AudioClient.Position;
var aTime = Game.AudioClient.Position - atime0;
var iTime = inputProxy.GetTimestampAverage();
statusbuf.AppendFormat(
"\nSTime: {0:G9}s {5} {6}\nATime: {1:G9}s ({3:+0.0ms;-0.0ms;0}) {5} {6}\nITime: {2:G9}s ({4:+0.0ms;-0.0ms;0}) {5} {7}",
cbus.Time, aTime, iTime,
(aTime - atime0 - cbus.Time) * 1e3,
(aTime - cbus.Time) * 1e3,
(iTime - cbus.Time) * 1e3,
forceSyncFrames != 0 ? "(force sync)" : "",
paused ? "(paused)" : "",
@@ -355,19 +350,25 @@ namespace Cryville.Crtr {
forceSyncFrames = Settings.Default.ForceSyncFrames;
Game.AudioClient.Start();
inputProxy.UnlockTime();
#if !UNITY_ANDROID || UNITY_EDITOR
DiscordController.Instance.SetResume(cbus.Time);
#endif
}
else {
Game.AudioClient.Pause();
inputProxy.LockTime();
#if !UNITY_ANDROID || UNITY_EDITOR
DiscordController.Instance.SetPaused();
#endif
}
}
#endregion
#endregion
#region Load
void Play() {
disableGC = Settings.Default.DisableGC;
clippingDist = Settings.Default.BackwardClippingDistance;
renderDist = Settings.Default.RenderDistance;
clippingDist = Settings.Default.BackwardRenderDistance;
renderDist = Settings.Default.ForwardRenderDistance;
renderStep = Settings.Default.RenderStep;
actualRenderStep = renderStep;
autoRenderStep = renderStep == 0;
@@ -377,7 +378,7 @@ namespace Cryville.Crtr {
areaJudgePrecision = 1 << Settings.Default.AreaJudgePrecision;
forceSyncFrames = Settings.Default.ForceSyncFrames;
texloaddone = false;
Game.NetworkTaskWorker.SuspendBackgroundTasks();
Game.SuspendBackgroundTasks();
Game.AudioSession = Game.AudioSequencer.NewSession();
var hitPlane = new Plane(Vector3.forward, Vector3.zero);
@@ -419,10 +420,10 @@ namespace Cryville.Crtr {
);
if (!skinFile.Exists) throw new FileNotFoundException("Skin not found\nPlease specify an available skin in the config");
using (StreamReader reader = new StreamReader(skinFile.FullName, Encoding.UTF8)) {
skin = JsonConvert.DeserializeObject<Skin>(reader.ReadToEnd(), new JsonSerializerSettings() {
skin = JsonConvert.DeserializeObject<SkinDefinition>(reader.ReadToEnd(), new JsonSerializerSettings() {
MissingMemberHandling = MissingMemberHandling.Error
});
if (skin.format != Skin.CURRENT_FORMAT) throw new FormatException("Invalid skin file version");
if (skin.format != SkinDefinition.CURRENT_FORMAT) throw new FormatException("Invalid skin file version");
}
loadThread = new Thread(new ParameterizedThreadStart(Load));
@@ -455,7 +456,7 @@ namespace Cryville.Crtr {
for (int i = 0; i < queue.Count; i++) {
#if UNITY_5_4_OR_NEWER
texHandler = new DownloadHandlerTexture();
texLoader = new UnityWebRequest(Game.FileProtocolPrefix + queue[i], "GET", texHandler, null);
texLoader = new UnityWebRequest(PlatformConfig.FileProtocolPrefix + queue[i], "GET", texHandler, null);
texLoader.SendWebRequest();
#else
texLoader = new WWW(Game.FileProtocolPrefix + queue[i]);
@@ -499,22 +500,22 @@ namespace Cryville.Crtr {
IEnumerator<float> Prehandle() {
Stopwatch timer = new Stopwatch();
timer.Reset(); timer.Start();
Logger.Log("main", 0, "Load/Prehandle", "Prehandling (iteration 2)"); yield return .00f;
Logger.Log("main", 0, "Load/Prehandle", "Prehandling (iteration 2)"); yield return 0;
cbus.BroadcastPreInit();
Logger.Log("main", 0, "Load/Prehandle", "Prehandling (iteration 3)"); yield return .05f;
Logger.Log("main", 0, "Load/Prehandle", "Prehandling (iteration 3)"); yield return 0;
using (var pbus = cbus.Clone(17)) {
while (pbus.Time != double.PositiveInfinity) {
pbus.ForwardOnce();
yield return (float)pbus.EventId / pbus.EventCount * .80f + .05f;
yield return (float)pbus.EventId / pbus.EventCount;
}
}
Logger.Log("main", 0, "Load/Prehandle", "Prehandling (iteration 4)"); yield return .85f;
Logger.Log("main", 0, "Load/Prehandle", "Prehandling (iteration 4)"); yield return 1;
cbus.BroadcastPostInit();
Logger.Log("main", 0, "Load/Prehandle", "Seeking to start offset"); yield return .90f;
Logger.Log("main", 0, "Load/Prehandle", "Seeking to start offset"); yield return 1;
cbus.ForwardByTime(startOffset);
bbus.ForwardByTime(startOffset);
Game.AudioSequencer.SeekTime(startOffset, SeekOrigin.Current);
Logger.Log("main", 0, "Load/Prehandle", "Cleaning up"); yield return .95f;
Logger.Log("main", 0, "Load/Prehandle", "Cleaning up"); yield return 1;
if (logEnabled && Settings.Default.HideLogOnPlay) ToggleLogs();
Camera.main.cullingMask |= 1;
GC.Collect();
@@ -528,7 +529,7 @@ namespace Cryville.Crtr {
logs.text = "";
}
Game.AudioSequencer.Playing = true;
atime0 = Game.AudioClient.Position - startOffset;
atime0 = Game.AudioClient.BufferPosition - startOffset;
inputProxy.SyncTime(cbus.Time);
inputProxy.Activate();
}
@@ -552,7 +553,7 @@ namespace Cryville.Crtr {
effectManager.Dispose();
effectManager = null;
}
etor = null;
PdtEvaluator.Instance.Reset();
motionRegistry = null;
Logger.Log("main", 1, "Game", "Stopped");
}
@@ -568,10 +569,8 @@ namespace Cryville.Crtr {
started = false;
}
}
Game.NetworkTaskWorker.ResumeBackgroundTasks();
#if BUILD
Game.ResumeBackgroundTasks();
ReturnToMenu();
#endif
}
void OnSettingsUpdate() {
@@ -588,11 +587,9 @@ namespace Cryville.Crtr {
}
Exception threadException;
#if !NO_THREAD
Thread loadThread = null;
volatile float loadPregress;
Stopwatch workerTimer;
#endif
void Load(object _info) {
var info = (LoadInfo)_info;
try {
@@ -622,7 +619,7 @@ namespace Cryville.Crtr {
};
using (StreamReader reader = new StreamReader(info.chartFile.FullName, Encoding.UTF8)) {
etor = new PdtEvaluator();
PdtEvaluator.Instance.Reset();
LoadRuleset(info.rulesetFile); loadPregress = .05f;
@@ -642,7 +639,7 @@ namespace Cryville.Crtr {
Logger.Log("main", 0, "Load/WorkerThread", "Initializing judge and input"); loadPregress = .35f;
judge = new Judge(this, pruleset);
etor.ContextJudge = judge;
PdtEvaluator.Instance.ContextJudge = judge;
inputProxy = new InputProxy(pruleset, judge, screenSize);
inputProxy.LoadFrom(_rscfg.inputs);
@@ -688,14 +685,15 @@ namespace Cryville.Crtr {
DirectoryInfo dir = file.Directory;
Logger.Log("main", 0, "Load/WorkerThread", "Loading ruleset: {0}", file);
using (StreamReader reader = new StreamReader(file.FullName, Encoding.UTF8)) {
ruleset = JsonConvert.DeserializeObject<Ruleset>(reader.ReadToEnd(), new JsonSerializerSettings() {
ruleset = JsonConvert.DeserializeObject<RulesetDefinition>(reader.ReadToEnd(), new JsonSerializerSettings() {
MissingMemberHandling = MissingMemberHandling.Error
});
if (ruleset.format != Ruleset.CURRENT_FORMAT) throw new FormatException("Invalid ruleset file version");
if (ruleset.format != RulesetDefinition.CURRENT_FORMAT) throw new FormatException("Invalid ruleset file version");
ruleset.LoadPdt(dir);
pruleset = ruleset.Root;
pruleset.Optimize(etor);
pruleset.Optimize(PdtEvaluator.Instance);
}
PdtEvaluator.Instance.ContextRulesetConfig = new RulesetConfigStore(pruleset.configs, _rscfg.configs);
RMVPool.Shared = new RMVPool();
MotionCachePool.Shared = new MotionCachePool();
MotionNodePool.Shared = new MotionNodePool();
@@ -706,7 +704,7 @@ namespace Cryville.Crtr {
Logger.Log("main", 0, "Load/WorkerThread", "Loading skin: {0}", file);
skin.LoadPdt(dir);
pskin = skin.Root;
pskin.Optimize(etor);
pskin.Optimize(PdtEvaluator.Instance);
effectManager = new EffectManager(pskin);
}
#endregion

View File

@@ -0,0 +1,105 @@
using Cryville.Common.ComponentModel;
using System;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
namespace Cryville.Crtr.Config {
public interface IPropertyAdapter {
string Category { get; }
string Name { get; }
string Description { get; }
PropertyType Type { get; }
object[] Range { get; }
object GetValue();
void SetValue(object value);
event Action ValueChanged;
object MapValue(object value);
bool SetMapped { get; }
object MapValueInverse(object value);
}
public enum PropertyType {
Unknown,
Number,
NumberStepped,
Boolean,
String,
}
public class DefaultPropertyAdapter : IPropertyAdapter {
readonly object _target;
readonly PropertyInfo _prop;
public string Category { get; private set; }
public string Name { get; private set; }
public string Description { get; private set; }
public PropertyType Type { get; private set; }
public object[] Range { get; private set; }
public object GetValue() { return _prop.GetValue(_target, null); }
public void SetValue(object value) { _prop.SetValue(_target, value, null); }
public event Action ValueChanged { add { } remove { } }
readonly double _precision;
readonly double _step;
readonly bool _logarithmic;
public object MapValue(object value) {
if (Type == PropertyType.Number || Type == PropertyType.NumberStepped) {
var result = (double)value;
if (_step != 0) result *= _step;
if (_logarithmic) result = Math.Pow(Math.E, result);
if (_precision != 0) result = Math.Round(result / _precision) * _precision;
return Convert.ChangeType(result, _prop.PropertyType);
}
return value;
}
public bool SetMapped { get { return true; } }
public object MapValueInverse(object value) {
if (Type == PropertyType.Number || Type == PropertyType.NumberStepped) {
var result = Convert.ToDouble(value);
if (_logarithmic) result = Math.Log(result);
if (_step != 0) result /= _step;
return result;
}
return value;
}
public DefaultPropertyAdapter(object target, PropertyInfo prop) {
_target = target;
_prop = prop;
var attrs = prop.GetCustomAttributes(typeof(CategoryAttribute), true);
if (attrs.Length > 0) Category = ((CategoryAttribute)attrs.Single()).Category;
Name = prop.Name;
var attrs2 = prop.GetCustomAttributes(typeof(DescriptionAttribute), true);
if (attrs2.Length > 0) Description = ((DescriptionAttribute)attrs2.Single()).Description;
if (prop.PropertyType == typeof(bool)) Type = PropertyType.Boolean;
else if (prop.PropertyType == typeof(char)) throw new NotSupportedException();
else if (prop.PropertyType.IsPrimitive) {
Type = prop.GetCustomAttributes(typeof(StepAttribute), true).Length > 0
? PropertyType.NumberStepped
: PropertyType.Number;
var attr = prop.GetCustomAttributes(typeof(RangeAttribute), true);
if (attr.Length > 0) {
var u = (RangeAttribute)attr.Single();
Range = new object[] { u.Min, u.Max };
}
attr = prop.GetCustomAttributes(typeof(PrecisionAttribute), true);
if (attr.Length > 0) {
var u = (PrecisionAttribute)attr.Single();
_precision = u.Precision;
}
attr = prop.GetCustomAttributes(typeof(StepAttribute), true);
if (attr.Length > 0) {
var u = (StepAttribute)attr.Single();
_step = u.Step;
}
attr = prop.GetCustomAttributes(typeof(LogarithmicScaleAttribute), true);
if (attr.Length > 0) {
_logarithmic = true;
}
}
else if (prop.PropertyType == typeof(string)) Type = PropertyType.String;
else return;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9b3e9219783719544bcbceade34a1090
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
namespace Cryville.Crtr.Config {
public interface IPropertyMasterAdapter {
string DefaultCategory { get; }
IEnumerable<IPropertyAdapter> GetProperties();
}
public class DefaultPropertyMasterAdapter : IPropertyMasterAdapter {
readonly object _target;
public DefaultPropertyMasterAdapter(object target) {
if (target == null) throw new ArgumentNullException("target");
_target = target;
}
public string DefaultCategory { get { return "miscellaneous"; } }
public IEnumerable<IPropertyAdapter> GetProperties() {
return _target.GetType().GetProperties().Where(p => {
var attrs = p.GetCustomAttributes(typeof(BrowsableAttribute), true);
if (attrs.Length == 0) return true;
else return ((BrowsableAttribute)attrs.Single()).Browsable;
}).Select(p => new DefaultPropertyAdapter(_target, p));
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4e0b160d43716cf4d8ba20b5a7eafd13
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -14,13 +14,13 @@ namespace Cryville.Crtr.Config {
[Category("gameplay")]
[JsonProperty("sound_offset")]
[Step(0.04f)]
[Step(0.04)]
[Precision(1e-3)]
public float SoundOffset { get; set; }
[Category("deprecated")][Obsolete]
[JsonProperty("scroll_velocity")][DefaultValue(1)]
[LogarithmicScale][Step(0.5f)][Precision(1e-1)]
[LogarithmicScale][Step(0.5)][Precision(1e-1)]
public float ScrollVelocity { get; set; }
public Generic() {
@@ -29,6 +29,8 @@ namespace Cryville.Crtr.Config {
ScrollVelocity = 1;
}
}
public Dictionary<string, object> configs
= new Dictionary<string, object>();
public Dictionary<string, InputEntry> inputs
= new Dictionary<string, InputEntry>();
public class InputEntry {

View File

@@ -0,0 +1,100 @@
using Cryville.Common;
using Cryville.Common.Pdt;
using Cryville.Crtr.Ruleset;
using System;
using System.Collections.Generic;
namespace Cryville.Crtr.Config {
internal class RulesetConfigPropertyMasterAdapter : IPropertyMasterAdapter {
readonly List<RulesetConfigPropertyAdapter> _props = new List<RulesetConfigPropertyAdapter>();
readonly RulesetConfigStore _store;
public RulesetConfigPropertyMasterAdapter(Dictionary<Identifier, ConfigDefinition> defs, Dictionary<string, object> values) {
_store = new RulesetConfigStore(defs, values);
PdtEvaluator.Instance.ContextRulesetConfig = _store;
if (defs == null) return;
foreach (var def in defs) {
_props.Add(new RulesetConfigPropertyAdapter(def.Key, def.Value, this));
}
}
public string DefaultCategory { get { return "miscellaneous"; } }
public IEnumerable<IPropertyAdapter> GetProperties() { return _props; }
public object GetValue(string key) {
return _store[key];
}
public void SetValue(string key, object value) {
_store[key] = value;
foreach (var prop in _props) {
prop.OnValueChanged();
}
}
}
internal class RulesetConfigPropertyAdapter : IPropertyAdapter {
readonly RulesetConfigPropertyMasterAdapter _master;
readonly ConfigDefinition _def;
public RulesetConfigPropertyAdapter(Identifier key, ConfigDefinition def, RulesetConfigPropertyMasterAdapter master) {
_master = master;
_def = def;
Name = (string)key.Name;
switch (_def.type) {
case ConfigType.number: Type = PropertyType.Number; break;
case ConfigType.number_stepped: Type = PropertyType.NumberStepped; break;
default: Type = PropertyType.Unknown; break;
}
_rangeOp = new PropOp.Clip(v => {
m_range[0] = (double)v.Behind;
m_range[1] = (double)v.Ahead;
});
}
public string Category { get { return _def.category; } }
public string Name { get; private set; }
public string Description { get { return null; } }
public PropertyType Type { get; private set; }
readonly PdtOperator _rangeOp;
readonly object[] m_range = new object[] { double.NegativeInfinity, double.PositiveInfinity };
public object[] Range {
get {
if (_def.range != null)
PdtEvaluator.Instance.Evaluate(_rangeOp, _def.range);
return m_range;
}
}
public object GetValue() {
return _master.GetValue(Name);
}
public void SetValue(object value) {
_master.SetValue(Name, value);
}
public event Action ValueChanged;
public void OnValueChanged() {
var ev = ValueChanged;
if (ev != null) ev();
}
public bool SetMapped { get { return false; } }
readonly PropStores.Float _numst = new PropStores.Float();
public object MapValue(object value) {
_numst.Value = (float)(double)value;
if (_def.value == null) return _numst.Value;
PdtEvaluator.Instance.ContextSelfValue = _numst.Source;
PdtEvaluator.Instance.Evaluate(_numst.Target, _def.value);
PdtEvaluator.Instance.ContextSelfValue = null;
return _numst.Value;
}
public object MapValueInverse(object value) { throw new NotSupportedException(); }
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c8b12ed5f582bb24fbc508f74f8ef79e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,44 @@
using Cryville.Common;
using Cryville.Common.Collections.Specialized;
using Cryville.Crtr.Ruleset;
using System;
using System.Collections.Generic;
namespace Cryville.Crtr.Config {
public class RulesetConfigStore {
readonly IntKeyedDictionary<PropSrc> _srcs = new IntKeyedDictionary<PropSrc>();
readonly Dictionary<string, int> _revMap = new Dictionary<string, int>();
readonly Dictionary<string, object> _values;
public RulesetConfigStore(Dictionary<Identifier, ConfigDefinition> defs, Dictionary<string, object> values) {
_values = values;
if (defs == null) return;
foreach (var def in defs) {
var key = def.Key.Key;
var name = (string)def.Key.Name;
if (!_values.ContainsKey(name)) {
double value = 0;
PdtEvaluator.Instance.Evaluate(new PropOp.Float(v => value = v), def.Value.@default);
_values.Add(name, value);
}
_revMap.Add(name, key);
_srcs.Add(key, new PropSrc.Float(() => {
float result = 0;
PdtEvaluator.Instance.ContextSelfValue = new PropSrc.Float(() => Convert.ToSingle(_values[name]));
PdtEvaluator.Instance.Evaluate(new PropOp.Float(v => result = v), def.Value.value);
PdtEvaluator.Instance.ContextSelfValue = null;
return result;
}));
}
}
public object this[string key] {
get { return _values[key]; }
set {
_values[key] = value;
_srcs[_revMap[key]].Invalidate();
}
}
public bool TryGetMappedSource(int key, out PropSrc result) {
return _srcs.TryGetValue(key, out result);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d346b4bc0a3d4a44f90a924d01c0d2f2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

Some files were not shown because too many files have changed in this diff Show More