Permalink
Browse files

STARTREK: Action menu

  • Loading branch information...
Drenn1 authored and sev- committed May 16, 2018
1 parent 2731ae2 commit 2120ce106210538c9508be1e275bdba97ddda63a
@@ -84,7 +84,7 @@ void StarTrekEngine::loadRoom(const Common::String &missionName, int roomIndex)
// Original sets up bytes 0-3 of rdf file as "remote function caller"

// Load map file
_awayMission.mapFileLoaded = 1;
_awayMission.activeAction = ACTION_WALK;
_mapFilename = _screenName;
_mapFile = loadFile(_mapFilename + ".map");
_iwFile = SharedPtr<IWFile>(new IWFile(this, _mapFilename + ".iw"));
@@ -161,7 +161,7 @@ void StarTrekEngine::handleAwayMissionEvents() {
// doSomethingWithBanData1();
_gfx->drawAllSprites();
// doSomethingWithBanData2();
// updateMusic(); // Is this needed?
_sound->checkLoopMusic();
// sub_22de0();
_frameIndex++;
_roomFrameCounter++;
@@ -172,7 +172,7 @@ void StarTrekEngine::handleAwayMissionEvents() {
case TREKEVENT_LBUTTONDOWN:
if (_awayMission.transitioningIntoRoom != 0)
break;
switch (_awayMission.mapFileLoaded) {
switch (_awayMission.activeAction) {
case 1:
if (_awayMission.field1c == 0) {
_kirkObject->sprite.drawMode = 1; // Hide these objects for function call below?
@@ -205,7 +205,35 @@ void StarTrekEngine::handleAwayMissionEvents() {
break;
case TREKEVENT_MOUSEMOVE:
break;
case TREKEVENT_RBUTTONDOWN:
case TREKEVENT_RBUTTONDOWN: // TODO: also triggered by key press?
/*
if (_awayMission.field1d)
break;
*/
//sub_2394b();
playSoundEffectIndex(0x07);
_awayMission.activeAction = showActionMenu();
/*
if (awayMission.activeAction == ACTION_USE) {
int16 clickedObject = sub_22f08();
if (clickedObject == -1)
break;
else
_awayMission.field20 = clickedObject;
}
if (_awayMission.activeAction == ACTION_USE
&& _awayMission.field20 == 0x47 && (_awayMission.field24 & 1) == 0) {
if (sub_2330c() == 0) {
addCommand(Command(_awayMission.activeAction, _awayMission.field20, 0, 0));
_sound->playVoc("communic");
_awayMission.activeAction = ACTION_WALK;
}
}
else if (_awayMission.activeAction == ACTION_LOOK)
sub_2383a(0);
else if (_awayMission.activeAction == ACTION_USE && (_awayMission.field24 & 1) == 0)
sub_2383a(1);
*/
break;
case TREKEVENT_KEYDOWN:
break;
@@ -28,9 +28,11 @@ struct AwayMission {
int16 mouseX;
int16 mouseY;
byte field1c;
byte field1d;
byte transitioningIntoRoom; // Set while beaming in or walking into a room
bool redshirtDead;
byte mapFileLoaded;
byte activeAction;
byte field20;
byte field24;
int8 field25[4];

@@ -40,17 +40,30 @@ void StarTrekEngine::pollSystemEvents() {
trekEvent.type = TREKEVENT_MOUSEMOVE;
addEventToQueue(trekEvent);
break;

case Common::EVENT_LBUTTONDOWN:
// TODO: what happens when mouse click is outside normal screen bounds?
// (apparently this can happen)
trekEvent.type = TREKEVENT_LBUTTONDOWN;
addEventToQueue(trekEvent);
break;

case Common::EVENT_RBUTTONDOWN:
trekEvent.type = TREKEVENT_RBUTTONDOWN;
addEventToQueue(trekEvent);
break;

case Common::EVENT_KEYDOWN:
trekEvent.type = TREKEVENT_KEYDOWN;
addEventToQueue(trekEvent);
break;

default:
break;
}
}

// TODO: check for events other than "tick" more often.
if (_eventQueue.empty()) {
int delay = 1000/18.206 - (_system->getMillis() - _frameStartMillis);

@@ -51,8 +51,9 @@ Graphics::Graphics(StarTrekEngine *vm) : _vm(vm), _egaMode(false) {
_lutData = new byte[256 * 3];

_paletteFadeLevel = 0;
_mouseLocked = false;

setMouseCursor(loadBitmap("pushbtn"));
setMouseBitmap(loadBitmap("pushbtn"));
CursorMan.showMouse(true);
}

@@ -180,9 +181,58 @@ Common::Point Graphics::getMousePos() {
return _vm->_system->getEventManager()->getMousePos();
}

void Graphics::setMouseCursor(SharedPtr<Bitmap> bitmap) {
void Graphics::setMouseBitmap(SharedPtr<Bitmap> bitmap) {
_mouseBitmap = bitmap;
_vm->_system->setMouseCursor(bitmap->pixels, bitmap->width, bitmap->height, bitmap->xoffset, bitmap->yoffset, 0);

if (_mouseLocked) {
_lockedMouseSprite.setBitmap(_mouseBitmap);
drawAllSprites(false);
}
}

/**
* This function is a workaround for when the mouse position needs to be locked in a set
* position (used in the action menu). This only affects the position it is drawn at; the
* sprite's "real" position is still updated normally.
*
* This does not call updateScreen.
*/
void Graphics::lockMousePosition(int16 x, int16 y) {
if (_mouseLocked) {
if (x != _lockedMouseSprite.pos.x || y != _lockedMouseSprite.pos.y) {
_lockedMouseSprite.pos.x = x;
_lockedMouseSprite.pos.y = y;
_lockedMouseSprite.bitmapChanged = true;
drawAllSprites(false);
}
return;
}

CursorMan.showMouse(false);
_mouseLocked = true;

_lockedMouseSprite = Sprite();
_lockedMouseSprite.setBitmap(_mouseBitmap);
_lockedMouseSprite.drawPriority = 15;
_lockedMouseSprite.drawPriority2 = 16;
_lockedMouseSprite.pos.x = x;
_lockedMouseSprite.pos.y = y;

addSprite(&_lockedMouseSprite);
drawAllSprites(false);
}

void Graphics::unlockMousePosition() {
if (!_mouseLocked)
return;

_mouseLocked = false;
CursorMan.showMouse(true);

_lockedMouseSprite.dontDrawNextFrame();
drawAllSprites();
delSprite(&_lockedMouseSprite);
}

void Graphics::drawSprite(const Sprite &sprite) {
@@ -340,14 +390,14 @@ void Graphics::drawSprite(const Sprite &sprite, const Common::Rect &rect) {
bool compareSpritesByLayer(Sprite *s1, Sprite *s2) {
if (s1->drawPriority != s2->drawPriority)
return s1->drawPriority < s2->drawPriority;
if (s1->field6 != s2->field6)
return s1->field6 < s2->field6;
if (s1->drawPriority2 != s2->drawPriority2)
return s1->drawPriority2 < s2->drawPriority2;
if (s1->pos.y != s2->pos.y)
return s1->pos.y < s2->pos.y;
return s1->pos.x < s2->pos.x;
}

void Graphics::drawAllSprites() {
void Graphics::drawAllSprites(bool updateScreen) {
// TODO: different video modes?

if (_numSprites == 0)
@@ -458,7 +508,8 @@ void Graphics::drawAllSprites() {
spr->lastDrawRect = spr->drawRect;
}

_vm->_system->updateScreen();
if (updateScreen)
_vm->_system->updateScreen();
}

void Graphics::addSprite(Sprite *sprite) {
@@ -67,11 +67,13 @@ class Graphics {
SharedPtr<Bitmap> loadBitmap(String basename);

Common::Point getMousePos();
void setMouseCursor(SharedPtr<Bitmap> bitmap);
void setMouseBitmap(SharedPtr<Bitmap> bitmap);
void lockMousePosition(int16 x, int16 y);
void unlockMousePosition();

void drawSprite(const Sprite &sprite);
void drawSprite(const Sprite &sprite, const Common::Rect &rect);
void drawAllSprites();
void drawAllSprites(bool updateScreen=true);

void addSprite(Sprite *sprite);
void delSprite(Sprite *sprite);
@@ -100,6 +102,11 @@ class Graphics {
Sprite *_sprites[MAX_SPRITES];
int _numSprites;

// These are used as a workaround for when the mouse position must be locked.
// The mouse is turned into a native game sprite when this happens.
bool _mouseLocked;
Sprite _lockedMouseSprite;

public:
SharedPtr<Bitmap> _mouseBitmap;
};
Oops, something went wrong.

0 comments on commit 2120ce1

Please sign in to comment.