Advertisement
DreadfulSanity

Broker_Currencyflow.lua - Storm Sigils, Trader's Tender, crossfaction per realm

Feb 2nd, 2023 (edited)
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 63.38 KB | None | 0 0
  1. --[[ *******************************************************************
  2. Project : Broker_Currencyflow
  3. Author : Aledara (wowi AT jocosoft DOT com), masi (mfourtytwoi@gmail.com)
  4. ********************************************************************* ]]
  5.  
  6. local MODNAME = "Currencyflow"
  7. local FULLNAME = "Broker: "..MODNAME
  8.  
  9. local Currencyflow = LibStub( "AceAddon-3.0" ):NewAddon( MODNAME, "AceEvent-3.0" )
  10. local QT = LibStub:GetLibrary( "LibQTip-1.0" )
  11. local L = LibStub:GetLibrary( "AceLocale-3.0" ):GetLocale( MODNAME )
  12. local Config = LibStub( "AceConfig-3.0" )
  13. local ConfigReg = LibStub( "AceConfigRegistry-3.0" )
  14. local ConfigDlg = LibStub( "AceConfigDialog-3.0" )
  15.  
  16. _G["Currencyflow"] = Currencyflow
  17.  
  18. local tooltip
  19. local RAID_CLASS_COLORS = CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS
  20. local ICON_QM = "Interface\\Icons\\INV_Misc_QuestionMark"
  21.  
  22. local fmt_yellow = "|cffffff00%s|r"
  23. local fmt_white = "|cffffffff%s|r"
  24. local COLOR_MAXREACHED = "ff8800"
  25. local HISTORY_DAYS = 30
  26.  
  27. local TYPE_MONEY = 1
  28. local TYPE_CURRENCY = 2
  29. local TYPE_FRAGMENT = 3
  30. local TYPE_ITEM = 4
  31.  
  32. local charToDelete = nil
  33.  
  34. -- These are the currencies we can keep track of
  35. local currencies = {
  36. ["current"] = {
  37. -- Dragonflight
  38. ["pve"] = {
  39. [2003] = {["type"] = TYPE_CURRENCY, ["name"] = L["DRAGON_ISLES_SUPPLIES"]}, -- Dragonflight Dragon Isles Supplies
  40. [2118] = {["type"] = TYPE_CURRENCY, ["name"] = L["ELEMENTAL_OVERFLOW"]}, -- Dragonflight Elemental Overflow
  41. [2122] = {["type"] = TYPE_CURRENCY, ["name"] = L["STORM_SIGIL"]}, -- Dragonflight Storm Sigil
  42. [2032] = {["type"] = TYPE_CURRENCY, ["name"] = L["TADERS_TENDERS"]}, -- Dragonflight Trader's Tenders
  43. },
  44. ["pvp"] = {
  45. [1602] = {["type"] = TYPE_CURRENCY, ["name"] = L["CONQUEST"]}, -- Dragonflight Conquest
  46. [1792] = {["type"] = TYPE_CURRENCY, ["name"] = L["Honor"]}, -- Dragonflight Honor
  47. }
  48. },
  49. ["legacy"] = {
  50. ["pve"] = {
  51. -- Shadowlands
  52. [1191] = {["type"] = TYPE_CURRENCY, ["name"] = L["NAME_VALOR"]}, -- Shadowlands Valor
  53. [1728] = {["type"] = TYPE_CURRENCY, ["name"] = L["NAME_PHANTASMA"]}, -- Shadowlands Phantasma
  54. [1767] = {["type"] = TYPE_CURRENCY, ["name"] = L["NAME_STYGIA"]}, -- Shadowlands Stygia
  55. [1810] = {["type"] = TYPE_CURRENCY, ["name"] = L["NAME_WILLING_SOUL"]}, -- Shadowlands Willing Soul
  56. [1813] = {["type"] = TYPE_CURRENCY, ["name"] = L["NAME_RESERVOIR_ANIMA"]}, -- Shadowlands Reservoir Anima
  57. [1816] = {["type"] = TYPE_CURRENCY, ["name"] = L["NAME_SINSTONE_FRAGMENTS"]}, -- Shadowlands Sinstone Fragments
  58. [1819] = {["type"] = TYPE_CURRENCY, ["name"] = L["NAME_MEDALLION_OF_SERVICE"]}, -- Shadowlands Medallion of Service
  59. [1820] = {["type"] = TYPE_CURRENCY, ["name"] = L["NAME_INFUSED_RUBY"]}, -- Shadowlands Infused Ruby
  60. [1822] = {["type"] = TYPE_CURRENCY, ["name"] = L["NAME_RENOWN"]}, -- Shadowlands Renown
  61. [1828] = {["type"] = TYPE_CURRENCY, ["name"] = L["NAME_SOUL_ASH"]}, -- Shadowlands Soul Ash
  62. [1885] = {["type"] = TYPE_CURRENCY, ["name"] = L["NAME_GRATEFUL_OFFERING"]}, -- Shadowlands Grateful Offering
  63. [1904] = {["type"] = TYPE_CURRENCY, ["name"] = L["NAME_TOWER_KNOWLEDGE"]}, -- Shadowlands Tower Knowledge
  64. [1906] = {["type"] = TYPE_CURRENCY, ["name"] = L["NAME_SOUL_CINDERS"]}, -- Shadowlands Soul Cinders
  65. [1931] = {["type"] = TYPE_CURRENCY, ["name"] = L["NAME_CATALOGED_RESEARCH"]}, -- Shadowlands Cataloged Research
  66. [1977] = {["type"] = TYPE_CURRENCY, ["name"] = L["NAME_STYGIAN_EMBER"]}, -- Shadowlands Stygian Ember
  67. [2009] = {["type"] = TYPE_CURRENCY, ["name"] = L["COSMIC_FLUX"]}, -- Shadowlands Cosmic Flux
  68. [1979] = {["type"] = TYPE_CURRENCY, ["name"] = L["CYPHERS_OF_THE_FIRST_ONES"]}, -- Shadowlands Cyphers of the First Ones
  69. -- BfA
  70. [1560] = {["type"] = TYPE_CURRENCY, ["name"] = L["NAME_WAR_RESOURCES"]}, -- BfA War Resources
  71. [1580] = {["type"] = TYPE_CURRENCY, ["name"] = L["NAME_SEAL_OF_WARTORN_FATE"]}, -- BfA Seal of Wartorn Fate
  72. [1710] = {["type"] = TYPE_CURRENCY, ["name"] = L["NAME_SEAFARERS_DUBLOON"]}, -- BfA Seafarer's Dubloon
  73. [1716] = {["type"] = TYPE_CURRENCY, ["name"] = L["NAME_HONORBOUND_SERVICE_MEDAL"]}, -- BfA Honorbound Service Medal
  74. [1717] = {["type"] = TYPE_CURRENCY, ["name"] = L["NAME_7TH_LEGION_SERVICE_MEDAL"]}, -- BfA 7th Legion Service Medal
  75. [1718] = {["type"] = TYPE_CURRENCY, ["name"] = L["NAME_TITAN_RESIDUUM"]}, -- BfA Titan Residuum
  76. [1721] = {["type"] = TYPE_CURRENCY, ["name"] = L["NAME_PRISMATIC_MANAPEARL"]}, -- BfA Prismatic Manapearl
  77. [1755] = {["type"] = TYPE_CURRENCY, ["name"] = L["NAME_COALESCING_VISIONS"]}, -- BfA Coalescing Visions
  78. [1719] = {["type"] = TYPE_CURRENCY, ["name"] = L["NAME_CORRUPTED_MEMENTOS"]}, -- BfA Corrupted Mementos
  79. [1803] = {["type"] = TYPE_CURRENCY, ["name"] = L["NAME_ECHOES_OF_NYALOTHA"]}, -- BfA Echoes of Ny'alotha
  80. -- Legion
  81. [1220] = {["type"] = TYPE_CURRENCY, ["name"] = L["NAME_ORDER_RESOURCES"]}, -- Legion Order Resources
  82. [1226] = {["type"] = TYPE_CURRENCY, ["name"] = L["NAME_NETHERSHARD"]}, -- Legion Nethershard
  83. [1268] = {["type"] = TYPE_CURRENCY, ["name"] = L["NAME_TIMEWORN_ARTIFACT"]}, -- Legion Timeworn Artifact
  84. [1273] = {["type"] = TYPE_CURRENCY, ["name"] = L["NAME_SEAL_OF_BROKEN_FATE"]}, -- Legion Seal of Broken Fate
  85. [1275] = {["type"] = TYPE_CURRENCY, ["name"] = L["NAME_CURIOUS_COINS"]}, -- Legion Curious Coins
  86. [1342] = {["type"] = TYPE_CURRENCY, ["name"] = L["NAME_LEGIONFALL_WAR_SUPPLIES"]}, -- Legion Legionfall War Supplies
  87. [1501] = {["type"] = TYPE_CURRENCY, ["name"] = L["NAME_WRITHING_ESSENCE"]}, -- Legion Writhing Essence
  88. [1508] = {["type"] = TYPE_CURRENCY, ["name"] = L["NAME_VEILED_ARGUNITE"]}, -- Legion Veiled Argunite
  89. [1533] = {["type"] = TYPE_CURRENCY, ["name"] = L["NAME_WAKENING_ESSENCE"]}, -- Legion Wakening Essence
  90. [1149] = {["type"] = TYPE_CURRENCY, ["name"] = L["NAME_SIGHTLESS_EYE"]}, -- Legion Sightless Eye
  91. [1154] = {["type"] = TYPE_CURRENCY, ["name"] = L["NAME_SHADOWY_COINS"]}, -- Legion Shadowy Coins
  92. [1155] = {["type"] = TYPE_CURRENCY, ["name"] = L["NAME_ANCIENT_MANA"]}, -- Legion Ancient Mana
  93. [1356] = {["type"] = TYPE_CURRENCY, ["name"] = L["NAME_ECHOES_OF_BATTLE"]}, -- Legion Echoes of Battle
  94. [1357] = {["type"] = TYPE_CURRENCY, ["name"] = L["NAME_ECHOES_OF_DOMINATION"]}, -- Legion Echoes of Domination
  95. -- WoD
  96. [823] = {["type"] = TYPE_CURRENCY, ["name"] = L["NAME_APEXIS_CRYSTAL"]}, -- WoD Apexis Crystal
  97. [824] = {["type"] = TYPE_CURRENCY, ["name"] = L["NAME_GARRISON_RESOURCES"]}, -- WoD Garrison Resources
  98. [944] = {["type"] = TYPE_CURRENCY, ["name"] = L["NAME_ARTIFACT_FRAGMENT"]}, -- WoD Artifact Fragment
  99. [980] = {["type"] = TYPE_CURRENCY, ["name"] = L["NAME_DINGY_IRON_COINS"]}, -- WoD Dingy Iron Coins
  100. [994] = {["type"] = TYPE_CURRENCY, ["name"] = L["NAME_SEAL_OF_TEMPERED_FATE"]}, -- WoD Seal of Tempered Fate
  101. [1101] = {["type"] = TYPE_CURRENCY, ["name"] = L["NAME_OIL"]}, -- WoD Oil
  102. [1129] = {["type"] = TYPE_CURRENCY, ["name"] = L["NAME_SEAL_OF_INEVITABLE_FATE"]}, -- WoD Seal of Inevitable Fate
  103. [1166] = {["type"] = TYPE_CURRENCY, ["name"] = L["NAME_TIMEWARPED_BADGE"]}, -- WoD Timewarped Badge
  104. -- MoP
  105. [697] = {["type"] = TYPE_CURRENCY, ["name"] = L["NAME_ELDERCHARMOFGOODFORTUNE"]}, -- MoP Elder Charm of Good Fortune
  106. [738] = {["type"] = TYPE_CURRENCY, ["name"] = L["NAME_LESSERGOODFORTUNE"]}, -- MoP Lesser Charm of Good Fortune
  107. [752] = {["type"] = TYPE_CURRENCY, ["name"] = L["NAME_MOGORUNEOFFATE"]}, -- MoP 5.2 Mogu Rune of Fate
  108. [776] = {["type"] = TYPE_CURRENCY, ["name"] = L["NAME_WARFORGEDSEAL"]}, -- MoP 5.4 Warforged Seal
  109. [777] = {["type"] = TYPE_CURRENCY, ["name"] = L["NAME_TIMELESSCOIN"]}, -- MoP 5.4 Timeless Coin
  110. -- Cata
  111. [416] = {["type"] = TYPE_CURRENCY, ["name"] = L["NAME_MARKOFTHEWORLDTREE"]},
  112. [614] = {["type"] = TYPE_CURRENCY, ["name"] = L["NAME_MOTEDARKNESS"]}, -- T13 (Dragonsoul) currency
  113. [615] = {["type"] = TYPE_CURRENCY, ["name"] = L["NAME_ESSENCEDEATHWING"]}, -- T13 (Dragonsoul) currency
  114. -- Wrath
  115. [241] = {["type"] = TYPE_CURRENCY, ["name"] = L["NAME_CHAMPIONSEAL"]},
  116. -- TBC
  117. -- WoW
  118. },
  119. ["pvp"] = {
  120. -- MoP
  121. [789] = {["type"] = TYPE_CURRENCY, ["name"] = L["NAME_BLOODYCOIN"]}, -- MoP 5.4 Bloody Coin
  122. -- Cata
  123. [391] = {["type"] = TYPE_CURRENCY, ["name"] = L["NAME_TOLBARADCOMMENDATION"]}, -- Tol Barad
  124. }
  125. },
  126. ["archaeology"] = {
  127. -- Archaeology Fragments
  128. [384] = {["type"] = TYPE_FRAGMENT, ["index"] = 1, ["name"] = L["NAME_AF_DWARF"]},
  129. [385] = {["type"] = TYPE_FRAGMENT, ["index"] = 8, ["name"] = L["NAME_AF_TROLL"]},
  130. [393] = {["type"] = TYPE_FRAGMENT, ["index"] = 3, ["name"] = L["NAME_AF_FOSSIL"]},
  131. [394] = {["type"] = TYPE_FRAGMENT, ["index"] = 4, ["name"] = L["NAME_AF_NIGHTELF"]},
  132. [397] = {["type"] = TYPE_FRAGMENT, ["index"] = 6, ["name"] = L["NAME_AF_ORC"]},
  133. [398] = {["type"] = TYPE_FRAGMENT, ["index"] = 2, ["name"] = L["NAME_AF_DRAENEI"]},
  134. [399] = {["type"] = TYPE_FRAGMENT, ["index"] = 9, ["name"] = L["NAME_AF_VRYKULL"]},
  135. [400] = {["type"] = TYPE_FRAGMENT, ["index"] = 5, ["name"] = L["NAME_AF_NERUBIAN"]},
  136. [401] = {["type"] = TYPE_FRAGMENT, ["index"] = 7, ["name"] = L["NAME_AF_TOLVIR"]},
  137. [676] = {["type"] = TYPE_FRAGMENT, ["index"] = 11, ["name"] = L["NAME_AF_PANDAREN"]},
  138. [677] = {["type"] = TYPE_FRAGMENT, ["index"] = 12, ["name"] = L["NAME_AF_MOGU"]},
  139. [754] = {["type"] = TYPE_FRAGMENT, ["index"] = 10, ["name"] = L["NAME_AF_MANTID"]}, -- MoP 5.2 Mantid Archaeology Fragment
  140. [821] = {["type"] = TYPE_FRAGMENT, ["index"] = 13, ["name"] = L["NAME_AF_DRAENOR_CLANS"]}, -- WoD Draenor Clans Archaeology Fragment
  141. [828] = {["type"] = TYPE_FRAGMENT, ["index"] = 14, ["name"] = L["NAME_AF_OGRE"]}, -- WoD Ogre Archaeology Fragment
  142. [829] = {["type"] = TYPE_FRAGMENT, ["index"] = 15, ["name"] = L["NAME_AF_ARAKKOA"]}, -- WoD Arakkoa Archaeology Fragment
  143. },
  144. ["profession"] = {
  145. [61] = {["type"] = TYPE_CURRENCY, ["name"] = L["NAME_DALJCTOKEN"]},
  146. [81] = {["type"] = TYPE_CURRENCY, ["name"] = L["NAME_EPICUREANAWARD"]},
  147. [361] = {["type"] = TYPE_CURRENCY, ["name"] = L["NAME_ILLJCTOKEN"]},
  148. [402] = {["type"] = TYPE_CURRENCY, ["name"] = L["NAME_IRONPAWTOKEN"]},
  149. [698] = {["type"] = TYPE_CURRENCY, ["name"] = L["NAME_ZENJCTOKEN"]}, -- MoP jewelcrafting
  150. [910] = {["type"] = TYPE_CURRENCY, ["name"] = L["NAME_SECRETDRAENORALCHEMY"]}, -- WoD alchemy
  151. [999] = {["type"] = TYPE_CURRENCY, ["name"] = L["NAME_SECRETDRAENORTAILORING"]}, -- WoD tailoring
  152. [1008] = {["type"] = TYPE_CURRENCY, ["name"] = L["NAME_SECRETDRAENORJEWELCRAFTING"]}, -- WoD jewelcrafting
  153. [1017] = {["type"] = TYPE_CURRENCY, ["name"] = L["NAME_SECRETDRAENORLEATHERWORKING"]}, -- WoD leatherworking
  154. [1020] = {["type"] = TYPE_CURRENCY, ["name"] = L["NAME_SECRETDRAENORBLACKSMITHING"]}, -- WoD blacksmithing
  155. },
  156. ["events"] = {
  157. [515] = {["type"] = TYPE_CURRENCY, ["name"] = L["NAME_DARKMOONPRIZETICKET"]},
  158. },
  159. ["misc"] = {
  160.  
  161. }
  162. }
  163.  
  164. local build = select(4, GetBuildInfo)
  165.  
  166. local tracking = {
  167. ["gold"] = {["type"] = TYPE_MONEY, ["name"] = L["NAME_MONEY"], ["icon"] = "Interface\\Minimap\\Tracking\\Auctioneer"},
  168.  
  169. [0] = {["type"] = TYPE_FRAGMENT, ["index"] = 16, ["name"] = L["NAME_AF_OTHER"]},
  170. }
  171.  
  172. -- Add currencies back into the tracking table (this is easier than re-writing all occurences of tracking)
  173. for k,v in pairs(currencies["current"]["pve"]) do tracking[k] = v end
  174. for k,v in pairs(currencies["current"]["pvp"]) do tracking[k] = v end
  175. for k,v in pairs(currencies["legacy"]["pve"]) do tracking[k] = v end
  176. for k,v in pairs(currencies["legacy"]["pvp"]) do tracking[k] = v end
  177. for k,v in pairs(currencies["events"]) do tracking[k] = v end
  178. for k,v in pairs(currencies["profession"]) do tracking[k] = v end
  179. for k,v in pairs(currencies["archaeology"]) do tracking[k] = v end
  180. for k,v in pairs(currencies["misc"]) do tracking[k] = v end
  181.  
  182. -- Used to copy a table instead of just copying the reference to it.
  183. -- Does not copy metatable information
  184. function deepcopy(object)
  185. local lookup_table = {}
  186. local function _copy(object)
  187. if type(object) ~= "table" then
  188. return object
  189. elseif lookup_table[object] then
  190. return lookup_table[object]
  191. end
  192. local new_table = {}
  193. lookup_table[object] = new_table
  194. for index, value in pairs(object) do
  195. new_table[_copy(index)] = _copy(value)
  196. end
  197. return new_table
  198. end
  199. return _copy(object)
  200. end
  201.  
  202. local function Notice( msg )
  203. if ( msg ~= nil and DEFAULT_CHAT_FRAME ) then
  204. DEFAULT_CHAT_FRAME:AddMessage( MODNAME.." notice: "..msg, 0.6, 1.0, 1.0 )
  205. end
  206. end
  207.  
  208. -- Returns character name, colored by class
  209. function Currencyflow:ColorByClass( name, class )
  210. local classcol = RAID_CLASS_COLORS[class] or {["r"] = 1, ["g"] = 1, ["b"] = 0}
  211. return format("|cff%02x%02x%02x%s|r", classcol["r"]*255, classcol["g"]*255, classcol["b"]*255, name)
  212. end
  213.  
  214. function Currencyflow:GetToday()
  215. local offset = time(date("*t")) - time(date("!*t")) -- Offset to UTC, in seconds
  216. return floor((time()+offset) / 86400)
  217. end
  218.  
  219. function Currencyflow:updateTime()
  220. local now = time()
  221. self.session.time = self.session.time + now - self.savedTime
  222.  
  223. self.db.realm.chars[self.meidx].history = self.db.realm.chars[self.meidx].history or {}
  224. self.db.realm.chars[self.meidx].history[self.today] = self.db.realm.chars[self.meidx].history[self.today] or { time = 0, gold = { gained = 0, spent = 0 } }
  225. self.db.realm.chars[self.meidx].history[self.today].time = self.db.realm.chars[self.meidx].history[self.today].time + now - self.savedTime
  226. self.savedTime = now
  227. end
  228.  
  229. --[[
  230. Displays the given amount of gold in the configured format.
  231. if colorize is true, it will color the text red if negative, green if positive (or 0)
  232. if it's false, it wil color the text white, and with a "-" in front if it's negative
  233. ]]
  234. function Currencyflow:FormatGold( amount, colorize )
  235. local ICON_GOLD = "|TInterface\\MoneyFrame\\UI-GoldIcon:0|t"
  236. local ICON_SILVER = "|TInterface\\MoneyFrame\\UI-SilverIcon:0|t"
  237. local ICON_COPPER = "|TInterface\\MoneyFrame\\UI-CopperIcon:0|t"
  238.  
  239. local COLOR_WHITE = "ffffff"
  240. local COLOR_GREEN = "00ff00"
  241. local COLOR_RED = "ff0000"
  242. local COLOR_COPPER = "eda55f"
  243. local COLOR_SILVER = "c7c7cf"
  244. local COLOR_GOLD = "ffd700"
  245.  
  246. -- Make sure amount is a number
  247. -- NaN values are not equal to themselfs, see http://snippets.luacode.org/snippets/Test_for_NaN_75
  248. if amount ~= amount or tostring(amount) == "-1.#IND" or tostring(amount) == "-nan(ind)" then amount = 0 end
  249.  
  250. local gold = abs(amount / 10000)
  251. local silver = abs(mod(amount / 100, 100))
  252. local copper = abs(mod(amount, 100))
  253.  
  254. -- Make sure the values are numbers too
  255. if gold ~= gold then gold = 0 end
  256. if silver ~= silver then silver = 0 end
  257. if copper ~= copper then copper = 0 end
  258.  
  259. -- Determine text color
  260. local color = COLOR_WHITE
  261. local sign = ""
  262. if colorize and self.db.profile.cashFormat ~= 1 then
  263. -- With format 1, the text color itself is in gold/silver/copper,
  264. -- so colorize has no effect, and we always show "-" on negative
  265. if amount < 0 then color = COLOR_RED else color = COLOR_GREEN end
  266. elseif amount < 0 then
  267. sign = "-"
  268. end
  269.  
  270. -- Determine unit display
  271. if self.db.profile.cashFormat == 1 then
  272. -- Abacus "Condensed"
  273. if gold > 0 then
  274. return sign..format("|cff%s%d|r |cff%s%02d|r |cff%s%02d|r", COLOR_GOLD, gold, COLOR_SILVER, silver, COLOR_COPPER, copper)
  275. elseif silver > 0 then
  276. return sign..format("|cff%s%d|r |cff%s%02d|r", COLOR_SILVER, silver, COLOR_COPPER, copper)
  277. else
  278. return sign..format("|cff%s%d|r", COLOR_COPPER, copper)
  279. end
  280. elseif self.db.profile.cashFormat == 2 then
  281. -- Abacus "Short"
  282. if gold > 0 then
  283. return sign..format("|cff%s%.1f|r|cff%sg|r ", color, gold, COLOR_GOLD)
  284. elseif silver > 0 then
  285. return sign..format("|cff%s%.1f|r|cff%ss|r", color, silver, COLOR_SILVER)
  286. else
  287. return sign..format("|cff%s%d|r|cff%sc|r", color, copper, COLOR_COPPER)
  288. end
  289. elseif self.db.profile.cashFormat == 3 then
  290. -- Abacus "Full"
  291. if gold > 0 then
  292. return sign..format("|cff%s%s|r|cff%sg|r |cff%s%02d|r|cff%ss|r |cff%s%02d|r|cff%sc|r", color, BreakUpLargeNumbers(math.floor(gold)), COLOR_GOLD, color, silver, COLOR_SILVER, color, copper, COLOR_COPPER)
  293. elseif silver > 0 then
  294. return sign..format("|cff%s%d|r|cff%ss|r |cff%s%02d|r|cff%sc|r", color, silver, COLOR_SILVER, color, copper, COLOR_COPPER)
  295. else
  296. return sign..format("|cff%s%d|r|cff%sc|r", color, copper, COLOR_COPPER)
  297. end
  298. elseif self.db.profile.cashFormat == 4 then
  299. -- With coin icons
  300. if gold > 0 then
  301. return sign..format("|cff%s%s|r%s |cff%s%02d|r%s |cff%s%02d|r%s", color, BreakUpLargeNumbers(math.floor(gold)), ICON_GOLD, color, silver, ICON_SILVER, color, copper, ICON_COPPER)
  302. elseif silver > 0 then
  303. return sign..format("|cff%s%d|r%s |cff%s%02d|r%s", color, silver, ICON_SILVER, color, copper, ICON_COPPER)
  304. else
  305. return sign..format("|cff%s%d|r%s", color, copper, ICON_COPPER)
  306. end
  307. end
  308. return "<error>"
  309. end
  310.  
  311. --[[
  312. Formats (colors) the given amount of currency with either the given color, or
  313. red/green if none given
  314. ]]
  315. function Currencyflow:FormatCurrency( amount, color )
  316. if color == "" then
  317. if amount < 0 then color = "ff0000" else color = "00ff00" end
  318. end
  319. return "|cff"..color..amount.."|r"
  320. end
  321.  
  322. --[[
  323. Returns time, gained, spent values.
  324. char: Character index, or 0 to sum all (non-ignored)
  325. day: Day #, or 0 for session, or negative for range
  326. currency: Currency id
  327. ]]
  328. function Currencyflow:db_GetHistory( char, day, currency )
  329.  
  330. -- Basically the same thing, except no sums/ranges!
  331. local getval = function( char, day, currency )
  332. -- time is set to 1 to avoid division by zero later on
  333. local time, gained, spent = 1, 0, 0
  334. if day == 0 then
  335. time = self.session.time or 0
  336. if self.session[currency] then
  337. gained = self.session[currency].gained or 0
  338. spent = self.session[currency].spent or 0
  339. end
  340. elseif self.db.realm.chars[char] and self.db.realm.chars[char].history and self.db.realm.chars[char].history[day] then
  341. time = self.db.realm.chars[char].history[day].time or 0
  342. self.db.realm.chars[char].history[day][currency] = self.db.realm.chars[char].history[day][currency] or {}
  343. if self.db.realm.chars[char].history[day][currency] then
  344. gained = self.db.realm.chars[char].history[day][currency].gained or 0
  345. spent = self.db.realm.chars[char].history[day][currency].spent or 0
  346. end
  347. end
  348. return time, gained, spent
  349. end
  350.  
  351. local i, time,gained,spent, t,g,s = 0, 0,0,0, 1,0,0
  352.  
  353. if char > 0 then
  354. if day >= 0 then
  355. time, gained, spent = getval(char, day, currency)
  356. else
  357. -- day < 0, so we need a range
  358. for i = self.today + day, self.today do
  359. t,g,s = getval(char, i, currency)
  360. time = time + t
  361. gained = gained + g
  362. spent = spent + s
  363. end
  364. end
  365. elseif day >= 0 then
  366. for k,v in pairs(self.db.realm.chars) do
  367. if not v.ignore then
  368. t,g,s = getval(k, day, currency)
  369. time = time + t
  370. gained = gained + g
  371. spent = spent + s
  372. end
  373. end
  374. else
  375. -- day < 0, so we need a range
  376. for k,v in pairs(self.db.realm.chars) do
  377. if not v.ignore then
  378. for i = self.today + day, self.today do
  379. t,g,s = getval(k, i, currency)
  380. time = time + t
  381. gained = gained + g
  382. spent = spent + s
  383. end
  384. end
  385. end
  386. end
  387.  
  388. return time, gained, spent
  389. end
  390.  
  391. --[[
  392. Returns current "inventory" of given char for given currency.
  393. char: Character index, or 0 to sum all
  394. currency: Currency id
  395. ]]
  396. function Currencyflow:db_GetTotal( char, currency )
  397. local value = 0
  398. if char == 0 then
  399. for k,_ in pairs(self.db.realm.chars) do
  400. if self.db.realm.chars[k] and not self.db.realm.chars[k].ignore then
  401. value = value + (self.db.realm.chars[k][currency] or 0)
  402. end
  403. end
  404. elseif self.db.realm.chars[char] then
  405. value = self.db.realm.chars[char][currency] or 0
  406. end
  407. return value
  408. end
  409.  
  410. --[[
  411. Update given currency to current amount. Updating session and todays
  412. history, and creating structure as needed.
  413. Pass false for Session only on login to sync database with the
  414. real world
  415. If ignore is set to true for this character, history is set to nil,
  416. to reduce database size
  417. ]]
  418. function Currencyflow:db_UpdateCurrency( currencyId, updateSession )
  419.  
  420. -- Bail if invalid id given
  421. if tracking[currencyId] == nil then return end
  422.  
  423. -- Update all character's maximum reached values, if weekly earnings are reset.
  424. -- currencyId can be "gold"
  425. if type(currencyId) == "number" then
  426. lastWeekEarned = self.db.realm.chars[self.meidx]["lastWeekEarned"..currencyId]
  427. local currencyInfo = C_CurrencyInfo.GetCurrencyInfo(currencyId)
  428.  
  429. if currencyInfo ~= nil then
  430. amount = currencyInfo.quantity
  431. earnedThisWeek = currencyInfo.quantityEarnedThisWeek
  432. weeklyMax = currencyInfo.maxWeeklyQuantity
  433. totalMax = currencyInfo.maxQuantity
  434. end
  435.  
  436. -- Only for currencies, that have a weekly maximum
  437. if lastWeekEarned and weeklyMax > 0 and lastWeekEarned > earnedThisWeek then
  438. for idx, charinfo in pairs(self.db.realm.chars) do
  439. charinfo["maxReached"..currencyId] = false
  440. end
  441. end
  442. end
  443.  
  444. -- If I'm being ignored, clear my history, and bail
  445. if self.db.realm.chars[self.meidx].ignore then
  446. self.db.realm.chars[self.meidx].history = nil
  447. return
  448. end
  449.  
  450. self:updateTime()
  451.  
  452. -- In case we roll over midnight during a session
  453. if self.today < self.GetToday() then
  454. self.today = self.GetToday()
  455.  
  456. -- Remove last history entry
  457. self.db.realm.chars[self.meidx].history[self.today - HISTORY_DAYS] = nil
  458.  
  459. -- Create blank entry for today
  460. self.db.realm.chars[self.meidx].history[self.today] = self.db.realm.chars[self.meidx].history[self.today] or { time = 0, gold = { gained = 0, spent = 0 } }
  461. end
  462.  
  463. -- Remember what it was
  464. local oldVal = self.db.realm.chars[self.meidx][currencyId] or 0
  465.  
  466. -- Get new value and check if maximum is reached
  467. if tracking[currencyId].type == TYPE_MONEY then
  468. amount = GetMoney()
  469. elseif tracking[currencyId].type == TYPE_CURRENCY then
  470. local currencyInfo = C_CurrencyInfo.GetCurrencyInfo(currencyId)
  471. amount = currencyInfo.quantity
  472. earnedThisWeek = currencyInfo.quantityEarnedThisWeek
  473. weeklyMax = currencyInfo.maxWeeklyQuantity
  474. totalMax = currencyInfo.maxQuantity
  475. texture = currencyInfo.iconFileID
  476. if not amount then amount = 0 end
  477. if weeklyMax and weeklyMax > 0 then
  478. self.db.realm.chars[self.meidx]["maxReached" .. currencyId] = earnedThisWeek >= weeklyMax / 100
  479. -- we can safely save the new earnedThisWeek value, since we checked for a reset before
  480. self.db.realm.chars[self.meidx]["lastWeekEarned" .. currencyId] = earnedThisWeek
  481. elseif totalMax and totalMax > 0 then
  482. self.db.realm.chars[self.meidx]["maxReached" .. currencyId] = amount >= totalMax / 100
  483. end
  484. elseif tracking[currencyId].type == TYPE_FRAGMENT then
  485. local currencyInfo = C_CurrencyInfo.GetCurrencyInfo(currencyId)
  486. if currencyInfo ~= nil then
  487. amount = currencyInfo.quantity
  488. end
  489. if amount then self.db.realm.chars[self.meidx]["maxReached" .. currencyId] = amount >= 200
  490. else amount = 0 end
  491. elseif tracking[currencyId].type == TYPE_ITEM then amount = GetItemCount(currencyId,true) or 0 end
  492.  
  493. -- Bail if amount has not changed
  494. if amount == oldVal then return end
  495.  
  496. -- Set new value
  497. self.db.realm.chars[self.meidx][currencyId] = amount
  498.  
  499. -- Make sure history structure exists
  500. self.db.realm.chars[self.meidx].history = self.db.realm.chars[self.meidx].history or {}
  501. self.db.realm.chars[self.meidx].history[self.today] = self.db.realm.chars[self.meidx].history[self.today] or {time = 0, gold = {gained = 0, spent = 0}}
  502. self.db.realm.chars[self.meidx].history[self.today][currencyId] = self.db.realm.chars[self.meidx].history[self.today][currencyId] or {gained = 0, spent = 0}
  503.  
  504. -- Make sure session structure exists
  505. self.session[currencyId] = self.session[currencyId] or {gained = 0, spent = 0}
  506.  
  507. -- If we seem to have gained/lost anything on login, it just "magically"
  508. -- happened, and we don't track it in history
  509. if updateSession then
  510. if amount > oldVal then
  511. self.db.realm.chars[self.meidx].history[self.today][currencyId].gained = (self.db.realm.chars[self.meidx].history[self.today][currencyId].gained or 0) + amount - oldVal
  512. self.session[currencyId].gained = self.session[currencyId].gained + amount - oldVal
  513. else
  514. self.db.realm.chars[self.meidx].history[self.today][currencyId].spent = (self.db.realm.chars[self.meidx].history[self.today][currencyId].spent or 0) + oldVal - amount
  515. self.session[currencyId].spent = self.session[currencyId].spent + oldVal - amount
  516. end
  517. end
  518. end
  519.  
  520. -- Add Other toons we know about and total to the tooltip, if so desired
  521. function Currencyflow:addCharactersAndTotal()
  522.  
  523. -- If neither charactares or totals are configured to be shown, get out of here
  524. if not self.db.profile.showOtherChars and not self.db.profile.showTotals then return end
  525.  
  526. local colsPerItem = 1
  527. if self.db.profile.showCashPerHour then colsPerItem = 2 end
  528.  
  529. -- Sort the table according to settings
  530. table.sort(self.db.realm.chars, function(a,b)
  531. if a == nil or b == nil then
  532. return false
  533. end
  534.  
  535. -- Safety net for nil values.
  536. a_value = nil == a[self.db.profile.sortChars] and 0 or a[self.db.profile.sortChars]
  537. b_value = nil == b[self.db.profile.sortChars] and 0 or b[self.db.profile.sortChars]
  538.  
  539. if self.db.profile.sortDesc then
  540. if a[self.db.profile.sortChars] == b[self.db.profile.sortChars] then
  541. return a.charname > b.charname
  542. else
  543. return a_value > b_value
  544. end
  545. elseif (a[self.db.profile.sortChars] == b[self.db.profile.sortChars]) then
  546. return a.charname < b.charname
  547. else
  548. return a_value < b_value
  549. end
  550. end)
  551.  
  552. -- We need to update self.meidx as it has most likely changed
  553. self.meidx = -1
  554. for k in pairs(self.db.realm.chars) do
  555. if self.db.realm.chars[k].charname == UnitName("player") then
  556. self.meidx = k
  557. break
  558. end
  559. end
  560.  
  561. -- Add other characters
  562. if self.db.profile.showOtherChars then
  563. tooltip:AddSeparator()
  564. lineNum = tooltip:AddLine(" ")
  565. tooltip:SetCell( lineNum, 1, format(fmt_yellow, L["CFGNAME_CHARACTERS"]), "LEFT", tooltip:GetColumnCount() )
  566.  
  567. for k,v in pairs(self.db.realm.chars) do
  568. if not v.ignore then
  569. local newLineNum = tooltip:AddLine(" ")
  570. tooltip:SetCell( newLineNum, 1, self:ColorByClass(v.charname, v.class) )
  571. tooltip:SetCell( newLineNum, 2, self:FormatGold(self:db_GetTotal(k, "gold"), false), "RIGHT", colsPerItem )
  572.  
  573. colNum = colsPerItem + 2
  574.  
  575. for id,currency in pairs(tracking) do
  576. if self.db.profile["showCurrency"..id] then
  577. if self.db.profile.colorMaxReached and v["maxReached"..id] then
  578. color = COLOR_MAXREACHED
  579. elseif math.fmod(colNum,2) == 0 then
  580. color = "aaaaff"
  581. else
  582. color = "ddddff"
  583. end
  584. tooltip:SetCell( newLineNum, colNum, self:FormatCurrency(self:db_GetTotal(k, id), color), "RIGHT" )
  585. colNum = colNum + 1
  586. end
  587. end
  588. end
  589. end
  590. end
  591.  
  592. -- Add grand total
  593. if self.db.profile.showTotals then
  594. tooltip:AddSeparator()
  595. local newLineNum = tooltip:AddLine(" ")
  596. tooltip:SetCell( newLineNum, 1, format(fmt_yellow, L["CFGNAME_TOTAL"]) )
  597. tooltip:SetCell( newLineNum, 2, self:FormatGold(self:db_GetTotal(0, "gold"), false), "RIGHT", colsPerItem )
  598.  
  599. colNum = colsPerItem + 2
  600.  
  601. for id,currency in pairs(tracking) do
  602. if self.db.profile["showCurrency"..id] then
  603. if math.fmod(colNum,2) == 0 then color = "aaaaff" else color = "ddddff" end
  604. tooltip:SetCell( newLineNum, colNum, self:FormatCurrency(self:db_GetTotal(0, id), color), "RIGHT" )
  605. colNum = colNum + 1
  606. end
  607. end
  608. end
  609. end
  610.  
  611. function Currencyflow:drawTooltip()
  612. tooltip:Hide()
  613. tooltip:Clear()
  614.  
  615. self:updateTime()
  616.  
  617. -- Add our header
  618. local lineNum = tooltip:AddHeader(" ")
  619. tooltip:SetCell( lineNum, 1, format(fmt_white, FULLNAME), "CENTER", tooltip:GetColumnCount() )
  620. tooltip:AddLine(" ")
  621.  
  622. local colsPerItem = 1
  623. if self.db.profile.showCashPerHour then colsPerItem = 2 end
  624.  
  625. -- Add the header for the gold column(s)
  626. lineNum = tooltip:AddLine(" ")
  627. tooltip:SetCell( lineNum, 2, "|TInterface\\Icons\\INV_Misc_Coin_01:16|t", "CENTER" )
  628. if self.db.profile.showCashPerHour then tooltip:SetCell( lineNum, 3, "|TInterface\\Icons\\INV_Misc_Coin_01:16|t/Hr", "CENTER" ) end
  629.  
  630. -- Add a header for each of the currencies we're showing
  631. local colNum = colsPerItem + 2
  632. local icon
  633.  
  634. for id,currency in pairs(tracking) do
  635. if self.db.profile["showCurrency"..id] then
  636. tooltip:SetCell( lineNum, colNum, "|T"..currency.icon..":16|t", "CENTER" )
  637. tooltip:SetCellScript( lineNum, colNum, "OnEnter", function()
  638. if not CurrencyHeaderTooltip then CurrencyHeaderTooltip = CreateFrame("GameTooltip", "CurrencyHeaderTooltip", UIParent, "GameTooltipTemplate") end
  639. CurrencyHeaderTooltip:SetOwner(tooltip, "ANCHOR_CURSOR")
  640. CurrencyHeaderTooltip:SetText(currency.name)
  641. CurrencyHeaderTooltip:SetFrameLevel(999)
  642. CurrencyHeaderTooltip:Show()
  643. end )
  644. tooltip:SetCellScript( lineNum, colNum, "OnLeave", function()
  645. CurrencyHeaderTooltip:Hide()
  646. end )
  647. colNum = colNum + 1
  648. end
  649. end
  650.  
  651. if self.db.profile.showThisSession then self:addNewCurrencySection( "session", L["CFGNAME_THISSESSION"] ) end
  652. if self.db.profile.showTodaySelf then self:addNewCurrencySection( "todayself", L["CFGNAME_TODAYSELF"] ) end
  653. if self.db.profile.showTodayTotal then self:addNewCurrencySection( "todayall", L["CFGNAME_TODAYTOTAL"] ) end
  654. if self.db.profile.showYesterdaySelf then self:addNewCurrencySection( "yesterdayself", L["CFGNAME_YESTERDAYSELF"] ) end
  655. if self.db.profile.showYesterdayTotal then self:addNewCurrencySection( "yesterdayall", L["CFGNAME_YESTERDAYTOTAL"] ) end
  656. if self.db.profile.showThisWeekSelf then self:addNewCurrencySection( "thisweekself", L["CFGNAME_WEEKSELF"] ) end
  657. if self.db.profile.showThisWeekTotal then self:addNewCurrencySection( "thisweekall", L["CFGNAME_WEEKTOTAL"] ) end
  658. if self.db.profile.showThisMonthSelf then self:addNewCurrencySection( "thismonthself", L["CFGNAME_MONTHSELF"] ) end
  659. if self.db.profile.showThisMonthTotal then self:addNewCurrencySection( "thismonthall", L["CFGNAME_MONTHTOTAL"] ) end
  660.  
  661. if not self.db.profile.showCashDetail then tooltip:AddLine(" ") end
  662.  
  663. -- Add Other toons we know about
  664. self:addCharactersAndTotal()
  665.  
  666. -- And a hint to show options
  667. tooltip:AddLine( " " )
  668. lineNum = tooltip:AddLine( " " )
  669. tooltip:SetCell( lineNum, 1, format(fmt_yellow, L["CFGNAME_TIPOPTIONS"]), "LEFT", tooltip:GetColumnCount() )
  670. lineNum = tooltip:AddLine( " " )
  671. tooltip:SetCell( lineNum, 1, format(fmt_yellow, L["CFGNAME_TIPRESETSESSION"]), "LEFT", tooltip:GetColumnCount() )
  672. end
  673.  
  674. function Currencyflow:addNewCurrencySection(type, title)
  675. local char,day,currency, column, t,g,s, l1,l2,l3
  676.  
  677. if type == "session" then char = self.meidx; day = 0
  678. elseif type == "todayself" then char = self.meidx; day = self.today
  679. elseif type == "todayall" then char = 0; day = self.today
  680. elseif type == "yesterdayself" then char = self.meidx; day = self.today - 1
  681. elseif type == "yesterdayall" then char = 0; day = self.today - 1
  682. elseif type == "thisweekself" then char = self.meidx; day = -7
  683. elseif type == "thisweekall" then char = 0; day = -7
  684. elseif type == "thismonthself" then char = self.meidx; day = -30
  685. elseif type == "thismonthall" then char = 0; day = -30
  686. else return end
  687.  
  688. -- Create the tooltip line(s)
  689. if self.db.profile.showCashDetail then
  690. lineNum = tooltip:AddLine(" ")
  691. tooltip:SetCell( lineNum, 1, format(fmt_yellow, title), "LEFT", tooltip:GetColumnCount() )
  692.  
  693. l1 = tooltip:AddLine(L["CFGNAME_GAINED"])
  694. l2 = tooltip:AddLine(L["CFGNAME_SPENT"])
  695. l3 = tooltip:AddLine(L["CFGNAME_PROFIT"])
  696. else
  697. l1 = tooltip:AddLine(title)
  698. end
  699.  
  700. -- Get values for gold
  701. column = 2
  702. t,g,s = self:db_GetHistory(char, day, "gold")
  703. self:setCurrencyColumn(l1, column, t,g,s, true)
  704.  
  705. column = column + 1
  706. if self.db.profile.showCashPerHour then column = column + 1 end
  707.  
  708. -- Add each currency we're tracking (and showing)
  709. for id,currency in pairs(tracking) do
  710. if self.db.profile["showCurrency"..id] then
  711. t,g,s = self:db_GetHistory( char, day, id )
  712. self:setCurrencyColumn(l1, column, t,g,s, false)
  713. column = column + 1
  714. end
  715. end
  716.  
  717. if self.db.profile.showCashDetail then tooltip:AddLine(" ") end
  718. end
  719.  
  720. function Currencyflow:setCurrencyColumn( startRow, startCol, t,g,s, doPerHour )
  721. local color
  722. if self.db.profile.showCashDetail then
  723. if startCol == 2 then
  724. tooltip:SetCell( startRow, startCol, self:FormatGold(g, false), "RIGHT" )
  725. tooltip:SetCell( startRow+1, startCol, self:FormatGold(s, false), "RIGHT" )
  726. tooltip:SetCell( startRow+2, startCol, self:FormatGold(g-s, true), "RIGHT" )
  727. else
  728. if math.fmod(startCol,2) == 0 then color = "aaaaff" else color = "ddddff" end
  729. tooltip:SetCell( startRow, startCol,self:FormatCurrency(g, color), "RIGHT" )
  730. tooltip:SetCell( startRow+1, startCol, self:FormatCurrency(s, color), "RIGHT" )
  731. tooltip:SetCell( startRow+2, startCol, self:FormatCurrency(g-s, ""), "RIGHT" )
  732. end
  733. elseif startCol == 2 then
  734. tooltip:SetCell( startRow, startCol, self:FormatGold(g-s, true), "RIGHT" )
  735. else
  736. tooltip:SetCell( startRow, startCol, self:FormatCurrency(g-s, ""), "RIGHT" )
  737. end
  738.  
  739. if doPerHour and self.db.profile.showCashPerHour then
  740. if self.db.profile.showCashDetail then
  741. if startCol == 2 then
  742. tooltip:SetCell( startRow, startCol+1, self:FormatGold( g/t*3600, false ), "RIGHT" )
  743. tooltip:SetCell( startRow+1, startCol+1, self:FormatGold( s/t*3600, false ), "RIGHT" )
  744. tooltip:SetCell( startRow+2, startCol+1, self:FormatGold( (g-s)/t*3600, true ), "RIGHT" )
  745. else
  746. if fmod(startCol,2) == 0 then color = "aaaaff" else color = "ddddff" end
  747. tooltip:SetCell( startRow, startCol+1,self:FormatCurrency( g/t*3600, color ), "RIGHT" )
  748. tooltip:SetCell( startRow+1, startCol+1, self:FormatCurrency( s/t*3600, color ), "RIGHT" )
  749. tooltip:SetCell( startRow+2, startCol+1, self:FormatCurrency( (g-s)/t*3600, "" ), "RIGHT" )
  750. end
  751. elseif startCol == 2 then
  752. tooltip:SetCell( startRow, startCol+1, self:FormatGold( (g-s)/t*3600, true ), "RIGHT" )
  753. else
  754. -- Not being used, but it's here for completeness
  755. tooltip:SetCell( startRow, startCol+1, self:FormatCurrency( (g-s)/t*3600, "" ), "RIGHT" )
  756. end
  757. end
  758. end
  759.  
  760. local LDB = LibStub( "LibDataBroker-1.1" )
  761. local launcher = LDB:NewDataObject( MODNAME, {
  762. type = "data source",
  763. text = " ",
  764. label = FULLNAME,
  765. icon = "Interface\\Minimap\\Tracking\\Auctioneer",
  766.  
  767. OnClick = function(clickedframe, button)
  768. if button == "LeftButton" and IsShiftKeyDown() then
  769. -- Reset current session
  770. StaticPopupDialogs["RESET_SESSION"] = {
  771. text = L["CFG_CONFIRMRESETSESSION"],
  772. button1 = L["NAME_YES"],
  773. button2 = L["NAME_NO"],
  774. OnAccept = function()
  775. Currencyflow.session = {time = 0, gold = {gained = 0, spent = 0}}
  776. end,
  777. timeout = 0,
  778. whileDead = true,
  779. hideOnEscape = true,
  780. }
  781. StaticPopup_Show ("RESET_SESSION")
  782.  
  783. elseif button == "RightButton" then
  784. Currencyflow:LoadCurrencies(); InterfaceOptionsFrame_OpenToCategory(FULLNAME)
  785. end
  786. end,
  787.  
  788. OnEnter = function ( self )
  789. -- We need to calculate how many columns we meed up front
  790. local numcols = 2 -- title and gold
  791. -- One for the cash per hour
  792. if Currencyflow.db.profile.showCashPerHour then numcols = numcols + 1 end
  793. -- And one for each currency we want shown
  794. for id,currency in pairs(tracking) do
  795. if Currencyflow.db.profile["showCurrency"..id] then numcols = numcols + 1 end
  796. end
  797.  
  798. tooltip = QT:Acquire( "CurrencyflowTT", numcols )
  799. tooltip:SetScale( Currencyflow.db.profile.tipscale )
  800.  
  801. Currencyflow:drawTooltip()
  802.  
  803. tooltip:SetAutoHideDelay(0.1, self)
  804. tooltip:EnableMouse()
  805. tooltip:SmartAnchorTo(self)
  806. tooltip:UpdateScrolling()
  807. tooltip:Show()
  808. end,
  809. } )
  810.  
  811. function Currencyflow:UpdateLabel()
  812.  
  813. function getLabelSegment(segment)
  814. segment = tonumber(segment)
  815. if segment == 2 then
  816. -- Current Gold
  817. return self:FormatGold(GetMoney(), false)
  818. elseif segment == 3 or segment == 4 then
  819. -- Session gold total, gold/hr
  820. t,g,s = self:db_GetHistory(self.meidx, 0, "gold")
  821. if segment == 3 then return self:FormatGold(g-s, false) else return self:FormatGold((g-s)/t*3600, false).."/Hr" end
  822. elseif segment == 5 or segment == 6 then
  823. -- Today gold total, gold/hr
  824. t,g,s = self:db_GetHistory(self.meidx, self.today, "gold")
  825. if segment == 5 then return self:FormatGold(g-s, false) else return self:FormatGold((g-s)/t*3600, false).."/Hr" end
  826. elseif segment == 7 or segment == 8 then
  827. -- Week gold total, gold/hr
  828. t,g,s = self:db_GetHistory(self.meidx, -7, "gold")
  829. if segment == 7 then return self:FormatGold(g-s, false) else return self:FormatGold((g-s)/t*3600, false).."/Hr" end
  830. elseif segment == 9 or segment == 10 then
  831. -- Month gold total, gold/hr
  832. t,g,s = self:db_GetHistory(self.meidx, -30, "gold")
  833. if segment == 9 then return self:FormatGold(g-s, false) else return self:FormatGold((g-s)/t*3600, false).."/Hr" end
  834. elseif tracking[segment] then
  835. -- Other currencies
  836. if tracking[segment].type == TYPE_CURRENCY or tracking[segment].type == TYPE_FRAGMENT then
  837. if self.db.profile.colorMaxReached
  838. and self.db.realm.chars[self.meidx]["maxReached"..segment] then
  839. color = COLOR_MAXREACHED
  840. else
  841. color = ""
  842. end
  843. local currencyInfo = C_CurrencyInfo.GetCurrencyInfo(segment)
  844. if currencyInfo ~= nil then
  845. amount = currencyInfo.quantity
  846. else
  847. amount = 0
  848. end
  849. elseif tracking[segment].type == TYPE_ITEM then amount = GetItemCount(segment,true) or 0 end
  850. return self:FormatCurrency(amount, (color or "")).." |T"..tracking[segment].icon..":0|t"
  851. else
  852. -- invalid
  853. return "???"
  854. end
  855. end
  856.  
  857. local result
  858. if self.db.profile.buttonFirst == "1" then result = MODNAME
  859. else
  860. result = getLabelSegment(self.db.profile.buttonFirst)
  861. if self.db.profile.buttonSecond > "1" then result = result.." / "..getLabelSegment(self.db.profile.buttonSecond) end
  862. if self.db.profile.buttonThird > "1" then result = result.." / "..getLabelSegment(self.db.profile.buttonThird) end
  863. if self.db.profile.buttonFourth > "1" then result = result.." / "..getLabelSegment(self.db.profile.buttonFourth) end
  864. end
  865. launcher.text = result
  866. end
  867.  
  868. function Currencyflow:SetupOptions()
  869.  
  870. -- Create configuration panel
  871. ConfigReg:RegisterOptionsTable( FULLNAME, self:OptionsMain() )
  872. ConfigReg:RegisterOptionsTable( FULLNAME.." - "..L["CFGPAGE_SECTIONS"], self:OptionsSections() )
  873. ConfigReg:RegisterOptionsTable( FULLNAME.." - "..L["CFGPAGE_COLUMNS"], self:OptionsColumns() )
  874. ConfigReg:RegisterOptionsTable( FULLNAME.." - "..L["CFGPAGE_CHARACTERS"], self:OptionsCharacters() )
  875. ConfigReg:RegisterOptionsTable( FULLNAME.." - "..L["CFGPAGE_PROFILES"], LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db) )
  876.  
  877. ConfigDlg:AddToBlizOptions( FULLNAME )
  878. ConfigDlg:AddToBlizOptions( FULLNAME.." - "..L["CFGPAGE_SECTIONS"], L["CFGPAGE_SECTIONS"], FULLNAME )
  879. ConfigDlg:AddToBlizOptions( FULLNAME.." - "..L["CFGPAGE_COLUMNS"], L["CFGPAGE_COLUMNS"], FULLNAME )
  880. ConfigDlg:AddToBlizOptions( FULLNAME.." - "..L["CFGPAGE_CHARACTERS"], L["CFGPAGE_CHARACTERS"], FULLNAME )
  881. ConfigDlg:AddToBlizOptions( FULLNAME.." - "..L["CFGPAGE_PROFILES"], L["CFGPAGE_PROFILES"], FULLNAME )
  882. end
  883.  
  884. function Currencyflow:OptionsMain()
  885. local buttonOptions = {
  886. ["001"] = L["CFGOPT_BTNNONE"],
  887. ["002"] = L["CFGOPT_BTNMONEY"],
  888. ["003"] = L["CFGOPT_BTNSESSIONTOTAL"],
  889. ["004"] = L["CFGOPT_BTNSESSIONPERHOUR"],
  890. ["005"] = L["CFGOPT_BTNTODAYTOTAL"],
  891. ["006"] = L["CFGOPT_BTNTODAYPERHOUR"],
  892. ["007"] = L["CFGOPT_BTNWEEKTOTAL"],
  893. ["008"] = L["CFGOPT_BTNWEEKPERHOUR"],
  894. ["009"] = L["CFGOPT_BTNMONTHTOTAL"],
  895. ["010"] = L["CFGOPT_BTNMONTHPERHOUR"],
  896. }
  897. for id,currency in pairs(tracking) do buttonOptions[tostring(id)] = format(L["CFGOPT_BTNOTHER"], currency.name) end
  898.  
  899. return {
  900. type = "group",
  901. desc = "General",
  902. get = function(key) return self.db.profile[key.arg] end,
  903. set = function(key, value) self.db.profile[key.arg] = value; Currencyflow:UpdateLabel() end,
  904. args = {
  905. header0 = {order = 0, name = L["CFGHDR_GENERAL"], type = "header"},
  906. colorMaxReached = {
  907. order = 1, name = L["CFG_COLORMAXREACHED"],
  908. type = "toggle", arg = "colorMaxReached",
  909. desc = L["CFGDESC_COLORMAXREACHED"],
  910. },
  911. header1 = {order = 5, name = L["CFGHDR_TOOLTIP"], type = "header"},
  912. cashFormat = {
  913. order = 10, name = L["CFGNAME_CASHFORMAT"],
  914. type = "select", arg = "cashFormat",
  915. values = { [1] = L["CFGOPT_CF_CONDENSED"], [2] = L["CFGOPT_CF_SHORT"], [3] = L["CFGOPT_CF_FULL"], [4] = L["CFGOPT_CF_COINS"] },
  916. desc = L["CFGDESC_CASHFORMAT"],
  917. },
  918. tipscale = {
  919. order = 20, name = L["CFGNAME_TTSCALE"],
  920. type = "range", arg = "tipscale",
  921. min = 0.5, max = 1.5, step = 0.05,
  922. desc = L["CFGDESC_TTSCALE"],
  923. },
  924. showCashDetail = {
  925. order = 30, name = L["CFGNAME_SHOWCASHDETAIL"],
  926. type = "toggle", arg = "showCashDetail",
  927. desc = L["CFGDESC_SHOWCASHDETAIL"],
  928. },
  929.  
  930. header2 = {order = 100, name = L["CFGHDR_BUTTON"], type = "header"},
  931. buttonFirst = {
  932. order = 110, name = L["CFGNAME_BUTTONFIRST"],
  933. type = "select", arg = "buttonFirst",
  934. values = buttonOptions,
  935. desc = L["CFGDESC_BUTTONFIRST"],
  936. },
  937. buttonSecond = {
  938. order = 120, name = L["CFGNAME_BUTTONSECOND"],
  939. type = "select", arg = "buttonSecond",
  940. values = buttonOptions,
  941. desc = L["CFGDESC_BUTTONSECOND"],
  942. },
  943. buttonThird = {
  944. order = 130, name = L["CFGNAME_BUTTONTHIRD"],
  945. type = "select", arg = "buttonThird",
  946. values = buttonOptions,
  947. desc = L["CFGDESC_BUTTONTHIRD"],
  948. },
  949. buttonFourth = {
  950. order = 140, name = L["CFGNAME_BUTTONFOURTH"],
  951. type = "select", arg = "buttonFourth",
  952. values = buttonOptions,
  953. desc = L["CFGDESC_BUTTONFOURTH"],
  954. },
  955. }
  956. }
  957. end
  958.  
  959. function Currencyflow:OptionsSections()
  960. local order = 1
  961. local options = {}
  962. local addSectionCheckbox = function(id, name)
  963. options[id] = {
  964. name = name,
  965. type = "toggle", order = order, arg = id,
  966. }
  967. order = order + 1
  968. end
  969.  
  970. addSectionCheckbox( "showThisSession", L["CFGNAME_THISSESSION"] )
  971.  
  972. options["header1"] = {name = L["CFGHDR_HISTORY"], type = "header", order = order}
  973. order = order + 1
  974.  
  975. addSectionCheckbox( "showTodaySelf", L["CFGNAME_TODAYSELF"] )
  976. addSectionCheckbox( "showTodayTotal", L["CFGNAME_TODAYTOTAL"] )
  977. addSectionCheckbox( "showYesterdaySelf", L["CFGNAME_YESTERDAYSELF"] )
  978. addSectionCheckbox( "showYesterdayTotal", L["CFGNAME_YESTERDAYTOTAL"] )
  979. addSectionCheckbox( "showThisWeekSelf", L["CFGNAME_WEEKSELF"] )
  980. addSectionCheckbox( "showThisWeekTotal", L["CFGNAME_WEEKTOTAL"] )
  981. addSectionCheckbox( "showThisMonthSelf", L["CFGNAME_MONTHSELF"] )
  982. addSectionCheckbox( "showThisMonthTotal", L["CFGNAME_MONTHTOTAL"] )
  983.  
  984. options["header2"] = {name = L["CFGHDR_OTHERCHARS"], type = "header", order = 100}
  985. options["showOtherChars"] = {
  986. name = L["CFGNAME_OTHERCHARS"],
  987. type = "toggle", order = 101, arg = "showOtherChars",
  988. desc = L["CFGDESC_OTHERCHARS"],
  989. }
  990. options["sortChars"] = {
  991. name = L["CFGNAME_SORTOTHERCHARS"],
  992. type = "select", order = 102, arg = "sortChars",
  993. desc = L["CFGDESC_SORTOTHERCHARS"],
  994. values = function()
  995. local val = {
  996. ["charname"] = L["CFGOPT_SORTNAME"],
  997. ["gold"] = L["NAME_MONEY"],
  998. }
  999. for id,currency in pairs(tracking) do
  1000. val[tostring(id)] = currency.name
  1001. end
  1002. return val
  1003. end,
  1004. disabled = function() return not self.db.profile.showOtherChars end,
  1005. }
  1006.  
  1007. options["sortDesc"] = {
  1008. name = L["CFGNAME_SORTDESC"],
  1009. type = "toggle", order = 103, arg = "sortDesc",
  1010. desc = L["CFGDESC_SORTDESC"],
  1011. disabled = function() return not self.db.profile.showOtherChars end,
  1012. }
  1013.  
  1014. options["header3"] = {name = L["CFGHDR_TOTALS"], type = "header", order = 200}
  1015.  
  1016. options["showTotals"] = {
  1017. name = L["CFGNAME_SHOWTOTALS"],
  1018. type = "toggle", order = 201, arg = "showTotals",
  1019. desc = L["CFGDESC_SHOWTOTALS"],
  1020. }
  1021.  
  1022. return {
  1023. type = "group",
  1024. get = function(key) return self.db.profile[key.arg] end,
  1025. set = function(key, value) self.db.profile[key.arg] = value; Currencyflow:UpdateLabel() end,
  1026. args = options
  1027. }
  1028. end
  1029.  
  1030. function Currencyflow:OptionsColumns()
  1031. local order = 1
  1032. local currencyColumns = {
  1033. header1 = {name = L["CFGHDR_GENERAL"], type = "header", order = 100},
  1034. showCashPerHour = {
  1035. name = L["CFGNAME_SHOWCASHPERHOUR"],
  1036. type = "toggle", order = 101, arg = "showCashPerHour",
  1037. desc = L["CFGDESC_SHOWCASHPERHOUR"],
  1038. },
  1039. }
  1040.  
  1041. local addColumn = function(id)
  1042. -- Retrieve item info at time of usage, to minimize risk of
  1043. -- item not being available
  1044. currencyColumns["showCurrency"..id] = {
  1045. name = function()
  1046. return "|T"..tracking[id].icon..":16|t "..tracking[id].name
  1047. end,
  1048. type = "toggle", order = order, arg = "showCurrency"..id,
  1049. desc = function() return format(L["CFGDESC_SHOWCOLUMNFOR"], tracking[id].name) end
  1050. }
  1051. order = order + 1
  1052. end
  1053.  
  1054.  
  1055. -- We have only one table with currencies, and we want to split them
  1056. -- into sections (PvE, PvP, Fragments, etc.). So we do this the hacky way.
  1057.  
  1058. -- Current Expansion PVE --
  1059. currencyColumns["header2"] = {name = "Dragonflight PvE", type = "header", order = 200}
  1060. order = 201
  1061. for k,v in pairs(currencies["current"]["pve"]) do
  1062. addColumn(k)
  1063. end
  1064.  
  1065. -- Current Expansion PVP
  1066. currencyColumns["header3"] = {name = "Dragonflight PvP", type = "header", order = 300}
  1067. order = 301
  1068. for k,v in pairs(currencies["current"]["pvp"]) do
  1069. addColumn(k)
  1070. end
  1071.  
  1072. -- Legacy --
  1073. currencyColumns["header4"] = {name = "Legacy", type = "header", order = 400}
  1074. order = 401
  1075. for k,v in pairs(currencies["legacy"]["pve"]) do
  1076. addColumn(k)
  1077. end
  1078. for k,v in pairs(currencies["legacy"]["pvp"]) do
  1079. addColumn(k)
  1080. end
  1081.  
  1082. -- Archeology Fragment --
  1083. currencyColumns["header5"] = {name = L["CFGHDR_ARCHFRAGMENTS"], type = "header", order = 600}
  1084. order = 601
  1085. for k,v in pairs(currencies["archaeology"]) do
  1086. addColumn(k)
  1087. end
  1088.  
  1089. -- Profession --
  1090. currencyColumns["header6"] = {name = "Profession", type = "header", order = 700}
  1091. order = 701
  1092. for k,v in pairs(currencies["profession"]) do
  1093. addColumn(k)
  1094. end
  1095.  
  1096. return {
  1097. type = "group",
  1098. get = function(key) return self.db.profile[key.arg] end,
  1099. set = function(key, value) self.db.profile[key.arg] = value; Currencyflow:UpdateLabel() end,
  1100. args = currencyColumns,
  1101. }
  1102. end
  1103.  
  1104. function Currencyflow:OptionsCharacters()
  1105. return {
  1106. type = "group",
  1107. args = {
  1108. header1 = { type = "description", name = L["CFGTXT_IGNOREDCHARS"], order = 10 },
  1109. ignoreChars = {
  1110. order = 11, type = "multiselect",
  1111. name = L["CFGNAME_IGNORECHARS"],
  1112. values = function()
  1113. local val = {}
  1114. for k,v in pairs(self.db.realm.chars) do val[k] = v.charname end
  1115. return val
  1116. end,
  1117. get = function(key,id) return self.db.realm.chars[id].ignore or false end,
  1118. set = function(key,id,value) self.db.realm.chars[id].ignore = value end,
  1119. },
  1120.  
  1121. header2 = { type = "header", name = L["CFGHDR_DELETECHAR"], order = 20 },
  1122. header3 = { type = "description", name = L["CFGTXT_DELETECHAR"], order = 21 },
  1123. deleteChars = {
  1124. order = 22, type = "select",
  1125. name = L["CFGHDR_DELETECHAR"],
  1126. desc = L["CFGDESC_DELETECHAR"],
  1127. values = function()
  1128. local val = {}
  1129. for k,v in pairs(self.db.realm.chars) do if k ~= self.meidx then val[k] = v.charname end end
  1130. return val
  1131. end,
  1132. get = function(key) return charToDelete end,
  1133. set = function(key, value) charToDelete = value end,
  1134. },
  1135. deleteConfirm = {
  1136. order = 23, type = "execute",
  1137. name = L["CFGNAME_DELETE"],
  1138. func = function()
  1139. if charToDelete ~= nil then self.db.realm.chars[charToDelete] = nil end
  1140. charToDelete = nil
  1141. end,
  1142. width = "half",
  1143. confirm = function()
  1144. return format(L["CFG_CONFIRMDELETE"], self.db.realm.chars[charToDelete].charname)
  1145. end,
  1146. disabled = function() return charToDelete == nil end,
  1147. }
  1148. }
  1149. }
  1150. end
  1151.  
  1152. -- This function tries to update the currencies list with client info
  1153. function Currencyflow:LoadCurrencies()
  1154. for id,currency in pairs(tracking) do
  1155. local name, icon
  1156. if currency.type == TYPE_CURRENCY then
  1157. local currencyInfo = C_CurrencyInfo.GetCurrencyInfo(id)
  1158. if currencyInfo ~= nil then
  1159. name = currencyInfo.name
  1160. icon = currencyInfo.iconFileID
  1161. end
  1162. elseif currency.type == TYPE_ITEM then
  1163. name, _, _, _, _, _, _, _, _, icon, _ = GetItemInfo(id)
  1164. elseif currency.type == TYPE_FRAGMENT then
  1165. local name, icon, _, _ = GetArchaeologyRaceInfo(currency.index)
  1166. -- Another dumb marvel of blizz consistency. When info
  1167. -- is not available, instead of returning nil or "",
  1168. -- this one puts "UNKNOWN" in the name.... sigh...
  1169. if icon == nil or icon == "" then
  1170. name = nil
  1171. end
  1172. end
  1173.  
  1174. if name ~= nil and name ~= "" then
  1175. currency.name = name
  1176. else
  1177. currency.name = "|cff999999"..currency.name.."|r"
  1178. end
  1179.  
  1180. if icon ~= nil and icon ~= "" then
  1181. currency.icon = icon
  1182. else
  1183. currency.icon = ICON_QM
  1184. end
  1185. end
  1186. end
  1187.  
  1188. function Currencyflow:OnEnable()
  1189. Notice("Currencyflow enabled")
  1190. self.savedTime = time()
  1191. self.today = self.GetToday()
  1192. self.session = {time = 0, gold = {gained = 0, spent = 0}}
  1193.  
  1194. self:LoadCurrencies()
  1195.  
  1196. -- Database, and initial layout
  1197. self.db = LibStub("AceDB-3.0"):New("Currencyflow_DB", { profile = {
  1198. cashFormat = 3,
  1199. tipscale = 1.0,
  1200. showCashDetail = true,
  1201. buttonFirst = "2",
  1202. buttonSecond = "1",
  1203. buttonThird = "1",
  1204. buttonFourth = "1",
  1205.  
  1206. showThisSession = true,
  1207. showTodaySelf = true,
  1208. showTodayTotal = true,
  1209. showYesterdaySelf = true,
  1210. showYesterdayTotal = true,
  1211. showThisWeekTotal = true,
  1212. showThisMonthTotal = true,
  1213. showOtherChars = true,
  1214. sortChars = "charname",
  1215. sortDesc = false,
  1216. showTotals = true,
  1217.  
  1218. showCashPerHour = true,
  1219. showCurrency392 = false, -- Honor points
  1220. showCurrency395 = false, -- Justice points
  1221. }}, "Default")
  1222.  
  1223. -- If there is a database, make sure it's up to date
  1224. if self.db.realm.chars then
  1225. self:UpdateDatabase()
  1226. else
  1227. -- If original Broker_Cashflow (not this addon!) db version 9 exists, import it.
  1228. cashflow = { db = LibStub("AceDB-3.0"):New("Cashflow_DB", { profile = {
  1229. cashFormat = 3,
  1230. tipscale = 1.0,
  1231. showCashDetail = true,
  1232. buttonFirst = "2",
  1233. buttonSecond = "1",
  1234. buttonThird = "1",
  1235. buttonFourth = "1",
  1236.  
  1237. showThisSession = true,
  1238. showTodaySelf = true,
  1239. showTodayTotal = true,
  1240. showYesterdaySelf = true,
  1241. showYesterdayTotal = true,
  1242. showThisWeekTotal = true,
  1243. showThisMonthTotal = true,
  1244. showOtherChars = true,
  1245. sortChars = "charname",
  1246. sortDesc = false,
  1247. showTotals = true,
  1248.  
  1249. showCashPerHour = true,
  1250. showCurrency392 = true, -- Honor points
  1251. showCurrency395 = true, -- Justice points
  1252. }}, "Default")}
  1253.  
  1254. -- Again, this is another addon, it's the original.
  1255. if cashflow.db.realm.version and cashflow.db.realm.version <= 9 then
  1256. -- We can only copy the characters for the current faction/realm.
  1257. Notice("Import database from Broker_Cashflow...")
  1258. realm_chars = deepcopy(cashflow.db.realm.chars)
  1259. self.db.realm.version = cashflow.db.realm.version
  1260. self.db.realm.chars = {}
  1261. for _,v in pairs(realm_chars) do
  1262. if v then
  1263. table.insert(self.db.realm.chars, deepcopy(v))
  1264. end
  1265. end
  1266. Notice("Import done.")
  1267.  
  1268. self:UpdateDatabase()
  1269. else
  1270. -- Create a skelleton structure
  1271. self.db.realm.version = 9
  1272. self.db.realm.chars = {}
  1273. end
  1274. end
  1275.  
  1276. -- Make sure I'm in the character list, and remember my position
  1277. self.meidx = -1
  1278.  
  1279. for k,v in pairs(self.db.realm.chars) do
  1280. if v.charname == UnitName("player") then self.meidx = k end
  1281. end
  1282. if self.meidx == -1 then
  1283. local _,classname = UnitClass("player")
  1284. table.insert(self.db.realm.chars, {
  1285. charname = UnitName("player"),
  1286. class = classname,
  1287. ignore = false,
  1288. history = {[self.today] = {["time"] = 0}}
  1289. })
  1290. self.meidx = #self.db.realm.chars
  1291. end
  1292.  
  1293. -- Remove old stuff
  1294. self:RemoveOldData()
  1295.  
  1296. -- Update current gold
  1297. self:db_UpdateCurrency( "gold", false )
  1298.  
  1299. -- Update other currencies
  1300. for id,currency in pairs(tracking) do self:db_UpdateCurrency( id, false ) end
  1301.  
  1302. -- Setup our configuration panel
  1303. self:SetupOptions()
  1304.  
  1305. -- Create some slashcommands
  1306. _G.SlashCmdList["CASHFLOW"] = function() InterfaceOptionsFrame_OpenToCategory(FULLNAME) end
  1307. _G["SLASH_CASHFLOW1"] = "/cashflow"
  1308. _G["SLASH_CASHFLOW2"] = "/cf"
  1309.  
  1310. -- self:RegisterEvent("CURRENCY_DISPLAY_UPDATE", "UpdateCurrencies")
  1311. self:RegisterEvent("PLAYER_LEAVING_WORLD", "UnregisterEvents")
  1312. self:RegisterEvent("PLAYER_ENTERING_WORLD", "RegisterEvents")
  1313.  
  1314. self:UpdateLabel()
  1315. end
  1316.  
  1317. function Currencyflow:UnregisterEvents()
  1318. self:UnregisterEvent("PLAYER_MONEY")
  1319. self:UnregisterEvent("PLAYER_TRADE_MONEY")
  1320. self:UnregisterEvent("TRADE_MONEY_CHANGED")
  1321. self:UnregisterEvent("SEND_MAIL_MONEY_CHANGED")
  1322. self:UnregisterEvent("SEND_MAIL_COD_CHANGED")
  1323. self:UnregisterEvent("MAIL_CLOSED")
  1324. self:UnregisterEvent("CURRENCY_DISPLAY_UPDATE")
  1325. end
  1326.  
  1327. function Currencyflow:RegisterEvents()
  1328. self:RegisterEvent("PLAYER_MONEY", "UpdateGold")
  1329. self:RegisterEvent("PLAYER_TRADE_MONEY", "UpdateGold")
  1330. self:RegisterEvent("TRADE_MONEY_CHANGED", "UpdateGold")
  1331. self:RegisterEvent("SEND_MAIL_MONEY_CHANGED", "UpdateGold")
  1332. self:RegisterEvent("SEND_MAIL_COD_CHANGED", "UpdateGold")
  1333. self:RegisterEvent("MAIL_CLOSED", "UpdateGold")
  1334. self:RegisterEvent("CURRENCY_DISPLAY_UPDATE", "UpdateCurrencies")
  1335. end
  1336.  
  1337. -- This will update the database format to the current version
  1338. function Currencyflow:UpdateDatabase()
  1339.  
  1340. -- If version is not set, we're "upgrading" to version 1
  1341. if not self.db.realm.version then self.db.realm.version = 1 end
  1342.  
  1343. -- Version 1 -> 2:
  1344. -- Migrate characters table from realm.chars[name] to
  1345. -- realm.chars[#].charname for easier sorting.
  1346. -- Gotta love how "flexible" lua is!
  1347. if self.db.realm.version == 1 then
  1348. Notice( "Updating database to version 2" )
  1349. local a = {}
  1350. for k,v in pairs(self.db.realm.chars) do table.insert(a, k) end
  1351. for _,k in pairs(a) do
  1352. self.db.realm.chars[k].charname = k
  1353. table.insert(self.db.realm.chars, self.db.realm.chars[k])
  1354. self.db.realm.chars[k] = nil
  1355. end
  1356. self.db.realm.version = 2
  1357. Notice( "Update complete" )
  1358. end
  1359.  
  1360. -- Version 2 -> 3:
  1361. -- Move history to character level
  1362. if self.db.realm.version == 2 then
  1363. Notice( "Updating database to version 3" )
  1364. for k,v in pairs(self.db.realm.chars) do
  1365. self.db.realm.chars[k].history = {[self.today] = {["time"] = 0}}
  1366. end
  1367. self.db.realm.history = nil
  1368. self.db.realm.version = 3
  1369. Notice( "Update complete" )
  1370. end
  1371.  
  1372. -- Version 3 -> 4:
  1373. -- Add "ignore" option to characters
  1374. if self.db.realm.version == 3 then
  1375. Notice( "Updating database to version 4" )
  1376. for k,v in pairs(self.db.realm.chars) do
  1377. self.db.realm.chars[k].ignore = false;
  1378. end
  1379. self.db.realm.version = 4
  1380. Notice( "Update complete" )
  1381. end
  1382.  
  1383. -- Version 4 -> 5:
  1384. -- Cataclysm!
  1385. if self.db.realm.version == 4 then
  1386. Notice( "Updating database to version 5" )
  1387. for k,v in pairs(self.db.realm.chars) do
  1388.  
  1389. -- Change ID of Champion's Seal (from item# 44990 to currency# 241)
  1390. if self.db.realm.chars[k][44990] then
  1391. self.db.realm.chars[k][241] = self.db.realm.chars[k][44990];
  1392. self.db.realm.chars[k][44990] = nil;
  1393. end
  1394.  
  1395. -- Clean out the old stuff that doesn't exist anymore
  1396. self.db.realm.chars[k][29434] = nil; -- Badge of Justice
  1397. self.db.realm.chars[k][47241] = nil; -- Emblem of Triumph
  1398. self.db.realm.chars[k][49426] = nil; -- Emblem of Frost
  1399. self.db.realm.chars[k][29434] = nil; -- Badge of Justice
  1400. self.db.realm.chars[k][20560] = nil; -- Alterac Valley MoH
  1401. self.db.realm.chars[k][20559] = nil; -- Arathi Basin MoH
  1402. self.db.realm.chars[k][29024] = nil; -- Eye of the Storm MoH
  1403. self.db.realm.chars[k][47395] = nil; -- Isle of Conquest MoH
  1404. self.db.realm.chars[k][42425] = nil; -- Strand o/t Anctients MoH
  1405. self.db.realm.chars[k][20558] = nil; -- Warsong Gulch MoH
  1406. self.db.realm.chars[k][43589] = nil; -- Wintergrasp MoH
  1407. self.db.realm.chars[k][37836] = nil; -- Venture Coin
  1408. self.db.realm.chars[k][43307] = nil; -- Stone Keeper's Shard
  1409. self.db.realm.chars[k][43307] = nil; -- Old Arena Points
  1410. self.db.realm.chars[k][43308] = nil; -- Old Honor Points
  1411.  
  1412. -- Reset honor, arena, and justice points, since old stuff has been converted
  1413. -- No use trying to calculate it. I tried, was very inacurate
  1414. self.db.realm.chars[k][392] = nil;
  1415. self.db.realm.chars[k][395] = nil;
  1416.  
  1417. -- Update preferences
  1418. self.db.profile["showCurrency241"] = self.db.profile["showCurrency44990"];
  1419. self.db.profile["showCurrency44990"] = nil;
  1420. self.db.profile["showCurrency47241"] = nil;
  1421. self.db.profile["showCurrency49426"] = nil;
  1422. self.db.profile["showCurrency29434"] = nil;
  1423. self.db.profile["showCurrency20560"] = nil;
  1424. self.db.profile["showCurrency20559"] = nil;
  1425. self.db.profile["showCurrency29024"] = nil;
  1426. self.db.profile["showCurrency47395"] = nil;
  1427. self.db.profile["showCurrency42425"] = nil;
  1428. self.db.profile["showCurrency20558"] = nil;
  1429. self.db.profile["showCurrency43589"] = nil;
  1430. self.db.profile["showCurrency37836"] = nil;
  1431. self.db.profile["showCurrency43307"] = nil;
  1432. self.db.profile["showCurrency43307"] = nil;
  1433. self.db.profile["showCurrency43308"] = nil;
  1434. end
  1435. self.db.realm.version = 5
  1436. Notice( "Update complete. Please cycle through all your characters to update current information." )
  1437. end
  1438.  
  1439. -- Version 5 -> 6:
  1440. -- Dal JC token & cooking award item -> currency
  1441. if self.db.realm.version == 5 then
  1442. Notice( "Updating database to version 6" )
  1443. for k,v in pairs(self.db.realm.chars) do
  1444. -- Change ID of Jewelcrafters token (from item# 41596 to currency# 61)
  1445. -- Change ID of Cooking award (from item# ... to currency# 81)
  1446. if self.db.realm.chars[k][41596] then
  1447. self.db.realm.chars[k][61] = self.db.realm.chars[k][41596];
  1448. self.db.realm.chars[k][41596] = nil;
  1449. end
  1450. if self.db.realm.chars[k][43016] then
  1451. self.db.realm.chars[k][81] = self.db.realm.chars[k][43016];
  1452. self.db.realm.chars[k][43016] = nil;
  1453. end
  1454. end
  1455. self.db.realm.version = 6
  1456. end
  1457.  
  1458. -- Version 6 -> 7:
  1459. -- Introduced buttonFirst and buttonSecond config options
  1460. if self.db.realm.version == 6 then
  1461. Notice( "Updating database to version 7" )
  1462. self.db.profile.buttonFirst = "2"
  1463. self.db.profile.buttonSecond = "1"
  1464. self.db.realm.version = 7
  1465. end
  1466.  
  1467. -- Version 7 -> 8:
  1468. -- Introduced buttonThird and buttonFourth config options
  1469. if self.db.realm.version == 7 then
  1470. Notice( "Updating database to version 8" )
  1471. self.db.profile.buttonThird = "1"
  1472. self.db.profile.buttonFourth = "1"
  1473. self.db.realm.version = 8
  1474. end
  1475.  
  1476. -- Version 8 -> 9:
  1477. -- History indexes changed (got rid of faulty offset calculation)
  1478. if self.db.realm.version == 8 then
  1479. Notice( "Updating database to version 9" )
  1480. for k,v in pairs(self.db.realm.chars) do
  1481. self.db.realm.chars[k].history = {[self.today] = {["time"] = 0}}
  1482. end
  1483. self.db.realm.version = 9
  1484. Notice( "Update complete" )
  1485. end
  1486.  
  1487. -- Version 9 -> 10:
  1488. -- Add boolean value indicating wether a currency's max is reached.
  1489. if self.db.realm.version == 9 then
  1490. Notice( "Updating database to version 10" )
  1491. for index, charinfo in pairs(self.db.realm.chars) do
  1492. for id, currency in pairs(tracking) do
  1493. if charinfo[id] and currency.type == TYPE_CURRENCY then
  1494. local currencyInfo = C_CurrencyInfo.GetCurrencyInfo(id)
  1495. if currencyInfo ~= nil then
  1496. weeklyMax = currencyInfo.maxWeeklyQuantity
  1497. totalMax = currencyInfo.maxQuantity
  1498. end
  1499. -- Since we can't get other character's weekly earnings, set default to false
  1500. -- Max values are 0 if unlimited
  1501. if weeklyMax > 0 then
  1502. charinfo["maxReached" .. id] = false
  1503. charinfo["lastWeekEarned" .. id] = nil -- Needed to get hold of weekly resets
  1504. elseif totalMax > 0 then charinfo["maxReached" .. id] = totalMax == charinfo[id]
  1505. end
  1506. elseif charinfo[id] and currency.type == TYPE_FRAGMENT then
  1507. -- Fragments can be collected up to 200
  1508. charinfo["maxReached" .. id] = charinfo[id] >= 200
  1509. end
  1510. end
  1511. end
  1512. self.db.realm.version = 10
  1513. Notice( "Update complete. For weekly maximums you need to log on each character." )
  1514. end
  1515. end
  1516.  
  1517. function Currencyflow:RemoveOldData()
  1518.  
  1519. local lastMonth = self.today - (HISTORY_DAYS - 1) -- Remove history over a month old
  1520.  
  1521. for day in pairs(self.db.realm.chars[self.meidx].history) do
  1522. if day < lastMonth then self.db.realm.chars[self.meidx].history[day] = nil end
  1523. end
  1524.  
  1525. self.db.realm.chars[self.meidx].history[self.today] = self.db.realm.chars[self.meidx].history[self.today] or {time = 0, gold = {gained = 0, spent = 0}}
  1526. end
  1527.  
  1528. function Currencyflow:UpdateGold()
  1529. self:db_UpdateCurrency("gold", true)
  1530. self:UpdateLabel()
  1531. end
  1532.  
  1533. function Currencyflow:UpdateCurrencies() -- Update all currencies
  1534. for id,currency in pairs(tracking) do self:db_UpdateCurrency(id, true) end
  1535. self:UpdateLabel()
  1536. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement