Add marketplace button functionality and skill unlocker integration

This commit is contained in:
2025-06-05 22:50:45 +02:00
parent 87b85cae43
commit cc737f22cf
16 changed files with 167 additions and 7 deletions

View File

@@ -1,8 +1,11 @@
[gd_scene load_steps=2 format=3 uid="uid://dtl03rod7l2t0"] [gd_scene load_steps=5 format=3 uid="uid://dtl03rod7l2t0"]
[ext_resource type="Texture2D" uid="uid://cvhoq7aubxlmq" path="res://sprites/ui/magnetic_skill_icon.png" id="1_5kqfg"] [ext_resource type="Texture2D" uid="uid://cvhoq7aubxlmq" path="res://sprites/ui/magnetic_skill_icon.png" id="1_5kqfg"]
[ext_resource type="Script" uid="uid://dx8lex40lotr5" path="res://scripts/ui/marketplace_button.gd" id="2_ulgvb"]
[ext_resource type="Texture2D" uid="uid://52adghxscdgy" path="res://sprites/locked_skill.png" id="2_vb2qn"]
[ext_resource type="Texture2D" uid="uid://rucyqmgrdld3" path="res://sprites/unlocked_skill.png" id="3_guyun"]
[node name="MarketplaceButton" type="Button"] [node name="MarketplaceButton" type="Button" node_paths=PackedStringArray("skill_level_container")]
offset_right = 8.0 offset_right = 8.0
offset_bottom = 8.0 offset_bottom = 8.0
size_flags_horizontal = 3 size_flags_horizontal = 3
@@ -12,3 +15,17 @@ text = "Fire brick 100"
icon = ExtResource("1_5kqfg") icon = ExtResource("1_5kqfg")
flat = true flat = true
autowrap_mode = 2 autowrap_mode = 2
script = ExtResource("2_ulgvb")
unlocked_skill_icon = ExtResource("3_guyun")
locked_skill_icon = ExtResource("2_vb2qn")
skill_level_container = NodePath("HBoxContainer")
[node name="HBoxContainer" type="HBoxContainer" parent="."]
layout_mode = 1
anchors_preset = 12
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
offset_top = -8.0
grow_horizontal = 2
grow_vertical = 0

View File

