⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 netstart.cpp

📁 Blood 2全套源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
			{
				KillTimer(hDlg, 1);
				return(TRUE);
			}
			else if (wParam == IDC_NEXT)
			{
				EndDialog(hDlg, DLG_NEXT);
				return(TRUE);
			}
		}
	}

	return(FALSE);
}


// ----------------------------------------------------------------------- //
//
//	ROUTINE:	NetStart_FillLevelList
//
//	PURPOSE:	Fills a list box with the list of levels
//
// ----------------------------------------------------------------------- //

BOOL NetStart_FillLevelList(HWND hList, char* sDir, int nData, BOOL bClearList)
{
	// Sanity checks...

	if (!hList) return(FALSE);
	if (!sDir) return(FALSE);


	// Get a list of world names and put them in the list box...

	if (bClearList)
	{
		SendMessage(hList, LB_RESETCONTENT, 0, 0);
	}


	// Get all the level files in the given directory...

	FileEntry* pFiles = s_pServerMgr->GetFileList(sDir);
	if (!pFiles) return(FALSE);

	FileEntry* ptr = pFiles;

	while (ptr)
	{
		if (ptr->m_Type == TYPE_FILE)
		{
			if (strnicmp(&ptr->m_pBaseFilename[strlen(ptr->m_pBaseFilename) - 4], ".dat", 4) == 0)
			{
				char sLevel[128];
				strcpy(sLevel, ptr->m_pBaseFilename);
				int len = strlen(sLevel);
				if (len > 4) sLevel[len - 4] = '\0';

				if (NetStart_IsOkToDisplayLevel(sLevel))
				{
					int nIndex = SendMessage(hList, LB_ADDSTRING, 0, (LPARAM)sLevel);
					if (nIndex != LB_ERR)
					{
						SendMessage(hList, LB_SETITEMDATA, nIndex, nData);
					}
				}
			}
		}

		ptr = ptr->m_pNext;
	}

	s_pServerMgr->FreeFileList(pFiles);


	// Set the current selection...

	SendMessage(hList, LB_SETCURSEL, 0, 0);


	// All done...

	return(TRUE);
}

BOOL NetStart_InitGameType(HWND hDlg)
{
	if (!hDlg) return(FALSE);

	CheckDlgButton(hDlg, IDC_BB, s_nGameType == NGT_DEATHMATCH ? BST_CHECKED : BST_UNCHECKED);
	CheckDlgButton(hDlg, IDC_CTF, s_nGameType == NGT_CAPTUREFLAG ? BST_CHECKED : BST_UNCHECKED);
	CheckDlgButton(hDlg, IDC_TEAMS, s_nGameType == NGT_TEAMS ? BST_CHECKED : BST_UNCHECKED);

#ifdef _ADDON
	CheckDlgButton(hDlg, IDC_SOCCER, s_nGameType == NGT_SOCCER ? BST_CHECKED : BST_UNCHECKED);
#endif

	return(TRUE);
}

BOOL NetStart_FillGameType(HWND hDlg)
{
	if (!hDlg) return(FALSE);

	if (IsDlgButtonChecked(hDlg, IDC_BB) == BST_CHECKED) s_nGameType = NGT_DEATHMATCH;
	if (IsDlgButtonChecked(hDlg, IDC_CTF) == BST_CHECKED) s_nGameType = NGT_CAPTUREFLAG;
	if (IsDlgButtonChecked(hDlg, IDC_TEAMS) == BST_CHECKED) s_nGameType = NGT_TEAMS;

#ifdef _ADDON
	if (IsDlgButtonChecked(hDlg, IDC_SOCCER) == BST_CHECKED) s_nGameType = NGT_SOCCER;
#endif

	s_pNetGame->m_byType = s_nGameType;

	return(TRUE);
}


// ----------------------------------------------------------------------- //
//
//	ROUTINE:	NetStart_GameEnd
//
//	PURPOSE:	Does the GAMEEND dialog
//
// ----------------------------------------------------------------------- //

