--- a/project_files/HedgewarsMobile/Classes/CommodityFunctions.h Mon May 09 18:00:39 2011 +0200
+++ b/project_files/HedgewarsMobile/Classes/CommodityFunctions.h Wed May 11 01:26:38 2011 +0200
@@ -23,7 +23,6 @@
#define DOCUMENTS_FOLDER() [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]
-#define SETTINGS_FILE() [DOCUMENTS_FOLDER() stringByAppendingString:@"/settings.plist"]
#define DEBUG_FILE() [DOCUMENTS_FOLDER() stringByAppendingString:@"/hw-game.log"]
#define HEDGEHOG_FILE() [[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"/Settings/Images/hedgehog.png"]
#define BASICFLAGS_FILE() [[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"/Settings/basicFlags.plist"]
--- a/project_files/HedgewarsMobile/Classes/CommodityFunctions.m Mon May 09 18:00:39 2011 +0200
+++ b/project_files/HedgewarsMobile/Classes/CommodityFunctions.m Wed May 11 01:26:38 2011 +0200
@@ -92,7 +92,7 @@
void playSound (NSString *snd) {
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
- NSNumber *audio = [prefs objectForKey:@"audio"];
+ NSNumber *audio = [prefs objectForKey:@"sound"];
if (audio == nil || [audio boolValue] == YES) {
// get the filename of the sound file:
--- a/project_files/HedgewarsMobile/Classes/CreationChamber.h Mon May 09 18:00:39 2011 +0200
+++ b/project_files/HedgewarsMobile/Classes/CreationChamber.h Wed May 11 01:26:38 2011 +0200
@@ -21,6 +21,7 @@
#import <Foundation/Foundation.h>
+void createSettings (void);
void createTeamNamed (NSString *nameWithoutExt);
void createWeaponNamed (NSString *nameWithoutExt, int type);
void createSchemeNamed (NSString *nameWithoutExt);
--- a/project_files/HedgewarsMobile/Classes/CreationChamber.m Mon May 09 18:00:39 2011 +0200
+++ b/project_files/HedgewarsMobile/Classes/CreationChamber.m Wed May 11 01:26:38 2011 +0200
@@ -22,6 +22,19 @@
#import "CreationChamber.h"
#import "hwconsts.h"
+void createSettings () {
+ NSUserDefaults *settings = [NSUserDefaults standardUserDefaults];
+ [settings setObject:[NSNumber numberWithBool:NO] forKey:@"alternate"];
+ [settings setObject:[NSNumber numberWithBool:YES] forKey:@"music"];
+ [settings setObject:[NSNumber numberWithBool:YES] forKey:@"sound"];
+ [settings setObject:[NSNumber numberWithBool:NO] forKey:@"classic_menu"];
+ [settings setObject:[NSNumber numberWithBool:YES] forKey:@"enhanced"];
+ [settings setObject:[NSNumber numberWithBool:YES] forKey:@"multitasking"];
+ [settings setObject:@"" forKey:@"username"];
+ [settings setObject:@"" forKey:@"password"];
+
+ [settings synchronize];
+}
void createTeamNamed (NSString *nameWithoutExt) {
NSString *teamsDirectory = TEAMS_DIRECTORY();
--- a/project_files/HedgewarsMobile/Classes/GameInterfaceBridge.h Mon May 09 18:00:39 2011 +0200
+++ b/project_files/HedgewarsMobile/Classes/GameInterfaceBridge.h Wed May 11 01:26:38 2011 +0200
@@ -31,7 +31,6 @@
UIViewController *parentController;
OverlayViewController *overlayController;
- NSDictionary *systemSettings;
NSString *savePath;
EngineProtocolNetwork *engineProtocol;
@@ -40,7 +39,6 @@
}
@property (nonatomic,retain) UIViewController *parentController;
-@property (nonatomic,retain) NSDictionary *systemSettings;
@property (nonatomic,retain) NSString *savePath;
@property (nonatomic,retain) OverlayViewController *overlayController;
--- a/project_files/HedgewarsMobile/Classes/GameInterfaceBridge.m Mon May 09 18:00:39 2011 +0200
+++ b/project_files/HedgewarsMobile/Classes/GameInterfaceBridge.m Wed May 11 01:26:38 2011 +0200
@@ -27,7 +27,7 @@
#import "ObjcExports.h"
@implementation GameInterfaceBridge
-@synthesize parentController, systemSettings, savePath, overlayController, engineProtocol, ipcPort, gameType;
+@synthesize parentController, savePath, overlayController, engineProtocol, ipcPort, gameType;
-(id) initWithController:(id) viewController {
if (self = [super init]) {
@@ -39,7 +39,6 @@
self.engineProtocol = [[EngineProtocolNetwork alloc] initOnPort:self.ipcPort];
self.engineProtocol.delegate = self;
- self.systemSettings = [NSDictionary dictionaryWithContentsOfFile:SETTINGS_FILE()];
self.overlayController = [[OverlayViewController alloc] initWithNibName:@"OverlayViewController" bundle:nil];
}
return self;
@@ -48,7 +47,6 @@
-(void) dealloc {
releaseAndNil(parentController);
releaseAndNil(engineProtocol);
- releaseAndNil(systemSettings);
releaseAndNil(savePath);
releaseAndNil(overlayController);
[super dealloc];
@@ -57,7 +55,6 @@
#pragma mark -
// overlay with controls, become visible later, with a transparency effect since the sdlwindow is not yet created
-(void) displayOverlayLater:(id) object {
- [self.overlayController setUseClassicMenu:[[self.systemSettings objectForKey:@"menu"] boolValue]];
[self.overlayController setInitialOrientation:self.parentController.interfaceOrientation];
UIWindow *gameWindow = (IS_DUALHEAD() ? [HedgewarsAppDelegate sharedAppDelegate].uiwindow : [[UIApplication sharedApplication] keyWindow]);
@@ -70,6 +67,7 @@
NSInteger width, height, orientation;
NSString *ipcString = [[NSString alloc] initWithFormat:@"%d", self.ipcPort];
NSString *localeString = [[NSString alloc] initWithFormat:@"%@.txt", [[NSLocale currentLocale] objectForKey:NSLocaleLanguageCode]];
+ NSUserDefaults *settings = [NSUserDefaults standardUserDefaults];
if (IS_DUALHEAD()) {
CGRect screenBounds = [[[UIScreen screens] objectAtIndex:1] bounds];
@@ -86,7 +84,7 @@
NSString *horizontalSize = [[NSString alloc] initWithFormat:@"%d", width];
NSString *verticalSize = [[NSString alloc] initWithFormat:@"%d", height];
NSString *rotation = [[NSString alloc] initWithFormat:@"%d", orientation];
- BOOL enhanced = [[self.systemSettings objectForKey:@"enhanced"] boolValue];
+ BOOL enhanced = [[settings objectForKey:@"enhanced"] boolValue];
NSString *modelId = modelType();
NSInteger tmpQuality;
@@ -104,7 +102,7 @@
tmpQuality = tmpQuality | 0x00000400;
// prevents using an empty nickname
- NSString *username = [self.systemSettings objectForKey:@"username"];
+ NSString *username = [settings objectForKey:@"username"];
if ([username length] == 0)
username = [NSString stringWithFormat:@"MobileUser-%@",ipcString];
@@ -114,9 +112,9 @@
gameArgs[ 3] = [[NSString stringWithFormat:@"%d",tmpQuality] UTF8String]; //quality
gameArgs[ 4] = "en.txt";//[localeString UTF8String]; //cLocaleFName
gameArgs[ 5] = [username UTF8String]; //UserNick
- gameArgs[ 6] = [[[self.systemSettings objectForKey:@"sound"] stringValue] UTF8String]; //isSoundEnabled
- gameArgs[ 7] = [[[self.systemSettings objectForKey:@"music"] stringValue] UTF8String]; //isMusicEnabled
- gameArgs[ 8] = [[[self.systemSettings objectForKey:@"alternate"] stringValue] UTF8String]; //cAltDamage
+ gameArgs[ 6] = [[[settings objectForKey:@"sound"] stringValue] UTF8String]; //isSoundEnabled
+ gameArgs[ 7] = [[[settings objectForKey:@"music"] stringValue] UTF8String]; //isMusicEnabled
+ gameArgs[ 8] = [[[settings objectForKey:@"alternate"] stringValue] UTF8String]; //cAltDamage
gameArgs[ 9] = [rotation UTF8String]; //rotateQt
gameArgs[10] = (self.gameType == gtSave) ? [self.savePath UTF8String] : NULL; //recordFileName
--- a/project_files/HedgewarsMobile/Classes/GeneralSettingsViewController.h Mon May 09 18:00:39 2011 +0200
+++ b/project_files/HedgewarsMobile/Classes/GeneralSettingsViewController.h Wed May 11 01:26:38 2011 +0200
@@ -23,9 +23,9 @@
#import "EditableCellView.h"
@interface GeneralSettingsViewController : UITableViewController <EditableCellViewDelegate> {
- NSMutableDictionary *settingsDictionary;
+ NSUserDefaults *settings;
}
-@property (nonatomic, retain) NSMutableDictionary *settingsDictionary;
+@property (nonatomic, retain) NSUserDefaults *settings;
@end
--- a/project_files/HedgewarsMobile/Classes/GeneralSettingsViewController.m Mon May 09 18:00:39 2011 +0200
+++ b/project_files/HedgewarsMobile/Classes/GeneralSettingsViewController.m Wed May 11 01:26:38 2011 +0200
@@ -23,7 +23,7 @@
#import "CommodityFunctions.h"
@implementation GeneralSettingsViewController
-@synthesize settingsDictionary;
+@synthesize settings;
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
@@ -39,21 +39,14 @@
-(void) viewWillAppear:(BOOL)animated {
[self.tableView setContentOffset:CGPointMake(0,0) animated:NO];
- NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] initWithContentsOfFile:SETTINGS_FILE()];
- self.settingsDictionary = dictionary;
- [dictionary release];
+ self.settings = [NSUserDefaults standardUserDefaults];
[super viewWillAppear:animated];
}
-(void) viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
- [self.settingsDictionary writeToFile:SETTINGS_FILE() atomically:YES];
-
- // we save the sound settings to respect that flag everywhere
- NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
- [prefs setObject:[NSNumber numberWithBool:[[self.settingsDictionary objectForKey:@"sound"] boolValue]] forKey:@"audio"];
- [prefs synchronize];
+ [self.settings synchronize];
}
#pragma mark -
@@ -64,31 +57,31 @@
switch (theSwitch.tag) {
case 10: //soundSwitch
// this turn off also the switch below
- [self.settingsDictionary setObject:[NSNumber numberWithBool:theSwitch.on] forKey:@"sound"];
- [self.settingsDictionary setObject:[NSNumber numberWithBool:NO] forKey:@"music"];
+ [self.settings setObject:[NSNumber numberWithBool:theSwitch.on] forKey:@"sound"];
+ [self.settings setObject:[NSNumber numberWithBool:NO] forKey:@"music"];
theOtherSwitch = (UISwitch *)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:1]].accessoryView;
[theOtherSwitch setOn:NO animated:YES];
break;
case 20: //musicSwitch
// if switch above is off, never turn on
- if (NO == [[self.settingsDictionary objectForKey:@"sound"] boolValue]) {
- [self.settingsDictionary setObject:[NSNumber numberWithBool:NO] forKey:@"music"];
+ if (NO == [[self.settings objectForKey:@"sound"] boolValue]) {
+ [self.settings setObject:[NSNumber numberWithBool:NO] forKey:@"music"];
theOtherSwitch = (UISwitch *)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:1]].accessoryView;
[theOtherSwitch setOn:NO animated:YES];
} else
- [self.settingsDictionary setObject:[NSNumber numberWithBool:theSwitch.on] forKey:@"music"];
+ [self.settings setObject:[NSNumber numberWithBool:theSwitch.on] forKey:@"music"];
break;
case 30: //alternateSwitch
- [self.settingsDictionary setObject:[NSNumber numberWithBool:theSwitch.on] forKey:@"alternate"];
+ [self.settings setObject:[NSNumber numberWithBool:theSwitch.on] forKey:@"alternate"];
break;
case 70: //enhanced graphics
- [self.settingsDictionary setObject:[NSNumber numberWithBool:theSwitch.on] forKey:@"enhanced"];
+ [self.settings setObject:[NSNumber numberWithBool:theSwitch.on] forKey:@"enhanced"];
break;
case 80: //nomultitasking
- [self.settingsDictionary setObject:[NSNumber numberWithBool:theSwitch.on] forKey:@"multitasking"];
+ [self.settings setObject:[NSNumber numberWithBool:theSwitch.on] forKey:@"multitasking"];
break;
case 60: //classic menu
- [self.settingsDictionary setObject:[NSNumber numberWithBool:theSwitch.on] forKey:@"menu"];
+ [self.settings setObject:[NSNumber numberWithBool:theSwitch.on] forKey:@"classic_menu"];
break;
default:
DLog(@"Wrong tag");
@@ -98,11 +91,9 @@
-(void) saveTextFieldValue:(NSString *)textString withTag:(NSInteger) tagValue {
if (tagValue == 40)
- [self.settingsDictionary setObject:textString forKey:@"username"];
- else {
- [self.settingsDictionary setObject:[NSNumber numberWithInt:[textString length]] forKey:@"password_length"];
- [self.settingsDictionary setObject:[textString MD5hash] forKey:@"password"];
- }
+ [self.settings setObject:textString forKey:@"username"];
+ else
+ [self.settings setObject:[textString MD5hash] forKey:@"password"];
}
#pragma mark -
@@ -175,23 +166,16 @@
if (row == 0) {
editableCell.titleLabel.text = NSLocalizedString(@"Nickname","from the settings table");
editableCell.textField.placeholder = NSLocalizedString(@"Insert your username (if you have one)",@"");
- editableCell.textField.text = [self.settingsDictionary objectForKey:@"username"];
+ editableCell.textField.text = [self.settings objectForKey:@"username"];
editableCell.textField.secureTextEntry = NO;
editableCell.tag = 40;
} else {
- // create a dummy password for setting some visual content for the password
- int pwdLength = [[self.settingsDictionary objectForKey:@"password_length"] intValue];
- char *dummyStr = (char *)malloc(sizeof(char)*pwdLength);
- for (int i = 0; i < pwdLength; i++)
- dummyStr[i] = i;
- NSString *dummy = [[NSString alloc] initWithBytes:dummyStr length:pwdLength encoding:NSASCIIStringEncoding];
- free(dummyStr);
+ NSString *pwd = [self.settings objectForKey:@"password"];
editableCell.titleLabel.text = NSLocalizedString(@"Password","from the settings table");
editableCell.textField.placeholder = NSLocalizedString(@"Insert your password",@"");
- editableCell.textField.text = dummy;
+ editableCell.textField.text = ([pwd length] == 0) ? @"0123456789" : pwd;
editableCell.textField.secureTextEntry = YES;
editableCell.tag = 50;
- [dummy release];
}
editableCell.accessoryView = nil;
@@ -210,11 +194,11 @@
switchContent = (UISwitch *)cell.accessoryView;
if (row == 0) {
cell.textLabel.text = NSLocalizedString(@"Sound", @"");
- switchContent.on = [[self.settingsDictionary objectForKey:@"sound"] boolValue];
+ switchContent.on = [[self.settings objectForKey:@"sound"] boolValue];
switchContent.tag = 10;
} else {
cell.textLabel.text = NSLocalizedString(@"Music", @"");
- switchContent.on = [[self.settingsDictionary objectForKey:@"music"] boolValue];
+ switchContent.on = [[self.settings objectForKey:@"music"] boolValue];
switchContent.tag = 20;
}
break;
@@ -233,25 +217,25 @@
case 0:
cell.textLabel.text = NSLocalizedString(@"Alternate Damage", @"");
cell.detailTextLabel.text = NSLocalizedString(@"Damage popups will notify you on every single hit", @"");
- switchContent.on = [[self.settingsDictionary objectForKey:@"alternate"] boolValue];
+ switchContent.on = [[self.settings objectForKey:@"alternate"] boolValue];
switchContent.tag = 30;
break;
case 1:
cell.textLabel.text = NSLocalizedString(@"Enanched Graphics Mode", @"");
cell.detailTextLabel.text = NSLocalizedString(@"The game will use more memory so it could crash!", @"");
- switchContent.on = [[self.settingsDictionary objectForKey:@"enhanced"] boolValue];
+ switchContent.on = [[self.settings objectForKey:@"enhanced"] boolValue];
switchContent.tag = 70;
break;
case 2:
cell.textLabel.text = NSLocalizedString(@"Multitasking Enabled", @"");
cell.detailTextLabel.text = NSLocalizedString(@"Disable it in case of issues when returing in game", @"");
- switchContent.on = [[self.settingsDictionary objectForKey:@"multitasking"] boolValue];
+ switchContent.on = [[self.settings objectForKey:@"multitasking"] boolValue];
switchContent.tag = 80;
break;
case 3:
cell.textLabel.text = NSLocalizedString(@"Classic Ammo Menu", @"");
cell.detailTextLabel.text = NSLocalizedString(@"Select which style of ammo menu you prefer",@"");
- switchContent.on = [[self.settingsDictionary objectForKey:@"menu"] boolValue];
+ switchContent.on = [[self.settings objectForKey:@"classic_menu"] boolValue];
switchContent.tag = 60;
break;
default:
@@ -287,13 +271,13 @@
}
-(void) viewDidUnload {
- self.settingsDictionary = nil;
+ self.settings = nil;
MSG_DIDUNLOAD();
[super viewDidUnload];
}
-(void) dealloc {
- [settingsDictionary release];
+ [settings release];
[super dealloc];
}
--- a/project_files/HedgewarsMobile/Classes/HedgewarsAppDelegate.m Mon May 09 18:00:39 2011 +0200
+++ b/project_files/HedgewarsMobile/Classes/HedgewarsAppDelegate.m Wed May 11 01:26:38 2011 +0200
@@ -116,8 +116,7 @@
device.multitaskingSupported &&
self.isInGame) {
// let's try to be permissive with multitasking here...
- NSDictionary *settings = [[NSDictionary alloc] initWithContentsOfFile:SETTINGS_FILE()];
- if ([[settings objectForKey:@"multitasking"] boolValue])
+ if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"multitasking"] boolValue])
HW_suspend();
else {
// so the game returns to the configuration view
@@ -128,7 +127,6 @@
[self applicationWillTerminate:application];
}
}
- [settings release];
}
}
--- a/project_files/HedgewarsMobile/Classes/MainMenuViewController.m Mon May 09 18:00:39 2011 +0200
+++ b/project_files/HedgewarsMobile/Classes/MainMenuViewController.m Wed May 11 01:26:38 2011 +0200
@@ -45,19 +45,8 @@
[[NSFileManager defaultManager] removeItemAtPath:SAVES_DIRECTORY() error:NULL];
[[NSFileManager defaultManager] createDirectoryAtPath:SAVES_DIRECTORY() withIntermediateDirectories:NO attributes:nil error:NULL];
- // SETTINGS FILE - merge when present
- NSString *baseSettingsFile = [[NSString alloc] initWithFormat:@"%@/Settings/settings.plist",resourcesDir];
- if ([[NSFileManager defaultManager] fileExistsAtPath:SETTINGS_FILE()]) {
- NSDictionary *settings = [[NSDictionary alloc] initWithContentsOfFile:SETTINGS_FILE()];
- NSMutableDictionary *update = [[NSMutableDictionary alloc] initWithContentsOfFile:baseSettingsFile];
- // the order of what adds what is important
- [update addEntriesFromDictionary:settings];
- [settings release];
- [update writeToFile:SETTINGS_FILE() atomically:YES];
- [update release];
- } else
- [[NSFileManager defaultManager] copyItemAtPath:baseSettingsFile toPath:SETTINGS_FILE() error:NULL];
- [baseSettingsFile release];
+ // SETTINGS - nsuserdefaults ftw
+ createSettings();
// TEAMS - update exisiting teams with new format
if ([[NSFileManager defaultManager] fileExistsAtPath:TEAMS_DIRECTORY()] == NO) {
--- a/project_files/HedgewarsMobile/Classes/OverlayViewController.h Mon May 09 18:00:39 2011 +0200
+++ b/project_files/HedgewarsMobile/Classes/OverlayViewController.h Wed May 11 01:26:38 2011 +0200
@@ -46,7 +46,6 @@
BOOL isAttacking;
// stuff initialized externally
- BOOL useClassicMenu;
NSInteger initialOrientation;
// dual head support
@@ -68,7 +67,6 @@
@property (nonatomic,retain) UIButton *confirmButton;
@property (nonatomic,retain) UISegmentedControl *grenadeTimeSegment;
-@property (assign) BOOL useClassicMenu;
@property (assign) NSInteger initialOrientation;
@property (assign) NSInteger initialScreenCount;
--- a/project_files/HedgewarsMobile/Classes/OverlayViewController.m Mon May 09 18:00:39 2011 +0200
+++ b/project_files/HedgewarsMobile/Classes/OverlayViewController.m Wed May 11 01:26:38 2011 +0200
@@ -35,7 +35,7 @@
@implementation OverlayViewController
-@synthesize popoverController, popupMenu, helpPage, amvc, useClassicMenu, initialScreenCount, initialOrientation,
+@synthesize popoverController, popupMenu, helpPage, amvc, initialScreenCount, initialOrientation,
lowerIndicator, savesIndicator, confirmButton, grenadeTimeSegment;
#pragma mark -
@@ -353,7 +353,7 @@
playSound(@"clickSound");
clearView();
- if (IS_DUALHEAD() || self.useClassicMenu == NO) {
+ if (IS_DUALHEAD() || [[[NSUserDefaults standardUserDefaults] objectForKey:@"classic_menu"] boolValue] == NO) {
if (self.amvc == nil)
self.amvc = [[AmmoMenuViewController alloc] init];
--- a/project_files/HedgewarsMobile/Classes/ServerSetup.m Mon May 09 18:00:39 2011 +0200
+++ b/project_files/HedgewarsMobile/Classes/ServerSetup.m Wed May 11 01:26:38 2011 +0200
@@ -33,9 +33,7 @@
-(id) init {
if (self = [super init]) {
- NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:SETTINGS_FILE()];
- self.systemSettings = dict;
- [dict release];
+ self.systemSettings = nil; //nsuserdefault
}
return self;
}
--- a/project_files/HedgewarsMobile/Resources/Settings/settings.plist Mon May 09 18:00:39 2011 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,24 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
-<plist version="1.0">
-<dict>
- <key>alternate</key>
- <false/>
- <key>music</key>
- <true/>
- <key>password</key>
- <string></string>
- <key>sound</key>
- <true/>
- <key>username</key>
- <string></string>
- <key>menu</key>
- <false/>
- <key>password_length</key>
- <integer>0</integer>
- <key>enhanced</key>
- <true/>
- <key>multitasking</key>
- <true/>
-</dict>
-</plist>