Browse Source

wip: Initialize the item rects and add highlighting on mouse over

pull/24/head
Ryan Reed 3 weeks ago
parent
commit
f63cfb0ca8
4 changed files with 68 additions and 16 deletions
  1. +15
    -2
      scenes/ui/inventory/inventory.gd
  2. +14
    -3
      scenes/ui/inventory/inventory.tscn
  3. +21
    -3
      scenes/ui/inventory/item_rect.gd
  4. +18
    -8
      scenes/ui/inventory/item_rect.tscn

+ 15
- 2
scenes/ui/inventory/inventory.gd View File

@ -6,6 +6,11 @@ extends Control
@export var item_rect_scene: PackedScene
@export var grid_container: GridContainer
@export var highlight_theme: Resource
var items: Array[Node] = []
var selected_item: int = 0
func _input(event: InputEvent) -> void:
if event.is_action_pressed("open_inventory"):
@ -14,9 +19,15 @@ func _input(event: InputEvent) -> void:
func _ready() -> void:
InventoryManager.item_picked_up.connect(add_item)
InventoryManager.item_dropped.connect(subtract_item)
for item: InventoryItemRect in grid_container.get_children():
item.queue_free()
for item_resource: DBItemResource in inventory_resource.inventory:
add_item(item_resource)
refresh_items()
func add_item(item_resource: DBItemResource, amount: int = 1) -> void:
var item_rect: InventoryItemRect = find_item_rect(item_resource)
@ -29,8 +40,7 @@ func add_item(item_resource: DBItemResource, amount: int = 1) -> void:
else:
item_rect = item_rect_scene.instantiate()
grid_container.add_child(item_rect)
item_rect.item_resource = item_resource
item_rect.update_rect()
item_rect.init(item_resource, highlight_theme)
func find_item_rect(item_resource: DBItemResource) -> InventoryItemRect:
var rect: InventoryItemRect = null
@ -56,6 +66,9 @@ func subtract_item(item_resource: DBItemResource) -> void:
else:
push_error("Attempting to subtract amount (" + str(item_resource.amount) + " from nonexistent inventory item (" + str(item_resource.name) + ")")
func refresh_items() -> void:
items = grid_container.get_children()
func toggle_inventory() -> void:
visible = not visible


+ 14
- 3
scenes/ui/inventory/inventory.tscn View File

@ -1,8 +1,10 @@
[gd_scene load_steps=4 format=3 uid="uid://dcr25y1lw4wjp"]
[gd_scene load_steps=6 format=3 uid="uid://dcr25y1lw4wjp"]
[ext_resource type="Script" uid="uid://dybecq130mxhn" path="res://scenes/ui/inventory/inventory.gd" id="1_s6ek7"]
[ext_resource type="Resource" uid="uid://cnpw7y1csu774" path="res://resources/inventory/player_inventory_empty.tres" id="2_avmd0"]
[ext_resource type="Resource" uid="uid://blfp6tiir282o" path="res://resources/inventory/player_inventory_testing.tres" id="2_pefhr"]
[ext_resource type="PackedScene" uid="uid://boueuk2hnfvg" path="res://scenes/ui/inventory/item_rect.tscn" id="3_xeaml"]
[ext_resource type="StyleBox" uid="uid://dlaswvta2mvim" path="res://resources/inventory/quickslot-panel-highlight-stylebox.tres" id="4_8ndef"]
[ext_resource type="Resource" uid="uid://b50yyok6ddux4" path="res://resources/blocks/005_grass.tres" id="4_lobmi"]
[node name="Inventory" type="Control" node_paths=PackedStringArray("grid_container")]
process_mode = 3
@ -20,9 +22,10 @@ offset_bottom = 200.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_s6ek7")
inventory_resource = ExtResource("2_avmd0")
inventory_resource = ExtResource("2_pefhr")
item_rect_scene = ExtResource("3_xeaml")
grid_container = NodePath("Background/MarginContainer/VBoxContainer/GridContainer")
highlight_theme = ExtResource("4_8ndef")
[node name="Background" type="Panel" parent="."]
layout_mode = 1
@ -58,3 +61,11 @@ size_flags_vertical = 3
theme_override_constants/h_separation = 20
theme_override_constants/v_separation = 20
columns = 10
[node name="ItemRect" parent="Background/MarginContainer/VBoxContainer/GridContainer" instance=ExtResource("3_xeaml")]
layout_mode = 2
item_resource = ExtResource("4_lobmi")
[node name="ItemRect2" parent="Background/MarginContainer/VBoxContainer/GridContainer" instance=ExtResource("3_xeaml")]
layout_mode = 2
item_resource = ExtResource("4_lobmi")

+ 21
- 3
scenes/ui/inventory/item_rect.gd View File

@ -4,16 +4,34 @@ extends Panel
@export var amount_label: Label
@export var item_resource: DBItemResource
@export var item_texture: TextureRect
@export var item_texture: TextureButton
var highlight_theme: Resource
func init(_item_resource: DBItemResource, _highlight_theme: Resource) -> void:
item_texture.mouse_entered.connect(_on_mouse_entered)
item_texture.mouse_exited.connect(_on_mouse_exited)
highlight_theme = _highlight_theme
item_resource = _item_resource
update_rect()
func update_rect() -> void:
item_texture.texture = load(item_resource.item_texture)
item_texture.texture_normal = load(item_resource.item_texture)
amount_label.text = "x" + str(item_resource.amount)
tooltip_text = item_resource.name + "\n" + item_resource.description
item_texture.tooltip_text = item_resource.name + "\n" + item_resource.description
func on_stack_full(is_full: bool) -> void:
if is_full:
amount_label.add_theme_color_override("font_color", Color(1, 0, 0))
else:
amount_label.add_theme_color_override("font_color", Color(1, 1, 1))
func _on_mouse_entered() -> void:
set("theme_override_styles/panel", highlight_theme)
func _on_mouse_exited() -> void:
set("theme_override_styles/panel", null)

+ 18
- 8
scenes/ui/inventory/item_rect.tscn View File

@ -8,21 +8,31 @@ outline_size = 3
outline_color = Color(0, 0, 0, 1)
[node name="ItemRect" type="Panel" node_paths=PackedStringArray("amount_label", "item_texture")]
custom_minimum_size = Vector2(64, 64)
custom_minimum_size = Vector2(72, 72)
offset_right = 64.0
offset_bottom = 64.0
script = ExtResource("1_oderi")
amount_label = NodePath("AmountLabel")
item_texture = NodePath("ItemTexture")
item_texture = NodePath("TextureButton")
metadata/_edit_use_anchors_ = true
[node name="ItemTexture" type="TextureRect" parent="."]
[node name="TextureButton" type="TextureButton" parent="."]
texture_filter = 1
layout_mode = 0
offset_right = 64.0
offset_bottom = 64.0
texture = ExtResource("1_o0kom")
expand_mode = 1
custom_minimum_size = Vector2(64, 64)
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -32.0
offset_top = -32.0
offset_right = 32.0
offset_bottom = 32.0
grow_horizontal = 2
grow_vertical = 2
texture_normal = ExtResource("1_o0kom")
ignore_texture_size = true
stretch_mode = 4
[node name="AmountLabel" type="Label" parent="."]


Loading…
Cancel
Save