aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorjohndoe1232012-10-26 11:01:10 +0000
committerWillem Jan Palenstijn2013-05-08 20:47:37 +0200
commit0022c57858f5cac3544692ad134a2446c4f3be3a (patch)
treeb178ebbf41fef989457b33eff50c2d19850988d1 /engines
parenteecd9b8b2a2eda9641bf7bbd5bd5860123d102b4 (diff)
downloadscummvm-rg350-0022c57858f5cac3544692ad134a2446c4f3be3a.tar.gz
scummvm-rg350-0022c57858f5cac3544692ad134a2446c4f3be3a.tar.bz2
scummvm-rg350-0022c57858f5cac3544692ad134a2446c4f3be3a.zip
NEVERHOOD: Add SavegameListBox
Diffstat (limited to 'engines')
-rw-r--r--engines/neverhood/graphics.h1
-rw-r--r--engines/neverhood/menumodule.cpp119
-rw-r--r--engines/neverhood/menumodule.h36
3 files changed, 148 insertions, 8 deletions
diff --git a/engines/neverhood/graphics.h b/engines/neverhood/graphics.h
index d6808e37f5..b5286906e9 100644
--- a/engines/neverhood/graphics.h
+++ b/engines/neverhood/graphics.h
@@ -149,6 +149,7 @@ public:
void drawChar(BaseSurface *destSurface, int16 x, int16 y, byte chr);
void drawString(BaseSurface *destSurface, int16 x, int16 y, const byte *string, int stringLen);
int16 getStringWidth(const byte *string, int stringLen);
+ uint16 getCharWidth() const { return _charWidth; }
uint16 getCharHeight() const { return _charHeight; }
protected:
uint16 _numRows;
diff --git a/engines/neverhood/menumodule.cpp b/engines/neverhood/menumodule.cpp
index 01fcd41d75..7e1198abd0 100644
--- a/engines/neverhood/menumodule.cpp
+++ b/engines/neverhood/menumodule.cpp
@@ -358,7 +358,7 @@ WidgetScene::WidgetScene(NeverhoodEngine *vm, Module *parentModule)
: Scene(vm, parentModule, true), _currWidget(NULL) {
}
-void WidgetScene::getMousPos(NPoint &pt) {
+void WidgetScene::getMousePos(NPoint &pt) {
pt.x = _mouseCursor->getX();
pt.y = _mouseCursor->getY();
}
@@ -397,7 +397,7 @@ void Widget::hide() {
void Widget::onClick() {
_parentScene->setCurrWidget(this);
- // TODO Somehow _parentScene->onClick(_itemID, 0);
+ // TODO _parentScene->onClick(_itemID, 0);
}
void Widget::setPosition(int16 x, int16 y) {
@@ -406,7 +406,7 @@ void Widget::setPosition(int16 x, int16 y) {
updateBounds();
}
-void Widget::refresh() {
+void Widget::refreshPosition() {
_needRefresh = true;
StaticSprite::updatePosition();
_collisionBoundsOffset.set(0, 0,
@@ -494,8 +494,117 @@ void TextLabelWidget::setString(const byte *string, int stringLen) {
_stringLen = stringLen;
}
-void TextLabelWidget::setY(int16 y) {
- _ty = y;
+void TextLabelWidget::setTY(int16 ty) {
+ _ty = ty;
+}
+
+SavegameListBox::SavegameListBox(NeverhoodEngine *vm, int16 x, int16 y, int16 itemID, WidgetScene *parentScene,
+ int baseObjectPriority, int baseSurfacePriority, bool visible,
+ StringArray *savegameList, TextSurface *textSurface1, TextSurface *textSurface2, uint32 fileHash1, NRect &rect)
+ : Widget(vm, x, y, itemID, parentScene, baseObjectPriority, baseSurfacePriority, visible),
+ _savegameList(savegameList), _textSurface1(textSurface1), _textSurface2(textSurface2), _fileHash1(fileHash1), _rect(rect),
+ _maxStringLength(0), _topIndex(0), _visibleItemsCount(0), _currIndex(0) {
+
+ _maxVisibleItemsCount = (_rect.y2 - _rect.y1) / _textSurface1->getCharHeight();
+ _maxStringLength = (_rect.x2 - _rect.x1) / _textSurface1->getCharWidth();
+}
+
+void SavegameListBox::onClick() {
+ NPoint mousePos;
+ int16 w = _rect.x2 - _rect.x1, h = _rect.y2 - _rect.y1;
+ _parentScene->getMousePos(mousePos);
+ mousePos.x -= _x + _rect.x1;
+ mousePos.y -= _y + _rect.y1;
+ if (mousePos.x >= 0 && mousePos.x <= w && mousePos.y >= 0 && mousePos.y <= h) {
+ int newIndex = _topIndex + mousePos.y / _textSurface1->getCharHeight();
+ if (newIndex <= _visibleItemsCount) {
+ _currIndex = newIndex;
+ refresh();
+ _parentScene->setCurrWidget(this);
+ // TODO _parentScene->onClick(_itemID, 5);
+ }
+ }
+}
+
+void SavegameListBox::addSprite() {
+ _spriteResource.load2(_fileHash1);
+ createSurface(_baseSurfacePriority, _spriteResource.getDimensions().width, _spriteResource.getDimensions().height);
+ refreshPosition();
+ _parentScene->addSprite(this);
+ _vm->_collisionMan->addSprite(this);
+ if (_visible)
+ show();
+ else
+ hide();
+ buildItems();
+ _topIndex = 0;
+ _visibleItemsCount = MIN(_maxVisibleItemsCount, (int)_textLabelItems.size());
+ refresh();
+}
+
+void SavegameListBox::buildItems() {
+ StringArray &savegameList = *_savegameList;
+ int16 itemX = _rect.x1, itemY = 0;
+ for (uint i = 0; i < savegameList.size(); ++i) {
+ const byte *string = (const byte*)savegameList[i].c_str();
+ int stringLen = (int)savegameList[i].size();
+ TextLabelWidget *label = new TextLabelWidget(_vm, itemX, itemY, i, _parentScene, _baseObjectPriority + 1,
+ _baseSurfacePriority + 1, _visible, string, MIN(stringLen, _maxStringLength), _surface, _x, _y, _textSurface1);
+ label->addSprite();
+ _textLabelItems.push_back(label);
+ }
+}
+
+void SavegameListBox::drawItems() {
+ for (int i = 0; i < (int)_textLabelItems.size(); ++i) {
+ TextLabelWidget *label = _textLabelItems[i];
+ if (i >= _topIndex && i <= _visibleItemsCount) {
+ label->setY(_rect.y1 + (i - _topIndex) * _textSurface1->getCharHeight());
+ label->updateBounds();
+ label->drawString(_maxStringLength);
+ } else {
+ label->clear();
+ }
+ }
+}
+
+void SavegameListBox::refresh() {
+ refreshPosition();
+ drawItems();
+}
+
+void SavegameListBox::scrollUp() {
+ if (_topIndex > 0) {
+ --_topIndex;
+ --_visibleItemsCount;
+ refresh();
+ }
+}
+
+void SavegameListBox::scrollDown() {
+ if (_visibleItemsCount < (int)_textLabelItems.size()) {
+ ++_topIndex;
+ ++_visibleItemsCount;
+ refresh();
+ }
+}
+
+void SavegameListBox::pageUp() {
+ int distance = MIN(_topIndex, _maxVisibleItemsCount);
+ if (distance > 0) {
+ _topIndex -= distance;
+ _visibleItemsCount = distance;
+ refresh();
+ }
+}
+
+void SavegameListBox::pageDown() {
+ int distance = MIN((int)_textLabelItems.size() - _visibleItemsCount - 1, _maxVisibleItemsCount);
+ if (distance > 0) {
+ _topIndex += distance;
+ _visibleItemsCount += distance;
+ refresh();
+ }
}
} // End of namespace Neverhood
diff --git a/engines/neverhood/menumodule.h b/engines/neverhood/menumodule.h
index 8381b4eb30..1d7678d4bf 100644
--- a/engines/neverhood/menumodule.h
+++ b/engines/neverhood/menumodule.h
@@ -79,12 +79,14 @@ protected:
uint32 handleMessage(int messageNum, const MessageParam &param, Entity *sender);
};
+typedef Common::Array<Common::String> StringArray;
+
class Widget;
class WidgetScene : public Scene {
public:
WidgetScene(NeverhoodEngine *vm, Module *parentModule);
- void getMousPos(NPoint &pt);
+ void getMousePos(NPoint &pt);
virtual void setCurrWidget(Widget *newWidget);
protected:
Widget *_currWidget;
@@ -98,7 +100,7 @@ public:
virtual void hide();
virtual void onClick();
virtual void setPosition(int16 x, int16 y);
- virtual void refresh();
+ virtual void refreshPosition();
virtual void addSprite();
virtual int16 getWidth();
virtual int16 getHeight();
@@ -127,7 +129,7 @@ public:
void clear();
void setString(const byte *string, int stringLen);
TextSurface *getTextSurface() const { return _textSurface; }
- void setY(int16 y);
+ void setTY(int16 ty);
protected:
BaseSurface *_drawSurface;
int16 _tx, _ty;
@@ -136,6 +138,34 @@ protected:
int _stringLen;
};
+class SavegameListBox : public Widget {
+public:
+ SavegameListBox(NeverhoodEngine *vm, int16 x, int16 y, int16 itemID, WidgetScene *parentScene,
+ int baseObjectPriority, int baseSurfacePriority, bool visible,
+ StringArray *savegameList, TextSurface *textSurface1, TextSurface *textSurface2, uint32 fileHash1, NRect &rect);
+ virtual void onClick();
+ virtual void addSprite();
+ void buildItems();
+ void drawItems();
+ void refresh();
+ void scrollUp();
+ void scrollDown();
+ void pageUp();
+ void pageDown();
+protected:
+ NRect _rect;
+ uint32 _fileHash1;
+ int _maxStringLength;
+ Common::Array<TextLabelWidget*> _textLabelItems;
+ int _topIndex;
+ int _visibleItemsCount;
+ StringArray *_savegameList;
+ TextSurface *_textSurface1;
+ TextSurface *_textSurface2;
+ int _currIndex;
+ int _maxVisibleItemsCount;
+};
+
} // End of namespace Neverhood
#endif /* NEVERHOOD_MENUMODULE_H */