New descriptive text popup feature for deck selection
http://wololo.net/forum/viewtopic.php?f=13&t=2423
This commit is contained in:
@@ -26,25 +26,26 @@
|
||||
#define JGUI_REPEAT_DELAY 0.2
|
||||
|
||||
const int kCancelMenuID = -1;
|
||||
const int kInfoMenuID = -200;
|
||||
|
||||
class JGuiListener
|
||||
{
|
||||
public:
|
||||
virtual ~JGuiListener() {}
|
||||
public:
|
||||
virtual ~JGuiListener()
|
||||
{
|
||||
}
|
||||
virtual void ButtonPressed(int controllerId, int controlId) = 0;
|
||||
};
|
||||
|
||||
|
||||
class JGuiObject
|
||||
{
|
||||
protected:
|
||||
protected:
|
||||
static JGE* mEngine;
|
||||
|
||||
private:
|
||||
private:
|
||||
int mId;
|
||||
|
||||
|
||||
public:
|
||||
public:
|
||||
JGuiObject(int id);
|
||||
virtual ~JGuiObject();
|
||||
|
||||
@@ -57,21 +58,23 @@ class JGuiObject
|
||||
virtual bool ButtonPressed(); // action button pressed, return false to ignore
|
||||
|
||||
// Used for mouse support so that the GUI engine can found out which Object was selected
|
||||
virtual bool getTopLeft(int& top, int& left) {return false;};
|
||||
virtual bool getTopLeft(int& top, int& left)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
;
|
||||
|
||||
int GetId();
|
||||
};
|
||||
|
||||
|
||||
class JGuiController
|
||||
{
|
||||
protected:
|
||||
protected:
|
||||
static JGE* mEngine;
|
||||
|
||||
int mId;
|
||||
bool mActive;
|
||||
|
||||
|
||||
JButton mActionButton;
|
||||
JButton mCancelButton;
|
||||
int mCurr;
|
||||
@@ -91,7 +94,7 @@ class JGuiController
|
||||
JGuiListener* mListener;
|
||||
//int mKeyHoldTime;
|
||||
|
||||
public:
|
||||
public:
|
||||
vector<JGuiObject*> mObjects;
|
||||
int mCount;
|
||||
|
||||
@@ -114,8 +117,6 @@ class JGuiController
|
||||
bool IsActive();
|
||||
void SetActive(bool flag);
|
||||
|
||||
//void SetImageBackground(const JTexture* tex, int x, int y);
|
||||
//void SetShadingBackground(int x, int y, int width, int height, PIXEL_TYPE color);
|
||||
};
|
||||
|
||||
ostream& operator<<(ostream &out, const JGuiObject &j);
|
||||
|
||||
115
JGE/src/JGui.cpp
115
JGE/src/JGui.cpp
@@ -15,43 +15,37 @@ JGE* JGuiObject::mEngine = NULL;
|
||||
|
||||
JGE* JGuiController::mEngine = NULL;
|
||||
|
||||
|
||||
JGuiObject::JGuiObject(int id): mId(id)
|
||||
JGuiObject::JGuiObject(int id) :
|
||||
mId(id)
|
||||
{
|
||||
mEngine = JGE::GetInstance();
|
||||
}
|
||||
|
||||
|
||||
JGuiObject::~JGuiObject()
|
||||
{
|
||||
// JGERelease();
|
||||
}
|
||||
|
||||
|
||||
bool JGuiObject::Leaving(JButton key __attribute__((unused)))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool JGuiObject::ButtonPressed()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void JGuiObject::Entering()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
int JGuiObject::GetId()
|
||||
{
|
||||
return mId;
|
||||
}
|
||||
|
||||
|
||||
void JGuiObject::Update(float dt __attribute__((unused)))
|
||||
{
|
||||
}
|
||||
@@ -61,7 +55,8 @@ ostream& operator<<(ostream &out, const JGuiObject &j)
|
||||
return j.toString(out);
|
||||
}
|
||||
|
||||
JGuiController::JGuiController(int id, JGuiListener* listener) : mId(id), mListener(listener)
|
||||
JGuiController::JGuiController(int id, JGuiListener* listener) :
|
||||
mId(id), mListener(listener)
|
||||
{
|
||||
mEngine = JGE::GetInstance();
|
||||
|
||||
@@ -71,8 +66,8 @@ JGuiController::JGuiController(int id, JGuiListener* listener) : mId(id), mListe
|
||||
mCount = 0;
|
||||
mCurr = 0;
|
||||
|
||||
mCursorX = SCREEN_WIDTH/2;
|
||||
mCursorY = SCREEN_HEIGHT/2;
|
||||
mCursorX = SCREEN_WIDTH / 2;
|
||||
mCursorY = SCREEN_HEIGHT / 2;
|
||||
mShowCursor = false;
|
||||
|
||||
mActionButton = JGE_BTN_OK;
|
||||
@@ -83,31 +78,27 @@ JGuiController::JGuiController(int id, JGuiListener* listener) : mId(id), mListe
|
||||
mActive = true;
|
||||
}
|
||||
|
||||
|
||||
JGuiController::~JGuiController()
|
||||
{
|
||||
for (int i=0;i<mCount;i++)
|
||||
if (mObjects[i]!=NULL)
|
||||
delete mObjects[i];
|
||||
for (int i = 0; i < mCount; i++)
|
||||
if (mObjects[i] != NULL) delete mObjects[i];
|
||||
|
||||
}
|
||||
|
||||
|
||||
void JGuiController::Render()
|
||||
{
|
||||
for (int i=0;i<mCount;i++)
|
||||
if (mObjects[i]!=NULL)
|
||||
mObjects[i]->Render();
|
||||
for (int i = 0; i < mCount; i++)
|
||||
if (mObjects[i] != NULL) mObjects[i]->Render();
|
||||
}
|
||||
bool JGuiController::CheckUserInput(JButton key){
|
||||
bool JGuiController::CheckUserInput(JButton key)
|
||||
{
|
||||
|
||||
if (!mCount) return false;
|
||||
if (key == mActionButton)
|
||||
{
|
||||
if (mObjects[mCurr] != NULL && mObjects[mCurr]->ButtonPressed())
|
||||
if (!mObjects.empty() && mObjects[mCurr] != NULL && mObjects[mCurr]->ButtonPressed())
|
||||
{
|
||||
if (mListener != NULL)
|
||||
mListener->ButtonPressed(mId, mObjects[mCurr]->GetId());
|
||||
if (mListener != NULL) mListener->ButtonPressed(mId, mObjects[mCurr]->GetId());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -118,14 +109,19 @@ bool JGuiController::CheckUserInput(JButton key){
|
||||
mListener->ButtonPressed(mId, kCancelMenuID);
|
||||
}
|
||||
}
|
||||
else if (JGE_BTN_CANCEL == key)
|
||||
{
|
||||
if (mListener != NULL) mListener->ButtonPressed(mId, kInfoMenuID);
|
||||
}
|
||||
|
||||
else if ((JGE_BTN_LEFT == key) || (JGE_BTN_UP == key)) // || mEngine->GetAnalogY() < 64 || mEngine->GetAnalogX() < 64)
|
||||
{
|
||||
int n = mCurr;
|
||||
n--;
|
||||
if (n<0)
|
||||
if (n < 0)
|
||||
{
|
||||
if ((mStyle&JGUI_STYLE_WRAPPING))
|
||||
n = mCount-1;
|
||||
if ((mStyle & JGUI_STYLE_WRAPPING))
|
||||
n = mCount - 1;
|
||||
else
|
||||
n = 0;
|
||||
}
|
||||
@@ -141,12 +137,12 @@ bool JGuiController::CheckUserInput(JButton key){
|
||||
{
|
||||
int n = mCurr;
|
||||
n++;
|
||||
if (n>mCount-1)
|
||||
if (n > mCount - 1)
|
||||
{
|
||||
if ((mStyle&JGUI_STYLE_WRAPPING))
|
||||
if ((mStyle & JGUI_STYLE_WRAPPING))
|
||||
n = 0;
|
||||
else
|
||||
n = mCount-1;
|
||||
n = mCount - 1;
|
||||
}
|
||||
|
||||
if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(JGE_BTN_DOWN))
|
||||
@@ -162,15 +158,15 @@ bool JGuiController::CheckUserInput(JButton key){
|
||||
unsigned int distance2;
|
||||
unsigned int minDistance2 = -1;
|
||||
int n = mCurr;
|
||||
if(mEngine->GetLeftClickCoordinates(x, y))
|
||||
if (mEngine->GetLeftClickCoordinates(x, y))
|
||||
{
|
||||
for(int i = 0; i < mCount; i++)
|
||||
for (int i = 0; i < mCount; i++)
|
||||
{
|
||||
int top, left;
|
||||
if(mObjects[i]->getTopLeft(top, left))
|
||||
if (mObjects[i]->getTopLeft(top, left))
|
||||
{
|
||||
distance2 = (top-y)*(top-y) + (left-x)*(left-x);
|
||||
if(distance2 < minDistance2)
|
||||
distance2 = (top - y) * (top - y) + (left - x) * (left - x);
|
||||
if (distance2 < minDistance2)
|
||||
{
|
||||
minDistance2 = distance2;
|
||||
n = i;
|
||||
@@ -191,57 +187,70 @@ bool JGuiController::CheckUserInput(JButton key){
|
||||
}
|
||||
void JGuiController::Update(float dt)
|
||||
{
|
||||
for (int i=0;i<mCount;i++)
|
||||
if (mObjects[i]!=NULL)
|
||||
mObjects[i]->Update(dt);
|
||||
for (int i = 0; i < mCount; i++)
|
||||
if (mObjects[i] != NULL) mObjects[i]->Update(dt);
|
||||
|
||||
JButton key = mEngine->ReadButton();
|
||||
CheckUserInput(key);
|
||||
}
|
||||
|
||||
|
||||
void JGuiController::Add(JGuiObject* ctrl)
|
||||
{
|
||||
mObjects.push_back(ctrl);
|
||||
mCount++;
|
||||
}
|
||||
|
||||
void JGuiController::RemoveAt(int i){
|
||||
void JGuiController::RemoveAt(int i)
|
||||
{
|
||||
if (!mObjects[i]) return;
|
||||
mObjects.erase(mObjects.begin()+i);
|
||||
mObjects.erase(mObjects.begin() + i);
|
||||
delete mObjects[i];
|
||||
mCount--;
|
||||
if (mCurr == mCount)
|
||||
mCurr = 0;
|
||||
if (mCurr == mCount) mCurr = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
void JGuiController::Remove(int id)
|
||||
{
|
||||
for (int i=0;i<mCount;i++)
|
||||
for (int i = 0; i < mCount; i++)
|
||||
{
|
||||
if (mObjects[i] != NULL && mObjects[i]->GetId() == id)
|
||||
{
|
||||
if (mObjects[i] != NULL && mObjects[i]->GetId()==id) {
|
||||
RemoveAt(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void JGuiController::Remove(JGuiObject* ctrl)
|
||||
{
|
||||
for (int i=0;i<mCount;i++)
|
||||
for (int i = 0; i < mCount; i++)
|
||||
{
|
||||
if (mObjects[i] != NULL && mObjects[i] == ctrl)
|
||||
{
|
||||
if (mObjects[i] != NULL && mObjects[i]==ctrl) {
|
||||
RemoveAt(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void JGuiController::SetActionButton(JButton button) { mActionButton = button; }
|
||||
void JGuiController::SetStyle(int style) { mStyle = style; }
|
||||
void JGuiController::SetCursor(JSprite* cursor) { mCursor = cursor; }
|
||||
bool JGuiController::IsActive() { return mActive; }
|
||||
void JGuiController::SetActive(bool flag) { mActive = flag; }
|
||||
void JGuiController::SetActionButton(JButton button)
|
||||
{
|
||||
mActionButton = button;
|
||||
}
|
||||
void JGuiController::SetStyle(int style)
|
||||
{
|
||||
mStyle = style;
|
||||
}
|
||||
void JGuiController::SetCursor(JSprite* cursor)
|
||||
{
|
||||
mCursor = cursor;
|
||||
}
|
||||
bool JGuiController::IsActive()
|
||||
{
|
||||
return mActive;
|
||||
}
|
||||
void JGuiController::SetActive(bool flag)
|
||||
{
|
||||
mActive = flag;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
OBJS = objs/ActionElement.o objs/ActionLayer.o objs/ActionStack.o objs/AIMomirPlayer.o objs/AIPlayer.o objs/AIStats.o objs/AllAbilities.o objs/CardGui.o objs/CardDescriptor.o objs/CardDisplay.o objs/CardEffect.o objs/CardPrimitive.o objs/CardSelector.o objs/CardSelectorSingleton.o objs/Counters.o objs/Credits.o objs/Damage.o objs/DamagerDamaged.o objs/DeckDataWrapper.o objs/DeckEditorMenu.o objs/DeckMenu.o objs/DeckMenuItem.o objs/DeckMetaData.o objs/DeckStats.o objs/DuelLayers.o objs/Effects.o objs/ExtraCost.o objs/GameApp.o objs/GameLauncher.o objs/GameObserver.o objs/GameOptions.o objs/GameState.o objs/GameStateAwards.o objs/GameStateDeckViewer.o objs/GameStateDuel.o objs/DeckManager.o objs/GameStateMenu.o objs/GameStateOptions.o objs/GameStateShop.o objs/GameStateStory.o objs/GameStateTransitions.o objs/GuiAvatars.o objs/GuiBackground.o objs/GuiCardsController.o objs/GuiCombat.o objs/GuiFrame.o objs/GuiHand.o objs/GuiLayers.o objs/GuiMana.o objs/GuiPhaseBar.o objs/GuiPlay.o objs/GuiStatic.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/MTGPack.o objs/MTGRules.o objs/Navigator.o objs/OptionItem.o objs/PhaseRing.o objs/Player.o objs/PlayerData.o objs/PlayGuiObjectController.o objs/PlayGuiObject.o objs/Pos.o objs/PrecompiledHeader.o objs/PriceList.o objs/ReplacementEffects.o objs/Rules.o objs/SimpleMenu.o objs/SimpleMenuItem.o objs/SimplePad.o objs/StoryFlow.o objs/StyleManager.o objs/Subtypes.o objs/TargetChooser.o objs/TargetsList.o objs/TextScroller.o objs/ThisDescriptor.o objs/Token.o objs/Translate.o objs/TranslateKeys.o objs/Trash.o objs/utils.o objs/WEvent.o objs/WResourceManager.o objs/WCachedResource.o objs/WDataSrc.o objs/WGui.o objs/WFilter.o objs/Tasks.o objs/WFont.o
|
||||
OBJS = objs/ActionElement.o objs/ActionLayer.o objs/ActionStack.o objs/AIMomirPlayer.o objs/AIPlayer.o objs/AIStats.o objs/AllAbilities.o objs/CardGui.o objs/CardDescriptor.o objs/CardDisplay.o objs/CardEffect.o objs/CardPrimitive.o objs/CardSelector.o objs/CardSelectorSingleton.o objs/Counters.o objs/Credits.o objs/Damage.o objs/DamagerDamaged.o objs/DeckDataWrapper.o objs/DeckEditorMenu.o objs/DeckMenu.o objs/DeckMenuItem.o objs/DeckMetaData.o objs/DeckStats.o objs/DuelLayers.o objs/Effects.o objs/ExtraCost.o objs/GameApp.o objs/GameLauncher.o objs/GameObserver.o objs/GameOptions.o objs/GameState.o objs/GameStateAwards.o objs/GameStateDeckViewer.o objs/GameStateDuel.o objs/DeckManager.o objs/GameStateMenu.o objs/GameStateOptions.o objs/GameStateShop.o objs/GameStateStory.o objs/GameStateTransitions.o objs/GuiAvatars.o objs/GuiBackground.o objs/GuiCardsController.o objs/GuiCombat.o objs/GuiFrame.o objs/GuiHand.o objs/GuiLayers.o objs/GuiMana.o objs/GuiPhaseBar.o objs/GuiPlay.o objs/GuiStatic.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/MTGPack.o objs/MTGRules.o objs/Navigator.o objs/OptionItem.o objs/PhaseRing.o objs/Player.o objs/PlayerData.o objs/PlayGuiObjectController.o objs/PlayGuiObject.o objs/Pos.o objs/PrecompiledHeader.o objs/PriceList.o objs/ReplacementEffects.o objs/Rules.o objs/SimpleMenu.o objs/SimpleMenuItem.o objs/SimplePad.o objs/SimplePopup.o objs/StoryFlow.o objs/StyleManager.o objs/Subtypes.o objs/TargetChooser.o objs/TargetsList.o objs/TextScroller.o objs/ThisDescriptor.o objs/Token.o objs/Translate.o objs/TranslateKeys.o objs/Trash.o objs/utils.o objs/WEvent.o objs/WResourceManager.o objs/WCachedResource.o objs/WDataSrc.o objs/WGui.o objs/WFilter.o objs/Tasks.o objs/WFont.o
|
||||
DEPS = $(patsubst objs/%.o, deps/%.d, $(OBJS))
|
||||
|
||||
RESULT = $(shell psp-config --psp-prefix 2> Makefile.cache)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
A class for very simple menus structure
|
||||
*/
|
||||
A class for menus with a fixed layout
|
||||
*/
|
||||
#ifndef _DeckMenu_H_
|
||||
#define _DeckMenu_H_
|
||||
|
||||
@@ -10,14 +10,16 @@
|
||||
#include "DeckMetaData.h"
|
||||
#include "TextScroller.h"
|
||||
|
||||
class DeckMenu:public JGuiController{
|
||||
protected:
|
||||
class DeckMenu: public JGuiController
|
||||
{
|
||||
protected:
|
||||
|
||||
float mHeight, mWidth, mX, mY;
|
||||
float titleX, titleY, titleWidth;
|
||||
float descX, descY, descHeight, descWidth;
|
||||
float statsX, statsY, statsHeight, statsWidth;
|
||||
float avatarX, avatarY;
|
||||
float detailedInfoBoxX, detailedInfoBoxY;
|
||||
float starsOffsetX;
|
||||
|
||||
bool menuInitialized;
|
||||
@@ -40,11 +42,24 @@ class DeckMenu:public JGuiController{
|
||||
void initMenuItems();
|
||||
string getDescription();
|
||||
string getMetaInformation();
|
||||
DeckMetaData *selectedDeck;
|
||||
|
||||
public:
|
||||
public:
|
||||
TextScroller * scroller;
|
||||
bool autoTranslate;
|
||||
DeckMenu(int id, JGuiListener* listener, int fontId, const string _title = "", const float& mFontScale = 1.0f );
|
||||
|
||||
//used for detailed info button
|
||||
JQuad * pspIcons[8];
|
||||
JTexture * pspIconsTexture;
|
||||
DeckMetaData * getSelectedDeck();
|
||||
bool selectedDeckHasDetails();
|
||||
int selectedDeckId;
|
||||
bool showDetailsScreen;
|
||||
bool enableDetails;
|
||||
float selectionTargetY;
|
||||
bool closed;
|
||||
|
||||
DeckMenu(int id, JGuiListener* listener, int fontId, const string _title = "", const int& startIndex = 0, const float& mFontScale = 1.0f);
|
||||
~DeckMenu();
|
||||
|
||||
void Render();
|
||||
@@ -54,10 +69,7 @@ class DeckMenu:public JGuiController{
|
||||
void updateScroller();
|
||||
void RenderBackground();
|
||||
|
||||
float selectionTargetY;
|
||||
bool closed;
|
||||
static void destroy();
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,29 +1,32 @@
|
||||
#ifndef _DECKSTATS_H_
|
||||
#define _DECKSTATS_H_
|
||||
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "MTGDefinitions.h"
|
||||
#include <DeckDataWrapper.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Player;
|
||||
class GameObserver;
|
||||
|
||||
class DeckStat{
|
||||
class DeckStat
|
||||
{
|
||||
public:
|
||||
int nbgames;
|
||||
int victories;
|
||||
DeckStat(int _nbgames = 0 , int _victories = 0):nbgames(_nbgames),victories(_victories){};
|
||||
DeckStat(int _nbgames = 0, int _victories = 0);
|
||||
int percentVictories();
|
||||
};
|
||||
|
||||
class DeckStats{
|
||||
class DeckStats
|
||||
{
|
||||
protected:
|
||||
static DeckStats * mInstance;
|
||||
public:
|
||||
map<string, DeckStat *>stats;
|
||||
map<string, DeckStat *> stats;
|
||||
static DeckStats * GetInstance();
|
||||
void saveStats(Player * player, Player * opponent, GameObserver * game);
|
||||
void save(const char * filename);
|
||||
@@ -38,15 +41,19 @@ public:
|
||||
int nbGames();
|
||||
};
|
||||
|
||||
|
||||
class StatsWrapper {
|
||||
class StatsWrapper
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
StatsWrapper( int deckId );
|
||||
StatsWrapper(int deckId);
|
||||
StatsWrapper(string filename);
|
||||
~StatsWrapper();
|
||||
|
||||
void initStatistics(string deckstats);
|
||||
|
||||
// Stats parameters and status
|
||||
int mDeckId;
|
||||
int currentPage;
|
||||
int pageCount;
|
||||
bool needUpdate;
|
||||
@@ -70,18 +77,23 @@ public:
|
||||
float noLandsProbInTurn[Constants::STATS_FOR_TURNS];
|
||||
float noCreaturesProbInTurn[Constants::STATS_FOR_TURNS];
|
||||
|
||||
int countCardsPerCost[Constants::STATS_MAX_MANA_COST+1];
|
||||
int countCardsPerCostAndColor[Constants::STATS_MAX_MANA_COST+1][Constants::MTG_NB_COLORS+1];
|
||||
int countCreaturesPerCost[Constants::STATS_MAX_MANA_COST+1];
|
||||
int countCreaturesPerCostAndColor[Constants::STATS_MAX_MANA_COST+1][Constants::MTG_NB_COLORS+1];
|
||||
int countSpellsPerCost[Constants::STATS_MAX_MANA_COST+1];
|
||||
int countSpellsPerCostAndColor[Constants::STATS_MAX_MANA_COST+1][Constants::MTG_NB_COLORS+1];
|
||||
int countLandsPerColor[Constants::MTG_NB_COLORS+1];
|
||||
int countBasicLandsPerColor[Constants::MTG_NB_COLORS+1];
|
||||
int countNonLandProducersPerColor[Constants::MTG_NB_COLORS+1];
|
||||
int totalCostPerColor[Constants::MTG_NB_COLORS+1];
|
||||
int countCardsPerCost[Constants::STATS_MAX_MANA_COST + 1];
|
||||
int countCardsPerCostAndColor[Constants::STATS_MAX_MANA_COST + 1][Constants::MTG_NB_COLORS + 1];
|
||||
int countCreaturesPerCost[Constants::STATS_MAX_MANA_COST + 1];
|
||||
int countCreaturesPerCostAndColor[Constants::STATS_MAX_MANA_COST + 1][Constants::MTG_NB_COLORS + 1];
|
||||
int countSpellsPerCost[Constants::STATS_MAX_MANA_COST + 1];
|
||||
int countSpellsPerCostAndColor[Constants::STATS_MAX_MANA_COST + 1][Constants::MTG_NB_COLORS + 1];
|
||||
int countLandsPerColor[Constants::MTG_NB_COLORS + 1];
|
||||
int countBasicLandsPerColor[Constants::MTG_NB_COLORS + 1];
|
||||
int countNonLandProducersPerColor[Constants::MTG_NB_COLORS + 1];
|
||||
int totalCostPerColor[Constants::MTG_NB_COLORS + 1];
|
||||
int totalColoredSymbols;
|
||||
|
||||
void updateStats(string filename, MTGAllCards * collection);
|
||||
void updateStats(DeckDataWrapper *mtgDeck);
|
||||
int countCardsByType(const char * _type, DeckDataWrapper * myDeck);
|
||||
float noLuck(int n, int a, int x);
|
||||
|
||||
vector<string> aiDeckNames;
|
||||
vector<DeckStat*> aiDeckStats;
|
||||
};
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
#define NO_USER_ACTIVITY_SHOWCARD_DELAY 0.1
|
||||
|
||||
enum
|
||||
{
|
||||
{
|
||||
STAGE_TRANSITION_RIGHT = 0,
|
||||
STAGE_TRANSITION_LEFT = 1,
|
||||
STAGE_WAITING = 2,
|
||||
@@ -33,8 +33,7 @@ enum
|
||||
STAGE_WELCOME = 6,
|
||||
STAGE_MENU = 7,
|
||||
STAGE_FILTERS = 8
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
// TODO: need a better name for MENU_FIRST_MENU, this is reused for the 1st submenu of
|
||||
// available options in the duel menu
|
||||
@@ -47,10 +46,10 @@ enum
|
||||
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 )
|
||||
// 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 = kCancelMenuID,
|
||||
@@ -62,10 +61,10 @@ enum DECK_VIEWER_MENU_ITEMS
|
||||
MENU_ITEM_SAVE_AS_AI_DECK = 5,
|
||||
MENU_ITEM_YES = 20,
|
||||
MENU_ITEM_NO = 21,
|
||||
MENU_ITEM_FILTER_BY = 22
|
||||
MENU_ITEM_FILTER_BY = 22,
|
||||
MENUITEM_MORE_INFO = kInfoMenuID
|
||||
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
#define ALL_COLORS -1
|
||||
|
||||
@@ -139,7 +138,7 @@ public:
|
||||
void renderDeckBackground();
|
||||
void renderOnScreenMenu();
|
||||
virtual void renderCard(int id, float rotation);
|
||||
virtual void renderCard (int id);
|
||||
virtual void renderCard(int id);
|
||||
virtual void Render();
|
||||
int loadDeck(int deckid);
|
||||
void LoadDeckStatistics(int deckId);
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#ifndef _GAME_STATE_DUEL_H_
|
||||
#define _GAME_STATE_DUEL_H_
|
||||
|
||||
|
||||
#include "GameState.h"
|
||||
#include "SimpleMenu.h"
|
||||
#include "SimplePopup.h"
|
||||
#include "DeckMenu.h"
|
||||
#include "MTGDeck.h"
|
||||
#include "GameObserver.h"
|
||||
@@ -16,10 +16,9 @@ class TestSuite;
|
||||
class Credits;
|
||||
class Rules;
|
||||
|
||||
|
||||
class GameStateDuel: public GameState, public JGuiListener
|
||||
{
|
||||
private:
|
||||
private:
|
||||
#ifdef TESTSUITE
|
||||
TestSuite * testSuite;
|
||||
#endif
|
||||
@@ -32,6 +31,10 @@ class GameStateDuel: public GameState, public JGuiListener
|
||||
DeckMenu * deckmenu;
|
||||
DeckMenu * opponentMenu;
|
||||
SimpleMenu * menu;
|
||||
SimplePopup * popupScreen; // used for informational screens, modal
|
||||
static int selectedPlayerDeckId;
|
||||
static int selectedAIDeckId;
|
||||
|
||||
bool premadeDeck;
|
||||
int OpponentsDeckid;
|
||||
string musictrack;
|
||||
@@ -42,7 +45,7 @@ class GameStateDuel: public GameState, public JGuiListener
|
||||
void ensureOpponentMenu(); //loads the opponentMenu if it doesn't exist
|
||||
void initScroller();
|
||||
|
||||
public:
|
||||
public:
|
||||
GameStateDuel(GameApp* parent);
|
||||
virtual ~GameStateDuel();
|
||||
#ifdef TESTSUITE
|
||||
@@ -53,7 +56,7 @@ class GameStateDuel: public GameState, public JGuiListener
|
||||
virtual void End();
|
||||
virtual void Update(float dt);
|
||||
virtual void Render();
|
||||
void initRand (unsigned seed = 0);
|
||||
void initRand(unsigned seed = 0);
|
||||
|
||||
enum ENUM_DUEL_STATE_MENU_ITEM
|
||||
{
|
||||
@@ -63,11 +66,11 @@ class GameStateDuel: public GameState, public JGuiListener
|
||||
MENUITEM_RANDOM_AI = -12,
|
||||
MENUITEM_MAIN_MENU = -13,
|
||||
MENUITEM_EVIL_TWIN = -14,
|
||||
MENUITEM_MULLIGAN = -15
|
||||
MENUITEM_MULLIGAN = -15,
|
||||
MENUITEM_MORE_INFO = kInfoMenuID
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -11,23 +11,17 @@ class MTGPlayerCards;
|
||||
class MTGInPlay;
|
||||
class ManaPool;
|
||||
|
||||
class Player: public Damageable{
|
||||
protected:
|
||||
class Player: public Damageable
|
||||
{
|
||||
protected:
|
||||
ManaPool * manaPool;
|
||||
|
||||
public:
|
||||
public:
|
||||
enum ENUM_PLAY_MODE
|
||||
{
|
||||
MODE_TEST_SUITE,
|
||||
MODE_HUMAN,
|
||||
MODE_AI,
|
||||
MODE_TEST_SUITE, MODE_HUMAN, MODE_AI,
|
||||
};
|
||||
|
||||
|
||||
virtual void End();
|
||||
int typeAsTarget(){return TARGET_PLAYER;}
|
||||
const string getDisplayName() const;
|
||||
virtual int displayStack(){return 1;}
|
||||
JTexture * mAvatarTex;
|
||||
JQuad * mAvatar;
|
||||
int playMode;
|
||||
@@ -42,32 +36,62 @@ class Player: public Damageable{
|
||||
int castrestrictedcreature;
|
||||
int castrestrictedspell;
|
||||
MTGPlayerCards * game;
|
||||
int afterDamage();
|
||||
int poisoned();
|
||||
int damaged();
|
||||
int prevented();
|
||||
Player(MTGDeck * deck, string deckFile, string deckFileSmall);
|
||||
virtual ~Player();
|
||||
void unTapPhase();
|
||||
MTGInPlay * inPlay();
|
||||
ManaPool * getManaPool();
|
||||
void cleanupPhase();
|
||||
virtual int Act(float dt){return 0;};
|
||||
virtual int isAI(){return 0;};
|
||||
Player * opponent();
|
||||
int getId();
|
||||
JQuad * getIcon();
|
||||
string deckFile;
|
||||
string deckFileSmall;
|
||||
string deckName;
|
||||
|
||||
virtual int receiveEvent(WEvent * event){return 0;};
|
||||
virtual void Render(){};
|
||||
Player(MTGDeck * deck, string deckFile, string deckFileSmall);
|
||||
virtual ~Player();
|
||||
|
||||
virtual void End();
|
||||
virtual int displayStack()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
const string getDisplayName() const;
|
||||
int typeAsTarget()
|
||||
{
|
||||
return TARGET_PLAYER;
|
||||
}
|
||||
|
||||
int afterDamage();
|
||||
int poisoned();
|
||||
int damaged();
|
||||
int prevented();
|
||||
void unTapPhase();
|
||||
MTGInPlay * inPlay();
|
||||
ManaPool * getManaPool();
|
||||
void cleanupPhase();
|
||||
virtual int Act(float dt)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
virtual int isAI()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
Player * opponent();
|
||||
int getId();
|
||||
JQuad * getIcon();
|
||||
|
||||
virtual int receiveEvent(WEvent * event)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual void Render()
|
||||
{
|
||||
}
|
||||
|
||||
void loadAvatar(string file);
|
||||
};
|
||||
|
||||
class HumanPlayer: public Player{
|
||||
public:
|
||||
class HumanPlayer: public Player
|
||||
{
|
||||
public:
|
||||
HumanPlayer(MTGDeck * deck, string deckFile, string deckFileSmall);
|
||||
HumanPlayer(string deckFile);
|
||||
|
||||
|
||||
48
projects/mtg/include/SimplePopup.h
Normal file
48
projects/mtg/include/SimplePopup.h
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* SimplePopup.h
|
||||
* Created on: Nov 18, 2010
|
||||
*
|
||||
* Simple popup dialog box for displaying information only.
|
||||
*/
|
||||
|
||||
#ifndef SIMPLEPOPUP_H_
|
||||
#define SIMPLEPOPUP_H_
|
||||
|
||||
#pragma once
|
||||
#include <JGui.h>
|
||||
#include <JTypes.h>
|
||||
#include <WFont.h>
|
||||
#include <DeckMetaData.h>
|
||||
|
||||
class SimplePopup: public JGuiController
|
||||
{
|
||||
|
||||
private:
|
||||
float mHeight, mWidth, mX, mY;
|
||||
int mMaxLines;
|
||||
int mFontId;
|
||||
DeckMetaData * mDeckInformation;
|
||||
string mTitle;
|
||||
WFont *mTextFont;
|
||||
StatsWrapper *stw;
|
||||
|
||||
void drawHorzPole(float x, float y, float width);
|
||||
void drawVertPole(float x, float y, float height);
|
||||
|
||||
public:
|
||||
MTGAllCards * mCollection;
|
||||
bool autoTranslate;
|
||||
bool closed;
|
||||
|
||||
SimplePopup(int id, JGuiListener* listener, const int fontId, const char * _title = "", DeckMetaData* deckInfo = NULL, MTGAllCards * collection = NULL);
|
||||
~SimplePopup(void);
|
||||
void Render();
|
||||
void Update(DeckMetaData* deckMetaData);
|
||||
|
||||
string getDetailedInformation(string deckFilename);
|
||||
|
||||
void Update(float dt);
|
||||
void Close();
|
||||
};
|
||||
|
||||
#endif /* SIMPLEPOPUP_H_ */
|
||||
@@ -6,13 +6,13 @@
|
||||
#include "GameApp.h"
|
||||
#include <iomanip>
|
||||
|
||||
DeckEditorMenu::DeckEditorMenu(int id, JGuiListener* listener, int fontId, const char * _title, DeckDataWrapper *_selectedDeck,
|
||||
StatsWrapper *stats) :
|
||||
DeckEditorMenu::DeckEditorMenu(int id, JGuiListener* listener, int fontId, const char * _title, DeckDataWrapper *_selectedDeck, StatsWrapper *stats) :
|
||||
DeckMenu(id, listener, fontId, _title), selectedDeck(_selectedDeck), stw(stats)
|
||||
{
|
||||
backgroundName = "DeckEditorMenuBackdrop";
|
||||
|
||||
deckTitle = selectedDeck ? selectedDeck->parent->meta_name : "";
|
||||
enableDetails = false;
|
||||
|
||||
mX = 123;
|
||||
mY = 70;
|
||||
@@ -37,6 +37,7 @@ DeckEditorMenu::DeckEditorMenu(int id, JGuiListener* listener, int fontId, const
|
||||
|
||||
float scrollerWidth = 80;
|
||||
SAFE_DELETE(scroller); // need to delete the scroller init in the base class
|
||||
this->showDetailsScreen = false;
|
||||
scroller = NEW TextScroller(Fonts::MAIN_FONT, 40, 230, scrollerWidth, 100, 1, 1);
|
||||
|
||||
}
|
||||
@@ -56,8 +57,7 @@ void DeckEditorMenu::Render()
|
||||
mainFont->SetColor(currentColor);
|
||||
}
|
||||
|
||||
if (stw && selectedDeck)
|
||||
drawDeckStatistics();
|
||||
if (stw && selectedDeck) drawDeckStatistics();
|
||||
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ void DeckEditorMenu::drawDeckStatistics()
|
||||
|
||||
deckStatsString
|
||||
<< "------- Deck Summary -----" << endl
|
||||
<< "Cards: "<< selectedDeck->getCount() << endl
|
||||
<< "Cards: "<< stw->cardCount << endl
|
||||
<< "Creatures: "<< setw(2) << stw->countCreatures
|
||||
<< " Enchantments: " << stw->countEnchantments << endl
|
||||
<< "Instants: " << setw(4) << stw->countInstants
|
||||
@@ -79,7 +79,6 @@ void DeckEditorMenu::drawDeckStatistics()
|
||||
<< "U: " << setw(2) << left << stw->countLandsPerColor[ Constants::MTG_COLOR_BLUE ] + stw->countBasicLandsPerColor[ Constants::MTG_COLOR_BLUE ] << " "
|
||||
<< "B: " << setw(2) << left << stw->countLandsPerColor[ Constants::MTG_COLOR_BLACK ] + stw->countBasicLandsPerColor[ Constants::MTG_COLOR_BLACK ] << " "
|
||||
<< "W: " << setw(2) << left << stw->countLandsPerColor[ Constants::MTG_COLOR_WHITE ] + stw->countBasicLandsPerColor[ Constants::MTG_COLOR_WHITE ] << endl
|
||||
|
||||
<< " --- Card color count --- " << endl
|
||||
<< "A: " << setw(2) << left << selectedDeck->getCount(Constants::MTG_COLOR_ARTIFACT) << " "
|
||||
<< "G: " << setw(2) << left << selectedDeck->getCount(Constants::MTG_COLOR_GREEN) << " "
|
||||
@@ -93,8 +92,8 @@ void DeckEditorMenu::drawDeckStatistics()
|
||||
<< "Mana: " << setprecision(2) << stw->avgManaCost << " "
|
||||
<< "Spell: " << setprecision(2) << stw->avgSpellCost << endl;
|
||||
|
||||
WFont *mainFont = resources.GetWFont( Fonts::MAIN_FONT );
|
||||
mainFont->DrawString( deckStatsString.str().c_str(), descX, descY + 25 );
|
||||
WFont *mainFont = resources.GetWFont(Fonts::MAIN_FONT);
|
||||
mainFont->DrawString(deckStatsString.str().c_str(), descX, descY + 25);
|
||||
}
|
||||
|
||||
DeckEditorMenu::~DeckEditorMenu()
|
||||
|
||||
@@ -17,6 +17,7 @@ namespace
|
||||
const float kLineHeight = 20;
|
||||
const float kDescriptionVerticalBoxPadding = 5;
|
||||
const float kDescriptionHorizontalBoxPadding = 5;
|
||||
const int DETAILED_INFO_THRESHOLD = 4;
|
||||
}
|
||||
|
||||
hgeParticleSystem* DeckMenu::stars = NULL;
|
||||
@@ -30,12 +31,14 @@ hgeParticleSystem* DeckMenu::stars = NULL;
|
||||
// * descriptive information 125
|
||||
// *** Need to make this configurable in a file somewhere to allow for class reuse
|
||||
|
||||
DeckMenu::DeckMenu(int id, JGuiListener* listener, int fontId, const string _title, const float& mFontScale) :
|
||||
DeckMenu::DeckMenu(int id, JGuiListener* listener, int fontId, const string _title, const int& startIndex, const float& mFontScale) :
|
||||
JGuiController(id, listener), fontId(fontId), menuFontScale(mFontScale)
|
||||
{
|
||||
|
||||
backgroundName = "DeckMenuBackdrop";
|
||||
|
||||
selectedDeck = NULL;
|
||||
enableDetails = true;
|
||||
mY = 55;
|
||||
mWidth = 176;
|
||||
mX = 125;
|
||||
@@ -49,6 +52,8 @@ DeckMenu::DeckMenu(int id, JGuiListener* listener, int fontId, const string _tit
|
||||
descHeight = 145;
|
||||
descWidth = 220;
|
||||
|
||||
detailedInfoBoxX = 400;
|
||||
detailedInfoBoxY = 235;
|
||||
starsOffsetX = 50;
|
||||
|
||||
statsX = 280;
|
||||
@@ -56,6 +61,8 @@ DeckMenu::DeckMenu(int id, JGuiListener* listener, int fontId, const string _tit
|
||||
statsHeight = 50;
|
||||
statsWidth = 227;
|
||||
|
||||
selectedDeckId = startIndex;
|
||||
|
||||
avatarX = 230;
|
||||
avatarY = 8;
|
||||
|
||||
@@ -85,8 +92,7 @@ DeckMenu::DeckMenu(int id, JGuiListener* listener, int fontId, const string _tit
|
||||
|
||||
selectionTargetY = selectionY = kVerticalMargin;
|
||||
|
||||
if (NULL == stars)
|
||||
stars = NEW hgeParticleSystem(resources.RetrievePSI("stars.psi", resources.GetQuad("stars")));
|
||||
if (NULL == stars) stars = NEW hgeParticleSystem(resources.RetrievePSI("stars.psi", resources.GetQuad("stars")));
|
||||
stars->FireAt(mX, mY);
|
||||
|
||||
updateScroller();
|
||||
@@ -108,6 +114,21 @@ void DeckMenu::RenderBackground()
|
||||
}
|
||||
}
|
||||
|
||||
DeckMetaData * DeckMenu::getSelectedDeck()
|
||||
{
|
||||
if (selectedDeck) return selectedDeck;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool DeckMenu::selectedDeckHasDetails()
|
||||
{
|
||||
DeckMetaData * currentMenuItem = getSelectedDeck();
|
||||
if (currentMenuItem) return (enableDetails && currentMenuItem->getGamesPlayed() > DETAILED_INFO_THRESHOLD);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void DeckMenu::initMenuItems()
|
||||
{
|
||||
float sY = mY + kVerticalMargin;
|
||||
@@ -116,10 +137,21 @@ void DeckMenu::initMenuItems()
|
||||
float y = mY + kVerticalMargin + i * kLineHeight;
|
||||
DeckMenuItem * currentMenuItem = static_cast<DeckMenuItem*> (mObjects[i]);
|
||||
currentMenuItem->Relocate(mX, y);
|
||||
if (currentMenuItem->hasFocus())
|
||||
sY = y;
|
||||
if (currentMenuItem->hasFocus()) sY = y;
|
||||
}
|
||||
selectionTargetY = selectionY = sY;
|
||||
|
||||
//Grab a texture in VRAM.
|
||||
pspIconsTexture = resources.RetrieveTexture("iconspsp.png", RETRIEVE_LOCK);
|
||||
|
||||
char buf[512];
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
sprintf(buf, "iconspsp%d", i);
|
||||
pspIcons[i] = resources.RetrieveQuad("iconspsp.png", (float) i * 32, 0, 32, 32, buf);
|
||||
pspIcons[i]->SetHotSpot(16, 16);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void DeckMenu::Render()
|
||||
@@ -134,32 +166,47 @@ void DeckMenu::Render()
|
||||
timeOpen = 0;
|
||||
menuInitialized = true;
|
||||
}
|
||||
if (timeOpen < 1)
|
||||
height *= timeOpen > 0 ? timeOpen : -timeOpen;
|
||||
|
||||
renderer->SetTexBlend(BLEND_SRC_ALPHA, BLEND_ONE);
|
||||
stars->Render();
|
||||
renderer->SetTexBlend(BLEND_SRC_ALPHA, BLEND_ONE_MINUS_SRC_ALPHA);
|
||||
if (timeOpen < 1) height *= timeOpen > 0 ? timeOpen : -timeOpen;
|
||||
|
||||
for (int i = startId; i < startId + maxItems; i++)
|
||||
{
|
||||
if (i > mCount - 1)
|
||||
break;
|
||||
if (i > mCount - 1) break;
|
||||
DeckMenuItem *currentMenuItem = static_cast<DeckMenuItem*> (mObjects[i]);
|
||||
if (currentMenuItem->mY - kLineHeight * startId < mY + height - kLineHeight + 7)
|
||||
{
|
||||
if (currentMenuItem->hasFocus())
|
||||
{
|
||||
selectedDeckId = i;
|
||||
selectedDeck = currentMenuItem->meta;
|
||||
|
||||
WFont *mainFont = resources.GetWFont(Fonts::MAIN_FONT);
|
||||
|
||||
// display the "more info" button if special condition is met
|
||||
if (selectedDeckHasDetails())
|
||||
{
|
||||
showDetailsScreen = true;
|
||||
float pspIconsSize = 0.5;
|
||||
const string detailedInfoString = "Detailed Info";
|
||||
float stringWidth = mainFont->GetStringWidth(detailedInfoString.c_str());
|
||||
float boxStartX = detailedInfoBoxX - stringWidth / 2;
|
||||
DWORD currentColor = mainFont->GetColor();
|
||||
renderer->FillRoundRect( boxStartX, detailedInfoBoxY - 5, stringWidth,
|
||||
mainFont->GetHeight() + 15, .5, ARGB( 125, 0, 255, 255) );
|
||||
renderer->RenderQuad(pspIcons[5], detailedInfoBoxX, detailedInfoBoxY + 2, 0, pspIconsSize, pspIconsSize);
|
||||
mainFont->SetColor(currentColor);
|
||||
mainFont->DrawString(detailedInfoString, boxStartX, detailedInfoBoxY + 10);
|
||||
}
|
||||
else
|
||||
showDetailsScreen = false;
|
||||
|
||||
// display the avatar image
|
||||
if (currentMenuItem->imageFilename.size() > 0)
|
||||
{
|
||||
JQuad * quad = resources.RetrieveTempQuad(currentMenuItem->imageFilename, TEXTURE_SUB_AVATAR);
|
||||
if (quad)
|
||||
renderer->RenderQuad(quad, avatarX, avatarY);
|
||||
if (quad) renderer->RenderQuad(quad, avatarX, avatarY);
|
||||
}
|
||||
// fill in the description part of the screen
|
||||
string text = currentMenuItem->desc;
|
||||
WFont *mainFont = resources.GetWFont(Fonts::MAIN_FONT);
|
||||
mainFont->DrawString(text.c_str(), descX, descY);
|
||||
mFont->SetColor(ARGB(255,255,255,255));
|
||||
|
||||
@@ -200,8 +247,7 @@ void DeckMenu::Update(float dt)
|
||||
JGuiController::Update(dt);
|
||||
if (mCurr > startId + maxItems - 1)
|
||||
startId = mCurr - maxItems + 1;
|
||||
else if (mCurr < startId)
|
||||
startId = mCurr;
|
||||
else if (mCurr < startId) startId = mCurr;
|
||||
stars->Update(dt);
|
||||
selectionT += 3 * dt;
|
||||
selectionY += (selectionTargetY - selectionY) * 8 * dt;
|
||||
@@ -224,8 +270,7 @@ void DeckMenu::Update(float dt)
|
||||
closed = false;
|
||||
timeOpen += dt * 10;
|
||||
}
|
||||
|
||||
scroller->Update(dt);
|
||||
if (scroller) scroller->Update(dt);
|
||||
}
|
||||
|
||||
void DeckMenu::Add(int id, const char * text, string desc, bool forceFocus, DeckMetaData * deckMetaData)
|
||||
@@ -240,8 +285,8 @@ void DeckMenu::Add(int id, const char * text, string desc, bool forceFocus, Deck
|
||||
menuItem->desc = deckMetaData ? deckMetaData->getDescription() : desc;
|
||||
|
||||
JGuiController::Add(menuItem);
|
||||
if (mCount <= maxItems)
|
||||
mHeight += kLineHeight;
|
||||
if (mCount <= maxItems) mHeight += kLineHeight;
|
||||
|
||||
if (forceFocus)
|
||||
{
|
||||
mObjects[mCurr]->Leaving(JGE_BTN_DOWN);
|
||||
@@ -277,5 +322,7 @@ void DeckMenu::destroy()
|
||||
|
||||
DeckMenu::~DeckMenu()
|
||||
{
|
||||
resources.Release(pspIconsTexture);
|
||||
SAFE_DELETE(scroller);
|
||||
scroller = NULL;
|
||||
}
|
||||
|
||||
@@ -3,13 +3,18 @@
|
||||
#include "DeckStats.h"
|
||||
#include "Player.h"
|
||||
#include "GameObserver.h"
|
||||
#include "MTGDeck.h"
|
||||
#include "ManaCostHybrid.h"
|
||||
|
||||
DeckStats * DeckStats::mInstance = NULL;
|
||||
|
||||
DeckStat::DeckStat(int _nbgames, int _victories) : nbgames(_nbgames), victories(_victories)
|
||||
{
|
||||
}
|
||||
|
||||
int DeckStat::percentVictories()
|
||||
{
|
||||
if (nbgames == 0)
|
||||
return 50;
|
||||
if (nbgames == 0) return 50;
|
||||
return (100 * victories / nbgames);
|
||||
}
|
||||
|
||||
@@ -159,10 +164,8 @@ void DeckStats::saveStats(Player *player, Player *opponent, GameObserver * game)
|
||||
int victory = 1;
|
||||
if (!game->gameOver)
|
||||
{
|
||||
if (player->life == opponent->life)
|
||||
return;
|
||||
if (player->life < opponent->life)
|
||||
victory = 0;
|
||||
if (player->life == opponent->life) return;
|
||||
if (player->life < opponent->life) victory = 0;
|
||||
}
|
||||
else if (game->gameOver == player)
|
||||
{
|
||||
@@ -181,18 +184,27 @@ void DeckStats::saveStats(Player *player, Player *opponent, GameObserver * game)
|
||||
}
|
||||
save(player);
|
||||
}
|
||||
|
||||
StatsWrapper::StatsWrapper(int deckId)
|
||||
{
|
||||
// Load deck statistics
|
||||
mDeckId = deckId;
|
||||
char buffer[512];
|
||||
sprintf(buffer, "stats/player_deck%i.txt", deckId);
|
||||
string deckstats = options.profileFile(buffer);
|
||||
initStatistics(deckstats);
|
||||
}
|
||||
|
||||
StatsWrapper::StatsWrapper(string deckstats)
|
||||
{
|
||||
initStatistics(deckstats);
|
||||
}
|
||||
|
||||
void StatsWrapper::initStatistics(string deckstats)
|
||||
{
|
||||
// Load deck statistics
|
||||
DeckStats * stats = DeckStats::GetInstance();
|
||||
aiDeckNames.clear();
|
||||
aiDeckStats.clear();
|
||||
|
||||
sprintf(buffer, "stats/player_deck%i.txt", deckId);
|
||||
string deckstats = options.profileFile(buffer);
|
||||
|
||||
if (fileExists(deckstats.c_str()))
|
||||
{
|
||||
stats->load(deckstats.c_str());
|
||||
@@ -202,8 +214,6 @@ StatsWrapper::StatsWrapper(int deckId)
|
||||
// Detailed deck statistics against AI
|
||||
int found = 1;
|
||||
int nbDecks = 0;
|
||||
while (found)
|
||||
{
|
||||
found = 0;
|
||||
char buffer[512];
|
||||
char smallDeckName[512];
|
||||
@@ -227,7 +237,6 @@ StatsWrapper::StatsWrapper(int deckId)
|
||||
delete mtgd;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
gamesPlayed = 0;
|
||||
@@ -235,8 +244,223 @@ StatsWrapper::StatsWrapper(int deckId)
|
||||
}
|
||||
}
|
||||
|
||||
void StatsWrapper::updateStats(string filename, MTGAllCards *collection)
|
||||
{
|
||||
if (fileExists(filename.c_str()))
|
||||
{
|
||||
MTGDeck * mtgd = NEW MTGDeck(filename.c_str(), collection);
|
||||
DeckDataWrapper *deckDataWrapper = NEW DeckDataWrapper(mtgd);
|
||||
updateStats(deckDataWrapper);
|
||||
SAFE_DELETE( mtgd );
|
||||
SAFE_DELETE( deckDataWrapper );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void StatsWrapper::updateStats(DeckDataWrapper *myDeck)
|
||||
{
|
||||
if (!this->needUpdate || !myDeck) return;
|
||||
this->needUpdate = false;
|
||||
this->cardCount = myDeck->getCount(WSrcDeck::UNFILTERED_COPIES);
|
||||
this->countLands = myDeck->getCount(Constants::MTG_COLOR_LAND);
|
||||
this->totalPrice = myDeck->totalPrice();
|
||||
|
||||
this->countManaProducers = 0;
|
||||
// Mana cost
|
||||
int currentCount, convertedCost;
|
||||
ManaCost * currentCost;
|
||||
this->totalManaCost = 0;
|
||||
this->totalCreatureCost = 0;
|
||||
this->totalSpellCost = 0;
|
||||
MTGCard * current = myDeck->getCard();
|
||||
|
||||
// Clearing arrays
|
||||
for (int i = 0; i <= Constants::STATS_MAX_MANA_COST; i++)
|
||||
{
|
||||
this->countCardsPerCost[i] = 0;
|
||||
this->countCreaturesPerCost[i] = 0;
|
||||
this->countSpellsPerCost[i] = 0;
|
||||
}
|
||||
|
||||
for (int i = 0; i <= Constants::MTG_NB_COLORS; i++)
|
||||
{
|
||||
this->totalCostPerColor[i] = 0;
|
||||
this->countLandsPerColor[i] = 0;
|
||||
this->countBasicLandsPerColor[i] = 0;
|
||||
this->countNonLandProducersPerColor[i] = 0;
|
||||
}
|
||||
|
||||
for (int i = 0; i <= Constants::STATS_MAX_MANA_COST; i++)
|
||||
{
|
||||
for (int k = 0; k <= Constants::MTG_NB_COLORS; k++)
|
||||
{
|
||||
this->countCardsPerCostAndColor[i][k] = 0;
|
||||
this->countCreaturesPerCostAndColor[i][k] = 0;
|
||||
this->countSpellsPerCostAndColor[i][k] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
for (int ic = 0; ic < myDeck->Size(true); ic++)
|
||||
{
|
||||
current = myDeck->getCard(ic, true);
|
||||
currentCost = current->data->getManaCost();
|
||||
convertedCost = currentCost->getConvertedCost();
|
||||
currentCount = myDeck->count(current);
|
||||
|
||||
// Add to the cards per cost counters
|
||||
this->totalManaCost += convertedCost * currentCount;
|
||||
if (convertedCost > Constants::STATS_MAX_MANA_COST)
|
||||
{
|
||||
convertedCost = Constants::STATS_MAX_MANA_COST;
|
||||
}
|
||||
this->countCardsPerCost[convertedCost] += currentCount;
|
||||
if (current->data->isCreature())
|
||||
{
|
||||
this->countCreaturesPerCost[convertedCost] += currentCount;
|
||||
this->totalCreatureCost += convertedCost * currentCount;
|
||||
}
|
||||
else if (current->data->isSpell())
|
||||
{
|
||||
this->countSpellsPerCost[convertedCost] += currentCount;
|
||||
this->totalSpellCost += convertedCost * currentCount;
|
||||
}
|
||||
|
||||
// Lets look for mana producing abilities
|
||||
|
||||
vector<string> abilitiesVector;
|
||||
string thisstring = current->data->magicText;
|
||||
abilitiesVector = split(thisstring, '\n');
|
||||
|
||||
for (int v = 0; v < (int) abilitiesVector.size(); v++)
|
||||
{
|
||||
string s = abilitiesVector[v];
|
||||
size_t t = s.find("add");
|
||||
if (t != string::npos)
|
||||
{
|
||||
s = s.substr(t + 3);
|
||||
ManaCost * mc = ManaCost::parseManaCost(s);
|
||||
for (int j = 0; j < Constants::MTG_NB_COLORS; j++)
|
||||
{
|
||||
if (mc->hasColor(j))
|
||||
{
|
||||
if (current->data->isLand())
|
||||
{
|
||||
if (current->data->hasType("Basic"))
|
||||
{
|
||||
this->countBasicLandsPerColor[j] += currentCount;
|
||||
}
|
||||
else
|
||||
{
|
||||
this->countLandsPerColor[j] += currentCount;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this->countNonLandProducersPerColor[j] += currentCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
SAFE_DELETE(mc);
|
||||
}
|
||||
}
|
||||
|
||||
// Add to the per color counters
|
||||
// a. regular costs
|
||||
for (int j = 0; j < Constants::MTG_NB_COLORS; j++)
|
||||
{
|
||||
this->totalCostPerColor[j] += currentCost->getCost(j) * currentCount;
|
||||
if (current->data->hasColor(j))
|
||||
{
|
||||
// Add to the per cost and color counter
|
||||
this->countCardsPerCostAndColor[convertedCost][j] += currentCount;
|
||||
if (current->data->isCreature())
|
||||
{
|
||||
this->countCreaturesPerCostAndColor[convertedCost][j] += currentCount;
|
||||
}
|
||||
else if (current->data->isSpell())
|
||||
{
|
||||
this->countSpellsPerCostAndColor[convertedCost][j] += currentCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// b. Hybrid costs
|
||||
ManaCostHybrid * hybridCost;
|
||||
int i;
|
||||
i = 0;
|
||||
|
||||
while ((hybridCost = currentCost->getHybridCost(i++)) != NULL)
|
||||
{
|
||||
this->totalCostPerColor[hybridCost->color1] += hybridCost->value1 * currentCount;
|
||||
this->totalCostPerColor[hybridCost->color2] += hybridCost->value2 * currentCount;
|
||||
}
|
||||
}
|
||||
|
||||
this->totalColoredSymbols = 0;
|
||||
for (int j = 1; j < Constants::MTG_NB_COLORS; j++)
|
||||
{
|
||||
this->totalColoredSymbols += this->totalCostPerColor[j];
|
||||
}
|
||||
|
||||
this->countCardsPerCost[0] -= this->countLands;
|
||||
|
||||
// Counts by type
|
||||
this->countCreatures = countCardsByType("Creature", myDeck);
|
||||
this->countInstants = countCardsByType("Instant", myDeck);
|
||||
this->countEnchantments = countCardsByType("Enchantment", myDeck);
|
||||
this->countSorceries = countCardsByType("Sorcery", myDeck);
|
||||
this->countSpells = this->countInstants + this->countEnchantments + this->countSorceries;
|
||||
//this->countArtifacts = countCardsByType("Artifact", myDeck);
|
||||
|
||||
// Average mana costs
|
||||
this->avgManaCost = ((this->cardCount - this->countLands) <= 0) ? 0 : (float) this->totalManaCost / (this->cardCount
|
||||
- this->countLands);
|
||||
this->avgCreatureCost = (this->countCreatures <= 0) ? 0 : (float) this->totalCreatureCost / this->countCreatures;
|
||||
this->avgSpellCost = (this->countSpells <= 0) ? 0 : (float) this->totalSpellCost / this->countSpells;
|
||||
|
||||
// Probabilities
|
||||
// TODO: this could be optimized by reusing results
|
||||
for (int i = 0; i < Constants::STATS_FOR_TURNS; i++)
|
||||
{
|
||||
this->noLandsProbInTurn[i] = noLuck(this->cardCount, this->countLands, 7 + i) * 100;
|
||||
this->noCreaturesProbInTurn[i] = noLuck(this->cardCount, this->countCreatures, 7 + i) * 100;
|
||||
}
|
||||
}
|
||||
|
||||
// This should probably be cached in DeckDataWrapper
|
||||
// or at least be calculated for all common types in one go
|
||||
int StatsWrapper::countCardsByType(const char * _type, DeckDataWrapper * myDeck)
|
||||
{
|
||||
int result = 0;
|
||||
for (int i = 0; i < myDeck->Size(true); i++)
|
||||
{
|
||||
MTGCard * current = myDeck->getCard(i, true);
|
||||
if (current->data->hasType(_type))
|
||||
{
|
||||
result += myDeck->count(current);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// n cards total, a of them are of desired type (A), x drawn
|
||||
// returns probability of no A's
|
||||
float StatsWrapper::noLuck(int n, int a, int x)
|
||||
{
|
||||
if ((a >= n) || (a == 0)) return 1;
|
||||
if ((n == 0) || (x == 0) || (x > n) || (n - a < x)) return 0;
|
||||
|
||||
a = n - a;
|
||||
float result = 1;
|
||||
|
||||
for (int i = 0; i < x; i++)
|
||||
result *= (float) (a - i) / (n - i);
|
||||
return result;
|
||||
}
|
||||
|
||||
StatsWrapper::~StatsWrapper()
|
||||
{
|
||||
aiDeckNames.clear();
|
||||
aiDeckStats.clear();
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include "WDataSrc.h"
|
||||
#include "DeckEditorMenu.h"
|
||||
#include "SimpleMenu.h"
|
||||
#include "utils.h"
|
||||
|
||||
//!! helper function; this is probably handled somewhere in the code already.
|
||||
// If not, should be placed in general library
|
||||
@@ -27,13 +28,11 @@ void StringExplode(string str, string separator, vector<string>* results)
|
||||
found = str.find_first_of(separator);
|
||||
while (found != string::npos)
|
||||
{
|
||||
if (found > 0)
|
||||
results->push_back(str.substr(0, found));
|
||||
if (found > 0) results->push_back(str.substr(0, found));
|
||||
str = str.substr(found + 1);
|
||||
found = str.find_first_of(separator);
|
||||
}
|
||||
if (str.length() > 0)
|
||||
results->push_back(str);
|
||||
if (str.length() > 0) results->push_back(str);
|
||||
}
|
||||
|
||||
GameStateDeckViewer::GameStateDeckViewer(GameApp* parent) :
|
||||
@@ -95,21 +94,18 @@ void GameStateDeckViewer::rotateCards(int direction)
|
||||
}
|
||||
void GameStateDeckViewer::rebuildFilters()
|
||||
{
|
||||
if (!filterMenu)
|
||||
filterMenu = NEW WGuiFilters("Filter by...", NULL);
|
||||
if (!filterMenu) filterMenu = NEW WGuiFilters("Filter by...", NULL);
|
||||
if (source)
|
||||
SAFE_DELETE(source);
|
||||
source = NEW WSrcDeckViewer(myDeck, myCollection);
|
||||
filterMenu->setSrc(source);
|
||||
if (displayed_deck != myDeck)
|
||||
source->swapSrc();
|
||||
if (displayed_deck != myDeck) source->swapSrc();
|
||||
filterMenu->Finish(true);
|
||||
updateStats();
|
||||
}
|
||||
void GameStateDeckViewer::updateFilters()
|
||||
{
|
||||
if (!displayed_deck)
|
||||
return;
|
||||
if (!displayed_deck) return;
|
||||
|
||||
filterMenu->recolorFilter(useFilter - 1);
|
||||
filterMenu->Finish(true);
|
||||
@@ -171,8 +167,8 @@ void GameStateDeckViewer::updateDecks()
|
||||
newDeckname = "";
|
||||
nbDecks = playerDeckList.size() + 1;
|
||||
welcome_menu->Add(MENU_ITEM_NEW_DECK, "--NEW--");
|
||||
if (options[Options::CHEATMODE].number && (!myCollection || myCollection->getCount(WSrcDeck::UNFILTERED_MIN_COPIES) < 4))
|
||||
welcome_menu->Add(MENU_ITEM_CHEAT_MODE, "--UNLOCK CARDS--");
|
||||
if (options[Options::CHEATMODE].number && (!myCollection || myCollection->getCount(WSrcDeck::UNFILTERED_MIN_COPIES) < 4)) welcome_menu->Add(
|
||||
MENU_ITEM_CHEAT_MODE, "--UNLOCK CARDS--");
|
||||
welcome_menu->Add(MENU_ITEM_CANCEL, "Cancel");
|
||||
|
||||
// update the deckmanager with the latest information
|
||||
@@ -286,8 +282,7 @@ void GameStateDeckViewer::End()
|
||||
|
||||
void GameStateDeckViewer::addRemove(MTGCard * card)
|
||||
{
|
||||
if (!card)
|
||||
return;
|
||||
if (!card) return;
|
||||
if (displayed_deck->Remove(card, 1, (displayed_deck == myDeck)))
|
||||
{
|
||||
if (displayed_deck == myCollection)
|
||||
@@ -372,8 +367,7 @@ void GameStateDeckViewer::Update(float dt)
|
||||
return;
|
||||
}
|
||||
hudAlpha = 255 - ((int) last_user_activity * 500);
|
||||
if (hudAlpha < 0)
|
||||
hudAlpha = 0;
|
||||
if (hudAlpha < 0) hudAlpha = 0;
|
||||
if (subMenu)
|
||||
{
|
||||
subMenu->Update(dt);
|
||||
@@ -399,15 +393,13 @@ void GameStateDeckViewer::Update(float dt)
|
||||
last_user_activity = 0;
|
||||
mStage = STAGE_TRANSITION_UP;
|
||||
useFilter++;
|
||||
if (useFilter >= MAX_SAVED_FILTERS)
|
||||
useFilter = 0;
|
||||
if (useFilter >= MAX_SAVED_FILTERS) useFilter = 0;
|
||||
break;
|
||||
case JGE_BTN_DOWN:
|
||||
last_user_activity = 0;
|
||||
mStage = STAGE_TRANSITION_DOWN;
|
||||
useFilter--;
|
||||
if (useFilter < 0)
|
||||
useFilter = MAX_SAVED_FILTERS - 1;
|
||||
if (useFilter < 0) useFilter = MAX_SAVED_FILTERS - 1;
|
||||
break;
|
||||
case JGE_BTN_CANCEL:
|
||||
options[Options::DISABLECARDS].number = !options[Options::DISABLECARDS].number;
|
||||
@@ -456,22 +448,19 @@ void GameStateDeckViewer::Update(float dt)
|
||||
SAFE_DELETE(source);
|
||||
source = NEW WSrcDeckViewer(myDeck, myCollection);
|
||||
filterMenu->setSrc(source);
|
||||
if (displayed_deck != myDeck)
|
||||
source->swapSrc();
|
||||
if (displayed_deck != myDeck) source->swapSrc();
|
||||
}
|
||||
filterMenu->Entering(JGE_BTN_NONE);
|
||||
break;
|
||||
case JGE_BTN_PREV:
|
||||
if (last_user_activity < NO_USER_ACTIVITY_HELP_DELAY)
|
||||
last_user_activity = NO_USER_ACTIVITY_HELP_DELAY + 1;
|
||||
else if ((mStage == STAGE_ONSCREEN_MENU) && (--stw->currentPage < 0))
|
||||
stw->currentPage = stw->pageCount;
|
||||
else if ((mStage == STAGE_ONSCREEN_MENU) && (--stw->currentPage < 0)) stw->currentPage = stw->pageCount;
|
||||
break;
|
||||
case JGE_BTN_NEXT:
|
||||
if (last_user_activity < NO_USER_ACTIVITY_HELP_DELAY)
|
||||
last_user_activity = NO_USER_ACTIVITY_HELP_DELAY + 1;
|
||||
else if ((mStage == STAGE_ONSCREEN_MENU) && (++stw->currentPage > stw->pageCount))
|
||||
stw->currentPage = 0;
|
||||
else if ((mStage == STAGE_ONSCREEN_MENU) && (++stw->currentPage > stw->pageCount)) stw->currentPage = 0;
|
||||
break;
|
||||
default: // no keypress
|
||||
if (last_user_activity > NO_USER_ACTIVITY_HELP_DELAY)
|
||||
@@ -605,18 +594,17 @@ void GameStateDeckViewer::renderOnScreenBasicInfo()
|
||||
WCardFilter * wc = displayed_deck->getFiltersRoot();
|
||||
|
||||
if (wc)
|
||||
sprintf(buffer, "%s %i of %i cards (%i unique)", (displayed_deck == myDeck) ? "DECK: " : " ",
|
||||
nowCopies, allCopies, displayed_deck->getCount(WSrcDeck::FILTERED_UNIQUE));
|
||||
sprintf(buffer, "%s %i of %i cards (%i unique)", (displayed_deck == myDeck) ? "DECK: " : " ", nowCopies, allCopies,
|
||||
displayed_deck->getCount(WSrcDeck::FILTERED_UNIQUE));
|
||||
else
|
||||
sprintf(buffer, "%s%i cards (%i unique)", (displayed_deck == myDeck) ? "DECK: " : " ",
|
||||
allCopies, displayed_deck->getCount(WSrcDeck::UNFILTERED_UNIQUE));
|
||||
sprintf(buffer, "%s%i cards (%i unique)", (displayed_deck == myDeck) ? "DECK: " : " ", allCopies, displayed_deck->getCount(
|
||||
WSrcDeck::UNFILTERED_UNIQUE));
|
||||
|
||||
float w = mFont->GetStringWidth(buffer);
|
||||
renderer->FillRoundRect(SCREEN_WIDTH - (w + 27), y + 5, w + 10, 15, 5, ARGB(128,0,0,0));
|
||||
|
||||
mFont->DrawString(buffer, SCREEN_WIDTH - 22, y + 15, JGETEXT_RIGHT);
|
||||
if (useFilter != 0)
|
||||
renderer->RenderQuad(mIcons[useFilter - 1], SCREEN_WIDTH - 10, y + 15, 0.0f, 0.5, 0.5);
|
||||
if (useFilter != 0) renderer->RenderQuad(mIcons[useFilter - 1], SCREEN_WIDTH - 10, y + 15, 0.0f, 0.5, 0.5);
|
||||
}
|
||||
|
||||
//returns position of the current card (cusor) in the currently viewed color/filter
|
||||
@@ -627,10 +615,8 @@ int GameStateDeckViewer::getCurrentPos()
|
||||
int currentPos = displayed_deck->getOffset();
|
||||
currentPos += 2; //we start by displaying card number 3
|
||||
currentPos = currentPos % total + 1;
|
||||
if (currentPos < 0)
|
||||
currentPos = (total + currentPos);
|
||||
if (!currentPos)
|
||||
currentPos = total;
|
||||
if (currentPos < 0) currentPos = (total + currentPos);
|
||||
if (!currentPos) currentPos = total;
|
||||
return currentPos;
|
||||
}
|
||||
|
||||
@@ -639,8 +625,7 @@ void GameStateDeckViewer::renderSlideBar()
|
||||
WFont * mFont = resources.GetWFont(Fonts::MAIN_FONT);
|
||||
|
||||
int total = displayed_deck->Size();
|
||||
if (total == 0)
|
||||
return;
|
||||
if (total == 0) return;
|
||||
|
||||
float filler = 15;
|
||||
float y = SCREEN_HEIGHT_F - 25;
|
||||
@@ -1275,8 +1260,7 @@ void GameStateDeckViewer::renderOnScreenMenu()
|
||||
|
||||
void GameStateDeckViewer::updateStats()
|
||||
{
|
||||
if (!stw->needUpdate || !myDeck)
|
||||
return;
|
||||
if (!stw->needUpdate || !myDeck) return;
|
||||
stw->needUpdate = false;
|
||||
stw->cardCount = myDeck->getCount(WSrcDeck::UNFILTERED_COPIES);
|
||||
stw->countLands = myDeck->getCount(Constants::MTG_COLOR_LAND);
|
||||
@@ -1345,8 +1329,7 @@ void GameStateDeckViewer::updateStats()
|
||||
// Lets look for mana producing abilities
|
||||
|
||||
vector<string> abilityStrings;
|
||||
string thisstring = current->data->magicText;
|
||||
StringExplode(thisstring, "\n", &abilityStrings);
|
||||
abilityStrings = split(current->data->magicText, '\n');
|
||||
|
||||
for (int v = 0; v < (int) abilityStrings.size(); v++)
|
||||
{
|
||||
@@ -1478,8 +1461,7 @@ void GameStateDeckViewer::renderCard(int id, float rotation)
|
||||
|
||||
int alpha = (int) (255 * (scale + 1.0 - max_scale));
|
||||
|
||||
if (!card)
|
||||
return;
|
||||
if (!card) return;
|
||||
JQuad * quad = NULL;
|
||||
|
||||
int cacheError = CACHE_ERROR_NONE;
|
||||
@@ -1500,8 +1482,7 @@ void GameStateDeckViewer::renderCard(int id, float rotation)
|
||||
}
|
||||
|
||||
int quadAlpha = alpha;
|
||||
if (!displayed_deck->count(card))
|
||||
quadAlpha /= 2;
|
||||
if (!displayed_deck->count(card)) quadAlpha /= 2;
|
||||
if (quad)
|
||||
{
|
||||
if (quad == backQuad)
|
||||
@@ -1520,8 +1501,7 @@ void GameStateDeckViewer::renderCard(int id, float rotation)
|
||||
{
|
||||
Pos pos = Pos(x, y, scale * 285 / 250, 0.0, 255);
|
||||
CardGui::DrawCard(card, pos, DrawMode::kText);
|
||||
if (!options[Options::DISABLECARDS].number)
|
||||
quad = resources.RetrieveCard(card, CACHE_THUMB);
|
||||
if (!options[Options::DISABLECARDS].number) quad = resources.RetrieveCard(card, CACHE_THUMB);
|
||||
if (quad)
|
||||
{
|
||||
float _scale = 285 * scale / quad->mHeight;
|
||||
@@ -1564,8 +1544,7 @@ void GameStateDeckViewer::Render()
|
||||
|
||||
JRenderer * r = JRenderer::GetInstance();
|
||||
r->ClearScreen(ARGB(0,0,0,0));
|
||||
if (displayed_deck == myDeck && mStage != STAGE_MENU)
|
||||
renderDeckBackground();
|
||||
if (displayed_deck == myDeck && mStage != STAGE_MENU) renderDeckBackground();
|
||||
int order[3] = { 1, 2, 3 };
|
||||
if (mRotation < 0.5 && mRotation > -0.5)
|
||||
{
|
||||
@@ -1613,29 +1592,24 @@ void GameStateDeckViewer::Render()
|
||||
{
|
||||
menu->Render();
|
||||
}
|
||||
if (subMenu)
|
||||
subMenu->Render();
|
||||
if (subMenu) subMenu->Render();
|
||||
|
||||
if (filterMenu && !filterMenu->isFinished())
|
||||
filterMenu->Render();
|
||||
if (filterMenu && !filterMenu->isFinished()) filterMenu->Render();
|
||||
|
||||
if (options.keypadActive())
|
||||
options.keypadRender();
|
||||
if (options.keypadActive()) options.keypadRender();
|
||||
|
||||
}
|
||||
|
||||
int GameStateDeckViewer::loadDeck(int deckid)
|
||||
{
|
||||
|
||||
if (!stw)
|
||||
stw = new StatsWrapper(deckid);
|
||||
if (!stw) stw = new StatsWrapper(deckid);
|
||||
|
||||
stw->currentPage = 0;
|
||||
stw->pageCount = 9;
|
||||
stw->needUpdate = true;
|
||||
|
||||
if (!playerdata)
|
||||
playerdata = NEW PlayerData(mParent->collection);
|
||||
if (!playerdata) playerdata = NEW PlayerData(mParent->collection);
|
||||
SAFE_DELETE(myCollection);
|
||||
myCollection = NEW DeckDataWrapper(playerdata->collection);
|
||||
myCollection->Sort(WSrcCards::SORT_ALPHA);
|
||||
@@ -1707,6 +1681,10 @@ void GameStateDeckViewer::ButtonPressed(int controllerId, int controlId)
|
||||
mSwitching = false;
|
||||
break;
|
||||
}
|
||||
else if (controlId == MENUITEM_MORE_INFO)
|
||||
{
|
||||
break;
|
||||
}
|
||||
else if (controlId == MENU_ITEM_CHEAT_MODE)
|
||||
{ // (PSY) Cheatmode: Complete the collection
|
||||
playerdata->collection->complete(); // Add the cards
|
||||
@@ -1714,8 +1692,7 @@ void GameStateDeckViewer::ButtonPressed(int controllerId, int controlId)
|
||||
for (int i = 0; i < setlist.size(); i++)
|
||||
{ // Update unlocked sets
|
||||
GameOptionAward * goa = dynamic_cast<GameOptionAward*> (&options[Options::optionSet(i)]);
|
||||
if (goa)
|
||||
goa->giveAward();
|
||||
if (goa) goa->giveAward();
|
||||
}
|
||||
options.save();
|
||||
SAFE_DELETE(myCollection);
|
||||
@@ -1787,8 +1764,7 @@ void GameStateDeckViewer::ButtonPressed(int controllerId, int controlId)
|
||||
break;
|
||||
case MENU_ITEM_FILTER_BY:
|
||||
mStage = STAGE_FILTERS;
|
||||
if (!filterMenu)
|
||||
rebuildFilters();
|
||||
if (!filterMenu) rebuildFilters();
|
||||
filterMenu->Entering(JGE_BTN_NONE);
|
||||
break;
|
||||
}
|
||||
@@ -1824,10 +1800,8 @@ void GameStateDeckViewer::ButtonPressed(int controllerId, int controlId)
|
||||
// returns probability of no A's
|
||||
float noLuck(int n, int a, int x)
|
||||
{
|
||||
if ((a >= n) || (a == 0))
|
||||
return 1;
|
||||
if ((n == 0) || (x == 0) || (x > n) || (n - a < x))
|
||||
return 0;
|
||||
if ((a >= n) || (a == 0)) return 1;
|
||||
if ((n == 0) || (x == 0) || (x > n) || (n - a < x)) return 0;
|
||||
|
||||
a = n - a;
|
||||
float result = 1;
|
||||
|
||||
@@ -31,6 +31,8 @@ enum ENUM_DUEL_STATE
|
||||
DUEL_STATE_START,
|
||||
DUEL_STATE_END,
|
||||
DUEL_STATE_CHOOSE_DECK1,
|
||||
DUEL_STATE_DECK1_DETAILED_INFO,
|
||||
DUEL_STATE_DECK2_DETAILED_INFO,
|
||||
DUEL_STATE_CHOOSE_DECK1_TO_2,
|
||||
DUEL_STATE_CHOOSE_DECK2,
|
||||
DUEL_STATE_CHOOSE_DECK2_TO_PLAY,
|
||||
@@ -46,9 +48,14 @@ enum ENUM_DUEL_MENUS
|
||||
{
|
||||
DUEL_MENU_GAME_MENU,
|
||||
DUEL_MENU_CHOOSE_DECK,
|
||||
DUEL_MENU_CHOOSE_OPPONENT
|
||||
DUEL_MENU_CHOOSE_OPPONENT,
|
||||
DUEL_MENU_DETAILED_DECK1_INFO,
|
||||
DUEL_MENU_DETAILED_DECK2_INFO
|
||||
};
|
||||
|
||||
int GameStateDuel::selectedPlayerDeckId = 0;
|
||||
int GameStateDuel::selectedAIDeckId = 0;
|
||||
|
||||
GameStateDuel::GameStateDuel(GameApp* parent) :
|
||||
GameState(parent)
|
||||
{
|
||||
@@ -62,6 +69,8 @@ GameStateDuel::GameStateDuel(GameApp* parent) :
|
||||
deckmenu = NULL;
|
||||
opponentMenu = NULL;
|
||||
menu = NULL;
|
||||
popupScreen = NULL;
|
||||
|
||||
#ifdef TESTSUITE
|
||||
testSuite = NULL;
|
||||
#endif
|
||||
@@ -100,7 +109,8 @@ void GameStateDuel::Start()
|
||||
{
|
||||
decksneeded = 1;
|
||||
|
||||
deckmenu = NEW DeckMenu(DUEL_MENU_CHOOSE_DECK, this, Fonts::OPTION_FONT, "Choose a Deck", MENU_FONT_SCALE);
|
||||
deckmenu = NEW DeckMenu(DUEL_MENU_CHOOSE_DECK, this, Fonts::OPTION_FONT, "Choose a Deck",
|
||||
GameStateDuel::selectedPlayerDeckId);
|
||||
|
||||
DeckManager *deckManager = DeckManager::GetInstance();
|
||||
vector<DeckMetaData *> playerDeckList = getValidDeckMetaData(options.profileFile());
|
||||
@@ -109,8 +119,7 @@ void GameStateDuel::Start()
|
||||
if (nbDecks)
|
||||
{
|
||||
decksneeded = 0;
|
||||
if (nbDecks > 1)
|
||||
deckmenu->Add(MENUITEM_RANDOM_PLAYER, "Random", "Play with a random deck.");
|
||||
if (nbDecks > 1) deckmenu->Add(MENUITEM_RANDOM_PLAYER, "Random", "Play with a random deck.");
|
||||
}
|
||||
|
||||
renderDeckMenu(deckmenu, playerDeckList);
|
||||
@@ -118,6 +127,7 @@ void GameStateDuel::Start()
|
||||
deckManager->updateMetaDataList(&playerDeckList, false);
|
||||
playerDeckList.clear();
|
||||
|
||||
DebugTrace("INFO: Player Deck menu has a size of " << sizeof( deckmenu ) );
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -170,8 +180,7 @@ void GameStateDuel::loadPlayer(int playerId, int decknb, int isAI)
|
||||
{ //AI Player, chooses deck
|
||||
AIPlayerFactory playerCreator;
|
||||
Player * opponent = NULL;
|
||||
if (playerId == 1)
|
||||
opponent = mPlayers[0];
|
||||
if (playerId == 1) opponent = mPlayers[0];
|
||||
mPlayers[playerId] = playerCreator.createAIPlayer(mParent->collection, opponent, decknb);
|
||||
deck[playerId] = mPlayers[playerId]->game;
|
||||
}
|
||||
@@ -180,8 +189,7 @@ void GameStateDuel::loadPlayer(int playerId, int decknb, int isAI)
|
||||
{ //Random deck
|
||||
AIPlayerFactory playerCreator;
|
||||
Player * opponent = NULL;
|
||||
if (playerId == 1)
|
||||
opponent = mPlayers[0];
|
||||
if (playerId == 1) opponent = mPlayers[0];
|
||||
mPlayers[playerId] = playerCreator.createAIPlayer(mParent->collection, opponent);
|
||||
deck[playerId] = mPlayers[playerId]->game;
|
||||
}
|
||||
@@ -189,8 +197,7 @@ void GameStateDuel::loadPlayer(int playerId, int decknb, int isAI)
|
||||
|
||||
void GameStateDuel::initRand(unsigned int seed)
|
||||
{
|
||||
if (!seed)
|
||||
seed = time(0);
|
||||
if (!seed) seed = time(0);
|
||||
srand(seed);
|
||||
}
|
||||
|
||||
@@ -246,6 +253,8 @@ void GameStateDuel::End()
|
||||
SAFE_DELETE(menu);
|
||||
SAFE_DELETE(opponentMenu);
|
||||
SAFE_DELETE(deckmenu);
|
||||
SAFE_DELETE(popupScreen);
|
||||
|
||||
#ifdef TESTSUITE
|
||||
SAFE_DELETE(testSuite);
|
||||
#endif
|
||||
@@ -267,12 +276,13 @@ bool GameStateDuel::MusicExist(string FileName)
|
||||
|
||||
void GameStateDuel::ensureOpponentMenu()
|
||||
{
|
||||
if (!opponentMenu)
|
||||
if (opponentMenu == NULL)
|
||||
{
|
||||
opponentMenu = NEW DeckMenu(DUEL_MENU_CHOOSE_OPPONENT, this, Fonts::OPTION_FONT, "Choose Your Opponent", MENU_FONT_SCALE);
|
||||
opponentMenu = NEW DeckMenu(DUEL_MENU_CHOOSE_OPPONENT, this, Fonts::OPTION_FONT, "Choose Your Opponent",
|
||||
GameStateDuel::selectedAIDeckId);
|
||||
opponentMenu->Add(MENUITEM_RANDOM_AI, "Random");
|
||||
if (options[Options::EVILTWIN_MODE_UNLOCKED].number)
|
||||
opponentMenu->Add(MENUITEM_EVIL_TWIN, "Evil Twin", _("Can you play against yourself?").c_str());
|
||||
if (options[Options::EVILTWIN_MODE_UNLOCKED].number) opponentMenu->Add(MENUITEM_EVIL_TWIN, "Evil Twin", _(
|
||||
"Can you play against yourself?").c_str());
|
||||
DeckManager * deckManager = DeckManager::GetInstance();
|
||||
vector<DeckMetaData*> opponentDeckList = fillDeckMenu(opponentMenu, JGE_GET_RES("ai/baka"), "ai_baka", mPlayers[0]);
|
||||
deckManager->updateMetaDataList(&opponentDeckList, true);
|
||||
@@ -286,9 +296,14 @@ void GameStateDuel::Update(float dt)
|
||||
switch (mGamePhase)
|
||||
{
|
||||
case DUEL_STATE_ERROR_NO_DECK:
|
||||
if (JGE_BTN_OK == mEngine->ReadButton())
|
||||
mParent->SetNextState(GAME_STATE_DECK_VIEWER);
|
||||
if (JGE_BTN_OK == mEngine->ReadButton()) mParent->SetNextState(GAME_STATE_DECK_VIEWER);
|
||||
break;
|
||||
|
||||
case DUEL_STATE_DECK1_DETAILED_INFO:
|
||||
case DUEL_STATE_DECK2_DETAILED_INFO:
|
||||
popupScreen->Update(dt);
|
||||
break;
|
||||
|
||||
case DUEL_STATE_CHOOSE_DECK1:
|
||||
if (mParent->gameType == GAME_TYPE_MOMIR)
|
||||
{
|
||||
@@ -331,10 +346,11 @@ void GameStateDuel::Update(float dt)
|
||||
#endif
|
||||
else
|
||||
{
|
||||
if (!rules)
|
||||
rules = NEW Rules("mtg.txt");
|
||||
if (!rules) rules = NEW Rules("mtg.txt");
|
||||
if (mParent->players[0] == PLAYER_TYPE_HUMAN)
|
||||
deckmenu->Update(dt);
|
||||
{
|
||||
if (!popupScreen || popupScreen->closed) deckmenu->Update(dt);
|
||||
}
|
||||
else
|
||||
{
|
||||
loadPlayer(0);
|
||||
@@ -406,19 +422,17 @@ void GameStateDuel::Update(float dt)
|
||||
musictrack = "ai_baka_music.mp3";
|
||||
else if (mParent->gameType == GAME_TYPE_MOMIR)
|
||||
musictrack = "ai_baka_music_momir.mp3";
|
||||
else if (mParent->gameType == GAME_TYPE_RANDOM1 || mParent->gameType == GAME_TYPE_RANDOM2)
|
||||
musictrack = "ai_baka_music_random.mp3";
|
||||
else if (mParent->gameType == GAME_TYPE_RANDOM1 || mParent->gameType == GAME_TYPE_RANDOM2) musictrack
|
||||
= "ai_baka_music_random.mp3";
|
||||
|
||||
if (!MusicExist(musictrack))
|
||||
musictrack = "ai_baka_music.mp3";
|
||||
if (!MusicExist(musictrack)) musictrack = "ai_baka_music.mp3";
|
||||
|
||||
GameApp::playMusic(musictrack);
|
||||
}
|
||||
game->Update(dt);
|
||||
if (game->gameOver)
|
||||
{
|
||||
if (game->players[1]->playMode != Player::MODE_TEST_SUITE)
|
||||
credits->compute(game->players[0], game->players[1], mParent);
|
||||
if (game->players[1]->playMode != Player::MODE_TEST_SUITE) credits->compute(game->players[0], game->players[1], mParent);
|
||||
mGamePhase = DUEL_STATE_END;
|
||||
#ifdef TESTSUITE
|
||||
if (mParent->players[1] == PLAYER_TYPE_TESTSUITE)
|
||||
@@ -450,8 +464,8 @@ void GameStateDuel::Update(float dt)
|
||||
|
||||
//almosthumane - mulligan
|
||||
if ((game->turn < 1) && (cardsinhand != 0) && game->currentGamePhase == Constants::MTG_PHASE_FIRSTMAIN
|
||||
&& game->players[0]->game->inPlay->nb_cards == 0 && game->players[0]->game->graveyard->nb_cards
|
||||
== 0 && game->players[0]->game->exile->nb_cards == 0) //1st Play Check
|
||||
&& game->players[0]->game->inPlay->nb_cards == 0 && game->players[0]->game->graveyard->nb_cards == 0
|
||||
&& game->players[0]->game->exile->nb_cards == 0) //1st Play Check
|
||||
//IF there was no play at the moment automatically mulligan
|
||||
{
|
||||
menu->Add(MENUITEM_MULLIGAN, "Mulligan");
|
||||
@@ -491,8 +505,7 @@ void GameStateDuel::Update(float dt)
|
||||
|
||||
break;
|
||||
default:
|
||||
if (JGE_BTN_OK == mEngine->ReadButton())
|
||||
mParent->SetNextState(GAME_STATE_MENU);
|
||||
if (JGE_BTN_OK == mEngine->ReadButton()) mParent->SetNextState(GAME_STATE_MENU);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -502,8 +515,7 @@ void GameStateDuel::Render()
|
||||
JRenderer * r = JRenderer::GetInstance();
|
||||
r->ClearScreen(ARGB(0,0,0,0));
|
||||
|
||||
if (game)
|
||||
game->Render();
|
||||
if (game) game->Render();
|
||||
|
||||
switch (mGamePhase)
|
||||
{
|
||||
@@ -557,15 +569,19 @@ void GameStateDuel::Render()
|
||||
case DUEL_STATE_CHOOSE_DECK1_TO_2:
|
||||
case DUEL_STATE_CHOOSE_DECK2:
|
||||
case DUEL_STATE_CHOOSE_DECK2_TO_PLAY:
|
||||
case DUEL_STATE_DECK1_DETAILED_INFO:
|
||||
case DUEL_STATE_DECK2_DETAILED_INFO:
|
||||
if (mParent->gameType != GAME_TYPE_CLASSIC)
|
||||
mFont->DrawString(_("LOADING DECKS").c_str(), 0, SCREEN_HEIGHT / 2);
|
||||
else
|
||||
{
|
||||
if (opponentMenu)
|
||||
opponentMenu->Render();
|
||||
else if (deckmenu)
|
||||
deckmenu->Render();
|
||||
else if (deckmenu && !deckmenu->closed) deckmenu->Render();
|
||||
|
||||
if (menu) menu->Render();
|
||||
|
||||
if (popupScreen && !popupScreen->closed) popupScreen->Render();
|
||||
}
|
||||
break;
|
||||
case DUEL_STATE_ERROR_NO_DECK:
|
||||
@@ -583,8 +599,7 @@ void GameStateDuel::Render()
|
||||
mFont->SetColor(ARGB(255,255,255,255));
|
||||
mFont->DrawString(buffer, SCREEN_WIDTH / 2, 0, JGETEXT_CENTER);
|
||||
}
|
||||
if (menu)
|
||||
menu->Render();
|
||||
if (menu) menu->Render();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -595,8 +610,44 @@ void GameStateDuel::ButtonPressed(int controllerId, int controlId)
|
||||
int aiDeckSize = deckManager->getAIDeckOrderList()->size();
|
||||
switch (controllerId)
|
||||
{
|
||||
case DUEL_MENU_CHOOSE_OPPONENT:
|
||||
|
||||
case DUEL_MENU_DETAILED_DECK1_INFO:
|
||||
if ((popupScreen || deckmenu->selectedDeckHasDetails()))
|
||||
{
|
||||
DeckMetaData* selectedDeck = deckmenu->getSelectedDeck();
|
||||
if (!popupScreen->closed)
|
||||
{
|
||||
popupScreen->Close();
|
||||
mGamePhase = DUEL_STATE_CHOOSE_DECK1;
|
||||
SAFE_DELETE( popupScreen );
|
||||
}
|
||||
else
|
||||
{
|
||||
popupScreen->Update(selectedDeck);
|
||||
popupScreen->Render();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case DUEL_MENU_DETAILED_DECK2_INFO:
|
||||
if ((popupScreen || opponentMenu->selectedDeckHasDetails()))
|
||||
{
|
||||
DeckMetaData* selectedDeck = opponentMenu->getSelectedDeck();
|
||||
if (!popupScreen->closed)
|
||||
{
|
||||
popupScreen->Close();
|
||||
mGamePhase = DUEL_STATE_CHOOSE_DECK2_TO_PLAY;
|
||||
SAFE_DELETE( popupScreen );
|
||||
}
|
||||
else
|
||||
{
|
||||
popupScreen->Update(selectedDeck);
|
||||
popupScreen->Render();
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case DUEL_MENU_CHOOSE_OPPONENT:
|
||||
|
||||
switch (controlId)
|
||||
{
|
||||
case MENUITEM_RANDOM_AI:
|
||||
@@ -612,12 +663,34 @@ void GameStateDuel::ButtonPressed(int controllerId, int controlId)
|
||||
opponentMenu->Close();
|
||||
deckmenu->Close();
|
||||
mParent->SetNextState(DUEL_STATE_CHOOSE_DECK1);
|
||||
mGamePhase = DUEL_MENU_GAME_MENU;
|
||||
mGamePhase = DUEL_STATE_CHOOSE_DECK1;
|
||||
break;
|
||||
}
|
||||
|
||||
else if (controlId == MENUITEM_MORE_INFO && opponentMenu->showDetailsScreen)
|
||||
{
|
||||
DeckMetaData* selectedDeck = opponentMenu->getSelectedDeck();
|
||||
if (!popupScreen)
|
||||
{
|
||||
popupScreen = NEW SimplePopup(DUEL_MENU_DETAILED_DECK2_INFO, this, Fonts::MAIN_FONT, "Detailed Information",
|
||||
selectedDeck, mParent->collection);
|
||||
popupScreen->Render();
|
||||
selectedAIDeckId = selectedDeck->getDeckId();
|
||||
}
|
||||
else
|
||||
{
|
||||
popupScreen->Update(selectedDeck);
|
||||
}
|
||||
mGamePhase = DUEL_STATE_DECK2_DETAILED_INFO;
|
||||
break;
|
||||
}
|
||||
else if (controlId == MENUITEM_MORE_INFO && !opponentMenu->showDetailsScreen)
|
||||
{
|
||||
// do nothing, ignore all key requests until popup is dismissed.
|
||||
break;
|
||||
}
|
||||
else if (controlId != MENUITEM_EVIL_TWIN && aiDeckSize > 0) // evil twin
|
||||
deckNumber = deckManager->getAIDeckOrderList()->at(controlId - 1)->getDeckId();
|
||||
|
||||
loadPlayer(1, deckNumber, 1);
|
||||
OpponentsDeckid = deckNumber;
|
||||
opponentMenu->Close();
|
||||
@@ -625,9 +698,9 @@ void GameStateDuel::ButtonPressed(int controllerId, int controlId)
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case DUEL_MENU_CHOOSE_DECK:
|
||||
{
|
||||
|
||||
if (controlId == MENUITEM_RANDOM_PLAYER) // Random Player Deck Selection
|
||||
{
|
||||
vector<DeckMetaData *> * playerDeckList = deckManager->getPlayerDeckOrderList();
|
||||
@@ -639,11 +712,32 @@ void GameStateDuel::ButtonPressed(int controllerId, int controlId)
|
||||
}
|
||||
else if (controlId == MENUITEM_MAIN_MENU || controlId == MENUITEM_CANCEL) // user clicked on "Cancel"
|
||||
{
|
||||
if (deckmenu)
|
||||
deckmenu->Close();
|
||||
if (deckmenu) deckmenu->Close();
|
||||
mGamePhase = DUEL_STATE_BACK_TO_MAIN_MENU;
|
||||
break;
|
||||
}
|
||||
else if (controlId == MENUITEM_MORE_INFO && deckmenu->showDetailsScreen)
|
||||
{
|
||||
DeckMetaData* selectedDeck = deckmenu->getSelectedDeck();
|
||||
if (!popupScreen)
|
||||
{
|
||||
popupScreen = NEW SimplePopup(DUEL_MENU_DETAILED_DECK1_INFO, this, Fonts::MAIN_FONT, "Detailed Information",
|
||||
selectedDeck, mParent->collection);
|
||||
popupScreen->Render();
|
||||
selectedPlayerDeckId = deckmenu->selectedDeckId;
|
||||
}
|
||||
else
|
||||
{
|
||||
popupScreen->Update(selectedDeck);
|
||||
}
|
||||
mGamePhase = DUEL_STATE_DECK1_DETAILED_INFO;
|
||||
break;
|
||||
}
|
||||
else if (controlId == MENUITEM_MORE_INFO)
|
||||
{
|
||||
// do nothing
|
||||
break;
|
||||
}
|
||||
if (controlId < 0)
|
||||
{
|
||||
mParent->SetNextState(GAME_STATE_DECK_VIEWER);
|
||||
@@ -652,8 +746,7 @@ void GameStateDuel::ButtonPressed(int controllerId, int controlId)
|
||||
if (mGamePhase == DUEL_STATE_CHOOSE_DECK1)
|
||||
{
|
||||
vector<DeckMetaData *> * playerDeck = deckManager->getPlayerDeckOrderList();
|
||||
if (!premadeDeck && controlId > 0)
|
||||
deckNumber = playerDeck->at(controlId - 1)->getDeckId();
|
||||
if (!premadeDeck && controlId > 0) deckNumber = playerDeck->at(controlId - 1)->getDeckId();
|
||||
loadPlayer(0, deckNumber);
|
||||
deckmenu->Close();
|
||||
mGamePhase = DUEL_STATE_CHOOSE_DECK1_TO_2;
|
||||
@@ -666,9 +759,9 @@ void GameStateDuel::ButtonPressed(int controllerId, int controlId)
|
||||
mGamePhase = DUEL_STATE_CHOOSE_DECK2_TO_PLAY;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
|
||||
switch (controlId)
|
||||
{
|
||||
|
||||
@@ -682,12 +775,13 @@ void GameStateDuel::ButtonPressed(int controllerId, int controlId)
|
||||
break;
|
||||
case MENUITEM_MULLIGAN:
|
||||
//almosthumane - mulligan
|
||||
{
|
||||
|
||||
|
||||
int cardsinhand = game->players[0]->game->hand->nb_cards;
|
||||
|
||||
for (int i = 0; i < cardsinhand; i++) //Discard hand
|
||||
game->currentPlayer->game->putInZone(game->currentPlayer->game->hand->cards[0], game->currentPlayer->game->hand,
|
||||
game->currentPlayer->game->putInZone(game->currentPlayer->game->hand->cards[0],
|
||||
game->currentPlayer->game->hand,
|
||||
game->currentPlayer->game->library);
|
||||
|
||||
game->currentPlayer->game->library->shuffle(); //Shuffle
|
||||
@@ -697,9 +791,9 @@ void GameStateDuel::ButtonPressed(int controllerId, int controlId)
|
||||
menu->Close();
|
||||
mGamePhase = DUEL_STATE_CANCEL;
|
||||
break;
|
||||
}
|
||||
|
||||
//END almosthumane - mulligan
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,8 +43,7 @@ static inline int getGrade(int v)
|
||||
//MTGAllCards
|
||||
int MTGAllCards::processConfLine(string &s, MTGCard *card, CardPrimitive * primitive)
|
||||
{
|
||||
if ('#' == s[0])
|
||||
return 0;
|
||||
if ('#' == s[0]) return 0;
|
||||
size_t i = s.find_first_of('=');
|
||||
if (i == string::npos || 0 == i)
|
||||
{
|
||||
@@ -61,26 +60,22 @@ int MTGAllCards::processConfLine(string &s, MTGCard *card, CardPrimitive * primi
|
||||
case 'a':
|
||||
if (0 == strcmp("auto", key))
|
||||
{
|
||||
if (!primitive)
|
||||
primitive = NEW CardPrimitive();
|
||||
if (!primitive) primitive = NEW CardPrimitive();
|
||||
primitive->addMagicText(val);
|
||||
}
|
||||
else if (0 == strncmp("auto", key, 4))
|
||||
{
|
||||
if (!primitive)
|
||||
primitive = NEW CardPrimitive();
|
||||
if (!primitive) primitive = NEW CardPrimitive();
|
||||
primitive->addMagicText(val, key + 4);
|
||||
}
|
||||
else if (0 == strcmp("alias", key))
|
||||
{
|
||||
if (!primitive)
|
||||
primitive = NEW CardPrimitive();
|
||||
if (!primitive) primitive = NEW CardPrimitive();
|
||||
primitive->alias = atoi(val);
|
||||
}
|
||||
else if (0 == strcmp("abilities", key))
|
||||
{
|
||||
if (!primitive)
|
||||
primitive = NEW CardPrimitive();
|
||||
if (!primitive) primitive = NEW CardPrimitive();
|
||||
string value = val;
|
||||
//Specific Abilities
|
||||
std::transform(value.begin(), value.end(), value.begin(), ::tolower);
|
||||
@@ -112,8 +107,7 @@ int MTGAllCards::processConfLine(string &s, MTGCard *card, CardPrimitive * primi
|
||||
break;
|
||||
|
||||
case 'c': //color
|
||||
if (!primitive)
|
||||
primitive = NEW CardPrimitive();
|
||||
if (!primitive) primitive = NEW CardPrimitive();
|
||||
{
|
||||
string value = val;
|
||||
std::transform(value.begin(), value.end(), value.begin(), ::tolower);
|
||||
@@ -128,12 +122,11 @@ int MTGAllCards::processConfLine(string &s, MTGCard *card, CardPrimitive * primi
|
||||
break;
|
||||
|
||||
case 'g': //grade
|
||||
if (s.size() - i - 1 > 2)
|
||||
currentGrade = getGrade(val[2]);
|
||||
if (s.size() - i - 1 > 2) currentGrade = getGrade(val[2]);
|
||||
break;
|
||||
|
||||
case 'k': //kicker
|
||||
if (!primitive)
|
||||
primitive = NEW CardPrimitive();
|
||||
if (!primitive) primitive = NEW CardPrimitive();
|
||||
if (ManaCost * cost = primitive->getManaCost())
|
||||
{
|
||||
string value = val;
|
||||
@@ -141,9 +134,9 @@ int MTGAllCards::processConfLine(string &s, MTGCard *card, CardPrimitive * primi
|
||||
cost->kicker = ManaCost::parseManaCost(value);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'o': //othercost
|
||||
if (!primitive)
|
||||
primitive = NEW CardPrimitive();
|
||||
if (!primitive) primitive = NEW CardPrimitive();
|
||||
if (ManaCost * cost = primitive->getManaCost())
|
||||
{
|
||||
string value = val;
|
||||
@@ -151,9 +144,9 @@ int MTGAllCards::processConfLine(string &s, MTGCard *card, CardPrimitive * primi
|
||||
cost->alternative = ManaCost::parseManaCost(value);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'b': //buyback
|
||||
if (!primitive)
|
||||
primitive = NEW CardPrimitive();
|
||||
if (!primitive) primitive = NEW CardPrimitive();
|
||||
if (ManaCost * cost = primitive->getManaCost())
|
||||
{
|
||||
string value = val;
|
||||
@@ -162,8 +155,7 @@ int MTGAllCards::processConfLine(string &s, MTGCard *card, CardPrimitive * primi
|
||||
}
|
||||
break;
|
||||
case 'f': //flashback
|
||||
if (!primitive)
|
||||
primitive = NEW CardPrimitive();
|
||||
if (!primitive) primitive = NEW CardPrimitive();
|
||||
if (ManaCost * cost = primitive->getManaCost())
|
||||
{
|
||||
string value = val;
|
||||
@@ -173,14 +165,12 @@ int MTGAllCards::processConfLine(string &s, MTGCard *card, CardPrimitive * primi
|
||||
break;
|
||||
|
||||
case 'i': //id
|
||||
if (!card)
|
||||
card = NEW MTGCard();
|
||||
if (!card) card = NEW MTGCard();
|
||||
card->setMTGId(atoi(val));
|
||||
break;
|
||||
|
||||
case 'm': //mana
|
||||
if (!primitive)
|
||||
primitive = NEW CardPrimitive();
|
||||
if (!primitive) primitive = NEW CardPrimitive();
|
||||
{
|
||||
string value = val;
|
||||
std::transform(value.begin(), value.end(), value.begin(), ::tolower);
|
||||
@@ -189,26 +179,21 @@ int MTGAllCards::processConfLine(string &s, MTGCard *card, CardPrimitive * primi
|
||||
break;
|
||||
|
||||
case 'n': //name
|
||||
if (!primitive)
|
||||
primitive = NEW CardPrimitive();
|
||||
if (0 == strcmp("Bloodrock Cyclops", val))
|
||||
cout << "val" << endl;
|
||||
if (!primitive) primitive = NEW CardPrimitive();
|
||||
if (0 == strcmp("Bloodrock Cyclops", val)) cout << "val" << endl;
|
||||
primitive->setName(val);
|
||||
break;
|
||||
|
||||
case 'p':
|
||||
if ('r' == key[1])
|
||||
{ // primitive
|
||||
if (!card)
|
||||
card = NEW MTGCard();
|
||||
if (!card) card = NEW MTGCard();
|
||||
map<string, CardPrimitive*>::iterator it = primitives.find(val);
|
||||
if (it != primitives.end())
|
||||
card->setPrimitive(it->second);
|
||||
if (it != primitives.end()) card->setPrimitive(it->second);
|
||||
}
|
||||
else
|
||||
{ //power
|
||||
if (!primitive)
|
||||
primitive = NEW CardPrimitive();
|
||||
if (!primitive) primitive = NEW CardPrimitive();
|
||||
primitive->setPower(atoi(val));
|
||||
}
|
||||
break;
|
||||
@@ -216,8 +201,7 @@ int MTGAllCards::processConfLine(string &s, MTGCard *card, CardPrimitive * primi
|
||||
case 'r': //retrace/rarity
|
||||
if ('e' == key[1])
|
||||
{ //retrace
|
||||
if (!primitive)
|
||||
primitive = NEW CardPrimitive();
|
||||
if (!primitive) primitive = NEW CardPrimitive();
|
||||
if (ManaCost * cost = primitive->getManaCost())
|
||||
{
|
||||
string value = val;
|
||||
@@ -227,15 +211,13 @@ int MTGAllCards::processConfLine(string &s, MTGCard *card, CardPrimitive * primi
|
||||
}
|
||||
else
|
||||
{//rarity
|
||||
if (!card)
|
||||
card = NEW MTGCard();
|
||||
if (!card) card = NEW MTGCard();
|
||||
card->setRarity(val[0]);
|
||||
}
|
||||
break;
|
||||
|
||||
case 's': //subtype
|
||||
if (!primitive)
|
||||
primitive = NEW CardPrimitive();
|
||||
if (!primitive) primitive = NEW CardPrimitive();
|
||||
while (true)
|
||||
{
|
||||
char* found = strchr(val, ' ');
|
||||
@@ -254,8 +236,7 @@ int MTGAllCards::processConfLine(string &s, MTGCard *card, CardPrimitive * primi
|
||||
break;
|
||||
|
||||
case 't':
|
||||
if (!primitive)
|
||||
primitive = NEW CardPrimitive();
|
||||
if (!primitive) primitive = NEW CardPrimitive();
|
||||
if (0 == strcmp("target", key))
|
||||
{
|
||||
string value = val;
|
||||
@@ -282,12 +263,11 @@ int MTGAllCards::processConfLine(string &s, MTGCard *card, CardPrimitive * primi
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (0 == strcmp("toughness", key))
|
||||
primitive->setToughness(atoi(val));
|
||||
else if (0 == strcmp("toughness", key)) primitive->setToughness(atoi(val));
|
||||
break;
|
||||
|
||||
default:
|
||||
DebugTrace("MTGDECK Parsing Error: " << s);
|
||||
DebugTrace( endl << "MTGDECK Parsing Error: " << " [" << primitive->getName() << "]" << s << std::endl);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -321,8 +301,7 @@ int MTGAllCards::load(const char * config_file, const char * set_name, int autol
|
||||
MTGSetInfo *si = setlist.getInfo(set_id);
|
||||
|
||||
std::ifstream setFile(config_file, ios::in | ios::ate);
|
||||
if (!setFile)
|
||||
return total_cards;
|
||||
if (!setFile) return total_cards;
|
||||
|
||||
streampos fileSize = setFile.tellg();
|
||||
setFile.seekg(0, ios::beg);
|
||||
@@ -336,13 +315,10 @@ int MTGAllCards::load(const char * config_file, const char * set_name, int autol
|
||||
|
||||
while (true)
|
||||
{
|
||||
if (!std::getline(stream, s))
|
||||
return total_cards;
|
||||
if (!s.size())
|
||||
continue;
|
||||
if (!std::getline(stream, s)) return total_cards;
|
||||
if (!s.size()) continue;
|
||||
|
||||
if (s[s.size() - 1] == '\r')
|
||||
s.erase(s.size() - 1); // Handle DOS files
|
||||
if (s[s.size() - 1] == '\r') s.erase(s.size() - 1); // Handle DOS files
|
||||
switch (conf_read_mode)
|
||||
{
|
||||
case MTGAllCards::READ_ANYTHING:
|
||||
@@ -358,8 +334,7 @@ int MTGAllCards::load(const char * config_file, const char * set_name, int autol
|
||||
{
|
||||
int fileGrade = getGrade(s[8]);
|
||||
int maxGrade = options[Options::MAX_GRADE].number;
|
||||
if (!maxGrade)
|
||||
maxGrade = Constants::GRADE_BORDERLINE; //Default setting for grade is borderline?
|
||||
if (!maxGrade) maxGrade = Constants::GRADE_BORDERLINE; //Default setting for grade is borderline?
|
||||
if (fileGrade > maxGrade)
|
||||
{
|
||||
return total_cards;
|
||||
@@ -370,19 +345,16 @@ int MTGAllCards::load(const char * config_file, const char * set_name, int autol
|
||||
case MTGAllCards::READ_METADATA:
|
||||
if (s[0] == '[' && s[1] == '/')
|
||||
conf_read_mode = MTGAllCards::READ_ANYTHING;
|
||||
else if (si)
|
||||
si->processConfLine(s);
|
||||
else if (si) si->processConfLine(s);
|
||||
continue;
|
||||
case MTGAllCards::READ_CARD:
|
||||
if (s[0] == '[' && s[1] == '/')
|
||||
{
|
||||
conf_read_mode = MTGAllCards::READ_ANYTHING;
|
||||
if (tempPrimitive)
|
||||
tempPrimitive = addPrimitive(tempPrimitive, tempCard);
|
||||
if (tempPrimitive) tempPrimitive = addPrimitive(tempPrimitive, tempCard);
|
||||
if (tempCard)
|
||||
{
|
||||
if (tempPrimitive)
|
||||
tempCard->setPrimitive(tempPrimitive);
|
||||
if (tempPrimitive) tempCard->setPrimitive(tempPrimitive);
|
||||
addCardToCollection(tempCard, set_id);
|
||||
}
|
||||
tempCard = NULL;
|
||||
@@ -395,7 +367,6 @@ int MTGAllCards::load(const char * config_file, const char * set_name, int autol
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return total_cards;
|
||||
}
|
||||
|
||||
@@ -517,8 +488,7 @@ bool MTGAllCards::addCardToCollection(MTGCard * card, int setId)
|
||||
|
||||
collection[newId] = card; //Push card into collection.
|
||||
MTGSetInfo * si = setlist.getInfo(setId);
|
||||
if (si)
|
||||
si->count(card); //Count card in set info
|
||||
if (si) si->count(card); //Count card in set info
|
||||
++total_cards;
|
||||
return true;
|
||||
}
|
||||
@@ -526,8 +496,7 @@ bool MTGAllCards::addCardToCollection(MTGCard * card, int setId)
|
||||
CardPrimitive * MTGAllCards::addPrimitive(CardPrimitive * primitive, MTGCard * card)
|
||||
{
|
||||
int maxGrade = options[Options::MAX_GRADE].number;
|
||||
if (!maxGrade)
|
||||
maxGrade = Constants::GRADE_BORDERLINE; //Default setting for grade is borderline?
|
||||
if (!maxGrade) maxGrade = Constants::GRADE_BORDERLINE; //Default setting for grade is borderline?
|
||||
if (currentGrade > maxGrade)
|
||||
{
|
||||
SAFE_DELETE(primitive);
|
||||
@@ -546,7 +515,7 @@ CardPrimitive * MTGAllCards::addPrimitive(CardPrimitive * primitive, MTGCard * c
|
||||
{
|
||||
//ERROR
|
||||
//Todo move the deletion somewhere else ?
|
||||
DebugTrace ("MTGDECK: primitives conflict: "<< key);
|
||||
DebugTrace("MTGDECK: primitives conflict: "<< key);
|
||||
SAFE_DELETE(primitive);
|
||||
return NULL;
|
||||
}
|
||||
@@ -579,17 +548,14 @@ MTGCard * MTGAllCards::getCardById(int id)
|
||||
|
||||
MTGCard * MTGAllCards::_(int index)
|
||||
{
|
||||
if (index >= total_cards)
|
||||
return NULL;
|
||||
if (index >= total_cards) return NULL;
|
||||
return getCardById(ids[index]);
|
||||
}
|
||||
|
||||
MTGCard * MTGAllCards::getCardByName(string name)
|
||||
{
|
||||
if (!name.size())
|
||||
return NULL;
|
||||
if (name[0] == '#')
|
||||
return NULL;
|
||||
if (!name.size()) return NULL;
|
||||
if (name[0] == '#') return NULL;
|
||||
|
||||
int cardnb = atoi(name.c_str());
|
||||
if (cardnb)
|
||||
@@ -613,12 +579,10 @@ MTGCard * MTGAllCards::getCardByName(string name)
|
||||
for (it = collection.begin(); it != collection.end(); it++)
|
||||
{
|
||||
MTGCard * c = it->second;
|
||||
if (setId != -1 && setId != c->setId)
|
||||
continue;
|
||||
if (setId != -1 && setId != c->setId) continue;
|
||||
string cardName = c->data->name;
|
||||
std::transform(cardName.begin(), cardName.end(), cardName.begin(), ::tolower);
|
||||
if (cardName.compare(name) == 0)
|
||||
return c;
|
||||
if (cardName.compare(name) == 0) return c;
|
||||
|
||||
}
|
||||
return NULL;
|
||||
@@ -632,6 +596,7 @@ MTGDeck::MTGDeck(MTGAllCards * _allcards)
|
||||
filename = "";
|
||||
meta_name = "";
|
||||
}
|
||||
|
||||
int MTGDeck::totalPrice()
|
||||
{
|
||||
int total = 0;
|
||||
@@ -640,12 +605,12 @@ int MTGDeck::totalPrice()
|
||||
for (it = cards.begin(); it != cards.end(); it++)
|
||||
{
|
||||
int nb = it->second;
|
||||
if (nb)
|
||||
total += pricelist->getPrice(it->first);
|
||||
if (nb) total += pricelist->getPrice(it->first);
|
||||
}
|
||||
SAFE_DELETE(pricelist);
|
||||
return total;
|
||||
}
|
||||
|
||||
MTGDeck::MTGDeck(const char * config_file, MTGAllCards * _allcards, int meta_only)
|
||||
{
|
||||
total_cards = 0;
|
||||
@@ -661,10 +626,8 @@ MTGDeck::MTGDeck(const char * config_file, MTGAllCards * _allcards, int meta_onl
|
||||
{
|
||||
while (std::getline(file, s))
|
||||
{
|
||||
if (!s.size())
|
||||
continue;
|
||||
if (s[s.size() - 1] == '\r')
|
||||
s.erase(s.size() - 1); //Handle DOS files
|
||||
if (!s.size()) continue;
|
||||
if (s[s.size() - 1] == '\r') s.erase(s.size() - 1); //Handle DOS files
|
||||
if (s[0] == '#')
|
||||
{
|
||||
size_t found = s.find("NAME:");
|
||||
@@ -676,15 +639,13 @@ MTGDeck::MTGDeck(const char * config_file, MTGAllCards * _allcards, int meta_onl
|
||||
found = s.find("DESC:");
|
||||
if (found != string::npos)
|
||||
{
|
||||
if (meta_desc.size())
|
||||
meta_desc.append("\n");
|
||||
if (meta_desc.size()) meta_desc.append("\n");
|
||||
meta_desc.append(s.substr(found + 5));
|
||||
continue;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (meta_only)
|
||||
break;
|
||||
if (meta_only) break;
|
||||
int cardnb = atoi(s.c_str());
|
||||
if (cardnb)
|
||||
{
|
||||
@@ -733,8 +694,7 @@ MTGCard * MTGDeck::getCardById(int mtgId)
|
||||
|
||||
int MTGDeck::addRandomCards(int howmany, int * setIds, int nbSets, int rarity, const char * _subtype, int * colors, int nbcolors)
|
||||
{
|
||||
if (howmany <= 0)
|
||||
return 1;
|
||||
if (howmany <= 0) return 1;
|
||||
|
||||
int unallowedColors[Constants::MTG_NB_COLORS + 1];
|
||||
for (int i = 0; i < Constants::MTG_NB_COLORS; ++i)
|
||||
@@ -750,12 +710,10 @@ int MTGDeck::addRandomCards(int howmany, int * setIds, int nbSets, int rarity, c
|
||||
}
|
||||
|
||||
int collectionTotal = database->totalCards();
|
||||
if (!collectionTotal)
|
||||
return 0;
|
||||
if (!collectionTotal) return 0;
|
||||
|
||||
char subtype[4096];
|
||||
if (_subtype)
|
||||
sprintf(subtype, "%s", _subtype);
|
||||
if (_subtype) sprintf(subtype, "%s", _subtype);
|
||||
|
||||
vector<int> subcollection;
|
||||
int subtotal = 0;
|
||||
@@ -769,8 +727,7 @@ int MTGDeck::addRandomCards(int howmany, int * setIds, int nbSets, int rarity, c
|
||||
{
|
||||
int ok = 0;
|
||||
|
||||
if (!nbSets)
|
||||
ok = 1;
|
||||
if (!nbSets) ok = 1;
|
||||
for (int j = 0; j < nbSets; ++j)
|
||||
{
|
||||
if (card->setId == setIds[j])
|
||||
@@ -801,8 +758,8 @@ int MTGDeck::addRandomCards(int howmany, int * setIds, int nbSets, int rarity, c
|
||||
}
|
||||
if (subtotal == 0)
|
||||
{
|
||||
if (rarity == Constants::RARITY_M)
|
||||
return addRandomCards(howmany, setIds, nbSets, Constants::RARITY_R, _subtype, colors, nbcolors);
|
||||
if (rarity == Constants::RARITY_M) return addRandomCards(howmany, setIds, nbSets, Constants::RARITY_R, _subtype, colors,
|
||||
nbcolors);
|
||||
return 0;
|
||||
}
|
||||
for (int i = 0; i < howmany; i++)
|
||||
@@ -828,8 +785,7 @@ int MTGDeck::add(MTGDeck * deck)
|
||||
|
||||
int MTGDeck::add(int cardid)
|
||||
{
|
||||
if (!database->getCardById(cardid))
|
||||
return 0;
|
||||
if (!database->getCardById(cardid)) return 0;
|
||||
if (cards.find(cardid) == cards.end())
|
||||
{
|
||||
cards[cardid] = 1;
|
||||
@@ -845,8 +801,7 @@ int MTGDeck::add(int cardid)
|
||||
|
||||
int MTGDeck::add(MTGCard * card)
|
||||
{
|
||||
if (!card)
|
||||
return 0;
|
||||
if (!card) return 0;
|
||||
return (add(card->getId()));
|
||||
}
|
||||
|
||||
@@ -897,8 +852,7 @@ int MTGDeck::removeAll()
|
||||
|
||||
int MTGDeck::remove(int cardid)
|
||||
{
|
||||
if (cards.find(cardid) == cards.end() || cards[cardid] == 0)
|
||||
return 0;
|
||||
if (cards.find(cardid) == cards.end() || cards[cardid] == 0) return 0;
|
||||
cards[cardid]--;
|
||||
total_cards--;
|
||||
//initCounters();
|
||||
@@ -907,8 +861,7 @@ int MTGDeck::remove(int cardid)
|
||||
|
||||
int MTGDeck::remove(MTGCard * card)
|
||||
{
|
||||
if (!card)
|
||||
return 0;
|
||||
if (!card) return 0;
|
||||
return (remove(card->getId()));
|
||||
}
|
||||
|
||||
@@ -1000,8 +953,7 @@ MTGSets::~MTGSets()
|
||||
|
||||
MTGSetInfo* MTGSets::getInfo(int setID)
|
||||
{
|
||||
if (setID < 0 || setID >= (int) setinfo.size())
|
||||
return NULL;
|
||||
if (setID < 0 || setID >= (int) setinfo.size()) return NULL;
|
||||
|
||||
return setinfo[setID];
|
||||
}
|
||||
@@ -1022,8 +974,8 @@ MTGSetInfo* MTGSets::randomSet(int blockId, int atleast)
|
||||
a = rand() % size();
|
||||
for (int i = a; i < size(); i++)
|
||||
{
|
||||
if (unlocked[i] && (blockId == -1 || setinfo[i]->block == blockId) && (atleast == -1 || setinfo[i]->totalCards()
|
||||
>= atleast))
|
||||
if (unlocked[i] && (blockId == -1 || setinfo[i]->block == blockId) &&
|
||||
(atleast == -1 || setinfo[i]->totalCards() >= atleast))
|
||||
{
|
||||
free(unlocked);
|
||||
return setinfo[i];
|
||||
@@ -1031,8 +983,8 @@ MTGSetInfo* MTGSets::randomSet(int blockId, int atleast)
|
||||
}
|
||||
for (int i = 0; i < a; i++)
|
||||
{
|
||||
if (unlocked[i] && (blockId == -1 || setinfo[i]->block == blockId) && (atleast == -1 || setinfo[i]->totalCards()
|
||||
>= atleast))
|
||||
if (unlocked[i] && (blockId == -1 || setinfo[i]->block == blockId) &&
|
||||
(atleast == -1 || setinfo[i]->totalCards() >= atleast))
|
||||
{
|
||||
free(unlocked);
|
||||
return setinfo[i];
|
||||
@@ -1040,19 +992,18 @@ MTGSetInfo* MTGSets::randomSet(int blockId, int atleast)
|
||||
}
|
||||
blockId = -1;
|
||||
iter++;
|
||||
if (iter == 2)
|
||||
atleast = -1;
|
||||
if (iter == 2) atleast = -1;
|
||||
}
|
||||
free(unlocked);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int blockSize(int blockId);
|
||||
|
||||
int MTGSets::Add(const char * name)
|
||||
{
|
||||
int setid = findSet(name);
|
||||
if (setid != -1)
|
||||
return setid;
|
||||
if (setid != -1) return setid;
|
||||
|
||||
MTGSetInfo* s = NEW MTGSetInfo(name);
|
||||
setinfo.push_back(s);
|
||||
@@ -1068,20 +1019,17 @@ int MTGSets::findSet(string name)
|
||||
for (int i = 0; i < (int) setinfo.size(); i++)
|
||||
{
|
||||
MTGSetInfo* s = setinfo[i];
|
||||
if (!s)
|
||||
continue;
|
||||
if (!s) continue;
|
||||
string set = s->id;
|
||||
std::transform(set.begin(), set.end(), set.begin(), ::tolower);
|
||||
if (set.compare(name) == 0)
|
||||
return i;
|
||||
if (set.compare(name) == 0) return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int MTGSets::findBlock(string s)
|
||||
{
|
||||
if (!s.size())
|
||||
return -1;
|
||||
if (!s.size()) return -1;
|
||||
|
||||
string comp = s;
|
||||
std::transform(comp.begin(), comp.end(), comp.begin(), ::tolower);
|
||||
@@ -1089,8 +1037,7 @@ int MTGSets::findBlock(string s)
|
||||
{
|
||||
string b = blocks[i];
|
||||
std::transform(b.begin(), b.end(), b.begin(), ::tolower);
|
||||
if (b.compare(comp) == 0)
|
||||
return i;
|
||||
if (b.compare(comp) == 0) return i;
|
||||
}
|
||||
|
||||
blocks.push_back(s);
|
||||
@@ -1101,24 +1048,23 @@ int MTGSets::operator[](string id)
|
||||
{
|
||||
return findSet(id);
|
||||
}
|
||||
|
||||
string MTGSets::operator[](int id)
|
||||
{
|
||||
if (id < 0 || id >= (int) setinfo.size())
|
||||
return "";
|
||||
if (id < 0 || id >= (int) setinfo.size()) return "";
|
||||
|
||||
MTGSetInfo * si = setinfo[id];
|
||||
if (!si)
|
||||
return "";
|
||||
if (!si) return "";
|
||||
|
||||
return si->id;
|
||||
}
|
||||
|
||||
int MTGSets::getSetNum(MTGSetInfo*i)
|
||||
{
|
||||
int it;
|
||||
for (it = 0; it < size(); it++)
|
||||
{
|
||||
if (setinfo[it] == i)
|
||||
return it;
|
||||
if (setinfo[it] == i) return it;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
@@ -1132,6 +1078,7 @@ MTGSetInfo::~MTGSetInfo()
|
||||
{
|
||||
SAFE_DELETE(mPack);
|
||||
}
|
||||
|
||||
MTGSetInfo::MTGSetInfo(string _id)
|
||||
{
|
||||
string whitespaces(" \t\f\v\n\r");
|
||||
@@ -1155,8 +1102,7 @@ MTGSetInfo::MTGSetInfo(string _id)
|
||||
|
||||
void MTGSetInfo::count(MTGCard*c)
|
||||
{
|
||||
if (!c)
|
||||
return;
|
||||
if (!c) return;
|
||||
|
||||
switch (c->getRarity())
|
||||
{
|
||||
@@ -1188,22 +1134,21 @@ int MTGSetInfo::totalCards()
|
||||
|
||||
string MTGSetInfo::getName()
|
||||
{
|
||||
if (name.size())
|
||||
return name; //Pretty name is translated when rendering.
|
||||
if (name.size()) return name; //Pretty name is translated when rendering.
|
||||
return id; //Ugly name as well.
|
||||
}
|
||||
|
||||
string MTGSetInfo::getBlock()
|
||||
{
|
||||
if (block < 0 || block >= (int) setlist.blocks.size())
|
||||
return "None";
|
||||
if (block < 0 || block >= (int) setlist.blocks.size()) return "None";
|
||||
|
||||
return setlist.blocks[block];
|
||||
}
|
||||
|
||||
void MTGSetInfo::processConfLine(string line)
|
||||
{
|
||||
size_t i = line.find_first_of("=");
|
||||
if (i == string::npos)
|
||||
return;
|
||||
if (i == string::npos) return;
|
||||
|
||||
string key = line.substr(0, i);
|
||||
std::transform(key.begin(), key.end(), key.begin(), ::tolower);
|
||||
@@ -1215,6 +1160,5 @@ void MTGSetInfo::processConfLine(string line)
|
||||
author = value;
|
||||
else if (key.compare("block") == 0)
|
||||
block = setlist.findBlock(value.c_str());
|
||||
else if (key.compare("year") == 0)
|
||||
year = atoi(value.c_str());
|
||||
else if (key.compare("year") == 0) year = atoi(value.c_str());
|
||||
}
|
||||
|
||||
115
projects/mtg/src/SimplePopup.cpp
Normal file
115
projects/mtg/src/SimplePopup.cpp
Normal file
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* SimplePopup.cpp
|
||||
*
|
||||
* Created on: Nov 18, 2010
|
||||
* Author: Michael
|
||||
*/
|
||||
|
||||
#include "PrecompiledHeader.h"
|
||||
#include "SimplePopup.h"
|
||||
#include "JTypes.h"
|
||||
#include "GameApp.h"
|
||||
#include "DeckStats.h"
|
||||
#include "DeckManager.h"
|
||||
#include <iomanip>
|
||||
|
||||
SimplePopup::SimplePopup(int id, JGuiListener* listener, const int fontId, const char * _title, DeckMetaData* deckMetaData, MTGAllCards * collection) :
|
||||
JGuiController(id, listener), mFontId(fontId), mCollection(collection)
|
||||
{
|
||||
mX = 35;
|
||||
mY = 50;
|
||||
mTitle = _title;
|
||||
mMaxLines = 10;
|
||||
mTextFont = resources.GetWFont(fontId);
|
||||
this->mCount = 1;
|
||||
stw = NULL;
|
||||
Update(deckMetaData);
|
||||
}
|
||||
|
||||
void SimplePopup::Render()
|
||||
{
|
||||
closed = false;
|
||||
|
||||
JRenderer *r = JRenderer::GetInstance();
|
||||
string detailedInformation = getDetailedInformation(mDeckInformation->getFilename());
|
||||
|
||||
mTextFont->SetScale(0.85f);
|
||||
const float textWidth = 183.0f;
|
||||
const float textHeight = mTextFont->GetHeight() * 10;
|
||||
r->DrawRoundRect(mX, mY, textWidth, textHeight, 2.0f, ARGB( 255, 125, 255, 0) );
|
||||
r->FillRoundRect(mX, mY, textWidth, textHeight, 2.0f, ARGB( 255, 0, 0, 0 ) );
|
||||
|
||||
mTextFont->DrawString(detailedInformation.c_str(), mX + 20 , mY + 10);
|
||||
|
||||
}
|
||||
void SimplePopup::Update(DeckMetaData* selectedDeck)
|
||||
{
|
||||
mDeckInformation = selectedDeck;
|
||||
SAFE_DELETE(stw);
|
||||
stw = NEW StatsWrapper(mDeckInformation->getDeckId());
|
||||
stw->updateStats(mDeckInformation->getFilename(), mCollection);
|
||||
}
|
||||
|
||||
|
||||
string SimplePopup::getDetailedInformation(string filename)
|
||||
{
|
||||
ostringstream oss;
|
||||
oss
|
||||
<< "------- Deck Summary -----" << endl
|
||||
<< "Cards: "<< stw->cardCount << endl
|
||||
<< "Creatures: "<< setw(2) << stw->countCreatures
|
||||
<< " Enchantments: " << stw->countEnchantments << endl
|
||||
<< "Instants: " << setw(4) << stw->countInstants
|
||||
<< " Sorceries: " << setw(2) << stw->countSorceries << endl
|
||||
<< "Lands: "
|
||||
<< "A: " << setw(2) << left << stw->countLandsPerColor[ Constants::MTG_COLOR_ARTIFACT ] + stw->countBasicLandsPerColor[ Constants::MTG_COLOR_ARTIFACT ] << " "
|
||||
<< "G: " << setw(2) << left << stw->countLandsPerColor[ Constants::MTG_COLOR_GREEN ] + stw->countLandsPerColor[ Constants::MTG_COLOR_GREEN ] << " "
|
||||
<< "R: " << setw(2) << left << stw->countLandsPerColor[ Constants::MTG_COLOR_RED ] + stw->countBasicLandsPerColor[ Constants::MTG_COLOR_RED ] << " "
|
||||
<< "U: " << setw(2) << left << stw->countLandsPerColor[ Constants::MTG_COLOR_BLUE ] + stw->countBasicLandsPerColor[ Constants::MTG_COLOR_BLUE ] << " "
|
||||
<< "B: " << setw(2) << left << stw->countLandsPerColor[ Constants::MTG_COLOR_BLACK ] + stw->countBasicLandsPerColor[ Constants::MTG_COLOR_BLACK ] << " "
|
||||
<< "W: " << setw(2) << left << stw->countLandsPerColor[ Constants::MTG_COLOR_WHITE ] + stw->countBasicLandsPerColor[ Constants::MTG_COLOR_WHITE ] << endl
|
||||
<< " --- Mana Curve --- " << endl;
|
||||
|
||||
for ( int costIdx = 0; costIdx < 15; ++costIdx )
|
||||
if ( stw->countCardsPerCost[ costIdx ] > 0 )
|
||||
oss << costIdx << ": " << setw(2) << left << stw->countCardsPerCost[ costIdx ] << " ";
|
||||
|
||||
oss << endl;
|
||||
|
||||
oss
|
||||
<< " --- Average Cost --- " << endl
|
||||
<< "Creature: "<< setprecision(2) << stw->avgCreatureCost << endl
|
||||
<< "Mana: " << setprecision(2) << stw->avgManaCost << " "
|
||||
<< "Spell: " << setprecision(2) << stw->avgSpellCost << endl;
|
||||
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
void SimplePopup::Update(float dt)
|
||||
{
|
||||
JButton key = mEngine->ReadButton();
|
||||
CheckUserInput(key);
|
||||
}
|
||||
|
||||
void SimplePopup::Close()
|
||||
{
|
||||
closed = true;
|
||||
mCount = 0;
|
||||
}
|
||||
|
||||
SimplePopup::~SimplePopup(void)
|
||||
{
|
||||
mTextFont = NULL;
|
||||
mDeckInformation = NULL;
|
||||
SAFE_DELETE(stw);
|
||||
}
|
||||
|
||||
void SimplePopup::drawHorzPole(float x, float y, float width)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void SimplePopup::drawVertPole(float x, float y, float height)
|
||||
{
|
||||
|
||||
}
|
||||
@@ -837,6 +837,10 @@
|
||||
RelativePath=".\src\SimplePad.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\SimplePopup.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\StoryFlow.cpp"
|
||||
>
|
||||
@@ -1254,6 +1258,10 @@
|
||||
RelativePath=".\include\Rules.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\ShopItem.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\SimpleMenu.h"
|
||||
>
|
||||
@@ -1266,6 +1274,10 @@
|
||||
RelativePath=".\include\SimplePad.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\SimplePopup.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\StoryFlow.h"
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user