GameExecutable: Fix } else { formatting.

Make code more readable.
This commit is contained in:
zcaliptium 2016-03-31 22:57:40 +03:00
parent 6434adfc1b
commit 80471f5041
13 changed files with 60 additions and 86 deletions

View File

@ -29,16 +29,14 @@ void CMGArrow::Render(CDrawPort *pdp)
CTString str; CTString str;
if (mg_adDirection == AD_NONE) { if (mg_adDirection == AD_NONE) {
str = "???"; str = "???";
} } else if (mg_adDirection == AD_UP) {
else if (mg_adDirection == AD_UP) {
str = TRANS("Page Up"); str = TRANS("Page Up");
} } else if (mg_adDirection == AD_DOWN) {
else if (mg_adDirection == AD_DOWN) {
str = TRANS("Page Down"); str = TRANS("Page Down");
} } else {
else {
ASSERT(FALSE); ASSERT(FALSE);
} }
PIX pixI = box.Min()(1); PIX pixI = box.Min()(1);
PIX pixJ = box.Min()(2); PIX pixJ = box.Min()(2);
pdp->PutText(str, pixI, pixJ, col); pdp->PutText(str, pixI, pixJ, col);

View File

@ -62,11 +62,9 @@ void CMGButton::Render(CDrawPort *pdp)
{ {
if (mg_bfsFontSize == BFS_LARGE) { if (mg_bfsFontSize == BFS_LARGE) {
SetFontBig(pdp); SetFontBig(pdp);
} } else if (mg_bfsFontSize == BFS_MEDIUM) {
else if (mg_bfsFontSize == BFS_MEDIUM) {
SetFontMedium(pdp); SetFontMedium(pdp);
} } else {
else {
ASSERT(mg_bfsFontSize == BFS_SMALL); ASSERT(mg_bfsFontSize == BFS_SMALL);
SetFontSmall(pdp); SetFontSmall(pdp);
} }
@ -159,6 +157,7 @@ void CMGButton::Render(CDrawPort *pdp)
if (mg_strLabel != "") { if (mg_strLabel != "") {
pixX += box.Size()(1)*0.55f; pixX += box.Size()(1)*0.55f;
} }
PIX pixY = box.Min()(2); PIX pixY = box.Min()(2);
if (!pdp->dp_FontData->fd_bFixedWidth) { if (!pdp->dp_FontData->fd_bFixedWidth) {
pixY -= pdp->dp_fTextScaling * 2; pixY -= pdp->dp_fTextScaling * 2;

View File

@ -27,10 +27,13 @@ void CMGChangePlayer::OnActivate(void)
PlayMenuSound(_psdPress); PlayMenuSound(_psdPress);
IFeel_PlayEffect("Menu_press"); IFeel_PlayEffect("Menu_press");
_iLocalPlayer = mg_iLocalPlayer; _iLocalPlayer = mg_iLocalPlayer;
if (_pGame->gm_aiMenuLocalPlayers[mg_iLocalPlayer] < 0) if (_pGame->gm_aiMenuLocalPlayers[mg_iLocalPlayer] < 0)
_pGame->gm_aiMenuLocalPlayers[mg_iLocalPlayer] = 0; _pGame->gm_aiMenuLocalPlayers[mg_iLocalPlayer] = 0;
_pGUIM->gmPlayerProfile.gm_piCurrentPlayer = &_pGame->gm_aiMenuLocalPlayers[mg_iLocalPlayer]; _pGUIM->gmPlayerProfile.gm_piCurrentPlayer = &_pGame->gm_aiMenuLocalPlayers[mg_iLocalPlayer];
_pGUIM->gmPlayerProfile.gm_pgmParentMenu = &_pGUIM->gmSelectPlayersMenu; _pGUIM->gmPlayerProfile.gm_pgmParentMenu = &_pGUIM->gmSelectPlayersMenu;
extern BOOL _bPlayerMenuFromSinglePlayer; extern BOOL _bPlayerMenuFromSinglePlayer;
_bPlayerMenuFromSinglePlayer = FALSE; _bPlayerMenuFromSinglePlayer = FALSE;
ChangeToMenu(&_pGUIM->gmPlayerProfile); ChangeToMenu(&_pGUIM->gmPlayerProfile);
@ -40,10 +43,10 @@ void CMGChangePlayer::SetPlayerText(void)
{ {
INDEX iPlayer = _pGame->gm_aiMenuLocalPlayers[mg_iLocalPlayer]; INDEX iPlayer = _pGame->gm_aiMenuLocalPlayers[mg_iLocalPlayer];
CPlayerCharacter &pc = _pGame->gm_apcPlayers[iPlayer]; CPlayerCharacter &pc = _pGame->gm_apcPlayers[iPlayer];
if (iPlayer<0 || iPlayer>7) { if (iPlayer<0 || iPlayer>7) {
mg_strText = "????"; mg_strText = "????";
} } else {
else {
mg_strText.PrintF(TRANS("Player %d: %s\n"), mg_iLocalPlayer + 1, pc.GetNameForPrinting()); mg_strText.PrintF(TRANS("Player %d: %s\n"), mg_iLocalPlayer + 1, pc.GetNameForPrinting());
} }
} }

View File

@ -74,8 +74,7 @@ static void Key_BackDel(CTString &str, INDEX &iPos, BOOL bShift, BOOL bRight)
if (bShift) { if (bShift) {
// delete to end of line // delete to end of line
str.TrimRight(iPos); str.TrimRight(iPos);
} } else {
else {
// delete only one char // delete only one char
str.DeleteChar(iPos); str.DeleteChar(iPos);
} }
@ -85,8 +84,7 @@ static void Key_BackDel(CTString &str, INDEX &iPos, BOOL bShift, BOOL bRight)
// delete to start of line // delete to start of line
str.TrimLeft(ctChars - iPos); str.TrimLeft(ctChars - iPos);
iPos = 0; iPos = 0;
} } else {
else {
// delete only one char // delete only one char
str.DeleteChar(iPos - 1); str.DeleteChar(iPos - 1);
iPos--; iPos--;
@ -147,24 +145,21 @@ void CMGEdit::Render(CDrawPort *pdp)
{ {
if (mg_bEditing) { if (mg_bEditing) {
mg_iTextMode = -1; mg_iTextMode = -1;
} } else if (mg_bFocused) {
else if (mg_bFocused) {
mg_iTextMode = 0; mg_iTextMode = 0;
} } else {
else {
mg_iTextMode = 1; mg_iTextMode = 1;
} }
if (mg_strText == "" && !mg_bEditing) { if (mg_strText == "" && !mg_bEditing) {
if (mg_bfsFontSize == BFS_SMALL) { if (mg_bfsFontSize == BFS_SMALL) {
mg_strText = "*"; mg_strText = "*";
} } else {
else {
mg_strText = TRANS("<none>"); mg_strText = TRANS("<none>");
} }
CMGButton::Render(pdp); CMGButton::Render(pdp);
mg_strText = ""; mg_strText = "";
} } else {
else {
CMGButton::Render(pdp); CMGButton::Render(pdp);
} }
} }

View File

@ -42,8 +42,7 @@ void CMGFileButton::SaveDescription(void)
CTFileName fnFileNameDescription = mg_fnm.NoExt() + ".des"; CTFileName fnFileNameDescription = mg_fnm.NoExt() + ".des";
try { try {
mg_strDes.Save_t(fnFileNameDescription); mg_strDes.Save_t(fnFileNameDescription);
} } catch (char *strError) {
catch (char *strError) {
CPrintF("%s\n", strError); CPrintF("%s\n", strError);
} }
} }
@ -62,8 +61,7 @@ void CMGFileButton::DoSave(void)
_pmgFileToSave = this; _pmgFileToSave = this;
extern void SaveConfirm(void); extern void SaveConfirm(void);
SaveConfirm(); SaveConfirm();
} } else {
else {
SaveYes(); SaveYes();
} }
} }
@ -118,16 +116,17 @@ void CMGFileButton::OnActivate(void)
// load now // load now
DoLoad(); DoLoad();
// if saving // if saving
} } else {
else {
// switch to editing mode // switch to editing mode
BOOL bWasEmpty = mg_strText == EMPTYSLOTSTRING; BOOL bWasEmpty = mg_strText == EMPTYSLOTSTRING;
mg_strDes = _pGUIM->gmLoadSaveMenu.gm_strSaveDes; mg_strDes = _pGUIM->gmLoadSaveMenu.gm_strSaveDes;
RefreshText(); RefreshText();
_strOrgDescription = _strTmpDescription = mg_strText; _strOrgDescription = _strTmpDescription = mg_strText;
if (bWasEmpty) { if (bWasEmpty) {
_strOrgDescription = EMPTYSLOTSTRING; _strOrgDescription = EMPTYSLOTSTRING;
} }
mg_pstrToChange = &_strTmpDescription; mg_pstrToChange = &_strTmpDescription;
StartEdit(); StartEdit();
mg_iState = FBS_SAVENAME; mg_iState = FBS_SAVENAME;
@ -148,8 +147,8 @@ BOOL CMGFileButton::OnKeyDown(int iVKey)
mg_iState = FBS_RENAME; mg_iState = FBS_RENAME;
} }
return TRUE; return TRUE;
}
else if (iVKey == VK_DELETE) { } else if (iVKey == VK_DELETE) {
if (FileExistsForWriting(mg_fnm)) { if (FileExistsForWriting(mg_fnm)) {
// delete the file, its description and thumbnail // delete the file, its description and thumbnail
RemoveFile(mg_fnm); RemoveFile(mg_fnm);
@ -164,8 +163,7 @@ BOOL CMGFileButton::OnKeyDown(int iVKey)
} }
} }
return CMenuGadget::OnKeyDown(iVKey); return CMenuGadget::OnKeyDown(iVKey);
} } else {
else {
// go out of editing mode // go out of editing mode
if (mg_bEditing) { if (mg_bEditing) {
if (iVKey == VK_UP || iVKey == VK_DOWN) { if (iVKey == VK_UP || iVKey == VK_DOWN) {
@ -185,6 +183,7 @@ void CMGFileButton::OnSetFocus(void)
} else { } else {
ClearThumbnail(); ClearThumbnail();
} }
pgmCurrentMenu->KillAllFocuses(); pgmCurrentMenu->KillAllFocuses();
CMGButton::OnSetFocus(); CMGButton::OnSetFocus();
} }
@ -195,6 +194,7 @@ void CMGFileButton::OnKillFocus(void)
if (mg_bEditing) { if (mg_bEditing) {
OnKeyDown(VK_ESCAPE); OnKeyDown(VK_ESCAPE);
} }
CMGEdit::OnKillFocus(); CMGEdit::OnKillFocus();
} }
@ -207,8 +207,7 @@ void CMGFileButton::OnStringChanged(void)
mg_strDes = _strTmpDescription + "\n" + mg_strInfo; mg_strDes = _strTmpDescription + "\n" + mg_strInfo;
DoSave(); DoSave();
// if renaming // if renaming
} } else if (mg_iState == FBS_RENAME) {
else if (mg_iState == FBS_RENAME) {
// do the rename // do the rename
mg_strDes = _strTmpDescription + "\n" + mg_strInfo; mg_strDes = _strTmpDescription + "\n" + mg_strInfo;
SaveDescription(); SaveDescription();

View File

@ -94,8 +94,7 @@ void CMGHighScore::Render(CDrawPort *pdp)
}} }}
if (iRow == 0) { if (iRow == 0) {
pixJ += pdp->GetHeight()*0.06f; pixJ += pdp->GetHeight()*0.06f;
} } else {
else {
pixJ += pdp->GetHeight()*0.04f; pixJ += pdp->GetHeight()*0.04f;
} }
}} }}

