git repos / blockattack-game

blame: source/code/puzzle_editor/PuzzleEditorState.cpp

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
#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
636cde3b Poul Sander 2025-05-15 21:40 37
PuzzleEditorState::PuzzleEditorState() {
636cde3b Poul Sander 2025-05-15 21:40 38
	this->window_resize = sago::SagoLogicalResize(BOARD_WIDTH+5, BOARD_HEIGHT+5);
636cde3b Poul Sander 2025-05-15 21:40 39
}
636cde3b Poul Sander 2025-05-15 21:40 40
1873b078 Poul Sander 2025-02-06 22:01 41
bool PuzzleEditorState::IsActive() {
1873b078 Poul Sander 2025-02-06 22:01 42
	return isActive;
1873b078 Poul Sander 2025-02-06 22:01 43
}
1873b078 Poul Sander 2025-02-06 22:01 44
1873b078 Poul Sander 2025-02-06 22:01 45
void PuzzleEditorState::ProcessInput(const SDL_Event& event, bool& processed) {
1873b078 Poul Sander 2025-02-06 22:01 46
	ImGui_ImplSDL2_ProcessEvent(&event);
1873b078 Poul Sander 2025-02-06 22:01 47
}
1873b078 Poul Sander 2025-02-06 22:01 48
a80f6a78 Poul Sander 2025-04-04 18:34 49
void PuzzleEditorState::Init() {
a80f6a78 Poul Sander 2025-04-04 18:34 50
	this->selected_file = "";
a80f6a78 Poul Sander 2025-04-04 18:34 51
	this->puzzle_files = sago::GetFileList("puzzles");
a80f6a78 Poul Sander 2025-04-04 18:34 52
}
a80f6a78 Poul Sander 2025-04-04 18:34 53
a80f6a78 Poul Sander 2025-04-04 18:34 54
void PuzzleEditorState::SelectFile(const std::string& file) {
a80f6a78 Poul Sander 2025-04-04 18:34 55
	this->selected_file = file;
a80f6a78 Poul Sander 2025-04-04 18:34 56
	PuzzleSetName(file);
a80f6a78 Poul Sander 2025-04-04 18:34 57
	LoadPuzzleStages();
298835a8 Poul Sander 2025-05-31 20:49 58
	read_only = false;
298835a8 Poul Sander 2025-05-31 20:49 59
	if (file == "puzzle.levels") {
298835a8 Poul Sander 2025-05-31 20:49 60
		read_only = true;
298835a8 Poul Sander 2025-05-31 20:49 61
	}
a80f6a78 Poul Sander 2025-04-04 18:34 62
}
a80f6a78 Poul Sander 2025-04-04 18:34 63
636cde3b Poul Sander 2025-05-15 21:40 64
static void LogicalToPhysical(const sago::SagoLogicalResize& resize, ImVec2& inout) {
636cde3b Poul Sander 2025-05-15 21:40 65
	int inx = inout.x;
636cde3b Poul Sander 2025-05-15 21:40 66
	int iny = inout.y;
636cde3b Poul Sander 2025-05-15 21:40 67
	int outx = inout.x;
636cde3b Poul Sander 2025-05-15 21:40 68
	int outy = inout.y;
636cde3b Poul Sander 2025-05-15 21:40 69
	resize.LogicalToPhysical(inx, iny, outx, outy);
636cde3b Poul Sander 2025-05-15 21:40 70
	inout.x = outx;
636cde3b Poul Sander 2025-05-15 21:40 71
	inout.y = outy;
636cde3b Poul Sander 2025-05-15 21:40 72
}
636cde3b Poul Sander 2025-05-15 21:40 73
59365d69 Poul Sander 2025-05-25 12:06 74
e1a54754 Poul Sander 2025-05-25 13:31 75
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 76
	float sprite_w = tex_w;
e1a54754 Poul Sander 2025-05-25 13:31 77
	float sprite_h = tex_h;
59365d69 Poul Sander 2025-05-25 12:06 78
	float topxf = topx;
59365d69 Poul Sander 2025-05-25 12:06 79
	float topyf = topy;
59365d69 Poul Sander 2025-05-25 12:06 80
	ImVec2 uv0 = ImVec2(topxf / tex_w, topyf / tex_h);
59365d69 Poul Sander 2025-05-25 12:06 81
	ImVec2 uv1 = ImVec2((topxf + sprite_w) / tex_w, (topyf + sprite_h) / tex_h);
59365d69 Poul Sander 2025-05-25 12:06 82
	ImGui::Image((ImTextureID)(intptr_t)texture, ImVec2((float)w, (float)h), uv0, uv1);
59365d69 Poul Sander 2025-05-25 12:06 83
}
59365d69 Poul Sander 2025-05-25 12:06 84
59365d69 Poul Sander 2025-05-25 12:06 85
59365d69 Poul Sander 2025-05-25 12:06 86
static void DrawBrick(int brick, int x, int y, int width, int height) {
59365d69 Poul Sander 2025-05-25 12:06 87
	if (brick < 0 || brick > 6) {
59365d69 Poul Sander 2025-05-25 12:06 88
		return;
59365d69 Poul Sander 2025-05-25 12:06 89
	}
59365d69 Poul Sander 2025-05-25 12:06 90
59365d69 Poul Sander 2025-05-25 12:06 91
	sago::SagoSprite& sprite = globalData.bricks[brick];
59365d69 Poul Sander 2025-05-25 12:06 92
	ImGui::SetCursorScreenPos({ static_cast<float>(x), static_cast<float>(y) });
1ae9f202 Poul Sander 2025-05-30 13:59 93
	ImGuiWritePartOfTexture(sprite.GetTextureHandler().get(), sprite.GetImageCord().x, sprite.GetImageCord().y, sprite.GetWidth(), sprite.GetHeight(), width, height);
59365d69 Poul Sander 2025-05-25 12:06 94
}
59365d69 Poul Sander 2025-05-25 12:06 95
72e87270 Poul Sander 2025-06-21 15:22 96
/**
72e87270 Poul Sander 2025-06-21 15:22 97
 * 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 98
 * If bricks are pushed out of the board then the disappear.
72e87270 Poul Sander 2025-06-21 15:22 99
 * @param level The level to edit
72e87270 Poul Sander 2025-06-21 15:22 100
 * @param x
72e87270 Poul Sander 2025-06-21 15:22 101
 * @param y
72e87270 Poul Sander 2025-06-21 15:22 102
 */
