View Single Post
07-03-12, 07:27 AM   #4
Othgar
"That" Guy
 
Othgar's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2010
Posts: 228
Last night while messing around in Beta, I decided I wanted to add some additional texture options to my xp bar. I found the ones I wanted, sized them made them work and made them user selected via slash command. Now I'm stuck on how to get them to save per character. I tried it the same way that I did it for locked/unlocked visable/hidden and couldn't get it to work. I'm guessing it's because I'm not defining the variable correctly, but for the life of me I can't figure out a way to define the variable and save it. Hopefully one of you guys will see something that I don't.

Here's my code:
LUA Code:
  1. -- Tribal Experience Bar
  2. -- By: Othgar
  3. -- Copyleft All Rights Reversed
  4.  
  5. -- Default state
  6. TXPVisible = true;
  7. TXPLocked = true;
  8.  
  9.  
  10. -- Constants
  11. local ThousandSeparator = ","
  12. local TipTitle = "Tribal XP"
  13. local _, class = UnitClass("player")
  14. local r,g,b = RAID_CLASS_COLORS[class].r, RAID_CLASS_COLORS[class].g, RAID_CLASS_COLORS[class].b
  15.  
  16.  
  17.  
  18. local function FmtBigNum(n)
  19.         local left, num, right = string.match(n .. "", '^([^%d]*%d)(%d*)(.-)')
  20.         return left..(num:reverse():gsub('(%d%d%d)', '%1'.. ","):reverse())..right
  21. end
  22.  
  23. local TribalExperienceBar = CreateFrame("StatusBar","TribalExperienceBar",UIParent)
  24. TribalExperienceBar:SetSize(675, 150)
  25. TribalExperienceBar:SetPoint("CENTER", UIParent, "CENTER", 0, 0);
  26. TribalExperienceBar:SetFrameStrata("MEDIUM");  
  27. TribalExperienceBar:SetClampedToScreen(1);
  28. TribalExperienceBar:SetBackdrop({bgFile="Interface\\Tooltips\\UI-Tooltip-Background", edgeFile="", tile=1, tileSize=10, edgeSize=10, insets={left=2, right=2, top=2, bottom=2}});
  29. TribalExperienceBar:SetBackdropColor(r,g,b,0)
  30. TribalExperienceBar:SetMovable(1);
  31. TribalExperienceBar:EnableMouse(1);
  32. TribalExperienceBar:SetStatusBarTexture("..")
  33. TribalExperienceBar:SetStatusBarColor(r,g,b)
  34. TribalExperienceBar:SetAlpha(.75)
  35.  
  36.  
  37.  
  38. local TXPBarText = TribalExperienceBar:CreateFontString("TXPBarText","OVERLAY");
  39. TXPBarText:SetFontObject(GameFontNormal)
  40. TXPBarText:SetTextColor(r,g,b)
  41. TXPBarText:SetPoint("CENTER", TribalExperienceBar, "BOTTOM", 0, 0);
  42. TXPBarText:SetJustifyH("CENTER");
  43. TXPBarText:SetJustifyV("CENTER");
  44.  
  45. --Register Events
  46.  
  47. TribalExperienceBar:RegisterEvent("PLAYER_ENTERING_WORLD");
  48. TribalExperienceBar:RegisterEvent("PLAYER_XP_UPDATE");
  49. TribalExperienceBar:RegisterEvent("PLAYER_LOGIN");
  50. TribalExperienceBar:RegisterEvent("PLAYER_LEVEL_UP");  
  51.  
  52.  
  53. --Event handling
  54. TribalExperienceBar:SetScript("OnEvent", function(self, event, ...)
  55.     local curxp = UnitXP("player")
  56.     local levelmax = UnitXPMax("player")
  57.     local perc = string.format("%.1f%%", (100*(curxp/levelmax)))
  58.     local perbox = levelmax / 20
  59.  
  60.     local mystr = string.format("%.1fb - %.1fb tnl | %s",  curxp / perbox, (levelmax - curxp) / perbox, perc)
  61.    
  62.     TXPBarText:SetText(mystr)
  63.  
  64.    
  65.     TribalExperienceBar:SetMinMaxValues(0, levelmax)
  66.     TribalExperienceBar:SetValue(curxp)
  67.  
  68.     if TXPVisible then
  69.         TribalExperienceBar:Show()
  70.     else
  71.         TribalExperienceBar:Hide()
  72.     end
  73. end)
  74.  
  75. -- move me
  76.  
  77. TribalExperienceBar:SetScript("OnMouseDown", function()
  78.     if not TXPLocked then
  79.         TribalExperienceBar:StartMoving()
  80.     else
  81.         TribalExperienceBar:StopMovingOrSizing()
  82.     end
  83. end)
  84.  
  85. TribalExperienceBar:SetScript("OnMouseUp", function() TribalExperienceBar:StopMovingOrSizing() end)
  86.  
  87.  
  88. -- register slash commands
  89.  
  90. SLASH_TXP1 = '/TXP';
  91. local function slashcmdhandler(param)
  92.     if param == "hide" then
  93.         if TXPVisible then
  94.             TXPVisible=false
  95.             TribalExperienceBar:Hide()
  96.             print("Experience hidden, type /TXP show to show.")
  97.         end
  98.     elseif param=="show" then
  99.         if not TXPVisible then
  100.             TXPVisible=true
  101.             TribalExperienceBar:Show()
  102.             print("Experience displayed, type /TXP hide to hide.")
  103.         end
  104.     elseif param == "rested" then
  105.         if GetXPExhaustion() == nil then
  106.             print("You have no rested EXP.")
  107.         else
  108.             print("You have "..GetXPExhaustion().." rested EXP remaining.")
  109.         end
  110.     elseif param == "lock" then
  111.         if TXPLocked == true then
  112.             TXPLocked = false
  113.             print("TXP UNlocked")
  114.         elseif TXPLocked == false then
  115.             TXPLocked = true
  116.            print("TXP Locked")
  117.         end
  118.     elseif param == "curve" then
  119.         if TribalExperienceBar:SetStatusBarTexture("Interface\\AddOns\\TXP\\media\\curve") == true then
  120.             TribalExperienceBar:SetStatusBarTexture("Interface\\AddOns\\TXP\\media\\curve")
  121.             print("Texture already set to Curve")
  122.         elseif TribalExperienceBar:SetStatusBarTexture("Interface\\AddOns\\TXP\\media\\curve") == false then
  123.             TribalExperienceBar:SetStatusBarTexture("Interface\\AddOns\\TXP\\media\\curve")
  124.             print("Texture set to Curve")
  125.         end
  126.     elseif param == "simple" then
  127.         if TribalExperienceBar:SetStatusBarTexture("Interface\\AddOns\\TXP\\media\\simple") == true then
  128.             TribalExperienceBar:SetStatusBarTexture("Interface\\AddOns\\TXP\\media\\simple")
  129.             print("Texture already set to Simple")
  130.         elseif TribalExperienceBar:SetStatusBarTexture("Interface\\AddOns\\TXP\\media\\simple") == false then
  131.             TribalExperienceBar:SetStatusBarTexture("Interface\\AddOns\\TXP\\media\\simple")
  132.             print("Texture set to Simple")
  133.         end
  134.     elseif param == "split" then
  135.         if TribalExperienceBar:SetStatusBarTexture("Interface\\AddOns\\TXP\\media\\split") == true then
  136.             TribalExperienceBar:SetStatusBarTexture("Interface\\AddOns\\TXP\\media\\split")
  137.             print("Texture already set to Split")
  138.         elseif TribalExperienceBar:SetStatusBarTexture("Interface\\AddOns\\TXP\\media\\split") == false then
  139.             TribalExperienceBar:SetStatusBarTexture("Interface\\AddOns\\TXP\\media\\split")
  140.             print("Texture set to Split")
  141.         end
  142.  
  143.     else
  144.         print("Valid commands are:");
  145.         print("/TXP show (Show the experience bar.)");
  146.         print("/TXP hide (Hide the experience bar.)");
  147.         print("/TXP rested (Shows the amount of rested XP.)");
  148.         print("/TXP Lock (Locks the experience bar if it is unlocked, Unlocks it if it is locked.")
  149.         print("/TXP Curve (Sets the status bar texture to Curve.")
  150.         print("/TXP Simple (Sets the bar texture to Simple")
  151.         print("/TXP Split (Sets the Bar texture to Split")
  152.     end
  153. end
  154. SlashCmdList["TXP"] = slashcmdhandler;
  155.  
  156. --Tooltip
  157.  
  158. local function OnEnter(self)  
  159.     GameTooltip:Show()
  160. end
  161.  
  162. local function OnLeave(self)  
  163.     GameTooltip:Hide()
  164. end
  165.  
  166. --hide @ 85
  167. if UnitLevel("player") >= 85 then
  168.     TribalExperienceBar:Hide() print("Experience bar hidden, type /TXP show to show.")
  169.     TXPVisible = false
  170. end

Here's my TOC:
LUA Code:
  1. ## Interface: 50100
  2. ## Title: Tribal XP Bar
  3. ## Notes: Tribally XP Bar of Prettiness
  4. ## Author: Othgar
  5. ## Version: 1.5a
  6. ## SavedVariablesPerCharacter: TXPVisible, TXPLocked
  7.  
  8.  
  9. TXP.lua

and attached is the full addon just in case.
Attached Files
File Type: zip TXP.zip (362.4 KB, 515 views)
__________________