headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
--- a/project_files/HedgewarsMobile/Classes/AboutViewController.m Fri Sep 30 22:33:28 2011 -0400
+++ b/project_files/HedgewarsMobile/Classes/AboutViewController.m Sun Oct 02 00:57:04 2011 +0200
@@ -20,7 +20,7 @@
#import "AboutViewController.h"
-#import "CommodityFunctions.h"
+
@implementation AboutViewController
@synthesize tableView, segmentedControl, people;
--- a/project_files/HedgewarsMobile/Classes/AmmoMenuViewController.m Fri Sep 30 22:33:28 2011 -0400
+++ b/project_files/HedgewarsMobile/Classes/AmmoMenuViewController.m Sun Oct 02 00:57:04 2011 +0200
@@ -21,9 +21,7 @@
#import "AmmoMenuViewController.h"
#import <QuartzCore/QuartzCore.h>
-#import "CommodityFunctions.h"
-#import "UIImageExtra.h"
-#import "PascalImports.h"
+
#define BTNS_PER_ROW 9
#define DEFAULT_DESCRIPTION IS_IPAD() ? \
@@ -92,7 +90,7 @@
int y = (HW_getNumberOfWeapons()/BTNS_PER_ROW)*44 + 18;
UILabel *name = [[UILabel alloc] initWithFrame:CGRectMake(x, y, 200, 20)];
name.backgroundColor = [UIColor clearColor];
- name.textColor = UICOLOR_HW_YELLOW_BODER;
+ name.textColor = [UIColor darkYellowColor];
name.font = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]];
self.nameLabel = name;
[self.view addSubview:self.nameLabel];
@@ -152,14 +150,14 @@
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(x, y, 40, 40);
button.tag = i;
- button.layer.borderColor = [UICOLOR_HW_YELLOW_TEXT CGColor];
+ button.layer.borderColor = [[UIColor lightYellowColor] CGColor];
button.layer.borderWidth = w;
[button.layer setCornerRadius:radius];
[button.layer setMasksToBounds:YES];
[button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchDown];
[button addTarget:self action:@selector(buttonReleased:) forControlEvents:UIControlEventTouchUpInside];
[button addTarget:self action:@selector(buttonCancelled:) forControlEvents:UIControlEventTouchUpOutside|UIControlEventTouchCancel];
- [button setTitleColor:UICOLOR_HW_YELLOW_TEXT forState:UIControlStateNormal];
+ [button setTitleColor:[UIColor lightYellowColor] forState:UIControlStateNormal];
button.titleLabel.backgroundColor = [UIColor blackColor];
button.titleLabel.font = [UIFont boldSystemFontOfSize:[UIFont smallSystemFontSize]];
[button.titleLabel.layer setCornerRadius:3];
@@ -169,9 +167,9 @@
[self.view addSubview:button];
[array addObject:button];
- int size = 32*getScreenScale();
- int x_src = ((i*size)/(int)(ammoStoreImage.size.height*getScreenScale()))*size;
- int y_src = (i*size)%(int)(ammoStoreImage.size.height*getScreenScale());
+ int size = 32 * [[UIScreen mainScreen] scale];
+ int x_src = ((i*size)/(int)(ammoStoreImage.size.height * [[UIScreen mainScreen] scale]))*size;
+ int y_src = (i*size)%(int)(ammoStoreImage.size.height * [[UIScreen mainScreen] scale]);
UIImage *img = [ammoStoreImage cutAt:CGRectMake(x_src, y_src, size, size)];
[imgs addObject:img];
}
@@ -221,7 +219,7 @@
shouldUpdateImage[i] = YES;
}
} else {
- button.layer.borderColor = [UICOLOR_HW_YELLOW_TEXT CGColor];
+ button.layer.borderColor = [[UIColor lightYellowColor] CGColor];
[button setTitle:nil forState:UIControlStateNormal];
if (button.currentBackgroundImage == nil || shouldUpdateImage[i] == YES) {
UIImage *img = [self.imagesArray objectAtIndex:i];
--- a/project_files/HedgewarsMobile/Classes/Appirater.m Fri Sep 30 22:33:28 2011 -0400
+++ b/project_files/HedgewarsMobile/Classes/Appirater.m Sun Oct 02 00:57:04 2011 +0200
@@ -37,7 +37,7 @@
#import "Appirater.h"
#import <SystemConfiguration/SCNetworkReachability.h>
#import <netinet/in.h>
-#import "CommodityFunctions.h"
+#import "ServerSetup.h"
NSString *const kAppiraterLaunchDate = @"kAppiraterLaunchDate";
NSString *const kAppiraterLaunchCount = @"kAppiraterLaunchCount";
@@ -106,7 +106,7 @@
launchCount > LAUNCHES_UNTIL_PROMPT &&
!declinedToRate &&
!ratedApp) {
- if (isNetworkReachable()) { // check if they can reach the app store
+ if ([ServerSetup isNetworkReachable]) { // check if they can reach the app store
willShowPrompt = YES;
[self performSelectorOnMainThread:@selector(showPrompt) withObject:nil waitUntilDone:NO];
}
--- a/project_files/HedgewarsMobile/Classes/CommodityFunctions.h Fri Sep 30 22:33:28 2011 -0400
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,83 +0,0 @@
-/*
- * Hedgewars-iOS, a Hedgewars port for iOS devices
- * Copyright (c) 2009-2010 Vittorio Giovara <vittorio.giovara@gmail.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *
- * File created on 08/04/2010.
- */
-
-
-#import <Foundation/Foundation.h>
-
-#define DOCUMENTS_FOLDER() [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]
-
-#define DEBUG_FILE() [DOCUMENTS_FOLDER() stringByAppendingString:@"/hw-game.log"]
-#define BASICFLAGS_FILE() [[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"/Settings/basicFlags.plist"]
-#define GAMEMODS_FILE() [[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"/Settings/gameMods.plist"]
-#define CREDITS_FILE() [[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"/Settings/credits.plist"]
-
-#define TEAMS_DIRECTORY() [DOCUMENTS_FOLDER() stringByAppendingString:@"/Teams/"]
-#define WEAPONS_DIRECTORY() [DOCUMENTS_FOLDER() stringByAppendingString:@"/Weapons/"]
-#define SCHEMES_DIRECTORY() [DOCUMENTS_FOLDER() stringByAppendingString:@"/Schemes/"]
-#define SAVES_DIRECTORY() [DOCUMENTS_FOLDER() stringByAppendingString:@"/Saves/"]
-
-#define GRAPHICS_DIRECTORY() [[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"/Data/Graphics/"]
-#define ICONS_DIRECTORY() [[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"/Data/Graphics/Icons/"]
-#define HATS_DIRECTORY() [[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"/Data/Graphics/Hats/"]
-#define GRAVES_DIRECTORY() [[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"/Data/Graphics/Graves/"]
-#define FLAGS_DIRECTORY() [[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"/Data/Graphics/Flags/"]
-#define FORTS_DIRECTORY() [[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"/Data/Forts/"]
-#define VOICES_DIRECTORY() [[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"/Data/Sounds/voices/"]
-#define THEMES_DIRECTORY() [[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"/Data/Themes/"]
-#define MAPS_DIRECTORY() [[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"/Data/Maps/"]
-#define MISSIONS_DIRECTORY() [[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"/Data/Missions/Maps/"]
-#define LOCALE_DIRECTORY() [[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"/Data/Locale/"]
-#define SCRIPTS_DIRECTORY() [[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"/Data/Scripts/plist/"]
-
-#define MSG_MEMCLEAN() DLog(@"has cleaned up some memory");
-#define MSG_DIDUNLOAD() DLog(@"unloaded");
-
-#define UICOLOR_HW_YELLOW_BODER [UIColor colorWithRed:(CGFloat)0xFE/255 green:(CGFloat)0xC0/255 blue:0 alpha:1]
-#define UICOLOR_HW_YELLOW_TEXT [UIColor colorWithRed:(CGFloat)0xF0/255 green:(CGFloat)0xD0/255 blue:0 alpha:1]
-#define UICOLOR_HW_DARKBLUE [UIColor colorWithRed:(CGFloat)0x0F/255 green:0 blue:(CGFloat)0x42/255 alpha:1]
-#define UICOLOR_HW_ALPHABLUE [UIColor colorWithRed:(CGFloat)0x0F/255 green:0 blue:(CGFloat)0x42/255 alpha:0.58f]
-#define UICOLOR_HW_ALMOSTBLACK (IS_NOT_POWERFUL(getModelType())) ? [UIColor blackColor] : [UIColor colorWithRed:0 green:0 blue:0 alpha:0.6]
-
-#define IS_DUALHEAD() ([[UIScreen class] respondsToSelector:@selector(screens)] && [[UIScreen screens] count] > 1)
-#define IS_IPAD() (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
-#define IS_NOT_POWERFUL(x) ([x hasPrefix:@"iPhone1"] || [x hasPrefix:@"iPod1,1"] || [x hasPrefix:@"iPod2,1"])
-#define IS_NOT_VERY_POWERFUL(x) ([x hasPrefix:@"iPad1"] || [x hasPrefix:@"iPhone2"] || [x hasPrefix:@"iPod3"] || [x hasPrefix:@"iPod4"])
-#define IS_VERY_POWERFUL(x) (IS_NOT_POWERFUL(x) == NO && IS_NOT_VERY_POWERFUL(x) == NO)
-
-#define UIVIEW_HW_SDLVIEW [[[[UIApplication sharedApplication] keyWindow] subviews] objectAtIndex:0]
-
-void print_free_memory (void);
-NSInteger randomPort (void);
-
-NSString *getModelType (void);
-NSArray *getAvailableColors (void);
-
-UILabel *createBlueLabel (NSString *title, CGRect frame);
-UILabel *createLabelWithParams (NSString *title, CGRect frame, CGFloat borderWidth, UIColor *borderColor, UIColor *backgroundColor);
-
-CGSize PSPNGSizeFromMetaData (NSString *aFileName);
-BOOL isNetworkReachable (void);
-
-@interface NSString (extra)
-
--(NSString *) MD5hash;
-
-@end
-
--- a/project_files/HedgewarsMobile/Classes/CommodityFunctions.m Fri Sep 30 22:33:28 2011 -0400
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,207 +0,0 @@
-/*
- * Hedgewars-iOS, a Hedgewars port for iOS devices
- * Copyright (c) 2009-2010 Vittorio Giovara <vittorio.giovara@gmail.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *
- * File created on 08/04/2010.
- */
-
-
-#import "CommodityFunctions.h"
-#import <sys/types.h>
-#import <sys/sysctl.h>
-#import <mach/mach.h>
-#import <mach/mach_host.h>
-#import <QuartzCore/QuartzCore.h>
-#import <CommonCrypto/CommonDigest.h>
-#import <SystemConfiguration/SCNetworkReachability.h>
-#import <netinet/in.h>
-#import "PascalImports.h"
-#import "hwconsts.h"
-
-
-NSInteger inline randomPort () {
- srandom(time(NULL));
- NSInteger res = (random() % 64511) + 1024;
- return (res == NETGAME_DEFAULT_PORT) ? randomPort() : res;
-}
-
-// by http://landonf.bikemonkey.org/code/iphone/Determining_Available_Memory.20081203.html
-void print_free_memory () {
-#ifdef DEBUG
- mach_port_t host_port;
- mach_msg_type_number_t host_size;
- vm_size_t pagesize;
-
- host_port = mach_host_self();
- host_size = sizeof(vm_statistics_data_t) / sizeof(integer_t);
- host_page_size(host_port, &pagesize);
-
- vm_statistics_data_t vm_stat;
-
- if (host_statistics(host_port, HOST_VM_INFO, (host_info_t)&vm_stat, &host_size) != KERN_SUCCESS)
- DLog(@"Failed to fetch vm statistics");
-
- /* Stats in bytes */
- natural_t mem_used = (vm_stat.active_count + vm_stat.inactive_count + vm_stat.wire_count) * pagesize;
- natural_t mem_free = vm_stat.free_count * pagesize;
- natural_t mem_total = mem_used + mem_free;
- DLog(@"used: %u free: %u total: %u", mem_used, mem_free, mem_total);
-#endif
-}
-
-NSString *getModelType () {
- size_t size;
- // set 'oldp' parameter to NULL to get the size of the data returned so we can allocate appropriate amount of space
- sysctlbyname("hw.machine", NULL, &size, NULL, 0);
- char *name = (char *)malloc(sizeof(char) * size);
- // get the platform name
- sysctlbyname("hw.machine", name, &size, NULL, 0);
- NSString *modelId = [NSString stringWithUTF8String:name];
- free(name);
-
- return modelId;
-}
-
-NSArray *getAvailableColors (void) {
- // by default colors are ARGB but we do computation over RGB, hence we have to "& 0x00FFFFFF" before processing
- unsigned int colors[] = HW_TEAMCOLOR_ARRAY;
- NSMutableArray *array = [[NSMutableArray alloc] init];
-
- int i = 0;
- while(colors[i] != 0)
- [array addObject:[NSNumber numberWithUnsignedInt:(colors[i++] & 0x00FFFFFF)]];
-
- NSArray *final = [NSArray arrayWithArray:array];
- [array release];
- return final;
-}
-
-UILabel *createBlueLabel (NSString *title, CGRect frame) {
- return createLabelWithParams(title, frame, 1.5f, UICOLOR_HW_YELLOW_BODER, UICOLOR_HW_DARKBLUE);
-}
-
-UILabel *createLabelWithParams (NSString *title, CGRect frame, CGFloat borderWidth, UIColor *borderColor, UIColor *backgroundColor) {
- UILabel *theLabel = [[UILabel alloc] initWithFrame:frame];
- theLabel.backgroundColor = backgroundColor;
-
- if (title != nil) {
- theLabel.text = title;
- theLabel.textColor = UICOLOR_HW_YELLOW_TEXT;
- theLabel.textAlignment = UITextAlignmentCenter;
- theLabel.font = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]*80/100];
- }
-
- [theLabel.layer setBorderWidth:borderWidth];
- [theLabel.layer setBorderColor:borderColor.CGColor];
- [theLabel.layer setCornerRadius:8.0f];
- [theLabel.layer setMasksToBounds:YES];
-
- return theLabel;
-}
-
-BOOL isNetworkReachable (void) {
- // Create zero addy
- struct sockaddr_in zeroAddress;
- bzero(&zeroAddress, sizeof(zeroAddress));
- zeroAddress.sin_len = sizeof(zeroAddress);
- zeroAddress.sin_family = AF_INET;
-
- // Recover reachability flags
- SCNetworkReachabilityRef defaultRouteReachability = SCNetworkReachabilityCreateWithAddress(NULL, (struct sockaddr *)&zeroAddress);
- SCNetworkReachabilityFlags flags;
-
- BOOL didRetrieveFlags = SCNetworkReachabilityGetFlags(defaultRouteReachability, &flags);
- CFRelease(defaultRouteReachability);
-
- if (!didRetrieveFlags) {
- NSLog(@"Error. Could not recover network reachability flags");
- return NO;
- }
-
- BOOL isReachable = flags & kSCNetworkFlagsReachable;
- BOOL needsConnection = flags & kSCNetworkFlagsConnectionRequired;
- BOOL nonWiFi = flags & kSCNetworkReachabilityFlagsTransientConnection;
-
- NSURL *testURL = [NSURL URLWithString:@"http://www.apple.com/"];
- NSURLRequest *testRequest = [NSURLRequest requestWithURL:testURL
- cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
- timeoutInterval:20.0];
- NSURLConnection *testConnection = [[NSURLConnection alloc] initWithRequest:testRequest delegate:nil];
- BOOL testResult = testConnection ? YES : NO;
- [testConnection release];
-
- return ((isReachable && !needsConnection) || nonWiFi) ? testResult : NO;
-}
-
-// this routine checks for the PNG size without loading it in memory
-// https://github.com/steipete/PSFramework/blob/master/PSFramework%20Version%200.3/PhotoshopFramework/PSMetaDataFunctions.m
-CGSize PSPNGSizeFromMetaData (NSString *aFileName) {
- // File Name to C String.
- const char *fileName = [aFileName UTF8String];
- // source file
- FILE *infile = fopen(fileName, "rb");
- if (infile == NULL) {
- DLog(@"Can't open the file: %@", aFileName);
- return CGSizeZero;
- }
-
- // Bytes Buffer.
- unsigned char buffer[30];
- // Grab Only First Bytes.
- fread(buffer, 1, 30, infile);
- // Close File.
- fclose(infile);
-
- // PNG Signature.
- unsigned char png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
-
- // Compare File signature.
- if ((int)(memcmp(&buffer[0], &png_signature[0], 8))) {
- DLog(@"The file (%@) is not a PNG file", aFileName);
- return CGSizeZero;
- }
-
- // Calc Sizes. Isolate only four bytes of each size (width, height).
- int width[4];
- int height[4];
- for (int d = 16; d < (16 + 4); d++) {
- width[d-16] = buffer[d];
- height[d-16] = buffer[d+4];
- }
-
- // Convert bytes to Long (Integer)
- long resultWidth = (width[0] << (int)24) | (width[1] << (int)16) | (width[2] << (int)8) | width[3];
- long resultHeight = (height[0] << (int)24) | (height[1] << (int)16) | (height[2] << (int)8) | height[3];
-
- // Return Size.
- return CGSizeMake(resultWidth,resultHeight);
-}
-
-@implementation NSString (extra)
-
--(NSString *)MD5hash {
- const char *cStr = [self UTF8String];
- unsigned char result[16];
- CC_MD5( cStr, strlen(cStr), result );
- return [NSString stringWithFormat:
- @"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
- result[0], result[1], result[2], result[3], result[4], result[5],
- result[6], result[7], result[8], result[9], result[10], result[11],
- result[12], result[13], result[14], result[15]];
-}
-
-
-@end
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/HedgewarsMobile/Classes/DefinesAndMacros.h Sun Oct 02 00:57:04 2011 +0200
@@ -0,0 +1,82 @@
+/*
+ * Hedgewars-iOS, a Hedgewars port for iOS devices
+ * Copyright (c) 2009-2010 Vittorio Giovara <vittorio.giovara@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * File created on 01/10/2011.
+ */
+
+
+// some macros by http://www.cimgf.com/2010/05/02/my-current-prefix-pch-file/
+// and http://blog.coriolis.ch/2009/01/05/macros-for-xcode/
+
+
+#ifdef DEBUG
+ #define DLog(...) NSLog(@"%s %@", __PRETTY_FUNCTION__, [NSString stringWithFormat:__VA_ARGS__])
+ #define ALog(...) [[NSAssertionHandler currentHandler] handleFailureInFunction:[NSString stringWithCString:__PRETTY_FUNCTION__ encoding:NSUTF8StringEncoding] file:[NSString stringWithCString:__FILE__ encoding:NSUTF8StringEncoding] lineNumber:__LINE__ description:__VA_ARGS__]
+ #define releaseAndNil(x) [x release]
+#else
+ #define DLog(...) do { } while (0)
+ #ifndef NS_BLOCK_ASSERTIONS
+ #define NS_BLOCK_ASSERTIONS
+ #endif
+ #define ALog(...) NSLog(@"%s %@", __PRETTY_FUNCTION__, [NSString stringWithFormat:__VA_ARGS__])
+ #define releaseAndNil(x) [x release], x = nil
+#endif
+
+
+#define ZAssert(condition, ...) do { if (!(condition)) { ALog(__VA_ARGS__); }} while(0)
+#define rotationManager(x) (x == UIInterfaceOrientationLandscapeRight) || (x == UIInterfaceOrientationLandscapeLeft)
+
+#define START_TIMER NSTimeInterval start = [NSDate timeIntervalSinceReferenceDate];
+#define END_TIMER(msg) NSTimeInterval stop = [NSDate timeIntervalSinceReferenceDate]; CMLog([NSString stringWithFormat:@"%@ Time = %f", msg, stop-start]);
+
+
+#define DOCUMENTS_FOLDER() [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]
+
+#define DEBUG_FILE() [DOCUMENTS_FOLDER() stringByAppendingString:@"/hw-game.log"]
+#define BASICFLAGS_FILE() [[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"/Settings/basicFlags.plist"]
+#define GAMEMODS_FILE() [[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"/Settings/gameMods.plist"]
+#define CREDITS_FILE() [[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"/Settings/credits.plist"]
+
+#define TEAMS_DIRECTORY() [DOCUMENTS_FOLDER() stringByAppendingString:@"/Teams/"]
+#define WEAPONS_DIRECTORY() [DOCUMENTS_FOLDER() stringByAppendingString:@"/Weapons/"]
+#define SCHEMES_DIRECTORY() [DOCUMENTS_FOLDER() stringByAppendingString:@"/Schemes/"]
+#define SAVES_DIRECTORY() [DOCUMENTS_FOLDER() stringByAppendingString:@"/Saves/"]
+
+#define GRAPHICS_DIRECTORY() [[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"/Data/Graphics/"]
+#define ICONS_DIRECTORY() [[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"/Data/Graphics/Icons/"]
+#define HATS_DIRECTORY() [[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"/Data/Graphics/Hats/"]
+#define GRAVES_DIRECTORY() [[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"/Data/Graphics/Graves/"]
+#define FLAGS_DIRECTORY() [[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"/Data/Graphics/Flags/"]
+#define FORTS_DIRECTORY() [[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"/Data/Forts/"]
+#define VOICES_DIRECTORY() [[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"/Data/Sounds/voices/"]
+#define THEMES_DIRECTORY() [[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"/Data/Themes/"]
+#define MAPS_DIRECTORY() [[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"/Data/Maps/"]
+#define MISSIONS_DIRECTORY() [[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"/Data/Missions/Maps/"]
+#define LOCALE_DIRECTORY() [[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"/Data/Locale/"]
+#define SCRIPTS_DIRECTORY() [[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"/Data/Scripts/plist/"]
+
+#define MSG_MEMCLEAN() DLog(@"has cleaned up some memory");
+#define MSG_DIDUNLOAD() DLog(@"unloaded");
+
+#define IS_DUALHEAD() ([[UIScreen class] respondsToSelector:@selector(screens)] && [[UIScreen screens] count] > 1)
+#define IS_IPAD() (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
+#define IS_NOT_POWERFUL(x) ([x hasPrefix:@"iPhone1"] || [x hasPrefix:@"iPod1,1"] || [x hasPrefix:@"iPod2,1"])
+#define IS_NOT_VERY_POWERFUL(x) ([x hasPrefix:@"iPad1"] || [x hasPrefix:@"iPhone2"] || [x hasPrefix:@"iPod3"] || [x hasPrefix:@"iPod4"])
+#define IS_VERY_POWERFUL(x) (IS_NOT_POWERFUL(x) == NO && IS_NOT_VERY_POWERFUL(x) == NO)
+
+#define UIVIEW_HW_SDLVIEW [[[[UIApplication sharedApplication] keyWindow] subviews] objectAtIndex:0]
+
--- a/project_files/HedgewarsMobile/Classes/EditableCellView.m Fri Sep 30 22:33:28 2011 -0400
+++ b/project_files/HedgewarsMobile/Classes/EditableCellView.m Sun Oct 02 00:57:04 2011 +0200
@@ -20,7 +20,7 @@
#import "EditableCellView.h"
-#import "CommodityFunctions.h"
+
@implementation EditableCellView
@synthesize delegate, textField, titleLabel, minimumCharacters, maximumCharacters, respectEditing, oldValue;
--- a/project_files/HedgewarsMobile/Classes/EngineProtocolNetwork.m Fri Sep 30 22:33:28 2011 -0400
+++ b/project_files/HedgewarsMobile/Classes/EngineProtocolNetwork.m Sun Oct 02 00:57:04 2011 +0200
@@ -20,10 +20,9 @@
#import "EngineProtocolNetwork.h"
-#import "PascalImports.h"
-#import "CommodityFunctions.h"
#import "OverlayViewController.h"
+
#define BUFFER_SIZE 255 // like in original frontend
@implementation EngineProtocolNetwork
--- a/project_files/HedgewarsMobile/Classes/FlagsViewController.m Fri Sep 30 22:33:28 2011 -0400
+++ b/project_files/HedgewarsMobile/Classes/FlagsViewController.m Sun Oct 02 00:57:04 2011 +0200
@@ -21,7 +21,7 @@
#import "FlagsViewController.h"
#import <QuartzCore/QuartzCore.h>
-#import "CommodityFunctions.h"
+
@implementation FlagsViewController
@synthesize teamDictionary, flagArray, communityArray, lastIndexPath;
--- a/project_files/HedgewarsMobile/Classes/FortsViewController.m Fri Sep 30 22:33:28 2011 -0400
+++ b/project_files/HedgewarsMobile/Classes/FortsViewController.m Sun Oct 02 00:57:04 2011 +0200
@@ -20,8 +20,7 @@
#import "FortsViewController.h"
-#import "CommodityFunctions.h"
-#import "UIImageExtra.h"
+
#define IMGNUM_PER_FORT 6
--- a/project_files/HedgewarsMobile/Classes/GameConfigViewController.m Fri Sep 30 22:33:28 2011 -0400
+++ b/project_files/HedgewarsMobile/Classes/GameConfigViewController.m Sun Oct 02 00:57:04 2011 +0200
@@ -25,9 +25,7 @@
#import "SchemeWeaponConfigViewController.h"
#import "HelpPageViewController.h"
#import "GameInterfaceBridge.h"
-#import "CommodityFunctions.h"
-#import "UIImageExtra.h"
-#import "PascalImports.h"
+
@implementation GameConfigViewController
@synthesize imgContainer, helpPage, mapConfigViewController, teamConfigViewController, schemeWeaponConfigViewController, interfaceBridge;
@@ -279,29 +277,39 @@
self.view.frame = CGRectMake(0, 0, screen.size.height, screen.size.width);
if (IS_IPAD()) {
- // load other controllers
+ // load other controllers and the background
if (self.mapConfigViewController == nil)
self.mapConfigViewController = [[MapConfigViewController alloc] initWithNibName:@"MapConfigViewController-iPad" bundle:nil];
- UILabel *leftBackground = createLabelWithParams(nil, CGRectMake(0, 60, 320, 620), 2.7f, UICOLOR_HW_YELLOW_BODER, UICOLOR_HW_ALPHABLUE);
- [self.mapConfigViewController.view addSubview:leftBackground];
- [leftBackground release];
- UILabel *middleBackground = createLabelWithParams(nil, CGRectMake(337, 187, 350, 505), 2.7f, UICOLOR_HW_YELLOW_BODER, UICOLOR_HW_ALPHABLUE);
- [self.mapConfigViewController.view addSubview:middleBackground];
- [middleBackground release];
- UILabel *rightBackground = createLabelWithParams(nil, CGRectMake(704, 214, 320, 464), 2.7f, UICOLOR_HW_YELLOW_BODER, UICOLOR_HW_ALPHABLUE);
- [self.mapConfigViewController.view addSubview:rightBackground];
- [rightBackground release];
- UILabel *topBackground = createLabelWithParams(nil, CGRectMake(714, 14, 300, 190), 2.3f, UICOLOR_HW_YELLOW_BODER, UICOLOR_HW_ALPHABLUE);
- [self.mapConfigViewController.view addSubview:topBackground];
- [topBackground release];
- UILabel *bottomLeftBackground = createLabelWithParams(nil, CGRectMake(106, 714, 320, 40), 2.0f, UICOLOR_HW_YELLOW_BODER, UICOLOR_HW_ALPHABLUE);
- [self.mapConfigViewController.view addSubview:bottomLeftBackground];
- [bottomLeftBackground release];
- UILabel *bottomRightBackground = createLabelWithParams(NSLocalizedString(@"Max Hogs: ",@""), CGRectMake(594, 714, 320, 40), 2.0f, UICOLOR_HW_YELLOW_BODER, UICOLOR_HW_ALPHABLUE);
- bottomRightBackground.font = [UIFont italicSystemFontOfSize:[UIFont labelFontSize]];
- [self.mapConfigViewController.view addSubview:bottomRightBackground];
- [bottomRightBackground release];
+ UILabel *theLabel;
+ // left column
+ theLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 60, 320, 620) andTitle:nil withBorderWidth:2.7f];
+ [self.mapConfigViewController.view addSubview:theLabel];
+ releaseAndNil(theLabel);
+ // center column
+ theLabel = [[UILabel alloc] initWithFrame:CGRectMake(337, 187, 350, 505) andTitle:nil withBorderWidth:2.7f];
+ [self.mapConfigViewController.view addSubview:theLabel];
+ releaseAndNil(theLabel);
+ // right column
+ theLabel = [[UILabel alloc] initWithFrame:CGRectMake(704, 214, 320, 464) andTitle:nil withBorderWidth:2.7f];
+ [self.mapConfigViewController.view addSubview:theLabel];
+ releaseAndNil(theLabel);
+ // top right column (map)
+ theLabel = [[UILabel alloc] initWithFrame:CGRectMake(714, 14, 300, 190) andTitle:nil withBorderWidth:2.3f];
+ [self.mapConfigViewController.view addSubview:theLabel];
+ releaseAndNil(theLabel);
+ // bottom left
+ theLabel = [[UILabel alloc] initWithFrame:CGRectMake(106, 714, 320, 40) andTitle:nil withBorderWidth:2.0f];
+ [self.mapConfigViewController.view addSubview:theLabel];
+ releaseAndNil(theLabel);
+ // bottom right
+ theLabel = [[UILabel alloc] initWithFrame:CGRectMake(594, 714, 320, 40)
+ andTitle:NSLocalizedString(@"Max Hogs: ",@"")
+ withBorderWidth:2.0f];
+ theLabel.font = [UIFont italicSystemFontOfSize:[UIFont labelFontSize]];
+ [self.mapConfigViewController.view addSubview:theLabel];
+ releaseAndNil(theLabel);
+
[self.mapConfigViewController.view bringSubviewToFront:self.mapConfigViewController.maxLabel];
[self.mapConfigViewController.view bringSubviewToFront:self.mapConfigViewController.sizeLabel];
[self.mapConfigViewController.view bringSubviewToFront:self.mapConfigViewController.segmentedControl];
--- a/project_files/HedgewarsMobile/Classes/GameInterfaceBridge.m Fri Sep 30 22:33:28 2011 -0400
+++ b/project_files/HedgewarsMobile/Classes/GameInterfaceBridge.m Sun Oct 02 00:57:04 2011 +0200
@@ -20,7 +20,7 @@
#import "GameInterfaceBridge.h"
-#import "PascalImports.h"
+#import "ServerSetup.h"
#import "EngineProtocolNetwork.h"
#import "OverlayViewController.h"
#import "StatsPageViewController.h"
@@ -32,7 +32,7 @@
-(id) initWithController:(id) viewController {
if (self = [super init]) {
- self.ipcPort = randomPort();
+ self.ipcPort = [ServerSetup randomPort];
self.gameType = gtNone;
self.savePath = nil;
@@ -79,11 +79,11 @@
height = (int) screenBounds.size.width;
}
- NSString *horizontalSize = [[NSString alloc] initWithFormat:@"%d", width * (int)getScreenScale()];
- NSString *verticalSize = [[NSString alloc] initWithFormat:@"%d", height * (int)getScreenScale()];
+ NSString *horizontalSize = [[NSString alloc] initWithFormat:@"%d", width * (int)[[UIScreen mainScreen] scale]];
+ NSString *verticalSize = [[NSString alloc] initWithFormat:@"%d", height * (int)[[UIScreen mainScreen] scale]];
NSString *rotation = [[NSString alloc] initWithString:@"0"];
- NSString *modelId = getModelType();
+ NSString *modelId = [HWUtils modelType];
NSInteger tmpQuality;
if ([modelId hasPrefix:@"iPhone1"] || [modelId hasPrefix:@"iPod1,1"] || [modelId hasPrefix:@"iPod2,1"]) // = iPhone and iPhone 3G or iPod Touch or iPod Touch 2G
tmpQuality = 0x00000001 | 0x00000002 | 0x00000008 | 0x00000040; // rqLowRes | rqBlurryLand | rqSimpleRope | rqKillFlakes
@@ -121,7 +121,7 @@
[localeString release];
[ipcString release];
- objcExportsInit();
+ [ObjcExports initialize];
// this is the pascal fuction that starts the game, wrapped around isInGame
[HedgewarsAppDelegate sharedAppDelegate].isInGame = YES;
--- a/project_files/HedgewarsMobile/Classes/GeneralSettingsViewController.m Fri Sep 30 22:33:28 2011 -0400
+++ b/project_files/HedgewarsMobile/Classes/GeneralSettingsViewController.m Sun Oct 02 00:57:04 2011 +0200
@@ -20,7 +20,6 @@
#import "GeneralSettingsViewController.h"
-#import "CommodityFunctions.h"
@implementation GeneralSettingsViewController
--- a/project_files/HedgewarsMobile/Classes/GravesViewController.m Fri Sep 30 22:33:28 2011 -0400
+++ b/project_files/HedgewarsMobile/Classes/GravesViewController.m Sun Oct 02 00:57:04 2011 +0200
@@ -20,8 +20,7 @@
#import "GravesViewController.h"
-#import "CommodityFunctions.h"
-#import "UIImageExtra.h"
+
@implementation GravesViewController
@synthesize teamDictionary, graveArray, lastIndexPath;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/HedgewarsMobile/Classes/HWUtils.h Sun Oct 02 00:57:04 2011 +0200
@@ -0,0 +1,60 @@
+/*
+ * Hedgewars-iOS, a Hedgewars port for iOS devices
+ * Copyright (c) 2009-2010 Vittorio Giovara <vittorio.giovara@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * File created on 01/10/2011.
+ */
+
+
+#import <Foundation/Foundation.h>
+
+@interface HWUtils : NSObject {
+
+}
+
++(NSString *)modelType;
++(NSArray *)teamColors;
+
+@end
+
+
+@interface UIColor (extra)
+
++(UIColor *)darkYellowColor;
++(UIColor *)lightYellowColor;
++(UIColor *)darkBlueColor;
++(UIColor *)darkBlueColorTransparent;
++(UIColor *)blackColorTransparent;
+
+@end
+
+
+@interface UILabel (extra)
+
+-(UILabel *)initWithFrame:(CGRect)frame andTitle:(NSString *)title;
+-(UILabel *)initWithFrame:(CGRect)frame andTitle:(NSString *)title withBorderWidth:(CGFloat) borderWidth;
+-(UILabel *)initWithFrame:(CGRect)frame andTitle:(NSString *)title withBorderWidth:(CGFloat) borderWidth
+ withBorderColor:(UIColor *)borderColor withBackgroundColor:(UIColor *)backColor;
+
+@end
+
+
+@interface NSString (extra)
+
+-(NSString *)MD5hash;
+
+@end
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/HedgewarsMobile/Classes/HWUtils.m Sun Oct 02 00:57:04 2011 +0200
@@ -0,0 +1,144 @@
+/*
+ * Hedgewars-iOS, a Hedgewars port for iOS devices
+ * Copyright (c) 2009-2010 Vittorio Giovara <vittorio.giovara@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * File created on 01/10/2011.
+ */
+
+
+#import "HWUtils.h"
+#import <sys/types.h>
+#import <sys/sysctl.h>
+#import <QuartzCore/QuartzCore.h>
+#import <CommonCrypto/CommonDigest.h>
+#import "PascalImports.h"
+#import "hwconsts.h"
+
+@implementation HWUtils
+
++(NSString *)modelType {
+ size_t size;
+ // set 'oldp' parameter to NULL to get the size of the data returned so we can allocate appropriate amount of space
+ sysctlbyname("hw.machine", NULL, &size, NULL, 0);
+ char *name = (char *)malloc(sizeof(char) * size);
+ // get the platform name
+ sysctlbyname("hw.machine", name, &size, NULL, 0);
+ NSString *modelId = [NSString stringWithUTF8String:name];
+ free(name);
+
+ return modelId;
+}
+
++(NSArray *)teamColors {
+ // by default colors are ARGB but we do computation over RGB, hence we have to "& 0x00FFFFFF" before processing
+ unsigned int colors[] = HW_TEAMCOLOR_ARRAY;
+ NSMutableArray *array = [[NSMutableArray alloc] init];
+
+ int i = 0;
+ while(colors[i] != 0)
+ [array addObject:[NSNumber numberWithUnsignedInt:(colors[i++] & 0x00FFFFFF)]];
+
+ NSArray *final = [NSArray arrayWithArray:array];
+ [array release];
+ return final;
+}
+
+@end
+
+
+@implementation UIColor (extra)
+
++(UIColor *)darkYellowColor {
+ return [UIColor colorWithRed:(CGFloat)0xFE/255 green:(CGFloat)0xC0/255 blue:0 alpha:1];
+}
+
++(UIColor *)lightYellowColor {
+ return [UIColor colorWithRed:(CGFloat)0xF0/255 green:(CGFloat)0xD0/255 blue:0 alpha:1];
+}
+
++(UIColor *)darkBlueColor {
+ return [UIColor colorWithRed:(CGFloat)0x0F/255 green:0 blue:(CGFloat)0x42/255 alpha:1];
+}
+
++(UIColor *)darkBlueColorTransparent {
+ return [UIColor colorWithRed:(CGFloat)0x0F/255 green:0 blue:(CGFloat)0x42/255 alpha:0.58f];
+}
+
++(UIColor *)blackColorTransparent {
+ if (IS_NOT_POWERFUL([HWUtils modelType]))
+ return [UIColor blackColor];
+ else
+ return [UIColor colorWithRed:0 green:0 blue:0 alpha:0.6];
+}
+
+@end
+
+
+@implementation UILabel (extra)
+
+-(UILabel *)initWithFrame:(CGRect)frame andTitle:(NSString *)title {
+ return [self initWithFrame:frame
+ andTitle:title
+ withBorderWidth:1.5f
+ withBorderColor:[UIColor darkYellowColor]
+ withBackgroundColor:[UIColor darkBlueColor]];
+}
+
+-(UILabel *)initWithFrame:(CGRect)frame andTitle:(NSString *)title withBorderWidth:(CGFloat) borderWidth {
+ return [self initWithFrame:frame
+ andTitle:title
+ withBorderWidth:borderWidth
+ withBorderColor:[UIColor darkYellowColor]
+ withBackgroundColor:[UIColor darkBlueColor]];
+}
+
+-(UILabel *)initWithFrame:(CGRect)frame andTitle:(NSString *)title withBorderWidth:(CGFloat) borderWidth
+ withBorderColor:(UIColor *)borderColor withBackgroundColor:(UIColor *)backColor{
+ UILabel *theLabel = [self initWithFrame:frame];
+ theLabel.backgroundColor = backColor;
+
+ if (title != nil) {
+ theLabel.text = title;
+ theLabel.textColor = [UIColor lightYellowColor];
+ theLabel.textAlignment = UITextAlignmentCenter;
+ theLabel.font = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]*80/100];
+ }
+
+ [theLabel.layer setBorderWidth:borderWidth];
+ [theLabel.layer setBorderColor:borderColor.CGColor];
+ [theLabel.layer setCornerRadius:8.0f];
+ [theLabel.layer setMasksToBounds:YES];
+
+ return theLabel;
+}
+
+@end
+
+
+@implementation NSString (extra)
+
+-(NSString *)MD5hash {
+ const char *cStr = [self UTF8String];
+ unsigned char result[16];
+ CC_MD5( cStr, strlen(cStr), result );
+ return [NSString stringWithFormat:
+ @"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
+ result[0], result[1], result[2], result[3], result[4], result[5],
+ result[6], result[7], result[8], result[9], result[10], result[11],
+ result[12], result[13], result[14], result[15]];
+}
+
+@end
--- a/project_files/HedgewarsMobile/Classes/HedgewarsAppDelegate.m Fri Sep 30 22:33:28 2011 -0400
+++ b/project_files/HedgewarsMobile/Classes/HedgewarsAppDelegate.m Sun Oct 02 00:57:04 2011 +0200
@@ -20,10 +20,8 @@
#import "HedgewarsAppDelegate.h"
-#import "PascalImports.h"
+#import "MainMenuViewController.h"
#import "ObjcExports.h"
-#import "CommodityFunctions.h"
-#import "MainMenuViewController.h"
#include <unistd.h>
@@ -97,7 +95,6 @@
[AudioManagerController cleanupMemory];
MSG_MEMCLEAN();
}
- print_free_memory();
// don't clean mainMenuViewController here!!!
}
--- a/project_files/HedgewarsMobile/Classes/HelpPageViewController.m Fri Sep 30 22:33:28 2011 -0400
+++ b/project_files/HedgewarsMobile/Classes/HelpPageViewController.m Sun Oct 02 00:57:04 2011 +0200
@@ -20,7 +20,7 @@
#import "HelpPageViewController.h"
-#import "CommodityFunctions.h"
+
@implementation HelpPageViewController
@synthesize scrollView;
--- a/project_files/HedgewarsMobile/Classes/HogHatViewController.m Fri Sep 30 22:33:28 2011 -0400
+++ b/project_files/HedgewarsMobile/Classes/HogHatViewController.m Sun Oct 02 00:57:04 2011 +0200
@@ -20,8 +20,7 @@
#import "HogHatViewController.h"
-#import "CommodityFunctions.h"
-#import "UIImageExtra.h"
+
@implementation HogHatViewController
@synthesize teamDictionary, hatArray, normalHogSprite, lastIndexPath, selectedHog;
--- a/project_files/HedgewarsMobile/Classes/InGameMenuViewController.m Fri Sep 30 22:33:28 2011 -0400
+++ b/project_files/HedgewarsMobile/Classes/InGameMenuViewController.m Sun Oct 02 00:57:04 2011 +0200
@@ -20,11 +20,9 @@
#import "InGameMenuViewController.h"
-#import "PascalImports.h"
-#import "CommodityFunctions.h"
#import "SDL_sysvideo.h"
#import "SDL_uikitkeyboard.h"
-#import "OpenGLES/ES1/gl.h"
+
#define VIEW_HEIGHT 200
--- a/project_files/HedgewarsMobile/Classes/LevelViewController.m Fri Sep 30 22:33:28 2011 -0400
+++ b/project_files/HedgewarsMobile/Classes/LevelViewController.m Sun Oct 02 00:57:04 2011 +0200
@@ -20,7 +20,6 @@
#import "LevelViewController.h"
-#import "CommodityFunctions.h"
@implementation LevelViewController
--- a/project_files/HedgewarsMobile/Classes/MapConfigViewController.m Fri Sep 30 22:33:28 2011 -0400
+++ b/project_files/HedgewarsMobile/Classes/MapConfigViewController.m Sun Oct 02 00:57:04 2011 +0200
@@ -20,12 +20,10 @@
#import "MapConfigViewController.h"
-#import "PascalImports.h"
-#import "CommodityFunctions.h"
-#import "UIImageExtra.h"
#import "SchemeWeaponConfigViewController.h"
#import "GameConfigViewController.h"
+
#define scIndex self.segmentedControl.selectedSegmentIndex
#define isRandomness() (segmentedControl.selectedSegmentIndex == 0 || segmentedControl.selectedSegmentIndex == 2)
@@ -74,7 +72,7 @@
// perform as if user clicked on an entry
[self tableView:self.tableView didSelectRowAtIndexPath:theIndex];
- if (IS_NOT_POWERFUL(getModelType()) == NO)
+ if (IS_NOT_POWERFUL([HWUtils modelType]) == NO)
[self.tableView scrollToRowAtIndexPath:theIndex atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
}
@@ -138,7 +136,7 @@
cell.textLabel.text = labelString;
cell.textLabel.adjustsFontSizeToFitWidth = YES;
cell.textLabel.minimumFontSize = 7;
- cell.textLabel.textColor = UICOLOR_HW_YELLOW_TEXT;
+ cell.textLabel.textColor = [UIColor lightYellowColor];
cell.textLabel.backgroundColor = [UIColor clearColor];
if (isRandomness()) {
@@ -155,7 +153,7 @@
} else
cell.accessoryView = nil;
- cell.backgroundColor = UICOLOR_HW_ALMOSTBLACK;
+ cell.backgroundColor = [UIColor blackColorTransparent];
return cell;
}
@@ -378,7 +376,7 @@
#pragma mark -
#pragma mark view management
-(void) loadDataSourceArray {
- NSString *model = getModelType();
+ NSString *model = [HWUtils modelType];
// only folders containing icon.png are a valid theme
NSArray *themeArrayFull = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:THEMES_DIRECTORY() error:NULL];
@@ -394,7 +392,7 @@
NSArray *mapArrayFull = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:MAPS_DIRECTORY() error:NULL];
NSMutableArray *mapArray = [[NSMutableArray alloc] init];
for (NSString *str in mapArrayFull) {
- CGSize imgSize = PSPNGSizeFromMetaData([MAPS_DIRECTORY() stringByAppendingFormat:@"%@/map.png",str]);
+ CGSize imgSize = [UIImage imageSizeFromMetadataOf:[MAPS_DIRECTORY() stringByAppendingFormat:@"%@/map.png",str]];
if (IS_NOT_POWERFUL(model) && imgSize.height > 1024.0f)
continue;
if (IS_NOT_VERY_POWERFUL(model) && imgSize.height > 1280.0f)
@@ -405,7 +403,7 @@
NSArray *missionArrayFull = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:MISSIONS_DIRECTORY() error:NULL];
NSMutableArray *missionArray = [[NSMutableArray alloc] init];
for (NSString *str in missionArrayFull) {
- CGSize imgSize = PSPNGSizeFromMetaData([MISSIONS_DIRECTORY() stringByAppendingFormat:@"%@/map.png",str]);
+ CGSize imgSize = [UIImage imageSizeFromMetadataOf:[MISSIONS_DIRECTORY() stringByAppendingFormat:@"%@/map.png",str]];
if (IS_NOT_POWERFUL(model) && imgSize.height > 1024.0f)
continue;
if (IS_NOT_VERY_POWERFUL(model) && imgSize.height > 1280.0f)
@@ -454,7 +452,7 @@
if ([self.tableView respondsToSelector:@selector(setBackgroundView:)])
[self.tableView setBackgroundView:nil];
self.tableView.backgroundColor = [UIColor clearColor];
- self.tableView.separatorColor = UICOLOR_HW_YELLOW_BODER;
+ self.tableView.separatorColor = [UIColor darkYellowColor];
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
}
--- a/project_files/HedgewarsMobile/Classes/MapPreviewButtonView.m Fri Sep 30 22:33:28 2011 -0400
+++ b/project_files/HedgewarsMobile/Classes/MapPreviewButtonView.m Sun Oct 02 00:57:04 2011 +0200
@@ -22,6 +22,7 @@
#import "MapPreviewButtonView.h"
#import "MapConfigViewController.h"
#import "UIImageExtra.h"
+#import "ServerSetup.h"
#import <pthread.h>
#define INDICATOR_TAG 7654
@@ -78,7 +79,7 @@
IPaddress ip;
BOOL serverQuit = NO;
static uint8_t map[128*32];
- int port = randomPort();
+ int port = [ServerSetup randomPort];
if (SDLNet_Init() < 0) {
DLog(@"SDLNet_Init: %s", SDLNet_GetError());
@@ -197,7 +198,7 @@
[self setTitle:nil forState:UIControlStateNormal];
// don't display preview on slower device, too slow and memory hog
- if (IS_NOT_POWERFUL(getModelType())) {
+ if (IS_NOT_POWERFUL([HWUtils modelType])) {
[self setTitle:NSLocalizedString(@"Preview not available",@"") forState:UIControlStateNormal];
[self turnOnWidgets];
} else {
--- a/project_files/HedgewarsMobile/Classes/ObjcExports.h Fri Sep 30 22:33:28 2011 -0400
+++ b/project_files/HedgewarsMobile/Classes/ObjcExports.h Sun Oct 02 00:57:04 2011 +0200
@@ -19,7 +19,15 @@
*/
-void objcExportsInit(void);
+@interface ObjcExports : NSObject {
+
+}
+
++(void) initialize;
+
+@end
+
+
BOOL isGameRunning(void);
void setGameRunning(BOOL value);
NSInteger cachedGrenadeTime(void);
--- a/project_files/HedgewarsMobile/Classes/ObjcExports.m Fri Sep 30 22:33:28 2011 -0400
+++ b/project_files/HedgewarsMobile/Classes/ObjcExports.m Sun Oct 02 00:57:04 2011 +0200
@@ -23,27 +23,29 @@
#import "OverlayViewController.h"
#import "AmmoMenuViewController.h"
-#pragma mark -
-#pragma mark internal variables
+
// actual game started (controls should be enabled)
-BOOL gameRunning;
+static BOOL gameRunning;
// black screen present
-BOOL savedGame;
+static BOOL savedGame;
// cache the grenade time
-NSInteger grenadeTime;
+static NSInteger grenadeTime;
// the reference to the newMenu instance
-OverlayViewController *overlay_instance;
+static OverlayViewController *overlay_instance;
+@implementation ObjcExports
-#pragma mark -
-#pragma mark functions called like oop
-void objcExportsInit() {
++(void) initialize {
overlay_instance = [OverlayViewController mainOverlay];
gameRunning = NO;
savedGame = NO;
grenadeTime = 2;
}
+@end
+
+#pragma mark -
+#pragma mark functions called by objc code
BOOL inline isGameRunning() {
return gameRunning;
}
--- a/project_files/HedgewarsMobile/Classes/OverlayViewController.m Fri Sep 30 22:33:28 2011 -0400
+++ b/project_files/HedgewarsMobile/Classes/OverlayViewController.m Sun Oct 02 00:57:04 2011 +0200
@@ -23,11 +23,10 @@
#import "InGameMenuViewController.h"
#import "HelpPageViewController.h"
#import "AmmoMenuViewController.h"
-#import "PascalImports.h"
-#import "CommodityFunctions.h"
#import "CGPointUtils.h"
#import "ObjcExports.h"
+
#define HIDING_TIME_DEFAULT [NSDate dateWithTimeIntervalSinceNow:2.7]
#define HIDING_TIME_NEVER [NSDate dateWithTimeIntervalSinceNow:10000]
#define doDim() [dimTimer setFireDate: (IS_DUALHEAD()) ? HIDING_TIME_NEVER : HIDING_TIME_DEFAULT]
--- a/project_files/HedgewarsMobile/Classes/SavedGamesViewController.m Fri Sep 30 22:33:28 2011 -0400
+++ b/project_files/HedgewarsMobile/Classes/SavedGamesViewController.m Sun Oct 02 00:57:04 2011 +0200
@@ -21,7 +21,7 @@
#import "SavedGamesViewController.h"
#import "GameInterfaceBridge.h"
-#import "CommodityFunctions.h"
+
@implementation SavedGamesViewController
@synthesize tableView, listOfSavegames, interfaceBridge, numberOfItems;
--- a/project_files/HedgewarsMobile/Classes/SchemeWeaponConfigViewController.m Fri Sep 30 22:33:28 2011 -0400
+++ b/project_files/HedgewarsMobile/Classes/SchemeWeaponConfigViewController.m Sun Oct 02 00:57:04 2011 +0200
@@ -20,7 +20,7 @@
#import "SchemeWeaponConfigViewController.h"
-#import "CommodityFunctions.h"
+
#define LABEL_TAG 57423
@@ -59,7 +59,7 @@
self.view.backgroundColor = [UIColor blackColor];
}
- self.tableView.separatorColor = UICOLOR_HW_YELLOW_BODER;
+ self.tableView.separatorColor = [UIColor darkYellowColor];
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
}
@@ -154,8 +154,8 @@
}
}
- cell.backgroundColor = UICOLOR_HW_ALMOSTBLACK;
- cell.textLabel.textColor = UICOLOR_HW_YELLOW_TEXT;
+ cell.backgroundColor = [UIColor blackColorTransparent];
+ cell.textLabel.textColor = [UIColor lightYellowColor];
cell.detailTextLabel.textColor = [UIColor whiteColor];
cell.textLabel.adjustsFontSizeToFitWidth = YES;
cell.detailTextLabel.adjustsFontSizeToFitWidth = YES;
@@ -294,7 +294,8 @@
self.tableView.scrollEnabled = NO;
CGRect frame = CGRectMake(0, 0, self.view.frame.size.width * 80/100, 60);
- UILabel *theLabel = createBlueLabel(NSLocalizedString(@"Missions don't need further configuration",@""), frame);
+ UILabel *theLabel = [[UILabel alloc] initWithFrame:frame
+ andTitle:NSLocalizedString(@"Missions don't need further configuration",@"")];
theLabel.center = CGPointMake(self.view.frame.size.width/2, self.view.frame.size.height/2);
theLabel.numberOfLines = 2;
theLabel.tag = LABEL_TAG;
--- a/project_files/HedgewarsMobile/Classes/ServerSetup.h Fri Sep 30 22:33:28 2011 -0400
+++ b/project_files/HedgewarsMobile/Classes/ServerSetup.h Sun Oct 02 00:57:04 2011 +0200
@@ -28,6 +28,9 @@
TCPsocket sd; // External socket descriptor
}
++(NSInteger) randomPort;
++(BOOL) isNetworkReachable;
+
@property (nonatomic, retain) NSDictionary *systemSettings;
@end
--- a/project_files/HedgewarsMobile/Classes/ServerSetup.m Fri Sep 30 22:33:28 2011 -0400
+++ b/project_files/HedgewarsMobile/Classes/ServerSetup.m Sun Oct 02 00:57:04 2011 +0200
@@ -20,8 +20,9 @@
#import "ServerSetup.h"
-#import "PascalImports.h"
-#import "CommodityFunctions.h"
+#import <netinet/in.h>
+#import <SystemConfiguration/SCNetworkReachability.h>
+
#import "hwconsts.h"
#define BUFFER_SIZE 256
@@ -29,6 +30,47 @@
@implementation ServerSetup
@synthesize systemSettings;
+
++(NSInteger) randomPort {
+ srandom(time(NULL));
+ NSInteger res = (random() % 64511) + 1024;
+ return (res == NETGAME_DEFAULT_PORT) ? [ServerSetup randomPort] : res;
+}
+
++(BOOL) isNetworkReachable {
+ // Create zero addy
+ struct sockaddr_in zeroAddress;
+ bzero(&zeroAddress, sizeof(zeroAddress));
+ zeroAddress.sin_len = sizeof(zeroAddress);
+ zeroAddress.sin_family = AF_INET;
+
+ // Recover reachability flags
+ SCNetworkReachabilityRef defaultRouteReachability = SCNetworkReachabilityCreateWithAddress(NULL, (struct sockaddr *)&zeroAddress);
+ SCNetworkReachabilityFlags flags;
+
+ BOOL didRetrieveFlags = SCNetworkReachabilityGetFlags(defaultRouteReachability, &flags);
+ CFRelease(defaultRouteReachability);
+
+ if (!didRetrieveFlags) {
+ NSLog(@"Error. Could not recover network reachability flags");
+ return NO;
+ }
+
+ BOOL isReachable = flags & kSCNetworkFlagsReachable;
+ BOOL needsConnection = flags & kSCNetworkFlagsConnectionRequired;
+ BOOL nonWiFi = flags & kSCNetworkReachabilityFlagsTransientConnection;
+
+ NSURL *testURL = [NSURL URLWithString:@"http://www.apple.com/"];
+ NSURLRequest *testRequest = [NSURLRequest requestWithURL:testURL
+ cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
+ timeoutInterval:20.0];
+ NSURLConnection *testConnection = [[NSURLConnection alloc] initWithRequest:testRequest delegate:nil];
+ BOOL testResult = testConnection ? YES : NO;
+ [testConnection release];
+
+ return ((isReachable && !needsConnection) || nonWiFi) ? testResult : NO;
+}
+
-(id) init {
if (self = [super init]) {
self.systemSettings = nil; //nsuserdefault
--- a/project_files/HedgewarsMobile/Classes/SettingsContainerViewController.m Fri Sep 30 22:33:28 2011 -0400
+++ b/project_files/HedgewarsMobile/Classes/SettingsContainerViewController.m Sun Oct 02 00:57:04 2011 +0200
@@ -21,7 +21,7 @@
#import "SettingsContainerViewController.h"
#import "SettingsBaseViewController.h"
-#import "CommodityFunctions.h"
+
@implementation SettingsContainerViewController
@synthesize baseController, activeController, splitViewRootController;
--- a/project_files/HedgewarsMobile/Classes/SingleSchemeViewController.m Fri Sep 30 22:33:28 2011 -0400
+++ b/project_files/HedgewarsMobile/Classes/SingleSchemeViewController.m Sun Oct 02 00:57:04 2011 +0200
@@ -21,8 +21,7 @@
#import "SingleSchemeViewController.h"
#import <QuartzCore/QuartzCore.h>
-#import "CommodityFunctions.h"
-#import "UIImageExtra.h"
+
#define LABEL_TAG 12345
#define SLIDER_TAG 54321
--- a/project_files/HedgewarsMobile/Classes/SingleTeamViewController.m Fri Sep 30 22:33:28 2011 -0400
+++ b/project_files/HedgewarsMobile/Classes/SingleTeamViewController.m Sun Oct 02 00:57:04 2011 +0200
@@ -27,9 +27,7 @@
#import "FortsViewController.h"
#import "FlagsViewController.h"
#import "LevelViewController.h"
-#import "CommodityFunctions.h"
-#import "UIImageExtra.h"
-#import "PascalImports.h"
+
#define TEAMNAME_TAG 78789
--- a/project_files/HedgewarsMobile/Classes/SingleWeaponViewController.m Fri Sep 30 22:33:28 2011 -0400
+++ b/project_files/HedgewarsMobile/Classes/SingleWeaponViewController.m Sun Oct 02 00:57:04 2011 +0200
@@ -20,9 +20,7 @@
#import "SingleWeaponViewController.h"
-#import "CommodityFunctions.h"
-#import "UIImageExtra.h"
-#import "PascalImports.h"
+
@implementation SingleWeaponViewController
@synthesize weaponName, description, ammoStoreImage;
@@ -165,10 +163,10 @@
weaponCell.delegate = self;
}
- int size = 32 * getScreenScale();
- int corners = 8 * getScreenScale();
- int x = ((row*size)/(int)(self.ammoStoreImage.size.height*getScreenScale()))*size;
- int y = (row*size)%(int)(self.ammoStoreImage.size.height*getScreenScale());
+ int size = 32 * [[UIScreen mainScreen] scale];
+ int corners = 8 * [[UIScreen mainScreen] scale];
+ int x = ((row*size)/(int)(self.ammoStoreImage.size.height * [[UIScreen mainScreen] scale]))*size;
+ int y = (row*size)%(int)(self.ammoStoreImage.size.height * [[UIScreen mainScreen] scale]);
UIImage *img = [[self.ammoStoreImage cutAt:CGRectMake(x, y, size, size)] makeRoundCornersOfSize:CGSizeMake(corners, corners)];
weaponCell.weaponIcon.image = img;
--- a/project_files/HedgewarsMobile/Classes/SquareButtonView.m Fri Sep 30 22:33:28 2011 -0400
+++ b/project_files/HedgewarsMobile/Classes/SquareButtonView.m Sun Oct 02 00:57:04 2011 +0200
@@ -21,8 +21,7 @@
#import "SquareButtonView.h"
#import <QuartzCore/QuartzCore.h>
-#import "CommodityFunctions.h"
-#import "UIImageExtra.h"
+
@implementation SquareButtonView
@synthesize colorArray, selectedColor, ownerDictionary;
@@ -32,7 +31,7 @@
colorIndex = -1;
selectedColor = 0;
- self.colorArray = getAvailableColors();
+ self.colorArray = [HWUtils teamColors];
// set the color to the first available one
[self nextColor];
@@ -41,7 +40,7 @@
[self.layer setCornerRadius:7.0f];
[self.layer setMasksToBounds:YES];
[self.layer setBorderWidth:2];
- [self.layer setBorderColor:[UICOLOR_HW_YELLOW_BODER CGColor]];
+ [self.layer setBorderColor:[[UIColor darkYellowColor] CGColor]];
// this changes the color at button press
[self addTarget:self action:@selector(nextColor) forControlEvents:UIControlEventTouchUpInside];
@@ -67,7 +66,7 @@
-(void) selectColor:(NSUInteger) color {
if (color != selectedColor) {
selectedColor = color;
- colorIndex = [colorArray indexOfObject:[NSNumber numberWithUnsignedInt:color]];
+ colorIndex = [self.colorArray indexOfObject:[NSNumber numberWithUnsignedInt:color]];
self.backgroundColor = [UIColor colorWithRed:((color & 0x00FF0000) >> 16)/255.0f
green:((color & 0x0000FF00) >> 8)/255.0f
--- a/project_files/HedgewarsMobile/Classes/StatsPageViewController.m Fri Sep 30 22:33:28 2011 -0400
+++ b/project_files/HedgewarsMobile/Classes/StatsPageViewController.m Sun Oct 02 00:57:04 2011 +0200
@@ -20,7 +20,6 @@
#import "StatsPageViewController.h"
-#import "CommodityFunctions.h"
#import <QuartzCore/QuartzCore.h>
@implementation StatsPageViewController
@@ -49,7 +48,7 @@
} else
self.view.backgroundColor = [UIColor blackColor];
- self.tableView.separatorColor = UICOLOR_HW_YELLOW_BODER;
+ self.tableView.separatorColor = [UIColor darkYellowColor];
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
[super viewDidLoad];
@@ -85,7 +84,7 @@
imgName = @"star";
imgPath = [[NSBundle mainBundle] resourcePath];
cell.textLabel.text = [self.statsArray objectAtIndex:1];
- cell.textLabel.textColor = UICOLOR_HW_YELLOW_TEXT;
+ cell.textLabel.textColor = [UIColor lightYellowColor];
} else if (section == 1) { // teams ranking
// color, # kills, teamname
NSArray *info = [[[self.statsArray objectAtIndex:0] objectAtIndex:row] componentsSeparatedByString:@" "];
@@ -99,7 +98,7 @@
} else if (section == 2) { // general info
imgName = @"iconDamage";
cell.textLabel.text = [self.statsArray objectAtIndex:row + 2];
- cell.textLabel.textColor = UICOLOR_HW_YELLOW_TEXT;
+ cell.textLabel.textColor = [UIColor lightYellowColor];
}
NSString *imgString = [[NSString alloc] initWithFormat:@"%@/%@.png",imgPath,imgName];
@@ -155,9 +154,9 @@
[button setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted];
button.titleLabel.font = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]];
- button.backgroundColor = UICOLOR_HW_ALMOSTBLACK;
+ button.backgroundColor = [UIColor blackColorTransparent];
[button.layer setBorderWidth:1];
- [button.layer setBorderColor:UICOLOR_HW_YELLOW_BODER.CGColor];
+ [button.layer setBorderColor:[[UIColor darkYellowColor] CGColor]];
[button.layer setCornerRadius:9.0f];
[button.layer setMasksToBounds:YES];
[button addTarget:self action:@selector(dismissView) forControlEvents:UIControlEventTouchUpInside];
--- a/project_files/HedgewarsMobile/Classes/SupportViewController.m Fri Sep 30 22:33:28 2011 -0400
+++ b/project_files/HedgewarsMobile/Classes/SupportViewController.m Sun Oct 02 00:57:04 2011 +0200
@@ -20,7 +20,7 @@
#import "SupportViewController.h"
-#import "CommodityFunctions.h"
+
@implementation SupportViewController
@synthesize waysToSupport;
--- a/project_files/HedgewarsMobile/Classes/TeamConfigViewController.m Fri Sep 30 22:33:28 2011 -0400
+++ b/project_files/HedgewarsMobile/Classes/TeamConfigViewController.m Sun Oct 02 00:57:04 2011 +0200
@@ -20,9 +20,9 @@
#import "TeamConfigViewController.h"
-#import "CommodityFunctions.h"
#import "SquareButtonView.h"
+
@implementation TeamConfigViewController
@synthesize listOfTeams, listOfSelectedTeams, cachedContentsOfDir;
@@ -47,7 +47,7 @@
} else
self.view.backgroundColor = [UIColor blackColor];
- self.tableView.separatorColor = UICOLOR_HW_YELLOW_BODER;
+ self.tableView.separatorColor = [UIColor darkYellowColor];
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
}
@@ -57,7 +57,7 @@
NSArray *contentsOfDir = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:TEAMS_DIRECTORY() error:NULL];
// avoid overwriting selected teams when returning on this view
if ([self.cachedContentsOfDir isEqualToArray:contentsOfDir] == NO) {
- NSArray *colors = getAvailableColors();
+ NSArray *colors = [HWUtils teamColors];
NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:[contentsOfDir count]];
for (int i = 0; i < [contentsOfDir count]; i++) {
NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
@@ -105,7 +105,7 @@
NSString *imgString = [[NSString alloc] initWithFormat:@"%@/hedgehog.png",[[NSBundle mainBundle] resourcePath]];
UIImage *hogSprite = [[UIImage alloc] initWithContentsOfFile:imgString];
[imgString release];
- CGFloat screenScale = getScreenScale();
+ CGFloat screenScale = [[UIScreen mainScreen] scale];
int w = hogSprite.size.width * screenScale;
int h = hogSprite.size.height * screenScale;
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
@@ -120,11 +120,7 @@
CGImageRef imageRef = CGBitmapContextCreateImage(context);
// Create a new UIImage object
- UIImage *resultImage;
- if ([self respondsToSelector:@selector(imageWithCGImage:scale:orientation:)])
- resultImage = [UIImage imageWithCGImage:imageRef scale:screenScale orientation:UIImageOrientationUp];
- else
- resultImage = [UIImage imageWithCGImage:imageRef];
+ UIImage *resultImage = [UIImage imageWithCGImage:imageRef scale:screenScale orientation:UIImageOrientationUp];
// Release colorspace, context and bitmap information
CGColorSpaceRelease(colorSpace);
@@ -199,8 +195,8 @@
cell.accessoryView = nil;
}
- cell.textLabel.textColor = UICOLOR_HW_YELLOW_TEXT;
- cell.backgroundColor = UICOLOR_HW_ALMOSTBLACK;
+ cell.textLabel.textColor = [UIColor lightYellowColor];
+ cell.backgroundColor = [UIColor blackColorTransparent];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
@@ -212,12 +208,8 @@
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
CGRect frame = CGRectMake(0, 0, self.view.frame.size.width * 80/100, 30);
- NSString *text;
- if (section == 0)
- text = NSLocalizedString(@"Playing Teams",@"");
- else
- text = NSLocalizedString(@"Available Teams",@"");
- UILabel *theLabel = createBlueLabel(text, frame);
+ NSString *text = (section == 0) ? NSLocalizedString(@"Playing Teams",@"") : NSLocalizedString(@"Available Teams",@"");
+ UILabel *theLabel = [[UILabel alloc] initWithFrame:frame andTitle:text];
theLabel.center = CGPointMake(self.view.frame.size.width/2, 20);
UIView *theView = [[[UIView alloc] init] autorelease];
--- a/project_files/HedgewarsMobile/Classes/UIImageExtra.h Fri Sep 30 22:33:28 2011 -0400
+++ b/project_files/HedgewarsMobile/Classes/UIImageExtra.h Sun Oct 02 00:57:04 2011 +0200
@@ -24,7 +24,8 @@
@interface UIImage (extra)
-CGFloat getScreenScale(void);
++(UIImage *)whiteImage:(CGSize) ofSize;
++(CGSize) imageSizeFromMetadataOf:(NSString *)aFileName;
-(UIImage *)scaleToSize:(CGSize) size;
-(UIImage *)mergeWith:(UIImage *)secondImage atPoint:(CGPoint) secondImagePoint;
@@ -34,6 +35,5 @@
-(UIImage *)convertToNegative;
-(UIImage *)maskImageWith:(UIImage *)maskImage;
-(UIImage *)makeRoundCornersOfSize:(CGSize) sizewh;
-+(UIImage *)whiteImage:(CGSize) ofSize;
@end
--- a/project_files/HedgewarsMobile/Classes/UIImageExtra.m Fri Sep 30 22:33:28 2011 -0400
+++ b/project_files/HedgewarsMobile/Classes/UIImageExtra.m Sun Oct 02 00:57:04 2011 +0200
@@ -24,21 +24,11 @@
@implementation UIImage (extra)
-CGFloat getScreenScale(void) {
- float scale = 1.0f;
- if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)])
- scale = [[UIScreen mainScreen] scale];
- return scale;
-}
-
-(UIImage *)scaleToSize:(CGSize) size {
DLog(@"warning - this is a very expensive operation, you should avoid using it");
// Create a bitmap graphics context; this will also set it as the current context
- if (UIGraphicsBeginImageContextWithOptions != NULL)
- UIGraphicsBeginImageContextWithOptions(size, NO, getScreenScale());
- else
- UIGraphicsBeginImageContext(size);
+ UIGraphicsBeginImageContextWithOptions(size, NO, [[UIScreen mainScreen] scale]);
// Draw the scaled image in the current context
[self drawInRect:CGRectMake(0, 0, size.width, size.height)];
@@ -58,7 +48,7 @@
DLog(@"Warning, secondImage == nil");
return self;
}
- CGFloat screenScale = getScreenScale();
+ CGFloat screenScale = [[UIScreen mainScreen] scale];
int w = self.size.width * screenScale;
int h = self.size.height * screenScale;
@@ -79,11 +69,7 @@
CGImageRef imageRef = CGBitmapContextCreateImage(context);
// Create a new UIImage object
- UIImage *resultImage;
- if ([self respondsToSelector:@selector(imageWithCGImage:scale:orientation:)])
- resultImage = [UIImage imageWithCGImage:imageRef scale:screenScale orientation:UIImageOrientationUp];
- else
- resultImage = [UIImage imageWithCGImage:imageRef];
+ UIImage *resultImage = [UIImage imageWithCGImage:imageRef scale:screenScale orientation:UIImageOrientationUp];
// Release colorspace, context and bitmap information
CGColorSpaceRelease(colorSpace);
@@ -203,7 +189,7 @@
-(UIImage *)makeRoundCornersOfSize:(CGSize) sizewh {
CGFloat cornerWidth = sizewh.width;
CGFloat cornerHeight = sizewh.height;
- CGFloat screenScale = getScreenScale();
+ CGFloat screenScale = [[UIScreen mainScreen] scale];
CGFloat w = self.size.width * screenScale;
CGFloat h = self.size.height * screenScale;
@@ -222,11 +208,7 @@
CGContextRelease(context);
CGColorSpaceRelease(colorSpace);
- UIImage *newImage;
- if ([self respondsToSelector:@selector(imageWithCGImage:scale:orientation:)])
- newImage = [UIImage imageWithCGImage:imageMasked scale:screenScale orientation:UIImageOrientationUp];
- else
- newImage = [UIImage imageWithCGImage:imageMasked];
+ UIImage *newImage = [UIImage imageWithCGImage:imageMasked scale:screenScale orientation:UIImageOrientationUp];
CGImageRelease(imageMasked);
@@ -268,4 +250,48 @@
return bkgImg;
}
+// this routine checks for the PNG size without loading it in memory
+// https://github.com/steipete/PSFramework/blob/master/PSFramework%20Version%200.3/PhotoshopFramework/PSMetaDataFunctions.m
++(CGSize) imageSizeFromMetadataOf:(NSString *)aFileName {
+ // File Name to C String.
+ const char *fileName = [aFileName UTF8String];
+ // source file
+ FILE *infile = fopen(fileName, "rb");
+ if (infile == NULL) {
+ DLog(@"Can't open the file: %@", aFileName);
+ return CGSizeZero;
+ }
+
+ // Bytes Buffer.
+ unsigned char buffer[30];
+ // Grab Only First Bytes.
+ fread(buffer, 1, 30, infile);
+ // Close File.
+ fclose(infile);
+
+ // PNG Signature.
+ unsigned char png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
+
+ // Compare File signature.
+ if ((int)(memcmp(&buffer[0], &png_signature[0], 8))) {
+ DLog(@"The file (%@) is not a PNG file", aFileName);
+ return CGSizeZero;
+ }
+
+ // Calc Sizes. Isolate only four bytes of each size (width, height).
+ int width[4];
+ int height[4];
+ for (int d = 16; d < (16 + 4); d++) {
+ width[d-16] = buffer[d];
+ height[d-16] = buffer[d+4];
+ }
+
+ // Convert bytes to Long (Integer)
+ long resultWidth = (width[0] << (int)24) | (width[1] << (int)16) | (width[2] << (int)8) | width[3];
+ long resultHeight = (height[0] << (int)24) | (height[1] << (int)16) | (height[2] << (int)8) | height[3];
+
+ // Return Size.
+ return CGSizeMake(resultWidth,resultHeight);
+}
+
@end
--- a/project_files/HedgewarsMobile/Classes/VoicesViewController.m Fri Sep 30 22:33:28 2011 -0400
+++ b/project_files/HedgewarsMobile/Classes/VoicesViewController.m Sun Oct 02 00:57:04 2011 +0200
@@ -20,7 +20,7 @@
#import "VoicesViewController.h"
-#import "CommodityFunctions.h"
+
@implementation VoicesViewController
@synthesize teamDictionary, voiceArray, lastIndexPath;
--- a/project_files/HedgewarsMobile/Classes/WeaponCellView.m Fri Sep 30 22:33:28 2011 -0400
+++ b/project_files/HedgewarsMobile/Classes/WeaponCellView.m Sun Oct 02 00:57:04 2011 +0200
@@ -20,7 +20,7 @@
#import "WeaponCellView.h"
-#import "CommodityFunctions.h"
+
@implementation WeaponCellView
@synthesize delegate, weaponName, weaponIcon, initialSli, probabilitySli, delaySli, crateSli, helpLabel,
--- a/project_files/HedgewarsMobile/Hedgewars.xcodeproj/project.pbxproj Fri Sep 30 22:33:28 2011 -0400
+++ b/project_files/HedgewarsMobile/Hedgewars.xcodeproj/project.pbxproj Sun Oct 02 00:57:04 2011 +0200
@@ -103,7 +103,7 @@
6165922111CA9BA200D6E256 /* VoicesViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6165920911CA9BA200D6E256 /* VoicesViewController.m */; };
6165922211CA9BA200D6E256 /* WeaponSettingsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6165920B11CA9BA200D6E256 /* WeaponSettingsViewController.m */; };
6165922E11CA9BD500D6E256 /* CGPointUtils.c in Sources */ = {isa = PBXBuildFile; fileRef = 6165922311CA9BD500D6E256 /* CGPointUtils.c */; };
- 6165922F11CA9BD500D6E256 /* CommodityFunctions.m in Sources */ = {isa = PBXBuildFile; fileRef = 6165922611CA9BD500D6E256 /* CommodityFunctions.m */; };
+ 6165922F11CA9BD500D6E256 /* HWUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = 6165922611CA9BD500D6E256 /* HWUtils.m */; };
6165923111CA9BD500D6E256 /* SquareButtonView.m in Sources */ = {isa = PBXBuildFile; fileRef = 6165922B11CA9BD500D6E256 /* SquareButtonView.m */; };
6165923211CA9BD500D6E256 /* UIImageExtra.m in Sources */ = {isa = PBXBuildFile; fileRef = 6165922D11CA9BD500D6E256 /* UIImageExtra.m */; };
6165925311CA9CB400D6E256 /* MainMenuViewController-iPad.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6165924B11CA9CB400D6E256 /* MainMenuViewController-iPad.xib */; };
@@ -392,6 +392,7 @@
615FEAE012A2A6640098EE92 /* localplayButton~iphone.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "localplayButton~iphone.png"; path = "Resources/Frontend/localplayButton~iphone.png"; sourceTree = "<group>"; };
6163EE7C11CC2600001C0453 /* SingleWeaponViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SingleWeaponViewController.h; sourceTree = "<group>"; };
6163EE7D11CC2600001C0453 /* SingleWeaponViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SingleWeaponViewController.m; sourceTree = "<group>"; };
+ 61641FE31437CDAA006E049C /* DefinesAndMacros.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DefinesAndMacros.h; path = Classes/DefinesAndMacros.h; sourceTree = "<group>"; };
616591E011CA9BA200D6E256 /* FlagsViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FlagsViewController.h; sourceTree = "<group>"; };
616591E111CA9BA200D6E256 /* FlagsViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FlagsViewController.m; sourceTree = "<group>"; };
616591E211CA9BA200D6E256 /* FortsViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FortsViewController.h; sourceTree = "<group>"; };
@@ -438,8 +439,8 @@
6165920B11CA9BA200D6E256 /* WeaponSettingsViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WeaponSettingsViewController.m; sourceTree = "<group>"; };
6165922311CA9BD500D6E256 /* CGPointUtils.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = CGPointUtils.c; path = Classes/CGPointUtils.c; sourceTree = "<group>"; };
6165922411CA9BD500D6E256 /* CGPointUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CGPointUtils.h; path = Classes/CGPointUtils.h; sourceTree = "<group>"; };
- 6165922511CA9BD500D6E256 /* CommodityFunctions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CommodityFunctions.h; path = Classes/CommodityFunctions.h; sourceTree = "<group>"; };
- 6165922611CA9BD500D6E256 /* CommodityFunctions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CommodityFunctions.m; path = Classes/CommodityFunctions.m; sourceTree = "<group>"; };
+ 6165922511CA9BD500D6E256 /* HWUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = HWUtils.h; path = Classes/HWUtils.h; sourceTree = "<group>"; };
+ 6165922611CA9BD500D6E256 /* HWUtils.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = HWUtils.m; path = Classes/HWUtils.m; sourceTree = "<group>"; };
6165922911CA9BD500D6E256 /* PascalImports.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PascalImports.h; path = Classes/PascalImports.h; sourceTree = "<group>"; };
6165922A11CA9BD500D6E256 /* SquareButtonView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SquareButtonView.h; path = Classes/SquareButtonView.h; sourceTree = "<group>"; };
6165922B11CA9BD500D6E256 /* SquareButtonView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SquareButtonView.m; path = Classes/SquareButtonView.m; sourceTree = "<group>"; };
@@ -700,6 +701,7 @@
29B97315FDCFA39411CA2CEA /* Other Sources */ = {
isa = PBXGroup;
children = (
+ 61641FE21437CD8F006E049C /* Headers */,
61DE91561258B76800B80214 /* Custom UIs */,
61AC067212B2E32D000B52A2 /* Appirater.h */,
61AC067312B2E32D000B52A2 /* Appirater.m */,
@@ -707,13 +709,10 @@
61C28D3E142D380400DA16C2 /* AudioManagerController.m */,
6165929C11CA9E2F00D6E256 /* HedgewarsAppDelegate.h */,
6165929D11CA9E2F00D6E256 /* HedgewarsAppDelegate.m */,
- 32CA4F630368D1EE00C91783 /* Hedgewars_Prefix.pch */,
- 61A97F0E136F675A00DD9878 /* hwconsts.h */,
- 6165922911CA9BD500D6E256 /* PascalImports.h */,
61D2059F127CDD1100ABD83E /* ObjcExports.h */,
61D205A0127CDD1100ABD83E /* ObjcExports.m */,
- 6165922511CA9BD500D6E256 /* CommodityFunctions.h */,
- 6165922611CA9BD500D6E256 /* CommodityFunctions.m */,
+ 6165922511CA9BD500D6E256 /* HWUtils.h */,
+ 6165922611CA9BD500D6E256 /* HWUtils.m */,
61006F93128DE31F00EBA7F7 /* CreationChamber.h */,
61006F94128DE31F00EBA7F7 /* CreationChamber.m */,
6165922411CA9BD500D6E256 /* CGPointUtils.h */,
@@ -905,6 +904,17 @@
name = Overlay;
sourceTree = "<group>";
};
+ 61641FE21437CD8F006E049C /* Headers */ = {
+ isa = PBXGroup;
+ children = (
+ 61641FE31437CDAA006E049C /* DefinesAndMacros.h */,
+ 32CA4F630368D1EE00C91783 /* Hedgewars_Prefix.pch */,
+ 61A97F0E136F675A00DD9878 /* hwconsts.h */,
+ 6165922911CA9BD500D6E256 /* PascalImports.h */,
+ );
+ name = Headers;
+ sourceTree = "<group>";
+ };
61798892114AA56300BA94A9 /* inc */ = {
isa = PBXGroup;
children = (
@@ -1555,7 +1565,7 @@
6165922111CA9BA200D6E256 /* VoicesViewController.m in Sources */,
6165922211CA9BA200D6E256 /* WeaponSettingsViewController.m in Sources */,
6165922E11CA9BD500D6E256 /* CGPointUtils.c in Sources */,
- 6165922F11CA9BD500D6E256 /* CommodityFunctions.m in Sources */,
+ 6165922F11CA9BD500D6E256 /* HWUtils.m in Sources */,
6165923111CA9BD500D6E256 /* SquareButtonView.m in Sources */,
6165923211CA9BD500D6E256 /* UIImageExtra.m in Sources */,
6165929E11CA9E2F00D6E256 /* HedgewarsAppDelegate.m in Sources */,
--- a/project_files/HedgewarsMobile/Hedgewars_Prefix.pch Fri Sep 30 22:33:28 2011 -0400
+++ b/project_files/HedgewarsMobile/Hedgewars_Prefix.pch Sun Oct 02 00:57:04 2011 +0200
@@ -14,50 +14,20 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * File created on 25/04/2010.
*/
-// some macros by http://www.cimgf.com/2010/05/02/my-current-prefix-pch-file/
-// and http://blog.coriolis.ch/2009/01/05/macros-for-xcode/
-
#ifdef __OBJC__
#import <Foundation/Foundation.h>
#import <CoreGraphics/CoreGraphics.h>
#import <UIKit/UIKit.h>
#import "PascalImports.h"
#import "UIImageExtra.h"
-#import "CommodityFunctions.h"
+#import "DefinesAndMacros.h"
#import "HedgewarsAppDelegate.h"
#import "AudioManagerController.h"
+#import "HWUtils.h"
#endif
-
-#ifdef DEBUG
- #define DLog(...) NSLog(@"%s %@", __PRETTY_FUNCTION__, [NSString stringWithFormat:__VA_ARGS__])
- #define ALog(...) [[NSAssertionHandler currentHandler] handleFailureInFunction:[NSString stringWithCString:__PRETTY_FUNCTION__ encoding:NSUTF8StringEncoding] file:[NSString stringWithCString:__FILE__ encoding:NSUTF8StringEncoding] lineNumber:__LINE__ description:__VA_ARGS__]
- #define releaseAndNil(x) [x release]
-#else
- #define DLog(...) do { } while (0)
- #ifndef NS_BLOCK_ASSERTIONS
- #define NS_BLOCK_ASSERTIONS
- #endif
- #define ALog(...) NSLog(@"%s %@", __PRETTY_FUNCTION__, [NSString stringWithFormat:__VA_ARGS__])
- #define releaseAndNil(x) [x release], x = nil
-#endif
-
-
-#define ZAssert(condition, ...) do { if (!(condition)) { ALog(__VA_ARGS__); }} while(0)
-#define rotationManager(x) (x == UIInterfaceOrientationLandscapeRight) || (x == UIInterfaceOrientationLandscapeLeft)
-
-#define START_TIMER NSTimeInterval start = [NSDate timeIntervalSinceReferenceDate];
-#define END_TIMER(msg) NSTimeInterval stop = [NSDate timeIntervalSinceReferenceDate]; CMLog([NSString stringWithFormat:@"%@ Time = %f", msg, stop-start]);
-
-
-#if !__IPHONE_3_2
-typedef enum {
- UIUserInterfaceIdiomPhone, // iPhone and iPod touch style UI
- UIUserInterfaceIdiomPad, // iPad style UI
-} UIUserInterfaceIdiom;
-#define UI_USER_INTERFACE_IDIOM() UIUserInterfaceIdiomPhone
-#define UIPopoverController id
-#endif // ifndef __IPHONE_3_2