mirror of
https://github.com/FyroxEngine/Fyrox.git
synced 2026-10-11 22:50:08 +00:00
ability to mark scene to load at editor startup from context menu
This commit is contained in:
@@ -24,46 +24,50 @@ use crate::{
|
||||
pool::Handle,
|
||||
uuid::{uuid, Uuid},
|
||||
},
|
||||
graph::SceneGraph,
|
||||
gui::{
|
||||
menu::{ContextMenuBuilder, MenuItem, MenuItemMessage},
|
||||
message::UiMessage,
|
||||
popup::PopupBuilder,
|
||||
popup::{Placement, PopupBuilder, PopupMessage},
|
||||
stack_panel::StackPanelBuilder,
|
||||
widget::WidgetBuilder,
|
||||
BuildContext, RcUiNodeHandle,
|
||||
BuildContext, RcUiNodeHandle, UiNode, UserInterface,
|
||||
},
|
||||
},
|
||||
menu::create_menu_item,
|
||||
};
|
||||
use fyrox::graph::SceneGraph;
|
||||
use fyrox::gui::popup::{Placement, PopupMessage};
|
||||
use fyrox::gui::{UiNode, UserInterface};
|
||||
|
||||
pub struct SceneItemMenu {
|
||||
pub menu: RcUiNodeHandle,
|
||||
close: Handle<MenuItem>,
|
||||
show_in_explorer: Handle<MenuItem>,
|
||||
placement_target: Handle<UiNode>,
|
||||
mark_as_startup: Handle<MenuItem>,
|
||||
}
|
||||
|
||||
pub enum SceneItemAction {
|
||||
None,
|
||||
Close(Uuid),
|
||||
ShowInExplorer(Uuid),
|
||||
MarkAsStartup(Uuid),
|
||||
}
|
||||
|
||||
impl SceneItemMenu {
|
||||
pub const CLOSE: Uuid = uuid!("e4c7f0eb-c9a7-4cf2-af4b-78c028be9c58");
|
||||
pub const SHOW_IN_EXPLORER: Uuid = uuid!("97a43a80-7860-4fce-b0fa-26ae6677d132");
|
||||
pub const MARK_AS_STARTUP: Uuid = uuid!("a5ef73ba-0523-44f3-99f5-93b0e47dead1");
|
||||
|
||||
pub fn new(ctx: &mut BuildContext) -> Self {
|
||||
let close = create_menu_item("Close", Self::CLOSE, vec![], ctx);
|
||||
let show_in_explorer =
|
||||
create_menu_item("Show In Explorer", Self::SHOW_IN_EXPLORER, vec![], ctx);
|
||||
let mark_as_startup =
|
||||
create_menu_item("Mark as Startup", Self::MARK_AS_STARTUP, vec![], ctx);
|
||||
let content = StackPanelBuilder::new(
|
||||
WidgetBuilder::new()
|
||||
.with_child(close)
|
||||
.with_child(show_in_explorer),
|
||||
.with_child(show_in_explorer)
|
||||
.with_child(mark_as_startup),
|
||||
)
|
||||
.build(ctx);
|
||||
let menu = ContextMenuBuilder::new(
|
||||
@@ -76,6 +80,7 @@ impl SceneItemMenu {
|
||||
menu,
|
||||
close,
|
||||
show_in_explorer,
|
||||
mark_as_startup,
|
||||
placement_target: Default::default(),
|
||||
}
|
||||
}
|
||||
@@ -91,6 +96,8 @@ impl SceneItemMenu {
|
||||
return SceneItemAction::Close(placement_target_id);
|
||||
} else if message.destination == self.show_in_explorer {
|
||||
return SceneItemAction::ShowInExplorer(placement_target_id);
|
||||
} else if message.destination == self.mark_as_startup {
|
||||
return SceneItemAction::MarkAsStartup(placement_target_id);
|
||||
}
|
||||
}
|
||||
} else if let Some(PopupMessage::Placement(Placement::Cursor(target))) =
|
||||
|
||||
@@ -716,6 +716,13 @@ impl SceneViewer {
|
||||
}
|
||||
}
|
||||
}
|
||||
SceneItemAction::MarkAsStartup(scene_id) => {
|
||||
if let Some(entry) = scenes.entry_by_scene_id(scene_id) {
|
||||
if let Some(entry_path) = entry.path.as_ref() {
|
||||
settings.general.add_startup_scene(entry_path);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(ButtonMessage::Click) = message.data::<ButtonMessage>() {
|
||||
|
||||
@@ -88,6 +88,15 @@ pub struct GeneralSettings {
|
||||
pub startup_scenes: Vec<PathBuf>,
|
||||
}
|
||||
|
||||
impl GeneralSettings {
|
||||
pub fn add_startup_scene(&mut self, path: &PathBuf) {
|
||||
if self.startup_scenes.contains(path) {
|
||||
return;
|
||||
}
|
||||
self.startup_scenes.push(path.clone());
|
||||
}
|
||||
}
|
||||
|
||||
fn default_style() -> EditorStyle {
|
||||
EditorStyle::Dark
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user