BOOL CALLBACK NetDlg_GameEnd(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	switch (uMsg)
	{
		case WM_INITDIALOG:
		{
			SetIcon(hDlg);
			ForceActiveFocus(hDlg);

			SetDlgItemInt(hDlg, IDC_MAXPLAYERS, s_nMaxPlayers, FALSE);
			SetDlgItemInt(hDlg, IDC_FRAGS, s_nEndFrags, FALSE);
			SetDlgItemInt(hDlg, IDC_MINUTES, s_nEndTime, FALSE);
			CheckDlgButton(hDlg, IDC_AFTERFRAGS,   (s_nEndType == NGE_FRAGS) ? BST_CHECKED : BST_UNCHECKED);
			CheckDlgButton(hDlg, IDC_AFTERMINUTES, (s_nEndType == NGE_TIME)  ? BST_CHECKED : BST_UNCHECKED);

			return(TRUE);
		}

		case WM_COMMAND:
		{
			if (NetStart_HandleDefaultDialogCommands(hDlg, wParam))
			{
				return(TRUE);
			}
			else if (wParam == IDC_NEXT)
			{
				NetStart_FillGameEnd(hDlg);
				EndDialog(hDlg, DLG_NEXT);
				return(TRUE);
			}
		}
	}

	return(FALSE);
}


// ----------------------------------------------------------------------- //
//
//	ROUTINE:	NetStart_FillGameEnd
//
//	PURPOSE:	Fills the NetGame structure with the game end info
//
// ----------------------------------------------------------------------- //

BOOL NetStart_FillGameEnd(HWND hDlg)
{
	// Sanity checks...

	if (!hDlg) return(FALSE);


	// Get the game end type...

	int nType = NGE_NEVER;

	if (IsDlgButtonChecked(hDlg, IDC_AFTERFRAGS) == BST_CHECKED) nType = NGE_FRAGS;

	if (IsDlgButtonChecked(hDlg, IDC_AFTERMINUTES) == BST_CHECKED)
	{
		if (nType == NGE_FRAGS) nType = NGE_FRAGSANDTIME;
		else nType = NGE_TIME;
	}

	s_pNetGame->m_byEnd = nType;
	s_nEndType          = nType;


	// Get the game end value...

	s_nEndFrags = GetDlgItemInt(hDlg, IDC_FRAGS, NULL, FALSE);
	s_nEndTime  = GetDlgItemInt(hDlg, IDC_MINUTES, NULL, FALSE);

	s_pNetGame->m_dwEndTime  = s_nEndTime;
	s_pNetGame->m_dwEndFrags = s_nEndFrags;


	// All done...

	return(TRUE);
}


// ----------------------------------------------------------------------- //
//
//	ROUTINE:	NetStart_GameLevels
//
//	PURPOSE:	Does the GAMELEVELS dialog
//
// ----------------------------------------------------------------------- //

BOOL CALLBACK NetDlg_GameLevels(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	static HWND hRetailList = NULL;
	static HWND hCustomList = NULL;
	static HWND hGameList   = NULL;

	switch (uMsg)
	{
		case WM_INITDIALOG:
		{
			SetIcon(hDlg);
			ForceActiveFocus(hDlg);

			hRetailList = GetDlgItem(hDlg, IDC_RETAILLIST);
			hCustomList = GetDlgItem(hDlg, IDC_CUSTOMLIST);
			hGameList   = GetDlgItem(hDlg, IDC_GAMELIST);

			NetStart_FillLevelList(hRetailList, "Worlds\\Multi", RETAIL_LEVEL);
			NetStart_FillLevelList(hCustomList, "\\", CUSTOM_LEVEL);

#ifdef _ADDON
			NetStart_FillLevelList(hRetailList, "Worlds_ao\\Multi_ao", ADDON_LEVEL, FALSE);
#endif

			InitGameLevels(hDlg);

			UpdateGameLevelControls(hDlg);

			return(TRUE);
		}

		case WM_COMMAND:
		{
			if (NetStart_HandleDefaultDialogCommands(hDlg, wParam))
			{
				return(TRUE);
			}
			else if (wParam == IDC_NEXT)
			{
				NetStart_FillGameLevels(hDlg);
				UpdateSaveGameLevels(hDlg);
				EndDialog(hDlg, DLG_NEXT);
				return(TRUE);
			}
			else if (wParam == IDC_ADDRETAIL)
			{
				AddSelToList(hRetailList, hGameList);
				UpdateGameLevelControls(hDlg);
				return(TRUE);
			}
			else if (wParam == IDC_ADDCUSTOM)
			{
				AddSelToList(hCustomList, hGameList);
				UpdateGameLevelControls(hDlg);
				return(TRUE);
			}
			else if (wParam == IDC_REMOVE)
			{
				RemoveSelFromList(hGameList);
				UpdateGameLevelControls(hDlg);
				return(TRUE);
			}
			else if (HIWORD(wParam) == LBN_SELCHANGE)
			{
				UpdateGameLevelControls(hDlg);
				return(TRUE);
			}
			else if (HIWORD(wParam) == LBN_DBLCLK)
			{
				switch(LOWORD(wParam))
				{
					case IDC_RETAILLIST: PostMessage(hDlg, WM_COMMAND, IDC_ADDRETAIL, 0); break;
					case IDC_CUSTOMLIST: PostMessage(hDlg, WM_COMMAND, IDC_ADDCUSTOM, 0); break;
					case IDC_GAMELIST:   PostMessage(hDlg, WM_COMMAND, IDC_REMOVE, 0); break;
				}
				return(TRUE);
			}
		}
	}

	return(FALSE);
}

