Add marketplace button functionality and skill unlocker integration
This commit is contained in:
@@ -4,7 +4,7 @@ extends Node
|
||||
@export var skill_manager: SkillManager
|
||||
|
||||
@onready var game_manager: GM = $"/root/GameManager"
|
||||
|
||||
signal skill_unlocked(skill_data: SkillData)
|
||||
|
||||
|
||||
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.current_session_state["skills_unlocked"].append(skill_data.name)
|
||||
skill_manager.add_skill(skill_data)
|
||||
skill_unlocked.emit(skill_data)
|
||||
return true
|
||||
|
||||
|
||||
@@ -33,6 +34,7 @@ func unlock_all_skills() -> void:
|
||||
|
||||
for skill in available_skills:
|
||||
skills.append(skill.name)
|
||||
skill_unlocked.emit(skill)
|
||||
|
||||
game_manager.unlock_skills(skills)
|
||||
skill_manager.apply_unlocked_skills()
|
||||
|
@@ -68,6 +68,14 @@ func get_kid_nodes() -> Array[CollectableComponent]:
|
||||
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:
|
||||
player_state["coins"] += amount
|
||||
player_state["coins"] = max(0, player_state["coins"])
|
||||
@@ -213,7 +221,6 @@ func on_level_complete() -> void:
|
||||
SaveSystem.save_game()
|
||||
|
||||
|
||||
|
||||
func get_unlocked_skills() -> Array:
|
||||
var skills_unlocked = player_state.get("unlocked_skills", [])
|
||||
var skills_current_session = current_session_state.get("skills_unlocked", [])
|
||||
|
@@ -12,4 +12,7 @@ enum SkillType {
|
||||
@export var config: Dictionary = {}
|
||||
@export var cost: int = 0
|
||||
@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
|
@@ -46,9 +46,10 @@ func get_button_text(skill: SkillData) -> String:
|
||||
|
||||
|
||||
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.icon = skill.icon
|
||||
button.skill_data = skill
|
||||
|
||||
button.pressed.connect(func () -> void: _on_button_pressed(skill))
|
||||
|
||||
|
48
scripts/ui/marketplace_button.gd
Normal file
48
scripts/ui/marketplace_button.gd
Normal 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
|
1
scripts/ui/marketplace_button.gd.uid
Normal file
1
scripts/ui/marketplace_button.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://dx8lex40lotr5
|
@@ -45,7 +45,6 @@ func _ready() -> void:
|
||||
Console.console_closed.connect(_on_console_close)
|
||||
|
||||
|
||||
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed("pause") and not is_console_open:
|
||||
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.")
|
||||
return
|
||||
|
||||
gm.resume_game()
|
||||
gm.reset_current_session_state()
|
||||
get_tree().change_scene_to_packed(exit_to_menu_scene)
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user