diff --git a/projects/mtg/include/SimpleMenu.h b/projects/mtg/include/SimpleMenu.h index 540cf08fd..2bca69d7b 100644 --- a/projects/mtg/include/SimpleMenu.h +++ b/projects/mtg/include/SimpleMenu.h @@ -23,6 +23,9 @@ private: float timeOpen; bool mClosed; + bool mCenterHorizontal; + bool mCenterVertical; + static JQuadPtr spadeR, spadeL, jewel, side; static JTexture *spadeRTex, *spadeLTex, *jewelTex, *sideTex; static WFont* titleFont; @@ -34,13 +37,15 @@ private: public: bool autoTranslate; - SimpleMenu(int id, JGuiListener* listener, int fontId, float x, float y, const char * _title = "", int _maxItems = 7); + SimpleMenu(int id, JGuiListener* listener, int fontId, float x, float y, const char * _title = "", int _maxItems = 7, bool centerHorizontal = true, bool centerVertical = true); virtual ~SimpleMenu(); void Render(); void Update(float dt); void Add(int id, const char * Text, string desc = "", bool forceFocus = false); void Close(); + void RecenterMenu(); + float selectionTargetY; bool isClosed() { diff --git a/projects/mtg/src/SimpleMenu.cpp b/projects/mtg/src/SimpleMenu.cpp index 84f5d888f..efebfe375 100644 --- a/projects/mtg/src/SimpleMenu.cpp +++ b/projects/mtg/src/SimpleMenu.cpp @@ -30,8 +30,8 @@ JTexture* SimpleMenu::sideTex = NULL; WFont* SimpleMenu::titleFont = NULL; hgeParticleSystem* SimpleMenu::stars = NULL; -SimpleMenu::SimpleMenu(int id, JGuiListener* listener, int fontId, float x, float y, const char * _title, int _maxItems) : - JGuiController(id, listener), fontId(fontId) +SimpleMenu::SimpleMenu(int id, JGuiListener* listener, int fontId, float x, float y, const char * _title, int _maxItems, bool centerHorizontal, bool centerVertical) + : JGuiController(id, listener), fontId(fontId), mCenterHorizontal(centerHorizontal), mCenterVertical(centerVertical) { autoTranslate = true; mHeight = 2 * kVerticalMargin; @@ -137,6 +137,13 @@ void SimpleMenu::Render() if ((!title.empty()) && (mWidth < titleFont->GetStringWidth(title.c_str()))) mWidth = titleFont->GetStringWidth(title.c_str()); mWidth += 2 * kHorizontalMargin; + + if (mCenterHorizontal) + mX = (JRenderer::GetInstance()->GetActualWidth() - mWidth) / 2; + + if (mCenterVertical) + mY = (JRenderer::GetInstance()->GetActualHeight() - mHeight) / 2; + for (int i = 0; i < mCount; ++i) { float y = mY + kVerticalMargin + i * kLineHeight;