diff --git a/projects/mtg/include/GameOptions.h b/projects/mtg/include/GameOptions.h index ded131ff4..2540a4324 100644 --- a/projects/mtg/include/GameOptions.h +++ b/projects/mtg/include/GameOptions.h @@ -65,6 +65,7 @@ public: MOMIR_MODE_UNLOCKED, EVILTWIN_MODE_UNLOCKED, RANDOMDECK_MODE_UNLOCKED, + AWARD_COLLECTOR, LAST_NAMED, //Any option after this does not look up in optionNames. SET_UNLOCKS = LAST_NAMED + 1, //For sets. }; diff --git a/projects/mtg/include/GameStateAwards.h b/projects/mtg/include/GameStateAwards.h index d98fab923..1a26b755c 100644 --- a/projects/mtg/include/GameStateAwards.h +++ b/projects/mtg/include/GameStateAwards.h @@ -27,6 +27,7 @@ class GameStateAwards: public GameState, public JGuiListener public: GameStateAwards(GameApp* parent); bool enterSet(int setid); + bool enterStats(int option); virtual ~GameStateAwards(); virtual void Start(); diff --git a/projects/mtg/include/OptionItem.h b/projects/mtg/include/OptionItem.h index 2a9e26bd0..56942477c 100644 --- a/projects/mtg/include/OptionItem.h +++ b/projects/mtg/include/OptionItem.h @@ -149,7 +149,7 @@ public: virtual JQuad * getImage(); WSrcImage(string s); -private: +protected: string filename; }; @@ -242,14 +242,17 @@ protected: class WGuiAward: public WGuiItem{ public: - WGuiAward(int _id, string name, string _text); + WGuiAward(int _id, string name, string _text, string _details=""); virtual ~WGuiAward(); virtual void Render(); virtual bool Selectable() {return Visible();}; virtual bool Visible(); virtual int getId() {return id;}; virtual void Underlay(); + virtual void Overlay(); + protected: + string details; int id; string text; }; @@ -345,7 +348,7 @@ protected: class WGuiHeader:public WGuiItem{ public: WGuiHeader(string _displayValue): WGuiItem(_displayValue) {}; - + virtual bool Selectable() {return false;}; virtual void Render(); }; diff --git a/projects/mtg/include/PriceList.h b/projects/mtg/include/PriceList.h index 0afee7e77..aa5a06c14 100644 --- a/projects/mtg/include/PriceList.h +++ b/projects/mtg/include/PriceList.h @@ -19,7 +19,6 @@ class PriceList{ int save(); int getPrice(int cardId); int setPrice(int cardId, int price); - }; #endif diff --git a/projects/mtg/src/GameOptions.cpp b/projects/mtg/src/GameOptions.cpp index fe585e028..3cca5e2c8 100644 --- a/projects/mtg/src/GameOptions.cpp +++ b/projects/mtg/src/GameOptions.cpp @@ -50,6 +50,7 @@ const char * Options::optionNames[] = { "prx_rimom", "prx_eviltwin", "prx_rnddeck", + "aw_collector", }; int Options::getID(string name){ if(!name.size()) @@ -825,6 +826,7 @@ bool GameOptionAward::giveAward(){ achieved = time(NULL); viewed = false; number = 1; + options.save(); //TODO - Consider efficiency of this placement. return true; } diff --git a/projects/mtg/src/GameStateAwards.cpp b/projects/mtg/src/GameStateAwards.cpp index 37539833c..9aab7743f 100644 --- a/projects/mtg/src/GameStateAwards.cpp +++ b/projects/mtg/src/GameStateAwards.cpp @@ -9,6 +9,7 @@ #include "../include/Translate.h" #include "../include/OptionItem.h" #include "../include/GameOptions.h" +#include "../include/DeckDataWrapper.h" enum ENUM_AWARDS_STATE{ STATE_LISTVIEW, @@ -30,6 +31,7 @@ void GameStateAwards::End() SAFE_DELETE(listview); SAFE_DELETE(setSrc); + resources.Release(mBgTex); if(saveMe) options.save(); } @@ -38,6 +40,7 @@ void GameStateAwards::Start() char buf[256]; mState = STATE_LISTVIEW; options.checkProfile(); + //resources.ClearUnlocked(); //Last resort. menu = NULL; saveMe = options.newAward(); @@ -51,8 +54,6 @@ void GameStateAwards::Start() WGuiHeader * wgh = NEW WGuiHeader("Achievements"); listview->Add(wgh); - wgh = NEW WGuiHeader(""); - listview->Add(wgh); aw = NEW WGuiAward(Options::DIFFICULTY_MODE_UNLOCKED,"Difficulty Modes","Achieved a 66% victory ratio."); btn = NEW WGuiButton(aw,-103,Options::DIFFICULTY_MODE_UNLOCKED,this); @@ -70,7 +71,13 @@ void GameStateAwards::Start() btn = NEW WGuiButton(aw,-103,Options::RANDOMDECK_MODE_UNLOCKED,this); listview->Add(btn); - listview->Add(NEW WGuiHeader("Click a set for details.")); + aw = NEW WGuiAward(Options::AWARD_COLLECTOR,"Valuable Collection","Collection valued over 10,000c.","Collection Info"); + btn = NEW WGuiButton(aw,-103,Options::AWARD_COLLECTOR,this); + listview->Add(btn); + + wgh = NEW WGuiHeader(""); + listview->Add(wgh); + int locked = 0; for (int i = 0; i < setlist.size(); i++){ MTGSetInfo * si = setlist.getInfo(i); @@ -89,7 +96,7 @@ void GameStateAwards::Start() sprintf(buf,"%s: %i cards.",si->author.c_str(),si->totalCards()); - aw = NEW WGuiAward(Options::optionSet(i),si->getName(),buf); + aw = NEW WGuiAward(Options::optionSet(i),si->getName(),buf,"Card Spoiler"); btn = NEW WGuiButton(aw,-103,Options::optionSet(i),this); listview->Add(btn); } @@ -104,6 +111,8 @@ void GameStateAwards::Start() detailview = NULL; setSrc = NULL; showMenu = false; + mBgTex = resources.RetrieveTexture("awardback.jpg"); + mBg = resources.RetrieveQuad("awardback.jpg"); } void GameStateAwards::Create() @@ -117,8 +126,9 @@ void GameStateAwards::Destroy() void GameStateAwards::Render() { JRenderer * r = JRenderer::GetInstance(); - JQuad * bg = resources.RetrieveTempQuad("awardback.jpg"); - r->RenderQuad(bg, 0, 0); + r->ClearScreen(ARGB(0,0,0,0)); + if(mBg) + r->RenderQuad(mBg, 0, 0); switch(mState){ case STATE_LISTVIEW: @@ -202,7 +212,7 @@ bool GameStateAwards::enterSet(int setid){ spoiler->setWidth(SCREEN_WIDTH - 220); MTGAllCards * c = GameApp::collection; for(it = c->collection.begin();it!=c->collection.end();it++){ - if(it->second && it->second->setId == setid) + if(it->second && it->second->setId == setid && it->second->getId() >= 0) //Add only non-tokens from this set. spoiler->Add(NEW WGuiItem(it->second->name)); } spoiler->Entering(0); @@ -214,6 +224,93 @@ bool GameStateAwards::enterSet(int setid){ detailview->Entering(0); return true; } +bool GameStateAwards::enterStats(int option){ + if(option != Options::AWARD_COLLECTOR) + return false; + DeckDataWrapper* ddw = NEW DeckDataWrapper(NEW MTGDeck(options.profileFile(PLAYER_COLLECTION).c_str(), mParent->collection)); + if(!ddw) + return false; + + SAFE_DELETE(detailview); + detailview = NEW WGuiList("Details"); + + detailview->Add(NEW WGuiHeader("Collection Stats")); + detailview->Entering(0); + + //Discover favorite set and unique cards + int unique = 0; + + if(setlist.size() > 0){ + int * counts = (int*)calloc(setlist.size(),sizeof(int)); + int setid = -1; + int dupes = 0; + MTGCard * many = NULL; + MTGCard * costly = NULL; + MTGCard * strong = NULL; + MTGCard * tough = NULL; + map::iterator it; + + for (it = ddw->cards.begin(); it!=ddw->cards.end(); it++){ + MTGCard * c = it->first; + if(!c) + continue; + if(!c->isLand() && (many == NULL || it->second > dupes)){ + many = c; + dupes = it->second; + } + unique++; + counts[c->setId]+=it->second; + if(costly == NULL + || c->getManaCost()->getConvertedCost() > costly->getManaCost()->getConvertedCost()) + costly = c; + + if(c->isCreature() && (strong == NULL || c->getPower() > strong->getPower())) + strong = c; + + if(c->isCreature() && (tough == NULL || c->getToughness() > tough->getToughness())) + tough = c; + + } + for(int i=0;i counts[setid]) + setid = i; + } + free(counts); + + char buf[1024]; + sprintf(buf,_("Total Value: %ic").c_str(),ddw->totalPrice()); + detailview->Add(NEW WGuiItem(buf));//ddw->colors + + sprintf(buf,_("Total Cards (including duplicates): %i").c_str(),ddw->getCount()); + detailview->Add(NEW WGuiItem(buf));//ddw->colors + + sprintf(buf,_("Unique Cards: %i").c_str(),unique); + detailview->Add(NEW WGuiItem(buf)); + + if(many){ + sprintf(buf,_("Most Duplicates: %i (%s)").c_str(),dupes,many->getName().c_str()); + detailview->Add(NEW WGuiItem(buf)); + } + if(setid >= 0){ + sprintf(buf,_("Favorite Set: %s").c_str(),setlist[setid].c_str()); + detailview->Add(NEW WGuiItem(buf)); + } + if(costly){ + sprintf(buf,_("Highest Mana Cost: %i (%s)").c_str(),costly->getManaCost()->getConvertedCost(),costly->getName().c_str()); + detailview->Add(NEW WGuiItem(buf)); + } + if(strong){ + sprintf(buf,_("Most Powerful: %i (%s)").c_str(),strong->getPower(),strong->getName().c_str()); + detailview->Add(NEW WGuiItem(buf)); + } + if(tough){ + sprintf(buf,_("Toughest: %i (%s)").c_str(),tough->getToughness(),strong->getName().c_str()); + detailview->Add(NEW WGuiItem(buf)); + } + } + + return true; +} void GameStateAwards::ButtonPressed(int controllerId, int controlId) { if(controllerId == -102) @@ -232,12 +329,14 @@ void GameStateAwards::ButtonPressed(int controllerId, int controlId) break; } else if(controllerId == -103){ - //Enter "Details Mode" for that item. TODO: Details for non-sets - if(controlId >= Options::SET_UNLOCKS){ + int setid = controlId-Options::SET_UNLOCKS; + + if(controlId >= Options::SET_UNLOCKS && enterSet(setid)){ mState = STATE_DETAILS; mDetailItem = controlId; - int setid = controlId-Options::SET_UNLOCKS; - enterSet(setid); + + }else if(controlId == Options::AWARD_COLLECTOR && enterStats(controlId)){ + mState = STATE_DETAILS; } } } \ No newline at end of file diff --git a/projects/mtg/src/OptionItem.cpp b/projects/mtg/src/OptionItem.cpp index 9828f620a..ef676383e 100644 --- a/projects/mtg/src/OptionItem.cpp +++ b/projects/mtg/src/OptionItem.cpp @@ -46,7 +46,6 @@ void WGuiItem::Render(){ float fH = (height-mFont->GetHeight())/2; mFont->DrawString(_(displayValue).c_str(),x+(width/2),y+fH,JGETEXT_CENTER); } - WGuiItem::WGuiItem(string _display){ displayValue = _display; mFocus = false; @@ -1220,6 +1219,29 @@ void WGuiTabMenu::save(){ //WGuiAward +void WGuiAward::Overlay(){ + JRenderer * r = JRenderer::GetInstance(); + JLBFont * mFont = resources.GetJLBFont(Constants::OPTION_FONT); + mFont->SetScale(.8); + mFont->SetColor(getColor(WGuiColor::TEXT)); + + string s = _(details); + if(s.size()){ + float fW = mFont->GetStringWidth(s.c_str()); + float fH = mFont->GetHeight(); + + if(fH < 16) + fH = 18; + JQuad * button = resources.RetrieveQuad("iconspsp.png", (float)4*32, 0, 32, 32,"",RETRIEVE_NORMAL); + + r->FillRoundRect(5,10,fW+32,fH+2,2,getColor(WGuiColor::BACK)); + if(button) + r->RenderQuad(button, 10,12,0,.5,.5); + mFont->DrawString(s,30,16); + } + + mFont->SetScale(1); +} void WGuiAward::Underlay(){ char buf[1024]; JRenderer * r = JRenderer::GetInstance(); @@ -1278,13 +1300,14 @@ void WGuiAward::Render(){ } setHeight(myY-y); mFont->SetScale(1); + } -WGuiAward::WGuiAward(int _id, string name, string _text): WGuiItem(name){ +WGuiAward::WGuiAward(int _id, string name, string _text, string _details): WGuiItem(name){ id = _id; text = _text; height = 60; - + details = _details; } WGuiAward::~WGuiAward(){ GameOptionAward * goa = dynamic_cast(&options[id]); @@ -1379,7 +1402,6 @@ JQuad * WSrcImage::getImage(){ WSrcImage::WSrcImage(string s){ filename = s; } - //WSrcMTGSet WSrcMTGSet::WSrcMTGSet(int setid, float delay){ MTGAllCards * ac = GameApp::collection; diff --git a/projects/mtg/src/ShopItem.cpp b/projects/mtg/src/ShopItem.cpp index ad151b5cc..c6d0de68d 100644 --- a/projects/mtg/src/ShopItem.cpp +++ b/projects/mtg/src/ShopItem.cpp @@ -448,6 +448,12 @@ void ShopItems::ButtonPressed(int controllerId, int controlId){ } delete tempDeck; } + //Check if we just scored an award... + if(myCollection && myCollection->totalPrice() > 10000){ + GameOptionAward * goa = dynamic_cast(&options[Options::AWARD_COLLECTOR]); + if(goa) + goa->giveAward(); + } showPriceDialog = -1; }else{ //error not enough money