diff --git a/SpriteBuilder/Resources/LocalizationInAppPurchasesPIDs.plist b/SpriteBuilder/Resources/LocalizationInAppPurchasesPIDs.plist
new file mode 100644
index 000000000..073e9b529
--- /dev/null
+++ b/SpriteBuilder/Resources/LocalizationInAppPurchasesPIDs.plist
@@ -0,0 +1,91 @@
+
+
+
+
+ com.spritebuilder.translationstier1
+ com.spritebuilder.translationstier2
+ com.spritebuilder.translationstier3
+ com.spritebuilder.translationstier4
+ com.spritebuilder.translationstier5
+ com.spritebuilder.translationstier6
+ com.spritebuilder.translationstier7
+ com.spritebuilder.translationstier8
+ com.spritebuilder.translationstier9
+ com.spritebuilder.translationstier10
+ com.spritebuilder.translationstier11
+ com.spritebuilder.translationstier12
+ com.spritebuilder.translationstier13
+ com.spritebuilder.translationstier14
+ com.spritebuilder.translationstier15
+ com.spritebuilder.translationstier16
+ com.spritebuilder.translationstier17
+ com.spritebuilder.translationstier18
+ com.spritebuilder.translationstier19
+ com.spritebuilder.translationstier20
+ com.spritebuilder.translationstier21
+ com.spritebuilder.translationstier22
+ com.spritebuilder.translationstier23
+ com.spritebuilder.translationstier24
+ com.spritebuilder.translationstier25
+ com.spritebuilder.translationstier26
+ com.spritebuilder.translationstier27
+ com.spritebuilder.translationstier28
+ com.spritebuilder.translationstier29
+ com.spritebuilder.translationstier30
+ com.spritebuilder.translationstier31
+ com.spritebuilder.translationstier32
+ com.spritebuilder.translationstier33
+ com.spritebuilder.translationstier34
+ com.spritebuilder.translationstier35
+ com.spritebuilder.translationstier36
+ com.spritebuilder.translationstier37
+ com.spritebuilder.translationstier38
+ com.spritebuilder.translationstier39
+ com.spritebuilder.translationstier40
+ com.spritebuilder.translationstier41
+ com.spritebuilder.translationstier42
+ com.spritebuilder.translationstier43
+ com.spritebuilder.translationstier44
+ com.spritebuilder.translationstier45
+ com.spritebuilder.translationstier46
+ com.spritebuilder.translationstier47
+ com.spritebuilder.translationstier48
+ com.spritebuilder.translationstier49
+ com.spritebuilder.translationstier50
+ com.spritebuilder.translationstier51
+ com.spritebuilder.translationstier52
+ com.spritebuilder.translationstier53
+ com.spritebuilder.translationstier54
+ com.spritebuilder.translationstier55
+ com.spritebuilder.translationstier56
+ com.spritebuilder.translationstier57
+ com.spritebuilder.translationstier58
+ com.spritebuilder.translationstier59
+ com.spritebuilder.translationstier60
+ com.spritebuilder.translationstier61
+ com.spritebuilder.translationstier62
+ com.spritebuilder.translationstier63
+ com.spritebuilder.translationstier64
+ com.spritebuilder.translationstier65
+ com.spritebuilder.translationstier66
+ com.spritebuilder.translationstier67
+ com.spritebuilder.translationstier68
+ com.spritebuilder.translationstier69
+ com.spritebuilder.translationstier70
+ com.spritebuilder.translationstier71
+ com.spritebuilder.translationstier72
+ com.spritebuilder.translationstier73
+ com.spritebuilder.translationstier74
+ com.spritebuilder.translationstier75
+ com.spritebuilder.translationstier76
+ com.spritebuilder.translationstier77
+ com.spritebuilder.translationstier78
+ com.spritebuilder.translationstier79
+ com.spritebuilder.translationstier80
+ com.spritebuilder.translationstier81
+ com.spritebuilder.translationstier82
+ com.spritebuilder.translationstier83
+ com.spritebuilder.translationstier84
+ com.spritebuilder.translationstier85
+
+
diff --git a/SpriteBuilder/SpriteBuilder.xcodeproj/project.pbxproj b/SpriteBuilder/SpriteBuilder.xcodeproj/project.pbxproj
index 2e6f6d248..5a276f7bc 100644
--- a/SpriteBuilder/SpriteBuilder.xcodeproj/project.pbxproj
+++ b/SpriteBuilder/SpriteBuilder.xcodeproj/project.pbxproj
@@ -99,6 +99,14 @@
77E1995D13858DE0006C361B /* TabNewMetalRollover.png in Resources */ = {isa = PBXBuildFile; fileRef = 77E1995113858DE0006C361B /* TabNewMetalRollover.png */; };
77E7D04B138F777A00E8EE67 /* CCBModalSheetController.m in Sources */ = {isa = PBXBuildFile; fileRef = 77E7D04A138F777A00E8EE67 /* CCBModalSheetController.m */; };
77E7D04F138F78F600E8EE67 /* StageSizeWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = 77E7D04E138F78F600E8EE67 /* StageSizeWindow.m */; };
+ 7B300A971990570F00AFF762 /* LocalizationTranslateWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 7BF55302193F8A7500183F09 /* LocalizationTranslateWindow.xib */; };
+ 7B3EF5DB195885F20023C169 /* LocalizationTranslateWindowHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 7B3EF5DA195885F20023C169 /* LocalizationTranslateWindowHandler.m */; };
+ 7B88AD47195A4846001BF73C /* LocalizationEditorTextFieldCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 7B88AD46195A4846001BF73C /* LocalizationEditorTextFieldCell.m */; };
+ 7BD26ED31979C1320003FEF4 /* LocalizationInAppPurchasesPIDs.plist in Resources */ = {isa = PBXBuildFile; fileRef = 7BD26ED21979C1320003FEF4 /* LocalizationInAppPurchasesPIDs.plist */; };
+ 7BD26EF1197E1D640003FEF4 /* TranslationSettings.m in Sources */ = {isa = PBXBuildFile; fileRef = 7BD26EF0197E1D640003FEF4 /* TranslationSettings.m */; };
+ 7BDECCD1196CBA2400F3EB11 /* LocalizationTranslateWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = 7BF55306193F912200183F09 /* LocalizationTranslateWindow.m */; };
+ 7BDECCD4196CBA6100F3EB11 /* StoreKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7BDECCD3196CBA6100F3EB11 /* StoreKit.framework */; };
+ 7BDECCE1197047EE00F3EB11 /* LocalizationTransactionObserver.m in Sources */ = {isa = PBXBuildFile; fileRef = 7BDECCE0197047EE00F3EB11 /* LocalizationTransactionObserver.m */; };
80271CCC1862478D00917BC0 /* InspectorStringSimple.m in Sources */ = {isa = PBXBuildFile; fileRef = 8076F94D18624318003C4153 /* InspectorStringSimple.m */; };
80279C7F183A8EAB005C6050 /* WarningCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 80E97F6318370F400052647D /* WarningCell.m */; };
8045F136183ADA900082BD94 /* seq-visible.png in Resources */ = {isa = PBXBuildFile; fileRef = 8045F12C183AD6D30082BD94 /* seq-visible.png */; };
@@ -1345,6 +1353,19 @@
77E7D04A138F777A00E8EE67 /* CCBModalSheetController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CCBModalSheetController.m; sourceTree = ""; };
77E7D04D138F78F600E8EE67 /* StageSizeWindow.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StageSizeWindow.h; sourceTree = ""; };
77E7D04E138F78F600E8EE67 /* StageSizeWindow.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = StageSizeWindow.m; sourceTree = ""; };
+ 7B3EF5D9195885F20023C169 /* LocalizationTranslateWindowHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LocalizationTranslateWindowHandler.h; sourceTree = ""; };
+ 7B3EF5DA195885F20023C169 /* LocalizationTranslateWindowHandler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LocalizationTranslateWindowHandler.m; sourceTree = ""; };
+ 7B88AD45195A4846001BF73C /* LocalizationEditorTextFieldCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LocalizationEditorTextFieldCell.h; sourceTree = ""; };
+ 7B88AD46195A4846001BF73C /* LocalizationEditorTextFieldCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LocalizationEditorTextFieldCell.m; sourceTree = ""; };
+ 7BD26ED21979C1320003FEF4 /* LocalizationInAppPurchasesPIDs.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = LocalizationInAppPurchasesPIDs.plist; sourceTree = ""; };
+ 7BD26EEF197E1D640003FEF4 /* TranslationSettings.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TranslationSettings.h; sourceTree = ""; };
+ 7BD26EF0197E1D640003FEF4 /* TranslationSettings.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TranslationSettings.m; sourceTree = ""; };
+ 7BDECCD3196CBA6100F3EB11 /* StoreKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = StoreKit.framework; path = System/Library/Frameworks/StoreKit.framework; sourceTree = SDKROOT; };
+ 7BDECCDF197047EE00F3EB11 /* LocalizationTransactionObserver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LocalizationTransactionObserver.h; sourceTree = ""; };
+ 7BDECCE0197047EE00F3EB11 /* LocalizationTransactionObserver.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LocalizationTransactionObserver.m; sourceTree = ""; };
+ 7BF55302193F8A7500183F09 /* LocalizationTranslateWindow.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = LocalizationTranslateWindow.xib; sourceTree = ""; };
+ 7BF55305193F912100183F09 /* LocalizationTranslateWindow.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LocalizationTranslateWindow.h; sourceTree = ""; };
+ 7BF55306193F912200183F09 /* LocalizationTranslateWindow.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LocalizationTranslateWindow.m; sourceTree = ""; };
800C005E1846A40D00544BD2 /* select-scale.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "select-scale.png"; sourceTree = ""; };
800C006F1848178D00544BD2 /* select-crosshair.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "select-crosshair.png"; sourceTree = ""; };
8045F12C183AD6D30082BD94 /* seq-visible.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "seq-visible.png"; sourceTree = ""; };
@@ -2488,6 +2509,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
+ 7BDECCD4196CBA6100F3EB11 /* StoreKit.framework in Frameworks */,
D35E589E18E391DA008571EC /* GLKit.framework in Frameworks */,
80AD79A21863878B00B653B7 /* libPVRTexLib.a in Frameworks */,
B7E1EFDD185F8D3D00C9E6E0 /* WebKit.framework in Frameworks */,
@@ -2790,6 +2812,8 @@
92FFB84E195DEA0300E9C96F /* AndroidPluginInstallerWindow.xib */,
92FFB852195DEA2800E9C96F /* AndroidPluginInstaller.h */,
92FFB853195DEA2800E9C96F /* AndroidPluginInstaller.m */,
+ 7BD26EEF197E1D640003FEF4 /* TranslationSettings.h */,
+ 7BD26EF0197E1D640003FEF4 /* TranslationSettings.m */,
);
name = "Application Settings & Globals";
sourceTree = "";
@@ -3297,6 +3321,7 @@
7789ABC1133AA82000CEFCC7 /* Frameworks */ = {
isa = PBXGroup;
children = (
+ 7BDECCD3196CBA6100F3EB11 /* StoreKit.framework */,
830F4EB019347032002B832D /* OCMock.framework */,
D35E589D18E391DA008571EC /* GLKit.framework */,
D2E0168418D783C900927430 /* AppleScriptKit.framework */,
@@ -3418,6 +3443,7 @@
7789ACEB133AB6A700CEFCC7 /* Resources */ = {
isa = PBXGroup;
children = (
+ 7BD26ED21979C1320003FEF4 /* LocalizationInAppPurchasesPIDs.plist */,
DC0A8D3E18C8C274009A619D /* SpriteKitTextureAtlasToolPath.txt */,
B7AC69DB17A9D9700041B8BD /* defaultTemplates.zip */,
E390C780170A371E003E9E92 /* Generated */,
@@ -3837,6 +3863,13 @@
children = (
B7083DF717B1CBC8006628C7 /* LocalizationEditorHandler.h */,
B7083DF817B1CBC8006628C7 /* LocalizationEditorHandler.m */,
+ 7B3EF5D9195885F20023C169 /* LocalizationTranslateWindowHandler.h */,
+ 7B3EF5DA195885F20023C169 /* LocalizationTranslateWindowHandler.m */,
+ 7BF55302193F8A7500183F09 /* LocalizationTranslateWindow.xib */,
+ 7BF55305193F912100183F09 /* LocalizationTranslateWindow.h */,
+ 7BF55306193F912200183F09 /* LocalizationTranslateWindow.m */,
+ 7BDECCDF197047EE00F3EB11 /* LocalizationTransactionObserver.h */,
+ 7BDECCE0197047EE00F3EB11 /* LocalizationTransactionObserver.m */,
B7083DF217B1C363006628C7 /* LocalizationEditorWindow.xib */,
B7083DF417B1CB88006628C7 /* LocalizationEditorWindow.h */,
B7083DF517B1CB88006628C7 /* LocalizationEditorWindow.m */,
@@ -3849,6 +3882,8 @@
B7083E0317B32623006628C7 /* LocalizationEditorLanguageTableView.m */,
B7083E0517B32DAD006628C7 /* LocalizationEditorTranslationTableView.h */,
B7083E0617B32DAD006628C7 /* LocalizationEditorTranslationTableView.m */,
+ 7B88AD45195A4846001BF73C /* LocalizationEditorTextFieldCell.h */,
+ 7B88AD46195A4846001BF73C /* LocalizationEditorTextFieldCell.m */,
);
name = "Localization Editor";
sourceTree = "";
@@ -6004,6 +6039,7 @@
E3C65128151C7B9000D639C0 /* InspectorBlockCCControl.xib in Resources */,
E34E5D6A153585EC000201FB /* ruler-bg-horizontal.png in Resources */,
E34E5D6B153585EC000201FB /* ruler-bg-vertical.png in Resources */,
+ 7B300A971990570F00AFF762 /* LocalizationTranslateWindow.xib in Resources */,
B7096E2B180CD98E00164A8A /* doc-scene.png in Resources */,
E34E5D6E1535AA78000201FB /* ruler-mark-major.png in Resources */,
E34E5D6F1535AA78000201FB /* ruler-mark-minor.png in Resources */,
@@ -6165,6 +6201,7 @@
B7096E2A180CD98E00164A8A /* doc-particlesystem.png in Resources */,
E334A4DE170CF475001604F7 /* seq-btn-end.png in Resources */,
E334A4DF170CF475001604F7 /* toolbar-bottom-noborder.png in Resources */,
+ 7BD26ED31979C1320003FEF4 /* LocalizationInAppPurchasesPIDs.plist in Resources */,
921EEADB18A5760700D864C2 /* joint-pivot-sel@2x.png in Resources */,
E334A4E6170D0020001604F7 /* debugger-bug.png in Resources */,
E3D839DC171356EC004F6127 /* pngquant in Resources */,
@@ -6545,6 +6582,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
+ 7BDECCD1196CBA2400F3EB11 /* LocalizationTranslateWindow.m in Sources */,
92B792D318C92FEF007DF895 /* CCBPhysicsTwoBodyJoint.m in Sources */,
92B792D218C92FE7007DF895 /* CCBPhysicsSpringJoint.m in Sources */,
9294EC8E18C65EC10059014C /* CCBPhysicsPinJoint.m in Sources */,
@@ -6615,6 +6653,7 @@
E3B4222A14E59F5D004547D6 /* InspectorFlip.m in Sources */,
5BA3DC35192110B90055DD96 /* GuideGridSizeWindow.m in Sources */,
E3B4222F14E5A849004547D6 /* InspectorBlendmode.m in Sources */,
+ 7B88AD47195A4846001BF73C /* LocalizationEditorTextFieldCell.m in Sources */,
E3B4223214E5CF97004547D6 /* NodeInfo.m in Sources */,
E3B4223714E5E6AD004547D6 /* InspectorSeparator.m in Sources */,
83DC65EA18D898D50028EF72 /* SBUserDefaultsKeys.m in Sources */,
@@ -6707,6 +6746,7 @@
E3B7BCA015E3BCFE00CF95EF /* MainToolbarDelegate.m in Sources */,
E3AF6CDB15F0A9BC0048DB2A /* HelpWindow.m in Sources */,
E3AF6CE415F0DBA90048DB2A /* HelpPage.m in Sources */,
+ 7BDECCE1197047EE00F3EB11 /* LocalizationTransactionObserver.m in Sources */,
E3C9CCBB161D0BBF008A3784 /* InspectorCodeConnectionsJS.m in Sources */,
E34039BE1624BF610067C7B8 /* CCBDocumentController.m in Sources */,
581BCFE8162DADE7007DE600 /* CCBSplitHorizontalView.m in Sources */,
@@ -6741,6 +6781,7 @@
B7AC6982179F50850041B8BD /* BFPopoverColorWell.m in Sources */,
B7AC6983179F50850041B8BD /* NSColor+BFColorPickerPopover.m in Sources */,
B7AC6984179F50850041B8BD /* NSColorPanel+BFColorPickerPopover.m in Sources */,
+ 7B3EF5DB195885F20023C169 /* LocalizationTranslateWindowHandler.m in Sources */,
B7AC6985179F50850041B8BD /* NSColorWell+BFColorPickerPopover.m in Sources */,
B7AC6986179F50850041B8BD /* BFColorPickerPopoverView.m in Sources */,
B7AC6987179F50850041B8BD /* BFColorPickerViewController.m in Sources */,
@@ -6777,6 +6818,7 @@
E525FBA4E26414A8E6EBA77C /* PublishCCBOperation.m in Sources */,
E525F2C0B3311DCAEC86C6B0 /* PublishImageOperation.m in Sources */,
E525F3B510C25EE6D73F2C68 /* DateCache.m in Sources */,
+ 7BD26EF1197E1D640003FEF4 /* TranslationSettings.m in Sources */,
E525F4E581031BFDE7E6DC9A /* NSString+Publishing.m in Sources */,
9248BD20199A8BB2009C154F /* SemanticVersioning.m in Sources */,
E525FA5D4791EB730859BF2C /* ProjectSettings+Convenience.m in Sources */,
diff --git a/SpriteBuilder/SpriteBuilder.xcodeproj/xcshareddata/xcschemes/SpriteBuilder.xcscheme b/SpriteBuilder/SpriteBuilder.xcodeproj/xcshareddata/xcschemes/SpriteBuilder.xcscheme
index ef15b1cb9..dc1b5c36f 100644
--- a/SpriteBuilder/SpriteBuilder.xcodeproj/xcshareddata/xcschemes/SpriteBuilder.xcscheme
+++ b/SpriteBuilder/SpriteBuilder.xcodeproj/xcshareddata/xcschemes/SpriteBuilder.xcscheme
@@ -67,6 +67,13 @@
ReferencedContainer = "container:SpriteBuilder.xcodeproj">
+
+
+
+
#import "ProjectSettings.h"
#import "CCNode+NodeInfo.h"
+#import "LocalizationTransactionObserver.h"
#import "PublishingFinishedDelegate.h"
#import "TaskStatusWindow.h"
@@ -299,6 +300,9 @@ enum {
// Physics editor
IBOutlet PhysicsHandler* __weak physicsHandler;
+ // Transaction Observer for Translation Downloads
+ LocalizationTransactionObserver* lto;
+
@private
MainWindow *__weak window;
BOOL _applicationLaunchComplete;
@@ -372,6 +376,8 @@ enum {
// Sequencer
@property (nonatomic, readonly) BOOL playingBack;
+//Transaction Observer for Translation Observer
+@property (nonatomic,strong) LocalizationTransactionObserver* lto;
// Methods
+ (AppDelegate*) appDelegate;
@@ -401,6 +407,7 @@ enum {
- (IBAction) menuSelectBehind:(id)sender;
- (IBAction) menuDeselect:(id)sender;
+- (BOOL) openProject:(NSString*) fileName;
- (void) closeProject;
- (IBAction) performClose:(id)sender;
- (void) removedDocumentWithPath:(NSString*)path;
diff --git a/SpriteBuilder/ccBuilder/AppDelegate.m b/SpriteBuilder/ccBuilder/AppDelegate.m
index a081a6938..b8971452d 100644
--- a/SpriteBuilder/ccBuilder/AppDelegate.m
+++ b/SpriteBuilder/ccBuilder/AppDelegate.m
@@ -131,6 +131,8 @@
#import "AndroidPluginInstallerWindow.h"
#import "AndroidPluginInstaller.h"
#import "UsageManager.h"
+#import "TranslationSettings.h"
+#import "LocalizationEditorWindow.h"
#import "ProjectSettings+Convenience.h"
#import "CCBDocumentDataCreator.h"
#import "CCBPublisherCacheCleaner.h"
@@ -182,6 +184,7 @@ @implementation AppDelegate
@synthesize itemTabView;
@dynamic selectedNodeCanHavePhysics;
@synthesize playingBack;
+@synthesize lto;
@dynamic showJoints;
static AppDelegate* sharedAppDelegate;
@@ -637,6 +640,12 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
[self.window makeKeyWindow];
_applicationLaunchComplete = YES;
+ //Transaction Observer for Translation Downloads
+ lto = [[LocalizationTransactionObserver alloc] init];
+ [[SKPaymentQueue defaultQueue] addTransactionObserver:lto];
+ #ifndef SPRITEBUILDER_PRO
+ [self restartProjectDownloads];
+ #endif
if (delayOpenFiles)
{
[self openFiles:delayOpenFiles];
@@ -2026,7 +2035,19 @@ - (BOOL) openProject:(NSString*) fileName
[cocos2dUpdater updateAndBypassIgnore:NO];
self.window.representedFilename = [fileName stringByDeletingLastPathComponent];
-
+ #ifndef SPRITEBUILDER_PRO
+ if(prjctSettings.isDownloadingTranslations)
+ {
+ TranslationSettings *translationSettings = [TranslationSettings translationSettings];
+ NSMutableArray *projectsDownloadingTranslations = translationSettings.projectsDownloadingTranslations;
+ if(![projectsDownloadingTranslations containsObject:prjctSettings.projectPath])
+ {
+ [projectsDownloadingTranslations addObject:prjctSettings.projectPath];
+ [translationSettings writeTranslationSettings];
+ }
+ [localizationEditorHandler restartTranslationDownload:prjctSettings];
+ }
+ #endif
return YES;
}
@@ -4676,5 +4697,67 @@ - (NSString*)getPathOfMenuItem:(NSMenuItem*)item
return fullpath;
}
-
+#pragma mark restart project translation downloads
+/*
+ * Restarts project downloads
+ */
+- (void)restartProjectDownloads
+{
+ TranslationSettings* translationSettings = [TranslationSettings translationSettings];
+ NSMutableArray *projectsDownloadingTranslations = translationSettings.projectsDownloadingTranslations;
+ [projectsDownloadingTranslations removeAllObjects];
+ [translationSettings.projectsDownloadingTranslations removeAllObjects];
+ [translationSettings writeTranslationSettings];
+ for(NSString *projectPath in projectsDownloadingTranslations)
+ {
+ NSMutableDictionary* projectDict = [NSMutableDictionary dictionaryWithContentsOfFile:projectPath];
+ if(projectDict)
+ {
+
+ ProjectSettings* ps = [[ProjectSettings alloc] initWithSerialization:projectDict];
+ if(ps)
+ {
+ ps.projectPath = projectPath;
+ [ps store];
+ if(ps.isDownloadingTranslations)
+ {
+ NSString* langFile = [[[projectPath stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"SpriteBuilder Resources"] stringByAppendingPathComponent:@"Strings.ccbLang"];
+ if(langFile)
+ {
+ if([ps isEqualTo:self.projectSettings])
+ {
+ [localizationEditorHandler setManagedFile:langFile];
+ [localizationEditorHandler restartTranslationDownload:self.projectSettings];
+ }
+ else
+ {
+ LocalizationEditorHandler* handler = [[LocalizationEditorHandler alloc] init];
+ [handler setManagedFileForBackgroundTranslationDownload:langFile];
+ [handler restartTranslationDownload:ps];
+ }
+
+ }
+ else
+ {
+ NSLog(@"No language file! Project Path: %@", ps.projectPath);
+ }
+ }
+ else
+ {
+ NSLog(@"Restarting a download in a project that isn't currently downloading translations! Project Path: %@", ps.projectPath);
+ }
+ }
+ else
+ {
+ NSAlert* alert = [NSAlert alertWithMessageText:@"Cannot Find Project" defaultButton:@"OK" alternateButton:NULL otherButton:NULL informativeTextWithFormat:@"Could not find the project at %@, which had a pending translation download. If you moved the project, please reopen it and its Language Editor Window and the translation download will begin again. If you deleted it and would like to restart your download, please contact customer support.", projectPath];
+ [alert runModal];
+ }
+ }
+ else
+ {
+ NSAlert* alert = [NSAlert alertWithMessageText:@"Cannot Find Project" defaultButton:@"OK" alternateButton:NULL otherButton:NULL informativeTextWithFormat:@"We cannot find the project at %@, which had a pending translation download. If you moved the project, please reopen it and its Language Editor Window and the translation download will begin again. If you deleted it and would like to restart your download, please contact customer support.", projectPath];
+ [alert runModal];
+ }
+ }
+}
@end
diff --git a/SpriteBuilder/ccBuilder/InspectorString.h b/SpriteBuilder/ccBuilder/InspectorString.h
index 469c9912a..fb2351824 100644
--- a/SpriteBuilder/ccBuilder/InspectorString.h
+++ b/SpriteBuilder/ccBuilder/InspectorString.h
@@ -29,6 +29,8 @@
@property (nonatomic) NSString* text;
@property (nonatomic,assign) BOOL localize;
@property (nonatomic,assign) BOOL hasTranslation;
+@property (strong) IBOutlet NSButton *localizeButton;
+@property (nonatomic,assign) BOOL localizeButtonEnabled;
- (IBAction)pressedEditTranslation:(id)sender;
diff --git a/SpriteBuilder/ccBuilder/InspectorString.m b/SpriteBuilder/ccBuilder/InspectorString.m
index 9f54bf9f3..5989710ad 100644
--- a/SpriteBuilder/ccBuilder/InspectorString.m
+++ b/SpriteBuilder/ccBuilder/InspectorString.m
@@ -27,9 +27,21 @@
#import "AppDelegate.h"
#import "CocosScene.h"
#import "LocalizationEditorHandler.h"
+#import "TranslationSettings.h"
@implementation InspectorString
+- (id)initWithSelection:(CCNode *)s andPropertyName:(NSString *)pn andDisplayName:(NSString *)dn andExtra:(NSString *)e
+{
+
+ self = [super initWithSelection:s andPropertyName:pn andDisplayName:dn andExtra:e];
+ TranslationSettings *translationSettings = [TranslationSettings translationSettings];
+ [translationSettings addObserver:self forKeyPath:@"projectsDownloadingTranslations" options:0 context:nil];
+ self.localizeButtonEnabled = ![AppDelegate appDelegate].projectSettings.isDownloadingTranslations;
+ [[AppDelegate appDelegate].localizationEditorHandler setEdited];
+ return self;
+}
+
- (void) setText:(NSString *)text
{
[[AppDelegate appDelegate] saveUndoStateWillChangeProperty:propertyName];
@@ -87,7 +99,8 @@ - (void) refresh
[self didChangeValueForKey:@"hasTranslation"];
[StringPropertySetter refreshStringProp:propertyName forNode:selection];
- [super refresh];
+ [super refresh];
+ [self.localizeButton setEnabled:self.localizeButtonEnabled];
}
- (IBAction)pressedEditTranslation:(id)sender
@@ -97,4 +110,25 @@ - (IBAction)pressedEditTranslation:(id)sender
[handler createOrEditTranslationForKey:[self text]];
}
+-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
+ ProjectSettings* ps = [AppDelegate appDelegate].projectSettings;
+ if([keyPath isEqualToString:@"projectsDownloadingTranslations"])
+ {
+ if(ps.isDownloadingTranslations)
+ {
+ self.localizeButtonEnabled = NO;
+ }
+ else
+ {
+ self.localizeButtonEnabled = YES;
+ }
+ [[AppDelegate appDelegate].localizationEditorHandler setEdited];
+ }
+ else
+ {
+ [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
+ }
+
+}
+
@end
diff --git a/SpriteBuilder/ccBuilder/InspectorString.xib b/SpriteBuilder/ccBuilder/InspectorString.xib
index ed3496abf..f67680c06 100644
--- a/SpriteBuilder/ccBuilder/InspectorString.xib
+++ b/SpriteBuilder/ccBuilder/InspectorString.xib
@@ -1,611 +1,91 @@
-
-
-
- 1080
- 12E55
- 3084
- 1187.39
- 626.00
-
-
-
-
-
-
-
- YES
-
-
- view
-
-
-
- 27
-
-
-
- pressedEditTranslation:
-
-
-
- 53
-
-
-
- value: displayName
-
-
-
-
-
- value: displayName
- value
- displayName
- 2
-
-
- 20
-
-
-
- value: text
-
-
-
-
-
- value: text
- value
- text
- 2
-
-
- 28
-
-
-
- delegate
-
-
-
- 29
-
-
-
- value: localize
-
-
-
-
-
- value: localize
- value
- localize
- 2
-
-
- 40
-
-
-
- enabled: localize
-
-
-
-
-
- enabled: localize
- enabled
- localize
- 2
-
-
- 47
-
-
-
- hidden: hasTranslation
-
-
-
-
-
- hidden: hasTranslation
- hidden
- hasTranslation
- 2
-
-
- 50
-
-
-
- hidden2: localize
-
-
-
-
-
- hidden2: localize
- hidden2
- localize
-
- YES
-
- YES
- NSMultipleValuesPlaceholder
- NSNoSelectionPlaceholder
- NSNotApplicablePlaceholder
- NSNullPlaceholder
- NSValueTransformerName
-
-
- YES
-
-
-
-
- NSNegateBoolean
-
-
-
- 2
-
-
- 52
-
-
-
-
- YES
-
- 0
-
- YES
-
-
-
-
-
- -2
-
-
- File's Owner
-
-
- -1
-
-
- First Responder
-
-
- -3
-
-
- Application
-
-
- 1
-
-
- YES
-
-
-
-
-
-
-
-
-
- 2
-
-
- YES
-
-
-
-
-
- 3
-
-
-
-
- 4
-
-
- YES
-
-
-
-
-
- 5
-
-
- YES
-
-
-
-
- 17
-
-
-
-
- 30
-
-
- YES
-
-
-
-
-
- 31
-
-
-
-
- 32
-
-
- YES
-
-
-
-
-
- 33
-
-
-
-
- 36
-
-
- YES
-
-
-
-
-
- 37
-
-
-
-
-
-
- YES
-
- YES
- -1.IBPluginDependency
- -2.IBPluginDependency
- -3.IBPluginDependency
- 1.IBPluginDependency
- 17.IBPluginDependency
- 2.IBPluginDependency
- 3.IBPluginDependency
- 30.IBPluginDependency
- 31.IBPluginDependency
- 32.IBPluginDependency
- 33.IBPluginDependency
- 36.IBPluginDependency
- 37.IBPluginDependency
- 4.IBPluginDependency
- 5.IBPluginDependency
-
-
- YES
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
-
-
-
- YES
-
-
-
-
-
- YES
-
-
-
-
- 53
-
-
-
- YES
-
- InspectorString
- InspectorValue
-
- pressedEditTranslation:
- id
-
-
- pressedEditTranslation:
-
- pressedEditTranslation:
- id
-
-
-
- IBProjectSource
- ./Classes/InspectorString.h
-
-
-
- InspectorValue
- NSObject
-
- view
- NSView
-
-
- view
-
- view
- NSView
-
-
-
- IBProjectSource
- ./Classes/InspectorValue.h
-
-
-
-
- 0
- IBCocoaFramework
-
- com.apple.InterfaceBuilder.CocoaPlugin.InterfaceBuilder3
-
-
- YES
- 3
-
- YES
-
- YES
- NSSwitch
- editor-warning
-
-
- YES
- {15, 15}
- {16, 16}
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ NSNegateBoolean
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/SpriteBuilder/ccBuilder/InspectorText.h b/SpriteBuilder/ccBuilder/InspectorText.h
index bb9ef797c..da23b0a7b 100644
--- a/SpriteBuilder/ccBuilder/InspectorText.h
+++ b/SpriteBuilder/ccBuilder/InspectorText.h
@@ -29,6 +29,8 @@
@property (nonatomic) NSAttributedString* text;
@property (nonatomic,assign) BOOL localize;
@property (nonatomic,assign) BOOL hasTranslation;
+@property (nonatomic,strong) IBOutlet NSButton *localizeButton;
+@property (nonatomic,assign) BOOL localizeButtonEnabled;
- (IBAction)pressedEditTranslation:(id)sender;
diff --git a/SpriteBuilder/ccBuilder/InspectorText.m b/SpriteBuilder/ccBuilder/InspectorText.m
index 3534b4cc0..6eebc1f51 100644
--- a/SpriteBuilder/ccBuilder/InspectorText.m
+++ b/SpriteBuilder/ccBuilder/InspectorText.m
@@ -27,9 +27,22 @@
#import "AppDelegate.h"
#import "CocosScene.h"
#import "LocalizationEditorHandler.h"
+#import "TranslationSettings.h"
@implementation InspectorText
+- (id)initWithSelection:(CCNode *)s andPropertyName:(NSString *)pn andDisplayName:(NSString *)dn andExtra:(NSString *)e
+{
+
+ self = [super initWithSelection:s andPropertyName:pn andDisplayName:dn andExtra:e];
+ TranslationSettings *translationSettings = [TranslationSettings translationSettings];
+ [translationSettings addObserver:self forKeyPath:@"projectsDownloadingTranslations" options:0 context:nil];
+ self.localizeButtonEnabled = ![AppDelegate appDelegate].projectSettings.isDownloadingTranslations;
+ dispatch_async(dispatch_get_main_queue(), ^{
+ [[AppDelegate appDelegate].localizationEditorHandler setEdited];
+ });
+ return self;
+}
- (void) setText:(NSAttributedString *)text
{
[[AppDelegate appDelegate] saveUndoStateWillChangeProperty:propertyName];
@@ -87,7 +100,9 @@ - (void) refresh
[self didChangeValueForKey:@"hasTranslation"];
[StringPropertySetter refreshStringProp:propertyName forNode:selection];
- [super refresh];
+ [super refresh];
+ [self.localizeButton setEnabled:self.localizeButtonEnabled];
+
}
- (IBAction)pressedEditTranslation:(id)sender
@@ -97,4 +112,26 @@ - (IBAction)pressedEditTranslation:(id)sender
[handler createOrEditTranslationForKey:[[self text] string]];
}
+-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
+ ProjectSettings* ps = [AppDelegate appDelegate].projectSettings;
+ if([keyPath isEqualToString:@"projectsDownloadingTranslations"])
+ {
+ if(ps.isDownloadingTranslations)
+ {
+ self.localizeButtonEnabled = NO;
+ }
+ else
+ {
+ self.localizeButtonEnabled = YES;
+ }
+ dispatch_async(dispatch_get_main_queue(), ^{
+ [[AppDelegate appDelegate].localizationEditorHandler setEdited];
+ });
+ }
+ else
+ {
+ [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
+ }
+
+}
@end
diff --git a/SpriteBuilder/ccBuilder/InspectorText.xib b/SpriteBuilder/ccBuilder/InspectorText.xib
index c3a2a1b39..3cb4e90aa 100644
--- a/SpriteBuilder/ccBuilder/InspectorText.xib
+++ b/SpriteBuilder/ccBuilder/InspectorText.xib
@@ -1,787 +1,114 @@
-
-
-
- 1080
- 12E55
- 3084
- 1187.39
- 626.00
-
- com.apple.InterfaceBuilder.CocoaPlugin
- 3084
-
-
- YES
- NSButton
- NSButtonCell
- NSCustomObject
- NSCustomView
- NSImageCell
- NSImageView
- NSScrollView
- NSScroller
- NSTextField
- NSTextFieldCell
- NSTextView
- NSUserDefaultsController
-
-
- YES
- com.apple.InterfaceBuilder.CocoaPlugin
-
-
- PluginDependencyRecalculationVersion
-
-
-
- YES
-
- InspectorText
-
-
- FirstResponder
-
-
- NSApplication
-
-
-
- 268
-
- YES
-
-
- 289
-
- YES
-
- YES
- Apple PDF pasteboard type
- Apple PICT pasteboard type
- Apple PNG pasteboard type
- NSFilenamesPboardType
- NeXT Encapsulated PostScript v1.2 pasteboard type
- NeXT TIFF v4.0 pasteboard type
-
-
- {{166, 6}, {16, 16}}
-
-
-
- _NS:9
- YES
-
- 134217728
- 33554432
-
- NSImage
- editor-warning
-
- _NS:9
- 0
- 0
- 0
- NO
-
- NO
- YES
-
-
-
- 257
- {{185, 6}, {41, 16}}
-
-
-
- _NS:9
- YES
-
- 67108864
- 134479872
- Edit
-
- LucidaGrande
- 9
- 3614
-
- _NS:9
-
- -2038284288
- 129
-
-
- 200
- 25
-
- NO
-
-
-
- 292
- {{5, 7}, {61, 18}}
-
-
-
- _NS:9
- YES
-
- -2080374784
- 268697600
- Localize
-
- _NS:9
-
- 1211912448
- 2
-
- NSImage
- NSSwitch
-
-
- NSSwitch
-
-
-
- 200
- 25
-
- NO
-
-
-
- 258
-
- YES
-
-
- 2304
-
- YES
-
-
- 2322
-
- YES
-
- YES
- Apple HTML pasteboard type
- Apple PDF pasteboard type
- Apple PICT pasteboard type
- Apple PNG pasteboard type
- Apple URL pasteboard type
- CorePasteboardFlavorType 0x6D6F6F76
- NSColor pasteboard type
- NSFilenamesPboardType
- NSStringPboardType
- NeXT Encapsulated PostScript v1.2 pasteboard type
- NeXT RTFD pasteboard type
- NeXT Rich Text Format v1.0 pasteboard type
- NeXT TIFF v4.0 pasteboard type
- NeXT font pasteboard type
- NeXT ruler pasteboard type
- WebURLsWithTitlesPboardType
- public.url
-
-
- {215, 69}
-
-
-
-
-
-
-
-
-
-
-
-
- YES
-
-
- 166
-
-
-
- 215
- 1
-
-
- 67112835
- 0
-
-
- 3
- MQA
-
-
- YES
-
- YES
- NSBackgroundColor
- NSColor
-
-
- YES
-
- 6
- System
- selectedTextBackgroundColor
-
- 3
- MC42NjY2NjY2NjY3AA
-
-
-
- 6
- System
- selectedTextColor
-
- 3
- MAA
-
-
-
-
-
-
- YES
-
- YES
- NSColor
- NSCursor
- NSUnderline
-
-
- YES
-
- 1
- MCAwIDEAA
-
-
- {8, -8}
- 13
-
-
-
-
-
-
- 0
-
- 6
- {463, 10000000}
-
-
-
- {{1, 1}, {215, 69}}
-
-
-
-
-
-
- {4, 5}
-
- 12582912
-
- YES
-
- YES
-
-
-
- TU0AKgAAAHCAFUqgBVKsAAAAwdVQUqwaEQeIRGJRGFlYqwWLQ+JxuOQpVRmEx2RROKwOQyOUQSPyaUym
-SxqWyKXyeYxyZzWbSuJTScRCbz2Nz+gRKhUOfTqeUai0OSxiWTiBQSHSGFquGwekxyAgAAAOAQAAAwAA
-AAEAEAAAAQEAAwAAAAEAEAAAAQIAAwAAAAIACAAIAQMAAwAAAAEABQAAAQYAAwAAAAEAAQAAAREABAAA
-AAEAAAAIARIAAwAAAAEAAQAAARUAAwAAAAEAAgAAARYAAwAAAAEAEAAAARcABAAAAAEAAABnARwAAwAA
-AAEAAQAAAT0AAwAAAAEAAgAAAVIAAwAAAAEAAQAAAVMAAwAAAAIAAQABAAAAAA
-
-
-
-
-
- 3
- MCAwAA
-
-
-
- 4
-
-
-
- -2147483392
- {{205, 1}, {11, 69}}
-
-
-
- NO
- 256
-
- _doScroller:
- 1
- 0.85256409645080566
-
-
-
- -2147483392
- {{-100, -100}, {87, 11}}
-
-
-
- NO
- 257
-
- _doScroller:
- 1
- 0.94565218687057495
-
-
- {{8, 25}, {217, 71}}
-
-
-
- 133650
-
-
-
- 0.25
- 4
- 1
-
-
-
- 268
- {{6, 98}, {76, 14}}
-
-
-
- YES
-
- 68157504
- 4326400
- Fnt File
-
- LucidaGrande
- 11
- 3100
-
-
-
- 6
- System
- controlColor
-
-
-
- 1
- MC4xNzM5MTMwNDM1IDAuMTczOTEzMDQzNSAwLjE3MzkxMzA0MzUAA
-
-
- NO
-
-
- {233, 112}
-
-
-
- NSView
-
-
- YES
-
-
-
-
- YES
-
-
- view
-
-
-
- 27
-
-
-
- pressedEditTranslation:
-
-
-
- 113
-
-
-
- value: displayName
-
-
-
-
-
- value: displayName
- value
- displayName
- 2
-
-
- 68
-
-
-
- attributedString: text
-
-
-
-
-
- attributedString: text
- attributedString
- text
-
- NSContinuouslyUpdatesValue
-
-
- 2
-
-
- 90
-
-
-
- value: localize
-
-
-
-
-
- value: localize
- value
- localize
- 2
-
-
- 112
-
-
-
- enabled: localize
-
-
-
-
-
- enabled: localize
- enabled
- localize
- 2
-
-
- 103
-
-
-
- hidden: hasTranslation
-
-
-
-
-
- hidden: hasTranslation
- hidden
- hasTranslation
- 2
-
-
- 106
-
-
-
- hidden2: localize
-
-
-
-
-
- hidden2: localize
- hidden2
- localize
-
- YES
-
- YES
- NSMultipleValuesPlaceholder
- NSNoSelectionPlaceholder
- NSNotApplicablePlaceholder
- NSNullPlaceholder
- NSValueTransformerName
-
-
- YES
-
-
-
-
- NSNegateBoolean
-
-
-
- 2
-
-
- 109
-
-
-
-
- YES
-
- 0
-
- YES
-
-
-
-
-
- -2
-
-
- File's Owner
-
-
- -1
-
-
- First Responder
-
-
- -3
-
-
- Application
-
-
- 1
-
-
- YES
-
-
-
-
-
-
-
-
-
- 2
-
-
- YES
-
-
-
-
-
- 3
-
-
-
-
- 17
-
-
-
-
- 80
-
-
- YES
-
-
-
-
-
-
-
- 81
-
-
-
-
- 82
-
-
-
-
- 83
-
-
-
-
- 91
-
-
- YES
-
-
-
-
-
- 92
-
-
-
-
- 95
-
-
- YES
-
-
-
-
-
- 96
-
-
-
-
- 99
-
-
- YES
-
-
-
-
-
- 100
-
-
-
-
-
-
- YES
-
- YES
- -1.IBPluginDependency
- -2.IBPluginDependency
- -3.IBPluginDependency
- 1.IBPluginDependency
- 100.IBPluginDependency
- 17.IBPluginDependency
- 2.IBPluginDependency
- 3.IBPluginDependency
- 80.IBPluginDependency
- 81.IBPluginDependency
- 82.IBPluginDependency
- 83.IBPluginDependency
- 91.IBPluginDependency
- 92.IBPluginDependency
- 95.IBPluginDependency
- 96.IBPluginDependency
- 99.IBPluginDependency
-
-
- YES
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
-
-
-
- YES
-
-
-
-
-
- YES
-
-
-
-
- 113
-
-
-
- YES
-
- InspectorText
- InspectorValue
-
- pressedEditTranslation:
- id
-
-
- pressedEditTranslation:
-
- pressedEditTranslation:
- id
-
-
-
- IBProjectSource
- ./Classes/InspectorText.h
-
-
-
- InspectorValue
- NSObject
-
- view
- NSView
-
-
- view
-
- view
- NSView
-
-
-
- IBProjectSource
- ./Classes/InspectorValue.h
-
-
-
-
- 0
- IBCocoaFramework
-
- com.apple.InterfaceBuilder.CocoaPlugin.InterfaceBuilder3
-
-
- YES
- 3
-
- YES
-
- YES
- NSSwitch
- editor-warning
-
-
- YES
- {15, 15}
- {16, 16}
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ NSNegateBoolean
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/SpriteBuilder/ccBuilder/LocalizationCancelTranslationsWindow.h b/SpriteBuilder/ccBuilder/LocalizationCancelTranslationsWindow.h
new file mode 100644
index 000000000..df23026c1
--- /dev/null
+++ b/SpriteBuilder/ccBuilder/LocalizationCancelTranslationsWindow.h
@@ -0,0 +1,23 @@
+//
+// LocalizationCancelTranslationsWindow.h
+// SpriteBuilder
+//
+// Created by Benjamin Koatz on 6/25/14.
+//
+//
+
+#import
+@class LocalizationEditorWindow;
+@class LocalizationTranslateWindow;
+
+@interface LocalizationCancelTranslationsWindow : NSWindowController{
+ LocalizationEditorWindow* _editorWindow;
+ LocalizationTranslateWindow* _translateWindow;
+}
+
+@property (nonatomic,strong) LocalizationTranslateWindow* translateWindow;
+@property (nonatomic,strong) LocalizationEditorWindow* editorWindow;
+- (IBAction)yes:(id)sender;
+- (IBAction)no:(id)sender;
+
+@end
diff --git a/SpriteBuilder/ccBuilder/LocalizationCancelTranslationsWindow.m b/SpriteBuilder/ccBuilder/LocalizationCancelTranslationsWindow.m
new file mode 100644
index 000000000..6e60b364e
--- /dev/null
+++ b/SpriteBuilder/ccBuilder/LocalizationCancelTranslationsWindow.m
@@ -0,0 +1,28 @@
+//
+// LocalizationCancelTranslationsWindow.m
+// SpriteBuilder
+//
+// Created by Benjamin Koatz on 6/25/14.
+//
+//
+
+#import "LocalizationCancelTranslationsWindow.h"
+#import "LocalizationEditorWindow.h"
+#import "LocalizationTranslateWindow.h"
+
+@implementation LocalizationCancelTranslationsWindow
+@synthesize editorWindow = _editorWindow;
+@synthesize translateWindow = _translateWindow;
+
+- (IBAction)yes:(id)sender {
+ [_editorWindow finishDownloadingTranslations];
+ [_translateWindow cancelDownload];
+ [NSApp endSheet:self.window];
+ [self.window orderOut:nil];
+}
+
+- (IBAction)no:(id)sender {
+ [NSApp endSheet:self.window];
+ [self.window orderOut:nil];
+}
+@end
diff --git a/SpriteBuilder/ccBuilder/LocalizationCancelTranslationsWindow.xib b/SpriteBuilder/ccBuilder/LocalizationCancelTranslationsWindow.xib
new file mode 100644
index 000000000..f7589f708
--- /dev/null
+++ b/SpriteBuilder/ccBuilder/LocalizationCancelTranslationsWindow.xib
@@ -0,0 +1,61 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/SpriteBuilder/ccBuilder/LocalizationEditorHandler.h b/SpriteBuilder/ccBuilder/LocalizationEditorHandler.h
index 638269434..3cdf7e706 100644
--- a/SpriteBuilder/ccBuilder/LocalizationEditorHandler.h
+++ b/SpriteBuilder/ccBuilder/LocalizationEditorHandler.h
@@ -12,7 +12,7 @@
@class LocalizationEditorWindow;
@class LocalizationEditorLanguage;
@class LocalizationEditorTranslation;
-
+@class ProjectSettings;
@interface LocalizationEditorHandler : NSObject
{
NSMutableArray* languages;
@@ -29,6 +29,7 @@
@property (nonatomic,readonly) NSMutableArray* languages;
@property (nonatomic,readonly) NSMutableArray* activeLanguages;
@property (nonatomic,readonly) NSMutableArray* translations;
+@property (nonatomic,readonly) LocalizationEditorLanguage* currentLanguage;
@property (nonatomic,readonly) LocalizationEditorWindow* windowController;
@property (nonatomic,copy) NSString* managedFile;
@@ -45,4 +46,9 @@
- (IBAction)openEditor:(id)sender;
- (void) createOrEditTranslationForKey:(NSString*)key;
+//Translation Download
+- (void) setManagedFileForBackgroundTranslationDownload:(NSString*) file;
+- (void) storeFileForBackgroundTranslationDownload;
+
+- (void)restartTranslationDownload:(ProjectSettings *)ps;
@end
diff --git a/SpriteBuilder/ccBuilder/LocalizationEditorHandler.m b/SpriteBuilder/ccBuilder/LocalizationEditorHandler.m
index bc97654ef..d4a4e1c20 100644
--- a/SpriteBuilder/ccBuilder/LocalizationEditorHandler.m
+++ b/SpriteBuilder/ccBuilder/LocalizationEditorHandler.m
@@ -10,13 +10,14 @@
#import "LocalizationEditorWindow.h"
#import "LocalizationEditorLanguage.h"
#import "LocalizationEditorTranslation.h"
-
+#import "ProjectSettings.h"
#import "AppDelegate.h"
#import "CocosScene.h"
#import "StringPropertySetter.h"
@implementation LocalizationEditorHandler
+@synthesize currentLanguage;
@synthesize languages;
@synthesize activeLanguages;
@synthesize translations;
@@ -155,6 +156,82 @@ - (NSString*) managedFile
return managedFile;
}
+/*
+ * Allows background translations downloads to set the managed file, without
+ * using or interfering with currently displayed attributes in the
+ * editor window.
+ */
+- (void) setManagedFileForBackgroundTranslationDownload:(NSString*) file
+{
+ managedFile = [file copy];
+
+ [translations removeAllObjects];
+ [activeLanguages removeAllObjects];
+
+ if (file)
+ {
+ if ([[NSFileManager defaultManager] fileExistsAtPath:managedFile])
+ {
+ NSDictionary* ser = [NSDictionary dictionaryWithContentsOfFile:managedFile];
+
+ // Read data
+
+ // Languages
+ NSArray* serLangs = [ser objectForKey:@"activeLanguages"];
+ for (NSString* isoCode in serLangs)
+ {
+ // Find language for code and add active language
+ LocalizationEditorLanguage* lang = [self getLanguageByIsoLangCode:isoCode];
+ if (lang) [activeLanguages addObject:lang];
+ }
+
+ // Translations
+ NSArray* serTranslations = [ser objectForKey:@"translations"];
+ for (id serTransl in serTranslations)
+ {
+ // Decode a translation and add it
+ LocalizationEditorTranslation* transl = [[LocalizationEditorTranslation alloc] initWithSerialization:serTransl];
+ if (transl) [translations addObject:transl];
+ }
+ }
+ }
+}
+
+/*
+ * Allows background translations downloads to store the managed file, without
+ * using or interfering with currently displayed attributes in the
+ * editor window.
+ */
+- (void) storeFileForBackgroundTranslationDownload
+{
+ if (!managedFile) return;
+
+ NSMutableDictionary* ser = [NSMutableDictionary dictionary];
+
+ // Write header
+ [ser setObject:@"SpriteBuilderTranslations" forKey:@"fileType"];
+ [ser setObject:[NSNumber numberWithInt:kCCBTranslationFileFormatVersion] forKey:@"fileVersion"];
+
+ // Languages
+ NSMutableArray* serLangs = [NSMutableArray array];
+ for (LocalizationEditorLanguage* lang in activeLanguages)
+ {
+ [serLangs addObject:lang.isoLangCode];
+ }
+ [ser setObject:serLangs forKey:@"activeLanguages"];
+
+ // Translations
+ NSMutableArray* serTransls = [NSMutableArray array];
+ for (LocalizationEditorTranslation* transl in translations)
+ {
+ [serTransls addObject:[transl serialization]];
+ }
+ [ser setObject:serTransls forKey:@"translations"];
+
+ // Store
+ [ser writeToFile:managedFile atomically:YES];
+}
+
- (void) setManagedFile:(NSString*) file
{
if (file == managedFile) return;
@@ -279,6 +356,10 @@ - (void) removeActiveLangage:(LocalizationEditorLanguage*) lang
[self setCurrentLanguage:currentLanguage];
}
+/*
+ * In addition to its normal functionality, now sets the 'downloading' state of the window
+ * according to project settings.
+ */
- (IBAction)openEditor:(id)sender
{
if (!windowController)
@@ -299,7 +380,7 @@ - (NSString*) translationForKey:(NSString*)key
if ([transl.key isEqualToString:key])
{
NSString* val = [transl.translations objectForKey:currentLanguage.isoLangCode];
- if (val)
+ if (val && ![val isEqualToString:@""])
{
return val;
}
@@ -346,5 +427,15 @@ - (void) createOrEditTranslationForKey:(NSString*)key
}
}
+/*
+ * Restart translation download
+ */
+- (void)restartTranslationDownload:(ProjectSettings *)ps{
+ if (!windowController)
+ {
+ windowController = [[LocalizationEditorWindow alloc] initWithWindowNibName:@"LocalizationEditorWindow"];
+ }
+ [windowController restartTranslationDownload:ps];
+}
@end
diff --git a/SpriteBuilder/ccBuilder/LocalizationEditorLanguage.h b/SpriteBuilder/ccBuilder/LocalizationEditorLanguage.h
index aa3052501..826afc1d7 100644
--- a/SpriteBuilder/ccBuilder/LocalizationEditorLanguage.h
+++ b/SpriteBuilder/ccBuilder/LocalizationEditorLanguage.h
@@ -8,12 +8,12 @@
#import
-@interface LocalizationEditorLanguage : NSObject
+@interface LocalizationEditorLanguage : NSObject
@property (nonatomic,copy) NSString* isoLangCode;
@property (nonatomic,copy) NSString* name;
@property (nonatomic,readwrite) BOOL quickEdit;
- (id) initWithIsoLangCode:(NSString*)code;
-
++ (NSString*) nameFromCode:(NSString*)code;
@end
diff --git a/SpriteBuilder/ccBuilder/LocalizationEditorLanguage.m b/SpriteBuilder/ccBuilder/LocalizationEditorLanguage.m
index 18e46666b..db9981bc0 100644
--- a/SpriteBuilder/ccBuilder/LocalizationEditorLanguage.m
+++ b/SpriteBuilder/ccBuilder/LocalizationEditorLanguage.m
@@ -42,5 +42,61 @@ - (id) initWithIsoLangCode:(NSString*)code
return self;
}
+/*
+ * Returns the name of a language from the iso code.
+ */
++ (NSString*) nameFromCode:(NSString*)code
+{
+ NSString* name = NULL;
+
+ if ([code isEqualToString:@"vn"])
+ {
+ name = @"Vietnamese";
+ }
+ else if ([code isEqualToString:@"zh-Hans"])
+ {
+ name = @"Simplified Chinese";
+ }
+ else if ([code isEqualToString:@"zh-Hant"])
+ {
+ name = @"Traditional Chinese";
+ }
+ else
+ {
+ NSLocale* enLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en"];
+ name = [enLocale displayNameForKey:NSLocaleLanguageCode value:code];
+ }
+
+ name = [NSString stringWithFormat:@"%@ (%@)", name, code];
+
+ return name;
+}
+
+/*
+ * Implemented in order to allow these languages to populate a mutable dictionary with
+ * the setObject:forKey: method
+ */
+-(id)copyWithZone:(NSZone *)zone{
+ LocalizationEditorLanguage* newLang = [[[self class] allocWithZone:zone] init];
+ newLang->_isoLangCode = _isoLangCode;
+ newLang->_name = _name;
+ newLang->_quickEdit = _quickEdit;
+ return newLang;
+}
+
+/*
+ * The two functions below were reimplemented in order to make comparing languages
+ * easier since we're only going to care if their name is the same.
+ */
+-(BOOL)isEqual:(id)object{
+ if([((LocalizationEditorLanguage *) object).name isEqualToString:self.name]){
+ return YES;
+ }
+ return NO;
+}
+- (NSUInteger)hash
+{
+ return [_name hash];
+}
@end
diff --git a/SpriteBuilder/ccBuilder/LocalizationEditorTextFieldCell.h b/SpriteBuilder/ccBuilder/LocalizationEditorTextFieldCell.h
new file mode 100644
index 000000000..f869c5d71
--- /dev/null
+++ b/SpriteBuilder/ccBuilder/LocalizationEditorTextFieldCell.h
@@ -0,0 +1,16 @@
+//
+// LocalizationEditorTextFieldCell.h
+// SpriteBuilder
+//
+// Created by Benjamin Koatz on 6/24/14.
+//
+//
+
+#import
+#import "CCBTextFieldCell.h"
+
+@interface LocalizationEditorTextFieldCell : CCBTextFieldCell {
+}
+
+
+@end
diff --git a/SpriteBuilder/ccBuilder/LocalizationEditorTextFieldCell.m b/SpriteBuilder/ccBuilder/LocalizationEditorTextFieldCell.m
new file mode 100644
index 000000000..489d23b8e
--- /dev/null
+++ b/SpriteBuilder/ccBuilder/LocalizationEditorTextFieldCell.m
@@ -0,0 +1,25 @@
+//
+// LocalizationEditorTextFieldCell.m
+// SpriteBuilder
+//
+// Created by Benjamin Koatz on 6/24/14.
+//
+//
+
+#import "LocalizationEditorTextFieldCell.h"
+
+@implementation LocalizationEditorTextFieldCell
+
+- (NSRect)titleRectForBounds:(NSRect)theRect {
+ NSRect titleFrame = [super titleRectForBounds:theRect];
+ NSSize titleSize = [[self attributedStringValue] size];
+ titleFrame.origin.y = theRect.origin.y + (theRect.size.height - titleSize.height) / 2.0;
+ return titleFrame;
+}
+
+- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView {
+ NSRect titleRect = [self titleRectForBounds:cellFrame];
+ [[self attributedStringValue] drawInRect:titleRect];
+}
+
+@end
diff --git a/SpriteBuilder/ccBuilder/LocalizationEditorTranslation.h b/SpriteBuilder/ccBuilder/LocalizationEditorTranslation.h
index 34453899b..9590aae41 100644
--- a/SpriteBuilder/ccBuilder/LocalizationEditorTranslation.h
+++ b/SpriteBuilder/ccBuilder/LocalizationEditorTranslation.h
@@ -11,13 +11,14 @@
@interface LocalizationEditorTranslation : NSObject
{
NSMutableDictionary* _translations;
+ NSMutableArray* _languagesDownloading;
}
- (id) initWithSerialization:(id)ser;
@property (nonatomic,copy) NSString* key;
@property (nonatomic,copy) NSString* comment;
-
+@property (nonatomic,strong) NSMutableArray* languagesDownloading;
@property (nonatomic,readonly) NSMutableDictionary* translations;
- (BOOL) hasTranslationsForLanguages:(NSArray*)languages;
diff --git a/SpriteBuilder/ccBuilder/LocalizationEditorTranslation.m b/SpriteBuilder/ccBuilder/LocalizationEditorTranslation.m
index 46bb8f981..a7b015cc1 100644
--- a/SpriteBuilder/ccBuilder/LocalizationEditorTranslation.m
+++ b/SpriteBuilder/ccBuilder/LocalizationEditorTranslation.m
@@ -12,14 +12,14 @@
@implementation LocalizationEditorTranslation
@synthesize translations = _translations;
-
+@synthesize languagesDownloading = _languagesDownloading;
- (id) init
{
self = [super init];
if (!self) return NULL;
_translations = [[NSMutableDictionary alloc] init];
-
+ _languagesDownloading = [[NSMutableArray alloc] init];
return self;
}
@@ -33,7 +33,7 @@ - (id) initWithSerialization:(id)ser
self.key = [dict objectForKey:@"key"];
self.comment = [dict objectForKey:@"comment"];
_translations = [[dict objectForKey:@"translations"] mutableCopy];
-
+ self.languagesDownloading = [[dict objectForKey:@"languagesDownloading"] mutableCopy];
return self;
}
@@ -56,7 +56,7 @@ - (id) serialization
if (self.key) [ser setObject:self.key forKey:@"key"];
if (self.comment) [ser setObject:self.comment forKey:@"comment"];
[ser setObject:self.translations forKey:@"translations"];
-
+ [ser setObject:self.languagesDownloading forKey:@"languagesDownloading"];
return ser;
}
diff --git a/SpriteBuilder/ccBuilder/LocalizationEditorWindow.h b/SpriteBuilder/ccBuilder/LocalizationEditorWindow.h
index 8c4a7c6d2..ace9d335d 100644
--- a/SpriteBuilder/ccBuilder/LocalizationEditorWindow.h
+++ b/SpriteBuilder/ccBuilder/LocalizationEditorWindow.h
@@ -7,18 +7,26 @@
//
#import
+#import
+@class LocalizationTranslateWindow;
+@class ProjectSettings;
@interface LocalizationEditorWindow : NSWindowController
{
IBOutlet NSTableView* tableTranslations;
IBOutlet NSTableView* tableLanguages;
IBOutlet NSPopUpButton* popLanguageAdd;
+ IBOutlet NSButton* _addTranslation;
IBOutlet NSPopUpButton* popCurrentLanguage;
IBOutlet NSTextView* textInspectorKey;
+ IBOutlet NSTextField* _translationProgressText;
+ IBOutlet NSProgressIndicator* _translationProgress;
+ IBOutlet NSButton* _translationsButton;
+ LocalizationTranslateWindow* _ltw;
}
@property (nonatomic,assign) BOOL inspectorEnabled;
-
+@property (nonatomic,strong) LocalizationTranslateWindow* ltw;
@property (nonatomic,copy) NSAttributedString* inspectorTextKey;
@property (nonatomic,copy) NSAttributedString* inspectorTextComment;
@property (nonatomic,copy) NSAttributedString* inspectorTextTranslation;
@@ -27,10 +35,17 @@
- (IBAction)pressedAdd:(id)sender;
- (IBAction)pressedAddGroup:(id)sender;
+- (IBAction)pressedTranslate:(id)sender;
- (IBAction)selectedAddLanguage:(id)sender;
- (void)removeLanguagesAtIndexes:(NSIndexSet*)idxs;
- (IBAction)selectedCurrentLanguage:(id)sender;
+- (void)addLanguages:(NSArray*)langs;
+- (void)setDownloadingTranslations;
+- (void)incrementTransByOne;
+- (double)translationProgress;
+- (void)finishDownloadingTranslations;
+- (void)restartTranslationDownload:(ProjectSettings *)ps;
- (void)removeTranslationsAtIndexes:(NSIndexSet*)idxs;
diff --git a/SpriteBuilder/ccBuilder/LocalizationEditorWindow.m b/SpriteBuilder/ccBuilder/LocalizationEditorWindow.m
index 47900b9e3..82643180f 100644
--- a/SpriteBuilder/ccBuilder/LocalizationEditorWindow.m
+++ b/SpriteBuilder/ccBuilder/LocalizationEditorWindow.m
@@ -6,26 +6,36 @@
//
//
+#import "LocalizationTranslateWindow.h"
#import "LocalizationEditorWindow.h"
#import "LocalizationEditorLanguage.h"
#import "LocalizationEditorHandler.h"
#import "LocalizationEditorTranslation.h"
+#import "LocalizationEditorLanguageTableView.h"
+#import "LocalizationTranslateWindowHandler.h"
#import "AppDelegate.h"
#import "CCBTextFieldCell.h"
#import "NSPasteboard+CCB.h"
+#import "ProjectSettings.h"
+#import "TranslationSettings.h"
@implementation LocalizationEditorWindow
-
-#pragma mark Init and Updating stuff
+@synthesize ltw = _ltw;
- (void) awakeFromNib
{
+ #ifdef SPRITEBUILDER_PRO
+ [_translationsButton setHidden:YES];
+ [_addTranslation setFrame:_translationsButton.frame];
+ #endif
[tableTranslations registerForDraggedTypes:[NSArray arrayWithObject:@"com.cocosbuilder.LocalizationEditorTranslation"]];
[self populateLanguageAddMenu];
[tableLanguages reloadData];
[self updateLanguageSelectionMenu];
[self addLanguageColumns];
[self updateQuickEditLangs];
+ [self addObserver:self forKeyPath:@"hasOpenFile" options:0 context:nil];
+ [_translationProgress setToolTip:[NSString stringWithFormat:@"%.0f/%.0f", _translationProgress.doubleValue, _translationProgress.maxValue]];
}
- (void) populateLanguageAddMenu
@@ -128,8 +138,16 @@ - (void) updateInspector
{
self.inspectorEnabled = YES;
- LocalizationEditorTranslation* translation = [handler.translations objectAtIndex:row];
+ LocalizationEditorTranslation* translation;
+ if(handler.translations.count)
+ {
+ translation = [handler.translations objectAtIndex:row];
+ }
+ else
+ {
+ translation = [[LocalizationEditorTranslation alloc] init];
+ }
if (translation.key)
{
self.inspectorTextKey = [[NSAttributedString alloc] initWithString:translation.key];
@@ -212,6 +230,159 @@ - (IBAction)selectedAddLanguage:(id)sender
[handler setEdited];
}
+/*
+ * If you are opening a new window and one doesn't exist, open it and make it modal. Else
+ * refresh and open.
+ * If you are cancelling a download, show a cancel alert, and if the user 'okays' the cancel,
+ * stop the download.
+ */
+- (IBAction)pressedTranslate:(id)sender {
+
+ if([_translationsButton.title isEqualToString:@"Buy Translations..."])
+ {
+ if(!_ltw || !_ltw.window)
+ {
+ _ltw = [[LocalizationTranslateWindow alloc] initWithWindowNibName:@"LocalizationTranslateWindow"];
+ }
+ else{
+ [_ltw refresh];
+ }
+ [_ltw setParentWindow:self];
+ [_ltw.window makeKeyAndOrderFront:sender];
+ [NSApp runModalForWindow:_ltw.window];
+ }
+ else
+ {
+ NSAlert* alert = [NSAlert alertWithMessageText:@"Stop Download" defaultButton:@"Stop Download" alternateButton:@"Cancel" otherButton:NULL informativeTextWithFormat:@"If you stop your download now, SpriteBuilder will not refund your purchase."];
+ NSArray *buttons = [alert buttons];
+ [(NSButton*)[buttons objectAtIndex:0] setKeyEquivalent:@""];
+ [(NSButton*)[buttons objectAtIndex:1] setKeyEquivalent:@"\r"];
+ NSInteger result = [alert runModal];
+ if(result == NSAlertDefaultReturn)
+ {
+ [self finishDownloadingTranslations];
+ [_ltw cancelDownloadWithError:nil];
+ [tableLanguages reloadData];
+ }
+ }
+}
+
+/*
+ * Add languages to the language table (called when a translation request includes 'translate to' languages
+ * that aren't already in the table.
+ */
+- (void)addLanguages:(NSArray*)langs
+{
+ LocalizationEditorHandler* handler = [AppDelegate appDelegate].localizationEditorHandler;
+ for(NSString* iso in langs)
+ {
+ if([iso isEqualToString:@"zh"])
+ {
+ [handler addActiveLanguage:[handler getLanguageByIsoLangCode:@"zh-Hans"]];
+ }
+ else
+ {
+ [handler addActiveLanguage:[handler getLanguageByIsoLangCode:iso]];
+ }
+ }
+ [tableLanguages reloadData];
+ [self updateLanguageSelectionMenu];
+ [self updateQuickEditLangs];
+ [self updateInspector];
+}
+
+/*
+ * Turn the window into a 'dowloading' one by setting the 'isDownloading' variable in the
+ * project settings and disabling everything except translation progress and the cancel button.
+ */
+
+-(void)setDownloadingTranslations{
+ ProjectSettings* ps = [AppDelegate appDelegate].projectSettings;
+ ps.isDownloadingTranslations = 1;
+ [ps store];
+ TranslationSettings *translationSettings = [TranslationSettings translationSettings];
+ if(![translationSettings.projectsDownloadingTranslations containsObject:ps.projectPath])
+ {
+ [[translationSettings projectsDownloadingTranslations] addObject:ps.projectPath];
+ [translationSettings updateTranslationSettings];
+ }
+ [_translationProgress setMaxValue:ps.numToDownload];
+ [_translationProgress setDoubleValue:ps.numDownloaded];
+ [_translationProgress setHidden:0];
+ [_translationProgressText setHidden:0];
+ [tableTranslations setEnabled:0];
+ [tableLanguages setEnabled:0];
+ [popLanguageAdd setEnabled:0];
+ [_addTranslation setEnabled:0];
+ [popCurrentLanguage setEnabled:0];
+ [_translationsButton setEnabled:1];
+ _translationsButton.title = @"Stop Download";
+ [_translationProgress setToolTip:[NSString stringWithFormat:@"%.0f/%.0f", _translationProgress.doubleValue, _translationProgress.maxValue]];
+}
+
+/*
+ * Make the translation progress bar increase by one
+ */
+-(void)incrementTransByOne{
+ [_translationProgress incrementBy:1.0];
+ [_translationProgress setToolTip:[NSString stringWithFormat:@"%.0f/%.0f", _translationProgress.doubleValue, _translationProgress.maxValue]];
+}
+
+/*
+ * Retrieve translation progress information.
+ */
+- (double)translationProgress{
+ return _translationProgress.doubleValue;
+}
+
+/*
+ * Turn the window into a normal, non-dowloading one by setting the 'isDownloading'
+ * in the project settings to 0 and enabling everything and hiding the translation
+ * progress information.
+ */
+-(void)finishDownloadingTranslations{
+ [_translationProgress setHidden:1];
+ [_translationProgressText setHidden:1];
+ [tableTranslations setEnabled:1];
+ [tableLanguages setEnabled:1];
+ [popLanguageAdd setEnabled:1];
+ [popCurrentLanguage setEnabled:1];
+ [_addTranslation setEnabled:1];
+ [_translationsButton setEnabled:1];
+ _translationsButton.title = @"Buy Translations...";
+ [_translationProgress setToolTip:@""];
+}
+
+/*
+ * For when there is no open file
+ */
+-(void)displayForNoOpenFile{
+
+ [tableTranslations setEnabled:0];
+ [tableLanguages setEnabled:0];
+ [popLanguageAdd setEnabled:0];
+ [popCurrentLanguage setEnabled:0];
+ [_addTranslation setEnabled:0];
+ #ifndef SPRITEBUILDER_PRO
+ [_translationProgress setHidden:1];
+ [_translationProgressText setHidden:1];
+ [_translationsButton setEnabled:0];
+ _translationsButton.title = @"Buy Translations...";
+ [_translationProgress setToolTip:@""];
+ #endif
+}
+
+/*
+ * Used in spritebuilder pro, since there's no support for buying translations yet.
+ */
+-(void)displayForOpenFile{
+ [tableTranslations setEnabled:1];
+ [tableLanguages setEnabled:1];
+ [popLanguageAdd setEnabled:1];
+ [_addTranslation setEnabled:1];
+ [popCurrentLanguage setEnabled:1];
+}
+
- (void)removeLanguagesAtIndexes:(NSIndexSet*)idxs
{
LocalizationEditorHandler* handler = [AppDelegate appDelegate].localizationEditorHandler;
@@ -227,13 +398,16 @@ - (void)removeLanguagesAtIndexes:(NSIndexSet*)idxs
[self updateLanguageSelectionMenu];
[self updateQuickEditLangs];
[self updateInspector];
-
[handler setEdited];
}
- (IBAction)selectedCurrentLanguage:(id)sender
{
[self updateInspector];
+}
+- (void)alertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo {
+
+
}
- (void)removeTranslationsAtIndexes:(NSIndexSet*)idxs
@@ -263,7 +437,15 @@ - (void) setInspectorTextKey:(NSAttributedString *)inspectorTextKey
if (row == -1) return;
- LocalizationEditorTranslation* translation = [handler.translations objectAtIndex:row];
+ LocalizationEditorTranslation* translation;
+ if(handler.translations.count)
+ {
+ translation = [handler.translations objectAtIndex:row];
+ }
+ else
+ {
+ translation = [[LocalizationEditorTranslation alloc] init];
+ }
translation.key = [inspectorTextKey string];
[tableTranslations reloadDataForRowIndexes:[NSIndexSet indexSetWithIndex:row] columnIndexes:[NSIndexSet indexSetWithIndex:1]];
@@ -289,7 +471,15 @@ - (void) setInspectorTextComment:(NSAttributedString *)inspectorTextComment
if (row == -1) return;
- LocalizationEditorTranslation* translation = [handler.translations objectAtIndex:row];
+ LocalizationEditorTranslation* translation;
+ if(handler.translations.count)
+ {
+ translation = [handler.translations objectAtIndex:row];
+ }
+ else
+ {
+ translation = [[LocalizationEditorTranslation alloc] init];
+ }
translation.comment = [inspectorTextComment string];
[tableTranslations reloadDataForRowIndexes:[NSIndexSet indexSetWithIndex:row] columnIndexes:[NSIndexSet indexSetWithIndex:2]];
@@ -302,7 +492,15 @@ - (NSAttributedString*) inspectorTextComment
if (row == -1) return NULL;
- LocalizationEditorTranslation* translation = [handler.translations objectAtIndex:row];
+ LocalizationEditorTranslation* translation;
+ if(handler.translations.count)
+ {
+ translation = [handler.translations objectAtIndex:row];
+ }
+ else
+ {
+ translation = [[LocalizationEditorTranslation alloc] init];
+ }
if (!translation.comment) return NULL;
return [[NSAttributedString alloc] initWithString:translation.comment];
@@ -315,7 +513,15 @@ - (void) setInspectorTextTranslation:(NSAttributedString *)inspectorTextTranslat
if (row == -1) return;
- LocalizationEditorTranslation* translation = [handler.translations objectAtIndex:row];
+ LocalizationEditorTranslation* translation;
+ if(handler.translations.count)
+ {
+ translation = [handler.translations objectAtIndex:row];
+ }
+ else
+ {
+ translation = [[LocalizationEditorTranslation alloc] init];
+ }
LocalizationEditorLanguage* lang = [self selectedLanguage];
if (!lang) return;
@@ -411,7 +617,16 @@ - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColu
}
else
{
- return [translation.translations objectForKey:aTableColumn.identifier];
+ if(translation.languagesDownloading &&
+ ((ProjectSettings*)[AppDelegate appDelegate].projectSettings).isDownloadingTranslations &&
+ [translation.languagesDownloading containsObject:aTableColumn.identifier])
+ {
+ return @"Downloading...";
+ }
+ else
+ {
+ return [translation.translations objectForKey:aTableColumn.identifier];
+ }
}
}
@@ -602,6 +817,7 @@ - (void) textDidEndEditing:(NSNotification *)notification
{
[handler setEdited];
}
+
}
#pragma mark Split view delegate
@@ -619,4 +835,48 @@ - (CGFloat) splitView:(NSSplitView *)splitView constrainMaxCoordinate:(CGFloat)p
else return proposedMaximumPosition;
}
+#pragma mark KVO for hasOpenFile
+/*
+ * This replaces the bindings of before. If 'has open file' changes, change the language window according to the 'isDownloading' status of the
+ * new project.
+ */
+-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
+ ProjectSettings* ps = [AppDelegate appDelegate].projectSettings;
+ #ifdef SPRITEBUILDER_PRO
+ if([keyPath isEqualToString:@"hasOpenFile"]){
+ if(ps)
+ {
+ [self displayForOpenFile];
+ }else{
+ [self displayForNoOpenFile];
+ }
+ }
+ #else
+ if([keyPath isEqualToString:@"hasOpenFile"]){
+ if(!ps)
+ {
+ [self displayForNoOpenFile];
+ }
+ else if(ps.isDownloadingTranslations)
+ {
+ _ltw = [[LocalizationTranslateWindow alloc] initWithDownload:ps parentWindow:self];
+ [_ltw restartDownload];
+ [self setDownloadingTranslations];
+ }else{
+ [self finishDownloadingTranslations];
+ _ltw = nil;
+ }
+ }
+ #endif
+
+}
+
+#pragma mark Restart Translation Download
+/*
+ * Restarts Translation Download
+ */
+- (void)restartTranslationDownload:(ProjectSettings *)ps{
+ _ltw = [[LocalizationTranslateWindow alloc] initWithDownload:ps parentWindow:self];
+ [_ltw restartDownload];
+}
@end
diff --git a/SpriteBuilder/ccBuilder/LocalizationEditorWindow.xib b/SpriteBuilder/ccBuilder/LocalizationEditorWindow.xib
index 069bae88d..c0be1bf23 100644
--- a/SpriteBuilder/ccBuilder/LocalizationEditorWindow.xib
+++ b/SpriteBuilder/ccBuilder/LocalizationEditorWindow.xib
@@ -1,2274 +1,430 @@
-
-
-
- 1080
- 12E55
- 3084
- 1187.39
- 626.00
-
- com.apple.InterfaceBuilder.CocoaPlugin
- 3084
-
-
- NSBox
- NSButton
- NSButtonCell
- NSCustomObject
- NSCustomView
- NSImageCell
- NSMenu
- NSMenuItem
- NSPopUpButton
- NSPopUpButtonCell
- NSScrollView
- NSScroller
- NSSplitView
- NSTableColumn
- NSTableHeaderView
- NSTableView
- NSTextField
- NSTextFieldCell
- NSTextView
- NSUserDefaultsController
- NSView
- NSWindowTemplate
-
-
- com.apple.InterfaceBuilder.CocoaPlugin
-
-
- PluginDependencyRecalculationVersion
-
-
-
-
- LocalizationEditorWindow
-
-
- FirstResponder
-
-
- NSApplication
-
-
- 15
- 2
- {{196, 240}, {863, 568}}
- 544735232
- Language Editor
- NSWindow
-
-
- {863, 568}
-
-
- 256
-
-
-
- 274
-
-
-
- 2304
-
-
-
- 256
- {565, 531}
-
-
-
- _NS:13
- YES
- NO
- YES
-
-
-
- -2147483392
- {{224, 0}, {16, 17}}
-
- _NS:19
-
-
-
- warning
- 20
- 20
- 20
-
-
- 134217728
- 33685504
- _NS:9
- 0
- 0
- 0
- NO
-
-
-
-
- key
- 200
- 100
- 1000
-
-
- 337641536
- 133120
- Text Cell
-
-
-
- 6
- System
- controlBackgroundColor
-
- 3
- MC42NjY2NjY2NjY3AA
-
-
-
- 6
- System
- controlTextColor
-
-
-
- 3
- YES
- YES
-
-
-
- comment
- 200
- 100
- 1000
-
-
- 337641536
- 133120
- Text Cell
-
-
-
-
-
- 3
- YES
- YES
-
-
-
- 3
- 2
-
- 3
- MQA
-
-
- 1
- MC44OTAxOTYwNzg0IDAuOTA1ODgyMzUyOSAwLjkyNTQ5MDE5NjEAA
-
- 16
- 1916796928
-
-
- 3
- 4
- 15
- 0
- YES
- 0
- 1
-
-
- {{0, 17}, {565, 531}}
-
-
-
- _NS:11
-
-
- 4
-
-
-
- -2147483392
- {{224, 17}, {15, 102}}
-
-
-
- _NS:58
- NO
-
- _doScroller:
- 37
- 0.1947367936372757
-
-
-
- -2147483392
- {{1, 119}, {223, 15}}
-
-
-
- _NS:60
- NO
- 1
-
- _doScroller:
- 0.57142859697341919
-
-
-
- 2304
-
-
-
- {565, 17}
-
-
-
- _NS:15
-
-
- 4
-
-
- {{0, 21}, {565, 548}}
-
-
-
- _NS:9
- 133680
-
-
-
-
- QSAAAEEgAABBkAAAQZAAAA
- 0.25
- 4
- 1
-
-
-
- 273
-
-
-
- 256
-
-
-
-
- 268
- {{4, 341}, {56, 14}}
-
-
-
- _NS:1535
- YES
-
- 68157504
- 272761856
- Language
-
- _NS:1535
-
-
- 6
- System
- controlColor
-
-
-
-
- NO
-
-
-
- 292
- {{4, 69}, {288, 14}}
-
-
-
- _NS:1535
- YES
-
- 68157504
- 272761856
- Comment
-
- _NS:1535
-
-
-
-
- NO
-
-
-
- 288
-
-
-
- 2304
-
-
-
- 2322
-
- Apple HTML pasteboard type
- Apple PDF pasteboard type
- Apple PICT pasteboard type
- Apple PNG pasteboard type
- Apple URL pasteboard type
- CorePasteboardFlavorType 0x6D6F6F76
- NSColor pasteboard type
- NSFilenamesPboardType
- NSStringPboardType
- NeXT Encapsulated PostScript v1.2 pasteboard type
- NeXT RTFD pasteboard type
- NeXT Rich Text Format v1.0 pasteboard type
- NeXT TIFF v4.0 pasteboard type
- NeXT font pasteboard type
- NeXT ruler pasteboard type
- WebURLsWithTitlesPboardType
- public.url
-
- {280, 54}
-
-
-
- _NS:13
-
-
-
-
-
-
-
-
-
-
-
- 166
-
-
-
- 280
- 1
-
-
- 67121127
- 0
-
-
-
-
- 6
- System
- selectedTextBackgroundColor
-
-
-
- 6
- System
- selectedTextColor
-
-
-
-
-
-
- 1
- MCAwIDEAA
-
-
- {8, -8}
- 13
-
-
-
-
-
- 1
-
- 6
- {463, 10000000}
-
-
-
- {{1, 1}, {280, 54}}
-
-
-
- _NS:11
-
-
-
- {4, 5}
-
- 79691776
-
-
-
-
-
- file://localhost/Applications/Xcode.app/Contents/SharedFrameworks/DVTKit.framework/Resources/DVTIbeamCursor.tiff
-
-
-
-
- 3
- MCAwAA
-
-
-
- 4
-
-
-
- 256
- {{265, 1}, {16, 54}}
-
-
-
- _NS:83
- NO
-
- _doScroller:
- 1
- 0.85256409645080566
-
-
-
- -2147483392
- {{-100, -100}, {87, 18}}
-
-
-
- _NS:33
- NO
- 1
-
- _doScroller:
- 1
- 0.94565218687057495
-
-
- {{7, 8}, {282, 56}}
-
-
-
- _NS:9
- 133138
-
-
-
- 0.25
- 4
- 1
-
-
-
- 268
- {{4, 426}, {288, 14}}
-
-
-
- _NS:1535
- YES
-
- 68157504
- 272761856
- Key (default value)
-
- _NS:1535
-
-
-
-
- NO
-
-
-
- 272
-
-
-
- 2304
-
-
-
- 2322
-
- Apple HTML pasteboard type
- Apple PDF pasteboard type
- Apple PICT pasteboard type
- Apple PNG pasteboard type
- Apple URL pasteboard type
- CorePasteboardFlavorType 0x6D6F6F76
- NSColor pasteboard type
- NSFilenamesPboardType
- NSStringPboardType
- NeXT Encapsulated PostScript v1.2 pasteboard type
- NeXT RTFD pasteboard type
- NeXT Rich Text Format v1.0 pasteboard type
- NeXT TIFF v4.0 pasteboard type
- NeXT font pasteboard type
- NeXT ruler pasteboard type
- WebURLsWithTitlesPboardType
- public.url
-
- {280, 240}
-
-
-
- _NS:13
-
-
-
-
-
-
-
-
-
-
-
- 166
-
-
-
- 280
- 1
-
-
- 67121127
- 0
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 1
-
- 6
- {463, 10000000}
-
-
-
- {{1, 1}, {280, 240}}
-
-
-
- _NS:11
-
-
-
- {4, 5}
-
- 79691776
-
-
-
-
-
- file://localhost/Applications/Xcode.app/Contents/SharedFrameworks/DVTKit.framework/Resources/DVTIbeamCursor.tiff
-
-
-
-
-
-
- 4
-
-
-
- 256
- {{265, 1}, {16, 240}}
-
-
-
- _NS:83
- NO
-
- _doScroller:
- 1
- 0.85256409645080566
-
-
-
- -2147483392
- {{-100, -100}, {87, 18}}
-
-
-
- _NS:33
- NO
- 1
-
- _doScroller:
- 1
- 0.94565218687057495
-
-
- {{7, 91}, {282, 242}}
-
-
-
- _NS:9
- 133138
-
-
-
- 0.25
- 4
- 1
-
-
-
- 264
-
-
-
- 2304
-
-
-
- 2322
-
- Apple HTML pasteboard type
- Apple PDF pasteboard type
- Apple PICT pasteboard type
- Apple PNG pasteboard type
- Apple URL pasteboard type
- CorePasteboardFlavorType 0x6D6F6F76
- NSColor pasteboard type
- NSFilenamesPboardType
- NSStringPboardType
- NeXT Encapsulated PostScript v1.2 pasteboard type
- NeXT RTFD pasteboard type
- NeXT Rich Text Format v1.0 pasteboard type
- NeXT TIFF v4.0 pasteboard type
- NeXT font pasteboard type
- NeXT ruler pasteboard type
- WebURLsWithTitlesPboardType
- public.url
-
- {280, 54}
-
-
-
- _NS:13
-
-
-
-
-
-
-
-
-
-
-
- 166
-
-
-
- 280
- 1
-
-
- 67121127
- 0
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 1
-
- 6
- {463, 10000000}
-
-
-
- {{1, 1}, {280, 54}}
-
-
-
- _NS:11
-
-
-
- {4, 5}
-
- 79691776
-
-
-
-
-
- file://localhost/Applications/Xcode.app/Contents/SharedFrameworks/DVTKit.framework/Resources/DVTIbeamCursor.tiff
-
-
-
-
-
-
- 4
-
-
-
- 256
- {{265, 1}, {16, 54}}
-
-
-
- _NS:83
- NO
-
- _doScroller:
- 1
- 0.85256409645080566
-
-
-
- -2147483392
- {{-100, -100}, {87, 18}}
-
-
-
- _NS:33
- NO
- 1
-
- _doScroller:
- 1
- 0.94565218687057495
-
-
- {{7, 365}, {282, 56}}
-
-
-
- _NS:9
- 133138
-
-
-
- 0.25
- 4
- 1
-
-
- {297, 446}
-
-
-
- _NS:11
- NSView
-
-
-
- 256
-
-
-
- 276
-
-
-
- 2304
-
-
-
- 256
- {297, 100}
-
-
-
- _NS:13
- YES
- NO
- YES
-
-
- -2147483392
- {{224, 0}, {16, 17}}
-
- _NS:19
-
-
-
- enabled
- 15
- 15
- 1000
-
-
- 67108864
- 268566528
-
-
- _NS:9
-
- 1211912448
- 2
-
- NSImage
- NSSwitch
-
-
- NSSwitch
-
-
-
- 200
- 25
-
- 3
- YES
- YES
-
-
-
- name
- 248
- 40
- 1000
-
-
- 337641536
- 133120
- Text Cell
-
-
-
-
-
- 3
- YES
-
-
-
- 3
- 2
-
- 1
- MC44OTAxOTYwNzg0IDAuOTA1ODgyMzUyOSAwLjkyNTQ5MDE5NjEAA
-
-
- 6
- System
- gridColor
-
- 3
- MC41AA
-
-
- 17
- 507510784
-
-
- 4
- 15
- 0
- YES
- 0
- 1
-
-
- {297, 100}
-
-
-
- _NS:11
-
-
- 4
-
-
-
- -2147483392
- {{224, 17}, {15, 102}}
-
-
-
- _NS:58
- NO
-
- _doScroller:
- 0.99009900990099009
-
-
-
- -2147483392
- {{0, 84}, {297, 16}}
-
-
-
- _NS:60
- NO
- 1
-
- _doScroller:
- 0.99331103678929766
-
-
- {297, 100}
-
-
-
- _NS:9
- 133680
-
-
-
- QSAAAEEgAABBmAAAQZgAAA
- 0.25
- 4
- 1
-
-
- {{0, 447}, {297, 100}}
-
-
-
- _NS:13
- NSView
-
-
- {{566, 21}, {297, 547}}
-
-
-
- _NS:9
- 2
-
-
-
- 17
- {{563, 0}, {5, 568}}
-
-
-
- _NS:9
- {0, 0}
-
- 67108864
- 0
- Box
-
-
- 6
- System
- textBackgroundColor
-
-
-
- 3
- MCAwLjgwMDAwMDAxMTkAA
-
-
- 3
- 2
- 0
- NO
-
-
-
- 289
- {{457, -1}, {109, 22}}
-
-
-
- _NS:22
- YES
-
- -2080374784
- 134348800
- Add Translation
-
- _NS:22
-
- -2034483200
- 134
-
- NSImage
- NSAddTemplate
-
-
-
- 400
- 75
-
- NO
-
-
-
- 34
- {{0, 18}, {863, 5}}
-
-
-
- _NS:9
- {0, 0}
-
- 67108864
- 0
- Box
-
-
-
- 3
- MCAwLjgwMDAwMDAxMTkAA
-
-
- 3
- 2
- 0
- NO
-
-
-
- {863, 568}
-
-
-
-
- {{0, 0}, {2560, 1418}}
- {863, 590}
- {10000000000000, 10000000000000}
- YES
-
-
- YES
-
-
-
-
-
-
- pressedAdd:
-
-
-
- 30
-
-
-
- window
-
-
-
- 34
-
-
-
- popLanguageAdd
-
-
-
- 78
-
-
-
- selectedAddLanguage:
-
-
-
- 79
-
-
-
- tableTranslations
-
-
-
- 80
-
-
-
- tableLanguages
-
-
-
- 81
-
-
-
- popCurrentLanguage
-
-
-
- 84
-
-
-
- textKey
-
-
-
- 120
-
-
-
- textTranslation
-
-
-
- 121
-
-
-
- textComment
-
-
-
- 122
-
-
-
- selectedCurrentLanguage:
-
-
-
- 132
-
-
-
- textInspectorKey
-
-
-
- 133
-
-
-
- dataSource
-
-
-
- 96
-
-
-
- delegate
-
-
-
- 97
-
-
-
- enabled: hasOpenFile
-
-
-
-
-
- enabled: hasOpenFile
- enabled
- hasOpenFile
- 2
-
-
- 146
-
-
-
- delegate
-
-
-
- 135
-
-
-
- enabled: hasOpenFile
-
-
-
-
-
- enabled: hasOpenFile
- enabled
- hasOpenFile
- 2
-
-
- 140
-
-
-
- dataSource
-
-
-
- 83
-
-
-
- enabled: hasOpenFile
-
-
-
-
-
- enabled: hasOpenFile
- enabled
- hasOpenFile
- 2
-
-
- 149
-
-
-
- editable: inspectorEnabled
-
-
-
-
-
- editable: inspectorEnabled
- editable
- inspectorEnabled
- 2
-
-
- 104
-
-
-
- attributedString: inspectorTextKey
-
-
-
-
-
- attributedString: inspectorTextKey
- attributedString
- inspectorTextKey
-
- NSContinuouslyUpdatesValue
-
-
- 2
-
-
- 125
-
-
-
- delegate
-
-
-
- 134
-
-
-
- enabled: inspectorEnabled
-
-
-
-
-
- enabled: inspectorEnabled
- enabled
- inspectorEnabled
- 2
-
-
- 101
-
-
-
- enabled: inspectorEnabled
-
-
-
-
-
- enabled: inspectorEnabled
- enabled
- inspectorEnabled
- 2
-
-
- 110
-
-
-
- enabled: inspectorEnabled
-
-
-
-
-
- enabled: inspectorEnabled
- enabled
- inspectorEnabled
- 2
-
-
- 107
-
-
-
- editable: inspectorEnabled
-
-
-
-
-
- editable: inspectorEnabled
- editable
- inspectorEnabled
- 2
-
-
- 113
-
-
-
- attributedString: inspectorTextTranslation
-
-
-
-
-
- attributedString: inspectorTextTranslation
- attributedString
- inspectorTextTranslation
-
- NSContinuouslyUpdatesValue
-
-
- 2
-
-
- 131
-
-
-
- delegate
-
-
-
- 136
-
-
-
- enabled: inspectorEnabled
-
-
-
-
-
- enabled: inspectorEnabled
- enabled
- inspectorEnabled
- 2
-
-
- 116
-
-
-
- editable: inspectorEnabled
-
-
-
-
-
- editable: inspectorEnabled
- editable
- inspectorEnabled
- 2
-
-
- 119
-
-
-
- attributedString: inspectorTextComment
-
-
-
-
-
- attributedString: inspectorTextComment
- attributedString
- inspectorTextComment
-
- NSContinuouslyUpdatesValue
-
-
- 2
-
-
- 128
-
-
-
- delegate
-
-
-
- 137
-
-
-
- enabled: hasOpenFile
-
-
-
-
-
- enabled: hasOpenFile
- enabled
- hasOpenFile
- 2
-
-
- 143
-
-
-
-
-
- 0
-
-
-
-
-
- -2
-
-
- File's Owner
-
-
- -1
-
-
- First Responder
-
-
- -3
-
-
- Application
-
-
- 1
-
-
-
-
-
-
-
- 2
-
-
-
-
-
-
-
-
-
-
-
-
- 3
-
-
-
-
-
-
-
-
-
-
- 4
-
-
-
-
-
-
-
-
-
- 5
-
-
-
-
- 6
-
-
-
-
- 7
-
-
-
-
- 8
-
-
-
-
-
-
-
- 9
-
-
-
-
-
-
-
- 10
-
-
-
-
- 18
-
-
-
-
-
-
-
-
- 19
-
-
-
-
-
-
-
-
-
-
-
-
-
- 20
-
-
-
-
-
-
-
- 21
-
-
-
-
- 23
-
-
-
-
-
-
-
- 24
-
-
-
-
- 29
-
-
-
-
- 38
-
-
-
-
-
-
-
-
-
- 39
-
-
-
-
-
-
-
-
- 40
-
-
-
-
- 42
-
-
-
-
- 43
-
-
-
-
-
-
-
- 44
-
-
-
-
-
-
-
- 45
-
-
-
-
- 47
-
-
-
-
- 48
-
-
-
-
-
-
-
-
-
- 49
-
-
-
-
- 50
-
-
-
-
- 51
-
-
-
-
- 52
-
-
-
-
-
-
-
- 53
-
-
-
-
- 54
-
-
-
-
-
-
-
- 55
-
-
-
-
-
-
-
- 56
-
-
-
-
-
-
-
-
-
- 57
-
-
-
-
- 58
-
-
-
-
- 59
-
-
-
-
- 60
-
-
-
-
-
-
-
- 61
-
-
-
-
- 62
-
-
-
-
-
-
-
-
-
- 63
-
-
-
-
- 64
-
-
-
-
- 65
-
-
-
-
- 66
-
-
-
-
-
-
-
-
-
- 67
-
-
-
-
-
-
-
- 68
-
-
-
-
- 69
-
-
-
-
- 70
-
-
-
-
- 71
-
-
-
-
- 72
-
-
-
-
-
-
-
- 73
-
-
-
-
-
-
-
- 74
-
-
-
-
-
-
-
- 75
-
-
-
-
- 93
-
-
-
-
-
-
-
- 94
-
-
-
-
- 95
-
-
-
-
- 98
-
-
-
-
-
-
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- {{357, 418}, {480, 270}}
-
- CCBTextFieldCell
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- LocalizationEditorLanguageTableView
- com.apple.InterfaceBuilder.CocoaPlugin
- LocalizationEditorTranslationTableView
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- CCBTextFieldCell
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- CCBTextFieldLabel
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- CCBTextFieldLabel
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- CCBTextFieldLabel
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- CCBTextFieldCell
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
- com.apple.InterfaceBuilder.CocoaPlugin
-
-
-
-
-
- 149
-
-
-
-
- CCBTableView
- NSTableView
-
- IBProjectSource
- ./Classes/CCBTableView.h
-
-
-
- CCBTextFieldCell
- NSTextFieldCell
-
- IBProjectSource
- ./Classes/CCBTextFieldCell.h
-
-
-
- CCBTextFieldLabel
- NSTextField
-
- IBProjectSource
- ./Classes/CCBTextFieldLabel.h
-
-
-
- LocalizationEditorLanguageTableView
- CCBTableView
-
- IBProjectSource
- ./Classes/LocalizationEditorLanguageTableView.h
-
-
-
- LocalizationEditorTranslationTableView
- CCBTableView
-
- IBProjectSource
- ./Classes/LocalizationEditorTranslationTableView.h
-
-
-
- LocalizationEditorWindow
- NSWindowController
-
- id
- id
- id
- id
-
-
-
- pressedAdd:
- id
-
-
- pressedAddGroup:
- id
-
-
- selectedAddLanguage:
- id
-
-
- selectedCurrentLanguage:
- id
-
-
-
- NSPopUpButton
- NSPopUpButton
- NSTableView
- NSTableView
- NSTextView
-
-
-
- popCurrentLanguage
- NSPopUpButton
-
-
- popLanguageAdd
- NSPopUpButton
-
-
- tableLanguages
- NSTableView
-
-
- tableTranslations
- NSTableView
-
-
- textInspectorKey
- NSTextView
-
-
-
- IBProjectSource
- ./Classes/LocalizationEditorWindow.h
-
-
-
-
- 0
- IBCocoaFramework
- YES
- 3
-
- {8, 8}
- {11, 11}
- {10, 3}
- {15, 15}
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/SpriteBuilder/ccBuilder/LocalizationTransactionObserver.h b/SpriteBuilder/ccBuilder/LocalizationTransactionObserver.h
new file mode 100644
index 000000000..dfb95a5c1
--- /dev/null
+++ b/SpriteBuilder/ccBuilder/LocalizationTransactionObserver.h
@@ -0,0 +1,19 @@
+//
+// LocalizationTransactionObserver.h
+// SpriteBuilder
+//
+// Created by Benjamin Koatz on 7/11/14.
+//
+//
+
+#import
+#import
+@class LocalizationTranslateWindow;
+
+@interface LocalizationTransactionObserver : NSObject
+{
+ LocalizationTranslateWindow* _ltw;
+}
+@property (nonatomic,strong) LocalizationTranslateWindow* ltw;
+
+@end
diff --git a/SpriteBuilder/ccBuilder/LocalizationTransactionObserver.m b/SpriteBuilder/ccBuilder/LocalizationTransactionObserver.m
new file mode 100644
index 000000000..536a959f2
--- /dev/null
+++ b/SpriteBuilder/ccBuilder/LocalizationTransactionObserver.m
@@ -0,0 +1,70 @@
+//
+// LocalizationTransactionObserver.m
+// SpriteBuilder
+//
+// Created by Benjamin Koatz on 7/11/14.
+//
+//
+
+#import "LocalizationTransactionObserver.h"
+#import "LocalizationTranslateWindow.h"
+
+@implementation LocalizationTransactionObserver
+@synthesize ltw = _ltw;
+
+/*
+ * Observes and handles responses from the paymentQueue
+ */
+- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions{
+
+ for (SKPaymentTransaction* transaction in transactions)
+ {
+ switch(transaction.transactionState)
+ {
+ case SKPaymentTransactionStateFailed:
+ {
+ NSLog(@"Failed: %@", transaction.error);
+ if(_ltw)
+ {
+ [_ltw enableAll];
+ [_ltw setPaymentError];
+ }
+ else
+ {
+ NSLog(@"No transaction window to process failure!!");
+ }
+ [queue finishTransaction:transaction];
+ _ltw = nil;
+ break;
+ }
+ case SKPaymentTransactionStatePurchased:
+ {
+ NSLog(@"Purchased");
+ NSURL* receiptURL = [[NSBundle mainBundle] appStoreReceiptURL];
+ NSData* receipt = [NSData dataWithContentsOfURL:receiptURL];
+ if(_ltw)
+ {
+ [_ltw saveReceipt:receipt transaction:transaction];
+ [_ltw validateReceipt:[receipt base64EncodedStringWithOptions:0]];
+ }
+ else
+ {
+ NSLog(@"No transaction window to process purchased!!");
+ }
+ [queue finishTransaction:transaction];
+ _ltw = nil;
+ break;
+ }
+ case SKPaymentTransactionStateRestored:
+ {
+ NSLog(@"Restored - Shouldn't happen");
+ [queue finishTransaction:transaction];
+ _ltw = nil;
+ break;
+ }
+ default:
+ break;
+ }
+ }
+}
+@end
diff --git a/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.h b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.h
new file mode 100644
index 000000000..e3411e52a
--- /dev/null
+++ b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.h
@@ -0,0 +1,113 @@
+//
+// LocalizationTranslateWindow.h
+// SpriteBuilder
+//
+// Created by Benjamin Koatz on 6/4/14.
+//
+//
+
+#import
+#import
+
+@class LocalizationEditorLanguage;
+@class LocalizationEditorWindow;
+@class LocalizationTranslateWindowHandler;
+@class ProjectSettings;
+
+@interface LocalizationTranslateWindow : NSWindowController
+{
+ //tab views
+ IBOutlet NSView* _noActiveLangsView;
+ IBOutlet NSView* _standardLangsView;
+ IBOutlet NSView* _downloadingLangsView;
+ IBOutlet NSView* _validatingPaymentView;
+ IBOutlet NSView* _downloadingLangsErrorView;
+ IBOutlet NSView* _downloadingCostsErrorView;
+ IBOutlet NSView* _paymentErrorView;
+ IBOutlet NSTabView* _translateFromTabView;
+
+ //fields inside tab views
+ IBOutlet NSTextField* _numWords;
+ IBOutlet NSTextField* _cost;
+ IBOutlet NSTextField* _noActiveLangsError;
+ IBOutlet NSProgressIndicator* _languagesDownloading;
+ IBOutlet NSProgressIndicator* _costDownloading;
+ IBOutlet NSProgressIndicator* _paymentValidating;
+ IBOutlet NSTextField* _costDownloadingText;
+ IBOutlet NSButton* _ignoreText;
+
+ //Language menus
+ IBOutlet NSPopUpButton* _popTranslateFrom;
+ IBOutlet NSTableView* _languageTable;
+ IBOutlet NSButton* _checkAll;
+
+ //Buttons
+ IBOutlet NSButton* _cancel;
+ IBOutlet NSButton *_buy;
+
+ //Translations downloading stuff
+ NSInteger _numTransToDownload;
+ NSTimer* _timerTransDownload;
+
+ //Language Info
+ LocalizationEditorLanguage* _currLang;
+ NSMutableDictionary* _languages;
+ NSMutableArray* _activeLanguages;
+
+ //Phrase Translation
+ NSMutableArray* _phrasesToTranslate;
+ NSInteger _tierForTranslations;
+
+ //Product and URL interaction
+ SKProduct* _product;
+ NSString* _guid;
+ NSMutableDictionary* _receipts;
+ NSString* _latestRequestID;
+
+ //Interaction with EditorWindow
+ LocalizationEditorWindow* __weak _parentWindow;
+ NSAlert* _buyAlert;
+ NSString* _projectPathDir;
+ NSString* _projectPath;
+
+ //Used when closing
+ NSURLSessionTask *_currTask;
+}
+
+- (id)initWithDownload:(ProjectSettings *)ps parentWindow:(LocalizationEditorWindow*)pw;
+- (IBAction)buy:(id)sender;
+- (IBAction)cancel:(id)sender;
+- (IBAction)toggleIgnore:(id)sender;
+- (IBAction)selectedTranslateFromMenu:(id)sender;
+- (IBAction)toggleCheckAll:(id)sender;
+- (IBAction)retryLanguages:(id)sender;
+- (IBAction)retryCost:(id)sender;
+- (void)cancelDownloadWithError:(NSError*)error;
+- (void)pauseDownload;
+- (void)restartDownload;
+- (void)refresh;
+
+//Needed for Transaction Observer
+-(void)enableAll;
+-(void)validateReceipt:(NSString *)receipt;
+-(void)saveReceipt:(NSData*)receipt transaction:(SKPaymentTransaction*)transaction;
+-(void)setPaymentError;
+
+@property (nonatomic,readwrite) NSInteger numTransToDownload;
+@property (nonatomic,strong) NSTimer* timerTransDownload;
+@property (nonatomic,strong) LocalizationEditorLanguage* currLang;
+@property (nonatomic,strong) NSMutableDictionary* languages;
+@property (nonatomic,strong) NSMutableArray* activeLanguages;
+@property (nonatomic,strong) NSMutableArray* phrasesToTranslate;
+@property (nonatomic,readwrite) NSInteger tierForTranslations;
+@property (nonatomic,strong) SKProduct* product;
+@property (nonatomic,copy) NSString* guid;
+@property (nonatomic,strong) NSMutableDictionary* receipts;
+@property (nonatomic,copy) NSString* latestRequestID;
+
+@property (nonatomic,weak) LocalizationEditorWindow* parentWindow;
+@property (nonatomic,strong) NSAlert* buyAlert;
+@property (nonatomic,strong) NSString* projectPathDir;
+@property (nonatomic,strong) NSString* projectPath;
+@property (nonatomic,strong) NSURLSessionTask* currTask;
+@end
\ No newline at end of file
diff --git a/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.m b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.m
new file mode 100644
index 000000000..1623969eb
--- /dev/null
+++ b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.m
@@ -0,0 +1,1244 @@
+//
+// LocalizationTranslateWindow.m
+// SpriteBuilder
+//
+// Created by Benjamin Koatz on 6/4/14.
+//
+//
+
+#import "LocalizationTranslateWindow.h"
+#import "LocalizationEditorHandler.h"
+#import "AppDelegate.h"
+#import "LocalizationEditorLanguage.h"
+#import "LocalizationEditorTranslation.h"
+#import "LocalizationEditorWindow.h"
+#import "SBErrors.h"
+#import "ProjectSettings.h"
+#import "CocosScene.h"
+#import "StringPropertySetter.h"
+#import "TranslationSettings.h"
+
+@implementation LocalizationTranslateWindow
+
+@synthesize numTransToDownload = _numTransToDownload;
+@synthesize timerTransDownload = _timerTransDownload;
+@synthesize currLang = _currLang;
+@synthesize languages = _languages;
+@synthesize activeLanguages = _activeLanguages;
+@synthesize phrasesToTranslate = _phrasesToTranslate;
+@synthesize tierForTranslations = _tierForTranslations;
+@synthesize product = _product;
+@synthesize guid = _guid;
+@synthesize receipts = _receipts;
+@synthesize latestRequestID = _latestRequestID;
+@synthesize parentWindow = _parentWindow;
+@synthesize buyAlert = _buyAlert;
+@synthesize projectPathDir = _projectPathDir;
+@synthesize projectPath = _projectPath;
+@synthesize currTask = _currTask;
+
+//Standards for the tab view
+static int downloadLangsIndex = 0;
+static int noActiveLangsIndex = 1;
+static int standardLangsIndex = 2;
+static int validatingPaymentIndex = 3;
+static int downloadCostErrorIndex = 4;
+static int downloadLangsErrorIndex = 5;
+static int paymentErrorIndex = 6;
+
+//URLs
+static NSString* const baseURL = @"http://www.spritebuilder.com/api/v1";
+static NSString* languageURL;
+static NSString* estimateURL;
+static NSString* receiptTranslationsURL;
+static NSString* translationsURL;
+static NSString* cancelURL;
+
+//Repeated messages for the user
+static NSString* const noActiveLangsString = @"No Valid Languages";
+static NSString* const downloadingLangsString = @"Downloading...";
+static NSString* noActiveLangsErrorString = @"We support translations from:\r\r%@.";
+
+//Interval for repeating a downlaod request, in seconds
+static double downloadRepeatInterval = 60;
+
+//Amount of server downtime allowed until download cancelled, in seconds
+static double serverTimeOut = 86400; //86400 = 24 hours
+
+//Number of intervals where the server has been unavailable
+static int numTimedOutIntervals = 0;
+
+#pragma mark Initializing
+/*
+ * Set up URLs and global variables and initialize with the information to restart a download request.
+ * Used when restarting a download request without showing the window
+ */
+-(id)initWithDownload:(ProjectSettings *)ps parentWindow:(LocalizationEditorWindow*)pw{
+ self = [super init];
+ if (!self)
+ {
+ return NULL;
+ }
+ [self setUpURLsAndGlobals];
+ self.projectPathDir = ps.projectPathDir;
+ self.projectPath = ps.projectPath;
+ self.latestRequestID = ps.latestRequestID;
+ self.parentWindow = pw;
+ self.numTransToDownload = ps.numToDownload;
+ return self;
+}
+
+/*
+ * Set up URLs and global variables and prepare the tab views, disable everything in the window until the
+ * languages are downloaded and get the available languages from the server.
+ * Used when opening a new translation window.
+ */
+-(void) awakeFromNib
+{
+ [self setUpURLsAndGlobals];
+ ProjectSettings *ps = ((ProjectSettings*)[[AppDelegate appDelegate] projectSettings]);
+ self.projectPathDir = ps.projectPathDir;
+ self.projectPath = ps.projectPath;
+ [[_translateFromTabView tabViewItemAtIndex:downloadLangsIndex] setView:_downloadingLangsView];
+ [[_translateFromTabView tabViewItemAtIndex:noActiveLangsIndex] setView:_noActiveLangsView];
+ [[_translateFromTabView tabViewItemAtIndex:standardLangsIndex] setView:_standardLangsView];
+ [[_translateFromTabView tabViewItemAtIndex:validatingPaymentIndex] setView:_validatingPaymentView];
+ [[_translateFromTabView tabViewItemAtIndex:downloadCostErrorIndex] setView:_downloadingCostsErrorView];
+ [[_translateFromTabView tabViewItemAtIndex:downloadLangsErrorIndex] setView:_downloadingLangsErrorView];
+ [[_translateFromTabView tabViewItemAtIndex:paymentErrorIndex] setView:_paymentErrorView];
+ [self disableAllExceptButtons];
+ [self getLanguagesFromServer];
+
+}
+
+/*
+ * Set up URLs and global variables like guid and language translation mapping dictionary.
+ */
+-(void)setUpURLsAndGlobals{
+ languageURL = [baseURL stringByAppendingString:@"/translations/languages?key=%@"];
+ estimateURL = [baseURL stringByAppendingString:@"/translations/estimate"];
+ receiptTranslationsURL = [baseURL stringByAppendingString:@"/translations"];
+ translationsURL = [baseURL stringByAppendingString:@"/translations?key=%@"];
+ cancelURL = [baseURL stringByAppendingString:@"/translations/cancel"];
+
+ self.guid = [[[NSUserDefaults standardUserDefaults] dictionaryRepresentation] objectForKey:@"sbUserID"];
+ self.languages = [[NSMutableDictionary alloc] init];
+ self.receipts = [[NSMutableDictionary alloc] init];
+ self.buyAlert = [NSAlert alertWithMessageText:@"Starting Translation Download" defaultButton:@"Continue" alternateButton:@"Cancel" otherButton:NULL informativeTextWithFormat:@"The average translation download wait is 30 minutes, but translation downloads can sometimes take days. Downloads are nonrefundable, and during a translation download the contents of the Language Editor window can't be modified."];
+ [self.buyAlert setShowsSuppressionButton:YES];
+
+}
+
+#pragma mark Downloading and Updating Languages
+
+/*
+ * Show the downloading languages message.
+ * Get languages from server and update active langauges. Once the session
+ * is done the JSON data will be parsed if there wasn't an error. Errors handled and
+ * displayed.
+ */
+-(void)getLanguagesFromServer{
+ _popTranslateFrom.title = downloadingLangsString;
+ [_translateFromTabView selectTabViewItemAtIndex:downloadLangsIndex];
+ [_languagesDownloading startAnimation:self];
+ NSString* URLstring =[NSString stringWithFormat:languageURL, _guid];
+ NSURL* url = [NSURL URLWithString:URLstring];
+ NSURLSessionDataTask *task = [[NSURLSession sharedSession] dataTaskWithURL: url
+ completionHandler:^(NSData *data,
+ NSURLResponse *response,
+ NSError *error)
+ {
+ if (!error)
+ {
+ [self parseJSONLanguages:data];
+ NSLog(@"Languages Status code: %li", ((NSHTTPURLResponse *)response).statusCode);
+ }
+ else
+ {
+ [_languagesDownloading stopAnimation:self];
+ [_translateFromTabView selectTabViewItemAtIndex:downloadLangsErrorIndex];
+ NSLog(@"Languages Error: %@", error.localizedDescription);
+ }
+ }];
+ [task resume];
+ _currTask = task;
+}
+
+
+/*
+ * Turns the JSON response into a dictionary and fill the _languages global accordingly.
+ * Then update the active languages array, the pop-up menu and the table. This is
+ * only done once in the beginning of the session. Errors handled and displayed.
+ */
+-(void)parseJSONLanguages:(NSData *)data{
+ NSError *JSONError;
+ NSMutableDictionary* availableLanguagesDict = [NSJSONSerialization JSONObjectWithData:data
+ options:NSJSONReadingMutableContainers error:&JSONError];
+ if(JSONError || [[[availableLanguagesDict allKeys] firstObject] isEqualToString:@"Error"])
+ {
+ [self printJSONOrNormalErrorForFunction:@"Languages" JSONError:JSONError Error:[availableLanguagesDict objectForKey:@"Error"]];
+ [_languagesDownloading stopAnimation:self];
+ [_translateFromTabView selectTabViewItemAtIndex:downloadLangsErrorIndex];
+ return;
+ }
+ for(NSString* lIso in availableLanguagesDict.allKeys)
+ {
+ NSMutableArray* translateTo = [[NSMutableArray alloc] init];
+ for(NSString* translateToIso in (NSArray *)[availableLanguagesDict objectForKey:lIso])
+ {
+ [translateTo addObject:[[LocalizationEditorLanguage alloc] initWithIsoLangCode:translateToIso]];
+ }
+ [_languages setObject:translateTo forKey:[[LocalizationEditorLanguage alloc] initWithIsoLangCode:lIso]];
+ }
+ [self updateActiveLanguages];
+ [self finishLanguageSetUp];
+}
+
+/*
+ * Remove active languages not in the keys of the global languages dictionary
+ */
+-(void)updateActiveLanguages{
+ LocalizationEditorHandler* handler = [AppDelegate appDelegate].localizationEditorHandler;
+ _activeLanguages = [[NSMutableArray alloc] initWithArray:handler.activeLanguages];
+ NSMutableArray* activeLangsCopy = _activeLanguages.copy;
+ for(LocalizationEditorLanguage* l in activeLangsCopy)
+ {
+ if(![[_languages allKeys] containsObject:l])
+ {
+ [_activeLanguages removeObject:l];
+ }
+ }
+}
+
+/*
+ * Once the languages are retrieved, this is called. The spinning wheel and
+ * message indicating downloading languages are hidden. All languages' quickEdit
+ * settings are checked off, and if there are active languages, the pop-up
+ * 'translate from' menu is set up and, in that function, the language table's
+ * data is reloaded.
+ * If there are no active languages that we can translate from
+ * then a the pop-up menu is disabled, an error message is shown.
+ */
+-(void)finishLanguageSetUp{
+
+ [_languagesDownloading stopAnimation:self];
+ [self uncheckLanguageDict];
+ if(_activeLanguages.count)
+ {
+ LocalizationEditorLanguage* l = [_activeLanguages objectAtIndex:0];
+ _currLang = l;
+ _popTranslateFrom.title = l.name;
+ [self enableAllExceptButtons];
+ [_translateFromTabView selectTabViewItemAtIndex:standardLangsIndex];
+ [self updateLanguageSelectionMenu:0];
+ }
+ else
+ {
+ _currLang = NULL;
+ _popTranslateFrom.title = noActiveLangsString;
+ [self updateNoActiveLangsError];
+ [_translateFromTabView selectTabViewItemAtIndex:noActiveLangsIndex];
+ }
+}
+
+/*
+ * If this is coming out of an instance where the language selection menu has to be
+ * updated without a user selection (the initial post-download call) everything is normal. But
+ * if this is just a normal user selection, and the user reselected the current language,
+ * ignore this and return.
+ *
+ * Otherwise, remove all items from the menu, then put all the active langauges back into it.
+ * Set the global currLang to the newly selected language and then update the main language
+ * table and the check-all box accordingly. Dispatch get main queue is used because it makes this work.
+ */
+- (void) updateLanguageSelectionMenu:(int)userSelection
+{
+
+ NSString* newLangSelection = _popTranslateFrom.selectedItem.title;
+ if(userSelection && [newLangSelection isEqualToString:_currLang.name])
+ {
+ return;
+ }
+ if(!_currLang)
+ {
+ newLangSelection = ((LocalizationEditorLanguage*)[_activeLanguages objectAtIndex:0]).name;
+ }
+
+ [_popTranslateFrom removeAllItems];
+ NSMutableArray* langTitles = [NSMutableArray array];
+ for (LocalizationEditorLanguage* lang in _activeLanguages)
+ {
+ if([lang.name isEqualToString:newLangSelection])
+ {
+ _currLang = lang;
+ }
+ [langTitles addObject:lang.name];
+ }
+
+ [_popTranslateFrom addItemsWithTitles:langTitles];
+
+ if (newLangSelection)
+ {
+ [_popTranslateFrom selectItemWithTitle:newLangSelection];
+ }
+
+ dispatch_async(dispatch_get_main_queue(), ^{
+ [_languageTable reloadData];
+ });
+ [self updateCheckAll];
+
+}
+
+/*
+ * Called when window reopened, just in case things were changed on the editor window
+ */
+-(void)refresh{
+ [self updateActiveLanguages];
+ [self finishLanguageSetUp];
+ [_languageTable reloadData];
+ [self getCostEstimate];
+}
+
+#pragma mark Downloading Cost Estimate and Word Count
+
+/*
+ * Gets the estimated cost of a translation request using the currrent user-set parameters.
+ * Updates phrases to translate, returning the number of phrases the user is asking to
+ * translate. Set both the number of words and the cost to 0 if there are 0 phrases to
+ * translate.
+ *
+ * We then start the spinning download image and a download message, and send the array of
+ * phrases as a post request to the the 'estimate' spritebuilder URL, and receive the number
+ * of the appropriate Apple Price Tier and the number of words that are in the the phrase we
+ * want to translate. We then send that price tier to Apple to come up with the appropriate,
+ * localized price.
+ */
+-(void)getCostEstimate{
+ [self disableAllExceptButtons];
+ [_translateFromTabView selectTabViewItemAtIndex:standardLangsIndex];
+ NSInteger phrases = [self updatePhrasesToTranslate];
+ if(phrases == 0)
+ {
+ _cost.stringValue = _numWords.stringValue = @"0";
+ [_buy setEnabled:0];
+ [self enableAllExceptButtons];
+ return;
+ }
+ [_costDownloading setHidden:0];
+ [_costDownloadingText setHidden:0];
+ [_costDownloading startAnimation:self];
+ NSDictionary *JSONObject = [[NSDictionary alloc] initWithObjectsAndKeys:
+ _guid,@"key",
+ _phrasesToTranslate,@"phrases",
+ nil];
+ NSError *error;
+ NSData *postdata = [NSJSONSerialization dataWithJSONObject:JSONObject options:0 error:&error];
+ if(error)
+ {
+ NSLog(@"Error: %@", error);
+ }
+ NSURL *url = [NSURL URLWithString:estimateURL];
+ NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
+ request.HTTPMethod = @"POST";
+ request.HTTPBody = postdata;
+ [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
+ NSURLSessionDataTask *task = [[NSURLSession sharedSession] dataTaskWithRequest: request
+ completionHandler:^(NSData *data,
+ NSURLResponse *response,
+ NSError *error)
+ {
+ if (!error)
+ {
+ [self parseJSONEstimate:data];
+ if(_tierForTranslations > 0)
+ {
+ [self requestIAPProducts];
+ }
+ else
+ {
+ [self enableAllExceptButtons];
+ [_costDownloading stopAnimation:self];
+ [_costDownloading setHidden:1];
+ [_costDownloadingText setHidden:1];
+ [_translateFromTabView selectTabViewItemAtIndex:downloadCostErrorIndex];
+ }
+ NSLog(@"Estimate Status code: %li", ((NSHTTPURLResponse *)response).statusCode);
+ }
+ else
+ {
+ [self enableAllExceptButtons];
+ [_costDownloading stopAnimation:self];
+ [_costDownloading setHidden:1];
+ [_costDownloadingText setHidden:1];
+ [_translateFromTabView selectTabViewItemAtIndex:downloadCostErrorIndex];
+ NSLog(@"Estimate Error: %@", error.localizedDescription);
+ }
+ }];
+ [task resume];
+ _currTask = task;
+}
+
+/*
+ * Goes through every LocalizationEditorTranslation, first seeing if there is a
+ * version of the phrase in the 'translate from' language that isn't null or just
+ * whitespace.
+ * Then it populates an array of the isoCodes for every language the phrase should be
+ * translated to. (If we are ignoring already translated text, this is every language
+ * with 'quick edit' enable. If we aren't, this is only those translations that don't
+ * have a translation string already.)
+ * If that array remains unpopulated, then we ignore this translation. Else we then add the
+ * count of the array to the number of tranlsations to download (for the progress bar later).
+ * Then we create a dictionary of the 'translate from' text, the context (if it exists), the
+ * source language (currLang), the languages to translate to and add that dictionary to an array
+ * of phrases.
+ *
+ * Return the number of phrases to translate.
+ */
+-(NSInteger)updatePhrasesToTranslate{
+ LocalizationEditorHandler* handler = [AppDelegate appDelegate].localizationEditorHandler;
+ NSMutableArray* trans = handler.translations;
+ _phrasesToTranslate = [[NSMutableArray alloc] init];
+ _numTransToDownload = 0;
+ for(LocalizationEditorTranslation* t in trans)
+ {
+ NSString* toTranslate = [t.translations objectForKey:_currLang.isoLangCode];
+ NSCharacterSet *set = [NSCharacterSet whitespaceCharacterSet];
+ if(!toTranslate || [toTranslate isEqualToString:@""]
+ || ([[toTranslate stringByTrimmingCharactersInSet: set] length] == 0))
+ {
+ continue;
+ }
+ NSMutableArray* langsToTranslate = [[NSMutableArray alloc] init];
+ for(LocalizationEditorLanguage* l in [_languages objectForKey:_currLang])
+ {
+ NSString* tempTrans = [t.translations objectForKey:l.isoLangCode];
+ if((!tempTrans || [tempTrans isEqualToString:@""]) || !_ignoreText.state)
+ {
+ if(l.quickEdit)
+ {
+ [langsToTranslate addObject:l.isoLangCode];
+ }
+ }
+ }
+ if(!langsToTranslate.count)
+ {
+ continue;
+ }
+ _numTransToDownload += langsToTranslate.count;
+ NSDictionary *phrase;
+ if(t.comment && ![t.comment isEqualToString:@""])
+ {
+ phrase = [[NSDictionary alloc] initWithObjectsAndKeys:
+ [t.translations objectForKey:_currLang.isoLangCode], @"text",
+ t.comment, @"context",
+ _currLang.isoLangCode,@"source_language",
+ langsToTranslate,@"target_languages",
+ nil];
+ }
+ else
+ {
+ phrase = [[NSDictionary alloc] initWithObjectsAndKeys:
+ [t.translations objectForKey:_currLang.isoLangCode], @"text",
+ _currLang.isoLangCode,@"source_language",
+ langsToTranslate,@"target_languages",
+ nil];
+ }
+ [_phrasesToTranslate addObject:phrase];
+ }
+ return _phrasesToTranslate.count;
+}
+
+/*
+ * Parses the JSON response from a request for a cost estimate. Sets the tier for
+ * translations, and the number of words we asked to translate as determined by
+ * the server. Handles error and sets the translation tier and number of words.
+ */
+-(void)parseJSONEstimate:(NSData*)data{
+ NSError *JSONerror;
+ NSDictionary* dataDict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&JSONerror];
+ if(JSONerror || [[[dataDict allKeys] firstObject] isEqualToString:@"Error"])
+ {
+ [self printJSONOrNormalErrorForFunction:@"Estimate" JSONError:JSONerror Error:[dataDict objectForKey:@"Error"]];
+ [self enableAllExceptButtons];
+ [_costDownloading stopAnimation:self];
+ [_costDownloading setHidden:1];
+ [_costDownloadingText setHidden:1];
+ [_translateFromTabView selectTabViewItemAtIndex:downloadCostErrorIndex];
+ return;
+ }
+ _tierForTranslations = [[dataDict objectForKey:@"iap_price_tier"] intValue];
+ _numWords.stringValue = [[dataDict objectForKey:@"wordcount"] stringValue];
+}
+
+/*
+ * Get the IAP PIDs from the correct plist, put those into a Products Request and start that request.
+ */
+-(void)requestIAPProducts{
+ NSURL *url = [[NSBundle mainBundle] URLForResource:@"LocalizationInAppPurchasesPIDs" withExtension:@".plist"];
+ NSSet* identifierSet = [NSSet setWithObject:[[NSArray arrayWithContentsOfURL:url] objectAtIndex:(_tierForTranslations-1)]];
+ SKProductsRequest* request = [[SKProductsRequest alloc] initWithProductIdentifiers:identifierSet];
+ [request setDelegate:self];
+ [request start];
+}
+
+#pragma mark Toggling/Clicking Button Events
+
+/*
+ * Solicit a payment after showing a warning about long download times.
+ */
+- (IBAction)buy:(id)sender {
+ NSInteger continueDownload;
+ if(![[AppDelegate appDelegate] showHelpDialog:@"longDownloadTime"])
+ {
+ return;
+ }
+ continueDownload = [_buyAlert runModal];
+ if ([[_buyAlert suppressionButton] state] == NSOnState)
+ {
+ [[AppDelegate appDelegate] disableHelpDialog:@"longDownloadTime"];
+ }
+ if((continueDownload == NSAlertDefaultReturn) && [SKPaymentQueue canMakePayments])
+ {
+ [[AppDelegate appDelegate].lto setLtw:self];
+ SKPaymentQueue* defaultQueue = [SKPaymentQueue defaultQueue];
+ SKPayment* payment = [SKPayment paymentWithProduct:_product];
+ [defaultQueue addPayment:payment];
+ [_paymentValidating startAnimation:self];
+ [_translateFromTabView selectTabViewItemAtIndex:validatingPaymentIndex];
+ [self disableAll];
+ }
+}
+
+/*
+ * Close the window.
+ */
+- (IBAction)cancel:(id)sender {
+ [NSApp endSheet:self.window];
+ [self.window close];
+}
+
+/*
+ * If a user clicks or unclicks ignore then update the cost of the translations
+ * they are seeking.
+ */
+- (IBAction)toggleIgnore:(id)sender {
+ [self getCostEstimate];
+}
+
+/*
+ * Update the langauge select menu if someone has selected the pop-up
+ * 'translate from' menu. Send 1 because this is a
+ * user-click generated event.
+ */
+- (IBAction)selectedTranslateFromMenu:(id)sender {
+ [self updateLanguageSelectionMenu:1];
+}
+
+/*
+ * If the check all box has been clicked, turn off mixed state (so
+ * people can only go from no check to check) and update the quickEdit
+ * state of all languages in the array of 'translate to' langauges for
+ * the current language and reload the main language table.
+ */
+- (IBAction)toggleCheckAll:(id)sender {
+ _checkAll.allowsMixedState = 0;
+ for (LocalizationEditorLanguage* l in [_languages objectForKey:_currLang])
+ {
+ l.quickEdit = _checkAll.state;
+ }
+ [_languageTable reloadData];
+}
+
+/*
+ * Clicked if there was an error in downloading languages and the user
+ * wants to retry
+ */
+- (IBAction)retryLanguages:(id)sender {
+ [self getLanguagesFromServer];
+}
+
+/*
+ * Clicked if there was an error in downloading cost Estimate and the user
+ * wants to retry
+ */
+- (IBAction)retryCost:(id)sender {
+ [self getCostEstimate];
+}
+
+#pragma mark Update Error Strings and the 'Check All' Button
+
+/*
+ * Put all the available 'translate from' languages in the no active languages error
+ */
+-(void)updateNoActiveLangsError{
+
+ NSMutableString* s = [[NSMutableString alloc] initWithString:@""];
+ for(LocalizationEditorLanguage* l in [_languages allKeys])
+ {
+ if(![s isEqualToString:@""])
+ {
+ [s appendString:@"\r\r"];
+ }
+ [s appendString:l.name];
+ }
+ _noActiveLangsError.stringValue = [NSString stringWithFormat:noActiveLangsErrorString, s];
+}
+
+/*
+ * Go through the dictionary of 'translate to' languages for the current language
+ * and update the check all box accordingly
+ */
+-(void)updateCheckAll{
+ BOOL checkAllFalse = 0;
+ BOOL checkAllTrue = 1;
+ for(LocalizationEditorLanguage* l in [_languages objectForKey:_currLang])
+ {
+ if(!l.quickEdit)
+ {
+ checkAllTrue = 0;
+ }
+ else
+ {
+ checkAllFalse = 1;
+ }
+ }
+ if(checkAllFalse && !checkAllTrue)
+ {
+ _checkAll.allowsMixedState = 1;
+ _checkAll.state = -1;
+ }
+ else if(!checkAllFalse)
+ {
+ _checkAll.allowsMixedState = 0;
+ _checkAll.state = 0;
+ }
+ else
+ {
+ _checkAll.allowsMixedState = 0;
+ _checkAll.state = 1;
+ }
+}
+
+#pragma mark Table View Delegate
+
+/*
+ * If there's no current language then there's going to be nothing to
+ * put in the tableView, so just return 0 for the size. Else, get the
+ * cost with the updated parameters and return the count of the array
+ * of 'translate to' languages associate with the current language.
+ */
+- (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView
+{
+
+ if(!_currLang)
+ {
+ return 0;
+ }
+ [self getCostEstimate];
+ return ((NSArray*)[_languages objectForKey:_currLang]).count;
+}
+
+/*
+ * If there's no current language then there's going to be nothing to put in the tableView,
+ * so just return 0. Else, just return the values for stuff from the 'translate from' array
+ * for the current language.
+ */
+- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
+{
+ if(!_currLang)
+ {
+ return 0;
+ }
+ if ([aTableColumn.identifier isEqualToString:@"enabled"])
+ {
+ LocalizationEditorLanguage* lang = [((NSArray*)[_languages objectForKey:_currLang]) objectAtIndex:rowIndex];
+ return [NSNumber numberWithBool:lang.quickEdit];
+ }
+ else if ([aTableColumn.identifier isEqualToString:@"name"])
+ {
+ LocalizationEditorLanguage* lang = [((NSArray*)[_languages objectForKey:_currLang]) objectAtIndex:rowIndex];
+ return lang.name;
+ }
+ return NULL;
+}
+
+/*
+ * Update the check all box and get new cost when the user toggles one of the languages in the main language table.
+ */
+- (void) tableView:(NSTableView *)tableView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
+{
+ if ([tableColumn.identifier isEqualToString:@"enabled"])
+ {
+ LocalizationEditorLanguage* lang = [((NSArray*)[_languages objectForKey:_currLang]) objectAtIndex:row];
+ lang.quickEdit = [object boolValue];
+ [self updateCheckAll];
+ [self getCostEstimate];
+ }
+}
+
+#pragma mark Product Request Delegate
+
+/*
+ * If product request fails, say that the cost estimate failed.
+ */
+-(void) request:(SKRequest *)request didFailWithError:(NSError *)error{
+ [self enableAllExceptButtons];
+ [_costDownloading stopAnimation:self];
+ [_costDownloading setHidden:1];
+ [_costDownloadingText setHidden:1];
+ [_translateFromTabView selectTabViewItemAtIndex:downloadCostErrorIndex];
+ NSLog(@"Product Request Failed: %@", error.localizedDescription);
+}
+
+/*
+ * Takes in the products returned by apple, prints any invalid identifiers and displays
+ * the price of those products.
+ */
+-(void) productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response{
+ _product = response.products[0];
+ for(NSString *invalidIdentifier in response.invalidProductIdentifiers)
+ {
+ [_translateFromTabView selectTabViewItemAtIndex:downloadCostErrorIndex];
+ [self enableAllExceptButtons];
+ [_costDownloading stopAnimation:self];
+ [_costDownloading setHidden:1];
+ [_costDownloadingText setHidden:1];
+ NSLog(@"Invalid Identifier: %@",invalidIdentifier);
+ return;
+ }
+ [self displayPrice];
+}
+
+#pragma mark Validate Receipt and Set Up Downloading Translations
+
+/*
+ * Validates the receipt with our server. If receipt is valid, set up timer for future
+ * 'get translation' events, and close the translation window. Also, set up the main editor
+ * window for its 'downloading translations' phase.
+ */
+-(void)validateReceipt:(NSString *)receipt{
+ NSDictionary *JSONObject = [[NSDictionary alloc] initWithObjectsAndKeys: _guid,@"key",receipt,@"receipt",_phrasesToTranslate,@"phrases",nil];
+ NSError *error;
+ NSData *postdata2 = [NSJSONSerialization dataWithJSONObject:JSONObject options:0 error:&error];
+ NSURL *url = [NSURL URLWithString:receiptTranslationsURL];
+ NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
+ request.HTTPMethod = @"POST";
+ request.HTTPBody = postdata2;
+ [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
+ NSURLSessionDataTask *task = [[NSURLSession sharedSession] dataTaskWithRequest: request
+ completionHandler:^(NSData *data,
+ NSURLResponse *response,
+ NSError *error)
+ {
+ if (!error)
+ {
+ if(![self parseJSONConfirmation:data])
+ {
+
+ ProjectSettings* ps = [AppDelegate appDelegate].projectSettings;
+ ps.numToDownload = _numTransToDownload;
+ [ps store];
+ [self getTranslations];
+ dispatch_async(dispatch_get_main_queue(), ^{
+ _timerTransDownload = [NSTimer scheduledTimerWithTimeInterval:downloadRepeatInterval target:self selector:@selector(getTranslations) userInfo:nil repeats:YES];
+ [NSApp endSheet:self.window];
+ [self.window close];
+ [self setLanguageWindowDownloading];
+ LocalizationEditorHandler* handler = [AppDelegate appDelegate].localizationEditorHandler;
+ [handler setEdited];
+ });
+ [self enableAll];
+ [_paymentValidating stopAnimation:self];
+ [_translateFromTabView selectTabViewItemAtIndex:standardLangsIndex];
+ }
+ NSLog(@"Receipt Validation status code: %li", ((NSHTTPURLResponse *)response).statusCode);
+ }
+ else
+ {
+ [self enableAll];
+ [_translateFromTabView selectTabViewItemAtIndex:paymentErrorIndex];
+ NSLog(@"Receipt Validation error: %@", error.localizedDescription);
+ }
+ }];
+ [task resume];
+ _currTask = task;
+}
+
+/*
+ * JSON confirmation just gives latest request ID. Put that in the project settings.
+ */
+-(int)parseJSONConfirmation:(NSData *)data{
+ NSError *JSONError;;
+ NSDictionary* initialTransDict = [NSJSONSerialization JSONObjectWithData:data
+ options:kNilOptions error:&JSONError];
+ if(JSONError || [[[initialTransDict allKeys] firstObject] isEqualToString:@"Error"])
+ {
+ [self printJSONOrNormalErrorForFunction:@"Request Confirmation" JSONError:JSONError Error:[initialTransDict objectForKey:@"Error"]];
+ [self enableAll];
+ [_paymentValidating stopAnimation:self];
+ [_translateFromTabView selectTabViewItemAtIndex:paymentErrorIndex];
+ return -1;
+ }
+ _latestRequestID = [initialTransDict objectForKey:@"request_id"];
+ ProjectSettings* ps = [AppDelegate appDelegate].projectSettings;
+ ps.latestRequestID = _latestRequestID;
+ [ps store];
+ return 0;
+}
+
+/*
+ * Set the 'downloading languages' for each translation and call the localization editor
+ * window's own 'set downloading translations' function.
+ */
+-(void)setLanguageWindowDownloading{
+ LocalizationEditorHandler* handler = [AppDelegate appDelegate].localizationEditorHandler;
+ NSArray* translations = handler.translations;
+ for(LocalizationEditorTranslation* t in translations)
+ {
+ for(NSDictionary* d in _phrasesToTranslate)
+ {
+ NSString* sourceText = [t.translations objectForKey:[d objectForKey:@"source_language"]];
+ if([sourceText isEqualToString:[d objectForKey:@"text"]] && [t.comment isEqualToString:[d objectForKey:@"context"]])
+ {
+ t.languagesDownloading = [NSMutableArray arrayWithArray:[d objectForKey:@"target_languages"]];
+ [_parentWindow addLanguages:[d objectForKey:@"target_languages"]];
+ }
+ }
+ }
+ [_parentWindow setDownloadingTranslations];
+}
+
+#pragma mark Download Translations
+
+/*
+ * Get translations for the user and parse them into the current localization editor window.
+ */
+-(void)getTranslations{
+ NSString* URLstring = [NSString stringWithFormat:translationsURL, _guid];
+ NSURL* url = [NSURL URLWithString:URLstring];
+ NSURLSessionDataTask *task = [[NSURLSession sharedSession] dataTaskWithURL: url
+ completionHandler:^(NSData *data,
+ NSURLResponse *response,
+ NSError *error)
+ {
+ if (!error)
+ {
+ if(![self parseJSONTranslations:data])
+ {
+ numTimedOutIntervals = 0;
+ }
+ NSLog(@"Translations Status code: %li", ((NSHTTPURLResponse *)response).statusCode);
+ }
+ else
+ {
+ numTimedOutIntervals++;
+ if(numTimedOutIntervals*downloadRepeatInterval >= serverTimeOut)
+ {
+ dispatch_async(dispatch_get_main_queue(), ^{
+ [_parentWindow finishDownloadingTranslations];
+ [self cancelDownloadWithError:error];
+ NSAlert* alert = [NSAlert alertWithMessageText:@"Translation Download Failed" defaultButton:@"OK" alternateButton:NULL otherButton:NULL informativeTextWithFormat:@"Your download has failed due to an error on our servers. Please contact customer service for a full refund."];
+ [alert runModal];
+ });
+ }
+ NSLog(@"Translations Error: %@", error.localizedDescription);
+ }
+ }];
+ [task setTaskDescription:@"translations"];
+ [task resume];
+ _currTask = task;
+}
+
+/*
+ * Find the current request in the response dictionary, and parse out translations
+ * from the phrases and put them into the handler's translation objects. Then increment
+ * the parent's download progress indicator by one, and, when the download is done,
+ * end it here and finish it in the window.
+ */
+-(int)parseJSONTranslations:(NSData *)data{
+ NSError *JSONerror;
+ ProjectSettings* ps = [AppDelegate appDelegate].projectSettings;
+ NSDictionary* initialTransDict = [NSJSONSerialization JSONObjectWithData:data
+ options:NSJSONReadingMutableContainers error:&JSONerror];
+ if(JSONerror || [[[initialTransDict allKeys] firstObject] isEqualToString:@"Error"])
+ {
+ numTimedOutIntervals++;
+ if(numTimedOutIntervals*downloadRepeatInterval >= serverTimeOut)
+ {
+ dispatch_async(dispatch_get_main_queue(), ^{
+ [_parentWindow finishDownloadingTranslations];
+ [self cancelDownloadWithError:JSONerror];
+ NSAlert* alert = [NSAlert alertWithMessageText:@"Translation Download Failed" defaultButton:@"OK" alternateButton:NULL otherButton:NULL informativeTextWithFormat:@"Your download has failed due to an error on our servers. Please contact customer service for a full refund."];
+ [alert runModal];
+ });
+ }
+ NSLog(@"Translations JSONError: %@", JSONerror.localizedDescription);
+ return -1;
+ }
+ BOOL isCurrentProjectOpen = [ps.projectPathDir isEqualToString:_projectPathDir];
+ LocalizationEditorHandler* handler;
+ if(isCurrentProjectOpen)
+ {
+ handler = [AppDelegate appDelegate].localizationEditorHandler;
+ }
+ else
+ {
+
+ NSMutableDictionary* projectDict = [NSMutableDictionary dictionaryWithContentsOfFile:_projectPath];
+ if(!projectDict)
+ {
+ [self cannotFindProjectAlert:_projectPath];
+ [self pauseDownload];
+ return -1;
+ }
+ ps = [[ProjectSettings alloc] initWithSerialization:projectDict];
+ if(!ps)
+ {
+ [self cannotFindProjectAlert:_projectPath];
+ [self pauseDownload];
+ return -1;
+ }
+ ps.projectPath = _projectPath;
+ [ps store];
+ handler = [[LocalizationEditorHandler alloc] init];
+ NSString* langFile = nil;
+ for(NSDictionary *rp in ps.resourcePaths)
+ {
+ NSString *tempLangFile = [_projectPathDir stringByAppendingPathComponent:[[rp objectForKey:@"path"] stringByAppendingPathComponent:@"Strings.ccbLang"]];
+ if([[NSFileManager defaultManager] fileExistsAtPath:tempLangFile])
+ {
+ langFile = tempLangFile;
+ }
+ }
+ if(!langFile)
+ {
+ [self cannotFindProjectAlert:_projectPath];
+ [self pauseDownload];
+ return -1;
+ }
+ [handler setManagedFileForBackgroundTranslationDownload:langFile];
+ }
+ NSArray* handlerTranslations = handler.translations;
+ NSArray* requests = [initialTransDict objectForKey:@"requests"];
+ NSDictionary* request = NULL;
+ for(NSDictionary* r in requests)
+ {
+ if([[r objectForKey:@"id"] isEqualToString:_latestRequestID])
+ {
+ request = r;
+ break;
+ }
+ }
+ NSArray* phrases = [request objectForKey:@"phrases"];
+ for(NSDictionary* phrase in phrases)
+ {
+ NSString* text = [phrase objectForKey:@"text"];
+ NSString* context = [phrase objectForKey:@"context"];
+ NSString* sourceLangIso = [phrase objectForKey:@"source_language"];
+ NSArray* serverTranslations = [phrase objectForKey:@"translations"];
+ for(NSDictionary* translation in serverTranslations)
+ {
+ NSString* translationIso = [translation objectForKey:@"target_language"];
+ NSString* translationStatus = [translation objectForKey:@"status"];
+ NSString* translationText = [translation objectForKey:@"translated_text"];
+ if([translationStatus isEqualToString:@"received"])
+ {
+ for(LocalizationEditorTranslation* t in handlerTranslations)
+ {
+ NSString* sourceText = [t.translations objectForKey:sourceLangIso];
+ if([sourceText isEqualToString:text] && [t.comment isEqualToString:context] && [t.languagesDownloading containsObject:translationIso])
+ {
+ [t.translations setObject:translationText forKey:translationIso];
+ [t.languagesDownloading removeObject:translationIso];
+ ps.numDownloaded++;
+ [ps store];
+ if(isCurrentProjectOpen)
+ {
+ [_parentWindow incrementTransByOne];
+ }
+ }
+ }
+ if(isCurrentProjectOpen)
+ {
+ dispatch_async(dispatch_get_main_queue(), ^{
+ [_parentWindow reload];
+ [handler setEdited];
+ });
+ }
+ else
+ {
+ [handler storeFileForBackgroundTranslationDownload];
+ }
+ }
+ }
+ }
+ if((ps.numDownloaded == ps.numToDownload) && ps.isDownloadingTranslations)
+ {
+ [self endDownload];
+ dispatch_async(dispatch_get_main_queue(), ^{
+
+ if(isCurrentProjectOpen)
+ {
+ [_parentWindow finishDownloadingTranslations];
+
+ NSAlert* alert = [NSAlert alertWithMessageText:@"Translation Download Complete" defaultButton:@"OK" alternateButton:NULL otherButton:NULL informativeTextWithFormat:@"You have successfully translated phrases for the project: %@.", [_projectPathDir lastPathComponent]];
+ [alert runModal];
+ }
+ else
+ {
+ NSAlert* alert = [NSAlert alertWithMessageText:@"Translation Download Complete" defaultButton:@"OK" alternateButton:@"Open Project" otherButton:NULL informativeTextWithFormat:@"You have successfully translated phrases for the project: %@.", [_projectPathDir lastPathComponent]];
+ NSInteger response = [alert runModal];
+ if(response == NSAlertAlternateReturn)
+ {
+ [[AppDelegate appDelegate] openProject:_projectPathDir];
+ }
+
+ }
+ });
+ }
+ return 0;
+}
+
+/*
+ * Kills the timer for the repeated download function
+ * but doesn't stop the download in the project settings or anything.
+ * Used when a language window changes to a different project.
+ */
+- (void)pauseDownload{
+ dispatch_async(dispatch_get_main_queue(), ^{
+ [_timerTransDownload invalidate];
+ });
+}
+
+/*
+ * Restarts the timer for the download function.
+ */
+-(void)restartDownload{
+ dispatch_async(dispatch_get_main_queue(), ^{
+ if(_timerTransDownload)
+ {
+ [_timerTransDownload invalidate];
+ }
+ [self getTranslations];
+ _timerTransDownload = [NSTimer scheduledTimerWithTimeInterval:downloadRepeatInterval target:self selector:@selector(getTranslations) userInfo:nil repeats:YES];
+ });
+}
+
+/*
+ * Ends the download cleanly in the translation window.
+ */
+- (void)endDownload{
+ _numTransToDownload = 0;
+ _latestRequestID = nil;
+ dispatch_async(dispatch_get_main_queue(), ^{
+ [_timerTransDownload invalidate];
+ });
+ ProjectSettings* ps;
+ if(![[AppDelegate appDelegate].projectSettings.projectPath isEqualToString:_projectPath])
+ {
+ NSMutableDictionary* projectDict = [NSMutableDictionary dictionaryWithContentsOfFile:_projectPath];
+ if(projectDict)
+ {
+ ps = [[ProjectSettings alloc] initWithSerialization:projectDict];
+ if(ps)
+ {
+ ps.projectPath = _projectPath;
+ [ps store];
+ }
+ else
+ {
+ ps = [[ProjectSettings alloc] init];
+ }
+ }
+ else
+ {
+ ps = [[ProjectSettings alloc] init];
+ }
+ }
+ else
+ {
+ ps = [AppDelegate appDelegate].projectSettings;
+ }
+ ps.isDownloadingTranslations = 0;
+ ps.numDownloaded = 0;
+ ps.numToDownload = 0;
+ [ps store];
+ TranslationSettings *translationSettings = [TranslationSettings translationSettings];
+ [[translationSettings projectsDownloadingTranslations] removeObject:ps.projectPath];
+ [translationSettings updateTranslationSettings];
+}
+
+#pragma mark Cancel Download
+
+/*
+ * Stops the download after a cancellation request has been sent.
+ */
+- (void)cancelDownloadWithError:(NSError*)error{
+ _numTransToDownload = 0;
+ _latestRequestID = nil;
+ [_timerTransDownload invalidate];
+ ProjectSettings* ps = [AppDelegate appDelegate].projectSettings;
+ ps.isDownloadingTranslations = 0;
+ ps.numDownloaded = 0;
+ ps.numToDownload = 0;
+ [ps store];
+ TranslationSettings *translationSettings = [TranslationSettings translationSettings];
+ [[translationSettings projectsDownloadingTranslations] removeObject:ps.projectPath];
+ [translationSettings writeTranslationSettings];
+ [self sendCancelNotificationWithError:error];
+}
+
+/*
+ * Sends cancel notification to the server with an error if there was one
+ */
+-(void)sendCancelNotificationWithError:(NSError*)error{
+ NSDictionary *JSONObject;
+ if(error)
+ {
+ JSONObject = [[NSDictionary alloc] initWithObjectsAndKeys: _guid,@"key",
+ _latestRequestID,@"id",error,@"server_error",nil];
+ }
+ else
+ {
+ JSONObject = [[NSDictionary alloc] initWithObjectsAndKeys: _guid,@"key",
+ _latestRequestID,@"id",nil];
+ }
+ NSError *JSONError;
+ NSData *postdata2 = [NSJSONSerialization dataWithJSONObject:JSONObject options:0 error:&JSONError];
+ NSURL *url = [NSURL URLWithString:cancelURL];
+ NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
+ request.HTTPMethod = @"POST";
+ request.HTTPBody = postdata2;
+ [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
+ NSURLSessionDataTask *task = [[NSURLSession sharedSession] dataTaskWithRequest: request
+ completionHandler:^(NSData *data,
+ NSURLResponse *response,
+ NSError *error)
+ {
+ if (!error)
+ {
+ NSLog(@"Cancel Status code: %li", ((NSHTTPURLResponse *)response).statusCode);
+ }
+ else
+ {
+ NSLog(@"Cancel Error: %@", error.localizedDescription);
+ }
+ }];
+ [task resume];
+ _currTask = task;
+
+}
+
+#pragma mark Small functions for transaction observer
+
+-(void)saveReceipt:(NSData*)receipt transaction:(SKPaymentTransaction*)transaction{
+ [_receipts setObject:receipt forKey:transaction.transactionIdentifier];
+}
+
+-(void)setPaymentError{
+ [_paymentValidating stopAnimation:self];
+ [_translateFromTabView selectTabViewItemAtIndex:paymentErrorIndex];
+}
+
+#pragma mark Misc. helper funcs
+
+-(void)cannotFindProjectAlert:(NSString*)projectPath{
+ NSAlert* alert = [NSAlert alertWithMessageText:@"Cannot Find Project" defaultButton:@"OK" alternateButton:NULL otherButton:NULL informativeTextWithFormat:@"Could not find the project at %@, which had a pending translation download. If you moved the project, please reopen it and its Language Editor Window and the translation download will begin again. If you deleted it and would like to restart your download, please contact customer support.", projectPath];
+ [alert runModal];
+}
+/*
+ * This function uses a ternary operator! Thank you high school computer science!!
+ */
+- (void)printJSONOrNormalErrorForFunction:(NSString*)functionName JSONError:(NSError*)JSONError Error:(NSError*)error{
+ NSLog(@"%@", JSONError ? [NSString stringWithFormat:@"%@ JSONError: %@", functionName, JSONError.localizedDescription] :
+ [NSString stringWithFormat:@"%@ Error: %@", functionName, error]);
+}
+
+/*
+ * Turns off the 'quick edit' option in the languages global dictionary
+ * e.g. 'unchecks' them
+ */
+-(void)uncheckLanguageDict{
+ for(LocalizationEditorLanguage* l in [_languages allKeys])
+ {
+ l.quickEdit = 0;
+ for(LocalizationEditorLanguage* l2 in [_languages objectForKey:l])
+ {
+ l2.quickEdit = 0;
+ }
+ }
+}
+
+/*
+ * Disable everything that can be disabled (except buy button since that is handled separately according to
+ * availability of a cost estimate, and cancel, since that shouldn't usually/ever be disabled)
+ */
+-(void)disableAllExceptButtons{
+ [_popTranslateFrom setEnabled:0];
+ [_languageTable setEnabled:0];
+ [_checkAll setEnabled:0];
+ [_ignoreText setEnabled:0];
+}
+
+/*
+ * Disable everything that can be disabled
+ */
+-(void)disableAll{
+ [_popTranslateFrom setEnabled:0];
+ [_languageTable setEnabled:0];
+ [_checkAll setEnabled:0];
+ [_ignoreText setEnabled:0];
+ [_cancel setEnabled:0];
+ [_buy setEnabled:0];
+ NSButton* closeButton = [self.window standardWindowButton:NSWindowCloseButton];
+ [closeButton setEnabled:NO];
+}
+
+/*
+ * Enable everything that can be enabled (except buy button since that is handled separately according to
+ * availability of a cost estimate, and cancel, since that shouldn't usually/ever be disabled)
+ * Use on main queue because that makes it work.
+ */
+-(void)enableAllExceptButtons{
+ dispatch_async(dispatch_get_main_queue(), ^{
+ [_popTranslateFrom setEnabled:YES];
+ [_languageTable setEnabled:YES];
+ [_checkAll setEnabled:YES];
+ [_ignoreText setEnabled:YES];
+ });
+}
+
+/*
+ * Enable everything that can be enabled
+ * Use on main queue because that makes it work.
+ */
+-(void)enableAll{
+ dispatch_async(dispatch_get_main_queue(), ^{
+ [_popTranslateFrom setEnabled:YES];
+ [_languageTable setEnabled:YES];
+ [_checkAll setEnabled:YES];
+ [_ignoreText setEnabled:YES];
+ [_cancel setEnabled:YES];
+ [_buy setEnabled:YES];
+ NSButton* closeButton = [self.window standardWindowButton:NSWindowCloseButton];
+ [closeButton setEnabled:YES];
+ });
+}
+
+/*
+ * Locally format the price of the current translation estimate, display it,
+ * and hide the cost downloading message and spinning icon.
+ */
+-(void)displayPrice{
+ NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
+ [numberFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
+ [numberFormatter setLocale:_product.priceLocale];
+ NSString *formattedString = [numberFormatter stringFromNumber:_product.price];
+ _cost.stringValue = formattedString;
+ [self enableAllExceptButtons];
+ [_costDownloading setHidden:1];
+ [_costDownloadingText setHidden:1];
+ [_costDownloading stopAnimation:self];
+ [_buy setEnabled:1];
+}
+@end
diff --git a/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.xib b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.xib
new file mode 100644
index 000000000..659cc2a1b
--- /dev/null
+++ b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.xib
@@ -0,0 +1,422 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/SpriteBuilder/ccBuilder/LocalizationTranslateWindowHandler.h b/SpriteBuilder/ccBuilder/LocalizationTranslateWindowHandler.h
new file mode 100644
index 000000000..469c2bbce
--- /dev/null
+++ b/SpriteBuilder/ccBuilder/LocalizationTranslateWindowHandler.h
@@ -0,0 +1,13 @@
+//
+// LocalizationTranslateWindowHandler.h
+// SpriteBuilder
+//
+// Created by Benjamin Koatz on 6/23/14.
+//
+//
+
+#import
+
+@interface LocalizationTranslateWindowHandler : NSWindow
+
+@end
\ No newline at end of file
diff --git a/SpriteBuilder/ccBuilder/LocalizationTranslateWindowHandler.m b/SpriteBuilder/ccBuilder/LocalizationTranslateWindowHandler.m
new file mode 100644
index 000000000..f7069e784
--- /dev/null
+++ b/SpriteBuilder/ccBuilder/LocalizationTranslateWindowHandler.m
@@ -0,0 +1,31 @@
+//
+// LocalizationTranslateWindowHandler.m
+// SpriteBuilder
+//
+// Created by Benjamin Koatz on 6/23/14.
+//
+//
+
+#import "LocalizationTranslateWindowHandler.h"
+#import "LocalizationTranslateWindow.h"
+
+@implementation LocalizationTranslateWindowHandler
+
+/*
+ * Allows translate window to cancel the current URL task (unless its going to be a background
+ * translation download) and close itself from a modal state
+ */
+-(void)close{
+ LocalizationTranslateWindow *wc = [self windowController];
+ NSURLSessionTask *ct = [wc currTask];
+ if(ct && ct.state !=
+ NSURLSessionTaskStateCompleted && ![ct.taskDescription isEqualToString:@"translations"])
+ {
+ [ct cancel];
+ }
+ if([self isModalPanel]){
+ [NSApp endSheet:self];
+ [self orderOut:nil];
+ }
+}
+@end
diff --git a/SpriteBuilder/ccBuilder/ProjectSettings.h b/SpriteBuilder/ccBuilder/ProjectSettings.h
index 77d663145..df087090f 100644
--- a/SpriteBuilder/ccBuilder/ProjectSettings.h
+++ b/SpriteBuilder/ccBuilder/ProjectSettings.h
@@ -85,6 +85,12 @@ typedef NS_ENUM(int8_t, CCBTargetEngine)
BOOL deviceOrientationLandscapeRight;
int resourceAutoScaleFactor;
+ //Translations
+ BOOL isDownloadingTranslations;
+ double numToDownload;
+ double numDownloaded;
+ NSString* latestRequestID;
+
NSString* versionStr;
BOOL needRepublish;
@@ -138,7 +144,13 @@ typedef NS_ENUM(int8_t, CCBTargetEngine)
@property (nonatomic, assign) int resourceAutoScaleFactor;
@property (nonatomic, assign) CCBPublishEnvironment publishEnvironment;
-// *** Temporary property, do not persist ***
+//TranslationDownloads
+@property (nonatomic,assign) BOOL isDownloadingTranslations;
+@property (nonatomic,readwrite) double numToDownload;
+@property (nonatomic,assign) double numDownloaded;
+@property (nonatomic,copy) NSString* latestRequestID;
+
+// Temporary property, do not persist
@property (nonatomic) BOOL canUpdateCocos2D;
@property (nonatomic, strong) NSMutableArray *cocos2dUpdateIgnoredVersions;
diff --git a/SpriteBuilder/ccBuilder/ProjectSettings.m b/SpriteBuilder/ccBuilder/ProjectSettings.m
index 083949d0b..a3647e16c 100644
--- a/SpriteBuilder/ccBuilder/ProjectSettings.m
+++ b/SpriteBuilder/ccBuilder/ProjectSettings.m
@@ -77,6 +77,10 @@ @implementation ProjectSettings
@synthesize versionStr;
@synthesize needRepublish;
@synthesize lastWarnings;
+@synthesize isDownloadingTranslations;
+@synthesize numDownloaded;
+@synthesize numToDownload;
+@synthesize latestRequestID;
- (id) init
{
@@ -123,6 +127,12 @@ - (id) init
self.resourceProperties = [NSMutableDictionary dictionary];
+ //Translation
+ self.isDownloadingTranslations = NO;
+ self.numDownloaded = 0;
+ self.numToDownload = 0;
+ self.latestRequestID = @"";
+
// Load available exporters
self.availableExporters = [NSMutableArray array];
for (PlugInExport* plugIn in [[PlugInManager sharedManager] plugInsExporters])
@@ -163,7 +173,6 @@ - (id) initWithSerialization:(id)dict
self.publishEnabledIOS = [[dict objectForKey:@"publishEnablediPhone"] boolValue];
self.publishEnabledAndroid = [[dict objectForKey:@"publishEnabledAndroid"] boolValue];
-
self.publishResolution_ios_phone = [[dict objectForKey:@"publishResolution_ios_phone"] boolValue];
self.publishResolution_ios_phonehd = [[dict objectForKey:@"publishResolution_ios_phonehd"] boolValue];
self.publishResolution_ios_tablet = [[dict objectForKey:@"publishResolution_ios_tablet"] boolValue];
@@ -218,6 +227,13 @@ - (id) initWithSerialization:(id)dict
}
[self detectBrowserPresence];
+
+ //Translations
+ self.isDownloadingTranslations = [[dict objectForKey:@"isDownloadingTranslations"] boolValue];
+ self.numDownloaded = [[dict objectForKey:@"numDownloaded"] doubleValue];
+ self.numToDownload = [[dict objectForKey:@"numToDownload"] doubleValue];
+ self.latestRequestID = [dict objectForKey:@"latestRequestID"];
+
[self initializeVersionStringWithProjectDict:dict];
@@ -293,7 +309,17 @@ - (id) serialize
[dict setObject:[NSNumber numberWithInt:self.designTarget] forKey:@"designTarget"];
[dict setObject:[NSNumber numberWithInt:self.defaultOrientation] forKey:@"defaultOrientation"];
[dict setObject:[NSNumber numberWithInt:self.deviceScaling] forKey:@"deviceScaling"];
-
+
+ //Translations
+ [dict setObject:[NSNumber numberWithBool:self.isDownloadingTranslations]
+ forKey:@"isDownloadingTranslations"];
+ [dict setObject:[NSNumber numberWithDouble:self.numDownloaded] forKey:@"numDownloaded"];
+ [dict setObject:[NSNumber numberWithDouble:self.numToDownload] forKey:@"numToDownload"];
+ if(self.latestRequestID)
+ {
+ [dict setObject:self.latestRequestID forKey:@"latestRequestID"];
+ }
+
[dict setObject:[NSNumber numberWithInt:self.publishEnvironment] forKey:@"publishEnvironment"];
[dict setObject:[NSNumber numberWithInt:self.excludedFromPackageMigration] forKey:@"excludedFromPackageMigration"];
diff --git a/SpriteBuilder/ccBuilder/TranslationSettings.h b/SpriteBuilder/ccBuilder/TranslationSettings.h
new file mode 100644
index 000000000..052f9cd27
--- /dev/null
+++ b/SpriteBuilder/ccBuilder/TranslationSettings.h
@@ -0,0 +1,31 @@
+//
+// TranslationSettings.h
+// SpriteBuilder
+//
+// Created by Benjamin Koatz on 7/21/14.
+//
+//
+
+#import
+#import "cocos2d.h"
+#import "CocosScene.h"
+#import "SequencerJoints.h"
+
+@class AppDelegate;
+
+@interface TranslationSettings : NSObject
+{
+ NSMutableArray *_projectsDownloadingTranslations;
+}
+
+// Settings
+@property (nonatomic,strong) NSMutableArray *projectsDownloadingTranslations;
+@property (nonatomic,strong) NSObject* observer;
+
++ (TranslationSettings*) translationSettings;
+
+- (void)loadTranslationSettings;
+- (void) writeTranslationSettings;
+- (void)updateTranslationSettings;
+
+@end
diff --git a/SpriteBuilder/ccBuilder/TranslationSettings.m b/SpriteBuilder/ccBuilder/TranslationSettings.m
new file mode 100644
index 000000000..bc0cf2b46
--- /dev/null
+++ b/SpriteBuilder/ccBuilder/TranslationSettings.m
@@ -0,0 +1,112 @@
+//
+// TranslationSettings.m
+// SpriteBuilder
+//
+// Created by Benjamin Koatz on 7/21/14.
+//
+//
+
+#import "TranslationSettings.h"
+#import "AppDelegate.h"
+#import "SequencerJoints.h"
+
+
+@implementation TranslationSettings
+
+@synthesize projectsDownloadingTranslations = _projectsDownloadingTranslations;
+
+static TranslationSettings *singleton;
+
+/*
+ * Creates singleton translation settings
+ */
++ (TranslationSettings*) translationSettings
+{
+ @synchronized([TranslationSettings class])
+ {
+ if (!singleton)
+ singleton = [[self alloc] init];
+ else
+ [singleton loadTranslationSettings];
+ return singleton;
+ }
+
+ return nil;
+}
+
+/*
+ * Initializes, loads and then writes the translation settings
+ */
+- (id)init
+{
+ self = [super init];
+ if (!self) return NULL;
+
+ self.projectsDownloadingTranslations = [[[NSUserDefaults standardUserDefaults] objectForKey:@"projectsDownloadingTranslations"] mutableCopy];
+
+ if(!self.projectsDownloadingTranslations)
+ {
+ self.projectsDownloadingTranslations = [[NSMutableArray alloc] init];
+ [self writeTranslationSettings];
+ }
+
+
+ return self;
+
+}
+
+/*
+ * Writes and loads translation settings
+ */
+- (void)updateTranslationSettings
+{
+ [self writeTranslationSettings];
+ [self loadTranslationSettings];
+}
+
+/*
+ * Loads translation settings
+ */
+- (void)loadTranslationSettings
+{
+ self.projectsDownloadingTranslations = [[[NSUserDefaults standardUserDefaults] objectForKey:@"projectsDownloadingTranslations"] mutableCopy];
+
+ if(!self.projectsDownloadingTranslations)
+ {
+ self.projectsDownloadingTranslations = [[NSMutableArray alloc] init];
+ [self writeTranslationSettings];
+ }
+}
+
+/*
+ * Writes translation settings
+ */
+- (void) writeTranslationSettings
+{
+ [[NSUserDefaults standardUserDefaults] setObject:self.projectsDownloadingTranslations forKey:@"projectsDownloadingTranslations"];
+}
+
+/*
+ * Adds an observer for a keyPath
+ */
+-(void)addObserver:(NSObject *)observer forKeyPath:(NSString *)keyPath options:(NSKeyValueObservingOptions)options context:(void *)context{
+
+ if(self.observer)
+ {
+ [self removeObserver:self.observer forKeyPath:keyPath];
+ }
+ [super addObserver:observer forKeyPath:keyPath options:options context:context];
+ self.observer = observer;
+}
+
+/*
+ * Removes an observer for a keyPath
+ */
+-(void)removeObserver:(NSObject *)observer forKeyPath:(NSString *)keyPath{
+
+ [super removeObserver:observer forKeyPath:keyPath];
+ self.observer = nil;
+}
+
+
+@end