Page 1 of 1

Use of build-in tooltips

Posted: Sat Nov 21, 2020 7:05 pm
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?

Re: Use of build-in tooltips

Posted: Sat Nov 21, 2020 7:13 pm
by PFQNiet
Not yet but I suggested it.

Re: Use of build-in tooltips

Posted: Tue Dec 01, 2020 12:13 pm
by ixu
Not yet but I suggested it.
Cannot see how this will help me with my issue. Could you explain?

Re: Use of build-in tooltips

Posted: Tue Dec 01, 2020 2:59 pm
by eradicator
Yea, i also made a suggestion about that once.

Currently choose-elem-button is your only chance.

Re: Use of build-in tooltips

Posted: Tue Dec 01, 2020 3:44 pm
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 1715 times

Re: Use of build-in tooltips

Posted: Thu Dec 03, 2020 12:21 am
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?

Re: Use of build-in tooltips

Posted: Thu Dec 03, 2020 10:51 am
by ixu
The Gui is like this:
inteb2.PNG
inteb2.PNG (1.78 MiB) Viewed 1665 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


Re: Use of build-in tooltips

Posted: Thu Dec 03, 2020 11:44 am
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

Re: Use of build-in tooltips

Posted: Thu Dec 03, 2020 1:54 pm
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 1655 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)

Re: Use of build-in tooltips

Posted: Thu Dec 03, 2020 2:07 pm
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.

Re: Use of build-in tooltips

Posted: Thu Dec 03, 2020 2:11 pm
by ixu
I was just kidding