Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ----------------------------------------------------------------------------------------------------------
- -- Author: Montage@Briarcliff
- -- Version: 1.4 Beta
- -- There is no copyright on this code
- -- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
- -- associated documentation files (the "Software"), to deal in the Software without restriction, including
- -- without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- -- copies of the Software, and to permit persons to whom the Software is furnished to do so.
- -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
- -- LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
- -- NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- -- WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
- -- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- ----------------------------------------------------------------------------------------------------------
- -- Make currency filter
- MoneyBar = {}
- local defaultSave = {
- x = 0,
- y = 1010,
- alpha = 0.3,
- scale = 1750,
- barr = 0,
- barg = 0,
- barb = 0,
- textr = 1,
- textg = 1,
- textb = 1,
- orient = 'horiz',
- };
- local defaultScale = {
- vert = 1000,
- horiz = 1750,
- };
- local currency = {}
- local main = UI.CreateContext("UI")
- local bar = UI.CreateFrame("Frame","Bar",main)
- local plati = UI.CreateFrame("Texture","Platinum",main)
- local gold = UI.CreateFrame("Texture","Gold",main)
- local silver = UI.CreateFrame("Texture","Silver",main)
- local pvp_icon = UI.CreateFrame("Texture","Favor Icon",main)
- local master_plaq = UI.CreateFrame("Texture","Master Craftsmen Mark",main)
- local art_mark = UI.CreateFrame("Texture","Artisan Mark",main)
- local planarite = UI.CreateFrame("Texture","Planarite",main)
- local corr_ss = UI.CreateFrame("Texture","Corrupted Sourcestone",main)
- local curse_ss = UI.CreateFrame("Texture","Cursed Sourcestone",main)
- local vile_ss = UI.CreateFrame("Texture","Vile Sourcestone",main)
- local in_ss = UI.CreateFrame("Texture","Inscribed Sourcestone",main)
- local luck_coin = UI.CreateFrame("Texture","Lucky Coin",main)
- local achieve_plaq = UI.CreateFrame("Texture","Plaque of Achievement",main)
- local moa = UI.CreateFrame("Texture","Mark of Ascension",main)
- local gmoa = UI.CreateFrame("Texture","Greater Mark of Ascension",main)
- local plati_text = UI.CreateFrame("Text","Platinum",main)
- local gold_text = UI.CreateFrame("Text","Gold",main)
- local silver_text = UI.CreateFrame("Text","Silver",main)
- local favor = UI.CreateFrame("Text","Favor",main)
- local master_plaq_text = UI.CreateFrame("Text","Master Craftsman's Mark",main)
- local art_text = UI.CreateFrame("Text","Artisan's Mark",main)
- local plan_text = UI.CreateFrame("Text","Planarite",main)
- local corr_text = UI.CreateFrame("Text","Corrupted Sourcestone",main)
- local curse_text = UI.CreateFrame("Text","Cursed Sourcestone",main)
- local vile_text = UI.CreateFrame("Text","Vile Sourcestone",main)
- local in_text = UI.CreateFrame("Text","Inscribed Sourcestone",main)
- local luck_text = UI.CreateFrame("Text","Lucky Coin",main)
- local ap_text = UI.CreateFrame("Text","Plaques of Achievement",main)
- local moa_text = UI.CreateFrame("Text","Marks of Ascension",main)
- local gmoa_text = UI.CreateFrame("Text","Greater Marks of Ascension",main)
- local MoneyBarIcons = {
- plati,
- gold,
- silver,
- pvp_icon,
- master_plaq,
- art_mark,
- planarite,
- corr_ss,
- curse_ss,
- vile_ss,
- in_ss,
- luck_coin,
- achieve_plaq,
- moa,
- gmoa,
- }
- local MoneyBarText = {
- plati_text,
- gold_text,
- silver_text,
- favor,
- master_plaq_text,
- art_text,
- plan_text,
- corr_text,
- curse_text,
- vile_text,
- in_text,
- luck_text,
- ap_text,
- moa_text,
- gmoa_text,
- }
- local MoneyBarLength = table.maxn(MoneyBarText)
- -- Configure Frames and set initial conditions
- function MoneyBar.Initialize(a)
- if a ~= "Money" then
- return
- end
- if not MoneyBarSave then
- MoneyBarSave = defaultSave
- end
- MoneyBar.BuildAll()
- print("Money Bar loaded.")
- end
- function MoneyBar.BuildAll()
- MoneyBar.GetCurrency()
- MoneyBar.BuildBar()
- MoneyBar.BuildIcons()
- MoneyBar.BuildTextFrames()
- MoneyBar.SetText()
- end
- -- Sets the parameters for the bar
- function MoneyBar.BuildBar()
- bar:SetPoint("TOPLEFT",main,"TOPLEFT",MoneyBarSave.x,MoneyBarSave.y)
- bar:SetBackgroundColor(MoneyBarSave.barr,MoneyBarSave.barg,MoneyBarSave.barb)
- if MoneyBarSave.orient == "vert" then
- bar:SetHeight(MoneyBarSave.scale)
- bar:SetWidth(75)
- else
- bar:SetWidth(MoneyBarSave.scale)
- bar:SetHeight(15)
- end
- bar:SetAlpha(MoneyBarSave.alpha)
- bar:SetLayer(0)
- bar:SetVisible(true)
- bar.fixedPos = true
- function bar.Event:LeftDown()
- if bar.fixedPos then
- return
- end
- bar.leftDown = true
- local mouse = Inspect.Mouse()
- bar.originalXDiff = mouse.x - bar:GetLeft()
- bar.originalYDiff = mouse.y - bar:GetTop()
- local left, top, right, bottom = bar:GetBounds()
- end
- function bar.Event:LeftUp()
- if bar.fixedPos then
- return
- end
- bar.leftDown = false
- end
- function bar.Event:LeftUpoutside()
- if bar.fixedPos then
- return
- end
- bar.leftDown = false
- end
- function bar.Event:MouseMove(x, y)
- if bar.fixedPos then
- return
- end
- if not bar.leftDown then
- return
- end
- local newX = x - self.originalXDiff
- local newY = y - self.originalYDiff
- bar:SetPoint("TOPLEFT", UIParent, "TOPLEFT", newX, newY)
- MoneyBarSave.x = newX
- MoneyBarSave.y = newY
- end
- end
- -- Sets the parameters for the icons
- function MoneyBar.BuildIcons()
- local barScaleWidth = 0
- local barScaleHeight = 0
- if MoneyBarSave.orient == "vert" then
- barScaleHeight = bar:GetHeight()
- else
- barScaleWidth = bar:GetWidth()
- end
- plati:SetPoint("TOPLEFT",bar,"TOPLEFT",0,0)
- gold:SetPoint("TOPLEFT",bar,"TOPLEFT",barScaleWidth*0.06,barScaleHeight*0.06)
- silver:SetPoint("TOPLEFT",bar,"TOPLEFT",barScaleWidth*0.12,barScaleHeight*0.12)
- pvp_icon:SetPoint("TOPLEFT",bar,"TOPLEFT",barScaleWidth*0.18,barScaleHeight*0.18)
- planarite:SetPoint("TOPLEFT",bar,"TOPLEFT",barScaleWidth*0.24,barScaleHeight*0.24)
- corr_ss:SetPoint("TOPLEFT",bar,"TOPLEFT",barScaleWidth*0.30,barScaleHeight*0.30)
- curse_ss:SetPoint("TOPLEFT",bar,"TOPLEFT",barScaleWidth*0.36,barScaleHeight*0.36)
- vile_ss:SetPoint("TOPLEFT",bar,"TOPLEFT",barScaleWidth*0.42,barScaleHeight*0.42)
- in_ss:SetPoint("TOPLEFT",bar,"TOPLEFT",barScaleWidth*0.48,barScaleHeight*0.48)
- achieve_plaq:SetPoint("TOPLEFT",bar,"TOPLEFT",barScaleWidth*0.54,barScaleHeight*0.54)
- moa:SetPoint("TOPLEFT",bar,"TOPLEFT",barScaleWidth*0.60,barScaleHeight*0.60)
- gmoa:SetPoint("TOPLEFT",bar,"TOPLEFT",barScaleWidth*0.66,barScaleHeight*0.66)
- luck_coin:SetPoint("TOPLEFT",bar,"TOPLEFT",barScaleWidth*0.72,barScaleHeight*0.72)
- master_plaq:SetPoint("TOPLEFT",bar,"TOPLEFT",barScaleWidth*0.78,barScaleHeight*0.78)
- art_mark:SetPoint("TOPLEFT",bar,"TOPLEFT",barScaleWidth*0.84,barScaleHeight*0.84)
- plati:SetTexture("Money","plat.png")
- gold:SetTexture("Money","gold.png")
- silver:SetTexture("Money","silver.png")
- pvp_icon:SetTexture("Rift","item_icons\\trinket5.dds")
- planarite:SetTexture("Rift","item_icons\\planarite_orb_b.dds")
- corr_ss:SetTexture("Rift","item_icons\\sourcestone_04.dds")
- curse_ss:SetTexture("Rift","item_icons\\sourcestone_02z_z.dds")
- vile_ss:SetTexture("Rift","item_icons\\sourcestone_01.dds")
- in_ss:SetTexture("Rift","item_icons\\mystical_stone1.dds")
- achieve_plaq:SetTexture("Rift","item_icons\\plaque_of_achievement.dds")
- moa:SetTexture("Rift","item_icons\\card30c.dds")
- gmoa:SetTexture("Rift","item_icons\\card30a.dds")
- luck_coin:SetTexture("Rift","item_icons\\trinket8.dds")
- master_plaq:SetTexture("Rift","item_icons\\card28a.dds")
- art_mark:SetTexture("Rift","item_icons\\trinket27a.dds")
- for i=1,MoneyBarLength,1 do
- MoneyBarIcons[i]:SetHeight(15)
- MoneyBarIcons[i]:SetWidth(15)
- MoneyBarIcons[i]:SetLayer(2)
- MoneyBarIcons[i]:SetVisible(true)
- end
- end
- -- Sets the parameters for the text frames
- function MoneyBar.BuildTextFrames()
- for i=1,MoneyBarLength,1 do
- MoneyBarText[i]:SetFontColor(MoneyBarSave.textr,MoneyBarSave.textg,MoneyBarSave.textb,1)
- end
- for i=1,MoneyBarLength,1 do
- MoneyBarText[i]:SetLayer(2)
- MoneyBarText[i]:SetVisible(true)
- if MoneyBarSave.orient == "vert" then
- MoneyBarText[i]:SetPoint("TOPLEFT",bar,"TOPLEFT",0,MoneyBarIcons[i]:GetBottom())
- else
- MoneyBarText[i]:SetPoint("TOPLEFT",bar,"TOPLEFT",MoneyBarIcons[i]:GetRight(),0)
- end
- end
- end
- -- Get the table of currencies
- function MoneyBar.GetCurrency()
- local list = Inspect.Currency.List()
- for k,j in pairs(list) do
- currency[j] = Inspect.Currency.Detail(k)
- end
- end
- -- Sets the text frames to the amount of each currency
- function MoneyBar.SetText()
- MoneyBar.ClearText()
- MoneyBar.TextLoc()
- local len = string.len(MoneyBar.GetStack("Platinum, Gold, Silver"))
- if len <= 4 then
- plati_text:SetText("0")
- else
- plati_text:SetText(string.sub(MoneyBar.GetStack("Platinum, Gold, Silver"),1,len-4))
- end
- gold_text:SetText(string.sub(MoneyBar.GetStack("Platinum, Gold, Silver"),len-3,len-2))
- silver_text:SetText(string.sub(MoneyBar.GetStack("Platinum, Gold, Silver"),len-1,len))
- favor:SetText(MoneyBar.GetStack("Favor"))
- plan_text:SetText(MoneyBar.GetStack("Planarite"))
- master_plaq_text:SetText(MoneyBar.GetStack("Master Craftsman's Mark"))
- art_text:SetText(MoneyBar.GetStack("Artisan's Mark"))
- corr_text:SetText(MoneyBar.GetStack("Corrupted Sourcestone"))
- curse_text:SetText(MoneyBar.GetStack("Cursed Sourcestone"))
- vile_text:SetText(MoneyBar.GetStack("Vile Sourcestone"))
- in_text:SetText(MoneyBar.GetStack("Inscribed Sourcestone"))
- luck_text:SetText(MoneyBar.GetStack("Lucky Coin"))
- ap_text:SetText(MoneyBar.GetStack("Plaque of Achievement"))
- moa_text:SetText(MoneyBar.GetStack("Mark of Ascension"))
- gmoa_text:SetText(MoneyBar.GetStack("Greater Mark of Ascension"))
- end
- -- Should clear text frame to prevent text messiness.
- function MoneyBar.ClearText()
- for i=1,MoneyBarLength,1 do
- MoneyBarText[i]:ClearAll()
- end
- end
- -- Change Text Colors
- function MoneyBar.ChangeTextColor(mbr,mbg,mbb)
- for i=1,MoneyBarLength,1 do
- MoneyBarText[i]:SetFontColor(mbr,mbg,mbb,1)
- end
- end
- -- Reset the Text Frame's position after ClearAll() has been used
- function MoneyBar.TextLoc()
- if MoneyBarSave.orient == "vert" then
- for i=1,MoneyBarLength,1 do
- MoneyBarText[i]:SetPoint("TOPLEFT",bar,"TOPLEFT",0,MoneyBarIcons[i]:GetTop() + 10)
- end
- else
- for i=1,MoneyBarLength,1 do
- MoneyBarText[i]:SetPoint("TOPLEFT",bar,"TOPLEFT",MoneyBarIcons[i]:GetRight(),0)
- end
- end
- end
- -- Gets the current amount of each currency
- function MoneyBar.GetStack(a)
- local list = Inspect.Currency.List()
- local stack = -1
- for k,j in pairs(list) do
- currency[j] = Inspect.Currency.Detail(k)
- if currency[j].name == a then
- stack = currency[j].stack
- break
- else
- stack = 0
- end
- end
- if not stack then
- stack = -1
- end
- stack = tostring(stack)
- return stack
- end
- function MoneyBar.Reset()
- bar:ClearAll()
- MoneyBar.BuildAll()
- end
- -- Slash Commands other than scale and Scale currently
- function MoneyBar.SlashHandler(args)
- local cmd = {}
- local numargs = 0
- for token in string.gmatch(args, "[^%s]+") do
- cmd[numargs] = token
- numargs = numargs + 1
- end
- if cmd[0] == "default" then
- MoneyBarSave = defaultSave;
- MoneyBar.Reset()
- print("Money Bar successfully reset to default configuration.")
- elseif cmd[0] == "alpha" then
- if numargs ~= 2 then
- print("Incorrect usage. /moneybar alpha <a>")
- return
- end
- MoneyBarSave.alpha = tonumber(cmd[1])/10
- bar:SetAlpha(MoneyBarSave.alpha)
- elseif cmd[0] == "move" then
- bar.fixedPos = not bar.fixedPos
- if bar.fixedPos then
- print("Moving toggled off.")
- else
- print("Moving toggled on. Drag bar to move it to a new position.")
- end
- elseif cmd[0] == "scale" then
- if numargs ~= 2 then
- print("Incorrect usage. /moneybar scale <w>")
- return
- end
- local scale = cmd[1]
- scale = tonumber(scale)
- if not scale then
- print("Enter a number to set the width (or height if vertical) of the bar (Default is 1750)")
- end
- if MoneyBarSave.orient == "vert" and (scale > 2000 or scale < 700) then -- Minimum limitation is there because it doesn't align correctly when lower than the minimum. Maximum dimension actually still aligns fine... but I REALLY don't think anyone has a monitor that is > ####x2000 screen resolution. TODO: Remove/change this limitation when currency filtering is implemented.
- print("Invalid scale number. Please choose a number between 700 and 2000.")
- return
- elseif MoneyBarSave.orient == "horiz" and (scale > 2100 or scale < 950) then -- Doesn't position correctly beyond these scales. TODO: Remove/change this limitation when currency filtering is implemented.
- print("Invalid scale number. Please choose a number between 950 and 2100.")
- return
- end
- MoneyBarSave.scale = scale
- if not bar.fixedPos then -- We want the bar to still be movable after scaling if it was movable before scaling
- MoneyBar.Reset()
- bar.fixedPos = false
- else
- MoneyBar.Reset()
- end
- print("Money Bar scale successfully set to: " .. scale)
- elseif cmd[0] == "orient" then
- if numargs ~= 2 then
- print("Incorrect usage. /moneybar orient <horiz/vert>")
- end
- if cmd[1] == "vert" then
- MoneyBarSave.orient = "vert"
- MoneyBarSave.scale = defaultScale.vert
- MoneyBarSave.y = 10
- MoneyBar.Reset()
- print("Money Bar orientation successfully set to: vert")
- elseif cmd[1] == "horiz" then
- MoneyBarSave.orient = "horiz"
- MoneyBarSave.scale = defaultScale.horiz
- MoneyBarSave.x = 10
- MoneyBar.Reset()
- print("Money Bar orientation successfully set to: horiz")
- else
- print("Incorrect usage. /moneybar orient <horiz/vert>")
- end
- elseif cmd[0] == "help" then
- print("/moneybar move toggles the bar to be movable. When toggled on, the bar is movable by dragging with your mouse.")
- print("/moneybar default sets the bar to the default position,width, orientation, and colors")
- print("/moneybar alpha <a> sets the bar's transparency. 'a' is a number between 0 and 10 with 10 being solid and 0 being invisible")
- print("/moneybar scale <w> allows you to change the width of the bar (default setting is 1750)")
- print("/moneybar orient <horiz/vert> sets the bar to horizontal or vertical")
- print("/moneybarcolor bar <r g b/color> takes in colors or RGB numbers as r g b where r, g, and b are between 0 and 255")
- print("/moneybarcolor text <r g b/color> takes in colors or RGB numbers as r g b where r, g, and b are between 0 and 255")
- print("Current color options are black, red, green, blue, brown, white, orange, and purple")
- else
- print("Not a valid command. Use /moneybar help to see a list of commands")
- end
- end
- -- Handles slash commands to change colors for the bar and text
- function MoneyBar.Colors(arg)
- local a,r,g,b = arg:match("(%a+) (%d+) (%d+) (%d+)")
- if not r then
- a,r = arg:match("(%a+) (%a+)")
- end
- if a == "bar" then
- if r == "black" then
- bar:SetBackgroundColor(0,0,0)
- elseif r == "red" then
- bar:SetBackgroundColor(1,0,0)
- elseif r == "green" then
- bar:SetBackgroundColor(0,1,0)
- elseif r == "blue" then
- bar:SetBackgroundColor(0,0,1)
- elseif r == "brown" then
- bar:SetBackgroundColor(0.54,0.36,0.36)
- elseif r == "orange" then
- bar:SetBackgroundColor(1,0.65,0)
- elseif r == "white" then
- bar:SetBackgroundColor(1,1,1)
- elseif r == "purple" then
- bar:SetBackgroundColor(0.61,0.19,1)
- elseif r and g and b then
- r = tonumber(r)/255
- g = tonumber(g)/255
- b = tonumber(b)/255
- bar:SetBackgroundColor(r,g,b)
- end
- elseif a == "text" then
- if r == "black" then
- ChangeTextColor(0,0,0)
- elseif r == "red" then
- ChangeTextColor(1,0,0)
- elseif r == "green" then
- ChangeTextColor(0,1,0)
- elseif r == "blue" then
- ChangeTextColor(0,0,1)
- elseif r == "brown" then
- ChangeTextColor(0.54,0.36,0.36)
- elseif r == "orange" then
- ChangeTextColor(1,0.65,0)
- elseif r == "white" then
- ChangeTextColor(1,1,1)
- elseif r == "purple" then
- ChangeTextColor(0.61,0.19,1)
- elseif r and g and b then
- r = tonumber(r)/255
- g = tonumber(g)/255
- b = tonumber(b)/255
- bar:SetBackgroundColor(r,g,b)
- end
- else
- print("The command is /moneybarcolor <bar/text> <color/rgb>")
- print("Current color options are black, red, green, blue, brown, white, orange, and purple")
- end
- end
- table.insert(Command.Slash.Register("moneybar"),{MoneyBar.SlashHandler,"Money","Slash Commands"})
- table.insert(Command.Slash.Register("moneybarcolor"),{MoneyBar.Colors,"Money","Color Slash Commands"})
- table.insert(Event.Addon.Load.End,{MoneyBar.Initialize,"Money","Create UI"})
- table.insert(Event.Currency,{MoneyBar.SetText,"Money","Update"})
- table.insert(Event.Unit.Available,{MoneyBar.GetCurrency,"Money","Get Currency"}) -- May remove later, especially once bug is fixed on Units not being available when loading
Add Comment
Please, Sign In to add comment