From 1d31ab09ad09f7ea4ece729d66d029d0a820445f Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Fri, 14 Jun 2019 20:31:43 +0100 Subject: [PATCH] Added common header creation --- expcore/gui/core.lua | 28 ++++++++++++++++++++++++++++ modules/gui/rocket-info.lua | 26 ++++++++------------------ modules/gui/science-info.lua | 15 +++++---------- modules/gui/task-list.lua | 26 +++++++------------------- modules/gui/warp-list.lua | 26 +++++++------------------- 5 files changed, 55 insertions(+), 66 deletions(-) diff --git a/expcore/gui/core.lua b/expcore/gui/core.lua index ea7ec520..14d6104b 100644 --- a/expcore/gui/core.lua +++ b/expcore/gui/core.lua @@ -326,4 +326,32 @@ function Gui.create_scroll_table(element,table_size,maximal_height,name) return list_table end +--- Creates a header section with a label and button area +-- @tparam LuaGuiElement element the element to add this header into +-- @tparam localeString caption the caption that is used as the title +-- @tparam[opt] localeString tooltip the tooltip that is shown on the caption +-- @tparam[opt] boolean right_align when true will include the right align area +-- @tparam[opt='header'] string name the name of the header area +-- @treturn LuaGuiElement the header that was made, or the align area if that was created +function Gui.create_header(element,caption,tooltip,right_align,name) + local header = + element.add{ + name=name or 'header', + type='frame', + style='subheader_frame' + } + Gui.set_padding(header,2,2,4,4) + header.style.horizontally_stretchable = true + header.style.use_header_filler = false + + header.add{ + type='label', + style='heading_1_label', + caption=caption, + tooltip=tooltip + } + + return right_align and Gui.create_alignment(header,'header-align') or header +end + return Gui \ No newline at end of file diff --git a/modules/gui/rocket-info.lua b/modules/gui/rocket-info.lua index 9b655431..9e38475c 100644 --- a/modules/gui/rocket-info.lua +++ b/modules/gui/rocket-info.lua @@ -145,26 +145,16 @@ end) --- Used to create the three different sections local function create_section(container,section_name,table_size) --- Header for the section - local header = - container.add{ - type='frame', - name=section_name..'-header', - style='subheader_frame', - } - Gui.set_padding(header,4,1,4,4) - header.style.horizontally_stretchable = true - - --- Caption for the header bar - header.add{ - type='label', - style='heading_1_label', - caption={'rocket-info.section-caption-'..section_name}, - tooltip={'rocket-info.section-tooltip-'..section_name} - } + local header_area = Gui.create_header( + container, + {'rocket-info.section-caption-'..section_name}, + {'rocket-info.section-tooltip-'..section_name}, + true, + section_name..'-header' + ) --- Right aligned button to toggle the section - local expand_flow = Gui.create_alignment(header,section_name) - toggle_section(expand_flow) + toggle_section(header_area) --- Table used to store the data local flow_table = Gui.create_scroll_table(container,table_size,215,section_name) diff --git a/modules/gui/science-info.lua b/modules/gui/science-info.lua index bea1cd50..6fd522d2 100644 --- a/modules/gui/science-info.lua +++ b/modules/gui/science-info.lua @@ -75,16 +75,11 @@ local function generate_container(player,element) Gui.set_padding(container) -- main header for the gui - local header = - container.add{ - name='header', - type='frame', - caption={'science-info.main-caption'}, - style='subheader_frame' - } - Gui.set_padding(header,2,2,4,4) - header.style.horizontally_stretchable = true - header.style.use_header_filler = false + Gui.create_header( + container, + {'science-info.main-caption'}, + {'science-info.main-tooltip'} + ) -- table that stores all the data local flow_table = Gui.create_scroll_table(container,4,185) diff --git a/modules/gui/task-list.lua b/modules/gui/task-list.lua index 333d6ece..2a4a4374 100644 --- a/modules/gui/task-list.lua +++ b/modules/gui/task-list.lua @@ -310,28 +310,16 @@ local function generate_container(player,element) container.style.vertically_stretchable = false -- main header for the gui - local header = - container.add{ - name='header', - type='frame', - style='subheader_frame' - } - Gui.set_padding(header,2,2,4,4) - header.style.horizontally_stretchable = true - header.style.use_header_filler = false - - --- Caption for the header bar - header.add{ - type='label', - style='heading_1_label', - caption={'task-list.main-caption'}, - tooltip={'task-list.sub-tooltip'} - } + local header_area = Gui.create_header( + container, + {'task-list.main-caption'}, + {'task-list.sub-tooltip'}, + true + ) --- Right aligned button to toggle the section if player_allowed_edit(player) then - local right_align = Gui.create_alignment(header) - add_new_task(right_align) + add_new_task(header_area) end -- table that stores all the data diff --git a/modules/gui/warp-list.lua b/modules/gui/warp-list.lua index 04a72ffb..7cdd8c67 100644 --- a/modules/gui/warp-list.lua +++ b/modules/gui/warp-list.lua @@ -577,28 +577,16 @@ local function generate_container(player,element) container.style.vertically_stretchable = false -- main header for the gui - local header = - container.add{ - name='header', - type='frame', - style='subheader_frame' - } - Gui.set_padding(header,2,2,4,4) - header.style.horizontally_stretchable = true - header.style.use_header_filler = false - - --- Caption for the header bar - header.add{ - type='label', - style='heading_1_label', - caption={'warp-list.main-caption'}, - tooltip={'warp-list.sub-tooltip',config.recharge_time,config.activation_range} - } + local header_area = Gui.create_header( + container, + {'warp-list.main-caption'}, + {'warp-list.sub-tooltip',config.recharge_time,config.activation_range}, + true + ) --- Right aligned button to toggle the section if player_allowed_edit(player) then - local right_align = Gui.create_alignment(header) - add_new_warp(right_align) + add_new_warp(header_area) end -- table that stores all the data