A team game with an emphasis on movement (with no shooting), inspired by Overwatch and Zineth
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.

114 lines
3.7 KiB

[WIP] Split up lobby -> menu, lobby, custom_game lobby.gd had gotten big, bloated, ugly, and hard to read. It needed a refactor. The first thing I did is split up the *GUI* into the logical steps it should be. So the new flow is: - Start the game - Click "Quick Play" - Matchmaking begins on my dedicated server - Start the game - Click "Custom Game" - *Only now* am I presented with server / client options - Start the game - Click "Singleplayer" - Singleplayer NOW, and only now, and NO MATTER WHAT PATH I TAKE, I am taken to the *lobby*, which now is where I: - Choose my name - Choose hero - See list of players - Get my team assigned - Anything else that I might like to put in The point here is that this has *nothing* to do with handshaking / matchmaking / etc! This is just part of the game! At this point I have *already been connected* to the server. I've already been aquainted with my other players. The game has begun. I put the things that don't belong in any of these flows in networking.gd, a sort of model-view sorta thing. All of these flows use some sort of networking thing like `init_server` that tbh should be *completely* abstracted from the UI. It's totally a WIP!!! Above is the IDEA, but below is what I've actually *done*: - Made the scenes, made a passable UI for each one that at least indicates ~what they'll do - Made the corresponding scripts, and split up the lobby script into ABOUT where I think it'll end up, but no promises It still errors all over the place, and it's nowhere near properly organized. PLUS, I'd also like to rewrite a lot of the code / rename things as part of the initial refactor goal of making me able to actually think about networking.
7 years ago
  1. extends Control
  2. onready var hero_select = get_node("HeroSelect/Hero")
  3. onready var level_select = get_node("LevelSelect")
  4. onready var start_game_button = get_node("StartGame")
  5. onready var ready_button = get_node("Ready")
  6. func _ready():
  7. # Connect (to networking)
  8. get_node("Username").connect("text_changed", self, "_send_name")
  9. get_node("Spectating").connect("toggled", self, "_set_info_callback", ["spectating"])
  10. ready_button.connect("toggled", self, "_set_info_callback", ["ready"])
  11. start_game_button.connect("pressed", networking, "start_game")
  12. # Connect (from networking)
  13. networking.connect("info_updated", self, "_render_player_list")
  14. get_tree().connect("connected_to_server", self, "_connected")
  15. # Connect (static)
  16. get_node("Back").connect("pressed", self, "_exit_to_menu")
  17. var spectating = util.args.get_value("-silent")
  18. get_node("Spectating").pressed = spectating
  19. # Shown, maybe, in _check_begun
  20. start_game_button.hide()
  21. if get_tree().is_network_server():
  22. start_game_button.show()
  23. if get_tree().is_network_server():
  24. # We put level in our players dict because it's automatically broadcast to other players
  25. var level = util.args.get_value("-level")
  26. if level == "r":
  27. level = randi() % level_select.get_item_count()
  28. level = int(level)
  29. _set_level(level)
  30. level_select.show()
  31. level_select.select(level)
  32. level_select.connect("item_selected", self, "_set_level")
  33. else:
  34. level_select.hide()
  35. if get_tree().is_network_server():
  36. _connected()
  37. func _connected():
  38. _send_name()
  39. networking.set_info_from_server("ready", false)
  40. networking.set_info_from_server("spectating", util.args.get_value("-silent"))
  41. networking.set_info_from_server("begun", false)
  42. if util.args.get_value("-hero") == "r":
  43. hero_select.random_hero()
  44. else:
  45. hero_select.set_hero(int(util.args.get_value("-hero")))
  46. if util.args.get_value("-start-game"):
  47. networking.start_game()
  48. func _set_level(level):
  49. networking.level = level
  50. # Because of the annoying way callbacks work (automatic parameter, optional parameter)
  51. # We need a utility function for making these kinds of callbacks for set_info
  52. func _set_info_callback(value, key):
  53. networking.set_info_from_server(key, value)
  54. sync func set_hero(peer, hero):
  55. networking.players[peer].hero = hero
  56. _render_player_list()
  57. func _send_name():
  58. var name = get_node("Username").text
  59. networking.set_info_from_server("username", name)
  60. func _check_begun():
  61. if networking.players.has(1) and networking.players[1].has("begun"):
  62. var game_started = networking.players[1].begun
  63. if game_started:
  64. start_game_button.show()
  65. start_game_button.text = "Join game"
  66. # The "Ready" toggle doesn't really make sense on a started game
  67. ready_button.hide()
  68. func _render_player_list():
  69. _check_begun()
  70. var list = ""
  71. var hero_names = hero_select.hero_names
  72. for p in networking.players:
  73. var player = networking.players[p]
  74. # A spectating server is just a dedicated server, ignore it
  75. if p and player.has("spectating") and not (player.spectating and p == 1):
  76. var username = player.username if player.has("username") else "Loading..."
  77. list += "%-15s " % username
  78. var hero = hero_names[player.hero] if player.has("hero") else "Loading..."
  79. list += "%-10s " % hero
  80. var team = "Loading..."
  81. if player.has("is_right_team"):
  82. if player.is_right_team:
  83. team = "Right Team"
  84. else:
  85. team = "Left Team"
  86. list += "%-11s" % team
  87. var ready_text = "Ready" if player.has("ready") and player.ready else ""
  88. list += "%-6s" % ready_text
  89. if player.has("spectating") and player.spectating:
  90. list += "Spectating"
  91. list += "\n"
  92. get_node("PlayerList").set_text(list)
  93. func _exit_to_menu():
  94. get_tree().network_peer.close_connection()
  95. get_tree().change_scene("res://scenes/menu.tscn")