Skip to content

Commit

Permalink
Tool accelerators
Browse files Browse the repository at this point in the history
  • Loading branch information
markusmoenig committed Jul 29, 2024
1 parent dee901b commit f2228c1
Show file tree
Hide file tree
Showing 17 changed files with 126 additions and 60 deletions.
7 changes: 7 additions & 0 deletions creator/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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")));
}
_ => {}
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;
}
}
}
Expand Down
44 changes: 0 additions & 44 deletions creator/src/tileeditor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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()));
Expand Down
64 changes: 62 additions & 2 deletions creator/src/toollist.rs
Original file line number Diff line number Diff line change
@@ -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<Box<dyn Tool>>,
Expand Down Expand Up @@ -41,6 +44,9 @@ impl ToolList {
];

Self {
server_time: TheTime::default(),
render_button_text: "Starting...".to_string(),

active_editor: ActiveEditor::GameEditor,

game_tools,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion creator/src/tools/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<char> {
Some('c')
}

fn tool_event(
&mut self,
Expand Down
5 changes: 4 additions & 1 deletion creator/src/tools/draw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<char> {
Some('d')
}

fn tool_event(
&mut self,
Expand Down
5 changes: 4 additions & 1 deletion creator/src/tools/eraser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<char> {
Some('e')
}

fn tool_event(
&mut self,
Expand Down
7 changes: 5 additions & 2 deletions creator/src/tools/mapobjects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
}
Expand All @@ -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<char> {
Some('m')
}

fn tool_event(
&mut self,
Expand Down
4 changes: 4 additions & 0 deletions creator/src/tools/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ pub trait Tool: Send {
fn info(&self) -> String;
fn icon_name(&self) -> String;

fn accel(&self) -> Option<char> {
None
}

#[allow(clippy::too_many_arguments)]
fn tool_event(
&mut self,
Expand Down
5 changes: 4 additions & 1 deletion creator/src/tools/picker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<char> {
Some('k')
}

fn tool_event(
&mut self,
Expand Down
5 changes: 4 additions & 1 deletion creator/src/tools/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<char> {
Some('r')
}

fn tool_event(
&mut self,
Expand Down
5 changes: 4 additions & 1 deletion creator/src/tools/screen/eraser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<char> {
Some('e')
}

fn tool_event(
&mut self,
Expand Down
5 changes: 4 additions & 1 deletion creator/src/tools/screen/picker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<char> {
Some('k')
}

fn tool_event(
&mut self,
Expand Down
5 changes: 4 additions & 1 deletion creator/src/tools/screen/tiledrawer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<char> {
Some('p')
}

fn tool_event(
&mut self,
Expand Down
5 changes: 4 additions & 1 deletion creator/src/tools/selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<char> {
Some('s')
}

fn tool_event(
&mut self,
Expand Down
5 changes: 4 additions & 1 deletion creator/src/tools/tiledrawer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<char> {
Some('p')
}

fn tool_event(
&mut self,
Expand Down
Loading

0 comments on commit f2228c1

Please sign in to comment.