📄 vinternetdlg.cpp
字号:
{
m_pSavedData->SetString("GameList", "favorites");
}
else if (m_pGameList == m_pLanGames)
{
m_pSavedData->SetString("GameList", "lan");
}
else if (m_pGameList == m_pFriendsGames)
{
m_pSavedData->SetString("GameList", "friends");
}
else
{
m_pSavedData->SetString("GameList", "internet");
}
// get the favorites list
KeyValues *favorites = m_pSavedData->FindKey("Favorites", true);
m_pFavorites->SaveFavoritesList(favorites);
m_pSavedData->SaveToFile(filesystem(), "ServerBrowser.vdf", "CONFIG");
}
//-----------------------------------------------------------------------------
// Purpose: Updates status test at bottom of window
// Input : *fmt -
// ... -
//-----------------------------------------------------------------------------
void VInternetDlg::UpdateStatusText(const char *fmt, ...)
{
if ( !m_pStatusLabel )
return;
char str[ 1024 ];
va_list argptr;
va_start( argptr, fmt );
vsprintf( str, fmt, argptr );
va_end( argptr );
m_pStatusLabel->SetText( str );
}
//-----------------------------------------------------------------------------
// Purpose: Updates status test at bottom of window
// Input : wchar_t* (unicode string) -
//-----------------------------------------------------------------------------
void VInternetDlg::UpdateStatusText(wchar_t *unicode)
{
if ( !m_pStatusLabel )
return;
m_pStatusLabel->SetText( unicode );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void VInternetDlg::OnGameListChanged()
{
m_pGameList = dynamic_cast<IGameList *>(m_pTabPanel->GetActivePage());
UpdateStatusText("");
InvalidateLayout();
Repaint();
}
//-----------------------------------------------------------------------------
// Purpose: returns a pointer to a static instance of this dialog
// Output : VInternetDlg
//-----------------------------------------------------------------------------
VInternetDlg *VInternetDlg::GetInstance()
{
return s_InternetDlg;
}
//-----------------------------------------------------------------------------
// Purpose: Adds a server to the list of favorites
// Input : &server -
//-----------------------------------------------------------------------------
void VInternetDlg::AddServerToFavorites(serveritem_t &server)
{
m_pFavorites->AddNewServer(server);
}
//-----------------------------------------------------------------------------
// Purpose:
// Output : CServerContextMenu
//-----------------------------------------------------------------------------
CServerContextMenu *VInternetDlg::GetContextMenu()
{
// create a drop down for this object's states
if (m_pContextMenu)
delete m_pContextMenu;
m_pContextMenu = new CServerContextMenu(this);
m_pContextMenu->SetParent(this);
m_pContextMenu->SetVisible(false);
return m_pContextMenu;
}
//-----------------------------------------------------------------------------
// Purpose: begins the process of joining a server from a game list
// the game info dialog it opens will also update the game list
//-----------------------------------------------------------------------------
CDialogGameInfo *VInternetDlg::JoinGame(IGameList *gameList, unsigned int serverIndex)
{
// open the game info dialog, then mark it to attempt to connect right away
CDialogGameInfo *gameDialog = OpenGameInfoDialog(gameList, serverIndex);
// set the dialog name to be the server name
gameDialog->Connect();
return gameDialog;
}
//-----------------------------------------------------------------------------
// Purpose: joins a game by a specified IP, not attached to any game list
//-----------------------------------------------------------------------------
CDialogGameInfo *VInternetDlg::JoinGame(int serverIP, int serverPort, const char *titleName)
{
// open the game info dialog, then mark it to attempt to connect right away
CDialogGameInfo *gameDialog = OpenGameInfoDialog(serverIP, serverPort, titleName);
// set the dialog name to be the server name
gameDialog->Connect();
return gameDialog;
}
//-----------------------------------------------------------------------------
// Purpose: opens a game info dialog from a game list
//-----------------------------------------------------------------------------
CDialogGameInfo *VInternetDlg::OpenGameInfoDialog(IGameList *gameList, unsigned int serverIndex)
{
CDialogGameInfo *gameDialog = new CDialogGameInfo(gameList, serverIndex);
serveritem_t &server = gameList->GetServer(serverIndex);
gameDialog->Run(server.name);
return gameDialog;
}
//-----------------------------------------------------------------------------
// Purpose: opens a game info dialog by a specified IP, not attached to any game list
//-----------------------------------------------------------------------------
CDialogGameInfo *VInternetDlg::OpenGameInfoDialog(int serverIP, int serverPort, const char *titleName)
{
CDialogGameInfo *gameDialog = new CDialogGameInfo(NULL, 0, serverIP, serverPort);
gameDialog->Run(titleName);
return gameDialog;
}
//-----------------------------------------------------------------------------
// Purpose: Save position and window size of a dialog from the .vdf file.
// Input : *dialog - panel we are setting position and size
// *dialogName - name of dialog in the .vdf file
//-----------------------------------------------------------------------------
void VInternetDlg::SaveDialogState(Panel *dialog, const char *dialogName)
{
// write the size and position to the document
int x, y, wide, tall;
dialog->GetBounds(x, y, wide, tall);
KeyValues *data;
data = m_pSavedData->FindKey(dialogName, true);
data->SetInt("x", x);
data->SetInt("y", y);
data->SetInt("w", wide);
data->SetInt("t", tall);
}
//-----------------------------------------------------------------------------
// Purpose: Load position and window size of a dialog from the .vdf file.
// Input : *dialog - panel we are setting position and size
// *dialogName - name of dialog in the .vdf file
//-----------------------------------------------------------------------------
void VInternetDlg::LoadDialogState(Panel *dialog, const char *dialogName)
{
// read the size and position from the document
KeyValues *data;
data = m_pSavedData->FindKey(dialogName, true);
// calculate defaults, center of the screen
int x, y, wide, tall, dwide, dtall;
int nx, ny, nwide, ntall;
vgui::surface()->GetScreenSize(wide, tall);
dialog->GetSize(dwide, dtall);
x = (int)((wide - dwide) * 0.5);
y = (int)((tall - dtall) * 0.5);
// set dialog
nx = data->GetInt("x", x);
ny = data->GetInt("y", y);
nwide = data->GetInt("w", dwide);
ntall = data->GetInt("t", dtall);
// make sure it's on the screen. If it isn't, move it over so it is.
if (nx + nwide > wide)
{
nx = wide - nwide;
}
if (ny + ntall > tall)
{
ny = tall - ntall;
}
if (nx < 0)
{
nx = 0;
}
if (ny < 0)
{
ny = 0;
}
dialog->SetBounds(nx, ny, nwide, ntall);
}
//-----------------------------------------------------------------------------
// Purpose: accessor to the filter save data
//-----------------------------------------------------------------------------
vgui::KeyValues *VInternetDlg::GetFilterSaveData(const char *filterSet)
{
vgui::KeyValues *filterList = m_pSavedData->FindKey("FilterList", true);
return filterList->FindKey(filterSet, true);
}
//-----------------------------------------------------------------------------
// Purpose: gets the name of the mod directory we're restricted to accessing, NULL if none
//-----------------------------------------------------------------------------
const char *VInternetDlg::GetActiveModName()
{
return m_szGameName[0] ? m_szGameName : NULL;
}
//-----------------------------------------------------------------------------
// Purpose: receives a specified game is active, so no other game types can be displayed in server list
//-----------------------------------------------------------------------------
void VInternetDlg::OnActiveGameName(const char *gameName)
{
v_strncpy(m_szGameName, gameName, sizeof(m_szGameName));
// reload filter settings (since they are no forced to be game specific)
m_pInternetGames->LoadFilterSettings();
m_pSpectateGames->LoadFilterSettings();
m_pFavorites->LoadFilterSettings();
m_pLanGames->LoadFilterSettings();
m_pFriendsGames->LoadFilterSettings();
}
//-----------------------------------------------------------------------------
// Purpose: safe string copy
//-----------------------------------------------------------------------------
void v_strncpy(char *dest, const char *src, int bufsize)
{
if (src == dest)
return;
strncpy(dest, src, bufsize - 1);
dest[bufsize - 1] = 0;
}
//-----------------------------------------------------------------------------
// Purpose: Message map
//-----------------------------------------------------------------------------
MessageMapItem_t VInternetDlg::m_MessageMap[] =
{
MAP_MESSAGE( VInternetDlg, "PageChanged", OnGameListChanged ),
MAP_MESSAGE_CONSTCHARPTR( VInternetDlg, "ActiveGameName", OnActiveGameName, "name" ),
};
IMPLEMENT_PANELMAP(VInternetDlg, vgui::Frame);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -