Fixed the SimpleMenu to recenter itself as its default behaviour during construction. (You can still override it to position it explicitly if needed.) This fixes the bad alignment of the menu when you'd select single player & the hermit mode was unlocked.

This commit is contained in:
wrenczes@gmail.com
2011-06-02 18:27:00 +00:00
parent 7c65191faa
commit 945c2601d0
2 changed files with 15 additions and 3 deletions

View File

@@ -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()
{

View File

@@ -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;