From a91cdb494c039d99b3771c40ea15dab0fa09ff18 Mon Sep 17 00:00:00 2001 From: Renaud Ellypse Parize Date: Thu, 26 Jan 2017 23:48:27 +0100 Subject: [PATCH 01/32] Fixed issue when shift-clicking links that are not player links Ticket #61 https://wow.curseforge.com/projects/total-rp-3/issues/61 --- totalRP3/modules/chatframe/chatframe.lua | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/totalRP3/modules/chatframe/chatframe.lua b/totalRP3/modules/chatframe/chatframe.lua index fbb181365..ccf3431c6 100644 --- a/totalRP3/modules/chatframe/chatframe.lua +++ b/totalRP3/modules/chatframe/chatframe.lua @@ -508,9 +508,15 @@ function hooking() -- We can replace the name inserted by the complete RP name of the player if we have it. hooksecurefunc("ChatEdit_InsertLink", function(name) + -- If we didn't get a name at all then we have nothing to do here + if not name then return end; + -- Do not modify the name inserted if the option is not enabled or if the ALT key is down. if not configInsertFullRPName() or IsAltKeyDown() then return end; + -- Do not modify the name if we don't know that character + if not (IsUnitIDKnown(name) or name == Globals.player_id) then return end; + local activeChatFrame = ChatEdit_GetActiveWindow(); if activeChatFrame and activeChatFrame.chatFrame and activeChatFrame.chatFrame.editBox then local editBox = activeChatFrame.chatFrame.editBox; @@ -521,6 +527,7 @@ function hooking() local textBefore = currentText:sub(1, currentCursorPosition - name:len() - 1); local textAfter = currentText:sub(currentCursorPosition+1 ); + -- TODO There's a new function in our API to easily get the full RP name using name method on some branch, use it once it's merged -- Retreive the info for the character and the naming method to use local info = getCharacterInfoTab(name); local nameMethod = configNameMethod(); From 8a6a0dc696da35912a25f933e6d108c59b593ce3 Mon Sep 17 00:00:00 2001 From: "Renaud \"Ellypse\" Parize" Date: Fri, 27 Jan 2017 11:11:35 +0100 Subject: [PATCH 02/32] Fixing companion purge (WIP) --- .../register/characters/register_main.lua | 21 +++++++++++++++++++ .../companions/register_companions_main.lua | 8 ++++--- .../modules/register/main/register_list.lua | 13 +++++++++--- 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/totalRP3/modules/register/characters/register_main.lua b/totalRP3/modules/register/characters/register_main.lua index 30b890506..620649175 100644 --- a/totalRP3/modules/register/characters/register_main.lua +++ b/totalRP3/modules/register/characters/register_main.lua @@ -299,6 +299,16 @@ end TRP3_API.register.getUnitIDCurrentProfile = getUnitIDCurrentProfile; +local function getCharacterInfoTab(unitID) + if unitID == Globals.player_id then + return get("player"); + elseif isUnitIDKnown(unitID) then + return getUnitIDCurrentProfile(unitID) or {}; + end + return {}; +end +TRP3_API.register.getCharacterInfoTab = getCharacterInfoTab; + --- Raises error if unknown unitID function TRP3_API.register.shouldUpdateInformation(unitID, infoType, version) --- Raises error if unit hasn't profile ID or no profile exists @@ -475,9 +485,13 @@ local function cleanupPlayerRelations() end local function cleanupProfiles() + local getAssociatedCompanions = TRP3_API.companions.register.getAssociationsForProfile; + local deleteCompanionProfile = TRP3_API.companions.register.deleteProfile; + if type(getConfigValue("register_auto_purge_mode")) ~= "number" then return; end + log("Purging profiles older than %s day(s)", getConfigValue("register_auto_purge_mode") / 86400); -- First, get a tab with all profileID with which we have a relation local relatedProfileIDs = {}; for _, profile in pairs(TRP3_API.profile.getProfiles()) do @@ -494,6 +508,13 @@ local function cleanupProfiles() end log("Profiles to purge: " .. tsize(profilesToPurge)); for _, profileID in pairs(profilesToPurge) do + -- We also need to purge the companions associated to that profile, so we retrieve them + local associatedCompanions = getAssociatedCompanions(profileID); + log("Purging " .. tsize(associatedCompanions) .. " companions associated to profile " .. profileID); + -- Delete every companion profiles + for _, companionProfileID in pairs(associatedCompanions) do + deleteCompanionProfile(companionProfileID, true); + end deleteProfile(profileID, true); end end diff --git a/totalRP3/modules/register/companions/register_companions_main.lua b/totalRP3/modules/register/companions/register_companions_main.lua index e3bfb8b67..3ecd3ce84 100644 --- a/totalRP3/modules/register/companions/register_companions_main.lua +++ b/totalRP3/modules/register/companions/register_companions_main.lua @@ -174,7 +174,7 @@ TRP3_API.companions.player.editProfile = editProfile; -- Delete a profile -- If the deleted profile is the currently selected one, assign the default profile -local function deleteProfile(profileID) +local function deleteProfile(profileID, silently) assert(playerCompanions[profileID], "Unknown profile: "..tostring(profileID)); local profileName = playerCompanions[profileID]["profileName"]; for companionID, _ in pairs(playerCompanions[profileID].links or EMPTY) do @@ -182,8 +182,10 @@ local function deleteProfile(profileID) end wipe(playerCompanions[profileID]); playerCompanions[profileID] = nil; - displayMessage(loc("PR_PROFILE_DELETED"):format(Utils.str.color("g")..profileName.."|r")); - Events.fireEvent(Events.REGISTER_PROFILE_DELETED, profileID); + if not silently then + displayMessage(loc("PR_PROFILE_DELETED"):format(Utils.str.color("g")..profileName.."|r")); + Events.fireEvent(Events.REGISTER_PROFILE_DELETED, profileID); + end end TRP3_API.companions.player.deleteProfile = deleteProfile; diff --git a/totalRP3/modules/register/main/register_list.lua b/totalRP3/modules/register/main/register_list.lua index 17b98f1b0..0d85ae40a 100644 --- a/totalRP3/modules/register/main/register_list.lua +++ b/totalRP3/modules/register/main/register_list.lua @@ -420,7 +420,7 @@ local function onCharactersActionSelected(value, button) else showConfirmPopup(loc("REG_LIST_ACTIONS_PURGE_IGNORE_C"):format(loc("REG_LIST_ACTIONS_PURGE_COUNT"):format(#profilesToPurge + #characterToPurge)), function() for _, profileID in pairs(profilesToPurge) do - deleteProfile(profileID); + deleteProfile(profileID, true); end for _, unitID in pairs(characterToPurge) do deleteCharacter(unitID); @@ -627,19 +627,26 @@ local function getCompanionLines() return companionLines; end +local DO_NOT_FIRE_EVENTS = true; local function onCompanionActionSelected(value, button) if value == "purge_all" then local list = getCompanionProfiles(); showConfirmPopup(loc("REG_LIST_ACTIONS_PURGE_ALL_COMP_C"):format(tsize(list)), function() for profileID, _ in pairs(list) do - deleteCompanionProfile(profileID); + -- We delete the companion profile without fire events to prevent UI freeze + deleteCompanionProfile(profileID, DO_NOT_FIRE_EVENTS); end + -- We then fire the event once every profile we needed to delete has been deleted + Events.fireEvent(Events.REGISTER_PROFILE_DELETED); end); elseif value == "actions_delete" then showConfirmPopup(loc("REG_LIST_ACTIONS_MASS_REMOVE_C"):format(tsize(selectedIDs)), function() for profileID, _ in pairs(selectedIDs) do - deleteCompanionProfile(profileID); + -- We delete the companion profile without fire events to prevent UI freeze + deleteCompanionProfile(profileID, DO_NOT_FIRE_EVENTS); end + -- We then fire the event once every profile we needed to delete has been deleted + Events.fireEvent(Events.REGISTER_PROFILE_DELETED); end); end end From 7e472926b3b0d16e1e65d6bafb68729472e63064 Mon Sep 17 00:00:00 2001 From: "Renaud \"Ellypse\" Parize" Date: Fri, 27 Jan 2017 11:13:43 +0100 Subject: [PATCH 03/32] Fixed in increase color contrast option always on We were checking the wrong option to increase color contrast in tooltip. Ticket #51 https://wow.curseforge.com/projects/total-rp-3/issues/51 --- totalRP3/modules/register/main/register_tooltip.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/totalRP3/modules/register/main/register_tooltip.lua b/totalRP3/modules/register/main/register_tooltip.lua index 1e530d66c..ba95b07cd 100644 --- a/totalRP3/modules/register/main/register_tooltip.lua +++ b/totalRP3/modules/register/main/register_tooltip.lua @@ -385,7 +385,7 @@ local function writeTooltipForCharacter(targetID, originalTexts, targetType) -- Only use custom colors if the option is enabled and if we have one - if getConfigValue(CONFIG_CHARACT_COLOR) and info.characteristics and info.characteristics.CH then + if getConfigValue(CONFIG_CHARACT_CONTRAST) and info.characteristics and info.characteristics.CH then r, g, b = Utils.color.hexaToFloat(info.characteristics.CH); local lighten = lightenColorUntilItIsReadable({ r = r, g = g, b = b }); From ab1b17782e50e3d8472411c7c83967fad7f92c64 Mon Sep 17 00:00:00 2001 From: "Renaud \"Ellypse\" Parize" Date: Fri, 27 Jan 2017 11:18:53 +0100 Subject: [PATCH 04/32] A lot of refactoring on the chat system (WIP) Fix Lua error with WIM Ticket #55 https://wow.curseforge.com/projects/total-rp-3/issues/55 Non-customized colored names in Prat Ticket #50 https://wow.curseforge.com/projects/total-rp-3/issues/50 --- totalRP3/core/impl/utils.lua | 64 ++++++++ totalRP3/modules/chatframe/WIM.lua | 39 ++--- totalRP3/modules/chatframe/chatframe.lua | 190 +++++++++-------------- totalRP3/modules/chatframe/prat.lua | 80 ++++------ 4 files changed, 179 insertions(+), 194 deletions(-) diff --git a/totalRP3/core/impl/utils.lua b/totalRP3/core/impl/utils.lua index 50cb6a09f..460c2265e 100644 --- a/totalRP3/core/impl/utils.lua +++ b/totalRP3/core/impl/utils.lua @@ -46,6 +46,7 @@ local UNKNOWNOBJECT = UNKNOWNOBJECT; local SetPortraitToTexture = SetPortraitToTexture; local getZoneText, getSubZoneText = GetZoneText, GetSubZoneText; local PlaySoundKitID, select, StopSound = PlaySoundKitID, select, StopSound; +local CreateColor = CreateColor; function Utils.pcall(func, ...) if func then @@ -487,6 +488,69 @@ Utils.color.lightenColorUntilItIsReadable = function(textColor) return textColor; end +--- Returns a Color using Blizzard's ColorMixin for a given hexadecimal color code +-- @see ColorMixin +function Utils.color.getColorFromHexadecimalCode(hexadecimalCode) + local r, g, b = Utils.color.hexaToFloat(hexadecimalCode); + return CreateColor(r, g, b, 1); +end + +--- Returns a Color using Blizzard's ColorMixin for a given class (english, not localized) +-- @see ColorMixin +function Utils.color.getClassColor(englishClass) + assert(englishClass, "No class given to TRP3_API.utils.getClassColor(englishClass).") + assert(RAID_CLASS_COLORS[englishClass], string.format("Unknown class %s", englishClass)); + + local classColorTable = RAID_CLASS_COLORS[englishClass]; + return CreateColor(classColorTable.r, classColorTable.g, classColorTable.b, 1); +end + +function Utils.color.getUnitClassColor(unitID) + local unitClass = Utils.str.GetClass(unitID); + return Utils.color.getClassColor(unitClass); +end + +local CONFIG_CHARACT_CONTRAST = "tooltip_char_contrast"; + +--- Returns the custom color defined in the unitID's profile as a Color using Blizzard's ColorMixing. +-- @param unitID +-- @return Color +-- @see ColorMixin +function Utils.color.getUnitCustomColor(unitID) + local info = TRP3_API.register.getCharacterInfoTab(unitID); + + if info.characteristics and info.characteristics.CH then + -- If we do have a custom color code (in hexa) defined, get the RGB float values + local r, g, b = Utils.color.hexaToFloat(info.characteristics.CH); + local characterColors = {r = r, g = g, b = b}; + + if TRP3_API.configuration.getValue(CONFIG_CHARACT_CONTRAST) then + -- If we have enabled the option to increase contrast we light up the color + characterColors = Utils.color.lightenColorUntilItIsReadable({ + r = characterColors.r, + g = characterColors.g, + b = characterColors.b + }); + end + + return CreateColor(characterColors.r, characterColors.g, characterColors.b, 1); + end +end + +function Utils.color.getChatColorForChannel(channel) + local chatInfo = ChatTypeInfo[channel]; + return CreateColor(chatInfo.r, chatInfo.g, chatInfo.b, 1); +end + +--- Returns a Color using Blizzard's ColorMixin for a given unit ID. +-- It will use the custom color if one is know, ligth it up if the setting is enabled, or default to class color +-- @param unitID +-- @see ColorMixin +-- +function Utils.color.getUnitColor(unitID) + return Utils.color.getUnitCustomColor(unitID) or Utils.color.getUnitClassColor(unitID); +end + --*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* -- Math --*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* diff --git a/totalRP3/modules/chatframe/WIM.lua b/totalRP3/modules/chatframe/WIM.lua index 3321fb079..514f0329d 100644 --- a/totalRP3/modules/chatframe/WIM.lua +++ b/totalRP3/modules/chatframe/WIM.lua @@ -1,17 +1,14 @@ local function onStart() -- Stop right here if WIM is not installed if not WIM then return false, "WIM not found." end + + -- Import Total RP 3 functions + local customGetColoredNameWithCustomFallbackFunction = TRP3_API.utils.customGetColoredNameWithCustomFallbackFunction; + local playerID = TRP3_API.globals.player_id; + local getUnitColor = TRP3_API.utils.color.getUnitColor; -- Get unit color (custom or default) + local getFullnameForUnitUsingChatMethod = TRP3_API.chat.getFullnameForUnitUsingChatMethod; -- Get full name using settings - local TRP3CustomGetColoredNameWithCustomFallbackFunction = TRP3_API.utils.customGetColoredNameWithCustomFallbackFunction; - local get = TRP3_API.profile.getData; - local getColoredName = TRP3_API.chat.getColoredName; - local getFullName = TRP3_API.chat.getFullnameUsingChatMethod; - local numberToHexa = TRP3_API.utils.color.numberToHexa; - local _G = _G; - - setfenv(1, WIM); - - local classes = constants.classes; + local classes = WIM.constants.classes; -- We store WIM's custom GetColoredName function as we will send it as a fallback to TRP3's GetColoredName function local WIMsGetColoredNameFunction = classes.GetColoredNameByChatEvent; @@ -19,25 +16,19 @@ local function onStart() -- Replace WIM's GetColoredName function by our own to display RP names and fallback to WIM's GetColoredName function -- if we couldn't handle the name ourselves. classes.GetColoredNameByChatEvent = function(...) - return TRP3CustomGetColoredNameWithCustomFallbackFunction(WIMsGetColoredNameFunction, ...); + return customGetColoredNameWithCustomFallbackFunction(WIMsGetColoredNameFunction, ...); end; -- Replace WIM's GetMyColoredName to display our full RP name classes.GetMyColoredName = function() - local name = _G.UnitName("player"); - local info = get("player"); - name = getFullName(info, name); - local color = getColoredName(info); - if not color then - local class, englishClass = _G.UnitClass("player"); - local classColorTable = _G.RAID_CLASS_COLORS[englishClass]; - color = numberToHexa(classColorTable.r * 255) .. numberToHexa(classColorTable.g * 255) .. numberToHexa(classColorTable.b * 255) - end - return ("|cff%s%s|r"):format(color, name); + local name = getFullnameForUnitUsingChatMethod(playerID); + local color = getUnitColor(playerID); + return color:WrapTextInColorCode(name); end end -local MODULE_STRUCTURE = { +-- Register a Total RP 3 module that can be disabled in the settings +TRP3_API.module.registerModule({ ["name"] = "WIM support", ["description"] = "Add support for the WoW Instant Messenger (WIM) add-on.", ["version"] = 1.000, @@ -47,6 +38,4 @@ local MODULE_STRUCTURE = { ["requiredDeps"] = { {"trp3_chatframes", 1.100}, } -}; - -TRP3_API.module.registerModule(MODULE_STRUCTURE); \ No newline at end of file +}); \ No newline at end of file diff --git a/totalRP3/modules/chatframe/chatframe.lua b/totalRP3/modules/chatframe/chatframe.lua index ccf3431c6..c1c206d68 100644 --- a/totalRP3/modules/chatframe/chatframe.lua +++ b/totalRP3/modules/chatframe/chatframe.lua @@ -25,7 +25,6 @@ local get = TRP3_API.profile.getData; local IsUnitIDKnown = TRP3_API.register.isUnitIDKnown; local getUnitIDCurrentProfile, isIDIgnored = TRP3_API.register.getUnitIDCurrentProfile, TRP3_API.register.isIDIgnored; local strsub, strlen, format, _G, pairs, tinsert, time, strtrim = strsub, strlen, format, _G, pairs, tinsert, time, strtrim; -local GetPlayerInfoByGUID, RemoveExtraSpaces, GetTime, PlaySound = GetPlayerInfoByGUID, RemoveExtraSpaces, GetTime, PlaySound; local getConfigValue, registerConfigKey, registerHandler = TRP3_API.configuration.getValue, TRP3_API.configuration.registerConfigKey, TRP3_API.configuration.registerHandler; local ChatFrame_RemoveMessageEventFilter, ChatFrame_AddMessageEventFilter = ChatFrame_RemoveMessageEventFilter, ChatFrame_AddMessageEventFilter; local ChatEdit_GetActiveWindow, IsAltKeyDown = ChatEdit_GetActiveWindow, IsAltKeyDown; @@ -33,6 +32,10 @@ local oldChatFrameOnEvent; local handleCharacterMessage, hooking; local tContains = tContains; local assert = assert; +local getUnitColor = Utils.color.getUnitColor; +local getChatColorForChannel = Utils.color.getChatColorForChannel; +local getColorFromHexadecimalCode = Utils.color.getColorFromHexadecimalCode; +local select = select; TRP3_API.chat = {}; @@ -42,10 +45,11 @@ TRP3_API.chat = {}; local POSSIBLE_CHANNELS; --- Used by other modules like our own Prat or WIM modules to get the list of channels we handle -function TRP3_API.chat.getPossibleChannels() - return POSSIBLE_CHANNELS; -end; +-- Used by other modules like our own Prat or WIM modules to check if a channel is handled by Total RP 3 +local function isChannelHandled(channel) + return tContains(POSSIBLE_CHANNELS, channel); +end +TRP3_API.chat.isChannelHandled = isChannelHandled; local CONFIG_NAME_METHOD = "chat_name"; local CONFIG_NAME_COLOR = "chat_color"; @@ -76,6 +80,7 @@ end local function configIsChannelUsed(channel) return getConfigValue(CONFIG_USAGE .. channel); end +TRP3_API.chat.configIsChannelUsed = configIsChannelUsed; local function configDoHandleNPCTalk() return getConfigValue(CONFIG_NPC_TALK); @@ -102,7 +107,7 @@ local function configOOCDetectionPattern() end local function configOOCDetectionColor() - return getConfigValue(CONFIG_OOC_COLOR); + return getColorFromHexadecimalCode(getConfigValue(CONFIG_OOC_COLOR)); end local function configInsertFullRPName() @@ -141,6 +146,7 @@ local function createConfigPage() local OOC_PATTERNS = { {"( OOC )", "(%(.-%))"}, {"(( OOC ))", "(%(%(.-%)%))"}, + {"(OOC) + (( OOC )) ", "(%(+[^%)]+%)+)"}, } -- Build configuration page @@ -261,17 +267,6 @@ end -- Utils --*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* -local function getCharacterClassColor(chatInfo, event, text, characterID, language, arg4, arg5, arg6, arg7, arg8, arg9, arg10, messageID, GUID) - local color; - if ( chatInfo and chatInfo.colorNameByClass and GUID ) then - local localizedClass, englishClass = GetPlayerInfoByGUID(GUID); - if englishClass and RAID_CLASS_COLORS[englishClass] then - local classColorTable = RAID_CLASS_COLORS[englishClass]; - return ("|cff%.2x%.2x%.2x"):format(classColorTable.r*255, classColorTable.g*255, classColorTable.b*255); - end - end -end - local function getCharacterInfoTab(unitID) if unitID == Globals.player_id then return get("player"); @@ -285,19 +280,22 @@ end -- Emote and OOC detection --*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* -local function detectEmoteAndOOC(type, message) +local function detectEmoteAndOOC(message) + if configDoEmoteDetection() and message:find(configEmoteDetectionPattern()) then - local chatInfo = ChatTypeInfo["EMOTE"]; - local color = ("|cff%.2x%.2x%.2x"):format(chatInfo.r*255, chatInfo.g*255, chatInfo.b*255); + local chatColor = getChatColorForChannel("EMOTE"); message = message:gsub(configEmoteDetectionPattern(), function(content) - return color .. content .. "|r"; + return chatColor:WrapTextInColorCode(content); end); end + if configDoOOCDetection() and message:find(configOOCDetectionPattern()) then + local OOCColor = configOOCDetectionColor(); message = message:gsub(configOOCDetectionPattern(), function(content) - return "|cff" .. configOOCDetectionColor() .. content .. "|r"; + return OOCColor:WrapTextInColorCode(content); end); end + return message; end @@ -305,30 +303,24 @@ end -- NPC talk detection --*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* -local NPC_TALK_CHANNELS = { - CHAT_MSG_SAY = 1, CHAT_MSG_EMOTE = 1, CHAT_MSG_PARTY = 1, CHAT_MSG_RAID = 1, CHAT_MSG_PARTY_LEADER = 1, CHAT_MSG_RAID_LEADER = 1 -}; local NPC_TALK_PATTERNS; -local stringInColorCode = "|cff%02x%02x%02x%s|r"; -local bracketedColoredStringCode = "|cff%02x%02x%02x[%s]|r" - local function handleNPCEmote(message) -- Go through all talk types - for TALK_TYPE, TALK_CHANNEL in pairs(NPC_TALK_PATTERNS) do - if message:find(TALK_TYPE) then - local chatInfo = ChatTypeInfo[TALK_CHANNEL]; - local name = message:sub(4, message:find(TALK_TYPE) - 2); -- Isolate the name + for talkType, talkChannel in pairs(NPC_TALK_PATTERNS) do + if message:find(talkType) then + local chatColor = getChatColorForChannel(talkChannel); + local name = message:sub(4, message:find(talkType) - 2); -- Isolate the name local content = message:sub(name:len() + 5); - return string.format(bracketedColoredStringCode, chatInfo.r*255, chatInfo.g*255, chatInfo.b*255, name), string.format(stringInColorCode, chatInfo.r*255, chatInfo.g*255, chatInfo.b*255, content); + return chatColor:WrapTextInColorCodecontent(name), chatColor:WrapTextInColorCodecontent(content); end end -- If none was found, we default to emote - local chatInfo = ChatTypeInfo["MONSTER_EMOTE"]; - return string.format("|cff%02x%02x%02x%s|r", chatInfo.r*255, chatInfo.g*255, chatInfo.b*255, message:sub(4)), " "; + local chatColor = getChatColorForChannel("MONSTER_EMOTE"); + return chatColor:WrapTextInColorCode(message:sub(4)), " "; end --*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* @@ -339,9 +331,9 @@ end -- So we are able to flag messages as needing their player name's to be modified local npcMessageId, npcMessageName, ownershipNameId; -function handleCharacterMessage(chatFrame, event, ...) +function handleCharacterMessage(_, event, message, ...) - local message, characterID, language, arg4, arg5, arg6, arg7, arg8, arg9, arg10, messageID, arg12, arg13, arg14, arg15, arg16 = ...; + local messageID = select(11, ...); -- Detect NPC talk pattern on authorized channels if event == "CHAT_MSG_EMOTE" then @@ -370,20 +362,22 @@ function handleCharacterMessage(chatFrame, event, ...) end -- Colorize emote and OOC - message = detectEmoteAndOOC(type, message); + message = detectEmoteAndOOC(message); - return false, message, characterID, language, arg4, arg5, arg6, arg7, arg8, arg9, arg10, messageID, arg12, arg13, arg14, arg15, arg16; + return false, message, ...; end local function getFullnameUsingChatMethod(info, characterName) local nameMethod = configNameMethod(); + if nameMethod ~= 1 then -- TRP3 names local characteristics = info.characteristics or {}; - if characteristics.FN then + + if characteristics.FN then -- Use custom name if defined characterName = characteristics.FN; end - if nameMethod == 4 and characteristics.TI then + if nameMethod == 4 and characteristics.TI then -- With short title in front of the name characterName = characteristics.TI .. " " .. characterName; end @@ -391,24 +385,16 @@ local function getFullnameUsingChatMethod(info, characterName) characterName = characterName .. " " .. characteristics.LN; end end + return characterName; end TRP3_API.chat.getFullnameUsingChatMethod = getFullnameUsingChatMethod; -local function getColoredName(info) - local characterColor; - if configShowNameCustomColors() and info.characteristics and info.characteristics.CH then - local color = info.characteristics.CH; - if getConfigValue(CONFIG_INCREASE_CONTRAST) then - local r, g, b = Utils.color.hexaToFloat(color); - local ligthenColor = Utils.color.lightenColorUntilItIsReadable({r = r, g = g, b = b}); - color = Utils.color.numberToHexa(ligthenColor.r * 255) .. Utils.color.numberToHexa(ligthenColor.g * 255) .. Utils.color.numberToHexa(ligthenColor.b * 255); - end - characterColor = color; - end - return characterColor; +local function getFullnameForUnitUsingChatMethod(unitID, characterName) + local info = getCharacterInfoTab(unitID); + return getFullnameUsingChatMethod(info, characterName); end -TRP3_API.chat.getColoredName = getColoredName; +TRP3_API.chat.getFullnameForUnitUsingChatMethod = getFullnameForUnitUsingChatMethod; -- I have renamed this function from beta 1 to beta 2 because Saelora commented on its name :P local defaultGetColoredNameFunction = GetColoredName; @@ -422,67 +408,52 @@ function Utils.customGetColoredNameWithCustomFallbackFunction(fallback, event, . assert(fallback, "Trying to call TRP3_API.utils.customGetColoredNameWithCustomFallbackFunction(fallback, event, ...) without a fallback function!") -- Do not change stuff if the is disabled for this channel, use the default function - if not tContains(POSSIBLE_CHANNELS, event) or not configIsChannelUsed(event) then return fallback(event, ...) end; + if not isChannelHandled(event) or not configIsChannelUsed(event) then return fallback(event, ...) end; local characterName, characterColor; - local message, characterID, language, arg4, arg5, arg6, arg7, arg8, arg9, arg10, messageID, arg12, arg13, arg14, arg15, arg16 = ...; - local character, realm = unitIDToInfo(characterID); - if not realm then -- Thanks Blizzard to not always send a full character ID - realm = Globals.player_realm_id; - if realm == nil then - -- if realm is nil (i.e. globals haven't been set yet) just run the vanilla version of the code to prevent errors. - return fallback(event, ...); - end - end - characterID = unitInfoToID(character, realm); - local info = getCharacterInfoTab(characterID); - - -- Get chat type and configuration - local type = strsub(event, 10); - local chatInfo = ChatTypeInfo[type]; + local _, unitID, _, _, _, _, _, _, _, _, messageID = ...; + -- We don't have a unit ID for this message (WTF? Some other add-on must be doing some weird shit again…) + -- Bail out, let the fallback function handle that shit. + if not unitID then return fallback(event, ...) end; + -- Check if this message ID was flagged as containing NPC chat -- If it does we use the NPC name that was saved before. if npcMessageId == messageID then return npcMessageName or UNKNOWN; end - -- WHISPER and WHISPER_INFORM have the same chat info - if ( strsub(type, 1, 7) == "WHISPER" ) then - chatInfo = ChatTypeInfo["WHISPER"]; + -- Extract the character name and realm from the unit ID + local character, realm = unitIDToInfo(unitID); + if not realm then + -- if realm is nil (i.e. globals haven't been set yet) just run the vanilla version of the code to prevent errors. + return fallback(event, ...); end + -- Make sure we have a unitID formatted as "Player-Realm" + unitID = unitInfoToID(character, realm); - -- Character name + -- Character name is without the server name is they are from the same realm, or with the realm attached if they aren't if realm == Globals.player_realm_id then characterName = character; else - characterName = characterID; + characterName = unitID; end - characterName = getFullnameUsingChatMethod(info, character); + -- Retrieve the character full name and their color + characterName = getFullnameForUnitUsingChatMethod(unitID, character); + local color = getUnitColor(unitID); + + -- And wrap the name inside the color's code + local coloredName = color:WrapTextInColorCode(characterName); -- Check if this message was flagged as containing a 's at the beggning. -- To avoid having a space between the name of the player and the 's we previously removed the 's -- from the message. We now need to insert it after the player's name, without a space. if ownershipNameId == messageID then - characterName = characterName .. "'s"; + coloredName = coloredName .. "'s"; end - if characterName ~= character and characterName ~= characterID then - characterColor = getColoredName(info); - -- Then class color - if not characterColor then - characterColor = getCharacterClassColor(chatInfo, event, ...); - else - characterColor = "|cff" .. characterColor; - end - if characterColor then - characterName = characterColor .. characterName .. "|r"; - end - return characterName; - else - return fallback(event, ...); - end + return coloredName; end -- This is the actual GetColoredName replacement function. @@ -506,54 +477,35 @@ function hooking() -- Hook the ChatEdit_InsertLink() function that is called when the user SHIFT-Click a player name -- in the chat frame to insert it into a text field. -- We can replace the name inserted by the complete RP name of the player if we have it. - hooksecurefunc("ChatEdit_InsertLink", function(name) + hooksecurefunc("ChatEdit_InsertLink", function(unitID) -- If we didn't get a name at all then we have nothing to do here - if not name then return end; + if not unitID then return end; -- Do not modify the name inserted if the option is not enabled or if the ALT key is down. if not configInsertFullRPName() or IsAltKeyDown() then return end; -- Do not modify the name if we don't know that character - if not (IsUnitIDKnown(name) or name == Globals.player_id) then return end; + if not (IsUnitIDKnown(unitID) or unitID == Globals.player_id) then return end; local activeChatFrame = ChatEdit_GetActiveWindow(); + if activeChatFrame and activeChatFrame.chatFrame and activeChatFrame.chatFrame.editBox then local editBox = activeChatFrame.chatFrame.editBox; local currentText = editBox:GetText(); local currentCursorPosition = editBox:GetCursorPosition(); -- Save the text that is before and after the name inserted - local textBefore = currentText:sub(1, currentCursorPosition - name:len() - 1); + local textBefore = currentText:sub(1, currentCursorPosition - unitID:len() - 1); local textAfter = currentText:sub(currentCursorPosition+1 ); - - -- TODO There's a new function in our API to easily get the full RP name using name method on some branch, use it once it's merged - -- Retreive the info for the character and the naming method to use - local info = getCharacterInfoTab(name); - local nameMethod = configNameMethod(); - - if info and info.characteristics and nameMethod ~= 1 then -- TRP3 names - local characteristics = info.characteristics; - -- Replace the name by the RP name - if characteristics.FN then - name = characteristics.FN; - end - - -- If the naming method is to use titles, add the short title before the name - if nameMethod == 4 and characteristics.TI then - name = characteristics.TI .. " " .. name; - end - - -- If the naming method is to use lastnames, add the lastname behind the name - if (nameMethod == 3 or nameMethod == 4) and characteristics.LN then -- With last name - name = name .. " " .. characteristics.LN; - end + + local name = getFullnameForUnitUsingChatMethod(unitID, unitID); -- Replace the text of the edit box editBox:SetText(textBefore .. name .. textAfter); -- Move the cursor to the end of the insertion editBox:SetCursorPosition(textBefore:len() + name:len()); - end + end end); end diff --git a/totalRP3/modules/chatframe/prat.lua b/totalRP3/modules/chatframe/prat.lua index 2618b1090..28f4aad8c 100644 --- a/totalRP3/modules/chatframe/prat.lua +++ b/totalRP3/modules/chatframe/prat.lua @@ -4,31 +4,20 @@ local function onStart() Prat:AddModuleToLoad(function() + -- Create Prat module local PRAT_MODULE = Prat:RequestModuleName("Total RP 3") local pratModule = Prat:NewModule(PRAT_MODULE); - - local tContains = tContains; - - local Globals = TRP3_API.globals; - local unitInfoToID = TRP3_API.utils.str.unitInfoToID; - local get = TRP3_API.profile.getData; - local getColoredName = TRP3_API.chat.getColoredName; - local isUnitIDKnown = TRP3_API.register.isUnitIDKnown; - local getUnitIDCurrentProfile = TRP3_API.register.getUnitIDCurrentProfile; - local getFullnameUsingChatMethod = TRP3_API.chat.getFullnameUsingChatMethod; - - local getConfigValue = TRP3_API.configuration.getValue; - local getHandledChannels = TRP3_API.chat.getPossibleChannels; - local CONFIG_USAGE = "chat_use_"; - - local function getCharacterInfoTab(unitID) - if unitID == Globals.player_id then - return get("player"); - elseif isUnitIDKnown(unitID) then - return getUnitIDCurrentProfile(unitID) or {}; - end - return {}; - end + + -- Import Total RP 3 functions + local unitInfoToID = TRP3_API.utils.str.unitInfoToID; -- Get "Player-Realm" unit ID + local getUnitColor = TRP3_API.utils.color.getUnitColor; -- Get unit color (custom or default) + local getFullnameForUnitUsingChatMethod = TRP3_API.chat.getFullnameForUnitUsingChatMethod; -- Get full name using settings + local isChannelHandled = TRP3_API.chat.isChannelHandled; -- Check if Total RP 3 handles this channel + local configIsChannelUsed = TRP3_API.chat.configIsChannelUsed; -- Check if a channel is enable in settings + + -- WoW imports + local GetPlayerInfoByGUID = GetPlayerInfoByGUID; + Prat:SetModuleOptions(pratModule, { name = "Total RP 3", @@ -42,12 +31,14 @@ local function onStart() } }); + -- Enable Total RP 3's module by default Prat:SetModuleDefaults(pratModule.name, { profile = { on = true, }, }); + -- Runs before Prat add the message to the chat frames function pratModule:Prat_PreAddMessage(arg, message, frame, event) -- If the message has no GUID (system?) we don't have anything to do with this @@ -55,30 +46,20 @@ local function onStart() -- Do not do any modification if the channel is not handled by TRP3 or customizations has been disabled -- for that channel in the settings - if not tContains(getHandledChannels(), event) or not getConfigValue(CONFIG_USAGE .. event) then return end; + if not isChannelHandled(event) or not configIsChannelUsed(event) then return end; -- Retrieve all the player info from the message GUID - local class, classFilename, race, raceFilename, sex, name, realm = GetPlayerInfoByGUID(message.GUID); - - if not realm or realm == "" then -- Thanks Blizzard for not always sending a full character ID - realm = Globals.player_realm_id; - if realm == nil then - return - end - end - - local characterID = unitInfoToID(name, realm); - local info = getCharacterInfoTab(characterID); - local characterName = getFullnameUsingChatMethod(info, name); - local color = getColoredName(info); - - if characterName == name and not color then return end; - - if color then - characterName = ("|cff%s%s|r"):format(color, characterName); - end - - message.PLAYER = characterName; + local _, _, _, _, _, name, realm = GetPlayerInfoByGUID(message.GUID); + + -- Calling our unitInfoToID() function to get a "Player-Realm" formatted string (handles cases where realm is nil) + local unitID = unitInfoToID(name, realm); + + -- Get the unit color and name + local color = getUnitColor(unitID); + local characterName = getFullnameForUnitUsingChatMethod(unitID, name); + + -- Replace the message player name with the colored character name + message.PLAYER = color:WrapTextInColorCode(characterName); message.sS = nil message.SERVER = nil message.Ss = nil @@ -94,16 +75,15 @@ local function onStart() end); end -local MODULE_STRUCTURE = { +-- Register a Total RP 3 module that can be disabled in the settings +TRP3_API.module.registerModule({ ["name"] = "Prat support", ["description"] = "Add support for the Prat add-on.", - ["version"] = 1.000, + ["version"] = 1.1, ["id"] = "trp3_prat", ["onStart"] = onStart, ["minVersion"] = 25, ["requiredDeps"] = { {"trp3_chatframes", 1.100}, } -}; - -TRP3_API.module.registerModule(MODULE_STRUCTURE); \ No newline at end of file +}); \ No newline at end of file From d4d244f9c967afc46174d41f3c3a38430c2ffb63 Mon Sep 17 00:00:00 2001 From: Renaud Ellypse Parize Date: Sat, 28 Jan 2017 12:18:14 +0100 Subject: [PATCH 05/32] CleanupCompanion function --- .../register/characters/register_main.lua | 37 +++++++++++++------ .../companions/register_companions_main.lua | 8 ++-- 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/totalRP3/modules/register/characters/register_main.lua b/totalRP3/modules/register/characters/register_main.lua index 620649175..aeaad79a7 100644 --- a/totalRP3/modules/register/characters/register_main.lua +++ b/totalRP3/modules/register/characters/register_main.lua @@ -474,6 +474,29 @@ local function cleanupCharacters() end end +local function cleanupCompanions() + local companionIDToInfo = TRP3_API.utils.str.companionIDToInfo; + local deleteCompanionProfile = TRP3_API.companions.register.deleteProfile; + + local companionProfiles = TRP3_API.companions.register.getProfiles(); + local characterProfiles = TRP3_API.profile.getProfiles(); + + for companionProfileID, companionProfile in pairs(companionProfiles) do + for companionFullID, _ in pairs(companionProfile.links) do + local ownerID, companionID = companionIDToInfo(companionFullID); + print(companionProfileID .. " is associated to " .. ownerID); + if not isUnitIDKnown(ownerID) or not profileExists(ownerID) then + print("Delete companion " .. companionFullID .." link to " .. ownerID .. " as character is not known or no profile for it".); + -- companionProfile.links[companionFullID] = nil; + end + end + if tsize(companionProfile.links) < 1 then + print("No more links to " .. companionProfileID .. ", delete companion profile!"); + -- deleteCompanionProfile(companionProfileID, true); + end + end +end + local function cleanupPlayerRelations() for _, profile in pairs(TRP3_API.profile.getProfiles()) do for profileID, relation in pairs(profile.relation or {}) do @@ -485,9 +508,7 @@ local function cleanupPlayerRelations() end local function cleanupProfiles() - local getAssociatedCompanions = TRP3_API.companions.register.getAssociationsForProfile; - local deleteCompanionProfile = TRP3_API.companions.register.deleteProfile; - + if true then return end; if type(getConfigValue("register_auto_purge_mode")) ~= "number" then return; end @@ -508,14 +529,7 @@ local function cleanupProfiles() end log("Profiles to purge: " .. tsize(profilesToPurge)); for _, profileID in pairs(profilesToPurge) do - -- We also need to purge the companions associated to that profile, so we retrieve them - local associatedCompanions = getAssociatedCompanions(profileID); - log("Purging " .. tsize(associatedCompanions) .. " companions associated to profile " .. profileID); - -- Delete every companion profiles - for _, companionProfileID in pairs(associatedCompanions) do - deleteCompanionProfile(companionProfileID, true); - end - deleteProfile(profileID, true); + -- deleteProfile(profileID, true); end end @@ -667,6 +681,7 @@ function TRP3_API.register.init() cleanupPlayerRelations(); cleanupProfiles(); cleanupCharacters(); + cleanupCompanions(); Config.registerConfigurationPage(TRP3_API.register.CONFIG_STRUCTURE); end); diff --git a/totalRP3/modules/register/companions/register_companions_main.lua b/totalRP3/modules/register/companions/register_companions_main.lua index 3ecd3ce84..65c7a93fd 100644 --- a/totalRP3/modules/register/companions/register_companions_main.lua +++ b/totalRP3/modules/register/companions/register_companions_main.lua @@ -402,7 +402,7 @@ function TRP3_API.companions.register.getAssociationsForProfile(profileID) return list; end -function TRP3_API.companions.register.deleteProfile(profileID) +function TRP3_API.companions.register.deleteProfile(profileID, silently) assert(registerCompanions[profileID], "Unknown profile ID: " .. tostring(profileID)); wipe(registerCompanions[profileID]); registerCompanions[profileID] = nil; @@ -411,8 +411,10 @@ function TRP3_API.companions.register.deleteProfile(profileID) registerProfileAssociation[key] = nil; end end - Events.fireEvent(Events.REGISTER_DATA_UPDATED, nil, profileID, nil); - Events.fireEvent(Events.REGISTER_PROFILE_DELETED, profileID); + if not silently then + Events.fireEvent(Events.REGISTER_DATA_UPDATED, nil, profileID, nil); + Events.fireEvent(Events.REGISTER_PROFILE_DELETED, profileID); + end end function TRP3_API.companions.register.getUnitMount(ownerID, unitType) From f24bf3efc1b9e78b9bcd7395c7383d08e3fb84c1 Mon Sep 17 00:00:00 2001 From: Renaud Ellypse Parize Date: Sat, 28 Jan 2017 12:41:46 +0100 Subject: [PATCH 06/32] CleanupCompanion finishing touches --- .../modules/register/characters/register_main.lua | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/totalRP3/modules/register/characters/register_main.lua b/totalRP3/modules/register/characters/register_main.lua index aeaad79a7..6a9736329 100644 --- a/totalRP3/modules/register/characters/register_main.lua +++ b/totalRP3/modules/register/characters/register_main.lua @@ -484,15 +484,13 @@ local function cleanupCompanions() for companionProfileID, companionProfile in pairs(companionProfiles) do for companionFullID, _ in pairs(companionProfile.links) do local ownerID, companionID = companionIDToInfo(companionFullID); - print(companionProfileID .. " is associated to " .. ownerID); if not isUnitIDKnown(ownerID) or not profileExists(ownerID) then - print("Delete companion " .. companionFullID .." link to " .. ownerID .. " as character is not known or no profile for it".); - -- companionProfile.links[companionFullID] = nil; + companionProfile.links[companionFullID] = nil; end end if tsize(companionProfile.links) < 1 then - print("No more links to " .. companionProfileID .. ", delete companion profile!"); - -- deleteCompanionProfile(companionProfileID, true); + log("Purging companion " .. companionProfileID .. ", no more characters linked to it."); + deleteCompanionProfile(companionProfileID, true); end end end @@ -508,7 +506,6 @@ local function cleanupPlayerRelations() end local function cleanupProfiles() - if true then return end; if type(getConfigValue("register_auto_purge_mode")) ~= "number" then return; end @@ -529,7 +526,7 @@ local function cleanupProfiles() end log("Profiles to purge: " .. tsize(profilesToPurge)); for _, profileID in pairs(profilesToPurge) do - -- deleteProfile(profileID, true); + deleteProfile(profileID, true); end end From b4724d4dfec1dcdfc848fe547dcf99b2ef537c7a Mon Sep 17 00:00:00 2001 From: Sylvain Telkostrasz Cossement Date: Sat, 28 Jan 2017 12:43:54 +0100 Subject: [PATCH 07/32] Do not wipe character on cleanup. --- .../register/characters/register_main.lua | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/totalRP3/modules/register/characters/register_main.lua b/totalRP3/modules/register/characters/register_main.lua index 6a9736329..a15df8a07 100644 --- a/totalRP3/modules/register/characters/register_main.lua +++ b/totalRP3/modules/register/characters/register_main.lua @@ -90,18 +90,19 @@ TRP3_API.register.getProfile = getProfile; local function deleteProfile(profileID, dontFireEvents) assert(profiles[profileID], "Unknown profile ID: " .. tostring(profileID)); - -- We shouldn't keep unbounded characters. - for character, _ in pairs(profiles[profileID].link) do - if characters[character].profileID == profileID then - wipe(characters[character]); - characters[character] = nil; + -- Unbound characters from this profile + for characterID, _ in pairs(profiles[profileID].link) do + if characters[characterID].profileID == profileID then + characters[characterID].profileID = nil; end end - local mspOwners = nil; - if profiles[profileID].msp then - mspOwners = {}; - for ownerID, _ in pairs(profiles[profileID].link) do - tinsert(mspOwners, ownerID); + local mspOwners; + if not dontFireEvents then + if profiles[profileID].msp then + mspOwners = {}; + for ownerID, _ in pairs(profiles[profileID].link) do + tinsert(mspOwners, ownerID); + end end end wipe(profiles[profileID]); @@ -466,6 +467,7 @@ end local tsize = Utils.table.size; +-- Unbound character from missing profiles local function cleanupCharacters() for unitID, character in pairs(characters) do if character.profileID and (not profiles[character.profileID] or not profiles[character.profileID].link[unitID]) then @@ -496,10 +498,10 @@ local function cleanupCompanions() end local function cleanupPlayerRelations() - for _, profile in pairs(TRP3_API.profile.getProfiles()) do - for profileID, relation in pairs(profile.relation or {}) do + for _, myProfile in pairs(TRP3_API.profile.getProfiles()) do + for profileID, relation in pairs(myProfile.relation or {}) do if not profiles[profileID] then - profile.relation[profileID] = nil; + myProfile.relation[profileID] = nil; end end end From 0e6f123de00490e4d619727652fb5fb2acff01e7 Mon Sep 17 00:00:00 2001 From: Sylvain Telkostrasz Cossement Date: Sat, 28 Jan 2017 13:01:41 +0100 Subject: [PATCH 08/32] Add 30 days for purge --- totalRP3/modules/register/characters/register_main.lua | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/totalRP3/modules/register/characters/register_main.lua b/totalRP3/modules/register/characters/register_main.lua index 30b890506..6283c4e85 100644 --- a/totalRP3/modules/register/characters/register_main.lua +++ b/totalRP3/modules/register/characters/register_main.lua @@ -586,9 +586,10 @@ function TRP3_API.register.init() local AUTO_PURGE_VALUES = { {loc("CO_REGISTER_AUTO_PURGE_0"), false}, {loc("CO_REGISTER_AUTO_PURGE_1"):format(1), 86400}, - {loc("CO_REGISTER_AUTO_PURGE_1"):format(2), 172800}, - {loc("CO_REGISTER_AUTO_PURGE_1"):format(5), 432000}, - {loc("CO_REGISTER_AUTO_PURGE_1"):format(10), 864000}, + {loc("CO_REGISTER_AUTO_PURGE_1"):format(2), 86400*2}, + {loc("CO_REGISTER_AUTO_PURGE_1"):format(5), 86400*5}, + {loc("CO_REGISTER_AUTO_PURGE_1"):format(10), 86400*10}, + {loc("CO_REGISTER_AUTO_PURGE_1"):format(30), 86400*30}, } -- Build configuration page From ac0668e029af6a78184628099ea488a0a8422cc9 Mon Sep 17 00:00:00 2001 From: Sylvain Telkostrasz Cossement Date: Sun, 29 Jan 2017 19:23:28 +0100 Subject: [PATCH 09/32] Field sanitization --- totalRP3/core/impl/locale/locale_enUS.lua | 2 ++ totalRP3/core/impl/utils.lua | 24 ++++++++++++++--- totalRP3/modules/dashboard/dashboard.lua | 17 ++++++++++++ .../characters/register_characteristics.lua | 17 ++++++++++++ .../register/characters/register_main.lua | 26 +++++++++++++++++++ .../register/characters/register_misc.lua | 16 ++++++++++++ 6 files changed, 99 insertions(+), 3 deletions(-) diff --git a/totalRP3/core/impl/locale/locale_enUS.lua b/totalRP3/core/impl/locale/locale_enUS.lua index d44ec4133..750453b9d 100644 --- a/totalRP3/core/impl/locale/locale_enUS.lua +++ b/totalRP3/core/impl/locale/locale_enUS.lua @@ -562,6 +562,8 @@ Possible status: CO_LOCATION_DISABLE_OOC_TT = "You will not respond to location request from other players when you've set your RP status to Out Of Character.", CO_LOCATION_DISABLE_PVP = "Disable location when flaged for PVP", CO_LOCATION_DISABLE_PVP_TT = "You will not respond to location request from other players when you are flaged for PvP.\n\nThis option is particularly useful on PvP realms where players from the other faction can abuse the location system to track you.", + CO_SANITIZER = "Sanitize incoming profiles", + CO_SANITIZER_TT = "Remove escaped sequences in tooltip fields from incoming profiles when TRP doesn't allow it (color, images ...).", --*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* -- TOOLBAR AND UI BUTTONS diff --git a/totalRP3/core/impl/utils.lua b/totalRP3/core/impl/utils.lua index 50cb6a09f..9306060a2 100644 --- a/totalRP3/core/impl/utils.lua +++ b/totalRP3/core/impl/utils.lua @@ -404,6 +404,19 @@ function Utils.str.safeMatch(text, pattern) return nil; -- Pattern error end +local escapes = { + ["|c%x%x%x%x%x%x%x%x"] = "", -- color start + ["|r"] = "", -- color end + ["|H.-|h(.-)|h"] = "%1", -- links + ["|T.-|t"] = "", -- textures +} +function Utils.str.sanitize(text) + for k, v in pairs(escapes) do + text = text:gsub(k, v); + end + return text; +end + --*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* -- Colors --*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* @@ -575,7 +588,12 @@ local structureTags = { local strtrim = strtrim; -- Convert the given text by his HTML representation -Utils.str.toHTML = function(text) +Utils.str.toHTML = function(text, noColor) + + local linkColor = "|cff00ff00"; + if noColor then + linkColor = ""; + end -- 1) Replacement : & character text = text:gsub("&", "&"); @@ -670,10 +688,10 @@ Utils.str.toHTML = function(text) end); line = line:gsub("%[(.-)%]%((.-)%)", - "|cff00ff00[%1]|r"); + "" .. linkColor .. "[%1]|r"); line = line:gsub("{link%*(.-)%*(.-)}", - "|cff00ff00[%2]|r"); + "" .. linkColor .. "[%2]|r"); line = line:gsub("{twitter%*(.-)%*(.-)}", "|cff61AAEE%2|r"); diff --git a/totalRP3/modules/dashboard/dashboard.lua b/totalRP3/modules/dashboard/dashboard.lua index 52e46bc1b..383b178a3 100644 --- a/totalRP3/modules/dashboard/dashboard.lua +++ b/totalRP3/modules/dashboard/dashboard.lua @@ -106,6 +106,23 @@ function TRP3_API.dashboard.getCharacterExchangeData() return get("player/character"); end +--*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* +-- SANITIZE +--*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* + +local FIELDS_TO_SANITIZE = { + "CO", "CU" +} +function TRP3_API.dashboard.sanitizeCharacter(structure) + if structure then + for _, field in pairs(FIELDS_TO_SANITIZE) do + if structure[field] then + structure[field] = Utils.str.sanitize(structure[field]); + end + end + end +end + --*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* -- INIT --*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* diff --git a/totalRP3/modules/register/characters/register_characteristics.lua b/totalRP3/modules/register/characters/register_characteristics.lua index bb93eb085..ec79a2223 100644 --- a/totalRP3/modules/register/characters/register_characteristics.lua +++ b/totalRP3/modules/register/characters/register_characteristics.lua @@ -803,6 +803,23 @@ local function onSave() showCharacteristicsTab(); end +--*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* +-- SANITIZE +--*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* + +local FIELDS_TO_SANITIZE = { + "RA", "CL", "FN", "LN", "FT", "TI" +} +function TRP3_API.register.ui.sanitizeCharacteristics(structure) + if structure then + for _, field in pairs(FIELDS_TO_SANITIZE) do + if structure[field] then + structure[field] = Utils.str.sanitize(structure[field]); + end + end + end +end + --*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* -- CHARACTERISTICS - INIT --*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* diff --git a/totalRP3/modules/register/characters/register_main.lua b/totalRP3/modules/register/characters/register_main.lua index 30b890506..450206026 100644 --- a/totalRP3/modules/register/characters/register_main.lua +++ b/totalRP3/modules/register/characters/register_main.lua @@ -268,6 +268,22 @@ local function saveCharacterInformation(unitID, race, class, gender, faction, ti end TRP3_API.register.saveCharacterInformation = saveCharacterInformation; +function TRP3_API.register.sanitizeFullProfile(data) + TRP3_API.register.sanitizeProfile(registerInfoTypes.CHARACTERISTICS, data.characteristics); + TRP3_API.register.sanitizeProfile(registerInfoTypes.CHARACTER, data.character); + TRP3_API.register.sanitizeProfile(registerInfoTypes.MISC, data.misc); +end + +function TRP3_API.register.sanitizeProfile(informationType, data) + if informationType == registerInfoTypes.CHARACTERISTICS then + TRP3_API.register.ui.sanitizeCharacteristics(data); + elseif informationType == registerInfoTypes.CHARACTER then + TRP3_API.dashboard.sanitizeCharacter(data); + elseif informationType == registerInfoTypes.MISC then + TRP3_API.register.ui.sanitizeMisc(data); + end +end + --- Raises error if unknown unitID or unit hasn't profile ID function TRP3_API.register.saveInformation(unitID, informationType, data) local profile = getUnitIDProfile(unitID); @@ -275,6 +291,9 @@ function TRP3_API.register.saveInformation(unitID, informationType, data) wipe(profile[informationType]); end + if getConfigValue("register_sanitization") == true then + TRP3_API.register.sanitizeProfile(informationType, data); + end profile[informationType] = data; Events.fireEvent(Events.REGISTER_DATA_UPDATED, unitID, hasProfile(unitID), informationType); end @@ -574,6 +593,7 @@ function TRP3_API.register.init() registerConfigKey("register_about_use_vote", true); registerConfigKey("register_auto_add", true); registerConfigKey("register_auto_purge_mode", 864000); + registerConfigKey("register_sanitization", true); local CONFIG_ENABLE_MAP_LOCATION = "register_map_location"; local CONFIG_DISABLE_MAP_LOCATION_ON_OOC = "register_map_location_ooc"; @@ -639,6 +659,12 @@ function TRP3_API.register.init() title = loc("CO_LOCATION_DISABLE_PVP"), help = loc("CO_LOCATION_DISABLE_PVP_TT"), configKey = CONFIG_DISABLE_MAP_LOCATION_ON_PVP, + }, + { + inherit = "TRP3_ConfigCheck", + title = loc("CO_SANITIZER"), + configKey = "register_sanitization", + help = loc("CO_SANITIZER_TT") } } }; diff --git a/totalRP3/modules/register/characters/register_misc.lua b/totalRP3/modules/register/characters/register_misc.lua index 586e350a5..6aa18de53 100644 --- a/totalRP3/modules/register/characters/register_misc.lua +++ b/totalRP3/modules/register/characters/register_misc.lua @@ -418,6 +418,22 @@ function TRP3_API.register.player.getMiscExchangeData() return currentCompressed; end +--*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* +-- SANITIZE +--*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* + +function TRP3_API.register.ui.sanitizeMisc(structure) + if structure and structure.PE then + for i=1, 5 do + local index = tostring(i); + if structure.PE[index] then + structure.PE[index].TI = Utils.str.sanitize(structure.PE[index].TI); + structure.PE[index].TX = Utils.str.sanitize(structure.PE[index].TX); + end + end + end +end + --*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* -- TUTORIAL --*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* From 04082e9396a629d5a40d9b5782a3e251981488eb Mon Sep 17 00:00:00 2001 From: "Renaud \"Ellypse\" Parize" Date: Wed, 1 Feb 2017 21:16:23 +0100 Subject: [PATCH 10/32] Added options dependencies Config options can now indicate if they need other options to be enabled. If that option is disabled, the dependent options will be disabled (their alpha will also be set to 0.5) --- totalRP3/core/impl/configuration.lua | 62 ++++++++++++++++++- totalRP3/modules/chatframe/chatframe.lua | 7 ++- .../register/characters/register_main.lua | 3 + .../filter/register_mature_filter.lua | 1 + .../register/main/register_tooltip.lua | 1 + 5 files changed, 72 insertions(+), 2 deletions(-) diff --git a/totalRP3/core/impl/configuration.lua b/totalRP3/core/impl/configuration.lua index d67bb38b2..ccd09d720 100644 --- a/totalRP3/core/impl/configuration.lua +++ b/totalRP3/core/impl/configuration.lua @@ -103,8 +103,10 @@ Config.resetValue = resetValue; --*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* local GENERATED_WIDGET_INDEX = 0; +local optionsDependentOnOtherOptions = {}; local function buildConfigurationPage(structure) + local optionsDependency = {}; local lastWidget; local marginLeft = structure.marginLeft or 5; for index, element in pairs(structure.elements) do @@ -117,6 +119,7 @@ local function buildConfigurationPage(structure) else widget:SetPoint("TOP", structure.parent, "TOP", 0, element.marginTop or 0); end + element.widget = widget; -- Titles if element.title then @@ -141,6 +144,7 @@ local function buildConfigurationPage(structure) -- Specific for Dropdown if _G[widget:GetName().."DropDown"] then local dropDown = _G[widget:GetName().."DropDown"]; + element.controller = _G[widget:GetName().."DropDownButton"]; if element.configKey then if not element.listCallback then element.listCallback = function(value) @@ -165,6 +169,7 @@ local function buildConfigurationPage(structure) if _G[widget:GetName().."Picker"] then if element.configKey then local button = _G[widget:GetName().."Picker"]; + element.controller = button; button.setColor(hexaToNumber(getValue(element.configKey))); button.onSelection = function(red, green, blue) if red and green and blue then @@ -180,6 +185,7 @@ local function buildConfigurationPage(structure) -- Specific for Button if _G[widget:GetName().."Button"] then local button = _G[widget:GetName().."Button"]; + element.controller = button; if element.callback then button:SetScript("OnClick", element.callback); end @@ -189,6 +195,7 @@ local function buildConfigurationPage(structure) -- Specific for EditBox if _G[widget:GetName().."Box"] then local box = _G[widget:GetName().."Box"]; + element.controller = box; if element.configKey then box:SetScript("OnTextChanged", function(self) local value = self:GetText(); @@ -207,9 +214,26 @@ local function buildConfigurationPage(structure) -- Specific for Check if _G[widget:GetName().."Check"] then local box = _G[widget:GetName().."Check"]; + element.controller = box; if element.configKey then box:SetScript("OnClick", function(self) - setValue(element.configKey, self:GetChecked()); + local optionIsEnabled = self:GetChecked(); + setValue(element.configKey, optionIsEnabled); + + if optionsDependentOnOtherOptions[element.configKey] then + for _, dependentOption in pairs(optionsDependentOnOtherOptions[element.configKey]) do + + dependentOption.widget:SetAlpha(optionIsEnabled and 1 or 0.5); + + if dependentOption.controller then + if optionIsEnabled then + dependentOption.controller:Enable(); + else + dependentOption.controller:Disable(); + end + end + end + end end); box:SetChecked(getValue(element.configKey)); end @@ -247,10 +271,45 @@ local function buildConfigurationPage(structure) onChange(slider, slider:GetValue()); end + + if element.dependentOnOptions then + for _, dependence in pairs(element.dependentOnOptions) do + if not optionsDependency[dependence] then + optionsDependency[dependence] = {}; + end + tinsert(optionsDependency[dependence], element); + end + end lastWidget = widget; GENERATED_WIDGET_INDEX = GENERATED_WIDGET_INDEX + 1; end + + -- Now that we have built all our widget we can go through the dependencies table + -- and disable the elements that need to be disabled if the option they are dependent on + -- is disabled. + for dependence, dependentElements in pairs(optionsDependency) do + + -- Go through each element of the dependence + for _, element in pairs(dependentElements) do + + -- If the option is disable we render the element as being disable + if not getValue(dependence) then + element.widget:SetAlpha(0.5); + + if element.controller then + element.controller:Disable(); + end + end + + -- Insert the dependent element in our optionsDependentOnOtherOptions table + -- used for cross option page dependencies (like the location feature needing the broadcast protocol) + if not optionsDependentOnOtherOptions[dependence] then + optionsDependentOnOtherOptions[dependence] = {}; + end + tinsert(optionsDependentOnOtherOptions[dependence], element) + end + end end local configurationPageCount = 0; @@ -370,6 +429,7 @@ TRP3_API.events.listenToEvent(TRP3_API.events.WORKFLOW_ON_LOAD, function() inherit = "TRP3_ConfigEditBox", title = loc("CO_GENERAL_BROADCAST_C"), configKey = "comm_broad_chan", + dependentOnOptions = {"comm_broad_use"}, }, { inherit = "TRP3_ConfigH1", diff --git a/totalRP3/modules/chatframe/chatframe.lua b/totalRP3/modules/chatframe/chatframe.lua index c1c206d68..c91730289 100644 --- a/totalRP3/modules/chatframe/chatframe.lua +++ b/totalRP3/modules/chatframe/chatframe.lua @@ -182,6 +182,7 @@ local function createConfigPage() inherit = "TRP3_ConfigCheck", title = "Increase color contrast", configKey = CONFIG_INCREASE_CONTRAST, + dependentOnOptions = {CONFIG_NAME_COLOR}, }, { inherit = "TRP3_ConfigH1", @@ -196,7 +197,8 @@ local function createConfigPage() inherit = "TRP3_ConfigEditBox", title = loc("CO_CHAT_MAIN_NPC_PREFIX"), configKey = CONFIG_NPC_TALK_PREFIX, - help = loc("CO_CHAT_MAIN_NPC_PREFIX_TT") + help = loc("CO_CHAT_MAIN_NPC_PREFIX_TT"), + dependentOnOptions = {CONFIG_NPC_TALK}, }, { inherit = "TRP3_ConfigH1", @@ -220,6 +222,7 @@ local function createConfigPage() listContent = EMOTE_PATTERNS, configKey = CONFIG_EMOTE_PATTERN, listCancel = true, + dependentOnOptions = {CONFIG_EMOTE}, }, { inherit = "TRP3_ConfigH1", @@ -237,11 +240,13 @@ local function createConfigPage() listContent = OOC_PATTERNS, configKey = CONFIG_OOC_PATTERN, listCancel = true, + dependentOnOptions = {CONFIG_OOC}, }, { inherit = "TRP3_ConfigColorPicker", title = loc("CO_CHAT_MAIN_OOC_COLOR"), configKey = CONFIG_OOC_COLOR, + dependentOnOptions = {CONFIG_OOC}, }, { inherit = "TRP3_ConfigH1", diff --git a/totalRP3/modules/register/characters/register_main.lua b/totalRP3/modules/register/characters/register_main.lua index 30b890506..595879923 100644 --- a/totalRP3/modules/register/characters/register_main.lua +++ b/totalRP3/modules/register/characters/register_main.lua @@ -627,18 +627,21 @@ function TRP3_API.register.init() title = loc("CO_LOCATION_ACTIVATE"), help = loc("CO_LOCATION_ACTIVATE_TT"), configKey = CONFIG_ENABLE_MAP_LOCATION, + dependentOnOptions = {"comm_broad_use"} }, { inherit = "TRP3_ConfigCheck", title = loc("CO_LOCATION_DISABLE_OOC"), help = loc("CO_LOCATION_DISABLE_OOC_TT"), configKey = CONFIG_DISABLE_MAP_LOCATION_ON_OOC, + dependentOnOptions = {"comm_broad_use", CONFIG_ENABLE_MAP_LOCATION}, }, { inherit = "TRP3_ConfigCheck", title = loc("CO_LOCATION_DISABLE_PVP"), help = loc("CO_LOCATION_DISABLE_PVP_TT"), configKey = CONFIG_DISABLE_MAP_LOCATION_ON_PVP, + dependentOnOptions = {"comm_broad_use", CONFIG_ENABLE_MAP_LOCATION}, } } }; diff --git a/totalRP3/modules/register/filter/register_mature_filter.lua b/totalRP3/modules/register/filter/register_mature_filter.lua index af4cb21ae..8034ac121 100644 --- a/totalRP3/modules/register/filter/register_mature_filter.lua +++ b/totalRP3/modules/register/filter/register_mature_filter.lua @@ -515,6 +515,7 @@ local function onStart() TRP3_API.popup.showPopup("mature_dictionary"); refreshDictionaryList(); end, + dependentOnOptions = {MATURE_FILTER_CONFIG}, }); -- Register our popups to the popup manager diff --git a/totalRP3/modules/register/main/register_tooltip.lua b/totalRP3/modules/register/main/register_tooltip.lua index ba95b07cd..d0ef225e2 100644 --- a/totalRP3/modules/register/main/register_tooltip.lua +++ b/totalRP3/modules/register/main/register_tooltip.lua @@ -1085,6 +1085,7 @@ local function onModuleInit() title = loc("CO_TOOLTIP_CONTRAST"), configKey = CONFIG_CHARACT_CONTRAST, help = loc("CO_TOOLTIP_CONTRAST_TT"), + dependentOnOptions = {CONFIG_CHARACT_COLOR}, }, { inherit = "TRP3_ConfigEditBox", From e9780cad4bf51494196fc6b5237591e8801265bd Mon Sep 17 00:00:00 2001 From: "Renaud \"Ellypse\" Parize" Date: Wed, 1 Feb 2017 21:30:43 +0100 Subject: [PATCH 11/32] Use GUID instead of unit ID to get class color --- totalRP3/core/impl/utils.lua | 64 +++++++++++-------- totalRP3/modules/chatframe/chatframe.lua | 36 +++++++---- .../register/characters/register_main.lua | 10 +++ 3 files changed, 73 insertions(+), 37 deletions(-) diff --git a/totalRP3/core/impl/utils.lua b/totalRP3/core/impl/utils.lua index 460c2265e..0ac4dd2c0 100644 --- a/totalRP3/core/impl/utils.lua +++ b/totalRP3/core/impl/utils.lua @@ -46,7 +46,6 @@ local UNKNOWNOBJECT = UNKNOWNOBJECT; local SetPortraitToTexture = SetPortraitToTexture; local getZoneText, getSubZoneText = GetZoneText, GetSubZoneText; local PlaySoundKitID, select, StopSound = PlaySoundKitID, select, StopSound; -local CreateColor = CreateColor; function Utils.pcall(func, ...) if func then @@ -274,7 +273,12 @@ Utils.str.id = generateID; -- Create a unit ID from a unit name and unit realm. If realm = nil then we use current realm. -- This method ALWAYS return a nil free UnitName-RealmShortName string. Utils.str.unitInfoToID = function(unitName, unitRealmID) - return strconcat(unitName or "_", '-', unitRealmID or Globals.player_realm_id); + -- Some functions (like GetPlayerInfoByGUID(GUID)) will return an empty string for the realm instead of null… + -- Thanks Blizz… + if not unitRealmID or unitRealmID == "" then + unitRealmID = Globals.player_realm_id + end + return strconcat(unitName or "_", '-', unitRealmID); end -- Separates the unit name and realm from an unit ID @@ -488,6 +492,15 @@ Utils.color.lightenColorUntilItIsReadable = function(textColor) return textColor; end +-- I quite like Blizzard's Color mixins, it has some nice functions like :WrapTextInColorCode(text) +-- But I will extend them with my own functions like :LightenColorUntilItIsReadable(); +local BlizzardCreateColor = CreateColor; +local function CreateColor(r, g, b, a) + local color = BlizzardCreateColor(r, g, b, a); + color.LightenColorUntilItIsReadable = Utils.color.lightenColorUntilItIsReadable; + return color; +end + --- Returns a Color using Blizzard's ColorMixin for a given hexadecimal color code -- @see ColorMixin function Utils.color.getColorFromHexadecimalCode(hexadecimalCode) @@ -505,11 +518,6 @@ function Utils.color.getClassColor(englishClass) return CreateColor(classColorTable.r, classColorTable.g, classColorTable.b, 1); end -function Utils.color.getUnitClassColor(unitID) - local unitClass = Utils.str.GetClass(unitID); - return Utils.color.getClassColor(unitClass); -end - local CONFIG_CHARACT_CONTRAST = "tooltip_char_contrast"; --- Returns the custom color defined in the unitID's profile as a Color using Blizzard's ColorMixing. @@ -517,23 +525,12 @@ local CONFIG_CHARACT_CONTRAST = "tooltip_char_contrast"; -- @return Color -- @see ColorMixin function Utils.color.getUnitCustomColor(unitID) - local info = TRP3_API.register.getCharacterInfoTab(unitID); + local info = TRP3_API.register.getUnitIDCurrentProfileSafe(unitID); if info.characteristics and info.characteristics.CH then -- If we do have a custom color code (in hexa) defined, get the RGB float values local r, g, b = Utils.color.hexaToFloat(info.characteristics.CH); - local characterColors = {r = r, g = g, b = b}; - - if TRP3_API.configuration.getValue(CONFIG_CHARACT_CONTRAST) then - -- If we have enabled the option to increase contrast we light up the color - characterColors = Utils.color.lightenColorUntilItIsReadable({ - r = characterColors.r, - g = characterColors.g, - b = characterColors.b - }); - end - - return CreateColor(characterColors.r, characterColors.g, characterColors.b, 1); + return CreateColor(r, g, b, 1); end end @@ -542,13 +539,28 @@ function Utils.color.getChatColorForChannel(channel) return CreateColor(chatInfo.r, chatInfo.g, chatInfo.b, 1); end ---- Returns a Color using Blizzard's ColorMixin for a given unit ID. --- It will use the custom color if one is know, ligth it up if the setting is enabled, or default to class color --- @param unitID --- @see ColorMixin +local GetPlayerInfoByGUID = GetPlayerInfoByGUID; +--- +-- Returns the color for the unit corresponding to the given GUID. +-- @param GUID The GUID to use to retrieve player information +-- @param useCustomColors If we should use custom color or not (usually defined in settings) +-- @param lightenColorUntilItIsReadable If we should increase the color so it is readable on dark background (usually defined in settings) -- -function Utils.color.getUnitColor(unitID) - return Utils.color.getUnitCustomColor(unitID) or Utils.color.getUnitClassColor(unitID); +function Utils.color.getUnitColorByGUID(GUID, useCustomColors, lightenColorUntilItIsReadable) + assert(GUID, "Invalid GUID given to Utils.color.getUnitColorByGUID(GUID)"); + local localizedClass, englishClass, localizedRace, englishRace, sex, name, realm = GetPlayerInfoByGUID(GUID); + local color = Utils.color.getClassColor(englishClass); + + if useCustomColors then + local unitID = Utils.str.unitInfoToID(name, realm); + color = Utils.color.getUnitCustomColor(unitID) or color; + + if lightenColorUntilItIsReadable then + color:LightenColorUntilItIsReadable(); + end + end + + return color ; end --*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* diff --git a/totalRP3/modules/chatframe/chatframe.lua b/totalRP3/modules/chatframe/chatframe.lua index c1c206d68..08e34e22c 100644 --- a/totalRP3/modules/chatframe/chatframe.lua +++ b/totalRP3/modules/chatframe/chatframe.lua @@ -26,13 +26,14 @@ local IsUnitIDKnown = TRP3_API.register.isUnitIDKnown; local getUnitIDCurrentProfile, isIDIgnored = TRP3_API.register.getUnitIDCurrentProfile, TRP3_API.register.isIDIgnored; local strsub, strlen, format, _G, pairs, tinsert, time, strtrim = strsub, strlen, format, _G, pairs, tinsert, time, strtrim; local getConfigValue, registerConfigKey, registerHandler = TRP3_API.configuration.getValue, TRP3_API.configuration.registerConfigKey, TRP3_API.configuration.registerHandler; +local setConfigValue = TRP3_API.configuration.setValue; local ChatFrame_RemoveMessageEventFilter, ChatFrame_AddMessageEventFilter = ChatFrame_RemoveMessageEventFilter, ChatFrame_AddMessageEventFilter; local ChatEdit_GetActiveWindow, IsAltKeyDown = ChatEdit_GetActiveWindow, IsAltKeyDown; local oldChatFrameOnEvent; local handleCharacterMessage, hooking; local tContains = tContains; local assert = assert; -local getUnitColor = Utils.color.getUnitColor; +local getUnitColorByGUID = Utils.color.getUnitColorByGUID; local getChatColorForChannel = Utils.color.getChatColorForChannel; local getColorFromHexadecimalCode = Utils.color.getColorFromHexadecimalCode; local select = select; @@ -77,6 +78,10 @@ local function configShowNameCustomColors() return getConfigValue(CONFIG_NAME_COLOR); end +local function configIncreaseNameColorContrast() + return getConfigValue(CONFIG_INCREASE_CONTRAST); +end + local function configIsChannelUsed(channel) return getConfigValue(CONFIG_USAGE .. channel); end @@ -403,19 +408,24 @@ local defaultGetColoredNameFunction = GetColoredName; -- and use their custom colors. -- (It is stored in Utils as we need it in other modules like Prat or WIM) -- It must receive a fallback function as first parameter. It is the function it will use if we don't handle name customizations ourselves -function Utils.customGetColoredNameWithCustomFallbackFunction(fallback, event, ...) +function Utils.customGetColoredNameWithCustomFallbackFunction(fallback, event, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12) assert(fallback, "Trying to call TRP3_API.utils.customGetColoredNameWithCustomFallbackFunction(fallback, event, ...) without a fallback function!") + local GUID = arg12; + local unitID = arg2; + local messageID = arg11; + -- Do not change stuff if the is disabled for this channel, use the default function - if not isChannelHandled(event) or not configIsChannelUsed(event) then return fallback(event, ...) end; + if not isChannelHandled(event) or not configIsChannelUsed(event) or not GUID then + return fallback(event, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12) + end; local characterName, characterColor; - local _, unitID, _, _, _, _, _, _, _, _, messageID = ...; -- We don't have a unit ID for this message (WTF? Some other add-on must be doing some weird shit again…) -- Bail out, let the fallback function handle that shit. - if not unitID then return fallback(event, ...) end; + if not unitID then return fallback(event, event, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12) end; -- Check if this message ID was flagged as containing NPC chat -- If it does we use the NPC name that was saved before. @@ -427,7 +437,7 @@ function Utils.customGetColoredNameWithCustomFallbackFunction(fallback, event, . local character, realm = unitIDToInfo(unitID); if not realm then -- if realm is nil (i.e. globals haven't been set yet) just run the vanilla version of the code to prevent errors. - return fallback(event, ...); + return fallback(event, event, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12); end -- Make sure we have a unitID formatted as "Player-Realm" unitID = unitInfoToID(character, realm); @@ -441,19 +451,23 @@ function Utils.customGetColoredNameWithCustomFallbackFunction(fallback, event, . -- Retrieve the character full name and their color characterName = getFullnameForUnitUsingChatMethod(unitID, character); - local color = getUnitColor(unitID); + local color = getUnitColorByGUID(GUID, configShowNameCustomColors(), configIncreaseNameColorContrast()); - -- And wrap the name inside the color's code - local coloredName = color:WrapTextInColorCode(characterName); + -- If we did get a color wrap the name inside the color code + if color then + -- And wrap the name inside the color's code + characterName = color:WrapTextInColorCode(characterName); + end + -- Check if this message was flagged as containing a 's at the beggning. -- To avoid having a space between the name of the player and the 's we previously removed the 's -- from the message. We now need to insert it after the player's name, without a space. if ownershipNameId == messageID then - coloredName = coloredName .. "'s"; + characterName = characterName .. "'s"; end - return coloredName; + return characterName; end -- This is the actual GetColoredName replacement function. diff --git a/totalRP3/modules/register/characters/register_main.lua b/totalRP3/modules/register/characters/register_main.lua index 30b890506..b28293b0d 100644 --- a/totalRP3/modules/register/characters/register_main.lua +++ b/totalRP3/modules/register/characters/register_main.lua @@ -299,6 +299,16 @@ end TRP3_API.register.getUnitIDCurrentProfile = getUnitIDCurrentProfile; + +function TRP3_API.register.getUnitIDCurrentProfileSafe(unitID) + if unitID == Globals.player_id then + return get("player"); + elseif isUnitIDKnown(unitID) then + return getUnitIDCurrentProfile(unitID) or {}; + end + return {}; +end + --- Raises error if unknown unitID function TRP3_API.register.shouldUpdateInformation(unitID, infoType, version) --- Raises error if unit hasn't profile ID or no profile exists From cb4e9ec4c909fef61f7f29c123d3ebfb63164134 Mon Sep 17 00:00:00 2001 From: "Renaud \"Ellypse\" Parize" Date: Sat, 4 Feb 2017 11:20:16 +0100 Subject: [PATCH 12/32] Fixed Prat and WIM modules --- totalRP3/core/impl/utils.lua | 14 +++++++++++--- totalRP3/modules/chatframe/WIM.lua | 14 ++++++++++++-- totalRP3/modules/chatframe/chatframe.lua | 2 ++ totalRP3/modules/chatframe/prat.lua | 19 +++++++++++++++++-- 4 files changed, 42 insertions(+), 7 deletions(-) diff --git a/totalRP3/core/impl/utils.lua b/totalRP3/core/impl/utils.lua index 0ac4dd2c0..fc66776c1 100644 --- a/totalRP3/core/impl/utils.lua +++ b/totalRP3/core/impl/utils.lua @@ -436,10 +436,11 @@ local function hexaToNumber(hexa) end Utils.color.hexaToNumber = hexaToNumber; -Utils.color.hexaToFloat = function(hexa) - local r, g, b = hexaToNumber(hexa); - return r / 255, g / 255, b / 255; +local function hexaToFloat(hexa) + local r, g, b = hexaToNumber(hexa); + return r / 255, g / 255, b / 255; end +Utils.color.hexaToFloat = hexaToFloat; --- Values must be 256 based local function colorCode(red, green, blue) @@ -563,6 +564,13 @@ function Utils.color.getUnitColorByGUID(GUID, useCustomColors, lightenColorUntil return color ; end +function Utils.color.extractColorFromText(text) + local rgb = text:match("|c%x%x(%x%x%x%x%x%x)"); + local r, g, b = hexaToFloat(rgb); + local color = CreateColor(r or 1, g or 2, b or 3, 1); + return color; +end + --*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* -- Math --*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* diff --git a/totalRP3/modules/chatframe/WIM.lua b/totalRP3/modules/chatframe/WIM.lua index 514f0329d..828e630e5 100644 --- a/totalRP3/modules/chatframe/WIM.lua +++ b/totalRP3/modules/chatframe/WIM.lua @@ -5,8 +5,12 @@ local function onStart() -- Import Total RP 3 functions local customGetColoredNameWithCustomFallbackFunction = TRP3_API.utils.customGetColoredNameWithCustomFallbackFunction; local playerID = TRP3_API.globals.player_id; - local getUnitColor = TRP3_API.utils.color.getUnitColor; -- Get unit color (custom or default) local getFullnameForUnitUsingChatMethod = TRP3_API.chat.getFullnameForUnitUsingChatMethod; -- Get full name using settings + local UnitClass = UnitClass; + local getClassColor = TRP3_API.utils.color.getClassColor; + local getUnitCustomColor = TRP3_API.utils.color.getUnitCustomColor; + local increaseColorContrast = TRP3_API.chat.configIncreaseNameColorContrast; + local configShowNameCustomColors = TRP3_API.chat.configShowNameCustomColors local classes = WIM.constants.classes; @@ -22,7 +26,13 @@ local function onStart() -- Replace WIM's GetMyColoredName to display our full RP name classes.GetMyColoredName = function() local name = getFullnameForUnitUsingChatMethod(playerID); - local color = getUnitColor(playerID); + local _, playerClass = UnitClass("Player"); + local color = configShowNameCustomColors() and getUnitCustomColor(playerID) or getClassColor(playerClass); + + if increaseColorContrast() then + color:LightenColorUntilItIsReadable(); + end + return color:WrapTextInColorCode(name); end end diff --git a/totalRP3/modules/chatframe/chatframe.lua b/totalRP3/modules/chatframe/chatframe.lua index 08e34e22c..548fd1323 100644 --- a/totalRP3/modules/chatframe/chatframe.lua +++ b/totalRP3/modules/chatframe/chatframe.lua @@ -77,10 +77,12 @@ end local function configShowNameCustomColors() return getConfigValue(CONFIG_NAME_COLOR); end +TRP3_API.chat.configShowNameCustomColors = configShowNameCustomColors; local function configIncreaseNameColorContrast() return getConfigValue(CONFIG_INCREASE_CONTRAST); end +TRP3_API.chat.configIncreaseNameColorContrast = configIncreaseNameColorContrast; local function configIsChannelUsed(channel) return getConfigValue(CONFIG_USAGE .. channel); diff --git a/totalRP3/modules/chatframe/prat.lua b/totalRP3/modules/chatframe/prat.lua index 28f4aad8c..7172a001b 100644 --- a/totalRP3/modules/chatframe/prat.lua +++ b/totalRP3/modules/chatframe/prat.lua @@ -10,10 +10,14 @@ local function onStart() -- Import Total RP 3 functions local unitInfoToID = TRP3_API.utils.str.unitInfoToID; -- Get "Player-Realm" unit ID - local getUnitColor = TRP3_API.utils.color.getUnitColor; -- Get unit color (custom or default) + local getUnitColorByGUID = TRP3_API.utils.color.getUnitColorByGUID; -- Get unit color (custom or default) local getFullnameForUnitUsingChatMethod = TRP3_API.chat.getFullnameForUnitUsingChatMethod; -- Get full name using settings local isChannelHandled = TRP3_API.chat.isChannelHandled; -- Check if Total RP 3 handles this channel local configIsChannelUsed = TRP3_API.chat.configIsChannelUsed; -- Check if a channel is enable in settings + local configIncreaseNameColorContrast = TRP3_API.chat.configIncreaseNameColorContrast; + local configShowNameCustomColors = TRP3_API.chat.configShowNameCustomColors; + local getUnitCustomColor = TRP3_API.utils.color.getUnitCustomColor; + local extractColorFromText = TRP3_API.utils.color.extractColorFromText; -- WoW imports local GetPlayerInfoByGUID = GetPlayerInfoByGUID; @@ -40,6 +44,8 @@ local function onStart() -- Runs before Prat add the message to the chat frames function pratModule:Prat_PreAddMessage(arg, message, frame, event) + + local color = extractColorFromText(message.PLAYER); -- If the message has no GUID (system?) we don't have anything to do with this if not message.GUID then return end; @@ -55,8 +61,17 @@ local function onStart() local unitID = unitInfoToID(name, realm); -- Get the unit color and name - local color = getUnitColor(unitID); local characterName = getFullnameForUnitUsingChatMethod(unitID, name); + + if configShowNameCustomColors() then + local customColor = getUnitCustomColor(unitID); + + if configIncreaseNameColorContrast() then + customColor:LightenColorUntilItIsReadable(); + end + + color = customColor or color; + end -- Replace the message player name with the colored character name message.PLAYER = color:WrapTextInColorCode(characterName); From 1dd0fefe6c179d05b6c7a08e68c26d8606570fc9 Mon Sep 17 00:00:00 2001 From: "Renaud \"Ellypse\" Parize" Date: Sat, 4 Feb 2017 11:56:06 +0100 Subject: [PATCH 13/32] Fixed NPC talk issue --- totalRP3/modules/chatframe/chatframe.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/totalRP3/modules/chatframe/chatframe.lua b/totalRP3/modules/chatframe/chatframe.lua index 548fd1323..12158276f 100644 --- a/totalRP3/modules/chatframe/chatframe.lua +++ b/totalRP3/modules/chatframe/chatframe.lua @@ -321,7 +321,7 @@ local function handleNPCEmote(message) local name = message:sub(4, message:find(talkType) - 2); -- Isolate the name local content = message:sub(name:len() + 5); - return chatColor:WrapTextInColorCodecontent(name), chatColor:WrapTextInColorCodecontent(content); + return chatColor:WrapTextInColorCode(name), chatColor:WrapTextInColorCode(content); end end From 3ce5514dce80d763246291e5a33e51721370facc Mon Sep 17 00:00:00 2001 From: "Renaud \"Ellypse\" Parize" Date: Sat, 4 Feb 2017 14:36:56 +0100 Subject: [PATCH 14/32] Fixed NPC speeches + added documentation to Prat module --- totalRP3/modules/chatframe/WIM.lua | 2 +- totalRP3/modules/chatframe/chatframe.lua | 16 ++++++++++++-- totalRP3/modules/chatframe/prat.lua | 27 +++++++++++++++++------- 3 files changed, 34 insertions(+), 11 deletions(-) diff --git a/totalRP3/modules/chatframe/WIM.lua b/totalRP3/modules/chatframe/WIM.lua index 828e630e5..7cbd5e527 100644 --- a/totalRP3/modules/chatframe/WIM.lua +++ b/totalRP3/modules/chatframe/WIM.lua @@ -6,11 +6,11 @@ local function onStart() local customGetColoredNameWithCustomFallbackFunction = TRP3_API.utils.customGetColoredNameWithCustomFallbackFunction; local playerID = TRP3_API.globals.player_id; local getFullnameForUnitUsingChatMethod = TRP3_API.chat.getFullnameForUnitUsingChatMethod; -- Get full name using settings - local UnitClass = UnitClass; local getClassColor = TRP3_API.utils.color.getClassColor; local getUnitCustomColor = TRP3_API.utils.color.getUnitCustomColor; local increaseColorContrast = TRP3_API.chat.configIncreaseNameColorContrast; local configShowNameCustomColors = TRP3_API.chat.configShowNameCustomColors + local UnitClass = UnitClass; local classes = WIM.constants.classes; diff --git a/totalRP3/modules/chatframe/chatframe.lua b/totalRP3/modules/chatframe/chatframe.lua index 12158276f..f37a5367d 100644 --- a/totalRP3/modules/chatframe/chatframe.lua +++ b/totalRP3/modules/chatframe/chatframe.lua @@ -338,9 +338,21 @@ end -- So we are able to flag messages as needing their player name's to be modified local npcMessageId, npcMessageName, ownershipNameId; -function handleCharacterMessage(_, event, message, ...) +function TRP3_API.chat.getNPCMessageID() + return npcMessageId; +end + +function TRP3_API.chat.getNPCMessageName() + return npcMessageName; +end - local messageID = select(11, ...); +function TRP3_API.chat.getOwnershipNameID() + return ownershipNameId; +end + +function handleCharacterMessage(_, event, message, ...) + + local messageID = select(10, ...); -- Detect NPC talk pattern on authorized channels if event == "CHAT_MSG_EMOTE" then diff --git a/totalRP3/modules/chatframe/prat.lua b/totalRP3/modules/chatframe/prat.lua index 7172a001b..19efdc909 100644 --- a/totalRP3/modules/chatframe/prat.lua +++ b/totalRP3/modules/chatframe/prat.lua @@ -10,14 +10,14 @@ local function onStart() -- Import Total RP 3 functions local unitInfoToID = TRP3_API.utils.str.unitInfoToID; -- Get "Player-Realm" unit ID - local getUnitColorByGUID = TRP3_API.utils.color.getUnitColorByGUID; -- Get unit color (custom or default) local getFullnameForUnitUsingChatMethod = TRP3_API.chat.getFullnameForUnitUsingChatMethod; -- Get full name using settings local isChannelHandled = TRP3_API.chat.isChannelHandled; -- Check if Total RP 3 handles this channel local configIsChannelUsed = TRP3_API.chat.configIsChannelUsed; -- Check if a channel is enable in settings - local configIncreaseNameColorContrast = TRP3_API.chat.configIncreaseNameColorContrast; - local configShowNameCustomColors = TRP3_API.chat.configShowNameCustomColors; - local getUnitCustomColor = TRP3_API.utils.color.getUnitCustomColor; - local extractColorFromText = TRP3_API.utils.color.extractColorFromText; + local configIncreaseNameColorContrast = TRP3_API.chat.configIncreaseNameColorContrast; -- Check if the config is to increase color contrast for custom colored names + local configShowNameCustomColors = TRP3_API.chat.configShowNameCustomColors; -- Check if the config is to use custom color for names + local getUnitCustomColor = TRP3_API.utils.color.getUnitCustomColor; -- Get the custom color of a unit using its Unit ID + local extractColorFromText = TRP3_API.utils.color.extractColorFromText; -- Get a Color object from a colored text + local getOwnershipNameID = TRP3_API.chat.getOwnershipNameID; -- Get the latest message ID associated to an ownership mark ('s) -- WoW imports local GetPlayerInfoByGUID = GetPlayerInfoByGUID; @@ -44,8 +44,6 @@ local function onStart() -- Runs before Prat add the message to the chat frames function pratModule:Prat_PreAddMessage(arg, message, frame, event) - - local color = extractColorFromText(message.PLAYER); -- If the message has no GUID (system?) we don't have anything to do with this if not message.GUID then return end; @@ -53,6 +51,9 @@ local function onStart() -- Do not do any modification if the channel is not handled by TRP3 or customizations has been disabled -- for that channel in the settings if not isChannelHandled(event) or not configIsChannelUsed(event) then return end; + + -- Extract the color used by Prat so we use it by default + local color = extractColorFromText(message.PLAYER); -- Retrieve all the player info from the message GUID local _, _, _, _, _, name, realm = GetPlayerInfoByGUID(message.GUID); @@ -63,15 +64,25 @@ local function onStart() -- Get the unit color and name local characterName = getFullnameForUnitUsingChatMethod(unitID, name); + -- Check if we use custom color and retrieve the color custom color associated to the unit ID if configShowNameCustomColors() then local customColor = getUnitCustomColor(unitID); - if configIncreaseNameColorContrast() then + -- If we did receive a color and the option to increase contrast is enabled, lighten up the color until it is readable on dark backgrounds + if customColor and configIncreaseNameColorContrast() then customColor:LightenColorUntilItIsReadable(); end + -- Use the custom color if it exists. color = customColor or color; end + + -- Check if this message was flagged as containing a 's at the beggning. + -- To avoid having a space between the name of the player and the 's we previously removed the 's + -- from the message. We now need to insert it after the player's name, without a space. + if getOwnershipNameID() == message.GUID then + characterName = characterName .. "'s"; + end -- Replace the message player name with the colored character name message.PLAYER = color:WrapTextInColorCode(characterName); From 59a9c0835d4d69ead558ae93cc8ac20c12e75725 Mon Sep 17 00:00:00 2001 From: "Renaud \"Ellypse\" Parize" Date: Sat, 4 Feb 2017 15:18:34 +0100 Subject: [PATCH 15/32] Tooltip colors uses new Color system --- totalRP3/core/impl/utils.lua | 1 + .../register/main/register_tooltip.lua | 56 ++++++++++++------- 2 files changed, 38 insertions(+), 19 deletions(-) diff --git a/totalRP3/core/impl/utils.lua b/totalRP3/core/impl/utils.lua index 500f8579e..db782174a 100644 --- a/totalRP3/core/impl/utils.lua +++ b/totalRP3/core/impl/utils.lua @@ -514,6 +514,7 @@ local function CreateColor(r, g, b, a) color.LightenColorUntilItIsReadable = Utils.color.lightenColorUntilItIsReadable; return color; end +Utils.color.CreateColor = CreateColor; --- Returns a Color using Blizzard's ColorMixin for a given hexadecimal color code -- @see ColorMixin diff --git a/totalRP3/modules/register/main/register_tooltip.lua b/totalRP3/modules/register/main/register_tooltip.lua index d0ef225e2..c884cc0f4 100644 --- a/totalRP3/modules/register/main/register_tooltip.lua +++ b/totalRP3/modules/register/main/register_tooltip.lua @@ -378,24 +378,25 @@ local function writeTooltipForCharacter(targetID, originalTexts, targetType) --*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* local localizedClass, englishClass = UnitClass(targetType); - local classColor = RAID_CLASS_COLORS[englishClass]; - local r, g, b = classColor.r, classColor.g, classColor.b; + local color = Utils.color.getClassColor(englishClass); local rightIcons = ""; local leftIcons = ""; -- Only use custom colors if the option is enabled and if we have one - if getConfigValue(CONFIG_CHARACT_CONTRAST) and info.characteristics and info.characteristics.CH then - r, g, b = Utils.color.hexaToFloat(info.characteristics.CH); - - local lighten = lightenColorUntilItIsReadable({ r = r, g = g, b = b }); - r, g, b = lighten.r, lighten.g, lighten.b; + if getConfigValue(CONFIG_CHARACT_COLOR) and info.characteristics and info.characteristics.CH then + local customColor = Utils.color.getColorFromHexadecimalCode(info.characteristics.CH); + + if getConfigValue(CONFIG_CHARACT_CONTRAST) then + customColor:LightenColorUntilItIsReadable(); + end + + color = customColor or color; end - -- Generate a color code string (|cffrrggbb) that we will use in the name and the class - local characterColorCode = colorCode(r * 255, g * 255, b * 255); - local completeName = characterColorCode .. getCompleteName(info.characteristics or {}, targetName, not showTitle()); + local completeName = getCompleteName(info.characteristics or {}, targetName, not showTitle()); + completeName = color:WrapTextInColorCode(completeName); if showIcons() then -- Player icon @@ -459,7 +460,7 @@ local function writeTooltipForCharacter(targetID, originalTexts, targetType) if info.characteristics and info.characteristics.CL and info.characteristics.CL:len() > 0 then class = info.characteristics.CL; end - lineLeft = strconcat("|cffffffff", race, " ", characterColorCode, class); + lineLeft = strconcat("|cffffffff", race, " ", color:WrapTextInColorCode(class)); lineRight = strconcat("|cffffffff", loc("REG_TT_LEVEL"):format(getLevelIconOrText(targetType), getFactionIcon(targetType))); tooltipBuilder:AddDoubleLine(lineLeft, lineRight, 1, 1, 1, 1, 1, 1, getSubLineFontSize()); @@ -534,12 +535,23 @@ local function writeTooltipForCharacter(targetID, originalTexts, targetType) local name = UnitName(targetType .. "target"); local targetTargetID = getUnitID(targetType .. "target"); if targetTargetID then + local localizedClass, englishClass = UnitClass(targetType .. "target"); local targetInfo = getCharacterInfoTab(targetTargetID); - local characterColorCode = ""; - if targetInfo.characteristics and targetInfo.characteristics.CH then - characterColorCode = "|cff" .. targetInfo.characteristics.CH; + local color = englishClass and Utils.color.getClassColor(englishClass) or Utils.color.CreateColor(1, 1, 1, 1); + + -- Only use custom colors if the option is enabled and if we have one + if getConfigValue(CONFIG_CHARACT_COLOR) and targetInfo.characteristics and targetInfo.characteristics.CH then + local customColor = Utils.color.getColorFromHexadecimalCode(targetInfo.characteristics.CH); + + if getConfigValue(CONFIG_CHARACT_CONTRAST) then + customColor:LightenColorUntilItIsReadable(); + end + + color = customColor or color; end - name = characterColorCode .. getCompleteName(targetInfo.characteristics or {}, targetName, true); + + name = getCompleteName(targetInfo.characteristics or {}, targetName, true); + name = color:WrapTextInColorCode(name); end tooltipBuilder:AddLine(loc("REG_TT_TARGET"):format(name), 1, 1, 1, getSubLineFontSize()); end @@ -684,13 +696,19 @@ local function writeCompanionTooltip(companionFullID, originalTexts, targetType, if showCompanionOwner() then local ownerName, ownerRealm = unitIDToInfo(ownerID); - local ownerFinalName, ownerColor = ownerName, ""; + local ownerFinalName, ownerColor = ownerName, Utils.color.CreateColor(1, 1, 1, 1); if ownerID == Globals.player_id or (IsUnitIDKnown(ownerID) and hasProfile(ownerID)) then local ownerInfo = getCharacterInfoTab(ownerID); if ownerInfo.characteristics then ownerFinalName = getCompleteName(ownerInfo.characteristics, ownerFinalName, true); - if ownerInfo.characteristics.CH then - ownerColor = "|cff" .. ownerInfo.characteristics.CH; + if getConfigValue(CONFIG_CHARACT_COLOR) and ownerInfo.characteristics.CH then + local customColor = Utils.color.getColorFromHexadecimalCode(ownerInfo.characteristics.CH); + + if getConfigValue(CONFIG_CHARACT_CONTRAST) then + customColor:LightenColorUntilItIsReadable(); + end + + ownerColor = customColor or ownerColor; end end else @@ -699,7 +717,7 @@ local function writeCompanionTooltip(companionFullID, originalTexts, targetType, end end - ownerFinalName = ownerColor .. ownerFinalName .. "|r"; + ownerFinalName = ownerColor:WrapTextInColorCode(ownerFinalName); ownerFinalName = loc("REG_COMPANION_TF_OWNER"):format(ownerFinalName); tooltipBuilder:AddLine(ownerFinalName, 1, 1, 1, getSubLineFontSize()); From 9a4502608ddaee5c6c2eaf3015cfb051dd4734de Mon Sep 17 00:00:00 2001 From: Sylvain Telkostrasz Cossement Date: Sun, 5 Feb 2017 20:18:06 +0100 Subject: [PATCH 16/32] Sanitizer fix --- totalRP3/core/impl/utils.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/totalRP3/core/impl/utils.lua b/totalRP3/core/impl/utils.lua index db782174a..c551d281b 100644 --- a/totalRP3/core/impl/utils.lua +++ b/totalRP3/core/impl/utils.lua @@ -416,6 +416,7 @@ local escapes = { ["|T.-|t"] = "", -- textures } function Utils.str.sanitize(text) + if not text then return end for k, v in pairs(escapes) do text = text:gsub(k, v); end From 21d7d65343ded2ca07eab58950ee5b193dc65227 Mon Sep 17 00:00:00 2001 From: Renaud Ellypse Parize Date: Tue, 7 Feb 2017 21:38:48 +0100 Subject: [PATCH 17/32] Fixed sanitize option order + added explanation to disable auto add to directory --- totalRP3/core/impl/locale/locale_enUS.lua | 4 +++- .../modules/register/characters/register_main.lua | 11 +++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/totalRP3/core/impl/locale/locale_enUS.lua b/totalRP3/core/impl/locale/locale_enUS.lua index 750453b9d..ccb9013b9 100644 --- a/totalRP3/core/impl/locale/locale_enUS.lua +++ b/totalRP3/core/impl/locale/locale_enUS.lua @@ -445,7 +445,9 @@ These tools also allow you to insert |cffffff00images, icons or link to external CO_REGISTER_ABOUT_VOTE = "Use voting system", CO_REGISTER_ABOUT_VOTE_TT = "Enables the voting system, allowing you to vote ('like' or 'unlike') for other's descriptions and allowing them to do the same for you.", CO_REGISTER_AUTO_ADD = "Auto add new players", - CO_REGISTER_AUTO_ADD_TT = "Automatically add new players you encounter to the register.", + CO_REGISTER_AUTO_ADD_TT = [[Automatically add new players you encounter to the register. + +|cffff0000Note: Disabling this option will prevent you from receiving any new profiles from players you have not encountered yet! Use this option if you do not want to receive new profiles form other players, only updates from players you have already seen.]], CO_REGISTER_AUTO_PURGE = "Auto purge directory", CO_REGISTER_AUTO_PURGE_TT = "Automatically remove from directory the profiles of character you haven't crossed for a certain time. You can choose the delay before deletion.\n\n|cff00ff00Note that profiles with a relation toward one of your characters will never be purged.\n\n|cffff9900There is a bug in WoW losing all the saved data when it reach a certain theshold. We strongly recommand to avoid disabling the purge system.", CO_REGISTER_AUTO_PURGE_0 = "Disable purge", diff --git a/totalRP3/modules/register/characters/register_main.lua b/totalRP3/modules/register/characters/register_main.lua index e7dcb27af..9680f8a30 100644 --- a/totalRP3/modules/register/characters/register_main.lua +++ b/totalRP3/modules/register/characters/register_main.lua @@ -672,6 +672,11 @@ function TRP3_API.register.init() listContent = AUTO_PURGE_VALUES, configKey = "register_auto_purge_mode", listCancel = true, + }, { + inherit = "TRP3_ConfigCheck", + title = loc("CO_SANITIZER"), + configKey = "register_sanitization", + help = loc("CO_SANITIZER_TT") }, { inherit = "TRP3_ConfigH1", @@ -698,12 +703,6 @@ function TRP3_API.register.init() configKey = CONFIG_DISABLE_MAP_LOCATION_ON_PVP, dependentOnOptions = {"comm_broad_use", CONFIG_ENABLE_MAP_LOCATION}, }, - { - inherit = "TRP3_ConfigCheck", - title = loc("CO_SANITIZER"), - configKey = "register_sanitization", - help = loc("CO_SANITIZER_TT") - } } }; TRP3_API.events.listenToEvent(TRP3_API.events.WORKFLOW_ON_FINISH, function() From 22fde74ebf8d7bc8b5e10117f125bf759fd88c54 Mon Sep 17 00:00:00 2001 From: Renaud Ellypse Parize Date: Tue, 7 Feb 2017 21:42:48 +0100 Subject: [PATCH 18/32] Version 1.2.6 beta 1 --- totalRP3/core/impl/globals.lua | 2 +- totalRP3/core/impl/locale/locale_enUS.lua | 32 +++++++---------------- totalRP3/modules/dashboard/dashboard.lua | 2 +- totalRP3/totalRP3.toc | 2 +- 4 files changed, 13 insertions(+), 25 deletions(-) diff --git a/totalRP3/core/impl/globals.lua b/totalRP3/core/impl/globals.lua index ffe779d4d..51ac9b1e0 100644 --- a/totalRP3/core/impl/globals.lua +++ b/totalRP3/core/impl/globals.lua @@ -39,7 +39,7 @@ TRP3_API = { addon_id_length = 15, version = 26, - version_display = "1.2.5", + version_display = "1.2.6-beta1", player = UnitName("player"), player_realm = GetRealmName(), diff --git a/totalRP3/core/impl/locale/locale_enUS.lua b/totalRP3/core/impl/locale/locale_enUS.lua index ccb9013b9..aa765c58b 100644 --- a/totalRP3/core/impl/locale/locale_enUS.lua +++ b/totalRP3/core/impl/locale/locale_enUS.lua @@ -953,28 +953,16 @@ You can also leave this field empty to create emotes without an NPC name at the Your profiles, companions profiles and settings will be temporarily stashed away and your UI will reload with empty data, like your installation of Total RP 3 was brand new. |cff00ff00Use the same command again (|cff999999/trp3 stash|cff00ff00) to restore your data.|r]], - WHATS_NEW_7 = [[# New in version 1.2.5 - -## Chat customization revamp - -We have completely changed our chat customizations to increase compatibility with other add-ons like Prat, WIM, or even Tongues! - -We have also built custom modules for both Prat and WIM to have the full RP names correctly displayed when using these add-ons. - -Additionally, this new system fixes a long standing issue where whispers were displayed in every chat tab when the option to have incoming whispers routed to their own tab was enabled. - -|cffccccccA big special thank you to |r{twitter*Saelorable*Saelora}|cffcccccc from Argent Dawn (EU) for helping us making this system <3|r - -## Bug fixes - -- We have implemented a custom bug fix for an issue in Blizzard's own code that is making any opened dropdown menu close themselves randomly when the map is opened, so it is easier for you to use Total RP 3's scanning features ({link*open_map_filters_dropdown*Reminder: now located inside the filter menu in the top right corner of the map}). -- The |cffccccccextensionxtooltip2|r channel should now be joined a little bit later so it is assigned the number 1 channel less often. - -## Other improvements - -- Skinning add-ons that modify the tooltips font should now work with Total RP 3's tooltips. -- Added link to our Discord server in the About tab of the Dashboard. -- Implemented a workaround against the PetTracker add-on as it is removing other add-ons options in the world map filters dropdown menu. The default dropdown menu is restored by Total RP 3 and PetTracker's options are properly added to the menu after Total RP 3's. ([ticket #45](https://wow.curseforge.com/projects/total-rp-3/issues/45)) + WHATS_NEW_8 = [[# New in version 1.2.6 + +- Fixed several issues with the new chat system introduced in version 1.2.5 that would prevent player names form being colored correctly ([ticket #50](https://wow.curseforge.com/projects/total-rp-3/issues/50)). +- Fixed a Lua error in the new WIM module ([ticket #55](https://wow.curseforge.com/projects/total-rp-3/issues/55)). +- Fixed an issue where the option to increase color contrast on player names in the tooltip was always enabled ([ticket #51](https://wow.curseforge.com/projects/total-rp-3/issues/51)) +- Fixed a Lua error when shift-clicking a spell name in the adventure journal ([ticket #61](https://wow.curseforge.com/projects/total-rp-3/issues/61)) +- Fixed an issue making the game freeze and possibly crash when trying to delete too many companion profiles from the directory. Additionally, companion profiles are now included in the automatic purge ([ticket #56](https://wow.curseforge.com/projects/total-rp-3/issues/56)). +- Fixed a long standing issue allowing advanced users to inject custom icons and color codes in places that were not meant for that, as this behaviour led to game crashes, as well as compatibility issues with other RP add-ons and stability issues in Total RP 3 itself ([ticket #63](https://wow.curseforge.com/projects/total-rp-3/issues/63)). +- The option to increase contrast on color names in the tooltip is now applied on the other colored fields, not just the name field. +- Added notice on the Auto add new players option of the directory to indicate that disabling this option will prevent you from receiving any new profile. ]], MORE_MODULES_2 = [[{h2:c}Optional modules{/h2} {h3}Total RP 3: Extended |cffF87431|r{/h3} diff --git a/totalRP3/modules/dashboard/dashboard.lua b/totalRP3/modules/dashboard/dashboard.lua index 383b178a3..93461dece 100644 --- a/totalRP3/modules/dashboard/dashboard.lua +++ b/totalRP3/modules/dashboard/dashboard.lua @@ -194,7 +194,7 @@ TRP3_API.dashboard.init = function() end); -- Tab bar - local whatsNewText = loc("WHATS_NEW_7"); + local whatsNewText = loc("WHATS_NEW_8"); local moreModuleText = loc("MORE_MODULES_2"); local aboutText = loc("THANK_YOU_1"); diff --git a/totalRP3/totalRP3.toc b/totalRP3/totalRP3.toc index 006e481f3..da9d7b57d 100644 --- a/totalRP3/totalRP3.toc +++ b/totalRP3/totalRP3.toc @@ -1,7 +1,7 @@ ## Interface: 70100 ## Title: Total RP 3 ## Author: Telkostrasz & Ellypse -## Version: 1.2.5 +## Version: 1.2.6-beta1 ## Notes: Main addon ## URL: http://totalrp3.info ## RequiredDeps: From 44512624c61444c598e3d966db914ee7d6b792ff Mon Sep 17 00:00:00 2001 From: "Renaud \"Ellypse\" Parize" Date: Mon, 20 Feb 2017 12:26:14 +0100 Subject: [PATCH 19/32] Fixed color picker when no color selected --- totalRP3/core/impl/popup.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/totalRP3/core/impl/popup.lua b/totalRP3/core/impl/popup.lua index b7998783f..3b03d8b06 100644 --- a/totalRP3/core/impl/popup.lua +++ b/totalRP3/core/impl/popup.lua @@ -536,7 +536,7 @@ local function initColorBrowser() hidePopups(); TRP3_ColorBrowser:Hide(); if TRP3_ColorBrowser.callback ~= nil then - TRP3_ColorBrowser.callback(TRP3_ColorBrowser.red * 255, TRP3_ColorBrowser.green * 255, TRP3_ColorBrowser.blue * 255); + TRP3_ColorBrowser.callback((TRP3_ColorBrowser.red or 1) * 255, (TRP3_ColorBrowser.green or 1) * 255, (TRP3_ColorBrowser.blue or 1) * 255); end end); end From 511bfdfa70fff34d5778710b37f106f017046124 Mon Sep 17 00:00:00 2001 From: "Renaud \"Ellypse\" Parize" Date: Wed, 1 Mar 2017 14:08:38 +0100 Subject: [PATCH 20/32] Preparing project for CurseForge packager --- .pkgmeta | 31 +++++++++++++++++++++++++++++++ CHANGELOG.md | 12 ++++++++++++ totalRP3/core/impl/globals.lua | 10 +++++++++- totalRP3/totalRP3.toc | 2 +- 4 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 .pkgmeta create mode 100644 CHANGELOG.md diff --git a/.pkgmeta b/.pkgmeta new file mode 100644 index 000000000..dba48f6e8 --- /dev/null +++ b/.pkgmeta @@ -0,0 +1,31 @@ +package-as: totalRP3 +enable-nolib-creation: no + +externals: + # Ace libs + totalRP3/libs/AceAddon-3.0: + url: https://repos.wowace.com/wow/ace3/trunk/AceAddon-3.0 + totalRP3/libs/AceSerializer-3.0: + url: https://repos.wowace.com/wow/ace3/trunk/AceSerializer-3.0 + totalRP3/libs/CallbackHandler-1.0: + url: https://repos.wowace.com/wow/ace3/trunk/CallbackHandler-1.0 + totalRP3/libs/LibStub: + url: https://repos.wowace.com/wow/ace3/trunk/LibStub + totalRP3/libs/LibCompress: + url: https://repos.wowace.com/wow/libcompress/trunk + + # LibDBIcon create a minimap icon for a databroker launcher + totalRP3/libs/LibDBIcon-1.0: + url: https://repos.wowace.com/wow/libdbicon-1-0/trunk + +ignore: + - README.md + - Documents + - totalRP3_zTest + - totalRP3_Debug # Should be moved to something inside the code using Curse's debug tags + - totalRP3_Dev # Should be removed as the version number will be replaced when run from the repo + - totalRP3_Localization + - totalRP3_KuiNameplates # Will be moved as a bundled module + - totalRP3_TipTac # Will be moved as a bundled module + +manual-changelog: CHANGELOG.md \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 000000000..20fe39b4c --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,12 @@ +# Change-log for version @project-version@ of Total RP 3 + +## Bug fixes + +- Fixed several issues with the new chat system introduced in version 1.2.5 that would prevent player names form being colored correctly ([ticket #50](https://wow.curseforge.com/projects/total-rp-3/issues/50)). +- Fixed a Lua error in the new WIM module ([ticket #55](https://wow.curseforge.com/projects/total-rp-3/issues/55)). +- Fixed an issue where the option to increase color contrast on player names in the tooltip was always enabled ([ticket #51](https://wow.curseforge.com/projects/total-rp-3/issues/51)). +- Fixed a Lua error when shift-clicking a spell name in the adventure journal ([ticket #61](https://wow.curseforge.com/projects/total-rp-3/issues/61)). +- Fixed an issue making the game freeze and possibly crash when trying to delete too many companion profiles from the directory. Additionally, companion profiles are now included in the automatic purge ([ticket #56](https://wow.curseforge.com/projects/total-rp-3/issues/56)). +- Fixed a long standing issue allowing advanced users to inject custom icons and color codes in places that were not meant for that, as this behaviour led to game crashes, as well as compatibility issues with other RP add-ons and stability issues in Total RP 3 itself ([ticket #63](https://wow.curseforge.com/projects/total-rp-3/issues/63)). +- The option to increase contrast on color names in the tooltip is now applied on the other colored fields, not just the name field. +- Added notice on the Auto add new players option of the directory to indicate that disabling this option will prevent you from receiving any new profile. \ No newline at end of file diff --git a/totalRP3/core/impl/globals.lua b/totalRP3/core/impl/globals.lua index ffe779d4d..cec606685 100644 --- a/totalRP3/core/impl/globals.lua +++ b/totalRP3/core/impl/globals.lua @@ -39,7 +39,15 @@ TRP3_API = { addon_id_length = 15, version = 26, - version_display = "1.2.5", + + --@debug@ + version_display = "dev", + --@end-debug@ + + --[===[@non-debug@ + version_display = "@project-version@", + --@end-non-debug@]===] + player = UnitName("player"), player_realm = GetRealmName(), diff --git a/totalRP3/totalRP3.toc b/totalRP3/totalRP3.toc index 006e481f3..802e67fb2 100644 --- a/totalRP3/totalRP3.toc +++ b/totalRP3/totalRP3.toc @@ -1,7 +1,7 @@ ## Interface: 70100 ## Title: Total RP 3 ## Author: Telkostrasz & Ellypse -## Version: 1.2.5 +## Version: @project-version@ ## Notes: Main addon ## URL: http://totalrp3.info ## RequiredDeps: From a7b7ffa6921e74bdf86f83f4b2d2e85a8b6e05e1 Mon Sep 17 00:00:00 2001 From: "Renaud \"Ellypse\" Parize" Date: Wed, 1 Mar 2017 14:21:16 +0100 Subject: [PATCH 21/32] Moved TipTac module as a bundled module --- totalRP3/modules/modules.xml | 2 + totalRP3/modules/tiptac/tiptac.lua | 54 ++++++++++++++++++++++++++ totalRP3_TipTac/changelog.md | 4 -- totalRP3_TipTac/totalRP3_TipTac.lua | 60 ----------------------------- totalRP3_TipTac/totalRP3_TipTac.toc | 11 ------ 5 files changed, 56 insertions(+), 75 deletions(-) create mode 100644 totalRP3/modules/tiptac/tiptac.lua delete mode 100644 totalRP3_TipTac/changelog.md delete mode 100644 totalRP3_TipTac/totalRP3_TipTac.lua delete mode 100644 totalRP3_TipTac/totalRP3_TipTac.toc diff --git a/totalRP3/modules/modules.xml b/totalRP3/modules/modules.xml index 914fee4b7..f7b6d9ca0 100644 --- a/totalRP3/modules/modules.xml +++ b/totalRP3/modules/modules.xml @@ -130,4 +130,6 @@ + +