Fixed a selection problem sometimes hapenning on the hand zone in touch/mouse mode and removed dead code.

This commit is contained in:
Xawotihs
2011-07-14 21:21:24 +00:00
parent 9f80620f0a
commit c2879b0b6e
2 changed files with 61 additions and 118 deletions

View File

@@ -32,7 +32,6 @@ public:
virtual void Add(PlayGuiObject*) = 0; virtual void Add(PlayGuiObject*) = 0;
virtual void Remove(PlayGuiObject*) = 0; virtual void Remove(PlayGuiObject*) = 0;
virtual bool CheckUserInput(JButton key) = 0; virtual bool CheckUserInput(JButton key) = 0;
virtual bool CheckUserInput(int x, int y) = 0;
virtual void PushLimitor() = 0; virtual void PushLimitor() = 0;
virtual void PopLimitor() = 0; virtual void PopLimitor() = 0;
virtual void Limit(LimitorFunctor<PlayGuiObject>* inLimitor, CardView::SelectorZone inZone) = 0; virtual void Limit(LimitorFunctor<PlayGuiObject>* inLimitor, CardView::SelectorZone inZone) = 0;
@@ -75,7 +74,6 @@ public:
void Add(PlayGuiObject*); void Add(PlayGuiObject*);
void Remove(PlayGuiObject*); void Remove(PlayGuiObject*);
bool CheckUserInput(JButton key); bool CheckUserInput(JButton key);
bool CheckUserInput(int x, int y);
void Update(float dt); void Update(float dt);
void Render(); void Render();
void Push(); void Push();

View File

@@ -226,123 +226,68 @@ bool CardSelector::CheckUserInput(JButton key)
} }
} }
} }
if (active != oldactive) if(key != JGE_BTN_NONE)
{ {
CardView::SelectorZone oldowner, owner; if (active != oldactive)
if (CardView *q = dynamic_cast<CardView*>(oldactive)) {
oldowner = q->owner; CardView::SelectorZone oldowner, owner;
else if (CardView *q = dynamic_cast<CardView*>(oldactive))
oldowner = CardView::nullZone; oldowner = q->owner;
if (CardView *q = dynamic_cast<CardView*>(active)) else
owner = q->owner; oldowner = CardView::nullZone;
else if (CardView *q = dynamic_cast<CardView*>(active))
owner = CardView::nullZone; owner = q->owner;
if (oldowner != owner) else
{ owner = CardView::nullZone;
if (CardView::nullZone != owner) if (oldowner != owner)
{ {
if (PlayGuiObject* old = fetchMemory(lasts[owner])) if (CardView::nullZone != owner)
switch (key) {
{ if (PlayGuiObject* old = fetchMemory(lasts[owner]))
case JGE_BTN_LEFT: switch (key)
if (old->x < oldactive->x) {
active = old; case JGE_BTN_LEFT:
break; if (old->x < oldactive->x)
case JGE_BTN_RIGHT: active = old;
if (old->x > oldactive->x) break;
active = old; case JGE_BTN_RIGHT:
break; if (old->x > oldactive->x)
case JGE_BTN_UP: active = old;
if (old->y < oldactive->y) break;
active = old; case JGE_BTN_UP:
break; if (old->y < oldactive->y)
case JGE_BTN_DOWN: active = old;
if (old->y > oldactive->y) break;
active = old; case JGE_BTN_DOWN:
break; if (old->y > oldactive->y)
default: active = old;
if (old) break;
active = old; default:
break; if (old)
} active = old;
} break;
lasts[oldowner] = SelectorMemory(oldactive); }
} }
} lasts[oldowner] = SelectorMemory(oldactive);
else }
{ }
// active card hasn't changed - that means we're probably at an edge of the battlefield. else
// check if we're not already a selected avatar - if not, select one depending whether we're going up/down. {
GuiAvatar* avatar = dynamic_cast<GuiAvatar*> (active); // active card hasn't changed - that means we're probably at an edge of the battlefield.
if (!avatar) // check if we're not already a selected avatar - if not, select one depending whether we're going up/down.
{ GuiAvatar* avatar = dynamic_cast<GuiAvatar*> (active);
if (key == JGE_BTN_DOWN) if (!avatar)
{ {
active = duel->GetAvatars()->GetSelf(); if (key == JGE_BTN_DOWN)
} {
else if (key == JGE_BTN_UP) active = duel->GetAvatars()->GetSelf();
{ }
active = duel->GetAvatars()->GetOpponent(); else if (key == JGE_BTN_UP)
} {
} active = duel->GetAvatars()->GetOpponent();
} }
if (active != oldactive) }
{ }
{
CardView* c = dynamic_cast<CardView*> (oldactive);
if (c)
c->zoom = 1.0f;
}
{
CardView* c = dynamic_cast<CardView*> (active);
if (c)
c->zoom = 1.4f;
}
if (oldactive)
oldactive->Leaving(JGE_BTN_NONE);
if (active)
active->Entering();
}
return true;
}
bool CardSelector::CheckUserInput(int x, int y)
{
if (!active)
{
for (vector<Target*>::iterator it = cards.begin(); it != cards.end(); ++it)
if ((NULL == limitor) || (limitor->select(*it)))
{
active = *it;
active->Entering();
return true;
}
return true;
}
Target* oldactive = active;
active = closest<True> (cards, limitor, static_cast<float> (x), static_cast<float> (y));
if (active != oldactive)
{
CardView::SelectorZone oldowner, owner;
if (CardView *q = dynamic_cast<CardView*>(oldactive))
oldowner = q->owner;
else
oldowner = CardView::nullZone;
if (CardView *q = dynamic_cast<CardView*>(active))
owner = q->owner;
else
owner = CardView::nullZone;
if (oldowner != owner)
{
if (CardView::nullZone != owner)
{
if (PlayGuiObject* old = fetchMemory(lasts[owner]))
if (old)
active = old;
}
lasts[oldowner] = SelectorMemory(oldactive);
}
} }
if (active != oldactive) if (active != oldactive)
{ {