Public repository for MUR pre alpha
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

101 lines
3.1 KiB

  1. extends Control
  2. onready var countdown_timer = get_node("countdown_timer")
  3. onready var player_settings = find_node("player_settings")
  4. onready var player_list = find_node("players")
  5. func _ready():
  6. if get_tree().get_root().has_node("multiplayer_menu"):
  7. get_tree().get_root().get_node("multiplayer_menu").hide()
  8. if get_tree().get_root().has_node("main_menu"):
  9. get_tree().get_root().get_node("main_menu").hide()
  10. get_node("menu/back").connect("pressed",self,"_on_back_pressed")
  11. gamestate.connect("players_changed", self, "_players_changed")
  12. gamestate.connect("game_ready", self, "_game_ready")
  13. gamestate.connect("game_started", self, "_game_started")
  14. client.connect("server_disconnected", self, "_server_disconnected")
  15. player_settings.get_name_node().connect("text_changed",self,"_on_name_text_changed")
  16. player_settings.get_color_node().connect("color_changed",self,"_on_color_color_changed")
  17. player_settings.get_color_node().connect("draw",self,"_on_player_changed")
  18. countdown_timer.set_wait_time(server.LOBBY_READY_WAIT_TIME)
  19. if gamestate.game_name:
  20. find_node("server_name").set_text(gamestate.game_name)
  21. find_node("server_name").set_tooltip(gamestate.game_name)
  22. func _draw():
  23. find_node("ready").grab_focus()
  24. func _physics_process(delta):
  25. if not countdown_timer.is_stopped():
  26. get_node("countdown").text = str(int(countdown_timer.get_time_left()) + 1)
  27. func _players_changed(players):
  28. player_list.clear()
  29. for p_id in players:
  30. var player = players[p_id]
  31. if p_id == get_tree().get_network_unique_id():
  32. player_list.add_item(player.name + " (You)")
  33. else:
  34. player_list.add_item(player.name)
  35. player_list.set_item_custom_bg_color(player_list.get_item_count()-1, player.color)
  36. if player.ready:
  37. player_list.set_item_icon(player_list.get_item_count()-1, player_list.get_node("ready_icon").get_button_icon())
  38. else:
  39. player_list.set_item_icon(player_list.get_item_count()-1, player_list.get_node("not_ready_icon").get_button_icon())
  40. find_node("server_bots").set_pressed(gamestate.bots)
  41. func _game_ready(all_ready):
  42. if all_ready:
  43. get_node("countdown").show()
  44. countdown_timer.start()
  45. else:
  46. countdown_timer.stop()
  47. get_node("countdown").hide()
  48. func _game_started():
  49. queue_free()
  50. func _on_name_text_changed(new_text):
  51. _on_player_changed()
  52. func _on_color_color_changed(color):
  53. _on_player_changed()
  54. func _on_ready_toggled(button_pressed):
  55. _on_player_changed()
  56. player_settings.get_name_node().set_editable(not button_pressed)
  57. player_settings.get_color_node().set_disabled(button_pressed)
  58. func _on_player_changed():
  59. var name = player_settings.get_name_node().text
  60. var color = player_settings.get_color_node().color
  61. var ready = find_node("ready").pressed
  62. gamestate.update_player(name,color,ready)
  63. func _on_back_pressed():
  64. gamestate.quit_game()
  65. if get_tree().get_root().has_node("multiplayer_menu"):
  66. get_tree().get_root().get_node("multiplayer_menu").show()
  67. get_tree().get_root().get_node("main_menu").hide()
  68. elif get_tree().get_root().has_node("main_menu"):
  69. get_tree().get_root().get_node("main_menu").show()
  70. queue_free()
  71. func _server_disconnected():
  72. _on_back_pressed()