extends Control var account_information: LoginServerLoginSuccessPacket var character_server_information: Array var current_character_server_idx := -1 var current_character_slot_idx := -1 var current_character_information: CharacterInformation @onready var username: LineEdit = %Username @onready var password: LineEdit = %Password func _ready() -> void: switch_screen(%Login) #$BackgroundMusic.play() %ChatWindow.visible = false func switch_screen(screen: Node): for node in get_children(): if node is CenterContainer: node.visible = false screen.visible = true func _on_login_pressed() -> void: $ButtonClickSound.play() Network.login_server.login(username.text, password.text) account_information = await Network.login_server.logged_in character_server_information = account_information.character_server_information Client.account.id = account_information.account_id get_tree().root.add_child(Network.login_server.get_keep_alive_timer()) for node in %CharacterServerList.get_children(): node.queue_free() for idx in character_server_information.size(): var info: CharacterServerInformation = character_server_information[idx] var select_character_server: Button = preload("res://ui/login/character_server_button.tscn").instantiate() select_character_server.text = info.server_name select_character_server.pressed.connect(_on_character_server_login_pressed.bind(info, idx)) %CharacterServerList.add_child(select_character_server) if idx == 0: current_character_server_idx = 0 select_character_server.grab_focus() # TODO: if setting is true to skip character server selection when only one server is available #if character_server_information.size() == 1: #(%CharacterServerList.get_child(0) as Button).pressed.emit() #else: #switch_screen(%CharacterServer) switch_screen(%CharacterServer) func _on_character_server_login_pressed(character_server_info: CharacterServerInformation, idx: int) -> void: if idx != current_character_server_idx: current_character_server_idx = idx return $ButtonClickSound.play() Network.character_server = CharacterServer.new( character_server_info.get_server_ip(), character_server_info.server_port ) Network.character_server.login( account_information.account_id, account_information.login_id1, account_information.login_id2, account_information.gender ) var response = await Network.character_server.received_packet if response is CharacterSelectionFailedPacket: print("character server login failed") %ChatWindow.add_message("character server login failed", ChatMessageFormat.new()) return get_tree().root.add_child(Network.character_server.get_keep_alive_timer()) var character_list: CharacterServerLoginSuccessCharacterListPacket = await Network.character_server.logged_in_character_list var login_character_list := LoginCharacterList.from_character_list_packet(character_list) %CharacterSelectionList.login_character_list = login_character_list %CharacterSelectionList.selected.connect(func(slot_idx: int): current_character_slot_idx = slot_idx %CharacterSelectionSlotLabel.text = "%s/%s" % [str(slot_idx + 1), login_character_list.slot_count] if slot_idx < character_list.character_information.size(): current_character_information = character_list.character_information[slot_idx] else: current_character_information = null ) # pre-select first character %CharacterSelectionList.select(0) switch_screen(%CharacterSelection) func _on_character_selected_pressed(slot_idx: int): $ButtonClickSound.play() Network.character_server.select_character(slot_idx) var selected_character = await Network.character_server.selected_character if selected_character is CharacterSelectionFailedPacket: # TODO: show error return Client.character.name = current_character_information.name Network.map_server = MapServer.new( selected_character.get_map_server_ip(), selected_character.map_server_port ) Network.map_server.login( account_information.account_id, current_character_information.character_id, account_information.login_id1, account_information.gender ) var _logged_in = await Network.map_server.logged_in # TODO: switch to game :) %ChatWindow.visible = true %ChatWindow.initialize() # TODO: load map var map_loaded_packet := MapLoadedPacket.new() Network.map_server.send(map_loaded_packet) # TODO: check which map server packets to send next func _on_character_server_back_button_pressed() -> void: $ButtonClickSound.play() switch_screen(%Login) func _on_character_server_next_button_pressed() -> void: (%CharacterServerList.get_child(0) as Button).pressed.emit() func _on_character_selection_back_button_pressed() -> void: $ButtonClickSound.play() switch_screen(%CharacterServer) func _on_character_login_pressed() -> void: _on_character_selected_pressed(current_character_slot_idx)