had to undo my refactoring of the menuitem classes. for some reason it broke scrolling on the opponent ai selection screens.
This commit is contained in:
@@ -5,47 +5,81 @@
|
|||||||
#include <JLBFont.h>
|
#include <JLBFont.h>
|
||||||
#include <JGui.h>
|
#include <JGui.h>
|
||||||
#include "DeckMenu.h"
|
#include "DeckMenu.h"
|
||||||
#include "SimpleMenuItem.h"
|
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
class DeckMenuItem: public SimpleMenuItem
|
class DeckMenuItem: public JGuiObject
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
bool mHasFocus;
|
||||||
bool mScrollEnabled;
|
bool mScrollEnabled;
|
||||||
bool mDisplayInitialized;
|
bool mDisplayInitialized;
|
||||||
|
bool mIsValidSelection;
|
||||||
|
|
||||||
DeckMenu* deckController;
|
DeckMenu* parent;
|
||||||
float mTitleResetWidth;
|
int fontId;
|
||||||
|
string mText;
|
||||||
protected:
|
float mX;
|
||||||
virtual void checkUserClick();
|
float mY;
|
||||||
|
float mTitleResetWidth;
|
||||||
|
string mDescription;
|
||||||
|
static float mYOffset;
|
||||||
|
float mScrollerOffset;
|
||||||
|
DeckMetaData *mMetaData;
|
||||||
|
string mImageFilename;
|
||||||
|
void checkUserClick();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
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();
|
||||||
|
|
||||||
string imageFilename;
|
|
||||||
float mScrollerOffset;
|
|
||||||
DeckMetaData *meta;
|
|
||||||
|
|
||||||
virtual void Relocate(float x, float y);
|
virtual void Relocate(float x, float y);
|
||||||
virtual float GetWidth();
|
virtual void RenderWithOffset(float yOffset);
|
||||||
virtual void Render();
|
virtual void Render();
|
||||||
virtual void Update(float dt);
|
virtual void Update(float dt);
|
||||||
|
|
||||||
virtual bool getTopLeft(float& top, float& left)
|
|
||||||
{
|
|
||||||
return SimpleMenuItem::getTopLeft(top, left);
|
|
||||||
}
|
|
||||||
|
|
||||||
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 JGuiController* getParent() const;
|
|
||||||
virtual void RenderWithOffset(float yOffset);
|
virtual bool getTopLeft(float& top, float& left)
|
||||||
|
{
|
||||||
|
top = mY + mYOffset;
|
||||||
|
left = mX;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Accessors
|
||||||
|
|
||||||
|
string getImageFilename() const { return mImageFilename; };
|
||||||
|
float getY() const { return mY; };
|
||||||
|
float getX() const { return mX; };
|
||||||
|
string getDescription() const { return mDescription; };
|
||||||
|
string getText() const { return mText; };
|
||||||
|
bool hasFocus() const { return mHasFocus; };
|
||||||
|
bool hasMetaData() const { return mMetaData == NULL ? false : true;};
|
||||||
|
|
||||||
|
float getWidth() const;
|
||||||
|
string getDeckName() const;
|
||||||
|
|
||||||
|
string getDeckStatsSummary() const
|
||||||
|
{
|
||||||
|
if (mMetaData)
|
||||||
|
return mMetaData->getStatsSummary();
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
DeckMetaData *getMetaData() const
|
||||||
|
{
|
||||||
|
return mMetaData;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setters
|
||||||
|
void setDescription( const string description ) { mDescription = description; };
|
||||||
|
|
||||||
|
;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -233,15 +233,16 @@ void DeckMenu::Render()
|
|||||||
if (currentMenuItem->getY() - kLineHeight * startId < mY + height - kLineHeight + 7)
|
if (currentMenuItem->getY() - kLineHeight * startId < mY + height - kLineHeight + 7)
|
||||||
{
|
{
|
||||||
// only load stats for visible items in the list
|
// only load stats for visible items in the list
|
||||||
if (currentMenuItem->meta && !currentMenuItem->meta->mStatsLoaded)
|
DeckMetaData* metaData = currentMenuItem->getMetaData();
|
||||||
|
if (metaData && !metaData->mStatsLoaded)
|
||||||
{
|
{
|
||||||
currentMenuItem->meta->LoadStats();
|
metaData->LoadStats();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentMenuItem->hasFocus())
|
if (currentMenuItem->hasFocus())
|
||||||
{
|
{
|
||||||
mSelectedDeckId = i;
|
mSelectedDeckId = i;
|
||||||
mSelectedDeck = currentMenuItem->meta;
|
mSelectedDeck = metaData;
|
||||||
WFont *mainFont = WResourceManager::Instance()->GetWFont(Fonts::MAIN_FONT);
|
WFont *mainFont = WResourceManager::Instance()->GetWFont(Fonts::MAIN_FONT);
|
||||||
|
|
||||||
// display the "more info" button if special condition is met
|
// display the "more info" button if special condition is met
|
||||||
@@ -255,10 +256,10 @@ void DeckMenu::Render()
|
|||||||
dismissButton->setIsSelectionValid(false);
|
dismissButton->setIsSelectionValid(false);
|
||||||
}
|
}
|
||||||
// display the avatar image
|
// display the avatar image
|
||||||
if (currentMenuItem->imageFilename.size() > 0)
|
if (currentMenuItem->getImageFilename().size() > 0)
|
||||||
{
|
{
|
||||||
JQuadPtr quad;
|
JQuadPtr quad;
|
||||||
if(currentMenuItem->imageFilename == "EvilTwinAvatar")
|
if(currentMenuItem->getImageFilename() == "EvilTwinAvatar")
|
||||||
{
|
{
|
||||||
quad = WResourceManager::Instance()->RetrieveTempQuad("avatar.jpg", TEXTURE_SUB_AVATAR);
|
quad = WResourceManager::Instance()->RetrieveTempQuad("avatar.jpg", TEXTURE_SUB_AVATAR);
|
||||||
if(quad.get())
|
if(quad.get())
|
||||||
@@ -271,7 +272,7 @@ void DeckMenu::Render()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
quad = WResourceManager::Instance()->RetrieveTempQuad(currentMenuItem->imageFilename, TEXTURE_SUB_AVATAR);
|
quad = WResourceManager::Instance()->RetrieveTempQuad(currentMenuItem->getImageFilename(), TEXTURE_SUB_AVATAR);
|
||||||
if (quad.get())
|
if (quad.get())
|
||||||
renderer->RenderQuad(quad.get(), avatarX, avatarY);
|
renderer->RenderQuad(quad.get(), avatarX, avatarY);
|
||||||
|
|
||||||
@@ -284,11 +285,11 @@ void DeckMenu::Render()
|
|||||||
mFont->SetColor(ARGB(255,255,255,255));
|
mFont->SetColor(ARGB(255,255,255,255));
|
||||||
|
|
||||||
// fill in the statistical portion
|
// fill in the statistical portion
|
||||||
if (currentMenuItem->meta)
|
if (currentMenuItem->hasMetaData())
|
||||||
{
|
{
|
||||||
ostringstream oss;
|
ostringstream oss;
|
||||||
oss << _("Deck: ") << currentMenuItem->meta->getName() << endl;
|
oss << _("Deck: ") << currentMenuItem->getDeckName() << endl;
|
||||||
oss << currentMenuItem->meta->getStatsSummary();
|
oss << currentMenuItem->getDeckStatsSummary();
|
||||||
mainFont->DrawString(oss.str(), statsX, statsY);
|
mainFont->DrawString(oss.str(), statsX, statsY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "PrecompiledHeader.h"
|
#include "PrecompiledHeader.h"
|
||||||
|
|
||||||
#include "DeckMenuItem.h"
|
#include "DeckMenuItem.h"
|
||||||
#include "Translate.h"
|
#include "Translate.h"
|
||||||
@@ -11,22 +11,23 @@
|
|||||||
|
|
||||||
const int kHorizontalScrollSpeed = 30; // higher 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): SimpleMenuItem(NULL, id, fontId, text, x, y, hasFocus, autoTranslate)
|
float DeckMenuItem::mYOffset = 0;
|
||||||
{
|
|
||||||
mEngine = JGE::GetInstance();
|
|
||||||
deckController = _parent;
|
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
WFont * mFont = WResourceManager::Instance()->GetWFont(fontId);
|
WFont * mFont = WResourceManager::Instance()->GetWFont(fontId);
|
||||||
meta = deckMetaData;
|
mMetaData = deckMetaData;
|
||||||
mText = trim(text);
|
mText = trim(text);
|
||||||
|
mIsValidSelection = false;
|
||||||
|
|
||||||
if (autoTranslate)
|
if (autoTranslate)
|
||||||
mText = _(mText);
|
mText = _(mText);
|
||||||
|
|
||||||
mXOffset = kItemXOffset;
|
|
||||||
|
|
||||||
|
mHasFocus = hasFocus;
|
||||||
float newImageWidth = 0.0f;
|
float newImageWidth = 0.0f;
|
||||||
if (meta && !meta->getGamesPlayed())
|
if (mMetaData && !mMetaData->getGamesPlayed())
|
||||||
{
|
{
|
||||||
JTexture * tex = WResourceManager::Instance()->RetrieveTexture("new.png");
|
JTexture * tex = WResourceManager::Instance()->RetrieveTexture("new.png");
|
||||||
if (tex)
|
if (tex)
|
||||||
@@ -43,36 +44,37 @@ DeckMenuItem::DeckMenuItem(DeckMenu* _parent, int id, int fontId, string text, f
|
|||||||
|
|
||||||
if (hasFocus)
|
if (hasFocus)
|
||||||
{
|
{
|
||||||
setIsSelectionValid( true );
|
mIsValidSelection = true;
|
||||||
Entering();
|
Entering();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (meta && meta->getAvatarFilename().size() > 0)
|
if (mMetaData && mMetaData->getAvatarFilename().size() > 0)
|
||||||
this->imageFilename = meta->getAvatarFilename();
|
mImageFilename = mMetaData->getAvatarFilename();
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// this is a non-deck menu item (ie "Random", "Cancel", etc
|
// this is a non-deck menu item (ie "Random", "Cancel", etc
|
||||||
switch(id)
|
switch(id)
|
||||||
{
|
{
|
||||||
case kRandomPlayerMenuID:
|
case kRandomPlayerMenuID:
|
||||||
this->imageFilename = "noavatar.jpg";
|
mImageFilename = "noavatar.jpg";
|
||||||
break;
|
break;
|
||||||
case kRandomAIPlayerMenuID:
|
case kRandomAIPlayerMenuID:
|
||||||
this->imageFilename = "noavatar.jpg";
|
mImageFilename = "noavatar.jpg";
|
||||||
break;
|
break;
|
||||||
case kEvilTwinMenuID:
|
case kEvilTwinMenuID:
|
||||||
{
|
{
|
||||||
this->imageFilename = "EvilTwinAvatar";
|
mImageFilename = "EvilTwinAvatar";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
this->imageFilename = "noavatar.jpg";
|
mImageFilename = "noavatar.jpg";
|
||||||
// do nothing.
|
// do nothing.
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
mDisplayInitialized = false;
|
mDisplayInitialized = false;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -87,99 +89,105 @@ void DeckMenuItem::Update(float dt)
|
|||||||
|
|
||||||
void DeckMenuItem::RenderWithOffset(float yOffset)
|
void DeckMenuItem::RenderWithOffset(float yOffset)
|
||||||
{
|
{
|
||||||
SimpleMenuItem::mYOffset = yOffset;
|
mYOffset = yOffset;
|
||||||
|
|
||||||
WFont * mFont = WResourceManager::Instance()->GetWFont(getFontId());
|
WFont * mFont = WResourceManager::Instance()->GetWFont(fontId);
|
||||||
|
|
||||||
if (!( hasFocus() && mScrollEnabled ))
|
if (!( mHasFocus && mScrollEnabled ))
|
||||||
mScrollerOffset = 0;
|
mScrollerOffset = 0;
|
||||||
if (!hasFocus() && mScrollEnabled)
|
if (!mHasFocus && mScrollEnabled)
|
||||||
mScrollerOffset = -1 * ( GetWidth() - ITEM_PX_WIDTH )/2;
|
mScrollerOffset = -1 * ( getWidth() - ITEM_PX_WIDTH )/2;
|
||||||
float offSet = mScrollerOffset;
|
float offSet = mScrollerOffset;
|
||||||
|
|
||||||
mFont->DrawString( getText().c_str(), getX(), getY() + yOffset, JGETEXT_CENTER, offSet, ITEM_PX_WIDTH);
|
mFont->DrawString(mText.c_str(), mX, mY + yOffset, JGETEXT_CENTER, offSet, ITEM_PX_WIDTH);
|
||||||
mDisplayInitialized = true;
|
mDisplayInitialized = true;
|
||||||
//Render a "new" icon for decks that have never been played yet
|
//Render a "new" icon for decks that have never been played yet
|
||||||
if (meta && !meta->getGamesPlayed())
|
if (mMetaData && !mMetaData->getGamesPlayed())
|
||||||
{
|
{
|
||||||
JTexture * tex = WResourceManager::Instance()->RetrieveTexture("new.png");
|
JTexture * tex = WResourceManager::Instance()->RetrieveTexture("new.png");
|
||||||
if (tex)
|
if (tex)
|
||||||
{
|
{
|
||||||
JQuadPtr quad = WResourceManager::Instance()->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
|
JQuadPtr quad = WResourceManager::Instance()->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);
|
quad->SetHotSpot(quad->mWidth/2.0f, quad->mHeight/2.0f);
|
||||||
float x = getX() + min(ITEM_PX_WIDTH - quad->mWidth, GetWidth() )/2 + quad->mWidth/2;
|
float x = mX + min(ITEM_PX_WIDTH - quad->mWidth, getWidth() )/2 + quad->mWidth/2;
|
||||||
if (quad)
|
if (quad) JRenderer::GetInstance()->RenderQuad(quad.get(), x , mY + yOffset + quad->mHeight/2, 0.5);
|
||||||
JRenderer::GetInstance()->RenderQuad(quad.get(), x , getY() + yOffset + quad->mHeight/2, 0.5);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckMenuItem::Render()
|
void DeckMenuItem::Render()
|
||||||
{
|
{
|
||||||
RenderWithOffset(0);
|
RenderWithOffset(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckMenuItem::Relocate(float x, float y)
|
void DeckMenuItem::checkUserClick()
|
||||||
{
|
{
|
||||||
setX( x );
|
int x1 = -1, y1 = -1;
|
||||||
setY( y );
|
if (mEngine->GetLeftClickCoordinates(x1, y1))
|
||||||
|
{
|
||||||
|
mIsValidSelection = false;
|
||||||
|
int x2 = kItemXOffset, y2 = static_cast<int>(mY + mYOffset);
|
||||||
|
if ( (x1 >= x2) && (x1 <= (x2 + ITEM_PX_WIDTH)) && (y1 >= y2) && (y1 < (y2 + kItemYHeight)))
|
||||||
|
mIsValidSelection = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
mIsValidSelection = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void DeckMenuItem::Entering()
|
void DeckMenuItem::Entering()
|
||||||
{
|
{
|
||||||
checkUserClick();
|
checkUserClick();
|
||||||
setFocus(true);
|
mHasFocus = true;
|
||||||
deckController->mSelectionTargetY = getY();
|
parent->mSelectionTargetY = mY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool DeckMenuItem::Leaving(JButton key)
|
bool DeckMenuItem::Leaving(JButton key)
|
||||||
{
|
{
|
||||||
return SimpleMenuItem::Leaving(key);
|
// check to see if the user clicked on the object, if so return true.
|
||||||
|
checkUserClick();
|
||||||
|
mHasFocus = false;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeckMenuItem::ButtonPressed()
|
bool DeckMenuItem::ButtonPressed()
|
||||||
{
|
{
|
||||||
return SimpleMenuItem::ButtonPressed();
|
return mIsValidSelection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DeckMenuItem::Relocate(float x, float y)
|
||||||
void DeckMenuItem::checkUserClick()
|
|
||||||
{
|
{
|
||||||
int x1 = -1, y1 = -1;
|
mX = x;
|
||||||
if (mEngine->GetLeftClickCoordinates(x1, y1))
|
mY = y;
|
||||||
{
|
|
||||||
SimpleMenuItem::setIsSelectionValid( false );
|
|
||||||
int x2 = static_cast<int>(mXOffset), y2 = static_cast<int>(getY() + mYOffset);
|
|
||||||
if ( (x1 >= x2) && (x1 <= (x2 + 200)) && (y1 >= y2) && (y1 < (y2 + 30)))
|
|
||||||
setIsSelectionValid( true );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
setIsSelectionValid( true );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Accessors
|
float DeckMenuItem::getWidth() const
|
||||||
float DeckMenuItem::GetWidth()
|
|
||||||
{
|
{
|
||||||
WFont * mFont = WResourceManager::Instance()->GetWFont(getFontId());
|
WFont * mFont = WResourceManager::Instance()->GetWFont(fontId);
|
||||||
return mFont->GetStringWidth(getText().c_str());
|
return mFont->GetStringWidth(mText.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
string DeckMenuItem::getDeckName() const
|
||||||
|
{
|
||||||
|
if (mMetaData)
|
||||||
|
return mMetaData->getName();
|
||||||
|
|
||||||
|
std::string s;
|
||||||
|
std::stringstream out;
|
||||||
|
out << mMetaData->getDeckId();
|
||||||
|
s = out.str();
|
||||||
|
return "[deck" + s + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
ostream& DeckMenuItem::toString(ostream& out) const
|
ostream& DeckMenuItem::toString(ostream& out) const
|
||||||
{
|
{
|
||||||
return out << "DeckMenuItem ::: mHasFocus : " << hasFocus()
|
return out << "DeckMenuItem ::: mHasFocus : " << mHasFocus
|
||||||
<< " ; parent : " << deckController
|
<< " ; parent : " << parent
|
||||||
<< " ; mText : " << getText()
|
<< " ; mText : " << mText
|
||||||
<< " ; mX,mY : " << getX() << "," << getY();
|
<< " ; mX,mY : " << mX << "," << mY;
|
||||||
}
|
}
|
||||||
|
|
||||||
JGuiController* DeckMenuItem::getParent() const
|
|
||||||
{
|
|
||||||
return deckController;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
DeckMenuItem::~DeckMenuItem()
|
DeckMenuItem::~DeckMenuItem()
|
||||||
{
|
{
|
||||||
meta = NULL;
|
mMetaData = NULL;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user