Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 148 lines (127 sloc) 3.719 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
--[[
vehicleBar.lua
A Dominos vehicle bar
--]]

--[[ Vehicle Bar ]]--

local VehicleBar = Dominos:CreateClass('Frame', Dominos.Frame)
Dominos.VehicleBar = VehicleBar

local L = LibStub('AceLocale-3.0'):GetLocale('Dominos')
local buttons = {VehicleMenuBarLeaveButton, VehicleMenuBarPitchUpButton, VehicleMenuBarPitchDownButton}

function VehicleBar:New()
local f = self.super.New(self, 'vehicle', L.TipVehicleBar)
f:SkinButtons()
f:LoadButtons()
f:Layout()
f:SetScript('OnEvent', f.OnEvent)
f:RegisterEvent('UNIT_ENTERED_VEHICLE')
f:RegisterEvent('UNIT_ENTERING_VEHICLE')

return f
end


function VehicleBar:OnEvent(event, arg1)
if event == 'UNIT_ENTERED_VEHICLE' then
if arg1 == 'player' then
self:UpdateButtonVisibility()
end
end
end

function VehicleBar:UpdateButtonVisibility()
if IsVehicleAimAngleAdjustable() then
_G['VehicleMenuBarPitchUpButton']:Show()
_G['VehicleMenuBarPitchDownButton']:Show()
else
_G['VehicleMenuBarPitchUpButton']:Hide()
_G['VehicleMenuBarPitchDownButton']:Hide()
end

if CanExitVehicle() then
_G['VehicleMenuBarLeaveButton']:Show()
else
_G['VehicleMenuBarLeaveButton']:Hide()
end
end

function VehicleBar:SkinButtons()
self:ApplySkin('PitchUpButton')
self:ApplySkin('PitchDownButton')
self:ApplySkin('LeaveButton')
end

function VehicleBar:ApplySkin(frameName)
local skin = self:GetSkinData(frameName)
local frame = _G['VehicleMenuBar' .. frameName]
frame:SetWidth(30)
frame:SetHeight(30)

if skin.normalTexture then
frame:GetNormalTexture():SetTexture(skin.normalTexture);
frame:GetNormalTexture():SetTexCoord(unpack(skin.normalTexCoord));
end

if skin.pushedTexture then
frame:GetPushedTexture():SetTexture(skin.pushedTexture);
frame:GetPushedTexture():SetTexCoord(unpack(skin.pushedTexCoord));
end

if skin.texture then
frame:SetTexture(skin.texture);
frame:SetTexCoord(unpack(skin.texCoord))
end
end

function VehicleBar:GetSkinData(frameName)
if frameName == 'PitchUpButton' then
return { --Pitch up button
height = 36,
width = 38,
point = "BOTTOMLEFT",
xOfs = 146,
yOfs = 41,
normalTexture = [[Interface\Vehicles\UI-Vehicles-Button-Pitch-Up]],
normalTexCoord = { 0.21875, 0.765625, 0.234375, 0.78125 },
pushedTexture = [[Interface\Vehicles\UI-Vehicles-Button-Pitch-Down]],
pushedTexCoord = { 0.21875, 0.765625, 0.234375, 0.78125 },
pitchHidden = 1,
}
elseif frameName == 'PitchDownButton' then
return { --Pitch up button
height = 36,
width = 38,
point = "BOTTOMLEFT",
xOfs = 146,
yOfs = 3,
normalTexture = [[Interface\Vehicles\UI-Vehicles-Button-PitchDown-Up]],
normalTexCoord = { 0.21875, 0.765625, 0.234375, 0.78125 },
pushedTexture = [[Interface\Vehicles\UI-Vehicles-Button-PitchDown-Down]],
pushedTexCoord = { 0.21875, 0.765625, 0.234375, 0.78125 },
pitchHidden = 1,
}
elseif frameName == 'LeaveButton' then
return { --Leave button
height = 47,
width = 50,
point = "BOTTOMRIGHT",
xOfs = -148,
yOfs = 18,
normalTexture = [[Interface\Vehicles\UI-Vehicles-Button-Exit-Up]],
normalTexCoord = { 0.140625, 0.859375, 0.140625, 0.859375 },
pushedTexture = [[Interface\Vehicles\UI-Vehicles-Button-Exit-Down]],
pushedTexCoord = { 0.140625, 0.859375, 0.140625, 0.859375 },
}
end
end

function VehicleBar:GetDefaults()
return {
point = 'CENTER',
x = -244,
y = 0,
numButtons = #buttons
}
end

function VehicleBar:AddButton(i)
local b = buttons[i]
b:SetParent(self.header)
b:Show()

self.buttons[i] = b
end

function VehicleBar:RemoveButton(i)
local b = self.buttons[i]
b:SetParent(nil)
b:Hide()

self.buttons[i] = nil
end

function VehicleBar:GetShowStates()
return '[target=vehicle,exists]show;hide'
end
Something went wrong with that request. Please try again.