fixed line endings
fixed horizontal scrolling to be controlled by a function of dt as per linshier suggestion. * this allows compatibility for multi-byte character sets
This commit is contained in:
@@ -10,42 +10,42 @@ using std::string;
|
|||||||
|
|
||||||
class DeckMenuItem: public JGuiObject
|
class DeckMenuItem: public JGuiObject
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
bool mHasFocus;
|
bool mHasFocus;
|
||||||
bool mScrollEnabled;
|
bool mScrollEnabled;
|
||||||
int mRemainder; // difference between the number of characters shown and full title
|
bool mDisplayInitialized;
|
||||||
|
|
||||||
DeckMenu* parent;
|
DeckMenu* parent;
|
||||||
int fontId;
|
int fontId;
|
||||||
string mText;
|
string mText;
|
||||||
|
float mTitleResetWidth;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
string imageFilename;
|
string imageFilename;
|
||||||
string desc;
|
string desc;
|
||||||
string displayName;
|
float mScrollerOffset;
|
||||||
int mScrollTimer;
|
DeckMetaData *meta;
|
||||||
DeckMetaData *meta;
|
|
||||||
|
|
||||||
float mX;
|
float mX;
|
||||||
float mY;
|
float mY;
|
||||||
|
|
||||||
void Relocate(float x, float y);
|
void Relocate(float x, float y);
|
||||||
float GetWidth();
|
float GetWidth();
|
||||||
string GetText() { return mText; }
|
string GetText() { return mText; }
|
||||||
string GetDescription() { return desc; }
|
string GetDescription() { return desc; }
|
||||||
bool hasFocus();
|
bool hasFocus();
|
||||||
|
|
||||||
DeckMenuItem(DeckMenu* _parent, int id, int fontId, string text, float x, float y, bool hasFocus = false, bool autoTranslate = false, DeckMetaData *meta = NULL);
|
DeckMenuItem(DeckMenu* _parent, int id, int fontId, string text, float x, float y, bool hasFocus = false, bool autoTranslate = false, DeckMetaData *meta = NULL);
|
||||||
~DeckMenuItem();
|
~DeckMenuItem();
|
||||||
|
|
||||||
void RenderWithOffset(float yOffset);
|
void RenderWithOffset(float yOffset);
|
||||||
virtual void Render();
|
virtual void Render();
|
||||||
|
virtual void Update( float dt );
|
||||||
virtual void Entering();
|
virtual void Entering();
|
||||||
virtual bool Leaving(JButton key);
|
virtual bool Leaving(JButton key);
|
||||||
virtual bool ButtonPressed();
|
virtual bool ButtonPressed();
|
||||||
virtual ostream& toString(ostream& out) const;
|
virtual ostream& toString(ostream& out) const;
|
||||||
virtual bool getTopLeft(float& top, float& left) {top = mY; left = mX; return true;};
|
virtual bool getTopLeft(float& top, float& left) {top = mY; left = mX; return true;};
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ JGuiController(id, listener), fontId(fontId), mShowDetailsScreen( showDetailsOve
|
|||||||
mSelectedDeck = NULL;
|
mSelectedDeck = NULL;
|
||||||
mY = 50;
|
mY = 50;
|
||||||
mWidth = 176;
|
mWidth = 176;
|
||||||
mX = 110;
|
mX = 115;
|
||||||
|
|
||||||
titleX = 110; // center point in title box
|
titleX = 110; // center point in title box
|
||||||
titleY = 15;
|
titleY = 15;
|
||||||
|
|||||||
@@ -5,74 +5,78 @@
|
|||||||
#include "WResourceManager.h"
|
#include "WResourceManager.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
#define ITEM_PX_WIDTH 190.f
|
#define ITEM_PX_WIDTH 190.0f
|
||||||
const int kHorizontalScrollSpeed = 10; // lower numbers mean faster scrolling
|
|
||||||
|
const int kHorizontalScrollSpeed = 30; // higher numbers mean faster scrolling
|
||||||
|
|
||||||
DeckMenuItem::DeckMenuItem(DeckMenu* _parent, int id, int fontId, string text, float x, float y, bool hasFocus, bool autoTranslate, DeckMetaData *deckMetaData)
|
DeckMenuItem::DeckMenuItem(DeckMenu* _parent, int id, int fontId, string text, float x, float y, bool hasFocus, bool autoTranslate, DeckMetaData *deckMetaData)
|
||||||
: JGuiObject(id), parent(_parent), fontId(fontId), mX(x), mY(y)
|
: JGuiObject(id), parent(_parent), fontId(fontId), mX(x), mY(y)
|
||||||
{
|
{
|
||||||
|
WFont * mFont = resources.GetWFont(fontId);
|
||||||
|
meta = deckMetaData;
|
||||||
mText = trim(text);
|
mText = trim(text);
|
||||||
displayName = text;
|
|
||||||
if (autoTranslate)
|
if (autoTranslate)
|
||||||
mText = _(mText);
|
mText = _(mText);
|
||||||
|
|
||||||
WFont * mFont = resources.GetWFont(fontId);
|
|
||||||
while (mFont->GetStringWidth(displayName.c_str()) > ITEM_PX_WIDTH)
|
|
||||||
displayName.erase(displayName.size() - 1);
|
|
||||||
|
|
||||||
mScrollTimer = 0;
|
|
||||||
mHasFocus = hasFocus;
|
mHasFocus = hasFocus;
|
||||||
mScrollEnabled = (displayName.length() != mText.length()) ;
|
float newImageWidth = 0.0f;
|
||||||
|
|
||||||
if (mScrollEnabled)
|
|
||||||
mText.append(" "); // add padding to reduce jerkiness when text scrolls
|
|
||||||
|
|
||||||
mRemainder = ( mText.length() - displayName.length() );
|
|
||||||
|
|
||||||
|
|
||||||
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);
|
|
||||||
string menuItemString = displayName;
|
|
||||||
size_t offset = 0;
|
|
||||||
|
|
||||||
if ( mHasFocus && mScrollEnabled )
|
|
||||||
{
|
|
||||||
offset = mScrollTimer / kHorizontalScrollSpeed;
|
|
||||||
int wrapIndexEnd = mText.length() - offset;
|
|
||||||
int nbWrapAroundChars = displayName.length() - wrapIndexEnd;
|
|
||||||
menuItemString = mText.substr(offset, displayName.length());
|
|
||||||
if ( nbWrapAroundChars > 0 )
|
|
||||||
// need to append start of title to end of menuItemString
|
|
||||||
menuItemString.append( mText.substr(0, nbWrapAroundChars ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
mFont->DrawString(menuItemString.c_str(), mX, mY + yOffset, JGETEXT_CENTER);
|
|
||||||
if ( mHasFocus && mScrollEnabled && offset == mText.length())
|
|
||||||
mScrollTimer = 0;
|
|
||||||
else if (mHasFocus && mScrollEnabled)
|
|
||||||
mScrollTimer++;
|
|
||||||
|
|
||||||
//Render a "new" icon for decks that have never been played yet
|
|
||||||
if (meta && !meta->getGamesPlayed())
|
if (meta && !meta->getGamesPlayed())
|
||||||
{
|
{
|
||||||
JTexture * tex = resources.RetrieveTexture("new.png");
|
JTexture * tex = resources.RetrieveTexture("new.png");
|
||||||
if (tex)
|
if (tex)
|
||||||
{
|
{
|
||||||
JQuad * quad = resources.RetrieveQuad("new.png", 2, 2, tex->mWidth - 4, tex->mHeight - 4); //avoids weird rectangle aroudn the texture because of bilinear filtering
|
JQuad * quad = resources.RetrieveQuad("new.png", 2.0f, 2.0f, tex->mWidth - 4.0f, tex->mHeight - 4.0f); //avoids weird rectangle around the texture because of bilinear filtering
|
||||||
quad->SetHotSpot(quad->mWidth/2, quad->mHeight/2);
|
newImageWidth = quad->mWidth;
|
||||||
float x = mX + min(ITEM_PX_WIDTH - quad->mWidth, mFont->GetStringWidth(menuItemString.c_str()))/2 + quad->mWidth/2;
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
float titleStringWidth = mFont->GetStringWidth( mText.c_str() );
|
||||||
|
mTitleResetWidth = (titleStringWidth - newImageWidth )/ 2;
|
||||||
|
mScrollEnabled = titleStringWidth > ( ITEM_PX_WIDTH - newImageWidth );
|
||||||
|
mScrollerOffset = 0.0f;
|
||||||
|
|
||||||
|
if (hasFocus)
|
||||||
|
Entering();
|
||||||
|
|
||||||
|
if (meta && meta->getAvatarFilename().size() > 0)
|
||||||
|
this->imageFilename = meta->getAvatarFilename();
|
||||||
|
else
|
||||||
|
this->imageFilename = "avatar.jpg";
|
||||||
|
|
||||||
|
mDisplayInitialized = false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeckMenuItem::Update(float dt)
|
||||||
|
{
|
||||||
|
mScrollerOffset += kHorizontalScrollSpeed * dt;
|
||||||
|
if ( (mScrollerOffset) > mTitleResetWidth )
|
||||||
|
mScrollerOffset = -ITEM_PX_WIDTH;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void DeckMenuItem::RenderWithOffset(float yOffset)
|
||||||
|
{
|
||||||
|
WFont * mFont = resources.GetWFont(fontId);
|
||||||
|
|
||||||
|
if (!( mHasFocus && mScrollEnabled ))
|
||||||
|
mScrollerOffset = 0;
|
||||||
|
if (!mHasFocus && mScrollEnabled)
|
||||||
|
mScrollerOffset = -1 * ( GetWidth() - ITEM_PX_WIDTH )/2;
|
||||||
|
float offSet = mScrollerOffset;
|
||||||
|
|
||||||
|
mFont->DrawString(mText.c_str(), mX, mY + yOffset, JGETEXT_CENTER, offSet, ITEM_PX_WIDTH);
|
||||||
|
mDisplayInitialized = true;
|
||||||
|
//Render a "new" icon for decks that have never been played yet
|
||||||
|
if (meta && !meta->getGamesPlayed())
|
||||||
|
{
|
||||||
|
JTexture * tex = resources.RetrieveTexture("new.png");
|
||||||
|
if (tex)
|
||||||
|
{
|
||||||
|
JQuad * quad = resources.RetrieveQuad("new.png", 2.0f, 2.0f, tex->mWidth - 4.0f, tex->mHeight - 4.0f); //avoids weird rectangle aroudn the texture because of bilinear filtering
|
||||||
|
quad->SetHotSpot(quad->mWidth/2.0f, quad->mHeight/2.0f);
|
||||||
|
float x = mX + min(ITEM_PX_WIDTH - quad->mWidth, GetWidth() )/2 + quad->mWidth/2;
|
||||||
if (quad) JRenderer::GetInstance()->RenderQuad(quad, x , mY + yOffset + quad->mHeight/2, 0.5);
|
if (quad) JRenderer::GetInstance()->RenderQuad(quad, x , mY + yOffset + quad->mHeight/2, 0.5);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,10 +17,8 @@ vector<DeckMetaData *> GameState::fillDeckMenu(SimpleMenu * _menu, const string&
|
|||||||
Player * statsPlayer)
|
Player * statsPlayer)
|
||||||
{
|
{
|
||||||
bool translate = _menu->autoTranslate;
|
bool translate = _menu->autoTranslate;
|
||||||
_menu->autoTranslate = false;
|
|
||||||
vector<DeckMetaData *> deckMetaDataVector = getValidDeckMetaData(path, smallDeckPrefix, statsPlayer);
|
vector<DeckMetaData *> deckMetaDataVector = getValidDeckMetaData(path, smallDeckPrefix, statsPlayer);
|
||||||
renderDeckMenu(_menu, deckMetaDataVector);
|
renderDeckMenu(_menu, deckMetaDataVector);
|
||||||
_menu->autoTranslate = translate;
|
|
||||||
|
|
||||||
return deckMetaDataVector;
|
return deckMetaDataVector;
|
||||||
}
|
}
|
||||||
@@ -29,10 +27,8 @@ vector<DeckMetaData *> GameState::fillDeckMenu(DeckMenu * _menu, const string& p
|
|||||||
Player * statsPlayer, int maxDecks)
|
Player * statsPlayer, int maxDecks)
|
||||||
{
|
{
|
||||||
bool translate = _menu->mAutoTranslate;
|
bool translate = _menu->mAutoTranslate;
|
||||||
_menu->mAutoTranslate = false;
|
|
||||||
vector<DeckMetaData *> deckMetaDataVector = getValidDeckMetaData(path, smallDeckPrefix, statsPlayer, maxDecks);
|
vector<DeckMetaData *> deckMetaDataVector = getValidDeckMetaData(path, smallDeckPrefix, statsPlayer, maxDecks);
|
||||||
renderDeckMenu(_menu, deckMetaDataVector);
|
renderDeckMenu(_menu, deckMetaDataVector);
|
||||||
_menu->mAutoTranslate = translate;
|
|
||||||
|
|
||||||
return deckMetaDataVector;
|
return deckMetaDataVector;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user