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

📄 menucontrols.cpp

📁 Blood 2全套源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// MenuControls.cpp: implementation of the CMenuControls class.
//
//////////////////////////////////////////////////////////////////////

#include "VKDefs.h"
#include "LTGUIMgr.h"
#include "basedefs_de.h"
#include "MenuLoadGame.h"
#include "MenuCommands.h"
#include "BloodClientShell.h"
#include "ClientRes.h"
#include "KeyFixes.h"

#define USE_CONFIGURE_JOYSTICK

// The different columns
#define MENU_COLUMN_ACTION	0
#define MENU_COLUMN_BUFFER	1
#define MENU_COLUMN_EQUALS	2
#define MENU_COLUMN_KEY		3								
	
char	*g_pControlActionName[MENU_CONTROLS_NUM_ACTIONS] =
{
	"Forward",			// 1
	"Backward",			// 2
	"Left",				// 3
	"Right",			// 4
	"Strafe",			// 5
	"StrafeLeft",		// 6
	"StrafeRight",		// 7
	"Run",				// 8
	"RunLock",			// 9
	"Jump",				// 10
	"Duck",				// 11
	"TurnAround",		// 12
	"Fire",				// 13
	"AltFire",			// 14
	"NextWeapon",		// 15
	"PrevWeapon",		// 16
	"DropWeapon",		// 17
	"Open",				// 18
	"InventoryLeft",	// 19
	"InventoryRight",	// 20
	"UseInventory",		// 21
	"Grab",				// 22
	"Message",			// 23
	"Taunt",			// 24
	"LookUp",			// 25
	"LookDown",			// 26
	"MouseAimToggle",	// 27
	"Crosshair",		// 28
//	"ScreenShrink",		// 29
//	"ScreenEnlarge",	// 30
	"Proximities",		// 31
	"Remotes",			// 32
	"Time",				// 33
	"Detonate",			// 34
	"Weapon_0",			// 35
	"Weapon_1",			// 36
	"Weapon_2",			// 37
	"Weapon_3",			// 38
	"Weapon_4",			// 39
	"Weapon_5",			// 40
	"Weapon_6",			// 41
	"Weapon_7",			// 42
	"Weapon_8",			// 43
	"Weapon_9"			// 44
};

int g_nControlActionStringID[MENU_CONTROLS_NUM_ACTIONS] =
{
	IDS_MENU_ACTION_FORWARD,		// 1
	IDS_MENU_ACTION_BACKWARD,		// 2
	IDS_MENU_ACTION_LEFT,			// 3
	IDS_MENU_ACTION_RIGHT,			// 4
	IDS_MENU_ACTION_STRAFE,			// 5
	IDS_MENU_ACTION_STRAFELEFT,		// 6
	IDS_MENU_ACTION_STRAFERIGHT,	// 7
	IDS_MENU_ACTION_RUN,			// 8
	IDS_MENU_ACTION_RUNLOCK,		// 9
	IDS_MENU_ACTION_JUMP,			// 10
	IDS_MENU_ACTION_DUCK,			// 11
	IDS_MENU_ACTION_TURNAROUND,		// 12
	IDS_MENU_ACTION_FIRE,			// 13
	IDS_MENU_ACTION_ALTFIRE,		// 14
	IDS_MENU_ACTION_NEXTWEAPON,		// 15
	IDS_MENU_ACTION_PREVWEAPON,		// 16
	IDS_MENU_ACTION_DROPWEAPON,		// 17
	IDS_MENU_ACTION_OPEN,			// 18
	IDS_MENU_ACTION_INVENTORYLEFT,	// 19
	IDS_MENU_ACTION_INVENTORYRIGHT,	// 20
	IDS_MENU_ACTION_USEINVENTORY,	// 21
	IDS_MENU_ACTION_GRAB,			// 22
	IDS_MENU_ACTION_MESSAGE,		// 23
	IDS_MENU_ACTION_TAUNT,			// 24
	IDS_MENU_ACTION_LOOKUP,			// 25
	IDS_MENU_ACTION_LOOKDOWN,		// 26
	IDS_MENU_ACTION_MOUSEAIMTOGGLE,	// 27
	IDS_MENU_ACTION_CROSSHAIR,		// 28
//	IDS_MENU_ACTION_SCREENSHRINK,	// 29
//	IDS_MENU_ACTION_SCREENENLARGE,	// 30
	IDS_MENU_ACTION_PROXIMITIES,	// 31
	IDS_MENU_ACTION_REMOTES,		// 32
	IDS_MENU_ACTION_TIME,			// 33
	IDS_MENU_ACTION_DETONATE,		// 34
	IDS_MENU_ACTION_WEAPON0,		// 35
	IDS_MENU_ACTION_WEAPON1,		// 36
	IDS_MENU_ACTION_WEAPON2,		// 37
	IDS_MENU_ACTION_WEAPON3,		// 38
	IDS_MENU_ACTION_WEAPON4,		// 39
	IDS_MENU_ACTION_WEAPON5,		// 40
	IDS_MENU_ACTION_WEAPON6,		// 41
	IDS_MENU_ACTION_WEAPON7,		// 42
	IDS_MENU_ACTION_WEAPON8,		// 43
	IDS_MENU_ACTION_WEAPON9			// 44
};

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CMenuControls::CMenuControls()
{
	for (int i=0; i < MENU_CONTROLS_NUM_DEVICES; i++)
	{
		for (int n=0; n < MENU_CONTROLS_NUM_ACTIONS; n++)
		{
			m_deviceControlArray[i][n] = NULL;
		}
	}	
}

CMenuControls::~CMenuControls()
{

}

