2007-05-30 21:56:52 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
2006-05-23 23:43:52 +00:00
|
|
|
*
|
2007-05-30 21:56:52 +00:00
|
|
|
* 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.
|
2006-05-23 23:43:52 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "agi/agi.h"
|
2009-06-06 17:39:13 +00:00
|
|
|
#include "agi/sprite.h" // for commit_both()
|
2006-05-23 23:43:52 +00:00
|
|
|
#include "agi/graphics.h"
|
|
|
|
#include "agi/keyboard.h"
|
|
|
|
|
|
|
|
namespace Agi {
|
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
void AgiEngine::printText2(int l, const char *msg, int foff, int xoff, int yoff,
|
2007-01-06 05:11:41 +00:00
|
|
|
int len, int fg, int bg, bool checkerboard) {
|
2006-05-23 23:43:52 +00:00
|
|
|
int x1, y1;
|
|
|
|
int maxx, minx, ofoff;
|
|
|
|
int update;
|
2009-06-06 17:39:13 +00:00
|
|
|
// Note: Must be unsigned to use AGDS cyrillic characters!
|
2007-04-06 18:34:53 +00:00
|
|
|
#ifdef __DS__
|
|
|
|
// On the DS, a compiler bug causes the text to render incorrectly, because
|
|
|
|
// GCC tries to optimisie out writes to this pointer (tested on DevkitARM v19b and v20)
|
|
|
|
// Making this pointer volatile fixes this.
|
|
|
|
volatile const unsigned char *m;
|
|
|
|
#else
|
2006-05-31 10:53:04 +00:00
|
|
|
const unsigned char *m;
|
2007-04-06 18:34:53 +00:00
|
|
|
#endif
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2009-06-06 17:39:13 +00:00
|
|
|
// kludge!
|
2006-05-23 23:43:52 +00:00
|
|
|
update = 1;
|
|
|
|
if (l == 2) {
|
|
|
|
update = l = 0;
|
|
|
|
}
|
|
|
|
|
2009-06-06 17:39:13 +00:00
|
|
|
// FR: strings with len == 1 were not printed
|
2006-05-23 23:43:52 +00:00
|
|
|
if (len == 1) {
|
2007-01-06 05:11:41 +00:00
|
|
|
_gfx->putTextCharacter(l, xoff + foff, yoff, *msg, fg, bg, checkerboard);
|
2006-05-23 23:43:52 +00:00
|
|
|
maxx = 1;
|
|
|
|
minx = 0;
|
|
|
|
ofoff = foff;
|
2009-06-06 17:39:13 +00:00
|
|
|
y1 = 0; // Check this
|
2006-05-23 23:43:52 +00:00
|
|
|
} else {
|
|
|
|
maxx = 0;
|
|
|
|
minx = GFX_WIDTH;
|
|
|
|
ofoff = foff;
|
|
|
|
|
2006-05-31 10:53:04 +00:00
|
|
|
for (m = (const unsigned char *)msg, x1 = y1 = 0; *m; m++) {
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2011-09-26 12:27:05 +00:00
|
|
|
// Note: there were extra checks for *m being a cursor character
|
|
|
|
// here (1, 2 or 3), which have been removed, as the cursor
|
2012-09-26 02:17:31 +00:00
|
|
|
// character is no longer printed via this function.
|
2011-09-26 12:27:05 +00:00
|
|
|
if (*m >= 0x20) {
|
2011-09-26 09:11:55 +00:00
|
|
|
int ypos = (y1 * CHAR_LINES) + yoff;
|
2006-05-23 23:43:52 +00:00
|
|
|
|
|
|
|
if ((x1 != (len - 1) || x1 == 39) && (ypos <= (GFX_HEIGHT - CHAR_LINES))) {
|
2011-09-26 09:11:55 +00:00
|
|
|
int xpos = (x1 * CHAR_COLS) + xoff + foff;
|
2006-05-23 23:43:52 +00:00
|
|
|
|
|
|
|
if (xpos >= GFX_WIDTH)
|
|
|
|
continue;
|
2012-09-26 02:17:31 +00:00
|
|
|
|
2007-01-06 05:11:41 +00:00
|
|
|
_gfx->putTextCharacter(l, xpos, ypos, *m, fg, bg, checkerboard);
|
2006-05-23 23:43:52 +00:00
|
|
|
|
|
|
|
if (x1 > maxx)
|
|
|
|
maxx = x1;
|
|
|
|
if (x1 < minx)
|
|
|
|
minx = x1;
|
|
|
|
}
|
|
|
|
|
|
|
|
x1++;
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2011-09-26 12:21:04 +00:00
|
|
|
// Change line if we've reached the end of this one, unless the next
|
|
|
|
// character is a new line itself, or the end of the string
|
|
|
|
if (x1 == len && m[1] != '\n' && m[1] != 0) {
|
2011-05-17 19:21:51 +00:00
|
|
|
y1++;
|
|
|
|
x1 = foff = 0;
|
|
|
|
}
|
2006-05-23 23:43:52 +00:00
|
|
|
} else {
|
2011-09-26 12:21:04 +00:00
|
|
|
if (m[1] != 0) {
|
|
|
|
y1++;
|
|
|
|
x1 = foff = 0;
|
|
|
|
}
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (l)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (maxx < minx)
|
|
|
|
return;
|
|
|
|
|
|
|
|
maxx *= CHAR_COLS;
|
|
|
|
minx *= CHAR_COLS;
|
|
|
|
|
|
|
|
if (update) {
|
2006-12-06 19:27:02 +00:00
|
|
|
_gfx->scheduleUpdate(foff + xoff + minx, yoff, ofoff + xoff + maxx + CHAR_COLS - 1,
|
2006-05-23 23:43:52 +00:00
|
|
|
yoff + y1 * CHAR_LINES + CHAR_LINES + 1);
|
2009-06-06 17:39:13 +00:00
|
|
|
|
|
|
|
// Making synchronous text updates reduces CPU load
|
|
|
|
// when updating status line and input area
|
2006-12-06 19:27:02 +00:00
|
|
|
_gfx->doUpdate();
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-06 17:39:13 +00:00
|
|
|
//
|
|
|
|
// len is in characters, not pixels!!
|
|
|
|
//
|
2007-01-16 12:40:51 +00:00
|
|
|
void AgiEngine::blitTextbox(const char *p, int y, int x, int len) {
|
2009-06-06 17:39:13 +00:00
|
|
|
// if x | y = -1, then center the box
|
2006-05-23 23:43:52 +00:00
|
|
|
int xoff, yoff, lin, h, w;
|
|
|
|
char *msg, *m;
|
|
|
|
|
2009-01-02 01:34:53 +00:00
|
|
|
debugC(3, kDebugLevelText, "blitTextbox(): x=%d, y=%d, len=%d", x, y, len);
|
2007-01-16 12:40:51 +00:00
|
|
|
if (_game.window.active)
|
|
|
|
closeWindow();
|
2006-05-23 23:43:52 +00:00
|
|
|
|
|
|
|
if (x == 0 && y == 0 && len == 0)
|
|
|
|
x = y = -1;
|
|
|
|
|
2010-06-15 10:28:58 +00:00
|
|
|
if (len <= 0)
|
|
|
|
len = 30;
|
2006-05-23 23:43:52 +00:00
|
|
|
|
|
|
|
xoff = x * CHAR_COLS;
|
|
|
|
yoff = y * CHAR_LINES;
|
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
m = msg = wordWrapString(agiSprintf(p), &len);
|
2006-05-23 23:43:52 +00:00
|
|
|
|
|
|
|
for (lin = 1; *m; m++) {
|
2009-06-06 17:39:13 +00:00
|
|
|
// Test \r for MacOS 8
|
2006-05-23 23:43:52 +00:00
|
|
|
if (*m == '\n' || *m == '\r')
|
|
|
|
lin++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lin * CHAR_LINES > GFX_HEIGHT)
|
|
|
|
lin = (GFX_HEIGHT / CHAR_LINES);
|
|
|
|
|
|
|
|
w = (len + 2) * CHAR_COLS;
|
|
|
|
h = (lin + 2) * CHAR_LINES;
|
|
|
|
|
|
|
|
if (xoff < 0)
|
|
|
|
xoff = (GFX_WIDTH - w - CHAR_COLS) / 2;
|
|
|
|
else
|
|
|
|
xoff -= CHAR_COLS;
|
|
|
|
|
|
|
|
if (yoff < 0)
|
|
|
|
yoff = (GFX_HEIGHT - 3 * CHAR_LINES - h) / 2;
|
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
drawWindow(xoff, yoff, xoff + w - 1, yoff + h - 1);
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
printText2(2, msg, 0, CHAR_COLS + xoff, CHAR_LINES + yoff,
|
2011-04-14 12:12:27 +00:00
|
|
|
len + 1, MSG_BOX_TEXT, MSG_BOX_COLOR);
|
2006-05-23 23:43:52 +00:00
|
|
|
|
|
|
|
free(msg);
|
|
|
|
|
2006-12-06 19:27:02 +00:00
|
|
|
_gfx->doUpdate();
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
void AgiEngine::eraseTextbox() {
|
|
|
|
if (!_game.window.active) {
|
2009-01-02 01:34:53 +00:00
|
|
|
debugC(3, kDebugLevelText, "eraseTextbox(): no window active");
|
2006-05-23 23:43:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-01-02 01:34:53 +00:00
|
|
|
debugC(4, kDebugLevelText, "eraseTextbox(): x1=%d, y1=%d, x2=%d, y2=%d", _game.window.x1,
|
2007-01-16 12:40:51 +00:00
|
|
|
_game.window.y1, _game.window.x2, _game.window.y2);
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
_gfx->restoreBlock(_game.window.x1, _game.window.y1,
|
|
|
|
_game.window.x2, _game.window.y2, _game.window.buffer);
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
free(_game.window.buffer);
|
|
|
|
_game.window.active = false;
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2006-12-06 19:27:02 +00:00
|
|
|
_gfx->doUpdate();
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Public functions
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Print text in the AGI engine screen.
|
|
|
|
*/
|
2007-01-16 12:40:51 +00:00
|
|
|
void AgiEngine::printText(const char *msg, int f, int x, int y, int len, int fg, int bg, bool checkerboard) {
|
2006-05-23 23:43:52 +00:00
|
|
|
f *= CHAR_COLS;
|
|
|
|
x *= CHAR_COLS;
|
|
|
|
y *= CHAR_LINES;
|
|
|
|
|
2009-01-02 01:34:53 +00:00
|
|
|
debugC(4, kDebugLevelText, "printText(): %s, %d, %d, %d, %d, %d, %d", msg, f, x, y, len, fg, bg);
|
2007-01-16 12:40:51 +00:00
|
|
|
printText2(0, agiSprintf(msg), f, x, y, len, fg, bg, checkerboard);
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Print text in the AGI engine console.
|
|
|
|
*/
|
2007-01-16 12:40:51 +00:00
|
|
|
void AgiEngine::printTextConsole(const char *msg, int x, int y, int len, int fg, int bg) {
|
2006-05-23 23:43:52 +00:00
|
|
|
x *= CHAR_COLS;
|
|
|
|
y *= 10;
|
|
|
|
|
2010-06-15 10:27:23 +00:00
|
|
|
debugC(4, kDebugLevelText, "printTextConsole(): %s, %d, %d, %d, %d, %d", msg, x, y, len, fg, bg);
|
2007-01-16 12:40:51 +00:00
|
|
|
printText2(1, msg, 0, x, y, len, fg, bg);
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-12-07 01:00:26 +00:00
|
|
|
* Wrap text line to the specified width.
|
2006-05-23 23:43:52 +00:00
|
|
|
* @param str String to wrap.
|
|
|
|
* @param len Length of line.
|
2009-01-02 01:34:53 +00:00
|
|
|
*
|
2011-09-26 08:45:13 +00:00
|
|
|
* Based on GBAGI implementation with permission from the author
|
2006-05-23 23:43:52 +00:00
|
|
|
*/
|
2009-01-07 13:27:58 +00:00
|
|
|
char *AgiEngine::wordWrapString(const char *s, int *len) {
|
2011-10-09 23:12:48 +00:00
|
|
|
char *outStr, *msgBuf;
|
|
|
|
int maxWidth = *len;
|
2009-01-07 13:27:58 +00:00
|
|
|
const char *pWord;
|
2009-01-02 01:34:53 +00:00
|
|
|
int lnLen, wLen;
|
|
|
|
|
2011-09-26 12:22:48 +00:00
|
|
|
// Allocate some extra space for the final buffer, as
|
|
|
|
// outStr may end up being longer than s
|
|
|
|
// 26 = 200 (screen height) / 8 (font height) + 1
|
|
|
|
msgBuf = outStr = (char *)malloc(strlen(s) + 26);
|
2009-01-02 01:34:53 +00:00
|
|
|
|
|
|
|
int msgWidth = 0;
|
|
|
|
|
|
|
|
lnLen = 0;
|
|
|
|
|
|
|
|
while (*s) {
|
|
|
|
pWord = s;
|
|
|
|
|
|
|
|
while (*s != '\0' && *s != ' ' && *s != '\n' && *s != '\r')
|
|
|
|
s++;
|
|
|
|
|
|
|
|
wLen = (int)(s - pWord);
|
|
|
|
|
|
|
|
if (wLen && *s == '\n' && s[-1] == ' ')
|
|
|
|
wLen--;
|
|
|
|
|
|
|
|
if (wLen + lnLen >= maxWidth) {
|
2011-09-26 09:11:55 +00:00
|
|
|
// Check if outStr isn't msgBuf. If this is the case, outStr hasn't advanced
|
|
|
|
// yet, so no output has been written yet
|
2009-01-02 01:34:53 +00:00
|
|
|
if (outStr != msgBuf) {
|
|
|
|
if (outStr[-1] == ' ')
|
|
|
|
outStr[-1] = '\n';
|
|
|
|
else
|
|
|
|
*outStr++ = '\n';
|
|
|
|
}
|
|
|
|
|
|
|
|
lnLen = 0;
|
|
|
|
|
|
|
|
while (wLen >= maxWidth) {
|
|
|
|
msgWidth = maxWidth;
|
|
|
|
|
|
|
|
memcpy(outStr, pWord, maxWidth);
|
|
|
|
|
|
|
|
wLen -= maxWidth;
|
|
|
|
outStr += maxWidth;
|
|
|
|
pWord += maxWidth;
|
|
|
|
*outStr++ = '\n';
|
|
|
|
}
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
2009-01-02 01:34:53 +00:00
|
|
|
|
|
|
|
if (wLen) {
|
|
|
|
memcpy(outStr, pWord, wLen);
|
|
|
|
outStr += wLen;
|
2009-05-24 15:17:42 +00:00
|
|
|
}
|
2009-01-02 01:34:53 +00:00
|
|
|
lnLen += wLen+1;
|
2009-05-24 15:17:42 +00:00
|
|
|
|
2009-01-02 01:34:53 +00:00
|
|
|
if (lnLen > msgWidth) {
|
|
|
|
msgWidth = lnLen;
|
|
|
|
|
|
|
|
if (*s == '\0' || *s == ' ' || *s == '\n' || *s == '\r')
|
|
|
|
msgWidth--;
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
|
|
|
|
2009-01-02 01:34:53 +00:00
|
|
|
if (*s == '\n')
|
|
|
|
lnLen = 0;
|
|
|
|
|
|
|
|
if (*s)
|
|
|
|
*outStr++ = *s++;
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
2009-01-02 01:34:53 +00:00
|
|
|
*outStr = '\0';
|
|
|
|
*len = msgWidth;
|
|
|
|
|
|
|
|
return msgBuf;
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove existing window, if any.
|
|
|
|
*/
|
2007-01-16 12:40:51 +00:00
|
|
|
void AgiEngine::closeWindow() {
|
2009-01-02 01:34:53 +00:00
|
|
|
debugC(4, kDebugLevelText, "closeWindow()");
|
2009-05-19 21:09:43 +00:00
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
_sprites->eraseBoth();
|
2009-06-06 17:39:13 +00:00
|
|
|
eraseTextbox(); // remove window, if any
|
2007-01-16 12:40:51 +00:00
|
|
|
_sprites->blitBoth();
|
2009-06-06 17:39:13 +00:00
|
|
|
_sprites->commitBoth(); // redraw sprites
|
2007-01-16 12:40:51 +00:00
|
|
|
_game.hasWindow = false;
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display a message box.
|
|
|
|
* This function displays the specified message in a text box
|
|
|
|
* centered in the screen and waits until a key is pressed.
|
|
|
|
* @param p The text to be displayed
|
|
|
|
*/
|
2007-01-16 12:40:51 +00:00
|
|
|
int AgiEngine::messageBox(const char *s) {
|
2006-05-23 23:43:52 +00:00
|
|
|
int k;
|
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
_sprites->eraseBoth();
|
|
|
|
blitTextbox(s, -1, -1, -1);
|
|
|
|
_sprites->blitBoth();
|
|
|
|
k = waitKey();
|
2009-01-02 01:34:53 +00:00
|
|
|
debugC(4, kDebugLevelText, "messageBox(): wait_key returned %02x", k);
|
2007-01-16 12:40:51 +00:00
|
|
|
closeWindow();
|
2006-05-23 23:43:52 +00:00
|
|
|
|
|
|
|
return k;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display a message box with buttons.
|
|
|
|
* This function displays the specified message in a text box
|
|
|
|
* centered in the screen and waits until a button is pressed.
|
|
|
|
* @param p The text to be displayed
|
|
|
|
* @param b NULL-terminated list of button labels
|
|
|
|
*/
|
2007-01-16 12:40:51 +00:00
|
|
|
int AgiEngine::selectionBox(const char *m, const char **b) {
|
2007-03-17 13:31:48 +00:00
|
|
|
int numButtons = 0;
|
2006-05-23 23:43:52 +00:00
|
|
|
int x, y, i, s;
|
|
|
|
int bx[5], by[5];
|
|
|
|
|
2009-06-06 17:42:37 +00:00
|
|
|
_noSaveLoadAllowed = true;
|
2009-05-21 21:51:50 +00:00
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
_sprites->eraseBoth();
|
|
|
|
blitTextbox(m, -1, -1, -1);
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
x = _game.window.x1 + 5 * CHAR_COLS / 2;
|
|
|
|
y = _game.window.y2 - 5 * CHAR_LINES / 2;
|
|
|
|
s = _game.window.x2 - _game.window.x1 + 1 - 5 * CHAR_COLS;
|
2009-01-02 01:34:53 +00:00
|
|
|
debugC(3, kDebugLevelText, "selectionBox(): s = %d", s);
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2009-06-06 17:39:13 +00:00
|
|
|
// Automatically position buttons
|
2006-05-23 23:43:52 +00:00
|
|
|
for (i = 0; b[i]; i++) {
|
2007-03-17 13:31:48 +00:00
|
|
|
numButtons++;
|
2006-05-23 23:43:52 +00:00
|
|
|
s -= CHAR_COLS * strlen(b[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i > 1) {
|
2009-01-02 01:34:53 +00:00
|
|
|
debugC(3, kDebugLevelText, "selectionBox(): s / %d = %d", i - 1, s / (i - 1));
|
2006-05-23 23:43:52 +00:00
|
|
|
s /= (i - 1);
|
|
|
|
} else {
|
|
|
|
x += s / 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; b[i]; i++) {
|
|
|
|
bx[i] = x;
|
|
|
|
by[i] = y;
|
|
|
|
x += CHAR_COLS * strlen(b[i]) + s;
|
|
|
|
}
|
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
_sprites->blitBoth();
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2009-06-06 17:45:52 +00:00
|
|
|
clearKeyQueue();
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2007-03-17 16:08:29 +00:00
|
|
|
AllowSyntheticEvents on(this);
|
|
|
|
|
2009-01-02 01:34:53 +00:00
|
|
|
debugC(4, kDebugLevelText, "selectionBox(): waiting...");
|
2011-12-10 20:12:35 +00:00
|
|
|
int key, active = 0;
|
|
|
|
int rc = -1;
|
|
|
|
while (rc == -1 && !(shouldQuit() || _restartGame)) {
|
2006-05-23 23:43:52 +00:00
|
|
|
for (i = 0; b[i]; i++)
|
2007-07-10 18:32:24 +00:00
|
|
|
_gfx->drawCurrentStyleButton(bx[i], by[i], b[i], i == active, false, i == 0);
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2009-06-06 17:45:52 +00:00
|
|
|
pollTimer();
|
2007-01-16 12:40:51 +00:00
|
|
|
key = doPollKeyboard();
|
2006-05-24 21:40:24 +00:00
|
|
|
switch (key) {
|
|
|
|
case KEY_ENTER:
|
|
|
|
rc = active;
|
2011-12-10 20:12:35 +00:00
|
|
|
debugC(4, kDebugLevelText, "selectionBox(): Button pressed: %d", rc);
|
|
|
|
break;
|
2007-03-17 13:31:48 +00:00
|
|
|
case KEY_RIGHT:
|
|
|
|
active++;
|
|
|
|
if (active >= numButtons)
|
|
|
|
active = 0;
|
|
|
|
break;
|
|
|
|
case KEY_LEFT:
|
|
|
|
active--;
|
|
|
|
if (active < 0)
|
|
|
|
active = numButtons - 1;
|
|
|
|
break;
|
2006-05-24 21:40:24 +00:00
|
|
|
case BUTTON_LEFT:
|
|
|
|
for (i = 0; b[i]; i++) {
|
2006-12-06 19:27:02 +00:00
|
|
|
if (_gfx->testButton(bx[i], by[i], b[i])) {
|
2006-05-24 21:40:24 +00:00
|
|
|
rc = active = i;
|
2011-12-10 20:12:35 +00:00
|
|
|
debugC(4, kDebugLevelText, "selectionBox(): Button pressed: %d", rc);
|
|
|
|
break;
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
|
|
|
}
|
2006-05-24 21:40:24 +00:00
|
|
|
break;
|
2009-06-06 17:39:13 +00:00
|
|
|
case 0x09: // Tab
|
2009-01-02 01:34:53 +00:00
|
|
|
debugC(3, kDebugLevelText, "selectionBox(): Focus change");
|
2006-05-24 21:40:24 +00:00
|
|
|
active++;
|
|
|
|
active %= i;
|
|
|
|
break;
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
2006-12-06 19:27:02 +00:00
|
|
|
_gfx->doUpdate();
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2011-12-10 20:12:35 +00:00
|
|
|
if (key == KEY_ESCAPE)
|
|
|
|
break;
|
|
|
|
}
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
closeWindow();
|
2009-01-02 01:34:53 +00:00
|
|
|
debugC(2, kDebugLevelText, "selectionBox(): Result = %d", rc);
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2009-06-06 17:42:37 +00:00
|
|
|
_noSaveLoadAllowed = false;
|
2009-05-21 21:51:50 +00:00
|
|
|
|
2006-05-23 23:43:52 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2006-12-06 19:27:02 +00:00
|
|
|
int AgiEngine::print(const char *p, int lin, int col, int len) {
|
2006-05-23 23:43:52 +00:00
|
|
|
if (p == NULL)
|
|
|
|
return 0;
|
|
|
|
|
2009-01-02 01:34:53 +00:00
|
|
|
debugC(4, kDebugLevelText, "print(): lin = %d, col = %d, len = %d", lin, col, len);
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
blitTextbox(p, lin, col, len);
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
if (getflag(fOutputMode)) {
|
2009-06-06 17:39:13 +00:00
|
|
|
// non-blocking window
|
2007-01-16 12:40:51 +00:00
|
|
|
setflag(fOutputMode, false);
|
2006-05-23 23:43:52 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2009-06-06 17:39:13 +00:00
|
|
|
// blocking
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2009-06-06 17:42:37 +00:00
|
|
|
_noSaveLoadAllowed = true;
|
2009-05-21 21:51:50 +00:00
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
if (_game.vars[vWindowReset] == 0) {
|
2006-05-23 23:43:52 +00:00
|
|
|
int k;
|
2007-01-16 12:40:51 +00:00
|
|
|
setvar(vKey, 0);
|
|
|
|
k = waitKey();
|
|
|
|
closeWindow();
|
2009-05-21 21:51:50 +00:00
|
|
|
|
2009-06-06 17:42:37 +00:00
|
|
|
_noSaveLoadAllowed = false;
|
2009-05-21 21:51:50 +00:00
|
|
|
|
2006-05-23 23:43:52 +00:00
|
|
|
return k;
|
|
|
|
}
|
|
|
|
|
2009-06-06 17:39:13 +00:00
|
|
|
// timed window
|
2006-05-23 23:43:52 +00:00
|
|
|
|
|
|
|
debugC(3, kDebugLevelText, "f15==0, v21==%d => timed", getvar(21));
|
2007-01-16 12:40:51 +00:00
|
|
|
_game.msgBoxTicks = getvar(vWindowReset) * 10;
|
|
|
|
setvar(vKey, 0);
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2009-06-06 17:43:51 +00:00
|
|
|
_menuSelected = false;
|
|
|
|
|
2006-05-23 23:43:52 +00:00
|
|
|
do {
|
2009-05-19 21:09:43 +00:00
|
|
|
if (getflag(fRestoreJustRan))
|
|
|
|
break;
|
|
|
|
|
2009-06-06 17:43:51 +00:00
|
|
|
if (_menuSelected)
|
|
|
|
break;
|
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
mainCycle();
|
|
|
|
if (_game.keypress == KEY_ENTER) {
|
2006-05-23 23:43:52 +00:00
|
|
|
debugC(4, kDebugLevelText, "KEY_ENTER");
|
2007-01-16 12:40:51 +00:00
|
|
|
setvar(vWindowReset, 0);
|
|
|
|
_game.keypress = 0;
|
2006-05-23 23:43:52 +00:00
|
|
|
break;
|
|
|
|
}
|
2010-06-15 18:17:51 +00:00
|
|
|
} while (_game.msgBoxTicks > 0 && !(shouldQuit() || _restartGame));
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
setvar(vWindowReset, 0);
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
closeWindow();
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2009-06-06 17:42:37 +00:00
|
|
|
_noSaveLoadAllowed = false;
|
2009-05-21 21:51:50 +00:00
|
|
|
|
2006-05-23 23:43:52 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2007-01-16 12:40:51 +00:00
|
|
|
void AgiEngine::printStatus(const char *message, ...) {
|
2006-05-23 23:43:52 +00:00
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start(args, message);
|
|
|
|
|
2011-03-18 13:41:40 +00:00
|
|
|
Common::String x = Common::String::vformat(message, args);
|
2006-05-23 23:43:52 +00:00
|
|
|
|
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
debugC(4, kDebugLevelText, "fg=%d, bg=%d", STATUS_FG, STATUS_BG);
|
2011-03-18 13:41:40 +00:00
|
|
|
printText(x.c_str(), 0, 0, _game.lineStatus, 40, STATUS_FG, STATUS_BG);
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
|
|
|
|
2009-10-21 01:23:05 +00:00
|
|
|
static void safeStrcat(Common::String &p, const char *t) {
|
2006-05-23 23:43:52 +00:00
|
|
|
if (t != NULL)
|
2009-10-20 12:23:21 +00:00
|
|
|
p += t;
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Formats AGI string.
|
|
|
|
* This function turns a AGI string into a real string expanding values
|
|
|
|
* according to the AGI format specifiers.
|
|
|
|
* @param s string containing the format specifier
|
|
|
|
* @param n logic number
|
|
|
|
*/
|
2007-01-16 12:40:51 +00:00
|
|
|
char *AgiEngine::agiSprintf(const char *s) {
|
2009-10-20 12:23:21 +00:00
|
|
|
static char agiSprintf_buf[768];
|
|
|
|
Common::String p;
|
|
|
|
char z[16];
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
debugC(3, kDebugLevelText, "logic %d, '%s'", _game.lognum, s);
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2009-10-20 12:23:21 +00:00
|
|
|
while (*s) {
|
2006-05-23 23:43:52 +00:00
|
|
|
switch (*s) {
|
|
|
|
case '%':
|
|
|
|
s++;
|
|
|
|
switch (*s++) {
|
|
|
|
int i;
|
|
|
|
case 'v':
|
|
|
|
i = strtoul(s, NULL, 10);
|
|
|
|
while (*s >= '0' && *s <= '9')
|
|
|
|
s++;
|
|
|
|
sprintf(z, "%015i", getvar(i));
|
|
|
|
|
|
|
|
i = 99;
|
|
|
|
if (*s == '|') {
|
|
|
|
s++;
|
|
|
|
i = strtoul(s, NULL, 10);
|
|
|
|
while (*s >= '0' && *s <= '9')
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == 99) {
|
2009-06-06 17:39:13 +00:00
|
|
|
// remove all leading 0
|
|
|
|
// don't remove the 3rd zero if 000
|
2009-01-29 05:26:12 +00:00
|
|
|
for (i = 0; z[i] == '0' && i < 14; i++)
|
2011-02-07 23:01:06 +00:00
|
|
|
;
|
2006-05-23 23:43:52 +00:00
|
|
|
} else {
|
|
|
|
i = 15 - i;
|
|
|
|
}
|
2007-01-16 12:40:51 +00:00
|
|
|
safeStrcat(p, z + i);
|
2006-05-23 23:43:52 +00:00
|
|
|
break;
|
|
|
|
case '0':
|
|
|
|
i = strtoul(s, NULL, 10) - 1;
|
2007-01-16 12:40:51 +00:00
|
|
|
safeStrcat(p, objectName(i));
|
2006-05-23 23:43:52 +00:00
|
|
|
break;
|
|
|
|
case 'g':
|
|
|
|
i = strtoul(s, NULL, 10) - 1;
|
2007-01-16 12:40:51 +00:00
|
|
|
safeStrcat(p, _game.logics[0].texts[i]);
|
2006-05-23 23:43:52 +00:00
|
|
|
break;
|
|
|
|
case 'w':
|
|
|
|
i = strtoul(s, NULL, 10) - 1;
|
2007-01-16 12:40:51 +00:00
|
|
|
safeStrcat(p, _game.egoWords[i].word);
|
2006-05-23 23:43:52 +00:00
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
i = strtoul(s, NULL, 10);
|
2007-07-27 12:59:41 +00:00
|
|
|
safeStrcat(p, agiSprintf(_game.strings[i]));
|
2006-05-23 23:43:52 +00:00
|
|
|
break;
|
|
|
|
case 'm':
|
|
|
|
i = strtoul(s, NULL, 10) - 1;
|
2007-01-16 12:40:51 +00:00
|
|
|
if (_game.logics[_game.lognum].numTexts > i)
|
2009-10-20 12:23:21 +00:00
|
|
|
safeStrcat(p, agiSprintf(_game.logics[_game.lognum].texts[i]));
|
2006-05-23 23:43:52 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (*s >= '0' && *s <= '9')
|
|
|
|
s++;
|
|
|
|
break;
|
|
|
|
|
2009-10-20 12:23:21 +00:00
|
|
|
case '\\':
|
|
|
|
s++;
|
|
|
|
// FALL THROUGH
|
|
|
|
|
2006-05-23 23:43:52 +00:00
|
|
|
default:
|
2009-10-20 12:23:21 +00:00
|
|
|
p += *s++;
|
2006-05-23 23:43:52 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-21 01:01:23 +00:00
|
|
|
assert(p.size() < sizeof(agiSprintf_buf));
|
2009-10-20 12:23:21 +00:00
|
|
|
strcpy(agiSprintf_buf, p.c_str());
|
|
|
|
return agiSprintf_buf;
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Write the status line.
|
|
|
|
*/
|
2007-01-16 12:40:51 +00:00
|
|
|
void AgiEngine::writeStatus() {
|
2006-05-23 23:43:52 +00:00
|
|
|
char x[64];
|
|
|
|
|
2006-12-06 19:27:02 +00:00
|
|
|
if (_debug.statusline) {
|
2007-01-16 12:40:51 +00:00
|
|
|
printStatus("%3d(%03d) %3d,%3d(%3d,%3d) ",
|
|
|
|
getvar(0), getvar(1), _game.viewTable[0].xPos,
|
2009-10-20 11:13:00 +00:00
|
|
|
_game.viewTable[0].yPos, WIN_TO_PIC_X(_mouse.x),
|
|
|
|
WIN_TO_PIC_Y(_mouse.y));
|
2006-05-23 23:43:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
if (!_game.statusLine) {
|
2008-02-22 09:13:27 +00:00
|
|
|
clearLines(_game.lineStatus, _game.lineStatus, 0);
|
|
|
|
flushLines(_game.lineStatus, _game.lineStatus);
|
|
|
|
|
2009-06-06 17:40:27 +00:00
|
|
|
#if 0
|
|
|
|
// FIXME: Breaks wrist watch prompt in SQ2
|
|
|
|
|
2008-02-22 09:13:27 +00:00
|
|
|
// Clear the user input line as well when clearing the status line
|
|
|
|
// Fixes bug #1893564 - AGI: Texts messed out in Naturette 1
|
|
|
|
clearLines(_game.lineUserInput, _game.lineUserInput, 0);
|
|
|
|
flushLines(_game.lineUserInput, _game.lineUserInput);
|
2009-06-06 17:40:27 +00:00
|
|
|
#endif
|
2006-05-23 23:43:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-09-23 16:43:43 +00:00
|
|
|
switch (getLanguage()) {
|
|
|
|
case Common::RU_RUS:
|
|
|
|
sprintf(x, " \x91\xe7\xa5\xe2: %i \xa8\xa7 %-3i", _game.vars[vScore], _game.vars[vMaxScore]);
|
|
|
|
printStatus("%-17s \x87\xa2\xe3\xaa:%s", x, getflag(fSoundOn) ? "\xa2\xaa\xab " : "\xa2\xeb\xaa\xab");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
sprintf(x, " Score:%i of %-3i", _game.vars[vScore], _game.vars[vMaxScore]);
|
|
|
|
printStatus("%-17s Sound:%s ", x, getflag(fSoundOn) ? "on " : "off");
|
|
|
|
break;
|
|
|
|
}
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Print user input prompt.
|
|
|
|
*/
|
2007-01-16 12:40:51 +00:00
|
|
|
void AgiEngine::writePrompt() {
|
2006-05-23 23:43:52 +00:00
|
|
|
int l, fg, bg, pos;
|
2008-04-10 21:58:59 +00:00
|
|
|
int promptLength = strlen(agiSprintf(_game.strings[0]));
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2010-06-15 10:27:42 +00:00
|
|
|
if (!_game.inputEnabled || _game.inputMode != INPUT_NORMAL)
|
2006-05-23 23:43:52 +00:00
|
|
|
return;
|
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
l = _game.lineUserInput;
|
|
|
|
fg = _game.colorFg;
|
|
|
|
bg = _game.colorBg;
|
|
|
|
pos = _game.cursorPos;
|
2006-05-23 23:43:52 +00:00
|
|
|
|
|
|
|
debugC(4, kDebugLevelText, "erase line %d", l);
|
2007-01-16 12:40:51 +00:00
|
|
|
clearLines(l, l, _game.colorBg);
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
debugC(4, kDebugLevelText, "prompt = '%s'", agiSprintf(_game.strings[0]));
|
2008-04-10 21:58:59 +00:00
|
|
|
printText(_game.strings[0], 0, 0, l, promptLength + 1, fg, bg);
|
|
|
|
printText((char *)_game.inputBuffer, 0, promptLength, l, pos + 1, fg, bg);
|
|
|
|
_gfx->printCharacter(pos + promptLength, l, _game.cursorChar, fg, bg);
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
flushLines(l, l);
|
2006-12-06 19:27:02 +00:00
|
|
|
_gfx->doUpdate();
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
|
|
|
|
2011-09-25 21:11:45 +00:00
|
|
|
void AgiEngine::clearPrompt(bool useBlackBg) {
|
2009-06-06 17:40:09 +00:00
|
|
|
int l;
|
|
|
|
|
|
|
|
l = _game.lineUserInput;
|
2011-09-25 21:11:45 +00:00
|
|
|
clearLines(l, l, useBlackBg ? 0 : _game.colorBg);
|
2009-06-06 17:40:09 +00:00
|
|
|
flushLines(l, l);
|
|
|
|
|
|
|
|
_gfx->doUpdate();
|
|
|
|
}
|
|
|
|
|
2006-05-23 23:43:52 +00:00
|
|
|
/**
|
|
|
|
* Clear text lines in the screen.
|
|
|
|
* @param l1 start line
|
|
|
|
* @param l2 end line
|
|
|
|
* @param c color
|
|
|
|
*/
|
2007-01-16 12:40:51 +00:00
|
|
|
void AgiEngine::clearLines(int l1, int l2, int c) {
|
2009-06-06 17:39:13 +00:00
|
|
|
// do we need to adjust for +8 on topline?
|
|
|
|
// inc for endline so it matches the correct num
|
|
|
|
// ie, from 22 to 24 is 3 lines, not 2 lines.
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2010-06-15 10:27:23 +00:00
|
|
|
debugC(4, kDebugLevelText, "clearLines(%d, %d, %d)", l1, l2, c);
|
|
|
|
|
2006-05-23 23:43:52 +00:00
|
|
|
l1 *= CHAR_LINES;
|
|
|
|
l2 *= CHAR_LINES;
|
|
|
|
l2 += CHAR_LINES - 1;
|
|
|
|
|
2006-12-06 19:27:02 +00:00
|
|
|
_gfx->drawRectangle(0, l1, GFX_WIDTH - 1, l2, c);
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2007-01-16 12:40:51 +00:00
|
|
|
void AgiEngine::flushLines(int l1, int l2) {
|
2006-05-23 23:43:52 +00:00
|
|
|
l1 *= CHAR_LINES;
|
|
|
|
l2 *= CHAR_LINES;
|
|
|
|
l2 += CHAR_LINES - 1;
|
|
|
|
|
2006-12-06 19:27:02 +00:00
|
|
|
_gfx->flushBlock(0, l1, GFX_WIDTH - 1, l2);
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2007-01-16 12:40:51 +00:00
|
|
|
void AgiEngine::drawWindow(int x1, int y1, int x2, int y2) {
|
|
|
|
_game.window.active = true;
|
|
|
|
_game.window.x1 = x1;
|
|
|
|
_game.window.y1 = y1;
|
|
|
|
_game.window.x2 = x2;
|
|
|
|
_game.window.y2 = y2;
|
|
|
|
_game.window.buffer = (uint8 *)malloc((x2 - x1 + 1) * (y2 - y1 + 1));
|
2006-05-23 23:43:52 +00:00
|
|
|
|
|
|
|
debugC(4, kDebugLevelText, "x1=%d, y1=%d, x2=%d, y2=%d", x1, y1, x2, y2);
|
2007-01-16 12:40:51 +00:00
|
|
|
_gfx->saveBlock(x1, y1, x2, y2, _game.window.buffer);
|
2011-04-14 12:12:27 +00:00
|
|
|
_gfx->drawBox(x1, y1, x2, y2, MSG_BOX_COLOR, MSG_BOX_LINE, 2);
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
|
|
|
|
2011-09-25 15:47:17 +00:00
|
|
|
} // End of namespace Agi
|