extends Control var account_information: LoginServerLoginSuccessPacket var character_server_information: Array var current_character_information: CharacterInformation func _ready() -> void: switch_screen(%Login) #$BackgroundMusic.play() # TODO: check why TextureRect doesn't work #get_tree().root.size_changed.connect(func(): #$Background.scale = get_viewport_rect().size / $Background.get_rect().size #) 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 info: CharacterServerInformation in character_server_information: var select_character_server = Button.new() select_character_server.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND select_character_server.text = info.server_name select_character_server.pressed.connect(_on_character_server_login_pressed.bind(info)) %CharacterServerList.add_child(select_character_server) switch_screen(%CharacterServer) func _on_character_server_login_pressed(character_server_info: CharacterServerInformation) -> void: $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") 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 for slot_idx in character_list.character_information.size(): var info: CharacterInformation = character_list.character_information[slot_idx] var character = Button.new() character.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND character.text = info.name character.pressed.connect(func(): current_character_information = info _on_character_selected_pressed(slot_idx) ) %CharacterList.add_child(character) 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 CharacterSelectionSuccessPacket: 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 _response = await Network.map_server.logged_in Client.character.name = current_character_information.name # TODO: switch to game :) # TODO: check next packages to sent to server, most probably to map server Network.map_server.received_packet.connect(func(packet: Packet): if packet is ServerMessagePacket: %ChatWindow.add_message(packet.message) )