implemented platform independant clickable OK button on gui combat window when selecting blocker order. removed iOS specific coding.

This commit is contained in:
techdragon.nguyen@gmail.com
2011-12-31 08:21:00 +00:00
parent f93246c75c
commit dfa007cecb
7 changed files with 127 additions and 213 deletions
-3
View File
@@ -6,11 +6,8 @@
BOOL bannerIsVisible; BOOL bannerIsVisible;
} }
- (void)addOkButtonListener: (CGRect) frame;
@property (nonatomic, retain) id eaglView; @property (nonatomic, retain) id eaglView;
@property (nonatomic, retain) UITextField *inputField; @property (nonatomic, retain) UITextField *inputField;
@property (nonatomic, retain) UIButton *okButtonView;
@property (nonatomic, assign) BOOL bannerIsVisible; @property (nonatomic, assign) BOOL bannerIsVisible;
@end @end
-27
View File
@@ -10,7 +10,6 @@
@synthesize bannerIsVisible; @synthesize bannerIsVisible;
@synthesize eaglView; @synthesize eaglView;
@synthesize okButtonView;
@synthesize inputField; @synthesize inputField;
#pragma mark initialization / deallocation methods #pragma mark initialization / deallocation methods
@@ -39,7 +38,6 @@
[eaglView setDelegate: nil]; [eaglView setDelegate: nil];
[eaglView release], eaglView = nil; [eaglView release], eaglView = nil;
[inputField release], inputField = nil; [inputField release], inputField = nil;
[okButtonView release], okButtonView = nil;
[super dealloc]; [super dealloc];
} }
@@ -88,31 +86,6 @@
// e.g. self.myOutlet = nil; // e.g. self.myOutlet = nil;
} }
#pragma mark - UIView Creation
- (void)addOkButtonListener: (CGRect) frame
{
// create an invisible view to handle the pressing of the OK button.
if ( okButtonView == nil )
{
okButtonView = [[UIButton alloc] initWithFrame: frame];
[okButtonView setBackgroundColor: [UIColor clearColor]];
[okButtonView setEnabled: YES];
[okButtonView addTarget: self.view action:@selector(handleOK:) forControlEvents: UIControlEventTouchUpInside];
[self.view addSubview: okButtonView];
}
else
{
[self.view bringSubviewToFront: okButtonView];
}
}
- (void)removeOkButtonListener
{
[[self.view.subviews lastObject] removeFromSuperview];
[okButtonView release], okButtonView = nil;
}
#pragma mark - device orientation handlers #pragma mark - device orientation handlers
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
-3
View File
@@ -150,9 +150,6 @@
width: (CGFloat) width width: (CGFloat) width
height: (CGFloat) height height: (CGFloat) height
{ {
CGRect uiFrame = CGRectMake(x, y, width, height);
if ( [command isEqualToString: @"okbuttoncreated"] )
[glViewController addOkButtonListener: uiFrame];
} }
- (void)handleWEngineCommand:(NSString *) command withParameter: (NSString *) parameter - (void)handleWEngineCommand:(NSString *) command withParameter: (NSString *) parameter
+2 -1
View File
@@ -28,8 +28,9 @@ 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 shiftLeft();
void shiftRight( DamagerDamaged* oldActive ); void shiftRight( DamagerDamaged* oldActive );
bool didClickOnButton( Pos buttonPosition, int& x, int& y);
int resolve(); int resolve();
public: public:
+1
View File
@@ -7,6 +7,7 @@ struct Pos
{ {
float actX, actY, actZ, actT, actA; float actX, actY, actZ, actT, actA;
float x, y, zoom, t, alpha; float x, y, zoom, t, alpha;
float width, height;
PIXEL_TYPE mask; PIXEL_TYPE mask;
Pos(float, float, float, float, float); Pos(float, float, float, float, float);
virtual void Update(float dt); virtual void Update(float dt);
+108 -165
View File
@@ -198,7 +198,7 @@ bool GuiCombat::clickOK()
} }
void GuiCombat::shiftLeft( DamagerDamaged* oldActive) void GuiCombat::shiftLeft()
{ {
switch (cursor_pos) switch (cursor_pos)
{ {
@@ -242,8 +242,9 @@ void GuiCombat::shiftLeft( DamagerDamaged* oldActive)
} }
break; break;
} }
} }
void GuiCombat::shiftRight( DamagerDamaged* oldActive ) void GuiCombat::shiftRight( DamagerDamaged* oldActive )
{ {
switch (cursor_pos) switch (cursor_pos)
@@ -289,6 +290,17 @@ void GuiCombat::shiftRight( DamagerDamaged* oldActive )
} }
} }
bool GuiCombat::didClickOnButton( Pos buttonPosition, int& x, int& y)
{
int x1 = buttonPosition.x - MARGIN;
int y1 = buttonPosition.y;
int x2 = static_cast<int>(buttonPosition.x + buttonPosition.width);
int y2 = static_cast<int>(buttonPosition.y + buttonPosition.height);
if ( (x >= x1 && x < x2) && (y >= y1 && y < y2))
return true;
return false;
}
bool GuiCombat::CheckUserInput(JButton key) bool GuiCombat::CheckUserInput(JButton key)
{ {
if (NONE == cursor_pos) if (NONE == cursor_pos)
@@ -296,192 +308,124 @@ bool GuiCombat::CheckUserInput(JButton key)
DamagerDamaged* oldActive = active; DamagerDamaged* oldActive = active;
int x,y; int x,y;
if(observer->getInput()->GetLeftClickCoordinates(x, y) && (BLK == cursor_pos)) if(observer->getInput()->GetLeftClickCoordinates(x, y))
{ {
DamagerDamaged* selectedCard = closest<True> (activeAtk->blockers, NULL, static_cast<float> (x), static_cast<float> (y)); // determine if OK button was clicked on
// find the index into the vector where the current selected card is. if (ok.width)
int c1 = 0, c2 = 0;
int i = 0;
for ( vector<DamagerDamaged*>::iterator it = activeAtk->blockers.begin(); it != activeAtk->blockers.end(); ++it)
{ {
if ( *it == selectedCard ) if (didClickOnButton(ok, x, y))
c2 = i; {
else if ( *it == active) cursor_pos = OK;
c1 = i; }
i++;
} }
// simulate pressing the "Left/Right D-Pad" control c1 - c2 times // position selected card
if ( c1 > c2 ) // card selected is to the left of the current active card if (BLK == cursor_pos)
{ {
for (int x = 0; x < c1 - c2; x++) DamagerDamaged* selectedCard = closest<True> (activeAtk->blockers, NULL, static_cast<float> (x), static_cast<float> (y));
shiftLeft( oldActive ); // find the index into the vector where the current selected card is.
} int c1 = 0, c2 = 0;
else if ( c1 < c2 ) int i = 0;
{ for ( vector<DamagerDamaged*>::iterator it = activeAtk->blockers.begin(); it != activeAtk->blockers.end(); ++it)
for (int x = 0; x < c2 - c1; x++) {
shiftRight( oldActive ); 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();
}
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:
if (BLK == cursor_pos) if (BLK == cursor_pos)
{
if (ORDER == step)
observer->cardClick(active->card); // { activeAtk->card->raiseBlockerRankOrder(active->card); }
else
{ {
signed damage = activeAtk->card->stepPower(step); if (ORDER == step)
for (vector<DamagerDamaged*>::iterator it = activeAtk->blockers.begin(); *it != active; ++it) observer->cardClick(active->card); // { activeAtk->card->raiseBlockerRankOrder(active->card); }
damage -= (*it)->sumDamages();
signed now = active->sumDamages();
damage -= now;
if (damage > 0)
addOne(active, step);
else if (activeAtk->card->has(Constants::DEATHTOUCH))
for (; now >= 1; --now)
removeOne(active, step);
else else
for (now -= active->card->toughness; now >= 0; --now)
removeOne(active, step);
}
}
else if (ATK == cursor_pos)
{
active = activeAtk->blockers.front();
active->zoom = kZoom_level3;
cursor_pos = BLK;
}
else if (OK == cursor_pos)
{
clickOK();
}
break;
case JGE_BTN_CANCEL:
if (BLK == cursor_pos)
{
oldActive->zoom = kZoom_level2;
active = activeAtk;
cursor_pos = ATK;
}
return true;
case JGE_BTN_LEFT:
switch (cursor_pos)
{
case NONE:
break;
case OK:
for (vector<AttackerDamaged*>::reverse_iterator it = attackers.rbegin(); it != attackers.rend(); ++it)
if ((*it)->show)
{ {
active = *it; signed damage = activeAtk->card->stepPower(step);
break; for (vector<DamagerDamaged*>::iterator it = activeAtk->blockers.begin(); *it != active; ++it)
damage -= (*it)->sumDamages();
signed now = active->sumDamages();
damage -= now;
if (damage > 0)
addOne(active, step);
else if (activeAtk->card->has(Constants::DEATHTOUCH))
for (; now >= 1; --now)
removeOne(active, step);
else
for (now -= active->card->toughness; now >= 0; --now)
removeOne(active, step);
} }
activeAtk = static_cast<AttackerDamaged*> (active);
cursor_pos = ATK;
break;
case ATK:
{
DamagerDamaged* old = active;
active = closest<Left> (attackers, NULL, static_cast<AttackerDamaged*> (active));
activeAtk = static_cast<AttackerDamaged*> (active);
if (old != active)
{
if (old)
old->zoom = kZoom_none;
if (active)
active->zoom = kZoom_level1;
} }
} else if (ATK == cursor_pos)
break;
case BLK:
{
DamagerDamaged* old = active;
active = closest<Left> (activeAtk->blockers, NULL, static_cast<DefenserDamaged*> (active));
if (old != active)
{ {
if (old) active = activeAtk->blockers.front();
old->zoom = kZoom_none; active->zoom = kZoom_level3;
if (active) cursor_pos = BLK;
active->zoom = kZoom_level1;
} }
} else if (OK == cursor_pos)
break;
}
break;
case JGE_BTN_RIGHT:
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) clickOK();
old->zoom = kZoom_none;
if (active)
active->zoom = kZoom_level1;
} }
}
break; break;
case ATK: case JGE_BTN_CANCEL:
{ if (BLK == cursor_pos)
DamagerDamaged* old = active;
active = closest<Right> (attackers, NULL, static_cast<AttackerDamaged*> (active));
if (active == oldActive)
{ {
active = activeAtk = NULL; oldActive->zoom = kZoom_level2;
cursor_pos = OK; active = activeAtk;
cursor_pos = ATK;
} }
else return true;
{ case JGE_BTN_LEFT:
if (old != active) shiftLeft();
{
if (old)
old->zoom = kZoom_none;
if (active)
active->zoom = kZoom_level1;
}
activeAtk = static_cast<AttackerDamaged*> (active);
}
}
break; break;
}
break; case JGE_BTN_RIGHT:
case JGE_BTN_DOWN: shiftRight( oldActive );
if (ORDER == step || BLK != cursor_pos || active->sumDamages() <= 0)
break; break;
removeOne(active, step);
break; case JGE_BTN_DOWN:
case JGE_BTN_UP: if (ORDER == step || BLK != cursor_pos || active->sumDamages() <= 0)
if (ORDER == step || BLK != cursor_pos) break;
removeOne(active, step);
break; break;
addOne(active, step); case JGE_BTN_UP:
break; if (ORDER == step || BLK != cursor_pos)
case JGE_BTN_PRI: break;
active = activeAtk = NULL; addOne(active, step);
cursor_pos = OK; break;
break; case JGE_BTN_PRI:
case JGE_BTN_NEXT: active = activeAtk = NULL;
if (!options[Options::REVERSETRIGGERS].number) cursor_pos = OK;
return false; break;
active = activeAtk = NULL; case JGE_BTN_NEXT:
cursor_pos = OK; if (!options[Options::REVERSETRIGGERS].number)
break; return false;
case JGE_BTN_PREV: active = activeAtk = NULL;
if (options[Options::REVERSETRIGGERS].number) cursor_pos = OK;
return false; break;
active = activeAtk = NULL; case JGE_BTN_PREV:
cursor_pos = OK; if (options[Options::REVERSETRIGGERS].number)
break; return false;
default: active = activeAtk = NULL;
; cursor_pos = OK;
break;
default:
;
} }
if (oldActive != active) if (oldActive != active)
{ {
@@ -537,7 +481,6 @@ void GuiCombat::Render()
JQuadPtr ok_quad = WResourceManager::Instance()->RetrieveTempQuad("Ok.png"); JQuadPtr ok_quad = WResourceManager::Instance()->RetrieveTempQuad("Ok.png");
ok_quad->SetHotSpot(28, 22); ok_quad->SetHotSpot(28, 22);
ok.Render(ok_quad.get()); ok.Render(ok_quad.get());
JGE::GetInstance()->SendCommand("okbuttoncreated:", ok.x, ok.y, ok_quad->mWidth, ok_quad->mHeight);
} }
renderer->DrawLine(0, SCREEN_HEIGHT / 2 + 10, SCREEN_WIDTH, SCREEN_HEIGHT / 2 + 10, ARGB(255, 255, 64, 0)); renderer->DrawLine(0, SCREEN_HEIGHT / 2 + 10, SCREEN_WIDTH, SCREEN_HEIGHT / 2 + 10, ARGB(255, 255, 64, 0));
if (FIRST_STRIKE == step) if (FIRST_STRIKE == step)
+2
View File
@@ -35,5 +35,7 @@ void Pos::Render(JQuad* quad)
JRenderer::GetInstance()->RenderQuad(quad, actX, actY, actT, actZ, actZ); JRenderer::GetInstance()->RenderQuad(quad, actX, actY, actT, actZ, actZ);
if (mask && !actT) if (mask && !actT)
JRenderer::GetInstance()->FillRect(actX,actY,actZ * quad->mWidth, actZ* quad->mHeight, mask); JRenderer::GetInstance()->FillRect(actX,actY,actZ * quad->mWidth, actZ* quad->mHeight, mask);
width = quad->mWidth;
height = quad->mHeight;
} }