Skip to content
This repository has been archived by the owner on Sep 8, 2024. It is now read-only.

STARK: Implement the settings menu #1417

Merged
merged 24 commits into from
May 29, 2018
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
74f3565
STARK: Fix the screen name stack
Dougaak May 21, 2018
19fed32
STARK: Build the Settings and link it with other screens
Dougaak May 21, 2018
ab76813
STARK: Change numbers to enums for readability
Dougaak May 22, 2018
83f3126
STARK: Implement CheckBoxWidget
Dougaak May 22, 2018
121cbc0
STARK: Roughly Implement VolumeWidget
Dougaak May 22, 2018
4159a8b
STARK: Implement the dragged widget
Dougaak May 23, 2018
2b40b95
STARK: Add the sound on the slider
Dougaak May 23, 2018
a8c3b32
STARK: Implement settings save and load
Dougaak May 24, 2018
ef83a24
STARK: Enable subtitles setting
Dougaak May 24, 2018
eacc77a
STARK: Enable special effects setting (unchecked)
Dougaak May 24, 2018
eeb0bc7
STARK: Enable time skip setting
Dougaak May 24, 2018
86732d7
STARK: Enable video quality setting
Dougaak May 24, 2018
a5df211
STARK: Enable volume setting
Dougaak May 25, 2018
e94d2a7
STARK: SpecialFX setting checked
Dougaak May 25, 2018
1079124
STARK: Add SpecialFX comments
Dougaak May 25, 2018
464b9bb
STARK: Fix SoundManager's memory problem
Dougaak May 26, 2018
7001c9c
STARK: Enable low-quality model setting
Dougaak May 26, 2018
dbb16f1
STARK: Twist the sliders' position
Dougaak May 27, 2018
484b36b
STARK: Small fixing on settings
Dougaak May 27, 2018
a176e21
STARK: Move isDemo() to Settings service
Dougaak May 27, 2018
924359e
STARK: Name changed
Dougaak May 27, 2018
03eeb91
STARK: Allow StaticLocationWidget has empty renderentry
Dougaak May 27, 2018
841c798
STARK: Fix low-res FMV wrong ration problem
Dougaak May 29, 2018
ccf04a2
STARK: Small fixing
Dougaak May 29, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions engines/stark/gfx/renderentry.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ class RenderEntry {
void setSortKey(float sortKey);
void setClickable(bool clickable);

/** Gets the position */
Common::Point getPosition() const { return _position; }

/** Gets the owner-object */
Resources::ItemVisual *getOwner() const { return _owner; }

Expand Down
2 changes: 2 additions & 0 deletions engines/stark/module.mk
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ MODULE_OBJS := \
services/stateprovider.o \
services/staticprovider.o \
services/userinterface.o \
services/settings.o \
stark.o \
tools/abstractsyntaxtree.o \
tools/block.o \
Expand All @@ -88,6 +89,7 @@ MODULE_OBJS := \
ui/menu/diaryindex.o \
ui/menu/locationscreen.o \
ui/menu/mainmenu.o \
ui/menu/settingsmenu.o \
ui/window.o \
ui/world/actionmenu.o \
ui/world/button.o \
Expand Down
3 changes: 3 additions & 0 deletions engines/stark/resources/anim.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ class Anim : public Object {
// Resource API
void readData(Formats::XRCReadStream *stream) override;

/** Get current displayed frame */
uint32 getCurrentFrame() { return _currentFrame; }

/** Sets the animation frame to be displayed */
virtual void selectFrame(uint32 frameIndex);

Expand Down
3 changes: 3 additions & 0 deletions engines/stark/resources/sound.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ class Sound : public Object {
/** Fade the sound's current volume and pan to the specified target over duration milliseconds */
void changeVolumePan(int32 volume, int32 pan, int32 duration);

/** Set whether to loop or not */
void setLooping(bool looping) { _looping = looping; }

protected:
void printData() override;

Expand Down
5 changes: 5 additions & 0 deletions engines/stark/services/services.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class ResourceProvider;
class StaticProvider;
class Scene;
class UserInterface;
class Settings;

/**
* Public services available as a singleton
Expand All @@ -67,6 +68,8 @@ class StarkServices : public Common::Singleton<StarkServices> {
gameInterface = nullptr;
userInterface = nullptr;
fontProvider = nullptr;
gameDescription = nullptr;
settings = nullptr;
}

ArchiveLoader *archiveLoader;
Expand All @@ -82,6 +85,7 @@ class StarkServices : public Common::Singleton<StarkServices> {
UserInterface *userInterface;
FontProvider *fontProvider;
const ADGameDescription *gameDescription;
Settings *settings;
};

/** Shortcuts for accessing the services. */
Expand All @@ -98,6 +102,7 @@ class StarkServices : public Common::Singleton<StarkServices> {
#define StarkUserInterface StarkServices::instance().userInterface
#define StarkFontProvider StarkServices::instance().fontProvider
#define StarkGameDescription StarkServices::instance().gameDescription
#define StarkSettings StarkServices::instance().settings

} // End of namespace Stark

Expand Down
83 changes: 83 additions & 0 deletions engines/stark/services/settings.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/* ResidualVM - A 3D game interpreter
*
* ResidualVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the AUTHORS
* 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 "engines/stark/services/settings.h"
#include "engines/stark/services/services.h"
#include "engines/stark/services/archiveloader.h"

#include "common/config-manager.h"
#include "common/debug.h"

#include "audio/mixer.h"

namespace Stark {

Settings::Settings(Audio::Mixer *mixer) :
_mixer(mixer) {
// Initialize keys
_boolKey[kHighModel] = "high_model";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The settings name are user facing through the configuration file. I suggest using more explicit names:

  • high_model => use_high_resolution_models
  • specialfx => enable_special_effects
  • shadow => enable_shadows
  • high_fmv => play_high_resolution_videos

_boolKey[kSubtitle] = "subtitles";
_boolKey[kSpecialFX] = "specialfx";
_boolKey[kShadow] = "shadow";
_boolKey[kHighFMV] = "high_fmv";
_boolKey[kTimeSkip] = "enable_time_skip";
_intKey[kVoice] = "speech_volume";
_intKey[kMusic] = "music_volume";
_intKey[kSfx] = "sfx_volume";

// Register default settings
ConfMan.registerDefault(_boolKey[kHighModel], true);
ConfMan.registerDefault(_boolKey[kSubtitle], true);
ConfMan.registerDefault(_boolKey[kSpecialFX], true);
ConfMan.registerDefault(_boolKey[kShadow], true);
ConfMan.registerDefault(_boolKey[kHighFMV], true);
ConfMan.registerDefault(_boolKey[kTimeSkip], false);

// Use the FunCom logo video to check low-resolution fmv
_hasLowRes = StarkArchiveLoader->getExternalFile("1402_lo_res.bbb", "Global/");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This causes a memory leak when the file is found:

Direct leak of 24 byte(s) in 1 object(s) allocated from:
    #0 0x7ff445ad1a91 in operator new(unsigned long) /build/gcc/src/gcc/libsanitizer/asan/asan_new_delete.cc:90
    #1 0x562c7ce33a29 in StdioStream::makeFromPath(Common::String const&, bool) ../backends/fs/stdiostream.cpp:102
    #2 0x562c7ce263f4 in POSIXFilesystemNode::createReadStream() ../backends/fs/posix/posix-fs.cpp:254
    #3 0x562c7d0598e7 in Common::FSNode::createReadStream() const ../common/fs.cpp:140
    #4 0x562c7d05a6ce in Common::FSDirectory::createReadStreamForMember(Common::String const&) const ../common/fs.cpp:233
    #5 0x562c7d03f504 in Common::SearchSet::createReadStreamForMember(Common::String const&) const ../common/archive.cpp:260
    #6 0x562c7cbe460d in Stark::ArchiveLoader::getExternalFile(Common::String const&, Common::String const&) const ../engines/stark/services/archiveloader.cpp:153
    #7 0x562c7cc11c0a in Stark::Settings::Settings(Audio::Mixer*) ../engines/stark/services/settings.cpp:56
    #8 0x562c7cb7c35c in Stark::StarkEngine::run() ../engines/stark/stark.cpp:126
    #9 0x562c7cb41c61 in runGame ../base/main.cpp:265
    #10 0x562c7cb4454c in scummvm_main ../base/main.cpp:532
    #11 0x562c7cb3d7f6 in main ../backends/platform/sdl/posix/posix-main.cpp:45
    #12 0x7ff44271b06a in __libc_start_main (/usr/lib/libc.so.6+0x2306a)


// Apply the volume
setIntSetting(kVoice, getIntSetting(kVoice));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really needed?

void Engine::syncSoundSettings() {

Should already do the same.

setIntSetting(kMusic, getIntSetting(kMusic));
setIntSetting(kSfx, getIntSetting(kSfx));
}

void Settings::setIntSetting(IntSettingIndex index, int value) {
ConfMan.setInt(_intKey[index], value);

Audio::Mixer::SoundType type;
switch (index) {
case kVoice:
type = Audio::Mixer::kSpeechSoundType;
break;
case kMusic:
type = Audio::Mixer::kMusicSoundType;
break;
case kSfx:
type = Audio::Mixer::kSFXSoundType;
}

bool flag = ConfMan.getBool("mute");
_mixer->setVolumeForSoundType(type, flag ? 0 : value);
}

} // End of namespace Stark
86 changes: 86 additions & 0 deletions engines/stark/services/settings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/* ResidualVM - A 3D game interpreter
*
* ResidualVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the AUTHORS
* 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 STARK_SERVICES_SETTINGS_H
#define STARK_SERVICES_SETTINGS_H

#include "common/config-manager.h"

namespace Audio {
class Mixer;
}

namespace Stark {

/**
* Settings services.
*
* Maintains the settings of the game.
*/
class Settings {
public:
enum BoolSettingIndex {
kHighModel,
kSubtitle,
kSpecialFX,
kShadow,
kHighFMV,
kTimeSkip
};

enum IntSettingIndex {
kVoice,
kMusic,
kSfx
};

explicit Settings(Audio::Mixer *mixer);
~Settings() {}

/** Get the settings value */
bool getBoolSetting(BoolSettingIndex index) { return ConfMan.getBool(_boolKey[index]); }
int getIntSetting(IntSettingIndex index) { return ConfMan.getInt(_intKey[index]); }

/** Flip the boolean settings */
void flipSetting(BoolSettingIndex index) {
ConfMan.setBool(_boolKey[index], !getBoolSetting(index));
}

/** Set the integer settings */
void setIntSetting(IntSettingIndex index, int value);

/** Check whether low-resolution fmv is available */
bool hasLowResFMV() { return _hasLowRes; }

private:
const static int _maxVolume = 256;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not used.


Audio::Mixer *_mixer;
bool _hasLowRes;

const char *_boolKey[6];
const char *_intKey[3];
};

} // End of namespace Stark

#endif // STARK_SERVICES_SETTINGS_H
11 changes: 11 additions & 0 deletions engines/stark/services/staticprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,17 @@ VisualImageXMG *StaticProvider::getUIElement(UIElement element) const {
return getCursorImage(element);
}

VisualImageXMG *StaticProvider::getUIElement(UIElement element, uint32 index) const {
Resources::Anim *anim = _stockAnims[element];

uint32 prevIndex = anim->getCurrentFrame();
anim->selectFrame(index);
VisualImageXMG *visualImage = anim->getVisual()->get<VisualImageXMG>();
anim->selectFrame(prevIndex);

return visualImage;
}

VisualImageXMG *StaticProvider::getUIImage(UIImage image) const {
Resources::Image *anim = _stockImages[image];
return anim->getVisual()->get<VisualImageXMG>();
Expand Down
3 changes: 3 additions & 0 deletions engines/stark/services/staticprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ class StaticProvider {
kTextScrollUpArrow = 6,
kTextScrollDownArrow = 7,
kQuit = 8,
kCheckMark = 13,
kVolume = 14,
kDiaryNormal = 15,
kInventory = 16,
kTextBackgroundActive = 20,
Expand Down Expand Up @@ -91,6 +93,7 @@ class StaticProvider {

/** Get an image for a static UI element */
VisualImageXMG *getUIElement(UIElement element) const;
VisualImageXMG *getUIElement(UIElement element, uint32 index) const;

/** Get an image for a static UI element */
VisualImageXMG *getUIImage(UIImage image) const;
Expand Down
28 changes: 21 additions & 7 deletions engines/stark/services/userinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "engines/stark/ui/cursor.h"
#include "engines/stark/ui/menu/diaryindex.h"
#include "engines/stark/ui/menu/mainmenu.h"
#include "engines/stark/ui/menu/settingsmenu.h"
#include "engines/stark/ui/world/inventorywindow.h"
#include "engines/stark/ui/world/fmvscreen.h"
#include "engines/stark/ui/world/gamescreen.h"
Expand All @@ -49,6 +50,7 @@ UserInterface::UserInterface(Gfx::Driver *gfx) :
_cursor(nullptr),
_diaryIndexScreen(nullptr),
_mainMenuScreen(nullptr),
_settingsMenuScreen(nullptr),
_exitGame(false),
_fmvScreen(nullptr),
_gameScreen(nullptr),
Expand All @@ -67,6 +69,7 @@ UserInterface::~UserInterface() {
delete _diaryIndexScreen;
delete _cursor;
delete _mainMenuScreen;
delete _settingsMenuScreen;
}

void UserInterface::init() {
Expand All @@ -75,6 +78,7 @@ void UserInterface::init() {
_mainMenuScreen = new MainMenuScreen(_gfx, _cursor);
_gameScreen = new GameScreen(_gfx, _cursor);
_diaryIndexScreen = new DiaryIndexScreen(_gfx, _cursor);
_settingsMenuScreen = new SettingsMenuScreen(_gfx, _cursor);
_fmvScreen = new FMVScreen(_gfx, _cursor);

_prevScreenNameStack.push(Screen::kScreenMainMenu);
Expand All @@ -95,6 +99,11 @@ void UserInterface::handleMouseMove(const Common::Point &pos) {
_cursor->setMousePosition(pos);
}

void UserInterface::handleMouseUp() {
// Only the settings menu needs to handle this event
_settingsMenuScreen->handleMouseUp();
}

void UserInterface::handleClick() {
_currentScreen->handleClick();
}
Expand Down Expand Up @@ -143,13 +152,7 @@ void UserInterface::changeScreen(Screen::Name screenName) {
return;
}

if (screenName == Screen::kScreenMainMenu) {
// MainMenuScreen will not request to go back
_prevScreenNameStack.clear();
} else {
_prevScreenNameStack.push(_currentScreen->getName());
}

_prevScreenNameStack.push(_currentScreen->getName());
_currentScreen->close();
_currentScreen = getScreenByName(screenName);
_currentScreen->open();
Expand All @@ -159,12 +162,21 @@ void UserInterface::backPrevScreen() {
// No need to check the stack since at least there will be a MainMenuScreen in it
// and MainMenuScreen will not request to go back
changeScreen(_prevScreenNameStack.pop());

// No need to push for going back
_prevScreenNameStack.pop();
}

void UserInterface::quitToMainMenu() {
changeScreen(Screen::kScreenGame);
StarkResourceProvider->shutdown();
changeScreen(Screen::kScreenMainMenu);
_prevScreenNameStack.clear();
}

void UserInterface::restoreScreenHistory() {
_prevScreenNameStack.clear();
_prevScreenNameStack.push(Screen::kScreenMainMenu);
}

Screen *UserInterface::getScreenByName(Screen::Name screenName) const {
Expand All @@ -177,6 +189,8 @@ Screen *UserInterface::getScreenByName(Screen::Name screenName) const {
return _gameScreen;
case Screen::kScreenMainMenu:
return _mainMenuScreen;
case Screen::kScreenSettingsMenu:
return _settingsMenuScreen;
default:
error("Unhandled screen name '%d'", screenName);
}
Expand Down
Loading