fix for shop crash. in the shop there is no "game" so cards in booster packs are never assigned a observer as no observer is ever created at this point.

This commit is contained in:
omegablast2002@yahoo.com
2011-11-27 14:25:24 +00:00
parent 4c56842cf5
commit d01a5531d9
2 changed files with 46 additions and 44 deletions

View File

@@ -178,48 +178,51 @@ bool CardDisplay::CheckUserInput(JButton key)
int n = mCurr; int n = mCurr;
int x1,y1; int x1,y1;
JButton key; JButton key;
JGE* jge = observer->getInput(); JGE* jge = observer?observer->getInput():JGE::GetInstance();
if (jge && jge->GetLeftClickCoordinates(x1, y1)) if(jge)
{ {
for (size_t i = 0; i < mObjects.size(); i++) if (jge->GetLeftClickCoordinates(x1, y1))
{ {
float top, left; for (size_t i = 0; i < mObjects.size(); i++)
if (mObjects[i]->getTopLeft(top, left))
{ {
distance2 = static_cast<unsigned int>((top - y1) * (top - y1) + (left - x1) * (left - x1)); float top, left;
if (distance2 < minDistance2) if (mObjects[i]->getTopLeft(top, left))
{ {
minDistance2 = distance2; distance2 = static_cast<unsigned int>((top - y1) * (top - y1) + (left - x1) * (left - x1));
n = i; if (distance2 < minDistance2)
{
minDistance2 = distance2;
n = i;
}
} }
} }
}
if (n < mCurr) if (n < mCurr)
key = JGE_BTN_LEFT; key = JGE_BTN_LEFT;
else else
key = JGE_BTN_RIGHT; key = JGE_BTN_RIGHT;
if (n < start_item) if (n < start_item)
{ {
rotateLeft(); rotateLeft();
} }
else if (n >= (int)(mObjects.size()) && mObjects.size()) else if (n >= (int)(mObjects.size()) && mObjects.size())
{ {
n = mObjects.size() - 1; n = mObjects.size() - 1;
} }
if (n >= start_item + nb_displayed_items) if (n >= start_item + nb_displayed_items)
{ {
rotateRight(); rotateRight();
} }
if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(key)) if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(key))
{ {
mCurr = n; mCurr = n;
mObjects[mCurr]->Entering(); mObjects[mCurr]->Entering();
result = true; result = true;
}
jge->LeftClickedProcessed();
} }
jge->LeftClickedProcessed();
} }
return result; return result;
} }

View File

@@ -130,17 +130,16 @@ void CardGui::DrawCard(MTGCard* inCard, const Pos& inPosition, int inMode)
void CardGui::Render() void CardGui::Render()
{ {
WFont * mFont = card->getObserver()->getResourceManager()->GetWFont(Fonts::MAIN_FONT);
JRenderer * renderer = JRenderer::GetInstance();
GameObserver * game = card->getObserver(); GameObserver * game = card->getObserver();
WFont * mFont = game?game->getResourceManager()->GetWFont(Fonts::MAIN_FONT):WResourceManager::Instance()->GetWFont(Fonts::MAIN_FONT);
JRenderer * renderer = JRenderer::GetInstance();
TargetChooser * tc = NULL; TargetChooser * tc = NULL;
if (game) if (game)
tc = game->getCurrentTargetChooser(); tc = game->getCurrentTargetChooser();
bool alternate = true; bool alternate = true;
JQuadPtr quad = card->getObserver()->getResourceManager()->RetrieveCard(card, CACHE_THUMB); JQuadPtr quad = game? game->getResourceManager()->RetrieveCard(card, CACHE_THUMB):WResourceManager::Instance()->RetrieveCard(card, CACHE_THUMB);
if (quad.get()) if (quad.get())
alternate = false; alternate = false;
@@ -153,7 +152,7 @@ void CardGui::Render()
JQuadPtr shadow; JQuadPtr shadow;
if (actZ > 1) if (actZ > 1)
{ {
shadow = card->getObserver()->getResourceManager()->GetQuad("shadow"); shadow = game? game->getResourceManager()->GetQuad("shadow"):WResourceManager::Instance()->GetQuad("shadow");
shadow->SetColor(ARGB(static_cast<unsigned char>(actA)/2,255,255,255)); shadow->SetColor(ARGB(static_cast<unsigned char>(actA)/2,255,255,255));
renderer->RenderQuad(shadow.get(), actX + (actZ - 1) * 15, actY + (actZ - 1) * 15, actT, 28 * actZ / 16, 40 * actZ / 16); renderer->RenderQuad(shadow.get(), actX + (actZ - 1) * 15, actY + (actZ - 1) * 15, actT, 28 * actZ / 16, 40 * actZ / 16);
} }
@@ -166,7 +165,7 @@ void CardGui::Render()
renderer->RenderQuad(extracostshadow.get(), actX + (actZ - 1) * 15, actY + (actZ - 1) * 15, actT, 28 * actZ / 16, 40 * actZ / 16); renderer->RenderQuad(extracostshadow.get(), actX + (actZ - 1) * 15, actY + (actZ - 1) * 15, actT, 28 * actZ / 16, 40 * actZ / 16);
} }
if(game->connectRule) if(game && game->connectRule)
{ {
// Am I a parent of a selected card, or am I a parent and myself being selected? // Am I a parent of a selected card, or am I a parent and myself being selected?
bool isActiveConnectedParent = mHasFocus && card->childrenCards.size(); bool isActiveConnectedParent = mHasFocus && card->childrenCards.size();
@@ -238,15 +237,15 @@ void CardGui::Render()
JQuadPtr icon; JQuadPtr icon;
if (card->hasSubtype("plains")) if (card->hasSubtype("plains"))
icon = card->getObserver()->getResourceManager()->GetQuad("c_white"); icon = game?game->getResourceManager()->GetQuad("c_white"):WResourceManager::Instance()->GetQuad("c_white");
else if (card->hasSubtype("swamp")) else if (card->hasSubtype("swamp"))
icon = card->getObserver()->getResourceManager()->GetQuad("c_black"); icon = game?game->getResourceManager()->GetQuad("c_black"):WResourceManager::Instance()->GetQuad("c_black");
else if (card->hasSubtype("forest")) else if (card->hasSubtype("forest"))
icon = card->getObserver()->getResourceManager()->GetQuad("c_green"); icon = game?game->getResourceManager()->GetQuad("c_green"):WResourceManager::Instance()->GetQuad("c_green");
else if (card->hasSubtype("mountain")) else if (card->hasSubtype("mountain"))
icon = card->getObserver()->getResourceManager()->GetQuad("c_red"); icon = game?game->getResourceManager()->GetQuad("c_red"):WResourceManager::Instance()->GetQuad("c_red");
else if (card->hasSubtype("island")) else if (card->hasSubtype("island"))
icon = card->getObserver()->getResourceManager()->GetQuad("c_blue"); icon = game?game->getResourceManager()->GetQuad("c_blue"):WResourceManager::Instance()->GetQuad("c_blue");
if (icon.get()) if (icon.get())
{ {