Skip to content

Commit

Permalink
0.3.0
Browse files Browse the repository at this point in the history
- add achievement points (wotlk)
  • Loading branch information
anzz1 authored Nov 4, 2022
1 parent b5f24b8 commit 6ed8ab8
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 25 deletions.
105 changes: 94 additions & 11 deletions Libs/LibClassicInspector/LibClassicInspector.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
for Classic/TBC/WOTLK
Requires: LibStub, CallbackHandler-1.0, LibDetours-1.0
Version: 3 (2022-10-21)
Version: 4 (2022-11-04)
--]]

Expand All @@ -19,7 +19,7 @@ assert(LibStub, "LibClassicInspector requires LibStub")
assert(LibStub:GetLibrary("CallbackHandler-1.0", true), "LibClassicInspector requires CallbackHandler-1.0")
assert(LibStub:GetLibrary("LibDetours-1.0", true), "LibClassicInspector requires LibDetours-1.0")

local lib, oldminor = LibStub:NewLibrary("LibClassicInspector", 3)
local lib, oldminor = LibStub:NewLibrary("LibClassicInspector", 4)

-- already loaded
if (not lib) then
Expand Down Expand Up @@ -2341,7 +2341,7 @@ local function getCacheUser2(guid)
local user = getCacheUser(guid)
if (user) then
local t = time()-INSPECTOR_REFRESH_DELAY
if ((not isClassic and user.talents.time < t) or user.inventory.time < t) then
if ((not isClassic and user.talents.time < t) or user.inventory.time < t or (isWotlk and user.achievements.time < t)) then
lib:DoInspect(guid)
end
else
Expand All @@ -2350,7 +2350,7 @@ local function getCacheUser2(guid)
return user
end

local function addCacheUser(guid, inventory, talents)
local function addCacheUser(guid, inventory, talents, achievements)
local user = {["guid"] = guid}
if(inventory) then
user.inventory = inventory
Expand All @@ -2362,6 +2362,11 @@ local function addCacheUser(guid, inventory, talents)
else
user.talents = {[1] = {[1] = {}, [2] = {}, [3] = {}}, [2] = {[1] = {}, [2] = {}, [3] = {}}, ["time"] = 0, ["active"] = 0}
end
if(achievements) then
user.achievements = achievements
else
user.achievements = {["time"] = 0}
end
if (not cache.first) then
cache.first = user
cache.last = user
Expand Down Expand Up @@ -2403,7 +2408,7 @@ local function cacheUserInventory(unit)
if(user) then
user.inventory = inventory
else
addCacheUser(guid, inventory, nil)
addCacheUser(guid, inventory, nil, nil)
end
-- Fire INVENTORY_READY(guid, isInspect[, unit]) callback
lib.callbacks:Fire("INVENTORY_READY", guid, true, unit)
Expand All @@ -2426,39 +2431,66 @@ local function cacheUserTalents(unit)
if(user) then
user.talents = talents
else
addCacheUser(guid, nil, talents)
addCacheUser(guid, nil, talents, nil)
end
-- Fire TALENTS_READY(guid, isInspect[, unit]) callback
lib.callbacks:Fire("TALENTS_READY", guid, true, unit)
end

local function cacheUserAchievements(guid)
local achievements = {["time"] = time(), ["t_pts"] = GetComparisonAchievementPoints()}
local user = getCacheUser(guid)
if(user) then
user.achievements = achievements
else
addCacheUser(guid, nil, nil, achievements)
end
end

local function tryInspect(unit, refresh)
if (lib:CanInspect(unit)) then
local guid = UnitGUID(unit)
local user = getCacheUser(guid)
local ret = false
if (user) then
if (refresh) then
local t = time()-INSPECTOR_REFRESH_DELAY
if ((not isClassic and user.talents.time < t) or user.inventory.time < t) then
NotifyInspect(unit)
return true
ret = true
end
if (isWotlk and user.achievements.time < t) then
if (not AchievementFrame or not AchievementFrame.isComparison) then
ClearAchievementComparisonUnit()
SetAchievementComparisonUnit(unit)
ret = true
end
end
else
if ((not isClassic and user.talents.time == 0) or user.inventory.time == 0) then
NotifyInspect(unit)
return true
ret = true
end
if (isWotlk and user.achievements.time == 0) then
if (not AchievementFrame or not AchievementFrame.isComparison) then
ClearAchievementComparisonUnit()
SetAchievementComparisonUnit(unit)
ret = true
end
end
end
else
NotifyInspect(unit)
if (isWotlk and (not AchievementFrame or not AchievementFrame.isComparison)) then
ClearAchievementComparisonUnit()
SetAchievementComparisonUnit(unit)
end
return true
end
end
return false
return ret
end


