mirror of
https://github.com/FyroxEngine/Fyrox.git
synced 2026-10-12 02:02:20 +00:00
update list of entities to create when adding a plugin to the editor
This commit is contained in:
+19
-1
@@ -57,6 +57,7 @@ pub mod world;
|
||||
|
||||
pub use fyrox;
|
||||
|
||||
use crate::world::WorldViewerItemContextMenu;
|
||||
use crate::{
|
||||
asset::{item::AssetItem, AssetBrowser},
|
||||
audio::{preview::AudioPreviewPanel, AudioPanel},
|
||||
@@ -2840,12 +2841,28 @@ impl Editor {
|
||||
);
|
||||
}
|
||||
|
||||
fn on_game_plugin_added(&mut self) {
|
||||
let mut widget_context_menu = self.widget_context_menu.borrow_mut();
|
||||
let mut scene_node_context_menu = self.scene_node_context_menu.borrow_mut();
|
||||
for menu in [
|
||||
&mut *widget_context_menu as &mut dyn WorldViewerItemContextMenu,
|
||||
&mut *scene_node_context_menu as &mut dyn WorldViewerItemContextMenu,
|
||||
] {
|
||||
menu.on_plugin_added(
|
||||
&self.engine.serialization_context,
|
||||
&self.engine.widget_constructors,
|
||||
self.engine.user_interfaces.first_mut(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn add_game_plugin<P>(&mut self, plugin: P)
|
||||
where
|
||||
P: Plugin + 'static,
|
||||
{
|
||||
plugin.register_property_editors(self.property_editors.clone());
|
||||
self.engine.add_plugin(plugin)
|
||||
self.engine.add_plugin(plugin);
|
||||
self.on_game_plugin_added();
|
||||
}
|
||||
|
||||
/// Tries to add a new dynamic plugin. This method attempts to load a dynamic library by the
|
||||
@@ -2882,6 +2899,7 @@ impl Editor {
|
||||
let plugin = self.engine.add_dynamic_plugin_custom(plugin);
|
||||
*self.property_editors.context_type_id.safe_lock() = plugin.type_id();
|
||||
plugin.register_property_editors(self.property_editors.clone());
|
||||
self.on_game_plugin_added();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
+37
-13
@@ -19,16 +19,22 @@
|
||||
// SOFTWARE.
|
||||
|
||||
use crate::{
|
||||
fyrox::graph::{NodeWrapper, SceneGraph},
|
||||
fyrox::{
|
||||
core::pool::Handle,
|
||||
asset::manager::ResourceManager,
|
||||
core::{
|
||||
pool::Handle,
|
||||
uuid::{uuid, Uuid},
|
||||
},
|
||||
engine::SerializationContext,
|
||||
graph::{NodeWrapper, SceneGraph},
|
||||
gui::{
|
||||
menu::MenuItemMessage,
|
||||
constructor::WidgetConstructorContainer,
|
||||
menu::{ContextMenuBuilder, MenuItem, MenuItemMessage},
|
||||
message::UiMessage,
|
||||
popup::{Placement, PopupBuilder, PopupMessage},
|
||||
stack_panel::StackPanelBuilder,
|
||||
stack_panel::{StackPanel, StackPanelBuilder},
|
||||
widget::{WidgetBuilder, WidgetMessage},
|
||||
BuildContext, RcUiNodeHandle, UiNode,
|
||||
BuildContext, RcUiNodeHandle, UiNode, UserInterface,
|
||||
},
|
||||
},
|
||||
menu::{create_menu_item, create_menu_item_shortcut, ui::UiMenu},
|
||||
@@ -42,10 +48,6 @@ use crate::{
|
||||
world::WorldViewerItemContextMenu,
|
||||
Engine, Message,
|
||||
};
|
||||
use fyrox::asset::manager::ResourceManager;
|
||||
use fyrox::core::uuid::{uuid, Uuid};
|
||||
use fyrox::gui::constructor::WidgetConstructorContainer;
|
||||
use fyrox::gui::menu::{ContextMenuBuilder, MenuItem};
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub struct WidgetContextMenu {
|
||||
@@ -57,12 +59,31 @@ pub struct WidgetContextMenu {
|
||||
paste: Handle<MenuItem>,
|
||||
make_root: Handle<MenuItem>,
|
||||
open_asset: Handle<MenuItem>,
|
||||
stack_panel: Handle<StackPanel>,
|
||||
}
|
||||
|
||||
impl WorldViewerItemContextMenu for WidgetContextMenu {
|
||||
fn menu(&self) -> RcUiNodeHandle {
|
||||
self.menu.clone()
|
||||
}
|
||||
|
||||
fn on_plugin_added(
|
||||
&mut self,
|
||||
_serialization_context: &SerializationContext,
|
||||
widget_constructors_container: &WidgetConstructorContainer,
|
||||
ui: &mut UserInterface,
|
||||
) {
|
||||
ui.send(self.widgets_menu.menu, WidgetMessage::Remove);
|
||||
self.widgets_menu = UiMenu::new(
|
||||
widget_constructors_container,
|
||||
"Create Child Widget",
|
||||
&mut ui.build_ctx(),
|
||||
);
|
||||
ui.send(
|
||||
self.widgets_menu.menu,
|
||||
WidgetMessage::LinkWith(self.stack_panel.to_base()),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn resource_path_of_first_selected_node(
|
||||
@@ -104,10 +125,11 @@ impl WidgetContextMenu {
|
||||
|
||||
let widgets_menu = UiMenu::new(widget_constructors_container, "Create Child Widget", ctx);
|
||||
|
||||
let stack_panel;
|
||||
let menu = ContextMenuBuilder::new(
|
||||
PopupBuilder::new(WidgetBuilder::new().with_visibility(false))
|
||||
.with_content(
|
||||
StackPanelBuilder::new(
|
||||
.with_content({
|
||||
stack_panel = StackPanelBuilder::new(
|
||||
WidgetBuilder::new()
|
||||
.with_child({
|
||||
delete_selection = create_menu_item_shortcut(
|
||||
@@ -152,8 +174,9 @@ impl WidgetContextMenu {
|
||||
})
|
||||
.with_child(widgets_menu.menu),
|
||||
)
|
||||
.build(ctx),
|
||||
)
|
||||
.build(ctx);
|
||||
stack_panel
|
||||
})
|
||||
.with_restrict_picking(false),
|
||||
)
|
||||
.build(ctx);
|
||||
@@ -168,6 +191,7 @@ impl WidgetContextMenu {
|
||||
paste,
|
||||
make_root,
|
||||
open_asset,
|
||||
stack_panel,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+42
-15
@@ -22,22 +22,27 @@ use crate::{
|
||||
command::{Command, CommandGroup},
|
||||
fyrox::{
|
||||
asset::untyped::UntypedResource,
|
||||
core::{algebra::Vector2, algebra::Vector3, pool::Handle, reflect::Reflect},
|
||||
core::{
|
||||
algebra::{Vector2, Vector3},
|
||||
pool::Handle,
|
||||
reflect::Reflect,
|
||||
uuid::{uuid, Uuid},
|
||||
},
|
||||
engine::SerializationContext,
|
||||
graph::SceneGraph,
|
||||
gui::{
|
||||
constructor::WidgetConstructorContainer,
|
||||
file_browser::FileSelectorMessage,
|
||||
file_browser::{FileSelector, FileSelectorMessage, FileType},
|
||||
menu::{
|
||||
self, ContextMenuBuilder, MenuItemBuilder, MenuItemContent, MenuItemMessage,
|
||||
SortingPredicate,
|
||||
self, ContextMenuBuilder, MenuItem, MenuItemBuilder, MenuItemContent,
|
||||
MenuItemMessage, SortingPredicate,
|
||||
},
|
||||
message::UiMessage,
|
||||
popup::{Placement, PopupBuilder, PopupMessage},
|
||||
stack_panel::StackPanelBuilder,
|
||||
widget::{WidgetBuilder, WidgetMessage},
|
||||
window::WindowMessage,
|
||||
BuildContext, RcUiNodeHandle, UiNode,
|
||||
window::{WindowAlignment, WindowMessage},
|
||||
BuildContext, RcUiNodeHandle, UiNode, UserInterface,
|
||||
},
|
||||
},
|
||||
make_save_file_selector,
|
||||
@@ -59,19 +64,18 @@ use crate::{
|
||||
world::WorldViewerItemContextMenu,
|
||||
Engine, Message, PasteCommand,
|
||||
};
|
||||
use fyrox::core::uuid::{uuid, Uuid};
|
||||
use fyrox::gui::file_browser::{FileSelector, FileType};
|
||||
use fyrox::gui::menu::MenuItem;
|
||||
use fyrox::gui::window::WindowAlignment;
|
||||
use std::{any::TypeId, path::PathBuf};
|
||||
|
||||
pub struct SceneNodeContextMenu {
|
||||
menu: RcUiNodeHandle,
|
||||
delete_selection: Handle<MenuItem>,
|
||||
copy_selection: Handle<MenuItem>,
|
||||
create_child_menu: Handle<MenuItem>,
|
||||
create_child_entity_menu: CreateEntityMenu,
|
||||
create_parent_menu: Handle<MenuItem>,
|
||||
create_parent_entity_menu: CreateEntityMenu,
|
||||
replace_with_menu: CreateEntityMenu,
|
||||
replace_with_menu: Handle<MenuItem>,
|
||||
replace_with_entity_menu: CreateEntityMenu,
|
||||
placement_target: Handle<UiNode>,
|
||||
save_as_prefab: Handle<MenuItem>,
|
||||
save_as_prefab_dialog: Handle<FileSelector>,
|
||||
@@ -85,6 +89,26 @@ impl WorldViewerItemContextMenu for SceneNodeContextMenu {
|
||||
fn menu(&self) -> RcUiNodeHandle {
|
||||
self.menu.clone()
|
||||
}
|
||||
|
||||
fn on_plugin_added(
|
||||
&mut self,
|
||||
serialization_context: &SerializationContext,
|
||||
widget_constructors_container: &WidgetConstructorContainer,
|
||||
ui: &mut UserInterface,
|
||||
) {
|
||||
for (handle, menu) in [
|
||||
(self.create_child_menu, &mut self.create_child_entity_menu),
|
||||
(self.create_parent_menu, &mut self.create_parent_entity_menu),
|
||||
(self.replace_with_menu, &mut self.replace_with_entity_menu),
|
||||
] {
|
||||
*menu = CreateEntityMenu::new(
|
||||
serialization_context,
|
||||
widget_constructors_container,
|
||||
&mut ui.build_ctx(),
|
||||
);
|
||||
ui.send(handle, MenuItemMessage::Items(menu.root_items.clone()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn resource_path_of_first_selected_node(
|
||||
@@ -141,7 +165,7 @@ impl SceneNodeContextMenu {
|
||||
CreateEntityMenu::new(serialization_context, widget_constructors_container, ctx);
|
||||
let create_parent_entity_menu =
|
||||
CreateEntityMenu::new(serialization_context, widget_constructors_container, ctx);
|
||||
let replace_with_menu =
|
||||
let replace_with_entity_menu =
|
||||
CreateEntityMenu::new(serialization_context, widget_constructors_container, ctx);
|
||||
|
||||
let menu = ContextMenuBuilder::new(
|
||||
@@ -209,7 +233,7 @@ impl SceneNodeContextMenu {
|
||||
.with_min_size(Vector2::new(120.0, 22.0)),
|
||||
)
|
||||
.with_content(MenuItemContent::text("Replace With Node"))
|
||||
.with_items(replace_with_menu.root_items.clone())
|
||||
.with_items(replace_with_entity_menu.root_items.clone())
|
||||
.build(ctx);
|
||||
replace_with
|
||||
})
|
||||
@@ -273,12 +297,15 @@ impl SceneNodeContextMenu {
|
||||
placement_target: Default::default(),
|
||||
save_as_prefab,
|
||||
save_as_prefab_dialog: Default::default(),
|
||||
replace_with_menu,
|
||||
replace_with_entity_menu,
|
||||
paste,
|
||||
make_root,
|
||||
open_asset,
|
||||
reset_inheritable_properties,
|
||||
create_parent_entity_menu,
|
||||
create_child_menu: create_child,
|
||||
create_parent_menu: create_parent,
|
||||
replace_with_menu: replace_with,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -350,7 +377,7 @@ impl SceneNodeContextMenu {
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if let Some(replacement) = self.replace_with_menu.handle_ui_message(
|
||||
} else if let Some(replacement) = self.replace_with_entity_menu.handle_ui_message(
|
||||
message,
|
||||
sender,
|
||||
controller,
|
||||
|
||||
@@ -57,7 +57,9 @@ use crate::{
|
||||
};
|
||||
use fyrox::core::color::Color;
|
||||
use fyrox::core::pool::HandlesVecExtension;
|
||||
use fyrox::engine::SerializationContext;
|
||||
use fyrox::gui::button::Button;
|
||||
use fyrox::gui::constructor::WidgetConstructorContainer;
|
||||
use fyrox::gui::scroll_viewer::ScrollViewer;
|
||||
use fyrox::gui::searchbar::SearchBar;
|
||||
use fyrox::gui::text_box::EmptyTextPlaceholder;
|
||||
@@ -137,6 +139,12 @@ pub trait WorldViewerDataProvider {
|
||||
|
||||
pub trait WorldViewerItemContextMenu {
|
||||
fn menu(&self) -> RcUiNodeHandle;
|
||||
fn on_plugin_added(
|
||||
&mut self,
|
||||
serialization_context: &SerializationContext,
|
||||
widget_constructors_container: &WidgetConstructorContainer,
|
||||
ui: &mut UserInterface,
|
||||
);
|
||||
}
|
||||
|
||||
pub struct WorldViewer {
|
||||
|
||||
Reference in New Issue
Block a user