use bevy::prelude::World;
use bevy_animation_graph::{core::animation_clip::EntityPath, prelude::AnimatedSceneInstance};
use egui_dock::egui;
use crate::{
tree::{Tree, TreeResult},
ui::{
PreviewScene,
native_windows::{EditorWindowContext, NativeEditorWindowExtension},
utils,
},
};
#[derive(Debug)]
pub struct PreviewHierarchyWindow;
impl NativeEditorWindowExtension for PreviewHierarchyWindow {
fn ui(&self, ui: &mut egui::Ui, world: &mut World, ctx: &mut EditorWindowContext) {
let mut query = world.query::<(&AnimatedSceneInstance, &PreviewScene)>();
let Ok((instance, _)) = query.single(world) else {
return;
};
let entity = instance.player_entity();
let tree = Tree::entity_tree(world, entity);
match utils::select_from_branches(ui, tree.0) {
TreeResult::Leaf((_, path), _) => {
let path = EntityPath { parts: path };
ui.output_mut(|o| {
o.commands
.push(egui::OutputCommand::CopyText(path.to_slashed_string()))
});
ctx.notifications
.info(format!("{} copied to clipboard", path.to_slashed_string()));
}
TreeResult::Node((_, path), _) => {
let path = EntityPath { parts: path };
ui.output_mut(|o| {
o.commands
.push(egui::OutputCommand::CopyText(path.to_slashed_string()))
});
ctx.notifications
.info(format!("{} copied to clipboard", path.to_slashed_string()));
}
TreeResult::None => (),
}
}
fn display_name(&self) -> String {
"Preview Hierarchy".to_string()
}
}