comparison modules/Action.lua @ 121:fb6c3a642ae3

Added proper vehicle bar support. The exit-vehicle button is a little kludgy, needs to be cleaned up later.
author Flick <flickerstreak@gmail.com>
date Mon, 09 Feb 2009 19:02:58 +0000
parents fb48811a8736
children 729232aeeb5e
comparison
equal deleted inserted replaced
120:320a93c5f72c 121:fb6c3a642ae3
191 type = "toggle", 191 type = "toggle",
192 width = "double", 192 width = "double",
193 set = "SetMindControl", 193 set = "SetMindControl",
194 get = "GetMindControl", 194 get = "GetMindControl",
195 }, 195 },
196 vehicle = {
197 name = L["Vehicle Support"],
198 desc = L["When on a vehicle, map the first 6 buttons of this bar to the vehicle actions. The vehicle-exit button is mapped to the 7th button. Pitch controls are not supported."],
199 order = 6,
200 type = "toggle",
201 width = "double",
202 get = "GetVehicle",
203 set = "SetVehicle",
204 },
196 actions = { 205 actions = {
197 name = L["Edit Action IDs"], 206 name = L["Edit Action IDs"],
198 order = 6, 207 order = 7,
199 type = "group", 208 type = "group",
200 inline = true, 209 inline = true,
201 args = { 210 args = {
202 method = { 211 method = {
203 name = L["Assign"], 212 name = L["Assign"],
315 local f = self.bar:GetFrame() 324 local f = self.bar:GetFrame()
316 for _, b in ipairs(self.btns) do 325 for _, b in ipairs(self.btns) do
317 b:Refresh() 326 b:Refresh()
318 end 327 end
319 f:SetAttribute("mindcontrol",self.config.mindcontrol) 328 f:SetAttribute("mindcontrol",self.config.mindcontrol)
329 f:SetAttribute("vehicle",self.config.vehicle)
320 f:Execute( 330 f:Execute(
321 [[ 331 [[
322 doMindControl = self:GetAttribute("mindcontrol") 332 doMindControl = self:GetAttribute("mindcontrol")
333 doVehicle = self:GetAttribute("vehicle")
323 control:ChildUpdate() 334 control:ChildUpdate()
324 ]]) 335 ]])
325 336
326 f:SetAttribute("_onstate-mindcontrol", 337 f:SetAttribute("_onstate-mc",
327 -- function _onstate-mindcontrol(self, stateid, newstate) 338 -- function _onstate-mc(self, stateid, newstate)
328 [[ 339 [[
340 local oldMcVehicleState = mcVehicleState
341 mcVehicleState = newstate
329 control:ChildUpdate() 342 control:ChildUpdate()
343 if oldMcVehicleState == "vehicle" or mcVehicleState == "vehicle" then
344 control:ChildUpdate("vehicle")
345 end
330 ]]) 346 ]])
331 RegisterStateDriver(f, "mindcontrol", "[bonusbar:5] mc; none") 347 RegisterStateDriver(f, "mc", "[target=vehicle,exists] vehicle; [bonusbar:5] mc; none")
348
332 self:UpdateButtonLock() 349 self:UpdateButtonLock()
333 end 350 end
334 351
335 function Handle:Destroy() 352 function Handle:Destroy()
336 for _,b in pairs(self.btns) do 353 for _,b in pairs(self.btns) do
434 return self.config.mindcontrol 451 return self.config.mindcontrol
435 end 452 end
436 453
437 function Handle:SetMindControl(info, value) 454 function Handle:SetMindControl(info, value)
438 self.config.mindcontrol = value 455 self.config.mindcontrol = value
456 self:Refresh()
457 end
458
459 function Handle:GetVehicle()
460 return self.config.vehicle
461 end
462
463 function Handle:SetVehicle(info, value)
464 self.config.vehicle = value
439 self:Refresh() 465 self:Refresh()
440 end 466 end
441 467
442 function Handle:GetActionEditMethod() 468 function Handle:GetActionEditMethod()
443 return self.editMethod or 0 469 return self.editMethod or 0
756 end 782 end
757 783
758 ------ Button class ------ 784 ------ Button class ------
759 local frameRecycler = { } 785 local frameRecycler = { }
760 local trash = CreateFrame("Frame") 786 local trash = CreateFrame("Frame")
761 local OnUpdate, KBAttach, GetHotkey 787 local OnUpdate, GetActionName, GetHotkey
762 do 788 do
763 local ATTACK_BUTTON_FLASH_TIME = ATTACK_BUTTON_FLASH_TIME 789 local ATTACK_BUTTON_FLASH_TIME = ATTACK_BUTTON_FLASH_TIME
764 local IsActionInRange = IsActionInRange 790 local IsActionInRange = IsActionInRange
765 791
766 function OnUpdate(frame, elapsed) 792 function OnUpdate(frame, elapsed)
797 frame.rangeTimer = 0.1 823 frame.rangeTimer = 0.1
798 end 824 end
799 end 825 end
800 end 826 end
801 827
802 local function GetActionName(f) 828 function GetActionName(f)
803 local b = f and f._reactionButton 829 local b = f and f._reactionButton
804 if b then 830 if b then
805 return format("%s:%s", b.bar:GetName(), b.idx) 831 return format("%s:%s", b.bar:GetName(), b.idx)
806 end 832 end
807 end 833 end
808 834
809 function GetHotkey(f) 835 function GetHotkey(f)
810 return KB:ToShortKey(GetBindingKey(format("CLICK %s:LeftButton",f:GetName()))) 836 return KB:ToShortKey(GetBindingKey(format("CLICK %s:LeftButton",f:GetName())))
811 end
812
813 local function kb_onEnter( self )
814 if ReAction:GetKeybindMode() then
815 KB:Set(self)
816 end
817 end
818
819 function KBAttach( button )
820 if not button.kbHooked then
821 button.kbHooked = true
822 local f = button:GetFrame()
823 f:HookScript("OnEnter", kb_onEnter)
824 f.GetActionName = GetActionName
825 f.GetHotkey = GetHotkey
826 end
827 end 837 end
828 838
829 -- This is a bit hokey : install a bare hook on ActionButton_UpdateHotkey because 839 -- This is a bit hokey : install a bare hook on ActionButton_UpdateHotkey because
830 -- even though it's secure it's never called in a way that can cause taint. This is 840 -- even though it's secure it's never called in a way that can cause taint. This is
831 -- for performance reasons to avoid having to hook frame:OnEvent securely. 841 -- for performance reasons to avoid having to hook frame:OnEvent securely.
892 902
893 f:SetAttribute("action", config.actionID) 903 f:SetAttribute("action", config.actionID)
894 f:SetAttribute("default-action", config.actionID) 904 f:SetAttribute("default-action", config.actionID)
895 -- install mind control actions for all buttons just for simplicity 905 -- install mind control actions for all buttons just for simplicity
896 if self.idx <= 12 then 906 if self.idx <= 12 then
897 f:SetAttribute("mindcontrol-action", 120 + self.idx) 907 f:SetAttribute("mc-action", 120 + self.idx)
898 end 908 end
909
910 -- set a tooltip onEnter
911 f:SetScript("OnEnter",
912 function(frame)
913 if ReAction:GetKeybindMode() then
914 KB:Set(frame)
915 elseif frame.vehicleExitMode then
916 GameTooltip_AddNewbieTip(frame, LEAVE_VEHICLE, 1.0, 1.0, 1.0, nil);
917 else
918 ActionButton_SetTooltip(frame)
919 end
920 end)
899 921
900 -- set a _childupdate handler, called within the header's context 922 -- set a _childupdate handler, called within the header's context
901 f:SetAttribute("_childupdate", 923 f:SetAttribute("_childupdate",
902 -- function _childupdate(self, snippetid, message) 924 -- function _childupdate(self, snippetid, message)
903 [[ 925 [[
904 local action = "default-action" 926 local action = "default-action"
905 if doMindControl and GetBonusBarOffset() == 5 then 927 if (doVehicle and mcVehicleState == "vehicle") or
906 action = "mindcontrol-action" 928 (doMindControl and mcVehicleState == "mc") then
929 action = "mc-action"
907 elseif page and state and page[state] then 930 elseif page and state and page[state] then
908 action = "action-"..page[state] 931 action = "action-"..page[state]
909 end 932 end
933
910 local value = self:GetAttribute(action) 934 local value = self:GetAttribute(action)
911 if value then 935 if value then
912 self:SetAttribute("action",value) 936 self:SetAttribute("action",value)
913 end 937 end
914 ]]) 938 ]])
939
940 -- Install a handler for the 7th button (only) to show/hide a
941 -- vehicle exit button. This is more than a little bit hack-ish and
942 -- will be replaced in the next iteration with the reimplementation
943 -- of action button functionality.
944 if idx == 7 then
945 local barFrame = bar:GetFrame()
946 function barFrame:ShowVehicleExit(show)
947 local tx = f.vehicleExitTexture
948 if show then
949 if not tx then
950 tx = f:CreateTexture(nil,"ARTWORK")
951 tx:SetAllPoints()
952 -- copied from Blizzard/VehicleMenuBar.lua SkinsData
953 tx:SetTexture("Interface\\Vehicles\\UI-Vehicles-Button-Exit-Up")
954 tx:SetTexCoord(0.140625, 0.859375, 0.140625, 0.859375)
955 f.vehicleExitTexture = tx
956 end
957 tx:Show()
958 f.vehicleExitMode = true
959 elseif tx then
960 tx:SetTexCoord(0,1,0,1)
961 tx:Hide()
962 f.vehicleExitMode = false
963 end
964 end
965
966 f:SetAttribute("macrotext","/run VehicleExit()")
967 f:SetAttribute("_childupdate-vehicle",
968 -- function _childupdate-vehicle(self, snippetid, message)
969 [[
970 local show = (mcVehicleState == "vehicle")
971 if show then
972 self:SetAttribute("type","macro")
973 self:SetAttribute("showgrid",self:GetAttribute("showgrid")+1)
974 self:Show()
975 else
976 self:SetAttribute("type","action")
977 local showgrid = self:GetAttribute("showgrid")
978 showgrid = showgrid - 1
979 if showgrid < 0 then showgrid = 0 end
980 self:SetAttribute("showgrid",self:GetAttribute("showgrid")-1)
981 if showgrid <= 0 then
982 self:Hide()
983 end
984 end
985 control:CallMethod("ShowVehicleExit",show)
986 ]])
987 end
915 988
916 -- install drag wrappers to lock buttons 989 -- install drag wrappers to lock buttons
917 bar:GetFrame():WrapScript(f, "OnDragStart", 990 bar:GetFrame():WrapScript(f, "OnDragStart",
918 -- OnDragStart(self, button, kind, value, ...) 991 -- OnDragStart(self, button, kind, value, ...)
919 [[ 992 [[
952 local f = self.frame 1025 local f = self.frame
953 f:UnregisterAllEvents() 1026 f:UnregisterAllEvents()
954 f:Hide() 1027 f:Hide()
955 f:SetParent(UIParent) 1028 f:SetParent(UIParent)
956 f:ClearAllPoints() 1029 f:ClearAllPoints()
1030 f:SetAttribute("_childupdate",nil)
1031 f:SetAttribute("_childupdate-vehicle",nil)
957 if self.name then 1032 if self.name then
958 frameRecycler[self.name] = f 1033 frameRecycler[self.name] = f
959 end 1034 end
960 if self.config.actionID then 1035 if self.config.actionID then
961 IDAlloc:Release(self.config.actionID) 1036 IDAlloc:Release(self.config.actionID)
1109 end 1184 end
1110 end 1185 end
1111 1186
1112 function Button:SetKeybindMode( mode ) 1187 function Button:SetKeybindMode( mode )
1113 if mode then 1188 if mode then
1114 KBAttach( self ) 1189 self.frame.GetActionName = GetActionName
1190 self.frame.GetHotkey = GetHotkey
1115 -- set the border for all buttons to the keybind-enable color 1191 -- set the border for all buttons to the keybind-enable color
1116 self.border:SetVertexColor(KB:GetColorKeyBoundMode()) 1192 self.border:SetVertexColor(KB:GetColorKeyBoundMode())
1117 self.border:Show() 1193 self.border:Show()
1118 elseif IsEquippedAction(self:GetActionID()) then 1194 elseif IsEquippedAction(self:GetActionID()) then
1119 self.border:SetVertexColor(0, 1.0, 0, 0.35) -- from ActionButton.lua 1195 self.border:SetVertexColor(0, 1.0, 0, 0.35) -- from ActionButton.lua