Mercurial > wow > reaction
diff 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 |
line wrap: on
line diff
--- a/modules/Action.lua Fri Feb 06 23:01:50 2009 +0000 +++ b/modules/Action.lua Mon Feb 09 19:02:58 2009 +0000 @@ -193,9 +193,18 @@ set = "SetMindControl", get = "GetMindControl", }, + vehicle = { + name = L["Vehicle Support"], + 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."], + order = 6, + type = "toggle", + width = "double", + get = "GetVehicle", + set = "SetVehicle", + }, actions = { name = L["Edit Action IDs"], - order = 6, + order = 7, type = "group", inline = true, args = { @@ -317,18 +326,26 @@ b:Refresh() end f:SetAttribute("mindcontrol",self.config.mindcontrol) + f:SetAttribute("vehicle",self.config.vehicle) f:Execute( [[ doMindControl = self:GetAttribute("mindcontrol") + doVehicle = self:GetAttribute("vehicle") control:ChildUpdate() ]]) - f:SetAttribute("_onstate-mindcontrol", - -- function _onstate-mindcontrol(self, stateid, newstate) + f:SetAttribute("_onstate-mc", + -- function _onstate-mc(self, stateid, newstate) [[ + local oldMcVehicleState = mcVehicleState + mcVehicleState = newstate control:ChildUpdate() + if oldMcVehicleState == "vehicle" or mcVehicleState == "vehicle" then + control:ChildUpdate("vehicle") + end ]]) - RegisterStateDriver(f, "mindcontrol", "[bonusbar:5] mc; none") + RegisterStateDriver(f, "mc", "[target=vehicle,exists] vehicle; [bonusbar:5] mc; none") + self:UpdateButtonLock() end @@ -439,6 +456,15 @@ self:Refresh() end + function Handle:GetVehicle() + return self.config.vehicle + end + + function Handle:SetVehicle(info, value) + self.config.vehicle = value + self:Refresh() + end + function Handle:GetActionEditMethod() return self.editMethod or 0 end @@ -758,7 +784,7 @@ ------ Button class ------ local frameRecycler = { } local trash = CreateFrame("Frame") -local OnUpdate, KBAttach, GetHotkey +local OnUpdate, GetActionName, GetHotkey do local ATTACK_BUTTON_FLASH_TIME = ATTACK_BUTTON_FLASH_TIME local IsActionInRange = IsActionInRange @@ -799,7 +825,7 @@ end end - local function GetActionName(f) + function GetActionName(f) local b = f and f._reactionButton if b then return format("%s:%s", b.bar:GetName(), b.idx) @@ -810,22 +836,6 @@ return KB:ToShortKey(GetBindingKey(format("CLICK %s:LeftButton",f:GetName()))) end - local function kb_onEnter( self ) - if ReAction:GetKeybindMode() then - KB:Set(self) - end - end - - function KBAttach( button ) - if not button.kbHooked then - button.kbHooked = true - local f = button:GetFrame() - f:HookScript("OnEnter", kb_onEnter) - f.GetActionName = GetActionName - f.GetHotkey = GetHotkey - end - end - -- This is a bit hokey : install a bare hook on ActionButton_UpdateHotkey because -- even though it's secure it's never called in a way that can cause taint. This is -- for performance reasons to avoid having to hook frame:OnEvent securely. @@ -894,25 +904,88 @@ f:SetAttribute("default-action", config.actionID) -- install mind control actions for all buttons just for simplicity if self.idx <= 12 then - f:SetAttribute("mindcontrol-action", 120 + self.idx) + f:SetAttribute("mc-action", 120 + self.idx) end + + -- set a tooltip onEnter + f:SetScript("OnEnter", + function(frame) + if ReAction:GetKeybindMode() then + KB:Set(frame) + elseif frame.vehicleExitMode then + GameTooltip_AddNewbieTip(frame, LEAVE_VEHICLE, 1.0, 1.0, 1.0, nil); + else + ActionButton_SetTooltip(frame) + end + end) -- set a _childupdate handler, called within the header's context f:SetAttribute("_childupdate", -- function _childupdate(self, snippetid, message) [[ local action = "default-action" - if doMindControl and GetBonusBarOffset() == 5 then - action = "mindcontrol-action" + if (doVehicle and mcVehicleState == "vehicle") or + (doMindControl and mcVehicleState == "mc") then + action = "mc-action" elseif page and state and page[state] then action = "action-"..page[state] end + local value = self:GetAttribute(action) if value then self:SetAttribute("action",value) end ]]) + -- Install a handler for the 7th button (only) to show/hide a + -- vehicle exit button. This is more than a little bit hack-ish and + -- will be replaced in the next iteration with the reimplementation + -- of action button functionality. + if idx == 7 then + local barFrame = bar:GetFrame() + function barFrame:ShowVehicleExit(show) + local tx = f.vehicleExitTexture + if show then + if not tx then + tx = f:CreateTexture(nil,"ARTWORK") + tx:SetAllPoints() + -- copied from Blizzard/VehicleMenuBar.lua SkinsData + tx:SetTexture("Interface\\Vehicles\\UI-Vehicles-Button-Exit-Up") + tx:SetTexCoord(0.140625, 0.859375, 0.140625, 0.859375) + f.vehicleExitTexture = tx + end + tx:Show() + f.vehicleExitMode = true + elseif tx then + tx:SetTexCoord(0,1,0,1) + tx:Hide() + f.vehicleExitMode = false + end + end + + f:SetAttribute("macrotext","/run VehicleExit()") + f:SetAttribute("_childupdate-vehicle", + -- function _childupdate-vehicle(self, snippetid, message) + [[ + local show = (mcVehicleState == "vehicle") + if show then + self:SetAttribute("type","macro") + self:SetAttribute("showgrid",self:GetAttribute("showgrid")+1) + self:Show() + else + self:SetAttribute("type","action") + local showgrid = self:GetAttribute("showgrid") + showgrid = showgrid - 1 + if showgrid < 0 then showgrid = 0 end + self:SetAttribute("showgrid",self:GetAttribute("showgrid")-1) + if showgrid <= 0 then + self:Hide() + end + end + control:CallMethod("ShowVehicleExit",show) + ]]) + end + -- install drag wrappers to lock buttons bar:GetFrame():WrapScript(f, "OnDragStart", -- OnDragStart(self, button, kind, value, ...) @@ -954,6 +1027,8 @@ f:Hide() f:SetParent(UIParent) f:ClearAllPoints() + f:SetAttribute("_childupdate",nil) + f:SetAttribute("_childupdate-vehicle",nil) if self.name then frameRecycler[self.name] = f end @@ -1111,7 +1186,8 @@ function Button:SetKeybindMode( mode ) if mode then - KBAttach( self ) + self.frame.GetActionName = GetActionName + self.frame.GetHotkey = GetHotkey -- set the border for all buttons to the keybind-enable color self.border:SetVertexColor(KB:GetColorKeyBoundMode()) self.border:Show()