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)
{
if(duration > 0)
if(time_acc < duration)
{
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.
*/
class InOutQuadEasing : public Easing

View File

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

View File

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

View File

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

View File

@@ -102,7 +102,6 @@ void GameStateShop::Start()
bListCards = false;
mTouched = false;
mStage = STAGE_FADE_IN;
mElapsed = 0;
needLoad = true;
booster = NULL;
srcCards = NEW WSrcUnlockedCards(0);
@@ -427,7 +426,7 @@ void GameStateShop::End()
{
save();
JRenderer::GetInstance()->EnableVSync(false);
mElapsed = 0;
SAFE_DELETE(shopMenu);
SAFE_DELETE(bigDisplay);
SAFE_DELETE(srcCards);
@@ -469,9 +468,6 @@ void GameStateShop::Update(float dt)
if (lightAlpha > 50)
lightAlpha = 50;
if (mStage != STAGE_FADE_IN)
mElapsed += dt;
JButton btn;
switch (mStage)
{
@@ -496,7 +492,7 @@ void GameStateShop::Update(float dt)
}
break;
case STAGE_SHOP_TASKS:
if (menu)
if (menu && !menu->isClosed())
{
menu->Update(dt);
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
{
//width and height of the phase symbol textures
const float kWidth = 28;
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;
const float CENTER = SCREEN_HEIGHT_F / 2 + 10;
void DrawGlyph(JQuad* inQuad, int inGlyph, float inY, float, unsigned int inP, float inScale)
{
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);
}
void GuiPhaseBar::DrawGlyph(JQuad *inQuad, int phaseId, float x, float y, float scale)
{
inQuad->SetTextureRect(phaseId * (kWidth + 1), 0, kWidth, kHeight);
JRenderer::GetInstance()->RenderQuad(inQuad, x, y - scale * kWidth/2, 0.0f, scale, scale);
}
GuiPhaseBar::GuiPhaseBar(DuelLayers* duelLayers) :
GuiLayer(duelLayers->getObserver()), PlayGuiObject(0, 0, 106, 0, false),
phase(NULL), angle(0.0f), zoomFactor(ICONSCALE), mpDuelLayers(duelLayers)
GuiLayer(duelLayers->getObserver()), PlayGuiObject(80, 0, 106, 0, false),
displayedPhaseId(0), angle(0.0f), zoomFactor(zoom_small), angleEasing(angle),
zoomFactorEasing(zoomFactor), mpDuelLayers(duelLayers)
{
if(duelLayers->getObserver()->getResourceManager())
{
@@ -57,10 +59,7 @@ GuiPhaseBar::GuiPhaseBar(DuelLayers* duelLayers) :
GameApp::systemError = "Error loading phasebar texture : " __FILE__;
}
zoom = ICONSCALE;
mpDuelLayers->getCardSelector()->Add(this);
}
GuiPhaseBar::~GuiPhaseBar()
@@ -69,32 +68,27 @@ GuiPhaseBar::~GuiPhaseBar()
void GuiPhaseBar::Update(float dt)
{
if (angle > 3 * dt)
angle -= 3 * dt;
else
angle = 0;
angleEasing.update(dt);
if (dt > 0.05f) dt = 0.05f;
if(zoomFactor + 0.05f < zoom)
if(angle <= -step)
{
zoomFactor += dt;
}
else if (zoomFactor - 0.05f > zoom)
{
zoomFactor -= dt;
displayedPhaseId = (displayedPhaseId + 1) % kPhases;
angleEasing.translate(step);
}
zoomFactorEasing.update(dt);
}
void GuiPhaseBar::Entering()
{
mHasFocus = true;
zoom = 1.4f*ICONSCALE;
zoomFactorEasing.start(zoom_big, 0.3f);
}
bool GuiPhaseBar::Leaving(JButton)
{
mHasFocus = false;
zoom = ICONSCALE;
zoomFactorEasing.start(zoom_small, 0.6f);
return true;
}
@@ -102,41 +96,28 @@ void GuiPhaseBar::Render()
{
JQuadPtr quad = WResourceManager::Instance()->GetQuad("phasebar");
//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);
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;
}
const float radius = 25 * zoomFactor;
yPos = centerYPosition;
for (int glyph = 2; glyph > 0; --glyph)
for(int i = 0; i < 6; ++i)
{
scale = zoomFactor * sinf(angle + glyph * M_PI / 6) / 2;
yPos -= kWidth * scale;
DrawGlyph(quad.get(), glyph, yPos, angle, p, scale);
}
//the position of the glyphe in the circle
const float circPos = (i - 2) * step + angle;
const float glyphY = this->y + this->mHeight / 2 + sin(circPos) * radius;
if (angle > 0)
{
scale = zoomFactor * sinf(angle) / 2;
yPos -= kWidth * scale;
float xPos = static_cast<float> (p % (kPhases * (int) (kWidth + 1)));
quad->SetTextureRect(xPos, kHeight, kWidth, kHeight);
JRenderer::GetInstance()->RenderQuad(quad.get(), 0, yPos, 0.0, scale, scale);
//the scale is computed so that the glyphes touch each other
//hint: sin(circPos + PI/2) = cos(circPos)
const float glyphScale = zoomFactor * cosf(circPos) * 0.5;
DrawGlyph(quad.get(), (displayedPhaseId - 3 + kPhases + i) % kPhases, 0, glyphY, glyphScale);
}
//print phase name
WFont * font = WResourceManager::Instance()->GetWFont(Fonts::MAIN_FONT);
string currentP = _("your turn");
string interrupt = "";
if (observer->currentPlayer == mpDuelLayers->getRenderedPlayerOpponent())
if (observer->currentPlayer == mpDuelLayers->getRenderedPlayerOpponent())
{
currentP = _("opponent's turn");
}
@@ -147,7 +128,7 @@ void GuiPhaseBar::Render()
}
if (observer->currentlyActing() != observer->currentPlayer)
{
if (observer->currentPlayer == mpDuelLayers->getRenderedPlayer())
if (observer->currentPlayer == mpDuelLayers->getRenderedPlayer())
{
interrupt = _(" - ") + _("opponent plays");
}
@@ -159,7 +140,7 @@ void GuiPhaseBar::Render()
char buf[200];
//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);
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);
@@ -170,8 +151,8 @@ int GuiPhaseBar::receiveEventMinus(WEvent *e)
WEventPhaseChange *event = dynamic_cast<WEventPhaseChange*> (e);
if (event)
{
angle = M_PI / 6;
phase = event->to;
int phasesToAnimate = (event->to->id - displayedPhaseId + kPhases) % kPhases;
angleEasing.start(float(phasesToAnimate * (- step)), 0.3f * float(sqrt(phasesToAnimate)));
}
return 1;
}

View File

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