Permalink
Browse files

STARTREK: Begin implementing event system.

Textbox now responds to mouse input.
  • Loading branch information...
Drenn1 authored and sev- committed Mar 11, 2018
1 parent 295c55c commit fd26d0a790342b086fc9430d3cb9d4449104e6ce
@@ -0,0 +1,94 @@
/* 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.
*/

#include "startrek/startrek.h"

namespace StarTrek {

void StarTrekEngine::initializeEventsAndMouse() {
_mouseMoveEventInQueue = false;
_tickEventInQueue = false;

// TODO: mouse
}

/**
* Returns false if there is no event waiting.
*/
bool StarTrekEngine::getNextEvent(TrekEvent *e) {
pollSystemEvents(); // TODO: put this somewhere else?

if (_eventQueue.empty())
return false;
*e = _eventQueue.front();
return true;
}

void StarTrekEngine::removeNextEvent() {
if (_eventQueue.empty())
return;

const TrekEvent &e = _eventQueue.front();

if (e.type == TREKEVENT_MOUSEMOVE)
_mouseMoveEventInQueue = false;
if (e.type == TREKEVENT_TICK)
_tickEventInQueue = false;

_eventQueue.pop_front();
}

bool StarTrekEngine::popNextEvent(TrekEvent *e) {
if (!getNextEvent(e))
return false;

removeNextEvent();
return true;
}

void StarTrekEngine::addEventToQueue(const TrekEvent &e) {
if (e.type == TREKEVENT_MOUSEMOVE && _mouseMoveEventInQueue) {
// Only allow one mouse move event at once
for (Common::List<TrekEvent>::iterator i = _eventQueue.begin(); i!=_eventQueue.end(); i++) {
if (i->type == TREKEVENT_MOUSEMOVE) {
*i = e;
return;
}
}

error("Couldn't find mouse move event in eventQueue");
}

if (e.type == TREKEVENT_TICK) {
// Only allow one tick event at once
if (_tickEventInQueue)
return;
_tickEventInQueue = true;
}

if (e.type == TREKEVENT_MOUSEMOVE)
_mouseMoveEventInQueue = true;

assert(_eventQueue.size() < 0x40);
_eventQueue.push_back(e);
}

}
@@ -47,23 +47,24 @@ const int MAX_SPRITES = 32;
const int MAX_MENUBUTTONS = 16; // This is arbitrary, the original game has no such limit

const int TEXTBOX_WIDTH = 26;
const int MAX_TEXTBOX_LINES = 12;


// Keeps track of data for a list of buttons making up a menu
struct Menu {
Sprite sprites[MAX_MENUBUTTONS];
uint16 retvals[MAX_MENUBUTTONS];
uint16 buttonVar2;
uint32 disabledButtons;
SharedPtr<FileStream> menuFile;
uint16 numButtons;
uint16 buttonVar1;
int16 selectedButton;
SharedPtr<Menu> nextMenu;

Menu() : nextMenu(SharedPtr<Menu>()) {}
};

class Graphics;
typedef String (Graphics::*TextGetterFunc)(int, int, String *);
typedef String (Graphics::*TextGetterFunc)(int, void *, String *);


