diff --git a/projects/mtg/include/GuiCombat.h b/projects/mtg/include/GuiCombat.h index 9cbbea10b..5bf1115a2 100644 --- a/projects/mtg/include/GuiCombat.h +++ b/projects/mtg/include/GuiCombat.h @@ -28,6 +28,8 @@ protected: void addOne(DefenserDamaged* blocker, CombatStep); void removeOne(DefenserDamaged* blocker, CombatStep); void remaskBlkViews(AttackerDamaged* before, AttackerDamaged* after); + void shiftLeft( DamagerDamaged* oldActive ); + void shiftRight( DamagerDamaged* oldActive ); int resolve(); public: @@ -43,7 +45,6 @@ public: virtual bool CheckUserInput(JButton key); virtual int receiveEventPlus(WEvent* e); virtual int receiveEventMinus(WEvent* e); - typedef vector::iterator inner_iterator; }; diff --git a/projects/mtg/src/GuiCombat.cpp b/projects/mtg/src/GuiCombat.cpp index 93604f1cc..a52401896 100644 --- a/projects/mtg/src/GuiCombat.cpp +++ b/projects/mtg/src/GuiCombat.cpp @@ -197,26 +197,133 @@ bool GuiCombat::clickOK() return false; } + +void GuiCombat::shiftLeft( DamagerDamaged* oldActive) +{ + switch (cursor_pos) + { + case NONE: + break; + case OK: + for (vector::reverse_iterator it = attackers.rbegin(); it != attackers.rend(); ++it) + if ((*it)->show) + { + active = *it; + break; + } + activeAtk = static_cast (active); + cursor_pos = ATK; + break; + case ATK: + { + DamagerDamaged* old = active; + active = closest (attackers, NULL, static_cast (active)); + activeAtk = static_cast (active); + if (old != active) + { + if (old) + old->zoom = kZoom_none; + if (active) + active->zoom = kZoom_level1; + } + } + break; + case BLK: + { + DamagerDamaged* old = active; + active = closest (activeAtk->blockers, NULL, static_cast (active)); + if (old != active) + { + if (old) + old->zoom = kZoom_none; + if (active) + active->zoom = kZoom_level1; + } + } + break; + } + +} +void GuiCombat::shiftRight( DamagerDamaged* oldActive ) +{ + switch (cursor_pos) + { + case NONE: + case OK: + break; + case BLK: + { + DamagerDamaged* old = active; + active = closest (activeAtk->blockers, NULL, static_cast (active)); + if (old != active) + { + if (old) + old->zoom = kZoom_none; + if (active) + active->zoom = kZoom_level1; + } + } + break; + case ATK: + { + DamagerDamaged* old = active; + active = closest (attackers, NULL, static_cast (active)); + if (active == oldActive) + { + active = activeAtk = NULL; + cursor_pos = OK; + } + else + { + if (old != active) + { + if (old) + old->zoom = kZoom_none; + if (active) + active->zoom = kZoom_level1; + } + activeAtk = static_cast (active); + } + } + break; + } +} + bool GuiCombat::CheckUserInput(JButton key) { if (NONE == cursor_pos) return false; DamagerDamaged* oldActive = active; -/* + int x,y; - if(observer->getInput()->GetLeftClickCoordinates(x, y)) + if(observer->getInput()->GetLeftClickCoordinates(x, y) && (BLK == cursor_pos)) { - DamagerDamaged* old = active; - active = closest (activeAtk->blockers, NULL, static_cast (x), static_cast (y)); - if (old != active) + DamagerDamaged* selectedCard = closest (activeAtk->blockers, NULL, static_cast (x), static_cast (y)); + // find the index into the vector where the current selected card is. + int c1 = 0, c2 = 0; + int i = 0; + for ( vector::iterator it = activeAtk->blockers.begin(); it != activeAtk->blockers.end(); ++it) { - if (old) - old->zoom = kZoom_none; - if (active) - active->zoom = kZoom_level1; + if ( *it == selectedCard ) + c2 = i; + else if ( *it == active) + c1 = i; + i++; + } + // simulate pressing the "Left/Right D-Pad" control c1 - c2 times + if ( c1 > c2 ) // card selected is to the left of the current active card + { + for (int x = 0; x < c1 - c2; x++) + shiftLeft( oldActive ); + } + else if ( c1 < c2 ) + { + for (int x = 0; x < c2 - c1; x++) + shiftRight( oldActive ); + } } -*/ + switch (key) { case JGE_BTN_OK: