-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRealLifeValue.lua
More file actions
363 lines (311 loc) · 12 KB
/
RealLifeValue.lua
File metadata and controls
363 lines (311 loc) · 12 KB
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
local addonName, addon = ...
-- Constants for WoW Token prices in real money
local CURRENCIES = {
gbp = { symbol = "£", tokenPrice = 17, name = "British Pound" },
eur = { symbol = "€", tokenPrice = 20, name = "Euro" },
usd = { symbol = "$", tokenPrice = 20, name = "US Dollar" }
}
-- Saved variables
RealLifeValueDB = RealLifeValueDB or {
currency = "gbp",
point = "CENTER",
relativePoint = "CENTER",
xOfs = 0,
yOfs = 0
}
-- State
local currentCurrency = "gbp"
-- Initialize the addon
local function Initialize()
C_WowTokenPublic.UpdateMarketPrice()
end
-- Helper function to convert gold to real money
local function ConvertGoldToRealMoney(goldAmount, currency)
local tokenPrice = C_WowTokenPublic.GetCurrentMarketPrice()
if not tokenPrice or tokenPrice == 0 then return nil end
-- tokenPrice is in copper, convert to gold
local tokenGoldPrice = tokenPrice / 10000
-- Calculate conversion rate (gold per currency unit)
local goldPerCurrency = tokenGoldPrice / CURRENCIES[currency].tokenPrice
-- Convert gold amount to currency
return goldAmount / goldPerCurrency
end
-- Helper functions
local function FormatCurrencyValue(value)
if not value or value < 0.01 then return "<0.01" end
return string.format("%.2f", value)
end
-- Tooltip modification
local function AddTooltipLine(tooltip, label, value, r, g, b)
if value then
tooltip:AddDoubleLine(label, value, r or 1, g or 1, b or 0, r or 1, g or 1, b or 0)
end
end
local function GetAuctionatorPrice(itemLink)
-- Check if Auctionator is loaded
if not C_AddOns.IsAddOnLoaded("Auctionator") then
return nil
end
-- Get the price using Auctionator's v1 API
if Auctionator and Auctionator.API and Auctionator.API.v1 then
local price = Auctionator.API.v1.GetAuctionPriceByItemLink("RealLifeValue", itemLink)
if price then
return price / 10000 -- Convert copper to gold
end
end
return nil
end
local function GetItemPrice(link)
-- Try to get Auctionator price first
local auctionPrice = GetAuctionatorPrice(link)
if auctionPrice then
return auctionPrice, "Price"
end
-- Then try UnderMine Journal
if C_AddOns.IsAddOnLoaded("TheUndermineJournal") and TUJMarketInfo then
local tujData = TUJMarketInfo(link)
if tujData and tujData['recent'] and tujData['recent'] > 0 then
return (tujData['recent'] / 10000), "Price"
end
end
-- Fall back to vendor price
local vendorPrice = select(11, GetItemInfo(link)) or 0
return (vendorPrice / 10000), "Vendor Price"
end
local function OnTooltipSetItem(tooltip)
local name, link = TooltipUtil.GetDisplayedItem(tooltip)
if not link then return end
local itemInfo = C_Item.GetItemInfo(link)
if not itemInfo then return end
local stackCount = select(8, GetItemInfo(link)) or 1
local goldPrice, priceSource = GetItemPrice(link)
if goldPrice and goldPrice > 0 then
local realPrice = ConvertGoldToRealMoney(goldPrice, currentCurrency)
if realPrice then
local info = CURRENCIES[currentCurrency]
AddTooltipLine(tooltip, info.symbol .. " " .. priceSource,
info.symbol .. FormatCurrencyValue(realPrice))
if stackCount > 1 then
AddTooltipLine(tooltip, info.symbol .. " Stack Price",
info.symbol .. FormatCurrencyValue(realPrice * stackCount))
end
end
end
end
-- Create the settings UI
local function CreateSettingsUI()
-- Create the main frame
local frame = CreateFrame("Frame", "RealLifeValueSettings", UIParent, "BackdropTemplate")
frame:SetSize(300, 200)
frame:SetFrameStrata("DIALOG")
-- Save position between sessions
frame:SetPoint(
RealLifeValueDB.point or "CENTER",
UIParent,
RealLifeValueDB.relativePoint or "CENTER",
RealLifeValueDB.xOfs or 0,
RealLifeValueDB.yOfs or 0
)
-- Use the correct API for retail/classic backdrops
if WOW_PROJECT_ID == WOW_PROJECT_MAINLINE then
frame:SetBackdrop({
bgFile = "Interface/Tooltips/UI-Tooltip-Background",
edgeFile = "Interface/Tooltips/UI-Tooltip-Border",
tile = true,
tileSize = 16,
edgeSize = 16,
insets = { left = 4, right = 4, top = 4, bottom = 4 }
})
else
-- Classic backdrop handling
frame.backdropInfo = {
bgFile = "Interface/Tooltips/UI-Tooltip-Background",
edgeFile = "Interface/Tooltips/UI-Tooltip-Border",
tile = true,
tileSize = 16,
edgeSize = 16,
insets = { left = 4, right = 4, top = 4, bottom = 4 }
}
frame:ApplyBackdrop()
end
frame:SetBackdropColor(0, 0, 0, 0.9)
frame:EnableMouse(true)
frame:SetMovable(true)
frame:RegisterForDrag("LeftButton")
-- Save position when dragged
frame:SetScript("OnDragStart", frame.StartMoving)
frame:SetScript("OnDragStop", function(self)
self:StopMovingOrSizing()
-- Save position
local point, _, relativePoint, xOfs, yOfs = self:GetPoint(1)
RealLifeValueDB.point = point
RealLifeValueDB.relativePoint = relativePoint
RealLifeValueDB.xOfs = xOfs
RealLifeValueDB.yOfs = yOfs
end)
-- Close button
local closeButton = CreateFrame("Button", nil, frame, "UIPanelCloseButton")
closeButton:SetPoint("TOPRIGHT", frame, "TOPRIGHT", 2, 2)
-- Add title with better styling
local titleBg = frame:CreateTexture(nil, "BACKGROUND")
titleBg:SetTexture("Interface/DialogFrame/UI-DialogBox-Header")
titleBg:SetTexCoord(0.31, 0.67, 0, 0.63)
titleBg:SetPoint("TOP", 0, 12)
titleBg:SetSize(150, 40)
local title = frame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
title:SetPoint("TOP", titleBg, "TOP", 0, -14)
title:SetText("RealLifeValue Settings")
-- Create radio buttons
local radioButtons = {}
local yOffset = -50
-- Status text for token price
local statusText = frame:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
statusText:SetPoint("TOPLEFT", 16, -30)
-- Update status text periodically
local function UpdateStatusText()
local tokenPrice = C_WowTokenPublic.GetCurrentMarketPrice()
if tokenPrice and tokenPrice > 0 then
if GetCoinTextureString then
statusText:SetText("Current Token Price: " .. GetCoinTextureString(tokenPrice))
else
-- Fallback if GetCoinTextureString isn't available
local gold = math.floor(tokenPrice / 10000)
statusText:SetText("Current Token Price: " .. gold .. "g")
end
statusText:SetTextColor(0, 1, 0)
else
statusText:SetText("Token Price: Updating...")
statusText:SetTextColor(1, 1, 0)
end
end
-- Create enhanced radio buttons
local function CreateRadioButton(currency, label)
local button = CreateFrame("CheckButton", nil, frame, "UIRadioButtonTemplate")
button:SetPoint("TOPLEFT", 20, yOffset)
button.currency = currency
-- Get the text object properly
local text = button.Text or button:GetFontString()
if not text then
text = button:CreateFontString(nil, "OVERLAY", "GameFontNormal")
text:SetPoint("LEFT", button, "RIGHT", 5, 0)
end
text:SetText(label)
button:SetScript("OnClick", function(self)
-- Just uncheck other buttons, no color changes
for _, otherButton in pairs(radioButtons) do
if otherButton ~= self then
otherButton:SetChecked(false)
end
end
end)
return button
end
-- Create radio button for each currency
for currency, info in pairs(CURRENCIES) do
radioButtons[currency] = CreateRadioButton(currency, info.symbol .. " - " .. info.name)
yOffset = yOffset - 25
end
-- Save button with enhanced styling
local saveButton = CreateFrame("Button", nil, frame, "UIPanelButtonTemplate")
saveButton:SetSize(100, 22)
saveButton:SetPoint("BOTTOMRIGHT", -16, 16)
saveButton:SetText("Save")
-- Cancel button
local cancelButton = CreateFrame("Button", nil, frame, "UIPanelButtonTemplate")
cancelButton:SetSize(100, 22)
cancelButton:SetPoint("BOTTOMLEFT", 16, 16)
cancelButton:SetText("Cancel")
cancelButton:SetScript("OnClick", function()
frame:Hide()
end)
saveButton:SetScript("OnClick", function()
local selectedCurrency = nil
for currency, button in pairs(radioButtons) do
if button:GetChecked() then
selectedCurrency = currency
break
end
end
if selectedCurrency then
-- Save settings
RealLifeValueDB.currency = selectedCurrency
currentCurrency = selectedCurrency
print("|cFF00FF00RealLifeValue:|r Currency set to " .. CURRENCIES[selectedCurrency].name)
frame:Hide()
else
print("|cFFFF0000RealLifeValue:|r Please select a currency")
end
end)
-- Function to update UI state based on saved settings
frame.UpdateState = function()
-- Check the currently selected currency
for currency, button in pairs(radioButtons) do
local isSelected = currency == RealLifeValueDB.currency
button:SetChecked(isSelected)
end
UpdateStatusText()
end
-- Update token price status periodically
if C_Timer then
C_Timer.NewTicker(5, UpdateStatusText)
end
-- Add a help text
local helpText = frame:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
helpText:SetPoint("BOTTOM", 0, 45)
helpText:SetText("Use /myrlvalue to check your character's worth")
helpText:SetTextColor(1, 0.82, 0)
frame:Hide()
return frame
end
-- Initialize settings frame
RealLifeValueSettings = CreateSettingsUI()
-- Enhanced slash commands with better feedback
SLASH_RLVALUE1 = '/rlvalue'
SlashCmdList['RLVALUE'] = function(msg)
if RealLifeValueSettings then
if RealLifeValueSettings:IsShown() then
RealLifeValueSettings:Hide()
else
RealLifeValueSettings:Show()
RealLifeValueSettings.UpdateState()
end
else
print("|cFFFF0000RealLifeValue:|r Error loading settings UI. Try reloading UI (/reload).")
end
end
SLASH_MYRLVALUE1 = '/myrlvalue'
SlashCmdList['MYRLVALUE'] = function()
local playerGold = GetMoney() / 10000 -- Convert copper to gold
local realPrice = ConvertGoldToRealMoney(playerGold, currentCurrency)
if realPrice then
local info = CURRENCIES[currentCurrency]
print("|cFF00FF00RealLifeValue:|r Your current gold is worth " .. info.symbol .. FormatCurrencyValue(realPrice))
else
print("|cFFFF0000RealLifeValue:|r Could not get current token price. Please try again later.")
end
end
-- Event handling and initialization
local frame = CreateFrame("Frame")
frame:RegisterEvent("PLAYER_LOGIN")
frame:SetScript("OnEvent", function(self, event)
if event == "PLAYER_LOGIN" then
Initialize()
-- Load saved settings
currentCurrency = RealLifeValueDB.currency or "gbp"
-- Register tooltip hooks based on WoW version
if TooltipDataProcessor and TooltipDataProcessor.AddTooltipPostCall then
TooltipDataProcessor.AddTooltipPostCall(Enum.TooltipDataType.Item, OnTooltipSetItem)
else
-- Classic tooltip hook
GameTooltip:HookScript("OnTooltipSetItem", OnTooltipSetItem)
end
-- Print loaded message
print("|cFF00FF00RealLifeValue loaded.|r Type /rlvalue for settings.")
end
end)
-- Update token price periodically
if C_Timer then
C_Timer.NewTicker(300, function()
C_WowTokenPublic.UpdateMarketPrice()
end)
end