Skip to content

Commit

Permalink
Brick pattern node
Browse files Browse the repository at this point in the history
  • Loading branch information
markusmoenig committed Apr 2, 2024
1 parent 3a4c875 commit ed52dc8
Show file tree
Hide file tree
Showing 10 changed files with 254 additions and 48 deletions.
2 changes: 1 addition & 1 deletion StarterProject.eldiron

Large diffs are not rendered by default.

Binary file added creator/embedded/move.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/trash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 36 additions & 6 deletions creator/src/modelfxeditor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,16 @@ impl ModelFXEditor {
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(70, 2, 5, 3));
toolbar_hlayout.set_margin(vec4i(10, 2, 5, 3));

let mut clear_button: TheTraybarButton =
TheTraybarButton::new(TheId::named("ModelFX Clear"));
clear_button.set_icon_name("trash".to_string());
clear_button.set_status_text("Clears the model, deleting all nodes.");

let mut move_button: TheTraybarButton = TheTraybarButton::new(TheId::named("ModelFX Move"));
move_button.set_icon_name("move".to_string());
move_button.set_status_text("Moves the model to the library.");

let mut floors_button = TheTraybarButton::new(TheId::named("ModelFX Add Floor"));
//add_button.set_icon_name("icon_role_add".to_string());
Expand Down Expand Up @@ -68,10 +77,10 @@ impl ModelFXEditor {
);

material_button.set_context_menu(Some(TheContextMenu {
items: vec![TheContextMenuItem::new(
"Material".to_string(),
TheId::named("Material"),
)],
items: vec![
TheContextMenuItem::new("Bricks".to_string(), TheId::named("Bricks")),
TheContextMenuItem::new("Material".to_string(), TheId::named("Material")),
],
..Default::default()
}));

