Skip to content

Commit

Permalink
Started with tool api
Browse files Browse the repository at this point in the history
  • Loading branch information
markusmoenig committed Jul 20, 2024
1 parent ddaaf8d commit 8ca7b41
Show file tree
Hide file tree
Showing 10 changed files with 399 additions and 79 deletions.
Binary file added creator/embedded/brush.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added creator/embedded/pen.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
56 changes: 49 additions & 7 deletions creator/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ lazy_static! {
// pub static ref VOXELTHREAD: Mutex<VoxelThread> = Mutex::new(VoxelThread::default());
pub static ref PRERENDERTHREAD: Mutex<PreRenderThread> = Mutex::new(PreRenderThread::default());
pub static ref UNDOMANAGER: Mutex<UndoManager> = Mutex::new(UndoManager::default());
pub static ref TOOLLIST: Mutex<ToolList> = Mutex::new(ToolList::default());
}

#[derive(PartialEq, Clone, Copy, Debug)]
enum ActiveEditor {
TileEditor,
pub enum ActiveEditor {
GameEditor,
ScreenEditor,
}

Expand Down Expand Up @@ -74,7 +75,7 @@ impl TheTrait for Editor {
project: Project::new(),
project_path: None,

active_editor: ActiveEditor::TileEditor,
active_editor: ActiveEditor::GameEditor,

sidebar: Sidebar::new(),
panels: Panels::new(),
Expand Down Expand Up @@ -324,6 +325,36 @@ impl TheTrait for Editor {
let mut shared_canvas = TheCanvas::new();
shared_canvas.set_layout(vsplitlayout);

// Tool List
let mut tool_list_canvas: TheCanvas = TheCanvas::new();

let mut tool_list_bar_canvas = TheCanvas::new();
tool_list_bar_canvas.set_widget(TheToolListBar::new(TheId::empty()));
tool_list_canvas.set_top(tool_list_bar_canvas);

let mut v_tool_list_layout = TheVLayout::new(TheId::named("Tool List Layout"));
v_tool_list_layout.limiter_mut().set_max_width(51);
v_tool_list_layout.set_margin(vec4i(2, 2, 2, 2));
v_tool_list_layout.set_padding(1);

TOOLLIST.lock().unwrap().set_active_editor(
ActiveEditor::GameEditor,
&mut v_tool_list_layout,
ctx,
);

tool_list_canvas.set_layout(v_tool_list_layout);

let mut tool_list_border_canvas = TheCanvas::new();
let mut border_widget = TheIconView::new(TheId::empty());
border_widget.set_border_color(Some([82, 82, 82, 255]));
border_widget.limiter_mut().set_max_width(1);
border_widget.limiter_mut().set_max_height(i32::MAX);
tool_list_border_canvas.set_widget(border_widget);

tool_list_canvas.set_right(tool_list_border_canvas);
shared_canvas.set_left(tool_list_canvas);

ui.canvas.set_center(shared_canvas);

let mut status_canvas = TheCanvas::new();
Expand Down Expand Up @@ -394,7 +425,7 @@ impl TheTrait for Editor {
if self.server.state == ServerState::Running {
// Ticks
self.client
.tick(self.active_editor == ActiveEditor::TileEditor);
.tick(self.active_editor == ActiveEditor::GameEditor);
let debug = self.server.tick();
if !debug.is_empty() {
self.sidebar.add_debug_messages(debug, ui, ctx);
Expand Down Expand Up @@ -523,7 +554,7 @@ impl TheTrait for Editor {
}
}

if self.active_editor == ActiveEditor::TileEditor
if self.active_editor == ActiveEditor::GameEditor
&& redraw_update
&& !self.project.regions.is_empty()
{
Expand Down Expand Up @@ -565,6 +596,17 @@ impl TheTrait for Editor {
&mut self.client,
&mut self.server_ctx,
);
if TOOLLIST.lock().unwrap().handle_event(
&event,
ui,
ctx,
&mut self.project,
&mut self.server,
&mut self.client,
&mut self.server_ctx,
) {
redraw = true;
}
if self.panels.handle_event(
&event,
ui,
Expand Down Expand Up @@ -671,7 +713,7 @@ impl TheTrait for Editor {
TheEvent::IndexChanged(id, index) => {
if id.name == "Editor Tab Tabbar" {
if index == 0 {
self.active_editor = ActiveEditor::TileEditor;
self.active_editor = ActiveEditor::GameEditor;
} else if index == 1 {
self.active_editor = ActiveEditor::ScreenEditor;
}
Expand Down Expand Up @@ -1369,7 +1411,7 @@ impl TheTrait for Editor {
update_server_icons = true;
} else if self.server.state == ServerState::Paused {
self.client
.tick(self.active_editor == ActiveEditor::TileEditor);
.tick(self.active_editor == ActiveEditor::GameEditor);
let debug = self.server.tick();
if !debug.is_empty() {
self.sidebar.add_debug_messages(debug, ui, ctx);
Expand Down
8 changes: 8 additions & 0 deletions creator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ pub mod tileeditor;
pub mod tilefxeditor;
pub mod tilemapeditor;
pub mod tilepicker;
pub mod toollist;
pub mod tools;
pub mod undo;

use rust_embed::RustEmbed;
Expand All @@ -30,6 +32,8 @@ pub mod prelude {
pub use shared::prelude::*;
pub use theframework::prelude::*;

pub use crate::editor::ActiveEditor;

pub use crate::externals::*;
pub use crate::misc::*;
pub use crate::modelfxeditor::*;
Expand All @@ -41,9 +45,13 @@ pub mod prelude {
pub use crate::tilefxeditor::*;
pub use crate::tilemapeditor::*;
pub use crate::tilepicker::*;
pub use crate::toollist::*;
pub use crate::undo::materialfx_undo::*;
pub use crate::undo::region_undo::*;
pub use crate::undo::*;

pub use crate::tools::tiledrawer::TileDrawerTool;
pub use crate::tools::*;
}

use crate::editor::Editor;
Expand Down
78 changes: 7 additions & 71 deletions creator/src/tileeditor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,7 @@ impl TileEditor {
// An item in the tile list was selected
else if id.name == "Tilemap Tile" {
self.curr_tile_uuid = Some(id.uuid);
server_ctx.curr_tile_id = Some(id.uuid);

if let Some(t) = TILEDRAWER.lock().unwrap().tiles.get(&id.uuid) {
if let Some(icon_view) = ui.get_icon_view("Icon Preview") {
Expand All @@ -831,6 +832,8 @@ impl TileEditor {
server.update_tiles(project.extract_tiles());
} else if id.name == "Ground Icon" {
self.curr_layer_role = Layer2DRole::Ground;
server_ctx.curr_layer_role = Layer2DRole::Ground;

self.set_icon_colors(ui);
server_ctx.show_fx_marker = false;
redraw = true;
Expand All @@ -850,6 +853,8 @@ impl TileEditor {
);
} else if id.name == "Wall Icon" {
self.curr_layer_role = Layer2DRole::Wall;
server_ctx.curr_layer_role = Layer2DRole::Wall;

self.set_icon_colors(ui);
server_ctx.show_fx_marker = false;
redraw = true;
Expand All @@ -869,6 +874,8 @@ impl TileEditor {
);
} else if id.name == "Ceiling Icon" {
self.curr_layer_role = Layer2DRole::Ceiling;
server_ctx.curr_layer_role = Layer2DRole::Ceiling;

self.set_icon_colors(ui);
server_ctx.show_fx_marker = false;
redraw = true;
Expand Down Expand Up @@ -1834,77 +1841,6 @@ impl TileEditor {
self.set_editor_group_index(EditorMode::Draw, ui, ctx);
}
} else if self.editor_mode == EditorMode::Draw {
if let Some(curr_tile_uuid) = self.curr_tile_uuid {
if TILEDRAWER
.lock()
.unwrap()
.tiles
.contains_key(&curr_tile_uuid)
{
if self.curr_layer_role == Layer2DRole::FX {
// Set the tile preview.
if let Some(widget) = ui.get_widget("TileFX RGBA") {
if let Some(tile_rgba) = widget.as_rgba_view() {
if let Some(tile) = project
.extract_region_tile(server_ctx.curr_region, (coord.x, coord.y))
{
let preview_size = TILEFXEDITOR.lock().unwrap().preview_size;
tile_rgba
.set_grid(Some(preview_size / tile.buffer[0].dim().width));
tile_rgba.set_buffer(
tile.buffer[0].scaled(preview_size, preview_size),
);
}
}
}
}

let palette = project.palette.clone();
if let Some(region) = project.get_region_mut(&server_ctx.curr_region) {
if self.curr_layer_role == Layer2DRole::FX {
if !TILEFXEDITOR.lock().unwrap().curr_timeline.is_empty() {
region.set_tilefx(
(coord.x, coord.y),
TILEFXEDITOR.lock().unwrap().curr_timeline.clone(),
)
} else if let Some(tile) = region.tiles.get_mut(&(coord.x, coord.y)) {
tile.tilefx = None;
}
} else {
let mut prev = None;
if let Some(tile) = region.tiles.get(&(coord.x, coord.y)) {
prev = Some(tile.clone());
}

region.set_tile(
(coord.x, coord.y),
self.curr_layer_role,
self.curr_tile_uuid,
);

if let Some(tile) = region.tiles.get(&(coord.x, coord.y)) {
if prev != Some(tile.clone()) {
let undo = RegionUndoAtom::RegionTileEdit(
vec2i(coord.x, coord.y),
prev,
Some(tile.clone()),
);

UNDOMANAGER
.lock()
.unwrap()
.add_region_undo(&region.id, undo, ctx);
}
}
}
self.set_icon_previews(region, &palette, coord, ui);

server.update_region(region);
RENDERER.lock().unwrap().set_region(region);
}
}
//self.redraw_region(ui, server, ctx, server_ctx);
}
}
redraw
}
Expand Down
Loading

0 comments on commit 8ca7b41

Please sign in to comment.