commit 298835a8
Add puzzle editor pallet
Changed files
| M | source/code/puzzle_editor/PuzzleEditorState.cpp before |
| M | source/code/puzzle_editor/PuzzleEditorState.hpp before |
| M | source/code/puzzlehandler.cpp before |
diff --git a/source/code/puzzle_editor/PuzzleEditorState.cpp b/source/code/puzzle_editor/PuzzleEditorState.cpp
index 06456cd..9d393df 100644
--- a/source/code/puzzle_editor/PuzzleEditorState.cpp
+++ b/source/code/puzzle_editor/PuzzleEditorState.cpp
@@ -22,6 +22,9 @@ https://blockattack.net
*/
#include "PuzzleEditorState.hpp"
+
+#include <unistd.h>
+
#include "imgui.h"
#include "backends/imgui_impl_sdl2.h"
#include "backends/imgui_impl_sdlrenderer2.h"
@@ -50,6 +53,10 @@ void PuzzleEditorState::SelectFile(const std::string& file) {
this->selected_file = file;
PuzzleSetName(file);
LoadPuzzleStages();
+ read_only = false;
+ if (file == "puzzle.levels") {
+ read_only = true;
+ }
}
static void LogicalToPhysical(const sago::SagoLogicalResize& resize, ImVec2& inout) {
@@ -154,6 +161,37 @@ void PuzzleEditorState::Draw(SDL_Renderer* target) {
}
}
ImGui::End();
+
+ ImGui::Begin("Palette");
+ if (ImGui::Selectable("Red", this->selected_action == 0)) {
+ this->selected_action = 0;
+ }
+ if (ImGui::Selectable("Blue", this->selected_action == 1)) {
+ this->selected_action = 1;
+ }
+ if (ImGui::Selectable("Clear", this->selected_action == selection_clear)) {
+ this->selected_action = selection_clear;
+ }
+ if (ImGui::Selectable("Move Up", this->selected_action == selection_move_up)) {
+ this->selected_action = selection_move_up;
+ }
+ if (ImGui::Selectable("Move down", this->selected_action == selection_move_down)) {
+ this->selected_action = selection_move_down;
+ }
+ if (ImGui::Selectable("Move left", this->selected_action == selection_move_left)) {
+ this->selected_action = selection_move_left;
+ }
+ if (ImGui::Selectable("Move right", this->selected_action == selection_move_right)) {
+ this->selected_action = selection_move_right;
+ }
+ ImGui::Separator();
+ ImGui::LabelText("moves allowed", "%i", PuzzleNumberOfMovesAllowed(this->selected_puzzle));
+ ImGui::Separator();
+ if (read_only) {
+ ImGui::LabelText("Read Only", "");
+ ImGui::Separator();
+ }
+ ImGui::End();
}
void PuzzleEditorState::Update() {
diff --git a/source/code/puzzle_editor/PuzzleEditorState.hpp b/source/code/puzzle_editor/PuzzleEditorState.hpp
index 967350d..50f99fc 100644
--- a/source/code/puzzle_editor/PuzzleEditorState.hpp
+++ b/source/code/puzzle_editor/PuzzleEditorState.hpp
@@ -30,6 +30,11 @@ https://blockattack.net
#include <string>
#include <vector>
+#define selection_clear 10
+#define selection_move_up 11
+#define selection_move_down 12
+#define selection_move_left 13
+#define selection_move_right 14
class PuzzleEditorState : public sago::GameStateInterface {
public:
@@ -47,7 +52,10 @@ public:
private:
void SelectFile(const std::string& file);
+ int selected_action = 0;
+
bool isActive = true;
+ bool read_only = true;
int selected_puzzle = -1;
std::string selected_file;
std::vector<std::string> puzzle_files;
diff --git a/source/code/puzzlehandler.cpp b/source/code/puzzlehandler.cpp
index d17f1bf..dd2e64a 100644
--- a/source/code/puzzlehandler.cpp
+++ b/source/code/puzzlehandler.cpp
@@ -43,6 +43,9 @@ static int puzzleLevels[maxNrOfPuzzleStages][6][12]; //Contains board layout;
static int nrOfPuzzles; //How many are there actually?
int PuzzleNumberOfMovesAllowed(int level) {
+ if (level < 0 || level >= nrOfMovesAllowed.size()) {
+ return -1;
+ }
return nrOfMovesAllowed.at(level);
}