* Some interface updates.
This commit is contained in:
jean.chalard
2009-09-13 10:57:55 +00:00
parent 7c4fbde7d3
commit 1f67998d7a
5 changed files with 90 additions and 7 deletions

View File

@@ -2,6 +2,7 @@
#define _CARDSELECTOR_H_
#include <vector>
#include <stack>
#include "GuiLayers.h"
#include "DuelLayers.h"
#include "Pos.h"
@@ -26,6 +27,13 @@ class ObjectSelector : public GuiLayer
typedef enum {
nullZone, handZone, playZone
} SelectorZone;
struct SelectorMemory
{
T* object;
float x, y;
SelectorMemory(T* object) : object(object) { if (object) { x = object->x; y = object->y; } };
SelectorMemory() { object = NULL; x = y = 0; };
};
protected:
vector<T*> cards;
@@ -34,7 +42,10 @@ class ObjectSelector : public GuiLayer
DuelLayers* duel;
LimitorFunctor<T>* limitor;
Pos bigpos;
map<const SelectorZone, T*> lasts;
map<const SelectorZone, SelectorMemory> lasts;
stack<SelectorMemory> memoryStack;
T* fetchMemory(SelectorMemory&);
public:
ObjectSelector(DuelLayers*);
@@ -44,6 +55,8 @@ class ObjectSelector : public GuiLayer
void Update(float dt);
void Render();
void Limit(LimitorFunctor<T>* limitor);
void Push();
void Pop();
typedef T Target;
};

View File

@@ -55,6 +55,46 @@ void CardSelector::Remove(CardSelector::Target* card)
}
}
template <>
CardSelector::Target* CardSelector::fetchMemory(SelectorMemory& memory)
{
if (NULL == memory.object) return NULL;
for (vector<Target*>::iterator it = cards.begin(); it != cards.end(); ++it)
{
if (*it == memory.object)
{
if ((NULL == limitor) || (limitor->select(memory.object)))
return memory.object;
else break;
}
}
// 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.
return closest<True>(cards, limitor, memory.x, memory.y);
}
template<>
void CardSelector::Push()
{
memoryStack.push(SelectorMemory(active));
}
template<>
void CardSelector::Pop()
{
Target* oldactive = active;
if (!memoryStack.empty())
{
active = fetchMemory(memoryStack.top());
memoryStack.pop();
}
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(0);
if (active) active->Entering();
}
}
template<>
bool CardSelector::CheckUserInput(u32 key)
{
@@ -102,16 +142,17 @@ bool CardSelector::CheckUserInput(u32 key)
if (oldowner != owner)
{
if (nullZone != owner)
if (PlayGuiObject* old = lasts[owner]) active = old;
lasts[oldowner] = oldactive;
if (PlayGuiObject* old = fetchMemory(lasts[owner]))
active = old;
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; }
oldactive->Leaving(key);
active->Entering();
if (oldactive) oldactive->Leaving(0);
if (active) active->Entering();
}
return true;
}
@@ -147,7 +188,15 @@ void CardSelector::Limit(LimitorFunctor<Target>* limitor)
this->limitor = limitor;
if (limitor && !limitor->select(active))
{
Target* oldactive = active;
active = closest<True>(cards, limitor, active);
if (limitor && !limitor->select(active)) active = NULL;
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(0);
if (active) active->Entering();
}
}
}

View File

@@ -26,4 +26,23 @@ static inline Target* closest(vector<Target*>& cards, Limitor* limitor, Target*
return card;
}
template <typename T, typename Target>
static inline Target* closest(vector<Target*>& cards, Limitor* limitor, float x, float y)
{
Target* card = NULL;
float curdist = 1000000.0f; // This is bigger than any possible distance
for (typename vector<Target*>::iterator it = cards.begin(); it != cards.end(); ++it)
{
if ((*it)->actA < 32) continue;
if ((NULL != limitor) && (!limitor->select(*it))) continue;
float dist = ((*it)->x - x) * ((*it)->x - x) + ((*it)->y - y) * ((*it)->y - y);
if (dist < curdist)
{
curdist = dist;
card = *it;
}
}
return card;
}
#endif

View File

@@ -28,7 +28,7 @@ void Damage::init(MTGCardInstance * _source, Damageable * _target, int _damage){
int Damage::resolve(){
if (damage <0) damage = 0; //Negative damages cannot happen
state = RESOLVED_OK;
cout << "RESOLVE " << damage << " >> " << _target->name << endl;
GameObserver * g = GameObserver::GetInstance();
WEvent * e = NEW WEventDamage(this);

View File

@@ -112,7 +112,9 @@ bool GuiHandSelf::CheckUserInput(u32 key)
if (trigger == key)
{
state = (Open == state ? Closed : Open);
if (Open == state) cs->Push();
cs->Limit(Open == state ? limitor : NULL);
if (Closed == state) cs->Pop();
backpos.x = Open == state ? OpenX : ClosedX;
Repos();
return true;
@@ -169,8 +171,8 @@ int GuiHandSelf::receiveEventMinus(WEvent* e)
{
CardView* cv = *it;
cs->Remove(cv);
Repos();
cards.erase(it);
Repos();
trash(cv);
return 1;
}