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.
|
||||
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);
|
||||
|
||||
GameOption& operator[](string);
|
||||
|
||||
@@ -47,10 +47,12 @@ public:
|
||||
|
||||
class OptionInteger:public OptionItem{
|
||||
public:
|
||||
int value;
|
||||
int value; //Current value.
|
||||
int defValue; //Default value.
|
||||
string strDefault; //What to call the default value.
|
||||
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 Render();
|
||||
@@ -126,6 +128,14 @@ class OptionTheme:public OptionDirectory{
|
||||
OptionTheme();
|
||||
};
|
||||
|
||||
class OptionVolume: public OptionInteger{
|
||||
public:
|
||||
OptionVolume(string _id, string _displayName, bool _bMusic = false);
|
||||
virtual void updateValue();
|
||||
private:
|
||||
bool bMusic;
|
||||
};
|
||||
|
||||
class OptionProfile:public OptionDirectory{
|
||||
public:
|
||||
OptionProfile(GameApp * _app);
|
||||
|
||||
@@ -43,6 +43,15 @@ GameApp::GameApp(): JApp()
|
||||
players[1] = 0;
|
||||
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.
|
||||
options.theGame = this;
|
||||
|
||||
//Ensure that options are properly loaded before loading files.
|
||||
options.reloadProfile();
|
||||
|
||||
//Test for Music files presence
|
||||
string filepath = RESPATH;
|
||||
filepath = filepath + "/" + resources.musicFile("Track0.mp3");
|
||||
@@ -200,7 +212,7 @@ void GameApp::Destroy()
|
||||
|
||||
SimpleMenu::destroy();
|
||||
|
||||
|
||||
options.theGame = NULL;
|
||||
LOG("==Destroying GameApp Successful==");
|
||||
|
||||
}
|
||||
|
||||
@@ -187,10 +187,10 @@ GameSettings::GameSettings()
|
||||
//Load global options
|
||||
globalOptions = NEW GameOptions(GLOBAL_SETTINGS);
|
||||
|
||||
//reloadProfile should be called for the rest.
|
||||
theGame = NULL;
|
||||
profileOptions = NULL;
|
||||
themeOptions = NULL;
|
||||
|
||||
checkProfile();
|
||||
}
|
||||
|
||||
GameSettings::~GameSettings(){
|
||||
@@ -220,8 +220,17 @@ int GameSettings::save(){
|
||||
if(globalOptions)
|
||||
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();
|
||||
}
|
||||
|
||||
checkProfile();
|
||||
|
||||
@@ -267,38 +276,30 @@ string GameSettings::profileFile(string filename, string fallback,bool sanity, b
|
||||
return buf;
|
||||
}
|
||||
|
||||
void GameSettings::reloadProfile(bool images){
|
||||
SAFE_DELETE(profileOptions);
|
||||
SAFE_DELETE(themeOptions);
|
||||
checkProfile();
|
||||
if(images)
|
||||
resources.Refresh(); //Update images
|
||||
}
|
||||
|
||||
void GameSettings::checkProfile(){
|
||||
//Load current profile's options. Doesn't save prior set.
|
||||
char buf[512];
|
||||
|
||||
//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);
|
||||
|
||||
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;
|
||||
}
|
||||
//If it doesn't exist, load current profile.
|
||||
if(!profileOptions)
|
||||
profileOptions = NEW GameOptions(profileFile(PLAYER_SETTINGS,"",false));
|
||||
|
||||
//Load theme options
|
||||
if(temp == "Default")
|
||||
sprintf(buf,RESPATH"/graphics/metrics.txt");
|
||||
else{
|
||||
sprintf(buf,RESPATH"/themes/%s/metrics.txt",temp.c_str());
|
||||
}
|
||||
if(!themeOptions){
|
||||
if(!profileOptions || (*profileOptions)[Options::ACTIVE_THEME].isDefault())
|
||||
sprintf(buf,RESPATH"/graphics/metrics.txt");
|
||||
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.
|
||||
if(theGame == NULL || theGame->collection == NULL)
|
||||
@@ -309,7 +310,7 @@ void GameSettings::checkProfile(){
|
||||
{
|
||||
//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 maxcards = 0;
|
||||
for (int i=0; i< MtgSets::SetsList->nb_items; i++){
|
||||
@@ -319,15 +320,17 @@ void GameSettings::checkProfile(){
|
||||
setId = i;
|
||||
}
|
||||
}
|
||||
|
||||
//Save this set as "unlocked"
|
||||
char buffer[4096];
|
||||
string s = MtgSets::SetsList->values[setId];
|
||||
sprintf(buffer,"unlocked_%s", s.c_str());
|
||||
(*profileOptions)[buffer]=1;
|
||||
profileOptions->save();
|
||||
|
||||
//Give the player their first deck
|
||||
createUsersFirstDeck(setId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void GameSettings::createUsersFirstDeck(int setId){
|
||||
|
||||
@@ -290,6 +290,7 @@ void GameStateMenu::Update(float dt)
|
||||
mReadConf = 1;
|
||||
}
|
||||
if (!nextDirectory(RESPATH"/sets/","_cards.dat")){
|
||||
|
||||
//Force default, if necessary.
|
||||
if(options[Options::ACTIVE_PROFILE].str == "")
|
||||
options[Options::ACTIVE_PROFILE].str = "Default";
|
||||
@@ -300,15 +301,8 @@ void GameStateMenu::Update(float dt)
|
||||
file.close();
|
||||
currentState = MENU_STATE_MAJOR_MAINMENU | MENU_STATE_MINOR_NONE;
|
||||
}else{
|
||||
//check for first time player!
|
||||
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;
|
||||
}
|
||||
}
|
||||
currentState = MENU_STATE_MAJOR_FIRST_TIME | MENU_STATE_MINOR_NONE;
|
||||
}
|
||||
|
||||
//List active profile and database size.
|
||||
PlayerData * playerdata = NEW PlayerData(mParent->collection);
|
||||
@@ -321,8 +315,8 @@ void GameStateMenu::Update(float dt)
|
||||
}
|
||||
break;
|
||||
case MENU_STATE_MAJOR_FIRST_TIME :
|
||||
options.checkProfile();
|
||||
currentState = MENU_STATE_MAJOR_MAINMENU | MENU_STATE_MINOR_NONE;
|
||||
options.checkProfile(); //Handles building a new deck, if needed.
|
||||
break;
|
||||
case MENU_STATE_MAJOR_MAINMENU :
|
||||
if (!scrollerSet) fillScroller();
|
||||
|
||||
@@ -20,7 +20,6 @@ GameStateOptions::~GameStateOptions() {
|
||||
|
||||
void GameStateOptions::Start()
|
||||
{
|
||||
|
||||
timer = 0;
|
||||
mState = SHOW_OPTIONS;
|
||||
JRenderer::GetInstance()->ResetPrivateVRAM();
|
||||
@@ -29,16 +28,17 @@ void GameStateOptions::Start()
|
||||
OptionsList * optionsList;
|
||||
|
||||
optionsList = NEW OptionsList("Settings");
|
||||
|
||||
optionsList->Add(NEW OptionHeader("General Options"));
|
||||
if (GameApp::HasMusic) optionsList->Add(NEW OptionInteger(Options::MUSICVOLUME, "Music volume", 100, 10));
|
||||
optionsList->Add(NEW OptionInteger(Options::SFXVOLUME, "SFX volume", 100, 10));
|
||||
if (GameApp::HasMusic) optionsList->Add(NEW OptionVolume(Options::MUSICVOLUME, "Music volume", true));
|
||||
optionsList->Add(NEW OptionVolume(Options::SFXVOLUME, "SFX volume"));
|
||||
optionsList->Add(NEW OptionInteger(Options::OSD, "Display InGame extra information"));
|
||||
if (options[Options::DIFFICULTY_MODE_UNLOCKED].number)
|
||||
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::INTERRUPTMYSPELLS, "Interrupt my spells"));
|
||||
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->Add(optionsList);
|
||||
|
||||
|
||||
@@ -64,13 +64,17 @@ void OptionInteger::Render(){
|
||||
sprintf(buf,_("No").c_str());
|
||||
}
|
||||
}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);
|
||||
}
|
||||
|
||||
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;
|
||||
increment = _increment;
|
||||
value = ::options[id].number;
|
||||
@@ -231,7 +235,7 @@ void OptionProfile::populate(){
|
||||
renderer->BindTexture(mAvatarTex);
|
||||
}
|
||||
|
||||
options.checkProfile();
|
||||
options.reloadProfile();
|
||||
PlayerData * pdata = NEW PlayerData(app->collection);
|
||||
|
||||
options[Options::ACTIVE_PROFILE] = temp;
|
||||
@@ -320,7 +324,6 @@ void OptionProfile::acceptSubmode()
|
||||
options[Options::ACTIVE_PROFILE] = selections[value];
|
||||
initialValue = value;
|
||||
populate();
|
||||
resources.Refresh(); //Update images, in case we've changed profiles, etc.
|
||||
bCheck = false;
|
||||
}
|
||||
|
||||
@@ -759,7 +762,7 @@ void OptionNewProfile::Update(float dt){
|
||||
|
||||
if(temp != value){
|
||||
options[Options::ACTIVE_PROFILE] = value;
|
||||
options.checkProfile();
|
||||
options.reloadProfile();
|
||||
}
|
||||
value = "";
|
||||
bChanged = true;
|
||||
@@ -798,3 +801,13 @@ OptionTheme::OptionTheme(): OptionDirectory(RESPATH"/themes",Options::ACTIVE_THE
|
||||
if(selections.size() == 1)
|
||||
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);
|
||||
mTextureMap[textureName] = id;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user