void InitGameLevels(HWND hDlg)
{
	// Sanity checks...

	if (!hDlg) return;


	// Get the "save" flag...

	BOOL bSave = FALSE;
	NS_GetGameVar("SaveGameLevels", bSave);
	if (!bSave) return;

	CheckDlgButton(hDlg, IDC_SAVE, bSave ? BST_CHECKED : BST_UNCHECKED);


	// If we get here, fill in the saved levels...

	HWND hList = GetDlgItem(hDlg, IDC_GAMELIST);
	if (!hList) return;

	POSITION pos = s_collLevels.GetHeadPosition();

	while (pos)
	{
		CString sGameLevel = s_collLevels.GetNext(pos);

		if (!sGameLevel.IsEmpty())
		{
			// Prepare the level name by stripping out the prefixes...

			char sLevel[128];
			char sTemp[128];
			strcpy(sLevel, sGameLevel);
			strcpy(sTemp, sGameLevel);

			int nLen = strlen(sTemp);

			if (nLen > 2)
			{
				int i = nLen - 1;

				while (i > 0 && sTemp[i] != '\\')
				{
					i--;
				}

				if (i < nLen - 1)
				{
					if (sTemp[i] == '\\') i++;
					strcpy(sLevel, &sTemp[i]);
				}
			}


			// Add the level to the list...

			int nType = RETAIL_LEVEL;

			strupr(sTemp);
			if (!strstr(sTemp, "\\MULTI\\") && !strstr(sTemp, "\\MULTI_AO\\"))
			{
				nType = CUSTOM_LEVEL;
			}

#ifdef _ADDON
			if (strstr(sTemp, "\\MULTI_AO\\"))
			{
				nType = ADDON_LEVEL;
			}
#endif

			if (NetStart_IsOkToDisplayLevel(sLevel))
			{
				int nIndex = SendMessage(hList, LB_ADDSTRING, 0, (LPARAM)(LPCSTR)sLevel);
				if (nIndex != LB_ERR) SendMessage(hList, LB_SETITEMDATA, nIndex, nType);
			}
		}
	}
}

void UpdateSaveGameLevels(HWND hDlg)
{
	BOOL bSave = IsDlgButtonChecked(hDlg, IDC_SAVE) == BST_CHECKED;
	SetGameVar("SaveGameLevels", bSave);
}

BOOL AddSelToList(HWND hSrcList, HWND hDestList)
{
	// Sanity checks...

	if (!hSrcList) return(FALSE);
	if (!hDestList) return(FALSE);


	// Get the select item...

	char sText[256];
	int  nData;

	int nIndex = SendMessage(hSrcList, LB_GETCURSEL, 0, 0);
	if (nIndex == LB_ERR) return(FALSE);

	int nRet = SendMessage(hSrcList, LB_GETTEXT, nIndex, (LPARAM)(LPSTR)sText);
	if (nRet == LB_ERR) return(FALSE);
	if (strlen(sText) <= 0) return(FALSE);

	nData = SendMessage(hSrcList, LB_GETITEMDATA, nIndex, 0);
	if (nData == LB_ERR) return(FALSE);


	// Add the select stuff to the destination list...

	nIndex = SendMessage(hDestList, LB_ADDSTRING, 0, (LPARAM)(LPCSTR)sText);
	if (nIndex == LB_ERR) return(FALSE);

	SendMessage(hDestList, LB_SETITEMDATA, nIndex, nData);


	// All done...

	return(TRUE);
}

