Skip to content

Commit

Permalink
~72 basics done (meta upgrades)
Browse files Browse the repository at this point in the history
  • Loading branch information
sh-cho committed Jun 15, 2024
1 parent 58b69bb commit 8765034
Show file tree
Hide file tree
Showing 14 changed files with 451 additions and 11 deletions.
3 changes: 2 additions & 1 deletion resources/meta_upgrade/experience_gain.tres
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
[gd_resource type="Resource" load_steps=2 format=3 uid="uid://b1j6h4bippirj"]
[gd_resource type="Resource" script_class="MetaUpgrade" load_steps=2 format=3 uid="uid://b1j6h4bippirj"]

[ext_resource type="Script" path="res://resources/meta_upgrade/meta_upgrade.gd" id="1_6epyd"]

[resource]
script = ExtResource("1_6epyd")
id = "experience_gain"
max_quantity = 1
experience_cost = 100
title = "Increase Experience"
description = "Increases experience drop chance by 10%."
1 change: 1 addition & 0 deletions resources/meta_upgrade/meta_upgrade.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ class_name MetaUpgrade

@export var id: String
@export var max_quantity: int = 1
@export var experience_cost: int = 10
@export var title: String
@export_multiline var description: String
47 changes: 46 additions & 1 deletion resources/themes/theme.tres
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_resource type="Theme" load_steps=16 format=3 uid="uid://c3hhobt5yor42"]
[gd_resource type="Theme" load_steps=21 format=3 uid="uid://c3hhobt5yor42"]

[ext_resource type="FontFile" uid="uid://ba3f2bejkjtdg" path="res://resources/themes/Rockboxcond12.ttf" id="1_fxvgl"]
[ext_resource type="Texture2D" uid="uid://m1p3h77wdeke" path="res://assets/ui/ui.png" id="1_vusi2"]
Expand All @@ -15,6 +15,14 @@ texture_margin_right = 1.0
texture_margin_bottom = 1.0
region_rect = Rect2(18, 2, 12, 12)

[sub_resource type="StyleBoxTexture" id="StyleBoxTexture_lwkpy"]
texture = ExtResource("1_vusi2")
texture_margin_left = 1.0
texture_margin_top = 1.0
texture_margin_right = 1.0
texture_margin_bottom = 1.0
region_rect = Rect2(18, 2, 12, 12)

