-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
112 additions
and
2 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
addons/godot_gameplay_systems/inventory_system/nodes/radial_menu_container.gd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
@tool | ||
extends Container | ||
|
||
|
||
func _draw() -> void: | ||
var child_count = get_child_count() | ||
var pie_slice_radians = 2 * PI / child_count | ||
var child_index = 0 | ||
|
||
for child in get_children(): | ||
if child is Control: | ||
# move child to a pie slice starting from the center of the container | ||
var child_angle = child_index * pie_slice_radians | ||
# var child_radius = min(size.x, size.y) / 2 | ||
var child_radius = min(size.x, size.y) / 2 | ||
var child_position = Vector2( | ||
child_radius * cos(child_angle), | ||
child_radius * sin(child_angle) | ||
) | ||
|
||
child_position.x += size.x / 2 - child.size.x / 2 | ||
child_position.y += size.y / 2 - child.size.y / 2 | ||
|
||
child.set_position(child_position) | ||
|
||
child_index += 1 | ||
|
||
|
||
func _enter_tree() -> void: | ||
child_entered_tree.connect(_handle_child_entered_tree) | ||
child_exiting_tree.connect(_handle_child_exiting_tree) | ||
|
||
|
||
func _handle_child_entered_tree(child: Node) -> void: | ||
_draw() | ||
|
||
|
||
func _handle_child_exiting_tree(child: Node) -> void: | ||
_draw() | ||
|
||
|
||
func _process(delta: float) -> void: | ||
if Engine.is_editor_hint(): | ||
_draw() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
RadialMenuContainer | ||
=================== | ||
|
||
A convenient `Container` useful to create radial menus. | ||
|
||
It inherits from `Container` and adds just a `_draw` method (which is called automatically at `_process` if inside the editor). | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters