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

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