Ticket #8599: AGI_SavegameMouseWithButtons.patch

File AGI_SavegameMouseWithButtons.patch, 3.4 KB (added by spookypeanut, 17 years ago)

Newer version of patch which replaces "Press ENTER" message with buttons

  • engines/agi/savegame.cpp

     
    458458        sprintf(saveLoadSlot, "%s.%.3d", _targetName.c_str(), num);
    459459        return saveLoadSlot;
    460460}
    461 
     461       
    462462int AgiEngine::selectSlot() {
    463463        int i, key, active = 0;
    464464        int rc = -1;
    465465        int hm = 2, vm = 3;     /* box margins */
     466        int xmin, xmax, slotClicked;
    466467        char desc[NUM_SLOTS][40];
     468        int textCentre, buttonLength, buttonX[2], buttonY;
     469        const char *buttonText[] = { "  OK  ", "Cancel", NULL };
    467470
    468471        for (i = 0; i < NUM_SLOTS; i++) {
    469472                char fileName[MAX_PATH];
    470473                Common::InSaveFile *in;
    471474               
    472                 debugC(4, kDebugLevelMain | kDebugLevelSavegame, "Game id seems to be %s", _targetName.c_str());
     475                debugC(4, kDebugLevelMain | kDebugLevelSavegame, "Current game id is %s", _targetName.c_str());
    473476                sprintf(fileName, "%s", getSavegameFilename(i));
    474477                if (!(in = _saveFileMan->openForLoading(fileName))) {
    475478                        debugC(4, kDebugLevelMain | kDebugLevelSavegame, "File %s does not exist", fileName);
     
    489492                }
    490493        }
    491494
     495        textCentre = GFX_WIDTH / CHAR_LINES / 2;
     496        buttonLength = 6;
     497        buttonX[0] = (textCentre - 3 * buttonLength / 2) * CHAR_COLS;
     498        buttonX[1] = (textCentre + buttonLength / 2) * CHAR_COLS;
     499        buttonY = (vm + 17) * CHAR_LINES;
     500       
     501        for (i = 0; i < 2; i++)
     502        _gfx->drawButton(buttonX[i], buttonY, buttonText[i], 0, 0, MSG_BOX_TEXT, MSG_BOX_COLOUR);
     503
    492504        for (;;) {
    493505                char dstr[64];
    494506                for (i = 0; i < NUM_SLOTS; i++) {
     
    496508                        printText(dstr, 0, hm + 1, vm + 4 + i,
    497509                                        (40 - 2 * hm) - 1, i == active ? MSG_BOX_COLOUR : MSG_BOX_TEXT,
    498510                                        i == active ? MSG_BOX_TEXT : MSG_BOX_COLOUR);
    499 
    500511                }
    501 
     512               
    502513                _gfx->pollTimer();      /* msdos driver -> does nothing */
    503514                key = doPollKeyboard();
    504515                switch (key) {
     
    510521                        rc = -1;
    511522                        goto getout;
    512523                case BUTTON_LEFT:
     524                        if (_gfx->testButton(buttonX[0], buttonY, buttonText[0])) {
     525                                rc = active;
     526                                strncpy(_game.strings[MAX_STRINGS], desc[i], MAX_STRINGLEN);
     527                                goto press;
     528                        }
     529                        if (_gfx->testButton(buttonX[1], buttonY, buttonText[1])) {
     530                                rc = -1;
     531                                goto getout;
     532                        }
     533                        xmin = (hm + 1) * CHAR_COLS;
     534                        xmax = xmin + CHAR_COLS * 34;
     535                        if ((int)g_mouse.x >= xmin && (int)g_mouse.x <= xmax) {
     536                                slotClicked = ((int)g_mouse.y-1)/CHAR_COLS-(vm+4);
     537                                if (slotClicked >= 0 && slotClicked < NUM_SLOTS)
     538                                        active = slotClicked;
     539                        }
    513540                        break;
    514541                case KEY_DOWN:
    515542                        active++;
     
    552579        drawWindow(hp, vp, GFX_WIDTH - hp, GFX_HEIGHT - vp);
    553580        printText("Select a slot in which you wish to save the game:",
    554581                        0, hm + 1, vm + 1, w, MSG_BOX_TEXT, MSG_BOX_COLOUR);
    555         printText("Press ENTER to select, ESC cancels",
    556                         0, hm + 1, vm + 17, w, MSG_BOX_TEXT, MSG_BOX_COLOUR);
    557582
    558583        slot = selectSlot();
    559584        if (slot < 0)   
     
    568593        _gfx->flushBlock(3 * CHAR_COLS, 11 * CHAR_LINES - 1,
    569594                        37 * CHAR_COLS, 12 * CHAR_LINES);
    570595
    571         getString(2, 11, 33, MAX_STRINGS);
     596        getString(2, 11, 31, MAX_STRINGS);
    572597        _gfx->printCharacter(3, 11, _game.cursorChar, MSG_BOX_COLOUR, MSG_BOX_TEXT);
    573598        do {
    574599                mainCycle();
     
    625650        drawWindow(hp, vp, GFX_WIDTH - hp, GFX_HEIGHT - vp);
    626651        printText("Select a game which you wish to\nrestore:",
    627652                        0, hm + 1, vm + 1, w, MSG_BOX_TEXT, MSG_BOX_COLOUR);
    628         printText("Press ENTER to select, ESC cancels",
    629                         0, hm + 1, vm + 17, w, MSG_BOX_TEXT, MSG_BOX_COLOUR);
    630653
    631654        slot = selectSlot();
    632655