Skip to content

Commit

Permalink
feat: working shop
Browse files Browse the repository at this point in the history
  • Loading branch information
SummationX committed Feb 22, 2025
1 parent 923a0c8 commit 72ad291
Show file tree
Hide file tree
Showing 3 changed files with 207 additions and 79 deletions.
52 changes: 43 additions & 9 deletions apps/gamejam/brackeys/13/scenes/shop/shop.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,26 @@ script = ExtResource("1_3omsn")

[node name="HBoxContainer" type="HBoxContainer" parent="."]
layout_mode = 0
offset_left = 81.0
offset_left = 32.0
offset_top = 27.0
offset_right = 1071.0
offset_bottom = 104.0
theme_override_constants/separation = 105

[node name="Label" type="Label" parent="HBoxContainer"]
[node name="ResourcePanel" type="TextureRect" parent="HBoxContainer"]
layout_mode = 2
size_flags_horizontal = 3
theme_override_font_sizes/font_size = 56
theme_override_styles/normal = SubResource("StyleBoxTexture_mr6sy")
horizontal_alignment = 1
size_flags_stretch_ratio = 1.86
texture = ExtResource("1_x5466")

[node name="Label" type="Label" parent="HBoxContainer/ResourcePanel"]
layout_mode = 0
offset_left = 10.0
offset_top = 6.0
offset_right = 443.0
offset_bottom = 69.0
horizontal_alignment = 3
vertical_alignment = 3

[node name="ShopTitle" type="Label" parent="HBoxContainer"]
layout_mode = 2
Expand All @@ -67,10 +75,10 @@ horizontal_alignment = 1

[node name="Button" type="Button" parent="HBoxContainer/Label3"]
layout_mode = 0
offset_left = 7.0
offset_top = 4.0
offset_right = 322.0
offset_bottom = 70.0
offset_left = 18.0
offset_top = 8.0
offset_right = 234.0
offset_bottom = 74.0
theme = ExtResource("5_lsrhg")
theme_type_variation = &"SpaceBar"

Expand Down Expand Up @@ -120,6 +128,22 @@ offset_bottom = 224.0
text = "Left Right"
horizontal_alignment = 3

[node name="GreenLight" type="TextureRect" parent="MainBG/CenterScreen"]
layout_mode = 0
offset_left = 191.0
offset_top = 302.0
offset_right = 231.0
offset_bottom = 342.0
texture = ExtResource("6_75t5l")

[node name="RedLight" type="TextureRect" parent="MainBG/CenterScreen"]
layout_mode = 0
offset_left = 148.0
offset_top = 302.0
offset_right = 188.0
offset_bottom = 342.0
texture = ExtResource("9_f5tfu")

[node name="LeftPanel" type="TextureRect" parent="MainBG"]
layout_mode = 0
offset_left = 20.0
Expand Down Expand Up @@ -211,6 +235,7 @@ theme_type_variation = &"RightButton"
[node name="Button2" type="Button" parent="MainBG/LeftButtons/VBoxContainer"]
layout_mode = 2
size_flags_vertical = 3
theme = ExtResource("5_lsrhg")
theme_type_variation = &"RightButton"

[node name="Button3" type="Button" parent="MainBG/LeftButtons/VBoxContainer"]
Expand Down Expand Up @@ -269,6 +294,15 @@ offset_right = 1034.0
offset_bottom = 449.0
texture = ExtResource("3_pd5pr")

[node name="Label" type="Label" parent="MainBG/NonInteractable/BottomScreen"]
layout_mode = 0
offset_left = 47.0
offset_top = 5.0
offset_right = 949.0
offset_bottom = 76.0
horizontal_alignment = 3
vertical_alignment = 1

[node name="VSlider" type="VSlider" parent="MainBG/NonInteractable"]
layout_mode = 0
offset_left = 901.0
Expand Down
2 changes: 2 additions & 0 deletions apps/gamejam/brackeys/13/scripts/global.gd
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,10 @@ func get_starship_stat(stat_name: String) -> float:

func apply_starship_bonus(stat_name: String, bonus: float):
if not base_starship_stats.has(stat_name):
print("not applying bonus")
return
starship_bonuses[stat_name] += bonus
print("applied bonus")
emit_signal("starship_stat_changed", stat_name, get_starship_stat(stat_name))

func reset_starship_bonus(stat_name: String):
Expand Down
232 changes: 162 additions & 70 deletions apps/gamejam/brackeys/13/scripts/shop.gd
Original file line number Diff line number Diff line change
@@ -1,102 +1,194 @@
extends ColorRect

