Added left mouse click support for menu, submenu and battle

This commit is contained in:
Xawotihs
2010-10-10 21:59:18 +00:00
parent e342103204
commit 93b1656f13
5 changed files with 57 additions and 7 deletions

View File

@@ -59,6 +59,7 @@ class ObjectSelector : public GuiLayer
void Add(T*); void Add(T*);
void Remove(T*); void Remove(T*);
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

@@ -39,6 +39,7 @@ class MenuItem: public JGuiObject
virtual void Entering(); virtual void Entering();
virtual bool Leaving(JButton key); virtual bool Leaving(JButton key);
virtual bool ButtonPressed(); virtual bool ButtonPressed();
virtual bool getTopLeft(int& top, int& left) {top = mY; left = mX; return true;};
virtual ostream& toString(ostream& out) const; virtual ostream& toString(ostream& out) const;
}; };

View File

@@ -42,6 +42,7 @@ class SimpleMenuItem: public JGuiObject
virtual bool Leaving(JButton key); virtual bool Leaving(JButton key);
virtual bool ButtonPressed(); virtual bool ButtonPressed();
virtual ostream& toString(ostream& out) const; virtual ostream& toString(ostream& out) const;
virtual bool getTopLeft(int& top, int& left) {top = mY; left = mX; return true;};
}; };
#endif #endif

View File

@@ -167,6 +167,43 @@ bool CardSelector::CheckUserInput(JButton key)
return true; return true;
} }
template<>
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, x, y);
if (active != oldactive) {
SelectorZone oldowner, owner;
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 (oldowner != owner) {
if (nullZone != owner) {
if (PlayGuiObject* old = fetchMemory(lasts[owner]))
if (old) active = old;
}
lasts[oldowner] = SelectorMemory(oldactive);
}
}
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;
}
template<> template<>
void CardSelector::Update(float dt) { void CardSelector::Update(float dt) {
float boundary = duel->RightBoundary(); float boundary = duel->RightBoundary();

View File

@@ -58,16 +58,26 @@ void DuelLayers::init(){
void DuelLayers::CheckUserInput(int isAI){ void DuelLayers::CheckUserInput(int isAI){
JButton key; JButton key;
while ((key = JGE::GetInstance()->ReadButton())){ int x, y;
while ((key = JGE::GetInstance()->ReadButton()) || JGE::GetInstance()->GetLeftClickCoordinates(x, y))
{
if ((!isAI) && (0 != key)) if ((!isAI) && (0 != key))
{
if (stack->CheckUserInput(key)) break;
if (combat->CheckUserInput(key)) break;
if (avatars->CheckUserInput(key)) break; //avatars need to check their input before action (CTRL_CROSS)
if (action->CheckUserInput(key)) break;
if (hand->CheckUserInput(key)) break;
if (cs->CheckUserInput(key)) break;
}
else if((!isAI) && (x != -1 && y != -1))
{
if (cs->CheckUserInput(x, y))
{ {
if (stack->CheckUserInput(key)) break; JGE::GetInstance()->LeftClickedProcessed();
if (combat->CheckUserInput(key)) break; break;
if (avatars->CheckUserInput(key)) break; //avatars need to check their input before action (CTRL_CROSS)
if (action->CheckUserInput(key)) break;
if (hand->CheckUserInput(key)) break;
if (cs->CheckUserInput(key)) break;
} }
}
} }
} }