Skip to content

Commit 1a7cd45

Browse files
committed
make it buildable
1 parent e9aef84 commit 1a7cd45

12 files changed

Lines changed: 126 additions & 92 deletions

File tree

CustomKnight/NewUI/UIController.cs

Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
using UnityEngine.UI;
1+
using System.Linq;
2+
using CustomKnight.Next.Skin;
3+
using CustomKnight.Next.Skin.Enum;
4+
using UnityEngine.UI;
25

36
namespace CustomKnight.NewUI
47
{
@@ -134,42 +137,17 @@ public static void showMenu()
134137
UI.SetActive(true);
135138
}
136139

137-
public static Texture2D GetSkinIcon(ISelectableSkin skin)
140+
public static Texture2D GetSkinIcon(ISkin skin)
138141
{
139-
var orbIcon = "orbicon.png";
140-
var orbFull = "OrbFull.png";
141-
var knight = "knight.png";
142-
if (skin.Exists(orbIcon))
142+
var hasIcon = skin.GetFeatures().Contains(Feature.Icon);
143+
if (hasIcon)
143144
{
144-
return skin.GetTexture(orbIcon);
145+
return skin.GetIcon();
145146
}
146-
Texture2D defaultOrb = Texture2D.blackTexture;
147-
148-
if (skin.Exists(knight))
149-
{
150-
var defaultSkin = SkinManager.GetDefaultSkin();
151-
if (skin.Exists(orbFull))
152-
{
153-
defaultOrb = skin.GetTexture(orbFull);
154-
}
155-
else if (defaultSkin.Exists(orbFull))
156-
{
157-
defaultOrb = defaultSkin.GetTexture(orbFull);
158-
}
159-
var tex = skin.GetTexture(knight).GetCropped(new Rect(2802f, 4096f - 3155f, 86f, 120f));
160-
if (defaultOrb != Texture2D.blackTexture)
161-
{
162-
tex = SheetItem.Overlay(defaultOrb, tex, 50, 65);
163-
}
164-
DefaultSkin.Save(tex, skin.GetId(), orbIcon, false);
165-
return tex;
166-
}
167-
168-
//should never happen but still
169-
return defaultOrb;
147+
return Texture2D.blackTexture;
170148
}
171149

172-
public static void ApplySkin(ISelectableSkin skin)
150+
public static void ApplySkin(ISkin skin)
173151
{
174152
UIManager.instance.TogglePauseGame();
175153
CustomKnight.GlobalSettings.AddRecentSkin(skin.GetId());
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using System.IO;
2+
using CustomKnight.Next.Skin;
3+
4+
namespace CustomKnight.Next.Migrations
5+
{
6+
internal class GenerateSkinIconMigration : BaseMigration
7+
{
8+
public override void Run(MigrationContext context)
9+
{
10+
11+
var knightPath = Path.Combine(context.SkinPath, "knight", "knight.png");
12+
var orbFull = Path.Combine("ui","orbfull.png");
13+
var orbIcon = Path.Combine("ui", "orbicon.png");
14+
var OrbfullPath = Path.Combine(context.SkinPath, orbFull);
15+
var OrbIconPath = Path.Combine(context.SkinPath, orbIcon);
16+
if (File.Exists(OrbIconPath))
17+
{
18+
return;
19+
}
20+
Texture2D defaultOrb = Texture2D.blackTexture;
21+
22+
if (File.Exists(knightPath))
23+
{
24+
var defaultSkin = SkinManager.GetDefaultSkin();
25+
if (File.Exists(OrbfullPath))
26+
{
27+
defaultOrb = TextureUtils.LoadTextureFromFile(OrbfullPath);
28+
}
29+
else if (DefaultSkin.Exists(orbFull))
30+
{
31+
defaultOrb = DefaultSkin.GetTexture(orbFull);
32+
}
33+
var tex = TextureUtils.LoadTextureFromFile(knightPath).GetCropped(new Rect(2802f, 4096f - 3155f, 86f, 120f));
34+
if (defaultOrb != Texture2D.blackTexture)
35+
{
36+
tex = SheetItem.Overlay(defaultOrb, tex, 50, 65);
37+
}
38+
DefaultSkin.Save(tex, context.SkinName, orbIcon, false);
39+
}
40+
41+
}
42+
}
43+
}

CustomKnight/Next/Migrations/MigrationManager.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ static class MigrationManager
77
new CharmMigration(),
88
new GroupMigration(),
99
new GenerateSaveHudMigration(),
10+
new GenerateSkinIconMigration(),
1011
new KnownSwapIntegrationMigration(),
1112
new MigrateDirectorySwapsToNames(),
1213
new GenerateManifestMigration(),

CustomKnight/Next/Skin/Enum/Feature.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public enum Feature
99
Cinematics,
1010
SaveSelection,
1111
UserInterface,
12-
MainMenu
12+
MainMenu,
13+
Icon
1314
}
1415
}

