diff --git a/source/code/puzzle_editor/PuzzleEditorState.cpp b/source/code/puzzle_editor/PuzzleEditorState.cpp index 9e700f3..dab2752 100644 --- a/source/code/puzzle_editor/PuzzleEditorState.cpp +++ b/source/code/puzzle_editor/PuzzleEditorState.cpp @@ -93,6 +93,26 @@ static void DrawBrick(int brick, int x, int y, int width, int height) { ImGuiWritePartOfTexture(sprite.GetTextureHandler().get(), sprite.GetImageCord().x, sprite.GetImageCord().y, sprite.GetWidth(), sprite.GetHeight(), width, height); } + +void PuzzleEditorState::BrickClicked(int x, int y) { + if (read_only) { + return; + } + if (x < 0 || x >= 6) { + return; + } + if (y <0 || y >= 12) { + return; + } + if (selected_action >= 0 && selected_action < 7) { + PuzzleSetBrick(this->selected_puzzle, x, y, this->selected_action); + } + if (selected_action == selection_clear) { + PuzzleSetBrick(this->selected_puzzle, x, y, -1); + } + +} + void PuzzleEditorState::Draw(SDL_Renderer* target) { DrawBackground(target); @@ -154,9 +174,10 @@ void PuzzleEditorState::Draw(SDL_Renderer* target) { //std::cout << "Clicked at: " << pos.x << "," << pos.y << "\n"; //std::cout << "Logical Pos: " << logical_pos_x << "," << logical_pos_y << "\n"; int board_x = logical_pos_x / 50; - int board_y = logical_pos_y / 50; + int board_y = 11-(logical_pos_y / 50); if (board_x >=0 && board_x < 6 && board_y >= 0 && board_y < 12) { std::cout << "Board Pos: " << board_x << "," << board_y << "\n"; + BrickClicked(board_x, board_y); } } diff --git a/source/code/puzzle_editor/PuzzleEditorState.hpp b/source/code/puzzle_editor/PuzzleEditorState.hpp index 50f99fc..142d8ca 100644 --- a/source/code/puzzle_editor/PuzzleEditorState.hpp +++ b/source/code/puzzle_editor/PuzzleEditorState.hpp @@ -52,6 +52,8 @@ public: private: void SelectFile(const std::string& file); + void BrickClicked(int x, int y); + int selected_action = 0; bool isActive = true; diff --git a/source/code/puzzlehandler.cpp b/source/code/puzzlehandler.cpp index fa0252e..afabe66 100644 --- a/source/code/puzzlehandler.cpp +++ b/source/code/puzzlehandler.cpp @@ -56,6 +56,16 @@ int PuzzleGetBrick(size_t level, int x, int y) { return puzzleLevels[level][x][y]; } +void PuzzleSetBrick(size_t level, int x, int y, int brick) { + if (level >= maxNrOfPuzzleStages || x >= 6 || y >= 12 || x < 0 || y < 0) { + return; + } + if (brick >= 7) { + return; + } + puzzleLevels[level][x][y] = brick; +} + int PuzzleGetNumberOfPuzzles() { return nrOfPuzzles; } diff --git a/source/code/puzzlehandler.hpp b/source/code/puzzlehandler.hpp index 573c8fb..707b7f4 100644 --- a/source/code/puzzlehandler.hpp +++ b/source/code/puzzlehandler.hpp @@ -29,6 +29,7 @@ http://www.blockattack.net int PuzzleNumberOfMovesAllowed(size_t level); int PuzzleGetBrick(size_t level, int x, int y); +void PuzzleSetBrick(size_t level, int x, int y, int brick); // used only for editor bool PuzzleIsCleared(size_t level); int LoadPuzzleStages(); int SavePuzzleStages();