2014-10-06 14:50:05 +02:00
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers , whose names
* are too numerous to list here . Please refer to the COPYRIGHT
* file distributed with this source distribution .
*
* This program is free software ; you can redistribute it and / or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation ; either version 2
* of the License , or ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program ; if not , write to the Free Software
* Foundation , Inc . , 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 , USA .
*
*/
/*
* This code is based on Labyrinth of Time code with assistance of
*
* Copyright ( c ) 1993 Terra Nova Development
* Copyright ( c ) 2004 The Wyrmkeep Entertainment Co .
*
*/
2015-02-19 15:41:15 +02:00
# include "common/translation.h"
# include "gui/message.h"
# include "gui/saveload.h"
2014-12-25 19:13:52 +01:00
# include "lab/lab.h"
2015-12-08 21:10:54 +01:00
2015-12-08 21:19:41 +01:00
# include "lab/dispman.h"
# include "lab/eventman.h"
2015-12-08 21:10:54 +01:00
# include "lab/image.h"
2015-12-08 21:28:45 +01:00
# include "lab/interface.h"
2015-12-08 21:00:50 +01:00
# include "lab/labsets.h"
2015-12-08 20:36:05 +01:00
# include "lab/music.h"
2015-12-08 21:10:54 +01:00
# include "lab/resource.h"
2015-12-08 20:53:44 +01:00
# include "lab/savegame.h"
2015-12-08 21:00:50 +01:00
# include "lab/utils.h"
2014-10-06 14:50:05 +02:00
namespace Lab {
2015-07-21 22:09:00 +03:00
static uint16 MonGadHeight = 1 ;
static uint16 hipal [ 20 ] ;
2014-10-06 14:50:05 +02:00
2015-12-01 02:05:29 +02:00
static TextFont * journalFont ;
2015-07-21 22:09:00 +03:00
static char * journaltext , * journaltexttitle ;
static uint16 JPage = 0 ;
static bool lastpage = false ;
2015-10-12 17:13:42 +03:00
static Image JBackImage , ScreenImage ;
2015-07-21 22:09:00 +03:00
static bool GotBackImage = false ;
2015-10-16 01:52:53 +03:00
static uint16 monitorPage ;
2015-07-21 22:09:00 +03:00
static const char * TextFileName ;
2014-10-06 14:50:05 +02:00
2015-12-05 18:14:50 +02:00
Image * MonButton ;
2014-10-06 14:50:05 +02:00
2014-12-22 10:03:05 +01:00
# define INCL(BITSET,BIT) ((BITSET) |= (BIT))
# define SETBIT(BITSET,BITNUM) INCL(BITSET, (1 << (BITNUM)))
# define INBIT(BITSET,BITNUM) ( ((1 << (BITNUM)) & (BITSET)) > 0 )
2015-12-08 09:19:00 +01:00
# define BRIDGE0 148
# define BRIDGE1 104
# define DIRTY 175
# define NONEWS 135
# define NOCLEAN 152
# define QUARTERNUM 30
2014-12-22 10:03:05 +01:00
2014-10-06 14:50:05 +02:00
static byte * loadBackPict ( const char * fileName , bool tomem ) {
2015-12-06 14:36:49 +01:00
byte * res = nullptr ;
2014-10-06 14:50:05 +02:00
2015-12-06 18:16:26 +01:00
g_lab - > _graphics - > FadePalette = hipal ;
2015-12-02 00:34:51 +01:00
g_lab - > _anim - > _noPalChange = true ;
2014-10-06 14:50:05 +02:00
if ( tomem )
2015-12-06 14:36:49 +01:00
res = g_lab - > _graphics - > readPictToMem ( fileName , g_lab - > _graphics - > _screenWidth , g_lab - > _graphics - > _screenHeight ) ;
2014-10-06 14:50:05 +02:00
else
2015-12-04 13:32:08 +01:00
g_lab - > _graphics - > readPict ( fileName , true ) ;
2014-10-06 14:50:05 +02:00
2015-11-27 23:18:15 +01:00
for ( uint16 i = 0 ; i < 16 ; i + + ) {
2015-12-02 00:34:51 +01:00
hipal [ i ] = ( ( g_lab - > _anim - > _diffPalette [ i * 3 ] > > 2 ) < < 8 ) +
2015-12-08 09:19:00 +01:00
( ( g_lab - > _anim - > _diffPalette [ i * 3 + 1 ] > > 2 ) < < 4 ) +
( ( g_lab - > _anim - > _diffPalette [ i * 3 + 2 ] > > 2 ) ) ;
2014-10-06 14:50:05 +02:00
}
2015-12-02 00:34:51 +01:00
g_lab - > _anim - > _noPalChange = false ;
2014-10-06 14:50:05 +02:00
return res ;
}
2015-12-08 09:46:54 +01:00
/**
* Does the things to properly set up the detective notes .
*/
2015-12-06 16:03:34 +01:00
void LabEngine : : doNotes ( ) {
2015-12-01 02:05:29 +02:00
TextFont * noteFont = g_lab - > _resource - > getFont ( " P:Note.fon " ) ;
char * ntext = g_lab - > _resource - > getText ( " Lab:Rooms/Notes " ) ;
2014-10-06 14:50:05 +02:00
2015-12-07 17:46:37 +01:00
g_lab - > _graphics - > flowText ( noteFont , - 2 + g_lab - > _utils - > svgaCord ( 1 ) , 0 , 0 , false , false , true , true , g_lab - > _utils - > vgaScaleX ( 25 ) + g_lab - > _utils - > svgaCord ( 15 ) , g_lab - > _utils - > vgaScaleY ( 50 ) , g_lab - > _utils - > vgaScaleX ( 295 ) - g_lab - > _utils - > svgaCord ( 15 ) , g_lab - > _utils - > vgaScaleY ( 148 ) , ntext ) ;
2015-12-06 14:36:49 +01:00
g_lab - > _graphics - > setPalette ( g_lab - > _anim - > _diffPalette , 256 ) ;
2015-12-01 02:05:29 +02:00
2015-12-07 07:48:54 +01:00
g_lab - > _graphics - > closeFont ( noteFont ) ;
2015-12-01 02:05:29 +02:00
delete [ ] ntext ;
2014-10-06 14:50:05 +02:00
}
2015-12-08 09:46:54 +01:00
/**
* Does the things to properly set up the old west newspaper . Assumes that
* OpenHiRes already called .
*/
2015-12-06 16:03:34 +01:00
void LabEngine : : doWestPaper ( ) {
2014-10-06 14:50:05 +02:00
char * ntext ;
2015-12-01 02:05:29 +02:00
TextFont * paperFont ;
2014-10-06 14:50:05 +02:00
int32 FileLen , CharsPrinted ;
uint16 y = 268 ;
2015-12-01 02:05:29 +02:00
paperFont = g_lab - > _resource - > getFont ( " P:News22.fon " ) ;
ntext = g_lab - > _resource - > getText ( " Lab:Rooms/Date " ) ;
2015-12-07 17:46:37 +01:00
g_lab - > _graphics - > flowText ( paperFont , 0 , 0 , 0 , false , true , false , true , g_lab - > _utils - > vgaScaleX ( 57 ) , g_lab - > _utils - > vgaScaleY ( 77 ) + g_lab - > _utils - > svgaCord ( 2 ) , g_lab - > _utils - > vgaScaleX ( 262 ) , g_lab - > _utils - > vgaScaleY ( 91 ) , ntext ) ;
2015-12-07 07:48:54 +01:00
g_lab - > _graphics - > closeFont ( paperFont ) ;
2015-12-01 02:05:29 +02:00
delete [ ] ntext ;
2014-10-06 14:50:05 +02:00
2015-12-01 02:05:29 +02:00
paperFont = g_lab - > _resource - > getFont ( " P:News32.fon " ) ;
ntext = g_lab - > _resource - > getText ( " Lab:Rooms/Headline " ) ;
2014-10-06 14:50:05 +02:00
FileLen = strlen ( ntext ) - 1 ;
2015-12-07 17:46:37 +01:00
CharsPrinted = g_lab - > _graphics - > flowText ( paperFont , - 8 , 0 , 0 , false , true , false , true , g_lab - > _utils - > vgaScaleX ( 57 ) , g_lab - > _utils - > vgaScaleY ( 86 ) - g_lab - > _utils - > svgaCord ( 2 ) , g_lab - > _utils - > vgaScaleX ( 262 ) , g_lab - > _utils - > vgaScaleY ( 118 ) , ntext ) ;
2014-10-06 14:50:05 +02:00
if ( CharsPrinted < FileLen ) {
2015-12-07 17:46:37 +01:00
y = 130 - g_lab - > _utils - > svgaCord ( 5 ) ;
g_lab - > _graphics - > flowText ( paperFont , - 8 - g_lab - > _utils - > svgaCord ( 1 ) , 0 , 0 , false , true , false , true , g_lab - > _utils - > vgaScaleX ( 57 ) , g_lab - > _utils - > vgaScaleY ( 86 ) - g_lab - > _utils - > svgaCord ( 2 ) , g_lab - > _utils - > vgaScaleX ( 262 ) , g_lab - > _utils - > vgaScaleY ( 132 ) , ntext ) ;
2014-10-06 14:50:05 +02:00
} else
2015-12-07 17:46:37 +01:00
y = 115 - g_lab - > _utils - > svgaCord ( 5 ) ;
2015-12-07 07:48:54 +01:00
g_lab - > _graphics - > closeFont ( paperFont ) ;
2015-12-01 02:05:29 +02:00
delete [ ] ntext ;
paperFont = g_lab - > _resource - > getFont ( " P:Note.fon " ) ;
ntext = g_lab - > _resource - > getText ( " Lab:Rooms/Col1 " ) ;
2015-12-05 22:20:26 +02:00
CharsPrinted = g_lab - > _graphics - > flowTextScaled ( paperFont , - 4 , 0 , 0 , false , false , false , true , 45 , y , 158 , 148 , ntext ) ;
2015-12-01 02:05:29 +02:00
delete [ ] ntext ;
ntext = g_lab - > _resource - > getText ( " Lab:Rooms/Col2 " ) ;
2015-12-05 22:20:26 +02:00
CharsPrinted = g_lab - > _graphics - > flowTextScaled ( paperFont , - 4 , 0 , 0 , false , false , false , true , 162 , y , 275 , 148 , ntext ) ;
2015-12-01 02:05:29 +02:00
delete [ ] ntext ;
2015-12-07 07:48:54 +01:00
g_lab - > _graphics - > closeFont ( paperFont ) ;
2014-10-06 14:50:05 +02:00
2015-12-06 14:36:49 +01:00
g_lab - > _graphics - > setPalette ( g_lab - > _anim - > _diffPalette , 256 ) ;
2014-10-06 14:50:05 +02:00
}
2015-12-08 09:46:54 +01:00
/**
* Loads in the data for the journal .
*/
2015-12-08 16:53:30 +02:00
void LabEngine : : loadJournalData ( ) {
2014-10-06 14:50:05 +02:00
char filename [ 20 ] ;
bool bridge , dirty , news , clean ;
2015-12-08 17:34:12 +02:00
journalFont = g_lab - > _resource - > getFont ( " P:Journal.fon " ) ;
2014-10-06 14:50:05 +02:00
2015-11-30 01:17:05 +01:00
g_lab - > _music - > updateMusic ( ) ;
2014-10-06 14:50:05 +02:00
strcpy ( filename , " Lab:Rooms/j0 " ) ;
2014-12-25 19:13:52 +01:00
bridge = g_lab - > _conditions - > in ( BRIDGE0 ) | | g_lab - > _conditions - > in ( BRIDGE1 ) ;
dirty = g_lab - > _conditions - > in ( DIRTY ) ;
news = ! g_lab - > _conditions - > in ( NONEWS ) ;
clean = ! g_lab - > _conditions - > in ( NOCLEAN ) ;
2014-10-06 14:50:05 +02:00
if ( bridge & & clean & & news )
filename [ 11 ] = ' 8 ' ;
else if ( clean & & news )
filename [ 11 ] = ' 9 ' ;
else if ( bridge & & clean )
filename [ 11 ] = ' 6 ' ;
else if ( clean )
filename [ 11 ] = ' 7 ' ;
else if ( bridge & & dirty & & news )
filename [ 11 ] = ' 4 ' ;
else if ( dirty & & news )
filename [ 11 ] = ' 5 ' ;
else if ( bridge & & dirty )
filename [ 11 ] = ' 2 ' ;
else if ( dirty )
filename [ 11 ] = ' 3 ' ;
else if ( bridge )
filename [ 11 ] = ' 1 ' ;
2015-12-01 02:05:29 +02:00
journaltext = g_lab - > _resource - > getText ( filename ) ;
journaltexttitle = g_lab - > _resource - > getText ( " Lab:Rooms/jt " ) ;
2014-10-06 14:50:05 +02:00
2015-12-03 15:06:45 +02:00
Common : : File * journalFile = g_lab - > _resource - > openDataFile ( " P:JImage " ) ;
2015-12-08 16:53:30 +02:00
Utils * utils = g_lab - > _utils ;
_journalGadgetList . push_back ( createButton ( 80 , utils - > vgaScaleY ( 162 ) + utils - > svgaCord ( 1 ) , 0 , VKEY_LTARROW , new Image ( journalFile ) , new Image ( journalFile ) ) ) ; // back
_journalGadgetList . push_back ( createButton ( 144 , utils - > vgaScaleY ( 164 ) - utils - > svgaCord ( 1 ) , 1 , VKEY_RTARROW , new Image ( journalFile ) , new Image ( journalFile ) ) ) ; // foward
_journalGadgetList . push_back ( createButton ( 194 , utils - > vgaScaleY ( 162 ) + utils - > svgaCord ( 1 ) , 2 , 0 , new Image ( journalFile ) , new Image ( journalFile ) ) ) ; // cancel
2015-12-03 15:06:45 +02:00
delete journalFile ;
2014-10-06 14:50:05 +02:00
}
2015-12-08 09:46:54 +01:00
/**
* Draws the text to the back journal screen to the appropriate Page number
*/
2015-02-24 00:31:26 +02:00
static void drawJournalText ( ) {
2014-10-06 14:50:05 +02:00
uint16 DrawingToPage = 1 ;
int32 CharsDrawn = 0L ;
char * CurText = journaltext ;
while ( DrawingToPage < JPage ) {
2015-11-30 01:17:05 +01:00
g_lab - > _music - > updateMusic ( ) ;
2014-10-06 14:50:05 +02:00
CurText = ( char * ) ( journaltext + CharsDrawn ) ;
2015-12-05 22:20:26 +02:00
CharsDrawn + = g_lab - > _graphics - > flowTextScaled ( journalFont , - 2 , 2 , 0 , false , false , false , false , 52 , 32 , 152 , 148 , CurText ) ;
2014-10-06 14:50:05 +02:00
lastpage = ( * CurText = = 0 ) ;
if ( lastpage )
JPage = ( DrawingToPage / 2 ) * 2 ;
else
DrawingToPage + + ;
}
if ( JPage < = 1 ) {
CurText = journaltexttitle ;
2015-12-07 17:46:37 +01:00
g_lab - > _graphics - > flowTextToMem ( & JBackImage , journalFont , - 2 , 2 , 0 , false , true , true , true , g_lab - > _utils - > vgaScaleX ( 52 ) , g_lab - > _utils - > vgaScaleY ( 32 ) , g_lab - > _utils - > vgaScaleX ( 152 ) , g_lab - > _utils - > vgaScaleY ( 148 ) , CurText ) ;
2014-10-06 14:50:05 +02:00
} else {
CurText = ( char * ) ( journaltext + CharsDrawn ) ;
2015-12-07 17:46:37 +01:00
CharsDrawn + = g_lab - > _graphics - > flowTextToMem ( & JBackImage , journalFont , - 2 , 2 , 0 , false , false , false , true , g_lab - > _utils - > vgaScaleX ( 52 ) , g_lab - > _utils - > vgaScaleY ( 32 ) , g_lab - > _utils - > vgaScaleX ( 152 ) , g_lab - > _utils - > vgaScaleY ( 148 ) , CurText ) ;
2014-10-06 14:50:05 +02:00
}
2015-11-30 01:17:05 +01:00
g_lab - > _music - > updateMusic ( ) ;
2014-10-06 14:50:05 +02:00
CurText = ( char * ) ( journaltext + CharsDrawn ) ;
lastpage = ( * CurText = = 0 ) ;
2015-12-07 17:46:37 +01:00
g_lab - > _graphics - > flowTextToMem ( & JBackImage , journalFont , - 2 , 2 , 0 , false , false , false , true , g_lab - > _utils - > vgaScaleX ( 171 ) , g_lab - > _utils - > vgaScaleY ( 32 ) , g_lab - > _utils - > vgaScaleX ( 271 ) , g_lab - > _utils - > vgaScaleY ( 148 ) , CurText ) ;
2014-10-06 14:50:05 +02:00
CurText = ( char * ) ( journaltext + CharsDrawn ) ;
lastpage = lastpage | | ( * CurText = = 0 ) ;
}
2015-12-08 09:46:54 +01:00
/**
* Does the turn page wipe .
*/
2014-10-06 14:50:05 +02:00
static void turnPage ( bool FromLeft ) {
if ( FromLeft ) {
2015-12-06 14:36:49 +01:00
for ( int i = 0 ; i < g_lab - > _graphics - > _screenWidth ; i + = 8 ) {
2015-11-30 01:17:05 +01:00
g_lab - > _music - > updateMusic ( ) ;
2015-11-24 23:59:30 +01:00
g_lab - > waitTOF ( ) ;
2015-12-06 14:36:49 +01:00
ScreenImage . _imageData = g_lab - > _graphics - > getCurrentDrawingBuffer ( ) ;
JBackImage . blitBitmap ( i , 0 , & ScreenImage , i , 0 , 8 , g_lab - > _graphics - > _screenHeight , false ) ;
2014-10-06 14:50:05 +02:00
}
} else {
2015-12-06 14:36:49 +01:00
for ( int i = ( g_lab - > _graphics - > _screenWidth - 8 ) ; i > 0 ; i - = 8 ) {
2015-11-30 01:17:05 +01:00
g_lab - > _music - > updateMusic ( ) ;
2015-11-24 23:59:30 +01:00
g_lab - > waitTOF ( ) ;
2015-12-06 14:36:49 +01:00
ScreenImage . _imageData = g_lab - > _graphics - > getCurrentDrawingBuffer ( ) ;
JBackImage . blitBitmap ( i , 0 , & ScreenImage , i , 0 , 8 , g_lab - > _graphics - > _screenHeight , false ) ;
2014-10-06 14:50:05 +02:00
}
}
}
2015-12-08 09:46:54 +01:00
/**
* Draws the journal from page x .
*/
2015-11-29 18:10:06 +01:00
void LabEngine : : drawJournal ( uint16 wipenum , bool needFade ) {
_event - > mouseHide ( ) ;
2014-10-06 14:50:05 +02:00
2015-11-30 01:17:05 +01:00
_music - > updateMusic ( ) ;
2014-10-06 14:50:05 +02:00
if ( ! GotBackImage )
2015-12-02 11:49:01 +01:00
JBackImage . _imageData = loadBackPict ( " P:Journal.pic " , true ) ;
2014-10-06 14:50:05 +02:00
drawJournalText ( ) ;
2015-12-06 14:36:49 +01:00
ScreenImage . _imageData = _graphics - > getCurrentDrawingBuffer ( ) ;
2014-10-06 14:50:05 +02:00
if ( wipenum = = 0 )
2015-12-06 14:36:49 +01:00
JBackImage . blitBitmap ( 0 , 0 , & ScreenImage , 0 , 0 , _graphics - > _screenWidth , _graphics - > _screenHeight , false ) ;
2014-10-06 14:50:05 +02:00
else
turnPage ( ( bool ) ( wipenum = = 1 ) ) ;
2015-12-08 16:53:30 +02:00
Gadget * backGadget = _event - > getGadget ( 0 ) ;
Gadget * forwardGadget = _event - > getGadget ( 1 ) ;
2014-10-06 14:50:05 +02:00
if ( JPage = = 0 )
2015-12-08 16:53:30 +02:00
disableGadget ( backGadget , 15 ) ;
2014-10-06 14:50:05 +02:00
else
2015-12-08 16:53:30 +02:00
enableGadget ( backGadget ) ;
2014-10-06 14:50:05 +02:00
if ( lastpage )
2015-12-08 16:53:30 +02:00
disableGadget ( forwardGadget , 15 ) ;
2014-10-06 14:50:05 +02:00
else
2015-12-08 16:53:30 +02:00
enableGadget ( forwardGadget ) ;
2014-10-06 14:50:05 +02:00
if ( needFade )
2015-12-06 18:16:26 +01:00
_graphics - > fade ( true , 0 ) ;
2014-10-06 14:50:05 +02:00
2015-12-02 00:34:51 +01:00
g_lab - > _anim - > _noPalChange = true ;
2015-12-06 14:36:49 +01:00
JBackImage . _imageData = _graphics - > readPictToMem ( " P:Journal.pic " , _graphics - > _screenWidth , _graphics - > _screenHeight ) ;
2014-10-06 14:50:05 +02:00
GotBackImage = true ;
eatMessages ( ) ;
2015-11-29 18:10:06 +01:00
_event - > mouseShow ( ) ;
2014-10-06 14:50:05 +02:00
2015-12-02 00:34:51 +01:00
g_lab - > _anim - > _noPalChange = false ;
2014-10-06 14:50:05 +02:00
}
2015-12-08 09:46:54 +01:00
/**
* Processes user input .
*/
2015-11-29 18:10:06 +01:00
void LabEngine : : processJournal ( ) {
2014-12-26 00:32:42 +01:00
IntuiMessage * Msg ;
2014-10-06 14:50:05 +02:00
uint32 Class ;
uint16 Qualifier , GadID ;
while ( 1 ) {
2015-12-08 11:27:34 +01:00
// Make sure we check the music at least after every message
_music - > updateMusic ( ) ;
2015-11-29 18:10:06 +01:00
Msg = getMsg ( ) ;
2014-10-06 14:50:05 +02:00
if ( Msg = = NULL ) {
2015-11-30 01:17:05 +01:00
_music - > updateMusic ( ) ;
2014-10-06 14:50:05 +02:00
} else {
2015-12-07 07:18:16 +01:00
Class = Msg - > _msgClass ;
Qualifier = Msg - > _qualifier ;
GadID = Msg - > _code ;
2014-10-06 14:50:05 +02:00
if ( ( ( Class = = MOUSEBUTTONS ) & & ( IEQUALIFIER_RBUTTON & Qualifier ) ) | |
2015-12-08 09:19:00 +01:00
( ( Class = = RAWKEY ) & & ( GadID = = 27 ) ) )
2014-10-06 14:50:05 +02:00
return ;
else if ( Class = = GADGETUP ) {
if ( GadID = = 0 ) {
if ( JPage > = 2 ) {
JPage - = 2 ;
drawJournal ( 1 , false ) ;
}
} else if ( GadID = = 1 ) {
return ;
} else if ( GadID = = 2 ) {
if ( ! lastpage ) {
JPage + = 2 ;
drawJournal ( 2 , false ) ;
}
}
}
}
}
}
2015-12-08 09:46:54 +01:00
/**
* Does the journal processing .
*/
2015-11-29 18:10:06 +01:00
void LabEngine : : doJournal ( ) {
2015-12-04 13:32:08 +01:00
_graphics - > blackAllScreen ( ) ;
2014-10-06 14:50:05 +02:00
lastpage = false ;
GotBackImage = false ;
2015-12-06 14:36:49 +01:00
JBackImage . _width = _graphics - > _screenWidth ;
JBackImage . _height = _graphics - > _screenHeight ;
2015-12-08 09:19:00 +01:00
JBackImage . _imageData = NULL ;
2014-10-06 14:50:05 +02:00
ScreenImage = JBackImage ;
2015-12-06 14:36:49 +01:00
ScreenImage . _imageData = _graphics - > getCurrentDrawingBuffer ( ) ;
2014-10-06 14:50:05 +02:00
2015-11-30 01:17:05 +01:00
_music - > updateMusic ( ) ;
2014-12-25 19:13:52 +01:00
loadJournalData ( ) ;
2014-10-06 14:50:05 +02:00
drawJournal ( 0 , true ) ;
2015-12-08 16:53:30 +02:00
_event - > attachGadgetList ( & _journalGadgetList ) ;
2015-11-29 18:10:06 +01:00
_event - > mouseShow ( ) ;
2014-10-06 14:50:05 +02:00
processJournal ( ) ;
2015-11-29 18:10:06 +01:00
_event - > attachGadgetList ( NULL ) ;
2015-12-06 18:16:26 +01:00
_graphics - > fade ( false , 0 ) ;
2015-11-29 18:10:06 +01:00
_event - > mouseHide ( ) ;
2015-12-08 17:34:12 +02:00
2015-12-08 16:53:30 +02:00
freeButtonList ( & _journalGadgetList ) ;
2015-12-08 17:34:12 +02:00
g_lab - > _graphics - > closeFont ( journalFont ) ;
2014-10-06 14:50:05 +02:00
2015-12-06 14:36:49 +01:00
ScreenImage . _imageData = _graphics - > getCurrentDrawingBuffer ( ) ;
2014-10-06 14:50:05 +02:00
2015-12-04 13:32:08 +01:00
_graphics - > setAPen ( 0 ) ;
2015-12-06 14:36:49 +01:00
_graphics - > rectFill ( 0 , 0 , _graphics - > _screenWidth - 1 , _graphics - > _screenHeight - 1 ) ;
2015-12-04 13:32:08 +01:00
_graphics - > blackScreen ( ) ;
2014-10-06 14:50:05 +02:00
}
2015-12-03 19:49:55 +01:00
bool LabEngine : : saveRestoreGame ( ) {
2015-02-19 15:41:15 +02:00
bool isOK = false ;
2015-07-17 10:50:04 +03:00
//g_lab->showMainMenu();
2015-02-19 15:41:15 +02:00
// The original had one screen for saving/loading. We have two.
// Ask the user which screen to use.
GUI : : MessageDialog saveOrLoad ( _ ( " Would you like to save or restore a game? " ) , _ ( " Save " ) , _ ( " Restore " ) ) ;
int choice = saveOrLoad . runModal ( ) ;
if ( choice = = GUI : : kMessageOK ) {
// Save
GUI : : SaveLoadChooser * dialog = new GUI : : SaveLoadChooser ( _ ( " Save game: " ) , _ ( " Save " ) , true ) ;
int slot = dialog - > runModalWithCurrentTarget ( ) ;
if ( slot > = 0 ) {
Common : : String desc = dialog - > getResultString ( ) ;
if ( desc . empty ( ) ) {
// create our own description for the saved game, the user didn't enter it
desc = dialog - > createDefaultSaveDescription ( slot ) ;
2014-10-06 14:50:05 +02:00
}
2015-12-06 21:53:57 +01:00
isOK = saveGame ( _direction , _inventory [ QUARTERNUM ] . _many , slot , desc ) ;
2014-10-06 14:50:05 +02:00
}
} else {
2015-02-19 15:41:15 +02:00
// Restore
GUI : : SaveLoadChooser * dialog = new GUI : : SaveLoadChooser ( _ ( " Restore game: " ) , _ ( " Restore " ) , false ) ;
int slot = dialog - > runModalWithCurrentTarget ( ) ;
2015-02-19 19:03:45 +02:00
if ( slot > = 0 ) {
2015-12-06 21:53:57 +01:00
isOK = loadGame ( & _direction , & ( _inventory [ QUARTERNUM ] . _many ) , slot ) ;
2015-02-19 19:03:45 +02:00
if ( isOK )
2015-12-04 13:32:08 +01:00
_music - > resetMusic ( ) ;
2015-02-19 19:03:45 +02:00
}
2014-10-06 14:50:05 +02:00
}
2015-12-08 17:14:27 +02:00
_alternate = false ;
_mainDisplay = true ;
2015-12-04 13:32:08 +01:00
_graphics - > screenUpdate ( ) ;
2015-11-20 19:45:07 +01:00
2015-02-19 19:03:45 +02:00
return isOK ;
2014-10-06 14:50:05 +02:00
}
2015-12-08 09:46:54 +01:00
/**
* Draws the text for the monitor .
*/
2015-12-01 02:05:29 +02:00
void LabEngine : : drawMonText ( char * text , TextFont * monitorFont , uint16 x1 , uint16 y1 , uint16 x2 , uint16 y2 , bool isinteractive ) {
2015-11-27 23:18:15 +01:00
uint16 DrawingToPage = 0 , yspacing = 0 , numlines , fheight ;
2014-10-06 14:50:05 +02:00
int32 CharsDrawn = 0L ;
char * CurText = text ;
2015-11-29 18:10:06 +01:00
_event - > mouseHide ( ) ;
2014-10-06 14:50:05 +02:00
if ( * text = = ' % ' ) {
text + + ;
numlines = ( * text - ' 0 ' ) * 10 ;
text + + ;
numlines + = ( * text - ' 0 ' ) ;
text + = 2 ;
2015-12-07 07:48:54 +01:00
fheight = g_lab - > _graphics - > textHeight ( monitorFont ) ;
2015-12-07 17:46:37 +01:00
x1 = MonButton - > _width + _utils - > vgaScaleX ( 3 ) ;
MonGadHeight = MonButton - > _height + _utils - > vgaScaleY ( 3 ) ;
2014-10-06 14:50:05 +02:00
if ( MonGadHeight > fheight )
yspacing = MonGadHeight - fheight ;
else
MonGadHeight = fheight ;
2015-12-04 13:32:08 +01:00
_graphics - > setAPen ( 0 ) ;
2015-12-06 14:36:49 +01:00
_graphics - > rectFill ( 0 , 0 , _graphics - > _screenWidth - 1 , y2 ) ;
2014-10-06 14:50:05 +02:00
2015-11-27 23:18:15 +01:00
for ( uint16 i = 0 ; i < numlines ; i + + )
2015-12-01 21:42:44 +01:00
MonButton - > drawImage ( 0 , i * MonGadHeight ) ;
2014-10-06 14:50:05 +02:00
} else if ( isinteractive ) {
2015-12-04 13:32:08 +01:00
_graphics - > setAPen ( 0 ) ;
2015-12-06 14:36:49 +01:00
_graphics - > rectFill ( 0 , 0 , _graphics - > _screenWidth - 1 , y2 ) ;
2014-10-06 14:50:05 +02:00
} else {
2015-12-04 13:32:08 +01:00
_graphics - > setAPen ( 0 ) ;
_graphics - > rectFill ( x1 , y1 , x2 , y2 ) ;
2014-10-06 14:50:05 +02:00
}
2015-10-16 01:52:53 +03:00
while ( DrawingToPage < monitorPage ) {
2015-11-30 01:17:05 +01:00
_music - > updateMusic ( ) ;
2014-10-06 14:50:05 +02:00
CurText = ( char * ) ( text + CharsDrawn ) ;
2015-12-04 13:32:08 +01:00
CharsDrawn + = _graphics - > flowText ( monitorFont , yspacing , 0 , 0 , false , false , false , false , x1 , y1 , x2 , y2 , CurText ) ;
2014-10-06 14:50:05 +02:00
lastpage = ( * CurText = = 0 ) ;
if ( lastpage )
2015-10-16 01:52:53 +03:00
monitorPage = DrawingToPage ;
2014-10-06 14:50:05 +02:00
else
DrawingToPage + + ;
}
CurText = ( char * ) ( text + CharsDrawn ) ;
lastpage = ( * CurText = = 0 ) ;
2015-12-04 13:32:08 +01:00
CharsDrawn = _graphics - > flowText ( monitorFont , yspacing , 2 , 0 , false , false , false , true , x1 , y1 , x2 , y2 , CurText ) ;
2014-10-06 14:50:05 +02:00
CurText + = CharsDrawn ;
lastpage = lastpage | | ( * CurText = = 0 ) ;
2015-11-29 18:10:06 +01:00
_event - > mouseShow ( ) ;
2014-10-06 14:50:05 +02:00
}
2015-12-08 09:46:54 +01:00
/**
* Processes user input .
*/
2015-12-01 02:05:29 +02:00
void LabEngine : : processMonitor ( char * ntext , TextFont * monitorFont , bool isinteractive , uint16 x1 , uint16 y1 , uint16 x2 , uint16 y2 ) {
2014-12-26 00:32:42 +01:00
IntuiMessage * Msg ;
2014-10-06 14:50:05 +02:00
uint32 Class ;
uint16 Qualifier , Code , MouseX , MouseY ;
const char * Test = " " , * StartFileName = TextFileName ;
2015-12-03 11:10:58 +01:00
CloseDataPtr startcptr = _cptr , testcptr , lastcptr [ 10 ] ;
2014-10-06 14:50:05 +02:00
uint16 depth = 0 ;
2015-12-03 11:10:58 +01:00
lastcptr [ 0 ] = _cptr ;
2014-10-06 14:50:05 +02:00
while ( 1 ) {
if ( isinteractive ) {
2015-12-03 11:10:58 +01:00
if ( _cptr = = NULL )
_cptr = startcptr ;
2014-10-06 14:50:05 +02:00
2015-12-03 11:10:58 +01:00
if ( _cptr = = startcptr )
2014-10-06 14:50:05 +02:00
Test = StartFileName ;
else
2015-12-06 21:53:57 +01:00
Test = _cptr - > _graphicName ;
2014-10-06 14:50:05 +02:00
if ( strcmp ( Test , TextFileName ) ) {
2015-10-16 01:52:53 +03:00
monitorPage = 0 ;
2014-10-06 14:50:05 +02:00
TextFileName = Test ;
2015-12-01 02:05:29 +02:00
ntext = g_lab - > _resource - > getText ( TextFileName ) ;
2015-12-06 18:16:26 +01:00
_graphics - > fade ( false , 0 ) ;
2015-12-01 02:05:29 +02:00
drawMonText ( ntext , monitorFont , x1 , y1 , x2 , y2 , isinteractive ) ;
2015-12-06 18:16:26 +01:00
_graphics - > fade ( true , 0 ) ;
2015-12-01 02:05:29 +02:00
delete [ ] ntext ;
2014-10-06 14:50:05 +02:00
}
}
2015-12-08 11:27:34 +01:00
// Make sure we check the music at least after every message
_music - > updateMusic ( ) ;
2014-10-06 14:50:05 +02:00
Msg = getMsg ( ) ;
if ( Msg = = NULL ) {
2015-11-30 01:17:05 +01:00
_music - > updateMusic ( ) ;
2014-10-06 14:50:05 +02:00
} else {
2015-12-07 07:18:16 +01:00
Class = Msg - > _msgClass ;
Qualifier = Msg - > _qualifier ;
MouseX = Msg - > _mouseX ;
MouseY = Msg - > _mouseY ;
Code = Msg - > _code ;
2014-10-06 14:50:05 +02:00
if ( ( ( Class = = MOUSEBUTTONS ) & & ( IEQUALIFIER_RBUTTON & Qualifier ) ) | |
2015-12-08 09:19:00 +01:00
( ( Class = = RAWKEY ) & & ( Code = = 27 ) ) )
2014-10-06 14:50:05 +02:00
return ;
else if ( ( Class = = MOUSEBUTTONS ) & & ( IEQUALIFIER_LEFTBUTTON & Qualifier ) ) {
2015-12-07 17:46:37 +01:00
if ( ( MouseY > = g_lab - > _utils - > vgaScaleY ( 171 ) ) & & ( MouseY < = g_lab - > _utils - > vgaScaleY ( 200 ) ) ) {
if ( ( MouseX > = g_lab - > _utils - > vgaScaleX ( 259 ) ) & & ( MouseX < = g_lab - > _utils - > vgaScaleX ( 289 ) ) ) {
2014-10-06 14:50:05 +02:00
if ( ! lastpage ) {
2015-10-16 01:52:53 +03:00
monitorPage + = 1 ;
2015-12-01 02:05:29 +02:00
drawMonText ( ntext , monitorFont , x1 , y1 , x2 , y2 , isinteractive ) ;
2014-10-06 14:50:05 +02:00
}
2015-12-07 17:46:37 +01:00
} else if ( ( MouseX > = g_lab - > _utils - > vgaScaleX ( 0 ) ) & & ( MouseX < = g_lab - > _utils - > vgaScaleX ( 31 ) ) ) {
2014-10-06 14:50:05 +02:00
return ;
2015-12-07 17:46:37 +01:00
} else if ( ( MouseX > = g_lab - > _utils - > vgaScaleX ( 290 ) ) & & ( MouseX < = g_lab - > _utils - > vgaScaleX ( 320 ) ) ) {
2015-10-16 01:52:53 +03:00
if ( monitorPage > = 1 ) {
monitorPage - = 1 ;
2015-12-01 02:05:29 +02:00
drawMonText ( ntext , monitorFont , x1 , y1 , x2 , y2 , isinteractive ) ;
2014-10-06 14:50:05 +02:00
}
2015-12-07 17:46:37 +01:00
} else if ( ( MouseX > = g_lab - > _utils - > vgaScaleX ( 31 ) ) & & ( MouseX < = g_lab - > _utils - > vgaScaleX ( 59 ) ) ) {
2014-10-06 14:50:05 +02:00
if ( isinteractive ) {
2015-10-16 01:52:53 +03:00
monitorPage = 0 ;
2014-10-06 14:50:05 +02:00
if ( depth ) {
depth - - ;
2015-12-03 11:10:58 +01:00
_cptr = lastcptr [ depth ] ;
2014-10-06 14:50:05 +02:00
}
2015-10-16 01:52:53 +03:00
} else if ( monitorPage > 0 ) {
monitorPage = 0 ;
2015-12-01 02:05:29 +02:00
drawMonText ( ntext , monitorFont , x1 , y1 , x2 , y2 , isinteractive ) ;
2014-10-06 14:50:05 +02:00
}
}
} else if ( isinteractive ) {
2015-12-03 11:10:58 +01:00
testcptr = _cptr ;
2014-10-06 14:50:05 +02:00
MouseY = 64 + ( MouseY / MonGadHeight ) * 42 ;
MouseX = 101 ;
2015-12-08 18:24:44 +02:00
setCurClose ( Common : : Point ( MouseX , MouseY ) , & _cptr , false ) ;
2014-10-06 14:50:05 +02:00
2015-12-03 11:10:58 +01:00
if ( testcptr ! = _cptr ) {
2015-12-03 11:02:58 +01:00
lastcptr [ depth ] = testcptr ;
2014-10-06 14:50:05 +02:00
depth + + ;
}
}
}
}
}
}
2015-12-08 09:46:54 +01:00
/**
* Does what ' s necessary for the monitor .
*/
2015-11-29 18:10:06 +01:00
void LabEngine : : doMonitor ( char * background , char * textfile , bool isinteractive , uint16 x1 , uint16 y1 , uint16 x2 , uint16 y2 ) {
2014-10-06 14:50:05 +02:00
char * ntext ;
2015-12-07 17:46:37 +01:00
x1 = _utils - > vgaScaleX ( x1 ) ;
x2 = _utils - > vgaScaleX ( x2 ) ;
y1 = _utils - > vgaScaleY ( y1 ) ;
y2 = _utils - > vgaScaleY ( y2 ) ;
2014-10-06 14:50:05 +02:00
TextFileName = textfile ;
2015-12-04 13:32:08 +01:00
_graphics - > blackAllScreen ( ) ;
_graphics - > readPict ( " P:Mon/Monitor.1 " , true ) ;
_graphics - > readPict ( " P:Mon/NWD1 " , true ) ;
_graphics - > readPict ( " P:Mon/NWD2 " , true ) ;
_graphics - > readPict ( " P:Mon/NWD3 " , true ) ;
_graphics - > blackAllScreen ( ) ;
2014-10-06 14:50:05 +02:00
2015-10-16 01:52:53 +03:00
monitorPage = 0 ;
2014-10-06 14:50:05 +02:00
lastpage = false ;
2015-12-06 18:16:26 +01:00
_graphics - > FadePalette = hipal ;
2014-10-06 14:50:05 +02:00
2015-12-01 02:05:29 +02:00
TextFont * monitorFont = _resource - > getFont ( " P:Map.fon " ) ;
2015-12-05 18:14:50 +02:00
Common : : File * buttonFile = g_lab - > _resource - > openDataFile ( " P:MonImage " ) ;
MonButton = new Image ( buttonFile ) ;
delete buttonFile ;
2014-10-06 14:50:05 +02:00
2015-12-01 02:05:29 +02:00
ntext = _resource - > getText ( textfile ) ;
2014-10-06 14:50:05 +02:00
loadBackPict ( background , false ) ;
2015-12-01 02:05:29 +02:00
drawMonText ( ntext , monitorFont , x1 , y1 , x2 , y2 , isinteractive ) ;
2015-11-29 18:10:06 +01:00
_event - > mouseShow ( ) ;
2015-12-06 18:16:26 +01:00
_graphics - > fade ( true , 0 ) ;
2015-12-01 02:05:29 +02:00
processMonitor ( ntext , monitorFont , isinteractive , x1 , y1 , x2 , y2 ) ;
2015-12-06 18:16:26 +01:00
_graphics - > fade ( false , 0 ) ;
2015-11-29 18:10:06 +01:00
_event - > mouseHide ( ) ;
2015-12-01 02:05:29 +02:00
delete [ ] ntext ;
2015-12-07 07:48:54 +01:00
g_lab - > _graphics - > closeFont ( monitorFont ) ;
2014-10-06 14:50:05 +02:00
2015-12-04 13:32:08 +01:00
_graphics - > setAPen ( 0 ) ;
2015-12-06 14:36:49 +01:00
_graphics - > rectFill ( 0 , 0 , _graphics - > _screenWidth - 1 , _graphics - > _screenHeight - 1 ) ;
2015-12-04 13:32:08 +01:00
_graphics - > blackAllScreen ( ) ;
2015-12-04 21:18:41 +02:00
_graphics - > freePict ( ) ;
2014-10-06 14:50:05 +02:00
}
} // End of namespace Lab