# Top Left Panel / Resource Panel
@onready var resource_panel : Label = $HBoxContainer/ResourcePanel/Label

# Bottom Panel
@onready var bottom_panel_screen_label : Label = $MainBG/NonInteractable/BottomScreen/Label

# Left Panel
@onready var categories_label := $MainBG/LeftPanel/ScreenPanel/Label
@onready var cate_selected:= categories[current_category]
@onready var categories_label : Label= $MainBG/LeftPanel/ScreenPanel/Label
@onready var cate_selected : String = categories[current_category]

# Center Panel
@onready var center_label_left := $MainBG/CenterScreen/HBoxContainer/Left
@onready var center_label_right := $MainBG/CenterScreen/HBoxContainer/Right
@onready var shown_text = chunk_array(chosen[current_category], 4)
@onready var center_label_left : Label = $MainBG/CenterScreen/HBoxContainer/Left
@onready var center_label_right : Label = $MainBG/CenterScreen/HBoxContainer/Right
@onready var center_label_bottom : Label = $MainBG/CenterScreen/Label
@onready var button_1_left : Button = $MainBG/LeftButtons/VBoxContainer/Button # ]
@onready var button_2_left : Button = $MainBG/LeftButtons/VBoxContainer/Button2 # ]
@onready var button_3_left : Button = $MainBG/LeftButtons/VBoxContainer/Button3 # } Referenced to be disabled when confirming upgrade
@onready var button_3_right : Button = $MainBG/RightButtons/VBoxContainer/Button3 # ]
@onready var green_light : TextureRect = $MainBG/CenterScreen/GreenLight
@onready var red_light : TextureRect = $MainBG/CenterScreen/RedLight

var green_light_off : CompressedTexture2D = preload("res://assets/audioknobs-ui/audioknobs/green-light-off.png")
var green_light_on : CompressedTexture2D = preload("res://assets/audioknobs-ui/audioknobs/green-light-on.png")
var red_light_off : CompressedTexture2D = preload("res://assets/audioknobs-ui/audioknobs/red-light-off.png")
var red_light_on : CompressedTexture2D = preload("res://assets/audioknobs-ui/audioknobs/red-light-on.png")

# Left Panel
var categories : Array[StringName]= ["Weapons", "Shield", "Power", "Thrusters"]
var current_category = 0
var categories : Array[StringName] = ["Weapons", "Shield", "Power", "Thrusters"]
var current_category : int = 0

# Center Panel
var current_parts = 0
var current_parts := 0
var is_on_confirm := false
var chosen_upgrade
var shown_text
var weapons := [
"+1 damage",
"+1 max ammo",
"+1 laser speed",
"+111 test",
"+12 test",
"+13 test",
"+123 test",
"+1244 test",
"+14 test",
{"name": "+1 laser speed", "stat_name": "laser_speed", "value": 1.0, "cost":
{"stone": 200.0, "metal": 50.0}},
{"name": "+1 ammo count", "stat_name": "laser_ammo", "value": 1.0, "cost":
{"gems": 10, "gold": 5}}
]
var shield := [
{"name": "None", "stat_name": "none", "value": 1.0, "cost":
{}}
]
var power := [
{"name": "Overheat?", "stat_name": "overheat", "value": 1.0, "cost":
{}}
]
var thrusters := [
{"name": "+1 acceleration", "stat_name": "acceleration", "value": 1.0, "cost":
{}},
{"name": "+1 rotation speed", "stat_name": "rotation_speed", "value": 1.0, "cost":
{}}
]
var shield := []
var power := []
var thrusters := []
var chosen = [weapons, shield, power, thrusters]


func _ready():
update_resource_panel()
update_bottom_panel_screen()

#region LeftPanelRegion

func _on_left_button_pressed_left_panel() -> void:
if cate_selected == categories[0]:
pass
else:
current_category -= 1
update_categories()
if cate_selected == categories[0]:
pass
else:
current_category -= 1
update_categories()

func _on_right_button_pressed_left_panel() -> void:
if cate_selected == categories[3]:
pass
else:
current_category += 1
update_categories()
if cate_selected == categories[3]:
pass
else:
current_category += 1
update_categories()

func update_categories() -> void:
cate_selected = categories[current_category]
categories_label.text = cate_selected
cate_selected = categories[current_category]
categories_label.text = cate_selected

