OK Wysi
I have given it a try and run into a few stumbling block in my implementation. I thought that I might share them as I found it very educational
I managed to create a rather large positioning problem with my first attempt. The second title row came out completely in the wrong place
The pseudo code started as something like
Code: Select all
local setup = Helper.createTableSetup(menu)
Add Title line 1
Add Title line 2
setup:addHeaderRow ...
get resources
for _, entry in ipairs(resources) do
check needed wares against storage and if there is insufficient energy or food then create an error message
display resource entry
end
I am not able to work out whether there is enough resources until it compares the station cargo with the build resources and that happens as part of going through the resources at the bottom of the code
cargo["energycells"] gets the energycells in storage nicely but
resources is unfortunately a table of tables rather than a single table like cargo and I don't know how to extract it in a one liner. So its difficult to add it as a condition around "Add Title line 2"
So I changed things and moved "Add Title line 2" down a bit
Code: Select all
local setup = Helper.createTableSetup(menu)
Add Title line 1
setup:addHeaderRow ...
get resources
for _, entry in ipairs(resources) do
check needed wares against storage and if there is insufficient energy or food then create an error message
display resource entry
end
if there is an error message then display it as Title line 2
if not display the original Title line 2
The result of that is that the second Title line vanishes from the top and re-appears after the HeaderRow and list of resources which I was not expecting. Oops
I guess that my assumption that
setup:addTitleRow created a special Title line was not correct and it looks like it only means add a table row with Title formatting which is educational
So to get this working I need to move the "Add Title line 2" and
get resources upwards and add an extra iteration through resources immediately after writing Title line 1 and move the checks in there. Not very elegant but should do the trick.
Code: Select all
local setup = Helper.createTableSetup(menu)
Add Title line 1
get resources
for _, entry in ipairs(resources) do
check needed wares against storage and if there is insufficient energy or food then create an error message
end
if there is an error message then display it as Title line 2
if not display the original Title line 2
setup:addHeaderRow ...
for _, entry in ipairs(resources) do
display resource entry
end
Or come up with something similar to menu_property.lua which uses what I thought was a different style of menu with updateable information in the second title row.
The magic bit in menu_property.lua seems to be the
displayThreeTableView and
Helper.updateCellText which allows you to update some Cell Text
Code: Select all
-- create tableview
menu.infotable, menu.selecttable, menu.buttontable = Helper.displayThreeTableView(menu, infodesc, selectdesc, buttondesc, false, "", "", 0, 0, 0, 0, "both", firsttime)
...
local infotext = IsSameComponent(rowdata, menu.playership) and "%s = %d %%, %s = %d %%, %s = %s / %s / %s" or "%s = %d %%, %s = %d %%, %s = %s / %s / %s\n%s%s %s"
Helper.updateCellText(menu.infotable, 2, 1, string.format(infotext, ReadText(1001, 2), shieldpercent, ReadText(1001, 1), hullpercent, ReadText(1001, 2943), cluster, sector, zone, ReadText(1001, 78), ReadText(1001, 120), aicommand))
and with a fantastic bit of luck
menu_buildcost.lua is also using the Helper.displayThreeTableView (I didn't think that it was when I made the original post) which supports the variable information in the second title line but it doesn't use infotext at all ....
So if I do
Code: Select all
local setup = Helper.createTableSetup(menu)
Add Title line 1
Add Title line 2
setup:addHeaderRow ...
get resources
for _, entry in ipairs(resources) do
check needed wares against storage and if there is insufficient energy or food then create an error message
display resource entry
end
if lengthrecyclingIssues ~= #recyclingIssues then -- there are some issues
local infotext = "%s"
Helper.updateCellText(menu.infotable, 2, 1, string.format(infotext, " \27R" .. recyclingIssues .. "\27X"))
end
then it sticks a red error message in the second title line and it seems to overwrite the original "Title line 2" with no problem which is exactly what I wanted
I hope that this is allowable and not a fortunate coincidence
and thanks for providing what should have been the simplest answer to implement
jth