Added first draft of an interactive button. Needs to handle addition of images a little better

refined detailed info window for stats display
removed PSP button for Touch interfaces (currently only iOS and Android) on deck selection screens
to not break the core engine and reduce some more complex code, I created a new vector in the JController object. mButtons.  This vector will contain all the valid buttons for a given screen.  The appropriate Add/Remove methods have been updated to account for this new vector.
This commit is contained in:
techdragon.nguyen@gmail.com
2012-01-25 18:35:24 +00:00
parent 59fad775c8
commit a36d886dd5
16 changed files with 523 additions and 232 deletions

View File

@@ -1,4 +1,4 @@
OBJS = objs/AbilityParser.o objs/ActionElement.o objs/ActionLayer.o objs/ActionStack.o objs/AIHints.o objs/AIMomirPlayer.o objs/AIPlayer.o objs/AIPlayerBaka.o objs/AIStats.o objs/AllAbilities.o objs/CardGui.o objs/CardDescriptor.o objs/CardDisplay.o objs/CardEffect.o objs/CardPrimitive.o objs/CardSelector.o objs/CardSelectorSingleton.o objs/Counters.o objs/Credits.o objs/Damage.o objs/DamagerDamaged.o objs/DeckDataWrapper.o objs/DeckEditorMenu.o objs/DeckMenu.o objs/DeckMenuItem.o objs/DeckMetaData.o objs/DeckStats.o objs/DuelLayers.o objs/Effects.o objs/ExtraCost.o objs/GameApp.o objs/GameLauncher.o objs/GameObserver.o objs/GameOptions.o objs/GameState.o objs/GameStateAwards.o objs/GameStateDeckViewer.o objs/GameStateDuel.o objs/DeckManager.o objs/GameStateMenu.o objs/GameStateOptions.o objs/GameStateShop.o objs/GameStateStory.o objs/GameStateTransitions.o objs/GuiAvatars.o objs/GuiBackground.o objs/GuiCardsController.o objs/GuiCombat.o objs/GuiFrame.o objs/GuiHand.o objs/GuiLayers.o objs/GuiMana.o objs/GuiPhaseBar.o objs/GuiPlay.o objs/GuiStatic.o objs/IconButton.o objs/ManaCost.o objs/ManaCostHybrid.o objs/MenuItem.o objs/ModRules.o objs/MTGAbility.o objs/MTGCardInstance.o objs/MTGCard.o objs/MTGDeck.o objs/MTGDefinitions.o objs/MTGGamePhase.o objs/MTGGameZones.o objs/MTGPack.o objs/MTGRules.o objs/Navigator.o objs/ObjectAnalytics.o objs/OptionItem.o objs/PhaseRing.o objs/Player.o objs/PlayerData.o objs/PlayGuiObjectController.o objs/PlayGuiObject.o objs/PlayRestrictions.o objs/Pos.o objs/PrecompiledHeader.o objs/PriceList.o objs/ReplacementEffects.o objs/Rules.o objs/SimpleMenu.o objs/SimpleMenuItem.o objs/SimplePad.o objs/SimplePopup.o objs/StoryFlow.o objs/StyleManager.o objs/Subtypes.o objs/TargetChooser.o objs/TargetsList.o objs/TextScroller.o objs/ThisDescriptor.o objs/Token.o objs/Translate.o objs/TranslateKeys.o objs/Trash.o objs/utils.o objs/WEvent.o objs/WResourceManager.o objs/WCachedResource.o objs/WDataSrc.o objs/WGui.o objs/WFilter.o objs/Tasks.o objs/WFont.o
OBJS = objs/AbilityParser.o objs/ActionElement.o objs/ActionLayer.o objs/ActionStack.o objs/AIHints.o objs/AIMomirPlayer.o objs/AIPlayer.o objs/AIPlayerBaka.o objs/AIStats.o objs/AllAbilities.o objs/CardGui.o objs/CardDescriptor.o objs/CardDisplay.o objs/CardEffect.o objs/CardPrimitive.o objs/CardSelector.o objs/CardSelectorSingleton.o objs/Counters.o objs/Credits.o objs/Damage.o objs/DamagerDamaged.o objs/DeckDataWrapper.o objs/DeckEditorMenu.o objs/DeckMenu.o objs/DeckMenuItem.o objs/DeckMetaData.o objs/DeckStats.o objs/DuelLayers.o objs/Effects.o objs/ExtraCost.o objs/GameApp.o objs/GameLauncher.o objs/GameObserver.o objs/GameOptions.o objs/GameState.o objs/GameStateAwards.o objs/GameStateDeckViewer.o objs/GameStateDuel.o objs/DeckManager.o objs/GameStateMenu.o objs/GameStateOptions.o objs/GameStateShop.o objs/GameStateStory.o objs/GameStateTransitions.o objs/GuiAvatars.o objs/GuiBackground.o objs/GuiCardsController.o objs/GuiCombat.o objs/GuiFrame.o objs/GuiHand.o objs/GuiLayers.o objs/GuiMana.o objs/GuiPhaseBar.o objs/GuiPlay.o objs/GuiStatic.o objs/IconButton.o objs/ManaCost.o objs/ManaCostHybrid.o objs/MenuItem.o objs/ModRules.o objs/MTGAbility.o objs/MTGCardInstance.o objs/MTGCard.o objs/MTGDeck.o objs/MTGDefinitions.o objs/MTGGamePhase.o objs/MTGGameZones.o objs/MTGPack.o objs/MTGRules.o objs/Navigator.o objs/ObjectAnalytics.o objs/OptionItem.o objs/PhaseRing.o objs/Player.o objs/PlayerData.o objs/PlayGuiObjectController.o objs/PlayGuiObject.o objs/PlayRestrictions.o objs/Pos.o objs/PrecompiledHeader.o objs/PriceList.o objs/ReplacementEffects.o objs/Rules.o objs/SimpleMenu.o objs/SimpleButton.o objs/SimpleMenuItem.o objs/SimplePad.o objs/SimplePopup.o objs/StoryFlow.o objs/StyleManager.o objs/Subtypes.o objs/TargetChooser.o objs/TargetsList.o objs/TextScroller.o objs/ThisDescriptor.o objs/Token.o objs/Translate.o objs/TranslateKeys.o objs/Trash.o objs/utils.o objs/WEvent.o objs/WResourceManager.o objs/WCachedResource.o objs/WDataSrc.o objs/WGui.o objs/WFilter.o objs/Tasks.o objs/WFont.o
DEPS = $(patsubst objs/%.o, deps/%.d, $(OBJS))
RESULT = $(shell psp-config --psp-prefix 2> Makefile.cache)

View File

@@ -9,9 +9,13 @@
#include "hge/hgeparticle.h"
#include "DeckMetaData.h"
#include "TextScroller.h"
#include "InteractiveButton.h"
class DeckMenu: public JGuiController
{
private:
InteractiveButton *dismissButton;
protected:
float mHeight, mWidth, mX, mY;
@@ -62,14 +66,14 @@ public:
DeckMetaData * getSelectedDeck();
void enableDisplayDetailsOverride();
bool showDetailsScreen();
virtual bool isClosed() const { return mClosed; }
virtual int getSelectedDeckId() const { return mSelectedDeckId; }
bool isClosed() const { return mClosed; }
int getSelectedDeckId() const { return mSelectedDeckId; }
void Render();
void Update(float dt);
void Add(int id, const char * Text, string desc = "", bool forceFocus = false, DeckMetaData *deckMetaData = NULL);
void Close();
virtual void Render();
virtual void Update(float dt);
virtual void Add(int id, const char * Text, string desc = "", bool forceFocus = false, DeckMetaData *deckMetaData = NULL);
virtual void Close();
void updateScroller();
void RenderBackground();
void RenderDeckManaColors();

View File

@@ -15,7 +15,7 @@ private:
bool mScrollEnabled;
bool mDisplayInitialized;
DeckMenu* parent;
DeckMenu* deckController;
float mTitleResetWidth;
protected:
@@ -43,6 +43,7 @@ public:
virtual bool Leaving(JButton key);
virtual bool ButtonPressed();
virtual ostream& toString(ostream& out) const;
virtual JGuiController* getParent() const;
virtual void RenderWithOffset(float yOffset);
};

View File

@@ -0,0 +1,41 @@
//
// InteractiveButton.h
//
// Created by Michael Nguyen on 1/23/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#ifndef wagic_InteractiveButton_h
#define wagic_InteractiveButton_h
#include <string>
#include <JLBFont.h>
#include <JGui.h>
#include "WResource_Fwd.h"
#include "SimpleButton.h"
using std::string;
#define SCALE_SELECTED 1.2f
#define SCALE_NORMAL 1.0f
class InteractiveButton: public SimpleButton
{
private:
JQuadPtr buttonImage;
JButton mActionKey;
public:
InteractiveButton(JGuiController* _parent, int id, int fontId, string text, float x, float y, JButton actionKey, bool hasFocus = false, bool autoTranslate = false);
virtual void Entering();
virtual bool ButtonPressed();
virtual void setImage( const JQuadPtr imagePtr, float xOffset = 0, float yOffset = 0);
virtual void checkUserClick();
//virtual void Update(float dt);
virtual void Render();
virtual ostream& toString(ostream& out) const;
};
#endif

View File

@@ -23,4 +23,8 @@
#include <boost/shared_ptr.hpp>
#if defined (IOS) || defined (ANDROID)
#define TOUCH_ENABLED
#endif
#endif //PRECOMPILEDHEADER_H

View File

