Skip to content

Commit

Permalink
XEEN: Implemented cmNPC and TownMessage dialog class
Browse files Browse the repository at this point in the history
  • Loading branch information
dreammaster committed Mar 3, 2015
1 parent 7bbbfd2 commit de5aedc
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 6 deletions.
4 changes: 2 additions & 2 deletions engines/xeen/font.cpp
Expand Up @@ -65,7 +65,7 @@ void FontSurface::writeSymbol(int symbolId) {
* @remarks Note that bounds is just used for wrapping purposes. Unless
* justification is set, the message will be written at _writePos
*/
Common::String FontSurface::writeString(const Common::String &s, const Common::Rect &bounds) {
const char *FontSurface::writeString(const Common::String &s, const Common::Rect &bounds) {
_displayString = s.c_str();
assert(_fontData);

Expand Down Expand Up @@ -250,7 +250,7 @@ Common::String FontSurface::writeString(const Common::String &s, const Common::R
break;
}

return Common::String(_displayString);
return _displayString;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion engines/xeen/font.h
Expand Up @@ -63,7 +63,7 @@ class FontSurface: public XSurface {

void writeSymbol(int symbolId);

Common::String writeString(const Common::String &s, const Common::Rect &clipRect);
const char *writeString(const Common::String &s, const Common::Rect &clipRect);
};

} // End of namespace Xeen
Expand Down
2 changes: 1 addition & 1 deletion engines/xeen/screen.cpp
Expand Up @@ -183,7 +183,7 @@ void Window::fill() {
fillRect(_innerBounds, _vm->_screen->_bgColor);
}

Common::String Window::writeString(const Common::String &s) {
const char *Window::writeString(const Common::String &s) {
return _vm->_screen->writeString(s, _innerBounds);
}

Expand Down
2 changes: 1 addition & 1 deletion engines/xeen/screen.h
Expand Up @@ -92,7 +92,7 @@ class Window: public XSurface {

void fill();

Common::String writeString(const Common::String &s);
const char *writeString(const Common::String &s);

void drawList(DrawStruct *items, int count);

Expand Down
6 changes: 5 additions & 1 deletion engines/xeen/scripts.cpp
Expand Up @@ -368,7 +368,11 @@ void Scripts::cmdSignText(Common::Array<byte> &params) {
}

void Scripts::cmdNPC(Common::Array<byte> &params) {
error("TODO: cmdNPC");
Map &map = *_vm->_map;

if (TownMessage::show(_vm, params[2], _message, map._events._text[params[1]],
params[3]))
_lineNum = params[4];
}

/**
Expand Down
115 changes: 115 additions & 0 deletions engines/xeen/town.cpp
Expand Up @@ -1192,4 +1192,119 @@ bool Town::isActive() const {
return _townSprites.size() > 0 && !_townSprites[0].empty();
}

/*------------------------------------------------------------------------*/

bool TownMessage::show(XeenEngine *vm, int portrait, const Common::String &name,
const Common::String &text, int confirm) {
TownMessage *dlg = new TownMessage(vm);
bool result = dlg->execute(portrait, name, text, confirm);
delete dlg;

return result;
}

bool TownMessage::execute(int portrait, const Common::String &name, const Common::String &text,
int confirm) {
EventsManager &events = *_vm->_events;
Interface &intf = *_vm->_interface;
Screen &screen = *_vm->_screen;
Town &town = *_vm->_town;
Window &w = screen._windows[11];

town._townMaxId = 4;
town._townActionId = 7;
town._drawFrameIndex = 0;
town._townPos = Common::Point(23, 22);

if (!confirm)
loadButtons();

if (town._townSprites[0].empty()) {
town._townSprites[0].load(Common::String::format("face%02d.fac", portrait));
town._townSprites[1].load("frame.fac");
}

if (!w._enabled)
w.open();

int result = -1;
Common::String msgText = text;
for (;;) {
Common::String msg = Common::String::format("\r\v014\x03c\t125%s\t000\v054%s",
name.c_str(), msgText.c_str());
const char *msgEnd = w.writeString(msg.c_str());
int wordCount = 0;

for (const char *msgP = msg.c_str(); msgP < msgEnd; ++msgP) {
if (*msgP == ' ')
++wordCount;
}

town._drawCtr2 = wordCount * 2;
town._townSprites[1].draw(screen, 0, Common::Point(16, 16));
town._townSprites[0].draw(screen, town._drawFrameIndex, Common::Point(23, 22));
w.update();

if (!msgEnd) {
// Doesn't look like the code here in original can ever be reached
assert(0);
}

if (confirm == 2) {
intf._face1State = intf._face2State = 2;
return false;
}

do {
events.clearEvents();
events.updateGameCounter();
if (msgEnd)
clearButtons();

do {
events.wait(3, true);
checkEvents(_vm);
if (_vm->shouldQuit())
return false;

town.drawTownAnim(false);
events.updateGameCounter();
} while (!_buttonValue);

if (msgEnd)
break;

if (!msgEnd) {
if (confirm || _buttonValue == Common::KEYCODE_ESCAPE ||
_buttonValue == Common::KEYCODE_n)
result = 0;
else if (_buttonValue == Common::KEYCODE_y)
result = 1;
}
} while (result == -1);

if (msgEnd) {
msgText = Common::String(msgEnd);
town._drawCtr2 = wordCount;
continue;
}
} while (result == -1);

intf._face1State = intf._face2State = 2;
if (!confirm)
intf.mainIconsPrint();

town._townSprites[0].clear();
town._townSprites[1].clear();
return result == 1;
}

void TownMessage::loadButtons() {
_iconSprites.load("confirm.icn");

addButton(Common::Rect(235, 75, 259, 95), Common::KEYCODE_y, &_iconSprites);
addButton(Common::Rect(260, 75, 284, 95), Common::KEYCODE_n, &_iconSprites);
addButton(Common::Rect(), Common::KEYCODE_ESCAPE);
}

} // End of namespace Xeen
18 changes: 18 additions & 0 deletions engines/xeen/town.h
Expand Up @@ -32,8 +32,10 @@
namespace Xeen {

class XeenEngine;
class TownMessage;

class Town: public ButtonContainer {
friend class TownMessage;
private:
XeenEngine *_vm;
SpriteResource _icons1, _icons2;
Expand Down Expand Up @@ -105,6 +107,22 @@ class Town: public ButtonContainer {
bool isActive() const;
};

class TownMessage : public ButtonContainer {
private:
XeenEngine *_vm;
SpriteResource _iconSprites;

TownMessage(XeenEngine *vm) : ButtonContainer(), _vm(vm) {}

bool execute(int portrait, const Common::String &name,
const Common::String &text, int confirm);

void loadButtons();
public:
static bool show(XeenEngine *vm, int portrait, const Common::String &name,
const Common::String &text, int confirm);
};

} // End of namespace Xeen

#endif /* XEEN_SPELLS_H */

0 comments on commit de5aedc

Please sign in to comment.