Refactor scene structure and resource paths; add death and game over screens
This commit is contained in:
62
scripts/ui/death_screen.gd
Normal file
62
scripts/ui/death_screen.gd
Normal file
@@ -0,0 +1,62 @@
|
||||
class_name DeathScreen
|
||||
extends Node
|
||||
|
||||
@export var death_screen_root: Control
|
||||
@export var current_level: LevelResource
|
||||
@export var current_level_label: Label
|
||||
@export var lives_left_label: Label
|
||||
@export var timeout_time: float = 2.0
|
||||
@export var nodes_to_disable: Array[Node] = []
|
||||
|
||||
@onready var gm: GM = $"/root/GameManager"
|
||||
|
||||
var timer: Timer
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
set_lables()
|
||||
|
||||
|
||||
func set_lables() -> void:
|
||||
if not gm:
|
||||
return
|
||||
|
||||
current_level_label.text = current_level.level_name
|
||||
lives_left_label.text = " x " + str(gm.get_lives())
|
||||
|
||||
|
||||
func setup_timer() -> void:
|
||||
timer = Timer.new()
|
||||
timer.wait_time = timeout_time
|
||||
timer.one_shot = true
|
||||
timer.timeout.connect(on_timeout)
|
||||
add_child(timer)
|
||||
timer.start()
|
||||
|
||||
|
||||
func toggle_nodes() -> void:
|
||||
for node in nodes_to_disable:
|
||||
if node.process_mode == PROCESS_MODE_DISABLED:
|
||||
node.process_mode = PROCESS_MODE_INHERIT
|
||||
else:
|
||||
node.process_mode = PROCESS_MODE_DISABLED
|
||||
|
||||
|
||||
func on_player_death() -> void:
|
||||
if not gm:
|
||||
return
|
||||
|
||||
toggle_nodes()
|
||||
set_lables()
|
||||
death_screen_root.show()
|
||||
setup_timer()
|
||||
|
||||
|
||||
func on_timeout() -> void:
|
||||
if not gm:
|
||||
return
|
||||
|
||||
if gm.get_lives() == 0:
|
||||
return
|
||||
|
||||
get_tree().reload_current_scene()
|
1
scripts/ui/death_screen.gd.uid
Normal file
1
scripts/ui/death_screen.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://b3d1p21sviww4
|
41
scripts/ui/game_over_screen.gd
Normal file
41
scripts/ui/game_over_screen.gd
Normal file
@@ -0,0 +1,41 @@
|
||||
class_name GameOverScreen
|
||||
extends Node
|
||||
|
||||
@export var game_over_screen: Control
|
||||
@export var restart_button: Button
|
||||
@export var main_menu_button: Button
|
||||
@export var main_menu_scene: PackedScene
|
||||
|
||||
@onready var gm: GM = $"/root/GameManager"
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
if not gm:
|
||||
return
|
||||
|
||||
game_over_screen.hide()
|
||||
restart_button.pressed.connect(on_restart_button_pressed)
|
||||
main_menu_button.pressed.connect(on_main_menu_button_pressed)
|
||||
|
||||
|
||||
func on_restart_button_pressed() -> void:
|
||||
if not gm:
|
||||
return
|
||||
|
||||
gm.reset_player_state()
|
||||
get_tree().reload_current_scene()
|
||||
|
||||
|
||||
func on_main_menu_button_pressed() -> void:
|
||||
if not gm or not main_menu_scene:
|
||||
return
|
||||
|
||||
gm.reset_player_state()
|
||||
get_tree().change_scene_to(main_menu_scene)
|
||||
|
||||
|
||||
func on_player_death() -> void:
|
||||
if not gm or not gm.get_lives() == 0:
|
||||
return
|
||||
|
||||
game_over_screen.show()
|
1
scripts/ui/game_over_screen.gd.uid
Normal file
1
scripts/ui/game_over_screen.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://bkd7o2u4psu4p
|
51
scripts/ui/hud.gd
Normal file
51
scripts/ui/hud.gd
Normal file
@@ -0,0 +1,51 @@
|
||||
class_name Hud
|
||||
extends Node
|
||||
|
||||
@export var player_health: HealthComponent
|
||||
@export var coins_label: Label
|
||||
@export var health_progressbar: ProgressBar
|
||||
@export var lives_label: Label
|
||||
|
||||
@onready var game_manager: GM = $"/root/GameManager"
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
if not player_health:
|
||||
var nodes := get_tree().get_nodes_in_group("player")
|
||||
for node in nodes:
|
||||
player_health = node.get_node_or_null("HealthComponent")
|
||||
if player_health:
|
||||
break
|
||||
return
|
||||
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
if not game_manager:
|
||||
return
|
||||
|
||||
set_health_progressbar()
|
||||
set_lives_label()
|
||||
set_coins_label()
|
||||
|
||||
|
||||
func set_coins_label() -> void:
|
||||
if not game_manager:
|
||||
return
|
||||
|
||||
#todo: set internationalized text
|
||||
coins_label.text = "Coins:" + str(game_manager.get_coins())
|
||||
|
||||
|
||||
func set_lives_label() -> void:
|
||||
if not game_manager:
|
||||
return
|
||||
|
||||
lives_label.text = "Lives:" + str(game_manager.get_lives())
|
||||
|
||||
|
||||
func set_health_progressbar() -> void:
|
||||
if not player_health:
|
||||
return
|
||||
|
||||
health_progressbar.value = player_health.health
|
||||
health_progressbar.max_value = player_health.max_health
|
1
scripts/ui/hud.gd.uid
Normal file
1
scripts/ui/hud.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://c3pde84b3kdco
|
99
scripts/ui/input_settings.gd
Normal file
99
scripts/ui/input_settings.gd
Normal file
@@ -0,0 +1,99 @@
|
||||
class_name InputSettings
|
||||
extends Control
|
||||
|
||||
@export var input_button_scene: PackedScene = preload("res://objects/ui/input_button.tscn")
|
||||
@export var action_list: Container
|
||||
@export var reset_to_default_button: Button
|
||||
|
||||
@export var input_actions: Dictionary = {
|
||||
'left': 'Move left',
|
||||
'right': 'Move right',
|
||||
'up': 'Move up',
|
||||
'down': 'Move down',
|
||||
'jump': 'Jump',
|
||||
'attack': 'Attack',
|
||||
'show_marketplace': "Toggle marketplace",
|
||||
}
|
||||
|
||||
var is_remapping: bool = false
|
||||
var action_to_remap = null
|
||||
var remapping_button = null
|
||||
var buttons: Array[Button] = []
|
||||
|
||||
@onready var config_file_handler = $'/root/ConfigFileHandler'
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
create_action_list()
|
||||
|
||||
if buttons.size() > 0:
|
||||
buttons[0].grab_focus()
|
||||
|
||||
if reset_to_default_button:
|
||||
reset_to_default_button.pressed.connect(on_reset_button_pressed)
|
||||
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if is_remapping:
|
||||
if event is InputEventKey or (event is InputEventMouseButton and event.pressed) or event is InputEventJoypadButton:
|
||||
if event is InputEventMouseButton and event.double_click:
|
||||
event.double_click = false
|
||||
|
||||
InputMap.action_erase_events(action_to_remap)
|
||||
InputMap.action_add_event(action_to_remap, event)
|
||||
update_action_list(remapping_button, event)
|
||||
|
||||
is_remapping = false
|
||||
action_to_remap = null
|
||||
remapping_button = null
|
||||
|
||||
accept_event()
|
||||
|
||||
|
||||
func create_action_list() -> void:
|
||||
InputMap.load_from_project_settings()
|
||||
for item in action_list.get_children():
|
||||
item.queue_free()
|
||||
|
||||
for action in input_actions:
|
||||
var button := input_button_scene.instantiate() as Button
|
||||
var action_label := button.find_child("LabelAction") as Label
|
||||
var input_label := button.find_child("LabelInput") as Label
|
||||
action_label.text = input_actions[action]
|
||||
|
||||
var events := InputMap.action_get_events(action)
|
||||
if events.size() > 0:
|
||||
input_label.text = events[0].as_text().trim_suffix(" (Physical)")
|
||||
else:
|
||||
input_label.text = "None"
|
||||
|
||||
action_list.add_child(button)
|
||||
button.pressed.connect(on_input_button_pressed.bind(button, action))
|
||||
buttons.append(button)
|
||||
|
||||
|
||||
func on_input_button_pressed(button: Button, action) -> void:
|
||||
if is_remapping:
|
||||
return
|
||||
|
||||
is_remapping = true
|
||||
action_to_remap = action
|
||||
remapping_button = button
|
||||
button.find_child("LabelInput").text = "Press any key..."
|
||||
|
||||
|
||||
func update_action_list(button: Button, event: InputEvent) -> void:
|
||||
button.find_child("LabelInput").text = event.as_text().trim_suffix(" (Physical)")
|
||||
|
||||
|
||||
func on_reset_button_pressed() -> void:
|
||||
create_action_list()
|
||||
|
||||
|
||||
func save_settings() -> void:
|
||||
config_file_handler.settings_config.set_value("input_settings", "input_actions", input_actions)
|
||||
config_file_handler.settings_config.save(config_file_handler.SETTINGS_FILE_PATH)
|
||||
|
||||
|
||||
func load_settings() -> void:
|
||||
pass
|
1
scripts/ui/input_settings.gd.uid
Normal file
1
scripts/ui/input_settings.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://dppwl7xie2mh
|
71
scripts/ui/marketplace.gd
Normal file
71
scripts/ui/marketplace.gd
Normal file
@@ -0,0 +1,71 @@
|
||||
class_name Marketplace
|
||||
extends Node
|
||||
|
||||
@export var root: Control
|
||||
@export var skill_data: Array[SkillData] = []
|
||||
@export var grid: GridContainer
|
||||
@export var font: Font
|
||||
@export var skill_unlocker: SkillUnlockerComponent
|
||||
@export var components_to_disable: Array[Node] = []
|
||||
@export var marketplace_button: PackedScene
|
||||
|
||||
@onready var game_manager: GM = $"/root/GameManager"
|
||||
|
||||
var buttons: Array[Button] = []
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
if not skill_unlocker:
|
||||
return
|
||||
|
||||
var skills_to_unlock: Array[SkillData] = []
|
||||
|
||||
for skill in skill_data:
|
||||
if skill in game_manager.player_state['unlocked_skills']:
|
||||
continue
|
||||
skills_to_unlock.append(skill)
|
||||
|
||||
for skill in skills_to_unlock:
|
||||
create_upgrade_button(skill)
|
||||
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed("show_marketplace"):
|
||||
if root.is_visible():
|
||||
root.hide()
|
||||
for component in components_to_disable:
|
||||
component.process_mode = PROCESS_MODE_INHERIT
|
||||
else:
|
||||
root.show()
|
||||
for component in components_to_disable:
|
||||
component.process_mode = PROCESS_MODE_DISABLED
|
||||
if buttons:
|
||||
buttons[0].grab_focus()
|
||||
|
||||
|
||||
func create_upgrade_button(skill: SkillData):
|
||||
var button := marketplace_button.instantiate() as Button
|
||||
button.text = skill.name + " " + str(skill.cost)
|
||||
button.icon = skill.icon
|
||||
|
||||
button.pressed.connect(func () -> void: _on_button_pressed(skill))
|
||||
|
||||
buttons.append(button)
|
||||
grid.add_child(button)
|
||||
grid.queue_sort()
|
||||
|
||||
|
||||
func remove_button(skill: SkillData):
|
||||
for child in grid.get_children():
|
||||
if child.text == skill.name + str(skill.cost):
|
||||
child.queue_free()
|
||||
break
|
||||
|
||||
|
||||
func _on_button_pressed(skill: SkillData) -> void:
|
||||
if not skill_unlocker:
|
||||
return
|
||||
|
||||
if skill_unlocker.try_unlock_skill(skill):
|
||||
remove_button(skill)
|
||||
|
1
scripts/ui/marketplace.gd.uid
Normal file
1
scripts/ui/marketplace.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://duifmqjarjpuv
|
95
scripts/ui/pause_menu.gd
Normal file
95
scripts/ui/pause_menu.gd
Normal file
@@ -0,0 +1,95 @@
|
||||
class_name PauseMenu
|
||||
extends Node
|
||||
|
||||
@export var pause_menu_control: Control
|
||||
@export var resume_button: Button
|
||||
@export var quit_button: Button
|
||||
@export var settings_button: Button
|
||||
@export var exit_to_menu_button: Button
|
||||
@export var settings_menu: Control
|
||||
@export var exit_to_menu_scene: PackedScene
|
||||
|
||||
@onready var gm: GM = $"/root/GameManager"
|
||||
|
||||
var is_paused: bool = false
|
||||
var is_console_open: bool = false
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
if not pause_menu_control:
|
||||
printerr("PauseMenu: Pause menu control not set.")
|
||||
return
|
||||
|
||||
if not resume_button:
|
||||
printerr("PauseMenu: Resume button not set.")
|
||||
return
|
||||
|
||||
if not quit_button:
|
||||
printerr("PauseMenu: Quit button not set.")
|
||||
return
|
||||
|
||||
if not settings_button:
|
||||
printerr("PauseMenu: Settings button not set.")
|
||||
return
|
||||
|
||||
if not exit_to_menu_button:
|
||||
printerr("PauseMenu: Exit to menu button not set.")
|
||||
return
|
||||
|
||||
pause_menu_control.hide()
|
||||
|
||||
resume_button.pressed.connect(_on_resume_button_pressed)
|
||||
quit_button.pressed.connect(_on_quit_button_pressed)
|
||||
settings_button.pressed.connect(_on_settings_button_pressed)
|
||||
exit_to_menu_button.pressed.connect(_on_exit_to_menu_button_pressed)
|
||||
Console.console_opened.connect(_on_console_open)
|
||||
Console.console_closed.connect(_on_console_close)
|
||||
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed("pause") and not is_console_open:
|
||||
if is_paused:
|
||||
_on_resume_button_pressed()
|
||||
else:
|
||||
gm.pause_game()
|
||||
is_paused = true
|
||||
pause_menu_control.show()
|
||||
resume_button.grab_focus()
|
||||
|
||||
|
||||
func _on_resume_button_pressed() -> void:
|
||||
pause_menu_control.hide()
|
||||
if settings_menu:
|
||||
settings_menu.hide()
|
||||
gm.resume_game()
|
||||
is_paused = false
|
||||
|
||||
|
||||
func _on_quit_button_pressed() -> void:
|
||||
gm.quit_game()
|
||||
|
||||
|
||||
func _on_settings_button_pressed() -> void:
|
||||
if not settings_menu:
|
||||
printerr("PauseMenu: Settings menu scene not set.")
|
||||
return
|
||||
|
||||
settings_menu.show()
|
||||
gm.pause_game()
|
||||
is_paused = true
|
||||
|
||||
|
||||
func _on_exit_to_menu_button_pressed() -> void:
|
||||
if not exit_to_menu_scene:
|
||||
printerr("PauseMenu: Exit to menu scene not set.")
|
||||
return
|
||||
|
||||
get_tree().change_scene_to_packed(exit_to_menu_scene)
|
||||
|
||||
|
||||
func _on_console_open():
|
||||
is_console_open = true
|
||||
|
||||
|
||||
func _on_console_close():
|
||||
is_console_open = false
|
1
scripts/ui/pause_menu.gd.uid
Normal file
1
scripts/ui/pause_menu.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://cugifchx6jhuk
|
95
scripts/ui/settings_menu.gd
Normal file
95
scripts/ui/settings_menu.gd
Normal file
@@ -0,0 +1,95 @@
|
||||
class_name SettingsMenu
|
||||
extends Node
|
||||
|
||||
@export var input_settings: Control
|
||||
@export var audio_settings: Control
|
||||
@export var display_settings: Control
|
||||
@export var gameplay_settings: Control
|
||||
@export var settings_menu_control: Control
|
||||
@export var input_settings_button: Button
|
||||
@export var audio_settings_button: Button
|
||||
@export var display_settings_button: Button
|
||||
@export var gameplay_settings_button: Button
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
if not settings_menu_control or not input_settings_button or not audio_settings_button or not display_settings_button or not gameplay_settings_button:
|
||||
printerr("No settings menu control or buttons found.")
|
||||
return
|
||||
|
||||
if input_settings:
|
||||
input_settings_button.pressed.connect(_on_input_settings_button_pressed)
|
||||
input_settings.hide()
|
||||
|
||||
if audio_settings:
|
||||
audio_settings_button.pressed.connect(_on_audio_settings_button_pressed)
|
||||
audio_settings.hide()
|
||||
|
||||
if display_settings:
|
||||
|
||||
display_settings_button.pressed.connect(_on_display_settings_button_pressed)
|
||||
display_settings.hide()
|
||||
|
||||
if gameplay_settings:
|
||||
gameplay_settings_button.pressed.connect(_on_gameplay_settings_button_pressed)
|
||||
gameplay_settings.hide()
|
||||
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed("ui_cancel"):
|
||||
if settings_menu_control.is_visible():
|
||||
settings_menu_control.hide()
|
||||
|
||||
|
||||
func _on_input_settings_button_pressed() -> void:
|
||||
if not input_settings:
|
||||
return
|
||||
|
||||
if input_settings.is_visible():
|
||||
input_settings.hide()
|
||||
else:
|
||||
input_settings.show()
|
||||
audio_settings.hide()
|
||||
display_settings.hide()
|
||||
gameplay_settings.hide()
|
||||
|
||||
|
||||
func _on_audio_settings_button_pressed() -> void:
|
||||
if not audio_settings:
|
||||
return
|
||||
|
||||
if audio_settings.is_visible():
|
||||
audio_settings.hide()
|
||||
else:
|
||||
audio_settings.show()
|
||||
input_settings.hide()
|
||||
display_settings.hide()
|
||||
gameplay_settings.hide()
|
||||
|
||||
|
||||
func _on_display_settings_button_pressed() -> void:
|
||||
if not display_settings:
|
||||
return
|
||||
|
||||
if display_settings.is_visible():
|
||||
display_settings.hide()
|
||||
else:
|
||||
display_settings.show()
|
||||
input_settings.hide()
|
||||
audio_settings.hide()
|
||||
gameplay_settings.hide()
|
||||
|
||||
|
||||
func _on_gameplay_settings_button_pressed() -> void:
|
||||
if not gameplay_settings:
|
||||
return
|
||||
|
||||
if gameplay_settings.is_visible():
|
||||
gameplay_settings.hide()
|
||||
else:
|
||||
gameplay_settings.show()
|
||||
input_settings.hide()
|
||||
audio_settings.hide()
|
||||
display_settings.hide()
|
||||
|
||||
|
1
scripts/ui/settings_menu.gd.uid
Normal file
1
scripts/ui/settings_menu.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://c506rigcjlm6x
|
Reference in New Issue
Block a user