View File

@ -80,8 +80,7 @@ void CMGKeyDefinition::SetBindingNames(BOOL bDefining)
// put question mark for second key // put question mark for second key
mg_strBinding = strKey1 + TRANS(" or ") + "?"; mg_strBinding = strKey1 + TRANS(" or ") + "?";
// otherwise // otherwise
} } else {
else {
// put question mark only // put question mark only
mg_strBinding = "?"; mg_strBinding = "?";
} }
@ -93,8 +92,7 @@ void CMGKeyDefinition::SetBindingNames(BOOL bDefining)
// add both // add both
mg_strBinding = strKey1 + TRANS(" or ") + strKey2; mg_strBinding = strKey1 + TRANS(" or ") + strKey2;
// if second key is undefined // if second key is undefined
} } else {
else {
// display only first one // display only first one
mg_strBinding = strKey1; mg_strBinding = strKey1;
} }
@ -140,14 +138,12 @@ void CMGKeyDefinition::DefineKey(INDEX iDik)
// clear second key // clear second key
ba.ba_iSecondKey = KID_NONE; ba.ba_iSecondKey = KID_NONE;
// if only first key bound // if only first key bound
} } else {
else {
// bind second key // bind second key
ba.ba_iSecondKey = iDik; ba.ba_iSecondKey = iDik;
} }
// if it is not this one // if it is not this one
} } else {
else {
// clear bindings that contain this key // clear bindings that contain this key
if (ba.ba_iFirstKey == iDik) { if (ba.ba_iFirstKey == iDik) {
ba.ba_iFirstKey = KID_NONE; ba.ba_iFirstKey = KID_NONE;
@ -195,8 +191,7 @@ void CMGKeyDefinition::Think(void)
// define the new key // define the new key
DefineKey(iDik); DefineKey(iDik);
// if escape pressed // if escape pressed
} } else {
else {
// undefine the key // undefine the key
DefineKey(KID_NONE); DefineKey(KID_NONE);
} }

View File

@ -67,8 +67,7 @@ void CMGServerList::AdjustFirstOnScreen(void)
if (mg_iSelected<mg_iFirstOnScreen) { if (mg_iSelected<mg_iFirstOnScreen) {
mg_iFirstOnScreen = ClampUp(mg_iSelected, ClampDn(ctSessions - mg_ctOnScreen - 1L, 0L)); mg_iFirstOnScreen = ClampUp(mg_iSelected, ClampDn(ctSessions - mg_ctOnScreen - 1L, 0L));
} } else if (mg_iSelected >= mg_iFirstOnScreen + mg_ctOnScreen) {
else if (mg_iSelected >= mg_iFirstOnScreen + mg_ctOnScreen) {
mg_iFirstOnScreen = ClampDn(mg_iSelected - mg_ctOnScreen + 1L, 0L); mg_iFirstOnScreen = ClampDn(mg_iSelected - mg_ctOnScreen + 1L, 0L);
} }
} }
@ -107,8 +106,8 @@ void SortAndFilterServers(void)
{FORDELETELIST(CNetworkSession, ns_lnNode, _lhServers, itns) { {FORDELETELIST(CNetworkSession, ns_lnNode, _lhServers, itns) {
delete &*itns; delete &*itns;
}} }}
{
FOREACHINLIST(CNetworkSession, ns_lnNode, _pNetwork->ga_lhEnumeratedSessions, itns) { {FOREACHINLIST(CNetworkSession, ns_lnNode, _pNetwork->ga_lhEnumeratedSessions, itns) {
CNetworkSession &ns = *itns; CNetworkSession &ns = *itns;
extern CTString _strServerFilter[7]; extern CTString _strServerFilter[7];
if (_strServerFilter[0] != "" && !ns.ns_strSession.Matches("*" + _strServerFilter[0] + "*")) continue; if (_strServerFilter[0] != "" && !ns.ns_strSession.Matches("*" + _strServerFilter[0] + "*")) continue;
@ -245,8 +244,7 @@ void CMGServerList::Render(CDrawPort *pdp)
PrintInBox(pdp, apixSeparatorI[0] + pixCharSizeI, pixListTopJ + pixCharSizeJ + pixLineSize + 1, apixSeparatorI[1] - apixSeparatorI[0], PrintInBox(pdp, apixSeparatorI[0] + pixCharSizeI, pixListTopJ + pixCharSizeJ + pixLineSize + 1, apixSeparatorI[1] - apixSeparatorI[0],
TRANS("searching..."), colItem); TRANS("searching..."), colItem);
} }
} } else {
else {
FOREACHINLIST(CNetworkSession, ns_lnNode, _lhServers, itns) { FOREACHINLIST(CNetworkSession, ns_lnNode, _lhServers, itns) {
CNetworkSession &ns = *itns; CNetworkSession &ns = *itns;
@ -352,8 +350,7 @@ void CMGServerList::OnMouseOver(PIX pixI, PIX pixJ)
AdjustFirstOnScreen(); AdjustFirstOnScreen();
mg_pixMouseDrag = -1; mg_pixMouseDrag = -1;
} }
} } else if (bInSlider) {
else if (bInSlider) {
mg_pixMouseDrag = pixJ; mg_pixMouseDrag = pixJ;
} }
} }

