Skip to content

Commit

Permalink
GH-61 Add floating window mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Naros committed Jan 10, 2024
1 parent 90bea05 commit 30b6df6
Show file tree
Hide file tree
Showing 14 changed files with 766 additions and 59 deletions.
2 changes: 1 addition & 1 deletion src/editor/about_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ void OrchestratorAboutDialog::_bind_methods()

void OrchestratorAboutDialog::_notification(int p_what)
{
if (p_what == NOTIFICATION_ENTER_TREE)
if (p_what == NOTIFICATION_READY)
{
connect("theme_changed", callable_mp(this, &OrchestratorAboutDialog::_on_theme_changed));
_version_btn->connect("pressed", callable_mp(this, &OrchestratorAboutDialog::_on_version_pressed));
Expand Down
3 changes: 3 additions & 0 deletions src/editor/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "editor/graph/nodes/graph_node_comment.h"
#include "editor/graph/nodes/graph_node_default.h"
#include "editor/graph/pins/graph_node_pins.h"
#include "editor/window_wrapper.h"
#include "main_view.h"
#include "script_view.h"

Expand Down Expand Up @@ -54,6 +55,8 @@ void register_editor_classes()

// View components
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorAboutDialog)
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorScreenSelect)
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorWindowWrapper)
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorMainView)
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorScriptView)
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorScriptViewSection)
Expand Down
2 changes: 1 addition & 1 deletion src/editor/graph/actions/action_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void OrchestratorGraphActionMenu::_bind_methods()

