📄 menubase.cpp
字号:
CLTGUIEditCtrl *pOption=new CLTGUIEditCtrl;
if ( !pOption->Create(m_pClientDE, dwCommandID, hDescription, pFont, nEditStringOffset, nBufferSize, this, lpszValue) )
{
delete pOption;
return DNULL;
}
// Set the color
pOption->SetColor(SETRGB(220,190,170), SETRGB(125,30,0), SETRGB(96, 96, 96));
// Add the option to the list
m_listOption.AddControl(pOption);
// Add the option to the list of controls to remove
m_controlArray.Add(pOption);
return pOption;
}
/******************************************************************/
// Wrapper for adding a control with a string ID instead of an HSTRING
CLTGUIFadeItemCtrl *CMenuBase::AddFadeItemOption(char *lpszOptionSurfPrefix, int nSurfaces, int messageCode, DWORD dwCommandID, int xPos, int yPos)
{
// Load the string
HSTRING hString=DNULL;
if (messageCode)
{
hString=m_pClientDE->FormatString(messageCode);
}
// Create the control
CLTGUIFadeItemCtrl *pCtrl=AddFadeItemOption(lpszOptionSurfPrefix, nSurfaces, hString, dwCommandID, xPos, yPos);
// Free the string
if (hString)
{
m_pClientDE->FreeString(hString);
}
return pCtrl;
}
/******************************************************************/
// Wrapper for adding a control with a string ID instead of an HSTRING
CLTGUITextItemCtrl *CMenuBase::AddTextItemOption(int messageCode, DWORD dwCommandID, CLTGUIFont *pFontArray, int nNumFonts, DBOOL bDrawSolid, int *pnValue)
{
// Load the string
HSTRING hString=DNULL;
if (messageCode)
{
hString=m_pClientDE->FormatString(messageCode);
}
// Create the control
CLTGUITextItemCtrl *pCtrl=AddTextItemOption(hString, dwCommandID, pFontArray, nNumFonts, bDrawSolid, pnValue);
// Free the string
if (hString)
{
m_pClientDE->FreeString(hString);
}
return pCtrl;
}
/******************************************************************/
// Wrapper for adding a control with a string ID instead of an HSTRING
CLTGUISliderCtrl *CMenuBase::AddSliderOption(int messageCode, CLTGUIFont *pFont, int nSliderOffset, HSURFACE hBarSurf, HSURFACE hTabSurf, int *pnValue)
{
// Load the string
HSTRING hString=DNULL;
if (messageCode)
{
hString=m_pClientDE->FormatString(messageCode);
}
// Create the control
CLTGUISliderCtrl *pCtrl=AddSliderOption(hString, pFont, nSliderOffset, hBarSurf, hTabSurf, pnValue);
// Free the string
if (hString)
{
m_pClientDE->FreeString(hString);
}
return pCtrl;
}
/******************************************************************/
// Wrapper for adding a control with a string ID instead of an HSTRING
CLTGUIOnOffCtrl *CMenuBase::AddOnOffOption(int messageCode, CLTGUIFont *pFont, int nRightColumnOffset, DBOOL *pbValue)
{
// Load the string
HSTRING hString=DNULL;
if (messageCode)
{
hString=m_pClientDE->FormatString(messageCode);
}
// Create the control
CLTGUIOnOffCtrl *pCtrl=AddOnOffOption(hString, pFont, nRightColumnOffset, pbValue);
// Free the string
if (hString)
{
m_pClientDE->FreeString(hString);
}
return pCtrl;
}
/******************************************************************/
// Wrapper for adding a control with a string ID instead of an HSTRING
CLTGUIEditCtrl *CMenuBase::AddEditOption(int messageCode, DWORD dwCommandID, CLTGUIFont *pFont, int nEditStringOffset, int nBufferSize, char *lpszValue)
{
// Load the string
HSTRING hString=DNULL;
if (messageCode)
{
hString=m_pClientDE->FormatString(messageCode);
}
// Create the control
CLTGUIEditCtrl *pCtrl=AddEditOption(hString, dwCommandID, pFont, nEditStringOffset, nBufferSize, lpszValue);
// Free the string
if (hString)
{
m_pClientDE->FreeString(hString);
}
return pCtrl;
}
/******************************************************************/
// Wrapper for adding a control with a string ID instead of an HSTRING
CLTGUITextItemCtrl *CMenuBase::AddLargeTextItemOption(int messageCode, DWORD dwCommandID)
{
// Load the string
HSTRING hString=DNULL;
if (messageCode)
{
hString=m_pClientDE->FormatString(messageCode);
}
// Create the control
CLTGUITextItemCtrl *pCtrl=AddLargeTextItemOption(hString, dwCommandID);
// Free the string
if (hString)
{
m_pClientDE->FreeString(hString);
}
return pCtrl;
}
/******************************************************************/
// Turns on and off low resolution fonts for the menus
void CMenuBase::SetLowResolutionFonts(DBOOL bLowRes)
{
// Go through each control added by AddLargeTextItemOption and sets its font accordingly.
unsigned int i;
for (i=0; i < m_largeFontItemArray.GetSize(); i++)
{
if (m_largeFontItemArray[i])
{
if (bLowRes)
{
m_largeFontItemArray[i]->SetFont(m_pMainMenus->GetSmallFont());
}
else
{
// If we are using engine fonts (instead of bitmap fonts) then use
// the large font instead of the font array.
if (!m_pMainMenus->IsEnglish())
{
m_largeFontItemArray[i]->SetFont(m_pMainMenus->GetLargeFont());
}
else
{
m_largeFontItemArray[i]->SetFont(m_pMainMenus->GetLargeFadeFonts(), m_pMainMenus->GetNumLargeFadeFonts(), DFALSE);
}
}
}
}
}
/******************************************************************/
// Calls UpdateData on each control in the menu
void CMenuBase::UpdateData(DBOOL bSaveAndValidate)
{
unsigned int i;
for (i=0; i < m_controlArray.GetSize(); i++)
{
m_controlArray[i]->UpdateData(bSaveAndValidate);
}
}
/******************************************************************/
// Turns the up/down arrows on/off and sets the X position that they should be pointing
void CMenuBase::UseArrows(DBOOL bUse, int xCenter)
{
m_bShowArrows=bUse;
m_nArrowCenter=xCenter;
}
/******************************************************************/
// Set the current menu item selection. Note that this will reset any animations.
void CMenuBase::SetCurrentItem(int nItemIndex)
{
if (nItemIndex >= (int)m_controlArray.GetSize())
{
// Just set it to zero if we are out of bounds
if (m_controlArray.GetSize() > 0)
{
m_listOption.SelectItem(0);
}
}
else
{
// Set the current item
m_listOption.SelectItem(nItemIndex);
}
// Reset the animations
int i;
for (i=0; i < (int)m_controlArray.GetSize(); i++)
{
m_controlArray[i]->ResetAnimation();
}
}
/******************************************************************/
// Returns the currently selected item
CLTGUICtrl *CMenuBase::GetCurrentItem()
{
int nIndex=GetCurrentItemIndex();
if (nIndex >= 0 && nIndex < m_listOption.GetNum())
{
return m_listOption.GetControl(nIndex);
}
else
{
return DNULL;
}
}
/******************************************************************/
// Sorts a file list. This was taken from the old menu code.
FileEntry* CMenuBase::SortFileList(FileEntry *pfe)
{
FileEntry *pfindex;
FileEntry *pfList[MAX_FILE_LIST];
int nCount=0;
// Build an array of FileEntries.
pfindex = pfe;
while (pfindex && nCount < MAX_FILE_LIST)
{
pfList[nCount++] = pfindex;
pfindex = pfindex->m_pNext;
}
if (pfindex) // Free any remaining items
{
m_pClientDE->FreeFileList(pfindex);
}
for (int i = nCount / 2; i > 0; i = (i == 2) ? 1 : (int) (i / 2.2))
{
for (int j = i; j < nCount; j++)
{
FileEntry *pfTemp = pfList[j];
for (int k = j; k >= i && _mbsicmp((const unsigned char*)pfTemp->m_pBaseFilename, (const unsigned char*)pfList[k - i]->m_pBaseFilename) < 0; k -= i)
{
pfList[k] = pfList[k - i];
}
pfList[k] = pfTemp;
}
}
pfindex = pfList[0];
for (i=1; i < nCount-1; i++)
{
pfindex->m_pNext = pfList[i];
pfindex = pfindex->m_pNext;
}
pfindex->m_pNext = DNULL;
return pfList[0];
}
/******************************************************************/
// Handles a key press. Returns FALSE if the key was not processed through this method.
// Left, Up, Down, Right, and Enter are automatically passed through OnUp(), OnDown(), etc.
DBOOL CMenuBase::HandleKeyDown(int key, int rep)
{
switch (key)
{
case VK_LEFT:
{
OnLeft();
break;
}
case VK_RIGHT:
{
OnRight();
break;
}
case VK_UP:
{
OnUp();
break;
}
case VK_DOWN:
{
OnDown();
break;
}
case VK_RETURN:
{
OnEnter();
break;
}
default:
{
return m_listOption.HandleKeyDown(key, rep);
break;
}
}
// Handled the key
return DTRUE;
}
/******************************************************************/
void CMenuBase::OnUp()
{
if ( m_pMainMenus )
{
m_pMainMenus->PlaySelectSound();
}
m_listOption.OnUp();
}
/******************************************************************/
void CMenuBase::OnDown()
{
if ( m_pMainMenus )
{
m_pMainMenus->PlaySelectSound();
}
m_listOption.OnDown();
}
/******************************************************************/
void CMenuBase::OnLeft()
{
if ( m_pMainMenus )
{
m_pMainMenus->PlaySelectSound();
}
m_listOption.OnLeft();
}
/******************************************************************/
void CMenuBase::OnRight()
{
if ( m_pMainMenus )
{
m_pMainMenus->PlaySelectSound();
}
m_listOption.OnRight();
}
/******************************************************************/
void CMenuBase::OnEnter()
{
if ( m_pMainMenus )
{
m_pMainMenus->PlayEnterSound();
}
m_listOption.OnEnter();
}
/******************************************************************/
// Device tracking
DBOOL CMenuBase::HandleDeviceTrack(DeviceInput *pInput, DDWORD dwNumDevices)
{
return DFALSE;
}
/******************************************************************/
DDWORD CMenuBase::OnCommand(DDWORD dwCommand, DDWORD dwParam1, DDWORD dwParam2)
{
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -