Skip to content

Commit

Permalink
Merge pull request #3 from PrashantMohta/saveskin
Browse files Browse the repository at this point in the history
Save settings
  • Loading branch information
Prashant Mohta authored Jun 6, 2021
2 parents dc92014 + 7009ef0 commit 6436f88
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 36 deletions.
56 changes: 30 additions & 26 deletions CustomKnight/Canvas/SkinSwapperPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,32 @@ 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;
int imageWidth = 300;
int panelHeight = 1080;
int imageHeight = 60;
Texture2D texture2D = new Texture2D(imageWidth, panelHeight);
for (int i = 0; i < imageWidth; i++)
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);

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);
}
Expand All @@ -48,50 +52,49 @@ 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)
new Rect(0, 0, PanelWidth, 60)
);

float textHeight = 90;
Panel.AddText(
"Change Skin Text",
"Change Skin",
new Vector2(0, y),
new Vector2(imageWidth, textHeight),
new Vector2(0, currentElementPosY),
new Vector2(PanelWidth, headingSize),
GUIController.Instance.trajanNormal,
24,
headingFontSize,
FontStyle.Bold,
TextAnchor.MiddleCenter
);
y += textHeight;
currentElementPosY += headingSize;

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, PanelWidth, OptionSize),
GUIController.Instance.trajanNormal,
directoryName,
24
buttonText,
fontSize
);
y += imageHeight;
currentElementPosY += OptionSize;

GC.Collect();
}

Panel.SetActive(false, true);

Vector2 newPanelSize = new Vector2(imageWidth, y);
Vector2 newPanelSize = new Vector2(PanelWidth, currentElementPosY);
Panel.ResizeBG(newPanelSize);

On.HeroController.Pause += OnPause;
Expand All @@ -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());
}

Expand Down
18 changes: 13 additions & 5 deletions CustomKnight/CustomKnight.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,15 @@

namespace CustomKnight
{
public class CustomKnight : Mod<SaveSettings, GlobalSettings>, 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;
Expand Down Expand Up @@ -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)>
{
Expand Down Expand Up @@ -191,7 +199,7 @@ public override void Initialize(Dictionary<string, Dictionary<string, GameObject

Instance = this;

Preloads = GlobalSettings.Preloads;
Preloads = Settings.Preloads;

if (!Directory.Exists(DATA_DIR))
{
Expand All @@ -207,7 +215,7 @@ public override void Initialize(Dictionary<string, Dictionary<string, GameObject
if (SKIN_FOLDER == null)
{
Log("Skin folder null: setting to default");
SKIN_FOLDER = GlobalSettings.DefaultSkin;
SKIN_FOLDER = Settings.DefaultSkin;
}

ResetTextures();
Expand All @@ -230,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()
{
Expand Down
4 changes: 0 additions & 4 deletions CustomKnight/CustomKnight.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,5 @@
<Compile Include="Settings.cs" />
<Compile Include="SpriteLoader.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Images\Panel_BG.png" />
</ItemGroup>

<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
Binary file removed CustomKnight/Images/Panel_BG.png
Binary file not shown.
9 changes: 8 additions & 1 deletion CustomKnight/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@ 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 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); }

}

}

0 comments on commit 6436f88

Please sign in to comment.