|
|
|
@ -21,11 +21,15 @@ var player_count = 3 |
|
|
|
|
var button_selected = null |
|
|
|
|
var mouse_click_mode = null |
|
|
|
|
|
|
|
|
|
var stocks_ui = [] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _ready(): |
|
|
|
|
randomize() |
|
|
|
|
_setup_players() |
|
|
|
|
_setup_countries() |
|
|
|
|
_setup_turns() |
|
|
|
|
_setup_stock_ui() |
|
|
|
|
|
|
|
|
|
turn = turns[turn_id] |
|
|
|
|
_on_EndTurnButton_pressed() |
|
|
|
@ -73,6 +77,58 @@ func _setup_turns(): |
|
|
|
|
object = country |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
func _setup_stock_ui(): |
|
|
|
|
stocks_ui.append({}) |
|
|
|
|
for country in countries: |
|
|
|
|
if country.id == 0: continue |
|
|
|
|
var name_lbl = Label.new() |
|
|
|
|
name_lbl.text = country.name |
|
|
|
|
var stock_price_lbl = Label.new() |
|
|
|
|
stock_price_lbl.text = str(country.stock_price) |
|
|
|
|
var stock_lbl = Label.new() |
|
|
|
|
stock_lbl.text = "??" |
|
|
|
|
var buy_btn = Button.new() |
|
|
|
|
buy_btn.text = "Buy" |
|
|
|
|
var sell_btn = Button.new() |
|
|
|
|
sell_btn.text = "Sell" |
|
|
|
|
|
|
|
|
|
stocks_ui.append({ |
|
|
|
|
stock_price_lbl = stock_price_lbl, |
|
|
|
|
stock_lbl = stock_lbl |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
buy_btn.connect("pressed", self, "_on_stock_buy_button_pressed", [country]) |
|
|
|
|
sell_btn.connect("pressed", self, "_on_stock_sell_button_pressed", [country]) |
|
|
|
|
|
|
|
|
|
$CanvasLayer/Control/VBoxContainer/Stocks.add_child(name_lbl) |
|
|
|
|
$CanvasLayer/Control/VBoxContainer/Stocks.add_child(stock_price_lbl) |
|
|
|
|
$CanvasLayer/Control/VBoxContainer/Stocks.add_child(stock_lbl) |
|
|
|
|
$CanvasLayer/Control/VBoxContainer/Stocks.add_child(buy_btn) |
|
|
|
|
$CanvasLayer/Control/VBoxContainer/Stocks.add_child(sell_btn) |
|
|
|
|
|
|
|
|
|
func _refresh_stock_ui(): |
|
|
|
|
for country in countries: |
|
|
|
|
if country.id == 0: continue |
|
|
|
|
var ui = stocks_ui[country.id] |
|
|
|
|
ui.stock_price_lbl.text = str(country.stock_price) |
|
|
|
|
ui.stock_lbl.text = str(turn.object.stocks[country.id]) |
|
|
|
|
|
|
|
|
|
func _on_stock_buy_button_pressed(country): |
|
|
|
|
if turn.object.money >= country.stock_price and country.total_stocks < 7: |
|
|
|
|
country.total_stocks += 1 |
|
|
|
|
turn.object.stocks[country.id] += 1 |
|
|
|
|
turn.object.money -= country.stock_price |
|
|
|
|
country.money += country.stock_price |
|
|
|
|
_refresh_stock_ui() |
|
|
|
|
|
|
|
|
|
func _on_stock_sell_button_pressed(country): |
|
|
|
|
if country.money >= country.stock_price and turn.object.stocks[country.id] > 0: |
|
|
|
|
country.total_stocks -= 1 |
|
|
|
|
turn.object.stocks[country.id] -= 1 |
|
|
|
|
turn.object.money += country.stock_price |
|
|
|
|
country.money -= country.stock_price |
|
|
|
|
_refresh_stock_ui() |
|
|
|
|
|
|
|
|
|
func _process(delta): |
|
|
|
|
$CanvasLayer/Control/VBoxContainer/CountryMoneyLabel.text = str(turns[turn_id].object.money) + "$" |
|
|
|
|
if turn.layer == "country": |
|
|
|
@ -81,14 +137,16 @@ func _process(delta): |
|
|
|
|
$CanvasLayer/Control/VBoxContainer/BuyFactory.visible = turn.layer == "country" |
|
|
|
|
$CanvasLayer/Control/VBoxContainer/BuyArmy.visible = turn.layer == "country" |
|
|
|
|
$CanvasLayer/Control/VBoxContainer/BuyBoat.visible = turn.layer == "country" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _on_EndTurnButton_pressed(): |
|
|
|
|
if turn.layer == "country": |
|
|
|
|
for army in turn.object.armies: |
|
|
|
|
army.entity.current_turn_movable = true |
|
|
|
|
for boat in turn.object.boats: |
|
|
|
|
boat.entity.current_turn_movable = true |
|
|
|
|
|
|
|
|
|
turn.object.compute_balance() |
|
|
|
|
$Grid.selected_thing = null |
|
|
|
|
|
|
|
|
@ -96,6 +154,8 @@ func _on_EndTurnButton_pressed(): |
|
|
|
|
if turn_id == len(turns): turn_id = 0 |
|
|
|
|
turn = turns[turn_id] |
|
|
|
|
|
|
|
|
|
if turn.layer == "player": |
|
|
|
|
_refresh_stock_ui() |
|
|
|
|
$CanvasLayer/Control/VBoxContainer/TurnLabel.text = turn.object.name + "'s turn." |
|
|
|
|
|
|
|
|
|
|
|
|
|
|