View Single Post
11/05/18, 03:23 AM   #2
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,963
If you got questions check the Wiki first and maybe visit us in the gitter ESOUI chat:
https://gitter.im/esoui/esoui

I'd say you start with reading this great tutorials first toi get more details about ESO and lua API:
https://wiki.esoui.com/Writing_your_first_addon
https://wiki.esoui.com/SimpleNotebookTutorial/part1

Originally Posted by Pollox View Post
To update a control's texture based on a value from lua, I store a reference to the control in lua when it's created, and use that reference later to update it. Is there a better way to couple the data to the gui?
Yeah, most of the time the texture controls will be created with a unique name and then youa ccess them this way.
You can also create a globalk name for your addon like
Lua Code:
  1. myAddonGlobalName = myAddonGlobalName or {}

myAddonGlobalName is a tbale then and you can add other subtables and add all controls to this subtable then like this:
Lua Code:
  1. myAddonGlobalName.myTextureControls = {}
  2. myAddonGlobalName.myTextureControls["textureForButton1"] = myTextureControl


Texture control texture change:
You define the texture control and you can then add the textures to use (pressed down, mouse over, up disabled) to this control as attributes like
Code:
myTextureControl.upTex = "/esoui/art...dds"
myTextureControl.downTex = "/esoui/art...dds"
In your code you could then easily use
Lua Code:
  1. myTexture:SetTexture(myTexture.downTex)
.

It depends on the texture control! If it's a button you can set the textures for up, down etc. before properly to the given button texture slots and it will handle it on it's own.

Maybe check the addon AdvancedFilters how it uses the textures. They are stored in the file textures.lua like this:
Lua Code:
  1. local textures = {
  2.     All = "esoui/art/inventory/inventory_tabicon_all_%s.dds",
  3. }
In the code the placeholder %s is replaced then with the state, like up, down, disabled:

Lua Code:
  1. local icon = {
  2.         up = string.format(iconPath, "up"),
  3.         down = string.format(iconPath, "down"),
  4.         over = string.format(iconPath, "over"),
  5.     }
  6.  
  7.  local button = WINDOW_MANAGER:CreateControlFromVirtual(self.control:GetName() .. subfilterName .. "Button", self.control, "AF_Button")
  8.     local texture = button:GetNamedChild("Texture")
  9.     local highlight = button:GetNamedChild("Highlight")
  10.  
  11.     texture:SetTexture(icon.up)
  12.     highlight:SetTexture(icon.over)
  13.  
  14. local function OnMouseEnter(thisButton)
  15.         ZO_Tooltips_ShowTextTooltip(thisButton, TOP, AF.strings[subfilterName])
  16.  
  17.         local clickable = thisButton.clickable
  18.         local active = self:GetCurrentButton() == thisButton
  19.  
  20.         if clickable and not active then
  21.             highlight:SetHidden(false)
  22.         end
  23.     end
  24.  
  25.     local function OnMouseExit()
  26.         ZO_Tooltips_HideTextTooltip()
  27.  
  28.         highlight:SetHidden(true)
  29.     end
  30.  
  31.  
  32.   button:SetHandler("OnClicked", OnClicked)
  33.     button:SetHandler("OnMouseEnter", OnMouseEnter)
  34.     button:SetHandler("OnMouseExit", OnMouseExit)
  35.  
  36.     button.texture = texture
  37.     button.up = icon.up
  38.     button.down = icon.down

AdvancedFilters creates a new "virtual control" (a kind of a template to use for your addon) "AF_Button" (given as last parameter in WINDOW_MANAGER:CreateControlFromVirtual). This AF_Button is defined in the XML file so the texture and highlight controls are added to the standard control automatically and you are able touse it.

Code:
<!-- Base Button -->
        <Button name="AF_Button" font="ZoFontGameMedium" virtual="true" hidden="false">
            <Dimensions x="32" y="32" />

            <Controls>
                <Texture name="$(parent)Texture" hidden="false">
                    <Anchor point="TOPLEFT" relativeTo="$(parent)" relativePoint="TOPLEFT" />
                    <Anchor point="BOTTOMRIGHT" relativeTo="$(parent)" relativePoint="BOTTOMRIGHT" />
                </Texture>

                <Texture name="$(parent)Highlight" hidden="true" blendMode="ADD">
                    <Anchor point="TOPLEFT" relativeTo="$(parent)" relativePoint="TOPLEFT" />
                    <Anchor point="BOTTOMRIGHT" relativeTo="$(parent)" relativePoint="BOTTOMRIGHT" />
                </Texture>
            </Controls>
        </Button>
Originally Posted by Pollox View Post
I started work on localization, but was confused by the various ways I've seen other addons do this. Any advice on the best way to proceed with my localization code?
Best approach imo is using the txt file to load different <langugage>.lua files depending on your client's language.
Your addon.txt (manifest) just uses a game's variable $(language) which provides the client language in this format: 2characters, e.g. en, or de or fr or jp or ru or es or ...

So just load a base file which contains the strings in e.g. English like this:
Code:
/lang/base.lua
And then add a line below to load the file for the client language dynamically using:
Code:
/lang/$(language).lua
In your base file define the strings
Lua Code:
  1. ZO_CreateStringId(GLOBALLY_UNIQUE_STRING_ID, "Translation")
-> GLOBALLY_UNIQUE_STRING_ID is an integer variable, a constant. The name should start with SI_ + your addon name, e.g.
Code:
SI_YOURADDON_SETTINGS_ONLY_IN_COMBAT
SI_YOURADDON_SETTINGS_ONLY_IN_COMBAT_TT  for the tooltip
This is missing in the wiki:
Do not just overwrite the translated strings using the same function as it was created, ZO_CreateStringId!
In the client language files "safe overwrite" them with a newer version in teh client's language:
SafeAddString(SI_YOURADDON_SETTINGS_ONLY_IN_COMBAT, "Translated text here", 1)
The 1 is the version I think.
So this will provide you the translated string into the variable SI_YOURADDON_SETTINGS_ONLY_IN_COMBAT

You can read the text from the variables then via AP function
Lua Code:
  1. GetString(SI_YOURADDON_SETTINGS_ONLY_IN_COMBAT)

So just put the GetString into your addons code at e.g. LAM settings menu
Lua Code:
  1. name = GetString(SI_YOURADDON_SETTINGS_ONLY_IN_COMBAT),
  2. tooltip = SI_YOURADDON_SETTINGS_ONLY_IN_COMBAT_TT),

Description can be found here:
https://wiki.esoui.com/How_to_add_localization_support

Originally Posted by Pollox View Post
Do control names have to be unique across my entire application, or can I use the parent control as a scope for it? For example, my controls use $(parent) as a prefix for the name, which leads to long names with several prefixes the more I nest my controls.
You can define a top level control and assign your controls to it. You can do that by using XML or lua code, your choice.
See the wiki for examples:
https://wiki.esoui.com/Writing_your_...ical_component

Last edited by Baertram : 11/05/18 at 03:38 AM.