diff --git a/source/code/main.cpp b/source/code/main.cpp index 4aaaa7d..43b167d 100644 --- a/source/code/main.cpp +++ b/source/code/main.cpp @@ -1309,6 +1309,7 @@ int main(int argc, char* argv[]) { else if (puzzleEditor) { InitImGui(sdlWindow, renderer, globalData.xsize, globalData.ysize); PuzzleEditorState s; + s.Init(); RunImGuiGameState(s); } else if (globalData.replayArgument.length()) { diff --git a/source/code/puzzle_editor/PuzzleEditorState.cpp b/source/code/puzzle_editor/PuzzleEditorState.cpp index ffff3f9..0778712 100644 --- a/source/code/puzzle_editor/PuzzleEditorState.cpp +++ b/source/code/puzzle_editor/PuzzleEditorState.cpp @@ -25,7 +25,8 @@ https://blockattack.net #include "imgui.h" #include "backends/imgui_impl_sdl2.h" #include "backends/imgui_impl_sdlrenderer2.h" - +#include "../sago/SagoMisc.hpp" +#include "../puzzlehandler.hpp" bool PuzzleEditorState::IsActive() { @@ -36,15 +37,33 @@ void PuzzleEditorState::ProcessInput(const SDL_Event& event, bool& processed) { ImGui_ImplSDL2_ProcessEvent(&event); } +void PuzzleEditorState::Init() { + this->selected_file = ""; + this->puzzle_files = sago::GetFileList("puzzles"); +} + +void PuzzleEditorState::SelectFile(const std::string& file) { + this->selected_file = file; + PuzzleSetName(file); + LoadPuzzleStages(); +} + void PuzzleEditorState::Draw(SDL_Renderer* target) { ImGui::Begin("File list", nullptr, ImGuiWindowFlags_NoCollapse); - if (ImGui::Selectable("File 1", this->selected_file == "File 1")) { - this->selected_file = "File 1"; - } - if (ImGui::Selectable("File 2", this->selected_file == "File 2")) { - this->selected_file = "File 2"; + for (const auto& file : this->puzzle_files) { + if (ImGui::Selectable(file.c_str(), this->selected_file == file)) { + SelectFile(file); + } } + + ImGui::End(); + ImGui::Begin("Puzzles in file"); + int puzzle_count = PuzzleGetNumberOfPuzzles(); + for (int i = 0; i < puzzle_count; ++i) { + if (ImGui::Selectable(std::to_string(i).c_str(), false)) { + } + } ImGui::End(); } diff --git a/source/code/puzzle_editor/PuzzleEditorState.hpp b/source/code/puzzle_editor/PuzzleEditorState.hpp index a46fedb..9dbe0d4 100644 --- a/source/code/puzzle_editor/PuzzleEditorState.hpp +++ b/source/code/puzzle_editor/PuzzleEditorState.hpp @@ -26,7 +26,7 @@ https://blockattack.net #include "../sago/GameStateInterface.hpp" #include - +#include class PuzzleEditorState : public sago::GameStateInterface { @@ -35,12 +35,17 @@ public: PuzzleEditorState(const PuzzleEditorState& orig) = delete; virtual ~PuzzleEditorState() = default; + void Init(); + bool IsActive() override; void ProcessInput(const SDL_Event& event, bool& processed) override; void Draw(SDL_Renderer* target) override; void Update() override; private: + void SelectFile(const std::string& file); + bool isActive = true; std::string selected_file; + std::vector puzzle_files; };