From 4a03d938451763dfb95b534f9002865e72ea7ec5 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sat, 16 Mar 2019 17:45:16 -0400 Subject: Can click to place tiles in editor now --- src/editor.cpp | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) (limited to 'src/editor.cpp') diff --git a/src/editor.cpp b/src/editor.cpp index 30dde45..8ca850a 100644 --- a/src/editor.cpp +++ b/src/editor.cpp @@ -63,7 +63,7 @@ void Editor::tick( } // Check for keypress changes since the last tick. - input_.tick(keystate); + input_.tick(); if (input_.wasPressed(SDL_SCANCODE_Z)) { @@ -130,10 +130,45 @@ void Editor::tick( mapFocus_ = !mapFocus_; } + bool newlyTabbed = false; + + if (input_.wasClicked(SDL_BUTTON_LEFT)) + { + if (EDITOR_MAP_AREA.contains(input_.getMousePos())) + { + if (!mapFocus_) + { + newlyTabbed = true; + } + + mapFocus_ = true; + } else if (EDITOR_TILESET_AREA.contains(input_.getMousePos())) + { + if (mapFocus_) + { + newlyTabbed = true; + } + + mapFocus_ = false; + + selectedTile_ = + (input_.getMousePos() - EDITOR_TILESET_AREA.pos).y() / TILE_SIZE.h(); + } + } + if (mapFocus_) { + if (EDITOR_MAP_AREA.contains(input_.getMousePos()) && + ( input_.hasMouseMoved() || newlyTabbed )) + { + cursor_ = (input_.getMousePos() - EDITOR_MAP_AREA.pos) / TILE_SIZE; + } + if (keystate[SDL_SCANCODE_RETURN] || - keystate[SDL_SCANCODE_SPACE]) + keystate[SDL_SCANCODE_SPACE] || + ( input_.isClicked(SDL_BUTTON_LEFT) && + EDITOR_MAP_AREA.contains(input_.getMousePos()) && + !newlyTabbed )) { level_.at(cursor_.x(), cursor_.y(), layer_) = selectedTile_; -- cgit 1.4.1