mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2024-12-24 20:57:18 +01:00
Now menu items can be added to the convert menu in the editor.
This commit is contained in:
parent
d8f00dc1b4
commit
48d50bed1d
@ -2892,6 +2892,27 @@ void EditorNode::_tool_menu_option(int p_idx) {
|
||||
}
|
||||
}
|
||||
|
||||
void EditorNode::_convert_button_menu_option(int p_idx) {
|
||||
switch (convert_menu->get_item_id(p_idx)) {
|
||||
case FILE_CONVERT_CUSTOM: {
|
||||
if (convert_menu->get_item_submenu(p_idx) == "") {
|
||||
Array params = convert_menu->get_item_metadata(p_idx);
|
||||
|
||||
Object *handler = ObjectDB::get_instance(params[0]);
|
||||
String callback = params[1];
|
||||
Variant *ud = ¶ms[2];
|
||||
Variant::CallError ce;
|
||||
|
||||
handler->call(callback, (const Variant **)&ud, 1, ce);
|
||||
if (ce.error != Variant::CallError::CALL_OK) {
|
||||
String err = Variant::get_call_error_text(handler, callback, (const Variant **)&ud, 1, ce);
|
||||
ERR_PRINT("Error calling function from convert menu: " + err);
|
||||
}
|
||||
} // else it's a submenu so don't do anything.
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
int EditorNode::_next_unsaved_scene(bool p_valid_filename, int p_start) {
|
||||
for (int i = p_start; i < editor_data.get_edited_scene_count(); i++) {
|
||||
if (!editor_data.get_edited_scene_root(i)) {
|
||||
@ -5307,6 +5328,46 @@ void EditorNode::remove_tool_menu_item(const String &p_name) {
|
||||
}
|
||||
}
|
||||
|
||||
void EditorNode::add_convert_menu_item(const String &p_name, Object *p_handler, const String &p_callback, const Variant &p_ud) {
|
||||
ERR_FAIL_NULL(p_handler);
|
||||
int idx = convert_menu->get_item_count();
|
||||
convert_menu->add_item(p_name, FILE_CONVERT_CUSTOM);
|
||||
|
||||
Array parameters;
|
||||
parameters.push_back(p_handler->get_instance_id());
|
||||
parameters.push_back(p_callback);
|
||||
parameters.push_back(p_ud);
|
||||
|
||||
convert_menu->set_item_metadata(idx, parameters);
|
||||
}
|
||||
|
||||
void EditorNode::add_convert_submenu_item(const String &p_name, PopupMenu *p_submenu) {
|
||||
ERR_FAIL_NULL(p_submenu);
|
||||
ERR_FAIL_COND(p_submenu->get_parent() != nullptr);
|
||||
|
||||
convert_menu->add_child(p_submenu);
|
||||
convert_menu->add_submenu_item(p_name, p_submenu->get_name(), FILE_CONVERT_CUSTOM);
|
||||
}
|
||||
|
||||
void EditorNode::remove_convert_menu_item(const String &p_name) {
|
||||
for (int i = 0; i < convert_menu->get_item_count(); i++) {
|
||||
if (convert_menu->get_item_id(i) != FILE_CONVERT_CUSTOM) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (convert_menu->get_item_text(i) == p_name) {
|
||||
if (convert_menu->get_item_submenu(i) != "") {
|
||||
Node *n = convert_menu->get_node(convert_menu->get_item_submenu(i));
|
||||
convert_menu->remove_child(n);
|
||||
memdelete(n);
|
||||
}
|
||||
convert_menu->remove_item(i);
|
||||
convert_menu->set_as_minsize();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EditorNode::_global_menu_action(const Variant &p_id, const Variant &p_meta) {
|
||||
int id = (int)p_id;
|
||||
if (id == GLOBAL_NEW_WINDOW) {
|
||||
@ -5564,6 +5625,7 @@ void EditorNode::_project_settings_changed() {
|
||||
void EditorNode::_bind_methods() {
|
||||
ClassDB::bind_method("_menu_option", &EditorNode::_menu_option);
|
||||
ClassDB::bind_method("_tool_menu_option", &EditorNode::_tool_menu_option);
|
||||
ClassDB::bind_method("_convert_button_menu_option", &EditorNode::_convert_button_menu_option);
|
||||
ClassDB::bind_method("_menu_confirm_current", &EditorNode::_menu_confirm_current);
|
||||
ClassDB::bind_method("_dialog_action", &EditorNode::_dialog_action);
|
||||
ClassDB::bind_method("_editor_select", &EditorNode::_editor_select);
|
||||
@ -6263,11 +6325,11 @@ EditorNode::EditorNode() {
|
||||
p->add_shortcut(ED_SHORTCUT("editor/quick_open_script", TTR("Quick Open Script..."), KEY_MASK_ALT + KEY_MASK_CMD + KEY_O), FILE_QUICK_OPEN_SCRIPT);
|
||||
|
||||
p->add_separator();
|
||||
PopupMenu *pm_export = memnew(PopupMenu);
|
||||
pm_export->set_name("Export");
|
||||
p->add_child(pm_export);
|
||||
convert_menu = memnew(PopupMenu);
|
||||
convert_menu->set_name("Export");
|
||||
p->add_child(convert_menu);
|
||||
p->add_submenu_item(TTR("Convert To..."), "Export");
|
||||
pm_export->connect("id_pressed", this, "_menu_option");
|
||||
convert_menu->connect("index_pressed", this, "_convert_button_menu_option");
|
||||
|
||||
p->add_separator();
|
||||
p->add_shortcut(ED_SHORTCUT("editor/undo", TTR("Undo"), KEY_MASK_CMD + KEY_Z), EDIT_UNDO, true);
|
||||
|
@ -342,6 +342,10 @@ public:
|
||||
void add_tool_submenu_item(const String &p_name, PopupMenu *p_submenu);
|
||||
void remove_tool_menu_item(const String &p_name);
|
||||
|
||||
void add_convert_menu_item(const String &p_name, Object *p_handler, const String &p_callback, const Variant &p_ud = Variant());
|
||||
void add_convert_submenu_item(const String &p_name, PopupMenu *p_submenu);
|
||||
void remove_convert_menu_item(const String &p_name);
|
||||
|
||||
void save_all_scenes();
|
||||
void save_scene_list(Vector<String> p_scene_filenames);
|
||||
void restart_editor();
|
||||
@ -419,6 +423,7 @@ private:
|
||||
FILE_CLOSE_ALL_AND_RELOAD_CURRENT_PROJECT,
|
||||
FILE_QUIT,
|
||||
FILE_EXTERNAL_OPEN_SCENE,
|
||||
FILE_CONVERT_CUSTOM,
|
||||
EDIT_UNDO,
|
||||
EDIT_REDO,
|
||||
EDIT_RELOAD_SAVED_SCENE,
|
||||
@ -541,6 +546,7 @@ private:
|
||||
HBoxContainer *menu_hb;
|
||||
Control *viewport;
|
||||
MenuButton *file_menu;
|
||||
PopupMenu *convert_menu;
|
||||
MenuButton *project_menu;
|
||||
MenuButton *debug_menu;
|
||||
MenuButton *settings_menu;
|
||||
@ -752,6 +758,7 @@ private:
|
||||
void _save_screenshot(NodePath p_path);
|
||||
|
||||
void _tool_menu_option(int p_idx);
|
||||
void _convert_button_menu_option(int p_idx);
|
||||
void _update_debug_options();
|
||||
void _update_file_menu_opened();
|
||||
void _update_file_menu_closed();
|
||||
|
@ -555,6 +555,21 @@ void EditorPlugin::remove_tool_menu_item(const String &p_name) {
|
||||
EditorNode::get_singleton()->remove_tool_menu_item(p_name);
|
||||
}
|
||||
|
||||
void EditorPlugin::add_convert_menu_item(const String &p_name, Object *p_handler, const String &p_callback, const Variant &p_ud) {
|
||||
EditorNode::get_singleton()->add_convert_menu_item(p_name, p_handler, p_callback, p_ud);
|
||||
}
|
||||
|
||||
void EditorPlugin::add_convert_submenu_item(const String &p_name, Object *p_submenu) {
|
||||
ERR_FAIL_NULL(p_submenu);
|
||||
PopupMenu *submenu = Object::cast_to<PopupMenu>(p_submenu);
|
||||
ERR_FAIL_NULL(submenu);
|
||||
EditorNode::get_singleton()->add_convert_submenu_item(p_name, submenu);
|
||||
}
|
||||
|
||||
void EditorPlugin::remove_convert_menu_item(const String &p_name) {
|
||||
EditorNode::get_singleton()->remove_convert_menu_item(p_name);
|
||||
}
|
||||
|
||||
void EditorPlugin::set_input_event_forwarding_always_enabled() {
|
||||
input_event_forwarding_always_enabled = true;
|
||||
EditorPluginList *always_input_forwarding_list = EditorNode::get_singleton()->get_editor_plugins_force_input_forwarding();
|
||||
@ -863,12 +878,19 @@ void EditorPlugin::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("add_control_to_container", "container", "control"), &EditorPlugin::add_control_to_container);
|
||||
ClassDB::bind_method(D_METHOD("add_control_to_bottom_panel", "control", "title"), &EditorPlugin::add_control_to_bottom_panel);
|
||||
ClassDB::bind_method(D_METHOD("add_control_to_dock", "slot", "control"), &EditorPlugin::add_control_to_dock);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("remove_control_from_docks", "control"), &EditorPlugin::remove_control_from_docks);
|
||||
ClassDB::bind_method(D_METHOD("remove_control_from_bottom_panel", "control"), &EditorPlugin::remove_control_from_bottom_panel);
|
||||
ClassDB::bind_method(D_METHOD("remove_control_from_container", "container", "control"), &EditorPlugin::remove_control_from_container);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("add_tool_menu_item", "name", "handler", "callback", "ud"), &EditorPlugin::add_tool_menu_item, DEFVAL(Variant()));
|
||||
ClassDB::bind_method(D_METHOD("add_tool_submenu_item", "name", "submenu"), &EditorPlugin::add_tool_submenu_item);
|
||||
ClassDB::bind_method(D_METHOD("remove_tool_menu_item", "name"), &EditorPlugin::remove_tool_menu_item);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("add_convert_menu_item", "name", "handler", "callback", "ud"), &EditorPlugin::add_convert_menu_item, DEFVAL(Variant()));
|
||||
ClassDB::bind_method(D_METHOD("add_convert_submenu_item", "name", "submenu"), &EditorPlugin::add_convert_submenu_item);
|
||||
ClassDB::bind_method(D_METHOD("remove_convert_menu_item", "name"), &EditorPlugin::remove_convert_menu_item);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("add_custom_type", "type", "base", "script", "icon"), &EditorPlugin::add_custom_type);
|
||||
ClassDB::bind_method(D_METHOD("remove_custom_type", "type"), &EditorPlugin::remove_custom_type);
|
||||
|
||||
|
@ -211,6 +211,10 @@ public:
|
||||
void add_tool_submenu_item(const String &p_name, Object *p_submenu);
|
||||
void remove_tool_menu_item(const String &p_name);
|
||||
|
||||
void add_convert_menu_item(const String &p_name, Object *p_handler, const String &p_callback, const Variant &p_ud = Variant());
|
||||
void add_convert_submenu_item(const String &p_name, Object *p_submenu);
|
||||
void remove_convert_menu_item(const String &p_name);
|
||||
|
||||
void set_input_event_forwarding_always_enabled();
|
||||
bool is_input_event_forwarding_always_enabled() { return input_event_forwarding_always_enabled; }
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user