2019-10-28 18:38:36 +02:00
local WD = require " modules.wave_defense.table "
2019-10-14 06:52:17 +02:00
local function create_gui ( player )
local frame = player.gui . top.add ( { type = " frame " , name = " wave_defense " } )
frame.style . maximal_height = 38
local label = frame.add ( { type = " label " , caption = " " , name = " label " } )
label.style . font_color = { r = 0.88 , g = 0.88 , b = 0.88 }
label.style . font = " default-bold "
label.style . left_padding = 4
label.style . right_padding = 4
label.style . minimal_width = 68
label.style . font_color = { r = 0.33 , g = 0.66 , b = 0.9 }
local progressbar = frame.add ( { type = " progressbar " , name = " progressbar " , value = 0 } )
2019-10-25 08:09:39 +02:00
progressbar.style . minimal_width = 96
progressbar.style . maximal_width = 96
2019-10-14 06:52:17 +02:00
progressbar.style . top_padding = 10
local line = frame.add ( { type = " line " , direction = " vertical " } )
line.style . left_padding = 4
line.style . right_padding = 4
2019-10-28 14:29:15 +02:00
2019-10-14 06:52:17 +02:00
local label = frame.add ( { type = " label " , caption = " " , name = " threat " , tooltip = " high threat may empower biters " } )
label.style . font = " default-bold "
label.style . left_padding = 4
2019-10-28 14:29:15 +02:00
label.style . right_padding = 1
2019-10-14 06:52:17 +02:00
label.style . minimal_width = 10
2019-10-28 14:29:15 +02:00
label.style . font_color = { r = 150 , g = 0 , b = 255 }
local label = frame.add ( { type = " label " , caption = " " , name = " threat_gains " , tooltip = " gain / minute " } )
label.style . font = " default "
label.style . left_padding = 1
label.style . right_padding = 1
end
--display threat gain/loss per minute during last 15 minutes
local function get_threat_gain ( )
2019-10-28 18:38:36 +02:00
local wave_defense_table = WD.get_table ( )
local past_index = wave_defense_table.threat_log_index - 900
2019-10-28 14:29:15 +02:00
if past_index < 1 then past_index = 1 end
2019-10-28 18:38:36 +02:00
local gain = math.floor ( ( wave_defense_table.threat_log [ wave_defense_table.threat_log_index ] - wave_defense_table.threat_log [ past_index ] ) / 15 )
2019-10-28 14:29:15 +02:00
return gain
2019-10-14 06:52:17 +02:00
end
local function update_gui ( player )
2019-10-28 18:38:36 +02:00
local wave_defense_table = WD.get_table ( )
2019-10-14 06:52:17 +02:00
if not player.gui . top.wave_defense then create_gui ( player ) end
2019-10-28 18:38:36 +02:00
player.gui . top.wave_defense . label.caption = " Wave: " .. wave_defense_table.wave_number
if wave_defense_table.wave_number == 0 then player.gui . top.wave_defense . label.caption = " First wave in " .. math.floor ( ( wave_defense_table.next_wave - game.tick ) / 60 ) + 1 end
local interval = wave_defense_table.next_wave - wave_defense_table.last_wave
player.gui . top.wave_defense . progressbar.value = 1 - ( wave_defense_table.next_wave - game.tick ) / interval
2019-10-28 14:29:15 +02:00
2019-10-28 18:38:36 +02:00
player.gui . top.wave_defense . threat.caption = " Threat: " .. math.floor ( wave_defense_table.threat )
2019-10-28 14:29:15 +02:00
2019-10-28 18:38:36 +02:00
if wave_defense_table.wave_number == 0 then
2019-10-28 14:29:15 +02:00
player.gui . top.wave_defense . threat_gains.caption = " "
return
end
local gain = get_threat_gain ( )
2019-10-28 18:38:36 +02:00
local d = wave_defense_table.wave_number / 75
2019-10-28 14:29:15 +02:00
if gain >= 0 then
player.gui . top.wave_defense . threat_gains.caption = " (+ " .. gain .. " ) "
local g = 255 - math.floor ( gain / d )
if g < 0 then g = 0 end
player.gui . top.wave_defense . threat_gains.style . font_color = { 255 , g , 0 }
else
player.gui . top.wave_defense . threat_gains.caption = " ( " .. gain .. " ) "
local r = 255 - math.floor ( math.abs ( gain ) / d )
if r < 0 then r = 0 end
player.gui . top.wave_defense . threat_gains.style . font_color = { r , 255 , 0 }
end
2019-10-14 06:52:17 +02:00
end
return update_gui