📄 vinternetdlg.cpp
字号:
//======== (C) Copyright 1999, 2000 Valve, L.L.C. All rights reserved. ========
//
// The copyright to the contents herein is the property of Valve, L.L.C.
// The contents may be used and/or copied only with the written permission of
// Valve, L.L.C., or in accordance with the terms and conditions stipulated in
// the agreement/contract under which the contents have been supplied.
//
// Purpose:
//
// $Workfile: $
// $Date: $
//
//-----------------------------------------------------------------------------
// $Log: $
//
// $NoKeywords: $
//=============================================================================
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <assert.h>
// base vgui interfaces
#include <VGUI_Controls.h>
#include <VGUI_IInput.h>
#include <VGUI_ISurface.h>
#include <VGUI_IScheme.h>
#include <VGUI_IVGui.h>
#include <VGUI_MouseCode.h>
#include "FileSystem.h"
// vgui controls
#include <VGUI_Button.h>
#include <VGUI_CheckButton.h>
#include <VGUI_ComboBox.h>
#include <VGUI_FocusNavGroup.h>
#include <VGUI_Frame.h>
#include <VGUI_KeyValues.h>
#include <VGUI_ListPanel.h>
#include <VGUI_MessageBox.h>
#include <VGUI_Panel.h>
#include <VGUI_PropertySheet.h>
#include <VGUI_QueryBox.h>
// serverbrowser headers
#include "inetapi.h"
#include "msgbuffer.h"
#include "proto_oob.h"
#include "ServerContextMenu.h"
#include "socket.h"
#include "util.h"
#include "vinternetdlg.h"
#include "ModList.h"
#include "DialogGameInfo.h"
// game list
#include "InternetGames.h"
#include "FavoriteGames.h"
#include "SpectateGames.h"
#include "LanGames.h"
#include "FriendsGames.h"
// interface to game engine / tracker
#include "IRunGameEngine.h"
using namespace vgui;
static VInternetDlg *s_InternetDlg = NULL;
//-----------------------------------------------------------------------------
// Purpose: Constructor
//-----------------------------------------------------------------------------
VInternetDlg::VInternetDlg( void ) : Frame(NULL, "VInternetDlg")
{
s_InternetDlg = this;
MakePopup();
m_szGameName[0] = 0;
m_pSavedData = NULL;
// load filters
LoadFilters();
m_pInternetGames = new CInternetGames();
m_pSpectateGames = new CSpectateGames();
m_pFavorites = new CFavoriteGames();
m_pLanGames = new CLanGames();
m_pFriendsGames = new CFriendsGames();
SetMinimumSize(512, 384);
m_pGameList = m_pInternetGames;
m_pContextMenu = new CServerContextMenu(this);;
// property sheet
m_pTabPanel = new PropertySheet(this, "GameTabs");
m_pTabPanel->SetTabWidth(72);
m_pTabPanel->AddPage(m_pInternetGames, "#ServerBrowser_InternetTab");
m_pTabPanel->AddPage(m_pFavorites, "#ServerBrowser_FavoritesTab");
m_pTabPanel->AddPage(m_pSpectateGames, "#ServerBrowser_SpectateTab");
m_pTabPanel->AddPage(m_pLanGames, "#ServerBrowser_LanTab");
m_pTabPanel->AddPage(m_pFriendsGames, "#ServerBrowser_FriendsTab");
m_pTabPanel->AddActionSignalTarget(this);
m_pStatusLabel = new Label(this, "StatusLabel", "");
LoadControlSettings("Servers/DialogServerBrowser.res");
m_pStatusLabel->SetText("");
// load favorite servers
KeyValues *favorites = m_pSavedData->FindKey("Favorites", true);
m_pFavorites->LoadFavoritesList(favorites);
// load current tab
const char *gameList = m_pSavedData->GetString("GameList");
if (!stricmp(gameList, "spectate"))
{
m_pTabPanel->SetActivePage(m_pSpectateGames);
}
else if (!stricmp(gameList, "favorites"))
{
m_pTabPanel->SetActivePage(m_pFavorites);
}
else if (!stricmp(gameList, "lan"))
{
m_pTabPanel->SetActivePage(m_pLanGames);
}
else if (!stricmp(gameList, "friends"))
{
m_pTabPanel->SetActivePage(m_pFriendsGames);
}
else
{
m_pTabPanel->SetActivePage(m_pInternetGames);
}
// load window settings
LoadDialogState(this, "ServerBrowser");
}
//-----------------------------------------------------------------------------
// Purpose: Destructor
//-----------------------------------------------------------------------------
VInternetDlg::~VInternetDlg()
{
}
//-----------------------------------------------------------------------------
// Purpose: Called once to set up
//-----------------------------------------------------------------------------
void VInternetDlg::Initialize()
{
SetTitle("Servers", true);
SetVisible(false);
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : serverID -
// Output : serveritem_t
//-----------------------------------------------------------------------------
serveritem_t &VInternetDlg::GetServer(unsigned int serverID)
{
return m_pGameList->GetServer(serverID);
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void VInternetDlg::Open( void )
{
m_pTabPanel->RequestFocus();
// if serverbrowser file is not there we will try to transfer the favorites list.
FileHandle_t f = filesystem()->Open("ServerBrowser.vdf", "rb");
if (f)
{
filesystem()->Close( f );
}
else
{
m_pFavorites->ImportFavorites(); // import old favorites from old server browser
}
surface()->SetMinimized(GetVPanel(), false);
SetVisible(true);
RequestFocus();
m_pTabPanel->RequestFocus();
MoveToFront();
}
//-----------------------------------------------------------------------------
// Purpose: relayouts the dialogs controls
//-----------------------------------------------------------------------------
void VInternetDlg::PerformLayout()
{
BaseClass::PerformLayout();
int x, y, wide, tall;
GetClientArea(x, y, wide, tall);
// game list in middle
m_pTabPanel->SetBounds(8, y + 8, GetWide() - 16, tall - (28));
x += 4;
// status text along bottom
m_pStatusLabel->SetBounds(x + 2, (tall - y) + 40, wide - 6, 20);
m_pStatusLabel->SetContentAlignment(Label::a_northwest);
Repaint();
}
//-----------------------------------------------------------------------------
// Purpose: This makes it so the menu will always be in front in GameUI
//-----------------------------------------------------------------------------
void VInternetDlg::PaintBackground()
{
BaseClass::PaintBackground();
if (m_pContextMenu->IsVisible())
{
m_pContextMenu->MoveToFront();
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void VInternetDlg::OnClose()
{
// bug here if you exit before logging in.
SaveDialogState(this, "ServerBrowser");
SaveFilters();
Frame::OnClose();
}
//-----------------------------------------------------------------------------
// Purpose: Loads filter settings from disk
//-----------------------------------------------------------------------------
void VInternetDlg::LoadFilters()
{
// free any old filters
if (m_pSavedData)
{
m_pSavedData->deleteThis();
}
m_pSavedData = new KeyValues ("Filters");
if (!m_pSavedData->LoadFromFile(filesystem(), "ServerBrowser.vdf", true, "CONFIG"))
{
// doesn't matter if the file is not found, defaults will work successfully and file will be created on exit
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void VInternetDlg::SaveFilters()
{
// set the current tab
if (m_pGameList == m_pSpectateGames)
{
m_pSavedData->SetString("GameList", "spectate");
}
else if (m_pGameList == m_pFavorites)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -