📄 consolecommand.cpp
字号:
//--------------------------------------------------
// Desc: 控制台命令解释器
// Author: artsylee/2007.3.23
//--------------------------------------------------
#include "ConsoleCommand.h"
#include "Common.h"
#include "NodeManager.h"
#include "GNode.h"
#include "NodeAdjust.h"
#include "Player.h"
#include "Character.h"
#include "GameCommon.h"
extern CCharacter player;
extern CNodeAdjust g_NodeAdjust;
extern CNodeManager g_NodeManager;
CCommand::CCommand()
{
}
CCommand::~CCommand()
{
m_ComMap.clear();
m_ExplainMap.clear();
}
bool CCommand::LoadCommand(const char *pFileName)
{
if(pFileName == NULL || pFileName[0] == 0)
{
return false;
}
FILE * fp = fopen(pFileName, "r");
if(!fp)
{
return false;
}
char *TOKEN = "#";
char *temp, szInput[2048];
string strcom;
string strexp;
int CommandIndex = 0;
while(!feof(fp))
{
fgets(szInput, 2048, fp);
if(szInput[0] != '#')
{
szInput[0] = 0;
continue;
}
temp = szInput;
++temp;
strcom = strtok(temp, TOKEN);
strexp = strtok(0, TOKEN);
m_ComMap.insert(map<string, int>::value_type(strcom, CommandIndex));
m_ExplainMap.insert(map<string, string>::value_type(strcom, strexp));
CommandIndex++;
}
fclose(fp);
return true;
}
bool CCommand::CreateConsole(void)
{
m_Console.CreateConsole(false);
m_Console.Print("----------------------------------------");
m_Console.Print(" ASEngine游戏控制台");
m_Console.Print("----------------------------------------");
m_Console.Print("---命令列表COMMANDS---");
char szInput[256];
map<string, int>::iterator itor = m_ComMap.begin();
while(itor!=m_ComMap.end())
{
strcpy(szInput, ((*itor).first).c_str());
m_Console.Print(szInput);
itor++;
}
m_Console.Print("----------------------");
m_Console.Print("提示: 输入 \"command ?\" 查看命令的使用说明.");
m_Console.Print("HINT: type \"command ?\" for command informations.");
return true;
}
void CCommand::OpenConsole(void)
{
m_Console.ActiveConsole();
}
void CCommand::Update()
{
//--------------------------------------------------
// 当前Direct input只有在激活状态下接受输入, 因此运行
// 控制台时无法用Dinput获取输入信息.
//--------------------------------------------------
if(GetAsyncKeyState(VK_F3) & 0x8000)
{
// m_Console.ActiveMainWindow();
m_Console.ShowConsole();
}
if(g_stInputInfo.KeyValue == DIK_F5)
{
m_Console.HideConsole();
}
if(m_Console.IsInput())
{
char szInput[256];
memset(szInput, 0, sizeof(szInput));
m_Console.GetInput(szInput);
m_Console.ClearInput();
char szString[5][256];
memset(szString, 0, sizeof(szString));
char *spes = " ,\t\r\n";
char *pTemp = NULL;
int ItemNum = 0;
pTemp = strtok(szInput, spes);
while(pTemp != NULL && ItemNum < 5)
{
strcpy(szString[ItemNum], pTemp);
ItemNum++;
pTemp = strtok(NULL, spes);
}
int comIndex = 0;
bool bBack = false;
map<string, int>::iterator itor = m_ComMap.find(szString[0]);
if(itor != m_ComMap.end())
{
comIndex = (*itor).second;
if(strcmp(szString[1], "?") == 0)
{
map<string, string>::iterator infoitor = m_ExplainMap.find(szString[0]);
if(infoitor != m_ExplainMap.end())
{
m_Console.Print("----------------------------------------");
char szExplain[2048];
strcpy(szExplain, ((*infoitor).second).c_str());
szExplain[2047] = 0;
char *clip = "/";
char *pExp = strtok(szExplain, clip);
while(pExp != NULL)
{
m_Console.Print(pExp);
pExp = strtok(NULL, clip);
}
m_Console.Print("----------------------------------------");
}
}
else
{
switch(comIndex)
{
case 0: // Show all nodes' name
{
m_Console.Print("Nodes in this scene");
for(unsigned i=0; i<g_NodeManager.GetSize(); i++)
{
GNode* pNode = g_NodeManager.GetNodeByPos(i);
if(pNode)
{
char szName[256];
pNode->GetName(szName);
m_Console.Print("Node name: %s, type: %s", szName, pNode->GetNodeTypeString());
}
}
}
break;
case 1: // node adjust tool
{
if(strcmp(szString[1], "off")==0)
{
if(IsGUIVisual(EDIT_WINDOW))
{
g_NodeAdjust.CloseEditor();
m_Console.Print("NAT tool has been disable!");
}
else
{
m_Console.Print("NAT tool Is off!");
}
}
else
{
if(!IsGUIVisual(EDIT_WINDOW))
{
g_NodeAdjust.OpenEditor();
bBack = true;
}
else
{
m_Console.Print("NAT tool Is open!");
}
}
}
break;
case 2: // back to game
{
bBack = true;
}
break;
case 3: // change camera
{
int num = atoi(szString[1]);
player.SetCamera(num);
bBack = true;
}
break;
case 4: // change node position
{
GNode* pNode = g_NodeManager.GetNode(szString[1]);
if(pNode)
{
char *p = NULL;
float x = (float)strtod(szString[2], &p);
float y = (float)strtod(szString[3], &p);
float z = (float)strtod(szString[4], &p);
if(x==0.0f || y==0.0f || z==0.0f)
{
m_Console.Print("非法参数!");
}
else
{
char NodeName[256];
pNode->GetName(NodeName);
pNode->SetPosition(D3DXVECTOR3(x, y, z));
m_Console.Print("已改变节点[%s]的位置(%0.2f, %0.2f, %0.2f)", NodeName, x, y, z);
}
}
else m_Console.Print("Invalid node name!");
}
break;
}
}
}
else
{
m_Console.Print("Invalid Command!");
}
if(bBack) m_Console.ActiveMainWindow();
else m_Console.ActiveConsole();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -