Jeck - Added filtering by card's first letter. This is pretty much the last filter I can think of, except possibly some more complex ones like the mana producer filter.

This commit is contained in:
wagic.jeck
2010-02-08 23:10:45 +00:00
parent 251f89d7b9
commit e5be940766
4 changed files with 46 additions and 1 deletions

View File

@@ -93,6 +93,15 @@ public:
protected:
int setid;
};
class WCFilterLetter: public WCardFilter{
public:
WCFilterLetter(string arg);
bool isMatch(MTGCard * c);
string getCode();
float filterFee() {return 1.0f;}; //Alpha searches are expensive!
protected:
char alpha;
};
class WCFilterColor: public WCardFilter{
public:
WCFilterColor(int _c) {color = _c;};

View File

@@ -452,6 +452,7 @@ public:
STATE_CANCEL,
BEGIN_FILTERS = 0,
FILTER_SET = BEGIN_FILTERS,
FILTER_ALPHA,
FILTER_RARITY,
FILTER_COLOR,
FILTER_PRODUCE,

View File

@@ -130,6 +130,8 @@ WCardFilter * WCFilterFactory::Terminal(string type, string arg){
return NEW WCFilterOnlyColor(arg);
else if(type == "s" || type == "set")
return NEW WCFilterSet(arg);
else if(type == "alpha")
return NEW WCFilterLetter(arg);
else if(type == "t" || type == "type")
return NEW WCFilterType(arg);
else if(type == "a" || type == "ability")
@@ -145,7 +147,28 @@ WCardFilter * WCFilterFactory::Terminal(string type, string arg){
return NEW WCFilterNULL();
}
//WCFilterLetter
WCFilterLetter::WCFilterLetter(string arg){
if(!arg.size())
alpha = 'a';
else
alpha = tolower(arg[0]);
}
bool WCFilterLetter::isMatch(MTGCard * c){
if(!c || !c->data)
return false;
string s = c->data->getLCName();
if(!s.size())
return false;
if(s[0] == alpha || (alpha == '#' && (isdigit(s[0]) || ispunct(s[0]))))
return true;
return false;
}
string WCFilterLetter::getCode(){
char buf[24];
sprintf(buf,"alpha:%c;",alpha);
return buf;
}
//WCFilterSet
WCFilterSet::WCFilterSet(string arg){
setid = setlist.findSet(arg);

View File

@@ -1532,6 +1532,10 @@ void WGuiFilterItem::updateValue(){
mParent->subMenu->Add(FILTER_TOUGH,"Toughness");
delMenu = false;
}
if(mParent->isAvailable(FILTER_ALPHA)){
mParent->subMenu->Add(FILTER_ALPHA,"First Letter");
delMenu = false;
}
if(!mNew)
mParent->subMenu->Add(-2,"Remove");
mParent->subMenu->Add(-1,"Cancel");
@@ -1605,6 +1609,14 @@ void WGuiFilterItem::updateValue(){
sprintf(buf,"s:%s;",setlist[i].c_str());
addArg((setlist.getInfo(i))->getName(),buf);
}
}else if(filterType == FILTER_ALPHA){
char buf[24], pretty[16];
for(char c='a';c<='z';c++){
sprintf(buf,"alpha:%c;",c);
sprintf(pretty,"Letter %c",toupper(c));
addArg(pretty,buf);
}
addArg("Digit","alpha:#;");
}
mParent->subMenu->Add(-1,"Cancel");
break;