From dfa007cecbb612e682e5b576583e5431b84eea47 Mon Sep 17 00:00:00 2001 From: "techdragon.nguyen@gmail.com" Date: Sat, 31 Dec 2011 08:21:00 +0000 Subject: [PATCH] implemented platform independant clickable OK button on gui combat window when selecting blocker order. removed iOS specific coding. --- JGE/src/iOS/EAGLViewController.h | 3 - JGE/src/iOS/EAGLViewController.m | 27 --- JGE/src/iOS/wagicAppDelegate.m | 3 - projects/mtg/include/GuiCombat.h | 3 +- projects/mtg/include/Pos.h | 1 + projects/mtg/src/GuiCombat.cpp | 301 +++++++++++++------------------ projects/mtg/src/Pos.cpp | 2 + 7 files changed, 127 insertions(+), 213 deletions(-) diff --git a/JGE/src/iOS/EAGLViewController.h b/JGE/src/iOS/EAGLViewController.h index 2eb237a7d..ae53d0a76 100755 --- a/JGE/src/iOS/EAGLViewController.h +++ b/JGE/src/iOS/EAGLViewController.h @@ -6,11 +6,8 @@ BOOL bannerIsVisible; } -- (void)addOkButtonListener: (CGRect) frame; - @property (nonatomic, retain) id eaglView; @property (nonatomic, retain) UITextField *inputField; -@property (nonatomic, retain) UIButton *okButtonView; @property (nonatomic, assign) BOOL bannerIsVisible; @end diff --git a/JGE/src/iOS/EAGLViewController.m b/JGE/src/iOS/EAGLViewController.m index f044b50f9..ae51c6e20 100755 --- a/JGE/src/iOS/EAGLViewController.m +++ b/JGE/src/iOS/EAGLViewController.m @@ -10,7 +10,6 @@ @synthesize bannerIsVisible; @synthesize eaglView; -@synthesize okButtonView; @synthesize inputField; #pragma mark initialization / deallocation methods @@ -39,7 +38,6 @@ [eaglView setDelegate: nil]; [eaglView release], eaglView = nil; [inputField release], inputField = nil; - [okButtonView release], okButtonView = nil; [super dealloc]; } @@ -88,31 +86,6 @@ // 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 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { diff --git a/JGE/src/iOS/wagicAppDelegate.m b/JGE/src/iOS/wagicAppDelegate.m index 82296d0e8..753756f56 100755 --- a/JGE/src/iOS/wagicAppDelegate.m +++ b/JGE/src/iOS/wagicAppDelegate.m @@ -150,9 +150,6 @@ width: (CGFloat) width height: (CGFloat) height { - CGRect uiFrame = CGRectMake(x, y, width, height); - if ( [command isEqualToString: @"okbuttoncreated"] ) - [glViewController addOkButtonListener: uiFrame]; } - (void)handleWEngineCommand:(NSString *) command withParameter: (NSString *) parameter diff --git a/projects/mtg/include/GuiCombat.h b/projects/mtg/include/GuiCombat.h index 5bf1115a2..38ee2a8b9 100644 --- a/projects/mtg/include/GuiCombat.h +++ b/projects/mtg/include/GuiCombat.h @@ -28,8 +28,9 @@ protected: void addOne(DefenserDamaged* blocker, CombatStep); void removeOne(DefenserDamaged* blocker, CombatStep); void remaskBlkViews(AttackerDamaged* before, AttackerDamaged* after); - void shiftLeft( DamagerDamaged* oldActive ); + void shiftLeft(); void shiftRight( DamagerDamaged* oldActive ); + bool didClickOnButton( Pos buttonPosition, int& x, int& y); int resolve(); public: diff --git a/projects/mtg/include/Pos.h b/projects/mtg/include/Pos.h index 76bdaf1ff..52fb4718c 100644 --- a/projects/mtg/include/Pos.h +++ b/projects/mtg/include/Pos.h @@ -7,6 +7,7 @@ struct Pos { float actX, actY, actZ, actT, actA; float x, y, zoom, t, alpha; + float width, height; PIXEL_TYPE mask; Pos(float, float, float, float, float); virtual void Update(float dt); diff --git a/projects/mtg/src/GuiCombat.cpp b/projects/mtg/src/GuiCombat.cpp index a52401896..5b879c5f6 100644 --- a/projects/mtg/src/GuiCombat.cpp +++ b/projects/mtg/src/GuiCombat.cpp @@ -198,7 +198,7 @@ bool GuiCombat::clickOK() } -void GuiCombat::shiftLeft( DamagerDamaged* oldActive) +void GuiCombat::shiftLeft() { switch (cursor_pos) { @@ -242,8 +242,9 @@ void GuiCombat::shiftLeft( DamagerDamaged* oldActive) } break; } - } + + void GuiCombat::shiftRight( DamagerDamaged* oldActive ) { switch (cursor_pos) @@ -289,199 +290,142 @@ 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(buttonPosition.x + buttonPosition.width); + int y2 = static_cast(buttonPosition.y + buttonPosition.height); + if ( (x >= x1 && x < x2) && (y >= y1 && y < y2)) + return true; + return false; +} + 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)) + if(observer->getInput()->GetLeftClickCoordinates(x, y)) { - 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) + // determine if OK button was clicked on + if (ok.width) { - 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: - if (BLK == cursor_pos) - { - if (ORDER == step) - observer->cardClick(active->card); // { activeAtk->card->raiseBlockerRankOrder(active->card); } - else + if (didClickOnButton(ok, x, y)) { - signed damage = activeAtk->card->stepPower(step); - for (vector::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); - } - } - 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::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; - } - break; - case JGE_BTN_RIGHT: - 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 + } + // position selected card + if (BLK == cursor_pos) + { + 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 != active) - { - if (old) - old->zoom = kZoom_none; - if (active) - active->zoom = kZoom_level1; - } - activeAtk = static_cast (active); + 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) + { + case JGE_BTN_OK: + if (BLK == cursor_pos) + { + if (ORDER == step) + observer->cardClick(active->card); // { activeAtk->card->raiseBlockerRankOrder(active->card); } + else + { + signed damage = activeAtk->card->stepPower(step); + for (vector::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); + } + } + else if (ATK == cursor_pos) + { + active = activeAtk->blockers.front(); + active->zoom = kZoom_level3; + cursor_pos = BLK; + } + else if (OK == cursor_pos) + { + clickOK(); + } break; - } - break; - case JGE_BTN_DOWN: - if (ORDER == step || BLK != cursor_pos || active->sumDamages() <= 0) + case JGE_BTN_CANCEL: + if (BLK == cursor_pos) + { + oldActive->zoom = kZoom_level2; + active = activeAtk; + cursor_pos = ATK; + } + return true; + case JGE_BTN_LEFT: + shiftLeft(); break; - removeOne(active, step); - break; - case JGE_BTN_UP: - if (ORDER == step || BLK != cursor_pos) + + case JGE_BTN_RIGHT: + shiftRight( oldActive ); break; - addOne(active, step); - break; - case JGE_BTN_PRI: - active = activeAtk = NULL; - cursor_pos = OK; - break; - case JGE_BTN_NEXT: - if (!options[Options::REVERSETRIGGERS].number) - return false; - active = activeAtk = NULL; - cursor_pos = OK; - break; - case JGE_BTN_PREV: - if (options[Options::REVERSETRIGGERS].number) - return false; - active = activeAtk = NULL; - cursor_pos = OK; - break; - default: - ; + + case JGE_BTN_DOWN: + if (ORDER == step || BLK != cursor_pos || active->sumDamages() <= 0) + break; + removeOne(active, step); + break; + case JGE_BTN_UP: + if (ORDER == step || BLK != cursor_pos) + break; + addOne(active, step); + break; + case JGE_BTN_PRI: + active = activeAtk = NULL; + cursor_pos = OK; + break; + case JGE_BTN_NEXT: + if (!options[Options::REVERSETRIGGERS].number) + return false; + active = activeAtk = NULL; + cursor_pos = OK; + break; + case JGE_BTN_PREV: + if (options[Options::REVERSETRIGGERS].number) + return false; + active = activeAtk = NULL; + cursor_pos = OK; + break; + default: + ; } if (oldActive != active) { @@ -537,7 +481,6 @@ void GuiCombat::Render() JQuadPtr ok_quad = WResourceManager::Instance()->RetrieveTempQuad("Ok.png"); ok_quad->SetHotSpot(28, 22); 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)); if (FIRST_STRIKE == step) diff --git a/projects/mtg/src/Pos.cpp b/projects/mtg/src/Pos.cpp index 88c9ecae2..c7eb4e48d 100644 --- a/projects/mtg/src/Pos.cpp +++ b/projects/mtg/src/Pos.cpp @@ -35,5 +35,7 @@ void Pos::Render(JQuad* quad) JRenderer::GetInstance()->RenderQuad(quad, actX, actY, actT, actZ, actZ); if (mask && !actT) JRenderer::GetInstance()->FillRect(actX,actY,actZ * quad->mWidth, actZ* quad->mHeight, mask); + width = quad->mWidth; + height = quad->mHeight; }