From 80471f50414fbbbb9a6eca4905f2c0bcdf1dbda3 Mon Sep 17 00:00:00 2001 From: zcaliptium Date: Thu, 31 Mar 2016 22:57:40 +0300 Subject: [PATCH] GameExecutable: Fix } else { formatting. Make code more readable. --- Sources/SeriousSam/GUI/Components/MGArrow.cpp | 10 +++----- .../SeriousSam/GUI/Components/MGButton.cpp | 7 +++--- .../GUI/Components/MGChangePlayer.cpp | 7 ++++-- Sources/SeriousSam/GUI/Components/MGEdit.cpp | 19 ++++++-------- .../GUI/Components/MGFileButton.cpp | 25 +++++++++---------- .../SeriousSam/GUI/Components/MGHighScore.cpp | 3 +-- .../GUI/Components/MGKeyDefinition.cpp | 21 ++++++---------- .../GUI/Components/MGServerList.cpp | 17 ++++++------- .../SeriousSam/GUI/Components/MGSlider.cpp | 6 ++--- .../SeriousSam/GUI/Components/MGTrigger.cpp | 14 ++++------- .../SeriousSam/GUI/Components/MGVarButton.cpp | 8 +++--- Sources/SeriousSam/GUI/Menus/GameMenu.cpp | 5 ++-- Sources/SeriousSam/SeriousSam.cpp | 4 +-- 13 files changed, 60 insertions(+), 86 deletions(-) diff --git a/Sources/SeriousSam/GUI/Components/MGArrow.cpp b/Sources/SeriousSam/GUI/Components/MGArrow.cpp index c88d1c4..ce7ccde 100644 --- a/Sources/SeriousSam/GUI/Components/MGArrow.cpp +++ b/Sources/SeriousSam/GUI/Components/MGArrow.cpp @@ -29,16 +29,14 @@ void CMGArrow::Render(CDrawPort *pdp) CTString str; if (mg_adDirection == AD_NONE) { str = "???"; - } - else if (mg_adDirection == AD_UP) { + } else if (mg_adDirection == AD_UP) { str = TRANS("Page Up"); - } - else if (mg_adDirection == AD_DOWN) { + } else if (mg_adDirection == AD_DOWN) { str = TRANS("Page Down"); - } - else { + } else { ASSERT(FALSE); } + PIX pixI = box.Min()(1); PIX pixJ = box.Min()(2); pdp->PutText(str, pixI, pixJ, col); diff --git a/Sources/SeriousSam/GUI/Components/MGButton.cpp b/Sources/SeriousSam/GUI/Components/MGButton.cpp index d45323a..2747988 100644 --- a/Sources/SeriousSam/GUI/Components/MGButton.cpp +++ b/Sources/SeriousSam/GUI/Components/MGButton.cpp @@ -62,11 +62,9 @@ void CMGButton::Render(CDrawPort *pdp) { if (mg_bfsFontSize == BFS_LARGE) { SetFontBig(pdp); - } - else if (mg_bfsFontSize == BFS_MEDIUM) { + } else if (mg_bfsFontSize == BFS_MEDIUM) { SetFontMedium(pdp); - } - else { + } else { ASSERT(mg_bfsFontSize == BFS_SMALL); SetFontSmall(pdp); } @@ -159,6 +157,7 @@ void CMGButton::Render(CDrawPort *pdp) if (mg_strLabel != "") { pixX += box.Size()(1)*0.55f; } + PIX pixY = box.Min()(2); if (!pdp->dp_FontData->fd_bFixedWidth) { pixY -= pdp->dp_fTextScaling * 2; diff --git a/Sources/SeriousSam/GUI/Components/MGChangePlayer.cpp b/Sources/SeriousSam/GUI/Components/MGChangePlayer.cpp index 2ae4818..bed5e08 100644 --- a/Sources/SeriousSam/GUI/Components/MGChangePlayer.cpp +++ b/Sources/SeriousSam/GUI/Components/MGChangePlayer.cpp @@ -27,10 +27,13 @@ void CMGChangePlayer::OnActivate(void) PlayMenuSound(_psdPress); IFeel_PlayEffect("Menu_press"); _iLocalPlayer = mg_iLocalPlayer; + if (_pGame->gm_aiMenuLocalPlayers[mg_iLocalPlayer] < 0) _pGame->gm_aiMenuLocalPlayers[mg_iLocalPlayer] = 0; + _pGUIM->gmPlayerProfile.gm_piCurrentPlayer = &_pGame->gm_aiMenuLocalPlayers[mg_iLocalPlayer]; _pGUIM->gmPlayerProfile.gm_pgmParentMenu = &_pGUIM->gmSelectPlayersMenu; + extern BOOL _bPlayerMenuFromSinglePlayer; _bPlayerMenuFromSinglePlayer = FALSE; ChangeToMenu(&_pGUIM->gmPlayerProfile); @@ -40,10 +43,10 @@ void CMGChangePlayer::SetPlayerText(void) { INDEX iPlayer = _pGame->gm_aiMenuLocalPlayers[mg_iLocalPlayer]; CPlayerCharacter &pc = _pGame->gm_apcPlayers[iPlayer]; + if (iPlayer<0 || iPlayer>7) { mg_strText = "????"; - } - else { + } else { mg_strText.PrintF(TRANS("Player %d: %s\n"), mg_iLocalPlayer + 1, pc.GetNameForPrinting()); } } \ No newline at end of file diff --git a/Sources/SeriousSam/GUI/Components/MGEdit.cpp b/Sources/SeriousSam/GUI/Components/MGEdit.cpp index 10a077f..b50f78b 100644 --- a/Sources/SeriousSam/GUI/Components/MGEdit.cpp +++ b/Sources/SeriousSam/GUI/Components/MGEdit.cpp @@ -74,8 +74,7 @@ static void Key_BackDel(CTString &str, INDEX &iPos, BOOL bShift, BOOL bRight) if (bShift) { // delete to end of line str.TrimRight(iPos); - } - else { + } else { // delete only one char str.DeleteChar(iPos); } @@ -85,8 +84,7 @@ static void Key_BackDel(CTString &str, INDEX &iPos, BOOL bShift, BOOL bRight) // delete to start of line str.TrimLeft(ctChars - iPos); iPos = 0; - } - else { + } else { // delete only one char str.DeleteChar(iPos - 1); iPos--; @@ -147,24 +145,21 @@ void CMGEdit::Render(CDrawPort *pdp) { if (mg_bEditing) { mg_iTextMode = -1; - } - else if (mg_bFocused) { + } else if (mg_bFocused) { mg_iTextMode = 0; - } - else { + } else { mg_iTextMode = 1; } + if (mg_strText == "" && !mg_bEditing) { if (mg_bfsFontSize == BFS_SMALL) { mg_strText = "*"; - } - else { + } else { mg_strText = TRANS(""); } CMGButton::Render(pdp); mg_strText = ""; - } - else { + } else { CMGButton::Render(pdp); } } diff --git a/Sources/SeriousSam/GUI/Components/MGFileButton.cpp b/Sources/SeriousSam/GUI/Components/MGFileButton.cpp index b1af656..d530ad3 100644 --- a/Sources/SeriousSam/GUI/Components/MGFileButton.cpp +++ b/Sources/SeriousSam/GUI/Components/MGFileButton.cpp @@ -42,8 +42,7 @@ void CMGFileButton::SaveDescription(void) CTFileName fnFileNameDescription = mg_fnm.NoExt() + ".des"; try { mg_strDes.Save_t(fnFileNameDescription); - } - catch (char *strError) { + } catch (char *strError) { CPrintF("%s\n", strError); } } @@ -62,8 +61,7 @@ void CMGFileButton::DoSave(void) _pmgFileToSave = this; extern void SaveConfirm(void); SaveConfirm(); - } - else { + } else { SaveYes(); } } @@ -118,16 +116,17 @@ void CMGFileButton::OnActivate(void) // load now DoLoad(); // if saving - } - else { + } else { // switch to editing mode BOOL bWasEmpty = mg_strText == EMPTYSLOTSTRING; mg_strDes = _pGUIM->gmLoadSaveMenu.gm_strSaveDes; RefreshText(); _strOrgDescription = _strTmpDescription = mg_strText; + if (bWasEmpty) { _strOrgDescription = EMPTYSLOTSTRING; } + mg_pstrToChange = &_strTmpDescription; StartEdit(); mg_iState = FBS_SAVENAME; @@ -148,8 +147,8 @@ BOOL CMGFileButton::OnKeyDown(int iVKey) mg_iState = FBS_RENAME; } return TRUE; - } - else if (iVKey == VK_DELETE) { + + } else if (iVKey == VK_DELETE) { if (FileExistsForWriting(mg_fnm)) { // delete the file, its description and thumbnail RemoveFile(mg_fnm); @@ -164,8 +163,7 @@ BOOL CMGFileButton::OnKeyDown(int iVKey) } } return CMenuGadget::OnKeyDown(iVKey); - } - else { + } else { // go out of editing mode if (mg_bEditing) { if (iVKey == VK_UP || iVKey == VK_DOWN) { @@ -185,6 +183,7 @@ void CMGFileButton::OnSetFocus(void) } else { ClearThumbnail(); } + pgmCurrentMenu->KillAllFocuses(); CMGButton::OnSetFocus(); } @@ -195,6 +194,7 @@ void CMGFileButton::OnKillFocus(void) if (mg_bEditing) { OnKeyDown(VK_ESCAPE); } + CMGEdit::OnKillFocus(); } @@ -206,9 +206,8 @@ void CMGFileButton::OnStringChanged(void) // do the save mg_strDes = _strTmpDescription + "\n" + mg_strInfo; DoSave(); - // if renaming - } - else if (mg_iState == FBS_RENAME) { + // if renaming + } else if (mg_iState == FBS_RENAME) { // do the rename mg_strDes = _strTmpDescription + "\n" + mg_strInfo; SaveDescription(); diff --git a/Sources/SeriousSam/GUI/Components/MGHighScore.cpp b/Sources/SeriousSam/GUI/Components/MGHighScore.cpp index 31466ee..a46c124 100644 --- a/Sources/SeriousSam/GUI/Components/MGHighScore.cpp +++ b/Sources/SeriousSam/GUI/Components/MGHighScore.cpp @@ -94,8 +94,7 @@ void CMGHighScore::Render(CDrawPort *pdp) }} if (iRow == 0) { pixJ += pdp->GetHeight()*0.06f; - } - else { + } else { pixJ += pdp->GetHeight()*0.04f; } }} diff --git a/Sources/SeriousSam/GUI/Components/MGKeyDefinition.cpp b/Sources/SeriousSam/GUI/Components/MGKeyDefinition.cpp index 4d82ba6..85cce3c 100644 --- a/Sources/SeriousSam/GUI/Components/MGKeyDefinition.cpp +++ b/Sources/SeriousSam/GUI/Components/MGKeyDefinition.cpp @@ -79,9 +79,8 @@ void CMGKeyDefinition::SetBindingNames(BOOL bDefining) if (bKey1Bound && !bKey2Bound) { // put question mark for second key mg_strBinding = strKey1 + TRANS(" or ") + "?"; - // otherwise - } - else { + // otherwise + } else { // put question mark only mg_strBinding = "?"; } @@ -92,9 +91,8 @@ void CMGKeyDefinition::SetBindingNames(BOOL bDefining) if (bKey2Bound) { // add both mg_strBinding = strKey1 + TRANS(" or ") + strKey2; - // if second key is undefined - } - else { + // if second key is undefined + } else { // display only first one mg_strBinding = strKey1; } @@ -139,15 +137,13 @@ void CMGKeyDefinition::DefineKey(INDEX iDik) ba.ba_iFirstKey = iDik; // clear second key ba.ba_iSecondKey = KID_NONE; - // if only first key bound - } - else { + // if only first key bound + } else { // bind second key ba.ba_iSecondKey = iDik; } // if it is not this one - } - else { + } else { // clear bindings that contain this key if (ba.ba_iFirstKey == iDik) { ba.ba_iFirstKey = KID_NONE; @@ -195,8 +191,7 @@ void CMGKeyDefinition::Think(void) // define the new key DefineKey(iDik); // if escape pressed - } - else { + } else { // undefine the key DefineKey(KID_NONE); } diff --git a/Sources/SeriousSam/GUI/Components/MGServerList.cpp b/Sources/SeriousSam/GUI/Components/MGServerList.cpp index 5872ea9..286a001 100644 --- a/Sources/SeriousSam/GUI/Components/MGServerList.cpp +++ b/Sources/SeriousSam/GUI/Components/MGServerList.cpp @@ -67,8 +67,7 @@ void CMGServerList::AdjustFirstOnScreen(void) if (mg_iSelected= mg_iFirstOnScreen + mg_ctOnScreen) { + } else if (mg_iSelected >= mg_iFirstOnScreen + mg_ctOnScreen) { mg_iFirstOnScreen = ClampDn(mg_iSelected - mg_ctOnScreen + 1L, 0L); } } @@ -104,11 +103,11 @@ extern CMGEdit mgServerFilter[7]; void SortAndFilterServers(void) { - { FORDELETELIST(CNetworkSession, ns_lnNode, _lhServers, itns) { + {FORDELETELIST(CNetworkSession, ns_lnNode, _lhServers, itns) { delete &*itns; - } } - { - FOREACHINLIST(CNetworkSession, ns_lnNode, _pNetwork->ga_lhEnumeratedSessions, itns) { + }} + + {FOREACHINLIST(CNetworkSession, ns_lnNode, _pNetwork->ga_lhEnumeratedSessions, itns) { CNetworkSession &ns = *itns; extern CTString _strServerFilter[7]; 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], TRANS("searching..."), colItem); } - } - else { + } else { FOREACHINLIST(CNetworkSession, ns_lnNode, _lhServers, itns) { CNetworkSession &ns = *itns; @@ -352,8 +350,7 @@ void CMGServerList::OnMouseOver(PIX pixI, PIX pixJ) AdjustFirstOnScreen(); mg_pixMouseDrag = -1; } - } - else if (bInSlider) { + } else if (bInSlider) { mg_pixMouseDrag = pixJ; } } diff --git a/Sources/SeriousSam/GUI/Components/MGSlider.cpp b/Sources/SeriousSam/GUI/Components/MGSlider.cpp index 18055f7..275aa19 100644 --- a/Sources/SeriousSam/GUI/Components/MGSlider.cpp +++ b/Sources/SeriousSam/GUI/Components/MGSlider.cpp @@ -60,14 +60,12 @@ BOOL CMGSlider::OnKeyDown(int iVKey) ApplyCurrentPosition(); return TRUE; // if scrolling right - } - else if ((iVKey == VK_RETURN || iVKey == VK_RIGHT) && mg_iCurPosPutText(mg_strLabel, box.Min()(1), pixJ, col); pdp->PutTextR(strValue, box.Max()(1), pixJ, col); - } - else { + } else { pdp->PutTextR(mg_strLabel, pixIL, pixJ, col); pdp->PutText(strValue, pixIR, pixJ, col); } - } - else { + } else { CTString strLabel = mg_strLabel + ": "; pdp->PutText(strLabel, box.Min()(1), pixJ, col); CTextureObject to; @@ -116,8 +113,7 @@ void CMGTrigger::Render(CDrawPort *pdp) pdp->PutTexture(&to, PIXaabbox2D( PIX2D(pixCX - pixSize / 2, pixCY - pixSize / 2), PIX2D(pixCX - pixSize / 2 + pixSize, pixCY - pixSize / 2 + pixSize)), C_WHITE | 255); - } - catch (char *strError) { + } catch (char *strError) { CPrintF("%s\n", strError); } to.SetData(NULL); diff --git a/Sources/SeriousSam/GUI/Components/MGVarButton.cpp b/Sources/SeriousSam/GUI/Components/MGVarButton.cpp index 5537ce3..970412a 100644 --- a/Sources/SeriousSam/GUI/Components/MGVarButton.cpp +++ b/Sources/SeriousSam/GUI/Components/MGVarButton.cpp @@ -141,9 +141,7 @@ void CMGVarButton::Render(CDrawPort *pdp) COLOR col = LCDGetColor(C_WHITE | 255, "separator"); CTString strText = mg_pvsVar->vs_strName; pdp->PutTextC(strText, pixIC, pixJ, col); - } - else if (mg_pvsVar->Validate()) - { + } else if (mg_pvsVar->Validate()) { // check whether the variable is disabled if (mg_pvsVar->vs_strFilter != "") mg_bEnabled = _pShell->GetINDEX(mg_pvsVar->vs_strFilter); COLOR col = GetCurrentColor(); @@ -160,13 +158,13 @@ void CMGVarButton::Render(CDrawPort *pdp) PIX pixJSize = box.Size()(2); LCDDrawBox(0, -1, PIXaabbox2D(PIX2D(pixIR, pixJ + 1), PIX2D(pixIR + pixISize - 4, pixJ + pixJSize - 6)), LCDGetColor(C_GREEN | 255, "slider box")); + // draw filled part of slider if (mg_pvsVar->vs_iSlider == 1) { // fill slider FLOAT fFactor = (FLOAT)(mg_pvsVar->vs_iValue + 1) / mg_pvsVar->vs_ctValues; pdp->Fill(pixIR + 1, pixJ + 2, (pixISize - 6)*fFactor, pixJSize - 9, col); - } - else { + } else { // ratio slider ASSERT(mg_pvsVar->vs_iSlider == 2); FLOAT fUnitWidth = (FLOAT)(pixISize - 5) / mg_pvsVar->vs_ctValues; diff --git a/Sources/SeriousSam/GUI/Menus/GameMenu.cpp b/Sources/SeriousSam/GUI/Menus/GameMenu.cpp index 91dd9d8..320a703 100644 --- a/Sources/SeriousSam/GUI/Menus/GameMenu.cpp +++ b/Sources/SeriousSam/GUI/Menus/GameMenu.cpp @@ -324,9 +324,8 @@ void CGameMenu::StartMenu(void) if (itmg->mg_iInList == -2) { // hide it itmg->mg_bVisible = FALSE; - // if in list - } - else if (itmg->mg_iInList >= 0) { + // if in list + } else if (itmg->mg_iInList >= 0) { // show it itmg->mg_bVisible = TRUE; } diff --git a/Sources/SeriousSam/SeriousSam.cpp b/Sources/SeriousSam/SeriousSam.cpp index b18fc39..5459745 100644 --- a/Sources/SeriousSam/SeriousSam.cpp +++ b/Sources/SeriousSam/SeriousSam.cpp @@ -1364,10 +1364,8 @@ BOOL TryToSetDisplayMode( enum GfxAPIType eGfxAPI, INDEX iAdapter, PIX pixSizeI, // report success return TRUE; - } - // if couldn't set new mode - else { + } else { // close the application window CloseMainWindow(); // report failure