Added upgrade system
This commit is contained in:
74
PermUpgrade/PermUpgrade.gd
Normal file
74
PermUpgrade/PermUpgrade.gd
Normal file
@@ -0,0 +1,74 @@
|
||||
extends PanelContainer
|
||||
|
||||
class_name PermUpgrade
|
||||
|
||||
@export var Name : String = ""
|
||||
@export var GlobalVariable : String = ""
|
||||
@export var BaseCost : int = 10
|
||||
|
||||
@onready var Level1 = $Container/Level1
|
||||
@onready var Level2 = $Container/Level2
|
||||
@onready var Level3 = $Container/Level3
|
||||
@onready var Level4 = $Container/Level4
|
||||
@onready var Level5 = $Container/Level5
|
||||
@onready var NameNode = $Container/Name
|
||||
@onready var StatusNode = $Container/Status
|
||||
@onready var BuyButton = $Container/Cost
|
||||
|
||||
var cost = BaseCost
|
||||
|
||||
func _ready() -> void:
|
||||
update()
|
||||
EventBus.upgrade_tokens_updated.connect(_on_upgrade_tokens_updated)
|
||||
|
||||
|
||||
func update() -> void:
|
||||
cost = BaseCost
|
||||
var qty = Global.get(GlobalVariable)
|
||||
|
||||
var inactive : Color = Color.DARK_SLATE_GRAY
|
||||
|
||||
|
||||
if qty < 1:
|
||||
Level1.modulate = inactive
|
||||
else:
|
||||
Level1.modulate = Color.ROYAL_BLUE
|
||||
cost *= 2
|
||||
if qty < 2:
|
||||
Level2.modulate = inactive
|
||||
else:
|
||||
cost *= 2
|
||||
Level2.modulate = Color.GREEN
|
||||
if qty < 3:
|
||||
Level3.modulate = inactive
|
||||
else:
|
||||
cost *= 2
|
||||
Level3.modulate = Color.RED
|
||||
if qty < 4:
|
||||
Level4.modulate = inactive
|
||||
else:
|
||||
cost *= 2
|
||||
Level4.modulate = Color.SILVER
|
||||
if qty < 5:
|
||||
Level5.modulate = inactive
|
||||
else:
|
||||
cost = -1
|
||||
Level5.modulate = Color.GOLD
|
||||
BuyButton.text = "MAX"
|
||||
|
||||
NameNode.text = Name
|
||||
StatusNode.text = Global.call("format_" + GlobalVariable)
|
||||
if not cost == -1:
|
||||
BuyButton.text = "%d" % cost
|
||||
|
||||
BuyButton.disabled = (Global.upgrade_tokens < cost) or (cost == -1)
|
||||
|
||||
func _on_cost_pressed() -> void:
|
||||
var now = Global.get(GlobalVariable)
|
||||
if now < 5:
|
||||
Global.set(GlobalVariable, now + 1)
|
||||
Global.upgrade_tokens -= cost
|
||||
pass # Replace with function body.
|
||||
|
||||
func _on_upgrade_tokens_updated(qty : int) -> void:
|
||||
update()
|
||||
83
PermUpgrade/PermUpgrade.tscn
Normal file
83
PermUpgrade/PermUpgrade.tscn
Normal file
@@ -0,0 +1,83 @@
|
||||
[gd_scene load_steps=5 format=3 uid="uid://bdhok2nkoirl0"]
|
||||
|
||||
[ext_resource type="Script" path="res://PermUpgrade/PermUpgrade.gd" id="1_g7x2d"]
|
||||
[ext_resource type="Theme" uid="uid://cfvww0geatnnk" path="res://MainTheme.tres" id="2_ie5gk"]
|
||||
[ext_resource type="Texture2D" uid="uid://ct1ksbbjc61lr" path="res://Brick/ShinyBrick.png" id="3_cpl7n"]
|
||||
[ext_resource type="Texture2D" uid="uid://cipjurqgguse7" path="res://Brick/BaseBrick.png" id="4_wqhv2"]
|
||||
|
||||
[node name="PermUpgrade" type="PanelContainer"]
|
||||
offset_right = 128.0
|
||||
offset_bottom = 26.0
|
||||
script = ExtResource("1_g7x2d")
|
||||
|
||||
[node name="Container" type="VBoxContainer" parent="."]
|
||||
custom_minimum_size = Vector2(128, 0)
|
||||
layout_mode = 2
|
||||
theme = ExtResource("2_ie5gk")
|
||||
theme_type_variation = &"UpgradePanel"
|
||||
|
||||
[node name="Name" type="Label" parent="Container"]
|
||||
layout_mode = 2
|
||||
theme = ExtResource("2_ie5gk")
|
||||
text = "Lives"
|
||||
horizontal_alignment = 1
|
||||
vertical_alignment = 1
|
||||
|
||||
[node name="Status" type="Label" parent="Container"]
|
||||
layout_mode = 2
|
||||
theme = ExtResource("2_ie5gk")
|
||||
text = "3"
|
||||
horizontal_alignment = 1
|
||||
vertical_alignment = 1
|
||||
|
||||
[node name="Level5" type="TextureRect" parent="Container"]
|
||||
modulate = Color(1, 0.843137, 0, 1)
|
||||
custom_minimum_size = Vector2(32, 16)
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 4
|
||||
size_flags_vertical = 0
|
||||
texture = ExtResource("3_cpl7n")
|
||||
stretch_mode = 2
|
||||
|
||||
[node name="Level4" type="TextureRect" parent="Container"]
|
||||
modulate = Color(0.752941, 0.752941, 0.752941, 1)
|
||||
custom_minimum_size = Vector2(32, 16)
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 4
|
||||
size_flags_vertical = 0
|
||||
texture = ExtResource("3_cpl7n")
|
||||
stretch_mode = 2
|
||||
|
||||
[node name="Level3" type="TextureRect" parent="Container"]
|
||||
modulate = Color(1, 0, 0, 1)
|
||||
custom_minimum_size = Vector2(32, 16)
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 4
|
||||
size_flags_vertical = 0
|
||||
texture = ExtResource("4_wqhv2")
|
||||
stretch_mode = 2
|
||||
|
||||
[node name="Level2" type="TextureRect" parent="Container"]
|
||||
modulate = Color(0.254902, 0.411765, 0.882353, 1)
|
||||
custom_minimum_size = Vector2(32, 16)
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 4
|
||||
size_flags_vertical = 0
|
||||
texture = ExtResource("4_wqhv2")
|
||||
stretch_mode = 2
|
||||
|
||||
[node name="Level1" type="TextureRect" parent="Container"]
|
||||
modulate = Color(0, 0.74902, 0, 1)
|
||||
custom_minimum_size = Vector2(32, 16)
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 4
|
||||
size_flags_vertical = 0
|
||||
texture = ExtResource("4_wqhv2")
|
||||
stretch_mode = 2
|
||||
|
||||
[node name="Cost" type="Button" parent="Container"]
|
||||
layout_mode = 2
|
||||
theme = ExtResource("2_ie5gk")
|
||||
text = "10"
|
||||
|
||||
[connection signal="pressed" from="Container/Cost" to="." method="_on_cost_pressed"]
|
||||
Reference in New Issue
Block a user