Facebook
From dslkdssdklsdlksdflksdfklsdf, 6 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 250
  1. --[[
  2.         This file is part of 'Masque', an add-on for World of Warcraft. For license information,
  3.         please see the included License.txt file.
  4.  
  5.         * File...: Masque.lua
  6.         * Author.: StormFX
  7.  
  8. ]]
  9.  
  10. local MASQUE, Core = ...
  11.  
  12. -- Lua Functions
  13. local print = print
  14.  
  15. ----------------------------------------
  16. -- Libraries, etc.
  17. ----------------------------------------
  18.  
  19. -- GLOBALS: LibStub
  20.  
  21. assert(LibStub, "Masque requires LibStub.")
  22. local Masque = LibStub("AceAddon-3.0"):NewAddon(MASQUE)
  23.  
  24. Core.API = LibStub:NewLibrary(MASQUE, 70200)
  25. Core.Version = GetAddOnMetadata(MASQUE, "Version")
  26.  
  27. local ACR = LibStub("AceConfigRegistry-3.0")
  28.  
  29. local LDB = LibStub("LibDataBroker-1.1", true)
  30. local LDBI = LibStub("LibDBIcon-1.0", true)
  31.  
  32. local L = Core.Locale
  33.  
  34. ----------------------------------------
  35. -- Basic Options Table
  36. ----------------------------------------
  37.  
  38. Core.Options = {
  39.         type = "group",
  40.         name = MASQUE,
  41.         args = {
  42.                 General = {
  43.                         type = "group",
  44.                         name = L["General"],
  45.                         order = 0,
  46.                         args = {},
  47.                 },
  48.         },
  49. }
  50.  
  51. ----------------------------------------
  52. -- ADDON_LOADED Event
  53. ----------------------------------------
  54.  
  55. function Masque:OnInitialize()
  56.         local Defaults = {
  57.                 profile = {
  58.                         Debug = false,
  59.                         Groups = {
  60.                                 ["*"] = {
  61.                                         Inherit = true,
  62.                                         Disabled = false,
  63.                                         SkinID = "Blizzard",
  64.                                         Gloss = 0,
  65.                                         Backdrop = false,
  66.                                         Colors = {},
  67.                                 },
  68.                         },
  69.                         LDB = {
  70.                                 hide = true,
  71.                                 minimapPos = 220,
  72.                                 radius = 80,
  73.                         },
  74.                 },
  75.         }
  76.         local db = LibStub("AceDB-3.0"):New("MasqueDB", Defaults, true)
  77.         db.RegisterCallback(Core, "OnProfileChanged", "Update")
  78.         db.RegisterCallback(Core, "OnProfileCopied", "Update")
  79.         db.RegisterCallback(Core, "OnProfileReset", "Update")
  80.         Core.db = db
  81.         SLASH_MASQUE1 = "/msq"
  82.         SLASH_MASQUE2 = "/masque"
  83.         SlashCmdList["MASQUE"] = function(Cmd, ...)
  84.                 if Cmd == "debug" then
  85.                         Core:Debug()
  86.                 else
  87.                         Core:ShowOptions()
  88.                 end
  89.         end
  90. end
  91.  
  92. ----------------------------------------
  93. -- PLAYER_LOGIN Event
  94. ----------------------------------------
  95.  
  96. function Masque:OnEnable()
  97.         local db = Core.db.profile
  98.         ACR:RegisterOptionsTable(MASQUE, Core.Options)
  99.         Core.ACR = ACR
  100.         Core.OptionsPanel = LibStub("AceConfigDialog-3.0"):AddToBlizOptions(MASQUE, MASQUE, nil, "General")
  101.         Core.Options.args.General.args.Load = {
  102.                 type = "execute",
  103.                 name = L["Load Masque Options"],
  104.                 desc = (L["Click this button to load Masque's options. You can also use the %s or %s chat command."]):format("|cffffcc00/msq|r", "|cffffcc00/masque|r"),
  105.                 func = function()
  106.                         Core:LoadOptions()
  107.                         InterfaceOptionsFrame_OpenToCategory(Core.OptionsPanel.Addons)
  108.                 end,
  109.                 hidden = function()
  110.                         return Core.OptionsLoaded
  111.                 end,
  112.                 order = 0,
  113.         }
  114.         if LDB then
  115.                 Core.LDBO = LDB:NewDataObject(MASQUE, {
  116.                         type  = "launcher",
  117.                         label = MASQUE,
  118.                         icon  = "Interface\Addons\Masque\Textures\Icon",
  119.                         OnClick = function(self, Button)
  120.                                 if Button == "LeftButton" or Button == "RightButton" then
  121.                                         Core:ShowOptions()
  122.                                 end
  123.                         end,
  124.                         OnTooltipShow = function(Tip)
  125.                                 if not Tip or not Tip.AddLine then
  126.                                         return
  127.                                 end
  128.                                 Tip:AddLine(MASQUE)
  129.                                 Tip:AddLine(L["Click to open Masque's options window."], 1, 1, 1)
  130.                         end,
  131.                 })
  132.                 Core.LDB = LDB
  133.                 if LDBI then
  134.                         LDBI:Register(MASQUE, Core.LDBO, db.LDB)
  135.                         Core.LDBI = LDBI
  136.                 end
  137.         end
  138. end
  139.  
  140. ----------------------------------------
  141. -- Core Methods
  142. ----------------------------------------
  143.  
  144. -- Toggles debug mode.
  145. function Core:Debug()
  146.         local db = self.db.profile
  147.         if db.Debug then
  148.                 db.Debug = false
  149.                 print("|cffffff99"..L["Masque debug mode disabled."].."|r")
  150.         else
  151.                 db.Debug = true
  152.                 print("|cffffff99"..L["Masque debug mode enabled."].."|r")
  153.         end
  154. end
  155.  
  156. -- Updates the current profile.
  157. function Core:Update()
  158.         local Global = Core:Group()
  159.         Global:Update()
  160.         if LDBI then
  161.                 LDBI:Refresh(MASQUE, Core.db.profile.LDB)
  162.         end
  163. end
  164.