mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-15 14:18:37 +00:00
TITANIC: Added Pet Inventorty virtual methods
This commit is contained in:
parent
5fe1f73159
commit
42c8ac1c88
@ -131,7 +131,7 @@ void CPetControl::draw(CScreenManager *screenManager) {
|
||||
|
||||
if (!bounds.isEmpty()) {
|
||||
if (_fieldC8 >= 0) {
|
||||
_inventory.proc5(_fieldC8);
|
||||
_inventory.changed(_fieldC8);
|
||||
_fieldC8 = -1;
|
||||
}
|
||||
|
||||
|
@ -182,7 +182,7 @@ Point CPetGlyphs::getPosition(int index) const {
|
||||
return tempPoint;
|
||||
}
|
||||
|
||||
Rect CPetGlyphs::getRect(int index) {
|
||||
Rect CPetGlyphs::getRect(int index) const {
|
||||
Point pt = getPosition(index);
|
||||
return Rect(pt.x, pt.y, pt.x + 52, pt.y + 52);
|
||||
}
|
||||
@ -235,7 +235,7 @@ int CPetGlyphs::getHighlightedIndex(int index) const {
|
||||
return (idx >= 0 && idx < _numVisibleGlyphs) ? idx : -1;
|
||||
}
|
||||
|
||||
int CPetGlyphs::getItemIndex(int index) {
|
||||
int CPetGlyphs::getItemIndex(int index) const {
|
||||
return _firstVisibleIndex + index;
|
||||
}
|
||||
|
||||
@ -248,8 +248,8 @@ void CPetGlyphs::setSelectedIndex(int index) {
|
||||
}
|
||||
}
|
||||
|
||||
CPetGlyph *CPetGlyphs::getGlyph(int index) {
|
||||
for (iterator i = begin(); i != end(); ++i) {
|
||||
CPetGlyph *CPetGlyphs::getGlyph(int index) const {
|
||||
for (const_iterator i = begin(); i != end(); ++i) {
|
||||
if (index-- == 0)
|
||||
return *i;
|
||||
}
|
||||
@ -414,7 +414,9 @@ bool CPetGlyphs::KeyCharMsg(int key) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CPetGlyphs::VirtualKeyCharMsg(int key) {
|
||||
bool CPetGlyphs::VirtualKeyCharMsg(CVirtualKeyCharMsg *msg) {
|
||||
Common::KeyCode key = msg->_keyState.keycode;
|
||||
|
||||
switch (key) {
|
||||
case Common::KEYCODE_LEFT:
|
||||
decSelection();
|
||||
@ -430,7 +432,7 @@ bool CPetGlyphs::VirtualKeyCharMsg(int key) {
|
||||
|
||||
if (_highlightIndex >= 0) {
|
||||
CPetGlyph *glyph = getGlyph(_highlightIndex);
|
||||
if (glyph && glyph->VirtualKeyCharMsg(key))
|
||||
if (glyph && glyph->VirtualKeyCharMsg(msg))
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -502,7 +504,7 @@ void CPetGlyphs::decSelection() {
|
||||
}
|
||||
}
|
||||
|
||||
CGameObject *CPetGlyphs::getObjectAt(const Point &pt) {
|
||||
CGameObject *CPetGlyphs::getObjectAt(const Point &pt) const {
|
||||
for (int idx = 0; idx < _numVisibleGlyphs; ++idx) {
|
||||
Rect glyphRect = getRect(idx);
|
||||
if (glyphRect.contains(pt)) {
|
||||
@ -532,4 +534,33 @@ Point CPetGlyphs::getHighlightedGlyphPos() const {
|
||||
return Point(0, 0);
|
||||
}
|
||||
|
||||
bool CPetGlyphs::areItemsValid() const {
|
||||
for (const_iterator i = begin(); i != end(); ++i) {
|
||||
if (!(*i)->isValid())
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CPetGlyphs::removeInvalid() {
|
||||
if (!areItemsValid()) {
|
||||
changeHighlight(-1);
|
||||
|
||||
for (iterator i = begin(); i != end(); ) {
|
||||
CPetGlyph *glyph = *i;
|
||||
|
||||
if (!glyph->isValid()) {
|
||||
i = erase(i);
|
||||
delete glyph;
|
||||
} else {
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
_firstVisibleIndex = CLIP(_firstVisibleIndex, 0,
|
||||
(int)size() - _numVisibleGlyphs);
|
||||
}
|
||||
}
|
||||
|
||||
} // End of namespace Titanic
|
||||
|
@ -128,15 +128,20 @@ public:
|
||||
*/
|
||||
virtual bool MouseButtonUpMsg(const Point &pt) { return false; }
|
||||
|
||||
virtual int proc21() { return 0; }
|
||||
virtual int proc22() { return 0; }
|
||||
/**
|
||||
* Handles mouse double-click messages
|
||||
*/
|
||||
virtual bool MouseDoubleClickMsg(const CMouseDoubleClickMsg *msg) { return false; }
|
||||
|
||||
/**
|
||||
* Handles keypresses when the glyph is focused
|
||||
* Handles keypresses
|
||||
*/
|
||||
virtual bool KeyCharMsg(int key) { return false; }
|
||||
|
||||
virtual bool VirtualKeyCharMsg(int key) { return false; }
|
||||
/**
|
||||
* Handles keypresses
|
||||
*/
|
||||
virtual bool VirtualKeyCharMsg(CVirtualKeyCharMsg *msg) { return false; }
|
||||
|
||||
/**
|
||||
* Unhighlight any currently highlighted element
|
||||
@ -182,9 +187,9 @@ public:
|
||||
virtual bool proc33(CPetGlyph *glyph) { return true; }
|
||||
|
||||
/**
|
||||
* Return whether the glyph has an associated image
|
||||
* Return whether the glyph is currently valid
|
||||
*/
|
||||
virtual bool hasImage() const { return true; }
|
||||
virtual bool isValid() const { return true; }
|
||||
|
||||
/**
|
||||
* Called on a highlighted item when PET area is entered
|
||||
@ -247,7 +252,7 @@ private:
|
||||
/**
|
||||
* Get a rect for the glyph
|
||||
*/
|
||||
Rect getRect(int index);
|
||||
Rect getRect(int index) const;
|
||||
|
||||
/**
|
||||
* Returns the on-screen index for the highlight to be shown at
|
||||
@ -257,7 +262,7 @@ private:
|
||||
/**
|
||||
* Returns the index of a glyph given the visible on-screen glyph number
|
||||
*/
|
||||
int getItemIndex(int index);
|
||||
int getItemIndex(int index) const;
|
||||
|
||||
/**
|
||||
* Set the item index
|
||||
@ -267,7 +272,7 @@ private:
|
||||
/**
|
||||
* Return a specified glyph
|
||||
*/
|
||||
CPetGlyph *getGlyph(int index);
|
||||
CPetGlyph *getGlyph(int index) const;
|
||||
|
||||
/**
|
||||
* Scrolls the glyphs to the left
|
||||
@ -288,6 +293,11 @@ private:
|
||||
* Make the PET dirty
|
||||
*/
|
||||
void makePetDirty();
|
||||
|
||||
/**
|
||||
* Returns true if all the glyphs are in a valid state
|
||||
*/
|
||||
bool areItemsValid() const;
|
||||
protected:
|
||||
int _firstVisibleIndex;
|
||||
int _totalGlyphs;
|
||||
@ -376,6 +386,11 @@ public:
|
||||
*/
|
||||
bool MouseButtonUpMsg(const Point &pt);
|
||||
|
||||
/**
|
||||
* Mouse double click message
|
||||
*/
|
||||
bool MouseDoubleClickMsg(const Point &pt) { return true; }
|
||||
|
||||
/**
|
||||
* Mouse drag start messagge
|
||||
*/
|
||||
@ -399,7 +414,7 @@ public:
|
||||
/**
|
||||
* Virtual key message
|
||||
*/
|
||||
bool VirtualKeyCharMsg(int key);
|
||||
bool VirtualKeyCharMsg(CVirtualKeyCharMsg *msg);
|
||||
|
||||
/**
|
||||
* When the PET section is entered, passes onto the highlighted
|
||||
@ -453,7 +468,7 @@ public:
|
||||
/**
|
||||
* Returns the object associated the glyph under the specified position
|
||||
*/
|
||||
CGameObject *getObjectAt(const Point &pt);
|
||||
CGameObject *getObjectAt(const Point &pt) const;
|
||||
|
||||
/**
|
||||
* Returns true if the specified glyph is the currently highlighted one
|
||||
@ -464,6 +479,12 @@ public:
|
||||
* Get the top-left position of the currently highlighted glyph
|
||||
*/
|
||||
Point getHighlightedGlyphPos() const;
|
||||
|
||||
/**
|
||||
* Removes any glyphs from the list that no longer have any images
|
||||
* associated with them
|
||||
*/
|
||||
void removeInvalid();
|
||||
};
|
||||
|
||||
} // End of namespace Titanic
|
||||
|
@ -41,8 +41,9 @@ bool CPetInventory::setup(CPetControl *petControl) {
|
||||
bool CPetInventory::reset() {
|
||||
_items.reset();
|
||||
_text.setup();
|
||||
_text.setColor(getColor(0));
|
||||
_text.setLineColor(0, getColor(0));
|
||||
|
||||
// TODO
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -56,9 +57,45 @@ Rect CPetInventory::getBounds() {
|
||||
return _movie ? _movie->getBounds() : Rect();
|
||||
}
|
||||
|
||||
void CPetInventory::changed(int changeType) {
|
||||
switch (changeType) {
|
||||
case 0:
|
||||
case 2:
|
||||
itemsChanged();
|
||||
break;
|
||||
case 1:
|
||||
removeInvalid();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool CPetInventory::MouseButtonDownMsg(CMouseButtonDownMsg *msg) {
|
||||
return _items.MouseButtonDownMsg(msg->_mousePos);
|
||||
}
|
||||
|
||||
bool CPetInventory::MouseDragStartMsg(CMouseDragStartMsg *msg) {
|
||||
bool result = _items.MouseDragStartMsg(msg);
|
||||
if (result)
|
||||
_petControl->makeDirty();
|
||||
return result;
|
||||
}
|
||||
|
||||
bool CPetInventory::MouseButtonUpMsg(CMouseButtonUpMsg *msg) {
|
||||
return _items.MouseButtonUpMsg(msg->_mousePos);
|
||||
}
|
||||
|
||||
bool CPetInventory::MouseDoubleClickMsg(CMouseDoubleClickMsg *msg) {
|
||||
return _items.MouseDoubleClickMsg(msg->_mousePos);
|
||||
}
|
||||
|
||||
bool CPetInventory::VirtualKeyCharMsg(CVirtualKeyCharMsg *msg) {
|
||||
return _items.VirtualKeyCharMsg(msg);
|
||||
}
|
||||
|
||||
CGameObject *CPetInventory::dragEnd(const Point &pt) const {
|
||||
warning("TODO: CPetInventory::dragEnd");
|
||||
return nullptr;
|
||||
return _items.getObjectAt(pt);
|
||||
}
|
||||
|
||||
bool CPetInventory::isValid(CPetControl *petControl) {
|
||||
@ -212,4 +249,8 @@ void CPetInventory::playMovie(CGameObject *movie, int flag) {
|
||||
}
|
||||
}
|
||||
|
||||
void CPetInventory::removeInvalid() {
|
||||
_items.removeInvalid();
|
||||
}
|
||||
|
||||
} // End of namespace Titanic
|
||||
|
@ -53,6 +53,11 @@ private:
|
||||
* Get the index of an item added to the PET
|
||||
*/
|
||||
int getItemIndex(CGameObject *item) const;
|
||||
|
||||
/**
|
||||
* Remove any invalid inventory glyphs
|
||||
*/
|
||||
void removeInvalid();
|
||||
public:
|
||||
CPetInventory();
|
||||
|
||||
@ -77,31 +82,45 @@ public:
|
||||
virtual Rect getBounds();
|
||||
|
||||
/**
|
||||
* Save the data for the class to file
|
||||
* Called when a general change occurs
|
||||
*/
|
||||
virtual void save(SimpleFile *file, int indent) const;
|
||||
virtual void changed(int changeType);
|
||||
|
||||
/**
|
||||
* Load the data for the class from file
|
||||
* Following are handlers for the various messages that the PET can
|
||||
* pass onto the currently active section/area
|
||||
*/
|
||||
virtual void load(SimpleFile *file, int param);
|
||||
virtual bool MouseButtonDownMsg(CMouseButtonDownMsg *msg);
|
||||
virtual bool MouseDragStartMsg(CMouseDragStartMsg *msg);
|
||||
virtual bool MouseButtonUpMsg(CMouseButtonUpMsg *msg);
|
||||
virtual bool MouseDoubleClickMsg(CMouseDoubleClickMsg *msg);
|
||||
virtual bool VirtualKeyCharMsg(CVirtualKeyCharMsg *msg);
|
||||
|
||||
/**
|
||||
* Returns item a drag-drop operation has dropped on, if any
|
||||
*/
|
||||
virtual CGameObject *dragEnd(const Point &pt) const;
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if the object is in a valid state
|
||||
*/
|
||||
virtual bool isValid(CPetControl *petControl);
|
||||
|
||||
/**
|
||||
* Load the data for the class from file
|
||||
*/
|
||||
virtual void load(SimpleFile *file, int param);
|
||||
|
||||
/**
|
||||
* Called after a game has been loaded
|
||||
*/
|
||||
virtual void postLoad();
|
||||
|
||||
/**
|
||||
* Save the data for the class to file
|
||||
*/
|
||||
virtual void save(SimpleFile *file, int indent) const;
|
||||
|
||||
/**
|
||||
* Called when a section is switched to
|
||||
*/
|
||||
@ -112,6 +131,14 @@ public:
|
||||
*/
|
||||
virtual void leave();
|
||||
|
||||
/**
|
||||
* Get a reference to the tooltip text associated with the section
|
||||
*/
|
||||
virtual CPetText *getText() { return &_text; }
|
||||
|
||||
/**
|
||||
* Special retrieval of glyph background image
|
||||
*/
|
||||
virtual CGameObject *getBackground(int index) const;
|
||||
|
||||
/**
|
||||
|
@ -109,9 +109,9 @@ public:
|
||||
virtual void getTooltip(CPetText *text);
|
||||
|
||||
/**
|
||||
* Return whether the glyph has an associated image
|
||||
* Return whether the glyph is currently valid
|
||||
*/
|
||||
virtual bool hasImage() const { return _item && _background; }
|
||||
virtual bool isValid() const { return _item && _background; }
|
||||
|
||||
/**
|
||||
* Returns the object associated with the glyph
|
||||
|
@ -76,7 +76,7 @@ bool CPetRealLife::KeyCharMsg(CKeyCharMsg *msg) {
|
||||
}
|
||||
|
||||
bool CPetRealLife::VirtualKeyCharMsg(CVirtualKeyCharMsg *msg) {
|
||||
return _glyphs.VirtualKeyCharMsg(msg->_keyState.keycode);
|
||||
return _glyphs.VirtualKeyCharMsg(msg);
|
||||
}
|
||||
|
||||
void CPetRealLife::postLoad() {
|
||||
|
@ -69,8 +69,6 @@ public:
|
||||
*/
|
||||
virtual Rect getBounds() { return Rect(); }
|
||||
|
||||
virtual void proc5(int val) {}
|
||||
|
||||
/**
|
||||
* Following are handlers for the various messages that the PET can
|
||||
* pass onto the currently active section/area
|
||||
|
@ -158,7 +158,7 @@ bool CPetRemote::MouseDoubleClickMsg(CMouseDoubleClickMsg *msg) {
|
||||
}
|
||||
|
||||
bool CPetRemote::VirtualKeyCharMsg(CVirtualKeyCharMsg *msg) {
|
||||
return _items.VirtualKeyCharMsg(msg->_keyState.keycode);
|
||||
return _items.VirtualKeyCharMsg(msg);
|
||||
}
|
||||
|
||||
bool CPetRemote::isValid(CPetControl *petControl) {
|
||||
|
@ -92,7 +92,7 @@ bool CPetRooms::MouseDoubleClickMsg(CMouseDoubleClickMsg *msg) {
|
||||
}
|
||||
|
||||
bool CPetRooms::VirtualKeyCharMsg(CVirtualKeyCharMsg *msg) {
|
||||
return _glyphs.VirtualKeyCharMsg(msg->_keyState.keycode);
|
||||
return _glyphs.VirtualKeyCharMsg(msg);
|
||||
}
|
||||
|
||||
bool CPetRooms::checkDragEnd(CGameObject *item) {
|
||||
|
@ -144,6 +144,9 @@ public:
|
||||
*/
|
||||
virtual CPetText *getText();
|
||||
|
||||
/**
|
||||
* Special retrieval of glyph background image
|
||||
*/
|
||||
virtual CGameObject *getBackground(int index);
|
||||
|
||||
/**
|
||||
|
@ -76,7 +76,10 @@ public:
|
||||
*/
|
||||
virtual Rect getBounds() { return Rect(); }
|
||||
|
||||
virtual void proc5(int val) {}
|
||||
/**
|
||||
* Called when a general change occurs
|
||||
*/
|
||||
virtual void changed(int changeType) {}
|
||||
|
||||
/**
|
||||
* Following are handlers for the various messages that the PET can
|
||||
@ -159,6 +162,9 @@ public:
|
||||
*/
|
||||
virtual CPetElement *getElement(uint id) { return nullptr; }
|
||||
|
||||
/**
|
||||
* Special retrieval of glyph background image
|
||||
*/
|
||||
virtual CGameObject *getBackground(int index) const { return nullptr; }
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user