settings_menu: Create a dedicated class for the settings

This commit is contained in:
2026-01-12 21:34:41 +01:00
parent 24d8a092e4
commit 416d3a2be9
13 changed files with 286 additions and 161 deletions

View File

@@ -2,7 +2,7 @@
* File name: control_menu.cpp
* Author: lejulien
* Date created: 10-01-2026 22:12:44
// Date modified: 12-01-2026 20:36:39
// Date modified: 12-01-2026 22:18:58
* ------
*/
@@ -11,26 +11,20 @@
#include <rlImGui.h>
#include <control_menu.hpp>
#include <settings_menu.hpp>
#include <world.hpp>
#include <rules.hpp>
namespace gol {
ControlMenu::ControlMenu(ctx context):context_(context) {
fps_ctrl_ = context.config_json["fps"].get<int>();
cell_size_ctrl_ = context.config_json["cell_size"].get<int>();
ControlMenu::ControlMenu(std::shared_ptr<ctx> context):context_(context) {
play_ctrl_ = true;
step_ctrl_ = false;
step_back_ctrl_ = false;
rand_ctrl_ = false;
edit_ctrl_ = false;
clear_ctrl_ = false;
settings_window_ = false;
paterns_ctrl_ = false;
width_ctrl_ = context.config_json["screen_width"].get<int>();
height_ctrl_ = context.config_json["screen_height"].get<int>();
dark_theme_ctrl_ = context.config_json["dark_theme"].get<bool>();
apply_ctrl_ = false;
}
void ControlMenu::update() {
@@ -40,11 +34,11 @@ void ControlMenu::update() {
}
}
if (rand_ctrl_) {
context_.world->randomize();
context_->world->randomize();
rand_ctrl_ = false;
}
if (clear_ctrl_) {
context_.world->clear();
context_->world->clear();
clear_ctrl_ = false;
}
if (edit_ctrl_ && play_ctrl_) {
@@ -61,12 +55,12 @@ void ControlMenu::update() {
menu_state_ = MenuState::EDIT;
}
if (step_ctrl_) {
context_.world->saveCompressed();
context_.rules->update();
context_->world->saveCompressed();
context_->rules->update();
step_ctrl_ = false;
}
if (step_back_ctrl_) {
context_.world->stepBack();
context_->world->stepBack();
step_back_ctrl_ = false;
}
}
@@ -91,10 +85,10 @@ void ControlMenu::display() {
if (ImGui::Button((paterns_ctrl_) ? "Hide paterns" : "Show paterns")) {
paterns_ctrl_ = !paterns_ctrl_;
}
if (ImGui::Button((settings_window_) ? "Hide settings" : "Show settings")) {
settings_window_ = !settings_window_;
if (ImGui::Button((context_->settings_menu->isOpen()) ? "Hide settings" : "Show settings")) {
context_->settings_menu->Toogle();
}
ImGui::Text("Generation: %zu", context_.world->getCycle());
ImGui::Text("Generation: %zu", context_->world->getCycle());
ImGui::End();}
} // namespace gol