annotate HotCorners.lua @ 3:be6f5d3e0a95

- Added Summary Panel.
author tercio
date Sun, 31 Aug 2014 21:23:10 -0300
parents a6fb0ff113b1
children d8a463c5ef5a
rev   line source
tercio@0 1 LibHotCorners = LibStub ("AceAddon-3.0"):NewAddon ("HotCorners", "AceConsole-3.0", "AceEvent-3.0", "AceTimer-3.0")
tercio@1 2 _G.HotCorners = LibHotCorners
tercio@0 3 local LibHotCorners = LibHotCorners
tercio@0 4
tercio@0 5 local LBD = LibStub ("LibDataBroker-1.1")
tercio@0 6
tercio@0 7 local debug = false
tercio@0 8 local tinsert = tinsert
tercio@0 9
tercio@0 10 local default_db = {
tercio@0 11 profile = {
tercio@0 12 is_enabled = true,
tercio@0 13 topleft_enabled = true,
tercio@1 14 topleft_quickfunc = false,
tercio@0 15 clicks = {},
tercio@0 16 disabled = {}
tercio@0 17 },
tercio@0 18 }
tercio@0 19
tercio@1 20 LibHotCorners.RegistredQuickFunctions = {}
tercio@1 21 LibHotCorners.QuickFunctions = {topleft = false}
tercio@1 22
tercio@0 23 function LibHotCorners:OnEnable()
tercio@0 24
tercio@0 25 end
tercio@0 26
tercio@0 27 function LibHotCorners:OnDisable()
tercio@0 28
tercio@0 29 end
tercio@0 30
tercio@2 31 LibHotCorners.ItemButtons = {}
tercio@2 32 LibHotCorners.ItemOnInventory = {}
tercio@2 33
tercio@0 34 local refresh_topleft = function()
tercio@0 35 LibHotCorners ["topleft"].is_enabled = LibHotCorners.db.profile.topleft_enabled
tercio@0 36 end
tercio@0 37
tercio@0 38 local OptionsTable = {
tercio@0 39 name = "HotCorners",
tercio@0 40 type = "group",
tercio@0 41 args = {
tercio@0 42 Enabled = {
tercio@0 43 type = "toggle",
tercio@0 44 name = "Enabled",
tercio@0 45 desc = "Enable or Disable this addon.",
tercio@0 46 order = 1,
tercio@0 47 get = function() return LibHotCorners.db.profile.is_enabled end,
tercio@0 48 set = function (self, val) LibHotCorners.db.profile.is_enabled = not LibHotCorners.db.profile.is_enabled; --[[ do something]] end,
tercio@0 49 },
tercio@0 50 TopLeftEnabled = {
tercio@0 51 type = "toggle",
tercio@0 52 name = "Top Left",
tercio@0 53 desc = "Enable or Disable the Top Left bar.",
tercio@0 54 order = 2,
tercio@0 55 get = function() return LibHotCorners.db.profile.topleft_enabled end,
tercio@0 56 set = function (self, val) LibHotCorners.db.profile.topleft_enabled = not LibHotCorners.db.profile.topleft_enabled; refresh_topleft() end,
tercio@0 57 },
tercio@1 58 QuickClickFunc = {
tercio@1 59 type = "select",
tercio@1 60 name = "Quick Click",
tercio@1 61 desc = "Select the behavior when clicking over the absolute topleft corner.",
tercio@1 62 values = function()
tercio@1 63 local options = {}
tercio@1 64 for index, quickfunc in ipairs (LibHotCorners.RegistredQuickFunctions) do
tercio@1 65 options [quickfunc.name] = quickfunc.name
tercio@1 66 end
tercio@1 67 return options
tercio@1 68 end,
tercio@1 69 get = function() return LibHotCorners.db.profile.topleft_quickfunc or "" end,
tercio@1 70 set = function (self, funcname)
tercio@1 71 LibHotCorners.db.profile.topleft_quickfunc = funcname;
tercio@1 72 for index, quickfunc in ipairs (LibHotCorners.RegistredQuickFunctions) do
tercio@1 73 if (quickfunc.name == funcname) then
tercio@1 74 LibHotCorners.QuickFunctions.topleft = quickfunc.func
tercio@1 75 break
tercio@1 76 end
tercio@1 77 end
tercio@1 78 end,
tercio@1 79 order = 4,
tercio@1 80 }
tercio@0 81 }
tercio@0 82 }
tercio@0 83
tercio@0 84 function LibHotCorners:OnInitialize()
tercio@0 85
tercio@0 86 --declarar primeiro o db usando a global que é declarada no toc.
tercio@0 87 self.db = LibStub ("AceDB-3.0"):New ("HotCornersDB", default_db, true)
tercio@0 88
tercio@0 89 --declara agora as opções da tab raiz
tercio@0 90 LibStub("AceConfig-3.0"):RegisterOptionsTable ("HotCorners", OptionsTable)
tercio@0 91 LibHotCorners.OptionsFrame1 = LibStub ("AceConfigDialog-3.0"):AddToBlizOptions ("HotCorners", "HotCorners")
tercio@0 92 --sub tab
tercio@0 93 LibStub ("AceConfig-3.0"):RegisterOptionsTable ("HotCorners-Profiles", LibStub ("AceDBOptions-3.0"):GetOptionsTable (self.db))
tercio@0 94 LibHotCorners.OptionsFrame2 = LibStub ("AceConfigDialog-3.0"):AddToBlizOptions ("HotCorners-Profiles", "Profiles", "HotCorners")
tercio@0 95
tercio@0 96 LibHotCorners ["topleft"].is_enabled = self.db.topleft_enabled
tercio@0 97 refresh_topleft()
tercio@0 98
tercio@0 99 SLASH_HOTCORNER1, SLASH_HOTCORNER2 = "/hotcorners", "/hotcorner"
tercio@0 100 function SlashCmdList.HOTCORNER (msg, editbox)
tercio@0 101 HotCornersOpenOptions (self);
tercio@0 102 end
tercio@0 103
tercio@0 104 for name, dataobj in LBD:DataObjectIterator() do
tercio@0 105 if (dataobj.type and dataobj.icon and dataobj.OnClick) then
tercio@0 106 LibHotCorners:RegisterHotCornerButton (name, "TopLeft", nil, name .. "HotCornerLauncher", dataobj.icon, dataobj.OnTooltipShow, dataobj.OnClick, nil, nil, dataobj.OnEnter, dataobj.OnLeave)
tercio@0 107 end
tercio@0 108 end
tercio@0 109 for k, v in pairs (LBD.attributestorage) do
tercio@0 110 --print (k, v)
tercio@0 111 --print ("----------------")
tercio@0 112 --vardump (v)
tercio@0 113 end
tercio@0 114
tercio@0 115 end
tercio@0 116
tercio@0 117 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
tercio@0 118 --> main function
tercio@0 119
tercio@0 120 LibHotCorners.embeds = LibHotCorners.embeds or {}
tercio@0 121 local embed_functions = {
tercio@0 122 "RegisterHotCornerButton",
tercio@0 123 "HideHotCornerButton",
tercio@0 124 }
tercio@0 125
tercio@0 126 function LibHotCorners:Embed (target)
tercio@0 127 for k, v in pairs (embed_functions) do
tercio@0 128 target[v] = self[v]
tercio@0 129 end
tercio@0 130 self.embeds [target] = true
tercio@0 131 return target
tercio@0 132 end
tercio@0 133
tercio@0 134 local CallbackHandler = LibStub:GetLibrary ("CallbackHandler-1.0")
tercio@0 135 LibHotCorners.callbacks = LibHotCorners.callbacks or CallbackHandler:New (LibHotCorners)
tercio@0 136
tercio@0 137 LibHotCorners.topleft = LibHotCorners.topleft or {widgets = {}, quickclick = false, is_enabled = false, map = {}}
tercio@0 138 LibHotCorners.bottomleft = {}
tercio@0 139 LibHotCorners.topright = {}
tercio@0 140 LibHotCorners.bottomright = {}
tercio@0 141
tercio@0 142 local function test (corner)
tercio@0 143 assert (corner == "topleft" or corner == "bottomleft" or corner == "topright" or corner == "bottomright", "LibHotCorners:RegisterAddon expects a corner on #1 argument.")
tercio@0 144 end
tercio@0 145
tercio@1 146 function LibHotCorners:AddQuickFunction (quickfunc, corner)
tercio@1 147
tercio@1 148 local current_quickfunc = LibHotCorners.db.profile [corner .. "_quickfunc"] or ""
tercio@1 149
tercio@1 150 --> passed only one table
tercio@1 151 if (quickfunc.name) then
tercio@1 152 --> check if already exists
tercio@1 153 local already_exists = false
tercio@1 154 for _, registred in ipairs (LibHotCorners.RegistredQuickFunctions) do
tercio@1 155 if (registred.name == quickfunc.name) then
tercio@1 156 registred.func = quickfunc.func
tercio@1 157 if (current_quickfunc == quickfunc.name) then
tercio@1 158 LibHotCorners.QuickFunctions [corner] = quickfunc.func
tercio@1 159 end
tercio@1 160 already_exists = true
tercio@1 161 break
tercio@1 162 end
tercio@1 163 end
tercio@1 164 --> add table
tercio@1 165 if (not already_exists) then
tercio@1 166 table.insert (LibHotCorners.RegistredQuickFunctions, quickfunc)
tercio@1 167 if (current_quickfunc == quickfunc.name) then
tercio@1 168 LibHotCorners.QuickFunctions [corner] = quickfunc.func
tercio@1 169 end
tercio@1 170 end
tercio@1 171 --> check if there is a quickfunc to be use
tercio@1 172 if (current_quickfunc == "") then
tercio@1 173 LibHotCorners.db.profile [corner .. "_quickfunc"] = quickfunc.name
tercio@1 174 LibHotCorners.QuickFunctions [corner] = quickfunc.func
tercio@1 175 end
tercio@1 176 else
tercio@1 177 --> passed a table of tables
tercio@1 178 for _, this_quickfunc in ipairs (quickfunc) do
tercio@1 179 --> check if already exists
tercio@1 180 local already_exists = false
tercio@1 181 for _, registred in ipairs (LibHotCorners.RegistredQuickFunctions) do
tercio@1 182 if (registred.name == this_quickfunc.name) then
tercio@1 183 registred.func = this_quickfunc.func
tercio@1 184 if (current_quickfunc == this_quickfunc.name) then
tercio@1 185 LibHotCorners.QuickFunctions [corner] = this_quickfunc.func
tercio@1 186 end
tercio@1 187 already_exists = true
tercio@1 188 break
tercio@1 189 end
tercio@1 190 end
tercio@1 191 --> add table
tercio@1 192 if (not already_exists) then
tercio@1 193 table.insert (LibHotCorners.RegistredQuickFunctions, this_quickfunc)
tercio@1 194 if (current_quickfunc == this_quickfunc.name) then
tercio@1 195 LibHotCorners.QuickFunctions [corner] = this_quickfunc.func
tercio@1 196 end
tercio@1 197 end
tercio@1 198 --> check if there is a quickfunc to be use
tercio@1 199 if (current_quickfunc == "") then
tercio@1 200 LibHotCorners.db.profile [corner .. "_quickfunc"] = this_quickfunc.name
tercio@1 201 LibHotCorners.QuickFunctions [corner] = this_quickfunc.func
tercio@1 202 current_quickfunc = this_quickfunc.name
tercio@1 203 end
tercio@1 204 end
tercio@1 205 end
tercio@1 206
tercio@1 207 end
tercio@1 208
tercio@1 209 function LibHotCorners:RegisterHotCornerButton (name, corner, optionstable, fname, icon, tooltip, clickfunc, menus, quickfunc, onenter, onleave, is_install)
tercio@0 210 corner = string.lower (corner)
tercio@0 211 test (corner)
tercio@0 212
tercio@1 213 optionstable = optionstable or {hide = false}
tercio@1 214
tercio@0 215 if (is_install) then
tercio@0 216 --> overwrite if already exists a widget
tercio@0 217 for i, widget in ipairs (LibHotCorners [corner]) do
tercio@0 218 if (widget.name == name) then
tercio@0 219 table.remove (LibHotCorners [corner], i)
tercio@1 220 table.insert (LibHotCorners [corner], i, {name = name, fname = fname, optionstable = optionstable, icon = icon, tooltip = tooltip, click = clickfunc, menus = menus, quickfunc = quickfunc, onenter = onenter, onleave = onleave, is_install = true})
tercio@1 221 if (quickfunc) then
tercio@1 222 LibHotCorners:AddQuickFunction (quickfunc, corner)
tercio@1 223 end
tercio@0 224 return LibHotCorners [corner].map [name]
tercio@0 225 end
tercio@0 226 end
tercio@1 227 --> add
tercio@1 228 table.insert (LibHotCorners [corner], {name = name, fname = fname, optionstable = optionstable, icon = icon, tooltip = tooltip, click = clickfunc, menus = menus, quickfunc = quickfunc, onenter = onenter, onleave = onleave, is_install = true})
tercio@0 229 LibHotCorners [corner].map [name] = #LibHotCorners [corner]
tercio@1 230 if (quickfunc) then
tercio@1 231 LibHotCorners:AddQuickFunction (quickfunc, corner)
tercio@1 232 end
tercio@0 233 return LibHotCorners [corner].map [name]
tercio@0 234 else
tercio@1 235 --> check if already exists
tercio@1 236 for i, widget in ipairs (LibHotCorners [corner]) do
tercio@1 237 if (widget.name == name) then
tercio@1 238 return
tercio@0 239 end
tercio@0 240 end
tercio@1 241 --> add
tercio@1 242 table.insert (LibHotCorners [corner], {name = name, fname = fname, optionstable = optionstable, icon = icon, tooltip = tooltip, click = clickfunc, menus = menus, quickfunc = quickfunc, onenter = onenter, onleave = onleave})
tercio@1 243 LibHotCorners [corner].map [name] = #LibHotCorners [corner]
tercio@1 244 if (quickfunc) then
tercio@1 245 LibHotCorners:AddQuickFunction (quickfunc, corner)
tercio@0 246 end
tercio@1 247 return LibHotCorners [corner].map [name]
tercio@0 248 end
tercio@0 249 end
tercio@0 250
tercio@0 251 function LibHotCorners:HideHotCornerButton (name, corner, value)
tercio@0 252
tercio@0 253 corner = string.lower (corner)
tercio@0 254 test (corner)
tercio@0 255
tercio@0 256 local corner_table = LibHotCorners [corner]
tercio@0 257 local addon_table = corner_table [corner_table.map [name]]
tercio@0 258
tercio@1 259 if (addon_table) then
tercio@1 260 addon_table.optionstable.hide = value
tercio@1 261 end
tercio@0 262
tercio@0 263 LibHotCorners [corner].is_enabled = false
tercio@0 264
tercio@1 265 for index, button_table in ipairs (corner_table) do
tercio@1 266 if (not button_table.optionstable.hide) then
tercio@0 267 LibHotCorners [corner].is_enabled = true
tercio@0 268 break
tercio@0 269 end
tercio@0 270 end
tercio@0 271
tercio@0 272 return true
tercio@0 273 end
tercio@0 274
tercio@0 275 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
tercio@0 276 --> data broker stuff
tercio@0 277 function LibHotCorners:DataBrokerCallback (event, name, dataobj)
tercio@0 278 if (not name or not dataobj or not dataobj.type) then
tercio@0 279 return
tercio@0 280 end
tercio@0 281 if (dataobj.icon and dataobj.OnClick) then
tercio@0 282 LibHotCorners:RegisterHotCornerButton (name, "TopLeft", nil, name .. "HotCornerLauncher", dataobj.icon, dataobj.OnTooltipShow, dataobj.OnClick, nil, nil, dataobj.OnEnter, dataobj.OnLeave)
tercio@0 283 end
tercio@0 284 end
tercio@0 285 LBD.RegisterCallback (LibHotCorners, "DataBrokerCallback")
tercio@0 286
tercio@0 287 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
tercio@0 288 --> scripts
tercio@0 289
tercio@0 290 --> background (window mode fix)
tercio@0 291 function HotCornersBackgroundOnEnter (self)
tercio@0 292 if (LibHotCornersTopLeft and LibHotCornersTopLeft:IsShown()) then
tercio@0 293 if (LibHotCornersTopLeft:GetWidth() > 2) then
tercio@2 294 HotCornersOnLeave (LibHotCornersTopLeft, true)
tercio@0 295 end
tercio@0 296 end
tercio@0 297 self:EnableMouse (false)
tercio@0 298 end
tercio@0 299
tercio@0 300 --> set size
tercio@0 301 local function set_size (self)
tercio@0 302 if (self.position == "topleft" or self.position == "topright") then
tercio@0 303 self:SetSize (40, GetScreenHeight())
tercio@0 304 else
tercio@0 305 self:SetSize (GetScreenWidth(), 40)
tercio@0 306 end
tercio@0 307 end
tercio@0 308
tercio@0 309 --> show tooltip
tercio@0 310 local show_tooltip = function (self)
tercio@2 311 if (self.table and self.table.tooltip) then
tercio@0 312 if (type (self.table.tooltip) == "function") then
tercio@0 313 GameTooltip:SetOwner (self, "ANCHOR_RIGHT")
tercio@0 314 self.table.tooltip (GameTooltip)
tercio@0 315 GameTooltip:Show()
tercio@0 316 elseif (type (self.table.tooltip) == "string") then
tercio@0 317 GameTooltip:SetOwner (self, "ANCHOR_RIGHT")
tercio@0 318 GameTooltip:AddLine (self.table.tooltip)
tercio@0 319 GameTooltip:Show()
tercio@0 320 end
tercio@2 321 elseif (self.table and self.table.onenter) then
tercio@0 322 self.table.onenter (self)
tercio@2 323 elseif (self.isItem) then
tercio@2 324 GameTooltip:SetOwner (self, "ANCHOR_BOTTOMRIGHT")
tercio@2 325 GameTooltip:SetHyperlink (self.itemtable[4])
tercio@2 326 GameTooltip:Show()
tercio@0 327 end
tercio@0 328 end
tercio@0 329
tercio@0 330 --> corner frame on enter
tercio@0 331 local more_clicked = function (t1, t2)
tercio@0 332 return t1[1] > t2[1]
tercio@0 333 end
tercio@0 334
tercio@2 335 LibHotCorners.BackPackItemList = {
tercio@2 336
tercio@2 337 --> alchemy
tercio@2 338 [76086] = true, -- Flask of Falling Leaves
tercio@2 339 [76084] = true, -- Flask of Spring Blossoms
tercio@2 340 [76085] = true, -- Flask of the Warm Sun
tercio@2 341 [76087] = true, -- Flask of the Earth
tercio@2 342 [76088] = true, -- Flask of Winter's Bite
tercio@2 343
tercio@2 344 [76081] = true, -- Elixir of Mirrors
tercio@2 345 [76079] = true, -- Elixir of Peace
tercio@2 346 [76080] = true, -- Elixir of Perfection
tercio@2 347 [76078] = true, -- Elixir of the Rapids
tercio@2 348 [76077] = true, -- Elixir of Weaponry
tercio@2 349 [70676] = true, -- Mad Hozen Elixir
tercio@2 350 [76075] = true, -- Mantid Elixir
tercio@2 351 [76083] = true, -- Monk's Elixir
tercio@2 352
tercio@2 353 [76094] = true, -- Alchemist's Rejuvenation
tercio@2 354 [96096] = true, -- Darkwater Potion
tercio@2 355 [75218] = true, -- Electrified Oil
tercio@2 356 [76097] = true, -- Master Healing Potion
tercio@2 357 [76098] = true, -- Master Mana Potion
tercio@2 358 [76092] = true, -- Potion of Focus
tercio@2 359 [76093] = true, -- Potion of the Jade Serpent
tercio@2 360 [76095] = true, -- Potion of Mogu Power
tercio@2 361 [76090] = true, -- Potion of the Mountains
tercio@2 362 [76091] = true, -- Greater Potion of Luck
tercio@2 363 [76089] = true, -- Virmen's Bite
tercio@2 364
tercio@2 365 --> cooking
tercio@2 366
tercio@2 367 --Way of the Grill: Strength
tercio@2 368 [74642] = true, -- Charbroiled Tiger Steak
tercio@2 369 [74645] = true, -- Eternal Blossom Fish
tercio@2 370 [74646] = true, -- Black Pepper Ribs and Shrimp
tercio@2 371
tercio@2 372 --Way of the Oven: Stamina
tercio@2 373 [74654] = true, -- Wildfowl Roast
tercio@2 374 [74655] = true, -- Twin Fish Platter
tercio@2 375 [74656] = true, -- Chun Tian Spring Rolls
tercio@2 376
tercio@2 377 --Way of the Pot: Intellect
tercio@2 378
tercio@2 379 [74644] = true, -- Swirling Mist Soup
tercio@2 380 [74649] = true, -- Braised Turtle
tercio@2 381 [74650] = true, -- Mogu Fish Stew
tercio@2 382
tercio@2 383 --Way of the Steamer: Spirit
tercio@2 384
tercio@2 385 [74651] = true, -- Shrimp Dumplings
tercio@2 386 [74652] = true, -- Fire Spirit Salmon
tercio@2 387 [74653] = true, -- Steamed Crab Surprise
tercio@2 388
tercio@2 389 --Way of the Wok: Agility
tercio@2 390
tercio@2 391 [74643] = true, -- Sauteed Carrots
tercio@2 392 [74647] = true, -- Valley Stir Fry
tercio@2 393 [74648] = true, -- Sea Mist Rice Noodles
tercio@2 394
tercio@2 395 --Way of the Brew: Headaches and Grandeur
tercio@2 396
tercio@2 397 [74626] = true, -- Ginseng Tea
tercio@2 398 [74637] = true, -- Jade Witch Brew
tercio@2 399 [74638] = true, -- Mad Brewer's Breakfast
tercio@2 400
tercio@2 401 --General Cooking
tercio@2 402
tercio@2 403 [74641] = true, -- Fish Cake
tercio@2 404 [74636] = true, -- Golden Carp Consomme
tercio@2 405 [86070] = true, -- Wildfowl Ginseng Soup
tercio@2 406 [86069] = true, -- Rice Pudding
tercio@2 407 [86074] = true, -- Spicy Vegetable Chips
tercio@2 408 [86073] = true, -- Spicy Salmon
tercio@2 409
tercio@2 410 --5.4 Recipes
tercio@2 411
tercio@2 412 [145308] = true, -- Mango Ice
tercio@2 413 [145309] = true, -- Farmer's Delight
tercio@2 414 [145311] = true, -- Fluffy Silkfeather Omelet
tercio@2 415 [145310] = true, -- Stuffed Lushrooms
tercio@2 416 [145307] = true, -- Spiced Blossom Soup
tercio@2 417 [145305] = true, -- Seasoned Pomfruit Slices
tercio@2 418
tercio@2 419 --Cart Kits
tercio@2 420 [101630] = true, -- Noodle Cart Kit
tercio@2 421 [101661] = true, -- Deluxe Noodle Cart Kit
tercio@2 422 [101662] = true, -- Pandaren Treasure Noodle Cart Kit
tercio@2 423
tercio@2 424 [101618] = true, -- Pandaren Treasure Noodle Soup
tercio@2 425 [101617] = true, -- Deluxe Noodle Soup
tercio@2 426 [101616] = true, -- Noodle Soup
tercio@2 427 }
tercio@2 428
tercio@0 429 function HotCornersOnEnter (self)
tercio@0 430
tercio@0 431 if (not LibHotCorners.db.profile.is_enabled) then
tercio@0 432 return
tercio@0 433 end
tercio@0 434
tercio@0 435 if (not LibHotCorners.db.profile [self.position .. "_enabled"]) then
tercio@0 436 return
tercio@0 437 end
tercio@0 438
tercio@2 439 if (self:GetWidth() < 1.1 and self:GetHeight() < 1.1) then
tercio@2 440 --print ("abrindo...")
tercio@2 441 end
tercio@2 442
tercio@0 443 set_size (self)
tercio@0 444
tercio@0 445 HotCornersBackgroundFrame:EnableMouse (true)
tercio@2 446 self.item_frame:Show()
tercio@0 447
tercio@0 448 local i = 1
tercio@0 449
tercio@0 450 local sort = {}
tercio@0 451 local clicks = LibHotCorners.db.profile.clicks
tercio@0 452 for index, button_table in ipairs (LibHotCorners [self.position]) do
tercio@0 453 tinsert (sort, {clicks [button_table.name] or 0, button_table})
tercio@0 454 end
tercio@0 455 table.sort (sort, more_clicked)
tercio@0 456
tercio@0 457 local last_button
tercio@0 458
tercio@0 459 local disabled = LibHotCorners.db.profile.disabled
tercio@0 460
tercio@0 461 for index, button_table in ipairs (sort) do
tercio@0 462 button_table = button_table [2]
tercio@0 463 if (not button_table.widget) then
tercio@0 464 LibHotCorners:CreateAddonWidget (self, button_table, index, self.position)
tercio@0 465 end
tercio@0 466
tercio@0 467 button_table.widget:ClearAllPoints()
tercio@0 468
tercio@1 469 if (not disabled [button_table.name] and not button_table.optionstable.hide) then
tercio@0 470 if (self.position == "topleft" or self.position == "topright") then
tercio@2 471
tercio@0 472 local y = i * 35 * -1
tercio@2 473 --button_table.widget:SetPoint ("topleft", self, "topleft", 4, y)
tercio@0 474 button_table.widget.y = y
tercio@2 475 HotCornersStartAnimOnShow (button_table.widget, "y")
tercio@2 476
tercio@2 477 else --bottom left / bottom right
tercio@0 478 local x = i * 35
tercio@0 479 button_table.widget:SetPoint ("topleft", self, "topleft", x, -4)
tercio@0 480 button_table.widget.x = x
tercio@0 481 end
tercio@0 482
tercio@0 483 button_table.widget:Show()
tercio@0 484 last_button = button_table.widget
tercio@0 485
tercio@0 486 i = i + 1
tercio@0 487 else
tercio@0 488 button_table.widget:Hide()
tercio@0 489 end
tercio@0 490 end
tercio@0 491
tercio@0 492 local OptionsButton = LibHotCorners [self.position].optionsbutton
tercio@0 493 local y = i * 35 * -1
tercio@0 494 OptionsButton:SetPoint ("top", self, "top", 0, y)
tercio@0 495 OptionsButton:Show()
tercio@0 496
tercio@2 497 --item frame
tercio@2 498 LibHotCorners:RefereshItems (self)
tercio@2 499
tercio@3 500 self.AnimOnShow:Play()
tercio@3 501 HotCornersInfosFrame:Show()
tercio@3 502 HotCornersInfosFrame:SetAlpha (0)
tercio@3 503 HotCornersInfosFrame.AnimOnShow:Play()
tercio@3 504
tercio@3 505 --update repair
tercio@3 506 local percent, items = 0, 0
tercio@3 507 for i = INVSLOT_FIRST_EQUIPPED, INVSLOT_LAST_EQUIPPED do
tercio@3 508 local durability, maxdurability = GetInventoryItemDurability (i)
tercio@3 509 if (durability and maxdurability) then
tercio@3 510 local p = durability / maxdurability * 100
tercio@3 511 percent = percent + p
tercio@3 512 items = items + 1
tercio@3 513 end
tercio@3 514 end
tercio@3 515
tercio@3 516 if (items == 0) then
tercio@3 517 HotCornersInfosFrame.repairText:SetText ("-- %")
tercio@3 518 end
tercio@3 519
tercio@3 520 percent = percent / items
tercio@3 521 HotCornersInfosFrame.repairText:SetText (math.floor (percent) .. "%")
tercio@3 522
tercio@3 523 --update date
tercio@3 524 HotCornersInfosFrame.clockText:SetText (date ("%H:%M"))
tercio@3 525 HotCornersInfosFrame.dayText:SetText (date ("%A\n%B %d"))
tercio@3 526
tercio@3 527 --update money
tercio@3 528 local money = GetMoney()
tercio@3 529 HotCornersInfosFrame.goldText:SetText (math.floor (money / 100 / 100))
tercio@3 530 HotCornersInfosFrame.silverText:SetText (math.floor ((money / 100) % 100))
tercio@3 531 HotCornersInfosFrame.bronzeText:SetText (math.floor (money % 100))
tercio@3 532
tercio@3 533 --HotCornersInfosFrame.clockText:SetText (date ("%A %B %d %H:%M:%S %Y"))
tercio@3 534
tercio@0 535 end
tercio@0 536
tercio@2 537 function LibHotCorners:RefereshItems (self)
tercio@2 538
tercio@2 539 if (not self) then
tercio@2 540 return LibHotCorners:ScheduleTimer ("RefereshItems", 1, LibHotCornersTopLeft)
tercio@2 541 end
tercio@2 542
tercio@2 543 if (not UnitAffectingCombat ("player") and not InCombatLockdown()) then
tercio@2 544 for itemId, itemTable in pairs (LibHotCorners.ItemOnInventory) do
tercio@2 545 itemTable [1] = 0
tercio@2 546 end
tercio@2 547
tercio@2 548 for bagID = 0, 4 do
tercio@2 549 local numItems = GetContainerNumSlots (bagID)
tercio@2 550 for slot = 1, numItems do
tercio@2 551 local itemId = GetContainerItemID (bagID, slot)
tercio@2 552 if (LibHotCorners.BackPackItemList [itemId]) then
tercio@2 553 local texture, itemCount, locked, quality, readable, lootable, itemLink = GetContainerItemInfo (bagID, slot)
tercio@2 554 if (not LibHotCorners.ItemOnInventory [itemId]) then
tercio@2 555 LibHotCorners.ItemOnInventory [itemId] = {itemCount, texture, quality, itemLink, itemId}
tercio@2 556 else
tercio@2 557 LibHotCorners.ItemOnInventory [itemId] [1] = LibHotCorners.ItemOnInventory [itemId] [1] + itemCount
tercio@2 558 end
tercio@2 559 end
tercio@2 560 end
tercio@2 561 end
tercio@2 562
tercio@2 563 local index = 1
tercio@2 564 for itemId, itemTable in pairs (LibHotCorners.ItemOnInventory) do
tercio@2 565 local itemCount, texture, quality, itemLink = unpack (itemTable)
tercio@2 566
tercio@2 567 local item_button = LibHotCorners:GetItemButton (index, self)
tercio@2 568 if (item_button) then
tercio@2 569 item_button:SetNormalTexture (texture)
tercio@2 570 item_button:SetHighlightTexture (texture)
tercio@2 571 item_button:SetPushedTexture (texture)
tercio@2 572
tercio@2 573 item_button.item_count:SetText (itemCount or 0)
tercio@2 574 item_button:SetAttribute ("macrotext", "/use " .. GetItemInfo (itemId) .. ";\n/script HotCorners:RefereshItems()")
tercio@2 575
tercio@2 576 item_button.itemtable = itemTable
tercio@2 577
tercio@2 578 if (not item_button:IsShown() or item_button:GetAlpha() < 1) then
tercio@2 579 HotCornersStartAnimOnShow (item_button, "item_topleft")
tercio@2 580 end
tercio@2 581 end
tercio@2 582 index = index + 1
tercio@2 583 end
tercio@2 584
tercio@2 585 end
tercio@2 586
tercio@2 587 --/run local itemid=GetContainerItemID (0, 1);print (itemid)
tercio@2 588 --UseContainerItem(bagID, slot[, onSelf])
tercio@2 589 end
tercio@2 590
tercio@2 591 function LibHotCorners:GetItemButton (index, parent)
tercio@2 592 local button = LibHotCorners.ItemButtons [index]
tercio@2 593 if (not button) then
tercio@2 594 button = CreateFrame ("button", "HotCornersItemButton" .. index, parent.item_frame, "HotCornersUseItemButtonTemplate")
tercio@2 595 button.isItem = true
tercio@2 596
tercio@2 597 if (parent.position == "topleft") then
tercio@2 598 local x = (index-1) * 33
tercio@2 599 button:SetPoint ("topleft", parent.item_frame, "topleft", x, -2)
tercio@2 600 button.x = x
tercio@2 601 elseif (parent.position == "topright") then
tercio@2 602 local x = (index-1) * 33
tercio@2 603 button:SetPoint ("topright", parent.item_frame, "topright", -x, -2)
tercio@2 604 end
tercio@2 605
tercio@2 606 LibHotCorners.ItemButtons [index] = button
tercio@2 607 end
tercio@2 608 return button
tercio@2 609 end
tercio@2 610
tercio@0 611 --> corner frame on leave
tercio@2 612 function HotCornersOnLeave (self, from_background)
tercio@2 613 if (not from_background) then
tercio@2 614 return
tercio@2 615 end
tercio@2 616
tercio@0 617 self:SetSize (1, 1)
tercio@0 618 for index, button_table in ipairs (LibHotCorners [self.position]) do
tercio@1 619 if (button_table.widget) then
tercio@1 620 button_table.widget:Hide()
tercio@1 621 end
tercio@0 622 end
tercio@2 623 for _, button in pairs (LibHotCorners.ItemButtons) do
tercio@2 624 button:Hide()
tercio@2 625 end
tercio@2 626
tercio@0 627 local OptionsButton = LibHotCorners [self.position].optionsbutton
tercio@0 628 OptionsButton:Hide()
tercio@2 629
tercio@2 630 self.item_frame:Hide()
tercio@3 631 HotCornersInfosFrame:Hide()
tercio@0 632 end
tercio@0 633
tercio@0 634 --> quick corner on click
tercio@0 635 function HotCornersOnQuickClick (self, button)
tercio@0 636 local parent_position = self:GetParent().position
tercio@1 637 local func = LibHotCorners.QuickFunctions [parent_position]
tercio@1 638 if (func) then
tercio@1 639 func (self, button)
tercio@0 640 end
tercio@0 641 end
tercio@0 642
tercio@0 643 --> options button onenter
tercio@0 644 function HotCornersOptionsButtonOnEnter (self)
tercio@0 645 set_size (self:GetParent())
tercio@0 646 for index, button_table in ipairs (LibHotCorners [self:GetParent().position]) do
tercio@0 647 if (not LibHotCorners.db.profile.disabled [button_table.name]) then
tercio@0 648 button_table.widget:Show()
tercio@0 649 end
tercio@0 650 end
tercio@0 651 self:Show()
tercio@0 652 end
tercio@0 653
tercio@0 654 function HotCornersOpenOptions (self)
tercio@0 655 InterfaceOptionsFrame_OpenToCategory ("HotCorners")
tercio@0 656 InterfaceOptionsFrame_OpenToCategory ("HotCorners")
tercio@0 657 end
tercio@0 658
tercio@0 659 function HotCornersSetEnabled (state)
tercio@0 660 LibHotCorners.db.profile.is_enabled = state
tercio@0 661 end
tercio@0 662
tercio@0 663 --> options button onleave
tercio@0 664 function HotCornersOptionsButtonOnLeave (self)
tercio@0 665 self:GetParent():GetScript("OnLeave")(self:GetParent())
tercio@0 666 end
tercio@0 667
tercio@0 668 --> button onenter
tercio@0 669 function HotCornersButtonOnEnter (self)
tercio@2 670 --set_size (self:GetParent())
tercio@2 671 --for index, button_table in ipairs (LibHotCorners [self:GetParent().position]) do
tercio@2 672 -- if (not LibHotCorners.db.profile.disabled [button_table.name] and button_table.widget) then
tercio@2 673 -- button_table.widget:Show()
tercio@2 674 -- end
tercio@2 675 --end
tercio@0 676 show_tooltip (self)
tercio@2 677 --local OptionsButton = LibHotCorners [self:GetParent().position].optionsbutton
tercio@2 678 --OptionsButton:Show()
tercio@0 679 end
tercio@0 680
tercio@0 681 --> button onleave
tercio@0 682 function HotCornersButtonOnLeave (self)
tercio@0 683 GameTooltip:Hide()
tercio@2 684 if (self.table and self.table.onleave) then
tercio@0 685 self.table.onleave (self)
tercio@0 686 end
tercio@2 687 --self:GetParent():GetScript("OnLeave")(self:GetParent())
tercio@2 688 --local OptionsButton = LibHotCorners [self:GetParent().position].optionsbutton
tercio@2 689 --OptionsButton:Hide()
tercio@0 690 end
tercio@0 691
tercio@0 692 --> button onmousedown
tercio@0 693 function HotCornersButtonOnMouseDown (self, button)
tercio@2 694 if (self.isItem) then
tercio@2 695 if (self:GetParent():GetParent().position == "topleft") then
tercio@2 696 self:SetPoint ("topleft", self:GetParent(), "topleft", self.x+1, -3)
tercio@2 697 end
tercio@0 698 else
tercio@2 699 if (self:GetParent().position == "topleft" or self:GetParent().position == "topright") then
tercio@2 700 self:SetPoint ("topleft", self:GetParent(), "topleft", 5, self.y - 1)
tercio@2 701 else
tercio@2 702 self:SetPoint ("topleft", self:GetParent(), "topleft", self.x+1, -6)
tercio@2 703 end
tercio@0 704 end
tercio@0 705 end
tercio@0 706
tercio@0 707 --> button onmouseup
tercio@0 708 function HotCornersButtonOnMouseUp (self, button)
tercio@2 709 if (self.isItem) then
tercio@2 710 if (self:GetParent():GetParent().position == "topleft") then
tercio@2 711 self:SetPoint ("topleft", self:GetParent(), "topleft", self.x, -2)
tercio@2 712 end
tercio@0 713 else
tercio@2 714 if (self:GetParent().position == "topleft" or self:GetParent().position == "topright") then
tercio@2 715 self:SetPoint ("topleft", self:GetParent(), "topleft", 4, self.y)
tercio@2 716 else
tercio@2 717 self:SetPoint ("topleft", self:GetParent(), "topleft", self.x, -4)
tercio@2 718 end
tercio@2 719 if (self.table.click) then
tercio@2 720 local clicks = LibHotCorners.db.profile.clicks
tercio@2 721 clicks [self.table.name] = clicks [self.table.name] or 0
tercio@2 722 clicks [self.table.name] = clicks [self.table.name] + 1
tercio@2 723 self.table.click (self, button)
tercio@2 724 end
tercio@0 725 end
tercio@2 726 end
tercio@2 727
tercio@2 728 --> start show animation
tercio@2 729 function HotCornersStartAnimOnShow (button, axis)
tercio@2 730 if (axis == "y") then
tercio@2 731 --button:SetPoint ("topleft", button:GetParent(), "topleft", -32, button.y)
tercio@2 732 button:SetPoint ("topleft", button:GetParent(), "topleft", 4, button.y)
tercio@2 733 button.AnimOnShow:Play()
tercio@2 734
tercio@2 735 elseif (axis == "item_topleft") then
tercio@2 736 button:Show()
tercio@2 737 button.AnimOnShow:Play()
tercio@2 738
tercio@0 739 end
tercio@0 740 end
tercio@2 741
tercio@2 742 --> on start / finish show animation
tercio@2 743 function HotCornersAnimOnShowStarted (button)
tercio@2 744
tercio@2 745 end
tercio@2 746 function HotCornersAnimOnShowFinished (button)
tercio@2 747 --button:SetPoint ("topleft", button:GetParent(), "topleft", 4, button.y)
tercio@2 748 button:Show()
tercio@2 749 --button:SetPoint ("topleft", button:GetParent(), "topleft", -4, button.y)
tercio@2 750 end
tercio@0 751
tercio@0 752 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
tercio@0 753 --> create top left corner
tercio@0 754
tercio@0 755 local TopLeftCorner = CreateFrame ("Frame", "LibHotCornersTopLeft", nil, "HotCornersFrameCornerTemplate")
tercio@0 756 TopLeftCorner:SetPoint ("topleft", UIParent, "topleft", 0, 0)
tercio@0 757 TopLeftCorner.position = "topleft"
tercio@0 758
tercio@0 759 --fast corner button
tercio@0 760 local QuickClickButton = CreateFrame ("button", "LibHotCornersTopLeftFastButton", TopLeftCorner, "HotCornersQuickCornerButtonTemplate")
tercio@0 761
tercio@0 762 --options button
tercio@0 763 local OptionsButton = CreateFrame ("button", "LibHotCornersTopLeftOptionsButton", TopLeftCorner, "HotCornersOptionsButtonTemplate")
tercio@0 764
tercio@0 765 if (debug) then
tercio@0 766 QuickClickButton:SetSize (20, 20)
tercio@0 767 QuickClickButton:SetBackdrop ({bgFile = [[Interface\DialogFrame\UI-DialogBox-Gold-Background]], tile = true, tileSize = 40})
tercio@0 768 QuickClickButton:SetBackdropColor (1, 0, 0, 1)
tercio@0 769 end
tercio@0 770
tercio@0 771 LibHotCorners.topleft.quickbutton = QuickClickButton
tercio@0 772 LibHotCorners.topleft.optionsbutton = OptionsButton
tercio@0 773
tercio@0 774 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
tercio@0 775 --> buttons
tercio@0 776
tercio@0 777 function LibHotCorners:CreateAddonWidget (frame, button_table, index, side)
tercio@0 778
tercio@0 779 --> create the button
tercio@0 780 local button = CreateFrame ("button", "LibHotCorners" .. side .. button_table.fname, frame, "HotCornersButtonTemplate")
tercio@0 781
tercio@0 782 --> write some attributes
tercio@0 783 button.index = index
tercio@0 784 button.table = button_table
tercio@0 785 button.parent = frame
tercio@0 786 button_table.widget = button
tercio@0 787
tercio@0 788 --> set the icon
tercio@0 789 button:SetNormalTexture (button_table.icon)
tercio@0 790 button:SetHighlightTexture (button_table.icon)
tercio@0 791
tercio@0 792 if (string.lower (button_table.icon):find ([[\icons\]])) then
tercio@0 793 button:GetNormalTexture():SetTexCoord (0.078125, 0.9375, 0.078125, 0.9375)
tercio@0 794 button:GetHighlightTexture():SetTexCoord (0.078125, 0.9375, 0.078125, 0.9375)
tercio@0 795 end
tercio@0 796
tercio@0 797 return button
tercio@0 798 end