From 6e2deea3d1b2fb4d79dac02a0d4310936c7f317c Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Tue, 24 Dec 2024 00:36:06 +0100 Subject: next commit --- ui/login.gd | 49 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 17 deletions(-) (limited to 'ui/login.gd') diff --git a/ui/login.gd b/ui/login.gd index 73b294c..3180024 100644 --- a/ui/login.gd +++ b/ui/login.gd @@ -4,8 +4,13 @@ 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) @@ -24,7 +29,7 @@ func switch_screen(screen: Node): func _on_login_pressed() -> void: $ButtonClickSound.play() - Network.login_server.login(%Username.text, %Password.text) + Network.login_server.login(username.text, password.text) account_information = await Network.login_server.logged_in character_server_information = account_information.character_server_information @@ -36,14 +41,18 @@ func _on_login_pressed() -> void: 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 + 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)) + 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 + # 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: @@ -51,7 +60,11 @@ func _on_login_pressed() -> void: switch_screen(%CharacterServer) -func _on_character_server_login_pressed(character_server_info: CharacterServerInformation) -> void: +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(), @@ -80,24 +93,18 @@ func _on_character_server_login_pressed(character_server_info: CharacterServerIn for slot_idx in character_list.character_information.size(): var info: CharacterInformation = character_list.character_information[slot_idx] - var character = preload("res://ui/character_selection_item.tscn").instantiate() + var character = preload("res://ui/login/character_selection_item.tscn").instantiate() character.initialize_with_info(info) - character.activated.connect(func(): - $CharacterSelection/VBoxContainer/HBoxContainer/CharacterInfo/Label.text = info.name - $CharacterSelection/VBoxContainer/HBoxContainer/CharacterInfo/HBoxContainer/Label2.text = str(info.level) - $CharacterSelection/VBoxContainer/HBoxContainer/CharacterInfo/HBoxContainer2/Label2.text = str(info.job_level) - $CharacterSelection/VBoxContainer/HBoxContainer/CharacterInfo/HBoxContainer4/Label2.text = Constants.Job.find_key(info.job) - $CharacterSelection/VBoxContainer/HBoxContainer/CharacterInfo/HBoxContainer3/Label2.text = str(info.strength) - ) character.selected.connect(func(): + current_character_slot_idx = slot_idx current_character_information = info - _on_character_selected_pressed(slot_idx) + %CharacterSelectionStatus.set_info(info) ) %CharacterList.add_child(character) # pre-select first character if slot_idx == 0: - character.activated.emit() + character.selected.emit() switch_screen(%CharacterSelection) @@ -144,6 +151,14 @@ func _on_character_server_back_button_pressed() -> void: 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) -- cgit v1.2.3