changeset 159:799c6ea9da7b

added vehicle exit floater some fixes for vehicle exit button on main bars still some lingering settexcoords issues on the vehicle exit icon
author Flick <flickerstreak@gmail.com>
date Mon, 29 Jun 2009 17:43:16 +0000
parents d2f289c3bae6
children caec78119a17
files classes/ActionButton.lua classes/Bar.lua classes/VehicleExitButton.lua classes/classes.xml locale/enUS.lua modules/VehicleExit.lua modules/modules.xml
diffstat 7 files changed, 287 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/classes/ActionButton.lua	Sat Jun 13 00:13:52 2009 +0000
+++ b/classes/ActionButton.lua	Mon Jun 29 17:43:16 2009 +0000
@@ -259,13 +259,19 @@
 function Action:InstallVehicle()
   local f = self:GetFrame()
   if self.idx == 7 and self:GetBarConfig().vehicle then
-    -- install vehicle-exit button on 7th button (only)
-    f:SetAttribute("_childupdate-vehicle", _childupdate_vehicleExit)
-    f:SetAttribute("macrotext","/run VehicleExit()")
-    self:GetBar():GetFrame().ShowVehicleExit = function(bar,show)
-      self:ShowVehicleExit(show)
+    if not self.vehicleInstalled then
+      self.vehicleInstalled = true
+      -- install vehicle-exit button on 7th button (only)
+      f:SetAttribute("_childupdate-vehicle", _childupdate_vehicleExit)
+      f:SetAttribute("macrotext","/run VehicleExit()")
+      self:GetBar():GetFrame().ShowVehicleExit = function(bar,show)
+        self:ShowVehicleExit(show)
+      end
     end
-  else
+    -- setscale blows away tex coords
+    self:UpdateIcon()
+  elseif self.vehicleInstalled then
+    self.vehicleInstalled = false
     f:SetAttribute("_childupdate-vehicle",nil)
     f:SetAttribute("macrotext",nil)
   end
@@ -375,7 +381,7 @@
   if self.vehicleExitMode then
     texture = "Interface\\Vehicles\\UI-Vehicles-Button-Exit-Up"
     icon:SetTexCoord(0.140625, 0.859375, 0.140625, 0.859375)
-    icon:SetVertexColor(1,0,0)
+    icon:SetVertexColor(1,1,1)
   else
     icon:SetTexCoord(0,1,0,1)
   end
@@ -389,11 +395,7 @@
     icon:Hide()
     self.frames.cooldown:Hide()
     self.rangeTimer = nil
-    if self.vehicleExitMode then
-      f:SetNormalTexture("Interface\\Buttons\\UI-Quickslot2")
-    else
-      f:SetNormalTexture("Interface\\Buttons\\UI-Quickslot")
-    end
+    f:SetNormalTexture("Interface\\Buttons\\UI-Quickslot")
   end
 end
 
@@ -455,15 +457,34 @@
 
 function Action:UpdateUsable()
   local isUsable, notEnoughMana = IsUsableAction(self.actionID)
-  if isUsable or self.vehicleExitMode then
-    self.frames.icon:SetVertexColor(1.0, 1.0, 1.0)
-    self.frames.normalTexture:SetVertexColor(1.0, 1.0, 1.0)
+  local noRange = IsActionInRange(self.actionID) == 0
+
+  isUsable = self.vehicleExitMode or (isUsable and not noRange)
+
+  if isUsable then
+    if self.usableStatus ~= "usable" then
+      self.frames.icon:SetVertexColor(1.0, 1.0, 1.0)
+      self.frames.normalTexture:SetVertexColor(1.0, 1.0, 1.0)
+      self.usableStatus = "usable"
+    end
+  elseif noRange then
+    if self.usableStatus ~= "norange" then
+      self.frames.icon:SetVertexColor(1.0,0.1,0.1)
+      self.frames.normalTexture:SetVertexColor(1.0, 1.0, 1.0)
+      self.usableStatus = "norange"
+    end
   elseif notEnoughMana then
-    self.frames.icon:SetVertexColor(0.5, 0.5, 1.0)
-    self.frames.normalTexture:SetVertexColor(0.5, 0.5, 1.0)
+    if self.usableStatus ~= "oom" then
+      self.frames.icon:SetVertexColor(0.5, 0.5, 1.0)
+      self.frames.normalTexture:SetVertexColor(0.5, 0.5, 1.0)
+      self.usableStatus = "oom"
+    end
   else
-    self.frames.icon:SetVertexColor(0.4, 0.4, 0.4)
-    self.frames.normalTexture:SetVertexColor(1.0, 1.0, 1.0)
+    if self.usableStatus ~= "unusable" then
+      self.frames.icon:SetVertexColor(0.4, 0.4, 0.4)
+      self.frames.normalTexture:SetVertexColor(1.0, 1.0, 1.0)
+      self.usableStatus = "unusable"
+    end
   end
 end
 
@@ -513,13 +534,7 @@
     rangeTimer = rangeTimer - elapsed
     self.rangeTimer = rangeTimer
     if rangeTimer <= 0 then
