Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Game camera override #27742

Merged
merged 1 commit into from
Nov 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 0 additions & 27 deletions core/script_language.h
Original file line number Diff line number Diff line change
Expand Up @@ -427,31 +427,6 @@ class ScriptDebugger {
ScriptLanguage *break_lang;

public:
typedef void (*RequestSceneTreeMessageFunc)(void *);

struct LiveEditFuncs {

void *udata;
void (*node_path_func)(void *, const NodePath &p_path, int p_id);
void (*res_path_func)(void *, const String &p_path, int p_id);

void (*node_set_func)(void *, int p_id, const StringName &p_prop, const Variant &p_value);
void (*node_set_res_func)(void *, int p_id, const StringName &p_prop, const String &p_value);
void (*node_call_func)(void *, int p_id, const StringName &p_method, VARIANT_ARG_DECLARE);
void (*res_set_func)(void *, int p_id, const StringName &p_prop, const Variant &p_value);
void (*res_set_res_func)(void *, int p_id, const StringName &p_prop, const String &p_value);
void (*res_call_func)(void *, int p_id, const StringName &p_method, VARIANT_ARG_DECLARE);
void (*root_func)(void *, const NodePath &p_scene_path, const String &p_scene_from);

void (*tree_create_node_func)(void *, const NodePath &p_parent, const String &p_type, const String &p_name);
void (*tree_instance_node_func)(void *, const NodePath &p_parent, const String &p_path, const String &p_name);
void (*tree_remove_node_func)(void *, const NodePath &p_at);
void (*tree_remove_and_keep_node_func)(void *, const NodePath &p_at, ObjectID p_keep_id);
void (*tree_restore_node_func)(void *, ObjectID p_id, const NodePath &p_at, int p_at_pos);
void (*tree_duplicate_node_func)(void *, const NodePath &p_at, const String &p_new_name);
void (*tree_reparent_node_func)(void *, const NodePath &p_at, const NodePath &p_new_place, const String &p_new_name, int p_at_pos);
};

_FORCE_INLINE_ static ScriptDebugger *get_singleton() { return singleton; }
void set_lines_left(int p_left);
int get_lines_left() const;
Expand Down Expand Up @@ -480,8 +455,6 @@ class ScriptDebugger {
virtual bool is_remote() const { return false; }
virtual void request_quit() {}

virtual void set_request_scene_tree_message_func(RequestSceneTreeMessageFunc p_func, void *p_udata) {}
virtual void set_live_edit_funcs(LiveEditFuncs *p_funcs) {}
virtual void set_multiplayer(Ref<MultiplayerAPI> p_multiplayer) {}

virtual bool is_profiling() const = 0;
Expand Down
44 changes: 44 additions & 0 deletions editor/plugins/canvas_item_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3730,6 +3730,7 @@ void CanvasItemEditor::_notification(int p_what) {
grid_snap_button->set_icon(get_icon("SnapGrid", "EditorIcons"));
snap_config_menu->set_icon(get_icon("GuiTabMenu", "EditorIcons"));
skeleton_menu->set_icon(get_icon("Bone", "EditorIcons"));
override_camera_button->set_icon(get_icon("Camera2D", "EditorIcons"));
pan_button->set_icon(get_icon("ToolPan", "EditorIcons"));
ruler_button->set_icon(get_icon("Ruler", "EditorIcons"));
pivot_button->set_icon(get_icon("EditPivot", "EditorIcons"));
Expand Down Expand Up @@ -3799,6 +3800,15 @@ void CanvasItemEditor::_notification(int p_what) {

anchor_mode_button->set_icon(get_icon("Anchor", "EditorIcons"));
}

if (p_what == NOTIFICATION_VISIBILITY_CHANGED) {
if (!is_visible() && override_camera_button->is_pressed()) {
ScriptEditorDebugger *debugger = ScriptEditor::get_singleton()->get_debugger();

debugger->set_camera_override(ScriptEditorDebugger::OVERRIDE_NONE);
override_camera_button->set_pressed(false);
}
}
}

void CanvasItemEditor::_selection_changed() {
Expand Down Expand Up @@ -4140,6 +4150,15 @@ void CanvasItemEditor::_button_toggle_grid_snap(bool p_status) {
grid_snap_active = p_status;
viewport->update();
}
void CanvasItemEditor::_button_override_camera(bool p_pressed) {
ScriptEditorDebugger *debugger = ScriptEditor::get_singleton()->get_debugger();

if (p_pressed) {
debugger->set_camera_override(ScriptEditorDebugger::OVERRIDE_2D);
} else {
debugger->set_camera_override(ScriptEditorDebugger::OVERRIDE_NONE);
}
}

void CanvasItemEditor::_button_tool_select(int p_index) {

Expand Down Expand Up @@ -4237,6 +4256,17 @@ void CanvasItemEditor::_button_toggle_anchor_mode(bool p_status) {
viewport->update();
}

void CanvasItemEditor::_update_override_camera_button(bool p_game_running) {
if (p_game_running) {
override_camera_button->set_disabled(false);
override_camera_button->set_tooltip(TTR("Game camera override\nOverrides game camera with editor viewport camera."));
} else {
override_camera_button->set_disabled(true);
override_camera_button->set_pressed(false);
override_camera_button->set_tooltip(TTR("Game camera override\nNo game instance running."));
}
}

void CanvasItemEditor::_popup_callback(int p_op) {

last_option = MenuOption(p_op);
Expand Down Expand Up @@ -4829,6 +4859,8 @@ void CanvasItemEditor::_bind_methods() {
ClassDB::bind_method("_button_zoom_plus", &CanvasItemEditor::_button_zoom_plus);
ClassDB::bind_method("_button_toggle_smart_snap", &CanvasItemEditor::_button_toggle_smart_snap);
ClassDB::bind_method("_button_toggle_grid_snap", &CanvasItemEditor::_button_toggle_grid_snap);
ClassDB::bind_method(D_METHOD("_button_override_camera", "pressed"), &CanvasItemEditor::_button_override_camera);
ClassDB::bind_method(D_METHOD("_update_override_camera_button", "game_running"), &CanvasItemEditor::_update_override_camera_button);
ClassDB::bind_method("_button_toggle_anchor_mode", &CanvasItemEditor::_button_toggle_anchor_mode);
ClassDB::bind_method("_update_scroll", &CanvasItemEditor::_update_scroll);
ClassDB::bind_method("_update_scrollbars", &CanvasItemEditor::_update_scrollbars);
Expand Down Expand Up @@ -5141,6 +5173,9 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) {
editor_selection->connect("selection_changed", this, "update");
editor_selection->connect("selection_changed", this, "_selection_changed");

editor->call_deferred("connect", "play_pressed", this, "_update_override_camera_button", make_binds(true));
editor->call_deferred("connect", "stop_pressed", this, "_update_override_camera_button", make_binds(false));

hb = memnew(HBoxContainer);
add_child(hb);
hb->set_anchors_and_margins_preset(Control::PRESET_WIDE);
Expand Down Expand Up @@ -5385,6 +5420,15 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) {

hb->add_child(memnew(VSeparator));

override_camera_button = memnew(ToolButton);
hb->add_child(override_camera_button);
override_camera_button->connect("toggled", this, "_button_override_camera");
override_camera_button->set_toggle_mode(true);
override_camera_button->set_disabled(true);
_update_override_camera_button(false);

hb->add_child(memnew(VSeparator));

view_menu = memnew(MenuButton);
view_menu->set_text(TTR("View"));
hb->add_child(view_menu);
Expand Down
4 changes: 4 additions & 0 deletions editor/plugins/canvas_item_editor_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ class CanvasItemEditor : public VBoxContainer {
ToolButton *ungroup_button;

MenuButton *skeleton_menu;
ToolButton *override_camera_button;
MenuButton *view_menu;
HBoxContainer *animation_hb;
MenuButton *animation_menu;
Expand Down Expand Up @@ -533,8 +534,11 @@ class CanvasItemEditor : public VBoxContainer {
void _button_zoom_plus();
void _button_toggle_smart_snap(bool p_status);
void _button_toggle_grid_snap(bool p_status);
void _button_override_camera(bool p_pressed);
void _button_tool_select(int p_index);

void _update_override_camera_button(bool p_game_running);

HSplitContainer *palette_split;
VSplitContainer *bottom_split;

Expand Down
72 changes: 72 additions & 0 deletions editor/plugins/spatial_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {

Expand Down Expand Up @@ -3096,6 +3098,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() {
Expand Down Expand Up @@ -4369,6 +4372,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;

rxlecky marked this conversation as resolved.
Show resolved Hide resolved
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;
}
}

Expand Down Expand Up @@ -4396,6 +4412,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) {
Expand Down Expand Up @@ -5290,6 +5335,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"));
Expand All @@ -5305,6 +5351,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();
Expand Down Expand Up @@ -5339,6 +5388,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);
}
}
}

Expand Down Expand Up @@ -5483,6 +5539,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"));
Expand Down Expand Up @@ -5536,6 +5594,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);

Expand Down Expand Up @@ -5633,6 +5693,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();
Expand Down Expand Up @@ -5721,6 +5792,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]);
}
Expand Down
12 changes: 7 additions & 5 deletions editor/plugins/spatial_editor_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@ class SpatialEditor : public VBoxContainer {

TOOL_OPT_LOCAL_COORDS,
TOOL_OPT_USE_SNAP,
TOOL_OPT_OVERRIDE_CAMERA,
TOOL_OPT_MAX

};
Expand Down Expand Up @@ -559,6 +560,7 @@ class SpatialEditor : public VBoxContainer {
MENU_TOOL_LIST_SELECT,
MENU_TOOL_LOCAL_COORDS,
MENU_TOOL_USE_SNAP,
MENU_TOOL_OVERRIDE_CAMERA,
MENU_TRANSFORM_CONFIGURE_SNAP,
MENU_TRANSFORM_DIALOG,
MENU_VIEW_USE_1_VIEWPORT,
Expand All @@ -585,9 +587,6 @@ class SpatialEditor : public VBoxContainer {
PopupMenu *gizmos_menu;
MenuButton *view_menu;

ToolButton *lock_button;
ToolButton *unlock_button;

AcceptDialog *accept;

ConfirmationDialog *snap_dialog;
Expand Down Expand Up @@ -615,13 +614,16 @@ class SpatialEditor : public VBoxContainer {
void _menu_item_pressed(int p_option);
void _menu_item_toggled(bool pressed, int p_option);
void _menu_gizmo_toggled(int p_option);
void _update_camera_override_button(bool p_game_running);
void _update_camera_override_viewport(Object *p_viewport);

HBoxContainer *hbc_menu;

void _generate_selection_box();
UndoRedo *undo_redo;

void _instance_scene();
int camera_override_viewport_id;

void _init_indicators();
void _update_gizmos_menu();
void _update_gizmos_menu_theme();
Expand Down Expand Up @@ -716,7 +718,7 @@ class SpatialEditor : public VBoxContainer {
void set_can_preview(Camera *p_preview);

SpatialEditorViewport *get_editor_viewport(int p_idx) {
ERR_FAIL_INDEX_V(p_idx, 4, NULL);
ERR_FAIL_INDEX_V(p_idx, static_cast<int>(VIEWPORTS_COUNT), NULL);
return viewports[p_idx];
}

Expand Down
Loading