mirror of
https://github.com/libretro/scummvm.git
synced 2025-01-25 04:01:03 +00:00
GLK: COMPREHEND: Adding method for reading text
This commit is contained in:
parent
e55aaa91da
commit
51ff674d99
@ -163,16 +163,16 @@ void Comprehend::runGame() {
|
||||
}
|
||||
|
||||
void Comprehend::initialize() {
|
||||
_textBufferWindow = (TextBufferWindow *)glk_window_open(0, 0, 0, wintype_TextBuffer, 1);
|
||||
_graphicsWindow = (GraphicsWindow *)glk_window_open(
|
||||
_textBufferWindow, winmethod_Above | winmethod_Proportional,
|
||||
160, wintype_Graphics, 0);
|
||||
glk_set_window(_textBufferWindow);
|
||||
_topWindow = (GraphicsWindow *)glk_window_open(0, 0, 0, wintype_Graphics, 1);
|
||||
_bottomWindow = (TextBufferWindow *)glk_window_open(
|
||||
_topWindow, winmethod_Below | winmethod_Fixed,
|
||||
80, wintype_TextBuffer, 0);
|
||||
glk_set_window(_bottomWindow);
|
||||
}
|
||||
|
||||
void Comprehend::deinitialize() {
|
||||
glk_window_close(_graphicsWindow);
|
||||
glk_window_close(_textBufferWindow);
|
||||
glk_window_close(_topWindow);
|
||||
glk_window_close(_bottomWindow);
|
||||
}
|
||||
|
||||
ComprehendGame *Comprehend::createGame() {
|
||||
@ -194,9 +194,27 @@ void Comprehend::print(const char *fmt, ...) {
|
||||
Common::String msg = Common::String::vformat(fmt, argp);
|
||||
va_end(argp);
|
||||
|
||||
glk_put_string_stream(glk_window_get_stream(_textBufferWindow),
|
||||
glk_put_string_stream(glk_window_get_stream(_bottomWindow),
|
||||
msg.c_str());
|
||||
}
|
||||
|
||||
void Comprehend::readLine(char *buffer, size_t maxLen) {
|
||||
event_t ev;
|
||||
|
||||
glk_request_line_event(_bottomWindow, buffer, maxLen - 1, 0);
|
||||
|
||||
for (;;) {
|
||||
glk_select(&ev);
|
||||
if (ev.type == evtype_Quit) {
|
||||
glk_cancel_line_event(_bottomWindow, &ev);
|
||||
return;
|
||||
} else if (ev.type == evtype_LineInput)
|
||||
break;
|
||||
}
|
||||
|
||||
buffer[ev.val1] = 0;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Comprehend
|
||||
} // namespace Glk
|
||||
|
@ -55,8 +55,8 @@ class Comprehend : public GlkAPI {
|
||||
private:
|
||||
int _saveSlot; ///< Save slot when loading savegame from launcher
|
||||
public:
|
||||
GraphicsWindow *_graphicsWindow;
|
||||
TextBufferWindow *_textBufferWindow;
|
||||
GraphicsWindow *_topWindow;
|
||||
TextBufferWindow *_bottomWindow;
|
||||
private:
|
||||
/**
|
||||
* Initialization code
|
||||
@ -103,7 +103,15 @@ public:
|
||||
return Common::kWritingFailed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Print string to the buffer window
|
||||
*/
|
||||
void print(const char *fmt, ...);
|
||||
|
||||
/**
|
||||
* Read an input line
|
||||
*/
|
||||
void readLine(char *buffer, size_t maxLen);
|
||||
};
|
||||
|
||||
extern Comprehend *g_comprehend;
|
||||
|
@ -158,29 +158,12 @@ void TransylvaniaGame::handle_special_opcode(uint8 operand)
|
||||
}
|
||||
}
|
||||
|
||||
static void read_string(char *buffer, size_t size)
|
||||
{
|
||||
#ifdef TODO
|
||||
char *p;
|
||||
|
||||
printf("> ");
|
||||
fgets(buffer, size, stdin);
|
||||
|
||||
/* Remove trailing newline */
|
||||
p = strchr(buffer, '\n');
|
||||
if (p)
|
||||
*p = '\0';
|
||||
#else
|
||||
error("TODO");
|
||||
#endif
|
||||
}
|
||||
|
||||
void TransylvaniaGame::before_game() {
|
||||
char buffer[128];
|
||||
|
||||
/* Welcome to Transylvania - sign your name */
|
||||
// Welcome to Transylvania - sign your name
|
||||
console_println(this, _strings.strings[0x20]);
|
||||
read_string(buffer, sizeof(buffer));
|
||||
g_comprehend->readLine(buffer, sizeof(buffer));
|
||||
|
||||
/*
|
||||
* Transylvania uses replace word 0 as the player's name, the game
|
||||
@ -195,9 +178,9 @@ void TransylvaniaGame::before_game() {
|
||||
strlen(_replaceWords[0]),
|
||||
"%s", buffer);
|
||||
|
||||
/* And your next of kin - This isn't store by the game */
|
||||
// And your next of kin - This isn't stored by the game
|
||||
console_println(this, _strings.strings[0x21]);
|
||||
read_string(buffer, sizeof(buffer));
|
||||
g_comprehend->readLine(buffer, sizeof(buffer));
|
||||
}
|
||||
|
||||
} // namespace Comprehend
|
||||
|
Loading…
x
Reference in New Issue
Block a user