Quantcast
WoWInterface - View Single Post - nibProfileLoader
View Single Post
04-07-12, 10:10 PM   #3
Orko
An Aku'mai Servant
 
Orko's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2009
Posts: 35
Here is the code from the addon I am using. I want an option to load two different profiles instead of just one. Right now the choices are load one profile or exit with the No button. Just a Yes or No button is currently there and I want like I descirbed in original post..

Lua Code:
  1. local frame = CreateFrame("FRAME");
  2. frame:RegisterEvent("VARIABLES_LOADED");
  3.  
  4. -- BEGIN USER OPTIONS --
  5. -- InterfaceName = Name to describe your UI
  6. -- ProfileName = Addon profile name to use with /reflux switch
  7. local InterfaceName  = "MyInterface"
  8. local ProfileName = "MyProfile"
  9.  
  10. local UseClassProfiles = false  -- Use specific profile names for different classes
  11. local ClassProfiles = {         -- Change profile names to suit
  12.     ["DEATHKNIGHT"] = "MyProfile",
  13.     ["DRUID"] = "MyProfile",
  14.     ["HUNTER"] = "MyProfile",
  15.     ["MAGE"] = "MyProfile",
  16.     ["PALADIN"] = "MyProfile",
  17.     ["PRIEST"] = "MyProfile",
  18.     ["ROGUE"] = "MyProfile",
  19.     ["SHAMAN"] = "MyProfile",
  20.     ["WARLOCK"] = "MyProfile",
  21.     ["WARRIOR"] = "MyProfile",
  22. }
  23. -- END USER OPTIONS --
  24.  
  25. local LocalizedMessages = {
  26.     ["enUS"] = {
  27.         [1] = "New character detected! Do you wish to load the settings for %s?",
  28.         [2] = "Yes",
  29.         [3] = "No",
  30.     },
  31.     ["deDE"] = {
  32.         [1] = "Neuen Character gefunden! Willst du die %s einstellungen laden?",
  33.         [2] = "Ja",
  34.         [3] = "Nein",
  35.     },
  36. }
  37.  
  38.  
  39. local CID, CE, HasAdded = "", false, false
  40.  
  41. local function AddChar()
  42.   if (CID ~= "") and not HasAdded then
  43.     tinsert(nibPLNames, CID)
  44.     HasAdded = true
  45.   end
  46. end
  47.  
  48. local function CharAnswered(ans)
  49.   AddChar()
  50.   if ans then
  51.     local _, class = UnitClass("player")
  52.     local NewProfile = UseClassProfiles and ClassProfiles[class] or ProfileName
  53.     local RefluxArg = string.format("%s %s", "switch", NewProfile)
  54.     SlashCmdList.REFLUX(RefluxArg) -- This will cause a UI reload
  55.   end
  56. end
  57.  
  58. local function AskNewChar()
  59.   local Locale = GetLocale() or "enUS"
  60.   local MsgTexts = LocalizedMessages[Locale] or LocalizedMessages["enUS"]
  61.   StaticPopupDialogs["PUDASKNEWCHAR"] = {
  62.     text = MsgTexts[1],
  63.     button1 = MsgTexts[2],
  64.     button2 = MsgTexts[3],
  65.     OnAccept = function()
  66.       CharAnswered(true)
  67.     end,
  68.     OnCancel = function()
  69.       CharAnswered(false)
  70.     end,
  71.     timeout = 0,
  72.     whileDead = true,
  73.     hideOnEscape = false,
  74.     notClosableByLogout = true,
  75.   }
  76.   StaticPopup_Show ("PUDASKNEWCHAR", InterfaceName);
  77. end
  78.  
  79. local function CheckNewChar()
  80.   CID = string.format("%s - %s", GetRealmName(), UnitName("player"))
  81.   CE = false
  82.   if (nibPLNames == nil) then nibPLNames = { }; end
  83.   for i,v in pairs(nibPLNames) do
  84.     if (v == CID) then CE = true; end
  85.   end
  86.   if not CE then AskNewChar(); end
  87. end
  88.  
  89. local function eventHandler(self, event, ...)
  90.   if (event == "VARIABLES_LOADED") then
  91.     CheckNewChar()
  92.   end
  93. end
  94. frame:SetScript("OnEvent", eventHandler);
__________________

Do not go where the path may lead, go instead where there is no path -- and leave a trail.
  Reply With Quote