Jeck - Profile loading fix, minor options menu improvements, minor cleanup.
This commit is contained in:
@@ -117,7 +117,8 @@ public:
|
|||||||
//The sanity=false option returns the adjusted path even if the file doesn't exist.
|
//The sanity=false option returns the adjusted path even if the file doesn't exist.
|
||||||
string profileFile(string filename="", string fallback="", bool sanity=true,bool relative=false);
|
string profileFile(string filename="", string fallback="", bool sanity=true,bool relative=false);
|
||||||
|
|
||||||
void checkProfile();
|
void reloadProfile(bool images = true); //Reloads profile using current options[ACTIVE_PROFILE]
|
||||||
|
void checkProfile(); //Confirms that a profile is loaded and contains a collection.
|
||||||
void createUsersFirstDeck(int setId);
|
void createUsersFirstDeck(int setId);
|
||||||
|
|
||||||
GameOption& operator[](string);
|
GameOption& operator[](string);
|
||||||
|
|||||||
@@ -47,10 +47,12 @@ public:
|
|||||||
|
|
||||||
class OptionInteger:public OptionItem{
|
class OptionInteger:public OptionItem{
|
||||||
public:
|
public:
|
||||||
int value;
|
int value; //Current value.
|
||||||
|
int defValue; //Default value.
|
||||||
|
string strDefault; //What to call the default value.
|
||||||
int maxValue, increment;
|
int maxValue, increment;
|
||||||
|
|
||||||
OptionInteger(string _id, string _displayValue, int _maxValue = 1, int _increment = 1);
|
OptionInteger(string _id, string _displayValue, int _maxValue = 1, int _increment = 1, int _defV = 0, string _sDef = "");
|
||||||
|
|
||||||
virtual void Reload() {if(id != "") value = options[id].number;};
|
virtual void Reload() {if(id != "") value = options[id].number;};
|
||||||
virtual void Render();
|
virtual void Render();
|
||||||
@@ -126,6 +128,14 @@ class OptionTheme:public OptionDirectory{
|
|||||||
OptionTheme();
|
OptionTheme();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class OptionVolume: public OptionInteger{
|
||||||
|
public:
|
||||||
|
OptionVolume(string _id, string _displayName, bool _bMusic = false);
|
||||||
|
virtual void updateValue();
|
||||||
|
private:
|
||||||
|
bool bMusic;
|
||||||
|
};
|
||||||
|
|
||||||
class OptionProfile:public OptionDirectory{
|
class OptionProfile:public OptionDirectory{
|
||||||
public:
|
public:
|
||||||
OptionProfile(GameApp * _app);
|
OptionProfile(GameApp * _app);
|
||||||
|
|||||||
@@ -43,6 +43,15 @@ GameApp::GameApp(): JApp()
|
|||||||
players[1] = 0;
|
players[1] = 0;
|
||||||
gameType = GAME_TYPE_CLASSIC;
|
gameType = GAME_TYPE_CLASSIC;
|
||||||
|
|
||||||
|
|
||||||
|
mCurrentState = NULL;
|
||||||
|
mNextState = NULL;
|
||||||
|
collection = NULL;
|
||||||
|
|
||||||
|
for(int i=0;i<6;i++)
|
||||||
|
Particles[i] = NULL;
|
||||||
|
|
||||||
|
music = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -64,6 +73,9 @@ void GameApp::Create()
|
|||||||
//Link this to our settings manager.
|
//Link this to our settings manager.
|
||||||
options.theGame = this;
|
options.theGame = this;
|
||||||
|
|
||||||
|
//Ensure that options are properly loaded before loading files.
|
||||||
|
options.reloadProfile();
|
||||||
|
|
||||||
//Test for Music files presence
|
//Test for Music files presence
|
||||||
string filepath = RESPATH;
|
string filepath = RESPATH;
|
||||||
filepath = filepath + "/" + resources.musicFile("Track0.mp3");
|
filepath = filepath + "/" + resources.musicFile("Track0.mp3");
|
||||||
@@ -200,7 +212,7 @@ void GameApp::Destroy()
|
|||||||
|
|
||||||
SimpleMenu::destroy();
|
SimpleMenu::destroy();
|
||||||
|
|
||||||
|
options.theGame = NULL;
|
||||||
LOG("==Destroying GameApp Successful==");
|
LOG("==Destroying GameApp Successful==");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -187,10 +187,10 @@ GameSettings::GameSettings()
|
|||||||
//Load global options
|
//Load global options
|
||||||
globalOptions = NEW GameOptions(GLOBAL_SETTINGS);
|
globalOptions = NEW GameOptions(GLOBAL_SETTINGS);
|
||||||
|
|
||||||
|
//reloadProfile should be called for the rest.
|
||||||
|
theGame = NULL;
|
||||||
profileOptions = NULL;
|
profileOptions = NULL;
|
||||||
themeOptions = NULL;
|
themeOptions = NULL;
|
||||||
|
|
||||||
checkProfile();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GameSettings::~GameSettings(){
|
GameSettings::~GameSettings(){
|
||||||
@@ -220,8 +220,17 @@ int GameSettings::save(){
|
|||||||
if(globalOptions)
|
if(globalOptions)
|
||||||
globalOptions->save();
|
globalOptions->save();
|
||||||
|
|
||||||
if(profileOptions)
|
if(profileOptions){
|
||||||
|
//Force our directories to exist.
|
||||||
|
MAKEDIR(RESPATH"/profiles");
|
||||||
|
string temp = profileFile("","",false,false);
|
||||||
|
MAKEDIR(temp.c_str());
|
||||||
|
temp+="/stats";
|
||||||
|
MAKEDIR(temp.c_str());
|
||||||
|
temp = profileFile(PLAYER_SETTINGS,"",false);
|
||||||
|
|
||||||
profileOptions->save();
|
profileOptions->save();
|
||||||
|
}
|
||||||
|
|
||||||
checkProfile();
|
checkProfile();
|
||||||
|
|
||||||
@@ -267,38 +276,30 @@ string GameSettings::profileFile(string filename, string fallback,bool sanity, b
|
|||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GameSettings::reloadProfile(bool images){
|
||||||
|
SAFE_DELETE(profileOptions);
|
||||||
|
SAFE_DELETE(themeOptions);
|
||||||
|
checkProfile();
|
||||||
|
if(images)
|
||||||
|
resources.Refresh(); //Update images
|
||||||
|
}
|
||||||
|
|
||||||
void GameSettings::checkProfile(){
|
void GameSettings::checkProfile(){
|
||||||
//Load current profile's options. Doesn't save prior set.
|
|
||||||
char buf[512];
|
char buf[512];
|
||||||
|
|
||||||
//Force our directories to exist.
|
//If it doesn't exist, load current profile.
|
||||||
MAKEDIR(RESPATH"/profiles");
|
if(!profileOptions)
|
||||||
string temp = profileFile("","",false,false);
|
profileOptions = NEW GameOptions(profileFile(PLAYER_SETTINGS,"",false));
|
||||||
MAKEDIR(temp.c_str());
|
|
||||||
temp+="/stats";
|
|
||||||
MAKEDIR(temp.c_str());
|
|
||||||
temp = profileFile(PLAYER_SETTINGS,"",false);
|
|
||||||
|
|
||||||
SAFE_DELETE(profileOptions);
|
|
||||||
profileOptions = NEW GameOptions(temp);
|
|
||||||
|
|
||||||
//Force a profile.
|
|
||||||
if((*profileOptions)[Options::ACTIVE_THEME].isDefault()){
|
|
||||||
temp = "Default";
|
|
||||||
(*profileOptions)[Options::ACTIVE_THEME].str = "Default";
|
|
||||||
}else{
|
|
||||||
temp = (*profileOptions)[Options::ACTIVE_THEME].str;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Load theme options
|
//Load theme options
|
||||||
if(temp == "Default")
|
if(!themeOptions){
|
||||||
sprintf(buf,RESPATH"/graphics/metrics.txt");
|
if(!profileOptions || (*profileOptions)[Options::ACTIVE_THEME].isDefault())
|
||||||
else{
|
sprintf(buf,RESPATH"/graphics/metrics.txt");
|
||||||
sprintf(buf,RESPATH"/themes/%s/metrics.txt",temp.c_str());
|
else
|
||||||
}
|
sprintf(buf,RESPATH"/themes/%s/metrics.txt",(*profileOptions)[Options::ACTIVE_THEME].str.c_str());
|
||||||
|
|
||||||
SAFE_DELETE(themeOptions);
|
themeOptions = NEW GameOptions(buf);
|
||||||
themeOptions = NEW GameOptions(buf);
|
}
|
||||||
|
|
||||||
//Validation of collection, etc, only happens if the game is up.
|
//Validation of collection, etc, only happens if the game is up.
|
||||||
if(theGame == NULL || theGame->collection == NULL)
|
if(theGame == NULL || theGame->collection == NULL)
|
||||||
@@ -309,7 +310,7 @@ void GameSettings::checkProfile(){
|
|||||||
{
|
{
|
||||||
//If we had any default settings, we'd set them here.
|
//If we had any default settings, we'd set them here.
|
||||||
|
|
||||||
//Give the player cards from the set for which we have the most variety
|
//Find the set for which we have the most variety
|
||||||
int setId = 0;
|
int setId = 0;
|
||||||
int maxcards = 0;
|
int maxcards = 0;
|
||||||
for (int i=0; i< MtgSets::SetsList->nb_items; i++){
|
for (int i=0; i< MtgSets::SetsList->nb_items; i++){
|
||||||
@@ -319,15 +320,17 @@ void GameSettings::checkProfile(){
|
|||||||
setId = i;
|
setId = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Save this set as "unlocked"
|
//Save this set as "unlocked"
|
||||||
char buffer[4096];
|
char buffer[4096];
|
||||||
string s = MtgSets::SetsList->values[setId];
|
string s = MtgSets::SetsList->values[setId];
|
||||||
sprintf(buffer,"unlocked_%s", s.c_str());
|
sprintf(buffer,"unlocked_%s", s.c_str());
|
||||||
(*profileOptions)[buffer]=1;
|
(*profileOptions)[buffer]=1;
|
||||||
profileOptions->save();
|
profileOptions->save();
|
||||||
|
|
||||||
|
//Give the player their first deck
|
||||||
createUsersFirstDeck(setId);
|
createUsersFirstDeck(setId);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameSettings::createUsersFirstDeck(int setId){
|
void GameSettings::createUsersFirstDeck(int setId){
|
||||||
|
|||||||
@@ -290,6 +290,7 @@ void GameStateMenu::Update(float dt)
|
|||||||
mReadConf = 1;
|
mReadConf = 1;
|
||||||
}
|
}
|
||||||
if (!nextDirectory(RESPATH"/sets/","_cards.dat")){
|
if (!nextDirectory(RESPATH"/sets/","_cards.dat")){
|
||||||
|
|
||||||
//Force default, if necessary.
|
//Force default, if necessary.
|
||||||
if(options[Options::ACTIVE_PROFILE].str == "")
|
if(options[Options::ACTIVE_PROFILE].str == "")
|
||||||
options[Options::ACTIVE_PROFILE].str = "Default";
|
options[Options::ACTIVE_PROFILE].str = "Default";
|
||||||
@@ -300,15 +301,8 @@ void GameStateMenu::Update(float dt)
|
|||||||
file.close();
|
file.close();
|
||||||
currentState = MENU_STATE_MAJOR_MAINMENU | MENU_STATE_MINOR_NONE;
|
currentState = MENU_STATE_MAJOR_MAINMENU | MENU_STATE_MINOR_NONE;
|
||||||
}else{
|
}else{
|
||||||
//check for first time player!
|
currentState = MENU_STATE_MAJOR_FIRST_TIME | MENU_STATE_MINOR_NONE;
|
||||||
file.open(options.profileFile(PLAYER_COLLECTION,"",false).c_str());
|
}
|
||||||
if(file){
|
|
||||||
file.close();
|
|
||||||
currentState = MENU_STATE_MAJOR_MAINMENU | MENU_STATE_MINOR_NONE;
|
|
||||||
}else{
|
|
||||||
currentState = MENU_STATE_MAJOR_FIRST_TIME | MENU_STATE_MINOR_NONE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//List active profile and database size.
|
//List active profile and database size.
|
||||||
PlayerData * playerdata = NEW PlayerData(mParent->collection);
|
PlayerData * playerdata = NEW PlayerData(mParent->collection);
|
||||||
@@ -321,8 +315,8 @@ void GameStateMenu::Update(float dt)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MENU_STATE_MAJOR_FIRST_TIME :
|
case MENU_STATE_MAJOR_FIRST_TIME :
|
||||||
options.checkProfile();
|
|
||||||
currentState = MENU_STATE_MAJOR_MAINMENU | MENU_STATE_MINOR_NONE;
|
currentState = MENU_STATE_MAJOR_MAINMENU | MENU_STATE_MINOR_NONE;
|
||||||
|
options.checkProfile(); //Handles building a new deck, if needed.
|
||||||
break;
|
break;
|
||||||
case MENU_STATE_MAJOR_MAINMENU :
|
case MENU_STATE_MAJOR_MAINMENU :
|
||||||
if (!scrollerSet) fillScroller();
|
if (!scrollerSet) fillScroller();
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ GameStateOptions::~GameStateOptions() {
|
|||||||
|
|
||||||
void GameStateOptions::Start()
|
void GameStateOptions::Start()
|
||||||
{
|
{
|
||||||
|
|
||||||
timer = 0;
|
timer = 0;
|
||||||
mState = SHOW_OPTIONS;
|
mState = SHOW_OPTIONS;
|
||||||
JRenderer::GetInstance()->ResetPrivateVRAM();
|
JRenderer::GetInstance()->ResetPrivateVRAM();
|
||||||
@@ -29,16 +28,17 @@ void GameStateOptions::Start()
|
|||||||
OptionsList * optionsList;
|
OptionsList * optionsList;
|
||||||
|
|
||||||
optionsList = NEW OptionsList("Settings");
|
optionsList = NEW OptionsList("Settings");
|
||||||
|
|
||||||
optionsList->Add(NEW OptionHeader("General Options"));
|
optionsList->Add(NEW OptionHeader("General Options"));
|
||||||
if (GameApp::HasMusic) optionsList->Add(NEW OptionInteger(Options::MUSICVOLUME, "Music volume", 100, 10));
|
if (GameApp::HasMusic) optionsList->Add(NEW OptionVolume(Options::MUSICVOLUME, "Music volume", true));
|
||||||
optionsList->Add(NEW OptionInteger(Options::SFXVOLUME, "SFX volume", 100, 10));
|
optionsList->Add(NEW OptionVolume(Options::SFXVOLUME, "SFX volume"));
|
||||||
optionsList->Add(NEW OptionInteger(Options::OSD, "Display InGame extra information"));
|
optionsList->Add(NEW OptionInteger(Options::OSD, "Display InGame extra information"));
|
||||||
if (options[Options::DIFFICULTY_MODE_UNLOCKED].number)
|
if (options[Options::DIFFICULTY_MODE_UNLOCKED].number)
|
||||||
optionsList->Add(NEW OptionInteger(Options::DIFFICULTY, "Difficulty", 3, 1));
|
optionsList->Add(NEW OptionInteger(Options::DIFFICULTY, "Difficulty", 3, 1));
|
||||||
optionsList->Add(NEW OptionInteger(Options::INTERRUPT_SECONDS, "Seconds to pause for an Interrupt", 20, 1));
|
optionsList->Add(NEW OptionInteger(Options::INTERRUPT_SECONDS, "Seconds to pause for an Interrupt", 20, 1));
|
||||||
optionsList->Add(NEW OptionInteger(Options::INTERRUPTMYSPELLS, "Interrupt my spells"));
|
optionsList->Add(NEW OptionInteger(Options::INTERRUPTMYSPELLS, "Interrupt my spells"));
|
||||||
optionsList->Add(NEW OptionInteger(Options::INTERRUPTMYABILITIES, "Interrupt my abilities"));
|
optionsList->Add(NEW OptionInteger(Options::INTERRUPTMYABILITIES, "Interrupt my abilities"));
|
||||||
optionsList->Add(NEW OptionInteger(Options::CACHESIZE, "Image Cache Size", 60, 5));
|
optionsList->Add(NEW OptionInteger(Options::CACHESIZE, "Image Cache Size", 60, 5,0,"Default"));
|
||||||
optionsTabs = NEW OptionsMenu();
|
optionsTabs = NEW OptionsMenu();
|
||||||
optionsTabs->Add(optionsList);
|
optionsTabs->Add(optionsList);
|
||||||
|
|
||||||
|
|||||||
@@ -64,13 +64,17 @@ void OptionInteger::Render(){
|
|||||||
sprintf(buf,_("No").c_str());
|
sprintf(buf,_("No").c_str());
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
sprintf(buf, "%i", value);
|
if(value == defValue && strDefault.size())
|
||||||
|
sprintf(buf, "%s", strDefault.c_str());
|
||||||
|
else
|
||||||
|
sprintf(buf, "%i", value);
|
||||||
}
|
}
|
||||||
mFont->DrawString(buf,width -10 ,y,JGETEXT_RIGHT);
|
mFont->DrawString(buf,width -10 ,y,JGETEXT_RIGHT);
|
||||||
}
|
}
|
||||||
|
|
||||||
OptionInteger::OptionInteger(string _id, string _displayValue, int _maxValue, int _increment): OptionItem(_id, _displayValue){
|
OptionInteger::OptionInteger(string _id, string _displayValue, int _maxValue, int _increment, int _defV, string _sDef): OptionItem(_id, _displayValue){
|
||||||
|
defValue = _defV;
|
||||||
|
strDefault = _sDef;
|
||||||
maxValue = _maxValue;
|
maxValue = _maxValue;
|
||||||
increment = _increment;
|
increment = _increment;
|
||||||
value = ::options[id].number;
|
value = ::options[id].number;
|
||||||
@@ -231,7 +235,7 @@ void OptionProfile::populate(){
|
|||||||
renderer->BindTexture(mAvatarTex);
|
renderer->BindTexture(mAvatarTex);
|
||||||
}
|
}
|
||||||
|
|
||||||
options.checkProfile();
|
options.reloadProfile();
|
||||||
PlayerData * pdata = NEW PlayerData(app->collection);
|
PlayerData * pdata = NEW PlayerData(app->collection);
|
||||||
|
|
||||||
options[Options::ACTIVE_PROFILE] = temp;
|
options[Options::ACTIVE_PROFILE] = temp;
|
||||||
@@ -320,7 +324,6 @@ void OptionProfile::acceptSubmode()
|
|||||||
options[Options::ACTIVE_PROFILE] = selections[value];
|
options[Options::ACTIVE_PROFILE] = selections[value];
|
||||||
initialValue = value;
|
initialValue = value;
|
||||||
populate();
|
populate();
|
||||||
resources.Refresh(); //Update images, in case we've changed profiles, etc.
|
|
||||||
bCheck = false;
|
bCheck = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -759,7 +762,7 @@ void OptionNewProfile::Update(float dt){
|
|||||||
|
|
||||||
if(temp != value){
|
if(temp != value){
|
||||||
options[Options::ACTIVE_PROFILE] = value;
|
options[Options::ACTIVE_PROFILE] = value;
|
||||||
options.checkProfile();
|
options.reloadProfile();
|
||||||
}
|
}
|
||||||
value = "";
|
value = "";
|
||||||
bChanged = true;
|
bChanged = true;
|
||||||
@@ -798,3 +801,13 @@ OptionTheme::OptionTheme(): OptionDirectory(RESPATH"/themes",Options::ACTIVE_THE
|
|||||||
if(selections.size() == 1)
|
if(selections.size() == 1)
|
||||||
bHidden = true;
|
bHidden = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OptionVolume::updateValue(){
|
||||||
|
value+=increment;
|
||||||
|
if (value>maxValue)
|
||||||
|
value=0;
|
||||||
|
}
|
||||||
|
|
||||||
|
OptionVolume::OptionVolume(string _id, string _displayName, bool _bMusic): OptionInteger(_id, _displayName, 100, 10,0,"Muted") {
|
||||||
|
bMusic = _bMusic;
|
||||||
|
}
|
||||||
@@ -935,10 +935,6 @@ int WResourceManager::CreateTexture(const string &textureName) {
|
|||||||
mTextureList.push_back(tex);
|
mTextureList.push_back(tex);
|
||||||
mTextureMap[textureName] = id;
|
mTextureMap[textureName] = id;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user