Add private multiplayer room codes
This commit is contained in:
1 parent
7362ca0f02
commit
19b1a67773
8 files changed
+341
-24
No files matched your search
@@ -137,7 +137,10 @@ var friend_match_button := Rect2(475, 665, 300, 64)
|
||||
var private_match_button := Rect2(825, 665, 300, 64)
|
||||
var ai_match_button := Rect2(1175, 665, 300, 64)
|
||||
var cancel_search_button := Rect2(625, 650, 350, 64)
|
||||
var room_code_input_rect := Rect2(510, 340, 580, 90)
|
||||
var join_room_button := Rect2(625, 525, 350, 64)
|
||||
var coop_side_button := Rect2(920, 18, 140, 54)
|
||||
var room_code_input := ""
|
||||
|
||||
@onready var ads_manager = $AdsManager
|
||||
@onready var account_manager = $AccountManager
|
||||
@@ -366,6 +369,20 @@ func _update_effects(delta: float) -> void:
|
||||
|
||||
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
if game_mode == "room_code_entry" and event is InputEventKey and event.pressed and not event.echo:
|
||||
if event.keycode == KEY_ESCAPE:
|
||||
_hide_virtual_keyboard()
|
||||
game_mode = "multiplayer_menu"
|
||||
elif event.keycode == KEY_BACKSPACE:
|
||||
room_code_input = room_code_input.left(maxi(0, room_code_input.length() - 1))
|
||||
elif event.keycode == KEY_ENTER:
|
||||
_join_entered_room()
|
||||
elif event.unicode > 0 and room_code_input.length() < 6:
|
||||
var character := char(event.unicode).to_upper()
|
||||
if "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".contains(character):
|
||||
room_code_input += character
|
||||
queue_redraw()
|
||||
return
|
||||
if event is InputEventKey and event.pressed and not event.echo and event.keycode in [KEY_P, KEY_ESCAPE] and game_mode in ["playing", "paused"]:
|
||||
_toggle_pause()
|
||||
return
|
||||
@@ -409,13 +426,23 @@ func _handle_pointer(position: Vector2, is_touch := false) -> void:
|
||||
elif quick_match_button.has_point(position):
|
||||
_open_matchmaking("quick")
|
||||
elif friend_match_button.has_point(position):
|
||||
_open_matchmaking("friend")
|
||||
_open_room_code_entry()
|
||||
elif private_match_button.has_point(position):
|
||||
_open_matchmaking("private")
|
||||
_open_private_room()
|
||||
elif ai_match_button.has_point(position):
|
||||
_start_coop_ai_game()
|
||||
queue_redraw()
|
||||
return
|
||||
if game_mode == "room_code_entry":
|
||||
if multiplayer_back_button.has_point(position):
|
||||
_hide_virtual_keyboard()
|
||||
game_mode = "multiplayer_menu"
|
||||
elif room_code_input_rect.has_point(position):
|
||||
_show_room_code_keyboard()
|
||||
elif join_room_button.has_point(position):
|
||||
_join_entered_room()
|
||||
queue_redraw()
|
||||
return
|
||||
if game_mode == "matchmaking":
|
||||
if cancel_search_button.has_point(position) or multiplayer_back_button.has_point(position):
|
||||
multiplayer_manager.cancel_search()
|
||||
@@ -607,6 +634,41 @@ func _open_matchmaking(mode: String) -> void:
|
||||
queue_redraw()
|
||||
|
||||
|
||||
func _open_private_room() -> void:
|
||||
multiplayer_manager.reset_coop_session(int(_difficulty().start_credits), 30)
|
||||
multiplayer_manager.create_private_room(selected_difficulty)
|
||||
game_mode = "matchmaking"
|
||||
queue_redraw()
|
||||
|
||||
|
||||
func _open_room_code_entry() -> void:
|
||||
room_code_input = ""
|
||||
game_mode = "room_code_entry"
|
||||
_show_room_code_keyboard()
|
||||
queue_redraw()
|
||||
|
||||
|
||||
func _join_entered_room() -> void:
|
||||
if room_code_input.length() != 6:
|
||||
_show_status("DER RAUMCODE MUSS SECHS ZEICHEN HABEN")
|
||||
return
|
||||
_hide_virtual_keyboard()
|
||||
multiplayer_manager.reset_coop_session(int(_difficulty().start_credits), 30)
|
||||
multiplayer_manager.join_private_room(room_code_input)
|
||||
game_mode = "matchmaking"
|
||||
queue_redraw()
|
||||
|
||||
|
||||
func _show_room_code_keyboard() -> void:
|
||||
if DisplayServer.has_feature(DisplayServer.FEATURE_VIRTUAL_KEYBOARD):
|
||||
DisplayServer.virtual_keyboard_show(room_code_input, room_code_input_rect, DisplayServer.KEYBOARD_TYPE_DEFAULT, 6, room_code_input.length(), room_code_input.length())
|
||||
|
||||
|
||||
func _hide_virtual_keyboard() -> void:
|
||||
if DisplayServer.has_feature(DisplayServer.FEATURE_VIRTUAL_KEYBOARD):
|
||||
DisplayServer.virtual_keyboard_hide()
|
||||
|
||||
|
||||
func _start_game() -> void:
|
||||
coop_online_mode = false
|
||||
credits = int(_difficulty().start_credits)
|
||||
@@ -1111,7 +1173,7 @@ func _load_progress() -> void:
|
||||
|
||||
|
||||
func _draw() -> void:
|
||||
if game_mode in ["menu", "profile", "multiplayer_menu", "matchmaking"]:
|
||||
if game_mode in ["menu", "profile", "multiplayer_menu", "room_code_entry", "matchmaking"]:
|
||||
draw_texture_rect(MAP_TEXTURES[selected_map], Rect2(Vector2.ZERO, SCREEN), false, Color("f3f6fb"))
|
||||
draw_rect(Rect2(Vector2.ZERO, SCREEN), Color(0.01, 0.025, 0.055, 0.06))
|
||||
if game_mode == "menu":
|
||||
@@ -1120,6 +1182,8 @@ func _draw() -> void:
|
||||
_draw_profile()
|
||||
elif game_mode == "multiplayer_menu":
|
||||
_draw_multiplayer_menu()
|
||||
elif game_mode == "room_code_entry":
|
||||
_draw_room_code_entry()
|
||||
else:
|
||||
_draw_matchmaking()
|
||||
return
|
||||
@@ -1426,14 +1490,30 @@ func _draw_multiplayer_menu() -> void:
|
||||
draw_string(font, Vector2(945, 225), "MITSPIELER • ENERGIE %d" % multiplayer_manager.player_credits[1], HORIZONTAL_ALIGNMENT_RIGHT, 440, 17, Color("ffcf7a"))
|
||||
draw_string(font, Vector2(570, 555), "REAKTORLEBEN %02d • GETRENNTE RESSOURCEN" % multiplayer_manager.shared_reactor_lives, HORIZONTAL_ALIGNMENT_CENTER, 460, 16, Color.WHITE)
|
||||
_draw_button(quick_match_button, "SCHNELLES SPIEL", false, Color("185f68"))
|
||||
_draw_button(friend_match_button, "MIT FREUND SPIELEN", false, Color("254f75"))
|
||||
_draw_button(private_match_button, "PRIVATES SPIEL", false, Color("493f67"))
|
||||
_draw_button(friend_match_button, "RAUM BEITRETEN", false, Color("254f75"))
|
||||
_draw_button(private_match_button, "RAUM ERSTELLEN", false, Color("493f67"))
|
||||
_draw_button(ai_match_button, "MIT KI-PARTNER", false, Color("6b4b28"))
|
||||
var service_text := "GERGAMES-SERVER VERBUNDEN • ONLINE-KOOP IST SPIELBEREIT" if online_manager.is_online() else "VERBINDUNG ZUM GERGAMES-SERVER WIRD AUTOMATISCH AUFGEBAUT"
|
||||
var service_color := Color("83ffc8") if online_manager.is_online() else Color("ffcf7a")
|
||||
draw_string(font, Vector2(0, 770), service_text, HORIZONTAL_ALIGNMENT_CENTER, 1600, 15, service_color)
|
||||
|
||||
|
||||
func _draw_room_code_entry() -> void:
|
||||
var font := ThemeDB.fallback_font
|
||||
draw_rect(Rect2(Vector2.ZERO, SCREEN), Color(0.005, 0.015, 0.035, 0.88))
|
||||
_draw_button(multiplayer_back_button, "< ZURÜCK", false, Color("26394a"))
|
||||
draw_string(font, Vector2(0, 205), "PRIVATEN RAUM BEITRETEN", HORIZONTAL_ALIGNMENT_CENTER, 1600, 42, Color("c7f5ff"))
|
||||
draw_string(font, Vector2(0, 260), "GIB DEN SECHSSTELLIGEN CODE DEINES MITPILOTEN EIN", HORIZONTAL_ALIGNMENT_CENTER, 1600, 17, Color("66dff3"))
|
||||
draw_rect(room_code_input_rect, Color(0.01, 0.035, 0.065, 0.98), true)
|
||||
draw_rect(room_code_input_rect, Color("65eaff") if room_code_input.length() == 6 else Color("39788e"), false, 3.0)
|
||||
var shown_code := room_code_input
|
||||
if shown_code.is_empty():
|
||||
shown_code = "------"
|
||||
draw_string(font, Vector2(room_code_input_rect.position.x, room_code_input_rect.position.y + 61), " ".join(shown_code.split("")), HORIZONTAL_ALIGNMENT_CENTER, room_code_input_rect.size.x, 38, Color("8ffaff") if not room_code_input.is_empty() else Color("688293"))
|
||||
draw_string(font, Vector2(0, 470), "BUCHSTABEN UND ZAHLEN • GROSS-/KLEINSCHREIBUNG IST EGAL", HORIZONTAL_ALIGNMENT_CENTER, 1600, 14, Color("9fdce9"))
|
||||
_draw_button(join_room_button, "RAUM BEITRETEN", room_code_input.length() == 6, Color("185f68") if room_code_input.length() == 6 else Color("26394a"))
|
||||
|
||||
|
||||
func _draw_coop_lane_preview(mirrored: bool) -> void:
|
||||
var points := PackedVector2Array([Vector2(205, 300), Vector2(505, 300), Vector2(505, 385), Vector2(720, 385)])
|
||||
if mirrored:
|
||||
@@ -1453,13 +1533,17 @@ func _draw_matchmaking() -> void:
|
||||
var font := ThemeDB.fallback_font
|
||||
draw_rect(Rect2(Vector2.ZERO, SCREEN), Color(0.005, 0.015, 0.035, 0.88))
|
||||
_draw_button(multiplayer_back_button, "< ZURÜCK", false, Color("26394a"))
|
||||
draw_string(font, Vector2(0, 210), "MITSPIELERSUCHE", HORIZONTAL_ALIGNMENT_CENTER, 1600, 46, Color("c7f5ff"))
|
||||
var private_mode: bool = multiplayer_manager.matchmaking_mode in ["private_host", "private_join"]
|
||||
draw_string(font, Vector2(0, 210), "PRIVATER KOOP-RAUM" if private_mode else "MITSPIELERSUCHE", HORIZONTAL_ALIGNMENT_CENTER, 1600, 46, Color("c7f5ff"))
|
||||
var pulse := 56.0 + sin(elapsed * 3.0) * 8.0
|
||||
draw_arc(Vector2(800, 390), pulse, -PI * 0.2, PI * 1.45, 52, Color("65eaff"), 5.0)
|
||||
draw_circle(Vector2(800, 390), 22.0, Color("8ffaff"))
|
||||
var mode_labels := {"quick": "SCHNELLES SPIEL", "friend": "FREUND EINLADEN", "private": "PRIVATEN RAUM ERSTELLEN"}
|
||||
draw_string(font, Vector2(0, 500), mode_labels.get(multiplayer_manager.matchmaking_mode, "KOOP-SPIEL"), HORIZONTAL_ALIGNMENT_CENTER, 1600, 23, Color.WHITE)
|
||||
_draw_button(cancel_search_button, "SUCHE ABBRECHEN", false, Color("5c3342"))
|
||||
var mode_labels := {"quick": "SCHNELLES SPIEL", "private_host": "RAUM ERSTELLEN", "private_join": "RAUM BEITRETEN"}
|
||||
var mode_text: String = mode_labels.get(multiplayer_manager.matchmaking_mode, "KOOP-SPIEL")
|
||||
if not multiplayer_manager.private_room_code.is_empty():
|
||||
mode_text = "RAUMCODE %s" % " ".join(multiplayer_manager.private_room_code.split(""))
|
||||
draw_string(font, Vector2(0, 500), mode_text, HORIZONTAL_ALIGNMENT_CENTER, 1600, 23, Color.WHITE)
|
||||
_draw_button(cancel_search_button, "ZURÜCK" if multiplayer_manager.matchmaking_state == "room_not_found" else "SUCHE ABBRECHEN", false, Color("5c3342"))
|
||||
var online_text := "ONLINE • SUCHE NACH EINEM MITPILOTEN"
|
||||
var online_color := Color("83ffc8")
|
||||
if multiplayer_manager.matchmaking_state == "waiting_for_service":
|
||||
@@ -1471,6 +1555,18 @@ func _draw_matchmaking() -> void:
|
||||
elif multiplayer_manager.matchmaking_state == "matched":
|
||||
online_text = "MITPILOT GEFUNDEN • KOOP-SITZUNG BEREIT"
|
||||
online_color = Color("8ffaff")
|
||||
elif multiplayer_manager.matchmaking_state == "creating_room":
|
||||
online_text = "PRIVATER RAUM WIRD ERSTELLT ."
|
||||
online_color = Color("ffcf7a")
|
||||
elif multiplayer_manager.matchmaking_state == "hosting":
|
||||
online_text = "TEILE DEN RAUMCODE MIT DEINEM MITPILOTEN • WARTE AUF BEITRITT"
|
||||
online_color = Color("83ffc8")
|
||||
elif multiplayer_manager.matchmaking_state == "joining_room":
|
||||
online_text = "PRIVATER RAUM WIRD GESUCHT ."
|
||||
online_color = Color("ffcf7a")
|
||||
elif multiplayer_manager.matchmaking_state == "room_not_found":
|
||||
online_text = "RAUM NICHT GEFUNDEN ODER BEREITS VOLL"
|
||||
online_color = Color("ff8e8e")
|
||||
draw_rect(Rect2(180, 520, 1240, 44), Color(0.005, 0.015, 0.035, 0.98), true)
|
||||
draw_string(font, Vector2(0, 548), online_text, HORIZONTAL_ALIGNMENT_CENTER, 1600, 16, online_color)
|
||||
|
||||
|
||||
Reference in new issue
Block a user