Jump to content

How to change the background color or edges color of the items in the inventory?


Recommended Posts

So, this is my first post here. I'm thinking of a mod to favor items, for example, click on Alt + the item in the inventory and the bottom of it would look like some food, but without "spoiling", always green. or like when it gets wet and turns blue around the edges, but I looked in the files and found nothing about it, just a code that changes the color of the text and not the edges

Link to comment
Share on other sites

I don't know much about this topic, but I might be able to put you on the right track.

hud.lua points to an animation file called spoil_meter.zip. Check it out, it might be a lead you could use. My theory is you need to figure out how to apply your own textures on the layer these are on.

Sorry if I wasn't much of a help.

Link to comment
Share on other sites

I'm not sure what your goals are, but one simple way to do this could be to add the perishable component to the item and then stop it from actually perishing by calling Perishable:StopPerishing(). This would give it a permanent green effect. Obviously this wouldn't really work if the item itself is perishable though, and it's possible that it might cause other bugs, but if you don't intend to use this on food then it might work.

A better but more complex method would be to to edit the ItemTile widget. The way the spoiled color frame works is by adding a UIAnim to the ItemTile, the state of which is adjusted based on the perish level. So, you can do the same by adding a UIAnim called "favor" that uses the same animations, set it to full green, and then hide it. Then, show or hide the animation using networked variables that the server uses to tell a client whether an item is favored or not. See the example below:

AddClassPostConstruct("widgets/itemtile",function(self)
    --First, create and setup the green frame.
    self.favor = self:AddChild(UIAnim())
    self.favor:GetAnimState():SetBank("spoiled_meter")
    self.favor:GetAnimState():SetBuild("spoiled_meter")
    self.favor:SetClickable(false)

    self.favor:GetAnimState():OverrideSymbol("meter", "spoiled_meter", "meter_green")
    self.favor:GetAnimState():OverrideSymbol("frame", "spoiled_meter", "frame_green")
    self.favor:GetAnimState():SetPercent("anim", 0)

    self.favor:Hide()
    
    --Now the green frame exists, it just needs to be shown or hidden when necessary. So, setup an event listener to do so.
    self.inst:ListenForEvent("favorchange", function(item, favored)
        if favored then self.favor:Show()
        else self.favor:Hide() end
     end, self.item)
end)

--Now you must create a networked variable that tells the clients when to show or hide the green frame.
AddPrefabPostInit("inventoryitem_classified", function(inst)
    inst.favored = GLOBAL.net_bool(inst.GUID, "inventoryitem.favored", "favordirty")
    inst.favored:set(false)
    
    if not GLOBAL.TheWorld.ismastersim then
      inst:DoTaskInTime(0, function(inst)
          inst:ListenForEvent("favordirty", function(inst) 
              inst._parent:PushEvent("favorchange", inst.favored:value())
            end)
        end)
    end
end)

--When the "favorchange" event is pushed by the server on an item, the server will set the network variable to the value passed.
AddClassPostConstruct("components/inventoryitem_replica", function(self)
    if GLOBAL.TheWorld.ismastersim then
	self.inst:ListenForEvent("favorchange", function(inst, favored) self.classified.favored:set(favored) end)
    end
end)

With the above code in modmain, all you should have to do is push the "favorchange" event along with true or false whenever you want to show the green border or not. As an example:

item:PushEvent("favorchange", true) --This will show the green effect.

item:PushEvent("favorchange", false) --This will hide the green effect.

I wrote this up quick and haven't tested it so there may be some syntax errors or bugs, but it should be enough to get you started. Hope this helps.

Edited by Ziro2k
  • Health 1
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...