Browse Source

Adding quick slots (UI does not work yet)

pull/1/head
Ryan Reed 1 month ago
parent
commit
6936497026
9 changed files with 207 additions and 3 deletions
  1. +30
    -0
      project.godot
  2. +4
    -1
      root.tscn
  3. +4
    -1
      scenes/player/ray_cast_3d.gd
  4. +44
    -0
      scenes/quick_slots.gd
  5. +1
    -0
      scenes/quick_slots.gd.uid
  6. +6
    -0
      scenes/quick_slots.tscn
  7. +112
    -0
      scenes/ui/quick_slots.tscn
  8. +2
    -0
      scenes/ui/ui.gd
  9. +4
    -1
      scenes/ui/ui.tscn

+ 30
- 0
project.godot View File

@ -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]


+ 4
- 1
root.tscn View File

@ -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")]

+ 4
- 1
scenes/player/ray_cast_3d.gd View File

@ -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


+ 44
- 0
scenes/quick_slots.gd View File

@ -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)

+ 1
- 0
scenes/quick_slots.gd.uid View File

@ -0,0 +1 @@
uid://bcq6vexsmyeol

+ 6
- 0
scenes/quick_slots.tscn View File

@ -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")

+ 112
- 0
scenes/ui/quick_slots.tscn View File

@ -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")

+ 2
- 0
scenes/ui/ui.gd View File

@ -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


+ 4
- 1
scenes/ui/ui.tscn View File

@ -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"]


Loading…
Cancel
Save