ios major refactoring for ios settings, now they are presented differently on iphone/ipad, code is simplified and optimized, and ui is a little refreshed (eg. no more stuck selected fields)
--- a/project_files/HedgewarsMobile/Classes/GeneralSettingsViewController.m Fri Sep 30 17:04:20 2011 +0200
+++ b/project_files/HedgewarsMobile/Classes/GeneralSettingsViewController.m Sat Oct 01 02:40:26 2011 +0200
@@ -33,6 +33,7 @@
#pragma mark -
#pragma mark View Lifecycle
-(void) viewDidLoad {
+ self.navigationItem.title = @"Edit game options";
[super viewDidLoad];
}
--- a/project_files/HedgewarsMobile/Classes/HogHatViewController.m Fri Sep 30 17:04:20 2011 +0200
+++ b/project_files/HedgewarsMobile/Classes/HogHatViewController.m Sat Oct 01 02:40:26 2011 +0200
@@ -48,7 +48,7 @@
self.normalHogSprite = hogSprite;
[hogSprite release];
- self.title = NSLocalizedString(@"Change hedgehog's hat",@"");
+ self.title = NSLocalizedString(@"Change hedgehogs' hat",@"");
}
-(void) viewWillAppear:(BOOL)animated {
--- a/project_files/HedgewarsMobile/Classes/MasterViewController.h Fri Sep 30 17:04:20 2011 +0200
+++ b/project_files/HedgewarsMobile/Classes/MasterViewController.h Sat Oct 01 02:40:26 2011 +0200
@@ -22,16 +22,14 @@
#import <UIKit/UIKit.h>
-@class SplitViewRootController;
@class GeneralSettingsViewController;
@class TeamSettingsViewController;
@class WeaponSettingsViewController;
@class SchemeSettingsViewController;
@class SupportViewController;
-@interface MasterViewController : UITableViewController {
- SplitViewRootController *rootController;
- MasterViewController *targetController;
+@interface MasterViewController : UIViewController <UITableViewDelegate, UITableViewDataSource, UITabBarControllerDelegate> {
+ UIViewController *targetController;
NSArray *controllerNames;
NSIndexPath *lastIndexPath;
GeneralSettingsViewController *generalSettingsViewController;
@@ -41,11 +39,10 @@
SupportViewController *supportViewController;
}
-@property (nonatomic, retain) MasterViewController *targetController;
-@property (nonatomic, retain) SplitViewRootController *rootController;
+@property (nonatomic, retain) UIViewController *targetController;
@property (nonatomic, retain) NSArray *controllerNames;
@property (nonatomic, retain) NSIndexPath *lastIndexPath;
--(IBAction) dismissSplitView;
+-(void) dismissSplitView;
@end
--- a/project_files/HedgewarsMobile/Classes/MasterViewController.m Fri Sep 30 17:04:20 2011 +0200
+++ b/project_files/HedgewarsMobile/Classes/MasterViewController.m Sat Oct 01 02:40:26 2011 +0200
@@ -28,7 +28,7 @@
#import "SupportViewController.h"
@implementation MasterViewController
-@synthesize rootController, targetController, controllerNames, lastIndexPath;
+@synthesize targetController, controllerNames, lastIndexPath;
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
@@ -39,9 +39,7 @@
#pragma mark -
#pragma mark View lifecycle
-(void) viewDidLoad {
- [super viewDidLoad];
-
- // the list of selectable controllers
+ // the list of available controllers
NSArray *array = [[NSArray alloc] initWithObjects:NSLocalizedString(@"General",@""),
NSLocalizedString(@"Teams",@""),
NSLocalizedString(@"Weapons",@""),
@@ -51,18 +49,95 @@
self.controllerNames = array;
[array release];
- // targetControllers tells whether we're on the right or left side of the splitview -- on iphone we only use the right side
- if (targetController == nil && IS_IPAD()) {
- if (nil == generalSettingsViewController)
+ UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone
+ target:self
+ action:@selector(dismissSplitView)];
+ if (IS_IPAD()) {
+ // this class gets loaded twice, we tell the difference by looking at targetController
+ if (self.targetController != nil) {
+ UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
+ tableView.delegate = self;
+ tableView.dataSource = self;
+ [tableView reloadData];
+ [self.view addSubview:tableView];
+ [self tableView:tableView didSelectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
+ [tableView release];
+ self.navigationItem.leftBarButtonItem = doneButton;
+ }
+ } else {
+ // this class just loads all controllers and set up tabbar and navigation controllers
+ NSMutableArray *tabBarNavigationControllers = [[NSMutableArray alloc] initWithCapacity:5];
+ UINavigationController *navController = nil;
+
+ if (nil == generalSettingsViewController) {
generalSettingsViewController = [[GeneralSettingsViewController alloc] initWithStyle:UITableViewStyleGrouped];
- generalSettingsViewController.navigationItem.hidesBackButton = YES;
- [generalSettingsViewController viewWillAppear:YES];
- [self.navigationController pushViewController:generalSettingsViewController animated:NO];
- } else {
- self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone
- target:self
- action:@selector(dismissSplitView)];
+ generalSettingsViewController.tabBarItem.title = [self.controllerNames objectAtIndex:0];
+ generalSettingsViewController.tabBarItem.image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/TargetBee.png",GRAPHICS_DIRECTORY()]];
+ navController = [[UINavigationController alloc] initWithRootViewController:generalSettingsViewController];
+ generalSettingsViewController.navigationItem.backBarButtonItem = doneButton;
+ generalSettingsViewController.navigationItem.leftBarButtonItem = doneButton;
+ [generalSettingsViewController release];
+ [tabBarNavigationControllers addObject:navController];
+ releaseAndNil(navController);
+ }
+ if (nil == teamSettingsViewController) {
+ teamSettingsViewController = [[TeamSettingsViewController alloc] initWithStyle:UITableViewStyleGrouped];
+ teamSettingsViewController.tabBarItem.title = [self.controllerNames objectAtIndex:1];
+ teamSettingsViewController.tabBarItem.image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/Egg.png",GRAPHICS_DIRECTORY()]];
+ navController = [[UINavigationController alloc] initWithRootViewController:teamSettingsViewController];
+ teamSettingsViewController.navigationItem.backBarButtonItem = doneButton;
+ teamSettingsViewController.navigationItem.leftBarButtonItem = doneButton;
+ [tabBarNavigationControllers addObject:navController];
+ releaseAndNil(navController);
+ }
+ if (nil == weaponSettingsViewController) {
+ weaponSettingsViewController = [[WeaponSettingsViewController alloc] initWithStyle:UITableViewStyleGrouped];
+ weaponSettingsViewController.tabBarItem.title = [self.controllerNames objectAtIndex:2];
+ weaponSettingsViewController.tabBarItem.image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/cheese.png",GRAPHICS_DIRECTORY()]];
+ navController = [[UINavigationController alloc] initWithRootViewController:weaponSettingsViewController];
+ weaponSettingsViewController.navigationItem.backBarButtonItem = doneButton;
+ weaponSettingsViewController.navigationItem.leftBarButtonItem = doneButton;
+ [tabBarNavigationControllers addObject:navController];
+ releaseAndNil(navController);
+ }
+ if (nil == schemeSettingsViewController) {
+ schemeSettingsViewController = [[SchemeSettingsViewController alloc] initWithStyle:UITableViewStyleGrouped];
+ schemeSettingsViewController.tabBarItem.title = [self.controllerNames objectAtIndex:3];
+ schemeSettingsViewController.tabBarItem.image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/Targetp.png",GRAPHICS_DIRECTORY()]];
+ navController = [[UINavigationController alloc] initWithRootViewController:schemeSettingsViewController];
+ schemeSettingsViewController.navigationItem.backBarButtonItem = doneButton;
+ schemeSettingsViewController.navigationItem.leftBarButtonItem = doneButton;
+ [tabBarNavigationControllers addObject:navController];
+ releaseAndNil(navController);
+ }
+ if (nil == supportViewController) {
+ supportViewController = [[SupportViewController alloc] initWithStyle:UITableViewStyleGrouped];
+ supportViewController.tabBarItem.title = [self.controllerNames objectAtIndex:4];
+ supportViewController.tabBarItem.image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/Seduction.png",GRAPHICS_DIRECTORY()]];
+ navController = [[UINavigationController alloc] initWithRootViewController:supportViewController];
+ supportViewController.navigationItem.backBarButtonItem = doneButton;
+ supportViewController.navigationItem.leftBarButtonItem = doneButton;
+ [tabBarNavigationControllers addObject:navController];
+ releaseAndNil(navController);
+ }
+
+ UITabBarController *tabController = [[UITabBarController alloc] init];
+ tabController.viewControllers = tabBarNavigationControllers;
+ tabController.delegate = self;
+
+ [self.view addSubview:tabController.view];
}
+ [doneButton release];
+ [super viewDidLoad];
+}
+
+-(void) tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
+ [viewController viewWillAppear:NO];
+}
+
+-(void) dismissSplitView {
+ [AudioManagerController playBackSound];
+ [[[HedgewarsAppDelegate sharedAppDelegate] mainViewController] dismissModalViewControllerAnimated:YES];
}
#pragma mark -
@@ -72,7 +147,7 @@
}
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return [controllerNames count];
+ return [self.controllerNames count];
}
// Customize the appearance of table view cells.
@@ -106,11 +181,7 @@
break;
}
- if (nil == targetController)
- cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
- else
- cell.accessoryType = UITableViewCellAccessoryNone;
-
+ cell.accessoryType = UITableViewCellAccessoryNone;
cell.textLabel.text = [controllerNames objectAtIndex:[indexPath row]];
UIImage *icon = [[UIImage alloc] initWithContentsOfFile:iconStr];
cell.imageView.image = icon;
@@ -127,7 +198,7 @@
UIViewController *nextController = nil;
if (newRow != oldRow) {
- [self.tableView deselectRowAtIndexPath:lastIndexPath animated:YES];
+ [tableView deselectRowAtIndexPath:lastIndexPath animated:YES];
[targetController.navigationController popToRootViewControllerAnimated:NO];
switch (newRow) {
@@ -158,18 +229,13 @@
break;
}
- nextController.title = [controllerNames objectAtIndex:newRow];
self.lastIndexPath = indexPath;
- [self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
+ [tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
- if (nil == targetController) {
- nextController.navigationItem.hidesBackButton = NO;
- [self.navigationController pushViewController:nextController animated:YES];
- } else {
- [AudioManagerController playClickSound];
- nextController.navigationItem.hidesBackButton = YES;
- [targetController.navigationController pushViewController:nextController animated:NO];
- }
+ nextController.navigationItem.hidesBackButton = YES;
+ [nextController viewWillAppear:NO];
+ [targetController.navigationController pushViewController:nextController animated:NO];
+ [AudioManagerController playClickSound];
}
}
@@ -192,8 +258,6 @@
}
-(void) viewDidUnload {
- //self.rootController = nil;
- //self.targetController = nil;
self.controllerNames = nil;
self.lastIndexPath = nil;
generalSettingsViewController = nil;
@@ -206,7 +270,6 @@
}
-(void) dealloc {
- releaseAndNil(rootController);
releaseAndNil(targetController);
releaseAndNil(controllerNames);
releaseAndNil(lastIndexPath);
@@ -218,9 +281,5 @@
[super dealloc];
}
--(IBAction) dismissSplitView {
- [self.rootController dismissModalViewControllerAnimated:YES];
-}
-
@end
--- a/project_files/HedgewarsMobile/Classes/SchemeSettingsViewController.m Fri Sep 30 17:04:20 2011 +0200
+++ b/project_files/HedgewarsMobile/Classes/SchemeSettingsViewController.m Sat Oct 01 02:40:26 2011 +0200
@@ -41,6 +41,8 @@
action:@selector(toggleEdit:)];
self.navigationItem.rightBarButtonItem = editButton;
[editButton release];
+
+ self.navigationItem.title = @"List of schemes";
}
-(void) viewWillAppear:(BOOL) animated {
@@ -126,7 +128,7 @@
[schemeFile release];
[self.listOfSchemes removeObjectAtIndex:row];
- [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
+ [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
#pragma mark -
@@ -144,6 +146,7 @@
[childController.tableView setContentOffset:CGPointMake(0,0) animated:NO];
[self.navigationController pushViewController:childController animated:YES];
+ [tableView deselectRowAtIndexPath:indexPath animated:YES];
}
--- a/project_files/HedgewarsMobile/Classes/SplitViewRootController.h Fri Sep 30 17:04:20 2011 +0200
+++ b/project_files/HedgewarsMobile/Classes/SplitViewRootController.h Sat Oct 01 02:40:26 2011 +0200
@@ -21,16 +21,12 @@
#import <UIKit/UIKit.h>
-@class MasterViewController;
-
@interface SplitViewRootController: UIViewController {
- MasterViewController *activeController;
- UINavigationController *rightNavController;
+ UINavigationController *activeController;
UISplitViewController *splitViewRootController;
}
-@property (nonatomic,retain) MasterViewController *activeController;
-@property (nonatomic,retain) UINavigationController *rightNavController;
+@property (nonatomic,retain) UINavigationController *activeController;
@property (nonatomic,retain) UISplitViewController *splitViewRootController;
@end
--- a/project_files/HedgewarsMobile/Classes/SplitViewRootController.m Fri Sep 30 17:04:20 2011 +0200
+++ b/project_files/HedgewarsMobile/Classes/SplitViewRootController.m Sat Oct 01 02:40:26 2011 +0200
@@ -24,66 +24,64 @@
#import "CommodityFunctions.h"
@implementation SplitViewRootController
-@synthesize activeController, rightNavController, splitViewRootController;
+@synthesize activeController, splitViewRootController;
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return rotationManager(interfaceOrientation);
}
+
+-(void) viewDidLoad {
+ CGRect rect = [[UIScreen mainScreen] bounds];
+ self.view.frame = CGRectMake(0, 0, rect.size.height, rect.size.width);
+
+ if (IS_IPAD()) {
+ // the contents on the right of the splitview, setting targetController to nil to avoid creating the table
+ MasterViewController *rightController = [[MasterViewController alloc] init];
+ rightController.targetController = nil;
+ UINavigationController *rightNavController = [[UINavigationController alloc] initWithRootViewController:rightController];
+ [rightController release];
+
+ // the contens on the left of the splitview, setting targetController that will receive push/pop actions
+ MasterViewController *leftController = [[MasterViewController alloc] init];
+ leftController.targetController = rightNavController.topViewController;
+ UINavigationController *leftNavController = [[UINavigationController alloc] initWithRootViewController:leftController];
+ [leftController release];
+
+ self.activeController = rightNavController;
+ self.splitViewRootController = [[UISplitViewController alloc] init];
+ self.splitViewRootController.delegate = nil;
+ self.splitViewRootController.view.frame = CGRectMake(0, 0, rect.size.height, rect.size.width);
+ self.splitViewRootController.viewControllers = [NSArray arrayWithObjects: leftNavController, rightNavController, nil];
+ [leftNavController release];
+ [rightNavController release];
+
+ // add view to main controller
+ [self.view addSubview:self.splitViewRootController.view];
+ } else {
+ MasterViewController *mainController = [[MasterViewController alloc] init];
+ mainController.targetController = nil;
+ mainController.view.frame = CGRectMake(0, 0, rect.size.height, rect.size.width);
+ [self.view addSubview:mainController.view];
+ // here setting activeController is not needed as the event is kept active by the uitabbarcontroller
+ }
+
+ [super viewDidLoad];
+}
+
+#pragma mark -
+#pragma mark Memory management
-(void) didReceiveMemoryWarning {
+ if (self.splitViewRootController.view.superview == nil)
+ self.splitViewRootController = nil;
if (self.activeController.view.superview == nil)
self.activeController = nil;
MSG_MEMCLEAN();
[super didReceiveMemoryWarning];
}
-// load the view programmatically; we need a splitViewController that handles a MasterViewController
-// (which is just a UITableViewController) and a DetailViewController where we present options
--(void) viewDidLoad {
- CGRect rect = [[UIScreen mainScreen] bounds];
- self.view.frame = CGRectMake(0, 0, rect.size.height, rect.size.width);
-
- if (self.activeController == nil) {
- MasterViewController *rightController = [[MasterViewController alloc] initWithStyle:UITableViewStyleGrouped];
- rightController.rootController = self;
- rightController.targetController = nil;
- self.activeController = rightController;
- [rightController release];
- }
- self.rightNavController = [[UINavigationController alloc] initWithRootViewController:self.activeController];
-
- if (IS_IPAD()) {
- MasterViewController *leftController = [[MasterViewController alloc] initWithStyle:UITableViewStylePlain];
- leftController.rootController = self;
- leftController.targetController = self.activeController;
- UINavigationController *leftNavController = [[UINavigationController alloc] initWithRootViewController:leftController];
- [leftController release];
-
- self.splitViewRootController = [[UISplitViewController alloc] init];
- self.splitViewRootController.delegate = nil;
- self.splitViewRootController.view.frame = CGRectMake(0, 0, rect.size.height, rect.size.width);
- self.splitViewRootController.viewControllers = [NSArray arrayWithObjects: leftNavController, self.rightNavController, nil];
- [leftNavController release];
- [self.rightNavController release];
-
- // add view to main controller
- [self.view addSubview:self.splitViewRootController.view];
- } else {
- self.rightNavController.view.frame = CGRectMake(0, 0, rect.size.height, rect.size.width);
- [self.view addSubview:self.rightNavController.view];
- }
-
- [super viewDidLoad];
-}
-
--(void) dismissModalViewControllerAnimated:(BOOL)animated {
- [AudioManagerController playBackSound];
- [self.parentViewController dismissModalViewControllerAnimated:YES];
-}
-
-(void) viewDidUnload {
self.activeController = nil;
- self.rightNavController = nil;
self.splitViewRootController = nil;
MSG_DIDUNLOAD();
[super viewDidUnload];
@@ -91,32 +89,32 @@
-(void) dealloc {
releaseAndNil(activeController);
- releaseAndNil(rightNavController);
releaseAndNil(splitViewRootController);
[super dealloc];
}
+
#pragma mark -
#pragma mark additional methods as we're using a UINavigationController programmatically
// see http://davidebenini.it/2009/01/03/viewwillappear-not-being-called-inside-a-uinavigationcontroller/
-(void) viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
- [self.activeController.navigationController viewWillAppear:animated];
+ [self.activeController viewWillAppear:animated];
}
-(void) viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
- [self.activeController.navigationController viewWillDisappear:animated];
+ [self.activeController viewWillDisappear:animated];
}
-(void) viewDidAppear:(BOOL)animated {
[super viewDidLoad];
- [self.activeController.navigationController viewDidAppear:animated];
+ [self.activeController viewDidAppear:animated];
}
-(void) viewDidDisappear:(BOOL)animated {
[super viewDidUnload];
- [self.activeController.navigationController viewDidDisappear:animated];
+ [self.activeController viewDidDisappear:animated];
}
--- a/project_files/HedgewarsMobile/Classes/SupportViewController.m Fri Sep 30 17:04:20 2011 +0200
+++ b/project_files/HedgewarsMobile/Classes/SupportViewController.m Sat Oct 01 02:40:26 2011 +0200
@@ -44,6 +44,7 @@
self.waysToSupport = array;
[array release];
+ self.navigationItem.title = @"♥";
self.tableView.rowHeight = 50;
}
--- a/project_files/HedgewarsMobile/Classes/TeamSettingsViewController.m Fri Sep 30 17:04:20 2011 +0200
+++ b/project_files/HedgewarsMobile/Classes/TeamSettingsViewController.m Sat Oct 01 02:40:26 2011 +0200
@@ -43,6 +43,8 @@
action:@selector(toggleEdit:)];
self.navigationItem.rightBarButtonItem = editButton;
[editButton release];
+
+ self.navigationItem.title = @"List of teams";
}
// load the list of teams in the teams directory
@@ -131,7 +133,7 @@
[teamFile release];
[self.listOfTeams removeObjectAtIndex:row];
- [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
+ [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
@@ -150,6 +152,7 @@
[childController.tableView setContentOffset:CGPointMake(0,0) animated:NO];
[self.navigationController pushViewController:childController animated:YES];
+ [tableView deselectRowAtIndexPath:indexPath animated:YES];
}
--- a/project_files/HedgewarsMobile/Classes/WeaponCellView.m Fri Sep 30 17:04:20 2011 +0200
+++ b/project_files/HedgewarsMobile/Classes/WeaponCellView.m Sat Oct 01 02:40:26 2011 +0200
@@ -102,9 +102,9 @@
helpLabel = [[UILabel alloc] init];
helpLabel.backgroundColor = [UIColor clearColor];
- helpLabel.textColor = [UIColor grayColor];
+ helpLabel.textColor = [UIColor darkGrayColor];
helpLabel.textAlignment = UITextAlignmentRight;
- helpLabel.font = [UIFont italicSystemFontOfSize:[UIFont smallSystemFontSize]];
+ helpLabel.font = [UIFont italicSystemFontOfSize:[UIFont systemFontSize]];
[self.contentView addSubview:weaponName];
[self.contentView addSubview:weaponIcon];
--- a/project_files/HedgewarsMobile/Classes/WeaponSettingsViewController.m Fri Sep 30 17:04:20 2011 +0200
+++ b/project_files/HedgewarsMobile/Classes/WeaponSettingsViewController.m Sat Oct 01 02:40:26 2011 +0200
@@ -42,6 +42,7 @@
self.navigationItem.rightBarButtonItem = editButton;
[editButton release];
+ self.navigationItem.title = @"List of weapons";
}
-(void) viewWillAppear:(BOOL) animated {
@@ -127,7 +128,7 @@
[schemeFile release];
[self.listOfWeapons removeObjectAtIndex:row];
- [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
+ [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
#pragma mark -
@@ -145,6 +146,7 @@
[childController.tableView setContentOffset:CGPointMake(0,0) animated:NO];
[self.navigationController pushViewController:childController animated:YES];
+ [tableView deselectRowAtIndexPath:indexPath animated:YES];
}
Binary file share/hedgewars/Data/Graphics/Target@2x.png has changed
Binary file share/hedgewars/Data/Graphics/Targetp@2x.png has changed