Erwan
-display the number of cards you own with the same name for each individual card in the shop
This commit is contained in:
@@ -44,6 +44,8 @@ class DeckDataWrapper{
|
|||||||
int getCount(int color = -1);
|
int getCount(int color = -1);
|
||||||
int totalPrice();
|
int totalPrice();
|
||||||
void save();
|
void save();
|
||||||
|
int countByName(MTGCard * card);
|
||||||
|
int count(MTGCard * card);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#include "../include/PriceList.h"
|
#include "../include/PriceList.h"
|
||||||
#include "../include/PlayerData.h"
|
#include "../include/PlayerData.h"
|
||||||
#include "../include/CardDisplay.h"
|
#include "../include/CardDisplay.h"
|
||||||
|
#include "../include/DeckDataWrapper.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
using std::string;
|
using std::string;
|
||||||
@@ -25,12 +26,15 @@ class ShopItem:public JGuiObject{
|
|||||||
JQuad * thumb;
|
JQuad * thumb;
|
||||||
float mScale;
|
float mScale;
|
||||||
float mTargetScale;
|
float mTargetScale;
|
||||||
|
DeckDataWrapper * mDDW;
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
int nameCount;
|
||||||
int quantity;
|
int quantity;
|
||||||
MTGCard * card;
|
MTGCard * card;
|
||||||
int price;
|
int price;
|
||||||
ShopItem(int id, JLBFont * font, int _cardid, int x, int y, bool hasFocus, MTGAllCards * collection, int _price);
|
ShopItem(int id, JLBFont * font, int _cardid, int x, int y, bool hasFocus, MTGAllCards * collection, int _price, DeckDataWrapper * ddw);
|
||||||
ShopItem(int id, JLBFont * font, char* text, JQuad * _quad, JQuad * _thumb,int x, int y, bool hasFocus, int _price);
|
ShopItem(int id, JLBFont * font, char* text, JQuad * _quad, JQuad * _thumb,int x, int y, bool hasFocus, int _price);
|
||||||
~ShopItem();
|
~ShopItem();
|
||||||
|
|
||||||
@@ -57,6 +61,7 @@ class ShopItems:public JGuiController,public JGuiListener{
|
|||||||
MTGCardInstance * displayCards[100];
|
MTGCardInstance * displayCards[100];
|
||||||
CardDisplay * display;
|
CardDisplay * display;
|
||||||
void safeDeleteDisplay();
|
void safeDeleteDisplay();
|
||||||
|
DeckDataWrapper * myCollection;
|
||||||
public:
|
public:
|
||||||
ShopItems(int id, JGuiListener* listener, JLBFont* font, int x, int y, MTGAllCards * _collection, int _setIds[]);
|
ShopItems(int id, JGuiListener* listener, JLBFont* font, int x, int y, MTGAllCards * _collection, int _setIds[]);
|
||||||
~ShopItems();
|
~ShopItems();
|
||||||
|
|||||||
@@ -74,6 +74,50 @@ int DeckDataWrapper::Remove(MTGCard * card){
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int DeckDataWrapper::count(MTGCard * card){
|
||||||
|
if(cards.find(card) == cards.end()){
|
||||||
|
cards[card] = 0;
|
||||||
|
}
|
||||||
|
return cards[card];
|
||||||
|
}
|
||||||
|
|
||||||
|
int DeckDataWrapper::countByName(MTGCard * card){
|
||||||
|
string name = card->name;
|
||||||
|
int total = 0;
|
||||||
|
map<MTGCard *,int,Cmp1>::iterator it;
|
||||||
|
it = cards.find(card);
|
||||||
|
if(cards.find(card) == cards.end()){
|
||||||
|
cards[card] = 0;
|
||||||
|
it = cards.find(card);
|
||||||
|
}
|
||||||
|
|
||||||
|
while(it !=cards.end()){
|
||||||
|
MTGCard * _card = (*it).first;
|
||||||
|
if (name.compare(_card->name) !=0){
|
||||||
|
it = cards.end();
|
||||||
|
}else{
|
||||||
|
total+= (*it).second;
|
||||||
|
it++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
it = cards.find(card);
|
||||||
|
it--;
|
||||||
|
while(1){
|
||||||
|
MTGCard * _card = (*it).first;
|
||||||
|
if (name.compare(_card->name) !=0){
|
||||||
|
break;
|
||||||
|
}else{
|
||||||
|
total+= (*it).second;
|
||||||
|
if (it == cards.begin()) break;
|
||||||
|
it--;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
MTGCard * DeckDataWrapper::getNext(MTGCard * previous, int color){
|
MTGCard * DeckDataWrapper::getNext(MTGCard * previous, int color){
|
||||||
map<MTGCard *,int,Cmp1>::iterator it;
|
map<MTGCard *,int,Cmp1>::iterator it;
|
||||||
|
|
||||||
|
|||||||
@@ -17,9 +17,9 @@ ShopItem::ShopItem(int id, JLBFont *font, char* text, JQuad * _quad,JQuad * _thu
|
|||||||
Entering();
|
Entering();
|
||||||
}
|
}
|
||||||
|
|
||||||
ShopItem::ShopItem(int id, JLBFont *font, int _cardid, int x, int y, bool hasFocus, MTGAllCards * collection, int _price): JGuiObject(id), mFont(font), mX(x), mY(y), price(_price){
|
ShopItem::ShopItem(int id, JLBFont *font, int _cardid, int x, int y, bool hasFocus, MTGAllCards * collection, int _price, DeckDataWrapper * ddw): JGuiObject(id), mFont(font), mX(x), mY(y), price(_price){
|
||||||
mHasFocus = hasFocus;
|
mHasFocus = hasFocus;
|
||||||
|
mDDW = ddw;
|
||||||
mScale = 1.0f;
|
mScale = 1.0f;
|
||||||
mTargetScale = 1.0f;
|
mTargetScale = 1.0f;
|
||||||
|
|
||||||
@@ -27,6 +27,8 @@ ShopItem::ShopItem(int id, JLBFont *font, int _cardid, int x, int y, bool hasFoc
|
|||||||
Entering();
|
Entering();
|
||||||
|
|
||||||
card = collection->getCardById(_cardid);
|
card = collection->getCardById(_cardid);
|
||||||
|
nameCount = mDDW->countByName(card);
|
||||||
|
|
||||||
quantity = 1 + (rand() % 4);
|
quantity = 1 + (rand() % 4);
|
||||||
if (card->getRarity() == Constants::RARITY_L) quantity = 50;
|
if (card->getRarity() == Constants::RARITY_L) quantity = 50;
|
||||||
quad = NULL;
|
quad = NULL;
|
||||||
@@ -53,7 +55,18 @@ void ShopItem::Render(){
|
|||||||
mFont->SetColor(ARGB(255,128,128,128));
|
mFont->SetColor(ARGB(255,128,128,128));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (card){
|
||||||
|
thumb = card->getThumb();
|
||||||
|
if (nameCount){
|
||||||
|
char buffer[512];
|
||||||
|
sprintf(buffer, "%s /%i/", card->name.c_str(), nameCount );
|
||||||
|
mText = buffer;
|
||||||
|
}else{
|
||||||
|
mText = card->name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
JRenderer * renderer = JRenderer::GetInstance();
|
JRenderer * renderer = JRenderer::GetInstance();
|
||||||
float x0 = mX;
|
float x0 = mX;
|
||||||
float y0 = mY - (mScale > 1 ? 4 : 0);
|
float y0 = mY - (mScale > 1 ? 4 : 0);
|
||||||
@@ -72,10 +85,7 @@ void ShopItem::Render(){
|
|||||||
mFont->DrawString(mText.c_str(), mX + 30, mY + 8);
|
mFont->DrawString(mText.c_str(), mX + 30, mY + 8);
|
||||||
}
|
}
|
||||||
//renderer->FillRect(mX-5, mY-5,230,35, );
|
//renderer->FillRect(mX-5, mY-5,230,35, );
|
||||||
if (card){
|
|
||||||
thumb = card->getThumb();
|
|
||||||
mText= card->name;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (thumb){
|
if (thumb){
|
||||||
renderer->RenderQuad(thumb,x0,y0,0,mScale * 0.45,mScale * 0.45);
|
renderer->RenderQuad(thumb,x0,y0,0,mScale * 0.45,mScale * 0.45);
|
||||||
@@ -145,6 +155,7 @@ ShopItems::ShopItems(int id, JGuiListener* listener, JLBFont* font, int x, int y
|
|||||||
for (int i=0; i < SHOP_BOOSTERS; i++){
|
for (int i=0; i < SHOP_BOOSTERS; i++){
|
||||||
setIds[i] = _setIds[i];
|
setIds[i] = _setIds[i];
|
||||||
};
|
};
|
||||||
|
myCollection = NEW DeckDataWrapper(NEW MTGDeck(RESPATH"/player/collection.dat", NULL,_collection));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -153,7 +164,7 @@ void ShopItems::Add(int cardid){
|
|||||||
int rnd = (rand() % 20);
|
int rnd = (rand() % 20);
|
||||||
int price = pricelist->getPrice(cardid);
|
int price = pricelist->getPrice(cardid);
|
||||||
price = price + price * (rnd -10)/100;
|
price = price + price * (rnd -10)/100;
|
||||||
JGuiController::Add(NEW ShopItem(mCount, mFont, cardid, mX + 10, mY + 10 + mHeight, (mCount == 0),collection, price));
|
JGuiController::Add(NEW ShopItem(mCount, mFont, cardid, mX + 10, mY + 10 + mHeight, (mCount == 0),collection, price,myCollection));
|
||||||
mHeight += 22;
|
mHeight += 22;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -234,6 +245,7 @@ void ShopItems::ButtonPressed(int controllerId, int controlId){
|
|||||||
pricelist->setPrice(item->card->getMTGId(),price);
|
pricelist->setPrice(item->card->getMTGId(),price);
|
||||||
playerdata->collection->add(item->card);
|
playerdata->collection->add(item->card);
|
||||||
item->quantity--;
|
item->quantity--;
|
||||||
|
item->nameCount++;
|
||||||
}else{
|
}else{
|
||||||
safeDeleteDisplay();
|
safeDeleteDisplay();
|
||||||
display = NEW CardDisplay(12,NULL, SCREEN_WIDTH - 200, SCREEN_HEIGHT/2,this,NULL,5);
|
display = NEW CardDisplay(12,NULL, SCREEN_WIDTH - 200, SCREEN_HEIGHT/2,this,NULL,5);
|
||||||
@@ -290,4 +302,5 @@ ShopItems::~ShopItems(){
|
|||||||
SAFE_DELETE(playerdata);
|
SAFE_DELETE(playerdata);
|
||||||
SAFE_DELETE(dialog);
|
SAFE_DELETE(dialog);
|
||||||
safeDeleteDisplay();
|
safeDeleteDisplay();
|
||||||
|
SAFE_DELETE(myCollection);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user