Use of build-in tooltips

Place to get help with not working mods / modding interface.
Post Reply
ixu
Fast Inserter
Fast Inserter
Posts: 105
Joined: Sun May 29, 2016 6:18 pm
Contact:

Use of build-in tooltips

Post by ixu »

Is there a way to call build-in tooltips from my mod - for example the one of recipes in crafting tab of character panel?
Mods: ingteb, ixuClock, ixuAutoSave, NoCheating, hardCrafting (Maintainer) and more
Desperately tried to implement redo :)

PFQNiet
Filter Inserter
Filter Inserter
Posts: 289
Joined: Sat Sep 05, 2020 7:48 pm
Contact:

Re: Use of build-in tooltips

Post by PFQNiet »

Not yet but I suggested it.

ixu
Fast Inserter
Fast Inserter
Posts: 105
Joined: Sun May 29, 2016 6:18 pm
Contact:

Re: Use of build-in tooltips

Post by ixu »

Not yet but I suggested it.
Cannot see how this will help me with my issue. Could you explain?
Mods: ingteb, ixuClock, ixuAutoSave, NoCheating, hardCrafting (Maintainer) and more
Desperately tried to implement redo :)

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

Re: Use of build-in tooltips

Post by eradicator »

Yea, i also made a suggestion about that once.

Currently choose-elem-button is your only chance.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

ixu
Fast Inserter
Fast Inserter
Posts: 105
Joined: Sun May 29, 2016 6:18 pm
Contact:

Re: Use of build-in tooltips

Post by ixu »

Currently choose-elem-button is your only chance.
Can you please explain how choose-elem-button displays the detailed tooltips I get when I hover over a recipe in the crafting menu?
tooltip.PNG
tooltip.PNG (187.75 KiB) Viewed 1666 times
Mods: ingteb, ixuClock, ixuAutoSave, NoCheating, hardCrafting (Maintainer) and more
Desperately tried to implement redo :)

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

Re: Use of build-in tooltips

Post by eradicator »

Maybe you should start by stating what you're actually trying to do. I was assuming you're building a custom gui, for which choose-elem-button might (or might not) be a possible approach. Have you read the doc on LuaGuiElement.elem_type and elem_value?
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

ixu
Fast Inserter
Fast Inserter
Posts: 105
Joined: Sun May 29, 2016 6:18 pm
Contact:

Re: Use of build-in tooltips

Post by ixu »

The Gui is like this:
inteb2.PNG
inteb2.PNG (1.78 MiB) Viewed 1616 times
There are sprites and sprite-buttons of items, recipes and technologies. I can set guiElement.tooltip to some self-created localised string, but in case of recipes it would be very nice to present the tooltip factorio would present.
the code is as follows (although the snippet probably doesn't say very much):

Code: Select all

local function CreateSprite(frame, target)
    local tooltip = target and target.HelperText
    local sprite = target and target.SpriteName
    local number = target and target.NumberOnSprite
    local show_percent_for_small_numbers = target and target.UsePercentage
    local style = Helper.SpriteStyleFromCode(target and target.SpriteStyle)

    if target then
        return frame.add {
            type = "sprite-button",
            tooltip = tooltip,
            sprite = sprite,
            number = number,
            show_percent_for_small_numbers = show_percent_for_small_numbers,
            style = style,
        }
    end
    return frame.add {type = "sprite-button", style = style}
end

Mods: ingteb, ixuClock, ixuAutoSave, NoCheating, hardCrafting (Maintainer) and more
Desperately tried to implement redo :)

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

Re: Use of build-in tooltips

Post by eradicator »

ixu wrote:
Thu Dec 03, 2020 10:51 am
I can set guiElement.tooltip to some self-created localised string,
choose-elem-button shows tooltips automatically:

Code: Select all

/c
game.player.gui.center.clear()
local button = game.player.gui.center.add{type='choose-elem-button',elem_type='recipe'}
button.elem_value = 'iron-plate'
button.locked = true
Attachments
elem.png
elem.png (97.37 KiB) Viewed 1612 times
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

ixu
Fast Inserter
Fast Inserter
Posts: 105
Joined: Sun May 29, 2016 6:18 pm
Contact:

Re: Use of build-in tooltips

Post by ixu »

That is quite cool. I missed it when I read the docu.
But actually this is not enough for my purpose.
1. This tooltip belongs to prototype. I need the one that belongs to the player (as in crafting-panel view)
2. Consequently, I would also like to have the number of objects that can be crafted displayed as a small number.
3. Since I allow a creation from my display, I would have liked to show it in the tooltip

Here is what I currently present:
tooltip2.PNG
tooltip2.PNG (805.59 KiB) Viewed 1606 times
So, if I would have a free wish here, I would like a function LuaPlayer.get_recipe_tooltip(recipe) analogous to Function LuaControl.get_craftable_count(recipe)
Mods: ingteb, ixuClock, ixuAutoSave, NoCheating, hardCrafting (Maintainer) and more
Desperately tried to implement redo :)

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

Re: Use of build-in tooltips

Post by eradicator »

Like i said it's not a perfect solution, just a possible workaround. Showing the number can be partially faked by adding a label to the element button like it was done before LuaGuiElement.number existed. But getting the position correct is difficult if you want it in the right-bottom corner and want it to work on all gui scales.

Code: Select all

button.add{type='label',...}
ixu wrote:
Thu Dec 03, 2020 1:54 pm
So, if I would have a free wish here
No free wishes in this subforum, gotta go to the other one ;). Maybe you can convince someone to add .number support to choose-elem-button, but I'm not getting my hopes up.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

ixu
Fast Inserter
Fast Inserter
Posts: 105
Joined: Sun May 29, 2016 6:18 pm
Contact:

Re: Use of build-in tooltips

Post by ixu »

I was just kidding
Mods: ingteb, ixuClock, ixuAutoSave, NoCheating, hardCrafting (Maintainer) and more
Desperately tried to implement redo :)

Post Reply

Return to “Modding help”