aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Gilbert2016-04-21 22:13:44 -0400
committerPaul Gilbert2016-07-10 16:11:38 -0400
commitb398a5001bb128c5e53d6ac5426b926de6b73893 (patch)
treeab3fd6f73bf07cf4e2f951ae788fba89f5361730
parenta8f8e4b69eab768f38d5cd73ceecce03bd096a4d (diff)
downloadscummvm-rg350-b398a5001bb128c5e53d6ac5426b926de6b73893.tar.gz
scummvm-rg350-b398a5001bb128c5e53d6ac5426b926de6b73893.tar.bz2
scummvm-rg350-b398a5001bb128c5e53d6ac5426b926de6b73893.zip
TITANIC: Implementing CPetLoad and CPetSave
-rw-r--r--engines/titanic/core/game_object.h10
-rw-r--r--engines/titanic/pet_control/pet_element.cpp2
-rw-r--r--engines/titanic/pet_control/pet_element.h9
-rw-r--r--engines/titanic/pet_control/pet_glyphs.h33
-rw-r--r--engines/titanic/pet_control/pet_load.cpp21
-rw-r--r--engines/titanic/pet_control/pet_load.h31
-rw-r--r--engines/titanic/pet_control/pet_load_save.cpp155
-rw-r--r--engines/titanic/pet_control/pet_load_save.h86
-rw-r--r--engines/titanic/pet_control/pet_quit.cpp4
-rw-r--r--engines/titanic/pet_control/pet_quit.h6
-rw-r--r--engines/titanic/pet_control/pet_save.cpp30
-rw-r--r--engines/titanic/pet_control/pet_save.h35
-rw-r--r--engines/titanic/pet_control/pet_text.cpp5
-rw-r--r--engines/titanic/pet_control/pet_text.h2
14 files changed, 413 insertions, 16 deletions
diff --git a/engines/titanic/core/game_object.h b/engines/titanic/core/game_object.h
index b987606a4c..94c3e5418d 100644
--- a/engines/titanic/core/game_object.h
+++ b/engines/titanic/core/game_object.h
@@ -107,11 +107,6 @@ protected:
void makeDirty(const Rect &r);
/**
- * Marks the area occupied by the object as dirty, requiring re-rendering
- */
- void makeDirty();
-
- /**
* Sets a new area in the PET
*/
void setPetArea(PetArea newArea) const;
@@ -321,6 +316,11 @@ public:
* Returns the object's frame number
*/
int getFrameNumber() const { return _frameNumber; }
+
+ /**
+ * Marks the area occupied by the object as dirty, requiring re-rendering
+ */
+ void makeDirty();
};
} // End of namespace Titanic
diff --git a/engines/titanic/pet_control/pet_element.cpp b/engines/titanic/pet_control/pet_element.cpp
index 032e7fc7a0..db6b122c94 100644
--- a/engines/titanic/pet_control/pet_element.cpp
+++ b/engines/titanic/pet_control/pet_element.cpp
@@ -33,7 +33,7 @@ void CPetElement::getBounds(Rect *rect) {
*rect = Rect();
}
-bool CPetElement::proc6(const Point &pt) {
+bool CPetElement::highlightBounds(const Point &pt) {
bool result = _bounds.contains(pt);
if (result)
setMode(MODE_SELECTED);
diff --git a/engines/titanic/pet_control/pet_element.h b/engines/titanic/pet_control/pet_element.h
index 8aec1fbcf6..7ee28368b2 100644
--- a/engines/titanic/pet_control/pet_element.h
+++ b/engines/titanic/pet_control/pet_element.h
@@ -69,7 +69,14 @@ public:
*/
virtual void getBounds(Rect *rect);
- virtual bool proc6(const Point &pt);
+ /**
+ * Highlights the element if the cursor is on it
+ */
+ virtual bool highlightBounds(const Point &pt);
+
+ /**
+ * Handles processing mouse button messages
+ */
virtual bool MouseButtonDownMsg(CMouseButtonDownMsg *msg);
/**
diff --git a/engines/titanic/pet_control/pet_glyphs.h b/engines/titanic/pet_control/pet_glyphs.h
index adc7ceb5e8..9d2f283af4 100644
--- a/engines/titanic/pet_control/pet_glyphs.h
+++ b/engines/titanic/pet_control/pet_glyphs.h
@@ -23,6 +23,7 @@
#ifndef TITANIC_PET_GLYPHS_H
#define TITANIC_PET_GLYPHS_H
+#include "common/keyboard.h"
#include "titanic/core/list.h"
#include "titanic/pet_control/pet_gfx_element.h"
#include "titanic/support/rect.h"
@@ -109,17 +110,41 @@ public:
*/
virtual Rect getBounds() { return Rect(); }
- virtual int proc16() { return 0; }
+ /**
+ * Checks and updates any highlight of the glyph or any contextual
+ * information it displays
+ */
+ virtual bool checkHighlight(const Point &pt) { return false; }
+
virtual int proc17() { return 0; }
virtual int proc18() { return 0; }
virtual int proc19() { return 0; }
+
+ /**
+ * Handles mouse button messages
+ */
virtual bool MouseButtonDownMsg(CMouseButtonDownMsg *msg) { return false; }
+
virtual int proc21() { return 0; }
virtual int proc22() { return 0; }
- virtual int proc23() { return 0; }
+
+ /**
+ * Handles keypresses when the glyph is focused
+ */
+ virtual bool KeyCharMsg(Common::KeyCode key) { return false; }
+
virtual int proc24() { return 0; }
- virtual void proc25() {}
- virtual void proc26() {}
+
+ /**
+ * Unhighlight any currently highlighted element
+ */
+ virtual void unhighlightCurrent() {}
+
+ /**
+ * Highlight any currently highlighted element
+ */
+ virtual void highlightCurrent() {}
+
virtual void proc27() {}
virtual void proc28() {}
virtual int proc29() { return 0; }
diff --git a/engines/titanic/pet_control/pet_load.cpp b/engines/titanic/pet_control/pet_load.cpp
index 1008425604..f4be690bd2 100644
--- a/engines/titanic/pet_control/pet_load.cpp
+++ b/engines/titanic/pet_control/pet_load.cpp
@@ -21,8 +21,29 @@
*/
#include "titanic/pet_control/pet_load.h"
+#include "titanic/pet_control/pet_control.h"
namespace Titanic {
+bool CPetLoad::reset() {
+ CPetLoadSave::reset();
+
+ CPetControl *pet = getPetControl();
+ if (pet) {
+ setName("PetLoad", pet);
+ _btnLoadSave.reset("PetLoadOut", pet, MODE_UNSELECTED);
+ _btnLoadSave.reset("PetLoadIn", pet, MODE_SELECTED);
+ }
+
+ return true;
+}
+
+void CPetLoad::getTooltip(CPetText *text) {
+ text->setText("Load the game.");
+}
+
+void CPetLoad::execute() {
+ warning("TODO: CPetLoad::execute");
+}
} // End of namespace Titanic
diff --git a/engines/titanic/pet_control/pet_load.h b/engines/titanic/pet_control/pet_load.h
index 297cb97c54..093fca0977 100644
--- a/engines/titanic/pet_control/pet_load.h
+++ b/engines/titanic/pet_control/pet_load.h
@@ -28,6 +28,37 @@
namespace Titanic {
class CPetLoad : public CPetLoadSave {
+public:
+ /**
+ * Reset the glyph
+ */
+ virtual bool reset();
+
+ /**
+ * Highlight any currently highlighted element
+ */
+ virtual void highlightCurrent() { resetSlots(); }
+
+ /**
+ * Returns the tooltip text for when the glyph is selected
+ */
+ virtual void getTooltip(CPetText *text);
+
+ /**
+ * Highlights a save slot
+ */
+ virtual void highlightSave(int index) {}
+
+ /**
+ * Unhighlight a save slot
+ */
+ virtual void unhighlightSave(int index) {}
+
+ /**
+ * Executes the loading or saving
+ */
+ virtual void execute();
+
};
} // End of namespace Titanic
diff --git a/engines/titanic/pet_control/pet_load_save.cpp b/engines/titanic/pet_control/pet_load_save.cpp
index 7660b717c6..4ebe9d03b0 100644
--- a/engines/titanic/pet_control/pet_load_save.cpp
+++ b/engines/titanic/pet_control/pet_load_save.cpp
@@ -21,8 +21,163 @@
*/
#include "titanic/pet_control/pet_load_save.h"
+#include "titanic/pet_control/pet_control.h"
+#include "titanic/core/project_item.h"
namespace Titanic {
+int CPetLoadSave::_savegameSlotNum;
+
+bool CPetLoadSave::setup(CPetControl *petControl, CPetGlyphs *owner) {
+ CPetGlyph::setup(petControl, owner);
+ _savegameSlotNum = -1;
+
+ for (int idx = 0; idx < SAVEGAME_SLOTS_COUNT; ++idx) {
+ Rect slotRect = getSlotBounds(idx);
+ _slotNames[idx].setBounds(slotRect);
+ _slotNames[idx].resize(3);
+ _slotNames[idx].set30(22);
+ _slotNames[idx].setHasBorder(false);
+ _slotNames[idx].setup();
+ }
+
+ Rect r1(0, 0, 68, 52);
+ r1.moveTo(496, 388);
+ _btnLoadSave.setBounds(r1);
+
+ Rect r2(0, 0, 168, 78);
+ r2.moveTo(309, 377);
+ _gutter.setBounds(r2);
+ return true;
+}
+
+bool CPetLoadSave::reset() {
+ highlightChange();
+
+ CPetControl *pet = getPetControl();
+ if (pet) {
+ _gutter.reset("PetSaveGutter", pet, MODE_UNSELECTED);
+ }
+
+ return true;
+}
+
+void CPetLoadSave::draw2(CScreenManager *screenManager) {
+ _gutter.draw(screenManager);
+
+ for (int idx = 0; idx < SAVEGAME_SLOTS_COUNT; ++idx)
+ _slotNames[idx].draw(screenManager);
+
+ _btnLoadSave.draw(screenManager);
+}
+
+bool CPetLoadSave::checkHighlight(const Point &pt) {
+ if (_btnLoadSave.highlightBounds(pt))
+ return true;
+
+ checkSlotsHighlight(pt);
+ return false;
+}
+
+bool CPetLoadSave::MouseButtonDownMsg(CMouseButtonDownMsg *msg) {
+ if (_btnLoadSave.MouseButtonDownMsg(msg)) {
+ execute();
+ resetSlots();
+ return true;
+ } else {
+ return false;
+ }
+}
+
+bool CPetLoadSave::KeyCharMsg(Common::KeyCode key) {
+ switch (key) {
+ case Common::KEYCODE_TAB:
+ case Common::KEYCODE_DOWN:
+ case Common::KEYCODE_KP2:
+ if (_savegameSlotNum != -1) {
+ highlightSlot((_savegameSlotNum + 1) % 5);
+ getPetControl()->makeDirty();
+ }
+ return true;
+
+ case Common::KEYCODE_UP:
+ case Common::KEYCODE_KP8:
+ if (_savegameSlotNum != -1) {
+ int slotNum = --_savegameSlotNum;
+ highlightSlot((slotNum == -1) ? SAVEGAME_SLOTS_COUNT - 1 : slotNum);
+ getPetControl()->makeDirty();
+ }
+ return true;
+
+ case Common::KEYCODE_RETURN:
+ case Common::KEYCODE_KP_ENTER:
+ execute();
+ return true;
+
+ default:
+ return false;
+ }
+}
+
+Rect CPetLoadSave::getSlotBounds(int index) {
+ return Rect(323, 376 + index * 16, 473, 392 + index * 16);
+}
+
+void CPetLoadSave::resetSlots() {
+ CPetControl *pet = getPetControl();
+ CProjectItem *project = pet ? pet->getRoot() : nullptr;
+
+ for (int idx = 0; idx < SAVEGAME_SLOTS_COUNT; ++idx) {
+ _slotNames[idx].setText("Empty");
+
+ if (project) {
+ warning("TODO: Get savegame name");
+ }
+ }
+
+ highlightSlot(_savegameSlotNum);
+}
+
+void CPetLoadSave::highlightSlot(int index) {
+ unhighlightSave(_savegameSlotNum);
+ _savegameSlotNum = index;
+ highlightChange();
+ highlightSave(_savegameSlotNum);
+}
+
+void CPetLoadSave::highlightChange() {
+ CPetSection *section = getPetSection();
+
+ uint col = section ? section->getColor(3) : 0;
+ for (int idx = 0; idx < SAVEGAME_SLOTS_COUNT; ++idx)
+ _slotNames[idx].setColor(col);
+
+ // TODO: Unknown if check
+ if (true) {
+ col = section ? section->getColor(4) : 0;
+ _slotNames[_savegameSlotNum].setColor(0, col);
+ }
+}
+
+bool CPetLoadSave::checkSlotsHighlight(const Point &pt) {
+ for (int idx = 0; idx < SAVEGAME_SLOTS_COUNT; ++idx) {
+ if (isSlotHighlighted(idx, pt)) {
+ highlightSlot(idx);
+ return true;
+ }
+ }
+
+ return false;
+}
+
+bool CPetLoadSave::isSlotHighlighted(int index, const Point &pt) {
+ Rect r = getSlotBounds(index);
+ if (r.contains(pt)) {
+ highlightSlot(index);
+ return true;
+ } else {
+ return false;
+ }
+}
} // End of namespace Titanic
diff --git a/engines/titanic/pet_control/pet_load_save.h b/engines/titanic/pet_control/pet_load_save.h
index 780fd75af0..ef7e54a3f2 100644
--- a/engines/titanic/pet_control/pet_load_save.h
+++ b/engines/titanic/pet_control/pet_load_save.h
@@ -24,14 +24,96 @@
#define TITANIC_PET_LOAD_SAVE_H
#include "titanic/pet_control/pet_glyphs.h"
+#include "titanic/pet_control/pet_text.h"
namespace Titanic {
+#define SAVEGAME_SLOTS_COUNT 5
+
class CPetLoadSave : public CPetGlyph {
+private:
+ /**
+ * Get the rect area for a given savegame name will be displayed in
+ */
+ Rect getSlotBounds(int index);
+
+ /**
+ * Highlight one of the slots
+ */
+ void highlightSlot(int index);
+
+ /**
+ * Called when savegame slot highlight changes or the view is reset
+ */
+ void highlightChange();
+
+ /**
+ * Check for whether a slot is under the passed point
+ */
+ bool checkSlotsHighlight(const Point &pt);
+
+ /**
+ * Checks if a point is within a given saveame slot
+ */
+ bool isSlotHighlighted(int index, const Point &pt);
+protected:
+ CPetText _slotNames[SAVEGAME_SLOTS_COUNT];
+ CPetGfxElement _btnLoadSave;
+ CPetGfxElement _gutter;
+ static int _savegameSlotNum;
protected:
- CPetGfxElement _element1;
- CPetGfxElement _element2;
+ /**
+ * Reset the slot names list
+ */
+ void resetSlots();
public:
+ /**
+ * Setup the glyph
+ */
+ virtual bool setup(CPetControl *petControl, CPetGlyphs *owner);
+
+ /**
+ * Reset the glyph
+ */
+ virtual bool reset();
+
+ /**
+ * Handles any secondary drawing of the glyph
+ */
+ virtual void draw2(CScreenManager *screenManager);
+
+ /**
+ * Checks and updates any highlight of the glyph or any contextual
+ * information it displays
+ */
+ virtual bool checkHighlight(const Point &pt);
+
+ /**
+ * Handles mouse button messages
+ */
+ virtual bool MouseButtonDownMsg(CMouseButtonDownMsg *msg);
+
+ /**
+ * Handles keypresses when the glyph is focused
+ */
+ virtual bool KeyCharMsg(Common::KeyCode key);
+
+ virtual void resetSaves() { resetSlots(); }
+
+ /**
+ * Highlights a save slot
+ */
+ virtual void highlightSave(int index) = 0;
+
+ /**
+ * Unhighlight a save slot
+ */
+ virtual void unhighlightSave(int index) = 0;
+
+ /**
+ * Executes the loading or saving
+ */
+ virtual void execute() = 0;
};
} // End of namespace Titanic
diff --git a/engines/titanic/pet_control/pet_quit.cpp b/engines/titanic/pet_control/pet_quit.cpp
index c3d6e4e40d..be7257f209 100644
--- a/engines/titanic/pet_control/pet_quit.cpp
+++ b/engines/titanic/pet_control/pet_quit.cpp
@@ -66,8 +66,8 @@ void CPetQuit::draw2(CScreenManager *screenManager) {
_btnYes.draw(screenManager);
}
-bool CPetQuit::proc16(const Point &pt) {
- return !_btnYes.proc6(pt);
+bool CPetQuit::checkHighlight(const Point &pt) {
+ return !_btnYes.highlightBounds(pt);
}
bool CPetQuit::mouseButtonDownMsg(CMouseButtonDownMsg *msg) {
diff --git a/engines/titanic/pet_control/pet_quit.h b/engines/titanic/pet_control/pet_quit.h
index 213ed450d4..cfe3e6fb76 100644
--- a/engines/titanic/pet_control/pet_quit.h
+++ b/engines/titanic/pet_control/pet_quit.h
@@ -49,7 +49,11 @@ public:
*/
virtual void draw2(CScreenManager *screenManager);
- virtual bool proc16(const Point &pt);
+ /**
+ * Checks and updates any highlight of the glyph or any contextual
+ * information it displays
+ */
+ virtual bool checkHighlight(const Point &pt);
virtual bool mouseButtonDownMsg(CMouseButtonDownMsg *msg);
diff --git a/engines/titanic/pet_control/pet_save.cpp b/engines/titanic/pet_control/pet_save.cpp
index d8835e1920..a2e458b52a 100644
--- a/engines/titanic/pet_control/pet_save.cpp
+++ b/engines/titanic/pet_control/pet_save.cpp
@@ -21,7 +21,37 @@
*/
#include "titanic/pet_control/pet_save.h"
+#include "titanic/pet_control/pet_control.h"
namespace Titanic {
+bool CPetSave::reset() {
+ CPetLoadSave::reset();
+
+ CPetControl *pet = getPetControl();
+ if (pet) {
+ setName("PetSave", pet);
+ _btnLoadSave.reset("PetSaveOut", pet, MODE_UNSELECTED);
+ _btnLoadSave.reset("PetSaveIn", pet, MODE_SELECTED);
+ }
+
+ return true;
+}
+
+void CPetSave::getTooltip(CPetText *text) {
+ text->setText("Save the game.");
+}
+
+void CPetSave::highlightSave(int index) {
+ warning("TODO: CPetSave::highlightSave");
+}
+
+void CPetSave::unhighlightSave(int index) {
+ warning("TODO: CPetSave::unhighlightSave");
+}
+
+void CPetSave::execute() {
+ warning("TODO: CPetSave::execute");
+}
+
} // End of namespace Titanic
diff --git a/engines/titanic/pet_control/pet_save.h b/engines/titanic/pet_control/pet_save.h
index 21e59cbf96..006b2cd95a 100644
--- a/engines/titanic/pet_control/pet_save.h
+++ b/engines/titanic/pet_control/pet_save.h
@@ -28,6 +28,41 @@
namespace Titanic {
class CPetSave : public CPetLoadSave {
+public:
+ /**
+ * Reset the glyph
+ */
+ virtual bool reset();
+
+ /**
+ * Unhighlight any currently highlighted element
+ */
+ virtual void unhighlightCurrent() { unhighlightSave(_savegameSlotNum); }
+
+ /**
+ * Highlight any currently highlighted element
+ */
+ virtual void highlightCurrent() { highlightSave(_savegameSlotNum); }
+
+ /**
+ * Returns the tooltip text for when the glyph is selected
+ */
+ virtual void getTooltip(CPetText *text);
+
+ /**
+ * Highlights a save slot
+ */
+ virtual void highlightSave(int index);
+
+ /**
+ * Unhighlight a save slot
+ */
+ virtual void unhighlightSave(int index);
+
+ /**
+ * Executes the loading or saving
+ */
+ virtual void execute();
};
} // End of namespace Titanic
diff --git a/engines/titanic/pet_control/pet_text.cpp b/engines/titanic/pet_control/pet_text.cpp
index af00473050..faa25d05ad 100644
--- a/engines/titanic/pet_control/pet_text.cpp
+++ b/engines/titanic/pet_control/pet_text.cpp
@@ -174,4 +174,9 @@ void CPetText::setColor(uint col) {
_textB = (col >> 16) & 0xff;
}
+void CPetText::set30(int val) {
+ if (val >= -1 && val < 257)
+ _field30 = val;
+}
+
} // End of namespace Titanic
diff --git a/engines/titanic/pet_control/pet_text.h b/engines/titanic/pet_control/pet_text.h
index 55416fdc7d..17707117e5 100644
--- a/engines/titanic/pet_control/pet_text.h
+++ b/engines/titanic/pet_control/pet_text.h
@@ -119,6 +119,8 @@ public:
* Set text color
*/
void setColor(uint col);
+
+ void set30(int val);
};
} // End of namespace Titanic