diff --git a/JGE/include/JLBFont.h b/JGE/include/JLBFont.h index bcb31f634..ee83bb3c7 100644 --- a/JGE/include/JLBFont.h +++ b/JGE/include/JLBFont.h @@ -53,7 +53,7 @@ public: /// @align - Text aligment. /// ////////////////////////////////////////////////////////////////////////// - void DrawString(const char *string, float x, float y, int align=JGETEXT_LEFT); + void DrawString(const char *string, float x, float y, int align=JGETEXT_LEFT, float leftOffset = 0, float width = 0); ////////////////////////////////////////////////////////////////////////// /// Rendering text to screen with syntax similar to printf of C/C++. diff --git a/JGE/src/JLBFont.cpp b/JGE/src/JLBFont.cpp index 61f11ea40..005fb753a 100644 --- a/JGE/src/JLBFont.cpp +++ b/JGE/src/JLBFont.cpp @@ -99,7 +99,7 @@ JLBFont::~JLBFont() } -void JLBFont::DrawString(const char *string, float x, float y, int align) +void JLBFont::DrawString(const char *string, float x, float y, int align, float leftOffset, float displayWidth) { char *p = (char*)string; float dx = x, dy = y; @@ -115,13 +115,41 @@ void JLBFont::DrawString(const char *string, float x, float y, int align) dx = floorf(dx); dy = floorf(dy); + float x0 = dx; int index; while (*p) { index = (*p - 32)+mBase; - mQuad->SetTextureRect(mXPos[index], mYPos[index], mCharWidth[index], mHeight); + float charWidth = mCharWidth[index]; + float delta = (charWidth + mTracking) * mScale; + float xPos = mXPos[index]; + if (leftOffset){ + if (leftOffset < 0){ + dx-=leftOffset; + leftOffset = 0; + continue; + }else if (leftOffset - delta > 0){ + leftOffset -= delta; + p++; + continue; + }else{ + xPos = mXPos[index] + (leftOffset); + delta -= leftOffset; + leftOffset = 0; + + charWidth = (delta/mScale) - mTracking; + } + } + else if (displayWidth){ + if (dx > x0+displayWidth) return; + if (dx+delta > x0+displayWidth) { + delta = x0 + displayWidth - dx; + charWidth = (delta/mScale) - mTracking; + } + } + mQuad->SetTextureRect(xPos, mYPos[index], charWidth , mHeight); mRenderer->RenderQuad(mQuad, dx, dy, mRotation, mScale, mScale); - dx += (mCharWidth[index] + mTracking) * mScale; + dx += delta; p++; } diff --git a/projects/mtg/Makefile b/projects/mtg/Makefile index 509ddc414..7491d5434 100644 --- a/projects/mtg/Makefile +++ b/projects/mtg/Makefile @@ -1,4 +1,4 @@ -OBJS = objs/ActionElement.o objs/ActionLayer.o objs/ActionStack.o objs/AIMomirPlayer.o objs/AIPlayer.o objs/AIStats.o objs/Blocker.o objs/CardGui.o objs/CardDescriptor.o objs/CardDisplay.o objs/ConstraintResolver.o objs/Counters.o objs/Credits.o objs/Damage.o objs/DamagerDamaged.o objs/DamageResolverLayer.o objs/DeckDataWrapper.o objs/DeckStats.o objs/DuelLayers.o objs/ExtraCost.o objs/GameApp.o objs/GameLauncher.o objs/GameObserver.o objs/GameOptions.o objs/GameStateDuel.o objs/GameStateMenu.o objs/GameStateOptions.o objs/GameStateShop.o objs/GuiCardsController.o objs/GuiLayers.o objs/Logger.o objs/ManaCost.o objs/ManaCostHybrid.o objs/MenuItem.o objs/MTGAbility.o objs/MTGCardInstance.o objs/MTGCard.o objs/MTGDeck.o objs/MTGDefinitions.o objs/MTGGamePhase.o objs/MTGGameZones.o objs/MTGGuiHand.o objs/MTGGuiPlay.o objs/MTGRules.o objs/OptionItem.o objs/PhaseRing.o objs/Player.o objs/PlayerData.o objs/PlayGuiObjectController.o objs/PlayGuiObject.o objs/PriceList.o objs/ShopItem.o objs/SimpleMenu.o objs/SimpleMenuItem.o objs/Subtypes.o objs/TargetChooser.o objs/TargetsList.o objs/TexturesCache.o objs/Token.o objs/Translate.o objs/utils.o objs/WEvent.o +OBJS = objs/ActionElement.o objs/ActionLayer.o objs/ActionStack.o objs/AIMomirPlayer.o objs/AIPlayer.o objs/AIStats.o objs/Blocker.o objs/CardGui.o objs/CardDescriptor.o objs/CardDisplay.o objs/ConstraintResolver.o objs/Counters.o objs/Credits.o objs/Damage.o objs/DamagerDamaged.o objs/DamageResolverLayer.o objs/DeckDataWrapper.o objs/DeckStats.o objs/DuelLayers.o objs/ExtraCost.o objs/GameApp.o objs/GameLauncher.o objs/GameObserver.o objs/GameOptions.o objs/GameStateDuel.o objs/GameStateMenu.o objs/GameStateOptions.o objs/GameStateShop.o objs/GuiCardsController.o objs/GuiLayers.o objs/Logger.o objs/ManaCost.o objs/ManaCostHybrid.o objs/MenuItem.o objs/MTGAbility.o objs/MTGCardInstance.o objs/MTGCard.o objs/MTGDeck.o objs/MTGDefinitions.o objs/MTGGamePhase.o objs/MTGGameZones.o objs/MTGGuiHand.o objs/MTGGuiPlay.o objs/MTGRules.o objs/OptionItem.o objs/PhaseRing.o objs/Player.o objs/PlayerData.o objs/PlayGuiObjectController.o objs/PlayGuiObject.o objs/PriceList.o objs/ShopItem.o objs/SimpleMenu.o objs/SimpleMenuItem.o objs/Subtypes.o objs/TargetChooser.o objs/TargetsList.o objs/TextScroller.o objs/TexturesCache.o objs/Token.o objs/Translate.o objs/utils.o objs/WEvent.o DEPS = $(patsubst objs/%.o, deps/%.d, $(OBJS)) RESULT = $(shell psp-config --psp-prefix 2> Makefile.cache) diff --git a/projects/mtg/bin/Res/sets/ICE/_cards.dat b/projects/mtg/bin/Res/sets/ICE/_cards.dat index 840c93d51..f450b80a5 100644 --- a/projects/mtg/bin/Res/sets/ICE/_cards.dat +++ b/projects/mtg/bin/Res/sets/ICE/_cards.dat @@ -344,6 +344,7 @@ mana={R} text=Pyroclasm deals 2 damage to each creature. id=2650 name=Pyroclasm +auto=damage:2 all(creature) rarity=U type=Sorcery mana={1}{R} diff --git a/projects/mtg/include/DeckDataWrapper.h b/projects/mtg/include/DeckDataWrapper.h index bb57b48bf..6b25367f6 100644 --- a/projects/mtg/include/DeckDataWrapper.h +++ b/projects/mtg/include/DeckDataWrapper.h @@ -42,6 +42,7 @@ class DeckDataWrapper{ void updateCounts(MTGCard * card = NULL, int removed = 0); void updateCurrentPosition(MTGCard * currentCard,int color = -1); int getCount(int color = -1); + int totalPrice(); void save(); }; diff --git a/projects/mtg/include/DeckStats.h b/projects/mtg/include/DeckStats.h index 8a4842e44..9451c47a1 100644 --- a/projects/mtg/include/DeckStats.h +++ b/projects/mtg/include/DeckStats.h @@ -31,6 +31,8 @@ public: void cleanStats(); ~DeckStats(); int percentVictories(string opponentsDeckFile); + int percentVictories(); + int nbGames(); }; #endif diff --git a/projects/mtg/include/GameStateMenu.h b/projects/mtg/include/GameStateMenu.h index 239481415..64ed07939 100644 --- a/projects/mtg/include/GameStateMenu.h +++ b/projects/mtg/include/GameStateMenu.h @@ -5,11 +5,13 @@ #include #include "../include/GameState.h" #include "../include/SimpleMenu.h" - +#include "../include/TextScroller.h" class GameStateMenu: public GameState, public JGuiListener { private: + TextScroller * scroller; + int scrollerSet; JGuiController* mGuiController; SimpleMenu* subMenuController; SimpleMenu* gameTypeMenu; @@ -38,7 +40,7 @@ class GameStateMenu: public GameState, public JGuiListener float angleMultiplier; float angleW; float yW; - + void fillScroller(); public: GameStateMenu(GameApp* parent); virtual ~GameStateMenu(); diff --git a/projects/mtg/include/MTGDeck.h b/projects/mtg/include/MTGDeck.h index cd5272383..c60d56a7f 100644 --- a/projects/mtg/include/MTGDeck.h +++ b/projects/mtg/include/MTGDeck.h @@ -12,6 +12,7 @@ #include "../include/GameApp.h" #include "../include/TexturesCache.h" + #include using std::string; diff --git a/projects/mtg/include/PriceList.h b/projects/mtg/include/PriceList.h index 45db65bb0..bc6b51478 100644 --- a/projects/mtg/include/PriceList.h +++ b/projects/mtg/include/PriceList.h @@ -6,6 +6,8 @@ #include "../include/MTGDeck.h" #include +class MTGAllCards; + class Price{ public: int cardid; diff --git a/projects/mtg/include/TextScroller.h b/projects/mtg/include/TextScroller.h new file mode 100644 index 000000000..2d9ae95c9 --- /dev/null +++ b/projects/mtg/include/TextScroller.h @@ -0,0 +1,33 @@ +#ifndef _TEXTSCROLLER_H_ +#define _TEXTSCROLLER_H_ + +class JLBFont; +#include +#include +#include +using namespace std; + +class TextScroller: public JGuiObject{ +private: + string mText; + string tempText; + JLBFont * mFont; + float mWidth; + float mSpeed; + float mX; + float mY; + float start; + int timer; + vector strings; + int currentId; + int mRandom; +public: + void Add(string text); + void Reset(); + void setRandom(int mode = 1); + TextScroller(JLBFont * font, float x, float y, float width, float speed = 30); + void Render(); + void Update(float dt); +}; + +#endif \ No newline at end of file diff --git a/projects/mtg/src/DeckDataWrapper.cpp b/projects/mtg/src/DeckDataWrapper.cpp index 81f6b58e5..e1ed6009c 100644 --- a/projects/mtg/src/DeckDataWrapper.cpp +++ b/projects/mtg/src/DeckDataWrapper.cpp @@ -1,5 +1,7 @@ +#include "../include/config.h" #include "../include/DeckDataWrapper.h" #include "../include/MTGDeck.h" +#include "../include/PriceList.h" DeckDataWrapper::DeckDataWrapper(MTGDeck * deck){ parent = deck; @@ -9,6 +11,7 @@ DeckDataWrapper::DeckDataWrapper(MTGDeck * deck){ for (int i = 0; i < deck->totalCards(); i++){ MTGCard * card = deck->_(i); Add(card); + } currentposition = 0; currentColor = -1; @@ -127,3 +130,16 @@ int DeckDataWrapper::getCount(int color){ if (color == -1) return colors[Constants::MTG_NB_COLORS]; return colors[color]; } + +int DeckDataWrapper::totalPrice(){ + int total = 0; + PriceList * pricelist = NEW PriceList(RESPATH"/settings/prices.dat",this->parent); + map::iterator it; + for ( it=cards.begin() ; it != cards.end(); it++ ){ + MTGCard * current = (*it).first; + int nb = (*it).second; + if (nb) total += pricelist->getPrice(current->getMTGId()); + } + delete pricelist; + return total; +} \ No newline at end of file diff --git a/projects/mtg/src/DeckStats.cpp b/projects/mtg/src/DeckStats.cpp index d4b1fdf52..4ded54042 100644 --- a/projects/mtg/src/DeckStats.cpp +++ b/projects/mtg/src/DeckStats.cpp @@ -39,6 +39,32 @@ int DeckStats::percentVictories(string opponentsFile){ } } +int DeckStats::nbGames(){ + int nbgames = 0; + map::iterator it; + for (it = stats.begin(); it != stats.end(); it++){ + DeckStat * d = it->second; + nbgames+=d->nbgames; + } + return nbgames; +} + + +int DeckStats::percentVictories(){ + int victories = 0; + int nbgames = 0; + map::iterator it; + for (it = stats.begin(); it != stats.end(); it++){ + DeckStat * d = it->second; + nbgames+=d->nbgames; + victories+=d->victories; + } + if (nbgames){ + return (victories * 100)/nbgames; + } + return 50; +} + void DeckStats::load(Player * player){ char filename[512]; sprintf(filename, RESPATH"/player/stats/%s.txt",player->deckFile.c_str()); diff --git a/projects/mtg/src/GameApp.cpp b/projects/mtg/src/GameApp.cpp index f54dc1252..62789348e 100644 --- a/projects/mtg/src/GameApp.cpp +++ b/projects/mtg/src/GameApp.cpp @@ -193,7 +193,6 @@ void GameApp::Destroy() SAFE_DELETE(music); Translator::EndInstance(); - SimpleMenu::destroy(); diff --git a/projects/mtg/src/GameStateMenu.cpp b/projects/mtg/src/GameStateMenu.cpp index 0112fcef9..1eb7da5f5 100644 --- a/projects/mtg/src/GameStateMenu.cpp +++ b/projects/mtg/src/GameStateMenu.cpp @@ -6,7 +6,10 @@ #include "../include/GameApp.h" #include "../include/MTGCard.h" #include "../include/Translate.h" - +#include "../include/DeckStats.h" +#include "../include/PlayerData.h" +#include "../include/utils.h" +#include "../include/DeckDataWrapper.h" static const char* GAME_VERSION = "WTH?! 0.6.2 - by WilLoW"; #define ALPHA_WARNING 0 @@ -69,6 +72,7 @@ GameStateMenu::GameStateMenu(GameApp* parent): GameState(parent) mVolume = 0; splashTex = NULL; splashQuad = NULL; + scroller = NULL; } GameStateMenu::~GameStateMenu() {} @@ -118,6 +122,8 @@ void GameStateMenu::Create() } currentState = MENU_STATE_MAJOR_LOADING_CARDS | MENU_STATE_MINOR_NONE; + scroller = NEW TextScroller(GameApp::CommonRes->GetJLBFont(Constants::MAIN_FONT), SCREEN_WIDTH/2 - 100 , SCREEN_HEIGHT-15,200); + } @@ -137,6 +143,7 @@ void GameStateMenu::Destroy() SAFE_DELETE(mMovingW); SAFE_DELETE(movingWTexture); SAFE_DELETE(bgTexture); + SAFE_DELETE(scroller); //SAFE_DELETE (bgMusic); } @@ -160,9 +167,73 @@ void GameStateMenu::Start(){ hasChosenGameType = 1; if (GameOptions::GetInstance()->values[OPTIONS_MOMIR_MODE_UNLOCKED].getIntValue()) hasChosenGameType =0; + + scrollerSet = 0; + + } +void GameStateMenu::fillScroller(){ + scroller->Reset(); + char buffer[4096]; + char buff2[512]; + + DeckStats * stats = DeckStats::GetInstance(); + int totalGames = 0; + for (int j=1; j<6; j++){ + sprintf(buffer, RESPATH"/player/stats/player_deck%i.txt",j); + if(fileExists(buffer)){ + stats->load(buffer); + int percentVictories = stats->percentVictories(); + + sprintf(buff2, "You have a %i%% victory ratio with Deck%i",percentVictories,j); + scroller->Add(buff2); + int nbGames = stats->nbGames(); + totalGames+= nbGames; + sprintf(buff2, "You have played %i games with Deck%i",nbGames,j); + scroller->Add(buff2); + } + } + if (totalGames){ + sprintf(buff2, "You have played a total of %i games",totalGames); + scroller->Add(buff2); + } + GameOptions * go = GameOptions::GetInstance(); + + if (!go->values[OPTIONS_DIFFICULTY_MODE_UNLOCKED].getIntValue()){ + scroller->Add("Unlock the difficult mode for more challenging duels!"); + } + if (!go->values[OPTIONS_MOMIR_MODE_UNLOCKED].getIntValue()){ + scroller->Add("Interested in playing Momir Basic? You'll have to unlock it first :)"); + } + + DeckDataWrapper* ddw = NEW DeckDataWrapper(NEW MTGDeck(RESPATH"/player/collection.dat", mParent->cache,mParent->collection)); + int totalCards = ddw->getCount(); + if (totalCards){ + sprintf(buff2, "You have a total of %i cards in your collection",totalCards); + scroller->Add(buff2); + + int estimatedValue = ddw->totalPrice(); + sprintf(buff2, "The shopkeeper would buy your entire collection for around %i credits",estimatedValue/2); + scroller->Add(buff2); + + sprintf(buff2, "The cards in your collection have an average value of %i credits",estimatedValue/totalCards); + scroller->Add(buff2); + } + delete ddw; + + PlayerData * playerdata = NEW PlayerData(mParent->collection); + sprintf(buff2, "You currently have %i credits",playerdata->credits); + delete playerdata; + scroller->Add(buff2); + + scroller->Add("Need more cards? Go to http://wololo.net/wagic"); + + scrollerSet = 1; + scroller->setRandom(); +} + int GameStateMenu::nextCardSet(){ int found = 0; if (!mDip){ @@ -245,6 +316,7 @@ void GameStateMenu::Update(float dt) } break; case MENU_STATE_MAJOR_MAINMENU : + if (!scrollerSet) fillScroller(); if (mGuiController!=NULL){ mGuiController->Update(dt); } @@ -307,6 +379,8 @@ void GameStateMenu::Update(float dt) angleW += angleMultiplier * dt; yW = yW + 5*dt + (yW - 55) *5*dt; } + + scroller->Update(dt); } @@ -391,10 +465,13 @@ void GameStateMenu::Render() mFont->SetScale(DEFAULT_MAIN_FONT_SCALE); mFont->SetColor(ARGB(128,255,255,255)); - mFont->DrawString(GAME_VERSION, SCREEN_WIDTH-10,SCREEN_HEIGHT-15,JGETEXT_RIGHT); - mFont->DrawString(nbcardsStr,10, SCREEN_HEIGHT-15); + mFont->DrawString(GAME_VERSION, SCREEN_WIDTH-10,5,JGETEXT_RIGHT); + mFont->DrawString(nbcardsStr,10, 5); mFont->SetScale(1.f); mFont->SetColor(ARGB(255,255,255,255)); + + scroller->Render(); + if (subMenuController){ subMenuController->Render(); } diff --git a/projects/mtg/src/MTGAbility.cpp b/projects/mtg/src/MTGAbility.cpp index 0c77f4c62..4fd24dc2c 100644 --- a/projects/mtg/src/MTGAbility.cpp +++ b/projects/mtg/src/MTGAbility.cpp @@ -938,12 +938,7 @@ void AbilityFactory::addAbilities(int _id, Spell * spell){ game->addObserver(NEW AConservator(_id,card)); break; } -/* case 1196: //Counterspell - { - Spell * starget = spell->getNextSpellTarget(); - if (starget) game->mLayers->stackLayer()->Fizzle(starget); - break; - } */ + case 1197: //Creature Bond { game->addObserver(NEW ACreatureBond(_id,card, card->target)); @@ -1593,34 +1588,12 @@ void AbilityFactory::addAbilities(int _id, Spell * spell){ } //Addons ICE-AGE Cards - case 2650: //Pyroclasm Need to be improved copied from hurricane with does 0 dammage to player and does 2 dammage to each creature - { - int x = 2; - for (int i = 0; i < 2 ; i++){ - game->mLayers->stackLayer()->addDamage(card, game->players[i], 0);// To be removed ? - for (int j = 0; j < game->players[i]->game->inPlay->nb_cards; j++){ - MTGCardInstance * current = game->players[i]->game->inPlay->cards[j]; - if (current->isACreature()){ - game->mLayers->stackLayer()->addDamage(card, current, x); - } - } - } - break; - } case 2660: //Word of Blasting { card->target->controller()->game->putInGraveyard(card->target); card->target->controller()->life-= card->target->getManaCost()->getConvertedCost(); break; } - case 2443: //Dark Banishing - { - if (card->target->hasColor(Constants::MTG_COLOR_BLACK)){ - }else{ - card->target->controller()->game->putInGraveyard(card->target); - } - break; - } case 2593: //Thoughtleech { game->addObserver(NEW AGiveLifeForTappedType (_id, card, "island")); diff --git a/projects/mtg/src/MTGDeck.cpp b/projects/mtg/src/MTGDeck.cpp index 1eea9e2eb..5049e18ed 100644 --- a/projects/mtg/src/MTGDeck.cpp +++ b/projects/mtg/src/MTGDeck.cpp @@ -257,6 +257,7 @@ int MTGAllCards::totalCards(){ return (total_cards); } + int MTGAllCards::readConfLine(std::ifstream &file, int set_id){ string s; diff --git a/projects/mtg/src/MTGGameZones.cpp b/projects/mtg/src/MTGGameZones.cpp index 98d75ad41..f998c89ef 100644 --- a/projects/mtg/src/MTGGameZones.cpp +++ b/projects/mtg/src/MTGGameZones.cpp @@ -379,6 +379,7 @@ void MTGLibrary::shuffleTopToBottom(int nbcards){ } } + MTGGameZone * MTGGameZone::stringToZone(string zoneName, MTGCardInstance * source,MTGCardInstance * target){ Player *p, *p2; GameObserver * g = GameObserver::GetInstance(); diff --git a/projects/mtg/src/TextScroller.cpp b/projects/mtg/src/TextScroller.cpp new file mode 100644 index 000000000..7d3e2fd19 --- /dev/null +++ b/projects/mtg/src/TextScroller.cpp @@ -0,0 +1,51 @@ +#include "../include/TextScroller.h" + +#include + +TextScroller::TextScroller(JLBFont * font, float x, float y, float width, float speed):JGuiObject(0){ + mFont = font; + mWidth = width; + mSpeed = speed; + mX = x; + mY = y; + start = -width; + timer = 0; + currentId = 0; + mRandom = 0; +} + +void TextScroller::setRandom(int mode){ + mRandom = mode; + if (mRandom && strings.size()){ + currentId = (rand() % strings.size()); + mText = strings[currentId]; + } +} + +void TextScroller::Add(string text){ + if (!strings.size()) mText = text; + strings.push_back(text); +} + +void TextScroller::Reset(){ + strings.clear(); +} + +void TextScroller::Update(float dt){ + start+=mSpeed*dt; + if (start > mFont->GetStringWidth(mText.c_str())){ + start = -mWidth; + if (mRandom){ + currentId = (rand() % strings.size()); + }else{ + currentId++; + if (currentId > strings.size()-1)currentId = 0; + } + mText = strings[currentId]; + } + +} + +void TextScroller::Render(){ + mFont->DrawString(mText.c_str(),mX,mY,JGETEXT_LEFT,start,mWidth); +} \ No newline at end of file diff --git a/projects/mtg/template.vcproj b/projects/mtg/template.vcproj index 81506693a..80841a4c7 100644 --- a/projects/mtg/template.vcproj +++ b/projects/mtg/template.vcproj @@ -484,6 +484,10 @@ RelativePath=".\src\TestSuiteAI.cpp" > + + @@ -781,6 +785,10 @@ RelativePath=".\include\TestSuiteAI.h" > + +