Mercurial > wow > hansgar_and_franzok_assist
comparison Hansgar_And_Franzok_Assist.lua @ 0:f18f59592449
- Major bug fixes.
| author | Tercio |
|---|---|
| date | Mon, 23 Feb 2015 13:27:32 -0300 |
| parents | |
| children | 5d4efee0e528 |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:f18f59592449 |
|---|---|
| 1 local floor = floor | |
| 2 local min = min | |
| 3 local UnitExists = UnitExists | |
| 4 local GetPlayerMapPosition = GetPlayerMapPosition | |
| 5 local UnitHealth = UnitHealth | |
| 6 | |
| 7 local f = CreateFrame ("frame", "Hansgar_And_Franzok_Assist", UIParent) | |
| 8 f:SetFrameStrata ("DIALOG") | |
| 9 | |
| 10 f:SetSize (155, 156) | |
| 11 f:SetBackdrop ({bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", tile = true, tileSize = 16, insets = {left = -1, right = -1, top = -1, bottom = -1}, | |
| 12 edgeFile = "Interface\\AddOns\\Hansgar_And_Franzok_Assist\\border_2", edgeSize = 8}) | |
| 13 f:SetPoint ("center", UIParent, "center") | |
| 14 f:SetBackdropColor (0, 0, 0, 0) | |
| 15 f:SetBackdropBorderColor (0, 0, 0, 1) | |
| 16 f:SetMovable (true) | |
| 17 f:EnableMouse (true) | |
| 18 f:Hide() | |
| 19 | |
| 20 local title = f:CreateFontString (nil, "overlay", "GameFontNormal") | |
| 21 title:SetText ("Hansgar & Franzok Assist") | |
| 22 title:SetPoint ("center", f, "center") | |
| 23 title:SetPoint ("bottom", f, "top", 0, 2) | |
| 24 | |
| 25 -- | |
| 26 local frame_event = CreateFrame ("frame", "Hansgar_And_Franzok_AssistEvents", f) | |
| 27 frame_event:RegisterEvent ("ENCOUNTER_START") | |
| 28 frame_event:RegisterEvent ("ENCOUNTER_END") | |
| 29 frame_event:RegisterEvent ("ADDON_LOADED") | |
| 30 | |
| 31 -- | |
| 32 local player_bar = CreateFrame ("statusbar", "Hansgar_And_Franzok_AssistPlayerBar", f) | |
| 33 player_bar:SetPoint ("topleft", f, "bottomleft", 0, -3) | |
| 34 player_bar:SetPoint ("topright", f, "bottomright", 0, -3) | |
| 35 player_bar:SetHeight (14) | |
| 36 player_bar:SetStatusBarColor (0, 0, 0, 0) | |
| 37 player_bar:SetMinMaxValues (0, 100) | |
| 38 player_bar:SetValue (0) | |
| 39 f.player_bar = player_bar | |
| 40 | |
| 41 player_bar.texture = player_bar:CreateTexture (nil, "overlay") | |
| 42 player_bar.texture:SetTexture ("Interface\\AddOns\\Hansgar_And_Franzok_Assist\\bar_skyline") | |
| 43 player_bar:SetStatusBarTexture (player_bar.texture) | |
| 44 | |
| 45 -- | |
| 46 | |
| 47 local db | |
| 48 | |
| 49 frame_event:SetFrameStrata ("FULLSCREEN") | |
| 50 | |
| 51 frame_event:SetScript ("OnEvent", function (self, event, ...) | |
| 52 | |
| 53 if (event == "ADDON_LOADED" and select (1, ...) == "Hansgar_And_Franzok_Assist") then | |
| 54 | |
| 55 db = Hansgar_And_Franzok_DB | |
| 56 if (not db) then | |
| 57 db = {} | |
| 58 Hansgar_And_Franzok_DB = db | |
| 59 end | |
| 60 db.STAMPERS_DELAY = db.STAMPERS_DELAY or 5 | |
| 61 | |
| 62 SLASH_Hansgar_And_Franzok_Assist1, SLASH_Hansgar_And_Franzok_Assist2 = "/hansgar", "/franzok" | |
| 63 function SlashCmdList.Hansgar_And_Franzok_Assist (msg, editbox) | |
| 64 | |
| 65 local command, rest = msg:match ("^(%S*)%s*(.-)$") | |
| 66 | |
| 67 if (command == "delay") then | |
| 68 local t = tonumber (rest) | |
| 69 if (t) then | |
| 70 db.STAMPERS_DELAY = t | |
| 71 print ("|cFFFFAA00Hansgar and Franzok Assist|r delay set to: ", t) | |
| 72 else | |
| 73 print ("|cFFFFAA00Hansgar and Franzok Assist|r invalid time.", t) | |
| 74 end | |
| 75 | |
| 76 elseif (command == "test" or command == "show") then | |
| 77 if (f.StampersPhase) then | |
| 78 return f:StopTracking() | |
| 79 end | |
| 80 f:StartTracking() | |
| 81 | |
| 82 elseif (command == "hide") then | |
| 83 if (f.StampersPhase) then | |
| 84 return f:StopTracking() | |
| 85 end | |
| 86 | |
| 87 else | |
| 88 print ("|cFFFFAA00Hansgar and Franzok Assist|r Commands:") | |
| 89 print ("|cFFFFFF00/hansgar delay <time>|r: time in seconds until the percentage goes from 0 to 100.") | |
| 90 print ("|cFFFFFF00/hansgar test|r: active the addon on test mode.") | |
| 91 print ("|cFFFFFF00/hansgar show|r: show the window and start test mode.") | |
| 92 print ("|cFFFFFF00/hansgar hide|r: hide the window.") | |
| 93 end | |
| 94 end | |
| 95 | |
| 96 elseif (event == "ENCOUNTER_START" or event == "ENCOUNTER_END") then | |
| 97 | |
| 98 local encounterID, encounterName, difficultyID, raidSize = select (1, ...) | |
| 99 if (encounterID == 1693 and difficultyID == 16) then | |
| 100 | |
| 101 if (event == "ENCOUNTER_START") then | |
| 102 | |
| 103 print ("|cFFFFAA00Hansgar and Franzok Assist|r: addon enabled, good look!") | |
| 104 | |
| 105 if (f.StampersPhase) then | |
| 106 f:StopTracking() | |
| 107 end | |
| 108 f:RegisterEvent ("COMBAT_LOG_EVENT_UNFILTERED") | |
| 109 | |
| 110 elseif (event == "ENCOUNTER_END") then | |
| 111 f:UnregisterEvent ("COMBAT_LOG_EVENT_UNFILTERED") | |
| 112 | |
| 113 if (f.StampersPhase) then | |
| 114 f:StopTracking() | |
| 115 end | |
| 116 end | |
| 117 end | |
| 118 end | |
| 119 | |
| 120 end) | |
| 121 | |
| 122 -- | |
| 123 | |
| 124 f:SetScript ("OnEvent", function (self, event, time, token, _, who_serial, who_name, who_flags, _, target_serial, target_name, target_flags, _, spellid, spellname, spellschool, buff_type, ...) | |
| 125 | |
| 126 if (event == "SPELL_AURA_APPLIED" and spellid == 162124 and not f.StampersPhase) then | |
| 127 f:StartTracking() | |
| 128 | |
| 129 elseif (event == "SPELL_AURA_REMOVED" and spellid == 162124 and f.StampersPhase) then | |
| 130 f:StopTracking() | |
| 131 | |
| 132 end | |
| 133 | |
| 134 end) | |
| 135 | |
| 136 local frame_tracker = CreateFrame ("frame", "Hansgar_And_Franzok_AssistTracker", UIParent) | |
| 137 local on_update_tracker = function (self, elapsed) | |
| 138 | |
| 139 for i = 1, GetNumGroupMembers() do | |
| 140 local x, y = GetPlayerMapPosition ("raid"..i) | |
| 141 if (UnitExists ("raid"..i) and UnitHealth ("raid"..i) > 1 and x and y) then | |
| 142 local block = f:WhichBlock (x, y) | |
| 143 if (block) then | |
| 144 if (not f.block_tracker [block]) then --> was a clear block | |
| 145 f.block_tracker [block] = GetTime() | |
| 146 f:Paint (f.all_blocks [block]) | |
| 147 end | |
| 148 end | |
| 149 end | |
| 150 end | |
| 151 | |
| 152 local px, py = GetPlayerMapPosition ("player") | |
| 153 local player_block = f:WhichBlock (px, py) | |
| 154 if (player_block) then | |
| 155 | |
| 156 local time_limit_at = f.block_tracker [player_block] + db.STAMPERS_DELAY | |
| 157 local time_now = GetTime() | |
| 158 | |
| 159 f.player_bar:SetValue ((time_limit_at - time_now) / db.STAMPERS_DELAY * 100) | |
| 160 f.player_bar:Show() | |
| 161 | |
| 162 local block_frame = f.all_blocks [player_block] | |
| 163 f.player_loc_box:SetPoint ("center", block_frame, "center") | |
| 164 f.player_loc_box:Show() | |
| 165 player_bar:Show() | |
| 166 else | |
| 167 f.player_loc_box:Hide() | |
| 168 f.player_bar:Hide() | |
| 169 end | |
| 170 end | |
| 171 | |
| 172 function f:StartTracking() | |
| 173 | |
| 174 print ("|cFFFFAA00Hansgar and Franzok Assist|r: Smart Stampers phase started.") | |
| 175 | |
| 176 f.StampersPhase = true | |
| 177 | |
| 178 if (not f.frames_built) then | |
| 179 f:CreateWindow() | |
| 180 end | |
| 181 | |
| 182 f:ResetBlocks() | |
| 183 f.player_loc_box:Hide() | |
| 184 | |
| 185 f.block_tracker = f.block_tracker or {} | |
| 186 table.wipe (f.block_tracker) | |
| 187 | |
| 188 SetMapToCurrentZone() | |
| 189 | |
| 190 frame_tracker:SetScript ("OnUpdate", on_update_tracker) | |
| 191 f:Show() | |
| 192 end | |
| 193 | |
| 194 function f:StopTracking() | |
| 195 | |
| 196 print ("|cFFFFAA00Hansgar and Franzok Assist|r: Smart Stampers phase ended.") | |
| 197 | |
| 198 f.StampersPhase = false | |
| 199 frame_tracker:SetScript ("OnUpdate", nil) | |
| 200 table.wipe (f.block_tracker) | |
| 201 f.player_loc_box:Hide() | |
| 202 f:Hide() | |
| 203 end | |
| 204 | |
| 205 local on_mouse_down = function (self) | |
| 206 if (not self.isMoving) then | |
| 207 self.isMoving = true | |
| 208 f:StartMoving() | |
| 209 end | |
| 210 end | |
| 211 local on_mouse_up = function (self) | |
| 212 if (self.isMoving) then | |
| 213 self.isMoving = nil | |
| 214 f:StopMovingOrSizing() | |
| 215 end | |
| 216 end | |
| 217 | |
| 218 local painting = function (self, elapsed) | |
| 219 self.step = self.step + elapsed | |
| 220 self.total_time = self.total_time + elapsed | |
| 221 | |
| 222 if (self.step > 0.2) then | |
| 223 self.step = 0 | |
| 224 local percent = self.total_time / db.STAMPERS_DELAY * 100 | |
| 225 | |
| 226 percent = min (percent, 100) | |
| 227 | |
| 228 local r, g, b = f:percent_color (percent, true) | |
| 229 self:SetBackdropColor (r, g, b, 0.5) | |
| 230 | |
| 231 self.number:SetText (floor (percent) .. "%") | |
| 232 self.number:SetTextColor (1, 1, 1, 1) | |
| 233 | |
| 234 if (percent == 100) then | |
| 235 self:SetScript ("OnUpdate", nil) | |
| 236 self.stamper_icon:Show() | |
| 237 self.number:Hide() | |
| 238 end | |
| 239 end | |
| 240 end | |
| 241 function f:Paint (block) | |
| 242 block.step = 0 | |
| 243 block.total_time = 0 | |
| 244 block:SetScript ("OnUpdate", painting) | |
| 245 end | |
| 246 | |
| 247 function f:ResetBlocks() | |
| 248 for _, block in ipairs (f.all_blocks) do | |
| 249 block:SetScript ("OnUpdate", nil) | |
| 250 block:SetBackdropColor (.8, .8, .8, 0.5) | |
| 251 block.number:SetText (block.id) | |
| 252 block.number:SetTextColor (1, 1, 1, 0.5) | |
| 253 block.number:Show() | |
| 254 block.stamper_icon:Hide() | |
| 255 end | |
| 256 end | |
| 257 | |
| 258 function f:CreateWindow() | |
| 259 local x = 0 | |
| 260 local y = 0 | |
| 261 | |
| 262 f.player_loc_box = frame_event:CreateTexture (nil, "overlay") | |
| 263 f.player_loc_box:SetSize (32, 40) | |
| 264 f.player_loc_box:SetTexture ([[Interface\ContainerFrame\UI-Icon-QuestBorder]]) | |
| 265 f.player_loc_box:Hide() | |
| 266 | |
| 267 f.all_blocks = {} | |
| 268 | |
| 269 for i = 1, 20 do | |
| 270 | |
| 271 local block = CreateFrame ("frame", "Hansgar_And_Franzok_Assist_Block" .. i, f) | |
| 272 block:SetSize (30, 38) | |
| 273 block:SetBackdrop ({bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", tile = true, tileSize = 16, insets = {left = 0, right = 0, top = 0, bottom = 0}, | |
| 274 }) | |
| 275 block:SetBackdropBorderColor (0, 0, 0, 1) | |
| 276 block:SetBackdropColor (.8, .8, .8, 0.5) | |
| 277 block:SetPoint ("TopLeft", f, "TopLeft", x, y) | |
| 278 | |
| 279 block:SetScript ("OnMouseDown", on_mouse_down) | |
| 280 block:SetScript ("OnMouseUp", on_mouse_up) | |
| 281 | |
| 282 block.id = i | |
| 283 | |
| 284 local number = block:CreateFontString (nil, "artwork", "GameFontHighlight") | |
| 285 number:SetPoint ("center", block, "center") | |
| 286 number:SetText (i) | |
| 287 number:SetTextColor (1, 1, 1, 0.5) | |
| 288 block.number = number | |
| 289 | |
| 290 local stamper_icon = block:CreateTexture (nil, "overlay") | |
| 291 stamper_icon:SetTexture ([[Interface\ICONS\Warrior_talent_icon_LambsToTheSlaughter]]) | |
| 292 stamper_icon:SetTexCoord (4/64, 60/64, 4/64, 60/64) | |
| 293 stamper_icon:SetSize (24, 24) | |
| 294 stamper_icon:SetPoint ("center", block, "center") | |
| 295 stamper_icon:Hide() | |
| 296 block.stamper_icon = stamper_icon | |
| 297 | |
| 298 x = x + 31 | |
| 299 if (x >= 155) then | |
| 300 x = 0 | |
| 301 y = y - 40 | |
| 302 end | |
| 303 | |
| 304 tinsert (f.all_blocks, block) | |
| 305 | |
| 306 end | |
| 307 | |
| 308 f.frames_built = true | |
| 309 | |
| 310 end | |
| 311 | |
| 312 local locs = { | |
| 313 --block 1: | |
| 314 {x1 = 0.51104891300201, y1 = 0.70877063274384, x2 = 0.50024521350861, y2 = 0.73220580816269}, | |
| 315 --block 2: | |
| 316 {x1 = 0.49676024913788, y1 = 0.70914703607559, x2 = 0.48485481739044, y2 = 0.73210543394089}, | |
| 317 --block 3: | |
| 318 {x1 = 0.48142266273499, y1 = 0.70876735448837, x2 = 0.46925610303879, y2 = 0.73205661773682}, | |
| 319 --block 4: | |
| 320 {x1 = 0.46603119373322, y1 = 0.70929777622223, x2 = 0.45397216081619, y2 = 0.73167610168457}, | |
| 321 --block 5: | |
| 322 {x1 = 0.45079308748245, y1 = 0.70926278829575, x2 = 0.43927478790283, y2 = 0.73225915431976}, | |
| 323 | |
| 324 --block 6 | |
| 325 {x1 = 0.51104187965393, y1 = 0.73422884941101, x2 = 0.49990028142929, y2 = 0.76343530416489}, | |
| 326 --block 7 | |
| 327 {x1 = 0.49673527479172, y1 = 0.73338270187378, x2 = 0.48483556509018, y2 = 0.76356953382492}, | |
| 328 --block 8 | |
| 329 {x1 = 0.48133307695389, y1 = 0.73373115062714, x2 = 0.46920585632324, y2 = 0.76366758346558}, | |
| 330 --block 9 | |
| 331 {x1 = 0.46568286418915, y1 = 0.73440700769424, x2 = 0.45381307601929, y2 = 0.76358675956726}, | |
| 332 --block 10 | |
| 333 {x1 = 0.45046973228455, y1 = 0.73361301422119, x2 = 0.43929302692413, y2 = 0.76388084888458}, | |
| 334 | |
| 335 --block 11 | |
| 336 {x1 = 0.51104211807251, y1 = 0.76532691717148, x2 = 0.50021582841873, y2 = 0.79546189308167}, | |
| 337 --block 12 | |
| 338 {x1 = 0.4964514374733, y1 = 0.76603573560715, x2 = 0.48449218273163, y2 = 0.79527854919434}, | |
| 339 --block 13 | |
| 340 {x1 = 0.48101079463959, y1 = 0.76503103971481, x2 = 0.46944016218185, y2 = 0.79543298482895}, | |
| 341 --block 14 | |
| 342 {x1 = 0.46541726589203, y1 = 0.7654857635498, x2 = 0.45369201898575, y2 = 0.79529416561127}, | |
| 343 --block 15 | |
| 344 {x1 = 0.45051556825638, y1 = 0.76583826541901, x2 = 0.43931984901428, y2 = 0.79570162296295}, | |
| 345 | |
| 346 --block 16 | |
| 347 {x1 = 0.51103663444519, y1 = 0.79726493358612, x2 = 0.50061076879501, y2 = 0.8241291642189}, | |
| 348 --block 17 | |
| 349 {x1 = 0.49670505523682, y1 = 0.79692482948303, x2 = 0.48469054698944, y2 = 0.82489335536957}, | |
| 350 --block 18 | |
| 351 {x1 = 0.48130965232849, y1 = 0.79742962121964, x2 = 0.46962946653366, y2 = 0.82453238964081}, | |
| 352 --block 19 | |
| 353 {x1 = 0.46575212478638, y1 = 0.79766929149628, x2 = 0.45400339365005, y2 = 0.82176661491394}, | |
| 354 --block 20 | |
| 355 {x1 = 0.45073217153549, y1 = 0.79751670360565, x2 = 0.43945103883743, y2 = 0.82504689693451}, | |
| 356 } | |
| 357 | |
| 358 function f:WhichBlock (x, y) | |
| 359 for i = 1, #locs do | |
| 360 local loc = locs [i] | |
| 361 if (x >= loc.x2 and x <= loc.x1 and y >= loc.y1 and y <= loc.y2) then | |
| 362 return i | |
| 363 end | |
| 364 end | |
| 365 end | |
| 366 | |
| 367 function f:percent_color (value, inverted) | |
| 368 local r, g | |
| 369 if (value < 50) then | |
| 370 r = 255 | |
| 371 else | |
| 372 r = floor ( 255 - (value * 2 - 100) * 255 / 100) | |
| 373 end | |
| 374 | |
| 375 if (value > 50) then | |
| 376 g = 255 | |
| 377 else | |
| 378 g = floor ( (value * 2) * 255 / 100) | |
| 379 end | |
| 380 | |
| 381 if (inverted) then | |
| 382 return g/255, r/255, 0 | |
| 383 else | |
| 384 return r/255, g/255, 0 | |
| 385 end | |
| 386 end |
