You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-06 12:20:30 +00:00
Merge pull request #27742 from rxlecky/camera-replication
Game camera override
This commit is contained in:
@@ -901,6 +901,8 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
|
||||
Ref<InputEventMouseButton> b = p_event;
|
||||
|
||||
if (b.is_valid()) {
|
||||
emit_signal("clicked", this);
|
||||
|
||||
float zoom_factor = 1 + (ZOOM_MULTIPLIER - 1) * b->get_factor();
|
||||
switch (b->get_button_index()) {
|
||||
|
||||
@@ -3101,6 +3103,7 @@ void SpatialEditorViewport::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("drop_data_fw"), &SpatialEditorViewport::drop_data_fw);
|
||||
|
||||
ADD_SIGNAL(MethodInfo("toggle_maximize_view", PropertyInfo(Variant::OBJECT, "viewport")));
|
||||
ADD_SIGNAL(MethodInfo("clicked", PropertyInfo(Variant::OBJECT, "viewport")));
|
||||
}
|
||||
|
||||
void SpatialEditorViewport::reset() {
|
||||
@@ -4373,6 +4376,19 @@ void SpatialEditor::_menu_item_toggled(bool pressed, int p_option) {
|
||||
tool_option_button[TOOL_OPT_USE_SNAP]->set_pressed(pressed);
|
||||
snap_enabled = pressed;
|
||||
} break;
|
||||
|
||||
case MENU_TOOL_OVERRIDE_CAMERA: {
|
||||
ScriptEditorDebugger *const debugger = ScriptEditor::get_singleton()->get_debugger();
|
||||
|
||||
if (pressed) {
|
||||
using Override = ScriptEditorDebugger::CameraOverride;
|
||||
|
||||
debugger->set_camera_override((Override)(Override::OVERRIDE_3D_1 + camera_override_viewport_id));
|
||||
} else {
|
||||
debugger->set_camera_override(ScriptEditorDebugger::OVERRIDE_NONE);
|
||||
}
|
||||
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4400,6 +4416,35 @@ void SpatialEditor::_menu_gizmo_toggled(int p_option) {
|
||||
update_all_gizmos();
|
||||
}
|
||||
|
||||
void SpatialEditor::_update_camera_override_button(bool p_game_running) {
|
||||
Button *const button = tool_option_button[TOOL_OPT_OVERRIDE_CAMERA];
|
||||
|
||||
if (p_game_running) {
|
||||
button->set_disabled(false);
|
||||
button->set_tooltip(TTR("Game camera override\nNo game instance running."));
|
||||
} else {
|
||||
button->set_disabled(true);
|
||||
button->set_pressed(false);
|
||||
button->set_tooltip(TTR("Game camera override\nOverrides game camera with editor viewport camera."));
|
||||
}
|
||||
}
|
||||
|
||||
void SpatialEditor::_update_camera_override_viewport(Object *p_viewport) {
|
||||
SpatialEditorViewport *current_viewport = Object::cast_to<SpatialEditorViewport>(p_viewport);
|
||||
|
||||
if (!current_viewport)
|
||||
return;
|
||||
|
||||
ScriptEditorDebugger *const debugger = ScriptEditor::get_singleton()->get_debugger();
|
||||
|
||||
camera_override_viewport_id = current_viewport->index;
|
||||
if (debugger->get_camera_override() >= ScriptEditorDebugger::OVERRIDE_3D_1) {
|
||||
using Override = ScriptEditorDebugger::CameraOverride;
|
||||
|
||||
debugger->set_camera_override((Override)(Override::OVERRIDE_3D_1 + camera_override_viewport_id));
|
||||
}
|
||||
}
|
||||
|
||||
void SpatialEditor::_menu_item_pressed(int p_option) {
|
||||
|
||||
switch (p_option) {
|
||||
@@ -5294,6 +5339,7 @@ void SpatialEditor::_notification(int p_what) {
|
||||
|
||||
tool_option_button[SpatialEditor::TOOL_OPT_LOCAL_COORDS]->set_icon(get_icon("Object", "EditorIcons"));
|
||||
tool_option_button[SpatialEditor::TOOL_OPT_USE_SNAP]->set_icon(get_icon("Snap", "EditorIcons"));
|
||||
tool_option_button[SpatialEditor::TOOL_OPT_OVERRIDE_CAMERA]->set_icon(get_icon("Camera", "EditorIcons"));
|
||||
|
||||
view_menu->get_popup()->set_item_icon(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT), get_icon("Panels1", "EditorIcons"));
|
||||
view_menu->get_popup()->set_item_icon(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS), get_icon("Panels2", "EditorIcons"));
|
||||
@@ -5309,6 +5355,9 @@ void SpatialEditor::_notification(int p_what) {
|
||||
get_tree()->connect("node_removed", this, "_node_removed");
|
||||
EditorNode::get_singleton()->get_scene_tree_dock()->get_tree_editor()->connect("node_changed", this, "_refresh_menu_icons");
|
||||
editor_selection->connect("selection_changed", this, "_refresh_menu_icons");
|
||||
|
||||
editor->connect("stop_pressed", this, "_update_camera_override_button", make_binds(false));
|
||||
editor->connect("play_pressed", this, "_update_camera_override_button", make_binds(true));
|
||||
} else if (p_what == NOTIFICATION_ENTER_TREE) {
|
||||
|
||||
_register_all_gizmos();
|
||||
@@ -5343,6 +5392,13 @@ void SpatialEditor::_notification(int p_what) {
|
||||
// Update grid color by rebuilding grid.
|
||||
_finish_grid();
|
||||
_init_grid();
|
||||
} else if (p_what == NOTIFICATION_VISIBILITY_CHANGED) {
|
||||
if (!is_visible() && tool_option_button[TOOL_OPT_OVERRIDE_CAMERA]->is_pressed()) {
|
||||
ScriptEditorDebugger *debugger = ScriptEditor::get_singleton()->get_debugger();
|
||||
|
||||
debugger->set_camera_override(ScriptEditorDebugger::OVERRIDE_NONE);
|
||||
tool_option_button[TOOL_OPT_OVERRIDE_CAMERA]->set_pressed(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5487,6 +5543,8 @@ void SpatialEditor::_bind_methods() {
|
||||
ClassDB::bind_method("_request_gizmo", &SpatialEditor::_request_gizmo);
|
||||
ClassDB::bind_method("_toggle_maximize_view", &SpatialEditor::_toggle_maximize_view);
|
||||
ClassDB::bind_method("_refresh_menu_icons", &SpatialEditor::_refresh_menu_icons);
|
||||
ClassDB::bind_method("_update_camera_override_button", &SpatialEditor::_update_camera_override_button);
|
||||
ClassDB::bind_method("_update_camera_override_viewport", &SpatialEditor::_update_camera_override_viewport);
|
||||
|
||||
ADD_SIGNAL(MethodInfo("transform_key_request"));
|
||||
ADD_SIGNAL(MethodInfo("item_lock_status_changed"));
|
||||
@@ -5540,6 +5598,8 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) {
|
||||
snap_key_enabled = false;
|
||||
tool_mode = TOOL_MODE_SELECT;
|
||||
|
||||
camera_override_viewport_id = 0;
|
||||
|
||||
hbc_menu = memnew(HBoxContainer);
|
||||
vbc->add_child(hbc_menu);
|
||||
|
||||
@@ -5637,6 +5697,17 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) {
|
||||
|
||||
hbc_menu->add_child(memnew(VSeparator));
|
||||
|
||||
tool_option_button[TOOL_OPT_OVERRIDE_CAMERA] = memnew(ToolButton);
|
||||
hbc_menu->add_child(tool_option_button[TOOL_OPT_OVERRIDE_CAMERA]);
|
||||
tool_option_button[TOOL_OPT_OVERRIDE_CAMERA]->set_toggle_mode(true);
|
||||
tool_option_button[TOOL_OPT_OVERRIDE_CAMERA]->set_flat(true);
|
||||
tool_option_button[TOOL_OPT_OVERRIDE_CAMERA]->set_disabled(true);
|
||||
button_binds.write[0] = MENU_TOOL_OVERRIDE_CAMERA;
|
||||
tool_option_button[TOOL_OPT_OVERRIDE_CAMERA]->connect("toggled", this, "_menu_item_toggled", button_binds);
|
||||
_update_camera_override_button(false);
|
||||
|
||||
hbc_menu->add_child(memnew(VSeparator));
|
||||
|
||||
// Drag and drop support;
|
||||
preview_node = memnew(Spatial);
|
||||
preview_bounds = AABB();
|
||||
@@ -5725,6 +5796,7 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) {
|
||||
|
||||
viewports[i] = memnew(SpatialEditorViewport(this, editor, i));
|
||||
viewports[i]->connect("toggle_maximize_view", this, "_toggle_maximize_view");
|
||||
viewports[i]->connect("clicked", this, "_update_camera_override_viewport");
|
||||
viewports[i]->assign_pending_data_pointers(preview_node, &preview_bounds, accept);
|
||||
viewport_base->add_child(viewports[i]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user