Added first draft of an interactive button. Needs to handle addition of images a little better

refined detailed info window for stats display
removed PSP button for Touch interfaces (currently only iOS and Android) on deck selection screens
to not break the core engine and reduce some more complex code, I created a new vector in the JController object. mButtons.  This vector will contain all the valid buttons for a given screen.  The appropriate Add/Remove methods have been updated to account for this new vector.
This commit is contained in:
techdragon.nguyen@gmail.com
2012-01-25 18:35:24 +00:00
parent 59fad775c8
commit a36d886dd5
16 changed files with 523 additions and 232 deletions

View File

@@ -4,142 +4,32 @@
#include "Translate.h"
#include "WResourceManager.h"
float SimpleMenuItem::mYOffset = 0;
SimpleMenuItem::SimpleMenuItem(int id): JGuiObject(id)
SimpleMenuItem::SimpleMenuItem(int id): SimpleButton(id)
{
mIsValidSelection = false;
}
SimpleMenuItem::SimpleMenuItem(SimpleMenu* _parent, int id, int fontId, string text, float x, float y, bool hasFocus, bool autoTranslate) :
JGuiObject(id), parent(_parent), mX(x), mY(y), mFontId(fontId)
SimpleButton( _parent, id, fontId, text, x, y, hasFocus, autoTranslate)
{
if (autoTranslate)
mText = _(text);
else
mText = text;
parent = (SimpleMenu *) _parent;
mDescription = "";
mHasFocus = hasFocus;
mScale = 1.0f;
mTargetScale = 1.0f;
mXOffset = mX;
if (hasFocus)
{
setIsSelectionValid(true);
Entering();
}
else
{
setIsSelectionValid(false);
}
}
void SimpleMenuItem::RenderWithOffset(float yOffset)
{
mYOffset = yOffset;
WFont * mFont = WResourceManager::Instance()->GetWFont(mFontId);
mFont->DrawString(mText.c_str(), mX, mY + yOffset, JGETEXT_CENTER);
}
void SimpleMenuItem::Render()
{
RenderWithOffset(0);
}
void SimpleMenuItem::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 SimpleMenuItem::checkUserClick()
{
setIsSelectionValid(true);
}
void SimpleMenuItem::Entering()
{
checkUserClick();
mHasFocus = true;
if (parent != NULL)
parent->selectionTargetY = mY;
}
setFocus(true);
if (getParent() != NULL)
{
SimpleMenu *menu = (SimpleMenu *) parent;
menu->selectionTargetY = getY();
}
bool SimpleMenuItem::Leaving(JButton key)
{
checkUserClick();
mHasFocus = false;
return true;
}
bool SimpleMenuItem::ButtonPressed()
{
return mIsValidSelection;
}
void SimpleMenuItem::Relocate(float x, float y)
{
mXOffset = x - (parent->getWidth()/2); // determines the leftmost point of the text;
mX = x;
mY = y;
}
/* Accessors */
float SimpleMenuItem::getX() const
{
return mX;
}
float SimpleMenuItem::getY() const
{
return mY;
}
void SimpleMenuItem::setFontId(const int &fontId)
{
mFontId = fontId;
}
int SimpleMenuItem::getFontId() const
{
return mFontId;
}
void SimpleMenuItem::setIsSelectionValid( bool validSelection )
{
mIsValidSelection = validSelection;
}
bool SimpleMenuItem::isSelectionValid() const
{
return mIsValidSelection;
}
void SimpleMenuItem::setFocus(bool value)
{
mHasFocus = value;
}
bool SimpleMenuItem::hasFocus() const
{
return mHasFocus;
}
string SimpleMenuItem::getDescription() const
{
return mDescription;
@@ -150,29 +40,13 @@ void SimpleMenuItem::setDescription( const string& desc )
mDescription = desc;
}
string SimpleMenuItem::getText() const
{
return mText;
}
void SimpleMenuItem::setText( const string& text)
{
mText = text;
}
float SimpleMenuItem::GetWidth() const
{
WFont * mFont = WResourceManager::Instance()->GetWFont(mFontId);
mFont->SetScale(1.0);
return mFont->GetStringWidth(mText.c_str());
}
ostream& SimpleMenuItem::toString(ostream& out) const
{
return out << "SimpleMenuItem ::: mHasFocus : " << mHasFocus
<< " ; parent : " << parent
<< " ; mText : " << mText
<< " ; mScale : " << mScale
<< " ; mTargetScale : " << mTargetScale
<< " ; mX,mY : " << mX << "," << mY;
return out << "SimpleMenuItem ::: mHasFocus : " << hasFocus()
<< " ; parent : " << getParent()
<< " ; mText : " << getText()
<< " ; mScale : " << getScale()
<< " ; mTargetScale : " << getTargetScale()
<< " ; mX,mY : " << getX() << "," << getY();
}