72e87270 Poul Sander 2025-06-21 15:22 103
static void BricksMoveUp(int level, int x, int y) {
72e87270 Poul Sander 2025-06-21 15:22 104
	for (int i = 11; i > y; i--) {
72e87270 Poul Sander 2025-06-21 15:22 105
		PuzzleSetBrick(level, x, i, PuzzleGetBrick(level, x, i-1));
72e87270 Poul Sander 2025-06-21 15:22 106
	}
72e87270 Poul Sander 2025-06-21 15:22 107
	PuzzleSetBrick(level, x, y, -1);  //Clear the space we started
72e87270 Poul Sander 2025-06-21 15:22 108
}
72e87270 Poul Sander 2025-06-21 15:22 109
72e87270 Poul Sander 2025-06-21 15:22 110
static void BricksMoveDown(int level, int x, int y) {
72e87270 Poul Sander 2025-06-21 15:22 111
	for (int i = 0; i < y; i++) {
72e87270 Poul Sander 2025-06-21 15:22 112
		PuzzleSetBrick(level, x, i, PuzzleGetBrick(level, x, i+1));
72e87270 Poul Sander 2025-06-21 15:22 113
	}
72e87270 Poul Sander 2025-06-21 15:22 114
	PuzzleSetBrick(level, x, y, -1);  //Clear the space we started
72e87270 Poul Sander 2025-06-21 15:22 115
}
72e87270 Poul Sander 2025-06-21 15:22 116
72e87270 Poul Sander 2025-06-21 15:22 117
static void BricksMoveColumnLeft(int level, int x) {
72e87270 Poul Sander 2025-06-21 15:22 118
	for (int i=0; i < x; i++) {
72e87270 Poul Sander 2025-06-21 15:22 119
		for (int j=0; j<12 ; j++) {
72e87270 Poul Sander 2025-06-21 15:22 120
			PuzzleSetBrick(level, i, j, PuzzleGetBrick(level, i+1, j));
72e87270 Poul Sander 2025-06-21 15:22 121
		}
72e87270 Poul Sander 2025-06-21 15:22 122
	}
72e87270 Poul Sander 2025-06-21 15:22 123
	for (int j=0; j<12 ; j++) {
72e87270 Poul Sander 2025-06-21 15:22 124
		PuzzleSetBrick(level, x, j, -1);
72e87270 Poul Sander 2025-06-21 15:22 125
	}
72e87270 Poul Sander 2025-06-21 15:22 126
}
72e87270 Poul Sander 2025-06-21 15:22 127
72e87270 Poul Sander 2025-06-21 15:22 128
static void BricksMoveColumnRight(int level, int x) {
72e87270 Poul Sander 2025-06-21 15:22 129
	for (int i=5; i > x; i--) {
72e87270 Poul Sander 2025-06-21 15:22 130
		for (int j=0; j<12 ; j++) {
72e87270 Poul Sander 2025-06-21 15:22 131
			PuzzleSetBrick(level, i, j, PuzzleGetBrick(level, i-1, j));
72e87270 Poul Sander 2025-06-21 15:22 132
		}
72e87270 Poul Sander 2025-06-21 15:22 133
	}
72e87270 Poul Sander 2025-06-21 15:22 134
	for (int j=0; j<12 ; j++) {
72e87270 Poul Sander 2025-06-21 15:22 135
		PuzzleSetBrick(level, x, j, -1);
72e87270 Poul Sander 2025-06-21 15:22 136
	}
72e87270 Poul Sander 2025-06-21 15:22 137
}
72e87270 Poul Sander 2025-06-21 15:22 138
b8a4e6f1 Poul Sander 2025-06-21 10:31 139
b8a4e6f1 Poul Sander 2025-06-21 10:31 140
void PuzzleEditorState::BrickClicked(int x, int y) {
b8a4e6f1 Poul Sander 2025-06-21 10:31 141
	if (read_only) {
b8a4e6f1 Poul Sander 2025-06-21 10:31 142
		return;
b8a4e6f1 Poul Sander 2025-06-21 10:31 143
	}
b8a4e6f1 Poul Sander 2025-06-21 10:31 144
	if (x < 0 || x >= 6) {
b8a4e6f1 Poul Sander 2025-06-21 10:31 145
		return;
b8a4e6f1 Poul Sander 2025-06-21 10:31 146
	}
b8a4e6f1 Poul Sander 2025-06-21 10:31 147
	if (y <0 || y >= 12) {
b8a4e6f1 Poul Sander 2025-06-21 10:31 148
		return;
b8a4e6f1 Poul Sander 2025-06-21 10:31 149
	}
b8a4e6f1 Poul Sander 2025-06-21 10:31 150
	if (selected_action >= 0 && selected_action < 7) {
b8a4e6f1 Poul Sander 2025-06-21 10:31 151
		PuzzleSetBrick(this->selected_puzzle, x, y, this->selected_action);
72e87270 Poul Sander 2025-06-21 15:22 152
		SavePuzzleStages();
b8a4e6f1 Poul Sander 2025-06-21 10:31 153
	}
b8a4e6f1 Poul Sander 2025-06-21 10:31 154
	if (selected_action == selection_clear) {
b8a4e6f1 Poul Sander 2025-06-21 10:31 155
		PuzzleSetBrick(this->selected_puzzle, x, y, -1);
72e87270 Poul Sander 2025-06-21 15:22 156
		SavePuzzleStages();
72e87270 Poul Sander 2025-06-21 15:22 157
	}
72e87270 Poul Sander 2025-06-21 15:22 158
	if (selected_action == selection_move_up) {
72e87270 Poul Sander 2025-06-21 15:22 159
		BricksMoveUp(this->selected_puzzle, x, y);
72e87270 Poul Sander 2025-06-21 15:22 160
		SavePuzzleStages();
72e87270 Poul Sander 2025-06-21 15:22 161
	}
72e87270 Poul Sander 2025-06-21 15:22 162
	if (selected_action == selection_move_down) {
72e87270 Poul Sander 2025-06-21 15:22 163
		BricksMoveDown(this->selected_puzzle, x, y);
72e87270 Poul Sander 2025-06-21 15:22 164
		SavePuzzleStages();
72e87270 Poul Sander 2025-06-21 15:22 165
	}
72e87270 Poul Sander 2025-06-21 15:22 166
	if (selected_action == selection_move_left) {
72e87270 Poul Sander 2025-06-21 15:22 167
		BricksMoveColumnLeft(this->selected_puzzle, x);
72e87270 Poul Sander 2025-06-21 15:22 168
		SavePuzzleStages();
72e87270 Poul Sander 2025-06-21 15:22 169
	}
72e87270 Poul Sander 2025-06-21 15:22 170
	if (selected_action == selection_move_right) {
72e87270 Poul Sander 2025-06-21 15:22 171
		BricksMoveColumnRight(this->selected_puzzle, x);
72e87270 Poul Sander 2025-06-21 15:22 172
		SavePuzzleStages();
b8a4e6f1 Poul Sander 2025-06-21 10:31 173
	}
b8a4e6f1 Poul Sander 2025-06-21 10:31 174
b8a4e6f1 Poul Sander 2025-06-21 10:31 175
}
b8a4e6f1 Poul Sander 2025-06-21 10:31 176
1873b078 Poul Sander 2025-02-06 22:01 177
void PuzzleEditorState::Draw(SDL_Renderer* target) {
6046ca3f Poul Sander 2025-04-06 16:14 178
	DrawBackground(target);
1fcc8881 Poul Sander 2025-05-15 18:54 179
1fcc8881 Poul Sander 2025-05-15 18:54 180
	ImGui::Begin("Board area");
1fcc8881 Poul Sander 2025-05-15 18:54 181
	ImGui::BeginChild("Test");
1fcc8881 Poul Sander 2025-05-15 18:54 182
	ImVec2 p = ImGui::GetCursorScreenPos();
636cde3b Poul Sander 2025-05-15 21:40 183
	ImVec2 size = ImGui::GetContentRegionAvail();
636cde3b Poul Sander 2025-05-15 21:40 184
	int xoffset = p.x;
636cde3b Poul Sander 2025-05-15 21:40 185
	int yoffset = p.y;
636cde3b Poul Sander 2025-05-15 21:40 186
	int height = BOARD_HEIGHT;
636cde3b Poul Sander 2025-05-15 21:40 187
	int width = BOARD_WIDTH;
636cde3b Poul Sander 2025-05-15 21:40 188
	window_resize.SetPhysicalSize(size.x, size.y);
636cde3b Poul Sander 2025-05-15 21:40 189
636cde3b Poul Sander 2025-05-15 21:40 190
59365d69 Poul Sander 2025-05-25 12:06 191
	int brick_size = 50;
59365d69 Poul Sander 2025-05-25 12:06 192
	window_resize.LogicalToPhysical(&brick_size, nullptr);
e1a54754 Poul Sander 2025-05-25 13:31 193
	brick_size -= window_resize.GetLeftMargin();
59365d69 Poul Sander 2025-05-25 12:06 194
	for (int i=0; i < 6; ++i) {
59365d69 Poul Sander 2025-05-25 12:06 195
		for (int j=0; j < 12; ++j) {
59365d69 Poul Sander 2025-05-25 12:06 196
			ImVec2 p1(i*50.0f, (11-j)*50.0f);
59365d69 Poul Sander 2025-05-25 12:06 197
			LogicalToPhysical(window_resize, p1);
59365d69 Poul Sander 2025-05-25 12:06 198
			p1.x += xoffset;
59365d69 Poul Sander 2025-05-25 12:06 199
			p1.y += yoffset;
59365d69 Poul Sander 2025-05-25 12:06 200
			int brick = PuzzleGetBrick(this->selected_puzzle, i, j);
59365d69 Poul Sander 2025-05-25 12:06 201
			DrawBrick(brick, static_cast<int>(p1.x), static_cast<int>(p1.y), brick_size, brick_size);
59365d69 Poul Sander 2025-05-25 12:06 202
		}
59365d69 Poul Sander 2025-05-25 12:06 203
	}
59365d69 Poul Sander 2025-05-25 12:06 204
1fcc8881 Poul Sander 2025-05-15 18:54 205
	for (int i=0; i <= 6;++i) {
636cde3b Poul Sander 2025-05-15 21:40 206
		ImVec2 p1(i*50.0f, 0);
636cde3b Poul Sander 2025-05-15 21:40 207
		ImVec2 p2(i*50.0f, height);
636cde3b Poul Sander 2025-05-15 21:40 208
		LogicalToPhysical(window_resize, p1);
636cde3b Poul Sander 2025-05-15 21:40 209
		LogicalToPhysical(window_resize, p2);
636cde3b Poul Sander 2025-05-15 21:40 210
		p1.x += xoffset;
636cde3b Poul Sander 2025-05-15 21:40 211
		p1.y += yoffset;
636cde3b Poul Sander 2025-05-15 21:40 212
		p2.x += xoffset;
636cde3b Poul Sander 2025-05-15 21:40 213
		p2.y += yoffset;
636cde3b Poul Sander 2025-05-15 21:40 214
		ImGui::GetWindowDrawList()->AddLine(p1, p2, IM_COL32(255, 0, 0, 100));
1fcc8881 Poul Sander 2025-05-15 18:54 215
	}
1fcc8881 Poul Sander 2025-05-15 18:54 216
	for (int i=0; i <= 12;++i) {
636cde3b Poul Sander 2025-05-15 21:40 217
		ImVec2 p1(0,i*50.0f);
636cde3b Poul Sander 2025-05-15 21:40 218
		ImVec2 p2(width, i*50.0f);
636cde3b Poul Sander 2025-05-15 21:40 219
		LogicalToPhysical(window_resize, p1);
636cde3b Poul Sander 2025-05-15 21:40 220
		LogicalToPhysical(window_resize, p2);
636cde3b Poul Sander 2025-05-15 21:40 221
		p1.x += xoffset;
636cde3b Poul Sander 2025-05-15 21:40 222
		p1.y += yoffset;
636cde3b Poul Sander 2025-05-15 21:40 223
		p2.x += xoffset;
636cde3b Poul Sander 2025-05-15 21:40 224
		p2.y += yoffset;
636cde3b Poul Sander 2025-05-15 21:40 225
		ImGui::GetWindowDrawList()->AddLine(p1, p2, IM_COL32(255, 0, 0, 100));
6046ca3f Poul Sander 2025-04-06 16:14 226
	}
37278577 Poul Sander 2025-06-21 07:50 227
	ImGuiIO& io = ImGui::GetIO();
37278577 Poul Sander 2025-06-21 07:50 228
	if (ImGui::IsMouseReleased(0) && io.MouseDownDurationPrev[0] < 0.3f && !ImGui::IsMouseDragPastThreshold(0)) {
37278577 Poul Sander 2025-06-21 07:50 229
		ImVec2 pos = io.MousePos;
37278577 Poul Sander 2025-06-21 07:50 230
		pos.x -= xoffset;
37278577 Poul Sander 2025-06-21 07:50 231
		pos.y -= yoffset;
37278577 Poul Sander 2025-06-21 07:50 232
		int logical_pos_x = 0;
37278577 Poul Sander 2025-06-21 07:50 233
		int logical_pos_y = 0;
37278577 Poul Sander 2025-06-21 07:50 234
		window_resize.PhysicalToLogical(pos.x, pos.y, logical_pos_x, logical_pos_y);
37278577 Poul Sander 2025-06-21 07:50 235
		//std::cout << "Clicked at: " << pos.x << "," << pos.y << "\n";
37278577 Poul Sander 2025-06-21 07:50 236
		//std::cout << "Logical Pos: " << logical_pos_x << "," << logical_pos_y << "\n";
37278577 Poul Sander 2025-06-21 07:50 237
		int board_x = logical_pos_x / 50;
b8a4e6f1 Poul Sander 2025-06-21 10:31 238
		int board_y = 11-(logical_pos_y / 50);
37278577 Poul Sander 2025-06-21 07:50 239
		if (board_x >=0 && board_x < 6 && board_y >= 0 && board_y < 12) {
37278577 Poul Sander 2025-06-21 07:50 240
			std::cout << "Board Pos: " << board_x << "," << board_y << "\n";
b8a4e6f1 Poul Sander 2025-06-21 10:31 241
			BrickClicked(board_x, board_y);
37278577 Poul Sander 2025-06-21 07:50 242
		}
37278577 Poul Sander 2025-06-21 07:50 243
37278577 Poul Sander 2025-06-21 07:50 244
	}
1fcc8881 Poul Sander 2025-05-15 18:54 245
	ImGui::EndChild();
1fcc8881 Poul Sander 2025-05-15 18:54 246
	ImGui::End();
1fcc8881 Poul Sander 2025-05-15 18:54 247
1873b078 Poul Sander 2025-02-06 22:01 248
	ImGui::Begin("File list", nullptr, ImGuiWindowFlags_NoCollapse);
a80f6a78 Poul Sander 2025-04-04 18:34 249
	for (const auto& file : this->puzzle_files) {
a80f6a78 Poul Sander 2025-04-04 18:34 250
		if (ImGui::Selectable(file.c_str(), this->selected_file == file)) {
a80f6a78 Poul Sander 2025-04-04 18:34 251
			SelectFile(file);
a80f6a78 Poul Sander 2025-04-04 18:34 252
		}
1873b078 Poul Sander 2025-02-06 22:01 253
	}
1873b078 Poul Sander 2025-02-06 22:01 254
a80f6a78 Poul Sander 2025-04-04 18:34 255
a80f6a78 Poul Sander 2025-04-04 18:34 256
	ImGui::End();
a80f6a78 Poul Sander 2025-04-04 18:34 257
	ImGui::Begin("Puzzles in file");
a80f6a78 Poul Sander 2025-04-04 18:34 258
	int puzzle_count = PuzzleGetNumberOfPuzzles();
a80f6a78 Poul Sander 2025-04-04 18:34 259
	for (int i = 0; i < puzzle_count; ++i) {
6046ca3f Poul Sander 2025-04-06 16:14 260
		if (ImGui::Selectable(std::to_string(i).c_str(), this->selected_puzzle == i)) {
6046ca3f Poul Sander 2025-04-06 16:14 261
			this->selected_puzzle = i;
a80f6a78 Poul Sander 2025-04-04 18:34 262
		}
a80f6a78 Poul Sander 2025-04-04 18:34 263
	}
1873b078 Poul Sander 2025-02-06 22:01 264
	ImGui::End();
298835a8 Poul Sander 2025-05-31 20:49 265
298835a8 Poul Sander 2025-05-31 20:49 266
	ImGui::Begin("Palette");
52352a94 Poul Sander 2025-06-03 19:04 267
	for (size_t i = 0; i < 7; ++i) {
52352a94 Poul Sander 2025-06-03 19:04 268
		if (ImGui::Selectable(fmt::format("##{}", i).c_str(), this->selected_action == i, 0, ImVec2(0,50))) {
52352a94 Poul Sander 2025-06-03 19:04 269
			this->selected_action = i;
52352a94 Poul Sander 2025-06-03 19:04 270
		}
52352a94 Poul Sander 2025-06-03 19:04 271
		ImGui::SameLine();
52352a94 Poul Sander 2025-06-03 19:04 272
		sago::SagoSprite& sprite = globalData.bricks[i];
52352a94 Poul Sander 2025-06-03 19:04 273
		ImGuiWritePartOfTexture(sprite.GetTextureHandler().get(), sprite.GetImageCord().x, sprite.GetImageCord().y, sprite.GetWidth(), sprite.GetHeight(), 50, 50);
298835a8 Poul Sander 2025-05-31 20:49 274
	}
298835a8 Poul Sander 2025-05-31 20:49 275
	if (ImGui::Selectable("Clear", this->selected_action == selection_clear)) {
298835a8 Poul Sander 2025-05-31 20:49 276
		this->selected_action = selection_clear;
298835a8 Poul Sander 2025-05-31 20:49 277
	}
298835a8 Poul Sander 2025-05-31 20:49 278
	if (ImGui::Selectable("Move Up", this->selected_action == selection_move_up)) {
298835a8 Poul Sander 2025-05-31 20:49 279
		this->selected_action = selection_move_up;
298835a8 Poul Sander 2025-05-31 20:49 280
	}
298835a8 Poul Sander 2025-05-31 20:49 281
	if (ImGui::Selectable("Move down", this->selected_action == selection_move_down)) {
298835a8 Poul Sander 2025-05-31 20:49 282
		this->selected_action = selection_move_down;
298835a8 Poul Sander 2025-05-31 20:49 283
	}
298835a8 Poul Sander 2025-05-31 20:49 284
	if (ImGui::Selectable("Move left", this->selected_action == selection_move_left)) {
298835a8 Poul Sander 2025-05-31 20:49 285
		this->selected_action = selection_move_left;
298835a8 Poul Sander 2025-05-31 20:49 286
	}
298835a8 Poul Sander 2025-05-31 20:49 287
	if (ImGui::Selectable("Move right", this->selected_action == selection_move_right)) {
298835a8 Poul Sander 2025-05-31 20:49 288
		this->selected_action = selection_move_right;
298835a8 Poul Sander 2025-05-31 20:49 289
	}
298835a8 Poul Sander 2025-05-31 20:49 290
	ImGui::Separator();
298835a8 Poul Sander 2025-05-31 20:49 291
	ImGui::LabelText("moves allowed", "%i", PuzzleNumberOfMovesAllowed(this->selected_puzzle));
298835a8 Poul Sander 2025-05-31 20:49 292
	ImGui::Separator();
298835a8 Poul Sander 2025-05-31 20:49 293
	if (read_only) {
298835a8 Poul Sander 2025-05-31 20:49 294
		ImGui::LabelText("Read Only", "");
298835a8 Poul Sander 2025-05-31 20:49 295
		ImGui::Separator();
298835a8 Poul Sander 2025-05-31 20:49 296
	}
298835a8 Poul Sander 2025-05-31 20:49 297
	ImGui::End();
1873b078 Poul Sander 2025-02-06 22:01 298
}
1873b078 Poul Sander 2025-02-06 22:01 299
1873b078 Poul Sander 2025-02-06 22:01 300
void PuzzleEditorState::Update() {
1873b078 Poul Sander 2025-02-06 22:01 301
}
1873b078 Poul Sander 2025-02-06 22:01 302
1970-01-01 00:00 303