aboutsummaryrefslogtreecommitdiff
path: root/engines/titanic/pet_control
diff options
context:
space:
mode:
authorPaul Gilbert2016-04-29 07:54:54 -0400
committerPaul Gilbert2016-07-10 16:22:40 -0400
commitb117bae55a52efdfd0e7593e4e3038d22101d8bc (patch)
tree7d57ee8c7c95bfb2f854fb106cf843f9bd2413e9 /engines/titanic/pet_control
parent487f2cef0f0be9bae3b815623b4dceb02e466ce0 (diff)
downloadscummvm-rg350-b117bae55a52efdfd0e7593e4e3038d22101d8bc.tar.gz
scummvm-rg350-b117bae55a52efdfd0e7593e4e3038d22101d8bc.tar.bz2
scummvm-rg350-b117bae55a52efdfd0e7593e4e3038d22101d8bc.zip
TITANIC: Implemented conversations text input entry
Diffstat (limited to 'engines/titanic/pet_control')
-rw-r--r--engines/titanic/pet_control/pet_control.cpp10
-rw-r--r--engines/titanic/pet_control/pet_control.h4
-rw-r--r--engines/titanic/pet_control/pet_conversations.cpp99
-rw-r--r--engines/titanic/pet_control/pet_conversations.h31
-rw-r--r--engines/titanic/pet_control/pet_text.cpp47
-rw-r--r--engines/titanic/pet_control/pet_text.h22
6 files changed, 191 insertions, 22 deletions
diff --git a/engines/titanic/pet_control/pet_control.cpp b/engines/titanic/pet_control/pet_control.cpp
index 89ea9e956a..997d35b681 100644
--- a/engines/titanic/pet_control/pet_control.cpp
+++ b/engines/titanic/pet_control/pet_control.cpp
@@ -44,7 +44,7 @@ END_MESSAGE_MAP()
CPetControl::CPetControl() : CGameObject(),
_currentArea(PET_CONVERSATION), _fieldC0(0), _locked(0), _fieldC8(0),
- _treeItem1(nullptr), _treeItem2(nullptr), _hiddenRoom(nullptr),
+ _activeNPC(nullptr), _treeItem2(nullptr), _hiddenRoom(nullptr),
_drawBounds(20, 350, 620, 480) {
setup();
_timers[0] = _timers[1] = nullptr;
@@ -60,7 +60,7 @@ CPetControl::CPetControl() : CGameObject(),
void CPetControl::save(SimpleFile *file, int indent) const {
file->writeNumberLine(0, indent);
file->writeNumberLine(_currentArea, indent);
- file->writeQuotedLine(_string1, indent);
+ file->writeQuotedLine(_activeNPCName, indent);
file->writeQuotedLine(_string2, indent);
saveAreas(file, indent);
@@ -73,7 +73,7 @@ void CPetControl::load(SimpleFile *file) {
if (!val) {
_currentArea = (PetArea)file->readNumber();
- _string1 = file->readString();
+ _activeNPCName = file->readString();
_string2 = file->readString();
loadAreas(file, 0);
@@ -151,8 +151,8 @@ Rect CPetControl::getBounds() {
void CPetControl::postLoad() {
CProjectItem *root = getRoot();
- if (!_string1.empty() && root)
- _treeItem1 = root->findByName(_string1);
+ if (!_activeNPCName.empty() && root)
+ _activeNPC = root->findByName(_activeNPCName);
if (!_string2.empty() && root)
_treeItem2 = root->findByName(_string2);
diff --git a/engines/titanic/pet_control/pet_control.h b/engines/titanic/pet_control/pet_control.h
index bd896575ce..7e720b7b10 100644
--- a/engines/titanic/pet_control/pet_control.h
+++ b/engines/titanic/pet_control/pet_control.h
@@ -56,8 +56,7 @@ private:
CPetControlSub5 _sub5;
CPetControlSub7 _sub7;
CPetFrame _frame;
- CTreeItem *_treeItem1;
- CString _string1;
+ CString _activeNPCName;
CTreeItem *_treeItem2;
CString _string2;
CRoomItem *_hiddenRoom;
@@ -107,6 +106,7 @@ protected:
bool TimerMsg(CTimerMsg *msg);
public:
PetArea _currentArea;
+ CTreeItem *_activeNPC;
public:
CLASSDEF
CPetControl();
diff --git a/engines/titanic/pet_control/pet_conversations.cpp b/engines/titanic/pet_control/pet_conversations.cpp
index 850fec1668..d7fe68ef88 100644
--- a/engines/titanic/pet_control/pet_conversations.cpp
+++ b/engines/titanic/pet_control/pet_conversations.cpp
@@ -26,7 +26,7 @@
namespace Titanic {
CPetConversations::CPetConversations() : CPetSection(),
- _field414(0), _field418(0) {
+ _logScrolled(false), _field418(0) {
}
void CPetConversations::save(SimpleFile *file, int indent) const {
@@ -34,7 +34,7 @@ void CPetConversations::save(SimpleFile *file, int indent) const {
}
void CPetConversations::load(SimpleFile *file, int param) {
- _text2.load(file, param);
+ _textInput.load(file, param);
_log.load(file, param);
for (int idx = 0; idx < 3; ++idx)
@@ -100,6 +100,16 @@ bool CPetConversations::MouseDoubleClickMsg(CMouseDoubleClickMsg *msg) {
|| _scrollUp.MouseDoubleClickMsg(msg->_mousePos);
}
+bool CPetConversations::KeyCharMsg(CKeyCharMsg *msg) {
+ Common::KeyState keyState;
+ keyState.ascii = msg->_key;
+ return handleKey(keyState);
+}
+
+bool CPetConversations::VirtualKeyCharMsg(CVirtualKeyCharMsg *msg) {
+ return handleKey(msg->_keyState);
+}
+
bool CPetConversations::setupControl(CPetControl *petControl) {
if (petControl) {
_petControl = petControl;
@@ -146,21 +156,42 @@ void CPetConversations::scrollUp() {
_log.scrollUp(CScreenManager::_screenManagerPtr);
if (_petControl)
_petControl->makeDirty();
- _field414 = true;
+ _logScrolled = true;
}
void CPetConversations::scrollDown() {
_log.scrollDown(CScreenManager::_screenManagerPtr);
if (_petControl)
_petControl->makeDirty();
- _field414 = true;
+ _logScrolled = true;
+}
+
+void CPetConversations::scrollUpPage() {
+ _log.scrollUpPage(CScreenManager::_screenManagerPtr);
+ if (_petControl)
+ _petControl->makeDirty();
+ _logScrolled = true;
+}
+
+void CPetConversations::scrollDownPage() {
+ _log.scrollDownPage(CScreenManager::_screenManagerPtr);
+ if (_petControl)
+ _petControl->makeDirty();
+ _logScrolled = true;
+}
+
+void CPetConversations::scrollToTop() {
+ _log.scrollToTop(CScreenManager::_screenManagerPtr);
+ if (_petControl)
+ _petControl->makeDirty();
+ _logScrolled = true;
}
void CPetConversations::scrollToBottom() {
_log.scrollToBottom(CScreenManager::_screenManagerPtr);
if (_petControl)
_petControl->makeDirty();
- _field414 = true;
+ _logScrolled = true;
}
int CPetConversations::canSummonNPC(const CString &name) {
@@ -177,4 +208,62 @@ void CPetConversations::summonNPC(const CString &name) {
}
}
+bool CPetConversations::handleKey(const Common::KeyState &keyState) {
+ switch (keyState.keycode) {
+ case Common::KEYCODE_UP:
+ case Common::KEYCODE_KP8:
+ scrollUp();
+ break;
+ case Common::KEYCODE_DOWN:
+ case Common::KEYCODE_KP2:
+ scrollDown();
+ break;
+ case Common::KEYCODE_PAGEUP:
+ case Common::KEYCODE_KP9:
+ scrollUpPage();
+ break;
+ case Common::KEYCODE_PAGEDOWN:
+ case Common::KEYCODE_KP3:
+ scrollDownPage();
+ break;
+ case Common::KEYCODE_HOME:
+ case Common::KEYCODE_KP7:
+ scrollToTop();
+ break;
+ case Common::KEYCODE_END:
+ case Common::KEYCODE_KP1:
+ scrollToBottom();
+ break;
+ case Common::KEYCODE_BACKSPACE:
+ // Erase key in text input
+ _textInput.handleKey((char)Common::KEYCODE_BACKSPACE);
+ case Common::KEYCODE_RETURN:
+ case Common::KEYCODE_KP_ENTER:
+ // Text line finished
+ textLineEntered(_textInput.getText());
+ return true;
+ default:
+ if (keyState.ascii >= 32 && keyState.ascii)
+ _textInput.handleKey(keyState.ascii);
+ return true;
+ }
+
+ return false;
+}
+
+void CPetConversations::textLineEntered(const CString &textLine) {
+ if (textLine.empty() || !_petControl)
+ return;
+
+ if (_petControl->_activeNPC) {
+ warning("TODO: textLineEntered");
+ } else {
+ _log.addLine("There is no one here to talk to", getColor(1));
+ }
+
+ // Clear input line and scroll log down to end to show response
+ _textInput.setup();
+ scrollToBottom();
+}
+
} // End of namespace Titanic
diff --git a/engines/titanic/pet_control/pet_conversations.h b/engines/titanic/pet_control/pet_conversations.h
index 9b312729fa..f7541eda46 100644
--- a/engines/titanic/pet_control/pet_conversations.h
+++ b/engines/titanic/pet_control/pet_conversations.h
@@ -45,9 +45,9 @@ private:
CPetGfxElement _valArray2[9];
int _field30C;
CPetText _log;
- CPetText _text2;
+ CPetText _textInput;
int _valArray3[3];
- int _field414;
+ bool _logScrolled;
int _field418;
CString _string1;
private:
@@ -67,6 +67,21 @@ private:
void scrollDown();
/**
+ * Scroll up one page in the conversation log
+ */
+ void scrollUpPage();
+
+ /**
+ * Scroll down one page in the conversation log
+ */
+ void scrollDownPage();
+
+ /**
+ * Scroll to the top of the conversation log
+ */
+ void scrollToTop();
+
+ /**
* Scroll to the bottom of the conversation log
*/
void scrollToBottom();
@@ -80,6 +95,16 @@ private:
* Summon an NPC
*/
void summonNPC(const CString &name);
+
+ /**
+ * Handle a keypress
+ */
+ bool handleKey(const Common::KeyState &keyState);
+
+ /**
+ * Handles an entered text line
+ */
+ void textLineEntered(const CString &textLine);
public:
CPetConversations();
@@ -105,6 +130,8 @@ public:
virtual bool MouseButtonDownMsg(CMouseButtonDownMsg *msg);
virtual bool MouseButtonUpMsg(CMouseButtonUpMsg *msg);
virtual bool MouseDoubleClickMsg(CMouseDoubleClickMsg *msg);
+ virtual bool KeyCharMsg(CKeyCharMsg *msg);
+ virtual bool VirtualKeyCharMsg(CVirtualKeyCharMsg *msg);
};
} // End of namespace Titanic
diff --git a/engines/titanic/pet_control/pet_text.cpp b/engines/titanic/pet_control/pet_text.cpp
index 2ea10994e6..a092255d7c 100644
--- a/engines/titanic/pet_control/pet_text.cpp
+++ b/engines/titanic/pet_control/pet_text.cpp
@@ -264,6 +264,24 @@ void CPetText::scrollDown(CScreenManager *screenManager) {
screenManager->setFontNumber(oldFontNumber);
}
+void CPetText::scrollUpPage(CScreenManager *screenManager) {
+ int oldFontNumber = screenManager->setFontNumber(_fontNumber2);
+ _scrollTop -= getPageHeight(screenManager);
+ constrainScrollUp(screenManager);
+ screenManager->setFontNumber(oldFontNumber);
+}
+
+void CPetText::scrollDownPage(CScreenManager *screenManager) {
+ int oldFontNumber = screenManager->setFontNumber(_fontNumber2);
+ _scrollTop += getPageHeight(screenManager);
+ constrainScrollDown(screenManager);
+ screenManager->setFontNumber(oldFontNumber);
+}
+
+void CPetText::scrollToTop(CScreenManager *screenManager) {
+ _scrollTop = 0;
+}
+
void CPetText::scrollToBottom(CScreenManager *screenManager) {
int oldFontNumber = screenManager->setFontNumber(_fontNumber2);
_scrollTop = _bounds.height();
@@ -286,6 +304,22 @@ void CPetText::constrainScrollDown(CScreenManager *screenManager) {
_scrollTop = maxScroll;
}
+int CPetText::getPageHeight(CScreenManager *screenManager) {
+ int textHeight = _bounds.height();
+ int oldFontNumber = screenManager->setFontNumber(_fontNumber2);
+ int fontHeight = screenManager->getFontHeight();
+ screenManager->setFontNumber(oldFontNumber);
+
+ if (fontHeight) {
+ int lines = textHeight / fontHeight;
+ if (lines > 1)
+ --lines;
+ return lines * fontHeight;
+ } else {
+ return 0;
+ }
+}
+
void CPetText::addLine(const CString &str, uint color) {
addLine(str, color & 0xff, (color >> 8) & 0xff,
(color >> 16) & 0xff);
@@ -308,19 +342,18 @@ void CPetText::addLine(const CString &str, byte r, byte g, byte b) {
++_lineCount;
}
-bool CPetText::handleKey(const Common::KeyState &keyState) {
- switch (keyState.keycode) {
- case Common::KEYCODE_BACKSPACE:
+bool CPetText::handleKey(char c) {
+ switch (c) {
+ case (char)Common::KEYCODE_BACKSPACE:
deleteLastChar();
break;
- case Common::KEYCODE_RETURN:
- case Common::KEYCODE_KP_ENTER:
+ case (char)Common::KEYCODE_RETURN:
return true;
default:
- if (keyState.ascii >= 32 && keyState.ascii <= 127)
- appendText(CString(keyState.ascii, 1));
+ if (c >= 32 && c <= 127)
+ appendText(CString(c, 1));
break;
}
diff --git a/engines/titanic/pet_control/pet_text.h b/engines/titanic/pet_control/pet_text.h
index 4bb699d58e..00eab10146 100644
--- a/engines/titanic/pet_control/pet_text.h
+++ b/engines/titanic/pet_control/pet_text.h
@@ -92,6 +92,11 @@ private:
* Ensures the Y scrolling for the text is in the valid range
*/
void constrainScrollDown(CScreenManager *screenManager);
+
+ /**
+ * Get the page height for paging up and down
+ */
+ int getPageHeight(CScreenManager *screenManager);
public:
CPetText(uint count = 10);
@@ -180,6 +185,21 @@ public:
void scrollDown(CScreenManager *screenManager);
/**
+ * Scroll the text up one page
+ */
+ void scrollUpPage(CScreenManager *screenManager);
+
+ /**
+ * Scroll the text down one page
+ */
+ void scrollDownPage(CScreenManager *screenManager);
+
+ /**
+ * Scroll to the top of the text
+ */
+ void scrollToTop(CScreenManager *screenManager);
+
+ /**
* Scroll to the bottom of the text
*/
void scrollToBottom(CScreenManager *screenManager);
@@ -199,7 +219,7 @@ public:
* the current text line
* @returns True if the Enter key was pressed
*/
- bool handleKey(const Common::KeyState &keyState);
+ bool handleKey(char c);
};
} // End of namespace Titanic