📄 trackerdialog.cpp
字号:
{
OnQuit();
}
else if (!stricmp(command, "Open"))
{
Activate();
}
else if (!stricmp(command, "Minimize"))
{
OnClose();
}
else if (!stricmp(command, "ServerBrowser"))
{
OpenServerBrowser();
}
else if (!stricmp(command, "OpenOptionsDialog"))
{
OpenOptionDialog();
}
else if (!stricmp(command, "About"))
{
OpenAboutDialog();
}
else
{
BaseClass::OnCommand(command);
}
}
//-----------------------------------------------------------------------------
// Purpose: Called when the X button is hit, minimizes tracker to icon
//-----------------------------------------------------------------------------
void CTrackerDialog::OnClose()
{
SetVisible(false);
}
//-----------------------------------------------------------------------------
// Purpose: Closes the app
//-----------------------------------------------------------------------------
void CTrackerDialog::OnQuit()
{
// make us disappear
BaseClass::OnClose();
}
//-----------------------------------------------------------------------------
// Purpose: Recalculates the buddy list
//-----------------------------------------------------------------------------
void CTrackerDialog::PerformLayout()
{
// chain back
BaseClass::PerformLayout();
// set our title
char szTitle[256];
switch (ServerSession().GetStatus())
{
case COnlineStatus::OFFLINE:
case COnlineStatus::CONNECTING:
sprintf(szTitle, "Friends - %s - offline", GetDoc()->GetUserName());
break;
case COnlineStatus::AWAY:
sprintf(szTitle, "Friends - %s - away", GetDoc()->GetUserName());
break;
case COnlineStatus::BUSY:
sprintf(szTitle, "Friends - %s - busy", GetDoc()->GetUserName());
break;
case COnlineStatus::ONLINE:
default:
sprintf(szTitle, "Friends - %s", GetDoc()->GetUserName());
}
SetTitle(szTitle, true);
//tagES
/* wchar_t unicode[256], unicodeName[64];
localize()->ConvertANSIToUnicode(GetDoc()->GetUserName(), unicodeName, sizeof( unicodeName ) / sizeof( wchar_t ));
switch (ServerSession().GetStatus())
{
case COnlineStatus::OFFLINE:
case COnlineStatus::CONNECTING:
localize()->ConstructString(unicode, sizeof( unicode ) / sizeof( wchar_t ), localize()->Find("#TrackerUI_Friends_Name_OfflineTitle"), 1, unicodeName );
break;
case COnlineStatus::AWAY:
localize()->ConstructString(unicode, sizeof( unicode ) / sizeof( wchar_t ), localize()->Find("#TrackerUI_Friends_Name_AwayTitle"), 1, unicodeName );
break;
case COnlineStatus::BUSY:
localize()->ConstructString(unicode, sizeof( unicode ) / sizeof( wchar_t ), localize()->Find("#TrackerUI_Friends_Name_BusyTitle"), 1, unicodeName );
break;
case COnlineStatus::ONLINE:
default:
localize()->ConstructString(unicode, sizeof( unicode ) / sizeof( wchar_t ), localize()->Find("#TrackerUI_Friends_Name_Title"), 1, unicodeName );
}
SetTitle(unicode, true);
*/
// check to see if we've changed status
if (m_bOnline != ServerSession().IsConnectedToServer())
{
if (!m_bOnline)
{
// we're coming online, start the transition
m_iLoginTransitionPixel = 0;
}
}
m_bOnline = ServerSession().IsConnectedToServer();
// layout buttons on this dialog
int x, y, wide, tall;
GetClientArea(x, y, wide, tall);
// put menu buttons below panel
int addFriendsRightSize = x + 0;
if (m_pTrackerButton->IsVisible())
{
m_pTrackerButton->SetBounds(x, y + tall - 28, 64, 24);
addFriendsRightSize += 64;
}
// put the valve logo in the bottom right, if there is room
// size the border panel
int bottomOfButton = 32;
int x3 = 6;
int x2, y2;
m_pTrackerButton->GetPos(x2, y2);
int topOfTrackerButton = y2;
m_pBuddyListPanel->SetBounds(x3, bottomOfButton, wide, topOfTrackerButton - bottomOfButton - 4);
m_pStatePanel->SetBounds(x3, bottomOfButton, wide, topOfTrackerButton - bottomOfButton - 4);
if (ServerSession().IsConnectedToServer())
{
m_pBuddyListPanel->SetVisible(true);
m_pStatePanel->SetVisible(false);
}
else
{
m_pStatePanel->SetVisible(true);
m_pBuddyListPanel->SetVisible(false);
}
// add the pixel slide for when we change connection state
if (m_iLoginTransitionPixel > -1)
{
m_pBuddyListPanel->SetVisible(true);
m_pStatePanel->SetVisible(true);
m_pStatePanel->SetPos(x3 - m_iLoginTransitionPixel, bottomOfButton);
m_pBuddyListPanel->SetPos(x3 - m_iLoginTransitionPixel + wide, bottomOfButton);
if (ServerSession().IsConnectedToServer())
{
m_iLoginTransitionPixel++;
}
else
{
m_iLoginTransitionPixel--;
}
if (m_iLoginTransitionPixel >= wide)
{
m_iLoginTransitionPixel = -1;
}
InvalidateLayout();
}
m_pBuddyListPanel->InvalidateLayout(true);
m_pStatePanel->InvalidateLayout(true);
OpenSavedChats();
}
//-----------------------------------------------------------------------------
// Purpose: Called when tracker is fully logged in to the server
//-----------------------------------------------------------------------------
void CTrackerDialog::OnLoginOK()
{
// make sure we have all the necessary information about ourself
ServerSession().RequestUserInfoFromServer(GetDoc()->GetUserID());
// let the game know our userID
Tracker_GetRunGameEngineInterface()->SetTrackerUserID(GetDoc()->GetUserID());
}
//-----------------------------------------------------------------------------
// Purpose: Popup the any previous chats we had going (not multiuser chats)
//-----------------------------------------------------------------------------
void CTrackerDialog::OpenSavedChats()
{
static done = false;
if (done)
return;
// open any previous chats we had going
// save chat window
int numBuds = GetDoc()->GetNumberOfBuddies();
for ( int i = 0; i < numBuds; i++)
{
unsigned int buddyID = GetDoc()->GetBuddyByIndex(i);
CBuddy *buddy = GetDoc()->GetBuddy( buddyID);
if (buddy)
{
KeyValues *checkChat = buddy->Data()->FindKey("ActiveChat", NULL);
if (checkChat)
{
buddy->OpenChatDialog(false);
buddy->LoadChat();
}
}
}
done = true;
}
//-----------------------------------------------------------------------------
// Purpose: Popup the login user dialog, if it's not already up
//-----------------------------------------------------------------------------
void CTrackerDialog::OnLoginFail(int reason)
{
// determine error
const char *errorText;
bool bQuitTracker = false;
switch (reason)
{
case -1:
errorText = "#TrackerUI_ErrorIncorrectPassword";
break;
case -2:
errorText = "#TrackerUI_ErrorUserDoesntExist";
break;
case -3:
// 'account already in use' error
// wait 10 seconds then try and connect again
return;
break;
case -4:
//!! need better error
errorText = "#TrackerUI_ErrorTrackerOutOfDate";
bQuitTracker = true;
break;
default:
errorText = "#TrackerUI_ErrorPleaseInstallLatestVersion";
break;
}
// popup error dialog
MessageBox *box = new MessageBox("", errorText);
box->SetSize(320, 160);
box->SetVisible(true);
box->SetTitle("#TrackerUI_Friends_LoginErrorTitle", true);
box->AddActionSignalTarget(this);
if (bQuitTracker)
{
box->SetCommand("Quit");
}
else
{
box->SetCommand("OpenCreateNewUserDialog");
}
box->MoveToFront();
box->DoModal();
// hide self
SetVisible(false);
Tracker_GetRunGameEngineInterface()->SetTrackerUserID(0);
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTrackerDialog::ApplySchemeSettings(vgui::IScheme *pScheme)
{
BaseClass::ApplySchemeSettings(pScheme);
m_pBuddyListPanel->SetBorder(scheme()->GetBorder(GetScheme(), "ButtonDepressedBorder"));
}
//-----------------------------------------------------------------------------
// Purpose: Called when a new user is created
//-----------------------------------------------------------------------------
void CTrackerDialog::OnUserCreated(int userid, const char *password)
{
// save the current user state
MarkUserDataAsNeedsSaving();
// kill the old panel
if (m_hDialogLoginUser)
{
m_hDialogLoginUser->MarkForDeletion();
m_hDialogLoginUser = NULL;
}
surface()->SetMinimized(this->GetVPanel(), false);
// move to main logging in screen
StartTrackerWithUser(GetDoc()->GetUserID());
}
//-----------------------------------------------------------------------------
// Purpose: Called when the tracker is initialized in the game, with the current game name
//-----------------------------------------------------------------------------
void CTrackerDialog::OnActiveGameName(const char *gameName)
{
strncpy(m_szGameDir, gameName, sizeof(m_szGameDir) - 1);
// set the server state
ServerSession().SetGameInfo(m_szGameDir, m_iGameIP, m_iGamePort);
// tell the game server our id
Tracker_GetRunGameEngineInterface()->SetTrackerUserID(GetDoc()->GetUserID());
}
//-----------------------------------------------------------------------------
// Purpose: Called when the Client joins a server, sets us up into tracker ingame mode
//-----------------------------------------------------------------------------
void CTrackerDialog::OnConnectToGame(int IP, int port)
{
// save game data
m_iGameIP = IP;
m_iGamePort = port;
// set in document
GetDoc()->Data()->SetInt("Login/GameIP", m_iGameIP);
GetDoc()->Data()->SetInt("Login/GamePort", m_iGamePort);
GetDoc()->Data()->SetString("Login/GameDir", m_szGameDir);
// tell server
ServerSession().SetGameInfo(m_szGameDir, m_iGameIP, m_iGamePort);
if (!m_bInGame)
{
// flip us to ingame mode if we're online
m_bInGame = true;
ServerSession().UserSelectNewStatus(COnlineStatus::INGAME);
}
// tell the game server our id
Tracker_GetRunGameEngineInterface()->SetTrackerUserID(GetDoc()->GetUserID());
}
//-----------------------------------------------------------------------------
// Purpose: Called when we disconnect from a game, resets tracker mode
//-----------------------------------------------------------------------------
void CTrackerDialog::OnDisconnectFromGame()
{
if (m_bInGame)
{
m_bInGame = false;
// go offline when not in a server, since the user can't access the UI anyway
m_iGameIP = 0;
m_iGamePort = 0;
ServerSession().SetGameInfo(m_szGameDir, m_iGameIP, m_iGamePort);
ServerSession().UserSelectNewStatus(COnlineStatus::ONLINE);
}
}
//-----------------------------------------------------------------------------
// Purpose: Message handler to save user data out to disk
//-----------------------------------------------------------------------------
void CTrackerDialog::OnSaveUserData()
{
GetDoc()->SaveAppData();
GetDoc()->SaveUserData();
m_bNeedToSaveUserData = false;
}
//-----------------------------------------------------------------------------
// Purpose: Marks the user data that it needs to be saved to disk
//-----------------------------------------------------------------------------
void CTrackerDialog::MarkUserDataAsNeedsSaving()
{
if (!m_bNeedToSaveUserData)
{
PostMessage(this, new KeyValues("SaveUserData"), 2.0f);
m_bNeedToSaveUserData = true;
}
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : *chatDialog -
// remove -
//-----------------------------------------------------------------------------
void CTrackerDialog::SetChatDialogInList(CDialogChat *chatDialog, bool remove)
{
if (remove)
{
m_hChatDialogs.RemoveElement(chatDialog);
}
else
{
m_hChatDialogs.PutElement(chatDialog);
}
}
//-----------------------------------------------------------------------------
// Purpose: Opens a chat dialog with other users
//-----------------------------------------------------------------------------
void CTrackerDialog::OnAddedToChat(KeyValues *msg)
{
int friendID = msg->GetInt("uid");
int chatID = msg->GetInt("ChatID");
// check to see if we're already in this chat
for (int i = 0; i < m_hChatDialogs.GetCount(); i++)
{
if (m_hChatDialogs[i] && m_hChatDialogs[i]->GetChatID() == chatID)
return;
}
// see if we already have a chat dialog open with this user
CDialogChat *dialogChat = GetDoc()->GetBuddy(friendID)->GetChatDialog();
if (!dialogChat)
{
// create the new multi-chat dialog
dialogChat = new CDialogChat(friendID);
surface()->CreatePopup(dialogChat->GetVPanel(), true);
dialogChat->Open(true);
dialogChat->OnInvited();
}
dialogChat->InitiateMultiUserChat(chatID);
dialogChat->FlashWindow();
}
//-----------------------------------------------------------------------------
// Purpose: Message map
//-----------------------------------------------------------------------------
MessageMapItem_t CTrackerDialog::m_MessageMap[] =
{
// network messages
MAP_MSGID( CTrackerDialog, TSVC_LOGINOK, OnLoginOK ),
MAP_MSGID_INT( CTrackerDialog, TSVC_FRIENDS, OnFriendsStatusChanged, "count" ),
MAP_MSGID_INT( CTrackerDialog, TSVC_LOGINFAIL, OnLoginFail, "reason" ),
MAP_MSGID_PARAMS( CTrackerDialog, TCL_ADDEDTOCHAT, OnAddedToChat ),
MAP_MSGID_PARAMS( CTrackerDialog, TCL_MESSAGE, OnReceivedMessage ),
MAP_MSGID_PARAMS( CTrackerDialog, TSVC_MESSAGE, OnReceivedMessage ),
MAP_MSGID_PARAMS( CTrackerDialog, TSVC_GAMEINFO, OnReceivedGameInfo ),
MAP_MSGID_PARAMS( CTrackerDialog, TSVC_FRIENDINFO, OnReceivedFriendInfo ),
MAP_MSGID_PARAMS( CTrackerDialog, TCL_USERBLOCK, OnReceivedUserBlock ),
MAP_MESSAGE( CTrackerDialog, "UserCreateCancel", OnUserCreateCancel ),
MAP_MESSAGE( CTrackerDialog, "SaveUserData", OnSaveUserData ),
MAP_MESSAGE( CTrackerDialog, "DisconnectedFromGame", OnDisconnectFromGame ),
MAP_MESSAGE_INT( CTrackerDialog, "UserChangeStatus", OnUserChangeStatus, "status" ),
MAP_MESSAGE_INT( CTrackerDialog, "OnlineStatus", OnOnlineStatusChanged, "value" ),
MAP_MESSAGE_CONSTCHARPTR( CTrackerDialog, "ActiveGameName", OnActiveGameName, "name" ),
MAP_MESSAGE_INT_INT( CTrackerDialog, "ConnectedToGame", OnConnectToGame, "ip", "port" ),
MAP_MESSAGE_INT_CONSTCHARPTR( CTrackerDialog, "UserCreateFinished", OnUserCreateFinished, "userid", "password" ),
};
IMPLEMENT_PANELMAP(CTrackerDialog, vgui::Frame);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -