Quantcast
Multilanguage - WoWInterface
Thread Tools Display Modes
06-23-13, 04:18 PM   #1
Seilem
A Murloc Raider
Join Date: Jul 2012
Posts: 4
Multilanguage

Hi. Is there a function for the title of the bosses?To avoid translating the bosses for different languages​​.
p.s. Sorry my bad english =(
  Reply With Quote
06-23-13, 07:21 PM   #2
p3lim
A Pyroguard Emberseer
 
p3lim's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 1,703
Code:
tonumber(string.sub(UnitGUID('target') or '', -12, -9), 16)
This can be used to get the creatureID of your target which is locale independant and you can pull IDs from wowhead.com.
  Reply With Quote
06-24-13, 12:32 AM   #3
Seilem
A Murloc Raider
Join Date: Jul 2012
Posts: 4
Originally Posted by p3lim View Post
Code:
tonumber(string.sub(UnitGUID('target') or '', -12, -9), 16)
This can be used to get the creatureID of your target which is locale independant and you can pull IDs from wowhead.com.
it's return id from target.
Me need
Lua Code:
  1. sha = UnitName("60491") -- Sha of Anger id
  2. print (sha);
how?
  Reply With Quote
06-24-13, 12:52 AM   #4
Dridzt
A Pyroguard Emberseer
 
Dridzt's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 1,257
Your best option is probably getting them from the Encounter Journal.
  Reply With Quote
06-24-13, 01:03 AM   #5
Seilem
A Murloc Raider
Join Date: Jul 2012
Posts: 4
Originally Posted by Dridzt View Post
Your best option is probably getting them from the Encounter Journal.
can be an example?
  Reply With Quote
06-24-13, 10:06 AM   #6
ravagernl
Proceritate Corporis
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 1,176
Originally Posted by Seilem View Post
can be an example?
Have you tried searching? It's not hard to google "encounter journal functions".

http://lmgtfy.com/?q=encounter+journal+functions
  Reply With Quote
06-24-13, 10:51 AM   #7
Dridzt
A Pyroguard Emberseer
 
Dridzt's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 1,257
To be fair I posted that half-asleep and re-reading his request I don't think the Encounter Journal will help.
It uses some internal creatureIDs that are not related to the NPCid we can get from parsing the GUID for example.

Without knowing more about what exactly he needs boss names for I don't think we can help.
Need some context.
  Reply With Quote
06-24-13, 11:51 AM   #8
Vlad
A Molten Giant
 
Vlad's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2005
Posts: 792
Originally Posted by Dridzt View Post
what exactly he needs boss names for

I think we can help regardless of his goals.

I reckon one has to use tooltip scanning, meaning the creature must be in the cache, otherwise a internal id to name database is required. It's true, this means the creatures must be in the cache for him to be able to get their localized names. Alternatively internal addon database over id and name is in order, but hopefully not needed.

Here is my example using a cache system:
Code:
local tooltip = CreateFrame("GameTooltip", "ExampleTooltipScanner", UIParent, "GameTooltipTemplate")

tooltip = setmetatable(tooltip, {__index = function(self, id)
  self:SetOwner(UIParent, "ANCHOR_NONE")
  self:SetHyperlink(("unit:0xF53%05X00000000"):format(id))
  local name
  if self:IsShown() then
    for i = 1, self:NumLines() do
      local text = _G[self:GetName() .. "TextLeft" .. i]
      if text and text.GetText then
        name = text:GetText()
        break
      end
    end
  end
  self:Hide()
  self[id] = name
  return name
end})
Note it doesn't handle errors, i.e. if it says "Retrieving data..." it will literally store that, or any other message on the tooltip. Just a heads up, can be fixed by making sure it only stores the "name" value when it's appropriate.
__________________
Profile: Curse | Wowhead
  Reply With Quote
06-24-13, 02:06 PM   #9
Seilem
A Murloc Raider
Join Date: Jul 2012
Posts: 4
Good! Thanks!
  Reply With Quote
06-24-13, 05:39 PM   #10
Vlad
A Molten Giant
 
Vlad's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2005
Posts: 792
I forgot to add that you query using tooltip[id] and it returns the string that it read from the tooltip, or nil if nothing (not cached).
__________________
Profile: Curse | Wowhead
  Reply With Quote
06-27-13, 11:59 AM   #11
Choonstertwo
A Chromatic Dragonspawn
 
Choonstertwo's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2011
Posts: 194
Originally Posted by Vlad View Post
I think we can help regardless of his goals.

I reckon one has to use tooltip scanning, meaning the creature must be in the cache, otherwise a internal id to name database is required. It's true, this means the creatures must be in the cache for him to be able to get their localized names. Alternatively internal addon database over id and name is in order, but hopefully not needed.

Here is my example using a cache system:
Code:
local tooltip = CreateFrame("GameTooltip", "ExampleTooltipScanner", UIParent, "GameTooltipTemplate")

tooltip = setmetatable(tooltip, {__index = function(self, id)
  self:SetOwner(UIParent, "ANCHOR_NONE")
  self:SetHyperlink(("unit:0xF53%05X00000000"):format(id))
  local name
  if self:IsShown() then
    for i = 1, self:NumLines() do
      local text = _G[self:GetName() .. "TextLeft" .. i]
      if text and text.GetText then
        name = text:GetText()
        break
      end
    end
  end
  self:Hide()
  self[id] = name
  return name
end})
Note it doesn't handle errors, i.e. if it says "Retrieving data..." it will literally store that, or any other message on the tooltip. Just a heads up, can be fixed by making sure it only stores the "name" value when it's appropriate.
Shouldn't that __index metamethod be checking the regular tooltip __index table at some point? That's where all the tooltip methods are stored and your metamethod seems to bypass it completely.

Alternatively, use a separate table as a self-generating cache instead of overloading the tooltip itself.
  Reply With Quote
06-27-13, 12:44 PM   #12
Vlad
A Molten Giant
 
Vlad's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2005
Posts: 792
Originally Posted by Choonstertwo View Post
Shouldn't that __index metamethod be checking the regular tooltip __index table at some point? That's where all the tooltip methods are stored and your metamethod seems to bypass it completely.

Alternatively, use a separate table as a self-generating cache instead of overloading the tooltip itself.
It does use tooltip to store, it's both a table and a widget and if you try tooltip[1234] and it doesn't exist, then it calls the function at __index to do a lookup and store the result string at that position, so next time you call tooltip[1234] it returns the string instead of doing a lookup. I refer to the tooltip object using "self" in the function, it's the same object.
__________________
Profile: Curse | Wowhead
  Reply With Quote
06-28-13, 02:45 AM   #13
Choonstertwo
A Chromatic Dragonspawn
 
Choonstertwo's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2011
Posts: 194
Originally Posted by Vlad View Post
It does use tooltip to store, it's both a table and a widget and if you try tooltip[1234] and it doesn't exist, then it calls the function at __index to do a lookup and store the result string at that position, so next time you call tooltip[1234] it returns the string instead of doing a lookup. I refer to the tooltip object using "self" in the function, it's the same object.
Yes, but all the tooltip's methods like :NumLines and :SetOwner are stored in the original tooltip metatable's __index table rather than the tooltip itself. Your __index function seems to bypass this table, meaning it can't access the methods.
  Reply With Quote
06-28-13, 03:33 AM   #14
Vlad
A Molten Giant
 
Vlad's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2005
Posts: 792
If that's the case, then replacing:
Code:
tooltip = setmetatable(tooltip, {__index = function(self, id)
with
Code:
getmetatable(tooltip).__index = function(self, id)
should fix the problem, no?
__________________
Profile: Curse | Wowhead
  Reply With Quote
06-28-13, 04:02 AM   #15
Choonstertwo
A Chromatic Dragonspawn
 
Choonstertwo's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2011
Posts: 194
Originally Posted by Vlad View Post
If that's the case, then replacing:
Code:
tooltip = setmetatable(tooltip, {__index = function(self, id)
with
Code:
getmetatable(tooltip).__index = function(self, id)
should fix the problem, no?
No, that would change the __index for every tooltip object (since they all share a metatable).

I'd change this:
lua Code:
  1. local tooltip = CreateFrame("GameTooltip", "ExampleTooltipScanner", UIParent, "GameTooltipTemplate")
  2.  
  3. tooltip = setmetatable(tooltip, {__index = function(self, id)
  4.     self:SetOwner(UIParent, "ANCHOR_NONE")
  5.     self:SetHyperlink(("unit:0xF53%05X00000000"):format(id))
  6.     ...

To this:
lua Code:
  1. local tooltip = CreateFrame("GameTooltip", "ExampleTooltipScanner", UIParent, "GameTooltipTemplate")
  2.  
  3. local tooltipMethods = getmetatable(tooltip).__index
  4. tooltip = setmetatable(tooltip, {__index = function(self, id)
  5.     local method = tooltipMethods[id] -- See if this key is a tooltip method
  6.     if method then return method end -- If it is, return the method now
  7.  
  8.     -- Otherwise look up a unit
  9.     self:SetOwner(UIParent, "ANCHOR_NONE")
  10.     self:SetHyperlink(("unit:0xF53%05X00000000"):format(id))
  11.     ...
  Reply With Quote
06-28-13, 07:44 AM   #16
Vlad
A Molten Giant
 
Vlad's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2005
Posts: 792
Ah right. Fyi I never posted what I posted as a "working sample" I just sketched, but you are right about the metatable issue that arose. I guess it would be easiest to simply have two object, one being the tooltip and one just being the cache table. Assigning the metatable to the cache table instead the tooltip.
__________________
Profile: Curse | Wowhead
  Reply With Quote
06-28-13, 07:52 AM   #17
Choonstertwo
A Chromatic Dragonspawn
 
Choonstertwo's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2011
Posts: 194
Originally Posted by Vlad View Post
Ah right. Fyi I never posted what I posted as a "working sample" I just sketched, but you are right about the metatable issue that arose. I guess it would be easiest to simply have two object, one being the tooltip and one just being the cache table. Assigning the metatable to the cache table instead the tooltip.
Yeah, that would probably be slightly simpler and more efficient.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Multilanguage

Thread Tools
Display Modes

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