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