| 1 | /* |
| 2 | =========================================================================== |
| 3 | blockattack - Block Attack - Rise of the Blocks |
| 4 | Copyright (C) 2005-2025 Poul Sander |
| 5 | |
| 6 | This program is free software: you can redistribute it and/or modify |
| 7 | it under the terms of the GNU General Public License as published by |
| 8 | the Free Software Foundation, either version 2 of the License, or |
| 9 | (at your option) any later version. |
| 10 | |
| 11 | This program is distributed in the hope that it will be useful, |
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | GNU General Public License for more details. |
| 15 | |
| 16 | You should have received a copy of the GNU General Public License |
| 17 | along with this program. If not, see http://www.gnu.org/licenses/ |
| 18 | |
| 19 | Source information and contacts persons can be found at |
| 20 | https://blockattack.net |
| 21 | =========================================================================== |
| 22 | */ |
| 23 | |
| 24 | |
| 25 | #pragma once |
| 26 | |
| 27 | #include "../global.hpp" |
| 28 | #include "../sago/GameStateInterface.hpp" |
| 29 | #include "../BlockGameSdl.hpp" |
| 30 | #include <string> |
| 31 | #include <vector> |
| 32 | #include <array> |
| 33 | |
| 34 | #define selection_clear 10 |
| 35 | #define selection_move_up 11 |
| 36 | #define selection_move_down 12 |
| 37 | #define selection_move_left 13 |
| 38 | #define selection_move_right 14 |
| 39 | |
| 40 | struct PuzzleState { |
| 41 | std::array<std::array<std::array<int, 12>, 6>, 50> puzzle_data; |
| 42 | std::vector<int> moves_allowed; |
| 43 | int puzzle_count; |
| 44 | int current_puzzle; |
| 45 | }; |
| 46 | |
| 47 | class PuzzleEditorState : public sago::GameStateInterface { |
| 48 | public: |
| 49 | PuzzleEditorState(); |
| 50 | PuzzleEditorState(const PuzzleEditorState& orig) = delete; |
| 51 | virtual ~PuzzleEditorState() = default; |
| 52 | |
| 53 | void Init(); |
| 54 | |
| 55 | bool IsActive() override; |
| 56 | void ProcessInput(const SDL_Event& event, bool& processed) override; |
| 57 | void Draw(SDL_Renderer* target) override; |
| 58 | void Update() override; |
| 59 | |
| 60 | private: |
| 61 | void SelectFile(const std::string& file); |
| 62 | |
| 63 | void BrickClicked(int x, int y); |
| 64 | void SaveCurrentState(); |
| 65 | void Undo(); |
| 66 | void Redo(); |
| 67 | bool CanUndo() const; |
| 68 | bool CanRedo() const; |
| 69 | |
| 70 | int selected_action = 0; |
| 71 | |
| 72 | bool isActive = true; |
| 73 | bool read_only = true; |
| 74 | int selected_puzzle = -1; |
| 75 | std::string selected_file; |
| 76 | std::vector<std::string> puzzle_files; |
| 77 | sago::SagoLogicalResize window_resize; |
| 78 | char new_filename_buffer[256] = "untitled.levels"; |
| 79 | |
| 80 | std::map<std::string, std::vector<PuzzleState> > undo_file_stack; |
| 81 | std::map<std::string, std::vector<PuzzleState> > redo_file_stack; |
| 82 | std::vector<PuzzleState> undo_stack; |
| 83 | std::vector<PuzzleState> redo_stack; |
| 84 | static const size_t MAX_UNDO_STATES = 50; |
| 85 | }; |