CustomKnight/Next/Skin/Skin.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@ public interface ISkin
3232
/// </summary>
3333
/// <returns>A <c>ItemGroup</c>> representing all the item groups in the skin</returns>
3434
public abstract ItemGroup[] GetGroups();
35-
35+
Texture2D GetIcon();
3636
}
3737
}

CustomKnight/Skin/Base/Skin/StaticSkin.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ public StaticSkin(string DirectoryName)
3434
public SkinSettings GetSettings() => skinSettings;
3535
public ItemGroup[] GetGroups() => [.. items];
3636

37+
public Texture2D GetIcon()
38+
{
39+
throw new NotImplementedException();
40+
}
41+
3742
// might yeet all of these afterwards
3843
public bool shouldCache() => ShouldCache();
3944
public bool hasSwapper() => true;

CustomKnight/Skin/Base/SkinManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace CustomKnight
99
/// </summary>
1010
public static class SkinManager
1111
{
12-
internal static string DEFAULT_SKIN = "Default";
12+
internal static string DEFAULT_SKIN = "default";
1313
internal static bool savedDefaultTextures = false;
1414
/// <summary>
1515
/// Name of the Data directory

CustomKnight/Skin/Base/SpriteLoader.cs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace CustomKnight
1+
using CustomKnight.Next.Skin;
2+
3+
namespace CustomKnight
24
{
35
internal class SpriteLoader
46
{
@@ -95,18 +97,22 @@ internal static void LoadSprites()
9597
texture.missing = cachedTex.missing;
9698
continue;
9799
}
98-
texture.missing = !SkinManager.CurrentSkin.Exists(texture.fileName);
99-
if (!texture.missing)
100+
var currentSkin = SkinManager.CurrentSkin;
101+
if(currentSkin is ISelectableSkin deprecatedSkin)
100102
{
101-
texture.tex = SkinManager.CurrentSkin.GetTexture(texture.fileName);
102-
if (SkinManager.CurrentSkin.ShouldCache())
103+
texture.missing = !deprecatedSkin.Exists(texture.fileName);
104+
if (!texture.missing)
103105
{
104-
TextureCache.setSkinTextureCache(SkinManager.CurrentSkin.GetId(), texture.fileName, new CustomKnightTexture(texture.fileName, texture.missing, texture.defaultTex, texture.tex));
106+
texture.tex = deprecatedSkin.GetTexture(texture.fileName);
107+
if (currentSkin.ShouldCache())
108+
{
109+
TextureCache.setSkinTextureCache(deprecatedSkin.GetId(), texture.fileName, new CustomKnightTexture(texture.fileName, texture.missing, texture.defaultTex, texture.tex));
110+
}
111+
}
112+
else
113+
{
114+
texture.tex = null;
105115
}
106-
}
107-
else
108-
{
109-
texture.tex = null;
110116
}
111117
}
112118
TextureCache.trimTextureCache();

CustomKnight/Skin/Cinematics/CinematicsManager.cs

Lines changed: 23 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,6 @@ private static bool GetCiematicSafely(string name, out Cinematic cinematic)
6363
}
6464

6565

