Some organisational prep work before I start working on a new navigation method (ie replacement for CardSelector). The current design was to allocate a CardSelector and pass in its pointer to a variety of classes via their constructors. To simplify things, now we use a singleton style pattern with an Instance() function - this means that when I implement a new class to replace CardSelector, I only need to modify what's returned by the singleton callback - as long as the new pointer class supports the same function calls, it'll be a straight drop-in.

This commit is contained in:
wrenczes@gmail.com
2010-10-22 08:41:44 +00:00
parent 84004c7c7f
commit e2de03d987
13 changed files with 177 additions and 118 deletions
+59 -36
View File
@@ -29,52 +29,75 @@ struct LimitorFunctor
template <typename T=PlayGuiObject>
class ObjectSelector : public GuiLayer
{
public:
typedef enum {
nullZone, handZone, playZone
} SelectorZone;
struct SelectorMemory
{
T* object;
float x, y;
SelectorMemory(T* object) : object(object) { if (object) { x = object->x; y = object->y; } };
SelectorMemory() { object = NULL; x = y = 0; };
};
public:
typedef enum {
nullZone, handZone, playZone
} SelectorZone;
struct SelectorMemory
{
T* object;
float x, y;
SelectorMemory(T* object) : object(object) { if (object) { x = object->x; y = object->y; } };
SelectorMemory() { object = NULL; x = y = 0; };
};
protected:
vector<T*> cards;
T* active;
DuelLayers* duel;
LimitorFunctor<T>* limitor;
Pos bigpos;
map<const SelectorZone, SelectorMemory> lasts;
stack< pair<LimitorFunctor<T>*, SelectorZone> > limitorStack;
stack<SelectorMemory> memoryStack;
protected:
vector<T*> cards;
T* active;
DuelLayers* duel;
LimitorFunctor<T>* limitor;
Pos bigpos;
map<const SelectorZone, SelectorMemory> lasts;
stack< pair<LimitorFunctor<T>*, SelectorZone> > limitorStack;
stack<SelectorMemory> memoryStack;
T* fetchMemory(SelectorMemory&);
T* fetchMemory(SelectorMemory&);
public:
ObjectSelector(DuelLayers*);
int bigMode;
void Add(T*);
void Remove(T*);
bool CheckUserInput(JButton key);
bool CheckUserInput(int x, int y);
void Update(float dt);
void Render();
void Push();
void Pop();
public:
ObjectSelector(DuelLayers*);
int bigMode;
void Add(T*);
void Remove(T*);
bool CheckUserInput(JButton key);
bool CheckUserInput(int x, int y);
void Update(float dt);
void Render();
void Push();
void Pop();
void Limit(LimitorFunctor<T>* limitor, SelectorZone);
void PushLimitor();
void PopLimitor();
void Limit(LimitorFunctor<T>* limitor, SelectorZone);
void PushLimitor();
void PopLimitor();
typedef T Target;
typedef T Target;
};
typedef ObjectSelector<> CardSelector;
typedef LimitorFunctor<CardSelector::Target> Limitor;
namespace CardSelectorSingleton
{
/*
** CardSelector is essentially a singleton in its usage
** It's not enforced, but it needs to eventually migrate to the real thing
** For now, this function will fake it out - it's up to the client caller to make sure
** that this gets destroyed via a Terminate call (this is currently handled in DualLayers's destructor)
*/
CardSelector* Instance();
/*
** Create the singleton pointer. Instance() isn't valid until this is called.
*/
CardSelector* Create(DuelLayers* inDuelLayers);
/*
** Teardown the singleton pointer instance.
*/
void Terminate();
}
struct Exp
{
static inline bool test(CardSelector::Target*, CardSelector::Target*);
+1 -1
View File
@@ -43,7 +43,7 @@ public:
int receiveEvent(WEvent * e);
float RightBoundary();
CardSelector* cs;
CardSelector* mCardSelector;
};
#include "ActionLayer.h"
+1 -2
View File
@@ -15,12 +15,11 @@ class GuiAvatars : public GuiLayer
GuiGraveyard* selfGraveyard, *opponentGraveyard;
GuiLibrary* selfLibrary, *opponentLibrary;
GuiOpponentHand *opponentHand;
CardSelector* cs;
GuiAvatar* active;
public:
GuiAvatars(CardSelector*);
GuiAvatars();
~GuiAvatars();
GuiAvatar* GetSelf();
+3 -4
View File
@@ -35,10 +35,9 @@ class GuiHand : public GuiLayer
const MTGHand* hand;
JQuad *back;
vector<CardView*> cards;
CardSelector* cs;
public:
GuiHand(CardSelector* cs, MTGHand* hand);
GuiHand(MTGHand* hand);
~GuiHand();
void Update(float dt);
bool isInHand(CardView*);
@@ -49,7 +48,7 @@ class GuiHand : public GuiLayer
class GuiHandOpponent : public GuiHand
{
public:
GuiHandOpponent(CardSelector* cs, MTGHand* hand);
GuiHandOpponent(MTGHand* hand);
virtual void Render();
virtual int receiveEventPlus(WEvent* e);
virtual int receiveEventMinus(WEvent* e);
@@ -66,7 +65,7 @@ class GuiHandSelf : public GuiHand
Pos backpos;
public:
GuiHandSelf(CardSelector* cs, MTGHand* hand);
GuiHandSelf(MTGHand* hand);
~GuiHandSelf();
virtual int receiveEventPlus(WEvent* e);
virtual int receiveEventMinus(WEvent* e);
+1 -2
View File
@@ -71,13 +71,12 @@ class GuiPlay : public GuiLayer
BattleField battleField;
Lands selfLands, opponentLands;
Spells selfSpells, opponentSpells;
CardSelector* cs;
iterator end_spells;
vector<CardView*> cards;
public:
GuiPlay(GameObserver*, CardSelector*);
GuiPlay(GameObserver*);
~GuiPlay();
virtual void Render();
void Replace();