Skip to content

Commit 298835a

Browse files
committed
Add puzzle editor pallet
1 parent 5cdbc29 commit 298835a

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

source/code/puzzle_editor/PuzzleEditorState.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ Source information and contacts persons can be found at
2222
*/
2323

2424
#include "PuzzleEditorState.hpp"
25+
26+
#include <unistd.h>
27+
2528
#include "imgui.h"
2629
#include "backends/imgui_impl_sdl2.h"
2730
#include "backends/imgui_impl_sdlrenderer2.h"
@@ -50,6 +53,10 @@ void PuzzleEditorState::SelectFile(const std::string& file) {
5053
this->selected_file = file;
5154
PuzzleSetName(file);
5255
LoadPuzzleStages();
56+
read_only = false;
57+
if (file == "puzzle.levels") {
58+
read_only = true;
59+
}
5360
}
5461

5562
static void LogicalToPhysical(const sago::SagoLogicalResize& resize, ImVec2& inout) {
@@ -154,6 +161,37 @@ void PuzzleEditorState::Draw(SDL_Renderer* target) {
154161
}
155162
}
156163
ImGui::End();
164+
165+
ImGui::Begin("Palette");
166+
if (ImGui::Selectable("Red", this->selected_action == 0)) {
167+
this->selected_action = 0;
168+
}
169+
if (ImGui::Selectable("Blue", this->selected_action == 1)) {
170+
this->selected_action = 1;
171+
}
172+
if (ImGui::Selectable("Clear", this->selected_action == selection_clear)) {
173+
this->selected_action = selection_clear;
174+
}
175+
if (ImGui::Selectable("Move Up", this->selected_action == selection_move_up)) {
176+
this->selected_action = selection_move_up;
177+
}
178+
if (ImGui::Selectable("Move down", this->selected_action == selection_move_down)) {
179+
this->selected_action = selection_move_down;
180+
}
181+
if (ImGui::Selectable("Move left", this->selected_action == selection_move_left)) {
182+
this->selected_action = selection_move_left;
183+
}
184+
if (ImGui::Selectable("Move right", this->selected_action == selection_move_right)) {
185+
this->selected_action = selection_move_right;
186+
}
187+
ImGui::Separator();
188+
ImGui::LabelText("moves allowed", "%i", PuzzleNumberOfMovesAllowed(this->selected_puzzle));
189+
ImGui::Separator();
190+
if (read_only) {
191+
ImGui::LabelText("Read Only", "");
192+
ImGui::Separator();
193+
}
194+
ImGui::End();
157195
}
158196

159197
void PuzzleEditorState::Update() {

source/code/puzzle_editor/PuzzleEditorState.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ Source information and contacts persons can be found at
3030
#include <string>
3131
#include <vector>
3232

33+
#define selection_clear 10
34+
#define selection_move_up 11
35+
#define selection_move_down 12
36+
#define selection_move_left 13
37+
#define selection_move_right 14
3338

3439
class PuzzleEditorState : public sago::GameStateInterface {
3540
public:
@@ -47,7 +52,10 @@ class PuzzleEditorState : public sago::GameStateInterface {
4752
private:
4853
void SelectFile(const std::string& file);
4954

55+
int selected_action = 0;
56+
5057
bool isActive = true;
58+
bool read_only = true;
5159
int selected_puzzle = -1;
5260
std::string selected_file;
5361
std::vector<std::string> puzzle_files;

source/code/puzzlehandler.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ static int puzzleLevels[maxNrOfPuzzleStages][6][12]; //Contains board layout;
4343
static int nrOfPuzzles; //How many are there actually?
4444

4545
int PuzzleNumberOfMovesAllowed(int level) {
46+
if (level < 0 || level >= nrOfMovesAllowed.size()) {
47+
return -1;
48+
}
4649
return nrOfMovesAllowed.at(level);
4750
}
4851

0 commit comments

Comments
 (0)