diff --git a/config/gui/science.lua b/config/gui/science.lua index d9e77d5f..c895e88f 100644 --- a/config/gui/science.lua +++ b/config/gui/science.lua @@ -2,9 +2,9 @@ -- @config Science return { -- list of all science packs to be shown in the gui - show_eta=true, --- @setting show_eta when true the eta for research completion will be shown - color_clamp=5, --- @setting color_clamp the amount required for the text to show as green or red - color_flux=0.1, --- @setting color_flux the ammount of flucuation allowed in production before icon change + show_eta = true, --- @setting show_eta when true the eta for research completion will be shown + color_cutoff = 0.8, --- @setting color_cutoff the amount that production can fall before the text changes color + color_flux = 0.1, --- @setting color_flux the amount of fluctuation allowed in production before the icon changes color 'automation-science-pack', 'logistic-science-pack', 'military-science-pack', diff --git a/expcore/gui/defines.lua b/expcore/gui/defines.lua index b61322e7..c322d1b2 100644 --- a/expcore/gui/defines.lua +++ b/expcore/gui/defines.lua @@ -105,7 +105,7 @@ local header = Gui.header( ]] Gui.header = -Gui.element(function(_,parent,caption,tooltip,add_alignment,name) +Gui.element(function(_,parent,caption,tooltip,add_alignment,name,label_name) -- Draw the header local header = parent.add{ @@ -123,7 +123,7 @@ Gui.element(function(_,parent,caption,tooltip,add_alignment,name) -- Draw the caption label if caption then header.add{ - name = 'header_label', + name = label_name or 'header_label', type = 'label', style = 'heading_1_label', caption = caption, diff --git a/modules/control/production.lua b/modules/control/production.lua index 026bad7c..2c7fced8 100644 --- a/modules/control/production.lua +++ b/modules/control/production.lua @@ -187,21 +187,21 @@ end -- Functions used to format production values -- @section formating ---- Returns a color value bassed on the value that was given --- @tparam number clamp value which seperates the different colours --- @tparam number active_value first value tested, tested against clamp --- @tparam number passive_value second value tested, tested against 0 +--- Returns a color value based on the value that was given +-- @tparam number cutoff value which separates the different colours +-- @tparam number active_value first value tested, tested against cutoff +-- @tparam number passive_value second value tested, tested against 0 when active is 0 -- @treturn table contains r,g,b keys -function Production.get_color(clamp,active_value,passive_value) - if active_value > clamp then +function Production.get_color(cutoff, active_value, passive_value) + if active_value > cutoff then return Colors.light_green - elseif active_value < -clamp then + elseif active_value < -cutoff then return Colors.indian_red elseif active_value ~= 0 then return Colors.orange elseif passive_value and passive_value > 0 then return Colors.orange - elseif passive_value and passive_value ~= 0 then + elseif passive_value and passive_value < 0 then return Colors.indian_red else return Colors.grey diff --git a/modules/gui/readme.lua b/modules/gui/readme.lua index b00d1e57..7c6e4dd1 100644 --- a/modules/gui/readme.lua +++ b/modules/gui/readme.lua @@ -187,7 +187,8 @@ Gui.element(function(_,parent) -- Add the external links local external_links = title_table(scroll_pane, 235, {'readme.servers-external'}, 2) for _,key in ipairs{'discord','website','patreon','status','github'} do - Gui.centered_label(external_links, 110, key:gsub("^%l", string.upper)) + local upper_key = key:gsub("^%l", string.upper) + Gui.centered_label(external_links, 110, upper_key) Gui.centered_label(external_links, 460, {'links.'..key}, {'readme.servers-open-in-browser'}) end diff --git a/modules/gui/rocket-info.lua b/modules/gui/rocket-info.lua index 494ea7e6..76eff701 100644 --- a/modules/gui/rocket-info.lua +++ b/modules/gui/rocket-info.lua @@ -440,6 +440,14 @@ Gui.element{ end end) +-- Used to assign an event to the header label to trigger a toggle +-- @element header_toggle +local header_toggle = Gui.element() +:on_click(function(_, element, event) + event.element = element.parent.alignment[toggle_section.name] + toggle_section:raise_custom_event(event) +end) + -- Draw a section header and main scroll -- @element rocket_list_container local section = @@ -450,7 +458,8 @@ Gui.element(function(_,parent,section_name,table_size) {'rocket-info.section-caption-'..section_name}, {'rocket-info.section-tooltip-'..section_name}, true, - section_name..'-header' + section_name..'-header', + header_toggle.name ) -- Right aligned button to toggle the section @@ -535,11 +544,6 @@ end Event.add(defines.events.on_rocket_launched,function(event) local force = event.rocket_silo.force update_rocket_gui_all(force.name) - if force.rockets_launched == 1 then - for _,player in pairs(force.players) do - Gui.update_top_flow(player) - end - end end) --- Update only the progress gui for a force diff --git a/modules/gui/science-info.lua b/modules/gui/science-info.lua index f905761d..01450b7f 100644 --- a/modules/gui/science-info.lua +++ b/modules/gui/science-info.lua @@ -56,8 +56,8 @@ Gui.element(function(_,parent,production_label_data) end) -- Get the data that is used with the production label -local function get_production_label_data(name,tooltip,value,secondary) - local data_colour = Production.get_color(config.color_clamp, value, secondary) +local function get_production_label_data(name, tooltip, value, cutout, secondary) + local data_colour = Production.get_color(config.color_cutoff * cutout, value, secondary) local surfix, caption = Production.format_number(value) return { @@ -134,9 +134,9 @@ Gui.element(function(_,parent,science_pack_data) delta_table.style.padding = 0 -- Draw the production labels - update_production_label(delta_table,science_pack_data.positive) - update_production_label(delta_table,science_pack_data.negative) - update_production_label(parent,science_pack_data.net) + update_production_label(delta_table, science_pack_data.positive) + update_production_label(delta_table, science_pack_data.negative) + update_production_label(parent, science_pack_data.net) -- Return the pack icon return pack_icon @@ -147,10 +147,9 @@ local function get_science_pack_data(player,science_pack) -- Check that some packs have been made local total = Production.get_production_total(force, science_pack) + if total.made == 0 then return end local minute = Production.get_production(force, science_pack, defines.flow_precision_index.one_minute) - if total.made == 0 then - return - end + local hour = Production.get_production(force, science_pack, defines.flow_precision_index.one_hour) -- Get the icon style local icon_style = 'slot_button' @@ -170,17 +169,17 @@ local function get_science_pack_data(player,science_pack) positive = get_production_label_data( 'pos-'..science_pack, {'science-info.pos-tooltip', total.made}, - minute.made + minute.made, hour.made ), negative = get_production_label_data( 'neg-'..science_pack, {'science-info.neg-tooltip', total.used}, - -minute.used + -minute.used, hour.used ), net = get_production_label_data( 'net-'..science_pack, {'science-info.net-tooltip', total.net}, - minute.net, + minute.net, minute.net > 0 and hour.net or 0, minute.made+minute.used ) } @@ -337,19 +336,19 @@ Event.on_nth_tick(60,function() local scroll_table = container.scroll.table local pack_data = force_pack_data[force_name] if not pack_data then - -- No data in chache so it needs to be generated + -- No data in cache so it needs to be generated pack_data = {} force_pack_data[force_name] = pack_data - for _,science_pack in ipairs(config) do - local next_data = get_science_pack_data(player,science_pack) + for _, science_pack in ipairs(config) do + local next_data = get_science_pack_data(player, science_pack) pack_data[science_pack] = next_data - update_science_pack(scroll_table,next_data) + update_science_pack(scroll_table, next_data) end else - -- Data found in chache is no need to generate it - for _,next_data in ipairs(pack_data) do - update_science_pack(scroll_table,next_data) + -- Data found in cache is no need to generate it + for _, next_data in pairs(pack_data) do + update_science_pack(scroll_table, next_data) end end @@ -362,11 +361,11 @@ Event.on_nth_tick(60,function() -- No data in chache so it needs to be generated eta_data = get_eta_label_data(player) force_eta_data[force_name] = eta_data - update_eta_label(eta_label,eta_data) + update_eta_label(eta_label, eta_data) else -- Data found in chache is no need to generate it - update_eta_label(eta_label,eta_data) + update_eta_label(eta_label, eta_data) end