[FEAT] Added support to scroll tile by tile

This commit is contained in:
2021-05-12 17:42:30 +02:00
parent f49f501306
commit 562c5ebc32

View File

@@ -483,9 +483,22 @@ void DoTileMap() {
if (keyJustPressed == SDL_SCANCODE_F) { Undo_Op(); FloodFill(); } if (keyJustPressed == SDL_SCANCODE_F) { Undo_Op(); FloodFill(); }
if (keyJustPressed == SDL_SCANCODE_R) { Undo_Op(); ReplaceTile(); } if (keyJustPressed == SDL_SCANCODE_R) { Undo_Op(); ReplaceTile(); }
static int scroll_x = 0;
static int scroll_y = 0;
static int old_map_x = 0;
static int old_map_y = 0;
if (mouse.mouse_down[MOUSE_BUTTON_LEFT] || mouse.mouse_down[MOUSE_BUTTON_RIGHT]) { Undo_Op(); } if (mouse.mouse_down[MOUSE_BUTTON_LEFT] || mouse.mouse_down[MOUSE_BUTTON_RIGHT]) { Undo_Op(); }
if (mouse.mouse_down[MOUSE_BUTTON_LEFT]) {
old_map_x = map_x; old_map_y = map_y;
scroll_x = cur_x; scroll_y = cur_y;
}
if (mouse.buttons[MOUSE_BUTTON_RIGHT]) { if (tile_back < sprites) map[(map_x + cur_x) + (map_y + cur_y)*map_width] = tile_back; } if (mouse.buttons[MOUSE_BUTTON_RIGHT]) { if (tile_back < sprites) map[(map_x + cur_x) + (map_y + cur_y)*map_width] = tile_back; }
if (mouse.buttons[MOUSE_BUTTON_LEFT]) { if (mouse.buttons[MOUSE_BUTTON_LEFT]) {
if (keyboard[SDL_SCANCODE_SPACE]) {
map_x = old_map_x - (cur_x - scroll_x);
map_y = old_map_y - (cur_y - scroll_y);
} else {
const int pos = (map_x + cur_x) + (map_y + cur_y)*map_width; const int pos = (map_x + cur_x) + (map_y + cur_y)*map_width;
if (tile_sel >= sprites) { if (tile_sel >= sprites) {
ignoreMouse = true; ignoreMouse = true;
@@ -498,6 +511,7 @@ void DoTileMap() {
map[pos] = tile_sel; map[pos] = tile_sel;
} }
} }
}
if (mouse.buttons[MOUSE_BUTTON_MIDDLE]) { tile_sel = map[(map_x + cur_x) + (map_y + cur_y)*map_width]; } if (mouse.buttons[MOUSE_BUTTON_MIDDLE]) { tile_sel = map[(map_x + cur_x) + (map_y + cur_y)*map_width]; }
if (keyJustPressed == SDL_SCANCODE_Z && keyboard[CTRL]) { Undo_Undo(); } if (keyJustPressed == SDL_SCANCODE_Z && keyboard[CTRL]) { Undo_Undo(); }