This repository has been archived on 2023-12-19. You can view files and clone it, but cannot push or open issues or pull requests.
MUR/scripts/menus/server_create_menu.gd

47 lines
1.3 KiB
GDScript3
Raw Normal View History

extends Control
func _ready():
var player_name = config.get_value("game","player_name", false)
var game_title = "New Game"
if player_name:
game_title += " by " + player_name
find_node("name").set_text(game_title)
find_node("bots").set_pressed(config.get_value("game","bots", true))
func _draw():
find_node("create").grab_focus()
func _on_create_pressed():
var req = game_server.http()
req.connect_http(self,"_on_game_created")
var server_name = find_node("name").text
var bots = 0
if find_node("bots").is_pressed():
bots = 1
req.post_request('client/game/create', to_json({'name' : server_name, 'bots' : bots}))
func _on_game_created(result, response_code, headers, body):
if result == OK && response_code == HTTPClient.RESPONSE_OK:
var json = JSON.parse(body.get_string_from_utf8())
gamestate.game_name = json.result['name']
client.join_game(game_server.get_server_addr(), int(json.result['port']))
else:
get_tree().get_root().get_node("multiplayer_menu").show_error_dialog(tr("ERROR_GAME_CREATION"))
queue_free()
func _on_name_text_changed(new_text):
if new_text:
find_node("create").set_disabled(false)
else:
find_node("create").set_disabled(true)
func _on_back_pressed():
queue_free()
get_tree().get_root().get_node("multiplayer_menu").show()