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.

54 lines
1.7 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. find_node("bot_difficulty").set_value(config.get_value("game","bot_difficulty", gamestate.DEFAULT_BOT_DIFFICULTY))
  10. find_node("bot_difficulty").set_editable(find_node("bots").is_pressed())
  11. find_node("bot_difficulty").set_tooltip(tr("BOT_DIFFICULTY"))
  12. func _draw():
  13. find_node("create").grab_focus()
  14. func _on_create_pressed():
  15. var req = game_server.http()
  16. req.connect_http(self,"_on_game_created")
  17. var server_name = find_node("name").text
  18. var bots = 0
  19. if find_node("bots").is_pressed():
  20. bots = 1
  21. var bot_difficulty = find_node("bot_difficulty").get_value()
  22. req.post_request('client/game/create', to_json({'name' : server_name, 'bots' : bots, 'bot_difficulty' : bot_difficulty}))
  23. func _on_game_created(result, response_code, headers, body):
  24. if result == OK && response_code == HTTPClient.RESPONSE_OK:
  25. var json = JSON.parse(body.get_string_from_utf8())
  26. gamestate.game_name = json.result['name']
  27. client.join_game(game_server.get_server_addr(), int(json.result['port']))
  28. else:
  29. get_tree().get_root().get_node("multiplayer_menu").show_error_dialog(tr("ERROR_GAME_CREATION"))
  30. queue_free()
  31. func _on_name_text_changed(new_text):
  32. if new_text:
  33. find_node("create").set_disabled(false)
  34. else:
  35. find_node("create").set_disabled(true)
  36. func _on_back_pressed():
  37. queue_free()
  38. get_tree().get_root().get_node("multiplayer_menu").show()
  39. func _on_bots_toggled(button_pressed):
  40. find_node("bot_difficulty").set_editable(button_pressed)