Merge branch 'more_easing' of https://github.com/ZobyTwo/wagic into ZobyTwo-more_easing

This commit is contained in:
xawotihs
2013-12-10 20:35:47 +01:00
7 changed files with 127 additions and 84 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;
@@ -167,6 +167,50 @@ public:
} }
}; };
/*! \brief This class defines an easing with quadratic acceleration
*/
class InQuadEasing : public Easing
{
public:
/*! \brief Calls Easing::Easing(val).
*
* \see Easing::Easing(float& val)
*/
InQuadEasing(float& val): Easing(val) {}
/*! \brief Implements the value calculation.
*
* \see Easing::updateValue()
*/
void updateValue()
{
float time_tmp = time_acc / duration;
value = delta_value * time_tmp * time_tmp + start_value;
}
};
/*! \brief This class defines an easing with quadratic decceleration
*/
class OutQuadEasing : public Easing
{
public:
/*! \brief Calls Easing::Easing(val).
*
* \see Easing::Easing(float& val)
*/
OutQuadEasing(float& val): Easing(val) {}
/*! \brief Implements the value calculation.
*
* \see Easing::updateValue()
*/
void updateValue()
{
float time_tmp = time_acc / duration;
value = (-delta_value) * time_tmp * (time_tmp - 2.0f) + start_value;
}
};
/*! \brief This class defines an easing with quadratic acceleration and decceleration. /*! \brief This class defines an easing with quadratic acceleration and decceleration.
*/ */
class InOutQuadEasing : public Easing class InOutQuadEasing : public Easing

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

@@ -2,8 +2,15 @@
#define TASK_H #define TASK_H
#include <vector> #include <vector>
#include <string>
#include "Easing.h"
using namespace std;
class GameObserver; class GameObserver;
class JQuad;
class JTexture;
// Task type constant // Task type constant
@@ -72,8 +79,11 @@ class TaskList
{ {
protected: protected:
string fileName; string fileName;
float vPos; float vPos;
float mElapsed; OutQuadEasing vPosInEasing;
InQuadEasing vPosOutEasing;
int mState; int mState;
JQuad * mBg[9]; JQuad * mBg[9];
JTexture * mBgTex; JTexture * mBgTex;
@@ -97,7 +107,6 @@ public:
{ {
return mState; return mState;
} }
;
void addTask(string params, bool rand = false); void addTask(string params, bool rand = false);
void addTask(Task *task); void addTask(Task *task);
void addRandomTask(int diff = 100); void addRandomTask(int diff = 100);

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)
{ {
@@ -496,7 +492,7 @@ void GameStateShop::Update(float dt)
} }
break; break;
case STAGE_SHOP_TASKS: case STAGE_SHOP_TASKS:
if (menu) if (menu && !menu->isClosed())
{ {
menu->Update(dt); menu->Update(dt);
return; return;

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;
} }

View File

@@ -258,9 +258,10 @@ Task* Task::createFromStr(const string params, bool rand)
/*---------------- TaskList -----------------*/ /*---------------- TaskList -----------------*/
TaskList::TaskList(string _fileName) TaskList::TaskList(string _fileName):
fileName(_fileName), vPos(-SCREEN_HEIGHT), vPosInEasing(vPos), vPosOutEasing(vPos)
{ {
fileName = _fileName;
if (fileName == "") if (fileName == "")
{ {
fileName = options.profileFile(PLAYER_TASKS).c_str(); fileName = options.profileFile(PLAYER_TASKS).c_str();
@@ -378,9 +379,10 @@ void TaskList::removeTask(Task *task)
void TaskList::Start() void TaskList::Start()
{ {
vPos = -SCREEN_HEIGHT; //Offscreen
mElapsed = 0;
mState = TASKS_IN; mState = TASKS_IN;
vPos = -SCREEN_HEIGHT; //Offscreen
vPosInEasing.start(0.0f, 1.0f);
if (!mBgTex) if (!mBgTex)
{ {
mBgTex = WResourceManager::Instance()->RetrieveTexture("taskboard.png", RETRIEVE_LOCK); mBgTex = WResourceManager::Instance()->RetrieveTexture("taskboard.png", RETRIEVE_LOCK);
@@ -410,7 +412,7 @@ void TaskList::Start()
void TaskList::End() void TaskList::End()
{ {
mState = TASKS_OUT; mState = TASKS_OUT;
mElapsed = 0; vPosOutEasing.start(float(-SCREEN_HEIGHT), 0.9f);
} }
void TaskList::passOneDay() void TaskList::passOneDay()
@@ -451,21 +453,23 @@ int TaskList::getTaskCount()
void TaskList::Update(float dt) void TaskList::Update(float dt)
{ {
mElapsed += dt; if(!vPosInEasing.finished())
if (mState == TASKS_IN && vPos < 0)
{ {
vPos = -SCREEN_HEIGHT + (SCREEN_HEIGHT * mElapsed / 0.75f); //Todo: more physical drop-in. vPosInEasing.update(dt);
if (vPos >= 0)
if(vPosInEasing.finished())
{ {
vPos = 0;
mState = TaskList::TASKS_ACTIVE; mState = TaskList::TASKS_ACTIVE;
} }
} }
else if (mState == TASKS_OUT && vPos > -SCREEN_HEIGHT) else if(!vPosOutEasing.finished())
{ {
vPos = -(SCREEN_HEIGHT * mElapsed / 0.75f); vPosOutEasing.update(dt);
if (vPos <= -SCREEN_HEIGHT) mState = TASKS_INACTIVE;
if(vPosOutEasing.finished())
{
mState = TASKS_INACTIVE;
}
} }
} }