| 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 |
#include "PuzzleEditorState.hpp" |
| 298835a8 |
Poul Sander |
2025-05-31 20:49 |
25 |
|
| 298835a8 |
Poul Sander |
2025-05-31 20:49 |
26 |
#include <unistd.h> |
| 52352a94 |
Poul Sander |
2025-06-03 19:04 |
27 |
#include <fmt/core.h> |
| 298835a8 |
Poul Sander |
2025-05-31 20:49 |
28 |
|
| 1873b078 |
Poul Sander |
2025-02-06 22:01 |
29 |
#include "imgui.h" |
| 37278577 |
Poul Sander |
2025-06-21 07:50 |
30 |
#include "imgui_internal.h" |
| 1873b078 |
Poul Sander |
2025-02-06 22:01 |
31 |
#include "backends/imgui_impl_sdl2.h" |
| 1873b078 |
Poul Sander |
2025-02-06 22:01 |
32 |
#include "backends/imgui_impl_sdlrenderer2.h" |
| a80f6a78 |
Poul Sander |
2025-04-04 18:34 |
33 |
#include "../sago/SagoMisc.hpp" |
| a80f6a78 |
Poul Sander |
2025-04-04 18:34 |
34 |
#include "../puzzlehandler.hpp" |
| 1873b078 |
Poul Sander |
2025-02-06 22:01 |
35 |
|
| 1873b078 |
Poul Sander |
2025-02-06 22:01 |
36 |
|
| af6d5a44 |
Poul Sander |
2025-06-21 19:31 |
37 |
void SetSinglePuzzleMode(int level); |
| af6d5a44 |
Poul Sander |
2025-06-21 19:31 |
38 |
|
| 636cde3b |
Poul Sander |
2025-05-15 21:40 |
39 |
PuzzleEditorState::PuzzleEditorState() { |
| 636cde3b |
Poul Sander |
2025-05-15 21:40 |
40 |
this->window_resize = sago::SagoLogicalResize(BOARD_WIDTH+5, BOARD_HEIGHT+5); |
| 636cde3b |
Poul Sander |
2025-05-15 21:40 |
41 |
} |
| 636cde3b |
Poul Sander |
2025-05-15 21:40 |
42 |
|
| 1873b078 |
Poul Sander |
2025-02-06 22:01 |
43 |
bool PuzzleEditorState::IsActive() { |
| 1873b078 |
Poul Sander |
2025-02-06 22:01 |
44 |
return isActive; |
| 1873b078 |
Poul Sander |
2025-02-06 22:01 |
45 |
} |
| 1873b078 |
Poul Sander |
2025-02-06 22:01 |
46 |
|
| 1873b078 |
Poul Sander |
2025-02-06 22:01 |
47 |
void PuzzleEditorState::ProcessInput(const SDL_Event& event, bool& processed) { |
| 1873b078 |
Poul Sander |
2025-02-06 22:01 |
48 |
ImGui_ImplSDL2_ProcessEvent(&event); |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
49 |
|
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
50 |
if (event.type == SDL_KEYDOWN && !read_only) { |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
51 |
const Uint8* keystate = SDL_GetKeyboardState(NULL); |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
52 |
bool ctrl_held = keystate[SDL_SCANCODE_LCTRL] || keystate[SDL_SCANCODE_RCTRL]; |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
53 |
|
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
54 |
if (ctrl_held && event.key.keysym.sym == SDLK_z) { |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
55 |
if (keystate[SDL_SCANCODE_LSHIFT] || keystate[SDL_SCANCODE_RSHIFT]) { |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
56 |
Redo(); |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
57 |
} else { |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
58 |
Undo(); |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
59 |
} |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
60 |
processed = true; |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
61 |
} else if (ctrl_held && event.key.keysym.sym == SDLK_y) { |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
62 |
Redo(); |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
63 |
processed = true; |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
64 |
} |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
65 |
} |
| 1873b078 |
Poul Sander |
2025-02-06 22:01 |
66 |
} |
| 1873b078 |
Poul Sander |
2025-02-06 22:01 |
67 |
|
| a80f6a78 |
Poul Sander |
2025-04-04 18:34 |
68 |
void PuzzleEditorState::Init() { |
| a80f6a78 |
Poul Sander |
2025-04-04 18:34 |
69 |
this->selected_file = ""; |
| a80f6a78 |
Poul Sander |
2025-04-04 18:34 |
70 |
this->puzzle_files = sago::GetFileList("puzzles"); |
| a80f6a78 |
Poul Sander |
2025-04-04 18:34 |
71 |
} |
| a80f6a78 |
Poul Sander |
2025-04-04 18:34 |
72 |
|
| a80f6a78 |
Poul Sander |
2025-04-04 18:34 |
73 |
void PuzzleEditorState::SelectFile(const std::string& file) { |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
74 |
undo_file_stack[this->selected_file] = undo_stack; |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
75 |
redo_file_stack[this->selected_file] = redo_stack; |
| a80f6a78 |
Poul Sander |
2025-04-04 18:34 |
76 |
this->selected_file = file; |
| a80f6a78 |
Poul Sander |
2025-04-04 18:34 |
77 |
PuzzleSetName(file); |
| a80f6a78 |
Poul Sander |
2025-04-04 18:34 |
78 |
LoadPuzzleStages(); |
| 298835a8 |
Poul Sander |
2025-05-31 20:49 |
79 |
read_only = false; |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
80 |
undo_stack = undo_file_stack[this->selected_file]; |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
81 |
redo_stack = redo_file_stack[this->selected_file]; |
| 298835a8 |
Poul Sander |
2025-05-31 20:49 |
82 |
if (file == "puzzle.levels") { |
| 298835a8 |
Poul Sander |
2025-05-31 20:49 |
83 |
read_only = true; |
| 298835a8 |
Poul Sander |
2025-05-31 20:49 |
84 |
} |
| a80f6a78 |
Poul Sander |
2025-04-04 18:34 |
85 |
} |
| a80f6a78 |
Poul Sander |
2025-04-04 18:34 |
86 |
|
| 636cde3b |
Poul Sander |
2025-05-15 21:40 |
87 |
static void LogicalToPhysical(const sago::SagoLogicalResize& resize, ImVec2& inout) { |
| 636cde3b |
Poul Sander |
2025-05-15 21:40 |
88 |
int inx = inout.x; |
| 636cde3b |
Poul Sander |
2025-05-15 21:40 |
89 |
int iny = inout.y; |
| 636cde3b |
Poul Sander |
2025-05-15 21:40 |
90 |
int outx = inout.x; |
| 636cde3b |
Poul Sander |
2025-05-15 21:40 |
91 |
int outy = inout.y; |
| 636cde3b |
Poul Sander |
2025-05-15 21:40 |
92 |
resize.LogicalToPhysical(inx, iny, outx, outy); |
| 636cde3b |
Poul Sander |
2025-05-15 21:40 |
93 |
inout.x = outx; |
| 636cde3b |
Poul Sander |
2025-05-15 21:40 |
94 |
inout.y = outy; |
| 636cde3b |
Poul Sander |
2025-05-15 21:40 |
95 |
} |
| 636cde3b |
Poul Sander |
2025-05-15 21:40 |
96 |
|
| 59365d69 |
Poul Sander |
2025-05-25 12:06 |
97 |
|
| e1a54754 |
Poul Sander |
2025-05-25 13:31 |
98 |
static void ImGuiWritePartOfTexture(SDL_Texture* texture, int topx, int topy, int tex_w, int tex_h, int w, int h) { |
| e1a54754 |
Poul Sander |
2025-05-25 13:31 |
99 |
float sprite_w = tex_w; |
| e1a54754 |
Poul Sander |
2025-05-25 13:31 |
100 |
float sprite_h = tex_h; |
| 59365d69 |
Poul Sander |
2025-05-25 12:06 |
101 |
float topxf = topx; |
| 59365d69 |
Poul Sander |
2025-05-25 12:06 |
102 |
float topyf = topy; |
| 59365d69 |
Poul Sander |
2025-05-25 12:06 |
103 |
ImVec2 uv0 = ImVec2(topxf / tex_w, topyf / tex_h); |
| 59365d69 |
Poul Sander |
2025-05-25 12:06 |
104 |
ImVec2 uv1 = ImVec2((topxf + sprite_w) / tex_w, (topyf + sprite_h) / tex_h); |
| 59365d69 |
Poul Sander |
2025-05-25 12:06 |
105 |
ImGui::Image((ImTextureID)(intptr_t)texture, ImVec2((float)w, (float)h), uv0, uv1); |
| 59365d69 |
Poul Sander |
2025-05-25 12:06 |
106 |
} |
| 59365d69 |
Poul Sander |
2025-05-25 12:06 |
107 |
|
| 59365d69 |
Poul Sander |
2025-05-25 12:06 |
108 |
|
| 59365d69 |
Poul Sander |
2025-05-25 12:06 |
109 |
static void DrawBrick(int brick, int x, int y, int width, int height) { |
| 59365d69 |
Poul Sander |
2025-05-25 12:06 |
110 |
if (brick < 0 || brick > 6) { |
| 59365d69 |
Poul Sander |
2025-05-25 12:06 |
111 |
return; |
| 59365d69 |
Poul Sander |
2025-05-25 12:06 |
112 |
} |
| 59365d69 |
Poul Sander |
2025-05-25 12:06 |
113 |
|
| 59365d69 |
Poul Sander |
2025-05-25 12:06 |
114 |
sago::SagoSprite& sprite = globalData.bricks[brick]; |
| 59365d69 |
Poul Sander |
2025-05-25 12:06 |
115 |
ImGui::SetCursorScreenPos({ static_cast<float>(x), static_cast<float>(y) }); |
| 1ae9f202 |
Poul Sander |
2025-05-30 13:59 |
116 |
ImGuiWritePartOfTexture(sprite.GetTextureHandler().get(), sprite.GetImageCord().x, sprite.GetImageCord().y, sprite.GetWidth(), sprite.GetHeight(), width, height); |
| 59365d69 |
Poul Sander |
2025-05-25 12:06 |
117 |
} |
| 59365d69 |
Poul Sander |
2025-05-25 12:06 |
118 |
|
| 72e87270 |
Poul Sander |
2025-06-21 15:22 |
119 |
/** |
| 72e87270 |
Poul Sander |
2025-06-21 15:22 |
120 |
* Takes the brick pointed to and moves up all bricks above it to leave an empty space. |
| 72e87270 |
Poul Sander |
2025-06-21 15:22 |
121 |
* If bricks are pushed out of the board then the disappear. |
| 72e87270 |
Poul Sander |
2025-06-21 15:22 |
122 |
* @param level The level to edit |
| 72e87270 |
Poul Sander |
2025-06-21 15:22 |
123 |
* @param x |
| 72e87270 |
Poul Sander |
2025-06-21 15:22 |
124 |
* @param y |
| 72e87270 |
Poul Sander |
2025-06-21 15:22 |
125 |
*/ |
| 72e87270 |
Poul Sander |
2025-06-21 15:22 |
126 |
static void BricksMoveUp(int level, int x, int y) { |
| 72e87270 |
Poul Sander |
2025-06-21 15:22 |
127 |
for (int i = 11; i > y; i--) { |
| 72e87270 |
Poul Sander |
2025-06-21 15:22 |
128 |
PuzzleSetBrick(level, x, i, PuzzleGetBrick(level, x, i-1)); |
| 72e87270 |
Poul Sander |
2025-06-21 15:22 |
129 |
} |
| 72e87270 |
Poul Sander |
2025-06-21 15:22 |
130 |
PuzzleSetBrick(level, x, y, -1); //Clear the space we started |
| 72e87270 |
Poul Sander |
2025-06-21 15:22 |
131 |
} |
| 72e87270 |
Poul Sander |
2025-06-21 15:22 |
132 |
|
| 72e87270 |
Poul Sander |
2025-06-21 15:22 |
133 |
static void BricksMoveDown(int level, int x, int y) { |
| 72e87270 |
Poul Sander |
2025-06-21 15:22 |
134 |
for (int i = 0; i < y; i++) { |
| 72e87270 |
Poul Sander |
2025-06-21 15:22 |
135 |
PuzzleSetBrick(level, x, i, PuzzleGetBrick(level, x, i+1)); |
| 72e87270 |
Poul Sander |
2025-06-21 15:22 |
136 |
} |
| 72e87270 |
Poul Sander |
2025-06-21 15:22 |
137 |
PuzzleSetBrick(level, x, y, -1); //Clear the space we started |
| 72e87270 |
Poul Sander |
2025-06-21 15:22 |
138 |
} |
| 72e87270 |
Poul Sander |
2025-06-21 15:22 |
139 |
|
| 72e87270 |
Poul Sander |
2025-06-21 15:22 |
140 |
static void BricksMoveColumnLeft(int level, int x) { |
| 72e87270 |
Poul Sander |
2025-06-21 15:22 |
141 |
for (int i=0; i < x; i++) { |
| 72e87270 |
Poul Sander |
2025-06-21 15:22 |
142 |
for (int j=0; j<12 ; j++) { |
| 72e87270 |
Poul Sander |
2025-06-21 15:22 |
143 |
PuzzleSetBrick(level, i, j, PuzzleGetBrick(level, i+1, j)); |
| 72e87270 |
Poul Sander |
2025-06-21 15:22 |
144 |
} |
| 72e87270 |
Poul Sander |
2025-06-21 15:22 |
145 |
} |
| 72e87270 |
Poul Sander |
2025-06-21 15:22 |
146 |
for (int j=0; j<12 ; j++) { |
| 72e87270 |
Poul Sander |
2025-06-21 15:22 |
147 |
PuzzleSetBrick(level, x, j, -1); |
| 72e87270 |
Poul Sander |
2025-06-21 15:22 |
148 |
} |
| 72e87270 |
Poul Sander |
2025-06-21 15:22 |
149 |
} |
| 72e87270 |
Poul Sander |
2025-06-21 15:22 |
150 |
|
| 72e87270 |
Poul Sander |
2025-06-21 15:22 |
151 |
static void BricksMoveColumnRight(int level, int x) { |
| 72e87270 |
Poul Sander |
2025-06-21 15:22 |
152 |
for (int i=5; i > x; i--) { |
| 72e87270 |
Poul Sander |
2025-06-21 15:22 |
153 |
for (int j=0; j<12 ; j++) { |
| 72e87270 |
Poul Sander |
2025-06-21 15:22 |
154 |
PuzzleSetBrick(level, i, j, PuzzleGetBrick(level, i-1, j)); |
| 72e87270 |
Poul Sander |
2025-06-21 15:22 |
155 |
} |
| 72e87270 |
Poul Sander |
2025-06-21 15:22 |
156 |
} |
| 72e87270 |
Poul Sander |
2025-06-21 15:22 |
157 |
for (int j=0; j<12 ; j++) { |
| 72e87270 |
Poul Sander |
2025-06-21 15:22 |
158 |
PuzzleSetBrick(level, x, j, -1); |
| 72e87270 |
Poul Sander |
2025-06-21 15:22 |
159 |
} |
| 72e87270 |
Poul Sander |
2025-06-21 15:22 |
160 |
} |
| 72e87270 |
Poul Sander |
2025-06-21 15:22 |
161 |
|
| b8a4e6f1 |
Poul Sander |
2025-06-21 10:31 |
162 |
|
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
163 |
void PuzzleEditorState::SaveCurrentState() { |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
164 |
if (undo_stack.size() >= MAX_UNDO_STATES) { |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
165 |
std::vector<PuzzleState> temp; |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
166 |
for (size_t i = 0; i < MAX_UNDO_STATES - 1; ++i) { |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
167 |
temp.push_back(undo_stack.back()); |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
168 |
undo_stack.pop_back(); |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
169 |
} |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
170 |
undo_stack = std::vector<PuzzleState>(); |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
171 |
while (!temp.empty()) { |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
172 |
undo_stack.push_back(temp.back()); |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
173 |
temp.pop_back(); |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
174 |
} |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
175 |
} |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
176 |
|
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
177 |
PuzzleState current_state; |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
178 |
current_state.puzzle_count = PuzzleGetNumberOfPuzzles(); |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
179 |
current_state.current_puzzle = this->selected_puzzle; |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
180 |
current_state.moves_allowed.resize(current_state.puzzle_count); |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
181 |
|
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
182 |
for (int level = 0; level < current_state.puzzle_count; ++level) { |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
183 |
current_state.moves_allowed[level] = PuzzleNumberOfMovesAllowed(level); |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
184 |
for (int x = 0; x < 6; ++x) { |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
185 |
for (int y = 0; y < 12; ++y) { |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
186 |
current_state.puzzle_data[level][x][y] = PuzzleGetBrick(level, x, y); |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
187 |
} |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
188 |
} |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
189 |
} |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
190 |
|
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
191 |
undo_stack.push_back(current_state); |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
192 |
while (!redo_stack.empty()) { |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
193 |
redo_stack.pop_back(); |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
194 |
} |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
195 |
} |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
196 |
|
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
197 |
void PuzzleEditorState::Undo() { |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
198 |
if (!CanUndo()) { |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
199 |
return; |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
200 |
} |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
201 |
|
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
202 |
PuzzleState current_state; |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
203 |
current_state.puzzle_count = PuzzleGetNumberOfPuzzles(); |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
204 |
current_state.current_puzzle = this->selected_puzzle; |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
205 |
current_state.moves_allowed.resize(current_state.puzzle_count); |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
206 |
|
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
207 |
for (int level = 0; level < current_state.puzzle_count; ++level) { |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
208 |
current_state.moves_allowed[level] = PuzzleNumberOfMovesAllowed(level); |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
209 |
for (int x = 0; x < 6; ++x) { |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
210 |
for (int y = 0; y < 12; ++y) { |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
211 |
current_state.puzzle_data[level][x][y] = PuzzleGetBrick(level, x, y); |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
212 |
} |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
213 |
} |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
214 |
} |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
215 |
redo_stack.push_back(current_state); |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
216 |
|
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
217 |
PuzzleState previous_state = undo_stack.back(); |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
218 |
undo_stack.pop_back(); |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
219 |
|
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
220 |
EditorResizePuzzleNumber(previous_state.puzzle_count); |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
221 |
for (int level = 0; level < previous_state.puzzle_count; ++level) { |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
222 |
PuzzleNumberOfMovesAllowedSet(level, previous_state.moves_allowed[level]); |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
223 |
for (int x = 0; x < 6; ++x) { |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
224 |
for (int y = 0; y < 12; ++y) { |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
225 |
PuzzleSetBrick(level, x, y, previous_state.puzzle_data[level][x][y]); |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
226 |
} |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
227 |
} |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
228 |
} |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
229 |
|
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
230 |
this->selected_puzzle = previous_state.current_puzzle; |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
231 |
SavePuzzleStages(); |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
232 |
} |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
233 |
|
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
234 |
void PuzzleEditorState::Redo() { |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
235 |
if (!CanRedo()) { |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
236 |
return; |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
237 |
} |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
238 |
|
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
239 |
PuzzleState current_state; |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
240 |
current_state.puzzle_count = PuzzleGetNumberOfPuzzles(); |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
241 |
current_state.current_puzzle = this->selected_puzzle; |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
242 |
current_state.moves_allowed.resize(current_state.puzzle_count); |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
243 |
|
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
244 |
for (int level = 0; level < current_state.puzzle_count; ++level) { |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
245 |
current_state.moves_allowed[level] = PuzzleNumberOfMovesAllowed(level); |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
246 |
for (int x = 0; x < 6; ++x) { |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
247 |
for (int y = 0; y < 12; ++y) { |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
248 |
current_state.puzzle_data[level][x][y] = PuzzleGetBrick(level, x, y); |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
249 |
} |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
250 |
} |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
251 |
} |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
252 |
undo_stack.push_back(current_state); |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
253 |
|
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
254 |
PuzzleState next_state = redo_stack.back(); |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
255 |
redo_stack.pop_back(); |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
256 |
|
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
257 |
EditorResizePuzzleNumber(next_state.puzzle_count); |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
258 |
for (int level = 0; level < next_state.puzzle_count; ++level) { |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
259 |
PuzzleNumberOfMovesAllowedSet(level, next_state.moves_allowed[level]); |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
260 |
for (int x = 0; x < 6; ++x) { |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
261 |
for (int y = 0; y < 12; ++y) { |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
262 |
PuzzleSetBrick(level, x, y, next_state.puzzle_data[level][x][y]); |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
263 |
} |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
264 |
} |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
265 |
} |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
266 |
|
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
267 |
this->selected_puzzle = next_state.current_puzzle; |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
268 |
SavePuzzleStages(); |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
269 |
} |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
270 |
|
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
271 |
bool PuzzleEditorState::CanUndo() const { |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
272 |
return !undo_stack.empty(); |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
273 |
} |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
274 |
|
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
275 |
bool PuzzleEditorState::CanRedo() const { |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
276 |
return !redo_stack.empty(); |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
277 |
} |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
278 |
|
| b8a4e6f1 |
Poul Sander |
2025-06-21 10:31 |
279 |
void PuzzleEditorState::BrickClicked(int x, int y) { |
| b8a4e6f1 |
Poul Sander |
2025-06-21 10:31 |
280 |
if (read_only) { |
| b8a4e6f1 |
Poul Sander |
2025-06-21 10:31 |
281 |
return; |
| b8a4e6f1 |
Poul Sander |
2025-06-21 10:31 |
282 |
} |
| b8a4e6f1 |
Poul Sander |
2025-06-21 10:31 |
283 |
if (x < 0 || x >= 6) { |
| b8a4e6f1 |
Poul Sander |
2025-06-21 10:31 |
284 |
return; |
| b8a4e6f1 |
Poul Sander |
2025-06-21 10:31 |
285 |
} |
| b8a4e6f1 |
Poul Sander |
2025-06-21 10:31 |
286 |
if (y <0 || y >= 12) { |
| b8a4e6f1 |
Poul Sander |
2025-06-21 10:31 |
287 |
return; |
| b8a4e6f1 |
Poul Sander |
2025-06-21 10:31 |
288 |
} |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
289 |
|
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
290 |
SaveCurrentState(); |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
291 |
|
| b8a4e6f1 |
Poul Sander |
2025-06-21 10:31 |
292 |
if (selected_action >= 0 && selected_action < 7) { |
| b8a4e6f1 |
Poul Sander |
2025-06-21 10:31 |
293 |
PuzzleSetBrick(this->selected_puzzle, x, y, this->selected_action); |
| 72e87270 |
Poul Sander |
2025-06-21 15:22 |
294 |
SavePuzzleStages(); |
| b8a4e6f1 |
Poul Sander |
2025-06-21 10:31 |
295 |
} |
| b8a4e6f1 |
Poul Sander |
2025-06-21 10:31 |
296 |
if (selected_action == selection_clear) { |
| b8a4e6f1 |
Poul Sander |
2025-06-21 10:31 |
297 |
PuzzleSetBrick(this->selected_puzzle, x, y, -1); |
| 72e87270 |
Poul Sander |
2025-06-21 15:22 |
298 |
SavePuzzleStages(); |
| 72e87270 |
Poul Sander |
2025-06-21 15:22 |
299 |
} |
| 72e87270 |
Poul Sander |
2025-06-21 15:22 |
300 |
if (selected_action == selection_move_up) { |
| 72e87270 |
Poul Sander |
2025-06-21 15:22 |
301 |
BricksMoveUp(this->selected_puzzle, x, y); |
| 72e87270 |
Poul Sander |
2025-06-21 15:22 |
302 |
SavePuzzleStages(); |
| 72e87270 |
Poul Sander |
2025-06-21 15:22 |
303 |
} |
| 72e87270 |
Poul Sander |
2025-06-21 15:22 |
304 |
if (selected_action == selection_move_down) { |
| 72e87270 |
Poul Sander |
2025-06-21 15:22 |
305 |
BricksMoveDown(this->selected_puzzle, x, y); |
| 72e87270 |
Poul Sander |
2025-06-21 15:22 |
306 |
SavePuzzleStages(); |
| 72e87270 |
Poul Sander |
2025-06-21 15:22 |
307 |
} |
| 72e87270 |
Poul Sander |
2025-06-21 15:22 |
308 |
if (selected_action == selection_move_left) { |
| 72e87270 |
Poul Sander |
2025-06-21 15:22 |
309 |
BricksMoveColumnLeft(this->selected_puzzle, x); |
| 72e87270 |
Poul Sander |
2025-06-21 15:22 |
310 |
SavePuzzleStages(); |
| 72e87270 |
Poul Sander |
2025-06-21 15:22 |
311 |
} |
| 72e87270 |
Poul Sander |
2025-06-21 15:22 |
312 |
if (selected_action == selection_move_right) { |
| 72e87270 |
Poul Sander |
2025-06-21 15:22 |
313 |
BricksMoveColumnRight(this->selected_puzzle, x); |
| 72e87270 |
Poul Sander |
2025-06-21 15:22 |
314 |
SavePuzzleStages(); |
| b8a4e6f1 |
Poul Sander |
2025-06-21 10:31 |
315 |
} |
| b8a4e6f1 |
Poul Sander |
2025-06-21 10:31 |
316 |
|
| b8a4e6f1 |
Poul Sander |
2025-06-21 10:31 |
317 |
} |
| b8a4e6f1 |
Poul Sander |
2025-06-21 10:31 |
318 |
|
| 1873b078 |
Poul Sander |
2025-02-06 22:01 |
319 |
void PuzzleEditorState::Draw(SDL_Renderer* target) { |
| 6046ca3f |
Poul Sander |
2025-04-06 16:14 |
320 |
DrawBackground(target); |
| 1fcc8881 |
Poul Sander |
2025-05-15 18:54 |
321 |
|
| 1fcc8881 |
Poul Sander |
2025-05-15 18:54 |
322 |
ImGui::Begin("Board area"); |
| 1fcc8881 |
Poul Sander |
2025-05-15 18:54 |
323 |
ImGui::BeginChild("Test"); |
| 1fcc8881 |
Poul Sander |
2025-05-15 18:54 |
324 |
ImVec2 p = ImGui::GetCursorScreenPos(); |
| 636cde3b |
Poul Sander |
2025-05-15 21:40 |
325 |
ImVec2 size = ImGui::GetContentRegionAvail(); |
| 636cde3b |
Poul Sander |
2025-05-15 21:40 |
326 |
int xoffset = p.x; |
| 636cde3b |
Poul Sander |
2025-05-15 21:40 |
327 |
int yoffset = p.y; |
| 636cde3b |
Poul Sander |
2025-05-15 21:40 |
328 |
int height = BOARD_HEIGHT; |
| 636cde3b |
Poul Sander |
2025-05-15 21:40 |
329 |
int width = BOARD_WIDTH; |
| 636cde3b |
Poul Sander |
2025-05-15 21:40 |
330 |
window_resize.SetPhysicalSize(size.x, size.y); |
| 636cde3b |
Poul Sander |
2025-05-15 21:40 |
331 |
|
| 636cde3b |
Poul Sander |
2025-05-15 21:40 |
332 |
|
| 59365d69 |
Poul Sander |
2025-05-25 12:06 |
333 |
int brick_size = 50; |
| 59365d69 |
Poul Sander |
2025-05-25 12:06 |
334 |
window_resize.LogicalToPhysical(&brick_size, nullptr); |
| e1a54754 |
Poul Sander |
2025-05-25 13:31 |
335 |
brick_size -= window_resize.GetLeftMargin(); |
| 59365d69 |
Poul Sander |
2025-05-25 12:06 |
336 |
for (int i=0; i < 6; ++i) { |
| 59365d69 |
Poul Sander |
2025-05-25 12:06 |
337 |
for (int j=0; j < 12; ++j) { |
| 59365d69 |
Poul Sander |
2025-05-25 12:06 |
338 |
ImVec2 p1(i*50.0f, (11-j)*50.0f); |
| 59365d69 |
Poul Sander |
2025-05-25 12:06 |
339 |
LogicalToPhysical(window_resize, p1); |
| 59365d69 |
Poul Sander |
2025-05-25 12:06 |
340 |
p1.x += xoffset; |
| 59365d69 |
Poul Sander |
2025-05-25 12:06 |
341 |
p1.y += yoffset; |
| 59365d69 |
Poul Sander |
2025-05-25 12:06 |
342 |
int brick = PuzzleGetBrick(this->selected_puzzle, i, j); |
| 59365d69 |
Poul Sander |
2025-05-25 12:06 |
343 |
DrawBrick(brick, static_cast<int>(p1.x), static_cast<int>(p1.y), brick_size, brick_size); |
| 59365d69 |
Poul Sander |
2025-05-25 12:06 |
344 |
} |
| 59365d69 |
Poul Sander |
2025-05-25 12:06 |
345 |
} |
| 59365d69 |
Poul Sander |
2025-05-25 12:06 |
346 |
|
| 1fcc8881 |
Poul Sander |
2025-05-15 18:54 |
347 |
for (int i=0; i <= 6;++i) { |
| 636cde3b |
Poul Sander |
2025-05-15 21:40 |
348 |
ImVec2 p1(i*50.0f, 0); |
| 636cde3b |
Poul Sander |
2025-05-15 21:40 |
349 |
ImVec2 p2(i*50.0f, height); |
| 636cde3b |
Poul Sander |
2025-05-15 21:40 |
350 |
LogicalToPhysical(window_resize, p1); |
| 636cde3b |
Poul Sander |
2025-05-15 21:40 |
351 |
LogicalToPhysical(window_resize, p2); |
| 636cde3b |
Poul Sander |
2025-05-15 21:40 |
352 |
p1.x += xoffset; |
| 636cde3b |
Poul Sander |
2025-05-15 21:40 |
353 |
p1.y += yoffset; |
| 636cde3b |
Poul Sander |
2025-05-15 21:40 |
354 |
p2.x += xoffset; |
| 636cde3b |
Poul Sander |
2025-05-15 21:40 |
355 |
p2.y += yoffset; |
| 636cde3b |
Poul Sander |
2025-05-15 21:40 |
356 |
ImGui::GetWindowDrawList()->AddLine(p1, p2, IM_COL32(255, 0, 0, 100)); |
| 1fcc8881 |
Poul Sander |
2025-05-15 18:54 |
357 |
} |
| 1fcc8881 |
Poul Sander |
2025-05-15 18:54 |
358 |
for (int i=0; i <= 12;++i) { |
| 636cde3b |
Poul Sander |
2025-05-15 21:40 |
359 |
ImVec2 p1(0,i*50.0f); |
| 636cde3b |
Poul Sander |
2025-05-15 21:40 |
360 |
ImVec2 p2(width, i*50.0f); |
| 636cde3b |
Poul Sander |
2025-05-15 21:40 |
361 |
LogicalToPhysical(window_resize, p1); |
| 636cde3b |
Poul Sander |
2025-05-15 21:40 |
362 |
LogicalToPhysical(window_resize, p2); |
| 636cde3b |
Poul Sander |
2025-05-15 21:40 |
363 |
p1.x += xoffset; |
| 636cde3b |
Poul Sander |
2025-05-15 21:40 |
364 |
p1.y += yoffset; |
| 636cde3b |
Poul Sander |
2025-05-15 21:40 |
365 |
p2.x += xoffset; |
| 636cde3b |
Poul Sander |
2025-05-15 21:40 |
366 |
p2.y += yoffset; |
| 636cde3b |
Poul Sander |
2025-05-15 21:40 |
367 |
ImGui::GetWindowDrawList()->AddLine(p1, p2, IM_COL32(255, 0, 0, 100)); |
| 6046ca3f |
Poul Sander |
2025-04-06 16:14 |
368 |
} |
| 37278577 |
Poul Sander |
2025-06-21 07:50 |
369 |
ImGuiIO& io = ImGui::GetIO(); |
| 37278577 |
Poul Sander |
2025-06-21 07:50 |
370 |
if (ImGui::IsMouseReleased(0) && io.MouseDownDurationPrev[0] < 0.3f && !ImGui::IsMouseDragPastThreshold(0)) { |
| 37278577 |
Poul Sander |
2025-06-21 07:50 |
371 |
ImVec2 pos = io.MousePos; |
| 37278577 |
Poul Sander |
2025-06-21 07:50 |
372 |
pos.x -= xoffset; |
| 37278577 |
Poul Sander |
2025-06-21 07:50 |
373 |
pos.y -= yoffset; |
| 37278577 |
Poul Sander |
2025-06-21 07:50 |
374 |
int logical_pos_x = 0; |
| 37278577 |
Poul Sander |
2025-06-21 07:50 |
375 |
int logical_pos_y = 0; |
| 37278577 |
Poul Sander |
2025-06-21 07:50 |
376 |
window_resize.PhysicalToLogical(pos.x, pos.y, logical_pos_x, logical_pos_y); |
| 37278577 |
Poul Sander |
2025-06-21 07:50 |
377 |
//std::cout << "Clicked at: " << pos.x << "," << pos.y << "\n"; |
| 37278577 |
Poul Sander |
2025-06-21 07:50 |
378 |
//std::cout << "Logical Pos: " << logical_pos_x << "," << logical_pos_y << "\n"; |
| 37278577 |
Poul Sander |
2025-06-21 07:50 |
379 |
int board_x = logical_pos_x / 50; |
| b8a4e6f1 |
Poul Sander |
2025-06-21 10:31 |
380 |
int board_y = 11-(logical_pos_y / 50); |
| 37278577 |
Poul Sander |
2025-06-21 07:50 |
381 |
if (board_x >=0 && board_x < 6 && board_y >= 0 && board_y < 12) { |
| 37278577 |
Poul Sander |
2025-06-21 07:50 |
382 |
std::cout << "Board Pos: " << board_x << "," << board_y << "\n"; |
| b8a4e6f1 |
Poul Sander |
2025-06-21 10:31 |
383 |
BrickClicked(board_x, board_y); |
| 37278577 |
Poul Sander |
2025-06-21 07:50 |
384 |
} |
| 37278577 |
Poul Sander |
2025-06-21 07:50 |
385 |
|
| 37278577 |
Poul Sander |
2025-06-21 07:50 |
386 |
} |
| 1fcc8881 |
Poul Sander |
2025-05-15 18:54 |
387 |
ImGui::EndChild(); |
| 1fcc8881 |
Poul Sander |
2025-05-15 18:54 |
388 |
ImGui::End(); |
| 1fcc8881 |
Poul Sander |
2025-05-15 18:54 |
389 |
|
| 1873b078 |
Poul Sander |
2025-02-06 22:01 |
390 |
ImGui::Begin("File list", nullptr, ImGuiWindowFlags_NoCollapse); |
| a80f6a78 |
Poul Sander |
2025-04-04 18:34 |
391 |
for (const auto& file : this->puzzle_files) { |
| a80f6a78 |
Poul Sander |
2025-04-04 18:34 |
392 |
if (ImGui::Selectable(file.c_str(), this->selected_file == file)) { |
| a80f6a78 |
Poul Sander |
2025-04-04 18:34 |
393 |
SelectFile(file); |
| a80f6a78 |
Poul Sander |
2025-04-04 18:34 |
394 |
} |
| 1873b078 |
Poul Sander |
2025-02-06 22:01 |
395 |
} |
| 1873b078 |
Poul Sander |
2025-02-06 22:01 |
396 |
|
| a80f6a78 |
Poul Sander |
2025-04-04 18:34 |
397 |
ImGui::End(); |
| a80f6a78 |
Poul Sander |
2025-04-04 18:34 |
398 |
ImGui::Begin("Puzzles in file"); |
| a80f6a78 |
Poul Sander |
2025-04-04 18:34 |
399 |
int puzzle_count = PuzzleGetNumberOfPuzzles(); |
| a80f6a78 |
Poul Sander |
2025-04-04 18:34 |
400 |
for (int i = 0; i < puzzle_count; ++i) { |
| 6046ca3f |
Poul Sander |
2025-04-06 16:14 |
401 |
if (ImGui::Selectable(std::to_string(i).c_str(), this->selected_puzzle == i)) { |
| 6046ca3f |
Poul Sander |
2025-04-06 16:14 |
402 |
this->selected_puzzle = i; |
| a80f6a78 |
Poul Sander |
2025-04-04 18:34 |
403 |
} |
| a80f6a78 |
Poul Sander |
2025-04-04 18:34 |
404 |
} |
| 0305b768 |
Poul Sander |
2025-07-17 14:08 |
405 |
if (ImGui::Button("Add puzzle")) { |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
406 |
if (!read_only) { |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
407 |
SaveCurrentState(); |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
408 |
EditorAddPuzzle(this->selected_puzzle); |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
409 |
SavePuzzleStages(); |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
410 |
} |
| 0305b768 |
Poul Sander |
2025-07-17 14:08 |
411 |
} |
| 0305b768 |
Poul Sander |
2025-07-17 14:08 |
412 |
if (ImGui::Button("Remove puzzle")) { |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
413 |
if (!read_only) { |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
414 |
SaveCurrentState(); |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
415 |
EditorRemovePuzzle(this->selected_puzzle); |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
416 |
SavePuzzleStages(); |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
417 |
} |
| 0305b768 |
Poul Sander |
2025-07-17 14:08 |
418 |
} |
| 1873b078 |
Poul Sander |
2025-02-06 22:01 |
419 |
ImGui::End(); |
| 298835a8 |
Poul Sander |
2025-05-31 20:49 |
420 |
|
| 298835a8 |
Poul Sander |
2025-05-31 20:49 |
421 |
ImGui::Begin("Palette"); |
| 52352a94 |
Poul Sander |
2025-06-03 19:04 |
422 |
for (size_t i = 0; i < 7; ++i) { |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
423 |
if (ImGui::Selectable(fmt::format("##{}", i).c_str(), this->selected_action == static_cast<int>(i), 0, ImVec2(0,50))) { |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
424 |
this->selected_action = static_cast<int>(i); |
| 52352a94 |
Poul Sander |
2025-06-03 19:04 |
425 |
} |
| 52352a94 |
Poul Sander |
2025-06-03 19:04 |
426 |
ImGui::SameLine(); |
| 52352a94 |
Poul Sander |
2025-06-03 19:04 |
427 |
sago::SagoSprite& sprite = globalData.bricks[i]; |
| 52352a94 |
Poul Sander |
2025-06-03 19:04 |
428 |
ImGuiWritePartOfTexture(sprite.GetTextureHandler().get(), sprite.GetImageCord().x, sprite.GetImageCord().y, sprite.GetWidth(), sprite.GetHeight(), 50, 50); |
| 298835a8 |
Poul Sander |
2025-05-31 20:49 |
429 |
} |
| 298835a8 |
Poul Sander |
2025-05-31 20:49 |
430 |
if (ImGui::Selectable("Clear", this->selected_action == selection_clear)) { |
| 298835a8 |
Poul Sander |
2025-05-31 20:49 |
431 |
this->selected_action = selection_clear; |
| 298835a8 |
Poul Sander |
2025-05-31 20:49 |
432 |
} |
| 298835a8 |
Poul Sander |
2025-05-31 20:49 |
433 |
if (ImGui::Selectable("Move Up", this->selected_action == selection_move_up)) { |
| 298835a8 |
Poul Sander |
2025-05-31 20:49 |
434 |
this->selected_action = selection_move_up; |
| 298835a8 |
Poul Sander |
2025-05-31 20:49 |
435 |
} |
| 0305b768 |
Poul Sander |
2025-07-17 14:08 |
436 |
/*if (ImGui::Selectable("Move down", this->selected_action == selection_move_down)) { |
| 298835a8 |
Poul Sander |
2025-05-31 20:49 |
437 |
this->selected_action = selection_move_down; |
| 298835a8 |
Poul Sander |
2025-05-31 20:49 |
438 |
} |
| 298835a8 |
Poul Sander |
2025-05-31 20:49 |
439 |
if (ImGui::Selectable("Move left", this->selected_action == selection_move_left)) { |
| 298835a8 |
Poul Sander |
2025-05-31 20:49 |
440 |
this->selected_action = selection_move_left; |
| 298835a8 |
Poul Sander |
2025-05-31 20:49 |
441 |
} |
| 298835a8 |
Poul Sander |
2025-05-31 20:49 |
442 |
if (ImGui::Selectable("Move right", this->selected_action == selection_move_right)) { |
| 298835a8 |
Poul Sander |
2025-05-31 20:49 |
443 |
this->selected_action = selection_move_right; |
| 0305b768 |
Poul Sander |
2025-07-17 14:08 |
444 |
}*/ |
| 298835a8 |
Poul Sander |
2025-05-31 20:49 |
445 |
ImGui::Separator(); |
| 298835a8 |
Poul Sander |
2025-05-31 20:49 |
446 |
ImGui::LabelText("moves allowed", "%i", PuzzleNumberOfMovesAllowed(this->selected_puzzle)); |
| 520e8c44 |
Poul Sander |
2025-06-29 18:16 |
447 |
if (ImGui::Button("+1 move")) { |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
448 |
if (!read_only) { |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
449 |
SaveCurrentState(); |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
450 |
} |
| 520e8c44 |
Poul Sander |
2025-06-29 18:16 |
451 |
PuzzleNumberOfMovesAllowedSet(this->selected_puzzle, PuzzleNumberOfMovesAllowed(this->selected_puzzle)+1); |
| 520e8c44 |
Poul Sander |
2025-06-29 18:16 |
452 |
SavePuzzleStages(); |
| 520e8c44 |
Poul Sander |
2025-06-29 18:16 |
453 |
} |
| 520e8c44 |
Poul Sander |
2025-06-29 18:16 |
454 |
if (ImGui::Button("-1 move")) { |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
455 |
if (!read_only) { |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
456 |
SaveCurrentState(); |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
457 |
} |
| 520e8c44 |
Poul Sander |
2025-06-29 18:16 |
458 |
PuzzleNumberOfMovesAllowedSet(this->selected_puzzle, PuzzleNumberOfMovesAllowed(this->selected_puzzle)-1); |
| 520e8c44 |
Poul Sander |
2025-06-29 18:16 |
459 |
SavePuzzleStages(); |
| 520e8c44 |
Poul Sander |
2025-06-29 18:16 |
460 |
} |
| 298835a8 |
Poul Sander |
2025-05-31 20:49 |
461 |
ImGui::Separator(); |
| 298835a8 |
Poul Sander |
2025-05-31 20:49 |
462 |
if (read_only) { |
| 298835a8 |
Poul Sander |
2025-05-31 20:49 |
463 |
ImGui::LabelText("Read Only", ""); |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
464 |
} else { |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
465 |
bool undo_availible = CanUndo(); |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
466 |
if (!undo_availible) { |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
467 |
ImGui::BeginDisabled(); |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
468 |
} |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
469 |
if (ImGui::Button("Undo (Ctrl+Z)")) { |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
470 |
Undo(); |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
471 |
} |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
472 |
if (!undo_availible) { |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
473 |
ImGui::EndDisabled(); |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
474 |
} |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
475 |
|
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
476 |
ImGui::SameLine(); |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
477 |
bool redo_availeble = CanRedo(); |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
478 |
|
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
479 |
if (!redo_availeble) { |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
480 |
ImGui::BeginDisabled(); |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
481 |
} |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
482 |
if (ImGui::Button("Redo (Ctrl+Y)")) { |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
483 |
Redo(); |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
484 |
} |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
485 |
if (!redo_availeble) { |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
486 |
ImGui::EndDisabled(); |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
487 |
} |
| 298835a8 |
Poul Sander |
2025-05-31 20:49 |
488 |
} |
| 4ebb3d36 |
Poul Sander |
2025-10-05 11:55 |
489 |
ImGui::Separator(); |
| af6d5a44 |
Poul Sander |
2025-06-21 19:31 |
490 |
if (ImGui::Button("Play")) { |
| af6d5a44 |
Poul Sander |
2025-06-21 19:31 |
491 |
SetSinglePuzzleMode(this->selected_puzzle); |
| af6d5a44 |
Poul Sander |
2025-06-21 19:31 |
492 |
runGame(Gametype::Puzzle, this->selected_puzzle); |
| af6d5a44 |
Poul Sander |
2025-06-21 19:31 |
493 |
} |
| 298835a8 |
Poul Sander |
2025-05-31 20:49 |
494 |
ImGui::End(); |
| 1873b078 |
Poul Sander |
2025-02-06 22:01 |
495 |
} |
| 1873b078 |
Poul Sander |
2025-02-06 22:01 |
496 |
|
| 1873b078 |
Poul Sander |
2025-02-06 22:01 |
497 |
void PuzzleEditorState::Update() { |
| 1873b078 |
Poul Sander |
2025-02-06 22:01 |
498 |
} |
| 1873b078 |
Poul Sander |
2025-02-06 22:01 |
499 |
|
|
|
1970-01-01 00:00 |
500 |
|