* Hand option.
This commit is contained in:
jean.chalard
2009-09-22 07:39:24 +00:00
parent 71d4818646
commit f6aba5c5cb
9 changed files with 174 additions and 29 deletions
+1 -1
View File
@@ -54,7 +54,7 @@ class ObjectSelector : public GuiLayer
bool CheckUserInput(u32 key); bool CheckUserInput(u32 key);
void Update(float dt); void Update(float dt);
void Render(); void Render();
void Limit(LimitorFunctor<T>* limitor); void Limit(LimitorFunctor<T>* limitor, SelectorZone);
void Push(); void Push();
void Pop(); void Pop();
+5 -3
View File
@@ -31,7 +31,8 @@ struct Options {
static const string ACTIVE_PROFILE; static const string ACTIVE_PROFILE;
static const string ACTIVE_THEME; static const string ACTIVE_THEME;
static const string ACTIVE_MODE; static const string ACTIVE_MODE;
static const string HANDMODE; static const string CLOSEDHAND;
static const string HANDDIRECTION;
}; };
struct Metrics { struct Metrics {
@@ -78,7 +79,8 @@ public:
PIXEL_TYPE asColor(PIXEL_TYPE fallback = ARGB(255,255,255,255)); PIXEL_TYPE asColor(PIXEL_TYPE fallback = ARGB(255,255,255,255));
bool isDefault(); //Returns true when number is 0 abd string is "" or "default" bool isDefault(); //Returns true when number is 0 abd string is "" or "default"
GameOption(int value = 0); GameOption(int value = 0);
GameOption(string value); GameOption(string);
GameOption(int, string);
}; };
@@ -116,7 +118,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=false,bool relative=false); string profileFile(string filename="", string fallback="", bool sanity=true,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.
+2
View File
@@ -28,6 +28,8 @@ class GuiHand : public GuiLayer
static const float OpenX; static const float OpenX;
static const float ClosedX; static const float ClosedX;
static const float OpenY;
static const float ClosedY;
protected: protected:
const MTGHand* hand; const MTGHand* hand;
+25
View File
@@ -206,4 +206,29 @@ class OptionsMenu
}; };
class OptionEnum : public OptionItem {
protected:
typedef pair<int, string> assoc;
unsigned index;
vector<assoc> values;
public:
OptionEnum(string id, string displayValue) : OptionItem(id, displayValue), index(0) {};
virtual void Reload();
virtual void Render();
virtual void setData();
virtual void updateValue();
virtual ostream& toString(ostream& out) const;
};
class OptionClosedHand : public OptionEnum {
public:
enum { INVISIBLE = 0, VISIBLE = 1 };
OptionClosedHand(string id, string displayValue);
};
class OptionHandDirection : public OptionEnum {
public:
enum { VERTICAL = 0, HORIZONTAL = 1};
OptionHandDirection(string id, string displayValue);
};
#endif #endif
+13 -2
View File
@@ -85,6 +85,9 @@ void CardSelector::Pop()
{ {
active = fetchMemory(memoryStack.top()); active = fetchMemory(memoryStack.top());
memoryStack.pop(); memoryStack.pop();
SelectorZone oldowner;
if (CardView *q = dynamic_cast<CardView*>(oldactive)) oldowner = q->owner; else oldowner = nullZone;
if (nullZone != oldowner) lasts[oldowner] = SelectorMemory(oldactive);
} }
if (active != oldactive) if (active != oldactive)
{ {
@@ -183,13 +186,21 @@ void CardSelector::Render()
} }
template<> template<>
void CardSelector::Limit(LimitorFunctor<Target>* limitor) void CardSelector::Limit(LimitorFunctor<Target>* limitor, SelectorZone destzone)
{ {
this->limitor = limitor; this->limitor = limitor;
if (limitor && !limitor->select(active)) if (limitor && !limitor->select(active))
{ {
Target* oldactive = active; Target* oldactive = active;
active = closest<True>(cards, limitor, active); SelectorZone oldowner;
if (CardView *q = dynamic_cast<CardView*>(oldactive)) oldowner = q->owner; else oldowner = nullZone;
if (oldowner != destzone)
{
if (nullZone != destzone)
if (PlayGuiObject* old = fetchMemory(lasts[destzone]))
active = old;
lasts[oldowner] = SelectorMemory(oldactive);
}
if (limitor && !limitor->select(active)) active = NULL; if (limitor && !limitor->select(active)) active = NULL;
if (active != oldactive) if (active != oldactive)
{ {
+7 -5
View File
@@ -42,6 +42,8 @@ const string Options::MOMIR_MODE_UNLOCKED = "_gprx_rimom"; //haha
const string Options::EVILTWIN_MODE_UNLOCKED = "_gprx_eviltwin"; const string Options::EVILTWIN_MODE_UNLOCKED = "_gprx_eviltwin";
const string Options::RANDOMDECK_MODE_UNLOCKED = "_gprx_rnddeck"; const string Options::RANDOMDECK_MODE_UNLOCKED = "_gprx_rnddeck";
const string Options::CACHESIZE = "_gcacheSize"; const string Options::CACHESIZE = "_gcacheSize";
const string Options::CLOSEDHAND = "closed_hand";
const string Options::HANDDIRECTION = "hand_direction";
//Theme metrics //Theme metrics
const string Metrics::LOADING_TC = "_tLoadingTC"; const string Metrics::LOADING_TC = "_tLoadingTC";
const string Metrics::STATS_TC = "_tStatsTC"; const string Metrics::STATS_TC = "_tStatsTC";
@@ -76,6 +78,7 @@ const string Metrics::KEYPAD_TC = "_tKeypadTC";
GameOption::GameOption(int value) : number(value){} GameOption::GameOption(int value) : number(value){}
GameOption::GameOption(string value) : number(0), str(value) {} GameOption::GameOption(string value) : number(0), str(value) {}
GameOption::GameOption(int num, string str) : number(num), str(str) {}
bool GameOption::isDefault(){ bool GameOption::isDefault(){
string test = str; string test = str;
@@ -203,7 +206,6 @@ 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){
@@ -224,11 +226,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(); string temp = profileFile("","",false,false);
MAKEDIR(temp.c_str()); MAKEDIR(temp.c_str());
temp+="/stats"; temp+="/stats";
MAKEDIR(temp.c_str()); MAKEDIR(temp.c_str());
temp = profileFile(PLAYER_SETTINGS); temp = profileFile(PLAYER_SETTINGS,"",false);
profileOptions->save(); profileOptions->save();
} }
@@ -290,7 +292,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)); profileOptions = NEW GameOptions(profileFile(PLAYER_SETTINGS,"",false));
//Load theme options //Load theme options
if(!themeOptions){ if(!themeOptions){
@@ -344,7 +346,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).c_str(), theGame->collection); MTGDeck *mCollection = NEW MTGDeck(options.profileFile(PLAYER_COLLECTION,"",false).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")){
+5
View File
@@ -42,6 +42,11 @@ void GameStateOptions::Start()
optionsTabs = NEW OptionsMenu(); optionsTabs = NEW OptionsMenu();
optionsTabs->Add(optionsList); optionsTabs->Add(optionsList);
optionsList = NEW OptionsList("Game");
optionsList->Add(NEW OptionClosedHand(Options::CLOSEDHAND, "Closed hand"));
optionsList->Add(NEW OptionHandDirection(Options::HANDDIRECTION, "Hand direction"));
optionsTabs->Add(optionsList);
optionsList = NEW OptionsList("Profiles"); optionsList = NEW OptionsList("Profiles");
OptionNewProfile * key = NEW OptionNewProfile("","New Profile"); OptionNewProfile * key = NEW OptionNewProfile("","New Profile");
key->bShowValue = false; key->bShowValue = false;
+48 -3
View File
@@ -2,6 +2,7 @@
#include "../include/GameApp.h" #include "../include/GameApp.h"
#include "../include/Trash.h" #include "../include/Trash.h"
#include "../include/GuiHand.h" #include "../include/GuiHand.h"
#include "../include/OptionItem.h"
const float GuiHand::ClosedRowX = 459; const float GuiHand::ClosedRowX = 459;
const float GuiHand::LeftRowX = 420; const float GuiHand::LeftRowX = 420;
@@ -9,6 +10,8 @@ const float GuiHand::RightRowX = 460;
const float GuiHand::OpenX = 394; const float GuiHand::OpenX = 394;
const float GuiHand::ClosedX = 494; const float GuiHand::ClosedX = 494;
const float GuiHand::OpenY = SCREEN_HEIGHT - 50;
const float GuiHand::ClosedY = SCREEN_HEIGHT;
bool HandLimitor::select(Target* t) bool HandLimitor::select(Target* t)
{ {
@@ -77,6 +80,13 @@ void GuiHandOpponent::Render()
GuiHandSelf::GuiHandSelf(CardSelector* cs, MTGHand* hand) : GuiHand(cs, hand), state(Closed), backpos(ClosedX, SCREEN_HEIGHT - 250, 1.0, 0, 255) GuiHandSelf::GuiHandSelf(CardSelector* cs, MTGHand* hand) : GuiHand(cs, hand), state(Closed), backpos(ClosedX, SCREEN_HEIGHT - 250, 1.0, 0, 255)
{ {
limitor = NEW HandLimitor(this); limitor = NEW HandLimitor(this);
if (OptionHandDirection::HORIZONTAL == options[Options::HANDDIRECTION].number)
{
backpos.t = M_PI/2;
backpos.y = ClosedY;
backpos.x = SCREEN_WIDTH - 30 * 7 - 14;
backpos.UpdateNow();
}
} }
GuiHandSelf::~GuiHandSelf(){ GuiHandSelf::~GuiHandSelf(){
@@ -86,12 +96,27 @@ GuiHandSelf::~GuiHandSelf(){
void GuiHandSelf::Repos() void GuiHandSelf::Repos()
{ {
float y = 48.0; float y = 48.0;
if (Closed == state) if (Closed == state && OptionClosedHand::VISIBLE == options[Options::CLOSEDHAND].number)
for (vector<CardView*>::iterator it = cards.begin(); it != cards.end(); ++it) for (vector<CardView*>::iterator it = cards.begin(); it != cards.end(); ++it)
{ {
(*it)->x = ClosedRowX; (*it)->y = y; (*it)->x = ClosedRowX; (*it)->y = y;
y += 20; y += 20;
} }
else
{
bool q = (Closed == state);
if (OptionHandDirection::HORIZONTAL == options[Options::HANDDIRECTION].number)
{
y = SCREEN_WIDTH - 30;
for (vector<CardView*>::iterator it = cards.begin(); it != cards.end(); ++it)
{
(*it)->x = y;
(*it)->y = SCREEN_HEIGHT - 30;
y -= 30;
(*it)->alpha = (q ? 0 : 255);
}
backpos.x = y + SCREEN_HEIGHT - 14;
}
else else
{ {
bool flip = false; bool flip = false;
@@ -101,6 +126,8 @@ void GuiHandSelf::Repos()
(*it)->y = y; (*it)->y = y;
if (flip) y += 65; if (flip) y += 65;
flip = !flip; flip = !flip;
(*it)->alpha = (q ? 0 : 255);
}
} }
} }
} }
@@ -113,9 +140,25 @@ bool GuiHandSelf::CheckUserInput(u32 key)
{ {
state = (Open == state ? Closed : Open); state = (Open == state ? Closed : Open);
if (Open == state) cs->Push(); if (Open == state) cs->Push();
cs->Limit(Open == state ? limitor : NULL); cs->Limit(Open == state ? limitor : NULL, CardSelector::handZone);
if (Closed == state) cs->Pop(); if (Closed == state) cs->Pop();
if (OptionHandDirection::HORIZONTAL == options[Options::HANDDIRECTION].number)
backpos.y = Open == state ? OpenY : ClosedY;
else
backpos.x = Open == state ? OpenX : ClosedX; backpos.x = Open == state ? OpenX : ClosedX;
if (Open == state && OptionClosedHand::INVISIBLE == options[Options::CLOSEDHAND].number)
{
if (OptionHandDirection::HORIZONTAL == options[Options::HANDDIRECTION].number)
for (vector<CardView*>::iterator it = cards.begin(); it != cards.end(); ++it)
{
(*it)->y = SCREEN_HEIGHT + 30; (*it)->UpdateNow();
}
else
for (vector<CardView*>::iterator it = cards.begin(); it != cards.end(); ++it)
{
(*it)->x = SCREEN_WIDTH + 30; (*it)->UpdateNow();
}
}
Repos(); Repos();
return true; return true;
} }
@@ -131,6 +174,7 @@ void GuiHandSelf::Update(float dt)
void GuiHandSelf::Render() void GuiHandSelf::Render()
{ {
backpos.Render(back); backpos.Render(back);
if (OptionClosedHand::VISIBLE == options[Options::CLOSEDHAND].number || state == Open)
for (vector<CardView*>::iterator it = cards.begin(); it != cards.end(); ++it) for (vector<CardView*>::iterator it = cards.begin(); it != cards.end(); ++it)
(*it)->Render(); (*it)->Render();
} }
@@ -138,6 +182,7 @@ void GuiHandSelf::Render()
float GuiHandSelf::LeftBoundary() float GuiHandSelf::LeftBoundary()
{ {
float min = SCREEN_WIDTH + 10; float min = SCREEN_WIDTH + 10;
if (OptionClosedHand::VISIBLE == options[Options::CLOSEDHAND].number || state == Open)
for (vector<CardView*>::iterator it = cards.begin(); it != cards.end(); ++it) for (vector<CardView*>::iterator it = cards.begin(); it != cards.end(); ++it)
if ((*it)->x - CardGui::Width / 2 < min) min = (*it)->x - CardGui::Width / 2; if ((*it)->x - CardGui::Width / 2 < min) min = (*it)->x - CardGui::Width / 2;
return min; return min;
@@ -191,7 +236,7 @@ int GuiHandOpponent::receiveEventPlus(WEvent* e)
card = NEW CardView(CardSelector::handZone, event->card, *(event->card->view)); card = NEW CardView(CardSelector::handZone, event->card, *(event->card->view));
else else
card = NEW CardView(CardSelector::handZone, event->card, ClosedRowX, 0); card = NEW CardView(CardSelector::handZone, event->card, ClosedRowX, 0);
card->t = -4*M_PI; card->alpha = 255; card->alpha = 255; card->t = -4*M_PI;
cards.push_back(card); cards.push_back(card);
return 1; return 1;
} }
+55 -2
View File
@@ -810,6 +810,59 @@ void OptionVolume::updateValue(){
value=0; value=0;
} }
OptionVolume::OptionVolume(string _id, string _displayName, bool _bMusic): OptionInteger(_id, _displayName, 100, 10,0,"Muted") { OptionVolume::OptionVolume(string id, string displayName, bool music): OptionInteger(id, displayName, 100, 10, 0, "Muted") {
bMusic = _bMusic; bMusic = music;
} }
void OptionEnum::setData()
{
options[id] = GameOption(values[index].first, values[index].second);
}
void OptionEnum::updateValue()
{
++index;
if (index >= values.size()) index = 0;
}
void OptionEnum::Render()
{
JLBFont * mFont = resources.GetJLBFont("f3");
if (hasFocus)
mFont->SetColor(options[Metrics::OPTION_ITEM_TCH].asColor(ARGB(255,255,255,0)));
else
mFont->SetColor(options[Metrics::OPTION_ITEM_TC].asColor());
JRenderer * renderer = JRenderer::GetInstance();
renderer->FillRoundRect(x-5,y-2,width-x-5,height,2,options[Metrics::OPTION_ITEM_FC].asColor(ARGB(150,50,50,50)));
mFont->DrawString(displayValue.c_str(),x,y);
mFont->DrawString(values[index].second.c_str(), width -10, y, JGETEXT_RIGHT);
}
void OptionEnum::Reload()
{
for (vector<assoc>::iterator it = values.begin(); it != values.end(); ++it)
if (it->second == options[id].str)
{
index = it - values.begin();
return;
}
index = 0;
}
ostream& OptionEnum::toString(ostream& out) const
{
return (out << values[index].second);
}
OptionClosedHand::OptionClosedHand(string id, string displayName) : OptionEnum(id, displayName)
{
values.push_back(assoc(INVISIBLE, "invisible"));
values.push_back(assoc(VISIBLE, "visible"));
Reload();
};
OptionHandDirection::OptionHandDirection(string id, string displayName) : OptionEnum(id, displayName)
{
values.push_back(assoc(VERTICAL, "vertical"));
values.push_back(assoc(HORIZONTAL, "horizontal"));
Reload();
};