Thread Tools Display Modes
03-08-12, 06:58 PM   #21
T4YR3L
A Deviate Faerie Dragon
Join Date: Dec 2009
Posts: 15
Originally Posted by suicidalkatt View Post
For bags you probably don't want to have it updating periodically and just use bag events.

Another thing is the (min, max) limits can change so the statusbar will be incorrect unless you update those limits.

So to correct those issues to make it a bit more efficient lets alter a few things.

First lets remove that BAG_UPDATE and register for the inventory update events needed.

OnLoad:
lua Code:
  1. local font,size = self.text:GetFont()
  2. self.text:SetFont(font,size,"OUTLINE")
  3. self.text:SetJustifyH("CENTER")
  4. self.text:SetJustifyV("CENTER")
  5.  
  6. if not self.statusbar then
  7.     self.statusbar = CreateFrame("StatusBar",nil,self)
  8.     self.statusbar:SetStatusBarTexture("Interface\\TargetingFrame\\UI-StatusBar")
  9.     self.statusbar:GetStatusBarTexture():SetHorizTile(false)
  10.     self.statusbar:SetMinMaxValues(0, 100)
  11.     self.statusbar:SetValue(100)
  12.     self.statusbar:SetWidth(self:GetWidth()-2)
  13.     self.statusbar:SetHeight(self:GetHeight()-2)
  14.     self.statusbar:SetFrameLevel(2)
  15.     self.statusbar:SetPoint("CENTER",self,"CENTER")
  16.     self.statusbar:SetStatusBarColor(0,1,0)
  17. end
  18. -- Inventory Events
  19. self:RegisterEvent("BAG_UPDATE")
  20. self:RegisterEvent("UNIT_INVENTORY_CHANGED")
  21. self:RegisterEvent("PLAYER_ENTERING_WORLD")

Second, since we're not going to be updating this constantly and only OnEvent, we leave our OnUpdate empty and we instead place our update code into the OnEvent:

OnEvent
lua Code:
  1. local bagRem, bagTtl = 0, 0
  2.  
  3. for i = 0, NUM_BAG_SLOTS do
  4.     bagRem, bagTtl = bagRem + GetContainerNumFreeSlots(i), bagTtl + GetContainerNumSlots(i)
  5. end
  6.  
  7. self.text:SetText(string.format("Bag: %d/%d", bagRem, bagTtl))
  8. self.statusbar:SetMinMaxValues(0,bagTtl) -- Here we update the amount of bagslots our status bar will show.
  9. self.statusbar:SetValue(bagRem)
  10. local min,max  = self.statusbar:GetMinMaxValues()
  11. if bagRem < (max*0.25) then
  12.     self.statusbar:SetStatusBarColor(1,0,0)
  13. elseif bagRem > (max*0.25) and bagRem < (max/2) then
  14.     self.statusbar:SetStatusBarColor(1,1,0)
  15. else
  16.     self.statusbar:SetStatusBarColor(0,1,0)
  17. end
sorry for the late response.. xD
yeah, you're right, I need to do more practice.
  Reply With Quote
09-21-12, 03:11 AM   #22
Be3f.
A Theradrim Guardian
 
Be3f.'s Avatar
Join Date: Jan 2011
Posts: 65
Originally Posted by suicidalkatt View Post
Bags

OnLoad:
lua Code:
  1. local font,size = self.text:GetFont()
  2. self.text:SetFont(font,size,"OUTLINE")
  3. self.text:SetJustifyH("CENTER")
  4. self.text:SetJustifyV("CENTER")
  5.  
  6. if not self.statusbar then
  7.     self.statusbar = CreateFrame("StatusBar",nil,self)
  8.     self.statusbar:SetStatusBarTexture("Interface\\TargetingFrame\\UI-StatusBar")
  9.     self.statusbar:GetStatusBarTexture():SetHorizTile(false)
  10.     self.statusbar:SetMinMaxValues(0, 100)
  11.     self.statusbar:SetValue(100)
  12.     self.statusbar:SetWidth(self:GetWidth()-2)
  13.     self.statusbar:SetHeight(self:GetHeight()-2)
  14.     self.statusbar:SetFrameLevel(2)
  15.     self.statusbar:SetPoint("CENTER",self,"CENTER")
  16.     self.statusbar:SetStatusBarColor(0,1,0)
  17. end
  18. -- Inventory Events
  19. self:RegisterEvent("BAG_UPDATE")
  20. self:RegisterEvent("UNIT_INVENTORY_CHANGED")
  21. self:RegisterEvent("PLAYER_ENTERING_WORLD")
OnEvent
lua Code:
  1. local bagRem, bagTtl = 0, 0
  2.  
  3. for i = 0, NUM_BAG_SLOTS do
  4.     bagRem, bagTtl = bagRem + GetContainerNumFreeSlots(i), bagTtl + GetContainerNumSlots(i)
  5. end
  6.  
  7. self.text:SetText(string.format("Bag: %d/%d", bagRem, bagTtl))
  8. self.statusbar:SetMinMaxValues(0,bagTtl) -- Here we update the amount of bagslots our status bar will show.
  9. self.statusbar:SetValue(bagRem)
  10. local min,max  = self.statusbar:GetMinMaxValues()
  11. if bagRem < (max*0.25) then
  12.     self.statusbar:SetStatusBarColor(1,0,0)
  13. elseif bagRem > (max*0.25) and bagRem < (max/2) then
  14.     self.statusbar:SetStatusBarColor(1,1,0)
  15. else
  16.     self.statusbar:SetStatusBarColor(0,1,0)
  17. end
Bump.

What would I have to change if I want the statusbar to expand in size/width (as my bags fills) instead of decrease in size/with when my bags fill?
__________________
-- Be3f.
  Reply With Quote
09-21-12, 03:16 AM   #23
suicidalkatt
A Rage Talon Dragon Guard
 
suicidalkatt's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 331
Originally Posted by Be3f. View Post
Bump.

What would I have to change if I want the statusbar to expand in size/width (as my bags fills) instead of decrease in size/with when my bags fill?
Change this:
Lua Code:
  1. self.statusbar:SetValue(bagRem)

To this:
Lua Code:
  1. self.statusbar:SetValue((bagTtl - bagRem))

This effectively changes it from displaying how many slots are remaining to how many slots are filled.

You can also do that with the text update.

Change this:
Lua Code:
  1. self.text:SetText(string.format("Bag: %d/%d", bagRem, bagTtl))

To this:
Lua Code:
  1. self.text:SetText(string.format("Bag: %d/%d", (bagTtl - bagRem), bagTtl))

Last edited by suicidalkatt : 09-21-12 at 03:20 AM.
  Reply With Quote
09-21-12, 03:43 AM   #24
Be3f.
A Theradrim Guardian
 
Be3f.'s Avatar
Join Date: Jan 2011
Posts: 65
Originally Posted by suicidalkatt View Post
This effectively changes it from displaying how many slots are remaining to how many slots are filled.
3 words: You are Awesome

btw: Thanks for the other databars
__________________
-- Be3f.
  Reply With Quote
09-21-12, 04:04 AM   #25
suicidalkatt
A Rage Talon Dragon Guard
 
suicidalkatt's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 331
Originally Posted by Be3f. View Post
3 words: You are Awesome

btw: Thanks for the other databars
NP friend :3
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » KgPanels Script Help! How to Make a DataBar..


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off