J :
* 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:
@@ -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;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+148
-159
@@ -47,146 +47,128 @@ 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)
|
{
|
||||||
{
|
CardView* c = dynamic_cast<CardView*>(active); if (c) c->zoom = 1.0;
|
||||||
CardView* c = dynamic_cast<CardView*>(active); if (c) c->zoom = 1.0;
|
active = closest<Diff>(cards, limitor, active);
|
||||||
active = closest<Diff>(cards, limitor, active);
|
c = dynamic_cast<CardView*>(active); if (c) c->zoom = 1.4;
|
||||||
c = dynamic_cast<CardView*>(active); if (c) c->zoom = 1.4;
|
}
|
||||||
}
|
if (active == *it) active = NULL;
|
||||||
if (active == *it) active = NULL;
|
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)))
|
||||||
{
|
return memory.object;
|
||||||
if ((NULL == limitor) || (limitor->select(memory.object)))
|
else break;
|
||||||
return memory.object;
|
|
||||||
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*>(active); if (c) c->zoom = 1.4; } //Is this needed, I think it is one in Entering() ?
|
||||||
{ CardView* c = dynamic_cast<CardView*>(oldactive); if (c) c->zoom = 1.0; } //Is this needed, I think it is one in Leaving(0) ?
|
if (oldactive) oldactive->Leaving(JGE_BTN_NONE);
|
||||||
{ CardView* c = dynamic_cast<CardView*>(active); if (c) c->zoom = 1.4; } //Is this needed, I think it is one in Entering() ?
|
if (active) active->Entering();
|
||||||
if (oldactive) oldactive->Leaving(JGE_BTN_NONE);
|
}
|
||||||
if (active) active->Entering();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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->Entering();
|
||||||
active = *it;
|
return true;
|
||||||
active->Entering();
|
}
|
||||||
return true;
|
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;
|
case JGE_BTN_OK:
|
||||||
case JGE_BTN_OK:
|
GameObserver::GetInstance()->ButtonPressed(active);
|
||||||
GameObserver::GetInstance()->ButtonPressed(active);
|
return true;
|
||||||
return true;
|
break;
|
||||||
break;
|
case JGE_BTN_LEFT:
|
||||||
case JGE_BTN_LEFT:
|
active = closest<Left>(cards, limitor, active);
|
||||||
active = closest<Left>(cards, limitor, active);
|
break;
|
||||||
break;
|
case JGE_BTN_RIGHT:
|
||||||
case JGE_BTN_RIGHT:
|
active = closest<Right>(cards, limitor, active);
|
||||||
active = closest<Right>(cards, limitor, active);
|
break;
|
||||||
break;
|
case JGE_BTN_UP:
|
||||||
case JGE_BTN_UP:
|
active = closest<Up>(cards, limitor, active);
|
||||||
active = closest<Up>(cards, limitor, active);
|
break;
|
||||||
break;
|
case JGE_BTN_DOWN:
|
||||||
case JGE_BTN_DOWN:
|
active = closest<Down>(cards, limitor, active);
|
||||||
active = closest<Down>(cards, limitor, active);
|
break;
|
||||||
break;
|
case JGE_BTN_CANCEL:
|
||||||
case JGE_BTN_CANCEL:
|
bigMode = (bigMode+1) % NB_BIG_MODES;
|
||||||
bigMode = (bigMode+1) % NB_BIG_MODES;
|
if(bigMode == BIG_MODE_TEXT)
|
||||||
if(bigMode == BIG_MODE_TEXT)
|
options[Options::DISABLECARDS].number = 1;
|
||||||
options[Options::DISABLECARDS].number = 1;
|
else
|
||||||
else
|
options[Options::DISABLECARDS].number = 0;
|
||||||
options[Options::DISABLECARDS].number = 0;
|
return true;
|
||||||
return true;
|
default:
|
||||||
default:
|
return false;
|
||||||
return false;
|
}
|
||||||
}
|
if (active != oldactive) {
|
||||||
if (active != oldactive)
|
SelectorZone oldowner, owner;
|
||||||
{
|
if (CardView *q = dynamic_cast<CardView*>(oldactive)) oldowner = q->owner; else oldowner = nullZone;
|
||||||
SelectorZone oldowner, owner;
|
if (CardView *q = dynamic_cast<CardView*>(active)) owner = q->owner; else owner = nullZone;
|
||||||
if (CardView *q = dynamic_cast<CardView*>(oldactive)) oldowner = q->owner; else oldowner = nullZone;
|
if (oldowner != owner) {
|
||||||
if (CardView *q = dynamic_cast<CardView*>(active)) owner = q->owner; else owner = nullZone;
|
if (nullZone != owner) {
|
||||||
if (oldowner != owner)
|
if (PlayGuiObject* old = fetchMemory(lasts[owner]))
|
||||||
{
|
switch (key)
|
||||||
if (nullZone != owner)
|
|
||||||
{
|
{
|
||||||
if (PlayGuiObject* old = fetchMemory(lasts[owner]))
|
case JGE_BTN_LEFT: if (old->x < oldactive->x) active = old; break;
|
||||||
switch (key)
|
case JGE_BTN_RIGHT: if (old->x > oldactive->x) active = old; break;
|
||||||
{
|
case JGE_BTN_UP: if (old->y < oldactive->y) active = old; break;
|
||||||
case JGE_BTN_LEFT: if (old->x < oldactive->x) active = old; break;
|
case JGE_BTN_DOWN: if (old->y > oldactive->y) active = old; break;
|
||||||
case JGE_BTN_RIGHT: if (old->x > oldactive->x) active = old; break;
|
default: if (old) active = old; break;
|
||||||
case JGE_BTN_UP: if (old->y < oldactive->y) active = old; break;
|
|
||||||
case JGE_BTN_DOWN: if (old->y > oldactive->y) active = old; break;
|
|
||||||
default: if (old) active = old; break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
lasts[oldowner] = SelectorMemory(oldactive);
|
}
|
||||||
}
|
lasts[oldowner] = SelectorMemory(oldactive);
|
||||||
}
|
|
||||||
if (active != oldactive)
|
|
||||||
{
|
|
||||||
{ CardView* c = dynamic_cast<CardView*>(oldactive); if (c) c->zoom = 1.0; }
|
|
||||||
{ CardView* c = dynamic_cast<CardView*>(active); if (c) c->zoom = 1.4; }
|
|
||||||
if (oldactive) oldactive->Leaving(JGE_BTN_NONE);
|
|
||||||
if (active) active->Entering();
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (active != oldactive) {
|
||||||
|
{ CardView* c = dynamic_cast<CardView*>(oldactive); if (c) c->zoom = 1.0; }
|
||||||
|
{ CardView* c = dynamic_cast<CardView*>(active); if (c) c->zoom = 1.4; }
|
||||||
|
if (oldactive) oldactive->Leaving(JGE_BTN_NONE);
|
||||||
|
if (active) active->Entering();
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
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,60 +181,67 @@ void CardSelector::Update(float dt)
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
void CardSelector::Render()
|
void CardSelector::Render() {
|
||||||
{
|
if (active) {
|
||||||
if (active)
|
active->Render();
|
||||||
{
|
if (CardView* c = dynamic_cast<CardView*>(active)) {
|
||||||
active->Render();
|
switch(bigMode) {
|
||||||
if (CardView* c = dynamic_cast<CardView*>(active)){
|
case BIG_MODE_SHOW:
|
||||||
switch(bigMode){
|
c->RenderBig(bigpos);
|
||||||
case BIG_MODE_SHOW:
|
break;
|
||||||
c->RenderBig(bigpos);
|
case BIG_MODE_TEXT:
|
||||||
break;
|
c->alternateRenderBig(bigpos);
|
||||||
case BIG_MODE_TEXT:
|
break;
|
||||||
c->alternateRenderBig(bigpos);
|
default:
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 (PlayGuiObject* old = fetchMemory(lasts[destzone]))
|
||||||
if (nullZone != destzone)
|
active = old;
|
||||||
if (PlayGuiObject* old = fetchMemory(lasts[destzone]))
|
lasts[oldowner] = SelectorMemory(oldactive);
|
||||||
active = old;
|
}
|
||||||
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;
|
||||||
{
|
break;
|
||||||
active = *it;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (active != oldactive)
|
|
||||||
{
|
|
||||||
{ CardView* c = dynamic_cast<CardView*>(oldactive); if (c) c->zoom = 1.0; }
|
|
||||||
{ CardView* c = dynamic_cast<CardView*>(active); if (c) c->zoom = 1.4; }
|
|
||||||
if (oldactive) oldactive->Leaving(JGE_BTN_NONE);
|
|
||||||
if (active) active->Entering();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (active != oldactive) {
|
||||||
|
{ CardView* c = dynamic_cast<CardView*>(oldactive); if (c) c->zoom = 1.0; }
|
||||||
|
{ CardView* c = dynamic_cast<CardView*>(active); if (c) c->zoom = 1.4; }
|
||||||
|
if (oldactive) oldactive->Leaving(JGE_BTN_NONE);
|
||||||
|
if (active) active->Entering();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
Reference in New Issue
Block a user