108 Commits

Author SHA1 Message Date
c2e94afc1c Update Cryville.Common.Logging. 2023-11-20 20:21:21 +08:00
e2c58c708f Remove console. 2023-11-20 20:15:52 +08:00
c52bf734d3 Watches file changes in legacy resource manager in favor of manual refresh. 2023-11-13 17:39:45 +08:00
ca60681de7 Implement enumerator for legacy resource manager. 2023-11-13 17:37:17 +08:00
8f3c38e273 Add more debug logs about environment. 2023-11-13 00:39:30 +08:00
119b87f3df Fix the two names in the item tile flipped. 2023-11-13 00:38:33 +08:00
2778725b91 Fix error on invalid resource item. 2023-11-13 00:36:30 +08:00
4ca5809597 Code cleanup. 2023-11-13 00:28:26 +08:00
0cdd6e569e Obsolete the old file dialog. 2023-11-13 00:27:20 +08:00
8c11be48cf Adapt resource manager to URI and list pattern. 2023-11-13 00:26:18 +08:00
9fcf6f3379 Remove ResourceItemMeta. 2023-11-13 00:23:08 +08:00
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
459 changed files with 37076 additions and 6095 deletions

File diff suppressed because it is too large Load Diff

View File

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

View File

@@ -3,9 +3,9 @@ using System;
namespace Cryville.Common.ComponentModel { namespace Cryville.Common.ComponentModel {
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)] [AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
public class StepAttribute : Attribute { public class StepAttribute : Attribute {
public StepAttribute(float step) { public StepAttribute(double step) {
Step = 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

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

View File

@@ -1,4 +1,4 @@
using Cryville.Common.Culture; using Cryville.Culture;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@@ -6,323 +6,339 @@ using System.Linq;
namespace Cryville.Common.Font { namespace Cryville.Common.Font {
public abstract class FontMatcher { public abstract class FontMatcher {
protected FontManager Manager { get; private set; } protected FontManager Manager { get; private set; }
public FontMatcher(FontManager manafer) { Manager = manafer; } public FontMatcher(FontManager manager) { Manager = manager; }
public abstract IEnumerable<Typeface> MatchScript(string script = null, bool distinctFamily = false); public abstract IEnumerable<Typeface> MatchLanguage(LanguageId lang, bool distinctFamily = false);
} }
public class FallbackListFontMatcher : FontMatcher { public class FallbackListFontMatcher : FontMatcher {
readonly LanguageMatching _matcher;
static readonly string UltimateFallbackScript = "zzzz";
public Dictionary<string, List<string>> MapScriptToTypefaces = new Dictionary<string, List<string>>(); public Dictionary<string, List<string>> MapScriptToTypefaces = new Dictionary<string, List<string>>();
public void LoadDefaultWindowsFallbackList() { public static Dictionary<string, List<string>> GetDefaultWindowsFallbackMap() {
if (Environment.OSVersion.Platform != PlatformID.Win32NT) return; var map = new Dictionary<string, List<string>>(StringComparer.OrdinalIgnoreCase);
MapScriptToTypefaces.Clear(); FillKeysWithScripts(map, () => new List<string>());
ScriptUtils.FillKeysWithScripts(MapScriptToTypefaces, () => new List<string>());
// Reference: https://github.com/chromium/chromium/blob/main/third_party/blink/renderer/platform/fonts/win/font_fallback_win.cc // 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 map[UltimateFallbackScript].Insert(0, "SimSun"); // Custom
MapScriptToTypefaces["zyyy"].Insert(0, "SimHei"); // Custom map[UltimateFallbackScript].Insert(0, "SimHei"); // Custom
MapScriptToTypefaces["zyyy"].Insert(0, "Microsoft YaHei"); // Custom map[UltimateFallbackScript].Insert(0, "Microsoft YaHei"); // Custom
MapScriptToTypefaces["zyyy"].Insert(0, "Arial"); map[UltimateFallbackScript].Insert(0, "Arial");
MapScriptToTypefaces["zyyy"].Insert(0, "Times New Roman"); map[UltimateFallbackScript].Insert(0, "Times New Roman");
MapScriptToTypefaces["zyyy"].Insert(0, "Segoe UI"); // Custom map[UltimateFallbackScript].Insert(0, "Segoe UI"); // Custom
MapScriptToTypefaces["arab"].Insert(0, "Tahoma"); map["arab"].Insert(0, "Tahoma");
MapScriptToTypefaces["cyrl"].Insert(0, "Times New Roman"); map["cyrl"].Insert(0, "Times New Roman");
MapScriptToTypefaces["grek"].Insert(0, "Times New Roman"); map["grek"].Insert(0, "Times New Roman");
MapScriptToTypefaces["hebr"].Insert(0, "David"); map["hebr"].Insert(0, "David");
MapScriptToTypefaces["jpan"].Insert(0, "MS PGothic"); map["jpan"].Insert(0, "MS PGothic");
MapScriptToTypefaces["latn"].Insert(0, "Times New Roman"); map["latn"].Insert(0, "Times New Roman");
MapScriptToTypefaces["hans"].Insert(0, "SimSun"); map["hans"].Insert(0, "SimSun");
MapScriptToTypefaces["hans"].Insert(0, "SimHei"); // Custom map["hans"].Insert(0, "SimHei"); // Custom
MapScriptToTypefaces["thai"].Insert(0, "Tahoma"); map["thai"].Insert(0, "Tahoma");
MapScriptToTypefaces["hans"].Insert(0, "PMingLiU"); map["hans"].Insert(0, "PMingLiU");
// Reference: https://learn.microsoft.com/en-us/globalization/input/font-support // Reference: https://learn.microsoft.com/en-us/globalization/input/font-support
var ver = Environment.OSVersion.Version; var ver = Environment.OSVersion.Version;
if (ver >= new Version(5, 0)) { // Windows 2000 if (ver >= new Version(5, 0)) { // Windows 2000
MapScriptToTypefaces["armn"].Insert(0, "Sylfaen"); map["armn"].Insert(0, "Sylfaen");
MapScriptToTypefaces["deva"].Insert(0, "Mangal"); map["deva"].Insert(0, "Mangal");
MapScriptToTypefaces["geor"].Insert(0, "Sylfaen"); map["geor"].Insert(0, "Sylfaen");
MapScriptToTypefaces["taml"].Insert(0, "Latha"); map["taml"].Insert(0, "Latha");
} }
if (ver >= new Version(5, 1)) { // Windows XP if (ver >= new Version(5, 1)) { // Windows XP
MapScriptToTypefaces["gujr"].Insert(0, "Shruti"); map["gujr"].Insert(0, "Shruti");
MapScriptToTypefaces["guru"].Insert(0, "Raavi"); map["guru"].Insert(0, "Raavi");
MapScriptToTypefaces["knda"].Insert(0, "Tunga"); map["knda"].Insert(0, "Tunga");
MapScriptToTypefaces["syrc"].Insert(0, "Estrangelo Edessa"); map["syrc"].Insert(0, "Estrangelo Edessa");
MapScriptToTypefaces["telu"].Insert(0, "Gautami"); map["telu"].Insert(0, "Gautami");
MapScriptToTypefaces["thaa"].Insert(0, "MV Boli"); map["thaa"].Insert(0, "MV Boli");
// SP2 // SP2
MapScriptToTypefaces["beng"].Insert(0, "Vrinda"); map["beng"].Insert(0, "Vrinda");
MapScriptToTypefaces["mlym"].Insert(0, "Kartika"); map["mlym"].Insert(0, "Kartika");
} }
if (ver >= new Version(6, 0)) { // Windows Vista if (ver >= new Version(6, 0)) { // Windows Vista
MapScriptToTypefaces["cans"].Insert(0, "Euphemia"); map["cans"].Insert(0, "Euphemia");
MapScriptToTypefaces["cher"].Insert(0, "Plantagenet"); map["cher"].Insert(0, "Plantagenet");
MapScriptToTypefaces["ethi"].Insert(0, "Nyala"); map["ethi"].Insert(0, "Nyala");
MapScriptToTypefaces["khmr"].Insert(0, "DaunPenh MoolBoran"); map["khmr"].Insert(0, "DaunPenh MoolBoran");
MapScriptToTypefaces["laoo"].Insert(0, "DokChampa"); map["laoo"].Insert(0, "DokChampa");
MapScriptToTypefaces["mong"].Insert(0, "Mongolian Baiti"); map["mong"].Insert(0, "Mongolian Baiti");
MapScriptToTypefaces["orya"].Insert(0, "Kalinga"); map["orya"].Insert(0, "Kalinga");
MapScriptToTypefaces["sinh"].Insert(0, "Iskoola Pota"); map["sinh"].Insert(0, "Iskoola Pota");
MapScriptToTypefaces["tibt"].Insert(0, "Microsoft Himalaya"); map["tibt"].Insert(0, "Microsoft Himalaya");
MapScriptToTypefaces["yiii"].Insert(0, "Microsoft Yi Baiti"); map["yiii"].Insert(0, "Microsoft Yi Baiti");
MapScriptToTypefaces["arab"].Insert(0, "Segoe UI"); map["arab"].Insert(0, "Segoe UI");
MapScriptToTypefaces["cyrl"].Insert(0, "Segoe UI"); map["cyrl"].Insert(0, "Segoe UI");
MapScriptToTypefaces["grek"].Insert(0, "Segoe UI"); map["grek"].Insert(0, "Segoe UI");
MapScriptToTypefaces["latn"].Insert(0, "Segoe UI"); map["latn"].Insert(0, "Segoe UI");
MapScriptToTypefaces["hans"].Add("SimSun-ExtB"); map["hans"].Add("SimSun-ExtB");
MapScriptToTypefaces["hant"].Add("MingLiU-ExtB"); map["hant"].Add("MingLiU-ExtB");
MapScriptToTypefaces["hant"].Add("MingLiU_HKSCS-ExtB"); map["hant"].Add("MingLiU_HKSCS-ExtB");
MapScriptToTypefaces["arab"].Add("Microsoft Uighur"); map["arab"].Add("Microsoft Uighur");
MapScriptToTypefaces["zmth"].Insert(0, "Cambria Math"); map["zmth"].Insert(0, "Cambria Math");
// Reference: https://en.wikipedia.org/wiki/List_of_CJK_fonts // Reference: https://en.wikipedia.org/wiki/List_of_CJK_fonts
MapScriptToTypefaces["jpan"].Insert(0, "Meiryo"); map["jpan"].Insert(0, "Meiryo");
MapScriptToTypefaces["hans"].Insert(0, "Microsoft YaHei"); map["hans"].Insert(0, "Microsoft YaHei");
} }
if (ver >= new Version(6, 1)) { // Windows 7 if (ver >= new Version(6, 1)) { // Windows 7
MapScriptToTypefaces["brai"].Insert(0, "Segoe UI Symbol"); map["brai"].Insert(0, "Segoe UI Symbol");
MapScriptToTypefaces["dsrt"].Insert(0, "Segoe UI Symbol"); map["dsrt"].Insert(0, "Segoe UI Symbol");
MapScriptToTypefaces["talu"].Insert(0, "Microsoft New Tai Lue"); map["talu"].Insert(0, "Microsoft New Tai Lue");
MapScriptToTypefaces["ogam"].Insert(0, "Segoe UI Symbol"); map["ogam"].Insert(0, "Segoe UI Symbol");
MapScriptToTypefaces["osma"].Insert(0, "Ebrima"); map["osma"].Insert(0, "Ebrima");
MapScriptToTypefaces["phag"].Insert(0, "Microsoft PhagsPa"); map["phag"].Insert(0, "Microsoft PhagsPa");
MapScriptToTypefaces["runr"].Insert(0, "Segoe UI Symbol"); map["runr"].Insert(0, "Segoe UI Symbol");
MapScriptToTypefaces["zsym"].Insert(0, "Segoe UI Symbol"); map["zsym"].Insert(0, "Segoe UI Symbol");
MapScriptToTypefaces["tale"].Insert(0, "Microsoft Tai Le"); map["tale"].Insert(0, "Microsoft Tai Le");
MapScriptToTypefaces["tfng"].Insert(0, "Ebrima"); map["tfng"].Insert(0, "Ebrima");
MapScriptToTypefaces["vaii"].Insert(0, "Ebrima"); map["vaii"].Insert(0, "Ebrima");
} }
if (ver >= new Version(6, 2)) { // Windows 8 if (ver >= new Version(6, 2)) { // Windows 8
MapScriptToTypefaces["glag"].Insert(0, "Segoe UI Symbol"); map["glag"].Insert(0, "Segoe UI Symbol");
MapScriptToTypefaces["goth"].Insert(0, "Segoe UI Symbol"); map["goth"].Insert(0, "Segoe UI Symbol");
MapScriptToTypefaces["hang"].Add("Malgun Gothic"); map["hang"].Add("Malgun Gothic");
MapScriptToTypefaces["ital"].Insert(0, "Segoe UI Symbol"); map["ital"].Insert(0, "Segoe UI Symbol");
MapScriptToTypefaces["lisu"].Insert(0, "Segoe UI"); map["lisu"].Insert(0, "Segoe UI");
MapScriptToTypefaces["mymr"].Insert(0, "Myanmar Text"); map["mymr"].Insert(0, "Myanmar Text");
MapScriptToTypefaces["nkoo"].Insert(0, "Ebrima"); map["nkoo"].Insert(0, "Ebrima");
MapScriptToTypefaces["orkh"].Insert(0, "Segoe UI Symbol"); map["orkh"].Insert(0, "Segoe UI Symbol");
MapScriptToTypefaces["ethi"].Insert(0, "Ebrima"); map["ethi"].Insert(0, "Ebrima");
MapScriptToTypefaces["cans"].Insert(0, "Gadugi"); map["cans"].Insert(0, "Gadugi");
MapScriptToTypefaces["hant"].Insert(0, "Microsoft JhengHei UI"); map["hant"].Insert(0, "Microsoft JhengHei UI");
MapScriptToTypefaces["hans"].Insert(0, "Microsoft YaHei UI"); map["hans"].Insert(0, "Microsoft YaHei UI");
MapScriptToTypefaces["beng"].Insert(0, "Nirmala UI"); map["beng"].Insert(0, "Nirmala UI");
MapScriptToTypefaces["deva"].Insert(0, "Nirmala UI"); map["deva"].Insert(0, "Nirmala UI");
MapScriptToTypefaces["gujr"].Insert(0, "Nirmala UI"); map["gujr"].Insert(0, "Nirmala UI");
MapScriptToTypefaces["guru"].Insert(0, "Nirmala UI"); // NOT DOCUMENTED, UNVERIFIED map["guru"].Insert(0, "Nirmala UI"); // NOT DOCUMENTED, UNVERIFIED
MapScriptToTypefaces["knda"].Insert(0, "Nirmala UI"); // NOT DOCUMENTED, UNVERIFIED map["knda"].Insert(0, "Nirmala UI"); // NOT DOCUMENTED, UNVERIFIED
MapScriptToTypefaces["mlym"].Insert(0, "Nirmala UI"); map["mlym"].Insert(0, "Nirmala UI");
MapScriptToTypefaces["orya"].Insert(0, "Nirmala UI"); map["orya"].Insert(0, "Nirmala UI");
MapScriptToTypefaces["sinh"].Insert(0, "Nirmala UI"); // NOT DOCUMENTED, UNVERIFIED map["sinh"].Insert(0, "Nirmala UI"); // NOT DOCUMENTED, UNVERIFIED
MapScriptToTypefaces["taml"].Insert(0, "Nirmala UI"); // NOT DOCUMENTED, UNVERIFIED map["taml"].Insert(0, "Nirmala UI"); // NOT DOCUMENTED, UNVERIFIED
MapScriptToTypefaces["telu"].Insert(0, "Nirmala UI"); map["telu"].Insert(0, "Nirmala UI");
MapScriptToTypefaces["armn"].Insert(0, "Segoe UI"); map["armn"].Insert(0, "Segoe UI");
MapScriptToTypefaces["geor"].Insert(0, "Segoe UI"); map["geor"].Insert(0, "Segoe UI");
MapScriptToTypefaces["hebr"].Insert(0, "Segoe UI"); map["hebr"].Insert(0, "Segoe UI");
} }
if (ver >= new Version(6, 3)) { // Windows 8.1 if (ver >= new Version(6, 3)) { // Windows 8.1
MapScriptToTypefaces["bugi"].Insert(0, "Leelawadee UI"); map["bugi"].Insert(0, "Leelawadee UI");
MapScriptToTypefaces["copt"].Insert(0, "Segoe UI Symbol"); map["copt"].Insert(0, "Segoe UI Symbol");
MapScriptToTypefaces["java"].Insert(0, "Javanese Text"); map["java"].Insert(0, "Javanese Text");
MapScriptToTypefaces["merc"].Insert(0, "Segoe UI Symbol"); map["merc"].Insert(0, "Segoe UI Symbol");
MapScriptToTypefaces["olck"].Insert(0, "Nirmala UI"); map["olck"].Insert(0, "Nirmala UI");
MapScriptToTypefaces["sora"].Insert(0, "Nirmala UI"); map["sora"].Insert(0, "Nirmala UI");
MapScriptToTypefaces["khmr"].Insert(0, "Leelawadee UI"); map["khmr"].Insert(0, "Leelawadee UI");
MapScriptToTypefaces["laoo"].Insert(0, "Leelawadee UI"); map["laoo"].Insert(0, "Leelawadee UI");
MapScriptToTypefaces["thai"].Insert(0, "Leelawadee UI"); map["thai"].Insert(0, "Leelawadee UI");
MapScriptToTypefaces["zsye"].Insert(0, "Segoe UI Emoji"); map["zsye"].Insert(0, "Segoe UI Emoji");
} }
if (ver >= new Version(10, 0)) { // Windows 10 if (ver >= new Version(10, 0)) { // Windows 10
MapScriptToTypefaces["brah"].Insert(0, "Segoe UI Historic"); map["brah"].Insert(0, "Segoe UI Historic");
MapScriptToTypefaces["cari"].Insert(0, "Segoe UI Historic"); map["cari"].Insert(0, "Segoe UI Historic");
MapScriptToTypefaces["cprt"].Insert(0, "Segoe UI Historic"); map["cprt"].Insert(0, "Segoe UI Historic");
MapScriptToTypefaces["egyp"].Insert(0, "Segoe UI Historic"); map["egyp"].Insert(0, "Segoe UI Historic");
MapScriptToTypefaces["armi"].Insert(0, "Segoe UI Historic"); map["armi"].Insert(0, "Segoe UI Historic");
MapScriptToTypefaces["phli"].Insert(0, "Segoe UI Historic"); map["phli"].Insert(0, "Segoe UI Historic");
MapScriptToTypefaces["prti"].Insert(0, "Segoe UI Historic"); map["prti"].Insert(0, "Segoe UI Historic");
MapScriptToTypefaces["khar"].Insert(0, "Segoe UI Historic"); map["khar"].Insert(0, "Segoe UI Historic");
MapScriptToTypefaces["lyci"].Insert(0, "Segoe UI Historic"); map["lyci"].Insert(0, "Segoe UI Historic");
MapScriptToTypefaces["lydi"].Insert(0, "Segoe UI Historic"); map["lydi"].Insert(0, "Segoe UI Historic");
MapScriptToTypefaces["phnx"].Insert(0, "Segoe UI Historic"); map["phnx"].Insert(0, "Segoe UI Historic");
MapScriptToTypefaces["xpeo"].Insert(0, "Segoe UI Historic"); map["xpeo"].Insert(0, "Segoe UI Historic");
MapScriptToTypefaces["sarb"].Insert(0, "Segoe UI Historic"); map["sarb"].Insert(0, "Segoe UI Historic");
MapScriptToTypefaces["shaw"].Insert(0, "Segoe UI Historic"); map["shaw"].Insert(0, "Segoe UI Historic");
MapScriptToTypefaces["xsux"].Insert(0, "Segoe UI Historic"); map["xsux"].Insert(0, "Segoe UI Historic");
MapScriptToTypefaces["ugar"].Insert(0, "Segoe UI Historic"); map["ugar"].Insert(0, "Segoe UI Historic");
// Segoe UI Symbol -> Segoe UI Historic // Segoe UI Symbol -> Segoe UI Historic
MapScriptToTypefaces["glag"].Insert(0, "Segoe UI Historic"); map["glag"].Insert(0, "Segoe UI Historic");
MapScriptToTypefaces["goth"].Insert(0, "Segoe UI Historic"); map["goth"].Insert(0, "Segoe UI Historic");
MapScriptToTypefaces["merc"].Insert(0, "Segoe UI Historic"); map["merc"].Insert(0, "Segoe UI Historic");
MapScriptToTypefaces["ogam"].Insert(0, "Segoe UI Historic"); map["ogam"].Insert(0, "Segoe UI Historic");
MapScriptToTypefaces["ital"].Insert(0, "Segoe UI Historic"); map["ital"].Insert(0, "Segoe UI Historic");
MapScriptToTypefaces["orkh"].Insert(0, "Segoe UI Historic"); map["orkh"].Insert(0, "Segoe UI Historic");
MapScriptToTypefaces["runr"].Insert(0, "Segoe UI Historic"); map["runr"].Insert(0, "Segoe UI Historic");
// //
MapScriptToTypefaces["jpan"].Insert(0, "Yu Gothic UI"); map["jpan"].Insert(0, "Yu Gothic UI");
MapScriptToTypefaces["zsym"].Add("Segoe MDL2 Assets"); 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;
Shared.Logger.Log(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;
Shared.Logger.Log(0, "UI", "Matching fallback fonts");
foreach (var typeface in EnumerateTypefaces(MapScriptToTypefaces[UltimateFallbackScript], distinctFamily)) {
yield return typeface;
} }
} }
public void LoadDefaultAndroidFallbackList() { IEnumerable<Typeface> EnumerateTypefaces(List<string> candidates, bool distinctFamily) {
if (Environment.OSVersion.Platform != PlatformID.Unix) return; foreach (var candidate in candidates) {
MapScriptToTypefaces.Clear(); if (Manager.MapFullNameToTypeface.TryGetValue(candidate, out var typeface1)) {
ScriptUtils.FillKeysWithScripts(MapScriptToTypefaces, () => new List<string>()); yield return typeface1;
MapScriptToTypefaces["zyyy"].Insert(0, "Noto Sans CJK TC"); // TODO Modify default fallback }
MapScriptToTypefaces["zyyy"].Insert(0, "Noto Sans CJK JP"); if (distinctFamily) continue;
MapScriptToTypefaces["zyyy"].Insert(0, "Noto Sans CJK SC"); IReadOnlyCollection<Typeface> typefaces2;
MapScriptToTypefaces["zyyy"].Insert(0, "Roboto"); if (Manager.MapNameToTypefaces.TryGetValue(candidate, out typefaces2)) {
MapScriptToTypefaces["zsye"].Insert(0, "Noto Color Emoji"); foreach (var typeface in typefaces2) {
MapScriptToTypefaces["zsye"].Add("Noto Color Emoji Flags"); if (typeface1 == typeface) continue;
MapScriptToTypefaces["arab"].Insert(0, "Noto Naskh Arabic"); yield return typeface;
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;
}
}
}
} }
} }
candidateScripts = ScriptUtils.EnumerateFallbackScripts(script);
} }
} }
} }

