From 969e6ac5e676bf1f0ed68183bc8ca5ff736d0b9f Mon Sep 17 00:00:00 2001 From: "techdragon.nguyen@gmail.com" Date: Mon, 30 Jan 2012 04:23:11 +0000 Subject: [PATCH] added more buttons to deck editor to cover all the functionality. Need to remove the PSP directions from the slide-in menus --- projects/mtg/include/GameStateDeckViewer.h | 3 +- projects/mtg/include/InteractiveButton.h | 7 ++- projects/mtg/src/DeckMenu.cpp | 2 + projects/mtg/src/GameStateDeckViewer.cpp | 51 ++++++++++++++++++---- projects/mtg/src/InteractiveButton.cpp | 45 ++++++++++--------- 5 files changed, 74 insertions(+), 34 deletions(-) diff --git a/projects/mtg/include/GameStateDeckViewer.h b/projects/mtg/include/GameStateDeckViewer.h index 275d1638d..f12ba69e1 100644 --- a/projects/mtg/include/GameStateDeckViewer.h +++ b/projects/mtg/include/GameStateDeckViewer.h @@ -97,7 +97,7 @@ private: int lastTotal; int mSelected; - InteractiveButton *toggleDeckButton, *sellCardButton; + InteractiveButton *toggleDeckButton, *sellCardButton, *statsNextButton, *statsPrevButton, *menuButton, *filterButton; WGuiFilters * filterMenu; WSrcDeckViewer * source; @@ -124,6 +124,7 @@ private: void sellCard(); void setButtonState(bool state); bool userPressedButton(); + void RenderButtons(); pair cardsCoordinates[CARDS_DISPLAYED]; diff --git a/projects/mtg/include/InteractiveButton.h b/projects/mtg/include/InteractiveButton.h index 0ffbb45f5..81ccf20b0 100644 --- a/projects/mtg/include/InteractiveButton.h +++ b/projects/mtg/include/InteractiveButton.h @@ -22,6 +22,10 @@ using std::string; const int kDismissButtonId = 10000; const int kToggleDeckActionId = 10001; const int kSellCardActionId = 10002; +const int kMenuButtonId = 10003; +const int kFilterButtonId = 10004; +const int kNextStatsButtonId = 10005; +const int kPrevStatsButtonId = 10006; class InteractiveButton: public SimpleButton { @@ -34,9 +38,8 @@ public: virtual void Entering(); virtual bool ButtonPressed(); - virtual void setImage( const JQuadPtr imagePtr, float xOffset = 0, float yOffset = 0); + virtual void setImage( const JQuadPtr imagePtr ); virtual void checkUserClick(); -//virtual void Update(float dt); virtual void Render(); virtual ostream& toString(ostream& out) const; diff --git a/projects/mtg/src/DeckMenu.cpp b/projects/mtg/src/DeckMenu.cpp index 4be1bab2a..c1e9a0cb0 100644 --- a/projects/mtg/src/DeckMenu.cpp +++ b/projects/mtg/src/DeckMenu.cpp @@ -198,6 +198,7 @@ void DeckMenu::initMenuItems() } mSelectionTargetY = selectionY = sY; +#ifndef TOUCH_ENABLED //Grab a texture in VRAM. pspIconsTexture = WResourceManager::Instance()->RetrieveTexture("iconspsp.png", RETRIEVE_MANAGE); @@ -209,6 +210,7 @@ void DeckMenu::initMenuItems() pspIcons[i]->SetHotSpot(16, 16); } dismissButton->setImage(pspIcons[5]); +#endif } void DeckMenu::Render() diff --git a/projects/mtg/src/GameStateDeckViewer.cpp b/projects/mtg/src/GameStateDeckViewer.cpp index 280cd22c9..36d5bcef5 100644 --- a/projects/mtg/src/GameStateDeckViewer.cpp +++ b/projects/mtg/src/GameStateDeckViewer.cpp @@ -59,8 +59,12 @@ GameStateDeckViewer::GameStateDeckViewer(GameApp* parent) : menu = NULL; stw = NULL; - toggleDeckButton = NEW InteractiveButton(NULL, kToggleDeckActionId, Fonts::MAIN_FONT, "View Deck", 10, 10, JGE_BTN_PRI); - sellCardButton = NEW InteractiveButton(NULL, kSellCardActionId, Fonts::MAIN_FONT, "Sell Card", (SCREEN_WIDTH_F/ 2) - 100, SCREEN_HEIGHT_F - 40, JGE_BTN_SEC); + toggleDeckButton = NEW InteractiveButton(NULL, kToggleDeckActionId, Fonts::MAIN_FONT, "View Deck", 10, SCREEN_HEIGHT_F - 15, JGE_BTN_PRI); + sellCardButton = NEW InteractiveButton(NULL, kSellCardActionId, Fonts::MAIN_FONT, "Sell Card", (SCREEN_WIDTH_F/ 2) - 100, SCREEN_HEIGHT_F - 15, JGE_BTN_SEC); + statsNextButton = NEW InteractiveButton(NULL, kNextStatsButtonId, Fonts::MAIN_FONT, "Stats ->", SCREEN_WIDTH_F - 50, SCREEN_HEIGHT_F - 40, JGE_BTN_NEXT); + statsPrevButton = NEW InteractiveButton(NULL, kPrevStatsButtonId, Fonts::MAIN_FONT, "<- Stats", SCREEN_WIDTH_F - 115, SCREEN_HEIGHT_F - 40, JGE_BTN_PREV); + menuButton = NEW InteractiveButton(NULL, kMenuButtonId, Fonts::MAIN_FONT, "menu", SCREEN_WIDTH_F - 35, SCREEN_HEIGHT_F - 15, JGE_BTN_MENU); + filterButton = NEW InteractiveButton(NULL, kFilterButtonId, Fonts::MAIN_FONT, "filter", (SCREEN_WIDTH_F - 95), SCREEN_HEIGHT_F - 15, JGE_BTN_CTRL); } GameStateDeckViewer::~GameStateDeckViewer() @@ -68,6 +72,10 @@ GameStateDeckViewer::~GameStateDeckViewer() SAFE_DELETE(bgMusic); SAFE_DELETE(toggleDeckButton); SAFE_DELETE(sellCardButton); + SAFE_DELETE(statsPrevButton); + SAFE_DELETE(statsNextButton); + SAFE_DELETE(menuButton); + SAFE_DELETE(filterButton); if (myDeck) { @@ -250,7 +258,11 @@ void GameStateDeckViewer::Start() pspIcons[i] = WResourceManager::Instance()->RetrieveQuad("iconspsp.png", (float) i * 32, 0, 32, 32, buf); pspIcons[i]->SetHotSpot(16, 16); } - +#ifndef TOUCH_ENABLED + toggleDeckButton->setImage( pspIcons[6] ); + sellCardButton->setImage( pspIcons[7] ); +#endif + //init welcome menu updateDecks(); @@ -368,13 +380,32 @@ bool GameStateDeckViewer::userPressedButton() return ( (toggleDeckButton->ButtonPressed()) || (sellCardButton->ButtonPressed()) + || (statsNextButton->ButtonPressed()) + || (statsPrevButton->ButtonPressed()) + || (menuButton->ButtonPressed()) + || (filterButton->ButtonPressed()) ); } void GameStateDeckViewer::setButtonState(bool state) { toggleDeckButton->setIsSelectionValid(state); - sellCardButton->setIsSelectionValid(state); + sellCardButton->setIsSelectionValid(state); + statsNextButton->setIsSelectionValid(state); + statsPrevButton->setIsSelectionValid(state); + filterButton->setIsSelectionValid(state); + menuButton->setIsSelectionValid(state); + +} + +void GameStateDeckViewer::RenderButtons() +{ + toggleDeckButton->Render(); + sellCardButton->Render(); + menuButton->Render(); + filterButton->Render(); + statsNextButton->Render(); + statsPrevButton->Render(); } void GameStateDeckViewer::Update(float dt) @@ -840,10 +871,12 @@ void GameStateDeckViewer::renderOnScreenMenu() font->DrawString(_("View Collection"), rightPspX - 20, rightPspY - 15, JGETEXT_RIGHT); } font->DrawString(_("Sell card"), rightPspX - 30, rightPspY + 20); + //Bottom menus +#ifndef TOUCH_ENABLED font->DrawString(_("menu"), SCREEN_WIDTH - 35 + rightTransition, SCREEN_HEIGHT - 15); font->DrawString(_("filter"), SCREEN_WIDTH - 95 + rightTransition, SCREEN_HEIGHT - 15); - +#endif //Your Deck Information char buffer[300]; int nb_letters = 0; @@ -897,9 +930,10 @@ void GameStateDeckViewer::renderOnScreenMenu() r->FillRect(SCREEN_WIDTH / 2 + rightTransition, 0, SCREEN_WIDTH / 2, SCREEN_HEIGHT, ARGB(128,0,0,0)); r->FillRect(10 + leftTransition, 10, SCREEN_WIDTH / 2 - 10, SCREEN_HEIGHT - 20, ARGB(128,0,0,0)); r->FillRect(SCREEN_WIDTH / 2 + rightTransition, 10, SCREEN_WIDTH / 2 - 10, SCREEN_HEIGHT - 20, ARGB(128,0,0,0)); +#ifndef TOUCH_ENABLED font->DrawString(_("menu"), SCREEN_WIDTH - 35 + rightTransition, SCREEN_HEIGHT - 15); font->DrawString(_("filter"), SCREEN_WIDTH - 95 + rightTransition, SCREEN_HEIGHT - 15); - +#endif int nb_letters = 0; float posX, posY; DWORD graphColor; @@ -1496,6 +1530,7 @@ void GameStateDeckViewer::Render() if (displayed_deck->Size() > 0) { + setButtonState(true); renderSlideBar(); } else @@ -1508,6 +1543,7 @@ void GameStateDeckViewer::Render() } else if (mStage == STAGE_WELCOME) { + setButtonState(false); welcome_menu->Render(); } else @@ -1532,8 +1568,7 @@ void GameStateDeckViewer::Render() if (options.keypadActive()) options.keypadRender(); - toggleDeckButton->Render(); - sellCardButton->Render(); + RenderButtons(); } int GameStateDeckViewer::loadDeck(int deckid) diff --git a/projects/mtg/src/InteractiveButton.cpp b/projects/mtg/src/InteractiveButton.cpp index 5f3213a15..dcbdd9960 100644 --- a/projects/mtg/src/InteractiveButton.cpp +++ b/projects/mtg/src/InteractiveButton.cpp @@ -15,7 +15,7 @@ #include "WResourceManager.h" #include "WFont.h" -const int kButtonHeight = 60; +const int kButtonHeight = 30; InteractiveButton::InteractiveButton(JGuiController* _parent, int id, int fontId, string text, float x, float y, JButton actionKey, bool hasFocus, bool autoTranslate) : SimpleButton( _parent, id, fontId, text, x, y, hasFocus, autoTranslate) @@ -66,40 +66,39 @@ void InteractiveButton::Render() WFont *mainFont = WResourceManager::Instance()->GetWFont(Fonts::MAIN_FONT); const string detailedInfoString = _(getText()); float stringWidth = mainFont->GetStringWidth(detailedInfoString.c_str()); + float pspIconsSize = 0.5; + float mainFontHeight = mainFont->GetHeight(); + float boxStartX = 0; #ifndef TOUCH_ENABLED mXOffset = -5; mYOffset = 10; - float boxStartX = getX() - 5; - float pspIconsSize = 0.5; - if (buttonImage != NULL) - { - renderer->FillRoundRect( boxStartX, getY() - 5, stringWidth, mainFont->GetHeight() + 15, .5, ARGB(255, 0, 0, 0) ); - renderer->RenderQuad(buttonImage.get(), boxStartX + (stringWidth/2), getY() + 2, 0, pspIconsSize, pspIconsSize); - } - else - { - mYOffset = -3; - mXOffset = 0; - renderer->FillRoundRect( boxStartX, getY() - 5, stringWidth , mainFont->GetHeight(), .5, ARGB(255, 192, 172, 119)); - renderer->DrawRoundRect( boxStartX, getY() - 5, stringWidth + 6, mainFont->GetHeight(), .75, ARGB(255,255,255,255)); - } + boxStartX = getX() - 5; + renderer->FillRoundRect( boxStartX, getY() - 5, stringWidth, mainFontHeight + 15, .5, ARGB( 255, 0, 0, 0) ); #else mXOffset = 0; mYOffset = 0; - renderer->FillRoundRect(getX() - 5, getY(), stringWidth - 3, mainFont->GetHeight() - 9, 5, ARGB(255, 192, 172, 119)); - renderer->DrawRoundRect(getX() - 5, getY(), stringWidth - 3, mainFont->GetHeight() - 9, 5, ARGB(255,255,255,255)); + boxStartX = getX() - 5; + renderer->FillRoundRect(boxStartX, getY(), stringWidth - 3, mainFont->GetHeight() - 9, 5, ARGB(255, 192, 172, 119)); + renderer->DrawRoundRect(boxStartX, getY(), stringWidth - 3, mainFont->GetHeight() - 9, 5, ARGB(255, 255, 255, 255)); #endif - mainFont->SetColor( ARGB(255, 200, 200, 200) ); - mainFont->DrawString(detailedInfoString, getX() - mXOffset, getY() + mYOffset); - + float buttonXOffset = getX() - mXOffset; + float buttonYOffset = getY() + mYOffset; + if (buttonImage != NULL) + { + renderer->RenderQuad(buttonImage.get(), buttonXOffset - buttonImage.get()->mWidth/2, buttonYOffset + mainFontHeight/2, 0, pspIconsSize, pspIconsSize); + } + mainFont->SetColor(ARGB(255, 200, 200, 200)); + mainFont->DrawString(detailedInfoString, buttonXOffset, buttonYOffset); } -void InteractiveButton::setImage( const JQuadPtr imagePtr, float xOffset, float yOffset) +void InteractiveButton::setImage( const JQuadPtr imagePtr ) { buttonImage = imagePtr; - mXOffset = xOffset; - mYOffset = yOffset; + float imageXOffset = getX() - buttonImage.get()->mWidth; + + if (imageXOffset < 0) + setX( getX() - imageXOffset/2 + 5 ); } /* Accessors */