Jeck - Daily build, deck renaming, small keypad bugfix, profileFile() fix, proposed new iconspsp.png.

* Decks now support naming and renaming. Also added a "Switch decks without saving" option.
 * Removed unused static const char * menuTexts, from old 6-deck limited system
 * Keypad didn't display correctly when not given a title, and was never destructed. Fixed.
 * profileFile() default behavior was to fall back to RESPATH/player. Fixed.
 * New iconspsp.png, updated look to seem like PSP buttons, added some extra (unused) button icons.
This commit is contained in:
wagic.jeck
2009-09-22 02:47:48 +00:00
parent 643b37d8b2
commit 7510ee165f
13 changed files with 503 additions and 438 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.6 KiB

After

Width:  |  Height:  |  Size: 27 KiB

View File

@@ -116,7 +116,7 @@ public:
//These return a filepath accurate to the current mode/profile/theme, and can //These return a filepath accurate to the current mode/profile/theme, and can
//optionally fallback to a file within a certain directory. //optionally fallback to a file within a certain directory.
//The sanity=false option returns the adjusted path even if the file doesn't exist. //The sanity=false option returns the adjusted path even if the file doesn't exist.
string profileFile(string filename="", string fallback="", bool sanity=true,bool relative=false); string profileFile(string filename="", string fallback="", bool sanity=false,bool relative=false);
void reloadProfile(bool images = true); //Reloads profile using current options[ACTIVE_PROFILE] void reloadProfile(bool images = true); //Reloads profile using current options[ACTIVE_PROFILE]
void checkProfile(); //Confirms that a profile is loaded and contains a collection. void checkProfile(); //Confirms that a profile is loaded and contains a collection.

View File

@@ -30,8 +30,6 @@ class GameState
JGE* mEngine; JGE* mEngine;
public: public:
static const char * const menuTexts[];
GameState(GameApp* parent); GameState(GameApp* parent);
virtual ~GameState() {} virtual ~GameState() {}

View File

@@ -53,7 +53,8 @@ private:
float mSlide; float mSlide;
int mAlpha; int mAlpha;
int mStage; int mStage;
int nbDecks;
int deckNum;
int colorFilter; int colorFilter;
JMusic * bgMusic; JMusic * bgMusic;
JQuad * backQuad; JQuad * backQuad;
@@ -74,11 +75,12 @@ private:
int hudAlpha; int hudAlpha;
float scrollSpeed; float scrollSpeed;
int delSellMenu; int delSellMenu;
string newDeckname;
public: public:
GameStateDeckViewer(GameApp* parent); GameStateDeckViewer(GameApp* parent);
virtual ~GameStateDeckViewer(); virtual ~GameStateDeckViewer();
void updateDecks();
void rotateCards(int direction); void rotateCards(int direction);
void loadIndexes(MTGCard * current = NULL); void loadIndexes(MTGCard * current = NULL);
void switchDisplay(); void switchDisplay();

View File

@@ -17,7 +17,6 @@
#include "../include/DeckStats.h" #include "../include/DeckStats.h"
#include "../include/Translate.h" #include "../include/Translate.h"
const char * const GameState::menuTexts[]= {"--NEW--","Deck 1", "Deck 2", "Deck 3", "Deck 4", "Deck 5", "Deck 6"} ;
hgeParticleSystem* GameApp::Particles[] = {NULL,NULL,NULL,NULL,NULL,NULL}; hgeParticleSystem* GameApp::Particles[] = {NULL,NULL,NULL,NULL,NULL,NULL};
int GameApp::HasMusic = 1; int GameApp::HasMusic = 1;
JMusic * GameApp::music = NULL; JMusic * GameApp::music = NULL;

View File