Expand All @@ -82,6 +91,13 @@ impl ModelFXEditor {
zoom.set_continuous(true);
zoom.limiter_mut().set_max_width(120);

toolbar_hlayout.add_widget(Box::new(clear_button));
toolbar_hlayout.add_widget(Box::new(move_button));

let mut spacer = TheSpacer::new(TheId::empty());
spacer.limiter_mut().set_max_size(vec2i(40, 5));
toolbar_hlayout.add_widget(Box::new(spacer));

toolbar_hlayout.add_widget(Box::new(floors_button));
toolbar_hlayout.add_widget(Box::new(walls_button));
toolbar_hlayout.add_widget(Box::new(material_button));
Expand Down Expand Up @@ -119,7 +135,7 @@ impl ModelFXEditor {

let mut text_layout = TheTextLayout::new(TheId::named("ModelFX Settings"));
//text_layout.set_fixed_text_width(90);
text_layout.limiter_mut().set_max_width(220);
text_layout.limiter_mut().set_max_width(240);
settings_canvas.set_layout(text_layout);

canvas.set_right(settings_canvas);
Expand Down Expand Up @@ -147,6 +163,13 @@ impl ModelFXEditor {
let mut redraw = false;

match event {
TheEvent::StateChanged(id, state) => {
if id.name == "ModelFX Clear" && state == &TheWidgetState::Clicked {
self.modelfx = ModelFX::default();
self.modelfx.draw(ui, ctx, &project.palette);
redraw = true;
}
}
TheEvent::ContextMenuSelected(id, item) => {
//println!("{:?}, {:?}", id, item);
if (id.name == "ModelFX Add Wall" || id.name == "ModelFX Add Material")
Expand Down Expand Up @@ -181,6 +204,13 @@ impl ModelFXEditor {
redraw = true;
}
}
TheEvent::TileEditorDelete(id, _) => {
if id.name == "ModelFX RGBA Layout View" {
self.modelfx.delete();
self.modelfx.draw(ui, ctx, &project.palette);
redraw = true;
}
}
TheEvent::ColorButtonClicked(id) => {
// When a color button is clicked, copy over the current palette index.
if id.name.starts_with(":MODELFX:") {
Expand Down
68 changes: 67 additions & 1 deletion creator/src/sidebar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub enum SidebarMode {
Module,
Screen,
Asset,
Model,
Debug,
Palette,
}
Expand Down Expand Up @@ -49,33 +50,61 @@ impl Sidebar {
let mut region_sectionbar_button = TheSectionbarButton::new(TheId::named("Region Section"));
region_sectionbar_button.set_text("Region".to_string());
region_sectionbar_button.set_state(TheWidgetState::Selected);
region_sectionbar_button.set_status_text(
"Edit and manage the regions available in the game. Regions can contain 2D and 3D content.",
);

let mut character_sectionbar_button =
TheSectionbarButton::new(TheId::named("Character Section"));
character_sectionbar_button.set_text("Character".to_string());
character_sectionbar_button.set_status_text(
"Edit and manage the characers (and their behavior) available in the game.",
);

let mut item_sectionbar_button = TheSectionbarButton::new(TheId::named("Item Section"));
item_sectionbar_button.set_text("Item".to_string());
item_sectionbar_button.set_status_text("Edit and manage the items available in the game.");

let mut tilemap_sectionbar_button =
TheSectionbarButton::new(TheId::named("Tilemap Section"));
tilemap_sectionbar_button.set_text("Tilemap".to_string());
tilemap_sectionbar_button.set_status_text(
"Edit and manage your tilemaps. A tilemap is an image containing square tile elements.",
);

let mut module_sectionbar_button = TheSectionbarButton::new(TheId::named("Module Section"));
module_sectionbar_button.set_text("Module".to_string());
module_sectionbar_button.set_status_text(
"Edit and manage your games code modules. Code modules are reusable code functions.",
);

let mut screen_sectionbar_button = TheSectionbarButton::new(TheId::named("Screen Section"));
screen_sectionbar_button.set_text("Screen".to_string());
screen_sectionbar_button.set_status_text(
"Edit and manage your game screens. Screens are the visible areas of your game.",
);

let mut asset_sectionbar_button = TheSectionbarButton::new(TheId::named("Asset Section"));
asset_sectionbar_button.set_text("Asset".to_string());
asset_sectionbar_button.set_status_text(
"Manage assets in the asset library, such as images, sounds, and fonts.",
);

let mut model_sectionbar_button = TheSectionbarButton::new(TheId::named("Model Section"));
model_sectionbar_button.set_text("Model".to_string());
model_sectionbar_button.set_status_text("Add and manage models in the model library.");

let mut debug_sectionbar_button = TheSectionbarButton::new(TheId::named("Debug Section"));
debug_sectionbar_button.set_text("Debug".to_string());
debug_sectionbar_button.set_status_text(
"See debug messages and warnings and errors produced by the game code.",
);

let mut palette_sectionbar_button =
TheSectionbarButton::new(TheId::named("Palette Section"));
palette_sectionbar_button.set_text("Palette".to_string());
palette_sectionbar_button
.set_status_text("Edit the color palette which contains the colors used in the game.");

let mut vlayout = TheVLayout::new(TheId::named("Section Buttons"));
vlayout.add_widget(Box::new(region_sectionbar_button));
Expand All @@ -85,6 +114,7 @@ impl Sidebar {
vlayout.add_widget(Box::new(module_sectionbar_button));
vlayout.add_widget(Box::new(screen_sectionbar_button));
vlayout.add_widget(Box::new(asset_sectionbar_button));
vlayout.add_widget(Box::new(model_sectionbar_button));
vlayout.add_widget(Box::new(debug_sectionbar_button));
vlayout.add_widget(Box::new(palette_sectionbar_button));
vlayout.set_margin(vec4i(5, 10, 5, 5));
Expand Down Expand Up @@ -568,6 +598,42 @@ impl Sidebar {

stack_layout.add_canvas(screens_canvas);

// Model

let model_canvas = TheCanvas::default();

stack_layout.add_canvas(model_canvas);

/*
let mut list_layout = TheListLayout::new(TheId::named("Screen List"));
list_layout
.limiter_mut()
.set_max_size(vec2i(self.width, 200));
let mut list_canvas = TheCanvas::default();
list_canvas.set_layout(list_layout);
let mut screen_add_button = TheTraybarButton::new(TheId::named("Screen Add"));
screen_add_button.set_icon_name("icon_role_add".to_string());
screen_add_button.set_status_text("Add a new screen.");
let mut screen_remove_button = TheTraybarButton::new(TheId::named("Screen Remove"));
screen_remove_button.set_icon_name("icon_role_remove".to_string());
screen_remove_button.set_status_text("Remove the current screen.");
screen_remove_button.set_disabled(true);
let mut toolbar_hlayout = TheHLayout::new(TheId::empty());
toolbar_hlayout.set_background_color(None);
toolbar_hlayout.set_margin(vec4i(5, 2, 5, 2));
toolbar_hlayout.add_widget(Box::new(screen_add_button));
toolbar_hlayout.add_widget(Box::new(screen_remove_button));
//toolbar_hlayout.add_widget(Box::new(TheHDivider::new(TheId::empty())));
let mut toolbar_canvas = TheCanvas::default();
toolbar_canvas.set_widget(TheTraybar::new(TheId::empty()));
toolbar_canvas.set_layout(toolbar_hlayout);
list_canvas.set_bottom(toolbar_canvas);
*/

// Asset

let mut asset_canvas = TheCanvas::default();
Expand Down Expand Up @@ -1842,7 +1908,7 @@ impl Sidebar {
widget.set_value(TheValue::Text("Palette".to_string()));
}

*SIDEBARMODE.lock().unwrap() = SidebarMode::Debug;
*SIDEBARMODE.lock().unwrap() = SidebarMode::Palette;

ctx.ui.send(TheEvent::SetStackIndex(
self.stack_layout_id.clone(),
Expand Down
2 changes: 2 additions & 0 deletions shared/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub mod level;
pub mod modelfx;
pub mod modelfxnode;
pub mod modelfxterminal;
pub mod patterns;
pub mod project;
pub mod region;
pub mod regionfx;
Expand Down Expand Up @@ -46,6 +47,7 @@ pub mod prelude {
pub use crate::renderer::Renderer;
//pub use crate::renderer_utils::*;
pub use crate::modelfxterminal::*;
pub use crate::patterns::*;
pub use crate::screen::*;
pub use crate::sdf3d::*;
pub use crate::server::context::ServerContext;
Expand Down
20 changes: 11 additions & 9 deletions shared/src/modelfx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl ModelFX {
pub fn add(&mut self, fx: String) -> bool {
if let Some(mut node) = ModelFXNode::new_node(&fx, None) {
node.collection_mut()
.set("_pos", TheValue::Int2(vec2i(10, 10)));
.set("_pos", TheValue::Int2(vec2i(200, 10)));
self.selected_node = Some(self.nodes.len());
self.nodes.push(node);
return true;
Expand Down Expand Up @@ -483,7 +483,7 @@ impl ModelFX {

/// Get the node index at the given coordinate.
pub fn get_node_at(&self, coord: Vec2i) -> Option<usize> {
for (i, rect) in self.node_rects.iter().enumerate() {
for (i, rect) in self.node_rects.iter().enumerate().rev() {
if rect.0 as i32 <= coord.x
&& coord.x <= rect.0 as i32 + rect.2 as i32
&& rect.1 as i32 <= coord.y
Expand All @@ -497,7 +497,7 @@ impl ModelFX {

/// Get the terminal index at the given coordinate.
pub fn get_terminal_at(&self, coord: Vec2i) -> Option<Vec3i> {
for (terminal, rect) in self.terminal_rects.iter() {
for (terminal, rect) in self.terminal_rects.iter().rev() {
if rect.0 as i32 <= coord.x
&& coord.x <= rect.0 as i32 + rect.2 as i32
&& rect.1 as i32 <= coord.y
Expand Down Expand Up @@ -573,11 +573,12 @@ impl ModelFX {

if t < max_t {
hit.normal = self.normal(p);
hit.hit_point = p;

let c = dot(hit.normal, normalize(vec3f(1.0, 2.0, 3.0))) * 0.5 + 0.5;
hit.color = vec4f(c, c, c, 1.0);

let terminal_index = self.nodes[hit.node].color_index_for_hit(&hit).1;
let terminal_index = self.nodes[hit.node].color_index_for_hit(&mut hit).1;
self.follow_trail(hit.node, terminal_index as usize, &mut hit, palette);

Some(hit)
Expand Down Expand Up @@ -651,7 +652,6 @@ impl ModelFX {
node: &ModelFXNode,
palette: &ThePalette,
) {
//}, palette: &ThePalette) {
let width = buffer.dim().width as usize;
let height = buffer.dim().height as usize;

Expand Down Expand Up @@ -706,11 +706,13 @@ impl ModelFX {
}

if t < max_t {
let hit = Hit {
let mut hit = Hit {
uv: vec2f(xx / width as f32, yy / height as f32),
normal: self.normal_node(p, node),
..Default::default()
};
let c = ModelFXColor::create(node.color_index_for_hit(&hit).0);
let c =
ModelFXColor::create(node.color_index_for_hit(&mut hit).0);
color = c.color().to_vec4f();
}

Expand All @@ -726,14 +728,14 @@ impl ModelFX {
} else {
// Material node
let mut hit = Hit {
uv: vec2f(xx, yy),
uv: vec2f(xx / width as f32, yy / height as f32) * 2.5,
..Default::default()
};
if let ModelFXNode::Material(_coll) = node {
node.material(&0, &mut hit, palette);
total = hit.color;
} else {
let c = ModelFXColor::create(node.color_index_for_hit(&hit).0);
let c = ModelFXColor::create(node.color_index_for_hit(&mut hit).0);
total = c.color().to_vec4f();
}
}
Expand Down
Loading

0 comments on commit ed52dc8

Please sign in to comment.