diff options
author | Daniel Weipert <git@mail.dweipert.de> | 2025-03-31 14:34:21 +0200 |
---|---|---|
committer | Daniel Weipert <git@mail.dweipert.de> | 2025-03-31 14:34:21 +0200 |
commit | 65bfe9c4c3e09c0d9f5058dd899a82c6a47ec15d (patch) | |
tree | 06a24e13c2ece277a1146f5cb76b575ca731c879 /stage/dice_selection | |
parent | 218748f67a6a6b35efc4a732ad11426d0f528709 (diff) |
next commit
Diffstat (limited to 'stage/dice_selection')
-rw-r--r-- | stage/dice_selection/dice_selection.gd | 89 | ||||
-rw-r--r-- | stage/dice_selection/dice_selection.gd.uid | 1 | ||||
-rw-r--r-- | stage/dice_selection/dice_selection.tscn | 67 | ||||
-rw-r--r-- | stage/dice_selection/dice_selection_item.gd | 9 | ||||
-rw-r--r-- | stage/dice_selection/dice_selection_item.gd.uid | 1 | ||||
-rw-r--r-- | stage/dice_selection/dice_selection_item.tscn | 66 | ||||
-rw-r--r-- | stage/dice_selection/dice_selection_slot.gd | 1 | ||||
-rw-r--r-- | stage/dice_selection/dice_selection_slot.gd.uid | 1 | ||||
-rw-r--r-- | stage/dice_selection/dice_selection_slot.tscn | 11 |
9 files changed, 246 insertions, 0 deletions
diff --git a/stage/dice_selection/dice_selection.gd b/stage/dice_selection/dice_selection.gd new file mode 100644 index 0000000..812005a --- /dev/null +++ b/stage/dice_selection/dice_selection.gd @@ -0,0 +1,89 @@ +extends Control + + +const DICE_SELECTION_ITEM_SCENE := preload("res://stage/dice_selection/dice_selection_item.tscn") + +signal dice_selected(dice: Array[DiceConfiguration]) + +@export var dice_count: int + + +func _ready() -> void: + for _i in 6: + var dice := DICE_SELECTION_ITEM_SCENE.instantiate() + #dice.dice_configuration = + dice.pressed.connect(_on_deck_dice_selected.bind(dice)) + dice.focus_entered.connect(_on_dice_focus_entered.bind(dice)) + dice.focus_exited.connect(_on_dice_focus_exited) + dice.size_flags_vertical = Control.SIZE_EXPAND_FILL + %DeckContainer.add_child(dice) + + for _i in dice_count: + pass + + # clear button press buffer + await get_tree().process_frame + %DeckContainer.get_child(0).grab_focus() + + +func _input(event: InputEvent) -> void: + if event.is_action_pressed("right_click"): + dice_selected.emit([] as Array[DiceConfiguration]) + + +func _on_deck_dice_selected(dice: Control) -> void: + if %SelectedContainer.get_child_count() >= dice_count: + return + + var slot_dice: TextureButton = dice.duplicate() + slot_dice.pressed.connect(_on_slot_dice_selected.bind(slot_dice)) + slot_dice.focus_entered.connect(_on_dice_focus_entered.bind(slot_dice)) + slot_dice.focus_exited.connect(_on_dice_focus_exited) + + %SelectedContainer.add_child(slot_dice) + + +func _on_slot_dice_selected(dice: Control) -> void: + if %SelectedContainer.get_child_count() > 1: + if dice.get_index() == %SelectedContainer.get_child_count() - 1: + %SelectedContainer.get_child(dice.get_index() - 1).grab_focus() + else: + %SelectedContainer.get_child(dice.get_index() + 1).grab_focus() + else: + # TODO: focus last child focused in DeckContainer + %DeckContainer.get_child(0).grab_focus() + + %SelectedContainer.remove_child(dice) + + +func _on_dice_focus_entered(dice: Control) -> void: + var dice_configuration := dice.dice_configuration as DiceConfiguration + var faces := [ + dice_configuration.front_face, + dice_configuration.back_face, + dice_configuration.top_face, + dice_configuration.bottom_face, + dice_configuration.left_face, + dice_configuration.right_face, + ] + + %Label.text = "" + for face in faces: + %Label.text += "%s: %s " % [face.type, face.value] + + +func _on_dice_focus_exited() -> void: + # is null while freeing and focus exit at same time + if has_node("%Label"): + %Label.text = "" + + +func _on_go_button_pressed() -> void: + if %SelectedContainer.get_child_count() < dice_count: + return + + var selected_dice_configurations: Array[DiceConfiguration] + for node in %SelectedContainer.get_children(): + selected_dice_configurations.append(node.dice_configuration) + + dice_selected.emit(selected_dice_configurations) diff --git a/stage/dice_selection/dice_selection.gd.uid b/stage/dice_selection/dice_selection.gd.uid new file mode 100644 index 0000000..a1c11ae --- /dev/null +++ b/stage/dice_selection/dice_selection.gd.uid @@ -0,0 +1 @@ +uid://m2cmtbl8jggr diff --git a/stage/dice_selection/dice_selection.tscn b/stage/dice_selection/dice_selection.tscn new file mode 100644 index 0000000..934d3fc --- /dev/null +++ b/stage/dice_selection/dice_selection.tscn @@ -0,0 +1,67 @@ +[gd_scene load_steps=4 format=3 uid="uid://7h2vibxobovj"] + +[ext_resource type="Script" uid="uid://m2cmtbl8jggr" path="res://stage/dice_selection/dice_selection.gd" id="1_tpblt"] + +[sub_resource type="InputEventAction" id="InputEventAction_dxcsf"] +action = &"left_click" + +[sub_resource type="Shortcut" id="Shortcut_sn5id"] +events = [SubResource("InputEventAction_dxcsf")] + +[node name="DiceSelection" type="Control"] +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +script = ExtResource("1_tpblt") +dice_count = 3 + +[node name="VBoxContainer" type="VBoxContainer" parent="."] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 + +[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"] +layout_mode = 2 +size_flags_vertical = 3 + +[node name="DeckContainer" type="GridContainer" parent="VBoxContainer/HBoxContainer"] +unique_name_in_owner = true +layout_mode = 2 +size_flags_horizontal = 3 +columns = 6 + +[node name="VBoxContainer" type="VBoxContainer" parent="VBoxContainer/HBoxContainer"] +layout_mode = 2 +size_flags_horizontal = 3 +size_flags_stretch_ratio = 0.2 + +[node name="PanelContainer" type="PanelContainer" parent="VBoxContainer/HBoxContainer/VBoxContainer"] +layout_mode = 2 +size_flags_vertical = 3 + +[node name="SelectedContainer" type="VBoxContainer" parent="VBoxContainer/HBoxContainer/VBoxContainer/PanelContainer"] +unique_name_in_owner = true +layout_mode = 2 + +[node name="GoButton" type="Button" parent="VBoxContainer/HBoxContainer/VBoxContainer" node_paths=PackedStringArray("shortcut_context")] +layout_mode = 2 +shortcut_context = NodePath(".") +shortcut = SubResource("Shortcut_sn5id") +text = "GO" + +[node name="PanelContainer" type="PanelContainer" parent="VBoxContainer"] +layout_mode = 2 +size_flags_vertical = 3 +size_flags_stretch_ratio = 0.1 + +[node name="Label" type="Label" parent="VBoxContainer/PanelContainer"] +unique_name_in_owner = true +layout_mode = 2 + +[connection signal="pressed" from="VBoxContainer/HBoxContainer/VBoxContainer/GoButton" to="." method="_on_go_button_pressed"] diff --git a/stage/dice_selection/dice_selection_item.gd b/stage/dice_selection/dice_selection_item.gd new file mode 100644 index 0000000..6e1002b --- /dev/null +++ b/stage/dice_selection/dice_selection_item.gd @@ -0,0 +1,9 @@ +extends TextureButton + + +@export var dice_configuration: DiceConfiguration + + +func _on_gui_input(event: InputEvent) -> void: + if event.is_action_pressed("left_click"): + pressed.emit() diff --git a/stage/dice_selection/dice_selection_item.gd.uid b/stage/dice_selection/dice_selection_item.gd.uid new file mode 100644 index 0000000..71e2f32 --- /dev/null +++ b/stage/dice_selection/dice_selection_item.gd.uid @@ -0,0 +1 @@ +uid://bgaq754eqfs8g diff --git a/stage/dice_selection/dice_selection_item.tscn b/stage/dice_selection/dice_selection_item.tscn new file mode 100644 index 0000000..4cedb3e --- /dev/null +++ b/stage/dice_selection/dice_selection_item.tscn @@ -0,0 +1,66 @@ +[gd_scene load_steps=13 format=3 uid="uid://d280t78wjw3hc"] + +[ext_resource type="Script" uid="uid://bgaq754eqfs8g" path="res://stage/dice_selection/dice_selection_item.gd" id="1_v6plq"] +[ext_resource type="Texture2D" uid="uid://blanietpri1be" path="res://icon.svg" id="2_1q4g0"] +[ext_resource type="Texture2D" uid="uid://db0v50mdroaox" path="res://stage/assets/isometric-tile.png" id="2_p1an8"] +[ext_resource type="Script" uid="uid://dnklife8p0m35" path="res://stage/dice_throw/dice_face_configuration.gd" id="3_xogsa"] +[ext_resource type="Script" uid="uid://6rit5abkk1rw" path="res://stage/dice_throw/dice_configuration.gd" id="4_p1an8"] + +[sub_resource type="Resource" id="Resource_xogsa"] +script = ExtResource("3_xogsa") +type = "move" +value = 1 +metadata/_custom_type_script = "uid://dnklife8p0m35" + +[sub_resource type="Resource" id="Resource_ye5qu"] +script = ExtResource("3_xogsa") +type = "attack" +value = 1 +metadata/_custom_type_script = "uid://dnklife8p0m35" + +[sub_resource type="Resource" id="Resource_xub8r"] +script = ExtResource("3_xogsa") +type = "move" +value = 1 +metadata/_custom_type_script = "uid://dnklife8p0m35" + +[sub_resource type="Resource" id="Resource_0m3mt"] +script = ExtResource("3_xogsa") +type = "defend" +value = 1 +metadata/_custom_type_script = "uid://dnklife8p0m35" + +[sub_resource type="Resource" id="Resource_inbll"] +script = ExtResource("3_xogsa") +type = "ability" +value = 1 +metadata/_custom_type_script = "uid://dnklife8p0m35" + +[sub_resource type="Resource" id="Resource_p1an8"] +script = ExtResource("3_xogsa") +type = "attack" +value = 1 +metadata/_custom_type_script = "uid://dnklife8p0m35" + +[sub_resource type="Resource" id="Resource_f5jvy"] +script = ExtResource("4_p1an8") +front_face = SubResource("Resource_xub8r") +back_face = SubResource("Resource_xogsa") +top_face = SubResource("Resource_p1an8") +bottom_face = SubResource("Resource_ye5qu") +left_face = SubResource("Resource_0m3mt") +right_face = SubResource("Resource_inbll") +metadata/_custom_type_script = "uid://6rit5abkk1rw" + +[node name="DiceSelectionItem" type="TextureButton"] +custom_minimum_size = Vector2(32, 32) +offset_right = 32.0 +offset_bottom = 32.0 +texture_normal = ExtResource("2_1q4g0") +texture_focused = ExtResource("2_p1an8") +ignore_texture_size = true +stretch_mode = 4 +script = ExtResource("1_v6plq") +dice_configuration = SubResource("Resource_f5jvy") + +[connection signal="gui_input" from="." to="." method="_on_gui_input"] diff --git a/stage/dice_selection/dice_selection_slot.gd b/stage/dice_selection/dice_selection_slot.gd new file mode 100644 index 0000000..09700e8 --- /dev/null +++ b/stage/dice_selection/dice_selection_slot.gd @@ -0,0 +1 @@ +extends PanelContainer diff --git a/stage/dice_selection/dice_selection_slot.gd.uid b/stage/dice_selection/dice_selection_slot.gd.uid new file mode 100644 index 0000000..c592163 --- /dev/null +++ b/stage/dice_selection/dice_selection_slot.gd.uid @@ -0,0 +1 @@ +uid://c8wesjl2abx3r diff --git a/stage/dice_selection/dice_selection_slot.tscn b/stage/dice_selection/dice_selection_slot.tscn new file mode 100644 index 0000000..674a0d8 --- /dev/null +++ b/stage/dice_selection/dice_selection_slot.tscn @@ -0,0 +1,11 @@ +[gd_scene load_steps=2 format=3 uid="uid://c0pej8plsktr"] + +[ext_resource type="Script" uid="uid://c8wesjl2abx3r" path="res://stage/dice_selection/dice_selection_slot.gd" id="1_o87as"] + +[node name="DiceSelectionSlot" type="PanelContainer"] +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +script = ExtResource("1_o87as") |