1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
use crate::prelude::*; #[derive(Default, Clone)] pub struct TransformInspectorData { radians: bool, } impl<'a> Inspect<'a> for Transform<f32> { type SystemData = ( ReadStorage<'a, Self>, Read<'a, LazyUpdate>, Write<'a, TransformInspectorData>, ); fn can_add(_: &mut Self::SystemData, _: ::amethyst::ecs::Entity) -> bool { true } fn inspect((storage, lazy, data): &mut Self::SystemData, entity: Entity) { amethyst_imgui::with(|ui| { let me = if let Some(x) = storage.get(entity) { x } else { return; }; let mut new_me = me.clone(); let mut changed = false; ui.push_id(im_str!("Transform")); new_me.translation_mut().control().null_to(0.).speed(0.05).label(im_str!("translation")).changed(&mut changed).build(); if data.radians { let mut rotation = new_me.rotation().euler_angles().2; rotation.control().null_to(0.).speed(0.25f32.to_radians()).label(im_str!("rotation")).changed(&mut changed).build(); new_me.set_rotation_2d(rotation); } else { let mut rotation = new_me.rotation().euler_angles().2.to_degrees(); if rotation == -180. { rotation = 180.; } rotation.control().null_to(0.).speed(0.25).label(im_str!("rotation")).changed(&mut changed).build(); new_me.set_rotation_2d(rotation.to_radians()); } ui.same_line(0.); ui.checkbox(im_str!("radians"), &mut data.radians); new_me.scale_mut().control().null_to(1.).speed(0.01).label(im_str!("scale")).changed(&mut changed).build(); if changed { lazy.insert(entity, new_me); } ui.pop_id(); }); } fn add((_storage, lazy, _): &mut Self::SystemData, entity: Entity) { lazy.insert(entity, Transform::<f32>::default()); } }