From 5fb10f662d3912fb82ffdd6b811b6a28ea0bdaaf Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 19 Jan 2020 21:22:19 -0800 Subject: [PATCH] ULTIMA1: Giving pence to king now working --- engines/ultima/shared/gfx/text_input.cpp | 2 + engines/ultima/ultima1/core/resources.cpp | 8 +-- engines/ultima/ultima1/core/resources.h | 2 +- engines/ultima/ultima1/u1dialogs/dialog.cpp | 7 +++ engines/ultima/ultima1/u1dialogs/dialog.h | 5 ++ engines/ultima/ultima1/u1dialogs/king.cpp | 70 ++++++++++++++++++--- engines/ultima/ultima1/u1dialogs/king.h | 28 +++++++-- 7 files changed, 104 insertions(+), 18 deletions(-) diff --git a/engines/ultima/shared/gfx/text_input.cpp b/engines/ultima/shared/gfx/text_input.cpp index ee6a91710ac..377233be511 100644 --- a/engines/ultima/shared/gfx/text_input.cpp +++ b/engines/ultima/shared/gfx/text_input.cpp @@ -75,9 +75,11 @@ bool TextInput::KeypressMsg(CKeypressMsg &msg) { setDirty(); } } else if (msg._keyState.keycode == Common::KEYCODE_RETURN || msg._keyState.keycode == Common::KEYCODE_KP_ENTER) { + _game->_textCursor->setVisible(false); CTextInputMsg inputMsg(_text, false); inputMsg.execute(_respondTo); } else if (msg._keyState.keycode == Common::KEYCODE_ESCAPE) { + _game->_textCursor->setVisible(false); CTextInputMsg inputMsg("", true); inputMsg.execute(_respondTo); } diff --git a/engines/ultima/ultima1/core/resources.cpp b/engines/ultima/ultima1/core/resources.cpp index 2a626b54180..bc1152da785 100644 --- a/engines/ultima/ultima1/core/resources.cpp +++ b/engines/ultima/ultima1/core/resources.cpp @@ -666,9 +666,9 @@ const char *const SRC_GROCERY_FIND_PACKS = "Thou dost find %d bags of food!"; const char *const SRC_WITH_KING = " with king"; const char *const SRC_HE_IS_NOT_HERE = "He is not here!"; const char *const SRC_HE_REJECTS_OFFER = "He rejects thine offer!"; -const char *const SRC_KING_TEXT[11] = { +const char *const SRC_KING_TEXT[10] = { "Dost thou offer pence\ror service: ", "neither", "pence", "service", "How much? ", - "none", "Thou hast not that much!", "In return I give unto thee %u hit points", + "Thou hast not that much!", "In return I give unto\rthee %u hit points", "Thou art on a quest for me already!", "Go now and kill a", "Go forth and find a" }; @@ -801,7 +801,7 @@ GameResources::GameResources(Shared::Resources *resManager) : LocalResourceFile( WITH_KING = SRC_WITH_KING; HE_IS_NOT_HERE = SRC_HE_IS_NOT_HERE; HE_REJECTS_OFFER = SRC_HE_REJECTS_OFFER; - Common::copy(&SRC_KING_TEXT[0], &SRC_KING_TEXT[11], KING_TEXT); + Common::copy(&SRC_KING_TEXT[0], &SRC_KING_TEXT[10], KING_TEXT); } void GameResources::synchronize() { @@ -928,7 +928,7 @@ void GameResources::synchronize() { syncString(WITH_KING); syncString(HE_IS_NOT_HERE); syncString(HE_REJECTS_OFFER); - syncStrings(KING_TEXT, 11); + syncStrings(KING_TEXT, 10); } } // End of namespace Ultima1 diff --git a/engines/ultima/ultima1/core/resources.h b/engines/ultima/ultima1/core/resources.h index 3513976b209..f7274f18b4b 100644 --- a/engines/ultima/ultima1/core/resources.h +++ b/engines/ultima/ultima1/core/resources.h @@ -159,7 +159,7 @@ public: const char *WITH_KING; const char *HE_IS_NOT_HERE; const char *HE_REJECTS_OFFER; - const char *KING_TEXT[11]; + const char *KING_TEXT[10]; public: GameResources(); diff --git a/engines/ultima/ultima1/u1dialogs/dialog.cpp b/engines/ultima/ultima1/u1dialogs/dialog.cpp index 5fb6299c44b..a068f1fce68 100644 --- a/engines/ultima/ultima1/u1dialogs/dialog.cpp +++ b/engines/ultima/ultima1/u1dialogs/dialog.cpp @@ -50,6 +50,13 @@ void Dialog::getKeypress() { msg.execute(infoArea); } +void Dialog::getInput(bool isNumeric, size_t maxCharacters) { + TreeItem *infoArea = _game->findByName("Info"); + + Shared::CInfoGetInput msg(this, isNumeric, maxCharacters); + msg.execute(infoArea); +} + void Dialog::draw() { // Redraw the game's info area U1Gfx::Info *infoArea = dynamic_cast(_game->findByName("Info")); diff --git a/engines/ultima/ultima1/u1dialogs/dialog.h b/engines/ultima/ultima1/u1dialogs/dialog.h index 455aae0f9d3..8463d1ce218 100644 --- a/engines/ultima/ultima1/u1dialogs/dialog.h +++ b/engines/ultima/ultima1/u1dialogs/dialog.h @@ -66,6 +66,11 @@ protected: * Prompts for a keypress */ void getKeypress(); + + /** + * Prompts for an input + */ + void getInput(bool isNumeric = true, size_t maxCharacters = 4); public: /** * Constructor diff --git a/engines/ultima/ultima1/u1dialogs/king.cpp b/engines/ultima/ultima1/u1dialogs/king.cpp index 80919c855bc..81a22db3b86 100644 --- a/engines/ultima/ultima1/u1dialogs/king.cpp +++ b/engines/ultima/ultima1/u1dialogs/king.cpp @@ -33,6 +33,7 @@ namespace U1Dialogs { BEGIN_MESSAGE_MAP(King, Dialog) ON_MESSAGE(ShowMsg) ON_MESSAGE(CharacterInputMsg) + ON_MESSAGE(TextInputMsg) END_MESSAGE_MAP() King::King(Ultima1Game *game) : Dialog(game), _mode(SELECT) { @@ -49,7 +50,7 @@ void King::draw() { Dialog::draw(); Shared::Gfx::VisualSurface s = getSurface(); - if (_mode != SELECT) { + if (_mode == SERVICE) { // Draw the background and frame s.clear(); s.frameRect(Rect(3, 3, _bounds.width() - 3, _bounds.height() - 3), getGame()->_borderColor); @@ -62,18 +63,33 @@ void King::draw() { void King::setMode(KingMode mode) { _mode = mode; + + switch (_mode) { + case PENCE: + addInfoMsg(_game->_res->KING_TEXT[2]); // Pence + addInfoMsg(_game->_res->KING_TEXT[4], false); // How much? + getInput(); + break; + + case SERVICE: + addInfoMsg(_game->_res->KING_TEXT[3]); + + default: + break; + } + setDirty(); } bool King::CharacterInputMsg(CCharacterInputMsg &msg) { switch (_mode) { case SELECT: - if (msg._keyState.keycode == Common::KEYCODE_s) - setMode(SERVICE); - else if (msg._keyState.keycode == Common::KEYCODE_s) + if (msg._keyState.keycode == Common::KEYCODE_p) setMode(PENCE); + else if (msg._keyState.keycode == Common::KEYCODE_s) + setMode(SERVICE); else - nothing(); + neither(); break; default: @@ -83,8 +99,48 @@ bool King::CharacterInputMsg(CCharacterInputMsg &msg) { return true; } -void King::nothing() { - addInfoMsg(_game->_res->NOTHING); +bool King::TextInputMsg(CTextInputMsg &msg) { + assert(_mode == PENCE); + const Shared::Character &c = *_game->_party; + uint amount = atoi(msg._text.c_str()); + + if (msg._escaped || !amount) { + none(); + } else if (amount > c._coins) { + notThatMuch(); + } else { + addInfoMsg(Common::String::format("%u", amount)); + giveHitPoints(amount * 3 / 2); + } + + return true; +} + +void King::neither() { + addInfoMsg(_game->_res->KING_TEXT[1]); + _game->endOfTurn(); + hide(); +} + +void King::none() { + addInfoMsg(_game->_res->NONE); + _game->endOfTurn(); + hide(); +} + +void King::notThatMuch() { + addInfoMsg(_game->_res->KING_TEXT[5]); + _game->endOfTurn(); + hide(); +} + +void King::giveHitPoints(uint amount) { + Shared::Character &c = *_game->_party; + assert(amount <= c._coins); + c._coins -= amount; + c._hitPoints += amount; + + addInfoMsg(Common::String::format(_game->_res->KING_TEXT[6], amount)); _game->endOfTurn(); hide(); } diff --git a/engines/ultima/ultima1/u1dialogs/king.h b/engines/ultima/ultima1/u1dialogs/king.h index 261d6d7ed29..d1ff7d68b51 100644 --- a/engines/ultima/ultima1/u1dialogs/king.h +++ b/engines/ultima/ultima1/u1dialogs/king.h @@ -32,6 +32,7 @@ namespace U1Dialogs { using Shared::CShowMsg; using Shared::CCharacterInputMsg; +using Shared::CTextInputMsg; /** * Dialog for talking to kings @@ -40,20 +41,35 @@ class King : public Dialog { DECLARE_MESSAGE_MAP; bool ShowMsg(CShowMsg &msg); bool CharacterInputMsg(CCharacterInputMsg &msg); - + bool TextInputMsg(CTextInputMsg &msg); enum KingMode { SELECT, PENCE, SERVICE }; private: KingMode _mode; private: - /** - * Nothing selected - */ - void nothing(); - /** * Set the mode */ void setMode(KingMode mode); + + /** + * Neither option (buy, service) selected + */ + void neither(); + + /** + * No pence entered + */ + void none(); + + /** + * Not that much + */ + void notThatMuch(); + + /** + * Give hit points + */ + void giveHitPoints(uint amount); public: CLASSDEF;