[SOLVED] GUI table row caption, item-name or entity-name?

Place to get help with not working mods / modding interface.
Post Reply
Kingdud
Long Handed Inserter
Long Handed Inserter
Posts: 76
Joined: Sat Dec 16, 2017 3:23 am
Contact:

[SOLVED] GUI table row caption, item-name or entity-name?

Post by Kingdud »

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

Code: Select all

info_table.add{type="label", caption={'entity-name.' .. item_internal_name, {"colon"}}}
then all but the module names work, because, obviously, modules don't have an entity at all. But if I switch over to use

Code: Select all

info_table.add{type="label", caption={'item-name.' .. item_internal_name, {"colon"}}}
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.

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
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
Last edited by Kingdud on Fri Jun 03, 2022 12:16 am, edited 1 time in total.

Qon
Smart Inserter
Smart Inserter
Posts: 2119
Joined: Thu Mar 17, 2016 6:27 am
Contact:

Re: GUI table row caption, item-name or entity-name?

Post by Qon »

Kingdud wrote:
Wed Jun 01, 2022 11:28 pm
P.S. any tips/references on how to make a collapsible window?
Add a button that deletes the thing you want to hide. Save state you want to keep, rebuild gui when uncollapsing and restore anything from the saved state.

Kingdud
Long Handed Inserter
Long Handed Inserter
Posts: 76
Joined: Sat Dec 16, 2017 3:23 am
Contact:

Re: GUI table row caption, item-name or entity-name?

Post by Kingdud »

I finally got something that works. This is what I ended up with:

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.
		localization_string = game.item_prototypes[item_internal_name].localised_name
		info_table.add{type="label", caption={"", localization_string, {"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
The trick was that sometimes localization strings are arrays, so starting the caption with

Code: Select all

{""
, and then including the locaization string gets that to work consistently.

Post Reply

Return to “Modding help”