* Create the subsystem for keybindings.
This commit is contained in:
jean.chalard
2010-02-14 13:21:12 +00:00
parent 4913eec2fb
commit 56ce4a14ae
38 changed files with 2154 additions and 1477 deletions
+4 -1
View File
@@ -2,7 +2,10 @@
#define _DUELLAYERS_H_
#include "GuiLayers.h"
#include "CardSelector.h"
#include "PlayGuiObject.h"
template <typename T> class ObjectSelector;
typedef ObjectSelector<PlayGuiObject> CardSelector;
class MTGGuiHand;
class MTGGuiPlay;
+6 -1
View File
@@ -45,6 +45,7 @@ public:
ECON_DIFFICULTY,
TRANSITIONS,
INTERRUPT_SECONDS,
KEY_BINDINGS,
//My interrupts
INTERRUPTMYSPELLS,
INTERRUPTMYABILITIES,
@@ -80,7 +81,7 @@ public:
static string getName(int option);
private:
static const char* optionNames[];
static const string optionNames[];
};
class GameOption {
@@ -130,6 +131,10 @@ private:
bool viewed; //Flag it as "New!" or not.
};
class GameOptionKeyBindings : public GameOption {
virtual bool read(string input);
};
class OptionVolume: public EnumDefinition{
public:
enum { MUTE = 0, MAX = 100 };
+2 -2
View File
@@ -58,7 +58,7 @@ class OptionSelect:public OptionItem{
virtual void Reload(){initSelections();};
virtual void Render();
virtual bool Selectable();
virtual void Entering(u32 key);
virtual void Entering(JButton key);
virtual bool Changed() {return (value != prior_value);};
virtual void setData();
virtual void initSelections();
@@ -118,7 +118,7 @@ class OptionProfile:public OptionDirectory{
virtual void addSelection(string s);
virtual bool Selectable() {return canSelect;};
virtual bool Changed() {return (initialValue != value);};
virtual void Entering(u32 key);
virtual void Entering(JButton key);
virtual void Reload();
virtual void Render();
virtual void confirmChange(bool confirmed);
+93
View File
@@ -0,0 +1,93 @@
#ifndef _SHOP_ITEM_H
#define _SHOP_ITEM_H
#include <JGui.h>
#include <JLBFont.h>
#include "SimpleMenu.h"
#include "MTGDeck.h"
#include "../include/PriceList.h"
#include "../include/PlayerData.h"
#include "../include/CardDisplay.h"
#include "../include/DeckDataWrapper.h"
#include <string>
using std::string;
class hgeDistortionMesh;
#define SHOP_BOOSTERS 3
class ShopItem:public JGuiObject{
private:
friend class ShopItems;
bool mHasFocus;
bool mRelease;
JLBFont *mFont;
string mText;
float xy[8];
JQuad * quad;
JQuad * thumb;
float mScale;
float mTargetScale;
hgeDistortionMesh* mesh;
void updateThumb();
public:
int nameCount;
int quantity;
MTGCard * card;
int price;
ShopItem(int id, JLBFont * font, int _cardid, float _xy[], bool hasFocus, MTGAllCards * collection, int _price, DeckDataWrapper * ddw);
ShopItem(int id, JLBFont * font, char* text, JQuad * _quad, JQuad * _thumb,float _xy[], bool hasFocus, int _price);
~ShopItem();
int updateCount(DeckDataWrapper * ddw);
virtual void Render();
virtual void Update(float dt);
virtual void Entering();
virtual bool Leaving(JButton key);
virtual bool ButtonPressed();
const char * getText();
virtual ostream& toString(ostream& out) const;
};
class ShopItems:public JGuiController,public JGuiListener{
private:
PlayerData * playerdata;
PriceList * pricelist;
int mX, mY, mHeight;
JLBFont* mFont;
JTexture * mBgAATex;
JQuad * mBgAA;
MTGAllCards * collection;
SimpleMenu * dialog;
int showPriceDialog;
int setIds[SHOP_BOOSTERS];
MTGCardInstance * displayCards[100];
CardDisplay * display;
void safeDeleteDisplay();
DeckDataWrapper * myCollection;
int lightAlpha;
int alphaChange;
public:
bool showCardList;
ShopItems(int id, JGuiListener* listener, JLBFont* font, int x, int y, MTGAllCards * _collection, int _setIds[]);
~ShopItems();
void Render();
virtual void Update(float dt);
void Add(int cardid);
void Add(char * text, JQuad * quad, JQuad * thumb,int _price);
void pricedialog(int id, int mode=1);
virtual void ButtonPressed(int controllerId, int controlId);
bool CheckUserInput(JButton key);
void savePriceList();
void saveAll();
static float _x1[],_y1[],_x2[],_y2[],_x3[],_y3[],_x4[],_y4[];
};
#endif
+27 -27
View File
@@ -46,8 +46,8 @@ public:
virtual PIXEL_TYPE getColor(int type);
virtual float getMargin(int type) {return 4;};
virtual void Entering(u32 key)=0;
virtual bool Leaving(u32 key)=0;
virtual void Entering(JButton key)=0;
virtual bool Leaving(JButton key)=0;
virtual void Update(float dt)=0;
virtual void updateValue(){};
@@ -82,15 +82,15 @@ public:
virtual void renderBack(WGuiBase * it);
virtual void subBack(WGuiBase * item) {};
virtual bool CheckUserInput(u32 key) {return false;};
virtual bool CheckUserInput(JButton key) {return false;};
};
//This is our base class for concrete items.
class WGuiItem: public WGuiBase{
public:
virtual void Entering(u32 key);
virtual bool Leaving(u32 key);
virtual bool CheckUserInput(u32 key);
virtual void Entering(JButton key);
virtual bool Leaving(JButton key);
virtual bool CheckUserInput(JButton key);
virtual void Update(float dt) {};
virtual void Render();
@@ -177,8 +177,8 @@ public:
virtual bool Changed() {return it->Changed();};
virtual void confirmChange(bool confirmed) {it->confirmChange(confirmed);};
virtual void Entering(u32 key) {it->Entering(key);};
virtual bool Leaving(u32 key) {return it->Leaving(key);};
virtual void Entering(JButton key) {it->Entering(key);};
virtual bool Leaving(JButton key) {return it->Leaving(key);};
virtual void Update(float dt) {it->Update(dt);};
virtual void updateValue() {it->updateValue();};
virtual void Reload() {it->Reload();};
@@ -208,7 +208,7 @@ public:
virtual void setHeight(float _h) {it->setHeight(_h);};
virtual void setHidden(bool bHidden) {it->setHidden(bHidden);};
virtual void setVisible(bool bVisisble) {it->setVisible(bVisisble);};
virtual bool CheckUserInput(u32 key) {return it->CheckUserInput(key);};
virtual bool CheckUserInput(JButton key) {return it->CheckUserInput(key);};
protected:
WGuiBase * it;
};
@@ -251,9 +251,9 @@ public:
virtual void ButtonPressed(int controllerId, int controlId);
virtual void confirmChange(bool confirmed);
virtual void Entering(u32 key);
virtual bool Leaving(u32 key);
virtual bool CheckUserInput(u32 key);
virtual void Entering(JButton key);
virtual bool Leaving(JButton key);
virtual bool CheckUserInput(JButton key);
bool bRight;
float percentRight;
@@ -269,12 +269,12 @@ public:
virtual bool isModal();
virtual void setData();
virtual void setModal(bool val);
virtual void Entering(u32 key);
virtual bool Leaving(u32 key);
virtual void Entering(JButton key);
virtual bool Leaving(JButton key);
virtual void Update(float dt);
virtual void Overlay();
virtual void ButtonPressed(int controllerId, int controlId);
virtual bool CheckUserInput(u32 key);
virtual bool CheckUserInput(JButton key);
string confirm;
string cancel;
@@ -312,7 +312,7 @@ class WGuiButton: public WGuiDeco{
public:
WGuiButton( WGuiBase* _it, int _controller, int _control, JGuiListener * jgl);
virtual void updateValue();
virtual bool CheckUserInput(u32 key);
virtual bool CheckUserInput(JButton key);
virtual bool Selectable() {return Visible();};
virtual PIXEL_TYPE getColor(int type);
virtual int getControlID() {return control;};
@@ -350,7 +350,7 @@ class WGuiMenu: public WGuiItem{
public:
friend class WGuiFilters;
virtual ~WGuiMenu();
WGuiMenu(u32 next, u32 prev, bool mDPad = false, WSyncable * syncme=NULL);
WGuiMenu(JButton next, JButton prev, bool mDPad = false, WSyncable * syncme=NULL);
virtual void Render();
virtual void Reload();
@@ -358,10 +358,10 @@ public:
virtual void ButtonPressed(int controllerId, int controlId);
virtual void Add(WGuiBase* item); //Remember, does not set X & Y of items automatically.
virtual void confirmChange(bool confirmed);
virtual bool Leaving(u32 key);
virtual void Entering(u32 key);
virtual bool Leaving(JButton key);
virtual void Entering(JButton key);
virtual void subBack(WGuiBase * item);
virtual bool CheckUserInput(u32 key);
virtual bool CheckUserInput(JButton key);
WGuiBase * Current();
virtual int getSelected() {return currentItem;};
virtual bool nextItem();
@@ -373,12 +373,12 @@ public:
protected:
virtual void syncMove();
virtual bool isButtonDir(u32 key, int dir); //For the DPad override.
u32 buttonNext, buttonPrev;
virtual bool isButtonDir(JButton key, int dir); //For the DPad override.
JButton buttonNext, buttonPrev;
bool mDPad;
vector<WGuiBase*> items;
int currentItem;
u32 held;
JButton held;
WSyncable * sync;
float duration;
};
@@ -399,7 +399,7 @@ protected:
};
class WGuiTabMenu: public WGuiMenu {
public:
WGuiTabMenu() : WGuiMenu(PSP_CTRL_RTRIGGER,PSP_CTRL_LTRIGGER) {};
WGuiTabMenu() : WGuiMenu(JGE_BTN_NEXT, JGE_BTN_PREV) {};
virtual void Render();
virtual void Add(WGuiBase * it);
void save();
@@ -415,11 +415,11 @@ public:
friend class WGuiFilterItem;
WGuiFilters(string header, WSrcCards * src);
~WGuiFilters();
bool CheckUserInput(u32 key);
bool CheckUserInput(JButton key);
string getCode(); //For use in filter factory.
void Update(float dt);
void Render();
void Entering(u32 key);
void Entering(JButton key);
void addColumn();
bool isAvailable(int type);
bool isAvailableCode(string code);
@@ -484,4 +484,4 @@ struct WLFiltersSort{
bool operator()(const WGuiBase*l, const WGuiBase*r);
};
#endif
#endif
+1 -1
View File
@@ -52,7 +52,7 @@ int ActionLayer::reactToTargetClick(ActionElement* ability, Targetable * card){
bool ActionLayer::CheckUserInput(u32 key){
GameObserver * g = GameObserver::GetInstance();
if (g->waitForExtraPayment && key == PSP_CTRL_CROSS){
if (g->waitForExtraPayment && key == JGE_BTN_SEC){
g->waitForExtraPayment = NULL;
return 1;
}
+12 -12
View File
@@ -538,7 +538,7 @@ void ActionStack::Update(float dt){
for (int i = 0; i < mCount ; i++){
Interruptible * current = (Interruptible *)mObjects[i];
if (tc->canTarget(current)){
if (mObjects[mCurr]) mObjects[mCurr]->Leaving(PSP_CTRL_UP);
if (mObjects[mCurr]) mObjects[mCurr]->Leaving(JGE_BTN_UP);
current->display = 1;
mCurr = i;
mObjects[mCurr]->Entering();
@@ -621,32 +621,32 @@ void ActionStack::endOfInterruption(){
bool ActionStack::CheckUserInput(u32 key){
u32 trigger = (options[Options::REVERSETRIGGERS].number ? PSP_CTRL_RTRIGGER : PSP_CTRL_LTRIGGER);
u32 trigger = (options[Options::REVERSETRIGGERS].number ? JGE_BTN_NEXT : JGE_BTN_PREV);
if (mode == ACTIONSTACK_STANDARD){
if (askIfWishesToInterrupt){
if (PSP_CTRL_CROSS == key){
if (JGE_BTN_SEC == key){
setIsInterrupting(askIfWishesToInterrupt);
return true;
}else if ((PSP_CTRL_CIRCLE == key) || (trigger == key) ){
}else if ((JGE_BTN_OK == key) || (trigger == key) ){
cancelInterruptOffer();
return true;
}else if ((PSP_CTRL_SQUARE == key)){
}else if ((JGE_BTN_PRI == key)){
cancelInterruptOffer(2);
return true;
}
return true;
}else if (game->isInterrupting){
if (PSP_CTRL_CROSS == key){
if (JGE_BTN_SEC == key){
endOfInterruption();
return true;
}
}
}else if (mode == ACTIONSTACK_TARGET){
if (modal){
if (PSP_CTRL_UP == key){
if (JGE_BTN_UP == key){
if( mObjects[mCurr]){
int n = getPreviousIndex(((Interruptible *) mObjects[mCurr]), 0, 0, 1);
if (n != -1 && n != mCurr && mObjects[mCurr]->Leaving(PSP_CTRL_UP)){
if (n != -1 && n != mCurr && mObjects[mCurr]->Leaving(JGE_BTN_UP)){
mCurr = n;
mObjects[mCurr]->Entering();
#if defined (WIN32) || defined (LINUX)
@@ -657,10 +657,10 @@ bool ActionStack::CheckUserInput(u32 key){
}
}
return true;
}else if (PSP_CTRL_DOWN == key){
}else if (JGE_BTN_DOWN == key){
if( mObjects[mCurr]){
int n = getNextIndex(((Interruptible *) mObjects[mCurr]), 0, 0, 1);
if (n!= -1 && n != mCurr && mObjects[mCurr]->Leaving(PSP_CTRL_DOWN)){
if (n!= -1 && n != mCurr && mObjects[mCurr]->Leaving(JGE_BTN_DOWN)){
mCurr = n;
mObjects[mCurr]->Entering();
#if defined (WIN32) || defined (LINUX)
@@ -671,7 +671,7 @@ bool ActionStack::CheckUserInput(u32 key){
}
}
return true;
}else if (PSP_CTRL_CIRCLE == key){
}else if (JGE_BTN_OK == key){
#if defined (WIN32) || defined (LINUX)
char buf[4096];
sprintf(buf, "ACTIONSTACK CLIKED mCurr = %i\n", mCurr);
@@ -682,7 +682,7 @@ bool ActionStack::CheckUserInput(u32 key){
}
return true; //Steal the input to other layers if we're visible
}
if (PSP_CTRL_TRIANGLE == key){
if (JGE_BTN_CANCEL == key){
if (modal) modal = 0; else modal = 1;
return true;
}
+5 -5
View File
@@ -78,7 +78,7 @@ void CardDisplay::Update(float dt){
}
bool CardDisplay::CheckUserInput(u32 key){
if (PSP_CTRL_CROSS == key)
if (JGE_BTN_SEC == key)
{
if (listener){
listener->ButtonPressed(mId, 0);
@@ -108,7 +108,7 @@ bool CardDisplay::CheckUserInput(u32 key){
switch(key)
{
case PSP_CTRL_LEFT :
case JGE_BTN_LEFT :
{
int n = mCurr;
n--;
@@ -116,13 +116,13 @@ bool CardDisplay::CheckUserInput(u32 key){
if (n< 0){n = 0;}
else{ rotateLeft();}
}
if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(PSP_CTRL_LEFT)){
if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(JGE_BTN_LEFT)){
mCurr = n;
mObjects[mCurr]->Entering();
}
return true;
}
case PSP_CTRL_RIGHT :
case JGE_BTN_RIGHT :
{
int n = mCurr;
n++;
@@ -130,7 +130,7 @@ bool CardDisplay::CheckUserInput(u32 key){
if (n>= start_item + nb_displayed_items){
rotateRight();
}
if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(PSP_CTRL_RIGHT)){
if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(JGE_BTN_RIGHT)){
mCurr = n;
mObjects[mCurr]->Entering();
}
+14 -13
View File
@@ -8,8 +8,9 @@
using std::cout;
#ifdef True
#undef True
#endif
struct Left : public Exp { static inline bool test(CardSelector::Target* ref, CardSelector::Target* test)
{ return ref->x - test->x > fabs(ref->y - test->y); } };
@@ -119,26 +120,26 @@ bool CardSelector::CheckUserInput(u32 key)
Target* oldactive = active;
switch (key)
{
case PSP_CTRL_CROSS:
case JGE_BTN_SEC:
GameObserver::GetInstance()->cancelCurrentAction();
return true;
case PSP_CTRL_CIRCLE:
case JGE_BTN_OK:
GameObserver::GetInstance()->ButtonPressed(active);
return true;
break;
case PSP_CTRL_LEFT:
case JGE_BTN_LEFT:
active = closest<Left>(cards, limitor, active);
break;
case PSP_CTRL_RIGHT:
case JGE_BTN_RIGHT:
active = closest<Right>(cards, limitor, active);
break;
case PSP_CTRL_UP:
case JGE_BTN_UP:
active = closest<Up>(cards, limitor, active);
break;
case PSP_CTRL_DOWN:
case JGE_BTN_DOWN:
active = closest<Down>(cards, limitor, active);
break;
case PSP_CTRL_TRIANGLE:
case JGE_BTN_CANCEL:
bigMode = (bigMode+1) % NB_BIG_MODES;
if(bigMode == BIG_MODE_TEXT)
options[Options::DISABLECARDS].number = 1;
@@ -160,10 +161,10 @@ bool CardSelector::CheckUserInput(u32 key)
if (PlayGuiObject* old = fetchMemory(lasts[owner]))
switch (key)
{
case PSP_CTRL_LEFT: if (old->x < oldactive->x) active = old; break;
case PSP_CTRL_RIGHT: if (old->x > oldactive->x) active = old; break;
case PSP_CTRL_UP: if (old->y < oldactive->y) active = old; break;
case PSP_CTRL_DOWN: if (old->y > oldactive->y) active = old; break;
case JGE_BTN_LEFT: if (old->x < oldactive->x) active = old; break;
case JGE_BTN_RIGHT: if (old->x > oldactive->x) active = old; break;
case JGE_BTN_UP: if (old->y < oldactive->y) active = old; break;
case JGE_BTN_DOWN: if (old->y > oldactive->y) active = old; break;
default: if (old) active = old; break;
}
}
+5 -6
View File
@@ -248,22 +248,21 @@ void GameApp::Update()
{
if (systemError.size()) return;
JGE* mEngine = JGE::GetInstance();
if (mEngine->GetButtonState(PSP_CTRL_START) && mEngine->GetButtonClick(PSP_CTRL_TRIANGLE))
if (mEngine->GetButtonState(JGE_BTN_MENU) && mEngine->GetButtonClick(JGE_BTN_CANCEL))
{
char s[80];
sprintf(s, "ms0:/psp/photo/MTG%d.png", mScreenShotCount++);
JRenderer::GetInstance()->ScreenShot(s);
}
//Exit when START and X ARE PRESSED SIMULTANEOUSLY
if (mEngine->GetButtonState(PSP_CTRL_START) && mEngine->GetButtonState(PSP_CTRL_CROSS)){
if (mEngine->GetButtonState(JGE_BTN_MENU) && mEngine->GetButtonState(JGE_BTN_SEC)){
mEngine->End();
return;
}
//Restart Rendering engine when START and SQUARE ARE PRESSED SIMULTANEOUSLY
if (mEngine->GetButtonState(PSP_CTRL_START) && mEngine->GetButtonState(PSP_CTRL_SQUARE)){
if (mEngine->GetButtonState(JGE_BTN_MENU) && mEngine->GetButtonState(JGE_BTN_PRI))
JRenderer::Destroy();
}
float dt = mEngine->GetDelta();
if (dt > 35.0f) // min 30 FPS ;)
@@ -337,10 +336,10 @@ void GameApp::Render()
nbUpdates+=1;
JLBFont * mFont= resources.GetJLBFont("simon");
char buf[512];
sprintf(buf, "avg:%f - %f fps",totalFPS/nbUpdates, fps);
sprintf(buf, "avg:%.02f - %.02f fps",totalFPS/nbUpdates, fps);
if (mFont) {
mFont->SetColor(ARGB(255,255,255,255));
mFont->DrawString(buf,1,1);
mFont->DrawString(buf,1,10);
}
#endif
+81 -43
View File
@@ -5,12 +5,13 @@
#include "../include/Translate.h"
#include "../include/OptionItem.h"
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <stdlib.h>
#include <JGE.h>
const char * Options::optionNames[] = {
const string Options::optionNames[] = {
//Global options
"Profile",
"Lang",
@@ -31,6 +32,13 @@ const char * Options::optionNames[] = {
"economic_difficulty",
"transitions",
"interruptSeconds",
#if defined(WIN32)
"keybindings_win",
#elsif defined(LINUX)
"keybindings_x",
#else
"keybindings_psp",
#endif
"interruptMySpells",
"interruptMyAbilities",
//General interrupts
@@ -57,8 +65,7 @@ const char * Options::optionNames[] = {
};
int Options::getID(string name){
if(!name.size())
INVALID_OPTION;
if (0 == name.size()) INVALID_OPTION;
std::transform(name.begin(),name.end(),name.begin(),::tolower);
@@ -335,9 +342,6 @@ GameOption& GameOptions::operator[](int optionID){
}
GameOption * GameOptions::get(int optionID) {
GameOption * go = NULL;
GameOptionEnum * goEnum = NULL;
//Invalid options!
if(optionID < 0)
return NULL;
@@ -347,39 +351,44 @@ GameOption * GameOptions::get(int optionID) {
values.reserve(optionID);
while(x <= optionID){
switch(x){
//Enum options
case Options::HANDDIRECTION:
goEnum = NEW GameOptionEnum();
goEnum->def = OptionHandDirection::getInstance();
go = goEnum;
break;
case Options::CLOSEDHAND:
goEnum = NEW GameOptionEnum();
goEnum->def = OptionClosedHand::getInstance();
go = goEnum;
break;
case Options::MANADISPLAY:
goEnum = NEW GameOptionEnum();
goEnum->def = OptionManaDisplay::getInstance();
go = goEnum;
break;
case Options::MAX_GRADE:
goEnum = NEW GameOptionEnum();
goEnum->def = OptionMaxGrade::getInstance();
go = goEnum;
break;
case Options::ECON_DIFFICULTY:
goEnum = NEW GameOptionEnum();
goEnum->def = OptionEconDifficulty::getInstance();
go = goEnum;
break;
default:
if(x >= Options::BEGIN_AWARDS)
go = NEW GameOptionAward();
else
go = NEW GameOption();
break;
GameOption * go = NULL;
GameOptionEnum * goEnum = NULL;
switch(x){
//Enum options
case Options::HANDDIRECTION:
goEnum = NEW GameOptionEnum();
goEnum->def = OptionHandDirection::getInstance();
go = goEnum;
break;
case Options::CLOSEDHAND:
goEnum = NEW GameOptionEnum();
goEnum->def = OptionClosedHand::getInstance();
go = goEnum;
break;
case Options::MANADISPLAY:
goEnum = NEW GameOptionEnum();
goEnum->def = OptionManaDisplay::getInstance();
go = goEnum;
break;
case Options::MAX_GRADE:
goEnum = NEW GameOptionEnum();
goEnum->def = OptionMaxGrade::getInstance();
go = goEnum;
break;
case Options::KEY_BINDINGS:
go = NEW GameOptionKeyBindings();
break;
case Options::ECON_DIFFICULTY:
goEnum = NEW GameOptionEnum();
goEnum->def = OptionEconDifficulty::getInstance();
go = goEnum;
break;
default:
if(x >= Options::BEGIN_AWARDS)
go = NEW GameOptionAward();
else
go = NEW GameOption();
break;
}
values.push_back(go);
x++;
@@ -684,10 +693,7 @@ bool GameOptionEnum::write(std::ofstream * file, string name){
if(!file || !def || number <= 0 || number >= (int) def->values.size())
return false;
char writer[1024];
sprintf(writer,"%s=%s\n", name.c_str(), menuStr().c_str());
(*file)<<writer;
(*file) << name << "=" << menuStr() << endl;
return true;
}
@@ -871,3 +877,35 @@ string GameOptionAward::menuStr(){
strftime(buf,255,_("%B %d, %I:%M%p %Y").c_str(),lt);
return buf;
}
static JButton u32_to_button(u32 b)
{
if (b < JGE_BTN_MAX) return static_cast<JButton>(b);
else return JGE_BTN_NONE;
}
bool GameOptionKeyBindings::read(string input){
istringstream iss(input);
vector< pair<LocalKeySym, JButton> > assoc;
while (iss.good())
{
stringstream s;
iss.get(*(s.rdbuf()), ',');
iss.get();
LocalKeySym local; char sep; u32 button;
s >> local >> sep >> button;
if (':' != sep) return false;
assoc.push_back(make_pair(local, u32_to_button(button)));
}
if (assoc.empty()) return false;
JGE* j = JGE::GetInstance();
j->ClearBindings();
for (vector< pair<LocalKeySym, JButton> >::const_iterator it = assoc.begin(); it != assoc.end(); ++it)
j->BindKey(it->first, it->second);
return true;
}
+11 -14
View File
@@ -110,8 +110,8 @@ void GameStateAwards::Start()
wgh->setDisplay(buf);
wgh->mFlags = WGuiItem::NO_TRANSLATE;
listview->Entering(0);
detailview = NULL;
listview->Entering(JGE_BTN_NONE);
detailview = NULL;
setSrc = NULL;
showMenu = false;
resources.Unmiss("awardback.jpg"); //Last resort, same as shop.
@@ -151,19 +151,18 @@ void GameStateAwards::Render()
void GameStateAwards::Update(float dt)
{
if(mEngine->GetButtonClick(PSP_CTRL_TRIANGLE))
if(mEngine->GetButtonClick(JGE_BTN_CANCEL))
options[Options::DISABLECARDS].number = !options[Options::DISABLECARDS].number;
if(showMenu){
menu->Update(dt);
}
else{
u32 key;
JButton key;
while ((key = JGE::GetInstance()->ReadButton())){
switch(key){
case PSP_CTRL_START:
case JGE_BTN_MENU:
showMenu = true;
SAFE_DELETE(menu);
menu = NEW SimpleMenu(-102, this,Constants::MENU_FONT, 50,170);
if(mState == STATE_DETAILS)
@@ -171,10 +170,10 @@ void GameStateAwards::Update(float dt)
menu->Add(1, "Back to Main Menu");
menu->Add(3, "Cancel");
break;
case PSP_CTRL_LTRIGGER:
case JGE_BTN_PREV:
mParent->DoTransition(TRANSITION_FADE,GAME_STATE_MENU);
break;
case PSP_CTRL_CROSS:
case JGE_BTN_SEC:
if(mState == STATE_LISTVIEW)
mParent->DoTransition(TRANSITION_FADE,GAME_STATE_MENU);
else{
@@ -194,9 +193,7 @@ void GameStateAwards::Update(float dt)
break;
}
}
}
if(setSrc)
setSrc->Update(dt);
}
@@ -217,7 +214,7 @@ bool GameStateAwards::enterSet(int setid){
setSrc->bakeFilters();
setSrc->Sort(WSrcCards::SORT_COLLECTOR);
detailview = NEW WGuiMenu(PSP_CTRL_DOWN,PSP_CTRL_UP);
detailview = NEW WGuiMenu(JGE_BTN_DOWN, JGE_BTN_UP);
WGuiList * spoiler = NEW WGuiList("Spoiler",setSrc);
spoiler->setX(210);
@@ -228,13 +225,13 @@ bool GameStateAwards::enterSet(int setid){
spoiler->Add(NEW WGuiItem(c->data->name));
}
setSrc->setOffset(0);
spoiler->Entering(0);
spoiler->Entering(JGE_BTN_NONE);
WGuiCardImage * wi = NEW WGuiCardImage(setSrc);
wi->setX(105);
wi->setY(137);
detailview->Add(wi);
detailview->Add(spoiler);
detailview->Entering(0);
detailview->Entering(JGE_BTN_NONE);
return true;
}
bool GameStateAwards::enterStats(int option){
@@ -248,7 +245,7 @@ bool GameStateAwards::enterStats(int option){
detailview = NEW WGuiList("Details");
detailview->Add(NEW WGuiHeader("Collection Stats"));
detailview->Entering(0);
detailview->Entering(JGE_BTN_NONE);
//Discover favorite set and unique cards
int unique = 0;
+56 -65
View File
@@ -280,43 +280,43 @@ void GameStateDeckViewer::Update(float dt)
if (mStage == STAGE_WAITING || mStage == STAGE_ONSCREEN_MENU){
switch (mEngine->ReadButton())
{
case PSP_CTRL_LEFT :
case JGE_BTN_LEFT :
last_user_activity = 0;
mStage = STAGE_TRANSITION_LEFT;
break;
case PSP_CTRL_RIGHT :
case JGE_BTN_RIGHT :
last_user_activity = 0;
mStage = STAGE_TRANSITION_RIGHT;
break;
case PSP_CTRL_UP :
case JGE_BTN_UP :
last_user_activity = 0;
mStage = STAGE_TRANSITION_UP;
useFilter[myD]++;
if(useFilter[myD] >= MAX_SAVED_FILTERS)
useFilter[myD] = 0;
break;
case PSP_CTRL_DOWN :
case JGE_BTN_DOWN :
last_user_activity = 0;
mStage = STAGE_TRANSITION_DOWN;
useFilter[myD]--;
if(useFilter[myD] < 0)
useFilter[myD] = MAX_SAVED_FILTERS-1;
break;
case PSP_CTRL_TRIANGLE:
case JGE_BTN_CANCEL:
options[Options::DISABLECARDS].number = !options[Options::DISABLECARDS].number;
break;
case PSP_CTRL_SQUARE :
case JGE_BTN_PRI :
if (last_user_activity > 0.2)
{
last_user_activity = 0;
switchDisplay();
}
break;
case PSP_CTRL_CIRCLE :
case JGE_BTN_OK :
last_user_activity = 0;
addRemove(cardIndex[2]);
break;
case PSP_CTRL_CROSS :
case JGE_BTN_SEC :
last_user_activity = 0;
SAFE_DELETE(sellMenu);
char buffer[4096];
@@ -332,7 +332,7 @@ void GameStateDeckViewer::Update(float dt)
}
stw.needUpdate = true;
break;
/*case PSP_CTRL_SQUARE :
/*case JGE_BTN_PRI :
if (last_user_activity < NO_USER_ACTIVITY_HELP_DELAY){
last_user_activity = NO_USER_ACTIVITY_HELP_DELAY + 1;
}else{
@@ -340,58 +340,52 @@ void GameStateDeckViewer::Update(float dt)
mStage = STAGE_WAITING;
}
break;*/
case PSP_CTRL_START :
case JGE_BTN_MENU :
mStage = STAGE_MENU;
break;
case PSP_CTRL_SELECT :
case JGE_BTN_CTRL :
mStage = STAGE_FILTERS;
if(displayed_deck == myDeck){
if(!filterDeck)
if (displayed_deck == myDeck) {
if (!filterDeck)
filterDeck = NEW WGuiFilters("Filter by...",myDeck);
filterDeck->Entering(0);
}else if(displayed_deck == myCollection){
if(!filterCollection)
filterDeck->Entering(JGE_BTN_NONE);
} else if(displayed_deck == myCollection) {
if (!filterCollection)
filterCollection = NEW WGuiFilters("Filter by...",myCollection);
filterCollection->Entering(0);
filterCollection->Entering(JGE_BTN_NONE);
}
break;
case PSP_CTRL_LTRIGGER :
if (last_user_activity < NO_USER_ACTIVITY_HELP_DELAY){
case JGE_BTN_PREV :
if (last_user_activity < NO_USER_ACTIVITY_HELP_DELAY)
last_user_activity = NO_USER_ACTIVITY_HELP_DELAY + 1;
}
else if ((mStage == STAGE_ONSCREEN_MENU) && (--stw.currentPage < 0)) {
else if ((mStage == STAGE_ONSCREEN_MENU) && (--stw.currentPage < 0))
stw.currentPage = stw.pageCount;
}
break;
case PSP_CTRL_RTRIGGER :
if (last_user_activity < NO_USER_ACTIVITY_HELP_DELAY){
case JGE_BTN_NEXT :
if (last_user_activity < NO_USER_ACTIVITY_HELP_DELAY)
last_user_activity = NO_USER_ACTIVITY_HELP_DELAY + 1;
}
else if ((mStage == STAGE_ONSCREEN_MENU) && (++stw.currentPage > stw.pageCount)) {
else if ((mStage == STAGE_ONSCREEN_MENU) && (++stw.currentPage > stw.pageCount))
stw.currentPage = 0;
}
break;
default : // no keypress
if (last_user_activity > NO_USER_ACTIVITY_HELP_DELAY){
if (mStage != STAGE_ONSCREEN_MENU){
mStage = STAGE_ONSCREEN_MENU;
onScreenTransition = 1;
}else{
if (onScreenTransition >0){
} else {
if (onScreenTransition >0)
onScreenTransition-= 0.05f;
}else{
else
onScreenTransition = 0;
}
}
}else{
} else
last_user_activity+= dt;
}
}
} if (mStage == STAGE_TRANSITION_RIGHT || mStage == STAGE_TRANSITION_LEFT) {
if (mStage == STAGE_TRANSITION_RIGHT){
mRotation -= dt * MED_SPEED;
if (mRotation < -1.0f){
if (mRotation < -1.0f) {
do {
rotateCards(mStage);
mRotation += 1;
@@ -399,7 +393,7 @@ void GameStateDeckViewer::Update(float dt)
mStage = STAGE_WAITING;
mRotation = 0;
}
}else if(mStage == STAGE_TRANSITION_LEFT){
} else if (mStage == STAGE_TRANSITION_LEFT) {
mRotation += dt * MED_SPEED;
if (mRotation > 1.0f){
do {
@@ -410,47 +404,47 @@ void GameStateDeckViewer::Update(float dt)
mRotation = 0;
}
}
} if (mStage == STAGE_TRANSITION_DOWN || mStage == STAGE_TRANSITION_UP){
if (mStage == STAGE_TRANSITION_DOWN){
} if (mStage == STAGE_TRANSITION_DOWN || mStage == STAGE_TRANSITION_UP) {
if (mStage == STAGE_TRANSITION_DOWN) {
mSlide -= 0.05f;
if (mSlide < -1.0f){
updateFilters();
loadIndexes();
mSlide = 1;
}else if (mSlide > 0 && mSlide < 0.05){
} else if (mSlide > 0 && mSlide < 0.05) {
mStage = STAGE_WAITING;
mSlide = 0;
}
} if (mStage == STAGE_TRANSITION_UP){
} if (mStage == STAGE_TRANSITION_UP) {
mSlide += 0.05f;
if (mSlide > 1.0f){
updateFilters();
loadIndexes();
mSlide = -1;
}else if (mSlide < 0 && mSlide > -0.05){
} else if (mSlide < 0 && mSlide > -0.05) {
mStage = STAGE_WAITING;
mSlide = 0;
}
}
}else if (mStage == STAGE_WELCOME){
} else if (mStage == STAGE_WELCOME)
welcome_menu->Update(dt);
}else if (mStage == STAGE_MENU){
else if (mStage == STAGE_MENU)
menu->Update(dt);
}else if(mStage == STAGE_FILTERS){
u32 key = mEngine->ReadButton();
else if(mStage == STAGE_FILTERS){
JButton key = mEngine->ReadButton();
if(displayed_deck == myDeck){
if(filterDeck){
if(key == PSP_CTRL_SELECT){
if (displayed_deck == myDeck) {
if (filterDeck) {
if (key == JGE_BTN_CTRL) {
useFilter[(displayed_deck == myDeck)] = 0;
filterDeck->Finish();
filterDeck->Update(dt);
loadIndexes();
return;
}
if(!filterDeck->isFinished()){
if (!filterDeck->isFinished()) {
filterDeck->CheckUserInput(key);
filterDeck->Update(dt);
} else {
@@ -458,23 +452,23 @@ void GameStateDeckViewer::Update(float dt)
loadIndexes();
}
}
}else{
if(filterCollection ){
if(key == PSP_CTRL_SELECT){
} else {
if (filterCollection) {
if (key == JGE_BTN_CTRL) {
useFilter[(displayed_deck == myDeck)] = 0;
filterCollection->Finish();
filterCollection->Update(dt);
loadIndexes();
return;
}
if(!filterCollection->isFinished()){
if (!filterCollection->isFinished()) {
filterCollection->CheckUserInput(key);
filterCollection->Update(dt);
} else {
mStage = STAGE_WAITING;
loadIndexes();
}
}
}
}
}
@@ -1550,11 +1544,11 @@ void GameStateDeckViewer::ButtonPressed(int controllerId, int controlId)
if(displayed_deck == myDeck){
if(!filterDeck)
filterDeck = NEW WGuiFilters("Filter by...",myDeck);
filterDeck->Entering(0);
filterDeck->Entering(JGE_BTN_NONE);
}else if(displayed_deck == myCollection){
if(!filterCollection)
filterCollection = NEW WGuiFilters("Filter by...",myCollection);
filterCollection->Entering(0);
filterCollection->Entering(JGE_BTN_NONE);
}
break;
}
@@ -1581,21 +1575,18 @@ void GameStateDeckViewer::ButtonPressed(int controllerId, int controlId)
}
}
// n cards total, a of them are of desired type (A), x drawn
// n cards total, a of them are of desired type (A), x drawn
// returns probability of no A's
float noLuck(int n, int a, int x) {
if ( (a >= n) || (a == 0)) {
if ((a >= n) || (a == 0))
return 1;
}
if ((n == 0) || (x == 0) || (x > n) || (n-a < x)) {
if ((n == 0) || (x == 0) || (x > n) || (n-a < x))
return 0;
}
a = n - a;
float result = 1;
for (int i=0; i<x; i++) {
for (int i=0; i<x; i++)
result *= (float)(a-i)/(n-i);
}
return result;
}
}
+12 -16
View File
@@ -218,7 +218,7 @@ void GameStateDuel::Update(float dt)
switch (mGamePhase)
{
case DUEL_STATE_ERROR_NO_DECK:
if (PSP_CTRL_CIRCLE == mEngine->ReadButton())
if (JGE_BTN_OK == mEngine->ReadButton())
mParent->SetNextState(GAME_STATE_DECK_VIEWER);
break;
case DUEL_STATE_CHOOSE_DECK1:
@@ -291,11 +291,11 @@ void GameStateDuel::Update(float dt)
}
else
{
if (opponentMenu->closed) mGamePhase = DUEL_STATE_PLAY;
else opponentMenu->Update(dt);
if (opponentMenu->closed) mGamePhase = DUEL_STATE_PLAY;
else opponentMenu->Update(dt);
}
break;
case DUEL_STATE_PLAY:
case DUEL_STATE_PLAY:
if (!game){
GameObserver::Init(mPlayers, 2);
game = GameObserver::GetInstance();
@@ -344,9 +344,8 @@ void GameStateDuel::Update(float dt)
loadTestSuitePlayers();
mGamePhase = DUEL_STATE_PLAY;
testSuite->initGame();
}else{
}else
mGamePhase = DUEL_STATE_END;
}
}else
#endif
if (mParent->players[0] == PLAYER_TYPE_CPU && mParent->players[1] == PLAYER_TYPE_CPU){
@@ -354,9 +353,8 @@ void GameStateDuel::Update(float dt)
Start();
}
}
if (mEngine->GetButtonClick(PSP_CTRL_START)){
mGamePhase = DUEL_STATE_MENU;
}
if (mEngine->GetButtonClick(JGE_BTN_MENU))
mGamePhase = DUEL_STATE_MENU;
break;
case DUEL_STATE_MENU:
menu->Update(dt);
@@ -380,9 +378,8 @@ void GameStateDuel::Update(float dt)
}
break;
default:
if (PSP_CTRL_CIRCLE == mEngine->ReadButton()){
if (JGE_BTN_OK == mEngine->ReadButton())
mParent->SetNextState(GAME_STATE_MENU);
}
}
}
@@ -439,14 +436,13 @@ void GameStateDuel::Render()
case DUEL_STATE_CHOOSE_DECK1_TO_2:
case DUEL_STATE_CHOOSE_DECK2:
case DUEL_STATE_CHOOSE_DECK2_TO_PLAY:
if (mParent->gameType != GAME_TYPE_CLASSIC){
if (mParent->gameType != GAME_TYPE_CLASSIC)
mFont->DrawString(_("LOADING DECKS").c_str(),0,SCREEN_HEIGHT/2);
}else{
if (opponentMenu){
else{
if (opponentMenu)
opponentMenu->Render();
}else if (deckmenu){
else if (deckmenu)
deckmenu->Render();
}
}
break;
case DUEL_STATE_ERROR_NO_DECK:
+5 -5
View File
@@ -431,7 +431,7 @@ void GameStateMenu::Update(float dt)
}
if (mGuiController)
mGuiController->Update(dt);
if(mEngine->GetButtonState(PSP_CTRL_RTRIGGER)) //Hook for GameStateAward state
if(mEngine->GetButtonState(JGE_BTN_NEXT)) //Hook for GameStateAward state
mParent->DoTransition(TRANSITION_FADE,GAME_STATE_AWARDS); //TODO: A slide transition would be nice.
break;
case MENU_STATE_MAJOR_SUBMENU :
@@ -471,8 +471,8 @@ void GameStateMenu::Update(float dt)
case MENU_STATE_MINOR_NONE :
;// Nothing to do.
}
if(mEngine->GetButtonState(PSP_CTRL_LTRIGGER)) {
if(mEngine->GetButtonState(JGE_BTN_PREV)) {
//Reset deck of cards
angleMultiplier = MIN_ANGLE_MULTIPLIER;
yW = 55;
@@ -480,12 +480,12 @@ void GameStateMenu::Update(float dt)
if (yW <= 55)
{
if (mEngine->GetButtonState(PSP_CTRL_SQUARE)) angleMultiplier += STEP_ANGLE_MULTIPLIER;
if (mEngine->GetButtonState(JGE_BTN_PRI)) angleMultiplier += STEP_ANGLE_MULTIPLIER;
else angleMultiplier *= 0.9999;
if (angleMultiplier > MAX_ANGLE_MULTIPLIER) angleMultiplier = MAX_ANGLE_MULTIPLIER;
else if (angleMultiplier < MIN_ANGLE_MULTIPLIER) angleMultiplier = MIN_ANGLE_MULTIPLIER;
if (mEngine->GetButtonState(PSP_CTRL_TRIANGLE) && (dt != 0))
if (mEngine->GetButtonState(JGE_BTN_CANCEL) && (dt != 0))
{
angleMultiplier = (cos(timeIndex)*angleMultiplier - M_PI/3 - 0.1 - angleW) / dt;
yW = yW + 5*dt + (yW - 45) *5* dt;
+21 -18
View File
@@ -28,9 +28,9 @@ void GameStateOptions::Start()
WGuiList * optionsList;
optionsList = NEW WGuiList("Settings");
optionsList->Add(NEW WGuiHeader("General Options"));
if (GameApp::HasMusic)
if (GameApp::HasMusic)
optionsList->Add(NEW WDecoEnum(NEW OptionInteger(Options::MUSICVOLUME,"Music volume",100,10,100),OptionVolume::getInstance()));
optionsList->Add(NEW WDecoEnum(NEW OptionInteger(Options::SFXVOLUME,"SFX volume",100,10,100),OptionVolume::getInstance()));
optionsList->Add(NEW OptionInteger(Options::OSD, "Display InGame extra information"));
@@ -40,9 +40,9 @@ void GameStateOptions::Start()
}
optionsList->Add(NEW OptionInteger(Options::INTERRUPT_SECONDS, "Seconds to pause for an Interrupt", 20, 1));
optionsList->Add(NEW OptionInteger(Options::INTERRUPTMYSPELLS, "Interrupt my spells"));
optionsList->Add(NEW OptionInteger(Options::INTERRUPTMYABILITIES, "Interrupt my abilities"));
optionsList->Add(NEW OptionInteger(Options::INTERRUPT_SECONDMAIN, "Interrupt opponent's end of turn"));
optionsTabs = NEW WGuiTabMenu();
optionsList->Add(NEW OptionInteger(Options::INTERRUPTMYABILITIES, "Interrupt my abilities"));
optionsList->Add(NEW OptionInteger(Options::INTERRUPT_SECONDMAIN, "Interrupt opponent's end of turn"));
optionsTabs = NEW WGuiTabMenu();
optionsTabs->Add(optionsList);
optionsList = NEW WGuiList("Game");
@@ -61,8 +61,8 @@ void GameStateOptions::Start()
cPrf->confirm = "Use this Profile";
OptionDirectory * od = NEW OptionTheme();
WDecoConfirm * cThm = NEW WDecoConfirm(this,od);
cThm->confirm = "Use this Theme";
cThm->confirm = "Use this Theme";
optionsList->Add(NEW WGuiSplit(cPrf,cThm));
optionsList->Add(NEW WGuiButton(NEW WGuiHeader("New Profile"),-102,4,this));
optionsList->Add(NEW WDecoCheat(NEW OptionInteger(Options::CHEATMODE, "Enable cheat mode")));
@@ -80,6 +80,9 @@ void GameStateOptions::Start()
optionsList->Add(oGra);
optionsTabs->Add(optionsList);
optionsList = NEW WGuiList("Key Bindings");
optionsTabs->Add(optionsList);
optionsList = NEW WGuiList("Credits");
optionsList->failMsg = "";
optionsTabs->Add(optionsList);
@@ -89,7 +92,7 @@ void GameStateOptions::Start()
optionsMenu->Add(1, "Save & Back to Main Menu");
optionsMenu->Add(3, "Cancel");
optionsTabs->Entering(0);
optionsTabs->Entering(JGE_BTN_NONE);
}
@@ -102,7 +105,7 @@ void GameStateOptions::End()
void GameStateOptions::Update(float dt)
{
{
timer += dt * 10;
if(options.keypadActive()){
@@ -121,23 +124,23 @@ void GameStateOptions::Update(float dt)
else switch(mState){
default:
case SHOW_OPTIONS:
u32 key;
JButton key;
while ((key = JGE::GetInstance()->ReadButton())){
if(!optionsTabs->CheckUserInput(key) && key == PSP_CTRL_START)
if(!optionsTabs->CheckUserInput(key) && key == JGE_BTN_MENU)
mState = SHOW_OPTIONS_MENU;
}
optionsTabs->Update(dt);
break;
case SHOW_OPTIONS_MENU:
optionsMenu->Update(dt);
break;
}
break;
}
if(mReload){
options.reloadProfile(true);
Translator::EndInstance();
Translator::GetInstance()->init();
optionsTabs->Reload();
optionsTabs->Reload();
mReload = false;
}
}
@@ -157,7 +160,7 @@ void GameStateOptions::Render()
"Art: Ilya B, Julio, Jeck, J, Lakeesha",
"Check themeinfo.txt for the full credits of each theme!",
"",
"Dev Team: Abrasax, Daddy32, Dr.Solomat, J, Jeck",
"Dev Team: Abrasax, Daddy32, Dr.Solomat, J, Jeck",
"Leungclj, Superhiro, Psyringe, Wololo, Yeshua",
"",
"Music by Celestial Aeon Project, http://www.jamendo.com",
@@ -189,7 +192,7 @@ void GameStateOptions::Render()
float startpos = 272 - timer;
float pos = startpos;
int size = sizeof(CreditsText) / sizeof(CreditsText[0]);
for (int i = 0; i < size; i++){
pos = startpos + 20 * i;
if (pos > -20 && pos < SCREEN_HEIGHT + 20){
@@ -197,13 +200,13 @@ void GameStateOptions::Render()
}
}
if (pos < -20)
if (pos < -20)
timer = 0;
optionsTabs->Render();
if(mState == SHOW_OPTIONS_MENU)
if(mState == SHOW_OPTIONS_MENU)
optionsMenu->Render();
if(options.keypadActive())
+42 -43
View File
@@ -71,7 +71,7 @@ void GameStateShop::Start(){
srcCards->setElapsed(15);
bigSync = 0;
shopMenu = NEW WGuiMenu(PSP_CTRL_DOWN,PSP_CTRL_UP,true,&bigSync);
shopMenu = NEW WGuiMenu(JGE_BTN_DOWN, JGE_BTN_UP, true, &bigSync);
MTGAllCards * ac = GameApp::collection;
playerdata = NEW PlayerData(ac);;
myCollection = NEW DeckDataWrapper(playerdata->collection);
@@ -87,7 +87,7 @@ void GameStateShop::Start(){
dist->xy = WDistort(_x1[i],_y1[i],_x2[i],_y2[i],_x3[i],_y3[i],_x4[i],_y4[i]);
shopMenu->Add(NEW WGuiButton(dist,-102,i,this));
}
shopMenu->Entering(0);
shopMenu->Entering(JGE_BTN_NONE);
if(!bigDisplay){
bigDisplay = NEW WGuiCardImage(srcCards);
@@ -337,11 +337,11 @@ void GameStateShop::beginFilters(){
filterMenu->setHeight(SCREEN_HEIGHT-2);
}
mStage = STAGE_ASK_ABOUT;
filterMenu->Entering(0);
filterMenu->Entering(JGE_BTN_NONE);
}
void GameStateShop::Update(float dt)
{
if(menu && menu->closed)
{
if (menu && menu->closed)
SAFE_DELETE(menu);
srcCards->Update(dt);
alphaChange = (500 - (rand() % 1000)) * dt;
@@ -350,10 +350,10 @@ void GameStateShop::Update(float dt)
if (lightAlpha > 50) lightAlpha = 50;
// mParent->effect->UpdateSmall(dt);
// mParent->effect->UpdateBig(dt);
if(mStage != STAGE_FADE_IN)
if (mStage != STAGE_FADE_IN)
mElapsed += dt;
u32 btn;
JButton btn;
switch(mStage){
case STAGE_SHOP_PURCHASE:
if (menu)
@@ -362,32 +362,32 @@ void GameStateShop::Update(float dt)
mStage = STAGE_SHOP_SHOP;
break;
case STAGE_SHOP_MENU:
if (menu){
if (menu)
menu->Update(dt);
}else{
else{
menu = NEW SimpleMenu(11,this,Constants::MENU_FONT,SCREEN_WIDTH/2-100,20);
menu->Add(22,"Ask about...");
menu->Add(14,"Check task board");
if(options[Options::CHEATMODE].number)
if (options[Options::CHEATMODE].number)
menu->Add(-2,"Steal 1,000 credits");
menu->Add(12,"Save & Back to Main Menu");
menu->Add(13, "Cancel");
}
}
break;
case STAGE_SHOP_TASKS:
if(menu){
case STAGE_SHOP_TASKS:
if (menu){
menu->Update(dt);
return;
}
if(taskList){
if (taskList){
btn = mEngine->ReadButton();
taskList->Update(dt);
if ( taskList->getState() != TaskList::TASKS_INACTIVE){
if( btn == PSP_CTRL_CROSS || btn == PSP_CTRL_TRIANGLE ){
if ( btn == JGE_BTN_SEC || btn == JGE_BTN_CANCEL ){
taskList->End();
return;
}else if(taskList->getState() == TaskList::TASKS_ACTIVE && btn == PSP_CTRL_START ){
if(!menu){
} else if (taskList->getState() == TaskList::TASKS_ACTIVE && btn == JGE_BTN_MENU){
if (!menu) {
menu = NEW SimpleMenu(11,this,Constants::MENU_FONT,SCREEN_WIDTH/2-100,20);
menu->Add(15,"Return to shop");
menu->Add(12,"Save & Back to Main Menu");
@@ -400,7 +400,7 @@ void GameStateShop::Update(float dt)
}
#ifdef TESTSUITE
if ((mEngine->GetButtonClick(PSP_CTRL_SQUARE)) && (taskList)) {
if ((mEngine->GetButtonClick(JGE_BTN_PRI)) && (taskList)) {
taskList->passOneDay();
if (taskList->getTaskCount() < 6) {
taskList->addRandomTask();
@@ -412,19 +412,19 @@ void GameStateShop::Update(float dt)
break;
case STAGE_ASK_ABOUT:
btn = mEngine->ReadButton();
if(menu && !menu->closed){
if (menu && !menu->closed){
menu->CheckUserInput(btn);
menu->Update(dt);
return;
}
if(filterMenu){
if(btn == PSP_CTRL_SELECT){
if (filterMenu){
if (btn == JGE_BTN_CTRL) {
needLoad = filterMenu->Finish();
filterMenu->Update(dt);
return;
}
if(filterMenu->isFinished()){
if(needLoad)
if (filterMenu->isFinished()){
if (needLoad)
load();
mStage = STAGE_SHOP_SHOP;
}else{
@@ -436,42 +436,41 @@ void GameStateShop::Update(float dt)
break;
case STAGE_SHOP_SHOP:
btn = mEngine->ReadButton();
if(menu && !menu->closed){
if (menu && !menu->closed){
menu->CheckUserInput(btn);
menu->Update(dt);
return;
}
if (btn == PSP_CTRL_START){
if(boosterDisplay){
if (btn == JGE_BTN_MENU){
if (boosterDisplay){
deleteDisplay();
return;
}
mStage = STAGE_SHOP_MENU;
return;
}else if(btn == PSP_CTRL_SELECT){
} else if (btn == JGE_BTN_CTRL)
beginFilters();
}else if(btn == PSP_CTRL_SQUARE){
else if (btn == JGE_BTN_PRI) {
srcCards->Shuffle();
load();
}else if(btn == PSP_CTRL_TRIANGLE){
load();
} else if (btn == JGE_BTN_CANCEL)
options[Options::DISABLECARDS].number = !options[Options::DISABLECARDS].number;
}else if (boosterDisplay){
if(btn == PSP_CTRL_CROSS)
else if (boosterDisplay){
if (btn == JGE_BTN_SEC)
deleteDisplay();
else {
boosterDisplay->CheckUserInput(btn);
boosterDisplay->Update(dt);}
boosterDisplay->CheckUserInput(btn);
boosterDisplay->Update(dt);}
return;
}else if(btn == PSP_CTRL_CROSS){
bListCards = !bListCards;
}else if(shopMenu){
if(shopMenu->CheckUserInput(btn))
}else if (btn == JGE_BTN_SEC)
bListCards = !bListCards;
else if (shopMenu){
if (shopMenu->CheckUserInput(btn))
srcCards->Touch();
}
if(shopMenu)
if (shopMenu)
shopMenu->Update(dt);
break;
case STAGE_FADE_IN:
mParent->DoAnimation(TRANSITION_FADE_IN);
@@ -486,7 +485,7 @@ void GameStateShop::makeDisplay(MTGDeck * d){
void GameStateShop::deleteDisplay(){
vector<MTGCardInstance*>::iterator i;
for(i=subBooster.begin();i!=subBooster.end();i++){
if(!*i) continue;
if (!*i) continue;
delete *i;
}
subBooster.clear();
@@ -749,4 +748,4 @@ void ShopBooster::addToDeck(MTGDeck * d, WSrcCards * srcCards){
carryover = pool->addToDeck(d,carryover+11);
SAFE_DELETE(pool);
}
}
}
+9 -9
View File
@@ -143,7 +143,7 @@ bool GuiCombat::CheckUserInput(u32 key)
DamagerDamaged* oldActive = active;
switch (key)
{
case PSP_CTRL_CIRCLE:
case JGE_BTN_OK:
if (BLK == cursor_pos)
{
if (ORDER == step) go->cardClick(active->card); // { activeAtk->card->raiseBlockerRankOrder(active->card); }
@@ -173,7 +173,7 @@ bool GuiCombat::CheckUserInput(u32 key)
clickOK();
}
break;
case PSP_CTRL_TRIANGLE:
case JGE_BTN_CANCEL:
if (BLK == cursor_pos)
{
oldActive->zoom = 2.2;
@@ -181,7 +181,7 @@ bool GuiCombat::CheckUserInput(u32 key)
cursor_pos = ATK;
}
return true;
case PSP_CTRL_LEFT:
case JGE_BTN_LEFT:
switch (cursor_pos)
{
case NONE : break;
@@ -206,7 +206,7 @@ bool GuiCombat::CheckUserInput(u32 key)
break;
}
break;
case PSP_CTRL_RIGHT:
case JGE_BTN_RIGHT:
switch (cursor_pos)
{
case NONE :
@@ -232,22 +232,22 @@ bool GuiCombat::CheckUserInput(u32 key)
break;
}
break;
case PSP_CTRL_DOWN:
case JGE_BTN_DOWN:
if (ORDER == step || BLK != cursor_pos || active->sumDamages() <= 0) break;
removeOne(active, step);
break;
case PSP_CTRL_UP:
case JGE_BTN_UP:
if (ORDER == step || BLK != cursor_pos) break;
addOne(active, step);
break;
case PSP_CTRL_SQUARE:
case JGE_BTN_PRI:
active = activeAtk = NULL; cursor_pos = OK;
break;
case PSP_CTRL_RTRIGGER:
case JGE_BTN_NEXT:
if (!options[Options::REVERSETRIGGERS].number) return false;
active = activeAtk = NULL; cursor_pos = OK;
break;
case PSP_CTRL_LTRIGGER:
case JGE_BTN_PREV:
if (options[Options::REVERSETRIGGERS].number) return false;
active = activeAtk = NULL; cursor_pos = OK;
break;
+1 -1
View File
@@ -139,7 +139,7 @@ void GuiHandSelf::Repos()
bool GuiHandSelf::CheckUserInput(u32 key)
{
u32 trigger = (options[Options::REVERSETRIGGERS].number ? PSP_CTRL_LTRIGGER : PSP_CTRL_RTRIGGER);
u32 trigger = (options[Options::REVERSETRIGGERS].number ? JGE_BTN_PREV : JGE_BTN_NEXT);
if (trigger == key)
{
state = (Open == state ? Closed : Open);
+3 -4
View File
@@ -7,7 +7,7 @@ GuiLayer::GuiLayer(){
hasFocus = false;
mCount = 0;
mCurr = 0;
mActionButton = PSP_CTRL_CIRCLE;
mActionButton = JGE_BTN_OK;
}
GuiLayer::~GuiLayer(){
@@ -20,16 +20,15 @@ void GuiLayer::Add(JGuiObject *object){
}
int GuiLayer::Remove(JGuiObject *object){
for (int i=0;i<mCount;i++){
for (int i=0;i<mCount;i++)
if (mObjects[i]==object){
delete mObjects[i];
mObjects.erase(mObjects.begin()+i);
mCount--;
if (mCurr == mCount)
mCurr = 0;
mCurr = 0;
return 1;
}
}
return 0;
}
+1 -1
View File
@@ -33,7 +33,7 @@ void MTGGamePhase::Update(float dt){
bool MTGGamePhase::CheckUserInput(u32 key){
GameObserver * game = GameObserver::GetInstance();
if (activeState == INACTIVE){
u32 trigger = (options[Options::REVERSETRIGGERS].number ? PSP_CTRL_RTRIGGER : PSP_CTRL_LTRIGGER);
u32 trigger = (options[Options::REVERSETRIGGERS].number ? JGE_BTN_NEXT : JGE_BTN_PREV);
if ((trigger == key) && game->currentActionPlayer == game->currentlyActing())
{
activeState = ACTIVE;
+2 -2
View File
@@ -9,7 +9,7 @@
#include "../include/WFilter.h"
#include "../include/DeckDataWrapper.h"
#include "../include/MTGPack.h"
#include "../../../JGE/src/TinyXML/tinyxml.h"
#include "../../../JGE/src/tinyxml/tinyxml.h"
int MTGPackEntryRandom::addCard(WSrcCards *pool, MTGDeck *to){
int fails = 0;
@@ -270,4 +270,4 @@ void MTGPacks::refreshUnlocked(){
if(packs[t]->unlockStatus < 0)
packs[t]->unlockStatus = 0;
}
}
}
+1 -1
View File
@@ -140,7 +140,7 @@ int MTGAttackRule::reactToClick(MTGCardInstance * card){
if(!card->isAttacker()){
CardSelector * cs = game->mLayers->cs;
cs->Limit(this,CardSelector::playZone);
cs->CheckUserInput(PSP_CTRL_RIGHT);
cs->CheckUserInput(JGE_BTN_RIGHT);
cs->Limit(NULL,CardSelector::playZone);
}
card->toggleAttacker();
+3 -3
View File
@@ -61,7 +61,7 @@ void OptionSelect::initSelections(){
}
}
void OptionSelect::Entering(u32 key){
void OptionSelect::Entering(JButton key){
OptionItem::Entering(key);
prior_value = value;
}
@@ -187,7 +187,7 @@ void OptionProfile::Render(){
mFont->SetScale(1);
}
void OptionProfile::Entering(u32 key){
void OptionProfile::Entering(JButton key){
mFocus = true;
initialValue = value;
}
@@ -427,4 +427,4 @@ void OptionTheme::confirmChange(bool confirmed){
resources.Refresh(); //Update images
prior_value = value;
}
}
}
+553
View File
@@ -0,0 +1,553 @@
#include "../include/config.h"
#include "../include/ShopItem.h"
#include "../include/GameStateShop.h"
#include "../include/CardGui.h"
#include "../include/WResourceManager.h"
#include "../include/Translate.h"
#include <hge/hgedistort.h>
float ShopItems::_x1[] = { 79, 19, 27,103,154,187,102,144,198,133,183};
float ShopItems::_y1[] = {150,194,222,167,164,156,195,190,175,220,220};
float ShopItems::_x2[] = {103, 48, 74,135,183,215,138,181,231,171,225};
float ShopItems::_y2[] = {155,179,218,165,166,155,195,186,177,225,216};
float ShopItems::_x3[] = { 48, 61, 9, 96,139,190, 81,146,187, 97,191};
float ShopItems::_y3[] = {164,205,257,184,180,170,219,212,195,251,252};
float ShopItems::_x4[] = { 76, 90, 65,131,171,221,123,187,225,141,237};
float ShopItems::_y4[] = {169,188,250,182,182,168,220,208,198,259,245};
ShopItem::ShopItem(int id, JLBFont *font, char* text, JQuad * _quad,JQuad * _thumb, float _xy[], bool hasFocus, int _price): JGuiObject(id), mFont(font), mText(text), quad(_quad), thumb(_thumb), price(_price)
{
for (int i = 0; i < 8; ++i){
xy[i] = _xy[i];
}
quantity = 10;
card = NULL;
mHasFocus = hasFocus;
mRelease = false;
mScale = 1.0f;
mTargetScale = 1.0f;
mesh=NEW hgeDistortionMesh(2,2);
mesh->SetTexture(thumb->mTex);
float x0,y0,w0,h0;
thumb->GetTextureRect(&x0,&y0,&w0,&h0);
mesh->SetTextureRect(x0,y0,w0,h0);
mesh->Clear(ARGB(0xFF,0xFF,0xFF,0xFF));
mesh->SetDisplacement(0, 0, xy[0],xy[1], HGEDISP_NODE);
mesh->SetDisplacement(1, 0, xy[2] - w0,xy[3], HGEDISP_NODE);
mesh->SetDisplacement(0, 1,xy[4],xy[5]-h0, HGEDISP_NODE);
mesh->SetDisplacement(1, 1, xy[6]-w0,xy[7]-h0, HGEDISP_NODE);
mesh->SetColor(1,1,ARGB(255,100,100,100));
mesh->SetColor(0,1,ARGB(255,100,100,100));
mesh->SetColor(1,0,ARGB(255,100,100,100));
mesh->SetColor(0,0,ARGB(255,200,200,200));
if (hasFocus)
Entering();
}
ShopItem::ShopItem(int id, JLBFont *font, int _cardid, float _xy[], bool hasFocus, MTGAllCards * collection, int _price, DeckDataWrapper * ddw): JGuiObject(id), mFont(font), price(_price){
for (int i = 0; i < 8; ++i){
xy[i] = _xy[i];
}
mHasFocus = hasFocus;
mRelease = false;
mScale = 1.0f;
mTargetScale = 1.0f;
if (hasFocus)
Entering();
card = collection->getCardById(_cardid);
updateCount(ddw);
quantity = 1 + (rand() % 4);
if (card->getRarity() == Constants::RARITY_L) quantity = 50;
quad = NULL;
mesh = NULL;
thumb = NULL;
updateThumb();
}
int ShopItem::updateCount(DeckDataWrapper * ddw){
if (!card) return 0;
nameCount = ddw->countByName(card);
return nameCount;
}
ShopItem::~ShopItem(){
OutputDebugString("delete shopitem\n");
if(thumb)
resources.Release(thumb->mTex);
SAFE_DELETE(mesh);
}
const char * ShopItem::getText(){
return mText.c_str();
}
void ShopItem::updateThumb(){
if(card == NULL)
return;
if(thumb && mRelease)
resources.Release(thumb->mTex);
mRelease = false;
if(mesh)
SAFE_DELETE(mesh);
else if(thumb)
SAFE_DELETE(thumb);
thumb = resources.RetrieveCard(card,RETRIEVE_LOCK,TEXTURE_SUB_THUMB);
#if defined (WIN32) || defined (LINUX)
//On pcs we render the big image if the thumbnail is not available
if (!thumb) thumb = resources.RetrieveCard(card,RETRIEVE_LOCK);
#endif
if (!thumb)
thumb = CardGui::alternateThumbQuad(card);
else
mRelease = true;
if (thumb){
mesh=NEW hgeDistortionMesh(2,2);
mesh->SetTexture(thumb->mTex);
float x0,y0,w0,h0;
thumb->GetTextureRect(&x0,&y0,&w0,&h0);
mesh->SetTextureRect(x0,y0,w0,h0);
mesh->Clear(ARGB(0xFF,0xFF,0xFF,0xFF));
mesh->SetDisplacement(0, 0, xy[0],xy[1], HGEDISP_NODE);
mesh->SetDisplacement(1, 0, xy[2] - w0,xy[3], HGEDISP_NODE);
mesh->SetDisplacement(0, 1,xy[4],xy[5]-h0, HGEDISP_NODE);
mesh->SetDisplacement(1, 1, xy[6]-w0,xy[7]-h0, HGEDISP_NODE);
mesh->SetColor(1,1,ARGB(255,100,100,100));
mesh->SetColor(0,1,ARGB(255,100,100,100));
mesh->SetColor(1,0,ARGB(255,100,100,100));
mesh->SetColor(0,0,ARGB(255,200,200,200));
}else{
mesh = NULL;
}
}
void ShopItem::Render(){
if (mHasFocus){
mFont->SetColor(ARGB(255,255,255,0));
}else{
mFont->SetColor(ARGB(255,255,255,255));
}
if (!quantity){
mFont->SetColor(ARGB(255,128,128,128));
}
if (card){
if (nameCount){
char buffer[512];
sprintf(buffer, "%s (%i)", _(card->data->name).c_str(), nameCount );
mText = buffer;
}else{
mText = _(card->data->name).c_str();
}
}
JRenderer * renderer = JRenderer::GetInstance();
if (mesh){
mesh->Render(0,0);
}else{
//ERROR Management
}
if (mHasFocus){
if (card) quad = resources.RetrieveCard(card);
if (quad){
float scale = 0.9 * 285/ quad->mHeight;
quad->SetColor(ARGB(255,255,255,255));
renderer->RenderQuad(quad,SCREEN_WIDTH - 105,SCREEN_HEIGHT/2 - 5,0, scale,scale);
}else{
if (card) CardGui::alternateRender(card,Pos(SCREEN_WIDTH - 105,SCREEN_HEIGHT/2 - 5,0.9f* 285/250, 0,255));
}
}
}
void ShopItem::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 ShopItem::Entering()
{
for (int i = 0; i < 2; ++i){
for (int j = 0; j < 2; ++j){
mesh->SetColor(i,j,ARGB(255,255,255,255));
}
}
mHasFocus = true;
mTargetScale = 1.2f;
}
bool ShopItem::Leaving(JButton key)
{
mesh->SetColor(1,1,ARGB(255,100,100,100));
mesh->SetColor(0,1,ARGB(255,100,100,100));
mesh->SetColor(1,0,ARGB(255,100,100,100));
mesh->SetColor(0,0,ARGB(255,200,200,200));
mHasFocus = false;
mTargetScale = 1.0f;
return true;
}
bool ShopItem::ButtonPressed()
{
return (quantity >0);
}
ShopItems::ShopItems(int id, JGuiListener* listener, JLBFont* font, int x, int y, MTGAllCards * _collection, int _setIds[]): JGuiController(id, listener), mX(x), mY(y), mFont(font), collection(_collection){
mHeight = 0;
showPriceDialog = -1;
dialog = NULL;
pricelist = NEW PriceList(RESPATH"/settings/prices.dat",_collection);
playerdata = NEW PlayerData(_collection);
display = NULL;
for (int i=0; i < SHOP_BOOSTERS; i++){
setIds[i] = _setIds[i];
};
myCollection = NEW DeckDataWrapper(NEW MTGDeck(options.profileFile(PLAYER_COLLECTION).c_str(), _collection));
showCardList = true;
mBgAA = NULL;
mBgAATex = resources.RetrieveTexture("shop_aliasing.png",RETRIEVE_LOCK);
if(mBgAATex){
mBgAA = resources.RetrieveQuad("shop_aliasing.png");
mBgAA->SetTextureRect(0,1,250,119);
}
lightAlpha = 0;
alphaChange = 0;
}
void ShopItems::Add(int cardid){
int rnd = (rand() % 20);
int price = pricelist->getPrice(cardid);
price = price + price * (rnd -10)/100;
float xy[] = {_x1[mCount],_y1[mCount],_x2[mCount],_y2[mCount],_x3[mCount],_y3[mCount],_x4[mCount],_y4[mCount]};
JGuiController::Add(NEW ShopItem(mCount, mFont, cardid, xy, (mCount == 0),collection, price,myCollection));
mHeight += 22;
}
void ShopItems::Add(char * text, JQuad * quad,JQuad * thumb, int price){
float xy[] = {_x1[mCount],_y1[mCount],_x2[mCount],_y2[mCount],_x3[mCount],_y3[mCount],_x4[mCount],_y4[mCount]};
JGuiController::Add(NEW ShopItem(mCount, mFont, text, quad, thumb, xy, (mCount == 0), price));
mHeight += 22;
}
void ShopItems::Update(float dt){
if (display){
display->Update(dt);
}else{
if (showPriceDialog!=-1){
ShopItem * item = ((ShopItem *)mObjects[showPriceDialog]);
int price = item->price;
char buffer[4096];
sprintf(buffer,"%s : %i credits",item->getText(),price);
if(!dialog){
dialog = NEW SimpleMenu(1,this,Constants::MENU_FONT,SCREEN_WIDTH-300,SCREEN_HEIGHT/2,buffer);
dialog->Add(1,"Yes");
dialog->Add(2,"No");
if(options[Options::CHEATMODE].number) {
dialog->Add(3,"*Steal 1,000 credits*");
}
}
else{
dialog->Update(dt);
}
}else{
SAFE_DELETE(dialog);
JGuiController::Update(dt);
}
}
alphaChange = (500 - (rand() % 1000)) * dt;
lightAlpha+= alphaChange;
if (lightAlpha < 0) lightAlpha = 0;
if (lightAlpha > 50) lightAlpha = 50;
}
void ShopItems::Render(){
JGuiController::Render();
JRenderer * r = JRenderer::GetInstance();
if (mBgAA)
r->RenderQuad(mBgAA,0,SCREEN_HEIGHT-127);
JQuad * quad = resources.RetrieveTempQuad("shop_light.jpg",TEXTURE_SUB_5551);
if (quad){
r->EnableTextureFilter(false);
r->SetTexBlend(BLEND_SRC_ALPHA, BLEND_ONE);
quad->SetColor(ARGB(lightAlpha,255,255,255));
r->RenderQuad(quad,0,0);
r->SetTexBlend(BLEND_SRC_ALPHA, BLEND_ONE_MINUS_SRC_ALPHA);
r->EnableTextureFilter(true);
}
if (display) display->Render();
if (showPriceDialog!=-1){
if(dialog){
dialog->Render();
}
}
mFont->SetColor(ARGB(255,255,255,255));
char c[4096];
r->FillRect(0,SCREEN_HEIGHT-17,SCREEN_WIDTH,17,ARGB(128,0,0,0));
sprintf(c, "%s", _("[]:other cards").c_str());
unsigned int len = 4 + mFont->GetStringWidth(c);
mFont->DrawString(c,SCREEN_WIDTH-len,SCREEN_HEIGHT-14);
char credits[512];
sprintf(credits,_("credits: %i").c_str(), playerdata->credits);
mFont->SetColor(ARGB(200,0,0,0));
mFont->DrawString(credits, 5, SCREEN_HEIGHT - 12);
mFont->SetColor(ARGB(255,255,255,255));
mFont->DrawString(credits, 5, SCREEN_HEIGHT - 14);
if(mCurr >= 0){
mFont->SetColor(ARGB(255,255,255,0));
ShopItem * item = ((ShopItem *)mObjects[mCurr]);
mFont->DrawString(item->mText.c_str(), SCREEN_WIDTH/2 - 50, SCREEN_HEIGHT - 14,JGETEXT_CENTER);
mFont->SetColor(ARGB(255,255,255,255));
}
if (showCardList){
r->FillRoundRect(290,5, 160, mCount * 20 + 15,5,ARGB(200,0,0,0));
for (int i = 0; i< mCount; ++i){
if (!mObjects[i]) continue;
ShopItem * s = (ShopItem *)(mObjects[i]);
if (i == mCurr) mFont->SetColor(ARGB(255,255,255,0));
else mFont->SetColor(ARGB(255,255,255,255));
char buffer[512];
sprintf(buffer, "%s", s->getText());
float x = 300;
float y = 10 + 20*i;
mFont->DrawString(buffer,x,y);
}
}
}
void ShopItems::pricedialog(int id, int mode){
if (mode){
showPriceDialog = id;
}else{
showPriceDialog = -1;
}
}
void ShopItems::ButtonPressed(int controllerId, int controlId){
if (controllerId == 12){
safeDeleteDisplay();
return;
}
ShopItem * item = ((ShopItem *)mObjects[showPriceDialog]);
int price = item->price;
switch(controlId){
case 1:
if (playerdata->credits >= price){
playerdata->credits -= price;
if (item->card){
int rnd = (rand() % 25);
price = price + (rnd * price)/100;
pricelist->setPrice(item->card->getMTGId(),price);
playerdata->collection->add(item->card);
item->quantity--;
myCollection->Add(item->card);
item->nameCount++;
item->price = price;
}else{
safeDeleteDisplay();
display = NEW CardDisplay(12,NULL, SCREEN_WIDTH - 200, SCREEN_HEIGHT/2,this,NULL,5);
MTGDeck * tempDeck = NEW MTGDeck(playerdata->collection->database);
int rare_or_mythic = Constants::RARITY_R;
int rnd = rand() % 8;
if (rnd == 0) rare_or_mythic = Constants::RARITY_M;
int sets[] = {setIds[showPriceDialog]};
MTGSetInfo* si = setlist.getInfo(setIds[showPriceDialog]);
tempDeck->addRandomCards(si->booster[MTGSetInfo::RARE], sets,1,rare_or_mythic);
tempDeck->addRandomCards(si->booster[MTGSetInfo::UNCOMMON], sets,1,Constants::RARITY_U);
tempDeck->addRandomCards(si->booster[MTGSetInfo::COMMON], sets,1,Constants::RARITY_C);
tempDeck->addRandomCards(si->booster[MTGSetInfo::LAND], sets,1,Constants::RARITY_L);
//Check for duplicates. Does not guarentee none, just makes them extremely unlikely.
//Code is kind of inefficient, but shouldn't be used often enough to matter.
int loops=0;
for(map<int,int>::iterator it = tempDeck->cards.begin();it!= tempDeck->cards.end() && loops < 15;it++,loops++){
int dupes = it->second - 1;
if(dupes <= 0)
continue;
for(int x=0;x<dupes;x++)
tempDeck->remove(it->first);
int rarity = (int) tempDeck->database->getCardById(it->first)->getRarity();
tempDeck->addRandomCards(dupes,sets,1,rarity);
it = tempDeck->cards.begin();
}
playerdata->collection->add(tempDeck);
myCollection->Add(tempDeck);
for (int j = 0; j < mCount; j++){
ShopItem * si = ((ShopItem *)mObjects[j]);
si->updateCount(myCollection);
}
int i = 0;
for(int cycle=0;cycle<4;cycle++)
for (map<int,int>::iterator it = tempDeck->cards.begin(); it!=tempDeck->cards.end(); it++){
MTGCard * c = tempDeck->getCardById(it->first);
char rarity = c->getRarity();
if((cycle == 0 && rarity == Constants::RARITY_L)
|| (cycle == 1 && rarity == Constants::RARITY_C)
|| (cycle == 2 && rarity == Constants::RARITY_U)
|| (cycle == 3 && (rarity == Constants::RARITY_R || rarity == Constants::RARITY_M)))
for (int j = 0; j < it->second; j++){
MTGCardInstance * card = NEW MTGCardInstance(c, NULL);
displayCards[i] = card;
display->AddCard(card);
i++;
}
}
delete tempDeck;
}
//Check if we just scored an award...
if(myCollection && myCollection->totalPrice() > 10000){
GameOptionAward * goa = dynamic_cast<GameOptionAward *>(&options[Options::AWARD_COLLECTOR]);
if(goa)
goa->giveAward();
}
showPriceDialog = -1;
}else{
//error not enough money
}
break;
case 2:
if (item->card){
int rnd = (rand() % 25);
price = price - (rnd * price)/100;
pricelist->setPrice(item->card->getMTGId(),price);
}
showPriceDialog = -1;
break;
case 3: // (PSY) Cheatmode: get free money
playerdata->credits += 1000;
break;
}
}
void ShopItems::safeDeleteDisplay(){
if (!display) return;
for (int i = 0; i < display->mCount; i++){
delete displayCards[i];
}
SAFE_DELETE(display);
}
void ShopItems::saveAll(){
savePriceList();
playerdata->save();
}
void ShopItems::savePriceList(){
pricelist->save();
}
ShopItems::~ShopItems(){
SAFE_DELETE(pricelist);
SAFE_DELETE(playerdata);
SAFE_DELETE(dialog);
safeDeleteDisplay();
SAFE_DELETE(myCollection);
resources.Release(mBgAATex);
}
ostream& ShopItem::toString(ostream& out) const
{
return out << "ShopItem ::: mHasFocus : " << mHasFocus
<< " ; mFont : " << mFont
<< " ; mText : " << mText
<< " ; quad : " << quad
<< " ; thumb : " << thumb
<< " ; mScale : " << mScale
<< " ; mTargetScale : " << mTargetScale
<< " ; nameCount : " << nameCount
<< " ; quantity : " << quantity
<< " ; card : " << card
<< " ; price : " << price;
}
bool ShopItems::CheckUserInput(JButton key){
if (display && display->CheckUserInput(key))
return true;
if (showPriceDialog == -1) {
JButton buttons[] = {JGE_BTN_LEFT, JGE_BTN_DOWN, JGE_BTN_RIGHT, JGE_BTN_UP, JGE_BTN_OK};
for (int i = 0; i < 5; ++i)
if (key == buttons[i])
showCardList = false;
if (key == JGE_BTN_CANCEL) {
options[Options::DISABLECARDS].number = !options[Options::DISABLECARDS].number;
vector<JGuiObject*>::iterator it;
for(it=mObjects.begin();it!=mObjects.end();it++){
ShopItem * si = dynamic_cast<ShopItem*>(*it);
if(si)
si->updateThumb();
}
return true;
}
if (key == JGE_BTN_SEC){
showCardList = !showCardList;
return true;
}
}
else if(dialog)
return dialog->CheckUserInput(key);
return JGuiController::CheckUserInput(key);
}
+1 -1
View File
@@ -168,7 +168,7 @@ void SimpleMenu::Add(int id, const char * text,string desc, bool forceFocus){
JGuiController::Add(smi);
if (mCount <= maxItems) mHeight += LINE_HEIGHT;
if (forceFocus){
mObjects[mCurr]->Leaving(PSP_CTRL_DOWN);
mObjects[mCurr]->Leaving(JGE_BTN_DOWN);
mCurr = mCount-1;
smi->Entering();
}
+32 -42
View File
@@ -184,79 +184,69 @@ void SimplePad::MoveSelection(unsigned char moveto)
moveto = KPD_INPUT;
else if(!bShowCancel && moveto == KPD_CANCEL )
moveto = KPD_SPACE;
if(selected < KPD_MAX && selected >= 0)
if (selected < KPD_MAX && selected >= 0)
priorKey = selected;
if(moveto < KPD_MAX) {
if (moveto < KPD_MAX)
selected = moveto;
}
else if(moveto == KPD_INPUT)
else if (moveto == KPD_INPUT)
selected = KPD_INPUT;
}
void SimplePad::Update(float dt){
JGE * mEngine = JGE::GetInstance();
u32 key = mEngine->ReadButton();
//Start button changes capslock setting.
if(key & PSP_CTRL_START)
if (key == JGE_BTN_MENU)
{
if(selected != KPD_OK)
if (selected != KPD_OK)
selected = KPD_OK;
else
Finish();
}
else if(key & PSP_CTRL_SELECT){
else if (key == JGE_BTN_CTRL)
bCapslock = !bCapslock;
}
if(selected == KPD_SPACE){
if(bShowCancel && mEngine->GetButtonClick(PSP_CTRL_RIGHT))
if (selected == KPD_SPACE){
if (bShowCancel && mEngine->GetButtonClick(JGE_BTN_RIGHT))
selected = KPD_CANCEL;
else if (key & PSP_CTRL_LEFT || key & PSP_CTRL_RIGHT
|| key & PSP_CTRL_UP || key & PSP_CTRL_DOWN)
else if (key == JGE_BTN_LEFT || key == JGE_BTN_RIGHT
|| key == JGE_BTN_UP || key == JGE_BTN_DOWN)
selected = priorKey;
} //Moving within/from the text field.
else if(selected == KPD_INPUT){
if (key & PSP_CTRL_DOWN )
else if (selected == KPD_INPUT){
if (key == JGE_BTN_DOWN )
selected = priorKey;
if (key & PSP_CTRL_LEFT){
if(cursor > 0)
cursor--;
}
else if (key & PSP_CTRL_RIGHT){
if(cursor < buffer.size())
cursor++;
}
if (key == JGE_BTN_LEFT && cursor > 0) cursor--;
else if (key == JGE_BTN_RIGHT && cursor < buffer.size()) cursor++;
}
else if(selected >= 0 && keys[selected]){
if (key & PSP_CTRL_LEFT)
else if (selected >= 0 && keys[selected]){
if (key == JGE_BTN_LEFT)
MoveSelection(keys[selected]->adjacency[KPD_LEFT]);
else if (key & PSP_CTRL_RIGHT)
else if (key == JGE_BTN_RIGHT)
MoveSelection(keys[selected]->adjacency[KPD_RIGHT]);
if (key & PSP_CTRL_DOWN)
if (key == JGE_BTN_DOWN)
MoveSelection(keys[selected]->adjacency[KPD_DOWN]);
else if (key & PSP_CTRL_UP)
else if (key == JGE_BTN_UP)
MoveSelection(keys[selected]->adjacency[KPD_UP]);
}
//These bits require a valid key...
if(selected >= 0 && selected < nbitems && keys[selected]){
if (key & PSP_CTRL_CIRCLE)
pressKey(keys[selected]->id);
if (selected >= 0 && selected < nbitems && keys[selected])
if (key == JGE_BTN_OK)
pressKey(keys[selected]->id);
if (buffer.size() > 0 && key == JGE_BTN_SEC)
buffer = buffer.substr(0, buffer.size() - 1);
if (buffer.size() && key == JGE_BTN_PREV) {
if (cursor > 0) cursor--;
}
if (buffer.size() > 0 && key & PSP_CTRL_CROSS)
buffer = buffer.substr(0,buffer.size() - 1);
if (buffer.size() && key & PSP_CTRL_LTRIGGER){
if(cursor > 0)
cursor--;
}
else if (key & PSP_CTRL_RTRIGGER){
if(cursor < buffer.size())
else if (key == JGE_BTN_NEXT) {
if (cursor < buffer.size())
cursor++;
else{
else {
buffer += ' ';
cursor = buffer.size();
}
+48 -47
View File
@@ -40,7 +40,7 @@ void WGuiBase::renderBack(WGuiBase * it){
//WGuiItem
void WGuiItem::Entering(u32 key){
void WGuiItem::Entering(JButton key){
mFocus = true;
}
float WGuiItem::minWidth(){
@@ -52,7 +52,7 @@ float WGuiItem::minHeight(){
return mFont->GetHeight();
}
bool WGuiItem::Leaving(u32 key){
bool WGuiItem::Leaving(JButton key){
mFocus = false;
return true;
}
@@ -90,12 +90,12 @@ string WGuiItem::_(string input){
return input;
return ::_(input);
}
bool WGuiItem::CheckUserInput(u32 key){
if(mFocus && key == PSP_CTRL_CIRCLE){
bool WGuiItem::CheckUserInput(JButton key){
if(mFocus && key == JGE_BTN_OK){
updateValue();
return true;
}
return false;
return false;
}
//WDecoStyled
@@ -149,7 +149,7 @@ void WGuiHeader::Render(){
}
bool WGuiMenu::Leaving(u32 key){
bool WGuiMenu::Leaving(JButton key){
int nbitems = (int) items.size();
if(key == buttonNext && currentItem < nbitems-1)
return false;
@@ -163,7 +163,7 @@ bool WGuiMenu::Leaving(u32 key){
mFocus = false;
return true;
}
void WGuiMenu::Entering(u32 key){
void WGuiMenu::Entering(JButton key){
mFocus = true;
//Try to force a selectable option.
@@ -198,7 +198,7 @@ void WGuiMenu::subBack(WGuiBase * item){
}
//WGuiList
WGuiList::WGuiList(string name, WSyncable * syncme): WGuiMenu(PSP_CTRL_DOWN,PSP_CTRL_UP,false,syncme){
WGuiList::WGuiList(string name, WSyncable * syncme): WGuiMenu(JGE_BTN_DOWN, JGE_BTN_UP, false, syncme){
failMsg = "NO OPTIONS AVAILABLE";
width = SCREEN_WIDTH-10;
height = SCREEN_HEIGHT-10;
@@ -237,7 +237,7 @@ void WGuiList::Render(){
if(items[i]->Selectable()) {
currentItem = i;
if(hasFocus())
items[currentItem]->Entering(0);
items[currentItem]->Entering(JGE_BTN_NONE);
break;
}
}
@@ -405,7 +405,7 @@ WDecoConfirm::~WDecoConfirm(){
SAFE_DELETE(confirmMenu);
}
void WDecoConfirm::Entering(u32 key){
void WDecoConfirm::Entering(JButton key){
setFocus(true);
if(it)
@@ -435,7 +435,7 @@ void WDecoConfirm::setData(){
it->setData();
}
bool WDecoConfirm::Leaving(u32 key){
bool WDecoConfirm::Leaving(JButton key){
if(!it)
return true;
@@ -458,9 +458,9 @@ bool WDecoConfirm::Leaving(u32 key){
return false;
}
bool WDecoConfirm::CheckUserInput(u32 key){
bool WDecoConfirm::CheckUserInput(JButton key){
if(hasFocus()){
if (mState == OP_CONFIRMED && key == PSP_CTRL_CIRCLE)
if (mState == OP_CONFIRMED && key == JGE_BTN_OK)
mState = OP_UNCONFIRMED;
if (mState != OP_CONFIRMING && it){
@@ -520,8 +520,8 @@ void WGuiButton::updateValue(){
mListener->ButtonPressed(controller, control);
}
bool WGuiButton::CheckUserInput(u32 key){
if (hasFocus() && key == PSP_CTRL_CIRCLE){
bool WGuiButton::CheckUserInput(JButton key){
if (hasFocus() && key == JGE_BTN_OK){
updateValue();
return true;
}
@@ -605,15 +605,15 @@ void WGuiSplit::setModal(bool val){
return left->setModal(val);
}
bool WGuiSplit::CheckUserInput(u32 key){
bool WGuiSplit::CheckUserInput(JButton key){
if(hasFocus()){
if (!bRight){
if(left->CheckUserInput(key))
return true;
if(key == PSP_CTRL_RIGHT && !isModal()
&& right->Selectable() && left->Leaving(PSP_CTRL_RIGHT)){
if(key == JGE_BTN_RIGHT && !isModal()
&& right->Selectable() && left->Leaving(JGE_BTN_RIGHT)){
bRight = !bRight;
right->Entering(PSP_CTRL_RIGHT);
right->Entering(JGE_BTN_RIGHT);
return true;
}
}
@@ -621,10 +621,10 @@ bool WGuiSplit::CheckUserInput(u32 key){
{
if(right->CheckUserInput(key))
return true;
if (key == PSP_CTRL_LEFT && !isModal()
&& left->Selectable() && right->Leaving(PSP_CTRL_LEFT)){
if (key == JGE_BTN_LEFT && !isModal()
&& left->Selectable() && right->Leaving(JGE_BTN_LEFT)){
bRight = !bRight;
left->Entering(PSP_CTRL_LEFT);
left->Entering(JGE_BTN_LEFT);
return true;
}
}
@@ -640,14 +640,14 @@ void WGuiSplit::Update(float dt){
left->Update(dt);
}
void WGuiSplit::Entering(u32 key){
void WGuiSplit::Entering(JButton key){
mFocus = true;
if(bRight)
right->Entering(key);
else
left->Entering(key);
}
bool WGuiSplit::Leaving(u32 key){
bool WGuiSplit::Leaving(JButton key){
if(bRight){
if(right->Leaving(key)){
@@ -693,7 +693,7 @@ void WGuiSplit::confirmChange(bool confirmed){
}
//WGuiMenu
WGuiMenu::WGuiMenu(u32 next = PSP_CTRL_RIGHT, u32 prev = PSP_CTRL_LEFT, bool m, WSyncable * syncme): WGuiItem(""){
WGuiMenu::WGuiMenu(JButton next = JGE_BTN_RIGHT, JButton prev = JGE_BTN_LEFT, bool m, WSyncable * syncme): WGuiItem(""){
buttonNext = next;
buttonPrev = prev;
currentItem = -1;
@@ -738,14 +738,14 @@ void WGuiMenu::Add(WGuiBase * it){
if(it)
items.push_back(it);
}
bool WGuiMenu::CheckUserInput(u32 key){
bool WGuiMenu::CheckUserInput(JButton key){
bool kidModal = false;
bool handledInput = false;
int nbitems = (int) items.size();
JGE * mEngine = JGE::GetInstance();
if(!mEngine->GetButtonState(held)) //Key isn't held down.
held = 0;
held = JGE_BTN_NONE;
if(currentItem >= 0 && currentItem < nbitems)
kidModal = items[currentItem]->isModal();
@@ -790,32 +790,34 @@ void WGuiMenu::syncMove(){
while(i > 0 && sync->next())
i = currentItem - sync->getPos();
}
bool WGuiMenu::isButtonDir(u32 key, int dir){
bool WGuiMenu::isButtonDir(JButton key, int dir){
if(!mDPad)
return ((dir > 0 && key == buttonNext) || (dir <= 0 && key == buttonPrev));
if(dir <= 0){
switch(buttonPrev){
case PSP_CTRL_LEFT:
if(key == PSP_CTRL_UP)
case JGE_BTN_LEFT:
if(key == JGE_BTN_UP)
return true;
break;
case PSP_CTRL_UP:
if(key == PSP_CTRL_LEFT)
case JGE_BTN_UP:
if(key == JGE_BTN_LEFT)
return true;
break;
default: ; // Nothing
}
return (key == buttonPrev);
}else {
switch(buttonNext){
case PSP_CTRL_RIGHT:
if(key == PSP_CTRL_DOWN)
case JGE_BTN_RIGHT:
if(key == JGE_BTN_DOWN)
return true;
break;
case PSP_CTRL_DOWN:
if(key == PSP_CTRL_RIGHT)
case JGE_BTN_DOWN:
if(key == JGE_BTN_RIGHT)
return true;
break;
default: ; // Nothing
}
return (key == buttonNext);
}
@@ -1259,7 +1261,7 @@ void WGuiListRow::Render(){
if(items[i]->Selectable()) {
currentItem = i;
if(hasFocus())
items[currentItem]->Entering(0);
items[currentItem]->Entering(JGE_BTN_NONE);
break;
}
}
@@ -1312,8 +1314,8 @@ void WGuiListRow::Render(){
setHeight(tallestRow*numRows+10);
}
WGuiListRow::WGuiListRow(string n, WSyncable * s) : WGuiList(n,s) {
buttonNext = PSP_CTRL_RIGHT;
buttonPrev = PSP_CTRL_LEFT;
buttonNext = JGE_BTN_RIGHT;
buttonPrev = JGE_BTN_LEFT;
width = SCREEN_WIDTH;
height = 20;
}
@@ -1367,7 +1369,7 @@ void WGuiFilters::buildList(){
subMenu = NULL;
list->Add(NEW WGuiHeader(displayValue));
list->Add(wgs);
list->Entering(0);
list->Entering(JGE_BTN_NONE);
}
WGuiFilters::WGuiFilters(string header, WSrcCards * src) : WGuiItem(header) {
bFinished = false;
@@ -1417,12 +1419,11 @@ void WGuiFilters::Update(float dt){
it = wgl->items.erase(it);
bDeleted = true;
}
if(bDeleted){
wgl->Entering(0);
}
if(bDeleted)
wgl->Entering(JGE_BTN_NONE);
}
}
void WGuiFilters::Entering(u32 key){
void WGuiFilters::Entering(JButton key){
bFinished = false;
WGuiItem::Entering(key);
}
@@ -1439,10 +1440,10 @@ void WGuiFilters::Render(){
if(subMenu && !subMenu->closed)
subMenu->Render();
}
bool WGuiFilters::CheckUserInput(u32 key){
bool WGuiFilters::CheckUserInput(JButton key){
if(subMenu && !subMenu->closed && subMenu->CheckUserInput(key))
return true;
if(key == PSP_CTRL_CROSS){//|| key == PSP_CTRL_START){
if(key == JGE_BTN_SEC){//|| key == JGE_BTN_MENU){
//TODO Pop up a "Are you sure?" dialog.
return true;
}
@@ -1729,4 +1730,4 @@ string WGuiFilterItem::getCode(){
if(mState != STATE_FINISHED || !mCode.size())
return "";
return mCode;
}
}