-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSellAllGrey.lua
214 lines (186 loc) · 7.46 KB
/
SellAllGrey.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
--[[
SellAllGrey
Original Author: VirtualOx
Original Addon: https://github.com/virtualox/SellAllGrey
Licensed under GNU General Public Licence version 3.
]]
-- Localization table
local L = {
enUS = {
earned_message = "You earned %s from selling grey items."
},
frFR = {
earned_message = "Vous avez gagné %s en vendant des objets gris."
},
deDE = {
earned_message = "Du hast %s durch den Verkauf von grauen Gegenständen verdient."
},
itIT = {
earned_message = "Hai guadagnato %s dalla vendita di oggetti grigi."
},
koKR = {
earned_message = "회색 아이템을 판매하여 %s를 획득했습니다."
},
zhCN = {
earned_message = "你卖掉灰色物品获得了 %s."
},
zhTW = {
earned_message = "你賣掉灰色物品獲得了 %s."
},
ruRU = {
earned_message = "Вы заработали %s, продавая серые предметы."
},
esES = {
earned_message = "Has ganado %s vendiendo objetos grises."
},
esMX = {
earned_message = "Has ganado %s vendiendo objetos grises."
},
ptBR = {
earned_message = "Você ganhou %s vendendo itens cinza."
}
}
-- Function to get localized text
local function GetLocaleText(key)
local locale = GetLocale()
return L[locale] and L[locale][key] or L["enUS"][key]
end
-- Function to format the currency with icons
local function FormatCurrency(amount)
local gold = floor(amount / 10000)
local silver = floor((amount % 10000) / 100)
local copper = amount % 100
local goldText = gold > 0 and string.format("|cffffd700%d|r|TInterface\\MoneyFrame\\UI-GoldIcon:0:0:2:0|t", gold) or ""
local silverText = silver > 0 and string.format("|cffc7c7cf%d|r|TInterface\\MoneyFrame\\UI-SilverIcon:0:0:2:0|t", silver) or ""
local copperText = copper > 0 and string.format("|cffeda55f%d|r|TInterface\\MoneyFrame\\UI-CopperIcon:0:0:2:0|t", copper) or ""
return goldText .. " " .. silverText .. " " .. copperText
end
-- Function to sell all grey items and calculate total earnings
local function SellGreyItems()
local totalEarnings = 0 -- Variable to keep track of total earnings
for bag = 0, 4 do
for slot = 1, C_Container.GetContainerNumSlots(bag) do
local itemLink = C_Container.GetContainerItemLink(bag, slot)
if itemLink then
local _, _, itemRarity, _, _, _, _, _, _, _, itemSellPrice = GetItemInfo(itemLink)
local itemCount = C_Container.GetContainerItemInfo(bag, slot).stackCount
if itemRarity == 0 and itemSellPrice > 0 then
-- Calculate earnings from this item and add to total
local earnings = itemSellPrice * itemCount
totalEarnings = totalEarnings + earnings
-- Sell the item
C_Container.UseContainerItem(bag, slot)
end
end
end
end
-- If there were any earnings, print the total earnings to the chat
if totalEarnings > 0 then
local formattedEarnings = FormatCurrency(totalEarnings)
-- Output to the chat window with addon name in yellow and message in white
local addonNameColor = "|cffffff00" -- Yellow color for addon name
local messageColor = "|cffffffff" -- White color for the rest of the message
print(addonNameColor .. "SellAllGrey:|r " .. messageColor .. string.format(GetLocaleText("earned_message"), formattedEarnings) .. "|r")
end
end
-- Saved Variables Table
local SellAllGreyDB
-- Create Minimap Button
local function CreateMinimapButton()
local minimapButton = CreateFrame("Button", "SellAllGreyMinimapButton", Minimap)
minimapButton:SetFrameStrata("MEDIUM")
minimapButton:SetSize(31, 31)
minimapButton:SetFrameLevel(8)
minimapButton:RegisterForClicks("LeftButtonUp", "RightButtonUp")
local minimapButtonTexture = minimapButton:CreateTexture(nil, "BACKGROUND")
minimapButtonTexture:SetTexture("Interface\\Icons\\INV_Misc_Coin_01") -- Using coin icon
minimapButtonTexture:SetSize(20, 20)
minimapButtonTexture:SetPoint("CENTER")
minimapButton:SetHighlightTexture("Interface\\Minimap\\UI-Minimap-ZoomButton-Highlight")
-- Position the button around the minimap
local function UpdateMinimapButtonPosition(angle)
local radius = 80
local x = radius * cos(angle)
local y = radius * sin(angle)
minimapButton:SetPoint("CENTER", Minimap, "CENTER", x, y)
end
-- Update button position
UpdateMinimapButtonPosition(SellAllGreyDB.minimapButtonAngle)
-- Allow dragging the button
minimapButton:SetScript("OnDragStart", function(self)
self:LockHighlight()
self:SetScript("OnUpdate", function(self)
local mx, my = Minimap:GetCenter()
local px, py = GetCursorPosition()
local scale = UIParent:GetEffectiveScale()
px, py = px / scale, py / scale
SellAllGreyDB.minimapButtonAngle = math.atan2(py - my, px - mx)
UpdateMinimapButtonPosition(SellAllGreyDB.minimapButtonAngle)
end)
end)
minimapButton:SetScript("OnDragStop", function(self)
self:SetScript("OnUpdate", nil)
self:UnlockHighlight()
end)
minimapButton:SetScript("OnMouseUp", function(self, button)
if button == "LeftButton" then
-- Toggle the addon
SellAllGreyDB.enabled = not SellAllGreyDB.enabled
local status = SellAllGreyDB.enabled and "|cff00ff00enabled|r" or "|cffff0000disabled|r"
print("|cffffff00SellAllGrey:|r Addon is now " .. status .. ".")
end
end)
minimapButton:SetScript("OnEnter", function(self)
GameTooltip:SetOwner(self, "ANCHOR_LEFT")
GameTooltip:AddLine("SellAllGrey")
GameTooltip:AddLine("Left-click to enable/disable the addon.", 1, 1, 1)
GameTooltip:Show()
end)
minimapButton:SetScript("OnLeave", function(self)
GameTooltip:Hide()
end)
-- Enable dragging
minimapButton:SetMovable(true)
minimapButton:EnableMouse(true)
minimapButton:RegisterForDrag("LeftButton")
end
-- Function to initialize the addon
local function Initialize()
if not SellAllGreyDB then
SellAllGreyDB = {}
end
if SellAllGreyDB.enabled == nil then
SellAllGreyDB.enabled = true
end
if not SellAllGreyDB.minimapButtonAngle then
SellAllGreyDB.minimapButtonAngle = 0
end
-- Create the minimap button after initializing saved variables
CreateMinimapButton()
end
-- Slash Command Handler
SLASH_SELLALLGREY1 = '/sellallgrey'
SLASH_SELLALLGREY2 = '/sag'
local function SlashCmdHandler(msg)
if msg == 'toggle' then
SellAllGreyDB.enabled = not SellAllGreyDB.enabled
local status = SellAllGreyDB.enabled and "|cff00ff00enabled|r" or "|cffff0000disabled|r"
print("|cffffff00SellAllGrey:|r Addon is now " .. status .. ".")
else
print("|cffffff00SellAllGrey:|r Usage: /sellallgrey toggle")
end
end
SlashCmdList["SELLALLGREY"] = SlashCmdHandler
-- Event handler function
local function OnEvent(self, event, ...)
if event == "ADDON_LOADED" and ... == "SellAllGrey" then
Initialize()
elseif event == "MERCHANT_SHOW" and SellAllGreyDB.enabled then
SellGreyItems()
end
end
-- Create frame and register events
local frame = CreateFrame("Frame")
frame:RegisterEvent("ADDON_LOADED")
frame:RegisterEvent("MERCHANT_SHOW")
frame:SetScript("OnEvent", OnEvent)