Mercurial > wow > reaction
comparison Editor.lua @ 216:376c424900f0
cleanup: editor bar options table generation
| author | Flick <flickerstreak@gmail.com> |
|---|---|
| date | Fri, 19 Nov 2010 14:33:45 -0800 |
| parents | 85213d045acb |
| children | e63aefb8a555 |
comparison
equal
deleted
inserted
replaced
| 215:258ca67bde4a | 216:376c424900f0 |
|---|---|
| 171 AceConfigReg:RegisterOptionsTable(self.configID, self.options) | 171 AceConfigReg:RegisterOptionsTable(self.configID, self.options) |
| 172 AceConfigDialog:SetDefaultSize(self.configID, 700, 540) | 172 AceConfigDialog:SetDefaultSize(self.configID, 700, 540) |
| 173 | 173 |
| 174 ReAction.RegisterCallback(self,"OnCreateBar") | 174 ReAction.RegisterCallback(self,"OnCreateBar") |
| 175 ReAction.RegisterCallback(self,"OnDestroyBar") | 175 ReAction.RegisterCallback(self,"OnDestroyBar") |
| 176 ReAction.RegisterCallback(self,"OnEraseBar") | |
| 177 ReAction.RegisterCallback(self,"OnRenameBar") | 176 ReAction.RegisterCallback(self,"OnRenameBar") |
| 178 | 177 |
| 179 for name, bar in ReAction:IterateBars() do | 178 self:RefreshBarOptions() |
| 180 self:CreateBarTree(bar) | |
| 181 end | |
| 182 | 179 |
| 183 return self | 180 return self |
| 184 end | 181 end |
| 185 | 182 |
| 186 | 183 |
| 201 | 198 |
| 202 function Editor:Refresh() | 199 function Editor:Refresh() |
| 203 AceConfigReg:NotifyChange(self.configID) | 200 AceConfigReg:NotifyChange(self.configID) |
| 204 end | 201 end |
| 205 | 202 |
| 206 function Editor:CreateBarTree(bar) | 203 function Editor:UpdateBarOptions(bar) |
| 207 local name = bar:GetName() | 204 local name = bar:GetName() |
| 208 -- AceConfig doesn't allow spaces, etc, in arg key names, and they must be | 205 local key = self.barOptMap[name] |
| 209 -- unique strings. So generate a unique key (it can be whatever) for the bar | |
| 210 local args = self.options.args | 206 local args = self.options.args |
| 211 local key | 207 |
| 212 local i = 1 | 208 if not key then |
| 213 repeat | 209 -- AceConfig doesn't allow spaces, etc, in arg key names, and they must be |
| 214 key = ("bar%s"):format(i) | 210 -- unique strings. So generate a unique key (it can be whatever) for the bar |
| 215 i = i+1 | 211 local i = 1 |
| 216 until args[key] == nil | 212 repeat |
| 217 self.barOptMap[name] = key | 213 key = ("bar%s"):format(i) |
| 218 args[key] = { | 214 i = i+1 |
| 219 type = "group", | 215 until args[key] == nil |
| 220 name = name, | 216 self.barOptMap[name] = key |
| 221 childGroups = "tab", | 217 |
| 222 order = i+100, | 218 args[key] = { |
| 223 args = { | 219 type = "group", |
| 224 general = { | 220 name = name, |
| 225 type = "group", | 221 childGroups = "tab", |
| 226 name = L["General"], | 222 order = i+100, |
| 227 order = 1, | 223 args = { |
| 228 args = { | 224 general = { |
| 229 name = { | 225 type = "group", |
| 230 type = "input", | 226 name = L["General"], |
| 231 name = L["Rename Bar"], | 227 order = 1, |
| 232 get = function() return bar:GetName() end, | 228 args = { |
| 233 set = function(info, value) return ReAction:RenameBar(bar, value) end, | 229 name = { |
| 234 order = 1, | 230 type = "input", |
| 235 }, | 231 name = L["Rename Bar"], |
| 236 delete = { | 232 get = function() return bar:GetName() end, |
| 237 type = "execute", | 233 set = function(info, value) return ReAction:RenameBar(bar, value) end, |
| 238 name = L["Delete Bar"], | 234 order = 1, |
| 239 desc = function() return bar:GetName() end, | 235 }, |
| 240 confirm = true, | 236 delete = { |
| 241 func = function() ReAction:EraseBar(bar) end, | 237 type = "execute", |
| 242 order = 2 | 238 name = L["Delete Bar"], |
| 243 }, | 239 desc = function() return bar:GetName() end, |
| 244 anchor = { | 240 confirm = true, |
| 245 type = "group", | 241 func = function() ReAction:EraseBar(bar) end, |
| 246 name = L["Anchor"], | 242 order = 2 |
| 247 inline = true, | 243 }, |
| 248 args = { | 244 anchor = { |
| 249 frame = { | 245 type = "group", |
| 250 type = "input", | 246 name = L["Anchor"], |
| 251 name = L["Frame"], | 247 inline = true, |
| 252 desc = L["The frame that the bar is anchored to"], | 248 args = { |
| 253 get = function() local _, f = bar:GetAnchor(); return f end, | 249 frame = { |
| 254 set = function(info, val) bar:SetAnchor(nil,val) end, | 250 type = "input", |
| 255 validate = function(info, name) | 251 name = L["Frame"], |
| 256 if name then | 252 desc = L["The frame that the bar is anchored to"], |
| 257 local f = ReAction:GetBar(name) | 253 get = function() local _, f = bar:GetAnchor(); return f end, |
| 258 if f then | 254 set = function(info, val) bar:SetAnchor(nil,val) end, |
| 259 return true | 255 validate = function(info, name) |
| 260 else | 256 if name then |
| 261 f = _G[name] | 257 local f = ReAction:GetBar(name) |
| 262 if f and type(f) == "table" and f.IsObjectType and f:IsObjectType("Frame") then | 258 if f then |
| 263 local _, explicit = f:IsProtected() | 259 return true |
| 264 return explicit | 260 else |
| 261 f = _G[name] | |
| 262 if f and type(f) == "table" and f.IsObjectType and f:IsObjectType("Frame") then | |
| 263 local _, explicit = f:IsProtected() | |
| 264 return explicit | |
| 265 end | |
| 265 end | 266 end |
| 266 end | 267 end |
| 267 end | 268 return false |
| 268 return false | 269 end, |
| 269 end, | 270 width = "double", |
| 270 width = "double", | 271 order = 1 |
| 271 order = 1 | 272 }, |
| 273 point = { | |
| 274 type = "select", | |
| 275 name = L["Point"], | |
| 276 desc = L["Anchor point on the bar frame"], | |
| 277 style = "dropdown", | |
| 278 get = function() return bar:GetAnchor() end, | |
| 279 set = function(info, val) bar:SetAnchor(val) end, | |
| 280 values = pointTable, | |
| 281 order = 2, | |
| 282 }, | |
| 283 relativePoint = { | |
| 284 type = "select", | |
| 285 name = L["Relative Point"], | |
| 286 desc = L["Anchor point on the target frame"], | |
| 287 style = "dropdown", | |
| 288 get = function() local p,f,r = bar:GetAnchor(); return r end, | |
| 289 set = function(info, val) bar:SetAnchor(nil,nil,val) end, | |
| 290 values = pointTable, | |
| 291 order = 3, | |
| 292 }, | |
| 293 x = { | |
| 294 type = "input", | |
| 295 pattern = "\-?%d+", | |
| 296 name = L["X offset"], | |
| 297 get = function() local p,f,r,x = bar:GetAnchor(); return ("%d"):format(x) end, | |
| 298 set = function(info,val) bar:SetAnchor(nil,nil,nil,val) end, | |
| 299 order = 4 | |
| 300 }, | |
| 301 y = { | |
| 302 type = "input", | |
| 303 pattern = "\-?%d+", | |
| 304 name = L["Y offset"], | |
| 305 get = function() local p,f,r,x,y = bar:GetAnchor(); return ("%d"):format(y) end, | |
| 306 set = function(info,val) bar:SetAnchor(nil,nil,nil,nil,val) end, | |
| 307 order = 5 | |
| 308 }, | |
| 272 }, | 309 }, |
| 273 point = { | 310 order = 3 |
| 274 type = "select", | |
| 275 name = L["Point"], | |
| 276 desc = L["Anchor point on the bar frame"], | |
| 277 style = "dropdown", | |
| 278 get = function() return bar:GetAnchor() end, | |
| 279 set = function(info, val) bar:SetAnchor(val) end, | |
| 280 values = pointTable, | |
| 281 order = 2, | |
| 282 }, | |
| 283 relativePoint = { | |
| 284 type = "select", | |
| 285 name = L["Relative Point"], | |
| 286 desc = L["Anchor point on the target frame"], | |
| 287 style = "dropdown", | |
| 288 get = function() local p,f,r = bar:GetAnchor(); return r end, | |
| 289 set = function(info, val) bar:SetAnchor(nil,nil,val) end, | |
| 290 values = pointTable, | |
| 291 order = 3, | |
| 292 }, | |
| 293 x = { | |
| 294 type = "input", | |
| 295 pattern = "\-?%d+", | |
| 296 name = L["X offset"], | |
| 297 get = function() local p,f,r,x = bar:GetAnchor(); return ("%d"):format(x) end, | |
| 298 set = function(info,val) bar:SetAnchor(nil,nil,nil,val) end, | |
| 299 order = 4 | |
| 300 }, | |
| 301 y = { | |
| 302 type = "input", | |
| 303 pattern = "\-?%d+", | |
| 304 name = L["Y offset"], | |
| 305 get = function() local p,f,r,x,y = bar:GetAnchor(); return ("%d"):format(y) end, | |
| 306 set = function(info,val) bar:SetAnchor(nil,nil,nil,nil,val) end, | |
| 307 order = 5 | |
| 308 }, | |
| 309 }, | 311 }, |
| 310 order = 3 | 312 alpha = { |
| 311 }, | 313 type = "range", |
| 312 alpha = { | 314 name = L["Transparency"], |
| 313 type = "range", | 315 get = function() return bar:GetAlpha() end, |
| 314 name = L["Transparency"], | 316 set = function(info, val) bar:SetAlpha(val) end, |
| 315 get = function() return bar:GetAlpha() end, | 317 min = 0, |
| 316 set = function(info, val) bar:SetAlpha(val) end, | 318 max = 1, |
| 317 min = 0, | 319 isPercent = true, |
| 318 max = 1, | 320 step = 0.01, |
| 319 isPercent = true, | 321 bigStep = 0.05, |
| 320 step = 0.01, | 322 order = 4, |
| 321 bigStep = 0.05, | 323 }, |
| 322 order = 4, | |
| 323 }, | 324 }, |
| 324 }, | 325 }, |
| 325 }, | 326 }, |
| 327 plugins = { } | |
| 326 } | 328 } |
| 327 } | 329 end |
| 328 self:RefreshBarOptions() | 330 |
| 331 if ReAction.barOptionGenerators then | |
| 332 for module, func in pairs(ReAction.barOptionGenerators) do | |
| 333 local success, r | |
| 334 if type(func) == "string" then | |
| 335 success, r = pcall(module[func], module, bar) | |
| 336 else | |
| 337 success, r = pcall(func, bar) | |
| 338 end | |
| 339 if success then | |
| 340 if r then | |
| 341 args[key].plugins[module:GetName()] = { [module:GetName()] = r } | |
| 342 end | |
| 343 else | |
| 344 geterrorhandler()(r) | |
| 345 end | |
| 346 end | |
| 347 end | |
| 329 end | 348 end |
| 330 | 349 |
| 331 function Editor:RefreshBarOptions() | 350 function Editor:RefreshBarOptions() |
| 332 for name, key in pairs(self.barOptMap) do | 351 for key, name in pairs(self.barOptMap) do |
| 333 local bar = ReAction:GetBar(name) | 352 if not ReAction:GetBar(name) then |
| 334 if bar and key and self.options.args[key] then | 353 self.barOptMap[key] = nil |
| 335 self.options.args[key].plugins = self:GenerateBarOptionsTable(bar) | |
| 336 end | 354 end |
| 337 end | 355 end |
| 338 AceConfigReg:NotifyChange(self.configID) | 356 for name, bar in ReAction:IterateBars() do |
| 357 self:UpdateBarOptions(bar) | |
| 358 end | |
| 359 self:Refresh() | |
| 339 end | 360 end |
| 340 | 361 |
| 341 function Editor:OnCreateBar(evt, bar) | 362 function Editor:OnCreateBar(evt, bar) |
| 342 if not self.tmp.creating then | 363 self:UpdateBarOptions(bar) |
| 343 -- a bit of hack to work around OnCreateBar event handler ordering | 364 self:Refresh() |
| 344 self:CreateBarTree(bar) | |
| 345 end | |
| 346 end | 365 end |
| 347 | 366 |
| 348 function Editor:OnDestroyBar(evt, bar, name) | 367 function Editor:OnDestroyBar(evt, bar, name) |
| 349 local key = self.barOptMap[name] | 368 local key = self.barOptMap[name] |
| 350 if key then | 369 if key then |
| 351 self.options.args[key] = nil | 370 self.barOptMap[name] = nil |
| 352 end | |
| 353 self:Refresh() | |
| 354 end | |
| 355 | |
| 356 function Editor:OnEraseBar(evt, name) | |
| 357 local key = self.barOptMap[name] | |
| 358 self.barOptMap[name] = nil | |
| 359 if key then | |
| 360 self.options.args[key] = nil | 371 self.options.args[key] = nil |
| 361 self:Refresh() | 372 self:Refresh() |
| 362 end | 373 end |
| 363 end | 374 end |
| 364 | 375 |
| 365 function Editor:OnRenameBar(evt, bar, oldname, newname) | 376 function Editor:OnRenameBar(evt, bar, oldname, newname) |
| 366 local key = self.barOptMap[oldname] | 377 local key = self.barOptMap[oldname] |
| 367 self.barOptMap[oldname], self.barOptMap[newname] = nil, key | |
| 368 if key then | 378 if key then |
| 379 self.barOptMap[oldname], self.barOptMap[newname] = nil, key | |
| 369 self.options.args[key].name = newname | 380 self.options.args[key].name = newname |
| 370 self:Refresh() | 381 self:Refresh() |
| 371 end | 382 end |
| 372 end | 383 end |
| 373 | 384 |
| 377 return ReAction:GetBarTypeOptions(_scratch) | 388 return ReAction:GetBarTypeOptions(_scratch) |
| 378 end | 389 end |
| 379 | 390 |
| 380 function Editor:CreateBar() | 391 function Editor:CreateBar() |
| 381 if self.tmp.barName and self.tmp.barName ~= "" then | 392 if self.tmp.barName and self.tmp.barName ~= "" then |
| 382 self.tmp.creating = true | |
| 383 local bar = ReAction:CreateBar(self.tmp.barName, self.tmp.barType or ReAction:GetDefaultBarType(), self.tmp.barRows, self.tmp.barCols, self.tmp.barSize, self.tmp.barSpacing) | 393 local bar = ReAction:CreateBar(self.tmp.barName, self.tmp.barType or ReAction:GetDefaultBarType(), self.tmp.barRows, self.tmp.barCols, self.tmp.barSize, self.tmp.barSpacing) |
| 384 if bar then | 394 if bar then |
| 385 self:CreateBarTree(bar) | |
| 386 AceConfigDialog:SelectGroup(self.configID, self.barOptMap[self.tmp.barName]) | 395 AceConfigDialog:SelectGroup(self.configID, self.barOptMap[self.tmp.barName]) |
| 387 self.tmp.barName = nil | 396 self.tmp.barName = nil |
| 388 end | 397 end |
| 389 self.tmp.creating = false | 398 end |
| 390 end | |
| 391 end | |
| 392 | |
| 393 function Editor:GenerateBarOptionsTable( bar ) | |
| 394 local opts = { } | |
| 395 if not ReAction.barOptionGenerators then | |
| 396 return | |
| 397 end | |
| 398 | |
| 399 for module, func in pairs(ReAction.barOptionGenerators) do | |
| 400 local success, r | |
| 401 if type(func) == "string" then | |
| 402 success, r = pcall(module[func], module, bar) | |
| 403 else | |
| 404 success, r = pcall(func, bar) | |
| 405 end | |
| 406 if success then | |
| 407 if r then | |
| 408 opts[module:GetName()] = { [module:GetName()] = r } | |
| 409 end | |
| 410 else | |
| 411 geterrorhandler()(r) | |
| 412 end | |
| 413 end | |
| 414 return opts | |
| 415 end | 399 end |
| 416 | 400 |
| 417 | 401 |
| 418 | 402 |
| 419 ---- Export to ReAction ---- | 403 ---- Export to ReAction ---- |
