From 138ddde0dfa19e49801cb35626130ccb9d34b878 Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Sun, 4 Sep 2011 11:48:28 -0400 Subject: Added Jump lists to highscore viewer Refs #204 --- Classes/HighscoreListController.h | 4 +++ Classes/HighscoreListController.m | 55 ++++++++++++++++++++++++++++++--------- 2 files changed, 47 insertions(+), 12 deletions(-) diff --git a/Classes/HighscoreListController.h b/Classes/HighscoreListController.h index 7b0069d..5921ec6 100755 --- a/Classes/HighscoreListController.h +++ b/Classes/HighscoreListController.h @@ -10,6 +10,7 @@ @interface HighscoreListController : UITableViewController { UINavigationBar* navigationBar; + UIToolbar* toolbar; UINavigationItem* myNavigationItem; NSArray* localHighscores; NSArray* globalHighscores; @@ -19,10 +20,13 @@ UIActivityIndicatorView* activity; UILabel* statusText; UITableView* tableView; + UISegmentedControl* areaControl; + UISegmentedControl* modeControl; } - (void)back; - (void)switchLists:(id)sender; +- (void)switchGameMode:(id)sender; - (void)scoreRequestOk:(id)sender; - (void)scoreRequestFail:(id)sender; diff --git a/Classes/HighscoreListController.m b/Classes/HighscoreListController.m index d7bffcb..68ea2f6 100755 --- a/Classes/HighscoreListController.m +++ b/Classes/HighscoreListController.m @@ -29,26 +29,36 @@ UIBarButtonItem* barButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(back)]; myNavigationItem.leftBarButtonItem = barButton; [barButton release]; + [navigationBar pushNavigationItem:myNavigationItem animated:NO]; - UISegmentedControl* segmentedControl = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"Local", @"Global", nil]]; - segmentedControl.selectedSegmentIndex = 0; - segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar; - [segmentedControl addTarget:self action:@selector(switchLists:) forControlEvents:UIControlEventValueChanged]; - UIBarButtonItem* barButton2 = [[UIBarButtonItem alloc] initWithCustomView:segmentedControl]; - [segmentedControl release]; - myNavigationItem.rightBarButtonItem = barButton2; - [barButton2 release]; + areaControl = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"Local", @"Global", nil]]; + areaControl.selectedSegmentIndex = 0; + areaControl.segmentedControlStyle = UISegmentedControlStyleBar; + [areaControl addTarget:self action:@selector(switchLists:) forControlEvents:UIControlEventValueChanged]; + UIBarButtonItem* barButton2 = [[UIBarButtonItem alloc] initWithCustomView:areaControl]; + + UIBarButtonItem* btnSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil]; - [navigationBar pushNavigationItem:myNavigationItem animated:NO]; + modeControl = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"Collect", @"Jump", nil]]; + modeControl.selectedSegmentIndex = 0; + modeControl.segmentedControlStyle = UISegmentedControlStyleBar; + [modeControl addTarget:self action:@selector(switchGameMode:) forControlEvents:UIControlEventValueChanged]; + UIBarButtonItem* barButton3 = [[UIBarButtonItem alloc] initWithCustomView:modeControl]; + + toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 480-44, 320, 44)]; + [toolbar setItems:[NSArray arrayWithObjects:barButton3, btnSpace, barButton2, nil] animated:NO]; + [barButton2 release]; + [barButton3 release]; showGlobal = NO; loadingGlobal = NO; tableView = [(UITableView*)self.view retain]; UIView* parentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)]; - [tableView setFrame:CGRectMake(0, 44, 320, 480-44)]; + [tableView setFrame:CGRectMake(0, 44, 320, 480-44-44)]; [parentView addSubview:navigationBar]; [parentView addSubview:tableView]; + [parentView addSubview:toolbar]; self.view = parentView; [parentView release]; } @@ -282,7 +292,7 @@ { loadingGlobal = YES; - loadingView = [[UIView alloc] initWithFrame:CGRectMake(0, 44, 320, 480-44)]; + loadingView = [[UIView alloc] initWithFrame:CGRectMake(0, 44, 320, 480-44-44)]; activity = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(150, 228-44, 20, 20)]; activity.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray; statusText = [[UILabel alloc] initWithFrame:CGRectMake(0, 256-44, 320, 21)]; @@ -298,7 +308,14 @@ CLScoreServerRequest* request = [[CLScoreServerRequest alloc] initWithGameName:@"Cart Collect" delegate:self]; tQueryFlags flags = kQueryFlagIgnore; - [request requestScores:kQueryAllTime limit:15 offset:0 flags:flags category:@"Classic"]; + + if (modeControl.selectedSegmentIndex == 0) + { + [request requestScores:kQueryAllTime limit:15 offset:0 flags:flags category:@"Classic"]; + } else { + [request requestScores:kQueryAllTime limit:15 offset:0 flags:flags category:@"Jump"]; + } + [request release]; } else { showGlobal = YES; @@ -307,6 +324,20 @@ } } +- (void)switchGameMode:(id)sender +{ + if ([(UISegmentedControl*)sender selectedSegmentIndex] == 0) + { + localHighscores = [Highscore localHighscoreListForGameMode:@"Collect"]; + } else { + localHighscores = [Highscore localHighscoreListForGameMode:@"Jump"]; + } + + globalHighscores = nil; + + [self switchLists:areaControl]; +} + - (void)scoreRequestOk:(id)sender { NSArray* highscores = [sender parseScores]; -- cgit 1.4.1