shape creation works!

This commit is contained in:
RustyStriker 2022-07-27 19:51:02 +03:00
parent c50609cd64
commit 898cb5e83c
4 changed files with 369 additions and 15 deletions

View file

@ -1,3 +1,4 @@
use bevy::ecs::schedule::ShouldRun;
use bevy::{prelude::*, window::PresentMode, winit::WinitSettings};
use bevy_egui::{egui, EguiContext, EguiPlugin};
use bevy_prototype_lyon::prelude::*;
@ -10,7 +11,9 @@ use shape_maker::*;
/// - toggling hidpi scaling (by pressing '/' button);
/// - configuring egui contexts during the startup.
fn main() {
App::new()
let mut app = App::new();
app
.insert_resource(ClearColor(Color::rgb(0.1, 0.1, 0.12)))
.insert_resource(Msaa { samples: 4 })
// Optimal power saving and present mode settings for desktop apps.
@ -22,12 +25,33 @@ fn main() {
})
.insert_resource(ButtonsColors::default())
.insert_resource(UiState::default())
;
app
.add_plugins(DefaultPlugins)
.add_plugin(EguiPlugin)
.add_plugin(ShapePlugin)
;
app
.add_startup_system(configure_visuals)
.add_startup_system(basic_setup_sys)
.add_system(create_sys.with_run_criteria(|state: Res<UiState>, mut ec: ResMut<EguiContext>|
if !ec.ctx_mut().is_pointer_over_area() && state.current_action == Action::Create { ShouldRun::Yes } else { ShouldRun::No }
))
.add_system(modify_sys.with_run_criteria(|state: Res<UiState>, mut ec: ResMut<EguiContext>|
if !ec.ctx_mut().is_pointer_over_area() && state.current_action == Action::Modify { ShouldRun::Yes } else { ShouldRun::No }
))
.add_system(action_bar_sys)
.run();
;
app.run();
}
fn basic_setup_sys(
mut coms: Commands,
) {
coms.spawn_bundle(OrthographicCameraBundle::new_2d())
.insert(MainCamera);
}
fn configure_visuals(mut egui_ctx: ResMut<EguiContext>) {
@ -48,26 +72,75 @@ fn action_bar_sys(
.resizable(false)
.show(egui_ctx.ctx_mut(), |ui| {
ui.horizontal(|hui| {
let modify_color = if let Action::Modify = state.current_action { colors.clicked } else { colors.regular };
let create_color = if let Action::Create = state.current_action { colors.clicked } else { colors.regular };
let delete_color = if let Action::Delete = state.current_action { colors.clicked } else { colors.regular };
if hui.button(egui::RichText::new("M").color(modify_color)).clicked() {
let m = hui.button(egui::RichText::new("M").color(state.current_action_color(&colors, Action::Modify)))
.on_hover_text("Modify");
if m.clicked() {
state.current_action = Action::Modify;
}
if hui.button(egui::RichText::new("C").color(create_color)).clicked() {
let c = hui.button(egui::RichText::new("C").color(state.current_action_color(&colors, Action::Create)))
.on_hover_text("Create");
if c.clicked() {
state.current_action = Action::Create;
}
if hui.button(egui::RichText::new("D").color(delete_color)).clicked() {
let d = hui.button(egui::RichText::new("D").color(state.current_action_color(&colors, Action::Delete)))
.on_hover_text("Delete");
if d.clicked() {
state.current_action = Action::Delete;
}
hui.label(" | ");
if hui.button(" I ").clicked() {
println!("Image loading is still not supported!");
if hui.button(" I ").on_hover_text("Import Image").clicked() {
println!("Importing Images is still not supported!");
}
hui.label(": :");
});
if state.current_action == Action::Create {
ui.horizontal(|hui| {
let tri = hui.button(egui::RichText::new("Tri").color(state.create_shape_color(&colors, CreateShape::Triangle)))
.on_hover_text("Triangle - from 3 edges");
if tri.clicked() {
state.create_shape = CreateShape::Triangle;
}
let squ = hui.button(egui::RichText::new("Squ").color(state.create_shape_color(&colors, CreateShape::Square)))
.on_hover_text("Square - from 2 opposing edges");
if squ.clicked() {
state.create_shape = CreateShape::Square;
}
let sce = hui.button(egui::RichText::new("SqC").color(state.create_shape_color(&colors, CreateShape::SquareCenter)))
.on_hover_text("Square - from center point and edge");
if sce.clicked() {
state.create_shape = CreateShape::SquareCenter;
}
let cir = hui.button(egui::RichText::new("Cir").color(state.create_shape_color(&colors, CreateShape::Circle)))
.on_hover_text("Circle - center point and radius");
if cir.clicked() {
state.create_shape = CreateShape::Circle;
}
// let cap = hui.button(egui::RichText::new("Cap").color(state.create_shape_color(&colors, CreateShape::Capsule)))
// .on_hover_text("Capsule - from 2 center points and a radius");
// if cap.clicked() {
// state.create_shape = CreateShape::Capsule;
// }
});
}
});
}
}
fn modify_sys(
mouse: Res<Input<MouseButton>>,
wnds: Res<Windows>,
q_cam: Query<(&Camera, &GlobalTransform), With<MainCamera>>,
mut paths: Query<&mut Path>,
mut transforms: Query<&mut Transform>,
shapes: Query<&ShapeData>,
) {
let mouse_pos = get_mouse_pos(&q_cam, &wnds);
if let Some(mouse_pos) = mouse_pos {
}
}