diff options
author | Max Horn | 2002-07-18 20:26:35 +0000 |
---|---|---|
committer | Max Horn | 2002-07-18 20:26:35 +0000 |
commit | 6e6c3c3c962b403a89b80e38cd3702413bc6c4af (patch) | |
tree | 6e1b58ace59706672ecd34379f7728a273c2d4fb /gui | |
parent | d66c9ea2b23ce4476783ddc7e1622fb6767b2cca (diff) | |
download | scummvm-rg350-6e6c3c3c962b403a89b80e38cd3702413bc6c4af.tar.gz scummvm-rg350-6e6c3c3c962b403a89b80e38cd3702413bc6c4af.tar.bz2 scummvm-rg350-6e6c3c3c962b403a89b80e38cd3702413bc6c4af.zip |
put stuff in util.h into namespace ScummVM; fixed stupid bug in String class; took painelf's patch which implements save/load dialog in new GUI and fixed it slightly; various other minor changes
svn-id: r4591
Diffstat (limited to 'gui')
-rw-r--r-- | gui/ListWidget.cpp | 53 | ||||
-rw-r--r-- | gui/ListWidget.h | 8 | ||||
-rw-r--r-- | gui/ScrollBarWidget.cpp | 6 | ||||
-rw-r--r-- | gui/dialog.cpp | 39 | ||||
-rw-r--r-- | gui/dialog.h | 3 |
5 files changed, 69 insertions, 40 deletions
diff --git a/gui/ListWidget.cpp b/gui/ListWidget.cpp index 612c8e4d32..2f697acbaa 100644 --- a/gui/ListWidget.cpp +++ b/gui/ListWidget.cpp @@ -27,8 +27,13 @@ /* * TODO: - * - Allow escape to abort changes - * - Add key repeat (for backspace, etc) + * - Abort changes when ESC is pressed or the selection changes + * - When the editing of a string is ended by return, we might consider sending + * a message. Return means that the edit was confirmed. Hence the SaveDialog + * could immediatly do the save in a trivial fashion. + * - Handle double clicks: either start editing of the selected item, or + * send a cmd to our target (i.e. as specified via setCmd or setDoubleCmd) + * This will allow a double click in the load dialog to immediatly load the game */ @@ -37,13 +42,13 @@ ListWidget::ListWidget(Dialog *boss, int x, int y, int w, int h) - : Widget(boss, x, y, w - kScrollBarWidth, h) + : Widget(boss, x, y, w - kScrollBarWidth, h), CommandSender(boss) { _flags = WIDGET_ENABLED | WIDGET_CLEARBG | WIDGET_RETAIN_FOCUS | WIDGET_WANT_TICKLE; _type = kListWidget; _numberingMode = kListNumberingOne; _entriesPerPage = (_h - 4) / LINE_HEIGHT; - _currentPos = 3; + _currentPos = 0; _selectedItem = -1; _scrollBar = new ScrollBarWidget(boss, _x + _w, _y, kScrollBarWidth, _h); _scrollBar->setTarget(this); @@ -53,38 +58,20 @@ ListWidget::ListWidget(Dialog *boss, int x, int y, int w, int h) _editable = true; _editMode = false; +} - // FIXME - fill in dummy data for now - _list.push_back("A simple game?"); - _list.push_back("This space for rent!"); - _list.push_back("To be or not to be..."); - _list.push_back("It's not easy come up with dummy text :-)"); - _list.push_back("Foo bar baz"); - _list.push_back("Empty slots follow:"); - _list.push_back(""); - _list.push_back(""); - _list.push_back("Now again a filled slot"); - _list.push_back("We need some more text!"); - _list.push_back("Because only this way..."); - _list.push_back("...can you see the scrollbar..."); - _list.push_back("...and verify that it works!"); - _list.push_back("One"); - _list.push_back("Two"); - _list.push_back("Three"); - _list.push_back("Four"); - _list.push_back("The End"); - +ListWidget::~ListWidget() +{ +} +void ListWidget::scrollBarRecalc() +{ _scrollBar->_numEntries = _list.size(); _scrollBar->_entriesPerPage = _entriesPerPage; _scrollBar->_currentPos = _currentPos; _scrollBar->recalc(); } -ListWidget::~ListWidget() -{ -} - void ListWidget::handleMouseDown(int x, int y, int button) { int oldSelectedItem = _selectedItem; @@ -220,19 +207,19 @@ void ListWidget::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) void ListWidget::drawWidget(bool hilite) { - NewGui *gui = _boss->getGui(); - int i, pos; - String buffer; + NewGui *gui = _boss->getGui(); + int i, pos, len = _list.size(); + ScummVM::String buffer; // Draw the list items - // FIXME - this is just a temporary demo hack - for (i = 0, pos = _currentPos; i < _entriesPerPage; i++, pos++) { + for (i = 0, pos = _currentPos; i < _entriesPerPage && pos < len; i++, pos++) { if (_numberingMode == kListNumberingZero || _numberingMode == kListNumberingOne) { char temp[10]; sprintf(temp, "%2d. ", (pos + _numberingMode)); buffer = temp; } else buffer = ""; + buffer += _list[pos]; gui->drawString(buffer, _x+5, _y+2 + LINE_HEIGHT * i, _w - 10, diff --git a/gui/ListWidget.h b/gui/ListWidget.h index 0fcee722ec..bdb00fd7be 100644 --- a/gui/ListWidget.h +++ b/gui/ListWidget.h @@ -33,7 +33,8 @@ enum { }; /* ListWidget */ -class ListWidget : public Widget, public CommandReceiver { +class ListWidget : public Widget, public CommandReceiver, public CommandSender { + typedef ScummVM::StringList StringList; protected: StringList _list; bool _editable; @@ -48,9 +49,10 @@ public: ListWidget(Dialog *boss, int x, int y, int w, int h); virtual ~ListWidget(); - void setList(const StringList& list) { _list = list; } + void setList(const StringList& list) { _list = list; scrollBarRecalc(); } const StringList& getList() const { return _list; } int getSelected() const { return _selectedItem; } + const ScummVM::String& getSelectedString() const { return _list[_selectedItem]; } void setNumberingMode(int numberingMode) { _numberingMode = numberingMode; } virtual void handleMouseDown(int x, int y, int button); @@ -58,6 +60,8 @@ public: virtual void handleKeyUp(char key, int modifiers); virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data); + void scrollBarRecalc(); + protected: void drawWidget(bool hilite); void lostFocusWidget(); diff --git a/gui/ScrollBarWidget.cpp b/gui/ScrollBarWidget.cpp index c83c6f224c..02503c97db 100644 --- a/gui/ScrollBarWidget.cpp +++ b/gui/ScrollBarWidget.cpp @@ -29,6 +29,8 @@ * - Auto-repeat: if one clicks & holds on one of the arrows, then after a * brief delay, it should start to contiously scroll * - Allow for a horizontal scrollbar, too? + * - If there are less items than fit on one pages, no scrolling can be done + * and we thus should not highlight the arrows/slider. */ #define UP_DOWN_BOX_HEIGHT 10 @@ -172,8 +174,8 @@ void ScrollBarWidget::checkBounds(int old_pos) void ScrollBarWidget::recalc() { _sliderHeight = (_h - 2 * UP_DOWN_BOX_HEIGHT) * _entriesPerPage / _numEntries; - if (_sliderHeight < 4) - _sliderHeight = 4; + if (_sliderHeight < UP_DOWN_BOX_HEIGHT) + _sliderHeight = UP_DOWN_BOX_HEIGHT; _sliderPos = UP_DOWN_BOX_HEIGHT + (_h - 2 * UP_DOWN_BOX_HEIGHT - _sliderHeight + 1) * _currentPos / (_numEntries - diff --git a/gui/dialog.cpp b/gui/dialog.cpp index 03b19b5062..d0bd4dfe2b 100644 --- a/gui/dialog.cpp +++ b/gui/dialog.cpp @@ -24,6 +24,7 @@ #include "newgui.h" #include "dialog.h" #include "widget.h" +#include "scumm.h" #include "ListWidget.h" Dialog::~Dialog() @@ -248,6 +249,15 @@ enum { kQuitCmd = 'QUIT' }; +/* + * TODO + * - Maybe go back to the old way of differentiating between the save and the load mode? + * This would include that in the load mode the list is not editable. + * - Currently the savegame list is only loaded once when the dialog is created. Instead, + * it should be loaded whenever the dialog is opened. Might want to add an open() + * method to Dialog for that. + */ + SaveLoadDialog::SaveLoadDialog(NewGui *gui) : Dialog (gui, 30, 20, 260, 124) { @@ -269,16 +279,41 @@ SaveLoadDialog::SaveLoadDialog(NewGui *gui) // FIXME - test _savegameList = new ListWidget(this, 10, 40, 180, 74); + + // Get savegame names + ScummVM::StringList l; + char name[32]; + Scumm *s = _gui->getScumm(); + + for (int i = 0; i <= 80; i++) { // 80 I got from old gui + s->getSavegameName(i, name); + l.push_back(name); + } + + ((ListWidget *)_savegameList)->setList(l); } void SaveLoadDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) { switch (cmd) { case kSaveCmd: - //printf("Saving game in slot %d\n", _savegameList->getSelected()); + if (_savegameList->getSelectedString()[0] != 0) { + Scumm *s = _gui->getScumm(); + s->_saveLoadSlot = _savegameList->getSelected(); + s->_saveLoadCompatible = false; + s->_saveLoadFlag = 1; // 1 for save, I assume (Painelf) + strcpy(s->_saveLoadName, _savegameList->getSelectedString()); + close(); + } break; case kLoadCmd: - //printf("Loading game in slot %d\n", _savegameList->getSelected()); + if (_savegameList->getSelectedString()[0] != 0) { + Scumm *s = _gui->getScumm(); + s->_saveLoadSlot = _savegameList->getSelected(); + s->_saveLoadCompatible = false; + s->_saveLoadFlag = 2; // 2 for load. Magic number anyone? + close(); + } break; case kPlayCmd: close(); diff --git a/gui/dialog.h b/gui/dialog.h index ee92f34e37..c42cb8ee27 100644 --- a/gui/dialog.h +++ b/gui/dialog.h @@ -23,6 +23,7 @@ #include "scummsys.h" #include "widget.h" +#include "ListWidget.h" class NewGui; @@ -83,7 +84,7 @@ public: virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data); protected: - Widget* _savegameList; + ListWidget* _savegameList; }; |