From be52b5bf76eaafb7ef3c94d77524638d59257744 Mon Sep 17 00:00:00 2001 From: Flugente Date: Sat, 31 May 2014 20:09:52 +0000 Subject: [PATCH] Fix: CTD on MeLoDY website if player has no active mercs git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@7249 3b4a5df2-a311-0410-b5c6-a8a6f20db521 --- Laptop/DropDown.h | 9 +- Laptop/merccompare.cpp | 241 +++++++++++++++++++++------------------ Utils/Text.h | 3 + Utils/_ChineseText.cpp | 3 + Utils/_DutchText.cpp | 3 + Utils/_EnglishText.cpp | 3 + Utils/_FrenchText.cpp | 3 + Utils/_GermanText.cpp | 3 + Utils/_ItalianText.cpp | 3 + Utils/_PolishText.cpp | 3 + Utils/_RussianText.cpp | 3 + Utils/_TaiwaneseText.cpp | 3 + 12 files changed, 167 insertions(+), 113 deletions(-) diff --git a/Laptop/DropDown.h b/Laptop/DropDown.h index 4ac3e369..0eef7e5e 100644 --- a/Laptop/DropDown.h +++ b/Laptop/DropDown.h @@ -82,10 +82,10 @@ public: void Display(); /* - * Sometimes a refresh inside the class isn't enough - best example is closing the dropdown area, after whcih te previous background cannot be restored by this class. + * Sometimes a refresh inside the class isn't enough - best example is closing the dropdown area, after which the previous background cannot be restored by this class. * In that case, the background and this class has to be redrawn. * This function is called internally whenver such a refreh is necessary. - * It has to be defined in derived classes and should notify your dialogues to redraw at apporpiate times + * It has to be defined in derived classes and should notify your dialogues to redraw at appropriate times * * This function has to be implemented! */ @@ -158,6 +158,11 @@ public: */ BOOLEAN IsDisplayed() { return mfMouseRegionsCreated; } + /* + * Do we have data to display? + */ + BOOLEAN HasEntries( ) { return !mEntryVector.empty(); } + // call to open/close the drop down void OpenDropDownRegionCallBack(MOUSE_REGION * pRegion, INT32 iReason ); void CloseDropDownRegionCallBack(MOUSE_REGION * pRegion, INT32 iReason ); diff --git a/Laptop/merccompare.cpp b/Laptop/merccompare.cpp index 1bc212f4..f733a4d8 100644 --- a/Laptop/merccompare.cpp +++ b/Laptop/merccompare.cpp @@ -417,12 +417,15 @@ BOOLEAN EnterMercCompareAnalyze() DropDownTemplate::getInstance( ).SetHelpText( szMercCompareWebSite[TEXT_MERCCOMPARE_DROPDOWNTEXT] ); DropDownTemplate::getInstance( ).Create( MCA_DROPDOWN_X + MCA_SIDEOFFSET, MCA_START_CONTENT_Y ); - // if a profile wa already set, use it - if ( gMercCompareProfile1 != NO_PROFILE ) - DropDownTemplate::getInstance( ).SetSelectedEntryKey( gMercCompareProfile1 ); + // if a profile was already set, use it + if ( DropDownTemplate::getInstance().HasEntries() ) + { + if ( gMercCompareProfile1 != NO_PROFILE ) + DropDownTemplate::getInstance( ).SetSelectedEntryKey( gMercCompareProfile1 ); - if ( gMercCompareProfile2 != NO_PROFILE ) - DropDownTemplate::getInstance( ).SetSelectedEntryKey( gMercCompareProfile2 ); + if ( gMercCompareProfile2 != NO_PROFILE ) + DropDownTemplate::getInstance( ).SetSelectedEntryKey( gMercCompareProfile2 ); + } RenderMercCompareAnalyze( ); @@ -463,13 +466,21 @@ void RenderMercCompareAnalyze() usPosX = LAPTOP_SCREEN_UL_X; usPosY = MCA_START_CONTENT_Y; - gMercCompareProfile1 = (UINT8)DropDownTemplate::getInstance( ).GetSelectedEntryKey( ); - gMercCompareProfile2 = (UINT8)DropDownTemplate::getInstance( ).GetSelectedEntryKey( ); + if ( DropDownTemplate::getInstance().HasEntries() ) + { + gMercCompareProfile1 = (UINT8)DropDownTemplate::getInstance( ).GetSelectedEntryKey( ); + gMercCompareProfile2 = (UINT8)DropDownTemplate::getInstance( ).GetSelectedEntryKey( ); - DisplayMercData( gMercCompareProfile1, gMercCompareProfile2 ); + DisplayMercData( gMercCompareProfile1, gMercCompareProfile2 ); - DropDownTemplate::getInstance( ).Display( ); - DropDownTemplate::getInstance( ).Display( ); + DropDownTemplate::getInstance( ).Display( ); + DropDownTemplate::getInstance( ).Display( ); + } + else + { + swprintf( sText, szMercCompareWebSite[TEXT_MERCCOMPARE_ERROR_NOBODYTHERE] ); + usPosY += DisplayWrappedString( usPosX, usPosY, LAPTOP_SCREEN_LR_X - LAPTOP_SCREEN_UL_X, 2, CAMPHIS_FONT_MED, MERCOMP_FONT_COLOR, sText, FONT_MCOLOR_BLACK, FALSE, 0 ); + } SetFontShadow( DEFAULT_SHADOW ); @@ -1056,128 +1067,136 @@ void RenderMercCompareMatrix( ) } } - gSquadToShow = ( UINT8 )DropDownTemplate::getInstance( ).GetSelectedEntryKey( ); - DropDownTemplate::getInstance( ).Display( ); - - SetFontShadow( MERCOMP_FONT_SHADOW ); - - usPosX = LAPTOP_SCREEN_UL_X; - usPosY = MCA_START_CONTENT_Y + 30; - - // display a table with all squadmembers - std::vector squadvector; - SOLDIERTYPE* pSoldier = NULL; - UINT16 id = gTacticalStatus.Team[gbPlayerNum].bFirstID; - UINT16 lastid = gTacticalStatus.Team[gbPlayerNum].bLastID; - for ( pSoldier = MercPtrs[id]; id <= lastid; ++id, pSoldier++ ) + if ( DropDownTemplate::getInstance().HasEntries() ) { - if ( pSoldier->bActive && pSoldier->ubProfile != NO_PROFILE && pSoldier->bAssignment == gSquadToShow ) + gSquadToShow = ( UINT8 )DropDownTemplate::getInstance( ).GetSelectedEntryKey( ); + DropDownTemplate::getInstance( ).Display( ); + + SetFontShadow( MERCOMP_FONT_SHADOW ); + + usPosX = LAPTOP_SCREEN_UL_X; + usPosY = MCA_START_CONTENT_Y + 30; + + // display a table with all squadmembers + std::vector squadvector; + SOLDIERTYPE* pSoldier = NULL; + UINT16 id = gTacticalStatus.Team[gbPlayerNum].bFirstID; + UINT16 lastid = gTacticalStatus.Team[gbPlayerNum].bLastID; + for ( pSoldier = MercPtrs[id]; id <= lastid; ++id, pSoldier++ ) { - // remember squamember - squadvector.push_back( pSoldier->ubProfile ); + if ( pSoldier->bActive && pSoldier->ubProfile != NO_PROFILE && pSoldier->bAssignment == gSquadToShow ) + { + // remember squamember + squadvector.push_back( pSoldier->ubProfile ); + } } - } - UINT16 spacepermerc = (LAPTOP_SCREEN_LR_X - LAPTOP_SCREEN_UL_X) / (squadvector.size() + 1); - spacepermerc = min( spacepermerc , 60); + UINT16 spacepermerc = (LAPTOP_SCREEN_LR_X - LAPTOP_SCREEN_UL_X) / (squadvector.size() + 1); + spacepermerc = min( spacepermerc , 60); - // now loop over the squadmembers and fill out the table - std::vector::iterator itend = squadvector.end( ); - for ( std::vector::iterator it = squadvector.begin(); it != itend; ++it ) - { - usPosX += spacepermerc; + // now loop over the squadmembers and fill out the table + std::vector::iterator itend = squadvector.end( ); + for ( std::vector::iterator it = squadvector.begin(); it != itend; ++it ) + { + usPosX += spacepermerc; - // write the names of all squamembers on top of the table - swprintf( sText, gMercProfiles[(*it)].zNickname ); - DisplayWrappedString( usPosX, usPosY, LAPTOP_SCREEN_LR_X - LAPTOP_SCREEN_UL_X, 2, CAMPHIS_FONT_MED, MERCOMP_FONT_COLOR, sText, FONT_MCOLOR_BLACK, FALSE, 0 ); + // write the names of all squamembers on top of the table + swprintf( sText, gMercProfiles[(*it)].zNickname ); + DisplayWrappedString( usPosX, usPosY, LAPTOP_SCREEN_LR_X - LAPTOP_SCREEN_UL_X, 2, CAMPHIS_FONT_MED, MERCOMP_FONT_COLOR, sText, FONT_MCOLOR_BLACK, FALSE, 0 ); + + DisplaySmallColouredLineWithShadow( usPosX - 10, usPosY - 6, usPosX - 10, usPosY + 17 * (squadvector.size( ) + 1) - 5, FROMRGB( 0, 255, 0 ) ); + } DisplaySmallColouredLineWithShadow( usPosX - 10, usPosY - 6, usPosX - 10, usPosY + 17 * (squadvector.size( ) + 1) - 5, FROMRGB( 0, 255, 0 ) ); - } - DisplaySmallColouredLineWithShadow( usPosX - 10, usPosY - 6, usPosX - 10, usPosY + 17 * (squadvector.size( ) + 1) - 5, FROMRGB( 0, 255, 0 ) ); + usPosX = LAPTOP_SCREEN_UL_X; - usPosX = LAPTOP_SCREEN_UL_X; - - DisplaySmallColouredLineWithShadow( usPosX, usPosY - 5, usPosX + spacepermerc * (squadvector.size( ) + 1), usPosY - 5, FROMRGB( 0, 255, 0 ) ); + DisplaySmallColouredLineWithShadow( usPosX, usPosY - 5, usPosX + spacepermerc * (squadvector.size( ) + 1), usPosY - 5, FROMRGB( 0, 255, 0 ) ); - UINT16 currentmouseregion = 0; + UINT16 currentmouseregion = 0; - for ( std::vector::iterator it = squadvector.begin(); it != itend; ++it ) - { - INT16 idA = GetSoldierIDFromMercID( (*it) ); + for ( std::vector::iterator it = squadvector.begin(); it != itend; ++it ) + { + INT16 idA = GetSoldierIDFromMercID( (*it) ); - if ( idA < 0 ) - continue; + if ( idA < 0 ) + continue; - SOLDIERTYPE* pSoldierA = MercPtrs[idA]; + SOLDIERTYPE* pSoldierA = MercPtrs[idA]; - if ( !pSoldierA ) - continue; + if ( !pSoldierA ) + continue; + + usPosY += 17; + usPosX = LAPTOP_SCREEN_UL_X; + + DisplaySmallColouredLineWithShadow( usPosX, usPosY - 5, usPosX + spacepermerc * (squadvector.size( ) + 1), usPosY - 5, FROMRGB( 0, 255, 0 ) ); + + // write name on the left side + swprintf( sText, gMercProfiles[pSoldierA->ubProfile].zNickname ); + DisplayWrappedString( usPosX, usPosY, LAPTOP_SCREEN_LR_X - LAPTOP_SCREEN_UL_X, 2, CAMPHIS_FONT_MED, MERCOMP_FONT_COLOR, sText, FONT_MCOLOR_BLACK, FALSE, 0 ); + + usPosX += spacepermerc; + + for ( std::vector::iterator it2 = squadvector.begin( ); it2 != itend; ++it2 ) + { + INT16 idB = GetSoldierIDFromMercID( (*it2) ); + + if ( idB < 0 ) + continue; + + if ( idA == idB ) + { + usPosX += spacepermerc; + continue; + } + + SOLDIERTYPE* pSoldierB = MercPtrs[idB]; + + if ( !pSoldierB ) + continue; + + if ( !gMercCompareMatrixLinkDefined[currentmouseregion] ) + { + MSYS_DefineRegion( &gMercCompareMatrixLinkRegion[currentmouseregion], usPosX - 5, usPosY, usPosX + spacepermerc - 5, usPosY + 17, MSYS_PRIORITY_HIGH, + CURSOR_WWW, MSYS_NO_CALLBACK, SelectMercCompareMatrixRegionCallBack ); + MSYS_AddRegion( &gMercCompareMatrixLinkRegion[currentmouseregion] ); + + // both profilenumbers are combined to a single value which cn later be reinterpreted. + // Note: this will fail if the profile IDs are bigger than UINT16 (currently UINT8) + MSYS_SetRegionUserData( &gMercCompareMatrixLinkRegion[currentmouseregion], 0, ((pSoldierA->ubProfile << 8) | pSoldierB->ubProfile) ); + gMercCompareMatrixLinkDefined[currentmouseregion] = TRUE; + ++currentmouseregion; + } + + // write down both relations + INT8 val = SoldierRelation( pSoldierA, pSoldierB ); + swprintf( sText, L"%d", val ); + DisplayWrappedString( usPosX, usPosY, LAPTOP_SCREEN_LR_X - LAPTOP_SCREEN_UL_X, 2, CAMPHIS_FONT_MED, (val > 0) ? FONT_MCOLOR_LTGREEN : (val < 0) ? FONT_MCOLOR_LTRED : MERCOMP_FONT_COLOR, sText, FONT_MCOLOR_BLACK, FALSE, 0 ); + usPosX += 15; + + swprintf( sText, L"/" ); + DisplayWrappedString( usPosX, usPosY, LAPTOP_SCREEN_LR_X - LAPTOP_SCREEN_UL_X, 2, CAMPHIS_FONT_MED, MERCOMP_FONT_COLOR, sText, FONT_MCOLOR_BLACK, FALSE, 0 ); + usPosX += 5; + + val = SoldierRelation( pSoldierB, pSoldierA ); + swprintf( sText, L"%d", val ); + DisplayWrappedString( usPosX, usPosY, LAPTOP_SCREEN_LR_X - LAPTOP_SCREEN_UL_X, 2, CAMPHIS_FONT_MED, (val > 0) ? FONT_MCOLOR_LTGREEN : (val < 0) ? FONT_MCOLOR_LTRED : MERCOMP_FONT_COLOR, sText, FONT_MCOLOR_BLACK, FALSE, 0 ); + + usPosX += spacepermerc - 20; + } + } usPosY += 17; usPosX = LAPTOP_SCREEN_UL_X; DisplaySmallColouredLineWithShadow( usPosX, usPosY - 5, usPosX + spacepermerc * (squadvector.size( ) + 1), usPosY - 5, FROMRGB( 0, 255, 0 ) ); - - // write name on the left side - swprintf( sText, gMercProfiles[pSoldierA->ubProfile].zNickname ); - DisplayWrappedString( usPosX, usPosY, LAPTOP_SCREEN_LR_X - LAPTOP_SCREEN_UL_X, 2, CAMPHIS_FONT_MED, MERCOMP_FONT_COLOR, sText, FONT_MCOLOR_BLACK, FALSE, 0 ); - - usPosX += spacepermerc; - - for ( std::vector::iterator it2 = squadvector.begin( ); it2 != itend; ++it2 ) - { - INT16 idB = GetSoldierIDFromMercID( (*it2) ); - - if ( idB < 0 ) - continue; - - if ( idA == idB ) - { - usPosX += spacepermerc; - continue; - } - - SOLDIERTYPE* pSoldierB = MercPtrs[idB]; - - if ( !pSoldierB ) - continue; - - if ( !gMercCompareMatrixLinkDefined[currentmouseregion] ) - { - MSYS_DefineRegion( &gMercCompareMatrixLinkRegion[currentmouseregion], usPosX - 5, usPosY, usPosX + spacepermerc - 5, usPosY + 17, MSYS_PRIORITY_HIGH, - CURSOR_WWW, MSYS_NO_CALLBACK, SelectMercCompareMatrixRegionCallBack ); - MSYS_AddRegion( &gMercCompareMatrixLinkRegion[currentmouseregion] ); - - // both profilenumbers are combined to a single value which cn later be reinterpreted. - // Note: this will fail if the profile IDs are bigger than UINT16 (currently UINT8) - MSYS_SetRegionUserData( &gMercCompareMatrixLinkRegion[currentmouseregion], 0, ((pSoldierA->ubProfile << 8) | pSoldierB->ubProfile) ); - gMercCompareMatrixLinkDefined[currentmouseregion] = TRUE; - ++currentmouseregion; - } - - // write down both relations - INT8 val = SoldierRelation( pSoldierA, pSoldierB ); - swprintf( sText, L"%d", val ); - DisplayWrappedString( usPosX, usPosY, LAPTOP_SCREEN_LR_X - LAPTOP_SCREEN_UL_X, 2, CAMPHIS_FONT_MED, (val > 0) ? FONT_MCOLOR_LTGREEN : (val < 0) ? FONT_MCOLOR_LTRED : MERCOMP_FONT_COLOR, sText, FONT_MCOLOR_BLACK, FALSE, 0 ); - usPosX += 15; - - swprintf( sText, L"/" ); - DisplayWrappedString( usPosX, usPosY, LAPTOP_SCREEN_LR_X - LAPTOP_SCREEN_UL_X, 2, CAMPHIS_FONT_MED, MERCOMP_FONT_COLOR, sText, FONT_MCOLOR_BLACK, FALSE, 0 ); - usPosX += 5; - - val = SoldierRelation( pSoldierB, pSoldierA ); - swprintf( sText, L"%d", val ); - DisplayWrappedString( usPosX, usPosY, LAPTOP_SCREEN_LR_X - LAPTOP_SCREEN_UL_X, 2, CAMPHIS_FONT_MED, (val > 0) ? FONT_MCOLOR_LTGREEN : (val < 0) ? FONT_MCOLOR_LTRED : MERCOMP_FONT_COLOR, sText, FONT_MCOLOR_BLACK, FALSE, 0 ); - - usPosX += spacepermerc - 20; - } } - - usPosY += 17; - usPosX = LAPTOP_SCREEN_UL_X; - - DisplaySmallColouredLineWithShadow( usPosX, usPosY - 5, usPosX + spacepermerc * (squadvector.size( ) + 1), usPosY - 5, FROMRGB( 0, 255, 0 ) ); + else + { + swprintf( sText, szMercCompareWebSite[TEXT_MERCCOMPARE_ERROR_NOBODYTHERE] ); + usPosY += DisplayWrappedString( usPosX, usPosY, LAPTOP_SCREEN_LR_X - LAPTOP_SCREEN_UL_X, 2, CAMPHIS_FONT_MED, MERCOMP_FONT_COLOR, sText, FONT_MCOLOR_BLACK, FALSE, 0 ); + } SetFontShadow( DEFAULT_SHADOW ); diff --git a/Utils/Text.h b/Utils/Text.h index 0e1fa746..c1015e7c 100644 --- a/Utils/Text.h +++ b/Utils/Text.h @@ -2765,6 +2765,9 @@ enum TEXT_MERCCOMPARE_DROPDOWNTEXT = TEXT_MERCCOMPARE_QUOTE1 + 2 * TEXT_MERCCOMPARE_CUSTOMERSTATEMENTS, TEXT_MERCCOMPARE_DROPDOWNTEXT_MATRIX, + // error messages + TEXT_MERCCOMPARE_ERROR_NOBODYTHERE, + TEXT_MERCCOMPARE_MAX, }; diff --git a/Utils/_ChineseText.cpp b/Utils/_ChineseText.cpp index 87bfff86..40b8988a 100644 --- a/Utils/_ChineseText.cpp +++ b/Utils/_ChineseText.cpp @@ -8615,6 +8615,9 @@ STR16 szMercCompareWebSite[] = // TODO.Translate // analyze L"Choose your employee", L"Choose your squad", + + // error messages + L"You currently have no employees at their workplace. Sub-par morale often results in a high rate of absent staff.", }; STR16 szMercCompareEventText[]= diff --git a/Utils/_DutchText.cpp b/Utils/_DutchText.cpp index 7ab97d98..3888d246 100644 --- a/Utils/_DutchText.cpp +++ b/Utils/_DutchText.cpp @@ -8629,6 +8629,9 @@ STR16 szMercCompareWebSite[] = // TODO.Translate // analyze L"Choose your employee", L"Choose your squad", + + // error messages + L"You currently have no employees at their workplace. Sub-par morale often results in a high rate of absent staff.", }; STR16 szMercCompareEventText[]= diff --git a/Utils/_EnglishText.cpp b/Utils/_EnglishText.cpp index ff01918c..8e842585 100644 --- a/Utils/_EnglishText.cpp +++ b/Utils/_EnglishText.cpp @@ -8613,6 +8613,9 @@ STR16 szMercCompareWebSite[] = // analyze L"Choose your employee", L"Choose your squad", + + // error messages + L"You currently have no employees at their workplace. Sub-par morale often results in a high rate of absent staff.", }; STR16 szMercCompareEventText[]= diff --git a/Utils/_FrenchText.cpp b/Utils/_FrenchText.cpp index 4ad159b9..6710ca50 100644 --- a/Utils/_FrenchText.cpp +++ b/Utils/_FrenchText.cpp @@ -8614,6 +8614,9 @@ STR16 szMercCompareWebSite[] = // TODO.Translate // analyze L"Choose your employee", L"Choose your squad", + + // error messages + L"You currently have no employees at their workplace. Sub-par morale often results in a high rate of absent staff.", }; STR16 szMercCompareEventText[]= diff --git a/Utils/_GermanText.cpp b/Utils/_GermanText.cpp index afaf102c..6711ecf6 100644 --- a/Utils/_GermanText.cpp +++ b/Utils/_GermanText.cpp @@ -8443,6 +8443,9 @@ STR16 szMercCompareWebSite[] = // TODO.Translate // analyze L"Choose your employee", L"Choose your squad", + + // error messages + L"You currently have no employees at their workplace. Sub-par morale often results in a high rate of absent staff.", }; STR16 szMercCompareEventText[]= diff --git a/Utils/_ItalianText.cpp b/Utils/_ItalianText.cpp index d177235e..67fe35db 100644 --- a/Utils/_ItalianText.cpp +++ b/Utils/_ItalianText.cpp @@ -8621,6 +8621,9 @@ STR16 szMercCompareWebSite[] = // TODO.Translate // analyze L"Choose your employee", L"Choose your squad", + + // error messages + L"You currently have no employees at their workplace. Sub-par morale often results in a high rate of absent staff.", }; STR16 szMercCompareEventText[]= diff --git a/Utils/_PolishText.cpp b/Utils/_PolishText.cpp index 29abd335..c7959dc6 100644 --- a/Utils/_PolishText.cpp +++ b/Utils/_PolishText.cpp @@ -8638,6 +8638,9 @@ STR16 szMercCompareWebSite[] = // TODO.Translate // analyze L"Choose your employee", L"Choose your squad", + + // error messages + L"You currently have no employees at their workplace. Sub-par morale often results in a high rate of absent staff.", }; STR16 szMercCompareEventText[]= diff --git a/Utils/_RussianText.cpp b/Utils/_RussianText.cpp index edee367d..09313392 100644 --- a/Utils/_RussianText.cpp +++ b/Utils/_RussianText.cpp @@ -8618,6 +8618,9 @@ STR16 szMercCompareWebSite[] = // TODO.Translate // analyze L"Choose your employee", L"Choose your squad", + + // error messages + L"You currently have no employees at their workplace. Sub-par morale often results in a high rate of absent staff.", }; STR16 szMercCompareEventText[]= diff --git a/Utils/_TaiwaneseText.cpp b/Utils/_TaiwaneseText.cpp index c0694fac..4111be56 100644 --- a/Utils/_TaiwaneseText.cpp +++ b/Utils/_TaiwaneseText.cpp @@ -8629,6 +8629,9 @@ STR16 szMercCompareWebSite[] = // TODO.Translate // analyze L"Choose your employee", L"Choose your squad", + + // error messages + L"You currently have no employees at their workplace. Sub-par morale often results in a high rate of absent staff.", }; STR16 szMercCompareEventText[]=