added MnGuyens further improved menu handling and extra options.

This commit is contained in:
omegablast2002@yahoo.com
2010-09-17 06:34:12 +00:00
parent 3965505b15
commit 5939cbded8
15 changed files with 535 additions and 377 deletions

View File

@@ -1,5 +1,6 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "DeckMetaData.h"
using namespace std; using namespace std;
@@ -12,12 +13,12 @@ protected:
public: public:
vector<int> playerDeckOrderList; vector<DeckMetaData *> playerDeckOrderList;
vector<int> aiDeckOrderList; vector<DeckMetaData *> aiDeckOrderList;
void updateMetaDataList(vector<DeckMetaData *>* refList, bool isAI );
vector<int> * getPlayerDeckOrderList(); vector<DeckMetaData *> * getPlayerDeckOrderList();
vector<int> * getAIDeckOrderList(); vector<DeckMetaData *> * getAIDeckOrderList();
static DeckManager * GetInstance(); static DeckManager * GetInstance();
static void EndInstance(); static void EndInstance();

View File

@@ -4,29 +4,39 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <map> #include <map>
#include "../include/DeckStats.h"
using namespace std; using namespace std;
enum DECK_DIFFICULTY
{
HARD = -1,
NORMAL = 0,
EASY = 1
};
class DeckMetaData { class DeckMetaData {
public: public:
DeckMetaData(); DeckMetaData();
DeckMetaData(string filename); DeckMetaData(string filename, Player * statsPlayer);
void load(string filename); void load(string filename);
bool operator<(DeckMetaData b); void loadStatsForPlayer( Player * statsPlayer, string opponentDeckName = "" );
string getDescription();
string desc; string desc;
string name; string name;
int deckid; int deckid;
// statistical information
string& trim(string &str); int nbGamesPlayed, victories, percentVictories, difficulty;
string& ltrim(string &str);
string& rtrim(string &str);
}; };
class DeckMetaDataList { class DeckMetaDataList {
public: public:
void invalidate(string filename); void invalidate(string filename);
DeckMetaData * get(string filename); DeckMetaData * get(string filename, Player * statsPlayer = NULL);
~DeckMetaDataList(); ~DeckMetaDataList();
static DeckMetaDataList * decksMetaData; static DeckMetaDataList * decksMetaData;

View File

@@ -9,6 +9,8 @@ class JGE;
#include <string> #include <string>
#include <vector> #include <vector>
#include <iostream> #include <iostream>
#include "../include/DeckMetaData.h"
using namespace std; using namespace std;
enum ENUM_GAME_STATE enum ENUM_GAME_STATE
@@ -54,15 +56,25 @@ class GameState
virtual void Update(float dt) = 0; virtual void Update(float dt) = 0;
virtual void Render() = 0; virtual void Render() = 0;
static int fillDeckMenu(SimpleMenu * _menu, string path, string smallDeckPrefix = "", Player * statsPlayer = NULL);
static int fillDeckMenu( vector<int> * deckIdList, SimpleMenu * _menu, string path, string smallDeckPrefix = "", Player * statsPlayer = NULL);
string& trim(string &str);
string& ltrim(string &str);
string& rtrim(string &str);
};
// deck manipulation methods
// 2010/09/15:
// this was originally one method to do everything. That has been split up into two distinct
// methods since the original was building a menu and returning a value. The first
// creates the vector containing the deck information. The second will render that information
// it makes it easier to manipulate the deck information menus.
// generate the Deck Meta Data and build the menu items of the menu given
static vector<DeckMetaData *> fillDeckMenu(SimpleMenu * _menu, string path, string smallDeckPrefix = "", Player * statsPlayer = NULL);
// build a vector of decks with the information passsed in.
static vector<DeckMetaData *> getValidDeckMetaData(string path, string smallDeckPrefix = "", Player * statsPlayer = NULL);
// build menu items based on the vector<DeckMetaData *>
static void renderDeckMenu(SimpleMenu * _menu, vector<DeckMetaData *> deckMetaDataList);
};
bool sortByName( DeckMetaData * d1, DeckMetaData * d2 );
#endif #endif

View File

@@ -35,6 +35,36 @@ enum
}; };
// TODO: need a better name for MENU_FIRST_MENU, this is reused for the 1st submenu of
// available options in the duel menu
enum
{
MENU_CARD_PURCHASE = 2,
MENU_DECK_SELECTION = 10,
MENU_DECK_BUILDER = 11,
MENU_FIRST_DUEL_SUBMENU = 102,
MENU_LANGUAGE_SELECTION = 103,
};
// enums for menu options
// TODO: make these enums a little more descriptive. (ie should reflect what menu they are attached to )
enum DECK_VIEWER_MENU_ITEMS
{
MENU_ITEM_NEW_DECK = -30,
MENU_ITEM_CHEAT_MODE = -12,
MENU_ITEM_CANCEL = -1,
MENU_ITEM_SAVE_RETURN_MAIN_MENU = 0,
MENU_ITEM_SAVE_RENAME = 1,
MENU_ITEM_SWITCH_DECKS_NO_SAVE = 2,
MENU_ITEM_MAIN_MENU = 3,
MENU_ITEM_EDITOR_CANCEL = 4,
MENU_ITEM_YES = 20,
MENU_ITEM_NO = 21,
MENU_ITEM_FILTER_BY = 22
};
#define ALL_COLORS -1 #define ALL_COLORS -1
#define ROTATE_LEFT 1; #define ROTATE_LEFT 1;

View File

@@ -52,6 +52,16 @@ class GameStateDuel: public GameState, public JGuiListener
virtual void Update(float dt); virtual void Update(float dt);
virtual void Render(); virtual void Render();
void initRand (unsigned seed = 0); void initRand (unsigned seed = 0);
enum ENUM_DUEL_STATE_MENU_ITEM
{
MENUITEM_NEW_DECK = -1,
MENUITEM_CANCEL = -10,
MENUITEM_RANDOM_PLAYER = -11,
MENUITEM_RANDOM_AI = -12,
MENUITEM_MAIN_MENU = -13,
MENUITEM_EVIL_TWIN = -14
};
}; };

View File

@@ -67,6 +67,15 @@ class GameStateMenu: public GameState, public JGuiListener
void resetDirectory(); void resetDirectory();
void createUsersFirstDeck(int setId); void createUsersFirstDeck(int setId);
virtual ostream& toString(ostream& out) const; virtual ostream& toString(ostream& out) const;
enum
{
MENU_CARD_PURCHASE = 2,
MENU_DECK_SELECTION = 10,
MENU_DECK_BUILDER = 11,
MENU_FIRST_DUEL_SUBMENU = 102,
MENU_LANGUAGE_SELECTION = 103,
};
}; };
#endif #endif

View File

@@ -33,9 +33,10 @@
using std::string; using std::string;
//string manipulation methods
string& trim(string &str);
string& ltrim(string &str);
string& rtrim(string &str);
int loadRandValues(string s); int loadRandValues(string s);
int filesize(const char * filename); int filesize(const char * filename);

View File

@@ -5,6 +5,7 @@
#include "../include/AllAbilities.h" #include "../include/AllAbilities.h"
#include "../include/ExtraCost.h" #include "../include/ExtraCost.h"
#include "../include/GuiCombat.h" #include "../include/GuiCombat.h"
#include "../include/GameStateDuel.h"
const char * const MTG_LAND_TEXTS[] = {"artifact","forest","island","mountain","swamp","plains","other lands"}; const char * const MTG_LAND_TEXTS[] = {"artifact","forest","island","mountain","swamp","plains","other lands"};
@@ -575,7 +576,7 @@ AIPlayer * AIPlayerFactory::createAIPlayer(MTGAllCards * collection, Player * op
char avatarFile[512]; char avatarFile[512];
char deckFileSmall[512]; char deckFileSmall[512];
if (deckid == -1){ //Evil twin if (deckid == GameStateDuel::MENUITEM_EVIL_TWIN){ //Evil twin
sprintf(deckFile, "%s", opponent->deckFile.c_str()); sprintf(deckFile, "%s", opponent->deckFile.c_str());
OutputDebugString(opponent->deckFile.c_str()); OutputDebugString(opponent->deckFile.c_str());
sprintf(avatarFile, "%s", "baka.jpg"); sprintf(avatarFile, "%s", "baka.jpg");

View File

@@ -9,13 +9,23 @@ DeckManager::~DeckManager()
{ {
} }
void DeckManager::updateMetaDataList( vector<DeckMetaData *> * refList, bool isAI )
{
if (refList)
{
vector<DeckMetaData *> * inputList = isAI? &aiDeckOrderList : &playerDeckOrderList;
inputList->clear();
inputList->assign( refList->begin(), refList->end());
}
}
vector<int> * DeckManager::getPlayerDeckOrderList()
vector<DeckMetaData *> * DeckManager::getPlayerDeckOrderList()
{ {
return &playerDeckOrderList; return &playerDeckOrderList;
} }
vector<int> * DeckManager::getAIDeckOrderList() vector<DeckMetaData *> * DeckManager::getAIDeckOrderList()
{ {
return &aiDeckOrderList; return &aiDeckOrderList;
} }
@@ -33,6 +43,5 @@ DeckManager* DeckManager::GetInstance()
void DeckManager::EndInstance() void DeckManager::EndInstance()
{ {
SAFE_DELETE(mInstance); SAFE_DELETE(mInstance);
} }

View File

@@ -1,6 +1,9 @@
#include "../include/DeckMetaData.h" #include "../include/DeckMetaData.h"
#include "../include/DeckStats.h"
#include "../include/MTGDeck.h" #include "../include/MTGDeck.h"
#include "../include/config.h" #include "../include/config.h"
#include "../include/utils.h"
//Possible improvements: //Possible improvements:
//Merge this with DeckStats //Merge this with DeckStats
//Have this class handle all the Meta Data rather than relying on MTGDeck. Then MTGDeck would have a MetaData object... //Have this class handle all the Meta Data rather than relying on MTGDeck. Then MTGDeck would have a MetaData object...
@@ -12,25 +15,75 @@ DeckMetaData::DeckMetaData(){
} }
DeckMetaData::DeckMetaData(string filename){ DeckMetaData::DeckMetaData(string filename, Player * statsPlayer){
load(filename); load(filename);
} }
void DeckMetaData::loadStatsForPlayer( Player * statsPlayer, string deckStatsFileName )
{
DeckStats * stats = DeckStats::GetInstance();
if ( statsPlayer )
{
stats->load(statsPlayer);
DeckStat * opponentDeckStats = stats->getDeckStat(deckStatsFileName);
if ( opponentDeckStats )
{
percentVictories = stats->percentVictories(deckStatsFileName);
victories = opponentDeckStats->victories;
nbGamesPlayed = opponentDeckStats->nbgames;
if (percentVictories < 34){
difficulty = HARD;
}else if (percentVictories < 67){
difficulty = NORMAL;
}else{
difficulty = EASY;
}
}
}
else
{
if(fileExists(deckStatsFileName.c_str())){
stats->load(deckStatsFileName.c_str());
nbGamesPlayed = stats->nbGames();
percentVictories = stats->percentVictories();
}
}
}
string DeckMetaData::getDescription()
{
char deckDesc[512];
string difficultyString = "";
switch( difficulty )
{
case HARD:
difficultyString = "Hard";
break;
case EASY:
difficultyString = "Easy";
break;
}
if ( nbGamesPlayed > 0 && difficultyString != "")
sprintf(deckDesc, "Difficulty: %s\nVictory %%: %i\nGames Played: %i\n\n%s", difficultyString.c_str(), percentVictories, nbGamesPlayed, desc.c_str() );
else if ( nbGamesPlayed > 0 )
sprintf(deckDesc, "Victory %%: %i\nGames Played: %i\n\n%s", percentVictories, nbGamesPlayed, desc.c_str() );
else
return desc.c_str();
return deckDesc;
}
void DeckMetaData::load(string filename){ void DeckMetaData::load(string filename){
MTGDeck * mtgd = NEW MTGDeck(filename.c_str(),NULL,1); MTGDeck * mtgd = NEW MTGDeck(filename.c_str(),NULL,1);
name = DeckMetaData::trim( mtgd->meta_name ); name = trim( mtgd->meta_name );
desc = DeckMetaData::trim( mtgd->meta_desc ); desc = trim( mtgd->meta_desc );
deckid = atoi( (filename.substr( filename.find("deck") + 4, filename.find(".txt") )).c_str() ); deckid = atoi( (filename.substr( filename.find("deck") + 4, filename.find(".txt") )).c_str() );
delete(mtgd); delete(mtgd);
} }
// Must define less than relative to DeckMetaData objects.
bool DeckMetaData::operator<(DeckMetaData b)
{
return strcmp(name.c_str(), b.name.c_str()) < 0;
}
DeckMetaDataList::~DeckMetaDataList(){ DeckMetaDataList::~DeckMetaDataList(){
for(map<string,DeckMetaData *>::iterator it = values.begin(); it != values.end(); ++it){ for(map<string,DeckMetaData *>::iterator it = values.begin(); it != values.end(); ++it){
SAFE_DELETE(it->second); SAFE_DELETE(it->second);
@@ -46,11 +99,12 @@ void DeckMetaDataList::invalidate(string filename){
} }
} }
DeckMetaData * DeckMetaDataList::get(string filename){
DeckMetaData * DeckMetaDataList::get(string filename, Player * statsPlayer){
map<string,DeckMetaData *>::iterator it = values.find(filename); map<string,DeckMetaData *>::iterator it = values.find(filename);
if (it ==values.end()){ if (it ==values.end()){
if (fileExists(filename.c_str())) { if (fileExists(filename.c_str())) {
values[filename] = NEW DeckMetaData(filename); values[filename] = NEW DeckMetaData(filename, statsPlayer);
} }
} }
@@ -58,44 +112,3 @@ DeckMetaData * DeckMetaDataList::get(string filename){
} }
string& DeckMetaData::trim(string &str)
{
int i,j,start,end;
//ltrim
for (i=0; (str[i]!=0 && str[i]<=32); )
i++;
start=i;
//rtrim
for(i=0,j=0; str[i]!=0; i++)
j = ((str[i]<=32)? j+1 : 0);
end=i-j;
str = str.substr(start,end-start);
return str;
}
string& DeckMetaData::ltrim(string &str)
{
int i,start;
for (i=0; (str[i]!=0 && str[i]<=32); )
i++;
start=i;
str = str.substr(start,str.length()-start);
return str;
}
string& DeckMetaData::rtrim(string &str)
{
int i,j,end;
for(i=0,j=0; str[i]!=0; i++)
j = ((str[i]<=32)? j+1 : 0);
end=i-j;
str = str.substr(0,end);
return str;
}

View File

@@ -5,112 +5,94 @@
#include "../include/SimpleMenu.h" #include "../include/SimpleMenu.h"
#include "../include/DeckStats.h" #include "../include/DeckStats.h"
#include "../include/DeckMetaData.h" #include "../include/DeckMetaData.h"
#include "../include/Player.h"
#include <vector> #include <vector>
int GameState::fillDeckMenu(SimpleMenu * _menu, string path, string smallDeckPrefix, Player * statsPlayer){ // The purpose of this method is to create a listing of decks to be used for the input menu
DeckMetaDataList * metas = DeckMetaDataList::decksMetaData; // by default, the list will be sorted by name
int found = 1; // TODO: revise sorting strategy to allow other types of sorting. Currently, it is hardwired to use
int nbDecks = 0; // sortByName to do the sorting. This was done since the menu item display is done in insertion order.
_menu->autoTranslate = false;
while (found){
found = 0;
char buffer[512];
char smallDeckName[512];
char deckDesc[512];
sprintf(buffer, "%s/deck%i.txt",path.c_str(),nbDecks+1);
if(DeckMetaData * meta = metas->get(buffer)){
found = 1;
nbDecks++;
sprintf(smallDeckName, "%s_deck%i",smallDeckPrefix.c_str(),nbDecks);
if (statsPlayer){
DeckStats * stats = DeckStats::GetInstance();
stats->load(statsPlayer);
int percentVictories = stats->percentVictories(string(smallDeckName));
string difficulty;
if (percentVictories < 34){
difficulty = "(hard)";
}else if (percentVictories < 67){
difficulty = "";
}else{
difficulty = "(easy)";
}
sprintf(deckDesc, "%s %s",meta->name.c_str(), _(difficulty).c_str());
}else{
sprintf(deckDesc, "%s",meta->name.c_str());
}
deckDesc[16] = 0;
//translate decks desc
Translator * t = Translator::GetInstance();
map<string,string>::iterator it = t->deckValues.find(meta->name);
if (it != t->deckValues.end())
_menu->Add(nbDecks,deckDesc,it->second);
else
_menu->Add(nbDecks,deckDesc,meta->desc);
}
}
return nbDecks;
}
int GameState::fillDeckMenu(vector<int> * deckIdList, SimpleMenu * _menu, string path, string smallDeckPrefix, Player * statsPlayer){ vector<DeckMetaData *> GameState::fillDeckMenu( SimpleMenu * _menu, string path, string smallDeckPrefix, Player * statsPlayer){
DeckMetaDataList * metas = DeckMetaDataList::decksMetaData;
int found = 1;
int nbDecks = 0;
_menu->autoTranslate = false; _menu->autoTranslate = false;
map<string,DeckMetaData> menu; vector<DeckMetaData *> deckMetaDataVector = getValidDeckMetaData( path, smallDeckPrefix, statsPlayer );
list<string> deckNameVector; renderDeckMenu( _menu, deckMetaDataVector);
while (found){
found = 0;
char buffer[512];
char smallDeckName[512];
char deckDesc[512];
sprintf(buffer, "%s/deck%i.txt",path.c_str(),nbDecks+1);
if(DeckMetaData * meta = metas->get(buffer)){
found = 1;
nbDecks++;
sprintf(smallDeckName, "%s_deck%i",smallDeckPrefix.c_str(),nbDecks);
if (statsPlayer){
DeckStats * stats = DeckStats::GetInstance();
stats->load(statsPlayer);
int percentVictories = stats->percentVictories(string(smallDeckName));
string difficulty;
if (percentVictories < 34){
difficulty = "(hard)";
}else if (percentVictories < 67){
difficulty = "";
}else{
difficulty = "(easy)";
}
sprintf(deckDesc, "%s %s",meta->name.c_str(), _(difficulty).c_str());
}else{
sprintf(deckDesc, "%s",meta->name.c_str());
}
deckDesc[16] = 0;
menu[deckDesc] = *meta;
deckNameVector.push_back( deckDesc );
}
}
deckNameVector.sort(); return deckMetaDataVector;
int deckNumber = 1;
deckIdList->clear();
Translator * t = Translator::GetInstance();
map<string,string>::iterator it;
for (list<string>::iterator i = deckNameVector.begin(); i != deckNameVector.end(); i++)
{
string deckName = *i;
DeckMetaData meta = menu[ deckName ];
string deckDescription = meta.desc;
deckIdList->push_back( meta.deckid );
//translate decks desc
it = t->deckValues.find(meta.name);
if (it != t->deckValues.end())
_menu->Add(deckNumber++, deckName.c_str(), it->second);
else
_menu->Add( deckNumber++ ,deckName.c_str(), deckDescription.c_str());
}
return nbDecks;
} }
vector<DeckMetaData *> GameState::getValidDeckMetaData( string path, string smallDeckPrefix, Player * statsPlayer)
{
vector<DeckMetaData*> retList;
DeckMetaDataList * metas = DeckMetaDataList::decksMetaData;
int found = 1;
int nbDecks = 1;
while (found){
found = 0;
char buffer[512];
char smallDeckName[512];
char deckDesc[512];
sprintf(buffer, "%s/deck%i.txt",path.c_str(),nbDecks);
if(DeckMetaData * meta = metas->get(buffer, statsPlayer)){
found = 1;
sprintf(smallDeckName, "%s_deck%i",smallDeckPrefix.c_str(),nbDecks);
sprintf(deckDesc, "%s",meta->name.c_str());
if (statsPlayer){
string smallDeckNameStr = string(smallDeckName);
meta->loadStatsForPlayer( statsPlayer, smallDeckNameStr );
}
else
{
char playerStatsDeckName[512];
sprintf(playerStatsDeckName, "stats/player_deck%i.txt", nbDecks);
string deckstats = options.profileFile(playerStatsDeckName);
meta->loadStatsForPlayer( NULL, deckstats );
}
deckDesc[16] = 0;
retList.push_back( meta );
nbDecks++;
}
}
std::sort( retList.begin(), retList.end(), sortByName);
return retList;
}
// build a menu with the given deck list and return a vector of the deck ids created.
void GameState::renderDeckMenu ( SimpleMenu * _menu, vector<DeckMetaData *> deckMetaDataList )
{
int deckNumber = 1;
Translator * t = Translator::GetInstance();
map<string,string>::iterator it;
for (vector<DeckMetaData *>::iterator i = deckMetaDataList.begin(); i != deckMetaDataList.end(); i++)
{
DeckMetaData * deckMetaData = *i;
string deckName = deckMetaData -> name;
string deckDescription = deckMetaData -> getDescription();
//translate decks desc
it = t->deckValues.find(deckName);
if (it != t->deckValues.end())
_menu->Add(deckNumber++, deckName.c_str(), it->second);
else
_menu->Add( deckNumber++ ,deckName.c_str(), deckDescription.c_str());
}
}
// deck sorting routines
bool sortByName( DeckMetaData * d1, DeckMetaData * d2 )
{
return strcmp( d1->name.c_str(), d2->name.c_str()) < 0;
}
//end deck sorting routine

View File

@@ -4,6 +4,7 @@
#include <JGE.h> #include <JGE.h>
#include "../include/config.h" #include "../include/config.h"
#include "../include/DeckManager.h" #include "../include/DeckManager.h"
#include "../include/GameStateDuel.h"
#include "../include/GameStateDeckViewer.h" #include "../include/GameStateDeckViewer.h"
#include "../include/Translate.h" #include "../include/Translate.h"
#include "../include/ManaCostHybrid.h" #include "../include/ManaCostHybrid.h"
@@ -15,16 +16,16 @@
//!! helper function; this is probably handled somewhere in the code already. //!! helper function; this is probably handled somewhere in the code already.
// If not, should be placed in general library // If not, should be placed in general library
void StringExplode(string str, string separator, vector<string>* results){ void StringExplode(string str, string separator, vector<string>* results){
size_t found; size_t found;
found = str.find_first_of(separator);
while (found != string::npos){
if (found > 0)
results->push_back(str.substr(0,found));
str = str.substr(found+1);
found = str.find_first_of(separator); found = str.find_first_of(separator);
while (found != string::npos){ }
if (found > 0) if (str.length() > 0)
results->push_back(str.substr(0,found)); results->push_back(str);
str = str.substr(found+1);
found = str.find_first_of(separator);
}
if (str.length() > 0)
results->push_back(str);
} }
GameStateDeckViewer::GameStateDeckViewer(GameApp* parent): GameState(parent) { GameStateDeckViewer::GameStateDeckViewer(GameApp* parent): GameState(parent) {
@@ -86,7 +87,7 @@ void GameStateDeckViewer::updateFilters(){
void GameStateDeckViewer::loadIndexes(){ void GameStateDeckViewer::loadIndexes(){
int x=0; int x=0;
for (int i = 0; i < 7; i++){ for (int i = 0; i < 7; i++){
cardIndex[i] = displayed_deck->getCard(i); cardIndex[i] = displayed_deck->getCard(i);
} }
} }
@@ -103,15 +104,22 @@ void GameStateDeckViewer::switchDisplay(){
void GameStateDeckViewer::updateDecks(){ void GameStateDeckViewer::updateDecks(){
SAFE_DELETE(welcome_menu); SAFE_DELETE(welcome_menu);
welcome_menu = NEW SimpleMenu(10,this,Constants::MENU_FONT,20,20); welcome_menu = NEW SimpleMenu( MENU_DECK_SELECTION, this, Constants::MENU_FONT,20,20);
DeckManager * deckManager = DeckManager::GetInstance(); DeckManager * deckManager = DeckManager::GetInstance();
nbDecks = fillDeckMenu( deckManager->getPlayerDeckOrderList(), welcome_menu,options.profileFile()); vector<DeckMetaData *> playerDeckList = fillDeckMenu( welcome_menu,options.profileFile());
deckNum = 0; deckNum = 0;
newDeckname = ""; newDeckname = "";
welcome_menu->Add(nbDecks+1, _("--NEW--").c_str()); nbDecks = playerDeckList.size() + 1;
welcome_menu->Add( MENU_ITEM_NEW_DECK, _("--NEW--").c_str() );
if(options[Options::CHEATMODE].number && (!myCollection || myCollection->getCount(WSrcDeck::UNFILTERED_MIN_COPIES) < 4)) if(options[Options::CHEATMODE].number && (!myCollection || myCollection->getCount(WSrcDeck::UNFILTERED_MIN_COPIES) < 4))
welcome_menu->Add(-12,"--UNLOCK CARDS--"); welcome_menu->Add( MENU_ITEM_CHEAT_MODE, "--UNLOCK CARDS--" );
welcome_menu->Add(-1, _("Cancel").c_str()); welcome_menu->Add( MENU_ITEM_CANCEL, _("Cancel").c_str() );
// update the deckmanager with the latest information
deckManager->updateMetaDataList( &playerDeckList, false);
// is this necessary to ensure no memory leaks?
playerDeckList.clear();
} }
void GameStateDeckViewer::Start() void GameStateDeckViewer::Start()
@@ -134,13 +142,13 @@ void GameStateDeckViewer::Start()
myCollection->Sort(WSrcCards::SORT_ALPHA); myCollection->Sort(WSrcCards::SORT_ALPHA);
displayed_deck = myCollection; displayed_deck = myCollection;
//Build menu. //Build menu.
menu = NEW SimpleMenu(11,this,Constants::MENU_FONT,SCREEN_WIDTH/2-150,20); menu = NEW SimpleMenu( MENU_DECK_BUILDER, this, Constants::MENU_FONT,SCREEN_WIDTH/2-150,20);
menu->Add(22,"Filter by..."); menu->Add( MENU_ITEM_FILTER_BY, "Filter by...");
menu->Add(2,"Switch decks without saving"); menu->Add( MENU_ITEM_SWITCH_DECKS_NO_SAVE, "Switch decks without saving");
menu->Add(1,"Save & Rename"); menu->Add( MENU_ITEM_SAVE_RENAME, "Save & Rename");
menu->Add(0,"Save & Back to Main Menu"); menu->Add( MENU_ITEM_SAVE_RETURN_MAIN_MENU, "Save & Back to Main Menu");
menu->Add(3,"Back to Main Menu"); menu->Add( MENU_ITEM_MAIN_MENU, "Back to Main Menu");
menu->Add(4,"Cancel"); menu->Add( MENU_ITEM_EDITOR_CANCEL, "Cancel");
//Icons //Icons
mIcons[Constants::MTG_COLOR_ARTIFACT] = resources.GetQuad("c_artifact"); mIcons[Constants::MTG_COLOR_ARTIFACT] = resources.GetQuad("c_artifact");
@@ -224,7 +232,7 @@ void GameStateDeckViewer::saveDeck(){
void GameStateDeckViewer::Update(float dt) void GameStateDeckViewer::Update(float dt)
{ {
int myD = (displayed_deck == myDeck); int myD = (displayed_deck == myDeck);
if(options.keypadActive()){ if(options.keypadActive()){
@@ -302,9 +310,9 @@ void GameStateDeckViewer::Update(float dt)
if (card && displayed_deck->count(card)){ if (card && displayed_deck->count(card)){
price = pricelist->getSellPrice(card->getMTGId()); price = pricelist->getSellPrice(card->getMTGId());
sprintf(buffer,"%s : %i %s",_(card->data->getName()).c_str(),price,_("credits").c_str()); sprintf(buffer,"%s : %i %s",_(card->data->getName()).c_str(),price,_("credits").c_str());
subMenu = NEW SimpleMenu(2,this,Constants::MAIN_FONT,SCREEN_WIDTH-300,SCREEN_HEIGHT/2,buffer); subMenu = NEW SimpleMenu( MENU_CARD_PURCHASE, this, Constants::MAIN_FONT,SCREEN_WIDTH-300,SCREEN_HEIGHT/2,buffer);
subMenu->Add(20,"Yes"); subMenu->Add( MENU_ITEM_YES,"Yes");
subMenu->Add(21,"No","",true); subMenu->Add( MENU_ITEM_NO,"No","",true);
} }
} }
stw.needUpdate = true; stw.needUpdate = true;
@@ -536,7 +544,7 @@ void GameStateDeckViewer::renderOnScreenMenu(){
float rightPspX = SCREEN_WIDTH-100 + rightTransition; float rightPspX = SCREEN_WIDTH-100 + rightTransition;
float rightPspY = SCREEN_HEIGHT/2 - 20 ; float rightPspY = SCREEN_HEIGHT/2 - 20 ;
if (stw.currentPage == 0) { if (stw.currentPage == 0) {
//FillRects //FillRects
r->FillRect(0-(onScreenTransition*84),0,84,SCREEN_HEIGHT,ARGB(128,0,0,0)); r->FillRect(0-(onScreenTransition*84),0,84,SCREEN_HEIGHT,ARGB(128,0,0,0));
@@ -606,7 +614,7 @@ void GameStateDeckViewer::renderOnScreenMenu(){
} }
font->DrawString(_("Press L/R to cycle through"), SCREEN_WIDTH-200+rightTransition, 5+fH); font->DrawString(_("Press L/R to cycle through"), SCREEN_WIDTH-200+rightTransition, 5+fH);
font->DrawString(_("deck statistics."), SCREEN_WIDTH-200+rightTransition, 5+fH*2); font->DrawString(_("deck statistics."), SCREEN_WIDTH-200+rightTransition, 5+fH*2);
} else { } else {
if (stw.needUpdate) { if (stw.needUpdate) {
updateStats(); updateStats();
@@ -623,11 +631,11 @@ void GameStateDeckViewer::renderOnScreenMenu(){
r->FillRect(SCREEN_WIDTH/2+rightTransition,10,SCREEN_WIDTH/2-10,SCREEN_HEIGHT-20,ARGB(128,0,0,0)); r->FillRect(SCREEN_WIDTH/2+rightTransition,10,SCREEN_WIDTH/2-10,SCREEN_HEIGHT-20,ARGB(128,0,0,0));
font->DrawString(_("menu"), SCREEN_WIDTH-35 +rightTransition, SCREEN_HEIGHT-15); font->DrawString(_("menu"), SCREEN_WIDTH-35 +rightTransition, SCREEN_HEIGHT-15);
font->DrawString(_("filter"), SCREEN_WIDTH-95 +rightTransition, SCREEN_HEIGHT-15); font->DrawString(_("filter"), SCREEN_WIDTH-95 +rightTransition, SCREEN_HEIGHT-15);
int nb_letters = 0; int nb_letters = 0;
float posX, posY; float posX, posY;
DWORD graphColor; DWORD graphColor;
graphColor = ARGB(200, 155, 155, 155); graphColor = ARGB(200, 155, 155, 155);
string STATS_TITLE_FORMAT = _("%i: %s"); string STATS_TITLE_FORMAT = _("%i: %s");
@@ -636,7 +644,7 @@ void GameStateDeckViewer::renderOnScreenMenu(){
// Title // Title
sprintf(buffer, STATS_TITLE_FORMAT.c_str(), stw.currentPage, _("Statistics Summary").c_str()); sprintf(buffer, STATS_TITLE_FORMAT.c_str(), stw.currentPage, _("Statistics Summary").c_str());
font->DrawString(buffer, 10+leftTransition, 10); font->DrawString(buffer, 10+leftTransition, 10);
posY = 30; posY = 30;
posX = 180; posX = 180;
sprintf(buffer, _("Your Deck: %i cards").c_str(), stw.cardCount); sprintf(buffer, _("Your Deck: %i cards").c_str(), stw.cardCount);
@@ -654,23 +662,23 @@ void GameStateDeckViewer::renderOnScreenMenu(){
} }
} }
posY += 25; posY += 25;
r->DrawLine(posX - 4 + leftTransition, posY - 1, posX - 4 + leftTransition, posY + 177, ARGB(128, 255, 255, 255)); r->DrawLine(posX - 4 + leftTransition, posY - 1, posX - 4 + leftTransition, posY + 177, ARGB(128, 255, 255, 255));
r->DrawLine(19 + leftTransition, posY - 1, 19 + leftTransition, posY + 177, ARGB(128, 255, 255, 255)); r->DrawLine(19 + leftTransition, posY - 1, 19 + leftTransition, posY + 177, ARGB(128, 255, 255, 255));
r->DrawLine(posX + 40 + leftTransition, posY - 1, posX + 40 + leftTransition, posY + 177, ARGB(128, 255, 255, 255)); r->DrawLine(posX + 40 + leftTransition, posY - 1, posX + 40 + leftTransition, posY + 177, ARGB(128, 255, 255, 255));
r->DrawLine(20 + leftTransition, posY - 1, posX + 40 + leftTransition, posY - 1, ARGB(128, 255, 255, 255)); r->DrawLine(20 + leftTransition, posY - 1, posX + 40 + leftTransition, posY - 1, ARGB(128, 255, 255, 255));
font->DrawString(_("Lands"), 20 + leftTransition, posY); font->DrawString(_("Lands"), 20 + leftTransition, posY);
sprintf(buffer, _("%i").c_str(), stw.countLands); sprintf(buffer, _("%i").c_str(), stw.countLands);
font->DrawString(buffer, posX + leftTransition, posY); font->DrawString(buffer, posX + leftTransition, posY);
posY += 14; posY += 14;
r->DrawLine(20 + leftTransition, posY - 1, posX + 40 + leftTransition, posY - 1, ARGB(128, 255, 255, 255)); r->DrawLine(20 + leftTransition, posY - 1, posX + 40 + leftTransition, posY - 1, ARGB(128, 255, 255, 255));
font->DrawString( _("Creatures"), 20 + leftTransition, posY); font->DrawString( _("Creatures"), 20 + leftTransition, posY);
sprintf(buffer, _("%i").c_str(), stw.countCreatures); sprintf(buffer, _("%i").c_str(), stw.countCreatures);
font->DrawString(buffer, posX + leftTransition, posY); font->DrawString(buffer, posX + leftTransition, posY);
posY += 14; posY += 14;
r->DrawLine(20 + leftTransition, posY - 1, posX + 40 + leftTransition, posY - 1, ARGB(128, 255, 255, 255)); r->DrawLine(20 + leftTransition, posY - 1, posX + 40 + leftTransition, posY - 1, ARGB(128, 255, 255, 255));
font->DrawString(_("Spells"), 20 + leftTransition, posY); font->DrawString(_("Spells"), 20 + leftTransition, posY);
@@ -693,7 +701,7 @@ void GameStateDeckViewer::renderOnScreenMenu(){
font->DrawString(buffer, posX + leftTransition, posY); font->DrawString(buffer, posX + leftTransition, posY);
//sprintf(buffer, "Artifacts: %i", stw.countArtifacts); //sprintf(buffer, "Artifacts: %i", stw.countArtifacts);
//mFont->DrawString(buffer, 20, 123); //mFont->DrawString(buffer, 20, 123);
posY += 14; posY += 14;
r->DrawLine(20 + leftTransition, posY - 1, posX + 40 + leftTransition, posY - 1, ARGB(128, 255, 255, 255)); r->DrawLine(20 + leftTransition, posY - 1, posX + 40 + leftTransition, posY - 1, ARGB(128, 255, 255, 255));
@@ -704,7 +712,7 @@ void GameStateDeckViewer::renderOnScreenMenu(){
posY += 14; posY += 14;
r->DrawLine(20 + leftTransition, posY - 1, posX + 40 + leftTransition, posY - 1, ARGB(128, 255, 255, 255)); r->DrawLine(20 + leftTransition, posY - 1, posX + 40 + leftTransition, posY - 1, ARGB(128, 255, 255, 255));
font->DrawString(_("Probabilities"), 20 + leftTransition, posY); font->DrawString(_("Probabilities"), 20 + leftTransition, posY);
posY += 10; posY += 10;
font->DrawString(_("No land in 1st hand"), 30 + leftTransition, posY); font->DrawString(_("No land in 1st hand"), 30 + leftTransition, posY);
sprintf(buffer, _("%2.2f%%").c_str(), stw.noLandsProbInTurn[0]); sprintf(buffer, _("%2.2f%%").c_str(), stw.noLandsProbInTurn[0]);
@@ -714,7 +722,7 @@ void GameStateDeckViewer::renderOnScreenMenu(){
font->DrawString(_("No land in 9 cards"), 30 + leftTransition, posY); font->DrawString(_("No land in 9 cards"), 30 + leftTransition, posY);
sprintf(buffer, _("%2.2f%%").c_str(), stw.noLandsProbInTurn[2]); sprintf(buffer, _("%2.2f%%").c_str(), stw.noLandsProbInTurn[2]);
font->DrawString(buffer, posX + leftTransition, posY); font->DrawString(buffer, posX + leftTransition, posY);
posY += 10; posY += 10;
font->DrawString(_("No creatures in 1st hand"), 30 + leftTransition, posY); font->DrawString(_("No creatures in 1st hand"), 30 + leftTransition, posY);
sprintf(buffer, _("%2.2f%%").c_str(), stw.noCreaturesProbInTurn[0]); sprintf(buffer, _("%2.2f%%").c_str(), stw.noCreaturesProbInTurn[0]);
@@ -734,7 +742,7 @@ void GameStateDeckViewer::renderOnScreenMenu(){
font->DrawString(_("Victory ratio"), 30 + leftTransition, posY); font->DrawString(_("Victory ratio"), 30 + leftTransition, posY);
sprintf(buffer, _("%i%%").c_str(), stw.percentVictories); sprintf(buffer, _("%i%%").c_str(), stw.percentVictories);
font->DrawString(buffer, posX + leftTransition, posY); font->DrawString(buffer, posX + leftTransition, posY);
posY += 15; posY += 15;
r->DrawLine(20 + leftTransition, posY - 1, posX + 40 + leftTransition, posY - 1, ARGB(128, 255, 255, 255)); r->DrawLine(20 + leftTransition, posY - 1, posX + 40 + leftTransition, posY - 1, ARGB(128, 255, 255, 255));
font->DrawString(_("Total price (credits)"), 20 + leftTransition, posY); font->DrawString(_("Total price (credits)"), 20 + leftTransition, posY);
@@ -751,12 +759,12 @@ void GameStateDeckViewer::renderOnScreenMenu(){
font->DrawString(_("Counts of manasources per type and color:"), 20 + leftTransition, 30); font->DrawString(_("Counts of manasources per type and color:"), 20 + leftTransition, 30);
posY = 70; posY = 70;
// Column titles // Column titles
for (int j=0; j<Constants::MTG_NB_COLORS-1;j++){ for (int j=0; j<Constants::MTG_NB_COLORS-1;j++){
r->RenderQuad(mIcons[j], 52 + j*15 + leftTransition, posY - 10,0,0.5,0.5); r->RenderQuad(mIcons[j], 52 + j*15 + leftTransition, posY - 10,0,0.5,0.5);
} }
//font->DrawString(_("C"), 30 + leftTransition, posY-16); //font->DrawString(_("C"), 30 + leftTransition, posY-16);
//font->DrawString(_("Ty"), 27 + leftTransition, posY-16); //font->DrawString(_("Ty"), 27 + leftTransition, posY-16);
@@ -765,7 +773,7 @@ void GameStateDeckViewer::renderOnScreenMenu(){
r->DrawLine(27 + leftTransition, posY - 1, 60 + (Constants::MTG_NB_COLORS-2)*15 + leftTransition, posY - 1, ARGB(128, 255, 255, 255)); r->DrawLine(27 + leftTransition, posY - 1, 60 + (Constants::MTG_NB_COLORS-2)*15 + leftTransition, posY - 1, ARGB(128, 255, 255, 255));
r->DrawLine(27 + leftTransition, 2*10 + posY + 12, 60 + (Constants::MTG_NB_COLORS-2)*15 + leftTransition, 2*10 + posY + 12, ARGB(128, 255, 255, 255)); r->DrawLine(27 + leftTransition, 2*10 + posY + 12, 60 + (Constants::MTG_NB_COLORS-2)*15 + leftTransition, 2*10 + posY + 12, ARGB(128, 255, 255, 255));
r->DrawLine(27 + leftTransition, 3*10 + posY + 14, 60 + (Constants::MTG_NB_COLORS-2)*15 + leftTransition, 3*10 + posY + 14, ARGB(128, 255, 255, 255)); r->DrawLine(27 + leftTransition, 3*10 + posY + 14, 60 + (Constants::MTG_NB_COLORS-2)*15 + leftTransition, 3*10 + posY + 14, ARGB(128, 255, 255, 255));
// Vertical table lines // Vertical table lines
r->DrawLine(26 + leftTransition, posY - 20, 26 + leftTransition, 3*10 + posY + 14, ARGB(128, 255, 255, 255)); r->DrawLine(26 + leftTransition, posY - 20, 26 + leftTransition, 3*10 + posY + 14, ARGB(128, 255, 255, 255));
r->DrawLine(43 + leftTransition, posY - 20, 43 + leftTransition, 3*10 + posY + 14, ARGB(128, 255, 255, 255)); r->DrawLine(43 + leftTransition, posY - 20, 43 + leftTransition, 3*10 + posY + 14, ARGB(128, 255, 255, 255));
@@ -775,22 +783,22 @@ void GameStateDeckViewer::renderOnScreenMenu(){
font->DrawString(_("NB"), 27 + leftTransition, posY+10); font->DrawString(_("NB"), 27 + leftTransition, posY+10);
font->DrawString(_("O"), 30 + leftTransition, posY+20); font->DrawString(_("O"), 30 + leftTransition, posY+20);
font->DrawString(_("T"), 30 + leftTransition, posY+33); font->DrawString(_("T"), 30 + leftTransition, posY+33);
int curCount; int curCount;
for (int j=0; j<Constants::MTG_NB_COLORS-1;j++){ for (int j=0; j<Constants::MTG_NB_COLORS-1;j++){
curCount = stw.countBasicLandsPerColor[j]; curCount = stw.countBasicLandsPerColor[j];
sprintf(buffer, (curCount==0?".":"%i"), curCount); sprintf(buffer, (curCount==0?".":"%i"), curCount);
font->DrawString(buffer, 49 + leftTransition + j*15, posY); font->DrawString(buffer, 49 + leftTransition + j*15, posY);
curCount = stw.countLandsPerColor[j]; curCount = stw.countLandsPerColor[j];
sprintf(buffer, (curCount==0?".":"%i"), curCount); sprintf(buffer, (curCount==0?".":"%i"), curCount);
font->DrawString(buffer, 49 + leftTransition + j*15, posY+10); font->DrawString(buffer, 49 + leftTransition + j*15, posY+10);
curCount = stw.countNonLandProducersPerColor[j]; curCount = stw.countNonLandProducersPerColor[j];
sprintf(buffer, (curCount==0?".":"%i"), curCount); sprintf(buffer, (curCount==0?".":"%i"), curCount);
font->DrawString(buffer, 49 + leftTransition + j*15, posY+20); font->DrawString(buffer, 49 + leftTransition + j*15, posY+20);
curCount = stw.countLandsPerColor[j] + stw.countBasicLandsPerColor[j] + stw.countNonLandProducersPerColor[j]; curCount = stw.countLandsPerColor[j] + stw.countBasicLandsPerColor[j] + stw.countNonLandProducersPerColor[j];
sprintf(buffer, (curCount==0?".":"%i"), curCount); sprintf(buffer, (curCount==0?".":"%i"), curCount);
font->DrawString(buffer, 49 + leftTransition + j*15, posY+33); font->DrawString(buffer, 49 + leftTransition + j*15, posY+33);
@@ -848,47 +856,47 @@ void GameStateDeckViewer::renderOnScreenMenu(){
float avgCost; float avgCost;
switch (stw.currentPage) { // Nested switch on the same variable. Oh yes. switch (stw.currentPage) { // Nested switch on the same variable. Oh yes.
case 2: // Total counts case 2: // Total counts
// Title // Title
sprintf(buffer, STATS_TITLE_FORMAT.c_str(), stw.currentPage, _("Mana cost detail").c_str()); sprintf(buffer, STATS_TITLE_FORMAT.c_str(), stw.currentPage, _("Mana cost detail").c_str());
font->DrawString(buffer, 10+leftTransition, 10); font->DrawString(buffer, 10+leftTransition, 10);
font->DrawString(_("Card counts per mana cost:"), 20 + leftTransition, 30); font->DrawString(_("Card counts per mana cost:"), 20 + leftTransition, 30);
avgCost = stw.avgManaCost; avgCost = stw.avgManaCost;
countPerCost = &stw.countCardsPerCost; countPerCost = &stw.countCardsPerCost;
countPerCostAndColor = &stw.countCardsPerCostAndColor; countPerCostAndColor = &stw.countCardsPerCostAndColor;
break; break;
case 3: // Creature counts case 3: // Creature counts
// Title // Title
sprintf(buffer, STATS_TITLE_FORMAT.c_str(), stw.currentPage, _("Mana cost detail - Creatures").c_str()); sprintf(buffer, STATS_TITLE_FORMAT.c_str(), stw.currentPage, _("Mana cost detail - Creatures").c_str());
font->DrawString(buffer, 10+leftTransition, 10); font->DrawString(buffer, 10+leftTransition, 10);
font->DrawString(_("Creature counts per mana cost:"), 20 + leftTransition, 30); font->DrawString(_("Creature counts per mana cost:"), 20 + leftTransition, 30);
avgCost = stw.avgCreatureCost; avgCost = stw.avgCreatureCost;
countPerCost = &stw.countCreaturesPerCost; countPerCost = &stw.countCreaturesPerCost;
countPerCostAndColor = &stw.countCreaturesPerCostAndColor; countPerCostAndColor = &stw.countCreaturesPerCostAndColor;
break; break;
case 4: // Spell counts case 4: // Spell counts
// Title // Title
sprintf(buffer, STATS_TITLE_FORMAT.c_str(), stw.currentPage, _("Mana cost detail - Spells").c_str()); sprintf(buffer, STATS_TITLE_FORMAT.c_str(), stw.currentPage, _("Mana cost detail - Spells").c_str());
font->DrawString(buffer, 10+leftTransition, 10); font->DrawString(buffer, 10+leftTransition, 10);
font->DrawString(_("Non-creature spell counts per mana cost:"), 20 + leftTransition, 30); font->DrawString(_("Non-creature spell counts per mana cost:"), 20 + leftTransition, 30);
avgCost = stw.avgSpellCost; avgCost = stw.avgSpellCost;
countPerCost = &stw.countSpellsPerCost; countPerCost = &stw.countSpellsPerCost;
countPerCostAndColor = &stw.countSpellsPerCostAndColor; countPerCostAndColor = &stw.countSpellsPerCostAndColor;
break; break;
default: default:
countPerCost = NULL; countPerCost = NULL;
countPerCostAndColor = NULL; countPerCostAndColor = NULL;
avgCost = 0; avgCost = 0;
break; break;
} }
posY = 70; posY = 70;
// Column titles // Column titles
for (int j=0; j<Constants::MTG_NB_COLORS-1;j++){ for (int j=0; j<Constants::MTG_NB_COLORS-1;j++){
r->RenderQuad(mIcons[j], 67 + j*15 + leftTransition, posY - 10,0,0.5,0.5); r->RenderQuad(mIcons[j], 67 + j*15 + leftTransition, posY - 10,0,0.5,0.5);
} }
font->DrawString(_("C"), 30 + leftTransition, posY-16); font->DrawString(_("C"), 30 + leftTransition, posY-16);
font->DrawString(_("#"), 45 + leftTransition, posY-16); font->DrawString(_("#"), 45 + leftTransition, posY-16);
@@ -896,7 +904,7 @@ void GameStateDeckViewer::renderOnScreenMenu(){
r->DrawLine(27 + leftTransition, posY - 20, 75 + (Constants::MTG_NB_COLORS-2)*15 + leftTransition, posY - 20, ARGB(128, 255, 255, 255)); r->DrawLine(27 + leftTransition, posY - 20, 75 + (Constants::MTG_NB_COLORS-2)*15 + leftTransition, posY - 20, ARGB(128, 255, 255, 255));
r->DrawLine(27 + leftTransition, posY - 1, 75 + (Constants::MTG_NB_COLORS-2)*15 + leftTransition, posY - 1, ARGB(128, 255, 255, 255)); r->DrawLine(27 + leftTransition, posY - 1, 75 + (Constants::MTG_NB_COLORS-2)*15 + leftTransition, posY - 1, ARGB(128, 255, 255, 255));
r->DrawLine(27 + leftTransition, STATS_MAX_MANA_COST*10 + posY + 12, 75 + (Constants::MTG_NB_COLORS-2)*15 + leftTransition, STATS_MAX_MANA_COST*10 + posY + 12, ARGB(128, 255, 255, 255)); r->DrawLine(27 + leftTransition, STATS_MAX_MANA_COST*10 + posY + 12, 75 + (Constants::MTG_NB_COLORS-2)*15 + leftTransition, STATS_MAX_MANA_COST*10 + posY + 12, ARGB(128, 255, 255, 255));
// Vertical table lines // Vertical table lines
r->DrawLine(26 + leftTransition, posY - 20, 26 + leftTransition, STATS_MAX_MANA_COST*10 + posY + 12, ARGB(128, 255, 255, 255)); r->DrawLine(26 + leftTransition, posY - 20, 26 + leftTransition, STATS_MAX_MANA_COST*10 + posY + 12, ARGB(128, 255, 255, 255));
r->DrawLine(41 + leftTransition, posY - 20, 41 + leftTransition, STATS_MAX_MANA_COST*10 + posY + 12, ARGB(128, 255, 255, 255)); r->DrawLine(41 + leftTransition, posY - 20, 41 + leftTransition, STATS_MAX_MANA_COST*10 + posY + 12, ARGB(128, 255, 255, 255));
@@ -915,7 +923,7 @@ void GameStateDeckViewer::renderOnScreenMenu(){
r->FillRect((float)77 + leftTransition + (Constants::MTG_NB_COLORS-2)*15, posY + 2, (*countPerCost)[i]*5, 8, graphColor); r->FillRect((float)77 + leftTransition + (Constants::MTG_NB_COLORS-2)*15, posY + 2, (*countPerCost)[i]*5, 8, graphColor);
posY += 10; posY += 10;
} }
posY += 10; posY += 10;
sprintf(buffer, _("Average converted mana cost: %2.2f").c_str(), avgCost); sprintf(buffer, _("Average converted mana cost: %2.2f").c_str(), avgCost);
font->DrawString(buffer, 20 + leftTransition, posY); font->DrawString(buffer, 20 + leftTransition, posY);
@@ -924,7 +932,7 @@ void GameStateDeckViewer::renderOnScreenMenu(){
font->DrawString(buffer, 20 + leftTransition, posY); font->DrawString(buffer, 20 + leftTransition, posY);
posY += 10; posY += 10;
font->DrawString(_("# - Total number of cards with given cost"), 20 + leftTransition, posY); font->DrawString(_("# - Total number of cards with given cost"), 20 + leftTransition, posY);
break; break;
case 8: case 8:
@@ -947,13 +955,13 @@ void GameStateDeckViewer::renderOnScreenMenu(){
r->FillRect(84 + leftTransition, posY + 2, graphScale*stw.noLandsProbInTurn[i], 8, graphColor); r->FillRect(84 + leftTransition, posY + 2, graphScale*stw.noLandsProbInTurn[i], 8, graphColor);
posY += 10; posY += 10;
} }
// No creatures probability detail // No creatures probability detail
posY += 10; posY += 10;
font->DrawString( _("No creatures in first n cards:"), 20 + leftTransition, posY); font->DrawString( _("No creatures in first n cards:"), 20 + leftTransition, posY);
posY += 20; posY += 20;
graphScale = (stw.noCreaturesProbInTurn[0]==0) ? 0:(graphWidth/stw.noCreaturesProbInTurn[0]); graphScale = (stw.noCreaturesProbInTurn[0]==0) ? 0:(graphWidth/stw.noCreaturesProbInTurn[0]);
for (int i=0; i<STATS_FOR_TURNS; i++) { for (int i=0; i<STATS_FOR_TURNS; i++) {
sprintf(buffer, _("%i:").c_str(), i+7); sprintf(buffer, _("%i:").c_str(), i+7);
font->DrawString(buffer, 30 + leftTransition, posY); font->DrawString(buffer, 30 + leftTransition, posY);
@@ -971,7 +979,7 @@ void GameStateDeckViewer::renderOnScreenMenu(){
font->DrawString(buffer, 10+leftTransition, 10); font->DrawString(buffer, 10+leftTransition, 10);
font->DrawString(_("Total colored manasymbols in cards' casting costs:"), 20 + leftTransition, 30); font->DrawString(_("Total colored manasymbols in cards' casting costs:"), 20 + leftTransition, 30);
posY = 50; posY = 50;
for (int i=1; i<Constants::MTG_NB_COLORS-1; i++) { for (int i=1; i<Constants::MTG_NB_COLORS-1; i++) {
if (stw.totalCostPerColor[i]>0) { if (stw.totalCostPerColor[i]>0) {
@@ -992,14 +1000,14 @@ void GameStateDeckViewer::renderOnScreenMenu(){
} }
} }
break; break;
case 9: // Victory statistics case 9: // Victory statistics
// Title // Title
sprintf(buffer, STATS_TITLE_FORMAT.c_str(), stw.currentPage, _("Victory statistics").c_str()); sprintf(buffer, STATS_TITLE_FORMAT.c_str(), stw.currentPage, _("Victory statistics").c_str());
font->DrawString(buffer, 10+leftTransition, 10); font->DrawString(buffer, 10+leftTransition, 10);
font->DrawString(_("Victories against AI:"), 20 + leftTransition, 30); font->DrawString(_("Victories against AI:"), 20 + leftTransition, 30);
sprintf(buffer, _("Games played: %i").c_str(), stw.gamesPlayed); sprintf(buffer, _("Games played: %i").c_str(), stw.gamesPlayed);
font->DrawString(buffer, 20 + leftTransition, 45); font->DrawString(buffer, 20 + leftTransition, 45);
sprintf(buffer, _("Victory ratio: %i%%").c_str(), stw.percentVictories); sprintf(buffer, _("Victory ratio: %i%%").c_str(), stw.percentVictories);
@@ -1072,7 +1080,7 @@ void GameStateDeckViewer::updateStats() {
currentCost = current->data->getManaCost(); currentCost = current->data->getManaCost();
convertedCost = currentCost->getConvertedCost(); convertedCost = currentCost->getConvertedCost();
currentCount = myDeck->count(current); currentCount = myDeck->count(current);
// Add to the cards per cost counters // Add to the cards per cost counters
stw.totalManaCost += convertedCost * currentCount; stw.totalManaCost += convertedCost * currentCount;
if (convertedCost > STATS_MAX_MANA_COST) { if (convertedCost > STATS_MAX_MANA_COST) {
@@ -1086,7 +1094,7 @@ void GameStateDeckViewer::updateStats() {
stw.countSpellsPerCost[convertedCost] += currentCount; stw.countSpellsPerCost[convertedCost] += currentCount;
stw.totalSpellCost += convertedCost * currentCount; stw.totalSpellCost += convertedCost * currentCount;
} }
// Lets look for mana producing abilities // Lets look for mana producing abilities
vector<string> abilityStrings; vector<string> abilityStrings;
@@ -1130,7 +1138,7 @@ void GameStateDeckViewer::updateStats() {
} }
} }
} }
// b. Hybrid costs // b. Hybrid costs
ManaCostHybrid * hybridCost; ManaCostHybrid * hybridCost;
int i; int i;
@@ -1320,13 +1328,13 @@ void GameStateDeckViewer::Render() {
if(options.keypadActive()) if(options.keypadActive())
options.keypadRender(); options.keypadRender();
} }
int GameStateDeckViewer::loadDeck(int deckid){ int GameStateDeckViewer::loadDeck(int deckid){
stw.currentPage = 0; stw.currentPage = 0;
stw.pageCount = 9; stw.pageCount = 9;
stw.needUpdate = true; stw.needUpdate = true;
@@ -1349,7 +1357,7 @@ int GameStateDeckViewer::loadDeck(int deckid){
SAFE_DELETE(myDeck); SAFE_DELETE(myDeck);
} }
myDeck = NEW DeckDataWrapper(NEW MTGDeck(options.profileFile(deckname,"",false,false).c_str(), mParent->collection)); myDeck = NEW DeckDataWrapper(NEW MTGDeck(options.profileFile(deckname,"",false,false).c_str(), mParent->collection));
// Check whether the cards in the deck are actually available in the player's collection: // Check whether the cards in the deck are actually available in the player's collection:
int cheatmode = options[Options::CHEATMODE].number; int cheatmode = options[Options::CHEATMODE].number;
bool bPure = true; bool bPure = true;
@@ -1357,7 +1365,7 @@ int GameStateDeckViewer::loadDeck(int deckid){
MTGCard * current = myDeck->getCard(i,true); MTGCard * current = myDeck->getCard(i,true);
int howmanyinDeck = myDeck->count(current); int howmanyinDeck = myDeck->count(current);
for (int i = myCollection->count(current); i < howmanyinDeck; i++){ for (int i = myCollection->count(current); i < howmanyinDeck; i++){
bPure = false; bPure = false;
if(cheatmode){ //Are we cheating? if(cheatmode){ //Are we cheating?
playerdata->collection->add(current); //Yup, add it to collection permanently. playerdata->collection->add(current); //Yup, add it to collection permanently.
myCollection->Add(current); myCollection->Add(current);
@@ -1367,60 +1375,60 @@ int GameStateDeckViewer::loadDeck(int deckid){
break; break;
} }
} }
myCollection->Remove(current,myDeck->count(current)); myCollection->Remove(current,myDeck->count(current));
} }
if(!bPure){ if(!bPure){
myDeck->validate(); myDeck->validate();
myCollection->validate(); myCollection->validate();
} }
// Load deck statistics // Load deck statistics
// TODO: Code cleanup (Copypasted with slight changes from GameStateMenu.cpp) // TODO: Code cleanup (Copypasted with slight changes from GameStateMenu.cpp)
char buffer[512]; char buffer[512];
DeckStats * stats = DeckStats::GetInstance(); DeckStats * stats = DeckStats::GetInstance();
stw.aiDeckNames.clear(); stw.aiDeckNames.clear();
stw.aiDeckStats.clear(); stw.aiDeckStats.clear();
sprintf(buffer, "stats/player_deck%i.txt", deckid); sprintf(buffer, "stats/player_deck%i.txt", deckid);
string deckstats = options.profileFile(buffer); string deckstats = options.profileFile(buffer);
if(fileExists(deckstats.c_str())){
stats->load(deckstats.c_str());
stw.percentVictories = stats->percentVictories();
stw.gamesPlayed = stats->nbGames();
// Detailed deck statistics against AI
int found = 1;
int nbDecks = 0;
while (found){
found = 0;
char buffer[512];
char smallDeckName[512];
//char deckDesc[512];
sprintf(buffer, "%s/deck%i.txt",RESPATH"/ai/baka",nbDecks+1);
if(fileExists(buffer)){
MTGDeck * mtgd = NEW MTGDeck(buffer,NULL,1);
found = 1;
nbDecks++;
sprintf(smallDeckName, "%s_deck%i","ai_baka",nbDecks); if(fileExists(deckstats.c_str())){
DeckStat* deckStat = stats->getDeckStat(string(smallDeckName)); stats->load(deckstats.c_str());
stw.percentVictories = stats->percentVictories();
if ((deckStat != NULL) && (deckStat->nbgames>0)) { stw.gamesPlayed = stats->nbGames();
int percentVictories = stats->percentVictories(string(smallDeckName));
stw.aiDeckNames.push_back(string(mtgd->meta_name));
stw.aiDeckStats.push_back(deckStat);
}
delete mtgd; // Detailed deck statistics against AI
int found = 1;
int nbDecks = 0;
while (found){
found = 0;
char buffer[512];
char smallDeckName[512];
//char deckDesc[512];
sprintf(buffer, "%s/deck%i.txt",RESPATH"/ai/baka",nbDecks+1);
if(fileExists(buffer)){
MTGDeck * mtgd = NEW MTGDeck(buffer,NULL,1);
found = 1;
nbDecks++;
sprintf(smallDeckName, "%s_deck%i","ai_baka",nbDecks);
DeckStat* deckStat = stats->getDeckStat(string(smallDeckName));
if ((deckStat != NULL) && (deckStat->nbgames>0)) {
int percentVictories = stats->percentVictories(string(smallDeckName));
stw.aiDeckNames.push_back(string(mtgd->meta_name));
stw.aiDeckStats.push_back(deckStat);
} }
delete mtgd;
} }
} else { }
stw.gamesPlayed = 0; } else {
stw.percentVictories = 0; stw.gamesPlayed = 0;
} stw.percentVictories = 0;
}
myDeck->Sort(WSrcCards::SORT_ALPHA); myDeck->Sort(WSrcCards::SORT_ALPHA);
SAFE_DELETE(filterMenu); SAFE_DELETE(filterMenu);
rebuildFilters(); rebuildFilters();
@@ -1433,10 +1441,10 @@ void GameStateDeckViewer::ButtonPressed(int controllerId, int controlId)
int deckIdNumber = controlId; int deckIdNumber = controlId;
int deckListSize = 0; int deckListSize = 0;
DeckManager *deckManager = DeckManager::GetInstance(); DeckManager *deckManager = DeckManager::GetInstance();
vector<int> * deckList; vector<DeckMetaData *> * deckList;
switch(controllerId){ switch(controllerId){
case 10: //Deck menu case MENU_DECK_SELECTION: //Deck menu
if (controlId == -1){ if (controlId == MENU_ITEM_CANCEL){
if(!mSwitching) if(!mSwitching)
mParent->DoTransition(TRANSITION_FADE,GAME_STATE_MENU); mParent->DoTransition(TRANSITION_FADE,GAME_STATE_MENU);
else else
@@ -1444,7 +1452,7 @@ void GameStateDeckViewer::ButtonPressed(int controllerId, int controlId)
mSwitching = false; mSwitching = false;
break; break;
} else if(controlId == -12){ // (PSY) Cheatmode: Complete the collection } else if(controlId == MENU_ITEM_CHEAT_MODE){ // (PSY) Cheatmode: Complete the collection
playerdata->collection->complete(); // Add the cards playerdata->collection->complete(); // Add the cards
playerdata->collection->save(); // Save the new collection playerdata->collection->save(); // Save the new collection
for(int i=0;i<setlist.size();i++){ // Update unlocked sets for(int i=0;i<setlist.size();i++){ // Update unlocked sets
@@ -1465,51 +1473,55 @@ void GameStateDeckViewer::ButtonPressed(int controllerId, int controlId)
mStage = STAGE_WAITING; mStage = STAGE_WAITING;
deckList = deckManager->getPlayerDeckOrderList(); deckList = deckManager->getPlayerDeckOrderList();
deckListSize = deckList->size(); deckListSize = deckList->size();
if (deckListSize > 0 && controlId < deckListSize) if (controlId == MENU_ITEM_NEW_DECK) // new deck option selected
deckIdNumber = deckList->at(controlId - 1); deckIdNumber = deckList->size() + 1;
else if (deckListSize > 0 && controlId <= deckListSize)
deckIdNumber = deckList->at(controlId - 1)->deckid;
else else
deckIdNumber = controlId; deckIdNumber = controlId;
loadDeck(deckIdNumber); loadDeck(deckIdNumber);
mStage = STAGE_WAITING; mStage = STAGE_WAITING;
deckNum = controlId; deckNum = controlId;
break; break;
case 11: //Save / exit menu
case MENU_DECK_BUILDER: //Save / exit menu
switch (controlId) switch (controlId)
{ {
case 0: case MENU_ITEM_SAVE_RETURN_MAIN_MENU:
saveDeck(); saveDeck();
mParent->DoTransition(TRANSITION_FADE,GAME_STATE_MENU); mParent->DoTransition(TRANSITION_FADE,GAME_STATE_MENU);
break; break;
case 1: case MENU_ITEM_SAVE_RENAME:
if(myDeck && myDeck->parent){ if(myDeck && myDeck->parent){
options.keypadStart(myDeck->parent->meta_name,&newDeckname); options.keypadStart(myDeck->parent->meta_name,&newDeckname);
options.keypadTitle("Rename deck"); options.keypadTitle("Rename deck");
} }
break; break;
case 2: case MENU_ITEM_SWITCH_DECKS_NO_SAVE:
updateDecks(); updateDecks();
mStage = STAGE_WELCOME; mStage = STAGE_WELCOME;
mSwitching = true; mSwitching = true;
break; break;
case 3: case MENU_ITEM_MAIN_MENU:
mParent->DoTransition(TRANSITION_FADE,GAME_STATE_MENU); mParent->DoTransition(TRANSITION_FADE,GAME_STATE_MENU);
break; break;
case 4: case MENU_ITEM_EDITOR_CANCEL:
mStage = STAGE_WAITING; mStage = STAGE_WAITING;
break; break;
case 22: case MENU_ITEM_FILTER_BY:
mStage = STAGE_FILTERS; mStage = STAGE_FILTERS;
if(!filterMenu) rebuildFilters(); if(!filterMenu) rebuildFilters();
filterMenu->Entering(JGE_BTN_NONE); filterMenu->Entering(JGE_BTN_NONE);
break; break;
} }
break; break;
case 2:
switch (controlId){ case MENU_CARD_PURCHASE: // Yes/ No sub menu.
case 20: switch (controlId){
case MENU_ITEM_YES:
{ {
MTGCard * card = cardIndex[2]; MTGCard * card = cardIndex[2];
if (card){ if (card){
@@ -1519,15 +1531,15 @@ void GameStateDeckViewer::ButtonPressed(int controllerId, int controlId)
pricelist->setPrice(card->getMTGId(),price); pricelist->setPrice(card->getMTGId(),price);
playerdata->collection->remove(card->getMTGId()); playerdata->collection->remove(card->getMTGId());
displayed_deck->Remove(card,1); displayed_deck->Remove(card,1);
displayed_deck->validate(); displayed_deck->validate();
stw.needUpdate = true; stw.needUpdate = true;
loadIndexes(); loadIndexes();
} }
} }
case 21: case MENU_ITEM_NO:
subMenu->Close(); subMenu->Close();
break; break;
} }
} }
} }

View File

@@ -21,7 +21,7 @@
#if defined (WIN32) || defined (LINUX) #if defined (WIN32) || defined (LINUX)
#include <time.h> #include <time.h>
#endif #endif
enum ENUM_DUEL_STATE enum ENUM_DUEL_STATE
{ {
DUEL_STATE_START, DUEL_STATE_START,
@@ -86,15 +86,28 @@ void GameStateDuel::Start()
menu = NULL; menu = NULL;
int decksneeded = 0; int decksneeded = 0;
for (int i = 0; i<2; i ++){ for (int i = 0; i<2; i ++){
if (mParent->players[i] == PLAYER_TYPE_HUMAN){ if (mParent->players[i] == PLAYER_TYPE_HUMAN){
decksneeded = 1; decksneeded = 1;
deckmenu = NEW SimpleMenu(DUEL_MENU_CHOOSE_DECK, this, Constants::MENU_FONT, 35, 25, "Choose a Deck"); deckmenu = NEW SimpleMenu(DUEL_MENU_CHOOSE_DECK, this, Constants::MENU_FONT, 35, 25, "Choose a Deck");
DeckManager *deckManager = DeckManager::GetInstance(); DeckManager *deckManager = DeckManager::GetInstance();
int nbDecks = fillDeckMenu( deckManager->getPlayerDeckOrderList(), deckmenu, options.profileFile()); vector<DeckMetaData *> playerDeckList = getValidDeckMetaData( options.profileFile() );
if (nbDecks) decksneeded = 0; int nbDecks = playerDeckList.size();
if (nbDecks)
{
decksneeded = 0;
if (nbDecks > 1 )
deckmenu->Add( MENUITEM_RANDOM_PLAYER, "Random", "Play with a random deck." );
}
renderDeckMenu( deckmenu, playerDeckList );
// save the changes to the player deck list maintained in DeckManager
deckManager->updateMetaDataList( &playerDeckList, false);
playerDeckList.clear();
break; break;
} }
} }
@@ -105,14 +118,14 @@ void GameStateDuel::Start()
Translator * t = Translator::GetInstance(); Translator * t = Translator::GetInstance();
map<string,string>::iterator it = t->deckValues.find("Create your Deck!"); map<string,string>::iterator it = t->deckValues.find("Create your Deck!");
if (it != t->deckValues.end()) if (it != t->deckValues.end())
deckmenu->Add(-1,_("Create your Deck!").c_str(), it->second); deckmenu->Add( MENUITEM_NEW_DECK, _("Create your Deck!").c_str(), it->second);
else else
deckmenu->Add(-1,_("Create your Deck!").c_str(),"Highly recommended to get\nthe full Wagic experience!"); deckmenu->Add( MENUITEM_NEW_DECK, _("Create your Deck!").c_str(),"Highly recommended to get\nthe full Wagic experience!");
premadeDeck = true; premadeDeck = true;
fillDeckMenu(deckmenu,RESPATH"/player/premade"); fillDeckMenu(deckmenu,RESPATH"/player/premade");
} }
deckmenu->Add(-1,_("New Deck...").c_str()); deckmenu->Add( MENUITEM_NEW_DECK, _("New Deck...").c_str());
deckmenu->Add(-2, "Main Menu", "Return to Main Menu" ); deckmenu->Add( MENUITEM_MAIN_MENU, "Main Menu", "Return to Main Menu" );
} }
for (int i = 0; i < 2; ++i){ for (int i = 0; i < 2; ++i){
@@ -122,8 +135,8 @@ void GameStateDuel::Start()
} }
void GameStateDuel::loadPlayer(int playerId, int decknb, int isAI){ void GameStateDuel::loadPlayer(int playerId, int decknb, int isAI){
if (decknb){ if (decknb) {
if (!isAI){ //Human Player if (!isAI) { //Human Player
char deckFile[255]; char deckFile[255];
if(premadeDeck) if(premadeDeck)
sprintf(deckFile, RESPATH"/player/premade/deck%i.txt",decknb); sprintf(deckFile, RESPATH"/player/premade/deck%i.txt",decknb);
@@ -135,14 +148,16 @@ void GameStateDuel::loadPlayer(int playerId, int decknb, int isAI){
deck[playerId] = NEW MTGPlayerCards(tempDeck); deck[playerId] = NEW MTGPlayerCards(tempDeck);
delete tempDeck; delete tempDeck;
mPlayers[playerId] = NEW HumanPlayer(deck[playerId],deckFile, deckFileSmall); mPlayers[playerId] = NEW HumanPlayer(deck[playerId],deckFile, deckFileSmall);
}else{ //AI Player, chose deck }
else { //AI Player, chose deck
AIPlayerFactory playerCreator; AIPlayerFactory playerCreator;
Player * opponent = NULL; Player * opponent = NULL;
if (playerId == 1) opponent = mPlayers[0]; if (playerId == 1) opponent = mPlayers[0];
mPlayers[playerId] = playerCreator.createAIPlayer(mParent->collection,opponent,decknb); mPlayers[playerId] = playerCreator.createAIPlayer(mParent->collection,opponent,decknb);
deck[playerId] = mPlayers[playerId]->game; deck[playerId] = mPlayers[playerId]->game;
} }
}else{ //Random AI deck }
else { //Random AI deck
AIPlayerFactory playerCreator; AIPlayerFactory playerCreator;
Player * opponent = NULL; Player * opponent = NULL;
if (playerId == 1) opponent = mPlayers[0]; if (playerId == 1) opponent = mPlayers[0];
@@ -221,12 +236,13 @@ bool GameStateDuel::MusicExist(string FileName){
void GameStateDuel::ensureOpponentMenu(){ void GameStateDuel::ensureOpponentMenu(){
if (!opponentMenu){ if (!opponentMenu){
opponentMenu = NEW SimpleMenu(DUEL_MENU_CHOOSE_OPPONENT, this, Constants::MENU_FONT, 35, 25, "Choose Opponent"); opponentMenu = NEW SimpleMenu(DUEL_MENU_CHOOSE_OPPONENT, this, Constants::MENU_FONT, 35, 25, "Choose Opponent");
opponentMenu->Add(0,"Random"); opponentMenu->Add( MENUITEM_RANDOM_AI, "Random");
if (options[Options::EVILTWIN_MODE_UNLOCKED].number) if (options[Options::EVILTWIN_MODE_UNLOCKED].number)
opponentMenu->Add(-1,"Evil Twin", "Can you play against yourself?"); opponentMenu->Add( MENUITEM_EVIL_TWIN, "Evil Twin", "Can you play against yourself?");
DeckManager * deckManager = DeckManager::GetInstance(); DeckManager * deckManager = DeckManager::GetInstance();
fillDeckMenu( deckManager->getAIDeckOrderList(), opponentMenu, RESPATH"/ai/baka", "ai_baka", mPlayers[0]); vector<DeckMetaData* > opponentDeckList = fillDeckMenu( opponentMenu, RESPATH"/ai/baka", "ai_baka", mPlayers[0]);
opponentMenu->Add(-2,"Cancel", "Choose a different player deck"); deckManager->updateMetaDataList(&opponentDeckList, true);
opponentMenu->Add( MENUITEM_CANCEL, "Cancel", "Choose a different player deck");
} }
} }
@@ -368,7 +384,7 @@ void GameStateDuel::Update(float dt)
menu->Add(14,"Mulligan"); menu->Add(14,"Mulligan");
} }
//END almosthumane - mulligan //END almosthumane - mulligan
menu->Add(12,"Back to main menu"); menu->Add(12, "Back to main menu");
menu->Add(13, "Cancel"); menu->Add(13, "Cancel");
} }
mGamePhase = DUEL_STATE_MENU; mGamePhase = DUEL_STATE_MENU;
@@ -492,15 +508,15 @@ void GameStateDuel::ButtonPressed(int controllerId, int controlId) {
case DUEL_MENU_CHOOSE_OPPONENT: case DUEL_MENU_CHOOSE_OPPONENT:
{ {
switch(controlId){ switch(controlId){
case 0: case MENUITEM_RANDOM_AI:
loadPlayer(1); loadPlayer(1);
opponentMenu->Close(); opponentMenu->Close();
mGamePhase = DUEL_STATE_CHOOSE_DECK2_TO_PLAY; mGamePhase = DUEL_STATE_CHOOSE_DECK2_TO_PLAY;
break; break;
default: default:
// cancel option. return to player deck selection // cancel option. return to player deck selection
if (controlId == -2) if (controlId == MENUITEM_CANCEL)
{ {
opponentMenu->Close(); opponentMenu->Close();
deckmenu->Close(); deckmenu->Close();
@@ -508,8 +524,8 @@ void GameStateDuel::ButtonPressed(int controllerId, int controlId) {
mGamePhase = DUEL_MENU_GAME_MENU; mGamePhase = DUEL_MENU_GAME_MENU;
break; break;
} }
else if ( controlId != -1 && aiDeckSize > 0) // evil twin else if ( controlId != MENUITEM_EVIL_TWIN && aiDeckSize > 0) // evil twin
deckNumber = deckManager->getAIDeckOrderList()->at( controlId - 1 ); deckNumber = deckManager->getAIDeckOrderList()->at( controlId - 1 )->deckid;
loadPlayer(1,deckNumber,1); loadPlayer(1,deckNumber,1);
OpponentsDeckid=deckNumber; OpponentsDeckid=deckNumber;
@@ -521,9 +537,18 @@ void GameStateDuel::ButtonPressed(int controllerId, int controlId) {
} }
case DUEL_MENU_CHOOSE_DECK: case DUEL_MENU_CHOOSE_DECK:
{ {
if (controlId == -2 ) // user clicked on "Cancel" if ( controlId == MENUITEM_RANDOM_PLAYER ) // Random Player Deck Selection
{
vector<DeckMetaData *> * playerDeckList = deckManager->getPlayerDeckOrderList();
deckNumber = playerDeckList->at(WRand() * 1001 % (playerDeckList->size()) )->deckid;
loadPlayer( 0, deckNumber );
deckmenu->Close();
mGamePhase = DUEL_STATE_CHOOSE_DECK2_TO_PLAY;
break;
}
else if (controlId == MENUITEM_MAIN_MENU ) // user clicked on "Cancel"
{ {
if ( deckmenu) if (deckmenu)
deckmenu->Close(); deckmenu->Close();
mGamePhase = DUEL_STATE_BACK_TO_MAIN_MENU; mGamePhase = DUEL_STATE_BACK_TO_MAIN_MENU;
break; break;
@@ -533,9 +558,9 @@ void GameStateDuel::ButtonPressed(int controllerId, int controlId) {
return; return;
} }
if (mGamePhase == DUEL_STATE_CHOOSE_DECK1){ if (mGamePhase == DUEL_STATE_CHOOSE_DECK1){
vector<int> * playerDeck = deckManager->getPlayerDeckOrderList(); vector<DeckMetaData *> * playerDeck = deckManager->getPlayerDeckOrderList();
if ( !premadeDeck && controlId > 0 ) if ( !premadeDeck && controlId > 0 )
deckNumber = playerDeck->at( controlId - 1 ); deckNumber = playerDeck->at( controlId - 1 )->deckid;
loadPlayer(0,deckNumber); loadPlayer(0,deckNumber);
deckmenu->Close(); deckmenu->Close();
mGamePhase = DUEL_STATE_CHOOSE_DECK1_TO_2; mGamePhase = DUEL_STATE_CHOOSE_DECK1_TO_2;

View File

@@ -311,7 +311,7 @@ void GameStateMenu::setLang(int id){
void GameStateMenu::loadLangMenu(){ void GameStateMenu::loadLangMenu(){
LOG("GameStateMenu::loadLangMenu"); LOG("GameStateMenu::loadLangMenu");
subMenuController = NEW SimpleMenu(103, this, Constants::MENU_FONT, 150,60); subMenuController = NEW SimpleMenu( MENU_LANGUAGE_SELECTION, this, Constants::MENU_FONT, 150,60);
if (!subMenuController) return; if (!subMenuController) return;
resetDirectory(); resetDirectory();
if (!mDip){ if (!mDip){
@@ -465,7 +465,7 @@ void GameStateMenu::Update(float dt)
if (MENU_STATE_MINOR_NONE == (currentState & MENU_STATE_MINOR)) { if (MENU_STATE_MINOR_NONE == (currentState & MENU_STATE_MINOR)) {
if (!hasChosenGameType){ if (!hasChosenGameType){
currentState = MENU_STATE_MAJOR_SUBMENU; currentState = MENU_STATE_MAJOR_SUBMENU;
subMenuController = NEW SimpleMenu(102, this, Constants::MENU_FONT, 150,60); subMenuController = NEW SimpleMenu( MENU_FIRST_DUEL_SUBMENU, this, Constants::MENU_FONT, 150,60);
if (subMenuController){ if (subMenuController){
subMenuController->Add(SUBMENUITEM_CLASSIC,"Classic"); subMenuController->Add(SUBMENUITEM_CLASSIC,"Classic");
if (options[Options::MOMIR_MODE_UNLOCKED].number) if (options[Options::MOMIR_MODE_UNLOCKED].number)
@@ -637,7 +637,7 @@ WFont * mFont = resources.GetWFont(Constants::MENU_FONT);
OutputDebugString(buf); OutputDebugString(buf);
#endif #endif
switch (controllerId){ switch (controllerId){
case 103: case MENU_LANGUAGE_SELECTION:
setLang(controlId); setLang(controlId);
resources.reloadWFonts(); // Fix for choosing Chinese language at first time. resources.reloadWFonts(); // Fix for choosing Chinese language at first time.
subMenuController->Close(); subMenuController->Close();
@@ -651,7 +651,7 @@ WFont * mFont = resources.GetWFont(Constants::MENU_FONT);
switch (controlId) switch (controlId)
{ {
case MENUITEM_PLAY: case MENUITEM_PLAY:
subMenuController = NEW SimpleMenu(102, this, Constants::MENU_FONT, 150,60); subMenuController = NEW SimpleMenu( MENU_FIRST_DUEL_SUBMENU, this, Constants::MENU_FONT, 150,60);
if (subMenuController){ if (subMenuController){
subMenuController->Add(SUBMENUITEM_1PLAYER,"1 Player"); subMenuController->Add(SUBMENUITEM_1PLAYER,"1 Player");
// TODO Put 2 players mode back // TODO Put 2 players mode back

View File

@@ -180,3 +180,46 @@ u32 ramAvailable (void)
return size; return size;
} }
string& trim(string &str)
{
int i,j,start,end;
//ltrim
for (i=0; (str[i]!=0 && str[i]<=32); )
i++;
start=i;
//rtrim
for(i=0,j=0; str[i]!=0; i++)
j = ((str[i]<=32)? j+1 : 0);
end=i-j;
str = str.substr(start,end-start);
return str;
}
string& ltrim(string &str)
{
int i,start;
for (i=0; (str[i]!=0 && str[i]<=32); )
i++;
start=i;
str = str.substr(start,str.length()-start);
return str;
}
string& rtrim(string &str)
{
int i,j,end;
for(i=0,j=0; str[i]!=0; i++)
j = ((str[i]<=32)? j+1 : 0);
end=i-j;
str = str.substr(0,end);
return str;
}