// Initialization
DBOOL CMenuControls::Init(CClientDE *pClientDE, CMainMenus *pMainMenus,
						  CMenuBase *pParentMenu, DWORD dwMenuID, int nMenuHeight)
{
	// Call the base class
	if (!CMenuBase::Init(pClientDE, pMainMenus, pParentMenu, dwMenuID, nMenuHeight))
	{
		return DFALSE;
	}
	
	memset(m_deviceControlArray, DNULL, sizeof(m_deviceControlArray));

	return DTRUE;
}

// Termination
void CMenuControls::Term()
{
	// Terminate the key and mouse arrays	
	int i;
	for (i=0; i < MENU_CONTROLS_NUM_DEVICES; i++)
	{
		int n;
		for (n=0; n < MENU_CONTROLS_NUM_ACTIONS; n++)
		{
			if (m_deviceControlArray[i][n])
			{
				delete []m_deviceControlArray[i][n];
				m_deviceControlArray[i][n]=DNULL;
			}
		}
	}	
}

// Builds the menu
void CMenuControls::Build()
{
	// Make sure to call the base class
	CMenuBase::Build();

	CreateTitle("interface\\mainmenus\\options.pcx", IDS_MENU_TITLE_OPTIONS, m_pMainMenus->GetTitlePos());		
	SetOptionPos(m_pMainMenus->GetOptionsPos());
	SetItemSpacing(0);
	SetScrollWrap(DFALSE);
	UseArrows(DTRUE, 298);

	// Add the controls to the menu
	InitControlList();
}

// Maps a device type to an index (DEVICETYPE_KEYBOARD=0, DEVICETYPE_MOUSE=1, etc);
// -1 is returned if the devicetype cannot be mapped.
int CMenuControls::GetDeviceIndexFromType(DWORD dwDeviceType)
{
	int nIndex;
	switch (dwDeviceType)
	{
	case DEVICETYPE_KEYBOARD:
		{
			nIndex=0;
			break;
		}
	case DEVICETYPE_MOUSE:
		{
			nIndex=1;
			break;
		}
	case DEVICETYPE_JOYSTICK:
		{
			nIndex=2;
			break;
		}
	default:
		{
			assert(DFALSE);
			return -1;
		}
	}

	return nIndex;
}

// Returns the device type from an index (ex: 0=DEVICETYPE_KEYBOARD, 1=DEVICETYPE_MOUSE, etc.)
DWORD CMenuControls::GetDeviceTypeFromIndex(int nIndex)
{
	DWORD dwType;
	switch (nIndex)
	{
	case 0:
		{
			dwType=DEVICETYPE_KEYBOARD;
			break;
		}
	case 1:
		{
			dwType=DEVICETYPE_MOUSE;
			break;
		}
	case 2:
		{
			dwType=DEVICETYPE_JOYSTICK;
			break;
		}	
	default:
		{
			assert(DFALSE);
			return -1;
		}
	}

	return dwType;
}

// Intialize the list of controls
DBOOL CMenuControls::InitControlList()
{
	// Remove the current options
	RemoveAllOptions();

	// Add the columns
	InitColumns();

	// Fill the binding arrays
	FillBindingArray(DEVICETYPE_KEYBOARD);
	FillBindingArray(DEVICETYPE_MOUSE);

#ifdef USE_CONFIGURE_JOYSTICK
	FillBindingArray(DEVICETYPE_JOYSTICK);
#endif

	// Fill out the column text for the bindings
	int i;
	for (i=0; i < MENU_CONTROLS_NUM_ACTIONS; i++)
	{
		SetControlText(i);
	}
	return DTRUE;
}

// Sets the key/mouse info for a control at a specific index
void CMenuControls::SetControlText(int nIndex)
{
	// Get the control for this index
	CLTGUIColumnTextCtrl *pCtrl=(CLTGUIColumnTextCtrl *)m_listOption.GetControl(nIndex);
	
	char szTemp[1024];
	memset(szTemp, 0, sizeof(szTemp));

	// Go through each device adding its control text
	int i;
	for (i=0; i < MENU_CONTROLS_NUM_DEVICES; i++)
	{		
		if ( m_deviceControlArray[i][nIndex] && _mbstrlen(m_deviceControlArray[i][nIndex]) > 0)
		{
			// Do we need to append "or" to the string?
			if (_mbstrlen(szTemp) > 0)
			{
				_mbscat((unsigned char*)szTemp, (const unsigned char*)" or ");
			}

			// Special case each device type so that it appears correctly on the screen
			switch (GetDeviceTypeFromIndex(i))
			{
			case DEVICETYPE_KEYBOARD:
				{
					// Translate the key message from English to the current keyboard
					char szNewKey[1024];
					ConvertKeyToCurrentKeyboard((char *)&szNewKey, m_deviceControlArray[i][nIndex], sizeof(szNewKey));

					_mbscat((unsigned char*)szTemp, (const unsigned char*)szNewKey);
					break;
				}
			case DEVICETYPE_MOUSE:
				{					
					// Change it from BUTTON to MBUTTON
					_mbscat((unsigned char*)szTemp, (const unsigned char*)"MBUTTON");

					// Get the number that is currently in the string and increment it by one
					// (changing MBUTTON 0 to MBUTTON 1)
					int nButton=atoi(m_deviceControlArray[i][nIndex]+_mbstrlen("button"));
						
					char szTemp2[256]; 
					sprintf(szTemp2, " %d", nButton+1);
					_mbscat((unsigned char*)szTemp, (const unsigned char*)szTemp2);					
					break;
				}
			case DEVICETYPE_JOYSTICK:
				{
					// Prepend a "J" to the control name
					_mbscat((unsigned char*)szTemp, (const unsigned char*)"J");				
					_mbscat((unsigned char*)szTemp, (const unsigned char*)m_deviceControlArray[i][nIndex]);
					break;

⌨️ 快捷键说明

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