SDK中的任务跟踪代码简单注释

本文介绍了一款游戏中的任务跟踪HUD元素设计与实现细节,包括类定义、构造函数、消息处理函数等。通过CHudTaskList类实现了任务列表的显示与更新机制。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 hud_tasklist.h

#ifndef HUD_TASKLIST_H              //任务跟踪列表头文件宏定义
#define HUD_TASKLIST_H

#define TASKLIST_MAX_TASKS 4        //最大任务记录条数为4
#define TASKLIST_TASK_INACTIVE 0      //没有活动的任务数
#define TASKLIST_TASK_COMPLETE 1      //完成的任务数
#define TASKLIST_TASK_LOWPRIORITY 2     //底优先权
#define TASKLIST_TASK_MEDPRIORITY 3     //中级优先权
#define TASKLIST_TASK_HIGHPRIORITY 4    //高级优先权

#define TASKLINE_NUM_FLASHES 8.0f      //任务跟踪器数目刷新时率
#define TASKLINE_FLASH_TIME 5.0f      //任务跟踪器刷新时率
#define TASKLINE_FADE_TIME 1.0f       //任务跟踪器提示淡化时率

class CHudTaskList : public CHudElement , public vgui::Panel
{
DECLARE_CLASS_SIMPLE( CHudTaskList, vgui::Panel );      
//全局声明该类

public:
CHudTaskList( 
const char *pElementName ); //The constructor.构造函数
void Init( void ); //This gets called when the element is created.初始化
void VidInit( void ); //Same as above, this may only gets called when you load up the map for the first time.同上,但仅在地图加载时调用
void Reset(); //This gets called when you reset the HUD.重绘HUD
void Paint( void ); //This gets called every frame, to display the element on the screen!绘制
// void OnThink(void); //This gets called also almost every frame, so we can update things often.实时更新
void MsgFunc_TaskList( bf_read &msg );//消息函数

private:
// CHudTexture *m_pIcon;   // Icon texture reference头标指针
wchar_t   m_pText[TASKLIST_MAX_TASKS][256]; // Unicode text buffer字符缓存
int    m_iPriority[TASKLIST_MAX_TASKS];   // 0=inactive, 1=complete, 2=low, 3=medium, 4=high当前状态的管理数组
float   m_flStartTime[TASKLIST_MAX_TASKS]; // When the message was recevied收到消息的时间
float   m_flDuration[TASKLIST_MAX_TASKS]; // Duration of the message持续时间
vgui::HFont m_hSmallFont, m_hLargeFont;//字体定义

protected:
virtual void ApplySchemeSettings( vgui::IScheme *pScheme );//配置加载函数

private:
   
// vgui::Label *m_pNameLabel; //The vgui label that will hold our name.标签名称
   vgui::HScheme scheme;     //The Scheme object to hold our scheme info.Scheme对象信息
}
;
#endif


hud_tasklist.cpp
//========= Copyright ? 1996-2004, Valve LLC, All rights reserved. ============
//
// Purpose: Task List element
//
//=============================================================================

#include 
"cbase.h"
#include 
"hudelement.h"
#include 
"hud_macros.h"
#include 
"iclientmode.h"
#include 
"view.h"

using namespace vgui;

#include 
<vgui_controls/Panel.h>
#include 
<vgui_controls/Frame.h>
#include 
<vgui/IScheme.h>
#include 
<vgui/ISurface.h>
#include 
<vgui/ILocalize.h>//本地化文件头

using namespace vgui;

#include 
"c_baseplayer.h"
#include 
"hud_tasklist.h"

DECLARE_HUDELEMENT( CHudTaskList );
//声明HUD元素对象
DECLARE_HUD_MESSAGE( CHudTaskList, TaskList );//声明HUD消息对象

// ===================================================================

//构造函数
CHudTaskList::CHudTaskList( const char *pElementName ) : CHudElement( pElementName ), vgui::Panel( NULL, "HudTaskList" )
{
DevMsg (
2"CHudTaskList::CHudTaskList - constructor sent %s ", pElementName);//调试函数
scheme = vgui::scheme()->LoadSchemeFromFile("resource/ClientScheme.res""ClientScheme");//配置文件
SetScheme(scheme); // Here we load up our scheme and set this element to use it. Using a different scheme than ClientScheme doesn't work right off the bat anyways, so... :)加载其他的配置文件
vgui::Panel *pParent = g_pClientMode->GetViewport();//获取客户端视角的panel对象指针
SetParent( pParent ); // Our parent is the screen itself.我们使用当前视角的panel
SetHiddenBits( 0 ); // Never Hidden. You could make it so that it gets hidden when health is, with HIDEHUD_HEALTH, or any other combination of HIDEHUD flags.设置为从不隐藏
SetBgColor(Color( 0,0,0,100 ));//设置背景色
SetPaintBackgroundEnabled( true );//使用背景色
SetPaintBackgroundType (2); // Rounded corner box使用圆角长方形
}
 

//初始化
void CHudTaskList::Init( void )
{
HOOK_HUD_MESSAGE( CHudTaskList, TaskList );
//HUD消息钩子
DevMsg (2"CHudTaskList::Init " );//调试信息
Reset();//重绘
}


//重绘
void CHudTaskList::Reset( void )
{
DevMsg (
2"CHudTaskList::Reset (clearing out list) " );//调试信息
for (int i=0; i<TASKLIST_MAX_TASKS; i++
{
   m_pText[i][
0= '

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值