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

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))
find_node("bot_difficulty").set_value(config.get_value("game","bot_difficulty", gamestate.DEFAULT_BOT_DIFFICULTY))
find_node("bot_difficulty").set_editable(find_node("bots").is_pressed())
find_node("bot_difficulty").set_tooltip(tr("BOT_DIFFICULTY"))
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
var bot_difficulty = find_node("bot_difficulty").get_value()
req.post_request('client/game/create', to_json({'name' : server_name, 'bots' : bots, 'bot_difficulty' : bot_difficulty}))
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()
func _on_bots_toggled(button_pressed):
find_node("bot_difficulty").set_editable(button_pressed)