NANCY: Implement UI button time delay

Added a time delay to the Menu and Help buttons as defined in the
boot summary. Also made the Help screen button use the same
time delay, instead of waiting for the sound.
This commit is contained in:
Kaloyan Chehlarski 2023-04-05 00:44:21 +03:00
parent 4b3b81eb52
commit 3e63de4aec
7 changed files with 29 additions and 17 deletions

View File

@ -73,8 +73,7 @@ BSUM::BSUM(Common::SeekableReadStream *chunkStream) {
s.skip(0x1A, kGameTypeVampire, kGameTypeVampire);
s.skip(0x1C, kGameTypeNancy1);
s.syncAsSint16LE(playerTimeMinuteLength);
s.skip(2);
s.syncAsUint16LE(buttonPressTimeDelay);
s.syncAsByte(overrideMovementTimeDeltas);
s.syncAsSint16LE(slowMovementTimeDelta);
s.syncAsSint16LE(fastMovementTimeDelta);

View File

@ -51,6 +51,7 @@ struct BSUM {
uint16 verticalEdgesSize;
uint16 playerTimeMinuteLength;
uint16 buttonPressTimeDelay;
byte overrideMovementTimeDeltas;
uint16 slowMovementTimeDelta;
uint16 fastMovementTimeDelta;

View File

@ -56,8 +56,8 @@ void Help::process() {
case kRun:
run();
break;
case kWaitForSound:
waitForSound();
case kWait:
wait();
break;
}
}
@ -111,13 +111,13 @@ void Help::run() {
if (_button->_isClicked) {
_button->_isClicked = false;
g_nancy->_sound->playSound("BUOK");
_state = kWaitForSound;
_buttonPressActivationTime = g_system->getMillis() + g_nancy->_bootSummary->buttonPressTimeDelay;
_state = kWait;
}
}
void Help::waitForSound() {
if (!g_nancy->_sound->isSoundPlaying("BUOK")) {
g_nancy->_sound->stopSound("BUOK");
void Help::wait() {
if (g_system->getMillis() > _buttonPressActivationTime) {
g_nancy->setToPreviousState();
}
}

View File

@ -40,7 +40,7 @@ namespace State {
class Help : public State, public Common::Singleton<Help> {
public:
enum State { kInit, kBegin, kRun, kWaitForSound };
enum State { kInit, kBegin, kRun, kWait };
Help();
virtual ~Help();
@ -53,11 +53,12 @@ private:
void init();
void begin();
void run();
void waitForSound();
void wait();
State _state;
UI::FullScreenImage _image;
UI::Button *_button;
Time _buttonPressActivationTime;
};
#define NancyHelpState Nancy::State::Help::instance()

View File

@ -717,9 +717,14 @@ void Scene::handleInput() {
_menuButton->handleInput(input);
if (_menuButton->_isClicked) {
_menuButton->_isClicked = false;
g_nancy->_sound->playSound("BUOK");
requestStateChange(NancyState::kMainMenu);
if (_buttonPressActivationTime == 0) {
g_nancy->_sound->playSound("BUOK");
_buttonPressActivationTime = g_system->getMillis() + g_nancy->_bootSummary->buttonPressTimeDelay;
} else if (g_system->getMillis() > _buttonPressActivationTime) {
_menuButton->_isClicked = false;
requestStateChange(NancyState::kMainMenu);
_buttonPressActivationTime = 0;
}
}
}
@ -727,9 +732,14 @@ void Scene::handleInput() {
_helpButton->handleInput(input);
if (_helpButton->_isClicked) {
_helpButton->_isClicked = false;
g_nancy->_sound->playSound("BUOK");
requestStateChange(NancyState::kHelp);
if (_buttonPressActivationTime == 0) {
g_nancy->_sound->playSound("BUOK");
_buttonPressActivationTime = g_system->getMillis() + g_nancy->_bootSummary->buttonPressTimeDelay;
} else if (g_system->getMillis() > _buttonPressActivationTime) {
_helpButton->_isClicked = false;
requestStateChange(NancyState::kHelp);
_buttonPressActivationTime = 0;
}
}
}
}

View File

@ -251,6 +251,7 @@ private:
UI::Button *_menuButton;
UI::Button *_helpButton;
Time _buttonPressActivationTime;
UI::ViewportOrnaments *_viewportOrnaments;
UI::TextboxOrnaments *_textboxOrnaments;

View File

@ -41,7 +41,7 @@ Button::Button(uint16 zOrder, Graphics::ManagedSurface &surface, const Common::R
}
void Button::handleInput(NancyInput &input) {
if (!_isClicked && _screenPosition.contains(input.mousePos)) {
if (_screenPosition.contains(input.mousePos)) {
g_nancy->_cursorManager->setCursorType(CursorManager::kHotspotArrow);
if (input.input & NancyInput::kLeftMouseButtonUp) {