ULTIMA1: Drop type selection for Drop action

This commit is contained in:
dreammaster 2020-01-21 06:24:18 +00:00 committed by Paul Gilbert
parent 499067af38
commit 61106900d2
14 changed files with 115 additions and 43 deletions

View File

@ -43,8 +43,8 @@ Maps::Map *Action::getMap() {
return static_cast<Maps::Map *>(getGame()->getMap());
}
void Action::addInfoMsg(const Common::String &text, bool newLine, bool replaceLine) {
CInfoMsg msg(text, newLine, replaceLine);
void Action::addInfoMsg(const Common::String &text, bool newLine) {
CInfoMsg msg(text, newLine);
msg.execute(getView());
}
@ -55,3 +55,4 @@ void Action::playFX(uint effectId) {
} // End of namespace Actions
} // End of namespace Shared
} // End of namespace Ultima

View File

@ -65,9 +65,8 @@ public:
* Adds a text string to the info area
* @param text Text to add
* @param newLine Whether to apply a newline at the end
* @param replaceLine If true, replaces the current last line
*/
void addInfoMsg(const Common::String &text, bool newLine = true, bool replaceLine = false);
void addInfoMsg(const Common::String &text, bool newLine = true);
/**
* Play a sound effect

View File

@ -214,7 +214,7 @@ void MapWidget::synchronize(Common::Serializer &s) {
}
void MapWidget::addInfoMsg(const Common::String &text, bool newLine) {
CInfoMsg msg(text, newLine, false);
CInfoMsg msg(text, newLine);
msg.execute(_game->getView());
}

View File

@ -246,7 +246,7 @@ MESSAGE3(CInfoGetInput, MessageTarget *, responder, (MessageTarget *)nullptr, bo
/**
* Adds text strings to the info area
*/
MESSAGE3(CInfoMsg, Common::String, text, "", bool, newLine, true, bool, replaceLine, false);
MESSAGE2(CInfoMsg, Common::String, text, "", bool, newLine, true);
/**
* Signals an unknown/unhandled keypress

View File

@ -49,8 +49,6 @@ bool Info::InfoMsg(CInfoMsg &msg) {
// Add new text
if (_lines.empty())
_lines.push_back(" ");
if (msg._replaceLine)
_lines.back() = _lines.back().firstChar();
_lines.back() += msg._text;

View File

@ -207,8 +207,8 @@ void MapBase::setDirection(Direction dir) {
_playerWidget->_direction = dir;
}
void MapBase::addInfoMsg(const Common::String &text, bool newLine, bool replaceLine) {
CInfoMsg msg(text, newLine, replaceLine);
void MapBase::addInfoMsg(const Common::String &text, bool newLine) {
CInfoMsg msg(text, newLine);
msg.execute(_game->getView());
}

View File

@ -126,7 +126,7 @@ protected:
* @param newLine Whether to apply a newline at the end
* @param replaceLine If true, replaces the current last line
*/
void addInfoMsg(const Common::String &text, bool newLine = true, bool replaceLine = false);
void addInfoMsg(const Common::String &text, bool newLine = true);
public:
Point _size; // X, Y size of the map
Point _tilesPerOrigTile; // For enhanced modes, number of tiles per original game tile

View File

