📄 menucontrols.cpp
字号:
}
}
}
}
// If the key is unassigned, then just set the text to the unassigned message
if ( _mbstrlen(szTemp) == 0 )
{
pCtrl->SetString(MENU_COLUMN_KEY, IDS_MENU_KEY_UNASSIGNED);
}
else
{
// Set the text in the control
HSTRING hString=m_pClientDE->CreateString(szTemp);
pCtrl->SetString(MENU_COLUMN_KEY, hString);
m_pClientDE->FreeString(hString);
}
}
// Fills out the binding array (m_keyArray and m_mouseArray) for a specific input device.
void CMenuControls::FillBindingArray(DWORD dwDeviceType)
{
// Get the bindings
DeviceBinding *pBinding=m_pClientDE->GetDeviceBindings(dwDeviceType);
// Iterate through each binding setting the control text if necessary
DeviceBinding *pCurrentBinding=pBinding;
while ( pCurrentBinding != NULL )
{
if ( pCurrentBinding->pActionHead )
{
char *lpszActionName=pCurrentBinding->pActionHead->strActionName;
if ( lpszActionName )
{
// Find the action in the global list
int nIndex=GetActionIndex(lpszActionName);
if ( nIndex != -1 )
{
SetBindingInfo(nIndex, pCurrentBinding->strTriggerName, dwDeviceType);
}
}
}
pCurrentBinding=pCurrentBinding->pNext;
if ( pCurrentBinding == pBinding )
{
break;
}
}
// Free the device bindings
m_pClientDE->FreeDeviceBindings(pBinding);
}
// Adds the columns to the controls
void CMenuControls::InitColumns()
{
// Create an empty string
HSTRING hEmpty=m_pClientDE->CreateString("");
int i;
for (i=0; i < MENU_CONTROLS_NUM_ACTIONS; i++)
{
// The initial column (contains the action)
CLTGUIColumnTextCtrl *pCtrl=AddColumnTextOption(MENU_CMD_CHANGE_CONTROL, m_pMainMenus->GetSmallFont());
// The "action" column
pCtrl->AddColumn(g_nControlActionStringID[i], 100, CF_JUSTIFY_RIGHT);
// This is a buffer column to space things out on the screen
pCtrl->AddColumn(hEmpty, 11, CF_JUSTIFY_LEFT);
// The equals column. Changes from "" to "=" when the user is binding the key
pCtrl->AddColumn(hEmpty, 20, CF_JUSTIFY_LEFT);
// The column that contains the key which is assigned to the control!
pCtrl->AddColumn(IDS_MENU_KEY_UNASSIGNED, 100, CF_JUSTIFY_LEFT);
}
m_pClientDE->FreeString(hEmpty);
}
// Sets the binding array info for a device based on an action index
void CMenuControls::SetBindingInfo(int nIndex, char *lpszNewControl, DWORD dwDeviceType)
{
if (lpszNewControl == DNULL)
{
assert(DFALSE);
return;
}
// Pointer to the text
char *pDeviceText=m_deviceControlArray[GetDeviceIndexFromType(dwDeviceType)][nIndex];
// Delete the current string
if ( pDeviceText != DNULL )
{
delete []pDeviceText;
pDeviceText=DNULL;
}
// Allocate the new string
int nBufferLength=_mbstrlen(lpszNewControl)+1;
pDeviceText=new char[nBufferLength];
memset(pDeviceText, 0, nBufferLength);
// Copy the string
_mbscpy((unsigned char*)pDeviceText, (const unsigned char*)lpszNewControl);
m_deviceControlArray[GetDeviceIndexFromType(dwDeviceType)][nIndex]=pDeviceText;
}
// This finds lpszString in g_pControlActionName and returns the index to it.
// -1 is returned if the string cannot be found.
int CMenuControls::GetActionIndex(char *lpszString)
{
int i;
for (i=0; i < MENU_CONTROLS_NUM_ACTIONS; i++)
{
if ( _mbsicmp((const unsigned char*)g_pControlActionName[i], (const unsigned char*)lpszString) == 0 )
{
return i;
}
}
// Couldn't find the key
return -1;
}
// Finds the index of an action that has a specific control assigned to it.
// -1 is returned if the action cannot be found
int CMenuControls::GetControlIndex(char *lpszAction, DWORD dwDeviceType)
{
int nDeviceIndex=GetDeviceIndexFromType(dwDeviceType);
if (nDeviceIndex == -1)
{
assert(FALSE);
return -1;
}
int i;
for (i=0; i < MENU_CONTROLS_NUM_ACTIONS; i++)
{
if ( m_deviceControlArray[nDeviceIndex][i] && _mbsicmp((const unsigned char*)m_deviceControlArray[nDeviceIndex][i], (const unsigned char*)lpszAction) == 0 )
{
return i;
}
}
// Couldn't find the string
return -1;
}
// Handle device tracking
DBOOL CMenuControls::HandleDeviceTrack(DeviceInput *pInput, DDWORD dwNumDevices)
{
DBOOL bStopTracking=DFALSE;
if ( !pInput )
{
assert(DFALSE);
return bStopTracking;
}
// Get the control for the selected item
int nIndex=m_listOption.GetSelectedItem();
CLTGUIColumnTextCtrl *pCtrl=(CLTGUIColumnTextCtrl *)m_listOption.GetControl(nIndex);
// Go through each device
while (dwNumDevices--)
{
// Only accept buttons or keys on the keyboard
if (pInput->m_ControlType != CONTROLTYPE_BUTTON &&
pInput->m_ControlType != CONTROLTYPE_KEY)
{
pInput++;
continue;
}
if (pInput->m_DeviceType == DEVICETYPE_KEYBOARD)
{
// Ignore the next keyboard message
g_pBloodClientShell->IgnoreKeyboardMessage(DTRUE);
// Don't allow the tab key to be bound
if ( _mbsicmp((const unsigned char*)pInput->m_ControlName, (const unsigned char*)"Tab") == 0 )
{
pInput++;
continue;
}
// Cancel this binding of the escape key was pressed
if ( _mbsicmp((const unsigned char*)pInput->m_ControlName, (const unsigned char*)"Escape") == 0 )
{
// Remove the "=" from the display
HSTRING hEmpty=m_pClientDE->CreateString("");
pCtrl->SetString(MENU_COLUMN_EQUALS, hEmpty);
m_pClientDE->FreeString(hEmpty);
bStopTracking=DTRUE;
break;
}
}
// Make sure that this key isn't binded anywhere else
int nOtherKeyIndex=GetControlIndex(pInput->m_ControlName, pInput->m_DeviceType);
if (nOtherKeyIndex != -1)
{
// "Unbind" that key
BindControlToAction(pInput->m_ControlName, "", pInput->m_DeviceName);
SetBindingInfo(nOtherKeyIndex, "", pInput->m_DeviceType);
SetControlText(nOtherKeyIndex);
}
// Remove the binding on the current key
char *pCurrentKey=m_deviceControlArray[GetDeviceIndexFromType(pInput->m_DeviceType)][nIndex];
if ( pCurrentKey )
{
BindControlToAction(pCurrentKey, "", pInput->m_DeviceName);
}
// Bind the key and update the control text
SetBindingInfo(nIndex, pInput->m_ControlName, pInput->m_DeviceType);
SetControlText(nIndex);
BindControlToAction(pInput->m_ControlName, g_pControlActionName[nIndex], pInput->m_DeviceName);
// Remove the "=" from the display
HSTRING hEmpty=m_pClientDE->CreateString("");
pCtrl->SetString(MENU_COLUMN_EQUALS, hEmpty);
m_pClientDE->FreeString(hEmpty);
pInput++;
bStopTracking=DTRUE;
}
return bStopTracking;
}
// Binds a key to a action
void CMenuControls::BindControlToAction(char *lpszControlName, char *lpszActionName, char *lpszDevice)
{
assert(lpszControlName);
assert(lpszActionName);
assert(lpszDevice);
char tempStr[256];
// Set the binding
sprintf(tempStr, "rangebind \"%s\" \"%s\" 0 0 \"%s\"", lpszDevice, lpszControlName, lpszActionName);
m_pClientDE->RunConsoleString(tempStr);
}
// Handle a keypress
DBOOL CMenuControls::HandleKeyDown(int key, int rep)
{
// Check to see if the base class is handling this key
if (CMenuBase::HandleKeyDown(key, rep))
{
return DTRUE;
}
switch (key)
{
case VK_DELETE:
{
// Unassign the key
int nIndex=m_listOption.GetSelectedItem();
int i;
for (i=0; i < MENU_CONTROLS_NUM_DEVICES; i++)
{
if (m_deviceControlArray[i][nIndex])
{
DWORD dwDeviceType=GetDeviceTypeFromIndex(i);
// Get the mouse device name
char szBuffer[2048];
if (m_pClientDE->GetDeviceName (dwDeviceType, szBuffer, sizeof(szBuffer)) == LT_OK)
{
BindControlToAction(m_deviceControlArray[i][nIndex], "", szBuffer);
}
}
SetBindingInfo(nIndex, "", GetDeviceTypeFromIndex(i));
SetControlText(nIndex);
}
break;
}
default:
{
// Didn't handle the key
return DFALSE;
break;
}
}
// Handled the key
return DTRUE;
}
DDWORD CMenuControls::OnCommand(DDWORD dwCommand, DDWORD dwParam1, DDWORD dwParam2)
{
switch (dwCommand)
{
case MENU_CMD_CHANGE_CONTROL:
{
// Set the current menu item to ??? while tracking the device.
int nIndex=m_listOption.GetSelectedItem();
CLTGUIColumnTextCtrl *pCtrl=(CLTGUIColumnTextCtrl *)m_listOption.GetControl(nIndex);
HSTRING hEquals=m_pClientDE->CreateString("=");
pCtrl->SetString(MENU_COLUMN_EQUALS, hEquals);
m_pClientDE->FreeString(hEquals);
m_pMainMenus->StartTrackingDevices(DEVICETYPE_KEYBOARD);
m_pMainMenus->StartTrackingDevices(DEVICETYPE_MOUSE);
#ifdef USE_CONFIGURE_JOYSTICK
if (g_pBloodClientShell->IsUseJoystick())
{
m_pMainMenus->StartTrackingDevices(DEVICETYPE_JOYSTICK);
}
#endif
break;
}
}
return DTRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -