View Single Post
03-02-12, 03:16 AM   #20
Aftermathhqt
A Molten Giant
 
Aftermathhqt's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 784
Originally Posted by zork View Post
Basic template for creating and calling a panel

TOC
lua Code:
  1. ## Interface: 40300
  2. ## Title: rConfig
  3. ## Author: zork
  4. ## Notes: A config template
  5. ## Version: 0.001
  6. ## SavedVariables: RCONFIG_DB_GLOB
  7. ## SavedVariablesPerCharacter: RCONFIG_DB_CHAR
  8. core.lua

LUA
lua Code:
  1. --VARIABLES/CONSTANTS
  2.  
  3. --init the addon frame
  4. local addon = CreateFrame("Frame")
  5. local db_glob, db_char
  6. local _G = _G
  7.  
  8. --FUNCTIONS
  9.  
  10. --default values
  11. local function loadDefaultsGlobal()
  12.   local t = {
  13.     name = 'green',
  14.   }
  15.   return t
  16. end
  17. local function loadDefaultsChar()
  18.   local t = {
  19.     width = 100,
  20.   }
  21.   return t
  22. end
  23.  
  24. local function loadDatabase()
  25.   db_glob = _G["RCONFIG_DB_GLOB"] or loadDefaultsGlobal()
  26.   _G["RCONFIG_DB_GLOB"] = db_glob
  27.   --saved variables per character
  28.   db_char = _G["RCONFIG_DB_CHAR"] or loadDefaultsChar()
  29.   _G["RCONFIG_DB_CHAR"] = db_char
  30. end
  31.  
  32. local function resetAllValues()
  33.   db_glob = loadDefaultsGlobal()
  34.   _G["RCONFIG_DB_GLOB"] = db_glob
  35.   db_char = loadDefaultsChar()
  36.   _G["RCONFIG_DB_CHAR"] = db_char
  37. end
  38.  
  39. --do you really want to reset all values?
  40. StaticPopupDialogs["RESET"] = {
  41.   text = "Reset all values for rConfig?",
  42.   button1 = ACCEPT,
  43.   button2 = CANCEL,
  44.   OnAccept = function() resetAllValues() print('reset done') end,
  45.   OnCancel = function() print('reset canceled') end,
  46.   timeout = 0,
  47.   whileDead = 1,
  48. }
  49.  
  50. local function createSubPanel(parent, name)
  51.   local panel = CreateFrame("FRAME")
  52.   panel.name = name
  53.   panel.parent = parent.name
  54.   panel.okay = function (self)
  55.     print(name..' okay')
  56.   end
  57.   panel.cancel = function (self)
  58.     print(name..' cancel')
  59.   end
  60.   panel.default = function (self)
  61.     --resetAllValues()
  62.     StaticPopup_Show("RESET")
  63.     print(name..' default')
  64.   end
  65.   panel.refresh = function (self)
  66.     print(name..' refresh')
  67.   end
  68.   InterfaceOptions_AddCategory(panel)
  69. end
  70.  
  71. local function initPanel()
  72.   local mainpanel = CreateFrame("FRAME")
  73.   mainpanel.name = "rConfig"
  74.   InterfaceOptions_AddCategory(mainpanel)
  75.   createSubPanel(mainpanel,"rConfigSubPanel1")
  76.   createSubPanel(mainpanel,"rConfigSubPanel2")
  77.   return mainpanel
  78. end
  79.  
  80. local function initSlashCmd(panel)
  81.   SLASH_RCONFIG1, SLASH_RCONFIG2 = '/rc', '/rconfig'
  82.   function SlashCmdList.RCONFIG(msg, editbox)
  83.     InterfaceOptionsFrame_OpenToCategory(panel)
  84.   end
  85. end
  86.  
  87. --INIT
  88.  
  89. function addon:VARIABLES_LOADED(...)
  90.   local self = self
  91.   --load the database
  92.   loadDatabase()
  93.   self:UnregisterEvent("VARIABLES_LOADED")
  94. end
  95.  
  96. function addon:PLAYER_LOGIN(...)
  97.   local self = self
  98.   print(db_glob.name)
  99.   local mainpanel = initPanel()
  100.   initSlashCmd(mainpanel)
  101.   self:UnregisterEvent("PLAYER_LOGIN")
  102. end
  103.  
  104. --CALL
  105.  
  106. --by doing this the addon will call functions based on registered events by itself
  107. addon:SetScript("OnEvent", function(self, event)
  108.   self[event](self)
  109.   --return self[event](self)
  110. end)
  111. --register events
  112. addon:RegisterEvent("VARIABLES_LOADED")
  113. addon:RegisterEvent("PLAYER_LOGIN")

Result is a blank panel.
Example shows loading the DB, creating the panel/subpanel and adding a slashcmd to call the panel.

Thanks Zork