@@ -0,0 +1,84 @@
//
// SimpleButton.h
// - base class for creating buttons/links inside of the game engine.
//
// Created by Michael Nguyen on 1/21/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#ifndef wagic_SimpleButton_h
#define wagic_SimpleButton_h
#include <string>
#include <JLBFont.h>
#include <JGui.h>
using std::string;
#define SCALE_SELECTED 1.2f
#define SCALE_NORMAL 1.0f
class SimpleButton: public JGuiObject
{
private:
float mScale;
float mTargetScale;
bool mHasFocus;
bool mIsValidSelection;
float mX;
float mY;
protected:
float mYOffset;
JGuiController* parent;
int mFontId;
string mText;
float mXOffset;
public:
SimpleButton(int id);
SimpleButton(JGuiController* _parent, int id, int fontId, string text, float x, float y, bool hasFocus = false, bool autoTranslate = false);
virtual float getScale() const;
virtual float getTargetScale() const;
virtual JGuiController* getParent() const;
virtual int getFontId() const;
virtual void setFontId( const int& fontId );
virtual void setX( const float& x ) { mX = x; };
virtual void setY( const float& y ) { mY = y; };
virtual void setIsSelectionValid( bool validSelection );
virtual void setFocus(bool value);
virtual void setText( const string& text);
virtual bool isSelectionValid() const;
virtual bool hasFocus() const;
virtual string getText() const;
float getX() const;
float getY() const;
virtual void checkUserClick();
virtual float GetWidth();
virtual void Relocate(float x, float y);
virtual void RenderWithOffset(float yOffset);
virtual void Render();
virtual void Update(float dt);
virtual void Entering();
virtual bool Leaving(JButton key);
virtual bool ButtonPressed();
virtual ostream& toString(ostream& out) const;
virtual bool getTopLeft(float& top, float& left)
{
top = mY + mYOffset;
left = mX;
return true;
}
;
};
#endif

View File

@@ -39,17 +39,17 @@ public:
bool isMultipleChoice;
SimpleMenu(JGE*, 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);
virtual void Render();
virtual void Update(float dt);
virtual void Add(int id, const char * Text, string desc = "", bool forceFocus = false);
int getmCurr(){return mCurr;}
float getWidth(){return mWidth; }
void Close();
virtual void Close();
void RecenterMenu();
float selectionTargetY;
bool isClosed()
virtual bool isClosed() const
{
return mClosed;
}

View File

@@ -4,6 +4,7 @@
#include <string>
#include <JLBFont.h>
#include <JGui.h>
#include "SimpleButton.h"
#include "SimpleMenu.h"
using std::string;
@@ -11,65 +12,20 @@ using std::string;
#define SCALE_SELECTED 1.2f
#define SCALE_NORMAL 1.0f
class SimpleMenuItem: public JGuiObject
class SimpleMenuItem: public SimpleButton
{
private:
SimpleMenu* parent;
float mScale;
float mTargetScale;
bool mHasFocus;
bool mIsValidSelection;
float mX;
float mY;
protected:
int mFontId;
string mText;
static float mYOffset;
float mXOffset;
string mDescription;
public:
SimpleMenuItem(int id);
SimpleMenuItem(SimpleMenu* _parent, int id, int fontId, string text, float x, float y, bool hasFocus = false, bool autoTranslate = false);
virtual int getFontId() const;
virtual void setFontId( const int& fontId );
virtual void setX( const float& x ) { mX = x; };
virtual void setY( const float& y ) { mY = y; };
virtual void setIsSelectionValid( bool validSelection );
virtual void setFocus(bool value);
virtual void setDescription( const string& desc );
virtual void setText( const string& text);
virtual bool isSelectionValid() const;
virtual bool hasFocus() const;
virtual string getDescription() const;
virtual string getText() const;
float getX() const;
float getY() const;
virtual void checkUserClick();
virtual float GetWidth() const;
virtual void Relocate(float x, float y);
virtual void RenderWithOffset(float yOffset);
virtual void Render();
virtual void Update(float dt);
virtual void Entering();
virtual bool Leaving(JButton key);
virtual bool ButtonPressed();
virtual void setDescription( const string& desc );
virtual string getDescription() const;
virtual ostream& toString(ostream& out) const;
virtual bool getTopLeft(float& top, float& left)
{
top = mY + mYOffset;
left = mX;
return true;
}
;
};
#endif

View File

@@ -35,7 +35,7 @@ private:
public:
bool autoTranslate;
SimplePopup(int id, JGuiListener* listener, const int fontId, const char * _title = "", DeckMetaData* deckInfo = NULL, MTGAllCards * collection = NULL);
SimplePopup(int id, JGuiListener* listener, const int fontId, const char * _title = "", DeckMetaData* deckInfo = NULL, MTGAllCards * collection = NULL, int x = 364, int y = 235);
~SimplePopup(void);
void drawBoundingBox(float x, float y, float width, float height);
bool isClosed()

View File

