ikatsuke Posted April 8, 2015 Share Posted April 8, 2015 (edited) 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: 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 April 10, 2015 by ikatsuke Link to comment Share on other sites More sharing options...
DarkXero Posted April 8, 2015 Share Posted April 8, 2015 AddClassPostConstruct("widgets/itemtile", function(self) self.inst:DoPeriodicTask(0.1, function() self.image:SetTint(99/255, 99/255, 242/255, 1) end) end) Link to comment Share on other sites More sharing options...
ikatsuke Posted April 8, 2015 Author Share Posted April 8, 2015 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. Also if anyone knows another way that would apply better it would be much appreciated Link to comment Share on other sites More sharing options...
DarkXero Posted April 8, 2015 Share Posted April 8, 2015 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 = 1in 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 More sharing options...
ikatsuke Posted April 8, 2015 Author Share Posted April 8, 2015 Thank you! That will work nicely. I will make sure to post my resulting code here once done. Link to comment Share on other sites More sharing options...
rezecib Posted April 8, 2015 Share Posted April 8, 2015 @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 More sharing options...
Corrosive Posted April 8, 2015 Share Posted April 8, 2015 (edited) @rezecib, Userdata functions are stored(by necessity) on the userdata's metatableprint(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.."()") endendEdit: I imagine you know this already. Was for @ikatsuke's benefit, but I forgot to tag him. Edited April 8, 2015 by Corrosive Link to comment Share on other sites More sharing options...
ikatsuke Posted April 9, 2015 Author Share Posted April 9, 2015 @rezecib, Userdata functions are stored(by necessity) on the userdata's metatableprint(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.."()") endendEdit: 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) endendBut with that little bit it would be so much more powerful thanks a lot! Link to comment Share on other sites More sharing options...
ikatsuke Posted April 10, 2015 Author Share Posted April 10, 2015 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 TintableI 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now