Browse Source

Merge pull request 'Quick Slot Highlight' (#8) from quickslot-highlight into master

pull/9/head
Ryan Reed 1 month ago
parent
commit
cb99add99a
3 changed files with 30 additions and 3 deletions
  1. +4
    -0
      resources/inventory/quickslot-panel-highlight-stylebox.tres
  2. +23
    -2
      scenes/ui/quick_slots.gd
  3. +3
    -1
      scenes/ui/quick_slots.tscn

+ 4
- 0
resources/inventory/quickslot-panel-highlight-stylebox.tres View File

@ -0,0 +1,4 @@
[gd_resource type="StyleBoxFlat" format=3 uid="uid://dlaswvta2mvim"]
[resource]
bg_color = Color(0.686275, 0.658824, 0, 1)

+ 23
- 2
scenes/ui/quick_slots.gd View File

@ -2,15 +2,26 @@ class_name QuickSlots
extends Node
var _items: Array[String] = ["001", "005", "002", "003", "004"]
var _selected_item: int = 0
@export var highlight_theme: Resource
@onready var slots_container: GridContainer = $GridContainer
var _items: Array[String] = ["001", "005", "002", "003", "004"]
var _previous_selected_item: int = 0
var _selected_item: int = 0 :
set(new_item_index):
_previous_selected_item = _selected_item
_selected_item = new_item_index
func _init() -> void:
InventoryManager.next_quick_slot.connect(select_next_item.bind())
InventoryManager.previous_quick_slot.connect(select_previous_item.bind())
InventoryManager.select_quick_slot.connect(select_item_index.bind())
func _ready() -> void:
var current_slot: Panel = slots_container.get_child(_selected_item)
current_slot.set("theme_override_styles/panel", highlight_theme)
func _unhandled_input(event: InputEvent) -> void:
if event.is_action_pressed("quickslot0"):
_selected_item = 0
@ -34,12 +45,22 @@ func get_selected_item() -> String:
func select_item_index(slot_index: int) -> void:
_selected_item = slot_index
update_highlighted_slot()
InventoryManager.quick_slot_item_changed.emit(get_selected_item())
func select_previous_item() -> void:
_selected_item = clampi(_selected_item - 1, 0, _items.size() - 1)
update_highlighted_slot()
InventoryManager.quick_slot_item_changed.emit(get_selected_item())
func select_next_item() -> void:
_selected_item = clampi(_selected_item + 1, 0, _items.size() - 1)
update_highlighted_slot()
InventoryManager.quick_slot_item_changed.emit(get_selected_item())
func update_highlighted_slot() -> void:
var previous_slot: Panel = slots_container.get_child(_previous_selected_item)
var current_slot: Panel = slots_container.get_child(_selected_item)
previous_slot.set("theme_override_styles/panel", null)
current_slot.set("theme_override_styles/panel", highlight_theme)

+ 3
- 1
scenes/ui/quick_slots.tscn View File

@ -1,7 +1,8 @@
[gd_scene load_steps=7 format=3 uid="uid://cbiygbgpfk220"]
[gd_scene load_steps=8 format=3 uid="uid://cbiygbgpfk220"]
[ext_resource type="Script" uid="uid://bcq6vexsmyeol" path="res://scenes/ui/quick_slots.gd" id="1_cqw2g"]
[ext_resource type="Texture2D" uid="uid://li36txj7oweq" path="res://assets/textures/dirt.png" id="2_kotkb"]
[ext_resource type="StyleBox" uid="uid://dlaswvta2mvim" path="res://resources/inventory/quickslot-panel-highlight-stylebox.tres" id="2_ps55n"]
[ext_resource type="Texture2D" uid="uid://ct1iawpfkdf5l" path="res://assets/textures/stone.png" id="3_cqw2g"]
[ext_resource type="Texture2D" uid="uid://bgo4mb3atmbot" path="res://assets/textures/grass.png" id="3_yyyxx"]
[ext_resource type="Texture2D" uid="uid://0mw651622h01" path="res://assets/textures/wood.png" id="4_yyyxx"]
@ -23,6 +24,7 @@ theme_override_constants/margin_top = 8
theme_override_constants/margin_right = 8
theme_override_constants/margin_bottom = 8
script = ExtResource("1_cqw2g")
highlight_theme = ExtResource("2_ps55n")
[node name="GridContainer" type="GridContainer" parent="."]
layout_mode = 2


Loading…
Cancel
Save