View Single Post
11-13-16, 05:53 PM   #5
Krainz
A Wyrmkin Dreamwalker
Join Date: Oct 2016
Posts: 57
Ok, I read about the addonTable and I think I understood that. I just need to put that line and then just put addonTable before any variable I want to use, right? Like addonTable.alpha and addonTable.fadealpha.

But I still need to make an interface options stuff. I'm taking the config.lua file from Mapster:

Lua Code:
  1. local Mapster = LibStub("AceAddon-3.0"):GetAddon("Mapster")
  2. local L = LibStub("AceLocale-3.0"):GetLocale("Mapster")
  3.  
  4. local optGetter, optSetter
  5. do
  6.     function optGetter(info)
  7.         local key = info[#info]
  8.         return Mapster.db.profile[key]
  9.     end
  10.  
  11.     function optSetter(info, value)
  12.         local key = info[#info]
  13.         Mapster.db.profile[key] = value
  14.         Mapster:Refresh()
  15.     end
  16. end
  17.  
  18. local options, moduleOptions = nil, {}
  19. local function getOptions()
  20.     if not options then
  21.         options = {
  22.             type = "group",
  23.             name = "Mapster",
  24.             args = {
  25.                 general = {
  26.                     order = 1,
  27.                     type = "group",
  28.                     name = "General Settings",
  29.                     get = optGetter,
  30.                     set = optSetter,
  31.                     args = {
  32.                         intro = {
  33.                             order = 1,
  34.                             type = "description",
  35.                             name = L["Mapster allows you to control various aspects of your World Map. You can change the style of the map, control the plugins that extend the map with new functionality, and configure different profiles for every of your characters."],
  36.                         },
  37.                         alphadesc = {
  38.                             order = 2,
  39.                             type = "description",
  40.                             name = L["You can change the transparency of the world map to allow you to continue seeing the world environment while your map is open for navigation."],
  41.                         },
  42.                         fade = {
  43.                             order = 2.2,
  44.                             type = "toggle",
  45.                             name = MAP_FADE_TEXT,
  46.                             desc = L["The map will fade out to the configured Fade Alpha level when you start moving."],
  47.                             get = function() return GetCVarBool("mapFade") end,
  48.                             set = function(_, v) v = v and 1 or 0; SetCVar("mapFade", v); end,
  49.                             width = "full",
  50.                         },
  51.                         alpha = {
  52.                             order = 3,
  53.                             name = L["Alpha"],
  54.                             desc = L["The transparency of the big map."],
  55.                             type = "range",
  56.                             min = 0, max = 1, bigStep = 0.01,
  57.                             isPercent = true,
  58.                         },
  59.                         fadealpha = {
  60.                             order = 4.1,
  61.                             type = "range",
  62.                             name = L["Faded Alpha"],
  63.                             desc = L["The transparency of the map while you are moving and the map is faded."],
  64.                             get = function() return WORLD_MAP_MIN_ALPHA end,
  65.                             set = function(_, v) SetCVar("mapAnimMinAlpha", v); WORLD_MAP_MIN_ALPHA = v end,
  66.                             min = 0, max = 1, bigStep = 0.01,
  67.                             isPercent = true,
  68.                             disabled = function() return not GetCVarBool("mapFade") end,
  69.                         },
  70.                         scaledesc = {
  71.                             order = 5,
  72.                             type = "description",
  73.                             name = L["Change the scale of the world map if you do not want the whole screen filled while the map is open."],
  74.                         },
  75.                         scale = {
  76.                             order = 6,
  77.                             name = L["Scale"],
  78.                             desc = L["Scale of the big map."],
  79.                             type = "range",
  80.                             min = 0.1, max = 2, bigStep = 0.01,
  81.                             isPercent = true,
  82.                         },
  83.                         arrowScale = {
  84.                             order = 7,
  85.                             name = L["PlayerArrow Scale"],
  86.                             desc = L["Adjust the size of the Player Arrow on the Map for better visibility."],
  87.                             type = "range",
  88.                             min = 0.5, max = 2, bigStep = 0.01,
  89.                             isPercent = true,
  90.                         },
  91.                         nl = {
  92.                             order = 10,
  93.                             type = "description",
  94.                             name = "",
  95.                         },
  96.                         poiScale = {
  97.                             order = 12,
  98.                             type = "range",
  99.                             name = L["POI Scale"],
  100.                             desc = L["Scale of the POI Icons on the Map."],
  101.                             min = 0.1, max = 2, bigStep = 0.01,
  102.                             isPercent = true,
  103.                         },
  104.                         ejScale = {
  105.                             order = 13,
  106.                             type = "range",
  107.                             name = L["EJ Icon Scale"],
  108.                             desc = L["Scale of the Encounter Journal Icons on the Map."],
  109.                             min = 0.1, max = 2, bigStep = 0.01,
  110.                             isPercent = true,
  111.                         },
  112.                         nl2 = {
  113.                             order = 20,
  114.                             type = "description",
  115.                             name = "",
  116.                         },
  117.                         hideMapButton = {
  118.                             order = 21,
  119.                             type = "toggle",
  120.                             name = L["Hide Map Button"],
  121.                         },
  122.                         disableMouse = {
  123.                             order = 22,
  124.                             type = "toggle",
  125.                             name = L["Disable Mouse"],
  126.                             desc = L["Disable the mouse interactivity of the main map, eg. to change zones."],
  127.                         },
  128.                     },
  129.                 },
  130.             },
  131.         }
  132.         for k,v in pairs(moduleOptions) do
  133.             options.args[k] = (type(v) == "function") and v() or v
  134.         end
  135.     end
  136.    
  137.     return options
  138. end
  139.  
  140. local function optFunc()
  141.     -- open the profiles tab before, so the menu expands
  142.     InterfaceOptionsFrame_OpenToCategory(Mapster.optionsFrames.Profiles)
  143.     InterfaceOptionsFrame_OpenToCategory(Mapster.optionsFrames.Mapster)
  144.     InterfaceOptionsFrame:Raise()
  145. end
  146.  
  147. function Mapster:SetupOptions()
  148.     self.optionsFrames = {}
  149.  
  150.     -- setup options table
  151.     LibStub("AceConfigRegistry-3.0"):RegisterOptionsTable("Mapster", getOptions)
  152.     self.optionsFrames.Mapster = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("Mapster", nil, nil, "general")
  153.  
  154.     self:RegisterModuleOptions("Profiles", LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db), "Profiles")
  155.  
  156.     LibStub("AceConsole-3.0"):RegisterChatCommand( "mapster", optFunc)
  157. end
  158.  
  159. function Mapster:RegisterModuleOptions(name, optionTbl, displayName)
  160.     moduleOptions[name] = optionTbl
  161.     self.optionsFrames[name] = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("Mapster", displayName, "Mapster", name)
  162. end

From reading it I can understand that there's this MAP_FADE_TEXT variable thing with SetCVar("mapFade"). How would I make that useful in the Hello World example I first posted?

Something like 'if addonTable.SetCVar("mapFade") = 1 then print("Hello World!") end'?

I'm including this in my .toc already:

Code:
#@no-lib-strip@
Libs\LibStub\LibStub.lua
Libs\CallbackHandler-1.0\CallbackHandler-1.0.xml

Libs\AceAddon-3.0\AceAddon-3.0.xml
Libs\AceEvent-3.0\AceEvent-3.0.xml
Libs\AceHook-3.0\AceHook-3.0.xml
Libs\AceDB-3.0\AceDB-3.0.xml
Libs\AceDBOptions-3.0\AceDBOptions-3.0.xml
Libs\AceLocale-3.0\AceLocale-3.0.xml

Libs\AceGUI-3.0\AceGUI-3.0.xml
Libs\AceConsole-3.0\AceConsole-3.0.xml
Libs\AceConfig-3.0\AceConfig-3.0.xml
#@end-no-lib-strip@
  Reply With Quote