47 Commits

Author SHA1 Message Date
8c11be48cf Adapt resource manager to URI and list pattern. 2023-11-13 00:26:18 +08:00
9fcf6f3379 Remove ResourceItemMeta. 2023-11-13 00:23:08 +08:00
b45cf9cba7 Fix incorrect layout width for tabs on enable. 2023-11-12 01:05:06 +08:00
28234d9587 Replace menu scene in build settings. 2023-11-11 11:57:09 +08:00
1803e1dee7 Implement the new settings browser. 2023-11-11 11:56:36 +08:00
166478e4bb Implement browser tabs. 2023-11-11 11:54:52 +08:00
c05b771425 Add description property to property adapter. 2023-11-11 11:42:05 +08:00
9db2ded366 Rename render distance settings. 2023-11-11 11:40:48 +08:00
9aed79f599 Rearrange the categories of the settings. 2023-11-11 11:39:53 +08:00
221887e447 Code cleanup. 2023-11-10 15:01:44 +08:00
36013d4e47 Update Cryville.Common.Reflection. 2023-11-10 15:00:38 +08:00
cf8dda1ea2 Add animations for browser item tile. 2023-11-10 15:00:14 +08:00
0f4aec4355 Implement drafted new UI. 2023-11-10 14:59:28 +08:00
ddf738ee27 Pull down IPathedResourceManager. Reconstruct resource browser. 2023-11-10 14:57:52 +08:00
bd834cff4a Add tweener and state tweener. 2023-11-10 14:51:14 +08:00
adf5019e2a Add null check for some UI components. 2023-11-10 14:50:15 +08:00
a19a3d9b81 Remove use of animator in UI. 2023-11-10 14:48:17 +08:00
b50f771d6e Clean up hardcoded UI paths. 2023-11-10 14:45:23 +08:00
8089e724f9 Add single layout group. 2023-11-10 14:35:02 +08:00
18f9fbea60 Add safe area. 2023-11-10 14:34:47 +08:00
6ea487ff13 Import new UI assets. 2023-11-10 14:34:01 +08:00
a83b16c829 Remove UIElements package. 2023-11-10 14:33:07 +08:00
b48bd7b8ba Code cleanup. 2023-11-10 14:32:28 +08:00
b56722b2d1 Add vertical mode for ImageSliced3. 2023-11-07 16:17:41 +08:00
5854801a53 Fix UI pattern for AspectRatioLayoutElement. 2023-11-07 15:53:16 +08:00
668f46d260 Prevents matching the fallback script twice. 2023-11-03 00:26:37 +08:00
b672889008 Update fallback script. 2023-11-03 00:25:49 +08:00
08a12097a4 Forces one font instance per full name. 2023-11-03 00:24:25 +08:00
7535ce04f5 Update docs. 2023-11-02 12:16:55 +08:00
bede668e73 Update UnsafeIL. 2023-11-02 12:16:48 +08:00
c2c28518ba Exclude Discord Game SDK from Android builds. 2023-11-02 12:16:33 +08:00
bfa1423f64 Import Cryville.Culture in favor of ScriptUtils. 2023-11-02 12:15:38 +08:00
395c094890 Discard unused docs. 2023-11-02 12:11:41 +08:00
a284edd130 Add debug logs about environment and fonts. 2023-11-01 01:02:55 +08:00
b57959b4bf Update Cryville.Audio. 2023-11-01 01:01:13 +08:00
724cb10bc1 Import Cryville.Interop.Java. 2023-11-01 00:59:09 +08:00
97e759f57d Adjust the progress report from prehandler. 2023-10-08 01:00:12 +08:00
3ce8ad72ed Add dialogs for audio engine initialization error. 2023-10-08 00:58:43 +08:00
c23d79e3f5 Emits a warning on text frame not found. 2023-10-08 00:53:12 +08:00
71294db3c1 Optimize GC and performance for MonoPInvokeCallback. 2023-09-25 17:09:27 +08:00
825818679c Rearrange platform specific plugins. 2023-09-25 10:52:16 +08:00
84acb2c12d Add suppressions for plugins. 2023-09-25 09:33:10 +08:00
9c034c0f7b Code cleanup for font table. 2023-09-17 20:26:31 +08:00
aa7452aead Draft virtual player strategy. (Amend) 2023-08-24 23:45:57 +08:00
f86562b2f2 Draft virtual player strategy. 2023-08-24 23:44:13 +08:00
8fa2bd1e81 Code structure cleanup. (2) 2023-08-24 16:18:16 +08:00
1f58390298 Code structure cleanup. 2023-08-24 15:47:34 +08:00
388 changed files with 32879 additions and 3455 deletions

View File

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

View File

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

View File

@@ -1,4 +1,5 @@
using Cryville.Common.Culture;
using Cryville.Common.Logging;
using Cryville.Culture;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -7,20 +8,22 @@ namespace Cryville.Common.Font {
public abstract class FontMatcher {
protected FontManager Manager { get; private set; }
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 {
readonly LanguageMatching _matcher;
static readonly string UltimateFallbackScript = "zzzz";
public Dictionary<string, List<string>> MapScriptToTypefaces = new Dictionary<string, List<string>>();
public static Dictionary<string, List<string>> GetDefaultWindowsFallbackMap() {
var map = new Dictionary<string, List<string>>();
ScriptUtils.FillKeysWithScripts(map, () => new List<string>());
var map = new Dictionary<string, List<string>>(StringComparer.OrdinalIgnoreCase);
FillKeysWithScripts(map, () => new List<string>());
// Reference: https://github.com/chromium/chromium/blob/main/third_party/blink/renderer/platform/fonts/win/font_fallback_win.cc
map["zyyy"].Insert(0, "SimSun"); // Custom
map["zyyy"].Insert(0, "SimHei"); // Custom
map["zyyy"].Insert(0, "Microsoft YaHei"); // Custom
map["zyyy"].Insert(0, "Arial");
map["zyyy"].Insert(0, "Times New Roman");
map["zyyy"].Insert(0, "Segoe UI"); // Custom
map[UltimateFallbackScript].Insert(0, "SimSun"); // Custom
map[UltimateFallbackScript].Insert(0, "SimHei"); // Custom
map[UltimateFallbackScript].Insert(0, "Microsoft YaHei"); // Custom
map[UltimateFallbackScript].Insert(0, "Arial");
map[UltimateFallbackScript].Insert(0, "Times New Roman");
map[UltimateFallbackScript].Insert(0, "Segoe UI"); // Custom
map["arab"].Insert(0, "Tahoma");
map["cyrl"].Insert(0, "Times New Roman");
map["grek"].Insert(0, "Times New Roman");
@@ -158,12 +161,12 @@ namespace Cryville.Common.Font {
return map;
}
public static Dictionary<string, List<string>> GetDefaultAndroidFallbackMap() {
var map = new Dictionary<string, List<string>>();
ScriptUtils.FillKeysWithScripts(map, () => new List<string>());
map["zyyy"].Insert(0, "Noto Sans CJK TC"); // TODO Modify default fallback
map["zyyy"].Insert(0, "Noto Sans CJK JP");
map["zyyy"].Insert(0, "Noto Sans CJK SC");
map["zyyy"].Insert(0, "Roboto");
var map = new Dictionary<string, List<string>>(StringComparer.OrdinalIgnoreCase);
FillKeysWithScripts(map, () => new List<string>());
map[UltimateFallbackScript].Insert(0, "Noto Sans CJK TC"); // TODO Modify default fallback
map[UltimateFallbackScript].Insert(0, "Noto Sans CJK JP");
map[UltimateFallbackScript].Insert(0, "Noto Sans CJK SC");
map[UltimateFallbackScript].Insert(0, "Roboto");
map["zsye"].Insert(0, "Noto Color Emoji");
map["zsye"].Add("Noto Color Emoji Flags");
map["arab"].Insert(0, "Noto Naskh Arabic");
@@ -275,9 +278,9 @@ namespace Cryville.Common.Font {
map["sund"].Insert(0, "Noto Sans Sundanese");
map["sylo"].Insert(0, "Noto Sans Syloti Nagri");
map["zsym"].Insert(0, "Noto Sans Symbols");
map["syrn"].Insert(0, "Noto Sans Syriac Eastern");
map["syre"].Insert(0, "Noto Sans Syriac Estrangela");
map["syrj"].Insert(0, "Noto Sans Syriac Western");
map["syrc"].Add("Noto Sans Syriac Eastern");
map["syrc"].Add("Noto Sans Syriac Western");
map["syrc"].Add("Noto Sans Syriac Estrangela");
map["tglg"].Insert(0, "Noto Sans Tagalog");
map["tagb"].Insert(0, "Noto Sans Tagbanwa");
map["tale"].Insert(0, "Noto Sans Tai Le");
@@ -296,33 +299,47 @@ namespace Cryville.Common.Font {
map["yiii"].Insert(0, "Noto Sans Yi");
return map;
}
public FallbackListFontMatcher(FontManager manager) : base(manager) { }
public override IEnumerable<Typeface> MatchScript(string script = null, bool distinctFamily = false) {
if (string.IsNullOrEmpty(script)) script = ScriptUtils.UltimateFallbackScript;
List<string> candidates;
IEnumerable<string> candidateScripts = new string[] { script };
while (candidateScripts != null) {
foreach (var candidateScript in candidateScripts) {
if (MapScriptToTypefaces.TryGetValue(candidateScript, out candidates)) {
foreach (var candidate in candidates) {
IReadOnlyCollection<Typeface> typefaces1;
if (Manager.MapFullNameToTypeface.TryGetValue(candidate, out typefaces1)) {
foreach (var typeface in typefaces1) {
yield return typeface;
}
}
if (distinctFamily) continue;
IReadOnlyCollection<Typeface> typefaces2;
if (Manager.MapNameToTypefaces.TryGetValue(candidate, out typefaces2)) {
foreach (var typeface in typefaces2) {
if (typefaces1.Contains(typeface)) continue;
yield return typeface;
}
}
}
static void FillKeysWithScripts<T>(IDictionary<string, T> map, Func<T> value) {
foreach (var s in IdValidity.Enumerate("script")) map.Add(s, value());
}
public FallbackListFontMatcher(LanguageMatching matcher, FontManager manager) : base(manager) {
_matcher = matcher;
}
public override IEnumerable<Typeface> MatchLanguage(LanguageId lang, bool distinctFamily = false) {
var supported = MapScriptToTypefaces.Keys.Select(i => new LanguageId(i)).ToList();
bool flag = false;
while (_matcher.Match(lang, supported, out var match, out var distance)) {
if (distance > 40) break;
Logger.Log("main", 0, "UI", "Matching fonts for language {0}, distance = {1}", match, distance);
if (match.Script.Equals(UltimateFallbackScript, StringComparison.OrdinalIgnoreCase)) {
flag = true;
}
var candidates = MapScriptToTypefaces[match.Script];
foreach (var typeface in EnumerateTypefaces(candidates, distinctFamily)) {
yield return typeface;
}
supported.Remove(match);
}
if (flag) yield break;
Logger.Log("main", 0, "UI", "Matching fallback fonts");
foreach (var typeface in EnumerateTypefaces(MapScriptToTypefaces[UltimateFallbackScript], distinctFamily)) {
yield return typeface;
}
}
IEnumerable<Typeface> EnumerateTypefaces(List<string> candidates, bool distinctFamily) {
foreach (var candidate in candidates) {
if (Manager.MapFullNameToTypeface.TryGetValue(candidate, out var typeface1)) {
yield return typeface1;
}
if (distinctFamily) continue;
IReadOnlyCollection<Typeface> typefaces2;
if (Manager.MapNameToTypefaces.TryGetValue(candidate, out typefaces2)) {
foreach (var typeface in typefaces2) {
if (typeface1 == typeface) continue;
yield return typeface;
}
}
candidateScripts = ScriptUtils.EnumerateFallbackScripts(script);
}
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -3,8 +3,10 @@ using Cryville.Common.Unity;
using Cryville.Crtr.Extension;
using Cryville.Crtr.Extensions;
using Cryville.Crtr.Extensions.Umg;
using Cryville.Crtr.UI;
using Newtonsoft.Json;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
@@ -12,14 +14,17 @@ using UnityEngine;
using Logger = Cryville.Common.Logging.Logger;
namespace Cryville.Crtr.Browsing {
internal class LegacyResourceManager : IResourceManager<ChartDetail> {
internal class LegacyResourceManager : IPathedResourceManager<ChartDetail> {
private readonly string _rootPath;
private DirectoryInfo cd;
private DirectoryInfo[] items = new DirectoryInfo[0];
public string[] CurrentDirectory { get; private set; }
public int Count { get { return items.Length; } }
static bool _init;
public event Action ItemChanged;
public LegacyResourceManager(string rootPath) {
_rootPath = rootPath;
if (!_init) {
@@ -28,94 +33,66 @@ namespace Cryville.Crtr.Browsing {
}
}
public int ChangeDirectory(string[] dir) {
public void ChangeDirectory(string[] dir) {
CurrentDirectory = dir;
cd = new DirectoryInfo(_rootPath + "/charts/" + string.Join("/", dir));
items = cd.GetDirectories();
return items.Length;
ItemChanged?.Invoke();
}
public int OpenDirectory(int id) {
public void OpenDirectory(int id) {
string[] nd = new string[CurrentDirectory.Length + 1];
Array.Copy(CurrentDirectory, nd, CurrentDirectory.Length);
nd[CurrentDirectory.Length] = items[id].Name;
return ChangeDirectory(nd);
ChangeDirectory(nd);
}
public int ReturnToDirectory(int id) {
string[] nd = new string[id + 1];
Array.Copy(CurrentDirectory, nd, id + 1);
return ChangeDirectory(nd);
public void ReturnToDirectory(int index) {
string[] nd = new string[index + 1];
Array.Copy(CurrentDirectory, nd, index + 1);
ChangeDirectory(nd);
}
public ResourceItemMeta GetItemMeta(int id) {
public ChartDetail this[int index] {
get {
var item = items[index];
ChartMeta meta = null;
var metaFile = new FileInfo(Path.Combine(item.FullName, ".umgc"));
if (metaFile.Exists) {
using (var reader = new StreamReader(metaFile.FullName)) {
meta = JsonConvert.DeserializeObject<ChartMeta>(reader.ReadToEnd());
}
}
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 {
Cover = cover,
Meta = meta,
};
}
}
public Uri GetItemUri(int id) {
var item = items[id];
var meta = new ChartMeta();
string name = item.Name;
string desc = "(Unknown)";
var metaFile = new FileInfo(item.FullName + "/.umgc");
if (metaFile.Exists) {
using (var reader = new StreamReader(metaFile.FullName)) {
meta = JsonConvert.DeserializeObject<ChartMeta>(reader.ReadToEnd());
name = meta.song.name;
desc = meta.name;
}
}
AsyncDelivery<Texture2D> cover = null;
if (meta.cover != null && meta.cover != "") {
var coverFile = item.GetFiles(meta.cover);
if (coverFile.Length > 0) {
cover = new AsyncDelivery<Texture2D>();
var task = new LoadTextureTask(PlatformConfig.FileProtocolPrefix + coverFile[0].FullName, cover.Deliver);
cover.CancelSource = task.Cancel;
Game.NetworkTaskWorker.SubmitNetworkTask(task);
}
}
return new ResourceItemMeta {
IsDirectory = false,
Icon = cover,
Name = name,
DescriptionMain = desc,
};
}
public ChartDetail GetItemDetail(int id) {
var item = items[id];
var meta = new ChartMeta();
var metaFile = new FileInfo(item.FullName + "/.umgc");
if (metaFile.Exists) {
using (var reader = new StreamReader(metaFile.FullName)) {
meta = JsonConvert.DeserializeObject<ChartMeta>(reader.ReadToEnd());
}
}
AsyncDelivery<Texture2D> cover = null;
if (meta.cover != null && meta.cover != "") {
var coverFile = item.GetFiles(meta.cover);
if (coverFile.Length > 0) {
cover = new AsyncDelivery<Texture2D>();
var task = new LoadTextureTask(PlatformConfig.FileProtocolPrefix + coverFile[0].FullName, cover.Deliver);
cover.CancelSource = task.Cancel;
Game.NetworkTaskWorker.SubmitNetworkTask(task);
}
}
return new ChartDetail {
Cover = cover,
Meta = meta,
};
}
public string GetItemPath(int id) {
var item = items[id];
var meta = new ChartMeta();
var metaFile = new FileInfo(item.FullName + "/.umgc");
var metaFile = new FileInfo(Path.Combine(item.FullName, ".umgc"));
using (var reader = new StreamReader(metaFile.FullName)) {
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) {
var file = new FileInfo(path);
public bool ImportItemFrom(Uri uri) {
if (!uri.IsFile) throw new NotSupportedException();
var file = new FileInfo(uri.LocalPath);
IEnumerable<ResourceConverter> converters;
if (!ExtensionManager.TryGetConverters(file.Extension, out converters)) return false;
foreach (var converter in converters) {
@@ -191,6 +168,27 @@ namespace Cryville.Crtr.Browsing {
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;
public ChartDetail Current => throw new NotImplementedException();
object IEnumerator.Current => Current;
public Enumerator(LegacyResourceManager list) { _list = list; }
public void Dispose() { }
public bool MoveNext() {
throw new NotImplementedException();
}
public void Reset() {
throw new NotImplementedException();
}
}
void LogAndPopup(int level, string format, params object[] args) {
var msg = string.Format(format, args);
Logger.Log("main", level, "Resource", msg);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -0,0 +1,83 @@
using Cryville.Common.Unity;
using Cryville.Common.Unity.UI;
using Cryville.Crtr.UI;
using System;
using System.Collections.Generic;
using UnityEngine;
namespace Cryville.Crtr.Browsing.UI {
public class PathedResourceBrowser : ResourceBrowser {
public IPathedResourceManager<ChartDetail> ResourceManager;
public ScrollableItemGrid ItemContainer;
readonly HashSet<int> _selectedItems = new HashSet<int>();
readonly Dictionary<int, BrowserItem> _items = new Dictionary<int, BrowserItem>();
FileDialog _dialog;
protected virtual void Start() {
ItemContainer.LoadItem = LoadItem;
ResourceManager.ItemChanged += OnItemChanged;
ResourceManager.ChangeDirectory(new string[] { "" });
InitDialog();
}
protected void InitDialog() {
_dialog = Instantiate(Resources.Load<GameObject>("Common/FileDialog")).GetComponent<FileDialog>();
_dialog.gameObject.SetActive(false);
_dialog.Filter = ResourceManager.GetSupportedFormats();
_dialog.PresetPaths = ResourceManager.GetPresetPaths();
_dialog.OnClose += OnAddDialogClosed;
}
void OnItemChanged() {
ItemContainer.ItemCount = ResourceManager.Count;
_selectedItems.Clear();
_items.Clear();
}
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 id) {
ResourceManager.ReturnToDirectory(id);
}
public void OnAddButtonClicked() {
_dialog.Show();
}
private void OnAddDialogClosed() {
if (_dialog.FileName == null) return;
if (ResourceManager.ImportItemFrom(new Uri(_dialog.FileName))) {
Popup.Create("Import succeeded");
OnPathClicked(ResourceManager.CurrentDirectory.Length - 1);
}
else {
Popup.Create("Import failed");
}
}
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,6 +1,7 @@
using Cryville.Common;
using Cryville.Common.Collections.Specialized;
using Cryville.Common.Pdt;
using Cryville.Crtr.Ruleset;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;

View File

@@ -2,6 +2,9 @@ using Cryville.Common;
using Cryville.Common.Buffers;
using Cryville.Crtr.Config;
using Cryville.Crtr.Event;
using Cryville.Crtr.Ruleset;
using Cryville.Crtr.Skin;
using Cryville.Crtr.UI;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
@@ -22,9 +25,9 @@ namespace Cryville.Crtr {
public class ChartPlayer : MonoBehaviour {
#region Fields
Chart chart;
Skin skin;
SkinDefinition skin;
public static PdtSkin pskin;
Ruleset ruleset;
RulesetDefinition ruleset;
PdtRuleset pruleset;
Dictionary<string, Texture2D> texs;
public static Dictionary<string, SpriteFrame> frames;
@@ -71,7 +74,7 @@ namespace Cryville.Crtr {
logs = logobj.GetComponent<TextMeshProUGUI>();
if (!initialized) {
Game.Init();
GenericResources.LoadDefault();
BuiltinResources.LoadDefault();
initialized = true;
}
OnSettingsUpdate();
@@ -265,12 +268,12 @@ namespace Cryville.Crtr {
"\nStates: c{0} / b{1}",
cbus.ActiveStateCount, bbus.ActiveStateCount
);
var aTime = Game.AudioClient.Position;
var aTime = Game.AudioClient.Position - atime0;
var iTime = inputProxy.GetTimestampAverage();
statusbuf.AppendFormat(
"\nSTime: {0:G9}s {5} {6}\nATime: {1:G9}s ({3:+0.0ms;-0.0ms;0}) {5} {6}\nITime: {2:G9}s ({4:+0.0ms;-0.0ms;0}) {5} {7}",
cbus.Time, aTime, iTime,
(aTime - atime0 - cbus.Time) * 1e3,
(aTime - cbus.Time) * 1e3,
(iTime - cbus.Time) * 1e3,
forceSyncFrames != 0 ? "(force sync)" : "",
paused ? "(paused)" : "",
@@ -364,8 +367,8 @@ namespace Cryville.Crtr {
#region Load
void Play() {
disableGC = Settings.Default.DisableGC;
clippingDist = Settings.Default.BackwardClippingDistance;
renderDist = Settings.Default.RenderDistance;
clippingDist = Settings.Default.BackwardRenderDistance;
renderDist = Settings.Default.ForwardRenderDistance;
renderStep = Settings.Default.RenderStep;
actualRenderStep = renderStep;
autoRenderStep = renderStep == 0;
@@ -417,10 +420,10 @@ namespace Cryville.Crtr {
);
if (!skinFile.Exists) throw new FileNotFoundException("Skin not found\nPlease specify an available skin in the config");
using (StreamReader reader = new StreamReader(skinFile.FullName, Encoding.UTF8)) {
skin = JsonConvert.DeserializeObject<Skin>(reader.ReadToEnd(), new JsonSerializerSettings() {
skin = JsonConvert.DeserializeObject<SkinDefinition>(reader.ReadToEnd(), new JsonSerializerSettings() {
MissingMemberHandling = MissingMemberHandling.Error
});
if (skin.format != Skin.CURRENT_FORMAT) throw new FormatException("Invalid skin file version");
if (skin.format != SkinDefinition.CURRENT_FORMAT) throw new FormatException("Invalid skin file version");
}
loadThread = new Thread(new ParameterizedThreadStart(Load));
@@ -497,22 +500,22 @@ namespace Cryville.Crtr {
IEnumerator<float> Prehandle() {
Stopwatch timer = new Stopwatch();
timer.Reset(); timer.Start();
Logger.Log("main", 0, "Load/Prehandle", "Prehandling (iteration 2)"); yield return .00f;
Logger.Log("main", 0, "Load/Prehandle", "Prehandling (iteration 2)"); yield return 0;
cbus.BroadcastPreInit();
Logger.Log("main", 0, "Load/Prehandle", "Prehandling (iteration 3)"); yield return .05f;
Logger.Log("main", 0, "Load/Prehandle", "Prehandling (iteration 3)"); yield return 0;
using (var pbus = cbus.Clone(17)) {
while (pbus.Time != double.PositiveInfinity) {
pbus.ForwardOnce();
yield return (float)pbus.EventId / pbus.EventCount * .80f + .05f;
yield return (float)pbus.EventId / pbus.EventCount;
}
}
Logger.Log("main", 0, "Load/Prehandle", "Prehandling (iteration 4)"); yield return .85f;
Logger.Log("main", 0, "Load/Prehandle", "Prehandling (iteration 4)"); yield return 1;
cbus.BroadcastPostInit();
Logger.Log("main", 0, "Load/Prehandle", "Seeking to start offset"); yield return .90f;
Logger.Log("main", 0, "Load/Prehandle", "Seeking to start offset"); yield return 1;
cbus.ForwardByTime(startOffset);
bbus.ForwardByTime(startOffset);
Game.AudioSequencer.SeekTime(startOffset, SeekOrigin.Current);
Logger.Log("main", 0, "Load/Prehandle", "Cleaning up"); yield return .95f;
Logger.Log("main", 0, "Load/Prehandle", "Cleaning up"); yield return 1;
if (logEnabled && Settings.Default.HideLogOnPlay) ToggleLogs();
Camera.main.cullingMask |= 1;
GC.Collect();
@@ -526,7 +529,7 @@ namespace Cryville.Crtr {
logs.text = "";
}
Game.AudioSequencer.Playing = true;
atime0 = Game.AudioClient.Position - startOffset;
atime0 = Game.AudioClient.BufferPosition - startOffset;
inputProxy.SyncTime(cbus.Time);
inputProxy.Activate();
}
@@ -682,10 +685,10 @@ namespace Cryville.Crtr {
DirectoryInfo dir = file.Directory;
Logger.Log("main", 0, "Load/WorkerThread", "Loading ruleset: {0}", file);
using (StreamReader reader = new StreamReader(file.FullName, Encoding.UTF8)) {
ruleset = JsonConvert.DeserializeObject<Ruleset>(reader.ReadToEnd(), new JsonSerializerSettings() {
ruleset = JsonConvert.DeserializeObject<RulesetDefinition>(reader.ReadToEnd(), new JsonSerializerSettings() {
MissingMemberHandling = MissingMemberHandling.Error
});
if (ruleset.format != Ruleset.CURRENT_FORMAT) throw new FormatException("Invalid ruleset file version");
if (ruleset.format != RulesetDefinition.CURRENT_FORMAT) throw new FormatException("Invalid ruleset file version");
ruleset.LoadPdt(dir);
pruleset = ruleset.Root;
pruleset.Optimize(PdtEvaluator.Instance);

View File

@@ -8,6 +8,7 @@ namespace Cryville.Crtr.Config {
public interface IPropertyAdapter {
string Category { get; }
string Name { get; }
string Description { get; }
PropertyType Type { get; }
object[] Range { get; }
object GetValue();
@@ -31,6 +32,7 @@ namespace Cryville.Crtr.Config {
readonly PropertyInfo _prop;
public string Category { get; private set; }
public string Name { get; private set; }
public string Description { get; private set; }
public PropertyType Type { get; private set; }
public object[] Range { get; private set; }
public object GetValue() { return _prop.GetValue(_target, null); }
@@ -68,6 +70,8 @@ namespace Cryville.Crtr.Config {
var attrs = prop.GetCustomAttributes(typeof(CategoryAttribute), true);
if (attrs.Length > 0) Category = ((CategoryAttribute)attrs.Single()).Category;
Name = prop.Name;
var attrs2 = prop.GetCustomAttributes(typeof(DescriptionAttribute), true);
if (attrs2.Length > 0) Description = ((DescriptionAttribute)attrs2.Single()).Description;
if (prop.PropertyType == typeof(bool)) Type = PropertyType.Boolean;
else if (prop.PropertyType == typeof(char)) throw new NotSupportedException();
else if (prop.PropertyType.IsPrimitive) {

View File

@@ -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;
}
}
}

View File

@@ -1,5 +1,6 @@
using Cryville.Common;
using Cryville.Common.Pdt;
using Cryville.Crtr.Ruleset;
using System;
using System.Collections.Generic;
@@ -53,8 +54,8 @@ namespace Cryville.Crtr.Config {
}
public string Category { get { return _def.category; } }
public string Name { get; private set; }
public string Description { get { return null; } }
public PropertyType Type { get; private set; }

View File

@@ -1,5 +1,6 @@
using Cryville.Common;
using Cryville.Common.Collections.Specialized;
using Cryville.Crtr.Ruleset;
using System;
using System.Collections.Generic;

View File

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

View File

@@ -1,3 +1,5 @@
using Cryville.Crtr.Ruleset;
using Cryville.Crtr.UI;
using Newtonsoft.Json;
using System;
using System.IO;
@@ -5,7 +7,7 @@ using System.Text;
using UnityEngine;
using Logger = Cryville.Common.Logging.Logger;
namespace Cryville.Crtr.Config {
namespace Cryville.Crtr.Config.UI {
public class ConfigPanelMaster : MonoBehaviour {
[SerializeField]
Menu m_menu;
@@ -22,7 +24,7 @@ namespace Cryville.Crtr.Config {
[SerializeField]
InputConfigPanel m_inputConfigPanel;
public Ruleset ruleset;
public RulesetDefinition ruleset;
RulesetConfig _rscfg;
bool _loaded;
@@ -38,10 +40,10 @@ namespace Cryville.Crtr.Config {
}
DirectoryInfo dir = file.Directory;
using (StreamReader reader = new StreamReader(file.FullName, Encoding.UTF8)) {
ruleset = JsonConvert.DeserializeObject<Ruleset>(reader.ReadToEnd(), new JsonSerializerSettings() {
ruleset = JsonConvert.DeserializeObject<RulesetDefinition>(reader.ReadToEnd(), new JsonSerializerSettings() {
MissingMemberHandling = MissingMemberHandling.Error
});
if (ruleset.format != Ruleset.CURRENT_FORMAT) throw new FormatException("Invalid ruleset file version");
if (ruleset.format != RulesetDefinition.CURRENT_FORMAT) throw new FormatException("Invalid ruleset file version");
ruleset.LoadPdt(dir);
}
FileInfo cfgfile = new FileInfo(

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 54c06a15adfb41548acca0d73f391fe7
guid: bad1f43573d4f1143a94fddddd30fb81
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -1,12 +1,13 @@
using Cryville.Common;
using Cryville.Common.Unity;
using Cryville.Crtr.Ruleset;
using Cryville.Input;
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace Cryville.Crtr.Config {
namespace Cryville.Crtr.Config.UI {
public class InputConfigPanel : MonoBehaviour {
[SerializeField]
ConfigPanelMaster m_configScene;

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: d27589834da67984d98c6147c8b6b5bb
guid: 279d2404a312e5543813d8aca02800b8
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -1,9 +1,10 @@
using Cryville.Common;
using Cryville.Crtr.Ruleset;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
namespace Cryville.Crtr.Config {
namespace Cryville.Crtr.Config.UI {
public class InputConfigPanelEntry : MonoBehaviour {
[SerializeField]
Text m_key;

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 8661f4d4934e11040a0c65729d4ba47a
guid: 9741a0ed8c1c5e0468ea89f2cf33f36c
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -1,13 +1,11 @@
using UnityEngine;
using UnityEngine.EventSystems;
namespace Cryville.Crtr.Config {
namespace Cryville.Crtr.Config.UI {
public class PVPBool : PropertyValuePanel, IPointerClickHandler {
[SerializeField]
RectTransform m_on;
[SerializeField]
RectTransform m_handleArea;
[SerializeField]
RectTransform m_handle;
protected override void OnValueUpdated() { }
@@ -31,10 +29,6 @@ namespace Cryville.Crtr.Config {
UpdateGraphics();
}
}
void OnRectTransformDimensionsChange() {
m_handleArea.sizeDelta = new Vector2(m_handle.rect.height - m_handle.rect.width, 0);
}
#pragma warning restore IDE0051
void UpdateGraphics() {

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 362a7cfafb57b9f46bbca9ed88d18c53
guid: 9cb1bc40304ff174f891239c8f450c1c
MonoImporter:
externalObjects: {}
serializedVersion: 2

View 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;
}
}
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 5b5d86b95e0bf894b86c63127d5ac06c
guid: 94cb9dad5ac3eb04ca16d58a7bae0cb5
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -1,57 +1,69 @@
using System;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
namespace Cryville.Crtr.Config {
public abstract class PVPNumberBase : PropertyValuePanel {
[SerializeField]
EventTrigger m_ctn;
namespace Cryville.Crtr.Config.UI {
public abstract class PVPNumberBase : PropertyValuePanel, IInitializePotentialDragHandler, IDragHandler, IEndDragHandler, IPointerClickHandler {
[SerializeField]
RectTransform m_handleArea;
[SerializeField]
Image m_handle;
[SerializeField]
Text m_text;
#pragma warning disable IDE0051
TMP_InputField m_text;
protected void Start() {
var ev = new EventTrigger.Entry { eventID = EventTriggerType.InitializePotentialDrag };
ev.callback.AddListener(e => OnInitializePotentialDrag((PointerEventData)e));
m_ctn.triggers.Add(ev);
ev = new EventTrigger.Entry { eventID = EventTriggerType.Drag };
ev.callback.AddListener(e => OnDrag((PointerEventData)e));
m_ctn.triggers.Add(ev);
ev = new EventTrigger.Entry { eventID = EventTriggerType.EndDrag };
ev.callback.AddListener(e => OnEndDrag((PointerEventData)e));
m_ctn.triggers.Add(ev);
ev = new EventTrigger.Entry { eventID = EventTriggerType.PointerClick };
ev.callback.AddListener(e => OnPointerClick((PointerEventData)e));
m_ctn.triggers.Add(ev);
m_text.interactable = SetMapped;
m_text.onValueChanged.AddListener(OnTextEdited);
m_text.onDeselect.AddListener(OnTextDeselected);
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() {
m_text.text = MappedValue.ToString();
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();
}
}
protected virtual void OnIdle() { }
void Update() {
protected virtual void Update() {
if (use) {
SetRatio(GetRatioFromPos(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;
Vector2 pp;
bool use, nouse;
public void OnInitializePotentialDrag(PointerEventData eventData) {
eventData.useDragThreshold = false;
// eventData.useDragThreshold = false;
pp = eventData.position;
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 32fb9b8479cd8294296453d1aa651ff4
guid: c928ece9c4b30f04cb33f66eb9f050b3
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -1,6 +1,6 @@
using System;
namespace Cryville.Crtr.Config {
namespace Cryville.Crtr.Config.UI {
public class PVPNumberStepped : PVPNumberBase {
protected override void OnIdle() {
SetRatio(0.5f);

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: f754d98e38098654a878fc9121db536d
guid: c309650ed758ea34ba64e765f59bb043
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -1,6 +1,6 @@
using UnityEngine.UI;
namespace Cryville.Crtr.Config {
namespace Cryville.Crtr.Config.UI {
public class PVPString : PropertyValuePanel {
protected override void OnValueUpdated() { _inputField.text = (string)MappedValue; }

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 1b9a6e3b503784e4aa78215e9b004a8f
guid: f81596a59a59fce48854b6753fe8cfc6
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -1,33 +1,27 @@
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace Cryville.Crtr.Config {
namespace Cryville.Crtr.Config.UI {
public class PropertyCategoryPanel : MonoBehaviour {
[SerializeField]
private GameObject m_propertyPrefab;
GameObject m_propertyPrefab;
Text _nameLabel = null;
[SerializeField]
TextMeshProUGUI m_nameLabel;
string _name;
string m_name;
public string Name {
get { return _name; }
set { _name = value; UpdateName(); }
get { return m_name; }
set { m_name = value; UpdateName(); }
}
bool _collapsed = false;
bool m_collapsed = false;
public bool Collapsed {
get { return _collapsed; }
set { _collapsed = value; UpdateName(); }
get { return m_collapsed; }
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) {
Name = name.ToUpper();
foreach (var prop in props) {
@@ -36,7 +30,7 @@ namespace Cryville.Crtr.Config {
}
}
void ToggleCollapsed() {
public void ToggleCollapsed() {
Collapsed = !Collapsed;
for (int i = 1; i < transform.childCount; i++) {
transform.GetChild(i).gameObject.SetActive(!Collapsed);
@@ -44,7 +38,7 @@ namespace Cryville.Crtr.Config {
}
private void UpdateName() {
_nameLabel.text = (Collapsed ? "+ " : "- ") + Name;
m_nameLabel.text = (Collapsed ? "+ " : "- ") + Name;
}
}
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 71da54f24b65d2f41a00c5a4bd0ff1bf
guid: 11c5451aac09cbd4a8e94c82d5c568e8
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -1,7 +1,7 @@
using System.Collections.Generic;
using UnityEngine;
namespace Cryville.Crtr.Config {
namespace Cryville.Crtr.Config.UI {
public class PropertyMasterPanel : MonoBehaviour {
[SerializeField]
GameObject m_categoryPrefab;

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 4e6129746af547242bfa4e7404185936
guid: f8d04667a373e4648a83440b496c8127
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -1,7 +1,7 @@
using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace Cryville.Crtr.Config {
namespace Cryville.Crtr.Config.UI {
public class PropertyPanel : MonoBehaviour {
[SerializeField]
GameObject m_bool;
@@ -12,18 +12,15 @@ namespace Cryville.Crtr.Config {
[SerializeField]
GameObject m_string;
Text _key;
Transform _valueContainer;
[SerializeField]
TextMeshProUGUI m_key;
[SerializeField]
Transform m_valueContainer;
PropertyValuePanel _value;
#pragma warning disable IDE0051
void Awake() {
_key = transform.Find("Key").GetComponent<Text>();
_valueContainer = transform.Find("Value");
}
#pragma warning restore IDE0051
public void Load(IPropertyAdapter prop) {
_key.text = prop.Name;
m_key.text = prop.Name;
GameObject vp;
switch (prop.Type) {
@@ -33,7 +30,7 @@ namespace Cryville.Crtr.Config {
case PropertyType.String: vp = m_string; break;
default: return;
}
_value = Instantiate(vp, _valueContainer, false).GetComponent<PropertyValuePanel>();
_value = Instantiate(vp, m_valueContainer, false).GetComponent<PropertyValuePanel>();
_value.Init(prop);
}
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: e47c05cfd69aa3f4d9886293e66877e9
guid: 0a812a9e54dd057459b501c0881b0f68
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -1,6 +1,6 @@
using UnityEngine;
namespace Cryville.Crtr.Config {
namespace Cryville.Crtr.Config.UI {
public abstract class PropertyValuePanel : MonoBehaviour {
IPropertyAdapter _property;
public void Init(IPropertyAdapter property) {
@@ -8,8 +8,16 @@ namespace Cryville.Crtr.Config {
_property.ValueChanged += GetValue;
GetValue();
}
protected bool SetMapped { get { return _property.SetMapped; } }
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;
public object RawValue {
get { return m_rawValue; }
@@ -21,19 +29,19 @@ namespace Cryville.Crtr.Config {
protected abstract void OnValueUpdated();
void GetValue() {
if (_property.SetMapped) {
MappedValue = _property.GetValue();
m_rawValue = _property.MapValueInverse(MappedValue);
m_mappedValue = _property.GetValue();
m_rawValue = _property.MapValueInverse(m_mappedValue);
}
else {
m_rawValue = _property.GetValue();
MappedValue = _property.MapValue(m_rawValue);
m_mappedValue = _property.MapValue(m_rawValue);
}
OnValueUpdated();
}
void SetValue() {
var outRaw = RawValue;
MappedValue = _property.MapValue(outRaw);
_property.SetValue(_property.SetMapped ? MappedValue : outRaw);
m_mappedValue = _property.MapValue(outRaw);
_property.SetValue(_property.SetMapped ? m_mappedValue : outRaw);
OnValueUpdated();
}
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: c71cc11a0b1429c4fac91296bf8c5a63
guid: aa6b204c7a1fd1d4c95d912196fc7566
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -1,11 +1,17 @@
#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
#define COMPILE
#endif
#if COMPILE
using Discord;
using System;
using UnityEngine;
using Logger = Cryville.Common.Logging.Logger;
#endif
using UnityEngine;
namespace Cryville.Crtr {
internal class DiscordController : MonoBehaviour {
#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
#if COMPILE
public static DiscordController Instance;
const long CLIENT_ID = 1059021675578007622L;

View File

@@ -1,9 +1,8 @@
using Cryville.Audio.Source;
using Cryville.Crtr.Event;
using Cryville.Audio.Source.Libav;
using System.Collections.Generic;
using System.IO;
namespace Cryville.Crtr {
namespace Cryville.Crtr.Event {
public class ChartHandler : TransformHandler {
protected override TransformHandler Parent { get { return null; } }

View File

@@ -1,8 +1,7 @@
fileFormatVersion: 2
guid: d8339b62359a4eb428e5d7939a0e8fe4
timeCreated: 1593870951
licenseType: Pro
guid: 59e25dacd9b4d1f45b1da3a381187560
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0

View File

@@ -1,7 +1,8 @@
using Cryville.Common;
using Cryville.Common.Buffers;
using Cryville.Common.Collections.Specialized;
using Cryville.Crtr.Components;
using Cryville.Crtr.Ruleset;
using Cryville.Crtr.Skin;
using System;
using System.Collections.Generic;
using System.Globalization;

View File

@@ -2,6 +2,8 @@ using Cryville.Common;
using Cryville.Common.Buffers;
using Cryville.Common.Collections.Specialized;
using Cryville.Common.Pdt;
using Cryville.Crtr.Ruleset;
using Cryville.Crtr.Skin;
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;

View File

@@ -1,3 +1,5 @@
using Cryville.Crtr.Ruleset;
using Cryville.Crtr.Skin;
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;

View File

@@ -1,9 +1,8 @@
using Cryville.Common.Math;
using Cryville.Crtr.Event;
using System;
using UnityEngine;
namespace Cryville.Crtr {
namespace Cryville.Crtr.Event {
public class GroupHandler : TransformHandler {
protected override TransformHandler Parent { get { return _ch; } }
public ChartHandler _ch;

View File

@@ -1,8 +1,7 @@
fileFormatVersion: 2
guid: 1d6ad7170a6c76248a8ec305e98a75b2
timeCreated: 1599459182
licenseType: Pro
guid: a254d6c958ea6c5409991bde44e67635
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0

View File

@@ -1,16 +1,16 @@
using Cryville.Common;
using Cryville.Crtr.Components;
using Cryville.Crtr.Event;
using Cryville.Crtr.Ruleset;
using Cryville.Crtr.Skin.Components;
using System;
using System.Collections.Generic;
using UnityEngine;
namespace Cryville.Crtr {
namespace Cryville.Crtr.Event {
public class NoteHandler : ContainerHandler {
readonly GroupHandler gh;
public readonly Chart.Note Event;
readonly Chart.Note _note;
public NoteHandler(Chart.Note ev, GroupHandler gh) : base() {
Event = ev;
_note = ev;
this.gh = gh;
}
@@ -43,7 +43,7 @@ namespace Cryville.Crtr {
public override void PreInit() {
base.PreInit();
foreach (var j in Event.judges) {
foreach (var j in _note.judges) {
judges.Add(j, new JudgeState(this, j.Id.Key));
}
}
@@ -63,7 +63,7 @@ namespace Cryville.Crtr {
base.StartGraphicalUpdate(s);
TransformAwake(s);
if (RootTransform) {
if (Event.IsLong) {
if (_note.IsLong) {
foreach (var i in sgos) {
i.Reset();
i.AppendPoint(Position, Rotation);
@@ -88,7 +88,7 @@ namespace Cryville.Crtr {
if (s.CloneType <= 2) {
Position = GetFramePoint(s.Parent, s.Track);
Rotation = GetFrameRotation(s.Parent, s.Track);
if (s.CloneType == 2 && RootTransform && Event.IsLong) {
if (s.CloneType == 2 && RootTransform && _note.IsLong) {
foreach (var i in sgos)
i.AppendPoint(Position, Rotation);
}
@@ -131,7 +131,7 @@ namespace Cryville.Crtr {
}
Quaternion GetFrameRotation(ContainerState state, float track) {
var r = GetFrame(state, track, th => Quaternion.Euler(th.Direction) * Vector3.forward);
var r = GetFrame(state, track, th => th.Handler.Rotation * Vector3.forward);
return Quaternion.LookRotation(r, state.Normal);
}

View File

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

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