Add marketplace button functionality and skill unlocker integration
This commit is contained in:
@@ -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