comparison Hansgar_And_Franzok_Assist.lua @ 7:fe47845b3f17

- frames movable.
author Tercio
date Fri, 13 Mar 2015 17:56:08 -0300
parents 3121ac72fcda
children 3a6b062ecaac
comparison
equal deleted inserted replaced
6:3121ac72fcda 7:fe47845b3f17
7 local abs = abs 7 local abs = abs
8 local GetPlayerFacing = GetPlayerFacing 8 local GetPlayerFacing = GetPlayerFacing
9 9
10 local f = CreateFrame ("frame", "Hansgar_And_Franzok_Assist", UIParent) 10 local f = CreateFrame ("frame", "Hansgar_And_Franzok_Assist", UIParent)
11 f:SetFrameStrata ("DIALOG") 11 f:SetFrameStrata ("DIALOG")
12 f.version = "v0.7" 12 f.version = "v0.8"
13 13
14 local tframe = CreateFrame ("frame", "Hansgar_And_Franzok_Assist_PTrack", UIParent) 14 local tframe = CreateFrame ("frame", "Hansgar_And_Franzok_Assist_PTrack", UIParent)
15 15
16 f:SetSize (155, 156) 16 f:SetSize (155, 156)
17 f:SetBackdrop ({bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", tile = true, tileSize = 16, insets = {left = -1, right = -1, top = -1, bottom = -1}, 17 f:SetBackdrop ({bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", tile = true, tileSize = 16, insets = {left = -1, right = -1, top = -1, bottom = -1},
18 edgeFile = "Interface\\AddOns\\Hansgar_And_Franzok_Assist\\border_2", edgeSize = 8}) 18 edgeFile = "Interface\\AddOns\\Hansgar_And_Franzok_Assist\\border_2", edgeSize = 8})
19 f:SetPoint ("center", UIParent, "center") 19 f:SetPoint ("center", UIParent, "center", 300, 200)
20 f:SetBackdropColor (0, 0, 0, 0) 20 f:SetBackdropColor (0, 0, 0, 0)
21 f:SetBackdropBorderColor (0, 0, 0, 1) 21 f:SetBackdropBorderColor (0, 0, 0, 1)
22 f:SetMovable (true) 22 f:SetMovable (true)
23 f:EnableMouse (true) 23 f:EnableMouse (true)
24 f.all_blocks = {} 24 f.all_blocks = {}
34 frame_event:RegisterEvent ("ENCOUNTER_START") 34 frame_event:RegisterEvent ("ENCOUNTER_START")
35 frame_event:RegisterEvent ("ENCOUNTER_END") 35 frame_event:RegisterEvent ("ENCOUNTER_END")
36 frame_event:RegisterEvent ("ADDON_LOADED") 36 frame_event:RegisterEvent ("ADDON_LOADED")
37 37
38 -- 38 --
39 local player_bar = CreateFrame ("statusbar", "Hansgar_And_Franzok_AssistPlayerBar", f) 39 local player_bar = CreateFrame ("statusbar", "Hansgar_And_Franzok_PlayerAssistBar", UIParent)
40 player_bar:SetPoint ("topleft", f, "bottomleft", 0, -3) 40
41 player_bar:SetPoint ("topright", f, "bottomright", 0, -3) 41 --player_bar:SetPoint ("topleft", f, "bottomleft", 0, -3)
42 player_bar:SetHeight (14) 42 --player_bar:SetPoint ("topright", f, "bottomright", 0, -3)
43
44 player_bar:SetPoint ("center", UIParent, "center", 0, 300)
45 player_bar:SetSize (280, 22)
46
47 player_bar:SetMovable (true)
48 player_bar:EnableMouse (true)
49 player_bar:SetResizable (true)
43 player_bar:SetStatusBarColor (0, 0, 0, 0) 50 player_bar:SetStatusBarColor (0, 0, 0, 0)
44 player_bar:SetMinMaxValues (0, 100) 51 player_bar:SetMinMaxValues (0, 100)
45 player_bar:SetValue (0) 52 player_bar:SetValue (0)
53 player_bar:SetMinResize (50, 15)
54 player_bar:SetMaxResize (500, 40)
55 player_bar:Hide()
56
57 local player_bar_backgroud = player_bar:CreateTexture (nil, "background")
58 player_bar_backgroud:SetTexture (0, 0, 0, 0.2)
59 player_bar_backgroud:SetAllPoints()
60
61 local icon = player_bar:CreateTexture (nil, "overlay")
62 icon:SetTexture ([[Interface\HELPFRAME\ReportLagIcon-Movement]])
63 icon:SetPoint ("left", player_bar, "left")
64 icon:SetDesaturated (true)
65 player_bar.icon = icon
66
67 local text = player_bar:CreateFontString (nil, "overlay", "GameFontNormal")
68 text:SetPoint ("right", player_bar, "right", -2, 0)
69 player_bar.text = text
70
71 player_bar:SetScript ("OnMouseDown", function (self)
72 if (not self.isMoving) then
73 self:StartMoving()
74 self.isMoving = true
75 end
76 end)
77 player_bar:SetScript ("OnMouseUp", function (self)
78 if (self.isMoving) then
79 self:StopMovingOrSizing()
80 self.isMoving = false
81 end
82 end)
83 player_bar:SetScript ("OnSizeChanged", function (self)
84 self.icon:SetSize (self:GetHeight(), self:GetHeight())
85
86 end)
87 local grip = CreateFrame ("button", "Hansgar_And_Franzok_AssistPlayerBarButton", player_bar)
88 grip:SetPoint ("bottomright", player_bar, "bottomright")
89 grip:SetSize (16, 16)
90 grip:SetScript ("OnMouseDown", function (self, button)
91 if (not player_bar.isMoving and button == "LeftButton") then
92 player_bar:StartSizing ("bottomright")
93 player_bar.isMoving = true
94 end
95 end)
96 grip:SetScript ("OnMouseUp", function (self, button)
97 if (player_bar.isMoving and button == "LeftButton") then
98 player_bar:StopMovingOrSizing()
99 player_bar.isMoving = false
100 end
101 end)
102 grip:SetNormalTexture ([[Interface\CHATFRAME\UI-ChatIM-SizeGrabber-Up]])
103 grip:SetHighlightTexture ([[Interface\CHATFRAME\UI-ChatIM-SizeGrabber-Highlight]])
104 grip:SetPushedTexture ([[Interface\CHATFRAME\UI-ChatIM-SizeGrabber-Down]])
105
106 player_bar.grip = grip
46 f.player_bar = player_bar 107 f.player_bar = player_bar
108
47 109
48 player_bar.texture = player_bar:CreateTexture (nil, "overlay") 110 player_bar.texture = player_bar:CreateTexture (nil, "overlay")
49 player_bar.texture:SetTexture ("Interface\\AddOns\\Hansgar_And_Franzok_Assist\\bar_skyline") 111 player_bar.texture:SetTexture ("Interface\\AddOns\\Hansgar_And_Franzok_Assist\\bar_skyline")
50 player_bar:SetStatusBarTexture (player_bar.texture) 112 player_bar:SetStatusBarTexture (player_bar.texture)
51 113
52 -- 114 --
53 115
54 local player_pos_frame = CreateFrame ("frame", "Hansgar_And_Franzok_Assist_DanceBar", UIParent) 116 local player_pos_frame = CreateFrame ("frame", "Hansgar_And_Franzok_Assist_BarDance", UIParent)
55 player_pos_frame:SetPoint ("topleft", player_bar, "bottomleft", 0, -3) 117 --player_pos_frame:SetPoint ("topleft", player_bar, "bottomleft", 0, -3)
56 player_pos_frame:SetPoint ("topright", player_bar, "bottomright", 0, -3) 118 --player_pos_frame:SetPoint ("topright", player_bar, "bottomright", 0, -3)
57 player_pos_frame:SetHeight (14) 119
58 player_pos_frame:SetBackdrop ({bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", tile = true, tileSize = 16, insets = {left = -1, right = -1, top = -1, bottom = -1}, 120 player_pos_frame:SetPoint ("center", UIParent, "center", 0, -75)
59 edgeFile = "Interface\\AddOns\\Hansgar_And_Franzok_Assist\\border_2", edgeSize = 8}) 121
60 player_pos_frame:SetBackdropColor (0, 0, 0, 1) 122 player_pos_frame:SetSize (155, 6)
123 player_pos_frame:SetBackdrop ({bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", tile = true, tileSize = 16})
124 player_pos_frame:SetBackdropColor (0, 0, 0, 0.4)
125 player_pos_frame:SetMovable (true)
126 player_pos_frame:EnableMouse (true)
127 player_pos_frame:SetScript ("OnMouseDown", function (self)
128 if (not self.isMoving) then
129 self:StartMoving()
130 self.isMoving = true
131 end
132 end)
133 player_pos_frame:SetScript ("OnMouseUp", function (self)
134 if (self.isMoving) then
135 self:StopMovingOrSizing()
136 self.isMoving = false
137 end
138 end)
61 player_pos_frame:Hide() 139 player_pos_frame:Hide()
62 140
63 --red 141 --red
64 local t1 = player_pos_frame:CreateTexture (nil, "artwork") 142 local t1 = player_pos_frame:CreateTexture (nil, "artwork")
65 t1:SetPoint ("left", player_pos_frame, "left") 143 t1:SetPoint ("left", player_pos_frame, "left")
66 t1:SetSize (player_pos_frame:GetWidth()*0.30, 14) 144 t1:SetSize (player_pos_frame:GetWidth()*0.30, 6)
67 t1:SetTexture (1, 1, 1) 145 t1:SetTexture (1, 1, 1)
68 --t1:SetTexCoord (260/512, 430/512, 29/256, 82/256) 146 --t1:SetTexCoord (260/512, 430/512, 29/256, 82/256)
69 t1:SetVertexColor (1, 0.2, 0.2, 0.4) 147 t1:SetVertexColor (1, 0.2, 0.2, 0.4)
70 148
71 --green 149 --green
72 local t2 = player_pos_frame:CreateTexture (nil, "artwork") 150 local t2 = player_pos_frame:CreateTexture (nil, "artwork")
73 t2:SetPoint ("left", t1, "right") 151 t2:SetPoint ("left", t1, "right")
74 t2:SetSize (player_pos_frame:GetWidth()*0.15, 14) 152 t2:SetSize (player_pos_frame:GetWidth()*0.15, 6)
75 t2:SetTexture (0.2, 1, 0.2, 0.4) 153 t2:SetTexture (0.2, 1, 0.2, 0.4)
76 154
77 --red 155 --red
78 local middle = player_pos_frame:CreateTexture (nil, "artwork") 156 local middle = player_pos_frame:CreateTexture (nil, "artwork")
79 middle:SetPoint ("left", t2, "right") 157 middle:SetPoint ("left", t2, "right")
80 middle:SetSize (player_pos_frame:GetWidth()*0.10, 14) 158 middle:SetSize (player_pos_frame:GetWidth()*0.10, 6)
81 middle:SetTexture (1, 1, 1) 159 middle:SetTexture (1, 1, 1)
82 --middle:SetTexCoord (260/512, 430/512, 29/256, 82/256) 160 --middle:SetTexCoord (260/512, 430/512, 29/256, 82/256)
83 middle:SetVertexColor (1, 0.2, 0.2, 0.4) 161 middle:SetVertexColor (1, 0.2, 0.2, 0.4)
84 162
85 --green 163 --green
86 local t3 = player_pos_frame:CreateTexture (nil, "artwork") 164 local t3 = player_pos_frame:CreateTexture (nil, "artwork")
87 t3:SetPoint ("left", middle, "right") 165 t3:SetPoint ("left", middle, "right")
88 t3:SetSize (player_pos_frame:GetWidth()*0.15, 14) 166 t3:SetSize (player_pos_frame:GetWidth()*0.15, 6)
89 t3:SetTexture (0.2, 1, 0.2, 0.4) 167 t3:SetTexture (0.2, 1, 0.2, 0.4)
90 168
91 --red 169 --red
92 local t4 = player_pos_frame:CreateTexture (nil, "artwork") 170 local t4 = player_pos_frame:CreateTexture (nil, "artwork")
93 t4:SetPoint ("left", t3, "right") 171 t4:SetPoint ("left", t3, "right")
94 t4:SetSize (player_pos_frame:GetWidth()*0.30, 14) 172 t4:SetSize (player_pos_frame:GetWidth()*0.30, 6)
95 t4:SetTexture (1, 1, 1) 173 t4:SetTexture (1, 1, 1)
96 --t4:SetTexCoord (260/512, 430/512, 29/256, 82/256) 174 --t4:SetTexCoord (260/512, 430/512, 29/256, 82/256)
97 t4:SetVertexColor (1, 0.2, 0.2, 0.4) 175 t4:SetVertexColor (1, 0.2, 0.2, 0.4)
98 176
99 local div = player_pos_frame:CreateTexture (nil, "overlay") 177 local div = player_pos_frame:CreateTexture (nil, "overlay")
192 db.AUTO_FACING = true 270 db.AUTO_FACING = true
193 end 271 end
194 if (db.FACING_SIDE == nil) then 272 if (db.FACING_SIDE == nil) then
195 db.FACING_SIDE = 1 273 db.FACING_SIDE = 1
196 end 274 end
275 if (db.SHOW_MAIN_FRAME == nil) then
276 db.SHOW_MAIN_FRAME = true
277 end
278 if (db.PLAY_SOUND == nil) then
279 db.PLAY_SOUND = false
280 end
197 -- 281 --
198 282
283 f:SetLockState (true)
284
199 elseif (event == "ENCOUNTER_START" or event == "ENCOUNTER_END") then 285 elseif (event == "ENCOUNTER_START" or event == "ENCOUNTER_END") then
200 286
201 local encounterID, encounterName, difficultyID, raidSize = select (1, ...) 287 local encounterID, encounterName, difficultyID, raidSize = select (1, ...)
202 288
203 if (encounterID == 1693) then 289 if (encounterID == 1693) then
281 if (f.StampersPhase) then 367 if (f.StampersPhase) then
282 return f:StopTracking() 368 return f:StopTracking()
283 end 369 end
284 f:EndTrackPlayerPosition() 370 f:EndTrackPlayerPosition()
285 371
372 elseif (command == "unlock") then
373 db.FRAME_LOCK = true
374 f:SetLockState()
375 print ("|cFFFFAA00Hansgar and Franzok Assist|r frame unlocked.")
376
286 elseif (command == "lock") then 377 elseif (command == "lock") then
287 f:SetLockState() 378 f:SetLockState()
288 379
289 if (db.FRAME_LOCK) then 380 if (db.FRAME_LOCK) then
290 print ("|cFFFFAA00Hansgar and Franzok Assist|r frame locked.") 381 print ("|cFFFFAA00Hansgar and Franzok Assist|r frame locked.")
391 if (player_block and f.block_tracker [player_block] and raid_size > 0) then 482 if (player_block and f.block_tracker [player_block] and raid_size > 0) then
392 483
393 local time_limit_at = f.block_tracker [player_block] + db.STAMPERS_DELAY 484 local time_limit_at = f.block_tracker [player_block] + db.STAMPERS_DELAY
394 local time_now = GetTime() 485 local time_now = GetTime()
395 486
396 f.player_bar:SetValue ((time_limit_at - time_now) / db.STAMPERS_DELAY * 100) 487 local timeleft = time_limit_at - time_now
488 f.player_bar:SetValue ((timeleft) / db.STAMPERS_DELAY * 100)
489 if (timeleft > 0) then
490 f.player_bar.text:SetText (format ("%.1f", timeleft))
491 else
492 f.player_bar.text:SetText ("Move!")
493 end
397 f.player_bar:Show() 494 f.player_bar:Show()
398 495
399 local block_frame = f.all_blocks [player_block] 496 local block_frame = f.all_blocks [player_block]
400 f.player_loc_box:SetPoint ("center", block_frame, "center") 497 f.player_loc_box:SetPoint ("center", block_frame, "center")
401 f.player_loc_box:Show() 498 f.player_loc_box:Show()
402 player_bar:Show() 499
403 else 500 else
404 f.player_loc_box:Hide() 501 f.player_loc_box:Hide()
405 f.player_bar:Hide() 502 f.player_bar:Hide()
406 end 503 end
407 end 504 end
413 f.StampersPhase = true 510 f.StampersPhase = true
414 511
415 if (not f.frames_built) then 512 if (not f.frames_built) then
416 f:CreateWindow() 513 f:CreateWindow()
417 end 514 end
418 515
419 f:ResetBlocks() 516 f:ResetBlocks()
420 f.player_loc_box:Hide() 517 f.player_loc_box:Hide()
421 518
422 f.block_tracker = f.block_tracker or {} 519 f.block_tracker = f.block_tracker or {}
423 table.wipe (f.block_tracker) 520 table.wipe (f.block_tracker)
424 521
425 SetMapToCurrentZone() 522 SetMapToCurrentZone()
426 523
427 frame_tracker:SetScript ("OnUpdate", on_update_tracker) 524 frame_tracker:SetScript ("OnUpdate", on_update_tracker)
428 f:Show() 525 f:Show()
526 f.player_bar:Show()
527
429 end 528 end
430 529
431 function f:StopTracking() 530 function f:StopTracking()
432 print ("|cFFFFAA00Hansgar and Franzok Assist|r: Smart Stampers phase ended.") 531 print ("|cFFFFAA00Hansgar and Franzok Assist|r: Smart Stampers phase ended.")
433 532
434 f.StampersPhase = false 533 f.StampersPhase = false
435 frame_tracker:SetScript ("OnUpdate", nil) 534 frame_tracker:SetScript ("OnUpdate", nil)
436 table.wipe (f.block_tracker) 535 table.wipe (f.block_tracker)
437 f.player_loc_box:Hide() 536 f.player_loc_box:Hide()
438 f:Hide() 537 f:Hide()
538 f.player_bar:SetValue (0)
539 f.player_bar:Hide()
439 end 540 end
440 541
441 local on_mouse_down = function (self) 542 local on_mouse_down = function (self)
442 if (not self.isMoving and not db.FRAME_LOCK) then 543 if (not self.isMoving and not db.FRAME_LOCK) then
443 self.isMoving = true 544 self.isMoving = true
521 block.cooldown:SetDrawEdge (true) 622 block.cooldown:SetDrawEdge (true)
522 end 623 end
523 end 624 end
524 end 625 end
525 626
526 function f:SetLockState() 627 function f:SetLockState (just_refresh)
527 db.FRAME_LOCK = not db.FRAME_LOCK 628
629 if (not just_refresh) then
630 db.FRAME_LOCK = not db.FRAME_LOCK
631 end
632
528 if (db.FRAME_LOCK) then 633 if (db.FRAME_LOCK) then
529 --locked 634 --locked
530 f:EnableMouse (false) 635 f:EnableMouse (false)
636 player_bar:EnableMouse (false)
637 player_pos_frame:EnableMouse (false)
638
531 for _, block in ipairs (f.all_blocks) do 639 for _, block in ipairs (f.all_blocks) do
532 block:EnableMouse (false) 640 block:EnableMouse (false)
641 end
642
643 if (f.StampersPhase and not just_refresh) then
644 f:EndTrackPlayerPosition()
645 f:StopTracking()
533 end 646 end
534 else 647 else
535 --unlocked 648 --unlocked
536 f:EnableMouse (true) 649 f:EnableMouse (true)
650 player_bar:EnableMouse (true)
651 player_pos_frame:EnableMouse (true)
652
537 for _, block in ipairs (f.all_blocks) do 653 for _, block in ipairs (f.all_blocks) do
538 block:EnableMouse (true) 654 block:EnableMouse (true)
539 end 655 end
656
657 if (not f.StampersPhase and not just_refresh) then
658 f:StartTracking()
659 f:StartTrackPlayerPosition()
660 end
661 end
662
663 if (not db.FRAME_LOCK) then
664 player_bar.grip:Show()
665 else
666 player_bar.grip:Hide()
540 end 667 end
541 end 668 end
542 669
543 function f:CreateWindow() 670 function f:CreateWindow()
544 local x = 0 671 local x = 0
599 726
600 tinsert (f.all_blocks, block) 727 tinsert (f.all_blocks, block)
601 728
602 end 729 end
603 730
604 f:SetLockState() 731 f:SetLockState (true)
605 732
606 f.frames_built = true 733 f.frames_built = true
607 734
608 end 735 end
609 736
640 Hansgar_safe_track = safe_track 767 Hansgar_safe_track = safe_track
641 768
642 -- /hansgar test 769 -- /hansgar test
643 -- /run Hansgar_safe_track [1].block.x1 = 0.50154542922974 770 -- /run Hansgar_safe_track [1].block.x1 = 0.50154542922974
644 771
645 local red_alpha_disabled = 0.15 772 local red_alpha_disabled = 0.2
646 local red_alpha_enabled = 0.5 773 local red_alpha_enabled = 0.5
647 774
648 local green_alpha_disabled = 0.05 775 local green_alpha_disabled = 0.05
649 local green_alpha_enabled = 0.9 776 local green_alpha_enabled = 0.9
650 777