From 58e1a807f3c7c9e0342ef1edd964d6d13de57dc3 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 23 Apr 2016 11:16:33 -0400 Subject: TITANIC: Clean up on element highlighting --- engines/titanic/pet_control/pet_glyphs.cpp | 38 ++++++++++++++++++++++----- engines/titanic/pet_control/pet_glyphs.h | 4 +-- engines/titanic/pet_control/pet_inventory.cpp | 4 +++ engines/titanic/pet_control/pet_inventory.h | 4 +-- 4 files changed, 39 insertions(+), 11 deletions(-) (limited to 'engines/titanic') diff --git a/engines/titanic/pet_control/pet_glyphs.cpp b/engines/titanic/pet_control/pet_glyphs.cpp index 1ab7d7ee1b..7144378548 100644 --- a/engines/titanic/pet_control/pet_glyphs.cpp +++ b/engines/titanic/pet_control/pet_glyphs.cpp @@ -38,7 +38,7 @@ void CPetGlyph::drawAt(CScreenManager *screenManager, const Point &pt) { _element.translate(-pt.x, -pt.y); } -void CPetGlyph::proc14(const Point &pt) { +void CPetGlyph::proc14() { warning("TODO: CPetGlyph::proc14"); } @@ -183,7 +183,34 @@ Rect CPetGlyphs::getRect(int index) { } void CPetGlyphs::changeHighlight(int index) { - warning("TODO: CPetGlyphs::changeHighlight"); + if (index == _highlightIndex) + return; + + if (_highlightIndex >= 0 && (_field20 & 4)) { + CPetGlyph *glyph = getGlyph(_highlightIndex); + if (glyph) + glyph->unhighlightCurrent(); + } + + _highlightIndex = index; + if (index >= 0) { + CPetGlyph *glyph = getGlyph(_highlightIndex); + + if (glyph) { + if (_field20 & 4) { + Point pt; + int idx = getHighlightedIndex(_highlightIndex); + if (idx >= 0) + pt = getPosition(idx); + + glyph->highlightCurrent(pt); + } + + glyph->proc14(); + } + } else if (_owner) { + _owner->proc28(); + } } void CPetGlyphs::highlight(int index) { @@ -281,11 +308,10 @@ bool CPetGlyphs::mouseButtonDown(const Point &pt) { int index = getItemIndex(idx); CPetGlyph *glyph = getGlyph(index); if (glyph) { - if (index == _highlightIndex) { - glyph->proc28(glyphRect); - glyph->proc14(pt); + if (glyph->checkHighlight(pt)) return true; - } else { + + if (!(_field20 & 2)) { changeHighlight(index); makePetDirty(); return true; diff --git a/engines/titanic/pet_control/pet_glyphs.h b/engines/titanic/pet_control/pet_glyphs.h index 496654762e..24d0a0840b 100644 --- a/engines/titanic/pet_control/pet_glyphs.h +++ b/engines/titanic/pet_control/pet_glyphs.h @@ -110,7 +110,7 @@ public: */ virtual void draw2(CScreenManager *screenManager) {} - virtual void proc14(const Point &pt); + virtual void proc14(); /** * Get the bounds for the glyph @@ -150,7 +150,7 @@ public: /** * Highlight any currently highlighted element */ - virtual void highlightCurrent() {} + virtual void highlightCurrent(const Point &pt) {} virtual void proc27(const Point &pt, bool flag) {} virtual void proc28(const Point &pt) {} diff --git a/engines/titanic/pet_control/pet_inventory.cpp b/engines/titanic/pet_control/pet_inventory.cpp index b27b664ab9..621bf2df0d 100644 --- a/engines/titanic/pet_control/pet_inventory.cpp +++ b/engines/titanic/pet_control/pet_inventory.cpp @@ -90,6 +90,10 @@ void CPetInventory::leave() { _items.leave(); } +CGameObject *CPetInventory::getBackground(int index) const { + return (index >= 0 && index < 46) ? _itemBackgrounds[index] : nullptr; +} + bool CPetInventory::setPetControl(CPetControl *petControl) { if (!petControl) return false; diff --git a/engines/titanic/pet_control/pet_inventory.h b/engines/titanic/pet_control/pet_inventory.h index ed1b679c63..969e253676 100644 --- a/engines/titanic/pet_control/pet_inventory.h +++ b/engines/titanic/pet_control/pet_inventory.h @@ -112,9 +112,7 @@ public: */ virtual void leave(); - virtual CGameObject *getBackground(int index) const { - return (index >= 0 && index < 46) ? _itemBackgrounds[index] : nullptr; - } + virtual CGameObject *getBackground(int index) const; /** * -- cgit v1.2.3