From 69f3a5229dd1bd3e20eb17c14f3fdb467fc68fe9 Mon Sep 17 00:00:00 2001 From: Relintai Date: Sat, 16 Jul 2022 21:42:46 +0200 Subject: [PATCH] Added a new plugin_refresher module. It's only a skeleton for now. Same idea as the godot-plugin-refresher addon, but done a bit differently. --- modules/plugin_refresher/SCsub | 11 ++++ modules/plugin_refresher/config.py | 16 +++++ modules/plugin_refresher/plugin_refresher.cpp | 61 +++++++++++++++++++ modules/plugin_refresher/plugin_refresher.h | 36 +++++++++++ .../plugin_refresher_editor_plugin.cpp | 58 ++++++++++++++++++ .../plugin_refresher_editor_plugin.h | 50 +++++++++++++++ modules/plugin_refresher/register_types.cpp | 36 +++++++++++ modules/plugin_refresher/register_types.h | 24 ++++++++ 8 files changed, 292 insertions(+) create mode 100644 modules/plugin_refresher/SCsub create mode 100644 modules/plugin_refresher/config.py create mode 100644 modules/plugin_refresher/plugin_refresher.cpp create mode 100644 modules/plugin_refresher/plugin_refresher.h create mode 100644 modules/plugin_refresher/plugin_refresher_editor_plugin.cpp create mode 100644 modules/plugin_refresher/plugin_refresher_editor_plugin.h create mode 100644 modules/plugin_refresher/register_types.cpp create mode 100644 modules/plugin_refresher/register_types.h diff --git a/modules/plugin_refresher/SCsub b/modules/plugin_refresher/SCsub new file mode 100644 index 000000000..fe784a07f --- /dev/null +++ b/modules/plugin_refresher/SCsub @@ -0,0 +1,11 @@ +import os + +Import('env') + +module_env = env.Clone() + +module_env.add_source_files(env.modules_sources,"register_types.cpp") + +if env["tools"]: + module_env.add_source_files(env.modules_sources,"plugin_refresher_editor_plugin.cpp") + module_env.add_source_files(env.modules_sources,"plugin_refresher.cpp") diff --git a/modules/plugin_refresher/config.py b/modules/plugin_refresher/config.py new file mode 100644 index 000000000..631a3b44c --- /dev/null +++ b/modules/plugin_refresher/config.py @@ -0,0 +1,16 @@ + + +def can_build(env, platform): + return True + + +def configure(env): + pass + + +def get_doc_classes(): + return [ + ] + +def get_doc_path(): + return "doc_classes" diff --git a/modules/plugin_refresher/plugin_refresher.cpp b/modules/plugin_refresher/plugin_refresher.cpp new file mode 100644 index 000000000..ea9fcf8ee --- /dev/null +++ b/modules/plugin_refresher/plugin_refresher.cpp @@ -0,0 +1,61 @@ + +#include "plugin_refresher.h" +#include "core/os/input_event.h" + +#include "editor/editor_settings.h" +#include "scene/gui/check_box.h" + +void PluginRefresher::set_enabled(const bool p_enabled) { + if (_enabler_check_box) { + _enabler_check_box->set_pressed(p_enabled); + } + + _set_enabled(p_enabled); +} + +void PluginRefresher::set_enabler_check_box(CheckBox *cb) { + _enabler_check_box = cb; + + if (_enabler_check_box) { + _enabler_check_box->connect("toggled", this, "_set_enabled"); + } +} + +void PluginRefresher::_set_enabled(const bool p_enabled) { + set_visible(p_enabled); + + bool sett_enabled = EditorSettings::get_singleton()->get_project_metadata("plugin_refresher", "enabled", false); + + if (sett_enabled != p_enabled) { + EditorSettings::get_singleton()->set_project_metadata("plugin_refresher", "enabled", p_enabled); + } +} + +void PluginRefresher::pressed() { + if (_button == BUTTON_LEFT) { + } else if (_button == BUTTON_RIGHT) { + } +} +void PluginRefresher::_gui_input(Ref p_event) { + Ref mouse_button = p_event; + + if (mouse_button.is_valid()) { + _button = mouse_button->get_button_index(); + } + + BaseButton::_gui_input(p_event); +} + +PluginRefresher::PluginRefresher() { + _button = 0; + set_button_mask(BUTTON_MASK_LEFT | BUTTON_MASK_RIGHT); + set_enabled_focus_mode(FOCUS_NONE); + set_tooltip("Left click: Refresh selected plugin.\nRight click: Settings."); +} + +PluginRefresher::~PluginRefresher() { +} + +void PluginRefresher::_bind_methods() { + ClassDB::bind_method(D_METHOD("_set_enabled", "enabled"), &PluginRefresher::_set_enabled); +} diff --git a/modules/plugin_refresher/plugin_refresher.h b/modules/plugin_refresher/plugin_refresher.h new file mode 100644 index 000000000..427558360 --- /dev/null +++ b/modules/plugin_refresher/plugin_refresher.h @@ -0,0 +1,36 @@ +#ifndef PLUGIN_REFRESHER_H +#define PLUGIN_REFRESHER_H + +#include "core/reference.h" +#include "core/ustring.h" +#include "core/variant.h" +#include "core/vector.h" + +#include "scene/gui/tool_button.h" + +class CheckBox; + +class PluginRefresher : public ToolButton { + GDCLASS(PluginRefresher, ToolButton); + +public: + void set_enabled(const bool p_enabled); + + void set_enabler_check_box(CheckBox *cb); + + PluginRefresher(); + ~PluginRefresher(); + +protected: + void _set_enabled(const bool p_enabled); + + void pressed(); + void _gui_input(Ref p_event); + + static void _bind_methods(); + + int _button; + CheckBox *_enabler_check_box; +}; + +#endif diff --git a/modules/plugin_refresher/plugin_refresher_editor_plugin.cpp b/modules/plugin_refresher/plugin_refresher_editor_plugin.cpp new file mode 100644 index 000000000..1d35b018c --- /dev/null +++ b/modules/plugin_refresher/plugin_refresher_editor_plugin.cpp @@ -0,0 +1,58 @@ +/* +Copyright (c) 2019-2022 Péter Magyar + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +#include "plugin_refresher_editor_plugin.h" + +#include "editor/editor_node.h" +#include "editor/editor_plugin_settings.h" +#include "editor/editor_settings.h" +#include "editor/project_settings_editor.h" +#include "plugin_refresher.h" +#include "scene/gui/check_box.h" + +String PluginRefresherEditorPlugin::get_name() const { + return "PluginRefresherEditorPlugin"; +} + +PluginRefresherEditorPlugin::PluginRefresherEditorPlugin(EditorNode *p_node) { + editor = p_node; + + _enable_check_box = memnew(CheckBox); + _enable_check_box->set_text(TTR("Show Refresher")); + + _plugin_refresher = memnew(PluginRefresher); + _plugin_refresher->set_icon(get_editor_interface()->get_base_control()->get_icon("Reload", "EditorIcons")); + + _plugin_refresher->set_enabler_check_box(_enable_check_box); + + add_control_to_container(CONTAINER_TOOLBAR, _plugin_refresher); + ProjectSettingsEditor::get_singleton()->get_plugin_settings()->add_control_to_top_bar(_enable_check_box); + + bool enabled = EditorSettings::get_singleton()->get_project_metadata("plugin_refresher", "enabled", false); + _plugin_refresher->set_enabled(enabled); +} + +PluginRefresherEditorPlugin::~PluginRefresherEditorPlugin() { +} + +void PluginRefresherEditorPlugin::_bind_methods() { +} diff --git a/modules/plugin_refresher/plugin_refresher_editor_plugin.h b/modules/plugin_refresher/plugin_refresher_editor_plugin.h new file mode 100644 index 000000000..12bb60ad3 --- /dev/null +++ b/modules/plugin_refresher/plugin_refresher_editor_plugin.h @@ -0,0 +1,50 @@ +#ifndef PLUGIN_REFRESHER_EDITOR_PLUGIN_H +#define PLUGIN_REFRESHER_EDITOR_PLUGIN_H + +/* +Copyright (c) 2019-2022 Péter Magyar + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +#include "core/reference.h" +#include "editor/editor_plugin.h" + +class CheckBox; +class PluginRefresher; + +class PluginRefresherEditorPlugin : public EditorPlugin { + GDCLASS(PluginRefresherEditorPlugin, EditorPlugin); + +public: + String get_name() const; + + PluginRefresherEditorPlugin(EditorNode *p_node); + ~PluginRefresherEditorPlugin(); + + EditorNode *editor; + +protected: + static void _bind_methods(); + + CheckBox *_enable_check_box; + PluginRefresher *_plugin_refresher; +}; + +#endif diff --git a/modules/plugin_refresher/register_types.cpp b/modules/plugin_refresher/register_types.cpp new file mode 100644 index 000000000..a9c8e5d20 --- /dev/null +++ b/modules/plugin_refresher/register_types.cpp @@ -0,0 +1,36 @@ +/* +Copyright (c) 2022 Péter Magyar + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +#include "register_types.h" + +#ifdef TOOLS_ENABLED +#include "plugin_refresher_editor_plugin.h" +#endif + +void register_plugin_refresher_types() { +#ifdef TOOLS_ENABLED + EditorPlugins::add_by_type(); +#endif +} + +void unregister_plugin_refresher_types() { +} diff --git a/modules/plugin_refresher/register_types.h b/modules/plugin_refresher/register_types.h new file mode 100644 index 000000000..c0e11da02 --- /dev/null +++ b/modules/plugin_refresher/register_types.h @@ -0,0 +1,24 @@ +/* +Copyright (c) 2022 Péter Magyar + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +void register_plugin_refresher_types(); +void unregister_plugin_refresher_types();