void OrchestratorGraphActionMenu::_notification(int p_what)
{
if (p_what == NOTIFICATION_ENTER_TREE)
if (p_what == NOTIFICATION_READY)
{
set_title("All Actions");

Expand Down
15 changes: 2 additions & 13 deletions src/editor/graph/graph_edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ void OrchestratorGraphEdit::free_clipboard()

void OrchestratorGraphEdit::_notification(int p_what)
{
if (p_what == NOTIFICATION_ENTER_TREE)
if (p_what == NOTIFICATION_READY)
{
Label* label = memnew(Label);
label->set_text("Use Right Mouse Button To Add New Nodes");
Expand Down Expand Up @@ -182,19 +182,8 @@ void OrchestratorGraphEdit::_notification(int p_what)

ProjectSettings* ps = ProjectSettings::get_singleton();
ps->connect("settings_changed", callable_mp(this, &OrchestratorGraphEdit::_on_project_settings_changed));
}
else if (p_what == NOTIFICATION_POST_ENTER_TREE)
{

_synchronize_graph_with_script(_deferred_tween_node == -1);
}
else if (p_what == NOTIFICATION_EXIT_TREE)
{
_script_graph->disconnect("node_removed", callable_mp(this, &OrchestratorGraphEdit::_on_graph_node_removed));
_script_graph->disconnect("node_added", callable_mp(this, &OrchestratorGraphEdit::_on_graph_node_added));
_script->disconnect("connections_changed", callable_mp(this, &OrchestratorGraphEdit::_on_graph_connections_changed));
}
else if (p_what == NOTIFICATION_READY)
{
_focus_node(_deferred_tween_node);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/editor/graph/graph_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void OrchestratorGraphNode::_bind_methods()

void OrchestratorGraphNode::_notification(int p_what)
{
if (p_what == NOTIFICATION_ENTER_TREE)
if (p_what == NOTIFICATION_READY)
{
// Update the title bar widget layouts
HBoxContainer* titlebar = get_titlebar_hbox();
Expand Down
2 changes: 1 addition & 1 deletion src/editor/graph/graph_node_pin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ String OrchestratorGraphNodePin::_get_color_name() const

void OrchestratorGraphNodePin::_notification(int p_what)
{
if (p_what == NOTIFICATION_ENTER_TREE)
if (p_what == NOTIFICATION_READY)
{
_create_widgets();

Expand Down
57 changes: 43 additions & 14 deletions src/editor/main_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "common/version.h"
#include "editor/about_dialog.h"
#include "editor/graph/graph_edit.h"
#include "editor/window_wrapper.h"
#include "plugin/plugin.h"
#include "plugin/settings.h"
#include "script/language.h"
Expand Down Expand Up @@ -52,22 +53,15 @@

#define SKEY(m,k) Key(static_cast<int>(m) | static_cast<int>(k))

OrchestratorMainView::OrchestratorMainView(OrchestratorPlugin* p_plugin)
OrchestratorMainView::OrchestratorMainView(OrchestratorPlugin* p_plugin, OrchestratorWindowWrapper* p_window_wrapper)
{
_plugin = p_plugin;
_wrapper = p_window_wrapper;
}

void OrchestratorMainView::_notification(int p_what)
{
if (p_what == NOTIFICATION_ENTER_TREE)
{
OrchestratorGraphEdit::initialize_clipboard();
}
else if (p_what == NOTIFICATION_EXIT_TREE)
{
OrchestratorGraphEdit::free_clipboard();
}
else if (p_what == NOTIFICATION_READY)
if (p_what == NOTIFICATION_READY)
{
set_anchors_preset(PRESET_FULL_RECT);
set_h_size_flags(SIZE_EXPAND_FILL);
Expand Down Expand Up @@ -172,6 +166,21 @@ void OrchestratorMainView::_notification(int p_what)
version->set_vertical_alignment(VERTICAL_ALIGNMENT_CENTER);
right_menu_container->add_child(version);

if (_wrapper->is_window_available())
{
vs = memnew(VSeparator);
vs->set_v_size_flags(SIZE_SHRINK_CENTER);
vs->set_custom_minimum_size(Vector2i(0, 24));
right_menu_container->add_child(vs);

_select = memnew(OrchestratorScreenSelect);
_select->set_flat(true);
_select->set_tooltip_text("Make the Orchestration editor floating.");
_select->connect("request_open_in_screen", callable_mp(_wrapper, &OrchestratorWindowWrapper::enable_window_on_screen).bind(true));
right_menu_container->add_child(_select);
_wrapper->connect("window_visibility_changed", callable_mp(this, &OrchestratorMainView::_on_window_changed));
}

_update_container = memnew(HBoxContainer);
_update_container->set_visible(false);

Expand Down Expand Up @@ -228,7 +237,7 @@ void OrchestratorMainView::_notification(int p_what)

_open_dialog = memnew(FileDialog);
_open_dialog->set_min_size(Vector2(700, 400));
_open_dialog->set_initial_position(Window::WINDOW_INITIAL_POSITION_CENTER_MAIN_WINDOW_SCREEN);
_open_dialog->set_initial_position(Window::WINDOW_INITIAL_POSITION_CENTER_SCREEN_WITH_KEYBOARD_FOCUS);
_open_dialog->set_title("Open Orchestration Script");
_open_dialog->set_file_mode(FileDialog::FILE_MODE_OPEN_FILE);
_open_dialog->add_filter("*.os", "Orchestrator Scripts");
Expand All @@ -237,7 +246,7 @@ void OrchestratorMainView::_notification(int p_what)

_save_dialog = memnew(FileDialog);
_save_dialog->set_min_size(Vector2(700, 400));
_save_dialog->set_initial_position(Window::WINDOW_INITIAL_POSITION_CENTER_MAIN_WINDOW_SCREEN);
_save_dialog->set_initial_position(Window::WINDOW_INITIAL_POSITION_CENTER_SCREEN_WITH_KEYBOARD_FOCUS);
_save_dialog->set_title("Save As Orchestration Script");
_save_dialog->set_file_mode(FileDialog::FILE_MODE_SAVE_FILE);
_save_dialog->add_filter("*.os", "Orchestrator Scripts");
Expand All @@ -253,7 +262,6 @@ void OrchestratorMainView::_notification(int p_what)
add_child(_close_confirm);

_goto_dialog = memnew(ConfirmationDialog);
_goto_dialog->set_initial_position(Window::WINDOW_INITIAL_POSITION_CENTER_MAIN_WINDOW_SCREEN);
_goto_dialog->set_title("Go to Node");

VBoxContainer* container = memnew(VBoxContainer);
Expand Down Expand Up @@ -300,6 +308,14 @@ void OrchestratorMainView::apply_changes()
file.editor->apply_changes();
}

void OrchestratorMainView::get_window_layout(const Ref<ConfigFile>& p_configuration)
{
}

void OrchestratorMainView::set_window_layout(const Ref<ConfigFile>& p_configuration)
{
}

bool OrchestratorMainView::build()
{
for (const ScriptFile& file : _script_files)
Expand Down Expand Up @@ -476,6 +492,10 @@ void OrchestratorMainView::_show_create_new_script_dialog()

ScriptCreateDialog* dialog = _plugin->get_script_create_dialog();

// Cache existing position and change it for our pop-out
const Window::WindowInitialPosition initial_position = dialog->get_initial_position();
dialog->set_initial_position(Window::WINDOW_INITIAL_POSITION_CENTER_SCREEN_WITH_KEYBOARD_FOCUS);

// Finds the LanguageMenu option button and forces the Orchestrator choice
// This must be done before calling "config" to make sure that all the dialog logic for templates
// and the language choice align properly.
Expand Down Expand Up @@ -505,6 +525,9 @@ void OrchestratorMainView::_show_create_new_script_dialog()
dialog->connect("script_created", callable_mp(this, &OrchestratorMainView::_on_script_file_created));

dialog->popup_centered();

// Restore old position
dialog->set_initial_position(initial_position);
}

void OrchestratorMainView::_update_files_list()
Expand Down Expand Up @@ -626,7 +649,7 @@ void OrchestratorMainView::_on_menu_option(int p_option)
break;
case GOTO_NODE:
{
_goto_dialog->show();
_goto_dialog->popup_centered();
break;
}
default:
Expand Down Expand Up @@ -725,6 +748,12 @@ void OrchestratorMainView::_on_goto_node_closed(LineEdit* p_edit)
p_edit->set_text("");
}

void OrchestratorMainView::_on_window_changed(bool p_visible)
{
_select->set_visible(!p_visible);
_floating = p_visible;
}

void OrchestratorMainView::_on_request_completed(int p_result, int p_code, const PackedStringArray& p_headers,
const PackedByteArray& p_data)
{
Expand Down
21 changes: 20 additions & 1 deletion src/editor/main_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#ifndef ORCHESTRATOR_MAIN_VIEW_H
#define ORCHESTRATOR_MAIN_VIEW_H

#include <godot_cpp/classes/config_file.hpp>
#include <godot_cpp/classes/control.hpp>
#include <godot_cpp/templates/hash_map.hpp>
#include <godot_cpp/templates/vector.hpp>
Expand All @@ -26,7 +27,9 @@ using namespace godot;
/// Forward declarations
class OrchestratorPlugin;
class OScript;
class OrchestratorScreenSelect;
class OrchestratorScriptView;
class OrchestratorWindowWrapper;

namespace godot
{
Expand Down Expand Up @@ -92,14 +95,18 @@ class OrchestratorMainView : public Control
OrchestratorPlugin* _plugin{ nullptr }; //! Orchestrator plugin
Timer* _update_timer{ nullptr }; //! Update timer
HTTPRequest* _http_request{ nullptr }; //! HTTP request
bool _floating{ false }; //! Whether this window is floating
OrchestratorScreenSelect* _select{ nullptr }; //! Screen selection
OrchestratorWindowWrapper* _wrapper{ nullptr }; //! Window wrapper

static void _bind_methods() { }
OrchestratorMainView() = default;

public:
/// Creates the main view
/// @param p_plugin the plugin instance
OrchestratorMainView(OrchestratorPlugin* p_plugin);
/// @param p_window_wrapper the window wrapper
OrchestratorMainView(OrchestratorPlugin* p_plugin, OrchestratorWindowWrapper* p_window_wrapper);

/// Godot callback that handles notifications
/// @param p_what the notification to be handled
Expand All @@ -112,6 +119,14 @@ class OrchestratorMainView : public Control
/// Saves all open files
void apply_changes();

/// Get the window's layout to be serialized to disk when the editor is restored
/// @param p_configuration the configuration
void get_window_layout(const Ref<ConfigFile>& p_configuration);

/// Set the window's layout, restoring the previous editor state
/// @param p_configuration the configuration
void set_window_layout(const Ref<ConfigFile>& p_configuration);

/// Performs the build step
/// @return true if the build was successful; false otherwise
bool build();
Expand Down Expand Up @@ -214,6 +229,10 @@ class OrchestratorMainView : public Control
/// @param p_edit the line edit control, should never be null
void _on_goto_node_visibility_changed(LineEdit* p_edit);

/// Dispatched when the window's floating status changes
/// @param p_visible the current visibility status
void _on_window_changed(bool p_visible);

void _on_request_completed(int p_result, int p_code, const PackedStringArray& p_headers, const PackedByteArray& p_data);
};

Expand Down
Loading

0 comments on commit 30b6df6

Please sign in to comment.