From 02d9a87417837ffda602b2d06c2c6897d15a1202 Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Tue, 23 Aug 2011 09:24:14 -0400 Subject: Added a UIPageControl to the level selection screen The page control updates when you swipe through the levels, but tapping it does nothing. I initially attempted to implement scrolling by tapping on the page control, but for some reason, it worked perfectly in the simulator and only randomly on the iPhone. Very weird. Refs #207 --- Cartographic.xcodeproj/project.pbxproj | 2 ++ Classes/CocosOverlayScrollView.h | 3 ++- Classes/CocosOverlayScrollView.m | 9 ++++++++- Classes/GameModeSelectionLayer.h | 1 + Classes/GameModeSelectionLayer.m | 9 ++++++++- 5 files changed, 21 insertions(+), 3 deletions(-) diff --git a/Cartographic.xcodeproj/project.pbxproj b/Cartographic.xcodeproj/project.pbxproj index 59cf7cd..4a478c9 100755 --- a/Cartographic.xcodeproj/project.pbxproj +++ b/Cartographic.xcodeproj/project.pbxproj @@ -1601,6 +1601,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = NO; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + GCC_C_LANGUAGE_STANDARD = c99; GCC_DYNAMIC_NO_PIC = NO; GCC_OPTIMIZATION_LEVEL = 0; GCC_PRECOMPILE_PREFIX_HEADER = YES; @@ -1629,6 +1630,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = YES; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + GCC_C_LANGUAGE_STANDARD = c99; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = Cart_Collect_Prefix.pch; GCC_TREAT_WARNINGS_AS_ERRORS = NO; diff --git a/Classes/CocosOverlayScrollView.h b/Classes/CocosOverlayScrollView.h index 29de1c7..ad8e83f 100755 --- a/Classes/CocosOverlayScrollView.h +++ b/Classes/CocosOverlayScrollView.h @@ -12,7 +12,8 @@ @interface CocosOverlayScrollView : UIScrollView { CCNode* targetLayer; + UIPageControl* pageControl; } @property(nonatomic, retain) CCNode* targetLayer; --(id) initWithFrame: (CGRect) frameRect numPages: (int) numPages width: (float) width layer: (CCNode*) layer; +-(id) initWithFrame: (CGRect) frameRect numPages: (int) numPages width: (float) width layer: (CCNode*) layer pageControl:(UIPageControl*)pageControl; @end diff --git a/Classes/CocosOverlayScrollView.m b/Classes/CocosOverlayScrollView.m index dcf5571..dee9dfe 100755 --- a/Classes/CocosOverlayScrollView.m +++ b/Classes/CocosOverlayScrollView.m @@ -12,7 +12,7 @@ @synthesize targetLayer; // Configure your favorite UIScrollView options here --(id) initWithFrame: (CGRect) frameRect numPages: (int) numPages width: (float) width layer: (CCNode*) layer { +-(id) initWithFrame: (CGRect) frameRect numPages: (int) numPages width: (float) width layer: (CCNode*) layer pageControl:(UIPageControl *)m_pageControl{ if ((self = [super initWithFrame: frameRect])){ self.contentSize = CGSizeMake(width*numPages, 320); self.bounces = YES; @@ -26,6 +26,7 @@ [self setScrollEnabled:TRUE]; self.targetLayer = layer; // self.canCancelContentTouches = YES; + pageControl = m_pageControl; } return self; } @@ -96,4 +97,10 @@ self.targetLayer = nil; [super dealloc]; } + +- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView +{ + [pageControl setCurrentPage:(NSUInteger)([scrollView contentOffset].x / [scrollView frame].size.width)]; +} + @end \ No newline at end of file diff --git a/Classes/GameModeSelectionLayer.h b/Classes/GameModeSelectionLayer.h index 451a5f8..478a173 100644 --- a/Classes/GameModeSelectionLayer.h +++ b/Classes/GameModeSelectionLayer.h @@ -15,6 +15,7 @@ NSMutableArray* gameModes; TouchDelegatingView* touchDelegatingView; CocosOverlayScrollView* scrollView; + UIPageControl* pageControl; } + (CCScene*)scene; diff --git a/Classes/GameModeSelectionLayer.m b/Classes/GameModeSelectionLayer.m index 9875d41..ad6a455 100644 --- a/Classes/GameModeSelectionLayer.m +++ b/Classes/GameModeSelectionLayer.m @@ -86,9 +86,15 @@ [panels addChild:menu]; [self addChild:panels]; + pageControl = [[UIPageControl alloc] init]; + pageControl.numberOfPages = numberOfPanels; + pageControl.currentPage = currentWorldOffset; + pageControl.frame = CGRectMake(0, 250, 480, 20); + [[[CCDirector sharedDirector] openGLView] addSubview:pageControl]; + menu.position = ccpAdd(menu.position, ccp(totalWidth/2 - totalPanelWidth/2, 320)); touchDelegatingView = [[TouchDelegatingView alloc] initWithFrame:CGRectMake(0, 0, 480, 320)]; - scrollView = [[CocosOverlayScrollView alloc] initWithFrame:CGRectMake(0, 0, totalPanelWidth, 320) numPages:numberOfPanels width:totalPanelWidth layer:panels]; + scrollView = [[CocosOverlayScrollView alloc] initWithFrame:CGRectMake(0, 0, totalPanelWidth, 320) numPages:numberOfPanels width:totalPanelWidth layer:panels pageControl:pageControl]; touchDelegatingView.scrollView = scrollView; [scrollView setContentOffset:CGPointMake(currentWorldOffset*totalPanelWidth+1,0) animated:NO]; [[[CCDirector sharedDirector] openGLView] addSubview:touchDelegatingView]; @@ -107,6 +113,7 @@ { [touchDelegatingView removeFromSuperview]; [scrollView removeFromSuperview]; + [pageControl removeFromSuperview]; } - (void)mainmenu -- cgit 1.4.1