Skip to content

Commit

Permalink
SWORD1: Improve accuracy of menu bars handling
Browse files Browse the repository at this point in the history
More specifically:
- Improve handling of menu bar fading during a palette fade;
- Fix _getOff not being handled if top menu was disabled.
  • Loading branch information
AndywinXp committed Oct 8, 2023
1 parent 083a3f9 commit 730af6e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
27 changes: 26 additions & 1 deletion engines/sword1/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,14 +389,39 @@ void Menu::setToTargetState() {
// Note that we are only doing this for the top menu:
// I haven't seen any instance of a bottom menu (dialog)
// being able to immediately open after a palette fade.
if (_objectBarStatus == MENU_CLOSING)
if (_objectBarStatus == MENU_CLOSING) {
_objectBarStatus = MENU_CLOSED;
_fadeObject = 0;
for (int i = 0; i < 16; i++) {
if (_objects[i])
_objects[i]->draw(_fadeEffectTop, _fadeObject);
else
_screen->showFrame(i * 40, 0, 0xffffffff, 0, _fadeEffectTop, _fadeObject);
}
}

if (_objectBarStatus == MENU_OPENING) {
_objectBarStatus = MENU_OPEN;
_fadeObject = 8;
showMenu(MENU_TOP);
}

if (_subjectBarStatus == MENU_CLOSING) {
_subjectBarStatus = MENU_CLOSED;
_fadeSubject = 0;
for (int i = 0; i < 16; i++) {
if (_subjects[i])
_subjects[i]->draw(_fadeEffectBottom, _fadeSubject);
else
_screen->showFrame(i * 40, 440, 0xffffffff, 0, _fadeEffectBottom, _fadeSubject);
}
}

if (_subjectBarStatus == MENU_OPENING) {
_subjectBarStatus = MENU_OPEN;
_fadeSubject = 8;
showMenu(MENU_TOP);
}
}

int Menu::logicChooser(Object *compact) {
Expand Down
2 changes: 1 addition & 1 deletion engines/sword1/mouse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ void Mouse::engine(uint16 x, uint16 y, uint16 eventFlags) {
//-
int32 touchedId = 0;
uint16 clicked = 0;
if (y > 40) {
if ((y > 40 && _inTopMenu) || !_inTopMenu) {
for (uint16 priority = 0; (priority < 10) && (!touchedId); priority++) {
for (uint16 cnt = 0; (cnt < _numObjs) && (!touchedId); cnt++) {
if ((_objList[cnt].compact->o_priority == priority) &&
Expand Down
6 changes: 5 additions & 1 deletion engines/sword1/sword1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1230,7 +1230,7 @@ static void vblCallback(void *refCon) {
if ((vm->_vblCount == 3) || (vm->_vblCount == 7)) {
vm->updateBottomMenu();
}
} else {
} else if (vm->fadeDirectionIsUp()) {
// This is an optimization for all the locks introduced
// with the fade palette changes: we disable the menu
// updates whenever the palette is fading, and we bring
Expand All @@ -1254,6 +1254,10 @@ bool SwordEngine::screenIsFading() {
return _screen->stillFading() != 0;
}

bool SwordEngine::fadeDirectionIsUp() {
return _screen->stillFading() == 1;
}

void SwordEngine::installTimerRoutines() {
debug(2, "SwordEngine::installTimerRoutines(): Installing timers...");
_ticker = 0;
Expand Down
1 change: 1 addition & 0 deletions engines/sword1/sword1.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ class SwordEngine : public Engine {
void startFadePaletteUp(int speed);
void waitForFade();
bool screenIsFading();
bool fadeDirectionIsUp();
void setMenuToTargetState();

void showDebugInfo();
Expand Down

0 comments on commit 730af6e

Please sign in to comment.