1
Fork 0
mirror of https://github.com/Steffo99/swear-jar.git synced 2024-11-22 23:54:21 +00:00
swear-jar/interface/purchasable_item.gd

115 lines
2.9 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
2023-10-02 17:19:13 +00:00
## If this is a converter, the scene to instantiate.
@export var item_scene: PackedScene
2023-10-01 12:39:16 +00:00
## 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
2023-10-02 03:31:31 +00:00
$Contents/Action/BuyButton.disabled = not (has_bought or (can_buy and 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
2023-10-02 03:31:31 +00:00
$Contents/Action/BuyButton.disabled = not (has_bought or (can_buy and has_unlocked))
$Contents/Action/BuyButton.text = "Buy" if value else "Lock"
2023-10-01 12:39:16 +00:00
## Whether the player is currently buying this item.
##
## Used to cancel the purchase.
2023-10-02 03:31:31 +00:00
var is_buying: bool = false:
2023-10-01 12:39:16 +00:00
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
2023-10-02 03:31:31 +00:00
## Whether this item can be bought one or infinite times.
@export var one_shot: bool
## Whether the player has already bought this item.
##
## Always false if one_shot is true.
var has_bought: bool:
get:
return has_bought
set(value):
has_bought = value
$Contents/Action/BuyButton.disabled = (has_bought or (can_buy and has_unlocked))
$Contents/Action/BuyButton.add_theme_color_override("font_color", Color.GREEN)
$Contents/Action/BuyButton.text = "Buy" if value else "Own"
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()