diff --git a/editor/src/lib.rs b/editor/src/lib.rs index 4755ee032..90a1486f9 100644 --- a/editor/src/lib.rs +++ b/editor/src/lib.rs @@ -57,6 +57,7 @@ pub mod world; pub use fyrox; +use crate::scene::controller::SceneController; use crate::world::create::EntityCreator; use crate::{ asset::{item::AssetItem, AssetBrowser}, @@ -1345,7 +1346,7 @@ impl Editor { if self.settings.general.show_node_removal_dialog && game_scene.is_current_selection_has_external_refs( &entry.selection, - &engine.scenes[game_scene.scene].graph, + engine, ) { can_delete_immediately = false; diff --git a/editor/src/scene/controller.rs b/editor/src/scene/controller.rs index dd9d7efc7..f7a8cbe72 100644 --- a/editor/src/scene/controller.rs +++ b/editor/src/scene/controller.rs @@ -21,9 +21,10 @@ use crate::{ command::{Command, CommandStack}, fyrox::{ - core::{algebra::Vector2, math::Rect, pool::Handle}, + core::{algebra::Vector2, define_as_any_trait, math::Rect, pool::Handle}, engine::Engine, gui::{ + file_browser::FileType, message::{KeyCode, MouseButton}, UiNode, }, @@ -34,8 +35,6 @@ use crate::{ settings::{keys::KeyBindings, Settings}, Message, }; -use fyrox::core::define_as_any_trait; -use fyrox::gui::file_browser::FileType; use std::path::Path; define_as_any_trait!(SceneControllerAsAny => SceneController); @@ -169,6 +168,13 @@ pub trait SceneController: SceneControllerAsAny { selection: &mut Selection, engine: &mut Engine, ) -> Vec; + + /// Checks whether the current selection has references to the nodes outside of the selection. + fn is_current_selection_has_external_refs( + &self, + editor_selection: &Selection, + engine: &Engine, + ) -> bool; } impl dyn SceneController { diff --git a/editor/src/scene/mod.rs b/editor/src/scene/mod.rs index 2949a8b78..3df2e845c 100644 --- a/editor/src/scene/mod.rs +++ b/editor/src/scene/mod.rs @@ -17,6 +17,7 @@ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. + use crate::{ asset::item::AssetItem, audio::AudioBusSelection, @@ -26,6 +27,7 @@ use crate::{ asset::manager::ResourceManager, core::{ algebra::{Matrix4, Vector2, Vector3}, + blank_reflect_ref, color::Color, define_as_any_trait, futures::executor::block_on, @@ -34,15 +36,16 @@ use crate::{ math::{aabb::AxisAlignedBoundingBox, plane::Plane, Rect}, pool::{ErasedHandle, Handle}, reflect::Reflect, + uuid::Uuid, visitor::Visitor, }, - engine::{Engine, SerializationContext}, + engine::{Engine, GraphicsContext, SerializationContext}, fxhash::FxHashSet, graph::{NodeWrapper, SceneGraph}, gui::{ + file_browser::FileType, inspector::PropertyChanged, - message::UiMessage, - message::{KeyCode, MessageDirection, MouseButton}, + message::{KeyCode, MessageDirection, MouseButton, UiMessage}, UiNode, }, material::{ @@ -55,16 +58,17 @@ use crate::{ scene::{ base::BaseBuilder, camera::{Camera, Projection}, + collider::BitMask, debug::{Line, SceneDrawingContext}, graph::{Graph, GraphUpdateSwitches}, light::{point::PointLight, spot::SpotLight}, - mesh::RenderPath, mesh::{ surface::{SurfaceBuilder, SurfaceData, SurfaceResource}, - Mesh, MeshBuilder, + Mesh, MeshBuilder, RenderPath, }, navmesh::NavigationalMesh, node::Node, + pivot::Pivot, pivot::PivotBuilder, terrain::Terrain, Scene, SceneContainer, @@ -95,12 +99,6 @@ use crate::{ world::selection::GraphSelection, Message, Settings, }; -use fyrox::core::blank_reflect_ref; -use fyrox::core::uuid::Uuid; -use fyrox::engine::GraphicsContext; -use fyrox::gui::file_browser::FileType; -use fyrox::scene::collider::BitMask; -use fyrox::scene::pivot::Pivot; use std::{ cell::RefCell, fmt::Debug, @@ -434,17 +432,6 @@ impl GameScene { ); } - /// Checks whether the current graph selection has references to the nodes outside of the selection. - pub fn is_current_selection_has_external_refs( - &self, - editor_selection: &Selection, - graph: &Graph, - ) -> bool { - editor_selection - .as_graph() - .is_some_and(|s| !graph.external_refs(s.nodes()).is_empty()) - } - fn try_save_selection_as_prefab(&self, path: &Path, selection: &Selection, engine: &Engine) { let source_scene = &engine.scenes[self.scene]; let mut dest_scene = Scene::new(); @@ -1118,6 +1105,17 @@ impl SceneController for GameScene { }) .collect::>() } + + fn is_current_selection_has_external_refs( + &self, + editor_selection: &Selection, + engine: &Engine, + ) -> bool { + let graph = &engine.scenes[self.scene].graph; + editor_selection + .as_graph() + .is_some_and(|s| !graph.external_refs(s.nodes()).is_empty()) + } } define_as_any_trait!(SelectionContainerAsAny => SelectionContainer); diff --git a/editor/src/scene/nullscene.rs b/editor/src/scene/nullscene.rs index 285955297..c2b62d10c 100644 --- a/editor/src/scene/nullscene.rs +++ b/editor/src/scene/nullscene.rs @@ -273,4 +273,12 @@ impl SceneController for NullSceneController { }) .collect::>() } + + fn is_current_selection_has_external_refs( + &self, + editor_selection: &Selection, + engine: &Engine, + ) -> bool { + false + } } diff --git a/editor/src/ui_scene/mod.rs b/editor/src/ui_scene/mod.rs index 7311d121b..7df7a5454 100644 --- a/editor/src/ui_scene/mod.rs +++ b/editor/src/ui_scene/mod.rs @@ -506,4 +506,14 @@ impl SceneController for UiScene { }) .collect::>() } + + fn is_current_selection_has_external_refs( + &self, + editor_selection: &Selection, + _engine: &Engine, + ) -> bool { + editor_selection + .as_ui() + .is_some_and(|s| !self.ui.external_refs(&s.widgets).is_empty()) + } } diff --git a/editor/src/world/menu.rs b/editor/src/world/menu.rs index f2e04e69b..53eba1083 100644 --- a/editor/src/world/menu.rs +++ b/editor/src/world/menu.rs @@ -278,10 +278,8 @@ impl SceneNodeContextMenu { if let Some(MenuItemMessage::Click) = message.data::() { if message.destination() == self.delete_selection { if settings.general.show_node_removal_dialog - && game_scene.is_current_selection_has_external_refs( - editor_selection, - &engine.scenes[game_scene.scene].graph, - ) + && game_scene + .is_current_selection_has_external_refs(editor_selection, engine) { sender.send(Message::OpenNodeRemovalDialog); } else if let Some(command) =