Skip to content

Commit

Permalink
PINK: basic walk, left click and seqTimer implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
voltya authored and sev- committed Jun 28, 2018
1 parent 4b7c756 commit cad72b1
Show file tree
Hide file tree
Showing 36 changed files with 680 additions and 86 deletions.
2 changes: 1 addition & 1 deletion engines/pink/cursor_mgr.cpp
Expand Up @@ -68,7 +68,7 @@ void CursorMgr::setCursor(Common::String &cursorName, Common::Point point) {
else if (cursorName == "ExitRight"){
index = kExitRightCursor;
}
else if (cursorName == "ExitForward")
else if (cursorName == "ExitForward" || cursorName == "ExitUp")
index = kExitForwardCursor;
else assert(0);
setCursor(index, point);
Expand Down
7 changes: 4 additions & 3 deletions engines/pink/director.cpp
Expand Up @@ -42,11 +42,12 @@ void Director::draw() {
void Director::drawSprite(ActionCEL *sprite) {
CelDecoder *decoder = sprite->getDecoder();
const Graphics::Surface *surface;
if (decoder->needsUpdate())
if (decoder->needsUpdate()) {

surface = decoder->decodeNextFrame();
}
else surface = decoder->getCurrentFrame();


if (!showBounds) {
Graphics::Surface *screen = _system->lockScreen();

Expand Down Expand Up @@ -116,7 +117,7 @@ void Director::clear() {
}

Actor *Director::getActorByPoint(Common::Point point) {
for (int i = _sprites.size() - 1; i > 0; --i) {
for (int i = _sprites.size() - 1; i >= 0; --i) {
CelDecoder *decoder = _sprites[i]->getDecoder();
const Graphics::Surface *frame = decoder->getCurrentFrame();
Common::Rect &rect = decoder->getRectangle();
Expand Down
1 change: 1 addition & 0 deletions engines/pink/module.mk
Expand Up @@ -42,6 +42,7 @@ MODULE_OBJS = \
objects/sequences/sequencer.o \
objects/walk/walk_mgr.o \
objects/walk/walk_location.o \
objects/walk/walk_shortest_path.o \

# This module can be built as a plugin
ifeq ($(ENABLE_PINK), DYNAMIC_PLUGIN)
Expand Down
2 changes: 2 additions & 0 deletions engines/pink/objects/actions/action_still.cpp
Expand Up @@ -48,6 +48,8 @@ void ActionStill::onStart() {
for (int i = 0; i < _startFrame; ++i) {
_decoder->decodeNextFrame();
}
_decoder->stop();
_actor->endAction();
}

} // End of namespace Pink
5 changes: 5 additions & 0 deletions engines/pink/objects/actions/walk_action.cpp
Expand Up @@ -22,6 +22,7 @@

#include "walk_action.h"
#include <engines/pink/archive.h>
#include "pink/cel_decoder.h"

namespace Pink {

Expand All @@ -36,4 +37,8 @@ void WalkAction::toConsole() {
_name.c_str(), _fileName.c_str(), _toCalcFramePositions);
}

void WalkAction::onStart() {
_decoder->start();
}

} // End of namespace Pink
3 changes: 3 additions & 0 deletions engines/pink/objects/actions/walk_action.h
Expand Up @@ -33,6 +33,9 @@ class WalkAction : public ActionCEL {

virtual void toConsole();

protected:
void onStart() override;

private:
bool _toCalcFramePositions;
};
Expand Down
46 changes: 37 additions & 9 deletions engines/pink/objects/actors/lead_actor.cpp
Expand Up @@ -71,16 +71,20 @@ LeadActor::State LeadActor::getState() const {
void LeadActor::update() {
switch (_state) {
case kReady:

_sequencer->update();
//fall-through intended
_cursorMgr->update();
break;
case kMoving:

_walkMgr->update();
_cursorMgr->update();
break;
case kInDialog1:
case kInDialog2:
_sequencer->update();
if (!_sequencer->_context){
_state = _nextState;
_nextState = kUnk_Loading;
}
break;

case kInventory:
Expand Down Expand Up @@ -136,7 +140,8 @@ void LeadActor::onKeyboardButtonClick(Common::KeyCode code) {

void LeadActor::start(bool isHandler) {
if (isHandler && _state != kPlayingVideo){
_state = kReady;
_state = kInDialog1;
_nextState = kReady;
}
updateCursor({0,0});
}
Expand Down Expand Up @@ -177,17 +182,19 @@ void LeadActor::onLeftButtonClick(Common::Point point) {
case kReady:
case kMoving: {
Actor *actor = _page->getGame()->getDirector()->getActorByPoint(point);

if (this == actor){
// inventory is not implemented
return;
}

_recipient = (SupportingActor*) actor;
if (actor->isClickable() &&
((SupportingActor*) actor)->isLeftClickHandlers())




_recipient->isLeftClickHandlers()){
_state = kMoving;
_nextState = kInDialog1;
_walkMgr->start(_walkMgr->findLocation(_recipient->getLocation()));
}
break;
}
case kPDA:
Expand All @@ -207,6 +214,27 @@ void LeadActor::onMouseOver(Common::Point point, CursorMgr *mgr) {
else Actor::onMouseOver(point, mgr);
}

void LeadActor::onWalkEnd() {
State oldNextState = _nextState;
_state = kReady;
_nextState = kUnk_Loading;
if (_recipient && oldNextState == kInDialog1){
// if use click not impl
sendLeftClickMessage(_recipient);
}
}

bool LeadActor::sendUseClickMessage(SupportingActor *actor) {
return false;
}

bool LeadActor::sendLeftClickMessage(SupportingActor *actor) {
actor->onLeftClickMessage();
_nextState = _state != kPlayingVideo ? kReady : kPlayingVideo;
_state = kInDialog1;
return false;
}

void ParlSqPink::toConsole() {
debug("ParlSqPink: _name = %s", _name.c_str());
for (int i = 0; i < _actions.size(); ++i) {
Expand Down
11 changes: 11 additions & 0 deletions engines/pink/objects/actors/lead_actor.h
Expand Up @@ -27,12 +27,15 @@
#include <common/rect.h>
#include "actor.h"


namespace Pink {

class CursorMgr;
class WalkMgr;
class Sequencer;

class SupportingActor;

class LeadActor : public Actor {
public:
enum State {
Expand Down Expand Up @@ -62,14 +65,22 @@ class LeadActor : public Actor {
void onKeyboardButtonClick(Common::KeyCode code);
void onLeftButtonClick(Common::Point point);
void onMouseMove(Common::Point point);
void onWalkEnd();

virtual void onMouseOver(Common::Point point, CursorMgr *mgr);

private:
void updateCursor(Common::Point point);

bool sendUseClickMessage(SupportingActor *actor);
bool sendLeftClickMessage(SupportingActor *actor);


State _state;
State _nextState;

SupportingActor *_recipient;

CursorMgr *_cursorMgr;
WalkMgr *_walkMgr;
Sequencer *_sequencer;
Expand Down
16 changes: 16 additions & 0 deletions engines/pink/objects/actors/supporting_actor.cpp
Expand Up @@ -57,4 +57,20 @@ bool SupportingActor::isLeftClickHandlers() {
return _handlerMgr.isLeftClickHandler(this);
}

void SupportingActor::onTimerMessage() {
_handlerMgr.onTimerMessage(this);
}

bool SupportingActor::onLeftClickMessage() {
return _handlerMgr.onLeftClickMessage(this);
}

bool SupportingActor::onUseClickMessage() {
return _handlerMgr.onUseClickMessage(this);
}

const Common::String &SupportingActor::getLocation() const {
return _location;
}

} // End of namespace Pink
7 changes: 7 additions & 0 deletions engines/pink/objects/actors/supporting_actor.h
Expand Up @@ -38,6 +38,13 @@ class SupportingActor : public Actor {
virtual bool isClickable() { return 1; }
bool isLeftClickHandlers();

void onTimerMessage();
bool onLeftClickMessage();
bool onUseClickMessage();

const Common::String &getLocation() const;


private:
HandlerMgr _handlerMgr;
Common::String _location;
Expand Down
14 changes: 7 additions & 7 deletions engines/pink/objects/handlers/handler.cpp
Expand Up @@ -46,13 +46,13 @@ bool Handler::isSuitable(Actor *actor) {
return true;
}

void Handler::executeSideEffects(LeadActor *actor) {
void Handler::executeSideEffects(Actor *actor) {
for (int i = 0; i < _sideEffects.size(); ++i) {
_sideEffects[i]->execute(actor);
}
}

void Handler::onMessage(LeadActor *actor) {
void Handler::handle(Actor *actor) {
executeSideEffects(actor);
}

Expand All @@ -70,8 +70,8 @@ void HandlerSequences::deserialize(Archive &archive) {
archive >> _sequences;
}

void HandlerSequences::onMessage(LeadActor *actor) {
Handler::onMessage(actor);
void HandlerSequences::handle(Actor *actor) {
Handler::handle(actor);
Sequencer *sequencer = actor->getSequencer();

assert(!_sequences.empty());
Expand All @@ -84,10 +84,10 @@ void HandlerSequences::onMessage(LeadActor *actor) {
assert(sequence);
sequencer->authorSequence(sequence, 0);

handle(sequence);
execute(sequence);
}

void HandlerStartPage::handle(Sequence *sequence) {
void HandlerStartPage::execute(Sequence *sequence) {
sequence->_unk = 1;
}

Expand Down Expand Up @@ -152,7 +152,7 @@ void HandlerUseClick::toConsole() {
}
}

void HandlerUseClick::handle(Sequence *sequence) {
void HandlerUseClick::execute(Sequence *sequence) {

}

Expand Down
14 changes: 7 additions & 7 deletions engines/pink/objects/handlers/handler.h
Expand Up @@ -39,11 +39,11 @@ class Handler : public Object {
public:
~Handler();
virtual void deserialize(Archive &archive);
virtual void onMessage(LeadActor *actor);
virtual void handle(Actor *actor);
bool isSuitable(Actor *actor);

protected:
void executeSideEffects(LeadActor *actor);
void executeSideEffects(Actor *actor);

Common::Array<Condition*> _conditions;
Common::Array<SideEffect*> _sideEffects;
Expand All @@ -54,10 +54,10 @@ class Sequence;
class HandlerSequences : public Handler {
public:
virtual void deserialize(Archive &archive);
virtual void onMessage(LeadActor *actor);
virtual void handle(Actor *actor);

protected:
virtual void handle(Sequence *sequence) = 0;
virtual void execute(Sequence *sequence) = 0;

Common::StringArray _sequences;
};
Expand All @@ -67,15 +67,15 @@ class HandlerStartPage : public HandlerSequences {
virtual void toConsole();

private:
virtual void handle(Sequence *sequence);
virtual void execute(Sequence *sequence);
};

class HandlerLeftClick : public HandlerSequences {
public:
virtual void toConsole();

private:
virtual void handle(Sequence *sequence) {}
virtual void execute(Sequence *sequence) {}
};

class HandlerUseClick : public HandlerSequences {
Expand All @@ -84,7 +84,7 @@ class HandlerUseClick : public HandlerSequences {
virtual void toConsole();

private:
virtual void handle(Sequence *sequence);
virtual void execute(Sequence *sequence);

Common::String _inventoryItem;
Common::String _recepient;
Expand Down
51 changes: 51 additions & 0 deletions engines/pink/objects/handlers/handler_mgr.cpp
Expand Up @@ -36,4 +36,55 @@ bool HandlerMgr::isLeftClickHandler(Actor *actor) {
return false;
}

void HandlerMgr::onTimerMessage(Actor *actor) {
Handler *handler = findSuitableHandlerTimer(actor);
if (handler)
handler->handle(actor);
}

bool HandlerMgr::onLeftClickMessage(Actor *actor) {
Handler *handler = findSuitableHandlerLeftClick(actor);
if (handler) {
handler->handle(actor);
return 1;
}
return 0;
}

bool HandlerMgr::onUseClickMessage(Actor *actor) {
Handler *handler = findSuitableHandlerUseClick(actor);
if (handler) {
handler->handle(actor);
return 1;
}
return 0;
}

Handler *HandlerMgr::findSuitableHandlerTimer(Actor *actor) {
for (int i = 0; i < _timerHandlers.size(); ++i) {
if (_timerHandlers[i]->isSuitable(actor))
return _timerHandlers[i];
}

return nullptr;
}

Handler *HandlerMgr::findSuitableHandlerLeftClick(Actor *actor) {
for (int i = 0; i < _leftClickHandlers.size(); ++i) {
if (_leftClickHandlers[i]->isSuitable(actor))
return _leftClickHandlers[i];
}

return nullptr;
}

Handler *HandlerMgr::findSuitableHandlerUseClick(Actor *actor) {
for (int i = 0; i < _useClickHandlers.size(); ++i) {
if (_useClickHandlers[i]->isSuitable(actor))
return _useClickHandlers[i];
}

return nullptr;
}

}

0 comments on commit cad72b1

Please sign in to comment.