class Graphics {
@@ -115,11 +116,12 @@ class Graphics {
// text.cpp (TODO: separate class)
public:
int showText(TextGetterFunc textGetter, int var, int xoffset, int yoffset, int textColor, bool loopChoices, int maxTextLines, int arg10);
String tmpFunction(int choiceIndex, int var, String *headerTextOutput);
String readTextFromRdf(int choiceIndex, int rdfVar, String *headerTextOutput);

String readTextFromRdf(int choiceIndex, void *data, String *headerTextOutput);
String readTextFromBuffer(int choiceIndex, void *data, String *headerTextOutput);

private:
int handleTextboxEvents(uint32 arg0, bool arg4);
int handleTextboxEvents(uint32 ticksUntilClickingEnabled, bool arg4);

SharedPtr<TextBitmap> initTextSprite(int *xoffsetPtr, int *yoffsetPtr, byte textColor, int numTextLines, bool withHeader, Sprite *sprite);
void drawMainText(SharedPtr<TextBitmap> bitmap, int numTextLines, int numTextboxLines, const String &text, bool withHeader);
@@ -134,20 +136,24 @@ class Graphics {
String skipTextAudioPrompt(const String &str);
String playTextAudio(const String &str);

int getMenuButtonAt(const Menu &menu, int x, int y);
void drawMenuButtonOutline(SharedPtr<Bitmap> bitmap, byte color);
void loadMenuButtons(String mnuFilename, int xpos, int ypos);
void setMenuButtonVar2Bits(uint32 bits);
void clearMenuButtonVar2Bits(uint32 bits);


uint16 _textboxVar1;
uint32 _textboxVar2;
uint32 _textboxVar3;
uint16 _textboxVar4;
uint16 _textboxVar5;
uint16 _textboxVar6;
uint16 _textboxVar7;
bool _textboxHasMultipleChoices;

SharedPtr<Menu> _activeMenu;

uint16 _textboxButtonVar4;
uint16 _word_4B422;
};

}
@@ -4,6 +4,7 @@ MODULE_OBJS = \
bitmap.o \
common.o \
detection.o \
events.o \
filestream.o \
font.o \
lzss.o \
@@ -55,6 +55,9 @@ StarTrekEngine::~StarTrekEngine() {
}

Common::Error StarTrekEngine::run() {
_cdAudioEnabled = true;
_midiAudioEnabled = true;

_gfx = new Graphics(this);
_sound = new Sound(this);

@@ -66,6 +69,8 @@ Common::Error StarTrekEngine::run() {
}

initGraphics(320, 200);

initializeEventsAndMouse();

// Hexdump data
#if 0
@@ -151,21 +156,38 @@ Common::Error StarTrekEngine::run() {
_gfx->showText(&Graphics::readTextFromRdf, 0x2220, 150, 160, 0xb3, 0, 10, 0);

while (!shouldQuit()) {
pollEvents();
pollSystemEvents();
}
#endif

return Common::kNoError;
}

void StarTrekEngine::pollEvents() {
Room *StarTrekEngine::getRoom() {
return _room;
}

void StarTrekEngine::pollSystemEvents() {
Common::Event event;
TrekEvent trekEvent;

while (_eventMan->pollEvent(event)) {
trekEvent.mouse = event.mouse;
trekEvent.kbd = event.kbd;

switch (event.type) {
case Common::EVENT_QUIT:
_system->quit();
break;

case Common::EVENT_MOUSEMOVE:
trekEvent.type = TREKEVENT_MOUSEMOVE;
addEventToQueue(trekEvent);
break;
case Common::EVENT_LBUTTONDOWN:
trekEvent.type = TREKEVENT_LBUTTONDOWN;
addEventToQueue(trekEvent);
break;
default:
break;
}
@@ -175,8 +197,14 @@ void StarTrekEngine::pollEvents() {
_system->delayMillis(1000/60);
}

Room *StarTrekEngine::getRoom() {
return _room;
void StarTrekEngine::playSound(int id) {
// TODO
}

void StarTrekEngine::updateClockTicks() {
// TODO (based on DOS interrupt 1A, AH=0; read system clock counter)

_clockTicks = 0;
}

SharedPtr<FileStream> StarTrekEngine::openFile(Common::String filename, int fileIndex) {
@@ -17,15 +17,13 @@
* 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.
*
* $URL: https://scummvm-startrek.googlecode.com/svn/trunk/startrek.h $
* $Id: startrek.h 14 2010-05-26 15:44:12Z clone2727 $
*
*/

#ifndef STARTREK_H
#define STARTREK_H

#include "common/events.h"
#include "common/list.h"
#include "common/ptr.h"
#include "common/rect.h"
#include "common/scummsys.h"
@@ -59,6 +57,24 @@ enum StarTrekGameFeatures {
GF_DEMO = (1 << 0)
};


enum TrekEventType {
TREKEVENT_TICK = 0, // DOS clock changes (see updateClockTicks)
TREKEVENT_LBUTTONDOWN = 1,
TREKEVENT_MOUSEMOVE = 2,
TREKEVENT_LBUTTONUP = 3,
TREKEVENT_RBUTTONDOWN = 4,
TREKEVENT_RBUTTONUP = 5,
TREKEVENT_KEYDOWN = 6
};

struct TrekEvent {
TrekEventType type;
Common::KeyState kbd;
Common::Point mouse;
uint32 tick;
};

struct StarTrekGameDescription;
class Graphics;
class Sound;
@@ -72,9 +88,35 @@ class StarTrekEngine : public ::Engine {
virtual ~StarTrekEngine();

// Running the game
void pollEvents();
Room *getRoom();
void pollSystemEvents();

void playSound(int id); // TODO: rename, figure out what it is

// Events
public:
void initializeEventsAndMouse();
bool getNextEvent(TrekEvent *e);
void removeNextEvent();
bool popNextEvent(TrekEvent *e);
void addEventToQueue(const TrekEvent &e);
void clearEventBuffer();
uint32 getClockTicks();
void updateEvents();
void updateTimerEvent();
void updateMouseEvents();
void updateKeyboardEvents();
void updateClockTicks();
bool checkKeyPressed();

Common::EventManager *getEventMan() { return _eventMan; }

private:
Common::List<TrekEvent> _eventQueue;
bool _mouseMoveEventInQueue;
bool _tickEventInQueue;

public:
// Detection related functions
const StarTrekGameDescription *_gameDescription;
uint32 getFeatures() const;
@@ -89,6 +131,14 @@ class StarTrekEngine : public ::Engine {
// Movie related functions
void playMovie(Common::String filename);
void playMovieMac(Common::String filename);


uint32 _clockTicks;

bool _midiAudioEnabled;
bool _cdAudioEnabled;
bool _textboxVar4;


private:
Graphics *_gfx;
Oops, something went wrong.

0 comments on commit fd26d0a

Please sign in to comment.