diff --git a/source/code/puzzle_editor/PuzzleEditorState.cpp b/source/code/puzzle_editor/PuzzleEditorState.cpp index 11f7c32..7f31c0b 100644 --- a/source/code/puzzle_editor/PuzzleEditorState.cpp +++ b/source/code/puzzle_editor/PuzzleEditorState.cpp @@ -389,6 +389,21 @@ void PuzzleEditorState::Draw(SDL_Renderer* target) { } } + ImGui::Separator(); + ImGui::InputText("##newfilename", new_filename_buffer, sizeof(new_filename_buffer)); + if (ImGui::Button("Create file")) { + std::string new_file(new_filename_buffer); + if (new_file.size()) { + const auto it = std::find(puzzle_files.begin(), puzzle_files.end(), new_file); + if (it == puzzle_files.end()) { + puzzle_files.push_back(new_file); + std::sort(puzzle_files.begin(), puzzle_files.end()); + sago::WriteFileContent(fmt::format("puzzles/{}", new_file).c_str(), "0"); // Create file with 0 puzzles in it + SelectFile(new_file); + } + } + } + ImGui::End(); ImGui::Begin("Puzzles in file"); const int puzzle_count = PuzzleGetNumberOfPuzzles(); diff --git a/source/code/puzzle_editor/PuzzleEditorState.hpp b/source/code/puzzle_editor/PuzzleEditorState.hpp index 8b0a3d8..e481afe 100644 --- a/source/code/puzzle_editor/PuzzleEditorState.hpp +++ b/source/code/puzzle_editor/PuzzleEditorState.hpp @@ -75,6 +75,7 @@ private: std::string selected_file; std::vector puzzle_files; sago::SagoLogicalResize window_resize; + char new_filename_buffer[256] = "untitled.levels"; std::map > undo_file_stack; std::map > redo_file_stack; diff --git a/source/code/puzzlehandler.cpp b/source/code/puzzlehandler.cpp index e104097..1205946 100644 --- a/source/code/puzzlehandler.cpp +++ b/source/code/puzzlehandler.cpp @@ -177,10 +177,14 @@ void EditorRemovePuzzle(size_t level) { } void EditorAddPuzzle(size_t level) { - if (nrOfPuzzles >= 50) { + if (nrOfPuzzles >= maxNrOfPuzzleStages) { return; } - memmove( puzzleLevels[level+1], puzzleLevels[level], sizeof(puzzleLevels[0])*(50-level-1) ); + if (level >= maxNrOfPuzzleStages) + { + level = 0; + } + memmove( puzzleLevels[level+1], puzzleLevels[level], sizeof(puzzleLevels[0])*(maxNrOfPuzzleStages-level-1) ); nrOfPuzzles++; for (size_t i = 0; i < 6; i++) { for (size_t j =0; j < 12; j++) {