annotate PVPScan.lua @ 0:ce416064d8a1

first commit
author tercio
date Sat, 17 May 2014 02:17:10 -0300
parents
children 726745261b87
rev   line source
tercio@0 1
tercio@0 2 PVPScan = LibStub ("AceAddon-3.0"):NewAddon ("PVPScan", "AceConsole-3.0", "AceEvent-3.0")
tercio@0 3
tercio@0 4 local LDB = LibStub ("LibDataBroker-1.1", true)
tercio@0 5 local LDBIcon = LDB and LibStub ("LibDBIcon-1.0", true)
tercio@0 6 local SharedMedia = LibStub:GetLibrary("LibSharedMedia-3.0")
tercio@0 7
tercio@0 8 local _bit_band = bit.band
tercio@0 9
tercio@0 10 local REACTION_HOSTILE = 0x00000040
tercio@0 11 local OBJECT_TYPE_PLAYER = 0x00000400
tercio@0 12
tercio@0 13 PVPScan.SpotBars = {}
tercio@0 14 PVPScan.NeedClass = {}
tercio@0 15 PVPScan.NextSpotBar = 1
tercio@0 16 PVPScan.CurrentShownIndex = {}
tercio@0 17 PVPScan.CurrentShownHash = {}
tercio@0 18 PVPScan.CurrentShownTime = {}
tercio@0 19
tercio@0 20 local default_db = {
tercio@0 21 profile = {
tercio@0 22 SpotBarHeight = 20,
tercio@0 23 SpotBarAmount = 5,
tercio@0 24 SpotBarWidth = 150,
tercio@0 25 Locked = false,
tercio@0 26 SoundPlay = false,
tercio@0 27 SoundFile = "",
tercio@0 28 Minimap = {hide = false, radius = 160, minimapPos = 220},
tercio@0 29 },
tercio@0 30 }
tercio@0 31
tercio@0 32 function PVPScan:OnEnable()
tercio@0 33 end
tercio@0 34
tercio@0 35 function PVPScan:OnDisable()
tercio@0 36 end
tercio@0 37
tercio@0 38 local OptionsTable = {
tercio@0 39 name = "PVPScan",
tercio@0 40 type = "group",
tercio@0 41 args = {
tercio@0 42 SpotBarHeight = {
tercio@0 43 type = "range",
tercio@0 44 name = "Bar Height",
tercio@0 45 desc = "Change the height of spot bars.",
tercio@0 46 min = 10,
tercio@0 47 max = 40,
tercio@0 48 step = 1,
tercio@0 49 get = function() return PVPScan.db.profile.SpotBarHeight end,
tercio@0 50 set = function (self, val) PVPScan.db.profile.SpotBarHeight = val; PVPScan:RefreshSpotBars() end,
tercio@0 51 order = 1,
tercio@0 52 },
tercio@0 53 SpotBarWidth = {
tercio@0 54 type = "range",
tercio@0 55 name = "Bar Width",
tercio@0 56 desc = "Change the width of spot bars.",
tercio@0 57 min = 50,
tercio@0 58 max = 250,
tercio@0 59 step = 1,
tercio@0 60 get = function() return PVPScan.db.profile.SpotBarWidth end,
tercio@0 61 set = function (self, val) PVPScan.db.profile.SpotBarWidth = val; PVPScan:RefreshSpotBars() end,
tercio@0 62 order = 2,
tercio@0 63 },
tercio@0 64 SpotBarAmount = {
tercio@0 65 type = "range",
tercio@0 66 name = "Bar Amount",
tercio@0 67 desc = "Change the amount of spot bars.",
tercio@0 68 min = 1,
tercio@0 69 max = 40,
tercio@0 70 step = 1,
tercio@0 71 get = function() return PVPScan.db.profile.SpotBarAmount end,
tercio@0 72 set = function (self, val) PVPScan.db.profile.SpotBarAmount = val; PVPScan:RefreshSpotBars() end,
tercio@0 73 order = 3,
tercio@0 74 },
tercio@0 75 Locked = {
tercio@0 76 type = "toggle",
tercio@0 77 name = "Lock Frame",
tercio@0 78 desc = "Lock or unlock the SpotBars Frame.",
tercio@0 79 order = 4,
tercio@0 80 get = function() return PVPScan.db.profile.Locked end,
tercio@0 81 set = function (self, val) PVPScan.db.profile.Locked = not PVPScan.db.profile.Locked end,
tercio@0 82 },
tercio@0 83 SoundPlay = {
tercio@0 84 type = "toggle",
tercio@0 85 name = "Play Sound",
tercio@0 86 desc = "Play a sound when a enemy is found.",
tercio@0 87 order = 5,
tercio@0 88 get = function() return PVPScan.db.profile.SoundPlay end,
tercio@0 89 set = function (self, val) PVPScan.db.profile.SoundPlay = not PVPScan.db.profile.SoundPlay end,
tercio@0 90 },
tercio@0 91 SoundFile = {
tercio@0 92 type = "select",
tercio@0 93 name = "Sound File",
tercio@0 94 desc = "Choose the sound to play when a enemy is found.",
tercio@0 95 values = function()
tercio@0 96 local SoundTable = {}
tercio@0 97 for name, _ in pairs (SharedMedia:HashTable ("sound")) do
tercio@0 98 SoundTable [name] = name
tercio@0 99 end
tercio@0 100 return SoundTable
tercio@0 101 end,
tercio@0 102 get = function() return PVPScan.db.profile.SoundFile end,
tercio@0 103 set = function (self, file) PVPScan.db.profile.SoundFile = file end,
tercio@0 104 order = 6,
tercio@0 105 },
tercio@0 106 Minimap = {
tercio@0 107 type = "toggle",
tercio@0 108 name = "Hide Minimap Icon",
tercio@0 109 desc = "Show or hide the minimap icon.",
tercio@0 110 order = 7,
tercio@0 111 get = function() return PVPScan.db.profile.Minimap.hide end,
tercio@0 112 set = function (self, val)
tercio@0 113 PVPScan.db.profile.Minimap.hide = not PVPScan.db.profile.Minimap.hide
tercio@0 114 LDBIcon:Refresh ("PVPScan", PVPScan.db.profile.Minimap)
tercio@0 115 if (PVPScan.db.profile.Minimap.hide) then
tercio@0 116 LDBIcon:Hide ("PVPScan")
tercio@0 117 else
tercio@0 118 LDBIcon:Show ("PVPScan")
tercio@0 119 end
tercio@0 120 end,
tercio@0 121 },
tercio@0 122 },
tercio@0 123 }
tercio@0 124
tercio@0 125 function PVPScan:OnInitialize()
tercio@0 126
tercio@0 127 --declarar primeiro o db usando a global que é declarada no toc.
tercio@0 128 self.db = LibStub ("AceDB-3.0"):New ("PVPScanDB", default_db, true)
tercio@0 129
tercio@0 130 --declara agora as opções da tab raiz
tercio@0 131 LibStub("AceConfig-3.0"):RegisterOptionsTable ("PVPScan", OptionsTable)
tercio@0 132 PVPScan.OptionsFrame1 = LibStub ("AceConfigDialog-3.0"):AddToBlizOptions ("PVPScan", "PVPScan")
tercio@0 133 --sub tab
tercio@0 134 LibStub ("AceConfig-3.0"):RegisterOptionsTable ("PVPScan-Profiles", LibStub ("AceDBOptions-3.0"):GetOptionsTable (self.db))
tercio@0 135 PVPScan.OptionsFrame2 = LibStub ("AceConfigDialog-3.0"):AddToBlizOptions ("PVPScan-Profiles", "Profiles", "PVPScan")
tercio@0 136
tercio@0 137 if LDB then
tercio@0 138 local databroker = LDB:NewDataObject ("PVPScan", {
tercio@0 139 type = "launcher",
tercio@0 140 icon = [[Interface\PvPRankBadges\PvPRank15]],
tercio@0 141 --HotCornerIgnore = true,
tercio@0 142 OnClick = function (self, button)
tercio@0 143 InterfaceOptionsFrame_OpenToCategory ("PVPScan")
tercio@0 144 InterfaceOptionsFrame_OpenToCategory ("PVPScan")
tercio@0 145 end
tercio@0 146 })
tercio@0 147
tercio@0 148 if (databroker and not LDBIcon:IsRegistered ("PVPScan")) then
tercio@0 149 LDBIcon:Register ("PVPScan", databroker, PVPScan.db.profile.Minimap)
tercio@0 150 end
tercio@0 151 end
tercio@0 152
tercio@0 153 PVPScan:RefreshSpotBars()
tercio@0 154
tercio@0 155 end
tercio@0 156
tercio@0 157 PVPScan:RegisterChatCommand ("pvpscan", function()
tercio@0 158 InterfaceOptionsFrame_OpenToCategory ("PVPScan")
tercio@0 159 InterfaceOptionsFrame_OpenToCategory ("PVPScan")
tercio@0 160 end)
tercio@0 161
tercio@0 162 ------------------------------------------------------------------------------------------------------------------------------------------------------------
tercio@0 163 --> parser stuff
tercio@0 164
tercio@0 165 local event_frame = CreateFrame ("frame", "PVPScanCombatLobReader", UIParent)
tercio@0 166 event_frame:RegisterEvent ("COMBAT_LOG_EVENT_UNFILTERED")
tercio@0 167
tercio@0 168 function PVPScan:OnParserEvent (event, time, token, hidding, who_serial, who_name, who_flags, who_flags2, target_serial, target_name, target_flags, target_flags2, ...)
tercio@0 169
tercio@0 170 if (PVPScan.NeedClass [who_name]) then
tercio@0 171 local class = PVPScan:GuessClass (...)
tercio@0 172 if (class) then
tercio@0 173 PVPScan:UpdateBar (PVPScan.NeedClass [who_name], class, who_name)
tercio@0 174 PVPScan.NeedClass [who_name] = nil
tercio@0 175 end
tercio@0 176 return
tercio@0 177 end
tercio@0 178
tercio@0 179 if (PVPScan.NeedClass [target_name]) then
tercio@0 180 local class = PVPScan:GuessClass (...)
tercio@0 181 if (class) then
tercio@0 182 PVPScan:UpdateBar (PVPScan.NeedClass [target_name], class, target_name)
tercio@0 183 PVPScan.NeedClass [target_name] = nil
tercio@0 184 end
tercio@0 185 return
tercio@0 186 end
tercio@0 187
tercio@0 188 if (not PVPScan.CurrentShownHash [target_name] and _bit_band (target_flags, OBJECT_TYPE_PLAYER) ~= 0) then --> is player
tercio@0 189 if (_bit_band (target_flags, REACTION_HOSTILE ) ~= 0) then --> is hostile
tercio@0 190 local class = PVPScan:GuessClass (...)
tercio@0 191 PVPScan:EnemySpoted (target_name, target_serial, target_flags, class)
tercio@0 192 end
tercio@0 193 end
tercio@0 194
tercio@0 195 if (not PVPScan.CurrentShownHash [who_name] and _bit_band (who_flags, OBJECT_TYPE_PLAYER) ~= 0) then --> is player
tercio@0 196 if (_bit_band (who_flags, REACTION_HOSTILE ) ~= 0) then --> is hostile
tercio@0 197 local class = PVPScan:GuessClass (...)
tercio@0 198 PVPScan:EnemySpoted (who_name, who_serial, who_flags, class)
tercio@0 199 end
tercio@0 200 end
tercio@0 201 end
tercio@0 202
tercio@0 203 event_frame:SetScript ("OnEvent", PVPScan.OnParserEvent)
tercio@0 204
tercio@0 205 function PVPScan:LeftCombatLockdown()
tercio@0 206 if (PVPScan.schedule_frame_update) then
tercio@0 207 PVPScan.schedule_frame_update = false
tercio@0 208 PVPScan:RefreshSpotBars()
tercio@0 209 end
tercio@0 210 end
tercio@0 211 function PVPScan:GotCombatLockdown()
tercio@0 212 end
tercio@0 213
tercio@0 214 PVPScan:RegisterEvent ("PLAYER_REGEN_DISABLED", "GotCombatLockdown")
tercio@0 215 PVPScan:RegisterEvent ("PLAYER_REGEN_ENABLED", "LeftCombatLockdown")
tercio@0 216
tercio@0 217 function PVPScan:EnemySpoted (name, serial, flags, class)
tercio@0 218
tercio@0 219 --> check for overwrite
tercio@0 220 local current_player_shown = PVPScan.CurrentShownIndex [PVPScan.NextSpotBar]
tercio@0 221 if (current_player_shown) then
tercio@0 222 PVPScan.NeedClass [current_player_shown] = nil
tercio@0 223 end
tercio@0 224
tercio@0 225 local SpotBar = PVPScan.SpotBars [PVPScan.NextSpotBar]
tercio@0 226
tercio@0 227 if (class) then
tercio@0 228 PVPScan:UpdateBar (PVPScan.NextSpotBar, class, name)
tercio@0 229 else
tercio@0 230 PVPScan:UpdateBar (PVPScan.NextSpotBar, nil, name)
tercio@0 231 PVPScan.NeedClass [name] = PVPScan.NextSpotBar
tercio@0 232 end
tercio@0 233
tercio@0 234 PVPScan.CurrentShownIndex [PVPScan.NextSpotBar] = name
tercio@0 235 PVPScan.CurrentShownHash [name] = PVPScan.NextSpotBar
tercio@0 236 PVPScan.CurrentShownTime [name] = GetTime()
tercio@0 237
tercio@0 238 if (not UnitAffectingCombat ("player") and not InCombatLockdown()) then
tercio@0 239 SpotBar:SetAttribute("macrotext", "/cleartarget\n/targetexact " .. name)
tercio@0 240 end
tercio@0 241
tercio@0 242 SpotBar:Show()
tercio@0 243
tercio@0 244 PVPScan.NextSpotBar = PVPScan.NextSpotBar + 1
tercio@0 245 if (PVPScan.NextSpotBar > PVPScan.db.profile.SpotBarAmount) then
tercio@0 246 PVPScan.NextSpotBar = 1
tercio@0 247 end
tercio@0 248
tercio@0 249 end
tercio@0 250
tercio@0 251
tercio@0 252
tercio@0 253 ------------------------------------------------------------------------------------------------------------------------------------------------------------
tercio@0 254 --> frames
tercio@0 255
tercio@0 256 function PVPScanOnFrameMouseDown (self)
tercio@0 257 if (not self.IsMoving) then
tercio@0 258 self:StartMoving()
tercio@0 259 self.IsMoving = true
tercio@0 260 end
tercio@0 261 end
tercio@0 262
tercio@0 263 function PVPScanOnFrameMouseUp (self)
tercio@0 264 if (self.IsMoving) then
tercio@0 265 self:StopMovingOrSizing()
tercio@0 266 self.IsMoving = false
tercio@0 267 end
tercio@0 268 end
tercio@0 269
tercio@0 270 function PVPScan:UpdateBar (index, class, name)
tercio@0 271
tercio@0 272 local SpotBar = PVPScan.SpotBars [index]
tercio@0 273
tercio@0 274 if (class) then
tercio@0 275 local color = RAID_CLASS_COLORS [class]
tercio@0 276 SpotBar.classtexture:SetVertexColor (color.r, color.g, color.b)
tercio@0 277
tercio@0 278 local texcoord = CLASS_ICON_TCOORDS [class]
tercio@0 279 SpotBar.classicon:SetTexture ([[Interface\Glues\CHARACTERCREATE\UI-CHARACTERCREATE-CLASSES]])
tercio@0 280 SpotBar.classicon:SetTexCoord (unpack (texcoord))
tercio@0 281 else
tercio@0 282 SpotBar.classtexture:SetVertexColor (.7, .7, .7)
tercio@0 283 SpotBar.classicon:SetTexture ([[Interface\InventoryItems\WoWUnknownItem01]])
tercio@0 284 SpotBar.classicon:SetTexCoord (0, 1, 0, 1)
tercio@0 285 end
tercio@0 286
tercio@0 287 SpotBar.name:SetText (name)
tercio@0 288
tercio@0 289 end
tercio@0 290
tercio@0 291 function PVPScan:RefreshSpotBars()
tercio@0 292
tercio@0 293 if (UnitAffectingCombat ("player") or InCombatLockdown()) then
tercio@0 294 PVPScan.schedule_frame_update = true
tercio@0 295 PVPScan:Print ("When the combat finishes, the frame will be updated.")
tercio@0 296 return
tercio@0 297 end
tercio@0 298
tercio@0 299 local amount_bars = PVPScan.db.profile.SpotBarAmount
tercio@0 300 PVPScanFrame:SetSize (PVPScan.db.profile.SpotBarWidth, PVPScan.db.profile.SpotBarHeight)
tercio@0 301
tercio@0 302 --> we need extra bars?
tercio@0 303 if (amount_bars > #PVPScan.SpotBars) then
tercio@0 304 for i = #PVPScan.SpotBars+1, amount_bars do
tercio@0 305
tercio@0 306 local new_bar = CreateFrame ("Button", "PVPScanSpotBar" .. i, PVPScanFrame, "PVPScanSpotBarTemplate")
tercio@0 307
tercio@0 308 local y = (i-1) * PVPScan.db.profile.SpotBarHeight * -1
tercio@0 309
tercio@0 310 new_bar:SetPoint ("topleft", PVPScanFrame, "topleft", 0, y)
tercio@0 311 new_bar:SetSize (PVPScan.db.profile.SpotBarWidth, PVPScan.db.profile.SpotBarHeight)
tercio@0 312
tercio@0 313 tinsert (PVPScan.SpotBars, new_bar)
tercio@0 314 end
tercio@0 315 end
tercio@0 316
tercio@0 317 if (#PVPScan.SpotBars > amount_bars) then
tercio@0 318 for i = #PVPScan.SpotBars, amount_bars+1, -1 do
tercio@0 319 PVPScan.SpotBars [i]:Hide()
tercio@0 320 local name = PVPScan.CurrentShownIndex [i]
tercio@0 321 if (name) then
tercio@0 322 tremove (PVPScan.CurrentShownIndex, i)
tercio@0 323 PVPScan.CurrentShownHash [name] = nil
tercio@0 324 PVPScan.CurrentShownTime [name] = nil
tercio@0 325 PVPScan.NeedClass [name] = nil
tercio@0 326 end
tercio@0 327 end
tercio@0 328 end
tercio@0 329
tercio@0 330 --> refresh existing
tercio@0 331 for index, bar in ipairs (PVPScan.SpotBars) do
tercio@0 332 local y = (index-1) * PVPScan.db.profile.SpotBarHeight * -1
tercio@0 333 bar:SetPoint ("topleft", PVPScanFrame, "topleft", 0, y)
tercio@0 334 bar:SetSize (PVPScan.db.profile.SpotBarWidth, PVPScan.db.profile.SpotBarHeight)
tercio@0 335 end
tercio@0 336
tercio@0 337 end
tercio@0 338
tercio@0 339
tercio@0 340
tercio@0 341
tercio@0 342
tercio@0 343 ------------------------------------------------------------------------------------------------------------------------------------------------------------
tercio@0 344 --> misc
tercio@0 345
tercio@0 346 function PVPScan:GuessClass (...)
tercio@0 347 local arg1, arg2, arg3, arg4 = select (1, ...)
tercio@0 348
tercio@0 349 if (type (arg1) == "number") then
tercio@0 350 if (PVPScan.ClassSpellList [arg1]) then
tercio@0 351 return PVPScan.ClassSpellList [arg1]
tercio@0 352 end
tercio@0 353 end
tercio@0 354
tercio@0 355 if (type (arg3) == "number") then
tercio@0 356 if (PVPScan.ClassSpellList [arg3]) then
tercio@0 357 return PVPScan.ClassSpellList [arg3]
tercio@0 358 end
tercio@0 359 end
tercio@0 360
tercio@0 361 if (type (arg2) == "number") then
tercio@0 362 if (PVPScan.ClassSpellList [arg3]) then
tercio@0 363 return PVPScan.ClassSpellList [arg3]
tercio@0 364 end
tercio@0 365 end
tercio@0 366
tercio@0 367 if (type (arg4) == "number") then
tercio@0 368 if (PVPScan.ClassSpellList [arg4]) then
tercio@0 369 return PVPScan.ClassSpellList [arg4]
tercio@0 370 end
tercio@0 371 end
tercio@0 372
tercio@0 373 return nil
tercio@0 374 end
tercio@0 375