Jump to content

Turning off % displays on items


Recommended Posts

@JadeKnightblazer@Mobbstar,

 

Line 220 in "..\scripts\widgets\itemtile.lua"

self.percent:SetString(string.format("%2.0f%%", val_to_show))

Specifically the "%%". It appends a percent sign to the values. (According to this)

 

It's in the "ItemTile:SetPercent(percent)" function. To change it, just override that function in your modmain using AddClassPostConstruct("widgets/itemtile", your_itemtile_postconst)

 

Link to comment
Share on other sites

@JadeKnightblazer@Mobbstar,

 

Line 220 in "..\scripts\widgets\itemtile.lua"

self.percent:SetString(string.format("%2.0f%%", val_to_show))

Specifically the "%%". It appends a percent sign to the values. (According to this)

 

It's in the "ItemTile:SetPercent(percent)" function. To change it, just override that function in your modmain using AddClassPostConstruct("widgets/itemtile", your_itemtile_postconst)

 

Thanks, now just to figure out how to use it for only certain items.

 

Was hoping something easy like this could be placed in the customitem script.

 

inst.AddWidget("itemtile")
inst.widgets.itemtile.percent:SetString(" ")
 
but... AddWidget does not work.
 
 
Possible to post an example of your AddClassPostConstruct, with the custom postconst enable / disable certain custom items with the ItemTile:SetPercent.
 
please :-)

 

Link to comment
Share on other sites

@JadeKnightblazer,

 

Not sure if I understood your question correctly. I think you meant something like this.

local function itemtile_post(self, invitem)    -- save old function    self.old_SetPercent = self.SetPercent    -- override with your own function    self.SetPercent = function(self, percent)        -- call old function first        self:old_SetPercent(percent)        if self.invitem and self.invitem.prefab == "your_item_prefab" then            local oldStr = self.percent:GetString()            self.percent:SetString(string.format("%2.0f", oldStr)) -- remove %        end    endendAddClassPostConstruct("widgets/itemtile", itemtile_post)

Remember to change your_item_prefab accordingly.

 

Link to comment
Share on other sites

--Turn off percent on certain Items	local function itemtile_post(self, invitem)    -- save old function    self.old_SetPercent = self.SetPercent     -- override with your own function    self.SetPercent = function(self, percent)		    -- call old function first		self:old_SetPercent(percent)				if self.invitem and self.invitem.prefab == "skitemmealticket" then                          local oldStr = self.percent:GetString()			--self.percent:SetString(string.format("%2.0f", oldStr)) -- remove %			  self.percent:SetString(string.sub(oldStr,1,-2))		end    endendAddClassPostConstruct("widgets/itemtile", itemtile_post)

All placed in the modmain.lua

 

This code does not crash the game at all, nor does it remove the percent indicator =/. Most likely on my end unless others havn't been around to get this run-a-around to work. 

Link to comment
Share on other sites

@JadeKnightblazer,

 

Add these print statements and see what they print to the console/log:

--Turn off percent on certain Itemslocal function itemtile_post(self, invitem)    -- save old function    self.old_SetPercent = self.SetPercent        -- override with your own function    self.SetPercent = function(self, percent)             -- call old function first        self:old_SetPercent(percent)                print("Checking prefab")        if self.invitem and self.invitem.prefab == "skitemmealticket" then            local oldStr = self.percent:GetString()            print(oldStr)            --self.percent:SetString(string.format("%2.0f", oldStr)) -- remove %            local newStr = string.sub(oldStr,1,-2)            print(newStr)            self.percent:SetString(newStr)        end    endendAddClassPostConstruct("widgets/itemtile", itemtile_post)
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
×
  • Create New...