Files
source/Utils/Animated ProgressBar.cpp
T
Wanne 7ca53fadc7 *** MERGED source code from development trunk revision 4890 up to latest current revision 5105 ***
Development Trunk (now obsolete): https://ja2svn.dyndns.org/source/ja2/branches/Wanne/JA2%201.13%20MP
A detailed list of all the features (changes) is visible in the history log of the development trunk:

INFO: There will be no further development in the development source trunk, so is obsolete from now on!

This commit contains the following features (bugfixes are not listed):

- New Feature: Show merc ranks in Strategy Screen before merc name
o Toggle on/off in the ingame options screen
o For each experience level (0-10) there are defined rank names in the language specific text files
o Additional language text that is not translated yet is marked with // TODO.Translate

- New Feature: Faster Bobby Ray Shipments
o This feature is selectable in the ja2_options.ini
o When activated Bobby Ray shipments will be really fast
-> Overnight Express: 5 - 7 hours
-> Air Service: 10, 12 or 14 hours
-> Standard Service: 15, 18 or 21 hours
o In a multiplayer game, this feature is disabled (because shipment arrive immediately in the destination sector)

- New Feature: AP cost for manipulating the merc inventory
o This feature is selectable in the start new game screen
o For example, putting a weapon from hand in the backpack costs APs
o The AP costs are defined in the APBPConstants.ini
o In a multiplayer game, this feature is disabled

- New Feature: Added possibility to set individual Gear Kit names
o Set individual names in the optional new tag <mGearKitName> inside the <GEARKIT> root element (File: TableData\MercStartingGear.xml)

- New Feature: Externalized the maximum purchase amount (JA2 vanilla: 10) for Bobby Rays purchases per shipment
o Define the max. amount in the ja2_options.ini: BOBBY_RAY_MAX_PURCHASE_AMOUNT, Range: 10 - 100)
o Nice scrolling bars to scroll through all the purchases

- New Feature: Now it is possible to walk on "water" tiles or handle those tiles like "normal" tiles 
o (instead of showing the swimming animation and counting the APs for swimming), when the soldier is located on the second level (level > 0)

- New Feature: Externalized AIM Veterans laptop site
o Add maximum of 4 pages
o Add  new AIM to veterans page, and remove AIM from veterans page.
o New XML file: OldAIMArchive.xml (language specific XML files: *.OldAIMArchive.xml)

- New Feature: Added possibility to choose from 254 IMP faces
o Modified IMPPortraits.xml
o Added new GameDir folder "IMPFaces" which contains the IMP face portraits
o Moved IMP faces in the new "IMPFaces" folder

- New Feature: ARSP - All Resolution Support Project
o See here: http://www.ja-galaxy-forum.com/board/ubbthreads.php?ubb=showflat&Number=298698&page=1
o Support any kind of screen resolution. This works by choosing the matching full supported resolution (640x480, 800x600, 1024x768) and then centering the graphics
o See ja2.ini for defining the screen resolution

- New Feature: AI Turn Speed Up (FF-MOD)
o see here: http://www.ja-galaxy-forum.com/board/ubbthreads.php?ubb=showflat&Number=298699#Post298699
o When this feature is activated it allows fast enemy turns
o New entry in ja2.ini to enable this feature: HIGHSPEED_TIMER = TRUE
o Turn on/off auto fast turns in ingame options
o New ja2_options.ini settings for fine tuning: [Clock Settings] ini block

- New Feature: "Lock" / "Release" mouse cursor in tactical windowed mode, so the mouse can stay within window boundary
o This is very helpful for doing scrolling with the mouse (by moving the mouse to the window edge) in windowed mode
o You can toggle on/off the feature by pressing CTRL + Z. It is also possible to press CTRL + Y. So the user can decide which fits better :)
o Whenever you toggle on/off a screen message appears on the tactical log to notify the player

