Add easing to GuiPhaseBar, simplify math a bit.

This commit is contained in:
Tobias Loose
2013-12-09 22:17:19 +01:00
parent 1e610ff653
commit 4c627f74b6
5 changed files with 53 additions and 67 deletions

View File

@@ -95,7 +95,7 @@ public:
*/ */
void update(float dt) void update(float dt)
{ {
if(duration > 0) if(time_acc < duration)
{ {
time_acc += dt; time_acc += dt;

View File

@@ -65,7 +65,6 @@ private:
JQuadPtr pspIcons[8]; JQuadPtr pspIcons[8];
WSrcCards * srcCards; WSrcCards * srcCards;
TaskList * taskList; TaskList * taskList;
float mElapsed;
WGuiMenu * shopMenu; WGuiMenu * shopMenu;
WGuiFilters * filterMenu; //Filter menu slides in sideways from right, or up from bottom. WGuiFilters * filterMenu; //Filter menu slides in sideways from right, or up from bottom.
WGuiCardImage * bigDisplay; WGuiCardImage * bigDisplay;

View File

@@ -4,15 +4,25 @@
#include "GuiLayers.h" #include "GuiLayers.h"
#include "PhaseRing.h" #include "PhaseRing.h"
#include "WEvent.h" #include "WEvent.h"
#include "PlayGuiObject.h"
#include "Easing.h"
class GuiPhaseBar: public GuiLayer, public PlayGuiObject class GuiPhaseBar: public GuiLayer, public PlayGuiObject
{ {
protected: private:
Phase* phase; static const float zoom_big;
static const float zoom_small;
static const float step;
int displayedPhaseId;
float angle; float angle;
float zoomFactor; float zoomFactor;
DuelLayers* mpDuelLayers; OutQuadEasing angleEasing;
InOutQuadEasing zoomFactorEasing;
DuelLayers* mpDuelLayers;
void DrawGlyph(JQuad *inQuad, int phaseId, float x, float y, float scale);
public: public:
GuiPhaseBar(DuelLayers* duelLayers); GuiPhaseBar(DuelLayers* duelLayers);
~GuiPhaseBar(); ~GuiPhaseBar();

View File

@@ -102,7 +102,6 @@ void GameStateShop::Start()
bListCards = false; bListCards = false;
mTouched = false; mTouched = false;
mStage = STAGE_FADE_IN; mStage = STAGE_FADE_IN;
mElapsed = 0;
needLoad = true; needLoad = true;
booster = NULL; booster = NULL;
srcCards = NEW WSrcUnlockedCards(0); srcCards = NEW WSrcUnlockedCards(0);
@@ -427,7 +426,7 @@ void GameStateShop::End()
{ {
save(); save();
JRenderer::GetInstance()->EnableVSync(false); JRenderer::GetInstance()->EnableVSync(false);
mElapsed = 0;
SAFE_DELETE(shopMenu); SAFE_DELETE(shopMenu);
SAFE_DELETE(bigDisplay); SAFE_DELETE(bigDisplay);
SAFE_DELETE(srcCards); SAFE_DELETE(srcCards);
@@ -469,9 +468,6 @@ void GameStateShop::Update(float dt)
if (lightAlpha > 50) if (lightAlpha > 50)
lightAlpha = 50; lightAlpha = 50;
if (mStage != STAGE_FADE_IN)
mElapsed += dt;
JButton btn; JButton btn;
switch (mStage) switch (mStage)
{ {

View File

@@ -24,26 +24,28 @@
}; };
*/ */
const float GuiPhaseBar::zoom_big = 1.5 * 1.4;
const float GuiPhaseBar::zoom_small = 1.5;
const float GuiPhaseBar::step = M_PI/6.0f;
namespace namespace
{ {
//width and height of the phase symbol textures
const float kWidth = 28; const float kWidth = 28;
const float kHeight = kWidth; const float kHeight = kWidth;
const unsigned kPhases = 12; const unsigned kPhases = NB_MTG_PHASES - 2; //there are two phases we do not show
}
const float ICONSCALE = 1.5; void GuiPhaseBar::DrawGlyph(JQuad *inQuad, int phaseId, float x, float y, float scale)
const float CENTER = SCREEN_HEIGHT_F / 2 + 10; {
inQuad->SetTextureRect(phaseId * (kWidth + 1), 0, kWidth, kHeight);
void DrawGlyph(JQuad* inQuad, int inGlyph, float inY, float, unsigned int inP, float inScale) JRenderer::GetInstance()->RenderQuad(inQuad, x, y - scale * kWidth/2, 0.0f, scale, scale);
{
float xPos = static_cast<float> ((inP + inGlyph * (int) (kWidth + 1)) % (kPhases * (int) (kWidth + 1)));
inQuad->SetTextureRect(xPos, 0, kWidth, kHeight);
JRenderer::GetInstance()->RenderQuad(inQuad, 0, inY, 0.0, inScale, inScale);
}
} }
GuiPhaseBar::GuiPhaseBar(DuelLayers* duelLayers) : GuiPhaseBar::GuiPhaseBar(DuelLayers* duelLayers) :
GuiLayer(duelLayers->getObserver()), PlayGuiObject(0, 0, 106, 0, false), GuiLayer(duelLayers->getObserver()), PlayGuiObject(80, 0, 106, 0, false),
phase(NULL), angle(0.0f), zoomFactor(ICONSCALE), mpDuelLayers(duelLayers) displayedPhaseId(0), angle(0.0f), zoomFactor(zoom_small), angleEasing(angle),
zoomFactorEasing(zoomFactor), mpDuelLayers(duelLayers)
{ {
if(duelLayers->getObserver()->getResourceManager()) if(duelLayers->getObserver()->getResourceManager())
{ {
@@ -57,10 +59,7 @@ GuiPhaseBar::GuiPhaseBar(DuelLayers* duelLayers) :
GameApp::systemError = "Error loading phasebar texture : " __FILE__; GameApp::systemError = "Error loading phasebar texture : " __FILE__;
} }
zoom = ICONSCALE;
mpDuelLayers->getCardSelector()->Add(this); mpDuelLayers->getCardSelector()->Add(this);
} }
GuiPhaseBar::~GuiPhaseBar() GuiPhaseBar::~GuiPhaseBar()
@@ -69,32 +68,27 @@ GuiPhaseBar::~GuiPhaseBar()
void GuiPhaseBar::Update(float dt) void GuiPhaseBar::Update(float dt)
{ {
if (angle > 3 * dt) angleEasing.update(dt);
angle -= 3 * dt;
else
angle = 0;
if (dt > 0.05f) dt = 0.05f; if(angle <= -step)
if(zoomFactor + 0.05f < zoom)
{ {
zoomFactor += dt; displayedPhaseId = (displayedPhaseId + 1) % kPhases;
} angleEasing.translate(step);
else if (zoomFactor - 0.05f > zoom)
{
zoomFactor -= dt;
} }
zoomFactorEasing.update(dt);
} }
void GuiPhaseBar::Entering() void GuiPhaseBar::Entering()
{ {
mHasFocus = true; mHasFocus = true;
zoom = 1.4f*ICONSCALE; zoomFactorEasing.start(zoom_big, 0.3f);
} }
bool GuiPhaseBar::Leaving(JButton) bool GuiPhaseBar::Leaving(JButton)
{ {
mHasFocus = false; mHasFocus = false;
zoom = ICONSCALE; zoomFactorEasing.start(zoom_small, 0.6f);
return true; return true;
} }
@@ -102,41 +96,28 @@ void GuiPhaseBar::Render()
{ {
JQuadPtr quad = WResourceManager::Instance()->GetQuad("phasebar"); JQuadPtr quad = WResourceManager::Instance()->GetQuad("phasebar");
//uncomment to draw a hideous line across hires screens. //uncomment to draw a hideous line across hires screens.
// 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); const float radius = 25 * zoomFactor;
float centerYPosition = CENTER + (kWidth / 2) * angle * zoomFactor / (M_PI / 6) - zoomFactor * kWidth / 4;
float yPos = centerYPosition;
float scale = 0;
for (int glyph = 3; glyph < 6; ++glyph)
{
scale = zoomFactor * sinf(angle + glyph * M_PI / 6) / 2;
DrawGlyph(quad.get(), glyph, yPos, angle, p, scale);
yPos += kWidth * scale;
}
yPos = centerYPosition; for(int i = 0; i < 6; ++i)
for (int glyph = 2; glyph > 0; --glyph)
{ {
scale = zoomFactor * sinf(angle + glyph * M_PI / 6) / 2; //the position of the glyphe in the circle
yPos -= kWidth * scale; const float circPos = (i - 2) * step + angle;
DrawGlyph(quad.get(), glyph, yPos, angle, p, scale); const float glyphY = this->y + this->mHeight / 2 + sin(circPos) * radius;
}
if (angle > 0) //the scale is computed so that the glyphes touch each other
{ //hint: sin(circPos + PI/2) = cos(circPos)
scale = zoomFactor * sinf(angle) / 2; const float glyphScale = zoomFactor * cosf(circPos) * 0.5;
yPos -= kWidth * scale;
float xPos = static_cast<float> (p % (kPhases * (int) (kWidth + 1))); DrawGlyph(quad.get(), (displayedPhaseId - 3 + kPhases + i) % kPhases, 0, glyphY, glyphScale);
quad->SetTextureRect(xPos, kHeight, kWidth, kHeight);
JRenderer::GetInstance()->RenderQuad(quad.get(), 0, yPos, 0.0, scale, scale);
} }
//print phase name //print phase name
WFont * font = WResourceManager::Instance()->GetWFont(Fonts::MAIN_FONT); WFont * font = WResourceManager::Instance()->GetWFont(Fonts::MAIN_FONT);
string currentP = _("your turn"); string currentP = _("your turn");
string interrupt = ""; string interrupt = "";
if (observer->currentPlayer == mpDuelLayers->getRenderedPlayerOpponent()) if (observer->currentPlayer == mpDuelLayers->getRenderedPlayerOpponent())
{ {
currentP = _("opponent's turn"); currentP = _("opponent's turn");
} }
@@ -147,7 +128,7 @@ void GuiPhaseBar::Render()
} }
if (observer->currentlyActing() != observer->currentPlayer) if (observer->currentlyActing() != observer->currentPlayer)
{ {
if (observer->currentPlayer == mpDuelLayers->getRenderedPlayer()) if (observer->currentPlayer == mpDuelLayers->getRenderedPlayer())
{ {
interrupt = _(" - ") + _("opponent plays"); interrupt = _(" - ") + _("opponent plays");
} }
@@ -159,7 +140,7 @@ void GuiPhaseBar::Render()
char buf[200]; char buf[200];
//running this string through translate returns gibberish even though we defined the variables in the lang.txt //running this string through translate returns gibberish even though we defined the variables in the lang.txt
string phaseNameToTranslate = observer->phaseRing->phaseName(phase->id); string phaseNameToTranslate = observer->phaseRing->phaseName(displayedPhaseId);
phaseNameToTranslate = _(phaseNameToTranslate); phaseNameToTranslate = _(phaseNameToTranslate);
sprintf(buf, _("(%s%s) %s").c_str(), currentP.c_str(), interrupt.c_str(),phaseNameToTranslate.c_str()); sprintf(buf, _("(%s%s) %s").c_str(), currentP.c_str(), interrupt.c_str(),phaseNameToTranslate.c_str());
font->DrawString(buf, SCREEN_WIDTH - 5, 2, JGETEXT_RIGHT); font->DrawString(buf, SCREEN_WIDTH - 5, 2, JGETEXT_RIGHT);
@@ -170,8 +151,8 @@ int GuiPhaseBar::receiveEventMinus(WEvent *e)
WEventPhaseChange *event = dynamic_cast<WEventPhaseChange*> (e); WEventPhaseChange *event = dynamic_cast<WEventPhaseChange*> (e);
if (event) if (event)
{ {
angle = M_PI / 6; int phasesToAnimate = (event->to->id - displayedPhaseId + kPhases) % kPhases;
phase = event->to; angleEasing.start(float(phasesToAnimate * (- step)), 0.3f * float(sqrt(phasesToAnimate)));
} }
return 1; return 1;
} }