Skip to content

Commit

Permalink
item progress bar
Browse files Browse the repository at this point in the history
  • Loading branch information
AmitaiMazliah committed Nov 19, 2023
1 parent cf7fa33 commit fc1e69b
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 8 deletions.
45 changes: 40 additions & 5 deletions prefabs/ui/item_view.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,56 @@ custom_minimum_size = Vector2(150, 220)
size_flags_horizontal = 6
script = ExtResource("1_7wrph")

[node name="MarginContainer" type="MarginContainer" parent="."]
layout_mode = 2
offset_right = 150.0
offset_bottom = 220.0
[node name="Control" type="Control" parent="."]
layout_mode = 1
anchors_preset = 10
anchor_right = 1.0
offset_bottom = 200.0
grow_horizontal = 2

[node name="MarginContainer" type="MarginContainer" parent="Control"]
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 = 5
theme_override_constants/margin_top = 5
theme_override_constants/margin_right = 5
theme_override_constants/margin_bottom = 5

[node name="ItemIcon" type="TextureRect" parent="MarginContainer"]
[node name="ItemIcon" type="TextureRect" parent="Control/MarginContainer"]
custom_minimum_size = Vector2(0, 175)
layout_mode = 2
texture = ExtResource("2_h1hb8")

[node name="ProgressBar" type="ProgressBar" parent="."]
layout_mode = 1
anchors_preset = 12
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
offset_top = -20.0
grow_horizontal = 2
grow_vertical = 0
step = 1.0
value = 50.0
show_percentage = false

[node name="Label" type="Label" parent="ProgressBar"]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
text = "5/10"
horizontal_alignment = 1
vertical_alignment = 1

[node name="OptionsContainer" type="VBoxContainer" parent="."]
visible = false
z_index = 5
layout_mode = 1
anchors_preset = 12
Expand Down
10 changes: 7 additions & 3 deletions scripts/UI/item_slot_view.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ extends Button

class_name ItemSlotView

@onready var _item_icon: TextureRect = $MarginContainer/ItemIcon
@onready var _item_icon: TextureRect = $Control/MarginContainer/ItemIcon
@onready var _item_process_bar: ProgressBar = $ProgressBar
@onready var _item_process_bar_label: Label = $ProgressBar/Label
@onready var _options_container: VBoxContainer = $OptionsContainer
@onready var _upgrade_button: Button = $OptionsContainer/UpgradeButton
@onready var _info_button: Button = $OptionsContainer/InfoButton
Expand Down Expand Up @@ -32,11 +34,13 @@ func _on_selected_changed(selected: bool):

func _update_ui():
if _item:
_item_icon.texture = _item.equipment.sprite
_item_process_bar.max_value = _item.amount_to_upgrade
_item_process_bar.value = _item.amount
_item_process_bar_label.text = str(_item.amount) + "/" + str(_item.amount_to_upgrade)
if _item.can_upgrade():
_upgrade_button.show()
_info_button.hide()
else:
_upgrade_button.hide()
_info_button.show()
_item_icon.texture = _item.equipment.sprite
tooltip_text = _item.equipment.description
3 changes: 3 additions & 0 deletions scripts/player/player_equipment.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ class_name PlayerEquipment
var equipment: Equipment
var level: int
var amount: int
var amount_to_upgrade: int :
get:
return EquipmentData.amount_per_level.get(level + 1)

func _init(equipment: Equipment, level: int, amount: int):
self.equipment = equipment
Expand Down

0 comments on commit fc1e69b

Please sign in to comment.