More reorganization work around CardSelector and the singleton pattern. Broke the source for the singleton into its own separate source file, to keep things clean. Also broke apart a circular header dependency: CardSelector defines and uses a SelectorZone, which is a member inside of CardView. CardView in turn is used heavily by CardSelector. Instead SelectorZone is now defined within CardView (where it's set & controlled anyway).

I've also added my current work on the zone navigation system (class Navigator) - it's currently turned off for now (the override for this is inside of CardSelectorSingleton's Instance() call, simply comment out the NEW CardSelector and uncomment out the NEW Navigator line.)  It's functional, but I want to do more testing before considering wiring it into the game options or something similar.  (Also, note that it currently doesn't support the mouse functionality added by DJardin.)

Lastly, there's a bug crash fix in ActionStack that I tripped across while testing - basically, an illegal index value would have us walk off the bounds of a vector.
This commit is contained in:
wrenczes@gmail.com
2010-10-31 07:50:53 +00:00
parent dfb9d76829
commit 5a1e8e6ffe
22 changed files with 1041 additions and 154 deletions
+9 -4
View File
@@ -8,7 +8,6 @@
#include "Pos.h"
#include "PlayGuiObject.h"
#include "MTGCardInstance.h"
#include "CardSelector.h"
class MTGCardInstance;
class PlayGuiObject;
@@ -37,13 +36,19 @@ struct CardGui : public PlayGuiObject {
virtual ostream& toString(ostream&) const;
};
class CardView : public CardGui {
public:
const CardSelector::SelectorZone owner;
typedef enum {
nullZone, handZone, playZone
} SelectorZone;
const SelectorZone owner;
MTGCardInstance* getCard(); // remove this when possible
CardView(const CardSelector::SelectorZone, MTGCardInstance* card, float x, float y);
CardView(const CardSelector::SelectorZone, MTGCardInstance* card, const Pos& ref);
CardView(const SelectorZone, MTGCardInstance* card, float x, float y);
CardView(const SelectorZone, MTGCardInstance* card, const Pos& ref);
void Render(){CardGui::Render();};
void Render(JQuad* q){Pos::Render(q);};
virtual ostream& toString(ostream&) const;
+41 -44
View File
@@ -3,6 +3,7 @@
#include <vector>
#include <stack>
#include "CardGui.h"
#include "GuiLayers.h"
#include "Pos.h"
@@ -11,6 +12,7 @@ using std::vector;
class PlayGuiObject;
class DuelLayers;
enum {
BIG_MODE_SHOW = 0,
BIG_MODE_TEXT = 1,
@@ -26,38 +28,57 @@ struct LimitorFunctor
typedef T Target;
};
template <typename T=PlayGuiObject>
class ObjectSelector : public GuiLayer
class CardSelectorBase : public GuiLayer
{
public:
CardSelectorBase(int inDrawMode) : mDrawMode(inDrawMode) {};
virtual void Add(PlayGuiObject*) = 0;
virtual void Remove(PlayGuiObject*) = 0;
virtual bool CheckUserInput(JButton key) = 0;
virtual bool CheckUserInput(int x, int y) = 0;
virtual void PushLimitor() = 0;
virtual void PopLimitor() = 0;
virtual void Limit(LimitorFunctor<PlayGuiObject>* inLimitor, CardView::SelectorZone inZone) = 0;
virtual void Push() = 0;
virtual void Pop() = 0;
virtual int GetDrawMode()
{
return mDrawMode;
}
protected:
int mDrawMode;
};
class CardSelector : public CardSelectorBase
{
public:
typedef enum {
nullZone, handZone, playZone
} SelectorZone;
struct SelectorMemory
{
T* object;
PlayGuiObject* object;
float x, y;
SelectorMemory(T* object) : object(object) { if (object) { x = object->x; y = object->y; } };
SelectorMemory() { object = NULL; x = y = 0; };
SelectorMemory(PlayGuiObject* object);
SelectorMemory();
};
protected:
vector<T*> cards;
T* active;
vector<PlayGuiObject*> cards;
PlayGuiObject* active;
DuelLayers* duel;
LimitorFunctor<T>* limitor;
LimitorFunctor<PlayGuiObject>* limitor;
Pos bigpos;
map<const SelectorZone, SelectorMemory> lasts;
stack< pair<LimitorFunctor<T>*, SelectorZone> > limitorStack;
map<const CardView::SelectorZone, SelectorMemory> lasts;
stack< pair<LimitorFunctor<PlayGuiObject>*, CardView::SelectorZone> > limitorStack;
stack<SelectorMemory> memoryStack;
T* fetchMemory(SelectorMemory&);
PlayGuiObject* fetchMemory(SelectorMemory&);
public:
ObjectSelector(DuelLayers*);
int bigMode;
void Add(T*);
void Remove(T*);
CardSelector(DuelLayers*);
void Add(PlayGuiObject*);
void Remove(PlayGuiObject*);
bool CheckUserInput(JButton key);
bool CheckUserInput(int x, int y);
void Update(float dt);
@@ -65,39 +86,15 @@ public:
void Push();
void Pop();
void Limit(LimitorFunctor<T>* limitor, SelectorZone);
void Limit(LimitorFunctor<PlayGuiObject>* limitor, CardView::SelectorZone);
void PushLimitor();
void PopLimitor();
typedef T Target;
typedef PlayGuiObject 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*);
@@ -0,0 +1,30 @@
#ifndef CARDSELECTORSINGLETON_H
#define CARDSELECTORSINGLETON_H
#include "CardSelector.h"
class DuelLayers;
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)
*/
CardSelectorBase* Instance();
/*
** Create the singleton pointer. Instance() isn't valid until this is called.
*/
CardSelectorBase* Create(DuelLayers* inDuelLayers);
/*
** Teardown the singleton pointer instance.
*/
void Terminate();
}
#endif //CARDSELECTORSINGLETON_H
+2 -2
View File
@@ -2,7 +2,6 @@
#define _DUELLAYERS_H_
#include "GuiLayers.h"
#include "CardSelector.h"
class MTGGuiHand;
class MTGGuiPlay;
@@ -13,6 +12,7 @@ class GuiHandSelf;
class GuiHandOpponent;
class GuiCombat;
class GuiAvatars;
class CardSelectorBase;
struct Pos;
class DuelLayers {
@@ -43,7 +43,7 @@ public:
int receiveEvent(WEvent * e);
float RightBoundary();
CardSelector* mCardSelector;
CardSelectorBase* mCardSelector;
};
#include "ActionLayer.h"
-1
View File
@@ -2,7 +2,6 @@
#define _GUIAVATARS_H_
#include "GuiLayers.h"
#include "CardSelector.h"
struct GuiAvatar;
class GuiGraveyard;
-1
View File
@@ -6,7 +6,6 @@
#include "MTGGameZones.h"
#include "CardGui.h"
#include "GuiHand.h"
#include "CardSelector.h"
class GuiHand;
+60
View File
@@ -0,0 +1,60 @@
#ifndef NAVIGATOR_H
#define NAVIGATOR_H
#include "JTypes.h"
#include "CardSelector.h"
#include "DuelLayers.h"
#include <map>
#include <vector>
// private class only used by Navigator, see implementation file
class CardZone;
class Navigator : public CardSelectorBase
{
public:
Navigator(DuelLayers* inDuelLayers);
virtual ~Navigator();
// Inherited functions from GuiLayer
bool CheckUserInput(JButton inKey);
bool CheckUserInput(int x, int y);
void Update(float dt);
void Render();
//Limitor operations
void PushLimitor();
void PopLimitor();
void Limit(LimitorFunctor<PlayGuiObject>* inLimitor, CardView::SelectorZone inZone);
virtual void Add(PlayGuiObject*);
virtual void Remove(PlayGuiObject*);
virtual void Push() {}
virtual void Pop() {}
protected:
PlayGuiObject* GetCurrentCard();
/**
** Helper function that translates a card type into an internal zone ID (used as the index for the card zone map)
*/
int CardToCardZone(PlayGuiObject* card);
void HandleKeyStroke(JButton inKey);
private:
std::map<int, CardZone*> mCardZones;
CardZone* mCurrentZone;
Pos mDrawPosition;
DuelLayers* mDuelLayers;
bool mLimitorEnabled;
std::stack<CardZone*> mCurrentZoneStack;
};
#endif //NAVIGATOR_H