func _on_enter_button_pressed_left_panel() -> void:
update_parts()
shown_text = chunk_array(chosen[current_category], 4)
unshow_confirm_upgrade() # unshow when the confirm text when switching categories
update_parts()

func update_parts() -> void:
center_label_left.text = shown_text[current_parts][0] + "\n" + shown_text[current_parts][1]
center_label_right.text = shown_text[current_parts][2] + "\n" + shown_text[current_parts][3]

func chunk_array(base: Array, size: int) -> Array:
var result = []
for i in range(0, base.size(), size):
var chunk = base.slice(i, i + size) # Get up to 'size' elements
while chunk.size() < size: # Fill missing spots with "empty"
chunk.append("")
result.append(chunk)
return result
center_label_left.text = shown_text[current_parts][0].name + "\n" + shown_text[current_parts][1].name
center_label_right.text = shown_text[current_parts][2].name + "\n" + shown_text[current_parts][3].name

func chunk_array(base: Array, t_size: int) -> Array:
var result = []
for i in range(0, base.size(), t_size):
var chunk = base.slice(i, i + t_size) # Get up to 'size' elements
while chunk.size() < t_size: # Fill missing spots with "empty"
chunk.append({"name": "", "stat": "none", "value": 0.0})
result.append(chunk)
return result

#endregion

#region Center Panel

func _on_button_1_left_pressed():
pass # Replace with function body.


func _on_button_2_left_pressed():
pass # Replace with function body.


func _on_button_3_left_pressed():
current_parts -= 1
current_parts = clamp(current_parts, 0, 5)
update_parts()


func _on_button_right_pressed():
pass # Replace with function body.


func _on_button_2_right_pressed():
pass # Replace with function body.


func _on_button_right_3_pressed():
current_parts += 1
current_parts = clamp(current_parts, 0, shown_text.size() - 1)
update_parts()
func _on_button_1_left_pressed() -> void:
show_confirm_upgrade(0)


func _on_button_2_left_pressed() -> void:
show_confirm_upgrade(1)


func _on_button_3_left_pressed() -> void:
if shown_text != null:
current_parts -= 1
current_parts = clamp(current_parts, 0, shown_text.size() - 1)
update_parts()


func _on_button_right_pressed() -> void:
if is_on_confirm: # Confirm upgrade
if can_afford():
Global.apply_starship_bonus(chosen_upgrade.stat_name, chosen_upgrade.value)
update_resource_panel()
update_bottom_panel_screen()
print("bought")
green_light.texture = green_light_on
await get_tree().create_timer(1.0).timeout
green_light.texture = green_light_off
else:
red_light.texture = red_light_on
await get_tree().create_timer(1.0).timeout
red_light.texture = red_light_off
else:
show_confirm_upgrade(2)

func can_afford() -> bool:
var cost = chosen_upgrade.get("cost", {})
for resource in cost.keys():
if Global.resources.get(resource, 0) < cost[resource]:
return false # Not enough resources
return true # Upgrade is affordable


func _on_button_2_right_pressed() -> void:
if is_on_confirm: # Cancel upgrade
unshow_confirm_upgrade()
update_parts()
else:
show_confirm_upgrade(3)


func _on_button_right_3_pressed() -> void:
if shown_text != null:
current_parts += 1
current_parts = clamp(current_parts, 0, shown_text.size() - 1)
update_parts()

func show_confirm_upgrade(button: int) -> void:
if shown_text != null:
if shown_text[current_parts][button].name != "":
is_on_confirm = true
chosen_upgrade = shown_text[current_parts][button]
center_label_left.text = chosen_upgrade.name
center_label_right.text = "Confirm" + "\n" + "Cancel"
center_label_bottom.text = ""
button_1_left.disabled = true
button_2_left.disabled = true
button_3_left.disabled = true
button_3_right.disabled = true

func unshow_confirm_upgrade() -> void:
is_on_confirm = false
button_1_left.disabled = false
button_2_left.disabled = false
button_3_left.disabled = false
button_3_right.disabled = false
center_label_bottom.text = "Left Right"

#endregion

func update_resource_panel() -> void:
var full_text = ""
for i in Global.resources.keys():
full_text += "%s: %d " % [i.capitalize(), Global.resources[i]]
resource_panel.text = full_text

func update_bottom_panel_screen() -> void:
var full_text = ""
for i in Global.base_starship_stats.keys():
full_text += "%s: %d " % [i.capitalize(), Global.base_starship_stats[i] + Global.starship_bonuses[i]]
bottom_panel_screen_label.text = full_text

0 comments on commit 72ad291

Please sign in to comment.