annotate Libs/DF/help.lua @ 11:2f09fe4be15c

Added an Options Panel.
author Tercio
date Mon, 20 Apr 2015 16:34:18 -0300
parents
children dc1c77254f80
rev   line source
Tercio@11 1
Tercio@11 2
Tercio@11 3 local DF = _G ["DetailsFramework"]
Tercio@11 4 local _
Tercio@11 5
Tercio@11 6 local _rawset = rawset --> lua local
Tercio@11 7 local _rawget = rawget --> lua local
Tercio@11 8
Tercio@11 9 local APIHelpFunctions = false
Tercio@11 10 local HelpMetaFunctions = {}
Tercio@11 11
Tercio@11 12 local get_members_function_index = {}
Tercio@11 13
Tercio@11 14 HelpMetaFunctions.__index = function (_table, _member_requested)
Tercio@11 15
Tercio@11 16 local func = get_members_function_index [_member_requested]
Tercio@11 17 if (func) then
Tercio@11 18 return func (_table, _member_requested)
Tercio@11 19 end
Tercio@11 20
Tercio@11 21 local fromMe = _rawget (_table, _member_requested)
Tercio@11 22 if (fromMe) then
Tercio@11 23 return fromMe
Tercio@11 24 end
Tercio@11 25
Tercio@11 26 return HelpMetaFunctions [_member_requested]
Tercio@11 27 end
Tercio@11 28
Tercio@11 29 local set_members_function_index = {}
Tercio@11 30
Tercio@11 31 HelpMetaFunctions.__newindex = function (_table, _key, _value)
Tercio@11 32 local func = set_members_function_index [_key]
Tercio@11 33 if (func) then
Tercio@11 34 return func (_table, _value)
Tercio@11 35 else
Tercio@11 36 return _rawset (_table, _key, _value)
Tercio@11 37 end
Tercio@11 38 end
Tercio@11 39
Tercio@11 40 function HelpMetaFunctions:AddHelp (width, height, x, y, buttonX, buttonY, text, anchor)
Tercio@11 41 self.helpTable [#self.helpTable + 1] = {
Tercio@11 42 HighLightBox = {x = x, y = y, width = width, height = height},
Tercio@11 43 ButtonPos = { x = buttonX, y = buttonY},
Tercio@11 44 ToolTipDir = anchor or "RIGHT",
Tercio@11 45 ToolTipText = text
Tercio@11 46 }
Tercio@11 47 end
Tercio@11 48
Tercio@11 49 function HelpMetaFunctions:SetPoint (v1, v2, v3, v4, v5)
Tercio@11 50 v1, v2, v3, v4, v5 = DF:CheckPoints (v1, v2, v3, v4, v5, self)
Tercio@11 51 if (not v1) then
Tercio@11 52 print ("Invalid parameter for SetPoint")
Tercio@11 53 return
Tercio@11 54 end
Tercio@11 55 return self.widget:SetPoint (v1, v2, v3, v4, v5)
Tercio@11 56 end
Tercio@11 57
Tercio@11 58 function HelpMetaFunctions:ShowHelp()
Tercio@11 59 if (not HelpPlate_IsShowing (self.helpTable)) then
Tercio@11 60 HelpPlate_Show (self.helpTable, self.frame, self.button, true)
Tercio@11 61 else
Tercio@11 62 HelpPlate_Hide (true)
Tercio@11 63 end
Tercio@11 64 end
Tercio@11 65
Tercio@11 66 local nameCounter = 1
Tercio@11 67 function DF:NewHelp (parent, width, height, x, y, buttonWidth, buttonHeight, name)
Tercio@11 68
Tercio@11 69 local help = {}
Tercio@11 70
Tercio@11 71 if (parent.dframework) then
Tercio@11 72 parent = parent.widget
Tercio@11 73 end
Tercio@11 74
Tercio@11 75 local helpButton = CreateFrame ("button", name or "DetailsFrameworkHelpButton"..nameCounter, parent, "MainHelpPlateButton")
Tercio@11 76 nameCounter = nameCounter + 1
Tercio@11 77
Tercio@11 78 if (not APIHelpFunctions) then
Tercio@11 79 APIHelpFunctions = true
Tercio@11 80 local idx = getmetatable (helpButton).__index
Tercio@11 81 for funcName, funcAddress in pairs (idx) do
Tercio@11 82 if (not HelpMetaFunctions [funcName]) then
Tercio@11 83 HelpMetaFunctions [funcName] = function (object, ...)
Tercio@11 84 local x = loadstring ( "return _G."..object.button:GetName()..":"..funcName.."(...)")
Tercio@11 85 return x (...)
Tercio@11 86 end
Tercio@11 87 end
Tercio@11 88 end
Tercio@11 89 end
Tercio@11 90
Tercio@11 91 if (buttonWidth and buttonHeight) then
Tercio@11 92 helpButton:SetWidth (buttonWidth)
Tercio@11 93 helpButton:SetHeight (buttonHeight)
Tercio@11 94 helpButton.I:SetWidth (buttonWidth*0.8)
Tercio@11 95 helpButton.I:SetHeight (buttonHeight*0.8)
Tercio@11 96 helpButton.Ring:SetWidth (buttonWidth)
Tercio@11 97 helpButton.Ring:SetHeight (buttonHeight)
Tercio@11 98 helpButton.Ring:SetPoint ("center", buttonWidth*.2, -buttonWidth*.2)
Tercio@11 99 end
Tercio@11 100
Tercio@11 101 help.helpTable = {
Tercio@11 102 FramePos = {x = x, y = y},
Tercio@11 103 FrameSize = {width = width, height = height}
Tercio@11 104 }
Tercio@11 105
Tercio@11 106 help.frame = parent
Tercio@11 107 help.button = helpButton
Tercio@11 108 help.widget = helpButton
Tercio@11 109 help.I = helpButton.I
Tercio@11 110 help.Ring = helpButton.Ring
Tercio@11 111
Tercio@11 112 helpButton:SetScript ("OnClick", function()
Tercio@11 113 help:ShowHelp()
Tercio@11 114 end)
Tercio@11 115
Tercio@11 116 setmetatable (help, HelpMetaFunctions)
Tercio@11 117
Tercio@11 118 return help
Tercio@11 119
Tercio@11 120 end