diff options
author | Eugenio Favalli <elvenprogrammer@gmail.com> | 2005-04-16 14:18:33 +0000 |
---|---|---|
committer | Eugenio Favalli <elvenprogrammer@gmail.com> | 2005-04-16 14:18:33 +0000 |
commit | f34960bc4a774764062a7bff70596779006c9413 (patch) | |
tree | eff906ad2f016a47689e3d19902057c13e00d7e5 /src | |
parent | 62de779017018a6e8f89fed9e0c930fc4904f5d2 (diff) | |
download | mana-f34960bc4a774764062a7bff70596779006c9413.tar.gz mana-f34960bc4a774764062a7bff70596779006c9413.tar.bz2 mana-f34960bc4a774764062a7bff70596779006c9413.tar.xz mana-f34960bc4a774764062a7bff70596779006c9413.zip |
- Readding stripping to executable (Dev-cpp project options)
- New slider skin
- Some updates to win32 compile guide
- Cleaned sound engine
- Improved setup window (need testing)
Diffstat (limited to 'src')
-rw-r--r-- | src/game.cpp | 3 | ||||
-rw-r--r-- | src/gui/setup.cpp | 191 | ||||
-rw-r--r-- | src/gui/setup.h | 31 | ||||
-rw-r--r-- | src/main.cpp | 5 | ||||
-rw-r--r-- | src/sound.cpp | 45 | ||||
-rw-r--r-- | src/sound.h | 26 |
6 files changed, 114 insertions, 187 deletions
diff --git a/src/game.cpp b/src/game.cpp index 3ddd72a9..1aa0f9bc 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -224,8 +224,7 @@ void do_input() } else if ((keysym.sym == SDLK_F7)) { - SOUND_ID id = sound.loadSfx("data/sfx/fist-swish.ogg"); - sound.playSfx(id); + sound.playSfx("sfx/fist-swish.ogg"); } // Emotions, Skill dialog diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index 6d4dade4..87d4ef42 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -21,11 +21,6 @@ * $Id$ */ -/* - * This module takes care of everything relating to the - * setup dialog. - */ - #include "setup.h" #include "button.h" #include "checkbox.h" @@ -35,159 +30,172 @@ #include "slider.h" #include "ok_dialog.h" #include "../main.h" -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <memory.h> +#include <sstream> -/* -SDL_Rect **modes; +#define SETUP_WIDTH 240 ModeListModel::ModeListModel() { - int i; - - modes = SDL_ListModes(NULL, SDL_FULLSCREEN | SDL_HWSURFACE); - - // Check if any modes available - if (modes == (SDL_Rect**)0) { - nmode = 0; - logger.log("No modes"); + SDL_Rect **modes; + + /* Get available fullscreen/hardware modes */ + modes = SDL_ListModes(NULL, SDL_FULLSCREEN|SDL_HWSURFACE); + + /* Check is there are any modes available */ + if(modes == (SDL_Rect **)0) { + logger.log("No modes available"); } - - // Check if modes restricted - if (modes == (SDL_Rect**)-1) { - logger.log("Modes unrestricted"); + + /* Check if our resolution is restricted */ + if(modes == (SDL_Rect **)-1) { + logger.log("All resolutions available"); } - - for (nmode = 0; modes[nmode]; ++nmode); - - mode = (char**)calloc(nmode, sizeof(char*)); - - for (i = 0; modes[i]; ++i) { - char *temp = (char*)malloc(20 * sizeof(char)); - mode[i] = temp; - if (sprintf(mode[i], "%d x %d", modes[i]->w, modes[i]->h) == -1) { - logger.log("Cannot allocate mode list"); + else{ + /* Print valid modes */ + logger.log("Available Modes"); + for (int i = 0; modes[i]; ++i) { + logger.log(" %dx%d", modes[i]->w, modes[i]->h); + std::stringstream mode; + mode << (int)modes[i]->w << "x" << (int)modes[i]->h; + videoModes.push_back(mode.str()); } } } ModeListModel::~ModeListModel() { - int i; - - // Cleanup - for (i = 0; i < nmode; i++) { - free(mode[i]); - } - - free(mode); + //delete videoModes; } int ModeListModel::getNumberOfElements() { - return nmode; + return videoModes.size(); } std::string ModeListModel::getElementAt(int i) { - return mode[i]; + return videoModes[i]; } -*/ + Setup::Setup(): Window("Setup") { - //modeListModel = new ModeListModel(); - //displayLabel = new gcn::Label("Display settings"); - //modeList = new ListBox(modeListModel); - //scrollArea = new ScrollArea(modeList); + videoLabel = new gcn::Label("Video settings"); + modeListModel = new ModeListModel(); + modeList = new ListBox(modeListModel); + modeList->setEnabled(false); + scrollArea = new ScrollArea(modeList); fsCheckBox = new CheckBox("Full screen", false); - soundLabel = new gcn::Label("Sound settings"); + openGlCheckBox = new CheckBox("OpenGL", false); + openGlCheckBox->setEnabled(false); + alphaLabel = new gcn::Label("Gui opacity:"); + alphaSlider = new Slider(0.2, 1.0); + audioLabel = new gcn::Label("Audio settings"); soundCheckBox = new CheckBox("Sound", false); - disabledRadio = new RadioButton("Disabled", "Modes", false); + sfxSlider = new Slider(0, 128); + musicSlider = new Slider(0, 128); + sfxLabel = new gcn::Label("Sfx volume"); + musicLabel = new gcn::Label("Music volume"); applyButton = new Button("Apply"); cancelButton = new Button("Cancel"); - alphaLabel = new gcn::Label("GUI opacity:"); - alphaSlider = new Slider(0.2, 1.0); - - // Set selections - last_sel = 0; - sel = 1; // Set events applyButton->setEventId("apply"); cancelButton->setEventId("cancel"); alphaSlider->setEventId("guialpha"); + sfxSlider->setEventId("sfx"); + musicSlider->setEventId("music"); // Set dimensions/positions - setContentSize(240, 216); - /* - scrollArea->setDimension(gcn::Rectangle(10, 40, 90, 50)); + setContentSize(SETUP_WIDTH, 216); + videoLabel->setPosition(SETUP_WIDTH - videoLabel->getWidth() - 5, 10); + scrollArea->setDimension(gcn::Rectangle(10, 30, 90, 50)); modeList->setDimension(gcn::Rectangle(0, 0, 60, 50)); - displayLabel->setDimension(gcn::Rectangle(10, 10, 100,16)); - */ + fsCheckBox->setPosition(110, 30); + openGlCheckBox->setPosition(110, 50); + alphaSlider->setDimension(gcn::Rectangle(10, 90, 100, 10)); + alphaLabel->setPosition(20 + alphaSlider->getWidth(), 87); + audioLabel->setPosition(SETUP_WIDTH - videoLabel->getWidth() - 5, 110); + soundCheckBox->setPosition(10, 130); + sfxSlider->setDimension(gcn::Rectangle(10, 150, 100, 10)); + musicSlider->setDimension(gcn::Rectangle(10, 170, 100, 10)); + sfxLabel->setPosition(20 + sfxSlider->getWidth(), 147); + musicLabel->setPosition(20 + musicSlider->getWidth(), 167); cancelButton->setPosition( - 240 - 5 - cancelButton->getWidth(), + SETUP_WIDTH - 5 - cancelButton->getWidth(), 216 - 5 - cancelButton->getHeight()); applyButton->setPosition( cancelButton->getX() - 5 - applyButton->getWidth(), 216 - 5 - applyButton->getHeight()); - soundLabel->setPosition(10, 110); - fsCheckBox->setPosition(120, 36); - soundCheckBox->setPosition(10, 130); - disabledRadio->setPosition(10, 140); - alphaLabel->setPosition(10, 157); - alphaSlider->setDimension(gcn::Rectangle( - alphaLabel->getWidth() + 20, 160, 100, 10)); - + // Listen for actions applyButton->addActionListener(this); cancelButton->addActionListener(this); alphaSlider->addActionListener(this); - + sfxSlider->addActionListener(this); + musicSlider->addActionListener(this); + // Assemble dialog - //add(scrollArea); - //add(displayLabel); + add(videoLabel); + add(scrollArea); add(fsCheckBox); - add(soundLabel); + add(openGlCheckBox); + add(audioLabel); add(soundCheckBox); - //add(disabledRadio); add(applyButton); add(cancelButton); - add(alphaLabel); add(alphaSlider); + add(alphaLabel); + add(sfxSlider); + add(musicSlider); + add(sfxLabel); + add(musicLabel); setLocationRelativeTo(getParent()); - // load default settings - //modeList->setSelected(1); + // Load default settings + modeList->setSelected(-1); if (config.getValue("screen", 0) == 1) { fsCheckBox->setMarked(true); } soundCheckBox->setMarked(config.getValue("sound", 0)); alphaSlider->setValue(config.getValue("guialpha", 0.8)); + sfxSlider->setValue(config.getValue("sfxVolume", 100)); + musicSlider->setValue(config.getValue("musicVolume", 60)); } Setup::~Setup() { - //delete modeListModel; - //delete modeList; - //delete scrollArea; + delete modeListModel; + delete modeList; + delete scrollArea; delete fsCheckBox; delete soundCheckBox; - delete soundLabel; - //delete displayLabel; + delete audioLabel; delete applyButton; delete cancelButton; - delete alphaLabel; delete alphaSlider; + delete alphaLabel; + delete sfxSlider; + delete musicSlider; + delete sfxLabel; + delete musicLabel; } void Setup::action(const std::string &eventId) { - if (eventId == "guialpha") + if (eventId == "sfx") + { + config.setValue("sfxVolume", (int)sfxSlider->getValue()); + sound.setSfxVolume(sfxSlider->getValue()); + } + else if (eventId == "music") + { + config.setValue("musicVolume", (int)musicSlider->getValue()); + sound.setMusicVolume(musicSlider->getValue()); + } + else if (eventId == "guialpha") { config.setValue("guialpha", alphaSlider->getValue()); } @@ -195,9 +203,6 @@ void Setup::action(const std::string &eventId) { setVisible(false); - /*screenW = modes[sel]->w; - screenH = modes[sel]->h;*/ - if (fsCheckBox->isMarked()) { // Fullscreen config.setValue("screen", 1); displayFlags |= SDL_FULLSCREEN; @@ -216,16 +221,6 @@ void Setup::action(const std::string &eventId) exit(1); } -/* if (displayFlags & SDL_FULLSCREEN) { -#ifdef WIN32 - displayFlags ^= SDL_FULLSCREEN; - screen = SDL_SetVideoMode(screenW, screenH, bitDepth, displayFlags); -#else - SDL_WM_ToggleFullScreen(screen); -#endif - }*/ - - // Sound settings if (soundCheckBox->isMarked()) { config.setValue("sound", 1); diff --git a/src/gui/setup.h b/src/gui/setup.h index 0fe3df1b..21f65038 100644 --- a/src/gui/setup.h +++ b/src/gui/setup.h @@ -21,8 +21,8 @@ * $Id$ */ -#ifndef tmw_included_setup_h -#define tmw_included_setup_h +#ifndef _TMW_SETUP_H +#define _TMW_SETUP_H #include "window.h" #include "../sound.h" @@ -55,8 +55,7 @@ class ModeListModel : public gcn::ListModel { std::string getElementAt(int i); private: - int nmode; - char **mode; + std::vector<std::string> videoModes; }; /** @@ -66,22 +65,20 @@ class ModeListModel : public gcn::ListModel { */ class Setup : public Window, public gcn::ActionListener { private: - // Dialog parts - //ModeListModel *modeListModel; - //gcn::Label *displayLabel; + // Dialog widgets + gcn::Label *videoLabel, *audioLabel; + gcn::ListBox *modeList; + ModeListModel *modeListModel; + gcn::ScrollArea *scrollArea; gcn::CheckBox *fsCheckBox; - gcn::Label *soundLabel; + gcn::CheckBox *openGlCheckBox; + gcn::Slider *alphaSlider; + gcn::Label *alphaLabel; gcn::CheckBox *soundCheckBox; - gcn::RadioButton *disabledRadio; - //gcn::ScrollArea *scrollArea; - //gcn::ListBox *modeList; + gcn::Slider *sfxSlider, *musicSlider; + gcn::Label *sfxLabel, *musicLabel; gcn::Button *applyButton; gcn::Button *cancelButton; - gcn::Label *alphaLabel; - gcn::Slider *alphaSlider; - - // Video selections - int last_sel, sel; public: @@ -93,7 +90,7 @@ class Setup : public Window, public gcn::ActionListener { /** * Destructor. */ - ~Setup(); + ~Setup(); /** * Event handling method. diff --git a/src/main.cpp b/src/main.cpp index 9becaaf7..da90e701 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -182,6 +182,8 @@ void init_engine() config.setValue("chatlog", "chatlog.txt"); #endif config.setValue("remember", 1); + config.setValue("sfxVolume", 100); + config.setValue("musicVolume", 60); config.write(dir); } @@ -294,7 +296,8 @@ void init_engine() if (config.getValue("sound", 0) == 1) { sound.init(); } - //sound.setVolume(64); + sound.setSfxVolume(config.getValue("sfxVolume", 100)); + sound.setMusicVolume(config.getValue("musicVolume", 60)); } catch (const char *err) { state = ERROR; diff --git a/src/sound.cpp b/src/sound.cpp index f76b6910..9b16a063 100644 --- a/src/sound.cpp +++ b/src/sound.cpp @@ -27,7 +27,8 @@ Sound::Sound(): installed(false), - items(-1) + sfxVolume(100), + musicVolume(60) { } @@ -187,35 +188,6 @@ void Sound::fadeOutMusic(int ms) } } -SOUND_ID Sound::loadSfx(const char *path) -{ - /* If sound system is not installed it can't load - * samples because doesn't know how to convert them */ - if (!installed) return 0; - - logger.log("Sound::loadSfx() pre-caching \"%s\"", path); - - ResourceManager *resman = ResourceManager::getInstance(); - SoundEffect *sample = resman->getSoundEffect(path); - if (sample) { - soundPool[++items] = sample; - logger.log("Sound::loadSfx() SOUND_ID = %d", items); - return items; - } - - return 0; -} - -void Sound::playSfx(SOUND_ID id) -{ - if (!installed) return; - - if (soundPool[id]) { - logger.log("Sound::playSfx() Playing SOUND_ID = %d", id); - soundPool[id]->play(0, sfxVolume); - } -} - void Sound::playSfx(const char *path) { if (!installed) return; @@ -228,22 +200,9 @@ void Sound::playSfx(const char *path) } } -void Sound::clearCache() -{ - for (SOUND_ID i = 0; i <= items; i++) { - soundPool[i]->unload(); - delete soundPool[i]; - soundPool[i] = NULL; - } - - soundPool.clear(); - logger.log("Sound::clearCache() Wiped all items off the cache"); -} - void Sound::close() { installed = false; - clearCache(); Mix_CloseAudio(); logger.log("Sound::close() Shutting down sound..."); } diff --git a/src/sound.h b/src/sound.h index 96cb8baf..27748fb6 100644 --- a/src/sound.h +++ b/src/sound.h @@ -27,12 +27,9 @@ #include <guichan.hpp> #include <SDL.h> #include <SDL_mixer.h> -#include <map> #include "resources/resourcemanager.h" -typedef short SOUND_ID; - /** Sound engine * * \ingroup CORE @@ -108,41 +105,18 @@ class Sound { void setSfxVolume(int volume); /** - * Preloads a sound-item into buffer. - * - * \param path Full path to file - */ - SOUND_ID loadSfx(const char *path); - - /** - * Plays an item in soundpool. - * - * \param id Id returned to the item in the soundpool - */ - void playSfx(SOUND_ID id); - - /** * Plays an item. * * \param path Full path to file */ void playSfx(const char *path); - /** - * Wipe all items off the cache - */ - void clearCache(); - private: bool installed; int musicVolume, sfxVolume; Mix_Music *music; - - /** list of preloaded sound data / items */ - std::map<int, SoundEffect*> soundPool; - SOUND_ID items; }; #endif |