BOOL RemoveSelFromList(HWND hList)
{
	// Sanity checks...

	if (!hList) return(FALSE);


	// Remove the currently selected item...

	int nIndex = SendMessage(hList, LB_GETCURSEL, 0, 0);
	if (nIndex == LB_ERR) return(FALSE);

	int nRet = SendMessage(hList, LB_DELETESTRING, nIndex, 0);
	if (nRet == LB_ERR) return(FALSE);


	// Keep something selected if possible...

	nRet = SendMessage(hList, LB_SETCURSEL, nIndex, 0);
	if (nRet == LB_ERR && nIndex > 0)
	{
		SendMessage(hList, LB_SETCURSEL, nIndex-1, 0);
	}


	// All done...

	return(TRUE);
}

void UpdateGameLevelControls(HWND hDlg)
{
	// Get the list boxes...

	HWND hRetailList = GetDlgItem(hDlg, IDC_RETAILLIST);
	HWND hCustomList = GetDlgItem(hDlg, IDC_CUSTOMLIST);
	HWND hGameList   = GetDlgItem(hDlg, IDC_GAMELIST);


	// Update the buttons...

	int nRet = SendMessage(hRetailList, LB_GETCURSEL, 0, 0);
	EnableWindow(GetDlgItem(hDlg, IDC_ADDRETAIL), nRet != LB_ERR);

	nRet = SendMessage(hCustomList, LB_GETCURSEL, 0, 0);
	EnableWindow(GetDlgItem(hDlg, IDC_ADDCUSTOM), nRet != LB_ERR);

	nRet = SendMessage(hGameList, LB_GETCURSEL, 0, 0);
	EnableWindow(GetDlgItem(hDlg, IDC_REMOVE), nRet != LB_ERR);

	nRet = SendMessage(hGameList, LB_GETCOUNT, 0, 0);
	EnableWindow(GetDlgItem(hDlg, IDC_NEXT), nRet > 0);
}


// ----------------------------------------------------------------------- //
//
//	ROUTINE:	NetStart_FillGameLevels
//
//	PURPOSE:	Fills the level names in the NetGame structure
//
// ----------------------------------------------------------------------- //

BOOL NetStart_FillGameLevels(HWND hDlg)
{
	// Sanity checks...

	if (!hDlg) return(FALSE);


	// Add each level from the game list...

	s_collLevels.RemoveAll();

	s_pNetGame->m_byNumLevels = 0;
	for (int j = 0; j < MAX_GAME_LEVELS; j++) s_pNetGame->m_sLevels[j][0] = '\0';

	HWND hList = GetDlgItem(hDlg, IDC_GAMELIST);
	if (!hList) return(FALSE);

	int nCount = SendMessage(hList, LB_GETCOUNT, 0, 0);
	if (nCount == LB_ERR) return(FALSE);
	if (nCount == 0) return(FALSE);

	if (nCount > MAX_GAME_LEVELS) nCount = MAX_GAME_LEVELS;

	for (int i = 0; i < nCount; i++)
	{
		char sLevel[128];
		char sText[128];

		int nRet = SendMessage(hList, LB_GETTEXT, i, (LPARAM)(LPSTR)sText);
		if (nRet != LB_ERR)
		{
			int nData = SendMessage(hList, LB_GETITEMDATA, i, 0);

			if (nData == CUSTOM_LEVEL)
			{
				wsprintf(sLevel, "%s", sText);
			}
#ifdef _ADDON
			else if (nData == ADDON_LEVEL)
			{
				wsprintf(sLevel, "Worlds_ao\\Multi_ao\\%s", sText);
			}
#endif
			else
			{
				wsprintf(sLevel, "Worlds\\Multi\\%s", sText);
			}

			strcpy(s_pNetGame->m_sLevels[s_pNetGame->m_byNumLevels], sLevel);
			s_collLevels.AddTail(sLevel);
			s_pNetGame->m_byNumLevels++;
		}
	}


	// All done...

	return(TRUE);
}

BOOL NetStart_SetEndGameInfo(HWND hDlg)
{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -