From 7a49e4921ae44020efbf0b1fa67f0ee3fca6d5c4 Mon Sep 17 00:00:00 2001 From: Flugente Date: Sat, 6 Oct 2018 17:51:25 +0000 Subject: [PATCH] Ammo colour in AmmoTypes.xml is now set using // tags instead of ///. For more information, see http://thepit.ja-galaxy-forum.com/index.php?t=msg&th=20659&goto=355255&#msg_355255 git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@8627 3b4a5df2-a311-0410-b5c6-a8a6f20db521 --- Standard Gaming Platform/Button System.cpp | 12 ++- Standard Gaming Platform/Button System.h | 1 + Standard Gaming Platform/Font.cpp | 11 +++ Standard Gaming Platform/Font.h | 4 + Tactical/Interface Items.cpp | 95 ++++++++++++---------- Tactical/Item Types.h | 1 + Tactical/Weapons.h | 12 ++- Tactical/XML_AmmoTypes.cpp | 55 ++++++------- 8 files changed, 108 insertions(+), 83 deletions(-) diff --git a/Standard Gaming Platform/Button System.cpp b/Standard Gaming Platform/Button System.cpp index 25b8d3d8..2de66f9c 100644 --- a/Standard Gaming Platform/Button System.cpp +++ b/Standard Gaming Platform/Button System.cpp @@ -2141,7 +2141,7 @@ INT32 CreateIconAndTextButton( INT32 Image, const STR16 string, UINT32 uiFont, } // Strip off any extraneous bits from button type - BType = Type & ( BUTTON_TYPE_MASK | BUTTON_NEWTOGGLE ); + BType = Type & ( BUTTON_TYPE_MASK | BUTTON_NEWTOGGLE | BUTTON_16BPPCOLOURTEXT ); // Is there a QuickButton image in the given image slot? if(ButtonPictures[Image].vobj == NULL) @@ -3521,6 +3521,7 @@ void DrawTextOnButton(GUI_BUTTON *b) SetFontBackground( FONT_MCOLOR_BLACK ); SetFontForeground( (UINT8)b->sForeColor ); sForeColor = b->sForeColor; + if( b->sShadowColor != -1 ) SetFontShadow( (UINT8)b->sShadowColor ); //Override the colors if necessary. @@ -3534,6 +3535,7 @@ void DrawTextOnButton(GUI_BUTTON *b) SetFontForeground( (UINT8)b->sForeColorDown ); sForeColor = b->sForeColorDown; } + if( b->uiFlags & BUTTON_ENABLED && b->Area.uiFlags & MSYS_MOUSE_IN_AREA && b->sShadowColorHilited != -1 ) { SetFontShadow( (UINT8)b->sShadowColorHilited ); @@ -3542,6 +3544,14 @@ void DrawTextOnButton(GUI_BUTTON *b) { SetFontShadow( (UINT8)b->sShadowColorDown ); } + else if ( b->uiFlags & BUTTON_16BPPCOLOURTEXT ) + { + SetRGBFontForeground( sForeColor ); + + if ( b->sShadowColor < 1 ) + SetRGBFontShadow( 1 ); + } + if( b->uiFlags & BUTTON_CLICKED_ON && b->fShiftText ) { // Was the button clicked on? if so, move the text slightly for the illusion // that the text moved into the screen. diff --git a/Standard Gaming Platform/Button System.h b/Standard Gaming Platform/Button System.h index dad12835..a00705da 100644 --- a/Standard Gaming Platform/Button System.h +++ b/Standard Gaming Platform/Button System.h @@ -70,6 +70,7 @@ #define BUTTON_NEWTOGGLE 0x00002000 #define BUTTON_FORCE_UNDIRTY 0x00004000 // no matter what happens this buttons does NOT get marked dirty #define BUTTON_IGNORE_CLICKS 0x00008000 // Ignore any clicks on this button +#define BUTTON_16BPPCOLOURTEXT 0x00010000 // Use 16 bit colours for the text of this button #define BUTTON_DISABLED_CALLBACK 0x80000000 #define BUTTON_SOUND_NONE 0x00 diff --git a/Standard Gaming Platform/Font.cpp b/Standard Gaming Platform/Font.cpp index fc36caa9..b965d7d2 100644 --- a/Standard Gaming Platform/Font.cpp +++ b/Standard Gaming Platform/Font.cpp @@ -241,6 +241,17 @@ void SetRGBFontShadow( UINT32 uiRed, UINT32 uiGreen, UINT32 uiBlue ) } //end Kris +// Flugente: set 16 bit colour directly +void SetRGBFontForeground( UINT16 usFontForeground16 ) +{ + FontForeground16 = usFontForeground16; +} + +void SetRGBFontShadow( UINT16 usFontShadow16 ) +{ + FontShadow16 = usFontShadow16; +} + //***************************************************************************** // ResetFontObjectPalette // diff --git a/Standard Gaming Platform/Font.h b/Standard Gaming Platform/Font.h index 7c7000f6..ef3b8152 100644 --- a/Standard Gaming Platform/Font.h +++ b/Standard Gaming Platform/Font.h @@ -118,6 +118,10 @@ void SetRGBFontForeground( UINT32 uiRed, UINT32 uiGreen, UINT32 uiBlue ); void SetRGBFontBackground( UINT32 uiRed, UINT32 uiGreen, UINT32 uiBlue ); void SetRGBFontShadow( UINT32 uiRed, UINT32 uiGreen, UINT32 uiBlue ); +// Flugente: set 16 bit colour directly +void SetRGBFontForeground( UINT16 usFontForeground16 ); +void SetRGBFontShadow( UINT16 usFontShadow16 ); + BOOLEAN ResetFontObjectPalette(INT32 iFont); UINT16 *SetFontObjectPalette8BPP(INT32 iFont, SGPPaletteEntry *pPal8); UINT16 *SetFontObjectPalette16BPP(INT32 iFont, UINT16 *pPal16); diff --git a/Tactical/Interface Items.cpp b/Tactical/Interface Items.cpp index d2f809c3..c25dc1a8 100644 --- a/Tactical/Interface Items.cpp +++ b/Tactical/Interface Items.cpp @@ -3891,7 +3891,9 @@ void INVRenderItem( UINT32 uiBuffer, SOLDIERTYPE * pSoldier, OBJECTTYPE *pObjec if ( pItemShown->usItemClass == IC_GUN && !Item[pObjShown->usItem].rocketlauncher ) { - SetFontForeground ( AmmoTypes[(*pObjShown)[iter]->data.gun.ubGunAmmoType].fontColour ); + SetRGBFontForeground( AmmoTypes[( *pObjShown )[iter]->data.gun.ubGunAmmoType].red, + AmmoTypes[( *pObjShown )[iter]->data.gun.ubGunAmmoType].green, + AmmoTypes[( *pObjShown )[iter]->data.gun.ubGunAmmoType].blue ); // HEADROCK HAM 3.4: Get estimate of bullets left. if ( (gTacticalStatus.uiFlags & TURNBASED) && (gTacticalStatus.uiFlags & INCOMBAT) ) @@ -4358,8 +4360,10 @@ void INVRenderItem( UINT32 uiBuffer, SOLDIERTYPE * pSoldier, OBJECTTYPE *pObjec UINT16 usMagIndex = Item[usAmmoItem].ubClassIndex; UINT16 usAmmoMagSize = Magazine[usMagIndex].ubMagSize; UINT8 usAmmoAmmoType = Magazine[usMagIndex].ubAmmoType; - - SetFontForeground ( AmmoTypes[usAmmoAmmoType].fontColour ); + + SetRGBFontForeground( AmmoTypes[usAmmoAmmoType].red, + AmmoTypes[usAmmoAmmoType].green, + AmmoTypes[usAmmoAmmoType].blue ); // count the total ammo left UINT16 totalammo = 0; @@ -4593,9 +4597,11 @@ void MAPINVRenderItem( UINT32 uiBuffer, SOLDIERTYPE * pSoldier, OBJECTTYPE *pOb // Set font properties SetFont( LARGEFONT1 ); + // Get color from ammo details - UINT8 ubAmmoColor = AmmoTypes[(*pObject)[0]->data.gun.ubGunAmmoType].fontColour; - SetFontForeground ( ubAmmoColor ); + SetRGBFontForeground( AmmoTypes[( *pObject )[0]->data.gun.ubGunAmmoType].red, + AmmoTypes[( *pObject )[0]->data.gun.ubGunAmmoType].green, + AmmoTypes[( *pObject )[0]->data.gun.ubGunAmmoType].blue ); sNewX = sX + 5; sNewY = ((sY + sHeight) - GetFontHeight( LARGEFONT1 )) - 2; @@ -4675,9 +4681,11 @@ void MAPINVRenderItem( UINT32 uiBuffer, SOLDIERTYPE * pSoldier, OBJECTTYPE *pOb // Set font properties SetFont( LARGEFONT1 ); + // Get color from ammo details - UINT8 ubAmmoColor = AmmoTypes[Magazine[Item[ pObject->usItem ].ubClassIndex].ubAmmoType].fontColour; - SetFontForeground ( ubAmmoColor ); + SetRGBFontForeground( AmmoTypes[Magazine[Item[pObject->usItem].ubClassIndex].ubAmmoType].red, + AmmoTypes[Magazine[Item[pObject->usItem].ubClassIndex].ubAmmoType].green, + AmmoTypes[Magazine[Item[pObject->usItem].ubClassIndex].ubAmmoType].blue ); sNewX = sX + 5; sNewY = ((sY + sHeight) - GetFontHeight( LARGEFONT1 )) - 2; @@ -5281,38 +5289,35 @@ BOOLEAN InternalInitItemDescriptionBox( OBJECTTYPE *pObject, INT16 sX, INT16 sY, } FilenameForBPP("INTERFACE\\infobox.sti", ubString); - sForeColour = ITEMDESC_AMMO_FORE; - + + // Flugente: the bullet icon has a very limited colour choice because its a .sti picture. So we change the display, always use the same default picture but use the colour for the text instead + //sForeColour = ITEMDESC_AMMO_FORE; + + sForeColour = (INT16)Get16BPPColor( FROMRGB( AmmoTypes[( *gpItemDescObject )[ubStatusIndex]->data.gun.ubGunAmmoType].red, + AmmoTypes[( *gpItemDescObject )[ubStatusIndex]->data.gun.ubGunAmmoType].green, + AmmoTypes[( *gpItemDescObject )[ubStatusIndex]->data.gun.ubGunAmmoType].blue ) ); + // silversurfer: This should never happen but some maps may contain items with invalid ammo types and this leads to graphical glitches // because the game cannot find the right ammo icon in infobox.sti and then uses index 0. Index 0 is the info box itself. // Better reset ammo type to 0 which is standard ball ammo. - if ( AmmoTypes[(*pObject)[ubStatusIndex]->data.gun.ubGunAmmoType].grayed == 0 || AmmoTypes[(*pObject)[ubStatusIndex]->data.gun.ubGunAmmoType].offNormal == 0 || AmmoTypes[(*pObject)[ubStatusIndex]->data.gun.ubGunAmmoType].onNormal == 0 ) - (*pObject)[ubStatusIndex]->data.gun.ubGunAmmoType = 0; + if ( ( *pObject )[ubStatusIndex]->data.gun.ubGunAmmoType >= gMAXAMMOTYPES_READ ) + ( *pObject )[ubStatusIndex]->data.gun.ubGunAmmoType = 0; + + // fixed pictures + giItemDescAmmoButtonImages = LoadButtonImage( ubString, + 4,// AmmoTypes[( *pObject )[ubStatusIndex]->data.gun.ubGunAmmoType].grayed, + 1,//AmmoTypes[(*pObject)[ubStatusIndex]->data.gun.ubGunAmmoType].offNormal, + -1, + 3,//AmmoTypes[(*pObject)[ubStatusIndex]->data.gun.ubGunAmmoType].onNormal, + -1 ); + + giItemDescAmmoButton = CreateIconAndTextButton( giItemDescAmmoButtonImages, pStr, BLOCKFONTNARROW, + sForeColour, FONT_MCOLOR_BLACK, + sForeColour, FONT_MCOLOR_BLACK, + TEXT_CJUSTIFIED, + (INT16)( ITEMDESC_AMMO_X ), (INT16)( ITEMDESC_AMMO_Y ), (BUTTON_TOGGLE| BUTTON_16BPPCOLOURTEXT ), MSYS_PRIORITY_HIGHEST, + DEFAULT_MOVE_CALLBACK, (GUI_CALLBACK)ItemDescAmmoCallback ); - giItemDescAmmoButtonImages = LoadButtonImage(ubString,AmmoTypes[(*pObject)[ubStatusIndex]->data.gun.ubGunAmmoType].grayed,AmmoTypes[(*pObject)[ubStatusIndex]->data.gun.ubGunAmmoType].offNormal,-1,AmmoTypes[(*pObject)[ubStatusIndex]->data.gun.ubGunAmmoType].onNormal,-1 ); - - if( guiCurrentItemDescriptionScreen == MAP_SCREEN ) - { - // in mapscreen, move over a bit - giItemDescAmmoButton = CreateIconAndTextButton( giItemDescAmmoButtonImages, pStr, BLOCKFONTNARROW, - sForeColour, FONT_MCOLOR_BLACK, - sForeColour, FONT_MCOLOR_BLACK, - TEXT_CJUSTIFIED, - (INT16)(ITEMDESC_AMMO_X), (INT16)(ITEMDESC_AMMO_Y), BUTTON_TOGGLE ,MSYS_PRIORITY_HIGHEST, - DEFAULT_MOVE_CALLBACK, (GUI_CALLBACK)ItemDescAmmoCallback ); - - } - else - { - - // not in mapscreen - giItemDescAmmoButton = CreateIconAndTextButton( giItemDescAmmoButtonImages, pStr, BLOCKFONTNARROW, - sForeColour, FONT_MCOLOR_BLACK, - sForeColour, FONT_MCOLOR_BLACK, - TEXT_CJUSTIFIED, - (INT16)(ITEMDESC_AMMO_X), (INT16)(ITEMDESC_AMMO_Y), BUTTON_TOGGLE ,MSYS_PRIORITY_HIGHEST, - DEFAULT_MOVE_CALLBACK, (GUI_CALLBACK)ItemDescAmmoCallback ); - } //if we are being init from the shop keeper screen and this is a dealer item we are getting info from if( guiTacticalInterfaceFlags & INTERFACE_SHOPKEEP_INTERFACE && pShopKeeperItemDescObject != NULL ) { @@ -5322,7 +5327,8 @@ BOOLEAN InternalInitItemDescriptionBox( OBJECTTYPE *pObject, INT16 sX, INT16 sY, DisableButton( giItemDescAmmoButton ); SetButtonFastHelpText( giItemDescAmmoButton, L"\0" ); } - else{ + else + { SetButtonFastHelpText( giItemDescAmmoButton, Message[ STR_EJECT_AMMO ] ); //CHRISL: Include the ubStatusIndex in the region information so we know which object in a stack we're looking at MSYS_SetBtnUserData( giItemDescAmmoButton, 1, ubStatusIndex ); @@ -5333,7 +5339,6 @@ BOOLEAN InternalInitItemDescriptionBox( OBJECTTYPE *pObject, INT16 sX, INT16 sY, SpecifyButtonTextOffsets( giItemDescAmmoButton, (UINT8) usX, (UINT8) usY, TRUE ); gfItemAmmoDown = FALSE; - } else { @@ -5466,7 +5471,6 @@ BOOLEAN InternalInitItemDescriptionBox( OBJECTTYPE *pObject, INT16 sX, INT16 sY, (UINT16)(gMoneyButtonLoc.x + gMoneyButtonOffsets[cnt].x), (UINT16)(gMoneyButtonLoc.y + gMoneyButtonOffsets[cnt].y), BUTTON_TOGGLE, MSYS_PRIORITY_HIGHEST, DEFAULT_MOVE_CALLBACK, BtnMoneyButtonCallback ); MSYS_SetBtnUserData( guiMoneyButtonBtn[cnt], 0, cnt); - } else { @@ -5500,7 +5504,6 @@ BOOLEAN InternalInitItemDescriptionBox( OBJECTTYPE *pObject, INT16 sX, INT16 sY, } } - // HEADROCK HAM 4: Three UDB tab buttons if (UsingEDBSystem() > 0) { @@ -5606,8 +5609,7 @@ BOOLEAN InternalInitItemDescriptionBox( OBJECTTYPE *pObject, INT16 sX, INT16 sY, } fInterfacePanelDirty = DIRTYLEVEL2; - - + gfInItemDescBox = TRUE; CHECKF( ReloadItemDesc( ) ); @@ -5658,9 +5660,7 @@ BOOLEAN InternalInitItemDescriptionBox( OBJECTTYPE *pObject, INT16 sX, INT16 sY, SetFactTrue( FACT_ATTACHED_ITEM_BEFORE ); gfItemDescHelpTextOffset = TRUE; } - - - + return( TRUE ); } @@ -6046,6 +6046,13 @@ void RenderBulletIcon(OBJECTTYPE *pObject, UINT32 ubStatusIndex) swprintf( pStr, L"%d", (*pObject)[ubStatusIndex]->data.gun.ubGunShotsLeft ); SpecifyButtonText( giItemDescAmmoButton, pStr ); + + // Flugente: redo the ammo colour, as it might have changed + INT16 sForeColour = (INT16)Get16BPPColor( FROMRGB( AmmoTypes[( *pObject )[ubStatusIndex]->data.gun.ubGunAmmoType].red, + AmmoTypes[( *pObject )[ubStatusIndex]->data.gun.ubGunAmmoType].green, + AmmoTypes[( *pObject )[ubStatusIndex]->data.gun.ubGunAmmoType].blue ) ); + + SpecifyButtonUpTextColors( giItemDescAmmoButton, sForeColour, -1 ); } void ItemDescAmmoCallback(GUI_BUTTON *btn,INT32 reason) diff --git a/Tactical/Item Types.h b/Tactical/Item Types.h index 43b01218..2d2190b0 100644 --- a/Tactical/Item Types.h +++ b/Tactical/Item Types.h @@ -1692,6 +1692,7 @@ typedef enum // Flugente: in order not to loop over MAXITEMS items if we only have a few thousand, remember the actual number of items in the xml extern UINT32 gMAXITEMS_READ; +extern UINT32 gMAXAMMOTYPES_READ; /* CHRISL: Arrays to track ic group information. These allow us to determine which LBE slots control which pockets and what LBE class the pockets are.*/ diff --git a/Tactical/Weapons.h b/Tactical/Weapons.h index 6059f4e4..5380a827 100644 --- a/Tactical/Weapons.h +++ b/Tactical/Weapons.h @@ -206,13 +206,11 @@ enum typedef struct { UINT32 uiIndex; - - // on interface - UINT8 fontColour; - // in detail screen (interface\infobox.sti) - INT32 grayed; - INT32 offNormal; - INT32 onNormal; + + // Flugente: fontColour takes RGB values from a sti library. Why not take RGB values directly? + UINT8 red; + UINT8 green; + UINT8 blue; // bullet contact with structure INT32 structureImpactReductionMultiplier; diff --git a/Tactical/XML_AmmoTypes.cpp b/Tactical/XML_AmmoTypes.cpp index df7f0f3a..57cef4cb 100644 --- a/Tactical/XML_AmmoTypes.cpp +++ b/Tactical/XML_AmmoTypes.cpp @@ -9,6 +9,8 @@ #include "XML.h" #endif +// Flugente: remember how many ammotypes we read +UINT32 gMAXAMMOTYPES_READ = 0; struct { @@ -49,10 +51,9 @@ ammotypeStartElementHandle(void *userData, const XML_Char *name, const XML_Char } else if(pData->curElement == ELEMENT && (strcmp(name, "uiIndex") == 0 || - strcmp(name, "fontColour") == 0 || - strcmp(name, "grayed") == 0 || - strcmp(name, "offNormal") == 0 || - strcmp(name, "onNormal") == 0 || + strcmp(name, "red" ) == 0 || + strcmp(name, "green" ) == 0 || + strcmp(name, "blue" ) == 0 || strcmp(name, "structureImpactReductionMultiplier") == 0 || strcmp(name, "armourImpactReductionMultiplier") == 0 || strcmp(name, "afterArmourDamageMultiplier") == 0 || @@ -132,31 +133,28 @@ ammotypeEndElementHandle(void *userData, const XML_Char *name) { pData->curArray[pData->curAmmoType.uiIndex] = pData->curAmmoType; //write the ammotype into the table } + + gMAXAMMOTYPES_READ = pData->curAmmoType.uiIndex; } else if(strcmp(name, "uiIndex") == 0) { pData->curElement = ELEMENT; pData->curAmmoType.uiIndex = (UINT32) strtoul(pData->szCharData, NULL, 0); } - else if(strcmp(name, "fontColour") == 0) + else if ( strcmp( name, "red" ) == 0 ) { pData->curElement = ELEMENT; - pData->curAmmoType.fontColour = (UINT8) atol(pData->szCharData); + pData->curAmmoType.red = (UINT8)atol( pData->szCharData ); } - else if(strcmp(name, "grayed") == 0) + else if ( strcmp( name, "green" ) == 0 ) { pData->curElement = ELEMENT; - pData->curAmmoType.grayed = (INT32) atol(pData->szCharData); + pData->curAmmoType.green = (UINT8)atol( pData->szCharData ); } - else if(strcmp(name, "offNormal") == 0) + else if ( strcmp( name, "blue" ) == 0 ) { pData->curElement = ELEMENT; - pData->curAmmoType.offNormal = (INT32) atol(pData->szCharData); - } - else if(strcmp(name, "onNormal") == 0) - { - pData->curElement = ELEMENT; - pData->curAmmoType.onNormal = (INT32) atol(pData->szCharData); + pData->curAmmoType.blue = (UINT8)atol( pData->szCharData ); } else if(strcmp(name, "structureImpactReductionMultiplier") == 0) { @@ -382,19 +380,16 @@ BOOLEAN ReadInAmmoTypeStats(STR fileName) lpcBuffer[uiFSize] = 0; //add a null terminator FileClose( hFile ); - - + XML_SetElementHandler(parser, ammotypeStartElementHandle, ammotypeEndElementHandle); XML_SetCharacterDataHandler(parser, ammotypeCharacterDataHandle); - - + memset(&pData,0,sizeof(pData)); pData.curArray = AmmoTypes; pData.maxArraySize = MAXITEMS; XML_SetUserData(parser, &pData); - - + if(!XML_Parse(parser, lpcBuffer, uiFSize, TRUE)) { CHAR8 errorBuf[511]; @@ -406,14 +401,16 @@ BOOLEAN ReadInAmmoTypeStats(STR fileName) return FALSE; } - MemFree(lpcBuffer); + // entries read were x -> x+1 entries + ++gMAXAMMOTYPES_READ; + MemFree(lpcBuffer); XML_ParserFree(parser); - return( TRUE ); } + BOOLEAN WriteAmmoTypeStats() { //DebugMsg (TOPIC_JA2,DBG_LEVEL_3,"writeammotypestats"); @@ -426,19 +423,15 @@ BOOLEAN WriteAmmoTypeStats() return( FALSE ); { - UINT32 cnt; - FilePrintf(hFile,"\r\n"); - for(cnt = 0;cnt < MAXITEMS;cnt++) + for ( UINT32 cnt = 0;cnt < gMAXAMMOTYPES_READ; ++cnt) { - FilePrintf(hFile,"\t\r\n"); FilePrintf(hFile,"\t\t%d\r\n", cnt ); - FilePrintf(hFile,"\t\t%d\r\n", AmmoTypes[cnt].fontColour ); - FilePrintf(hFile,"\t\t%d\r\n", AmmoTypes[cnt].grayed ); - FilePrintf(hFile,"\t\t%d\r\n", AmmoTypes[cnt].offNormal ); - FilePrintf(hFile,"\t\t%d\r\n", AmmoTypes[cnt].onNormal ); + FilePrintf(hFile,"\t\t%d\r\n", AmmoTypes[cnt].red ); + FilePrintf(hFile,"\t\t%d\r\n", AmmoTypes[cnt].green ); + FilePrintf(hFile,"\t\t%d\r\n", AmmoTypes[cnt].blue ); FilePrintf(hFile,"\t\t%d\r\n", AmmoTypes[cnt].structureImpactReductionMultiplier ); FilePrintf(hFile,"\t\t%d\r\n", AmmoTypes[cnt].structureImpactReductionDivisor ); FilePrintf(hFile,"\t\t%d\r\n", AmmoTypes[cnt].armourImpactReductionMultiplier );