Lazerbeak12345 / flow-extras

An experimental collection of widgets for the Minetest Flow formspec replacement
MIT License
1 stars 0 forks source link

Unable to set `bgimg` in `List` #4

Closed Winterhuman closed 2 months ago

Winterhuman commented 3 months ago

Minetest version: 5.8.0 Sway release: 25444 (1.0.3) Flow release: 25058 (2024-05-15) Flow extras release: 21728 (1.7.2)

I was playing around with your other project, Sway, but, I've recently run into a problem.

I wanted to replace the sway.InventoryTiles() function so I could set the inventory tile image to something else, however, bgimg doesn't respond to any value I set (other than bgimg = { [2] = "example.png" }, which causes an assertion since it's invalid).

I also want to replace the tiles for things like the craft & craftpreview inventories, but that's probably a Sway issue and not relevant here.

Here's what I'm doing:

local list_spacing = 0.25
local function inv_tiles(fields)
    if fields == nil then
        fields = {}
    end
    local w = fields.w or 8
    local h = fields.h or 4
    local bgimg = "example.png"
    return gui.VBox{
        align_v = "end",
        expand = true,
        flow_extras.List{
            align_h = "center",
            inventory_location = "current_player",
            list_name = "main",
            w = w,
            h = 1,
            bgimg = bgimg,
            spacing = list_spacing
        },
        h > 1 and flow_extras.List{
            align_h = "center",
            inventory_location = "current_player",
            list_name = "main",
            w = w,
            h = h - 1,
            bgimg = bgimg,
            starting_item_index = w,
            spacing = list_spacing
        } or gui.Nil{}
    }
end

Please, let me know if you need any more information.

Lazerbeak12345 commented 3 months ago

What sort of values are you trying to set it to?

{
  [2] = "example.png"
}

Wouldn't work because it's a sparse list and this function uses the lua # operator, which assumes the list is not sparse.

(This might be a bug)

Lazerbeak12345 commented 3 months ago

If you're making a mod for sway, this actually sounds like a feature I'd like to be in sway itself - so feel free to send a PR if that's the case. I've been thinking about making the textures easier to swap out by other mods.

Winterhuman commented 3 months ago

This isn't a mod for Sway, but rather an inventory mod I'm making for a game to override the size and look of it. So far, I've tried:

local bgimg = "example.png"
local bgimg =  { "example.png" }
local bgimg = { "example.png", "example.png", ... Number of Tiles }
local bgimg = { bgimg = "example.png" }

I've also tried renaming the image to sway_hb_bg.png and flow_extras_list_bg.png, and trying images with or without alpha channels.

...But no matter what, it uses a different image. Strangely, the inventory tiles I get are brighter than the background they're against (and opaque), but, the flow_extras ... .png & sway_hb_bg.png images are all dark & translucent, and every screenshot I find of a sway/sfinv mod has dark tiles.

I think this means the inventory tiles are using the default formspec texture built into the engine (this is a guess), although I couldn't find any reference to such a texture.

Winterhuman commented 3 months ago

Here's what the tiles looks like currently:

inv

Lazerbeak12345 commented 3 months ago

updated OP with human readable version numbers

Lazerbeak12345 commented 3 months ago

Feel free to re-open if that didn't work.

Lazerbeak12345 commented 3 months ago

Released flow_extras as version 1.7.3

Winterhuman commented 3 months ago

@Lazerbeak12345 Updated flow-extras to 25471 (1.7.3), which I checked by looking at mod.conf and the new gui.Image line, but neither "example.png" nor { "example.png" } cause any change unfortunately.

Winterhuman commented 3 months ago

Adding minetest.log(string.format("%s", the_image)) just before the return line containing gui.Image shows it is being set to example.png, so it isn't that the texture name isn't being passed (manually writing the texture name into the return line leads to the same thing).

When I simplify the return line to return gui.Image{ w = 1, h = 1, texture_name = the_image }, just in case the conditioning was wrong, it also doesn't change anything.

And, if I add:

gui.Image{
    w = 1, h = 1,
    texture_name = "example.png"
},

...inbetween flow.extras.List{} and h > 1 and flow_extras.List{} in my mod, the image displays the right image. I think this means the problem must be in the flow_extras.Grid{} stuff.

Update: moving the gui.List(fields) line before the grid stuff reveals that the images have been getting set, however, they're behind the inventory tiles. So, it's not that the gui.Image tiles aren't using the image, it's that the inventory tiles themselves have the light-grey opaque backgrounds and are covering the bgimg images.

In other words, this is a bug in flow's List element, which is drawing opaque backgrounds when presumably it shouldn't, so this issue can remain closed (unless I've missed something).

Lazerbeak12345 commented 3 months ago

likely fixable with style elements. I'll investigate later

Lazerbeak12345 commented 3 months ago

Thanks to lyk3yx the flow_inspector mod should now work with your use case. They have yet to upload it to contentdb, but I thought I'd mention it since it should make debugging this a bit easier.

Lazerbeak12345 commented 3 months ago

Did some rudimentary testing with the inspector tool.

It seems that (as it is), flow extras doesn't make the list background thingies invisible when it should.

This may require a fair bit of logic rework, so if it's complicated, you'll see a PR for that one

Lazerbeak12345 commented 3 months ago

looking at i3's code (which is under the same license as this repo, so it's legally fine), there's two things they do

  1. get_slots in their gui.lua renders boxes behind each slot, just like I do. I'm sure I'm missing something.
  2. Render image in front of certain slots - but this renders in front of the actual items.

I considered the second option, but if the first option works for i3, then it can work for flow_extras.List.

luk3yx commented 3 months ago

dig through the generated formspec from I3 by hand to look for anything related

Are you looking for listcolors[]? Unfortunately it changes the colours of every list[] element (regardless of whether the list is before or after listcolors[]), i3 works around this by making it semi-transparent so it can still add backgrounds without making other list[]s look bad, unified_inventory (and probably other mods) just make it fully transparent and require you to add slot backgrounds to every list element. I've made flow handle gui.Listcolors correctly in https://github.com/luk3yx/minetest-flow/commit/da87496e26f4d4685fd2164cfdf799358ae90e0c.

Lazerbeak12345 commented 3 months ago

That looks like it to me. I just hadn't gotten around to it yet.

Thinking of it, perhaps I should just document that that element is a prerequisite for this bg functionality. I don't want inclusion of flow-extras.List element to break the rest of the larger form - especially if they are modifying someone else's form.

Lazerbeak12345 commented 2 months ago

resolved in 7687adf

I'd recommend using what luk3yx discovered as a workaround.