function f:INSPECT_READY(event, guid)
if (not guid) then
return
Expand Down Expand Up @@ -2510,7 +2542,7 @@ function f:CHAT_MSG_ADDON(event, prefix, text, channelType, senderFullName, send
if(user) then
user.talents = talents
else
addCacheUser(guid, nil, talents)
addCacheUser(guid, nil, talents, nil)
end
-- Fire TALENTS_READY(guid, isInspect[, unit]) callback
lib.callbacks:Fire("TALENTS_READY", guid, false, nil)
Expand Down Expand Up @@ -2548,6 +2580,24 @@ end
function f:ACTIVE_TALENT_GROUP_CHANGED()
infoChanged = true
end
if (isWotlk) then
function f:INSPECT_ACHIEVEMENT_READY(event, guid, ...)
if (guid and GUIDIsPlayer(guid)) then
cacheUserAchievements(guid)
-- Fire ACHIEVEMENTS_READY(guid, isInspect) callback
lib.callbacks:Fire("ACHIEVEMENTS_READY", guid, true)
end
if (AchievementFrame and AchievementFrame.isComparison and AchievementFrameComparison) then
AchievementFrameComparison_OnEvent(AchievementFrameComparison, event, guid, ...)
end
end
if (not AchievementFrame or not AchievementFrameComparison) then
AchievementFrame_LoadUI()
end
if (AchievementFrameComparison) then
AchievementFrameComparison:UnregisterEvent("INSPECT_ACHIEVEMENT_READY")
end
end

f:SetScript("OnEvent", function(self, event, ...)
return self[event](self, event, ...)
Expand All @@ -2564,6 +2614,7 @@ f:RegisterEvent("CHARACTER_POINTS_CHANGED")
if (isWotlk) then
f:RegisterEvent("PLAYER_TALENT_UPDATE")
f:RegisterEvent("ACTIVE_TALENT_GROUP_CHANGED")
f:RegisterEvent("INSPECT_ACHIEVEMENT_READY")
end
C_ChatInfo.RegisterAddonMessagePrefix(C_PREFIX)

Expand Down Expand Up @@ -2762,6 +2813,10 @@ function lib:DoInspect(unitorguid)
if (lib:CanInspect(unit)) then
if (time() >= nextInspectTime) then
NotifyInspect(unit)
if (isWotlk and (not AchievementFrame or not AchievementFrame.isComparison)) then
ClearAchievementComparisonUnit()
SetAchievementComparisonUnit(unit)
end
return 1
else
local c = #queue
Expand Down Expand Up @@ -3292,3 +3347,31 @@ function lib:PlayerGUIDToUnitToken(guid)
return nil
end


--------------------------------------------------------------------------
-- ClassicInspector:GetTotalAchievementPoints(unitorguid)
--
-- Parameters
-- @string unitorguid - unit token or guid
--
-- Returns
-- @number total_points - total achievement points
--
function lib:GetTotalAchievementPoints(unitorguid)
if (not isWotlk) then
return nil
end
local guid = getPlayerGUID(unitorguid)
if (not guid) then
return nil
end
if (guid == UnitGUID("player")) then
return GetTotalAchievementPoints()
else
local user = getCacheUser2(guid)
if (user and user.achievements.time > 0) then
return user.achievements["t_pts"]
end
end
return nil
end
6 changes: 5 additions & 1 deletion Locale/enUS.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ TACOTIP_LOCALE = {
["Pet"] = "Pet",
["Target"] = "Target",
["None"] = "None",
["Self"] = "Target",
["Self"] = "Self",
["You"] = "You",
["Talents"] = "Talents",
["Style"] = "Style",
Expand Down Expand Up @@ -93,11 +93,15 @@ TACOTIP_LOCALE = {
["Anchor to mouse only in WorldFrame\nSkips raid / party frames"] = "Anchor to mouse only in WorldFrame\nSkips raid / party frames",
["Anchor Spells to Mouse"] = "Anchor Spells to Mouse",
["Anchor spell tooltips to mouse cursor"] = "Anchor spell tooltips to mouse cursor",
["Show Achievement Points"] = "Show Achievement Points",
["Show total achievement points in tooltips"] = "Show total achievement points in tooltips",
["TEXT_OPT_DESC"] = "Better player tooltips - class colors, talents/specialization,\n gearscore, guild ranks",
["TEXT_OPT_UBERTIPS"] = "Show enhanced tooltips for spells (\"UberTooltips\")",
["TEXT_HELP_MOVER_SHOWN"] = "Mover is shown. Drag the yellow dot to move the tooltip. Middle-Click to change anchor. Right-Click to save.",
["TEXT_HELP_MOVER_SAVED"] = "Custom tooltip position saved. Mover hidden. Type '/tacotip custom' to show mover again.",
["TEXT_HELP_ANCHOR"] = "Usage: /tacotip anchor ANCHOR. Valid ANCHOR values are TOPLEFT/TOPRIGHT/BOTTOMLEFT/BOTTOMRIGHT/CENTER.",
["TEXT_HELP_WELCOME"] = "by kebabstorm loaded. Safe travels!",
["TEXT_HELP_FIRST_LOGIN"] = "Type /tacotip to set up your preferences.",
["TEXT_DLG_CUSTOM_POS_CONFIRM"] = "\nDo you want to save custom tooltip position or reset back to default?\n\n",
["FORMAT_GUILD_RANK_1"] = "%s of <%s>",
["CHARACTER_FRAME_GS_TITLE_FONT"] = "Fonts\\FRIZQT__.TTF",
Expand Down
2 changes: 1 addition & 1 deletion TacoTip.toc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## Interface: 11304
## Version: 0.2.9
## Version: 0.3.0
## Title: TacoTip
## Notes: TacoTip (GearScore & Talents)
## Author: kebabstorm
Expand Down
27 changes: 27 additions & 0 deletions main.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

local addOnName = ...
local addOnVersion = GetAddOnMetadata(addOnName, "Version") or "0.0.1"

local clientVersionString = GetBuildInfo()
local clientBuildMajor = string.byte(clientVersionString, 1)
Expand All @@ -26,6 +27,7 @@ local isPawnLoaded = PawnClassicLastUpdatedVersion and PawnClassicLastUpdatedVer
local HORDE_ICON = "|TInterface\\TargetingFrame\\UI-PVP-HORDE:16:16:-2:0:64:64:0:38:0:38|t"
local ALLIANCE_ICON = "|TInterface\\TargetingFrame\\UI-PVP-ALLIANCE:16:16:-2:0:64:64:0:38:0:38|t"
local PVP_FLAG_ICON = "|TInterface\\GossipFrame\\BattleMasterGossipIcon:0|t"
local ACHIEVEMENT_ICON = "|TInterface\\AchievementFrame\\UI-Achievement-TinyShield:18:18:0:0:20:20:0:12.5:0:12.5|t"

local POWERBAR_UPDATE_RATE = 0.2

Expand Down Expand Up @@ -266,6 +268,16 @@ GameTooltip:HookScript("OnTooltipSetUnit", function(self)
if (miniText ~= "") then
tinsert(linesToAdd, {miniText, 1, 1, 1})
end
if (CI:IsWotlk() and TacoTipConfig.show_achievement_points) then
local achi_pts = CI:GetTotalAchievementPoints(guid)
if (achi_pts) then
if (wide_style) then
tinsert(linesToAdd, {ACHIEVEMENT_ICON.." "..achi_pts, " ", 1, 1, 1, 1, 1, 1})
else
tinsert(linesToAdd, {ACHIEVEMENT_ICON.." "..achi_pts, 1, 1, 1})
end
end
end
end
end

Expand Down Expand Up @@ -732,6 +744,21 @@ local function onEvent(self, event, ...)
if (CharacterModelFrame and PaperDollFrame) then
TT:RefreshCharacterFrame()
end
local first_login = (TacoTipConfig.conf_version ~= addOnVersion)
if (first_login) then
for k,v in pairs(TT:GetDefaults()) do
if (TacoTipConfig[k] == nil) then
TacoTipConfig[k] = v
end
end
TacoTipConfig.conf_version = addOnVersion
end
CAfter(3, function()
print("|cff59f0dcTacoTip v"..addOnVersion.." "..L["TEXT_HELP_WELCOME"])
if (first_login) then
print("|cff59f0dcTacoTip:|r "..L["TEXT_HELP_FIRST_LOGIN"])
end
end)
end
elseif (event == "UPDATE_MOUSEOVER_UNIT") then
if (GameTooltip:GetUnit()) then
Expand Down
40 changes: 28 additions & 12 deletions options.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,8 @@ local HORDE_ICON = "|TInterface\\TargetingFrame\\UI-PVP-HORDE:16:16:-2:0:64:64:0
local ALLIANCE_ICON = "|TInterface\\TargetingFrame\\UI-PVP-ALLIANCE:16:16:-2:0:64:64:0:38:0:38|t"
local PVP_FLAG_ICON = "|TInterface\\GossipFrame\\BattleMasterGossipIcon:0|t"

local function resetCfg()
if (TacoTipDragButton) then
TacoTipDragButton:_Disable()
end
if (TacoTipConfig and TacoTipConfig.instant_fade) then
TT.frame:UnregisterEvent("UPDATE_MOUSEOVER_UNIT")
Detours:DetourUnhook(TT, GameTooltip, "FadeOut")
end
TacoTipConfig = {
function TT:GetDefaults()
return {
color_class = true,
show_titles = true,
show_guild_name = true,
Expand All @@ -51,7 +44,7 @@ local function resetCfg()
hide_in_combat = false,
show_item_level = true,
tip_style = 2,
show_target = false,
show_target = true,
show_pawn_player = false,
show_team = false,
show_pvp_icon = false,
Expand All @@ -70,10 +63,23 @@ local function resetCfg()
character_gs_offset_y = 0,
character_ilvl_offset_x = 0,
character_ilvl_offset_y = 0,
unlock_info_position = false
unlock_info_position = false,
conf_version = addOnVersion,
show_achievement_points = false
--custom_pos = nil,
--custom_anchor = nil,
}
end

local function resetCfg()
if (TacoTipDragButton) then
TacoTipDragButton:_Disable()
end
if (TacoTipConfig and TacoTipConfig.instant_fade) then
TT.frame:UnregisterEvent("UPDATE_MOUSEOVER_UNIT")
Detours:DetourUnhook(TT, GameTooltip, "FadeOut")
end
TacoTipConfig = TT:GetDefaults()
if (PersonalGearScore) then
PersonalGearScore:RefreshPosition()
end
Expand Down Expand Up @@ -656,7 +662,16 @@ frame:SetScript("OnShow", function(frame)
function(self, value)
TacoTipConfig.anchor_mouse_spells = value
end)
options.anchorMouseSpells:SetPoint("TOPLEFT", extraText, "BOTTOMLEFT", 188, -88)
options.anchorMouseSpells:SetPoint("TOPLEFT", extraText, "BOTTOMLEFT", 188, -88)

options.showAchievementPoints = newCheckbox(
"ShowAchievementPoints",
L["Show Achievement Points"],
L["Show total achievement points in tooltips"],
function(self, value)
TacoTipConfig.show_achievement_points = value
end)
options.showAchievementPoints:SetPoint("TOPLEFT", extraText, "BOTTOMLEFT", 188, -116)


local styleText = frame:CreateFontString(nil, "ARTWORK", "GameFontNormal")
Expand Down Expand Up @@ -739,6 +754,7 @@ frame:SetScript("OnShow", function(frame)
options.anchorMouseSpells:SetChecked(TacoTipConfig.anchor_mouse_spells)
options.lockCharacterInfoPosition:SetChecked(not TacoTipConfig.unlock_info_position)
options.lockCharacterInfoPosition:SetDisabled(not (TacoTipConfig.show_gs_character or TacoTipConfig.show_avg_ilvl))
options.showAchievementPoints:SetChecked(TacoTipConfig.show_achievement_points)
end

frame.Refresh = function()
Expand Down

0 comments on commit 6ed8ab8

Please sign in to comment.