2018-04-06 21:58:50 +02:00
|
|
|
local Event = require "utils.event"
|
2018-09-23 00:25:13 +02:00
|
|
|
local Game = require 'utils.game'
|
2018-04-06 21:58:50 +02:00
|
|
|
|
2017-06-13 13:16:07 +02:00
|
|
|
if not global.score_rockets_launched then global.score_rockets_launched = 0 end
|
|
|
|
|
|
|
|
local function create_score_gui(event)
|
2018-09-22 22:07:05 +02:00
|
|
|
local player = Game.players[event.player_index]
|
2017-12-15 18:52:26 +02:00
|
|
|
|
2017-06-13 13:16:07 +02:00
|
|
|
if player.gui.top.score == nil then
|
2017-12-15 18:52:26 +02:00
|
|
|
local button = player.gui.top.add({ type = "sprite-button", name = "score", sprite = "item/rocket-silo" })
|
2017-06-13 13:16:07 +02:00
|
|
|
button.style.minimal_height = 38
|
|
|
|
button.style.minimal_width = 38
|
|
|
|
button.style.top_padding = 2
|
|
|
|
button.style.left_padding = 4
|
|
|
|
button.style.right_padding = 4
|
|
|
|
button.style.bottom_padding = 2
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function refresh_score()
|
|
|
|
local x = 1
|
2018-09-22 22:07:05 +02:00
|
|
|
while (Game.players[x] ~= nil) do
|
|
|
|
local player = Game.players[x]
|
2017-12-15 18:52:26 +02:00
|
|
|
local frame = player.gui.top["score_panel"]
|
|
|
|
|
|
|
|
if (frame) then
|
2017-06-13 13:16:07 +02:00
|
|
|
frame.score_table.label_rockets_launched.caption = "Rockets launched: " .. global.score_rockets_launched
|
2017-12-15 18:52:26 +02:00
|
|
|
frame.score_table.label_biters_killed.caption = "Biters liberated: " .. global.score_biter_total_kills
|
2017-06-13 13:16:07 +02:00
|
|
|
-- frame.score_table.label_score_polls_created.caption = "Polls created: " .. global.score_total_polls_created
|
|
|
|
end
|
|
|
|
x = x + 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function score_show(player)
|
|
|
|
|
|
|
|
local rocket_score_value_string = tostring(global.score_rockets_launched)
|
|
|
|
|
|
|
|
local frame = player.gui.top.add { type = "frame", name = "score_panel" }
|
2017-12-15 18:52:26 +02:00
|
|
|
|
|
|
|
local score_table = frame.add { type = "table", column_count = 5, name = "score_table" }
|
|
|
|
local label = score_table.add { type = "label", caption = "", name = "label_rockets_launched" }
|
|
|
|
label.style.font = "default-bold"
|
2017-06-13 13:16:07 +02:00
|
|
|
label.style.font_color = { r=0.98, g=0.66, b=0.22}
|
|
|
|
label.style.top_padding = 2
|
|
|
|
label.style.left_padding = 4
|
|
|
|
label.style.right_padding = 4
|
2017-12-15 18:52:26 +02:00
|
|
|
|
|
|
|
score_table.add { type = "label", caption = "|"}
|
|
|
|
|
|
|
|
local label = score_table.add { type = "label", caption = "", name = "label_biters_killed" }
|
|
|
|
label.style.font = "default-bold"
|
2017-06-13 13:16:07 +02:00
|
|
|
label.style.font_color = { r=0.98, g=0.11, b=0.11}
|
|
|
|
label.style.top_padding = 2
|
|
|
|
label.style.left_padding = 4
|
|
|
|
label.style.right_padding = 4
|
2017-12-15 18:52:26 +02:00
|
|
|
--[[
|
2017-06-13 13:16:07 +02:00
|
|
|
if global.score_total_polls_created then
|
2017-12-15 18:52:26 +02:00
|
|
|
score_table.add { type = "label", caption = "|"}
|
|
|
|
|
|
|
|
local label = score_table.add { type = "label", caption = "", name = "label_score_polls_created" }
|
|
|
|
label.style.font = "default-bold"
|
2017-06-13 13:16:07 +02:00
|
|
|
label.style.font_color = { r=0.80, g=0.80, b=0.80}
|
|
|
|
label.style.top_padding = 2
|
|
|
|
label.style.left_padding = 4
|
|
|
|
label.style.right_padding = 4
|
|
|
|
end
|
2017-12-15 18:52:26 +02:00
|
|
|
--]]
|
2017-06-13 13:16:07 +02:00
|
|
|
refresh_score()
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
local function on_gui_click(event)
|
|
|
|
if not (event and event.element and event.element.valid) then return end
|
2017-12-15 18:52:26 +02:00
|
|
|
|
2018-09-22 22:07:05 +02:00
|
|
|
local player = Game.players[event.element.player_index]
|
2017-12-15 18:52:26 +02:00
|
|
|
local name = event.element.name
|
|
|
|
local frame = player.gui.top["score_panel"]
|
|
|
|
|
2017-06-13 13:16:07 +02:00
|
|
|
if (name == "score") and (frame == nil) then
|
|
|
|
score_show(player)
|
|
|
|
else
|
|
|
|
if (name == "score") then
|
|
|
|
frame.destroy()
|
|
|
|
end
|
|
|
|
end
|
2017-12-15 18:52:26 +02:00
|
|
|
|
2017-06-13 13:16:07 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
local function rocket_launched(event)
|
|
|
|
global.score_rockets_launched = global.score_rockets_launched + 1
|
2017-12-15 18:52:26 +02:00
|
|
|
game.print ("A rocket has been launched!")
|
2017-06-13 13:16:07 +02:00
|
|
|
refresh_score()
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-04-06 21:58:50 +02:00
|
|
|
Event.add(defines.events.on_entity_died, refresh_score)
|
|
|
|
Event.add(defines.events.on_gui_click, on_gui_click)
|
|
|
|
Event.add(defines.events.on_player_joined_game, create_score_gui)
|
|
|
|
Event.add(defines.events.on_rocket_launched, rocket_launched)
|