@ -39,8 +39,8 @@ void MapWidget::synchronize(Common::Serializer &s) {
s.syncString(_name);
}
void MapWidget::addInfoMsg(const Common::String &text, bool newLine, bool replaceLine) {
CInfoMsg msg(text, newLine, replaceLine);
void MapWidget::addInfoMsg(const Common::String &text, bool newLine) {
CInfoMsg msg(text, newLine);
msg.execute(_game->getView());
}

View File

@ -88,7 +88,7 @@ public:
* @param newLine Whether to apply a newline at the end
* @param replaceLine If true, replaces the current last line
*/
void addInfoMsg(const Common::String &text, bool newLine = true, bool replaceLine = false);
void addInfoMsg(const Common::String &text, bool newLine = true);
/**
* Get the tile for the widget

View File

@ -159,7 +159,7 @@ void MapCityCastle::loadTownCastleData() {
void MapCityCastle::drop() {
U1Dialogs::Drop *drop = new U1Dialogs::Drop(_game);
_game->setPopup(drop);
drop->show();
}
void MapCityCastle::inform() {

View File

@ -35,9 +35,9 @@ Maps::Ultima1Map *Dialog::getMap() {
return static_cast<Maps::Ultima1Map *>(_game->getMap());
}
void Dialog::addInfoMsg(const Common::String &text, bool newLine, bool replaceLine) {
Shared::CInfoMsg msg(text, newLine, replaceLine);
msg.execute(_game->getView());
void Dialog::addInfoMsg(const Common::String &text, bool newLine) {
Shared::CInfoMsg msg(text, newLine);
msg.execute(_parentView);
}
} // End of namespace U1Dialogs

View File

@ -58,7 +58,7 @@ protected:
* @param newLine Whether to apply a newline at the end
* @param replaceLine If true, replaces the current last line
*/
void addInfoMsg(const Common::String &text, bool newLine = true, bool replaceLine = false);
void addInfoMsg(const Common::String &text, bool newLine = true);
public:
/**
* Constructor

View File

@ -23,6 +23,7 @@
#include "ultima/ultima1/u1dialogs/drop.h"
#include "ultima/ultima1/game.h"
#include "ultima/ultima1/core/resources.h"
#include "ultima/shared/gfx/text_cursor.h"
#include "ultima/shared/engine/messages.h"
namespace Ultima {
@ -30,38 +31,88 @@ namespace Ultima1 {
namespace U1Dialogs {
BEGIN_MESSAGE_MAP(Drop, Dialog)
ON_MESSAGE(ShowMsg)
ON_MESSAGE(TextInputMsg)
ON_MESSAGE(KeypressMsg)
END_MESSAGE_MAP()
Drop::Drop(Ultima1Game *game) : Dialog(game), _mode(SELECT) {
// The dialog itself doesn't initially display, instead we add a prompt to the info area for
// what kind of thing to drop
// The drop dialog covers the entire screen, but doesn't erase what's under it
_bounds = Common::Rect(0, 0, 320, 200);
}
void Drop::draw() {
return;
}
bool Drop::KeypressMsg(CKeypressMsg &msg) {
switch (_mode) {
case SELECT:
_game->_textCursor->setVisible(false);
bool Drop::ShowMsg(CShowMsg &msg) {
// Add a prompt in the info area for what kind of thing to drop
addInfoMsg(getGame()->_res->DROP_PENCE_WEAPON_ARMOR);
Shared::CInfoGetKeypress keyMsg(this);
keyMsg.execute(_game);
switch (msg._keyState.keycode) {
case Common::KEYCODE_p:
_mode = DROP_PENCE;
setDirty();
break;
case Common::KEYCODE_w:
_mode = DROP_WEAPON;
setDirty();
break;
case Common::KEYCODE_a:
_mode = DROP_ARMOR;
setDirty();
break;
default:
nothing();
break;
}
break;
return true;
}
bool Drop::TextInputMsg(CTextInputMsg &msg) {
if (msg._escaped) {
addInfoMsg(Common::String::format("%s %s", _game->_res->ACTION_NAMES[3], _game->_res->NOTHING), true, true);
hide();
delete this;
default:
break;
}
return true;
}
void Drop::nothing() {
addInfoMsg(Common::String::format(" %s", _game->_res->NOTHING));
hide();
delete this;
}
void Drop::draw() {
switch (_mode) {
case SELECT:
drawSelection();
break;
case DROP_PENCE:
drawDropPence();
break;
case DROP_WEAPON:
drawDropWeapon();
break;
case DROP_ARMOR:
drawDropArmor();
break;
}
}
void Drop::drawSelection() {
Shared::Gfx::VisualSurface s = getSurface();
s.writeString(_game->_res->DROP_PENCE_WEAPON_ARMOR, TextPoint(1, 24), _game->_textColor);
_game->_textCursor->setPosition(TextPoint(1 + strlen(_game->_res->DROP_PENCE_WEAPON_ARMOR), 24));
_game->_textCursor->setVisible(true);
}
void Drop::drawDropPence() {
// TODO
}
void Drop::drawDropWeapon() {
// TODO
}
void Drop::drawDropArmor() {
// TODO
}
} // End of namespace U1Dialogs
} // End of namespace Ultima1
} // End of namespace Ultima

View File

@ -29,20 +29,43 @@ namespace Ultima {
namespace Ultima1 {
namespace U1Dialogs {
using Shared::CShowMsg;
using Shared::CTextInputMsg;
using Shared::CKeypressMsg;
/**
* Implements the drop dialog
*/
class Drop : public Dialog {
DECLARE_MESSAGE_MAP;
bool ShowMsg(CShowMsg &msg);
bool TextInputMsg(CTextInputMsg &msg);
bool KeypressMsg(CKeypressMsg &msg);
enum Mode { SELECT, DROP_PENCE, DROP_WEAPON, DROP_ARMOR };
private:
Mode _mode;
private:
/**
* Nothing selected
*/
void nothing();
/**
* Draw the initial mode selection display
*/
void drawSelection();
/**
* Draw the drop pence display
*/
void drawDropPence();
/**
* Draw the drop weapon display
*/
void drawDropWeapon();
/**
* Draw the drop armor display
*/
void drawDropArmor();
public:
CLASSDEF;