1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
pub mod deletion_tool;
pub mod icon_tool;
pub mod polygon_room_tool;
pub mod rect_room_tool;
pub mod wall_tool;
pub use deletion_tool::DeletionTool;
pub use icon_tool::IconTool;
pub use polygon_room_tool::PolygonRoomTool;
pub use rect_room_tool::RectRoomTool;
pub use wall_tool::WallTool;
use crate::button::Button;
use crate::map::Map;
use crate::math::Vec2;
use crate::transform::Transform;
use raylib::core::drawing::RaylibDrawHandle;
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
#[repr(u8)]
pub enum ToolType {
RectRoomTool,
PolygonRoomTool,
WallTool,
IconTool,
DeletionTool,
NumTools,
}
pub trait Tool {
/// Code that needs to be called when this Tool is activated or reactivated goes here.
fn activate(&mut self) {}
/// Cleanup that needs to be done when the user switches from this tool to something else goes here.
fn deactivate(&mut self) {}
/// Called on each frame when this tool is active.
fn update(&mut self, map: &Map, mouse_pos_m: &Vec2<f64>);
/// Draw the contents of this tool.
// TODO: Maybe make this tool mappable? This might make it easier to make things resizable while
// it's still being drawn.
fn draw(&self, rld: &mut RaylibDrawHandle, transform: &Transform);
/// Generic keybinding.
/// Code to place a single node for this tool.
fn place_single(&mut self, _map: &mut Map, _mouse_pos_m: &Vec2<f64>) {}
/// Generic keybinding.
/// Code to finish whatever one is doing with this tool currently and trying to apply the
/// changes to the map data.
fn finish(&mut self, _map: &mut Map) {}
/// Generic keybinding.
/// Stop whatever one is doing with this tool and do not apply any changes to the map data.
fn abort(&mut self) {}
/// If there are any additional keybindings that need to be handled by this tool, these can be
/// handled here.
fn on_button_pressed(&mut self, _map: &mut Map, _button: Button) {}
}
|