SHERLOCK: RT: Implement Options dialog event handling

This commit is contained in:
Paul Gilbert 2015-07-23 22:56:42 -04:00
parent 1018dad556
commit c4736c274e
10 changed files with 325 additions and 6 deletions

View file

@ -38,6 +38,7 @@ MODULE_OBJS = \
tattoo/widget_inventory.o \
tattoo/widget_lab.o \
tattoo/widget_options.o \
tattoo/widget_quit.o \
tattoo/widget_talk.o \
tattoo/widget_text.o \
tattoo/widget_tooltip.o \

View file

@ -266,5 +266,9 @@ Audio::SoundHandle Sound::getFreeSoundHandle() {
error("getFreeSoundHandle: No sound handle found");
}
void Sound::setVolume(int volume) {
warning("TODO: setVolume - %d", volume);
}
} // End of namespace Sherlock

View file

@ -99,6 +99,8 @@ public:
void freeDigiSound();
Audio::SoundHandle getFreeSoundHandle();
void setVolume(int volume);
};
} // End of namespace Sherlock

View file

@ -87,7 +87,15 @@ public:
TattooEngine(OSystem *syst, const SherlockGameDescription *gameDesc);
virtual ~TattooEngine();
/**
* Shows the hangman puzzle
*/
void doHangManPuzzle();
/**
* Save the game configuration
*/
void saveConfig() {}
};
} // End of namespace Tattoo

View file

@ -374,15 +374,13 @@ void TattooUserInterface::doStandardControl() {
case Common::KEYCODE_F5:
// Save game
freeMenu();
_fileMode = SAVEMODE_SAVE;
initFileMenu();
saveGame();
return;
case Common::KEYCODE_F7:
// Load game
freeMenu();
_fileMode = SAVEMODE_LOAD;
initFileMenu();
loadGame();
return;
case Common::KEYCODE_F1:
@ -882,6 +880,16 @@ void TattooUserInterface::clearWindow() {
banishWindow();
}
void TattooUserInterface::loadGame() {
_fileMode = SAVEMODE_LOAD;
// TODO
}
void TattooUserInterface::saveGame() {
_fileMode = SAVEMODE_SAVE;
// TODO
}
} // End of namespace Tattoo
} // End of namespace Sherlock

View file

