Mouse support in graveyards an library browsing during battle
This commit is contained in:
@@ -21,6 +21,7 @@ class CardDisplay:public PlayGuiObjectController{
|
||||
void rotateLeft();
|
||||
void rotateRight();
|
||||
bool CheckUserInput(JButton key);
|
||||
bool CheckUserInput(int x, int y);
|
||||
virtual void Update(float dt);
|
||||
void Render();
|
||||
void init(MTGGameZone * zone);
|
||||
|
||||
@@ -30,6 +30,7 @@ class GuiAvatars : public GuiLayer
|
||||
int receiveEventPlus(WEvent*);
|
||||
int receiveEventMinus(WEvent*);
|
||||
bool CheckUserInput(JButton key);
|
||||
bool CheckUserInput(int x, int y);
|
||||
float LeftBoundarySelf();
|
||||
};
|
||||
|
||||
|
||||
@@ -44,6 +44,7 @@ struct GuiGameZone : public GuiStatic{
|
||||
int showCards;
|
||||
virtual void Render();
|
||||
virtual bool CheckUserInput(JButton key);
|
||||
virtual bool CheckUserInput(int x, int y);
|
||||
virtual void Update(float dt);
|
||||
GuiGameZone(float x, float y, bool hasFocus, MTGGameZone * zone, GuiAvatars* parent);
|
||||
~GuiGameZone();
|
||||
|
||||
@@ -34,6 +34,7 @@ class PlayGuiObject: public JGuiObject, public JGuiListener, public Pos{
|
||||
PlayGuiObject(float desiredHeight, float x, float y, bool hasFocus);
|
||||
PlayGuiObject(float desiredHeight, const Pos& ref, bool hasFocus);
|
||||
virtual void ButtonPressed(int controllerId, int controlId){};
|
||||
virtual bool getTopLeft(int& top, int& left) {top = actY; left = actX; return true;};
|
||||
virtual ~PlayGuiObject(){};
|
||||
vector<Effect*> effects;
|
||||
};
|
||||
|
||||
@@ -77,68 +77,121 @@ void CardDisplay::Update(float dt){
|
||||
if (update) init(zone);
|
||||
}
|
||||
|
||||
bool CardDisplay::CheckUserInput(JButton key){
|
||||
if (JGE_BTN_SEC == key || JGE_BTN_PRI == key)
|
||||
bool CardDisplay::CheckUserInput(int x, int y) {
|
||||
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){
|
||||
listener->ButtonPressed(mId, 0);
|
||||
return true;
|
||||
int top, left;
|
||||
if(mObjects[i]->getTopLeft(top, left))
|
||||
{
|
||||
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)
|
||||
return false;
|
||||
|
||||
if (mActionButton == key)
|
||||
{
|
||||
if (mObjects[mCurr] && mObjects[mCurr]->ButtonPressed()){
|
||||
CardGui * cardg = (CardGui *)mObjects[mCurr];
|
||||
if (tc)
|
||||
{
|
||||
tc->toggleTarget(cardg->card);
|
||||
return true;
|
||||
}else{
|
||||
if (game) game->ButtonPressed(cardg);
|
||||
return true;
|
||||
}
|
||||
{
|
||||
if (mObjects[mCurr] && mObjects[mCurr]->ButtonPressed()){
|
||||
CardGui * cardg = (CardGui *)mObjects[mCurr];
|
||||
if (tc) {
|
||||
tc->toggleTarget(cardg->card);
|
||||
return true;
|
||||
} else {
|
||||
if (game) game->ButtonPressed(cardg);
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
switch(key)
|
||||
{
|
||||
case JGE_BTN_LEFT :
|
||||
{
|
||||
int n = mCurr;
|
||||
n--;
|
||||
if (n<start_item){
|
||||
if (n< 0){n = 0;}
|
||||
else{ rotateLeft();}
|
||||
}
|
||||
if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(JGE_BTN_LEFT)){
|
||||
mCurr = n;
|
||||
mObjects[mCurr]->Entering();
|
||||
}
|
||||
return true;
|
||||
{
|
||||
case JGE_BTN_LEFT :
|
||||
{
|
||||
int n = mCurr;
|
||||
n--;
|
||||
if (n<start_item) {
|
||||
if (n< 0) {
|
||||
n = 0;
|
||||
} else {
|
||||
rotateLeft();
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -73,7 +73,11 @@ void DuelLayers::CheckUserInput(int isAI){
|
||||
}
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -80,6 +80,17 @@ bool GuiAvatars::CheckUserInput(JButton key){
|
||||
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)
|
||||
{
|
||||
self->Update(dt);
|
||||
|
||||
@@ -180,6 +180,11 @@ bool GuiGameZone::CheckUserInput(JButton key){
|
||||
return false;
|
||||
}
|
||||
|
||||
bool GuiGameZone::CheckUserInput(int x, int y){
|
||||
if (showCards) return cd->CheckUserInput(x, y);
|
||||
return false;
|
||||
}
|
||||
|
||||
void GuiGameZone::Update(float dt){
|
||||
if (showCards) cd->Update(dt);
|
||||
PlayGuiObject::Update(dt);
|
||||
|
||||
Reference in New Issue
Block a user