From 35b0f811f23f029110373798b19d9d0895d907f0 Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Sun, 5 Jan 2025 16:54:36 +0100 Subject: next commit --- ui/chat_window.gd | 17 ++++++++++++++ ui/chat_window.tscn | 22 +++++++++++++++--- ui/login.gd | 24 ++++++++------------ ui/login.tscn | 3 ++- ui/login/login_character_selection_list.gd | 34 +++++++++++++++++++++------- ui/login/login_character_selection_list.tscn | 2 ++ 6 files changed, 76 insertions(+), 26 deletions(-) (limited to 'ui') diff --git a/ui/chat_window.gd b/ui/chat_window.gd index c88a3ee..7841d57 100644 --- a/ui/chat_window.gd +++ b/ui/chat_window.gd @@ -3,6 +3,9 @@ extends PanelContainer @export var player_color: Color = Color8(255, 255, 255) +var is_dragging := false +var drag_anchor := Vector2.ZERO + func _ready() -> void: # clear test label @@ -57,3 +60,17 @@ func _on_broadcast_formatted_message_packet_received(packet: BroadcastFormattedM format.size = packet.font_size add_message(packet.message, format) + + +func _process(_delta: float) -> void: + if is_dragging: + global_position += get_global_mouse_position() - drag_anchor + drag_anchor = get_global_mouse_position() + + +func _on_handle_gui_input(event: InputEvent) -> void: + if event.is_action_pressed("primary_click"): + is_dragging = true + drag_anchor = get_global_mouse_position() + elif event.is_action_released("primary_click"): + is_dragging = false diff --git a/ui/chat_window.tscn b/ui/chat_window.tscn index e67d360..b430fb8 100644 --- a/ui/chat_window.tscn +++ b/ui/chat_window.tscn @@ -1,6 +1,8 @@ -[gd_scene load_steps=3 format=3 uid="uid://c8uqw08hxfqlu"] +[gd_scene load_steps=5 format=3 uid="uid://c8uqw08hxfqlu"] [ext_resource type="Script" uid="uid://cy5bwkc4gokw1" path="res://ui/chat_window.gd" id="1_vovuq"] +[ext_resource type="PackedScene" uid="uid://cjcm2mai50thr" path="res://ui/bmp_texture_button.tscn" id="2_2x3wj"] +[ext_resource type="Texture2D" uid="uid://dqq3mtjcrwqnp" path="res://client_data/data/texture/À¯ÀúÀÎÅÍÆäÀ̽º/basic_interface/sys_base_off.bmp" id="3_smgio"] [sub_resource type="StyleBoxFlat" id="StyleBoxFlat_ku06j"] bg_color = Color(0.133333, 0.133333, 0.133333, 0.784314) @@ -37,9 +39,23 @@ layout_mode = 2 layout_mode = 2 text = "Label" -[node name="LineEdit" type="LineEdit" parent="VBoxContainer"] +[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"] +layout_mode = 2 + +[node name="ToPlayer" type="LineEdit" parent="VBoxContainer/HBoxContainer"] unique_name_in_owner = true layout_mode = 2 + +[node name="LineEdit" type="LineEdit" parent="VBoxContainer/HBoxContainer"] +unique_name_in_owner = true +layout_mode = 2 +size_flags_horizontal = 3 placeholder_text = "Send Messages here" -[connection signal="text_submitted" from="VBoxContainer/LineEdit" to="." method="_on_line_edit_text_submitted"] +[node name="Handle" parent="VBoxContainer/HBoxContainer" instance=ExtResource("2_2x3wj")] +layout_mode = 2 +texture_normal = ExtResource("3_smgio") +stretch_mode = 5 + +[connection signal="text_submitted" from="VBoxContainer/HBoxContainer/LineEdit" to="." method="_on_line_edit_text_submitted"] +[connection signal="gui_input" from="VBoxContainer/HBoxContainer/Handle" to="." method="_on_handle_gui_input"] diff --git a/ui/login.gd b/ui/login.gd index 8cabec8..fb3c80b 100644 --- a/ui/login.gd +++ b/ui/login.gd @@ -15,8 +15,6 @@ var current_character_information: CharacterInformation func _ready() -> void: switch_screen(%Login) #$BackgroundMusic.play() - - %ChatWindow.visible = false func switch_screen(screen: Node): @@ -94,11 +92,15 @@ func _on_character_server_login_pressed(character_server_info: CharacterServerIn 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] + var info = login_character_list.get_info_for_slot(slot_idx) + if info: + current_character_information = info else: current_character_information = null ) + %CharacterSelectionList.requested_login.connect(func(slot_idx: int): + _on_character_selected_pressed(slot_idx) + ) # pre-select first character %CharacterSelectionList.select(0) @@ -117,6 +119,7 @@ func _on_character_selected_pressed(slot_idx: int): return Client.character.name = current_character_information.name + Client.character.info = current_character_information Network.map_server = MapServer.new( selected_character.get_map_server_ip(), @@ -131,16 +134,9 @@ func _on_character_selected_pressed(slot_idx: int): ) 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 + get_tree().change_scene_to_file( + "res://client_data/data/%s.tscn" % current_character_information.get_map_name() + ) func _on_character_server_back_button_pressed() -> void: diff --git a/ui/login.tscn b/ui/login.tscn index 4842c26..172b00e 100644 --- a/ui/login.tscn +++ b/ui/login.tscn @@ -46,7 +46,6 @@ stretch_mode = 6 [node name="Login" type="CenterContainer" parent="."] unique_name_in_owner = true -visible = false layout_mode = 1 anchors_preset = 15 anchor_right = 1.0 @@ -174,6 +173,7 @@ texture_hover = ExtResource("16_hqeko") [node name="CharacterSelection" type="CenterContainer" parent="."] unique_name_in_owner = true +visible = false layout_mode = 1 anchors_preset = 15 anchor_right = 1.0 @@ -305,6 +305,7 @@ stream = ExtResource("3_2nukd") [node name="ChatWindow" parent="." instance=ExtResource("4_ah2a1")] unique_name_in_owner = true +visible = false layout_mode = 1 anchors_preset = -1 anchor_top = 0.829 diff --git a/ui/login/login_character_selection_list.gd b/ui/login/login_character_selection_list.gd index 221c47f..bd19fa1 100644 --- a/ui/login/login_character_selection_list.gd +++ b/ui/login/login_character_selection_list.gd @@ -3,6 +3,7 @@ extends Control signal selected(slot_idx: int) +signal requested_login(slot_idx: int) var item_scene := preload("res://ui/login/character_selection_item.tscn") @@ -40,7 +41,6 @@ func set_selected_slot_index(value: int) -> void: if selected_slot_index == value: return - var character_list := login_character_list.character_information var maximum_slot_count := login_character_list.slot_count %CharacterList.get_child(selected_slot_index - slot_offset).is_selected = false @@ -57,13 +57,14 @@ func set_selected_slot_index(value: int) -> void: slot_offset = min(selected_slot_index, maximum_slot_count - displayed_slots_count) elif selected_slot_index < slot_offset: #slot_offset = selected_slot_index - slot_offset = max(0, selected_slot_index - displayed_slots_count) + slot_offset = max(0, selected_slot_index - (displayed_slots_count - 1)) draw() %CharacterList.get_child(selected_slot_index - slot_offset).is_selected = true - if selected_slot_index < character_list.size(): - %CharacterSelectionStatus.set_info(character_list[selected_slot_index]) + var info = login_character_list.get_info_for_slot(selected_slot_index) + if info: + %CharacterSelectionStatus.set_info(info) else: $CharacterSelectionStatus.clear() @@ -79,14 +80,12 @@ func draw(): if not login_character_list: return - var character_information: Array[CharacterInformation] = login_character_list.character_information - for display_slot_idx in displayed_slots_count: var item: CharacterSelectionItem = %CharacterList.get_child(display_slot_idx) var slot_idx = slot_offset + display_slot_idx - if slot_idx < character_information.size(): - var info: CharacterInformation = character_information[slot_idx] + var info = login_character_list.get_info_for_slot(slot_idx) + if info: item.initialize_with_info(info) else: item.clear() @@ -94,6 +93,10 @@ func draw(): if item.selected.is_connected(_on_item_selected): item.selected.disconnect(_on_item_selected) item.selected.connect(_on_item_selected.bind(slot_idx)) + + if item.gui_input.is_connected(_on_item_gui_input): + item.gui_input.disconnect(_on_item_gui_input) + item.gui_input.connect(_on_item_gui_input.bind(slot_idx)) func select(slot_idx: int): @@ -104,6 +107,21 @@ func _on_item_selected(slot_idx: int): selected_slot_index = slot_idx +func _on_item_gui_input(event: InputEvent, slot_idx: int) -> void: + if event is InputEventMouseButton and event.double_click: + requested_login.emit(slot_idx) + + +func _input(event: InputEvent) -> void: + if event.is_action_pressed("ui_accept"): + requested_login.emit(selected_slot_index) + + if event.is_action_pressed("ui_left"): + %ButtonLeft.pressed.emit() + if event.is_action_pressed("ui_right"): + %ButtonRight.pressed.emit() + + func _on_button_left_pressed() -> void: selected_slot_index -= 1 diff --git a/ui/login/login_character_selection_list.tscn b/ui/login/login_character_selection_list.tscn index 1a5aba7..391ed63 100644 --- a/ui/login/login_character_selection_list.tscn +++ b/ui/login/login_character_selection_list.tscn @@ -27,6 +27,7 @@ theme_override_constants/separation = 16 alignment = 1 [node name="ButtonLeft" parent="MarginContainer/HBoxContainer" instance=ExtResource("2_s7n6r")] +unique_name_in_owner = true texture_filter = 0 layout_mode = 2 texture_normal = ExtResource("3_c5a25") @@ -46,6 +47,7 @@ layout_mode = 2 layout_mode = 2 [node name="ButtonRight" parent="MarginContainer/HBoxContainer" instance=ExtResource("2_s7n6r")] +unique_name_in_owner = true texture_filter = 0 layout_mode = 2 texture_normal = ExtResource("7_c8nb3") -- cgit v1.2.3