Skip to content

Commit

Permalink
Merge pull request #81582 from YuriSizov/graph-toolbarniceness
Browse files Browse the repository at this point in the history
Make `GraphEdit` toolbar more customizable
  • Loading branch information
akien-mga committed Oct 2, 2023
2 parents 2d6cee4 + b07c664 commit 57a6813
Show file tree
Hide file tree
Showing 14 changed files with 284 additions and 88 deletions.
22 changes: 18 additions & 4 deletions doc/classes/GraphEdit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,6 @@
</method>
</methods>
<members>
<member name="arrange_nodes_button_hidden" type="bool" setter="set_arrange_nodes_button_hidden" getter="is_arrange_nodes_button_hidden" default="false">
If [code]true[/code], the Arrange Nodes button is hidden.
</member>
<member name="clip_contents" type="bool" setter="set_clip_contents" getter="is_clipping_contents" overrides="Control" default="true" />
<member name="connection_lines_antialiased" type="bool" setter="set_connection_lines_antialiased" getter="is_connection_lines_antialiased" default="true">
If [code]true[/code], the lines between nodes will use antialiasing.
Expand Down Expand Up @@ -258,11 +255,26 @@
<member name="scroll_offset" type="Vector2" setter="set_scroll_offset" getter="get_scroll_offset" default="Vector2(0, 0)">
The scroll offset.
</member>
<member name="show_arrange_button" type="bool" setter="set_show_arrange_button" getter="is_showing_arrange_button" default="true">
If [code]true[/code], the button to automatically arrange graph nodes is visible.
</member>
<member name="show_grid" type="bool" setter="set_show_grid" getter="is_showing_grid" default="true">
If [code]true[/code], the grid is visible.
</member>
<member name="show_grid_buttons" type="bool" setter="set_show_grid_buttons" getter="is_showing_grid_buttons" default="true">
If [code]true[/code], buttons that allow to configure grid and snapping options are visible.
</member>
<member name="show_menu" type="bool" setter="set_show_menu" getter="is_showing_menu" default="true">
If [code]true[/code], the menu toolbar is visible.
</member>
<member name="show_minimap_button" type="bool" setter="set_show_minimap_button" getter="is_showing_minimap_button" default="true">
If [code]true[/code], the button to toggle the minimap is visible.
</member>
<member name="show_zoom_buttons" type="bool" setter="set_show_zoom_buttons" getter="is_showing_zoom_buttons" default="true">
If [code]true[/code], buttons that allow to change and reset the zoom level are visible.
</member>
<member name="show_zoom_label" type="bool" setter="set_show_zoom_label" getter="is_showing_zoom_label" default="false">
If [code]true[/code], makes a label with the current zoom level visible. The zoom value is displayed in percents.
If [code]true[/code], the label with the current zoom level is visible. The zoom level is displayed in percents.
</member>
<member name="snapping_distance" type="int" setter="set_snapping_distance" getter="get_snapping_distance" default="20">
The snapping distance in pixels, also determines the grid line distance.
Expand Down Expand Up @@ -436,6 +448,8 @@
<theme_item name="zoom_reset" data_type="icon" type="Texture2D">
The icon for the zoom reset button.
</theme_item>
<theme_item name="menu_panel" data_type="style" type="StyleBox">
</theme_item>
<theme_item name="panel" data_type="style" type="StyleBox">
The background drawn under the grid.
</theme_item>
Expand Down
3 changes: 3 additions & 0 deletions editor/editor_themes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1960,6 +1960,9 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) {

// GraphEdit
theme->set_stylebox("panel", "GraphEdit", style_tree_bg);
Ref<StyleBoxFlat> graph_toolbar_style = make_flat_stylebox(dark_color_1 * Color(1, 1, 1, 0.6), 4, 2, 4, 2, 3);
theme->set_stylebox("menu_panel", "GraphEdit", graph_toolbar_style);

if (dark_theme) {
theme->set_color("grid_major", "GraphEdit", Color(1.0, 1.0, 1.0, 0.1));
theme->set_color("grid_minor", "GraphEdit", Color(1.0, 1.0, 1.0, 0.05));
Expand Down
4 changes: 4 additions & 0 deletions editor/plugins/animation_blend_space_1d_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,13 @@
#include "editor/editor_undo_redo_manager.h"
#include "editor/gui/editor_file_dialog.h"
#include "scene/animation/animation_blend_tree.h"
#include "scene/gui/button.h"
#include "scene/gui/check_box.h"
#include "scene/gui/line_edit.h"
#include "scene/gui/option_button.h"
#include "scene/gui/panel_container.h"
#include "scene/gui/separator.h"
#include "scene/gui/spin_box.h"

StringName AnimationNodeBlendSpace1DEditor::get_blend_position_path() const {
StringName path = AnimationTreeEditor::get_singleton()->get_base_path() + "blend_position";
Expand Down
7 changes: 4 additions & 3 deletions editor/plugins/animation_blend_space_1d_editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,16 @@
#include "editor/editor_plugin.h"
#include "editor/plugins/animation_tree_editor_plugin.h"
#include "scene/animation/animation_blend_space_1d.h"
#include "scene/gui/button.h"
#include "scene/gui/graph_edit.h"
#include "scene/gui/popup.h"
#include "scene/gui/separator.h"
#include "scene/gui/tree.h"

class Button;
class CheckBox;
class LineEdit;
class OptionButton;
class PanelContainer;
class SpinBox;
class VSeparator;

class AnimationNodeBlendSpace1DEditor : public AnimationTreeNodeEditorPlugin {
GDCLASS(AnimationNodeBlendSpace1DEditor, AnimationTreeNodeEditorPlugin);
Expand Down
4 changes: 4 additions & 0 deletions editor/plugins/animation_blend_space_2d_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,16 @@
#include "editor/gui/editor_file_dialog.h"
#include "scene/animation/animation_blend_tree.h"
#include "scene/animation/animation_player.h"
#include "scene/gui/button.h"
#include "scene/gui/check_box.h"
#include "scene/gui/grid_container.h"
#include "scene/gui/line_edit.h"
#include "scene/gui/menu_button.h"
#include "scene/gui/option_button.h"
#include "scene/gui/panel.h"
#include "scene/gui/panel_container.h"
#include "scene/gui/separator.h"
#include "scene/gui/spin_box.h"
#include "scene/main/window.h"

bool AnimationNodeBlendSpace2DEditor::can_edit(const Ref<AnimationNode> &p_node) {
Expand Down
7 changes: 4 additions & 3 deletions editor/plugins/animation_blend_space_2d_editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,16 @@
#include "editor/editor_plugin.h"
#include "editor/plugins/animation_tree_editor_plugin.h"
#include "scene/animation/animation_blend_space_2d.h"
#include "scene/gui/button.h"
#include "scene/gui/graph_edit.h"
#include "scene/gui/popup.h"
#include "scene/gui/separator.h"
#include "scene/gui/tree.h"

class Button;
class CheckBox;
class LineEdit;
class OptionButton;
class PanelContainer;
class SpinBox;
class VSeparator;

class AnimationNodeBlendSpace2DEditor : public AnimationTreeNodeEditorPlugin {
GDCLASS(AnimationNodeBlendSpace2DEditor, AnimationTreeNodeEditorPlugin);
Expand Down
2 changes: 1 addition & 1 deletion editor/plugins/animation_blend_tree_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,7 @@ void AnimationNodeBlendTreeEditor::edit(const Ref<AnimationNode> &p_node) {
}

add_node->set_disabled(read_only);
graph->set_arrange_nodes_button_hidden(read_only);
graph->set_show_arrange_button(!read_only);
}

AnimationNodeBlendTreeEditor::AnimationNodeBlendTreeEditor() {
Expand Down
3 changes: 3 additions & 0 deletions editor/plugins/animation_tree_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@
#include "editor/gui/editor_file_dialog.h"
#include "scene/animation/animation_blend_tree.h"
#include "scene/animation/animation_player.h"
#include "scene/gui/button.h"
#include "scene/gui/menu_button.h"
#include "scene/gui/panel.h"
#include "scene/gui/scroll_container.h"
#include "scene/gui/separator.h"
#include "scene/main/window.h"
#include "scene/scene_string_names.h"

Expand Down
3 changes: 2 additions & 1 deletion editor/plugins/animation_tree_editor_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@

#include "editor/editor_plugin.h"
#include "scene/animation/animation_tree.h"
#include "scene/gui/button.h"
#include "scene/gui/graph_edit.h"

class Button;
class EditorFileDialog;
class ScrollContainer;

class AnimationTreeNodeEditorPlugin : public VBoxContainer {
GDCLASS(AnimationTreeNodeEditorPlugin, VBoxContainer);
Expand Down
10 changes: 10 additions & 0 deletions misc/extension_api_validation/4.1-stable.expected
Original file line number Diff line number Diff line change
Expand Up @@ -264,3 +264,13 @@ Validate extension JSON: Error: Field 'classes/AnimationTree/methods/set_tree_ro
These definitions have been moved to those base classes, so the APIs are actually available.
Some properties were renamed for integration, but the old setter/getters are kept.
Also changed some methods name/argument/signature. Compatibility methods registered.


GH-81582
--------

Validate extension JSON: API was removed: classes/GraphEdit/methods/is_arrange_nodes_button_hidden
Validate extension JSON: API was removed: classes/GraphEdit/methods/set_arrange_nodes_button_hidden
Validate extension JSON: API was removed: classes/GraphEdit/properties/arrange_nodes_button_hidden

Make GraphEdit toolbar more customizable
46 changes: 46 additions & 0 deletions scene/gui/graph_edit.compat.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**************************************************************************/
/* graph_edit.compat.inc */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* 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. */
/**************************************************************************/

#ifndef DISABLE_DEPRECATED

bool GraphEdit::_is_arrange_nodes_button_hidden_bind_compat_81582() const {
return !is_showing_arrange_button();
}

void GraphEdit::_set_arrange_nodes_button_hidden_bind_compat_81582(bool p_enable) {
set_show_arrange_button(!p_enable);
}

void GraphEdit::_bind_compatibility_methods() {
ClassDB::bind_compatibility_method(D_METHOD("is_arrange_nodes_button_hidden"), &GraphEdit::_is_arrange_nodes_button_hidden_bind_compat_81582);
ClassDB::bind_compatibility_method(D_METHOD("set_arrange_nodes_button_hidden", "enable"), &GraphEdit::_set_arrange_nodes_button_hidden_bind_compat_81582);
}

#endif
Loading

0 comments on commit 57a6813

Please sign in to comment.