Skip to content

Commit

Permalink
Fixed /keystone command; Fixed issues with nicknames
Browse files Browse the repository at this point in the history
  • Loading branch information
Tercioo committed May 19, 2022
1 parent 026aa22 commit c006675
Show file tree
Hide file tree
Showing 10 changed files with 249 additions and 63 deletions.
22 changes: 22 additions & 0 deletions Libs/DF/fw.lua
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,28 @@ function DF:trim (s)
return from > #s and "" or s:match(".*%S", from)
end

--truncated revoming at a maximum of 10 character from the string
function DF:TruncateTextSafe(fontString, maxWidth)
local text = fontString:GetText()
local numIterations = 10

while (fontString:GetStringWidth() > maxWidth) do
text = strsub(text, 1, #text-1)
fontString:SetText(text)
if (#text <= 1) then
break
end

numIterations = numIterations - 1
if (numIterations <= 0) then
break
end
end

text = DF:CleanTruncateUTF8String(text)
fontString:SetText(text)
end

function DF:TruncateText (fontString, maxWidth)
local text = fontString:GetText()

Expand Down
88 changes: 60 additions & 28 deletions Libs/LibOpenRaid/LibOpenRaid.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Code Rules:
- Public callbacks are callbacks registered by an external addon.
Change Log:
- added "KeystoneWipe" callback
- finished keystone info, see docs
- added interrupts to cooldown tracker, new filter: "interrupt"
- after encounter_end cooldowns now check for cooldowns reset.
Expand Down Expand Up @@ -45,7 +46,7 @@ if (WOW_PROJECT_ID ~= WOW_PROJECT_MAINLINE) then
end

local major = "LibOpenRaid-1.0"
local CONST_LIB_VERSION = 37
local CONST_LIB_VERSION = 39
LIB_OPEN_RAID_CAN_LOAD = false

--declae the library within the LibStub
Expand Down Expand Up @@ -153,17 +154,13 @@ LIB_OPEN_RAID_CAN_LOAD = false
function openRaidLib.commHandler.OnReceiveComm(self, event, prefix, text, channel, sender, target, zoneChannelID, localID, name, instanceID)
--check if the data belong to us
if (prefix == CONST_COMM_PREFIX) then
--check if the lib can receive comms
if (not openRaidLib.IsCommAllowed()) then
return
end

sender = Ambiguate(sender, "none")

--don't receive comms from the player it self
local playerName = UnitName("player")
if (playerName == sender) then
--return
return
end

local data = text
Expand All @@ -179,6 +176,13 @@ LIB_OPEN_RAID_CAN_LOAD = false
return
end

--if this is isn't a keystone data comm, check if the lib can receive comms
if (dataTypePrefix ~= CONST_COMM_KEYSTONE_DATA_PREFIX and dataTypePrefix ~= CONST_COMM_KEYSTONE_DATAREQUEST_PREFIX) then
if (not openRaidLib.IsCommAllowed()) then
return
end
end

--get the table with functions regitered for this type of data
local callbackTable = openRaidLib.commHandler.commCallback[dataTypePrefix]
if (not callbackTable) then
Expand Down Expand Up @@ -361,6 +365,7 @@ LIB_OPEN_RAID_CAN_LOAD = false
"TalentUpdate",
"PvPTalentUpdate",
"KeystoneUpdate",
"KeystoneWipe",
}

--save build the table to avoid lose registered events on older versions
Expand Down Expand Up @@ -1967,6 +1972,25 @@ openRaidLib.commHandler.RegisterComm(CONST_COMM_COOLDOWNFULLLIST_PREFIX, openRai
end
end

function openRaidLib.WipeKeystoneData()
wipe(openRaidLib.KeystoneInfoManager.KeystoneData)
--trigger public callback
openRaidLib.publicCallback.TriggerCallback("KeystoneWipe", openRaidLib.KeystoneInfoManager.KeystoneData)

--keystones are only available on retail
if (not checkClientVersion("retail")) then
return
end

--generate keystone info for the player
local unitName = UnitName("player")
local keystoneInfo = openRaidLib.KeystoneInfoManager.GetKeystoneInfo(unitName, true)
openRaidLib.KeystoneInfoManager.UpdatePlayerKeystoneInfo(keystoneInfo)

openRaidLib.publicCallback.TriggerCallback("KeystoneUpdate", unitName, keystoneInfo, openRaidLib.KeystoneInfoManager.KeystoneData)
return true
end

--> manager constructor
openRaidLib.KeystoneInfoManager = {
--structure:
Expand Down Expand Up @@ -2000,23 +2024,17 @@ openRaidLib.commHandler.RegisterComm(CONST_COMM_COOLDOWNFULLLIST_PREFIX, openRai
end
end

local updateKeystoneInfo = function(keystoneInfo, level, mapID, challengeMapID, classID, rating, mythicPlusMapID)
keystoneInfo.level = level or C_MythicPlus.GetOwnedKeystoneLevel() or 0
keystoneInfo.mapID = mapID or C_MythicPlus.GetOwnedKeystoneMapID() or 0
keystoneInfo.mythicPlusMapID = mythicPlusMapID or 0

if (not mythicPlusMapID and not mapID and keystoneInfo.mapID ~= 0) then
keystoneInfo.mythicPlusMapID = getMythicPlusMapID() or 0
end

keystoneInfo.challengeMapID = challengeMapID or C_MythicPlus.GetOwnedKeystoneChallengeMapID() or 0
function openRaidLib.KeystoneInfoManager.UpdatePlayerKeystoneInfo(keystoneInfo)
keystoneInfo.level = C_MythicPlus.GetOwnedKeystoneLevel() or 0
keystoneInfo.mapID = C_MythicPlus.GetOwnedKeystoneMapID() or 0
keystoneInfo.mythicPlusMapID = getMythicPlusMapID() or 0
keystoneInfo.challengeMapID = C_MythicPlus.GetOwnedKeystoneChallengeMapID() or 0

local _, _, playerClassID = UnitClass("player")
keystoneInfo.classID = classID or playerClassID
keystoneInfo.classID = playerClassID

local ratingSummary = C_PlayerInfo.GetPlayerMythicPlusRatingSummary("player")
local currentRating = ratingSummary and ratingSummary.currentSeasonScore or 0
keystoneInfo.rating = rating or currentRating
keystoneInfo.rating = ratingSummary and ratingSummary.currentSeasonScore or 0
end

function openRaidLib.KeystoneInfoManager.GetAllKeystonesInfo()
Expand All @@ -2031,14 +2049,14 @@ openRaidLib.commHandler.RegisterComm(CONST_COMM_COOLDOWNFULLLIST_PREFIX, openRai
openRaidLib.TCopy(keystoneInfo, keystoneTablePrototype)
openRaidLib.KeystoneInfoManager.KeystoneData[unitName] = keystoneInfo
end

updateKeystoneInfo(keystoneInfo)
return keystoneInfo
end

local getKeystoneInfoToComm = function()
local playerName = UnitName("player")
local keystoneInfo = openRaidLib.KeystoneInfoManager.GetKeystoneInfo(playerName, true)
openRaidLib.KeystoneInfoManager.UpdatePlayerKeystoneInfo(keystoneInfo)

local dataToSend = CONST_COMM_KEYSTONE_DATA_PREFIX .. "," .. keystoneInfo.level .. "," .. keystoneInfo.mapID .. "," .. keystoneInfo.challengeMapID .. "," .. keystoneInfo.classID .. "," .. keystoneInfo.rating .. "," .. keystoneInfo.mythicPlusMapID
return dataToSend
end
Expand All @@ -2055,20 +2073,23 @@ openRaidLib.commHandler.RegisterComm(CONST_COMM_COOLDOWNFULLLIST_PREFIX, openRai
diagnosticComm("SendPlayerKeystoneInfoToGuild| " .. dataToSend) --debug
end

--when a request data is received, only send the data to party and guild
--sending stuff to raid need to be called my the application with 'openRaidLib.RequestKeystoneDataFromRaid()'
function openRaidLib.KeystoneInfoManager.OnReceiveRequestData()
if (not checkClientVersion("retail")) then
return
end

--update the information about the key stone the player has
openRaidLib.KeystoneInfoManager.GetKeystoneInfo(UnitName("player"), true)
local keystoneInfo = openRaidLib.KeystoneInfoManager.GetKeystoneInfo(UnitName("player"), true)
openRaidLib.KeystoneInfoManager.UpdatePlayerKeystoneInfo(keystoneInfo)

if (IsInGroup() and not IsInRaid()) then
openRaidLib.Schedules.NewUniqueTimer(1 + math.random(1, 3), openRaidLib.KeystoneInfoManager.SendPlayerKeystoneInfoToParty, "KeystoneInfoManager", "sendKeystoneInfoToParty_Schedule")
openRaidLib.Schedules.NewUniqueTimer(0.1, openRaidLib.KeystoneInfoManager.SendPlayerKeystoneInfoToParty, "KeystoneInfoManager", "sendKeystoneInfoToParty_Schedule")
end

if (IsInGuild()) then
openRaidLib.Schedules.NewUniqueTimer(1 + math.random(1, 3), openRaidLib.KeystoneInfoManager.SendPlayerKeystoneInfoToGuild, "KeystoneInfoManager", "sendKeystoneInfoToGuild_Schedule")
openRaidLib.Schedules.NewUniqueTimer(math.random(0, 3) + math.random(), openRaidLib.KeystoneInfoManager.SendPlayerKeystoneInfoToGuild, "KeystoneInfoManager", "sendKeystoneInfoToGuild_Schedule")
end
end
openRaidLib.commHandler.RegisterComm(CONST_COMM_KEYSTONE_DATAREQUEST_PREFIX, openRaidLib.KeystoneInfoManager.OnReceiveRequestData)
Expand All @@ -2087,7 +2108,12 @@ openRaidLib.commHandler.RegisterComm(CONST_COMM_COOLDOWNFULLLIST_PREFIX, openRai

if (level and mapID and challengeMapID and classID and rating and mythicPlusMapID) then
local keystoneInfo = openRaidLib.KeystoneInfoManager.GetKeystoneInfo(unitName, true)
updateKeystoneInfo(keystoneInfo, level, mapID, challengeMapID, classID, rating, mythicPlusMapID)
keystoneInfo.level = level
keystoneInfo.mapID = mapID
keystoneInfo.mythicPlusMapID = mythicPlusMapID
keystoneInfo.challengeMapID = challengeMapID
keystoneInfo.classID = classID
keystoneInfo.rating = rating

--trigger public callback
openRaidLib.publicCallback.TriggerCallback("KeystoneUpdate", unitName, keystoneInfo, openRaidLib.KeystoneInfoManager.KeystoneData)
Expand All @@ -2104,9 +2130,11 @@ openRaidLib.commHandler.RegisterComm(CONST_COMM_COOLDOWNFULLLIST_PREFIX, openRai

if (IsInGroup() and not IsInRaid()) then
--update the information about the key stone the player has
openRaidLib.KeystoneInfoManager.GetKeystoneInfo(UnitName("player"), true)
--send to the group which kstone the player has
openRaidLib.Schedules.NewUniqueTimer(1 + math.random(1, 3), openRaidLib.KeystoneInfoManager.SendPlayerKeystoneInfoToParty, "KeystoneInfoManager", "sendKeystoneInfoToParty_Schedule")
local keystoneInfo = openRaidLib.KeystoneInfoManager.GetKeystoneInfo(UnitName("player"), true)
openRaidLib.KeystoneInfoManager.UpdatePlayerKeystoneInfo(keystoneInfo)

--send to the group which keystone the player has
openRaidLib.Schedules.NewUniqueTimer(1 + math.random(0, 2) + math.random(), openRaidLib.KeystoneInfoManager.SendPlayerKeystoneInfoToParty, "KeystoneInfoManager", "sendKeystoneInfoToParty_Schedule")
end
end

Expand All @@ -2121,6 +2149,8 @@ openRaidLib.commHandler.RegisterComm(CONST_COMM_COOLDOWNFULLLIST_PREFIX, openRai
--trigger public callback
local unitName = UnitName("player")
local keystoneInfo = openRaidLib.KeystoneInfoManager.GetKeystoneInfo(unitName, true)
openRaidLib.KeystoneInfoManager.UpdatePlayerKeystoneInfo(keystoneInfo)

openRaidLib.publicCallback.TriggerCallback("KeystoneUpdate", unitName, keystoneInfo, openRaidLib.KeystoneInfoManager.KeystoneData)
end

Expand All @@ -2135,6 +2165,8 @@ openRaidLib.commHandler.RegisterComm(CONST_COMM_COOLDOWNFULLLIST_PREFIX, openRai
--trigger public callback
local unitName = UnitName("player")
local keystoneInfo = openRaidLib.KeystoneInfoManager.GetKeystoneInfo(unitName, true)
openRaidLib.KeystoneInfoManager.UpdatePlayerKeystoneInfo(keystoneInfo)

openRaidLib.publicCallback.TriggerCallback("KeystoneUpdate", unitName, keystoneInfo, openRaidLib.KeystoneInfoManager.KeystoneData)
end

Expand Down
13 changes: 12 additions & 1 deletion Libs/LibOpenRaid/docs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -417,4 +417,15 @@ function MyAddonObject.OnKeystoneUpdate(unitName, keystoneInfo, allKeystoneInfo)
end

--registering the callback:
openRaidLib.RegisterCallback(MyAddonObject, "KeystoneUpdate", "OnKeystoneUpdate")
openRaidLib.RegisterCallback(MyAddonObject, "KeystoneUpdate", "OnKeystoneUpdate")

===================================================================================================================================
"KeystoneWipe": triggered after the call openRaidLib.WipeKeystoneData()
===================================================================================================================================

function MyAddonObject.OnKeystoneUpdate(allKeystoneInfo)
print("no keystone data:", next(allKeystoneInfo) == nil)
end

--registering the callback:
openRaidLib.RegisterCallback(MyAddonObject, "KeystoneWipe", "OnKeystoneWipe")
4 changes: 2 additions & 2 deletions boot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

local version, build, date, tocversion = GetBuildInfo()

_detalhes.build_counter = 9814
_detalhes.alpha_build_counter = 9814 --if this is higher than the regular counter, use it instead
_detalhes.build_counter = 9815
_detalhes.alpha_build_counter = 9815 --if this is higher than the regular counter, use it instead
_detalhes.bcc_counter = 37
_detalhes.dont_open_news = true
_detalhes.game_version = version
Expand Down
24 changes: 16 additions & 8 deletions classes/class_damage.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2480,16 +2480,24 @@ end
for lineId = 1, self:GetNumLinesShown() do
local thisLine = self:GetLine(lineId)

local playerName = thisLine.lineText1
local text2 = thisLine.lineText2
local text3 = thisLine.lineText3
local text4 = thisLine.lineText4
--check if there's something showing in this line
if (thisLine.minha_tabela) then
local playerNameFontString = thisLine.lineText1
local text2 = thisLine.lineText2
local text3 = thisLine.lineText3
local text4 = thisLine.lineText4

local totalWidth = text2:GetStringWidth() + text3:GetStringWidth() + text4:GetStringWidth()
totalWidth = totalWidth + 50
local totalWidth = text2:GetStringWidth() + text3:GetStringWidth() + text4:GetStringWidth()
totalWidth = totalWidth + 40 - self.fontstrings_text_limit_offset

DetailsFramework:TruncateText(playerName, self.cached_bar_width - totalWidth) --this avoid truncated strings with ...
--playerName:SetWidth(self.cached_bar_width - totalWidth)
DetailsFramework:TruncateTextSafe(playerNameFontString, self.cached_bar_width - totalWidth) --this avoid truncated strings with ...

--these commented lines are for to create a cache and store the name already truncated there to safe performance
--local truncatedName = playerNameFontString:GetText()
--local actorObject = thisLine.minha_tabela
--actorObject.name_cached = truncatedName
--actorObject.name_cached_time = GetTime()
end
end
end
end
Expand Down
34 changes: 24 additions & 10 deletions classes/container_actors.lua
Original file line number Diff line number Diff line change
Expand Up @@ -213,23 +213,37 @@
end
end

--check if the nickname fit some minimal rules to be presented to other players
local checkValidNickname = function(nickname, playerName)
if (nickname and type(nickname) == "string") then
if (nickname == "") then
return playerName

elseif (nickname:find(" ")) then
return playerName

--elseif(#nickname > 14) then --cannot check for size as other alphabets uses 2 or 4 bytes to represent letters
-- return playerName
end
else
return playerName
end

--remove scapes
nickname = nickname:gsub("|","")
return nickname
end

--> read the actor flag
local read_actor_flag = function(actorObject, dono_do_pet, serial, flag, nome, container_type)

if (flag) then
--> this is player actor
if (_bit_band (flag, OBJECT_TYPE_PLAYER) ~= 0) then
if (not _detalhes.ignore_nicktag) then
actorObject.displayName = _detalhes:GetNickname (nome, false, true) --> serial, default, silent
if (actorObject.displayName and actorObject.displayName ~= "") then
--don't display empty nicknames
if (actorObject.displayName:find(" ")) then
if (_detalhes.remove_realm_from_name) then
actorObject.displayName = nome:gsub (("%-.*"), "")
else
actorObject.displayName = nome
end
end
actorObject.displayName = checkValidNickname(Details:GetNickname(nome, false, true), nome) --defaults to player name
if (_detalhes.remove_realm_from_name) then
actorObject.displayName = actorObject.displayName:gsub(("%-.*"), "")
end
end

Expand Down
1 change: 1 addition & 0 deletions classes/include_instance.lua
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ _detalhes.instance_defaults = {
--use one fontstring for each value in the lines, e.g. one fontstring to damage done, another fontstring to dps and another to percent amount
use_multi_fontstrings = true,
use_auto_align_multi_fontstrings = true,
fontstrings_text_limit_offset = -10,
fontstrings_text4_anchor = 0,
fontstrings_text3_anchor = 38,
fontstrings_text2_anchor = 73,
Expand Down
17 changes: 17 additions & 0 deletions frames/window_options2_sections.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1580,6 +1580,23 @@ do
desc = Loc ["STRING_OPTIONS_ALIGNED_TEXT_COLUMNS_AUTOALIGN_DESC"],
},


{--name size offset
type = "range",
get = function() return tonumber(currentInstance.fontstrings_text_limit_offset) end,
set = function (self, fixedparam, value)
editInstanceSetting(currentInstance, "fontstrings_text_limit_offset", value)
editInstanceSetting(currentInstance, "InstanceRefreshRows")
Details.options.RefreshInstances(currentInstance)
afterUpdate()
end,
min = -30,
max = 30,
step = 1,
name = "Unit Name Size Offset",
desc = "Unit Name Size Offset",
},

{--lineText2 (left, usuali is the 'done' amount)
type = "range",
get = function() return tonumber (currentInstance.fontstrings_text2_anchor) end,
Expand Down
Loading

0 comments on commit c006675

Please sign in to comment.