From 6936497026e9fe388eaf39b5e6f9fe4f20a95648 Mon Sep 17 00:00:00 2001 From: Ryan Reed Date: Thu, 6 Mar 2025 19:00:47 -0500 Subject: [PATCH] Adding quick slots (UI does not work yet) --- project.godot | 30 ++++++++++ root.tscn | 5 +- scenes/player/ray_cast_3d.gd | 5 +- scenes/quick_slots.gd | 44 ++++++++++++++ scenes/quick_slots.gd.uid | 1 + scenes/quick_slots.tscn | 6 ++ scenes/ui/quick_slots.tscn | 112 +++++++++++++++++++++++++++++++++++ scenes/ui/ui.gd | 2 + scenes/ui/ui.tscn | 5 +- 9 files changed, 207 insertions(+), 3 deletions(-) create mode 100644 scenes/quick_slots.gd create mode 100644 scenes/quick_slots.gd.uid create mode 100644 scenes/quick_slots.tscn create mode 100644 scenes/ui/quick_slots.tscn diff --git a/project.godot b/project.godot index f06f268..e2a6e23 100644 --- a/project.godot +++ b/project.godot @@ -103,6 +103,36 @@ crouch={ "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194326,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) ] } +quickslot0={ +"deadzone": 0.2, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":49,"key_label":0,"unicode":49,"location":0,"echo":false,"script":null) +] +} +quickslot1={ +"deadzone": 0.2, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":50,"key_label":0,"unicode":50,"location":0,"echo":false,"script":null) +] +} +quickslot2={ +"deadzone": 0.2, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":51,"key_label":0,"unicode":51,"location":0,"echo":false,"script":null) +] +} +quickslot3={ +"deadzone": 0.2, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":52,"key_label":0,"unicode":52,"location":0,"echo":false,"script":null) +] +} +quickslot_next={ +"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":8,"position":Vector2(189, 22),"global_position":Vector2(198, 68),"factor":1.0,"button_index":4,"canceled":false,"pressed":true,"double_click":false,"script":null) +] +} +quickslot_previous={ +"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":16,"position":Vector2(173, 17),"global_position":Vector2(182, 63),"factor":1.0,"button_index":5,"canceled":false,"pressed":true,"double_click":false,"script":null) +] +} [layer_names] diff --git a/root.tscn b/root.tscn index 194c3f5..cf11b8e 100644 --- a/root.tscn +++ b/root.tscn @@ -1,6 +1,7 @@ -[gd_scene load_steps=4 format=3 uid="uid://cgx0nawwjjj7g"] +[gd_scene load_steps=5 format=3 uid="uid://cgx0nawwjjj7g"] [ext_resource type="PackedScene" uid="uid://c0epfh4sqjcjq" path="res://data_structure/db_items.tscn" id="1_pyidc"] +[ext_resource type="PackedScene" uid="uid://ctxl46pkm0ac5" path="res://scenes/quick_slots.tscn" id="2_28aoi"] [ext_resource type="PackedScene" uid="uid://mkfitwqnerku" path="res://scenes/world/world.tscn" id="2_vvh5c"] [ext_resource type="PackedScene" uid="uid://c7fj7wla8bd70" path="res://scenes/ui/ui.tscn" id="3_vvh5c"] @@ -8,6 +9,8 @@ [node name="DBItems" parent="." instance=ExtResource("1_pyidc")] +[node name="QuickSlots" parent="." instance=ExtResource("2_28aoi")] + [node name="World" parent="." instance=ExtResource("2_vvh5c")] [node name="UI" parent="." instance=ExtResource("3_vvh5c")] diff --git a/scenes/player/ray_cast_3d.gd b/scenes/player/ray_cast_3d.gd index d310ded..f8b8cf9 100644 --- a/scenes/player/ray_cast_3d.gd +++ b/scenes/player/ray_cast_3d.gd @@ -9,7 +9,10 @@ func _process(_delta: float) -> void: if Input.is_action_just_pressed("left_click_interact"): (collider as Block).interact_left_click() if Input.is_action_just_pressed("right_click_interact"): - EntityManager.create_block.emit("001", collider.position + get_collision_normal()) + EntityManager.create_block.emit( + QuickSlots.ref.get_selected_item(), + collider.position + get_collision_normal() + ) if Waila.ref.get_target() == collider: return diff --git a/scenes/quick_slots.gd b/scenes/quick_slots.gd new file mode 100644 index 0000000..eff0ef7 --- /dev/null +++ b/scenes/quick_slots.gd @@ -0,0 +1,44 @@ +class_name QuickSlots +extends Node + +#region Singleton +static var ref: QuickSlots + +func _init() -> void: + if not ref: + ref = self + else: + queue_free() +#endregion + + +var _items: Array[String] = ["001", "002", "003", "004"] +var _selected_item: int = 0 + + +func _unhandled_input(event: InputEvent) -> void: + if event.is_action_pressed("quickslot0"): + _selected_item = 0 + if event.is_action_pressed("quickslot1"): + _selected_item = 1 + if event.is_action_pressed("quickslot2"): + _selected_item = 2 + if event.is_action_pressed("quickslot3"): + _selected_item = 3 + if event.is_action_pressed("quickslot_next"): + select_next_item() + if event.is_action_pressed("quickslot_previous"): + select_previous_item() + + +func get_quickslot_index() -> int: + return _selected_item + +func get_selected_item() -> String: + return _items[_selected_item] + +func select_previous_item() -> void: + _selected_item = clampi(_selected_item - 1, 0, _items.size() - 1) + +func select_next_item() -> void: + _selected_item = clampi(_selected_item + 1, 0, _items.size() - 1) diff --git a/scenes/quick_slots.gd.uid b/scenes/quick_slots.gd.uid new file mode 100644 index 0000000..67324e1 --- /dev/null +++ b/scenes/quick_slots.gd.uid @@ -0,0 +1 @@ +uid://bcq6vexsmyeol diff --git a/scenes/quick_slots.tscn b/scenes/quick_slots.tscn new file mode 100644 index 0000000..4beb217 --- /dev/null +++ b/scenes/quick_slots.tscn @@ -0,0 +1,6 @@ +[gd_scene load_steps=2 format=3 uid="uid://ctxl46pkm0ac5"] + +[ext_resource type="Script" uid="uid://bcq6vexsmyeol" path="res://scenes/quick_slots.gd" id="1_5cv54"] + +[node name="QuickSlots" type="Node"] +script = ExtResource("1_5cv54") diff --git a/scenes/ui/quick_slots.tscn b/scenes/ui/quick_slots.tscn new file mode 100644 index 0000000..0047363 --- /dev/null +++ b/scenes/ui/quick_slots.tscn @@ -0,0 +1,112 @@ +[gd_scene load_steps=5 format=3 uid="uid://cbiygbgpfk220"] + +[ext_resource type="Texture2D" uid="uid://li36txj7oweq" path="res://assets/textures/dirt.png" id="2_kotkb"] +[ext_resource type="Texture2D" uid="uid://ct1iawpfkdf5l" path="res://assets/textures/stone.png" id="3_cqw2g"] +[ext_resource type="Texture2D" uid="uid://0mw651622h01" path="res://assets/textures/wood-side.png" id="4_yyyxx"] +[ext_resource type="Texture2D" uid="uid://goygbpyqhych" path="res://assets/textures/leaves.png" id="5_ps55n"] + +[node name="QuickSlots" type="MarginContainer"] +anchors_preset = 7 +anchor_left = 0.5 +anchor_top = 1.0 +anchor_right = 0.5 +anchor_bottom = 1.0 +offset_left = -20.0 +offset_top = -40.0 +offset_right = 20.0 +grow_horizontal = 2 +grow_vertical = 0 +theme_override_constants/margin_left = 8 +theme_override_constants/margin_top = 8 +theme_override_constants/margin_right = 8 +theme_override_constants/margin_bottom = 8 + +[node name="GridContainer" type="GridContainer" parent="."] +layout_mode = 2 +theme_override_constants/h_separation = 8 +theme_override_constants/v_separation = 8 +columns = 4 + +[node name="Slot0" type="Panel" parent="GridContainer"] +custom_minimum_size = Vector2(64, 64) +layout_mode = 2 + +[node name="MarginContainer" type="MarginContainer" parent="GridContainer/Slot0"] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +theme_override_constants/margin_left = 4 +theme_override_constants/margin_top = 4 +theme_override_constants/margin_right = 4 +theme_override_constants/margin_bottom = 4 + +[node name="TextureRect" type="TextureRect" parent="GridContainer/Slot0/MarginContainer"] +texture_filter = 1 +layout_mode = 2 +texture = ExtResource("2_kotkb") + +[node name="Slot1" type="Panel" parent="GridContainer"] +custom_minimum_size = Vector2(64, 64) +layout_mode = 2 + +[node name="MarginContainer" type="MarginContainer" parent="GridContainer/Slot1"] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +theme_override_constants/margin_left = 4 +theme_override_constants/margin_top = 4 +theme_override_constants/margin_right = 4 +theme_override_constants/margin_bottom = 4 + +[node name="TextureRect" type="TextureRect" parent="GridContainer/Slot1/MarginContainer"] +texture_filter = 1 +layout_mode = 2 +texture = ExtResource("3_cqw2g") + +[node name="Slot2" type="Panel" parent="GridContainer"] +custom_minimum_size = Vector2(64, 64) +layout_mode = 2 + +[node name="MarginContainer" type="MarginContainer" parent="GridContainer/Slot2"] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +theme_override_constants/margin_left = 4 +theme_override_constants/margin_top = 4 +theme_override_constants/margin_right = 4 +theme_override_constants/margin_bottom = 4 + +[node name="TextureRect" type="TextureRect" parent="GridContainer/Slot2/MarginContainer"] +texture_filter = 1 +layout_mode = 2 +texture = ExtResource("4_yyyxx") + +[node name="Slot3" type="Panel" parent="GridContainer"] +custom_minimum_size = Vector2(64, 64) +layout_mode = 2 + +[node name="MarginContainer" type="MarginContainer" parent="GridContainer/Slot3"] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +theme_override_constants/margin_left = 4 +theme_override_constants/margin_top = 4 +theme_override_constants/margin_right = 4 +theme_override_constants/margin_bottom = 4 + +[node name="TextureRect" type="TextureRect" parent="GridContainer/Slot3/MarginContainer"] +texture_filter = 1 +layout_mode = 2 +texture = ExtResource("5_ps55n") diff --git a/scenes/ui/ui.gd b/scenes/ui/ui.gd index d213111..56e5f6a 100644 --- a/scenes/ui/ui.gd +++ b/scenes/ui/ui.gd @@ -4,6 +4,7 @@ extends CanvasLayer @onready var crosshair: CenterContainer = $Crosshair @onready var options_menu: MarginContainer = $OptionsMenu +@onready var quick_slots: MarginContainer = $QuickSlots @onready var waila: Waila = $Waila @@ -15,6 +16,7 @@ func _process(_delta: float) -> void: func toggle_options_menu() -> void: crosshair.visible = !options_menu.visible options_menu.visible = !options_menu.visible + quick_slots.visible = !options_menu.visible if options_menu.visible: waila.visible = false Input.mouse_mode = Input.MOUSE_MODE_VISIBLE diff --git a/scenes/ui/ui.tscn b/scenes/ui/ui.tscn index 5874af3..f200f20 100644 --- a/scenes/ui/ui.tscn +++ b/scenes/ui/ui.tscn @@ -1,8 +1,9 @@ -[gd_scene load_steps=4 format=3 uid="uid://c7fj7wla8bd70"] +[gd_scene load_steps=5 format=3 uid="uid://c7fj7wla8bd70"] [ext_resource type="Script" uid="uid://bslimr2y4lnvq" path="res://scenes/ui/ui.gd" id="1_aac20"] [ext_resource type="PackedScene" uid="uid://dvogu3djluqsn" path="res://scenes/ui/waila.tscn" id="1_u7n8c"] [ext_resource type="PackedScene" uid="uid://w6wtjosjn1qu" path="res://scenes/ui/options_menu.tscn" id="2_f5cxw"] +[ext_resource type="PackedScene" uid="uid://cbiygbgpfk220" path="res://scenes/ui/quick_slots.tscn" id="4_g5kmx"] [node name="UI" type="CanvasLayer"] script = ExtResource("1_aac20") @@ -29,6 +30,8 @@ mouse_filter = 2 [node name="OptionsMenu" parent="." instance=ExtResource("2_f5cxw")] visible = false +[node name="QuickSlots" parent="." instance=ExtResource("4_g5kmx")] + [connection signal="toggled" from="OptionsMenu/PanelContainer/MarginContainer/VBoxContainer/Waila/CheckButton" to="." method="_on_waila_toggled"] [connection signal="toggled" from="OptionsMenu/PanelContainer/MarginContainer/VBoxContainer/BlockHighlights/CheckButton" to="." method="_on_block_highlights_toggled"] [connection signal="pressed" from="OptionsMenu/PanelContainer/MarginContainer/CenterContainer/HBoxContainer/CloseButton" to="." method="_on_close_button_pressed"]