@@ -19,3 +19,6 @@ config = {
cost = 50 cost = 50
icon = ExtResource("2_yimbq") icon = ExtResource("2_yimbq")
type = 1 type = 1
is_active = false
level = 0
max_level = 3

View File

@@ -20,3 +20,6 @@ config = {
cost = 180 cost = 180
icon = ExtResource("3_wkqmb") icon = ExtResource("3_wkqmb")
type = 1 type = 1
is_active = false
level = 0
max_level = 1

View File

@@ -20,3 +20,6 @@ config = {
cost = 150 cost = 150
icon = ExtResource("3_w87qb") icon = ExtResource("3_w87qb")
type = 1 type = 1
is_active = false
level = 0
max_level = 3

View File

@@ -20,3 +20,6 @@ config = {
cost = 150 cost = 150
icon = ExtResource("3_6btth") icon = ExtResource("3_6btth")
type = 1 type = 1
is_active = false
level = 0
max_level = 3

View File

@@ -4,7 +4,7 @@ extends Node
@export var skill_manager: SkillManager @export var skill_manager: SkillManager
@onready var game_manager: GM = $"/root/GameManager" @onready var game_manager: GM = $"/root/GameManager"
signal skill_unlocked(skill_data: SkillData)
func has_enough_coins(amount: int) -> bool: func has_enough_coins(amount: int) -> bool:
@@ -24,6 +24,7 @@ func try_unlock_skill(skill_data: SkillData) -> bool:
game_manager.remove_coins(skill_data.cost) game_manager.remove_coins(skill_data.cost)
game_manager.current_session_state["skills_unlocked"].append(skill_data.name) game_manager.current_session_state["skills_unlocked"].append(skill_data.name)
skill_manager.add_skill(skill_data) skill_manager.add_skill(skill_data)
skill_unlocked.emit(skill_data)
return true return true
@@ -33,6 +34,7 @@ func unlock_all_skills() -> void:
for skill in available_skills: for skill in available_skills:
skills.append(skill.name) skills.append(skill.name)
skill_unlocked.emit(skill)
game_manager.unlock_skills(skills) game_manager.unlock_skills(skills)
skill_manager.apply_unlocked_skills() skill_manager.apply_unlocked_skills()

View File

@@ -68,6 +68,14 @@ func get_kid_nodes() -> Array[CollectableComponent]:
return kid_nodes return kid_nodes
func get_player_node() -> Node:
for node in nodes_in_scene:
if node is PlayerController:
return node
return null
func add_coins(amount: int) -> void: func add_coins(amount: int) -> void:
player_state["coins"] += amount player_state["coins"] += amount
player_state["coins"] = max(0, player_state["coins"]) player_state["coins"] = max(0, player_state["coins"])
@@ -213,7 +221,6 @@ func on_level_complete() -> void:
SaveSystem.save_game() SaveSystem.save_game()
func get_unlocked_skills() -> Array: func get_unlocked_skills() -> Array:
var skills_unlocked = player_state.get("unlocked_skills", []) var skills_unlocked = player_state.get("unlocked_skills", [])
var skills_current_session = current_session_state.get("skills_unlocked", []) var skills_current_session = current_session_state.get("skills_unlocked", [])

View File

@@ -13,3 +13,6 @@ enum SkillType {
@export var cost: int = 0 @export var cost: int = 0
@export var icon: Texture2D @export var icon: Texture2D
@export var type: SkillType = SkillType.ATTACK @export var type: SkillType = SkillType.ATTACK
@export var is_active: bool = false
@export var level: int = 1
@export var max_level: int = 1

View File

@@ -46,9 +46,10 @@ func get_button_text(skill: SkillData) -> String:
func create_upgrade_button(skill: SkillData): func create_upgrade_button(skill: SkillData):
var button := marketplace_button.instantiate() as Button var button := marketplace_button.instantiate() as MarketplaceButton
button.text = get_button_text(skill) button.text = get_button_text(skill)
button.icon = skill.icon button.icon = skill.icon
button.skill_data = skill
button.pressed.connect(func () -> void: _on_button_pressed(skill)) button.pressed.connect(func () -> void: _on_button_pressed(skill))

View File

@@ -0,0 +1,48 @@
class_name MarketplaceButton
extends Button
@export var skill_data: SkillData
@export var unlocked_skill_icon: Texture2D
@export var locked_skill_icon: Texture2D
@export var skill_level_container: Container
@onready var gm: GM = $"/root/GameManager"
func _ready() -> void:
if not skill_data:
printerr("MarketplaceButton: skill_data is not set.")
if not unlocked_skill_icon or not locked_skill_icon:
printerr("MarketplaceButton: unlocked_skill_icon or locked_skill_icon is not set.")
return
if not skill_level_container:
printerr("MarketplaceButton: skill_level_container is not set.")
return
setup()
var player := gm.get_player_node()
var skill_unlocker_component := player.get_node_or_null("SkillUnlockerComponent") as SkillUnlockerComponent
if skill_unlocker_component:
skill_unlocker_component.skill_unlocked.connect(_on_skill_unlock)
func setup() -> void:
if not skill_data:
return
for i in range(skill_data.max_level):
var _icon := TextureRect.new()
_icon.texture = unlocked_skill_icon if i < skill_data.level else locked_skill_icon
skill_level_container.add_child(_icon)
func _on_skill_unlock(skill: SkillData) -> void:
if skill.name == skill_data.name:
for i in range(skill_data.max_level):
var icon := skill_level_container.get_child(i) as TextureRect
if i < skill.level:
icon.texture = unlocked_skill_icon
else:
icon.texture = locked_skill_icon
disabled = skill.level >= skill_data.max_level

View File

@@ -0,0 +1 @@
uid://dx8lex40lotr5

View File

@@ -45,7 +45,6 @@ func _ready() -> void:
Console.console_closed.connect(_on_console_close) Console.console_closed.connect(_on_console_close)
func _unhandled_input(event: InputEvent) -> void: func _unhandled_input(event: InputEvent) -> void:
if event.is_action_pressed("pause") and not is_console_open: if event.is_action_pressed("pause") and not is_console_open:
if UiManager.is_visible_on_stack(pause_menu_control): if UiManager.is_visible_on_stack(pause_menu_control):
@@ -78,6 +77,8 @@ func _on_exit_to_menu_button_pressed() -> void:
printerr("PauseMenu: Exit to menu scene not set.") printerr("PauseMenu: Exit to menu scene not set.")
return return
gm.resume_game()
gm.reset_current_session_state()
get_tree().change_scene_to_packed(exit_to_menu_scene) get_tree().change_scene_to_packed(exit_to_menu_scene)

BIN
sprites/locked_skill.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 124 B

View File

@@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://52adghxscdgy"
path="res://.godot/imported/locked_skill.png-48fa9e93aa2c711c18fd9edb5233eb69.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://sprites/locked_skill.png"
dest_files=["res://.godot/imported/locked_skill.png-48fa9e93aa2c711c18fd9edb5233eb69.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

BIN
sprites/unlocked_skill.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 124 B

View File

@@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://rucyqmgrdld3"
path="res://.godot/imported/unlocked_skill.png-be1990df98d42600170074fac52ea327.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://sprites/unlocked_skill.png"
dest_files=["res://.godot/imported/unlocked_skill.png-be1990df98d42600170074fac52ea327.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1