@@ -93,6 +93,49 @@ static void DrawBrick(int brick, int x, int y, int width, int height) {
9393 ImGuiWritePartOfTexture (sprite.GetTextureHandler ().get (), sprite.GetImageCord ().x , sprite.GetImageCord ().y , sprite.GetWidth (), sprite.GetHeight (), width, height);
9494}
9595
96+ /* *
97+ * Takes the brick pointed to and moves up all bricks above it to leave an empty space.
98+ * If bricks are pushed out of the board then the disappear.
99+ * @param level The level to edit
100+ * @param x
101+ * @param y
102+ */
103+ static void BricksMoveUp (int level, int x, int y) {
104+ for (int i = 11 ; i > y; i--) {
105+ PuzzleSetBrick (level, x, i, PuzzleGetBrick (level, x, i-1 ));
106+ }
107+ PuzzleSetBrick (level, x, y, -1 ); // Clear the space we started
108+ }
109+
110+ static void BricksMoveDown (int level, int x, int y) {
111+ for (int i = 0 ; i < y; i++) {
112+ PuzzleSetBrick (level, x, i, PuzzleGetBrick (level, x, i+1 ));
113+ }
114+ PuzzleSetBrick (level, x, y, -1 ); // Clear the space we started
115+ }
116+
117+ static void BricksMoveColumnLeft (int level, int x) {
118+ for (int i=0 ; i < x; i++) {
119+ for (int j=0 ; j<12 ; j++) {
120+ PuzzleSetBrick (level, i, j, PuzzleGetBrick (level, i+1 , j));
121+ }
122+ }
123+ for (int j=0 ; j<12 ; j++) {
124+ PuzzleSetBrick (level, x, j, -1 );
125+ }
126+ }
127+
128+ static void BricksMoveColumnRight (int level, int x) {
129+ for (int i=5 ; i > x; i--) {
130+ for (int j=0 ; j<12 ; j++) {
131+ PuzzleSetBrick (level, i, j, PuzzleGetBrick (level, i-1 , j));
132+ }
133+ }
134+ for (int j=0 ; j<12 ; j++) {
135+ PuzzleSetBrick (level, x, j, -1 );
136+ }
137+ }
138+
96139
97140void PuzzleEditorState::BrickClicked (int x, int y) {
98141 if (read_only) {
@@ -106,9 +149,27 @@ void PuzzleEditorState::BrickClicked(int x, int y) {
106149 }
107150 if (selected_action >= 0 && selected_action < 7 ) {
108151 PuzzleSetBrick (this ->selected_puzzle , x, y, this ->selected_action );
152+ SavePuzzleStages ();
109153 }
110154 if (selected_action == selection_clear) {
111155 PuzzleSetBrick (this ->selected_puzzle , x, y, -1 );
156+ SavePuzzleStages ();
157+ }
158+ if (selected_action == selection_move_up) {
159+ BricksMoveUp (this ->selected_puzzle , x, y);
160+ SavePuzzleStages ();
161+ }
162+ if (selected_action == selection_move_down) {
163+ BricksMoveDown (this ->selected_puzzle , x, y);
164+ SavePuzzleStages ();
165+ }
166+ if (selected_action == selection_move_left) {
167+ BricksMoveColumnLeft (this ->selected_puzzle , x);
168+ SavePuzzleStages ();
169+ }
170+ if (selected_action == selection_move_right) {
171+ BricksMoveColumnRight (this ->selected_puzzle , x);
172+ SavePuzzleStages ();
112173 }
113174
114175}
0 commit comments