feat: collection context menu

This commit is contained in:
LunarAkai 2025-07-01 12:48:34 +02:00
commit a47a818f8b
5 changed files with 38 additions and 4 deletions

View file

@ -32,6 +32,14 @@ window/size/transparent=true
window/subwindows/embed_subwindows=false window/subwindows/embed_subwindows=false
window/per_pixel_transparency/allowed=true window/per_pixel_transparency/allowed=true
[input]
right_click={
"deadzone": 0.2,
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":2,"position":Vector2(94, 14),"global_position":Vector2(103, 60),"factor":1.0,"button_index":2,"canceled":false,"pressed":true,"double_click":false,"script":null)
]
}
[rendering] [rendering]
renderer/rendering_method="gl_compatibility" renderer/rendering_method="gl_compatibility"

View file

@ -2,6 +2,7 @@ class_name ContainerSelectionButton extends MarginContainer
@export var button: Button @export var button: Button
@export var container_box: ContainerBox @export var container_box: ContainerBox
@export var popup_menu: PopupMenu
var button_index: int var button_index: int
@ -19,3 +20,15 @@ func _enter_tree() -> void:
## Buttons are 1-indexed, while [member UIManager.panel_array] is 0-index ## Buttons are 1-indexed, while [member UIManager.panel_array] is 0-index
func _on_button_pressed() -> void: func _on_button_pressed() -> void:
SignalBus.on_panel_requested.emit(button_index-1) SignalBus.on_panel_requested.emit(button_index-1)
func _input(event: InputEvent) -> void:
if get_global_rect().has_point(get_global_mouse_position()):
if event.is_action_released("right_click"):
popup_menu.popup_on_parent(
Rect2(
button.get_global_rect().position.x,
button.get_global_rect().position.y+20,
button.get_global_rect().size.x,
button.get_global_rect().size.y)
)

View file

@ -1,7 +1,9 @@
[gd_scene load_steps=6 format=3 uid="uid://csre4kogd8afg"] [gd_scene load_steps=8 format=3 uid="uid://csre4kogd8afg"]
[ext_resource type="Script" uid="uid://osei0aimuya2" path="res://src/UI/buttons/container_selection_button.gd" id="1_g121j"] [ext_resource type="Script" uid="uid://osei0aimuya2" path="res://src/UI/buttons/container_selection_button.gd" id="1_g121j"]
[ext_resource type="Theme" uid="uid://bal6yp0a25hf2" path="res://src/theme/main_theme.tres" id="1_ru1ls"] [ext_resource type="Theme" uid="uid://bal6yp0a25hf2" path="res://src/theme/main_theme.tres" id="1_ru1ls"]
[ext_resource type="Texture2D" uid="uid://ne4o3drvj5vw" path="res://src/assets/icons/color-picker.svg" id="3_wvlx0"]
[ext_resource type="Texture2D" uid="uid://s3vf3vhl8y3e" path="res://src/assets/icons/trash.svg" id="4_4ff2x"]
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_dv4hw"] [sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_dv4hw"]
@ -10,7 +12,7 @@
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_gtrax"] [sub_resource type="StyleBoxFlat" id="StyleBoxFlat_gtrax"]
bg_color = Color(0.43134, 0.43134, 0.43134, 1) bg_color = Color(0.43134, 0.43134, 0.43134, 1)
[node name="ContainerSelectionButton" type="MarginContainer" node_paths=PackedStringArray("button")] [node name="ContainerSelectionButton" type="MarginContainer" node_paths=PackedStringArray("button", "popup_menu")]
offset_right = 40.0 offset_right = 40.0
offset_bottom = 40.0 offset_bottom = 40.0
scale = Vector2(1, 1.02369) scale = Vector2(1, 1.02369)
@ -20,6 +22,7 @@ theme_override_constants/margin_right = 5
theme_override_constants/margin_bottom = 5 theme_override_constants/margin_bottom = 5
script = ExtResource("1_g121j") script = ExtResource("1_g121j")
button = NodePath("Button") button = NodePath("Button")
popup_menu = NodePath("PopupMenu")
[node name="Button" type="Button" parent="."] [node name="Button" type="Button" parent="."]
layout_mode = 2 layout_mode = 2
@ -30,4 +33,13 @@ theme_override_styles/hover = SubResource("StyleBoxFlat_05tj4")
theme_override_styles/pressed = SubResource("StyleBoxFlat_gtrax") theme_override_styles/pressed = SubResource("StyleBoxFlat_gtrax")
text = "Collection 1" text = "Collection 1"
[node name="PopupMenu" type="PopupMenu" parent="."]
item_count = 2
item_0/text = "Edit Name"
item_0/icon = ExtResource("3_wvlx0")
item_0/id = 0
item_1/text = "Delete"
item_1/icon = ExtResource("4_4ff2x")
item_1/id = 1
[connection signal="pressed" from="Button" to="." method="_on_button_pressed"] [connection signal="pressed" from="Button" to="." method="_on_button_pressed"]

View file

@ -22,7 +22,8 @@ func _process(delta: float) -> void:
pass pass
func _on_index_pressed(index:int) -> void: func _on_index_pressed(index:int) -> void:
print(index) if instantiated_menu != null:
return
if index == 0: if index == 0:
instantiated_menu = edit_menu.instantiate() instantiated_menu = edit_menu.instantiate()
add_child(instantiated_menu) add_child(instantiated_menu)

View file

@ -75,7 +75,7 @@ theme_override_constants/separation = 10
layout_mode = 2 layout_mode = 2
size_flags_horizontal = 3 size_flags_horizontal = 3
bbcode_enabled = true bbcode_enabled = true
text = "[b]MM.DD.YYYY[b]" text = "[b]DD.MM.YYYY[b]"
fit_content = true fit_content = true
horizontal_alignment = 1 horizontal_alignment = 1
vertical_alignment = 1 vertical_alignment = 1