66-
public static bool HasCinematic(string CinematicName)
67-
{
68-
var cinematicUrl = GetCinematicUrl(CinematicName);
69-
return cinematicUrl.Length > 0;
70-
}
71-
7266
private static void XB1CinematicVideoPlayer_ctor(On.XB1CinematicVideoPlayer.orig_ctor orig, XB1CinematicVideoPlayer self, CinematicVideoPlayerConfig config)
7367
{
7468
orig(self, config);
@@ -80,60 +74,49 @@ private static void XB1CinematicVideoPlayer_ctor(On.XB1CinematicVideoPlayer.orig
8074
if (cinematicKvp.Value.OriginalVideo != null && (cinematicKvp.Value.OriginalVideo.originalPath == source.clip.originalPath))
8175
{
8276
cinematicKvp.Value.player = self;
83-
if (SkinManager.GetCurrentSkin().HasCinematic(cinematicKvp.Value.ClipName))
84-
{
85-
source.clip = null;
86-
source.url = SkinManager.GetCurrentSkin().GetCinematicUrl(cinematicKvp.Value.ClipName);
87-
source.Prepare();
88-
}
89-
else if (HasCinematic(cinematicKvp.Value.ClipName))
77+
var skin = SkinManager.GetCurrentSkin();
78+
if(skin is ISelectableSkin deprecatedSkin)
9079
{
91-
source.clip = null;
92-
source.url = GetCinematicUrl(cinematicKvp.Value.ClipName);
93-
source.Prepare();
80+
81+
if (deprecatedSkin.HasCinematic(cinematicKvp.Value.ClipName))
82+
{
83+
source.clip = null;
84+
source.url = deprecatedSkin.GetCinematicUrl(cinematicKvp.Value.ClipName);
85+
source.Prepare();
86+
}
9487
}
9588
}
9689
}
9790
}
9891
}
9992

100-
101-
public static string GetCinematicUrl(string CinematicName)
102-
{
103-
EnsureDirectory($"{SkinManager.DATA_DIR}/Cinematics/");
104-
string path = "";
105-
string file = ($"{SkinManager.DATA_DIR}/Cinematics/{CinematicName}").Replace("\\", "/");
106-
if (File.Exists(file + ".webm"))
107-
{
108-
path = file + ".webm";
109-
}
110-
CustomKnight.Instance.LogFine("[GetCinematicUrl]" + CinematicName + ":" + path);
111-
return path;
112-
}
113-
11493
private static void CinematicSequence_Update(On.CinematicSequence.orig_Update orig, CinematicSequence self)
11594
{
11695
var fles = new CinematicSequenceR(self);
11796
if (GetCiematicSafely(fles.videoReference.VideoFileName, out var cinematic))
11897
{
119-
if (SkinManager.GetCurrentSkin().HasCinematic(cinematic.ClipName) || HasCinematic(cinematic.ClipName))
98+
var skin = SkinManager.GetCurrentSkin();
99+
if (skin is ISelectableSkin deprecatedSkin)
120100
{
121-
if (cinematic.player != null)
101+
if (deprecatedSkin.HasCinematic(cinematic.ClipName))
122102
{
123-
VideoPlayer source = ReflectionHelper.GetField<XB1CinematicVideoPlayer, VideoPlayer>(cinematic.player, "videoPlayer"); ;
124-
if ((ulong)source.frame < source.frameCount - 1)
103+
if (cinematic.player != null)
125104
{
126-
fles.framesSinceBegan = 0;
105+
VideoPlayer source = ReflectionHelper.GetField<XB1CinematicVideoPlayer, VideoPlayer>(cinematic.player, "videoPlayer"); ;
106+
if ((ulong)source.frame < source.frameCount - 1)
107+
{
108+
fles.framesSinceBegan = 0;
109+
}
110+
else
111+
{
112+
fles.framesSinceBegan = 11;
113+
}
127114
}
128115
else
129116
{
130-
fles.framesSinceBegan = 11;
117+
fles.framesSinceBegan = 0;
131118
}
132119
}
133-
else
134-
{
135-
fles.framesSinceBegan = 0;
136-
}
137120
}
138121
}
139122
orig(self);

CustomKnight/Skin/Morph/DefaultSkin.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,18 @@ public static void SaveSkin()
4747
isGeneratingDefaultSkin = true;
4848
CoroutineHelper.GetRunner().StartCoroutine(GenerateSkin());
4949
}
50+
51+
public static bool Exists(string fileName)
52+
{
53+
var filePath = Path.Combine(SkinManager.SKINS_FOLDER, SkinManager.DEFAULT_SKIN, fileName);
54+
return File.Exists(filePath);
55+
}
56+
57+
public static Texture2D GetTexture(string fileName)
58+
{
59+
var filePath = Path.Combine(SkinManager.SKINS_FOLDER, SkinManager.DEFAULT_SKIN, fileName);
60+
return TextureUtils.LoadTextureFromFile(filePath);
61+
}
5062
public static void Save(Texture2D texture, string skinName, string path, bool overwrite = false)
5163
{
5264
var folderPath = Path.Combine(SkinManager.SKINS_FOLDER, skinName);

0 commit comments

Comments
 (0)