Thread Tools Display Modes
08/16/15, 10:04 AM   #21
Randactyl
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 251
Continuing with localization, I like to have all of my strings in the same file so they are all in the same place when I need to edit them. Then I can use metatables to set a fallback option if I haven't gotten a particular string translated yet.

Lua Code:
  1. local strings = {
  2.     ["de"] = {
  3.         ["SI_MYADDON_NAME"] = "My German Addon name",
  4.     },
  5.     ["en"] = {
  6.         ["SI_MYADDON_NAME"] = "My Addon name",
  7.         ["SI_MYADDON_GENERAL_OPTIONS_HEADER"] = "General Options",
  8.     },
  9. }
  10.  
  11. setmetatable(strings["de"], {__index = strings["en"]})
  12.  
  13. local function AddStringsToGame()
  14.     local lang = GetCVar("language.2")
  15.     if strings[lang] == nil then lang = "en" end
  16.  
  17.     for i,v in pairs(strings[lang]) do
  18.         ZO_CreateStringId(i, v)
  19.     end
  20. end
  21.  
  22. AddStringsToGame()

After the index metatabe is set, strings["de"] essentially becomes a union of the original strings["de"] and strings["en"] with any matching keys pulled from strings["de"] rather than strings["en"]:

Lua Code:
  1. strings["de"] = {
  2.     ["SI_MYADDON_NAME"] = "My German Addon name",
  3.     ["SI_MYADDON_GENERAL_OPTIONS_HEADER"] = "General Options",
  4. }

As for exactly why this works or what else you can use metatables for, I couldn't tell you. Metatables are basically magic to me right now

I think making the decision to use this over votan's SafeAddString example really just comes down to personal preference. I suppose my method hogs more memory, but that shouldn't be an issue unless there are a lot of strings. If it did become an issue you could just nil the local strings table after the necessary ones were added to the game.
  Reply With Quote
08/16/15, 02:47 PM   #22
merlight
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 671
@Randactyl that's not how it works.

strings["de"] is still the same table. The metatable's __index provides fallback values for missing keys. But it's only scanned when you explicitly request a missing key, e.g.
strings["de"]["SI_MYADDON_GENERAL_OPTIONS_HEADER"]. Iterating over it with next/pairs will only see SI_MYADDON_NAME, because that's the only key in the table itself.

To make it work, you need to iterate over the "en" table:
Lua Code:
  1. for k in next, strings["en"] do
  2.     ZO_CreateStringId(k, strings[lang][k])
  3. end

On a positive note, you don't have to clean the local strings table -- it should be garbage-collected afterwards.

Last edited by merlight : 08/16/15 at 02:50 PM.
  Reply With Quote
08/17/15, 01:16 PM   #23
Randactyl
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 251
Hmm alrighty then, thanks!
  Reply With Quote
10/25/16, 03:53 AM   #24
Letho
AddOn Author - Click to view addons
Join Date: Apr 2016
Posts: 238
I know this thread is old but my problem is quite related to the scene manager. It's acting very funny right know.

What I am doing:

Code:
-- self.aura[auraName] is a top level control

self.aura[auraName].sceneFragment = ZO_SimpleSceneFragment:New(self.aura[auraName]);
HUD_SCENE:AddFragment(AuraMastery.aura[auraName].sceneFragment);
Create the fragment and assign it to the HUD_SCENE.



I am using a registered update handler to listen for desired (de-)buffs. This handler simply looks at a specified frequency if the effect is present and sets the boolean variable 'display' to true or false depending on wether the effect is present or not

Code:
HUD_SCENE:RemoveFragment(AuraMastery.aura[auraName].sceneFragment);		
if (display) then
    HUD_SCENE:AddFragment(AuraMastery.aura[auraName].sceneFragment);

    (...)
Remove set fragment if the buff/debuff is not present, then check if it is present (display = true). IF it is present, add the fragment to the scene again.

In clearer words, I:

1. create a top level control (TLC)
2. make it a shard
3. assign this shard to HUD_SCENE

4. updating handler (updating every 5frames):
check if aura is present
=>
if (not present): remove the shard from HUD_SCENE
else add the shard from HUD_SCENE






My problem: The control is visible if I start the game. To make it work I have to /reloadui, then everything runs flawlessly. Any ideas?

Last edited by Letho : 10/25/16 at 04:34 AM.
  Reply With Quote

ESOUI » Developer Discussions » General Authoring Discussion » What is a Scene, the SceneManager and other concepts

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