⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 guishapenamehud.cc

📁 五行MMORPG引擎系统V1.0
💻 CC
📖 第 1 页 / 共 2 页
字号:
//-----------------------------------------------------------------------------
// Torque Game Engine
// Copyright (C) GarageGames.com, Inc.
//-----------------------------------------------------------------------------

#include "dgl/dgl.h"
#include "dgl/gNewFont.h"
#include "gui/core/guiControl.h"
#include "gui/core/guiTSControl.h"
#include "console/consoleTypes.h"
#include "sceneGraph/sceneGraph.h"
#include "game/shapeBase.h"
#include "game/gameConnection.h"

#ifdef TGE_RPG
#include "game/gameTSCtrl.h"
#include "rpg/gobjects/RPGBase.h"
#endif

//----------------------------------------------------------------------------
/// Displays name & damage above shape objects.
///
/// This control displays the name and damage value of all named
/// ShapeBase objects on the client.  The name and damage of objects
/// within the control's display area are overlayed above the object.
///
/// This GUI control must be a child of a TSControl, and a server connection
/// and control object must be present.
///
/// This is a stand-alone control and relies only on the standard base GuiControl.
class GuiShapeNameHud : public GuiControl 
{
   typedef GuiControl Parent;

   // field data
   ColorF   mFillColor;
   ColorF   mFrameColor;
   ColorF   mTextColor;

   F32      mVerticalOffset;
   F32      mDistanceFade;
   bool     mShowFrame;
   bool     mShowFill;

#ifdef TGE_RPG
	enum
	{
		TTN_NULL=-1,
		TTN_TASKTONPC,
		TTN_TASKNPC,
		TTN_RUNNINGTASK,
		TTN_AMOUNT
	};
	STE				m_arFileNameTasks[TTN_AMOUNT];
	TextureHandle	m_arTexTasks[TTN_AMOUNT];
	U32				m_nTaskState;
#endif

protected:
   void drawName( Point2I offset, const char *buf, F32 opacity);

public:
   GuiShapeNameHud();

#ifdef TGE_RPG
	void getCursor(GuiCursor *&cursor, bool &visible, const GuiEvent &event);
	bool onWake();
#endif

	//RPG movement
	//void onMouseMove(const GuiEvent& event);
	//void onMouseDragged(const GuiEvent& event);
	void onMouseDown(const GuiEvent& event);
   void onMouseUp(const GuiEvent & event);

      //void onMouseEnter(const GuiEvent & event);
      //void onMouseLeave(const GuiEvent & event);
      void onRightMouseDown(const GuiEvent & event);
      void onRightMouseUp(const GuiEvent & event);


   // GuiControl
   virtual void onRender(Point2I offset, const RectI &updateRect);

   static void initPersistFields();
   DECLARE_CONOBJECT( GuiShapeNameHud );
};


//-----------------------------------------------------------------------------

IMPLEMENT_CONOBJECT(GuiShapeNameHud);

/// Default distance for object's information to be displayed.
static const F32 cDefaultVisibleDistance = 500.0f;

GuiShapeNameHud::GuiShapeNameHud()
{
   mFillColor.set( 0.25, 0.25, 0.25, 0.25 );
   mFrameColor.set( 0, 1, 0, 1 );
   mTextColor.set( 0, 1, 0, 1 );
   mShowFrame = mShowFill = true;
   mVerticalOffset = 0.5;
   mDistanceFade = 0.1;

#ifdef TGE_RPG
	m_nTaskState = TTN_NULL;

	m_arFileNameTasks[TTN_TASKTONPC]		= StringTable->insert("ui/img/taskToNpc");
	m_arFileNameTasks[TTN_TASKNPC]		= StringTable->insert("ui/img/taskNpc");
	m_arFileNameTasks[TTN_RUNNINGTASK]	= StringTable->insert("ui/img/runningTask");
#endif
}

void GuiShapeNameHud::initPersistFields()
{
   Parent::initPersistFields();
   addGroup("Colors");
   addField( "fillColor",  TypeColorF, Offset( mFillColor, GuiShapeNameHud ) );
   addField( "frameColor", TypeColorF, Offset( mFrameColor, GuiShapeNameHud ) );
   addField( "textColor",  TypeColorF, Offset( mTextColor, GuiShapeNameHud ) );
   endGroup("Colors");

   addGroup("Misc");
   addField( "showFill",   TypeBool, Offset( mShowFill, GuiShapeNameHud ) );
   addField( "showFrame",  TypeBool, Offset( mShowFrame, GuiShapeNameHud ) );
   addField( "verticalOffset", TypeF32, Offset( mVerticalOffset, GuiShapeNameHud ) );
   addField( "distanceFade", TypeF32, Offset( mDistanceFade, GuiShapeNameHud ) );

#ifdef TGE_RPG
   addField( "arFilenameTasks", TypeFilename, Offset(m_arFileNameTasks , GuiShapeNameHud ),TTN_AMOUNT );
#endif
   endGroup("Misc");
}


