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.

46 lines
1.3 KiB

  1. extends Control
  2. func _ready():
  3. var player_name = config.get_value("game","player_name", false)
  4. var game_title = "New Game"
  5. if player_name:
  6. game_title += " by " + player_name
  7. find_node("name").set_text(game_title)
  8. find_node("bots").set_pressed(config.get_value("game","bots", true))
  9. func _draw():
  10. find_node("create").grab_focus()
  11. func _on_create_pressed():
  12. var req = game_server.http()
  13. req.connect_http(self,"_on_game_created")
  14. var server_name = find_node("name").text
  15. var bots = 0
  16. if find_node("bots").is_pressed():
  17. bots = 1
  18. req.post_request('client/game/create', to_json({'name' : server_name, 'bots' : bots}))
  19. func _on_game_created(result, response_code, headers, body):
  20. if result == OK && response_code == HTTPClient.RESPONSE_OK:
  21. var json = JSON.parse(body.get_string_from_utf8())
  22. gamestate.game_name = json.result['name']
  23. client.join_game(game_server.get_server_addr(), int(json.result['port']))
  24. else:
  25. get_tree().get_root().get_node("multiplayer_menu").show_error_dialog(tr("ERROR_GAME_CREATION"))
  26. queue_free()
  27. func _on_name_text_changed(new_text):
  28. if new_text:
  29. find_node("create").set_disabled(false)
  30. else:
  31. find_node("create").set_disabled(true)
  32. func _on_back_pressed():
  33. queue_free()
  34. get_tree().get_root().get_node("multiplayer_menu").show()