Anyways i started on a new GUI

Here is it!



The thing is i need to figure how to create new windows for the tabs :<

LUA Code:
  1. -- Create an function so we can give all the frames texts in a smart way!
  2.  
  3. function CreateOptions(self, TextTitle, DescriptionsText) -- CreateOptions(self, "Header Text", "Description Text")
  4.     local title = self:CreateFontString(nil, "OVERLAY")
  5.     title:SetFontObject('GameFontNormalLarge')
  6.     title:SetPoint('TOPLEFT', 16, -16)
  7.     title:SetText(TextTitle) -- Header Text
  8.    
  9.     local title2 = self:CreateFontString(nil, "OVERLAY")
  10.     title2:SetFontObject('GameFontHighlightSmall')
  11.     title2:SetPoint('TOPLEFT', 17, -37)
  12.     title2:SetText(DescriptionsText) -- Description Text.
  13. end
  14.  
  15. function Checkbox(self, selfid, px, py, description, SetChecked, OnClick) -- Checkbox(self, 1, 14, -55, "Description Text", SetChecked, OnClick)
  16.     local checkbox = CreateFrame("CheckButton", "CheckBoxButton" .. selfid, self, "OptionsSmallCheckButtonTemplate")
  17.     checkbox:SetPoint("TOPLEFT", self, px, py)
  18.     checkbox:SetScript("OnClick", OnClick)
  19.     checkbox:SetWidth(28)
  20.     checkbox:SetHeight(28)
  21.     checkbox:SetFrameStrata("HIGH")
  22.     checkbox:SetChecked(SetChecked)
  23.     checkbox:SetHitRectInsets(0, -60, 0, 0)
  24.     checkbox:GetNormalTexture():SetAlpha(0.6)
  25.     checkbox:SetNormalTexture("")
  26.     checkbox:SetPushedTexture("")
  27.     checkbox:SetHighlightTexture("")
  28.     checkbox:SetBackdrop({
  29.         bgFile = AftermathhUI.media.backdrop,
  30.         insets = {top = 1, left = 1, bottom = 1, right = 1},
  31.     })
  32.  
  33.     CreateBorderLight(checkbox, AftermathhUI.media.bordersize, AftermathhUI.bordercolor, AftermathhUI.bordercolor, AftermathhUI.bordercolor, -4)
  34.    
  35.     checkbox:HookScript("OnEnter", function(self)
  36.         ColorBorder(checkbox, 1.0, 0.82, 0)
  37.     end)
  38.    
  39.     checkbox:HookScript("OnLeave", function(self)
  40.         ColorBorder(checkbox, AftermathhUI.bordercolor, AftermathhUI.bordercolor, AftermathhUI.bordercolor)
  41.     end)
  42.    
  43.     local checkboxtexture = checkbox:CreateTexture(nil, "ARTWORK")
  44.     checkboxtexture:SetWidth(25)
  45.     checkboxtexture:SetHeight(22)
  46.     checkboxtexture:SetAlpha(0.9)
  47.     checkboxtexture:SetPoint("LEFT", 2, 1)
  48.     checkboxtexture:SetTexture("Interface\\RAIDFRAME\\ReadyCheck-Ready")
  49.     checkbox:SetCheckedTexture(checkboxtexture)
  50.    
  51.     local checkboxtext = self:CreateFontString(nil, "ARTWORK", "GameFontNormal")
  52.     checkboxtext:SetPoint("LEFT", checkbox, "RIGHT", 5, 1)
  53.     checkboxtext:SetFontObject("GameFontNormal")
  54.     checkboxtext:SetTextColor(1, 1, 1)
  55.     checkboxtext:SetText(description)
  56. end
  57.  
  58. function ShowBuffs_OnClick()
  59.  
  60. end
  61.  
  62. local AftermathhUIFrame = CreateFrame("Frame", "AftermathhUIFrame", UIParent)
  63. AftermathhUIFrame:SetSize(800, 550)
  64. AftermathhUIFrame:SetFrameStrata("HIGH")
  65. AftermathhUIFrame:SetFrameLevel(25)
  66. AftermathhUIFrame:SetBackdrop({
  67.     bgFile = AftermathhUI.media.blank,
  68.     insets = {top = -1, left = -1, bottom = -1, right = -1},
  69. })
  70. AftermathhUIFrame:SetBackdropColor(unpack(AftermathhUI.media.backdropcolor))
  71. AftermathhUIFrame:Hide()
  72.  
  73. CreateOptions(AftermathhUIFrame, "AftermathhUI_Config", "Welcome to AftermathhUI_Config. Here you can find most of the options that are needed!")
  74.  
  75. CreateBorderLight(AftermathhUIFrame, AftermathhUI.media.bordersize, AftermathhUI.bordercolor, AftermathhUI.bordercolor, AftermathhUI.bordercolor, 1)
  76.  
  77. AftermathhUIFrame:SetClampedToScreen(true)
  78. AftermathhUIFrame:SetMovable(true)
  79. AftermathhUIFrame:SetUserPlaced(true)
  80. AftermathhUIFrame:EnableMouse(true)
  81. AftermathhUIFrame:RegisterForDrag("LeftButton")
  82. AftermathhUIFrame:SetHitRectInsets(-15, -15, -5, -5)
  83.  
  84. AftermathhUIFrame:ClearAllPoints()
  85. AftermathhUIFrame.ClearAllPoints = function() end
  86. AftermathhUIFrame:SetPoint("CENTER", UIParent)
  87. AftermathhUIFrame.SetPoint = function() end
  88.  
  89. AftermathhUIFrame:SetScript("OnDragStart", function(self)
  90.     AftermathhUIFrame:StartMoving()
  91. end)
  92.  
  93. AftermathhUIFrame:SetScript("OnDragStop", function(self)
  94.     AftermathhUIFrame:StopMovingOrSizing()
  95. end)
  96.  
  97. Checkbox(AftermathhUIFrame, 1, 14, -95, "Show PvP Icon.", AftermathhUI.ouf.showpvpicon)
  98. Checkbox(AftermathhUIFrame, 2, 14, -115, "Show Buffs.", AftermathhUI.ouf.showbuffs, ShowBuffs_OnClick)
  99. Checkbox(AftermathhUIFrame, 3, 14, -135, "Show Debuffs.", AftermathhUI.ouf.showdebuffs)
  100. Checkbox(AftermathhUIFrame, 4, 14, -155, "Only Show Player Debuffs.", AftermathhUI.ouf.onlyshowplayerdebuffs)
  101. Checkbox(AftermathhUIFrame, 5, 14, -175, "Show Aggroo.", AftermathhUI.ouf.showaggroo)
  102. Checkbox(AftermathhUIFrame, 6, 14, -195, "Show Debuff Highlight", AftermathhUI.ouf.showdebuffhighlight)
  103. Checkbox(AftermathhUIFrame, 7, 14, -215, "Tooltip On Mouseover (Player etc).", AftermathhUI.ouf.tooltiponouf)
  104. Checkbox(AftermathhUIFrame, 8, 14, -235, "Show Role Icon.", AftermathhUI.ouf.showroleicon)
  105. Checkbox(AftermathhUIFrame, 9, 14, -255, "Show Boss Frames.", AftermathhUI.ouf.bossframes)
  106. Checkbox(AftermathhUIFrame, 10, 14, -275, "Show Party Frames.", AftermathhUI.ouf.showparty)
  107. Checkbox(AftermathhUIFrame, 11, 14, -295, "Tooltip On Mouseover (Raidframes).", AftermathhUI.ouf.tooltiponraid)
  108. Checkbox(AftermathhUIFrame, 12, 14, -315, "Highlight On Mouseover (Raidframes).", AftermathhUI.ouf.highlightontarget)
  109. Checkbox(AftermathhUIFrame, 13, 14, -335, "Make Raid Frames Vertical.", AftermathhUI.ouf.raidframesvertical)
  110. Checkbox(AftermathhUIFrame, 14, 14, -355, "Aura Watch (Raidframes).", AftermathhUI.ouf.aurawatch)
  111. Checkbox(AftermathhUIFrame, 15, 14, -375, "Raid Debuffs.", AftermathhUI.ouf.raiddebuffs)
  112. Checkbox(AftermathhUIFrame, 16, 14, -395, "Show Aggro On Raidframes.", AftermathhUI.ouf.showaggroonraidframes)
  113. Checkbox(AftermathhUIFrame, 17, 14, -415, "Experiance Bar.", AftermathhUI.ouf.expbar)
  114. Checkbox(AftermathhUIFrame, 18, 14, -435, "Reputation Bar.", AftermathhUI.ouf.repbar)
  115. Checkbox(AftermathhUIFrame, 19, 14, -455, "Moveable Frames.", AftermathhUI.ouf.moveableframes)
  116. Checkbox(AftermathhUIFrame, 20, 14, -475, "Totembar from oUF.", AftermathhUI.ouf.totembar)
  117. Checkbox(AftermathhUIFrame, 21, 14, -495, "Heal Prediction.", AftermathhUI.ouf.healprediction)
  118. Checkbox(AftermathhUIFrame, 22, 14, -515, "Combat Feedback.", AftermathhUI.ouf.combatfeedback)
  119.  
  120. --- Coulum 2
  121.  
  122. Checkbox(AftermathhUIFrame, 23, 350, -95, "Classcolor on Castbar.", AftermathhUI.ouf.castbarclasscolor)
  123. Checkbox(AftermathhUIFrame, 24, 350, -115, "Show Safe Zone.", AftermathhUI.ouf.showsafezone)
  124. Checkbox(AftermathhUIFrame, 25, 350, -135, "Show Latency.", AftermathhUI.ouf.showlatency)
  125. Checkbox(AftermathhUIFrame, 26, 350, -155, "Target Castbar Icon.", AftermathhUI.ouf.targetcastbaricon)
  126. Checkbox(AftermathhUIFrame, 27, 350, -175, "Focus Castbar Icon.", AftermathhUI.ouf.focuscastbaricon)
  127. Checkbox(AftermathhUIFrame, 28, 350, -195, "Show Interrupt Highlight.", AftermathhUI.ouf.showinterrupthighlight)
  128.  
  129. local function AftermathhUIFrameOnEnter(self, fontsub)
  130.     self:HookScript("OnEnter", function(self)
  131.         ColorBorder(self, 1.0, 0.82, 0)
  132.     end)
  133.     self:HookScript("OnLeave", function(self)
  134.         ColorBorder(self, AftermathhUI.bordercolor, AftermathhUI.bordercolor, AftermathhUI.bordercolor)
  135.     end)
  136. end
  137.  
  138. local function AftermathhUIFontOnEnter(self)
  139.     self:HookScript("OnEnter", function(self)
  140.         self:SetTextColor(1, 1, 1)
  141.     end)
  142.     self:HookScript("OnLeave", function(self)
  143.         self:SetTextColor(1.0, 0.82, 0)
  144.     end)
  145. end
  146.  
  147. local AftermathhUIFrameSub1 = CreateFrame("Button", nil, UIParent)
  148. AftermathhUIFrameSub1:SetSize(75, 20)
  149. AftermathhUIFrameSub1:SetFrameStrata("HIGH")
  150. AftermathhUIFrameSub1:SetFrameLevel(26)
  151. AftermathhUIFrameSub1:SetBackdrop({
  152.     bgFile = AftermathhUI.media.texture2,
  153.     --insets = {top = -1, left = -1, bottom = -1, right = -1},
  154. })
  155. AftermathhUIFrameSub1:SetBackdropColor(.40, .40, .40, 1)
  156. AftermathhUIFrameSub1:SetPoint("TOPLEFT", AftermathhUIFrame, 16, -65)
  157. AftermathhUIFrameSub1:Hide()
  158.  
  159. CreateBorderLight(AftermathhUIFrameSub1, AftermathhUI.media.bordersize, AftermathhUI.bordercolor, AftermathhUI.bordercolor, AftermathhUI.bordercolor, 1)
  160.  
  161. AftermathhUIFrameOnEnter(AftermathhUIFrameSub1)
  162.  
  163. local AftermathhUIFrameSub1Font = AftermathhUIFrameSub1:CreateFontString(nil, "OVERLAY")
  164. AftermathhUIFrameSub1Font:SetFontObject('GameFontHighlightSmall')
  165. AftermathhUIFrameSub1Font:SetText("Unitframes")
  166. AftermathhUIFrameSub1Font:SetTextColor(1.0, 0.82, 0)
  167. AftermathhUIFrameSub1Font:SetPoint("CENTER")
  168.  
  169. local AftermathhUIFrameSub2 = CreateFrame("Button", nil, UIParent)
  170. AftermathhUIFrameSub2:SetSize(75, 20)
  171. AftermathhUIFrameSub2:SetFrameStrata("HIGH")
  172. AftermathhUIFrameSub2:SetFrameLevel(26)
  173. AftermathhUIFrameSub2:SetBackdrop({
  174.     bgFile = AftermathhUI.media.texture2,
  175.     --insets = {top = -1, left = -1, bottom = -1, right = -1},
  176. })
  177. AftermathhUIFrameSub2:SetBackdropColor(.40, .40, .40, 1)
  178. AftermathhUIFrameSub2:SetPoint("TOPLEFT", AftermathhUIFrame, 95, -65)
  179. AftermathhUIFrameSub2:Hide()
  180.  
  181. CreateBorderLight(AftermathhUIFrameSub2, AftermathhUI.media.bordersize, AftermathhUI.bordercolor, AftermathhUI.bordercolor, AftermathhUI.bordercolor, 1)
  182.  
  183. AftermathhUIFrameOnEnter(AftermathhUIFrameSub2)
  184.  
  185. local AftermathhUIFrameSub2Font = AftermathhUIFrameSub2:CreateFontString(nil, "OVERLAY")
  186. AftermathhUIFrameSub2Font:SetFontObject('GameFontHighlightSmall')
  187. AftermathhUIFrameSub2Font:SetText("Buffs")
  188. AftermathhUIFrameSub2Font:SetTextColor(1.0, 0.82, 0)
  189. AftermathhUIFrameSub2Font:SetPoint("CENTER")
  Reply With Quote