浏览代码

Allow the gui to render for both vehicles and vehicle-mounted players.

yourarcade 9 年之前
父节点
当前提交
213b7020a3
共有 1 个文件被更改,包括 13 次插入6 次删除
  1. 13 6
      Engine/source/T3D/vehicles/guiSpeedometer.cpp

+ 13 - 6
Engine/source/T3D/vehicles/guiSpeedometer.cpp

@@ -147,22 +147,29 @@ void GuiSpeedometerHud::initPersistFields()
 //-----------------------------------------------------------------------------
 /**
    Gui onRender method.
-   Renders a health bar with filled background and border.
+   Renders an analog speedometer needle over a specified bitmap background.
 */
 void GuiSpeedometerHud::onRender(Point2I offset, const RectI &updateRect)
 {
-   // Must have a connection and player control object
+   // Must have a connection
    GameConnection* conn = GameConnection::getConnectionToServer();
    if (!conn)
       return;
-   Vehicle* control = dynamic_cast<Vehicle*>(conn->getControlObject());
-   if (!control)
-      return;
+
+   // Requires either a vehicle control object or a vehicle-mounted player		
+   Vehicle* vehicle = dynamic_cast<Vehicle*>(conn->getControlObject());
+   if(!vehicle){
+      Player * player = dynamic_cast<Player*>(conn->getControlObject());
+      if(!player) return;
+      if (!player->isMounted()) return;
+      vehicle = dynamic_cast<Vehicle*>(player->getObjectMount());
+      if(!vehicle) return;
+   }
 
    Parent::onRender(offset,updateRect);
 
    // Use the vehicle's velocity as its speed...
-   mSpeed = control->getVelocity().len();
+   mSpeed = vehicle->getVelocity().len();
    if (mSpeed > mMaxSpeed)
       mSpeed = mMaxSpeed;