1
Fork 0
mirror of https://github.com/Steffo99/swear-jar.git synced 2024-11-25 17:14:20 +00:00
swear-jar/interface/purchasable_item.gd

96 lines
2.2 KiB
GDScript3
Raw Normal View History

2023-10-01 12:39:16 +00:00
extends Panel
class_name PurchasableItem
## Icon of the item that can be purchased.
@export var item_icon: Texture2D:
get:
return item_icon
set(value):
item_icon = value
$Contents/Header/IconRect.texture = item_icon
2023-10-01 12:39:16 +00:00
## Name of the item that can be purchased.
@export var item_name: String:
get:
return item_name
set(value):
item_name = value
$Contents/Header/NameLabel.text = value
## Description of the item that can be purchased.
@export var item_description: String:
get:
return item_description
set(value):
item_description = value
2023-10-01 16:18:00 +00:00
$Contents/Description/DescriptionLabel.text = value
2023-10-01 12:39:16 +00:00
## Text to be displayed on the cost label of the item.
@export var item_cost_text: String:
get:
return item_cost_text
set(value):
item_cost_text = value
$Contents/Action/CostLabel.text = value
## Collectible type of the item required to buy the item.
@export var item_cost_type: StringName
## Amount of items of the given type to collect to buy the item.
@export var item_cost_goal: int
## Whether the player can click or not the Buy button.
##
## Used to prevent two items from getting bought at the same time.
2023-10-01 12:43:38 +00:00
@export var can_buy: bool = true:
2023-10-01 12:39:16 +00:00
get:
return can_buy
set(value):
can_buy = value
$Contents/Action/BuyButton.disabled = not (can_buy && has_unlocked)
## Whether the player has unlocked this item for purchase.
##
## Used to force the player to follow the tech tree.
@export var has_unlocked: bool = true:
get:
return has_unlocked
set(value):
has_unlocked = value
$Contents/Action/BuyButton.disabled = not (can_buy && has_unlocked)
2023-10-01 12:39:16 +00:00
## Whether the player is currently buying this item.
##
## Used to cancel the purchase.
var is_buying: bool:
get:
return is_buying
set(value):
is_buying = value
2023-10-01 16:18:00 +00:00
$Contents/Action/BuyButton.text = "Undo" if value else "Buy"
2023-10-01 12:39:16 +00:00
## Emitted when a purchase has started.
signal purchase_begin
## Emitted when a purchase is cancelled.
signal purchase_cancel
## Emitted when a purchase is completed.
##
## Emitted by complete_purchase().
signal purchase_success
func _on_buy_button_pressed():
if is_buying:
is_buying = false
purchase_cancel.emit()
else:
is_buying = true
purchase_begin.emit()
func complete_purchase():
is_buying = false
purchase_success.emit()