Skip to content

Commit

Permalink
allow changing auto save interval
Browse files Browse the repository at this point in the history
  • Loading branch information
IAmMoltony committed Jan 11, 2025
1 parent e22c747 commit 383fd58
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ public static void Set(string key, Color val)
Set(key, $"{val.R};{val.G};{val.B}");
}

public static void Set(string key, int val)
{
Set(key, val.ToString());
}

public static string Get(string key)
{
// If the setting is found in the settings dictionary, return it
Expand Down
18 changes: 16 additions & 2 deletions src/SettingsScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public class SettingsScreen : IGameState
private readonly CheckBox _enableHintsBox;
private readonly CheckBox _showBgBox;
private readonly CheckBox _enableSoundBox;
private readonly NumberTextBox _autoSaveIntervalBox;

private readonly NumberTextBox _accentColorRedBox;
private readonly NumberTextBox _accentColorGreenBox;
private readonly NumberTextBox _accentColorBlueBox;
Expand All @@ -38,7 +40,8 @@ public SettingsScreen()
_enableHintsBox = new(40, 110, StringManager.GetString("enableHints"), Color.Gray, Color.DarkGray, Settings.GetBool("enableHints"));
_showBgBox = new(40, 140, StringManager.GetString("showBgGrid"), Color.Gray, Color.DarkGray, Settings.GetBool("showBgGrid"));
_enableSoundBox = new(40, 170, StringManager.GetString("enableSound"), Color.Gray, Color.DarkGray, Settings.GetBool("sound"));
AccentColorButton = new(40, 215, 0, 40, StringManager.GetString("changeAccentColor"), Settings.GetDarkAccentColor(), Settings.GetAccentColor(), true);
_autoSaveIntervalBox = new(40, 285, 100, Color.DarkGray, Color.Gray, Color.White, Color.White, 10000); // just a random big number
AccentColorButton = new(40, 205, 0, 40, StringManager.GetString("changeAccentColor"), Settings.GetDarkAccentColor(), Settings.GetAccentColor(), true);
AccentColorResetButton = new(0, 0, 0, 40, StringManager.GetString("reset"), Settings.GetDarkAccentColor(), Settings.GetAccentColor(), true);
AccentColorOKButton = new(0, 0, 0, 40, StringManager.GetString("ok"), Settings.GetDarkAccentColor(), Settings.GetAccentColor(), true);
_accentColorRedBox = new(0, 0, 200, Color.DarkGray, Color.Gray, Color.White, Color.White, 255);
Expand All @@ -50,6 +53,8 @@ public SettingsScreen()
_accentColorGreenBox.SetNumberValue(accentColor.G);
_accentColorBlueBox.SetNumberValue(accentColor.B);

_autoSaveIntervalBox.SetNumberValue(Settings.GetInt("editorAutoSaveInterval"));

_dialogRect = new();
_setAccentColor = false;
}
Expand All @@ -67,8 +72,11 @@ public void Draw(SpriteBatch sprBatch)
_enableHintsBox.Draw(sprBatch);
_showBgBox.Draw(sprBatch);
_enableSoundBox.Draw(sprBatch);
AccentColorButton.Draw(sprBatch);

TextRenderer.DrawText(sprBatch, "DefaultFont", 40, 255, 0.4f, StringManager.GetString("autoSaveInterval"), Color.White);
_autoSaveIntervalBox.Draw(sprBatch);

AccentColorButton.Draw(sprBatch);
if (_setAccentColor)
{
Rectangle dialogTextRect = new();
Expand Down Expand Up @@ -148,6 +156,7 @@ public void Draw(SpriteBatch sprBatch)
_showBgBox.Update(mouse, mouseOld, kb, kbOld);
_enableSoundBox.Update(mouse, mouseOld, kb, kbOld);
AccentColorButton.Update(mouse, mouseOld, kb, kbOld);
_autoSaveIntervalBox.Update(mouse, mouseOld, kb, kbOld);

if (AccentColorButton.IsClicked)
{
Expand Down Expand Up @@ -184,13 +193,18 @@ public void UpdateInput(TextInputEventArgs tiea)
_accentColorGreenBox.UpdateInput(tiea);
_accentColorBlueBox.UpdateInput(tiea);
}
else
{
_autoSaveIntervalBox.UpdateInput(tiea);
}
}

private void saveSettings()
{
Settings.Set("enableHints", _enableHintsBox.isChecked);
Settings.Set("showBgGrid", _showBgBox.isChecked);
Settings.Set("sound", _enableSoundBox.isChecked);
Settings.Set("editorAutoSaveInterval", _autoSaveIntervalBox.GetNumberValue());
Settings.Save();
}

Expand Down

0 comments on commit 383fd58

Please # to comment.