Phase bar is now clickable/touchable and animated.
This commit is contained in:
@@ -10,11 +10,18 @@ class GuiPhaseBar: public GuiLayer
|
|||||||
protected:
|
protected:
|
||||||
Phase* phase;
|
Phase* phase;
|
||||||
float angle;
|
float angle;
|
||||||
|
float zoomFactor;
|
||||||
|
float zoomTarget;
|
||||||
|
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);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -40,8 +40,21 @@ 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)
|
phase(NULL), angle(0.0f), zoomTarget(ICONSCALE), zoomFactor(ICONSCALE)
|
||||||
{
|
{
|
||||||
JQuadPtr quad = WResourceManager::Instance()->GetQuad("phasebar");
|
JQuadPtr quad = WResourceManager::Instance()->GetQuad("phasebar");
|
||||||
if (quad.get() != NULL)
|
if (quad.get() != NULL)
|
||||||
@@ -51,6 +64,8 @@ GuiPhaseBar::GuiPhaseBar() :
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
GameApp::systemError = "Error loading phasebar texture : " __FILE__;
|
GameApp::systemError = "Error loading phasebar texture : " __FILE__;
|
||||||
|
|
||||||
|
instance = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
GuiPhaseBar::~GuiPhaseBar()
|
GuiPhaseBar::~GuiPhaseBar()
|
||||||
@@ -63,6 +78,15 @@ void GuiPhaseBar::Update(float dt)
|
|||||||
angle -= 3 * dt;
|
angle -= 3 * dt;
|
||||||
else
|
else
|
||||||
angle = 0;
|
angle = 0;
|
||||||
|
|
||||||
|
if(zoomFactor + 0.05 < zoomTarget)
|
||||||
|
{
|
||||||
|
zoomFactor += 0.05;
|
||||||
|
}
|
||||||
|
else if (zoomFactor - 0.05 > zoomTarget)
|
||||||
|
{
|
||||||
|
zoomFactor -= 0.05;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiPhaseBar::Render()
|
void GuiPhaseBar::Render()
|
||||||
@@ -73,12 +97,12 @@ void GuiPhaseBar::Render()
|
|||||||
JRenderer::GetInstance()->DrawLine(0, CENTER, SCREEN_WIDTH, CENTER, ARGB(255, 255, 255, 255));
|
JRenderer::GetInstance()->DrawLine(0, CENTER, SCREEN_WIDTH, CENTER, ARGB(255, 255, 255, 255));
|
||||||
|
|
||||||
unsigned int p = (phase->id + kPhases - 4) * (int) (kWidth + 1);
|
unsigned int p = (phase->id + kPhases - 4) * (int) (kWidth + 1);
|
||||||
float centerYPosition = CENTER + (kWidth / 2) * angle * ICONSCALE / (M_PI / 6) - ICONSCALE * kWidth / 4;
|
float centerYPosition = CENTER + (kWidth / 2) * angle * zoomFactor / (M_PI / 6) - zoomFactor * kWidth / 4;
|
||||||
float yPos = centerYPosition;
|
float yPos = centerYPosition;
|
||||||
float scale = 0;
|
float scale = 0;
|
||||||
for (int glyph = 3; glyph < 6; ++glyph)
|
for (int glyph = 3; glyph < 6; ++glyph)
|
||||||
{
|
{
|
||||||
scale = ICONSCALE * sinf(angle + glyph * M_PI / 6) / 2;
|
scale = zoomFactor * sinf(angle + glyph * M_PI / 6) / 2;
|
||||||
DrawGlyph(quad.get(), glyph, yPos, angle, p, scale);
|
DrawGlyph(quad.get(), glyph, yPos, angle, p, scale);
|
||||||
yPos += kWidth * scale;
|
yPos += kWidth * scale;
|
||||||
}
|
}
|
||||||
@@ -86,14 +110,14 @@ void GuiPhaseBar::Render()
|
|||||||
yPos = centerYPosition;
|
yPos = centerYPosition;
|
||||||
for (int glyph = 2; glyph > 0; --glyph)
|
for (int glyph = 2; glyph > 0; --glyph)
|
||||||
{
|
{
|
||||||
scale = ICONSCALE * sinf(angle + glyph * M_PI / 6) / 2;
|
scale = zoomFactor * sinf(angle + glyph * M_PI / 6) / 2;
|
||||||
yPos -= kWidth * scale;
|
yPos -= kWidth * scale;
|
||||||
DrawGlyph(quad.get(), glyph, yPos, angle, p, scale);
|
DrawGlyph(quad.get(), glyph, yPos, angle, p, scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (angle > 0)
|
if (angle > 0)
|
||||||
{
|
{
|
||||||
scale = ICONSCALE * sinf(angle) / 2;
|
scale = zoomFactor * sinf(angle) / 2;
|
||||||
yPos -= kWidth * scale;
|
yPos -= kWidth * scale;
|
||||||
float xPos = static_cast<float> (p % (kPhases * (int) (kWidth + 1)));
|
float xPos = static_cast<float> (p % (kPhases * (int) (kWidth + 1)));
|
||||||
quad->SetTextureRect(xPos, kHeight, kWidth, kHeight);
|
quad->SetTextureRect(xPos, kHeight, kWidth, kHeight);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include "PrecompiledHeader.h"
|
#include "PrecompiledHeader.h"
|
||||||
|
|
||||||
#include "MTGGamePhase.h"
|
#include "MTGGamePhase.h"
|
||||||
|
#include "GuiPhaseBar.h"
|
||||||
|
|
||||||
MTGGamePhase::MTGGamePhase(int id) :
|
MTGGamePhase::MTGGamePhase(int id) :
|
||||||
ActionElement(id)
|
ActionElement(id)
|
||||||
@@ -40,7 +41,25 @@ bool MTGGamePhase::CheckUserInput(JButton key)
|
|||||||
GameObserver * game = GameObserver::GetInstance();
|
GameObserver * game = GameObserver::GetInstance();
|
||||||
if (activeState == INACTIVE)
|
if (activeState == INACTIVE)
|
||||||
{
|
{
|
||||||
|
int x1,y1;
|
||||||
JButton trigger = (options[Options::REVERSETRIGGERS].number ? JGE_BTN_NEXT : JGE_BTN_PREV);
|
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.4);
|
||||||
|
if(key == JGE_BTN_OK)
|
||||||
|
{
|
||||||
|
key = trigger;
|
||||||
|
JGE::GetInstance()->LeftClickedProcessed();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
GuiPhaseBar::GetInstance()->Zoom(1.0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ((trigger == key) && game->currentActionPlayer == game->currentlyActing())
|
if ((trigger == key) && game->currentActionPlayer == game->currentlyActing())
|
||||||
{
|
{
|
||||||
activeState = ACTIVE;
|
activeState = ACTIVE;
|
||||||
|
|||||||
Reference in New Issue
Block a user