TOLTECS: Implemented scrolling in the savegame list

This commit is contained in:
Benjamin Haisch 2009-12-10 09:05:32 +00:00 committed by Willem Jan Palenstijn
parent d80cc85347
commit 145a696fe0
2 changed files with 49 additions and 15 deletions

View File

@ -43,8 +43,8 @@ namespace Toltecs {
MenuSystem::MenuSystem(ToltecsEngine *vm) : _vm(vm) { MenuSystem::MenuSystem(ToltecsEngine *vm) : _vm(vm) {
_currMenuID = kMenuIdNone; _currMenuID = kMenuIdNone;
_newMenuID = kMenuIdMain; _newMenuID = kMenuIdMain;
//_newMenuID = kMenuIdLoad;
_newMenuID = kMenuIdSave; _newMenuID = kMenuIdSave;
_newMenuID = kMenuIdLoad;
_currItemID = kItemIdNone; _currItemID = kItemIdNone;
_editingDescription = false; _editingDescription = false;
_cfgText = true; _cfgText = true;
@ -167,22 +167,20 @@ void MenuSystem::handleMouseClick(int x, int y) {
void MenuSystem::handleKeyDown(const Common::KeyState& kbd) { void MenuSystem::handleKeyDown(const Common::KeyState& kbd) {
if (_editingDescription) { if (_editingDescription) {
if (kbd.keycode >= Common::KEYCODE_SPACE && kbd.keycode <= Common::KEYCODE_z) { if (kbd.keycode >= Common::KEYCODE_SPACE && kbd.keycode <= Common::KEYCODE_z) {
debug("ascii = %c", kbd.ascii);
_editingDescriptionItem->caption += kbd.ascii; _editingDescriptionItem->caption += kbd.ascii;
restoreRect(_editingDescriptionItem->rect.left, _editingDescriptionItem->rect.top, restoreRect(_editingDescriptionItem->rect.left, _editingDescriptionItem->rect.top,
_editingDescriptionItem->rect.width() + 1, _editingDescriptionItem->rect.height() - 2); _editingDescriptionItem->rect.width() + 1, _editingDescriptionItem->rect.height() - 2);
setItemCaption(_editingDescriptionItem, (const byte*)_editingDescriptionItem->caption.c_str()); setItemCaption(_editingDescriptionItem, (const byte*)_editingDescriptionItem->caption.c_str());
drawItem(_editingDescriptionID, true); drawItem(_editingDescriptionID, true);
} else if (kbd.keycode == Common::KEYCODE_BACKSPACE) { } else if (kbd.keycode == Common::KEYCODE_BACKSPACE) {
debug("backspace");
_editingDescriptionItem->caption.deleteLastChar(); _editingDescriptionItem->caption.deleteLastChar();
restoreRect(_editingDescriptionItem->rect.left, _editingDescriptionItem->rect.top, restoreRect(_editingDescriptionItem->rect.left, _editingDescriptionItem->rect.top,
_editingDescriptionItem->rect.width() + 1, _editingDescriptionItem->rect.height() - 2); _editingDescriptionItem->rect.width() + 1, _editingDescriptionItem->rect.height() - 2);
setItemCaption(_editingDescriptionItem, (const byte*)_editingDescriptionItem->caption.c_str()); setItemCaption(_editingDescriptionItem, (const byte*)_editingDescriptionItem->caption.c_str());
drawItem(_editingDescriptionID, true); drawItem(_editingDescriptionID, true);
} else if (kbd.keycode == Common::KEYCODE_RETURN) { } else if (kbd.keycode == Common::KEYCODE_RETURN) {
debug("return");
_editingDescription = false; _editingDescription = false;
_newMenuID = kMenuIdMain;
} }
} }
} }
@ -264,7 +262,7 @@ void MenuSystem::initMenu(MenuID menuID) {
break; break;
case kMenuIdVolumes: case kMenuIdVolumes:
drawString(0, 74, 320, 1, 229, (byte*)"Adjust volume"); drawString(0, 74, 320, 1, 229, (byte*)"Adjust volume");
drawString(0, 130, 200, 0, 244, (byte*)"Master"); drawString(0, 130, 200, 0, 246, (byte*)"Master");
drawString(0, 155, 200, 0, 244, (byte*)"Voices"); drawString(0, 155, 200, 0, 244, (byte*)"Voices");
drawString(0, 180, 200, 0, 244, (byte*)"Music"); drawString(0, 180, 200, 0, 244, (byte*)"Music");
drawString(0, 205, 200, 0, 244, (byte*)"Sound FX"); drawString(0, 205, 200, 0, 244, (byte*)"Sound FX");
@ -376,8 +374,18 @@ void MenuSystem::clickItem(ItemID id) {
case kItemIdSavegame4: case kItemIdSavegame4:
case kItemIdSavegame5: case kItemIdSavegame5:
case kItemIdSavegame6: case kItemIdSavegame6:
case kItemIdSavegame7:
clickSavegameItem(id); clickSavegameItem(id);
break; break;
case kItemIdDone:
_newMenuID = kMenuIdMain;
break;
case kItemIdSavegameUp:
scrollSavegames(-6);
break;
case kItemIdSavegameDown:
scrollSavegames(+6);
break;
default: default:
break; break;
} }
@ -452,6 +460,20 @@ void MenuSystem::initSavegames() {
} }
} }
// DEBUG: Add some more items
_savegames.push_back(SavegameItem("abc", "Test 1"));
_savegames.push_back(SavegameItem("abc", "Test 2"));
_savegames.push_back(SavegameItem("abc", "Test 3"));
_savegames.push_back(SavegameItem("abc", "Test 4"));
_savegames.push_back(SavegameItem("abc", "Test 5"));
_savegames.push_back(SavegameItem("abc", "Test 6"));
_savegames.push_back(SavegameItem("abc", "Test 7"));
_savegames.push_back(SavegameItem("abc", "Test 8"));
_savegames.push_back(SavegameItem("abc", "Test 9"));
_savegames.push_back(SavegameItem("abc", "Test 10"));
_savegames.push_back(SavegameItem("abc", "Test 11"));
_savegames.push_back(SavegameItem("abc", "Test 12"));
} }
void MenuSystem::setSavegameCaptions() { void MenuSystem::setSavegameCaptions() {
@ -465,6 +487,20 @@ void MenuSystem::setSavegameCaptions() {
setItemCaption(getItem(kItemIdSavegame7), index < _savegames.size() ? (const byte*)_savegames[index++]._description.c_str() : (const byte*)""); setItemCaption(getItem(kItemIdSavegame7), index < _savegames.size() ? (const byte*)_savegames[index++]._description.c_str() : (const byte*)"");
} }
void MenuSystem::scrollSavegames(int delta) {
int newPos = CLIP<int>(_savegameListTopIndex + delta, 0, _savegames.size() - 1);
_savegameListTopIndex = newPos;
restoreRect(80, 92, 440, 140);
setSavegameCaptions();
drawItem(kItemIdSavegame1, false);
drawItem(kItemIdSavegame2, false);
drawItem(kItemIdSavegame3, false);
drawItem(kItemIdSavegame4, false);
drawItem(kItemIdSavegame5, false);
drawItem(kItemIdSavegame6, false);
drawItem(kItemIdSavegame7, false);
}
void MenuSystem::clickSavegameItem(ItemID id) { void MenuSystem::clickSavegameItem(ItemID id) {
if (_currMenuID == kMenuIdLoad) { if (_currMenuID == kMenuIdLoad) {
SavegameItem *savegameItem; SavegameItem *savegameItem;
@ -487,6 +523,9 @@ void MenuSystem::clickSavegameItem(ItemID id) {
case kItemIdSavegame6: case kItemIdSavegame6:
savegameItem = &_savegames[_savegameListTopIndex + 5]; savegameItem = &_savegames[_savegameListTopIndex + 5];
break; break;
case kItemIdSavegame7:
savegameItem = &_savegames[_savegameListTopIndex + 6];
break;
default: default:
return; return;
} }
@ -495,8 +534,8 @@ void MenuSystem::clickSavegameItem(ItemID id) {
_editingDescription = true; _editingDescription = true;
_editingDescriptionItem = getItem(id); _editingDescriptionItem = getItem(id);
_editingDescriptionID = id; _editingDescriptionID = id;
_editingDescriptionItem->activeColor = 230; // TODO: Correct color _editingDescriptionItem->activeColor = 249;
_editingDescriptionItem->defaultColor = 230; _editingDescriptionItem->defaultColor = 249;
drawItem(_editingDescriptionID, true); drawItem(_editingDescriptionID, true);
} }
} }
@ -506,10 +545,7 @@ void MenuSystem::setCfgText(bool value, bool active) {
Item *item = getItem(kItemIdToggleText); Item *item = getItem(kItemIdToggleText);
_cfgText = value; _cfgText = value;
restoreRect(item->rect.left, item->rect.top, item->rect.width() + 1, item->rect.height() - 2); restoreRect(item->rect.left, item->rect.top, item->rect.width() + 1, item->rect.height() - 2);
if (_cfgText) setItemCaption(item, _cfgText ? (const byte*)"TEXT ON" : (const byte*)"TEXT OFF");
setItemCaption(item, (const byte*)"TEXT ON");
else
setItemCaption(item, (const byte*)"TEXT OFF");
drawItem(kItemIdToggleText, true); drawItem(kItemIdToggleText, true);
} }
} }
@ -519,10 +555,7 @@ void MenuSystem::setCfgVoices(bool value, bool active) {
Item *item = getItem(kItemIdToggleVoices); Item *item = getItem(kItemIdToggleVoices);
_cfgVoices = value; _cfgVoices = value;
restoreRect(item->rect.left, item->rect.top, item->rect.width() + 1, item->rect.height() - 2); restoreRect(item->rect.left, item->rect.top, item->rect.width() + 1, item->rect.height() - 2);
if (_cfgVoices) setItemCaption(item, _cfgVoices ? (const byte*)"VOICES ON" : (const byte*)"VOICES OFF");
setItemCaption(item, (const byte*)"VOICES ON");
else
setItemCaption(item, (const byte*)"VOICES OFF");
drawItem(kItemIdToggleVoices, true); drawItem(kItemIdToggleVoices, true);
} }
} }

View File

@ -172,6 +172,7 @@ protected:
void initSavegames(); void initSavegames();
void setSavegameCaptions(); void setSavegameCaptions();
void scrollSavegames(int delta);
void clickSavegameItem(ItemID id); void clickSavegameItem(ItemID id);
void setCfgText(bool value, bool active); void setCfgText(bool value, bool active);
void setCfgVoices(bool value, bool active); void setCfgVoices(bool value, bool active);