aboutsummaryrefslogtreecommitdiff
path: root/src/client/tool/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/tool/mod.rs')
-rw-r--r--src/client/tool/mod.rs98
1 files changed, 98 insertions, 0 deletions
diff --git a/src/client/tool/mod.rs b/src/client/tool/mod.rs
new file mode 100644
index 0000000..08e1380
--- /dev/null
+++ b/src/client/tool/mod.rs
@@ -0,0 +1,98 @@
+//! Tools, which are user interfaces that must be specifically selected in order to do something.
+//!
+//! As stated, a tool is not simply everything that helps a user do something, think of it more as a
+//! mode which must be elected by the user to perform a task on a specific object type or a class of
+//! objects. If instead the operation is defined by the state of the program, it is not a tool, since
+//! the user didn't explicitly ask for this function to be performed, but it is rather an option
+//! that's inherent to the situation the user finds themselves in.
+
+pub mod deletion_tool;
+pub mod icon_tool;
+pub mod polygon_room_tool;
+pub mod rect_room_tool;
+pub mod selection_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 selection_tool::SelectionTool;
+pub use wall_tool::WallTool;
+
+use crate::client::input::Input;
+use crate::client::map::Map;
+use crate::client::transform::Transform;
+use crate::client::Connection;
+use crate::math::Vec2;
+use crate::net::Cargo;
+use raylib::core::drawing::RaylibDrawHandle;
+
+#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
+#[repr(u8)]
+/// The types of tools available in graf karto. For information about the tool itself, please see the
+/// referenced Tool's documentation.
+pub enum ToolType {
+ /// See [RectRoomTool] for information on this tool.
+ RectRoomTool,
+ /// See [PolygonRoomTool] for information on this tool.
+ PolygonRoomTool,
+ /// See [WallTool] for information on this tool.
+ WallTool,
+ /// See [IconTool] for information on this tool.
+ IconTool,
+ /// See [DeletionTool] for information on this tool.
+ DeletionTool,
+ /// See [SelectionTool] for information on this tool.
+ SelectionTool,
+ /// Not a real tool but used to know how many tools are available. New tools must be added
+ /// above this variant.
+ // TODO: Since we now use a hash map in the editor, check if this is still necessary at all.
+ NumTools,
+}
+
+/// Base trait for tools. A tool is something that performs a specific action on one or more types of
+/// elements. It must be selected in order to be active. For this reason, the selection tool is a
+/// tool (it must be selected from the toolbox), but the dimension indicator for instance is not,
+/// since it is automatically updated when applicable.
+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.
+ 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,
+ _server: &Connection<Cargo>,
+ _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, _server: &Connection<Cargo>) {}
+
+ /// 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 handle_custom_bindings(
+ &mut self,
+ _map: &mut Map,
+ _server: &Connection<Cargo>,
+ _input: &mut Input,
+ ) {
+ }
+}