- Added a way to name and describe AI Decks. Let's find cool names and descriptions :)
This commit is contained in:
wagic.the.homebrew@gmail.com
2009-05-25 12:43:58 +00:00
parent fc2ae93367
commit ee58109449
12 changed files with 100 additions and 36 deletions

View File

@@ -272,22 +272,24 @@ void GameStateDuel::Update(float dt)
char deckDesc[512];
sprintf(buffer, RESPATH"/ai/baka/deck%i.txt",nbAIDecks+1);
if(fileExists(buffer)){
found = 1;
nbAIDecks++;
sprintf(aiSmallDeckName, "ai_baka_deck%i",nbAIDecks);
DeckStats * stats = DeckStats::GetInstance();
stats->load(mPlayers[0]);
int percentVictories = stats->percentVictories(string(aiSmallDeckName));
string difficulty;
if (percentVictories < 34){
difficulty = "(hard)";
}else if (percentVictories < 67){
difficulty = "";
}else{
difficulty = "(easy)";
}
sprintf(deckDesc, "Deck %i %s",nbAIDecks, _(difficulty).c_str());
opponentMenu->Add(nbAIDecks,deckDesc);
MTGDeck * mtgd = NEW MTGDeck(buffer,NULL,NULL,1);
found = 1;
nbAIDecks++;
sprintf(aiSmallDeckName, "ai_baka_deck%i",nbAIDecks);
DeckStats * stats = DeckStats::GetInstance();
stats->load(mPlayers[0]);
int percentVictories = stats->percentVictories(string(aiSmallDeckName));
string difficulty;
if (percentVictories < 34){
difficulty = "(hard)";
}else if (percentVictories < 67){
difficulty = "";
}else{
difficulty = "(easy)";
}
sprintf(deckDesc, "%s %s",mtgd->meta_name.c_str(), _(difficulty).c_str());
opponentMenu->Add(nbAIDecks,deckDesc,mtgd->meta_desc);
delete mtgd;
}
}
}

View File

@@ -327,16 +327,35 @@ MTGCard * MTGAllCards::getCardByName(string name){
MTGDeck::MTGDeck(const char * config_file, TexturesCache * cache, MTGAllCards * _allcards){
MTGDeck::MTGDeck(const char * config_file, TexturesCache * cache, MTGAllCards * _allcards, int meta_only){
mCache = cache;
total_cards = 0;
allcards = _allcards;
filename = config_file;
size_t slash = filename.find_last_of("/");
size_t dot = filename.find(".");
meta_name = filename.substr(slash+1,dot-slash-1);
std::ifstream file(config_file);
std::string s;
if(file){
while(std::getline(file,s)){
if (!s.size()) continue;
if (s[0] == '#'){
size_t found = s.find("NAME:");
if ( found != string::npos){
meta_name = s.substr(found+5);
continue;
}
found = s.find("DESC:");
if ( found != string::npos){
if (meta_desc.size()) meta_desc.append("\n");
meta_desc.append(s.substr(found+5));
continue;
}
continue;
}
if (meta_only) break;
int cardnb = atoi(s.c_str());
if (cardnb){
add(cardnb);

View File

@@ -134,8 +134,10 @@ void SimpleMenu::Render(){
if (i > mCount-1) break;
if ((static_cast<SimpleMenuItem*>(mObjects[i]))->mY - LINE_HEIGHT * startId < mY + height - LINE_HEIGHT + 7)
{
if (static_cast<SimpleMenuItem*>(mObjects[i])->hasFocus())
mFont->SetColor(ARGB(255,255,255,0));
if (static_cast<SimpleMenuItem*>(mObjects[i])->hasFocus()){
GameApp::CommonRes->GetJLBFont(Constants::MAIN_FONT)->DrawString(static_cast<SimpleMenuItem*>(mObjects[i])->desc.c_str(),mX+mWidth+20,mY+15);
mFont->SetColor(ARGB(255,255,255,0));
}
else
mFont->SetColor(ARGB(255,255,255,255));
(static_cast<SimpleMenuItem*>(mObjects[i]))->RenderWithOffset(-LINE_HEIGHT*startId);
@@ -168,8 +170,10 @@ void SimpleMenu::Update(float dt){
}
}
void SimpleMenu::Add(int id, const char * text){
JGuiController::Add(NEW SimpleMenuItem(this, id, mFont, text, 0, mY + VMARGIN + mCount*LINE_HEIGHT, (mCount == 0)));
void SimpleMenu::Add(int id, const char * text,string desc){
SimpleMenuItem * smi = NEW SimpleMenuItem(this, id, mFont, text, 0, mY + VMARGIN + mCount*LINE_HEIGHT, (mCount == 0));
smi->desc = desc;
JGuiController::Add(smi);
if (mCount <= maxItems) mHeight += LINE_HEIGHT;
}