Skip to content

Commit cc85404

Browse files
committed
Simplified the way the last preset color group is saved/loaded
No need for operator== or getVector() in cfg::Option
1 parent 285f53a commit cc85404

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

cells.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ colors = {
1616
}
1717
height = 600
1818
lastFilename = ""
19+
lastPresetColor = "Rainbow"
1920
presetRules = {
2021
"B3/S23",
2122
"B3/S12345",

src/cells/cells.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,18 @@ const char* Cells::title = "Cells v0.4.1 Alpha";
99
const cfg::File::ConfigMap Cells::defaultOptions = {
1010
{"Window", {
1111
{"fullscreen", cfg::makeOption(false)},
12-
{"width", cfg::makeOption(640, 0)},
13-
{"height", cfg::makeOption(480, 0)},
12+
{"width", cfg::makeOption(800, 0)},
13+
{"height", cfg::makeOption(600, 0)},
1414
{"vsync", cfg::makeOption(true)}
1515
}
1616
},
1717
{"Board", {
18-
{"width", cfg::makeOption(640, 3)},
19-
{"height", cfg::makeOption(480, 3)},
18+
{"width", cfg::makeOption(800, 3)},
19+
{"height", cfg::makeOption(600, 3)},
2020
{"rules", cfg::makeOption(Board::defaultRuleString)},
21-
{"autosave", cfg::makeOption(true)}
21+
{"autosave", cfg::makeOption(true)},
22+
{"lastFilename", cfg::makeOption("")},
23+
{"lastPresetColor", cfg::makeOption("")}
2224
}
2325
},
2426
{"Simulation", {

src/cells/settingsgui.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,6 @@ void SettingsGUI::loadSettings()
201201
toolButtons[tool.getTool()].setPressed(true);
202202
unsigned row = 0;
203203
unsigned col = 0;
204-
const auto& currentColors = config("colors", "Board");
205204
for (const auto& opt: config.getSection("PresetColors"))
206205
{
207206
colorButtons.emplace_back();
@@ -213,9 +212,8 @@ void SettingsGUI::loadSettings()
213212
colorButtons.back().setMode(Button::Mode::Sticky);
214213
colorButtons.back().linkButtons(colorButtons);
215214

216-
// Compare the colors to see which preset was last used
217-
if (opt.second.getVector() != nullptr && currentColors.getVector() != nullptr &&
218-
*(opt.second.getVector()) == *(currentColors.getVector()))
215+
// Check if this was the last preset used
216+
if (config("lastPresetColor", "Board").toString() == opt.first)
219217
colorButtons.back().setPressed(true);
220218

221219
++row;
@@ -241,6 +239,12 @@ void SettingsGUI::saveSettings()
241239
for (auto& elem: opt.second)
242240
elem = ColorCode(elem.toString()).toString();
243241
}
242+
// Save the last color preset used
243+
for (Button& button: colorButtons)
244+
{
245+
if (button.isPressed())
246+
config("lastPresetColor", "Board") = button.getText();
247+
}
244248
}
245249

246250
void SettingsGUI::toggle()

0 commit comments

Comments
 (0)