1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-24 03:47:58 +02:00

159 lines
5.7 KiB
Lua
Raw Normal View History

2021-11-14 21:01:01 +01:00
local Public = require 'modules.wave_defense.table'
2021-02-10 21:21:29 +01:00
local BiterHealthBooster = require 'modules.biter_health_booster_v2'
2019-10-28 17:38:36 +01:00
2021-11-23 20:28:23 +01:00
local floor = math.floor
2019-10-14 06:52:17 +02:00
local function create_gui(player)
2020-08-09 20:23:45 +02:00
local frame = player.gui.top.add({type = 'frame', name = 'wave_defense'})
2020-12-05 18:09:37 +01:00
frame.style.maximal_height = 37
2020-08-09 20:23:45 +02:00
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.font_color = {r = 0.33, g = 0.66, b = 0.9}
2021-03-24 20:14:55 +01:00
local wave_number_label = frame.add({type = 'label', caption = ' ', name = 'wave_number'})
wave_number_label.style.font_color = {r = 0.88, g = 0.88, b = 0.88}
wave_number_label.style.font = 'default-bold'
wave_number_label.style.right_padding = 4
wave_number_label.style.font_color = {r = 0.33, g = 0.66, b = 0.9}
2020-08-09 20:23:45 +02:00
local progressbar = frame.add({type = 'progressbar', name = 'progressbar', value = 0})
local experimental = get_game_version()
if experimental then
progressbar.style = 'achievement_progressbar'
progressbar.style.minimal_width = 96
progressbar.style.maximal_width = 96
progressbar.style.padding = -1
progressbar.style.top_padding = 1
else
progressbar.style.minimal_width = 96
progressbar.style.maximal_width = 96
progressbar.style.top_padding = 10
end
2020-08-09 20:23:45 +02:00
local line = frame.add({type = 'line', direction = 'vertical'})
line.style.left_padding = 4
line.style.right_padding = 4
2021-03-24 20:14:55 +01:00
local threat_label = frame.add({type = 'label', caption = ' ', name = 'threat', tooltip = {'wave_defense.tooltip_1'}})
threat_label.style.font = 'default-bold'
threat_label.style.left_padding = 4
threat_label.style.font_color = {r = 150, g = 0, b = 255}
2020-08-09 20:23:45 +02:00
2021-03-24 20:14:55 +01:00
local threat_value_label = frame.add({type = 'label', caption = ' ', name = 'threat_value', tooltip = {'wave_defense.tooltip_1'}})
threat_value_label.style.font = 'default-bold'
threat_value_label.style.right_padding = 1
threat_value_label.style.minimal_width = 10
threat_value_label.style.font_color = {r = 150, g = 0, b = 255}
2020-08-09 20:23:45 +02:00
2021-03-24 20:14:55 +01:00
local threat_gains_label = frame.add({type = 'label', caption = ' ', name = 'threat_gains', tooltip = {'wave_defense.tooltip_2'}})
threat_gains_label.style.font = 'default'
threat_gains_label.style.left_padding = 1
threat_gains_label.style.right_padding = 1
2019-10-28 13:29:15 +01:00
end
--display threat gain/loss per minute during last 15 minutes
local function get_threat_gain()
2021-11-14 21:01:01 +01:00
local threat_log_index = Public.get('threat_log_index')
local threat_log = Public.get('threat_log')
2020-11-17 12:45:47 +01:00
local past_index = threat_log_index - 900
2020-08-09 20:23:45 +02:00
if past_index < 1 then
past_index = 1
end
2021-11-23 20:28:23 +01:00
local gain = floor((threat_log[threat_log_index] - threat_log[past_index]) / 15)
2020-08-09 20:23:45 +02:00
return gain
2019-10-14 06:52:17 +02:00
end
2021-11-14 21:01:01 +01:00
function Public.update_gui(player)
2020-08-09 20:23:45 +02:00
if not player.gui.top.wave_defense then
create_gui(player)
end
local gui = player.gui.top.wave_defense
local biter_health_boost = 1
2021-02-10 21:21:29 +01:00
local biter_health_boosts = BiterHealthBooster.get('biter_health_boost')
if biter_health_boost then
biter_health_boost = biter_health_boosts
2020-08-09 20:23:45 +02:00
end
2022-04-18 01:17:16 +02:00
local paused = Public.get('paused')
local paused_waves_for = Public.get('paused_waves_for')
local last_pause = Public.get('last_pause')
2021-11-14 21:01:01 +01:00
local wave_number = Public.get('wave_number')
local next_wave = Public.get('next_wave')
local last_wave = Public.get('last_wave')
local max_active_biters = Public.get('max_active_biters')
local threat = Public.get('threat')
local enable_threat_log = Public.get('enable_threat_log')
2020-11-17 12:45:47 +01:00
2020-08-09 20:23:45 +02:00
gui.label.caption = {'wave_defense.gui_2'}
2022-04-18 01:17:16 +02:00
if not paused then
gui.wave_number.caption = wave_number
if wave_number == 0 then
gui.label.caption = {'wave_defense.gui_1'}
gui.wave_number.caption = floor((next_wave - game.tick) / 60) + 1 .. 's'
end
local interval = next_wave - last_wave
local value = 1 - (next_wave - game.tick) / interval
if value < 0 then
value = 0
elseif value > 1 then
value = 1
end
gui.progressbar.value = value
else
gui.label.caption = {'wave_defense.gui_4'}
local pause_for = floor((paused_waves_for - game.tick) / 60) + 1
if pause_for < 0 then
pause_for = 0
end
gui.wave_number.caption = pause_for .. 's'
local interval = paused_waves_for - last_pause
local value = 1 - (paused_waves_for - game.tick) / interval
if value < 0 then
value = 0
elseif value > 1 then
value = 1
end
gui.progressbar.value = value
return
2021-11-28 20:42:38 +01:00
end
2020-08-09 20:23:45 +02:00
gui.threat.caption = {'wave_defense.gui_3'}
2020-11-17 12:45:47 +01:00
gui.threat.tooltip = {'wave_defense.tooltip_1', biter_health_boost * 100, max_active_biters}
2021-11-23 20:28:23 +01:00
gui.threat_value.caption = floor(threat)
gui.threat_value.tooltip = {
'wave_defense.tooltip_1',
biter_health_boost * 100,
2020-11-17 12:45:47 +01:00
max_active_biters
}
2020-08-09 20:23:45 +02:00
2020-11-17 12:45:47 +01:00
if wave_number == 0 then
2020-08-09 20:23:45 +02:00
gui.threat_gains.caption = ''
return
end
2020-11-17 12:45:47 +01:00
if enable_threat_log then
2020-08-09 20:23:45 +02:00
local gain = get_threat_gain()
2020-11-17 12:45:47 +01:00
local d = wave_number / 75
2020-08-09 20:23:45 +02:00
if gain >= 0 then
gui.threat_gains.caption = ' (+' .. gain .. ')'
2021-11-23 20:28:23 +01:00
local g = 255 - floor(gain / d)
2020-08-09 20:23:45 +02:00
if g < 0 then
g = 0
end
gui.threat_gains.style.font_color = {255, g, 0}
else
gui.threat_gains.caption = ' (' .. gain .. ')'
2021-11-23 20:28:23 +01:00
local r = 255 - floor(math.abs(gain) / d)
2020-08-09 20:23:45 +02:00
if r < 0 then
r = 0
end
gui.threat_gains.style.font_color = {r, 255, 0}
end
end
2019-10-14 06:52:17 +02:00
end
2021-11-14 21:01:01 +01:00
return Public