Revamped Deck Selection Screen using abrasax's design as a template.
TODO:
change literals to use constants,
refactor the rendering code for the menu to have be leaner.
add text scroller to list all the tasks.
* 1st implementation will list all the tasks.dat
* 2nd round will try to get the scroller to only display relevant tasks to ai
Special thanks to wololo and MootPoint for helping me hammer this out. To abrasax, for the initial design of the layout.
This commit is contained in:
109
projects/mtg/src/DeckMenuItem.cpp
Normal file
109
projects/mtg/src/DeckMenuItem.cpp
Normal file
@@ -0,0 +1,109 @@
|
||||
#include "PrecompiledHeader.h"
|
||||
|
||||
#include "DeckMenuItem.h"
|
||||
#include "Translate.h"
|
||||
#include "WResourceManager.h"
|
||||
|
||||
DeckMenuItem::DeckMenuItem(DeckMenu* _parent, int id, int fontId, string text, int x, int y, bool hasFocus, bool autoTranslate, DeckMetaData *deckMetaData): JGuiObject(id), parent(_parent), fontId(fontId), mX(x), mY(y)
|
||||
{
|
||||
if (autoTranslate)
|
||||
mText = _(text);
|
||||
else
|
||||
mText = text;
|
||||
mHasFocus = hasFocus;
|
||||
|
||||
mScale = 1.0f;
|
||||
mTargetScale = 1.0f;
|
||||
|
||||
if (hasFocus)
|
||||
Entering();
|
||||
|
||||
meta = deckMetaData;
|
||||
if ( meta && meta->getAvatarFilename().size() > 0 )
|
||||
this->imageFilename = meta->getAvatarFilename();
|
||||
else
|
||||
this->imageFilename = "avatar.jpg";
|
||||
|
||||
}
|
||||
|
||||
|
||||
void DeckMenuItem::RenderWithOffset(float yOffset)
|
||||
{
|
||||
WFont * mFont = resources.GetWFont(fontId);
|
||||
mFont->DrawString(mText.c_str(), mX, mY + yOffset, JGETEXT_CENTER);
|
||||
}
|
||||
|
||||
void DeckMenuItem::Render()
|
||||
{
|
||||
RenderWithOffset(0);
|
||||
}
|
||||
|
||||
void DeckMenuItem::Update(float dt)
|
||||
{
|
||||
if (mScale < mTargetScale)
|
||||
{
|
||||
mScale += 8.0f*dt;
|
||||
if (mScale > mTargetScale)
|
||||
mScale = mTargetScale;
|
||||
}
|
||||
else if (mScale > mTargetScale)
|
||||
{
|
||||
mScale -= 8.0f*dt;
|
||||
if (mScale < mTargetScale)
|
||||
mScale = mTargetScale;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DeckMenuItem::Entering()
|
||||
{
|
||||
mHasFocus = true;
|
||||
parent->selectionTargetY = mY;
|
||||
}
|
||||
|
||||
|
||||
bool DeckMenuItem::Leaving(JButton key)
|
||||
{
|
||||
mHasFocus = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool DeckMenuItem::ButtonPressed()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void DeckMenuItem::Relocate(int x, int y)
|
||||
{
|
||||
mX = x;
|
||||
mY = y;
|
||||
}
|
||||
|
||||
int DeckMenuItem::GetWidth()
|
||||
{
|
||||
WFont * mFont = resources.GetWFont(fontId);
|
||||
mFont->SetScale(1.0);
|
||||
return mFont->GetStringWidth(mText.c_str());
|
||||
}
|
||||
|
||||
bool DeckMenuItem::hasFocus()
|
||||
{
|
||||
return mHasFocus;
|
||||
}
|
||||
|
||||
ostream& DeckMenuItem::toString(ostream& out) const
|
||||
{
|
||||
return out << "DeckMenuItem ::: mHasFocus : " << mHasFocus
|
||||
<< " ; parent : " << parent
|
||||
<< " ; mText : " << mText
|
||||
<< " ; mScale : " << mScale
|
||||
<< " ; mTargetScale : " << mTargetScale
|
||||
<< " ; mX,mY : " << mX << "," << mY;
|
||||
}
|
||||
|
||||
|
||||
DeckMenuItem::~DeckMenuItem()
|
||||
{
|
||||
meta = NULL;
|
||||
}
|
||||
Reference in New Issue
Block a user