Add information to existing tooltips

Place to get help with not working mods / modding interface.
Post Reply
Roaan
Manual Inserter
Manual Inserter
Posts: 1
Joined: Thu Nov 16, 2017 7:11 pm
Contact:

Add information to existing tooltips

Post by Roaan » Thu Nov 07, 2019 12:16 am

I am new to modding Factorio but I am a software developer by trade so I am not new to coding, just new to Factorio modding. I love the new tooltip update and now that the inserter rotation speed is exposed in the tool tip I'd like to add a little mod that simply adds an additional line item in the tooltip for items transferred per second. Here is my mockup:

Image

All the information needed is in the tooltip already I just want to add some simplistic math that can give a ballpark throughput number. Something super simple like:

Code: Select all

throughput = (rotation_speed / 360) * hand_stack_size
My problem is that I am not sure where tooltip rendering takes place and I am not sure which file I would make my changes in. I took a look a two different mods source codes that have two different approaches and didn't make much progress.

Actual Craft Time - Intercept Tooltip
This mod does all it's work in control.lua but it constructs its own custom UI and does not modify any existing. I first came to this mod because I was trying to subscribe to an event and when a tooltip GUI gets rendered I would intercept and if its an inserter tooltip just add in my line of info. But I couldn't figure out where tooltips were rendered so I moved on.

Multi-Product Recipe Details - Changing a tooltip in place
This mod does a fantastic job of using data-final-fixes.lua to altar all recipes to use the full name of each output instead of just the image. I made a lot of progress here and used data.raw to get information about inserters but I still was not able to find out how to modify the tooltip. Int he end I realized that (if I understand correctly) since this file is only run during loading this wont really help because inserter stack size can be altered by research so my code will probably need to live in control.lua not final fixes.

So currently I'm at a loss. I have looked through the APIs and the possible prototypes and events but I still have yet to figure out where tooltips are generated and how to add to them.

Honktown
Fast Inserter
Fast Inserter
Posts: 183
Joined: Thu Oct 03, 2019 7:10 am
Contact:

Re: Add information to existing tooltips

Post by Honktown » Thu Nov 07, 2019 7:18 pm

I can't provide any specific help, but some mods alter enemy info boxes:

Explosive Biters and Cold Biters are up-to-date. Explosive biters are vulnerable to "cold" damage and cold are resistant to it.

Hardcorio is another one. It hasn't been updated since .16, so there may be out of date things in it, but if I recall correctly, it gave enemies extra resistances. The base game resistance types might not be changeable (not sure), but mods that add variants to enemy damage/resistance could have performance issues during combat, because there's a lot of scripting which compensates for behavior base Factorio doesn't provide.

Galindell World may have also had a similar behavior, because it added more enemy variants (wasn't working right last I played).

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 3740
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Add information to existing tooltips

Post by eradicator » Thu Nov 07, 2019 8:41 pm

The vanilla gui is not moddable.
Author of: Hand Crank Generator, Screenshot Hotkey 2.0
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

User avatar
Deadlock989
Smart Inserter
Smart Inserter
Posts: 1482
Joined: Fri Nov 06, 2015 7:41 pm

Re: Add information to existing tooltips

Post by Deadlock989 » Thu Nov 07, 2019 9:09 pm

The best you can do in this regard (currently) is extend the localised description for the entity/recipe/item with faked tooltip-style fonts and text. It doesn't fully match the tooltip section conventions, and you can't do anything about existing dividers, and you can't insert into the middle of existing generated tooltips, but it's as close as you'll get for now.

For example, in your localisations:

Code: Select all

[item-description]
reload-time=[font=default-semibold][color=230,208,175]Reload time:[/color][/font] __1__
movement-penalty=[font=default-semibold][color=230,208,175]Movement penalty:[/color][/font] __1__%
ammo-type=[font=default-semibold][color=230,208,175]Ammo type:[/color][/font] __1__
and then applied to gun descriptions:

Code: Select all

	for _,gun in pairs(data.raw.gun) do
		local desc = {""}
		if gun.attack_parameters then
			if gun.attack_parameters.ammo_category then 
				table.insert(desc, {"item-description.ammo-type", {"ammo-category-name."..gun.attack_parameters.ammo_category}})
			end
			if gun.attack_parameters.movement_slow_down_factor and gun.attack_parameters.movement_slow_down_factor > 0 then 
				if #desc > 1 then table.insert(desc, "\n") end
				table.insert(desc, {"item-description.movement-penalty", gun.attack_parameters.movement_slow_down_factor*100})
			end
		end
		if #desc > 1 then gun.localised_description = desc end
	end
results in things like:

Untitled.png
Untitled.png (23.39 KiB) Viewed 100 times

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 3740
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Add information to existing tooltips

Post by eradicator » Fri Nov 08, 2019 2:11 pm

Deadlock989 wrote:
Thu Nov 07, 2019 9:09 pm

Code: Select all

		if #desc > 1 then gun.localised_description = desc end
Congratulations. You just overwrote all description changes that any other mod might have done. Incorporating existing localised_description keys is easy, but if a mod adds a locale.cfg with a description for an item it's impossible to do this properly (the engine doesn't support it, see this thread).
Author of: Hand Crank Generator, Screenshot Hotkey 2.0
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

User avatar
Deadlock989
Smart Inserter
Smart Inserter
Posts: 1482
Joined: Fri Nov 06, 2015 7:41 pm

Re: Add information to existing tooltips

Post by Deadlock989 » Fri Nov 08, 2019 2:27 pm

eradicator wrote:
Fri Nov 08, 2019 2:11 pm
Congratulations. You just overwrote all description changes that any other mod might have done. Incorporating existing localised_description keys is easy, but if a mod adds a locale.cfg with a description for an item it's impossible to do this properly (the engine doesn't support it, see this thread).
Couldn't care less. If there was a way to detect an existing locale string, I would use it, but there isn't, so you can't. Not my fault, not my problem, not my circus, not my monkeys.

Honktown
Fast Inserter
Fast Inserter
Posts: 183
Joined: Thu Oct 03, 2019 7:10 am
Contact:

Re: Add information to existing tooltips

Post by Honktown » Fri Nov 08, 2019 6:52 pm

@localediscussion
Does the Lua not return nil if you try to use a string that isn't present? Has anyone tried to do if string == nil then <use it> else <default>?

Post Reply

Return to “Modding help”

Who is online

Users browsing this forum: Bilka, Linver