Erwan
- Updated options system
This commit is contained in:
@@ -733,7 +733,7 @@ class AManaProducer: public MTGAbility{
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (GameOptions::GetInstance()->values[OPTIONS_SFXVOLUME] > 0 && currentlyTapping < 3){
|
if (GameOptions::GetInstance()->values[OPTIONS_SFXVOLUME].getIntValue() > 0 && currentlyTapping < 3){
|
||||||
JSample * sample = SampleCache::GetInstance()->getSample("sound/sfx/mana.wav");
|
JSample * sample = SampleCache::GetInstance()->getSample("sound/sfx/mana.wav");
|
||||||
if (sample) JSoundSystem::GetInstance()->PlaySample(sample);
|
if (sample) JSoundSystem::GetInstance()->PlaySample(sample);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,25 +1,42 @@
|
|||||||
#ifndef _GAME_OPTIONS_H_
|
#ifndef _GAME_OPTIONS_H_
|
||||||
#define _GAME_OPTIONS_H_
|
#define _GAME_OPTIONS_H_
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
using std::map;
|
||||||
|
using std::string;
|
||||||
|
|
||||||
|
#define OPTIONS_MUSICVOLUME "musicVolume"
|
||||||
|
#define OPTIONS_SFXVOLUME "sfxVolume"
|
||||||
|
|
||||||
#define MAX_OPTIONS 50
|
|
||||||
#define OPTIONS_MUSICVOLUME 0
|
|
||||||
#define OPTIONS_SFXVOLUME 1
|
|
||||||
#define OPTIONS_INTERRUPTATENDOFPHASE_OFFSET 2
|
|
||||||
#define OPTIONS_SAVEFILE RESPATH"/settings/options.txt"
|
#define OPTIONS_SAVEFILE RESPATH"/settings/options.txt"
|
||||||
|
|
||||||
|
class GameOption {
|
||||||
|
public:
|
||||||
|
int value;
|
||||||
|
string svalue;
|
||||||
|
int getIntValue();
|
||||||
|
GameOption(int _value = 0);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
class GameOptions {
|
class GameOptions {
|
||||||
public:
|
public:
|
||||||
int values[MAX_OPTIONS];
|
map<string,GameOption> values;
|
||||||
static GameOptions * GetInstance();
|
static GameOptions * GetInstance();
|
||||||
static void Destroy();
|
static void Destroy();
|
||||||
int save();
|
int save();
|
||||||
int load();
|
int load();
|
||||||
|
static const char * phaseInterrupts[];
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GameOptions();
|
GameOptions();
|
||||||
~GameOptions();
|
~GameOptions();
|
||||||
static GameOptions* mInstance;
|
static GameOptions* mInstance;
|
||||||
|
|
||||||
|
static map <string,int> optionsTypes;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -200,7 +200,7 @@ class GameStateDeckViewer: public GameState, public JGuiListener
|
|||||||
}
|
}
|
||||||
welcome_menu->Add(10, "Cancel");
|
welcome_menu->Add(10, "Cancel");
|
||||||
|
|
||||||
if (GameApp::HasMusic && GameOptions::GetInstance()->values[OPTIONS_MUSICVOLUME] > 0){
|
if (GameApp::HasMusic && GameOptions::GetInstance()->values[OPTIONS_MUSICVOLUME].getIntValue() > 0){
|
||||||
if (GameApp::music){
|
if (GameApp::music){
|
||||||
JSoundSystem::GetInstance()->StopMusic(GameApp::music);
|
JSoundSystem::GetInstance()->StopMusic(GameApp::music);
|
||||||
SAFE_DELETE(GameApp::music);
|
SAFE_DELETE(GameApp::music);
|
||||||
|
|||||||
@@ -8,12 +8,12 @@ using std::string;
|
|||||||
|
|
||||||
class OptionItem:public JGuiObject{
|
class OptionItem:public JGuiObject{
|
||||||
public:
|
public:
|
||||||
string displayValue;
|
string displayValue, id;
|
||||||
int id, value;
|
int value;
|
||||||
int hasFocus;
|
int hasFocus;
|
||||||
int maxValue, increment;
|
int maxValue, increment;
|
||||||
float x, y;
|
float x, y;
|
||||||
OptionItem(int id, string _displayValue, int _maxValue = 1, int _increment = 1);
|
OptionItem(string _id, string _displayValue, int _maxValue = 1, int _increment = 1);
|
||||||
|
|
||||||
~OptionItem();
|
~OptionItem();
|
||||||
virtual void Render();
|
virtual void Render();
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ int Spell::resolve(){
|
|||||||
source->controller()->game->putInPlay(source);
|
source->controller()->game->putInPlay(source);
|
||||||
|
|
||||||
//Play SFX
|
//Play SFX
|
||||||
if (GameOptions::GetInstance()->values[OPTIONS_SFXVOLUME] > 0){
|
if (GameOptions::GetInstance()->values[OPTIONS_SFXVOLUME].getIntValue() > 0){
|
||||||
JSample * sample = source->getSample();
|
JSample * sample = source->getSample();
|
||||||
if (sample){
|
if (sample){
|
||||||
JSoundSystem::GetInstance()->PlaySample(sample);
|
JSoundSystem::GetInstance()->PlaySample(sample);
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ void GameObserver::userRequestNextGamePhase(){
|
|||||||
if (getCurrentTargetChooser()) return;
|
if (getCurrentTargetChooser()) return;
|
||||||
if (mLayers->combatLayer()->remainingDamageSteps) return;
|
if (mLayers->combatLayer()->remainingDamageSteps) return;
|
||||||
//TODO CHECK POSSIBILITY
|
//TODO CHECK POSSIBILITY
|
||||||
if (opponent()->isAI() || GameOptions::GetInstance()->values[OPTIONS_INTERRUPTATENDOFPHASE_OFFSET+currentGamePhase]){
|
if (opponent()->isAI() || GameOptions::GetInstance()->values[GameOptions::phaseInterrupts[currentGamePhase]].getIntValue()){
|
||||||
mLayers->stackLayer()->AddNextGamePhase();
|
mLayers->stackLayer()->AddNextGamePhase();
|
||||||
}else{
|
}else{
|
||||||
nextGamePhase();
|
nextGamePhase();
|
||||||
|
|||||||
@@ -4,6 +4,32 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <JGE.h>
|
||||||
|
|
||||||
|
const char* GameOptions::phaseInterrupts[] = {
|
||||||
|
"interrupt ---",
|
||||||
|
"interrupt Untap",
|
||||||
|
"interrupt Upkeep",
|
||||||
|
"interrupt Draw",
|
||||||
|
"interrupt Main phase 1",
|
||||||
|
"interrupt Combat begins",
|
||||||
|
"interrupt Attackers",
|
||||||
|
"interrupt Blockers",
|
||||||
|
"interrupt Combat damage",
|
||||||
|
"interrupt Combat ends",
|
||||||
|
"interrupt Main phase 2",
|
||||||
|
"interrupt End of turn",
|
||||||
|
"interrupt Cleanup",
|
||||||
|
"interrupt ---"
|
||||||
|
};
|
||||||
|
|
||||||
|
GameOption::GameOption(int _value){
|
||||||
|
value = _value;
|
||||||
|
}
|
||||||
|
|
||||||
|
int GameOption::getIntValue(){
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
GameOptions* GameOptions::mInstance = NULL;
|
GameOptions* GameOptions::mInstance = NULL;
|
||||||
|
|
||||||
@@ -14,9 +40,6 @@ GameOptions * GameOptions::GetInstance(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
GameOptions::GameOptions(){
|
GameOptions::GameOptions(){
|
||||||
for(int i = 0; i < MAX_OPTIONS; i++){
|
|
||||||
values[i] = 0;
|
|
||||||
}
|
|
||||||
load();
|
load();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -24,12 +47,10 @@ int GameOptions::load(){
|
|||||||
std::ifstream file(OPTIONS_SAVEFILE);
|
std::ifstream file(OPTIONS_SAVEFILE);
|
||||||
std::string s;
|
std::string s;
|
||||||
if(file){
|
if(file){
|
||||||
for (int i = 0; i < MAX_OPTIONS; i++){
|
while(std::getline(file,s)){
|
||||||
if(std::getline(file,s)){
|
int found =s.find("=");
|
||||||
values[i] = atoi(s.c_str());
|
string name = s.substr(0,found);
|
||||||
}else{
|
values[name] = GameOption(atoi(s.substr(found+1).c_str()));
|
||||||
//TODO error management
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
@@ -38,10 +59,11 @@ int GameOptions::load(){
|
|||||||
|
|
||||||
int GameOptions::save(){
|
int GameOptions::save(){
|
||||||
std::ofstream file(OPTIONS_SAVEFILE);
|
std::ofstream file(OPTIONS_SAVEFILE);
|
||||||
char writer[10];
|
char writer[1024];
|
||||||
if (file){
|
if (file){
|
||||||
for (int i = 0; i < MAX_OPTIONS; i++){
|
map<string, GameOption>::iterator it;
|
||||||
sprintf(writer,"%i\n", values[i]);
|
for ( it=values.begin() ; it != values.end(); it++ ){
|
||||||
|
sprintf(writer,"%s=%d\n", it->first.c_str(), it->second.getIntValue());
|
||||||
file<<writer;
|
file<<writer;
|
||||||
}
|
}
|
||||||
file.close();
|
file.close();
|
||||||
|
|||||||
@@ -133,12 +133,12 @@ void GameStateMenu::Start(){
|
|||||||
JRenderer::GetInstance()->EnableVSync(true);
|
JRenderer::GetInstance()->EnableVSync(true);
|
||||||
subMenuController = NULL;
|
subMenuController = NULL;
|
||||||
|
|
||||||
if (GameApp::HasMusic && !GameApp::music && GameOptions::GetInstance()->values[OPTIONS_MUSICVOLUME] > 0){
|
if (GameApp::HasMusic && !GameApp::music && GameOptions::GetInstance()->values[OPTIONS_MUSICVOLUME].getIntValue() > 0){
|
||||||
GameApp::music = JSoundSystem::GetInstance()->LoadMusic("sound/Track0.mp3");
|
GameApp::music = JSoundSystem::GetInstance()->LoadMusic("sound/Track0.mp3");
|
||||||
JSoundSystem::GetInstance()->PlayMusic(GameApp::music, true);
|
JSoundSystem::GetInstance()->PlayMusic(GameApp::music, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GameApp::HasMusic && GameApp::music && GameOptions::GetInstance()->values[OPTIONS_MUSICVOLUME] == 0){
|
if (GameApp::HasMusic && GameApp::music && GameOptions::GetInstance()->values[OPTIONS_MUSICVOLUME].getIntValue() == 0){
|
||||||
JSoundSystem::GetInstance()->StopMusic(GameApp::music);
|
JSoundSystem::GetInstance()->StopMusic(GameApp::music);
|
||||||
SAFE_DELETE(GameApp::music);
|
SAFE_DELETE(GameApp::music);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,9 +67,9 @@ void GameStateOptions::Render()
|
|||||||
|
|
||||||
const char * const CreditsText[] = {
|
const char * const CreditsText[] = {
|
||||||
"Wagic, The Homebrew ?! by WilLoW",
|
"Wagic, The Homebrew ?! by WilLoW",
|
||||||
"This is a work in progress and it contains bugs, deal with it",
|
"This is a work in progress and it contains bugs",
|
||||||
"updates on http://www.wololo.net/wagic",
|
"updates on http://www.wololo.net/wagic",
|
||||||
"Many thanks to Abrasax and J for their help in this release",
|
"Many thanks to J for his help in this release, and to all card creators",
|
||||||
"",
|
"",
|
||||||
"Developped with the JGE++ Library (http://jge.khors.com)",
|
"Developped with the JGE++ Library (http://jge.khors.com)",
|
||||||
"",
|
"",
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ void MTGPlayerCards::putInGraveyard(MTGCardInstance * card){
|
|||||||
void MTGPlayerCards::putInZone(MTGCardInstance * card, MTGGameZone * from, MTGGameZone * to){
|
void MTGPlayerCards::putInZone(MTGCardInstance * card, MTGGameZone * from, MTGGameZone * to){
|
||||||
if (from->removeCard(card)){
|
if (from->removeCard(card)){
|
||||||
|
|
||||||
if (GameOptions::GetInstance()->values[OPTIONS_SFXVOLUME] > 0){
|
if (GameOptions::GetInstance()->values[OPTIONS_SFXVOLUME].getIntValue() > 0){
|
||||||
if (to == graveyard){
|
if (to == graveyard){
|
||||||
if (card->isACreature()){
|
if (card->isACreature()){
|
||||||
JSample * sample = SampleCache::GetInstance()->getSample("sound/sfx/graveyard.wav");
|
JSample * sample = SampleCache::GetInstance()->getSample("sound/sfx/graveyard.wav");
|
||||||
|
|||||||
@@ -4,12 +4,12 @@
|
|||||||
#include "../include/GameOptions.h"
|
#include "../include/GameOptions.h"
|
||||||
|
|
||||||
|
|
||||||
OptionItem::OptionItem(int _id, string _displayValue, int _maxValue, int _increment):JGuiObject(0){
|
OptionItem::OptionItem(string _id, string _displayValue, int _maxValue, int _increment):JGuiObject(0){
|
||||||
id = _id;
|
id = _id;
|
||||||
maxValue = _maxValue;
|
maxValue = _maxValue;
|
||||||
increment = _increment;
|
increment = _increment;
|
||||||
displayValue = _displayValue;
|
displayValue = _displayValue;
|
||||||
value = GameOptions::GetInstance()->values[id];
|
value = GameOptions::GetInstance()->values[id].getIntValue();
|
||||||
hasFocus = 0;
|
hasFocus = 0;
|
||||||
x = 0;
|
x = 0;
|
||||||
y = 0;
|
y = 0;
|
||||||
@@ -20,7 +20,10 @@ OptionItem::~OptionItem(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void OptionItem::setData(){
|
void OptionItem::setData(){
|
||||||
GameOptions::GetInstance()->values[id] = value;
|
GameOptions::GetInstance()->values[id] = GameOption(value);
|
||||||
|
char buf[4096];
|
||||||
|
sprintf(buf, "Option: %s => %i\n", id.c_str(), GameOptions::GetInstance()->values[id].getIntValue());
|
||||||
|
OutputDebugString(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OptionItem::Render(){
|
void OptionItem::Render(){
|
||||||
|
|||||||
Reference in New Issue
Block a user