git repos / blockattack-game

blame: source/code/puzzle_editor/PuzzleEditorState.hpp

normal view · raw

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