Compare commits
56 Commits
0.7.1
...
c2e94afc1c
Author | SHA1 | Date | |
---|---|---|---|
c2e94afc1c | |||
e2c58c708f | |||
c52bf734d3 | |||
ca60681de7 | |||
8f3c38e273 | |||
119b87f3df | |||
2778725b91 | |||
4ca5809597 | |||
0cdd6e569e | |||
8c11be48cf | |||
9fcf6f3379 | |||
b45cf9cba7 | |||
28234d9587 | |||
1803e1dee7 | |||
166478e4bb | |||
c05b771425 | |||
9db2ded366 | |||
9aed79f599 | |||
221887e447 | |||
36013d4e47 | |||
cf8dda1ea2 | |||
0f4aec4355 | |||
ddf738ee27 | |||
bd834cff4a | |||
adf5019e2a | |||
a19a3d9b81 | |||
b50f771d6e | |||
8089e724f9 | |||
18f9fbea60 | |||
6ea487ff13 | |||
a83b16c829 | |||
b48bd7b8ba | |||
b56722b2d1 | |||
5854801a53 | |||
668f46d260 | |||
b672889008 | |||
08a12097a4 | |||
7535ce04f5 | |||
bede668e73 | |||
c2c28518ba | |||
bfa1423f64 | |||
395c094890 | |||
a284edd130 | |||
b57959b4bf | |||
724cb10bc1 | |||
97e759f57d | |||
3ce8ad72ed | |||
c23d79e3f5 | |||
71294db3c1 | |||
825818679c | |||
84acb2c12d | |||
9c034c0f7b | |||
aa7452aead | |||
f86562b2f2 | |||
8fa2bd1e81 | |||
1f58390298 |
1073
Assets/Console.unity
1073
Assets/Console.unity
File diff suppressed because it is too large
Load Diff
@@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -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();
|
||||||
|
@@ -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;
|
||||||
@@ -7,20 +7,22 @@ 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 manager) { Manager = manager; }
|
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 static Dictionary<string, List<string>> GetDefaultWindowsFallbackMap() {
|
public static Dictionary<string, List<string>> GetDefaultWindowsFallbackMap() {
|
||||||
var map = new Dictionary<string, List<string>>();
|
var map = new Dictionary<string, List<string>>(StringComparer.OrdinalIgnoreCase);
|
||||||
ScriptUtils.FillKeysWithScripts(map, () => new List<string>());
|
FillKeysWithScripts(map, () => 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
|
||||||
map["zyyy"].Insert(0, "SimSun"); // Custom
|
map[UltimateFallbackScript].Insert(0, "SimSun"); // Custom
|
||||||
map["zyyy"].Insert(0, "SimHei"); // Custom
|
map[UltimateFallbackScript].Insert(0, "SimHei"); // Custom
|
||||||
map["zyyy"].Insert(0, "Microsoft YaHei"); // Custom
|
map[UltimateFallbackScript].Insert(0, "Microsoft YaHei"); // Custom
|
||||||
map["zyyy"].Insert(0, "Arial");
|
map[UltimateFallbackScript].Insert(0, "Arial");
|
||||||
map["zyyy"].Insert(0, "Times New Roman");
|
map[UltimateFallbackScript].Insert(0, "Times New Roman");
|
||||||
map["zyyy"].Insert(0, "Segoe UI"); // Custom
|
map[UltimateFallbackScript].Insert(0, "Segoe UI"); // Custom
|
||||||
map["arab"].Insert(0, "Tahoma");
|
map["arab"].Insert(0, "Tahoma");
|
||||||
map["cyrl"].Insert(0, "Times New Roman");
|
map["cyrl"].Insert(0, "Times New Roman");
|
||||||
map["grek"].Insert(0, "Times New Roman");
|
map["grek"].Insert(0, "Times New Roman");
|
||||||
@@ -158,12 +160,12 @@ namespace Cryville.Common.Font {
|
|||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
public static Dictionary<string, List<string>> GetDefaultAndroidFallbackMap() {
|
public static Dictionary<string, List<string>> GetDefaultAndroidFallbackMap() {
|
||||||
var map = new Dictionary<string, List<string>>();
|
var map = new Dictionary<string, List<string>>(StringComparer.OrdinalIgnoreCase);
|
||||||
ScriptUtils.FillKeysWithScripts(map, () => new List<string>());
|
FillKeysWithScripts(map, () => new List<string>());
|
||||||
map["zyyy"].Insert(0, "Noto Sans CJK TC"); // TODO Modify default fallback
|
map[UltimateFallbackScript].Insert(0, "Noto Sans CJK TC"); // TODO Modify default fallback
|
||||||
map["zyyy"].Insert(0, "Noto Sans CJK JP");
|
map[UltimateFallbackScript].Insert(0, "Noto Sans CJK JP");
|
||||||
map["zyyy"].Insert(0, "Noto Sans CJK SC");
|
map[UltimateFallbackScript].Insert(0, "Noto Sans CJK SC");
|
||||||
map["zyyy"].Insert(0, "Roboto");
|
map[UltimateFallbackScript].Insert(0, "Roboto");
|
||||||
map["zsye"].Insert(0, "Noto Color Emoji");
|
map["zsye"].Insert(0, "Noto Color Emoji");
|
||||||
map["zsye"].Add("Noto Color Emoji Flags");
|
map["zsye"].Add("Noto Color Emoji Flags");
|
||||||
map["arab"].Insert(0, "Noto Naskh Arabic");
|
map["arab"].Insert(0, "Noto Naskh Arabic");
|
||||||
@@ -275,9 +277,9 @@ namespace Cryville.Common.Font {
|
|||||||
map["sund"].Insert(0, "Noto Sans Sundanese");
|
map["sund"].Insert(0, "Noto Sans Sundanese");
|
||||||
map["sylo"].Insert(0, "Noto Sans Syloti Nagri");
|
map["sylo"].Insert(0, "Noto Sans Syloti Nagri");
|
||||||
map["zsym"].Insert(0, "Noto Sans Symbols");
|
map["zsym"].Insert(0, "Noto Sans Symbols");
|
||||||
map["syrn"].Insert(0, "Noto Sans Syriac Eastern");
|
map["syrc"].Add("Noto Sans Syriac Eastern");
|
||||||
map["syre"].Insert(0, "Noto Sans Syriac Estrangela");
|
map["syrc"].Add("Noto Sans Syriac Western");
|
||||||
map["syrj"].Insert(0, "Noto Sans Syriac Western");
|
map["syrc"].Add("Noto Sans Syriac Estrangela");
|
||||||
map["tglg"].Insert(0, "Noto Sans Tagalog");
|
map["tglg"].Insert(0, "Noto Sans Tagalog");
|
||||||
map["tagb"].Insert(0, "Noto Sans Tagbanwa");
|
map["tagb"].Insert(0, "Noto Sans Tagbanwa");
|
||||||
map["tale"].Insert(0, "Noto Sans Tai Le");
|
map["tale"].Insert(0, "Noto Sans Tai Le");
|
||||||
@@ -296,34 +298,48 @@ namespace Cryville.Common.Font {
|
|||||||
map["yiii"].Insert(0, "Noto Sans Yi");
|
map["yiii"].Insert(0, "Noto Sans Yi");
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
public FallbackListFontMatcher(FontManager manager) : base(manager) { }
|
static void FillKeysWithScripts<T>(IDictionary<string, T> map, Func<T> value) {
|
||||||
public override IEnumerable<Typeface> MatchScript(string script = null, bool distinctFamily = false) {
|
foreach (var s in IdValidity.Enumerate("script")) map.Add(s, value());
|
||||||
if (string.IsNullOrEmpty(script)) script = ScriptUtils.UltimateFallbackScript;
|
}
|
||||||
List<string> candidates;
|
|
||||||
IEnumerable<string> candidateScripts = new string[] { script };
|
public FallbackListFontMatcher(LanguageMatching matcher, FontManager manager) : base(manager) {
|
||||||
while (candidateScripts != null) {
|
_matcher = matcher;
|
||||||
foreach (var candidateScript in candidateScripts) {
|
}
|
||||||
if (MapScriptToTypefaces.TryGetValue(candidateScript, out candidates)) {
|
public override IEnumerable<Typeface> MatchLanguage(LanguageId lang, bool distinctFamily = false) {
|
||||||
foreach (var candidate in candidates) {
|
var supported = MapScriptToTypefaces.Keys.Select(i => new LanguageId(i)).ToList();
|
||||||
IReadOnlyCollection<Typeface> typefaces1;
|
bool flag = false;
|
||||||
if (Manager.MapFullNameToTypeface.TryGetValue(candidate, out typefaces1)) {
|
while (_matcher.Match(lang, supported, out var match, out var distance)) {
|
||||||
foreach (var typeface in typefaces1) {
|
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;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
IEnumerable<Typeface> EnumerateTypefaces(List<string> candidates, bool distinctFamily) {
|
||||||
|
foreach (var candidate in candidates) {
|
||||||
|
if (Manager.MapFullNameToTypeface.TryGetValue(candidate, out var typeface1)) {
|
||||||
|
yield return typeface1;
|
||||||
}
|
}
|
||||||
if (distinctFamily) continue;
|
if (distinctFamily) continue;
|
||||||
IReadOnlyCollection<Typeface> typefaces2;
|
IReadOnlyCollection<Typeface> typefaces2;
|
||||||
if (Manager.MapNameToTypefaces.TryGetValue(candidate, out typefaces2)) {
|
if (Manager.MapNameToTypefaces.TryGetValue(candidate, out typefaces2)) {
|
||||||
foreach (var typeface in typefaces2) {
|
foreach (var typeface in typefaces2) {
|
||||||
if (typefaces1.Contains(typeface)) continue;
|
if (typeface1 == typeface) continue;
|
||||||
yield return typeface;
|
yield return typeface;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
candidateScripts = ScriptUtils.EnumerateFallbackScripts(script);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -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;
|
||||||
Encoding encoding;
|
EncodingID = encodingID;
|
||||||
switch (platformID) {
|
LanguageID = languageID;
|
||||||
case 0: encoding = Encoding.BigEndianUnicode; break;
|
NameID = nameID;
|
||||||
case 3: encoding = Encoding.BigEndianUnicode; break;
|
Length = length;
|
||||||
default: return this;
|
StringOffset = stringOffset;
|
||||||
}
|
}
|
||||||
value = encoding.GetString(reader.ReadBytes(length));
|
public void Load(BinaryReader reader, UInt32 origin) {
|
||||||
return this;
|
reader.BaseStream.Position = origin + StringOffset;
|
||||||
|
Encoding encoding;
|
||||||
|
try {
|
||||||
|
switch (PlatformID) {
|
||||||
|
case 0: encoding = Encoding.BigEndianUnicode; break;
|
||||||
|
case 1: encoding = Encoding.GetEncoding(10000 + EncodingID); break;
|
||||||
|
case 3: encoding = Encoding.BigEndianUnicode; break;
|
||||||
|
default: return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (NotSupportedException) { return; }
|
||||||
|
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 {
|
||||||
|
@@ -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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,4 +1,3 @@
|
|||||||
using Cryville.Common.Logging;
|
|
||||||
using Microsoft.Win32;
|
using Microsoft.Win32;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@@ -35,7 +34,7 @@ namespace Cryville.Common.Network.Http11 {
|
|||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,7 +95,7 @@ namespace Cryville.Common.Network.Http11 {
|
|||||||
writer.Flush();
|
writer.Flush();
|
||||||
}
|
}
|
||||||
var response = new Http11Response(stream);
|
var response = new Http11Response(stream);
|
||||||
Logger.Log("main", 0, "Network", "{0}", response);
|
Shared.Logger.Log(0, "Network", "{0}", response);
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -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();
|
||||||
|
7
Assets/Cryville/Common/Shared.cs
Normal file
7
Assets/Cryville/Common/Shared.cs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
using Cryville.Common.Logging;
|
||||||
|
|
||||||
|
namespace Cryville.Common {
|
||||||
|
public static class Shared {
|
||||||
|
public static readonly Logger Logger = new Logger();
|
||||||
|
}
|
||||||
|
}
|
@@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: ae9dab8f520fadc4194032f523ca87c1
|
guid: ef30832cb8f75dd4bb24744d068553f2
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
95
Assets/Cryville/Common/Tweener.cs
Normal file
95
Assets/Cryville/Common/Tweener.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
11
Assets/Cryville/Common/Tweener.cs.meta
Normal file
11
Assets/Cryville/Common/Tweener.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 0b4037ba4138aae47b8da984f30b4db9
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
50
Assets/Cryville/Common/Unity/ScopedThreadAttacherInjector.cs
Normal file
50
Assets/Cryville/Common/Unity/ScopedThreadAttacherInjector.cs
Normal 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
|
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 2322d8e9250e9e6469826361223dfdda
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
181
Assets/Cryville/Common/Unity/StateTweener.cs
Normal file
181
Assets/Cryville/Common/Unity/StateTweener.cs
Normal 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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
11
Assets/Cryville/Common/Unity/StateTweener.cs.meta
Normal file
11
Assets/Cryville/Common/Unity/StateTweener.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: d605791cb18d88e4fb0ab6f794361eee
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -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();
|
||||||
|
if (axis == 0) {
|
||||||
vh.AddVert(new Vector3(corner1.x, corner2.y), color, new Vector2(uv.x, uv.w));
|
vh.AddVert(new Vector3(corner1.x, corner2.y), color, new Vector2(uv.x, uv.w));
|
||||||
vh.AddVert(new Vector3(corner1.x, corner1.y), color, new Vector2(uv.x, uv.y));
|
vh.AddVert(new Vector3(corner1.x, corner1.y), color, new Vector2(uv.x, uv.y));
|
||||||
vh.AddVert(new Vector3(corner1.x + w3, corner2.y), color, new Vector2(uv.x + actualLeftUVWidth, uv.w));
|
vh.AddVert(new Vector3(corner1.x + w3, corner2.y), color, new Vector2(uv.x + actualStartUVWidth, uv.w));
|
||||||
vh.AddVert(new Vector3(corner1.x + w4, corner1.y), color, new Vector2(uv.x + actualLeftUVWidth, uv.y));
|
vh.AddVert(new Vector3(corner1.x + w4, corner1.y), color, new Vector2(uv.x + actualStartUVWidth, uv.y));
|
||||||
vh.AddVert(new Vector3(corner2.x - w5, corner2.y), color, new Vector2(uv.z - actualRightUVWidth, uv.w));
|
vh.AddVert(new Vector3(corner2.x - w5, corner2.y), color, new Vector2(uv.z - actualEndUVLength, uv.w));
|
||||||
vh.AddVert(new Vector3(corner2.x - w6, corner1.y), color, new Vector2(uv.z - actualRightUVWidth, uv.y));
|
vh.AddVert(new Vector3(corner2.x - w6, corner1.y), color, new Vector2(uv.z - actualEndUVLength, uv.y));
|
||||||
vh.AddVert(new Vector3(corner2.x, corner2.y), color, new Vector2(uv.z, uv.w));
|
vh.AddVert(new Vector3(corner2.x, corner2.y), color, new Vector2(uv.z, uv.w));
|
||||||
vh.AddVert(new Vector3(corner2.x, corner1.y), color, new Vector2(uv.z, uv.y));
|
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);
|
||||||
|
38
Assets/Cryville/Common/Unity/UI/SafeArea.cs
Normal file
38
Assets/Cryville/Common/Unity/UI/SafeArea.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
11
Assets/Cryville/Common/Unity/UI/SafeArea.cs.meta
Normal file
11
Assets/Cryville/Common/Unity/UI/SafeArea.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 112824c0b55202c4f9c779de7574b5fd
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@@ -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);
|
||||||
|
94
Assets/Cryville/Common/Unity/UI/SingleLayoutGroup.cs
Normal file
94
Assets/Cryville/Common/Unity/UI/SingleLayoutGroup.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
11
Assets/Cryville/Common/Unity/UI/SingleLayoutGroup.cs.meta
Normal file
11
Assets/Cryville/Common/Unity/UI/SingleLayoutGroup.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 5d03df0bb58478e42935bbdf633a4aa4
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -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 {
|
||||||
|
@@ -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; }
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,12 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: cfa7de3f6f944914d9999fcfda245f97
|
|
||||||
timeCreated: 1637552994
|
|
||||||
licenseType: Free
|
|
||||||
MonoImporter:
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
@@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,12 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: b38d66b3e6e5d94438c72f855c4efff9
|
|
||||||
timeCreated: 1637554149
|
|
||||||
licenseType: Free
|
|
||||||
MonoImporter:
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
10
Assets/Cryville/Crtr/Browsing/ChartDetail.cs
Normal file
10
Assets/Cryville/Crtr/Browsing/ChartDetail.cs
Normal 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; }
|
||||||
|
}
|
||||||
|
}
|
11
Assets/Cryville/Crtr/Browsing/ChartDetail.cs.meta
Normal file
11
Assets/Cryville/Crtr/Browsing/ChartDetail.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 5f9870328bccefa4d8d4f6d5e3cef591
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,12 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 477e04b1ed5b60e48886fb76081245c5
|
|
||||||
timeCreated: 1637722157
|
|
||||||
licenseType: Free
|
|
||||||
MonoImporter:
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
@@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -3,65 +3,88 @@ 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 meta = new ChartMeta();
|
var item = _items[index];
|
||||||
string name = item.Name;
|
ChartMeta meta = null;
|
||||||
string desc = "(Unknown)";
|
AsyncDelivery<Texture2D> cover = null;
|
||||||
var metaFile = new FileInfo(item.FullName + "/.umgc");
|
var metaFile = new FileInfo(Path.Combine(item.FullName, ".umgc"));
|
||||||
if (metaFile.Exists) {
|
if (metaFile.Exists) {
|
||||||
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());
|
||||||
name = meta.song.name;
|
|
||||||
desc = meta.name;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
AsyncDelivery<Texture2D> cover = null;
|
|
||||||
if (meta.cover != null && meta.cover != "") {
|
if (meta.cover != null && meta.cover != "") {
|
||||||
var coverFile = item.GetFiles(meta.cover);
|
var coverFile = item.GetFiles(meta.cover);
|
||||||
if (coverFile.Length > 0) {
|
if (coverFile.Length > 0) {
|
||||||
@@ -71,51 +94,27 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
Game.NetworkTaskWorker.SubmitNetworkTask(task);
|
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(PlatformConfig.FileProtocolPrefix + coverFile[0].FullName, cover.Deliver);
|
|
||||||
cover.CancelSource = task.Cancel;
|
|
||||||
Game.NetworkTaskWorker.SubmitNetworkTask(task);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return new ChartDetail {
|
return new ChartDetail {
|
||||||
Cover = cover,
|
Cover = cover,
|
||||||
Meta = meta,
|
Meta = meta,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public string GetItemPath(int id) {
|
public Uri GetItemUri(int id) {
|
||||||
var item = items[id];
|
var item = _items[id];
|
||||||
var meta = new ChartMeta();
|
var meta = new ChartMeta();
|
||||||
var metaFile = new FileInfo(item.FullName + "/.umgc");
|
var metaFile = new FileInfo(Path.Combine(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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,12 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 5d443a346e9a19d4eabbb0fa9ec7016f
|
|
||||||
timeCreated: 1637566071
|
|
||||||
licenseType: Free
|
|
||||||
MonoImporter:
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
@@ -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");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,12 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: c6b4df13dea0e4a469d7e54e7e8fb428
|
|
||||||
timeCreated: 1637234060
|
|
||||||
licenseType: Free
|
|
||||||
MonoImporter:
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
@@ -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; }
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,12 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 256d7d3efda1f9b4c882eb42e608cc8e
|
|
||||||
timeCreated: 1638414803
|
|
||||||
licenseType: Free
|
|
||||||
MonoImporter:
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
@@ -1,12 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: a69c80e5f3e7bd04485bc3afc5826584
|
|
||||||
timeCreated: 1638415083
|
|
||||||
licenseType: Free
|
|
||||||
MonoImporter:
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
@@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 520554ce9a8205b4b91e0ff2b8011673
|
guid: ba8a8b6df16a9714f9785aba6adc0427
|
||||||
folderAsset: yes
|
folderAsset: yes
|
||||||
DefaultImporter:
|
DefaultImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
18
Assets/Cryville/Crtr/Browsing/UI/BrowserItem.cs
Normal file
18
Assets/Cryville/Crtr/Browsing/UI/BrowserItem.cs
Normal 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() { }
|
||||||
|
}
|
||||||
|
}
|
11
Assets/Cryville/Crtr/Browsing/UI/BrowserItem.cs.meta
Normal file
11
Assets/Cryville/Crtr/Browsing/UI/BrowserItem.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: c3cee963751f1ee4c9792c8c8983f51d
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
80
Assets/Cryville/Crtr/Browsing/UI/BrowserItemTile.cs
Normal file
80
Assets/Cryville/Crtr/Browsing/UI/BrowserItemTile.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
11
Assets/Cryville/Crtr/Browsing/UI/BrowserItemTile.cs.meta
Normal file
11
Assets/Cryville/Crtr/Browsing/UI/BrowserItemTile.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 18dcb7d928c649f46bda005527fb6a17
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
55
Assets/Cryville/Crtr/Browsing/UI/BrowserTab.cs
Normal file
55
Assets/Cryville/Crtr/Browsing/UI/BrowserTab.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
11
Assets/Cryville/Crtr/Browsing/UI/BrowserTab.cs.meta
Normal file
11
Assets/Cryville/Crtr/Browsing/UI/BrowserTab.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 62b498b3519eb364cb6683512b28400a
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
104
Assets/Cryville/Crtr/Browsing/UI/BrowserTabLayout.cs
Normal file
104
Assets/Cryville/Crtr/Browsing/UI/BrowserTabLayout.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
11
Assets/Cryville/Crtr/Browsing/UI/BrowserTabLayout.cs.meta
Normal file
11
Assets/Cryville/Crtr/Browsing/UI/BrowserTabLayout.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 5160f264c834b9c4dbe5875accab32a8
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
71
Assets/Cryville/Crtr/Browsing/UI/DetailPanel.cs
Normal file
71
Assets/Cryville/Crtr/Browsing/UI/DetailPanel.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
11
Assets/Cryville/Crtr/Browsing/UI/DetailPanel.cs.meta
Normal file
11
Assets/Cryville/Crtr/Browsing/UI/DetailPanel.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 9bdcc04cb1961dd4e9483dbf6c6d6f8b
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
11
Assets/Cryville/Crtr/Browsing/UI/PathPart.cs.meta
Normal file
11
Assets/Cryville/Crtr/Browsing/UI/PathPart.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 961fa71cc64cc2a4b88adfc5a1aad216
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
91
Assets/Cryville/Crtr/Browsing/UI/PathedResourceBrowser.cs
Normal file
91
Assets/Cryville/Crtr/Browsing/UI/PathedResourceBrowser.cs
Normal 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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: f3c17bb298cf2294dad4b675c7290b2a
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@@ -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() { }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
11
Assets/Cryville/Crtr/Browsing/UI/ResourceBrowser.cs.meta
Normal file
11
Assets/Cryville/Crtr/Browsing/UI/ResourceBrowser.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 8d8141a90dc49f741b382e7abbf0a9c8
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
95
Assets/Cryville/Crtr/Browsing/UI/ResourceBrowserMaster.cs
Normal file
95
Assets/Cryville/Crtr/Browsing/UI/ResourceBrowserMaster.cs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 1c6c8bc301408004a904079721302722
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
11
Assets/Cryville/Crtr/Browsing/UI/SettingsBrowser.cs
Normal file
11
Assets/Cryville/Crtr/Browsing/UI/SettingsBrowser.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
11
Assets/Cryville/Crtr/Browsing/UI/SettingsBrowser.cs.meta
Normal file
11
Assets/Cryville/Crtr/Browsing/UI/SettingsBrowser.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 8523c789afb6adb48ac62a48f7decf0f
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@@ -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
|
@@ -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;
|
||||||
|
@@ -1,7 +1,11 @@
|
|||||||
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;
|
||||||
@@ -15,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;
|
||||||
@@ -41,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;
|
||||||
@@ -64,19 +68,21 @@ namespace Cryville.Crtr {
|
|||||||
|
|
||||||
#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);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Play();
|
Play();
|
||||||
@@ -98,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();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,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 {
|
||||||
@@ -177,7 +185,7 @@ 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);
|
||||||
ReturnToMenu();
|
ReturnToMenu();
|
||||||
@@ -198,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) {
|
||||||
@@ -219,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);
|
||||||
@@ -265,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)" : "",
|
||||||
@@ -332,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 {
|
||||||
@@ -364,8 +372,8 @@ namespace Cryville.Crtr {
|
|||||||
#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;
|
||||||
@@ -417,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));
|
||||||
@@ -430,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;
|
||||||
@@ -466,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));
|
||||||
@@ -474,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();
|
||||||
@@ -490,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,7 +560,7 @@ namespace Cryville.Crtr {
|
|||||||
}
|
}
|
||||||
PdtEvaluator.Instance.Reset();
|
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();
|
||||||
@@ -594,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);
|
||||||
@@ -603,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)) },
|
||||||
@@ -624,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);
|
||||||
PdtEvaluator.Instance.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) {
|
||||||
@@ -663,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;
|
||||||
}
|
}
|
||||||
@@ -680,12 +688,12 @@ 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(PdtEvaluator.Instance);
|
pruleset.Optimize(PdtEvaluator.Instance);
|
||||||
@@ -698,7 +706,7 @@ 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(PdtEvaluator.Instance);
|
pskin.Optimize(PdtEvaluator.Instance);
|
||||||
|
@@ -8,6 +8,7 @@ namespace Cryville.Crtr.Config {
|
|||||||
public interface IPropertyAdapter {
|
public interface IPropertyAdapter {
|
||||||
string Category { get; }
|
string Category { get; }
|
||||||
string Name { get; }
|
string Name { get; }
|
||||||
|
string Description { get; }
|
||||||
PropertyType Type { get; }
|
PropertyType Type { get; }
|
||||||
object[] Range { get; }
|
object[] Range { get; }
|
||||||
object GetValue();
|
object GetValue();
|
||||||
@@ -31,6 +32,7 @@ namespace Cryville.Crtr.Config {
|
|||||||
readonly PropertyInfo _prop;
|
readonly PropertyInfo _prop;
|
||||||
public string Category { get; private set; }
|
public string Category { get; private set; }
|
||||||
public string Name { get; private set; }
|
public string Name { get; private set; }
|
||||||
|
public string Description { get; private set; }
|
||||||
public PropertyType Type { get; private set; }
|
public PropertyType Type { get; private set; }
|
||||||
public object[] Range { get; private set; }
|
public object[] Range { get; private set; }
|
||||||
public object GetValue() { return _prop.GetValue(_target, null); }
|
public object GetValue() { return _prop.GetValue(_target, null); }
|
||||||
@@ -68,6 +70,8 @@ namespace Cryville.Crtr.Config {
|
|||||||
var attrs = prop.GetCustomAttributes(typeof(CategoryAttribute), true);
|
var attrs = prop.GetCustomAttributes(typeof(CategoryAttribute), true);
|
||||||
if (attrs.Length > 0) Category = ((CategoryAttribute)attrs.Single()).Category;
|
if (attrs.Length > 0) Category = ((CategoryAttribute)attrs.Single()).Category;
|
||||||
Name = prop.Name;
|
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;
|
if (prop.PropertyType == typeof(bool)) Type = PropertyType.Boolean;
|
||||||
else if (prop.PropertyType == typeof(char)) throw new NotSupportedException();
|
else if (prop.PropertyType == typeof(char)) throw new NotSupportedException();
|
||||||
else if (prop.PropertyType.IsPrimitive) {
|
else if (prop.PropertyType.IsPrimitive) {
|
||||||
|
@@ -1,27 +0,0 @@
|
|||||||
using System;
|
|
||||||
|
|
||||||
namespace Cryville.Crtr.Config {
|
|
||||||
public class PVPNumber : PVPNumberBase {
|
|
||||||
protected override void OnValueUpdated() {
|
|
||||||
base.OnValueUpdated();
|
|
||||||
if (Range != null && Range.Length == 2) {
|
|
||||||
var min = (double)Range[0];
|
|
||||||
var max = (double)Range[1];
|
|
||||||
var value = Convert.ToDouble(RawValue);
|
|
||||||
if (value < min) {
|
|
||||||
value = min;
|
|
||||||
RawValue = value;
|
|
||||||
}
|
|
||||||
else if (value > max) {
|
|
||||||
value = max;
|
|
||||||
RawValue = value;
|
|
||||||
}
|
|
||||||
SetRatio((float)((value - min) / (max - min)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
protected override double GetValue(double ratio, float deltaTime, double min, double max) {
|
|
||||||
// if (LogarithmicMode) throw new NotImplementedException();
|
|
||||||
return (1 - ratio) * min + ratio * max;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,5 +1,6 @@
|
|||||||
using Cryville.Common;
|
using Cryville.Common;
|
||||||
using Cryville.Common.Pdt;
|
using Cryville.Common.Pdt;
|
||||||
|
using Cryville.Crtr.Ruleset;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
@@ -53,8 +54,8 @@ namespace Cryville.Crtr.Config {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public string Category { get { return _def.category; } }
|
public string Category { get { return _def.category; } }
|
||||||
|
|
||||||
public string Name { get; private set; }
|
public string Name { get; private set; }
|
||||||
|
public string Description { get { return null; } }
|
||||||
|
|
||||||
public PropertyType Type { get; private set; }
|
public PropertyType Type { get; private set; }
|
||||||
|
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
using Cryville.Common;
|
using Cryville.Common;
|
||||||
using Cryville.Common.Collections.Specialized;
|
using Cryville.Common.Collections.Specialized;
|
||||||
|
using Cryville.Crtr.Ruleset;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 8a36c371ab6077d43ac28fe09b0fe675
|
guid: 26842cf5cfcceb14a9dbb07adbdf4da0
|
||||||
timeCreated: 1620725915
|
folderAsset: yes
|
||||||
licenseType: Free
|
|
||||||
DefaultImporter:
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
userData:
|
userData:
|
||||||
assetBundleName:
|
assetBundleName:
|
||||||
assetBundleVariant:
|
assetBundleVariant:
|
@@ -1,11 +1,12 @@
|
|||||||
|
using Cryville.Crtr.Ruleset;
|
||||||
|
using Cryville.Crtr.UI;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using Logger = Cryville.Common.Logging.Logger;
|
|
||||||
|
|
||||||
namespace Cryville.Crtr.Config {
|
namespace Cryville.Crtr.Config.UI {
|
||||||
public class ConfigPanelMaster : MonoBehaviour {
|
public class ConfigPanelMaster : MonoBehaviour {
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
Menu m_menu;
|
Menu m_menu;
|
||||||
@@ -22,7 +23,7 @@ namespace Cryville.Crtr.Config {
|
|||||||
[SerializeField]
|
[SerializeField]
|
||||||
InputConfigPanel m_inputConfigPanel;
|
InputConfigPanel m_inputConfigPanel;
|
||||||
|
|
||||||
public Ruleset ruleset;
|
public RulesetDefinition ruleset;
|
||||||
RulesetConfig _rscfg;
|
RulesetConfig _rscfg;
|
||||||
|
|
||||||
bool _loaded;
|
bool _loaded;
|
||||||
@@ -38,10 +39,10 @@ namespace Cryville.Crtr.Config {
|
|||||||
}
|
}
|
||||||
DirectoryInfo dir = file.Directory;
|
DirectoryInfo dir = file.Directory;
|
||||||
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);
|
||||||
}
|
}
|
||||||
FileInfo cfgfile = new FileInfo(
|
FileInfo cfgfile = new FileInfo(
|
||||||
@@ -72,7 +73,7 @@ namespace Cryville.Crtr.Config {
|
|||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
Popup.CreateException(ex);
|
Popup.CreateException(ex);
|
||||||
Logger.Log("main", 4, "Config", "An error occurred while loading the config: {0}", ex);
|
Game.MainLogger.Log(4, "Config", "An error occurred while loading the config: {0}", ex);
|
||||||
m_menu.Back();
|
m_menu.Back();
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 54c06a15adfb41548acca0d73f391fe7
|
guid: bad1f43573d4f1143a94fddddd30fb81
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
@@ -1,12 +1,13 @@
|
|||||||
using Cryville.Common;
|
using Cryville.Common;
|
||||||
using Cryville.Common.Unity;
|
using Cryville.Common.Unity;
|
||||||
|
using Cryville.Crtr.Ruleset;
|
||||||
using Cryville.Input;
|
using Cryville.Input;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
|
|
||||||
namespace Cryville.Crtr.Config {
|
namespace Cryville.Crtr.Config.UI {
|
||||||
public class InputConfigPanel : MonoBehaviour {
|
public class InputConfigPanel : MonoBehaviour {
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
ConfigPanelMaster m_configScene;
|
ConfigPanelMaster m_configScene;
|
@@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: d27589834da67984d98c6147c8b6b5bb
|
guid: 279d2404a312e5543813d8aca02800b8
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
@@ -1,9 +1,10 @@
|
|||||||
using Cryville.Common;
|
using Cryville.Common;
|
||||||
|
using Cryville.Crtr.Ruleset;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.EventSystems;
|
using UnityEngine.EventSystems;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
|
|
||||||
namespace Cryville.Crtr.Config {
|
namespace Cryville.Crtr.Config.UI {
|
||||||
public class InputConfigPanelEntry : MonoBehaviour {
|
public class InputConfigPanelEntry : MonoBehaviour {
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
Text m_key;
|
Text m_key;
|
@@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 8661f4d4934e11040a0c65729d4ba47a
|
guid: 9741a0ed8c1c5e0468ea89f2cf33f36c
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
@@ -1,13 +1,11 @@
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.EventSystems;
|
using UnityEngine.EventSystems;
|
||||||
|
|
||||||
namespace Cryville.Crtr.Config {
|
namespace Cryville.Crtr.Config.UI {
|
||||||
public class PVPBool : PropertyValuePanel, IPointerClickHandler {
|
public class PVPBool : PropertyValuePanel, IPointerClickHandler {
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
RectTransform m_on;
|
RectTransform m_on;
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
RectTransform m_handleArea;
|
|
||||||
[SerializeField]
|
|
||||||
RectTransform m_handle;
|
RectTransform m_handle;
|
||||||
|
|
||||||
protected override void OnValueUpdated() { }
|
protected override void OnValueUpdated() { }
|
||||||
@@ -31,10 +29,6 @@ namespace Cryville.Crtr.Config {
|
|||||||
UpdateGraphics();
|
UpdateGraphics();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnRectTransformDimensionsChange() {
|
|
||||||
m_handleArea.sizeDelta = new Vector2(m_handle.rect.height - m_handle.rect.width, 0);
|
|
||||||
}
|
|
||||||
#pragma warning restore IDE0051
|
#pragma warning restore IDE0051
|
||||||
|
|
||||||
void UpdateGraphics() {
|
void UpdateGraphics() {
|
@@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 362a7cfafb57b9f46bbca9ed88d18c53
|
guid: 9cb1bc40304ff174f891239c8f450c1c
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
24
Assets/Cryville/Crtr/Config/UI/PVPNumber.cs
Normal file
24
Assets/Cryville/Crtr/Config/UI/PVPNumber.cs
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
using System;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Cryville.Crtr.Config.UI {
|
||||||
|
public class PVPNumber : PVPNumberBase {
|
||||||
|
[SerializeField]
|
||||||
|
RectTransform m_on;
|
||||||
|
|
||||||
|
protected override void OnValueUpdated() {
|
||||||
|
base.OnValueUpdated();
|
||||||
|
if (Range == null || Range.Length != 2) return;
|
||||||
|
var min = (double)Range[0];
|
||||||
|
var max = (double)Range[1];
|
||||||
|
var value = Convert.ToDouble(RawValue);
|
||||||
|
float ratio = (float)((value - min) / (max - min));
|
||||||
|
SetRatio(ratio);
|
||||||
|
m_on.anchorMax = new Vector2(ratio, m_on.anchorMax.y);
|
||||||
|
}
|
||||||
|
protected override double GetValue(double ratio, float deltaTime, double min, double max) {
|
||||||
|
// if (LogarithmicMode) throw new NotImplementedException();
|
||||||
|
return (1 - ratio) * min + ratio * max;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 5b5d86b95e0bf894b86c63127d5ac06c
|
guid: 94cb9dad5ac3eb04ca16d58a7bae0cb5
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
@@ -1,57 +1,69 @@
|
|||||||
|
using System;
|
||||||
|
using TMPro;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.EventSystems;
|
using UnityEngine.EventSystems;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
|
|
||||||
namespace Cryville.Crtr.Config {
|
namespace Cryville.Crtr.Config.UI {
|
||||||
public abstract class PVPNumberBase : PropertyValuePanel {
|
public abstract class PVPNumberBase : PropertyValuePanel, IInitializePotentialDragHandler, IDragHandler, IEndDragHandler, IPointerClickHandler {
|
||||||
[SerializeField]
|
|
||||||
EventTrigger m_ctn;
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
RectTransform m_handleArea;
|
RectTransform m_handleArea;
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
Image m_handle;
|
Image m_handle;
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
Text m_text;
|
TMP_InputField m_text;
|
||||||
#pragma warning disable IDE0051
|
|
||||||
protected void Start() {
|
protected void Start() {
|
||||||
var ev = new EventTrigger.Entry { eventID = EventTriggerType.InitializePotentialDrag };
|
m_text.interactable = SetMapped;
|
||||||
ev.callback.AddListener(e => OnInitializePotentialDrag((PointerEventData)e));
|
m_text.onValueChanged.AddListener(OnTextEdited);
|
||||||
m_ctn.triggers.Add(ev);
|
m_text.onDeselect.AddListener(OnTextDeselected);
|
||||||
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);
|
|
||||||
OnIdle();
|
OnIdle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OnTextEdited(string value) {
|
||||||
|
if (!m_text.isFocused) return;
|
||||||
|
if (double.TryParse(value, out var result)) {
|
||||||
|
try { MappedValue = result; }
|
||||||
|
catch (Exception) { }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void OnTextDeselected(string value) {
|
||||||
|
OnValueUpdated();
|
||||||
|
}
|
||||||
|
|
||||||
protected override void OnValueUpdated() {
|
protected override void OnValueUpdated() {
|
||||||
|
if (Range != null && Range.Length == 2) {
|
||||||
|
var min = (double)Range[0];
|
||||||
|
var max = (double)Range[1];
|
||||||
|
var value = Convert.ToDouble(RawValue);
|
||||||
|
if (value < min) {
|
||||||
|
value = min;
|
||||||
|
RawValue = value;
|
||||||
|
}
|
||||||
|
else if (value > max) {
|
||||||
|
value = max;
|
||||||
|
RawValue = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!m_text.isFocused) {
|
||||||
m_text.text = MappedValue.ToString();
|
m_text.text = MappedValue.ToString();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected virtual void OnIdle() { }
|
protected virtual void OnIdle() { }
|
||||||
|
|
||||||
void Update() {
|
protected virtual void Update() {
|
||||||
if (use) {
|
if (use) {
|
||||||
SetRatio(GetRatioFromPos(pp));
|
SetRatio(GetRatioFromPos(pp));
|
||||||
SetValueFromPos(pp);
|
SetValueFromPos(pp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnRectTransformDimensionsChange() {
|
|
||||||
m_handleArea.sizeDelta = new Vector2(m_handle.rectTransform.rect.height - m_handle.rectTransform.rect.width, 0);
|
|
||||||
}
|
|
||||||
#pragma warning restore IDE0051
|
|
||||||
|
|
||||||
Camera cam;
|
Camera cam;
|
||||||
Vector2 pp;
|
Vector2 pp;
|
||||||
bool use, nouse;
|
bool use, nouse;
|
||||||
public void OnInitializePotentialDrag(PointerEventData eventData) {
|
public void OnInitializePotentialDrag(PointerEventData eventData) {
|
||||||
eventData.useDragThreshold = false;
|
// eventData.useDragThreshold = false;
|
||||||
pp = eventData.position;
|
pp = eventData.position;
|
||||||
}
|
}
|
||||||
|
|
@@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 32fb9b8479cd8294296453d1aa651ff4
|
guid: c928ece9c4b30f04cb33f66eb9f050b3
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
@@ -1,6 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace Cryville.Crtr.Config {
|
namespace Cryville.Crtr.Config.UI {
|
||||||
public class PVPNumberStepped : PVPNumberBase {
|
public class PVPNumberStepped : PVPNumberBase {
|
||||||
protected override void OnIdle() {
|
protected override void OnIdle() {
|
||||||
SetRatio(0.5f);
|
SetRatio(0.5f);
|
@@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: f754d98e38098654a878fc9121db536d
|
guid: c309650ed758ea34ba64e765f59bb043
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
@@ -1,6 +1,6 @@
|
|||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
|
|
||||||
namespace Cryville.Crtr.Config {
|
namespace Cryville.Crtr.Config.UI {
|
||||||
public class PVPString : PropertyValuePanel {
|
public class PVPString : PropertyValuePanel {
|
||||||
protected override void OnValueUpdated() { _inputField.text = (string)MappedValue; }
|
protected override void OnValueUpdated() { _inputField.text = (string)MappedValue; }
|
||||||
|
|
@@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 1b9a6e3b503784e4aa78215e9b004a8f
|
guid: f81596a59a59fce48854b6753fe8cfc6
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
@@ -1,33 +1,27 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using TMPro;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
|
||||||
|
|
||||||
namespace Cryville.Crtr.Config {
|
namespace Cryville.Crtr.Config.UI {
|
||||||
public class PropertyCategoryPanel : MonoBehaviour {
|
public class PropertyCategoryPanel : MonoBehaviour {
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
private GameObject m_propertyPrefab;
|
GameObject m_propertyPrefab;
|
||||||
|
|
||||||
Text _nameLabel = null;
|
[SerializeField]
|
||||||
|
TextMeshProUGUI m_nameLabel;
|
||||||
|
|
||||||
string _name;
|
string m_name;
|
||||||
public string Name {
|
public string Name {
|
||||||
get { return _name; }
|
get { return m_name; }
|
||||||
set { _name = value; UpdateName(); }
|
set { m_name = value; UpdateName(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
bool _collapsed = false;
|
bool m_collapsed = false;
|
||||||
public bool Collapsed {
|
public bool Collapsed {
|
||||||
get { return _collapsed; }
|
get { return m_collapsed; }
|
||||||
set { _collapsed = value; UpdateName(); }
|
set { m_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<IPropertyAdapter> props) {
|
public void Load(string name, IEnumerable<IPropertyAdapter> props) {
|
||||||
Name = name.ToUpper();
|
Name = name.ToUpper();
|
||||||
foreach (var prop in props) {
|
foreach (var prop in props) {
|
||||||
@@ -36,7 +30,7 @@ namespace Cryville.Crtr.Config {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ToggleCollapsed() {
|
public void ToggleCollapsed() {
|
||||||
Collapsed = !Collapsed;
|
Collapsed = !Collapsed;
|
||||||
for (int i = 1; i < transform.childCount; i++) {
|
for (int i = 1; i < transform.childCount; i++) {
|
||||||
transform.GetChild(i).gameObject.SetActive(!Collapsed);
|
transform.GetChild(i).gameObject.SetActive(!Collapsed);
|
||||||
@@ -44,7 +38,7 @@ namespace Cryville.Crtr.Config {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateName() {
|
private void UpdateName() {
|
||||||
_nameLabel.text = (Collapsed ? "+ " : "- ") + Name;
|
m_nameLabel.text = (Collapsed ? "+ " : "- ") + Name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 71da54f24b65d2f41a00c5a4bd0ff1bf
|
guid: 11c5451aac09cbd4a8e94c82d5c568e8
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
@@ -1,7 +1,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Cryville.Crtr.Config {
|
namespace Cryville.Crtr.Config.UI {
|
||||||
public class PropertyMasterPanel : MonoBehaviour {
|
public class PropertyMasterPanel : MonoBehaviour {
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
GameObject m_categoryPrefab;
|
GameObject m_categoryPrefab;
|
@@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 4e6129746af547242bfa4e7404185936
|
guid: f8d04667a373e4648a83440b496c8127
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
@@ -1,7 +1,7 @@
|
|||||||
|
using TMPro;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
|
||||||
|
|
||||||
namespace Cryville.Crtr.Config {
|
namespace Cryville.Crtr.Config.UI {
|
||||||
public class PropertyPanel : MonoBehaviour {
|
public class PropertyPanel : MonoBehaviour {
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
GameObject m_bool;
|
GameObject m_bool;
|
||||||
@@ -12,18 +12,15 @@ namespace Cryville.Crtr.Config {
|
|||||||
[SerializeField]
|
[SerializeField]
|
||||||
GameObject m_string;
|
GameObject m_string;
|
||||||
|
|
||||||
Text _key;
|
[SerializeField]
|
||||||
Transform _valueContainer;
|
TextMeshProUGUI m_key;
|
||||||
|
[SerializeField]
|
||||||
|
Transform m_valueContainer;
|
||||||
|
|
||||||
PropertyValuePanel _value;
|
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(IPropertyAdapter prop) {
|
public void Load(IPropertyAdapter prop) {
|
||||||
_key.text = prop.Name;
|
m_key.text = prop.Name;
|
||||||
|
|
||||||
GameObject vp;
|
GameObject vp;
|
||||||
switch (prop.Type) {
|
switch (prop.Type) {
|
||||||
@@ -33,7 +30,7 @@ namespace Cryville.Crtr.Config {
|
|||||||
case PropertyType.String: vp = m_string; break;
|
case PropertyType.String: vp = m_string; break;
|
||||||
default: return;
|
default: return;
|
||||||
}
|
}
|
||||||
_value = Instantiate(vp, _valueContainer, false).GetComponent<PropertyValuePanel>();
|
_value = Instantiate(vp, m_valueContainer, false).GetComponent<PropertyValuePanel>();
|
||||||
_value.Init(prop);
|
_value.Init(prop);
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: e47c05cfd69aa3f4d9886293e66877e9
|
guid: 0a812a9e54dd057459b501c0881b0f68
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
@@ -1,6 +1,6 @@
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Cryville.Crtr.Config {
|
namespace Cryville.Crtr.Config.UI {
|
||||||
public abstract class PropertyValuePanel : MonoBehaviour {
|
public abstract class PropertyValuePanel : MonoBehaviour {
|
||||||
IPropertyAdapter _property;
|
IPropertyAdapter _property;
|
||||||
public void Init(IPropertyAdapter property) {
|
public void Init(IPropertyAdapter property) {
|
||||||
@@ -8,8 +8,16 @@ namespace Cryville.Crtr.Config {
|
|||||||
_property.ValueChanged += GetValue;
|
_property.ValueChanged += GetValue;
|
||||||
GetValue();
|
GetValue();
|
||||||
}
|
}
|
||||||
|
protected bool SetMapped { get { return _property.SetMapped; } }
|
||||||
protected object[] Range { get { return _property.Range; } }
|
protected object[] Range { get { return _property.Range; } }
|
||||||
public object MappedValue { get; private set; }
|
private object m_mappedValue;
|
||||||
|
public object MappedValue {
|
||||||
|
get { return m_mappedValue; }
|
||||||
|
set {
|
||||||
|
m_rawValue = _property.MapValueInverse(value);
|
||||||
|
SetValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
private object m_rawValue;
|
private object m_rawValue;
|
||||||
public object RawValue {
|
public object RawValue {
|
||||||
get { return m_rawValue; }
|
get { return m_rawValue; }
|
||||||
@@ -21,19 +29,19 @@ namespace Cryville.Crtr.Config {
|
|||||||
protected abstract void OnValueUpdated();
|
protected abstract void OnValueUpdated();
|
||||||
void GetValue() {
|
void GetValue() {
|
||||||
if (_property.SetMapped) {
|
if (_property.SetMapped) {
|
||||||
MappedValue = _property.GetValue();
|
m_mappedValue = _property.GetValue();
|
||||||
m_rawValue = _property.MapValueInverse(MappedValue);
|
m_rawValue = _property.MapValueInverse(m_mappedValue);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
m_rawValue = _property.GetValue();
|
m_rawValue = _property.GetValue();
|
||||||
MappedValue = _property.MapValue(m_rawValue);
|
m_mappedValue = _property.MapValue(m_rawValue);
|
||||||
}
|
}
|
||||||
OnValueUpdated();
|
OnValueUpdated();
|
||||||
}
|
}
|
||||||
void SetValue() {
|
void SetValue() {
|
||||||
var outRaw = RawValue;
|
var outRaw = RawValue;
|
||||||
MappedValue = _property.MapValue(outRaw);
|
m_mappedValue = _property.MapValue(outRaw);
|
||||||
_property.SetValue(_property.SetMapped ? MappedValue : outRaw);
|
_property.SetValue(_property.SetMapped ? m_mappedValue : outRaw);
|
||||||
OnValueUpdated();
|
OnValueUpdated();
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: c71cc11a0b1429c4fac91296bf8c5a63
|
guid: aa6b204c7a1fd1d4c95d912196fc7566
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
@@ -1,157 +0,0 @@
|
|||||||
using Cryville.Common.Network.Http11;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Threading;
|
|
||||||
using UnityEngine;
|
|
||||||
using UnityEngine.SceneManagement;
|
|
||||||
using UnityEngine.UI;
|
|
||||||
using Logger = Cryville.Common.Logging.Logger;
|
|
||||||
using unity = UnityEngine;
|
|
||||||
|
|
||||||
namespace Cryville.Crtr {
|
|
||||||
public class Console : MonoBehaviour {
|
|
||||||
public Text Logs;
|
|
||||||
public InputField InputBox;
|
|
||||||
CommandWorker worker;
|
|
||||||
readonly Queue<string> _fallbackQueue = new Queue<string>();
|
|
||||||
|
|
||||||
~Console() {
|
|
||||||
worker.Deactivate();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Start() {
|
|
||||||
Game.Init();
|
|
||||||
InputBox.Select();
|
|
||||||
|
|
||||||
worker = new CommandWorker(MainThreadFallback);
|
|
||||||
worker.Activate();
|
|
||||||
}
|
|
||||||
|
|
||||||
void OnApplicationQuit() {
|
|
||||||
Game.Shutdown();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Submit() {
|
|
||||||
worker.Issue(InputBox.text);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Update() {
|
|
||||||
if (
|
|
||||||
unity::Input.GetKeyDown(KeyCode.Return)
|
|
||||||
|| unity::Input.GetKeyDown(KeyCode.KeypadEnter)
|
|
||||||
) {
|
|
||||||
Submit();
|
|
||||||
InputBox.text = "";
|
|
||||||
InputBox.Select();
|
|
||||||
InputBox.ActivateInputField();
|
|
||||||
}
|
|
||||||
if (_fallbackQueue.Count > 0) {
|
|
||||||
switch (_fallbackQueue.Dequeue()) {
|
|
||||||
case "play":
|
|
||||||
SceneManager.LoadScene("Play");
|
|
||||||
break;
|
|
||||||
case "quit":
|
|
||||||
Application.Quit();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
Logger.Log("main", 4, "Console", "Unknown command. Type \"help\" for help");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
string _logs = Logs.text;
|
|
||||||
Game.MainLogger.Enumerate((level, module, msg) => {
|
|
||||||
string color;
|
|
||||||
switch (level) {
|
|
||||||
case 0: color = "#888888"; break;
|
|
||||||
case 1: color = "#bbbbbb"; break;
|
|
||||||
case 2: color = "#0088ff"; break;
|
|
||||||
case 3: color = "#ffff00"; break;
|
|
||||||
case 4: color = "#ff0000"; break;
|
|
||||||
case 5: color = "#bb0000"; break;
|
|
||||||
default: color = "#ff00ff"; break;
|
|
||||||
}
|
|
||||||
_logs += string.Format(
|
|
||||||
"\r\n\x02<color={1}ff>[{0}] <{2}> {3}</color>",
|
|
||||||
DateTime.UtcNow.ToString("s"), color, module, msg
|
|
||||||
);
|
|
||||||
});
|
|
||||||
Logs.text = _logs.Substring(Mathf.Max(0, _logs.IndexOf('\x02', Mathf.Max(0, _logs.Length - 8192))));
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainThreadFallback(string cmd) {
|
|
||||||
_fallbackQueue.Enqueue(cmd);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CommandWorker {
|
|
||||||
readonly Action<string> _fallback;
|
|
||||||
Thread _thread;
|
|
||||||
readonly Queue<string> _queue = new Queue<string>();
|
|
||||||
|
|
||||||
public CommandWorker(Action<string> fallback) {
|
|
||||||
_fallback = fallback;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Activate() {
|
|
||||||
_thread = new Thread(ThreadLoop);
|
|
||||||
_thread.Start();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Deactivate() {
|
|
||||||
_thread.Abort();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Issue(string cmd) {
|
|
||||||
lock (_queue) {
|
|
||||||
_queue.Enqueue(cmd);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ThreadLoop() {
|
|
||||||
while (true) {
|
|
||||||
string cmd = null;
|
|
||||||
lock (_queue) {
|
|
||||||
if (_queue.Count > 0) cmd = _queue.Dequeue();
|
|
||||||
}
|
|
||||||
if (cmd != null) ProcessCommand(cmd);
|
|
||||||
else Thread.Sleep(20);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ProcessCommand(string cmd) {
|
|
||||||
Logger.Log("main", 2, "Console", "Command processing: {0}", cmd);
|
|
||||||
var p = cmd.Split(' ');
|
|
||||||
try {
|
|
||||||
switch (p[0]) {
|
|
||||||
case "!http":
|
|
||||||
var httpcl = new Http11Client(new Uri(p[1]));
|
|
||||||
httpcl.Connect();
|
|
||||||
httpcl.Request("GET", new Uri(p[1])).MessageBody.ReadToEnd();
|
|
||||||
httpcl.Close();
|
|
||||||
break;
|
|
||||||
case "!https":
|
|
||||||
var httpscl = new Https11Client(new Uri(p[1]));
|
|
||||||
httpscl.Connect();
|
|
||||||
httpscl.Request("GET", new Uri(p[1])).MessageBody.ReadToEnd();
|
|
||||||
httpscl.Close();
|
|
||||||
break;
|
|
||||||
case "help": case "?":
|
|
||||||
Logger.Log(
|
|
||||||
"main", 1, "Console",
|
|
||||||
"\n\thelp" +
|
|
||||||
"\n\tplay" +
|
|
||||||
"\n\tquit"
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
_fallback.Invoke(cmd);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex) {
|
|
||||||
Logger.Log("main", 4, "Console", "{0}", ex);
|
|
||||||
}
|
|
||||||
Logger.Log("main", 2, "Console", "Command done: {0}", cmd);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,12 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 069c1a41e65819549b4dfcda4e619b76
|
|
||||||
timeCreated: 1620726427
|
|
||||||
licenseType: Free
|
|
||||||
MonoImporter:
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
@@ -1,11 +1,16 @@
|
|||||||
|
#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
|
||||||
|
#define COMPILE
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if COMPILE
|
||||||
using Discord;
|
using Discord;
|
||||||
using System;
|
using System;
|
||||||
|
#endif
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using Logger = Cryville.Common.Logging.Logger;
|
|
||||||
|
|
||||||
namespace Cryville.Crtr {
|
namespace Cryville.Crtr {
|
||||||
internal class DiscordController : MonoBehaviour {
|
internal class DiscordController : MonoBehaviour {
|
||||||
#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
|
#if COMPILE
|
||||||
public static DiscordController Instance;
|
public static DiscordController Instance;
|
||||||
|
|
||||||
const long CLIENT_ID = 1059021675578007622L;
|
const long CLIENT_ID = 1059021675578007622L;
|
||||||
@@ -19,7 +24,7 @@ namespace Cryville.Crtr {
|
|||||||
launchTime = (long)(DateTime.UtcNow - DateTime.UnixEpoch).TotalSeconds;
|
launchTime = (long)(DateTime.UtcNow - DateTime.UnixEpoch).TotalSeconds;
|
||||||
try {
|
try {
|
||||||
dc = new Discord.Discord(CLIENT_ID, (UInt64)CreateFlags.NoRequireDiscord);
|
dc = new Discord.Discord(CLIENT_ID, (UInt64)CreateFlags.NoRequireDiscord);
|
||||||
Logger.Log("main", 1, "Discord", "Connected to Discord");
|
Game.MainLogger.Log(1, "Discord", "Connected to Discord");
|
||||||
am = dc.GetActivityManager();
|
am = dc.GetActivityManager();
|
||||||
SetIdle();
|
SetIdle();
|
||||||
}
|
}
|
||||||
@@ -28,7 +33,7 @@ namespace Cryville.Crtr {
|
|||||||
dc.Dispose();
|
dc.Dispose();
|
||||||
dc = null;
|
dc = null;
|
||||||
}
|
}
|
||||||
Logger.Log("main", 3, "Discord", "Cannot connect to Discord");
|
Game.MainLogger.Log(3, "Discord", "Cannot connect to Discord");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,7 +45,7 @@ namespace Cryville.Crtr {
|
|||||||
catch (ResultException ex) {
|
catch (ResultException ex) {
|
||||||
dc.Dispose();
|
dc.Dispose();
|
||||||
dc = null;
|
dc = null;
|
||||||
Logger.Log("main", 4, "Discord", "An error occurred while running callbacks: {0}", ex);
|
Game.MainLogger.Log(4, "Discord", "An error occurred while running callbacks: {0}", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,9 +1,8 @@
|
|||||||
using Cryville.Audio.Source;
|
using Cryville.Audio.Source.Libav;
|
||||||
using Cryville.Crtr.Event;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
|
||||||
namespace Cryville.Crtr {
|
namespace Cryville.Crtr.Event {
|
||||||
public class ChartHandler : TransformHandler {
|
public class ChartHandler : TransformHandler {
|
||||||
protected override TransformHandler Parent { get { return null; } }
|
protected override TransformHandler Parent { get { return null; } }
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user