Skip to content

Commit

Permalink
feat: allow moving the sidebar
Browse files Browse the repository at this point in the history
fixes #47
  • Loading branch information
derkork committed Oct 6, 2023
1 parent f1ebf7a commit ea191f2
Show file tree
Hide file tree
Showing 9 changed files with 153 additions and 26 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.6.0] - 2023-10-06
### Added
- You can now move the sidebar for quickly adding new states to the other side of the editor. This is useful if you have your node tree on the right side of the editor. The location will be saved with the editor layout ([#47](https://github.com/derkork/godot-statecharts/issues/47)).


## [0.5.0] - 2023-09-27
### Added
Expand Down
53 changes: 49 additions & 4 deletions addons/godot_state_charts/godot_state_charts.gd
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,66 @@ var _ui_sidebar_spatial:Control
var _sidebar_ui:PackedScene = preload("utilities/editor_sidebar.tscn")


enum SidebarLocation {
LEFT = 1,
RIGHT = 2
}

## The current location of the sidebar. Default is left.
var _current_sidebar_location:SidebarLocation = SidebarLocation.LEFT


func _enter_tree():
# prepare a copy of the sidebar for both 2D and 3D.
_ui_sidebar_canvas = _sidebar_ui.instantiate()
_ui_sidebar_canvas.sidebar_toggle_requested.connect(_toggle_sidebar)
_ui_sidebar_canvas.hide()
_ui_sidebar_spatial = _sidebar_ui.instantiate()
_ui_sidebar_spatial.sidebar_toggle_requested.connect(_toggle_sidebar)
_ui_sidebar_spatial.hide()
# and add it to the right place in the editor ui
add_control_to_container(EditorPlugin.CONTAINER_SPATIAL_EDITOR_SIDE_LEFT, _ui_sidebar_spatial)
add_control_to_container(EditorPlugin.CONTAINER_CANVAS_EDITOR_SIDE_LEFT, _ui_sidebar_canvas)
_add_sidebars()
# get notified when selection changes so we can
# update the sidebar contents accordingly
get_editor_interface().get_selection().selection_changed.connect(_on_selection_changed)


func _set_window_layout(configuration):
_remove_sidebars()
_current_sidebar_location = configuration.get_value("GodotStateCharts", "sidebar_location", SidebarLocation.LEFT)
_add_sidebars()


func _get_window_layout(configuration):
configuration.set_value("GodotStateCharts", "sidebar_location", _current_sidebar_location)


func _toggle_sidebar():
_remove_sidebars()
_current_sidebar_location = SidebarLocation.RIGHT if _current_sidebar_location == SidebarLocation.LEFT else SidebarLocation.LEFT
_add_sidebars()
queue_save_layout()


func _add_sidebars():
if _current_sidebar_location == SidebarLocation.LEFT:
add_control_to_container(EditorPlugin.CONTAINER_SPATIAL_EDITOR_SIDE_LEFT, _ui_sidebar_spatial)
add_control_to_container(EditorPlugin.CONTAINER_CANVAS_EDITOR_SIDE_LEFT, _ui_sidebar_canvas)
else:
add_control_to_container(EditorPlugin.CONTAINER_SPATIAL_EDITOR_SIDE_RIGHT, _ui_sidebar_spatial)
add_control_to_container(EditorPlugin.CONTAINER_CANVAS_EDITOR_SIDE_RIGHT, _ui_sidebar_canvas)


func _remove_sidebars():
if _current_sidebar_location == SidebarLocation.LEFT:
remove_control_from_container(EditorPlugin.CONTAINER_CANVAS_EDITOR_SIDE_LEFT,_ui_sidebar_canvas)
remove_control_from_container(EditorPlugin.CONTAINER_SPATIAL_EDITOR_SIDE_LEFT, _ui_sidebar_spatial)
else:
remove_control_from_container(EditorPlugin.CONTAINER_CANVAS_EDITOR_SIDE_RIGHT,_ui_sidebar_canvas)
remove_control_from_container(EditorPlugin.CONTAINER_SPATIAL_EDITOR_SIDE_RIGHT, _ui_sidebar_spatial)



func _ready():
# inititalize the side bars
_ui_sidebar_canvas.setup(get_editor_interface(), get_undo_redo())
Expand All @@ -32,8 +78,7 @@ func _ready():

func _exit_tree():
# remove the side bars
remove_control_from_container(EditorPlugin.CONTAINER_SPATIAL_EDITOR_SIDE_LEFT, _ui_sidebar_spatial)
remove_control_from_container(EditorPlugin.CONTAINER_CANVAS_EDITOR_SIDE_LEFT, _ui_sidebar_canvas)
_remove_sidebars()
if is_instance_valid(_ui_sidebar_canvas):
_ui_sidebar_canvas.queue_free()
if is_instance_valid(_ui_sidebar_spatial):
Expand Down
2 changes: 1 addition & 1 deletion addons/godot_state_charts/plugin.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
name="Godot State Charts"
description="A simple, yet powerful state charts library for Godot"
author="Jan Thomä & Contributors"
version="0.5.0"
version="0.6.0"
script="godot_state_charts.gd"
20 changes: 20 additions & 0 deletions addons/godot_state_charts/toggle_sidebar.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions addons/godot_state_charts/toggle_sidebar.svg.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://vga3avpb4gyh"
path="res://.godot/imported/toggle_sidebar.svg-99e4fe22fa516ab6214c0533adb07ec0.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://addons/godot_state_charts/toggle_sidebar.svg"
dest_files=["res://.godot/imported/toggle_sidebar.svg-99e4fe22fa516ab6214c0533adb07ec0.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
svg/scale=1.0
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false
6 changes: 6 additions & 0 deletions addons/godot_state_charts/utilities/editor_sidebar.gd
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
@tool
extends Control

## Emitted when the user requests to toggle the sidebar.
signal sidebar_toggle_requested()

## The currently selected node or null
var _selected_node:Node
## The editor interface
Expand Down Expand Up @@ -99,3 +102,6 @@ func _on_animation_tree_state_pressed():
func _on_animation_player_state_pressed():
_create_node(AnimationPlayerState, "AnimationPlayerState")


func _on_toggle_sidebar_button_pressed():
sidebar_toggle_requested.emit()
55 changes: 35 additions & 20 deletions addons/godot_state_charts/utilities/editor_sidebar.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=9 format=3 uid="uid://bephgxrkhh3e2"]
[gd_scene load_steps=10 format=3 uid="uid://bephgxrkhh3e2"]

[ext_resource type="Script" path="res://addons/godot_state_charts/utilities/editor_sidebar.gd" id="1_7kcy8"]
[ext_resource type="Texture2D" uid="uid://c4ojtah20jtxc" path="res://addons/godot_state_charts/atomic_state.svg" id="2_0k4pg"]
Expand All @@ -8,6 +8,7 @@
[ext_resource type="Texture2D" uid="uid://3wqyduuj0fq" path="res://addons/godot_state_charts/animation_tree_state.svg" id="6_8npp8"]
[ext_resource type="Texture2D" uid="uid://chb8tq62aj2b2" path="res://addons/godot_state_charts/transition.svg" id="6_72e5q"]
[ext_resource type="Texture2D" uid="uid://b3m20gsesp4i0" path="res://addons/godot_state_charts/animation_player_state.svg" id="8_ci7iy"]
[ext_resource type="Texture2D" uid="uid://vga3avpb4gyh" path="res://addons/godot_state_charts/toggle_sidebar.svg" id="9_dqcj0"]

[node name="EditorSidebar" type="MarginContainer"]
custom_minimum_size = Vector2(192, 0)
Expand All @@ -21,18 +22,21 @@ theme_override_constants/margin_top = 4
theme_override_constants/margin_bottom = 4
script = ExtResource("1_7kcy8")

[node name="AddSection" type="VBoxContainer" parent="."]
[node name="VBoxContainer" type="VBoxContainer" parent="."]
layout_mode = 2

[node name="AddSection" type="VBoxContainer" parent="VBoxContainer"]
unique_name_in_owner = true
visible = false
layout_mode = 2

[node name="AddLabel" type="Label" parent="AddSection"]
[node name="AddLabel" type="Label" parent="VBoxContainer/AddSection"]
layout_mode = 2
text = "Add"
horizontal_alignment = 1
vertical_alignment = 1

[node name="AddNodeNameLineEdit" type="LineEdit" parent="AddSection"]
[node name="AddNodeNameLineEdit" type="LineEdit" parent="VBoxContainer/AddSection"]
unique_name_in_owner = true
layout_mode = 2
placeholder_text = "Name"
Expand All @@ -42,70 +46,70 @@ select_all_on_focus = true
caret_blink = true
caret_blink_interval = 0.5

[node name="AddGridContainer" type="HFlowContainer" parent="AddSection"]
[node name="AddGridContainer" type="HFlowContainer" parent="VBoxContainer/AddSection"]
unique_name_in_owner = true
layout_mode = 2
theme_override_constants/h_separation = 5
theme_override_constants/v_separation = 5
alignment = 1

[node name="CompoundState" type="Button" parent="AddSection/AddGridContainer" groups=["statebutton"]]
[node name="CompoundState" type="Button" parent="VBoxContainer/AddSection/AddGridContainer" groups=["statebutton"]]
layout_mode = 2
size_flags_horizontal = 0
size_flags_vertical = 0
tooltip_text = "CompoundState"
icon = ExtResource("3_b4okj")
icon_alignment = 1

[node name="ParallelState" type="Button" parent="AddSection/AddGridContainer" groups=["statebutton"]]
[node name="ParallelState" type="Button" parent="VBoxContainer/AddSection/AddGridContainer" groups=["statebutton"]]
layout_mode = 2
size_flags_horizontal = 0
size_flags_vertical = 0
tooltip_text = "ParallelState"
icon = ExtResource("4_lmfic")
icon_alignment = 1

[node name="AtomicState" type="Button" parent="AddSection/AddGridContainer" groups=["statebutton"]]
[node name="AtomicState" type="Button" parent="VBoxContainer/AddSection/AddGridContainer" groups=["statebutton"]]
layout_mode = 2
size_flags_horizontal = 0
size_flags_vertical = 0
tooltip_text = "AtomicState"
icon = ExtResource("2_0k4pg")
icon_alignment = 1

[node name="HistoryState" type="Button" parent="AddSection/AddGridContainer" groups=["statebutton"]]
[node name="HistoryState" type="Button" parent="VBoxContainer/AddSection/AddGridContainer" groups=["statebutton"]]
layout_mode = 2
size_flags_horizontal = 0
size_flags_vertical = 0
tooltip_text = "HistoryState"
icon = ExtResource("5_oj1t0")
icon_alignment = 1

[node name="Transition" type="Button" parent="AddSection/AddGridContainer"]
[node name="Transition" type="Button" parent="VBoxContainer/AddSection/AddGridContainer"]
layout_mode = 2
size_flags_horizontal = 0
size_flags_vertical = 0
tooltip_text = "Transition"
icon = ExtResource("6_72e5q")
icon_alignment = 1

[node name="AnimationTreeState" type="Button" parent="AddSection/AddGridContainer" groups=["statebutton"]]
[node name="AnimationTreeState" type="Button" parent="VBoxContainer/AddSection/AddGridContainer" groups=["statebutton"]]
layout_mode = 2
size_flags_horizontal = 0
size_flags_vertical = 0
tooltip_text = "AnimationTreeState"
icon = ExtResource("6_8npp8")
icon_alignment = 1

[node name="AnimationPlayerState" type="Button" parent="AddSection/AddGridContainer" groups=["statebutton"]]
[node name="AnimationPlayerState" type="Button" parent="VBoxContainer/AddSection/AddGridContainer" groups=["statebutton"]]
layout_mode = 2
size_flags_horizontal = 0
size_flags_vertical = 0
tooltip_text = "AnimationPlayerState"
icon = ExtResource("8_ci7iy")
icon_alignment = 1

[node name="NoOptionsLabel" type="Label" parent="."]
[node name="NoOptionsLabel" type="Label" parent="VBoxContainer"]
unique_name_in_owner = true
custom_minimum_size = Vector2(100, 0)
layout_mode = 2
Expand All @@ -114,10 +118,21 @@ text = "This node cannot have further child nodes."
horizontal_alignment = 1
autowrap_mode = 2

[connection signal="pressed" from="AddSection/AddGridContainer/CompoundState" to="." method="_on_compound_state_pressed"]
[connection signal="pressed" from="AddSection/AddGridContainer/ParallelState" to="." method="_on_parallel_state_pressed"]
[connection signal="pressed" from="AddSection/AddGridContainer/AtomicState" to="." method="_on_atomic_state_pressed"]
[connection signal="pressed" from="AddSection/AddGridContainer/HistoryState" to="." method="_on_history_state_pressed"]
[connection signal="pressed" from="AddSection/AddGridContainer/Transition" to="." method="_on_transition_pressed"]
[connection signal="pressed" from="AddSection/AddGridContainer/AnimationTreeState" to="." method="_on_animation_tree_state_pressed"]
[connection signal="pressed" from="AddSection/AddGridContainer/AnimationPlayerState" to="." method="_on_animation_player_state_pressed"]
[node name="Spacer" type="Control" parent="VBoxContainer"]
layout_mode = 2
size_flags_vertical = 3

[node name="ToggleSidebarButton" type="Button" parent="VBoxContainer"]
layout_mode = 2
size_flags_horizontal = 4
tooltip_text = "Toggle sidebar location"
icon = ExtResource("9_dqcj0")

[connection signal="pressed" from="VBoxContainer/AddSection/AddGridContainer/CompoundState" to="." method="_on_compound_state_pressed"]
[connection signal="pressed" from="VBoxContainer/AddSection/AddGridContainer/ParallelState" to="." method="_on_parallel_state_pressed"]
[connection signal="pressed" from="VBoxContainer/AddSection/AddGridContainer/AtomicState" to="." method="_on_atomic_state_pressed"]
[connection signal="pressed" from="VBoxContainer/AddSection/AddGridContainer/HistoryState" to="." method="_on_history_state_pressed"]
[connection signal="pressed" from="VBoxContainer/AddSection/AddGridContainer/Transition" to="." method="_on_transition_pressed"]
[connection signal="pressed" from="VBoxContainer/AddSection/AddGridContainer/AnimationTreeState" to="." method="_on_animation_tree_state_pressed"]
[connection signal="pressed" from="VBoxContainer/AddSection/AddGridContainer/AnimationPlayerState" to="." method="_on_animation_player_state_pressed"]
[connection signal="pressed" from="VBoxContainer/ToggleSidebarButton" to="." method="_on_toggle_sidebar_button_pressed"]
2 changes: 1 addition & 1 deletion manual/manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Starting with version 0.2.0 there is also an improved UI to quickly add nodes an

If you hold down `Shift` while clicking the button for the node you want to add, the newly added node will be selected automatically. Otherwise the node will be added to the currently selected node but the currently selected node will stay selected.

The new UI supports undo/redo, so you can undo the addition of a node or transition with `Ctrl+Z`.
The new UI supports undo/redo, so you can undo the addition of a node or transition with `Ctrl+Z`. You can move the sidebar to the other side of the editor by clicking the <img src="../addons/godot_state_charts/toggle_sidebar.svg" width="16" height="16" title="toggle sidebar icon"> icon at the bottom of the sidebar.

### Examples

Expand Down
Binary file modified raw_assets/icons.afdesign
Binary file not shown.

0 comments on commit ea191f2

Please sign in to comment.