@ -204,6 +204,16 @@ public:
* If there is no object being pointed it, clear any previously displayed name
*/
void displayObjectNames();
/**
* Show the load game dialog, and allow the user to load a game
*/
void loadGame();
/**
* Show the save game dialog, and allow the user to save the game
*/
void saveGame();
public:
/**
* Resets the user interface

View file

@ -23,13 +23,14 @@
#include "sherlock/tattoo/widget_options.h"
#include "sherlock/tattoo/tattoo.h"
#include "sherlock/tattoo/tattoo_fixed_text.h"
#include "sherlock/tattoo/tattoo_scene.h"
#include "sherlock/tattoo/tattoo_user_interface.h"
namespace Sherlock {
namespace Tattoo {
WidgetOptions::WidgetOptions(SherlockEngine *vm) : WidgetBase(vm) {
WidgetOptions::WidgetOptions(SherlockEngine *vm) : WidgetBase(vm), _quitWidget(vm) {
_midiSliderX = _digiSliderX = 0;
_selector = _oldSelector = -1;
}
@ -56,8 +57,192 @@ void WidgetOptions::load() {
}
void WidgetOptions::handleEvents() {
TattooEngine &vm = *(TattooEngine *)_vm;
Events &events = *_vm->_events;
// TODO
Music &music = *_vm->_music;
Screen &screen = *_vm->_screen;
Sound &sound = *_vm->_sound;
Talk &talk = *_vm->_talk;
TattooUserInterface &ui = *(TattooUserInterface *)_vm->_ui;
Common::Point mousePos = events.mousePos();
if (talk._talkToAbort) {
sound.stopSound();
return;
}
// Flag if they started pressing outside the window
if (events._firstPress && !_bounds.contains(mousePos))
_outsideMenu = true;
if (events.kbHit()) {
ui._keyState = events.getKey();
// Emulate a mouse release if Enter or Space Bar is pressed
if (ui._keyState.keycode == Common::KEYCODE_RETURN || ui._keyState.keycode == Common::KEYCODE_SPACE) {
events._pressed = events._oldButtons = false;
events._released = true;
} else if (ui._keyState.keycode == Common::KEYCODE_ESCAPE) {
close();
return;
} else {
checkTabbingKeys(11);
}
}
// Check highlighting the various controls
if (_bounds.contains(mousePos)) {
_selector = (mousePos.y - _bounds.top) / (_surface.fontHeight() + 7);
// If one of the sliders has been selected, & the mouse is not pressed, reset the selector to -1
if ((_selector == 3 || _selector == 6) && !events._pressed)
_selector = -1;
} else {
_selector = -1;
if (_outsideMenu && (events._released || events._rightReleased)) {
close();
return;
}
}
// If the selected control has changed, redraw the dialog contents
if (_selector != _oldSelector)
render(OP_CONTENTS);
_oldSelector = _selector;
// Adjust the Volume Sliders (if neccessary) here
switch (_selector) {
case 3: {
// Set Music Volume
_midiSliderX = mousePos.x - _bounds.left;
if (_midiSliderX < _surface.widestChar())
_midiSliderX = _surface.widestChar();
else
if (_midiSliderX > _bounds.width() - _surface.widestChar())
_midiSliderX = _bounds.width() - _surface.widestChar();
int temp = music._musicVolume;
music._musicVolume = (_midiSliderX - _surface.widestChar()) * 127 / (_bounds.width() - _surface.widestChar() * 2);
if (music._musicVolume != temp) {
music.setMIDIVolume(music._musicVolume);
vm.saveConfig();
}
render(OP_NAMES);
break;
}
case 6: {
// Set Digitized Volume
_digiSliderX = mousePos.x - _bounds.left;
if (_digiSliderX < _surface.widestChar())
_digiSliderX = _surface.widestChar();
else if (_digiSliderX > _bounds.width() - _surface.widestChar())
_digiSliderX = _bounds.width() - _surface.widestChar();
int temp = sound._soundVolume;
sound._soundVolume = (_digiSliderX - _surface.widestChar()) * 15 / (_bounds.width() - _surface.widestChar() * 2);
if (sound._soundVolume != temp) {
sound.setVolume(sound._soundVolume);
vm.saveConfig();
}
render(OP_NAMES);
break;
}
default:
break;
}
// Option selected
if (events._released || events._rightReleased) {
_outsideMenu = false;
int temp = _selector;
_selector = 255;
switch (temp) {
case 0:
// Load Game
close();
ui.loadGame();
break;
case 1:
// Save Game
close();
ui.saveGame();
break;
case 2:
// Toggle Music
music._musicOn = !music._musicOn;
if (!music._musicOn)
music.stopMusic();
else
music.startSong();
render(OP_NAMES);
vm.saveConfig();
break;
case 4:
// Toggle Sound Effects
sound.stopSound();
sound._digitized = !sound._digitized;
render(OP_NAMES);
vm.saveConfig();
break;
case 5:
// Toggle Voices
sound._voices = !sound._voices;
render(OP_NAMES);
vm.saveConfig();
break;
case 7:
// Toggle Text Windows
vm._textWindowsOn = !vm._textWindowsOn;
render(OP_NAMES);
vm.saveConfig();
break;
case 8: {
// New Font Style
int fontNumber = screen.fontNumber() + 1;
if (fontNumber == 7)
fontNumber = 0;
screen.setFont(fontNumber);
render(OP_CONTENTS);
vm.saveConfig();
break;
}
case 9:
// Toggle Transparent Menus
vm._transparentMenus = !vm._transparentMenus;
render(OP_CONTENTS);
vm.saveConfig();
break;
case 10:
// Quit
banishWindow();
_quitWidget.show();
break;
default:
break;
}
_oldSelector = -1;
}
}
void WidgetOptions::render(OptionRenderMode mode) {
@ -192,6 +377,14 @@ void WidgetOptions::render(OptionRenderMode mode) {
}
}
void WidgetOptions::close() {
TattooScene &scene = *(TattooScene *)_vm->_scene;
TattooUserInterface &ui = *(TattooUserInterface *)_vm->_ui;
banishWindow();
ui._menuMode = scene._labTableScene ? LAB_MODE : STD_MODE;
}
} // End of namespace Tattoo
} // End of namespace Sherlock

View file

@ -25,6 +25,7 @@
#include "common/scummsys.h"
#include "sherlock/tattoo/widget_base.h"
#include "sherlock/tattoo/widget_quit.h"
namespace Sherlock {
@ -41,11 +42,17 @@ class WidgetOptions : public WidgetBase {
private:
int _midiSliderX, _digiSliderX;
int _selector, _oldSelector;
WidgetQuit _quitWidget;
/**
* Render the contents of the dialog onto the widget's surface
*/
void render(OptionRenderMode mode = OP_ALL);
/**
* Close the dialog
*/
void close();
public:
WidgetOptions(SherlockEngine *vm);
virtual ~WidgetOptions() {}

View file

@ -0,0 +1,36 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "sherlock/tattoo/widget_quit.h"
#include "sherlock/tattoo/tattoo.h"
namespace Sherlock {
namespace Tattoo {
void WidgetQuit::show() {
// TODO
}
} // End of namespace Tattoo
} // End of namespace Sherlock

View file

@ -0,0 +1,50 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#ifndef SHERLOCK_TATTOO_WIDGET_QUIT_H
#define SHERLOCK_TATTOO_WIDGET_QUIT_H
#include "common/scummsys.h"
#include "sherlock/tattoo/widget_base.h"
namespace Sherlock {
class SherlockEngine;
namespace Tattoo {
class WidgetQuit: public WidgetBase {
public:
WidgetQuit(SherlockEngine *vm) : WidgetBase(vm) {}
virtual ~WidgetQuit() {}
/**
* Prompt the user whether to quit
*/
void show();
};
} // End of namespace Tattoo
} // End of namespace Sherlock
#endif