Skip to content

Commit

Permalink
Started with new node based FX Tool
Browse files Browse the repository at this point in the history
  • Loading branch information
markusmoenig committed Aug 5, 2024
1 parent bbec9a5 commit b5512e0
Show file tree
Hide file tree
Showing 15 changed files with 521 additions and 104 deletions.
2 changes: 1 addition & 1 deletion StarterProject.eldiron

Large diffs are not rendered by default.

Binary file added creator/embedded/magicwand.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions creator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ pub mod prelude {
pub use crate::tools::code::CodeTool;
pub use crate::tools::draw::DrawTool;
pub use crate::tools::eraser::EraserTool;
pub use crate::tools::fx::FXTool;
pub use crate::tools::game::GameTool;
pub use crate::tools::mapobjects::MapObjectsTool;
pub use crate::tools::picker::PickerTool;
Expand Down
190 changes: 117 additions & 73 deletions creator/src/tilefxeditor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,105 +27,149 @@ impl TileFXEditor {
let mut toolbar_canvas = TheCanvas::default();
let mut toolbar_hlayout = TheHLayout::new(TheId::empty());
toolbar_hlayout.limiter_mut().set_max_height(25);
toolbar_hlayout.set_margin(vec4i(120, 2, 5, 3));
toolbar_hlayout.set_margin(vec4i(10, 2, 5, 3));

let mut time_slider = TheTimeSlider::new(TheId::named("TileFX Timeline"));
time_slider.set_status_text("The timeline for the tile based effects.");
time_slider.limiter_mut().set_max_width(400);
toolbar_hlayout.add_widget(Box::new(time_slider));

let mut add_button = TheTraybarButton::new(TheId::named("TileFX Clear Marker"));
//add_button.set_icon_name("icon_role_add".to_string());
add_button.set_text(str!("Clear"));
add_button.set_status_text("Clears the currently selected marker.");

let mut clear_button = TheTraybarButton::new(TheId::named("TileFX Clear"));
let mut nodes_button = TheTraybarButton::new(TheId::named("RegionFX Nodes"));
//add_button.set_icon_name("icon_role_add".to_string());
clear_button.set_text(str!("Clear All"));
clear_button.set_status_text("Clears all markers from the timeline.");

let mut clear_mask_button = TheTraybarButton::new(TheId::named("TileFX Clear Mask"));
clear_mask_button.set_text(str!("Clear Mask"));
clear_mask_button.set_status_text("Clear the pixel mask. If there are pixels selected the FX will only be applied to those pixels.");

toolbar_hlayout.add_widget(Box::new(add_button));
toolbar_hlayout.add_widget(Box::new(clear_button));
toolbar_hlayout.add_widget(Box::new(clear_mask_button));
nodes_button.set_text(str!("Effect Nodes"));
nodes_button.set_status_text("Available effect nodes.");
nodes_button.set_context_menu(Some(TheContextMenu {
items: vec![
TheContextMenuItem::new_submenu(
"Effects".to_string(),
TheId::named("Effect Nodes"),
TheContextMenu {
items: vec![TheContextMenuItem::new(
"Brightness".to_string(),
TheId::named("Brightness"),
)],
..Default::default()
},
),
// TheContextMenuItem::new("Noise2D".to_string(), TheId::named("Noise2D")),
// TheContextMenuItem::new("Noise3D".to_string(), TheId::named("Noise3D")),
],
..Default::default()
}));

toolbar_hlayout.add_widget(Box::new(nodes_button));
toolbar_hlayout.set_reverse_index(Some(1));

toolbar_canvas.set_layout(toolbar_hlayout);

canvas.set_top(toolbar_canvas);

// Left FX List
// Node Editor
let mut node_canvas = TheCanvas::new();
let node_view = TheNodeCanvasView::new(TheId::named("RegionFX NodeCanvas"));
node_canvas.set_widget(node_view);

canvas.set_center(node_canvas);

/*
// Toolbar
let mut toolbar_canvas = TheCanvas::default();
let mut toolbar_hlayout = TheHLayout::new(TheId::empty());
toolbar_hlayout.limiter_mut().set_max_height(25);
toolbar_hlayout.set_margin(vec4i(120, 2, 5, 3));
let mut time_slider = TheTimeSlider::new(TheId::named("TileFX Timeline"));
time_slider.set_status_text("The timeline for the tile based effects.");
time_slider.limiter_mut().set_max_width(400);
toolbar_hlayout.add_widget(Box::new(time_slider));
let mut add_button = TheTraybarButton::new(TheId::named("TileFX Clear Marker"));
//add_button.set_icon_name("icon_role_add".to_string());
add_button.set_text(str!("Clear"));
add_button.set_status_text("Clears the currently selected marker.");
let mut clear_button = TheTraybarButton::new(TheId::named("TileFX Clear"));
//add_button.set_icon_name("icon_role_add".to_string());
clear_button.set_text(str!("Clear All"));
clear_button.set_status_text("Clears all markers from the timeline.");
let mut clear_mask_button = TheTraybarButton::new(TheId::named("TileFX Clear Mask"));
clear_mask_button.set_text(str!("Clear Mask"));
clear_mask_button.set_status_text("Clear the pixel mask. If there are pixels selected the FX will only be applied to those pixels.");
toolbar_hlayout.add_widget(Box::new(add_button));
toolbar_hlayout.add_widget(Box::new(clear_button));
toolbar_hlayout.add_widget(Box::new(clear_mask_button));
toolbar_hlayout.set_reverse_index(Some(1));
toolbar_canvas.set_layout(toolbar_hlayout);
canvas.set_top(toolbar_canvas);
let mut list_canvas = TheCanvas::default();
let mut list_layout = TheListLayout::new(TheId::named("TileFX List"));
// Left FX List
let mut item = TheListItem::new(TheId::named("TileFX Brightness"));
item.set_text(str!("Brightness"));
list_layout.add_item(item, ctx);
let mut list_canvas = TheCanvas::default();
let mut list_layout = TheListLayout::new(TheId::named("TileFX List"));
let mut item = TheListItem::new(TheId::named("TileFX Daylight"));
item.set_text(str!("Daylight"));
list_layout.add_item(item, ctx);
let mut item = TheListItem::new(TheId::named("TileFX Brightness"));
item.set_text(str!("Brightness"));
list_layout.add_item(item, ctx);
let mut item = TheListItem::new(TheId::named("TileFX Light Emitter"));
item.set_text(str!("Light Emitter"));
list_layout.add_item(item, ctx);
let mut item = TheListItem::new(TheId::named("TileFX Daylight"));
item.set_text(str!("Daylight"));
list_layout.add_item(item, ctx);
let mut item = TheListItem::new(TheId::named("TileFX Mirror"));
item.set_text(str!("Mirror"));
list_layout.add_item(item, ctx);
let mut item = TheListItem::new(TheId::named("TileFX Light Emitter"));
item.set_text(str!("Light Emitter"));
list_layout.add_item(item, ctx);
list_layout.limiter_mut().set_max_width(130);
list_layout.select_first_item(ctx);
list_canvas.set_layout(list_layout);
let mut item = TheListItem::new(TheId::named("TileFX Mirror"));
item.set_text(str!("Mirror"));
list_layout.add_item(item, ctx);
canvas.set_left(list_canvas);
list_layout.limiter_mut().set_max_width(130);
list_layout.select_first_item(ctx);
list_canvas.set_layout(list_layout);
// Tile FX Center
canvas.set_left(list_canvas);
let mut center_canvas = TheCanvas::default();
// Tile FX Center
let mut text_layout = TheTextLayout::new(TheId::named("TileFX Settings"));
text_layout.limiter_mut().set_max_width(300);
center_canvas.set_layout(text_layout);
let mut center_canvas = TheCanvas::default();
let mut center_color_canvas = TheCanvas::default();
let mut color_layout = TheVLayout::new(TheId::named("TileFX Color Settings"));
color_layout.limiter_mut().set_max_width(140);
color_layout.set_background_color(Some(ListLayoutBackground));
center_color_canvas.set_layout(color_layout);
let mut text_layout = TheTextLayout::new(TheId::named("TileFX Settings"));
text_layout.limiter_mut().set_max_width(300);
center_canvas.set_layout(text_layout);
center_canvas.set_right(center_color_canvas);
canvas.set_center(center_canvas);
let mut center_color_canvas = TheCanvas::default();
let mut color_layout = TheVLayout::new(TheId::named("TileFX Color Settings"));
color_layout.limiter_mut().set_max_width(140);
color_layout.set_background_color(Some(ListLayoutBackground));
center_color_canvas.set_layout(color_layout);
// Tile Preview
center_canvas.set_right(center_color_canvas);
canvas.set_center(center_canvas);
let mut preview_canvas = TheCanvas::default();
let mut tile_rgba = TheRGBAView::new(TheId::named("TileFX RGBA"));
tile_rgba.set_mode(TheRGBAViewMode::TileSelection);
tile_rgba.set_grid(Some(self.preview_size / 24));
tile_rgba.set_grid_color([40, 40, 40, 255]);
tile_rgba.set_buffer(TheRGBABuffer::new(TheDim::new(
0,
0,
self.preview_size,
self.preview_size,
)));
tile_rgba
.limiter_mut()
.set_max_size(vec2i(self.preview_size, self.preview_size));
// Tile Preview
let mut vlayout = TheVLayout::new(TheId::empty());
vlayout.limiter_mut().set_max_width(200);
vlayout.add_widget(Box::new(tile_rgba));
let mut preview_canvas = TheCanvas::default();
let mut tile_rgba = TheRGBAView::new(TheId::named("TileFX RGBA"));
tile_rgba.set_mode(TheRGBAViewMode::TileSelection);
tile_rgba.set_grid(Some(self.preview_size / 24));
tile_rgba.set_grid_color([40, 40, 40, 255]);
tile_rgba.set_buffer(TheRGBABuffer::new(TheDim::new(
0,
0,
self.preview_size,
self.preview_size,
)));
tile_rgba
.limiter_mut()
.set_max_size(vec2i(self.preview_size, self.preview_size));
preview_canvas.set_layout(vlayout);
let mut vlayout = TheVLayout::new(TheId::empty());
vlayout.limiter_mut().set_max_width(200);
vlayout.add_widget(Box::new(tile_rgba));
canvas.set_right(preview_canvas);
preview_canvas.set_layout(vlayout);
canvas.set_right(preview_canvas);
*/
canvas
}

Expand Down
1 change: 1 addition & 0 deletions creator/src/toollist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ impl ToolList {
Box::new(DrawTool::new()),
Box::new(MapObjectsTool::new()),
Box::new(CodeTool::new()),
Box::new(FXTool::new()),
Box::new(PickerTool::new()),
Box::new(EraserTool::new()),
Box::new(SelectionTool::new()),
Expand Down
55 changes: 55 additions & 0 deletions creator/src/tools/fx.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
use crate::prelude::*;
use ToolEvent::*;

pub struct FXTool {
id: TheId,
}

impl Tool for FXTool {
fn new() -> Self
where
Self: Sized,
{
Self {
id: TheId::named("FX Tool"),
}
}

fn id(&self) -> TheId {
self.id.clone()
}
fn info(&self) -> String {
str!("FX Tool (X). Apply effects to tiles.")
}
fn icon_name(&self) -> String {
str!("magicwand")
}
fn accel(&self) -> Option<char> {
Some('x')
}

fn tool_event(
&mut self,
tool_event: ToolEvent,
_tool_context: ToolContext,
_ui: &mut TheUI,
ctx: &mut TheContext,
_project: &mut Project,
_server: &mut Server,
_client: &mut Client,
server_ctx: &mut ServerContext,
) -> bool {
if let Activate = tool_event {
ctx.ui
.send(TheEvent::SetStackIndex(TheId::named("Main Stack"), 3));
server_ctx.show_fx_marker = true;

return true;
} else if let DeActivate = tool_event {
server_ctx.show_fx_marker = false;
return true;
};

false
}
}
1 change: 1 addition & 0 deletions creator/src/tools/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pub use crate::prelude::*;
pub mod code;
pub mod draw;
pub mod eraser;
pub mod fx;
pub mod game;
pub mod mapobjects;
pub mod picker;
Expand Down
6 changes: 6 additions & 0 deletions shared/src/geofxnode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,12 @@ impl GeoFXNode {
}
}
}
BottomWall => {
let mut pos = self.position(&coll);
area.push(Vec2i::from(pos));
pos.y += 1.0;
area.push(Vec2i::from(pos));
}
_ => {
area.push(Vec2i::from(self.position(&coll)));
}
Expand Down
4 changes: 4 additions & 0 deletions shared/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ pub mod server;
pub mod tilearea;
pub mod tiledrawer;
pub mod tilefx;
pub mod tilefxnode;
pub mod tilefxobject;
pub mod tilemap;
pub mod update;
pub mod widget;
Expand Down Expand Up @@ -66,6 +68,8 @@ pub mod prelude {
pub use crate::tilearea::TileArea;
pub use crate::tiledrawer::{RegionDrawSettings, TileDrawer};
pub use crate::tilefx::TileFX;
pub use crate::tilefxnode::*;
pub use crate::tilefxobject::TileFXObject;
pub use crate::tilemap::{Tile, TileRole, Tilemap};
pub use crate::update::*;
pub use crate::widget::*;
Expand Down
4 changes: 3 additions & 1 deletion shared/src/materialfxnode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,8 @@ impl MaterialFXNode {
if resolved.len() == 1 {
hit.mat.base_color =
lerp(resolved[0].mat.base_color, hit.mat.base_color, value);
hit.mat.roughness = lerp(resolved[0].mat.roughness, hit.mat.roughness, value);
hit.mat.metallic = lerp(resolved[0].mat.metallic, hit.mat.metallic, value);
}

Some(0)
Expand All @@ -596,7 +598,7 @@ impl MaterialFXNode {
match &self.role {
Brick => {
if hit.interior_distance < 0.0 || hit.two_d {
let p = hit.pattern_pos; // / (5.0);
let p = hit.pattern_pos;
let d = bricks(p, hit, params);
hit.interior_distance_mortar = Some(hit.interior_distance);
hit.interior_distance = d;
Expand Down
Loading

0 comments on commit b5512e0

Please sign in to comment.