Jeck - Profile loading fix, minor options menu improvements, minor cleanup.

This commit is contained in:
wagic.jeck
2009-09-09 11:11:17 +00:00
parent 4993cc5dea
commit 91a9387e33
8 changed files with 1277 additions and 1248 deletions
+13 -1
View File
@@ -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==");
}
+34 -31
View File
@@ -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,39 +276,31 @@ 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);
//If it doesn't exist, load current profile.
if(!profileOptions)
profileOptions = NEW GameOptions(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
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());
themeOptions = NEW GameOptions(buf);
}
SAFE_DELETE(themeOptions);
themeOptions = NEW GameOptions(buf);
//Validation of collection, etc, only happens if the game is up.
if(theGame == NULL || theGame->collection == NULL)
return;
@@ -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){
+4 -10
View File
@@ -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();
+203 -203
View File
@@ -1,203 +1,203 @@
#include "../include/config.h"
#include "../include/GameStateOptions.h"
#include "../include/GameApp.h"
#include "../include/OptionItem.h"
#include "../include/SimpleMenu.h"
#include "../include/SimplePad.h"
#include "../include/GameOptions.h"
#include "../include/Translate.h"
GameStateOptions::GameStateOptions(GameApp* parent): GameState(parent) {
optionsTabs = NULL;
optionsMenu = NULL;
confirmMenu = NULL;
}
GameStateOptions::~GameStateOptions() {
}
void GameStateOptions::Start()
{
timer = 0;
mState = SHOW_OPTIONS;
JRenderer::GetInstance()->ResetPrivateVRAM();
JRenderer::GetInstance()->EnableVSync(true);
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));
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));
optionsTabs = NEW OptionsMenu();
optionsTabs->Add(optionsList);
optionsList = NEW OptionsList("Profiles");
OptionNewProfile * key = NEW OptionNewProfile("","New Profile");
key->bShowValue = false;
optionsList->Add(key);
OptionProfile * pickProf = NEW OptionProfile(mParent);
optionsList->Add(pickProf);
OptionTheme * theme = NEW OptionTheme();
optionsList->Add(theme);
optionsTabs->Add(optionsList);
optionsList = NEW OptionsList("Credits");
optionsList->failMsg = "";
optionsTabs->Add(optionsList);
JLBFont * mFont = resources.GetJLBFont("f3");
optionsMenu = NEW SimpleMenu(102, this,mFont, 50,170);
optionsMenu->Add(1, "Save & Back to Main Menu");
optionsMenu->Add(2, "Back to Main Menu");
optionsMenu->Add(3, "Cancel");
confirmMenu = NEW SimpleMenu(103, this,mFont, 50,170);
confirmMenu->Add(1, "Use this profile");
confirmMenu->Add(2, "Cancel");
}
void GameStateOptions::End()
{
JRenderer::GetInstance()->EnableVSync(false);
SAFE_DELETE(optionsTabs);
SAFE_DELETE(optionsMenu);
SAFE_DELETE(confirmMenu);
}
void GameStateOptions::Update(float dt)
{
timer += dt;
if(options.keypadActive()){
options.keypadUpdate(dt);
}
else if (mState == SHOW_OPTIONS){
switch(optionsTabs->Submode()){
case OPTIONS_SUBMODE_RELOAD:
optionsTabs->acceptSubmode();
optionsTabs->reloadValues();
mState = SHOW_OPTIONS;
break;
case OPTIONS_SUBMODE_PROFILE:
mState = SHOW_OPTIONS_PROFILE;
break;
default:
if (PSP_CTRL_START == mEngine->ReadButton() )
mState = SHOW_OPTIONS_MENU;
optionsTabs->Update(dt);
break;
}
}else if(mState == SHOW_OPTIONS_MENU){
optionsMenu->Update(dt);
}else if(mState == SHOW_OPTIONS_PROFILE){
confirmMenu->Update(dt);
}
}
void GameStateOptions::Render()
{
//Erase
JRenderer::GetInstance()->ClearScreen(ARGB(0,0,0,0));
const char * const CreditsText[] = {
"Wagic, The Homebrew?! by WilLoW",
"",
"updates, new cards, and more on http://wololo.net/wagic",
"Many thanks to the devs and card creators who help this project",
"",
"Developped with the JGE++ Library (http://jge.khors.com)",
"Player's avatar from http://mathieuchoinet.blogspot.com, under CC License",
"Background picture and some art from the KDE project, www.kde.org",
"SFX From www.soundsnap.com",
"",
"Music by Celestial Aeon Project, http://www.jamendo.com",
"",
"",
"This work is not related to or endorsed by Wizards of the Coast, Inc",
"",
"Please support this project with donations at http://wololo.net/wagic",
};
JLBFont * mFont = resources.GetJLBFont("magic");
mFont->SetColor(ARGB(255,200,200,200));
mFont->SetScale(1.0);
float startpos = 272 - timer * 10;
float pos = startpos;
int size = sizeof(CreditsText) / sizeof(CreditsText[0]);
for (int i = 0; i < size; i++){
pos = startpos +20*i;
if (pos > -20){
mFont->DrawString(_(CreditsText[i]).c_str(),SCREEN_WIDTH/2,pos ,JGETEXT_CENTER);
}
}
if (pos < -20)
timer = 0;
mFont->SetScale(1.f);
optionsTabs->Render();
switch(mState){
case SHOW_OPTIONS_MENU:
optionsMenu->Render();
break;
case SHOW_OPTIONS_PROFILE:
confirmMenu->Render();
break;
}
if(options.keypadActive())
options.keypadRender();
}
void GameStateOptions::ButtonPressed(int controllerId, int controlId)
{
//Exit menu?
if(controllerId == 102)
switch (controlId){
case 1:
optionsTabs->save();
case 2:
mParent->SetNextState(GAME_STATE_MENU);
break;
case 3:
mState = SHOW_OPTIONS;
break;
}
//Profile confirmation?
else if(controllerId == 103)
switch (controlId){
case 1:
//Load the New profile.
optionsTabs->acceptSubmode();
optionsTabs->reloadValues();
//Reset the current settings to those of the profile...
mState = SHOW_OPTIONS;
break;
case 2:
optionsTabs->cancelSubmode();
mState = SHOW_OPTIONS;
break;
}
};
#include "../include/config.h"
#include "../include/GameStateOptions.h"
#include "../include/GameApp.h"
#include "../include/OptionItem.h"
#include "../include/SimpleMenu.h"
#include "../include/SimplePad.h"
#include "../include/GameOptions.h"
#include "../include/Translate.h"
GameStateOptions::GameStateOptions(GameApp* parent): GameState(parent) {
optionsTabs = NULL;
optionsMenu = NULL;
confirmMenu = NULL;
}
GameStateOptions::~GameStateOptions() {
}
void GameStateOptions::Start()
{
timer = 0;
mState = SHOW_OPTIONS;
JRenderer::GetInstance()->ResetPrivateVRAM();
JRenderer::GetInstance()->EnableVSync(true);
OptionsList * optionsList;
optionsList = NEW OptionsList("Settings");
optionsList->Add(NEW OptionHeader("General Options"));
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,0,"Default"));
optionsTabs = NEW OptionsMenu();
optionsTabs->Add(optionsList);
optionsList = NEW OptionsList("Profiles");
OptionNewProfile * key = NEW OptionNewProfile("","New Profile");
key->bShowValue = false;
optionsList->Add(key);
OptionProfile * pickProf = NEW OptionProfile(mParent);
optionsList->Add(pickProf);
OptionTheme * theme = NEW OptionTheme();
optionsList->Add(theme);
optionsTabs->Add(optionsList);
optionsList = NEW OptionsList("Credits");
optionsList->failMsg = "";
optionsTabs->Add(optionsList);
JLBFont * mFont = resources.GetJLBFont("f3");
optionsMenu = NEW SimpleMenu(102, this,mFont, 50,170);
optionsMenu->Add(1, "Save & Back to Main Menu");
optionsMenu->Add(2, "Back to Main Menu");
optionsMenu->Add(3, "Cancel");
confirmMenu = NEW SimpleMenu(103, this,mFont, 50,170);
confirmMenu->Add(1, "Use this profile");
confirmMenu->Add(2, "Cancel");
}
void GameStateOptions::End()
{
JRenderer::GetInstance()->EnableVSync(false);
SAFE_DELETE(optionsTabs);
SAFE_DELETE(optionsMenu);
SAFE_DELETE(confirmMenu);
}
void GameStateOptions::Update(float dt)
{
timer += dt;
if(options.keypadActive()){
options.keypadUpdate(dt);
}
else if (mState == SHOW_OPTIONS){
switch(optionsTabs->Submode()){
case OPTIONS_SUBMODE_RELOAD:
optionsTabs->acceptSubmode();
optionsTabs->reloadValues();
mState = SHOW_OPTIONS;
break;
case OPTIONS_SUBMODE_PROFILE:
mState = SHOW_OPTIONS_PROFILE;
break;
default:
if (PSP_CTRL_START == mEngine->ReadButton() )
mState = SHOW_OPTIONS_MENU;
optionsTabs->Update(dt);
break;
}
}else if(mState == SHOW_OPTIONS_MENU){
optionsMenu->Update(dt);
}else if(mState == SHOW_OPTIONS_PROFILE){
confirmMenu->Update(dt);
}
}
void GameStateOptions::Render()
{
//Erase
JRenderer::GetInstance()->ClearScreen(ARGB(0,0,0,0));
const char * const CreditsText[] = {
"Wagic, The Homebrew?! by WilLoW",
"",
"updates, new cards, and more on http://wololo.net/wagic",
"Many thanks to the devs and card creators who help this project",
"",
"Developped with the JGE++ Library (http://jge.khors.com)",
"Player's avatar from http://mathieuchoinet.blogspot.com, under CC License",
"Background picture and some art from the KDE project, www.kde.org",
"SFX From www.soundsnap.com",
"",
"Music by Celestial Aeon Project, http://www.jamendo.com",
"",
"",
"This work is not related to or endorsed by Wizards of the Coast, Inc",
"",
"Please support this project with donations at http://wololo.net/wagic",
};
JLBFont * mFont = resources.GetJLBFont("magic");
mFont->SetColor(ARGB(255,200,200,200));
mFont->SetScale(1.0);
float startpos = 272 - timer * 10;
float pos = startpos;
int size = sizeof(CreditsText) / sizeof(CreditsText[0]);
for (int i = 0; i < size; i++){
pos = startpos +20*i;
if (pos > -20){
mFont->DrawString(_(CreditsText[i]).c_str(),SCREEN_WIDTH/2,pos ,JGETEXT_CENTER);
}
}
if (pos < -20)
timer = 0;
mFont->SetScale(1.f);
optionsTabs->Render();
switch(mState){
case SHOW_OPTIONS_MENU:
optionsMenu->Render();
break;
case SHOW_OPTIONS_PROFILE:
confirmMenu->Render();
break;
}
if(options.keypadActive())
options.keypadRender();
}
void GameStateOptions::ButtonPressed(int controllerId, int controlId)
{
//Exit menu?
if(controllerId == 102)
switch (controlId){
case 1:
optionsTabs->save();
case 2:
mParent->SetNextState(GAME_STATE_MENU);
break;
case 3:
mState = SHOW_OPTIONS;
break;
}
//Profile confirmation?
else if(controllerId == 103)
switch (controlId){
case 1:
//Load the New profile.
optionsTabs->acceptSubmode();
optionsTabs->reloadValues();
//Reset the current settings to those of the profile...
mState = SHOW_OPTIONS;
break;
case 2:
optionsTabs->cancelSubmode();
mState = SHOW_OPTIONS;
break;
}
};
File diff suppressed because it is too large Load Diff
-4
View File
@@ -935,10 +935,6 @@ int WResourceManager::CreateTexture(const string &textureName) {
mTextureList.push_back(tex);
mTextureMap[textureName] = id;
}
else
{
}
return id;
}