From 08f2395886865b52387f66a2628084a44a23fc6c Mon Sep 17 00:00:00 2001 From: Prashant Mohta Date: Sun, 6 Jun 2021 17:39:27 +0530 Subject: [PATCH 1/3] adds skin settings support --- CustomKnight/Canvas/SkinSwapperPanel.cs | 34 +++++++++++++----------- CustomKnight/CustomKnight.cs | 16 ++++++++--- CustomKnight/CustomKnight.csproj | 4 --- CustomKnight/Images/Panel_BG.png | Bin 3205 -> 0 bytes CustomKnight/Settings.cs | 7 ++++- 5 files changed, 37 insertions(+), 24 deletions(-) delete mode 100644 CustomKnight/Images/Panel_BG.png diff --git a/CustomKnight/Canvas/SkinSwapperPanel.cs b/CustomKnight/Canvas/SkinSwapperPanel.cs index 7be62fa..7e32ca7 100644 --- a/CustomKnight/Canvas/SkinSwapperPanel.cs +++ b/CustomKnight/Canvas/SkinSwapperPanel.cs @@ -18,15 +18,18 @@ public class SkinSwapperPanel { public static CanvasPanel Panel; - private static float y; - public static void BuildMenu(GameObject canvas) { Log("Building Skin Swapper Panel"); - y = 30.0f; + float currentElementPosY = CustomKnight.Instance.Settings.PanelStartPos; + int NameLength = CustomKnight.Instance.Settings.NameLength; + int OptionSize = CustomKnight.Instance.Settings.OptionSize; + int imageWidth = 300; int panelHeight = 1080; - int imageHeight = 60; + int imageHeight = OptionSize; + int fontSize = OptionSize - 15; + Texture2D texture2D = new Texture2D(imageWidth, panelHeight); for (int i = 0; i < imageWidth; i++) { @@ -48,50 +51,50 @@ public static void BuildMenu(GameObject canvas) Panel = new CanvasPanel( canvas, texture2D, - new Vector2(0, y), + new Vector2(0, currentElementPosY), Vector2.zero, new Rect(0, 0, imageWidth, 60) ); - float textHeight = 90; + float textHeight = 40; Panel.AddText( "Change Skin Text", "Change Skin", - new Vector2(0, y), + new Vector2(0, currentElementPosY), new Vector2(imageWidth, textHeight), GUIController.Instance.trajanNormal, 24, FontStyle.Bold, TextAnchor.MiddleCenter ); - y += textHeight; + currentElementPosY += textHeight; GC.Collect(); foreach (string path in Directory.GetDirectories(CustomKnight.DATA_DIR)) { string directoryName = new DirectoryInfo(path).Name; - + string buttonText = directoryName.Length <= NameLength ? directoryName : directoryName.Substring(0,NameLength - 3) + "..."; Panel.AddButton( directoryName, texture2D2, - new Vector2(0, y), + new Vector2(0, currentElementPosY), Vector2.zero, ChangeSkin, - new Rect(0, y, imageWidth, imageHeight), + new Rect(0, currentElementPosY, imageWidth, imageHeight), GUIController.Instance.trajanNormal, - directoryName, - 24 + buttonText, + fontSize ); - y += imageHeight; + currentElementPosY += imageHeight; GC.Collect(); } Panel.SetActive(false, true); - Vector2 newPanelSize = new Vector2(imageWidth, y); + Vector2 newPanelSize = new Vector2(imageWidth, currentElementPosY); Panel.ResizeBG(newPanelSize); On.HeroController.Pause += OnPause; @@ -102,6 +105,7 @@ public static void BuildMenu(GameObject canvas) private static void ChangeSkin(string buttonName) { CustomKnight.SKIN_FOLDER = buttonName; + CustomKnight.Instance.Settings.DefaultSkin = buttonName; GameManager.instance.StartCoroutine(ChangeSkinRoutine()); } diff --git a/CustomKnight/CustomKnight.cs b/CustomKnight/CustomKnight.cs index b6565a4..96cf210 100644 --- a/CustomKnight/CustomKnight.cs +++ b/CustomKnight/CustomKnight.cs @@ -17,8 +17,15 @@ namespace CustomKnight { - public class CustomKnight : Mod, ITogglableMod + public class CustomKnight : Mod, ITogglableMod { + public GlobalModSettings Settings = new GlobalModSettings(); + public override ModSettings GlobalSettings + { + get => Settings; + set => Settings = (GlobalModSettings) value; + } + public class CustomKnightTexture { public bool missing; @@ -132,9 +139,10 @@ public CustomKnightTexture(string fileName, bool missing, Texture2D defaultTex, public static CustomKnight Instance { get; private set; } + public override List<(string, string)> GetPreloadNames() { - if (GlobalSettings.Preloads) + if (Settings.Preloads) { return new List<(string, string)> { @@ -191,7 +199,7 @@ public override void Initialize(Dictionary - - - - \ No newline at end of file diff --git a/CustomKnight/Images/Panel_BG.png b/CustomKnight/Images/Panel_BG.png deleted file mode 100644 index a868ee2da04d8ee1f43ba97b44918b6132fe108c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3205 zcmeAS@N?(olHy`uVBq!ia0y~yVANq?V6os}28y)Y5zGZrjKx9jP7LeL$-D$|SkfJR z9T^xl_H+M9WMyDrW(e>JaRrKxg3%Bdu_3V8;7bQEpD>gJ`33(U*?=MVJG&|{A#fIW zL>4nJ@ErzW#^d=bQWzLGm^@t^Ln`9lUNB^2Fc4r~_{)55)Q{VaO!;$8a;30tVv1~B z;}E8xJwf!uD0eh8MiawmUKlM3MoYrcl5n_`gs*dcFMRdGG~VBOJ*chd>FVdQ&MBb@ E0PX?GJOBUy diff --git a/CustomKnight/Settings.cs b/CustomKnight/Settings.cs index 195bb43..28328bb 100644 --- a/CustomKnight/Settings.cs +++ b/CustomKnight/Settings.cs @@ -4,9 +4,14 @@ namespace CustomKnight { public class SaveSettings : ModSettings { } - public class GlobalSettings : ModSettings + public class GlobalModSettings : ModSettings { public bool Preloads { get => GetBool(true); set => SetBool(value); } public string DefaultSkin { get => GetString("Default"); set => SetString(value); } + public float PanelStartPos { get => GetFloat(80.0f); set => SetFloat(value);} + public int NameLength { get => GetInt(10); set => SetInt(value); } + public int OptionSize { get => GetInt(35); set => SetInt(value); } + } + } \ No newline at end of file From d68708c1638937eeb88bf84a5b37d23f78f5c10e Mon Sep 17 00:00:00 2001 From: Prashant Mohta Date: Sun, 6 Jun 2021 18:24:36 +0530 Subject: [PATCH 2/3] add more settings --- CustomKnight/Canvas/SkinSwapperPanel.cs | 40 ++++++++++++------------- CustomKnight/Settings.cs | 4 ++- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/CustomKnight/Canvas/SkinSwapperPanel.cs b/CustomKnight/Canvas/SkinSwapperPanel.cs index 7e32ca7..b58aa00 100644 --- a/CustomKnight/Canvas/SkinSwapperPanel.cs +++ b/CustomKnight/Canvas/SkinSwapperPanel.cs @@ -21,28 +21,29 @@ public class SkinSwapperPanel public static void BuildMenu(GameObject canvas) { Log("Building Skin Swapper Panel"); - float currentElementPosY = CustomKnight.Instance.Settings.PanelStartPos; + float currentElementPosY = CustomKnight.Instance.Settings.PanelY; + int PanelWidth = CustomKnight.Instance.Settings.PanelWidth; + int PanelHeight = CustomKnight.Instance.Settings.PanelHeight; + int NameLength = CustomKnight.Instance.Settings.NameLength; int OptionSize = CustomKnight.Instance.Settings.OptionSize; + int fontSize = (int)(OptionSize * 0.6f); + int headingSize = (int)(OptionSize * 1.1f); + int headingFontSize = (int)(headingSize * 0.85f); - int imageWidth = 300; - int panelHeight = 1080; - int imageHeight = OptionSize; - int fontSize = OptionSize - 15; - - Texture2D texture2D = new Texture2D(imageWidth, panelHeight); - for (int i = 0; i < imageWidth; i++) + Texture2D texture2D = new Texture2D(PanelWidth, PanelHeight); + for (int i = 0; i < PanelWidth; i++) { - for (int j = 0; j < panelHeight; j++) + for (int j = 0; j < PanelHeight; j++) { texture2D.SetPixel(i, j, Color.clear); } } texture2D.Apply(); - Texture2D texture2D2 = new Texture2D(imageWidth, imageHeight); - for (int k = 0; k < imageWidth; k++) + Texture2D texture2D2 = new Texture2D(PanelWidth, OptionSize); + for (int k = 0; k < PanelWidth; k++) { - for (int l = 0; l < imageHeight; l++) + for (int l = 0; l < OptionSize; l++) { texture2D2.SetPixel(k, l, Color.clear); } @@ -53,21 +54,20 @@ public static void BuildMenu(GameObject canvas) texture2D, new Vector2(0, currentElementPosY), Vector2.zero, - new Rect(0, 0, imageWidth, 60) + new Rect(0, 0, PanelWidth, 60) ); - float textHeight = 40; Panel.AddText( "Change Skin Text", "Change Skin", new Vector2(0, currentElementPosY), - new Vector2(imageWidth, textHeight), + new Vector2(PanelWidth, headingSize), GUIController.Instance.trajanNormal, - 24, + headingFontSize, FontStyle.Bold, TextAnchor.MiddleCenter ); - currentElementPosY += textHeight; + currentElementPosY += headingSize; GC.Collect(); @@ -82,19 +82,19 @@ public static void BuildMenu(GameObject canvas) new Vector2(0, currentElementPosY), Vector2.zero, ChangeSkin, - new Rect(0, currentElementPosY, imageWidth, imageHeight), + new Rect(0, currentElementPosY, PanelWidth, OptionSize), GUIController.Instance.trajanNormal, buttonText, fontSize ); - currentElementPosY += imageHeight; + currentElementPosY += OptionSize; GC.Collect(); } Panel.SetActive(false, true); - Vector2 newPanelSize = new Vector2(imageWidth, currentElementPosY); + Vector2 newPanelSize = new Vector2(PanelWidth, currentElementPosY); Panel.ResizeBG(newPanelSize); On.HeroController.Pause += OnPause; diff --git a/CustomKnight/Settings.cs b/CustomKnight/Settings.cs index 28328bb..01d93bb 100644 --- a/CustomKnight/Settings.cs +++ b/CustomKnight/Settings.cs @@ -8,7 +8,9 @@ public class GlobalModSettings : ModSettings { public bool Preloads { get => GetBool(true); set => SetBool(value); } public string DefaultSkin { get => GetString("Default"); set => SetString(value); } - public float PanelStartPos { get => GetFloat(80.0f); set => SetFloat(value);} + public float PanelY { get => GetFloat(80.0f); set => SetFloat(value);} + public int PanelWidth { get => GetInt(250); set => SetInt(value); } + public int PanelHeight { get => GetInt(1080); set => SetInt(value); } public int NameLength { get => GetInt(10); set => SetInt(value); } public int OptionSize { get => GetInt(35); set => SetInt(value); } From 7009ef0ae136c062a30e921f426da6bbec9a8d35 Mon Sep 17 00:00:00 2001 From: Prashant Mohta Date: Sun, 6 Jun 2021 18:25:35 +0530 Subject: [PATCH 3/3] bump version --- CustomKnight/CustomKnight.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CustomKnight/CustomKnight.cs b/CustomKnight/CustomKnight.cs index 96cf210..03dd2ae 100644 --- a/CustomKnight/CustomKnight.cs +++ b/CustomKnight/CustomKnight.cs @@ -238,7 +238,7 @@ private void GeoControl_Start(On.GeoControl.orig_Start orig, GeoControl self) orig(self); } - public override string GetVersion() => "1.2.4"; + public override string GetVersion() => "1.2.4b"; private void ResetTextures() {