@@ -3,12 +3,12 @@
#include "DeckMenu.h"
#include "DeckMenuItem.h"
#include "DeckMetaData.h"
#include "InteractiveButton.h"
#include "JTypes.h"
#include "GameApp.h"
#include "Translate.h"
#include "TextScroller.h"
#include "Tasks.h"
#include "IconButton.h"
#include <iomanip>
@@ -100,6 +100,13 @@ JGuiController(JGE::GetInstance(), id, listener), fontId(fontId), mShowDetailsSc
if (NULL == stars)
stars = NEW hgeParticleSystem(WResourceManager::Instance()->RetrievePSI("stars.psi", WResourceManager::Instance()->GetQuad("stars").get()));
stars->FireAt(mX, mY);
const string detailedInfoString = _("Detailed Info");
float stringWidth = mFont->GetStringWidth(detailedInfoString.c_str());
float boxStartX = detailedInfoBoxX - stringWidth / 2 + 20;
dismissButton = NEW InteractiveButton( this, kDetailedInfoButtonId, Fonts::MAIN_FONT, detailedInfoString, boxStartX, detailedInfoBoxY, JGE_BTN_CANCEL);
JGuiController::Add(dismissButton, true);
updateScroller();
}
@@ -201,7 +208,7 @@ void DeckMenu::initMenuItems()
pspIcons[i] = WResourceManager::Instance()->RetrieveQuad("iconspsp.png", (float) i * 32, 0, 32, 32, buf);
pspIcons[i]->SetHotSpot(16, 16);
}
dismissButton->setImage(pspIcons[5]);
}
void DeckMenu::Render()
@@ -216,14 +223,12 @@ void DeckMenu::Render()
timeOpen = 0;
menuInitialized = true;
}
if (timeOpen < 1) height *= timeOpen > 0 ? timeOpen : -timeOpen;
for (int i = startId; i < startId + maxItems; i++)
{
if (i > mCount - 1) break;
if (mObjects[i]->GetId() >= kDetailedInfoButtonId)
break; // objects with id > 9999 are clickable buttons
if (i > mCount - 1) break;
DeckMenuItem *currentMenuItem = static_cast<DeckMenuItem*> (mObjects[i]);
if (currentMenuItem->getY() - kLineHeight * startId < mY + height - kLineHeight + 7)
{
@@ -242,17 +247,13 @@ void DeckMenu::Render()
// display the "more info" button if special condition is met
if (showDetailsScreen())
{
float pspIconsSize = 0.5;
const string detailedInfoString = _("Detailed Info");
float stringWidth = mainFont->GetStringWidth(detailedInfoString.c_str());
float boxStartX = detailedInfoBoxX - stringWidth / 2;
DWORD currentColor = mainFont->GetColor();
renderer->FillRoundRect( boxStartX, detailedInfoBoxY - 5, stringWidth, mainFont->GetHeight() + 15, .5, ARGB( 255, 0, 0, 0) );
renderer->RenderQuad(pspIcons[5].get(), detailedInfoBoxX, detailedInfoBoxY + 2, 0, pspIconsSize, pspIconsSize);
mainFont->SetColor(currentColor);
mainFont->DrawString(detailedInfoString, boxStartX, detailedInfoBoxY + 10);
dismissButton->setIsSelectionValid(true);
dismissButton->Render();
}
else
{
dismissButton->setIsSelectionValid(false);
}
// display the avatar image
if (currentMenuItem->imageFilename.size() > 0)
{
@@ -318,9 +319,12 @@ void DeckMenu::Render()
void DeckMenu::Update(float dt)
{
JGuiController::Update(dt);
if (mCurr > startId + maxItems - 1)
startId = mCurr - maxItems + 1;
else if (mCurr < startId) startId = mCurr;
else if (mCurr < startId)
startId = mCurr;
stars->Update(dt);
selectionT += 3 * dt;
selectionY += (mSelectionTargetY - selectionY) * 8 * dt;
@@ -345,6 +349,7 @@ void DeckMenu::Update(float dt)
}
if (mScroller)
mScroller->Update(dt);
}
void DeckMenu::Add(int id, const char * text, string desc, bool forceFocus, DeckMetaData * deckMetaData)
@@ -405,4 +410,5 @@ DeckMenu::~DeckMenu()
{
WResourceManager::Instance()->Release(pspIconsTexture);
SAFE_DELETE(mScroller);
dismissButton = NULL;
}

View File

@@ -14,7 +14,7 @@ const int kHorizontalScrollSpeed = 30; // higher numbers mean faster scrolling
DeckMenuItem::DeckMenuItem(DeckMenu* _parent, int id, int fontId, string text, float x, float y, bool hasFocus, bool autoTranslate, DeckMetaData *deckMetaData): SimpleMenuItem(NULL, id, fontId, text, x, y, hasFocus, autoTranslate)
{
mEngine = JGE::GetInstance();
parent = _parent;
deckController = _parent;
WFont * mFont = WResourceManager::Instance()->GetWFont(fontId);
meta = deckMetaData;
@@ -129,7 +129,7 @@ void DeckMenuItem::Entering()
{
checkUserClick();
setFocus(true);
parent->mSelectionTargetY = getY();
deckController->mSelectionTargetY = getY();
}
@@ -168,11 +168,17 @@ float DeckMenuItem::GetWidth()
ostream& DeckMenuItem::toString(ostream& out) const
{
return out << "DeckMenuItem ::: mHasFocus : " << hasFocus()
<< " ; parent : " << parent
<< " ; parent : " << deckController
<< " ; mText : " << getText()
<< " ; mX,mY : " << getX() << "," << getY();
}
JGuiController* DeckMenuItem::getParent() const
{
return deckController;
}
DeckMenuItem::~DeckMenuItem()
{
meta = NULL;

View File

@@ -0,0 +1,105 @@
//
// InteractiveButton.cpp
// wagic
//
// Created by Michael Nguyen on 1/23/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#include <iostream>
#include "PrecompiledHeader.h"
#include "InteractiveButton.h"
#include "Translate.h"
#include "JTypes.h"
#include "WResourceManager.h"
#include "WFont.h"
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)
{
setIsSelectionValid(false); // by default it's turned off since you can't auto select it.
mActionKey = actionKey;
}
void InteractiveButton::Entering()
{
}
void InteractiveButton::checkUserClick()
{
int x1 = -1, y1 = -1;
if (mEngine->GetLeftClickCoordinates(x1, y1))
{
setIsSelectionValid(false);
int buttonImageWidth = static_cast<int>(GetWidth());
int x2 = static_cast<int>(getX()), y2 = static_cast<int>(getY() + mYOffset);
int buttonHeight = 50;
if ( (x1 >= x2) && (x1 <= (x2 + buttonImageWidth)) && (y1 >= y2) && (y1 < (y2 + buttonHeight)))
setIsSelectionValid( true );
}
else
setIsSelectionValid( false );
}
bool InteractiveButton::ButtonPressed()
{
checkUserClick();
if (isSelectionValid())
{
mEngine->ReadButton();
mEngine->LeftClickedProcessed();
mEngine->HoldKey_NoRepeat( mActionKey );
setIsSelectionValid(false);
return true;
}
return false;
}
void InteractiveButton::Render()
{
if (!isSelectionValid()) return;
JRenderer *renderer = JRenderer::GetInstance();
WFont *mainFont = WResourceManager::Instance()->GetWFont(Fonts::MAIN_FONT);
const string detailedInfoString = _(getText());
float stringWidth = mainFont->GetStringWidth(detailedInfoString.c_str());
DWORD currentColor = mainFont->GetColor();
#ifndef TOUCH_ENABLED
mXOffset = stringWidth / 2;
mYOffset = 10;
float boxStartX = getX() - mXOffset;
float pspIconsSize = 0.5;
renderer->FillRoundRect( boxStartX, getY() - 5, stringWidth, mainFont->GetHeight() + 15, .5, ARGB( 255, 0, 0, 0) );
if (buttonImage != NULL)
renderer->RenderQuad(buttonImage.get(), getX(), getY() + 2, 0, pspIconsSize, pspIconsSize);
#else
mXOffset = 0;
mYOffset = 0;
renderer->FillRoundRect(getX() - 5, getY(), stringWidth + 6, mainFont->GetHeight(), .5, ARGB(255, 192, 172, 119));
renderer->DrawRoundRect(getX() - 5, getY(), stringWidth + 6, mainFont->GetHeight(), .75, ARGB(255,255,255,255));
#endif
mainFont->SetColor(currentColor);
mainFont->DrawString(detailedInfoString, getX() - mXOffset, getY() + mYOffset);
}
void InteractiveButton::setImage( const JQuadPtr imagePtr, float xOffset, float yOffset)
{
buttonImage = imagePtr;
mXOffset = xOffset;
mYOffset = yOffset;
}
/* Accessors */
ostream& InteractiveButton::toString(ostream& out) const
{
return out << "InteractiveButton ::: mHasFocus : " << hasFocus()
<< " ; parent : " << getParent()
<< " ; mText : " << getText()
<< " ; mScale : " << getScale()
<< " ; mTargetScale : " << getTargetScale()
<< " ; mX,mY : " << getX() << "," << getY();
}

View File

@@ -0,0 +1,188 @@
//
// SimpleButton.cpp
// wagic
//
// Created by Michael Nguyen on 1/23/12.
// Copyright (c) 2012 Wagic the Homebrew. All rights reserved.
//
#include "PrecompiledHeader.h"
#include "SimpleButton.h"
#include "Translate.h"
#include "WFont.h"
#include "WResourceManager.h"
SimpleButton::SimpleButton(int id): JGuiObject(id)
{
mIsValidSelection = false;
}
SimpleButton::SimpleButton(JGuiController* _parent, int id, int fontId, string text, float x, float y, bool hasFocus, bool autoTranslate) :
JGuiObject(id), parent(_parent), mX(x), mY(y), mFontId(fontId)
{
mYOffset = 0;
if (autoTranslate)
mText = _(text);
else
mText = text;
mHasFocus = hasFocus;
mScale = 1.0f;
mTargetScale = 1.0f;
mXOffset = mX;
if (hasFocus)
{
setIsSelectionValid(true);
Entering();
}
else
{
setIsSelectionValid(false);
}
}
void SimpleButton::RenderWithOffset(float yOffset)
{
mYOffset = yOffset;
WFont * mFont = WResourceManager::Instance()->GetWFont(mFontId);
mFont->DrawString(mText.c_str(), mX, mY + yOffset, JGETEXT_CENTER);
}
void SimpleButton::Render()
{
RenderWithOffset(0);
}
void SimpleButton::Update(float dt)
{
if (mScale < mTargetScale)
{
mScale += 8.0f * dt;
if (mScale > mTargetScale) mScale = mTargetScale;
}
else if (mScale > mTargetScale)
{
mScale -= 8.0f * dt;
if (mScale < mTargetScale) mScale = mTargetScale;
}
}
void SimpleButton::checkUserClick()
{
setIsSelectionValid(true);
}
void SimpleButton::Entering()
{
checkUserClick();
mHasFocus = true;
}
bool SimpleButton::Leaving(JButton key)
{
checkUserClick();
mHasFocus = false;
return true;
}
bool SimpleButton::ButtonPressed()
{
return mIsValidSelection;
}
void SimpleButton::Relocate(float x, float y)
{
mXOffset = 0;
mX = x;
mY = y;
}
/* Accessors */
JGuiController* SimpleButton::getParent() const
{
return parent;
}
float SimpleButton::getScale() const
{
return mScale;
}
float SimpleButton::getTargetScale() const
{
return mTargetScale;
}
float SimpleButton::getX() const
{
return mX;
}
float SimpleButton::getY() const
{
return mY;
}
void SimpleButton::setFontId(const int &fontId)
{
mFontId = fontId;
}
int SimpleButton::getFontId() const
{
return mFontId;
}
void SimpleButton::setIsSelectionValid( bool validSelection )
{
mIsValidSelection = validSelection;
}
bool SimpleButton::isSelectionValid() const
{
return mIsValidSelection;
}
void SimpleButton::setFocus(bool value)
{
mHasFocus = value;
}
bool SimpleButton::hasFocus() const
{
return mHasFocus;
}
string SimpleButton::getText() const
{
return mText;
}
void SimpleButton::setText( const string& text)
{
mText = text;
}
float SimpleButton::GetWidth()
{
WFont * mFont = WResourceManager::Instance()->GetWFont(mFontId);
mFont->SetScale(1.0);
return mFont->GetStringWidth(mText.c_str());
}
ostream& SimpleButton::toString(ostream& out) const
{
return out << "SimpleButton ::: mHasFocus : " << hasFocus()
<< " ; parent : " << getParent()
<< " ; mText : " << getText()
<< " ; mScale : " << getScale()
<< " ; mTargetScale : " << getTargetScale()
<< " ; mX,mY : " << getX() << "," << getY();
}

View File

@@ -4,142 +4,32 @@
#include "Translate.h"
#include "WResourceManager.h"
float SimpleMenuItem::mYOffset = 0;
SimpleMenuItem::SimpleMenuItem(int id): JGuiObject(id)
SimpleMenuItem::SimpleMenuItem(int id): SimpleButton(id)
{
mIsValidSelection = false;
}
SimpleMenuItem::SimpleMenuItem(SimpleMenu* _parent, int id, int fontId, string text, float x, float y, bool hasFocus, bool autoTranslate) :
JGuiObject(id), parent(_parent), mX(x), mY(y), mFontId(fontId)
SimpleButton( _parent, id, fontId, text, x, y, hasFocus, autoTranslate)
{
if (autoTranslate)
mText = _(text);
else
mText = text;
parent = (SimpleMenu *) _parent;
mDescription = "";
mHasFocus = hasFocus;
mScale = 1.0f;
mTargetScale = 1.0f;
mXOffset = mX;
if (hasFocus)
{
setIsSelectionValid(true);
Entering();
}
else
{
setIsSelectionValid(false);
}
}
void SimpleMenuItem::RenderWithOffset(float yOffset)
{
mYOffset = yOffset;
WFont * mFont = WResourceManager::Instance()->GetWFont(mFontId);
mFont->DrawString(mText.c_str(), mX, mY + yOffset, JGETEXT_CENTER);
}
void SimpleMenuItem::Render()
{
RenderWithOffset(0);
}
void SimpleMenuItem::Update(float dt)
{
if (mScale < mTargetScale)
{
mScale += 8.0f * dt;
if (mScale > mTargetScale) mScale = mTargetScale;
}
else if (mScale > mTargetScale)
{
mScale -= 8.0f * dt;
if (mScale < mTargetScale) mScale = mTargetScale;
}
}
void SimpleMenuItem::checkUserClick()
{
setIsSelectionValid(true);
}
void SimpleMenuItem::Entering()
{
checkUserClick();
mHasFocus = true;
if (parent != NULL)
parent->selectionTargetY = mY;
}
setFocus(true);
if (getParent() != NULL)
{
SimpleMenu *menu = (SimpleMenu *) parent;
menu->selectionTargetY = getY();
}
bool SimpleMenuItem::Leaving(JButton key)
{
checkUserClick();
mHasFocus = false;
return true;
}
bool SimpleMenuItem::ButtonPressed()
{
return mIsValidSelection;
}
void SimpleMenuItem::Relocate(float x, float y)
{
mXOffset = x - (parent->getWidth()/2); // determines the leftmost point of the text;
mX = x;
mY = y;
}
/* Accessors */
float SimpleMenuItem::getX() const
{
return mX;
}
float SimpleMenuItem::getY() const
{
return mY;
}
void SimpleMenuItem::setFontId(const int &fontId)
{
mFontId = fontId;
}
int SimpleMenuItem::getFontId() const
{
return mFontId;
}
void SimpleMenuItem::setIsSelectionValid( bool validSelection )
{
mIsValidSelection = validSelection;
}
bool SimpleMenuItem::isSelectionValid() const
{
return mIsValidSelection;
}
void SimpleMenuItem::setFocus(bool value)
{
mHasFocus = value;
}
bool SimpleMenuItem::hasFocus() const
{
return mHasFocus;
}
string SimpleMenuItem::getDescription() const
{
return mDescription;
@@ -150,29 +40,13 @@ void SimpleMenuItem::setDescription( const string& desc )
mDescription = desc;
}
string SimpleMenuItem::getText() const
{
return mText;
}
void SimpleMenuItem::setText( const string& text)
{
mText = text;
}
float SimpleMenuItem::GetWidth() const
{
WFont * mFont = WResourceManager::Instance()->GetWFont(mFontId);
mFont->SetScale(1.0);
return mFont->GetStringWidth(mText.c_str());
}
ostream& SimpleMenuItem::toString(ostream& out) const
{
return out << "SimpleMenuItem ::: mHasFocus : " << mHasFocus
<< " ; parent : " << parent
<< " ; mText : " << mText
<< " ; mScale : " << mScale
<< " ; mTargetScale : " << mTargetScale
<< " ; mX,mY : " << mX << "," << mY;
return out << "SimpleMenuItem ::: mHasFocus : " << hasFocus()
<< " ; parent : " << getParent()
<< " ; mText : " << getText()
<< " ; mScale : " << getScale()
<< " ; mTargetScale : " << getTargetScale()
<< " ; mX,mY : " << getX() << "," << getY();
}

View File

@@ -3,6 +3,7 @@
*
* Created on: Nov 18, 2010
* Author: Michael
* The popups all have a default button created to act as the dismiss button, mapped to JGE_BTN_CANCEL (triangle) with "Detailed Info" to use for the button width.
*/
#include "PrecompiledHeader.h"
@@ -13,7 +14,9 @@
#include "DeckManager.h"
#include <iomanip>
SimplePopup::SimplePopup(int id, JGuiListener* listener, const int fontId, const char * _title, DeckMetaData* deckMetaData, MTGAllCards * collection) :
const int kDismissButtonId = 10000;
SimplePopup::SimplePopup(int id, JGuiListener* listener, const int fontId, const char * _title, DeckMetaData* deckMetaData, MTGAllCards * collection, int cancelX, int cancelY) :
JGuiController(JGE::GetInstance(), id, listener), mFontId(fontId), mCollection(collection)
{
mX = 19;
@@ -25,6 +28,8 @@ SimplePopup::SimplePopup(int id, JGuiListener* listener, const int fontId, const
mTextFont = WResourceManager::Instance()->GetWFont(fontId);
this->mCount = 1; // a hack to ensure the menus do book keeping correctly. Since we aren't adding items to the menu, this is required
mStatsWrapper = NULL;
JGuiController::Add(NEW InteractiveButton(this, kDismissButtonId, Fonts::MAIN_FONT, "Detailed Info", cancelX, cancelY, JGE_BTN_CANCEL), true);
Update(deckMetaData);
}
@@ -36,15 +41,15 @@ void SimplePopup::Render()
string detailedInformation = getDetailedInformation(mDeckInformation->getFilename());
const float textHeight = mTextFont->GetHeight() * mMaxLines;
r->DrawRoundRect(mX, mY, mWidth, textHeight, 2.0f, ARGB( 255, 125, 255, 0) );
r->FillRoundRect(mX, mY, mWidth, textHeight, 2.0f, ARGB( 255, 0, 0, 0 ) );
r->FillRoundRect(mX, mY + 2, mWidth + 11, textHeight - 12, 2.0f, ARGB( 255, 0, 0, 0 ) );
// currently causes a crash on the PSP when drawing the corners.
// TODO: clean up the image ot make it loook cleaner. Find solution to load gfx to not crash PSP
#if 0
drawBoundingBox( mX, mY, mWidth, textHeight );
r->DrawRoundRect(mX, mY + 2, mWidth + 11, textHeight - 12, 2.0f, ARGB( 255, 125, 255, 0) );
drawBoundingBox( mX-3, mY, mWidth + 3, textHeight );
#endif
mTextFont->DrawString(detailedInformation.c_str(), mX + 9 , mY + 15);
mTextFont->DrawString(detailedInformation.c_str(), mX + 9 , mY + 10);
}
@@ -117,10 +122,11 @@ string SimplePopup::getDetailedInformation(string filename)
return oss.str();
}
void SimplePopup::Update(float dt)
void SimplePopup::Update(float dt)
{
JButton key = mEngine->ReadButton();
CheckUserInput(key);
}
// drawing routines

View File

@@ -276,6 +276,10 @@
12211ED11494823F00641703 /* Default@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 12211ED01494823E00641703 /* Default@2x.png */; };
12211ED41494916D00641703 /* Default-Landscape.png in Resources */ = {isa = PBXBuildFile; fileRef = 12211ED21494916D00641703 /* Default-Landscape.png */; };
12211ED51494916D00641703 /* Default-Portrait.png in Resources */ = {isa = PBXBuildFile; fileRef = 12211ED31494916D00641703 /* Default-Portrait.png */; };
12272FC414CD57CF00192DC7 /* SimpleButton.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 12272FC314CD57CF00192DC7 /* SimpleButton.cpp */; };
12272FC514CD57CF00192DC7 /* SimpleButton.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 12272FC314CD57CF00192DC7 /* SimpleButton.cpp */; };
12272FC814CD6A3900192DC7 /* InteractiveButton.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 12272FC714CD6A3900192DC7 /* InteractiveButton.cpp */; };
12272FC914CD6A3900192DC7 /* InteractiveButton.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 12272FC714CD6A3900192DC7 /* InteractiveButton.cpp */; };
12769486144127380088F6D3 /* AIPlayerBaka.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 12769483144127380088F6D3 /* AIPlayerBaka.cpp */; };
12769487144127380088F6D3 /* AIPlayerBakaB.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 12769484144127380088F6D3 /* AIPlayerBakaB.cpp */; };
12769488144127380088F6D3 /* TestSuiteAI.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 12769485144127380088F6D3 /* TestSuiteAI.cpp */; };
@@ -558,6 +562,10 @@
12211ED01494823E00641703 /* Default@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "Default@2x.png"; path = "../Default@2x.png"; sourceTree = "<group>"; };
12211ED21494916D00641703 /* Default-Landscape.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "Default-Landscape.png"; path = "../Default-Landscape.png"; sourceTree = "<group>"; };
12211ED31494916D00641703 /* Default-Portrait.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "Default-Portrait.png"; path = "../Default-Portrait.png"; sourceTree = "<group>"; };
12272FC114CD558C00192DC7 /* SimpleButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SimpleButton.h; sourceTree = "<group>"; };
12272FC314CD57CF00192DC7 /* SimpleButton.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SimpleButton.cpp; sourceTree = "<group>"; };
12272FC614CD68FB00192DC7 /* InteractiveButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InteractiveButton.h; sourceTree = "<group>"; };
12272FC714CD6A3900192DC7 /* InteractiveButton.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InteractiveButton.cpp; sourceTree = "<group>"; };
12769483144127380088F6D3 /* AIPlayerBaka.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AIPlayerBaka.cpp; sourceTree = "<group>"; };
12769484144127380088F6D3 /* AIPlayerBakaB.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AIPlayerBakaB.cpp; sourceTree = "<group>"; };
12769485144127380088F6D3 /* TestSuiteAI.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TestSuiteAI.cpp; sourceTree = "<group>"; };
@@ -1489,6 +1497,7 @@
CEA376851291C60500B9016A /* include */ = {
isa = PBXGroup;
children = (
12272FC114CD558C00192DC7 /* SimpleButton.h */,
12CCA032144A05DF00E343A0 /* AbilityParser.h */,
127694891441274D0088F6D3 /* AIPlayerBaka.h */,
1276948A1441274D0088F6D3 /* AIPlayerBakaB.h */,
@@ -1603,6 +1612,7 @@
CEA376EA1291C60500B9016A /* WFont.h */,
CEA376EB1291C60500B9016A /* WGui.h */,
CEA376EC1291C60500B9016A /* WResourceManager.h */,
12272FC614CD68FB00192DC7 /* InteractiveButton.h */,
);
path = include;
sourceTree = "<group>";
@@ -1720,6 +1730,8 @@
CEA377551291C60500B9016A /* WFont.cpp */,
CEA377561291C60500B9016A /* WGui.cpp */,
CEA377571291C60500B9016A /* WResourceManager.cpp */,
12272FC314CD57CF00192DC7 /* SimpleButton.cpp */,
12272FC714CD6A3900192DC7 /* InteractiveButton.cpp */,
);
path = src;
sourceTree = "<group>";
@@ -2189,6 +2201,8 @@
12059E4614980B7300DAC43B /* ZipArchive.mm in Sources */,
12059E4714980B7300DAC43B /* Reachability.m in Sources */,
12059E4814980B7300DAC43B /* WagicDownloadProgressViewController.m in Sources */,
12272FC514CD57CF00192DC7 /* SimpleButton.cpp in Sources */,
12272FC914CD6A3900192DC7 /* InteractiveButton.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -2397,6 +2411,8 @@
12211EAF14933D6600641703 /* ZipArchive.mm in Sources */,
12211EB71493483C00641703 /* Reachability.m in Sources */,
12211EC91494360C00641703 /* WagicDownloadProgressViewController.m in Sources */,
12272FC414CD57CF00192DC7 /* SimpleButton.cpp in Sources */,
12272FC814CD6A3900192DC7 /* InteractiveButton.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};