2009-05-08 13:28:41 +00:00
/*
* OpenClonk , http : //www.openclonk.org
*
2013-12-17 20:01:09 +00:00
* Copyright ( c ) 1998 - 2000 , Matthes Bender
* Copyright ( c ) 2001 - 2009 , RedWolf Design GmbH , http : //www.clonk.de/
2016-04-03 18:18:29 +00:00
* Copyright ( c ) 2009 - 2016 , The OpenClonk Team and contributors
2009-05-08 13:28:41 +00:00
*
2013-12-17 20:01:09 +00:00
* Distributed under the terms of the ISC license ; see accompanying file
* " COPYING " for details .
2009-05-08 13:28:41 +00:00
*
2013-12-17 20:01:09 +00:00
* " Clonk " is a registered trademark of Matthes Bender , used with permission .
* See accompanying file " TRADEMARK " for details .
2009-05-08 13:28:41 +00:00
*
2013-12-17 20:01:09 +00:00
* To redistribute this file separately , substitute the full license texts
* for the above references .
2009-05-08 13:28:41 +00:00
*/
/* Operates viewports, message board and draws the game */
2016-04-03 18:07:56 +00:00
# include "C4Include.h"
2016-10-22 11:19:22 +00:00
# include "C4ForbidLibraryCompilation.h"
2016-04-03 18:07:56 +00:00
# include "game/C4GraphicsSystem.h"
2009-05-08 13:28:41 +00:00
2016-04-03 18:07:56 +00:00
# include "editor/C4Console.h"
2017-04-30 08:49:09 +00:00
# include "game/C4Application.h"
2016-04-03 18:07:56 +00:00
# include "game/C4FullScreen.h"
2017-04-30 08:49:09 +00:00
# include "game/C4Viewport.h"
# include "graphics/C4Draw.h"
# include "graphics/C4GraphicsResource.h"
# include "graphics/StdPNG.h"
2016-04-03 18:07:56 +00:00
# include "gui/C4Gui.h"
# include "gui/C4LoaderScreen.h"
# include "landscape/C4Landscape.h"
2016-04-02 15:50:49 +00:00
# include "landscape/C4Sky.h"
2016-04-03 18:07:56 +00:00
# include "network/C4Network2.h"
# include "object/C4GameObjects.h"
2009-05-08 13:28:41 +00:00
2016-02-01 19:47:37 +00:00
static const int MAX_BACKGROUND_FPS = 5 ;
2009-05-08 13:28:41 +00:00
C4GraphicsSystem : : C4GraphicsSystem ( )
2010-03-28 17:58:21 +00:00
{
2009-05-08 13:28:41 +00:00
Default ( ) ;
2010-03-28 17:58:21 +00:00
}
2009-05-08 13:28:41 +00:00
C4GraphicsSystem : : ~ C4GraphicsSystem ( )
2010-03-28 17:58:21 +00:00
{
2009-05-08 13:28:41 +00:00
Clear ( ) ;
2010-03-28 17:58:21 +00:00
}
2009-05-08 13:28:41 +00:00
2009-08-15 18:50:32 +00:00
bool C4GraphicsSystem : : Init ( )
2010-03-28 17:58:21 +00:00
{
2009-05-08 13:28:41 +00:00
// Success
2009-08-15 18:50:32 +00:00
return true ;
2010-03-28 17:58:21 +00:00
}
2009-05-08 13:28:41 +00:00
void C4GraphicsSystem : : Clear ( )
2010-03-28 17:58:21 +00:00
{
2009-05-08 13:28:41 +00:00
// Clear message board
2015-12-27 21:26:40 +00:00
MessageBoard . reset ( ) ;
2009-05-08 13:28:41 +00:00
// clear loader
2016-11-02 23:58:02 +00:00
if ( pLoaderScreen ) { delete pLoaderScreen ; pLoaderScreen = nullptr ; }
2009-05-08 13:28:41 +00:00
// Close viewports
2010-09-29 01:44:05 +00:00
: : Viewports . Clear ( ) ;
2009-05-08 13:28:41 +00:00
// No debug stuff
DeactivateDebugOutput ( ) ;
2010-03-28 17:58:21 +00:00
}
2009-05-08 13:28:41 +00:00
bool C4GraphicsSystem : : StartDrawing ( )
2010-03-28 17:58:21 +00:00
{
2009-05-08 13:28:41 +00:00
// only if ddraw is ready
2011-10-03 14:30:18 +00:00
if ( ! pDraw ) return false ;
if ( ! pDraw - > Active ) return false ;
2009-05-08 13:28:41 +00:00
2016-02-01 19:47:37 +00:00
// if the window is not focused, draw no more than MAX_BACKGROUND_FPS frames per second
if ( ! Application . Active & & ( C4TimeMilliseconds : : Now ( ) - lastFrame ) < 1000 / MAX_BACKGROUND_FPS )
return false ;
2009-05-08 13:28:41 +00:00
// drawing OK
return true ;
2010-03-28 17:58:21 +00:00
}
2009-05-08 13:28:41 +00:00
void C4GraphicsSystem : : FinishDrawing ( )
2010-03-28 17:58:21 +00:00
{
2010-09-28 18:16:33 +00:00
if ( ! Application . isEditor ) FullScreen . pSurface - > PageFlip ( ) ;
2016-02-01 19:47:37 +00:00
lastFrame = C4TimeMilliseconds : : Now ( ) ;
2010-03-28 17:58:21 +00:00
}
2009-05-08 13:28:41 +00:00
void C4GraphicsSystem : : Execute ( )
2010-03-28 17:58:21 +00:00
{
2009-05-08 13:28:41 +00:00
// activity check
if ( ! StartDrawing ( ) ) return ;
bool fBGDrawn = false ;
// If lobby running, message board only (page flip done by startup message board)
2010-10-29 23:47:50 +00:00
if ( ! : : pGUI - > HasFullscreenDialog ( true ) ) // allow for message board behind GUI
2010-03-28 17:58:21 +00:00
if ( : : Network . isLobbyActive ( ) | | ! Game . IsRunning )
2010-09-28 18:16:33 +00:00
if ( ! Application . isEditor )
2010-03-28 17:58:21 +00:00
{
2009-05-08 13:28:41 +00:00
// Message board
if ( iRedrawBackground ) ClearFullscreenBackground ( ) ;
2015-12-27 21:26:40 +00:00
MessageBoard - > Execute ( ) ;
2010-10-29 23:47:50 +00:00
if ( ! C4GUI : : IsActive ( ) )
2009-05-08 13:28:41 +00:00
{ FinishDrawing ( ) ; return ; }
fBGDrawn = true ;
2010-03-28 17:58:21 +00:00
}
2009-05-08 13:28:41 +00:00
// fullscreen GUI?
2010-10-29 23:47:50 +00:00
if ( ! Application . isEditor & & C4GUI : : IsActive ( ) & & ( : : pGUI - > HasFullscreenDialog ( false ) | | ! Game . IsRunning ) )
2010-03-28 17:58:21 +00:00
{
2009-05-08 13:28:41 +00:00
if ( ! fBGDrawn & & iRedrawBackground ) ClearFullscreenBackground ( ) ;
2009-06-05 16:53:56 +00:00
: : pGUI - > Render ( ! fBGDrawn ) ;
2009-05-08 13:28:41 +00:00
FinishDrawing ( ) ;
return ;
2010-03-28 17:58:21 +00:00
}
2009-05-08 13:28:41 +00:00
2013-04-04 16:12:34 +00:00
2009-05-08 13:28:41 +00:00
// Reset object audibility
2009-06-15 21:47:26 +00:00
: : Objects . ResetAudibility ( ) ;
2009-05-08 13:28:41 +00:00
// some hack to ensure the mouse is drawn after a dialog close and before any
// movement messages
2010-10-29 23:47:50 +00:00
if ( ! C4GUI : : IsActive ( ) )
2010-09-29 21:58:59 +00:00
: : pGUI - > SetMouseInGUI ( false , false ) ;
2009-05-08 13:28:41 +00:00
// Viewports
2010-09-29 01:44:05 +00:00
: : Viewports . Execute ( ! Application . isEditor & & iRedrawBackground ) ;
if ( iRedrawBackground ) - - iRedrawBackground ;
2009-05-08 13:28:41 +00:00
2010-09-28 18:16:33 +00:00
if ( ! Application . isEditor )
2010-03-28 17:58:21 +00:00
{
2009-05-08 13:28:41 +00:00
// Upper board
UpperBoard . Execute ( ) ;
// Message board
2015-12-27 21:26:40 +00:00
MessageBoard - > Execute ( ) ;
2009-05-08 13:28:41 +00:00
// Help & Messages
DrawHelp ( ) ;
DrawHoldMessages ( ) ;
DrawFlashMessage ( ) ;
2010-03-28 17:58:21 +00:00
}
2009-05-08 13:28:41 +00:00
// InGame-GUI
2010-10-29 23:47:50 +00:00
if ( C4GUI : : IsActive ( ) )
2010-03-28 17:58:21 +00:00
{
2009-06-05 16:53:56 +00:00
: : pGUI - > Render ( false ) ;
2010-03-28 17:58:21 +00:00
}
2009-05-08 13:28:41 +00:00
// done
FinishDrawing ( ) ;
2010-03-28 17:58:21 +00:00
}
2009-05-08 13:28:41 +00:00
void C4GraphicsSystem : : Default ( )
2010-03-28 17:58:21 +00:00
{
2017-05-03 18:28:00 +00:00
MessageBoard = std : : make_unique < C4MessageBoard > ( ) ;
2009-05-08 13:28:41 +00:00
InvalidateBg ( ) ;
2009-08-15 18:50:32 +00:00
ShowVertices = false ;
ShowAction = false ;
ShowCommand = false ;
ShowEntrance = false ;
ShowPathfinder = false ;
ShowNetstatus = false ;
2015-07-15 00:44:11 +00:00
Show8BitSurface = 0 ;
2012-09-20 11:33:38 +00:00
ShowLights = false ;
2013-04-04 16:12:34 +00:00
ShowMenuInfo = false ;
2009-08-15 18:50:32 +00:00
ShowHelp = false ;
2009-05-08 13:28:41 +00:00
FlashMessageText [ 0 ] = 0 ;
FlashMessageTime = 0 ; FlashMessageX = FlashMessageY = 0 ;
2016-11-02 23:58:02 +00:00
pLoaderScreen = nullptr ;
2010-03-28 17:58:21 +00:00
}
2009-05-08 13:28:41 +00:00
void C4GraphicsSystem : : ClearFullscreenBackground ( )
2010-03-28 17:58:21 +00:00
{
2011-10-03 14:30:18 +00:00
pDraw - > FillBG ( 0 ) ;
2009-05-08 13:28:41 +00:00
- - iRedrawBackground ;
2010-03-28 17:58:21 +00:00
}
2009-05-08 13:28:41 +00:00
2012-10-02 21:02:52 +00:00
bool C4GraphicsSystem : : InitLoaderScreen ( const char * szLoaderSpec )
2010-03-28 17:58:21 +00:00
{
2009-05-08 13:28:41 +00:00
// create new loader; overwrite current only if successful
C4LoaderScreen * pNewLoader = new C4LoaderScreen ( ) ;
2012-10-02 21:02:52 +00:00
pNewLoader - > SetBlackScreen ( false ) ;
2009-08-15 18:50:32 +00:00
if ( ! pNewLoader - > Init ( szLoaderSpec ) ) { delete pNewLoader ; return false ; }
2009-05-08 13:28:41 +00:00
if ( pLoaderScreen ) delete pLoaderScreen ;
pLoaderScreen = pNewLoader ;
// done, success
2009-08-15 18:50:32 +00:00
return true ;
2010-03-28 17:58:21 +00:00
}
2009-05-08 13:28:41 +00:00
void C4GraphicsSystem : : EnableLoaderDrawing ( )
2010-03-28 17:58:21 +00:00
{
2009-05-08 13:28:41 +00:00
// reset black screen loader flag
if ( pLoaderScreen ) pLoaderScreen - > SetBlackScreen ( false ) ;
2010-03-28 17:58:21 +00:00
}
2009-05-08 13:28:41 +00:00
2013-09-20 21:50:19 +00:00
bool C4GraphicsSystem : : SaveScreenshot ( bool fSaveAll , float fSaveAllZoom )
2010-03-28 17:58:21 +00:00
{
2015-09-30 00:48:34 +00:00
// Find a unique screenshot filename by iterating over all possible names
// Keep static counter so multiple screenshots in succession do not use same filename even if the background thread hasn't started writing the file yet
2009-05-08 13:28:41 +00:00
char szFilename [ _MAX_PATH + 1 ] ;
2015-09-30 00:48:34 +00:00
static int32_t iScreenshotIndex = 1 ;
2016-11-02 23:58:02 +00:00
const char * strFilePath = nullptr ;
2009-05-08 13:28:41 +00:00
do
sprintf ( szFilename , " Screenshot%03i.png " , iScreenshotIndex + + ) ;
while ( FileExists ( strFilePath = Config . AtScreenshotPath ( szFilename ) ) ) ;
2013-09-20 21:50:19 +00:00
bool fSuccess = DoSaveScreenshot ( fSaveAll , strFilePath , fSaveAllZoom ) ;
2009-05-08 13:28:41 +00:00
// log if successful/where it has been stored
if ( ! fSuccess )
2009-05-11 13:09:53 +00:00
LogF ( LoadResStr ( " IDS_PRC_SCREENSHOTERROR " ) , Config . AtUserDataRelativePath ( Config . AtScreenshotPath ( szFilename ) ) ) ;
2009-05-08 13:28:41 +00:00
else
2009-05-11 13:09:53 +00:00
LogF ( LoadResStr ( " IDS_PRC_SCREENSHOT " ) , Config . AtUserDataRelativePath ( Config . AtScreenshotPath ( szFilename ) ) ) ;
2009-05-08 13:28:41 +00:00
// return success
return ! ! fSuccess ;
2010-03-28 17:58:21 +00:00
}
2009-05-08 13:28:41 +00:00
2013-09-20 21:50:19 +00:00
bool C4GraphicsSystem : : DoSaveScreenshot ( bool fSaveAll , const char * szFilename , float fSaveAllZoom )
2010-03-28 17:58:21 +00:00
{
2009-05-08 13:28:41 +00:00
// Fullscreen only
2017-12-23 11:11:28 +00:00
if ( Application . isEditor )
{
Log ( LoadResStr ( " IDS_PRC_SCREENSHOTERROREDITOR " ) ) ;
return false ;
}
2009-05-08 13:28:41 +00:00
// back surface must be present
2010-03-06 14:07:30 +00:00
if ( ! FullScreen . pSurface ) return false ;
2009-05-08 13:28:41 +00:00
// save landscape
if ( fSaveAll )
2010-03-28 17:58:21 +00:00
{
2013-09-14 18:04:15 +00:00
// Create full map screenshots at zoom 2x. Fractional zooms (like 1.7x) should work but might cause some trouble at screen borders.
2013-09-20 21:50:19 +00:00
float zoom = fSaveAllZoom ;
2009-05-08 13:28:41 +00:00
// get viewport to draw in
2010-09-29 01:44:05 +00:00
C4Viewport * pVP = : : Viewports . GetFirstViewport ( ) ; if ( ! pVP ) return false ;
2015-09-30 00:48:34 +00:00
// create image large enough to hold the landscape
std : : unique_ptr < CPNGFile > png ( new CPNGFile ( ) ) ;
2016-04-02 15:50:49 +00:00
int32_t lWdt = : : Landscape . GetWidth ( ) * zoom , lHgt = : : Landscape . GetHeight ( ) * zoom ;
2015-09-30 00:48:34 +00:00
if ( ! png - > Create ( lWdt , lHgt , false ) ) return false ;
2009-05-08 13:28:41 +00:00
// get backbuffer size
int32_t bkWdt = C4GUI : : GetScreenWdt ( ) , bkHgt = C4GUI : : GetScreenHgt ( ) ;
2009-08-15 18:50:32 +00:00
if ( ! bkWdt | | ! bkHgt ) return false ;
2009-05-08 13:28:41 +00:00
// facet for blitting
C4TargetFacet bkFct ;
// mark background to be redrawn
InvalidateBg ( ) ;
2015-02-02 23:59:46 +00:00
// draw on one big viewport
pVP - > SetOutputSize ( 0 , 0 , 0 , 0 , bkWdt , bkHgt ) ;
2009-05-08 13:28:41 +00:00
// backup and clear sky parallaxity
2016-04-02 15:50:49 +00:00
int32_t iParX = : : Landscape . GetSky ( ) . ParX ; : : Landscape . GetSky ( ) . ParX = 10 ;
int32_t iParY = : : Landscape . GetSky ( ) . ParY ; : : Landscape . GetSky ( ) . ParY = 10 ;
2015-02-02 23:59:46 +00:00
// backup and clear viewport borders
FLOAT_RECT vp_borders = { pVP - > BorderLeft , pVP - > BorderRight , pVP - > BorderTop , pVP - > BorderBottom } ;
pVP - > BorderLeft = pVP - > BorderRight = pVP - > BorderTop = pVP - > BorderBottom = 0.0f ;
2009-05-08 13:28:41 +00:00
// temporarily change viewport player
int32_t iVpPlr = pVP - > Player ; pVP - > Player = NO_OWNER ;
// blit all tiles needed
for ( int32_t iY = 0 ; iY < lHgt ; iY + = bkHgt ) for ( int32_t iX = 0 ; iX < lWdt ; iX + = bkWdt )
{
2010-03-28 17:58:21 +00:00
// get max width/height
int32_t bkWdt2 = bkWdt , bkHgt2 = bkHgt ;
if ( iX + bkWdt2 > lWdt ) bkWdt2 - = iX + bkWdt2 - lWdt ;
if ( iY + bkHgt2 > lHgt ) bkHgt2 - = iY + bkHgt2 - lHgt ;
// update facet
2015-10-17 21:35:33 +00:00
bkFct . Set ( FullScreen . pSurface , 0 , 0 , ceil ( float ( bkWdt2 ) / zoom ) , ceil ( float ( bkHgt2 ) / zoom ) , iX / zoom , iY / zoom , zoom , 0 , 0 ) ;
2010-03-28 17:58:21 +00:00
// draw there
2016-01-10 14:50:21 +00:00
pVP - > Draw ( bkFct , true , false ) ;
2010-03-28 17:58:21 +00:00
// render
FullScreen . pSurface - > PageFlip ( ) ; FullScreen . pSurface - > PageFlip ( ) ;
// get output (locking primary!)
if ( FullScreen . pSurface - > Lock ( ) )
2009-05-08 13:28:41 +00:00
{
2010-03-28 17:58:21 +00:00
// transfer each pixel - slooow...
2015-09-28 22:54:34 +00:00
for ( int32_t iY2 = 0 ; iY2 < bkHgt2 ; + + iY2 )
2015-12-15 18:44:22 +00:00
# ifndef USE_CONSOLE
2015-09-30 00:48:34 +00:00
glReadPixels ( 0 , FullScreen . pSurface - > Hgt - iY2 - 1 , bkWdt2 , 1 , GL_BGR , GL_UNSIGNED_BYTE , reinterpret_cast < BYTE * > ( png - > GetRow ( iY + iY2 ) ) + iX * 3 ) ;
2015-12-15 18:44:22 +00:00
# else
for ( int32_t iX2 = 0 ; iX2 < bkWdt2 ; + + iX2 )
png - > SetPix ( iX + iX2 , iY + iY2 , FullScreen . pSurface - > GetPixDw ( iX2 , iY2 , false ) ) ;
# endif
2010-03-28 17:58:21 +00:00
// done; unlock
FullScreen . pSurface - > Unlock ( ) ;
2015-09-30 00:48:34 +00:00
// This can take a long time and we would like to pump messages
// However, we're currently hogging the primary surface and horrible things might happen if we do that, including initiation of another screenshot
// The only thing that can be safely run is music (sound could play but that would just make them out of sync of the game)
: : Application . MusicSystem . Execute ( true ) ;
2009-05-08 13:28:41 +00:00
}
}
// restore viewport player
pVP - > Player = iVpPlr ;
2015-02-02 23:59:46 +00:00
// restore viewport borders
pVP - > BorderLeft = vp_borders . left ;
pVP - > BorderTop = vp_borders . top ;
pVP - > BorderRight = vp_borders . right ;
pVP - > BorderBottom = vp_borders . bottom ;
2009-05-08 13:28:41 +00:00
// restore parallaxity
2016-04-02 15:50:49 +00:00
: : Landscape . GetSky ( ) . ParX = iParX ;
: : Landscape . GetSky ( ) . ParY = iParY ;
2015-02-02 23:59:46 +00:00
// restore viewport size
: : Viewports . RecalculateViewports ( ) ;
2009-05-08 13:28:41 +00:00
// save!
2015-09-30 00:48:34 +00:00
CPNGFile : : ScheduleSaving ( png . release ( ) , szFilename ) ;
2015-10-10 03:05:50 +00:00
return true ;
2010-03-28 17:58:21 +00:00
}
2015-09-30 00:48:34 +00:00
// Save primary surface in background thread
return FullScreen . pSurface - > SavePNG ( szFilename , false , false , true ) ;
2010-03-28 17:58:21 +00:00
}
2009-05-08 13:28:41 +00:00
void C4GraphicsSystem : : DeactivateDebugOutput ( )
2010-03-28 17:58:21 +00:00
{
2009-08-15 18:50:32 +00:00
ShowVertices = false ;
ShowAction = false ;
ShowCommand = false ;
ShowEntrance = false ;
ShowPathfinder = false ; // allow pathfinder! - why this??
2012-09-20 11:33:38 +00:00
ShowLights = false ;
2015-07-15 00:44:11 +00:00
Show8BitSurface = 0 ;
2009-08-15 18:50:32 +00:00
ShowNetstatus = false ;
2013-04-04 16:12:34 +00:00
ShowMenuInfo = false ;
2010-03-28 17:58:21 +00:00
}
2009-05-08 13:28:41 +00:00
void C4GraphicsSystem : : DrawHoldMessages ( )
2010-03-28 17:58:21 +00:00
{
2010-09-28 18:16:33 +00:00
if ( ! Application . isEditor & & Game . HaltCount )
2010-03-28 17:58:21 +00:00
{
2011-10-03 14:30:18 +00:00
pDraw - > TextOut ( " Pause " , : : GraphicsResource . FontRegular , 1.0 ,
2010-03-28 17:58:21 +00:00
FullScreen . pSurface , C4GUI : : GetScreenWdt ( ) / 2 ,
2013-10-18 16:49:21 +00:00
C4GUI : : GetScreenHgt ( ) / 2 - : : GraphicsResource . FontRegular . GetLineHeight ( ) * 2 ,
2011-10-03 14:34:08 +00:00
C4Draw : : DEFAULT_MESSAGE_COLOR , ACenter ) ;
2009-06-05 15:14:20 +00:00
: : GraphicsSystem . OverwriteBg ( ) ;
2009-05-08 13:28:41 +00:00
}
2010-03-28 17:58:21 +00:00
}
2009-05-08 13:28:41 +00:00
void C4GraphicsSystem : : FlashMessage ( const char * szMessage )
2010-03-28 17:58:21 +00:00
{
2009-05-08 13:28:41 +00:00
// Store message
SCopy ( szMessage , FlashMessageText , C4MaxTitle ) ;
// Calculate message time
FlashMessageTime = SLen ( FlashMessageText ) * 2 ;
// Initial position
FlashMessageX = - 1 ;
FlashMessageY = 10 ;
// Upper board active: stay below upper board
if ( Config . Graphics . UpperBoard )
FlashMessageY + = C4UpperBoardHeight ;
// More than one viewport: try to stay below portraits etc.
2010-09-29 01:44:05 +00:00
if ( : : Viewports . GetViewportCount ( ) > 1 )
2009-05-08 13:28:41 +00:00
FlashMessageY + = 64 ;
// New flash message: redraw background (might be drawing one message on top of another)
InvalidateBg ( ) ;
2010-03-28 17:58:21 +00:00
}
2009-05-08 13:28:41 +00:00
void C4GraphicsSystem : : FlashMessageOnOff ( const char * strWhat , bool fOn )
2010-03-28 17:58:21 +00:00
{
2009-05-08 13:28:41 +00:00
StdStrBuf strMessage ;
strMessage . Format ( " %s: %s " , strWhat , LoadResStr ( fOn ? " IDS_CTL_ON " : " IDS_CTL_OFF " ) ) ;
FlashMessage ( strMessage . getData ( ) ) ;
2010-03-28 17:58:21 +00:00
}
2009-05-08 13:28:41 +00:00
void C4GraphicsSystem : : DrawFlashMessage ( )
2010-03-28 17:58:21 +00:00
{
2009-05-08 13:28:41 +00:00
if ( ! FlashMessageTime ) return ;
2010-09-28 18:16:33 +00:00
if ( Application . isEditor ) return ;
2011-10-03 14:30:18 +00:00
pDraw - > TextOut ( FlashMessageText , : : GraphicsResource . FontRegular , 1.0 , FullScreen . pSurface ,
2010-03-28 17:58:21 +00:00
( FlashMessageX = = - 1 ) ? C4GUI : : GetScreenWdt ( ) / 2 : FlashMessageX ,
( FlashMessageY = = - 1 ) ? C4GUI : : GetScreenHgt ( ) / 2 : FlashMessageY ,
2011-10-03 14:34:08 +00:00
C4Draw : : DEFAULT_MESSAGE_COLOR ,
2010-03-28 17:58:21 +00:00
( FlashMessageX = = - 1 ) ? ACenter : ALeft ) ;
2009-05-08 13:28:41 +00:00
FlashMessageTime - - ;
// Flash message timed out: redraw background
if ( ! FlashMessageTime ) InvalidateBg ( ) ;
2010-03-28 17:58:21 +00:00
}
2009-05-08 13:28:41 +00:00
void C4GraphicsSystem : : DrawHelp ( )
2010-03-28 17:58:21 +00:00
{
2009-05-08 13:28:41 +00:00
if ( ! ShowHelp ) return ;
2010-09-28 18:16:33 +00:00
if ( Application . isEditor ) return ;
2010-09-29 01:44:05 +00:00
int32_t iX = : : Viewports . ViewportArea . X , iY = : : Viewports . ViewportArea . Y ;
int32_t iWdt = : : Viewports . ViewportArea . Wdt ;
2009-05-08 13:28:41 +00:00
StdStrBuf strText ;
// left coloumn
strText . AppendFormat ( " [%s] \n \n " , LoadResStr ( " IDS_CTL_GAMEFUNCTIONS " ) ) ;
// main functions
strText . AppendFormat ( " <c ffff00>%s</c> - %s \n " , GetKeyboardInputName ( " ToggleShowHelp " ) . getData ( ) , LoadResStr ( " IDS_CON_HELP " ) ) ;
strText . AppendFormat ( " <c ffff00>%s</c> - %s \n " , GetKeyboardInputName ( " MusicToggle " ) . getData ( ) , LoadResStr ( " IDS_CTL_MUSIC " ) ) ;
strText . AppendFormat ( " <c ffff00>%s</c> - %s \n " , GetKeyboardInputName ( " NetClientListDlgToggle " ) . getData ( ) , LoadResStr ( " IDS_DLG_NETWORK " ) ) ;
// messages
StdCopyStrBuf strAltChatKey ( GetKeyboardInputName ( " ChatOpen " , false , 0 ) ) ;
strText . AppendFormat ( " \n <c ffff00>%s/%s</c> - %s \n " , GetKeyboardInputName ( " ChatOpen " , false , 1 ) . getData ( ) , strAltChatKey . getData ( ) , LoadResStr ( " IDS_CTL_SENDMESSAGE " ) ) ;
strText . AppendFormat ( " <c ffff00>%s</c> - %s \n " , GetKeyboardInputName ( " MsgBoardScrollUp " ) . getData ( ) , LoadResStr ( " IDS_CTL_MESSAGEBOARDBACK " ) ) ;
strText . AppendFormat ( " <c ffff00>%s</c> - %s \n " , GetKeyboardInputName ( " MsgBoardScrollDown " ) . getData ( ) , LoadResStr ( " IDS_CTL_MESSAGEBOARDFORWARD " ) ) ;
// irc chat
strText . AppendFormat ( " \n <c ffff00>%s</c> - %s \n " , GetKeyboardInputName ( " ToggleChat " ) . getData ( ) , LoadResStr ( " IDS_CTL_IRCCHAT " ) ) ;
// scoreboard
strText . AppendFormat ( " \n <c ffff00>%s</c> - %s \n " , GetKeyboardInputName ( " ScoreboardToggle " ) . getData ( ) , LoadResStr ( " IDS_CTL_SCOREBOARD " ) ) ;
// screenshots
strText . AppendFormat ( " \n <c ffff00>%s</c> - %s \n " , GetKeyboardInputName ( " Screenshot " ) . getData ( ) , LoadResStr ( " IDS_CTL_SCREENSHOT " ) ) ;
strText . AppendFormat ( " <c ffff00>%s</c> - %s \n " , GetKeyboardInputName ( " ScreenshotEx " ) . getData ( ) , LoadResStr ( " IDS_CTL_SCREENSHOTEX " ) ) ;
2011-10-03 14:30:18 +00:00
pDraw - > TextOut ( strText . getData ( ) , : : GraphicsResource . FontRegular , 1.0 , FullScreen . pSurface ,
2011-10-03 14:34:08 +00:00
iX + 128 , iY + 64 , C4Draw : : DEFAULT_MESSAGE_COLOR , ALeft ) ;
2009-05-08 13:28:41 +00:00
// right coloumn
strText . Clear ( ) ;
// game speed
strText . AppendFormat ( " \n \n <c ffff00>%s</c> - %s \n " , GetKeyboardInputName ( " GameSpeedUp " ) . getData ( ) , LoadResStr ( " IDS_CTL_GAMESPEEDUP " ) ) ;
strText . AppendFormat ( " <c ffff00>%s</c> - %s \n " , GetKeyboardInputName ( " GameSlowDown " ) . getData ( ) , LoadResStr ( " IDS_CTL_GAMESPEEDDOWN " ) ) ;
// debug
strText . AppendFormat ( " \n \n [%s] \n \n " , " Debug " ) ;
strText . AppendFormat ( " <c ffff00>%s</c> - %s \n " , GetKeyboardInputName ( " DbgModeToggle " ) . getData ( ) , LoadResStr ( " IDS_CTL_DEBUGMODE " ) ) ;
strText . AppendFormat ( " <c ffff00>%s</c> - %s \n " , GetKeyboardInputName ( " DbgShowVtxToggle " ) . getData ( ) , " Entrance+Vertices " ) ;
2015-01-15 18:57:01 +00:00
strText . AppendFormat ( " <c ffff00>%s</c> - %s \n " , GetKeyboardInputName ( " DbgShowActionToggle " ) . getData ( ) , " Actions/Commands/Pathfinder/Lights/Menus " ) ;
2015-07-15 00:44:11 +00:00
strText . AppendFormat ( " <c ffff00>%s</c> - %s \n " , GetKeyboardInputName ( " DbgShow8BitSurface " ) . getData ( ) , " 8-bit surfaces " ) ;
2011-10-03 14:30:18 +00:00
pDraw - > TextOut ( strText . getData ( ) , : : GraphicsResource . FontRegular , 1.0 , FullScreen . pSurface ,
2011-10-03 14:34:08 +00:00
iX + iWdt / 2 + 64 , iY + 64 , C4Draw : : DEFAULT_MESSAGE_COLOR , ALeft ) ;
2010-03-28 17:58:21 +00:00
}
2009-05-08 13:28:41 +00:00
bool C4GraphicsSystem : : ToggleShowNetStatus ( )
2010-03-28 17:58:21 +00:00
{
2009-05-08 13:28:41 +00:00
ShowNetstatus = ! ShowNetstatus ;
return true ;
2010-03-28 17:58:21 +00:00
}
2009-05-08 13:28:41 +00:00
bool C4GraphicsSystem : : ToggleShowVertices ( )
2010-03-28 17:58:21 +00:00
{
2009-05-08 13:28:41 +00:00
if ( ! Game . DebugMode & & ! Console . Active ) { FlashMessage ( LoadResStr ( " IDS_MSG_NODEBUGMODE " ) ) ; return false ; }
2015-11-15 15:15:25 +00:00
ShowVertices = ! ShowVertices ;
ShowEntrance = ! ShowEntrance ; // vertices and entrance now toggled together
2009-05-08 13:28:41 +00:00
FlashMessageOnOff ( " Entrance+Vertices " , ShowVertices | | ShowEntrance ) ;
return true ;
2010-03-28 17:58:21 +00:00
}
2009-05-08 13:28:41 +00:00
bool C4GraphicsSystem : : ToggleShowAction ( )
2010-03-28 17:58:21 +00:00
{
2009-05-08 13:28:41 +00:00
if ( ! Game . DebugMode & & ! Console . Active ) { FlashMessage ( LoadResStr ( " IDS_MSG_NODEBUGMODE " ) ) ; return false ; }
2015-01-15 18:57:01 +00:00
if ( ! ( ShowAction | | ShowCommand | | ShowPathfinder | | ShowLights | | ShowMenuInfo ) )
2010-03-28 17:58:21 +00:00
{ ShowAction = true ; FlashMessage ( " Actions " ) ; }
2009-05-08 13:28:41 +00:00
else if ( ShowAction )
2010-03-28 17:58:21 +00:00
{ ShowAction = false ; ShowCommand = true ; FlashMessage ( " Commands " ) ; }
2009-05-08 13:28:41 +00:00
else if ( ShowCommand )
2010-03-28 17:58:21 +00:00
{ ShowCommand = false ; ShowPathfinder = true ; FlashMessage ( " Pathfinder " ) ; }
2009-05-08 13:28:41 +00:00
else if ( ShowPathfinder )
2012-09-20 11:33:38 +00:00
{ ShowPathfinder = false ; ShowLights = true ; FlashMessage ( " Lights " ) ; }
else if ( ShowLights )
2015-01-15 18:57:01 +00:00
{ ShowLights = false ; ShowMenuInfo = true ; FlashMessage ( " Menu Info " ) ; }
2013-04-04 16:12:34 +00:00
else if ( ShowMenuInfo )
2015-01-15 18:57:01 +00:00
{ ShowMenuInfo = false ; FlashMessageOnOff ( " Actions/Commands/Pathfinder/Lights/Menus " , false ) ; }
2009-05-08 13:28:41 +00:00
return true ;
2010-03-28 17:58:21 +00:00
}
2009-05-08 13:28:41 +00:00
2015-07-15 00:44:11 +00:00
bool C4GraphicsSystem : : ToggleShow8BitSurface ( )
2010-03-28 17:58:21 +00:00
{
2009-05-08 13:28:41 +00:00
if ( ! Game . DebugMode & & ! Console . Active ) { FlashMessage ( LoadResStr ( " IDS_MSG_NODEBUGMODE " ) ) ; return false ; }
2015-07-15 00:44:11 +00:00
Show8BitSurface = ( Show8BitSurface + 1 ) % 3 ;
if ( Show8BitSurface = = 0 )
FlashMessage ( " Default view " ) ;
else if ( Show8BitSurface = = 1 )
FlashMessage ( " Foreground 8-bit landscape " ) ;
else if ( Show8BitSurface = = 2 )
FlashMessage ( " Background 8-bit landscape " ) ;
2009-05-08 13:28:41 +00:00
return true ;
2010-03-28 17:58:21 +00:00
}
2009-05-08 13:28:41 +00:00
bool C4GraphicsSystem : : ToggleShowHelp ( )
2010-03-28 17:58:21 +00:00
{
2015-11-15 15:15:25 +00:00
ShowHelp = ! ShowHelp ;
2009-05-08 13:28:41 +00:00
// Turned off? Invalidate background.
if ( ! ShowHelp ) InvalidateBg ( ) ;
return true ;
2010-03-28 17:58:21 +00:00
}
2009-05-08 13:28:41 +00:00