View File

@ -60,14 +60,12 @@ BOOL CMGSlider::OnKeyDown(int iVKey)
ApplyCurrentPosition(); ApplyCurrentPosition();
return TRUE; return TRUE;
// if scrolling right // if scrolling right
} } else if ((iVKey == VK_RETURN || iVKey == VK_RIGHT) && mg_iCurPos<mg_iMaxPos) {
else if ((iVKey == VK_RETURN || iVKey == VK_RIGHT) && mg_iCurPos<mg_iMaxPos) {
mg_iCurPos++; mg_iCurPos++;
ApplyCurrentPosition(); ApplyCurrentPosition();
return TRUE; return TRUE;
// if lmb pressed // if lmb pressed
} } else if (iVKey == VK_LBUTTON) {
else if (iVKey == VK_LBUTTON) {
// get position of slider box on screen // get position of slider box on screen
PIXaabbox2D boxSlider = GetSliderBox(); PIXaabbox2D boxSlider = GetSliderBox();
// if mouse is within // if mouse is within

View File

@ -27,10 +27,8 @@ INDEX GetNewLoopValue(int iVKey, INDEX iCurrent, INDEX ctMembers)
if (iVKey == VK_RETURN || iVKey == VK_LBUTTON || iVKey == VK_RIGHT) if (iVKey == VK_RETURN || iVKey == VK_LBUTTON || iVKey == VK_RIGHT)
{ {
return iNext; return iNext;
}
// left arrow and backspace sets prev text // left arrow and backspace sets prev text
else if ((iVKey == VK_BACK || iVKey == VK_RBUTTON) || (iVKey == VK_LEFT)) } else if ((iVKey == VK_BACK || iVKey == VK_RBUTTON) || (iVKey == VK_LEFT)) {
{
return iPrev; return iPrev;
} }
return iCurrent; return iCurrent;
@ -94,16 +92,15 @@ void CMGTrigger::Render(CDrawPort *pdp)
if (mg_bVisual) { if (mg_bVisual) {
strValue = TRANS("none"); strValue = TRANS("none");
} }
if (mg_iCenterI == -1) { if (mg_iCenterI == -1) {
pdp->PutText(mg_strLabel, box.Min()(1), pixJ, col); pdp->PutText(mg_strLabel, box.Min()(1), pixJ, col);
pdp->PutTextR(strValue, box.Max()(1), pixJ, col); pdp->PutTextR(strValue, box.Max()(1), pixJ, col);
} } else {
else {
pdp->PutTextR(mg_strLabel, pixIL, pixJ, col); pdp->PutTextR(mg_strLabel, pixIL, pixJ, col);
pdp->PutText(strValue, pixIR, pixJ, col); pdp->PutText(strValue, pixIR, pixJ, col);
} }
} } else {
else {
CTString strLabel = mg_strLabel + ": "; CTString strLabel = mg_strLabel + ": ";
pdp->PutText(strLabel, box.Min()(1), pixJ, col); pdp->PutText(strLabel, box.Min()(1), pixJ, col);
CTextureObject to; CTextureObject to;
@ -116,8 +113,7 @@ void CMGTrigger::Render(CDrawPort *pdp)
pdp->PutTexture(&to, PIXaabbox2D( pdp->PutTexture(&to, PIXaabbox2D(
PIX2D(pixCX - pixSize / 2, pixCY - pixSize / 2), PIX2D(pixCX - pixSize / 2, pixCY - pixSize / 2),
PIX2D(pixCX - pixSize / 2 + pixSize, pixCY - pixSize / 2 + pixSize)), C_WHITE | 255); PIX2D(pixCX - pixSize / 2 + pixSize, pixCY - pixSize / 2 + pixSize)), C_WHITE | 255);
} } catch (char *strError) {
catch (char *strError) {
CPrintF("%s\n", strError); CPrintF("%s\n", strError);
} }
to.SetData(NULL); to.SetData(NULL);

