Ticket #8563: kyra-menu.diff
File kyra-menu.diff, 17.5 KB (added by , 18 years ago) |
---|
-
engines/kyra/kyra3.h
52 52 53 53 SoundDigital *_soundDigital; 54 54 55 int _lang;56 57 55 // sound specific 58 56 private: 59 57 void playMenuAudioFile(); … … 71 69 72 70 int musicUpdate(int forceRestart); 73 71 74 // gui/menu specific 75 private: 76 static const char *_mainMenuStrings[]; 77 int handleMainMenu(Movie *logo); 78 void drawMainMenu(const char * const *strings, int select); 79 void drawMainBox(int x, int y, int w, int h, int fill); 80 81 void gui_printString(const char *string, int x, int y, int col1, int col2, int flags, ...); 72 virtual void gui_initMainMenu(); 73 virtual void gui_updateMainMenuAnimation(); 82 74 83 75 // unknown 84 private: 76 private: 85 77 uint8 *_unkPage1; 86 78 uint8 *_unkPage2; 87 79 … … 96 88 97 89 uint8 *_unkShapeTable[20]; 98 90 91 // main menu 92 Movie *_mainMenuLogo; 93 int _mainMenuFrame; 94 int _mainMenuFrameAdd; 95 99 96 // translation stuff 100 97 uint8 *_scoreFile; 101 98 uint8 *_cCodeFile; -
engines/kyra/staticres.cpp
1225 1225 const uint16 KyraEngine::_amuletX2[] = { 0x000, 0x0FD, 0x0E7, 0x0FD, 0x113, 0x000 }; 1226 1226 const uint16 KyraEngine::_amuletY2[] = { 0x000, 0x09F, 0x0AA, 0x0B5, 0x0AA, 0x000 }; 1227 1227 1228 // kyra 3 static res 1229 const char *KyraEngine_v3::_mainMenuStrings[] = { 1228 // Kyra 2 and 3 main menu 1229 1230 const char *KyraEngine::_mainMenuStrings[] = { 1230 1231 "Start a new game", 1231 1232 "Introduction", 1232 1233 "Load a game", … … 1242 1243 0 1243 1244 }; 1244 1245 1246 // kyra 3 static res 1247 1245 1248 const char *KyraEngine_v3::_soundList[] = { 1246 1249 "ARREST1.AUD", 1247 1250 "BATH1.AUD", -
engines/kyra/kyra.cpp
313 313 _gameSpeed = 60; 314 314 _tickLength = (uint8)(1000.0 / _gameSpeed); 315 315 316 _lang = 0; 317 Common::Language lang = Common::parseLanguage(ConfMan.get("language")); 318 319 switch (lang) { 320 case Common::EN_ANY: 321 case Common::EN_USA: 322 case Common::EN_GRB: 323 _lang = 0; 324 break; 325 326 case Common::FR_FRA: 327 _lang = 1; 328 break; 329 330 case Common::DE_DEU: 331 _lang = 2; 332 break; 333 334 default: 335 warning("unsupported language, switching back to English"); 336 _lang = 0; 337 break; 338 } 339 316 340 return 0; 317 341 } 318 342 -
engines/kyra/gui.cpp
1471 1471 _screen->fadePalette(_screen->_currentPalette, 2); 1472 1472 } 1473 1473 1474 #pragma mark - 1474 1475 1476 // Kyra 2 and 3 main menu 1477 1478 void KyraEngine::gui_updateMainMenuAnimation() { 1479 _screen->updateScreen(); 1480 delay(10); 1481 } 1482 1483 int KyraEngine::gui_handleMainMenu() { 1484 debugC(9, kDebugLevelMain, "KyraEngine::gui_handleMainMenu()"); 1485 int command = -1; 1486 1487 uint8 colorMap[16]; 1488 memset(colorMap, 0, sizeof(colorMap)); 1489 _screen->setTextColorMap(colorMap); 1490 1491 const char * const *strings = &_mainMenuStrings[_lang << 2]; 1492 Screen::FontId oldFont = _screen->setFont(Screen::FID_8_FNT); 1493 int charWidthBackUp = _screen->_charWidth; 1494 1495 _screen->_charWidth = -2; 1496 _screen->setScreenDim(3); 1497 int backUpX = _screen->_curDim->sx; 1498 int backUpY = _screen->_curDim->sy; 1499 int backUpWidth = _screen->_curDim->w; 1500 int backUpHeight = _screen->_curDim->h; 1501 _screen->copyRegion(backUpX, backUpY, backUpX, backUpY, backUpWidth, backUpHeight, 0, 3); 1502 1503 int x = _screen->_curDim->sx << 3; 1504 int y = _screen->_curDim->sy; 1505 int width = _screen->_curDim->w << 3; 1506 int height = _screen->_curDim->h; 1507 1508 gui_drawMainBox(x, y, width, height, 1); 1509 gui_drawMainBox(x + 1, y + 1, width - 2, height - 2, 0); 1510 1511 int selected = 0; 1512 1513 gui_drawMainMenu(strings, selected); 1514 1515 _system->warpMouse(300, 180); 1516 _screen->showMouse(); 1517 1518 int fh = _screen->getFontHeight(); 1519 int textPos = ((_screen->_curDim->w >> 1) + _screen->_curDim->sx) << 3; 1520 1521 Common::Rect menuRect(x + 16, y + 4, x + width - 16, y + 4 + fh * 4); 1522 1523 while (command == -1 && !_quitFlag) { 1524 gui_updateMainMenuAnimation(); 1525 if (menuRect.contains(mouseX(), mouseY())) { 1526 int item = (mouseY() - menuRect.top) / fh; 1527 1528 if (item != selected) { 1529 gui_printString(strings[selected], textPos, menuRect.top + selected * fh, 0x80, 0, 5); 1530 gui_printString(strings[item], textPos, menuRect.top + item * fh, 0xFF, 0, 5); 1531 1532 selected = item; 1533 } 1534 1535 if (_mousePressFlag) { 1536 // TODO: Flash the text 1537 command = item; 1538 } 1539 } 1540 } 1541 1542 if (_quitFlag) 1543 command = -1; 1544 1545 _screen->copyRegion(backUpX, backUpY, backUpX, backUpY, backUpWidth, backUpHeight, 3, 0); 1546 _screen->_charWidth = charWidthBackUp; 1547 _screen->setFont(oldFont); 1548 1549 return command; 1550 } 1551 1552 void KyraEngine::gui_drawMainMenu(const char * const *strings, int select) { 1553 debugC(9, kDebugLevelMain, "KyraEngine::gui_drawMainMenu(%p)", (const void*)strings); 1554 static const uint16 menuTable[] = { 0x01, 0x04, 0x0C, 0x04, 0x00, 0x80, 0xFF, 0x00, 0x01, 0x02, 0x03 }; 1555 1556 int top = _screen->_curDim->sy; 1557 top += menuTable[1]; 1558 1559 for (int i = 0; i < menuTable[3]; ++i) { 1560 int curY = top + i * _screen->getFontHeight(); 1561 int color = (i == select) ? menuTable[6] : menuTable[5]; 1562 gui_printString(strings[i], ((_screen->_curDim->w >> 1) + _screen->_curDim->sx) << 3, curY, color, 0, 5); 1563 } 1564 } 1565 1566 void KyraEngine::gui_drawMainBox(int x, int y, int w, int h, int fill) { 1567 debugC(9, kDebugLevelMain, "KyraEngine::gui_drawMainBox(%d, %d, %d, %d, %d)", x, y, w, h, fill); 1568 static const uint8 colorTable[] = { 0x16, 0x19, 0x1A, 0x16 }; 1569 --w; --h; 1570 1571 if (fill) { 1572 _screen->fillRect(x, y, x+w, y+h, colorTable[0]); 1573 } 1574 1575 _screen->drawClippedLine(x, y+h, x+w, y+h, colorTable[1]); 1576 _screen->drawClippedLine(x+w, y, x+w, y+h, colorTable[1]); 1577 _screen->drawClippedLine(x, y, x+w, y, colorTable[2]); 1578 _screen->drawClippedLine(x, y, x, y+h, colorTable[2]); 1579 1580 _screen->setPagePixel(_screen->_curPage, x, y+h, colorTable[3]); 1581 _screen->setPagePixel(_screen->_curPage, x+w, y, colorTable[3]); 1582 } 1583 1584 void KyraEngine::gui_printString(const char *format, int x, int y, int col1, int col2, int flags, ...) { 1585 debugC(9, kDebugLevelMain, "KyraEngine::gui_printString('%s', %d, %d, %d, %d, %d, ...)", format, x, y, col1, col2, flags); 1586 if (!format) 1587 return; 1588 1589 char string[512]; 1590 va_list vaList; 1591 va_start(vaList, flags); 1592 vsprintf(string, format, vaList); 1593 va_end(vaList); 1594 1595 if (flags & 1) { 1596 x -= _screen->getTextWidth(string) >> 1; 1597 } 1598 1599 if (flags & 2) { 1600 x -= _screen->getTextWidth(string); 1601 } 1602 1603 if (flags & 4) { 1604 _screen->printText(string, x - 1, y, 240, col2); 1605 _screen->printText(string, x, y + 1, 240, col2); 1606 } 1607 1608 if (flags & 8) { 1609 _screen->printText(string, x - 1, y, 227, col2); 1610 _screen->printText(string, x, y + 1, 227, col2); 1611 } 1612 1613 _screen->printText(string, x, y, col1, col2); 1614 } 1615 1475 1616 } // end of namespace Kyra 1476 1617 -
engines/kyra/kyra2.cpp
36 36 KyraEngine_v2::~KyraEngine_v2() { 37 37 } 38 38 39 int KyraEngine_v2::init() { 40 KyraEngine::init(); 41 _screen->loadFont(Screen::FID_6_FNT, "6.FNT"); 42 _screen->loadFont(Screen::FID_8_FNT, "8FAT.FNT"); 43 _screen->loadFont(Screen::FID_BOOKFONT_FNT, "BOOKFONT.FNT"); 44 _screen->setScreenDim(0); 45 return 0; 46 } 47 39 48 int KyraEngine_v2::go() { 40 49 uint8 pal[768]; 41 50 … … 55 64 56 65 delete title; 57 66 58 waitForEvent(); 67 bool running = true; 68 while (running && !_quitFlag) { 69 switch (gui_handleMainMenu()) { 70 case 0: 71 break; 72 case 1: 73 break; 74 case 2: 75 break; 76 case 3: 77 running = false; 78 break; 79 default: 80 break; 81 } 82 } 83 59 84 return 0; 60 85 } 61 86 -
engines/kyra/kyra3.cpp
86 86 87 87 int KyraEngine_v3::setupGameFlags() { 88 88 _game = GI_KYRA3; 89 _lang = 0;90 Common::Language lang = Common::parseLanguage(ConfMan.get("language"));91 92 switch (lang) {93 case Common::EN_ANY:94 case Common::EN_USA:95 case Common::EN_GRB:96 _lang = 0;97 break;98 99 case Common::FR_FRA:100 _lang = 1;101 break;102 103 case Common::DE_DEU:104 _lang = 2;105 break;106 107 default:108 warning("unsupported language, switching back to English");109 _lang = 0;110 break;111 }112 113 89 return 0; 114 90 } 115 91 … … 119 95 120 96 int KyraEngine_v3::init() { 121 97 KyraEngine::init(); 98 99 gui_initMainMenu(); 122 100 123 101 _soundDigital = new SoundDigital(this, _mixer); 124 102 assert(_soundDigital); … … 159 137 uint8 *pal = _screen->getPalette(1); 160 138 assert(pal); 161 139 162 Movie *logo = createWSAMovie();163 assert( logo);164 logo->open("REVENGE.WSA", 1, pal);165 assert( logo->opened());140 _mainMenuLogo = createWSAMovie(); 141 assert(_mainMenuLogo); 142 _mainMenuLogo->open("REVENGE.WSA", 1, pal); 143 assert(_mainMenuLogo->opened()); 166 144 167 145 bool running = true; 168 146 while (running && !_quitFlag) { … … 176 154 // XXX 177 155 playMenuAudioFile(); 178 156 179 logo->setX(0); logo->setY(0);180 logo->setDrawPage(0);157 _mainMenuLogo->setX(0); _mainMenuLogo->setY(0); 158 _mainMenuLogo->setDrawPage(0); 181 159 182 160 for (int i = 0; i < 64 && !_quitFlag; ++i) { 183 161 uint32 nextRun = _system->getMillis() + 3 * _tickLength; 184 logo->displayFrame(i);162 _mainMenuLogo->displayFrame(i); 185 163 _screen->updateScreen(); 186 164 delayUntil(nextRun); 187 165 } 188 166 189 167 for (int i = 64; i > 29 && !_quitFlag; --i) { 190 168 uint32 nextRun = _system->getMillis() + 3 * _tickLength; 191 logo->displayFrame(i);169 _mainMenuLogo->displayFrame(i); 192 170 _screen->updateScreen(); 193 171 delayUntil(nextRun); 194 172 } 195 173 196 switch ( handleMainMenu(logo)) {174 switch (gui_handleMainMenu()) { 197 175 case 0: 198 delete logo;199 logo = 0;176 delete _mainMenuLogo; 177 _mainMenuLogo = 0; 200 178 preinit(); 201 179 realInit(); 202 180 // XXX … … 208 186 break; 209 187 210 188 case 2: 211 //delete logo;212 // logo = 0;189 //delete _mainMenuLogo; 190 //_mainMenuLogo = 0; 213 191 //show load dialog 214 192 //running = false; 215 193 break; 216 194 217 195 case 3: 196 _soundDigital->beginFadeOut(_musicSoundChannel); 197 _screen->fadeToBlack(); 198 _soundDigital->stopSound(_musicSoundChannel); 199 _musicSoundChannel = -1; 218 200 running = false; 219 201 break; 220 202 … … 222 204 break; 223 205 } 224 206 } 225 delete logo;207 delete _mainMenuLogo; 226 208 227 209 return 0; 228 210 } … … 347 329 348 330 #pragma mark - 349 331 350 int KyraEngine_v3::handleMainMenu(Movie *logo) { 351 debugC(9, kDebugLevelMain, "KyraEngine::handleMainMenu(%p)", (const void*)logo); 352 int command = -1; 353 354 uint8 colorMap[16]; 355 memset(colorMap, 0, sizeof(colorMap)); 356 _screen->setTextColorMap(colorMap); 357 358 const char * const *strings = &_mainMenuStrings[_lang << 2]; 359 Screen::FontId oldFont = _screen->setFont(Screen::FID_8_FNT); 360 int charWidthBackUp = _screen->_charWidth; 361 362 _screen->_charWidth = -2; 363 _screen->setScreenDim(3); 364 int backUpX = _screen->_curDim->sx; 365 int backUpY = _screen->_curDim->sy; 366 int backUpWidth = _screen->_curDim->w; 367 int backUpHeight = _screen->_curDim->h; 368 _screen->copyRegion(backUpX, backUpY, backUpX, backUpY, backUpWidth, backUpHeight, 0, 3); 332 void KyraEngine_v3::gui_initMainMenu() { 333 KyraEngine::gui_initMainMenu(); 334 _mainMenuFrame = 29; 335 _mainMenuFrameAdd = 1; 336 } 369 337 370 int x = _screen->_curDim->sx << 3; 371 int y = _screen->_curDim->sy; 372 int width = _screen->_curDim->w << 3; 373 int height = _screen->_curDim->h; 374 375 drawMainBox(x, y, width, height, 1); 376 drawMainBox(x + 1, y + 1, width - 2, height - 2, 0); 377 378 int curFrame = 29, frameAdd = 1; 379 uint32 nextRun = 0; 380 381 int selected = 0; 382 383 drawMainMenu(strings, selected); 384 385 _system->warpMouse(300, 180); 386 _screen->showMouse(); 387 388 int fh = _screen->getFontHeight(); 389 int textPos = ((_screen->_curDim->w >> 1) + _screen->_curDim->sx) << 3; 390 391 Common::Rect menuRect(x + 16, y + 4, x + width - 16, y + 4 + fh * 4); 392 393 while (command == -1 && !_quitFlag) { 394 // yes 2 * _tickLength here not 3 * like in the first draw 395 nextRun = _system->getMillis() + 2 * _tickLength; 396 logo->displayFrame(curFrame); 397 _screen->updateScreen(); 338 void KyraEngine_v3::gui_updateMainMenuAnimation() { 339 // yes 2 * _tickLength here not 3 * like in the first draw 340 uint32 nextRun = _system->getMillis() + 2 * _tickLength; 341 _mainMenuLogo->displayFrame(_mainMenuFrame); 342 _screen->updateScreen(); 398 343 399 curFrame += frameAdd;400 if (curFrame < 29) {401 curFrame = 29;402 frameAdd = 1;403 } else if (curFrame > 63) {404 curFrame = 64;405 frameAdd = -1;406 344 _mainMenuFrame += _mainMenuFrameAdd; 345 if (_mainMenuFrame < 29) { 346 _mainMenuFrame = 29; 347 _mainMenuFrameAdd = 1; 348 } else if (_mainMenuFrame > 63) { 349 _mainMenuFrame = 64; 350 _mainMenuFrameAdd = -1; 351 } 407 352 408 353 // XXX 409 354 410 while (_system->getMillis() < nextRun) { 411 // XXX 412 _screen->updateScreen(); 413 if ((int32)nextRun - (int32)_system->getMillis() >= 10) 414 delay(10); 415 } 416 417 if (menuRect.contains(mouseX(), mouseY())) { 418 int item = (mouseY() - menuRect.top) / fh; 419 420 if (item != selected) { 421 gui_printString(strings[selected], textPos, menuRect.top + selected * fh, 0x80, 0, 5); 422 gui_printString(strings[item], textPos, menuRect.top + item * fh, 0xFF, 0, 5); 423 424 selected = item; 425 } 426 427 if (_mousePressFlag) { 428 // TODO: Flash the text 429 command = item; 430 } 431 } 355 while (_system->getMillis() < nextRun) { 356 // XXX 357 _screen->updateScreen(); 358 if ((int32)nextRun - (int32)_system->getMillis() >= 10) 359 delay(10); 432 360 } 433 434 if (_quitFlag)435 command = -1;436 437 _screen->copyRegion(backUpX, backUpY, backUpX, backUpY, backUpWidth, backUpHeight, 3, 0);438 _screen->_charWidth = charWidthBackUp;439 _screen->setFont(oldFont);440 441 if (command == 3) {442 _soundDigital->beginFadeOut(_musicSoundChannel);443 _screen->fadeToBlack();444 _soundDigital->stopSound(_musicSoundChannel);445 _musicSoundChannel = -1;446 }447 448 return command;449 361 } 450 362 451 void KyraEngine_v3::drawMainMenu(const char * const *strings, int select) {452 debugC(9, kDebugLevelMain, "KyraEngine::drawMainMenu(%p)", (const void*)strings);453 static const uint16 menuTable[] = { 0x01, 0x04, 0x0C, 0x04, 0x00, 0x80, 0xFF, 0x00, 0x01, 0x02, 0x03 };454 455 int top = _screen->_curDim->sy;456 top += menuTable[1];457 458 for (int i = 0; i < menuTable[3]; ++i) {459 int curY = top + i * _screen->getFontHeight();460 int color = (i == select) ? menuTable[6] : menuTable[5];461 gui_printString(strings[i], ((_screen->_curDim->w >> 1) + _screen->_curDim->sx) << 3, curY, color, 0, 5);462 }463 }464 465 void KyraEngine_v3::drawMainBox(int x, int y, int w, int h, int fill) {466 debugC(9, kDebugLevelMain, "KyraEngine::drawMainBox(%d, %d, %d, %d, %d)", x, y, w, h, fill);467 static const uint8 colorTable[] = { 0x16, 0x19, 0x1A, 0x16 };468 --w; --h;469 470 if (fill) {471 _screen->fillRect(x, y, x+w, y+h, colorTable[0]);472 }473 474 _screen->drawClippedLine(x, y+h, x+w, y+h, colorTable[1]);475 _screen->drawClippedLine(x+w, y, x+w, y+h, colorTable[1]);476 _screen->drawClippedLine(x, y, x+w, y, colorTable[2]);477 _screen->drawClippedLine(x, y, x, y+h, colorTable[2]);478 479 _screen->setPagePixel(_screen->_curPage, x, y+h, colorTable[3]);480 _screen->setPagePixel(_screen->_curPage, x+w, y, colorTable[3]);481 }482 483 void KyraEngine_v3::gui_printString(const char *format, int x, int y, int col1, int col2, int flags, ...) {484 debugC(9, kDebugLevelMain, "KyraEngine::gui_printString('%s', %d, %d, %d, %d, %d, ...)", format, x, y, col1, col2, flags);485 if (!format)486 return;487 488 char string[512];489 va_list vaList;490 va_start(vaList, flags);491 vsprintf(string, format, vaList);492 va_end(vaList);493 494 if (flags & 1) {495 x -= _screen->getTextWidth(string) >> 1;496 }497 498 if (flags & 2) {499 x -= _screen->getTextWidth(string);500 }501 502 if (flags & 4) {503 _screen->printText(string, x - 1, y, 240, col2);504 _screen->printText(string, x, y + 1, 240, col2);505 }506 507 if (flags & 8) {508 _screen->printText(string, x - 1, y, 227, col2);509 _screen->printText(string, x, y + 1, 227, col2);510 }511 512 _screen->printText(string, x, y, col1, col2);513 }514 515 363 #pragma mark - 516 364 517 365 void KyraEngine_v3::preinit() { -
engines/kyra/kyra.h
696 696 void gui_restorePalette(); 697 697 void gui_setupControls(Menu &menu); 698 698 699 // Kyra 2 and 3 main menu 700 701 static const char *_mainMenuStrings[]; 702 virtual void gui_initMainMenu() {}; 703 int gui_handleMainMenu(); 704 virtual void gui_updateMainMenuAnimation(); 705 void gui_drawMainMenu(const char * const *strings, int select); 706 void gui_drawMainBox(int x, int y, int w, int h, int fill); 707 708 void gui_printString(const char *string, int x, int y, int col1, int col2, int flags, ...); 709 699 710 uint8 _game; 700 711 bool _quitFlag; 701 712 bool _skipFlag; … … 711 722 uint16 _gameSpeed; 712 723 uint16 _tickLength; 713 724 uint32 _features; 725 int _lang; 714 726 int _mouseX, _mouseY; 715 727 int8 _itemInHand; 716 728 int _mouseState; -
engines/kyra/screen.cpp
793 793 794 794 void Screen::setScreenDim(int dim) { 795 795 debugC(9, kDebugLevelScreen, "setScreenDim(%d)", dim); 796 if (_vm->game() != GI_KYRA3) {796 if (_vm->game() == GI_KYRA1) { 797 797 assert(dim < _screenDimTableCount); 798 798 _curDim = &_screenDimTable[dim]; 799 799 } else { -
engines/kyra/kyra2.h
31 31 ~KyraEngine_v2(); 32 32 33 33 int setupGameFlags() { _game = GI_KYRA2; return 0; } 34 34 35 35 int go(); 36 37 private: 38 int init(); 36 39 }; 37 40 38 41 } // end of namespace Kyra