- New Feature: Weapon overheating
o Basically, every shot fired from a gun increases its temperature. On higher temperatures, the gun jams more frequently
o On/off toggle in the ingame options
o Graphical thermometer indication on the weapon picture
o New ja2_options.ini section with a few options, Section: [Tactical Weapon Overheating Settings]
o XML changes (New Tags)
--> AmmoTypes.xml: <temperatureModificator>
--> Items.xml: <barrel>, <usOverheatingCooldownFactor>
--> Weapons.xml: <usOverheatingJamThreshold>, <usOverheatingDamageThreshold>, <usOverheatingSingleShotTemperature>
o Added a few barells to Items.xml (end of the file)
o more infos: http://www.ja-galaxy-forum.com/board/ubbthreads.php?ubb=showflat&Number=301059&page=1

- New Feature: Resting weapons on a surfaces
o You can now rest your weapon on crates, low walls, rocks, debris, open windows etc. while you are crouched. Resting will give yu the superior gun handling modifiers from PRONE position.
o A little 'A' on your gun indicates if you are resting it or not.
o Both settings can be turned on and off in Ja2_Options.ini under 'Tactical Gameplay Settings'

- New Feature: Externalized option on whether mercs can exit sector using grid exit in turn based mode
o new ja2_options.ini property: GRID_EXIT_IN_TURNBASED
o This ini setting does not affect leaving sectors on map edges

- Rework/Update: Ammo boxes and Ammo crates
o Ammo crate items added for remaining calibers.  Tweaked prices to correspond to magazines, tweaked capacities and weights to be reasonable (~800 or less).
o Shift-R reload now looks at both boxes and crates in sector items and merc's inventory to reload, and tops off magazines in inventory as well.  Only possible outside of combat.
o Ctrl-Shift-A still creates crates as per usual, with some fixes to ensure all ammo is caught on the first press.
o Shift-A now creates ammo boxes in the same loop.  They mostly behave like crates, but fit in mercs inventories.
o Ammo boxes are available to purchase at BR and tony, sam, etc.  Individual magazines/drums/etc are no longer available.
o Removed ammo crate xml tag.  Added ubMagType tag to Magazines array.  This allows us to differentiate between magazines, bullets, boxes and crates.
o Changed ammo filtering in BR's to display boxes appropriately.  Added back the "Mag:" display (changed text to "Size:")
o Added ja2set.dat.xml file (WF map version in WF maps folder) to be used instead of ja2set.dat file (ja2.ini setting added) For now, if you want to play vanilla instead, just change the setting in the ini (see comments in file).
o Added P4-P9Items image files (up to 5k images each) and tileslots.  1.13 core items will continue to use Guns and P1-P3Items for the foreseeable future.  P4-P9 can be used by customizers/modders to avoid conflicts with Guns/P1-P3 items.  TODO: Need to discuss a strategy for this in the forums.
o Added in Ambient/0.bad and 32.bad to avoid an exception in the code.
o Updated the XML Editor
o Standardized the text on all the ammo items.

- New Multiplayer Feature: Sharing same FOV (field of view) in a coop/team-dm (for friendly teams) game
o You will also see enemies, that your teammate sees

git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@5108 3b4a5df2-a311-0410-b5c6-a8a6f20db521
2012-03-23 18:46:54 +00:00

396 lines
12 KiB
C++

