Skip to content

Commit

Permalink
stuffs so broke
Browse files Browse the repository at this point in the history
  • Loading branch information
MiniMinerX committed Jan 24, 2025
1 parent 727bd57 commit 668b2b1
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 37 deletions.
15 changes: 10 additions & 5 deletions crates/editor_ui/src/game_view.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use bevy::{prelude::*, window::PrimaryWindow};
use bevy_egui::{egui::{self, RichText, Widget}, render_systems::ExtractedEguiSettings};
use bevy_egui::{egui::{self, RichText, Widget}, render_systems::ExtractedEguiSettings, EguiContextSettings};
use space_undo::UndoRedo;
use transform_gizmo_egui::GizmoMode;

Expand Down Expand Up @@ -148,15 +148,20 @@ pub struct LastGameTabRect(Option<egui::Rect>);
pub fn set_camera_viewport(
mut local: Local<LastGameTabRect>,
ui_state: Res<GameViewTab>,
primary_window: Query<&mut Window, With<PrimaryWindow>>,
egui_settings: Res<ExtractedEguiSettings>,
primary_window: Query<(Entity, &mut Window), With<PrimaryWindow>>,
mut egui_settings: Query<&mut EguiContextSettings>,
mut cameras: Query<&mut Camera, With<EditorCameraMarker>>,
) {
let Ok(mut cam) = cameras.get_single_mut() else {
return;
};

let Ok(window) = primary_window.get_single() else {
let Ok((entity,window)) = primary_window.get_single() else {
return;
};

let Ok(context_settings) =
egui_settings.get_mut(entity) else {
return;
};

Expand All @@ -173,7 +178,7 @@ pub fn set_camera_viewport(
let scale_factor = window.scale_factor();
debug!(
"Window scale factor: {} egui scale factor: {}",
scale_factor, egui_settings.scale_factor
scale_factor, context_settings.scale_factor
);

let mut viewport_pos = viewport_rect.left_top().to_vec2() * scale_factor;
Expand Down
9 changes: 6 additions & 3 deletions crates/editor_ui/src/inspector/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

pub mod components_order;
pub mod events_dispatcher;
pub mod refl_impl;
Expand Down Expand Up @@ -373,6 +374,7 @@ impl EditorTab for InspectorTab {
}
}


impl InspectorTab {
fn show_component(
&mut self,
Expand All @@ -389,9 +391,10 @@ impl InspectorTab {
.default_open(*self.open_components.get(name).unwrap_or(&default))
.show(ui, |ui| {
ui.push_id(format!("content-{:?}-{}", &e.id(), &name), |ui| {
if env.ui_for_reflect_with_options(value, ui, ui.id(), &()) {
(set_changed)();
}
//if env.ui_for_reflect_with_options(value, ui, ui.id(), &()) {
// (set_changed)();
//}
ui.label("show component function error");
});
});
if header.header_response.clicked() {
Expand Down
17 changes: 16 additions & 1 deletion crates/editor_ui/src/inspector/refl_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ use std::any::{Any, TypeId};

use bevy::{
prelude::{AppTypeRegistry, ResMut},
reflect::Reflect,
reflect::{PartialReflect, Reflect},
};
use bevy_egui::egui;
use bevy_inspector_egui::reflect_inspector::ProjectorReflect;
use space_shared::ext::bevy_inspector_egui::{
inspector_egui_impls::InspectorEguiImpl, reflect_inspector::InspectorUi,
};

use space_prefab::component::EntityLink;

/// Method from `bevy_inspector_egui` to make dummy reflection ui
/*
pub fn many_unimplemented<T: Any>(
_ui: &mut egui::Ui,
_options: &dyn Any,
Expand All @@ -22,6 +24,19 @@ pub fn many_unimplemented<T: Any>(
) -> bool {
false
}
*/

pub fn many_unimplemented<T: Any>(
ui: &mut egui::Ui,
_options: &dyn Any,
_id: egui::Id,
_env: InspectorUi<'_, '_>,
_values: &mut [&mut dyn PartialReflect],
_projector: &dyn ProjectorReflect,
) -> bool {
//no_multiedit(ui, &pretty_type_name::<T>());
false
}

/// Custom UI for [`EntityLink`] struct
pub fn setup_ref_registry(reg: ResMut<AppTypeRegistry>) {
Expand Down
24 changes: 18 additions & 6 deletions crates/editor_ui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,19 @@ use bevy_egui::{egui, EguiContext};
use space_editor_tabs::prelude::*;

use game_view::{has_window_changed, GameViewPlugin};

/*
use prelude::{
clean_meshless, reset_camera_viewport, set_camera_viewport, GameModeSettings, GameViewTab,
MeshlessVisualizerPlugin, SpaceHierarchyPlugin, SpaceInspectorPlugin,
};
*/

use prelude::{
reset_camera_viewport, set_camera_viewport, GameModeSettings, GameViewTab,
SpaceHierarchyPlugin, SpaceInspectorPlugin,
};

use space_editor_core::toast::ToastUiPlugin;
use space_prefab::prelude::*;
use space_shared::{
Expand Down Expand Up @@ -187,11 +196,11 @@ impl PluginGroup for EditorPluginGroup {
.add(EditorDefaultBundlesPlugin)
.add(EditorDefaultCameraPlugin)
.add(bevy_egui::EguiPlugin)
.add(EventListenerPlugin::<selection::SelectEvent>::default())
//.add(EventListenerPlugin::<selection::SelectEvent>::default())
.add(DefaultInspectorConfigPlugin);
res = EditorUiPlugin::default().add_plugins_to_group(res);
res.add(PanOrbitCameraPlugin)
.add(selection::EditorPickingPlugin)
//.add(selection::EditorPickingPlugin)
.add(bevy_debug_grid::DebugGridPlugin::without_floor_grid())
.add(
WorldInspectorPlugin::default()
Expand Down Expand Up @@ -270,12 +279,14 @@ fn game_gizmos(mut gizmos_config: ResMut<GizmoConfigStore>) {
gizmos_config.config_mut::<EditorGizmo>().0.render_layers = RenderLayers::layer(0)
}

/*
type AutoAddQueryFilter = (
Without<PrefabMarker>,
Without<Pickable>,
With<Parent>,
Changed<Handle<Mesh>>,
);
*/

#[derive(Default, Reflect, GizmoConfigGroup)]
pub struct EditorGizmo;
Expand Down Expand Up @@ -347,7 +358,7 @@ pub fn simple_editor_setup(mut commands: Commands) {
..default()
},
Transform::from_xyz(4.0, 8.0, 4.0).looking_at(Vec3::ZERO, Vec3::Y),
CascadeShadowConfigBuilder::default().into(),
CascadeShadowConfigBuilder::default().build(),
Name::from("Editor Level Light"),
));

Expand Down Expand Up @@ -390,12 +401,13 @@ pub fn simple_editor_setup(mut commands: Commands) {
bevy_panorbit_camera::PanOrbitCamera::default(),
EditorCameraMarker,
Name::from("Editor Camera"),
PickableBundle::default(),
//PickableBundle::default(),
RayCastPickable,
all_render_layers(),
));
}


pub fn game_mode_changed(
mut commands: Commands,
mode: Res<GameModeSettings>,
Expand All @@ -418,7 +430,7 @@ pub fn game_mode_changed(
bevy_panorbit_camera::PanOrbitCamera::default(),
EditorCameraMarker,
Name::from("Editor Camera"),
PickableBundle::default(),
//PickableBundle::default(),
RayCastPickable,
all_render_layers(),
));
Expand All @@ -431,7 +443,7 @@ pub fn game_mode_changed(
},
EditorCameraMarker,
Name::from("Editor 2D Camera"),
PickableBundle::default(),
//PickableBundle::default(),
RayCastPickable,
all_render_layers(),
));
Expand Down
2 changes: 2 additions & 0 deletions crates/editor_ui/src/menu_toolbars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ fn in_game_menu(
});
}



#[derive(Resource, Default)]
pub struct MenuToolbarState {
pub file_dialog: Option<egui_file::FileDialog>,
Expand Down
6 changes: 6 additions & 0 deletions crates/editor_ui/src/meshless_visualizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ use space_shared::*;
use crate::{EditorGizmo, LAST_RENDER_LAYER};
use space_editor_core::selected::Selected;




/*
#[derive(Default)]
pub struct MeshlessVisualizerPlugin;
Expand Down Expand Up @@ -540,3 +544,5 @@ mod tests {
assert_eq!(query.iter(&app.world()).count(), 2);
}
}
*/
37 changes: 21 additions & 16 deletions crates/editor_ui/src/selection.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::*;
use bevy::prelude::*;

bevy::picking::backend::ray::r

/*
pub struct EditorPickingPlugin;
impl Plugin for EditorPickingPlugin {
Expand Down Expand Up @@ -99,22 +99,7 @@ pub fn select_listener(
}
}
pub fn delete_selected(
mut commands: Commands,
query: Query<Entity, With<Selected>>,
keyboard: Res<ButtonInput<KeyCode>>,
) {
let shift = keyboard.any_pressed([KeyCode::ShiftLeft, KeyCode::ShiftRight]);
let ctrl = keyboard.any_pressed([KeyCode::ControlLeft, KeyCode::ControlRight]);
let delete = keyboard.any_just_pressed([KeyCode::Backspace, KeyCode::Delete]);
if ctrl && shift && delete {
for entity in query.iter() {
info!("Delete Entity: {entity:?}");
commands.entity(entity).despawn_recursive();
}
}
}
impl From<ListenerInput<Pointer<Down>>> for SelectEvent {
fn from(value: ListenerInput<Pointer<Down>>) -> Self {
Expand All @@ -125,10 +110,30 @@ impl From<ListenerInput<Pointer<Down>>> for SelectEvent {
}
}
/// This event used for selecting entities
#[derive(Event, Clone, EntityEvent)]
pub struct SelectEvent {
#[target]
e: Entity,
event: ListenerInput<Pointer<Down>>,
}
pub fn delete_selected(
mut commands: Commands,
query: Query<Entity, With<Selected>>,
keyboard: Res<ButtonInput<KeyCode>>,
) {
let shift = keyboard.any_pressed([KeyCode::ShiftLeft, KeyCode::ShiftRight]);
let ctrl = keyboard.any_pressed([KeyCode::ControlLeft, KeyCode::ControlRight]);
let delete = keyboard.any_just_pressed([KeyCode::Backspace, KeyCode::Delete]);
if ctrl && shift && delete {
for entity in query.iter() {
info!("Delete Entity: {entity:?}");
commands.entity(entity).despawn_recursive();
}
}
}
*/
12 changes: 6 additions & 6 deletions crates/editor_ui/src/ui_plugin.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::tools::gizmo::*;
use crate::*;
use bevy::{ecs::schedule::ScheduleLabel, prelude::*};
use meshless_visualizer::draw_light_gizmo;
//use meshless_visualizer::draw_light_gizmo;

use self::{change_chain::ChangeChainViewPlugin, editor_tab_name::EditorTabName};

Expand Down Expand Up @@ -38,7 +38,7 @@ impl FlatPluginList for EditorUiPlugin {
fn add_plugins_to_group(&self, group: PluginGroupBuilder) -> PluginGroupBuilder {
let mut res = group
.add(SelectedPlugin)
.add(MeshlessVisualizerPlugin)
//.add(MeshlessVisualizerPlugin)
.add(EditorUiCore::default())
.add(GameViewPlugin)
.add(menu_toolbars::BottomMenuPlugin)
Expand Down Expand Up @@ -166,7 +166,7 @@ impl Plugin for EditorUiCore {
//play systems
app.add_systems(OnEnter(EditorState::GamePrepare), save_prefab_before_play);
// clean up meshless children on entering the game state
app.add_systems(OnEnter(EditorState::GamePrepare), clean_meshless);
//app.add_systems(OnEnter(EditorState::GamePrepare), clean_meshless);
app.add_systems(
OnEnter(SaveState::Idle),
to_game_after_save.run_if(in_state(EditorState::GamePrepare)),
Expand All @@ -183,8 +183,8 @@ impl Plugin for EditorUiCore {
Update,
(
draw_camera_gizmo,
draw_light_gizmo,
selection::delete_selected,
//draw_light_gizmo,
//selection::delete_selected,
)
.run_if(in_state(EditorState::Editor).and_then(in_state(ShowEditorUi::Show))),
);
Expand All @@ -198,7 +198,7 @@ impl Plugin for EditorUiCore {
app.add_systems(OnEnter(EditorState::Editor), change_camera_in_editor);
}

app.add_event::<selection::SelectEvent>();
//app.add_event::<selection::SelectEvent>();

app.init_resource::<BundleReg>();
}
Expand Down

0 comments on commit 668b2b1

Please sign in to comment.