item details and more ui layout
This commit is contained in:
parent
f5496c27df
commit
458912bbe1
4 changed files with 61 additions and 16 deletions
|
@ -1,10 +1,11 @@
|
|||
[gd_scene load_steps=6 format=3 uid="uid://bshvduqysqivm"]
|
||||
[gd_scene load_steps=7 format=3 uid="uid://bshvduqysqivm"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://ct5na682hxc6g" path="res://src/input_listener.gd" id="1_qw0r6"]
|
||||
[ext_resource type="Script" uid="uid://qvoqvonnxwfc" path="res://src/inventory_ui.gd" id="2_hj2ta"]
|
||||
[ext_resource type="Resource" uid="uid://bllq6ri54q3ne" path="res://resources/player_inventory.tres" id="3_ty45s"]
|
||||
[ext_resource type="Script" uid="uid://c62nslejr74jw" path="res://src/h_item_list.gd" id="4_yyk2a"]
|
||||
[ext_resource type="PackedScene" uid="uid://gn8k2ir47n1m" path="res://scenes/inventory_item.tscn" id="5_uae8j"]
|
||||
[ext_resource type="Script" uid="uid://dfvvqpgu8r5v6" path="res://src/item_details_ui.gd" id="6_uae8j"]
|
||||
|
||||
[node name="Control" type="Control"]
|
||||
layout_mode = 3
|
||||
|
@ -54,18 +55,45 @@ item_scene = ExtResource("5_uae8j")
|
|||
layout_mode = 2
|
||||
text = ">"
|
||||
|
||||
[node name="Details" type="HBoxContainer" parent="VBoxContainer"]
|
||||
[node name="Details" type="HBoxContainer" parent="VBoxContainer" node_paths=PackedStringArray("icon_image", "description_label")]
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 3
|
||||
script = ExtResource("6_uae8j")
|
||||
icon_image = NodePath("ItemDisplay/TextureRect")
|
||||
description_label = NodePath("ItemDescription/Label")
|
||||
|
||||
[node name="Status" type="VBoxContainer" parent="VBoxContainer/Details"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
|
||||
[node name="ItemDisplay" type="Control" parent="VBoxContainer/Details"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
|
||||
[node name="TextureRect" type="TextureRect" parent="VBoxContainer/Details/ItemDisplay"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
expand_mode = 5
|
||||
stretch_mode = 4
|
||||
|
||||
[node name="ItemDescription" type="Control" parent="VBoxContainer/Details"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
|
||||
[node name="Label" type="Label" parent="VBoxContainer/Details/ItemDescription"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
autowrap_mode = 2
|
||||
|
||||
[connection signal="pressed" from="." to="." method="show"]
|
||||
[connection signal="pressed" from="VBoxContainer/ItemNavigation/MoveLeft" to="VBoxContainer/ItemNavigation/HItemList" method="move_left"]
|
||||
[connection signal="selected" from="VBoxContainer/ItemNavigation/HItemList" to="VBoxContainer/Details" method="_on_updated"]
|
||||
[connection signal="pressed" from="VBoxContainer/ItemNavigation/MoveRight" to="VBoxContainer/ItemNavigation/HItemList" method="move_right"]
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
class_name HItemList extends HBoxContainer
|
||||
|
||||
signal selected(item: Option, index, int)
|
||||
|
||||
@export var item_scene: PackedScene
|
||||
@export var max_items: int = 4
|
||||
@export var buffered_items: int = 1
|
||||
|
@ -52,13 +54,8 @@ func _update_display():
|
|||
var item_option = _get_item(item_index_from_ring_buffer)
|
||||
bind_item.call(node, item_option)
|
||||
|
||||
#if item_option.is_none():
|
||||
# node.hide() # Hide if no item available
|
||||
#else:
|
||||
# if i >= buffered_items and i < (buffer_size - buffered_items):
|
||||
# node.show()
|
||||
# else:
|
||||
# node.hide()
|
||||
var selected_item = _get_item(indices[buffered_items])
|
||||
selected.emit(selected_item)
|
||||
|
||||
func add_item(item: Variant):
|
||||
items.append(item)
|
||||
|
|
23
godot/src/item_details_ui.gd
Normal file
23
godot/src/item_details_ui.gd
Normal file
|
@ -0,0 +1,23 @@
|
|||
class_name ItemDetailsUI extends HBoxContainer
|
||||
|
||||
@export var icon_image: TextureRect
|
||||
@export var description_label: Label
|
||||
|
||||
var _default_icon: Texture2D
|
||||
var _default_description: String
|
||||
|
||||
func _ready() -> void:
|
||||
_default_icon = icon_image.texture
|
||||
_default_description = description_label.text
|
||||
|
||||
func _set_default():
|
||||
icon_image.texture = _default_icon
|
||||
description_label.text = _default_description
|
||||
|
||||
func _on_updated(_item: Option):
|
||||
if _item.is_some():
|
||||
var item: Item = _item.unwrap()
|
||||
icon_image.texture = item.icon
|
||||
description_label.text = item.description
|
||||
else:
|
||||
_set_default()
|
|
@ -35,19 +35,16 @@ func set_offset(value: int) -> void:
|
|||
|
||||
var _index: int
|
||||
|
||||
var selected_index: int:
|
||||
var start_index: int:
|
||||
get: return _index
|
||||
set(value): set_selected(value)
|
||||
set(value): set_start_index(value)
|
||||
|
||||
func set_selected(value: int) -> void:
|
||||
func set_start_index(value: int) -> void:
|
||||
var previous = self.get_range()
|
||||
_index = self.index(value)
|
||||
var current = self.get_range()
|
||||
updated.emit(current, previous)
|
||||
|
||||
var start_index: int:
|
||||
get: return _index
|
||||
|
||||
var end_index: int:
|
||||
get: return start_index + capacity
|
||||
|
||||
|
@ -55,7 +52,7 @@ var end_index: int:
|
|||
func _init(source_size: int, capacity: int, start_index: int = 0, offset: int = 0) -> void:
|
||||
self.source_size = source_size
|
||||
self.capacity = capacity
|
||||
selected_index = start_index
|
||||
self.start_index = start_index
|
||||
self.offset = offset
|
||||
|
||||
func index(value: int) -> int:
|
||||
|
|
Loading…
Add table
Reference in a new issue