* Fix issue 357, where the hand loses focus when the opponent declares
  attackers while the hand is open.
* Harmonize the code for CardSelector.cpp to the coding style.
This commit is contained in:
jean.chalard
2010-03-05 17:01:00 +00:00
parent a04c0eff00
commit ec0354f630
3 changed files with 155 additions and 160 deletions
+5 -1
View File
@@ -48,6 +48,7 @@ class ObjectSelector : public GuiLayer
LimitorFunctor<T>* limitor; LimitorFunctor<T>* limitor;
Pos bigpos; Pos bigpos;
map<const SelectorZone, SelectorMemory> lasts; map<const SelectorZone, SelectorMemory> lasts;
stack< pair<LimitorFunctor<T>*, SelectorZone> > limitorStack;
stack<SelectorMemory> memoryStack; stack<SelectorMemory> memoryStack;
T* fetchMemory(SelectorMemory&); T* fetchMemory(SelectorMemory&);
@@ -60,10 +61,13 @@ class ObjectSelector : public GuiLayer
bool CheckUserInput(JButton key); bool CheckUserInput(JButton key);
void Update(float dt); void Update(float dt);
void Render(); void Render();
void Limit(LimitorFunctor<T>* limitor, SelectorZone);
void Push(); void Push();
void Pop(); void Pop();
void Limit(LimitorFunctor<T>* limitor, SelectorZone);
void PushLimitor();
void PopLimitor();
typedef T Target; typedef T Target;
}; };
+39 -50
View File
@@ -47,7 +47,6 @@ template<>
void CardSelector::Remove(CardSelector::Target* card) void CardSelector::Remove(CardSelector::Target* card)
{ {
for (vector<Target*>::iterator it = cards.begin(); it != cards.end(); ++it) for (vector<Target*>::iterator it = cards.begin(); it != cards.end(); ++it)
{
if (card == *it) if (card == *it)
{ {
if (active == *it) if (active == *it)
@@ -60,45 +59,36 @@ void CardSelector::Remove(CardSelector::Target* card)
cards.erase(it); cards.erase(it);
return; return;
} }
}
} }
template<> template<>
CardSelector::Target* CardSelector::fetchMemory(SelectorMemory& memory) CardSelector::Target* CardSelector::fetchMemory(SelectorMemory& memory) {
{
if (NULL == memory.object) return NULL; if (NULL == memory.object) return NULL;
for (vector<Target*>::iterator it = cards.begin(); it != cards.end(); ++it) for (vector<Target*>::iterator it = cards.begin(); it != cards.end(); ++it)
{ if (*it == memory.object) {
if (*it == memory.object)
{
if ((NULL == limitor) || (limitor->select(memory.object))) if ((NULL == limitor) || (limitor->select(memory.object)))
return memory.object; return memory.object;
else break; else break;
} }
}
// We come here if the card is not in the selector any more, or if // We come here if the card is not in the selector any more, or if
// it is there but it is now refused by the limitor. // it is there but it is now refused by the limitor.
return closest<True>(cards, limitor, memory.x, memory.y); return closest<True>(cards, limitor, memory.x, memory.y);
} }
template<> template<>
void CardSelector::Push() void CardSelector::Push() {
{
memoryStack.push(SelectorMemory(active)); memoryStack.push(SelectorMemory(active));
} }
template<> template<>
void CardSelector::Pop() void CardSelector::Pop() {
{
Target* oldactive = active; Target* oldactive = active;
if (!memoryStack.empty()) if (!memoryStack.empty()) {
{
active = fetchMemory(memoryStack.top()); active = fetchMemory(memoryStack.top());
memoryStack.pop(); memoryStack.pop();
SelectorZone oldowner; SelectorZone oldowner;
if (CardView *q = dynamic_cast<CardView*>(oldactive)) oldowner = q->owner; else oldowner = nullZone; if (CardView *q = dynamic_cast<CardView*>(oldactive)) oldowner = q->owner; else oldowner = nullZone;
if (nullZone != oldowner) lasts[oldowner] = SelectorMemory(oldactive); if (nullZone != oldowner) lasts[oldowner] = SelectorMemory(oldactive);
} }
if (active != oldactive) if (active != oldactive) {
{
{ CardView* c = dynamic_cast<CardView*>(oldactive); if (c) c->zoom = 1.0; } //Is this needed, I think it is one in Leaving(0) ? { CardView* c = dynamic_cast<CardView*>(oldactive); if (c) c->zoom = 1.0; } //Is this needed, I think it is one in Leaving(0) ?
{ CardView* c = dynamic_cast<CardView*>(active); if (c) c->zoom = 1.4; } //Is this needed, I think it is one in Entering() ? { CardView* c = dynamic_cast<CardView*>(active); if (c) c->zoom = 1.4; } //Is this needed, I think it is one in Entering() ?
if (oldactive) oldactive->Leaving(JGE_BTN_NONE); if (oldactive) oldactive->Leaving(JGE_BTN_NONE);
@@ -109,11 +99,9 @@ void CardSelector::Pop()
template<> template<>
bool CardSelector::CheckUserInput(JButton key) bool CardSelector::CheckUserInput(JButton key)
{ {
if (!active) if (!active) {
{
for (vector<Target*>::iterator it = cards.begin(); it != cards.end(); ++it) for (vector<Target*>::iterator it = cards.begin(); it != cards.end(); ++it)
if ((NULL == limitor) || (limitor->select(*it))) if ((NULL == limitor) || (limitor->select(*it))) {
{
active = *it; active = *it;
active->Entering(); active->Entering();
return true; return true;
@@ -121,8 +109,7 @@ bool CardSelector::CheckUserInput(JButton key)
return true; return true;
} }
Target* oldactive = active; Target* oldactive = active;
switch (key) switch (key) {
{
case JGE_BTN_SEC: case JGE_BTN_SEC:
GameObserver::GetInstance()->cancelCurrentAction(); GameObserver::GetInstance()->cancelCurrentAction();
return true; return true;
@@ -152,15 +139,12 @@ bool CardSelector::CheckUserInput(JButton key)
default: default:
return false; return false;
} }
if (active != oldactive) if (active != oldactive) {
{
SelectorZone oldowner, owner; SelectorZone oldowner, owner;
if (CardView *q = dynamic_cast<CardView*>(oldactive)) oldowner = q->owner; else oldowner = nullZone; if (CardView *q = dynamic_cast<CardView*>(oldactive)) oldowner = q->owner; else oldowner = nullZone;
if (CardView *q = dynamic_cast<CardView*>(active)) owner = q->owner; else owner = nullZone; if (CardView *q = dynamic_cast<CardView*>(active)) owner = q->owner; else owner = nullZone;
if (oldowner != owner) if (oldowner != owner) {
{ if (nullZone != owner) {
if (nullZone != owner)
{
if (PlayGuiObject* old = fetchMemory(lasts[owner])) if (PlayGuiObject* old = fetchMemory(lasts[owner]))
switch (key) switch (key)
{ {
@@ -174,8 +158,7 @@ bool CardSelector::CheckUserInput(JButton key)
lasts[oldowner] = SelectorMemory(oldactive); lasts[oldowner] = SelectorMemory(oldactive);
} }
} }
if (active != oldactive) if (active != oldactive) {
{
{ CardView* c = dynamic_cast<CardView*>(oldactive); if (c) c->zoom = 1.0; } { CardView* c = dynamic_cast<CardView*>(oldactive); if (c) c->zoom = 1.0; }
{ CardView* c = dynamic_cast<CardView*>(active); if (c) c->zoom = 1.4; } { CardView* c = dynamic_cast<CardView*>(active); if (c) c->zoom = 1.4; }
if (oldactive) oldactive->Leaving(JGE_BTN_NONE); if (oldactive) oldactive->Leaving(JGE_BTN_NONE);
@@ -185,8 +168,7 @@ bool CardSelector::CheckUserInput(JButton key)
} }
template<> template<>
void CardSelector::Update(float dt) void CardSelector::Update(float dt) {
{
float boundary = duel->RightBoundary(); float boundary = duel->RightBoundary();
float position = boundary - CardGui::BigWidth / 2; float position = boundary - CardGui::BigWidth / 2;
if (CardView* c = dynamic_cast<CardView*>(active)) if (CardView* c = dynamic_cast<CardView*>(active))
@@ -199,13 +181,11 @@ void CardSelector::Update(float dt)
} }
template<> template<>
void CardSelector::Render() void CardSelector::Render() {
{ if (active) {
if (active)
{
active->Render(); active->Render();
if (CardView* c = dynamic_cast<CardView*>(active)){ if (CardView* c = dynamic_cast<CardView*>(active)) {
switch(bigMode){ switch(bigMode) {
case BIG_MODE_SHOW: case BIG_MODE_SHOW:
c->RenderBig(bigpos); c->RenderBig(bigpos);
break; break;
@@ -220,35 +200,29 @@ void CardSelector::Render()
} }
template<> template<>
void CardSelector::Limit(LimitorFunctor<Target>* limitor, SelectorZone destzone) 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;
SelectorZone oldowner; SelectorZone oldowner;
if (CardView *q = dynamic_cast<CardView*>(oldactive)) oldowner = q->owner; else oldowner = nullZone; if (CardView *q = dynamic_cast<CardView*>(oldactive)) oldowner = q->owner; else oldowner = nullZone;
if (oldowner != destzone) if (oldowner != destzone) {
{
if (nullZone != destzone) if (nullZone != destzone)
if (PlayGuiObject* old = fetchMemory(lasts[destzone])) if (PlayGuiObject* old = fetchMemory(lasts[destzone]))
active = old; active = old;
lasts[oldowner] = SelectorMemory(oldactive); lasts[oldowner] = SelectorMemory(oldactive);
} }
if (limitor && !limitor->select(active)) if (limitor && !limitor->select(active)) {
{
active = NULL; active = NULL;
for (vector<Target*>::iterator it = cards.begin(); it != cards.end(); ++it) for (vector<Target*>::iterator it = cards.begin(); it != cards.end(); ++it)
if (limitor->select(*it)) if (limitor->select(*it)) {
{
active = *it; active = *it;
break; break;
} }
} }
if (active != oldactive) if (active != oldactive) {
{
{ CardView* c = dynamic_cast<CardView*>(oldactive); if (c) c->zoom = 1.0; } { CardView* c = dynamic_cast<CardView*>(oldactive); if (c) c->zoom = 1.0; }
{ CardView* c = dynamic_cast<CardView*>(active); if (c) c->zoom = 1.4; } { CardView* c = dynamic_cast<CardView*>(active); if (c) c->zoom = 1.4; }
if (oldactive) oldactive->Leaving(JGE_BTN_NONE); if (oldactive) oldactive->Leaving(JGE_BTN_NONE);
@@ -256,3 +230,18 @@ void CardSelector::Limit(LimitorFunctor<Target>* limitor, SelectorZone destzone)
} }
} }
} }
template<>
void CardSelector::PushLimitor() {
if (NULL == limitor) return;
SelectorZone owner;
if (CardView *q = dynamic_cast<CardView*>(active)) owner = q->owner; else owner = nullZone;
limitorStack.push(make_pair(limitor, owner));
}
template<>
void CardSelector::PopLimitor() {
if (limitorStack.empty()) return;
Limit(limitorStack.top().first, limitorStack.top().second);
limitorStack.pop();
}
+2
View File
@@ -139,9 +139,11 @@ int MTGAttackRule::reactToClick(MTGCardInstance * card){
//Graphically select the next card that can attack //Graphically select the next card that can attack
if(!card->isAttacker()){ if(!card->isAttacker()){
CardSelector * cs = game->mLayers->cs; CardSelector * cs = game->mLayers->cs;
cs->PushLimitor();
cs->Limit(this,CardSelector::playZone); cs->Limit(this,CardSelector::playZone);
cs->CheckUserInput(JGE_BTN_RIGHT); cs->CheckUserInput(JGE_BTN_RIGHT);
cs->Limit(NULL,CardSelector::playZone); cs->Limit(NULL,CardSelector::playZone);
cs->PopLimitor();
} }
card->toggleAttacker(); card->toggleAttacker();
return 1; return 1;