-      if self.vehicleExitMode then
-        self.frames.icon:SetVertexColor(1,1,1)
-      elseif IsActionInRange(self.actionID) == 0 then
-        self.frames.icon:SetVertexColor(1.0,0.1,0.1)
-      else
-        self:UpdateUsable()
-      end
+      self:UpdateUsable()
       self.rangeTimer = TOOLTIP_UPDATE_TIME
     end
   end
--- a/classes/Bar.lua	Sat Jun 13 00:13:52 2009 +0000
+++ b/classes/Bar.lua	Mon Jun 29 17:43:16 2009 +0000
@@ -115,7 +115,7 @@
 
 local _onstate_unitexists = -- function( self, stateid, newstate )
 [[
-  unithide = not newstate
+  unithide = not newstate or newstate == "hide"
 ]] .. _reaction_refresh
 
 local _onclick =  -- function( self, button, down )
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/classes/VehicleExitButton.lua	Mon Jun 29 17:43:16 2009 +0000
@@ -0,0 +1,64 @@
+local ReAction = ReAction
+local format = string.format
+
+ReAction:UpdateRevision("$Revision: 154 $")
+
+--
+-- VExitButton Button class
+--
+local Super = ReAction.Button
+local VExitButton = setmetatable( { }, { __index = Super } )
+ReAction.Button.VehicleExit = VExitButton
+
+function VExitButton:New( idx, config, bar )
+  local name = format("ReAction_%s_VehicleExit_%d",bar:GetName(),idx)
+ 
+  self = Super.New(self, name, config, bar, idx, "SecureFrameTemplate, ActionButtonTemplate", "Button")
+
+  -- frame setup
+  local f = self:GetFrame()
+  self.frames.icon:SetTexture("Interface\\Vehicles\\UI-Vehicles-Button-Exit-Up")
+  self.frames.icon:SetTexCoord(0.140625, 0.859375, 0.140625, 0.859375)
+
+  -- attribute setup
+  -- (none)
+
+  -- non secure scripts
+  f:SetScript("OnClick", VehicleExit)
+  f:SetScript("OnEnter", function(frame) GameTooltip_AddNewbieTip(frame, LEAVE_VEHICLE, 1.0, 1.0, 1.0, nil) end)
+  f:SetScript("OnLeave", GameTooltip_Hide)
+  f:SetScript("OnEvent", function(frame, evt, ...) self:OnEvent(evt,...) end)
+
+  -- event registration
+  f:EnableMouse(true)
+  f:RegisterForClicks("AnyUp")
+  f:RegisterEvent("UPDATE_BINDINGS")
+
+  -- attach to skinner
+  bar:SkinButton(self)
+
+  self:Refresh()
+  self:UpdateHotkey()
+
+  return self
+end
+
+function VExitButton:GetActionID()
+  return 1
+end
+
+function VExitButton:Refresh()
+  Super.Refresh(self)
+  -- it seems that setscale kills the texcoord, have to refresh it
+  self.frames.icon:SetTexCoord(0.140625, 0.859375, 0.140625, 0.859375) 
+end
+
+function VExitButton:OnEvent(event, ...)
+  if self[event] then
+    self[event](self, event, ...)
+  end
+end
+
+function VExitButton:UPDATE_BINDINGS()
+  self:UpdateHotkey()
+end
--- a/classes/classes.xml	Sat Jun 13 00:13:52 2009 +0000
+++ b/classes/classes.xml	Mon Jun 29 17:43:16 2009 +0000
@@ -10,5 +10,6 @@
 <Script file="PetActionButton.lua"/>
 <Script file="StanceButton.lua"/>
 <Script file="BagButton.lua"/>
+<Script file="VehicleExitButton.lua"/>
 
 </Ui>
\ No newline at end of file
--- a/locale/enUS.lua	Sat Jun 13 00:13:52 2009 +0000
+++ b/locale/enUS.lua	Mon Jun 29 17:43:16 2009 +0000
@@ -194,6 +194,12 @@
 -- Bag
 "Bag Bar",
 
