Start M0 editor workflow polish

This commit is contained in:
Rbanh committed 2026-06-06 02:15:14 -04:00
1 parent 3e053a81ab
commit 19c4d017dc
8 files changed
+236 -40

No files matched your search

+73 -10
View File
@@ -8,7 +8,7 @@ use crate::state::{EditorMode, PlayPossession};
use crate::ui::helpers::{
reset_scene_lighting_to_project_defaults, toggle_play_mode, toggle_play_paused,
};
use crate::ui::selection_ops::focus_editor_camera_on_selection;
use crate::ui::selection_ops::{focus_editor_camera_on_selection, reset_selected_transforms};
use crate::ui::theme::{apply_editor_theme, PANEL_BG, TEXT, TEXT_DIM};
use crate::ui::UiState;
@@ -127,6 +127,8 @@ pub struct CommandPalette {
pub open: bool,
pub filter: String,
pub pending_run: Option<String>,
pub focus_filter: bool,
pub selected_index: usize,
}
pub struct ExtensibilityPlugin;
@@ -160,6 +162,7 @@ fn register_builtin_commands(mut registry: ResMut<EditorCommandRegistry>) {
registry.register(Box::new(ResetLightingCommand));
registry.register(Box::new(GroupSelectionCommand));
registry.register(Box::new(FocusSelectionCommand));
registry.register(Box::new(ResetSelectionTransformCommand));
registry.register(Box::new(CreatePostProcessVolumeCommand));
registry.register(Box::new(FocusActiveVolumesCommand));
registry.register(Box::new(SelectVolumesAtCameraCommand));
@@ -272,6 +275,18 @@ impl EditorCommand for FocusSelectionCommand {
}
}
struct ResetSelectionTransformCommand;
impl EditorCommand for ResetSelectionTransformCommand {
fn name(&self) -> &str {
"selection.reset_transform"
}
fn execute(&self, world: &mut World) {
reset_selected_transforms(world);
}
}
struct CreatePostProcessVolumeCommand;
impl EditorCommand for CreatePostProcessVolumeCommand {
@@ -322,6 +337,8 @@ fn command_palette_ui(
if ctx.input(|input| input.modifiers.command && input.key_pressed(egui::Key::P)) {
palette.open = true;
palette.focus_filter = true;
palette.selected_index = 0;
}
if !palette.open {
@@ -339,25 +356,71 @@ fn command_palette_ui(
.color(TEXT_DIM)
.small(),
);
ui.add(
let filter_response = ui.add(
egui::TextEdit::singleline(&mut palette.filter)
.hint_text("Type to filter...")
.desired_width(f32::INFINITY),
);
if palette.focus_filter {
filter_response.request_focus();
palette.focus_filter = false;
}
if filter_response.changed() {
palette.selected_index = 0;
}
let filter = palette.filter.to_lowercase();
let filtered_names: Vec<String> = registry
.names()
.into_iter()
.filter(|name| filter.is_empty() || name.to_lowercase().contains(&filter))
.collect();
if !filtered_names.is_empty() {
palette.selected_index = palette.selected_index.min(filtered_names.len() - 1);
} else {
palette.selected_index = 0;
}
if ui.input_mut(|input| input.consume_key(egui::Modifiers::NONE, egui::Key::ArrowDown))
&& !filtered_names.is_empty()
{
palette.selected_index = (palette.selected_index + 1) % filtered_names.len();
}
if ui.input_mut(|input| input.consume_key(egui::Modifiers::NONE, egui::Key::ArrowUp))
&& !filtered_names.is_empty()
{
palette.selected_index = if palette.selected_index == 0 {
filtered_names.len() - 1
} else {
palette.selected_index - 1
};
}
if ui.input_mut(|input| input.consume_key(egui::Modifiers::NONE, egui::Key::Enter)) {
if let Some(name) = filtered_names.get(palette.selected_index) {
palette.pending_run = Some(name.clone());
palette.open = false;
ui.close();
}
}
if ui.input_mut(|input| input.consume_key(egui::Modifiers::NONE, egui::Key::Escape)) {
palette.open = false;
ui.close();
}
ui.separator();
egui::ScrollArea::vertical()
.max_height(280.0)
.show(ui, |ui| {
for name in registry.names() {
if !palette.filter.is_empty()
&& !name.to_lowercase().contains(&palette.filter.to_lowercase())
{
continue;
}
for (index, name) in filtered_names.iter().enumerate() {
let selected = index == palette.selected_index;
let response =
ui.selectable_label(false, egui::RichText::new(&name).color(TEXT));
ui.selectable_label(selected, egui::RichText::new(name).color(TEXT));
if selected {
response.scroll_to_me(Some(egui::Align::Center));
}
if response.clicked() {
palette.pending_run = Some(name);
palette.selected_index = index;
palette.pending_run = Some(name.clone());
palette.open = false;
ui.close();
}
+73 -27
View File
@@ -637,9 +637,42 @@ pub fn set_transform_with_history(
if transform_nearly_eq(&old, &new) {
return;
}
if let Some(mut transform) = world.get_mut::<Transform>(entity) {
*transform = new;
}
push_history(world, EditorCommand::SetTransform { entity, old, new });
}
pub fn set_transform_group_with_history(
world: &mut World,
changes: impl IntoIterator<Item = (Entity, Transform, Transform)>,
) {
let mut entities = Vec::new();
let mut olds = Vec::new();
let mut news = Vec::new();
for (entity, old, new) in changes {
if transform_nearly_eq(&old, &new) {
continue;
}
if let Some(mut transform) = world.get_mut::<Transform>(entity) {
*transform = new;
entities.push(entity);
olds.push(old);
news.push(new);
}
}
if !entities.is_empty() {
push_history(
world,
EditorCommand::SetTransformGroup {
entities,
olds,
news,
},
);
}
}
pub fn set_actor_kind_with_history(
world: &mut World,
entity: Entity,
@@ -1219,7 +1252,7 @@ fn capture_gizmo_transform_edits(world: &mut World) {
let start_group =
active.map(|(entity, transform)| selected_transforms(world, &selection, entity, transform));
let finished_edit = {
let (finished_edit, live_edit) = {
let mut tracker = world.resource_mut::<TransformEditTracker>();
if tracker.active.is_none() {
if let (Some((entity, transform)), Some(group)) = (active, start_group) {
@@ -1228,15 +1261,26 @@ fn capture_gizmo_transform_edits(world: &mut World) {
}
}
match tracker.active.take() {
Some((primary, old, group)) if active.is_none() => Some((primary, old, group)),
Some((primary, old, group)) if active.is_none() => (Some((primary, old, group)), None),
Some(state) if active.is_some() => {
let live = Some(state.clone());
tracker.active = Some(state);
None
(None, live)
}
_ => None,
_ => (None, None),
}
};
if let Some((primary, old_primary, group)) = live_edit {
let Some(new_primary) = world.get::<Transform>(primary).copied() else {
return;
};
if group.len() > 1 {
let changes = transform_group_changes(old_primary, new_primary, group);
apply_transform_group(world, &changes);
}
}
if let Some((primary, old_primary, group)) = finished_edit {
let Some(new_primary) = world.get::<Transform>(primary).copied() else {
return;
@@ -1245,34 +1289,36 @@ fn capture_gizmo_transform_edits(world: &mut World) {
set_transform_with_history(world, primary, old_primary, new_primary);
return;
}
let translation_delta = new_primary.translation - old_primary.translation;
let rotation_delta = new_primary.rotation * old_primary.rotation.inverse();
let scale_ratio = new_primary.scale / old_primary.scale;
let mut entities = Vec::new();
let mut olds = Vec::new();
let mut news = Vec::new();
for (entity, old) in group {
let changes = transform_group_changes(old_primary, new_primary, group);
set_transform_group_with_history(world, changes);
}
}
fn transform_group_changes(
old_primary: Transform,
new_primary: Transform,
group: Vec<(Entity, Transform)>,
) -> Vec<(Entity, Transform, Transform)> {
let translation_delta = new_primary.translation - old_primary.translation;
let rotation_delta = new_primary.rotation * old_primary.rotation.inverse();
let scale_ratio = new_primary.scale / old_primary.scale;
group
.into_iter()
.map(|(entity, old)| {
let new = Transform {
translation: old.translation + translation_delta,
rotation: rotation_delta * old.rotation,
scale: old.scale * scale_ratio,
};
if let Some(mut transform) = world.get_mut::<Transform>(entity) {
*transform = new;
}
entities.push(entity);
olds.push(old);
news.push(new);
}
if !entities.is_empty() {
push_history(
world,
EditorCommand::SetTransformGroup {
entities,
olds,
news,
},
);
(entity, old, new)
})
.collect()
}
fn apply_transform_group(world: &mut World, changes: &[(Entity, Transform, Transform)]) {
for (entity, _, new) in changes {
if let Some(mut transform) = world.get_mut::<Transform>(*entity) {
*transform = *new;
}
}
}
+20 -1
View File
@@ -5,8 +5,11 @@ use bevy_inspector_egui::bevy_inspector::hierarchy::SelectedEntities;
use shared::LevelObject;
use crate::camera::EditorCamera;
use crate::history::{delete_entities_with_history, duplicate_entities_with_history};
use crate::history::{
delete_entities_with_history, duplicate_entities_with_history, set_transform_group_with_history,
};
use crate::selection::SelectedEntity;
use crate::ui::UiState;
pub fn focus_editor_camera_on_selection(world: &mut World) {
let Some(entity) = world.resource::<SelectedEntity>().0 else {
@@ -58,3 +61,19 @@ pub fn duplicate_selection(world: &mut World, selected: &SelectedEntities) {
let entities = selected_level_entities(world, selected);
duplicate_entities_with_history(world, &entities);
}
pub fn reset_selected_transforms(world: &mut World) {
let changes: Vec<_> = world
.resource::<UiState>()
.selected_entities
.iter()
.filter(|entity| is_level_object(world, *entity))
.filter_map(|entity| {
world
.get::<Transform>(entity)
.copied()
.map(|old| (entity, old, Transform::default()))
})
.collect();
set_transform_group_with_history(world, changes);
}