@@ -203,6 +203,7 @@ GameSettings::~GameSettings(){
SAFE_DELETE(globalOptions); SAFE_DELETE(globalOptions);
SAFE_DELETE(profileOptions); SAFE_DELETE(profileOptions);
SAFE_DELETE(themeOptions); SAFE_DELETE(themeOptions);
SAFE_DELETE(keypad);
} }
GameOption& GameSettings::operator[](string option_name){ GameOption& GameSettings::operator[](string option_name){
@@ -223,11 +224,11 @@ int GameSettings::save(){
if(profileOptions){ if(profileOptions){
//Force our directories to exist. //Force our directories to exist.
MAKEDIR(RESPATH"/profiles"); MAKEDIR(RESPATH"/profiles");
string temp = profileFile("","",false,false); string temp = profileFile();
MAKEDIR(temp.c_str()); MAKEDIR(temp.c_str());
temp+="/stats"; temp+="/stats";
MAKEDIR(temp.c_str()); MAKEDIR(temp.c_str());
temp = profileFile(PLAYER_SETTINGS,"",false); temp = profileFile(PLAYER_SETTINGS);
profileOptions->save(); profileOptions->save();
} }
@@ -289,7 +290,7 @@ void GameSettings::checkProfile(){
//If it doesn't exist, load current profile. //If it doesn't exist, load current profile.
if(!profileOptions) if(!profileOptions)
profileOptions = NEW GameOptions(profileFile(PLAYER_SETTINGS,"",false)); profileOptions = NEW GameOptions(profileFile(PLAYER_SETTINGS));
//Load theme options //Load theme options
if(!themeOptions){ if(!themeOptions){
@@ -343,7 +344,7 @@ void GameSettings::createUsersFirstDeck(int setId){
if(theGame == NULL || theGame->collection == NULL) if(theGame == NULL || theGame->collection == NULL)
return; return;
MTGDeck *mCollection = NEW MTGDeck(options.profileFile(PLAYER_COLLECTION,"",false).c_str(), theGame->collection); MTGDeck *mCollection = NEW MTGDeck(options.profileFile(PLAYER_COLLECTION).c_str(), theGame->collection);
//10 lands of each //10 lands of each
int sets[] = {setId}; int sets[] = {setId};
if (!mCollection->addRandomCards(10, sets,1, Constants::RARITY_L,"Forest")){ if (!mCollection->addRandomCards(10, sets,1, Constants::RARITY_L,"Forest")){

View File

@@ -9,6 +9,8 @@
GameStateDeckViewer::GameStateDeckViewer(GameApp* parent): GameState(parent) { GameStateDeckViewer::GameStateDeckViewer(GameApp* parent): GameState(parent) {
bgMusic = NULL; bgMusic = NULL;
scrollSpeed = MED_SPEED; scrollSpeed = MED_SPEED;
nbDecks = 0;
deckNum = 0;
} }
GameStateDeckViewer::~GameStateDeckViewer() { GameStateDeckViewer::~GameStateDeckViewer() {
@@ -67,14 +69,27 @@ void GameStateDeckViewer::switchDisplay(){
loadIndexes(); loadIndexes();
} }
void GameStateDeckViewer::updateDecks(){
SAFE_DELETE(welcome_menu);
welcome_menu = NEW SimpleMenu(10,this,menuFont,20,20);
nbDecks = fillDeckMenu(welcome_menu,options.profileFile());
deckNum = 0;
newDeckname = "";
welcome_menu->Add(nbDecks+1, "--NEW--");
welcome_menu->Add(-1, "Cancel");
}
void GameStateDeckViewer::Start() void GameStateDeckViewer::Start()
{ {
newDeckname = "";
hudAlpha = 0; hudAlpha = 0;
delSellMenu = 0; delSellMenu = 0;
pricelist = NEW PriceList(RESPATH"/settings/prices.dat",mParent->collection); pricelist = NEW PriceList(RESPATH"/settings/prices.dat",mParent->collection);
playerdata = NEW PlayerData(mParent->collection); playerdata = NEW PlayerData(mParent->collection);
sellMenu = NULL; sellMenu = NULL;
myCollection = NEW DeckDataWrapper(NEW MTGDeck(options.profileFile(PLAYER_COLLECTION,"",false).c_str(), mParent->collection)); myCollection = NEW DeckDataWrapper(NEW MTGDeck(options.profileFile(PLAYER_COLLECTION).c_str(), mParent->collection));
displayed_deck = myCollection; displayed_deck = myCollection;
myDeck = NULL; myDeck = NULL;
menuFont = resources.GetJLBFont(Constants::MENU_FONT); menuFont = resources.GetJLBFont(Constants::MENU_FONT);
@@ -83,8 +98,10 @@ void GameStateDeckViewer::Start()
menu = NEW SimpleMenu(11,this,menuFont,SCREEN_WIDTH/2-100,20); menu = NEW SimpleMenu(11,this,menuFont,SCREEN_WIDTH/2-100,20);
menu->Add(11,"Save"); menu->Add(11,"Save");
menu->Add(12,"Back to main menu"); menu->Add(12,"Rename deck");
menu->Add(13, "Cancel"); menu->Add(13,"Switch decks without saving");
menu->Add(14,"Back to main menu");
menu->Add(15,"Cancel");
//icon images //icon images
@@ -114,7 +131,8 @@ void GameStateDeckViewer::Start()
//menuFont = NEW JLBFont("graphics/f3",16); //menuFont = NEW JLBFont("graphics/f3",16);
menuFont = resources.GetJLBFont("f3"); menuFont = resources.GetJLBFont("f3");
welcome_menu = NEW SimpleMenu(10,this,menuFont,20,20); welcome_menu = NEW SimpleMenu(10,this,menuFont,20,20);
int nbDecks = fillDeckMenu(welcome_menu,options.profileFile()); nbDecks = fillDeckMenu(welcome_menu,options.profileFile());
deckNum = 0;
welcome_menu->Add(nbDecks+1, "--NEW--"); welcome_menu->Add(nbDecks+1, "--NEW--");
welcome_menu->Add(-1, "Cancel"); welcome_menu->Add(-1, "Cancel");
@@ -135,6 +153,7 @@ void GameStateDeckViewer::Start()
mRotation = 0; mRotation = 0;
mSlide = 0; mSlide = 0;
mAlpha = 255; mAlpha = 255;
newDeckname = "";
//mEngine->ResetPrivateVRAM(); //mEngine->ResetPrivateVRAM();
//mEngine->EnableVSync(true); //mEngine->EnableVSync(true);
currentCard = NULL; currentCard = NULL;
@@ -189,6 +208,22 @@ int GameStateDeckViewer::Remove(MTGCard * card){
void GameStateDeckViewer::Update(float dt) void GameStateDeckViewer::Update(float dt)
{ {
if(options.keypadActive()){
options.keypadUpdate(dt);
if(newDeckname != ""){
newDeckname = options.keypadFinish();
if(newDeckname != ""){
loadDeck(deckNum);
if(myDeck && myDeck->parent)
myDeck->parent->meta_name = newDeckname;
}
newDeckname = "";
}
//Prevent screen from updating.
return;
}
// mParent->effect->UpdateBig(dt); // mParent->effect->UpdateBig(dt);
hudAlpha = 255-(last_user_activity * 500); hudAlpha = 255-(last_user_activity * 500);
if (hudAlpha < 0) hudAlpha = 0; if (hudAlpha < 0) hudAlpha = 0;
@@ -660,13 +695,15 @@ void GameStateDeckViewer::Render()
} }
if (sellMenu) sellMenu->Render(); if (sellMenu) sellMenu->Render();
if(options.keypadActive())
options.keypadRender();
} }
int GameStateDeckViewer::loadDeck(int deckid){ int GameStateDeckViewer::loadDeck(int deckid){
SAFE_DELETE(myCollection); SAFE_DELETE(myCollection);
string profile = options[Options::ACTIVE_PROFILE].str; string profile = options[Options::ACTIVE_PROFILE].str;
myCollection = NEW DeckDataWrapper(NEW MTGDeck(options.profileFile(PLAYER_COLLECTION,"",false).c_str(), mParent->collection)); myCollection = NEW DeckDataWrapper(NEW MTGDeck(options.profileFile(PLAYER_COLLECTION).c_str(), mParent->collection));
displayed_deck = myCollection; displayed_deck = myCollection;
char deckname[256]; char deckname[256];
sprintf(deckname,"deck%i.txt",deckid); sprintf(deckname,"deck%i.txt",deckid);
@@ -692,11 +729,20 @@ void GameStateDeckViewer::ButtonPressed(int controllerId, int controlId)
case 10: case 10:
if (controlId == -1){ if (controlId == -1){
mParent->SetNextState(GAME_STATE_MENU); mParent->SetNextState(GAME_STATE_MENU);
return; break;
}
else if(controlId == nbDecks+1){
char buf[512];
deckNum = controlId;
sprintf(buf,"deck%i",deckNum);
options.keypadStart(buf,&newDeckname);
options.keypadTitle("Deck name");
//Fallthrough to deck editing.
} }
loadDeck(controlId); loadDeck(controlId);
mStage = STAGE_WAITING; mStage = STAGE_WAITING;
return; deckNum = controlId;
break;
} }
switch (controlId) switch (controlId)
@@ -709,9 +755,19 @@ void GameStateDeckViewer::ButtonPressed(int controllerId, int controlId)
mStage = STAGE_WAITING; mStage = STAGE_WAITING;
break; break;
case 12: case 12:
mParent->SetNextState(GAME_STATE_MENU); if(myDeck && myDeck->parent){
options.keypadStart(myDeck->parent->meta_name,&newDeckname);
options.keypadTitle("Rename deck");
}
break; break;
case 13: case 13:
updateDecks();
mStage = STAGE_WELCOME;
break;
case 14:
mParent->SetNextState(GAME_STATE_MENU);
break;
case 15:
mStage = STAGE_WAITING; mStage = STAGE_WAITING;
break; break;
case 20: case 20:
@@ -735,5 +791,4 @@ void GameStateDeckViewer::ButtonPressed(int controllerId, int controlId)
delSellMenu = 1; delSellMenu = 1;
break; break;
} }
} }

View File

@@ -139,12 +139,12 @@ void GameStateDuel::loadPlayerRandom(int playerId, int isAI, int mode){
void GameStateDuel::loadPlayerMomir(int playerId, int isAI){ void GameStateDuel::loadPlayerMomir(int playerId, int isAI){
string deckFileSmall = "momir"; string deckFileSmall = "momir";
char empty[] = ""; char empty[] = "";
MTGDeck * tempDeck = NEW MTGDeck(options.profileFile("momir.txt").c_str(), mParent->collection); MTGDeck * tempDeck = NEW MTGDeck(options.profileFile("momir.txt","",true).c_str(), mParent->collection);
deck[playerId] = NEW MTGPlayerCards(mParent->collection, tempDeck); deck[playerId] = NEW MTGPlayerCards(mParent->collection, tempDeck);
if (!isAI) // Human Player if (!isAI) // Human Player
mPlayers[playerId] = NEW HumanPlayer(deck[playerId], options.profileFile("momir.txt").c_str(), deckFileSmall); mPlayers[playerId] = NEW HumanPlayer(deck[playerId], options.profileFile("momir.txt","",true).c_str(), deckFileSmall);
else else
mPlayers[playerId] = NEW AIMomirPlayer(deck[playerId], options.profileFile("momir.txt").c_str(), deckFileSmall, empty); mPlayers[playerId] = NEW AIMomirPlayer(deck[playerId], options.profileFile("momir.txt","",true).c_str(), deckFileSmall, empty);
delete tempDeck; delete tempDeck;
} }

View File

@@ -231,7 +231,7 @@ void GameStateMenu::fillScroller(){
sprintf(buff2, _("You have unlocked %i expansions out of %i").c_str(),nbunlocked, MtgSets::SetsList->nb_items); sprintf(buff2, _("You have unlocked %i expansions out of %i").c_str(),nbunlocked, MtgSets::SetsList->nb_items);
scroller->Add(buff2); scroller->Add(buff2);
DeckDataWrapper* ddw = NEW DeckDataWrapper(NEW MTGDeck(options.profileFile(PLAYER_COLLECTION,"",false).c_str(), mParent->collection)); DeckDataWrapper* ddw = NEW DeckDataWrapper(NEW MTGDeck(options.profileFile(PLAYER_COLLECTION).c_str(), mParent->collection));
int totalCards = ddw->getCount(); int totalCards = ddw->getCount();
if (totalCards){ if (totalCards){
sprintf(buff2, _("You have a total of %i cards in your collection").c_str(),totalCards); sprintf(buff2, _("You have a total of %i cards in your collection").c_str(),totalCards);
@@ -319,7 +319,7 @@ void GameStateMenu::Update(float dt)
options[Options::ACTIVE_PROFILE].str = "Default"; options[Options::ACTIVE_PROFILE].str = "Default";
//check for deleted collection / first-timer //check for deleted collection / first-timer
std::ifstream file(options.profileFile(PLAYER_COLLECTION,"",false).c_str()); std::ifstream file(options.profileFile(PLAYER_COLLECTION).c_str());
if(file){ if(file){
file.close(); file.close();
resources.Release(mSplash); resources.Release(mSplash);

View File

@@ -23,7 +23,6 @@ void GameStateShop::Create(){
} }
void GameStateShop::Start() void GameStateShop::Start()
{ {
menu = NULL; menu = NULL;

View File

@@ -9,7 +9,7 @@ PlayerData::PlayerData(MTGAllCards * allcards){
//CREDITS //CREDITS
credits = 3000; //Default value credits = 3000; //Default value
std::ifstream file(options.profileFile(PLAYER_SAVEFILE,"",false).c_str()); std::ifstream file(options.profileFile(PLAYER_SAVEFILE).c_str());
std::string s; std::string s;
if(file){ if(file){
if(std::getline(file,s)){ if(std::getline(file,s)){
@@ -21,12 +21,12 @@ PlayerData::PlayerData(MTGAllCards * allcards){
} }
//COLLECTION //COLLECTION
collection = NEW MTGDeck(options.profileFile(PLAYER_COLLECTION,"",false).c_str(), allcards); collection = NEW MTGDeck(options.profileFile(PLAYER_COLLECTION).c_str(), allcards);
} }
int PlayerData::save(){ int PlayerData::save(){
std::ofstream file(options.profileFile(PLAYER_SAVEFILE,"",false).c_str()); std::ofstream file(options.profileFile(PLAYER_SAVEFILE).c_str());
char writer[64]; char writer[64];
if (file){ if (file){
sprintf(writer,"%i\n", credits); sprintf(writer,"%i\n", credits);

View File

@@ -1,410 +1,421 @@
#include "../include/config.h" #include "../include/config.h"
#include "../include/SimplePad.h" #include "../include/SimplePad.h"
#include "JTypes.h" #include "JTypes.h"
#include "../include/GameApp.h" #include "../include/GameApp.h"
#include "../include/Translate.h" #include "../include/Translate.h"
#define ALPHA_COLUMNS 8 #define ALPHA_COLUMNS 8
#define ALPHA_ROWS 8 #define ALPHA_ROWS 8
#define KPD_UP 0 #define KPD_UP 0
#define KPD_DOWN 1 #define KPD_DOWN 1
#define KPD_LEFT 2 #define KPD_LEFT 2
#define KPD_RIGHT 3 #define KPD_RIGHT 3
SimpleKey::SimpleKey( string _ds, int _id){ SimpleKey::SimpleKey( string _ds, int _id){
displayValue = _ds; id = _id; displayValue = _ds; id = _id;
for(int x=0;x<4;x++) for(int x=0;x<4;x++)
adjacency[x] = KPD_NOWHERE; adjacency[x] = KPD_NOWHERE;
} }
void SimplePad::linkKeys(int from, int to, int dir){ void SimplePad::linkKeys(int from, int to, int dir){
if(keys[from] && keys[to]){ if(keys[from] && keys[to]){
keys[from]->adjacency[dir] = to; keys[from]->adjacency[dir] = to;
switch(dir){ switch(dir){
case KPD_UP: case KPD_UP:
case KPD_LEFT: case KPD_LEFT:
dir++; dir++;
break; break;
default: default:
dir--; dir--;
} }
keys[to]->adjacency[dir] = from; keys[to]->adjacency[dir] = from;
} }
} }
SimplePad::SimplePad(){ SimplePad::SimplePad(){
nbitems = 0; nbitems = 0;
bActive = false; bActive = false;
selected = 0; selected = 0;
priorKey = 0; priorKey = 0;
cursor = 0; cursor = 0;
bShowCancel = false; bShowCancel = false;
bShowNumpad = false; bShowNumpad = false;
bCapslock = true; bCapslock = true;
char buf[2]; char buf[2];
buf[1] = '\0'; buf[1] = '\0';
SimpleKey * k; SimpleKey * k;
for(int x=0;x<KPD_MAX;x++) for(int x=0;x<KPD_MAX;x++)
keys[x] = NULL; keys[x] = NULL;
//Add the alphabet. We cheat a bit here. //Add the alphabet. We cheat a bit here.
for(int x='a';x<='z';x++) for(int x='a';x<='z';x++)
{ {
buf[0] = x; buf[0] = x;
k=Add(buf,x); k=Add(buf,x);
int idx = x-'a'; int idx = x-'a';
if(idx > KPD_A) if(idx > KPD_A)
k->adjacency[KPD_LEFT] = idx-1; k->adjacency[KPD_LEFT] = idx-1;
if(idx < KPD_Z) if(idx < KPD_Z)
k->adjacency[KPD_RIGHT] = idx+1; k->adjacency[KPD_RIGHT] = idx+1;
if(idx > ALPHA_COLUMNS) if(idx > ALPHA_COLUMNS)
k->adjacency[KPD_UP] = idx-1-ALPHA_COLUMNS; k->adjacency[KPD_UP] = idx-1-ALPHA_COLUMNS;
else else
k->adjacency[KPD_UP] = KPD_INPUT; k->adjacency[KPD_UP] = KPD_INPUT;
if(idx < 25-ALPHA_COLUMNS) if(idx < 25-ALPHA_COLUMNS)
k->adjacency[KPD_DOWN] = idx+1+ALPHA_COLUMNS; k->adjacency[KPD_DOWN] = idx+1+ALPHA_COLUMNS;
} }
Add("Spacebar",KPD_SPACE); Add("Spacebar",KPD_SPACE);
for(int x=25-ALPHA_COLUMNS;x<26;x++) for(int x=25-ALPHA_COLUMNS;x<26;x++)
keys[x]->adjacency[KPD_DOWN] = KPD_SPACE; keys[x]->adjacency[KPD_DOWN] = KPD_SPACE;
k=Add("Confirm",KPD_OK); k=Add("Confirm",KPD_OK);
keys[KPD_Z]->adjacency[KPD_RIGHT] = KPD_OK; keys[KPD_Z]->adjacency[KPD_RIGHT] = KPD_OK;
k->adjacency[KPD_UP] = KPD_CAPS; k->adjacency[KPD_UP] = KPD_CAPS;
k->adjacency[KPD_LEFT] = KPD_Z; k->adjacency[KPD_LEFT] = KPD_Z;
k->adjacency[KPD_DOWN] = KPD_CANCEL; k->adjacency[KPD_DOWN] = KPD_CANCEL;
k=Add("Cancel",KPD_CANCEL); k=Add("Cancel",KPD_CANCEL);
k->adjacency[KPD_UP] = KPD_OK; k->adjacency[KPD_UP] = KPD_OK;
k->adjacency[KPD_LEFT] = KPD_SPACE; k->adjacency[KPD_LEFT] = KPD_SPACE;
k=Add("Del",KPD_DEL); k=Add("Del",KPD_DEL);
keys[KPD_I]->adjacency[KPD_RIGHT] = KPD_DEL; keys[KPD_I]->adjacency[KPD_RIGHT] = KPD_DEL;
k->adjacency[KPD_UP] = KPD_9; k->adjacency[KPD_UP] = KPD_9;
k->adjacency[KPD_DOWN] = KPD_CAPS; k->adjacency[KPD_DOWN] = KPD_CAPS;
k->adjacency[KPD_LEFT] = KPD_I; k->adjacency[KPD_LEFT] = KPD_I;
k=Add("Caps",KPD_CAPS); k=Add("Caps",KPD_CAPS);
keys[KPD_R]->adjacency[KPD_RIGHT] = KPD_CAPS; keys[KPD_R]->adjacency[KPD_RIGHT] = KPD_CAPS;
keys[KPD_R]->adjacency[KPD_DOWN] = KPD_Z; keys[KPD_R]->adjacency[KPD_DOWN] = KPD_Z;
k->adjacency[KPD_UP] = KPD_DEL; k->adjacency[KPD_UP] = KPD_DEL;
k->adjacency[KPD_DOWN] = KPD_OK; k->adjacency[KPD_DOWN] = KPD_OK;
k->adjacency[KPD_LEFT] = KPD_R; k->adjacency[KPD_LEFT] = KPD_R;
for(int x=0;x<10;x++){ for(int x=0;x<10;x++){
buf[0] = '0'+x; buf[0] = '0'+x;
Add(buf,KPD_0+x); Add(buf,KPD_0+x);
if(x < 8) if(x < 8)
linkKeys(KPD_0+x,KPD_A+x,KPD_DOWN); linkKeys(KPD_0+x,KPD_A+x,KPD_DOWN);
if(x > 0) if(x > 0)
linkKeys(KPD_0+x,KPD_0+x-1,KPD_LEFT); linkKeys(KPD_0+x,KPD_0+x-1,KPD_LEFT);
} }
keys[KPD_8]->adjacency[KPD_DOWN] = KPD_DEL; keys[KPD_8]->adjacency[KPD_DOWN] = KPD_DEL;
keys[KPD_9]->adjacency[KPD_DOWN] = KPD_DEL; keys[KPD_9]->adjacency[KPD_DOWN] = KPD_DEL;
keys[KPD_0]->adjacency[KPD_LEFT] = KPD_NOWHERE; keys[KPD_0]->adjacency[KPD_LEFT] = KPD_NOWHERE;
keys[KPD_A]->adjacency[KPD_LEFT] = KPD_NOWHERE; keys[KPD_A]->adjacency[KPD_LEFT] = KPD_NOWHERE;
keys[KPD_J]->adjacency[KPD_LEFT] = KPD_NOWHERE; keys[KPD_J]->adjacency[KPD_LEFT] = KPD_NOWHERE;
keys[KPD_S]->adjacency[KPD_LEFT] = KPD_NOWHERE; keys[KPD_S]->adjacency[KPD_LEFT] = KPD_NOWHERE;
} }
SimplePad::~SimplePad() SimplePad::~SimplePad()
{ {
for(int x=0;x<KPD_MAX;x++) for(int x=0;x<KPD_MAX;x++)
SAFE_DELETE(keys[x]); SAFE_DELETE(keys[x]);
} }
SimpleKey * SimplePad::Add(string display, unsigned char id){ SimpleKey * SimplePad::Add(string display, unsigned char id){
if(nbitems >= KPD_MAX) if(nbitems >= KPD_MAX)
return NULL; return NULL;
keys[nbitems++] = NEW SimpleKey(display,id); keys[nbitems++] = NEW SimpleKey(display,id);
return keys[nbitems-1]; return keys[nbitems-1];
} }
void SimplePad::pressKey(unsigned char key){ void SimplePad::pressKey(unsigned char key){
string input = ""; string input = "";
if(isalpha(key)) { if(isalpha(key)) {
if(bCapslock) if(bCapslock)
input += toupper(key); input += toupper(key);
else else
input += key; input += key;
if(cursor < buffer.size()) if(cursor < buffer.size())
cursor++; cursor++;
buffer.insert(cursor,input); buffer.insert(cursor,input);
} }
else if(key == KPD_CAPS) else if(key == KPD_CAPS)
bCapslock = !bCapslock; bCapslock = !bCapslock;
else if(key == KPD_DEL) { else if(key == KPD_DEL) {
if(!buffer.size()) if(!buffer.size())
return; return;
if(cursor >= buffer.size()) { if(cursor >= buffer.size()) {
cursor = buffer.size(); cursor = buffer.size();
buffer = buffer.substr(0,cursor-1); buffer = buffer.substr(0,cursor-1);
} }
else else
buffer = buffer.substr(0,cursor) + buffer.substr(cursor+1); buffer = buffer.substr(0,cursor) + buffer.substr(cursor+1);
cursor--; cursor--;
} }
else if(key == KPD_OK) else if(key == KPD_OK)
Finish(); Finish();
else if(key == KPD_CANCEL) { else if(key == KPD_CANCEL) {
bCanceled = true; bCanceled = true;
Finish(); Finish();
} }
} }
void SimplePad::MoveSelection(unsigned char moveto) void SimplePad::MoveSelection(unsigned char moveto)
{ {
if(!bShowNumpad && moveto >= KPD_0 && moveto <= KPD_9 ) if(!bShowNumpad && moveto >= KPD_0 && moveto <= KPD_9 )
moveto = KPD_INPUT; moveto = KPD_INPUT;
else if(!bShowCancel && moveto == KPD_CANCEL ) else if(!bShowCancel && moveto == KPD_CANCEL )
moveto = KPD_SPACE; moveto = KPD_SPACE;
if(selected < KPD_MAX && selected >= 0) if(selected < KPD_MAX && selected >= 0)
priorKey = selected; priorKey = selected;
if(moveto < KPD_MAX) { if(moveto < KPD_MAX) {
selected = moveto; selected = moveto;
} }
else if(moveto == KPD_INPUT) else if(moveto == KPD_INPUT)
selected = KPD_INPUT; selected = KPD_INPUT;
} }
void SimplePad::Update(float dt){ void SimplePad::Update(float dt){
JGE * mEngine = JGE::GetInstance(); JGE * mEngine = JGE::GetInstance();
//We can always confirm! //Start button changes capslock setting.
if(mEngine->GetButtonClick(PSP_CTRL_START)) if(mEngine->GetButtonClick(PSP_CTRL_START))
{ {
if(selected != KPD_OK) if(selected != KPD_OK)
selected = KPD_OK; selected = KPD_OK;
else else
Finish(); Finish();
return; }
} else if(mEngine->GetButtonClick(PSP_CTRL_SELECT)){
bCapslock = !bCapslock;
if(selected == KPD_SPACE){ }
if(bShowCancel && mEngine->GetButtonClick(PSP_CTRL_RIGHT))
selected = KPD_CANCEL; if(selected == KPD_SPACE){
else if (mEngine->GetButtonClick(PSP_CTRL_LEFT)||mEngine->GetButtonClick(PSP_CTRL_RIGHT) if(bShowCancel && mEngine->GetButtonClick(PSP_CTRL_RIGHT))
||mEngine->GetButtonClick(PSP_CTRL_UP)||mEngine->GetButtonClick(PSP_CTRL_DOWN)) selected = KPD_CANCEL;
selected = priorKey; else if (mEngine->GetButtonClick(PSP_CTRL_LEFT)||mEngine->GetButtonClick(PSP_CTRL_RIGHT)
} //Moving within/from the text field. ||mEngine->GetButtonClick(PSP_CTRL_UP)||mEngine->GetButtonClick(PSP_CTRL_DOWN))
else if(selected == KPD_INPUT){ selected = priorKey;
if (mEngine->GetButtonClick(PSP_CTRL_DOWN) ) } //Moving within/from the text field.
selected = priorKey; else if(selected == KPD_INPUT){
if (mEngine->GetButtonClick(PSP_CTRL_LEFT)){ if (mEngine->GetButtonClick(PSP_CTRL_DOWN) )
if(cursor > 0) selected = priorKey;
cursor--; if (mEngine->GetButtonClick(PSP_CTRL_LEFT)){
} if(cursor > 0)
else if (mEngine->GetButtonClick(PSP_CTRL_RIGHT)){ cursor--;
if(cursor < buffer.size()) }
cursor++; else if (mEngine->GetButtonClick(PSP_CTRL_RIGHT)){
} if(cursor < buffer.size())
} cursor++;
else if(selected >= 0 && keys[selected]){ }
if (mEngine->GetButtonClick(PSP_CTRL_LEFT)) }
MoveSelection(keys[selected]->adjacency[KPD_LEFT]); else if(selected >= 0 && keys[selected]){
else if (mEngine->GetButtonClick(PSP_CTRL_RIGHT)) if (mEngine->GetButtonClick(PSP_CTRL_LEFT))
MoveSelection(keys[selected]->adjacency[KPD_RIGHT]); MoveSelection(keys[selected]->adjacency[KPD_LEFT]);
if (mEngine->GetButtonClick(PSP_CTRL_DOWN)) else if (mEngine->GetButtonClick(PSP_CTRL_RIGHT))
MoveSelection(keys[selected]->adjacency[KPD_DOWN]); MoveSelection(keys[selected]->adjacency[KPD_RIGHT]);
else if (mEngine->GetButtonClick(PSP_CTRL_UP)) if (mEngine->GetButtonClick(PSP_CTRL_DOWN))
MoveSelection(keys[selected]->adjacency[KPD_UP]); MoveSelection(keys[selected]->adjacency[KPD_DOWN]);
} else if (mEngine->GetButtonClick(PSP_CTRL_UP))
MoveSelection(keys[selected]->adjacency[KPD_UP]);
}
//These bits require a valid key...
if(selected >= 0 && selected < nbitems && keys[selected]){
if (mEngine->GetButtonClick(PSP_CTRL_CIRCLE)) //These bits require a valid key...
pressKey(keys[selected]->id); if(selected >= 0 && selected < nbitems && keys[selected]){
} if (mEngine->GetButtonClick(PSP_CTRL_CIRCLE))
if (buffer.size() > 0 && mEngine->GetButtonClick(PSP_CTRL_CROSS)) pressKey(keys[selected]->id);
buffer = buffer.substr(0,buffer.size() - 1); }
if (buffer.size() && mEngine->GetButtonClick(PSP_CTRL_LTRIGGER)){ if (buffer.size() > 0 && mEngine->GetButtonClick(PSP_CTRL_CROSS))
if(cursor > 0) buffer = buffer.substr(0,buffer.size() - 1);
cursor--; if (buffer.size() && mEngine->GetButtonClick(PSP_CTRL_LTRIGGER)){
} if(cursor > 0)
else if (mEngine->GetButtonClick(PSP_CTRL_RTRIGGER)){ cursor--;
if(cursor < buffer.size()) }
cursor++; else if (mEngine->GetButtonClick(PSP_CTRL_RTRIGGER)){
else{ if(cursor < buffer.size())
buffer += ' '; cursor++;
cursor = buffer.size(); else{
} buffer += ' ';
} cursor = buffer.size();
}
mX = 50; }
mY = 50;
mX = 50;
} mY = 50;
void SimplePad::Start(string value, string * _dest) {
bActive = true; //Clear input buffer.
bCanceled=false; mEngine->ResetInput();
buffer = value; }
original = buffer; void SimplePad::Start(string value, string * _dest) {
dest = _dest; bActive = true;
cursor = buffer.size(); bCanceled=false;
} buffer = value;
original = buffer;
string SimplePad::Finish() { dest = _dest;
bActive = false; cursor = buffer.size();
if(bCanceled){ //Clear input buffer.
dest = NULL; JGE * mEngine = JGE::GetInstance();
return original; mEngine->ResetInput();
} }
if(dest != NULL){
dest->clear(); dest->insert(0,buffer); string SimplePad::Finish() {
dest = NULL; bActive = false;
}
return buffer; //Clear input buffer.
} JGE * mEngine = JGE::GetInstance();
mEngine->ResetInput();
void SimplePad::Render(){
//This could use some cleaning up to make margins more explicit //Return result.
JLBFont * mFont = resources.GetJLBFont("f3"); if(bCanceled){
dest = NULL;
int offX = 0, offY = 0; return original;
int kH = mFont->GetHeight(); }
int hSpacing = mFont->GetStringWidth("W"); if(dest != NULL){
int rowLen = mFont->GetStringWidth("JKLMNOPQR") + 14*7; dest->clear(); dest->insert(0,buffer);
int vSpacing = 0; dest = NULL;
int kW = hSpacing; }
return buffer;
JRenderer * renderer = JRenderer::GetInstance(); }
void SimplePad::Render(){
if(title != "") //This could use some cleaning up to make margins more explicit
vSpacing = kH+8; JLBFont * mFont = resources.GetJLBFont("f3");
else
vSpacing = 0; int offX = 0, offY = 0;
int kH = mFont->GetHeight();
offY = vSpacing; int hSpacing = mFont->GetStringWidth("W");
if(bShowNumpad) int rowLen = mFont->GetStringWidth("JKLMNOPQR") + 14*7;
offY += kH+14; int vSpacing = 0;
//Draw Keypad Background. int kW = hSpacing;
renderer->FillRoundRect(mX-kW,mY-kH,(kW+12)*11,(kH+14)*5+offY,2,options[Metrics::POPUP_MENU_FC].asColor(ARGB(180,0,0,0)));
offY = vSpacing; JRenderer * renderer = JRenderer::GetInstance();
//Draw text entry bubble
renderer->FillRoundRect(mX-kW/2,mY+offY,(kW+12)*9+kW/2,kH,2,options[Metrics::KEYPAD_FCH].asColor(ARGB(255,255,255,255)));
vSpacing = kH+8;
//Draw text-entry title, if we've got one.
if(title != ""){
mFont->DrawString(title.c_str(),mX,mY); offY = vSpacing;
mY+=kH+12; if(bShowNumpad)
} offY += kH+14;
//Draw Keypad Background.
//Draw cursor. renderer->FillRoundRect(mX-kW,mY-kH,(kW+12)*11,(kH+14)*5+offY,2,options[Metrics::POPUP_MENU_FC].asColor(ARGB(180,0,0,0)));
if(cursor < buffer.size()) offY = vSpacing;
{ //Draw text entry bubble
kW = mFont->GetStringWidth(buffer.substr(cursor,1).c_str()); renderer->FillRoundRect(mX-kW/2,mY+offY,(kW+12)*9+kW/2,kH,2,options[Metrics::KEYPAD_FCH].asColor(ARGB(255,255,255,255)));
renderer->FillRoundRect(mX+mFont->GetStringWidth(buffer.substr(0,cursor).c_str()),mY+kH-4,
kW,4,2,options[Metrics::KEY_FCH].asColor(ARGB(150,150,150,0))); //Draw text-entry title, if we've got one.
} if(title != ""){
else mFont->DrawString(title.c_str(),mX,mY);
{ }
cursor = buffer.size(); mY+=kH+12;
renderer->FillRoundRect(mX+mFont->GetStringWidth(buffer.substr(0,cursor).c_str()),mY+kH-4,
kW,4,2,options[Metrics::KEY_FCH].asColor(ARGB(150,150,150,0))); //Draw cursor.
} if(cursor < buffer.size())
{
mFont->SetColor(options[Metrics::KEYPAD_TC].asColor(ARGB(255,0,0,0))); kW = mFont->GetStringWidth(buffer.substr(cursor,1).c_str());
mFont->DrawString(buffer.c_str(),mX,mY); renderer->FillRoundRect(mX+mFont->GetStringWidth(buffer.substr(0,cursor).c_str()),mY+kH-4,
offY += kH + 12; kW,4,2,options[Metrics::KEY_FCH].asColor(ARGB(150,150,150,0)));
}
if(!bShowNumpad) else
vSpacing -= kH + 12; {
cursor = buffer.size();
for(int x=0;x<nbitems;x++) renderer->FillRoundRect(mX+mFont->GetStringWidth(buffer.substr(0,cursor).c_str()),mY+kH-4,
if(keys[x]){ kW,4,2,options[Metrics::KEY_FCH].asColor(ARGB(150,150,150,0)));
}
if((x == KPD_CANCEL && !bShowCancel) || (x >= KPD_0 && x <= KPD_9 && !bShowNumpad))
continue; mFont->SetColor(options[Metrics::KEYPAD_TC].asColor(ARGB(255,0,0,0)));
mFont->DrawString(buffer.c_str(),mX,mY);
switch(x){ offY += kH + 12;
case KPD_0:
offX = 0; if(!bShowNumpad)
offY = vSpacing; vSpacing -= kH + 12;
break;
case KPD_A: for(int x=0;x<nbitems;x++)
offX = 0; if(keys[x]){
offY = vSpacing+(kH+12)*1;
break; if((x == KPD_CANCEL && !bShowCancel) || (x >= KPD_0 && x <= KPD_9 && !bShowNumpad))
case KPD_J: continue;
offX = 0;
offY = vSpacing+(kH+12)*2; switch(x){
break; case KPD_0:
case KPD_S: offX = 0;
offX = 0; offY = vSpacing;
offY = vSpacing+(kH+12)*3; break;
break; case KPD_A:
case KPD_SPACE: offX = 0;
offX = 0; offY = vSpacing+(kH+12)*1;
offY = vSpacing+(kH+12)*4; break;
break; case KPD_J:
case KPD_OK: offX = 0;
offX = rowLen + hSpacing; offY = vSpacing+(kH+12)*2;
offY = vSpacing+(kH+12)*3; break;
break; case KPD_S:
case KPD_CANCEL: offX = 0;
offX = rowLen + hSpacing; offY = vSpacing+(kH+12)*3;
offY = vSpacing+(kH+12)*4; break;
break; case KPD_SPACE:
case KPD_DEL: offX = 0;
offX = rowLen + hSpacing; offY = vSpacing+(kH+12)*4;
offY = vSpacing+(kH+12)*1; break;
break; case KPD_OK:
case KPD_CAPS: offX = rowLen + hSpacing;
offX = rowLen + hSpacing; offY = vSpacing+(kH+12)*3;
offY = vSpacing+(kH+12)*2; break;
break; case KPD_CANCEL:
} offX = rowLen + hSpacing;
offY = vSpacing+(kH+12)*4;
kW = mFont->GetStringWidth(keys[x]->displayValue.c_str()); break;
//Render a key. case KPD_DEL:
if(x != selected){ offX = rowLen + hSpacing;
renderer->FillRoundRect(mX+offX-4,mY+offY-4,kW+8,kH+4,2,options[Metrics::POPUP_MENU_FC].asColor(ARGB(180,50,50,50))); offY = vSpacing+(kH+12)*1;
mFont->SetColor(options[Metrics::POPUP_MENU_TCH].asColor(ARGB(255,255,255,0))); break;
} case KPD_CAPS:
else{ offX = rowLen + hSpacing;
renderer->FillRoundRect(mX+offX-4,mY+offY-4,kW+8,kH+4,2,options[Metrics::POPUP_MENU_FC].asColor(ARGB(255,100,100,100))); offY = vSpacing+(kH+12)*2;
mFont->SetColor(options[Metrics::POPUP_MENU_TC].asColor(ARGB(255,255,255,255))); break;
} }
char vkey[2]; kW = mFont->GetStringWidth(keys[x]->displayValue.c_str());
vkey[1] = '\0'; //Render a key.
vkey[0] = keys[x]->id; if(x != selected){
renderer->FillRoundRect(mX+offX-4,mY+offY-4,kW+8,kH+4,2,options[Metrics::POPUP_MENU_FC].asColor(ARGB(180,50,50,50)));
mFont->SetColor(options[Metrics::POPUP_MENU_TCH].asColor(ARGB(255,255,255,0)));
if(isalpha(vkey[0])) { }
if(bCapslock) vkey[0] = toupper(vkey[0]); else{
mFont->DrawString(vkey,mX+offX,mY+offY); renderer->FillRoundRect(mX+offX-4,mY+offY-4,kW+8,kH+4,2,options[Metrics::POPUP_MENU_FC].asColor(ARGB(255,100,100,100)));
} mFont->SetColor(options[Metrics::POPUP_MENU_TC].asColor(ARGB(255,255,255,255)));
else }
mFont->DrawString(keys[x]->displayValue.c_str(),mX+offX,mY+offY);
offX += kW + 14; char vkey[2];
} vkey[1] = '\0';
} vkey[0] = keys[x]->id;
unsigned int SimplePad::cursorPos(){
if(cursor > buffer.size()) if(isalpha(vkey[0])) {
return buffer.size(); if(bCapslock) vkey[0] = toupper(vkey[0]);
mFont->DrawString(vkey,mX+offX,mY+offY);
return cursor; }
} else
mFont->DrawString(keys[x]->displayValue.c_str(),mX+offX,mY+offY);
offX += kW + 14;
}
}
unsigned int SimplePad::cursorPos(){
if(cursor > buffer.size())
return buffer.size();
return cursor;
}