From 6d5342c02b0612072557d922bdea48bb3f82173c Mon Sep 17 00:00:00 2001 From: "techdragon.nguyen@gmail.com" Date: Fri, 6 Jan 2012 19:13:43 +0000 Subject: [PATCH] fixed a memory leaks in app delegate * adjusted the touch sensitivity of the iOS port for deck menu selection. Decks were being selected even though the selection was touched. It was highlighted but as soon as you let go it would instantly select (OK button) select the selected deck. This isn't a problem on Android as the SDL already handles this as far as I can tell. I limited this to only iOS so I don't accidentally mess up the other ports. --- JGE/src/iOS/wagicAppDelegate.m | 6 ++++++ projects/mtg/include/DeckMenuItem.h | 5 ++++- projects/mtg/src/DeckMenuItem.cpp | 27 ++++++++++++++++++++++++++- 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/JGE/src/iOS/wagicAppDelegate.m b/JGE/src/iOS/wagicAppDelegate.m index e4197c948..5bc24c0c7 100755 --- a/JGE/src/iOS/wagicAppDelegate.m +++ b/JGE/src/iOS/wagicAppDelegate.m @@ -115,6 +115,8 @@ NSString *resPath = [NSString stringWithFormat: @"%@/Res", docsPath]; NSError *error = nil; + [compoundPredicate release], compoundPredicate = nil; + if ( ([resourceZipFiles count] > 0 ) && ![fileManager fileExistsAtPath: userPath] ) [fileManager createDirectoryAtPath: userPath withIntermediateDirectories: YES attributes:nil error:nil ]; @@ -206,6 +208,8 @@ [fm moveItemAtPath: fromPath toPath: toPath error: nil]; } + [playerDataPredicate release], playerDataPredicate = nil; + [self createManifest: docsPath]; [[NSNotificationCenter defaultCenter] postNotificationName: @"readyToStartGame" object: nil]; @@ -243,6 +247,8 @@ - (void) setupNetworkListeners { + NSLog(@"App checking network connections"); + hostReach = [[Reachability reachabilityForGoogleDNS] retain]; internetReach = [[Reachability reachabilityForInternetConnection] retain]; wifiReach = [[Reachability reachabilityForLocalWiFi] retain]; diff --git a/projects/mtg/include/DeckMenuItem.h b/projects/mtg/include/DeckMenuItem.h index fb2810cc9..27ae40c74 100644 --- a/projects/mtg/include/DeckMenuItem.h +++ b/projects/mtg/include/DeckMenuItem.h @@ -14,13 +14,16 @@ private: bool mHasFocus; bool mScrollEnabled; bool mDisplayInitialized; - + bool mIsValidSelection; + DeckMenu* parent; int fontId; string mText; float mTitleResetWidth; static float mYOffset; + void checkUserClick(); + public: string imageFilename; string desc; diff --git a/projects/mtg/src/DeckMenuItem.cpp b/projects/mtg/src/DeckMenuItem.cpp index cc124b4bd..dca691788 100644 --- a/projects/mtg/src/DeckMenuItem.cpp +++ b/projects/mtg/src/DeckMenuItem.cpp @@ -6,6 +6,8 @@ #include #define ITEM_PX_WIDTH 190.0f +#define kItemXOffset 22 +#define kItemYHeight 20 const int kHorizontalScrollSpeed = 30; // higher numbers mean faster scrolling @@ -17,6 +19,8 @@ DeckMenuItem::DeckMenuItem(DeckMenu* _parent, int id, int fontId, string text, f WFont * mFont = WResourceManager::Instance()->GetWFont(fontId); meta = deckMetaData; mText = trim(text); + mIsValidSelection = false; + if (autoTranslate) mText = _(mText); @@ -113,25 +117,46 @@ void DeckMenuItem::Render() RenderWithOffset(0); } +void DeckMenuItem::checkUserClick() +{ +#ifdef IOS + int x1 = 0, y1 = 0; + if ( mEngine->GetLeftClickCoordinates(x1, y1)) + { + mIsValidSelection = false; + int x2 = kItemXOffset, y2 = static_cast(mY + mYOffset); + if ( (x1 >= x2) && (x1 <= (x2 + ITEM_PX_WIDTH)) && (y1 >= y2) && (y1 < (y2 + kItemYHeight))) + mIsValidSelection = true; + } + else + mIsValidSelection = true; +#endif +} + + void DeckMenuItem::Entering() { + checkUserClick(); mHasFocus = true; parent->mSelectionTargetY = mY; } bool DeckMenuItem::Leaving(JButton key) { + // check to see if the user clicked on the object, if so return true. + checkUserClick(); mHasFocus = false; return true; } bool DeckMenuItem::ButtonPressed() { - return true; + return mIsValidSelection; } void DeckMenuItem::Relocate(float x, float y) { + checkUserClick(); mX = x; mY = y; }