89 lines
2.4 KiB
C++
89 lines
2.4 KiB
C++
/*
|
|
* File name: control_menu.cpp
|
|
* Author: lejulien
|
|
* Date created: 10-01-2026 22:12:44
|
|
// Date modified: 12-01-2026 22:18:58
|
|
* ------
|
|
*/
|
|
|
|
#include <imgui.h>
|
|
#include <raylib.h>
|
|
#include <rlImGui.h>
|
|
|
|
#include <control_menu.hpp>
|
|
#include <settings_menu.hpp>
|
|
#include <paterns_menu.hpp>
|
|
#include <world.hpp>
|
|
#include <rules.hpp>
|
|
|
|
namespace gol {
|
|
|
|
ControlMenu::ControlMenu(std::shared_ptr<ctx> context):context_(context) {
|
|
}
|
|
|
|
void ControlMenu::update() {
|
|
if (menu_state_ == MenuState::PLAY || menu_state_ == MenuState::EDIT) {
|
|
if (!play_ctrl_ && !edit_ctrl_) {
|
|
menu_state_ = MenuState::NONE;
|
|
}
|
|
}
|
|
if (rand_ctrl_) {
|
|
context_->world->randomize();
|
|
rand_ctrl_ = false;
|
|
}
|
|
if (clear_ctrl_) {
|
|
context_->world->clear();
|
|
clear_ctrl_ = false;
|
|
}
|
|
if (edit_ctrl_ && play_ctrl_) {
|
|
if (menu_state_ == MenuState::PLAY) {
|
|
menu_state_ = MenuState::EDIT;
|
|
play_ctrl_ = false;
|
|
} else if (menu_state_ == MenuState::EDIT) {
|
|
menu_state_ = MenuState::PLAY;
|
|
edit_ctrl_ = false;
|
|
}
|
|
} else if (play_ctrl_) {
|
|
menu_state_ = MenuState::PLAY;
|
|
} else if (edit_ctrl_) {
|
|
menu_state_ = MenuState::EDIT;
|
|
}
|
|
if (step_ctrl_) {
|
|
context_->world->saveCompressed();
|
|
context_->rules->update();
|
|
step_ctrl_ = false;
|
|
}
|
|
if (step_back_ctrl_) {
|
|
context_->world->stepBack();
|
|
step_back_ctrl_ = false;
|
|
}
|
|
}
|
|
|
|
void ControlMenu::display() {
|
|
bool control_panel_open = true;
|
|
ImGuiWindowFlags control_panel_flags = ImGuiWindowFlags_AlwaysAutoResize |
|
|
ImGuiWindowFlags_NoResize;
|
|
ImVec2 menu_pos(3, 3);
|
|
ImGui::SetNextWindowPos(menu_pos, ImGuiCond_Always);
|
|
ImGui::Begin("Control Panel", &control_panel_open, control_panel_flags);
|
|
ImGui::Checkbox("Play", &play_ctrl_);
|
|
if (ImGui::Button("Step")) {
|
|
step_ctrl_ = true;
|
|
}
|
|
if (ImGui::Button("Step Back")) {
|
|
step_back_ctrl_ = true;
|
|
}
|
|
ImGui::Checkbox("Edit", &edit_ctrl_);
|
|
ImGui::Checkbox("Clear", &clear_ctrl_);
|
|
ImGui::Checkbox("Randomize", &rand_ctrl_);
|
|
if (ImGui::Button((context_->paterns_menu->isOpen()) ? "Hide paterns" : "Show paterns")) {
|
|
context_->paterns_menu->Toogle();
|
|
}
|
|
if (ImGui::Button((context_->settings_menu->isOpen()) ? "Hide settings" : "Show settings")) {
|
|
context_->settings_menu->Toogle();
|
|
}
|
|
ImGui::Text("Generation: %zu", context_->world->getCycle());
|
|
ImGui::End();}
|
|
|
|
} // namespace gol
|