Build production-ready editor authoring workflows
CI / Format, lint, test, build (push) Waiting to run
CI / Format, lint, test, build (push) Waiting to run
This commit is contained in:
1 parent
cc1fa6ea3b
commit
0553a85220
163 files changed
+34547
-1565
No files matched your search
@@ -5,11 +5,12 @@ mod transform;
|
||||
use bevy::prelude::*;
|
||||
use bevy_egui::egui;
|
||||
use egui_phosphor_icons::icons;
|
||||
use shared::{ActorId, ActorKind, ActorName, LevelObject};
|
||||
use shared::{ActorId, ActorKind, ActorName, HydratedPrefabMember, LevelObject};
|
||||
|
||||
use crate::ext::extensibility::ActorInspectorSectionRegistry;
|
||||
use crate::ui::inspector;
|
||||
use crate::ui::theme::{panel_heading, BORDER, TEXT_DIM, WIDGET_BG};
|
||||
use crate::ui::selection_ops::is_linked_read_only;
|
||||
use crate::ui::theme::{panel_heading, BORDER, SELECTION, TEXT, TEXT_DIM, WIDGET_BG};
|
||||
use crate::ui::widgets::phosphor_icon;
|
||||
|
||||
use transform::transform_inspector_ui;
|
||||
@@ -17,6 +18,8 @@ use transform::transform_inspector_ui;
|
||||
const COMPACT_ACTOR_HEADER_WIDTH: f32 = 360.0;
|
||||
|
||||
pub fn draw_actor_inspector(world: &mut World, ui: &mut egui::Ui, entity: Entity) {
|
||||
let linked_read_only = is_linked_read_only(world, entity);
|
||||
let prefab_member = world.get::<HydratedPrefabMember>(entity).is_some();
|
||||
let Some(entity_ref) = world.get_entity(entity).ok() else {
|
||||
ui.label("Entity no longer exists.");
|
||||
return;
|
||||
@@ -79,34 +82,59 @@ pub fn draw_actor_inspector(world: &mut World, ui: &mut egui::Ui, entity: Entity
|
||||
});
|
||||
ui.add_space(6.0);
|
||||
|
||||
egui::ScrollArea::vertical()
|
||||
.auto_shrink([false, false])
|
||||
.show(ui, |ui| {
|
||||
transform_inspector_ui(world, ui, entity);
|
||||
if linked_read_only {
|
||||
ui.small(
|
||||
egui::RichText::new(if prefab_member {
|
||||
"Linked prefab member"
|
||||
} else {
|
||||
"Linked scene member"
|
||||
})
|
||||
.color(TEXT_DIM),
|
||||
);
|
||||
ui.add_space(4.0);
|
||||
}
|
||||
|
||||
match kind {
|
||||
ActorKind::StaticMesh
|
||||
| ActorKind::Brush
|
||||
| ActorKind::ImportedModel
|
||||
| ActorKind::Light
|
||||
| ActorKind::Empty
|
||||
| ActorKind::PrefabAnchor
|
||||
| ActorKind::PlayerSpawn
|
||||
| ActorKind::WeaponSpawn
|
||||
| ActorKind::TriggerVolume
|
||||
| ActorKind::PostProcessVolume
|
||||
| ActorKind::TeamSpawn
|
||||
| ActorKind::Objective => {
|
||||
inspector::authoring_inspector_ui(world, ui, entity);
|
||||
}
|
||||
}
|
||||
|
||||
world.resource_scope(|world, registry: Mut<ActorInspectorSectionRegistry>| {
|
||||
registry.draw_sections(world, ui, entity);
|
||||
if prefab_member {
|
||||
egui::ScrollArea::vertical()
|
||||
.auto_shrink([false, false])
|
||||
.show(ui, |ui| {
|
||||
crate::assets::prefab_overrides::prefab_member_inspector_ui(world, ui, entity);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
inspector::add_component_footer(world, ui, entity);
|
||||
});
|
||||
ui.add_enabled_ui(!linked_read_only, |ui| {
|
||||
egui::ScrollArea::vertical()
|
||||
.auto_shrink([false, false])
|
||||
.show(ui, |ui| {
|
||||
transform_inspector_ui(world, ui, entity);
|
||||
|
||||
match kind {
|
||||
ActorKind::StaticMesh
|
||||
| ActorKind::Brush
|
||||
| ActorKind::ImportedModel
|
||||
| ActorKind::Light
|
||||
| ActorKind::Empty
|
||||
| ActorKind::PrefabAnchor
|
||||
| ActorKind::PlayerSpawn
|
||||
| ActorKind::WeaponSpawn
|
||||
| ActorKind::TriggerVolume
|
||||
| ActorKind::PostProcessVolume
|
||||
| ActorKind::TeamSpawn
|
||||
| ActorKind::Objective
|
||||
| ActorKind::AudioSource
|
||||
| ActorKind::AudioListener => {
|
||||
inspector::authoring_inspector_ui(world, ui, entity);
|
||||
}
|
||||
}
|
||||
|
||||
world.resource_scope(|world, registry: Mut<ActorInspectorSectionRegistry>| {
|
||||
registry.draw_sections(world, ui, entity);
|
||||
});
|
||||
|
||||
inspector::add_component_footer(world, ui, entity);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
fn actor_icon(kind: ActorKind) -> egui_phosphor_icons::Icon {
|
||||
@@ -119,14 +147,52 @@ fn actor_icon(kind: ActorKind) -> egui_phosphor_icons::Icon {
|
||||
ActorKind::TriggerVolume => icons::SELECTION,
|
||||
ActorKind::PostProcessVolume => icons::APERTURE,
|
||||
ActorKind::TeamSpawn | ActorKind::Objective => icons::FLAG,
|
||||
ActorKind::AudioSource => icons::SPEAKER_HIGH,
|
||||
ActorKind::AudioListener => icons::HEADPHONES,
|
||||
ActorKind::Empty => icons::CIRCLE,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn draw_multi_actor_inspector(world: &mut World, ui: &mut egui::Ui, entities: &[Entity]) {
|
||||
ui.heading(format!("{} objects selected", entities.len()));
|
||||
ui.label("Multi-edit: use the viewport gizmo for shared transform.");
|
||||
if entities.is_empty() {
|
||||
egui::Frame::new()
|
||||
.fill(WIDGET_BG)
|
||||
.stroke(egui::Stroke::new(1.0, BORDER))
|
||||
.corner_radius(egui::CornerRadius::same(4))
|
||||
.inner_margin(egui::Margin::symmetric(10, 10))
|
||||
.show(ui, |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
ui.label(phosphor_icon(icons::SELECTION, 24.0).color(TEXT_DIM));
|
||||
ui.label(egui::RichText::new("No selection").color(TEXT_DIM).strong());
|
||||
});
|
||||
});
|
||||
return;
|
||||
}
|
||||
if entities.len() == 1 {
|
||||
draw_actor_inspector(world, ui, entities[0]);
|
||||
return;
|
||||
}
|
||||
|
||||
egui::Frame::new()
|
||||
.fill(WIDGET_BG)
|
||||
.stroke(egui::Stroke::new(1.0, BORDER))
|
||||
.corner_radius(egui::CornerRadius::same(4))
|
||||
.inner_margin(egui::Margin::symmetric(10, 10))
|
||||
.show(ui, |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
ui.label(phosphor_icon(icons::SELECTION_ALL, 26.0).color(SELECTION));
|
||||
ui.vertical(|ui| {
|
||||
ui.label(
|
||||
egui::RichText::new(format!("{} objects selected", entities.len()))
|
||||
.color(TEXT)
|
||||
.strong(),
|
||||
);
|
||||
ui.label(
|
||||
egui::RichText::new("Shared transform gizmo")
|
||||
.color(TEXT_DIM)
|
||||
.small(),
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -29,16 +29,18 @@ use crate::asset_db::{
|
||||
find_asset_by_path, find_asset_mut_by_path, save_registry, update_import_settings,
|
||||
ImportSettings, MaterialImportPolicy, ModelHierarchyMode, ModelPlacementMode,
|
||||
};
|
||||
use crate::assets::animation::load_animation_manifest;
|
||||
use crate::assets::operators::{
|
||||
apply_material_operator, apply_texture_operator, place_asset_operator, place_subasset_operator,
|
||||
apply_material_operator, apply_texture_operator, assign_animation_clip_operator,
|
||||
place_asset_operator, place_subasset_operator,
|
||||
};
|
||||
use crate::assets::static_mesh::{
|
||||
load_static_mesh_manifest, material_id_from_label, part_id_from_label,
|
||||
refresh_static_mesh_artifact,
|
||||
};
|
||||
use crate::assets::{
|
||||
asset_cache_key, draw_asset_cell_with, invalidate_on_catalog_refresh, kind_icon,
|
||||
prefetch_folder_thumbnails, AssetThumbnailCache, ThumbnailCacheSnapshot, ThumbnailStudio,
|
||||
prefetch_folder_thumbnails, refresh_model_artifacts, AssetThumbnailCache,
|
||||
ThumbnailCacheSnapshot, ThumbnailStudio,
|
||||
};
|
||||
use crate::ui::helpers::asset_label;
|
||||
use crate::ui::theme::{panel_heading, ACCENT, BORDER, ELEVATED_BG, TEXT, TEXT_DIM, WIDGET_BG};
|
||||
@@ -81,6 +83,7 @@ struct EmbeddedAsset {
|
||||
thumbnail_key: String,
|
||||
mesh_label: Option<String>,
|
||||
material_label: Option<String>,
|
||||
requires_scene_instance: bool,
|
||||
}
|
||||
|
||||
fn fit_width(ui: &egui::Ui, min: f32, max: f32) -> f32 {
|
||||
@@ -343,115 +346,188 @@ fn embedded_assets_for_asset(world: &World, asset: &EditorAsset) -> Vec<Embedded
|
||||
else {
|
||||
return Vec::new();
|
||||
};
|
||||
let Some(manifest_path) = record.import_settings.static_mesh_manifest_path.as_deref() else {
|
||||
return Vec::new();
|
||||
};
|
||||
let Ok(manifest) = load_static_mesh_manifest(manifest_path) else {
|
||||
return Vec::new();
|
||||
};
|
||||
|
||||
let mut embedded = Vec::new();
|
||||
for part in &manifest.parts {
|
||||
let mesh_id = part_effective_id(part);
|
||||
let material_label = part.material_label.clone();
|
||||
embedded.push(EmbeddedAsset {
|
||||
selection: AssetSelection::SubAsset {
|
||||
parent_path: parent_path.clone(),
|
||||
sub_asset_id: mesh_id,
|
||||
let static_manifest = record
|
||||
.import_settings
|
||||
.static_mesh_manifest_path
|
||||
.as_deref()
|
||||
.and_then(|path| load_static_mesh_manifest(path).ok());
|
||||
let skinned_primitives = crate::assets::gltf_skinned_primitive_labels(parent_path.as_str());
|
||||
if let Some(manifest) = static_manifest.as_ref() {
|
||||
for part in &manifest.parts {
|
||||
let mesh_id = part_effective_id(part);
|
||||
let material_label = part.material_label.clone();
|
||||
let requires_scene_instance = skinned_primitives.contains(&part.mesh_label);
|
||||
embedded.push(EmbeddedAsset {
|
||||
selection: AssetSelection::SubAsset {
|
||||
parent_path: parent_path.clone(),
|
||||
sub_asset_id: mesh_id,
|
||||
label: part.name.clone(),
|
||||
kind: AssetSubAssetKind::Mesh,
|
||||
source_path: None,
|
||||
},
|
||||
label: part.name.clone(),
|
||||
kind: AssetSubAssetKind::Mesh,
|
||||
source_path: None,
|
||||
},
|
||||
label: part.name.clone(),
|
||||
kind: AssetSubAssetKind::Mesh,
|
||||
detail: part
|
||||
.source_mesh
|
||||
.clone()
|
||||
.unwrap_or_else(|| part.mesh_label.clone()),
|
||||
texture_path: None,
|
||||
thumbnail_key: subasset_thumbnail_key(
|
||||
parent_path,
|
||||
AssetSubAssetKind::Mesh,
|
||||
&part_effective_id(part),
|
||||
),
|
||||
mesh_label: Some(part.mesh_label.clone()),
|
||||
material_label,
|
||||
});
|
||||
}
|
||||
|
||||
let mut material_ids = HashSet::new();
|
||||
for part in &manifest.parts {
|
||||
let Some(material_id) = part_effective_material_id(part) else {
|
||||
continue;
|
||||
};
|
||||
if !material_ids.insert(material_id.clone()) {
|
||||
continue;
|
||||
detail: if requires_scene_instance {
|
||||
"Skinned | place model or animation clip".to_string()
|
||||
} else {
|
||||
part.source_mesh
|
||||
.clone()
|
||||
.unwrap_or_else(|| part.mesh_label.clone())
|
||||
},
|
||||
texture_path: None,
|
||||
thumbnail_key: subasset_thumbnail_key(
|
||||
parent_path,
|
||||
AssetSubAssetKind::Mesh,
|
||||
&part_effective_id(part),
|
||||
),
|
||||
mesh_label: Some(part.mesh_label.clone()),
|
||||
material_label,
|
||||
requires_scene_instance,
|
||||
});
|
||||
}
|
||||
let label = if part.material_slot_name.trim().is_empty() {
|
||||
part.material_label
|
||||
.clone()
|
||||
.unwrap_or_else(|| "Source Material".to_string())
|
||||
} else {
|
||||
part.material_slot_name.clone()
|
||||
};
|
||||
embedded.push(EmbeddedAsset {
|
||||
selection: AssetSelection::SubAsset {
|
||||
parent_path: parent_path.clone(),
|
||||
sub_asset_id: material_id,
|
||||
label: label.clone(),
|
||||
|
||||
let mut material_ids = HashSet::new();
|
||||
for part in &manifest.parts {
|
||||
let Some(material_id) = part_effective_material_id(part) else {
|
||||
continue;
|
||||
};
|
||||
if !material_ids.insert(material_id.clone()) {
|
||||
continue;
|
||||
}
|
||||
let label = if part.material_slot_name.trim().is_empty() {
|
||||
part.material_label
|
||||
.clone()
|
||||
.unwrap_or_else(|| "Source Material".to_string())
|
||||
} else {
|
||||
part.material_slot_name.clone()
|
||||
};
|
||||
embedded.push(EmbeddedAsset {
|
||||
selection: AssetSelection::SubAsset {
|
||||
parent_path: parent_path.clone(),
|
||||
sub_asset_id: material_id,
|
||||
label: label.clone(),
|
||||
kind: AssetSubAssetKind::Material,
|
||||
source_path: None,
|
||||
},
|
||||
label,
|
||||
kind: AssetSubAssetKind::Material,
|
||||
source_path: None,
|
||||
},
|
||||
label,
|
||||
kind: AssetSubAssetKind::Material,
|
||||
detail: "Embedded source material".to_string(),
|
||||
texture_path: None,
|
||||
thumbnail_key: subasset_thumbnail_key(
|
||||
parent_path,
|
||||
AssetSubAssetKind::Material,
|
||||
&part_effective_material_id(part).unwrap_or_else(|| {
|
||||
material_id_from_label(
|
||||
part.material_label
|
||||
.as_deref()
|
||||
.unwrap_or(&part.material_slot_name),
|
||||
)
|
||||
}),
|
||||
),
|
||||
mesh_label: None,
|
||||
material_label: part.material_label.clone(),
|
||||
});
|
||||
detail: "Embedded source material".to_string(),
|
||||
texture_path: None,
|
||||
thumbnail_key: subasset_thumbnail_key(
|
||||
parent_path,
|
||||
AssetSubAssetKind::Material,
|
||||
&part_effective_material_id(part).unwrap_or_else(|| {
|
||||
material_id_from_label(
|
||||
part.material_label
|
||||
.as_deref()
|
||||
.unwrap_or(&part.material_slot_name),
|
||||
)
|
||||
}),
|
||||
),
|
||||
mesh_label: None,
|
||||
material_label: part.material_label.clone(),
|
||||
requires_scene_instance: false,
|
||||
});
|
||||
}
|
||||
|
||||
let mut texture_paths = HashSet::new();
|
||||
for dependency in &manifest.source.dependencies {
|
||||
if !is_texture_path(dependency) || !texture_paths.insert(dependency.clone()) {
|
||||
continue;
|
||||
}
|
||||
let label = Path::new(dependency)
|
||||
.file_stem()
|
||||
.and_then(|stem| stem.to_str())
|
||||
.unwrap_or(dependency)
|
||||
.to_string();
|
||||
embedded.push(EmbeddedAsset {
|
||||
selection: AssetSelection::SubAsset {
|
||||
parent_path: parent_path.clone(),
|
||||
sub_asset_id: format!("texture:{}", stable_subasset_slug(dependency)),
|
||||
label: label.clone(),
|
||||
kind: AssetSubAssetKind::Texture,
|
||||
source_path: Some(dependency.clone()),
|
||||
},
|
||||
label,
|
||||
kind: AssetSubAssetKind::Texture,
|
||||
detail: dependency.clone(),
|
||||
texture_path: Some(dependency.clone()),
|
||||
thumbnail_key: subasset_thumbnail_key(
|
||||
parent_path,
|
||||
AssetSubAssetKind::Texture,
|
||||
&stable_subasset_slug(dependency),
|
||||
),
|
||||
mesh_label: None,
|
||||
material_label: None,
|
||||
requires_scene_instance: false,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
let mut texture_paths = HashSet::new();
|
||||
for dependency in &manifest.source.dependencies {
|
||||
if !is_texture_path(dependency) || !texture_paths.insert(dependency.clone()) {
|
||||
continue;
|
||||
let animation_manifest = record
|
||||
.import_settings
|
||||
.animation_manifest_path
|
||||
.as_deref()
|
||||
.and_then(|path| load_animation_manifest(path).ok());
|
||||
if let Some(manifest) = animation_manifest {
|
||||
for skeleton in manifest.skeletons {
|
||||
let signature = skeleton.signature.0;
|
||||
let signature_short = signature.get(..8).unwrap_or(&signature);
|
||||
embedded.push(EmbeddedAsset {
|
||||
selection: AssetSelection::SubAsset {
|
||||
parent_path: parent_path.clone(),
|
||||
sub_asset_id: skeleton.id.clone(),
|
||||
label: skeleton.label.clone(),
|
||||
kind: AssetSubAssetKind::Skeleton,
|
||||
source_path: Some(parent_path.clone()),
|
||||
},
|
||||
label: skeleton.label,
|
||||
kind: AssetSubAssetKind::Skeleton,
|
||||
detail: format!(
|
||||
"{} joints | rig {}",
|
||||
skeleton.joint_paths.len(),
|
||||
signature_short
|
||||
),
|
||||
texture_path: None,
|
||||
thumbnail_key: subasset_thumbnail_key(
|
||||
parent_path,
|
||||
AssetSubAssetKind::Skeleton,
|
||||
&skeleton.id,
|
||||
),
|
||||
mesh_label: None,
|
||||
material_label: None,
|
||||
requires_scene_instance: false,
|
||||
});
|
||||
}
|
||||
for clip in manifest.clips {
|
||||
let event_suffix = if clip.events.is_empty() {
|
||||
String::new()
|
||||
} else {
|
||||
format!(" | {} events", clip.events.len())
|
||||
};
|
||||
embedded.push(EmbeddedAsset {
|
||||
selection: AssetSelection::SubAsset {
|
||||
parent_path: parent_path.clone(),
|
||||
sub_asset_id: clip.id.clone(),
|
||||
label: clip.label.clone(),
|
||||
kind: AssetSubAssetKind::AnimationClip,
|
||||
source_path: Some(parent_path.clone()),
|
||||
},
|
||||
label: clip.label,
|
||||
kind: AssetSubAssetKind::AnimationClip,
|
||||
detail: format!("{:.2}s{event_suffix}", clip.duration_seconds),
|
||||
texture_path: None,
|
||||
thumbnail_key: subasset_thumbnail_key(
|
||||
parent_path,
|
||||
AssetSubAssetKind::AnimationClip,
|
||||
&clip.id,
|
||||
),
|
||||
mesh_label: None,
|
||||
material_label: None,
|
||||
requires_scene_instance: false,
|
||||
});
|
||||
}
|
||||
let label = Path::new(dependency)
|
||||
.file_stem()
|
||||
.and_then(|stem| stem.to_str())
|
||||
.unwrap_or(dependency)
|
||||
.to_string();
|
||||
embedded.push(EmbeddedAsset {
|
||||
selection: AssetSelection::SubAsset {
|
||||
parent_path: parent_path.clone(),
|
||||
sub_asset_id: format!("texture:{}", stable_subasset_slug(dependency)),
|
||||
label: label.clone(),
|
||||
kind: AssetSubAssetKind::Texture,
|
||||
source_path: Some(dependency.clone()),
|
||||
},
|
||||
label,
|
||||
kind: AssetSubAssetKind::Texture,
|
||||
detail: dependency.clone(),
|
||||
texture_path: Some(dependency.clone()),
|
||||
thumbnail_key: subasset_thumbnail_key(
|
||||
parent_path,
|
||||
AssetSubAssetKind::Texture,
|
||||
&stable_subasset_slug(dependency),
|
||||
),
|
||||
mesh_label: None,
|
||||
material_label: None,
|
||||
});
|
||||
}
|
||||
|
||||
embedded
|
||||
@@ -566,6 +642,7 @@ fn asset_toolbar(world: &mut World, ui: &mut egui::Ui) {
|
||||
AssetKindFilter::Material,
|
||||
"Materials",
|
||||
);
|
||||
ui.selectable_value(&mut state.kind_filter, AssetKindFilter::Audio, "Audio");
|
||||
ui.selectable_value(&mut state.kind_filter, AssetKindFilter::Level, "Levels");
|
||||
ui.selectable_value(&mut state.kind_filter, AssetKindFilter::Prefab, "Prefabs");
|
||||
ui.selectable_value(
|
||||
@@ -712,6 +789,9 @@ fn breadcrumb(world: &mut World, ui: &mut egui::Ui, current_folder: &str) {
|
||||
|
||||
fn selection_footer(world: &mut World, ui: &mut egui::Ui, selected_entities: &SelectedEntities) {
|
||||
let selection = world.resource::<EditorAssets>().selected.clone();
|
||||
let selected_embedded = selection
|
||||
.as_ref()
|
||||
.and_then(|selection| embedded_asset_for_selection(world, selection));
|
||||
if let Some(AssetSelection::SubAsset { label, kind, .. }) = selection.clone() {
|
||||
ui.add(
|
||||
egui::Label::new(format!(
|
||||
@@ -723,7 +803,14 @@ fn selection_footer(world: &mut World, ui: &mut egui::Ui, selected_entities: &Se
|
||||
);
|
||||
ui.horizontal_wrapped(|ui| match kind {
|
||||
AssetSubAssetKind::Mesh => {
|
||||
if ui.button("Place At Origin").clicked() {
|
||||
if selected_embedded
|
||||
.as_ref()
|
||||
.is_some_and(|embedded| embedded.requires_scene_instance)
|
||||
{
|
||||
ui.small(
|
||||
egui::RichText::new("Place the model or an animation clip").color(TEXT_DIM),
|
||||
);
|
||||
} else if ui.button("Place At Origin").clicked() {
|
||||
if let Some(selection) = selection.as_ref() {
|
||||
place_subasset_operator(world, selection.clone(), Vec3::ZERO);
|
||||
}
|
||||
@@ -739,6 +826,30 @@ fn selection_footer(world: &mut World, ui: &mut egui::Ui, selected_entities: &Se
|
||||
AssetSubAssetKind::Material => {
|
||||
ui.small(egui::RichText::new("Embedded source material").color(TEXT_DIM));
|
||||
}
|
||||
AssetSubAssetKind::Skeleton => {
|
||||
ui.small(egui::RichText::new("Inspect-only rig metadata").color(TEXT_DIM));
|
||||
}
|
||||
AssetSubAssetKind::AnimationClip => {
|
||||
let animated_actor = selected_entities
|
||||
.as_slice()
|
||||
.iter()
|
||||
.copied()
|
||||
.find(|entity| world.get::<shared::ModelRef>(*entity).is_some());
|
||||
let action = if animated_actor.is_some() {
|
||||
"Assign To Selected Actor"
|
||||
} else {
|
||||
"Create Animated Actor"
|
||||
};
|
||||
if ui.button(action).clicked() {
|
||||
if let Some(selection) = selection.as_ref() {
|
||||
if let Some(entity) = animated_actor {
|
||||
assign_animation_clip_operator(world, selection.clone(), entity);
|
||||
} else {
|
||||
place_subasset_operator(world, selection.clone(), Vec3::ZERO);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
} else if let Some(asset) = world.resource::<EditorAssets>().selected_asset().cloned() {
|
||||
ui.add(egui::Label::new(format!("Selected: {}", asset_label(&asset))).truncate());
|
||||
@@ -753,12 +864,15 @@ fn selection_footer(world: &mut World, ui: &mut egui::Ui, selected_entities: &Se
|
||||
EditorAssetKind::Primitive(_)
|
||||
| EditorAssetKind::Light(_)
|
||||
| EditorAssetKind::Model
|
||||
| EditorAssetKind::AudioClip
|
||||
| EditorAssetKind::Prefab
|
||||
| EditorAssetKind::Level
|
||||
) && ui.button("Place At Origin").clicked()
|
||||
{
|
||||
place_asset_operator(world, asset.clone(), Vec3::ZERO);
|
||||
}
|
||||
if matches!(asset.kind, EditorAssetKind::Level) && ui.button("Open Scene").clicked() {
|
||||
open_level_asset(world, &asset);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
ui.label(egui::RichText::new("No asset selected").color(TEXT_DIM));
|
||||
@@ -1143,6 +1257,7 @@ fn prefetch_embedded_thumbnails(
|
||||
parent_path.clone(),
|
||||
mesh_label,
|
||||
embedded_asset.material_label.clone(),
|
||||
embedded_asset.requires_scene_instance,
|
||||
&mut studio,
|
||||
);
|
||||
}
|
||||
@@ -1167,6 +1282,7 @@ fn prefetch_embedded_thumbnails(
|
||||
&asset_server,
|
||||
);
|
||||
}
|
||||
AssetSubAssetKind::Skeleton | AssetSubAssetKind::AnimationClip => {}
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -1201,6 +1317,13 @@ fn draw_embedded_asset_cell(
|
||||
let thumb_size = thumbnail_size.clamp(44.0, 64.0);
|
||||
let cell_size = egui::vec2(104.0, thumb_size + 50.0);
|
||||
let (rect, response) = ui.allocate_exact_size(cell_size, egui::Sense::click_and_drag());
|
||||
let response = if embedded.requires_scene_instance {
|
||||
response.on_hover_text(
|
||||
"Skinned primitives require their model hierarchy. Place the model or an animation clip instead.",
|
||||
)
|
||||
} else {
|
||||
response
|
||||
};
|
||||
let fill = if selected {
|
||||
crate::ui::theme::SELECTION_BG_MUTED
|
||||
} else if response.hovered() {
|
||||
@@ -1277,7 +1400,10 @@ fn draw_embedded_asset_cell(
|
||||
.resource_mut::<EditorAssets>()
|
||||
.select(embedded.selection.clone());
|
||||
}
|
||||
if response.drag_started() {
|
||||
if response.drag_started()
|
||||
&& embedded.kind != AssetSubAssetKind::Skeleton
|
||||
&& !embedded.requires_scene_instance
|
||||
{
|
||||
world
|
||||
.resource_mut::<EditorAssets>()
|
||||
.start_drag(embedded.selection.clone());
|
||||
@@ -1294,7 +1420,10 @@ fn compact_subasset_label(embedded: &EmbeddedAsset) -> String {
|
||||
.split_once(" / ")
|
||||
.map(|(head, _)| head)
|
||||
.unwrap_or(&embedded.label),
|
||||
AssetSubAssetKind::Material | AssetSubAssetKind::Texture => embedded.label.as_str(),
|
||||
AssetSubAssetKind::Material
|
||||
| AssetSubAssetKind::Texture
|
||||
| AssetSubAssetKind::Skeleton
|
||||
| AssetSubAssetKind::AnimationClip => embedded.label.as_str(),
|
||||
};
|
||||
compact_text(base, 16)
|
||||
}
|
||||
@@ -1339,6 +1468,8 @@ fn subasset_icon(kind: AssetSubAssetKind) -> Icon {
|
||||
AssetSubAssetKind::Mesh => icons::CUBE,
|
||||
AssetSubAssetKind::Material => icons::PALETTE,
|
||||
AssetSubAssetKind::Texture => icons::IMAGE,
|
||||
AssetSubAssetKind::Skeleton => icons::BONE,
|
||||
AssetSubAssetKind::AnimationClip => icons::FILM_STRIP,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1347,6 +1478,8 @@ fn subasset_kind_label(kind: AssetSubAssetKind) -> &'static str {
|
||||
AssetSubAssetKind::Mesh => "Mesh",
|
||||
AssetSubAssetKind::Material => "Material",
|
||||
AssetSubAssetKind::Texture => "Texture",
|
||||
AssetSubAssetKind::Skeleton => "Skeleton",
|
||||
AssetSubAssetKind::AnimationClip => "Animation Clip",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1741,6 +1874,39 @@ fn top_level_asset_details_panel(
|
||||
ui.label(panel_heading("Material"));
|
||||
material_asset_editor(world, ui, asset, path);
|
||||
}
|
||||
if matches!(asset.kind, EditorAssetKind::AudioClip) {
|
||||
detail_row(ui, "Format", audio_format_label(path));
|
||||
let previewing = world
|
||||
.resource::<crate::play::audio_preview::AudioPreviewState>()
|
||||
.clip_path
|
||||
.as_deref()
|
||||
== Some(path);
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
if ui
|
||||
.add_enabled(
|
||||
!previewing,
|
||||
egui::Button::new(format!("{} Audition", icons::PLAY.as_str())),
|
||||
)
|
||||
.clicked()
|
||||
{
|
||||
if let Err(error) =
|
||||
crate::play::audio_preview::audition_audio_asset(world, asset)
|
||||
{
|
||||
world.resource_mut::<SceneIo>().status =
|
||||
format!("Audio audition failed: {error}");
|
||||
}
|
||||
}
|
||||
if ui
|
||||
.add_enabled(
|
||||
previewing,
|
||||
egui::Button::new(format!("{} Stop", icons::STOP.as_str())),
|
||||
)
|
||||
.clicked()
|
||||
{
|
||||
crate::play::audio_preview::stop_audio_preview(world);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
ui.separator();
|
||||
@@ -1804,7 +1970,14 @@ fn subasset_details_panel(
|
||||
ui.separator();
|
||||
match embedded.kind {
|
||||
AssetSubAssetKind::Mesh => {
|
||||
if ui.button("Place At Origin").clicked() {
|
||||
if embedded.requires_scene_instance {
|
||||
ui.small(
|
||||
egui::RichText::new(
|
||||
"This skinned primitive needs its source hierarchy. Place the model or an animation clip instead.",
|
||||
)
|
||||
.color(TEXT_DIM),
|
||||
);
|
||||
} else if ui.button("Place At Origin").clicked() {
|
||||
place_subasset_operator(world, selection.clone(), Vec3::ZERO);
|
||||
}
|
||||
}
|
||||
@@ -1825,6 +1998,31 @@ fn subasset_details_panel(
|
||||
.color(TEXT_DIM),
|
||||
);
|
||||
}
|
||||
AssetSubAssetKind::Skeleton => {
|
||||
ui.small(
|
||||
egui::RichText::new("Skeleton metadata is generated from the model source.")
|
||||
.color(TEXT_DIM),
|
||||
);
|
||||
}
|
||||
AssetSubAssetKind::AnimationClip => {
|
||||
let animated_actor = selected_entities
|
||||
.as_slice()
|
||||
.iter()
|
||||
.copied()
|
||||
.find(|entity| world.get::<shared::ModelRef>(*entity).is_some());
|
||||
let action = if animated_actor.is_some() {
|
||||
"Assign To Selected Actor"
|
||||
} else {
|
||||
"Create Animated Actor"
|
||||
};
|
||||
if ui.button(action).clicked() {
|
||||
if let Some(entity) = animated_actor {
|
||||
assign_animation_clip_operator(world, selection.clone(), entity);
|
||||
} else {
|
||||
place_subasset_operator(world, selection.clone(), Vec3::ZERO);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ui.button("Select Parent Asset").clicked() {
|
||||
world
|
||||
@@ -1852,12 +2050,15 @@ fn asset_action_buttons(
|
||||
EditorAssetKind::Primitive(_)
|
||||
| EditorAssetKind::Light(_)
|
||||
| EditorAssetKind::Model
|
||||
| EditorAssetKind::AudioClip
|
||||
| EditorAssetKind::Prefab
|
||||
| EditorAssetKind::Level
|
||||
) && ui.button("Place At Origin").clicked()
|
||||
{
|
||||
place_asset_operator(world, asset.clone(), Vec3::ZERO);
|
||||
}
|
||||
if matches!(asset.kind, EditorAssetKind::Level) && ui.button("Open Scene").clicked() {
|
||||
open_level_asset(world, asset);
|
||||
}
|
||||
if matches!(asset.kind, EditorAssetKind::Model)
|
||||
&& has_embedded_assets(world, asset)
|
||||
&& ui.button("Toggle Contents").clicked()
|
||||
@@ -1875,6 +2076,13 @@ fn asset_action_buttons(
|
||||
});
|
||||
}
|
||||
|
||||
fn open_level_asset(world: &mut World, asset: &EditorAsset) {
|
||||
let Some(path) = asset.path.as_deref() else {
|
||||
return;
|
||||
};
|
||||
world.resource_mut::<SceneIo>().request = Some(SceneIoRequest::OpenPath(PathBuf::from(path)));
|
||||
}
|
||||
|
||||
fn import_settings_editor(
|
||||
world: &mut World,
|
||||
ui: &mut egui::Ui,
|
||||
@@ -1989,8 +2197,8 @@ fn apply_import_settings(
|
||||
update_import_settings(&mut registry, path, settings);
|
||||
if matches!(asset.kind, EditorAssetKind::Model) {
|
||||
if let Some(record) = find_asset_mut_by_path(&mut registry, path) {
|
||||
if let Err(error) = refresh_static_mesh_artifact(record) {
|
||||
status = format!("Static mesh refresh failed for {}: {error}", asset.label);
|
||||
if let Err(error) = refresh_model_artifacts(record) {
|
||||
status = format!("Model artifact refresh failed for {}: {error}", asset.label);
|
||||
warn!("{status}");
|
||||
}
|
||||
}
|
||||
@@ -2705,6 +2913,7 @@ fn asset_matches_kind_filter(asset: &EditorAsset, filter: AssetKindFilter) -> bo
|
||||
AssetKindFilter::Model => matches!(asset.kind, EditorAssetKind::Model),
|
||||
AssetKindFilter::Texture => matches!(asset.kind, EditorAssetKind::Texture),
|
||||
AssetKindFilter::Material => matches!(asset.kind, EditorAssetKind::Material),
|
||||
AssetKindFilter::Audio => matches!(asset.kind, EditorAssetKind::AudioClip),
|
||||
AssetKindFilter::Level => matches!(asset.kind, EditorAssetKind::Level),
|
||||
AssetKindFilter::Prefab => matches!(asset.kind, EditorAssetKind::Prefab),
|
||||
AssetKindFilter::Builtin => asset.path.is_none(),
|
||||
@@ -2717,6 +2926,7 @@ fn kind_filter_label(filter: AssetKindFilter) -> &'static str {
|
||||
AssetKindFilter::Model => "Models",
|
||||
AssetKindFilter::Texture => "Textures",
|
||||
AssetKindFilter::Material => "Materials",
|
||||
AssetKindFilter::Audio => "Audio",
|
||||
AssetKindFilter::Level => "Levels",
|
||||
AssetKindFilter::Prefab => "Prefabs",
|
||||
AssetKindFilter::Builtin => "Built-ins",
|
||||
@@ -2739,6 +2949,7 @@ fn kind_label(kind: &EditorAssetKind) -> &'static str {
|
||||
EditorAssetKind::Model => "Model",
|
||||
EditorAssetKind::Texture => "Texture",
|
||||
EditorAssetKind::Material => "Material",
|
||||
EditorAssetKind::AudioClip => "Audio Clip",
|
||||
EditorAssetKind::Level => "Level",
|
||||
EditorAssetKind::Prefab => "Prefab",
|
||||
EditorAssetKind::PostProcessVolume => "Post Process Volume",
|
||||
@@ -2752,6 +2963,22 @@ fn file_size(path: &str) -> Option<u64> {
|
||||
fs::metadata(path).ok().map(|metadata| metadata.len())
|
||||
}
|
||||
|
||||
fn audio_format_label(path: &str) -> &'static str {
|
||||
match Path::new(path)
|
||||
.extension()
|
||||
.and_then(|extension| extension.to_str())
|
||||
.map(str::to_ascii_lowercase)
|
||||
.as_deref()
|
||||
{
|
||||
Some("ogg" | "oga") => "Ogg audio",
|
||||
Some("spx") => "Speex",
|
||||
Some("wav") => "WAV",
|
||||
Some("mp3") => "MP3",
|
||||
Some("flac") => "FLAC",
|
||||
_ => "Unknown",
|
||||
}
|
||||
}
|
||||
|
||||
fn modified_time(path: &str) -> Option<SystemTime> {
|
||||
fs::metadata(path)
|
||||
.ok()
|
||||
@@ -2813,13 +3040,17 @@ fn asset_context_menu(
|
||||
EditorAssetKind::Primitive(_)
|
||||
| EditorAssetKind::Light(_)
|
||||
| EditorAssetKind::Model
|
||||
| EditorAssetKind::AudioClip
|
||||
| EditorAssetKind::Prefab
|
||||
| EditorAssetKind::Level
|
||||
) && ui.button("Place at Origin").clicked()
|
||||
{
|
||||
place_asset_operator(world, asset.clone(), Vec3::ZERO);
|
||||
ui.close();
|
||||
}
|
||||
if matches!(asset.kind, EditorAssetKind::Level) && ui.button("Open Scene").clicked() {
|
||||
open_level_asset(world, asset);
|
||||
ui.close();
|
||||
}
|
||||
if matches!(asset.kind, EditorAssetKind::Model) && has_embedded_assets(world, asset) {
|
||||
let expanded = asset.path.as_deref().is_some_and(|path| {
|
||||
world
|
||||
@@ -2888,7 +3119,12 @@ fn subasset_context_menu(
|
||||
}
|
||||
match embedded.kind {
|
||||
AssetSubAssetKind::Mesh => {
|
||||
if ui.button("Place at Origin").clicked() {
|
||||
if embedded.requires_scene_instance {
|
||||
ui.label(
|
||||
egui::RichText::new("Skinned mesh: place parent model or animation clip")
|
||||
.color(TEXT_DIM),
|
||||
);
|
||||
} else if ui.button("Place at Origin").clicked() {
|
||||
place_subasset_operator(world, embedded.selection.clone(), Vec3::ZERO);
|
||||
ui.close();
|
||||
}
|
||||
@@ -2906,8 +3142,35 @@ fn subasset_context_menu(
|
||||
AssetSubAssetKind::Material => {
|
||||
ui.label(egui::RichText::new("Embedded source material").color(TEXT_DIM));
|
||||
}
|
||||
AssetSubAssetKind::Skeleton => {
|
||||
ui.label(egui::RichText::new("Inspect-only rig metadata").color(TEXT_DIM));
|
||||
}
|
||||
AssetSubAssetKind::AnimationClip => {
|
||||
let animated_actor = selected_entities
|
||||
.as_slice()
|
||||
.iter()
|
||||
.copied()
|
||||
.find(|entity| world.get::<shared::ModelRef>(*entity).is_some());
|
||||
let action = if animated_actor.is_some() {
|
||||
"Assign To Selected Actor"
|
||||
} else {
|
||||
"Create Animated Actor"
|
||||
};
|
||||
if ui.button(action).clicked() {
|
||||
if let Some(entity) = animated_actor {
|
||||
assign_animation_clip_operator(world, embedded.selection.clone(), entity);
|
||||
} else {
|
||||
place_subasset_operator(world, embedded.selection.clone(), Vec3::ZERO);
|
||||
}
|
||||
ui.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
if ui.button("Regenerate Thumbnail").clicked() {
|
||||
if matches!(
|
||||
embedded.kind,
|
||||
AssetSubAssetKind::Mesh | AssetSubAssetKind::Material | AssetSubAssetKind::Texture
|
||||
) && ui.button("Regenerate Thumbnail").clicked()
|
||||
{
|
||||
regenerate_subasset_thumbnail(world, embedded);
|
||||
ui.close();
|
||||
}
|
||||
@@ -2969,6 +3232,7 @@ fn regenerate_subasset_thumbnail(world: &mut World, embedded: &EmbeddedAsset) {
|
||||
parent_path.clone(),
|
||||
mesh_label,
|
||||
embedded.material_label.clone(),
|
||||
embedded.requires_scene_instance,
|
||||
&mut studio,
|
||||
);
|
||||
});
|
||||
@@ -2991,6 +3255,7 @@ fn regenerate_subasset_thumbnail(world: &mut World, embedded: &EmbeddedAsset) {
|
||||
cache.request_texture(key.clone(), texture_path, &asset_server);
|
||||
}
|
||||
}
|
||||
AssetSubAssetKind::Skeleton | AssetSubAssetKind::AnimationClip => {}
|
||||
}
|
||||
});
|
||||
world.resource_mut::<SceneIo>().status =
|
||||
@@ -3004,7 +3269,7 @@ fn reimport_asset(world: &mut World, asset: &EditorAsset) {
|
||||
let mut status = format!("Reimported {}", asset.label);
|
||||
if let Some(mut registry) = world.get_resource_mut::<crate::asset_db::AssetRegistry>() {
|
||||
if let Some(record) = find_asset_mut_by_path(&mut registry, path) {
|
||||
if let Err(error) = refresh_static_mesh_artifact(record) {
|
||||
if let Err(error) = refresh_model_artifacts(record) {
|
||||
status = format!("Reimport failed for {}: {error}", asset.label);
|
||||
warn!("{status}");
|
||||
}
|
||||
@@ -3038,6 +3303,9 @@ fn build_delete_request(world: &World, asset: &EditorAsset) -> Option<AssetDelet
|
||||
if let Some(manifest) = record.import_settings.static_mesh_manifest_path {
|
||||
files.push(manifest);
|
||||
}
|
||||
if let Some(manifest) = record.import_settings.animation_manifest_path {
|
||||
files.push(manifest);
|
||||
}
|
||||
if !record.dependencies.is_empty() {
|
||||
warnings.push(format!(
|
||||
"{} imported dependencies will be kept because they may be shared.",
|
||||
@@ -3190,3 +3458,35 @@ fn dedup_strings(values: &mut Vec<String>) {
|
||||
let mut seen = HashSet::new();
|
||||
values.retain(|value| seen.insert(value.clone()));
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn audio_filter_matches_only_audio_clips() {
|
||||
let audio = EditorAsset {
|
||||
label: "Impact".into(),
|
||||
path: Some("assets/audio/impact.ogg".into()),
|
||||
folder_path: "assets/audio".into(),
|
||||
kind: EditorAssetKind::AudioClip,
|
||||
};
|
||||
let texture = EditorAsset {
|
||||
kind: EditorAssetKind::Texture,
|
||||
..audio.clone()
|
||||
};
|
||||
|
||||
assert!(asset_matches_kind_filter(&audio, AssetKindFilter::Audio));
|
||||
assert!(!asset_matches_kind_filter(&texture, AssetKindFilter::Audio));
|
||||
assert_eq!(kind_filter_label(AssetKindFilter::Audio), "Audio");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn audio_details_label_supported_formats() {
|
||||
assert_eq!(audio_format_label("assets/audio/music.oga"), "Ogg audio");
|
||||
assert_eq!(audio_format_label("assets/audio/voice.spx"), "Speex");
|
||||
assert_eq!(audio_format_label("assets/audio/source.WAV"), "WAV");
|
||||
assert_eq!(audio_format_label("assets/audio/source.mp3"), "MP3");
|
||||
assert_eq!(audio_format_label("assets/audio/source.flac"), "FLAC");
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,7 @@ pub(crate) enum AssetKindFilter {
|
||||
Model,
|
||||
Texture,
|
||||
Material,
|
||||
Audio,
|
||||
Level,
|
||||
Prefab,
|
||||
Builtin,
|
||||
|
||||
@@ -0,0 +1,283 @@
|
||||
//! Audio source/listener authoring cards and transient audition controls.
|
||||
|
||||
use bevy::prelude::*;
|
||||
use bevy_egui::egui;
|
||||
use egui_phosphor_icons::icons;
|
||||
use settings::{AUDIO_GAIN_DB_MAX, AUDIO_GAIN_DB_MIN};
|
||||
use shared::{
|
||||
AudioListenerDesc, AudioRolloff, AudioSourceDesc, COMPONENT_AUDIO_LISTENER_DESC,
|
||||
COMPONENT_AUDIO_SOURCE_DESC,
|
||||
};
|
||||
|
||||
use crate::assets::{audio_clip_ref_for_asset, EditorAsset, EditorAssetKind, EditorAssets};
|
||||
use crate::history::{set_audio_listener_with_history, set_audio_source_with_history};
|
||||
use crate::play::audio_preview::{audition_audio_source, stop_audio_preview, AudioPreviewState};
|
||||
use crate::ui::inspector::{
|
||||
apply_component_card_response, component_card, component_card_context, property_row,
|
||||
ComponentCardOptions,
|
||||
};
|
||||
use crate::ui::theme::{SELECTION, TEXT_DIM};
|
||||
|
||||
pub fn audio_source_inspector_ui(world: &mut World, ui: &mut egui::Ui, entity: Entity) {
|
||||
let Some(mut source) = world.get::<AudioSourceDesc>(entity).cloned() else {
|
||||
return;
|
||||
};
|
||||
let original = source.clone();
|
||||
let audio_assets: Vec<EditorAsset> = world
|
||||
.resource::<EditorAssets>()
|
||||
.assets
|
||||
.iter()
|
||||
.filter(|asset| matches!(asset.kind, EditorAssetKind::AudioClip))
|
||||
.cloned()
|
||||
.collect();
|
||||
let dragged_audio = world
|
||||
.resource::<EditorAssets>()
|
||||
.dragging_selection()
|
||||
.and_then(|selection| {
|
||||
world
|
||||
.resource::<EditorAssets>()
|
||||
.asset_for_selection(selection)
|
||||
})
|
||||
.filter(|asset| matches!(asset.kind, EditorAssetKind::AudioClip))
|
||||
.cloned();
|
||||
let buses = world
|
||||
.resource::<settings::ProjectSettings>()
|
||||
.audio
|
||||
.buses
|
||||
.clone();
|
||||
let previewing = world.resource::<AudioPreviewState>().source == Some(entity);
|
||||
let diagnostics = world
|
||||
.resource::<game::audio::AudioRuntimeDiagnostics>()
|
||||
.clone();
|
||||
let mut pending_clip: Option<EditorAsset> = None;
|
||||
let mut clear_clip = false;
|
||||
let mut audition = false;
|
||||
let mut stop = false;
|
||||
|
||||
let card = component_card_context(
|
||||
world,
|
||||
entity,
|
||||
ComponentCardOptions::removable(
|
||||
COMPONENT_AUDIO_SOURCE_DESC,
|
||||
"Audio Source",
|
||||
icons::SPEAKER_HIGH,
|
||||
),
|
||||
);
|
||||
let card_response = component_card(ui, &card, |ui| {
|
||||
let clip_response = property_row(ui, "Clip", |ui| {
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
let selected_text = source
|
||||
.clip
|
||||
.as_ref()
|
||||
.map(|clip| clip.label.as_str())
|
||||
.filter(|label| !label.trim().is_empty())
|
||||
.unwrap_or("None");
|
||||
egui::ComboBox::from_id_salt(("audio_clip", entity))
|
||||
.selected_text(selected_text)
|
||||
.width(150.0)
|
||||
.show_ui(ui, |ui| {
|
||||
for asset in &audio_assets {
|
||||
let selected = source.clip.as_ref().is_some_and(|clip| {
|
||||
clip.source_path.as_deref() == asset.path.as_deref()
|
||||
});
|
||||
if ui.selectable_label(selected, &asset.label).clicked() {
|
||||
pending_clip = Some(asset.clone());
|
||||
}
|
||||
}
|
||||
});
|
||||
if ui
|
||||
.add_enabled(source.clip.is_some(), egui::Button::new(icons::X.as_str()))
|
||||
.on_hover_text("Clear clip")
|
||||
.clicked()
|
||||
{
|
||||
clear_clip = true;
|
||||
}
|
||||
})
|
||||
.response
|
||||
});
|
||||
if dragged_audio.is_some() && clip_response.hovered() {
|
||||
ui.painter().rect_stroke(
|
||||
clip_response.rect.expand(3.0),
|
||||
3.0,
|
||||
egui::Stroke::new(1.5, SELECTION),
|
||||
egui::StrokeKind::Outside,
|
||||
);
|
||||
if ui.input(|input| input.pointer.any_released()) {
|
||||
pending_clip = dragged_audio.clone();
|
||||
}
|
||||
}
|
||||
|
||||
property_row(ui, "Playback", |ui| {
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
if ui
|
||||
.add_enabled(
|
||||
source.clip.is_some() && !previewing,
|
||||
egui::Button::new(format!("{} Audition", icons::PLAY.as_str())),
|
||||
)
|
||||
.clicked()
|
||||
{
|
||||
audition = true;
|
||||
}
|
||||
if ui
|
||||
.add_enabled(
|
||||
previewing,
|
||||
egui::Button::new(format!("{} Stop", icons::STOP.as_str())),
|
||||
)
|
||||
.clicked()
|
||||
{
|
||||
stop = true;
|
||||
}
|
||||
});
|
||||
});
|
||||
property_row(ui, "Gain", |ui| {
|
||||
ui.add(
|
||||
egui::Slider::new(&mut source.gain_db, AUDIO_GAIN_DB_MIN..=AUDIO_GAIN_DB_MAX)
|
||||
.suffix(" dB"),
|
||||
);
|
||||
});
|
||||
property_row(ui, "Pitch", |ui| {
|
||||
ui.add(
|
||||
egui::DragValue::new(&mut source.pitch)
|
||||
.range(0.25..=4.0)
|
||||
.speed(0.01),
|
||||
);
|
||||
});
|
||||
property_row(ui, "Mode", |ui| {
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.checkbox(&mut source.autoplay, "Autoplay");
|
||||
ui.checkbox(&mut source.looping, "Loop");
|
||||
});
|
||||
});
|
||||
property_row(ui, "Spatial blend", |ui| {
|
||||
ui.add(egui::Slider::new(&mut source.spatial_blend, 0.0..=1.0));
|
||||
});
|
||||
property_row(ui, "Min distance", |ui| {
|
||||
ui.add(
|
||||
egui::DragValue::new(&mut source.attenuation.min_distance)
|
||||
.range(0.01..=10_000.0)
|
||||
.speed(0.1)
|
||||
.suffix(" m"),
|
||||
);
|
||||
});
|
||||
property_row(ui, "Max distance", |ui| {
|
||||
ui.add(
|
||||
egui::DragValue::new(&mut source.attenuation.max_distance)
|
||||
.range(0.02..=100_000.0)
|
||||
.speed(0.25)
|
||||
.suffix(" m"),
|
||||
);
|
||||
});
|
||||
property_row(ui, "Rolloff", |ui| {
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
egui::ComboBox::from_id_salt(("audio_rolloff", entity))
|
||||
.selected_text(format!("{:?}", source.attenuation.rolloff))
|
||||
.show_ui(ui, |ui| {
|
||||
for (rolloff, label) in [
|
||||
(AudioRolloff::Linear, "Linear"),
|
||||
(AudioRolloff::Inverse, "Inverse"),
|
||||
(AudioRolloff::Exponential, "Exponential"),
|
||||
] {
|
||||
ui.selectable_value(&mut source.attenuation.rolloff, rolloff, label);
|
||||
}
|
||||
});
|
||||
ui.add(
|
||||
egui::DragValue::new(&mut source.attenuation.rolloff_factor)
|
||||
.range(0.01..=8.0)
|
||||
.speed(0.05),
|
||||
);
|
||||
});
|
||||
});
|
||||
property_row(ui, "Bus", |ui| {
|
||||
egui::ComboBox::from_id_salt(("audio_bus", entity))
|
||||
.selected_text(
|
||||
buses
|
||||
.iter()
|
||||
.find(|bus| bus.id == source.bus)
|
||||
.map(|bus| bus.label.as_str())
|
||||
.unwrap_or(source.bus.as_str()),
|
||||
)
|
||||
.show_ui(ui, |ui| {
|
||||
for bus in &buses {
|
||||
ui.selectable_value(&mut source.bus, bus.id.clone(), &bus.label);
|
||||
}
|
||||
});
|
||||
});
|
||||
ui.small(
|
||||
egui::RichText::new(&diagnostics.message)
|
||||
.color(TEXT_DIM)
|
||||
.italics(),
|
||||
);
|
||||
});
|
||||
|
||||
if clear_clip {
|
||||
source.clip = None;
|
||||
}
|
||||
if let Some(asset) = pending_clip {
|
||||
match audio_clip_ref_for_asset(world, &asset) {
|
||||
Ok(clip) => {
|
||||
source.clip = Some(clip);
|
||||
world.resource_mut::<EditorAssets>().clear_drag();
|
||||
}
|
||||
Err(error) => {
|
||||
world.resource_mut::<crate::scene_io::SceneIo>().status =
|
||||
format!("Audio clip assignment failed: {error}");
|
||||
}
|
||||
}
|
||||
}
|
||||
source.attenuation.max_distance = source
|
||||
.attenuation
|
||||
.max_distance
|
||||
.max(source.attenuation.min_distance + 0.01);
|
||||
if source != original {
|
||||
set_audio_source_with_history(world, entity, source);
|
||||
}
|
||||
if stop {
|
||||
stop_audio_preview(world);
|
||||
} else if audition {
|
||||
if let Err(error) = audition_audio_source(world, entity) {
|
||||
world.resource_mut::<crate::scene_io::SceneIo>().status =
|
||||
format!("Audio audition failed: {error}");
|
||||
}
|
||||
}
|
||||
apply_component_card_response(world, entity, card_response);
|
||||
}
|
||||
|
||||
pub fn audio_listener_inspector_ui(world: &mut World, ui: &mut egui::Ui, entity: Entity) {
|
||||
let Some(mut listener) = world.get::<AudioListenerDesc>(entity).copied() else {
|
||||
return;
|
||||
};
|
||||
let original = listener;
|
||||
let card = component_card_context(
|
||||
world,
|
||||
entity,
|
||||
ComponentCardOptions::removable(
|
||||
COMPONENT_AUDIO_LISTENER_DESC,
|
||||
"Audio Listener",
|
||||
icons::HEADPHONES,
|
||||
),
|
||||
);
|
||||
let card_response = component_card(ui, &card, |ui| {
|
||||
property_row(ui, "Enabled", |ui| {
|
||||
ui.checkbox(&mut listener.enabled, "Receive spatial audio");
|
||||
});
|
||||
property_row(ui, "Priority", |ui| {
|
||||
ui.add(egui::DragValue::new(&mut listener.priority).speed(1));
|
||||
});
|
||||
property_row(ui, "Ear gap", |ui| {
|
||||
ui.add(
|
||||
egui::DragValue::new(&mut listener.ear_gap)
|
||||
.range(0.01..=2.0)
|
||||
.speed(0.01)
|
||||
.suffix(" m"),
|
||||
);
|
||||
});
|
||||
ui.small(
|
||||
egui::RichText::new("Highest priority enabled listener wins; actor ID breaks ties.")
|
||||
.color(TEXT_DIM),
|
||||
);
|
||||
});
|
||||
if listener != original {
|
||||
set_audio_listener_with_history(world, entity, listener);
|
||||
}
|
||||
apply_component_card_response(world, entity, card_response);
|
||||
}
|
||||
@@ -0,0 +1,619 @@
|
||||
//! Non-blocking build/package jobs backed by the headless package command.
|
||||
|
||||
use std::collections::VecDeque;
|
||||
use std::io::{BufRead, BufReader};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::{Command, Stdio};
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::time::Duration;
|
||||
|
||||
use bevy::prelude::*;
|
||||
use bevy_egui::egui;
|
||||
use egui_phosphor_icons::icons;
|
||||
|
||||
use crate::project_io::ProjectWorkspace;
|
||||
use crate::scene_io::SceneIo;
|
||||
|
||||
const MAX_LOG_LINES: usize = 1_500;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
enum BuildResult {
|
||||
Succeeded(PathBuf),
|
||||
Failed(String),
|
||||
Cancelled,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct BuildJob {
|
||||
log: Arc<Mutex<VecDeque<String>>>,
|
||||
result: Arc<Mutex<Option<BuildResult>>>,
|
||||
cancel: Arc<AtomicBool>,
|
||||
run_after: bool,
|
||||
worker: Option<std::thread::JoinHandle<()>>,
|
||||
}
|
||||
|
||||
impl Drop for BuildJob {
|
||||
fn drop(&mut self) {
|
||||
self.cancel.store(true, Ordering::Release);
|
||||
if let Some(worker) = self.worker.take() {
|
||||
let _ = worker.join();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Resource, Debug)]
|
||||
pub struct BuildPanel {
|
||||
profiles: Vec<String>,
|
||||
selected_profile: String,
|
||||
job: Option<BuildJob>,
|
||||
last_result: Option<BuildResult>,
|
||||
last_output: Option<PathBuf>,
|
||||
last_log: Vec<String>,
|
||||
}
|
||||
|
||||
impl Default for BuildPanel {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
profiles: Vec::new(),
|
||||
selected_profile: "development".into(),
|
||||
job: None,
|
||||
last_result: None,
|
||||
last_output: None,
|
||||
last_log: Vec::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl BuildPanel {
|
||||
pub fn is_running(&self) -> bool {
|
||||
self.job.is_some()
|
||||
}
|
||||
|
||||
pub fn has_output(&self) -> bool {
|
||||
self.last_output.is_some()
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for BuildPanel {
|
||||
fn drop(&mut self) {
|
||||
if let Some(job) = &self.job {
|
||||
job.cancel.store(true, Ordering::Release);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn request_build(world: &mut World, run_after: bool) {
|
||||
refresh_profiles(world);
|
||||
if world.resource::<BuildPanel>().is_running() {
|
||||
world
|
||||
.resource_mut::<SceneIo>()
|
||||
.set_status("A package build is already running");
|
||||
return;
|
||||
}
|
||||
if world.resource::<SceneIo>().has_unsaved_tabs() {
|
||||
world
|
||||
.resource_mut::<SceneIo>()
|
||||
.set_status("Save all modified scene tabs before building a package");
|
||||
return;
|
||||
}
|
||||
let engine_root = engine_workspace_root();
|
||||
let root = PathBuf::from(&world.resource::<ProjectWorkspace>().root);
|
||||
let profile = world.resource::<BuildPanel>().selected_profile.clone();
|
||||
let mut panel = world.resource_mut::<BuildPanel>();
|
||||
panel.last_result = None;
|
||||
panel.last_log.clear();
|
||||
panel.job = Some(spawn_build_job(
|
||||
engine_root,
|
||||
root,
|
||||
profile.clone(),
|
||||
run_after,
|
||||
));
|
||||
world
|
||||
.resource_mut::<SceneIo>()
|
||||
.set_status(format!("Building {profile} package..."));
|
||||
}
|
||||
|
||||
pub fn cancel_build(world: &mut World) {
|
||||
if let Some(job) = world.resource::<BuildPanel>().job.as_ref() {
|
||||
job.cancel.store(true, Ordering::Release);
|
||||
world
|
||||
.resource_mut::<SceneIo>()
|
||||
.set_status("Cancelling package build...");
|
||||
}
|
||||
}
|
||||
|
||||
pub fn reveal_last_output(world: &mut World) {
|
||||
let output = world.resource::<BuildPanel>().last_output.clone();
|
||||
let status = match output {
|
||||
Some(path) if path.is_dir() => match Command::new("xdg-open").arg(&path).spawn() {
|
||||
Ok(child) => {
|
||||
reap_child(child);
|
||||
format!("Revealed {}", path.display())
|
||||
}
|
||||
Err(error) => format!("Could not reveal {}: {error}", path.display()),
|
||||
},
|
||||
_ => "No completed package output is available".into(),
|
||||
};
|
||||
world.resource_mut::<SceneIo>().set_status(status);
|
||||
}
|
||||
|
||||
pub fn tick_build_job(world: &mut World) {
|
||||
let completed = world.resource::<BuildPanel>().job.as_ref().and_then(|job| {
|
||||
job.result
|
||||
.lock()
|
||||
.ok()?
|
||||
.clone()
|
||||
.map(|result| (result, job.run_after))
|
||||
});
|
||||
let Some((result, run_after)) = completed else {
|
||||
return;
|
||||
};
|
||||
let status = match &result {
|
||||
BuildResult::Succeeded(path) => {
|
||||
world.resource_mut::<BuildPanel>().last_output = Some(path.clone());
|
||||
if run_after {
|
||||
launch_package(path)
|
||||
.map(|_| format!("Package built and launched from {}", path.display()))
|
||||
.unwrap_or_else(|error| error)
|
||||
} else {
|
||||
format!("Package ready at {}", path.display())
|
||||
}
|
||||
}
|
||||
BuildResult::Failed(error) => format!("Package build failed: {error}"),
|
||||
BuildResult::Cancelled => "Package build cancelled".into(),
|
||||
};
|
||||
let completed_log = world
|
||||
.resource::<BuildPanel>()
|
||||
.job
|
||||
.as_ref()
|
||||
.and_then(|job| {
|
||||
job.log
|
||||
.lock()
|
||||
.ok()
|
||||
.map(|log| log.iter().cloned().collect::<Vec<_>>())
|
||||
})
|
||||
.unwrap_or_default();
|
||||
let mut panel = world.resource_mut::<BuildPanel>();
|
||||
panel.last_result = Some(result);
|
||||
panel.last_log = completed_log;
|
||||
panel.job = None;
|
||||
world.resource_mut::<SceneIo>().set_status(status);
|
||||
}
|
||||
|
||||
pub fn build_ui(world: &mut World, ui: &mut egui::Ui) {
|
||||
if world.resource::<BuildPanel>().profiles.is_empty() {
|
||||
refresh_profiles(world);
|
||||
}
|
||||
let running = world.resource::<BuildPanel>().is_running();
|
||||
let profiles = world.resource::<BuildPanel>().profiles.clone();
|
||||
let mut selected = world.resource::<BuildPanel>().selected_profile.clone();
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Profile");
|
||||
egui::ComboBox::from_id_salt("build_profile")
|
||||
.selected_text(&selected)
|
||||
.show_ui(ui, |ui| {
|
||||
for profile in &profiles {
|
||||
ui.selectable_value(&mut selected, profile.clone(), profile);
|
||||
}
|
||||
});
|
||||
if ui
|
||||
.add_enabled(
|
||||
!running,
|
||||
egui::Button::new(format!("{} Build", icons::HAMMER.as_str())),
|
||||
)
|
||||
.clicked()
|
||||
{
|
||||
world.resource_mut::<BuildPanel>().selected_profile = selected.clone();
|
||||
request_build(world, false);
|
||||
}
|
||||
if ui
|
||||
.add_enabled(
|
||||
!running,
|
||||
egui::Button::new(format!("{} Build and Run", icons::PLAY.as_str())),
|
||||
)
|
||||
.clicked()
|
||||
{
|
||||
world.resource_mut::<BuildPanel>().selected_profile = selected.clone();
|
||||
request_build(world, true);
|
||||
}
|
||||
if ui
|
||||
.add_enabled(
|
||||
running,
|
||||
egui::Button::new(format!("{} Cancel", icons::X.as_str())),
|
||||
)
|
||||
.clicked()
|
||||
{
|
||||
cancel_build(world);
|
||||
}
|
||||
let can_reveal = world.resource::<BuildPanel>().last_output.is_some();
|
||||
if ui
|
||||
.add_enabled(
|
||||
can_reveal,
|
||||
egui::Button::new(format!("{} Reveal Output", icons::FOLDER_OPEN.as_str())),
|
||||
)
|
||||
.clicked()
|
||||
{
|
||||
reveal_last_output(world);
|
||||
}
|
||||
});
|
||||
world.resource_mut::<BuildPanel>().selected_profile = selected;
|
||||
ui.separator();
|
||||
if running {
|
||||
ui.horizontal(|ui| {
|
||||
ui.spinner();
|
||||
ui.label("Compiler and packager are running in the background");
|
||||
});
|
||||
} else if let Some(result) = world.resource::<BuildPanel>().last_result.clone() {
|
||||
let (label, color) = match result {
|
||||
BuildResult::Succeeded(path) => (
|
||||
format!("Ready: {}", path.display()),
|
||||
egui::Color32::from_rgb(125, 210, 145),
|
||||
),
|
||||
BuildResult::Failed(error) => (
|
||||
format!("Failed: {error}"),
|
||||
egui::Color32::from_rgb(255, 137, 129),
|
||||
),
|
||||
BuildResult::Cancelled => ("Cancelled".into(), egui::Color32::from_rgb(255, 190, 110)),
|
||||
};
|
||||
ui.colored_label(color, label);
|
||||
} else {
|
||||
ui.label("No package build has run in this session");
|
||||
}
|
||||
let lines = {
|
||||
let panel = world.resource::<BuildPanel>();
|
||||
panel
|
||||
.job
|
||||
.as_ref()
|
||||
.and_then(|job| {
|
||||
job.log
|
||||
.lock()
|
||||
.ok()
|
||||
.map(|log| log.iter().cloned().collect::<Vec<_>>())
|
||||
})
|
||||
.unwrap_or_else(|| panel.last_log.clone())
|
||||
};
|
||||
egui::ScrollArea::vertical()
|
||||
.id_salt("build_output_log")
|
||||
.stick_to_bottom(true)
|
||||
.show(ui, |ui| {
|
||||
for line in lines {
|
||||
ui.monospace(line);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn refresh_profiles(world: &mut World) {
|
||||
let root = PathBuf::from(&world.resource::<ProjectWorkspace>().root);
|
||||
let mut profiles = fs_profiles(&root.join("assets/build_profiles"));
|
||||
if profiles.is_empty() {
|
||||
profiles.push("development".into());
|
||||
}
|
||||
let mut panel = world.resource_mut::<BuildPanel>();
|
||||
if !profiles.contains(&panel.selected_profile) {
|
||||
panel.selected_profile = profiles[0].clone();
|
||||
}
|
||||
panel.profiles = profiles;
|
||||
}
|
||||
|
||||
fn fs_profiles(root: &Path) -> Vec<String> {
|
||||
let mut profiles = std::fs::read_dir(root)
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.flatten()
|
||||
.filter_map(|entry| {
|
||||
let path = entry.path();
|
||||
(path.extension().and_then(|extension| extension.to_str()) == Some("ron"))
|
||||
.then(|| path.file_stem()?.to_str().map(str::to_string))?
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
profiles.sort();
|
||||
profiles
|
||||
}
|
||||
|
||||
fn spawn_build_job(
|
||||
engine_root: PathBuf,
|
||||
project_root: PathBuf,
|
||||
profile: String,
|
||||
run_after: bool,
|
||||
) -> BuildJob {
|
||||
let log = Arc::new(Mutex::new(VecDeque::new()));
|
||||
let result = Arc::new(Mutex::new(None));
|
||||
let cancel = Arc::new(AtomicBool::new(false));
|
||||
let thread_log = Arc::clone(&log);
|
||||
let thread_result = Arc::clone(&result);
|
||||
let thread_cancel = Arc::clone(&cancel);
|
||||
let worker = std::thread::spawn(move || {
|
||||
let mut command = Command::new("cargo");
|
||||
command
|
||||
.current_dir(&engine_root)
|
||||
.args([
|
||||
"package-project",
|
||||
"--project",
|
||||
&project_root.to_string_lossy(),
|
||||
"--profile",
|
||||
&profile,
|
||||
])
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped());
|
||||
#[cfg(unix)]
|
||||
{
|
||||
use std::os::unix::process::CommandExt;
|
||||
command.process_group(0);
|
||||
}
|
||||
let mut child = match command.spawn() {
|
||||
Ok(child) => child,
|
||||
Err(error) => {
|
||||
set_result(
|
||||
&thread_result,
|
||||
BuildResult::Failed(format!("could not start Cargo: {error}")),
|
||||
);
|
||||
return;
|
||||
}
|
||||
};
|
||||
let output_path = Arc::new(Mutex::new(None));
|
||||
let stdout_thread = child.stdout.take().map(|stdout| {
|
||||
stream_output(
|
||||
stdout,
|
||||
Arc::clone(&thread_log),
|
||||
Some(Arc::clone(&output_path)),
|
||||
)
|
||||
});
|
||||
let stderr_thread = child
|
||||
.stderr
|
||||
.take()
|
||||
.map(|stderr| stream_output(stderr, Arc::clone(&thread_log), None));
|
||||
let mut poll_error = None;
|
||||
let status = loop {
|
||||
if thread_cancel.load(Ordering::Acquire) {
|
||||
terminate_process_tree(&mut child);
|
||||
let _ = child.wait();
|
||||
break None;
|
||||
}
|
||||
match child.try_wait() {
|
||||
Ok(Some(status)) => break Some(status),
|
||||
Ok(None) => std::thread::sleep(Duration::from_millis(100)),
|
||||
Err(error) => {
|
||||
terminate_process_tree(&mut child);
|
||||
let _ = child.wait();
|
||||
poll_error = Some(format!("could not poll build process: {error}"));
|
||||
break None;
|
||||
}
|
||||
}
|
||||
};
|
||||
if let Some(thread) = stdout_thread {
|
||||
let _ = thread.join();
|
||||
}
|
||||
if let Some(thread) = stderr_thread {
|
||||
let _ = thread.join();
|
||||
}
|
||||
let final_result = match (poll_error, status) {
|
||||
(Some(error), _) => BuildResult::Failed(error),
|
||||
(None, None) => BuildResult::Cancelled,
|
||||
(None, Some(status)) if !status.success() => {
|
||||
BuildResult::Failed(format!("packager exited with {status}"))
|
||||
}
|
||||
(None, Some(_)) => output_path
|
||||
.lock()
|
||||
.ok()
|
||||
.and_then(|path| path.clone())
|
||||
.map(BuildResult::Succeeded)
|
||||
.unwrap_or_else(|| {
|
||||
BuildResult::Failed("packager did not report an output directory".into())
|
||||
}),
|
||||
};
|
||||
set_result(&thread_result, final_result);
|
||||
});
|
||||
BuildJob {
|
||||
log,
|
||||
result,
|
||||
cancel,
|
||||
run_after,
|
||||
worker: Some(worker),
|
||||
}
|
||||
}
|
||||
|
||||
fn engine_workspace_root() -> PathBuf {
|
||||
Path::new(env!("CARGO_MANIFEST_DIR"))
|
||||
.parent()
|
||||
.and_then(Path::parent)
|
||||
.expect("editor crate must live under <workspace>/crates/editor")
|
||||
.to_path_buf()
|
||||
}
|
||||
|
||||
fn terminate_process_tree(child: &mut std::process::Child) {
|
||||
#[cfg(unix)]
|
||||
{
|
||||
let process_group = format!("-{}", child.id());
|
||||
let _ = Command::new("kill")
|
||||
.args(["-TERM", "--", &process_group])
|
||||
.stdout(Stdio::null())
|
||||
.stderr(Stdio::null())
|
||||
.status();
|
||||
std::thread::sleep(Duration::from_millis(150));
|
||||
let _ = Command::new("kill")
|
||||
.args(["-KILL", "--", &process_group])
|
||||
.stdout(Stdio::null())
|
||||
.stderr(Stdio::null())
|
||||
.status();
|
||||
}
|
||||
#[cfg(windows)]
|
||||
{
|
||||
let _ = Command::new("taskkill")
|
||||
.args(["/PID", &child.id().to_string(), "/T", "/F"])
|
||||
.stdout(Stdio::null())
|
||||
.stderr(Stdio::null())
|
||||
.status();
|
||||
}
|
||||
let _ = child.kill();
|
||||
}
|
||||
|
||||
fn stream_output(
|
||||
stream: impl std::io::Read + Send + 'static,
|
||||
log: Arc<Mutex<VecDeque<String>>>,
|
||||
output_path: Option<Arc<Mutex<Option<PathBuf>>>>,
|
||||
) -> std::thread::JoinHandle<()> {
|
||||
std::thread::spawn(move || {
|
||||
for line in BufReader::new(stream).lines().map_while(Result::ok) {
|
||||
if let Some(path) = line.strip_prefix("package-project: ready at ") {
|
||||
if let Some(output_path) = &output_path {
|
||||
if let Ok(mut output_path) = output_path.lock() {
|
||||
*output_path = Some(PathBuf::from(path));
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Ok(mut log) = log.lock() {
|
||||
log.push_back(line);
|
||||
while log.len() > MAX_LOG_LINES {
|
||||
log.pop_front();
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn set_result(result: &Arc<Mutex<Option<BuildResult>>>, value: BuildResult) {
|
||||
if let Ok(mut result) = result.lock() {
|
||||
*result = Some(value);
|
||||
}
|
||||
}
|
||||
|
||||
fn launch_package(output: &Path) -> Result<(), String> {
|
||||
let metadata_path = output.join("build-metadata.json");
|
||||
let metadata = std::fs::read_to_string(&metadata_path)
|
||||
.map_err(|error| format!("Could not read {}: {error}", metadata_path.display()))?;
|
||||
let metadata: serde_json::Value = serde_json::from_str(&metadata)
|
||||
.map_err(|error| format!("Invalid {}: {error}", metadata_path.display()))?;
|
||||
let target = metadata
|
||||
.get("target")
|
||||
.and_then(serde_json::Value::as_str)
|
||||
.ok_or_else(|| format!("Package target is missing from {}", metadata_path.display()))?;
|
||||
validate_launch_target(target, std::env::consts::ARCH, std::env::consts::OS)?;
|
||||
|
||||
let native_name = if cfg!(windows) {
|
||||
"blacksite.exe"
|
||||
} else {
|
||||
"blacksite"
|
||||
};
|
||||
let foreign_name = if cfg!(windows) {
|
||||
"blacksite"
|
||||
} else {
|
||||
"blacksite.exe"
|
||||
};
|
||||
let executable = output.join(native_name);
|
||||
if !executable.is_file() {
|
||||
let foreign = output.join(foreign_name);
|
||||
if foreign.is_file() {
|
||||
return Err(format!(
|
||||
"Package {} targets a different operating system and cannot run on this host",
|
||||
foreign.display()
|
||||
));
|
||||
}
|
||||
return Err(format!(
|
||||
"Package executable is missing at {}",
|
||||
executable.display()
|
||||
));
|
||||
}
|
||||
let child = Command::new(&executable)
|
||||
.current_dir(output)
|
||||
.spawn()
|
||||
.map_err(|error| format!("Could not launch {}: {error}", executable.display()))?;
|
||||
reap_child(child);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn validate_launch_target(target: &str, host_arch: &str, host_os: &str) -> Result<(), String> {
|
||||
let segments = target.split('-').collect::<Vec<_>>();
|
||||
let target_os = if segments.contains(&"windows") {
|
||||
"windows"
|
||||
} else if segments.contains(&"linux") && !segments.contains(&"android") {
|
||||
"linux"
|
||||
} else {
|
||||
return Err(format!(
|
||||
"Package target `{target}` is not a runnable desktop target"
|
||||
));
|
||||
};
|
||||
let target_arch = segments.first().copied().unwrap_or_default();
|
||||
let target_arch = normalize_architecture(target_arch);
|
||||
let host_arch = normalize_architecture(host_arch);
|
||||
if target_os != host_os || target_arch != host_arch {
|
||||
return Err(format!(
|
||||
"Package targets {target_arch}-{target_os}, but this host is {host_arch}-{host_os}"
|
||||
));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn normalize_architecture(architecture: &str) -> &str {
|
||||
match architecture {
|
||||
"i386" | "i486" | "i586" | "i686" | "x86" => "x86",
|
||||
architecture if architecture.starts_with("armv") => "arm",
|
||||
architecture => architecture,
|
||||
}
|
||||
}
|
||||
|
||||
fn reap_child(mut child: std::process::Child) {
|
||||
std::thread::spawn(move || {
|
||||
let _ = child.wait();
|
||||
});
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn profile_scan_is_sorted_and_uses_file_stems() {
|
||||
let root =
|
||||
std::env::temp_dir().join(format!("blacksite-build-profiles-{}", std::process::id()));
|
||||
let _ = std::fs::remove_dir_all(&root);
|
||||
std::fs::create_dir_all(&root).unwrap();
|
||||
std::fs::write(root.join("release.ron"), "()").unwrap();
|
||||
std::fs::write(root.join("development.ron"), "()").unwrap();
|
||||
std::fs::write(root.join("ignore.txt"), "").unwrap();
|
||||
assert_eq!(fs_profiles(&root), vec!["development", "release"]);
|
||||
std::fs::remove_dir_all(root).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn engine_workspace_contains_the_game_package() {
|
||||
let root = engine_workspace_root();
|
||||
assert!(root.join("Cargo.toml").is_file());
|
||||
assert!(root.join("crates/game/Cargo.toml").is_file());
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[test]
|
||||
fn cancellation_terminates_the_compiler_process_group() {
|
||||
use std::os::unix::process::CommandExt;
|
||||
use std::time::Instant;
|
||||
|
||||
let mut command = Command::new("sh");
|
||||
command
|
||||
.args(["-c", "(trap '' TERM; sleep 30) & wait"])
|
||||
.stdout(Stdio::null())
|
||||
.stderr(Stdio::null())
|
||||
.process_group(0);
|
||||
let mut child = command.spawn().unwrap();
|
||||
let started = Instant::now();
|
||||
terminate_process_tree(&mut child);
|
||||
let status = child.wait().unwrap();
|
||||
assert!(!status.success());
|
||||
assert!(started.elapsed() < Duration::from_secs(3));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn package_launch_rejects_same_os_cross_architecture_targets() {
|
||||
assert!(validate_launch_target("x86_64-unknown-linux-gnu", "x86_64", "linux").is_ok());
|
||||
assert!(
|
||||
validate_launch_target("aarch64-unknown-linux-gnu", "x86_64", "linux")
|
||||
.unwrap_err()
|
||||
.contains("aarch64-linux")
|
||||
);
|
||||
assert!(
|
||||
validate_launch_target("x86_64-pc-windows-msvc", "x86_64", "linux")
|
||||
.unwrap_err()
|
||||
.contains("windows")
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,8 @@ use egui_phosphor_icons::icons;
|
||||
pub enum EditorComponentCategory {
|
||||
Authoring,
|
||||
Rendering,
|
||||
Animation,
|
||||
Audio,
|
||||
Physics,
|
||||
Gameplay,
|
||||
Volumes,
|
||||
@@ -136,6 +138,54 @@ impl Default for EditorComponentRegistry {
|
||||
conflicts_with: &[],
|
||||
hydration_effect: "Hydrates into runtime Bevy light components.",
|
||||
},
|
||||
EditorComponentDescriptor {
|
||||
type_name: "shared::animation::AnimationControllerDesc",
|
||||
display_name: "Animation Controller",
|
||||
category: EditorComponentCategory::Animation,
|
||||
addable: true,
|
||||
removable: true,
|
||||
reorderable: true,
|
||||
hidden: false,
|
||||
icon: icons::FILM_SLATE.as_str(),
|
||||
description: "Authors named animation states for an imported model rig.",
|
||||
search_terms: &["animation", "controller", "state", "clip", "skeleton", "rig"],
|
||||
recommended: &[],
|
||||
conflicts_with: &[],
|
||||
hydration_effect:
|
||||
"Hydrates into a Bevy animation graph and player bound to the imported model.",
|
||||
},
|
||||
EditorComponentDescriptor {
|
||||
type_name: "shared::components::AudioSourceDesc",
|
||||
display_name: "Audio Source",
|
||||
category: EditorComponentCategory::Audio,
|
||||
addable: true,
|
||||
removable: true,
|
||||
reorderable: true,
|
||||
hidden: false,
|
||||
icon: icons::SPEAKER_HIGH.as_str(),
|
||||
description: "Plays a routed 2D or spatial audio clip from this actor.",
|
||||
search_terms: &["audio", "sound", "clip", "speaker", "spatial"],
|
||||
recommended: &[],
|
||||
conflicts_with: &["shared::components::AudioListenerDesc"],
|
||||
hydration_effect:
|
||||
"Hydrates into runtime Bevy audio voices with bus and attenuation control.",
|
||||
},
|
||||
EditorComponentDescriptor {
|
||||
type_name: "shared::components::AudioListenerDesc",
|
||||
display_name: "Audio Listener",
|
||||
category: EditorComponentCategory::Audio,
|
||||
addable: true,
|
||||
removable: true,
|
||||
reorderable: true,
|
||||
hidden: false,
|
||||
icon: icons::HEADPHONES.as_str(),
|
||||
description: "Receives spatial audio at this actor transform.",
|
||||
search_terms: &["audio", "sound", "listener", "ears", "spatial"],
|
||||
recommended: &[],
|
||||
conflicts_with: &["shared::components::AudioSourceDesc"],
|
||||
hydration_effect:
|
||||
"The highest-priority enabled listener becomes the runtime listener.",
|
||||
},
|
||||
EditorComponentDescriptor {
|
||||
type_name: "shared::components::Primitive",
|
||||
display_name: "Primitive",
|
||||
|
||||
@@ -8,16 +8,19 @@ use shared::{
|
||||
};
|
||||
|
||||
use crate::assets::EditorAssets;
|
||||
use crate::diagnostics_bundle::export_diagnostic_bundle;
|
||||
use crate::history::set_brush_with_history;
|
||||
use crate::history::EditorHistory;
|
||||
use crate::project_io::ProjectWorkspace;
|
||||
use crate::scene_io::SceneIo;
|
||||
use crate::scene_io::{SceneIo, SceneIoEventSeverity};
|
||||
use crate::selection::SelectedEntity;
|
||||
use crate::ui::UiState;
|
||||
|
||||
#[derive(Resource, Default)]
|
||||
pub struct DiagnosticsPanel {
|
||||
pub open: bool,
|
||||
pub bundle_status: Option<String>,
|
||||
pub project_validation: Option<scene::ProjectValidationReport>,
|
||||
}
|
||||
|
||||
#[derive(Resource, Default)]
|
||||
@@ -26,10 +29,18 @@ pub struct BrushDiagnosticsPanel {
|
||||
}
|
||||
|
||||
pub fn diagnostics_ui(world: &mut World, ui: &mut egui::Ui) {
|
||||
let scene_io = world.resource::<SceneIo>();
|
||||
let dirty = if scene_io.dirty { " (dirty)" } else { "" };
|
||||
ui.label(format!("Scene: {}{dirty}", scene_io.active_path_label()));
|
||||
ui.label(format!("Status: {}", scene_io.status));
|
||||
let (scene_label, dirty, status, scene_events) = {
|
||||
let scene_io = world.resource::<SceneIo>();
|
||||
(
|
||||
scene_io.active_path_label(),
|
||||
scene_io.dirty,
|
||||
scene_io.status.clone(),
|
||||
scene_io.events.iter().rev().cloned().collect::<Vec<_>>(),
|
||||
)
|
||||
};
|
||||
let dirty = if dirty { " (dirty)" } else { "" };
|
||||
ui.label(format!("Scene: {scene_label}{dirty}"));
|
||||
ui.label(format!("Status: {status}"));
|
||||
ui.label(format!(
|
||||
"History: {}",
|
||||
world.resource::<EditorHistory>().status
|
||||
@@ -58,6 +69,125 @@ pub fn diagnostics_ui(world: &mut World, ui: &mut egui::Ui) {
|
||||
let count = level_query.iter(world).count();
|
||||
ui.label(format!("Level objects: {count}"));
|
||||
|
||||
ui.separator();
|
||||
ui.horizontal(|ui| {
|
||||
ui.strong("Project validation");
|
||||
if ui.button("Validate Project").clicked() {
|
||||
let root = world.resource::<ProjectWorkspace>().root.clone();
|
||||
let report = scene::validate_project(std::path::Path::new(&root));
|
||||
let summary = format!(
|
||||
"Project validation: {} dependencies, {} findings, {} blocking errors",
|
||||
report.dependencies.len(),
|
||||
report.findings.len(),
|
||||
report.blocking_error_count()
|
||||
);
|
||||
world.resource_mut::<SceneIo>().set_status(summary);
|
||||
world.resource_mut::<DiagnosticsPanel>().project_validation = Some(report);
|
||||
}
|
||||
});
|
||||
if let Some(report) = world
|
||||
.resource::<DiagnosticsPanel>()
|
||||
.project_validation
|
||||
.as_ref()
|
||||
.cloned()
|
||||
{
|
||||
let color = if report.is_release_ready() {
|
||||
egui::Color32::from_rgb(125, 210, 145)
|
||||
} else {
|
||||
egui::Color32::from_rgb(255, 137, 129)
|
||||
};
|
||||
ui.colored_label(
|
||||
color,
|
||||
format!(
|
||||
"{} dependencies, {} blocking errors",
|
||||
report.dependencies.len(),
|
||||
report.blocking_error_count()
|
||||
),
|
||||
);
|
||||
for finding in report.findings.iter().take(12) {
|
||||
let actor = finding
|
||||
.owner_actor_id
|
||||
.as_deref()
|
||||
.map(|actor| format!(" / {actor}"))
|
||||
.unwrap_or_default();
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.monospace(format!("{}{}", finding.source_path, actor));
|
||||
ui.label(&finding.message);
|
||||
if let Some(actor_id) = finding.owner_actor_id.as_deref() {
|
||||
if ui.small_button("Select").clicked() {
|
||||
let mut query = world.query::<(Entity, &shared::ActorId)>();
|
||||
if let Some(entity) = query
|
||||
.iter(world)
|
||||
.find_map(|(entity, id)| (id.0 == actor_id).then_some(entity))
|
||||
{
|
||||
world.resource_mut::<SelectedEntity>().0 = Some(entity);
|
||||
world
|
||||
.resource_mut::<UiState>()
|
||||
.selected_entities
|
||||
.select_replace(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
if report.findings.len() > 12 {
|
||||
ui.small(format!(
|
||||
"{} additional findings",
|
||||
report.findings.len() - 12
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
ui.separator();
|
||||
ui.horizontal(|ui| {
|
||||
ui.strong("Support bundle");
|
||||
if ui.button("Export Diagnostic Bundle").clicked() {
|
||||
let status = match export_diagnostic_bundle(world) {
|
||||
Ok(path) => format!("Exported {}", path.display()),
|
||||
Err(error) => format!("Export failed: {error}"),
|
||||
};
|
||||
world.resource_mut::<DiagnosticsPanel>().bundle_status = Some(status);
|
||||
}
|
||||
});
|
||||
ui.small("Allowlisted metadata only; scene and asset contents, environment values, credentials, and modal state are excluded.");
|
||||
if let Some(status) = world
|
||||
.resource::<DiagnosticsPanel>()
|
||||
.bundle_status
|
||||
.as_deref()
|
||||
{
|
||||
ui.monospace(status);
|
||||
}
|
||||
|
||||
ui.separator();
|
||||
ui.horizontal(|ui| {
|
||||
ui.strong("Scene I/O log");
|
||||
if ui
|
||||
.add_enabled(!scene_events.is_empty(), egui::Button::new("Clear"))
|
||||
.clicked()
|
||||
{
|
||||
world.resource_mut::<SceneIo>().clear_events();
|
||||
}
|
||||
});
|
||||
if scene_events.is_empty() {
|
||||
ui.small("No scene I/O operations recorded this session.");
|
||||
} else {
|
||||
egui::ScrollArea::vertical()
|
||||
.id_salt("scene_io_diagnostics_log")
|
||||
.max_height(180.0)
|
||||
.show(ui, |ui| {
|
||||
for event in scene_events {
|
||||
let color = match event.severity {
|
||||
SceneIoEventSeverity::Info => ui.visuals().weak_text_color(),
|
||||
SceneIoEventSeverity::Error => egui::Color32::from_rgb(244, 110, 105),
|
||||
};
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.colored_label(color, format!("#{:02}", event.id));
|
||||
ui.colored_label(color, event.message);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ui.separator();
|
||||
ui.small("Native Bevy scenes are saved to assets/levels/*.scn.ron");
|
||||
ui.small("BRP is enabled on the editor for external tooling.");
|
||||
|
||||
@@ -36,7 +36,7 @@ impl PanelNodes {
|
||||
EditorTab::Viewport | EditorTab::GameView => self.main_view(),
|
||||
EditorTab::Hierarchy => self.hierarchy(),
|
||||
EditorTab::Inspector => self.inspector(),
|
||||
EditorTab::AssetBrowser | EditorTab::Toolbar => self.bottom(),
|
||||
EditorTab::AssetBrowser | EditorTab::Build | EditorTab::Toolbar => self.bottom(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,18 +51,21 @@ impl PanelNodes {
|
||||
EditorTab::Viewport | EditorTab::GameView => nodes.main_view = path.node.0,
|
||||
EditorTab::Hierarchy => nodes.hierarchy = path.node.0,
|
||||
EditorTab::Inspector => nodes.inspector = path.node.0,
|
||||
EditorTab::AssetBrowser | EditorTab::Toolbar => nodes.bottom = path.node.0,
|
||||
EditorTab::AssetBrowser | EditorTab::Build | EditorTab::Toolbar => {
|
||||
nodes.bottom = path.node.0
|
||||
}
|
||||
}
|
||||
}
|
||||
nodes
|
||||
}
|
||||
}
|
||||
|
||||
pub const PANEL_TABS: [EditorTab; 4] = [
|
||||
pub const PANEL_TABS: [EditorTab; 5] = [
|
||||
EditorTab::Viewport,
|
||||
EditorTab::Hierarchy,
|
||||
EditorTab::Inspector,
|
||||
EditorTab::AssetBrowser,
|
||||
EditorTab::Build,
|
||||
];
|
||||
|
||||
pub fn tab_label(tab: &EditorTab) -> &'static str {
|
||||
@@ -71,6 +74,7 @@ pub fn tab_label(tab: &EditorTab) -> &'static str {
|
||||
EditorTab::Hierarchy => "Hierarchy",
|
||||
EditorTab::Inspector => "Inspector",
|
||||
EditorTab::AssetBrowser => "Asset Browser",
|
||||
EditorTab::Build => "Build",
|
||||
EditorTab::Toolbar => "Toolbar (legacy)",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ use sim::Player;
|
||||
use crate::assets::{snapshot_for_asset, EditorAsset, EditorAssetKind};
|
||||
use crate::camera::EditorCamera;
|
||||
use crate::gizmos::{EditorGizmoMode, EditorGizmoSpace};
|
||||
use crate::history::{set_material_with_history, spawn_with_history, EditorEntitySnapshot};
|
||||
use crate::history::{set_material_group_with_history, spawn_with_history, EditorEntitySnapshot};
|
||||
use crate::play::default_player_spawn;
|
||||
use crate::scene_io::SceneIo;
|
||||
use crate::viewport::{recall_camera_bookmark, save_camera_bookmark, CameraBookmarks};
|
||||
@@ -97,6 +97,9 @@ pub fn light_snapshot(name: &str, translation: Vec3) -> EditorEntitySnapshot {
|
||||
collider: None,
|
||||
physics: None,
|
||||
light: Some(LightDesc::default()),
|
||||
animation_controller: None,
|
||||
audio_source: None,
|
||||
audio_listener: None,
|
||||
player_spawn: false,
|
||||
model: None,
|
||||
prefab: None,
|
||||
@@ -145,6 +148,9 @@ pub fn ensure_player_spawn_for_edit(world: &mut World) -> Entity {
|
||||
collider: None,
|
||||
physics: None,
|
||||
light: None,
|
||||
animation_controller: None,
|
||||
audio_source: None,
|
||||
audio_listener: None,
|
||||
player_spawn: true,
|
||||
model: None,
|
||||
prefab: None,
|
||||
@@ -233,6 +239,9 @@ pub fn create_scene_sun_override_from_project_settings(world: &mut World) -> Ent
|
||||
collider: None,
|
||||
physics: None,
|
||||
light: Some(light),
|
||||
animation_controller: None,
|
||||
audio_source: None,
|
||||
audio_listener: None,
|
||||
player_spawn: false,
|
||||
model: None,
|
||||
prefab: None,
|
||||
@@ -256,6 +265,7 @@ pub fn asset_label(asset: &EditorAsset) -> String {
|
||||
EditorAssetKind::Model => "Model",
|
||||
EditorAssetKind::Texture => "Texture",
|
||||
EditorAssetKind::Material => "Material",
|
||||
EditorAssetKind::AudioClip => "Audio Clip",
|
||||
EditorAssetKind::Level => "Level",
|
||||
EditorAssetKind::Prefab => "Prefab",
|
||||
EditorAssetKind::PostProcessVolume => "Post Process Volume",
|
||||
@@ -270,26 +280,32 @@ pub fn apply_texture_to_selection(
|
||||
world: &mut World,
|
||||
asset: &EditorAsset,
|
||||
selected: &SelectedEntities,
|
||||
) {
|
||||
let Some(path) = asset.path.clone() else {
|
||||
return;
|
||||
};
|
||||
for entity in selected_level_entities(world, selected) {
|
||||
let mut material = world
|
||||
.get::<MaterialDesc>(entity)
|
||||
.cloned()
|
||||
.unwrap_or_default();
|
||||
material.base_color_texture = Some(path.clone());
|
||||
set_material_with_history(world, entity, material);
|
||||
}
|
||||
) -> Result<(), String> {
|
||||
let path = asset
|
||||
.path
|
||||
.clone()
|
||||
.ok_or_else(|| format!("Texture has no source path: {}", asset.label))?;
|
||||
let changes = selected_level_entities(world, selected)
|
||||
.into_iter()
|
||||
.map(|entity| {
|
||||
let mut material = world
|
||||
.get::<MaterialDesc>(entity)
|
||||
.cloned()
|
||||
.unwrap_or_default();
|
||||
material.base_color_texture = Some(path.clone());
|
||||
(entity, material)
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
set_material_group_with_history(world, changes);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn apply_material_asset_to_selection(
|
||||
world: &mut World,
|
||||
asset: &EditorAsset,
|
||||
selected: &SelectedEntities,
|
||||
) {
|
||||
crate::assets::materials::apply_material_asset_to_selection(world, asset, selected);
|
||||
) -> Result<(), String> {
|
||||
crate::assets::materials::apply_material_asset_to_selection(world, asset, selected)
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
|
||||
@@ -5,7 +5,7 @@ use bevy_egui::egui;
|
||||
use bevy_inspector_egui::bevy_inspector::hierarchy::SelectedEntities;
|
||||
use egui::containers::scroll_area::ScrollSource;
|
||||
use egui_phosphor_icons::icons;
|
||||
use shared::EditorVisibility;
|
||||
use shared::{EditorVisibility, HydratedPrefabMember};
|
||||
|
||||
use crate::history::{
|
||||
create_empty_child_with_history, delete_entities_with_history, duplicate_entities_with_history,
|
||||
@@ -19,11 +19,17 @@ use crate::ui::helpers::{
|
||||
};
|
||||
use crate::ui::hierarchy_ops::{
|
||||
authored_children, editor_visibility, entity_hierarchy_path, entity_matches_filter,
|
||||
hierarchy_label_for_entity, is_entity_locked, level_object_roots, sort_siblings,
|
||||
would_create_cycle, HierarchyLabel,
|
||||
hierarchy_drop_violation, hierarchy_label_for_entity, is_ancestor, is_entity_locked,
|
||||
level_object_roots, mutable_authored_children, sort_siblings, HierarchyDropViolation,
|
||||
HierarchyLabel,
|
||||
};
|
||||
use crate::ui::hierarchy_state::{HierarchyPanelState, HierarchySort};
|
||||
use crate::ui::theme::{panel_heading, TEXT, TEXT_DIM, TEXT_SELECTED};
|
||||
use crate::ui::selection_ops::is_linked_read_only;
|
||||
use crate::ui::theme::{
|
||||
overlay_chip_frame, panel_heading, ACCENT, ERROR, PANEL_BG_DARK, SELECTION, SELECTION_BG_MUTED,
|
||||
SELECTION_SECONDARY, TEXT, TEXT_DIM, TEXT_MUTED, TEXT_SELECTED,
|
||||
};
|
||||
use crate::ui::widgets::phosphor_icon;
|
||||
|
||||
#[derive(Clone)]
|
||||
struct HierarchyDragPayload {
|
||||
@@ -37,6 +43,12 @@ enum DropTarget {
|
||||
Before(Entity),
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
enum DropBlock {
|
||||
Hierarchy(HierarchyDropViolation),
|
||||
LockedTarget(Entity),
|
||||
}
|
||||
|
||||
pub fn hierarchy_panel_ui(
|
||||
world: &mut World,
|
||||
ui: &mut egui::Ui,
|
||||
@@ -121,7 +133,7 @@ pub fn hierarchy_panel_ui(
|
||||
|
||||
if ui.input(|input| input.key_pressed(egui::Key::F2)) {
|
||||
if let Some(entity) = selected_entities.as_slice().first().copied() {
|
||||
if is_level_object(world, entity) {
|
||||
if is_level_object(world, entity) && !is_entity_locked(&locked, entity) {
|
||||
*renaming_entity = Some(entity);
|
||||
*rename_buffer = entity_name(world, entity);
|
||||
}
|
||||
@@ -130,12 +142,10 @@ pub fn hierarchy_panel_ui(
|
||||
|
||||
let filter_lower = filter.trim().to_lowercase();
|
||||
let mut drop_target = None;
|
||||
let mut invalid_drop = false;
|
||||
let mut drop_block = None;
|
||||
|
||||
let dragging = world
|
||||
.resource::<HierarchyPanelState>()
|
||||
.active_drag
|
||||
.is_some();
|
||||
let active_drag = world.resource::<HierarchyPanelState>().active_drag.clone();
|
||||
let dragging = active_drag.is_some();
|
||||
|
||||
egui::ScrollArea::vertical()
|
||||
.id_salt("hierarchy_tree")
|
||||
@@ -148,7 +158,7 @@ pub fn hierarchy_panel_ui(
|
||||
ui.spacing_mut().item_spacing.y = 2.0;
|
||||
|
||||
if dragging {
|
||||
draw_root_drop_zone(ui, &mut drop_target);
|
||||
draw_root_drop_zone(ui, active_drag.as_deref(), &mut drop_target);
|
||||
}
|
||||
|
||||
let mut roots = level_object_roots(world);
|
||||
@@ -171,12 +181,12 @@ pub fn hierarchy_panel_ui(
|
||||
&filter_lower,
|
||||
sort_mode,
|
||||
show_generated,
|
||||
dragging,
|
||||
active_drag.as_deref(),
|
||||
&expanded,
|
||||
&locked,
|
||||
&prefs_paths,
|
||||
&mut drop_target,
|
||||
&mut invalid_drop,
|
||||
&mut drop_block,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -192,6 +202,8 @@ pub fn hierarchy_panel_ui(
|
||||
}
|
||||
});
|
||||
|
||||
draw_hierarchy_drag_preview(world, ui, active_drag.as_deref(), drop_target, drop_block);
|
||||
|
||||
if ui.ctx().input(|input| input.pointer.any_released()) {
|
||||
if let Some(target) = drop_target {
|
||||
let drag_entities = world
|
||||
@@ -200,7 +212,7 @@ pub fn hierarchy_panel_ui(
|
||||
.take();
|
||||
if let Some(entities) = drag_entities {
|
||||
let payload = HierarchyDragPayload { entities };
|
||||
apply_drop(world, &payload, target, invalid_drop);
|
||||
apply_drop(world, &payload, target, drop_block);
|
||||
}
|
||||
} else {
|
||||
world.resource_mut::<HierarchyPanelState>().active_drag = None;
|
||||
@@ -220,14 +232,45 @@ fn sort_label(sort: HierarchySort) -> &'static str {
|
||||
}
|
||||
}
|
||||
|
||||
fn draw_root_drop_zone(ui: &mut egui::Ui, drop_target: &mut Option<DropTarget>) {
|
||||
fn draw_root_drop_zone(
|
||||
ui: &mut egui::Ui,
|
||||
drag_entities: Option<&[Entity]>,
|
||||
drop_target: &mut Option<DropTarget>,
|
||||
) {
|
||||
let (rect, response) =
|
||||
ui.allocate_exact_size(egui::vec2(ui.available_width(), 2.0), egui::Sense::hover());
|
||||
if let Some(hover) = response.dnd_hover_payload::<HierarchyDragPayload>() {
|
||||
ui.painter()
|
||||
.rect_filled(rect, 1.0, egui::Color32::from_rgb(80, 120, 200));
|
||||
ui.allocate_exact_size(egui::vec2(ui.available_width(), 27.0), egui::Sense::hover());
|
||||
let hovered = drag_entities.is_some()
|
||||
&& (response.contains_pointer()
|
||||
|| response
|
||||
.dnd_hover_payload::<HierarchyDragPayload>()
|
||||
.is_some());
|
||||
ui.painter().rect(
|
||||
rect,
|
||||
2.0,
|
||||
if hovered {
|
||||
SELECTION_BG_MUTED
|
||||
} else {
|
||||
PANEL_BG_DARK
|
||||
},
|
||||
egui::Stroke::new(1.0, if hovered { SELECTION } else { TEXT_MUTED }),
|
||||
egui::StrokeKind::Inside,
|
||||
);
|
||||
ui.painter().text(
|
||||
rect.left_center() + egui::vec2(9.0, 0.0),
|
||||
egui::Align2::LEFT_CENTER,
|
||||
icons::TREE_STRUCTURE.as_str(),
|
||||
egui::FontId::new(13.0, egui::FontFamily::Name("phosphor-regular".into())),
|
||||
if hovered { SELECTION } else { TEXT_DIM },
|
||||
);
|
||||
ui.painter().text(
|
||||
rect.left_center() + egui::vec2(29.0, 0.0),
|
||||
egui::Align2::LEFT_CENTER,
|
||||
"SCENE ROOT",
|
||||
egui::FontId::new(11.0, egui::FontFamily::Proportional),
|
||||
if hovered { TEXT_SELECTED } else { TEXT_DIM },
|
||||
);
|
||||
if hovered {
|
||||
*drop_target = Some(DropTarget::Root);
|
||||
let _ = hover;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -246,12 +289,12 @@ fn draw_authored_node(
|
||||
filter_lower: &str,
|
||||
sort_mode: HierarchySort,
|
||||
show_generated: bool,
|
||||
drag_active: bool,
|
||||
drag_entities: Option<&[Entity]>,
|
||||
expanded: &std::collections::HashSet<Entity>,
|
||||
locked: &std::collections::HashSet<Entity>,
|
||||
prefs_paths: &[String],
|
||||
drop_target: &mut Option<DropTarget>,
|
||||
invalid_drop: &mut bool,
|
||||
drop_block: &mut Option<DropBlock>,
|
||||
) {
|
||||
let path = entity_hierarchy_path(world, entity);
|
||||
let mut is_expanded = expanded.contains(&entity) || prefs_paths.iter().any(|p| p == &path);
|
||||
@@ -265,15 +308,18 @@ fn draw_authored_node(
|
||||
.any(|child| is_hierarchy_generated_child(world, child))
|
||||
}));
|
||||
|
||||
draw_drop_before(
|
||||
world,
|
||||
ui,
|
||||
entity,
|
||||
depth,
|
||||
drag_active,
|
||||
drop_target,
|
||||
invalid_drop,
|
||||
);
|
||||
if sort_mode == HierarchySort::Manual {
|
||||
draw_drop_before(
|
||||
world,
|
||||
ui,
|
||||
entity,
|
||||
depth,
|
||||
drag_entities,
|
||||
locked,
|
||||
drop_target,
|
||||
drop_block,
|
||||
);
|
||||
}
|
||||
|
||||
ui.horizontal(|ui| {
|
||||
ui.add_space(depth as f32 * 14.0);
|
||||
@@ -318,21 +364,37 @@ fn draw_authored_node(
|
||||
ui.add_space(18.0);
|
||||
}
|
||||
|
||||
let linked_read_only = is_linked_read_only(world, entity);
|
||||
let is_locked = is_entity_locked(locked, entity);
|
||||
let visible = editor_visibility(world, entity).visible;
|
||||
let eye_icon = if visible {
|
||||
icons::EYE.regular()
|
||||
} else {
|
||||
icons::EYE_SLASH.regular()
|
||||
};
|
||||
if ui.small_button(eye_icon).clicked() {
|
||||
set_editor_visibility_with_history(
|
||||
world,
|
||||
entity,
|
||||
EditorVisibility { visible: !visible },
|
||||
);
|
||||
let prefab_member = world.get::<HydratedPrefabMember>(entity).is_some();
|
||||
if ui
|
||||
.add_enabled(
|
||||
!is_locked && (!linked_read_only || prefab_member),
|
||||
egui::Button::new(eye_icon),
|
||||
)
|
||||
.clicked()
|
||||
{
|
||||
if prefab_member {
|
||||
crate::assets::prefab_overrides::set_prefab_component_override(
|
||||
world,
|
||||
entity,
|
||||
EditorVisibility { visible: !visible },
|
||||
);
|
||||
} else {
|
||||
set_editor_visibility_with_history(
|
||||
world,
|
||||
entity,
|
||||
EditorVisibility { visible: !visible },
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
let is_locked = is_entity_locked(locked, entity);
|
||||
let lock_icon = if is_locked {
|
||||
icons::LOCK.regular()
|
||||
} else {
|
||||
@@ -351,15 +413,33 @@ fn draw_authored_node(
|
||||
let response = ui.text_edit_singleline(rename_buffer);
|
||||
let commit =
|
||||
response.lost_focus() || ui.input(|input| input.key_pressed(egui::Key::Enter));
|
||||
if commit {
|
||||
if commit && !is_locked && !linked_read_only {
|
||||
rename_entity_with_history(world, entity, rename_buffer.clone());
|
||||
*renaming_entity = None;
|
||||
}
|
||||
} else {
|
||||
let selected = selected_entities.contains(entity);
|
||||
let primary = selected_entities.as_slice().first().copied() == Some(entity);
|
||||
let label = hierarchy_label_for_entity(world, entity, HierarchyNodeKind::Authored);
|
||||
let color = if selected { TEXT_SELECTED } else { TEXT };
|
||||
let response = ui.selectable_label(selected, hierarchy_label_text(label, color));
|
||||
let response = ui.add_sized(
|
||||
egui::vec2(ui.available_width().max(72.0), 24.0),
|
||||
egui::Button::selectable(selected, hierarchy_label_text(label, color))
|
||||
.sense(egui::Sense::click_and_drag()),
|
||||
);
|
||||
if selected {
|
||||
ui.painter().line_segment(
|
||||
[response.rect.left_top(), response.rect.left_bottom()],
|
||||
egui::Stroke::new(
|
||||
if primary { 3.0 } else { 2.0 },
|
||||
if primary {
|
||||
SELECTION
|
||||
} else {
|
||||
SELECTION_SECONDARY
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
if response.clicked() && !is_locked {
|
||||
let additive = ui.input(|input| {
|
||||
input.modifiers.shift || input.modifiers.command || input.modifiers.ctrl
|
||||
@@ -371,38 +451,37 @@ fn draw_authored_node(
|
||||
}
|
||||
world.resource_mut::<SelectedEntity>().0 = Some(entity);
|
||||
}
|
||||
if response.double_clicked() && is_level_object(world, entity) {
|
||||
if response.double_clicked()
|
||||
&& is_level_object(world, entity)
|
||||
&& !is_locked
|
||||
&& !linked_read_only
|
||||
{
|
||||
*renaming_entity = Some(entity);
|
||||
*rename_buffer = entity_name(world, entity);
|
||||
}
|
||||
|
||||
if response.drag_started() {
|
||||
let drag_entities: Vec<Entity> = if selected_entities.contains(entity) {
|
||||
selected_entities
|
||||
.iter()
|
||||
.filter(|e| is_level_object(world, *e))
|
||||
.collect()
|
||||
if response.drag_started() && !is_locked && (!linked_read_only || prefab_member) {
|
||||
let candidates: Vec<Entity> = if selected_entities.contains(entity) {
|
||||
selected_entities.iter().collect()
|
||||
} else {
|
||||
vec![entity]
|
||||
};
|
||||
let drag_entities = draggable_selection(world, &candidates, locked);
|
||||
response.dnd_set_drag_payload(HierarchyDragPayload {
|
||||
entities: drag_entities.clone(),
|
||||
});
|
||||
world.resource_mut::<HierarchyPanelState>().active_drag = Some(drag_entities);
|
||||
}
|
||||
|
||||
if let Some(hover) = response.dnd_hover_payload::<HierarchyDragPayload>() {
|
||||
let invalid = would_create_cycle(world, &hover.entities, Some(entity));
|
||||
*invalid_drop = invalid;
|
||||
let hover_payload = response.dnd_hover_payload::<HierarchyDragPayload>();
|
||||
let hovered_entities = hover_payload
|
||||
.as_deref()
|
||||
.map(|payload| payload.entities.as_slice())
|
||||
.or_else(|| drag_entities.filter(|_| response.contains_pointer()));
|
||||
if let Some(entities) = hovered_entities {
|
||||
*drop_block = drop_block_for_target(world, locked, entities, Some(entity), entity);
|
||||
*drop_target = Some(DropTarget::On(entity));
|
||||
if invalid {
|
||||
ui.painter().rect_stroke(
|
||||
response.rect,
|
||||
2.0,
|
||||
egui::Stroke::new(2.0, egui::Color32::RED),
|
||||
egui::StrokeKind::Outside,
|
||||
);
|
||||
}
|
||||
draw_attach_target_feedback(ui, response.rect, drop_block.is_some());
|
||||
}
|
||||
|
||||
response.context_menu(|ui| {
|
||||
@@ -413,6 +492,7 @@ fn draw_authored_node(
|
||||
selected_entities,
|
||||
renaming_entity,
|
||||
rename_buffer,
|
||||
locked,
|
||||
)
|
||||
});
|
||||
}
|
||||
@@ -437,12 +517,12 @@ fn draw_authored_node(
|
||||
filter_lower,
|
||||
sort_mode,
|
||||
show_generated,
|
||||
drag_active,
|
||||
drag_entities,
|
||||
expanded,
|
||||
locked,
|
||||
prefs_paths,
|
||||
drop_target,
|
||||
invalid_drop,
|
||||
drop_block,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -458,43 +538,94 @@ fn draw_authored_node(
|
||||
}
|
||||
}
|
||||
|
||||
#[expect(
|
||||
clippy::too_many_arguments,
|
||||
reason = "immediate-mode drop feedback threads the current drag, lock, and target state"
|
||||
)]
|
||||
fn draw_drop_before(
|
||||
world: &World,
|
||||
ui: &mut egui::Ui,
|
||||
entity: Entity,
|
||||
depth: usize,
|
||||
drag_active: bool,
|
||||
drag_entities: Option<&[Entity]>,
|
||||
locked: &std::collections::HashSet<Entity>,
|
||||
drop_target: &mut Option<DropTarget>,
|
||||
invalid_drop: &mut bool,
|
||||
drop_block: &mut Option<DropBlock>,
|
||||
) {
|
||||
if !drag_active {
|
||||
let Some(drag_entities) = drag_entities else {
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
ui.horizontal(|ui| {
|
||||
ui.add_space(depth as f32 * 14.0 + 18.0);
|
||||
let (rect, response) =
|
||||
ui.allocate_exact_size(egui::vec2(ui.available_width(), 2.0), egui::Sense::hover());
|
||||
if let Some(hover) = response.dnd_hover_payload::<HierarchyDragPayload>() {
|
||||
*invalid_drop = would_create_cycle(
|
||||
world,
|
||||
&hover.entities,
|
||||
world
|
||||
.get::<ChildOf>(entity)
|
||||
.map(|child_of| child_of.parent()),
|
||||
);
|
||||
*drop_target = Some(DropTarget::Before(entity));
|
||||
let color = if *invalid_drop {
|
||||
egui::Color32::RED
|
||||
ui.allocate_exact_size(egui::vec2(ui.available_width(), 7.0), egui::Sense::hover());
|
||||
let hovered = response.contains_pointer()
|
||||
|| response
|
||||
.dnd_hover_payload::<HierarchyDragPayload>()
|
||||
.is_some();
|
||||
if hovered {
|
||||
let parent = world
|
||||
.get::<ChildOf>(entity)
|
||||
.map(|child_of| child_of.parent());
|
||||
*drop_block = if world.get::<HydratedPrefabMember>(entity).is_some()
|
||||
|| drag_entities
|
||||
.iter()
|
||||
.any(|dragged| world.get::<HydratedPrefabMember>(*dragged).is_some())
|
||||
{
|
||||
let root =
|
||||
crate::assets::prefab_overrides::prefab_member_override_target(world, entity)
|
||||
.map(|(root, _)| root)
|
||||
.unwrap_or(entity);
|
||||
Some(DropBlock::Hierarchy(
|
||||
HierarchyDropViolation::PrefabBoundary { root },
|
||||
))
|
||||
} else {
|
||||
egui::Color32::from_rgb(80, 120, 200)
|
||||
drop_block_for_target(world, locked, drag_entities, parent, entity)
|
||||
};
|
||||
ui.painter().rect_filled(rect, 1.0, color);
|
||||
let _ = hover;
|
||||
*drop_target = Some(DropTarget::Before(entity));
|
||||
let color = if drop_block.is_some() {
|
||||
ERROR
|
||||
} else {
|
||||
SELECTION
|
||||
};
|
||||
ui.painter().line_segment(
|
||||
[rect.left_center(), rect.right_center()],
|
||||
egui::Stroke::new(2.0, color),
|
||||
);
|
||||
ui.painter().circle_filled(rect.left_center(), 3.5, color);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn draw_attach_target_feedback(ui: &egui::Ui, rect: egui::Rect, invalid: bool) {
|
||||
let color = if invalid { ERROR } else { ACCENT };
|
||||
ui.painter().rect_filled(
|
||||
rect,
|
||||
2.0,
|
||||
if invalid {
|
||||
egui::Color32::from_rgba_premultiplied(105, 25, 29, 68)
|
||||
} else {
|
||||
egui::Color32::from_rgba_premultiplied(92, 66, 18, 62)
|
||||
},
|
||||
);
|
||||
ui.painter().rect_stroke(
|
||||
rect,
|
||||
2.0,
|
||||
egui::Stroke::new(2.0, color),
|
||||
egui::StrokeKind::Inside,
|
||||
);
|
||||
if rect.width() > 150.0 {
|
||||
ui.painter().text(
|
||||
rect.right_center() - egui::vec2(7.0, 0.0),
|
||||
egui::Align2::RIGHT_CENTER,
|
||||
if invalid { "BLOCKED" } else { "ATTACH" },
|
||||
egui::FontId::new(9.0, egui::FontFamily::Proportional),
|
||||
color,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn draw_generated_node(
|
||||
world: &World,
|
||||
ui: &mut egui::Ui,
|
||||
@@ -558,8 +689,22 @@ fn draw_runtime_node(
|
||||
ui.add_space(18.0);
|
||||
let label = hierarchy_label_for_entity(world, entity, HierarchyNodeKind::Runtime);
|
||||
let selected = selected_entities.contains(entity);
|
||||
let primary = selected_entities.as_slice().first().copied() == Some(entity);
|
||||
let color = if selected { TEXT_SELECTED } else { TEXT_DIM };
|
||||
let response = ui.selectable_label(selected, hierarchy_label_text(label, color));
|
||||
if selected {
|
||||
ui.painter().line_segment(
|
||||
[response.rect.left_top(), response.rect.left_bottom()],
|
||||
egui::Stroke::new(
|
||||
if primary { 3.0 } else { 2.0 },
|
||||
if primary {
|
||||
SELECTION
|
||||
} else {
|
||||
SELECTION_SECONDARY
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
if response.clicked() {
|
||||
selected_entities.select_replace(entity);
|
||||
}
|
||||
@@ -609,23 +754,62 @@ fn authored_context_menu(
|
||||
selected_entities: &mut SelectedEntities,
|
||||
renaming_entity: &mut Option<Entity>,
|
||||
rename_buffer: &mut String,
|
||||
locked: &std::collections::HashSet<Entity>,
|
||||
) {
|
||||
if ui.button("Rename").clicked() {
|
||||
let entity_locked = is_entity_locked(locked, entity);
|
||||
let linked_read_only = is_linked_read_only(world, entity);
|
||||
let prefab_member = world.get::<HydratedPrefabMember>(entity).is_some();
|
||||
let entity_mutable = !entity_locked && !linked_read_only;
|
||||
let selection_mutable = selected_entities.iter().all(|selected| {
|
||||
!is_entity_locked(locked, selected) && !is_linked_read_only(world, selected)
|
||||
});
|
||||
if entity_locked {
|
||||
ui.small(egui::RichText::new("Actor locked").color(TEXT_DIM));
|
||||
ui.separator();
|
||||
} else if linked_read_only {
|
||||
ui.small(egui::RichText::new("Linked source member").color(TEXT_DIM));
|
||||
ui.separator();
|
||||
}
|
||||
if ui
|
||||
.add_enabled(entity_mutable, egui::Button::new("Rename"))
|
||||
.clicked()
|
||||
{
|
||||
*renaming_entity = Some(entity);
|
||||
*rename_buffer = entity_name(world, entity);
|
||||
ui.close();
|
||||
}
|
||||
if ui.button("Duplicate").clicked() {
|
||||
if ui
|
||||
.add_enabled(entity_mutable, egui::Button::new("Duplicate"))
|
||||
.clicked()
|
||||
{
|
||||
duplicate_entities_with_history(world, &[entity]);
|
||||
ui.close();
|
||||
}
|
||||
if ui.button("Delete").clicked() {
|
||||
if ui
|
||||
.add_enabled(entity_mutable, egui::Button::new("Delete"))
|
||||
.clicked()
|
||||
{
|
||||
delete_entities_with_history(world, &[entity]);
|
||||
ui.close();
|
||||
}
|
||||
if prefab_member && !entity_locked {
|
||||
if ui.button("Remove from prefab instance").clicked() {
|
||||
crate::assets::prefab_overrides::remove_prefab_source_child(world, entity);
|
||||
selected_entities.remove(entity);
|
||||
ui.close();
|
||||
return;
|
||||
}
|
||||
if ui.button("Unparent override").clicked() {
|
||||
crate::assets::prefab_overrides::reparent_prefab_source_child(world, entity, None);
|
||||
ui.close();
|
||||
return;
|
||||
}
|
||||
}
|
||||
if selected_entities.len() >= 2
|
||||
&& selected_entities.contains(entity)
|
||||
&& ui.button("Group").clicked()
|
||||
&& ui
|
||||
.add_enabled(selection_mutable, egui::Button::new("Group"))
|
||||
.clicked()
|
||||
{
|
||||
let entities: Vec<Entity> = selected_entities
|
||||
.iter()
|
||||
@@ -634,11 +818,17 @@ fn authored_context_menu(
|
||||
group_selection_with_history(world, &entities);
|
||||
ui.close();
|
||||
}
|
||||
if ui.button("Unparent").clicked() {
|
||||
if ui
|
||||
.add_enabled(entity_mutable, egui::Button::new("Unparent"))
|
||||
.clicked()
|
||||
{
|
||||
reparent_with_history(world, entity, None);
|
||||
ui.close();
|
||||
}
|
||||
if ui.button("Create child Empty").clicked() {
|
||||
let create_child = ui
|
||||
.add_enabled(entity_mutable, egui::Button::new("Create child Empty"))
|
||||
.on_disabled_hover_text("Locked and generated source actors cannot be modified");
|
||||
if create_child.clicked() {
|
||||
create_empty_child_with_history(world, entity);
|
||||
ui.close();
|
||||
}
|
||||
@@ -650,8 +840,167 @@ fn authored_context_menu(
|
||||
}
|
||||
}
|
||||
|
||||
fn apply_drop(world: &mut World, drag: &HierarchyDragPayload, target: DropTarget, invalid: bool) {
|
||||
if invalid || drag.entities.is_empty() {
|
||||
fn top_level_drag_entities(world: &World, candidates: &[Entity]) -> Vec<Entity> {
|
||||
candidates
|
||||
.iter()
|
||||
.copied()
|
||||
.filter(|entity| {
|
||||
!candidates
|
||||
.iter()
|
||||
.copied()
|
||||
.any(|other| other != *entity && is_ancestor(world, other, *entity))
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn draggable_selection(
|
||||
world: &World,
|
||||
candidates: &[Entity],
|
||||
locked: &std::collections::HashSet<Entity>,
|
||||
) -> Vec<Entity> {
|
||||
let editable: Vec<_> = candidates
|
||||
.iter()
|
||||
.copied()
|
||||
.filter(|entity| {
|
||||
is_level_object(world, *entity)
|
||||
&& !is_entity_locked(locked, *entity)
|
||||
&& (!is_linked_read_only(world, *entity)
|
||||
|| world.get::<HydratedPrefabMember>(*entity).is_some())
|
||||
})
|
||||
.collect();
|
||||
top_level_drag_entities(world, &editable)
|
||||
}
|
||||
|
||||
fn draw_hierarchy_drag_preview(
|
||||
world: &World,
|
||||
ui: &egui::Ui,
|
||||
drag_entities: Option<&[Entity]>,
|
||||
target: Option<DropTarget>,
|
||||
block: Option<DropBlock>,
|
||||
) {
|
||||
let Some(entities) = drag_entities.filter(|entities| !entities.is_empty()) else {
|
||||
return;
|
||||
};
|
||||
let Some(pointer) = ui.input(|input| input.pointer.hover_pos()) else {
|
||||
return;
|
||||
};
|
||||
|
||||
let title = if entities.len() == 1 {
|
||||
entity_name(world, entities[0])
|
||||
} else {
|
||||
format!("{} ACTORS", entities.len())
|
||||
};
|
||||
let action = if let Some(block) = block {
|
||||
match block {
|
||||
DropBlock::Hierarchy(HierarchyDropViolation::Cycle) => "Cannot attach: hierarchy cycle",
|
||||
DropBlock::Hierarchy(HierarchyDropViolation::PrefabBoundary { .. }) => {
|
||||
"Cannot attach: prefab contents are read-only"
|
||||
}
|
||||
DropBlock::LockedTarget(_) => "Cannot attach: target is locked",
|
||||
}
|
||||
} else {
|
||||
match target {
|
||||
Some(DropTarget::Root) => "Move to scene root",
|
||||
Some(DropTarget::On(parent)) => {
|
||||
return draw_hierarchy_drag_preview_card(
|
||||
ui,
|
||||
pointer,
|
||||
&title,
|
||||
&format!("Attach to {}", entity_name(world, parent)),
|
||||
false,
|
||||
);
|
||||
}
|
||||
Some(DropTarget::Before(sibling)) => {
|
||||
return draw_hierarchy_drag_preview_card(
|
||||
ui,
|
||||
pointer,
|
||||
&title,
|
||||
&format!("Insert before {}", entity_name(world, sibling)),
|
||||
false,
|
||||
);
|
||||
}
|
||||
None => "Drop on an actor to attach",
|
||||
}
|
||||
};
|
||||
draw_hierarchy_drag_preview_card(ui, pointer, &title, action, block.is_some());
|
||||
}
|
||||
|
||||
fn draw_hierarchy_drag_preview_card(
|
||||
ui: &egui::Ui,
|
||||
pointer: egui::Pos2,
|
||||
title: &str,
|
||||
action: &str,
|
||||
invalid: bool,
|
||||
) {
|
||||
let content = ui.ctx().content_rect();
|
||||
let pos = egui::pos2(
|
||||
(pointer.x + 18.0).min(content.right() - 248.0),
|
||||
(pointer.y + 18.0).min(content.bottom() - 58.0),
|
||||
);
|
||||
egui::Area::new(egui::Id::new("hierarchy_drag_preview"))
|
||||
.fixed_pos(pos)
|
||||
.default_size(egui::vec2(236.0, 56.0))
|
||||
.order(egui::Order::Tooltip)
|
||||
.interactable(false)
|
||||
.show(ui.ctx(), |ui| {
|
||||
ui.set_min_size(egui::vec2(236.0, 56.0));
|
||||
ui.set_max_size(egui::vec2(236.0, 56.0));
|
||||
overlay_chip_frame().show(ui, |ui| {
|
||||
ui.set_width(218.0);
|
||||
ui.horizontal(|ui| {
|
||||
ui.label(
|
||||
phosphor_icon(icons::TREE_STRUCTURE, 18.0).color(if invalid {
|
||||
ERROR
|
||||
} else {
|
||||
ACCENT
|
||||
}),
|
||||
);
|
||||
ui.vertical(|ui| {
|
||||
ui.spacing_mut().item_spacing.y = 1.0;
|
||||
ui.label(egui::RichText::new(title).strong().color(TEXT_SELECTED));
|
||||
ui.label(egui::RichText::new(action).size(11.0).color(if invalid {
|
||||
ERROR
|
||||
} else {
|
||||
TEXT_DIM
|
||||
}));
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
fn apply_drop(
|
||||
world: &mut World,
|
||||
drag: &HierarchyDragPayload,
|
||||
target: DropTarget,
|
||||
block: Option<DropBlock>,
|
||||
) {
|
||||
if block.is_some() || drag.entities.is_empty() {
|
||||
return;
|
||||
}
|
||||
let prefab_members = drag
|
||||
.entities
|
||||
.iter()
|
||||
.all(|entity| world.get::<HydratedPrefabMember>(*entity).is_some());
|
||||
if prefab_members {
|
||||
match target {
|
||||
DropTarget::Root => {
|
||||
crate::assets::prefab_overrides::reparent_prefab_source_children(
|
||||
world,
|
||||
&drag.entities,
|
||||
None,
|
||||
);
|
||||
}
|
||||
DropTarget::On(parent) => {
|
||||
crate::assets::prefab_overrides::reparent_prefab_source_children(
|
||||
world,
|
||||
&drag.entities,
|
||||
Some(parent),
|
||||
);
|
||||
expand_parent_after_drop(world, parent);
|
||||
}
|
||||
DropTarget::Before(_) => {}
|
||||
}
|
||||
return;
|
||||
}
|
||||
match target {
|
||||
@@ -660,14 +1009,18 @@ fn apply_drop(world: &mut World, drag: &HierarchyDragPayload, target: DropTarget
|
||||
}
|
||||
DropTarget::On(parent) => {
|
||||
reorder_siblings_with_history(world, &drag.entities, Some(parent), i32::MAX);
|
||||
expand_parent_after_drop(world, parent);
|
||||
}
|
||||
DropTarget::Before(before) => {
|
||||
let parent = world
|
||||
.get::<ChildOf>(before)
|
||||
.map(|child_of| child_of.parent());
|
||||
let siblings = match parent {
|
||||
Some(parent) => authored_children(world, parent),
|
||||
None => level_object_roots(world),
|
||||
Some(parent) => mutable_authored_children(world, parent),
|
||||
None => level_object_roots(world)
|
||||
.into_iter()
|
||||
.filter(|entity| !is_linked_read_only(world, *entity))
|
||||
.collect(),
|
||||
};
|
||||
let insert_index = siblings
|
||||
.iter()
|
||||
@@ -678,6 +1031,53 @@ fn apply_drop(world: &mut World, drag: &HierarchyDragPayload, target: DropTarget
|
||||
}
|
||||
}
|
||||
|
||||
fn drop_block_for_target(
|
||||
world: &World,
|
||||
locked: &std::collections::HashSet<Entity>,
|
||||
drag_entities: &[Entity],
|
||||
new_parent: Option<Entity>,
|
||||
target: Entity,
|
||||
) -> Option<DropBlock> {
|
||||
if is_entity_locked(locked, target)
|
||||
|| new_parent.is_some_and(|parent| is_entity_locked(locked, parent))
|
||||
{
|
||||
return Some(DropBlock::LockedTarget(target));
|
||||
}
|
||||
if is_linked_read_only(world, target) {
|
||||
if world.get::<HydratedPrefabMember>(target).is_some()
|
||||
&& hierarchy_drop_violation(world, drag_entities, new_parent).is_none()
|
||||
{
|
||||
return None;
|
||||
}
|
||||
let root = crate::assets::prefab_overrides::prefab_member_override_target(world, target)
|
||||
.map(|(root, _)| root)
|
||||
.unwrap_or(target);
|
||||
return Some(DropBlock::Hierarchy(
|
||||
HierarchyDropViolation::PrefabBoundary { root },
|
||||
));
|
||||
}
|
||||
hierarchy_drop_violation(world, drag_entities, new_parent).map(DropBlock::Hierarchy)
|
||||
}
|
||||
|
||||
fn expand_parent_after_drop(world: &mut World, parent: Entity) {
|
||||
let path = entity_hierarchy_path(world, parent);
|
||||
{
|
||||
let mut state = world.resource_mut::<HierarchyPanelState>();
|
||||
if state.expanded.insert(parent) {
|
||||
state.mark_dirty();
|
||||
}
|
||||
}
|
||||
|
||||
let mut prefs = world.resource_mut::<UserPreferences>();
|
||||
if !prefs
|
||||
.hierarchy_expanded_paths
|
||||
.iter()
|
||||
.any(|entry| entry == &path)
|
||||
{
|
||||
prefs.hierarchy_expanded_paths.push(path);
|
||||
}
|
||||
}
|
||||
|
||||
fn subtree_matches_filter(
|
||||
world: &World,
|
||||
entity: Entity,
|
||||
@@ -744,3 +1144,76 @@ pub(crate) fn is_runtime_hierarchy_entity(world: &World, entity: Entity) -> bool
|
||||
|| entity_ref.contains::<ProjectSun>())
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use shared::LevelObject;
|
||||
|
||||
#[test]
|
||||
fn drag_selection_keeps_only_top_level_actors() {
|
||||
let mut world = World::new();
|
||||
let parent = world.spawn(LevelObject).id();
|
||||
let child = world.spawn((LevelObject, ChildOf(parent))).id();
|
||||
let peer = world.spawn(LevelObject).id();
|
||||
|
||||
let normalized = top_level_drag_entities(&world, &[parent, child, peer]);
|
||||
|
||||
assert_eq!(normalized, vec![parent, peer]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn drag_selection_excludes_locked_actors_before_subtree_normalization() {
|
||||
let mut world = World::new();
|
||||
let parent = world.spawn(LevelObject).id();
|
||||
let child = world.spawn((LevelObject, ChildOf(parent))).id();
|
||||
let peer = world.spawn(LevelObject).id();
|
||||
let locked = std::collections::HashSet::from([parent]);
|
||||
|
||||
let normalized = draggable_selection(&world, &[parent, child, peer], &locked);
|
||||
|
||||
assert_eq!(normalized, vec![child, peer]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn locked_drop_target_reports_specific_block() {
|
||||
let mut world = World::new();
|
||||
let actor = world.spawn(LevelObject).id();
|
||||
let target = world.spawn(LevelObject).id();
|
||||
let locked = std::collections::HashSet::from([target]);
|
||||
|
||||
assert_eq!(
|
||||
drop_block_for_target(&world, &locked, &[actor], Some(target), target),
|
||||
Some(DropBlock::LockedTarget(target))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deep_filtered_tree_keeps_matching_descendant_discoverable() {
|
||||
let mut world = World::new();
|
||||
let root = world.spawn((LevelObject, Name::new("Root"))).id();
|
||||
let mut parent = root;
|
||||
for depth in 0..64 {
|
||||
parent = world
|
||||
.spawn((
|
||||
LevelObject,
|
||||
Name::new(if depth == 63 { "Needle" } else { "Branch" }),
|
||||
ChildOf(parent),
|
||||
))
|
||||
.id();
|
||||
}
|
||||
|
||||
assert!(subtree_matches_filter(
|
||||
&world,
|
||||
root,
|
||||
"needle",
|
||||
HierarchySort::Manual
|
||||
));
|
||||
assert!(!subtree_matches_filter(
|
||||
&world,
|
||||
root,
|
||||
"missing",
|
||||
HierarchySort::Manual
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
use bevy::prelude::*;
|
||||
use shared::{
|
||||
ActorKind, AuthoringLightKind, EditorVisibility, HierarchySiblingIndex, LevelObject, LightDesc,
|
||||
ModelRef, PhysicsBody, PlayerSpawn,
|
||||
ActorKind, AuthoringLightKind, EditorVisibility, HierarchySiblingIndex, HydratedPrefabMember,
|
||||
LevelObject, LightDesc, ModelRef, PhysicsBody, PlayerSpawn, PrefabInstance,
|
||||
};
|
||||
|
||||
use super::helpers::{entity_name, is_level_object, HierarchyNodeKind};
|
||||
@@ -44,6 +44,66 @@ pub fn would_create_cycle(world: &World, targets: &[Entity], new_parent: Option<
|
||||
.any(|entity| is_ancestor(world, *entity, parent))
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum HierarchyDropViolation {
|
||||
Cycle,
|
||||
PrefabBoundary { root: Entity },
|
||||
}
|
||||
|
||||
/// Returns the authored prefab-instance root containing `entity`, including the root itself.
|
||||
pub fn prefab_instance_boundary(world: &World, entity: Entity) -> Option<Entity> {
|
||||
let mut current = Some(entity);
|
||||
while let Some(candidate) = current {
|
||||
if world.get::<PrefabInstance>(candidate).is_some() {
|
||||
return Some(candidate);
|
||||
}
|
||||
current = world
|
||||
.get::<ChildOf>(candidate)
|
||||
.map(|child_of| child_of.parent())
|
||||
.filter(|parent| is_level_object(world, *parent));
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
/// Authored local children may be attached to instances; hydrated source members remain read-only.
|
||||
pub fn hierarchy_drop_violation(
|
||||
world: &World,
|
||||
targets: &[Entity],
|
||||
new_parent: Option<Entity>,
|
||||
) -> Option<HierarchyDropViolation> {
|
||||
if would_create_cycle(world, targets, new_parent) {
|
||||
return Some(HierarchyDropViolation::Cycle);
|
||||
}
|
||||
let prefab_targets: Vec<_> = targets
|
||||
.iter()
|
||||
.filter_map(|target| {
|
||||
crate::assets::prefab_overrides::prefab_member_override_target(world, *target)
|
||||
})
|
||||
.collect();
|
||||
if !prefab_targets.is_empty() {
|
||||
let (root, path) = &prefab_targets[0];
|
||||
let compatible_targets = prefab_targets.len() == targets.len()
|
||||
&& prefab_targets.iter().all(|(candidate_root, candidate)| {
|
||||
candidate_root == root && candidate.instance_chain == path.instance_chain
|
||||
});
|
||||
let compatible_parent = new_parent.is_none_or(|parent| {
|
||||
crate::assets::prefab_overrides::prefab_member_override_target(world, parent)
|
||||
.is_some_and(|(parent_root, parent_path)| {
|
||||
parent_root == *root && parent_path.instance_chain == path.instance_chain
|
||||
})
|
||||
});
|
||||
if compatible_targets && compatible_parent {
|
||||
return None;
|
||||
}
|
||||
return Some(HierarchyDropViolation::PrefabBoundary { root: *root });
|
||||
}
|
||||
new_parent
|
||||
.and_then(|parent| world.get::<HydratedPrefabMember>(parent))
|
||||
.map(|owner| HierarchyDropViolation::PrefabBoundary {
|
||||
root: owner.instance_root,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn level_object_roots(world: &mut World) -> Vec<Entity> {
|
||||
let mut query = world.query_filtered::<(Entity, Option<&ChildOf>), With<LevelObject>>();
|
||||
query
|
||||
@@ -67,6 +127,30 @@ pub fn authored_children(world: &World, parent: Entity) -> Vec<Entity> {
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
pub fn mutable_authored_children(world: &World, parent: Entity) -> Vec<Entity> {
|
||||
authored_children(world, parent)
|
||||
.into_iter()
|
||||
.filter(|entity| {
|
||||
world.get::<HydratedPrefabMember>(*entity).is_none()
|
||||
&& world
|
||||
.get::<crate::scene_io::ComposedSceneMember>(*entity)
|
||||
.is_none()
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn mutable_level_object_roots(world: &mut World) -> Vec<Entity> {
|
||||
level_object_roots(world)
|
||||
.into_iter()
|
||||
.filter(|entity| {
|
||||
world.get::<HydratedPrefabMember>(*entity).is_none()
|
||||
&& world
|
||||
.get::<crate::scene_io::ComposedSceneMember>(*entity)
|
||||
.is_none()
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn entity_tie_break(a: Entity, b: Entity) -> std::cmp::Ordering {
|
||||
a.to_bits().cmp(&b.to_bits())
|
||||
}
|
||||
@@ -75,8 +159,9 @@ pub fn sort_siblings(world: &World, entities: &mut [Entity], sort_mode: Hierarch
|
||||
match sort_mode {
|
||||
HierarchySort::Manual => {
|
||||
entities.sort_by(|a, b| {
|
||||
sibling_index(world, *a)
|
||||
.cmp(&sibling_index(world, *b))
|
||||
linked_order_class(world, *a)
|
||||
.cmp(&linked_order_class(world, *b))
|
||||
.then_with(|| sibling_index(world, *a).cmp(&sibling_index(world, *b)))
|
||||
.then_with(|| entity_tie_break(*a, *b))
|
||||
});
|
||||
}
|
||||
@@ -100,6 +185,18 @@ pub fn sort_siblings(world: &World, entities: &mut [Entity], sort_mode: Hierarch
|
||||
}
|
||||
}
|
||||
|
||||
fn linked_order_class(world: &World, entity: Entity) -> u8 {
|
||||
if world.get::<HydratedPrefabMember>(entity).is_some()
|
||||
|| world
|
||||
.get::<crate::scene_io::ComposedSceneMember>(entity)
|
||||
.is_some()
|
||||
{
|
||||
0
|
||||
} else {
|
||||
1
|
||||
}
|
||||
}
|
||||
|
||||
fn actor_kind_sort_key(world: &World, entity: Entity) -> u8 {
|
||||
world
|
||||
.get::<ActorKind>(entity)
|
||||
@@ -108,6 +205,7 @@ fn actor_kind_sort_key(world: &World, entity: Entity) -> u8 {
|
||||
ActorKind::Empty => 0,
|
||||
ActorKind::Brush | ActorKind::StaticMesh | ActorKind::ImportedModel => 1,
|
||||
ActorKind::Light => 2,
|
||||
ActorKind::AudioSource | ActorKind::AudioListener => 3,
|
||||
ActorKind::PrefabAnchor => 3,
|
||||
ActorKind::PlayerSpawn => 4,
|
||||
ActorKind::WeaponSpawn => 5,
|
||||
@@ -160,6 +258,7 @@ pub fn renumber_siblings(world: &mut World, parent: Option<Entity>, ordered: &[E
|
||||
}
|
||||
|
||||
pub fn capture_sibling_state(world: &World, entity: Entity) -> SiblingChange {
|
||||
let transform = world.get::<Transform>(entity).copied();
|
||||
SiblingChange {
|
||||
entity,
|
||||
old_parent: world
|
||||
@@ -170,6 +269,8 @@ pub fn capture_sibling_state(world: &World, entity: Entity) -> SiblingChange {
|
||||
.map(|child_of| child_of.parent()),
|
||||
old_index: sibling_index(world, entity),
|
||||
new_index: sibling_index(world, entity),
|
||||
old_transform: transform,
|
||||
new_transform: transform,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,6 +282,9 @@ pub fn apply_sibling_change(world: &mut World, change: &SiblingChange) {
|
||||
entity_mut.remove::<ChildOf>();
|
||||
}
|
||||
entity_mut.insert(HierarchySiblingIndex(change.old_index));
|
||||
if let Some(transform) = change.old_transform {
|
||||
entity_mut.insert(transform);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -192,6 +296,9 @@ pub fn apply_sibling_change_new(world: &mut World, change: &SiblingChange) {
|
||||
entity_mut.remove::<ChildOf>();
|
||||
}
|
||||
entity_mut.insert(HierarchySiblingIndex(change.new_index));
|
||||
if let Some(transform) = change.new_transform {
|
||||
entity_mut.insert(transform);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -235,8 +342,8 @@ fn renumber_inserted_siblings(
|
||||
insert_index: i32,
|
||||
) -> Vec<SiblingChange> {
|
||||
let mut siblings = match new_parent {
|
||||
Some(parent) => authored_children(world, parent),
|
||||
None => level_object_roots(world),
|
||||
Some(parent) => mutable_authored_children(world, parent),
|
||||
None => mutable_level_object_roots(world),
|
||||
};
|
||||
siblings.retain(|entity| !moving.contains(entity));
|
||||
let insert = insert_index.clamp(0, siblings.len() as i32) as usize;
|
||||
@@ -252,8 +359,8 @@ fn renumber_existing_siblings(
|
||||
exclude: &[Entity],
|
||||
) -> Vec<SiblingChange> {
|
||||
let mut siblings = match parent {
|
||||
Some(parent) => authored_children(world, parent),
|
||||
None => level_object_roots(world),
|
||||
Some(parent) => mutable_authored_children(world, parent),
|
||||
None => mutable_level_object_roots(world),
|
||||
};
|
||||
siblings.retain(|entity| !exclude.contains(entity));
|
||||
sort_siblings(world, &mut siblings, HierarchySort::Manual);
|
||||
@@ -272,6 +379,20 @@ fn apply_sibling_order(
|
||||
.map(|child_of| child_of.parent());
|
||||
let old_index = sibling_index(world, *entity);
|
||||
let new_index = index as i32;
|
||||
let old_transform = world.get::<Transform>(*entity).copied();
|
||||
let new_transform = if old_parent != parent {
|
||||
world
|
||||
.get::<GlobalTransform>(*entity)
|
||||
.map(|global| {
|
||||
match parent.and_then(|parent| world.get::<GlobalTransform>(parent)) {
|
||||
Some(parent_global) => global.reparented_to(parent_global),
|
||||
None => global.compute_transform(),
|
||||
}
|
||||
})
|
||||
.or(old_transform)
|
||||
} else {
|
||||
old_transform
|
||||
};
|
||||
if old_parent != parent || old_index != new_index {
|
||||
changes.push(SiblingChange {
|
||||
entity: *entity,
|
||||
@@ -279,6 +400,8 @@ fn apply_sibling_order(
|
||||
new_parent: parent,
|
||||
old_index,
|
||||
new_index,
|
||||
old_transform,
|
||||
new_transform,
|
||||
});
|
||||
}
|
||||
if let Ok(mut entity_mut) = world.get_entity_mut(*entity) {
|
||||
@@ -288,6 +411,9 @@ fn apply_sibling_order(
|
||||
entity_mut.remove::<ChildOf>();
|
||||
}
|
||||
entity_mut.insert(HierarchySiblingIndex(new_index));
|
||||
if let Some(transform) = new_transform {
|
||||
entity_mut.insert(transform);
|
||||
}
|
||||
}
|
||||
}
|
||||
changes
|
||||
@@ -340,6 +466,8 @@ pub fn actor_kind_icon(kind: ActorKind) -> &'static str {
|
||||
ActorKind::StaticMesh => icons::CUBE.as_str(),
|
||||
ActorKind::ImportedModel => icons::CUBE_TRANSPARENT.as_str(),
|
||||
ActorKind::Light => icons::LIGHTBULB.as_str(),
|
||||
ActorKind::AudioSource => icons::SPEAKER_HIGH.as_str(),
|
||||
ActorKind::AudioListener => icons::HEADPHONES.as_str(),
|
||||
ActorKind::PrefabAnchor => icons::PACKAGE.as_str(),
|
||||
ActorKind::PlayerSpawn => icons::USER_CIRCLE.as_str(),
|
||||
ActorKind::WeaponSpawn => icons::CROSSHAIR.as_str(),
|
||||
@@ -434,6 +562,7 @@ pub fn is_entity_locked(locked: &std::collections::HashSet<Entity>, entity: Enti
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use shared::ActorId;
|
||||
|
||||
#[test]
|
||||
fn sort_by_name_is_stable_for_duplicate_names() {
|
||||
@@ -448,4 +577,99 @@ mod tests {
|
||||
sort_siblings(&world, &mut entities, HierarchySort::Name);
|
||||
assert_eq!(entities, first, "duplicate-name sort must be deterministic");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reparent_preserves_world_transform_and_round_trips_history() {
|
||||
let mut world = World::new();
|
||||
let parent = world
|
||||
.spawn((
|
||||
LevelObject,
|
||||
Transform::from_xyz(10.0, 0.0, 0.0),
|
||||
GlobalTransform::from_xyz(10.0, 0.0, 0.0),
|
||||
HierarchySiblingIndex(0),
|
||||
))
|
||||
.id();
|
||||
let child = world
|
||||
.spawn((
|
||||
LevelObject,
|
||||
Transform::from_xyz(12.0, 1.0, -3.0),
|
||||
GlobalTransform::from_xyz(12.0, 1.0, -3.0),
|
||||
HierarchySiblingIndex(1),
|
||||
))
|
||||
.id();
|
||||
|
||||
let changes = reorder_entities_under_parent(&mut world, &[child], Some(parent), 0);
|
||||
let child_change = changes
|
||||
.iter()
|
||||
.find(|change| change.entity == child)
|
||||
.expect("reparent should record the moved actor");
|
||||
|
||||
assert_eq!(world.get::<ChildOf>(child).unwrap().parent(), parent);
|
||||
assert_eq!(
|
||||
world.get::<Transform>(child).unwrap().translation,
|
||||
Vec3::new(2.0, 1.0, -3.0)
|
||||
);
|
||||
|
||||
apply_sibling_change(&mut world, child_change);
|
||||
assert!(world.get::<ChildOf>(child).is_none());
|
||||
assert_eq!(
|
||||
world.get::<Transform>(child).unwrap().translation,
|
||||
Vec3::new(12.0, 1.0, -3.0)
|
||||
);
|
||||
|
||||
apply_sibling_change_new(&mut world, child_change);
|
||||
assert_eq!(world.get::<ChildOf>(child).unwrap().parent(), parent);
|
||||
assert_eq!(
|
||||
world.get::<Transform>(child).unwrap().translation,
|
||||
Vec3::new(2.0, 1.0, -3.0)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cycle_detection_rejects_descendant_parent() {
|
||||
let mut world = World::new();
|
||||
let parent = world.spawn(LevelObject).id();
|
||||
let child = world.spawn((LevelObject, ChildOf(parent))).id();
|
||||
|
||||
assert!(would_create_cycle(&world, &[parent], Some(child)));
|
||||
assert!(!would_create_cycle(&world, &[child], None));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn prefab_boundary_allows_local_and_same_layer_override_structure() {
|
||||
let mut world = World::new();
|
||||
let instance = world.spawn((LevelObject, PrefabInstance::default())).id();
|
||||
let local_child = world.spawn((LevelObject, ChildOf(instance))).id();
|
||||
let generated_child = world
|
||||
.spawn((
|
||||
LevelObject,
|
||||
ActorId::new("generated-child"),
|
||||
ChildOf(instance),
|
||||
HydratedPrefabMember {
|
||||
instance_root: instance,
|
||||
},
|
||||
))
|
||||
.id();
|
||||
let actor = world.spawn(LevelObject).id();
|
||||
let nested_instance = world.spawn((LevelObject, PrefabInstance::default())).id();
|
||||
|
||||
assert_eq!(
|
||||
hierarchy_drop_violation(&world, &[actor], Some(instance)),
|
||||
None
|
||||
);
|
||||
assert_eq!(
|
||||
hierarchy_drop_violation(&world, &[nested_instance], Some(local_child)),
|
||||
None
|
||||
);
|
||||
assert_eq!(
|
||||
hierarchy_drop_violation(&world, &[nested_instance], Some(generated_child)),
|
||||
Some(HierarchyDropViolation::PrefabBoundary { root: instance })
|
||||
);
|
||||
assert_eq!(
|
||||
hierarchy_drop_violation(&world, &[generated_child], None),
|
||||
None
|
||||
);
|
||||
assert_eq!(hierarchy_drop_violation(&world, &[instance], None), None);
|
||||
assert_eq!(hierarchy_drop_violation(&world, &[local_child], None), None);
|
||||
}
|
||||
}
|
||||
@@ -8,22 +8,26 @@ use bevy_egui::egui;
|
||||
use egui_phosphor_icons::{icons, Icon};
|
||||
use shared::{
|
||||
brush_math::{validate_brush, BrushDiagnosticSeverity},
|
||||
inspector_component_active, AuthoringLightKind, AuthoringRigidBody, BrushDesc, BrushKind,
|
||||
ColliderDesc, ColliderShapeDesc, ColorDesc, ComponentInstanceId, EditorAssetRef,
|
||||
infer_actor_kind, inspector_component_active, ActorKind, AnimationControllerDesc,
|
||||
AudioListenerDesc, AudioSourceDesc, AuthoringLightKind, AuthoringRigidBody, BrushDesc,
|
||||
BrushKind, ColliderDesc, ColliderShapeDesc, ColorDesc, ComponentInstanceId, EditorAssetRef,
|
||||
InspectorOrder, LevelObject, LightDesc, MaterialDesc, MaterialParameter,
|
||||
MaterialParameterValue, MaterialShaderKind, ObjectiveMarker, PhysicsBody, PlayerSpawn,
|
||||
PostProcessVolumeDesc, PrefabInstance, Primitive, PrimitiveShape, ProjectSun, RigidBodyDesc,
|
||||
StaticMeshRenderer, StaticMeshRendererEntry, TeamSpawn, TriggerVolume, WeaponSpawn,
|
||||
AUTHORING_DIRECTIONAL_LUX_MAX, AUTHORING_POINT_SPOT_LUMENS_MAX, COMPONENT_BRUSH_DESC,
|
||||
COMPONENT_COLLIDER_DESC, COMPONENT_LIGHT_DESC, COMPONENT_MATERIAL_DESC,
|
||||
COMPONENT_OBJECTIVE_MARKER, COMPONENT_PHYSICS_BODY, COMPONENT_PLAYER_SPAWN,
|
||||
COMPONENT_POST_PROCESS_VOLUME, COMPONENT_PREFAB_INSTANCE, COMPONENT_PRIMITIVE,
|
||||
COMPONENT_PROJECT_SUN, COMPONENT_RIGID_BODY_DESC, COMPONENT_STATIC_MESH_RENDERER,
|
||||
COMPONENT_TEAM_SPAWN, COMPONENT_TRIGGER_VOLUME, COMPONENT_WEAPON_SPAWN,
|
||||
MaterialParameterValue, MaterialShaderKind, ModelRef, ObjectiveMarker, PhysicsBody,
|
||||
PlayerSpawn, PostProcessVolumeDesc, PrefabInstance, Primitive, PrimitiveShape, ProjectSun,
|
||||
RigidBodyDesc, StaticMeshRenderer, StaticMeshRendererEntry, TeamSpawn, TriggerVolume,
|
||||
WeaponSpawn, AUTHORING_DIRECTIONAL_LUX_MAX, AUTHORING_POINT_SPOT_LUMENS_MAX,
|
||||
COMPONENT_ANIMATION_CONTROLLER_DESC, COMPONENT_AUDIO_LISTENER_DESC,
|
||||
COMPONENT_AUDIO_SOURCE_DESC, COMPONENT_BRUSH_DESC, COMPONENT_COLLIDER_DESC,
|
||||
COMPONENT_LIGHT_DESC, COMPONENT_MATERIAL_DESC, COMPONENT_OBJECTIVE_MARKER,
|
||||
COMPONENT_PHYSICS_BODY, COMPONENT_PLAYER_SPAWN, COMPONENT_POST_PROCESS_VOLUME,
|
||||
COMPONENT_PREFAB_INSTANCE, COMPONENT_PRIMITIVE, COMPONENT_PROJECT_SUN,
|
||||
COMPONENT_RIGID_BODY_DESC, COMPONENT_STATIC_MESH_RENDERER, COMPONENT_TEAM_SPAWN,
|
||||
COMPONENT_TRIGGER_VOLUME, COMPONENT_WEAPON_SPAWN,
|
||||
};
|
||||
|
||||
use crate::history::{
|
||||
material_eq, set_brush_with_history, set_collider_with_history,
|
||||
material_eq, set_animation_controller_with_history, set_audio_listener_with_history,
|
||||
set_audio_source_with_history, set_brush_with_history, set_collider_with_history,
|
||||
set_inspector_order_with_history, set_light_with_history, set_material_with_history,
|
||||
set_physics_with_history, set_post_process_volume_with_history, set_primitive_with_history,
|
||||
set_rigid_body_with_history, set_static_mesh_renderer_with_history, EditorEntitySnapshot,
|
||||
@@ -134,11 +138,14 @@ enum AddComponentShelfDirection {
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
enum CopiedComponent {
|
||||
AnimationControllerDesc(AnimationControllerDesc),
|
||||
Primitive(Primitive),
|
||||
BrushDesc(BrushDesc),
|
||||
StaticMeshRenderer(StaticMeshRenderer),
|
||||
MaterialDesc(MaterialDesc),
|
||||
LightDesc(LightDesc),
|
||||
AudioSourceDesc(AudioSourceDesc),
|
||||
AudioListenerDesc(AudioListenerDesc),
|
||||
RigidBodyDesc(RigidBodyDesc),
|
||||
ColliderDesc(ColliderDesc),
|
||||
PhysicsBody(PhysicsBody),
|
||||
@@ -153,11 +160,14 @@ enum CopiedComponent {
|
||||
impl CopiedComponent {
|
||||
fn type_name(&self) -> &'static str {
|
||||
match self {
|
||||
Self::AnimationControllerDesc(_) => COMPONENT_ANIMATION_CONTROLLER_DESC,
|
||||
Self::Primitive(_) => COMPONENT_PRIMITIVE,
|
||||
Self::BrushDesc(_) => COMPONENT_BRUSH_DESC,
|
||||
Self::StaticMeshRenderer(_) => COMPONENT_STATIC_MESH_RENDERER,
|
||||
Self::MaterialDesc(_) => COMPONENT_MATERIAL_DESC,
|
||||
Self::LightDesc(_) => COMPONENT_LIGHT_DESC,
|
||||
Self::AudioSourceDesc(_) => COMPONENT_AUDIO_SOURCE_DESC,
|
||||
Self::AudioListenerDesc(_) => COMPONENT_AUDIO_LISTENER_DESC,
|
||||
Self::RigidBodyDesc(_) => COMPONENT_RIGID_BODY_DESC,
|
||||
Self::ColliderDesc(_) => COMPONENT_COLLIDER_DESC,
|
||||
Self::PhysicsBody(_) => COMPONENT_PHYSICS_BODY,
|
||||
@@ -357,6 +367,9 @@ fn component_card_key(world: &World, entity: Entity, type_name: &str) -> String
|
||||
|
||||
fn present_component_type_names(world: &World, entity: Entity) -> Vec<&'static str> {
|
||||
let mut present = Vec::new();
|
||||
if world.get::<AnimationControllerDesc>(entity).is_some() {
|
||||
present.push(COMPONENT_ANIMATION_CONTROLLER_DESC);
|
||||
}
|
||||
if world.get::<StaticMeshRenderer>(entity).is_some() {
|
||||
present.push(COMPONENT_STATIC_MESH_RENDERER);
|
||||
}
|
||||
@@ -372,6 +385,12 @@ fn present_component_type_names(world: &World, entity: Entity) -> Vec<&'static s
|
||||
if world.get::<LightDesc>(entity).is_some() {
|
||||
present.push(COMPONENT_LIGHT_DESC);
|
||||
}
|
||||
if world.get::<AudioSourceDesc>(entity).is_some() {
|
||||
present.push(COMPONENT_AUDIO_SOURCE_DESC);
|
||||
}
|
||||
if world.get::<AudioListenerDesc>(entity).is_some() {
|
||||
present.push(COMPONENT_AUDIO_LISTENER_DESC);
|
||||
}
|
||||
if world.get::<RigidBodyDesc>(entity).is_some() {
|
||||
present.push(COMPONENT_RIGID_BODY_DESC);
|
||||
}
|
||||
@@ -410,6 +429,10 @@ fn present_component_type_names(world: &World, entity: Entity) -> Vec<&'static s
|
||||
|
||||
fn copy_component(world: &mut World, entity: Entity, type_name: &str) {
|
||||
let component = match type_name {
|
||||
COMPONENT_ANIMATION_CONTROLLER_DESC => world
|
||||
.get::<AnimationControllerDesc>(entity)
|
||||
.cloned()
|
||||
.map(CopiedComponent::AnimationControllerDesc),
|
||||
COMPONENT_PRIMITIVE => world
|
||||
.get::<Primitive>(entity)
|
||||
.cloned()
|
||||
@@ -430,6 +453,14 @@ fn copy_component(world: &mut World, entity: Entity, type_name: &str) {
|
||||
.get::<LightDesc>(entity)
|
||||
.cloned()
|
||||
.map(CopiedComponent::LightDesc),
|
||||
COMPONENT_AUDIO_SOURCE_DESC => world
|
||||
.get::<AudioSourceDesc>(entity)
|
||||
.cloned()
|
||||
.map(CopiedComponent::AudioSourceDesc),
|
||||
COMPONENT_AUDIO_LISTENER_DESC => world
|
||||
.get::<AudioListenerDesc>(entity)
|
||||
.copied()
|
||||
.map(CopiedComponent::AudioListenerDesc),
|
||||
COMPONENT_RIGID_BODY_DESC => world
|
||||
.get::<RigidBodyDesc>(entity)
|
||||
.copied()
|
||||
@@ -478,6 +509,11 @@ fn paste_component(world: &mut World, entity: Entity, type_name: &str) {
|
||||
.get_resource::<InspectorClipboard>()
|
||||
.and_then(|clipboard| clipboard.component.clone());
|
||||
match component {
|
||||
Some(CopiedComponent::AnimationControllerDesc(value))
|
||||
if type_name == COMPONENT_ANIMATION_CONTROLLER_DESC =>
|
||||
{
|
||||
set_animation_controller_with_history(world, entity, value);
|
||||
}
|
||||
Some(CopiedComponent::Primitive(value)) if type_name == COMPONENT_PRIMITIVE => {
|
||||
set_primitive_with_history(world, entity, value);
|
||||
}
|
||||
@@ -495,6 +531,16 @@ fn paste_component(world: &mut World, entity: Entity, type_name: &str) {
|
||||
Some(CopiedComponent::LightDesc(value)) if type_name == COMPONENT_LIGHT_DESC => {
|
||||
set_light_with_history(world, entity, value);
|
||||
}
|
||||
Some(CopiedComponent::AudioSourceDesc(value))
|
||||
if type_name == COMPONENT_AUDIO_SOURCE_DESC =>
|
||||
{
|
||||
set_audio_source_with_history(world, entity, value);
|
||||
}
|
||||
Some(CopiedComponent::AudioListenerDesc(value))
|
||||
if type_name == COMPONENT_AUDIO_LISTENER_DESC =>
|
||||
{
|
||||
set_audio_listener_with_history(world, entity, value);
|
||||
}
|
||||
Some(CopiedComponent::RigidBodyDesc(value)) if type_name == COMPONENT_RIGID_BODY_DESC => {
|
||||
set_rigid_body_with_history(world, entity, value);
|
||||
}
|
||||
@@ -532,6 +578,11 @@ fn paste_component(world: &mut World, entity: Entity, type_name: &str) {
|
||||
|
||||
fn reset_component(world: &mut World, entity: Entity, type_name: &str) {
|
||||
match type_name {
|
||||
COMPONENT_ANIMATION_CONTROLLER_DESC => {
|
||||
let controller =
|
||||
crate::ui::animation_inspector::default_controller_for_actor(world, entity);
|
||||
set_animation_controller_with_history(world, entity, controller);
|
||||
}
|
||||
COMPONENT_PRIMITIVE => set_primitive_with_history(world, entity, Primitive::default()),
|
||||
COMPONENT_BRUSH_DESC => set_brush_with_history(world, entity, BrushDesc::default()),
|
||||
COMPONENT_STATIC_MESH_RENDERER => {
|
||||
@@ -541,6 +592,12 @@ fn reset_component(world: &mut World, entity: Entity, type_name: &str) {
|
||||
set_material_with_history(world, entity, MaterialDesc::default())
|
||||
}
|
||||
COMPONENT_LIGHT_DESC => set_light_with_history(world, entity, LightDesc::default()),
|
||||
COMPONENT_AUDIO_SOURCE_DESC => {
|
||||
set_audio_source_with_history(world, entity, AudioSourceDesc::default())
|
||||
}
|
||||
COMPONENT_AUDIO_LISTENER_DESC => {
|
||||
set_audio_listener_with_history(world, entity, AudioListenerDesc::default())
|
||||
}
|
||||
COMPONENT_RIGID_BODY_DESC => {
|
||||
set_rigid_body_with_history(world, entity, RigidBodyDesc::default());
|
||||
}
|
||||
@@ -586,8 +643,17 @@ fn remove_registered_component(world: &mut World, entity: Entity, type_name: &st
|
||||
let Some(before) = crate::history::snapshot_entity(world, entity) else {
|
||||
return;
|
||||
};
|
||||
let removed_dedicated_audio_kind = matches!(
|
||||
(type_name, before.actor_kind),
|
||||
(COMPONENT_AUDIO_SOURCE_DESC, ActorKind::AudioSource)
|
||||
| (COMPONENT_AUDIO_LISTENER_DESC, ActorKind::AudioListener)
|
||||
);
|
||||
let removed = if let Ok(mut entity_mut) = world.get_entity_mut(entity) {
|
||||
match type_name {
|
||||
COMPONENT_ANIMATION_CONTROLLER_DESC if before.animation_controller.is_some() => {
|
||||
entity_mut.remove::<AnimationControllerDesc>();
|
||||
true
|
||||
}
|
||||
COMPONENT_PRIMITIVE if before.primitive.is_some() => {
|
||||
entity_mut.remove::<Primitive>();
|
||||
true
|
||||
@@ -608,6 +674,14 @@ fn remove_registered_component(world: &mut World, entity: Entity, type_name: &st
|
||||
entity_mut.remove::<LightDesc>();
|
||||
true
|
||||
}
|
||||
COMPONENT_AUDIO_SOURCE_DESC if before.audio_source.is_some() => {
|
||||
entity_mut.remove::<AudioSourceDesc>();
|
||||
true
|
||||
}
|
||||
COMPONENT_AUDIO_LISTENER_DESC if before.audio_listener.is_some() => {
|
||||
entity_mut.remove::<AudioListenerDesc>();
|
||||
true
|
||||
}
|
||||
COMPONENT_RIGID_BODY_DESC if before.rigid_body.is_some() => {
|
||||
entity_mut.remove::<RigidBodyDesc>();
|
||||
true
|
||||
@@ -656,6 +730,19 @@ fn remove_registered_component(world: &mut World, entity: Entity, type_name: &st
|
||||
if !removed {
|
||||
return;
|
||||
}
|
||||
if type_name == COMPONENT_ANIMATION_CONTROLLER_DESC {
|
||||
crate::ui::animation_inspector::stop_preview_if_actor(world, entity);
|
||||
}
|
||||
if removed_dedicated_audio_kind {
|
||||
let fallback = world
|
||||
.get_entity(entity)
|
||||
.ok()
|
||||
.and_then(infer_actor_kind)
|
||||
.unwrap_or(ActorKind::Empty);
|
||||
if let Ok(mut entity_mut) = world.get_entity_mut(entity) {
|
||||
entity_mut.insert(fallback);
|
||||
}
|
||||
}
|
||||
if let Some(after) = crate::history::snapshot_entity(world, entity) {
|
||||
let snapshot = diff_added(&after, &before);
|
||||
crate::history::push_command(
|
||||
@@ -690,11 +777,20 @@ fn draw_authoring_component_by_type(
|
||||
type_name: &'static str,
|
||||
) {
|
||||
match type_name {
|
||||
COMPONENT_ANIMATION_CONTROLLER_DESC => {
|
||||
crate::ui::animation_inspector::animation_controller_inspector_ui(world, ui, entity);
|
||||
}
|
||||
COMPONENT_STATIC_MESH_RENDERER => static_mesh_renderer_ui(world, ui, entity),
|
||||
COMPONENT_BRUSH_DESC => brush_editor_ui(world, ui, entity),
|
||||
COMPONENT_PRIMITIVE => primitive_editor_ui(world, ui, entity),
|
||||
COMPONENT_MATERIAL_DESC => material_editor_ui(world, ui, entity),
|
||||
COMPONENT_LIGHT_DESC => light_editor_ui(world, ui, entity),
|
||||
COMPONENT_AUDIO_SOURCE_DESC => {
|
||||
crate::ui::audio_inspector::audio_source_inspector_ui(world, ui, entity);
|
||||
}
|
||||
COMPONENT_AUDIO_LISTENER_DESC => {
|
||||
crate::ui::audio_inspector::audio_listener_inspector_ui(world, ui, entity);
|
||||
}
|
||||
COMPONENT_RIGID_BODY_DESC => rigid_body_editor_ui(world, ui, entity),
|
||||
COMPONENT_COLLIDER_DESC => collider_editor_ui(world, ui, entity),
|
||||
COMPONENT_PHYSICS_BODY => physics_editor_ui(world, ui, entity),
|
||||
@@ -982,6 +1078,8 @@ fn filtered_component_descriptors<'a>(
|
||||
[
|
||||
EditorComponentCategory::Authoring,
|
||||
EditorComponentCategory::Rendering,
|
||||
EditorComponentCategory::Animation,
|
||||
EditorComponentCategory::Audio,
|
||||
EditorComponentCategory::Physics,
|
||||
EditorComponentCategory::Gameplay,
|
||||
EditorComponentCategory::Volumes,
|
||||
@@ -1002,6 +1100,8 @@ fn component_category_label(category: EditorComponentCategory) -> &'static str {
|
||||
match category {
|
||||
EditorComponentCategory::Authoring => "Authoring",
|
||||
EditorComponentCategory::Rendering => "Rendering",
|
||||
EditorComponentCategory::Animation => "Animation",
|
||||
EditorComponentCategory::Audio => "Audio",
|
||||
EditorComponentCategory::Physics => "Physics",
|
||||
EditorComponentCategory::Gameplay => "Gameplay",
|
||||
EditorComponentCategory::Volumes => "Volumes",
|
||||
@@ -1046,8 +1146,15 @@ fn component_add_state(
|
||||
.copied()
|
||||
.filter(|type_name| !component_present(world, entity, type_name))
|
||||
.collect::<Vec<_>>();
|
||||
let animation_target_missing = descriptor.type_name == COMPONENT_ANIMATION_CONTROLLER_DESC
|
||||
&& (!world
|
||||
.get::<ActorKind>(entity)
|
||||
.is_some_and(|kind| *kind == ActorKind::ImportedModel)
|
||||
|| world.get::<ModelRef>(entity).is_none());
|
||||
let reason = if duplicate {
|
||||
Some("Already present on this actor.".to_string())
|
||||
} else if animation_target_missing {
|
||||
Some("Animation Controller requires an ImportedModel actor with ModelRef.".to_string())
|
||||
} else if !conflicts.is_empty() {
|
||||
Some(format!(
|
||||
"Conflicts with {}.",
|
||||
@@ -1110,6 +1217,9 @@ fn component_display_name(
|
||||
|
||||
fn component_present(world: &World, entity: Entity, type_name: &str) -> bool {
|
||||
match type_name {
|
||||
COMPONENT_ANIMATION_CONTROLLER_DESC => {
|
||||
world.get::<AnimationControllerDesc>(entity).is_some()
|
||||
}
|
||||
"shared::components::Primitive" => world.get::<Primitive>(entity).is_some(),
|
||||
"shared::components::BrushDesc" => world.get::<BrushDesc>(entity).is_some(),
|
||||
"shared::components::StaticMeshRenderer" => {
|
||||
@@ -1117,6 +1227,8 @@ fn component_present(world: &World, entity: Entity, type_name: &str) -> bool {
|
||||
}
|
||||
"shared::components::MaterialDesc" => world.get::<MaterialDesc>(entity).is_some(),
|
||||
"shared::components::LightDesc" => world.get::<LightDesc>(entity).is_some(),
|
||||
"shared::components::AudioSourceDesc" => world.get::<AudioSourceDesc>(entity).is_some(),
|
||||
"shared::components::AudioListenerDesc" => world.get::<AudioListenerDesc>(entity).is_some(),
|
||||
"shared::components::RigidBodyDesc" => world.get::<RigidBodyDesc>(entity).is_some(),
|
||||
"shared::components::ColliderDesc" => world.get::<ColliderDesc>(entity).is_some(),
|
||||
"shared::components::PlayerSpawn" => world.get::<PlayerSpawn>(entity).is_some(),
|
||||
@@ -1133,6 +1245,13 @@ fn component_present(world: &World, entity: Entity, type_name: &str) -> bool {
|
||||
|
||||
fn insert_registered_component(world: &mut World, entity: Entity, type_name: &str) {
|
||||
match type_name {
|
||||
COMPONENT_ANIMATION_CONTROLLER_DESC => {
|
||||
let controller =
|
||||
crate::ui::animation_inspector::default_controller_for_actor(world, entity);
|
||||
insert_component(world, entity, move |world, e| {
|
||||
world.entity_mut(e).insert(controller);
|
||||
});
|
||||
}
|
||||
"shared::components::Primitive" => insert_component(world, entity, |world, e| {
|
||||
world
|
||||
.entity_mut(e)
|
||||
@@ -1154,6 +1273,17 @@ fn insert_registered_component(world: &mut World, entity: Entity, type_name: &st
|
||||
"shared::components::LightDesc" => insert_component(world, entity, |world, e| {
|
||||
world.entity_mut(e).insert(LightDesc::default());
|
||||
}),
|
||||
"shared::components::AudioSourceDesc" => insert_component(world, entity, |world, e| {
|
||||
world
|
||||
.entity_mut(e)
|
||||
.insert((shared::ActorKind::AudioSource, AudioSourceDesc::default()));
|
||||
}),
|
||||
"shared::components::AudioListenerDesc" => insert_component(world, entity, |world, e| {
|
||||
world.entity_mut(e).insert((
|
||||
shared::ActorKind::AudioListener,
|
||||
AudioListenerDesc::default(),
|
||||
));
|
||||
}),
|
||||
"shared::components::RigidBodyDesc" => insert_component(world, entity, |world, e| {
|
||||
world.entity_mut(e).insert(RigidBodyDesc::default());
|
||||
}),
|
||||
@@ -1234,6 +1364,17 @@ fn diff_added(before: &EditorEntitySnapshot, after: &EditorEntitySnapshot) -> Ed
|
||||
collider: after.collider.clone().filter(|_| before.collider.is_none()),
|
||||
physics: after.physics.clone().filter(|_| before.physics.is_none()),
|
||||
light: after.light.clone().filter(|_| before.light.is_none()),
|
||||
animation_controller: after
|
||||
.animation_controller
|
||||
.clone()
|
||||
.filter(|_| before.animation_controller.is_none()),
|
||||
audio_source: after
|
||||
.audio_source
|
||||
.clone()
|
||||
.filter(|_| before.audio_source.is_none()),
|
||||
audio_listener: after
|
||||
.audio_listener
|
||||
.filter(|_| before.audio_listener.is_none()),
|
||||
player_spawn: after.player_spawn && !before.player_spawn,
|
||||
model: after.model.clone().filter(|_| before.model.is_none()),
|
||||
prefab: after.prefab.clone().filter(|_| before.prefab.is_none()),
|
||||
|
||||
@@ -45,6 +45,25 @@ pub fn top_menu_bar(
|
||||
world.resource_mut::<SceneIo>().request = Some(SceneIoRequest::SaveAs);
|
||||
ui.close();
|
||||
}
|
||||
let recovery_available = world.resource::<SceneIo>().recovery_snapshot.is_some();
|
||||
if recovery_available {
|
||||
ui.separator();
|
||||
if menu_item(ui, "Restore Recovery Snapshot", None, true).clicked() {
|
||||
world.resource_mut::<SceneIo>().request =
|
||||
Some(SceneIoRequest::RestoreRecovery);
|
||||
ui.close();
|
||||
}
|
||||
if menu_item(ui, "Save Recovery Copy As...", None, true).clicked() {
|
||||
world.resource_mut::<SceneIo>().request =
|
||||
Some(SceneIoRequest::SaveRecoveryCopyAs);
|
||||
ui.close();
|
||||
}
|
||||
if menu_item(ui, "Discard Recovery Snapshot", None, true).clicked() {
|
||||
world.resource_mut::<SceneIo>().request =
|
||||
Some(SceneIoRequest::DiscardRecovery);
|
||||
ui.close();
|
||||
}
|
||||
}
|
||||
ui.separator();
|
||||
if menu_item(ui, "Import Assets...", None, true).clicked() {
|
||||
world.resource_mut::<SceneIo>().request = Some(SceneIoRequest::ImportAssets);
|
||||
@@ -59,6 +78,24 @@ pub fn top_menu_bar(
|
||||
Some(SceneIoRequest::SaveSelectionAsPrefab);
|
||||
ui.close();
|
||||
}
|
||||
ui.separator();
|
||||
if menu_item(ui, "Switch Project...", None, true).clicked() {
|
||||
world.resource_mut::<SceneIo>().request = Some(SceneIoRequest::SwitchProject);
|
||||
ui.close();
|
||||
}
|
||||
if menu_item(ui, "Reveal Project Folder", None, true).clicked() {
|
||||
let root = world
|
||||
.resource::<crate::project_io::ProjectWorkspace>()
|
||||
.root
|
||||
.clone();
|
||||
let status =
|
||||
match crate::launcher::reveal_project_root(std::path::Path::new(&root)) {
|
||||
Ok(()) => format!("Revealed project folder {root}"),
|
||||
Err(error) => format!("Reveal project folder failed: {error}"),
|
||||
};
|
||||
world.resource_mut::<SceneIo>().set_status(status);
|
||||
ui.close();
|
||||
}
|
||||
let recent: Vec<(usize, String)> = world
|
||||
.resource::<SceneIo>()
|
||||
.recent_paths
|
||||
@@ -123,6 +160,30 @@ pub fn top_menu_bar(
|
||||
}
|
||||
});
|
||||
|
||||
ui.menu_button("Build", |ui| {
|
||||
let running = world.resource::<super::build::BuildPanel>().is_running();
|
||||
if menu_item(ui, "Build Package", None, !running).clicked() {
|
||||
open_and_focus_tab(dock_state, EditorTab::Build, panel_nodes);
|
||||
super::build::request_build(world, false);
|
||||
ui.close();
|
||||
}
|
||||
if menu_item(ui, "Build and Run", None, !running).clicked() {
|
||||
open_and_focus_tab(dock_state, EditorTab::Build, panel_nodes);
|
||||
super::build::request_build(world, true);
|
||||
ui.close();
|
||||
}
|
||||
if menu_item(ui, "Cancel Build", None, running).clicked() {
|
||||
super::build::cancel_build(world);
|
||||
ui.close();
|
||||
}
|
||||
ui.separator();
|
||||
let has_output = world.resource::<super::build::BuildPanel>().has_output();
|
||||
if menu_item(ui, "Reveal Output", None, has_output).clicked() {
|
||||
super::build::reveal_last_output(world);
|
||||
ui.close();
|
||||
}
|
||||
});
|
||||
|
||||
ui.menu_button("View", |ui| {
|
||||
if menu_item(ui, "Reset Layout", None, true).clicked() {
|
||||
let layout = reset_and_save_layout(world);
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
mod actor_inspector;
|
||||
mod animation_inspector;
|
||||
mod asset_browser;
|
||||
mod audio_inspector;
|
||||
mod build;
|
||||
mod component_registry;
|
||||
mod diagnostics;
|
||||
mod dock_tabs;
|
||||
@@ -13,6 +16,7 @@ mod layout;
|
||||
mod menu;
|
||||
mod play_controls;
|
||||
mod post_process_volume_ui;
|
||||
mod scene_tabs;
|
||||
pub mod selection_ops;
|
||||
mod status_bar;
|
||||
pub(crate) mod theme;
|
||||
@@ -34,6 +38,7 @@ use crate::project_io::UserPreferences;
|
||||
use crate::selection::SelectedEntity;
|
||||
use crate::state::EditorMode;
|
||||
|
||||
pub use build::BuildPanel;
|
||||
pub use diagnostics::{BrushDiagnosticsPanel, DiagnosticsPanel};
|
||||
pub use layout::LayoutSaveTimer;
|
||||
pub use viewport_chrome::ViewportUiState;
|
||||
@@ -124,6 +129,7 @@ impl UiState {
|
||||
)]
|
||||
fn ui(&mut self, world: &mut World, ctx: &mut egui::Context, dt: f32) {
|
||||
apply_editor_theme(ctx);
|
||||
let selected_before_ui = world.resource::<SelectedEntity>().0;
|
||||
|
||||
let mode = *world.resource::<State<EditorMode>>().get();
|
||||
if self.last_mode_tab != Some(mode) {
|
||||
@@ -156,7 +162,7 @@ impl UiState {
|
||||
&mut self.panel_nodes,
|
||||
);
|
||||
|
||||
editor_toolbar_panel(world, root_ui);
|
||||
editor_toolbar_panel(world, root_ui, &mut self.selected_entities);
|
||||
status_bar_ui(world, root_ui, &self.selected_entities, mode);
|
||||
|
||||
let mut viewer = TabViewer {
|
||||
@@ -202,6 +208,8 @@ impl UiState {
|
||||
.resource_mut::<crate::rendering_diagnostics::RenderingDiagnosticsPanel>()
|
||||
.open = rendering_open;
|
||||
|
||||
crate::session::session_resume_window(world, ctx);
|
||||
|
||||
world.resource_scope(|world, mut panel: Mut<ProjectSettingsPanel>| {
|
||||
project_settings_window(world, ctx, &mut panel);
|
||||
});
|
||||
@@ -210,11 +218,32 @@ impl UiState {
|
||||
world.resource_mut::<ViewportUiState>().shortcuts_open = true;
|
||||
}
|
||||
|
||||
let requested_selection = world.resource::<SelectedEntity>().0;
|
||||
reconcile_operator_selection(
|
||||
&mut self.selected_entities,
|
||||
selected_before_ui,
|
||||
requested_selection,
|
||||
);
|
||||
let selected = self.selected_entities.as_slice().first().copied();
|
||||
world.resource_mut::<SelectedEntity>().0 = selected;
|
||||
}
|
||||
}
|
||||
|
||||
fn reconcile_operator_selection(
|
||||
selected_entities: &mut SelectedEntities,
|
||||
selected_before_ui: Option<Entity>,
|
||||
requested_selection: Option<Entity>,
|
||||
) {
|
||||
let selected_after_ui = selected_entities.as_slice().first().copied();
|
||||
if requested_selection == selected_before_ui || selected_after_ui != selected_before_ui {
|
||||
return;
|
||||
}
|
||||
selected_entities.clear();
|
||||
if let Some(entity) = requested_selection {
|
||||
selected_entities.select_replace(entity);
|
||||
}
|
||||
}
|
||||
|
||||
fn tab_title(icon: egui_phosphor_icons::Icon, label: &str) -> egui::WidgetText {
|
||||
let mut job = egui::text::LayoutJob::default();
|
||||
job.append(
|
||||
@@ -247,6 +276,7 @@ pub enum EditorTab {
|
||||
Inspector,
|
||||
Toolbar,
|
||||
AssetBrowser,
|
||||
Build,
|
||||
}
|
||||
|
||||
pub struct EditorUiPlugin;
|
||||
@@ -256,12 +286,14 @@ impl Plugin for EditorUiPlugin {
|
||||
app.insert_resource(UiState::default_layout())
|
||||
.add_plugins(fonts::EditorFontsPlugin)
|
||||
.init_resource::<DiagnosticsPanel>()
|
||||
.init_resource::<BuildPanel>()
|
||||
.init_resource::<BrushDiagnosticsPanel>()
|
||||
.init_resource::<component_registry::EditorComponentRegistry>()
|
||||
.init_resource::<crate::rendering_diagnostics::RenderingDiagnosticsPanel>()
|
||||
.init_resource::<asset_browser::AssetBrowserUiState>()
|
||||
.init_resource::<inspector::InspectorClipboard>()
|
||||
.init_resource::<inspector::InspectorPanelState>()
|
||||
.init_resource::<animation_inspector::AnimationInspectorState>()
|
||||
.init_resource::<ViewportUiState>()
|
||||
.init_resource::<LayoutSaveTimer>()
|
||||
.add_systems(
|
||||
@@ -275,7 +307,13 @@ impl Plugin for EditorUiPlugin {
|
||||
.after(crate::project_io::load_user_preferences_on_startup),
|
||||
)
|
||||
.add_systems(EguiPrimaryContextPass, show_ui_system)
|
||||
.add_systems(Update, hierarchy_state::tick_hierarchy_prefs_save);
|
||||
.add_systems(
|
||||
Update,
|
||||
(
|
||||
hierarchy_state::tick_hierarchy_prefs_save,
|
||||
build::tick_build_job,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -360,6 +398,7 @@ impl egui_dock::TabViewer for TabViewer<'_> {
|
||||
EditorTab::AssetBrowser => {
|
||||
asset_browser::asset_browser_ui(self.world, ui, self.selected_entities);
|
||||
}
|
||||
EditorTab::Build => build::build_ui(self.world, ui),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -370,6 +409,7 @@ impl egui_dock::TabViewer for TabViewer<'_> {
|
||||
EditorTab::Inspector => (icons::SLIDERS, "Inspector"),
|
||||
EditorTab::Toolbar => (icons::WRENCH, "Toolbar"),
|
||||
EditorTab::AssetBrowser => (icons::FOLDER, "Asset Browser"),
|
||||
EditorTab::Build => (icons::HAMMER, "Build"),
|
||||
};
|
||||
tab_title(icon, label)
|
||||
}
|
||||
@@ -381,3 +421,33 @@ impl egui_dock::TabViewer for TabViewer<'_> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn operator_selection_wins_when_ui_selection_did_not_change() {
|
||||
let before = Entity::from_bits(1);
|
||||
let spawned = Entity::from_bits(2);
|
||||
let mut selected = SelectedEntities::default();
|
||||
selected.select_replace(before);
|
||||
|
||||
reconcile_operator_selection(&mut selected, Some(before), Some(spawned));
|
||||
|
||||
assert_eq!(selected.as_slice(), &[spawned]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn direct_ui_selection_wins_over_stale_operator_resource() {
|
||||
let before = Entity::from_bits(1);
|
||||
let clicked = Entity::from_bits(2);
|
||||
let requested = Entity::from_bits(3);
|
||||
let mut selected = SelectedEntities::default();
|
||||
selected.select_replace(clicked);
|
||||
|
||||
reconcile_operator_selection(&mut selected, Some(before), Some(requested));
|
||||
|
||||
assert_eq!(selected.as_slice(), &[clicked]);
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@ pub fn toggle_play_mode(world: &mut World) {
|
||||
if save_before && world.resource::<SceneIo>().dirty {
|
||||
let status = save_active_or_prompt_world(world);
|
||||
if status.contains("failed") || status.contains("cancelled") {
|
||||
world.resource_mut::<SceneIo>().status = status;
|
||||
world.resource_mut::<SceneIo>().set_status(status);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,282 @@
|
||||
//! Top-level authored scene tabs and composition controls.
|
||||
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use bevy::prelude::*;
|
||||
use bevy_egui::egui;
|
||||
use bevy_inspector_egui::bevy_inspector::hierarchy::SelectedEntities;
|
||||
use egui_phosphor_icons::icons;
|
||||
use shared::{SceneComposition, SubsceneReference};
|
||||
|
||||
use crate::scene_io::{ComposedSceneMember, SceneIo, SceneIoRequest};
|
||||
use crate::selection::SelectedEntity;
|
||||
|
||||
use super::selection_ops::focus_editor_camera_on_selection;
|
||||
use super::theme::{BORDER, SELECTION, SELECTION_BG, TEXT, TEXT_DIM, TEXT_MUTED, WIDGET_BG};
|
||||
use super::widgets::phosphor_icon;
|
||||
|
||||
pub fn scene_tabs_chrome(
|
||||
world: &mut World,
|
||||
ui: &mut egui::Ui,
|
||||
selected: &mut SelectedEntities,
|
||||
editing: bool,
|
||||
) {
|
||||
let (tabs, active_tab) = {
|
||||
let io = world.resource::<SceneIo>();
|
||||
(io.tabs.clone(), io.active_tab)
|
||||
};
|
||||
let composition_editing = editing
|
||||
&& !world
|
||||
.resource::<SceneIo>()
|
||||
.active_path
|
||||
.as_deref()
|
||||
.is_some_and(crate::scene_io::is_prefab_document);
|
||||
let composition_count = world.resource::<SceneComposition>().subscenes.len();
|
||||
let mut request = None;
|
||||
ui.spacing_mut().item_spacing.x = 3.0;
|
||||
ui.menu_button(
|
||||
super::tab_title(icons::STACK, &format!("Composition {composition_count}")),
|
||||
|ui| composition_menu(world, ui, selected, composition_editing),
|
||||
)
|
||||
.response
|
||||
.on_hover_text(if composition_editing {
|
||||
"Scene composition"
|
||||
} else {
|
||||
"Composition is unavailable for prefab documents"
|
||||
});
|
||||
ui.separator();
|
||||
if ui
|
||||
.add_enabled(
|
||||
editing,
|
||||
egui::Button::new(phosphor_icon(icons::PLUS, 13.0))
|
||||
.frame(false)
|
||||
.min_size(egui::vec2(22.0, 20.0)),
|
||||
)
|
||||
.on_hover_text("New scene tab")
|
||||
.clicked()
|
||||
{
|
||||
request = Some(SceneIoRequest::New);
|
||||
}
|
||||
|
||||
for (index, tab) in tabs.iter().enumerate().rev() {
|
||||
if ui
|
||||
.add_enabled(
|
||||
editing,
|
||||
egui::Button::new(phosphor_icon(icons::X, 11.0))
|
||||
.frame(false)
|
||||
.min_size(egui::vec2(18.0, 20.0)),
|
||||
)
|
||||
.on_hover_text("Close scene tab")
|
||||
.clicked()
|
||||
{
|
||||
request = Some(SceneIoRequest::CloseTab(index));
|
||||
}
|
||||
let active = index == active_tab;
|
||||
let label = if tab.dirty {
|
||||
format!("{} *", tab.label())
|
||||
} else {
|
||||
tab.label()
|
||||
};
|
||||
let text = egui::RichText::new(label)
|
||||
.color(if active { TEXT } else { TEXT_DIM })
|
||||
.strong();
|
||||
let response = ui.add_enabled(
|
||||
editing,
|
||||
egui::Button::new(text)
|
||||
.fill(if active { SELECTION_BG } else { WIDGET_BG })
|
||||
.stroke(egui::Stroke::new(
|
||||
1.0,
|
||||
if active { SELECTION } else { BORDER },
|
||||
))
|
||||
.min_size(egui::vec2(128.0, 20.0)),
|
||||
);
|
||||
if response.clicked() && !active {
|
||||
request = Some(SceneIoRequest::SwitchTab(index));
|
||||
}
|
||||
if response.hovered() {
|
||||
let path = tab
|
||||
.path
|
||||
.as_deref()
|
||||
.map(Path::display)
|
||||
.map(|path| path.to_string())
|
||||
.unwrap_or_else(|| "Unsaved scene".to_string());
|
||||
response.on_hover_text(path);
|
||||
}
|
||||
}
|
||||
|
||||
if !editing {
|
||||
ui.label(egui::RichText::new("Play mode").color(TEXT_MUTED));
|
||||
}
|
||||
|
||||
if let Some(request) = request {
|
||||
world.resource_mut::<SceneIo>().request = Some(request);
|
||||
}
|
||||
}
|
||||
|
||||
fn composition_menu(
|
||||
world: &mut World,
|
||||
ui: &mut egui::Ui,
|
||||
selected: &mut SelectedEntities,
|
||||
editing: bool,
|
||||
) {
|
||||
ui.set_min_width(480.0);
|
||||
let mut composition = world.resource::<SceneComposition>().clone();
|
||||
ui.label(
|
||||
egui::RichText::new(format!("Scene ID {}", composition.scene_id))
|
||||
.monospace()
|
||||
.size(11.0)
|
||||
.color(TEXT_MUTED),
|
||||
);
|
||||
ui.separator();
|
||||
|
||||
let mut changed = false;
|
||||
let mut remove = None;
|
||||
let mut focus = None;
|
||||
if composition.subscenes.is_empty() {
|
||||
ui.label(egui::RichText::new("No composed subscenes").color(TEXT_DIM));
|
||||
}
|
||||
for (index, reference) in composition.subscenes.iter_mut().enumerate() {
|
||||
ui.horizontal(|ui| {
|
||||
let file_name = Path::new(&reference.path)
|
||||
.file_name()
|
||||
.and_then(|name| name.to_str())
|
||||
.unwrap_or(&reference.path);
|
||||
ui.label(egui::RichText::new(file_name).strong().color(TEXT));
|
||||
ui.label(
|
||||
egui::RichText::new(&reference.path)
|
||||
.monospace()
|
||||
.size(10.0)
|
||||
.color(TEXT_MUTED),
|
||||
);
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
if ui
|
||||
.add_enabled(
|
||||
editing,
|
||||
egui::Button::new(phosphor_icon(icons::TRASH, 14.0)).frame(false),
|
||||
)
|
||||
.on_hover_text("Remove subscene reference")
|
||||
.clicked()
|
||||
{
|
||||
remove = Some(index);
|
||||
}
|
||||
if ui
|
||||
.add_enabled(reference.visible, egui::Button::new("Focus"))
|
||||
.clicked()
|
||||
{
|
||||
focus = Some(reference.id.clone());
|
||||
ui.close();
|
||||
}
|
||||
if ui
|
||||
.add_enabled(
|
||||
editing,
|
||||
egui::Checkbox::new(&mut reference.locked, "Locked"),
|
||||
)
|
||||
.changed()
|
||||
{
|
||||
changed = true;
|
||||
}
|
||||
if ui
|
||||
.add_enabled(
|
||||
editing,
|
||||
egui::Checkbox::new(&mut reference.visible, "Loaded"),
|
||||
)
|
||||
.changed()
|
||||
{
|
||||
changed = true;
|
||||
}
|
||||
});
|
||||
});
|
||||
ui.add_space(4.0);
|
||||
}
|
||||
if let Some(index) = remove {
|
||||
composition.subscenes.remove(index);
|
||||
changed = true;
|
||||
}
|
||||
|
||||
ui.separator();
|
||||
if ui
|
||||
.add_enabled(editing, egui::Button::new("Add Subscene..."))
|
||||
.clicked()
|
||||
{
|
||||
match choose_subscene(world, &composition) {
|
||||
Ok(Some(reference)) => {
|
||||
composition.subscenes.push(reference);
|
||||
changed = true;
|
||||
}
|
||||
Ok(None) => {}
|
||||
Err(error) => world
|
||||
.resource_mut::<SceneIo>()
|
||||
.set_status(format!("Add subscene failed: {error}")),
|
||||
}
|
||||
}
|
||||
|
||||
if changed {
|
||||
crate::history::set_scene_composition_with_history(world, composition);
|
||||
}
|
||||
if let Some(reference_id) = focus {
|
||||
focus_subscene(world, selected, &reference_id);
|
||||
}
|
||||
}
|
||||
|
||||
fn choose_subscene(
|
||||
world: &World,
|
||||
composition: &SceneComposition,
|
||||
) -> Result<Option<SubsceneReference>, String> {
|
||||
let project_root = PathBuf::from(&world.resource::<crate::project_io::ProjectWorkspace>().root)
|
||||
.canonicalize()
|
||||
.map_err(|error| format!("could not resolve project root: {error}"))?;
|
||||
let Some(path) = rfd::FileDialog::new()
|
||||
.set_directory(project_root.join("assets/levels"))
|
||||
.add_filter("Bevy scene", &["scn.ron", "ron"])
|
||||
.pick_file()
|
||||
else {
|
||||
return Ok(None);
|
||||
};
|
||||
let path = path
|
||||
.canonicalize()
|
||||
.map_err(|error| format!("could not resolve {}: {error}", path.display()))?;
|
||||
let relative = path.strip_prefix(&project_root).map_err(|_| {
|
||||
format!(
|
||||
"{} is outside project root {}",
|
||||
path.display(),
|
||||
project_root.display()
|
||||
)
|
||||
})?;
|
||||
scene::validate_level_file(&path)?;
|
||||
let relative = relative.to_string_lossy().replace('\\', "/");
|
||||
if composition
|
||||
.subscenes
|
||||
.iter()
|
||||
.any(|reference| reference.path == relative)
|
||||
{
|
||||
return Err(format!("{relative} is already composed"));
|
||||
}
|
||||
Ok(Some(SubsceneReference {
|
||||
id: uuid::Uuid::new_v4().to_string(),
|
||||
path: relative,
|
||||
visible: true,
|
||||
locked: true,
|
||||
}))
|
||||
}
|
||||
|
||||
fn focus_subscene(world: &mut World, selected: &mut SelectedEntities, reference_id: &str) {
|
||||
let mut query = world.query::<(Entity, &ComposedSceneMember)>();
|
||||
let entity = query.iter(world).find_map(|(entity, member)| {
|
||||
(member.reference_id == reference_id
|
||||
|| member.reference_id.starts_with(&format!("{reference_id}/")))
|
||||
.then_some(entity)
|
||||
});
|
||||
let Some(entity) = entity else {
|
||||
world
|
||||
.resource_mut::<SceneIo>()
|
||||
.set_status("Subscene is not loaded or contains no authored actors");
|
||||
return;
|
||||
};
|
||||
selected.clear();
|
||||
selected.select_replace(entity);
|
||||
world.resource_mut::<SelectedEntity>().0 = Some(entity);
|
||||
focus_editor_camera_on_selection(world);
|
||||
world
|
||||
.resource_mut::<SceneIo>()
|
||||
.set_status(format!("Focused composed subscene {reference_id}"));
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
use bevy::prelude::*;
|
||||
use bevy_inspector_egui::bevy_inspector::hierarchy::SelectedEntities;
|
||||
use shared::LevelObject;
|
||||
use shared::{HydratedPrefabMember, LevelObject};
|
||||
|
||||
use crate::camera::EditorCamera;
|
||||
use crate::history::{
|
||||
@@ -11,6 +11,25 @@ use crate::history::{
|
||||
use crate::selection::SelectedEntity;
|
||||
use crate::ui::UiState;
|
||||
|
||||
fn is_locked(world: &World, entity: Entity) -> bool {
|
||||
world
|
||||
.get_resource::<crate::ui::hierarchy_state::HierarchyPanelState>()
|
||||
.is_some_and(|state| state.locked.contains(&entity))
|
||||
}
|
||||
|
||||
pub fn is_linked_read_only(world: &World, entity: Entity) -> bool {
|
||||
world.get::<HydratedPrefabMember>(entity).is_some()
|
||||
|| world
|
||||
.get::<crate::scene_io::ComposedSceneMember>(entity)
|
||||
.is_some()
|
||||
}
|
||||
|
||||
pub fn is_mutable_level_object(world: &World, entity: Entity) -> bool {
|
||||
is_level_object(world, entity)
|
||||
&& !is_locked(world, entity)
|
||||
&& !is_linked_read_only(world, entity)
|
||||
}
|
||||
|
||||
pub fn focus_editor_camera_on_selection(world: &mut World) {
|
||||
let Some(entity) = world.resource::<SelectedEntity>().0 else {
|
||||
return;
|
||||
@@ -53,12 +72,18 @@ pub fn is_level_object(world: &World, entity: Entity) -> bool {
|
||||
}
|
||||
|
||||
pub fn delete_selection(world: &mut World, selected: &SelectedEntities) {
|
||||
let entities = selected_level_entities(world, selected);
|
||||
let entities: Vec<_> = selected_level_entities(world, selected)
|
||||
.into_iter()
|
||||
.filter(|entity| is_mutable_level_object(world, *entity))
|
||||
.collect();
|
||||
delete_entities_with_history(world, &entities);
|
||||
}
|
||||
|
||||
pub fn duplicate_selection(world: &mut World, selected: &SelectedEntities) {
|
||||
let entities = selected_level_entities(world, selected);
|
||||
let entities: Vec<_> = selected_level_entities(world, selected)
|
||||
.into_iter()
|
||||
.filter(|entity| is_mutable_level_object(world, *entity))
|
||||
.collect();
|
||||
duplicate_entities_with_history(world, &entities);
|
||||
}
|
||||
|
||||
@@ -67,7 +92,7 @@ pub fn reset_selected_transforms(world: &mut World) {
|
||||
.resource::<UiState>()
|
||||
.selected_entities
|
||||
.iter()
|
||||
.filter(|entity| is_level_object(world, *entity))
|
||||
.filter(|entity| is_mutable_level_object(world, *entity))
|
||||
.filter_map(|entity| {
|
||||
world
|
||||
.get::<Transform>(entity)
|
||||
|
||||
@@ -3,13 +3,15 @@
|
||||
use bevy::prelude::*;
|
||||
use bevy_egui::egui;
|
||||
use bevy_inspector_egui::bevy_inspector::hierarchy::SelectedEntities;
|
||||
use egui_phosphor_icons::icons;
|
||||
|
||||
use crate::history::EditorHistory;
|
||||
use crate::operators::ActiveOperator;
|
||||
use crate::scene_io::SceneIo;
|
||||
use crate::state::{EditorMode, PlayPaused};
|
||||
|
||||
use super::theme::{status_bar_frame, TEXT};
|
||||
use super::theme::{status_bar_frame, ACCENT, SELECTION, SUCCESS, TEXT, TEXT_DIM, TEXT_MUTED};
|
||||
use super::widgets::phosphor_icon;
|
||||
|
||||
pub fn status_bar_ui(
|
||||
world: &World,
|
||||
@@ -18,10 +20,10 @@ pub fn status_bar_ui(
|
||||
mode: EditorMode,
|
||||
) {
|
||||
egui::Panel::bottom("editor_status_bar")
|
||||
.exact_size(24.0)
|
||||
.exact_size(27.0)
|
||||
.frame(status_bar_frame())
|
||||
.show_inside(root_ui, |ui| {
|
||||
ui.spacing_mut().item_spacing.x = 12.0;
|
||||
ui.spacing_mut().item_spacing.x = 10.0;
|
||||
egui::containers::Sides::new()
|
||||
.shrink_left()
|
||||
.truncate()
|
||||
@@ -29,23 +31,41 @@ pub fn status_bar_ui(
|
||||
ui,
|
||||
|ui| {
|
||||
let status = primary_status_line(world);
|
||||
ui.label(
|
||||
egui::RichText::new("●")
|
||||
.color(if world.resource::<SceneIo>().dirty {
|
||||
ACCENT
|
||||
} else {
|
||||
SUCCESS
|
||||
})
|
||||
.small(),
|
||||
);
|
||||
ui.add(
|
||||
egui::Label::new(egui::RichText::new(&status).color(TEXT)).truncate(),
|
||||
egui::Label::new(egui::RichText::new(&status).color(TEXT_DIM))
|
||||
.truncate(),
|
||||
)
|
||||
.on_hover_text(status);
|
||||
},
|
||||
|ui| {
|
||||
let mode_label = match mode {
|
||||
EditorMode::Editing => "Edit".to_string(),
|
||||
let (mode_icon, mode_label, mode_color) = match mode {
|
||||
EditorMode::Editing => (icons::PENCIL_SIMPLE, "EDIT", ACCENT),
|
||||
EditorMode::Playing => {
|
||||
if world.resource::<PlayPaused>().0 {
|
||||
"Play (paused)".to_string()
|
||||
(icons::PAUSE, "PAUSED", ACCENT)
|
||||
} else {
|
||||
"Play".to_string()
|
||||
(icons::PLAY, "PLAYING", SUCCESS)
|
||||
}
|
||||
}
|
||||
};
|
||||
ui.label(egui::RichText::new(mode_label).color(TEXT));
|
||||
ui.label(phosphor_icon(mode_icon, 13.0).color(mode_color));
|
||||
ui.label(
|
||||
egui::RichText::new(mode_label)
|
||||
.color(mode_color)
|
||||
.strong()
|
||||
.small(),
|
||||
);
|
||||
|
||||
ui.separator();
|
||||
|
||||
let count = selected.len();
|
||||
let selection = match count {
|
||||
@@ -53,11 +73,15 @@ pub fn status_bar_ui(
|
||||
1 => "1 selected".to_string(),
|
||||
_ => format!("{count} selected"),
|
||||
};
|
||||
ui.label(egui::RichText::new(selection).color(TEXT));
|
||||
ui.label(egui::RichText::new(selection).color(if count == 0 {
|
||||
TEXT_MUTED
|
||||
} else {
|
||||
SELECTION
|
||||
}));
|
||||
|
||||
ui.label(
|
||||
egui::RichText::new(world.resource::<EditorHistory>().status.clone())
|
||||
.color(TEXT),
|
||||
.color(TEXT_DIM),
|
||||
);
|
||||
|
||||
if let Some(operator_label) = world.resource::<ActiveOperator>().label() {
|
||||
@@ -76,7 +100,12 @@ pub fn status_bar_ui(
|
||||
|
||||
fn scene_line(scene_io: &SceneIo) -> String {
|
||||
let dirty = if scene_io.dirty { " *" } else { "" };
|
||||
format!("Scene: {}{dirty}", scene_io.active_path_label())
|
||||
let recovery = if scene_io.recovery_snapshot.is_some() {
|
||||
" [recovery]"
|
||||
} else {
|
||||
""
|
||||
};
|
||||
format!("Scene: {}{dirty}{recovery}", scene_io.active_path_label())
|
||||
}
|
||||
|
||||
fn primary_status_line(world: &World) -> String {
|
||||
@@ -95,5 +124,8 @@ mod tests {
|
||||
|
||||
scene_io.mark_dirty();
|
||||
assert!(scene_line(&scene_io).ends_with('*'));
|
||||
|
||||
scene_io.recovery_snapshot = Some("recovery.scn.ron".into());
|
||||
assert!(scene_line(&scene_io).ends_with("[recovery]"));
|
||||
}
|
||||
}
|
||||
+133
-49
@@ -1,65 +1,103 @@
|
||||
//! Unity-inspired dark pro theme for editor egui + egui_dock chrome.
|
||||
//! Blacksite editor visual system for egui and egui_dock chrome.
|
||||
|
||||
use bevy_egui::egui::{self, Color32, CornerRadius, FontId, Stroke, Visuals};
|
||||
use egui_dock::{Style as DockStyle, TabInteractionStyle, TabStyle};
|
||||
|
||||
pub const PANEL_BG: Color32 = Color32::from_rgb(32, 33, 36);
|
||||
pub const PANEL_BG_DARK: Color32 = Color32::from_rgb(24, 25, 28);
|
||||
pub const WIDGET_BG: Color32 = Color32::from_rgb(42, 43, 47);
|
||||
pub const ELEVATED_BG: Color32 = Color32::from_rgb(55, 57, 63);
|
||||
pub const ACCENT: Color32 = Color32::from_rgb(56, 121, 184);
|
||||
pub const ACCENT_HOVER: Color32 = Color32::from_rgb(72, 143, 211);
|
||||
pub const SELECTION_BG: Color32 = Color32::from_rgb(46, 103, 158);
|
||||
pub const SELECTION_BG_MUTED: Color32 = Color32::from_rgb(43, 75, 108);
|
||||
pub const TEXT: Color32 = Color32::from_rgb(226, 229, 234);
|
||||
pub const TEXT_SELECTED: Color32 = Color32::from_rgb(250, 253, 255);
|
||||
pub const TEXT_DIM: Color32 = Color32::from_rgb(170, 176, 184);
|
||||
pub const TEXT_MUTED: Color32 = Color32::from_rgb(126, 133, 143);
|
||||
pub const BORDER: Color32 = Color32::from_rgb(69, 72, 78);
|
||||
pub const VIEWPORT_OVERLAY: Color32 = Color32::from_rgba_premultiplied(26, 27, 30, 220);
|
||||
pub const CANVAS_BG: Color32 = Color32::from_rgb(7, 8, 10);
|
||||
pub const PANEL_BG: Color32 = Color32::from_rgb(13, 15, 18);
|
||||
pub const PANEL_BG_DARK: Color32 = Color32::from_rgb(9, 11, 13);
|
||||
pub const WIDGET_BG: Color32 = Color32::from_rgb(21, 24, 28);
|
||||
pub const ELEVATED_BG: Color32 = Color32::from_rgb(31, 35, 40);
|
||||
pub const ACCENT: Color32 = Color32::from_rgb(229, 164, 51);
|
||||
pub const ACCENT_HOVER: Color32 = Color32::from_rgb(249, 193, 79);
|
||||
pub const SELECTION: Color32 = Color32::from_rgb(65, 198, 207);
|
||||
pub const SELECTION_SECONDARY: Color32 = Color32::from_rgb(84, 139, 155);
|
||||
pub const SELECTION_BG: Color32 = Color32::from_rgb(22, 72, 78);
|
||||
pub const SELECTION_BG_MUTED: Color32 = Color32::from_rgb(23, 48, 54);
|
||||
pub const TEXT: Color32 = Color32::from_rgb(220, 225, 229);
|
||||
pub const TEXT_SELECTED: Color32 = Color32::from_rgb(250, 251, 252);
|
||||
pub const TEXT_DIM: Color32 = Color32::from_rgb(155, 163, 171);
|
||||
pub const TEXT_MUTED: Color32 = Color32::from_rgb(96, 105, 114);
|
||||
pub const BORDER: Color32 = Color32::from_rgb(38, 43, 49);
|
||||
pub const BORDER_STRONG: Color32 = Color32::from_rgb(64, 71, 79);
|
||||
pub const SUCCESS: Color32 = Color32::from_rgb(84, 190, 127);
|
||||
pub const WARNING: Color32 = Color32::from_rgb(235, 180, 72);
|
||||
pub const ERROR: Color32 = Color32::from_rgb(226, 94, 94);
|
||||
pub const AXIS_X: Color32 = Color32::from_rgb(232, 83, 105);
|
||||
pub const AXIS_Y: Color32 = Color32::from_rgb(91, 201, 130);
|
||||
pub const AXIS_Z: Color32 = Color32::from_rgb(77, 147, 235);
|
||||
pub const VIEWPORT_OVERLAY: Color32 = Color32::from_rgba_premultiplied(7, 9, 11, 240);
|
||||
|
||||
pub fn apply_editor_theme(ctx: &egui::Context) {
|
||||
let mut visuals = Visuals::dark();
|
||||
visuals.panel_fill = PANEL_BG;
|
||||
visuals.window_fill = WIDGET_BG;
|
||||
visuals.extreme_bg_color = PANEL_BG_DARK;
|
||||
visuals.faint_bg_color = Color32::from_rgb(38, 40, 44);
|
||||
visuals.extreme_bg_color = CANVAS_BG;
|
||||
visuals.faint_bg_color = Color32::from_rgb(17, 19, 22);
|
||||
visuals.code_bg_color = PANEL_BG_DARK;
|
||||
visuals.text_edit_bg_color = Some(PANEL_BG_DARK);
|
||||
visuals.text_edit_bg_color = Some(CANVAS_BG);
|
||||
visuals.weak_text_color = Some(TEXT_MUTED);
|
||||
visuals.widgets.noninteractive.bg_fill = WIDGET_BG;
|
||||
visuals.widgets.noninteractive.fg_stroke = Stroke::new(1.0, TEXT);
|
||||
visuals.widgets.noninteractive.bg_fill = PANEL_BG;
|
||||
visuals.widgets.noninteractive.bg_stroke = Stroke::new(1.0, BORDER);
|
||||
visuals.widgets.noninteractive.fg_stroke = Stroke::new(1.0, TEXT_DIM);
|
||||
visuals.widgets.inactive.bg_fill = WIDGET_BG;
|
||||
visuals.widgets.inactive.weak_bg_fill = Color32::from_rgb(47, 49, 54);
|
||||
visuals.widgets.inactive.weak_bg_fill = Color32::from_rgb(24, 27, 31);
|
||||
visuals.widgets.inactive.bg_stroke = Stroke::new(1.0, BORDER);
|
||||
visuals.widgets.inactive.fg_stroke = Stroke::new(1.0, TEXT);
|
||||
visuals.widgets.hovered.bg_fill = ELEVATED_BG;
|
||||
visuals.widgets.hovered.weak_bg_fill = ELEVATED_BG;
|
||||
visuals.widgets.hovered.bg_stroke = Stroke::new(1.0, ACCENT_HOVER);
|
||||
visuals.widgets.hovered.bg_stroke = Stroke::new(1.0, BORDER_STRONG);
|
||||
visuals.widgets.hovered.fg_stroke = Stroke::new(1.0, TEXT_SELECTED);
|
||||
visuals.widgets.active.bg_fill = SELECTION_BG;
|
||||
visuals.widgets.active.weak_bg_fill = SELECTION_BG;
|
||||
visuals.widgets.active.bg_stroke = Stroke::new(1.0, ACCENT_HOVER);
|
||||
visuals.widgets.active.bg_fill = Color32::from_rgb(38, 42, 47);
|
||||
visuals.widgets.active.weak_bg_fill = Color32::from_rgb(38, 42, 47);
|
||||
visuals.widgets.active.bg_stroke = Stroke::new(1.0, ACCENT);
|
||||
visuals.widgets.active.fg_stroke = Stroke::new(1.0, TEXT_SELECTED);
|
||||
visuals.widgets.open.bg_fill = ELEVATED_BG;
|
||||
visuals.widgets.open.weak_bg_fill = ELEVATED_BG;
|
||||
visuals.widgets.open.bg_stroke = Stroke::new(1.0, BORDER_STRONG);
|
||||
visuals.widgets.open.fg_stroke = Stroke::new(1.0, TEXT_SELECTED);
|
||||
visuals.selection.bg_fill = SELECTION_BG;
|
||||
visuals.selection.stroke = Stroke::new(1.0, TEXT_SELECTED);
|
||||
visuals.hyperlink_color = Color32::from_rgb(132, 186, 247);
|
||||
visuals.warn_fg_color = Color32::from_rgb(255, 200, 80);
|
||||
visuals.error_fg_color = Color32::from_rgb(255, 100, 100);
|
||||
visuals.selection.stroke = Stroke::new(1.0, SELECTION);
|
||||
visuals.hyperlink_color = SELECTION;
|
||||
visuals.warn_fg_color = WARNING;
|
||||
visuals.error_fg_color = ERROR;
|
||||
visuals.window_stroke = Stroke::new(1.0, BORDER);
|
||||
visuals.window_corner_radius = CornerRadius::same(4);
|
||||
visuals.menu_corner_radius = CornerRadius::same(3);
|
||||
visuals.window_shadow = egui::epaint::Shadow {
|
||||
offset: [0, 8],
|
||||
blur: 28,
|
||||
spread: 2,
|
||||
color: Color32::from_black_alpha(190),
|
||||
};
|
||||
visuals.popup_shadow = egui::epaint::Shadow {
|
||||
offset: [0, 5],
|
||||
blur: 18,
|
||||
spread: 1,
|
||||
color: Color32::from_black_alpha(205),
|
||||
};
|
||||
visuals.button_frame = true;
|
||||
visuals.collapsing_header_frame = false;
|
||||
visuals.indent_has_left_vline = true;
|
||||
visuals.striped = true;
|
||||
visuals.slider_trailing_fill = true;
|
||||
visuals.interact_cursor = Some(egui::CursorIcon::PointingHand);
|
||||
|
||||
let mut style = (*ctx.global_style()).clone();
|
||||
style.visuals = visuals;
|
||||
style.spacing.item_spacing = egui::vec2(8.0, 6.0);
|
||||
style.spacing.button_padding = egui::vec2(8.0, 4.0);
|
||||
style.spacing.indent = 16.0;
|
||||
style.spacing.item_spacing = egui::vec2(8.0, 7.0);
|
||||
style.spacing.button_padding = egui::vec2(10.0, 5.0);
|
||||
style.spacing.interact_size = egui::vec2(40.0, 28.0);
|
||||
style.spacing.window_margin = egui::Margin::same(10);
|
||||
style.spacing.menu_margin = egui::Margin::same(8);
|
||||
style.spacing.indent = 17.0;
|
||||
style.interaction.tooltip_delay = 0.32;
|
||||
style.interaction.tooltip_grace_time = 0.18;
|
||||
style.animation_time = 0.12;
|
||||
style.compact_menu_style = true;
|
||||
style.text_styles.insert(
|
||||
egui::TextStyle::Body,
|
||||
FontId::new(13.0, egui::FontFamily::Proportional),
|
||||
FontId::new(14.0, egui::FontFamily::Proportional),
|
||||
);
|
||||
style.text_styles.insert(
|
||||
egui::TextStyle::Button,
|
||||
@@ -67,42 +105,49 @@ pub fn apply_editor_theme(ctx: &egui::Context) {
|
||||
);
|
||||
style.text_styles.insert(
|
||||
egui::TextStyle::Heading,
|
||||
FontId::new(15.0, egui::FontFamily::Proportional),
|
||||
FontId::new(16.0, egui::FontFamily::Proportional),
|
||||
);
|
||||
style.text_styles.insert(
|
||||
egui::TextStyle::Small,
|
||||
FontId::new(12.0, egui::FontFamily::Proportional),
|
||||
);
|
||||
ctx.set_global_style(style);
|
||||
}
|
||||
|
||||
pub fn editor_dock_style(ctx: &egui::Context) -> DockStyle {
|
||||
let mut style = DockStyle::from_egui(ctx.global_style().as_ref());
|
||||
style.dock_area_padding = Some(egui::Margin::same(2));
|
||||
style.dock_area_padding = Some(egui::Margin::same(1));
|
||||
style.main_surface_border_stroke = Stroke::new(1.0, BORDER);
|
||||
style.main_surface_border_rounding = CornerRadius::ZERO;
|
||||
style.separator.width = 2.0;
|
||||
style.separator.extra_interact_width = 5.0;
|
||||
style.separator.color_idle = BORDER;
|
||||
style.separator.color_hovered = ELEVATED_BG;
|
||||
style.separator.color_hovered = BORDER_STRONG;
|
||||
style.separator.color_dragged = ACCENT_HOVER;
|
||||
|
||||
style.tab_bar.bg_fill = PANEL_BG_DARK;
|
||||
style.tab_bar.height = 26.0;
|
||||
style.tab_bar.hline_color = BORDER;
|
||||
style.tab_bar.height = 30.0;
|
||||
style.tab_bar.inner_margin = egui::Margin::symmetric(2, 1);
|
||||
style.tab_bar.hline_color = ACCENT;
|
||||
style.tab_bar.corner_radius = CornerRadius::ZERO;
|
||||
|
||||
let active = TabInteractionStyle {
|
||||
outline_color: BORDER,
|
||||
outline_color: ACCENT,
|
||||
bg_fill: PANEL_BG,
|
||||
text_color: TEXT,
|
||||
corner_radius: CornerRadius::same(3),
|
||||
text_color: TEXT_SELECTED,
|
||||
corner_radius: CornerRadius::same(1),
|
||||
};
|
||||
let inactive = TabInteractionStyle {
|
||||
outline_color: Color32::TRANSPARENT,
|
||||
bg_fill: WIDGET_BG,
|
||||
bg_fill: Color32::TRANSPARENT,
|
||||
text_color: TEXT_DIM,
|
||||
corner_radius: CornerRadius::same(3),
|
||||
corner_radius: CornerRadius::same(1),
|
||||
};
|
||||
let hovered = TabInteractionStyle {
|
||||
outline_color: BORDER,
|
||||
outline_color: BORDER_STRONG,
|
||||
bg_fill: ELEVATED_BG,
|
||||
text_color: TEXT,
|
||||
corner_radius: CornerRadius::same(3),
|
||||
corner_radius: CornerRadius::same(1),
|
||||
};
|
||||
|
||||
style.tab = TabStyle {
|
||||
@@ -113,8 +158,16 @@ pub fn editor_dock_style(ctx: &egui::Context) -> DockStyle {
|
||||
inactive_with_kb_focus: inactive.clone(),
|
||||
active_with_kb_focus: active.clone(),
|
||||
focused_with_kb_focus: active,
|
||||
hline_below_active_tab_name: true,
|
||||
spacing: 2.0,
|
||||
..style.tab
|
||||
};
|
||||
style.tab.tab_body.inner_margin = egui::Margin::same(4);
|
||||
style.tab.tab_body.bg_fill = PANEL_BG;
|
||||
style.tab.tab_body.stroke = Stroke::new(1.0, BORDER);
|
||||
style.overlay.selection_color = SELECTION_BG;
|
||||
style.overlay.button_color = SELECTION;
|
||||
style.overlay.button_border_stroke = Stroke::new(1.0, SELECTION);
|
||||
|
||||
style
|
||||
}
|
||||
@@ -125,14 +178,45 @@ pub fn panel_heading(text: &str) -> egui::RichText {
|
||||
|
||||
pub fn status_bar_frame() -> egui::Frame {
|
||||
egui::Frame::new()
|
||||
.fill(Color32::from_rgb(0, 122, 204))
|
||||
.inner_margin(egui::Margin::symmetric(8, 2))
|
||||
.fill(PANEL_BG_DARK)
|
||||
.inner_margin(egui::Margin::symmetric(10, 3))
|
||||
.stroke(Stroke::new(1.0, BORDER))
|
||||
}
|
||||
|
||||
pub fn brand_mark_frame() -> egui::Frame {
|
||||
egui::Frame::new()
|
||||
.fill(CANVAS_BG)
|
||||
.corner_radius(CornerRadius::same(2))
|
||||
.inner_margin(egui::Margin::symmetric(8, 4))
|
||||
.stroke(Stroke::new(1.0, BORDER_STRONG))
|
||||
}
|
||||
|
||||
pub fn viewport_toolbar_frame() -> egui::Frame {
|
||||
egui::Frame::new()
|
||||
.fill(VIEWPORT_OVERLAY)
|
||||
.corner_radius(CornerRadius::same(4))
|
||||
.inner_margin(egui::Margin::same(4))
|
||||
.corner_radius(CornerRadius::same(3))
|
||||
.inner_margin(egui::Margin::same(5))
|
||||
.stroke(Stroke::new(1.0, BORDER_STRONG))
|
||||
.shadow(egui::epaint::Shadow {
|
||||
offset: [0, 3],
|
||||
blur: 12,
|
||||
spread: 0,
|
||||
color: Color32::from_black_alpha(110),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn overlay_chip_frame() -> egui::Frame {
|
||||
egui::Frame::new()
|
||||
.fill(VIEWPORT_OVERLAY)
|
||||
.corner_radius(CornerRadius::same(3))
|
||||
.inner_margin(egui::Margin::symmetric(8, 5))
|
||||
.stroke(Stroke::new(1.0, BORDER_STRONG))
|
||||
}
|
||||
|
||||
pub fn toolbar_group_frame() -> egui::Frame {
|
||||
egui::Frame::new()
|
||||
.fill(PANEL_BG_DARK)
|
||||
.corner_radius(CornerRadius::same(3))
|
||||
.inner_margin(egui::Margin::symmetric(5, 3))
|
||||
.stroke(Stroke::new(1.0, BORDER))
|
||||
}
|
||||
+118
-63
@@ -2,6 +2,7 @@
|
||||
|
||||
use bevy::prelude::*;
|
||||
use bevy_egui::egui;
|
||||
use bevy_inspector_egui::bevy_inspector::hierarchy::SelectedEntities;
|
||||
use egui_phosphor_icons::icons;
|
||||
|
||||
use crate::history::spawn_with_history;
|
||||
@@ -15,35 +16,46 @@ use shared::PrimitiveShape;
|
||||
use super::helpers::{
|
||||
light_snapshot, primitive_snapshot, toggle_play_mode, toggle_play_paused, toggle_possession,
|
||||
};
|
||||
use super::widgets::{icon_button, panel_toolbar_row, toolbar_separator, transport_button_large};
|
||||
use super::theme::{brand_mark_frame, toolbar_group_frame, ACCENT, TEXT, TEXT_MUTED};
|
||||
use super::widgets::{
|
||||
icon_button, panel_toolbar_row, phosphor_icon, toolbar_separator, transport_button_large,
|
||||
};
|
||||
|
||||
/// Toolbar strip height (menu bar is separate).
|
||||
const TOOLBAR_HEIGHT: f32 = 56.0;
|
||||
const TRANSPORT_WIDTH: f32 = 152.0;
|
||||
const TRANSPORT_SLOT_STEP: f32 = 54.0;
|
||||
const TOOLBAR_HEIGHT: f32 = 50.0;
|
||||
const TRANSPORT_WIDTH: f32 = 150.0;
|
||||
const TRANSPORT_SLOT_STEP: f32 = 50.0;
|
||||
|
||||
pub fn editor_toolbar_panel(world: &mut World, root_ui: &mut egui::Ui) {
|
||||
pub fn editor_toolbar_panel(
|
||||
world: &mut World,
|
||||
root_ui: &mut egui::Ui,
|
||||
selected: &mut SelectedEntities,
|
||||
) {
|
||||
egui::Panel::top("editor_toolbar")
|
||||
.exact_size(TOOLBAR_HEIGHT)
|
||||
.show_inside(root_ui, |ui| {
|
||||
toolbar_ui(world, ui);
|
||||
toolbar_ui(world, ui, selected);
|
||||
});
|
||||
}
|
||||
|
||||
pub fn toolbar_ui(world: &mut World, ui: &mut egui::Ui) {
|
||||
pub fn toolbar_ui(world: &mut World, ui: &mut egui::Ui, selected: &mut SelectedEntities) {
|
||||
let (toolbar_rect, _) = ui.allocate_exact_size(
|
||||
egui::vec2(ui.available_width(), TOOLBAR_HEIGHT - 4.0),
|
||||
egui::vec2(ui.available_width(), TOOLBAR_HEIGHT - 2.0),
|
||||
egui::Sense::hover(),
|
||||
);
|
||||
|
||||
let center_y = toolbar_rect.center().y;
|
||||
let left_rect = egui::Rect::from_min_max(
|
||||
egui::pos2(toolbar_rect.left() + 8.0, center_y - 18.0),
|
||||
egui::pos2(toolbar_rect.right(), center_y + 18.0),
|
||||
egui::pos2(toolbar_rect.left() + 8.0, center_y - 20.0),
|
||||
egui::pos2(toolbar_rect.right(), center_y + 20.0),
|
||||
);
|
||||
let transport_rect = egui::Rect::from_center_size(
|
||||
egui::pos2(toolbar_rect.center().x, center_y),
|
||||
egui::vec2(TRANSPORT_WIDTH, 44.0),
|
||||
egui::vec2(TRANSPORT_WIDTH, 46.0),
|
||||
);
|
||||
let right_rect = egui::Rect::from_min_max(
|
||||
egui::pos2(transport_rect.right() + 18.0, center_y - 20.0),
|
||||
egui::pos2(toolbar_rect.right() - 8.0, center_y + 20.0),
|
||||
);
|
||||
|
||||
let mut left_ui = ui.new_child(
|
||||
@@ -62,42 +74,89 @@ pub fn toolbar_ui(world: &mut World, ui: &mut egui::Ui) {
|
||||
.layout(egui::Layout::left_to_right(egui::Align::Center)),
|
||||
);
|
||||
transport_ui.spacing_mut().item_spacing.x = 10.0;
|
||||
transport_controls(world, &mut transport_ui);
|
||||
toolbar_group_frame().show(&mut transport_ui, |ui| {
|
||||
transport_controls(world, ui);
|
||||
});
|
||||
|
||||
let mut right_ui = ui.new_child(
|
||||
egui::UiBuilder::new()
|
||||
.id_salt("toolbar_scene_documents")
|
||||
.max_rect(right_rect)
|
||||
.layout(egui::Layout::right_to_left(egui::Align::Center)),
|
||||
);
|
||||
let editing = *world.resource::<State<EditorMode>>().get() == EditorMode::Editing;
|
||||
super::scene_tabs::scene_tabs_chrome(world, &mut right_ui, selected, editing);
|
||||
|
||||
ui.painter().line_segment(
|
||||
[toolbar_rect.left_bottom(), toolbar_rect.right_bottom()],
|
||||
egui::Stroke::new(1.0, super::theme::BORDER),
|
||||
);
|
||||
ui.painter().line_segment(
|
||||
[
|
||||
toolbar_rect.left_bottom() + egui::vec2(8.0, 0.0),
|
||||
toolbar_rect.left_bottom() + egui::vec2(134.0, 0.0),
|
||||
],
|
||||
egui::Stroke::new(2.0, ACCENT),
|
||||
);
|
||||
}
|
||||
|
||||
fn left_toolbar(world: &mut World, ui: &mut egui::Ui) {
|
||||
panel_toolbar_row(ui, |ui| {
|
||||
if icon_button(ui, icons::CUBE, "Spawn cube").clicked() {
|
||||
spawn_primitive_at_camera(world, PrimitiveShape::Box, "Cube");
|
||||
}
|
||||
if icon_button(ui, icons::MOUNTAINS, "Spawn ramp").clicked() {
|
||||
spawn_primitive_at_camera(world, PrimitiveShape::Ramp, "Ramp");
|
||||
}
|
||||
if icon_button(ui, icons::SPHERE, "Spawn sphere").clicked() {
|
||||
spawn_primitive_at_camera(world, PrimitiveShape::Sphere, "Sphere");
|
||||
}
|
||||
if icon_button(ui, icons::LIGHTBULB, "Spawn point light").clicked() {
|
||||
let pos = camera_ground_spawn(world);
|
||||
spawn_with_history(world, light_snapshot("Point Light", pos));
|
||||
}
|
||||
if icon_button(ui, icons::PENCIL_SIMPLE_LINE, "Draw brush (B)").clicked() {
|
||||
start_draw_brush_tool(world);
|
||||
}
|
||||
brand_mark_frame().show(ui, |ui| {
|
||||
ui.set_min_width(118.0);
|
||||
ui.set_min_height(30.0);
|
||||
ui.horizontal(|ui| {
|
||||
ui.label(phosphor_icon(icons::CROSSHAIR, 19.0).color(ACCENT));
|
||||
ui.vertical(|ui| {
|
||||
ui.spacing_mut().item_spacing.y = 0.0;
|
||||
ui.label(
|
||||
egui::RichText::new("BLACKSITE")
|
||||
.size(11.0)
|
||||
.strong()
|
||||
.color(TEXT),
|
||||
);
|
||||
ui.label(
|
||||
egui::RichText::new("EDITOR // DEV")
|
||||
.size(9.0)
|
||||
.color(TEXT_MUTED),
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
toolbar_separator(ui);
|
||||
toolbar_group_frame().show(ui, |ui| {
|
||||
panel_toolbar_row(ui, |ui| {
|
||||
if icon_button(ui, icons::CUBE, "Spawn cube").clicked() {
|
||||
spawn_primitive_at_camera(world, PrimitiveShape::Box, "Cube");
|
||||
}
|
||||
if icon_button(ui, icons::MOUNTAINS, "Spawn ramp").clicked() {
|
||||
spawn_primitive_at_camera(world, PrimitiveShape::Ramp, "Ramp");
|
||||
}
|
||||
if icon_button(ui, icons::SPHERE, "Spawn sphere").clicked() {
|
||||
spawn_primitive_at_camera(world, PrimitiveShape::Sphere, "Sphere");
|
||||
}
|
||||
if icon_button(ui, icons::LIGHTBULB, "Spawn point light").clicked() {
|
||||
let pos = camera_ground_spawn(world);
|
||||
spawn_with_history(world, light_snapshot("Point Light", pos));
|
||||
}
|
||||
if icon_button(ui, icons::PENCIL_SIMPLE_LINE, "Draw brush (B)").clicked() {
|
||||
start_draw_brush_tool(world);
|
||||
}
|
||||
|
||||
if icon_button(ui, icons::FILE, "New scene").clicked() {
|
||||
world.resource_mut::<SceneIo>().request = Some(SceneIoRequest::New);
|
||||
}
|
||||
if icon_button(ui, icons::FOLDER_OPEN, "Open scene").clicked() {
|
||||
world.resource_mut::<SceneIo>().request = Some(SceneIoRequest::Open);
|
||||
}
|
||||
if icon_button(ui, icons::FLOPPY_DISK, "Save scene").clicked() {
|
||||
world.resource_mut::<SceneIo>().request = Some(SceneIoRequest::Save);
|
||||
}
|
||||
if icon_button(ui, icons::COPY, "Save scene as").clicked() {
|
||||
world.resource_mut::<SceneIo>().request = Some(SceneIoRequest::SaveAs);
|
||||
}
|
||||
toolbar_separator(ui);
|
||||
|
||||
if icon_button(ui, icons::FILE, "New scene").clicked() {
|
||||
world.resource_mut::<SceneIo>().request = Some(SceneIoRequest::New);
|
||||
}
|
||||
if icon_button(ui, icons::FOLDER_OPEN, "Open scene").clicked() {
|
||||
world.resource_mut::<SceneIo>().request = Some(SceneIoRequest::Open);
|
||||
}
|
||||
if icon_button(ui, icons::FLOPPY_DISK, "Save scene").clicked() {
|
||||
world.resource_mut::<SceneIo>().request = Some(SceneIoRequest::Save);
|
||||
}
|
||||
if icon_button(ui, icons::COPY, "Save scene as").clicked() {
|
||||
world.resource_mut::<SceneIo>().request = Some(SceneIoRequest::SaveAs);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -106,11 +165,9 @@ fn transport_controls(world: &mut World, ui: &mut egui::Ui) {
|
||||
match mode {
|
||||
EditorMode::Editing => {
|
||||
ui.add_space(TRANSPORT_SLOT_STEP);
|
||||
let play_clicked = ui
|
||||
.push_id("transport_center", |ui| {
|
||||
transport_button_large(ui, icons::PLAY, "Play (F5)", true).clicked()
|
||||
})
|
||||
.inner;
|
||||
let play_clicked =
|
||||
transport_button_large(ui, "transport_center", icons::PLAY, "Play (F5)", true)
|
||||
.clicked();
|
||||
if play_clicked {
|
||||
toggle_play_mode(world);
|
||||
}
|
||||
@@ -123,20 +180,20 @@ fn transport_controls(world: &mut World, ui: &mut egui::Ui) {
|
||||
} else {
|
||||
"Pause simulation (F6)"
|
||||
};
|
||||
let pause_clicked = ui
|
||||
.push_id("transport_left", |ui| {
|
||||
transport_button_large(ui, pause_icon, pause_tip, false).clicked()
|
||||
})
|
||||
.inner;
|
||||
let pause_clicked =
|
||||
transport_button_large(ui, "transport_left", pause_icon, pause_tip, false)
|
||||
.clicked();
|
||||
if pause_clicked {
|
||||
toggle_play_paused(world);
|
||||
}
|
||||
let stop_clicked = ui
|
||||
.push_id("transport_center", |ui| {
|
||||
transport_button_large(ui, icons::STOP, "Stop and return to Edit (F5)", false)
|
||||
.clicked()
|
||||
})
|
||||
.inner;
|
||||
let stop_clicked = transport_button_large(
|
||||
ui,
|
||||
"transport_center",
|
||||
icons::STOP,
|
||||
"Stop and return to Edit (F5)",
|
||||
false,
|
||||
)
|
||||
.clicked();
|
||||
if stop_clicked {
|
||||
toggle_play_mode(world);
|
||||
}
|
||||
@@ -146,11 +203,9 @@ fn transport_controls(world: &mut World, ui: &mut egui::Ui) {
|
||||
PlayPossession::Possessed => (icons::SIGN_OUT, "Eject from player (F8)"),
|
||||
PlayPossession::Ejected => (icons::USER, "Possess player (F8)"),
|
||||
};
|
||||
let possession_clicked = ui
|
||||
.push_id("transport_right", |ui| {
|
||||
transport_button_large(ui, eject_icon, eject_tip, false).clicked()
|
||||
})
|
||||
.inner;
|
||||
let possession_clicked =
|
||||
transport_button_large(ui, "transport_right", eject_icon, eject_tip, false)
|
||||
.clicked();
|
||||
if possession_clicked {
|
||||
toggle_possession(world);
|
||||
}
|
||||
|
||||
@@ -7,12 +7,15 @@ use egui_phosphor_icons::icons;
|
||||
use transform_gizmo_bevy::prelude::GizmoOptions;
|
||||
|
||||
use crate::assets::operators::{
|
||||
apply_material_operator, apply_texture_operator, place_asset_operator, place_subasset_operator,
|
||||
apply_material_operator, apply_texture_operator, assign_animation_clip_operator,
|
||||
assign_audio_clip_operator, place_asset_operator, place_subasset_operator,
|
||||
};
|
||||
use crate::assets::thumbnails::kind_icon;
|
||||
use crate::assets::{AssetSelection, AssetSubAssetKind, EditorAssets};
|
||||
use crate::camera::EditorCamera;
|
||||
use crate::gizmos::{EditorGizmoMode, EditorGizmoSpace};
|
||||
use crate::render_target::ViewportRenderTarget;
|
||||
use crate::selection::ViewportClick;
|
||||
use crate::selection::{ViewportClick, ViewportPickStack};
|
||||
use crate::state::PlayPossession;
|
||||
use crate::viewport::actor_icons::ActorIconSettings;
|
||||
use crate::viewport::brush_edit::{BrushEditMode, BrushElementSelection};
|
||||
@@ -25,8 +28,13 @@ use crate::viewport::{
|
||||
use super::helpers::{
|
||||
focus_editor_camera_on_selection, viewport_recall_bookmark, viewport_save_bookmark,
|
||||
};
|
||||
use super::theme::viewport_toolbar_frame;
|
||||
use super::widgets::{icon_button_small, panel_toolbar_row, tool_button};
|
||||
use super::theme::{
|
||||
overlay_chip_frame, viewport_toolbar_frame, ACCENT, ACCENT_HOVER, AXIS_X, AXIS_Y, AXIS_Z,
|
||||
BORDER, BORDER_STRONG, ELEVATED_BG, SELECTION, SUCCESS, TEXT, TEXT_DIM, TEXT_MUTED, WARNING,
|
||||
};
|
||||
use super::widgets::{
|
||||
icon_button_small, panel_toolbar_row, phosphor_icon, tool_button, tool_button_accent,
|
||||
};
|
||||
|
||||
#[derive(Resource, Default)]
|
||||
pub struct ViewportUiState {
|
||||
@@ -97,6 +105,19 @@ pub fn viewport_tab_ui(
|
||||
egui::Rect::from_min_max(egui::pos2(0.0, 0.0), egui::pos2(1.0, 1.0)),
|
||||
egui::Color32::WHITE,
|
||||
);
|
||||
painter.rect_stroke(
|
||||
rect,
|
||||
0.0,
|
||||
egui::Stroke::new(
|
||||
1.0,
|
||||
if response.hovered() {
|
||||
BORDER_STRONG
|
||||
} else {
|
||||
BORDER
|
||||
},
|
||||
),
|
||||
egui::StrokeKind::Inside,
|
||||
);
|
||||
} else {
|
||||
ui.allocate_rect(rect, egui::Sense::hover());
|
||||
ui.scope_builder(egui::UiBuilder::new().max_rect(rect), |ui| {
|
||||
@@ -114,35 +135,49 @@ pub fn viewport_tab_ui(
|
||||
}
|
||||
|
||||
scene_view_overlay_toolbar(world, ui.ctx(), rect);
|
||||
scene_view_selection_hud(world, ui.ctx(), rect, selected_entities);
|
||||
scene_view_brush_draw_hints(world, ui.ctx(), rect);
|
||||
scene_view_mode_badge(world, ui.ctx(), rect);
|
||||
scene_view_render_badge(world, ui.ctx(), rect);
|
||||
scene_view_brush_mode_badge(world, ui.ctx(), rect);
|
||||
scene_view_gi_badge(world, ui.ctx(), rect);
|
||||
scene_view_volume_hud(world, ui.ctx(), rect);
|
||||
scene_view_orientation_widget(world, ui.ctx(), rect);
|
||||
viewport_asset_drop_ui(world, ui, rect, selected_entities);
|
||||
}
|
||||
|
||||
fn scene_view_mode_badge(world: &World, ctx: &egui::Context, scene_rect: egui::Rect) {
|
||||
fn scene_view_render_badge(world: &World, ctx: &egui::Context, scene_rect: egui::Rect) {
|
||||
let Some(mode) = world.get_resource::<EditorViewportMode>() else {
|
||||
return;
|
||||
};
|
||||
let mode = *mode;
|
||||
let (label, color) = match mode {
|
||||
EditorViewportMode::Lit => ("Lit", egui::Color32::from_rgb(120, 200, 120)),
|
||||
EditorViewportMode::Unlit => ("Unlit", egui::Color32::from_rgb(200, 200, 120)),
|
||||
EditorViewportMode::Collider => ("Collider", egui::Color32::from_rgb(220, 140, 80)),
|
||||
EditorViewportMode::Lit => ("Lit", SUCCESS),
|
||||
EditorViewportMode::Unlit => ("Unlit", WARNING),
|
||||
EditorViewportMode::Collider => ("Collider", WARNING),
|
||||
};
|
||||
|
||||
egui::Area::new(egui::Id::new("scene_view_mode_badge"))
|
||||
.fixed_pos(scene_rect.right_bottom() + egui::vec2(-72.0, -22.0))
|
||||
let profile = world.get_resource::<settings::ActiveCameraRenderProfile>();
|
||||
let (gi_label, gi_color) = match profile.map(|profile| profile.gi_path) {
|
||||
Some(settings::GiPath::SolariDeferred) => ("Solari", ACCENT),
|
||||
_ => ("Forward", SELECTION),
|
||||
};
|
||||
|
||||
egui::Area::new(egui::Id::new("scene_view_render_badge"))
|
||||
.fixed_pos(scene_rect.right_bottom() + egui::vec2(-10.0, -10.0))
|
||||
.pivot(egui::Align2::RIGHT_BOTTOM)
|
||||
.interactable(false)
|
||||
.show(ctx, |ui| {
|
||||
egui::Frame::NONE
|
||||
.fill(egui::Color32::from_black_alpha(160))
|
||||
.inner_margin(egui::Margin::symmetric(8, 4))
|
||||
.show(ui, |ui| {
|
||||
ui.colored_label(color, label);
|
||||
overlay_chip_frame().show(ui, |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
ui.label(egui::RichText::new(label).color(color).strong().small());
|
||||
ui.label(egui::RichText::new("/").color(TEXT_MUTED).small());
|
||||
ui.label(
|
||||
egui::RichText::new(gi_label)
|
||||
.color(gi_color)
|
||||
.strong()
|
||||
.small(),
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
if mode == EditorViewportMode::Collider {
|
||||
@@ -150,10 +185,13 @@ fn scene_view_mode_badge(world: &World, ctx: &egui::Context, scene_rect: egui::R
|
||||
.fixed_pos(scene_rect.left_bottom() + egui::vec2(8.0, -28.0))
|
||||
.interactable(false)
|
||||
.show(ctx, |ui| {
|
||||
ui.colored_label(
|
||||
egui::Color32::from_rgb(255, 180, 100),
|
||||
"Meshes hidden - switch to Lit (sun icon) for shading",
|
||||
);
|
||||
overlay_chip_frame().show(ui, |ui| {
|
||||
ui.label(
|
||||
egui::RichText::new("Collider view / meshes hidden")
|
||||
.color(WARNING)
|
||||
.small(),
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -173,51 +211,39 @@ fn scene_view_brush_mode_badge(world: &World, ctx: &egui::Context, scene_rect: e
|
||||
.fixed_pos(scene_rect.left_top() + egui::vec2(8.0, 52.0))
|
||||
.interactable(false)
|
||||
.show(ctx, |ui| {
|
||||
egui::Frame::new()
|
||||
.fill(egui::Color32::from_rgba_unmultiplied(20, 18, 28, 230))
|
||||
.stroke(egui::Stroke::new(
|
||||
1.0,
|
||||
egui::Color32::from_rgba_unmultiplied(210, 140, 255, 210),
|
||||
))
|
||||
.corner_radius(egui::CornerRadius::same(4))
|
||||
.inner_margin(egui::Margin::symmetric(8, 6))
|
||||
.show(ui, |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
ui.label(
|
||||
egui::RichText::new(format!("Brush {}", mode.label()))
|
||||
.color(egui::Color32::from_rgb(230, 190, 255))
|
||||
.strong(),
|
||||
);
|
||||
ui.label(
|
||||
egui::RichText::new(format!("{selected_count} selected"))
|
||||
.color(egui::Color32::from_rgb(205, 200, 215))
|
||||
.small(),
|
||||
);
|
||||
ui.label(
|
||||
egui::RichText::new("Element gizmo")
|
||||
.color(egui::Color32::from_rgb(255, 190, 120))
|
||||
.small(),
|
||||
);
|
||||
});
|
||||
ui.add_space(4.0);
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
match mode {
|
||||
BrushEditMode::Vertex => key_hint(ui, "LMB", "Select vertex"),
|
||||
BrushEditMode::Edge => key_hint(ui, "LMB", "Select edge"),
|
||||
BrushEditMode::Face => key_hint(ui, "LMB", "Select face"),
|
||||
BrushEditMode::Clip => key_hint(ui, "LMB", "Select face"),
|
||||
BrushEditMode::Object => {}
|
||||
}
|
||||
if !matches!(mode, BrushEditMode::Clip) {
|
||||
key_hint(ui, "W/E/R", "Move/rotate/scale");
|
||||
}
|
||||
if matches!(mode, BrushEditMode::Clip) {
|
||||
key_hint(ui, "Enter", "Clip");
|
||||
}
|
||||
key_hint(ui, "Shift+LMB", "Multi");
|
||||
key_hint(ui, "Esc", "Object");
|
||||
});
|
||||
overlay_chip_frame().show(ui, |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
ui.label(
|
||||
egui::RichText::new(format!("Brush {}", mode.label()))
|
||||
.color(ACCENT)
|
||||
.strong(),
|
||||
);
|
||||
ui.label(
|
||||
egui::RichText::new(format!("{selected_count} selected"))
|
||||
.color(SELECTION)
|
||||
.small(),
|
||||
);
|
||||
ui.label(egui::RichText::new("Element gizmo").color(SUCCESS).small());
|
||||
});
|
||||
ui.add_space(4.0);
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
match mode {
|
||||
BrushEditMode::Vertex => key_hint(ui, "LMB", "Select vertex"),
|
||||
BrushEditMode::Edge => key_hint(ui, "LMB", "Select edge"),
|
||||
BrushEditMode::Face => key_hint(ui, "LMB", "Select face"),
|
||||
BrushEditMode::Clip => key_hint(ui, "LMB", "Select face"),
|
||||
BrushEditMode::Object => {}
|
||||
}
|
||||
if !matches!(mode, BrushEditMode::Clip) {
|
||||
key_hint(ui, "W/E/R", "Move/rotate/scale");
|
||||
}
|
||||
if matches!(mode, BrushEditMode::Clip) {
|
||||
key_hint(ui, "Enter", "Clip");
|
||||
}
|
||||
key_hint(ui, "Shift+LMB", "Multi");
|
||||
key_hint(ui, "Esc", "Object");
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -237,51 +263,35 @@ fn scene_view_brush_draw_hints(world: &World, ctx: &egui::Context, scene_rect: e
|
||||
.fixed_pos(scene_rect.left_top() + egui::vec2(8.0, 52.0))
|
||||
.interactable(false)
|
||||
.show(ctx, |ui| {
|
||||
egui::Frame::new()
|
||||
.fill(egui::Color32::from_rgba_unmultiplied(18, 22, 26, 220))
|
||||
.stroke(egui::Stroke::new(
|
||||
1.0,
|
||||
egui::Color32::from_rgba_unmultiplied(95, 150, 190, 180),
|
||||
))
|
||||
.corner_radius(egui::CornerRadius::same(4))
|
||||
.inner_margin(egui::Margin::symmetric(8, 6))
|
||||
.show(ui, |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
ui.label(
|
||||
egui::RichText::new("Draw Brush")
|
||||
.color(egui::Color32::from_rgb(170, 220, 255))
|
||||
.strong(),
|
||||
);
|
||||
ui.label(
|
||||
egui::RichText::new(format!("{} pts", tool.vertices.len()))
|
||||
.color(egui::Color32::from_rgb(190, 200, 205))
|
||||
.small(),
|
||||
);
|
||||
ui.label(
|
||||
egui::RichText::new(hint)
|
||||
.color(egui::Color32::from_rgb(150, 220, 170))
|
||||
.small(),
|
||||
);
|
||||
});
|
||||
ui.add_space(4.0);
|
||||
ui.horizontal_wrapped(|ui| match tool.phase {
|
||||
BrushToolPhase::Outline => {
|
||||
key_hint(ui, "LMB", "Point");
|
||||
key_hint(ui, "Enter", "Height");
|
||||
key_hint(ui, "Backspace", "Remove");
|
||||
key_hint(ui, "Esc", "Cancel");
|
||||
key_hint(ui, "RMB", "Cancel");
|
||||
}
|
||||
BrushToolPhase::Height => {
|
||||
key_hint(ui, "Mouse Up/Down", "Height");
|
||||
key_hint(ui, "Enter", "Create");
|
||||
key_hint(ui, "LMB", "Create");
|
||||
key_hint(ui, "Backspace", "Outline");
|
||||
key_hint(ui, "Esc", "Cancel");
|
||||
key_hint(ui, "RMB", "Cancel");
|
||||
}
|
||||
});
|
||||
overlay_chip_frame().show(ui, |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
ui.label(egui::RichText::new("Draw Brush").color(SELECTION).strong());
|
||||
ui.label(
|
||||
egui::RichText::new(format!("{} pts", tool.vertices.len()))
|
||||
.color(TEXT_DIM)
|
||||
.small(),
|
||||
);
|
||||
ui.label(egui::RichText::new(hint).color(SUCCESS).small());
|
||||
});
|
||||
ui.add_space(4.0);
|
||||
ui.horizontal_wrapped(|ui| match tool.phase {
|
||||
BrushToolPhase::Outline => {
|
||||
key_hint(ui, "LMB", "Point");
|
||||
key_hint(ui, "Enter", "Height");
|
||||
key_hint(ui, "Backspace", "Remove");
|
||||
key_hint(ui, "Esc", "Cancel");
|
||||
key_hint(ui, "RMB", "Cancel");
|
||||
}
|
||||
BrushToolPhase::Height => {
|
||||
key_hint(ui, "Mouse Up/Down", "Height");
|
||||
key_hint(ui, "Enter", "Create");
|
||||
key_hint(ui, "LMB", "Create");
|
||||
key_hint(ui, "Backspace", "Outline");
|
||||
key_hint(ui, "Esc", "Cancel");
|
||||
key_hint(ui, "RMB", "Cancel");
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -290,35 +300,149 @@ fn key_hint(ui: &mut egui::Ui, key: &str, label: &str) {
|
||||
ui.label(
|
||||
egui::RichText::new(key)
|
||||
.monospace()
|
||||
.color(egui::Color32::from_rgb(232, 238, 242))
|
||||
.background_color(egui::Color32::from_rgba_unmultiplied(45, 52, 58, 220)),
|
||||
);
|
||||
ui.label(
|
||||
egui::RichText::new(label)
|
||||
.color(egui::Color32::from_rgb(190, 200, 205))
|
||||
.small(),
|
||||
.color(TEXT)
|
||||
.background_color(ELEVATED_BG),
|
||||
);
|
||||
ui.label(egui::RichText::new(label).color(TEXT_DIM).small());
|
||||
});
|
||||
}
|
||||
|
||||
fn scene_view_gi_badge(world: &World, ctx: &egui::Context, scene_rect: egui::Rect) {
|
||||
let Some(profile) = world.get_resource::<settings::ActiveCameraRenderProfile>() else {
|
||||
fn scene_view_selection_hud(
|
||||
world: &World,
|
||||
ctx: &egui::Context,
|
||||
scene_rect: egui::Rect,
|
||||
selected_entities: &SelectedEntities,
|
||||
) {
|
||||
let Some(&primary) = selected_entities.as_slice().first() else {
|
||||
return;
|
||||
};
|
||||
let (label, color) = match profile.gi_path {
|
||||
settings::GiPath::Forward => ("Forward", egui::Color32::from_rgb(140, 180, 255)),
|
||||
settings::GiPath::SolariDeferred => ("Solari", egui::Color32::from_rgb(255, 170, 90)),
|
||||
let name = world
|
||||
.get::<Name>(primary)
|
||||
.map(|name| name.as_str().to_string())
|
||||
.unwrap_or_else(|| "Selected entity".to_string());
|
||||
let kind = world
|
||||
.get::<shared::ActorKind>(primary)
|
||||
.map(|kind| format!("{kind:?}"))
|
||||
.unwrap_or_else(|| "Entity".to_string());
|
||||
let count = selected_entities.len();
|
||||
let selection_detail = if count > 1 {
|
||||
format!("{kind} / {count} selected")
|
||||
} else {
|
||||
kind
|
||||
};
|
||||
egui::Area::new(egui::Id::new("scene_view_gi_badge"))
|
||||
.fixed_pos(scene_rect.right_bottom() + egui::vec2(-148.0, -22.0))
|
||||
|
||||
let pick_detail = world.get_resource::<ViewportPickStack>().and_then(|stack| {
|
||||
(stack.entities.len() > 1 && stack.entities.contains(&primary)).then(|| {
|
||||
format!(
|
||||
"Pick {}/{}",
|
||||
stack.index.min(stack.entities.len() - 1) + 1,
|
||||
stack.entities.len()
|
||||
)
|
||||
})
|
||||
});
|
||||
let top_offset = if scene_rect.width() < 1100.0 {
|
||||
50.0
|
||||
} else {
|
||||
10.0
|
||||
};
|
||||
|
||||
egui::Area::new(egui::Id::new("scene_view_selection_hud"))
|
||||
.fixed_pos(scene_rect.right_top() + egui::vec2(-10.0, top_offset))
|
||||
.pivot(egui::Align2::RIGHT_TOP)
|
||||
.interactable(false)
|
||||
.show(ctx, |ui| {
|
||||
egui::Frame::NONE
|
||||
.fill(egui::Color32::from_black_alpha(160))
|
||||
.inner_margin(egui::Margin::symmetric(8, 4))
|
||||
.show(ui, |ui| {
|
||||
ui.colored_label(color, label);
|
||||
overlay_chip_frame().show(ui, |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
ui.label(phosphor_icon(icons::CROSSHAIR, 17.0).color(SELECTION));
|
||||
ui.vertical(|ui| {
|
||||
ui.set_max_width(260.0);
|
||||
ui.add(
|
||||
egui::Label::new(egui::RichText::new(&name).color(TEXT).strong())
|
||||
.truncate(),
|
||||
);
|
||||
ui.label(
|
||||
egui::RichText::new(&selection_detail)
|
||||
.color(TEXT_DIM)
|
||||
.small(),
|
||||
);
|
||||
});
|
||||
if let Some(pick_detail) = pick_detail {
|
||||
ui.separator();
|
||||
ui.label(
|
||||
egui::RichText::new(pick_detail)
|
||||
.color(ACCENT)
|
||||
.monospace()
|
||||
.small(),
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
fn scene_view_orientation_widget(world: &mut World, ctx: &egui::Context, scene_rect: egui::Rect) {
|
||||
let rotation = {
|
||||
let mut cameras = world.query_filtered::<(&Camera, &GlobalTransform), With<EditorCamera>>();
|
||||
let mut rotation = None;
|
||||
for (camera, transform) in cameras.iter(world) {
|
||||
rotation.get_or_insert(transform.rotation());
|
||||
if camera.is_active {
|
||||
rotation = Some(transform.rotation());
|
||||
break;
|
||||
}
|
||||
}
|
||||
rotation
|
||||
};
|
||||
let Some(rotation) = rotation else {
|
||||
return;
|
||||
};
|
||||
|
||||
egui::Area::new(egui::Id::new("scene_view_orientation_widget"))
|
||||
.fixed_pos(scene_rect.right_bottom() + egui::vec2(-10.0, -48.0))
|
||||
.pivot(egui::Align2::RIGHT_BOTTOM)
|
||||
.interactable(false)
|
||||
.show(ctx, |ui| {
|
||||
overlay_chip_frame().show(ui, |ui| {
|
||||
let (rect, _) =
|
||||
ui.allocate_exact_size(egui::vec2(72.0, 72.0), egui::Sense::hover());
|
||||
let painter = ui.painter_at(rect);
|
||||
let center = rect.center();
|
||||
painter.circle_filled(center, 4.0, egui::Color32::from_rgb(210, 214, 219));
|
||||
|
||||
let view_rotation = rotation.inverse();
|
||||
let mut axes = [
|
||||
("X", view_rotation * Vec3::X, AXIS_X),
|
||||
("Y", view_rotation * Vec3::Y, AXIS_Y),
|
||||
("Z", view_rotation * Vec3::Z, AXIS_Z),
|
||||
];
|
||||
axes.sort_by(|left, right| {
|
||||
left.1
|
||||
.z
|
||||
.partial_cmp(&right.1.z)
|
||||
.unwrap_or(std::cmp::Ordering::Equal)
|
||||
});
|
||||
for (label, axis, color) in axes {
|
||||
let endpoint = center + egui::vec2(axis.x, -axis.y) * 27.0;
|
||||
let facing = axis.z <= 0.0;
|
||||
let color = if facing {
|
||||
color
|
||||
} else {
|
||||
color.gamma_multiply(0.48)
|
||||
};
|
||||
painter.line_segment(
|
||||
[center, endpoint],
|
||||
egui::Stroke::new(if facing { 2.2 } else { 1.2 }, color),
|
||||
);
|
||||
painter.circle_filled(endpoint, if facing { 9.0 } else { 7.0 }, color);
|
||||
painter.text(
|
||||
endpoint,
|
||||
egui::Align2::CENTER_CENTER,
|
||||
label,
|
||||
egui::FontId::monospace(10.0),
|
||||
egui::Color32::from_rgb(18, 20, 22),
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -333,17 +457,26 @@ fn scene_view_volume_hud(world: &World, ctx: &egui::Context, scene_rect: egui::R
|
||||
.fixed_pos(scene_rect.left_bottom() + egui::vec2(8.0, -56.0))
|
||||
.interactable(false)
|
||||
.show(ctx, |ui| {
|
||||
egui::Frame::NONE
|
||||
.fill(egui::Color32::from_black_alpha(150))
|
||||
.inner_margin(egui::Margin::symmetric(8, 4))
|
||||
.show(ui, |ui| {
|
||||
ui.label(format!(
|
||||
"Volume: {} ({:.0}%, {} overrides)",
|
||||
primary.label,
|
||||
primary.weight * 100.0,
|
||||
primary.override_count
|
||||
));
|
||||
overlay_chip_frame().show(ui, |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
ui.label(phosphor_icon(icons::CUBE, 14.0).color(SELECTION));
|
||||
ui.label(
|
||||
egui::RichText::new(&primary.label)
|
||||
.color(TEXT)
|
||||
.strong()
|
||||
.small(),
|
||||
);
|
||||
ui.label(
|
||||
egui::RichText::new(format!(
|
||||
"{:.0}% / {} overrides",
|
||||
primary.weight * 100.0,
|
||||
primary.override_count
|
||||
))
|
||||
.color(TEXT_DIM)
|
||||
.small(),
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -358,7 +491,7 @@ fn scene_view_overlay_toolbar(world: &mut World, ctx: &egui::Context, scene_rect
|
||||
viewport_toolbar_frame().show(ui, |ui| {
|
||||
panel_toolbar_row(ui, |ui| {
|
||||
let gizmo_mode = *world.resource::<crate::gizmos::EditorGizmoMode>();
|
||||
if tool_button(
|
||||
if tool_button_accent(
|
||||
ui,
|
||||
icons::ARROWS_OUT_CARDINAL,
|
||||
gizmo_mode == EditorGizmoMode::Translate,
|
||||
@@ -368,7 +501,7 @@ fn scene_view_overlay_toolbar(world: &mut World, ctx: &egui::Context, scene_rect
|
||||
{
|
||||
super::helpers::set_gizmo_mode(world, EditorGizmoMode::Translate);
|
||||
}
|
||||
if tool_button(
|
||||
if tool_button_accent(
|
||||
ui,
|
||||
icons::ARROWS_CLOCKWISE,
|
||||
gizmo_mode == EditorGizmoMode::Rotate,
|
||||
@@ -378,7 +511,7 @@ fn scene_view_overlay_toolbar(world: &mut World, ctx: &egui::Context, scene_rect
|
||||
{
|
||||
super::helpers::set_gizmo_mode(world, EditorGizmoMode::Rotate);
|
||||
}
|
||||
if tool_button(
|
||||
if tool_button_accent(
|
||||
ui,
|
||||
icons::ARROWS_IN_LINE_HORIZONTAL,
|
||||
gizmo_mode == EditorGizmoMode::Scale,
|
||||
@@ -459,6 +592,14 @@ fn scene_view_overlay_toolbar(world: &mut World, ctx: &egui::Context, scene_rect
|
||||
if tool_button(ui, icons::MAGNET, snap, "Snap translation").clicked() {
|
||||
settings.snap_translate = !settings.snap_translate;
|
||||
}
|
||||
if settings.snap_translate {
|
||||
ui.label(
|
||||
egui::RichText::new(format!("{:.2}m", settings.snap_increment))
|
||||
.color(SELECTION)
|
||||
.monospace()
|
||||
.small(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(mut visualizers) =
|
||||
@@ -532,7 +673,8 @@ fn scene_options_popover(
|
||||
ui.checkbox(&mut settings.snap_translate, "Snap translation");
|
||||
ui.add(
|
||||
egui::Slider::new(&mut settings.snap_increment, 0.25..=4.0)
|
||||
.text("Snap step"),
|
||||
.text("Snap step")
|
||||
.suffix(" m"),
|
||||
);
|
||||
}
|
||||
if let Some(mut gizmo_options) = world.get_resource_mut::<GizmoOptions>() {
|
||||
@@ -564,6 +706,7 @@ fn scene_options_popover(
|
||||
ui.checkbox(&mut visualizers.show_actor_icon_actor, "Actors");
|
||||
ui.checkbox(&mut visualizers.show_actor_icon_mesh, "Meshes");
|
||||
ui.checkbox(&mut visualizers.show_actor_icon_light, "Lights");
|
||||
ui.checkbox(&mut visualizers.show_actor_icon_audio, "Audio");
|
||||
ui.checkbox(&mut visualizers.show_actor_icon_physics, "Physics");
|
||||
ui.checkbox(&mut visualizers.show_actor_icon_gameplay, "Gameplay");
|
||||
ui.checkbox(&mut visualizers.show_actor_icon_volume, "Volumes");
|
||||
@@ -578,7 +721,10 @@ fn scene_options_popover(
|
||||
ui.separator();
|
||||
ui.checkbox(&mut visualizers.show_colliders, "Colliders");
|
||||
ui.checkbox(&mut visualizers.show_lights, "Lights");
|
||||
ui.checkbox(&mut visualizers.show_audio, "Audio ranges");
|
||||
ui.checkbox(&mut visualizers.show_spawns, "Player spawns");
|
||||
ui.checkbox(&mut visualizers.show_gameplay, "Gameplay markers");
|
||||
ui.checkbox(&mut visualizers.show_volumes, "Volumes");
|
||||
ui.checkbox(
|
||||
&mut visualizers.show_prefab_model_anchors,
|
||||
"Prefab/model anchors",
|
||||
@@ -669,29 +815,74 @@ fn viewport_asset_drop_ui(
|
||||
viewport_rect: egui::Rect,
|
||||
selected: &SelectedEntities,
|
||||
) {
|
||||
let pointer_pos = ui.input(|input| input.pointer.hover_pos());
|
||||
let drag_selection = world
|
||||
.resource::<EditorAssets>()
|
||||
.dragging_selection()
|
||||
.cloned();
|
||||
let drag_descriptor = drag_selection
|
||||
.as_ref()
|
||||
.and_then(|selection| asset_drag_descriptor(world, selection, selected));
|
||||
let over_viewport = pointer_pos.is_some_and(|pos| viewport_rect.contains(pos));
|
||||
|
||||
if let (Some(pointer), Some((icon, label, action))) = (pointer_pos, drag_descriptor.as_ref()) {
|
||||
draw_asset_drag_preview(
|
||||
ui,
|
||||
viewport_rect,
|
||||
pointer,
|
||||
*icon,
|
||||
label,
|
||||
action,
|
||||
over_viewport,
|
||||
);
|
||||
}
|
||||
|
||||
if drag_selection.is_some() && over_viewport {
|
||||
ui.painter().rect_stroke(
|
||||
viewport_rect.shrink(2.0),
|
||||
0.0,
|
||||
egui::Stroke::new(2.0, ACCENT_HOVER),
|
||||
egui::StrokeKind::Inside,
|
||||
);
|
||||
}
|
||||
|
||||
let pointer_released = ui.input(|input| input.pointer.any_released());
|
||||
if !pointer_released {
|
||||
return;
|
||||
}
|
||||
|
||||
let pointer_pos = ui.input(|input| input.pointer.hover_pos());
|
||||
if !pointer_pos.is_some_and(|pos| viewport_rect.contains(pos)) {
|
||||
world.resource_mut::<EditorAssets>().clear_drag();
|
||||
return;
|
||||
}
|
||||
|
||||
let selection = {
|
||||
let assets = world.resource::<EditorAssets>();
|
||||
assets.dragging_selection().cloned()
|
||||
};
|
||||
world.resource_mut::<EditorAssets>().clear_drag();
|
||||
|
||||
let Some(selection) = selection else {
|
||||
let Some(selection) = drag_selection else {
|
||||
return;
|
||||
};
|
||||
let placement = viewport_ground_position(world, pointer_pos.unwrap(), viewport_rect)
|
||||
.map(|pos| snap_translation(pos, world.resource::<ViewportSettings>()))
|
||||
.unwrap_or(Vec3::ZERO);
|
||||
if matches!(
|
||||
selection,
|
||||
AssetSelection::SubAsset {
|
||||
kind: AssetSubAssetKind::AnimationClip,
|
||||
..
|
||||
}
|
||||
) {
|
||||
if let Some(entity) = selected
|
||||
.as_slice()
|
||||
.iter()
|
||||
.copied()
|
||||
.find(|entity| world.get::<shared::ModelRef>(*entity).is_some())
|
||||
{
|
||||
assign_animation_clip_operator(world, selection, entity);
|
||||
} else {
|
||||
place_subasset_operator(world, selection, placement);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if matches!(
|
||||
selection,
|
||||
AssetSelection::SubAsset {
|
||||
@@ -702,6 +893,15 @@ fn viewport_asset_drop_ui(
|
||||
place_subasset_operator(world, selection, placement);
|
||||
return;
|
||||
}
|
||||
if matches!(
|
||||
selection,
|
||||
AssetSelection::SubAsset {
|
||||
kind: AssetSubAssetKind::Skeleton,
|
||||
..
|
||||
}
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
if let AssetSelection::SubAsset {
|
||||
kind: AssetSubAssetKind::Texture,
|
||||
@@ -730,6 +930,19 @@ fn viewport_asset_drop_ui(
|
||||
let Some(asset) = asset else {
|
||||
return;
|
||||
};
|
||||
if matches!(asset.kind, crate::assets::EditorAssetKind::AudioClip) {
|
||||
if let Some(entity) = selected
|
||||
.as_slice()
|
||||
.iter()
|
||||
.copied()
|
||||
.find(|entity| world.get::<shared::AudioSourceDesc>(*entity).is_some())
|
||||
{
|
||||
assign_audio_clip_operator(world, asset, entity);
|
||||
} else {
|
||||
place_asset_operator(world, asset, placement);
|
||||
}
|
||||
return;
|
||||
}
|
||||
match asset.kind {
|
||||
crate::assets::EditorAssetKind::Texture => {
|
||||
apply_texture_operator(world, asset, selected);
|
||||
@@ -744,3 +957,204 @@ fn viewport_asset_drop_ui(
|
||||
|
||||
place_asset_operator(world, asset, placement);
|
||||
}
|
||||
|
||||
fn asset_drag_descriptor(
|
||||
world: &World,
|
||||
selection: &AssetSelection,
|
||||
selected: &SelectedEntities,
|
||||
) -> Option<(egui_phosphor_icons::Icon, String, String)> {
|
||||
let assets = world.resource::<EditorAssets>();
|
||||
let asset = assets.asset_for_selection(selection)?;
|
||||
let icon = match selection {
|
||||
AssetSelection::SubAsset {
|
||||
kind: AssetSubAssetKind::Mesh,
|
||||
..
|
||||
} => icons::CUBE,
|
||||
AssetSelection::SubAsset {
|
||||
kind: AssetSubAssetKind::Material,
|
||||
..
|
||||
} => icons::PAINT_BRUSH,
|
||||
AssetSelection::SubAsset {
|
||||
kind: AssetSubAssetKind::Texture,
|
||||
..
|
||||
} => icons::IMAGE,
|
||||
AssetSelection::SubAsset {
|
||||
kind: AssetSubAssetKind::Skeleton,
|
||||
..
|
||||
} => icons::BONE,
|
||||
AssetSelection::SubAsset {
|
||||
kind: AssetSubAssetKind::AnimationClip,
|
||||
..
|
||||
} => icons::FILM_STRIP,
|
||||
_ => kind_icon(&asset.kind),
|
||||
};
|
||||
let label = match selection {
|
||||
AssetSelection::SubAsset { label, .. } => label.clone(),
|
||||
_ => asset.label.clone(),
|
||||
};
|
||||
let action = match selection {
|
||||
AssetSelection::SubAsset {
|
||||
kind: AssetSubAssetKind::Texture,
|
||||
..
|
||||
} if !selected.is_empty() => "Apply texture to selection",
|
||||
AssetSelection::SubAsset {
|
||||
kind: AssetSubAssetKind::Material,
|
||||
..
|
||||
} if !selected.is_empty() => "Apply material to selection",
|
||||
AssetSelection::SubAsset {
|
||||
kind: AssetSubAssetKind::Skeleton,
|
||||
..
|
||||
} => "Inspect skeleton",
|
||||
AssetSelection::SubAsset {
|
||||
kind: AssetSubAssetKind::AnimationClip,
|
||||
..
|
||||
} if selected
|
||||
.as_slice()
|
||||
.iter()
|
||||
.any(|entity| world.get::<shared::ModelRef>(*entity).is_some()) =>
|
||||
{
|
||||
"Assign clip to animated actor"
|
||||
}
|
||||
AssetSelection::SubAsset {
|
||||
kind: AssetSubAssetKind::AnimationClip,
|
||||
..
|
||||
} => "Create animated actor",
|
||||
_ => match asset.kind {
|
||||
crate::assets::EditorAssetKind::Texture if !selected.is_empty() => {
|
||||
"Apply texture to selection"
|
||||
}
|
||||
crate::assets::EditorAssetKind::Material if !selected.is_empty() => {
|
||||
"Apply material to selection"
|
||||
}
|
||||
crate::assets::EditorAssetKind::AudioClip
|
||||
if selected
|
||||
.as_slice()
|
||||
.iter()
|
||||
.any(|entity| world.get::<shared::AudioSourceDesc>(*entity).is_some()) =>
|
||||
{
|
||||
"Assign clip to audio source"
|
||||
}
|
||||
crate::assets::EditorAssetKind::AudioClip => "Create audio source",
|
||||
_ => "Place in scene",
|
||||
},
|
||||
};
|
||||
Some((icon, label, action.to_string()))
|
||||
}
|
||||
|
||||
fn draw_asset_drag_preview(
|
||||
ui: &egui::Ui,
|
||||
viewport_rect: egui::Rect,
|
||||
pointer: egui::Pos2,
|
||||
icon: egui_phosphor_icons::Icon,
|
||||
label: &str,
|
||||
action: &str,
|
||||
over_viewport: bool,
|
||||
) {
|
||||
if over_viewport {
|
||||
let painter = ui.painter();
|
||||
painter.circle_filled(pointer, 3.0, ACCENT_HOVER);
|
||||
painter.circle_stroke(pointer, 11.0, egui::Stroke::new(1.5, ACCENT_HOVER));
|
||||
painter.line_segment(
|
||||
[
|
||||
pointer - egui::vec2(17.0, 0.0),
|
||||
pointer - egui::vec2(7.0, 0.0),
|
||||
],
|
||||
egui::Stroke::new(1.5, ACCENT_HOVER),
|
||||
);
|
||||
painter.line_segment(
|
||||
[
|
||||
pointer + egui::vec2(7.0, 0.0),
|
||||
pointer + egui::vec2(17.0, 0.0),
|
||||
],
|
||||
egui::Stroke::new(1.5, ACCENT_HOVER),
|
||||
);
|
||||
painter.line_segment(
|
||||
[
|
||||
pointer - egui::vec2(0.0, 17.0),
|
||||
pointer - egui::vec2(0.0, 7.0),
|
||||
],
|
||||
egui::Stroke::new(1.5, ACCENT_HOVER),
|
||||
);
|
||||
painter.line_segment(
|
||||
[
|
||||
pointer + egui::vec2(0.0, 7.0),
|
||||
pointer + egui::vec2(0.0, 17.0),
|
||||
],
|
||||
egui::Stroke::new(1.5, ACCENT_HOVER),
|
||||
);
|
||||
}
|
||||
|
||||
let content = ui.ctx().content_rect();
|
||||
let pos = egui::pos2(
|
||||
(pointer.x + 20.0).min(content.right() - 258.0),
|
||||
(pointer.y + 20.0).min(content.bottom() - 64.0),
|
||||
);
|
||||
egui::Area::new(egui::Id::new("asset_drag_preview"))
|
||||
.fixed_pos(pos)
|
||||
.default_size(egui::vec2(246.0, 60.0))
|
||||
.order(egui::Order::Tooltip)
|
||||
.interactable(false)
|
||||
.show(ui.ctx(), |ui| {
|
||||
ui.set_min_size(egui::vec2(246.0, 60.0));
|
||||
ui.set_max_size(egui::vec2(246.0, 60.0));
|
||||
overlay_chip_frame().show(ui, |ui| {
|
||||
ui.set_width(228.0);
|
||||
ui.horizontal(|ui| {
|
||||
ui.label(phosphor_icon(icon, 20.0).color(if over_viewport {
|
||||
ACCENT_HOVER
|
||||
} else {
|
||||
TEXT_DIM
|
||||
}));
|
||||
ui.vertical(|ui| {
|
||||
ui.spacing_mut().item_spacing.y = 1.0;
|
||||
ui.label(egui::RichText::new(label).strong().color(TEXT));
|
||||
ui.label(
|
||||
egui::RichText::new(if over_viewport {
|
||||
action
|
||||
} else {
|
||||
"Drag into the viewport"
|
||||
})
|
||||
.size(11.0)
|
||||
.color(if over_viewport {
|
||||
ACCENT_HOVER
|
||||
} else {
|
||||
TEXT_MUTED
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
if over_viewport {
|
||||
let corner = 16.0;
|
||||
let inset = viewport_rect.shrink(8.0);
|
||||
for (a, b, c) in [
|
||||
(
|
||||
inset.left_top(),
|
||||
egui::vec2(corner, 0.0),
|
||||
egui::vec2(0.0, corner),
|
||||
),
|
||||
(
|
||||
inset.right_top(),
|
||||
egui::vec2(-corner, 0.0),
|
||||
egui::vec2(0.0, corner),
|
||||
),
|
||||
(
|
||||
inset.left_bottom(),
|
||||
egui::vec2(corner, 0.0),
|
||||
egui::vec2(0.0, -corner),
|
||||
),
|
||||
(
|
||||
inset.right_bottom(),
|
||||
egui::vec2(-corner, 0.0),
|
||||
egui::vec2(0.0, -corner),
|
||||
),
|
||||
] {
|
||||
ui.painter()
|
||||
.line_segment([a, a + b], egui::Stroke::new(3.0, ACCENT_HOVER));
|
||||
ui.painter()
|
||||
.line_segment([a, a + c], egui::Stroke::new(3.0, ACCENT_HOVER));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,14 @@
|
||||
//! Reusable editor widgets: icon buttons, tool toggles, menu labels.
|
||||
|
||||
use std::hash::Hash;
|
||||
|
||||
use bevy_egui::egui::{self, Button, FontId, RichText, Ui, WidgetText};
|
||||
use egui_phosphor_icons::Icon;
|
||||
|
||||
use super::theme::{ACCENT, ACCENT_HOVER, ELEVATED_BG};
|
||||
use super::theme::{
|
||||
ACCENT, ACCENT_HOVER, BORDER, ELEVATED_BG, SELECTION, SELECTION_BG, SUCCESS, TEXT_MUTED,
|
||||
TEXT_SELECTED, WIDGET_BG,
|
||||
};
|
||||
|
||||
const PHOSPHOR: &str = "phosphor-regular";
|
||||
|
||||
@@ -15,42 +20,61 @@ pub fn phosphor_icon_text(icon: &str, size: f32) -> RichText {
|
||||
RichText::new(icon).font(FontId::new(size, egui::FontFamily::Name(PHOSPHOR.into())))
|
||||
}
|
||||
|
||||
/// Large transport control (Play / Pause / Stop / Eject) — icon only, tooltip for label.
|
||||
/// Large transport control (Play / Pause / Stop / Eject), icon-only with a tooltip.
|
||||
pub fn transport_button_large(
|
||||
ui: &mut Ui,
|
||||
id_salt: impl Hash,
|
||||
icon: Icon,
|
||||
tooltip: &str,
|
||||
accent: bool,
|
||||
) -> egui::Response {
|
||||
const SIZE: f32 = 44.0;
|
||||
const ICON_PX: f32 = 22.0;
|
||||
const SIZE: f32 = 40.0;
|
||||
const ICON_PX: f32 = 20.0;
|
||||
|
||||
let fill = if accent {
|
||||
ACCENT
|
||||
SUCCESS
|
||||
} else {
|
||||
ELEVATED_BG.linear_multiply(0.85)
|
||||
ELEVATED_BG.linear_multiply(0.9)
|
||||
};
|
||||
ui.add(
|
||||
Button::new(phosphor_icon(icon, ICON_PX))
|
||||
.fill(fill)
|
||||
.stroke(egui::Stroke::new(
|
||||
1.0,
|
||||
if accent {
|
||||
ACCENT_HOVER
|
||||
} else {
|
||||
super::theme::BORDER
|
||||
},
|
||||
))
|
||||
.min_size(egui::vec2(SIZE, SIZE))
|
||||
.corner_radius(5.0),
|
||||
)
|
||||
.on_hover_text(tooltip)
|
||||
let (_, rect) = ui.allocate_space(egui::vec2(SIZE, SIZE));
|
||||
let response = ui.interact(rect, ui.make_persistent_id(id_salt), egui::Sense::click());
|
||||
response.widget_info(|| {
|
||||
egui::WidgetInfo::labeled(egui::WidgetType::Button, ui.is_enabled(), tooltip)
|
||||
});
|
||||
let fill = if response.is_pointer_button_down_on() {
|
||||
fill.linear_multiply(0.82)
|
||||
} else if response.hovered() {
|
||||
fill.linear_multiply(1.15)
|
||||
} else {
|
||||
fill
|
||||
};
|
||||
let stroke = egui::Stroke::new(
|
||||
if response.hovered() { 1.5 } else { 1.0 },
|
||||
if accent {
|
||||
SUCCESS.linear_multiply(1.15)
|
||||
} else if response.hovered() {
|
||||
TEXT_MUTED
|
||||
} else {
|
||||
BORDER
|
||||
},
|
||||
);
|
||||
ui.painter()
|
||||
.rect(rect, 6.0, fill, stroke, egui::StrokeKind::Inside);
|
||||
ui.painter().text(
|
||||
rect.center(),
|
||||
egui::Align2::CENTER_CENTER,
|
||||
icon.as_str(),
|
||||
FontId::new(ICON_PX, egui::FontFamily::Name(PHOSPHOR.into())),
|
||||
TEXT_SELECTED,
|
||||
);
|
||||
response.on_hover_text(tooltip)
|
||||
}
|
||||
|
||||
pub fn icon_button(ui: &mut Ui, icon: Icon, tooltip: &str) -> egui::Response {
|
||||
ui.add(
|
||||
Button::new(phosphor_icon(icon, 18.0))
|
||||
.frame(false)
|
||||
Button::new(phosphor_icon(icon, 17.0))
|
||||
.fill(WIDGET_BG.linear_multiply(0.78))
|
||||
.stroke(egui::Stroke::new(1.0, BORDER))
|
||||
.min_size(egui::vec2(32.0, 32.0)),
|
||||
)
|
||||
.on_hover_text(tooltip)
|
||||
@@ -59,31 +83,56 @@ pub fn icon_button(ui: &mut Ui, icon: Icon, tooltip: &str) -> egui::Response {
|
||||
pub fn icon_button_small(ui: &mut Ui, icon: Icon, tooltip: &str) -> egui::Response {
|
||||
ui.add(
|
||||
Button::new(phosphor_icon(icon, 16.0))
|
||||
.frame(false)
|
||||
.min_size(egui::vec2(22.0, 22.0)),
|
||||
.fill(WIDGET_BG.linear_multiply(0.72))
|
||||
.stroke(egui::Stroke::new(1.0, BORDER))
|
||||
.min_size(egui::vec2(27.0, 27.0))
|
||||
.corner_radius(4.0),
|
||||
)
|
||||
.on_hover_text(tooltip)
|
||||
}
|
||||
|
||||
pub fn tool_button(ui: &mut Ui, icon: Icon, selected: bool, tooltip: &str) -> egui::Response {
|
||||
tool_button_with_color(ui, icon, selected, tooltip, SELECTION_BG, SELECTION)
|
||||
}
|
||||
|
||||
pub fn tool_button_accent(
|
||||
ui: &mut Ui,
|
||||
icon: Icon,
|
||||
selected: bool,
|
||||
tooltip: &str,
|
||||
) -> egui::Response {
|
||||
tool_button_with_color(
|
||||
ui,
|
||||
icon,
|
||||
selected,
|
||||
tooltip,
|
||||
ACCENT.linear_multiply(0.84),
|
||||
ACCENT_HOVER,
|
||||
)
|
||||
}
|
||||
|
||||
fn tool_button_with_color(
|
||||
ui: &mut Ui,
|
||||
icon: Icon,
|
||||
selected: bool,
|
||||
tooltip: &str,
|
||||
selected_fill: egui::Color32,
|
||||
selected_stroke: egui::Color32,
|
||||
) -> egui::Response {
|
||||
let fill = if selected {
|
||||
ACCENT
|
||||
selected_fill
|
||||
} else {
|
||||
ELEVATED_BG.linear_multiply(0.6)
|
||||
WIDGET_BG.linear_multiply(0.82)
|
||||
};
|
||||
ui.add(
|
||||
Button::new(phosphor_icon(icon, 16.0))
|
||||
Button::new(phosphor_icon(icon, 17.0))
|
||||
.fill(fill)
|
||||
.stroke(egui::Stroke::new(
|
||||
1.0,
|
||||
if selected {
|
||||
ACCENT
|
||||
} else {
|
||||
super::theme::BORDER
|
||||
},
|
||||
if selected { selected_stroke } else { BORDER },
|
||||
))
|
||||
.min_size(egui::vec2(26.0, 26.0))
|
||||
.corner_radius(3.0),
|
||||
.min_size(egui::vec2(30.0, 30.0))
|
||||
.corner_radius(4.0),
|
||||
)
|
||||
.on_hover_text(tooltip)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user