Cleaned up my phasebar code and merged it into the overall item selection code

This commit is contained in:
Xawotihs
2011-08-04 05:57:10 +00:00
parent 46dfe03099
commit eac5a35b43
6 changed files with 61 additions and 49 deletions

View File

@@ -5,25 +5,22 @@
#include "PhaseRing.h"
#include "WEvent.h"
class GuiPhaseBar: public GuiLayer
class GuiPhaseBar: public GuiLayer, public PlayGuiObject
{
protected:
Phase* phase;
float angle;
float zoomTarget;
float zoomFactor;
static GuiPhaseBar*instance;
public:
static GuiPhaseBar* GetInstance();
public:
GuiPhaseBar();
~GuiPhaseBar();
void Update(float dt);
void Zoom(float);
virtual void Render();
virtual int receiveEventMinus(WEvent * e);
virtual ostream& toString(ostream& out) const;
virtual void Entering();
virtual bool Leaving(JButton key);
};
#endif // _GUIPHASEBAR_H_

View File

@@ -13,12 +13,16 @@ protected:
float animation;
int currentState;
WFont * mFont;
static MTGGamePhase* instance;
public:
MTGGamePhase(int id);
static MTGGamePhase* GetInstance() { return instance; };
virtual void Update(float dt);
bool CheckUserInput(JButton key);
virtual MTGGamePhase * clone() const;
virtual ostream& toString(ostream& out) const;
bool NextGamePhase();
};
#endif

View File

@@ -292,12 +292,12 @@ bool CardSelector::CheckUserInput(JButton key)
if (active != oldactive)
{
{
CardView* c = dynamic_cast<CardView*> (oldactive);
PlayGuiObject* c = dynamic_cast<PlayGuiObject*> (oldactive);
if (c)
c->zoom = 1.0f;
}
{
CardView* c = dynamic_cast<CardView*> (active);
PlayGuiObject* c = dynamic_cast<PlayGuiObject*> (active);
if (c)
c->zoom = 1.4f;
}

View File

@@ -8,6 +8,8 @@
#include "Subtypes.h"
#include <JLogger.h>
#include <JRenderer.h>
#include "MTGGamePhase.h"
#include "GuiPhaseBar.h"
GameObserver * GameObserver::mInstance = NULL;
@@ -816,6 +818,10 @@ void GameObserver::ButtonPressed(PlayGuiObject * target)
{
cardClick(NULL, avatar->player);
}
else if (GuiPhaseBar* phaseBar = dynamic_cast<GuiPhaseBar*>(target))
{
MTGGamePhase::GetInstance()->NextGamePhase();
}
}
void GameObserver::stackObjectClicked(Interruptible * action)

View File

@@ -4,6 +4,7 @@
#include "GuiPhaseBar.h"
#include "GameObserver.h"
#include "Translate.h"
#include "CardSelectorSingleton.h"
/*
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() :
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");
if (quad.get() != NULL)
@@ -65,7 +54,9 @@ GuiPhaseBar::GuiPhaseBar() :
else
GameApp::systemError = "Error loading phasebar texture : " __FILE__;
instance = this;
zoom = ICONSCALE;
CardSelectorSingleton::Instance()->Add(this);
}
GuiPhaseBar::~GuiPhaseBar()
@@ -79,16 +70,30 @@ void GuiPhaseBar::Update(float dt)
else
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()
{
GameObserver * g = GameObserver::GetInstance();
@@ -164,3 +169,8 @@ int GuiPhaseBar::receiveEventMinus(WEvent *e)
}
return 1;
}
ostream& GuiPhaseBar::toString(ostream& out) const
{
return out << "GuiPhaseBar";
}

View File

@@ -3,6 +3,8 @@
#include "MTGGamePhase.h"
#include "GuiPhaseBar.h"
MTGGamePhase* MTGGamePhase::instance = 0;
MTGGamePhase::MTGGamePhase(int id) :
ActionElement(id)
{
@@ -10,6 +12,7 @@ MTGGamePhase::MTGGamePhase(int id) :
currentState = -1;
mFont = WResourceManager::Instance()->GetWFont(Fonts::MAIN_FONT);
mFont->SetBase(0); // using 2nd font
instance = this;
}
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();
if (activeState == INACTIVE)
{
int x1,y1;
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())
if (game->currentActionPlayer == game->currentlyActing())
{
activeState = ACTIVE;
game->userRequestNextGamePhase();
@@ -70,6 +54,17 @@ bool MTGGamePhase::CheckUserInput(JButton key)
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
{
return NEW MTGGamePhase(*this);