View Single Post
04-14-12, 12:54 PM   #16
Nibelheim
local roygbi-
 
Nibelheim's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 1,600
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  = "Deeui4"
  8. local TankName = "DeeUi-DPS"
  9. local HealName = "DeeUi-Heal"
  10.      
  11. local UseClassProfiles = false  -- Use specific profile names for different classes
  12. local ClassProfiles = {         -- Change profile names to suit
  13.     ["DEATHKNIGHT"] = "MyProfile",
  14.     ["DRUID"] = "MyProfile",
  15.     ["HUNTER"] = "MyProfile",
  16.     ["MAGE"] = "MyProfile",
  17.     ["PALADIN"] = "MyProfile",
  18.     ["PRIEST"] = "MyProfile",
  19.     ["ROGUE"] = "MyProfile",
  20.     ["SHAMAN"] = "MyProfile",
  21.     ["WARLOCK"] = "MyProfile",
  22.     ["WARRIOR"] = "MyProfile",
  23. }
  24. -- END USER OPTIONS --
  25.  
  26. local LocalizedMessages = {
  27.     ["enUS"] = {
  28.         [1] = "Thanks for using DeeUi4. Choose your destiny.",
  29.         [2] = "Tank/DPS",
  30.         [3] = "Heal",
  31.     },
  32.     ["deDE"] = {
  33.         [1] = "Neuen Character gefunden! Willst du die %s einstellungen laden?",
  34.         [2] = "Tank/DPS",
  35.         [3] = "Heal",
  36.     },
  37. }
  38.  
  39.  
  40. local CID, CE, HasAdded = "", false, false
  41.  
  42. local function AddChar()
  43.   if (CID ~= "") and not HasAdded then
  44.     tinsert(nibPLNames, CID)
  45.     HasAdded = true
  46.   end
  47. end
  48.  
  49. local function CharAnswered(ans)
  50.   AddChar()
  51.   if ans == "Tank" then
  52.     local _, class = UnitClass("player")
  53.     local NewProfile = UseClassProfiles and ClassProfiles[class] or TankName
  54.     local RefluxArg = string.format("%s %s", "switch", DeeUi-DPS)
  55.     SlashCmdList.REFLUX(RefluxArg) -- This will cause a UI reload
  56.   elseif ans == "Heal" then
  57.     local _, class = UnitClass("player")
  58.     local NewProfile = UseClassProfiles and ClassProfiles[class] or HealName
  59.     local RefluxArg = string.format("%s %s", "switch", DeeUi-Heal)
  60.     SlashCmdList.REFLUX(RefluxArg) -- This will cause a UI reload
  61.   end
  62. end
  63.  
  64. local function AskNewChar()
  65.   local Locale = GetLocale() or "enUS"
  66.   local MsgTexts = LocalizedMessages[Locale] or LocalizedMessages["enUS"]
  67.   -- Define a new Pop Up message
  68.   StaticPopupDialogs["PUDASKNEWCHAR"] = {
  69.     -- Message to display
  70.     text = MsgTexts[1];
  71.  
  72.     -- Text to show on first button
  73.     button1 = MsgTexts[2];
  74.  
  75.     -- Text to show on second button
  76.     button2 = MsgTexts[3];
  77.  
  78.     -- Function to call when first button is pressed
  79.     OnAccept = function()
  80.         -- Call CharAnswered with "Tank" argument
  81.         CharAnswered("Tank");
  82.     end
  83.  
  84.     -- Function to call when second button is pressed
  85.     OnCancel = function()
  86.         -- Call CharAnswered with "Heal" argument
  87.         CharAnswered("Heal");
  88.     end
  89.  
  90.     -- Pop Up message stays open until user action
  91.     timeout = 0;
  92.  
  93.     -- Pop Up message is shown even if the player is dead
  94.     whileDead = true,
  95.  
  96.     -- Hitting Esc won't close the Pop Up message
  97.     hideOnEscape = false;
  98.  
  99.     -- Logging out won't send the signal to hit the second button (OnCancel), thereby making the Pop Up message show next time they log in if they didn't click any buttons
  100.     notClosableByLogout = true
  101.   };
  102.  
  103.   -- Show the Pop Up message
  104.   StaticPopup_Show ("PUDASKNEWCHAR", InterfaceName);
  105. end
  106.  
  107. local function CheckNewChar()
  108.   CID = string.format("%s - %s", GetRealmName(), UnitName("player"))
  109.   CE = false
  110.   if (nibPLNames == nil) then nibPLNames = { }; end
  111.   for i,v in pairs(nibPLNames) do
  112.     if (v == CID) then CE = true; end
  113.   end
  114.   if not CE then AskNewChar(); end
  115. end
  116.  
  117. local function eventHandler(self, event, ...)
  118.   if (event == "VARIABLES_LOADED") then
  119.     CheckNewChar()
  120.   end
  121. end
  122. frame:SetScript("OnEvent", eventHandler)
  Reply With Quote