Jump to content

[SOLVED] How to use the slotbg Widget component?


Recommended Posts

Hello,

I've managed to add a custom inventory widget for my weapon, but I'd like to have the tile icon (the tan square) be invisible.

image.png.cecb403deb34bfc2b9038c85466ae53c.png

I know you can do this since Walter's slingshot has an inventory tile with a rock on it. But how would I go about implementing this?

image.png.6b41a171def384875e43b27b63ac0427.png

Edited by Scrumch
I figured out where it is I need to add code, but not how
Link to comment
Share on other sites

You can change this in the widget setup of your weapon. bgatlas and bgimage

 

eg:

containerparams.casket = {
    widget =
    {
        slotpos = slotpos,
        pos = Vector3(0, -100, 0),
		bgatlas = "images/casket-ui.xml",
		bgimage = "casket-ui.tex",
    },
	issidewidget = false,
    type = "casket",
}

 

Edited by krylincy
Link to comment
Share on other sites

Thank you

I've tried that and it just makes the inventory slot itself invisible, not the tan square?

image.png.c6668643d1265d8d34d771be79b95076.png


Here's my widget setup:

Spoiler

local Vector3 = GLOBAL.Vector3
local require = GLOBAL.require
local modparams = {}
-----------------------------------------------------------------------

-----------------------------------------------------------------------
AddComponentPostInit("container", function(self)
    function self:RemoveSingleItemBySlot(slot)
        if slot and self.slots[slot] then
            local item = self.slots[slot]
            return self:RemoveItem(item)
        end
    end
end)

function OnlyArrows(container, item, slot)
    if item.prefab == "wakes_arrow" then
        return true
    end

    return false
end

modparams.wakes_bow = {
    widget =
    {
        slotpos =
        {
            Vector3(0, 0, 0),
        },
        
        animbank = "wakes_bow_ui",
        animbuild = "wakes_bow_ui",
        bgatlas = "images/casket-ui.xml",
        bgimage = "casket-ui.tex",
        pos = Vector3(0, 40, 0),
    },
    issidewidget = false,
    itemtestfn = OnlyArrows,
    type = "hand_inv",
}

local containers = require("containers")

for k, v in pairs(modparams) do
    containers.MAXITEMSLOTS = math.max(containers.MAXITEMSLOTS, v.widget.slotpos ~= nil and #v.widget.slotpos or 0)
end

local OldWidgetSetup = containers.widgetsetup

function containers.widgetsetup(container, prefab, data)
    if modparams[prefab or container.inst.prefab] and not data then
        data = modparams[prefab or container.inst.prefab]
    end
    OldWidgetSetup(container, prefab, data)
end

Also the mod itself if I've put the inventory slot somewhere wrong.

icontest.zip

Link to comment
Share on other sites

Progress! 

I looked in the containers (not container) file and found out I need to set it up with slotbg:

modparams.wakes_bow = {
    widget =
    {
        slotpos =
        {
            Vector3(0, 0, 0),
        },
		slotbg =
        {
			{atlas = "images/inventoryimages/quiver_slot.xml"},
            { image = "quiver_slot.tex" },
        },
        animbank = "wakes_bow_ui",
        animbuild = "wakes_bow_ui",
        pos = Vector3(0, 40, 0),
    },
	issidewidget = false,
	itemtestfn = OnlyArrows,
    type = "hand_inv",
}

This works when I just use previously mentioned default tiles (like Walter's, { image = "slingshot_ammo_slot.tex" },) but when I try to add my own image files I get a blank space (which is good) but it can't be interacted with?

image.png.08855bb413f8977a2b9d64ac6ee599ce.png

Does anyone know how the devs set these slotbg's up?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...