#ifdef TGE_RPG
void GuiShapeNameHud::getCursor(GuiCursor *&cursor, bool &visible, const GuiEvent &event)
{
	GuiControl* parent = getParent();
	if (parent)
		parent->getCursor(cursor, visible, event);
}


bool GuiShapeNameHud::onWake()
{
	if(!Parent::onWake())
		return false;
	for(U32 n=0; n<TTN_AMOUNT; n++)
		m_arTexTasks[n] = TextureHandle(m_arFileNameTasks[n],BitmapTexture);
	return true;
}

#endif

//----------------------------------------------------------------------------
/// RPG movement
//void GuiShapeNameHud::onMouseMove(const GuiEvent &event)
//{   
//	GuiTSCtrl* parent = dynamic_cast<GuiTSCtrl*>(getParent());
//	if (parent)
//		parent->onMouseMove(event);
//}

//void GuiShapeNameHud::onMouseDragged(const GuiEvent &event)
//{   
//	GuiTSCtrl* parent = dynamic_cast<GuiTSCtrl*>(getParent());
//	if (parent)
//		parent->onMouseDragged(event);
//}

void GuiShapeNameHud::onMouseDown(const GuiEvent &event)
{   
	GuiTSCtrl* parent = dynamic_cast<GuiTSCtrl*>(getParent());
	if (parent)
		parent->onMouseDown(event);
}


void GuiShapeNameHud::onMouseUp(const GuiEvent &event)
{   
	GuiTSCtrl* parent = dynamic_cast<GuiTSCtrl*>(getParent());
	if (parent)
		parent->onMouseUp(event);
}


void GuiShapeNameHud::onRightMouseDown(const GuiEvent &event)
{   
	//Let's let the parent execute its event handling (if any)   
	GuiTSCtrl* parent = dynamic_cast<GuiTSCtrl*>(getParent());
	if (parent)
		parent->onRightMouseDown(event);
}


void GuiShapeNameHud::onRightMouseUp(const GuiEvent &event)
{   
	//Let's let the parent execute its event handling (if any)   
	GuiTSCtrl* parent = dynamic_cast<GuiTSCtrl*>(getParent());
	if (parent)
		parent->onRightMouseUp(event);
}


#ifdef TGE_RPG
static void findObjectsCallback(SceneObject* obj, void * val)
{
	Vector<SceneObject*> * list = (Vector<SceneObject*>*)val;
	list->push_back(obj);
}
#endif


#ifdef TGE_RPG
//----------------------------------------------------------------------------
/// Core rendering method for this control.
///
/// This method scans through all the current client ShapeBase objects.
/// If one is named, it displays the name and damage information for it.
///
/// Information is offset from the center of the object's bounding box,
/// unless the object is a PlayerObjectType, in which case the eye point
/// is used.
///
/// @param   updateRect   Extents of control.
void GuiShapeNameHud::onRender( Point2I, const RectI &updateRect)
{
   // Background fill first
   if (mShowFill)
      dglDrawRectFill(updateRect, mFillColor);

   // Must be in a TS Control
   GuiTSCtrl *parent = dynamic_cast<GuiTSCtrl*>(getParent());
   if (!parent) return;

   // Must have a connection and control object
   GameConnection* conn = GameConnection::getConnectionToServer();
   if (!conn)
      return;

   ShapeBase* control = conn->getControlObject();
   if (!control)
      return;

   // Get control camera info
   MatrixF cam;
   Point3F camPos;
   VectorF camDir;
   conn->getControlCameraTransform(0,&cam);
   cam.getColumn(3, &camPos);
   cam.getColumn(1, &camDir);

   F32 camFov;
   conn->getControlCameraFov(&camFov);
   camFov = mDegToRad(camFov) / 2;

   // Visible distance info & name fading
   F32 visDistance = gClientSceneGraph->getVisibleDistance();
   F32 visDistanceSqr = visDistance * visDistance;
   F32 fadeDistance = visDistance * mDistanceFade;

   // Collision info. We're going to be running LOS tests and we
   // don't want to collide with the control object.
   static U32 losMask = TerrainObjectType | InteriorObjectType | ShapeBaseObjectType;
   control->disableCollision();

   // All ghosted objects are added to the server connection group,
   // so we can find all the shape base objects by iterating through
   // our current connection.


		ShapeBase*	shape;
		RPGBase*		pRPGBase;

		for(U32 i = 0; i < GameTSCtrl::ms_arGameBases.size(); i++)
		{
			shape = static_cast<ShapeBase*>(GameTSCtrl::ms_arGameBases[i]);
			if(shape == NULL)
				continue;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -