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 .
*
*/
2014-12-25 19:13:52 +01:00
# include "lab/lab.h"
2015-12-08 21:10:54 +01:00
2015-12-08 21:35:31 +01:00
# include "lab/anim.h"
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:00:50 +01:00
# include "lab/labsets.h"
2015-12-08 20:36:05 +01:00
# include "lab/music.h"
2015-12-08 21:47:36 +01:00
# include "lab/processroom.h"
2015-12-08 21:10:54 +01:00
# include "lab/resource.h"
2015-12-08 21:00:50 +01:00
# include "lab/utils.h"
2014-10-06 14:50:05 +02:00
namespace Lab {
2015-12-08 09:19:00 +01:00
# define BRIDGE0 148
# define BRIDGE1 104
# define DIRTY 175
# define NONEWS 135
# define NOCLEAN 152
2014-12-22 10:03:05 +01:00
2015-12-06 16:03:34 +01:00
void LabEngine : : doNotes ( ) {
2015-12-18 05:42:26 +02:00
TextFont * noteFont = _resource - > getFont ( " F:Note.fon " ) ;
2015-12-19 02:12:42 +02:00
Common : : String noteText = _resource - > getText ( " Lab:Rooms/Notes " ) ;
2014-10-06 14:50:05 +02:00
2015-12-17 18:35:53 +01:00
Common : : Rect textRect = Common : : Rect ( _utils - > vgaScaleX ( 25 ) + _utils - > svgaCord ( 15 ) , _utils - > vgaScaleY ( 50 ) , _utils - > vgaScaleX ( 295 ) - _utils - > svgaCord ( 15 ) , _utils - > vgaScaleY ( 148 ) ) ;
2015-12-19 02:12:42 +02:00
_graphics - > flowText ( noteFont , - 2 + _utils - > svgaCord ( 1 ) , 0 , 0 , false , false , true , true , textRect , noteText . c_str ( ) ) ;
2015-12-10 07:04:59 +01:00
_graphics - > setPalette ( _anim - > _diffPalette , 256 ) ;
2015-12-19 13:08:54 +01:00
_graphics - > closeFont ( & noteFont ) ;
2014-10-06 14:50:05 +02:00
}
2015-12-06 16:03:34 +01:00
void LabEngine : : doWestPaper ( ) {
2015-12-18 05:42:26 +02:00
TextFont * paperFont = _resource - > getFont ( " F:News22.fon " ) ;
2015-12-19 02:12:42 +02:00
Common : : String paperText = _resource - > getText ( " Lab:Rooms/Date " ) ;
2015-12-17 18:35:53 +01:00
Common : : Rect textRect = Common : : Rect ( _utils - > vgaScaleX ( 57 ) , _utils - > vgaScaleY ( 77 ) + _utils - > svgaCord ( 2 ) , _utils - > vgaScaleX ( 262 ) , _utils - > vgaScaleY ( 91 ) ) ;
2015-12-19 02:12:42 +02:00
_graphics - > flowText ( paperFont , 0 , 0 , 0 , false , true , false , true , textRect , paperText . c_str ( ) ) ;
2015-12-19 13:08:54 +01:00
_graphics - > closeFont ( & paperFont ) ;
2014-10-06 14:50:05 +02:00
2015-12-18 05:42:26 +02:00
paperFont = _resource - > getFont ( " F:News32.fon " ) ;
2015-12-14 21:44:06 +01:00
paperText = _resource - > getText ( " Lab:Rooms/Headline " ) ;
2015-12-10 10:51:02 +01:00
2015-12-19 02:12:42 +02:00
int fileLen = paperText . size ( ) - 1 ;
2015-12-17 18:35:53 +01:00
textRect = Common : : Rect ( _utils - > vgaScaleX ( 57 ) , _utils - > vgaScaleY ( 86 ) - _utils - > svgaCord ( 2 ) , _utils - > vgaScaleX ( 262 ) , _utils - > vgaScaleY ( 118 ) ) ;
2015-12-19 02:12:42 +02:00
int charsPrinted = _graphics - > flowText ( paperFont , - 8 , 0 , 0 , false , true , false , true , textRect , paperText . c_str ( ) ) ;
2015-12-10 10:51:02 +01:00
uint16 y ;
if ( charsPrinted < fileLen ) {
2015-12-10 07:04:59 +01:00
y = 130 - _utils - > svgaCord ( 5 ) ;
2015-12-17 18:35:53 +01:00
textRect = Common : : Rect ( _utils - > vgaScaleX ( 57 ) , _utils - > vgaScaleY ( 86 ) - _utils - > svgaCord ( 2 ) , _utils - > vgaScaleX ( 262 ) , _utils - > vgaScaleY ( 132 ) ) ;
2015-12-19 02:12:42 +02:00
_graphics - > flowText ( paperFont , - 8 - _utils - > svgaCord ( 1 ) , 0 , 0 , false , true , false , true , textRect , paperText . c_str ( ) ) ;
2014-10-06 14:50:05 +02:00
} else
2015-12-10 07:04:59 +01:00
y = 115 - _utils - > svgaCord ( 5 ) ;
2015-12-10 10:51:02 +01:00
2015-12-19 13:08:54 +01:00
_graphics - > closeFont ( & paperFont ) ;
2015-12-01 02:05:29 +02:00
2015-12-18 05:42:26 +02:00
paperFont = _resource - > getFont ( " F:Note.fon " ) ;
2015-12-14 21:44:06 +01:00
paperText = _resource - > getText ( " Lab:Rooms/Col1 " ) ;
2015-12-22 00:43:53 +01:00
_graphics - > flowText ( paperFont , - 4 , 0 , 0 , false , false , false , true , _utils - > vgaRectScale ( 45 , y , 158 , 148 ) , paperText . c_str ( ) ) ;
2015-12-22 01:37:41 +01:00
2015-12-14 21:44:06 +01:00
paperText = _resource - > getText ( " Lab:Rooms/Col2 " ) ;
2015-12-22 00:43:53 +01:00
_graphics - > flowText ( paperFont , - 4 , 0 , 0 , false , false , false , true , _utils - > vgaRectScale ( 162 , y , 275 , 148 ) , paperText . c_str ( ) ) ;
2014-10-06 14:50:05 +02:00
2015-12-22 01:37:41 +01:00
_graphics - > closeFont ( & paperFont ) ;
2015-12-10 07:04:59 +01:00
_graphics - > setPalette ( _anim - > _diffPalette , 256 ) ;
2014-10-06 14:50:05 +02:00
}
2015-12-08 16:53:30 +02:00
void LabEngine : : loadJournalData ( ) {
2015-12-19 13:08:54 +01:00
if ( _journalFont )
_graphics - > closeFont ( & _journalFont ) ;
2015-12-18 05:42:26 +02:00
_journalFont = _resource - > getFont ( " F:Journal.fon " ) ;
2015-12-22 19:40:34 +01:00
updateMusicAndEvents ( ) ;
2014-10-06 14:50:05 +02:00
2015-12-19 14:14:11 +01:00
Common : : String filename = " Lab:Rooms/j0 " ;
2015-12-10 10:51:02 +01:00
bool bridge = _conditions - > in ( BRIDGE0 ) | | _conditions - > in ( BRIDGE1 ) ;
bool dirty = _conditions - > in ( DIRTY ) ;
bool news = ! _conditions - > in ( NONEWS ) ;
bool clean = ! _conditions - > in ( NOCLEAN ) ;
2014-10-06 14:50:05 +02:00
if ( bridge & & clean & & news )
2015-12-19 14:14:11 +01:00
filename + = ' 8 ' ;
2014-10-06 14:50:05 +02:00
else if ( clean & & news )
2015-12-19 14:14:11 +01:00
filename + = ' 9 ' ;
2014-10-06 14:50:05 +02:00
else if ( bridge & & clean )
2015-12-19 14:14:11 +01:00
filename + = ' 6 ' ;
2014-10-06 14:50:05 +02:00
else if ( clean )
2015-12-19 14:14:11 +01:00
filename + = ' 7 ' ;
2014-10-06 14:50:05 +02:00
else if ( bridge & & dirty & & news )
2015-12-19 14:14:11 +01:00
filename + = ' 4 ' ;
2014-10-06 14:50:05 +02:00
else if ( dirty & & news )
2015-12-19 14:14:11 +01:00
filename + = ' 5 ' ;
2014-10-06 14:50:05 +02:00
else if ( bridge & & dirty )
2015-12-19 14:14:11 +01:00
filename + = ' 2 ' ;
2014-10-06 14:50:05 +02:00
else if ( dirty )
2015-12-19 14:14:11 +01:00
filename + = ' 3 ' ;
2014-10-06 14:50:05 +02:00
else if ( bridge )
2015-12-19 14:14:11 +01:00
filename + = ' 1 ' ;
2014-10-06 14:50:05 +02:00
2015-12-20 16:02:35 +01:00
_journalText = _resource - > getText ( filename ) ;
2015-12-13 11:55:49 +01:00
_journalTextTitle = _resource - > getText ( " Lab:Rooms/jt " ) ;
2014-10-06 14:50:05 +02:00
2015-12-10 07:04:59 +01:00
Common : : File * journalFile = _resource - > openDataFile ( " P:JImage " ) ;
2015-12-22 01:37:41 +01:00
_journalButtonList . push_back ( _event - > createButton ( 80 , _utils - > vgaScaleY ( 162 ) + _utils - > svgaCord ( 1 ) , 0 , VKEY_LTARROW , new Image ( journalFile , this ) , new Image ( journalFile , this ) ) ) ; // back
_journalButtonList . push_back ( _event - > createButton ( 194 , _utils - > vgaScaleY ( 162 ) + _utils - > svgaCord ( 1 ) , 2 , 0 , new Image ( journalFile , this ) , new Image ( journalFile , this ) ) ) ; // cancel
_journalButtonList . push_back ( _event - > createButton ( 144 , _utils - > vgaScaleY ( 164 ) - _utils - > svgaCord ( 1 ) , 1 , VKEY_RTARROW , new Image ( journalFile , this ) , new Image ( journalFile , this ) ) ) ; // forward
2015-12-03 15:06:45 +02:00
delete journalFile ;
2015-12-10 12:45:21 +02:00
_anim - > _noPalChange = true ;
2015-12-13 22:55:10 +01:00
_journalBackImage - > _imageData = new byte [ _graphics - > _screenWidth * _graphics - > _screenHeight ] ;
_graphics - > readPict ( " P:Journal.pic " , true , false , _journalBackImage - > _imageData ) ;
2015-12-10 12:45:21 +02:00
_anim - > _noPalChange = false ;
// Keep a copy of the blank journal
_blankJournal = new byte [ _graphics - > _screenWidth * _graphics - > _screenHeight ] ;
2015-12-13 22:55:10 +01:00
memcpy ( _blankJournal , _journalBackImage - > _imageData , _graphics - > _screenWidth * _graphics - > _screenHeight ) ;
2015-12-10 12:45:21 +02:00
2015-12-13 22:55:10 +01:00
_screenImage - > _imageData = _graphics - > getCurrentDrawingBuffer ( ) ;
2014-10-06 14:50:05 +02:00
}
2015-12-13 11:55:49 +01:00
void LabEngine : : drawJournalText ( ) {
2015-12-10 10:51:02 +01:00
uint16 drawingToPage = 1 ;
2015-12-14 21:44:06 +01:00
int charsDrawn = 0 ;
2015-12-19 02:12:42 +02:00
const char * curText = _journalText . c_str ( ) ;
2014-10-06 14:50:05 +02:00
2015-12-13 11:55:49 +01:00
while ( drawingToPage < _journalPage ) {
2015-12-22 19:40:34 +01:00
updateMusicAndEvents ( ) ;
2015-12-22 01:37:41 +01:00
curText = _journalText . c_str ( ) + charsDrawn ;
2015-12-17 18:46:46 +01:00
charsDrawn + = _graphics - > flowText ( _journalFont , - 2 , 2 , 0 , false , false , false , false , _utils - > vgaRectScale ( 52 , 32 , 152 , 148 ) , curText ) ;
2014-10-06 14:50:05 +02:00
2015-12-13 11:55:49 +01:00
_lastPage = ( * curText = = 0 ) ;
2014-10-06 14:50:05 +02:00
2015-12-13 11:55:49 +01:00
if ( _lastPage )
_journalPage = ( drawingToPage / 2 ) * 2 ;
2014-10-06 14:50:05 +02:00
else
2015-12-10 10:51:02 +01:00
drawingToPage + + ;
2014-10-06 14:50:05 +02:00
}
2015-12-13 11:55:49 +01:00
if ( _journalPage < = 1 ) {
2015-12-19 02:12:42 +02:00
curText = _journalTextTitle . c_str ( ) ;
2015-12-17 18:35:53 +01:00
_graphics - > flowTextToMem ( _journalBackImage , _journalFont , - 2 , 2 , 0 , false , true , true , true , _utils - > vgaRectScale ( 52 , 32 , 152 , 148 ) , curText ) ;
2014-10-06 14:50:05 +02:00
} else {
2015-12-22 01:37:41 +01:00
curText = _journalText . c_str ( ) + charsDrawn ;
2015-12-17 18:35:53 +01:00
charsDrawn + = _graphics - > flowTextToMem ( _journalBackImage , _journalFont , - 2 , 2 , 0 , false , false , false , true , _utils - > vgaRectScale ( 52 , 32 , 152 , 148 ) , curText ) ;
2014-10-06 14:50:05 +02:00
}
2015-12-22 19:40:34 +01:00
updateMusicAndEvents ( ) ;
2015-12-22 01:37:41 +01:00
curText = _journalText . c_str ( ) + charsDrawn ;
2015-12-13 11:55:49 +01:00
_lastPage = ( * curText = = 0 ) ;
2015-12-17 18:35:53 +01:00
_graphics - > flowTextToMem ( _journalBackImage , _journalFont , - 2 , 2 , 0 , false , false , false , true , _utils - > vgaRectScale ( 171 , 32 , 271 , 148 ) , curText ) ;
2014-10-06 14:50:05 +02:00
}
2015-12-13 11:55:49 +01:00
void LabEngine : : turnPage ( bool fromLeft ) {
2015-12-10 10:51:02 +01:00
if ( fromLeft ) {
2015-12-13 11:55:49 +01:00
for ( int i = 0 ; i < _graphics - > _screenWidth ; i + = 8 ) {
2015-12-22 19:40:34 +01:00
updateMusicAndEvents ( ) ;
2015-12-13 11:55:49 +01:00
waitTOF ( ) ;
2015-12-13 22:55:10 +01:00
_screenImage - > _imageData = _graphics - > getCurrentDrawingBuffer ( ) ;
_journalBackImage - > blitBitmap ( i , 0 , _screenImage , i , 0 , 8 , _graphics - > _screenHeight , false ) ;
2014-10-06 14:50:05 +02:00
}
} else {
2015-12-13 11:55:49 +01:00
for ( int i = ( _graphics - > _screenWidth - 8 ) ; i > 0 ; i - = 8 ) {
2015-12-22 19:40:34 +01:00
updateMusicAndEvents ( ) ;
2015-12-13 11:55:49 +01:00
waitTOF ( ) ;
2015-12-13 22:55:10 +01:00
_screenImage - > _imageData = _graphics - > getCurrentDrawingBuffer ( ) ;
_journalBackImage - > blitBitmap ( i , 0 , _screenImage , i , 0 , 8 , _graphics - > _screenHeight , false ) ;
2014-10-06 14:50:05 +02:00
}
}
}
2015-11-29 18:10:06 +01:00
void LabEngine : : drawJournal ( uint16 wipenum , bool needFade ) {
_event - > mouseHide ( ) ;
2015-12-22 19:40:34 +01:00
updateMusicAndEvents ( ) ;
2014-10-06 14:50:05 +02:00
drawJournalText ( ) ;
2015-12-13 11:55:49 +01:00
_graphics - > loadBackPict ( " P:Journal.pic " , _highPalette ) ;
2014-10-06 14:50:05 +02:00
if ( wipenum = = 0 )
2015-12-13 22:55:10 +01:00
_journalBackImage - > blitBitmap ( 0 , 0 , _screenImage , 0 , 0 , _graphics - > _screenWidth , _graphics - > _screenHeight , false ) ;
2014-10-06 14:50:05 +02:00
else
2015-12-14 14:20:22 +01:00
turnPage ( ( wipenum = = 1 ) ) ;
2014-10-06 14:50:05 +02:00
2015-12-18 03:31:07 +02:00
_event - > toggleButton ( _event - > getButton ( 0 ) , 15 , ( _journalPage > 0 ) ) ; // back button
_event - > toggleButton ( _event - > getButton ( 2 ) , 15 , ( ! _lastPage ) ) ; // forward button
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-10 12:45:21 +02:00
// Reset the journal background, so that all the text that has been blitted on it is erased
2015-12-13 22:55:10 +01:00
memcpy ( _journalBackImage - > _imageData , _blankJournal , _graphics - > _screenWidth * _graphics - > _screenHeight ) ;
2014-10-06 14:50:05 +02:00
eatMessages ( ) ;
2015-11-29 18:10:06 +01:00
_event - > mouseShow ( ) ;
2014-10-06 14:50:05 +02:00
}
2015-11-29 18:10:06 +01:00
void LabEngine : : processJournal ( ) {
2014-10-06 14:50:05 +02:00
while ( 1 ) {
2015-12-08 11:27:34 +01:00
// Make sure we check the music at least after every message
2015-12-22 19:40:34 +01:00
updateMusicAndEvents ( ) ;
2015-12-13 15:37:39 +02:00
IntuiMessage * msg = _event - > getMsg ( ) ;
2015-12-16 00:07:31 +01:00
if ( g_engine - > shouldQuit ( ) ) {
_quitLab = true ;
return ;
}
2014-10-06 14:50:05 +02:00
2015-12-16 00:07:31 +01:00
if ( ! msg )
2015-12-22 19:40:34 +01:00
updateMusicAndEvents ( ) ;
2015-12-16 00:07:31 +01:00
else {
2015-12-10 10:51:02 +01:00
uint32 msgClass = msg - > _msgClass ;
2015-12-16 23:27:32 +02:00
uint16 buttonId = msg - > _code ;
2014-10-06 14:50:05 +02:00
2015-12-18 00:41:24 +02:00
if ( ( msgClass = = kMessageRightClick ) | |
( ( msgClass = = kMessageRawKey ) & & ( buttonId = = Common : : KEYCODE_ESCAPE ) ) )
2014-10-06 14:50:05 +02:00
return ;
2015-12-18 00:41:24 +02:00
else if ( msgClass = = kMessageButtonUp ) {
2015-12-16 23:27:32 +02:00
if ( buttonId = = 0 ) {
2015-12-13 11:55:49 +01:00
if ( _journalPage > = 2 ) {
_journalPage - = 2 ;
2014-10-06 14:50:05 +02:00
drawJournal ( 1 , false ) ;
}
2015-12-16 23:27:32 +02:00
} else if ( buttonId = = 1 ) {
2014-10-06 14:50:05 +02:00
return ;
2015-12-16 23:27:32 +02:00
} else if ( buttonId = = 2 ) {
2015-12-13 11:55:49 +01:00
if ( ! _lastPage ) {
_journalPage + = 2 ;
2014-10-06 14:50:05 +02:00
drawJournal ( 2 , false ) ;
}
}
}
}
}
}
2015-11-29 18:10:06 +01:00
void LabEngine : : doJournal ( ) {
2015-12-04 13:32:08 +01:00
_graphics - > blackAllScreen ( ) ;
2015-12-13 22:51:23 +01:00
_lastPage = false ;
2014-10-06 14:50:05 +02:00
2015-12-13 22:55:10 +01:00
_screenImage - > _width = _journalBackImage - > _width = _graphics - > _screenWidth ;
_screenImage - > _height = _journalBackImage - > _height = _graphics - > _screenHeight ;
_journalBackImage - > _imageData = nullptr ;
_screenImage - > _imageData = _graphics - > getCurrentDrawingBuffer ( ) ;
2014-10-06 14:50:05 +02:00
2015-12-22 19:40:34 +01:00
updateMusicAndEvents ( ) ;
2014-12-25 19:13:52 +01:00
loadJournalData ( ) ;
2015-12-13 19:36:56 +02:00
_event - > attachButtonList ( & _journalButtonList ) ;
2015-12-10 12:45:21 +02:00
drawJournal ( 0 , true ) ;
2015-11-29 18:10:06 +01:00
_event - > mouseShow ( ) ;
2014-10-06 14:50:05 +02:00
processJournal ( ) ;
2015-12-16 16:11:06 +01:00
_event - > attachButtonList ( nullptr ) ;
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-10 12:45:21 +02:00
delete [ ] _blankJournal ;
2015-12-13 22:55:10 +01:00
delete [ ] _journalBackImage - > _imageData ;
2015-12-22 00:12:12 +01:00
_blankJournal = _journalBackImage - > _imageData = nullptr ;
2015-12-13 19:36:56 +02:00
_event - > freeButtonList ( & _journalButtonList ) ;
2015-12-19 13:08:54 +01:00
_graphics - > closeFont ( & _journalFont ) ;
2014-10-06 14:50:05 +02:00
2015-12-13 22:55:10 +01:00
_screenImage - > _imageData = _graphics - > getCurrentDrawingBuffer ( ) ;
2014-10-06 14:50:05 +02:00
2015-12-14 22:50:09 +01:00
_graphics - > setPen ( 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-17 18:35:53 +01:00
void LabEngine : : drawMonText ( char * text , TextFont * monitorFont , Common : : Rect textRect , bool isinteractive ) {
2015-12-14 14:20:22 +01:00
uint16 drawingToPage = 0 , yspacing = 0 ;
2015-12-14 21:44:06 +01:00
int charsDrawn = 0 ;
2015-12-10 10:51:02 +01:00
char * curText = text ;
2014-10-06 14:50:05 +02:00
2015-11-29 18:10:06 +01:00
_event - > mouseHide ( ) ;
2014-10-06 14:50:05 +02:00
if ( * text = = ' % ' ) {
text + + ;
2015-12-14 14:20:22 +01:00
uint16 numlines = ( * text - ' 0 ' ) * 10 ;
2014-10-06 14:50:05 +02:00
text + + ;
numlines + = ( * text - ' 0 ' ) ;
text + = 2 ;
2015-12-14 14:20:22 +01:00
uint16 fheight = _graphics - > textHeight ( monitorFont ) ;
2015-12-17 18:35:53 +01:00
textRect . left = _monitorButton - > _width + _utils - > vgaScaleX ( 3 ) ;
2015-12-13 19:36:56 +02:00
_monitorButtonHeight = _monitorButton - > _height + _utils - > vgaScaleY ( 3 ) ;
2014-10-06 14:50:05 +02:00
2015-12-13 19:36:56 +02:00
if ( _monitorButtonHeight > fheight )
yspacing = _monitorButtonHeight - fheight ;
2014-10-06 14:50:05 +02:00
else
2015-12-13 19:36:56 +02:00
_monitorButtonHeight = fheight ;
2014-10-06 14:50:05 +02:00
2015-12-14 22:50:09 +01:00
_graphics - > setPen ( 0 ) ;
2015-12-17 18:35:53 +01:00
_graphics - > rectFill ( 0 , 0 , _graphics - > _screenWidth - 1 , textRect . bottom ) ;
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-13 19:36:56 +02:00
_monitorButton - > drawImage ( 0 , i * _monitorButtonHeight ) ;
2014-10-06 14:50:05 +02:00
} else if ( isinteractive ) {
2015-12-14 22:50:09 +01:00
_graphics - > setPen ( 0 ) ;
2015-12-17 18:35:53 +01:00
_graphics - > rectFill ( 0 , 0 , _graphics - > _screenWidth - 1 , textRect . bottom ) ;
2014-10-06 14:50:05 +02:00
} else {
2015-12-14 22:50:09 +01:00
_graphics - > setPen ( 0 ) ;
2015-12-17 18:35:53 +01:00
_graphics - > rectFill ( textRect ) ;
2014-10-06 14:50:05 +02:00
}
2015-12-13 11:55:49 +01:00
while ( drawingToPage < _monitorPage ) {
2015-12-22 19:40:34 +01:00
updateMusicAndEvents ( ) ;
2015-12-22 01:37:41 +01:00
curText = text + charsDrawn ;
2015-12-17 18:35:53 +01:00
charsDrawn + = _graphics - > flowText ( monitorFont , yspacing , 0 , 0 , false , false , false , false , textRect , curText ) ;
2015-12-13 11:55:49 +01:00
_lastPage = ( * curText = = 0 ) ;
2014-10-06 14:50:05 +02:00
2015-12-13 11:55:49 +01:00
if ( _lastPage )
_monitorPage = drawingToPage ;
2014-10-06 14:50:05 +02:00
else
2015-12-10 10:51:02 +01:00
drawingToPage + + ;
2014-10-06 14:50:05 +02:00
}
2015-12-22 01:37:41 +01:00
curText = text + charsDrawn ;
2015-12-13 11:55:49 +01:00
_lastPage = ( * curText = = 0 ) ;
2015-12-17 18:35:53 +01:00
charsDrawn = _graphics - > flowText ( monitorFont , yspacing , 2 , 0 , false , false , false , true , textRect , curText ) ;
2015-11-29 18:10:06 +01:00
_event - > mouseShow ( ) ;
2014-10-06 14:50:05 +02:00
}
2015-12-17 18:35:53 +01:00
void LabEngine : : processMonitor ( char * ntext , TextFont * monitorFont , bool isInteractive , Common : : Rect textRect ) {
2015-12-19 02:12:42 +02:00
Common : : String startFileName = _monitorTextFilename ;
2015-12-09 11:22:41 +01:00
CloseDataPtr startClosePtr = _closeDataPtr , lastClosePtr [ 10 ] ;
2014-10-06 14:50:05 +02:00
uint16 depth = 0 ;
2015-12-09 11:22:41 +01:00
lastClosePtr [ 0 ] = _closeDataPtr ;
2014-10-06 14:50:05 +02:00
while ( 1 ) {
2015-12-13 13:34:37 +01:00
if ( isInteractive ) {
2015-12-16 16:11:06 +01:00
if ( ! _closeDataPtr )
2015-12-09 11:22:41 +01:00
_closeDataPtr = startClosePtr ;
2014-10-06 14:50:05 +02:00
2015-12-19 02:12:42 +02:00
Common : : String test ;
2015-12-09 11:22:41 +01:00
if ( _closeDataPtr = = startClosePtr )
2015-12-10 10:51:02 +01:00
test = startFileName ;
2014-10-06 14:50:05 +02:00
else
2015-12-10 10:51:02 +01:00
test = _closeDataPtr - > _graphicName ;
2014-10-06 14:50:05 +02:00
2015-12-19 02:12:42 +02:00
if ( test ! = _monitorTextFilename ) {
2015-12-16 16:11:06 +01:00
_monitorPage = 0 ;
2015-12-13 11:55:49 +01:00
_monitorTextFilename = test ;
2014-10-06 14:50:05 +02:00
2015-12-20 16:04:20 +01:00
Common : : String text = _resource - > getText ( _monitorTextFilename ) ;
2015-12-06 18:16:26 +01:00
_graphics - > fade ( false , 0 ) ;
2015-12-19 02:12:42 +02:00
drawMonText ( ( char * ) text . c_str ( ) , monitorFont , textRect , isInteractive ) ;
2015-12-06 18:16:26 +01:00
_graphics - > fade ( true , 0 ) ;
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
2015-12-22 19:40:34 +01:00
updateMusicAndEvents ( ) ;
2015-12-13 15:37:39 +02:00
IntuiMessage * msg = _event - > getMsg ( ) ;
2015-12-16 00:07:31 +01:00
if ( g_engine - > shouldQuit ( ) ) {
_quitLab = true ;
return ;
}
2014-10-06 14:50:05 +02:00
2015-12-16 00:07:31 +01:00
if ( ! msg ) {
2015-12-22 19:40:34 +01:00
updateMusicAndEvents ( ) ;
2014-10-06 14:50:05 +02:00
} else {
2015-12-10 10:51:02 +01:00
uint32 msgClass = msg - > _msgClass ;
2015-12-18 00:58:36 +02:00
uint16 mouseX = msg - > _mouse . x ;
uint16 mouseY = msg - > _mouse . y ;
2015-12-10 10:51:02 +01:00
uint16 code = msg - > _code ;
2015-12-09 11:22:41 +01:00
2015-12-18 00:41:24 +02:00
if ( ( msgClass = = kMessageRightClick ) | |
( ( msgClass = = kMessageRawKey ) & & ( code = = Common : : KEYCODE_ESCAPE ) ) )
2014-10-06 14:50:05 +02:00
return ;
2015-12-18 00:41:24 +02:00
else if ( msgClass = = kMessageLeftClick ) {
2015-12-10 07:04:59 +01:00
if ( ( mouseY > = _utils - > vgaScaleY ( 171 ) ) & & ( mouseY < = _utils - > vgaScaleY ( 200 ) ) ) {
2015-12-15 16:18:32 +01:00
if ( mouseX < = _utils - > vgaScaleX ( 31 ) ) {
2014-10-06 14:50:05 +02:00
return ;
2015-12-15 16:18:32 +01:00
} else if ( mouseX < = _utils - > vgaScaleX ( 59 ) ) {
2015-12-13 13:34:37 +01:00
if ( isInteractive ) {
2015-12-13 11:55:49 +01:00
_monitorPage = 0 ;
2014-10-06 14:50:05 +02:00
if ( depth ) {
depth - - ;
2015-12-09 11:22:41 +01:00
_closeDataPtr = lastClosePtr [ depth ] ;
2014-10-06 14:50:05 +02:00
}
2015-12-13 11:55:49 +01:00
} else if ( _monitorPage > 0 ) {
_monitorPage = 0 ;
2015-12-17 18:35:53 +01:00
drawMonText ( ntext , monitorFont , textRect , isInteractive ) ;
2014-10-06 14:50:05 +02:00
}
2015-12-15 16:18:32 +01:00
} else if ( mouseX < _utils - > vgaScaleX ( 259 ) ) {
return ;
} else if ( mouseX < = _utils - > vgaScaleX ( 289 ) ) {
if ( ! _lastPage ) {
_monitorPage + = 1 ;
2015-12-17 18:35:53 +01:00
drawMonText ( ntext , monitorFont , textRect , isInteractive ) ;
2015-12-15 16:18:32 +01:00
}
} else if ( _monitorPage > = 1 ) {
// mouseX between 290 and 320 (scaled)
_monitorPage - = 1 ;
2015-12-17 18:35:53 +01:00
drawMonText ( ntext , monitorFont , textRect , isInteractive ) ;
2014-10-06 14:50:05 +02:00
}
2015-12-13 13:34:37 +01:00
} else if ( isInteractive ) {
2015-12-09 11:22:41 +01:00
CloseDataPtr tmpClosePtr = _closeDataPtr ;
2015-12-13 19:36:56 +02:00
mouseY = 64 + ( mouseY / _monitorButtonHeight ) * 42 ;
2015-12-09 11:22:41 +01:00
mouseX = 101 ;
setCurrentClose ( Common : : Point ( mouseX , mouseY ) , & _closeDataPtr , false ) ;
2014-10-06 14:50:05 +02:00
2015-12-09 11:22:41 +01:00
if ( tmpClosePtr ! = _closeDataPtr ) {
lastClosePtr [ depth ] = tmpClosePtr ;
2014-10-06 14:50:05 +02:00
depth + + ;
}
}
}
}
}
}
2015-12-20 17:21:55 +01:00
void LabEngine : : doMonitor ( const Common : : String background , const Common : : String textfile , bool isinteractive , Common : : Rect textRect ) {
2015-12-17 18:35:53 +01:00
Common : : Rect scaledRect = _utils - > vgaRectScale ( textRect . left , textRect . top , textRect . right , textRect . bottom ) ;
2015-12-13 11:55:49 +01:00
_monitorTextFilename = textfile ;
2014-10-06 14:50:05 +02:00
2015-12-04 13:32:08 +01:00
_graphics - > blackAllScreen ( ) ;
2015-12-20 16:52:49 +01:00
_graphics - > readPict ( " P:Mon/Monitor.1 " ) ;
_graphics - > readPict ( " P:Mon/NWD1 " ) ;
_graphics - > readPict ( " P:Mon/NWD2 " ) ;
_graphics - > readPict ( " P:Mon/NWD3 " ) ;
2015-12-04 13:32:08 +01:00
_graphics - > blackAllScreen ( ) ;
2014-10-06 14:50:05 +02:00
2015-12-13 11:55:49 +01:00
_monitorPage = 0 ;
_lastPage = false ;
2015-12-14 08:59:16 +01:00
_graphics - > _fadePalette = _highPalette ;
2014-10-06 14:50:05 +02:00
2015-12-18 05:42:26 +02:00
TextFont * monitorFont = _resource - > getFont ( " F:Map.fon " ) ;
2015-12-10 07:04:59 +01:00
Common : : File * buttonFile = _resource - > openDataFile ( " P:MonImage " ) ;
2015-12-13 22:51:23 +01:00
_monitorButton = new Image ( buttonFile , this ) ;
2015-12-05 18:14:50 +02:00
delete buttonFile ;
2014-10-06 14:50:05 +02:00
2015-12-20 16:02:35 +01:00
Common : : String ntext = _resource - > getText ( textfile ) ;
_graphics - > loadBackPict ( background , _highPalette ) ;
2015-12-19 02:12:42 +02:00
drawMonText ( ( char * ) ntext . c_str ( ) , monitorFont , scaledRect , 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-19 02:12:42 +02:00
processMonitor ( ( char * ) ntext . c_str ( ) , monitorFont , isinteractive , scaledRect ) ;
2015-12-06 18:16:26 +01:00
_graphics - > fade ( false , 0 ) ;
2015-11-29 18:10:06 +01:00
_event - > mouseHide ( ) ;
2015-12-19 13:08:54 +01:00
_graphics - > closeFont ( & monitorFont ) ;
2014-10-06 14:50:05 +02:00
2015-12-14 22:50:09 +01:00
_graphics - > setPen ( 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