From 821bbed1e052205746d9bc2118120a7d31a2a2a1 Mon Sep 17 00:00:00 2001 From: Torbjörn Andersson Date: Wed, 7 Jan 2004 19:03:30 +0000 Subject: Tried to make the menus behave a bit more like the original. Perhaps most noticeably: * It no longer matters where you release the mouse button when talking to someone. It uses whatever topic you selected on mouse-down. * The inventory menu doesn't vanish if you're holding an object, even if you move the pointer away from it. * When using an object on a character (to talk to him about it), the top menu fades away, rather than vanishing instantly. Ok, that last change is rather non-obvious, but it does obsolete the clearMenu() function, which has therefore been removed. svn-id: r12222 --- sword1/menu.cpp | 83 ++++++++++++++++++++++++++++++++++--------------------- sword1/mouse.cpp | 8 ++++-- sword1/screen.cpp | 11 -------- sword1/screen.h | 1 - 4 files changed, 56 insertions(+), 47 deletions(-) (limited to 'sword1') diff --git a/sword1/menu.cpp b/sword1/menu.cpp index aaafc5133d..d643a22850 100644 --- a/sword1/menu.cpp +++ b/sword1/menu.cpp @@ -128,47 +128,66 @@ uint8 SwordMenu::checkMenuClick(uint8 menuType) { return 0; uint16 x, y; _mouse->giveCoords(&x, &y); - if (menuType == MENU_BOT) { - for (uint8 cnt = 0; cnt < SwordLogic::_scriptVars[IN_SUBJECT]; cnt++) { - if (_subjects[cnt]->wasClicked(x, y)) { - if (mouseEvent & BS1L_BUTTON_DOWN) { - SwordLogic::_scriptVars[OBJECT_HELD] = _subjectBar[cnt]; - refreshMenus(); - } else if (mouseEvent & BS1L_BUTTON_UP) { - if (SwordLogic::_scriptVars[OBJECT_HELD] == _subjectBar[cnt]) + if (_subjectBarStatus == MENU_OPEN) { + // Conversation mode. Icons are highlighted on mouse-down, but + // the actual response is made on mouse-up. + if (menuType == MENU_BOT) { + if (SwordLogic::_scriptVars[OBJECT_HELD] && (mouseEvent & BS1L_BUTTON_UP)) { + for (uint8 cnt = 0; cnt < SwordLogic::_scriptVars[IN_SUBJECT]; cnt++) { + if (_subjectBar[cnt] == SwordLogic::_scriptVars[OBJECT_HELD]) + return cnt + 1; + } + } else if (mouseEvent & BS1L_BUTTON_DOWN) { + for (uint8 cnt = 0; cnt < SwordLogic::_scriptVars[IN_SUBJECT]; cnt++) { + if (_subjects[cnt]->wasClicked(x, y)) { + SwordLogic::_scriptVars[OBJECT_HELD] = _subjectBar[cnt]; + refreshMenus(); + break; + } + } + } + } else { + if (SwordLogic::_scriptVars[OBJECT_HELD] && (mouseEvent & BS1L_BUTTON_UP)) { + for (uint8 cnt = 0; cnt < _inMenu; cnt++) { + if (_menuList[cnt] == SwordLogic::_scriptVars[OBJECT_HELD]) return cnt + 1; - else { - SwordLogic::_scriptVars[OBJECT_HELD] = 0; + } + } else if (mouseEvent & BS1L_BUTTON_DOWN) { + for (uint8 cnt = 0; cnt < _inMenu; cnt++) { + if (_objects[cnt]->wasClicked(x, y)) { + SwordLogic::_scriptVars[OBJECT_HELD] = _menuList[cnt]; refreshMenus(); + break; } } } } } else { - for (uint8 cnt = 0; cnt < _inMenu; cnt++) { - if (_objects[cnt]->wasClicked(x, y)) { - if (mouseEvent & BS1R_BUTTON_DOWN) { // looking at item - SwordLogic::_scriptVars[OBJECT_HELD] = _menuList[cnt]; - SwordLogic::_scriptVars[MENU_LOOKING] = 1; - SwordLogic::_scriptVars[DEFAULT_ICON_TEXT] = _objectDefs[_menuList[cnt]].textDesc; - refreshMenus(); - } else if (mouseEvent & BS1L_BUTTON_DOWN) { - if (SwordLogic::_scriptVars[OBJECT_HELD]) { - if (SwordLogic::_scriptVars[OBJECT_HELD] == _menuList[cnt]) { - _mouse->setLuggage(0, 0); - SwordLogic::_scriptVars[OBJECT_HELD] = 0; // reselected => deselect it - } else { // the player is clicking another item on this one. - // run its use-script, if there is one - SwordLogic::_scriptVars[SECOND_ITEM] = _menuList[cnt]; - _mouse->setLuggage(0, 0); - } - } else { + // Normal use, i.e. inventory. Things happen on mouse-down. + if (menuType == MENU_TOP) { + for (uint8 cnt = 0; cnt < _inMenu; cnt++) { + if (_objects[cnt]->wasClicked(x, y)) { + if (mouseEvent & BS1R_BUTTON_DOWN) { // looking at item SwordLogic::_scriptVars[OBJECT_HELD] = _menuList[cnt]; - _mouse->setLuggage(_objectDefs[_menuList[cnt]].luggageIconRes, 0); - refreshMenus(); - return cnt + 1; + SwordLogic::_scriptVars[MENU_LOOKING] = 1; + SwordLogic::_scriptVars[DEFAULT_ICON_TEXT] = _objectDefs[_menuList[cnt]].textDesc; + } else if (mouseEvent & BS1L_BUTTON_DOWN) { + if (SwordLogic::_scriptVars[OBJECT_HELD]) { + if (SwordLogic::_scriptVars[OBJECT_HELD] == _menuList[cnt]) { + _mouse->setLuggage(0, 0); + SwordLogic::_scriptVars[OBJECT_HELD] = 0; // reselected => deselect it + } else { // the player is clicking another item on this one. + // run its use-script, if there is one + SwordLogic::_scriptVars[SECOND_ITEM] = _menuList[cnt]; + _mouse->setLuggage(0, 0); + } + } else { + SwordLogic::_scriptVars[OBJECT_HELD] = _menuList[cnt]; + _mouse->setLuggage(_objectDefs[_menuList[cnt]].luggageIconRes, 0); + } } refreshMenus(); + break; } } } @@ -352,5 +371,5 @@ void SwordMenu::fnAddSubject(int32 sub) { } void SwordMenu::cfnReleaseMenu(void) { - _screen->clearMenu(MENU_TOP); + _objectBarStatus = MENU_CLOSING; } diff --git a/sword1/mouse.cpp b/sword1/mouse.cpp index d455a17584..a42214ffc8 100644 --- a/sword1/mouse.cpp +++ b/sword1/mouse.cpp @@ -104,13 +104,15 @@ void SwordMouse::engine(uint16 x, uint16 y, uint16 eventFlags) { if (!SwordLogic::_scriptVars[TOP_MENU_DISABLED]) { if (y < 40) { // okay, we are in the top menu. if (!_inTopMenu) { // are we just entering it? - _menu->fnStartMenu(); + if (!SwordLogic::_scriptVars[OBJECT_HELD]) + _menu->fnStartMenu(); setPointer(MSE_POINTER, 0); } _menu->checkTopMenu(); _inTopMenu = true; } else if (_inTopMenu) { // we're not in the menu. did we just leave it? - _menu->fnEndMenu(); + if (!SwordLogic::_scriptVars[OBJECT_HELD]) + _menu->fnEndMenu(); _inTopMenu = false; } } else if (_inTopMenu) { @@ -144,7 +146,7 @@ void SwordMouse::engine(uint16 x, uint16 y, uint16 eventFlags) { _getOff = 0; } if (touchedId) { // there's something new selected, now. - if (_objList[clicked].compact->o_mouse_on) //run its get on + if (_objList[clicked].compact->o_mouse_on) //run its get on _logic->runMouseScript(_objList[clicked].compact, _objList[clicked].compact->o_mouse_on); _getOff = _objList[clicked].compact->o_mouse_off; //setup get-off for later diff --git a/sword1/screen.cpp b/sword1/screen.cpp index 553424f85c..ce80b3298c 100644 --- a/sword1/screen.cpp +++ b/sword1/screen.cpp @@ -763,17 +763,6 @@ void SwordScreen::showFrame(uint16 x, uint16 y, uint32 resId, uint32 frameNo, co _system->copy_rect(frame, 40, x, y, 40, 40); } -void SwordScreen::clearMenu(uint8 menuType) { - // isn't there a better way to do this? - uint8 *tmp = (uint8*)malloc(640 * 40); - memset(tmp, 0, 640 * 40); - if (menuType == MENU_BOT) - _system->copy_rect(tmp, 640, 0, 440, 640, 40); - else - _system->copy_rect(tmp, 640, 0, 0, 640, 40); - free(tmp); -} - // ------------------- router debugging code -------------------------------- void SwordScreen::vline(uint16 x, uint16 y1, uint16 y2) { diff --git a/sword1/screen.h b/sword1/screen.h index b30cb27643..8abe94a95b 100644 --- a/sword1/screen.h +++ b/sword1/screen.h @@ -82,7 +82,6 @@ public: void updateScreen(void); void showFrame(uint16 x, uint16 y, uint32 resId, uint32 frameNo, const byte *fadeMask = NULL, int8 fadeStatus = 0); - void clearMenu(uint8 menuType); void fnSetParallax(uint32 screen, uint32 resId); void fnFlash(uint8 color); -- cgit v1.2.3