More BS2 restructuring.

The various game settings are no longer stored in the Gui class. They are
stored in the class that use them.

Code that doesn't belong in the Gui class, e.g. the "restart" code, has
been moved out of it.

Afterwards, the Gui class had been reduced to nothing more than a handful
of trivial methods for invoking the in-game dialogs. So the entire Gui
class has been removed.

svn-id: r16827
This commit is contained in:
Torbjörn Andersson 2005-02-20 15:38:48 +00:00
parent b1039bb59e
commit 807b33ec29
11 changed files with 825 additions and 775 deletions

View File

@ -30,7 +30,6 @@
#include "sword2/sword2.h"
#include "sword2/defs.h"
#include "sword2/build_display.h"
#include "sword2/controls.h"
#include "sword2/interpreter.h"
#include "sword2/logic.h"
#include "sword2/maketext.h"
@ -246,7 +245,7 @@ void Logic::createSequenceSpeech(MovieTextObject *sequenceText[]) {
// if we want subtitles, or speech failed to load
if (_vm->_gui->_subtitles || !speechRunning) {
if (_vm->getSubtitles() || !speechRunning) {
// open text resource & get the line
text = _vm->fetchTextLine(_vm->_resman->openResource(text_res), local_text);
// make the sprite

File diff suppressed because it is too large Load Diff

View File

@ -21,33 +21,152 @@
#ifndef _CONTROL_S
#define _CONTROL_S
#include "sword2/defs.h"
#define MAX_WIDGETS 25
namespace Sword2 {
class Sword2Engine;
class FontRendererGui;
class Widget;
class Switch;
class Slider;
class Button;
class ScrollButton;
class Slot;
enum {
kSaveDialog,
kLoadDialog
};
/**
* Base class for all dialogs.
*/
class Dialog {
private:
int _numWidgets;
Widget *_widgets[MAX_WIDGETS];
bool _finish;
int _result;
class Gui {
public:
Sword2Engine *_vm;
int _baseSlot;
uint8 _currentGraphicsLevel;
Dialog(Sword2Engine *vm);
virtual ~Dialog();
bool _subtitles;
bool _pointerTextSelected;
void registerWidget(Widget *widget);
Gui(Sword2Engine *vm);
virtual void paint();
virtual void setResult(int result);
uint32 restoreControl(void);
void saveControl(void);
bool startControl(void);
void quitControl(void);
void restartControl(void);
void optionControl(void);
void readOptionSettings(void);
void writeOptionSettings(void);
void updateGraphicsLevel(int newLevel);
virtual int runModal();
virtual void onAction(Widget *widget, int result = 0) {}
};
class OptionsDialog : public Dialog {
private:
FontRendererGui *_fr;
Widget *_panel;
Switch *_objectLabelsSwitch;
Switch *_subtitlesSwitch;
Switch *_reverseStereoSwitch;
Switch *_musicSwitch;
Switch *_speechSwitch;
Switch *_fxSwitch;
Slider *_musicSlider;
Slider *_speechSlider;
Slider *_fxSlider;
Slider *_gfxSlider;
Widget *_gfxPreview;
Button *_okButton;
Button *_cancelButton;
SoundMixer *_mixer;
public:
OptionsDialog(Sword2Engine *vm);
~OptionsDialog();
virtual void paint();
virtual void onAction(Widget *widget, int result = 0);
};
class SaveLoadDialog : public Dialog {
private:
int _mode, _selectedSlot;
byte _editBuffer[SAVE_DESCRIPTION_LEN];
int _editPos, _firstPos;
int _cursorTick;
FontRendererGui *_fr1;
FontRendererGui *_fr2;
Widget *_panel;
Slot *_slotButton[8];
ScrollButton *_zupButton;
ScrollButton *_upButton;
ScrollButton *_downButton;
ScrollButton *_zdownButton;
Button *_okButton;
Button *_cancelButton;
public:
SaveLoadDialog(Sword2Engine *vm, int mode);
~SaveLoadDialog();
void updateSlots();
void drawEditBuffer(Slot *slot);
virtual void onAction(Widget *widget, int result = 0);
virtual void paint();
virtual void setResult(int result);
virtual int runModal();
};
/**
* A "mini" dialog is usually a yes/no question, but also used for the
* restart/restore dialog at the beginning of the game.
*/
class MiniDialog : public Dialog {
private:
uint32 _headerTextId;
uint32 _okTextId;
uint32 _cancelTextId;
FontRendererGui *_fr;
Widget *_panel;
Button *_okButton;
Button *_cancelButton;
public:
MiniDialog(Sword2Engine *vm, uint32 headerTextId, uint32 okTextId = TEXT_OK, uint32 cancelTextId = TEXT_CANCEL);
virtual ~MiniDialog();
virtual void paint();
virtual void onAction(Widget *widget, int result = 0);
};
class StartDialog : public MiniDialog {
public:
StartDialog(Sword2Engine *vm);
virtual int runModal();
};
class RestartDialog : public MiniDialog {
public:
RestartDialog(Sword2Engine *vm);
virtual int runModal();
};
class QuitDialog : public MiniDialog {
public:
QuitDialog(Sword2Engine *vm);
virtual int runModal();
};
} // End of namespace Sword2
#endif

View File

@ -24,6 +24,21 @@
#define SIZE 0x10000 // 65536 items per section
#define NuSIZE 0xffff // & with this
#define TEXT_OK 0x08EB0000
#define TEXT_CANCEL 0x08EB0001
#define TEXT_RESTORE 0x08EB0002
#define TEXT_SAVE 0x08EB0003
#define TEXT_QUIT 0x08EB0004
#define TEXT_RESTART 0x08EB0005
#define TEXT_OPTIONS 0x08EB000A
#define TEXT_SUBTITLES 0x08EB000B
#define TEXT_OBJECT_LABELS 0x08EB000C
#define TEXT_MUSIC_VOLUME 0x08EB000E
#define TEXT_SPEECH_VOLUME 0x08EB000F
#define TEXT_FX_VOLUME 0x08EB0010
#define TEXT_GFX_QUALITY 0x08EB0011
#define TEXT_REVERSE_STEREO 0x08EB0015
// always 8 (George object used for Nico player character as well)
#define CUR_PLAYER_ID 8

View File

@ -26,7 +26,6 @@
#include "sword2/defs.h"
#include "sword2/build_display.h"
#include "sword2/console.h"
#include "sword2/controls.h"
#include "sword2/interpreter.h"
#include "sword2/logic.h"
#include "sword2/maketext.h"
@ -1246,7 +1245,7 @@ int32 Logic::fnISpeak(int32 *params) {
// we don't want to use a wav for this line either, then just
// quit back to script right now!
if (!_vm->_gui->_subtitles && !wantSpeechForLine(params[S_WAV]))
if (!_vm->getSubtitles() && !wantSpeechForLine(params[S_WAV]))
return IR_CONT;
// Drop out for 1st cycle to allow walks/anims to end and
@ -1411,7 +1410,7 @@ int32 Logic::fnISpeak(int32 *params) {
}
}
if (_vm->_gui->_subtitles || !speechRunning) {
if (_vm->getSubtitles() || !speechRunning) {
// We want subtitles, or the speech failed to load.
// Either way, we're going to show the text so create
// the text sprite.

View File

@ -326,19 +326,34 @@ void Mouse::systemMenuMouse(void) {
switch (hit) {
case 0:
_vm->_gui->optionControl();
{
OptionsDialog dialog(_vm);
dialog.runModal();
}
break;
case 1:
_vm->_gui->quitControl();
{
QuitDialog dialog(_vm);
dialog.runModal();
}
break;
case 2:
_vm->_gui->saveControl();
{
SaveLoadDialog dialog(_vm, kSaveDialog);
dialog.runModal();
}
break;
case 3:
_vm->_gui->restoreControl();
{
SaveLoadDialog dialog(_vm, kLoadDialog);
dialog.runModal();
}
break;
case 4:
_vm->_gui->restartControl();
{
RestartDialog dialog(_vm);
dialog.runModal();
}
break;
}
@ -993,7 +1008,7 @@ void Mouse::createPointerText(uint32 text_id, uint32 pointer_res) {
int16 xOffset, yOffset;
uint8 justification;
if (!_vm->_gui->_pointerTextSelected || !text_id)
if (!_objectLabels || !text_id)
return;
// Check what the pointer is, to set offsets correctly for text

View File

@ -135,6 +135,8 @@ private:
uint32 _mouseTouching;
uint32 _oldMouseTouching;
bool _objectLabels;
uint32 _menuSelectedPos;
void decompressMouse(byte *decomp, byte *comp, int width, int height, int pitch, int xOff = 0, int yOff = 0);
@ -151,6 +153,9 @@ public:
void getPos(int &x, int &y);
void setPos(int x, int y);
bool getObjectLabels() { return _objectLabels; }
void setObjectLabels(bool b) { _objectLabels = b; }
bool getMouseStatus() { return _mouseStatus; }
uint32 getMouseTouching() { return _mouseTouching; }
void setMouseTouching(uint32 touching) { _mouseTouching = touching; }

View File

@ -102,6 +102,22 @@ uint32 Sword2Engine::saveGame(uint16 slotNo, byte *desc) {
uint32 errorCode = saveData(slotNo, saveBufferMem, bufferSize);
free(saveBufferMem);
if (errorCode != SR_OK) {
uint32 textId;
switch (errorCode) {
case SR_ERR_FILEOPEN:
textId = 213516674;
break;
default: // SR_ERR_WRITEFAIL
textId = 213516676;
break;
}
_screen->displayMsg(fetchTextLine(_resman->openResource(textId / SIZE), textId & 0xffff) + 2, 0);
}
return errorCode;
}
@ -205,6 +221,37 @@ uint32 Sword2Engine::restoreGame(uint16 slotNo) {
else
free(saveBufferMem);
if (errorCode != SR_OK) {
uint32 textId;
switch (errorCode) {
case SR_ERR_FILEOPEN:
textId = 213516670;
break;
case SR_ERR_INCOMPATIBLE:
textId = 213516671;
break;
default: // SR_ERR_READFAIL
textId = 213516673;
break;
}
_screen->displayMsg(fetchTextLine(_resman->openResource(textId / SIZE), textId & 0xffff) + 2, 0);
} else {
// Prime system with a game cycle
// Reset the graphic 'BuildUnit' list before a new logic list
// (see fnRegisterFrame)
_screen->resetRenderLists();
// Reset the mouse hot-spot list. See fnRegisterMouse()
// and fnRegisterFrame()
_mouse->resetMouseList();
if (_logic->processSession())
error("restore 1st cycle failed??");
}
// Force the game engine to pick a cursor. This appears to be needed
// when using the -x command-line option to restore a game.
_mouse->setMouseTouching(1);

View File

@ -23,7 +23,6 @@
#include "sword2/sword2.h"
#include "sword2/console.h"
#include "sword2/controls.h"
#include "sword2/defs.h"
#include "sword2/interpreter.h"
#include "sword2/logic.h"

View File

@ -38,6 +38,7 @@
#include "sword2/memory.h"
#include "sword2/mouse.h"
#include "sword2/resman.h"
#include "sword2/router.h"
#include "sword2/sound.h"
#ifdef _WIN32_WCE
@ -128,7 +129,6 @@ Sword2Engine::Sword2Engine(GameDetector *detector, OSystem *syst) : Engine(syst)
_mouse = NULL;
_logic = NULL;
_fontRenderer = NULL;
_gui = NULL;
_debugger = NULL;
_keyboardEvent.pending = false;
@ -152,7 +152,6 @@ Sword2Engine::Sword2Engine(GameDetector *detector, OSystem *syst) : Engine(syst)
Sword2Engine::~Sword2Engine() {
delete _debugger;
delete _sound;
delete _gui;
delete _fontRenderer;
delete _screen;
delete _mouse;
@ -179,6 +178,43 @@ void Sword2Engine::errorString(const char *buf1, char *buf2) {
}
}
void Sword2Engine::registerDefaultSettings() {
ConfMan.registerDefault("music_mute", false);
ConfMan.registerDefault("speech_mute", false);
ConfMan.registerDefault("sfx_mute", false);
ConfMan.registerDefault("gfx_details", 2);
ConfMan.registerDefault("subtitles", false);
ConfMan.registerDefault("reverse_stereo", false);
}
void Sword2Engine::readSettings() {
_mixer->setVolumeForSoundType(SoundMixer::kMusicAudioDataType, ConfMan.getInt("music_volume"));
_mixer->setVolumeForSoundType(SoundMixer::kSpeechAudioDataType, ConfMan.getInt("speech_volume"));
_mixer->setVolumeForSoundType(SoundMixer::kSFXAudioDataType, ConfMan.getInt("sfx_volume"));
setSubtitles(ConfMan.getBool("subtitles"));
_sound->muteMusic(ConfMan.getBool("music_mute"));
_sound->muteSpeech(ConfMan.getBool("speech_mute"));
_sound->muteFx(ConfMan.getBool("sfx_mute"));
_sound->setReverseStereo(ConfMan.getBool("reverse_stereo"));
_mouse->setObjectLabels(ConfMan.getBool("object_labels"));
_screen->setRenderLevel(ConfMan.getInt("gfx_details"));
}
void Sword2Engine::writeSettings() {
ConfMan.set("music_volume", _mixer->getVolumeForSoundType(SoundMixer::kMusicAudioDataType));
ConfMan.set("speech_volume", _mixer->getVolumeForSoundType(SoundMixer::kSpeechAudioDataType));
ConfMan.set("sfx_volume", _mixer->getVolumeForSoundType(SoundMixer::kSFXAudioDataType));
ConfMan.set("music_mute", _sound->isMusicMute());
ConfMan.set("speech_mute", _sound->isSpeechMute());
ConfMan.set("sfx_mute", _sound->isFxMute());
ConfMan.set("gfx_details", _screen->getRenderLevel());
ConfMan.set("subtitles", getSubtitles());
ConfMan.set("object_labels", _mouse->getObjectLabels());
ConfMan.set("reverse_stereo", _sound->isReverseStereo());
ConfMan.flushToDisk();
}
/**
* The global script variables and player object should be kept open throughout
* the game, so that they are never expelled by the resource manager.
@ -209,7 +245,6 @@ int Sword2Engine::init(GameDetector &detector) {
_resman = new ResourceManager(this);
_logic = new Logic(this);
_fontRenderer = new FontRenderer(this);
_gui = new Gui(this);
_sound = new Sound(this);
_mouse = new Mouse(this);
@ -217,9 +252,8 @@ int Sword2Engine::init(GameDetector &detector) {
if (!_mixer->isReady())
warning("Sound initialization failed");
_mixer->setVolumeForSoundType(SoundMixer::kMusicAudioDataType, ConfMan.getInt("music_volume"));
_mixer->setVolumeForSoundType(SoundMixer::kSpeechAudioDataType, ConfMan.getInt("speech_volume"));
_mixer->setVolumeForSoundType(SoundMixer::kSFXAudioDataType, ConfMan.getInt("sfx_volume"));
registerDefaultSettings();
readSettings();
initStartMenu();
@ -235,14 +269,15 @@ int Sword2Engine::init(GameDetector &detector) {
else
Logic::_scriptVars[DEMO] = 0;
_gui->readOptionSettings();
if (_saveSlot != -1) {
if (saveExists(_saveSlot))
restoreGame(_saveSlot);
else {
SaveLoadDialog dialog(this, kLoadDialog);
_mouse->setMouse(NORMAL_MOUSE_ID);
if (!_gui->restoreControl())
if (!dialog.runModal())
startGame();
}
} else if (!_bootParam && saveExists()) {
@ -251,7 +286,10 @@ int Sword2Engine::init(GameDetector &detector) {
_mouse->setMouse(NORMAL_MOUSE_ID);
_logic->fnPlayMusic(pars);
result = _gui->startControl();
StartDialog dialog(this);
result = dialog.runModal();
// If the game is started from the beginning, the cutscene
// player will kill the music for us. Otherwise, the restore
@ -350,6 +388,63 @@ void Sword2Engine::closeGame() {
_quit = true;
}
void Sword2Engine::restartGame() {
ScreenInfo *screenInfo = _screen->getScreenInfo();
uint32 temp_demo_flag;
_mouse->closeMenuImmediately();
// Restart the game. To do this, we must...
// Stop music instantly!
_sound->stopMusic(true);
// In case we were dead - well we're not anymore!
Logic::_scriptVars[DEAD] = 0;
// Restart the game. Clear all memory and reset the globals
temp_demo_flag = Logic::_scriptVars[DEMO];
// Remove all resources from memory, including player object and
// global variables
_resman->removeAll();
// Reopen global variables resource and player object
setupPersistentResources();
Logic::_scriptVars[DEMO] = temp_demo_flag;
// Free all the route memory blocks from previous game
_logic->_router->freeAllRouteMem();
// Call the same function that first started us up
startGame();
// Prime system with a game cycle
// Reset the graphic 'BuildUnit' list before a new logic list
// (see fnRegisterFrame)
_screen->resetRenderLists();
// Reset the mouse hot-spot list (see fnRegisterMouse and
// fnRegisterFrame)
_mouse->resetMouseList();
_mouse->closeMenuImmediately();
// FOR THE DEMO - FORCE THE SCROLLING TO BE RESET!
// - this is taken from fnInitBackground
// switch on scrolling (2 means first time on screen)
screenInfo->scroll_flag = 2;
if (_logic->processSession())
error("restart 1st cycle failed??");
// So palette not restored immediately after control panel - we want
// to fade up instead!
screenInfo->new_palette = 99;
}
bool Sword2Engine::checkForMouseEvents() {
return _mouseEvent.pending;
}
@ -529,11 +624,11 @@ void Sword2Engine::pauseGame() {
_sound->pauseAllSound();
_mouse->pauseGame();
// If level at max, turn down because palette-matching won't work
// when dimmed
// If render level is at max, turn it down because palette-matching
// won't work when the palette is dimmed.
if (_gui->_currentGraphicsLevel == 3) {
_gui->updateGraphicsLevel(2);
if (_screen->getRenderLevel() == 3) {
_screen->setRenderLevel(2);
_graphicsLevelFudged = true;
}
@ -559,7 +654,7 @@ void Sword2Engine::unpauseGame() {
// If graphics level at max, turn up again
if (_graphicsLevelFudged) {
_gui->updateGraphicsLevel(3);
_screen->setRenderLevel(3);
_graphicsLevelFudged = false;
}

View File

@ -111,6 +111,8 @@ private:
uint32 _totalScreenManagers;
uint32 _startRes;
bool _useSubtitles;
struct StartUp {
char description[MAX_description];
@ -131,8 +133,15 @@ public:
int go();
int init(GameDetector &detector);
void registerDefaultSettings();
void readSettings();
void writeSettings();
void setupPersistentResources();
bool getSubtitles() { return _useSubtitles; }
void setSubtitles(bool b) { _useSubtitles = b; }
bool _quit;
uint32 _features;
@ -145,7 +154,6 @@ public:
Mouse *_mouse;
Logic *_logic;
FontRenderer *_fontRenderer;
Gui *_gui;
Debugger *_debugger;
@ -238,6 +246,7 @@ public:
void startGame();
void gameCycle();
void closeGame();
void restartGame();
void sleepUntil(uint32 time);