J :
* Some interface updates.
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
#define _CARDSELECTOR_H_
|
#define _CARDSELECTOR_H_
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <stack>
|
||||||
#include "GuiLayers.h"
|
#include "GuiLayers.h"
|
||||||
#include "DuelLayers.h"
|
#include "DuelLayers.h"
|
||||||
#include "Pos.h"
|
#include "Pos.h"
|
||||||
@@ -26,6 +27,13 @@ class ObjectSelector : public GuiLayer
|
|||||||
typedef enum {
|
typedef enum {
|
||||||
nullZone, handZone, playZone
|
nullZone, handZone, playZone
|
||||||
} SelectorZone;
|
} 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:
|
protected:
|
||||||
vector<T*> cards;
|
vector<T*> cards;
|
||||||
@@ -34,7 +42,10 @@ class ObjectSelector : public GuiLayer
|
|||||||
DuelLayers* duel;
|
DuelLayers* duel;
|
||||||
LimitorFunctor<T>* limitor;
|
LimitorFunctor<T>* limitor;
|
||||||
Pos bigpos;
|
Pos bigpos;
|
||||||
map<const SelectorZone, T*> lasts;
|
map<const SelectorZone, SelectorMemory> lasts;
|
||||||
|
stack<SelectorMemory> memoryStack;
|
||||||
|
|
||||||
|
T* fetchMemory(SelectorMemory&);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ObjectSelector(DuelLayers*);
|
ObjectSelector(DuelLayers*);
|
||||||
@@ -44,6 +55,8 @@ class ObjectSelector : public GuiLayer
|
|||||||
void Update(float dt);
|
void Update(float dt);
|
||||||
void Render();
|
void Render();
|
||||||
void Limit(LimitorFunctor<T>* limitor);
|
void Limit(LimitorFunctor<T>* limitor);
|
||||||
|
void Push();
|
||||||
|
void Pop();
|
||||||
|
|
||||||
typedef T Target;
|
typedef T Target;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -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<>
|
template<>
|
||||||
bool CardSelector::CheckUserInput(u32 key)
|
bool CardSelector::CheckUserInput(u32 key)
|
||||||
{
|
{
|
||||||
@@ -102,16 +142,17 @@ bool CardSelector::CheckUserInput(u32 key)
|
|||||||
if (oldowner != owner)
|
if (oldowner != owner)
|
||||||
{
|
{
|
||||||
if (nullZone != owner)
|
if (nullZone != owner)
|
||||||
if (PlayGuiObject* old = lasts[owner]) active = old;
|
if (PlayGuiObject* old = fetchMemory(lasts[owner]))
|
||||||
lasts[oldowner] = oldactive;
|
active = old;
|
||||||
|
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; }
|
||||||
oldactive->Leaving(key);
|
if (oldactive) oldactive->Leaving(0);
|
||||||
active->Entering();
|
if (active) active->Entering();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -147,7 +188,15 @@ void CardSelector::Limit(LimitorFunctor<Target>* limitor)
|
|||||||
this->limitor = limitor;
|
this->limitor = limitor;
|
||||||
if (limitor && !limitor->select(active))
|
if (limitor && !limitor->select(active))
|
||||||
{
|
{
|
||||||
|
Target* oldactive = active;
|
||||||
active = closest<True>(cards, limitor, active);
|
active = closest<True>(cards, limitor, active);
|
||||||
if (limitor && !limitor->select(active)) active = NULL;
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,4 +26,23 @@ static inline Target* closest(vector<Target*>& cards, Limitor* limitor, Target*
|
|||||||
return card;
|
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
|
#endif
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ void Damage::init(MTGCardInstance * _source, Damageable * _target, int _damage){
|
|||||||
int Damage::resolve(){
|
int Damage::resolve(){
|
||||||
if (damage <0) damage = 0; //Negative damages cannot happen
|
if (damage <0) damage = 0; //Negative damages cannot happen
|
||||||
state = RESOLVED_OK;
|
state = RESOLVED_OK;
|
||||||
|
cout << "RESOLVE " << damage << " >> " << _target->name << endl;
|
||||||
GameObserver * g = GameObserver::GetInstance();
|
GameObserver * g = GameObserver::GetInstance();
|
||||||
WEvent * e = NEW WEventDamage(this);
|
WEvent * e = NEW WEventDamage(this);
|
||||||
|
|
||||||
|
|||||||
@@ -112,7 +112,9 @@ bool GuiHandSelf::CheckUserInput(u32 key)
|
|||||||
if (trigger == key)
|
if (trigger == key)
|
||||||
{
|
{
|
||||||
state = (Open == state ? Closed : Open);
|
state = (Open == state ? Closed : Open);
|
||||||
|
if (Open == state) cs->Push();
|
||||||
cs->Limit(Open == state ? limitor : NULL);
|
cs->Limit(Open == state ? limitor : NULL);
|
||||||
|
if (Closed == state) cs->Pop();
|
||||||
backpos.x = Open == state ? OpenX : ClosedX;
|
backpos.x = Open == state ? OpenX : ClosedX;
|
||||||
Repos();
|
Repos();
|
||||||
return true;
|
return true;
|
||||||
@@ -169,8 +171,8 @@ int GuiHandSelf::receiveEventMinus(WEvent* e)
|
|||||||
{
|
{
|
||||||
CardView* cv = *it;
|
CardView* cv = *it;
|
||||||
cs->Remove(cv);
|
cs->Remove(cv);
|
||||||
Repos();
|
|
||||||
cards.erase(it);
|
cards.erase(it);
|
||||||
|
Repos();
|
||||||
trash(cv);
|
trash(cv);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user