* ostream printing of JGui objects.
This commit is contained in:
jean.chalard
2009-05-23 08:34:50 +00:00
parent 215e23a975
commit dd054c4963
32 changed files with 1505 additions and 528 deletions

View File

@@ -62,6 +62,7 @@ class NextGamePhase: public Interruptible {
public:
int resolve();
void Render();
virtual ostream& toString(ostream& out) const;
NextGamePhase(int id);
};
@@ -75,6 +76,7 @@ class Spell: public Interruptible, public TargetsList {
~Spell();
int resolve();
void Render();
virtual ostream& toString(ostream& out) const;
};
class StackAbility: public Interruptible {
@@ -82,6 +84,7 @@ class StackAbility: public Interruptible {
MTGAbility * ability;
int resolve();
void Render();
virtual ostream& toString(ostream& out) const;
StackAbility(int id, MTGAbility * _ability);
};
@@ -91,6 +94,7 @@ class PutInGraveyard: public Interruptible {
int removeFromGame;
int resolve();
void Render();
virtual ostream& toString(ostream& out) const;
PutInGraveyard(int id, MTGCardInstance * _card);
};
@@ -101,6 +105,7 @@ class DrawAction: public Interruptible {
Player * player;
int resolve();
void Render();
virtual ostream& toString(ostream& out) const;
DrawAction(int id, Player * _player, int _nbcards);
};

File diff suppressed because it is too large Load Diff

View File

@@ -20,6 +20,7 @@ class CardDisplay:public PlayGuiObjectController{
bool CheckUserInput(u32 key);
void Render();
void init(MTGGameZone * zone);
virtual ostream& toString(ostream& out) const;
};
@@ -29,4 +30,7 @@ class DefaultTargetDisplay:CardDisplay{
DefaultTargetDisplay(int id, GameObserver* _game, int _x, int _y, JGuiListener * _listener, int _nb_displayed_items );
~DefaultTargetDisplay();
};
std::ostream& operator<<(std::ostream& out, const CardDisplay& m);
#endif

View File

@@ -20,6 +20,7 @@ class CardGui: public PlayGuiObject{
CardGui(int id, MTGCardInstance * _card, float desiredHeight, float _x=0, float _y=0, bool hasFocus = false);
virtual void Render();
virtual void Update(float dt);
virtual ostream& toString(ostream& out) const;
void RenderBig(float x=-1, float y = -1, int alternate = 0);
static void alternateRender(MTGCard * card, JQuad ** manaIcons, float x, float y, float rotation= 0, float scale=1);

View File

@@ -36,6 +36,7 @@ class Damage: public Interruptible {
Damage(int id, MTGCardInstance* _source, Damageable * _target);
Damage(int id, MTGCardInstance* _source, Damageable * _target, int _damage);
int resolve();
virtual ostream& toString(ostream& out) const;
};
@@ -49,6 +50,7 @@ class DamageStack :public GuiLayer, public Interruptible{
void Render();
int CombatDamages();//Deprecated ?
int CombatDamages(int strike);
virtual ostream& toString(ostream& out) const;
DamageStack(int id, GameObserver* _game);
};

View File

@@ -54,6 +54,7 @@ class GameStateMenu: public GameState, public JGuiListener
int nextCardSet(); // Retrieves the next set subfolder automatically
void createUsersFirstDeck(int setId);
virtual ostream& toString(ostream& out) const;
};
#endif

View File

@@ -25,8 +25,8 @@ using std::map;
//Two stupid variables used to give a hint to the AI:
// Should I cast a spell on an enemy or friendly unit ?
#define BAKA_EFFECT_GOOD 1
#define BAKA_EFFECT_BAD -1
#define BAKA_EFFECT_GOOD 1
#define BAKA_EFFECT_BAD -1
#define BAKA_EFFECT_DONTKNOW 0
#define COUNT_POWER 1
@@ -38,7 +38,7 @@ using std::map;
class MTGAbility: public ActionElement{
protected:
char menuText[25];
GameObserver * game;
public:
int forceDestroy;
@@ -58,6 +58,7 @@ class MTGAbility: public ActionElement{
virtual int fireAbility();
virtual int stillInUse(MTGCardInstance * card){if (card==source) return 1; return 0;};
virtual int resolve(){return 0;};
virtual ostream& toString(ostream& out) const;
/*Poor man's casting */
/* Todo replace that crap with dynamic casting */
@@ -70,7 +71,6 @@ class MTGAbility: public ActionElement{
PUT_INTO_PLAY = 5,
MOMIR = 6,
MTG_BLOCK_RULE = 7,
};
};
@@ -83,6 +83,7 @@ class TriggeredAbility:public MTGAbility{
virtual void Render(){};
virtual int trigger()=0;
virtual int resolve() = 0;
virtual ostream& toString(ostream& out) const;
};
@@ -95,6 +96,7 @@ class ActivatedAbility:public MTGAbility{
virtual int isReactingToClick(MTGCardInstance * card, ManaCost * mana = NULL);
virtual int reactToTargetClick(Targetable * object);
virtual int resolve() = 0;
virtual ostream& toString(ostream& out) const;
};
class TargetAbility:public ActivatedAbility{
@@ -105,6 +107,7 @@ class TargetAbility:public ActivatedAbility{
virtual int reactToClick(MTGCardInstance * card);
virtual int reactToTargetClick(Targetable * object);
virtual void Render();
virtual ostream& toString(ostream& out) const;
};
class InstantAbility:public MTGAbility{
@@ -115,6 +118,7 @@ class InstantAbility:public MTGAbility{
InstantAbility(int _id, MTGCardInstance * source);
InstantAbility(int _id, MTGCardInstance * source,Damageable * _target);
virtual int resolve(){return 0;};
virtual ostream& toString(ostream& out) const;
};
/* State based effects. This class works ONLY for InPlay and needs to be extended for other areas of the game !!! */
@@ -129,6 +133,7 @@ class ListMaintainerAbility:public MTGAbility{
virtual int added(MTGCardInstance * card) = 0;
virtual int removed(MTGCardInstance * card) = 0;
virtual int destroy();
virtual ostream& toString(ostream& out) const;
};
/* An attempt to globalize triggered abilities as much as possible */
@@ -234,7 +239,7 @@ class AbilityFactory{
class AManaProducer: public MTGAbility{
protected:
ManaCost * cost;
ManaCost * output;
string menutext;
@@ -255,9 +260,10 @@ class AManaProducer: public MTGAbility{
const char * getMenuText();
int testDestroy();
~AManaProducer();
virtual ostream& toString(ostream& out) const;
};
#include "MTGCardInstance.h"
#endif

View File

@@ -18,6 +18,7 @@ class MTGGamePhase: public ActionElement {
virtual void Render();
virtual void Update(float dt);
bool CheckUserInput(u32 key);
virtual ostream& toString(ostream& out) const;
};

View File

@@ -13,9 +13,9 @@ class MTGPutInPlayRule:public MTGAbility{
int isReactingToClick(MTGCardInstance * card, ManaCost * mana = NULL);
int reactToClick(MTGCardInstance * card);
int testDestroy();
virtual ostream& toString(ostream& out) const;
MTGPutInPlayRule(int _id);
const char * getMenuText(){return "Put into play";}
};
class MTGAttackRule:public MTGAbility{
@@ -23,10 +23,10 @@ class MTGAttackRule:public MTGAbility{
int isReactingToClick(MTGCardInstance * card, ManaCost * mana = NULL);
int reactToClick(MTGCardInstance * card);
int testDestroy();
virtual ostream& toString(ostream& out) const;
MTGAttackRule(int _id);
const char * getMenuText(){return "Attacker";}
void Update(float dt);
};
class MTGBlockRule:public MTGAbility{
@@ -34,6 +34,7 @@ class MTGBlockRule:public MTGAbility{
int isReactingToClick(MTGCardInstance * card, ManaCost * mana = NULL);
int reactToClick(MTGCardInstance * card);
int testDestroy();
virtual ostream& toString(ostream& out) const;
MTGBlockRule(int _id);
const char * getMenuText(){return "Blocker";}
};
@@ -78,8 +79,12 @@ OutputDebugString("Receive5\n");
return 0;
}
virtual ostream& toString(ostream& out) const
{
out << "MTGPersistRule ::: (";
return MTGAbility::toString(out) << ")";
}
int testDestroy(){return 0;}
};
@@ -119,6 +124,11 @@ class MTGLegendRule:public ListMaintainerAbility{
int removed(MTGCardInstance * card){return 0;}
int testDestroy(){return 0;}
virtual ostream& toString(ostream& out) const
{
return out << "MTGLegendRule :::";
}
};
@@ -143,6 +153,7 @@ public:
int reactToClick(MTGCardInstance * card);
int reactToClick(MTGCardInstance * card, int id);
const char * getMenuText(){return "Momir";}
virtual ostream& toString(ostream& out) const;
};
@@ -166,6 +177,11 @@ class MTGLifelinkRule:public MTGAbility{
int testDestroy(){return 0;}
virtual ostream& toString(ostream& out) const
{
out << "MTGLifelinkRule ::: (";
return MTGAbility::toString(out) << ")";
}
};

View File

@@ -64,4 +64,6 @@ class ManaCost{
#endif
};
std::ostream& operator<<(std::ostream& out, const ManaCost& m);
#endif

View File

@@ -39,6 +39,8 @@ class MenuItem: public JGuiObject
virtual void Entering();
virtual bool Leaving(u32 key);
virtual bool ButtonPressed();
virtual ostream& toString(ostream& out) const;
};
#endif

View File

@@ -22,6 +22,7 @@ class OptionItem:public JGuiObject{
virtual bool Leaving();
void setData();
virtual void updateValue(){value+=increment; if (value>maxValue) value=0;};
virtual ostream& toString(ostream& out) const;
};
class OptionsList{

View File

@@ -47,6 +47,7 @@ class GuiAvatar: public PlayGuiObject{
Player * player;
virtual void Render();
GuiAvatar(int id, float desiredHeight,float _x, float _y, bool hasFocus,Player * _player);
virtual ostream& toString(ostream& out) const;
};
class GuiGameZone: public PlayGuiObject{
@@ -62,16 +63,19 @@ class GuiGameZone: public PlayGuiObject{
~GuiGameZone();
virtual void ButtonPressed(int controllerId, int controlId);
void toggleDisplay();
virtual ostream& toString(ostream& out) const;
};
class GuiGraveyard: public GuiGameZone{
public:
GuiGraveyard(int id, float desiredHeight,float _x, float _y, bool hasFocus,Player * player);
virtual ostream& toString(ostream& out) const;
};
class GuiLibrary: public GuiGameZone{
public:
GuiLibrary(int id, float desiredHeight,float _x, float _y, bool hasFocus,Player * player);
virtual ostream& toString(ostream& out) const;
};

View File

@@ -46,6 +46,7 @@ class ShopItem:public JGuiObject{
virtual bool ButtonPressed();
const char * getText();
virtual ostream& toString(ostream& out) const;
};
class ShopItems:public JGuiController,public JGuiListener{

View File

@@ -40,6 +40,7 @@ class SimpleMenuItem: public JGuiObject
virtual void Entering();
virtual bool Leaving(u32 key);
virtual bool ButtonPressed();
virtual ostream& toString(ostream& out) const;
};
#endif

View File

@@ -19,7 +19,7 @@ private:
float start;
int timer;
vector<string> strings;
int currentId;
unsigned int currentId;
int mRandom;
public:
void Add(string text);
@@ -28,6 +28,7 @@ public:
TextScroller(JLBFont * font, float x, float y, float width, float speed = 30);
void Render();
void Update(float dt);
virtual ostream& toString(ostream& out) const;
};
#endif
#endif

View File

@@ -7,8 +7,8 @@
#include "../include/GameObserver.h"
#include "../include/Damage.h"
#include "../include/ManaCost.h"
#include "../include/GameOptions.h"
// WALDORF - added to support drawing big cards during interrupts
#include "../include/GameOptions.h"
// WALDORF - added to support drawing big cards during interrupts
#include "../include/CardGui.h"
#include "../include/Translate.h"
@@ -38,6 +38,11 @@ NextGamePhase::NextGamePhase(int id): Interruptible(id){
type = ACTION_NEXTGAMEPHASE;
}
ostream& NextGamePhase::toString(ostream& out) const
{
out << "NextGamePhase ::: ";
return out;
}
/* Ability */
int StackAbility::resolve(){
@@ -64,6 +69,11 @@ StackAbility::StackAbility(int id,MTGAbility * _ability): Interruptible(id),abil
type=ACTION_ABILITY;
}
ostream& StackAbility::toString(ostream& out) const
{
out << "StackAbility ::: ability : " << ability;
return out;
}
/* Spell Cast */
@@ -121,36 +131,36 @@ void Spell::Render(){
}else{
//
}
// WALDORF - added these lines to render a big card as well as the small one
// in the interrupt window. A big card will be rendered no matter whether
// the user has been using big cards or not. However, I do take into which
// kind of big card they like.
// The card will be rendered in the same place as the GuiHand
// card. It doesn't attempt to hide the GUIHand card, it
// just overwrites it.
// I stole the render code from RenderBig() in CardGUI.cpp
quad = source->getQuad();
if (quad){
quad->SetColor(ARGB(220,255,255,255));
float scale = 257.f / quad->mHeight;
renderer->RenderQuad(quad, 10 , 20 , 0.0f,scale,scale);
}
else
{
MTGCard * mtgcard = source->model;
JLBFont * font = GameApp::CommonRes->GetJLBFont("graphics/magic");
CardGui::alternateRender(mtgcard, NULL, 10 + 90 , 20 + 130, 0.0f,0.9f);
quad = source->getThumb();
if (quad){
float scale = 250 / quad->mHeight;
quad->SetColor(ARGB(40,255,255,255));
renderer->RenderQuad(quad, 20, 20, 0.0f, scale, scale);
}
}
// WALDORF - end
// WALDORF - added these lines to render a big card as well as the small one
// in the interrupt window. A big card will be rendered no matter whether
// the user has been using big cards or not. However, I do take into which
// kind of big card they like.
// The card will be rendered in the same place as the GuiHand
// card. It doesn't attempt to hide the GUIHand card, it
// just overwrites it.
// I stole the render code from RenderBig() in CardGUI.cpp
quad = source->getQuad();
if (quad){
quad->SetColor(ARGB(220,255,255,255));
float scale = 257.f / quad->mHeight;
renderer->RenderQuad(quad, 10 , 20 , 0.0f,scale,scale);
}
else
{
MTGCard * mtgcard = source->model;
JLBFont * font = GameApp::CommonRes->GetJLBFont("graphics/magic");
CardGui::alternateRender(mtgcard, NULL, 10 + 90 , 20 + 130, 0.0f,0.9f);
quad = source->getThumb();
if (quad){
float scale = 250 / quad->mHeight;
quad->SetColor(ARGB(40,255,255,255));
renderer->RenderQuad(quad, 20, 20, 0.0f, scale, scale);
}
}
// WALDORF - end
Damageable * target = getNextDamageableTarget();
@@ -167,6 +177,12 @@ void Spell::Render(){
}
}
ostream& Spell::toString(ostream& out) const
{
out << "Spell ::: cost : " << cost;
return out;
}
/* Put a card in graveyard */
@@ -206,6 +222,11 @@ void PutInGraveyard::Render(){
}
}
ostream& PutInGraveyard::toString(ostream& out) const
{
out << "PutInGraveyard ::: removeFromGame : " << removeFromGame;
return out;
}
/* Draw a Card */
DrawAction::DrawAction(int id, Player * _player, int _nbcards):Interruptible(id), nbcards(_nbcards), player(_player){
@@ -229,6 +250,12 @@ void DrawAction::Render(){
mFont->DrawString(buffer, x + 20 , y, JGETEXT_LEFT);
}
ostream& DrawAction::toString(ostream& out) const
{
out << "DrawAction ::: nbcards : " << nbcards << " ; player : " << player;
return out;
}
/* The Action Stack itself */
int ActionStack::addPutInGraveyard(MTGCardInstance * card){
PutInGraveyard * death = NEW PutInGraveyard(mCount,card);
@@ -445,11 +472,11 @@ void ActionStack::unpackDamageStacks(){
}
void ActionStack::repackDamageStacks(){
std::vector<JGuiObject *>::iterator iter = mObjects.begin() ;
while( iter != mObjects.end() ){
Interruptible * action = ((Interruptible *) *iter);
int found = 0;
std::vector<JGuiObject *>::iterator iter = mObjects.begin() ;
while( iter != mObjects.end() ){
Interruptible * action = ((Interruptible *) *iter);
int found = 0;
if (action->type == ACTION_DAMAGE){
Damage * damage = (Damage *) action;
for (int j = 0; j < mCount; j++){
@@ -467,8 +494,8 @@ void ActionStack::repackDamageStacks(){
}
}
}
}
if (!found) ++iter;
}
if (!found) ++iter;
}
/*
@@ -562,13 +589,13 @@ void ActionStack::Update(float dt){
GuiLayer::Update(dt);
}
if (askIfWishesToInterrupt){
// WALDORF - added code to use a game option setting to determine how
// long the Interrupt timer should be. If it is set to zero (0), the
// game will wait for ever for the user to make a selection.
if (GameOptions::GetInstance()->values[OPTIONS_INTERRUPT_SECONDS].getIntValue() > 0)
{
if (timer < 0) timer = GameOptions::GetInstance()->values[OPTIONS_INTERRUPT_SECONDS].getIntValue();
timer -= dt;
// WALDORF - added code to use a game option setting to determine how
// long the Interrupt timer should be. If it is set to zero (0), the
// game will wait for ever for the user to make a selection.
if (GameOptions::GetInstance()->values[OPTIONS_INTERRUPT_SECONDS].getIntValue() > 0)
{
if (timer < 0) timer = GameOptions::GetInstance()->values[OPTIONS_INTERRUPT_SECONDS].getIntValue();
timer -= dt;
if (timer < 0) cancelInterruptOffer();
}
}
@@ -686,17 +713,17 @@ int ActionStack::CombatDamages(int strike){
//Cleans history of last turn
int ActionStack::garbageCollect(){
std::vector<JGuiObject *>::iterator iter = mObjects.begin() ;
while( iter != mObjects.end() ){
Interruptible * current = ((Interruptible *) *iter);
if (current->state != NOT_RESOLVED){
iter = mObjects.erase( iter ) ;
std::vector<JGuiObject *>::iterator iter = mObjects.begin() ;
while( iter != mObjects.end() ){
Interruptible * current = ((Interruptible *) *iter);
if (current->state != NOT_RESOLVED){
iter = mObjects.erase( iter ) ;
mCount--;
SAFE_DELETE(current);
}else {
++iter ;
}
SAFE_DELETE(current);
}else {
++iter ;
}
}
return 1;
}
@@ -756,26 +783,26 @@ void ActionStack::Render(){
}
char buffer[200];
// WALDORF - changed "interrupt ?" to "Interrupt?". Don't display count down
// seconds if the user disables auto progressing interrupts by setting the seconds
// value to zero in Options.
if (GameOptions::GetInstance()->values[OPTIONS_INTERRUPT_SECONDS].getIntValue() == 0)
sprintf(buffer, _("Interrupt?").c_str());
else
sprintf(buffer, "%s %i", _("Interrupt?").c_str(),static_cast<int>(timer));
//WALDORF - removed all the unnecessary math. just display the prompt at the
// top of the box.
//mFont->DrawString(buffer, x0 + 5 , currenty - 40 - ((Interruptible *)mObjects[mCount-1])->mHeight);
mFont->DrawString(buffer, x0 + 5, y0);
if (mCount > 1) sprintf(buffer, _("X Interrupt - 0 No - [] No to All").c_str());
else sprintf(buffer, _("X Interrupt - 0 No").c_str());
// WALDORF - puts the button legend right under the prompt. the stack
// will be displayed below it now. no more need to do wierd currY math.
//mFont->DrawString(buffer, x0 + 5 , currenty);
// WALDORF - changed "interrupt ?" to "Interrupt?". Don't display count down
// seconds if the user disables auto progressing interrupts by setting the seconds
// value to zero in Options.
if (GameOptions::GetInstance()->values[OPTIONS_INTERRUPT_SECONDS].getIntValue() == 0)
sprintf(buffer, _("Interrupt?").c_str());
else
sprintf(buffer, "%s %i", _("Interrupt?").c_str(),static_cast<int>(timer));
//WALDORF - removed all the unnecessary math. just display the prompt at the
// top of the box.
//mFont->DrawString(buffer, x0 + 5 , currenty - 40 - ((Interruptible *)mObjects[mCount-1])->mHeight);
mFont->DrawString(buffer, x0 + 5, y0);
if (mCount > 1) sprintf(buffer, _("X Interrupt - 0 No - [] No to All").c_str());
else sprintf(buffer, _("X Interrupt - 0 No").c_str());
// WALDORF - puts the button legend right under the prompt. the stack
// will be displayed below it now. no more need to do wierd currY math.
//mFont->DrawString(buffer, x0 + 5 , currenty);
mFont->DrawString(buffer, x0 + 5, y0 + 14);
}else if (mode == ACTIONSTACK_TARGET && modal){
for (int i=0;i<mCount ;i++){

View File

@@ -145,6 +145,11 @@ void CardDisplay::Render(){
}
}
ostream& CardDisplay::toString(ostream& out) const
{
return (out << "CardDisplay ::: x,y : " << x << "," << y << " ; start_item : " << start_item << " ; nb_displayed_items " << nb_displayed_items << " ; tc : " << tc << " ; listener : " << listener);
}
DefaultTargetDisplay::DefaultTargetDisplay(int id, GameObserver* _game, int _x, int _y,JGuiListener * _listener, int _nb_displayed_items ):CardDisplay(id, _game, _x, _y, _listener, NULL, _nb_displayed_items ){
tc = NEW TargetChooser();
}
@@ -152,3 +157,8 @@ DefaultTargetDisplay::DefaultTargetDisplay(int id, GameObserver* _game, int _x,
DefaultTargetDisplay::~DefaultTargetDisplay(){
SAFE_DELETE(tc);
}
std::ostream& operator<<(std::ostream& out, const CardDisplay& m)
{
return m.toString(out);
}

View File

@@ -414,5 +414,7 @@ CardGui::~CardGui(){
LOG("==CardGui object destruction Successful");
}
ostream& CardGui::toString(ostream& out) const
{
return (out << "CardGui ::: mParticleSys : " << mParticleSys << " ; alpha : " << alpha << " ; card : " << card);
}

View File

@@ -80,6 +80,12 @@ void Damage::Render(){
}
ostream& Damage::toString(ostream& out) const
{
out << "Damage ::: target : " << target << " ; damage " << damage;
return out;
}
DamageStack::DamageStack(int id, GameObserver * _game):GuiLayer(id, _game), Interruptible(id){
currentState = -1;
type = ACTION_DAMAGES;
@@ -158,3 +164,7 @@ void DamageStack::Render(){
}
}
ostream& DamageStack::toString(ostream& out) const
{
return (out << "DamageStack ::: currentState : " << currentState);
}

View File

@@ -584,3 +584,34 @@ JLBFont * mFont = GameApp::CommonRes->GetJLBFont(Constants::MENU_FONT);
break;
}
}
ostream& GameStateMenu::toString(ostream& out) const
{
return out << "GameStateMenu ::: scroller : " << scroller
<< " ; scrollerSet : " << scrollerSet
<< " ; mGuiController : " << mGuiController
<< " ; subMenuController : " << subMenuController
<< " ; gameTypeMenu : " << gameTypeMenu
<< " ; hasChosenGameType : " << hasChosenGameType
<< " ; mIcons : " << mIcons
<< " ; mIconsTexture : " << mIconsTexture
<< " ; bgTexture : " << bgTexture
<< " ; movingWTexture : " << movingWTexture
<< " ; mBg : " << mBg
<< " ; mMovingW : " << mMovingW
<< " ; splashTex : " << splashTex
<< " ; splashQuad : " << splashQuad
<< " ; mCreditsYPos : " << mCreditsYPos
<< " ; currentState : " << currentState
<< " ; mVolume : " << mVolume
<< " ; nbcardsStr : " << nbcardsStr
<< " ; mDip : " << mDip
<< " ; mDit : " << mDit
<< " ; mCurrentSetName : " << mCurrentSetName
<< " ; mCurrentSetFileName : " << mCurrentSetFileName
<< " ; mReadConf : " << mReadConf
<< " ; timeIndex : " << timeIndex
<< " ; angleMultiplier : " << angleMultiplier
<< " ; angleW : " << angleW
<< " ; yW : " << yW;
}

View File

@@ -1926,6 +1926,17 @@ int MTGAbility::fireAbility(){
return 1;
}
ostream& MTGAbility::toString(ostream& out) const
{
return out << "MTGAbility ::: menuText : " << menuText
<< " ; game : " << game
<< " ; forceDestroy : " << forceDestroy
<< " ; cost : " << cost
<< " ; target : " << target
<< " ; aType : " << aType
<< " ; source : " << source;
}
//
ActivatedAbility::ActivatedAbility(int id, MTGCardInstance * card, ManaCost * _cost, int _playerturnonly,int tap):MTGAbility(id,card), playerturnonly(_playerturnonly), needsTapping(tap){
@@ -1989,6 +2000,13 @@ int ActivatedAbility::reactToTargetClick(Targetable * object){
}
ostream& ActivatedAbility::toString(ostream& out) const
{
out << "ActivatedAbility ::: playerturnonly : " << playerturnonly
<< " ; needsTapping : " << needsTapping
<< " (";
return MTGAbility::toString(out) << ")";
}
//The whole targetAbility mechanism is messed up, mainly because of its interactions with
@@ -2057,6 +2075,11 @@ void TargetAbility::Render(){
//TODO ?
}
ostream& TargetAbility::toString(ostream& out) const
{
out << "TargetAbility ::: (";
return ActivatedAbility::toString(out) << ")";
}
//
@@ -2072,6 +2095,11 @@ void TriggeredAbility::Update(float dt){
if (trigger()) fireAbility();
}
ostream& TriggeredAbility::toString(ostream& out) const
{
out << "TriggeredAbility ::: (";
return MTGAbility::toString(out) << ")";
}
//
@@ -2110,6 +2138,13 @@ int InstantAbility::testDestroy(){
}
ostream& InstantAbility::toString(ostream& out) const
{
out << "InstantAbility ::: init : " << init
<< " (";
return MTGAbility::toString(out) << ")";
}
void ListMaintainerAbility::Update(float dt){
map<MTGCardInstance *,bool>::iterator it=cards.begin();
@@ -2167,6 +2202,12 @@ int ListMaintainerAbility::destroy(){
return 1;
}
ostream& ListMaintainerAbility::toString(ostream& out) const
{
out << "ListMaintainerAbility ::: (";
return MTGAbility::toString(out) << ")";
}
/* An attempt to globalize triggered abilities as much as possible */
@@ -2461,3 +2502,18 @@ other solutions need to be provided for abilities that add mana (ex: mana flare)
}
int AManaProducer::currentlyTapping = 0;
ostream& AManaProducer::toString(ostream& out) const
{
out << "AManaProducer ::: cost : " << cost
<< " ; output : " << output
<< " ; menutext : " << menutext
<< " ; x0,y0 : " << x0 << "," << y0
<< " ; x1,y1 : " << x1 << "," << y1
<< " ; x,y : " << x << "," << y
<< " ; animation : " << animation
<< " ; controller : " << controller
<< " ; tap : " << tap
<< " (";
return MTGAbility::toString(out) << ")";
}

View File

@@ -53,3 +53,8 @@ bool MTGGamePhase::CheckUserInput(u32 key){
}
return false;
}
ostream& MTGGamePhase::toString(ostream& out) const
{
return out << "MTGGamePhase ::: animation " << animation << " ; currentState : " << currentState;
}

View File

@@ -1,427 +1,427 @@
/* This class handles the display on the main game screen :
cards in play, graveyard, library, games phases, Players avatars
*/
#include "../include/config.h"
#include "../include/MTGGuiPlay.h"
#include "../include/MTGCardInstance.h"
#include "../include/CardGui.h"
#include "../include/CardDisplay.h"
#include "../include/Translate.h"
#define ZX_MAIN 100
#define ZY_MAIN 22
#define ZH_CREATURES 50
#define Z_CARDWIDTH 30
#define Z_CARDHEIGHT 40
#define Z_MAIN_NBCARDS 7
#define Z_SPELLS_NBCARDS 3
#define ZX_SPELL 450
#define ZY_SPELL 22
MTGGuiPlay::MTGGuiPlay(int id, GameObserver * _game):PlayGuiObjectController(id, _game){
currentPlayer = NULL;
offset = 0;
mPhaseBarTexture = GameApp::CommonRes->GetTexture("graphics/phasebar.png");
for (int i=0; i < 12; i++){
phaseIcons[2*i] = NEW JQuad(mPhaseBarTexture, i*28, 0, 28, 28);
phaseIcons[2*i + 1] = NEW JQuad(mPhaseBarTexture, i*28, 28, 28, 28);
}
mGlitter = NEW JQuad(mPhaseBarTexture, 392, 0, 5, 5);
mGlitter->SetHotSpot(2.5,2.5);
mGlitterAlpha = -1;
mFont= GameApp::CommonRes->GetJLBFont("graphics/simon");
//load all the icon images
/* This class handles the display on the main game screen :
cards in play, graveyard, library, games phases, Players avatars
*/
#include "../include/config.h"
#include "../include/MTGGuiPlay.h"
#include "../include/MTGCardInstance.h"
#include "../include/CardGui.h"
#include "../include/CardDisplay.h"
#include "../include/Translate.h"
#define ZX_MAIN 100
#define ZY_MAIN 22
#define ZH_CREATURES 50
#define Z_CARDWIDTH 30
#define Z_CARDHEIGHT 40
#define Z_MAIN_NBCARDS 7
#define Z_SPELLS_NBCARDS 3
#define ZX_SPELL 450
#define ZY_SPELL 22
MTGGuiPlay::MTGGuiPlay(int id, GameObserver * _game):PlayGuiObjectController(id, _game){
currentPlayer = NULL;
offset = 0;
mPhaseBarTexture = GameApp::CommonRes->GetTexture("graphics/phasebar.png");
for (int i=0; i < 12; i++){
phaseIcons[2*i] = NEW JQuad(mPhaseBarTexture, i*28, 0, 28, 28);
phaseIcons[2*i + 1] = NEW JQuad(mPhaseBarTexture, i*28, 28, 28, 28);
}
mGlitter = NEW JQuad(mPhaseBarTexture, 392, 0, 5, 5);
mGlitter->SetHotSpot(2.5,2.5);
mGlitterAlpha = -1;
mFont= GameApp::CommonRes->GetJLBFont("graphics/simon");
//load all the icon images
mIcons[Constants::MTG_COLOR_ARTIFACT] = GameApp::CommonRes->GetQuad("c_artifact");
mIcons[Constants::MTG_COLOR_LAND] = GameApp::CommonRes->GetQuad("c_land");
mIcons[Constants::MTG_COLOR_WHITE] = GameApp::CommonRes->GetQuad("c_white");
mIcons[Constants::MTG_COLOR_RED] = GameApp::CommonRes->GetQuad("c_red");
mIcons[Constants::MTG_COLOR_BLACK] = GameApp::CommonRes->GetQuad("c_black");
mIcons[Constants::MTG_COLOR_BLUE] = GameApp::CommonRes->GetQuad("c_blue");
mIcons[Constants::MTG_COLOR_GREEN] = GameApp::CommonRes->GetQuad("c_green");
for (int i=0; i < 7; i++){
mIcons[i]->SetHotSpot(16,16);
}
mBgTex = GameApp::CommonRes->GetTexture("graphics/background.png");
if (mBgTex) mBg = NEW JQuad(mBgTex, 0, 0, 480, 272);
else {
mBg = NULL;
GameApp::systemError = "error Loading Texture mBgTex in MTGGuiPlay intialization";
}
mBgTex2 = GameApp::CommonRes->GetTexture("graphics/back.jpg");
if (mBgTex2){
mBg2 = NEW JQuad(mBgTex2, 0, 0, 480, 255);
for (int i= 0; i < 4; i++){
alphaBg[i] = 255;
}
}else{
mBg2 = NULL;
GameApp::systemError = "error Loading Texture mBgTex2 in MTGGuiPlay intialization";
}
alphaBg[0] = 0;
AddPlayersGuiInfo();
}
CardGui * MTGGuiPlay::getByCard(MTGCardInstance * card){
for (int i = offset; i < mCount; i++){
CardGui * cardg = (CardGui *)mObjects[i];
if(cardg && cardg->card == card){
return cardg;
}
}
return NULL;
}
void MTGGuiPlay::initCardsDisplay(){
for (int i = 0; i < SCREEN_WIDTH/5; i++){
for(int j=0; j < SCREEN_HEIGHT/5; j++){
cardsGrid[i][j] = NULL;
}
}
cards_x_limit = 12;
nb_creatures = 0;
nb_lands = 0;
nb_spells = 0;
}
void MTGGuiPlay::adjustCardPosition(CardGui * cardg){
int x5 = cardg->x / 5;
int y5 = cardg->y / 5;
while (cardsGrid[x5][y5] && x5 <SCREEN_WIDTH/5 && y5 < SCREEN_HEIGHT/5 ){
x5++;
y5++;
}
cardg->x = x5 * 5;
cardg->y = y5 * 5;
cardsGrid[x5][y5] = cardg->card;
}
void MTGGuiPlay::setCardPosition(CardGui * cardg, int player, int playerTurn, int spellMode){
MTGCardInstance * card = cardg->card;
if (card->target)
return;
if (spellMode && (card->isACreature() || card->hasType("land"))) return;
if (!spellMode && !card->isACreature() && !card->hasType("land")) return;
if (card->isACreature()){
int x_offset = nb_creatures % cards_x_limit;
int y_offset = nb_creatures / cards_x_limit;
cardg->x= ZX_MAIN + (Z_CARDWIDTH * x_offset);
cardg->y=ZY_MAIN + ZH_CREATURES + (Z_CARDHEIGHT * y_offset) + 100 * (1-player);
nb_creatures++;
if (playerTurn){
if (card->isAttacker()){
cardg->y=122 + 30 * (1-player);
}
}else{
if (card->isDefenser()){
CardGui * targetg = getByCard(card->isDefenser());
if (targetg) cardg->x = targetg->x;
cardg->y=122 + 30 * (1-player);
}
}
}else if(card->hasType("land")){
int x_offset = nb_lands % cards_x_limit;
int y_offset = nb_lands/ cards_x_limit;
cardg->x=ZX_MAIN + (Z_CARDWIDTH * x_offset);
cardg->y=ZY_MAIN + (Z_CARDHEIGHT * y_offset) + 200 * (1-player);
nb_lands++;
}else{
int y_offset = nb_spells % Z_SPELLS_NBCARDS;
int x_offset = nb_spells/ Z_SPELLS_NBCARDS;
cardg->x=ZX_SPELL - (Z_CARDWIDTH * x_offset);
cardg->y=ZY_SPELL + (Z_CARDHEIGHT * y_offset) + 125 * (1-player);
nb_spells++;
cards_x_limit = 12 - (nb_spells + 2)/ Z_SPELLS_NBCARDS;
}
adjustCardPosition(cardg);
}
void MTGGuiPlay::setTargettingCardPosition(CardGui * cardg, int player, int playerTurn){
MTGCardInstance * card = cardg->card;
MTGCardInstance * target = card->target;
if (!target)
return;
CardGui * targetg = getByCard(target);
if (targetg){
cardg->y=targetg->y + 5;
cardg->x=targetg->x + 5;
}
adjustCardPosition(cardg);
return;
}
void MTGGuiPlay::forceUpdateCards(){
GameObserver * game = GameObserver::GetInstance();
Player * player = game->players[0];
int player0Mode =(game->currentPlayer == player);
int nb_cards = player->game->inPlay->nb_cards;
resetObjects();
AddPlayersGuiInfo();
offset = mCount;
bool hasFocus = player0Mode;
offset = 6;
Player * opponent = game->players[1];
int opponent_cards = opponent ->game->inPlay->nb_cards;
for (int i = 0;i<nb_cards; i++){
if (hasFocus) mCurr = mCount ;
CardGui * object = NEW CardGui(mCount, player->game->inPlay->cards[i],40, i*35 + 10, 200, hasFocus);
Add(object);
hasFocus = false;
}
hasFocus = !player0Mode;
for (int i = 0;i<opponent_cards; i++){
if (hasFocus) mCurr = mCount ;
CardGui * object = NEW CardGui(mCount, opponent->game->inPlay->cards[i],40, i*35 + 10, 10, hasFocus);
Add(object);
hasFocus = false;
}
currentPlayer = game->currentPlayer;
}
void MTGGuiPlay::updateCards(){
GameObserver * game = GameObserver::GetInstance();
Player * player = game->players[0];
int player0Mode =(game->currentPlayer == player);
int nb_cards = player->game->inPlay->nb_cards;
MTGCardInstance * attackers[MAX_ATTACKERS];
for (int i = 0; i <MAX_ATTACKERS; i++){
attackers[i] = NULL;
}
offset = 6;
Player * opponent = game->players[1];
int opponent_cards = opponent ->game->inPlay->nb_cards;
if (mCount - offset != (nb_cards+opponent_cards) || game->currentPlayer != currentPlayer ){ //if the number of cards has changed, then an update occured (is this test engouh ?)
forceUpdateCards();
}
//This is just so that we display the cards of the current player first, so that blockers are correctly positionned
for (int j= 0; j < 2; j++){
initCardsDisplay();
if (j != player0Mode){
for (int i =0; i<nb_cards; i++){
CardGui * cardGui = (CardGui *)mObjects[i + offset];
setCardPosition(cardGui, 0, player0Mode, 1);
}
for (int i =0; i<nb_cards; i++){
CardGui * cardGui = (CardGui *)mObjects[i + offset];
setCardPosition(cardGui, 0, player0Mode, 0);
}
}else{
for (int i =0; i<opponent_cards; i++){
CardGui * cardGui = (CardGui *)mObjects[nb_cards + i + offset];
setCardPosition(cardGui, 1, !player0Mode,1);
}
for (int i =0; i<opponent_cards; i++){
CardGui * cardGui = (CardGui *)mObjects[nb_cards + i + offset];
setCardPosition(cardGui, 1, !player0Mode,0);
}
}
}
for (int i =0; i<nb_cards; i++){
CardGui * cardGui = (CardGui *)mObjects[i + offset ];
setTargettingCardPosition(cardGui, 0, player0Mode);
}
for (int i =0; i<opponent_cards; i++){
CardGui * cardGui = (CardGui *)mObjects[nb_cards + i + offset];
setTargettingCardPosition(cardGui, 1, !player0Mode);
}
}
void MTGGuiPlay::AddPlayersGuiInfo(){
//init with the players objects
if (mCount == 0){
Add(NEW GuiAvatar(-1,50,2,155,false, GameObserver::GetInstance()->players[0]));
Add(NEW GuiAvatar(-2,50,2,30,false,GameObserver::GetInstance()->players[1]));
Add(NEW GuiGraveyard(-3,30,40,150,false, GameObserver::GetInstance()->players[0]));
Add(NEW GuiLibrary(-4,30,40,180,false, GameObserver::GetInstance()->players[0]));
Add(NEW GuiGraveyard(-5,30,40,30,false, GameObserver::GetInstance()->players[1]));
Add(NEW GuiLibrary(-6,30,40,60,false, GameObserver::GetInstance()->players[1]));
}
}
void MTGGuiPlay::Update(float dt){
updateCards();
PlayGuiObjectController::Update(dt);
}
bool MTGGuiPlay::CheckUserInput(u32 key){
for (int i = 2; i<6;i++){
GuiGameZone * zone = (GuiGameZone *)mObjects[i];
if (zone->showCards){
return zone->cd->CheckUserInput(key);
}
}
return PlayGuiObjectController::CheckUserInput(key);
}
void MTGGuiPlay::RenderPlayerInfo(int playerid){
JRenderer * r = JRenderer::GetInstance();
Player * player = GameObserver::GetInstance()->players[playerid];
//Avatar
GuiAvatar * avatar = (GuiAvatar *)mObjects[3*playerid];
avatar->Render();
//Mana
ManaCost * cost = player->getManaPool();
int nbicons = 0;
for (int j=0; j<6;j++){
int value = cost->getCost(j);
for (int i=0; i<value; i++){
float x = 10 + (nbicons %4) * 15;
float y = 90 + 125 * (1-playerid) + (15 * (nbicons / 4));
r->RenderQuad(mIcons[j],x,y,0,0.5, 0.5);
nbicons++;
}
}
}
void MTGGuiPlay::RenderPhaseBar(){
GameObserver * game = GameObserver::GetInstance();
JRenderer * renderer = JRenderer::GetInstance();
int currentPhase = game->getCurrentGamePhase();
for (int i=0; i < 12; i++){
int index = 2*i + 1 ;
if (i==currentPhase-1){
index-=1;
}
renderer->RenderQuad(phaseIcons[index], 200 + 14*i,0,0,0.5,0.5);
}
if (game->currentlyActing()->isAI()){
mFont->SetColor(ARGB(255,128,128,128));
}else{
mFont->SetColor(ARGB(255,255,255,255));
}
mFont->SetScale(DEFAULT_MAIN_FONT_SCALE);
mFont->DrawString(_(Constants::MTGPhaseNames[currentPhase]).c_str(), 375, 2);
}
void MTGGuiPlay::Render(){
LOG("Start MTGGuiPlay Render\n");
JRenderer * renderer = JRenderer::GetInstance();
//alphaBg[1] = 255;
//alphaBg[2]= 255;
//alphaBg[3] = 255;
//mBg2->SetColor(ARGB(alphaBg[0], alphaBg[1],alphaBg[2],alphaBg[3]));
renderer->RenderQuad(mBg2,0,17);
if (game->currentGamePhase >= Constants::MTG_PHASE_COMBATBEGIN && game->currentGamePhase < Constants::MTG_PHASE_COMBATEND){
if (alphaBg[0] < 50){
alphaBg[3]-=12;
alphaBg[2]-=12;
alphaBg[0]+=3;
}
alphaBg[1] = 255;
}else{
if (alphaBg[0]){
alphaBg[0]-=3;
alphaBg[3]+=12;
alphaBg[2]+=12;
}
alphaBg[1] = 255;
}
renderer->FillRect(0,0,480,272,ARGB(alphaBg[0], alphaBg[1],alphaBg[2],alphaBg[3]));
renderer->RenderQuad(mBg,0,0);
for (int i=0;i<mCount;i++){
if (mObjects[i]!=NULL && i!=mCurr){
mObjects[i]->Render();
}
}
RenderPhaseBar();
RenderPlayerInfo(0);
RenderPlayerInfo(1);
int opponentHand = game->players[1]->game->hand->nb_cards;
char buffer[10];
sprintf(buffer,"%i",opponentHand);
mIcons[Constants::MTG_COLOR_GREEN] = GameApp::CommonRes->GetQuad("c_green");
for (int i=0; i < 7; i++){
mIcons[i]->SetHotSpot(16,16);
}
mBgTex = GameApp::CommonRes->GetTexture("graphics/background.png");
if (mBgTex) mBg = NEW JQuad(mBgTex, 0, 0, 480, 272);
else {
mBg = NULL;
GameApp::systemError = "error Loading Texture mBgTex in MTGGuiPlay intialization";
}
mBgTex2 = GameApp::CommonRes->GetTexture("graphics/back.jpg");
if (mBgTex2){
mBg2 = NEW JQuad(mBgTex2, 0, 0, 480, 255);
for (int i= 0; i < 4; i++){
alphaBg[i] = 255;
}
}else{
mBg2 = NULL;
GameApp::systemError = "error Loading Texture mBgTex2 in MTGGuiPlay intialization";
}
alphaBg[0] = 0;
AddPlayersGuiInfo();
}
CardGui * MTGGuiPlay::getByCard(MTGCardInstance * card){
for (int i = offset; i < mCount; i++){
CardGui * cardg = (CardGui *)mObjects[i];
if(cardg && cardg->card == card){
return cardg;
}
}
return NULL;
}
void MTGGuiPlay::initCardsDisplay(){
for (int i = 0; i < SCREEN_WIDTH/5; i++){
for(int j=0; j < SCREEN_HEIGHT/5; j++){
cardsGrid[i][j] = NULL;
}
}
cards_x_limit = 12;
nb_creatures = 0;
nb_lands = 0;
nb_spells = 0;
}
void MTGGuiPlay::adjustCardPosition(CardGui * cardg){
int x5 = cardg->x / 5;
int y5 = cardg->y / 5;
while (cardsGrid[x5][y5] && x5 <SCREEN_WIDTH/5 && y5 < SCREEN_HEIGHT/5 ){
x5++;
y5++;
}
cardg->x = x5 * 5;
cardg->y = y5 * 5;
cardsGrid[x5][y5] = cardg->card;
}
void MTGGuiPlay::setCardPosition(CardGui * cardg, int player, int playerTurn, int spellMode){
MTGCardInstance * card = cardg->card;
if (card->target)
return;
if (spellMode && (card->isACreature() || card->hasType("land"))) return;
if (!spellMode && !card->isACreature() && !card->hasType("land")) return;
if (card->isACreature()){
int x_offset = nb_creatures % cards_x_limit;
int y_offset = nb_creatures / cards_x_limit;
cardg->x= ZX_MAIN + (Z_CARDWIDTH * x_offset);
cardg->y=ZY_MAIN + ZH_CREATURES + (Z_CARDHEIGHT * y_offset) + 100 * (1-player);
nb_creatures++;
if (playerTurn){
if (card->isAttacker()){
cardg->y=122 + 30 * (1-player);
}
}else{
if (card->isDefenser()){
CardGui * targetg = getByCard(card->isDefenser());
if (targetg) cardg->x = targetg->x;
cardg->y=122 + 30 * (1-player);
}
}
}else if(card->hasType("land")){
int x_offset = nb_lands % cards_x_limit;
int y_offset = nb_lands/ cards_x_limit;
cardg->x=ZX_MAIN + (Z_CARDWIDTH * x_offset);
cardg->y=ZY_MAIN + (Z_CARDHEIGHT * y_offset) + 200 * (1-player);
nb_lands++;
}else{
int y_offset = nb_spells % Z_SPELLS_NBCARDS;
int x_offset = nb_spells/ Z_SPELLS_NBCARDS;
cardg->x=ZX_SPELL - (Z_CARDWIDTH * x_offset);
cardg->y=ZY_SPELL + (Z_CARDHEIGHT * y_offset) + 125 * (1-player);
nb_spells++;
cards_x_limit = 12 - (nb_spells + 2)/ Z_SPELLS_NBCARDS;
}
adjustCardPosition(cardg);
}
void MTGGuiPlay::setTargettingCardPosition(CardGui * cardg, int player, int playerTurn){
MTGCardInstance * card = cardg->card;
MTGCardInstance * target = card->target;
if (!target)
return;
CardGui * targetg = getByCard(target);
if (targetg){
cardg->y=targetg->y + 5;
cardg->x=targetg->x + 5;
}
adjustCardPosition(cardg);
return;
}
void MTGGuiPlay::forceUpdateCards(){
GameObserver * game = GameObserver::GetInstance();
Player * player = game->players[0];
int player0Mode =(game->currentPlayer == player);
int nb_cards = player->game->inPlay->nb_cards;
resetObjects();
AddPlayersGuiInfo();
offset = mCount;
bool hasFocus = player0Mode;
offset = 6;
Player * opponent = game->players[1];
int opponent_cards = opponent ->game->inPlay->nb_cards;
for (int i = 0;i<nb_cards; i++){
if (hasFocus) mCurr = mCount ;
CardGui * object = NEW CardGui(mCount, player->game->inPlay->cards[i],40, i*35 + 10, 200, hasFocus);
Add(object);
hasFocus = false;
}
hasFocus = !player0Mode;
for (int i = 0;i<opponent_cards; i++){
if (hasFocus) mCurr = mCount ;
CardGui * object = NEW CardGui(mCount, opponent->game->inPlay->cards[i],40, i*35 + 10, 10, hasFocus);
Add(object);
hasFocus = false;
}
currentPlayer = game->currentPlayer;
}
void MTGGuiPlay::updateCards(){
GameObserver * game = GameObserver::GetInstance();
Player * player = game->players[0];
int player0Mode =(game->currentPlayer == player);
int nb_cards = player->game->inPlay->nb_cards;
MTGCardInstance * attackers[MAX_ATTACKERS];
for (int i = 0; i <MAX_ATTACKERS; i++){
attackers[i] = NULL;
}
offset = 6;
Player * opponent = game->players[1];
int opponent_cards = opponent ->game->inPlay->nb_cards;
if (mCount - offset != (nb_cards+opponent_cards) || game->currentPlayer != currentPlayer ){ //if the number of cards has changed, then an update occured (is this test engouh ?)
forceUpdateCards();
}
//This is just so that we display the cards of the current player first, so that blockers are correctly positionned
for (int j= 0; j < 2; j++){
initCardsDisplay();
if (j != player0Mode){
for (int i =0; i<nb_cards; i++){
CardGui * cardGui = (CardGui *)mObjects[i + offset];
setCardPosition(cardGui, 0, player0Mode, 1);
}
for (int i =0; i<nb_cards; i++){
CardGui * cardGui = (CardGui *)mObjects[i + offset];
setCardPosition(cardGui, 0, player0Mode, 0);
}
}else{
for (int i =0; i<opponent_cards; i++){
CardGui * cardGui = (CardGui *)mObjects[nb_cards + i + offset];
setCardPosition(cardGui, 1, !player0Mode,1);
}
for (int i =0; i<opponent_cards; i++){
CardGui * cardGui = (CardGui *)mObjects[nb_cards + i + offset];
setCardPosition(cardGui, 1, !player0Mode,0);
}
}
}
for (int i =0; i<nb_cards; i++){
CardGui * cardGui = (CardGui *)mObjects[i + offset ];
setTargettingCardPosition(cardGui, 0, player0Mode);
}
for (int i =0; i<opponent_cards; i++){
CardGui * cardGui = (CardGui *)mObjects[nb_cards + i + offset];
setTargettingCardPosition(cardGui, 1, !player0Mode);
}
}
void MTGGuiPlay::AddPlayersGuiInfo(){
//init with the players objects
if (mCount == 0){
Add(NEW GuiAvatar(-1,50,2,155,false, GameObserver::GetInstance()->players[0]));
Add(NEW GuiAvatar(-2,50,2,30,false,GameObserver::GetInstance()->players[1]));
Add(NEW GuiGraveyard(-3,30,40,150,false, GameObserver::GetInstance()->players[0]));
Add(NEW GuiLibrary(-4,30,40,180,false, GameObserver::GetInstance()->players[0]));
Add(NEW GuiGraveyard(-5,30,40,30,false, GameObserver::GetInstance()->players[1]));
Add(NEW GuiLibrary(-6,30,40,60,false, GameObserver::GetInstance()->players[1]));
}
}
void MTGGuiPlay::Update(float dt){
updateCards();
PlayGuiObjectController::Update(dt);
}
bool MTGGuiPlay::CheckUserInput(u32 key){
for (int i = 2; i<6;i++){
GuiGameZone * zone = (GuiGameZone *)mObjects[i];
if (zone->showCards){
return zone->cd->CheckUserInput(key);
}
}
return PlayGuiObjectController::CheckUserInput(key);
}
void MTGGuiPlay::RenderPlayerInfo(int playerid){
JRenderer * r = JRenderer::GetInstance();
Player * player = GameObserver::GetInstance()->players[playerid];
//Avatar
GuiAvatar * avatar = (GuiAvatar *)mObjects[3*playerid];
avatar->Render();
//Mana
ManaCost * cost = player->getManaPool();
int nbicons = 0;
for (int j=0; j<6;j++){
int value = cost->getCost(j);
for (int i=0; i<value; i++){
float x = 10 + (nbicons %4) * 15;
float y = 90 + 125 * (1-playerid) + (15 * (nbicons / 4));
r->RenderQuad(mIcons[j],x,y,0,0.5, 0.5);
nbicons++;
}
}
}
void MTGGuiPlay::RenderPhaseBar(){
GameObserver * game = GameObserver::GetInstance();
JRenderer * renderer = JRenderer::GetInstance();
int currentPhase = game->getCurrentGamePhase();
for (int i=0; i < 12; i++){
int index = 2*i + 1 ;
if (i==currentPhase-1){
index-=1;
}
renderer->RenderQuad(phaseIcons[index], 200 + 14*i,0,0,0.5,0.5);
}
if (game->currentlyActing()->isAI()){
mFont->SetColor(ARGB(255,128,128,128));
}else{
mFont->SetColor(ARGB(255,255,255,255));
}
mFont->SetScale(DEFAULT_MAIN_FONT_SCALE);
mFont->DrawString(_(Constants::MTGPhaseNames[currentPhase]).c_str(), 375, 2);
}
void MTGGuiPlay::Render(){
LOG("Start MTGGuiPlay Render\n");
JRenderer * renderer = JRenderer::GetInstance();
//alphaBg[1] = 255;
//alphaBg[2]= 255;
//alphaBg[3] = 255;
//mBg2->SetColor(ARGB(alphaBg[0], alphaBg[1],alphaBg[2],alphaBg[3]));
renderer->RenderQuad(mBg2,0,17);
if (game->currentGamePhase >= Constants::MTG_PHASE_COMBATBEGIN && game->currentGamePhase < Constants::MTG_PHASE_COMBATEND){
if (alphaBg[0] < 50){
alphaBg[3]-=12;
alphaBg[2]-=12;
alphaBg[0]+=3;
}
alphaBg[1] = 255;
}else{
if (alphaBg[0]){
alphaBg[0]-=3;
alphaBg[3]+=12;
alphaBg[2]+=12;
}
alphaBg[1] = 255;
}
renderer->FillRect(0,0,480,272,ARGB(alphaBg[0], alphaBg[1],alphaBg[2],alphaBg[3]));
renderer->RenderQuad(mBg,0,0);
for (int i=0;i<mCount;i++){
if (mObjects[i]!=NULL && i!=mCurr){
mObjects[i]->Render();
}
}
RenderPhaseBar();
RenderPlayerInfo(0);
RenderPlayerInfo(1);
int opponentHand = game->players[1]->game->hand->nb_cards;
char buffer[10];
sprintf(buffer,"%i",opponentHand);
mFont->SetColor(ARGB(128,0,0,0));
mFont->DrawString(buffer, 56, 20);
mFont->SetColor(ARGB(255,255,255,255));
mFont->DrawString(buffer, 54, 18);
if (mGlitterAlpha < 0){
mGlitterAlpha = 510;
int position = rand() % 2;
if (position){
mGlitterX = 65 + rand() % (420);
mGlitterY = 17 + rand() % (5);
}else{
mGlitterX = 65 + rand() % (5);
mGlitterY = 15 + rand() % (250);
}
}
mGlitter->SetColor(ARGB((255-abs(255-mGlitterAlpha)),240,240,255));
renderer->RenderQuad(mGlitter,mGlitterX,mGlitterY, (float)(mGlitterAlpha)/(float)255, 1.2*float(mGlitterAlpha)/float(255),1.2*float(mGlitterAlpha)/float(255));
mGlitterAlpha-=10;
if (mCount && mObjects[mCurr] != NULL){
mObjects[mCurr]->Render();
if (hasFocus && mCurr >= offset && showBigCards && !game->currentlyActing()->isAI() ){
//For some reason RenderBig crashes when the testsuite is playing, so we add a "isAI()" test...which was supposed to be there at some point anyways...
CardGui * cardg = ((CardGui *)mObjects[mCurr]);
cardg->RenderBig(-1,-1,showBigCards-1);
}
}
LOG("End MTGGuiPlay Render\n");
}
MTGGuiPlay::~MTGGuiPlay(){
LOG("==Destroying MTGGuiPlay==");
delete mBg;
//delete mBgTex;
delete mGlitter;
for (int i=0; i < 12; i++){
delete phaseIcons[2*i] ;
delete phaseIcons[2*i + 1];
}
//delete mPhaseBarTexture;
SAFE_DELETE(mBg2);
//SAFE_DELETE(mBgTex2);
LOG("==Destroying MTGGuiPlay Successful==");
}
mFont->DrawString(buffer, 54, 18);
if (mGlitterAlpha < 0){
mGlitterAlpha = 510;
int position = rand() % 2;
if (position){
mGlitterX = 65 + rand() % (420);
mGlitterY = 17 + rand() % (5);
}else{
mGlitterX = 65 + rand() % (5);
mGlitterY = 15 + rand() % (250);
}
}
mGlitter->SetColor(ARGB((255-abs(255-mGlitterAlpha)),240,240,255));
renderer->RenderQuad(mGlitter,mGlitterX,mGlitterY, (float)(mGlitterAlpha)/(float)255, 1.2*float(mGlitterAlpha)/float(255),1.2*float(mGlitterAlpha)/float(255));
mGlitterAlpha-=10;
if (mCount && mObjects[mCurr] != NULL){
mObjects[mCurr]->Render();
if (hasFocus && mCurr >= offset && showBigCards && !game->currentlyActing()->isAI() ){
//For some reason RenderBig crashes when the testsuite is playing, so we add a "isAI()" test...which was supposed to be there at some point anyways...
CardGui * cardg = ((CardGui *)mObjects[mCurr]);
cardg->RenderBig(-1,-1,showBigCards-1);
}
}
LOG("End MTGGuiPlay Render\n");
}
MTGGuiPlay::~MTGGuiPlay(){
LOG("==Destroying MTGGuiPlay==");
delete mBg;
//delete mBgTex;
delete mGlitter;
for (int i=0; i < 12; i++){
delete phaseIcons[2*i] ;
delete phaseIcons[2*i + 1];
}
//delete mPhaseBarTexture;
SAFE_DELETE(mBg2);
//SAFE_DELETE(mBgTex2);
LOG("==Destroying MTGGuiPlay Successful==");
}

View File

@@ -77,6 +77,13 @@ int MTGPutInPlayRule::testDestroy(){
return 0;
}
ostream& MTGPutInPlayRule::toString(ostream& out) const
{
out << "MTGPutInPlayRule ::: (";
return MTGAbility::toString(out) << ")";
}
MTGAttackRule::MTGAttackRule(int _id):MTGAbility(_id,NULL){
aType=MTGAbility::MTG_ATTACK_RULE;
}
@@ -112,7 +119,11 @@ int MTGAttackRule::testDestroy(){
return 0;
}
ostream& MTGAttackRule::toString(ostream& out) const
{
out << "MTGAttackRule ::: (";
return MTGAbility::toString(out) << ")";
}
MTGBlockRule::MTGBlockRule(int _id):MTGAbility(_id,NULL){
aType=MTGAbility::MTG_BLOCK_RULE;
@@ -149,6 +160,11 @@ int MTGBlockRule::testDestroy(){
return 0;
}
ostream& MTGBlockRule::toString(ostream& out) const
{
out << "MTGBlockRule ::: (";
return MTGAbility::toString(out) << ")";
}
//
// * Momir
@@ -259,4 +275,10 @@ void MTGMomirRule::Render(){
mFont->SetScale(2 - (float)textAlpha/130);
mFont->SetColor(ARGB(textAlpha,255,255,255));
mFont->DrawString(text.c_str(),SCREEN_WIDTH/2,SCREEN_HEIGHT/2,JGETEXT_CENTER);
}
}
ostream& MTGMomirRule::toString(ostream& out) const
{
out << "MTGMomirRule ::: pool : " << pool << " ; initialized : " << initialized << " ; textAlpha : " << textAlpha << " ; text " << text << " ; alreadyplayed : " << alreadyplayed << " ; collection : " << collection << "(";
return MTGAbility::toString(out) << ")";
}

View File

@@ -400,4 +400,9 @@ void ManaCost::Dump(){
OutputDebugString("\n=============\n");
}
#endif
#endif
ostream& operator<<(ostream& out, const ManaCost& m)
{
return out << "(manacost)";
}

View File

@@ -103,3 +103,18 @@ bool MenuItem::ButtonPressed()
MenuItem::~MenuItem(){
if (mParticleSys) delete mParticleSys;
}
ostream& MenuItem::toString(ostream& out) const
{
return out << "MenuItem ::: mHasFocus : " << mHasFocus
<< " ; mFont : " << mFont
<< " ; mText : " << mText
<< " ; mX,mY : " << mX << "," << mY
<< " ; updatedSinceLastRender : " << updatedSinceLastRender
<< " ; lastDt : " << lastDt
<< " ; mScale : " << mScale
<< " ; mTargetScale : " << mTargetScale
<< " ; onQuad : " << onQuad
<< " ; offQuad : " << offQuad
<< " ; mParticleSys : " << mParticleSys;
}

View File

@@ -121,3 +121,14 @@ void OptionsList::Update(float dt){
options[i]->Update(dt);
}
}
ostream& OptionItem::toString(ostream& out) const
{
return out << "OptionItem ::: displayValue : " << displayValue
<< " ; id : " << id
<< " ; value : " << value
<< " ; hasFocus : " << hasFocus
<< " ; maxValue : " << maxValue
<< " ; increment : " << increment
<< " ; x,y : " << x << "," << y;
}

View File

@@ -88,6 +88,13 @@ void GuiAvatar::Render(){
mFont->DrawString(buffer, x+1,y+38);
}
ostream& GuiAvatar::toString(ostream& out) const
{
return out << "GuiAvatar ::: avatarRed : " << avatarRed
<< " ; currentLife : " << currentLife
<< " ; player : " << player;
}
void GuiGameZone::toggleDisplay(){
if (showCards){
@@ -140,12 +147,28 @@ GuiGameZone::~GuiGameZone(){
if(cd) delete cd;
}
ostream& GuiGameZone::toString(ostream& out) const
{
return out << "GuiGameZone ::: zone : " << zone
<< " ; cd : " << cd
<< " ; showCards : " << showCards;
}
GuiGraveyard::GuiGraveyard(int id, float desiredHeight,float _x, float _y, bool hasFocus,Player * player):GuiGameZone(id, desiredHeight, _x, _y, hasFocus,player->game->graveyard){
type= GUI_GRAVEYARD;
}
ostream& GuiGraveyard::toString(ostream& out) const
{
return out << "GuiGraveyard :::";
}
GuiLibrary::GuiLibrary(int id, float desiredHeight,float _x, float _y, bool hasFocus,Player * player):GuiGameZone(id, desiredHeight, _x, _y, hasFocus,player->game->library){
type = GUI_LIBRARY;
}
ostream& GuiLibrary::toString(ostream& out) const
{
return out << "GuiLibrary :::";
}

View File

@@ -304,3 +304,20 @@ ShopItems::~ShopItems(){
safeDeleteDisplay();
SAFE_DELETE(myCollection);
}
ostream& ShopItem::toString(ostream& out) const
{
return out << "ShopItem ::: mHasFocus : " << mHasFocus
<< " ; mFont : " << mFont
<< " ; mText : " << mText
<< " ; mX,mY : " << mX << "," << mY
<< " ; quad : " << quad
<< " ; thumb : " << thumb
<< " ; mScale : " << mScale
<< " ; mTargetScale : " << mTargetScale
<< " ; mDDW : " << mDDW
<< " ; nameCount : " << nameCount
<< " ; quantity : " << quantity
<< " ; card : " << card
<< " ; price : " << price;
}

View File

@@ -78,3 +78,14 @@ bool SimpleMenuItem::hasFocus()
{
return mHasFocus;
}
ostream& SimpleMenuItem::toString(ostream& out) const
{
return out << "SimpleMenuItem ::: mHasFocus : " << mHasFocus
<< " ; parent : " << parent
<< " ; mFont : " << mFont
<< " ; mText : " << mText
<< " ; mScale : " << mScale
<< " ; mTargetScale : " << mTargetScale
<< " ; mX,mY : " << mX << "," << mY;
}

View File

@@ -48,4 +48,19 @@ void TextScroller::Update(float dt){
void TextScroller::Render(){
mFont->DrawString(mText.c_str(),mX,mY,JGETEXT_LEFT,start,mWidth);
}
}
ostream& TextScroller::toString(ostream& out) const
{
return out << "TextScroller ::: mText : " << mText
<< " ; tempText : " << tempText
<< " ; mFont : " << mFont
<< " ; mWidth : " << mWidth
<< " ; mSpeed : " << mSpeed
<< " ; mX,mY : " << mX << "," << mY
<< " ; start : " << start
<< " ; timer : " << timer
<< " ; strings : ?" // << strings
<< " ; currentId : " << currentId
<< " ; mRandom : " << mRandom;
}