Guest User

In game options

a guest
Feb 7th, 2012
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.63 KB | None | 0 0
  1. local NewOptionsPanel = function(name, title, parent)
  2.     local panel = CreateFrame('FRAME', name.."Options", UIParent)
  3.     panel.name = name;
  4.    
  5.     if parent then
  6.         panel.parent = parent.name
  7.     end
  8.    
  9.     function panel:NewChild(childName)
  10.         return GorLib.NewOptionsPanel(childName, nil, panel)
  11.     end
  12.    
  13.     if title then
  14.         panel.title = panel:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
  15.         panel.title:SetPoint("TopLeft", 5 ,-5)
  16.         panel.title:SetText(title)
  17.     end
  18.    
  19.     InterfaceOptions_AddCategory(panel)
  20.     return panel
  21. end
  22.  
  23. local NewMenuButton = function(name, text, parent)
  24.     local b = _G[parent:GetName()..name]
  25.     if not b then
  26.         b = CreateFrame("Button", parent:GetName()..name, parent, "UIMenuButtonStretchTemplate")   
  27.     end
  28.    
  29.         b:SetText(text)
  30.         b:SetWidth(b:GetTextWidth() + 10)
  31.         b:SetScript("OnClick", function(self) self.Click() end)
  32.     return b
  33. end
  34.  
  35. local NewMenu = function(name, parent, titleText)
  36.     local parent = parent or UIParent
  37.     local menu = CreateFrame('Frame', name, parent, 'TranslucentFrameTemplate')
  38.     menu:SetSize(220, 300)
  39.     menu:Hide()
  40.     menu.close = CreateFrame('Button', menu:GetName()..'CloseButton', menu, 'UIPanelCloseButton')
  41.     menu.close:SetPoint('TopRight', -5, -5)
  42.     menu:SetScript("OnShow", function(self)
  43.         self:SetPoint("Center")
  44.     end)
  45.    
  46.     local title = menu:CreateFontString(nil, "OVERLAY", "GameFontNormal")
  47.     title:SetPoint("TopLeft", 15, -15)
  48.     title:SetText(titleText or name)
  49.    
  50.    
  51.         menu:EnableMouse(true)
  52.         menu:SetMovable(true)
  53.         function menu.OnDragStop(self) self:StopMovingOrSizing()  end
  54.         function menu.OnDragStart(self) self:StartMoving() end
  55.         local handlers = {"OnDragStart", "OnDragStop"}
  56.         menu:RegisterForDrag("LeftButton")
  57.         for _, handler in ipairs(handlers) do
  58.           menu:SetScript(handler, function(self, button) self[handler](self) end)
  59.         end
  60.     return menu
  61. end
  62.  
  63. local Editbox = function(parent)
  64.     local editBox = CreateFrame('EditBox', parent:GetName() .. 'Editbox', parent,  'InputBoxTemplate')
  65.     editBox:SetSize(200, 20)
  66.     editBox:SetAutoFocus(false)
  67.     editBox:SetScript('OnShow', function(self)
  68.         self:SetText('')
  69.     end)
  70.     editBox:SetScript('OnEnterPressed', function(self)
  71.         self.CollectText(self:GetText())
  72.     end)
  73.     editBox:SetScript('OnEditFocusLost', function(self) self:HighlightText(0, 0) end)
  74.     editBox:SetScript('OnEditFocusGained', function(self) self:HighlightText() end)
  75.     return editBox
  76. end
  77.  
  78. local GUI = {}
  79.  
  80. local buttons
  81.  
  82. function GUI:ProfileButtons(parent)
  83.     if buttons then
  84.         for i = 1,  #buttons do
  85.             buttons[i]:Hide()
  86.         end
  87.     end
  88.    
  89.     buttons = {}
  90.  
  91.     local buttonNames = {}
  92.    
  93.     for i, b in pairs(ActionBarSaverDB.sets) do
  94.         for j, c in pairs(b) do
  95.             tinsert(buttonNames, {name = j, class = i})
  96.         end    
  97.     end
  98.    
  99.    
  100.     for i, b in pairs(buttonNames) do
  101.         buttons[i] = NewMenuButton(i, b.name, parent)
  102.         buttons[i]:Show()
  103.         buttons[i].Click = function()
  104.             GUI.SelectedClass = b.class
  105.             GUI.SelectedName = b.name
  106.             GUI.opts.SelectText:SetText("Selected Profile = "..b.name)
  107.         end
  108.         buttons[i]:SetPoint("TopLeft", 16, -80 - ( (i*buttons[i]:GetHeight()) - buttons[i]:GetHeight()))
  109.     end
  110. end
  111.  
  112. function GUI:Load()
  113.     local options = NewOptionsPanel("ActionBarSaver", "Action Bar Saver")
  114.     GUI.opts = options
  115.     options.SaveBox = NewMenu("SaveBox", options, "Enter Profile Name")
  116.    
  117.     options.SelectText = options:CreateFontString(nil, "OVERLAY", "GameFontNormal")
  118.     options.SelectText:SetPoint("TopLeft", 20, -65)
  119.  
  120.     do
  121.         options.SaveBox:SetSize(230, 100)
  122.         local EB = Editbox(options.SaveBox)
  123.         EB.CollectText = function(text)
  124.             ActionBarSaver:SaveProfile(text)
  125.             options.SaveBox:Hide()
  126.         end
  127.        
  128.         EB:SetPoint("Bottom", 5, 40)
  129.         local save = NewMenuButton("Save", "Save", options.SaveBox)
  130.         save:SetPoint("BottomRight", -15, 15)
  131.         save.Click = function()
  132.             ActionBarSaver:SaveProfile(EB:GetText())
  133.             options.SaveBox:Hide()
  134.             GUI:ProfileButtons(options)
  135.         end
  136.    
  137.         local cancel = NewMenuButton("Cancel", "Cancel", options.SaveBox)
  138.         cancel:SetPoint("BottomLeft", 15, 15)
  139.         cancel.Click = function()
  140.             EB:SetText("")
  141.             options.SaveBox:Hide()
  142.         end
  143.    
  144.     end
  145.     options.SAVE = NewMenuButton("Save", "Save New Profile", options)
  146.     options.SAVE:SetPoint("TopLeft", 15, -40)
  147.     options.SAVE.Click = function()
  148.         ToggleFrame(options.SaveBox)
  149.     end
  150.  
  151.     options.LOAD = NewMenuButton("Load", "Load Profile", options)
  152.     options.LOAD:SetPoint("Left", options.SAVE, "Right", 10, 0)
  153.     options.LOAD.Click = function()
  154.         if GUI.SelectedName then
  155.             ActionBarSaver:RestoreProfile(GUI.SelectedName, GUI.SelectedClass)
  156.             GUI.opts.SelectText:SetText("")
  157.             GUI.SelectedName = nil
  158.             GUI.SelectedClass = nil
  159.         else
  160.             GUI.opts.SelectText:SetText("Select a profile from below to load, then press Load.")
  161.         end
  162.     end
  163.    
  164.     options.Delete = NewMenuButton("Delete", "Delete Profile", options)
  165.     options.Delete:SetPoint("Left", options.LOAD, "Right", 10, 0)
  166.     options.Delete.Click = function()
  167.         if GUI.SelectedName then
  168.             ActionBarSaverDB.sets[GUI.SelectedClass][GUI.SelectedName] = nil
  169.             GUI.opts.SelectText:SetText("Profile ".. GUI.SelectedName .." has been deleted!")
  170.             GUI:ProfileButtons(options)
  171.             GUI.SelectedName = nil
  172.             GUI.SelectedClass = nil
  173.         else
  174.             GUI.opts.SelectText:SetText("Select a profile from below to delete, then press Delete.")
  175.         end
  176.     end
  177.    
  178.     GUI:ProfileButtons(options)
  179.    
  180.     local oldABS_SlashCmdList = SlashCmdList["ABS"]
  181.     SlashCmdList["ABS"] = function(msg)
  182.         if msg == "show" then
  183.             InterfaceOptionsFrame_OpenToCategory(GUI.opts)
  184.         else
  185.             oldABS_SlashCmdList(msg)
  186.         end
  187.     end
  188. end
  189.  
  190. local f = CreateFrame("Frame")
  191. f:RegisterEvent("PLAYER_ENTERING_WORLD")
  192. f:SetScript("OnEvent", function()
  193.     GUI:Load()
  194.     f:UnregisterEvent("PLAYER_ENTERING_WORLD")
  195. end)
Advertisement
Add Comment
Please, Sign In to add comment