Compare commits
1 Commits
546d9f24b5
...
568c292ed4
| Author | SHA1 | Date | |
|---|---|---|---|
| 568c292ed4 |
@@ -11,7 +11,6 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <context.hpp>
|
#include <context.hpp>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace gol {
|
namespace gol {
|
||||||
@@ -25,14 +24,9 @@ public:
|
|||||||
void display();
|
void display();
|
||||||
void refresh();
|
void refresh();
|
||||||
private:
|
private:
|
||||||
bool loadPatern(std::string &path);
|
|
||||||
bool is_open_ = false;
|
bool is_open_ = false;
|
||||||
std::shared_ptr<ctx> context_ = nullptr;
|
std::shared_ptr<ctx> context_ = nullptr;
|
||||||
std::map<std::string,std::string> paterns_paths_list_;
|
std::vector<std::string> paterns_list_;
|
||||||
std::vector<std::string> paterns_name_list_;
|
|
||||||
int patern_width_ = 0;
|
|
||||||
int patern_height_ = 0;
|
|
||||||
std::vector<uint32_t> loaded_patern_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace gol
|
} // namespace gol
|
||||||
|
|||||||
@@ -6,94 +6,49 @@
|
|||||||
* ------
|
* ------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <paterns_menu.hpp>
|
||||||
|
|
||||||
|
#include <filesystem>
|
||||||
|
|
||||||
#include <imgui.h>
|
#include <imgui.h>
|
||||||
#include <raylib.h>
|
#include <raylib.h>
|
||||||
#include <rlImGui.h>
|
#include <rlImGui.h>
|
||||||
|
|
||||||
#include <filesystem>
|
|
||||||
#include <fstream>
|
|
||||||
#include <iostream>
|
|
||||||
#include <paterns_menu.hpp>
|
|
||||||
#include <sstream>
|
|
||||||
|
|
||||||
namespace gol {
|
namespace gol {
|
||||||
|
|
||||||
PaternsMenu::PaternsMenu(std::shared_ptr<ctx> ctx) : context_(ctx) {}
|
PaternsMenu::PaternsMenu(std::shared_ptr<ctx> ctx): context_(ctx) {}
|
||||||
|
|
||||||
void PaternsMenu::Toogle() { is_open_ = !is_open_; }
|
void PaternsMenu::Toogle() {
|
||||||
|
is_open_ = !is_open_;
|
||||||
bool PaternsMenu::isOpen() { return is_open_; }
|
|
||||||
|
|
||||||
void PaternsMenu::refresh() {
|
|
||||||
paterns_name_list_.clear();
|
|
||||||
paterns_paths_list_.clear();
|
|
||||||
auto paterns_path = context_->program_dir / "paterns";
|
|
||||||
if (std::filesystem::exists(paterns_path) &&
|
|
||||||
std::filesystem::is_directory(paterns_path)) {
|
|
||||||
for (const auto &entry :
|
|
||||||
std::filesystem::directory_iterator(paterns_path)) {
|
|
||||||
if (!std::filesystem::is_directory(entry) &&
|
|
||||||
entry.path().has_filename()) {
|
|
||||||
paterns_paths_list_[entry.path().filename()] = entry.path();
|
|
||||||
paterns_name_list_.push_back(entry.path().filename());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PaternsMenu::loadPatern(std::string &path) {
|
bool PaternsMenu::isOpen() {
|
||||||
std::ifstream file(path);
|
return is_open_;
|
||||||
std::string file_data;
|
}
|
||||||
if (!file.is_open()) {
|
|
||||||
std::cerr << "Failure in opening patern : " << path << std::endl;
|
void PaternsMenu::refresh() {
|
||||||
return false;
|
paterns_list_.clear();
|
||||||
}
|
auto paterns_path = context_->program_dir / "paterns";
|
||||||
loaded_patern_.clear();
|
if (std::filesystem::exists(paterns_path) && std::filesystem::is_directory(paterns_path)) {
|
||||||
try {
|
for (const auto& entry : std::filesystem::directory_iterator(paterns_path)) {
|
||||||
std::getline(file, file_data);
|
paterns_list_.push_back(entry.path());
|
||||||
std::stringstream ss(file_data);
|
|
||||||
std::string width, height, data;
|
|
||||||
std::getline(ss, width, '|');
|
|
||||||
std::getline(ss, height, '|');
|
|
||||||
std::getline(ss, data, '|');
|
|
||||||
patern_width_ = std::stoi(width);
|
|
||||||
patern_height_ = std::stoi(height);
|
|
||||||
for (int i = 0; i < patern_width_ * patern_height_; i++) {
|
|
||||||
loaded_patern_.push_back((data[i] == '1') ? 1 : 0);
|
|
||||||
}
|
}
|
||||||
} catch (std::exception &e) {
|
|
||||||
std::cerr << "Failure in loading patern : " << path << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PaternsMenu::display() {
|
void PaternsMenu::display() {
|
||||||
if (is_open_) {
|
if (is_open_) {
|
||||||
ImGuiWindowFlags paterns_flags =
|
ImGuiWindowFlags paterns_flags = ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoResize;
|
||||||
ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoResize;
|
ImGui::SetNextWindowSize(ImVec2(150, 200), ImGuiCond_Always);
|
||||||
ImGui::SetNextWindowSize(ImVec2(200, 250), ImGuiCond_Always);
|
|
||||||
ImGui::Begin("paterns", &is_open_, paterns_flags);
|
ImGui::Begin("paterns", &is_open_, paterns_flags);
|
||||||
for (auto patern_name : paterns_name_list_) {
|
if (ImGui::Button("refresh")) {
|
||||||
ImGui::PushID(patern_name.c_str());
|
refresh();
|
||||||
if (ImGui::Button(patern_name.c_str()) &&
|
}
|
||||||
loadPatern(paterns_paths_list_[patern_name])) {
|
for (auto patern_name: paterns_list_) {
|
||||||
// TODO: If patern is loaded successfuly, start the preview in the
|
ImGui::Button(patern_name.c_str());
|
||||||
// editor
|
|
||||||
}
|
|
||||||
ImGui::PopID();
|
|
||||||
ImGui::SameLine(ImGui::GetWindowWidth() - 57.);
|
|
||||||
std::string del_id = patern_name.c_str();
|
|
||||||
del_id.append("_del");
|
|
||||||
ImGui::PushID(del_id.c_str());
|
|
||||||
if (ImGui::Button("delete")) {
|
|
||||||
std::filesystem::remove(paterns_paths_list_[patern_name]);
|
|
||||||
refresh();
|
|
||||||
}
|
|
||||||
ImGui::PopID();
|
|
||||||
}
|
}
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace gol
|
} // namespace gol
|
||||||
|
|||||||
@@ -12,7 +12,6 @@
|
|||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
|
||||||
#include <selection_menu.hpp>
|
#include <selection_menu.hpp>
|
||||||
#include <paterns_menu.hpp>
|
|
||||||
|
|
||||||
namespace gol {
|
namespace gol {
|
||||||
|
|
||||||
@@ -91,7 +90,6 @@ void SelectionMenu::display() {
|
|||||||
}
|
}
|
||||||
patern_file << std::flush;
|
patern_file << std::flush;
|
||||||
patern_file.close();
|
patern_file.close();
|
||||||
context_->paterns_menu->refresh();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sel_ctrl_ = false;
|
sel_ctrl_ = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user