aboutsummaryrefslogtreecommitdiff
path: root/src/tool/room_tool.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/tool/room_tool.rs')
-rw-r--r--src/tool/room_tool.rs27
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()
+ }
}