WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   AddOn Search/Requests (https://www.wowinterface.com/forums/forumdisplay.php?f=6)
-   -   Copy gold to clipboard (https://www.wowinterface.com/forums/showthread.php?t=59138)

Believe82 05-27-22 03:53 PM

Copy gold to clipboard
 
I wonder if there is something that could do this. I have one addon that actually has an export frame and shows me text from the gold in that raid, that I can than highlight and copy. I wonder if I can get something similar.
If not a direct copy of my gold value, a frame were I can automatically highlight the gold I have and copy to clipboard.

Many thanks.

Fizzlemizz 05-27-22 04:04 PM

You can't "programatically" send text to the clipboard. You need the frame to display the text that you then select and CTRL-C to get it onto the clipboard.

You can create a frame with an EditBox and automaticaly set it to select some text (EditBox:HighlightText(start, end)) so you just need to CTRL-C to copy to the clipboard.

Edit: I missed the bit where you were asking for a popup frame if that was the only way.

You can paste the following into the website addon.bool.no and give it a unique title (GetGold?) to create/download a small addon to do this. /gg will show/hide the frame with your current gold/silver/copper (the button will toggle current character/all characters) ready to copy (CTRL-C).Pasting the text into an editor will paste the numbers but not the icons.
Quote:

Notes
Using a text editor (eg. NotPad):
The following line will need to be added (after the other lines starting with ##) to the addons .TOC file located in the addons folder (THE ADDON WILL NOT WORK PROPERLY WITHOUT THIS):
## SavedVariables: GG_DATA

Will only show total gold for characters you have logged on to.
Will show gold for deleted character unless you edit the addons SavedVariables file and delete the characters information:
File Location:
[WoW folder]\[game version folder eg. _retail_]\WFT\Account\[your account name]\SavedVariables\[addon name].lua

Lua Code:
  1. local f = CreateFrame("Frame", "GetGoldDisplayFrame", UIParent, BackdropTemplateMixin and "BackdropTemplate")
  2. f:SetPoint("CENTER")
  3. f:SetMovable(true)
  4. f:SetUserPlaced(true)
  5.  
  6. local CTData, CTName
  7.  
  8. f:RegisterEvent("PLAYER_LOGIN")
  9. f:RegisterEvent("PLAYER_MONEY")
  10. f:SetScript("OnEvent", function(self, event)
  11.     if event == "PLAYER_MONEY" then
  12.         CTData.gold = GetMoney()
  13.         return
  14.     end
  15.     GG_DATA = GG_DATA or { characters={} }
  16.     CTName = UnitName("player")
  17.     CTData = CTName .. "-" .. GetNormalizedRealmName()
  18.     if not GG_DATA.characters[CTData] then
  19.         GG_DATA.characters[CTData] = { }
  20.     end
  21.     CTData = GG_DATA.characters[CTData]
  22.     CTData.gold = GetMoney()
  23. end)
  24.  
  25. local TotalText = "Total Gold is:"
  26. local PlayerText = "Gold for %s:"
  27.  
  28. local function ShowGold(self, playergold)
  29.     local Total = 0
  30.     if not playergold then
  31.         self.Title:SetText(TotalText)
  32.         self.GetFor:SetText(CTName)
  33.         for k, v in pairs(GG_DATA.characters) do
  34.             Total = Total + v.gold
  35.         end
  36.     else
  37.         self.Title:SetText(format(PlayerText, CTName))
  38.         Total = CTData.gold
  39.         self.GetFor:SetText("All")
  40.     end
  41.     self.Text:SetText(GetMoneyString(Total, true))
  42.     self.Text:HighlightText()
  43.     self.Text:SetFocus()
  44.     self:Show()
  45. end
  46.  
  47. local function GetGold(msg)
  48.     if f.Title then
  49.         if f:IsShown() then
  50.             f:Hide()
  51.             return
  52.         end
  53.         ShowGold(f)
  54.         return
  55.     end
  56.     local backdrop = {
  57.         bgFile = "Interface/DialogFrame/UI-DialogBox-Background",
  58.         edgeFile = "Interface/GLUES/Common/Glue-Tooltip-Border",
  59.         tile = true,
  60.         edgeSize = 8,
  61.         tileSize = 8,
  62.         insets = {
  63.         left = 2,
  64.         right = 2,
  65.         top = 2,
  66.         bottom = 2,
  67.         },
  68.     }
  69.     f:EnableMouse(true)
  70.     f:RegisterForDrag("LeftButton")
  71.     f:SetClampedToScreen(true)
  72.     f:SetScript("OnDragStart", function(self) self:StartMoving() end)
  73.     f:SetScript("OnDragStop", function(self) self:StopMovingOrSizing() end)
  74.     f:SetBackdrop(backdrop)
  75.     f:SetSize(220, 100)
  76.     f.Title = f:CreateFontString()
  77.     f.Title:SetFontObject(GameFontNormal)
  78.     f.Title:SetPoint("TOP", 0, -5)
  79.     f.Title:SetText("Total Gold is:")
  80.     f.Close = CreateFrame("Button", "$parentClose", f, "UIPanelCloseButton")
  81.     f.Close:SetSize(24, 24)
  82.     f.Close:SetPoint("TOPRIGHT")
  83.     f.Text = CreateFrame("EditBox", nil, f)
  84.     f.Text:SetFontObject(GameFontNormal)
  85.     f.Text:SetSize(190, 24)
  86.     f.Text:SetJustifyH("CENTER")
  87.     f.Text:SetPoint("CENTER", 0, 10)
  88.     f.Text:SetMultiLine(false)
  89.     f.Text:SetScript("OnEscapePressed", function(self)
  90.         self:ClearFocus()
  91.         self:GetParent():Hide()
  92.     end)
  93.     f.GetFor = CreateFrame("Button", "$parentGetFor", f, "UIPanelButtonTemplate")
  94.     f.GetFor:SetSize(100, 30)
  95.     f.GetFor:SetText("All")
  96.     f.GetFor:SetPoint("BOTTOM", 0, 10)
  97.     f.GetFor:SetScript("OnClick", function(self)
  98.         self.Player = not self.Player
  99.         ShowGold(f, self.Player)
  100.     end)
  101.     ShowGold(f)
  102. end
  103.  
  104. SLASH_GG1 = "/gg"
  105. SlashCmdList.GG = GetGold
  106.  
  107. --[[    Notes
  108. -- Using a text editor (eg. NotPad):
  109. -- The following line will need to be added (after the other lines starting with ##) to the addons .TOC file located in the addons folder (THE ADDON WILL NOT WORK PROPERLY WITHOUT THIS):
  110. ## SavedVariables: GG_DATA
  111.  
  112. -- Will only show total gold for characters you have logged on to.
  113. -- Will show gold for deleted character unless you edit the addons SavedVariables file and delete the characters information:
  114. -- File Location:
  115. [WoW folder]\[game version folder eg. _retail_]\WFT\Account\[your account name]\SavedVariables\[addon name].lua
  116. ]]--

Believe82 05-30-22 06:19 PM

Ty, this is perfect and exactly what I was looking for.

Small addtion if possible please, this is showing the gold of only the current char.

Would it be possible to show the gold of all the chars in my account added up?

Fizzlemizz 05-31-22 12:21 PM

You can't get this information for other characters, just the one currently logged on.

It requires a bunch of code to save data as each character logs on/off or has their bank balance updated. It would be something I would think an alt. oriented addon might provide.

Believe82 05-31-22 03:37 PM

Is it possible for me to access an other addons data?

Elvui saves and shows the gold for all my chars I wonder if it would be possible to fetch that data.

This is how they show:


Is it possible to fetch their data to the frame? (I didn't link their gold.lua cause I didn't know if it would be breaking any coders rule of not sharing other peoples addons code here)

Fizzlemizz 06-01-22 08:19 PM

You could probably get the information from the Elvui SavedVariables but I've never used the addon and have no idea how it's data is structured.

It's global information and using it to display information in your addon wouldn't be a problem.

Believe82 06-02-22 10:50 PM

This is Elvui Gold.lua
Does it help?

Code:

local E, L, V, P, G = unpack(ElvUI)
local DT = E:GetModule('DataTexts')
local B = E:GetModule('Bags')

local _G = _G
local type, wipe, pairs, ipairs, sort = type, wipe, pairs, ipairs, sort
local format, strjoin, tinsert = format, strjoin, tinsert

local GetMoney = GetMoney
local IsControlKeyDown = IsControlKeyDown
local IsLoggedIn = IsLoggedIn
local IsShiftKeyDown = IsShiftKeyDown
local C_WowTokenPublic_UpdateMarketPrice = C_WowTokenPublic.UpdateMarketPrice
local C_WowTokenPublic_GetCurrentMarketPrice = C_WowTokenPublic.GetCurrentMarketPrice
local C_Timer_NewTicker = C_Timer.NewTicker
local BreakUpLargeNumbers = BreakUpLargeNumbers
-- GLOBALS: ElvDB

local Profit, Spent, Ticker = 0, 0
local resetCountersFormatter = strjoin('', '|cffaaaaaa', L["Reset Session Data: Hold Ctrl + Right Click"], '|r')
local resetInfoFormatter = strjoin('', '|cffaaaaaa', L["Reset Character Data: Hold Shift + Right Click"], '|r')

local CURRENCY = CURRENCY
local PRIEST_COLOR = RAID_CLASS_COLORS.PRIEST
local C_CurrencyInfo_GetBackpackCurrencyInfo = C_CurrencyInfo.GetBackpackCurrencyInfo

local iconString = '|T%s:16:16:0:0:64:64:4:60:4:60|t'

local menuList = {}

local function sortFunction(a, b)
        return a.amount > b.amount
end

local function OnEvent(self)
        if not IsLoggedIn() then return end

        if E.Retail and not Ticker then
                C_WowTokenPublic_UpdateMarketPrice()
                Ticker = C_Timer_NewTicker(60, C_WowTokenPublic_UpdateMarketPrice)
        end

        ElvDB = ElvDB or {}

        ElvDB.gold = ElvDB.gold or {}
        ElvDB.gold[E.myrealm] = ElvDB.gold[E.myrealm] or {}

        ElvDB.class = ElvDB.class or {}
        ElvDB.class[E.myrealm] = ElvDB.class[E.myrealm] or {}
        ElvDB.class[E.myrealm][E.myname] = E.myclass

        ElvDB.faction = ElvDB.faction or {}
        ElvDB.faction[E.myrealm] = ElvDB.faction[E.myrealm] or {}
        ElvDB.faction[E.myrealm][E.myname] = E.myfaction

        ElvDB.serverID = ElvDB.serverID or {}
        ElvDB.serverID[E.serverID] = ElvDB.serverID[E.serverID] or {}
        ElvDB.serverID[E.serverID][E.myrealm] = true

        --prevent an error possibly from really old profiles
        local oldMoney = ElvDB.gold[E.myrealm][E.myname]
        if oldMoney and type(oldMoney) ~= 'number' then
                ElvDB.gold[E.myrealm][E.myname] = nil
                oldMoney = nil
        end

        local NewMoney = GetMoney()
        ElvDB.gold[E.myrealm][E.myname] = NewMoney

        local OldMoney = oldMoney or NewMoney
        local Change = NewMoney-OldMoney -- Positive if we gain money
        if OldMoney>NewMoney then                -- Lost Money
                Spent = Spent - Change
        else                                                        -- Gained Moeny
                Profit = Profit + Change
        end

        self.text:SetText(E:FormatMoney(NewMoney, E.global.datatexts.settings.Gold.goldFormat or "BLIZZARD", not E.global.datatexts.settings.Gold.goldCoins))
end

local function deleteCharacter(self, realm, name)
        ElvDB.gold[realm][name] = nil
        ElvDB.class[realm][name] = nil
        ElvDB.faction[realm][name] = nil

        if name == E.myname and realm == E.myrealm then
                OnEvent(self)
        end
end

local function Click(self, btn)
        if btn == 'RightButton' then
                if IsShiftKeyDown() then
                        wipe(menuList)
                        tinsert(menuList, { text = 'Delete Character', isTitle = true, notCheckable = true })

                        for realm in pairs(ElvDB.serverID[E.serverID]) do
                                for name in pairs(ElvDB.gold[realm]) do
                                        tinsert(menuList, {
                                                text = format('%s - %s', name, realm),
                                                notCheckable = true,
                                                func = function()
                                                        deleteCharacter(self, realm, name)
                                                end
                                        })
                                end
                        end

                        DT:SetEasyMenuAnchor(DT.EasyMenu, self)
                        _G.EasyMenu(menuList, DT.EasyMenu, nil, nil, nil, 'MENU')
                elseif IsControlKeyDown() then
                        Profit = 0
                        Spent = 0
                end
        else
                _G.ToggleAllBags()
        end
end

local myGold = {}
local function OnEnter()
        DT.tooltip:ClearLines()

        local textOnly = not E.global.datatexts.settings.Gold.goldCoins and true or false
        local style = E.global.datatexts.settings.Gold.goldFormat or 'BLIZZARD'

        DT.tooltip:AddLine(L["Session:"])
        DT.tooltip:AddDoubleLine(L["Earned:"], E:FormatMoney(Profit, style, textOnly), 1, 1, 1, 1, 1, 1)
        DT.tooltip:AddDoubleLine(L["Spent:"], E:FormatMoney(Spent, style, textOnly), 1, 1, 1, 1, 1, 1)
        if Profit < Spent then
                DT.tooltip:AddDoubleLine(L["Deficit:"], E:FormatMoney(Profit-Spent, style, textOnly), 1, 0, 0, 1, 1, 1)
        elseif (Profit-Spent)>0 then
                DT.tooltip:AddDoubleLine(L["Profit:"], E:FormatMoney(Profit-Spent, style, textOnly), 0, 1, 0, 1, 1, 1)
        end
        DT.tooltip:AddLine(' ')

        local totalGold, totalHorde, totalAlliance = 0, 0, 0
        DT.tooltip:AddLine(L["Character: "])

        wipe(myGold)
        for realm in pairs(ElvDB.serverID[E.serverID]) do
                for k, _ in pairs(ElvDB.gold[realm]) do
                        if ElvDB.gold[realm][k] then
                                local color = E:ClassColor(ElvDB.class[realm][k]) or PRIEST_COLOR
                                tinsert(myGold,
                                        {
                                                name = k,
                                                realm = realm,
                                                amount = ElvDB.gold[realm][k],
                                                amountText = E:FormatMoney(ElvDB.gold[realm][k], style, textOnly),
                                                faction = ElvDB.faction[realm][k] or '',
                                                r = color.r, g = color.g, b = color.b,
                                        }
                                )
                        end

                        if ElvDB.faction[realm][k] == 'Alliance' then
                                totalAlliance = totalAlliance+ElvDB.gold[realm][k]
                        elseif ElvDB.faction[realm][k] == 'Horde' then
                                totalHorde = totalHorde+ElvDB.gold[realm][k]
                        end

                        totalGold = totalGold+ElvDB.gold[realm][k]
                end
        end

        sort(myGold, sortFunction)

        for _, g in ipairs(myGold) do
                local nameLine = ''
                if g.faction ~= '' and g.faction ~= 'Neutral' then
                        nameLine = format([[|TInterface\FriendsFrame\PlusManz-%s:14|t ]], g.faction)
                end

                local toonName = format('%s%s%s', nameLine, g.name, (g.realm and g.realm ~= E.myrealm and ' - '..g.realm) or '')
                DT.tooltip:AddDoubleLine((g.name == E.myname and toonName..[[ |TInterface\COMMON\Indicator-Green:14|t]]) or toonName, g.amountText, g.r, g.g, g.b, 1, 1, 1)
        end

        DT.tooltip:AddLine(' ')
        DT.tooltip:AddLine(L["Server: "])
        if totalAlliance > 0 and totalHorde > 0 then
                if totalAlliance ~= 0 then DT.tooltip:AddDoubleLine(L["Alliance: "], E:FormatMoney(totalAlliance, style, textOnly), 0, .376, 1, 1, 1, 1) end
                if totalHorde ~= 0 then DT.tooltip:AddDoubleLine(L["Horde: "], E:FormatMoney(totalHorde, style, textOnly), 1, .2, .2, 1, 1, 1) end
                DT.tooltip:AddLine(' ')
        end
        DT.tooltip:AddDoubleLine(L["Total: "], E:FormatMoney(totalGold, style, textOnly), 1, 1, 1, 1, 1, 1)

        if E.Retail then
                DT.tooltip:AddLine(' ')
                DT.tooltip:AddDoubleLine(L["WoW Token:"], E:FormatMoney(C_WowTokenPublic_GetCurrentMarketPrice() or 0, style, textOnly), 0, .8, 1, 1, 1, 1)
        end

        if E.Retail then
                for i = 1, _G.MAX_WATCHED_TOKENS do
                        local info = C_CurrencyInfo_GetBackpackCurrencyInfo(i)
                        if info then
                                if i == 1 then
                                        DT.tooltip:AddLine(' ')
                                        DT.tooltip:AddLine(CURRENCY)
                                end
                                if info.quantity then
                                        DT.tooltip:AddDoubleLine(format('%s %s', format(iconString, info.iconFileID), info.name), BreakUpLargeNumbers(info.quantity), 1, 1, 1, 1, 1, 1)
                                end
                        end
                end
        end

        local grayValue = B:GetGraysValue()
        if grayValue > 0 then
                DT.tooltip:AddLine(' ')
                DT.tooltip:AddDoubleLine(L["Grays"], E:FormatMoney(grayValue, style, textOnly), nil, nil, nil, 1, 1, 1)
        end

        DT.tooltip:AddLine(' ')
        DT.tooltip:AddLine(resetCountersFormatter)
        DT.tooltip:AddLine(resetInfoFormatter)
        DT.tooltip:Show()
end

DT:RegisterDatatext('Gold', nil, {'PLAYER_MONEY', 'SEND_MAIL_MONEY_CHANGED', 'SEND_MAIL_COD_CHANGED', 'PLAYER_TRADE_MONEY', 'TRADE_MONEY_CHANGED'}, OnEvent, nil, Click, OnEnter, nil, L["Gold"])


Fizzlemizz 06-03-22 11:06 AM

Not really because way too lazy.

I've updated the code in my OP to add totals for characters. In order to get it to work properly you will need to follow the Notes after copy/pasting/downloading/installing the new version of the addon.

A copy of the notes is also at the end of the code.

Believe82 06-03-22 12:11 PM

Ty! this works perfectly.
It is exactly what I needed and wanted.
Love the nice button touch of changing between all and single char.


All times are GMT -6. The time now is 04:21 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI