Research GUI (#302)

* Update research.lua

* Update research.lua

* Update research.lua

* Update research.lua

* Update research.lua

* Update research.lua

* Update research.lua

* Update research.lua

* Update research.lua

* Update research.lua

* Update research.lua

* Update research.lua

* Update research.lua
This commit is contained in:
2024-07-23 03:24:42 +09:00
committed by GitHub
parent 02d6a23c2d
commit ed88770314
3 changed files with 302 additions and 482 deletions

View File

@@ -5,11 +5,6 @@ return {
enabled = true, enabled = true,
pollution_ageing_by_research = false, pollution_ageing_by_research = false,
queue_amount = 3, queue_amount = 3,
bonus = {
enabled = false,
name = 'laboratory_productivity_bonus',
rate = 1
},
-- this enable 20 more inventory for each mining productivity level up to 4 -- this enable 20 more inventory for each mining productivity level up to 4
bonus_inventory = { bonus_inventory = {
enabled = true, enabled = true,
@@ -17,285 +12,70 @@ return {
rate = 5, rate = 5,
limit = 20 limit = 20
}, },
file_name = 'log/research.log',
milestone = { milestone = {
{ ['automation'] = 600,
name = 'automation', ['logistics'] = 300,
time = 600 ['steel-processing'] = 300,
}, ['logistic-science-pack'] = 300,
{ ['electronics'] = 300,
name = 'logistics', ['fast-inserter'] = 300,
time = 300 ['steel-axe'] = 300,
}, ['automation-2'] = 300,
{ ['advanced-material-processing'] = 300,
name = 'steel-processing', ['engine'] = 300,
time = 300 ['fluid-handling'] = 300,
}, ['oil-processing'] = 300,
{ ['sulfur-processing'] = 300,
name = 'logistic-science-pack', ['plastics'] = 300,
time = 300 ['advanced-electronics'] = 300,
}, ['chemical-science-pack'] = 300,
{ ['modules'] = 300,
name = 'electronics', ['logistics-2'] = 300,
time = 300 ['railway'] = 300,
}, ['research-speed-1'] = 300,
{ ['research-speed-2'] = 300,
name = 'fast-inserter', ['battery'] = 300,
time = 300 ['concrete'] = 300,
}, ['flammables'] = 300,
{ ['low-density-structure'] = 300,
name = 'steel-axe', ['advanced-material-processing-2'] = 300,
time = 300 ['productivity-module'] = 300,
}, ['production-science-pack'] = 300,
{ ['advanced-electronics-2'] = 300,
name = 'automation-2', ['advanced-oil-processing'] = 300,
time = 300 ['electric-engine'] = 300,
}, ['robotics'] = 300,
{ ['construction-robotics'] = 300,
name = 'advanced-material-processing', ['worker-robots-speed-1'] = 300,
time = 300 ['worker-robots-speed-2'] = 300,
}, ['utility-science-pack'] = 300,
{ ['productivity-module-2'] = 300,
name = 'engine', ['speed-module-2'] = 300,
time = 300 ['rocket-fuel'] = 300,
}, ['effect-transmission'] = 300,
{ ['productivity-module-3'] = 300,
name = 'fluid-handling', ['rocket-control-unit'] = 300,
time = 300 ['speed-module-3'] = 300,
}, ['rocket-silo'] = 300,
{ ['space-science-pack'] = 300,
name = 'oil-processing',
time = 300
},
{
name = 'sulfur-processing',
time = 300
},
{
name = 'plastics',
time = 300
},
{
name = 'advanced-electronics',
time = 300
},
{
name = 'chemical-science-pack',
time = 300
},
{
name = 'modules',
time = 300
},
{
name = 'logistics-2',
time = 300
},
{
name = 'railway',
time = 300
},
{
name = 'research-speed-1',
time = 300
},
{
name = 'research-speed-2',
time = 300
},
{
name = 'battery',
time = 300
},
{
name = 'concrete',
time = 300
},
{
name = 'flammables',
time = 300
},
{
name = 'low-density-structure',
time = 300
},
{
name = 'advanced-material-processing-2',
time = 300
},
{
name = 'productivity-module',
time = 300
},
{
name = 'production-science-pack',
time = 300
},
{
name = 'advanced-electronics-2',
time = 300
},
{
name = 'advanced-oil-processing',
time = 300
},
{
name = 'lubricant',
time = 300
},
{
name = 'electric-engine',
time = 300
},
{
name = 'robotics',
time = 300
},
{
name = 'construction-robotics',
time = 300
},
{
name = 'worker-robots-speed-1',
time = 300
},
{
name = 'worker-robots-speed-2',
time = 300
},
{
name = 'utility-science-pack',
time = 300
},
{
name = 'productivity-module-2',
time = 300
},
{
name = 'speed-module-2',
time = 300
},
{
name = 'rocket-fuel',
time = 300
},
{
name = 'effect-transmission',
time = 300
},
{
name = 'productivity-module-3',
time = 300
},
{
name = 'rocket-control-unit',
time = 300
},
{
name = 'speed-module-3',
time = 300
},
{
name = 'rocket-silo',
time = 300
},
{
name = 'space-science-pack',
time = 300
}
}, },
inf_res = { inf_res = {
{ -- Mining Productivity
-- Mining Productivity ['mining-productivity-4'] = 4,
name = 'mining-productivity-4', -- Robot Speed
level = 4 ['worker-robots-speed-6'] = 6,
}, -- Laser Damage
{ ['energy-weapons-damage-7'] = 7,
-- Robot Speed -- Explosive Damage
name = 'worker-robots-speed-6', ['stronger-explosives-7'] = 7,
level = 6 -- Bullet Damage
}, ['physical-projectile-damage-7'] = 7,
{ -- Flame Damage
-- Laser Damage ['refined-flammables-7'] = 7,
name = 'energy-weapons-damage-7', -- Artillery Range
level = 7 ['artillery-shell-range-1'] = 1,
}, -- Artillery Speed
{ ['artillery-shell-speed-1'] = 1
-- Explosive Damage
name = 'stronger-explosives-7',
level = 7
},
{
-- Bullet Damage
name = 'physical-projectile-damage-7',
level = 7
},
{
-- Flame Damage
name = 'refined-flammables-7',
level = 7
},
{
-- Artillery Range
name = 'artillery-shell-range-1',
level = 1
},
{
-- Artillery Speed
name = 'artillery-shell-speed-1',
level = 1
}
} }
--[[
limit_research = false,
limit_research_list = {
{
-- Mining Productivity
name = 'mining-productivity-4',
enabled = false,
level = 4
},
{
-- Robot Speed
name = 'worker-robots-speed-6',
enabled = false,
level = 6
},
{
-- Laser Damage
name = 'energy-weapons-damage-7',
enabled = false,
level = 7
},
{
-- Explosive Damage
name = 'stronger-explosives-7',
enabled = false,
level = 7
},
{
-- Bullet Damage
name = 'physical-projectile-damage-7',
enabled = false,
level = 7
},
{
-- Flame Damage
name = 'refined-flammables-7',
enabled = false,
level = 7
},
{
-- Artillery Range
name = 'artillery-shell-range-1',
enabled = false,
level = 1
},
{
-- Artillery Speed
name = 'artillery-shell-speed-1',
enabled = false,
level = 1
}
}
]]
} }

View File

@@ -1,108 +1,44 @@
local Event = require 'utils.event' --- @dep utils.event
local Common = require 'expcore.common' --- @dep utils.event
local Global = require 'utils.global' --- @dep utils.global local Global = require 'utils.global' --- @dep utils.global
local config = require 'config.research' --- @dep config.research local Event = require 'utils.event' --- @dep utils.event
local config_bonus = Common.opt_require 'config.bonus' --- @dep config.bonus
local Commands = require 'expcore.commands' --- @dep expcore.commands local Commands = require 'expcore.commands' --- @dep expcore.commands
local format_time = _C.format_time --- @dep expcore.common local config = require 'config.research' --- @dep config.research
local research = {} local research = {}
Global.register(research, function(tbl) Global.register(research, function(tbl)
research = tbl research = tbl
end) end)
local research_time_format = {hours=true, minutes=true, seconds=true, time=true, string=true} local function res_queue(force, res, by_script)
research.res_queue_enable = false local res_q = force.research_queue
local base_rate = 0
if config.bonus.enabled then
for k, _ in pairs(config_bonus.force_bonus) do
if config_bonus.force_bonus[k].name == config.bonus.name then
base_rate = config_bonus.force_bonus[k].max
end
end
end
local function research_notification(event)
local is_inf_res = false
for i=1, #config.inf_res do
if (event.research.name == config.inf_res[i].name) and (event.research.level >= config.inf_res[i].level) then
is_inf_res = true
end
end
if config.bonus_inventory.enabled then
if (event.research.force.mining_drill_productivity_bonus * 10) <= (config.bonus_inventory.limit / config.bonus_inventory.rate) then
if event.research.force.technologies['toolbelt'].researched then
event.research.force[config.bonus_inventory.name] = (math.floor(event.research.force.mining_drill_productivity_bonus * 10) * config.bonus_inventory.rate) + 10
else
event.research.force[config.bonus_inventory.name] = math.floor(event.research.force.mining_drill_productivity_bonus * 10) * config.bonus_inventory.rate
end
end
end
if is_inf_res then
if event.research.name == 'mining-productivity-4' and event.research.level > 4 then
if config.bonus.enabled then
event.research.force[config.bonus.name] = base_rate + event.research.level * config.bonus.rate
end
if config.pollution_ageing_by_research then
game.map_settings.pollution.ageing = math.min(10, event.research.level / 5)
end
end
if not (event.by_script) then
game.print{'expcom-res.inf', format_time(game.tick, research_time_format), event.research.name, event.research.level - 1}
end
else
if not (event.by_script) then
game.print{'expcom-res.msg', format_time(game.tick, research_time_format), event.research.name}
end
end
end
local function res_queue(event)
if event.research.force.rockets_launched == 0 or event.research.force.technologies['mining-productivity-4'].level <= 4 then
return
end
local res_q = event.research.research_queue
if #res_q < config.queue_amount then if #res_q < config.queue_amount then
for i=1, config.queue_amount - #res_q do for i=1, config.queue_amount - #res_q do
event.research.force.add_research(event.research.force.technologies['mining-productivity-4']) force.add_research(force.technologies['mining-productivity-4'])
if not (event.by_script) then if not (by_script) then
game.print{'expcom-res.inf-q', event.research.name, event.research.level + i} game.print{'expcom-res.inf-q', res.name, res.level + i}
end end
end end
end end
end end
local function research_queue_logic(event)
research_notification(event)
if research.res_queue_enable then
res_queue(event)
end
end
Event.add(defines.events.on_research_finished, research_queue_logic)
Event.add(defines.events.on_research_cancelled, research_queue_logic)
Commands.new_command('auto-research', 'Automatically queue up research') Commands.new_command('auto-research', 'Automatically queue up research')
:add_alias('ares') :add_alias('ares')
:register(function(player) :register(function(player)
research.res_queue_enable = not research.res_queue_enable research.res_queue_enable = not research.res_queue_enable
if research.res_queue_enable then if research.res_queue_enable then
res_queue(player.force) res_queue(player.force, nil, true)
end end
game.print{'expcom-res.res', player.name, research.res_queue_enable} game.print{'expcom-res.res', player.name, research.res_queue_enable}
return Commands.success return Commands.success
end) end)
Event.add(defines.events.on_research_finished, function(event)
if research.res_queue_enable then
if event.research.force.rockets_launched > 0 and event.research.force.technologies['mining-productivity-4'].level > 4 then
res_queue(event.research.force, {name=event.research.name, level=event.research.level}, event.by_script)
end
end
end)

View File

@@ -1,4 +1,4 @@
--- research milestone gui --- research gui
-- @gui Research -- @gui Research
local Gui = require 'expcore.gui' --- @dep expcore.gui local Gui = require 'expcore.gui' --- @dep expcore.gui
@@ -14,11 +14,57 @@ Global.register(research, function(tbl)
end) end)
research.time = {} research.time = {}
local res = {} research.res_queue_enable = false
local res_i = {}
local research_time_format = {
hours=true,
minutes=true,
seconds=true,
time=true,
string=true
}
local empty_time = format_time(0, {
hours=true,
minutes=true,
seconds=true,
time=true,
string=true,
null=true
})
local res = {
['lookup_name'] = {},
['disp'] = {}
}
local res_total = 0 local res_total = 0
local research_time_format = {hours=true, minutes=true, seconds=true, time=true, string=true} local mi = 1
local empty_time = format_time(0, {hours=true, minutes=true, seconds=true, time=true, string=true, null=true})
for k, v in pairs(config.milestone) do
research.time[mi] = 0
res['lookup_name'][k] = mi
res_total = res_total + v * 60
res['disp'][mi] = {
name = '[technology=' .. k .. '] ' .. k:gsub('-', ' '),
raw_name = k,
prev = res_total,
prev_disp = format_time(res_total, research_time_format),
}
mi = mi + 1
end
local function add_log()
local result_data = {}
for i=1, #research.time, 1 do
result_data[res['disp'][i]['raw_name']] = research.time[i]
end
game.write_file(config.file_name, game.table_to_json(result_data) .. '\n', true, 0)
end
local function research_res_n(res_) local function research_res_n(res_)
local res_n = 1 local res_n = 1
@@ -38,111 +84,160 @@ local function research_res_n(res_)
if res_n < 3 then if res_n < 3 then
res_n = 3 res_n = 3
elseif res_n > (#research.time - 5) then
res_n = #research.time - 5
end end
return res_n return res_n
end end
for i=1, #config.milestone do local function research_notification(event)
res_total = res_total + config.milestone[i].time * 60 local is_inf_res = false
res_i[config.milestone[i].name] = i
research.time[i] = 0 if config.inf_res[event.research.name] then
res[i] = { if event.research.name == 'mining-productivity-4' and event.research.level == 5 then
name = '[technology=' .. config.milestone[i].name .. '] ' .. config.milestone[i].name:gsub('-', ' '), -- Add run result to log
prev = res_total, add_log()
prev_disp = format_time(res_total, research_time_format), end
}
if event.research.level >= config.inf_res[event.research.name] then
is_inf_res = true
end
end
if is_inf_res then
if event.research.name == 'mining-productivity-4' then
if config.bonus_inventory.enabled then
if (event.research.level - 1) <= math.ceil(config.bonus_inventory.limit / config.bonus_inventory.rate) then
event.research.force[config.bonus_inventory.name] = math.max((event.research.level - 1) * config.bonus_inventory.rate, config.bonus_inventory.limit)
end
end
if config.pollution_ageing_by_research then
game.map_settings.pollution.ageing = math.min(10, event.research.level / 5)
end
end
if not (event.by_script) then
game.print{'expcom-res.inf', format_time(game.tick, research_time_format), event.research.name, event.research.level - 1}
end
else
if not (event.by_script) then
game.print{'expcom-res.msg', format_time(game.tick, research_time_format), event.research.name}
end
if event.research.name == 'mining-productivity-1' or event.research.name == 'mining-productivity-2' or event.research.name == 'mining-productivity-3' then
if config.bonus_inventory.enabled then
event.research.force[config.bonus_inventory.name] = event.research.level * config.bonus_inventory.rate
end
end
end
end end
--- Display label for the clock display
-- @element research_gui_clock_display
local research_gui_clock =
Gui.element{
type = 'label',
name = Gui.unique_static_name,
caption = empty_time,
style = 'heading_1_label'
}
--- A vertical flow containing the clock
-- @element research_clock_set
local research_clock_set =
Gui.element(function(_, parent, name)
local research_set = parent.add{type='flow', direction='vertical', name=name}
local disp = Gui.scroll_table(research_set, 360, 1, 'disp')
research_gui_clock(disp)
return research_set
end)
--- A vertical flow containing the data
-- @element research_data_set
local research_data_set =
Gui.element(function(_, parent, name)
local research_set = parent.add{type='flow', direction='vertical', name=name}
local disp = Gui.scroll_table(research_set, 360, 4, 'disp')
for i=1, 8, 1 do
disp.add{
type = 'label',
name = 'research_display_n_' .. i,
caption = '',
style = 'heading_1_label'
}
disp.add{
type = 'label',
name = 'research_display_d_' .. i,
caption = empty_time,
style = 'heading_1_label'
}
disp.add{
type = 'label',
name = 'research_display_p_' .. i,
caption = '',
style = 'heading_1_label'
}
disp.add{
type = 'label',
name = 'research_display_t_' .. i,
caption = empty_time,
style = 'heading_1_label'
}
end
local res_n = research_res_n(res['disp'])
for j=1, 8, 1 do
local res_j = res_n + j - 3
if res['disp'][res_j] then
local res_r = res['disp'][res_j]
disp['research_display_n_' .. j].caption = res_r.name
if research.time[res_j] == 0 then
disp['research_display_d_' .. j].caption = empty_time
disp['research_display_p_' .. j].caption = res_r.prev_disp
disp['research_display_t_' .. j].caption = empty_time
else
if research.time[res_j] < res['disp'][res_j].prev then
disp['research_display_d_' .. j].caption = '-' .. format_time(res['disp'][res_j].prev - research.time[res_j], research_time_format)
else
disp['research_display_d_' .. j].caption = format_time(research.time[res_j] - res['disp'][res_j].prev, research_time_format)
end
disp['research_display_p_' .. j].caption = res_r.prev_disp
disp['research_display_t_' .. j].caption = format_time(research.time[res_j], research_time_format)
end
else
disp['research_display_n_' .. j].caption = ''
disp['research_display_d_' .. j].caption = ''
disp['research_display_p_' .. j].caption = ''
disp['research_display_t_' .. j].caption = ''
end
end
return research_set
end)
local research_container = local research_container =
Gui.element(function(definition, parent) Gui.element(function(definition, parent)
local container = Gui.container(parent, definition.name, 200) local container = Gui.container(parent, definition.name, 320)
local scroll_table = Gui.scroll_table(container, 400, 4)
scroll_table.add{ research_clock_set(container, 'research_st_1')
name = 'clock_text', research_data_set(container, 'research_st_2')
caption = 'Time:',
type = 'label',
style = 'heading_1_label'
}
scroll_table.add{
name = 'clock_text_2',
caption = '',
type = 'label',
style = 'heading_1_label'
}
scroll_table.add{
name = 'clock_text_3',
caption = '',
type = 'label',
style = 'heading_1_label'
}
scroll_table.add{
name = 'clock_display',
caption = empty_time,
type = 'label',
style = 'heading_1_label'
}
for i=1, 8 do
scroll_table.add{
name = 'research_display_n_' .. i,
caption = '',
type = 'label',
style = 'heading_1_label'
}
scroll_table.add{
name = 'research_display_d_' .. i,
caption = empty_time,
type = 'label',
style = 'heading_1_label'
}
scroll_table.add{
name = 'research_display_p_' .. i,
caption = '',
type = 'label',
style = 'heading_1_label'
}
scroll_table.add{
name = 'research_display_t_' .. i,
caption = empty_time,
type = 'label',
style = 'heading_1_label'
}
end
local res_n = research_res_n(res)
for j=1, 8 do
local res_j = res_n + j - 3
if res[res_j] ~= nil then
local res_r = res[res_j]
scroll_table['research_display_n_' .. j].caption = res_r.name
if research.time[res_j] < res[res_j].prev then
scroll_table['research_display_d_' .. j].caption = '-' .. format_time(res[res_j].prev - research.time[res_j], research_time_format)
else
scroll_table['research_display_d_' .. j].caption = format_time(research.time[res_j] - res[res_j].prev, research_time_format)
end
scroll_table['research_display_p_' .. j].caption = res_r.prev_disp
scroll_table['research_display_t_' .. j].caption = format_time(research.time[res_j], research_time_format)
else
scroll_table['research_display_n_' .. j].caption = ''
scroll_table['research_display_d_' .. j].caption = ''
scroll_table['research_display_p_' .. j].caption = ''
scroll_table['research_display_t_' .. j].caption = ''
end
end
return container.parent return container.parent
end) end)
@@ -154,35 +249,42 @@ Gui.left_toolbar_button('item/space-science-pack', {'expcom-res.main-tooltip'},
end) end)
Event.add(defines.events.on_research_finished, function(event) Event.add(defines.events.on_research_finished, function(event)
if event.research.name == nil then research_notification(event)
return
elseif res_i[event.research.name] == nil then if res['lookup_name'][event.research.name] == nil then
return return
end end
local n_i = res_i[event.research.name] local n_i = res['lookup_name'][event.research.name]
research.time[n_i] = game.tick research.time[n_i] = game.tick
local res_n = research_res_n(res) local res_n = research_res_n(res['disp'])
local res_disp = {} local res_disp = {}
for j=1, 8 do for j=1, 8, 1 do
local res_j = res_n + j - 3 local res_j = res_n + j - 3
res_disp[j] = {} res_disp[j] = {}
if res[res_j] ~= nil then if res['disp'][res_j] then
local res_r = res[res_j] local res_r = res['disp'][res_j]
res_disp[j]['n'] = res_r.name res_disp[j]['n'] = res_r.name
if research.time[res_j] < res[res_j].prev then if research.time[res_j] == 0 then
res_disp[j]['d'] = '-' .. format_time(res[res_j].prev - research.time[res_j], research_time_format) res_disp[j]['d'] = empty_time
res_disp[j]['p']= res_r.prev_disp
res_disp[j]['t'] = empty_time
else else
res_disp[j]['d'] = format_time(research.time[res_j] - res[res_j].prev, research_time_format) if research.time[res_j] < res['disp'][res_j].prev then
end res_disp[j]['d'] = '-' .. format_time(res['disp'][res_j].prev - research.time[res_j], research_time_format)
res_disp[j]['p'] = res_r.prev_disp else
res_disp[j]['t'] = format_time(research.time[res_j], research_time_format) res_disp[j]['d'] = format_time(research.time[res_j] - res['disp'][res_j].prev, research_time_format)
end
res_disp[j]['p'] = res_r.prev_disp
res_disp[j]['t'] = format_time(research.time[res_j], research_time_format)
end
else else
res_disp[j]['n'] = '' res_disp[j]['n'] = ''
@@ -194,12 +296,13 @@ Event.add(defines.events.on_research_finished, function(event)
for _, player in pairs(game.connected_players) do for _, player in pairs(game.connected_players) do
local frame = Gui.get_left_element(player, research_container) local frame = Gui.get_left_element(player, research_container)
local disp = frame.container['research_st_2'].disp.table
for j=1, 8 do for j=1, 8, 1 do
frame.container.scroll.table['research_display_n_' .. j].caption = res_disp[j]['n'] disp['research_display_n_' .. j].caption = res_disp[j]['n']
frame.container.scroll.table['research_display_d_' .. j].caption = res_disp[j]['d'] disp['research_display_d_' .. j].caption = res_disp[j]['d']
frame.container.scroll.table['research_display_p_' .. j].caption = res_disp[j]['p'] disp['research_display_p_' .. j].caption = res_disp[j]['p']
frame.container.scroll.table['research_display_t_' .. j].caption = res_disp[j]['t'] disp['research_display_t_' .. j].caption = res_disp[j]['t']
end end
end end
end) end)
@@ -209,6 +312,7 @@ Event.on_nth_tick(60, function()
for _, player in pairs(game.connected_players) do for _, player in pairs(game.connected_players) do
local frame = Gui.get_left_element(player, research_container) local frame = Gui.get_left_element(player, research_container)
frame.container.scroll.table['clock_display'].caption = current_time local disp = frame.container['research_st_1'].disp.table
disp[research_gui_clock.name].caption = current_time
end end
end) end)