+-- VehicleExit
+"Exit Vehicle Floater",
+"Exit Vehicle",
+"Show only when passenger",
+"Only show the button when riding as a passenger in a vehicle (no vehicle controls)",
+
 -- ConfigUI
 "Center",
 "Left",
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/VehicleExit.lua	Mon Jun 29 17:43:16 2009 +0000
@@ -0,0 +1,173 @@
+--[[
+  ReAction Vehicle Exit button module
+
+  The button module implements a single button which you can use
+  to exit a vehicle that doesn't have controls (replacement for
+  MainMenuBarLeaveVehicleButton).
+
+--]]
+
+-- local imports
+local ReAction = ReAction
+local L = ReAction.L
+
+ReAction:UpdateRevision("$Revision: 200 $")
+
+-- module declaration
+local moduleID = "VehicleExit"
+local module = ReAction:NewModule( moduleID )
+
+-- Button class
+local Button = ReAction.Button.VehicleExit
+
+-- module methods
+function module:OnInitialize()
+  self.db = ReAction.db:RegisterNamespace( moduleID,
+    { 
+      profile = {
+        buttons = { }
+      }
+    }
+  )
+  self.registered = { }
+  self.buttons = { }
+
+  ReAction:RegisterBarOptionGenerator(self, "GetBarOptions")
+
+  ReAction.RegisterCallback(self, "OnCreateBar")
+  ReAction.RegisterCallback(self, "OnDestroyBar")
+  ReAction.RegisterCallback(self, "OnRefreshBar")
+  ReAction.RegisterCallback(self, "OnEraseBar")
+  ReAction.RegisterCallback(self, "OnRenameBar")
+end
+
+function module:OnEnable()
+  ReAction:RegisterBarType(L["Exit Vehicle Floater"], 
+    { 
+      type = moduleID ,
+      defaultButtonSize = 36,
+      defaultBarRows = 1,
+      defaultBarCols = 1,
+      defaultBarSpacing = 3
+    })
+end
+
+function module:OnDisable()
+  ReAction:UnregisterBarType(L["Exit Vehicle Floater"])
+end
+
+function module:OnCreateBar(event, bar, name)
+  if bar.config.type == moduleID then
+    self:OnRefreshBar(event, bar, name)
+  end
+end
+
+function module:OnRefreshBar(event, bar, name)
+  if bar.config.type == moduleID then
+    local profile = self.db.profile
+    if profile.buttons[name] == nil then
+      profile.buttons[name] = {}
+    end
+    local btnCfg = profile.buttons[name]
+
+    if profile.buttons[name] == nil then
+      profile.buttons[name] = { }
+    end
+    if self.buttons[bar] == nil then
+      local success, r = pcall(Button.New, Button, 1, profile.buttons[name], bar)
+      if success and r then
+        self.buttons[bar] = r
+        bar:AddButton(1,r)
+      end
+    else
+      self.buttons[bar]:Refresh()
+    end
+    bar:ClipNButtons(1)
+    self:UpdateRegistration(bar)
+  end
+end
+
+function module:OnDestroyBar(event, bar, name)
+  if self.buttons[bar] then
+    self.buttons[bar]:Destroy()
+    self.buttons[bar] = nil
+  end
+end
+
+function module:OnEraseBar(event, bar, name)
+  self.db.profile.buttons[name] = nil
+end
+
+function module:OnRenameBar(event, bar, oldname, newname)
+  local b = self.db.profile.buttons
+  b[newname], b[oldname] = b[oldname], nil
+end
+
+
+function module:UpdateRegistration(bar)
+  -- auto show/hide when on a vehicle
+  local config = self.db.profile.buttons[bar:GetName()]
+  local f = bar:GetFrame()
+  if config.withControls then
+    if bar.vehicleExitStateRegistered then
+      UnregisterStateDriver(f, "unitexists")
+      bar.vehicleExitStateRegistered = false
+    end
+    bar:RegisterUnitWatch("vehicle",true)
+  else
+    bar:RegisterUnitWatch("vehicle",false)
+    if not bar.vehicleExitStateRegistered then
+      f:SetAttribute("unit","vehicle")
+      RegisterStateDriver(f, "unitexists", "[target=vehicle,exists,nobonusbar:5] show; hide") -- spoof onstate-unitexists
+      bar.vehicleExitStateRegistered = true
+    end
+  end
+end
+
+---- Options ----
+local Handler = { }
+local meta = { __index = Handler }
+
+function Handler:New(bar)
+  return setmetatable(
+    {
+      bar = bar
+    }, meta)
+end
+
+function Handler:GetConfig()
+  return module.db.profile.buttons[self.bar:GetName()]
+end
+
+function Handler:GetPassengerOnly()
+  return not self:GetConfig().withControls
+end
+
+function Handler:SetPassengerOnly(info, value)
+  self:GetConfig().withControls = not value
+  module:UpdateRegistration(self.bar)
+end
+
+
+function module:GetBarOptions(bar)
+  if bar.config.type == moduleID then
+    return {
+      type = "group",
+      name = L["Exit Vehicle"],
+      handler = Handler:New(bar),
+      args = {
+        passengerOnly = {
+          name = L["Show only when passenger"],
+          desc = L["Only show the button when riding as a passenger in a vehicle (no vehicle controls)"],
+          order = 2,
+          width = "double",
+          type = "toggle",
+          get = "GetPassengerOnly",
+          set = "SetPassengerOnly",
+        },
+      }
+    }
+  end
+end
+
+
--- a/modules/modules.xml	Sat Jun 13 00:13:52 2009 +0000
+++ b/modules/modules.xml	Mon Jun 29 17:43:16 2009 +0000
@@ -10,5 +10,6 @@
 <Script file="PetAction.lua"/>
 <Script file="Stance.lua"/>
 <Script file="Bag.lua"/>
+<Script file="VehicleExit.lua"/>
 
 </Ui>
\ No newline at end of file