-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wasm
- Loading branch information
Showing
7 changed files
with
107 additions
and
42 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use specs::prelude::*; | ||
|
||
use crate::resources::{AddingNode, AddingWire, CurrentModeText}; | ||
|
||
pub struct CurrentModeSys; | ||
impl<'a> System<'a> for CurrentModeSys { | ||
type SystemData = ( | ||
Write<'a, CurrentModeText>, | ||
Read<'a, AddingNode>, | ||
Read<'a, AddingWire>, | ||
); | ||
|
||
fn run(&mut self, (mut current_mode, adding_node, adding_wire): Self::SystemData) { | ||
match adding_node.0 { | ||
Some(_) => { | ||
current_mode.0 = "Click to place node".to_string(); | ||
return; | ||
} | ||
_ => {} | ||
}; | ||
|
||
match adding_wire.0 { | ||
Some((_, _, None, Some(_))) => { | ||
current_mode.0 = "Right click to set wire position".to_string(); | ||
return; | ||
} | ||
Some((_, _, Some(_), Some(_))) => { | ||
current_mode.0 = | ||
"Right click a node to set wire output or left click to cancel".to_string(); | ||
return; | ||
} | ||
_ => {} | ||
}; | ||
|
||
*current_mode = CurrentModeText::default(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,62 @@ | ||
use crate::resources::CurrentModeText; | ||
use crate::resources::{self, GridMode}; | ||
use crate::ResetSys; | ||
use crate::{components::nodes, UiSignal}; | ||
use egui::menu; | ||
use egui::Layout; | ||
use macroquad::prelude::*; | ||
use specs::prelude::*; | ||
|
||
pub fn render_top_panel(ui: &mut egui::Ui, world: &mut World) { | ||
ui.horizontal(|ui| { | ||
menu::menu(ui, "Nodes", |ui| { | ||
macro_rules! node_button { | ||
( $name:expr, $node:ident ) => { | ||
if ui.button($name).clicked() { | ||
world | ||
.fetch_mut::<resources::UiSignals>() | ||
.0 | ||
.push(UiSignal::AddNode(nodes::NodeTy::$node)); | ||
} | ||
}; | ||
} | ||
ui.horizontal(|ui| { | ||
menu::menu(ui, "Nodes", |ui| { | ||
macro_rules! node_button { | ||
( $name:expr, $node:ident ) => { | ||
if ui.button($name).clicked() { | ||
world | ||
.fetch_mut::<resources::UiSignals>() | ||
.0 | ||
.push(UiSignal::AddNode(nodes::NodeTy::$node)); | ||
} | ||
}; | ||
} | ||
|
||
node_button!("Connection Node", Wire); | ||
node_button!("On Node", OnNode); | ||
node_button!("Off Node", OffNode); | ||
node_button!("Not Node", NotNode); | ||
node_button!("And Node", AndNode); | ||
node_button!("Or Node", OrNode); | ||
node_button!("Nand Node", NandNode); | ||
node_button!("Nor Node", NorNode); | ||
node_button!("Xor Node", XorNode); | ||
node_button!("Xnor Node", XnorNode); | ||
}); | ||
node_button!("Connection Node", Wire); | ||
node_button!("On Node", OnNode); | ||
node_button!("Off Node", OffNode); | ||
node_button!("Not Node", NotNode); | ||
node_button!("And Node", AndNode); | ||
node_button!("Or Node", OrNode); | ||
node_button!("Nand Node", NandNode); | ||
node_button!("Nor Node", NorNode); | ||
node_button!("Xor Node", XorNode); | ||
node_button!("Xnor Node", XnorNode); | ||
}); | ||
|
||
if ui.button("Restart Sim").clicked() || is_key_pressed(KeyCode::Space) { | ||
ResetSys.run_now(&world); | ||
world.insert(resources::Tick(0)); | ||
} | ||
|
||
if ui.button("Restart Sim").clicked() || is_key_pressed(KeyCode::Space) { | ||
ResetSys.run_now(&world); | ||
world.insert(resources::Tick(0)); | ||
} | ||
let mut grid_mode = *world.fetch::<GridMode>(); | ||
menu::menu(ui, "Grid Mode", |ui| { | ||
ui.radio_value(&mut grid_mode, GridMode::CrossHatches, "Cross Hatches"); | ||
ui.radio_value(&mut grid_mode, GridMode::Lines, "Lines"); | ||
ui.radio_value(&mut grid_mode, GridMode::Dots, "Dots"); | ||
ui.radio_value(&mut grid_mode, GridMode::Off, "Off"); | ||
}); | ||
world.insert(grid_mode); | ||
|
||
let mut grid_mode = *world.fetch::<GridMode>(); | ||
menu::menu(ui, "Grid Mode", |ui| { | ||
ui.radio_value(&mut grid_mode, GridMode::CrossHatches, "Cross Hatches"); | ||
ui.radio_value(&mut grid_mode, GridMode::Lines, "Lines"); | ||
ui.radio_value(&mut grid_mode, GridMode::Dots, "Dots"); | ||
ui.radio_value(&mut grid_mode, GridMode::Off, "Off"); | ||
if ui.button("Remove All").clicked() { | ||
world.delete_all(); | ||
} | ||
}); | ||
world.insert(grid_mode); | ||
|
||
if ui.button("Remove All").clicked() { | ||
world.delete_all(); | ||
} | ||
ui.with_layout(Layout::right_to_left(), |ui| { | ||
ui.label("\t\t"); | ||
let current_mode = world.fetch::<CurrentModeText>(); | ||
ui.label(¤t_mode.0); | ||
}); | ||
}); | ||
} |