diff --git a/projects/mtg/include/DeckMenuItem.h b/projects/mtg/include/DeckMenuItem.h index 27ae40c74..1b063f6dc 100644 --- a/projects/mtg/include/DeckMenuItem.h +++ b/projects/mtg/include/DeckMenuItem.h @@ -5,24 +5,18 @@ #include #include #include "DeckMenu.h" +#include "SimpleMenuItem.h" using std::string; -class DeckMenuItem: public JGuiObject +class DeckMenuItem: public SimpleMenuItem { private: - bool mHasFocus; bool mScrollEnabled; bool mDisplayInitialized; - bool mIsValidSelection; DeckMenu* parent; - int fontId; - string mText; float mTitleResetWidth; - static float mYOffset; - - void checkUserClick(); public: string imageFilename; @@ -30,11 +24,9 @@ public: float mScrollerOffset; DeckMetaData *meta; - float mX; - float mY; - void Relocate(float x, float y); float GetWidth(); + string GetText() { return mText; diff --git a/projects/mtg/include/SimpleMenuItem.h b/projects/mtg/include/SimpleMenuItem.h index 50e5978d1..cca6dd2b9 100644 --- a/projects/mtg/include/SimpleMenuItem.h +++ b/projects/mtg/include/SimpleMenuItem.h @@ -14,16 +14,25 @@ using std::string; class SimpleMenuItem: public JGuiObject { private: - bool mHasFocus; + SimpleMenu* parent; - int fontId; - string mText; float mScale; float mTargetScale; + +protected: + int fontId; + string mText; + bool mHasFocus; static float mYOffset; + float mXOffset; + + bool mIsValidSelection; + void checkUserClick(); + public: string desc; + SimpleMenuItem(int id); SimpleMenuItem(SimpleMenu* _parent, int id, int fontId, string text, float x, float y, bool hasFocus = false, bool autoTranslate = false); float mX; diff --git a/projects/mtg/src/DeckMenuItem.cpp b/projects/mtg/src/DeckMenuItem.cpp index e4c5907bd..15a79c371 100644 --- a/projects/mtg/src/DeckMenuItem.cpp +++ b/projects/mtg/src/DeckMenuItem.cpp @@ -1,4 +1,4 @@ - #include "PrecompiledHeader.h" +#include "PrecompiledHeader.h" #include "DeckMenuItem.h" #include "Translate.h" @@ -11,19 +11,22 @@ const int kHorizontalScrollSpeed = 30; // higher numbers mean faster scrolling -float DeckMenuItem::mYOffset = 0; - -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) +DeckMenuItem::DeckMenuItem(DeckMenu* _parent, int id, int iFontId, string text, float x, float y, bool hasFocus, bool autoTranslate, DeckMetaData *deckMetaData): SimpleMenuItem(id) { + mEngine = JGE::GetInstance(); + parent = _parent; + fontId = iFontId; + mY = y; + mX = x; WFont * mFont = WResourceManager::Instance()->GetWFont(fontId); meta = deckMetaData; mText = trim(text); - mIsValidSelection = false; + SimpleMenuItem::mIsValidSelection = false; if (autoTranslate) mText = _(mText); + mXOffset = kItemXOffset; mHasFocus = hasFocus; float newImageWidth = 0.0f; @@ -89,7 +92,7 @@ void DeckMenuItem::Update(float dt) void DeckMenuItem::RenderWithOffset(float yOffset) { - mYOffset = yOffset; + SimpleMenuItem::mYOffset = yOffset; WFont * mFont = WResourceManager::Instance()->GetWFont(fontId); @@ -120,26 +123,10 @@ void DeckMenuItem::Render() 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(mY + mYOffset); - if ( (x1 >= x2) && (x1 <= (x2 + ITEM_PX_WIDTH)) && (y1 >= y2) && (y1 < (y2 + kItemYHeight))) - mIsValidSelection = true; - } -#else - mIsValidSelection = true; -#endif -} - void DeckMenuItem::Entering() { - checkUserClick(); + SimpleMenuItem::checkUserClick(); mHasFocus = true; parent->mSelectionTargetY = mY; } @@ -147,14 +134,14 @@ void DeckMenuItem::Entering() bool DeckMenuItem::Leaving(JButton key) { // check to see if the user clicked on the object, if so return true. - checkUserClick(); + SimpleMenuItem::checkUserClick(); mHasFocus = false; return true; } bool DeckMenuItem::ButtonPressed() { - return mIsValidSelection; + return SimpleMenuItem::mIsValidSelection; } void DeckMenuItem::Relocate(float x, float y) diff --git a/projects/mtg/src/SimpleMenuItem.cpp b/projects/mtg/src/SimpleMenuItem.cpp index 3500dec9f..8dee00fe5 100644 --- a/projects/mtg/src/SimpleMenuItem.cpp +++ b/projects/mtg/src/SimpleMenuItem.cpp @@ -6,6 +6,11 @@ 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) : 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; mTargetScale = 1.0f; - + + mXOffset = mX; 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(mY + mYOffset); + if ( (x1 >= x2) && (x1 <= (x2 + 200)) && (y1 >= y2) && (y1 < (y2 + 30))) + mIsValidSelection = true; + } + else + mIsValidSelection = true; +} + void SimpleMenuItem::Entering() { mHasFocus = true;