View File

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

View File

@@ -23,9 +23,9 @@ namespace Cryville.Common.Font {
protected override void GetName(BinaryReader reader) { protected override void GetName(BinaryReader reader) {
var dir = new TableDirectory(reader, (uint)reader.BaseStream.Position); 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()); 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(); 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(); 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(); 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 fileFormatVersion: 2
guid: 520554ce9a8205b4b91e0ff2b8011673 guid: 1a624371d4108614b9cdc4acca1499e2
folderAsset: yes folderAsset: yes
DefaultImporter: DefaultImporter:
externalObjects: {} externalObjects: {}

View File

@@ -1,15 +1,13 @@
using Cryville.Common.Logging;
using Microsoft.Win32; using Microsoft.Win32;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.IO; using System.IO;
using System.Linq;
using System.Net.Sockets; using System.Net.Sockets;
using System.Text; using System.Text;
namespace Cryville.Common.Network { namespace Cryville.Common.Network.Http11 {
public class HttpClient { public class Http11Client : IDisposable {
private readonly string _directHost; private readonly string _directHost;
protected string DirectHost { get { return _directHost; } } protected string DirectHost { get { return _directHost; } }
@@ -19,36 +17,24 @@ namespace Cryville.Common.Network {
readonly Uri _baseUri; readonly Uri _baseUri;
readonly int origPort; readonly int origPort;
protected string Version = "HTTP/1.1"; protected const string Version = "HTTP/1.1";
protected TcpClient TcpClient { get; private set; } protected TcpClient TcpClient { get; private set; }
protected Stream RawTcpStream { protected Stream RawTcpStream { get { return TcpClient.GetStream(); } }
get { protected virtual Stream Stream { get { return TcpClient.GetStream(); } }
return TcpClient.GetStream(); protected virtual string WindowsProxyProtocolName { get { return "http"; } }
}
}
protected virtual Stream Stream {
get {
return TcpClient.GetStream();
}
}
protected virtual string WindowsProxyProtocolName {
get {
return "http";
}
}
private readonly bool _proxied = false; private readonly bool _proxied = false;
public Dictionary<string, string> Headers { get; set; } public Dictionary<string, string> Headers { get; set; }
public HttpClient(Uri baseUri, int port = 80) { public Http11Client(Uri baseUri, int port = 80) {
_directHost = baseUri.Host; _directHost = baseUri.Host;
_directPort = port; _directPort = port;
_baseUri = baseUri; _baseUri = baseUri;
origPort = _baseUri.Port; origPort = _baseUri.Port;
Headers = new Dictionary<string, string>(); Headers = new Dictionary<string, string>();
_proxied = GetProxy(ref _directHost, ref _directPort); _proxied = GetProxy(ref _directHost, ref _directPort);
Logger.Log("main", 0, "Network", "Connecting to {0}:{1}", DirectHost, DirectPort); Shared.Logger.Log(0, "Network", "Connecting to {0}:{1}", DirectHost, DirectPort);
TcpClient = new TcpClient(DirectHost, DirectPort); TcpClient = new TcpClient(DirectHost, DirectPort);
} }
@@ -62,17 +48,28 @@ namespace Cryville.Common.Network {
TcpClient.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; string struri = GetUri(uri).PathAndQuery;
return Request(Stream, method, struri, body, encoding); return Request(Stream, method, struri, body, encoding);
} }
public HttpResponse Request(Stream stream, string method, string uri, string body = null, Encoding encoding = null) { Http11Response Request(Stream stream, string method, string uri, string body = null, Encoding encoding = null) {
var headers = new Dictionary<string, string>(); var headers = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
foreach (var h in Headers) foreach (var h in Headers)
headers.Add(h.Key, h.Value); headers.Add(h.Key, h.Value);
headers["Host"] = _baseUri.Host; headers["Host"] = _baseUri.Host;
byte[] payload = new byte[0]; byte[] payload = null;
if (body != null) { if (body != null) {
if (encoding == null) if (encoding == null)
encoding = Encoding.UTF8; encoding = Encoding.UTF8;
@@ -80,23 +77,25 @@ namespace Cryville.Common.Network {
headers.Add("Content-Encoding", encoding.EncodingName); headers.Add("Content-Encoding", encoding.EncodingName);
headers.Add("Content-Length", payload.Length.ToString(CultureInfo.InvariantCulture)); headers.Add("Content-Length", payload.Length.ToString(CultureInfo.InvariantCulture));
} }
string request_line = string.Format( using (var writer = new StreamWriter(stream, Encoding.ASCII, 1024, true)) {
"{0} {1} {2}\r\n", method, uri, Version writer.Write(method);
); writer.Write(' ');
string header_fields = string.Concat(( writer.Write(uri);
from h in headers select h.Key + ":" + h.Value + "\r\n" writer.Write(' ');
).ToArray()); writer.Write(Version);
byte[] buffer0 = Encoding.ASCII.GetBytes(string.Format( writer.Write("\r\n");
"{0}{1}\r\n", request_line, header_fields foreach (var header in headers) {
)); writer.Write(header.Key);
byte[] buffer1 = new byte[buffer0.Length + payload.Length]; writer.Write(':');
Array.Copy(buffer0, buffer1, buffer0.Length); writer.Write(header.Value);
Array.Copy(payload, 0, buffer1, buffer0.Length, payload.Length); writer.Write("\r\n");
Logger.Log("main", 0, "Network", Encoding.UTF8.GetString(buffer1)); }
stream.Write(buffer1, 0, buffer1.Length); writer.Write("\r\n");
stream.Flush(); if (payload != null) writer.Write(payload);
var response = new HttpResponse(stream); writer.Flush();
Logger.Log("main", 0, "Network", "{0}", response); }
var response = new Http11Response(stream);
Shared.Logger.Log(0, "Network", "{0}", response);
return response; return response;
} }

View File

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

View File

@@ -1,31 +1,41 @@
using Cryville.Common.Logging; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Text; using System.Text;
namespace Cryville.Common.Network { namespace Cryville.Common.Network.Http11 {
public class HttpResponse { public class Http11Response : IDisposable {
static readonly char[] spchar = new char[]{ ' ' }; static readonly char[] spchar = new char[]{ ' ' };
public string HttpVersion { get; private set; } public string HttpVersion { get; private set; }
public string StatusCode { get; private set; } public string StatusCode { get; private set; }
public string ReasonPhase { get; private set; } public string ReasonPhase { get; private set; }
public Dictionary<string, string> Headers { get; private set; } public Dictionary<string, string> Headers { get; private set; }
public HttpResponseStream MessageBody { get; private set; } public Http11ResponseStream MessageBody { get; private set; }
internal HttpResponse(Stream stream) { internal Http11Response(Stream stream) {
var reader = new BinaryReader(stream, Encoding.ASCII); var reader = new BinaryReader(stream, Encoding.ASCII);
var statu_line = ReadLine(reader).Split(spchar, 3); var statu_line = ReadLine(reader).Split(spchar, 3);
HttpVersion = statu_line[0]; HttpVersion = statu_line[0];
StatusCode = statu_line[1]; StatusCode = statu_line[1];
ReasonPhase = statu_line[2]; ReasonPhase = statu_line[2];
Logger.Log("main", 0, "Network", "Receive Response: {0} {1} {2}", HttpVersion, StatusCode, ReasonPhase); Headers = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
Headers = new Dictionary<string, string>();
while (ParseHeader(reader, Headers)) ; while (ParseHeader(reader, Headers)) ;
if (Headers.ContainsKey("content-length")) { if (Headers.ContainsKey("content-length")) {
int length = int.Parse(Headers["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") { 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 // TODO Multiline header
var header = ReadLine(reader); var header = ReadLine(reader);
if (header == "") return false; if (header == "") return false;
var s = header.Split(':'); var s = header.Split(':', 2);
string field_name = s[0].Trim().ToLower(); string field_name = s[0].Trim().ToLower();
string field_value = s[1].Trim(); string field_value = s[1].Trim();
if (headers.ContainsKey(field_name)) headers[field_name] += "," + field_value; if (headers.ContainsKey(field_name)) headers[field_name] += "," + field_value;
else headers.Add(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; return true;
} }

View File

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

View File

@@ -1,12 +1,11 @@
using Cryville.Common.Logging;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
namespace Cryville.Common.Network { namespace Cryville.Common.Network.Http11 {
public abstract class HttpResponseStream : Stream { public abstract class Http11ResponseStream : Stream {
public override bool CanRead { get { return true; } } public override bool CanRead { get { return true; } }
public override bool CanSeek { get { return false; } } 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 BinaryReader _reader;
readonly int _length; readonly int _length;
int _pos = 0; int _pos = 0;
internal HttpResponseBlockStream(BinaryReader reader, int length) { internal Http11ResponseBlockStream(BinaryReader reader, int length) {
_reader = reader; _reader = reader;
_length = length; _length = length;
} }
@@ -51,7 +50,6 @@ namespace Cryville.Common.Network {
if (recv_len == 0) return 0; if (recv_len == 0) return 0;
while (recv < recv_len) { while (recv < recv_len) {
recv += _reader.Read(buffer, offset + recv, count - recv); 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; _pos += recv_len;
return 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; readonly BinaryReader _reader;
byte[] _chunk = null; byte[] _chunk = null;
int _pos = 0; int _pos = 0;
internal HttpResponseChunkedStream(BinaryReader reader) { internal Http11ResponseChunkedStream(BinaryReader reader) {
_reader = reader; _reader = reader;
ReadChunk(); ReadChunk();
} }
public void ReadChunk() { public void ReadChunk() {
if (_chunk != null && _chunk.Length == 0) return; if (_chunk != null && _chunk.Length == 0) return;
string[] chunkHeader = HttpResponse.ReadLine(_reader).Split(';'); string[] chunkHeader = Http11Response.ReadLine(_reader).Split(';');
// int chunkSize = Array.IndexOf(LEN, chunkHeader[0].ToLower()[0]); int chunkSize;
int chunkSize = int.Parse(chunkHeader[0], NumberStyles.HexNumber); if (!int.TryParse(chunkHeader[0], NumberStyles.HexNumber, CultureInfo.InvariantCulture, out chunkSize))
if (chunkSize == -1)
throw new IOException("Corrupted chunk received"); throw new IOException("Corrupted chunk received");
if (chunkSize == 0) { if (chunkSize == 0) {
_chunk = new byte[0]; _chunk = new byte[0];
// TODO TE Header, now just discard // TODO TE Header, now just discard
var headers = new Dictionary<string, string>(); var headers = new Dictionary<string, string>();
while (HttpResponse.ParseHeader(_reader, headers)) ; while (Http11Response.ParseHeader(_reader, headers)) ;
return; return;
} }
_chunk = new byte[chunkSize]; _chunk = new byte[chunkSize];
int recv = 0; int recv = 0;
while (recv < chunkSize) { while (recv < chunkSize) {
recv += _reader.Read(_chunk, recv, chunkSize - recv); recv += _reader.Read(_chunk, recv, chunkSize - recv);
Logger.Log("main", 0, "Network", "Message chunk received: {0}/{1}", recv, chunkSize);
} }
_pos = 0; _pos = 0;
if (HttpResponse.ReadLine(_reader) != "") if (Http11Response.ReadLine(_reader) != "")
throw new IOException("Corrupted chunk received"); throw new IOException("Corrupted chunk received");
} }
public override int Read(byte[] buffer, int offset, int count) { 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;
using System.IO; using System.IO;
namespace Cryville.Common.Network { namespace Cryville.Common.Network.Http11 {
public class HttpsClient : HttpClient { public class Https11Client : Http11Client {
readonly TlsClient _tlsClient; readonly TlsClient _tlsClient;
protected override Stream Stream { 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); _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.Security;
using Org.BouncyCastle.Tls; using Org.BouncyCastle.Tls;
using Org.BouncyCastle.Tls.Crypto; using Org.BouncyCastle.Tls.Crypto;
using Org.BouncyCastle.Tls.Crypto.Impl.BC; using Org.BouncyCastle.Tls.Crypto.Impl.BC;
using System;
using System.Collections; using System.Collections;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
@@ -10,7 +10,7 @@ using System.Text;
using BcTlsClient = Org.BouncyCastle.Tls.TlsClient; using BcTlsClient = Org.BouncyCastle.Tls.TlsClient;
namespace Cryville.Common.Network { namespace Cryville.Common.Network {
public class TlsClient { public class TlsClient : IDisposable {
readonly TlsClientProtocol _protocol; readonly TlsClientProtocol _protocol;
readonly BcTlsClient _tlsClient; readonly BcTlsClient _tlsClient;
public Stream Stream { get; private set; } public Stream Stream { get; private set; }
@@ -28,6 +28,17 @@ namespace Cryville.Common.Network {
_protocol.Close(); _protocol.Close();
} }
public void Dispose() {
Dispose(true);
GC.SuppressFinalize(this);
}
public virtual void Dispose(bool disposing) {
if (disposing) {
Close();
}
}
private class InternalTlsClient : DefaultTlsClient { private class InternalTlsClient : DefaultTlsClient {
readonly string _host; readonly string _host;
@@ -72,20 +83,6 @@ namespace Cryville.Common.Network {
public override TlsAuthentication GetAuthentication() { public override TlsAuthentication GetAuthentication() {
return new NullTlsAuthentication(); 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 { private class NullTlsAuthentication : TlsAuthentication {

View File

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

View File

@@ -1,5 +1,4 @@
using Cryville.Common.Collections; using Cryville.Common.Collections;
using Cryville.Common.Logging;
using Cryville.Common.Reflection; using Cryville.Common.Reflection;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@@ -203,7 +202,7 @@ namespace Cryville.Common.Pdt {
switch (GetIdentifier()) { switch (GetIdentifier()) {
case "ver": case "ver":
ws(); ws();
Logger.Log("main", 3, "PDT", "Legacy PDT directive #ver={0} found. Ignoring.", GetNumber()); Shared.Logger.Log(3, "PDT", "Legacy PDT directive #ver={0} found. Ignoring.", GetNumber());
break; break;
case "format": case "format":
ws(); ws();

View File

@@ -0,0 +1,7 @@
using Cryville.Common.Logging;
namespace Cryville.Common {
public static class Shared {
public static readonly Logger Logger = new Logger();
}
}

View File

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

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; suspended = true;
if (currentNetworkTask != null) { if (currentNetworkTask != null) {
currentNetworkTask.Cancel(); currentNetworkTask.Cancel();
networkTasks.Enqueue(currentNetworkTask);
currentNetworkTask = null; currentNetworkTask = null;
} }
} }
@@ -91,15 +92,6 @@ namespace Cryville.Common.Unity {
/// A network task. /// A network task.
/// </summary> /// </summary>
public abstract class NetworkTask { public abstract class NetworkTask {
protected NetworkTask(string uri) {
Uri = uri;
}
/// <summary>
/// The URI of the resource.
/// </summary>
public string Uri { get; private set; }
/// <summary> /// <summary>
/// Whether the task is cancelled. /// Whether the task is cancelled.
/// </summary> /// </summary>
@@ -108,40 +100,56 @@ namespace Cryville.Common.Unity {
/// <summary> /// <summary>
/// Cancels the task. /// Cancels the task.
/// </summary> /// </summary>
public virtual void Cancel() { public void Cancel() {
Cancelled = true; Cancelled = true;
OnCancel();
} }
protected virtual void OnCancel() { }
#if UNITY_5_4_OR_NEWER
protected UnityWebRequest www;
/// <summary> /// <summary>
/// Starts the task. /// Starts the task.
/// </summary> /// </summary>
public virtual void Start() { public abstract void Start();
www = new UnityWebRequest(Uri);
www.SendWebRequest();
}
/// <summary> /// <summary>
/// Gets whether the task is done. /// Gets whether the task is done.
/// </summary> /// </summary>
/// <returns>Whether the task is done.</returns> /// <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; if (!www.isDone) return false;
return true; return true;
} }
#else #else
protected WWW www; protected WWW www;
/// <summary> /// <inheritdoc />
/// Starts the task.
/// </summary>
public virtual void Start() { public virtual void Start() {
www = new WWW(Uri); www = new WWW(Uri);
} }
/// <summary> /// <inheritdoc />
/// Gets whether the task is done.
/// </summary>
/// <returns>Whether the task is done.</returns>
public virtual bool Done() { public virtual bool Done() {
if (!www.isDone) return false; if (!www.isDone) return false;
return true; return true;
@@ -149,9 +157,9 @@ namespace Cryville.Common.Unity {
#endif #endif
} }
/// <summary> /// <summary>
/// A <see cref="NetworkTask" /> that loads a texture. /// A <see cref="UnityNetworkTask" /> that loads a texture.
/// </summary> /// </summary>
public class LoadTextureTask : NetworkTask { public class LoadTextureTask : UnityNetworkTask {
/// <summary> /// <summary>
/// Creates an instance of the <see cref="LoadTextureTask" /> class. /// Creates an instance of the <see cref="LoadTextureTask" /> class.
/// </summary> /// </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> /// <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. /// 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> /// </summary>
[ExecuteAlways]
public class AspectRatioLayoutElement : UIBehaviour, ILayoutElement { public class AspectRatioLayoutElement : UIBehaviour, ILayoutElement {
[SerializeField] [SerializeField]
[Tooltip("The aspect ratio. Width divided by height.")] [Tooltip("The aspect ratio. Width divided by height.")]
@@ -35,32 +36,27 @@ namespace Cryville.Common.Unity.UI {
SetDirty(); SetDirty();
} }
private void SetDirty() {
if (!IsActive()) return;
LayoutRebuilder.MarkLayoutForRebuild(transform as RectTransform);
}
/// <inheritdoc /> /// <inheritdoc />
public float minWidth { public float minWidth {
get { get {
return m_isVertical ? 0 : (transform as RectTransform).rect.height * m_aspectRatio; return m_isVertical ? -1 : (transform as RectTransform).rect.height * m_aspectRatio;
} }
} }
/// <inheritdoc /> /// <inheritdoc />
public float preferredWidth { get { return minWidth; } } public float preferredWidth { get { return minWidth; } }
/// <inheritdoc /> /// <inheritdoc />
public float flexibleWidth { get { return 0; } } public float flexibleWidth { get { return -1; } }
/// <inheritdoc /> /// <inheritdoc />
public float minHeight { public float minHeight {
get { get {
return m_isVertical ? (transform as RectTransform).rect.width / m_aspectRatio : 0; return m_isVertical ? (transform as RectTransform).rect.width / m_aspectRatio : -1;
} }
} }
/// <inheritdoc /> /// <inheritdoc />
public float preferredHeight { get { return minHeight; } } public float preferredHeight { get { return minHeight; } }
/// <inheritdoc /> /// <inheritdoc />
public float flexibleHeight { get { return 0; } } public float flexibleHeight { get { return -1; } }
/// <inheritdoc /> /// <inheritdoc />
public int layoutPriority { get { return 1; } } public int layoutPriority { get { return 1; } }
@@ -71,34 +67,44 @@ namespace Cryville.Common.Unity.UI {
/// <inheritdoc /> /// <inheritdoc />
public void CalculateLayoutInputVertical() { } public void CalculateLayoutInputVertical() { }
protected override void OnDidApplyAnimationProperties() {
base.OnDidApplyAnimationProperties();
SetDirty();
}
protected override void OnDisable() {
SetDirty();
base.OnDisable();
}
protected override void OnEnable() { protected override void OnEnable() {
base.OnEnable(); base.OnEnable();
SetDirty(); SetDirty();
} }
protected override void OnBeforeTransformParentChanged() {
protected override void OnRectTransformDimensionsChange() { base.OnBeforeTransformParentChanged();
base.OnRectTransformDimensionsChange();
SetDirty(); SetDirty();
} }
protected override void OnTransformParentChanged() { protected override void OnTransformParentChanged() {
base.OnTransformParentChanged(); base.OnTransformParentChanged();
SetDirty(); SetDirty();
} }
protected override void OnDidApplyAnimationProperties() {
// Overriding fails compiler base.OnDidApplyAnimationProperties();
new void OnValidate() {
SetDirty(); 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; } 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 { public override Texture mainTexture {
get { return Sprite == null ? s_WhiteTexture : Sprite.texture; } 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) { 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) { if (Sprite == null) {
throw new UnityException("No sprite"); throw new UnityException("No sprite");
} }
@@ -95,51 +85,87 @@ namespace Cryville.Common.Unity.UI {
throw new UnityException("No sprite border"); 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; float w3, w4, w5, w6;
if (actualTotalCornerWidth > actualWidth) { if (actualTotalCornerLength > actualLength) {
switch (Compact) { switch (Compact) {
case CompactMode.SqueezeBoth: case CompactMode.SqueezeBoth:
w3 = w4 = actualLeftCornerWidth / actualTotalCornerWidth * actualWidth; w3 = w4 = actualStartCornerLength / actualTotalCornerLength * actualLength;
w5 = w6 = actualRightCornerWidth / actualTotalCornerWidth * actualWidth; w5 = w6 = actualEndCornerLength / actualTotalCornerLength * actualLength;
break; break;
case CompactMode.SqueezeLeft: case CompactMode.SqueezeLeft:
w3 = w4 = actualWidth - actualRightCornerWidth; w3 = w4 = actualLength - actualEndCornerLength;
w5 = w6 = actualRightCornerWidth; w5 = w6 = actualEndCornerLength;
break; break;
case CompactMode.SqueezeRight: case CompactMode.SqueezeRight:
w3 = w4 = actualLeftCornerWidth; w3 = w4 = actualStartCornerLength;
w5 = w6 = actualWidth - actualLeftCornerWidth; w5 = w6 = actualLength - actualStartCornerLength;
break; break;
case CompactMode.DiagonalLeft: case CompactMode.DiagonalLeft:
w3 = actualLeftCornerWidth; w3 = actualStartCornerLength;
w4 = actualWidth - actualRightCornerWidth; w4 = actualLength - actualEndCornerLength;
w5 = actualWidth - actualLeftCornerWidth; w5 = actualLength - actualStartCornerLength;
w6 = actualRightCornerWidth; w6 = actualEndCornerLength;
break; break;
case CompactMode.DiagonalRight: case CompactMode.DiagonalRight:
w3 = actualWidth - actualRightCornerWidth; w3 = actualLength - actualEndCornerLength;
w4 = actualLeftCornerWidth; w4 = actualStartCornerLength;
w5 = actualRightCornerWidth; w5 = actualEndCornerLength;
w6 = actualWidth - actualLeftCornerWidth; w6 = actualLength - actualStartCornerLength;
break; break;
default: default:
throw new ArgumentOutOfRangeException("Compact"); throw new ArgumentOutOfRangeException("Compact");
} }
} }
else { else {
w3 = w4 = actualLeftCornerWidth; w3 = w4 = actualStartCornerLength;
w5 = w6 = actualRightCornerWidth; 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.Clear();
vh.AddVert(new Vector3(corner1.x, corner2.y), color, new Vector2(uv.x, uv.w)); if (axis == 0) {
vh.AddVert(new Vector3(corner1.x, corner1.y), color, new Vector2(uv.x, uv.y)); vh.AddVert(new Vector3(corner1.x, corner2.y), color, new Vector2(uv.x, uv.w));
vh.AddVert(new Vector3(corner1.x + w3, corner2.y), color, new Vector2(uv.x + actualLeftUVWidth, uv.w)); vh.AddVert(new Vector3(corner1.x, corner1.y), color, new Vector2(uv.x, uv.y));
vh.AddVert(new Vector3(corner1.x + w4, corner1.y), color, new Vector2(uv.x + actualLeftUVWidth, uv.y)); vh.AddVert(new Vector3(corner1.x + w3, corner2.y), color, new Vector2(uv.x + actualStartUVWidth, uv.w));
vh.AddVert(new Vector3(corner2.x - w5, corner2.y), color, new Vector2(uv.z - actualRightUVWidth, 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 - w6, corner1.y), color, new Vector2(uv.z - actualRightUVWidth, 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, corner2.y), color, new Vector2(uv.z, 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, corner1.y), color, new Vector2(uv.z, 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) { if (((int)Compact & 0x1) == 0) {
vh.AddTriangle(2, 1, 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() { private void OnFrameUpdate() {
if (!initialized) return; if (!initialized) return;
if (lines != null) for (int i = 0; i < lines.Length; i++) if (lines != null) {
if (lines[i] != null) foreach (GameObject c in lines[i]) for (int i = 0; i < lines.Length; i++) {
GameObject.Destroy(c); if (lines[i] != null) {
foreach (GameObject c in lines[i]) Destroy(c);
}
}
}
lines = new GameObject[VisibleLines][]; lines = new GameObject[VisibleLines][];
refl = new int[VisibleLines]; refl = new int[VisibleLines];
for (int i = 0; i < refl.Length; i++) refl[i] = i; for (int i = 0; i < refl.Length; i++) refl[i] = i;
@@ -153,8 +157,9 @@ namespace Cryville.Common.Unity.UI {
private void ResetLines() { private void ResetLines() {
for (int i = 0; i < lines.Length; i++) { for (int i = 0; i < lines.Length; i++) {
if (lines[i] != null) foreach (GameObject c in lines[i]) if (lines[i] != null) {
GameObject.Destroy(c); foreach (GameObject c in lines[i]) Destroy(c);
}
lines[i] = new GameObject[LineItemCount]; lines[i] = new GameObject[LineItemCount];
GenerateLine(i, refl[i]); GenerateLine(i, refl[i]);
} }
@@ -200,7 +205,7 @@ namespace Cryville.Common.Unity.UI {
void GenerateLine(int index, int line) { void GenerateLine(int index, int line) {
for (int j = 0; j < LineItemCount; j++) { 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; lines[index][j] = child;
} }
LoadLine(index, line); 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,6 +1,8 @@
using Cryville.Common.Font; using Cryville.Common.Font;
using Cryville.Culture;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization;
using System.Reflection; using System.Reflection;
using TMPro; using TMPro;
using UnityEngine; using UnityEngine;
@@ -22,19 +24,21 @@ namespace Cryville.Common.Unity.UI {
if (FontMatcher == null) return; if (FontMatcher == null) return;
_text = GetComponent<TextMeshProUGUI>(); _text = GetComponent<TextMeshProUGUI>();
if (_font == null) { if (_font == null) {
foreach (var typeface in FontMatcher.MatchScript(null, true)) { foreach (var typeface in FontMatcher.MatchLanguage(new LanguageId(CultureInfo.CurrentCulture.Name), true)) {
try { try {
var ifont = CreateFontAsset(typeface.File.FullName, typeface.IndexInFile); var ifont = CreateFontAsset(typeface.File.FullName, typeface.IndexInFile);
if (m_shader) ifont.material.shader = m_shader; if (m_shader) ifont.material.shader = m_shader;
else if (DefaultShader) ifont.material.shader = DefaultShader; else if (DefaultShader) ifont.material.shader = DefaultShader;
if (_font == null) { if (_font == null) {
_font = ifont; _font = ifont;
Shared.Logger.Log(1, "UI", "Using main font: {0}", typeface.FullName);
if (MaxFallbackCount <= 0) break; if (MaxFallbackCount <= 0) break;
} }
else { else {
if (_font.fallbackFontAssetTable == null) if (_font.fallbackFontAssetTable == null)
_font.fallbackFontAssetTable = new List<FontAsset>(); _font.fallbackFontAssetTable = new List<FontAsset>();
_font.fallbackFontAssetTable.Add(ifont); _font.fallbackFontAssetTable.Add(ifont);
Shared.Logger.Log(1, "UI", "Using fallback font #{0}: {1}", _font.fallbackFontAssetTable.Count, typeface.FullName);
if (_font.fallbackFontAssetTable.Count >= MaxFallbackCount) break; 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.Common.Collections.Specialized;
using Cryville.Crtr.Skin;
using UnityEngine; using UnityEngine;
namespace Cryville.Crtr { namespace Cryville.Crtr {

View File

@@ -1,21 +0,0 @@
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; }
public string Name { get; set; }
public string DescriptionMain { get; set; }
public string DescriptionSub { get; set; }
}
}

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,4 +1,3 @@
using Cryville.Common.Logging;
using Cryville.Crtr.Extension; using Cryville.Crtr.Extension;
using Mono.Cecil; using Mono.Cecil;
using System; using System;
@@ -36,7 +35,7 @@ namespace Cryville.Crtr.Browsing {
modules.Enqueue(new ModuleItem(extension.OpenRead())); modules.Enqueue(new ModuleItem(extension.OpenRead()));
} }
catch (Exception ex) { catch (Exception ex) {
Logger.Log("main", 4, "Extension", "Failed to load DLL {0}: {1}", extension, ex); Game.MainLogger.Log(4, "Extension", "Failed to load DLL {0}: {1}", extension, ex);
} }
} }
} }
@@ -68,10 +67,10 @@ namespace Cryville.Crtr.Browsing {
LoadExtension(type); LoadExtension(type);
} }
} }
Logger.Log("main", 1, "Extension", "Loaded module {0}", module.Definition.Name); Game.MainLogger.Log(1, "Extension", "Loaded module {0}", module.Definition.Name);
} }
catch (Exception ex) { catch (Exception ex) {
Logger.Log("main", 4, "Extension", "An error occurred while trying to load module {0}: {1}", module.Definition.Name, ex); Game.MainLogger.Log(4, "Extension", "An error occurred while trying to load module {0}: {1}", module.Definition.Name, ex);
} }
finally { finally {
module.Definition.Dispose(); module.Definition.Dispose();
@@ -89,7 +88,7 @@ namespace Cryville.Crtr.Browsing {
missingList.Add(reference.Name); missingList.Add(reference.Name);
} }
} }
Logger.Log("main", 4, "Extension", "Could not load the module {0} because the following dependencies were missing: {1}", module.Definition.Name, missingList.Aggregate((current, next) => current + ", " + next)); Game.MainLogger.Log(4, "Extension", "Could not load the module {0} because the following dependencies were missing: {1}", module.Definition.Name, missingList.Aggregate((current, next) => current + ", " + next));
module.Definition.Dispose(); module.Definition.Dispose();
module.Stream.Dispose(); module.Stream.Dispose();
} }
@@ -128,10 +127,10 @@ namespace Cryville.Crtr.Browsing {
if (name != null && path != null) _localRes.Add(name, path); if (name != null && path != null) _localRes.Add(name, path);
} }
} }
Logger.Log("main", 1, "Extension", "Loaded extension {0}", type); Game.MainLogger.Log(1, "Extension", "Loaded extension {0}", type);
} }
catch (Exception ex) { catch (Exception ex) {
Logger.Log("main", 4, "Extension", "Failed to load extension {0}: {1}", type, ex); Game.MainLogger.Log(4, "Extension", "Failed to load extension {0}: {1}", type, ex);
} }
} }
} }

View File

@@ -1,17 +1,22 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace Cryville.Crtr.Browsing { namespace Cryville.Crtr.Browsing {
public interface IResourceManager<T> { public interface IResourceManager<T> : IReadOnlyList<T> {
string[] CurrentDirectory { get; } Uri GetItemUri(int id);
int ChangeDirectory(string[] dir);
int OpenDirectory(int id);
int ReturnToDirectory(int id);
ResourceItemMeta GetItemMeta(int id);
T GetItemDetail(int id);
string GetItemPath(int id);
bool ImportItemFrom(string path); bool ImportItemFrom(Uri uri);
[Obsolete]
string[] GetSupportedFormats(); string[] GetSupportedFormats();
[Obsolete]
IReadOnlyDictionary<string, string> GetPresetPaths(); 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 index);
} }
} }

View File

@@ -3,119 +3,118 @@ using Cryville.Common.Unity;
using Cryville.Crtr.Extension; using Cryville.Crtr.Extension;
using Cryville.Crtr.Extensions; using Cryville.Crtr.Extensions;
using Cryville.Crtr.Extensions.Umg; using Cryville.Crtr.Extensions.Umg;
using Cryville.Crtr.UI;
using Newtonsoft.Json; using Newtonsoft.Json;
using System; using System;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using UnityEngine; using UnityEngine;
using Logger = Cryville.Common.Logging.Logger;
namespace Cryville.Crtr.Browsing { namespace Cryville.Crtr.Browsing {
internal class LegacyResourceManager : IResourceManager<ChartDetail> { internal class LegacyResourceManager : IPathedResourceManager<ChartDetail> {
private readonly string _rootPath; readonly string _rootPath;
private DirectoryInfo cd; DirectoryInfo _cd;
private DirectoryInfo[] items = new DirectoryInfo[0]; readonly FileSystemWatcher _watcher = new FileSystemWatcher();
DirectoryInfo[] _items = new DirectoryInfo[0];
public string[] CurrentDirectory { get; private set; } public string[] CurrentDirectory { get; private set; }
public int Count { get { return _items.Length; } }
static bool _init; static bool _init;
public event Action ItemChanged;
int _version;
public LegacyResourceManager(string rootPath) { public LegacyResourceManager(string rootPath) {
_rootPath = rootPath; _rootPath = rootPath;
if (!_init) { if (!_init) {
_init = true; _init = true;
ExtensionManager.Init(rootPath); ExtensionManager.Init(rootPath);
} }
_watcher.Changed += OnFileChanged;
_watcher.Created += OnFileChanged;
_watcher.Deleted += OnFileChanged;
_watcher.Renamed += OnFileChanged;
_watcher.Error += OnFileWatcherError;
} }
public int ChangeDirectory(string[] dir) { void OnFileWatcherError(object sender, ErrorEventArgs e) {
Game.MainLogger.Log(4, "Data", "An error occurred while watching file changes: {0}", e.GetException());
}
void OnFileChanged(object sender, FileSystemEventArgs e) {
ReloadFiles();
}
void ReloadFiles() {
_items = _cd.GetDirectories();
_version++;
ItemChanged?.Invoke();
}
public void ChangeDirectory(string[] dir) {
CurrentDirectory = dir; CurrentDirectory = dir;
cd = new DirectoryInfo(_rootPath + "/charts/" + string.Join("/", dir)); string path = Path.Combine(_rootPath, "charts", Path.Combine(dir));
items = cd.GetDirectories(); _cd = new DirectoryInfo(path);
return items.Length; _watcher.Path = path;
_watcher.EnableRaisingEvents = true;
ReloadFiles();
} }
public int OpenDirectory(int id) { public void OpenDirectory(int id) {
string[] nd = new string[CurrentDirectory.Length + 1]; string[] nd = new string[CurrentDirectory.Length + 1];
Array.Copy(CurrentDirectory, nd, CurrentDirectory.Length); Array.Copy(CurrentDirectory, nd, CurrentDirectory.Length);
nd[CurrentDirectory.Length] = items[id].Name; nd[CurrentDirectory.Length] = _items[id].Name;
return ChangeDirectory(nd); ChangeDirectory(nd);
} }
public int ReturnToDirectory(int id) { public void ReturnToDirectory(int index) {
string[] nd = new string[id + 1]; string[] nd = new string[index + 1];
Array.Copy(CurrentDirectory, nd, id + 1); Array.Copy(CurrentDirectory, nd, index + 1);
return ChangeDirectory(nd); ChangeDirectory(nd);
} }
public ResourceItemMeta GetItemMeta(int id) { public ChartDetail this[int index] {
var item = items[id]; get {
var item = _items[index];
ChartMeta meta = null;
AsyncDelivery<Texture2D> cover = null;
var metaFile = new FileInfo(Path.Combine(item.FullName, ".umgc"));
if (metaFile.Exists) {
using (var reader = new StreamReader(metaFile.FullName)) {
meta = JsonConvert.DeserializeObject<ChartMeta>(reader.ReadToEnd());
}
if (meta.cover != null && meta.cover != "") {
var coverFile = item.GetFiles(meta.cover);
if (coverFile.Length > 0) {
cover = new AsyncDelivery<Texture2D>();
var task = new LoadTextureTask(PlatformConfig.FileProtocolPrefix + coverFile[0].FullName, cover.Deliver);
cover.CancelSource = task.Cancel;
Game.NetworkTaskWorker.SubmitNetworkTask(task);
}
}
}
return new ChartDetail {
Cover = cover,
Meta = meta,
};
}
}
public Uri GetItemUri(int id) {
var item = _items[id];
var meta = new ChartMeta(); var meta = new ChartMeta();
string name = item.Name; var metaFile = new FileInfo(Path.Combine(item.FullName, ".umgc"));
string desc = "(Unknown)";
var metaFile = new FileInfo(item.FullName + "/.umgc");
if (metaFile.Exists) {
using (var reader = new StreamReader(metaFile.FullName)) {
meta = JsonConvert.DeserializeObject<ChartMeta>(reader.ReadToEnd());
name = meta.song.name;
desc = meta.name;
}
}
AsyncDelivery<Texture2D> cover = null;
if (meta.cover != null && meta.cover != "") {
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);
cover.CancelSource = task.Cancel;
Game.NetworkTaskWorker.SubmitNetworkTask(task);
}
}
return new ResourceItemMeta {
IsDirectory = false,
Icon = cover,
Name = name,
DescriptionMain = desc,
};
}
public ChartDetail GetItemDetail(int id) {
var item = items[id];
var meta = new ChartMeta();
var metaFile = new FileInfo(item.FullName + "/.umgc");
if (metaFile.Exists) {
using (var reader = new StreamReader(metaFile.FullName)) {
meta = JsonConvert.DeserializeObject<ChartMeta>(reader.ReadToEnd());
}
}
AsyncDelivery<Texture2D> cover = null;
if (meta.cover != null && meta.cover != "") {
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);
cover.CancelSource = task.Cancel;
Game.NetworkTaskWorker.SubmitNetworkTask(task);
}
}
return new ChartDetail {
Cover = cover,
Meta = meta,
};
}
public string GetItemPath(int id) {
var item = items[id];
var meta = new ChartMeta();
var metaFile = new FileInfo(item.FullName + "/.umgc");
using (var reader = new StreamReader(metaFile.FullName)) { using (var reader = new StreamReader(metaFile.FullName)) {
meta = JsonConvert.DeserializeObject<ChartMeta>(reader.ReadToEnd()); meta = JsonConvert.DeserializeObject<ChartMeta>(reader.ReadToEnd());
} }
return string.Format("{0}/{1}.json", items[id].Name, meta.data); return new Uri(Path.Combine(_items[id].Name, string.Format("{0}.json", meta.data)));
} }
public bool ImportItemFrom(string path) { public bool ImportItemFrom(Uri uri) {
var file = new FileInfo(path); if (!uri.IsFile) throw new NotSupportedException();
var file = new FileInfo(uri.LocalPath);
IEnumerable<ResourceConverter> converters; IEnumerable<ResourceConverter> converters;
if (!ExtensionManager.TryGetConverters(file.Extension, out converters)) return false; if (!ExtensionManager.TryGetConverters(file.Extension, out converters)) return false;
foreach (var converter in converters) { foreach (var converter in converters) {
@@ -136,12 +135,12 @@ namespace Cryville.Crtr.Browsing {
} }
else if (res is RawChartResource) { else if (res is RawChartResource) {
var tres = (RawChartResource)res; var tres = (RawChartResource)res;
var dir = new DirectoryInfo(_rootPath + "/charts/" + res.Name); var dir = new DirectoryInfo(Path.Combine(_rootPath, "charts", res.Name));
if (!dir.Exists) dir.Create(); if (!dir.Exists) dir.Create();
using (var writer = new StreamWriter(dir.FullName + "/.json")) { using (var writer = new StreamWriter(Path.Combine(dir.FullName, ".json"))) {
writer.Write(JsonConvert.SerializeObject(ConvertChartData(tres.Main), Game.GlobalJsonSerializerSettings)); writer.Write(JsonConvert.SerializeObject(ConvertChartData(tres.Main), Game.GlobalJsonSerializerSettings));
} }
using (var writer = new StreamWriter(dir.FullName + "/.umgc")) { using (var writer = new StreamWriter(Path.Combine(dir.FullName, ".umgc"))) {
tres.Meta.data = ""; tres.Meta.data = "";
writer.Write(JsonConvert.SerializeObject(tres.Meta, Game.GlobalJsonSerializerSettings)); writer.Write(JsonConvert.SerializeObject(tres.Meta, Game.GlobalJsonSerializerSettings));
} }
@@ -156,18 +155,18 @@ namespace Cryville.Crtr.Browsing {
DirectoryInfo dest; DirectoryInfo dest;
bool singleFileFlag = false; bool singleFileFlag = false;
if (res is ChartResource) if (res is ChartResource)
dest = new DirectoryInfo(_rootPath + "/charts/" + res.Name); dest = new DirectoryInfo(Path.Combine(_rootPath, "charts", res.Name));
else if (res is ExtensionResource) { else if (res is ExtensionResource) {
dest = new DirectoryInfo(_rootPath + "/extensions"); dest = new DirectoryInfo(Path.Combine(_rootPath, "extensions"));
singleFileFlag = true; singleFileFlag = true;
Popup.Create("Please restart the game to reload the extensions"); Popup.Create("Please restart the game to reload the extensions");
} }
else if (res is RulesetResource) else if (res is RulesetResource)
dest = new DirectoryInfo(_rootPath + "/rulesets/" + res.Name); dest = new DirectoryInfo(Path.Combine(_rootPath, "rulesets", res.Name));
else if (res is SkinResource) else if (res is SkinResource)
dest = new DirectoryInfo(_rootPath + "/skins/" + (res as SkinResource).RulesetName + "/" + res.Name); dest = new DirectoryInfo(Path.Combine(_rootPath, "skins", (res as SkinResource).RulesetName, res.Name));
else if (res is SongResource) else if (res is SongResource)
dest = new DirectoryInfo(_rootPath + "/songs/" + res.Name); dest = new DirectoryInfo(Path.Combine(_rootPath, "songs", res.Name));
else { else {
LogAndPopup(3, "Attempt to import unsupported file resource: {0}", res); LogAndPopup(3, "Attempt to import unsupported file resource: {0}", res);
continue; continue;
@@ -191,15 +190,57 @@ namespace Cryville.Crtr.Browsing {
return false; return false;
} }
Enumerator GetEnumerator() { return new Enumerator(this); }
IEnumerator<ChartDetail> IEnumerable<ChartDetail>.GetEnumerator() { return GetEnumerator(); }
IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); }
public struct Enumerator : IEnumerator<ChartDetail> {
readonly LegacyResourceManager _list;
int _index;
readonly int _version;
ChartDetail _current;
public ChartDetail Current => _current;
object IEnumerator.Current => Current;
public Enumerator(LegacyResourceManager list) {
_list = list;
_index = 0;
_version = list._version;
_current = default(ChartDetail);
}
public void Dispose() { }
public bool MoveNext() {
LegacyResourceManager list = _list;
if (_version != list._version)
throw new InvalidOperationException("Collection was changed.");
if (_index < list.Count) {
_current = list[_index++];
return true;
}
else {
_current = default(ChartDetail);
return false;
}
}
void IEnumerator.Reset() {
if (_version != _list._version)
throw new InvalidOperationException("Collection was changed.");
_index = 0;
_current = default(ChartDetail);
}
}
void LogAndPopup(int level, string format, params object[] args) { void LogAndPopup(int level, string format, params object[] args) {
var msg = string.Format(format, args); var msg = string.Format(format, args);
Logger.Log("main", level, "Resource", msg); Game.MainLogger.Log(level, "Resource", msg);
Popup.Create(msg); Popup.Create(msg);
} }
void LogAndPopupExtra(int level, object extraLog, string format, params object[] args) { void LogAndPopupExtra(int level, object extraLog, string format, params object[] args) {
var msg = string.Format(format, args); var msg = string.Format(format, args);
Logger.Log("main", level, "Resource", "{0}\n{1}", msg, extraLog); Game.MainLogger.Log(level, "Resource", "{0}\n{1}", msg, extraLog);
Popup.Create(msg); Popup.Create(msg);
} }

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

@@ -1,8 +1,8 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 8a36c371ab6077d43ac28fe09b0fe675 guid: ba8a8b6df16a9714f9785aba6adc0427
timeCreated: 1620725915 folderAsset: yes
licenseType: Free
DefaultImporter: DefaultImporter:
externalObjects: {}
userData: userData:
assetBundleName: assetBundleName:
assetBundleVariant: 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 ChartDetail meta;
internal void Load(int id, ChartDetail 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,80 @@
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
[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.Cover != null) meta.Cover.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) {
m_icon.sprite = m_iconPlaceholder;
if (meta.Cover != null) meta.Cover.Destination = DisplayCover;
if (meta.Meta != null) {
m_title.text = meta.Meta.song.name;
m_desc.text = meta.Meta.name;
}
else {
m_title.text = "<color=#ff0000>Invalid resource</color>";
m_desc.text = string.Empty;
}
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>();
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,71 @@
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;
if (meta != null) {
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
);
}
else {
m_title.text = "<color=#ff0000>Invalid resource</color>";
m_desc.text = string.Empty;
}
}
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;
using UnityEngine.UI; using UnityEngine.UI;
namespace Cryville.Crtr.Browsing { namespace Cryville.Crtr.Browsing.UI {
internal class PathPart : MonoBehaviour { internal class PathPart : MonoBehaviour {
private int _id; private int _id;
private Text _exp; private Text _exp;
@@ -21,7 +21,7 @@ namespace Cryville.Crtr.Browsing {
else return exp; else return exp;
} }
public void OnClick() { 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,91 @@
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>();
[Obsolete]
FileDialog _dialog;
protected virtual void Start() {
ItemContainer.LoadItem = LoadItem;
ResourceManager.ItemChanged += OnItemChanged;
ResourceManager.ChangeDirectory(new string[] { "" });
InitDialog();
}
[Obsolete]
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;
}
bool _itemChanged;
void OnItemChanged() { _itemChanged = true; }
void Update() {
if (_itemChanged) {
_itemChanged = false;
_selectedItems.Clear();
_items.Clear();
ItemContainer.ItemCount = ResourceManager.Count;
}
}
private bool LoadItem(int id, GameObject obj) {
var bi = obj.GetComponent<BrowserItem>();
_items[id] = bi;
try {
var item = ResourceManager[id];
bi.Load(id, item, _selectedItems.Contains(id));
}
catch (Exception) {
bi.Load(id, default(ChartDetail), _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[id]);
}
public void OnPathClicked(int index) {
ResourceManager.ReturnToDirectory(index);
}
[Obsolete]
public void OnAddButtonClicked() {
_dialog.Show();
}
[Obsolete]
private void OnAddDialogClosed() {
if (_dialog.FileName == null) return;
if (ResourceManager.ImportItemFrom(new Uri(_dialog.FileName))) {
Popup.Create("Import succeeded");
}
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; using UnityEngine;
namespace Cryville.Crtr.Browsing { namespace Cryville.Crtr.Browsing.UI {
public abstract class ResourceBrowserUnit : MonoBehaviour { public abstract class ResourceBrowser : MonoBehaviour {
[SerializeField]
Sprite m_icon;
public Sprite Icon { get { return m_icon; } }
protected ResourceBrowserMaster Master { get; private set; } protected ResourceBrowserMaster Master { get; private set; }
protected virtual void Awake() { protected virtual void Awake() {
Master = GetComponentInParent<ResourceBrowserMaster>(); 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.GetItemUri(id).LocalPath;
}
}
}

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;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
namespace Cryville.Crtr { namespace Cryville.Crtr {
public static class GenericResources { public static class BuiltinResources {
public static Dictionary<string, Type> Components public static Dictionary<string, Type> Components
= new Dictionary<string, Type>(); = new Dictionary<string, Type>();
public static Dictionary<string, Shader> Shaders public static Dictionary<string, Shader> Shaders

View File

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

View File

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

View File

@@ -1,9 +1,11 @@
#define BUILD
using Cryville.Common; using Cryville.Common;
using Cryville.Common.Buffers; using Cryville.Common.Buffers;
using Cryville.Common.Logging;
using Cryville.Crtr.Config; using Cryville.Crtr.Config;
using Cryville.Crtr.Event; using Cryville.Crtr.Event;
using Cryville.Crtr.Ruleset;
using Cryville.Crtr.Skin;
using Cryville.Crtr.UI;
using Newtonsoft.Json; using Newtonsoft.Json;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@@ -17,16 +19,15 @@ using UnityEngine.Networking;
using UnityEngine.SceneManagement; using UnityEngine.SceneManagement;
using UnityEngine.Scripting; using UnityEngine.Scripting;
using Coroutine = Cryville.Common.Coroutine; using Coroutine = Cryville.Common.Coroutine;
using Logger = Cryville.Common.Logging.Logger;
using Stopwatch = System.Diagnostics.Stopwatch; using Stopwatch = System.Diagnostics.Stopwatch;
namespace Cryville.Crtr { namespace Cryville.Crtr {
public class ChartPlayer : MonoBehaviour { public class ChartPlayer : MonoBehaviour {
#region Fields #region Fields
Chart chart; Chart chart;
Skin skin; SkinDefinition skin;
public static PdtSkin pskin; public static PdtSkin pskin;
Ruleset ruleset; RulesetDefinition ruleset;
PdtRuleset pruleset; PdtRuleset pruleset;
Dictionary<string, Texture2D> texs; Dictionary<string, Texture2D> texs;
public static Dictionary<string, SpriteFrame> frames; public static Dictionary<string, SpriteFrame> frames;
@@ -43,6 +44,7 @@ namespace Cryville.Crtr {
static bool initialized; static bool initialized;
TextMeshProUGUI logs; TextMeshProUGUI logs;
TextMeshProUGUI status; TextMeshProUGUI status;
BufferedLoggerListener loggerListener;
static Vector2 screenSize; static Vector2 screenSize;
public static Rect hitRect; public static Rect hitRect;
@@ -62,27 +64,26 @@ namespace Cryville.Crtr {
public static float sv = 16f; public static float sv = 16f;
public static Dictionary<Identifier, MotionRegistry> motionRegistry; public static Dictionary<Identifier, MotionRegistry> motionRegistry;
public static PdtEvaluator etor;
#endregion #endregion
#region MonoBehaviour #region MonoBehaviour
void Start() { void Start() {
d_addLogEntry = new Action<int, string, string>(AddLogEntry); d_addLogEntry = AddLogEntry;
var logobj = GameObject.Find("Logs"); var logobj = GameObject.Find("Logs");
if (logobj != null) if (logobj != null)
logs = logobj.GetComponent<TextMeshProUGUI>(); logs = logobj.GetComponent<TextMeshProUGUI>();
if (!initialized) { if (!initialized) {
Game.Init(); Game.Init();
GenericResources.LoadDefault(); BuiltinResources.LoadDefault();
initialized = true; initialized = true;
} }
OnSettingsUpdate(); OnSettingsUpdate();
status = GameObject.Find("Status").GetComponent<TextMeshProUGUI>(); status = GameObject.Find("Status").GetComponent<TextMeshProUGUI>();
loggerListener = new BufferedLoggerListener();
Game.MainLogger.AddListener(loggerListener);
#if BUILD
try { try {
Play(); Play();
} }
@@ -91,7 +92,6 @@ namespace Cryville.Crtr {
Popup.CreateException(ex); Popup.CreateException(ex);
ReturnToMenu(); ReturnToMenu();
} }
#endif
// Camera.main.RenderToCubemap(); // Camera.main.RenderToCubemap();
} }
@@ -104,6 +104,8 @@ namespace Cryville.Crtr {
if (loadThread != null) loadThread.Abort(); if (loadThread != null) loadThread.Abort();
if (inputProxy != null) inputProxy.Dispose(); if (inputProxy != null) inputProxy.Dispose();
if (texs != null) foreach (var t in texs) Texture.Destroy(t.Value); if (texs != null) foreach (var t in texs) Texture.Destroy(t.Value);
Game.MainLogger.RemoveListener(loggerListener);
loggerListener.Dispose();
GC.Collect(); GC.Collect();
} }
@@ -130,7 +132,7 @@ namespace Cryville.Crtr {
} }
else if (loadThread != null) LoadUpdate(); else if (loadThread != null) LoadUpdate();
if (logEnabled) LogUpdate(); if (logEnabled) LogUpdate();
else Game.MainLogger.Enumerate((level, module, msg) => { }); else loggerListener.Enumerate((level, module, msg) => { });
} }
void GameUpdate() { void GameUpdate() {
try { try {
@@ -183,12 +185,10 @@ namespace Cryville.Crtr {
if (!texloaddone) texLoader.Tick(1.0 / Application.targetFrameRate); if (!texloaddone) texLoader.Tick(1.0 / Application.targetFrameRate);
if (!loadThread.IsAlive) { if (!loadThread.IsAlive) {
if (threadException != null) { if (threadException != null) {
Logger.Log("main", 4, "Load/MainThread", "Load failed"); Game.MainLogger.Log(4, "Load/MainThread", "Load failed");
loadThread = null; loadThread = null;
Popup.CreateException(threadException); Popup.CreateException(threadException);
#if BUILD
ReturnToMenu(); ReturnToMenu();
#endif
} }
else if (texloaddone) { else if (texloaddone) {
if (texLoader == null) Stop(); if (texLoader == null) Stop();
@@ -206,7 +206,7 @@ namespace Cryville.Crtr {
readonly StringBuffer logsbuf = new StringBuffer(); readonly StringBuffer logsbuf = new StringBuffer();
readonly List<string> logEntries = new List<string>(); readonly List<string> logEntries = new List<string>();
int logsLength = 0; int logsLength = 0;
Action<int, string, string> d_addLogEntry; LogHandler d_addLogEntry;
void AddLogEntry(int level, string module, string msg) { void AddLogEntry(int level, string module, string msg) {
string color; string color;
switch (level) { switch (level) {
@@ -227,7 +227,7 @@ namespace Cryville.Crtr {
} }
void LogUpdate() { void LogUpdate() {
logsbuf.Clear(); logsbuf.Clear();
Game.MainLogger.Enumerate(d_addLogEntry); loggerListener.Enumerate(d_addLogEntry);
while (logsLength >= 4096) { while (logsLength >= 4096) {
logsLength -= logEntries[0].Length; logsLength -= logEntries[0].Length;
logEntries.RemoveAt(0); logEntries.RemoveAt(0);
@@ -273,12 +273,12 @@ namespace Cryville.Crtr {
"\nStates: c{0} / b{1}", "\nStates: c{0} / b{1}",
cbus.ActiveStateCount, bbus.ActiveStateCount cbus.ActiveStateCount, bbus.ActiveStateCount
); );
var aTime = Game.AudioClient.Position; var aTime = Game.AudioClient.Position - atime0;
var iTime = inputProxy.GetTimestampAverage(); var iTime = inputProxy.GetTimestampAverage();
statusbuf.AppendFormat( 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}", "\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, cbus.Time, aTime, iTime,
(aTime - atime0 - cbus.Time) * 1e3, (aTime - cbus.Time) * 1e3,
(iTime - cbus.Time) * 1e3, (iTime - cbus.Time) * 1e3,
forceSyncFrames != 0 ? "(force sync)" : "", forceSyncFrames != 0 ? "(force sync)" : "",
paused ? "(paused)" : "", paused ? "(paused)" : "",
@@ -340,7 +340,7 @@ namespace Cryville.Crtr {
texloaddone = true; texloaddone = true;
texLoader = null; texLoader = null;
if (loadThread.IsAlive) { if (loadThread.IsAlive) {
Logger.Log("main", 2, "Game", "Stop requested while the chart is loading. Waiting for the loading thread to exit..."); Game.MainLogger.Log(2, "Game", "Stop requested while the chart is loading. Waiting for the loading thread to exit...");
} }
} }
else { else {
@@ -355,19 +355,25 @@ namespace Cryville.Crtr {
forceSyncFrames = Settings.Default.ForceSyncFrames; forceSyncFrames = Settings.Default.ForceSyncFrames;
Game.AudioClient.Start(); Game.AudioClient.Start();
inputProxy.UnlockTime(); inputProxy.UnlockTime();
#if !UNITY_ANDROID || UNITY_EDITOR
DiscordController.Instance.SetResume(cbus.Time);
#endif
} }
else { else {
Game.AudioClient.Pause(); Game.AudioClient.Pause();
inputProxy.LockTime(); inputProxy.LockTime();
#if !UNITY_ANDROID || UNITY_EDITOR
DiscordController.Instance.SetPaused();
#endif
} }
} }
#endregion #endregion
#region Load #region Load
void Play() { void Play() {
disableGC = Settings.Default.DisableGC; disableGC = Settings.Default.DisableGC;
clippingDist = Settings.Default.BackwardClippingDistance; clippingDist = Settings.Default.BackwardRenderDistance;
renderDist = Settings.Default.RenderDistance; renderDist = Settings.Default.ForwardRenderDistance;
renderStep = Settings.Default.RenderStep; renderStep = Settings.Default.RenderStep;
actualRenderStep = renderStep; actualRenderStep = renderStep;
autoRenderStep = renderStep == 0; autoRenderStep = renderStep == 0;
@@ -377,7 +383,7 @@ namespace Cryville.Crtr {
areaJudgePrecision = 1 << Settings.Default.AreaJudgePrecision; areaJudgePrecision = 1 << Settings.Default.AreaJudgePrecision;
forceSyncFrames = Settings.Default.ForceSyncFrames; forceSyncFrames = Settings.Default.ForceSyncFrames;
texloaddone = false; texloaddone = false;
Game.NetworkTaskWorker.SuspendBackgroundTasks(); Game.SuspendBackgroundTasks();
Game.AudioSession = Game.AudioSequencer.NewSession(); Game.AudioSession = Game.AudioSequencer.NewSession();
var hitPlane = new Plane(Vector3.forward, Vector3.zero); var hitPlane = new Plane(Vector3.forward, Vector3.zero);
@@ -419,10 +425,10 @@ namespace Cryville.Crtr {
); );
if (!skinFile.Exists) throw new FileNotFoundException("Skin not found\nPlease specify an available skin in the config"); 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)) { 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 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)); loadThread = new Thread(new ParameterizedThreadStart(Load));
@@ -432,7 +438,7 @@ namespace Cryville.Crtr {
skinFile = skinFile, skinFile = skinFile,
}); });
Logger.Log("main", 0, "Load/MainThread", "Loading textures..."); Game.MainLogger.Log(0, "Load/MainThread", "Loading textures...");
frames = new Dictionary<string, SpriteFrame>(); frames = new Dictionary<string, SpriteFrame>();
texs = new Dictionary<string, Texture2D>(); texs = new Dictionary<string, Texture2D>();
var skinDir = skinFile.Directory.FullName; var skinDir = skinFile.Directory.FullName;
@@ -455,7 +461,7 @@ namespace Cryville.Crtr {
for (int i = 0; i < queue.Count; i++) { for (int i = 0; i < queue.Count; i++) {
#if UNITY_5_4_OR_NEWER #if UNITY_5_4_OR_NEWER
texHandler = new DownloadHandlerTexture(); 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(); texLoader.SendWebRequest();
#else #else
texLoader = new WWW(Game.FileProtocolPrefix + queue[i]); texLoader = new WWW(Game.FileProtocolPrefix + queue[i]);
@@ -468,7 +474,7 @@ namespace Cryville.Crtr {
var tex = texHandler.texture; var tex = texHandler.texture;
tex.wrapMode = TextureWrapMode.Clamp; tex.wrapMode = TextureWrapMode.Clamp;
if (frames.ContainsKey(name)) { if (frames.ContainsKey(name)) {
Logger.Log("main", 3, "Load/Prehandle", "Duplicated texture name: {0}", name); Game.MainLogger.Log(3, "Load/Prehandle", "Duplicated texture name: {0}", name);
} }
else { else {
frames.Add(name, new SpriteFrame(tex)); frames.Add(name, new SpriteFrame(tex));
@@ -476,7 +482,7 @@ namespace Cryville.Crtr {
texs.Add(name, tex); texs.Add(name, tex);
} }
else { else {
Logger.Log("main", 4, "Load/Prehandle", "Unable to load texture: {0}", name); Game.MainLogger.Log(4, "Load/Prehandle", "Unable to load texture: {0}", name);
} }
texLoader.Dispose(); texLoader.Dispose();
texHandler.Dispose(); texHandler.Dispose();
@@ -492,50 +498,50 @@ namespace Cryville.Crtr {
} }
texloaddone = true; texloaddone = true;
stopwatch.Stop(); stopwatch.Stop();
Logger.Log("main", 1, "Load/MainThread", "Main thread done ({0}ms)", stopwatch.Elapsed.TotalMilliseconds); Game.MainLogger.Log(1, "Load/MainThread", "Main thread done ({0}ms)", stopwatch.Elapsed.TotalMilliseconds);
yield return 1; yield return 1;
} }
IEnumerator<float> Prehandle() { IEnumerator<float> Prehandle() {
Stopwatch timer = new Stopwatch(); Stopwatch timer = new Stopwatch();
timer.Reset(); timer.Start(); timer.Reset(); timer.Start();
Logger.Log("main", 0, "Load/Prehandle", "Prehandling (iteration 2)"); yield return .00f; Game.MainLogger.Log(0, "Load/Prehandle", "Prehandling (iteration 2)"); yield return 0;
cbus.BroadcastPreInit(); cbus.BroadcastPreInit();
Logger.Log("main", 0, "Load/Prehandle", "Prehandling (iteration 3)"); yield return .05f; Game.MainLogger.Log(0, "Load/Prehandle", "Prehandling (iteration 3)"); yield return 0;
using (var pbus = cbus.Clone(17)) { using (var pbus = cbus.Clone(17)) {
while (pbus.Time != double.PositiveInfinity) { while (pbus.Time != double.PositiveInfinity) {
pbus.ForwardOnce(); 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; Game.MainLogger.Log(0, "Load/Prehandle", "Prehandling (iteration 4)"); yield return 1;
cbus.BroadcastPostInit(); cbus.BroadcastPostInit();
Logger.Log("main", 0, "Load/Prehandle", "Seeking to start offset"); yield return .90f; Game.MainLogger.Log(0, "Load/Prehandle", "Seeking to start offset"); yield return 1;
cbus.ForwardByTime(startOffset); cbus.ForwardByTime(startOffset);
bbus.ForwardByTime(startOffset); bbus.ForwardByTime(startOffset);
Game.AudioSequencer.SeekTime(startOffset, SeekOrigin.Current); Game.AudioSequencer.SeekTime(startOffset, SeekOrigin.Current);
Logger.Log("main", 0, "Load/Prehandle", "Cleaning up"); yield return .95f; Game.MainLogger.Log(0, "Load/Prehandle", "Cleaning up"); yield return 1;
if (logEnabled && Settings.Default.HideLogOnPlay) ToggleLogs(); if (logEnabled && Settings.Default.HideLogOnPlay) ToggleLogs();
Camera.main.cullingMask |= 1; Camera.main.cullingMask |= 1;
GC.Collect(); GC.Collect();
if (disableGC) GarbageCollector.GCMode = GarbageCollector.Mode.Disabled; if (disableGC) GarbageCollector.GCMode = GarbageCollector.Mode.Disabled;
timer.Stop(); timer.Stop();
Logger.Log("main", 1, "Load/Prehandle", "Prehandling done ({0}ms)", timer.Elapsed.TotalMilliseconds); yield return 1; Game.MainLogger.Log(1, "Load/Prehandle", "Prehandling done ({0}ms)", timer.Elapsed.TotalMilliseconds); yield return 1;
if (Settings.Default.ClearLogOnPlay) { if (Settings.Default.ClearLogOnPlay) {
logEntries.Clear(); logEntries.Clear();
logsLength = 0; logsLength = 0;
Game.MainLogger.Enumerate((level, module, msg) => { }); loggerListener.Enumerate((level, module, msg) => { });
logs.text = ""; logs.text = "";
} }
Game.AudioSequencer.Playing = true; Game.AudioSequencer.Playing = true;
atime0 = Game.AudioClient.Position - startOffset; atime0 = Game.AudioClient.BufferPosition - startOffset;
inputProxy.SyncTime(cbus.Time); inputProxy.SyncTime(cbus.Time);
inputProxy.Activate(); inputProxy.Activate();
} }
public void Stop() { public void Stop() {
try { try {
Logger.Log("main", 1, "Game", "Stopping"); Game.MainLogger.Log(1, "Game", "Stopping");
Game.AudioClient.Start(); Game.AudioClient.Start();
Game.AudioSession = Game.AudioSequencer.NewSession(); Game.AudioSession = Game.AudioSequencer.NewSession();
Camera.main.cullingMask &= ~1; Camera.main.cullingMask &= ~1;
@@ -552,9 +558,9 @@ namespace Cryville.Crtr {
effectManager.Dispose(); effectManager.Dispose();
effectManager = null; effectManager = null;
} }
etor = null; PdtEvaluator.Instance.Reset();
motionRegistry = null; motionRegistry = null;
Logger.Log("main", 1, "Game", "Stopped"); Game.MainLogger.Log(1, "Game", "Stopped");
} }
catch (Exception ex) { catch (Exception ex) {
if (!logEnabled) ToggleLogs(); if (!logEnabled) ToggleLogs();
@@ -568,10 +574,8 @@ namespace Cryville.Crtr {
started = false; started = false;
} }
} }
Game.NetworkTaskWorker.ResumeBackgroundTasks(); Game.ResumeBackgroundTasks();
#if BUILD
ReturnToMenu(); ReturnToMenu();
#endif
} }
void OnSettingsUpdate() { void OnSettingsUpdate() {
@@ -588,11 +592,9 @@ namespace Cryville.Crtr {
} }
Exception threadException; Exception threadException;
#if !NO_THREAD
Thread loadThread = null; Thread loadThread = null;
volatile float loadPregress; volatile float loadPregress;
Stopwatch workerTimer; Stopwatch workerTimer;
#endif
void Load(object _info) { void Load(object _info) {
var info = (LoadInfo)_info; var info = (LoadInfo)_info;
try { try {
@@ -600,7 +602,7 @@ namespace Cryville.Crtr {
workerTimer.Start(); workerTimer.Start();
LoadChart(info); LoadChart(info);
workerTimer.Stop(); workerTimer.Stop();
Logger.Log("main", 1, "Load/WorkerThread", "Worker thread done ({0}ms)", workerTimer.Elapsed.TotalMilliseconds); Game.MainLogger.Log(1, "Load/WorkerThread", "Worker thread done ({0}ms)", workerTimer.Elapsed.TotalMilliseconds);
} }
catch (Exception ex) { catch (Exception ex) {
Game.LogException("Load/WorkerThread", "An error occurred while loading the data", ex); Game.LogException("Load/WorkerThread", "An error occurred while loading the data", ex);
@@ -609,7 +611,7 @@ namespace Cryville.Crtr {
} }
void LoadChart(LoadInfo info) { void LoadChart(LoadInfo info) {
Logger.Log("main", 0, "Load/WorkerThread", "Loading chart: {0}", info.chartFile); Game.MainLogger.Log(0, "Load/WorkerThread", "Loading chart: {0}", info.chartFile);
motionRegistry = new Dictionary<Identifier, MotionRegistry> { motionRegistry = new Dictionary<Identifier, MotionRegistry> {
{ new Identifier("pt") , new MotionRegistry(typeof(Vec2)) }, { new Identifier("pt") , new MotionRegistry(typeof(Vec2)) },
@@ -622,7 +624,7 @@ namespace Cryville.Crtr {
}; };
using (StreamReader reader = new StreamReader(info.chartFile.FullName, Encoding.UTF8)) { using (StreamReader reader = new StreamReader(info.chartFile.FullName, Encoding.UTF8)) {
etor = new PdtEvaluator(); PdtEvaluator.Instance.Reset();
LoadRuleset(info.rulesetFile); loadPregress = .05f; LoadRuleset(info.rulesetFile); loadPregress = .05f;
@@ -630,28 +632,28 @@ namespace Cryville.Crtr {
MissingMemberHandling = MissingMemberHandling.Error MissingMemberHandling = MissingMemberHandling.Error
}); });
Logger.Log("main", 0, "Load/WorkerThread", "Applying ruleset (iteration 1)"); loadPregress = .10f; Game.MainLogger.Log(0, "Load/WorkerThread", "Applying ruleset (iteration 1)"); loadPregress = .10f;
pruleset.PrePatch(chart); pruleset.PrePatch(chart);
Logger.Log("main", 0, "Load/WorkerThread", "Batching events"); loadPregress = .20f; Game.MainLogger.Log(0, "Load/WorkerThread", "Batching events"); loadPregress = .20f;
var batcher = new EventBatcher(chart); var batcher = new EventBatcher(chart);
batcher.Forward(); batcher.Forward();
cbus = batcher.Batch(); loadPregress = .30f; cbus = batcher.Batch(); loadPregress = .30f;
LoadSkin(info.skinFile); LoadSkin(info.skinFile);
Logger.Log("main", 0, "Load/WorkerThread", "Initializing judge and input"); loadPregress = .35f; Game.MainLogger.Log(0, "Load/WorkerThread", "Initializing judge and input"); loadPregress = .35f;
judge = new Judge(this, pruleset); judge = new Judge(this, pruleset);
etor.ContextJudge = judge; PdtEvaluator.Instance.ContextJudge = judge;
inputProxy = new InputProxy(pruleset, judge, screenSize); inputProxy = new InputProxy(pruleset, judge, screenSize);
inputProxy.LoadFrom(_rscfg.inputs); inputProxy.LoadFrom(_rscfg.inputs);
if (!inputProxy.IsCompleted()) { if (!inputProxy.IsCompleted()) {
Logger.Log("main", 2, "Game", "Input config not completed. Input disabled"); Game.MainLogger.Log(2, "Game", "Input config not completed. Input disabled");
inputProxy.Clear(); inputProxy.Clear();
} }
Logger.Log("main", 0, "Load/WorkerThread", "Attaching handlers"); loadPregress = .40f; Game.MainLogger.Log(0, "Load/WorkerThread", "Attaching handlers"); loadPregress = .40f;
var ch = new ChartHandler(chart); var ch = new ChartHandler(chart);
cbus.RootState.AttachHandler(ch); cbus.RootState.AttachHandler(ch);
foreach (var gs in cbus.RootState.Children) { foreach (var gs in cbus.RootState.Children) {
@@ -669,16 +671,16 @@ namespace Cryville.Crtr {
} }
} }
cbus.AttachSystems(pskin, judge); cbus.AttachSystems(pskin, judge);
Logger.Log("main", 0, "Load/WorkerThread", "Prehandling (iteration 1)"); loadPregress = .60f; Game.MainLogger.Log(0, "Load/WorkerThread", "Prehandling (iteration 1)"); loadPregress = .60f;
using (var pbus = cbus.Clone(16)) { using (var pbus = cbus.Clone(16)) {
pbus.Forward(); pbus.Forward();
} }
Logger.Log("main", 0, "Load/WorkerThread", "Cloning states (type 1)"); loadPregress = .70f; Game.MainLogger.Log(0, "Load/WorkerThread", "Cloning states (type 1)"); loadPregress = .70f;
bbus = cbus.Clone(1, -clippingDist); bbus = cbus.Clone(1, -clippingDist);
Logger.Log("main", 0, "Load/WorkerThread", "Cloning states (type 2)"); loadPregress = .80f; Game.MainLogger.Log(0, "Load/WorkerThread", "Cloning states (type 2)"); loadPregress = .80f;
tbus = bbus.Clone(2); tbus = bbus.Clone(2);
Logger.Log("main", 0, "Load/WorkerThread", "Cloning states (type 3)"); loadPregress = .90f; Game.MainLogger.Log(0, "Load/WorkerThread", "Cloning states (type 3)"); loadPregress = .90f;
nbus = bbus.Clone(3); nbus = bbus.Clone(3);
loadPregress = 1; loadPregress = 1;
} }
@@ -686,16 +688,17 @@ namespace Cryville.Crtr {
void LoadRuleset(FileInfo file) { void LoadRuleset(FileInfo file) {
DirectoryInfo dir = file.Directory; DirectoryInfo dir = file.Directory;
Logger.Log("main", 0, "Load/WorkerThread", "Loading ruleset: {0}", file); Game.MainLogger.Log(0, "Load/WorkerThread", "Loading ruleset: {0}", file);
using (StreamReader reader = new StreamReader(file.FullName, Encoding.UTF8)) { 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 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); ruleset.LoadPdt(dir);
pruleset = ruleset.Root; pruleset = ruleset.Root;
pruleset.Optimize(etor); pruleset.Optimize(PdtEvaluator.Instance);
} }
PdtEvaluator.Instance.ContextRulesetConfig = new RulesetConfigStore(pruleset.configs, _rscfg.configs);
RMVPool.Shared = new RMVPool(); RMVPool.Shared = new RMVPool();
MotionCachePool.Shared = new MotionCachePool(); MotionCachePool.Shared = new MotionCachePool();
MotionNodePool.Shared = new MotionNodePool(); MotionNodePool.Shared = new MotionNodePool();
@@ -703,10 +706,10 @@ namespace Cryville.Crtr {
void LoadSkin(FileInfo file) { void LoadSkin(FileInfo file) {
DirectoryInfo dir = file.Directory; DirectoryInfo dir = file.Directory;
Logger.Log("main", 0, "Load/WorkerThread", "Loading skin: {0}", file); Game.MainLogger.Log(0, "Load/WorkerThread", "Loading skin: {0}", file);
skin.LoadPdt(dir); skin.LoadPdt(dir);
pskin = skin.Root; pskin = skin.Root;
pskin.Optimize(etor); pskin.Optimize(PdtEvaluator.Instance);
effectManager = new EffectManager(pskin); effectManager = new EffectManager(pskin);
} }
#endregion #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")] [Category("gameplay")]
[JsonProperty("sound_offset")] [JsonProperty("sound_offset")]
[Step(0.04f)] [Step(0.04)]
[Precision(1e-3)] [Precision(1e-3)]
public float SoundOffset { get; set; } public float SoundOffset { get; set; }
[Category("deprecated")][Obsolete] [Category("deprecated")][Obsolete]
[JsonProperty("scroll_velocity")][DefaultValue(1)] [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 float ScrollVelocity { get; set; }
public Generic() { public Generic() {
@@ -29,6 +29,8 @@ namespace Cryville.Crtr.Config {
ScrollVelocity = 1; ScrollVelocity = 1;
} }
} }
public Dictionary<string, object> configs
= new Dictionary<string, object>();
public Dictionary<string, InputEntry> inputs public Dictionary<string, InputEntry> inputs
= new Dictionary<string, InputEntry>(); = new Dictionary<string, InputEntry>();
public class InputEntry { public class InputEntry {

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