enabled touch code for handling choosign blockers on touch interface.

TODO:  Please have somebody test on non-Touch device.  I don't have one anymore.  If it breaks it let me know and I'll make it a compile time option.  Seems to work with 2 and 3 blockers.  I couldn't get the game to get 4 blockers on the screen, but I think it should work the same.  This should be cross platform and not iOS specific
This commit is contained in:
techdragon.nguyen@gmail.com
2011-12-30 23:42:13 +00:00
parent e102d3f369
commit c88ed95c95
2 changed files with 119 additions and 11 deletions
+2 -1
View File
@@ -28,6 +28,8 @@ protected:
void addOne(DefenserDamaged* blocker, CombatStep); void addOne(DefenserDamaged* blocker, CombatStep);
void removeOne(DefenserDamaged* blocker, CombatStep); void removeOne(DefenserDamaged* blocker, CombatStep);
void remaskBlkViews(AttackerDamaged* before, AttackerDamaged* after); void remaskBlkViews(AttackerDamaged* before, AttackerDamaged* after);
void shiftLeft( DamagerDamaged* oldActive );
void shiftRight( DamagerDamaged* oldActive );
int resolve(); int resolve();
public: public:
@@ -43,7 +45,6 @@ public:
virtual bool CheckUserInput(JButton key); virtual bool CheckUserInput(JButton key);
virtual int receiveEventPlus(WEvent* e); virtual int receiveEventPlus(WEvent* e);
virtual int receiveEventMinus(WEvent* e); virtual int receiveEventMinus(WEvent* e);
typedef vector<AttackerDamaged*>::iterator inner_iterator; typedef vector<AttackerDamaged*>::iterator inner_iterator;
}; };
+116 -9
View File
@@ -197,17 +197,28 @@ bool GuiCombat::clickOK()
return false; return false;
} }
bool GuiCombat::CheckUserInput(JButton key)
void GuiCombat::shiftLeft( DamagerDamaged* oldActive)
{ {
if (NONE == cursor_pos) switch (cursor_pos)
return false; {
DamagerDamaged* oldActive = active; case NONE:
/* break;
int x,y; case OK:
if(observer->getInput()->GetLeftClickCoordinates(x, y)) for (vector<AttackerDamaged*>::reverse_iterator it = attackers.rbegin(); it != attackers.rend(); ++it)
if ((*it)->show)
{
active = *it;
break;
}
activeAtk = static_cast<AttackerDamaged*> (active);
cursor_pos = ATK;
break;
case ATK:
{ {
DamagerDamaged* old = active; DamagerDamaged* old = active;
active = closest<True> (activeAtk->blockers, NULL, static_cast<float> (x), static_cast<float> (y)); active = closest<Left> (attackers, NULL, static_cast<AttackerDamaged*> (active));
activeAtk = static_cast<AttackerDamaged*> (active);
if (old != active) if (old != active)
{ {
if (old) if (old)
@@ -216,7 +227,103 @@ bool GuiCombat::CheckUserInput(JButton key)
active->zoom = kZoom_level1; active->zoom = kZoom_level1;
} }
} }
*/ break;
case BLK:
{
DamagerDamaged* old = active;
active = closest<Left> (activeAtk->blockers, NULL, static_cast<DefenserDamaged*> (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<Right> (activeAtk->blockers, NULL, static_cast<DefenserDamaged*> (active));
if (old != active)
{
if (old)
old->zoom = kZoom_none;
if (active)
active->zoom = kZoom_level1;
}
}
break;
case ATK:
{
DamagerDamaged* old = active;
active = closest<Right> (attackers, NULL, static_cast<AttackerDamaged*> (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<AttackerDamaged*> (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) && (BLK == cursor_pos))
{
DamagerDamaged* selectedCard = closest<True> (activeAtk->blockers, NULL, static_cast<float> (x), static_cast<float> (y));
// find the index into the vector where the current selected card is.
int c1 = 0, c2 = 0;
int i = 0;
for ( vector<DamagerDamaged*>::iterator it = activeAtk->blockers.begin(); it != activeAtk->blockers.end(); ++it)
{
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) switch (key)
{ {
case JGE_BTN_OK: case JGE_BTN_OK: