public
Description: WoW Addon - Swap a random minipet every time you visit the bank
Homepage: http://www.tekkub.net
Clone URL: git://github.com/tekkub/kennel.git
Click here to lend your support to: kennel and make a donation at www.pledgie.com !
tekkub (author)
Mon Aug 10 01:47:01 -0700 2009
commit  36129463967eb84ccb862c1482dc605151459be7
tree    62d26509392c7e1597e44d2e7a8713f46913f6c8
parent  97e354559c0572837c6e4941729da740018e6ff8 parent  9647ca4c65af7c85449f082cb5804bd0f8829df5
kennel / Config.lua
100644 301 lines (246 sloc) 9.983 kb
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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301

local NUMROWS, NUMCOLS, ICONSIZE, GAP, EDGEGAP = 5, 8, 32, 8, 16
local rows = {}
local kennel = KENNELFRAME
KENNELFRAME = nil
 
local frame = CreateFrame("Frame", nil, InterfaceOptionsFramePanelContainer)
frame.name = "Kennel"
frame:Hide()
frame:SetScript("OnShow", function(frame)
local tektab = LibStub("tekKonfig-TopTab")
 
local title, subtitle = LibStub("tekKonfig-Heading").new(frame, "Kennel", "This panel allows you to select which pets Kennel will put out.")
 
 
local enabled = LibStub("tekKonfig-Checkbox").new(frame, nil, "Enabled", "TOPLEFT", subtitle, "BOTTOMLEFT", -2, -GAP)
local checksound = enabled:GetScript("OnClick")
enabled:SetScript("OnClick", function(self) checksound(self); KennelDBPC.disabled = not KennelDBPC.disabled end)
enabled:SetChecked(not KennelDBPC.disabled)
 
local mountdismiss = LibStub("tekKonfig-Checkbox").new(frame, nil, "Dismiss when mounted", "TOPLEFT", enabled, "BOTTOMLEFT", 0, -4)
mountdismiss:SetScript("OnClick", function(self) checksound(self); KennelDBPC.dismissonmount = not KennelDBPC.dismissonmount end)
mountdismiss:SetChecked(KennelDBPC.dismissonmount)
 
 
local group = LibStub("tekKonfig-Group").new(frame, nil, "TOP", mountdismiss, "BOTTOM", 0, -GAP-14)
group:SetPoint("LEFT", EDGEGAP, 0)
group:SetPoint("BOTTOMRIGHT", -EDGEGAP, EDGEGAP)
 
 
local randoms, zones
local tab1 = tektab.new(frame, "Random", "BOTTOMLEFT", group, "TOPLEFT", 0, -4)
local tab2 = tektab.new(frame, "Zone", "LEFT", tab1, "RIGHT", -15, 0)
tab2:Deactivate()
tab1:SetScript("OnClick", function(self)
self:Activate()
tab2:Deactivate()
randoms:Show()
zones:Hide()
end)
tab2:SetScript("OnClick", function(self)
self:Activate()
tab1:Deactivate()
randoms:Hide()
zones:Show()
end)
 
 
----------------------------
-- Random panel --
----------------------------
 
randoms = CreateFrame("Frame", nil, group)
randoms:SetAllPoints()
 
local scrollbar = LibStub("tekKonfig-Scroll").new(randoms, 6, 1)
 
randoms:EnableMouseWheel()
randoms:SetScript("OnMouseWheel", function(self, val) scrollbar:SetValue(scrollbar:GetValue() - val) end)
 
local randomstext = randoms:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
randomstext:SetHeight(32)
randomstext:SetPoint("TOPLEFT", randoms, "TOPLEFT", EDGEGAP, -EDGEGAP)
randomstext:SetPoint("RIGHT", randoms, -EDGEGAP-16, 0)
randomstext:SetNonSpaceWrap(true)
randomstext:SetJustifyH("LEFT")
randomstext:SetJustifyV("TOP")
randomstext:SetText("These pets will be used at random. Solid blue highlighted pets will be used more often.")
 
local function OnClick(self)
local v = kennel.randomdb[self.id] + 1
if v == 3 then v = 0 end
kennel.randomdb[self.id] = v
 
self:GetNormalTexture():SetDesaturated(v == 0)
self:SetChecked(v > 0)
self:GetCheckedTexture():SetAlpha(v/2)
 
kennel.nlow = 0
for i=1,GetNumCompanions("CRITTER") do
local _, name, id = GetCompanionInfo("CRITTER", i)
if kennel.randomdb[id] == 1 then kennel.nlow = kennel.nlow + 1 end
end
end
local function ShowTooltip(self)
if not self.name then return end
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
GameTooltip:SetText("|cffffffff"..self.name)
GameTooltip:Show()
end
local function HideTooltip() GameTooltip:Hide() end
 
for i=1,NUMROWS do
local row = CreateFrame("Frame", nil, randoms)
row:SetHeight(ICONSIZE)
if i == 1 then row:SetPoint("TOPLEFT", randoms, EDGEGAP, -EDGEGAP-ICONSIZE-6)
else row:SetPoint("TOPLEFT", rows[i-1], "BOTTOMLEFT", 0, -6) end
row:SetPoint("RIGHT", -EDGEGAP, 0)
row.buttons = {}
rows[i] = row
 
for j=1,NUMCOLS do
local iconbutton = CreateFrame("CheckButton", nil, row)
if j == 1 then iconbutton:SetPoint("TOPLEFT", row, "TOPLEFT")
else iconbutton:SetPoint("LEFT", row.buttons[j-1], "RIGHT", GAP, 0) end
iconbutton:SetWidth(ICONSIZE)
iconbutton:SetHeight(ICONSIZE)
 
iconbutton:SetHighlightTexture("Interface\\Buttons\\ButtonHilight-Square")
iconbutton:SetCheckedTexture("Interface\\Buttons\\UI-Button-Outline")
local tex = iconbutton:GetCheckedTexture()
tex:ClearAllPoints()
tex:SetPoint("CENTER")
tex:SetWidth(ICONSIZE/37*66) tex:SetHeight(ICONSIZE/37*66)
 
iconbutton:SetScript("OnEnter", ShowTooltip)
iconbutton:SetScript("OnLeave", HideTooltip)
iconbutton:SetScript("OnClick", OnClick)
 
row.buttons[j] = iconbutton
end
end
 
local offset = 0
local function Update()
scrollbar:SetMinMaxValues(0, math.max(0, math.ceil(GetNumCompanions("CRITTER")/NUMCOLS - NUMROWS)))
 
for i=1,NUMROWS do
for j=1,NUMCOLS do
local butt, buttoffset = rows[i].buttons[j], (i+offset-1)*NUMCOLS + j
local _, name, id, tex = GetCompanionInfo("CRITTER", buttoffset)
if name then
butt.name, butt.id = name, id
butt:SetNormalTexture(tex)
butt:GetNormalTexture():SetDesaturated(kennel.randomdb[id] == 0)
butt:SetChecked(kennel.randomdb[id] > 0)
butt:GetCheckedTexture():SetAlpha(kennel.randomdb[id]/2)
butt:Show()
else
butt:Hide()
end
end
end
end
 
local f = scrollbar:GetScript("OnValueChanged")
scrollbar:SetScript("OnValueChanged", function(self, value, ...)
offset = math.floor(value)
Update()
return f(self, value, ...)
end)
 
Update()
scrollbar:SetValue(0)
randoms:SetScript("OnShow", Update)
 
 
--------------------------
-- Zone panel --
--------------------------
 
zones = CreateFrame("Frame", nil, group)
zones:SetAllPoints()
zones:Hide()
 
local scrollbar = LibStub("tekKonfig-Scroll").new(zones, 6, 1)
 
zones:EnableMouseWheel()
zones:SetScript("OnMouseWheel", function(self, val) scrollbar:SetValue(scrollbar:GetValue() - val) end)
 
local zonestext = zones:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
zonestext:SetHeight(34)
zonestext:SetPoint("TOPLEFT", zones, "TOPLEFT", EDGEGAP, -EDGEGAP)
zonestext:SetPoint("RIGHT", zones, -EDGEGAP-16, 0)
zonestext:SetNonSpaceWrap(true)
zonestext:SetJustifyH("LEFT")
zonestext:SetJustifyV("TOP")
zonestext:SetText("These pets will be used when you are in the corresponding zone or subzone. Summon the desired pet and click an 'add' button to set that pet for the current zone or subzone.")
 
 
local NUMROWS = 10
local ROWHEIGHT = 15
local rows, Update, selectedzone = {}
local function OnClick(self)
selectedzone = self.zone:GetText()
Update()
end
for i=1,NUMROWS do
local row = CreateFrame("CheckButton", nil, zones)
row:SetHeight(ROWHEIGHT)
if i == 1 then row:SetPoint("TOP", zonestext, "BOTTOM", 0, -8)
else row:SetPoint("TOP", rows[i-1], "BOTTOM") end
row:SetPoint("LEFT", 4, 0)
row:SetPoint("RIGHT", scrollbar, "LEFT", -4, 0)
 
local highlight = row:CreateTexture()
highlight:SetTexture("Interface\\HelpFrame\\HelpFrameButton-Highlight")
highlight:SetTexCoord(0, 1, 0, 0.578125)
highlight:SetAllPoints()
row:SetHighlightTexture(highlight)
row:SetCheckedTexture(highlight)
 
local textzone = row:CreateFontString(nil, nil, "GameFontNormalSmall")
textzone:SetPoint("LEFT", EDGEGAP + GAP, 0)
local textpet = row:CreateFontString(nil, nil, "GameFontHighlightSmall")
textpet:SetPoint("LEFT", textzone, "RIGHT", GAP, 0)
textpet:SetPoint("RIGHT", -GAP, 0)
textpet:SetJustifyH("RIGHT")
 
row:SetScript("OnClick", OnClick)
 
row.zone = textzone
row.pet = textpet
textzone:SetText("Testing zone")
textpet:SetText("Test pet")
rows[i] = row
end
 
local offset, deletebutt, sortedzones = 0
function Update()
if not sortedzones then
sortedzones = {}
for i in pairs(KennelDBPC.zone) do table.insert(sortedzones, i) end
table.sort(sortedzones)
end
 
scrollbar:SetMinMaxValues(0, math.max(0, #sortedzones - NUMROWS))
 
local selectedvisible
for i,row in pairs(rows) do
local zone = sortedzones[i + offset]
local pet = zone and KennelDBPC.zone[zone]
if pet then
row.zone:SetText(zone)
row.pet:SetText(pet)
row:SetChecked(zone == selectedzone)
selectedvisible = selectedvisible or zone == selectedzone
row:Show()
else
row:Hide()
end
end
 
if selectedvisible then deletebutt:Enable() else deletebutt:Disable() end
end
 
local function GetCurrentPet()
for i=1,GetNumCompanions("CRITTER") do
local _, name, _, _, summoned = GetCompanionInfo("CRITTER", i)
if summoned then return name end
end
end
 
local addzone = LibStub("tekKonfig-Button").new(zones, "BOTTOMLEFT", zones, "BOTTOMLEFT", EDGEGAP, EDGEGAP):MakeSmall()
addzone.tiptext = "Click to set the currently summoned pet to be used in the current zone."
addzone:SetText("Add zone")
addzone:SetScript("OnClick", function()
KennelDBPC.zone[GetZoneText()] = GetCurrentPet()
sortedzones, selectedzone = nil
Update()
end)
 
local addsubzone = LibStub("tekKonfig-Button").new(zones, "LEFT", addzone, "RIGHT", GAP/2, 0):MakeSmall()
addsubzone.tiptext = "Click to set the currently summoned pet to be used in the current subzone."
addsubzone:SetText("Add subzone")
addsubzone:SetScript("OnShow", function(self) if GetSubZoneText() == "" then self:Disable() else self:Enable() end end)
addsubzone:SetScript("OnClick", function()
KennelDBPC.zone[GetZoneText() .." - "..GetSubZoneText()] = GetCurrentPet()
sortedzones, selectedzone = nil
Update()
end)
 
deletebutt = LibStub("tekKonfig-Button").new(zones, "BOTTOM", zones, "BOTTOM", 0, EDGEGAP):MakeSmall():MakeGrey()
deletebutt:SetPoint("RIGHT", scrollbar, "LEFT", -EDGEGAP, 0)
deletebutt.tiptext = "Remove the currently selected zone-pet setting."
deletebutt:SetText("Delete")
deletebutt:SetScript("OnClick", function()
KennelDBPC.zone[selectedzone], sortedzones, selectedzone = nil
Update()
end)
 
local f = scrollbar:GetScript("OnValueChanged")
scrollbar:SetScript("OnValueChanged", function(self, value, ...)
offset = math.floor(value)
Update()
return f(self, value, ...)
end)
 
Update()
scrollbar:SetValue(0)
zones:SetScript("OnShow", Update)
 
 
frame:SetScript("OnShow", nil)
end)
 
 
InterfaceOptions_AddCategory(frame)
 
LibStub("tekKonfig-AboutPanel").new("Kennel", "Kennel")