Tyski Posted Thursday at 02:28 AM Share Posted Thursday at 02:28 AM To preface, I am diving into creating mods for DST and started tackling bigger projects, but my LUA knowledge is preliminary and mainly being translated from when I played around with LUA in OG Roblox. I've created a prefab that can be used like a sewing kit to instead increase the max durability of repairable clothing; once per clothing piece. Now, I worked this out all fine and dandy. However... I created a UI widget to overlay the clothing inventory image as an indicator that the equipment has had its durability increased and therefore cannot have it done again. I utilized the wet item widget and TEX, for when your items in your inventory are wet, as a guideline. (Spoilage was another option but that is behind the inventory image [but they're both in the same code so would of ended up in a similar place]) Using Itemtile.lua I was able to hook in my own itemtile overlay to be an event listened for that activates the indicator akin to making your items have that wetness border. and this works as intended. (A bit blurry and could use some position adjustments, but that is an easy TEX troubleshooting fix) The crux of the problem is that when the affected item is picked up/equipped/dropped or just moved out of its inventory slot in any way, the custom itemtile overlay goes away for ever. I have inferred that this is maybe a result of the lacking PushEvent() instance to cause the custom itemtile overlay to appear again; or as coded to only show after checking if the affected prefab has the appropriate tag. As currently only the custom prefab calls the event to apply the overlay the first time. I thought it'd be as simple as hooking onto the itemtile:Refresh() code in Itemtile.lua but from testing that just runs on a load and probably after entering/exiting caves. (Tested by having the custom itemtile overlay show as default in Refresh() ) There's the function in Itemtile.lua, itemtile:StartDrag(), which sets the self.dragging value in itemtile to true however I cannot find, with my preliminary experience, where this value is ever then set back to false/nil. As I tried to pursue utilizing the instance of stopping item dragging to check and call to reinstate the custom itemtile overlay. I have tried to trace where itemtile:StartDrag() may be called from using debug traceback and also modifying it to call a nil value to crash and then see where StartDrag() was called, but while it led me to the widget inventorybar, inventory_classified and inventoryitem_classified prefabs, and the inventoryitem_replica component, I still didn't find much fruition to either where itemtile's self.dragging was set false/nil again to reinstate the itemtile widget, or where I may hook to call PushEvent() for my custom itemtile overlay. I tried following the event "wetness_changed" to find where the code calls to reinstate the wet item overlay, but that let me in circles with moisture and calling to check if an item IsWet, and also getting myself lost in function variables and guessing what they originally were and from where they are called. I did find that itemtile does a check of sort to kill layers with itemtile:SetImageFromItem() but I'm struggling to decipher if there's a table where my custom itemtile overlay gets piled and hidden/killed as a result of the item leaving the inventory slot. I also followed the OnGetItem() call in invetorybar.lua widget, as that set Itemtile(item) for the inventory item in question which calls the aforementioned function but it calls to either kill or show the tile on item acquisition, not turn call to turn on specific overlays if any. From my understanding. I looked into other potential avenues others may have experienced, found, or delved into but seems to have very little discussion on utilizing a custom overlay component for inventory items. Tinting the inventory image of an item Hiding percentages of an item Applying a background color utilizing the spoilage background (Most useful in helping create event listeners and calls) And that is about all I could sift out minus like one or two posts that weren't fruitful/updated with anything meaningful of an answer/solution. Here is current relevant custom code (which works... once): Spoiler -- Network listener to activate overlay for client AddPrefabPostInit("inventoryitem_classified", function(inst) inst.altered = GLOBAL.net_bool(inst.GUID, "inventoryitem.altered", "altereddirty") inst.altered:set(false) if not GLOBAL.TheWorld.ismastersim then local function OnAlteredDirty(parent) local inventoryitem = parent.replica.inventoryitem if inventoryitem ~= nil then parent:PushEvent("tailor_alteration", inst.altered:value()) end end local _RegisterNetListeners = self.RegisterNetListeners self.RegisterNetListeners = function(self, inst) inst:ListenForEvent("altereddirty", OnAlteredDirty, inst._parent) _RegisterNetListeners() end end end) -- Hook to add custom itemtile overlay AddClassPostConstruct("widgets/itemtile", function(self) local UIAnim = require "widgets/uianim" self.tailor_alter = self:AddChild(UIAnim()) self.tailor_alter:GetAnimState():SetBank("alter_icon") self.tailor_alter:GetAnimState():SetBuild("alter_icon") self.tailor_alter:GetAnimState():PlayAnimation("idle") self.wetness:GetAnimState():AnimateWhilePaused(false) self.tailor_alter:SetClickable(false) self.tailor_alter:Hide() self.inst:ListenForEvent("tailor_alteration", function(item, altered) if altered then self.tailor_alter:Show() else self.tailor_alter:Hide() end end, self.item) end) -- New hook to add custom itemtile overlay on game/instance load, which was a good find AddClassPostConstruct("widgets/itemtile", function(self) local _Refresh = self.Refresh self.Refresh = function(self) _Refresh(self) if not self.isactivetile and self.tailor_alter and self.item:HasTag("alteration_tailored") then self.tailor_alter:Show() else self.tailor_alter:Hide() end end end) -- Serversided listener for the event AddClassPostConstruct("components/inventoryitem_replica", function(self) if GLOBAL.TheWorld.ismastersim then self.inst:ListenForEvent("tailor_alteration", function(inst, altered) self.classified.altered:set(altered) end) end end) TL;DR I created an inventoryitem widget overlay that works but goes away if the affected item is moved in any way from it's inventory slot; eg. the overlay is not re-updated and I'm unsure where to call it beyond the initial prefab event call. Also I wanted to ask here to avoid relying on just setting a PeriodicTask() to constantly check if an item has the tag and therefore gets the overlay. That sounds like unnecessary processing when there's probably a solution just slightly beyond my current knowledge. Link to comment https://forums.kleientertainment.com/forums/topic/171097-help-itemtile-widget-inventoryitem-moved-eventpush-call/ 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