Jump to content

Inventory item tint/colour possible?


Recommended Posts

I've been searching around the existing lua scripts in the quest of finding a way to tint inventory items. It seems I can only affect the color of an object that has been dropped on the floor or widgets.

 

It would be pretty cool to allow tinting of inventory items (vanity reasons would be an immediate use).

 

I keep bumping into opaque userdata types that do not provide any visibility into which methods are available to be called.

 

Anyone has any suggestions towards how could this be achieved?

 

Here is a visual of what I mean:

 

inventory_item_tint.png

 

I could of-course create a tile-map with all possible colors but that would be really heavy and process intensive to update if shapes changes :( also it would be a pain to duplicate any tex files that I'd like to allow tinting for and force the mod to replace those.

Edited by ikatsuke
Link to comment
Share on other sites

Thanks for the quick reply.

 

While that method would work great as an overall theme (it currently every single item slot with the tinted version), I am attempting to target a single item only. In fact i want to target a single instance of an item.

 

I will try to use your suggestion and see what I can come up that applies better to my use case. I will report back with whatever solution I find for further discussion. :D

 

Also if anyone knows another way that would apply better it would be much appreciated :)

Link to comment
Share on other sites

unpack = GLOBAL.unpacklocal tint = {	{99/255, 99/255, 242/255, 1},	{1/255, 5/255, 100/255, 1},	{200/255, 10/255, 0/255, 1}}AddClassPostConstruct("widgets/itemtile", function(self)	if self.item and self.item.reskin and tint[self.item.reskin] then		self.image:SetTint(unpack(tint[self.item.reskin]))	endend)

Turns out the task wasn't needed.

 

Now to tint an item, you just have to create:

-- 1, 2, 3inst.reskin = 1

in the item's instance while created by the player, so you can now have different items of the same type with different colors.

Link to comment
Share on other sites

@ikatsuke, Userdata are C++ objects defined in the game's compiled exe. You can decompile it to get function names (and maybe more if you know what you're doing), but I believe Peter and Mark plan to get it to generate an API at some point.

 

This project has some of it documented, but it's mixed up with normal game components at the moment.

Link to comment
Share on other sites

@rezecib,

 

Userdata functions are stored(by necessity) on the userdata's metatable

print(table.inspect(getmetatable( <variable referencing userdata> )))

or for something more reusable:

function GetUFuncs(userdata) -- Get funky    for k,_ in pairs(getmetatable(userdata).__index) do print(k.."()") endend

Edit: I imagine you know this already.  Was for @ikatsuke's benefit, but I forgot to tag him.

Edited by Corrosive
Link to comment
Share on other sites

@rezecib,

 

Userdata functions are stored(by necessity) on the userdata's metatable

print(table.inspect(getmetatable( <variable referencing userdata> )))

or for something more reusable:

function GetUFuncs(userdata) -- Get funky    for k,_ in pairs(getmetatable(userdata).__index) do print(k.."()") endend

Edit: I imagine you know this already.  Was for @ikatsuke's benefit, but I forgot to tag him.

 

 

omg, that is the greatest little gem. I had made this func:

p = function (obj)  if type(obj) ~= "table" or type(obj) == "userdata" then    return print(obj)  end  for k,v in pairs(obj) do    print(k)  endend

But with that little bit it would be so much more powerful :D thanks a lot!

Link to comment
Share on other sites

Alrite, here is what I ended up with. Two parts code.

 

A hook onto widgets/itemtile from modmain.lua:

AddClassPostConstruct("widgets/itemtile", function(self)	if self.item    and self.item.components    and self.item.components.tintable  then    self.item.components.tintable:SetImage(self.image)	endend)

Followed by a component tintable.lua:

local Tintable = Class(function(self, inst)  self.inst = inst  self.tint = {1,1,1,1}  self.image = nilend)function Tintable:Tint()  local t = self:tint  -- Tint the inventory tile  self.image:SetTint(unpack(t))  -- Tint the in-game instance  self.inst.AnimState:OverrideMultColour(unpack(t))end-- Provide a way for the hook to provide an instance to the image from itemtilefunction Tintable:SetImage(image)  self.image = image  self:Tint()endfunction Tintable:Set(r, g, b, a)  self.tint = {r, g, b, a}  self:Tint()endreturn Tintable

I trimmed off the onSave/onLoad and extra comments for concise example. It works, not so sure how it stands in terms of performance, network, and what not. I see a few applications that I will be investigating soon.

 

Thanks for all the help guys and am looking forward to feedback to my implementation :)

 

Here is a repo with the full source and some extra information: https://github.com/rdelpeso/mod-tintable-dst

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...