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.

104 lines
3.2 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. var port = null # Defined by command-line argument with default
  3. onready var hero_select = get_node("HeroSelect/Hero")
  4. onready var level_select = get_node("LevelSelect")
  5. onready var start_game_button = get_node("StartGame")
  6. onready var ready_button = get_node("Ready")
  7. func _ready():
  8. get_node("Username").connect("text_changed", self, "_send_name")
  9. var spectating = util.args.get_value("-silent")
  10. get_node("Spectating").pressed = spectating
  11. get_node("Spectating").connect("toggled", self, "_set_info_callback", ["spectating"])
  12. ready_button.connect("toggled", self, "_set_info_callback", ["ready"])
  13. start_game_button.connect("pressed", networking, "start_game")
  14. get_node("Back").connect("pressed", self, "_exit_to_menu")
  15. # Shown, maybe, in _check_begun
  16. start_game_button.hide()
  17. if get_tree().is_network_server():
  18. start_game_button.show()
  19. if get_tree().is_network_server():
  20. # We put level in our players dict because it's automatically broadcast to other players
  21. var level = util.args.get_value("-level")
  22. if level == "r":
  23. level = randi() % level_select.get_item_count()
  24. level = int(level)
  25. _set_level(level)
  26. level_select.show()
  27. level_select.select(level)
  28. level_select.connect("item_selected", self, "_set_level")
  29. else:
  30. level_select.hide()
  31. networking.connect("info_updated", self, "render_player_list")
  32. get_tree().connect("connected_to_server", self, "_connected")
  33. if get_tree().is_network_server():
  34. _connected()
  35. func _connected():
  36. _send_name()
  37. if util.args.get_value("-hero") == "r":
  38. hero_select.random_hero()
  39. else:
  40. print(util.args.get_value("-hero"))
  41. hero_select.set_hero(int(util.args.get_value("-hero")))
  42. if util.args.get_value("-start-game"):
  43. networking.start_game()
  44. func _set_level(level):
  45. networking.level = level
  46. # Because of the annoying way callbacks work (automatic parameter, optional parameter)
  47. # We need a utility function for making these kinds of callbacks for set_info
  48. func _set_info_callback(value, key):
  49. networking.set_info(key, value)
  50. sync func set_hero(peer, hero):
  51. networking.players[peer].hero = hero
  52. render_player_list()
  53. func _send_name():
  54. var name = get_node("Username").text
  55. networking.set_info("username", name)
  56. func _check_begun():
  57. var game_started = networking.players[1].begun
  58. if game_started:
  59. start_game_button.show()
  60. # The "Ready" toggle doesn't really make sense on a started game
  61. ready_button.hide()
  62. func render_player_list():
  63. _check_begun()
  64. var list = ""
  65. var hero_names = hero_select.hero_names
  66. for p in networking.players:
  67. var player = networking.players[p]
  68. # A spectating server is just a dedicated server, ignore it
  69. if not (player.spectating and p == 1):
  70. list += "%-15s " % player.username
  71. list += "%-10s " % hero_names[player.hero]
  72. var team_format = "%-11s"
  73. if player.is_right_team:
  74. list += team_format % "Right Team"
  75. else:
  76. list += team_format % "Left Team"
  77. var ready_text = "Ready" if player.ready else ""
  78. list += "%-6s" % ready_text
  79. if player.spectating:
  80. list += "Spectating"
  81. list += "\n"
  82. get_node("PlayerList").set_text(list)
  83. func _exit_to_menu():
  84. get_tree().network_peer.close_connection()
  85. get_tree().change_scene("res://scenes/menu.tscn")