diff options
| author | Arne Dußin | 2020-11-09 21:15:35 +0100 |
|---|---|---|
| committer | Arne Dußin | 2020-11-09 21:15:35 +0100 |
| commit | b06e0075bf4dfd51f8ad5df801f9c43fbd73df1f (patch) | |
| tree | bb9de75363ade9f2f27ebdb60507dbefb36afc35 /src/tool/room_tool.rs | |
| parent | e08cb85528e6b72d5f3b2fbeb79b581fa7a4e461 (diff) | |
| download | graf_karto-b06e0075bf4dfd51f8ad5df801f9c43fbd73df1f.tar.gz graf_karto-b06e0075bf4dfd51f8ad5df801f9c43fbd73df1f.zip | |
Add configuration options
Diffstat (limited to 'src/tool/room_tool.rs')
| -rw-r--r-- | src/tool/room_tool.rs | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/src/tool/room_tool.rs b/src/tool/room_tool.rs index 09126c9..1bfb225 100644 --- a/src/tool/room_tool.rs +++ b/src/tool/room_tool.rs @@ -1,4 +1,6 @@ use super::Tool; +use crate::button::Button; +use crate::config::{RoomToolKeybindings, ToolKeybindings}; use crate::grid::snap_to_grid; use crate::map_data::MapData; use crate::math::{Rect, Vec2}; @@ -8,6 +10,7 @@ use raylib::ffi::{Color, MouseButton}; use raylib::RaylibHandle; pub struct RoomTool { + keybindings: RoomToolKeybindings, /// The rectangle that is currently being drawn by the user. Once it is finished, it will be /// pushed into the room_rects. unfinished_rect: Option<(Vec2<f32>, Vec2<f32>)>, @@ -15,8 +18,9 @@ pub struct RoomTool { impl RoomTool { /// Create a new room tool where no rooms have been drawn yet. - pub fn new() -> Self { + pub fn new(keybindings: RoomToolKeybindings) -> Self { Self { + keybindings, unfinished_rect: None, } } @@ -31,18 +35,15 @@ impl Tool for RoomTool { } // Start or finish drawing the currently unfinished rectangle - if rl.is_mouse_button_pressed(MouseButton::MOUSE_LEFT_BUTTON) { - if let Some((pos1, pos2)) = self.unfinished_rect { - map_data.rooms_mut().push(Rect::bounding_rect(pos1, pos2)); - self.unfinished_rect = None; - } else { - let snapped_mouse_pos = snap_to_grid(mouse_pos_m, 0.5); - self.unfinished_rect = Some((snapped_mouse_pos, snapped_mouse_pos)) - } + if self.keybindings.finish_draw.is_pressed(rl) && self.unfinished_rect.is_some() { + let (pos1, pos2) = self.unfinished_rect.take().unwrap(); + map_data.rooms_mut().push(Rect::bounding_rect(pos1, pos2)); + } else if self.keybindings.start_draw.is_pressed(rl) { + let snapped_mouse_pos = snap_to_grid(mouse_pos_m, 0.5); + self.unfinished_rect = Some((snapped_mouse_pos, snapped_mouse_pos)) } - // Abort drawing the room (if any) in case the right mouse button was pressed. - if rl.is_mouse_button_pressed(MouseButton::MOUSE_RIGHT_BUTTON) { + if self.keybindings.abort_draw.is_pressed(rl) { self.unfinished_rect = None; } } @@ -74,4 +75,8 @@ impl Tool for RoomTool { ); } } + + fn activation_key(&self) -> Button { + self.keybindings.activation_key() + } } |
