Mouse support in graveyards an library browsing during battle

This commit is contained in:
Xawotihs
2010-10-13 22:28:19 +00:00
parent 4a0331cbb9
commit e8ecd74361
8 changed files with 125 additions and 48 deletions
+1
View File
@@ -21,6 +21,7 @@ class CardDisplay:public PlayGuiObjectController{
void rotateLeft(); void rotateLeft();
void rotateRight(); void rotateRight();
bool CheckUserInput(JButton key); bool CheckUserInput(JButton key);
bool CheckUserInput(int x, int y);
virtual void Update(float dt); virtual void Update(float dt);
void Render(); void Render();
void init(MTGGameZone * zone); void init(MTGGameZone * zone);
+1
View File
@@ -30,6 +30,7 @@ class GuiAvatars : public GuiLayer
int receiveEventPlus(WEvent*); int receiveEventPlus(WEvent*);
int receiveEventMinus(WEvent*); int receiveEventMinus(WEvent*);
bool CheckUserInput(JButton key); bool CheckUserInput(JButton key);
bool CheckUserInput(int x, int y);
float LeftBoundarySelf(); float LeftBoundarySelf();
}; };
+1
View File
@@ -44,6 +44,7 @@ struct GuiGameZone : public GuiStatic{
int showCards; int showCards;
virtual void Render(); virtual void Render();
virtual bool CheckUserInput(JButton key); virtual bool CheckUserInput(JButton key);
virtual bool CheckUserInput(int x, int y);
virtual void Update(float dt); virtual void Update(float dt);
GuiGameZone(float x, float y, bool hasFocus, MTGGameZone * zone, GuiAvatars* parent); GuiGameZone(float x, float y, bool hasFocus, MTGGameZone * zone, GuiAvatars* parent);
~GuiGameZone(); ~GuiGameZone();
+1
View File
@@ -34,6 +34,7 @@ class PlayGuiObject: public JGuiObject, public JGuiListener, public Pos{
PlayGuiObject(float desiredHeight, float x, float y, bool hasFocus); PlayGuiObject(float desiredHeight, float x, float y, bool hasFocus);
PlayGuiObject(float desiredHeight, const Pos& ref, bool hasFocus); PlayGuiObject(float desiredHeight, const Pos& ref, bool hasFocus);
virtual void ButtonPressed(int controllerId, int controlId){}; virtual void ButtonPressed(int controllerId, int controlId){};
virtual bool getTopLeft(int& top, int& left) {top = actY; left = actX; return true;};
virtual ~PlayGuiObject(){}; virtual ~PlayGuiObject(){};
vector<Effect*> effects; vector<Effect*> effects;
}; };
+100 -47
View File
@@ -77,68 +77,121 @@ void CardDisplay::Update(float dt){
if (update) init(zone); if (update) init(zone);
} }
bool CardDisplay::CheckUserInput(JButton key){ bool CardDisplay::CheckUserInput(int x, int y) {
if (JGE_BTN_SEC == key || JGE_BTN_PRI == key) unsigned int distance2;
unsigned int minDistance2 = -1;
int n = mCurr;
JButton key;
if(JGE::GetInstance()->GetLeftClickCoordinates(x, y))
{
for(int i = 0; i < mCount; i++)
{ {
if (listener){ int top, left;
listener->ButtonPressed(mId, 0); if(mObjects[i]->getTopLeft(top, left))
return true; {
distance2 = (top-y)*(top-y) + (left-x)*(left-x);
if(distance2 < minDistance2)
{
minDistance2 = distance2;
n = i;
}
} }
} }
if(n < mCurr)
key = JGE_BTN_LEFT;
else
key = JGE_BTN_RIGHT;
if (n<start_item) {
rotateLeft();
} else if (n>= mCount) {
n = mCount-1;
}
if (n>= start_item + nb_displayed_items) {
rotateRight();
}
if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(key))
{
mCurr = n;
mObjects[mCurr]->Entering();
}
JGE::GetInstance()->LeftClickedProcessed();
return true;
}
return false;
}
bool CardDisplay::CheckUserInput(JButton key){
if (JGE_BTN_SEC == key || JGE_BTN_PRI == key)
{
if (listener){
listener->ButtonPressed(mId, 0);
return true;
}
}
if (!mCount) if (!mCount)
return false; return false;
if (mActionButton == key) if (mActionButton == key)
{ {
if (mObjects[mCurr] && mObjects[mCurr]->ButtonPressed()){ if (mObjects[mCurr] && mObjects[mCurr]->ButtonPressed()){
CardGui * cardg = (CardGui *)mObjects[mCurr]; CardGui * cardg = (CardGui *)mObjects[mCurr];
if (tc) if (tc) {
{ tc->toggleTarget(cardg->card);
tc->toggleTarget(cardg->card); return true;
return true; } else {
}else{ if (game) game->ButtonPressed(cardg);
if (game) game->ButtonPressed(cardg); return true;
return true;
}
} }
return true;
} }
return true;
}
switch(key) switch(key)
{ {
case JGE_BTN_LEFT : case JGE_BTN_LEFT :
{ {
int n = mCurr; int n = mCurr;
n--; n--;
if (n<start_item){ if (n<start_item) {
if (n< 0){n = 0;} if (n< 0) {
else{ rotateLeft();} n = 0;
} } else {
if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(JGE_BTN_LEFT)){ rotateLeft();
mCurr = n;
mObjects[mCurr]->Entering();
}
return true;
} }
case JGE_BTN_RIGHT :
{
int n = mCurr;
n++;
if (n>= mCount){n = mCount-1;}
if (n>= start_item + nb_displayed_items){
rotateRight();
}
if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(JGE_BTN_RIGHT)){
mCurr = n;
mObjects[mCurr]->Entering();
}
}
return true;
default:
;
} }
if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(JGE_BTN_LEFT)){
mCurr = n;
mObjects[mCurr]->Entering();
}
return true;
}
case JGE_BTN_RIGHT :
{
int n = mCurr;
n++;
if (n>= mCount) {
n = mCount-1;
}
if (n>= start_item + nb_displayed_items) {
rotateRight();
}
if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(JGE_BTN_RIGHT)){
mCurr = n;
mObjects[mCurr]->Entering();
}
}
return true;
default:
;
}
return false; return false;
} }
+5 -1
View File
@@ -73,7 +73,11 @@ void DuelLayers::CheckUserInput(int isAI){
} }
if(JGE::GetInstance()->GetLeftClickCoordinates(x, y)) if(JGE::GetInstance()->GetLeftClickCoordinates(x, y))
{ {
if (cs->CheckUserInput(x, y)) if (avatars->CheckUserInput(x, y))
{
JGE::GetInstance()->LeftClickedProcessed();
}
else if (cs->CheckUserInput(x, y))
{ {
JGE::GetInstance()->LeftClickedProcessed(); JGE::GetInstance()->LeftClickedProcessed();
} }
+11
View File
@@ -80,6 +80,17 @@ bool GuiAvatars::CheckUserInput(JButton key){
return false; return false;
} }
bool GuiAvatars::CheckUserInput(int x, int y){
// if (self->CheckUserInput(key)) return true;
// if (opponent->CheckUserInput(key)) return true;
if (selfGraveyard->CheckUserInput(x, y)) return true;
if (opponentGraveyard->CheckUserInput(x, y)) return true;
if (opponentHand->CheckUserInput(x, y)) return true;
if (selfLibrary->CheckUserInput(x, y)) return true;
if (opponentLibrary->CheckUserInput(x, y)) return true;
return false;
}
void GuiAvatars::Update(float dt) void GuiAvatars::Update(float dt)
{ {
self->Update(dt); self->Update(dt);
+5
View File
@@ -180,6 +180,11 @@ bool GuiGameZone::CheckUserInput(JButton key){
return false; return false;
} }
bool GuiGameZone::CheckUserInput(int x, int y){
if (showCards) return cd->CheckUserInput(x, y);
return false;
}
void GuiGameZone::Update(float dt){ void GuiGameZone::Update(float dt){
if (showCards) cd->Update(dt); if (showCards) cd->Update(dt);
PlayGuiObject::Update(dt); PlayGuiObject::Update(dt);