Пример #1
0
bool CardDisplay::CheckUserInput(JButton key)
{
    if (JGE_BTN_SEC == key || JGE_BTN_PRI == key || JGE_BTN_UP == key || JGE_BTN_DOWN == key)
    {
        if (listener)
        {
            listener->ButtonPressed(mId, 0);
            return true;
        }
    }
    if (!mObjects.size()) 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 (observer) observer->ButtonPressed(cardg);
                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_RIGHT:
    {
        int n = mCurr;
        n++;
        if (n >= (int) (mObjects.size()))
        {
            n = mObjects.size() - 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:
    {
      bool result = false;
      unsigned int distance2;
      unsigned int minDistance2 = -1;
      int n = mCurr;
      int x1,y1;
      JButton key;
      JGE* jge = observer?observer->getInput():JGE::GetInstance();
      if(jge)
      {
          if (jge->GetLeftClickCoordinates(x1, y1))
          {
              for (size_t i = 0; i < mObjects.size(); i++)
              {
                  float top, left;
                  if (mObjects[i]->getTopLeft(top, left))
                  {
                      distance2 = static_cast<unsigned int>((top - y1) * (top - y1) + (left - x1) * (left - x1));
                      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 >= (int)(mObjects.size()) && mObjects.size())
              {
                  n = mObjects.size() - 1;
              }
              if (n >= start_item + nb_displayed_items)
              {
                  rotateRight();
              }

              if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(key))
              {
                  mCurr = n;
                  mObjects[mCurr]->Entering();
                  result = true;
              }
              jge->LeftClickedProcessed();
          }
      }
      return result;
    }
    }

    return false;
}
Пример #2
0
bool CardSelector::CheckUserInput(JButton key)
{
    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;
    timer = 800;
    int x,y;
    JGE* jge = observer->getInput();
    if(!jge) return false;
    if(jge->GetLeftClickCoordinates(x, y))
    {
        active = closest<CardSelectorTrue> (cards, limitor, static_cast<float> (x), static_cast<float> (y));
    }

    switch (key)
    {
    case JGE_BTN_SEC:
        observer->cancelCurrentAction();
        goto switch_active;
        break;
    case JGE_BTN_OK:
        observer->ButtonPressed(active);
        goto switch_active;
        break;
    case JGE_BTN_LEFT:
        active = closest<CardSelectorLeft> (cards, limitor, active);
        break;
    case JGE_BTN_RIGHT:
        active = closest<CardSelectorRight> (cards, limitor, active);
        break;
    case JGE_BTN_UP:
        active = closest<CardSelectorUp> (cards, limitor, active);
        break;
    case JGE_BTN_DOWN:
        active = closest<CardSelectorDown> (cards, limitor, active);
        break;
    case JGE_BTN_CANCEL:
        mDrawMode = (mDrawMode + 1) % DrawMode::kNumDrawModes;
        if (mDrawMode == DrawMode::kText)
            options[Options::DISABLECARDS].number = 1;
        else
            options[Options::DISABLECARDS].number = 0;
        return true;
    default:
      {
        if(!jge->GetLeftClickCoordinates(x, y))
        {
          return false;
        }
      }
    }
    if(key != JGE_BTN_NONE)
    {
      if (active != oldactive)
      {
          CardView::SelectorZone oldowner, owner;
          if (CardView *q = dynamic_cast<CardView*>(oldactive))
              oldowner = q->owner;
          else
              oldowner = CardView::nullZone;
          if (CardView *q = dynamic_cast<CardView*>(active))
              owner = q->owner;
          else
              owner = CardView::nullZone;
          if (oldowner != owner)
          {
              if (CardView::nullZone != owner)
              {
                  if (PlayGuiObject* old = fetchMemory(lasts[owner]))
                      switch (key)
                      {
                      case JGE_BTN_LEFT:
                          if (old->x < oldactive->x)
                              active = old;
                          break;
                      case JGE_BTN_RIGHT:
                          if (old->x > oldactive->x)
                              active = old;
                          break;
                      case JGE_BTN_UP:
                          if (old->y < oldactive->y)
                              active = old;
                          break;
                      case JGE_BTN_DOWN:
                          if (old->y > oldactive->y)
                              active = old;
                          break;
                      default:
                          if (old)
                              active = old;
                          break;
                      }
              }
              lasts[oldowner] = SelectorMemory(oldactive);
          }
      }
      else
      {
          // active card hasn't changed - that means we're probably at an edge of the battlefield.
          // check if we're not already a selected avatar - if not, select one depending whether we're going up/down.
          GuiAvatar* avatar = dynamic_cast<GuiAvatar*> (active);
          if (!avatar)
          {
              if (key == JGE_BTN_DOWN)
              {
                  active = duel->GetAvatars()->GetSelf();
              }
              else if (key == JGE_BTN_UP)
              {
                  active = duel->GetAvatars()->GetOpponent();
              }
          }
      }
    }

switch_active:
    if (active != oldactive)
    {
        {
            PlayGuiObject* c = dynamic_cast<PlayGuiObject*> (oldactive);
            if (c)
                c->zoom = 1.0f;
        }
        {
            PlayGuiObject* c = dynamic_cast<PlayGuiObject*> (active);
            if (c)
                c->zoom = 1.4f;
        }
        if (oldactive)
            oldactive->Leaving(JGE_BTN_NONE);
        if (active)
            active->Entering();
    }
    else
    {
        timer = 800;
    }
    return true;
}