#ifdef PRECOMPILEDHEADERS
#include "Utils All.h"
#else
#include "types.h"
#include "Animated ProgressBar.h"
#include "MemMan.h"
#include "debug.h"
#include "Font Control.h"
#include "vsurface.h"
#include "video.h"
#include "Render Dirty.h"
#include "music control.h"
#include "Timer Control.h"
#include "sysutil.h"
#include "math.h"
#endif
double rStart, rEnd;
double rActual;
#define MAX_PROGRESSBARS 4
PROGRESSBAR *pBar[ MAX_PROGRESSBARS ];
UINT16 gusLeftmostShaded = 0;
extern BOOLEAN bShowSmallImage;
void CreateLoadingScreenProgressBar()
{
gusLeftmostShaded = 162;
// Special case->show small image centered
if (bShowSmallImage == TRUE)
{
if (iResolution >= _800x600)
{
CreateProgressBar(0, iScreenWidthOffset + 162, iScreenHeightOffset + 427, iScreenWidthOffset + 480, iScreenHeightOffset + 443);
}
}
else
{
if (iResolution >= _640x480 && iResolution < _800x600)
{
CreateProgressBar(0, 162, 427, 480, 443);
}
else if (iResolution < _1024x768)
{
CreateProgressBar(0, (202 + (SCREEN_WIDTH - 800)/2), 533 + ((SCREEN_HEIGHT - 600) / 2), 600 + ((SCREEN_WIDTH - 800) / 2), 554 + ((SCREEN_HEIGHT - 600) / 2));
}
else
{
CreateProgressBar(0, 259 + ((SCREEN_WIDTH - 1024) / 2), 683 + ((SCREEN_HEIGHT - 768) / 2), 767 + ((SCREEN_WIDTH - 1024) / 2), 708 + ((SCREEN_HEIGHT - 768) / 2));
}
}
SetProgressBarUseBorder(0, FALSE );
}
void RemoveLoadingScreenProgressBar()
{
RemoveProgressBar( 0 );
SetFontShadow(DEFAULT_SHADOW);
}
// OJW - 20090422
void CreateProgressBarNoBorder( UINT8 ubProgressBarID, UINT16 usLeft, UINT16 usTop, UINT16 usRight, UINT16 usBottom )
{
CreateProgressBar( ubProgressBarID, usLeft, usTop, usRight, usBottom );
SetProgressBarUseBorder( ubProgressBarID, FALSE );
}
//This creates a single progress bar given the coordinates without a panel (containing a title and background).
//A panel is automatically created if you specify a title using SetProgressBarTitle
BOOLEAN CreateProgressBar( UINT8 ubProgressBarID, UINT16 usLeft, UINT16 usTop, UINT16 usRight, UINT16 usBottom )
{
PROGRESSBAR *pNew;
//Allocate new progress bar
pNew = (PROGRESSBAR*)MemAlloc( sizeof( PROGRESSBAR ) );
Assert( pNew );
if( pBar[ ubProgressBarID ] )
RemoveProgressBar( ubProgressBarID );
memset( pNew, 0, sizeof( PROGRESSBAR ) );
pBar[ ubProgressBarID ] = pNew;
pNew->ubProgressBarID = ubProgressBarID;
//Assign coordinates
pNew->usBarLeft = usLeft;
pNew->usBarTop = usTop;
pNew->usBarRight = usRight;
pNew->usBarBottom = usBottom;
//Init default data
pNew->fPanel = FALSE;
pNew->usMsgFont = (UINT16)FONT12POINT1;
pNew->ubMsgFontForeColor = FONT_BLACK;
pNew->ubMsgFontShadowColor = 0;
SetRelativeStartAndEndPercentage( pNew->ubProgressBarID, 0, 100, NULL );
pNew->swzTitle = NULL;
//Default the progress bar's color to be red
pNew->ubColorFillRed = 150;
pNew->ubColorFillGreen = 0;
pNew->ubColorFillBlue = 0;
pNew->fDisplayText = FALSE;
//OJW - 20090222
pNew->uiFrameBuffer = FRAME_BUFFER;
pNew->fDrawBorder = TRUE;
return TRUE;
}
//You may also define a panel to go in behind the progress bar. You can now assign a title to go with
//the panel.
void DefineProgressBarPanel( UINT32 ubID, UINT8 r, UINT8 g, UINT8 b,
UINT16 usLeft, UINT16 usTop, UINT16 usRight, UINT16 usBottom )
{
PROGRESSBAR *pCurr;
Assert( ubID < MAX_PROGRESSBARS );
pCurr = pBar[ ubID ];
if( !pCurr )
return;
pCurr->fPanel = TRUE;
pCurr->usPanelLeft = usLeft;
pCurr->usPanelTop = usTop;
pCurr->usPanelRight = usRight;
pCurr->usPanelBottom = usBottom;
pCurr->usColor = Get16BPPColor( FROMRGB( r, g, b ) );
//Calculate the slightly lighter and darker versions of the same rgb color
pCurr->usLtColor = Get16BPPColor( FROMRGB( (UINT8)min( 255, (UINT16)(r*1.33)),
(UINT8)min( 255, (UINT16)(g*1.33)),
(UINT8)min( 255, (UINT16)(b*1.33)) ));
pCurr->usDkColor = Get16BPPColor( FROMRGB( (UINT8)(r*0.75), (UINT8)(g*0.75), (UINT8)(b*0.75) ) );
}
//Assigning a title for the panel will automatically position the text horizontally centered on the
//panel and vertically centered from the top of the panel, to the top of the progress bar.
void SetProgressBarTitle( UINT32 ubID, STR16 pString, UINT32 usFont, UINT8 ubForeColor, UINT8 ubShadowColor )
{
PROGRESSBAR *pCurr;
Assert( ubID < MAX_PROGRESSBARS );
pCurr = pBar[ ubID ];
if( !pCurr )
return;
if( pCurr->swzTitle )
{
MemFree( pCurr->swzTitle );
pCurr->swzTitle = NULL;
}
if( pString && wcslen( pString ) )
{
pCurr->swzTitle = (STR16) MemAlloc( (UINT32) ( sizeof( CHAR16 ) * ( wcslen( pString ) + 1 ) ) );
swprintf( pCurr->swzTitle, pString );
}
pCurr->usTitleFont = (UINT16)usFont;
pCurr->ubTitleFontForeColor = ubForeColor;
pCurr->ubTitleFontShadowColor = ubShadowColor;
}
//Unless you set up the attributes, any text you pass to SetRelativeStartAndEndPercentage will
//default to FONT12POINT1 in a black color.
void SetProgressBarMsgAttributes( UINT32 ubID, UINT32 usFont, UINT8 ubForeColor, UINT8 ubShadowColor )
{
PROGRESSBAR *pCurr;
Assert( ubID < MAX_PROGRESSBARS );
pCurr = pBar[ ubID ];
if( !pCurr )
return;
pCurr->usMsgFont = (UINT16)usFont;
pCurr->ubMsgFontForeColor = ubForeColor;
pCurr->ubMsgFontShadowColor = ubShadowColor;
}
//OJW - 20090422
void SetProgressBarRenderBuffer( UINT32 ubID , UINT32 uiBufferID )
{
PROGRESSBAR *pCurr;
Assert( ubID < MAX_PROGRESSBARS );
pCurr = pBar[ ubID ];
if( !pCurr )
return;
pCurr->uiFrameBuffer = uiBufferID;
}
void SetProgressBarUseBorder( UINT32 ubID , BOOLEAN bBorder )
{
PROGRESSBAR *pCurr;
Assert( ubID < MAX_PROGRESSBARS );
pCurr = pBar[ ubID ];
if( !pCurr )
return;
pCurr->fDrawBorder = bBorder;
}
//When finished, the progress bar needs to be removed.
void RemoveProgressBar( UINT8 ubID )
{
Assert( ubID < MAX_PROGRESSBARS );
if( pBar[ubID] )
{
if( pBar[ubID]->swzTitle )
MemFree( pBar[ubID]->swzTitle );
MemFree( pBar[ubID] );
pBar[ubID] = NULL;
return;
}
}
//An important setup function. The best explanation is through example. The example being the loading
//of a file -- there are many stages of the map loading. In JA2, the first step is to load the tileset.
//Because it is a large chunk of the total loading of the map, we may gauge that it takes up 30% of the
//total load. Because it is also at the beginning, we would pass in the arguments ( 0, 30, "text" ).
//As the process animates using UpdateProgressBar( 0 to 100 ), the total progress bar will only reach 30%
//at the 100% mark within UpdateProgressBar. At that time, you would go onto the next step, resetting the
//relative start and end percentage from 30 to whatever, until your done.
void SetRelativeStartAndEndPercentage( UINT8 ubID, UINT16 uiRelStartPerc, UINT16 uiRelEndPerc, STR16 str)
{
PROGRESSBAR *pCurr;
UINT16 usStartX, usStartY;
Assert( ubID < MAX_PROGRESSBARS );
pCurr = pBar[ ubID ];
if( !pCurr )
return;
pCurr->rStart = (double)uiRelStartPerc*0.01f;
pCurr->rEnd = (double)uiRelEndPerc*0.01f;
//Render the entire panel now, as it doesn't need update during the normal rendering
if( pCurr->fPanel )
{
//Draw panel
ColorFillVideoSurfaceArea( FRAME_BUFFER,
pCurr->usPanelLeft, pCurr->usPanelTop, pCurr->usPanelRight, pCurr->usPanelBottom, pCurr->usLtColor );
ColorFillVideoSurfaceArea( FRAME_BUFFER,
pCurr->usPanelLeft+1, pCurr->usPanelTop+1, pCurr->usPanelRight, pCurr->usPanelBottom, pCurr->usDkColor );
ColorFillVideoSurfaceArea( FRAME_BUFFER,
pCurr->usPanelLeft+1, pCurr->usPanelTop+1, pCurr->usPanelRight-1, pCurr->usPanelBottom-1, pCurr->usColor );
InvalidateRegion( pCurr->usPanelLeft, pCurr->usPanelTop, pCurr->usPanelRight, pCurr->usPanelBottom );
//Draw title
if( pCurr->swzTitle )
{
usStartX = pCurr->usPanelLeft + // left position
(pCurr->usPanelRight - pCurr->usPanelLeft)/2 - // + half width
StringPixLength( pCurr->swzTitle, pCurr->usTitleFont ) / 2; // - half string width
usStartY = pCurr->usPanelTop + 3;
SetFont( pCurr->usTitleFont );
SetFontForeground( pCurr->ubTitleFontForeColor );
SetFontShadow( pCurr->ubTitleFontShadowColor );
SetFontBackground( 0 );
mprintf( usStartX, usStartY, pCurr->swzTitle );
}
}
if( pCurr->fDisplayText )
{
//Draw message
if( str )
{
if( pCurr->fUseSaveBuffer )
{
UINT16 usFontHeight = GetFontHeight( pCurr->usMsgFont );
RestoreExternBackgroundRect( pCurr->usBarLeft, pCurr->usBarBottom, (INT16)(pCurr->usBarRight-pCurr->usBarLeft), (INT16)(usFontHeight + 3) );
}
SetFont( pCurr->usMsgFont );
SetFontForeground( pCurr->ubMsgFontForeColor );
SetFontShadow( pCurr->ubMsgFontShadowColor );
SetFontBackground( 0 );
mprintf( pCurr->usBarLeft, pCurr->usBarBottom + 3, str );
}
}
}
//This part renders the progress bar at the percentage level that you specify. If you have set relative
//percentage values in the above function, then the uiPercentage will be reflected based off of the relative
//percentages.
void RenderProgressBar( UINT8 ubID, UINT32 uiPercentage )
{
static UINT32 uiLastTime = 0;
UINT32 uiCurTime = GetJA2Clock();
double rActual;
PROGRESSBAR *pCurr=NULL;
//UINT32 r, g;
INT32 end;
Assert( ubID < MAX_PROGRESSBARS );
pCurr = pBar[ubID];
if( pCurr == NULL )
return;
if( pCurr )
{
rActual = pCurr->rStart+(pCurr->rEnd-pCurr->rStart)*uiPercentage*0.01;
if( fabs(rActual - pCurr->rLastActual) < 0.01 )
{
return;
}
pCurr->rLastActual = ( DOUBLE )( ( INT32)( rActual * 100 ) * 0.01 );
end = (INT32)(pCurr->usBarLeft+2.0+rActual*(pCurr->usBarRight-pCurr->usBarLeft-4));
if( end < pCurr->usBarLeft+2 || end > pCurr->usBarRight-2 )
{
return;
}
if( !pCurr->fDrawBorder )
{
ColorFillVideoSurfaceArea( pCurr->uiFrameBuffer, //FRAME_BUFFER,
pCurr->usBarLeft, pCurr->usBarTop, end, pCurr->usBarBottom,
Get16BPPColor(FROMRGB( pCurr->ubColorFillRed, pCurr->ubColorFillGreen, pCurr->ubColorFillBlue )) );
//if( pCurr->usBarRight > gusLeftmostShaded )
//{
// ShadowVideoSurfaceRect( FRAME_BUFFER, gusLeftmostShaded+1, pCurr->usBarTop, end, pCurr->usBarBottom );
// gusLeftmostShaded = (UINT16)end;
//}
}
else
{
//Border edge of the progress bar itself in gray
ColorFillVideoSurfaceArea( pCurr->uiFrameBuffer,
pCurr->usBarLeft, pCurr->usBarTop, pCurr->usBarRight, pCurr->usBarBottom,
Get16BPPColor(FROMRGB(160, 160, 160)) );
//Interior of progress bar in black
ColorFillVideoSurfaceArea( pCurr->uiFrameBuffer,
pCurr->usBarLeft+2, pCurr->usBarTop+2, pCurr->usBarRight-2, pCurr->usBarBottom-2,
Get16BPPColor(FROMRGB( 0, 0, 0)) );
ColorFillVideoSurfaceArea(pCurr->uiFrameBuffer, pCurr->usBarLeft+2, pCurr->usBarTop+2, end, pCurr->usBarBottom-2, Get16BPPColor(FROMRGB(72 , 155, 24)));
}
InvalidateRegion( pCurr->usBarLeft, pCurr->usBarTop, pCurr->usBarRight, pCurr->usBarBottom );
ExecuteBaseDirtyRectQueue();
EndFrameBufferRender();
RefreshScreen( NULL );
}
// update music here
if( uiCurTime > ( uiLastTime + 200 ) )
{
MusicPoll( TRUE );
uiLastTime = GetJA2Clock();
}
}
void SetProgressBarColor( UINT8 ubID, UINT8 ubColorFillRed, UINT8 ubColorFillGreen, UINT8 ubColorFillBlue )
{
PROGRESSBAR *pCurr=NULL;
Assert( ubID < MAX_PROGRESSBARS );
pCurr = pBar[ubID];
if( pCurr == NULL )
return;
pCurr->ubColorFillRed = ubColorFillRed;
pCurr->ubColorFillGreen = ubColorFillGreen;
pCurr->ubColorFillBlue = ubColorFillBlue;
}
void SetProgressBarTextDisplayFlag( UINT8 ubID, BOOLEAN fDisplayText, BOOLEAN fUseSaveBuffer, BOOLEAN fSaveScreenToFrameBuffer )
{
PROGRESSBAR *pCurr=NULL;
Assert( ubID < MAX_PROGRESSBARS );
pCurr = pBar[ubID];
if( pCurr == NULL )
return;
pCurr->fDisplayText = fDisplayText;
pCurr->fUseSaveBuffer = fUseSaveBuffer;
//if we are to use the save buffer, blit the portion of the screen to the save buffer
if( fSaveScreenToFrameBuffer )
{
UINT16 usFontHeight = GetFontHeight( pCurr->usMsgFont )+3;
//blit everything to the save buffer ( cause the save buffer can bleed through )
BlitBufferToBuffer(guiRENDERBUFFER, guiSAVEBUFFER, pCurr->usBarLeft, pCurr->usBarBottom, (UINT16)(pCurr->usBarRight-pCurr->usBarLeft), usFontHeight );
}
}