[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_ju7t5"]

[sub_resource type="StyleBoxTexture" id="StyleBoxTexture_ipsqo"]
Expand Down Expand Up @@ -89,6 +97,37 @@ border_width_right = 2
border_width_bottom = 2
border_color = Color(0.247059, 0.14902, 0.192157, 1)

[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_0mxql"]
bg_color = Color(0.996078, 0.682353, 0.203922, 1)
border_width_left = 2
border_width_top = 2
border_width_right = 2
border_width_bottom = 2
border_color = Color(0.8, 0.8, 0.8, 0)

[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_r3ucr"]
bg_color = Color(0.996078, 0.682353, 0.203922, 1)
border_width_left = 2
border_width_top = 2
border_width_right = 2
border_width_bottom = 2
border_color = Color(0.8, 0.8, 0.8, 0)

[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_uogwr"]
bg_color = Color(0.996078, 0.682353, 0.203922, 1)
border_width_left = 2
border_width_top = 2
border_width_right = 2
border_width_bottom = 2
border_color = Color(0.8, 0.8, 0.8, 0)

[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_q7anq"]
content_margin_left = 4.0
content_margin_top = 0.0
content_margin_right = 4.0
content_margin_bottom = 0.0
bg_color = Color(0.247059, 0.14902, 0.192157, 1)

[resource]
default_font = ExtResource("1_fxvgl")
default_font_size = 16
Expand All @@ -101,9 +140,11 @@ BlueOutlineLabel/constants/outline_size = 8
BlueOutlineLabel/constants/shadow_offset_x = 0
BlueOutlineLabel/constants/shadow_offset_y = 0
Button/colors/font_color = Color(0.247059, 0.14902, 0.192157, 1)
Button/colors/font_disabled_color = Color(0.545098, 0.607843, 0.705882, 1)
Button/colors/font_focus_color = Color(0.247059, 0.14902, 0.192157, 1)
Button/colors/font_hover_color = Color(0.741176, 0.423529, 0.290196, 1)
Button/colors/font_pressed_color = Color(0.247059, 0.14902, 0.192157, 1)
Button/styles/disabled = SubResource("StyleBoxTexture_lwkpy")
Button/styles/focus = SubResource("StyleBoxEmpty_ju7t5")
Button/styles/hover = SubResource("StyleBoxTexture_ipsqo")
Button/styles/normal = SubResource("StyleBoxTexture_ohc1h")
Expand All @@ -117,3 +158,7 @@ Label/constants/line_spacing = 0
PanelContainer/styles/panel = SubResource("StyleBoxTexture_hjilj")
ProgressBar/styles/background = SubResource("StyleBoxFlat_exix6")
ProgressBar/styles/fill = SubResource("StyleBoxFlat_fbfos")
VScrollBar/styles/grabber = SubResource("StyleBoxFlat_0mxql")
VScrollBar/styles/grabber_highlight = SubResource("StyleBoxFlat_r3ucr")
VScrollBar/styles/grabber_pressed = SubResource("StyleBoxFlat_uogwr")
VScrollBar/styles/scroll = SubResource("StyleBoxFlat_q7anq")
7 changes: 7 additions & 0 deletions scenes/autoload/meta_progression.gd
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ func add_meta_upgrade(upgrade: MetaUpgrade):
}

save_data["meta_upgrades"][upgrade.id]["quantity"] += 1
save()


func get_upgrade_count(upgrade_id: String) -> int:
if save_data["meta_upgrades"].has(upgrade_id):
return save_data["meta_upgrades"][upgrade_id]["quantity"]
return 0


func on_experience_collected(number: float):
Expand Down
6 changes: 6 additions & 0 deletions scenes/autoload/screen_transition.gd
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,9 @@ func transition():
$AnimationPlayer.play("default")
await $AnimationPlayer.animation_finished
rect.visible = false


func transition_to_scene(scene_path: String):
transition()
await transitioned_halfway
get_tree().change_scene_to_file(scene_path)
7 changes: 6 additions & 1 deletion scenes/component/vial_drop_component.gd
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ func _ready():


func on_died():
if randf() > drop_rate:
var adjusted_drop_rate = drop_rate
var experience_gain_upgrade_count = MetaProgression.get_upgrade_count("experience_gain")
if experience_gain_upgrade_count > 0:
adjusted_drop_rate += experience_gain_upgrade_count * 0.1

if randf() > adjusted_drop_rate:
return

if vial_scene == null:
Expand Down
10 changes: 6 additions & 4 deletions scenes/ui/end_screen.gd
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func _ready():
.set_trans(Tween.TRANS_BACK)

get_tree().paused = true
%RestartButton.pressed.connect(on_restart_button_pressed)
%ContinueButton.pressed.connect(on_continue_button_pressed)
%QuitButton.pressed.connect(on_quit_button_pressed)


Expand All @@ -32,13 +32,15 @@ func play_jingle(defeat: bool = false):
$VictoryStreamPlayer.play()


func on_restart_button_pressed():
func on_continue_button_pressed():
ScreenTransition.transition()
await ScreenTransition.transitioned_halfway

get_tree().paused = false
get_tree().change_scene_to_file("res://scenes/main/main.tscn")
get_tree().change_scene_to_file("res://scenes/ui/meta_menu.tscn")


func on_quit_button_pressed():
get_tree().quit()
ScreenTransition.transition_to_scene("res://scenes/ui/main_menu.tscn")
await ScreenTransition.transitioned_halfway
get_tree().paused = false
6 changes: 3 additions & 3 deletions scenes/ui/end_screen.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,12 @@ text = "You won!"
[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer/PanelContainer/MarginContainer/VBoxContainer"]
layout_mode = 2

[node name="RestartButton" parent="MarginContainer/PanelContainer/MarginContainer/VBoxContainer/VBoxContainer" instance=ExtResource("2_4hyb7")]
[node name="ContinueButton" parent="MarginContainer/PanelContainer/MarginContainer/VBoxContainer/VBoxContainer" instance=ExtResource("2_4hyb7")]
unique_name_in_owner = true
layout_mode = 2
text = "Restart"
text = "Continue"

[node name="QuitButton" parent="MarginContainer/PanelContainer/MarginContainer/VBoxContainer/VBoxContainer" instance=ExtResource("2_4hyb7")]
unique_name_in_owner = true
layout_mode = 2
text = "Quit"
text = "Quit to Menu"
8 changes: 7 additions & 1 deletion scenes/ui/main_menu.gd
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,23 @@ var options_scene = preload("res://scenes/ui/options_menu.tscn")

func _ready():
%PlayButton.pressed.connect(on_play_pressed)
%UpgradesButton.pressed.connect(on_upgrades_pressed)
%OptionsButton.pressed.connect(on_options_pressed)
%QuitButton.pressed.connect(on_quit_pressed)


func on_play_pressed():
ScreenTransition.transition()
await ScreenTransition.transitioned_halfway

get_tree().change_scene_to_file("res://scenes/main/main.tscn")


func on_upgrades_pressed():
ScreenTransition.transition()
await ScreenTransition.transitioned_halfway
get_tree().change_scene_to_file("res://scenes/ui/meta_menu.tscn")


func on_options_pressed():
ScreenTransition.transition()
await ScreenTransition.transitioned_halfway
Expand Down
5 changes: 5 additions & 0 deletions scenes/ui/main_menu.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ unique_name_in_owner = true
layout_mode = 2
text = "Play"

[node name="UpgradesButton" parent="MarginContainer/PanelContainer/MarginContainer/VBoxContainer" instance=ExtResource("2_8jljl")]
unique_name_in_owner = true
layout_mode = 2
text = "Upgrades"

[node name="OptionsButton" parent="MarginContainer/PanelContainer/MarginContainer/VBoxContainer" instance=ExtResource("2_8jljl")]
unique_name_in_owner = true
layout_mode = 2
Expand Down
26 changes: 26 additions & 0 deletions scenes/ui/meta_menu.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
extends CanvasLayer
class_name MetaMenu

@export var upgrades: Array[MetaUpgrade] = []

@onready var grid_container: GridContainer = %GridContainer
@onready var back_button: Button = %BackButton

var meta_upgrade_card_scene = preload("res://scenes/ui/meta_upgrade_card.tscn")


func _ready():
back_button.pressed.connect(on_back_pressed)

# remove debug childrens
for child in grid_container.get_children():
child.queue_free()

for u in upgrades:
var meta_upgrade_card_instance = meta_upgrade_card_scene.instantiate() as MetaUpgradeCard
grid_container.add_child(meta_upgrade_card_instance)
meta_upgrade_card_instance.set_meta_upgrade(u)


func on_back_pressed():
ScreenTransition.transition_to_scene("res://scenes/ui/main_menu.tscn")
69 changes: 69 additions & 0 deletions scenes/ui/meta_menu.tscn

Large diffs are not rendered by default.

54 changes: 54 additions & 0 deletions scenes/ui/meta_upgrade_card.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
extends PanelContainer
class_name MetaUpgradeCard

@onready var name_label: Label = %NameLabel
@onready var description_label: Label = %DescriptionLabel
@onready var progress_bar: ProgressBar = %ProgressBar
@onready var purchase_button: Button = %PurchaseButton
@onready var progress_label: Label = %ProgressLabel
@onready var count_label: Label = %CountLabel

var upgrade: MetaUpgrade


func _ready():
purchase_button.pressed.connect(on_purchase_pressed)


func set_meta_upgrade(upgrade: MetaUpgrade) -> void:
self.upgrade = upgrade
name_label.text = upgrade.title
description_label.text = upgrade.description
update_progress()


func update_progress():
var current_quantity := 0
if MetaProgression.save_data["meta_upgrades"].has(upgrade.id):
current_quantity = MetaProgression.save_data["meta_upgrades"][upgrade.id]["quantity"]

var is_maxed: bool = current_quantity >= upgrade.max_quantity
var currency = MetaProgression.save_data["meta_upgrade_currency"]
var percent = currency / upgrade.experience_cost
percent = min(percent, 1.0)
progress_bar.value = percent
purchase_button.disabled = percent < 1 || is_maxed
if is_maxed:
purchase_button.text = "Max"

progress_label.text = "%d/%d" % [currency, upgrade.experience_cost]
count_label.text = "x%d" % current_quantity


func select_card():
$AnimationPlayer.play("selected")


func on_purchase_pressed():
if upgrade == null:
return
MetaProgression.add_meta_upgrade(upgrade)
MetaProgression.save_data["meta_upgrade_currency"] -= upgrade.experience_cost
MetaProgression.save()
get_tree().call_group("meta_upgrade_card", "update_progress")
$AnimationPlayer.play("selected")
Loading

0 comments on commit 8765034

Please sign in to comment.