Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local frame = CreateFrame("Frame", "PlayerGoldFrame", UIParent)
- frame:SetPoint("CENTER", UIParent, "CENTER", 0, 0)
- frame:SetSize(250, 75)
- frame:EnableMouse(true)
- frame:SetMovable(true)
- frame:RegisterForDrag("LeftButton")
- frame:Show()
- frame.bgTexture = frame:CreateTexture(nil, "BACKGROUND")
- frame.bgTexture:SetAllPoints(frame)
- frame.bgTexture:SetColorTexture(0, 0, 0, 0.5)
- local totalGoldLabel = frame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
- totalGoldLabel:SetPoint("TOP", frame, "TOP", 0, -10)
- totalGoldLabel:SetText("Total Gold:")
- local goldGainedLabel = frame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
- goldGainedLabel:SetPoint("CENTER", frame, "CENTER", 0, 0)
- goldGainedLabel:SetText("Gold Gained:")
- local goldSpentLabel = frame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
- goldSpentLabel:SetPoint("BOTTOM", frame, "BOTTOM", 0, 10)
- goldSpentLabel:SetText("Gold Spent:")
- local prevGold = GetMoney()
- local addonName = "PlayerGoldAddon"
- local addonData = {}
- local function UpdateGold()
- local playerGold = GetMoney()
- local goldDiff = playerGold - prevGold
- totalGoldLabel:SetText("Total Gold: " .. GetCoinTextureString(playerGold))
- if goldDiff > 0 then
- addonData.goldGained = (addonData.goldGained or 0) + goldDiff
- goldGainedLabel:SetText("Gold Gained: " .. GetCoinTextureString(addonData.goldGained))
- goldSpentLabel:SetText("Gold Spent: " .. GetCoinTextureString(addonData.goldSpent or 0))
- elseif goldDiff < 0 then
- addonData.goldSpent = (addonData.goldSpent or 0) - goldDiff
- goldGainedLabel:SetText("Gold Gained: " .. GetCoinTextureString(addonData.goldGained or 0))
- goldSpentLabel:SetText("Gold Spent: " .. GetCoinTextureString(addonData.goldSpent))
- else
- goldGainedLabel:SetText("Gold Gained: " .. GetCoinTextureString(addonData.goldGained or 0))
- goldSpentLabel:SetText("Gold Spent: " .. GetCoinTextureString(addonData.goldSpent))
- end
- prevGold = playerGold
- end
- local function UpdateAddonData()
- if not addonData.goldGained then
- addonData.goldGained = 0
- end
- if not addonData.goldSpent then
- addonData.goldSpent = 0
- end
- end
- frame:RegisterEvent("PLAYER_MONEY")
- frame:SetScript("OnEvent", function()
- UpdateGold()
- UpdateAddonData()
- end)
- UpdateGold()
- UpdateAddonData()
- frame:SetScript("OnDragStart", function(self)
- self:StartMoving()
- end)
- frame:SetScript("OnDragStop", function(self)
- self:StopMovingOrSizing()
- end)
- SLASH_PLAYERGOLD1 = "/playergold"
- SlashCmdList["PLAYERGOLD"] = function()
- frame:SetShown(not frame:IsShown())
- end
- local addonFrame = CreateFrame("Frame")
- addonFrame:RegisterEvent("PLAYER_LOGOUT")
- addonFrame:SetScript("OnEvent", function()
- SaveVariables(addonName, addonData)
- end)
Add Comment
Please, Sign In to add comment