Added the notion of a 'cancel' button, and unified all the 'cancel' menu IDs to be kCancelMenuID (ie -1). I've slaved the Menu button (ie Esc on win, 'Start' button on PSP) to this - the idea being, if you hit the Menu button to bring up a menu, hitting it again will dismiss it without doing anything, which is pretty standard behavior for most console/computer games.

This commit is contained in:
wrenczes@gmail.com
2010-11-07 02:08:17 +00:00
parent b0c61049da
commit 3c19533a4c
13 changed files with 303 additions and 274 deletions
+3
View File
@@ -25,6 +25,8 @@
#define JGUI_INITIAL_DELAY 0.4 #define JGUI_INITIAL_DELAY 0.4
#define JGUI_REPEAT_DELAY 0.2 #define JGUI_REPEAT_DELAY 0.2
const int kCancelMenuID = -1;
class JGuiListener class JGuiListener
{ {
public: public:
@@ -71,6 +73,7 @@ class JGuiController
JButton mActionButton; JButton mActionButton;
JButton mCancelButton;
int mCurr; int mCurr;
int mStyle; int mStyle;
+8
View File
@@ -76,6 +76,7 @@ JGuiController::JGuiController(int id, JGuiListener* listener) : mId(id), mListe
mShowCursor = false; mShowCursor = false;
mActionButton = JGE_BTN_OK; mActionButton = JGE_BTN_OK;
mCancelButton = JGE_BTN_MENU;
mStyle = JGUI_STYLE_WRAPPING; mStyle = JGUI_STYLE_WRAPPING;
@@ -110,6 +111,13 @@ bool JGuiController::CheckUserInput(JButton key){
return true; return true;
} }
} }
else if (key == mCancelButton)
{
if (mListener != NULL)
{
mListener->ButtonPressed(mId, kCancelMenuID);
}
}
else if ((JGE_BTN_LEFT == key) || (JGE_BTN_UP == key)) // || mEngine->GetAnalogY() < 64 || mEngine->GetAnalogX() < 64) else if ((JGE_BTN_LEFT == key) || (JGE_BTN_UP == key)) // || mEngine->GetAnalogY() < 64 || mEngine->GetAnalogX() < 64)
{ {
int n = mCurr; int n = mCurr;
+2 -2
View File
@@ -53,12 +53,12 @@ enum DECK_VIEWER_MENU_ITEMS
{ {
MENU_ITEM_NEW_DECK = -30, MENU_ITEM_NEW_DECK = -30,
MENU_ITEM_CHEAT_MODE = -12, MENU_ITEM_CHEAT_MODE = -12,
MENU_ITEM_CANCEL = -1, MENU_ITEM_CANCEL = kCancelMenuID,
MENU_ITEM_SAVE_RETURN_MAIN_MENU = 0, MENU_ITEM_SAVE_RETURN_MAIN_MENU = 0,
MENU_ITEM_SAVE_RENAME = 1, MENU_ITEM_SAVE_RENAME = 1,
MENU_ITEM_SWITCH_DECKS_NO_SAVE = 2, MENU_ITEM_SWITCH_DECKS_NO_SAVE = 2,
MENU_ITEM_MAIN_MENU = 3, MENU_ITEM_MAIN_MENU = 3,
MENU_ITEM_EDITOR_CANCEL = 4, MENU_ITEM_EDITOR_CANCEL = kCancelMenuID,
MENU_ITEM_SAVE_AS_AI_DECK = 5, MENU_ITEM_SAVE_AS_AI_DECK = 5,
MENU_ITEM_YES = 20, MENU_ITEM_YES = 20,
MENU_ITEM_NO = 21, MENU_ITEM_NO = 21,
+2 -2
View File
@@ -57,8 +57,8 @@ class GameStateDuel: public GameState, public JGuiListener
enum ENUM_DUEL_STATE_MENU_ITEM enum ENUM_DUEL_STATE_MENU_ITEM
{ {
MENUITEM_NEW_DECK = -1, MENUITEM_CANCEL = kCancelMenuID,
MENUITEM_CANCEL = -10, MENUITEM_NEW_DECK = -10,
MENUITEM_RANDOM_PLAYER = -11, MENUITEM_RANDOM_PLAYER = -11,
MENUITEM_RANDOM_AI = -12, MENUITEM_RANDOM_AI = -12,
MENUITEM_MAIN_MENU = -13, MENUITEM_MAIN_MENU = -13,
+1 -1
View File
@@ -232,7 +232,7 @@ void ActionLayer::setMenuObject(Targetable * object, bool must){
abilitiesMenu->Add(i,currentAction->getMenuText()); abilitiesMenu->Add(i,currentAction->getMenuText());
} }
} }
if (!must) abilitiesMenu->Add(-1, "Cancel"); if (!must) abilitiesMenu->Add(kCancelMenuID, "Cancel");
else cantCancel = 1; else cantCancel = 1;
modal = 1; modal = 1;
} }
+11 -5
View File
@@ -17,6 +17,12 @@ enum ENUM_AWARDS_STATE{
STATE_DETAILS, STATE_DETAILS,
}; };
namespace
{
const int kBackToTrophiesID = 2;
const int kBackToMainMenuID = 1;
}
GameStateAwards::GameStateAwards(GameApp* parent): GameState(parent){ GameStateAwards::GameStateAwards(GameApp* parent): GameState(parent){
} }
@@ -164,9 +170,9 @@ void GameStateAwards::Update(float dt)
SAFE_DELETE(menu); SAFE_DELETE(menu);
menu = NEW SimpleMenu(-102, this,Fonts::MENU_FONT, 50,170); menu = NEW SimpleMenu(-102, this,Fonts::MENU_FONT, 50,170);
if(mState == STATE_DETAILS) if(mState == STATE_DETAILS)
menu->Add(2, "Back to Trophies"); menu->Add(kBackToTrophiesID, "Back to Trophies");
menu->Add(1, "Back to Main Menu"); menu->Add(kBackToMainMenuID, "Back to Main Menu");
menu->Add(3, "Cancel"); menu->Add(kCancelMenuID, "Cancel");
break; break;
case JGE_BTN_PREV: case JGE_BTN_PREV:
mParent->DoTransition(TRANSITION_FADE,GAME_STATE_MENU); mParent->DoTransition(TRANSITION_FADE,GAME_STATE_MENU);
@@ -321,11 +327,11 @@ void GameStateAwards::ButtonPressed(int controllerId, int controlId)
{ {
if(controllerId == -102) if(controllerId == -102)
switch (controlId){ switch (controlId){
case 1: case kBackToMainMenuID:
mParent->DoTransition(TRANSITION_FADE,GAME_STATE_MENU); mParent->DoTransition(TRANSITION_FADE,GAME_STATE_MENU);
showMenu = false; showMenu = false;
break; break;
case 2: case kBackToTrophiesID:
mState = STATE_LISTVIEW; mState = STATE_LISTVIEW;
SAFE_DELETE(detailview); SAFE_DELETE(detailview);
showMenu = false; showMenu = false;
+2 -2
View File
@@ -129,7 +129,7 @@ void GameStateDuel::Start()
fillDeckMenu(deckmenu,RESPATH"/player/premade"); fillDeckMenu(deckmenu,RESPATH"/player/premade");
} }
deckmenu->Add( MENUITEM_NEW_DECK, "New Deck...", "Create a new deck to play with."); deckmenu->Add( MENUITEM_NEW_DECK, "New Deck...", "Create a new deck to play with.");
deckmenu->Add( MENUITEM_MAIN_MENU, "Main Menu", "Return to Main Menu"); deckmenu->Add( MENUITEM_CANCEL, "Main Menu", "Return to Main Menu");
} }
for (int i = 0; i < 2; ++i){ for (int i = 0; i < 2; ++i){
@@ -556,7 +556,7 @@ void GameStateDuel::ButtonPressed(int controllerId, int controlId) {
mGamePhase = DUEL_STATE_CHOOSE_DECK2_TO_PLAY; mGamePhase = DUEL_STATE_CHOOSE_DECK2_TO_PLAY;
break; break;
} }
else if (controlId == MENUITEM_MAIN_MENU ) // user clicked on "Cancel" else if (controlId == MENUITEM_MAIN_MENU || controlId == MENUITEM_CANCEL ) // user clicked on "Cancel"
{ {
if (deckmenu) if (deckmenu)
deckmenu->Close(); deckmenu->Close();
+4 -1
View File
@@ -50,6 +50,7 @@ enum ENUM_MENU_STATE_MINOR
enum enum
{ {
SUBMENUITEM_CANCEL = kCancelMenuID,
MENUITEM_PLAY, MENUITEM_PLAY,
MENUITEM_DECKEDITOR, MENUITEM_DECKEDITOR,
MENUITEM_SHOP, MENUITEM_SHOP,
@@ -58,7 +59,6 @@ enum
SUBMENUITEM_1PLAYER, SUBMENUITEM_1PLAYER,
SUBMENUITEM_2PLAYER, SUBMENUITEM_2PLAYER,
SUBMENUITEM_DEMO, SUBMENUITEM_DEMO,
SUBMENUITEM_CANCEL,
SUBMENUITEM_TESTSUITE, SUBMENUITEM_TESTSUITE,
SUBMENUITEM_MOMIR, SUBMENUITEM_MOMIR,
SUBMENUITEM_CLASSIC, SUBMENUITEM_CLASSIC,
@@ -698,7 +698,10 @@ void GameStateMenu::ButtonPressed(int controllerId, int controlId)
currentState = MENU_STATE_MAJOR_DUEL | MENU_STATE_MINOR_SUBMENU_CLOSING; currentState = MENU_STATE_MAJOR_DUEL | MENU_STATE_MINOR_SUBMENU_CLOSING;
break; break;
case SUBMENUITEM_CANCEL: case SUBMENUITEM_CANCEL:
if (subMenuController != NULL)
{
subMenuController->Close(); subMenuController->Close();
}
currentState = MENU_STATE_MAJOR_MAINMENU | MENU_STATE_MINOR_SUBMENU_CLOSING; currentState = MENU_STATE_MAJOR_MAINMENU | MENU_STATE_MINOR_SUBMENU_CLOSING;
break; break;
+18 -9
View File
@@ -8,6 +8,15 @@
#include "GameOptions.h" #include "GameOptions.h"
#include "Translate.h" #include "Translate.h"
namespace
{
const int kSaveAndBackToMainMenuID = 1;
const int kBackToMainMenuID = 2;
const int kNewProfileID = 4;
const int kReloadID = 5;
}
GameStateOptions::GameStateOptions(GameApp* parent): GameState(parent), mReload(false), grabber(NULL), optionsMenu(NULL), optionsTabs(NULL) {} GameStateOptions::GameStateOptions(GameApp* parent): GameState(parent), mReload(false), grabber(NULL), optionsMenu(NULL), optionsTabs(NULL) {}
GameStateOptions::~GameStateOptions() {} GameStateOptions::~GameStateOptions() {}
@@ -62,7 +71,7 @@ void GameStateOptions::Start()
optionsList->Add(NEW WGuiSplit(cPrf,cThm)); optionsList->Add(NEW WGuiSplit(cPrf,cThm));
optionsList->Add(cStyle); optionsList->Add(cStyle);
optionsList->Add(NEW WGuiButton(NEW WGuiHeader("New Profile"),-102,4,this)); optionsList->Add(NEW WGuiButton(NEW WGuiHeader("New Profile"),-102, kNewProfileID, this));
optionsList->Add(NEW WDecoCheat(NEW OptionInteger(Options::CHEATMODE, "Enable cheat mode"))); optionsList->Add(NEW WDecoCheat(NEW OptionInteger(Options::CHEATMODE, "Enable cheat mode")));
optionsTabs->Add(optionsList); optionsTabs->Add(optionsList);
@@ -89,9 +98,9 @@ void GameStateOptions::Start()
optionsTabs->Add(optionsList); optionsTabs->Add(optionsList);
optionsMenu = NEW SimpleMenu(-102, this,Fonts::MENU_FONT, 50,170); optionsMenu = NEW SimpleMenu(-102, this,Fonts::MENU_FONT, 50,170);
optionsMenu->Add(2, "Back to Main Menu"); optionsMenu->Add(kBackToMainMenuID, "Back to Main Menu");
optionsMenu->Add(1, "Save & Back to Main Menu"); optionsMenu->Add(kSaveAndBackToMainMenuID, "Save & Back to Main Menu");
optionsMenu->Add(3, "Cancel"); optionsMenu->Add(kCancelMenuID, "Cancel");
optionsTabs->Entering(JGE_BTN_NONE); optionsTabs->Entering(JGE_BTN_NONE);
} }
@@ -245,21 +254,21 @@ void GameStateOptions::ButtonPressed(int controllerId, int controlId)
//Exit menu? //Exit menu?
if(controllerId == -102) if(controllerId == -102)
switch (controlId){ switch (controlId){
case 1: case kSaveAndBackToMainMenuID:
mState = SAVE; mState = SAVE;
break; break;
//Set Audio volume //Set Audio volume
case 2: case kBackToMainMenuID:
mParent->DoTransition(TRANSITION_FADE,GAME_STATE_MENU); mParent->DoTransition(TRANSITION_FADE,GAME_STATE_MENU);
break; break;
case 3: case kCancelMenuID:
mState = SHOW_OPTIONS; mState = SHOW_OPTIONS;
break; break;
case 4: case kNewProfileID:
options.keypadStart("",&newProfile); options.keypadStart("",&newProfile);
options.keypadTitle("New Profile"); options.keypadTitle("New Profile");
break; break;
case 5: case kReloadID:
mReload = true; mReload = true;
break; break;
} }
+2 -2
View File
@@ -417,7 +417,7 @@ void GameStateShop::Update(float dt)
if (options[Options::CHEATMODE].number) if (options[Options::CHEATMODE].number)
menu->Add(-2,"Steal 1,000 credits"); menu->Add(-2,"Steal 1,000 credits");
menu->Add(12,"Save & Back to Main Menu"); menu->Add(12,"Save & Back to Main Menu");
menu->Add(13, "Cancel"); menu->Add(kCancelMenuID, "Cancel");
} }
break; break;
case STAGE_SHOP_TASKS: case STAGE_SHOP_TASKS:
@@ -437,7 +437,7 @@ void GameStateShop::Update(float dt)
menu = NEW SimpleMenu(11,this,Fonts::MENU_FONT,SCREEN_WIDTH/2-100,20); menu = NEW SimpleMenu(11,this,Fonts::MENU_FONT,SCREEN_WIDTH/2-100,20);
menu->Add(15,"Return to shop"); menu->Add(15,"Return to shop");
menu->Add(12,"Save & Back to Main Menu"); menu->Add(12,"Save & Back to Main Menu");
menu->Add(13, "Cancel"); menu->Add(kCancelMenuID, "Cancel");
} }
} }
} }
+2 -2
View File
@@ -48,7 +48,7 @@ void GameStateStory::loadStoriesMenu(const char * root){
for (size_t i = 0; i < stories.size(); ++i){ for (size_t i = 0; i < stories.size(); ++i){
menu->Add(i, stories[i].c_str()); menu->Add(i, stories[i].c_str());
} }
menu->Add(-1,"Cancel"); menu->Add(kCancelMenuID, "Cancel");
} }
} }
@@ -62,7 +62,7 @@ void GameStateStory::Update(float dt) {
if (!menu && mEngine->GetButtonClick(JGE_BTN_MENU)){ if (!menu && mEngine->GetButtonClick(JGE_BTN_MENU)){
menu = NEW SimpleMenu(100, this, Fonts::MENU_FONT, SCREEN_WIDTH/2-100, 25); menu = NEW SimpleMenu(100, this, Fonts::MENU_FONT, SCREEN_WIDTH/2-100, 25);
menu->Add(0,"Back to main menu"); menu->Add(0,"Back to main menu");
menu->Add(-1, "Cancel"); menu->Add(kCancelMenuID, "Cancel");
} }
if (menu) { if (menu) {
menu->Update(dt); menu->Update(dt);
+2 -2
View File
@@ -1649,7 +1649,7 @@ void WGuiFilterItem::updateValue(){
} }
if(!mNew) if(!mNew)
mParent->subMenu->Add(-2,"Remove"); mParent->subMenu->Add(-2,"Remove");
mParent->subMenu->Add(-1,"Cancel"); mParent->subMenu->Add(kCancelMenuID,"Cancel");
if(delMenu){ if(delMenu){
SAFE_DELETE(mParent->subMenu); SAFE_DELETE(mParent->subMenu);
mState = STATE_FINISHED; mState = STATE_FINISHED;
@@ -1754,7 +1754,7 @@ void WGuiFilterItem::updateValue(){
} }
mParent->addArg("Digit","alpha:#;"); mParent->addArg("Digit","alpha:#;");
} }
mParent->subMenu->Add(-1,"Cancel"); mParent->subMenu->Add(kCancelMenuID,"Cancel");
break; break;
case STATE_CHOOSE_VAL: case STATE_CHOOSE_VAL:
mState = STATE_FINISHED; mState = STATE_FINISHED;