[SOLVED] GUI table row caption, item-name or entity-name?
Posted: Wed Jun 01, 2022 11:28 pm
I'm writing a mod that allows you to cheat items into existence, but keeps track of what you cheat into existence so that you can later repay it back. IE: start a fresh game with all tech unlocked, and cheat electric miners into existence along with your end-game mall without needing to wait for techs to unlock, then, as you get production online, it lets you pay back that loan by deleting the items from your inventory as soon as they show up there (once you disable loan mode).
This is my first mod that uses any of the mod_gui functions. I've cobbled together something that mostly works, mainly from the tight_space scenario.
One thing I can't figure out though: the array I have for items to pay back has both entities and items in it. If you paste down a beacon with modules inside, I create both the beacon and the modules inside, and add all to the list. So if I use
then all but the module names work, because, obviously, modules don't have an entity at all. But if I switch over to use
then suddenly almost nothing comes back with a localized name. I don't understand why. In almost every case I can find the entity-name and item-name match, so why doesn't item-name localize?! I've even tried calling entity.prototype.items_to_place_this to try and extract the item-names for entities, and even then, it still won't localize. What am I missing? Full code for my function below. The table itself builds, so this is really down to me trying to get the 'unknown key' junk off my window.
P.S. any tips/references on how to make a collapsible window? Is it a setting, or is there a scenario that has one I can look at? The loan list can get quite long, so I was hoping to make it hidable without needing to add another button
This is my first mod that uses any of the mod_gui functions. I've cobbled together something that mostly works, mainly from the tight_space scenario.
One thing I can't figure out though: the array I have for items to pay back has both entities and items in it. If you paste down a beacon with modules inside, I create both the beacon and the modules inside, and add all to the list. So if I use
Code: Select all
info_table.add{type="label", caption={'entity-name.' .. item_internal_name, {"colon"}}}
Code: Select all
info_table.add{type="label", caption={'item-name.' .. item_internal_name, {"colon"}}}
Code: Select all
local function addLoanWindowRow(p_name, item_internal_name, count)
if not global.players[p_name].info_table then
initLoanWindow(p_name)
end
local info_table = global.players[p_name].info_table
if global.players[p_name].loan_window_labels[item_internal_name] then
global.players[p_name].loan_window_labels[item_internal_name].caption = util.format_number(count)
else
--Table.add fills in one cell at a time.
info_table.add{type="label", caption={'entity-name.' .. item_internal_name, {"colon"}}}
--We need to set a name field and save a reference to update this row in a timely manner.
global.players[p_name].loan_window_labels[item_internal_name] = info_table.add{type="label", caption=util.format_number(count), name=item_internal_name}
end
end