allow to compile engine as library with HWLIBRARY symbol
move the first run check in the first view controller instead of appdelegate
relocate things around to make room for controls/buttons/menu
--- a/cocoaTouch/MainMenuViewController.m Fri Feb 12 18:40:14 2010 +0000
+++ b/cocoaTouch/MainMenuViewController.m Sat Feb 13 01:56:35 2010 +0000
@@ -10,25 +10,20 @@
#import "SDL_uikitappdelegate.h"
#import "PascalImports.h"
+// in case we don't want SDL_mixer...
+//#import "SoundEffect.h"
+//SoundEffect *erasingSound = [[SoundEffect alloc] initWithContentsOfFile:[mainBundle pathForResource:@"Erase" ofType:@"caf"]];
+//SoundEffect *selectSound = [[SoundEffect alloc] initWithContentsOfFile:[mainBundle pathForResource:@"Select" ofType:@"caf"]];
+
+
@implementation MainMenuViewController
@synthesize versionLabel, settingsViewController, mainView;
-/*
- // The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
-- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
- if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
- // Custom initialization
- }
- return self;
-}
-*/
-
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
-
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
@@ -40,9 +35,9 @@
}
}
-
-// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
-(void) viewDidLoad {
+ [NSThread detachNewThreadSelector:@selector(checkFirstRun) toTarget:self withObject:nil];
+
char *ver;
HW_versionInfo(NULL, &ver);
self.versionLabel.text = [[NSString stringWithUTF8String:ver] autorelease];
@@ -71,6 +66,51 @@
[super viewDidAppear:animated];
}
+-(void) checkFirstRun {
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+
+ NSString *filePath = [[SDLUIKitDelegate sharedAppDelegate] dataFilePath:@"settings.plist"];
+ if (!([[NSFileManager defaultManager] fileExistsAtPath:filePath])) {
+ // file not present, means that also other files are absent
+ NSLog(@"First time run, creating settings files");
+
+ // show a popup with an indicator to make the user wait
+ UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"One-time Preferences Configuration",@"")
+ message:nil
+ delegate:nil
+ cancelButtonTitle:nil
+ otherButtonTitles:nil];
+ [alert show];
+
+ UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc]
+ initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
+ indicator.center = CGPointMake(alert.bounds.size.width / 2, alert.bounds.size.height - 50);
+ [indicator startAnimating];
+ [alert addSubview:indicator];
+ [indicator release];
+
+ // create settings.plist
+ NSMutableDictionary *saveDict = [[NSMutableDictionary alloc] init];
+
+ [saveDict setObject:@"" forKey:@"username"];
+ [saveDict setObject:@"" forKey:@"password"];
+ [saveDict setObject:@"1" forKey:@"music"];
+ [saveDict setObject:@"1" forKey:@"sounds"];
+ [saveDict setObject:@"0" forKey:@"alternate"];
+
+ [saveDict writeToFile:filePath atomically:YES];
+ [saveDict release];
+
+ // create other files
+
+ // memory cleanup
+ [alert dismissWithClickedButtonIndex:0 animated:YES];
+ [alert release];
+ }
+ [pool release];
+ [NSThread exit];
+}
+
#pragma mark -
#pragma mark Action buttons
-(IBAction) startPlaying {
@@ -103,12 +143,12 @@
[UIView beginAnimations:@"View Switch" context:NULL];
[UIView setAnimationDuration:1];
- //[UIView setAnimationDuration:UIViewAnimationCurveEaseOut];
+
self.settingsViewController.view.frame = CGRectMake(0, 0, 480, 320);
self.mainView.frame = CGRectMake(0, 320, 480, 320);
+ [UIView commitAnimations];
[self.view addSubview:settingsViewController.view];
- [UIView commitAnimations];
}
}
--- a/cocoaTouch/SDLOverrides/SDL_uikitappdelegate.m Fri Feb 12 18:40:14 2010 +0000
+++ b/cocoaTouch/SDLOverrides/SDL_uikitappdelegate.m Sat Feb 13 01:56:35 2010 +0000
@@ -30,11 +30,6 @@
#import "PascalImports.h"
#import "MainMenuViewController.h"
-//#import "SoundEffect.h"
-// SoundEffect *erasingSound = [[SoundEffect alloc] initWithContentsOfFile:[mainBundle pathForResource:@"Erase" ofType:@"caf"]];
-// SoundEffect *selectSound = [[SoundEffect alloc] initWithContentsOfFile:[mainBundle pathForResource:@"Select" ofType:@"caf"]];
-
-
#ifdef main
#undef main
#endif
@@ -50,9 +45,9 @@
@synthesize uiwindow, window, viewController;
-/* convenience method */
+// convenience method
+(SDLUIKitDelegate *)sharedAppDelegate {
- /* the delegate is set in UIApplicationMain(), which is guaranteed to be called before this method */
+ // the delegate is set in UIApplicationMain(), which is guaranteed to be called before this method
return (SDLUIKitDelegate *)[[UIApplication sharedApplication] delegate];
}
@@ -105,48 +100,12 @@
[internal_pool release];
}
--(BOOL) checkFirstRun {
- //move all this inside the MainMenuViewController
- BOOL isFirstRun = NO;
-
- //use a nssthread a ask the user to wait
-
- NSString *filePath = [self dataFilePath:@"settings.plist"];
- if (!([[NSFileManager defaultManager] fileExistsAtPath:filePath])) {
- isFirstRun = YES;
- // file not present, let's create it
- NSMutableDictionary *saveDict = [[NSMutableDictionary alloc] init];
-
- [saveDict setObject:@"" forKey:@"username"];
- [saveDict setObject:@"" forKey:@"password"];
- [saveDict setObject:@"1" forKey:@"music"];
- [saveDict setObject:@"1" forKey:@"sounds"];
- [saveDict setObject:@"0" forKey:@"alternate"];
-
- [saveDict writeToFile:filePath atomically:YES];
- [saveDict release];
- }
- return isFirstRun;
-}
-
-(NSString *)dataFilePath: (NSString *)fileName {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
return [documentsDirectory stringByAppendingPathComponent:fileName];
}
--(void) applicationDidReceiveMemoryWarning:(UIApplication *)application {
- /* we get too many ones on ipod touch
- UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Running low on memory"
- message:@"I will try to free some memory but game might slow down a little"
- delegate:nil
- cancelButtonTitle:@"Ok"
- otherButtonTitles:nil ];
- [alert show];
- [alert release];
- */
-}
-
#pragma mark -
#pragma mark SDLUIKitDelegate methods
// override the direct execution of SDL_main to allow us to implement the frontend (even using a nib)
@@ -159,29 +118,28 @@
self.viewController = [[MainMenuViewController alloc] initWithNibName:@"MainMenuViewController" bundle:nil];
- /* Set working directory to resource path */
+ // Set working directory to resource path
[[NSFileManager defaultManager] changeCurrentDirectoryPath: [[NSBundle mainBundle] resourcePath]];
[uiwindow addSubview:viewController.view];
[uiwindow makeKeyAndVisible];
[uiwindow layoutSubviews];
- [self checkFirstRun];
}
-(void) applicationWillTerminate:(UIApplication *)application {
SDL_SendQuit();
- /* hack to prevent automatic termination. See SDL_uikitevents.m for details */
+ // hack to prevent automatic termination. See SDL_uikitevents.m for details
// have to remove this otherwise game goes on when pushing the home button
//longjmp(*(jump_env()), 1);
}
-(void) applicationWillResignActive:(UIApplication*)application {
-// NSLog(@"%@", NSStringFromSelector(_cmd));
+ //NSLog(@"%@", NSStringFromSelector(_cmd));
SDL_SendWindowEvent(self.window, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
}
-(void) applicationDidBecomeActive:(UIApplication*)application {
-// NSLog(@"%@", NSStringFromSelector(_cmd));
+ //NSLog(@"%@", NSStringFromSelector(_cmd));
SDL_SendWindowEvent(self.window, SDL_WINDOWEVENT_RESTORED, 0, 0);
}
--- a/cocoaTouch/SettingsViewController.h Fri Feb 12 18:40:14 2010 +0000
+++ b/cocoaTouch/SettingsViewController.h Sat Feb 13 01:56:35 2010 +0000
@@ -20,7 +20,6 @@
UITableViewCell *volumeCell;
UIView *buttonContainer;
UIView *parentView;
- BOOL needsReset;
}
@property (nonatomic, retain) IBOutlet UITextField *username;
--- a/cocoaTouch/SettingsViewController.m Fri Feb 12 18:40:14 2010 +0000
+++ b/cocoaTouch/SettingsViewController.m Sat Feb 13 01:56:35 2010 +0000
@@ -28,7 +28,6 @@
-(void) viewDidLoad {
NSString *filePath = [[SDLUIKitDelegate sharedAppDelegate] dataFilePath:@"settings.plist"];
- needsReset = NO;
if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
NSMutableDictionary *data = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
username.text = [data objectForKey:@"username"];
@@ -75,26 +74,6 @@
[super viewDidUnload];
}
-//- (void)applicationWillTerminate:(NSNotification *)notification {
--(void) viewWillDisappear:(BOOL)animated {
- if (!needsReset) {
- NSMutableDictionary *saveDict = [[NSMutableDictionary alloc] init];
- NSString *tmpMus = (musicSwitch.on) ? @"1" : @"0";
- NSString *tmpEff = (soundsSwitch.on) ? @"1" : @"0";
- NSString *tmpAlt = (altDamageSwitch.on) ? @"1" : @"0";
-
- [saveDict setObject:username.text forKey:@"username"];
- [saveDict setObject:password.text forKey:@"password"];
- [saveDict setObject:tmpMus forKey:@"music"];
- [saveDict setObject:tmpEff forKey:@"sounds"];
- [saveDict setObject:tmpAlt forKey:@"alternate"];
-
- [saveDict writeToFile:[[SDLUIKitDelegate sharedAppDelegate] dataFilePath:@"settings.plist"] atomically:YES];
- [saveDict release];
- }
- [super viewWillDisappear:animated];
-}
-
-(void) dealloc {
[username release];
[password release];
@@ -112,7 +91,6 @@
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}
-
// makes the keyboard go away when background is tapped
-(IBAction) backgroundTap: (id)sender {
[username resignFirstResponder];
@@ -139,6 +117,40 @@
}
#pragma mark -
+#pragma mark Return to mainView
+-(void) flushData {
+ NSLog(@"writing preferences to file");
+
+ NSMutableDictionary *saveDict = [[NSMutableDictionary alloc] init];
+ NSString *tmpMus = (musicSwitch.on) ? @"1" : @"0";
+ NSString *tmpEff = (soundsSwitch.on) ? @"1" : @"0";
+ NSString *tmpAlt = (altDamageSwitch.on) ? @"1" : @"0";
+
+ [saveDict setObject:username.text forKey:@"username"];
+ [saveDict setObject:password.text forKey:@"password"];
+ [saveDict setObject:tmpMus forKey:@"music"];
+ [saveDict setObject:tmpEff forKey:@"sounds"];
+ [saveDict setObject:tmpAlt forKey:@"alternate"];
+
+ [saveDict writeToFile:[[SDLUIKitDelegate sharedAppDelegate] dataFilePath:@"settings.plist"] atomically:YES];
+ [saveDict release];
+}
+
+-(void) returnMainView {
+ [self flushData];
+
+ [UIView beginAnimations:@"Get Back" context:NULL];
+ [UIView setAnimationDuration:1];
+
+ self.view.frame = CGRectMake(0, -320, 480, 320);
+ self.parentView.frame = CGRectMake(0, 0, 480, 320);
+ [UIView commitAnimations];
+
+ [self.view performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:1];
+ self.parentView = nil;
+}
+
+#pragma mark -
#pragma mark UIActionSheet Methods
-(IBAction) deleteData: (id)sender {
/* temporary commented out
@@ -150,22 +162,11 @@
[actionSheet showInView:self.view];
[actionSheet release];
*/
- [UIView beginAnimations:@"Get Back" context:NULL];
- [UIView setAnimationDuration:1];
- //[UIView setAnimationDuration:UIViewAnimationCurveEaseOut];
-
- self.view.frame = CGRectMake(0, -320, 480, 320);
- self.parentView.frame = CGRectMake(0, 0, 480, 320);
- [UIView commitAnimations];
-
- [self.view performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:1];
- self.parentView = nil;
+ [self returnMainView];
}
-(void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger) buttonIndex {
if ([actionSheet cancelButtonIndex] != buttonIndex) {
- needsReset = YES;
-
// get the documents dirctory
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
--- a/hedgewars/PascalExports.pas Fri Feb 12 18:40:14 2010 +0000
+++ b/hedgewars/PascalExports.pas Sat Feb 13 01:56:35 2010 +0000
@@ -21,7 +21,9 @@
// called by pascal code, they deal with the objc code
function IPH_getDocumentsPath: PChar; cdecl; external;
procedure IPH_showControls; cdecl; external;
+{$ENDIF}
+{$IFDEF HWLIBRARY}
// retrieve protocol information
procedure HW_versionInfo(netProto: PShortInt; versionStr: PString); cdecl; export;
@@ -45,7 +47,7 @@
implementation
-{$IFDEF IPHONEOS}
+{$IFDEF HWLIBRARY}
procedure HW_versionInfo(netProto: PShortInt; versionStr: PString); cdecl; export;
begin
if netProto <> nil then netProto^:= cNetProtoVersion;
--- a/hedgewars/hwengine.pas Fri Feb 12 18:40:14 2010 +0000
+++ b/hedgewars/hwengine.pas Sat Feb 13 01:56:35 2010 +0000
@@ -22,7 +22,7 @@
{$R hwengine.rc}
{$ENDIF}
-{$IFDEF IPHONEOS}
+{$IFDEF HWLIBRARY}
unit hwengine;
interface
{$ELSE}
@@ -69,7 +69,7 @@
// SinTable.inc
// proto.inc
-{$IFDEF IPHONEOS}
+{$IFDEF HWLIBRARY}
type arrayofpchar = array[0..5] of PChar;
procedure DoTimer(Lag: LongInt);
procedure OnDestroy;
@@ -224,7 +224,7 @@
end;
///////////////
-{$IFDEF IPHONEOS}
+{$IFDEF HWLIBRARY}
procedure Game(gameArgs: arrayofpchar); cdecl; export;
{$ELSE}
procedure Game;cdecl; export;
@@ -232,7 +232,7 @@
var p: TPathType;
s: shortstring;
begin
-{$IFDEF IPHONEOS}
+{$IFDEF HWLIBRARY}
initEverything();
Randomize();
@@ -386,7 +386,8 @@
free_uConsts(); //stub
free_uScript();
end;
-{$IFNDEF IPHONEOS}
+
+{$IFNDEF HWLIBRARY}
/////////////////////////
procedure GenLandPreview;
var Preview: TPreview;
--- a/hedgewars/options.inc Fri Feb 12 18:40:14 2010 +0000
+++ b/hedgewars/options.inc Sat Feb 13 01:56:35 2010 +0000
@@ -22,13 +22,15 @@
{$ERROR Only Free Pascal supported!}
{$ENDIF}
+{$MODE OBJFPC}
+
{$IFDEF IPHONEOS}
{$DEFINE SDL13}
{$DEFINE GLES11}
{$DEFINE LOWRES}
{$DEFINE SDL_MIXER_NEWER}
{$DEFINE SDL_IMAGE_NEWER}
- {$MODE OBJFPC}
+ {$DEFINE HWLIBRARY}
{$ENDIF}
{$IFNDEF DARWIN}
--- a/hedgewars/uMisc.pas Fri Feb 12 18:40:14 2010 +0000
+++ b/hedgewars/uMisc.pas Sat Feb 13 01:56:35 2010 +0000
@@ -642,7 +642,7 @@
procedure init_uMisc;
-var i: LongInt;
+{$IFNDEF IPHONEOS}var i: LongInt;{$ENDIF}
begin
cDrownSpeed.QWordValue := 257698038; // 0.06
cMaxWindSpeed.QWordValue:= 2147484; // 0.0005
--- a/hedgewars/uWorld.pas Fri Feb 12 18:40:14 2010 +0000
+++ b/hedgewars/uWorld.pas Sat Feb 13 01:56:35 2010 +0000
@@ -359,8 +359,8 @@
tdx, tdy: Double;
grp: TCapGroup;
s: string[15];
- highlight: Boolean;
- offset: LongInt;
+ highlight: Boolean;
+ offset, offsetX, offsetY: LongInt;
scale: GLfloat;
begin
if ZoomValue < zoom then
@@ -451,7 +451,11 @@
// Turn time
+{$IFDEF IPHONEOS}
+offset:= 313;
+{$ELSE}
offset:= 48;
+{$ENDIF}
if TurnTimeLeft <> 0 then
begin
i:= Succ(Pred(TurnTimeLeft) div 1000);
@@ -516,7 +520,7 @@
// Captions
{$IFDEF IPHONEOS}
-offset:= 49;
+offset:= 40;
{$ELSE}
if ((TrainingFlags and tfTimeTrial) <> 0) and (TimeTrialStartTime > 0) then offset:= 48
else offset:= 8;
@@ -578,11 +582,13 @@
// Wind bar
{$IFDEF IPHONEOS}
-offset:= 305;
+offsetX:= 305;
+offsetY:= 315;
{$ELSE}
-offset:= 30;
+offsetX:= 30;
+offsetY:= 180;
{$ENDIF}
-DrawSprite(sprWindBar, (cScreenWidth shr 1) - 180, cScreenHeight - offset, 0);
+DrawSprite(sprWindBar, (cScreenWidth shr 1) - offsetY, cScreenHeight - offsetX, 0);
if WindBarWidth > 0 then
begin
{$WARNINGS OFF}
@@ -591,7 +597,7 @@
r.y:= 0;
r.w:= WindBarWidth;
r.h:= 13;
- DrawSpriteFromRect(sprWindR, r, (cScreenWidth shr 1) - 103, cScreenHeight - offset + 2, 13, 0);
+ DrawSpriteFromRect(sprWindR, r, (cScreenWidth shr 1) - offsetY + 77, cScreenHeight - offsetX + 2, 13, 0);
end else
if WindBarWidth < 0 then
begin
@@ -601,7 +607,7 @@
r.y:= 0;
r.w:= - WindBarWidth;
r.h:= 13;
- DrawSpriteFromRect(sprWindL, r, (cScreenWidth shr 1) - 106 + WindBarWidth, cScreenHeight - offset + 2, 13, 0);
+ DrawSpriteFromRect(sprWindL, r, (cScreenWidth shr 1) - offsetY + 74 + WindBarWidth, cScreenHeight - offsetX + 2, 13, 0);
end;
// AmmoMenu
@@ -626,7 +632,7 @@
// fps
{$IFDEF IPHONEOS}
-offset:= 40;
+offset:= 300;
{$ELSE}
offset:= 10;
{$ENDIF}