Cleaned up my phasebar code and merged it into the overall item selection code
This commit is contained in:
@@ -5,25 +5,22 @@
|
|||||||
#include "PhaseRing.h"
|
#include "PhaseRing.h"
|
||||||
#include "WEvent.h"
|
#include "WEvent.h"
|
||||||
|
|
||||||
class GuiPhaseBar: public GuiLayer
|
class GuiPhaseBar: public GuiLayer, public PlayGuiObject
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
Phase* phase;
|
Phase* phase;
|
||||||
float angle;
|
float angle;
|
||||||
float zoomTarget;
|
|
||||||
float zoomFactor;
|
float zoomFactor;
|
||||||
static GuiPhaseBar*instance;
|
|
||||||
|
|
||||||
public:
|
|
||||||
static GuiPhaseBar* GetInstance();
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GuiPhaseBar();
|
GuiPhaseBar();
|
||||||
~GuiPhaseBar();
|
~GuiPhaseBar();
|
||||||
void Update(float dt);
|
void Update(float dt);
|
||||||
void Zoom(float);
|
|
||||||
virtual void Render();
|
virtual void Render();
|
||||||
virtual int receiveEventMinus(WEvent * e);
|
virtual int receiveEventMinus(WEvent * e);
|
||||||
|
virtual ostream& toString(ostream& out) const;
|
||||||
|
virtual void Entering();
|
||||||
|
virtual bool Leaving(JButton key);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _GUIPHASEBAR_H_
|
#endif // _GUIPHASEBAR_H_
|
||||||
|
|||||||
@@ -13,12 +13,16 @@ protected:
|
|||||||
float animation;
|
float animation;
|
||||||
int currentState;
|
int currentState;
|
||||||
WFont * mFont;
|
WFont * mFont;
|
||||||
|
static MTGGamePhase* instance;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MTGGamePhase(int id);
|
MTGGamePhase(int id);
|
||||||
|
static MTGGamePhase* GetInstance() { return instance; };
|
||||||
virtual void Update(float dt);
|
virtual void Update(float dt);
|
||||||
bool CheckUserInput(JButton key);
|
bool CheckUserInput(JButton key);
|
||||||
virtual MTGGamePhase * clone() const;
|
virtual MTGGamePhase * clone() const;
|
||||||
virtual ostream& toString(ostream& out) const;
|
virtual ostream& toString(ostream& out) const;
|
||||||
|
bool NextGamePhase();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -292,12 +292,12 @@ bool CardSelector::CheckUserInput(JButton key)
|
|||||||
if (active != oldactive)
|
if (active != oldactive)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
CardView* c = dynamic_cast<CardView*> (oldactive);
|
PlayGuiObject* c = dynamic_cast<PlayGuiObject*> (oldactive);
|
||||||
if (c)
|
if (c)
|
||||||
c->zoom = 1.0f;
|
c->zoom = 1.0f;
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
CardView* c = dynamic_cast<CardView*> (active);
|
PlayGuiObject* c = dynamic_cast<PlayGuiObject*> (active);
|
||||||
if (c)
|
if (c)
|
||||||
c->zoom = 1.4f;
|
c->zoom = 1.4f;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,8 @@
|
|||||||
#include "Subtypes.h"
|
#include "Subtypes.h"
|
||||||
#include <JLogger.h>
|
#include <JLogger.h>
|
||||||
#include <JRenderer.h>
|
#include <JRenderer.h>
|
||||||
|
#include "MTGGamePhase.h"
|
||||||
|
#include "GuiPhaseBar.h"
|
||||||
|
|
||||||
GameObserver * GameObserver::mInstance = NULL;
|
GameObserver * GameObserver::mInstance = NULL;
|
||||||
|
|
||||||
@@ -816,6 +818,10 @@ void GameObserver::ButtonPressed(PlayGuiObject * target)
|
|||||||
{
|
{
|
||||||
cardClick(NULL, avatar->player);
|
cardClick(NULL, avatar->player);
|
||||||
}
|
}
|
||||||
|
else if (GuiPhaseBar* phaseBar = dynamic_cast<GuiPhaseBar*>(target))
|
||||||
|
{
|
||||||
|
MTGGamePhase::GetInstance()->NextGamePhase();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameObserver::stackObjectClicked(Interruptible * action)
|
void GameObserver::stackObjectClicked(Interruptible * action)
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include "GuiPhaseBar.h"
|
#include "GuiPhaseBar.h"
|
||||||
#include "GameObserver.h"
|
#include "GameObserver.h"
|
||||||
#include "Translate.h"
|
#include "Translate.h"
|
||||||
|
#include "CardSelectorSingleton.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
static int colors[] =
|
static int colors[] =
|
||||||
@@ -40,21 +41,9 @@ namespace
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GuiPhaseBar* GuiPhaseBar::instance = NULL;
|
|
||||||
|
|
||||||
|
|
||||||
GuiPhaseBar* GuiPhaseBar::GetInstance()
|
|
||||||
{
|
|
||||||
return GuiPhaseBar::instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GuiPhaseBar::Zoom(float zoom)
|
|
||||||
{
|
|
||||||
zoomTarget = zoom*ICONSCALE;
|
|
||||||
}
|
|
||||||
|
|
||||||
GuiPhaseBar::GuiPhaseBar() :
|
GuiPhaseBar::GuiPhaseBar() :
|
||||||
phase(NULL), angle(0.0f), zoomTarget(ICONSCALE), zoomFactor(ICONSCALE)
|
PlayGuiObject(0, 0, 106, 0, false),
|
||||||
|
phase(NULL), angle(0.0f), zoomFactor(ICONSCALE)
|
||||||
{
|
{
|
||||||
JQuadPtr quad = WResourceManager::Instance()->GetQuad("phasebar");
|
JQuadPtr quad = WResourceManager::Instance()->GetQuad("phasebar");
|
||||||
if (quad.get() != NULL)
|
if (quad.get() != NULL)
|
||||||
@@ -65,7 +54,9 @@ GuiPhaseBar::GuiPhaseBar() :
|
|||||||
else
|
else
|
||||||
GameApp::systemError = "Error loading phasebar texture : " __FILE__;
|
GameApp::systemError = "Error loading phasebar texture : " __FILE__;
|
||||||
|
|
||||||
instance = this;
|
zoom = ICONSCALE;
|
||||||
|
CardSelectorSingleton::Instance()->Add(this);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GuiPhaseBar::~GuiPhaseBar()
|
GuiPhaseBar::~GuiPhaseBar()
|
||||||
@@ -79,16 +70,30 @@ void GuiPhaseBar::Update(float dt)
|
|||||||
else
|
else
|
||||||
angle = 0;
|
angle = 0;
|
||||||
|
|
||||||
if(zoomFactor + 0.05 < zoomTarget)
|
if (dt > 0.05f) dt = 0.05f;
|
||||||
|
if(zoomFactor + 0.05f < zoom)
|
||||||
{
|
{
|
||||||
zoomFactor += (float)0.05;
|
zoomFactor += dt;
|
||||||
}
|
}
|
||||||
else if (zoomFactor - 0.05 > zoomTarget)
|
else if (zoomFactor - 0.05f > zoom)
|
||||||
{
|
{
|
||||||
zoomFactor -= (float)0.05;
|
zoomFactor -= dt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GuiPhaseBar::Entering()
|
||||||
|
{
|
||||||
|
mHasFocus = true;
|
||||||
|
zoom = 1.4f*ICONSCALE;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GuiPhaseBar::Leaving(JButton key)
|
||||||
|
{
|
||||||
|
mHasFocus = false;
|
||||||
|
zoom = ICONSCALE;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void GuiPhaseBar::Render()
|
void GuiPhaseBar::Render()
|
||||||
{
|
{
|
||||||
GameObserver * g = GameObserver::GetInstance();
|
GameObserver * g = GameObserver::GetInstance();
|
||||||
@@ -164,3 +169,8 @@ int GuiPhaseBar::receiveEventMinus(WEvent *e)
|
|||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ostream& GuiPhaseBar::toString(ostream& out) const
|
||||||
|
{
|
||||||
|
return out << "GuiPhaseBar";
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
#include "MTGGamePhase.h"
|
#include "MTGGamePhase.h"
|
||||||
#include "GuiPhaseBar.h"
|
#include "GuiPhaseBar.h"
|
||||||
|
|
||||||
|
MTGGamePhase* MTGGamePhase::instance = 0;
|
||||||
|
|
||||||
MTGGamePhase::MTGGamePhase(int id) :
|
MTGGamePhase::MTGGamePhase(int id) :
|
||||||
ActionElement(id)
|
ActionElement(id)
|
||||||
{
|
{
|
||||||
@@ -10,6 +12,7 @@ MTGGamePhase::MTGGamePhase(int id) :
|
|||||||
currentState = -1;
|
currentState = -1;
|
||||||
mFont = WResourceManager::Instance()->GetWFont(Fonts::MAIN_FONT);
|
mFont = WResourceManager::Instance()->GetWFont(Fonts::MAIN_FONT);
|
||||||
mFont->SetBase(0); // using 2nd font
|
mFont->SetBase(0); // using 2nd font
|
||||||
|
instance = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MTGGamePhase::Update(float dt)
|
void MTGGamePhase::Update(float dt)
|
||||||
@@ -36,31 +39,12 @@ void MTGGamePhase::Update(float dt)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MTGGamePhase::CheckUserInput(JButton key)
|
bool MTGGamePhase::NextGamePhase()
|
||||||
{
|
{
|
||||||
GameObserver * game = GameObserver::GetInstance();
|
GameObserver * game = GameObserver::GetInstance();
|
||||||
if (activeState == INACTIVE)
|
if (activeState == INACTIVE)
|
||||||
{
|
{
|
||||||
int x1,y1;
|
if (game->currentActionPlayer == game->currentlyActing())
|
||||||
JButton trigger = (options[Options::REVERSETRIGGERS].number ? JGE_BTN_NEXT : JGE_BTN_PREV);
|
|
||||||
if(JGE::GetInstance()->GetLeftClickCoordinates(x1, y1))
|
|
||||||
{
|
|
||||||
if(x1 < 28 && y1 <185 && y1 > 106)
|
|
||||||
{ /* See GuiPhaseBar to understand where those values come from */
|
|
||||||
GuiPhaseBar::GetInstance()->Zoom(1.4f);
|
|
||||||
if(key == JGE_BTN_OK)
|
|
||||||
{
|
|
||||||
key = trigger;
|
|
||||||
JGE::GetInstance()->LeftClickedProcessed();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
GuiPhaseBar::GetInstance()->Zoom(1.0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((trigger == key) && game->currentActionPlayer == game->currentlyActing())
|
|
||||||
{
|
{
|
||||||
activeState = ACTIVE;
|
activeState = ACTIVE;
|
||||||
game->userRequestNextGamePhase();
|
game->userRequestNextGamePhase();
|
||||||
@@ -70,6 +54,17 @@ bool MTGGamePhase::CheckUserInput(JButton key)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool MTGGamePhase::CheckUserInput(JButton key)
|
||||||
|
{
|
||||||
|
JButton trigger = (options[Options::REVERSETRIGGERS].number ? JGE_BTN_NEXT : JGE_BTN_PREV);
|
||||||
|
if (trigger == key)
|
||||||
|
{
|
||||||
|
return NextGamePhase();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
MTGGamePhase * MTGGamePhase::clone() const
|
MTGGamePhase * MTGGamePhase::clone() const
|
||||||
{
|
{
|
||||||
return NEW MTGGamePhase(*this);
|
return NEW MTGGamePhase(*this);
|
||||||
|
|||||||
Reference in New Issue
Block a user