Skip to content

Commit

Permalink
PRINCE: Hero talking - dialog option choosing
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaslw committed Jun 22, 2014
1 parent 1e1d304 commit f00eeed
Show file tree
Hide file tree
Showing 3 changed files with 154 additions and 106 deletions.
179 changes: 90 additions & 89 deletions engines/prince/hero.cpp
Expand Up @@ -621,105 +621,106 @@ void Hero::rotateHero() {

void Hero::showHero() {
if (_visible) {
// Is he talking?
if (_talkTime == 0) { //?
// Scale of hero
selectZoom();
switch (_state) {
case STAY:
//if(OptionsFlag == false) {
//if(OpcodePC == null) {
_boredomTime++;
if (_boredomTime == 200) { // 140 for second hero
_boredomTime = 0;
_state = BORE;
}
switch (_lastDirection) {
case LEFT:
_moveSetType = Move_SL;
break;
case RIGHT:
_moveSetType = Move_SR;
break;
case UP:
_moveSetType = Move_SU;
break;
case DOWN:
_moveSetType = Move_SD;
break;
}
if (_talkTime != 0) {
_talkTime--;
if (_talkTime == 0) {
_state = STAY; // test this
}
}
// Scale of hero
selectZoom();
switch (_state) {
case STAY:
//if(OptionsFlag == false) {
//if(OpcodePC == null) {
_boredomTime++;
if (_boredomTime == 200) { // 140 for second hero
_boredomTime = 0;
_state = BORE;
}
switch (_lastDirection) {
case LEFT:
_moveSetType = Move_SL;
break;
case TURN:
/*
if(_lastDirection == _destDirection) {
_state = STAY;
} else {
_frame = 0;
rotateHero();
_lastDirection = _destDirection;
}
*/
case RIGHT:
_moveSetType = Move_SR;
break;
case MOVE:
switch (_lastDirection) {
case LEFT:
_moveSetType = Move_ML;
break;
case RIGHT:
_moveSetType = Move_MR;
break;
case UP:
_moveSetType = Move_MU;
break;
case DOWN:
_moveSetType = Move_MD;
break;
}
case UP:
_moveSetType = Move_SU;
break;
case BORE:
//if (_direction == UP) {
switch (_boreNum) {
case 0:
_moveSetType = Move_BORED1;
break;
case 1:
_moveSetType = Move_BORED2;
break;
}
if (_phase == _moveSet[_moveSetType]->getFrameCount() - 1) {
_boreNum = _vm->_randomSource.getRandomNumber(1); // rand one of two 'bored' animation
_lastDirection = DOWN;
_state = STAY;
}
case DOWN:
_moveSetType = Move_SD;
break;
}
break;
case TURN:
/*
if(_lastDirection == _destDirection) {
_state = STAY;
} else {
_frame = 0;
rotateHero();
_lastDirection = _destDirection;
}
*/
break;
case MOVE:
switch (_lastDirection) {
case LEFT:
_moveSetType = Move_ML;
break;
case SPEC:
//specialAnim();
case RIGHT:
_moveSetType = Move_MR;
break;
case TALK:
switch (_lastDirection) {
case LEFT:
_moveSetType = Move_TL;
break;
case RIGHT:
_moveSetType = Move_TR;
break;
case UP:
_moveSetType = Move_TU;
break;
case DOWN:
_moveSetType = Move_TD;
break;
}
case UP:
_moveSetType = Move_MU;
break;
case TRAN:
case DOWN:
_moveSetType = Move_MD;
break;
case RUN:
}
break;
case BORE:
//if (_direction == UP) {
switch (_boreNum) {
case 0:
_moveSetType = Move_BORED1;
break;
case DMOVE:
case 1:
_moveSetType = Move_BORED2;
break;
}
} else {
_talkTime--; // o ile?
if (_phase == _moveSet[_moveSetType]->getFrameCount() - 1) {
_boreNum = _vm->_randomSource.getRandomNumber(1); // rand one of two 'bored' animation
_lastDirection = DOWN;
_state = STAY;
}
break;
case SPEC:
//specialAnim();
break;
case TALK:
switch (_lastDirection) {
case LEFT:
_moveSetType = Move_TL;
break;
case RIGHT:
_moveSetType = Move_TR;
break;
case UP:
_moveSetType = Move_TU;
break;
case DOWN:
_moveSetType = Move_TD;
break;
}
break;
case TRAN:
break;
case RUN:
break;
case DMOVE:
break;
}
showHeroAnimFrame();
} else {
Expand Down
77 changes: 61 additions & 16 deletions engines/prince/prince.cpp
Expand Up @@ -710,13 +710,13 @@ void PrinceEngine::keyHandler(Common::Event event) {
break;
case Common::KEYCODE_k:
_mainHero->_middleY += 5;
addInvObj();
//addInvObj();
break;
case Common::KEYCODE_j:
_mainHero->_middleX -= 5;
_flags->setFlagValue(Flags::CURSEBLINK, 1);
addInvObj();
_flags->setFlagValue(Flags::CURSEBLINK, 0);
//_flags->setFlagValue(Flags::CURSEBLINK, 1);
//addInvObj();
//_flags->setFlagValue(Flags::CURSEBLINK, 0);
break;
case Common::KEYCODE_l:
_mainHero->_middleX += 5;
Expand Down Expand Up @@ -843,6 +843,18 @@ void PrinceEngine::printAt(uint32 slot, uint8 color, const char *s, uint16 x, ui
text._color = color;
}

int PrinceEngine::calcText(const char *s) {
int lines = 1;
while (*s) {
if (*s == '\n') {
lines++;
}
s++;
}
return lines;
//time = lines * 30
}

uint32 PrinceEngine::getTextWidth(const char *s) {
uint16 textW = 0;
while (*s) {
Expand All @@ -855,21 +867,20 @@ uint32 PrinceEngine::getTextWidth(const char *s) {
void PrinceEngine::showTexts(Graphics::Surface *screen) {
for (uint32 slot = 0; slot < MAXTEXTS; ++slot) {
Text& text = _textSlots[slot];
if (!text._str && !text._time)
if (!text._str && !text._time) {
continue;
}

Common::Array<Common::String> lines;
_font->wordWrapText(text._str, _graph->_frontScreen->w, lines);

for (uint8 i = 0; i < lines.size(); ++i) {
_font->drawString(
screen,
lines[i],
text._x - getTextWidth(lines[i].c_str())/2,
text._y - (lines.size() - i) * (_font->getFontHeight()),
screen->w,
text._color
);
for (uint8 i = 0; i < lines.size(); i++) {
int x = text._x - getTextWidth(lines[i].c_str()) / 2;
int y = text._y - (lines.size() - i) * (_font->getFontHeight());
if (y < 0) {
y = 0;
}
_font->drawString(screen, lines[i], x, y, screen->w, text._color);
}

text._time--;
Expand Down Expand Up @@ -1974,6 +1985,7 @@ void PrinceEngine::runDialog(Common::Array<DialogLine> &dialogData) {
Common::Point mousePos = _system->getEventManager()->getMousePos();

int dialogSelected = -1;
int dialogSelectedText = -1;

for (uint i = 0; i < dialogData.size(); i++) {
int actualColor = _dialogColor1;
Expand All @@ -1985,6 +1997,7 @@ void PrinceEngine::runDialog(Common::Array<DialogLine> &dialogData) {
if (dialogOption.contains(mousePos)) {
actualColor = _dialogColor2;
dialogSelected = dialogData[i]._nr;
dialogSelectedText = i;
}

for (uint j = 0; j < lines.size(); j++) {
Expand All @@ -2006,7 +2019,7 @@ void PrinceEngine::runDialog(Common::Array<DialogLine> &dialogData) {
case Common::EVENT_MOUSEMOVE:
break;
case Common::EVENT_LBUTTONDOWN:
dialogLeftMouseButton(dialogSelected);
dialogLeftMouseButton(dialogSelected, dialogData[dialogSelectedText]._line.c_str());
return;
break;
case Common::EVENT_RBUTTONDOWN:
Expand All @@ -2033,12 +2046,44 @@ void PrinceEngine::runDialog(Common::Array<DialogLine> &dialogData) {
delete _dialogImage;
}

void PrinceEngine::dialogLeftMouseButton(int dialogSelected) {
void PrinceEngine::dialogLeftMouseButton(int dialogSelected, const char *s) {
if (dialogSelected != -1) {
//TODO @@showa_dialoga:
talkHero(0, s);
}
}

void PrinceEngine::talkHero(int slot, const char *s) {
// heroSlot = textSlot

Text &text = _textSlots[slot];
int lines = calcText(s);
int time = lines * 30;
int x, y;
//int textSkip = -2; // global?

if (slot == 0) {
text._color = 0xFF00DC; // test this
_mainHero->_state = Hero::TALK;
_mainHero->_talkTime = time;
x = _mainHero->_middleX;
y = _mainHero->_middleY - _mainHero->_scaledFrameYSize - 10;
//y -= (_font->getFontHeight() + textSkip) * lines; // need this?
} else {
//text._color = _secondHero->color;
text._color = 0xFF00DC; // test this !
_secondHero->_state = Hero::TALK;
_secondHero->_talkTime = time;
x = _secondHero->_middleX;
y = _secondHero->_middleY - _secondHero->_currHeight - 10; // set currHeight
//y -= (_font->getFontHeight() + textSkip) * lines; // need this?
}
text._time = time; // changed by SETSPECVOICE?
text._str = s;
text._x = x;
text._y = y;
}

// Test
void PrinceEngine::testDialog() {
Common::Array<DialogLine> tempDialogBox;
Expand Down
4 changes: 3 additions & 1 deletion engines/prince/prince.h
Expand Up @@ -249,6 +249,7 @@ class PrinceEngine : public Engine {

void changeCursor(uint16 curId);
void printAt(uint32 slot, uint8 color, const char *s, uint16 x, uint16 y);
int calcText(const char *s);

static const uint8 MAXTEXTS = 32;
Text _textSlots[MAXTEXTS];
Expand Down Expand Up @@ -345,7 +346,7 @@ class PrinceEngine : public Engine {
void rightMouseButton();
void inventoryLeftMouseButton();
void inventoryRightMouseButton();
void dialogLeftMouseButton(int dialogSelected);
void dialogLeftMouseButton(int dialogSelected, const char *s);

int _dialogWidth;
int _dialogHeight;
Expand All @@ -356,6 +357,7 @@ class PrinceEngine : public Engine {

void createDialogBox(Common::Array<DialogLine> &dialogData);
void runDialog(Common::Array<DialogLine> &dialogData);
void talkHero(int slot, const char *s);
void testDialog();

int testAnimNr;
Expand Down

0 comments on commit f00eeed

Please sign in to comment.