diff --git a/projects/mtg/include/GameStateShop.h b/projects/mtg/include/GameStateShop.h index 12275da85..5c4f3a67c 100644 --- a/projects/mtg/include/GameStateShop.h +++ b/projects/mtg/include/GameStateShop.h @@ -42,6 +42,9 @@ class GameStateShop: public GameState, public JGuiListener virtual void Render(); virtual void ButtonPressed(int controllerId, int controlId); + + + }; diff --git a/projects/mtg/include/ShopItem.h b/projects/mtg/include/ShopItem.h index 10e7b8b36..ac15e005a 100644 --- a/projects/mtg/include/ShopItem.h +++ b/projects/mtg/include/ShopItem.h @@ -13,6 +13,8 @@ #include using std::string; +class hgeDistortionMesh; + #define SHOP_BOOSTERS 3 class ShopItem:public JGuiObject{ @@ -20,12 +22,12 @@ class ShopItem:public JGuiObject{ bool mHasFocus; JLBFont *mFont; string mText; - int mX; - int mY; + float xy[8]; JQuad * quad; JQuad * thumb; float mScale; float mTargetScale; + hgeDistortionMesh* mesh; public: @@ -33,8 +35,8 @@ class ShopItem:public JGuiObject{ int quantity; MTGCard * card; 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, 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); @@ -74,6 +76,7 @@ class ShopItems:public JGuiController,public JGuiListener{ virtual void ButtonPressed(int controllerId, int controlId); void savePriceList(); void saveAll(); + static float _x1[],_y1[],_x2[],_y2[],_x3[],_y3[],_x4[],_y4[]; }; #endif diff --git a/projects/mtg/src/GameStateMenu.cpp b/projects/mtg/src/GameStateMenu.cpp index c8cf8b37d..ae8e5d6ca 100644 --- a/projects/mtg/src/GameStateMenu.cpp +++ b/projects/mtg/src/GameStateMenu.cpp @@ -204,7 +204,7 @@ void GameStateMenu::fillScroller(){ scroller->Add(_("Interested in playing Momir Basic? You'll have to unlock it first :)")); } if (!go->values[OPTIONS_RANDOMDECK_MODE_UNLOCKED].getIntValue()){ - scroller->Add(_("You haven't locked the random deck mode yet")); + scroller->Add(_("You haven't unlocked the random deck mode yet")); } if (!go->values[OPTIONS_EVILTWIN_MODE_UNLOCKED].getIntValue()){ scroller->Add(_("You haven't unlocked the evil twin mode yet")); diff --git a/projects/mtg/src/GameStateShop.cpp b/projects/mtg/src/GameStateShop.cpp index b47bcdaf8..793837f96 100644 --- a/projects/mtg/src/GameStateShop.cpp +++ b/projects/mtg/src/GameStateShop.cpp @@ -9,6 +9,7 @@ #include "../include/Translate.h" #include "../include/GameOptions.h" + GameStateShop::GameStateShop(GameApp* parent): GameState(parent) {} @@ -25,6 +26,9 @@ void GameStateShop::Create(){ void GameStateShop::Start() { + + + menu = NULL; menuFont = GameApp::CommonRes->GetJLBFont(Constants::MENU_FONT); itemFont = GameApp::CommonRes->GetJLBFont(Constants::MAIN_FONT); @@ -33,7 +37,7 @@ void GameStateShop::Start() mStage = STAGE_SHOP_SHOP; bgTexture = JRenderer::GetInstance()->LoadTexture("graphics/shop.jpg", TEX_TYPE_USE_VRAM); - mBg = NEW JQuad(bgTexture, 0, 0, 400, 280); // Create background quad for rendering. + mBg = NEW JQuad(bgTexture, 0, 0, 480, 272); // Create background quad for rendering. mBack = GameApp::CommonRes->GetQuad("back"); JRenderer::GetInstance()->ResetPrivateVRAM(); @@ -161,9 +165,11 @@ void GameStateShop::Render() r->ClearScreen(ARGB(0,0,0,0)); if (mBg)JRenderer::GetInstance()->RenderQuad(mBg,0,0); - r->FillRect(5,SCREEN_HEIGHT-15,110,15,ARGB(200,0,0,0)); itemFont->SetColor(ARGB(255,255,255,255)); - itemFont->DrawString(_("press [] to refresh").c_str(),10,SCREEN_HEIGHT-12); + char c[4096]; + sprintf(c, _("press [] to refresh").c_str()); + unsigned int len = 4 + itemFont->GetStringWidth(c); + itemFont->DrawString(c,SCREEN_WIDTH-len,SCREEN_HEIGHT-12); if (shop) shop->Render(); diff --git a/projects/mtg/src/ShopItem.cpp b/projects/mtg/src/ShopItem.cpp index f68c3a3e5..ba110e91c 100644 --- a/projects/mtg/src/ShopItem.cpp +++ b/projects/mtg/src/ShopItem.cpp @@ -3,10 +3,27 @@ #include "../include/GameStateShop.h" #include "../include/CardGui.h" #include "../include/Translate.h" +#include -ShopItem::ShopItem(int id, JLBFont *font, char* text, JQuad * _quad,JQuad * _thumb, int x, int y, bool hasFocus, int _price): JGuiObject(id), mFont(font), mText(text), mX(x), mY(y), quad(_quad), thumb(_thumb), price(_price) + + float ShopItems::_x1[] = { 40, 3, 23, 99,142,182, 90,132,177,106,163}; + float ShopItems::_y1[] = {156,174,194,166,166,162,184,185,180,211,208}; + + float ShopItems::_x2[] = { 44, 25, 64,128,171,211,121,165,209,143,200}; + float ShopItems::_y2[] = {147,163,190,166,166,162,184,185,180,211,208}; + + float ShopItems::_x3[] = { 86, 47, 12, 85,133,177, 73,120,170, 88,153}; + float ShopItems::_y3[] = {152,177,216,181,180,176,203,204,198,237,232}; + + float ShopItems::_x4[] = { 86, 66, 58,118,164,207,108,156,205,130,199}; + float ShopItems::_y4[] = {145,167,211,181,180,176,203,204,198,237,232}; + +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; @@ -14,11 +31,28 @@ ShopItem::ShopItem(int id, JLBFont *font, char* text, JQuad * _quad,JQuad * _thu 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, int x, int y, bool hasFocus, MTGAllCards * collection, int _price, DeckDataWrapper * ddw): JGuiObject(id), mFont(font), mX(x), mY(y), price(_price){ +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; mScale = 1.0f; mTargetScale = 1.0f; @@ -32,7 +66,26 @@ ShopItem::ShopItem(int id, JLBFont *font, int _cardid, int x, int y, bool hasFoc quantity = 1 + (rand() % 4); if (card->getRarity() == Constants::RARITY_L) quantity = 50; quad = NULL; - thumb = NULL; + thumb = card->getThumb(); + if (!thumb) thumb = GameApp::CommonRes->GetQuad("back_thumb"); + 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; + } } @@ -43,7 +96,8 @@ int ShopItem::updateCount(DeckDataWrapper * ddw){ } ShopItem::~ShopItem(){ - + OutputDebugString("delete shopitem\n"); + SAFE_DELETE(mesh); } const char * ShopItem::getText(){ @@ -62,8 +116,7 @@ void ShopItem::Render(){ } - if (card){ - thumb = card->getThumb(); + if (card){ if (nameCount){ char buffer[512]; sprintf(buffer, "%s (%i)", _(card->name).c_str(), nameCount ); @@ -74,9 +127,9 @@ void ShopItem::Render(){ } JRenderer * renderer = JRenderer::GetInstance(); - float x0 = mX; - float y0 = mY - (mScale > 1 ? 4 : 0); - if (GetId()%2){ + //float x0 = mX; + //float y0 = mY - (mScale > 1 ? 4 : 0); + /* if (GetId()%2){ float xs[] = {mX, mX, mX+230,mX+230}; float ys[] = {mY-5+17,mY-5+19,mY-5+35,mY-5} ; @@ -89,12 +142,13 @@ void ShopItem::Render(){ float ys[] = {mY-5,mY-5+35,mY-5+17,mY-5+19} ; renderer->FillPolygon(xs,ys,4,ARGB(128,0,0,0)); mFont->DrawString(mText.c_str(), mX + 30, mY + 8); - } + }*/ //renderer->FillRect(mX-5, mY-5,230,35, ); - if (thumb){ - renderer->RenderQuad(thumb,x0,y0,0,mScale * 0.45,mScale * 0.45); + if (mesh){ + mesh->Render(0,0); + //renderer->RenderQuad(thumb,x0,y0,0,mScale * 0.45,mScale * 0.45); }else{ //NOTHING } @@ -104,10 +158,11 @@ void ShopItem::Render(){ } if (quad){ quad->SetColor(ARGB(255,255,255,255)); - renderer->RenderQuad(quad,mX + SCREEN_WIDTH/2 + 20,5,0, 0.9f,0.9f); + renderer->RenderQuad(quad,SCREEN_WIDTH/2 + 50,5,0, 0.9f,0.9f); }else{ - if (card) CardGui::alternateRender(card,NULL,mX + SCREEN_WIDTH/2 + 100 + 20,133,0, 0.9f); + if (card) CardGui::alternateRender(card,NULL,SCREEN_WIDTH/2 + 100 + 20,133,0, 0.9f); } + mFont->DrawString(mText.c_str(), 100, SCREEN_HEIGHT - 30); } } @@ -132,6 +187,12 @@ void ShopItem::Update(float dt) 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; @@ -140,6 +201,11 @@ void ShopItem::Entering() bool ShopItem::Leaving(u32 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; @@ -171,12 +237,14 @@ void ShopItems::Add(int cardid){ int rnd = (rand() % 20); int price = pricelist->getPrice(cardid); price = price + price * (rnd -10)/100; - JGuiController::Add(NEW ShopItem(mCount, mFont, cardid, mX + 10, mY + 10 + mHeight, (mCount == 0),collection, price,myCollection)); + 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){ - JGuiController::Add(NEW ShopItem(mCount, mFont, text, quad, thumb, mX + 10, mY + 10 + mHeight, (mCount == 0), 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; } @@ -220,9 +288,9 @@ void ShopItems::Render(){ sprintf(credits,_("credits: %i").c_str(), playerdata->credits); unsigned int len = 4 + mFont->GetStringWidth(credits); mFont->SetColor(ARGB(200,0,0,0)); - mFont->DrawString(credits, SCREEN_WIDTH - len + 2, SCREEN_HEIGHT - 13); + mFont->DrawString(credits, 5, SCREEN_HEIGHT - 13); mFont->SetColor(ARGB(255,255,255,255)); - mFont->DrawString(credits, SCREEN_WIDTH - len, SCREEN_HEIGHT - 15); + mFont->DrawString(credits, 5, SCREEN_HEIGHT - 15); if (display) display->Render(); } @@ -336,7 +404,6 @@ ostream& ShopItem::toString(ostream& out) const return out << "ShopItem ::: mHasFocus : " << mHasFocus << " ; mFont : " << mFont << " ; mText : " << mText - << " ; mX,mY : " << mX << "," << mY << " ; quad : " << quad << " ; thumb : " << thumb << " ; mScale : " << mScale