diff options
Diffstat (limited to 'engines/queen')
-rw-r--r-- | engines/queen/command.cpp | 178 | ||||
-rw-r--r-- | engines/queen/command.h | 27 | ||||
-rw-r--r-- | engines/queen/logic.cpp | 7 |
3 files changed, 116 insertions, 96 deletions
diff --git a/engines/queen/command.cpp b/engines/queen/command.cpp index de4cbc8317..dfbb4801d9 100644 --- a/engines/queen/command.cpp +++ b/engines/queen/command.cpp @@ -43,7 +43,6 @@ namespace Queen { CmdText::CmdText(uint8 y, QueenEngine *vm) : _y(y), _vm(vm) { - _isReversed = (_vm->resource()->getLanguage() == Common::HB_ISR); clear(); } @@ -51,45 +50,24 @@ void CmdText::clear() { memset(_command, 0, sizeof(_command)); } -void CmdText::display(InkColor color) { +void CmdText::display(InkColor color, const char *command, bool outlined) { _vm->display()->textCurrentColor(_vm->display()->getInkColor(color)); - _vm->display()->setTextCentered(_y, _command, false); + if (!command) { + command = _command; + } + _vm->display()->setTextCentered(_y, command, outlined); } -void CmdText::displayTemp(InkColor color, Verb v, const char *name, bool outlined) { - char temp[MAX_COMMAND_LEN] = ""; - if (_isReversed) { - if (name != NULL) - sprintf(temp, "%s ", name); - strcat(temp, _vm->logic()->verbName(v)); - } else { - strcpy(temp, _vm->logic()->verbName(v)); - if (name != NULL) { - strcat(temp, " "); - strcat(temp, name); - } - } - _vm->display()->textCurrentColor(_vm->display()->getInkColor(color)); - _vm->display()->setTextCentered(_y, temp, outlined); +void CmdText::displayTemp(InkColor color, Verb v) { + char temp[MAX_COMMAND_LEN]; + strcpy(temp, _vm->logic()->verbName(v)); + display(color, temp, false); } void CmdText::displayTemp(InkColor color, const char *name, bool outlined) { char temp[MAX_COMMAND_LEN]; - if (_isReversed) { - sprintf(temp, "%s %s", name, _command); - } else { - if (_vm->resource()->getLanguage() != Common::GR_GRE) { - sprintf(temp, "%s %s", _command, name); - } else { - // don't show a space after the goto and give commands in the Greek version - if (_command[1] != -34 && !(_command[1] == -2 && strlen(_command) > 5)) - sprintf(temp, "%s %s", _command, name); - else - sprintf(temp, "%s%s", _command, name); - } - } - _vm->display()->textCurrentColor(_vm->display()->getInkColor(color)); - _vm->display()->setTextCentered(_y, temp, outlined); + sprintf(temp, "%s %s", _command, name); + display(color, temp, outlined); } void CmdText::setVerb(Verb v) { @@ -97,41 +75,78 @@ void CmdText::setVerb(Verb v) { } void CmdText::addLinkWord(Verb v) { - if (_isReversed) { + strcat(_command, " "); + strcat(_command, _vm->logic()->verbName(v)); +} + +void CmdText::addObject(const char *objName) { + strcat(_command, " "); + strcat(_command, objName); +} + +class CmdTextHebrew : public CmdText { +public: + + CmdTextHebrew(uint8 y, QueenEngine *vm) : CmdText(y, vm) {} + + virtual void displayTemp(InkColor color, const char *name, bool outlined) { + char temp[MAX_COMMAND_LEN]; + + sprintf(temp, "%s %s", name, _command); + display(color, temp, outlined); + } + + virtual void addLinkWord(Verb v) { char temp[MAX_COMMAND_LEN]; strcpy(temp, _command); strcpy(_command, _vm->logic()->verbName(v)); strcat(_command, " "); strcat(_command, temp); - } else { - strcat(_command, " "); - strcat(_command, _vm->logic()->verbName(v)); } -} -void CmdText::addObject(const char *objName) { - if (_isReversed) { + virtual void addObject(const char *objName) { char temp[MAX_COMMAND_LEN]; strcpy(temp, _command); strcpy(_command, objName); strcat(_command, " "); strcat(_command, temp); - } else { - if (_vm->resource()->getLanguage() != Common::GR_GRE) { + } +}; + +class CmdTextGreek : public CmdText { +public: + + CmdTextGreek(uint8 y, QueenEngine *vm) : CmdText(y, vm) {} + + virtual void displayTemp(InkColor color, const char *name, bool outlined) { + char temp[MAX_COMMAND_LEN]; + // don't show a space after the goto and give commands in the Greek version + if (_command[1] != -34 && !(_command[1] == -2 && strlen(_command) > 5)) + sprintf(temp, "%s %s", _command, name); + else + sprintf(temp, "%s%s", _command, name); + display(color, temp, outlined); + } + + virtual void addObject(const char *objName) { + // don't show a space after the goto and give commands in the Greek version + if (_command[1] != -34 && !(_command[1] == -2 && strlen(_command) > 5)) strcat(_command, " "); - } else { - // don't show a space after the goto and give commands in the Greek version - if (_command[1] != -34 && !(_command[1] == -2 && strlen(_command) > 5)) - strcat(_command, " "); - } strcat(_command, objName); } -} +}; -bool CmdText::isEmpty() const { - return _command[0] == 0; +CmdText *CmdText::makeCmdTextInstance(uint8 y, QueenEngine *vm) { + switch (vm->resource()->getLanguage()) { + case Common::HB_ISR: + return new CmdTextHebrew(y, vm); + case Common::GR_GRE: + return new CmdTextGreek(y, vm); + default: + return new CmdText(y, vm); + } } void CmdState::init() { @@ -144,11 +159,12 @@ void CmdState::init() { } Command::Command(QueenEngine *vm) - : _cmdList(NULL), _cmdArea(NULL), _cmdObject(NULL), _cmdInventory(NULL), _cmdGameState(NULL), - _cmdText(CmdText::COMMAND_Y_POS, vm), _vm(vm) { + : _cmdList(NULL), _cmdArea(NULL), _cmdObject(NULL), _cmdInventory(NULL), _cmdGameState(NULL), _vm(vm) { + _cmdText = CmdText::makeCmdTextInstance(CmdText::COMMAND_Y_POS, vm); } Command::~Command() { + delete _cmdText; delete[] _cmdList; delete[] _cmdArea; delete[] _cmdObject; @@ -158,7 +174,7 @@ Command::~Command() { void Command::clear(bool clearTexts) { debug(6, "Command::clear(%d)", clearTexts); - _cmdText.clear(); + _cmdText->clear(); if (clearTexts) { _vm->display()->clearTexts(CmdText::COMMAND_Y_POS, CmdText::COMMAND_Y_POS); } @@ -179,12 +195,12 @@ void Command::executeCurrentAction() { _state.verb = State::findDefaultVerb(od->state); _state.selAction = (_state.verb == VERB_NONE) ? VERB_WALK_TO : _state.verb; - _cmdText.setVerb(_state.selAction); - _cmdText.addObject(_vm->logic()->objectName(od->name)); + _cmdText->setVerb(_state.selAction); + _cmdText->addObject(_vm->logic()->objectName(od->name)); } // always highlight the current command when actioned - _cmdText.display(INK_CMD_SELECT); + _cmdText->display(INK_CMD_SELECT); _state.selNoun = _state.noun; _state.commandLevel = 1; @@ -574,7 +590,7 @@ void Command::grabCurrentSelection() { void Command::grabSelectedObject(int16 objNum, uint16 objState, uint16 objName) { if (_state.action != VERB_NONE) { - _cmdText.addObject(_vm->logic()->objectName(objName)); + _cmdText->addObject(_vm->logic()->objectName(objName)); } _state.subject[_state.commandLevel - 1] = objNum; @@ -584,8 +600,8 @@ void Command::grabSelectedObject(int16 objNum, uint16 objState, uint16 objName) if (State::findUse(objState) == STATE_USE_ON) { // object supports 2 levels, command not fully constructed _state.commandLevel = 2; - _cmdText.addLinkWord(VERB_PREP_WITH); - _cmdText.display(INK_CMD_NORMAL); + _cmdText->addLinkWord(VERB_PREP_WITH); + _cmdText->display(INK_CMD_NORMAL); _parse = false; } else { _parse = true; @@ -593,8 +609,8 @@ void Command::grabSelectedObject(int16 objNum, uint16 objState, uint16 objName) } else if (_state.action == VERB_GIVE && _state.commandLevel == 1) { // command not fully constructed _state.commandLevel = 2; - _cmdText.addLinkWord(VERB_PREP_TO); - _cmdText.display(INK_CMD_NORMAL); + _cmdText->addLinkWord(VERB_PREP_TO); + _cmdText->display(INK_CMD_NORMAL); _parse = false; } else { _parse = true; @@ -629,22 +645,22 @@ void Command::grabSelectedItem() { if (_state.verb == VERB_NONE) { // set to Look At _state.verb = VERB_LOOK_AT; - _cmdText.setVerb(VERB_LOOK_AT); + _cmdText->setVerb(VERB_LOOK_AT); } _state.action = _state.verb; } else { // Action>0 ONLY if command has been constructed // Left Mouse Button pressed just do Look At _state.action = VERB_LOOK_AT; - _cmdText.setVerb(VERB_LOOK_AT); + _cmdText->setVerb(VERB_LOOK_AT); } } _state.verb = VERB_NONE; } else { - if (_cmdText.isEmpty()) { + if (_cmdText->isEmpty()) { _state.verb = VERB_LOOK_AT; _state.action = VERB_LOOK_AT; - _cmdText.setVerb(VERB_LOOK_AT); + _cmdText->setVerb(VERB_LOOK_AT); } else { if (_state.commandLevel == 2 && _parse) _state.verb = _state.action; @@ -653,7 +669,7 @@ void Command::grabSelectedItem() { if (_state.verb == VERB_NONE) { // No match made, so command not yet completed. Redefine as LOOK AT _state.action = VERB_LOOK_AT; - _cmdText.setVerb(VERB_LOOK_AT); + _cmdText->setVerb(VERB_LOOK_AT); } else { _state.action = _state.verb; } @@ -680,14 +696,14 @@ void Command::grabSelectedNoun() { (_state.commandLevel == 2 && _parse)) { _state.verb = VERB_WALK_TO; _state.action = VERB_WALK_TO; - _cmdText.setVerb(VERB_WALK_TO); + _cmdText->setVerb(VERB_WALK_TO); } } else if (_mouseKey == Input::MOUSE_RBUTTON) { - if (_cmdText.isEmpty()) { + if (_cmdText->isEmpty()) { _state.verb = State::findDefaultVerb(od->state); _state.selAction = (_state.verb == VERB_NONE) ? VERB_WALK_TO : _state.verb; - _cmdText.setVerb(_state.selAction); - _cmdText.addObject(_vm->logic()->objectName(od->name)); + _cmdText->setVerb(_state.selAction); + _cmdText->addObject(_vm->logic()->objectName(od->name)); } else { if ((_state.commandLevel == 2 && !_parse) || _state.action != VERB_NONE) { _state.verb = _state.action; @@ -721,8 +737,8 @@ void Command::grabSelectedVerb() { _state.commandLevel = 1; _state.oldVerb = VERB_NONE; _state.oldNoun = 0; - _cmdText.setVerb(_state.verb); - _cmdText.display(INK_CMD_NORMAL); + _cmdText->setVerb(_state.verb); + _cmdText->display(INK_CMD_NORMAL); } } @@ -1251,7 +1267,7 @@ void Command::lookForCurrentObject(int16 cx, int16 cy) { _state.oldNoun = _state.noun; _vm->display()->clearTexts(CmdText::COMMAND_Y_POS, CmdText::COMMAND_Y_POS); if (_state.action != VERB_NONE) { - _cmdText.display(INK_CMD_NORMAL); + _cmdText->display(INK_CMD_NORMAL); } return; } @@ -1259,13 +1275,13 @@ void Command::lookForCurrentObject(int16 cx, int16 cy) { // if no command yet selected, then use DEFAULT command, if any if (_state.action == VERB_NONE) { Verb v = State::findDefaultVerb(od->state); - _cmdText.setVerb((v == VERB_NONE) ? VERB_WALK_TO : v); + _cmdText->setVerb((v == VERB_NONE) ? VERB_WALK_TO : v); if (_state.noun == 0) { - _cmdText.clear(); + _cmdText->clear(); } } const char *name = _vm->logic()->objectName(od->name); - _cmdText.displayTemp(INK_CMD_NORMAL, name); + _cmdText->displayTemp(INK_CMD_NORMAL, name, false); _state.oldNoun = _state.noun; } @@ -1274,7 +1290,7 @@ void Command::lookForCurrentIcon(int16 cx, int16 cy) { if (_state.oldVerb != _state.verb) { if (_state.action == VERB_NONE) { - _cmdText.clear(); + _cmdText->clear(); } _vm->display()->clearTexts(CmdText::COMMAND_Y_POS, CmdText::COMMAND_Y_POS); @@ -1283,15 +1299,15 @@ void Command::lookForCurrentIcon(int16 cx, int16 cy) { if (id != NULL && id->name > 0) { if (_state.action == VERB_NONE) { Verb v = State::findDefaultVerb(id->state); - _cmdText.setVerb((v == VERB_NONE) ? VERB_LOOK_AT : v); + _cmdText->setVerb((v == VERB_NONE) ? VERB_LOOK_AT : v); } const char *name = _vm->logic()->objectName(id->name); - _cmdText.displayTemp(INK_CMD_NORMAL, name); + _cmdText->displayTemp(INK_CMD_NORMAL, name, false); } } else if (isVerbAction(_state.verb)) { - _cmdText.displayTemp(INK_CMD_NORMAL, _state.verb); + _cmdText->displayTemp(INK_CMD_NORMAL, _state.verb); } else if (_state.verb == VERB_NONE) { - _cmdText.display(INK_CMD_NORMAL); + _cmdText->display(INK_CMD_NORMAL); } _state.oldVerb = _state.verb; } diff --git a/engines/queen/command.h b/engines/queen/command.h index e0a6cef80a..e787bb3c1b 100644 --- a/engines/queen/command.h +++ b/engines/queen/command.h @@ -33,47 +33,50 @@ namespace Queen { class QueenEngine; -struct CmdText { +class CmdText { +public: + + static CmdText *makeCmdTextInstance(uint8 y, QueenEngine *vm); CmdText(uint8 y, QueenEngine *vm); + virtual ~CmdText() {} //! reset the command sentence void clear(); //! display the command sentence using the specified color - void display(InkColor color); + void display(InkColor color, const char *command = 0, bool outlined = false); //! display a temporary command sentence using the specified parameters - void displayTemp(InkColor color, Verb v, const char *name = NULL, bool outlined = false); + void displayTemp(InkColor color, Verb v); //! display a temporary command sentence using the specified parameters - void displayTemp(InkColor color, const char *name, bool outlined = false); + virtual void displayTemp(InkColor color, const char *name, bool outlined); //! set the verb for the command sentence void setVerb(Verb v); //! set the link word (between verb and object) for the command sentence - void addLinkWord(Verb v); + virtual void addLinkWord(Verb v); //! add an object name to the command sentence - void addObject(const char *objName); + virtual void addObject(const char *objName); //! returns true if the command sentence is empty - bool isEmpty() const; + bool isEmpty() const { return _command[0] == 0; } enum { MAX_COMMAND_LEN = 256, COMMAND_Y_POS = 151 }; - uint8 _y; - - //! flag indicating if the words in the sentence are reversed (hebrew version) - bool _isReversed; +protected: //! buffer containing the current command sentence char _command[MAX_COMMAND_LEN]; + uint8 _y; + QueenEngine *_vm; }; @@ -217,7 +220,7 @@ private: uint16 _numCmdGameState; //! textual form of the command (displayed between room and panel areas) - CmdText _cmdText; + CmdText *_cmdText; //! flag indicating that the current command is fully constructed bool _parse; diff --git a/engines/queen/logic.cpp b/engines/queen/logic.cpp index fb1105084e..67eb1c1f41 100644 --- a/engines/queen/logic.cpp +++ b/engines/queen/logic.cpp @@ -1195,8 +1195,8 @@ void Logic::handlePinnacleRoom() { _entryObj = 0; uint16 prevObj = 0; - CmdText cmdText(5, _vm); - cmdText.setVerb(VERB_WALK_TO); + CmdText *cmdText = CmdText::makeCmdTextInstance(5, _vm); + cmdText->setVerb(VERB_WALK_TO); while (_vm->input()->mouseButton() == 0 || _entryObj == 0) { _vm->update(); @@ -1218,11 +1218,12 @@ void Logic::handlePinnacleRoom() { ObjectData *objData = objectData(curObj); if (objData->name > 0) { _entryObj = objData->entryObj; - cmdText.displayTemp(INK_PINNACLE_ROOM, objectName(objData->name), true); + cmdText->displayTemp(INK_PINNACLE_ROOM, objectName(objData->name), true); } prevObj = curObj; } } + delete cmdText; _vm->input()->clearMouseButton(); _newRoom = objectData(_entryObj)->room; |