82 lines
2.5 KiB
GDScript
82 lines
2.5 KiB
GDScript
extends Node
|
|
|
|
var last_scene
|
|
|
|
@onready var playlist_generator: Node = $PlaylistGenerator
|
|
|
|
@onready var continue_button: Button = $MarginContainer/VBoxContainer/Continue
|
|
@onready var option_button: OptionButton = $MarginContainer/VBoxContainer/HBoxContainer/OptionButton
|
|
@onready var add_leaderboard: Button = $"MarginContainer/VBoxContainer/HBoxContainer/Add Leaderboard"
|
|
@onready var add_leaderboard_menu: Control = $"Add Leaderboard Menu"
|
|
@onready var new_leaderboard_name: TextEdit = $"Add Leaderboard Menu/MarginContainer/HBoxContainer/NewLeaderboardName"
|
|
@onready var confirm_leaderboard_add: Button = $"Add Leaderboard Menu/MarginContainer/HBoxContainer/Confirm"
|
|
|
|
|
|
func _enter_tree() -> void:
|
|
SaveLoad.load_persistent_data()
|
|
SaveLoad.load_user_data()
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready() -> void:
|
|
add_leaderboard_menu.visible = false
|
|
playlist_generator.load_playlist()
|
|
refresh_option_list()
|
|
continue_text_check()
|
|
|
|
|
|
func _on_continue_pressed() -> void:
|
|
var level
|
|
var load_to_gamemode
|
|
|
|
|
|
playlist_generator.load_playlist()
|
|
|
|
|
|
if GameGlobals.current_level == null:
|
|
level = "res://scenes/HUBWORLD.tscn"
|
|
load_to_gamemode = "res://GameModes/hubworld.tres"
|
|
else:
|
|
level = GameGlobals.current_level
|
|
load_to_gamemode = GameGlobals.current_gamemode
|
|
|
|
SaveLoad.save_persistent_data()
|
|
SaveLoad.load_user_data()
|
|
SaveLoad.save_user_data()
|
|
get_tree().change_scene_to_file(level)
|
|
print("LEVEL : ",GameGlobals.current_level)
|
|
|
|
func _on_exit_pressed() -> void:
|
|
SaveLoad.save_persistent_data()
|
|
get_tree().quit()
|
|
|
|
func continue_text_check():
|
|
if SaveLoad.check_user_data_exists():
|
|
continue_button.text = "Continue"
|
|
else:
|
|
continue_button.text = "New Game"
|
|
|
|
|
|
func _on_add_leaderboard_pressed() -> void:
|
|
add_leaderboard_menu.visible = true
|
|
|
|
func refresh_option_list():
|
|
option_button.clear()
|
|
for i in GameGlobals.all_user_leaderboards[int(GameGlobals.user_id)]:
|
|
option_button.add_item(i)
|
|
option_button.selected = int(GameGlobals.last_leaderboard_id)
|
|
|
|
func _on_confirm_pressed() -> void:
|
|
var valid_name = HelperFuncs.only_valid_chars(new_leaderboard_name.text)
|
|
|
|
GameGlobals.all_user_leaderboards[GameGlobals.user_id].append(valid_name)
|
|
GameGlobals.last_leaderboard_id = GameGlobals.all_user_leaderboards[GameGlobals.user_id].size() - 1
|
|
|
|
refresh_option_list()
|
|
continue_text_check()
|
|
add_leaderboard_menu.visible = false
|
|
|
|
|
|
func _on_option_button_item_selected(index: int) -> void:
|
|
GameGlobals.last_leaderboard_id = option_button.selected
|
|
continue_text_check()
|