From f2228c1442b3d6e302d7ed9970bd6b161548c470 Mon Sep 17 00:00:00 2001 From: Markus Moenig Date: Mon, 29 Jul 2024 14:16:26 +0700 Subject: [PATCH] Tool accelerators --- creator/src/editor.rs | 7 +++ creator/src/tileeditor.rs | 44 ------------------ creator/src/toollist.rs | 64 +++++++++++++++++++++++++- creator/src/tools/code.rs | 5 +- creator/src/tools/draw.rs | 5 +- creator/src/tools/eraser.rs | 5 +- creator/src/tools/mapobjects.rs | 7 ++- creator/src/tools/mod.rs | 4 ++ creator/src/tools/picker.rs | 5 +- creator/src/tools/render.rs | 5 +- creator/src/tools/screen/eraser.rs | 5 +- creator/src/tools/screen/picker.rs | 5 +- creator/src/tools/screen/tiledrawer.rs | 5 +- creator/src/tools/selection.rs | 5 +- creator/src/tools/tiledrawer.rs | 5 +- creator/src/tools/tilemap.rs | 5 +- creator/src/tools/zoom.rs | 5 +- 17 files changed, 126 insertions(+), 60 deletions(-) diff --git a/creator/src/editor.rs b/creator/src/editor.rs index 3f54b0fc..4898d37e 100644 --- a/creator/src/editor.rs +++ b/creator/src/editor.rs @@ -464,6 +464,7 @@ impl TheTrait for Editor { if let Some(widget) = ui.get_widget("Server Time Slider") { widget.set_value(TheValue::Time(self.server.world.time)); + TOOLLIST.lock().unwrap().server_time = self.server.world.time; } } @@ -550,12 +551,15 @@ impl TheTrait for Editor { } } PreRenderResult::Progress(text) => { + TOOLLIST.lock().unwrap().render_button_text = text.clone(); ui.set_widget_value("Render Button", ctx, TheValue::Text(text)); } PreRenderResult::Paused => { + TOOLLIST.lock().unwrap().render_button_text = "Paused".to_string(); ui.set_widget_value("Render Button", ctx, TheValue::Text(str!("Paused"))); } PreRenderResult::Finished => { + TOOLLIST.lock().unwrap().render_button_text = "Finished".to_string(); ui.set_widget_value("Render Button", ctx, TheValue::Text(str!("Finished"))); } _ => {} @@ -1160,6 +1164,8 @@ impl TheTrait for Editor { if let Some(widget) = ui.get_widget("Server Time Slider") { widget.set_value(TheValue::Time(self.project.time)); + TOOLLIST.lock().unwrap().server_time = + self.server.world.time; } self.server.set_time(self.project.time); @@ -1479,6 +1485,7 @@ impl TheTrait for Editor { if let TheValue::Time(time) = value { self.server.set_time(time); self.project.time = time; + TOOLLIST.lock().unwrap().server_time = time; } } } diff --git a/creator/src/tileeditor.rs b/creator/src/tileeditor.rs index f25edd13..8c76149b 100644 --- a/creator/src/tileeditor.rs +++ b/creator/src/tileeditor.rs @@ -129,48 +129,6 @@ impl TileEditor { tile_picker.set_layout(vlayout); center.set_left(tile_picker); - // Top Toolbar - let mut top_toolbar = TheCanvas::new(); - top_toolbar.set_widget(TheTraybar::new(TheId::empty())); - - let mut gb = TheGroupButton::new(TheId::named("2D3D Group")); - gb.add_text("2D Map".to_string()); - gb.add_text("Mixed".to_string()); - gb.add_text("3D Map".to_string()); - - let mut time_slider = TheTimeSlider::new(TheId::named("Server Time Slider")); - time_slider.set_continuous(true); - time_slider.limiter_mut().set_max_width(400); - - let mut spacer = TheSpacer::new(TheId::empty()); - spacer.limiter_mut().set_max_width(30); - - let mut render_button = TheTraybarButton::new(TheId::named("Render Button")); - render_button.set_text("Starting...".to_string()); - render_button.set_status_text("Controls the 3D background renderer. During rendering it displays how many tiles are left to render."); - render_button.set_fixed_size(true); - render_button.limiter_mut().set_max_width(80); - - render_button.set_context_menu(Some(TheContextMenu { - items: vec![ - TheContextMenuItem::new("Start".to_string(), TheId::named("Start Renderer")), - TheContextMenuItem::new("Pause".to_string(), TheId::named("Pause Renderer")), - TheContextMenuItem::new("Restart".to_string(), TheId::named("Restart Renderer")), - ], - ..Default::default() - })); - - let mut toolbar_hlayout = TheHLayout::new(TheId::empty()); - toolbar_hlayout.set_background_color(None); - toolbar_hlayout.set_margin(vec4i(10, 4, 5, 4)); - toolbar_hlayout.add_widget(Box::new(gb)); - toolbar_hlayout.add_widget(Box::new(spacer)); - toolbar_hlayout.add_widget(Box::new(time_slider)); - toolbar_hlayout.add_widget(Box::new(render_button)); - toolbar_hlayout.set_reverse_index(Some(1)); - - top_toolbar.set_layout(toolbar_hlayout); - // Tool Params let mut toolbar_hlayout = TheHLayout::new(TheId::named("Game Tool Params")); toolbar_hlayout.set_background_color(None); @@ -182,8 +140,6 @@ impl TileEditor { center.set_top(toolbar_canvas); - //center.set_top(top_toolbar); - // Bottom Toolbar let mut bottom_toolbar = TheCanvas::new(); bottom_toolbar.set_widget(TheTraybar::new(TheId::empty())); diff --git a/creator/src/toollist.rs b/creator/src/toollist.rs index d1b44397..b479832d 100644 --- a/creator/src/toollist.rs +++ b/creator/src/toollist.rs @@ -1,9 +1,12 @@ -use crate::editor::{PRERENDERTHREAD, RENDERER}; +use crate::editor::{PRERENDERTHREAD, RENDERER, RENDERMODE}; use crate::prelude::*; pub use ActiveEditor::*; pub struct ToolList { + pub server_time: TheTime, + pub render_button_text: String, + pub active_editor: ActiveEditor, pub game_tools: Vec>, @@ -41,6 +44,9 @@ impl ToolList { ]; Self { + server_time: TheTime::default(), + render_button_text: "Starting...".to_string(), + active_editor: ActiveEditor::GameEditor, game_tools, @@ -103,6 +109,53 @@ impl ToolList { ) -> bool { let mut redraw = false; match event { + TheEvent::KeyDown(TheValue::Char(c)) => { + let mut acc = true; + if let Some(id) = &ctx.ui.focus { + if let Some(widget) = ui.get_widget_abs(None, Some(&id.uuid)) { + acc = !widget.supports_text_input(); + } + } + + if acc { + match self.active_editor { + GameEditor => { + let mut tool_uuid = None; + for tool in self.game_tools.iter() { + if tool.accel() == Some(*c) { + tool_uuid = Some(tool.id().uuid); + ctx.ui.set_widget_state( + self.game_tools[self.curr_game_tool].id().name, + TheWidgetState::None, + ); + ctx.ui + .set_widget_state(tool.id().name, TheWidgetState::Selected); + } + } + if let Some(uuid) = tool_uuid { + self.set_tool(uuid, ui, ctx, project, server, client, server_ctx); + } + } + ScreenEditor => { + let mut tool_uuid = None; + for tool in self.screen_tools.iter() { + if tool.accel() == Some(*c) { + tool_uuid = Some(tool.id().uuid); + ctx.ui.set_widget_state( + self.screen_tools[self.curr_screen_tool].id().name, + TheWidgetState::None, + ); + ctx.ui + .set_widget_state(tool.id().name, TheWidgetState::Selected); + } + } + if let Some(uuid) = tool_uuid { + self.set_tool(uuid, ui, ctx, project, server, client, server_ctx); + } + } + } + } + } TheEvent::StateChanged(id, state) => { if id.name.contains("Tool") && *state == TheWidgetState::Selected { redraw = self.set_tool(id.uuid, ui, ctx, project, server, client, server_ctx); @@ -383,15 +436,22 @@ impl ToolList { gb.add_text("Mixed".to_string()); gb.add_text("3D Map".to_string()); + match *RENDERMODE.lock().unwrap() { + EditorDrawMode::Draw2D => gb.set_index(0), + EditorDrawMode::DrawMixed => gb.set_index(1), + EditorDrawMode::Draw3D => gb.set_index(2), + } + let mut time_slider = TheTimeSlider::new(TheId::named("Server Time Slider")); time_slider.set_continuous(true); time_slider.limiter_mut().set_max_width(400); + time_slider.set_value(TheValue::Time(self.server_time)); let mut spacer = TheSpacer::new(TheId::empty()); spacer.limiter_mut().set_max_width(30); let mut render_button = TheTraybarButton::new(TheId::named("Render Button")); - render_button.set_text("Starting...".to_string()); + render_button.set_text(self.render_button_text.clone()); render_button.set_status_text("Controls the 3D background renderer. During rendering it displays how many tiles are left to render."); render_button.set_fixed_size(true); render_button.limiter_mut().set_max_width(80); diff --git a/creator/src/tools/code.rs b/creator/src/tools/code.rs index 2da6b173..b679fc3e 100644 --- a/creator/src/tools/code.rs +++ b/creator/src/tools/code.rs @@ -19,11 +19,14 @@ impl Tool for CodeTool { self.id.clone() } fn info(&self) -> String { - str!("I draw tiles") + str!("Code Tool (C).") } fn icon_name(&self) -> String { str!("code") } + fn accel(&self) -> Option { + Some('c') + } fn tool_event( &mut self, diff --git a/creator/src/tools/draw.rs b/creator/src/tools/draw.rs index 200be6ed..12ebdd71 100644 --- a/creator/src/tools/draw.rs +++ b/creator/src/tools/draw.rs @@ -36,11 +36,14 @@ impl Tool for DrawTool { self.id.clone() } fn info(&self) -> String { - str!("Draw Tool. Draw with materials.") + str!("Draw Tool (D). Draw with materials on the heightmap and objects.") } fn icon_name(&self) -> String { str!("brush") } + fn accel(&self) -> Option { + Some('d') + } fn tool_event( &mut self, diff --git a/creator/src/tools/eraser.rs b/creator/src/tools/eraser.rs index ffbebdb8..44ee7882 100644 --- a/creator/src/tools/eraser.rs +++ b/creator/src/tools/eraser.rs @@ -21,11 +21,14 @@ impl Tool for EraserTool { self.id.clone() } fn info(&self) -> String { - str!("I draw tiles") + str!("Eraser Tool (E). Erase content in the region editors.") } fn icon_name(&self) -> String { str!("eraser") } + fn accel(&self) -> Option { + Some('e') + } fn tool_event( &mut self, diff --git a/creator/src/tools/mapobjects.rs b/creator/src/tools/mapobjects.rs index 39b66e24..45b74a56 100644 --- a/creator/src/tools/mapobjects.rs +++ b/creator/src/tools/mapobjects.rs @@ -15,7 +15,7 @@ impl Tool for MapObjectsTool { Self: Sized, { Self { - id: TheId::named("Map Objects Tool"), + id: TheId::named("Model Tool"), processed_coords: FxHashSet::default(), } } @@ -24,11 +24,14 @@ impl Tool for MapObjectsTool { self.id.clone() } fn info(&self) -> String { - str!("Map Object Tool. Place 3D objects onto the map like walls.") + str!("Model Tool (M). Place 3D objects on the map (Walls, Furniture...).") } fn icon_name(&self) -> String { str!("mapobjects") } + fn accel(&self) -> Option { + Some('m') + } fn tool_event( &mut self, diff --git a/creator/src/tools/mod.rs b/creator/src/tools/mod.rs index 9d4cfd8e..4670171a 100644 --- a/creator/src/tools/mod.rs +++ b/creator/src/tools/mod.rs @@ -37,6 +37,10 @@ pub trait Tool: Send { fn info(&self) -> String; fn icon_name(&self) -> String; + fn accel(&self) -> Option { + None + } + #[allow(clippy::too_many_arguments)] fn tool_event( &mut self, diff --git a/creator/src/tools/picker.rs b/creator/src/tools/picker.rs index c46bd954..201cff4c 100644 --- a/creator/src/tools/picker.rs +++ b/creator/src/tools/picker.rs @@ -21,11 +21,14 @@ impl Tool for PickerTool { self.id.clone() } fn info(&self) -> String { - str!("Picker Tool.") + str!("Picker Tool (K). Pick content in the region editor.") } fn icon_name(&self) -> String { str!("picker") } + fn accel(&self) -> Option { + Some('k') + } fn tool_event( &mut self, diff --git a/creator/src/tools/render.rs b/creator/src/tools/render.rs index 3ef26561..1e4c12e8 100644 --- a/creator/src/tools/render.rs +++ b/creator/src/tools/render.rs @@ -19,11 +19,14 @@ impl Tool for RenderTool { self.id.clone() } fn info(&self) -> String { - str!("Render Setings.") + str!("Render Setings (R).") } fn icon_name(&self) -> String { str!("faders") } + fn accel(&self) -> Option { + Some('r') + } fn tool_event( &mut self, diff --git a/creator/src/tools/screen/eraser.rs b/creator/src/tools/screen/eraser.rs index 289c0d4d..72f18438 100644 --- a/creator/src/tools/screen/eraser.rs +++ b/creator/src/tools/screen/eraser.rs @@ -19,11 +19,14 @@ impl Tool for ScreenEraserTool { self.id.clone() } fn info(&self) -> String { - str!("Eraser Tool. Erase tiles drawn on widgets.") + str!("Eraser Tool (E). Erase tiles drawn on widgets.") } fn icon_name(&self) -> String { str!("eraser") } + fn accel(&self) -> Option { + Some('e') + } fn tool_event( &mut self, diff --git a/creator/src/tools/screen/picker.rs b/creator/src/tools/screen/picker.rs index e979e66f..ff31c799 100644 --- a/creator/src/tools/screen/picker.rs +++ b/creator/src/tools/screen/picker.rs @@ -19,11 +19,14 @@ impl Tool for ScreenPickerTool { self.id.clone() } fn info(&self) -> String { - str!("Picker Tool. Selects the widget at the click position.") + str!("Picker Tool (K). Selects the widget at the click position.") } fn icon_name(&self) -> String { str!("picker") } + fn accel(&self) -> Option { + Some('k') + } fn tool_event( &mut self, diff --git a/creator/src/tools/screen/tiledrawer.rs b/creator/src/tools/screen/tiledrawer.rs index 2de3b0d7..3b14a41d 100644 --- a/creator/src/tools/screen/tiledrawer.rs +++ b/creator/src/tools/screen/tiledrawer.rs @@ -19,11 +19,14 @@ impl Tool for ScreenTileDrawerTool { self.id.clone() } fn info(&self) -> String { - str!("Tile Drawer Tool. Draw tiles on the current widget.") + str!("Pen Tool (P). Draw tiles on the current widget.") } fn icon_name(&self) -> String { str!("pen") } + fn accel(&self) -> Option { + Some('p') + } fn tool_event( &mut self, diff --git a/creator/src/tools/selection.rs b/creator/src/tools/selection.rs index 9fcfc28b..dc218335 100644 --- a/creator/src/tools/selection.rs +++ b/creator/src/tools/selection.rs @@ -19,11 +19,14 @@ impl Tool for SelectionTool { self.id.clone() } fn info(&self) -> String { - str!("Select Tool.") + str!("Selection Tool (S). Select areas in the region editor.") } fn icon_name(&self) -> String { str!("selection") } + fn accel(&self) -> Option { + Some('s') + } fn tool_event( &mut self, diff --git a/creator/src/tools/tiledrawer.rs b/creator/src/tools/tiledrawer.rs index 9589af3e..58f947b5 100644 --- a/creator/src/tools/tiledrawer.rs +++ b/creator/src/tools/tiledrawer.rs @@ -21,11 +21,14 @@ impl Tool for TileDrawerTool { self.id.clone() } fn info(&self) -> String { - str!("I draw tiles") + str!("Pen Tool (P). Draw tiles.") } fn icon_name(&self) -> String { str!("pen") } + fn accel(&self) -> Option { + Some('p') + } fn tool_event( &mut self, diff --git a/creator/src/tools/tilemap.rs b/creator/src/tools/tilemap.rs index c50e5cb5..a0c39978 100644 --- a/creator/src/tools/tilemap.rs +++ b/creator/src/tools/tilemap.rs @@ -19,11 +19,14 @@ impl Tool for TilemapTool { self.id.clone() } fn info(&self) -> String { - str!("Tilemap Tool.") + str!("Tilemap Tool (T). Create new tiles from your tilemaps.") } fn icon_name(&self) -> String { str!("square") } + fn accel(&self) -> Option { + Some('t') + } fn tool_event( &mut self, diff --git a/creator/src/tools/zoom.rs b/creator/src/tools/zoom.rs index 14c56806..8f47333d 100644 --- a/creator/src/tools/zoom.rs +++ b/creator/src/tools/zoom.rs @@ -19,11 +19,14 @@ impl Tool for ZoomTool { self.id.clone() } fn info(&self) -> String { - str!("Zoom Tool.") + str!("Zoom Tool (Z).") } fn icon_name(&self) -> String { str!("zoom") } + fn accel(&self) -> Option { + Some('z') + } fn tool_event( &mut self,