Thread Tools Display Modes
10/01/15, 02:16 PM   #1
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,579
Bug in LocalizeString

I have done some experiments with image tags in text buffer controls and found something I believe is a bug in LocalizeString.

What I tried to achieve was putting a small icon in front of name links when the player is a friend or guild mate.
In order to do this, I post hooked the ZO_LinkHandler_CreateLink method and modified the link if applicable.
Lua Code:
  1. local originalCreateLink = ZO_LinkHandler_CreateLink
  2. ZO_LinkHandler_CreateLink = function(text, color, linkType, rawName, ...)
  3.     local link = originalCreateLink(text, color, linkType, rawName, ...)
  4.     if((linkType == DISPLAY_NAME_LINK_TYPE or linkType == CHARACTER_LINK_TYPE) and currentChannel > LINK_INDICATORS_DISABLED) then
  5.         if(linkType == DISPLAY_NAME_LINK_TYPE and not IsDecoratedDisplayName(rawName)) then
  6.             rawName = DecorateDisplayName(rawName)
  7.         end
  8.         link = AddChatIndicators(link, rawName, currentChannel)
  9.     end
  10.     return link
  11. end
This works fine in general, but I noticed that it would corrupt the character name link in the friend status messages like this:
Code:
|t12:12:SocialIndicators/images/epact/friendicon.dds|t|H1:character:Some-Friend-Of-Mine^Mx[Some-Friend-Of-Mine.|h
So I started looking what could cause this issue and first put a d(link) after the AddChatIndicators line in the code above.
To my surprise it showed the correct output for the debug output, so it didn't seem to be something that happens in my own code.

Next I checked the spot where the output was generated which is in the EVENT_FRIEND_PLAYER_STATUS_CHANGED handler in chathandlers.lua.
Lua Code:
  1. ...
  2. if(characterName ~= "") then
  3.     local characterNameLink = ZO_LinkHandler_CreateCharacterLink(characterName)
  4.     return zo_strformat(SI_FRIENDS_LIST_FRIEND_CHARACTER_LOGGED_ON, displayNameLink, characterNameLink)
  5. else
  6. ...
There doesn't happen anything between creating the link and putting together the output which is returned by this function and the output doesn't get changed after it is returned and handled in the chat system, so I tried to eliminate some other potential causes and directly printed the message like this using ZAM-Notebook:
Lua Code:
  1. local handlers = ZO_ChatSystem_GetEventHandlers()
  2. d(handlers[EVENT_FRIEND_PLAYER_STATUS_CHANGED]("@SomeFriend", "Some-Friend-Of-Mine^Mx", PLAYER_STATUS_OFFLINE, PLAYER_STATUS_ONLINE)
For some reason it didn't corrupt the output like before but now simply didn't show the name at all after the icon.

The display name links are shown without a problem, so I next tried to see what makes them different.
I reduced my code to
Lua Code:
  1. local icon = "|t12:12:|t"
  2. local link = "|H1:character:Some-Friend-Of-Mine^Mx|h[Some-Friend-Of-Mine]|h"
  3. d(LocalizeString("<<1>>", icon .. link))
which only shows a white box, but not the character link when called.
When I directly print the icon and link without putting it through LocalizeString it works fine.

I tried to replace each of the elements of the link individually and found that it does work as long as the caret (^) is not present.

Seeing as formatting works fine with only the character link and no icon and also how the display link didn't get influenced by the character link, I tried a few different combinations.

Lua Code:
  1. local icon = "|t12:12:|t"
  2. local link = "|H1:character:The-Bug-Is-Real^Mx|h[The-Bug-Is-Real]|h"
  3. d(LocalizeString("1:<<1>>", link .. icon))
  4. d(LocalizeString("2:<<1>><<2>>", link, icon))
  5. d(LocalizeString("3:<<1>>", icon .. link))
  6. d(LocalizeString("4:<<1>><<2>>", icon, link))
  7. d(LocalizeString("5:<<1>>", link .. link))
  8. d(LocalizeString("6:<<1>><<2>>", link, link))
  9. d(LocalizeString("7:<<1>>", icon .. icon))
  10. d(LocalizeString("8:<<1>><<2>>", icon, icon))
Without the caret it works as expected:

As soon as I put it in again, it won't work when there is a link and some other tag in the same argument:


Which leads me to believe that there is a bug in LocalizeString that causes this behavior.

Bonus bug:
I experimented with the icon tag to see if there is maybe a hidden fourth argument that allows me to change the color or something and randomly put in something like this:
Lua Code:
  1. local icon = "|t12:12::cc0000|t"
Which caused the link to show up again similar to the first result in this post.
After playing around a bit more I reduced it to
Lua Code:
  1. local icon = "|t12:12:c|t"
which seems to be the only letter that causes this behavior.

conclusion:
I don't expect this to be fixed any time soon, so I now use a workaround by replacing the formatter function and passing the icon and character link to zo_strformat separately. On the plus side this also allows me to reduce the look ups for one player as I can use the same icons for the player link and character link.
Lua Code:
  1. local function InitializePlayerStatusMessageWorkaround()
  2.     local loggonMessage = GetString(SI_FRIENDS_LIST_FRIEND_CHARACTER_LOGGED_ON):gsub("<<2>>", "<<2>><<3>><<4>>")
  3.     local loggoffMessage = GetString(SI_FRIENDS_LIST_FRIEND_CHARACTER_LOGGED_OFF):gsub("<<2>>", "<<2>><<3>><<4>>")
  4.     local handlers = ZO_ChatSystem_GetEventHandlers()
  5.     handlers[EVENT_FRIEND_PLAYER_STATUS_CHANGED] = function(displayName, characterName, oldStatus, newStatus)
  6.         local wasOnline = oldStatus ~= PLAYER_STATUS_OFFLINE
  7.         local isOnline = newStatus ~= PLAYER_STATUS_OFFLINE
  8.         local oldChannel = currentChannel
  9.         currentChannel = LINK_INDICATORS_DISABLED
  10.  
  11.         if(not wasOnline and isOnline) then
  12.             local friend, guild = GetLinkIndicators(displayName, LINK_INDICATORS_AUTO)
  13.             local displayNameLink = friend .. guild .. ZO_LinkHandler_CreateDisplayNameLink(displayName)
  14.             if(characterName ~= "") then
  15.                 local characterNameLink = ZO_LinkHandler_CreateCharacterLink(characterName)
  16.                 return zo_strformat(loggonMessage, displayNameLink, friend, guild, characterNameLink)
  17.             else
  18.                 return zo_strformat(SI_FRIENDS_LIST_FRIEND_LOGGED_ON, displayNameLink)
  19.             end
  20.         elseif(wasOnline and not isOnline) then
  21.             local friend, guild = GetLinkIndicators(displayName, LINK_INDICATORS_AUTO)
  22.             local displayNameLink = friend .. guild .. ZO_LinkHandler_CreateDisplayNameLink(displayName)
  23.             if(characterName ~= "") then
  24.                 local characterNameLink = ZO_LinkHandler_CreateCharacterLink(characterName)
  25.                 return zo_strformat(loggoffMessage, displayNameLink, friend, guild, characterNameLink)
  26.             else
  27.                 return zo_strformat(SI_FRIENDS_LIST_FRIEND_LOGGED_OFF, displayNameLink)
  28.             end
  29.         end
  30.         currentChannel = oldChannel
  31.     end
  32. end

I hope this was interesting for someone and if you like it, I can write more post like this in the future. (I probably will, even if you don't like it )

Last edited by sirinsidiator : 10/01/15 at 02:25 PM.
  Reply With Quote
10/01/15, 03:08 PM   #2
merlight
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 671
Originally Posted by sirinsidiator View Post
I experimented with the icon tag to see if there is maybe a hidden fourth argument that allows me to change the color or something and randomly put in something like this:
Lua Code:
  1. local icon = "|t12:12::cc0000|t"
I don't know about direct color value, but the fourth argument can be "inheritColor", which makes the texture take the text color of the control (iirc it works inside Label, not sure about TextBuffer).
Lua Code:
  1. string.format("|t%d:%d:%s:inheritcolor|t", width, height, path)
  2.  
  3. -- btw while looking for this I also found how to specify dimensions in percent
  4. -- (of original texture size, I guess)
  5. ("|t%f%%:%f%%:%s|t"):format(widthPercent, heightPercent, path)
  Reply With Quote
10/01/15, 03:15 PM   #3
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,579
Nice catch!
I tried it like this just now and get a red box:
Lua Code:
  1. d("|cff0000|t12:12::inheritcolor|t")
This will safe me some trouble in the future. Making all icons for all alliance colors is a waste of time and space
  Reply With Quote

ESOUI » Developer Discussions » General Authoring Discussion » Bug in LocalizeString


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off