Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local NewOptionsPanel = function(name, title, parent)
- local panel = CreateFrame('FRAME', name.."Options", UIParent)
- panel.name = name;
- if parent then
- panel.parent = parent.name
- end
- function panel:NewChild(childName)
- return GorLib.NewOptionsPanel(childName, nil, panel)
- end
- if title then
- panel.title = panel:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
- panel.title:SetPoint("TopLeft", 5 ,-5)
- panel.title:SetText(title)
- end
- InterfaceOptions_AddCategory(panel)
- return panel
- end
- local NewMenuButton = function(name, text, parent)
- local b = _G[parent:GetName()..name]
- if not b then
- b = CreateFrame("Button", parent:GetName()..name, parent, "UIMenuButtonStretchTemplate")
- end
- b:SetText(text)
- b:SetWidth(b:GetTextWidth() + 10)
- b:SetScript("OnClick", function(self) self.Click() end)
- return b
- end
- local NewMenu = function(name, parent, titleText)
- local parent = parent or UIParent
- local menu = CreateFrame('Frame', name, parent, 'TranslucentFrameTemplate')
- menu:SetSize(220, 300)
- menu:Hide()
- menu.close = CreateFrame('Button', menu:GetName()..'CloseButton', menu, 'UIPanelCloseButton')
- menu.close:SetPoint('TopRight', -5, -5)
- menu:SetScript("OnShow", function(self)
- self:SetPoint("Center")
- end)
- local title = menu:CreateFontString(nil, "OVERLAY", "GameFontNormal")
- title:SetPoint("TopLeft", 15, -15)
- title:SetText(titleText or name)
- menu:EnableMouse(true)
- menu:SetMovable(true)
- function menu.OnDragStop(self) self:StopMovingOrSizing() end
- function menu.OnDragStart(self) self:StartMoving() end
- local handlers = {"OnDragStart", "OnDragStop"}
- menu:RegisterForDrag("LeftButton")
- for _, handler in ipairs(handlers) do
- menu:SetScript(handler, function(self, button) self[handler](self) end)
- end
- return menu
- end
- local Editbox = function(parent)
- local editBox = CreateFrame('EditBox', parent:GetName() .. 'Editbox', parent, 'InputBoxTemplate')
- editBox:SetSize(200, 20)
- editBox:SetAutoFocus(false)
- editBox:SetScript('OnShow', function(self)
- self:SetText('')
- end)
- editBox:SetScript('OnEnterPressed', function(self)
- self.CollectText(self:GetText())
- end)
- editBox:SetScript('OnEditFocusLost', function(self) self:HighlightText(0, 0) end)
- editBox:SetScript('OnEditFocusGained', function(self) self:HighlightText() end)
- return editBox
- end
- local GUI = {}
- local buttons
- function GUI:ProfileButtons(parent)
- if buttons then
- for i = 1, #buttons do
- buttons[i]:Hide()
- end
- end
- buttons = {}
- local buttonNames = {}
- for i, b in pairs(ActionBarSaverDB.sets) do
- for j, c in pairs(b) do
- tinsert(buttonNames, {name = j, class = i})
- end
- end
- for i, b in pairs(buttonNames) do
- buttons[i] = NewMenuButton(i, b.name, parent)
- buttons[i]:Show()
- buttons[i].Click = function()
- GUI.SelectedClass = b.class
- GUI.SelectedName = b.name
- GUI.opts.SelectText:SetText("Selected Profile = "..b.name)
- end
- buttons[i]:SetPoint("TopLeft", 16, -80 - ( (i*buttons[i]:GetHeight()) - buttons[i]:GetHeight()))
- end
- end
- function GUI:Load()
- local options = NewOptionsPanel("ActionBarSaver", "Action Bar Saver")
- GUI.opts = options
- options.SaveBox = NewMenu("SaveBox", options, "Enter Profile Name")
- options.SelectText = options:CreateFontString(nil, "OVERLAY", "GameFontNormal")
- options.SelectText:SetPoint("TopLeft", 20, -65)
- do
- options.SaveBox:SetSize(230, 100)
- local EB = Editbox(options.SaveBox)
- EB.CollectText = function(text)
- ActionBarSaver:SaveProfile(text)
- options.SaveBox:Hide()
- end
- EB:SetPoint("Bottom", 5, 40)
- local save = NewMenuButton("Save", "Save", options.SaveBox)
- save:SetPoint("BottomRight", -15, 15)
- save.Click = function()
- ActionBarSaver:SaveProfile(EB:GetText())
- options.SaveBox:Hide()
- GUI:ProfileButtons(options)
- end
- local cancel = NewMenuButton("Cancel", "Cancel", options.SaveBox)
- cancel:SetPoint("BottomLeft", 15, 15)
- cancel.Click = function()
- EB:SetText("")
- options.SaveBox:Hide()
- end
- end
- options.SAVE = NewMenuButton("Save", "Save New Profile", options)
- options.SAVE:SetPoint("TopLeft", 15, -40)
- options.SAVE.Click = function()
- ToggleFrame(options.SaveBox)
- end
- options.LOAD = NewMenuButton("Load", "Load Profile", options)
- options.LOAD:SetPoint("Left", options.SAVE, "Right", 10, 0)
- options.LOAD.Click = function()
- if GUI.SelectedName then
- ActionBarSaver:RestoreProfile(GUI.SelectedName, GUI.SelectedClass)
- GUI.opts.SelectText:SetText("")
- GUI.SelectedName = nil
- GUI.SelectedClass = nil
- else
- GUI.opts.SelectText:SetText("Select a profile from below to load, then press Load.")
- end
- end
- options.Delete = NewMenuButton("Delete", "Delete Profile", options)
- options.Delete:SetPoint("Left", options.LOAD, "Right", 10, 0)
- options.Delete.Click = function()
- if GUI.SelectedName then
- ActionBarSaverDB.sets[GUI.SelectedClass][GUI.SelectedName] = nil
- GUI.opts.SelectText:SetText("Profile ".. GUI.SelectedName .." has been deleted!")
- GUI:ProfileButtons(options)
- GUI.SelectedName = nil
- GUI.SelectedClass = nil
- else
- GUI.opts.SelectText:SetText("Select a profile from below to delete, then press Delete.")
- end
- end
- GUI:ProfileButtons(options)
- local oldABS_SlashCmdList = SlashCmdList["ABS"]
- SlashCmdList["ABS"] = function(msg)
- if msg == "show" then
- InterfaceOptionsFrame_OpenToCategory(GUI.opts)
- else
- oldABS_SlashCmdList(msg)
- end
- end
- end
- local f = CreateFrame("Frame")
- f:RegisterEvent("PLAYER_ENTERING_WORLD")
- f:SetScript("OnEvent", function()
- GUI:Load()
- f:UnregisterEvent("PLAYER_ENTERING_WORLD")
- end)
Advertisement
Add Comment
Please, Sign In to add comment