📄 menudisplay.cpp
字号:
// MenuDisplay.cpp: implementation of the CMenuDisplay class.
//
//////////////////////////////////////////////////////////////////////
#include "MenuBase.h"
#include "MainMenus.h"
#include "MenuDisplay.h"
#include "MenuCommands.h"
#include "BloodClientShell.h"
#include "ClientRes.h"
int MenuDisplayCompare( const void *arg1, const void *arg2 )
{
MenuDisplayResolution *pRes1=(MenuDisplayResolution *)arg1;
MenuDisplayResolution *pRes2=(MenuDisplayResolution *)arg2;
if (pRes1->m_dwWidth < pRes2->m_dwWidth)
{
return -1;
}
if (pRes1->m_dwWidth > pRes2->m_dwWidth)
{
return 1;
}
else
{
if ( pRes1->m_dwHeight < pRes2->m_dwHeight )
{
return -1;
}
if ( pRes1->m_dwHeight > pRes2->m_dwHeight )
{
return 1;
}
}
return 0;
}
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CMenuDisplay::CMenuDisplay()
{
m_pRendererCtrl=DNULL;
m_pResolutionCtrl=DNULL;
m_nDetailLevel=2;
}
CMenuDisplay::~CMenuDisplay()
{
}
// Build the menu
void CMenuDisplay::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);
// Show the please wait message
m_pMainMenus->ShowSyncMessage(IDS_MENU_MESSAGE_PLEASEWAIT);
// Build the array of renderers
BuildRendererArray();
// Add the "renderer" option
m_pRendererCtrl=AddTextItemOption(DNULL, 0, m_pMainMenus->GetSmallFont());
if (!m_pRendererCtrl)
{
return;
}
unsigned int i;
for (i=0; i < m_rendererArray.GetSize(); i++)
{
// Load the renderer formating text. This is "Renderer: [%s - %s]" in English
HSTRING hRendererFormat=m_pClientDE->FormatString(IDS_MENU_DISPLAY_RENDERER, m_rendererArray[i].m_renderDll, m_rendererArray[i].m_description);
m_pRendererCtrl->AddString(hRendererFormat);
m_pClientDE->FreeString(hRendererFormat);
}
// Add the "resolution" control
m_pResolutionCtrl=AddTextItemOption(DNULL, 0, m_pMainMenus->GetSmallFont());
if (!m_pResolutionCtrl)
{
return;
}
// Setup the resolution control based on the currently selected renderer
SetupResolutionCtrl();
// Add the detail option
CLTGUITextItemCtrl *pCtrl=AddTextItemOption(DNULL, 0, m_pMainMenus->GetSmallFont(), 1, DTRUE, &m_nDetailLevel);
pCtrl->AddString(IDS_MENU_DISPLAY_DETAIL_LOW);
pCtrl->AddString(IDS_MENU_DISPLAY_DETAIL_MEDIUM);
pCtrl->AddString(IDS_MENU_DISPLAY_DETAIL_HIGH);
// Load the detail setting
HCONSOLEVAR hVar=m_pClientDE->GetConsoleVar("GlobalDetail");
if (hVar)
{
switch ((int)m_pClientDE->GetVarValueFloat(hVar))
{
case DETAIL_LOW:
{
m_nDetailLevel=0;
break;
}
case DETAIL_MEDIUM:
{
m_nDetailLevel=1;
break;
}
case DETAIL_HIGH:
{
m_nDetailLevel=2;
break;
}
}
}
else
{
m_nDetailLevel=2;
}
UpdateData(DFALSE);
}
// Setup the resolution control based on the currently selected resolution
void CMenuDisplay::SetupResolutionCtrl()
{
if (!m_pRendererCtrl || !m_pResolutionCtrl)
{
return;
}
// Clear the current resolutions
m_pResolutionCtrl->RemoveAll();
// Get the selected renderer
int nRendererIndex=m_pRendererCtrl->GetSelIndex();
// Get the number of resolutions
if (nRendererIndex > (int)m_rendererArray.GetSize()-1)
{
return;
}
unsigned int nResolutions=m_rendererArray[nRendererIndex].m_resolutionArray.GetSize();
// Add each resolution
unsigned int i;
for (i=0; i < nResolutions; i++)
{
DDWORD dwWidth=m_rendererArray[nRendererIndex].m_resolutionArray[i].m_dwWidth;
DDWORD dwHeight=m_rendererArray[nRendererIndex].m_resolutionArray[i].m_dwHeight;
DDWORD dwBitDepth=m_rendererArray[nRendererIndex].m_resolutionArray[i].m_dwBitDepth;
// Load the resolution format string. This is "Resolution: [%dx%dx%d]" in English
HSTRING hResolutionFormat=m_pClientDE->FormatString(IDS_MENU_DISPLAY_RESOLUTION, dwWidth, dwHeight, dwBitDepth);
m_pResolutionCtrl->AddString(hResolutionFormat);
m_pClientDE->FreeString(hResolutionFormat);
}
m_pResolutionCtrl->SetSelIndex(0);
}
// Build the array of renderers
void CMenuDisplay::BuildRendererArray()
{
// Clear the current renderer arrays
unsigned int i;
for (i=0; i < m_rendererArray.GetSize(); i++)
{
m_rendererArray[i].m_resolutionArray.SetSize(0);
}
m_rendererArray.SetSize(0);
// Build the list of render modes
RMode *pRenderModes=m_pClientDE->GetRenderModes();
// Iterate through the list of render modes adding each one to the array
RMode *pCurrentMode=pRenderModes;
while (pCurrentMode != DNULL)
{
// Get the index for this renderer
int nRenderIndex=GetRendererIndex(pCurrentMode);
// Check to see if we need to add this renderer
if (nRenderIndex == -1)
{
MenuDisplayRenderer renderer;
renderer.m_bHardware=pCurrentMode->m_bHardware;
_mbscpy((unsigned char*)renderer.m_renderDll, (const unsigned char*)pCurrentMode->m_RenderDLL);
_mbscpy((unsigned char*)renderer.m_description, (const unsigned char*)pCurrentMode->m_Description);
_mbscpy((unsigned char*)renderer.m_internalName, (const unsigned char*)pCurrentMode->m_InternalName);
m_rendererArray.Add(renderer);
nRenderIndex=m_rendererArray.GetSize()-1;
}
// Add the display resolutions for this renderer
MenuDisplayResolution resolution;
resolution.m_dwWidth=pCurrentMode->m_Width;
resolution.m_dwHeight=pCurrentMode->m_Height;
resolution.m_dwBitDepth=pCurrentMode->m_BitDepth;
m_rendererArray[nRenderIndex].m_resolutionArray.Add(resolution);
// Go to the next render mode
pCurrentMode=pCurrentMode->m_pNext;
}
// Free the linked list of render modes
m_pClientDE->RelinquishRenderModes(pRenderModes);
// Sort the render resolution based on screen width and height
for (i=0; i < m_rendererArray.GetSize(); i++)
{
SortRenderModes(i);
}
}
// Sort the render resolution based on screen width and height
void CMenuDisplay::SortRenderModes(int nRendererIndex)
{
// Build a temporary array of render modes
int nResolutions=m_rendererArray[nRendererIndex].m_resolutionArray.GetSize();
if ( nResolutions < 1 )
{
return;
}
MenuDisplayResolution *pResolutions = new MenuDisplayResolution[nResolutions];
int i;
for (i=0; i < nResolutions; i++)
{
pResolutions[i]=m_rendererArray[nRendererIndex].m_resolutionArray[i];
}
// Sort the array
qsort(pResolutions, nResolutions, sizeof(MenuDisplayResolution), MenuDisplayCompare);
// Clear the current renderer resolutions array
m_rendererArray[nRendererIndex].m_resolutionArray.SetSize(0);
// Copy the sorted array back to the resolutions array
for (i=0; i < nResolutions; i++)
{
m_rendererArray[nRendererIndex].m_resolutionArray.Add(pResolutions[i]);
}
}
// Returns an index into m_rendererArray for this renderer.
// -1 is returned if it cannot be found
int CMenuDisplay::GetRendererIndex(RMode *pMode)
{
assert(pMode);
if (!pMode)
{
return -1;
}
// Find out if this renderer already exists in the array
int nRenderIndex=-1;
unsigned int i;
for (i=0; i < m_rendererArray.GetSize(); i++)
{
if (_mbsicmp((const unsigned char*)m_rendererArray[i].m_description, (const unsigned char*)pMode->m_Description) == 0 &&
_mbsicmp((const unsigned char*)m_rendererArray[i].m_renderDll, (const unsigned char*)pMode->m_RenderDLL) == 0)
{
nRenderIndex=i;
break;
}
}
return nRenderIndex;
}
// Sets the renderer
DBOOL CMenuDisplay::SetRenderer(int nRendererIndex, int nResolutionIndex)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -