made DeckMenuItem a subclass of SimpleMenuItem
moved code to check on click position into base class from DeckMenuItem TODO: apply same logic for standard menus
This commit is contained in:
@@ -5,24 +5,18 @@
|
|||||||
#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 JGuiObject
|
class DeckMenuItem: public SimpleMenuItem
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
bool mHasFocus;
|
|
||||||
bool mScrollEnabled;
|
bool mScrollEnabled;
|
||||||
bool mDisplayInitialized;
|
bool mDisplayInitialized;
|
||||||
bool mIsValidSelection;
|
|
||||||
|
|
||||||
DeckMenu* parent;
|
DeckMenu* parent;
|
||||||
int fontId;
|
|
||||||
string mText;
|
|
||||||
float mTitleResetWidth;
|
float mTitleResetWidth;
|
||||||
static float mYOffset;
|
|
||||||
|
|
||||||
void checkUserClick();
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
string imageFilename;
|
string imageFilename;
|
||||||
@@ -30,11 +24,9 @@ public:
|
|||||||
float mScrollerOffset;
|
float mScrollerOffset;
|
||||||
DeckMetaData *meta;
|
DeckMetaData *meta;
|
||||||
|
|
||||||
float mX;
|
|
||||||
float mY;
|
|
||||||
|
|
||||||
void Relocate(float x, float y);
|
void Relocate(float x, float y);
|
||||||
float GetWidth();
|
float GetWidth();
|
||||||
|
|
||||||
string GetText()
|
string GetText()
|
||||||
{
|
{
|
||||||
return mText;
|
return mText;
|
||||||
|
|||||||
@@ -14,16 +14,25 @@ using std::string;
|
|||||||
class SimpleMenuItem: public JGuiObject
|
class SimpleMenuItem: public JGuiObject
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
bool mHasFocus;
|
|
||||||
SimpleMenu* parent;
|
SimpleMenu* parent;
|
||||||
int fontId;
|
|
||||||
string mText;
|
|
||||||
float mScale;
|
float mScale;
|
||||||
float mTargetScale;
|
float mTargetScale;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
int fontId;
|
||||||
|
string mText;
|
||||||
|
bool mHasFocus;
|
||||||
static float mYOffset;
|
static float mYOffset;
|
||||||
|
float mXOffset;
|
||||||
|
|
||||||
|
bool mIsValidSelection;
|
||||||
|
void checkUserClick();
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
string desc;
|
string desc;
|
||||||
|
SimpleMenuItem(int id);
|
||||||
SimpleMenuItem(SimpleMenu* _parent, int id, int fontId, string text, float x, float y, bool hasFocus = false, bool autoTranslate = false);
|
SimpleMenuItem(SimpleMenu* _parent, int id, int fontId, string text, float x, float y, bool hasFocus = false, bool autoTranslate = false);
|
||||||
|
|
||||||
float mX;
|
float mX;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "PrecompiledHeader.h"
|
#include "PrecompiledHeader.h"
|
||||||
|
|
||||||
#include "DeckMenuItem.h"
|
#include "DeckMenuItem.h"
|
||||||
#include "Translate.h"
|
#include "Translate.h"
|
||||||
@@ -11,19 +11,22 @@
|
|||||||
|
|
||||||
const int kHorizontalScrollSpeed = 30; // higher numbers mean faster scrolling
|
const int kHorizontalScrollSpeed = 30; // higher numbers mean faster scrolling
|
||||||
|
|
||||||
float DeckMenuItem::mYOffset = 0;
|
DeckMenuItem::DeckMenuItem(DeckMenu* _parent, int id, int iFontId, string text, float x, float y, bool hasFocus, bool autoTranslate, DeckMetaData *deckMetaData): SimpleMenuItem(id)
|
||||||
|
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
|
mEngine = JGE::GetInstance();
|
||||||
|
parent = _parent;
|
||||||
|
fontId = iFontId;
|
||||||
|
mY = y;
|
||||||
|
mX = x;
|
||||||
WFont * mFont = WResourceManager::Instance()->GetWFont(fontId);
|
WFont * mFont = WResourceManager::Instance()->GetWFont(fontId);
|
||||||
meta = deckMetaData;
|
meta = deckMetaData;
|
||||||
mText = trim(text);
|
mText = trim(text);
|
||||||
mIsValidSelection = false;
|
SimpleMenuItem::mIsValidSelection = false;
|
||||||
|
|
||||||
if (autoTranslate)
|
if (autoTranslate)
|
||||||
mText = _(mText);
|
mText = _(mText);
|
||||||
|
|
||||||
|
mXOffset = kItemXOffset;
|
||||||
|
|
||||||
mHasFocus = hasFocus;
|
mHasFocus = hasFocus;
|
||||||
float newImageWidth = 0.0f;
|
float newImageWidth = 0.0f;
|
||||||
@@ -89,7 +92,7 @@ void DeckMenuItem::Update(float dt)
|
|||||||
|
|
||||||
void DeckMenuItem::RenderWithOffset(float yOffset)
|
void DeckMenuItem::RenderWithOffset(float yOffset)
|
||||||
{
|
{
|
||||||
mYOffset = yOffset;
|
SimpleMenuItem::mYOffset = yOffset;
|
||||||
|
|
||||||
WFont * mFont = WResourceManager::Instance()->GetWFont(fontId);
|
WFont * mFont = WResourceManager::Instance()->GetWFont(fontId);
|
||||||
|
|
||||||
@@ -120,26 +123,10 @@ void DeckMenuItem::Render()
|
|||||||
RenderWithOffset(0);
|
RenderWithOffset(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckMenuItem::checkUserClick()
|
|
||||||
{
|
|
||||||
#ifdef IOS
|
|
||||||
int x1 = -1, y1 = -1;
|
|
||||||
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;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void DeckMenuItem::Entering()
|
void DeckMenuItem::Entering()
|
||||||
{
|
{
|
||||||
checkUserClick();
|
SimpleMenuItem::checkUserClick();
|
||||||
mHasFocus = true;
|
mHasFocus = true;
|
||||||
parent->mSelectionTargetY = mY;
|
parent->mSelectionTargetY = mY;
|
||||||
}
|
}
|
||||||
@@ -147,14 +134,14 @@ void DeckMenuItem::Entering()
|
|||||||
bool DeckMenuItem::Leaving(JButton key)
|
bool DeckMenuItem::Leaving(JButton key)
|
||||||
{
|
{
|
||||||
// check to see if the user clicked on the object, if so return true.
|
// check to see if the user clicked on the object, if so return true.
|
||||||
checkUserClick();
|
SimpleMenuItem::checkUserClick();
|
||||||
mHasFocus = false;
|
mHasFocus = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeckMenuItem::ButtonPressed()
|
bool DeckMenuItem::ButtonPressed()
|
||||||
{
|
{
|
||||||
return mIsValidSelection;
|
return SimpleMenuItem::mIsValidSelection;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckMenuItem::Relocate(float x, float y)
|
void DeckMenuItem::Relocate(float x, float y)
|
||||||
|
|||||||
@@ -6,6 +6,11 @@
|
|||||||
|
|
||||||
float SimpleMenuItem::mYOffset = 0;
|
float SimpleMenuItem::mYOffset = 0;
|
||||||
|
|
||||||
|
SimpleMenuItem::SimpleMenuItem(int id): JGuiObject(id)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
SimpleMenuItem::SimpleMenuItem(SimpleMenu* _parent, int id, int fontId, string text, float x, float y, bool hasFocus, bool autoTranslate) :
|
SimpleMenuItem::SimpleMenuItem(SimpleMenu* _parent, int id, int fontId, string text, float x, float y, bool hasFocus, bool autoTranslate) :
|
||||||
JGuiObject(id), parent(_parent), fontId(fontId), mX(x), mY(y)
|
JGuiObject(id), parent(_parent), fontId(fontId), mX(x), mY(y)
|
||||||
{
|
{
|
||||||
@@ -17,7 +22,8 @@ SimpleMenuItem::SimpleMenuItem(SimpleMenu* _parent, int id, int fontId, string t
|
|||||||
|
|
||||||
mScale = 1.0f;
|
mScale = 1.0f;
|
||||||
mTargetScale = 1.0f;
|
mTargetScale = 1.0f;
|
||||||
|
|
||||||
|
mXOffset = mX;
|
||||||
if (hasFocus) Entering();
|
if (hasFocus) Entering();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,6 +53,20 @@ void SimpleMenuItem::Update(float dt)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SimpleMenuItem::checkUserClick()
|
||||||
|
{
|
||||||
|
int x1 = -1, y1 = -1;
|
||||||
|
if (mEngine->GetLeftClickCoordinates(x1, y1))
|
||||||
|
{
|
||||||
|
mIsValidSelection = false;
|
||||||
|
int x2 = mXOffset, y2 = static_cast<int>(mY + mYOffset);
|
||||||
|
if ( (x1 >= x2) && (x1 <= (x2 + 200)) && (y1 >= y2) && (y1 < (y2 + 30)))
|
||||||
|
mIsValidSelection = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
mIsValidSelection = true;
|
||||||
|
}
|
||||||
|
|
||||||
void SimpleMenuItem::Entering()
|
void SimpleMenuItem::Entering()
|
||||||
{
|
{
|
||||||
mHasFocus = true;
|
mHasFocus = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user