forked from kc8pnd/MobInfo2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMI2_Config.lua
286 lines (241 loc) · 9.54 KB
/
MI2_Config.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
--
-- MI2_Config.lua
--
-- Configuration dialog related module of the MobInfo2 AddOn
--
-----------------------------------------------------------------------------
-- MI2_OptionsFrameOnLoad()
--
-- This "OnLoad" event handler for the options dialog installs the
-- ESC key handler.
-----------------------------------------------------------------------------
function MI2_OptionsFrameOnLoad()
tinsert(UISpecialFrames, "frmMIConfig") -- Esc Closes Options Frame
UIPanelWindows["frmMIConfig"] = {area = "center", pushable = 0}
PanelTemplates_SetNumTabs( MI2_MainOptionsFrame, 4 )
MI2_MainOptionsFrame.selectedTab = 1
PanelTemplates_UpdateTabs( MI2_MainOptionsFrame )
PanelTemplates_SetNumTabs( MI2_SearchResultFrame, 2 )
MI2_SearchResultFrame.selectedTab = 1
PanelTemplates_UpdateTabs( MI2_SearchResultFrame )
MI2_OptDisableMobInfoText:SetTextColor( 1.0, 1.0, 1.0 )
MI2_OptHealthPosX:SetMinMaxValues( -50, 50 )
MI2_OptHealthPosY:SetMinMaxValues( -40, 80 )
MI2_OptManaPosX:SetMinMaxValues( -50, 50 )
MI2_OptManaPosY:SetMinMaxValues( -40, 80 )
MI2_OptTargetFontSize:SetMinMaxValues( 6, 20 )
end -- MI2_OptionsFrameOnLoad()
-----------------------------------------------------------------------------
-- MI2_SetHealthOptionsState()
--
-- Set the state of health options in health options dialog to either
-- enabled or disabled, as indicated by "MobInfoConfig.DisableHealth".
-----------------------------------------------------------------------------
function MI2_SetHealthOptionsState()
local r,g,b
if MobInfoConfig.DisableHealth == 2 then
MI2_MobHealthFrame:Hide()
end
end -- of MI2_SetHealthOptionsState()
-----------------------------------------------------------------------------
-- MI2_UpdateOptions()
--
-- Update state of all options in options dialog with correct values from
-- data structure "MobInfoConfig".
-----------------------------------------------------------------------------
function MI2_UpdateOptions()
for index, value in MI2_OPTIONS do
local option = string.sub( index, 8 )
--DEFAULT_CHAT_FRAME:AddMessage( "MI_DBG: index="..index..", cmnd="..value.cmnd..", opt="..option )
if MobInfoConfig[option] then
if value.dd then
-- do nothing for dropdowns
elseif value.val then
getglobal(index):SetValue( MobInfoConfig[option] )
elseif value.txt then
getglobal(index):SetText( MobInfoConfig[option] )
else
getglobal(index):SetChecked( MobInfoConfig[option] )
end
end
end
end -- MI2_UpdateOptions()
-----------------------------------------------------------------------------
-- MI2_ShowOptionHelpTooltip()
--
-- Show help text for current hovered option in options dialog
-- in the game tooltip window.
-----------------------------------------------------------------------------
function MI2_ShowOptionHelpTooltip()
GameTooltip_SetDefaultAnchor( GameTooltip, UIParent )
GameTooltip:SetText( mifontWhite..MI2_OPTIONS[this:GetName()].text )
GameTooltip:AddLine(mifontGold..MI2_OPTIONS[this:GetName()].help)
if MI2_OPTIONS[this:GetName()].info then
GameTooltip:AddLine(mifontGold..MI2_OPTIONS[this:GetName()].info)
end
GameTooltip:Show()
end -- of MI2_ShowOptionHelpTooltip()
-----------------------------------------------------------------------------
-- MI2_OptionsFrameOnShow()
--
-- Show help text for current hovered option in options dialog
-- in the game tooltip window.
-----------------------------------------------------------------------------
function MI2_OptionsFrameOnShow()
txtMIConfigTitle:SetText( MI_TXT_CONFIG_TITLE )
MI2_UpdateOptions()
end -- MI2_OptionsFrameOnShow()
function miConfig_OnMouseDown(arg1)
if (arg1 == "LeftButton") then
frmMIConfig:StartMoving()
end
end
function miConfig_OnMouseUp(arg1)
if (arg1 == "LeftButton") then
frmMIConfig:StopMovingOrSizing()
end
end
function miConfig_btnMIDone_OnClick()
HideUIPanel(frmMIConfig)
if MYADDONS_ACTIVE_OPTIONSFRAME then
if (MYADDONS_ACTIVE_OPTIONSFRAME == this) then
ShowUIPanel(myAddOnsFrame)
end
end
end
-----------------------------------------------------------------------------
-- MI2_TabButton_OnClick()
--
-- Event handler: one of the options dialog TABs has been clicked.
-- Show the corresponding options frame and hide all other option frames.
-----------------------------------------------------------------------------
function MI2_TabButton_OnClick( )
PanelTemplates_Tab_OnClick( MI2_MainOptionsFrame )
local selected = MI2_MainOptionsFrame.selectedTab
-- choose special information frame if mob health has been disabled
local healthFrame = MI2_FrmHealthOptions
if MobInfoConfig.DisableHealth ~= 0 then
healthFrame = MI2_FrmHealthDisabledInfo
end
if selected == 1 then
MI2_FrmTooltipOptions:Show()
else
MI2_FrmTooltipOptions:Hide()
end
if selected == 2 then
healthFrame:Show()
else
healthFrame:Hide()
end
if selected == 3 then
MI2_FrmDatabaseOptions:Show()
else
MI2_FrmDatabaseOptions:Hide()
end
if selected == 4 then
MI2_FrmSearchOptions:Show()
else
MI2_FrmSearchOptions:Hide()
end
end
-----------------------------------------------------------------------------
-- MI2_OptTargetFont_OnClick()
--
-- Event handler: one of the choices in the font selection box has been
-- clicked. Store it as a config option.
-----------------------------------------------------------------------------
function MI2_OptTargetFont_OnClick()
local oldID = UIDropDownMenu_GetSelectedID( MI2_OptTargetFont )
UIDropDownMenu_SetSelectedID( MI2_OptTargetFont, this:GetID())
if oldID ~= this:GetID() then
MobInfoConfig.TargetFont = this:GetID()
MI2_MobHealth_SetPos()
end
end -- MI2_OptTargetFont_OnClick()
-----------------------------------------------------------------------------
-- MI2_OptItemsQuality_OnClick()
--
-- Event handler: one of the choices in the font selection box has been
-- clicked. Store it as a config option.
-----------------------------------------------------------------------------
function MI2_OptItemsQuality_OnClick()
local oldID = UIDropDownMenu_GetSelectedID( MI2_OptItemsQuality )
UIDropDownMenu_SetSelectedID( MI2_OptItemsQuality, this:GetID())
if oldID ~= this:GetID() then
MobInfoConfig.ItemsQuality = this:GetID()
end
end -- MI2_OptItemsQuality_OnClick()
-----------------------------------------------------------------------------
-- MI2_DropDown_Initialize()
--
-- Initialize a dropdown list with entries that are retrieved from the
-- localization info.
-----------------------------------------------------------------------------
function MI2_DropDown_Initialize()
if string.sub(this:GetName(),-6) ~= "Button" then return end
local dropDownName = string.sub(this:GetName(),1,-7)
local choice = MI2_OPTIONS[dropDownName].choice1
local count = 1
while choice do
local info = { text = choice, value = count, func = getglobal(dropDownName.."_OnClick") }
UIDropDownMenu_AddButton( info )
count = count + 1
choice = MI2_OPTIONS[dropDownName]["choice"..count]
end
end -- MI2_DropDown_Initialize()
-----------------------------------------------------------------------------
-- MI2_OptItemsQuality_OnShow()
--
-- Event handler: show a drop down list
-- Ensure that current selection is shown correctly.
-----------------------------------------------------------------------------
function MI2_DropDown_OnShow()
local frameName = this:GetName()
local itemName = string.sub(frameName, 8)
local text = MI2_OPTIONS[frameName]["choice"..MobInfoConfig[itemName]]
UIDropDownMenu_SetSelectedID( this, MobInfoConfig[itemName] )
UIDropDownMenu_SetText( text, this )
end -- MI2_OptItemsQuality_OnShow()
-----------------------------------------------------------------------------
-- MI2_DbOptionsFrameOnShow()
--
-----------------------------------------------------------------------------
function MI2_DbOptionsFrameOnShow()
local mobDbSize, healthDbSize, playerDbSize, itemDbSize = 0, 0, 0, 0
-- count and diplay size of MobInfo database
for index in MobInfoDB do mobDbSize = mobDbSize + 1 end
MI2_TxtMobDbSize:SetText( MI_TXT_MOB_DB_SIZE..mifontWhite..(mobDbSize-1) )
-- count and diplay size of MobHealth database
for index in MobHealthDB do healthDbSize = healthDbSize + 1 end
MI2_TxtHealthDbSize:SetText( MI_TXT_HEALTH_DB_SIZE..mifontWhite..healthDbSize )
-- count and diplay size of MobHealthPlayer database
for index in MobHealthPlayerDB do playerDbSize = playerDbSize + 1 end
MI2_TxtPlayerDbSize:SetText( MI_TXT_PLAYER_DB_SIZE..mifontWhite..playerDbSize )
-- count and diplay size of MI2_ItemNameTable database
-- for index in MI2_ItemNameTable do itemDbSize = itemDbSize + 1 end
-- MI2_TxtItemDbSize:SetText( MI_TXT_ITEM_DB_SIZE..mifontWhite..itemDbSize )
-- update mob index display and state of "clear mob" button
if MI2_Target.mobIndex and MobInfoDB[MI2_Target.mobIndex] then
MI2_OptClearTarget:Enable()
MI2_TxtTargetIndex:SetText( MI_TXT_CUR_TARGET..mifontWhite..MI2_Target.mobIndex )
else
MI2_OptClearTarget:Disable()
MI2_TxtTargetIndex:SetText( MI_TXT_CUR_TARGET..mifontWhite.."---" )
end
-- update import status
if MI2_Import_Status then
if MobInfoConfig.ImportSignature == MI2_Import_Signature then
MI2_OptImportMobData:Disable()
MI2_TxtImportStatus:SetText( "Status: <data already imported ("..MI2_Import_Status..")>" )
elseif MI2_Import_Status == "BADVER" then
MI2_OptImportMobData:Disable()
MI2_TxtImportStatus:SetText( "Status: <import database too old>" )
else
MI2_OptImportMobData:Enable()
MI2_TxtImportStatus:SetText( "Status: "..MI2_Import_Status.." available for import" )
end
else
MI2_OptImportMobData:Disable()
MI2_TxtImportStatus:SetText( "Status: <no import data>" )
end
end -- MI2_DbOptionsFrameOnShow()