2019-07-28 13:32:28 +02:00
|
|
|
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))
|
2019-08-07 20:29:46 +02:00
|
|
|
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"))
|
2019-07-28 13:32:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
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
|
2019-08-07 20:29:46 +02:00
|
|
|
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}))
|
2019-07-28 13:32:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
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()
|
2019-08-07 20:29:46 +02:00
|
|
|
|
|
|
|
|
|
|
|
func _on_bots_toggled(button_pressed):
|
|
|
|
find_node("bot_difficulty").set_editable(button_pressed)
|