View File

@ -141,9 +141,7 @@ void CMGVarButton::Render(CDrawPort *pdp)
COLOR col = LCDGetColor(C_WHITE | 255, "separator"); COLOR col = LCDGetColor(C_WHITE | 255, "separator");
CTString strText = mg_pvsVar->vs_strName; CTString strText = mg_pvsVar->vs_strName;
pdp->PutTextC(strText, pixIC, pixJ, col); pdp->PutTextC(strText, pixIC, pixJ, col);
} } else if (mg_pvsVar->Validate()) {
else if (mg_pvsVar->Validate())
{
// check whether the variable is disabled // check whether the variable is disabled
if (mg_pvsVar->vs_strFilter != "") mg_bEnabled = _pShell->GetINDEX(mg_pvsVar->vs_strFilter); if (mg_pvsVar->vs_strFilter != "") mg_bEnabled = _pShell->GetINDEX(mg_pvsVar->vs_strFilter);
COLOR col = GetCurrentColor(); COLOR col = GetCurrentColor();
@ -160,13 +158,13 @@ void CMGVarButton::Render(CDrawPort *pdp)
PIX pixJSize = box.Size()(2); PIX pixJSize = box.Size()(2);
LCDDrawBox(0, -1, PIXaabbox2D(PIX2D(pixIR, pixJ + 1), PIX2D(pixIR + pixISize - 4, pixJ + pixJSize - 6)), LCDDrawBox(0, -1, PIXaabbox2D(PIX2D(pixIR, pixJ + 1), PIX2D(pixIR + pixISize - 4, pixJ + pixJSize - 6)),
LCDGetColor(C_GREEN | 255, "slider box")); LCDGetColor(C_GREEN | 255, "slider box"));
// draw filled part of slider // draw filled part of slider
if (mg_pvsVar->vs_iSlider == 1) { if (mg_pvsVar->vs_iSlider == 1) {
// fill slider // fill slider
FLOAT fFactor = (FLOAT)(mg_pvsVar->vs_iValue + 1) / mg_pvsVar->vs_ctValues; FLOAT fFactor = (FLOAT)(mg_pvsVar->vs_iValue + 1) / mg_pvsVar->vs_ctValues;
pdp->Fill(pixIR + 1, pixJ + 2, (pixISize - 6)*fFactor, pixJSize - 9, col); pdp->Fill(pixIR + 1, pixJ + 2, (pixISize - 6)*fFactor, pixJSize - 9, col);
} } else {
else {
// ratio slider // ratio slider
ASSERT(mg_pvsVar->vs_iSlider == 2); ASSERT(mg_pvsVar->vs_iSlider == 2);
FLOAT fUnitWidth = (FLOAT)(pixISize - 5) / mg_pvsVar->vs_ctValues; FLOAT fUnitWidth = (FLOAT)(pixISize - 5) / mg_pvsVar->vs_ctValues;

View File

@ -325,8 +325,7 @@ void CGameMenu::StartMenu(void)
// hide it // hide it
itmg->mg_bVisible = FALSE; itmg->mg_bVisible = FALSE;
// if in list // if in list
} } else if (itmg->mg_iInList >= 0) {
else if (itmg->mg_iInList >= 0) {
// show it // show it
itmg->mg_bVisible = TRUE; itmg->mg_bVisible = TRUE;
} }

View File

@ -1364,10 +1364,8 @@ BOOL TryToSetDisplayMode( enum GfxAPIType eGfxAPI, INDEX iAdapter, PIX pixSizeI,
// report success // report success
return TRUE; return TRUE;
}
// if couldn't set new mode // if couldn't set new mode
else { } else {
// close the application window // close the application window
CloseMainWindow(); CloseMainWindow();
// report failure // report failure