Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- All Credit for Datapanel.lua goes to Tuks.
- Tukui = http://www.tukui.org/download.php.
- Edited by Cokedriver.
- ]]
- local Core = LibStub("AceAddon-3.0"):GetAddon("BasicUI")
- local Module = Core:NewModule("Datapanel", "AceEvent-3.0")
- -- Constants (variables whose values are never altered):
- local PLAYER_CLASS = UnitClass("player")
- local PLAYER_NAME = UnitName("player")
- local PLAYER_REALM = GetRealmName()
- local SCREEN_WIDTH = tonumber(string.match(({GetScreenResolutions()})[GetCurrentResolution()], "(%d+)x+%d"))
- local TOC_VERSION = select(4, GetBuildInfo())
- local GAME_LOCALE = GetLocale()
- -- Variables:
- local db, currentFightDPS, playerRole
- local hexa = "|cffffffff" -- not very descriptive names :(
- -- Variables that point to frames or other objects:
- local MainPanel, LeftPanel, CenterPanel, RightPanel, BGPanel
- ------------------------------------------------------------------------
- -- Local functions
- local function RGBToHex(r, g, b)
- if r > 1 then r = 1 elseif r < 0 then r = 0 end
- if g > 1 then g = 1 elseif g < 0 then g = 0 end
- if b > 1 then b = 1 elseif b < 0 then b = 0 end
- return format("|cff%02x%02x%02x", r*255, g*255, b*255)
- end
- local function HexToRGB(hex)
- local rhex, ghex, bhex = strsub(hex, 1, 2), strsub(hex, 3, 4), strsub(hex, 5, 6)
- return tonumber(rhex, 16), tonumber(ghex, 16), tonumber(bhex, 16)
- end
- local function ShortValue(v)
- if v >= 1e6 then
- return format("%.1fm", v / 1e6):gsub("%.?0+([km])$", "%1")
- elseif v >= 1e3 or v <= -1e3 then
- return format("%.1fk", v / 1e3):gsub("%.?0+([km])$", "%1")
- else
- return v
- end
- end
- local function GetTooltipAnchor()
- local _, y = GetCursorPosition()
- if (y * 2) > UIParent:GetHeight() then
- return "ANCHOR_BOTTOM", 1, 3
- else
- return "ANCHOR_TOP", 1, -3
- end
- end
- local function SetMainPanel()
- local db = Core.db.profile
- if db.datapanel.location ~= "top" then
- MainPanel:SetPoint("BOTTOM", UIParent, 0, 0)
- MainPanel:SetWidth(1200)
- MainPanel:SetFrameLevel(1)
- MainMenuBar:ClearAllPoints()
- MainMenuBar:SetPoint("BOTTOM", MainPanel, "TOP", 0, -3)
- -- Hide Panels When in a Vehicle or Pet Battle
- MainPanel:RegisterUnitEvent("UNIT_ENTERING_VEHICLE", "player")
- MainPanel:RegisterUnitEvent("UNIT_EXITED_VEHICLE", "player")
- MainPanel:RegisterUnitEvent("PET_BATTLE_OPENING_START")
- MainPanel:RegisterUnitEvent("PET_BATTLE_CLOSE")
- MainPanel:RegisterUnitEvent("PLAYER_ENTERING_WORLD")
- MainPanel:SetScript("OnEvent", function(self, event, ...)
- if event == "UNIT_ENTERING_VEHICLE" or event == "PET_BATTLE_OPENING_START" then
- self:Hide()
- elseif event == "UNIT_EXITED_VEHICLE" or event == "PET_BATTLE_CLOSE" or event == "PLAYER_ENTERING_WORLD" then
- SetMainPanel()
- self:Show()
- end
- end)
- else
- MainPanel:SetPoint("TOP", UIParent, 0, 0)
- MainPanel:SetWidth(SCREEN_WIDTH)
- end
- end
- local function SetPanelLeft()
- local db = Core.db.profile
- if db.datapanel.location ~= "top" then
- PanelLeft:SetPoint("LEFT", MainPanel, 5, 0)
- PanelLeft:SetHeight(35)
- PanelLeft:SetWidth(1200 / 3)
- PanelLeft:SetFrameStrata("MEDIUM")
- PanelLeft:SetFrameLevel(2)
- else
- PanelLeft:SetPoint("LEFT", MainPanel, 5, 0)
- PanelLeft:SetHeight(35)
- PanelLeft:SetWidth(SCREEN_WIDTH / 3)
- PanelLeft:SetFrameStrata("LOW")
- PanelLeft:SetFrameLevel(1)
- end
- end
- local function SetPanelCenter()
- local db = Core.db.profile
- if db.datapanel.location ~= "top" then
- PanelCenter:SetPoint("CENTER", MainPanel, 0, 0)
- PanelCenter:SetHeight(35)
- PanelCenter:SetWidth(1200 / 3)
- --PanelCenter:SetFrameStrata("MEDIUM")
- --PanelCenter:SetFrameLevel(1)
- else
- PanelCenter:SetPoint("CENTER", MainPanel, 0, 0)
- PanelCenter:SetHeight(35)
- PanelCenter:SetWidth(SCREEN_WIDTH / 3)
- PanelCenter:SetFrameStrata("LOW")
- PanelCenter:SetFrameLevel(1)
- end
- end
- local function SetPanelRight()
- local db = Core.db.profile
- if db.datapanel.location ~= "top" then
- PanelRight:SetPoint("RIGHT", MainPanel, -5, 0)
- PanelRight:SetHeight(35)
- PanelRight:SetWidth(1200 / 3)
- --PanelRight:SetFrameStrata("MEDIUM")
- --PanelRight:SetFrameLevel(1)
- else
- PanelRight:SetPoint("RIGHT", MainPanel, -5, 0)
- PanelRight:SetHeight(35)
- PanelRight:SetWidth(SCREEN_WIDTH / 3)
- PanelRight:SetFrameStrata("LOW")
- PanelRight:SetFrameLevel(1)
- end
- end
- local function MoveObjects()
- local db = Core.db.profile
- if db.datapanel.location ~= "top" then
- -- World Status
- WorldStateAlwaysUpFrame:ClearAllPoints()
- WorldStateAlwaysUpFrame:SetPoint('TOP', -20, -40)
- -- Move the tooltip above the Actionbar
- hooksecurefunc('GameTooltip_SetDefaultAnchor', function(self)
- self:SetPoint('BOTTOMRIGHT', UIParent, -95, 135)
- end)
- -- Move the Bags above the Actionbar
- CONTAINER_WIDTH = 192;
- CONTAINER_SPACING = 5;
- VISIBLE_CONTAINER_SPACING = 3;
- CONTAINER_OFFSET_Y = 70;
- CONTAINER_OFFSET_X = 0;
- function UpdateContainerFrameAnchors()
- local _, xOffset, yOffset, _, _, _, _;
- local containerScale = 1;
- screenHeight = GetScreenHeight() / containerScale;
- -- Adjust the start anchor for bags depending on the multibars
- xOffset = CONTAINER_OFFSET_X / containerScale;
- yOffset = CONTAINER_OFFSET_Y / containerScale + 25;
- -- freeScreenHeight determines when to start a new column of bags
- freeScreenHeight = screenHeight - yOffset;
- column = 0;
- for index, frameName in ipairs(ContainerFrame1.bags) do
- frame = _G[frameName];
- frame:SetScale(containerScale);
- if ( index == 1 ) then
- -- First bag
- frame:SetPoint('BOTTOMRIGHT', frame:GetParent(), 'BOTTOMRIGHT', -xOffset, yOffset );
- elseif ( freeScreenHeight < frame:GetHeight() ) then
- -- Start a new column
- column = column + 1;
- freeScreenHeight = screenHeight - yOffset;
- frame:SetPoint('BOTTOMRIGHT', frame:GetParent(), 'BOTTOMRIGHT', -(column * CONTAINER_WIDTH) - xOffset, yOffset );
- else
- -- Anchor to the previous bag
- frame:SetPoint('BOTTOMRIGHT', ContainerFrame1.bags[index - 1], 'TOPRIGHT', 0, CONTAINER_SPACING);
- end
- freeScreenHeight = freeScreenHeight - frame:GetHeight() - VISIBLE_CONTAINER_SPACING;
- end
- end
- else
- -- Player Frame
- PlayerFrame:ClearAllPoints()
- PlayerFrame:SetPoint("TOPLEFT", -19, -20)
- -- Target Frame
- TargetFrame:ClearAllPoints()
- TargetFrame:SetPoint("TOPLEFT", 250, -20)
- -- Minimap Frame
- MinimapCluster:ClearAllPoints()
- MinimapCluster:SetPoint('TOPRIGHT', 0, -32)
- -- Buff Frame
- BuffFrame:ClearAllPoints()
- BuffFrame:SetPoint('TOP', MinimapCluster, -110, -2)
- -- PvP Frame
- WorldStateAlwaysUpFrame:ClearAllPoints()
- WorldStateAlwaysUpFrame:SetPoint('TOP', 0, -32)
- end
- end
- ------------------------------------------------------------------------
- -- Module functions
- function Module:OnEnable()
- -- You should fix your DB to use module namespaces properly:
- local db = Core.db.profile
- -- This line should not be needed if you're using modules correctly:
- --if not db.datapanel.enable then return end
- if db.datapanel.enable then -- How is this different than "enable" ? If the panel is not enabled, what's the point of doing anything else?
- self:CreatePanel() -- factor this giant blob out into its own function to keep things clean
- end
- if db.misc.classcolor then
- --local _, class = UnitClass("player")
- local color = RAID_CLASS_COLORS[select(2, UnitClass("player"))]
- hexa = RGBToHex(color.r, color.g, color.b) -- no need to format it yourself, it's already done
- else
- hexa = RGBToHex(db.datapanel.customcolor.r, db.datapanel.customcolor.g, db.datapanel.customcolor.b) -- no need to duplicate the code you already wrote into the function
- end
- -- Rather than hardcode all the possible plugins here just use a nice table that you can add/remove stuff to much more easily. Scroll to the bottom to see it.
- self.plugins = {}
- for name, constructor in pairs(self.pluginConstructors) do
- local position = db.datapanel[name]
- if position and position > 0 then
- local plugin = constructor()
- self.plugins[name] = plugin
- self:PlacePlugin(position, plugin)
- end
- end
- -- no need to make a separate frame to handle events, your module object already does this!
- self:UpdatePlayerRole()
- self:RegisterEvent("PLAYER_SPECIALIZATION_CHANGED", "UpdatePlayerRole")
- end
- function Module:UpdatePlayerRole()
- local spec = GetSpecialization()
- local specRole = GetSpecializationRole(spec) -- no need for a giant table that must be maintained by hand
- if specRole == "TANK" then
- playerRole = "Tank"
- elseif specRole == "HEALER" then
- playerRole = "Caster"
- elseif specRole == "DAMAGER" then
- if UnitPowerType("player") == SPELL_POWER_MANA then
- playerRole = "Caster"
- else
- playerRole = "Melee"
- end
- else
- playerRole = nil -- no spec
- end
- end
- function Module:SetFontString(parent, file, size, flags)
- local fs = parent:CreateFontString(nil, "OVERLAY")
- fs:SetFont(file, size, flags)
- fs:SetJustifyH("LEFT")
- fs:SetShadowColor(0, 0, 0)
- fs:SetShadowOffset(1.25, -1.25)
- return fs
- end
- function Module:PlacePlugin(position, plugin)
- local left = PanelLeft
- local center = PanelCenter
- local right = PanelRight
- -- Left Panel Data
- if position == 1 then
- plugin:SetParent(left)
- plugin:SetHeight(left:GetHeight())
- plugin:SetPoint('LEFT', left, 30, 0)
- plugin:SetPoint('TOP', left)
- plugin:SetPoint('BOTTOM', left)
- elseif position == 2 then
- plugin:SetParent(left)
- plugin:SetHeight(left:GetHeight())
- plugin:SetPoint('TOP', left)
- plugin:SetPoint('BOTTOM', left)
- elseif position == 3 then
- plugin:SetParent(left)
- plugin:SetHeight(left:GetHeight())
- plugin:SetPoint('RIGHT', left, -30, 0)
- plugin:SetPoint('TOP', left)
- plugin:SetPoint('BOTTOM', left)
- -- Center Panel Data
- elseif position == 4 then
- plugin:SetParent(center)
- plugin:SetHeight(center:GetHeight())
- plugin:SetPoint('LEFT', center, 30, 0)
- plugin:SetPoint('TOP', center)
- plugin:SetPoint('BOTTOM', center)
- elseif position == 5 then
- plugin:SetParent(center)
- plugin:SetHeight(center:GetHeight())
- plugin:SetPoint('TOP', center)
- plugin:SetPoint('BOTTOM', center)
- elseif position == 6 then
- plugin:SetParent(center)
- plugin:SetHeight(center:GetHeight())
- plugin:SetPoint('RIGHT', center, -30, 0)
- plugin:SetPoint('TOP', center)
- plugin:SetPoint('BOTTOM', center)
- -- Right Panel Data
- elseif position == 7 then
- plugin:SetParent(right)
- plugin:SetHeight(right:GetHeight())
- plugin:SetPoint('LEFT', right, 30, 0)
- plugin:SetPoint('TOP', right)
- plugin:SetPoint('BOTTOM', right)
- elseif position == 8 then
- plugin:SetParent(right)
- plugin:SetHeight(right:GetHeight())
- plugin:SetPoint('TOP', right)
- plugin:SetPoint('BOTTOM', right)
- elseif position == 9 then
- plugin:SetParent(right)
- plugin:SetHeight(right:GetHeight())
- plugin:SetPoint('RIGHT', right, -30, 0)
- plugin:SetPoint('TOP', right)
- plugin:SetPoint('BOTTOM', right)
- end
- end
- function Module:CreatePanel()
- local db = Core.db.profile
- if MainPanel then return end -- already done
- -- These are not "local" here because they're already "local" at the top of the file.
- MainPanel = CreateFrame("Frame", "BasicUI_Datapanel", UIParent)
- PanelLeft = CreateFrame("Frame", nil, MainPanel)
- PanelCenter = CreateFrame("Frame", nil, MainPanel)
- PanelRight = CreateFrame("Frame", nil, MainPanel)
- BGPanel = CreateFrame("Frame", nil, MainPanel)
- -- These are common to all panel styles, so don't duplicate code.
- MainPanel:SetHeight(35)
- MainPanel:SetFrameStrata("LOW")
- MainPanel:SetBackdrop({ bgFile = db.datapanel.background, edgeFile = db.datapanel.border, edgeSize = 25, insets = { left = 5, right = 5, top = 5, bottom = 5 } })
- MainPanel:SetBackdropColor(0, 0, 0, 1)
- -- Setup the Panels
- SetMainPanel()
- SetPanelLeft()
- SetPanelCenter()
- SetPanelRight()
- -- No Need for function it always sets it self on the PanelLeft
- BGPanel:SetAllPoints(PanelLeft)
- BGPanel:SetFrameStrata("LOW")
- BGPanel:SetFrameLevel(1)
- -- Move some Objects for the Datapanel
- MoveObjects()
- end
- ------------------------------------------------------------------------
- -- Panel creation
- -- This can be simplified hugely by using a table, instead of a bunch of if/end blocks.
- Module.pluginConstructors = {
- armor = function()
- local db = Core.db.profile
- local plugin = CreateFrame("Frame", "StatArmor", MainPanel) -- proper parentage
- plugin:EnableMouse(true)
- plugin:SetFrameLevel(3)
- plugin:SetFrameStrata("BACKGROUND")
- local Text = plugin:CreateFontString("StatArmorText", "OVERLAY") -- proper parentage
- Text:SetFont(db.media.fontNormal, db.media.fontSize, "THINOUTLINE")
- plugin.text = Text -- important!
- plugin:RegisterEvent("PLAYER_ENTERING_WORLD")
- plugin:RegisterUnitEvent("UNIT_AURA", "player") -- limit UNIT_* events to the player when possible
- plugin:RegisterUnitEvent("UNIT_INVENTORY_CHANGED", "player")
- plugin:SetScript("OnEvent", function()
- local _ , effectiveArmor = UnitArmor("player");
- plugin.text:SetFormattedText("%sArmor:|r %s", hexa, effectiveArmor)
- plugin:SetWidth(plugin.text:GetStringWidth()) -- important!
- end)
- plugin:SetScript("OnEnter", function(self)
- if UnitAffectingCombat("player") then return end
- local anchor, x, y = GetTooltipAnchor(self)
- GameTooltip:SetOwner(self, GameTooltip:SetOwner(self, anchor, x, y))
- GameTooltip:AddLine("Mitigation by Level:")
- GameTooltip:Show()
- end)
- plugin:SetScript("OnLeave", function() GameTooltip:Hide() end)
- plugin:SetScript("OnMouseDown", function(self, button)
- ToggleCharacter("PaperDollFrame")
- end)
- return plugin -- important!
- end,
- bags = function()
- local db = Core.db.profile
- local plugin = CreateFrame("Frame", nil, MainPanel) -- proper parentage
- plugin:EnableMouse(true)
- local Text = plugin:CreateFontString(nil, "OVERLAY") -- proper parentage
- Text:SetFont(db.media.fontNormal, db.media.fontSize,"THINOUTLINE")
- --plugin.text = Text -- important!
- local Profit = 0
- local Spent = 0
- local OldMoney = 0
- local myPlayerRealm = GetRealmName();
- local function formatMoney(c)
- local str = ""
- if not c or c < 0 then
- return str
- end
- if c >= 10000 then
- local g = math.floor(c/10000)
- c = c - g*10000
- str = str..BreakUpLargeNumbers(g).."|cFFFFD800g|r "
- end
- if c >= 100 then
- local s = math.floor(c/100)
- c = c - s*100
- str = str..s.."|cFFC7C7C7s|r "
- end
- if c >= 0 then
- str = str..c.."|cFFEEA55Fc|r"
- end
- return str
- end
- plugin:RegisterEvent("PLAYER_MONEY")
- plugin:RegisterEvent("PLAYER_ENTERING_WORLD")
- plugin:RegisterUnitEvent("SEND_MAIL_MONEY_CHANGED", "player") -- limit UNIT_* events to the player when possible
- plugin:RegisterUnitEvent("SEND_MAIL_COD_CHANGED", "player")
- plugin:RegisterUnitEvent("PLAYER_TRADE_MONEY", "player")
- plugin:RegisterUnitEvent("TRADE_MONEY_CHANGED", "player")
- plugin:SetScript("OnEvent", function(self)
- local totalSlots, freeSlots = 0, 0
- local itemLink, subtype, isBag
- for i = 0,NUM_BAG_SLOTS do
- isBag = true
- if i > 0 then
- itemLink = GetInventoryItemLink('player', ContainerIDToInventoryID(i))
- if itemLink then
- subtype = select(7, GetItemInfo(itemLink))
- if (subtype == 'Mining Bag') or (subtype == 'Gem Bag') or (subtype == 'Engineering Bag') or (subtype == 'Enchanting Bag') or (subtype == 'Herb Bag') or (subtype == 'Inscription Bag') or (subtype == 'Leatherworking Bag') or (subtype == 'Fishing Bag')then
- isBag = false
- end
- end
- end
- if isBag then
- totalSlots = totalSlots + GetContainerNumSlots(i)
- freeSlots = freeSlots + GetContainerNumFreeSlots(i)
- end
- Text:SetText(hexa.."Bags:|r"..freeSlots.."/"..totalSlots)
- plugin:SetWidth(Text:GetStringWidth()) -- important!
- --Text:SetText("Bags: ".. freeSlots.. '/' ..totalSlots)
- if freeSlots < 6 then
- Text:SetTextColor(1,0,0)
- elseif freeSlots < 10 then
- Text:SetTextColor(1,0,0)
- elseif freeSlots > 10 then
- Text:SetTextColor(1,1,1)
- end
- --self:SetAllPoints(Text)]]
- end
- if event == "PLAYER_ENTERING_WORLD" then
- OldMoney = GetMoney()
- end
- local NewMoney = GetMoney()
- local Change = NewMoney-OldMoney -- Positive if we gain money
- if OldMoney>NewMoney then -- Lost Money
- Spent = Spent - Change
- else -- Gained Money
- Profit = Profit + Change
- end
- --Text:SetText(formatMoney(NewMoney))
- local myPlayerName = UnitName("player")
- if not BasicDB then BasicDB = {} end
- if not BasicDB.gold then BasicDB.gold = {} end
- if not BasicDB.gold[myPlayerRealm] then BasicDB.gold[myPlayerRealm]={} end
- BasicDB.gold[myPlayerRealm][myPlayerName] = GetMoney()
- OldMoney = NewMoney
- end)
- plugin:SetScript("OnEnter", function(self)
- if UnitAffectingCombat("player") then return end
- local anchor, x, y = GetTooltipAnchor(self)
- GameTooltip:SetOwner(self, GameTooltip:SetOwner(self, anchor, x, y))
- GameTooltip:AddLine(hexa..PLAYER_NAME.."'s|r".." Gold")
- GameTooltip:AddLine' '
- GameTooltip:AddLine("This Session: ")
- GameTooltip:AddDoubleLine("Earned:", formatMoney(Profit), 1, 1, 1, 1, 1, 1)
- GameTooltip:AddDoubleLine("Spent:", formatMoney(Spent), 1, 1, 1, 1, 1, 1)
- if Profit < Spent then
- GameTooltip:AddDoubleLine("Deficit:", formatMoney(Profit-Spent), 1, 0, 0, 1, 1, 1)
- elseif (Profit-Spent)>0 then
- GameTooltip:AddDoubleLine("Profit:", formatMoney(Profit-Spent), 0, 1, 0, 1, 1, 1)
- end
- GameTooltip:AddDoubleLine("Total:", formatMoney(OldMoney), 1, 1, 1, 1, 1, 1)
- GameTooltip:AddLine' '
- local totalGold = 0
- GameTooltip:AddLine("Character's: ")
- local thisRealmList = BasicDB.gold[myPlayerRealm];
- for k,v in pairs(thisRealmList) do
- GameTooltip:AddDoubleLine(k, formatMoney(v), 1, 1, 1, 1, 1, 1)
- totalGold=totalGold+v;
- end
- GameTooltip:AddLine' '
- GameTooltip:AddLine("Server:")
- GameTooltip:AddDoubleLine("Total: ", formatMoney(totalGold), 1, 1, 1, 1, 1, 1)
- for i = 1, GetNumWatchedTokens() do
- local name, count, extraCurrencyType, icon, itemID = GetBackpackCurrencyInfo(i)
- if name and i == 1 then
- GameTooltip:AddLine(" ")
- GameTooltip:AddLine(CURRENCY..":")
- end
- local r, g, b = 1,1,1
- if itemID then r, g, b = GetItemQualityColor(select(3, GetItemInfo(itemID))) end
- if name and count then GameTooltip:AddDoubleLine(name, count, r, g, b, 1, 1, 1) end
- end
- GameTooltip:AddLine' '
- GameTooltip:AddLine("|cffeda55fClick|r to Open Bags")
- GameTooltip:Show()
- end)
- plugin:SetScript("OnLeave", function() GameTooltip:Hide() end)
- plugin:SetScript("OnMouseDown", function(self, button)
- if db.datapanel.bag ~= true then
- ToggleAllBags()
- else
- ToggleBag(0)
- end
- end)
- return plugin -- important!
- end,
- -- You can update the rest yourself if you want.
- -- Also, it would be more maintainable to put each plugin in its own file, and add them to this table from there, eg:
- --[[
- local Core = LibStub("AceAddon-3.0"):GetAddon("BasicUI")
- local Module = Core:GetModule("Datapanel")
- Module.pluginConstructors["armor"] = function()
- -- create and return the armor plugin
- end
- ]]
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement