From 76a36333c19dcff6674fa7201a09f8f6b022ed67 Mon Sep 17 00:00:00 2001 From: Benjamin Koatz Date: Wed, 18 Jun 2014 12:51:27 -0700 Subject: [PATCH 01/39] Created a new translation window. Will commit more frequently in the future. Check comments for explanations --- .../SpriteBuilder.xcodeproj/project.pbxproj | 31 + .../ccBuilder/LocalizationEditorHandler.h | 1 + .../ccBuilder/LocalizationEditorHandler.m | 1 + .../ccBuilder/LocalizationEditorLanguage.h | 2 +- .../ccBuilder/LocalizationEditorLanguage.m | 26 + .../ccBuilder/LocalizationEditorTranslation.h | 3 +- .../ccBuilder/LocalizationEditorTranslation.m | 4 +- .../ccBuilder/LocalizationEditorWindow.h | 3 + .../ccBuilder/LocalizationEditorWindow.m | 38 +- .../ccBuilder/LocalizationEditorWindow.xib | 2691 +++-------------- .../LocalizationInAppPurchasesPIDs.plist | 7 + .../ccBuilder/LocalizationTranslateWindow.h | 60 + .../ccBuilder/LocalizationTranslateWindow.m | 816 +++++ .../ccBuilder/LocalizationTranslateWindow.xib | 401 +++ 14 files changed, 1804 insertions(+), 2280 deletions(-) create mode 100644 SpriteBuilder/ccBuilder/LocalizationInAppPurchasesPIDs.plist create mode 100644 SpriteBuilder/ccBuilder/LocalizationTranslateWindow.h create mode 100644 SpriteBuilder/ccBuilder/LocalizationTranslateWindow.m create mode 100644 SpriteBuilder/ccBuilder/LocalizationTranslateWindow.xib diff --git a/SpriteBuilder/SpriteBuilder.xcodeproj/project.pbxproj b/SpriteBuilder/SpriteBuilder.xcodeproj/project.pbxproj index 3bfef9b8b..da7915551 100644 --- a/SpriteBuilder/SpriteBuilder.xcodeproj/project.pbxproj +++ b/SpriteBuilder/SpriteBuilder.xcodeproj/project.pbxproj @@ -99,6 +99,10 @@ 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 */; }; + 7B5135C21947CC2500DE177D /* LocalizationInAppPurchasesPIDs.plist in Resources */ = {isa = PBXBuildFile; fileRef = 7B5135C11947CC2500DE177D /* LocalizationInAppPurchasesPIDs.plist */; }; + 7BCC1C0D194904190062DF38 /* StoreKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7BCC1C0C194904190062DF38 /* StoreKit.framework */; }; + 7BF55303193F8A7500183F09 /* LocalizationTranslateWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 7BF55302193F8A7500183F09 /* LocalizationTranslateWindow.xib */; }; + 7BF55307193F912200183F09 /* LocalizationTranslateWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = 7BF55306193F912200183F09 /* LocalizationTranslateWindow.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 */; }; @@ -1239,6 +1243,11 @@ 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 = ""; }; + 7B5135C11947CC2500DE177D /* LocalizationInAppPurchasesPIDs.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = LocalizationInAppPurchasesPIDs.plist; path = ../ccBuilder/LocalizationInAppPurchasesPIDs.plist; sourceTree = ""; }; + 7BCC1C0C194904190062DF38 /* StoreKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = StoreKit.framework; path = System/Library/Frameworks/StoreKit.framework; sourceTree = SDKROOT; }; + 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 = ""; }; @@ -2255,6 +2264,7 @@ 7789ABE8133AB10500CEFCC7 /* ApplicationServices.framework in Frameworks */, 7789ABC3133AA82000CEFCC7 /* Cocoa.framework in Frameworks */, E3AF6CDF15F0CF8B0048DB2A /* libMMMarkdown-Mac.a in Frameworks */, + 7BCC1C0D194904190062DF38 /* StoreKit.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -3035,6 +3045,7 @@ 7789ABC1133AA82000CEFCC7 /* Frameworks */ = { isa = PBXGroup; children = ( + 7BCC1C0C194904190062DF38 /* StoreKit.framework */, D35E589D18E391DA008571EC /* GLKit.framework */, D2E0168418D783C900927430 /* AppleScriptKit.framework */, DC68033A189168390060BE39 /* SpriteKit.framework */, @@ -3152,6 +3163,7 @@ 7789ACEB133AB6A700CEFCC7 /* Resources */ = { isa = PBXGroup; children = ( + 7B5135C11947CC2500DE177D /* LocalizationInAppPurchasesPIDs.plist */, DC0A8D3E18C8C274009A619D /* SpriteKitTextureAtlasToolPath.txt */, B7AC69DB17A9D9700041B8BD /* defaultTemplates.zip */, E390C780170A371E003E9E92 /* Generated */, @@ -3394,6 +3406,9 @@ children = ( B7083DF717B1CBC8006628C7 /* LocalizationEditorHandler.h */, B7083DF817B1CBC8006628C7 /* LocalizationEditorHandler.m */, + 7BF55302193F8A7500183F09 /* LocalizationTranslateWindow.xib */, + 7BF55305193F912100183F09 /* LocalizationTranslateWindow.h */, + 7BF55306193F912200183F09 /* LocalizationTranslateWindow.m */, B7083DF217B1C363006628C7 /* LocalizationEditorWindow.xib */, B7083DF417B1CB88006628C7 /* LocalizationEditorWindow.h */, B7083DF517B1CB88006628C7 /* LocalizationEditorWindow.m */, @@ -5181,6 +5196,9 @@ 7789ABBD133AA82000CEFCC7 = { DevelopmentTeam = U2K5E32W7G; SystemCapabilities = { + com.apple.InAppPurchase = { + enabled = 1; + }; com.apple.Sandbox = { enabled = 1; }; @@ -5434,6 +5452,7 @@ 92F0960818F8851300D47A94 /* inspector-body-remove-hi.png in Resources */, E35A2D8F1540111A00F78B72 /* position-2.png in Resources */, E35A2D901540111A00F78B72 /* position-3.png in Resources */, + 7B5135C21947CC2500DE177D /* LocalizationInAppPurchasesPIDs.plist in Resources */, 921EEADC18A5760700D864C2 /* joint-pivot.png in Resources */, E3EDBC1615483EE000EEF1F3 /* ResolutionSettingsWindow.xib in Resources */, E370BA0C1549B2460048ED73 /* scale-0.png in Resources */, @@ -5604,6 +5623,7 @@ B7AC69B217A1969E0041B8BD /* header-bg2.png in Resources */, B7AC69B417A1A2040041B8BD /* header-bg2-crop.png in Resources */, B72D1DC0186125E80091252F /* Requirements.plist in Resources */, + 7BF55303193F8A7500183F09 /* LocalizationTranslateWindow.xib in Resources */, B7AC69C917A70A4B0041B8BD /* inspector-codeconnections.png in Resources */, 92D9D48318F8AB3800F167C1 /* joint-connection-disconnected@2x.png in Resources */, 926D13C918B5778300582959 /* joint-distance-slide@2x.png in Resources */, @@ -6174,6 +6194,7 @@ E525FBA4E26414A8E6EBA77C /* PublishCCBOperation.m in Sources */, E525F2C0B3311DCAEC86C6B0 /* PublishImageOperation.m in Sources */, E525F3B510C25EE6D73F2C68 /* DateCache.m in Sources */, + 7BF55307193F912200183F09 /* LocalizationTranslateWindow.m in Sources */, E525F4E581031BFDE7E6DC9A /* NSString+Publishing.m in Sources */, E525FA5D4791EB730859BF2C /* ProjectSettings+Convenience.m in Sources */, E525F2137095DF73409AC768 /* PublishGeneratedFilesOperation.m in Sources */, @@ -6842,6 +6863,9 @@ ALWAYS_SEARCH_USER_PATHS = NO; ARCHS = "$(ARCHS_STANDARD_64_BIT)"; CLANG_ENABLE_OBJC_ARC = YES; + CODE_SIGN_ENTITLEMENTS = SpriteBuilder.entitlements; + CODE_SIGN_IDENTITY = "Mac Developer"; + "CODE_SIGN_IDENTITY[sdk=macosx*]" = "Mac Developer"; COPY_PHASE_STRIP = NO; GCC_DYNAMIC_NO_PIC = NO; GCC_ENABLE_OBJC_EXCEPTIONS = YES; @@ -6869,8 +6893,10 @@ "\"$(SRCROOT)/libs/Tupac\"", "\"$(SRCROOT)/libs/PVRTexTool\"", ); + "OTHER_CODE_SIGN_FLAGS[sdk=*]" = "--deep"; OTHER_LDFLAGS = "-all_load"; PRODUCT_NAME = SpriteBuilder; + PROVISIONING_PROFILE = "3C61F300-140F-4802-AB93-852E91DF6DEB"; WRAPPER_EXTENSION = app; }; name = Debug; @@ -6881,6 +6907,9 @@ ALWAYS_SEARCH_USER_PATHS = NO; ARCHS = "$(ARCHS_STANDARD_64_BIT)"; CLANG_ENABLE_OBJC_ARC = YES; + CODE_SIGN_ENTITLEMENTS = SpriteBuilder.entitlements; + CODE_SIGN_IDENTITY = "Mac Developer"; + "CODE_SIGN_IDENTITY[sdk=macosx*]" = "Mac Developer"; COPY_PHASE_STRIP = YES; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; GCC_ENABLE_OBJC_EXCEPTIONS = YES; @@ -6908,8 +6937,10 @@ "\"$(SRCROOT)/libs/Tupac\"", "\"$(SRCROOT)/libs/PVRTexTool\"", ); + "OTHER_CODE_SIGN_FLAGS[sdk=*]" = "--deep"; OTHER_LDFLAGS = "-all_load"; PRODUCT_NAME = SpriteBuilder; + PROVISIONING_PROFILE = "3C61F300-140F-4802-AB93-852E91DF6DEB"; WRAPPER_EXTENSION = app; }; name = Release; diff --git a/SpriteBuilder/ccBuilder/LocalizationEditorHandler.h b/SpriteBuilder/ccBuilder/LocalizationEditorHandler.h index 638269434..e89b8fb37 100644 --- a/SpriteBuilder/ccBuilder/LocalizationEditorHandler.h +++ b/SpriteBuilder/ccBuilder/LocalizationEditorHandler.h @@ -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; diff --git a/SpriteBuilder/ccBuilder/LocalizationEditorHandler.m b/SpriteBuilder/ccBuilder/LocalizationEditorHandler.m index bc97654ef..8dbbb9cc6 100644 --- a/SpriteBuilder/ccBuilder/LocalizationEditorHandler.m +++ b/SpriteBuilder/ccBuilder/LocalizationEditorHandler.m @@ -17,6 +17,7 @@ @implementation LocalizationEditorHandler +@synthesize currentLanguage; @synthesize languages; @synthesize activeLanguages; @synthesize translations; diff --git a/SpriteBuilder/ccBuilder/LocalizationEditorLanguage.h b/SpriteBuilder/ccBuilder/LocalizationEditorLanguage.h index aa3052501..d1a75d1bf 100644 --- a/SpriteBuilder/ccBuilder/LocalizationEditorLanguage.h +++ b/SpriteBuilder/ccBuilder/LocalizationEditorLanguage.h @@ -8,7 +8,7 @@ #import -@interface LocalizationEditorLanguage : NSObject +@interface LocalizationEditorLanguage : NSObject @property (nonatomic,copy) NSString* isoLangCode; @property (nonatomic,copy) NSString* name; diff --git a/SpriteBuilder/ccBuilder/LocalizationEditorLanguage.m b/SpriteBuilder/ccBuilder/LocalizationEditorLanguage.m index 18e46666b..854556e5b 100644 --- a/SpriteBuilder/ccBuilder/LocalizationEditorLanguage.m +++ b/SpriteBuilder/ccBuilder/LocalizationEditorLanguage.m @@ -42,5 +42,31 @@ - (id) initWithIsoLangCode:(NSString*)code return self; } +/* + * 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/LocalizationEditorTranslation.h b/SpriteBuilder/ccBuilder/LocalizationEditorTranslation.h index 34453899b..5049760af 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,copy) 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..8312ff839 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; } diff --git a/SpriteBuilder/ccBuilder/LocalizationEditorWindow.h b/SpriteBuilder/ccBuilder/LocalizationEditorWindow.h index 8c4a7c6d2..c315ab910 100644 --- a/SpriteBuilder/ccBuilder/LocalizationEditorWindow.h +++ b/SpriteBuilder/ccBuilder/LocalizationEditorWindow.h @@ -7,6 +7,7 @@ // #import +@class LocalizationTranslateWindow; @interface LocalizationEditorWindow : NSWindowController { @@ -15,6 +16,7 @@ IBOutlet NSPopUpButton* popLanguageAdd; IBOutlet NSPopUpButton* popCurrentLanguage; IBOutlet NSTextView* textInspectorKey; + LocalizationTranslateWindow* _ltw; } @property (nonatomic,assign) BOOL inspectorEnabled; @@ -27,6 +29,7 @@ - (IBAction)pressedAdd:(id)sender; - (IBAction)pressedAddGroup:(id)sender; +- (IBAction)pressedTranslate:(id)sender; - (IBAction)selectedAddLanguage:(id)sender; - (void)removeLanguagesAtIndexes:(NSIndexSet*)idxs; diff --git a/SpriteBuilder/ccBuilder/LocalizationEditorWindow.m b/SpriteBuilder/ccBuilder/LocalizationEditorWindow.m index 47900b9e3..eabaf267d 100644 --- a/SpriteBuilder/ccBuilder/LocalizationEditorWindow.m +++ b/SpriteBuilder/ccBuilder/LocalizationEditorWindow.m @@ -6,14 +6,15 @@ // // +#import "LocalizationTranslateWindow.h" #import "LocalizationEditorWindow.h" #import "LocalizationEditorLanguage.h" #import "LocalizationEditorHandler.h" #import "LocalizationEditorTranslation.h" +#import "LocalizationEditorLanguageTableView.h" #import "AppDelegate.h" #import "CCBTextFieldCell.h" #import "NSPasteboard+CCB.h" - @implementation LocalizationEditorWindow #pragma mark Init and Updating stuff @@ -26,6 +27,7 @@ - (void) awakeFromNib [self updateLanguageSelectionMenu]; [self addLanguageColumns]; [self updateQuickEditLangs]; + } - (void) populateLanguageAddMenu @@ -197,6 +199,19 @@ - (IBAction)pressedAdd:(id)sender - (IBAction)pressedAddGroup:(id)sender {} +/* + * Just displays a translate window. + * TODO Make the window key and main + */ +- (IBAction)pressedTranslate:(id)sender { + _ltw = [[LocalizationTranslateWindow alloc] initWithWindowNibName:@"LocalizationTranslateWindow"]; + [[_ltw window] makeKeyAndOrderFront:nil]; +} + +/* + * If a language is added, do what is shown here but also reload the langauge menu on the + * language translation window if there is one open. + */ - (IBAction)selectedAddLanguage:(id)sender { NSString* name = popLanguageAdd.selectedItem.title; @@ -208,6 +223,8 @@ - (IBAction)selectedAddLanguage:(id)sender [self updateLanguageSelectionMenu]; [self updateQuickEditLangs]; [self updateInspector]; + if(_ltw) + [_ltw reloadLanguageMenu]; [handler setEdited]; } @@ -234,6 +251,10 @@ - (void)removeLanguagesAtIndexes:(NSIndexSet*)idxs - (IBAction)selectedCurrentLanguage:(id)sender { [self updateInspector]; +} +- (void)alertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo { + + } - (void)removeTranslationsAtIndexes:(NSIndexSet*)idxs @@ -411,13 +432,23 @@ - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColu } else { - return [translation.translations objectForKey:aTableColumn.identifier]; + if([translation.languagesDownloading containsObject:aTableColumn.identifier]){ + [[aTableColumn dataCellForRow:rowIndex] setEnabled:0]; + return @"Downloading..."; + }else{ + [[aTableColumn dataCellForRow:rowIndex] setEnabled:1]; + return [translation.translations objectForKey:aTableColumn.identifier]; + } } } return NULL; } +/* + * If a translation is updated, update the tableView in the translation window if there + * is one open. + */ - (void) tableView:(NSTableView *)tableView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row { LocalizationEditorHandler* handler = [AppDelegate appDelegate].localizationEditorHandler; @@ -481,6 +512,8 @@ - (void) tableView:(NSTableView *)tableView setObjectValue:(id)object forTableCo [tableTranslations reloadDataForRowIndexes:[NSIndexSet indexSetWithIndex:row] columnIndexes:[NSIndexSet indexSetWithIndex:0]]; [handler setEdited]; } + if(_ltw) + [_ltw reloadCost]; } [self updateInspector]; @@ -602,6 +635,7 @@ - (void) textDidEndEditing:(NSNotification *)notification { [handler setEdited]; } + } #pragma mark Split view delegate diff --git a/SpriteBuilder/ccBuilder/LocalizationEditorWindow.xib b/SpriteBuilder/ccBuilder/LocalizationEditorWindow.xib index 069bae88d..02da88597 100644 --- a/SpriteBuilder/ccBuilder/LocalizationEditorWindow.xib +++ b/SpriteBuilder/ccBuilder/LocalizationEditorWindow.xib @@ -1,2274 +1,417 @@ - - - - 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 - - - 256 - {565, 17} - - - - _NS:16 - - - - - -2147483392 - {{224, 0}, {16, 17}} - - _NS:19 - - - - warning - 20 - 20 - 20 - - 75497536 - 2048 - - - LucidaGrande - 11 - 3100 - - - 3 - MC4zMzMzMzI5ODU2AA - - - 6 - System - headerTextColor - - 3 - MAA - - - - - 134217728 - 33685504 - _NS:9 - 0 - 0 - 0 - NO - - - - - key - 200 - 100 - 1000 - - 75497536 - 2048 - Key - - - - - - 337641536 - 133120 - Text Cell - - - - 6 - System - controlBackgroundColor - - 3 - MC42NjY2NjY2NjY3AA - - - - 6 - System - controlTextColor - - - - 3 - YES - YES - - - - comment - 200 - 100 - 1000 - - 75497536 - 2048 - Comment - - - 3 - MC4zMzMzMzI5ODU2AA - - - - - 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 - {{62, 336}, {230, 22}} - - - - _NS:9 - YES - - -2076180416 - 133120 - - _NS:9 - - 109199360 - 129 - - - 400 - 75 - - - Item 1 - - 1048576 - 2147483647 - 1 - - NSImage - NSMenuCheckmark - - - NSImage - NSMenuMixedState - - _popUpItemAction: - - - YES - - OtherViews - - - - - Item 2 - - 1048576 - 2147483647 - - - _popUpItemAction: - - - - - Item 3 - - 1048576 - 2147483647 - - - _popUpItemAction: - - - - - LucidaGrande - 13 - 1044 - - - 1 - YES - YES - 2 - - NO - - - - 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 - - 75497536 - 2048 - - - - 3 - MC4zMzMzMzI5ODU2AA - - - - - 67108864 - 268566528 - - - _NS:9 - - 1211912448 - 2 - - NSImage - NSSwitch - - - NSSwitch - - - - 200 - 25 - - 3 - YES - YES - - - - name - 248 - 40 - 1000 - - 75497536 - 2048 - - - - - - - 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 - - - - 289 - {{760, -1}, {104, 22}} - - - - _NS:9 - YES - - -2080374720 - 134350848 - - _NS:9 - - -2034614272 - 134 - - - 400 - 75 - - - YES - Add Language - - 1048576 - 2147483647 - 1 - - - - _popUpItemAction: - - - YES - - OtherViews - - - - - - YES - 1 - YES - YES - - 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/LocalizationInAppPurchasesPIDs.plist b/SpriteBuilder/ccBuilder/LocalizationInAppPurchasesPIDs.plist new file mode 100644 index 000000000..8317b8548 --- /dev/null +++ b/SpriteBuilder/ccBuilder/LocalizationInAppPurchasesPIDs.plist @@ -0,0 +1,7 @@ + + + + + com.spritebuilder.translationstier1 + + diff --git a/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.h b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.h new file mode 100644 index 000000000..90e0b2647 --- /dev/null +++ b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.h @@ -0,0 +1,60 @@ +// +// LocalizationTranslateWindow.h +// SpriteBuilder +// +// Created by Benjamin Koatz on 6/4/14. +// +// + +#import +#import + +@class LocalizationEditorLanguage; +@class LocalizationEditorWindow; + +@interface LocalizationTranslateWindow : NSWindowController +{ + NSEvent * (^monitorHandler)(NSEvent *); + IBOutlet NSButton *_buy; + NSEvent* eventMon; + IBOutlet NSTableView* _languageTable; + IBOutlet NSTextField* _numWords; + IBOutlet NSTextField* _numWordsText; + IBOutlet NSTextField* _cost; + IBOutlet NSTextField* _costText; + IBOutlet NSPopUpButton* _popTranslateFrom; + IBOutlet NSButton* _translateFromInfo; + NSTextView *_translateFromInfoV; + NSPopover *_translatePopOver; + IBOutlet NSTextField* _noActiveLangsError; + IBOutlet NSButton* _ignoreText; + IBOutlet NSButton* _checkAll; + IBOutlet NSButton* _cancel; + IBOutlet NSProgressIndicator* _languagesDownloading; + IBOutlet NSTextField* _languagesDownloadingText; + IBOutlet NSProgressIndicator* _costDownloading; + IBOutlet NSTextField* _costDownloadingText; + NSViewController *_translateInfoVC; + NSMutableArray* _phrasesToTranslate; + NSMutableArray* _activeLanguages; + NSMutableDictionary* _languages; + NSInteger _tierForTranslations; + NSArray *_products; + NSString* _guid; + NSMutableDictionary* _receipts; + NSInteger _numTransToDownload; + NSTimer* _timerTransDownload; + IBOutlet NSTextField* _translationsDownloadText; + IBOutlet NSProgressIndicator* _translationsProgressBar; + LocalizationEditorLanguage* _currLang; +} +- (IBAction)buy:(id)sender; +- (IBAction)cancel:(id)sender; +- (IBAction)toggleIgnore:(id)sender; +- (IBAction)selectedTranslateFromMenu:(id)sender; +- (IBAction)toggleCheckAll:(id)sender; +- (IBAction)showInfo:(id)sender; +- (void)reloadLanguageMenu; +- (void)reloadCost; +@property (strong) IBOutlet NSButton *buy; +@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..b6263e7ae --- /dev/null +++ b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.m @@ -0,0 +1,816 @@ +// +// 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" + +@implementation LocalizationTranslateWindow +/* + * Set up the guid, the languages global dictionary and get the dictionary's contents from the server + */ +-(void) awakeFromNib +{ + //_guid = [[[NSUserDefaults standardUserDefaults] dictionaryRepresentation] objectForKey:@"sbUserID"]; + _guid = [[[NSUserDefaults standardUserDefaults] dictionaryRepresentation] objectForKey:@"PayloadUUID"]; + _languages = [[NSMutableDictionary alloc] init]; + [self getLanguagesFromServer]; + [_translateFromInfoV setEditable:0]; + __weak typeof(self) weakSelf = self; + monitorHandler = ^NSEvent * (NSEvent * theEvent){ + + if(theEvent.keyCode == 36) + { + [weakSelf buy:nil]; + } + // Return the event, a new event, or, to stop + // the event from being dispatched, nil + return theEvent; + }; + + // Creates an object we do not own, but must keep track of so that + // it can be "removed" when we're done; therefore, put it in an ivar. + eventMon = [NSEvent addLocalMonitorForEventsMatchingMask:NSKeyDownMask + handler:monitorHandler]; +} + +/* + * 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 reload. If there are no active languages that we can translate from + * then a the pop-up menu is disabled, an error message with instructions is shown. + */ +-(void)finishSetUp{ + [_languagesDownloading setHidden:1]; + [_languagesDownloadingText setHidden:1]; + [_languagesDownloading stopAnimation:self]; + [self uncheckLanguageDict]; + if(_activeLanguages.count) + { + [_ignoreText setHidden:0]; + [_cost setHidden:0]; + [_numWords setHidden:0]; + [_costText setHidden:0]; + [_numWordsText setHidden:0]; + [_popTranslateFrom setEnabled:1]; + LocalizationEditorLanguage* l = [_activeLanguages objectAtIndex:0]; + _popTranslateFrom.title = l.name; + _currLang = l; + [self updateLanguageSelectionMenu:1]; + } + else + { + _currLang = NULL; + _popTranslateFrom.title = @"No Active Languages!"; + [self updateNoActiveLangsError]; + [_noActiveLangsError setHidden:0]; + } +} + +/* + * Turns off the 'quick edit' option in the languages global dictionary + */ +-(void)uncheckLanguageDict{ + for(LocalizationEditorLanguage* l in [_languages allKeys]) + { + l.quickEdit = 0; + for(LocalizationEditorLanguage* l2 in [_languages objectForKey:l]) + l2.quickEdit = 0; + } +} + +/* + * If this is coming out of a reload of the menu (the initial post-download call or reload + * after a language is added on the Language Translation window) 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 if this isn't the initial + * update (e.g. if the window is already loaded and someone is selecting a new language + * to translate from) then update the main language table and the check all box accordingly. + * If there are still languages that can be activated, update and show the missing active + * languages message. + */ +- (void) updateLanguageSelectionMenu:(NSInteger)isReload +{ + NSString* newLangSelection = _popTranslateFrom.selectedItem.title; + if(self.isWindowLoaded && _currLang && !isReload && [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]; + } + if([self isWindowLoaded]) + { + [_languageTable reloadData]; + [self updateCheckAll]; + } + if(_activeLanguages.count == [_languages allKeys].count) + { + if(_translatePopOver.isShown) + { + [_translatePopOver close]; + } + [_translateFromInfo setHidden:1]; + } + else{ + [_translateFromInfo setHidden:0]; + } +} + + +/* + * Counts the number of words in a string, counting words + * as space-separated sets of letters, including - and '. + * TODO line this up with unbabel's way of delimiting + * what's a word and what's not + */ +-(NSInteger) numWordsInPhrase:(NSString*) phrase{ + NSInteger l = phrase.length; + NSInteger words = 0; + NSInteger lastWasLetter = 0; + NSInteger firstLetterReached = 0; + NSMutableCharacterSet* letters = [NSMutableCharacterSet letterCharacterSet]; + [letters addCharactersInString:@"-'"]; + for(NSInteger i=0; i + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 157ff6add16b1e67e5334b41044278892e1726e0 Mon Sep 17 00:00:00 2001 From: Benjamin Koatz Date: Wed, 18 Jun 2014 17:38:20 -0700 Subject: [PATCH 02/39] Small project change --- SpriteBuilder/SpriteBuilder.xcodeproj/project.pbxproj | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/SpriteBuilder/SpriteBuilder.xcodeproj/project.pbxproj b/SpriteBuilder/SpriteBuilder.xcodeproj/project.pbxproj index 60b521784..aef1adf7c 100644 --- a/SpriteBuilder/SpriteBuilder.xcodeproj/project.pbxproj +++ b/SpriteBuilder/SpriteBuilder.xcodeproj/project.pbxproj @@ -6906,6 +6906,9 @@ ALWAYS_SEARCH_USER_PATHS = NO; ARCHS = "$(ARCHS_STANDARD_64_BIT)"; CLANG_ENABLE_OBJC_ARC = YES; + CODE_SIGN_ENTITLEMENTS = SpriteBuilder.entitlements; + CODE_SIGN_IDENTITY = "Mac Developer"; + "CODE_SIGN_IDENTITY[sdk=macosx*]" = "Mac Developer"; COPY_PHASE_STRIP = NO; GCC_DYNAMIC_NO_PIC = NO; GCC_ENABLE_OBJC_EXCEPTIONS = YES; @@ -6936,6 +6939,7 @@ MACOSX_DEPLOYMENT_TARGET = 10.9; OTHER_LDFLAGS = "-all_load"; PRODUCT_NAME = SpriteBuilder; + PROVISIONING_PROFILE = ""; WRAPPER_EXTENSION = app; }; name = Debug; @@ -6946,6 +6950,9 @@ ALWAYS_SEARCH_USER_PATHS = NO; ARCHS = "$(ARCHS_STANDARD_64_BIT)"; CLANG_ENABLE_OBJC_ARC = YES; + CODE_SIGN_ENTITLEMENTS = SpriteBuilder.entitlements; + CODE_SIGN_IDENTITY = "Mac Developer"; + "CODE_SIGN_IDENTITY[sdk=macosx*]" = "Mac Developer"; COPY_PHASE_STRIP = YES; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; GCC_ENABLE_OBJC_EXCEPTIONS = YES; @@ -6976,6 +6983,7 @@ MACOSX_DEPLOYMENT_TARGET = 10.9; OTHER_LDFLAGS = "-all_load"; PRODUCT_NAME = SpriteBuilder; + PROVISIONING_PROFILE = ""; WRAPPER_EXTENSION = app; }; name = Release; From 131954661d6048fb63ed7ba08c9af06fcb97f6fd Mon Sep 17 00:00:00 2001 From: Benjamin Koatz Date: Fri, 20 Jun 2014 14:37:51 -0700 Subject: [PATCH 03/39] Moved the numerous items and messages that overlapped under the 'translate from' menu into separate views of a single tab view, some other small formatting edits. --- .../ccBuilder/LocalizationEditorWindow.m | 3 +- .../ccBuilder/LocalizationEditorWindow.xib | 2 +- .../ccBuilder/LocalizationTranslateWindow.h | 9 ++-- .../ccBuilder/LocalizationTranslateWindow.m | 45 +++++-------------- 4 files changed, 19 insertions(+), 40 deletions(-) diff --git a/SpriteBuilder/ccBuilder/LocalizationEditorWindow.m b/SpriteBuilder/ccBuilder/LocalizationEditorWindow.m index eabaf267d..be87b84ce 100644 --- a/SpriteBuilder/ccBuilder/LocalizationEditorWindow.m +++ b/SpriteBuilder/ccBuilder/LocalizationEditorWindow.m @@ -244,7 +244,8 @@ - (void)removeLanguagesAtIndexes:(NSIndexSet*)idxs [self updateLanguageSelectionMenu]; [self updateQuickEditLangs]; [self updateInspector]; - + if(_ltw) + [_ltw reloadLanguageMenu]; [handler setEdited]; } diff --git a/SpriteBuilder/ccBuilder/LocalizationEditorWindow.xib b/SpriteBuilder/ccBuilder/LocalizationEditorWindow.xib index 02da88597..c3deddbf2 100644 --- a/SpriteBuilder/ccBuilder/LocalizationEditorWindow.xib +++ b/SpriteBuilder/ccBuilder/LocalizationEditorWindow.xib @@ -1,7 +1,7 @@ - + diff --git a/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.h b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.h index 90e0b2647..42c3be505 100644 --- a/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.h +++ b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.h @@ -14,24 +14,25 @@ @interface LocalizationTranslateWindow : NSWindowController { + IBOutlet NSView* _noActiveLangsView; + IBOutlet NSView* _standardLangsView; + IBOutlet NSView* _downloadingLangsView; + IBOutlet NSTabView* _translateFromTabView; NSEvent * (^monitorHandler)(NSEvent *); IBOutlet NSButton *_buy; NSEvent* eventMon; IBOutlet NSTableView* _languageTable; IBOutlet NSTextField* _numWords; - IBOutlet NSTextField* _numWordsText; IBOutlet NSTextField* _cost; - IBOutlet NSTextField* _costText; IBOutlet NSPopUpButton* _popTranslateFrom; IBOutlet NSButton* _translateFromInfo; NSTextView *_translateFromInfoV; NSPopover *_translatePopOver; IBOutlet NSTextField* _noActiveLangsError; - IBOutlet NSButton* _ignoreText; IBOutlet NSButton* _checkAll; IBOutlet NSButton* _cancel; + IBOutlet NSButton* _ignoreText; IBOutlet NSProgressIndicator* _languagesDownloading; - IBOutlet NSTextField* _languagesDownloadingText; IBOutlet NSProgressIndicator* _costDownloading; IBOutlet NSTextField* _costDownloadingText; NSViewController *_translateInfoVC; diff --git a/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.m b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.m index b6263e7ae..db7744f31 100644 --- a/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.m +++ b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.m @@ -23,23 +23,10 @@ -(void) awakeFromNib _guid = [[[NSUserDefaults standardUserDefaults] dictionaryRepresentation] objectForKey:@"PayloadUUID"]; _languages = [[NSMutableDictionary alloc] init]; [self getLanguagesFromServer]; - [_translateFromInfoV setEditable:0]; - __weak typeof(self) weakSelf = self; - monitorHandler = ^NSEvent * (NSEvent * theEvent){ - - if(theEvent.keyCode == 36) - { - [weakSelf buy:nil]; - } - // Return the event, a new event, or, to stop - // the event from being dispatched, nil - return theEvent; - }; + [[_translateFromTabView tabViewItemAtIndex:0] setView:_downloadingLangsView]; + [[_translateFromTabView tabViewItemAtIndex:1] setView:_noActiveLangsView]; + [[_translateFromTabView tabViewItemAtIndex:2] setView:_standardLangsView]; - // Creates an object we do not own, but must keep track of so that - // it can be "removed" when we're done; therefore, put it in an ivar. - eventMon = [NSEvent addLocalMonitorForEventsMatchingMask:NSKeyDownMask - handler:monitorHandler]; } /* @@ -51,17 +38,12 @@ -(void) awakeFromNib * then a the pop-up menu is disabled, an error message with instructions is shown. */ -(void)finishSetUp{ - [_languagesDownloading setHidden:1]; - [_languagesDownloadingText setHidden:1]; + [_languagesDownloading stopAnimation:self]; [self uncheckLanguageDict]; if(_activeLanguages.count) { - [_ignoreText setHidden:0]; - [_cost setHidden:0]; - [_numWords setHidden:0]; - [_costText setHidden:0]; - [_numWordsText setHidden:0]; + [_translateFromTabView selectTabViewItemAtIndex:2]; [_popTranslateFrom setEnabled:1]; LocalizationEditorLanguage* l = [_activeLanguages objectAtIndex:0]; _popTranslateFrom.title = l.name; @@ -73,7 +55,7 @@ -(void)finishSetUp{ _currLang = NULL; _popTranslateFrom.title = @"No Active Languages!"; [self updateNoActiveLangsError]; - [_noActiveLangsError setHidden:0]; + [_translateFromTabView selectTabViewItemAtIndex:1]; } } @@ -325,8 +307,7 @@ -(void)requestIAPProducts{ -(void)getLanguagesFromServer{ _popTranslateFrom.title = @"Downloading..."; [_popTranslateFrom setEnabled:0]; - [_languagesDownloading setHidden:0]; - [_languagesDownloadingText setHidden:0]; + [_translateFromTabView selectTabViewItemAtIndex:0]; [_languagesDownloading startAnimation:self]; NSString* URLstring = [NSString stringWithFormat:@"http://spritebuilder-rails.herokuapp.com/translations/languages?key=%@", _guid]; @@ -473,7 +454,8 @@ -(IBAction)unclick:(id)sender{ */ - (void)reloadLanguageMenu{ [self updateActiveLanguages]; - if(!_noActiveLangsError.isHidden) + if([_translateFromTabView indexOfTabViewItem:[_translateFromTabView selectedTabViewItem]] + == 1) { if(!_activeLanguages.count) { @@ -481,12 +463,7 @@ - (void)reloadLanguageMenu{ timer = [NSTimer scheduledTimerWithTimeInterval:.1 target:self selector:@selector(toggleNoActiveLangsAlpha) userInfo:nil repeats:NO]; return; } - [_ignoreText setHidden:0]; - [_cost setHidden:0]; - [_numWords setHidden:0]; - [_costText setHidden:0]; - [_numWordsText setHidden:0]; - [_noActiveLangsError setHidden:1]; + [_translateFromTabView selectTabViewItemAtIndex:2]; [_popTranslateFrom setEnabled:1]; [self updateLanguageSelectionMenu: 0]; }else{ @@ -520,7 +497,7 @@ -(void)updateMissingActiveLangs{ [s appendString:l.name]; } } - NSString* info = [NSString stringWithFormat: @"Remember! If you don't see a language in the menu above, it could be because you haven't activated it! You can still activate the following language(s): %@. To activate, go the Language Translation window, select \"Add Language\" and fill in the phrases you want to translate.", s]; + NSString* info = [NSString stringWithFormat: @"Additional translatable language(s): %@.\rTo activate, select \"Add Language\" in Language Translation window and add phrases you want to translate.", s]; _translateFromInfoV.string = info; } From 3d8fbbb9062c547790481ee2c0363f773e74d2e6 Mon Sep 17 00:00:00 2001 From: Benjamin Koatz Date: Fri, 20 Jun 2014 14:50:35 -0700 Subject: [PATCH 04/39] Translate window changes that I forgot to put in last commit (whoops). Also now if you delete the last active language, the window is updated to reflect the 'no active langs' error message with appropriate reloading/hiding/setting of table and drop down menu and info button --- .../ccBuilder/LocalizationTranslateWindow.m | 26 +- .../ccBuilder/LocalizationTranslateWindow.xib | 455 ++++++++++-------- 2 files changed, 282 insertions(+), 199 deletions(-) diff --git a/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.m b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.m index db7744f31..e4d96da79 100644 --- a/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.m +++ b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.m @@ -461,14 +461,26 @@ - (void)reloadLanguageMenu{ { NSTimer* timer = [NSTimer scheduledTimerWithTimeInterval:0 target:self selector:@selector(toggleNoActiveLangsAlpha) userInfo:nil repeats:NO]; timer = [NSTimer scheduledTimerWithTimeInterval:.1 target:self selector:@selector(toggleNoActiveLangsAlpha) userInfo:nil repeats:NO]; - return; } - [_translateFromTabView selectTabViewItemAtIndex:2]; - [_popTranslateFrom setEnabled:1]; - [self updateLanguageSelectionMenu: 0]; + else + { + [_translateFromTabView selectTabViewItemAtIndex:2]; + [_popTranslateFrom setEnabled:1]; + [self updateLanguageSelectionMenu: 0]; + } }else{ - [self updateMissingActiveLangs]; - [self updateLanguageSelectionMenu: 1]; + if(!_activeLanguages.count) + { + [_translateFromTabView selectTabViewItemAtIndex:1]; + [_translateFromInfo setHidden:1]; + [_popTranslateFrom setEnabled:0]; + _popTranslateFrom.title = @"No active languages!"; + _currLang = NULL; + [_languageTable reloadData]; + }else{ + [self updateMissingActiveLangs]; + [self updateLanguageSelectionMenu: 1]; + } } } @@ -516,7 +528,7 @@ -(void)updateNoActiveLangsError{ } [s appendString:l.name]; } - _noActiveLangsError.stringValue = [NSString stringWithFormat:@"You haven't added any languages that we can translate! The languages you can translate from are: %@. Add at least one of them in the Language Editor window and fill in the phrases you would like to translate.", s]; + _noActiveLangsError.stringValue = [NSString stringWithFormat:@"You haven't added any languages that we can translate! The languages you can translate from are: %@.\rAdd at least one of them in the Language Editor window and fill in the phrases you would like to translate.", s]; } /* * Go through the dictionary of 'translate to' languages for the current language diff --git a/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.xib b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.xib index 6b2fe3ee7..fdebd5cd5 100644 --- a/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.xib +++ b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.xib @@ -1,7 +1,7 @@ - + @@ -13,20 +13,23 @@ - - + + - + - + + + + @@ -35,22 +38,22 @@ - + - + - + - + - - + + @@ -68,7 +71,7 @@ - + @@ -90,7 +93,7 @@ - + - + - - - - - - - - - - + @@ -190,47 +163,24 @@ - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + - + - - + + - - + + + + + + Additional translatable language(s): English. To activate, select "Add Language" in Language Translation window and add phrases you want to translate." + + + + + + + + + + + + - + @@ -383,7 +313,7 @@ - + @@ -397,5 +327,146 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + You haven't added any languages that we can translate! The languages you can translate from are: English. Add at least one of them in the Language Editor window and fill in the phrases you would like to translate. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From a062ac242f11f45e6dbb025116ed6bf05f7833f1 Mon Sep 17 00:00:00 2001 From: Benjamin Koatz Date: Mon, 23 Jun 2014 10:20:18 -0700 Subject: [PATCH 05/39] Made it so that clicking elsewhere in the window closes the translate info popover if it is open. Also did some formatting changes to make the code a bit clearer. --- .../ccBuilder/LocalizationTranslateWindow.h | 59 ++++++++++++------- .../ccBuilder/LocalizationTranslateWindow.m | 32 ++++++---- .../ccBuilder/LocalizationTranslateWindow.xib | 3 +- .../LocalizationTranslateWindowHandler.h | 16 +++++ .../LocalizationTranslateWindowHandler.m | 32 ++++++++++ 5 files changed, 106 insertions(+), 36 deletions(-) create mode 100644 SpriteBuilder/ccBuilder/LocalizationTranslateWindowHandler.h create mode 100644 SpriteBuilder/ccBuilder/LocalizationTranslateWindowHandler.m diff --git a/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.h b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.h index 42c3be505..86c215218 100644 --- a/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.h +++ b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.h @@ -11,44 +11,60 @@ @class LocalizationEditorLanguage; @class LocalizationEditorWindow; +@class LocalizationTranslateWindowHandler; -@interface LocalizationTranslateWindow : NSWindowController +@interface LocalizationTranslateWindow : NSWindowController { + //info button + NSPopover *_translatePopOver; + NSTextView *_translateFromInfoV; + NSViewController *_translateInfoVC; + IBOutlet NSButton* _translateFromInfo; + + //tab views IBOutlet NSView* _noActiveLangsView; IBOutlet NSView* _standardLangsView; IBOutlet NSView* _downloadingLangsView; IBOutlet NSTabView* _translateFromTabView; - NSEvent * (^monitorHandler)(NSEvent *); - IBOutlet NSButton *_buy; - NSEvent* eventMon; - IBOutlet NSTableView* _languageTable; + + //fields inside tab views IBOutlet NSTextField* _numWords; IBOutlet NSTextField* _cost; - IBOutlet NSPopUpButton* _popTranslateFrom; - IBOutlet NSButton* _translateFromInfo; - NSTextView *_translateFromInfoV; - NSPopover *_translatePopOver; IBOutlet NSTextField* _noActiveLangsError; - IBOutlet NSButton* _checkAll; - IBOutlet NSButton* _cancel; - IBOutlet NSButton* _ignoreText; IBOutlet NSProgressIndicator* _languagesDownloading; IBOutlet NSProgressIndicator* _costDownloading; IBOutlet NSTextField* _costDownloadingText; - NSViewController *_translateInfoVC; - NSMutableArray* _phrasesToTranslate; - NSMutableArray* _activeLanguages; + IBOutlet NSButton* _ignoreText; + + //Language menus + IBOutlet NSPopUpButton* _popTranslateFrom; + IBOutlet NSTableView* _languageTable; + IBOutlet NSButton* _checkAll; + + //Buttons + IBOutlet NSButton* _cancel; + IBOutlet NSButton *_buy; + + //Translations downloading stuff + IBOutlet NSTextField* _translationsDownloadText; + IBOutlet NSProgressIndicator* _translationsProgressBar; + NSInteger _numTransToDownload; + NSTimer* _timerTransDownload; + + IBOutlet LocalizationTranslateWindowHandler* _w; + + //Global variables + LocalizationEditorLanguage* _currLang; NSMutableDictionary* _languages; + NSMutableArray* _activeLanguages; + NSMutableArray* _phrasesToTranslate; NSInteger _tierForTranslations; - NSArray *_products; + NSArray* _products; NSString* _guid; NSMutableDictionary* _receipts; - NSInteger _numTransToDownload; - NSTimer* _timerTransDownload; - IBOutlet NSTextField* _translationsDownloadText; - IBOutlet NSProgressIndicator* _translationsProgressBar; - LocalizationEditorLanguage* _currLang; + } + - (IBAction)buy:(id)sender; - (IBAction)cancel:(id)sender; - (IBAction)toggleIgnore:(id)sender; @@ -57,5 +73,4 @@ - (IBAction)showInfo:(id)sender; - (void)reloadLanguageMenu; - (void)reloadCost; -@property (strong) IBOutlet NSButton *buy; @end \ No newline at end of file diff --git a/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.m b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.m index e4d96da79..10f8b335b 100644 --- a/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.m +++ b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.m @@ -12,8 +12,13 @@ #import "LocalizationEditorLanguage.h" #import "LocalizationEditorTranslation.h" #import "LocalizationEditorWindow.h" +#import "LocalizationTranslateWindowHandler.h" @implementation LocalizationTranslateWindow + +static int downloadLangsIndex = 0; +static int noActiveLangsIndex = 1; +static int standardLangsIndex = 2; /* * Set up the guid, the languages global dictionary and get the dictionary's contents from the server */ @@ -22,11 +27,11 @@ -(void) awakeFromNib //_guid = [[[NSUserDefaults standardUserDefaults] dictionaryRepresentation] objectForKey:@"sbUserID"]; _guid = [[[NSUserDefaults standardUserDefaults] dictionaryRepresentation] objectForKey:@"PayloadUUID"]; _languages = [[NSMutableDictionary alloc] init]; + [[_translateFromTabView tabViewItemAtIndex:downloadLangsIndex] setView:_downloadingLangsView]; + [[_translateFromTabView tabViewItemAtIndex:noActiveLangsIndex] setView:_noActiveLangsView]; + [[_translateFromTabView tabViewItemAtIndex:standardLangsIndex] setView:_standardLangsView]; [self getLanguagesFromServer]; - [[_translateFromTabView tabViewItemAtIndex:0] setView:_downloadingLangsView]; - [[_translateFromTabView tabViewItemAtIndex:1] setView:_noActiveLangsView]; - [[_translateFromTabView tabViewItemAtIndex:2] setView:_standardLangsView]; - + [_w setPopOver:_translatePopOver button:_translateFromInfo]; } /* @@ -43,7 +48,7 @@ -(void)finishSetUp{ [self uncheckLanguageDict]; if(_activeLanguages.count) { - [_translateFromTabView selectTabViewItemAtIndex:2]; + [_translateFromTabView selectTabViewItemAtIndex:standardLangsIndex]; [_popTranslateFrom setEnabled:1]; LocalizationEditorLanguage* l = [_activeLanguages objectAtIndex:0]; _popTranslateFrom.title = l.name; @@ -55,7 +60,7 @@ -(void)finishSetUp{ _currLang = NULL; _popTranslateFrom.title = @"No Active Languages!"; [self updateNoActiveLangsError]; - [_translateFromTabView selectTabViewItemAtIndex:1]; + [_translateFromTabView selectTabViewItemAtIndex:noActiveLangsIndex]; } } @@ -307,7 +312,7 @@ -(void)requestIAPProducts{ -(void)getLanguagesFromServer{ _popTranslateFrom.title = @"Downloading..."; [_popTranslateFrom setEnabled:0]; - [_translateFromTabView selectTabViewItemAtIndex:0]; + [_translateFromTabView selectTabViewItemAtIndex:downloadLangsIndex]; [_languagesDownloading startAnimation:self]; NSString* URLstring = [NSString stringWithFormat:@"http://spritebuilder-rails.herokuapp.com/translations/languages?key=%@", _guid]; @@ -380,7 +385,7 @@ - (IBAction)buy:(id)sender { //[_buy setState:NSOnState]; SKPayment* payment = [SKPayment paymentWithProduct:[_products objectAtIndex:(_tierForTranslations -1)]]; [[SKPaymentQueue defaultQueue] addPayment:payment]; - _cancel.stringValue = @"Finish"; + _cancel.title = @"Finish"; } /* @@ -423,7 +428,7 @@ - (IBAction)toggleCheckAll:(id)sender { - (IBAction)showInfo:(id)sender { [self updateMissingActiveLangs]; if(_translateFromInfo.intValue == 1){ - [_translatePopOver showRelativeToRect:[_translateFromInfo bounds] ofView:_translateFromInfo preferredEdge:NSMaxYEdge]; + [_translatePopOver showRelativeToRect:[_translateFromInfo bounds] ofView:_translateFromInfo preferredEdge:NSMaxYEdge]; }else{ [_translatePopOver close]; } @@ -455,7 +460,7 @@ -(IBAction)unclick:(id)sender{ - (void)reloadLanguageMenu{ [self updateActiveLanguages]; if([_translateFromTabView indexOfTabViewItem:[_translateFromTabView selectedTabViewItem]] - == 1) + == noActiveLangsIndex) { if(!_activeLanguages.count) { @@ -464,14 +469,14 @@ - (void)reloadLanguageMenu{ } else { - [_translateFromTabView selectTabViewItemAtIndex:2]; + [_translateFromTabView selectTabViewItemAtIndex:standardLangsIndex]; [_popTranslateFrom setEnabled:1]; [self updateLanguageSelectionMenu: 0]; } }else{ if(!_activeLanguages.count) { - [_translateFromTabView selectTabViewItemAtIndex:1]; + [_translateFromTabView selectTabViewItemAtIndex:noActiveLangsIndex]; [_translateFromInfo setHidden:1]; [_popTranslateFrom setEnabled:0]; _popTranslateFrom.title = @"No active languages!"; @@ -607,7 +612,7 @@ - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColu } /* - * Update the check all box and get new cost when the user toggles one of the languages in the main language table. + * Update the check all box and get new cost when the user toggles one of the languages in the main language table.x */ - (void) tableView:(NSTableView *)tableView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row { @@ -802,4 +807,5 @@ -(void)parseJSONTranslations:(NSData *)data{ [_languageTable reloadData]; } + @end diff --git a/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.xib b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.xib index fdebd5cd5..77ed458ac 100644 --- a/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.xib +++ b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.xib @@ -30,12 +30,13 @@ + - + diff --git a/SpriteBuilder/ccBuilder/LocalizationTranslateWindowHandler.h b/SpriteBuilder/ccBuilder/LocalizationTranslateWindowHandler.h new file mode 100644 index 000000000..495a7b926 --- /dev/null +++ b/SpriteBuilder/ccBuilder/LocalizationTranslateWindowHandler.h @@ -0,0 +1,16 @@ +// +// LocalizationTranslateWindowView.h +// SpriteBuilder +// +// Created by Benjamin Koatz on 6/23/14. +// +// + +#import + +@interface LocalizationTranslateWindowHandler : NSWindow +@property (nonatomic,strong) NSPopover* translatePopOver; +@property (nonatomic,strong) NSButton* translateButton; +-(void)setPopOver:(NSPopover*)p button:(NSButton*)b; + +@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..11554b8bf --- /dev/null +++ b/SpriteBuilder/ccBuilder/LocalizationTranslateWindowHandler.m @@ -0,0 +1,32 @@ +// +// LocalizationTranslateWindowView.m +// SpriteBuilder +// +// Created by Benjamin Koatz on 6/23/14. +// +// + +#import "LocalizationTranslateWindowHandler.h" + + +@implementation LocalizationTranslateWindowHandler +-(void)setPopOver:(NSPopover*)p button:(NSButton*)b{ + + self.translateButton = b; + self.translatePopOver = p; + +} +-(void)mouseUp:(NSEvent *)theEvent{ + [super mouseUp:theEvent]; + if([self.translatePopOver isShown]){ + [self.translatePopOver close]; + } + self.translateButton.intValue = 0; +} + +-(id)copyWithZone:(NSZone *)zone{ + LocalizationTranslateWindowHandler* newHandler = [[[self class] allocWithZone:zone] init]; + newHandler->_translatePopOver = _translatePopOver; + return newHandler; +} +@end From c4e065823af1d960bfac85f616415e510741e217 Mon Sep 17 00:00:00 2001 From: Benjamin Koatz Date: Mon, 23 Jun 2014 10:21:07 -0700 Subject: [PATCH 06/39] just the project file from the pref commit --- SpriteBuilder/SpriteBuilder.xcodeproj/project.pbxproj | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/SpriteBuilder/SpriteBuilder.xcodeproj/project.pbxproj b/SpriteBuilder/SpriteBuilder.xcodeproj/project.pbxproj index aef1adf7c..4afcdb590 100644 --- a/SpriteBuilder/SpriteBuilder.xcodeproj/project.pbxproj +++ b/SpriteBuilder/SpriteBuilder.xcodeproj/project.pbxproj @@ -99,6 +99,7 @@ 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 */; }; + 7B3EF5DB195885F20023C169 /* LocalizationTranslateWindowHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 7B3EF5DA195885F20023C169 /* LocalizationTranslateWindowHandler.m */; }; 7B5135C21947CC2500DE177D /* LocalizationInAppPurchasesPIDs.plist in Resources */ = {isa = PBXBuildFile; fileRef = 7B5135C11947CC2500DE177D /* LocalizationInAppPurchasesPIDs.plist */; }; 7BCC1C0D194904190062DF38 /* StoreKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7BCC1C0C194904190062DF38 /* StoreKit.framework */; }; 7BF55303193F8A7500183F09 /* LocalizationTranslateWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 7BF55302193F8A7500183F09 /* LocalizationTranslateWindow.xib */; }; @@ -1255,6 +1256,8 @@ 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 = ""; }; 7B5135C11947CC2500DE177D /* LocalizationInAppPurchasesPIDs.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = LocalizationInAppPurchasesPIDs.plist; path = ../ccBuilder/LocalizationInAppPurchasesPIDs.plist; sourceTree = ""; }; 7BCC1C0C194904190062DF38 /* StoreKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = StoreKit.framework; path = System/Library/Frameworks/StoreKit.framework; sourceTree = SDKROOT; }; 7BF55302193F8A7500183F09 /* LocalizationTranslateWindow.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = LocalizationTranslateWindow.xib; sourceTree = ""; }; @@ -3435,6 +3438,8 @@ children = ( B7083DF717B1CBC8006628C7 /* LocalizationEditorHandler.h */, B7083DF817B1CBC8006628C7 /* LocalizationEditorHandler.m */, + 7B3EF5D9195885F20023C169 /* LocalizationTranslateWindowHandler.h */, + 7B3EF5DA195885F20023C169 /* LocalizationTranslateWindowHandler.m */, 7BF55302193F8A7500183F09 /* LocalizationTranslateWindow.xib */, 7BF55305193F912100183F09 /* LocalizationTranslateWindow.h */, 7BF55306193F912200183F09 /* LocalizationTranslateWindow.m */, @@ -6195,6 +6200,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 */, @@ -6937,6 +6943,8 @@ "\"$(SRCROOT)/libs/PVRTexTool\"", ); MACOSX_DEPLOYMENT_TARGET = 10.9; + OTHER_CODE_SIGN_FLAGS = "--deep"; + "OTHER_CODE_SIGN_FLAGS[sdk=*]" = "--deep"; OTHER_LDFLAGS = "-all_load"; PRODUCT_NAME = SpriteBuilder; PROVISIONING_PROFILE = ""; @@ -6981,6 +6989,7 @@ "\"$(SRCROOT)/libs/PVRTexTool\"", ); MACOSX_DEPLOYMENT_TARGET = 10.9; + OTHER_CODE_SIGN_FLAGS = "--deep"; OTHER_LDFLAGS = "-all_load"; PRODUCT_NAME = SpriteBuilder; PROVISIONING_PROFILE = ""; From 61b30ddd5827d5846c6e010e8415a5af86c483c9 Mon Sep 17 00:00:00 2001 From: Benjamin Koatz Date: Tue, 24 Jun 2014 10:53:02 -0700 Subject: [PATCH 07/39] Coordinated with the server to get language downloading and estimation working, and added a few more error views along with some internal error checking and code cleaning --- .../ccBuilder/LocalizationTranslateWindow.h | 9 +- .../ccBuilder/LocalizationTranslateWindow.m | 102 ++++++--- .../ccBuilder/LocalizationTranslateWindow.xib | 208 ++++++++++++++++-- 3 files changed, 270 insertions(+), 49 deletions(-) diff --git a/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.h b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.h index 86c215218..4c317b298 100644 --- a/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.h +++ b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.h @@ -21,10 +21,15 @@ NSViewController *_translateInfoVC; IBOutlet NSButton* _translateFromInfo; + //Window Handler (To deal with mouse events) + IBOutlet LocalizationTranslateWindowHandler* _w; + //tab views IBOutlet NSView* _noActiveLangsView; IBOutlet NSView* _standardLangsView; IBOutlet NSView* _downloadingLangsView; + IBOutlet NSView* _downloadingLangsErrorView; + IBOutlet NSView* _downloadingCostsErrorView; IBOutlet NSTabView* _translateFromTabView; //fields inside tab views @@ -51,8 +56,6 @@ NSInteger _numTransToDownload; NSTimer* _timerTransDownload; - IBOutlet LocalizationTranslateWindowHandler* _w; - //Global variables LocalizationEditorLanguage* _currLang; NSMutableDictionary* _languages; @@ -71,6 +74,8 @@ - (IBAction)selectedTranslateFromMenu:(id)sender; - (IBAction)toggleCheckAll:(id)sender; - (IBAction)showInfo:(id)sender; +- (IBAction)retryLanguages:(id)sender; +- (IBAction)retryCost:(id)sender; - (void)reloadLanguageMenu; - (void)reloadCost; @end \ No newline at end of file diff --git a/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.m b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.m index 10f8b335b..82025b72f 100644 --- a/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.m +++ b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.m @@ -19,19 +19,30 @@ @implementation LocalizationTranslateWindow static int downloadLangsIndex = 0; static int noActiveLangsIndex = 1; static int standardLangsIndex = 2; +static int downloadCostErrorIndex = 3; +static int downloadLangsErrorIndex = 4; +static NSString* languageURL = @"http://spritebuilder-meteor.herokuapp.com/api/v1/translations/languages?key=%@"; +static NSString* const estimateURL = @"http://spritebuilder-meteor.herokuapp.com/api/v1/translations/estimate"; +static NSString* const receiptURL = @"http://spritebuilder-rails.herokuapp.com/translations"; +static NSString* translationsURL = @"http://spritebuilder-rails.herokuapp.com/translations?key=%@"; +static NSString* const noActiveLangsString = @"No Active Languages!"; +static NSString* const downloadingLangsString = @"Downloading..."; +static NSString* missingActiveLangsErrorString = @"Additional translatable language(s): %@.\rTo activate, select \"Add Language\" in Language Translation window and add phrases you want to translate."; +static NSString* noActiveLangsErrorString = @"You haven't added any languages that we can translate! The languages you can translate from are: %@.\rAdd at least one of them in the Language Editor window and fill in the phrases you would like to translate."; /* * Set up the guid, the languages global dictionary and get the dictionary's contents from the server */ -(void) awakeFromNib { - //_guid = [[[NSUserDefaults standardUserDefaults] dictionaryRepresentation] objectForKey:@"sbUserID"]; - _guid = [[[NSUserDefaults standardUserDefaults] dictionaryRepresentation] objectForKey:@"PayloadUUID"]; + _guid = [[[NSUserDefaults standardUserDefaults] dictionaryRepresentation] objectForKey:@"sbUserID"]; _languages = [[NSMutableDictionary alloc] init]; [[_translateFromTabView tabViewItemAtIndex:downloadLangsIndex] setView:_downloadingLangsView]; [[_translateFromTabView tabViewItemAtIndex:noActiveLangsIndex] setView:_noActiveLangsView]; [[_translateFromTabView tabViewItemAtIndex:standardLangsIndex] setView:_standardLangsView]; - [self getLanguagesFromServer]; + [[_translateFromTabView tabViewItemAtIndex:downloadCostErrorIndex] setView:_downloadingCostsErrorView]; + [[_translateFromTabView tabViewItemAtIndex:downloadLangsErrorIndex] setView:_downloadingLangsErrorView]; [_w setPopOver:_translatePopOver button:_translateFromInfo]; + [self getLanguagesFromServer]; } /* @@ -58,7 +69,7 @@ -(void)finishSetUp{ else { _currLang = NULL; - _popTranslateFrom.title = @"No Active Languages!"; + _popTranslateFrom.title = noActiveLangsString; [self updateNoActiveLangsError]; [_translateFromTabView selectTabViewItemAtIndex:noActiveLangsIndex]; } @@ -185,6 +196,7 @@ -(NSInteger)updatePhrasesToTranslate{ LocalizationEditorHandler* handler = [AppDelegate appDelegate].localizationEditorHandler; NSMutableArray* trans = handler.translations; [_phrasesToTranslate removeAllObjects]; + _phrasesToTranslate = [[NSMutableArray alloc] init]; NSInteger words = 0; for(LocalizationEditorTranslation* t in trans) { @@ -248,7 +260,7 @@ -(NSInteger)updatePhrasesToTranslate{ * the appropriate, localized price. * TODO uncomment HTTP request. */ --(void) getCost{ +-(void)getCost{ NSInteger words = [self updatePhrasesToTranslate]; _numWords.stringValue = [NSString stringWithFormat:@"%ld", words]; @@ -257,6 +269,7 @@ -(void) getCost{ _cost.stringValue = [NSString stringWithFormat:@"%ld", words]; return; } + [_translateFromTabView selectTabViewItemAtIndex:standardLangsIndex]; [_costDownloading setHidden:0]; [_costDownloadingText setHidden:0]; [_costDownloading startAnimation:self]; @@ -264,21 +277,30 @@ -(void) getCost{ _guid,@"key", _phrasesToTranslate,@"phrases", nil]; + if(![NSJSONSerialization isValidJSONObject:JSONObject]){ + NSLog(@"Not a JSON Object!!!"); + } NSError *error; - NSData *postdata2 = [NSJSONSerialization dataWithJSONObject:JSONObject options:0 error:&error]; - NSURL *url = [NSURL URLWithString:@"http://spritebuilder-rails.herokuapp.com/translations/estimate"]; + 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 = postdata2; - /*NSURLSessionDataTask *task = [[NSURLSession sharedSession] dataTaskWithRequest: request + 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) { - NSDictionary* dataDict = (NSDictionary *)data; - tierForTranslations = [[dataDict objectForKey:@"tier"] intValue]; + [self parseJSONEstimate:data]; + if(_tierForTranslations > 0){ + [self requestIAPProducts]; + } NSLog(@"Status code: %li", ((NSHTTPURLResponse *)response).statusCode); } else @@ -286,11 +308,25 @@ -(void) getCost{ NSLog(@"Error: %@", error.localizedDescription); } }]; - [task resume];*/ - _tierForTranslations = 1; - [self requestIAPProducts]; + [task resume]; + //_tierForTranslations = 1; + //[self requestIAPProducts]; } +-(void)parseJSONEstimate:(NSData*)data{ + NSError *JSONerror; + NSDictionary* dataDict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&JSONerror]; + if(JSONerror || [[[dataDict allKeys] firstObject] isEqualToString:@"Error"]) + { + NSLog(@"%@", JSONerror ? [NSString stringWithFormat:@"JSONError: %@", JSONerror.localizedDescription] : + [NSString stringWithFormat:@"Error: %@", [dataDict objectForKey:@"Error"]]); + [_costDownloading stopAnimation:self]; + [_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. */ @@ -310,12 +346,12 @@ -(void)requestIAPProducts{ * parsed if there wasn't an error. */ -(void)getLanguagesFromServer{ - _popTranslateFrom.title = @"Downloading..."; + _popTranslateFrom.title = downloadingLangsString; [_popTranslateFrom setEnabled:0]; [_translateFromTabView selectTabViewItemAtIndex:downloadLangsIndex]; [_languagesDownloading startAnimation:self]; NSString* URLstring = - [NSString stringWithFormat:@"http://spritebuilder-rails.herokuapp.com/translations/languages?key=%@", _guid]; + [NSString stringWithFormat:languageURL, _guid]; NSURL* url = [NSURL URLWithString:URLstring]; NSURLSessionDataTask *task = [[NSURLSession sharedSession] dataTaskWithURL: url completionHandler:^(NSData *data, @@ -344,9 +380,12 @@ -(void)parseJSONLanguages:(NSData *)data{ NSError *JSONerror; NSMutableDictionary* availableLanguagesDict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&JSONerror]; - if(JSONerror) + if(JSONerror || [[[availableLanguagesDict allKeys] firstObject] isEqualToString:@"Error"]) { - NSLog(@"JSONError: %@", JSONerror.localizedDescription); + NSLog(@"%@", JSONerror ? [NSString stringWithFormat:@"JSONError: %@", JSONerror.localizedDescription] : + [NSString stringWithFormat:@"Error: %@", [availableLanguagesDict objectForKey:@"Error"]]); + [_languagesDownloading stopAnimation:self]; + [_translateFromTabView selectTabViewItemAtIndex:downloadLangsErrorIndex]; return; } for(NSString* lIso in availableLanguagesDict.allKeys) @@ -385,7 +424,7 @@ - (IBAction)buy:(id)sender { //[_buy setState:NSOnState]; SKPayment* payment = [SKPayment paymentWithProduct:[_products objectAtIndex:(_tierForTranslations -1)]]; [[SKPaymentQueue defaultQueue] addPayment:payment]; - _cancel.title = @"Finish"; + _buy.title = @"Finish"; } /* @@ -433,6 +472,16 @@ - (IBAction)showInfo:(id)sender { [_translatePopOver close]; } } + +- (IBAction)retryLanguages:(id)sender { + [self getLanguagesFromServer]; +} + +- (IBAction)retryCost:(id)sender { + [self getCost]; +} + + /* * Once a new language is input to the Language Translate window's main * table, this is called to reload the cost in the translate window. @@ -441,11 +490,6 @@ - (void)reloadCost{ [self getCost]; } --(IBAction)unclick:(id)sender{ - [_translatePopOver close]; - [_translateFromInfo setIntValue:0]; -} - /* * Update the active languages from the Language Translate window. If this * event is being percolated by a no active languages message, flash that @@ -479,7 +523,7 @@ - (void)reloadLanguageMenu{ [_translateFromTabView selectTabViewItemAtIndex:noActiveLangsIndex]; [_translateFromInfo setHidden:1]; [_popTranslateFrom setEnabled:0]; - _popTranslateFrom.title = @"No active languages!"; + _popTranslateFrom.title = noActiveLangsString; _currLang = NULL; [_languageTable reloadData]; }else{ @@ -514,7 +558,7 @@ -(void)updateMissingActiveLangs{ [s appendString:l.name]; } } - NSString* info = [NSString stringWithFormat: @"Additional translatable language(s): %@.\rTo activate, select \"Add Language\" in Language Translation window and add phrases you want to translate.", s]; + NSString* info = [NSString stringWithFormat: missingActiveLangsErrorString, s]; _translateFromInfoV.string = info; } @@ -533,7 +577,7 @@ -(void)updateNoActiveLangsError{ } [s appendString:l.name]; } - _noActiveLangsError.stringValue = [NSString stringWithFormat:@"You haven't added any languages that we can translate! The languages you can translate from are: %@.\rAdd at least one of them in the Language Editor window and fill in the phrases you would like to translate.", s]; + _noActiveLangsError.stringValue = [NSString stringWithFormat:noActiveLangsErrorString, s]; } /* * Go through the dictionary of 'translate to' languages for the current language @@ -698,7 +742,7 @@ -(void)validateReceipt:(NSData *)receipt{ nil]; NSError *error; NSData *postdata2 = [NSJSONSerialization dataWithJSONObject:JSONObject options:0 error:&error]; - NSURL *url = [NSURL URLWithString:@"http://spritebuilder-rails.herokuapp.com/translations/receipt/"]; + NSURL *url = [NSURL URLWithString:receiptURL]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; request.HTTPMethod = @"POST"; request.HTTPBody = postdata2; @@ -732,7 +776,7 @@ -(void)showTranslationsDownloading{ -(void)getTranslations{ NSString* URLstring = - [NSString stringWithFormat:@"http://spritebuilder-rails.herokuapp.com/translations?key=%@", _guid]; + [NSString stringWithFormat:translationsURL, _guid]; NSURL* url = [NSURL URLWithString:URLstring]; NSURLSessionDataTask *task = [[NSURLSession sharedSession] dataTaskWithURL: url completionHandler:^(NSData *data, diff --git a/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.xib b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.xib index 77ed458ac..9c0a2149a 100644 --- a/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.xib +++ b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.xib @@ -13,6 +13,8 @@ + + @@ -148,12 +150,12 @@ Gw - + - + @@ -226,12 +228,25 @@ Gw - + + + + + + + + + + + + + + @@ -377,7 +392,7 @@ Gw - - + + + + + - + - - - - - + @@ -419,12 +434,11 @@ Gw - + - - + @@ -432,7 +446,7 @@ Gw - + + + + + + + + + + + + + + + + + + + - + - + + + + @@ -468,6 +504,142 @@ Gw + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 005161f53ab1857d4da16052e48e70d4a8c4cd4c Mon Sep 17 00:00:00 2001 From: Benjamin Koatz Date: Tue, 24 Jun 2014 16:07:20 -0700 Subject: [PATCH 08/39] Reorganized a bunch of code and added pragma marks, along with adding the feature that languages are added to the active languages of the Language Window if they are translated to in the translate window. Buying still doesn't work that much but it's getting there. --- .../ccBuilder/LocalizationEditorWindow.h | 3 +- .../ccBuilder/LocalizationEditorWindow.m | 24 + .../ccBuilder/LocalizationTranslateWindow.h | 7 +- .../ccBuilder/LocalizationTranslateWindow.m | 531 +++++++++--------- .../ccBuilder/LocalizationTranslateWindow.xib | 212 ++----- 5 files changed, 362 insertions(+), 415 deletions(-) diff --git a/SpriteBuilder/ccBuilder/LocalizationEditorWindow.h b/SpriteBuilder/ccBuilder/LocalizationEditorWindow.h index c315ab910..03c2c110e 100644 --- a/SpriteBuilder/ccBuilder/LocalizationEditorWindow.h +++ b/SpriteBuilder/ccBuilder/LocalizationEditorWindow.h @@ -34,7 +34,8 @@ - (IBAction)selectedAddLanguage:(id)sender; - (void)removeLanguagesAtIndexes:(NSIndexSet*)idxs; - (IBAction)selectedCurrentLanguage:(id)sender; - +- (void)addLanguages:(NSArray*)langs; +//- (void)removeLanguages:(NSArray*)langs; - (void)removeTranslationsAtIndexes:(NSIndexSet*)idxs; - (void) reload; diff --git a/SpriteBuilder/ccBuilder/LocalizationEditorWindow.m b/SpriteBuilder/ccBuilder/LocalizationEditorWindow.m index be87b84ce..04a038272 100644 --- a/SpriteBuilder/ccBuilder/LocalizationEditorWindow.m +++ b/SpriteBuilder/ccBuilder/LocalizationEditorWindow.m @@ -205,6 +205,7 @@ - (IBAction)pressedAddGroup:(id)sender */ - (IBAction)pressedTranslate:(id)sender { _ltw = [[LocalizationTranslateWindow alloc] initWithWindowNibName:@"LocalizationTranslateWindow"]; + [_ltw setParentWindow:self]; [[_ltw window] makeKeyAndOrderFront:nil]; } @@ -229,6 +230,29 @@ - (IBAction)selectedAddLanguage:(id)sender [handler setEdited]; } +/* + * TO COMMENT + */ +- (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]; + //[handler setEdited]; +} + - (void)removeLanguagesAtIndexes:(NSIndexSet*)idxs { LocalizationEditorHandler* handler = [AppDelegate appDelegate].localizationEditorHandler; diff --git a/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.h b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.h index 4c317b298..6a4d1fb2b 100644 --- a/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.h +++ b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.h @@ -22,7 +22,7 @@ IBOutlet NSButton* _translateFromInfo; //Window Handler (To deal with mouse events) - IBOutlet LocalizationTranslateWindowHandler* _w; + IBOutlet LocalizationTranslateWindowHandler* _handler; //tab views IBOutlet NSView* _noActiveLangsView; @@ -66,6 +66,8 @@ NSString* _guid; NSMutableDictionary* _receipts; + LocalizationEditorWindow* _parentWindow; + } - (IBAction)buy:(id)sender; @@ -78,4 +80,7 @@ - (IBAction)retryCost:(id)sender; - (void)reloadLanguageMenu; - (void)reloadCost; + +@property (nonatomic,strong) LocalizationEditorWindow* parentWindow; + @end \ No newline at end of file diff --git a/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.m b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.m index 82025b72f..de8addb49 100644 --- a/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.m +++ b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.m @@ -16,21 +16,32 @@ @implementation LocalizationTranslateWindow +@synthesize parentWindow = _parentWindow; + +#pragma mark Standards for the tab view static int downloadLangsIndex = 0; static int noActiveLangsIndex = 1; static int standardLangsIndex = 2; static int downloadCostErrorIndex = 3; static int downloadLangsErrorIndex = 4; + +#pragma mark URLs static NSString* languageURL = @"http://spritebuilder-meteor.herokuapp.com/api/v1/translations/languages?key=%@"; static NSString* const estimateURL = @"http://spritebuilder-meteor.herokuapp.com/api/v1/translations/estimate"; static NSString* const receiptURL = @"http://spritebuilder-rails.herokuapp.com/translations"; static NSString* translationsURL = @"http://spritebuilder-rails.herokuapp.com/translations?key=%@"; -static NSString* const noActiveLangsString = @"No Active Languages!"; + +#pragma mark Messages for the user +static NSString* const noActiveLangsString = @"No Valid Languages"; static NSString* const downloadingLangsString = @"Downloading..."; -static NSString* missingActiveLangsErrorString = @"Additional translatable language(s): %@.\rTo activate, select \"Add Language\" in Language Translation window and add phrases you want to translate."; -static NSString* noActiveLangsErrorString = @"You haven't added any languages that we can translate! The languages you can translate from are: %@.\rAdd at least one of them in the Language Editor window and fill in the phrases you would like to translate."; +static NSString* missingActiveLangsErrorString = @"Additional translatable language(s): %@.\r\rTo activate, select \"Add Language\" in Language Translation window and add phrases you want to translate."; +static NSString* noActiveLangsErrorString = @"We support translations from:\r\r%@."; + +#pragma mark Init + /* - * Set up the guid, the languages global dictionary and get the dictionary's contents from the server + * Set up the guid, the languages global dictionary, the tab views, the window handler + * and get the dictionary's contents from the server */ -(void) awakeFromNib { @@ -41,16 +52,97 @@ -(void) awakeFromNib [[_translateFromTabView tabViewItemAtIndex:standardLangsIndex] setView:_standardLangsView]; [[_translateFromTabView tabViewItemAtIndex:downloadCostErrorIndex] setView:_downloadingCostsErrorView]; [[_translateFromTabView tabViewItemAtIndex:downloadLangsErrorIndex] setView:_downloadingLangsErrorView]; - [_w setPopOver:_translatePopOver button:_translateFromInfo]; + [_handler setPopOver:_translatePopOver button:_translateFromInfo]; [self getLanguagesFromServer]; } +#pragma mark Downloading and updating languages + +/* + * Disable the translate from menu and 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. + */ +-(void)getLanguagesFromServer{ + _popTranslateFrom.title = downloadingLangsString; + [_popTranslateFrom setEnabled:0]; + [_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(@"Status code: %li", ((NSHTTPURLResponse *)response).statusCode); + } + else + { + NSLog(@"Error: %@", error.localizedDescription); + } + }]; + [task resume]; +} + +/* + * 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 SpriteBuilder 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"]) + { + NSLog(@"%@", JSONerror ? [NSString stringWithFormat:@"JSONError: %@", JSONerror.localizedDescription] : + [NSString stringWithFormat:@"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 finishSetUp]; +} + +/* + * 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 reload. If there are no active languages that we can translate from + * 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 with instructions is shown. */ -(void)finishSetUp{ @@ -59,12 +151,12 @@ -(void)finishSetUp{ [self uncheckLanguageDict]; if(_activeLanguages.count) { - [_translateFromTabView selectTabViewItemAtIndex:standardLangsIndex]; - [_popTranslateFrom setEnabled:1]; LocalizationEditorLanguage* l = [_activeLanguages objectAtIndex:0]; - _popTranslateFrom.title = l.name; _currLang = l; - [self updateLanguageSelectionMenu:1]; + _popTranslateFrom.title = l.name; + [_popTranslateFrom setEnabled:1]; + [_translateFromTabView selectTabViewItemAtIndex:standardLangsIndex]; + [self updateLanguageSelectionMenu:0]; } else { @@ -77,6 +169,7 @@ -(void)finishSetUp{ /* * Turns off the 'quick edit' option in the languages global dictionary + * e.g. 'unchecks' them */ -(void)uncheckLanguageDict{ for(LocalizationEditorLanguage* l in [_languages allKeys]) @@ -88,8 +181,9 @@ -(void)uncheckLanguageDict{ } /* - * If this is coming out of a reload of the menu (the initial post-download call or reload - * after a language is added on the Language Translation window) everything is normal. But + * 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 or reload after + * a language is added/deleted on the Language Translation window) everything is normal. But * if this is just a normal user selection, and the user reselected the current language, * ignore this and return. * @@ -97,13 +191,16 @@ -(void)uncheckLanguageDict{ * Set the global currLang to the newly selected language and if this isn't the initial * update (e.g. if the window is already loaded and someone is selecting a new language * to translate from) then update the main language table and the check all box accordingly. - * If there are still languages that can be activated, update and show the missing active - * languages message. + * Finally, toggle the visibility of the 'Translate From Info' button. + * + * The 'isNewLangActive' variable handles the edge case where a user deletes an active + * 'translate from' language from the Langauge window, and just sets the current language + * and language selection menu accordingly. */ -- (void) updateLanguageSelectionMenu:(NSInteger)isReload +- (void) updateLanguageSelectionMenu:(NSInteger)userReselection { NSString* newLangSelection = _popTranslateFrom.selectedItem.title; - if(self.isWindowLoaded && _currLang && !isReload && [newLangSelection isEqualToString:_currLang.name]) + if(self.isWindowLoaded && _currLang && userReselection && [newLangSelection isEqualToString:_currLang.name]) { return; } @@ -114,17 +211,23 @@ - (void) updateLanguageSelectionMenu:(NSInteger)isReload [_popTranslateFrom removeAllItems]; NSMutableArray* langTitles = [NSMutableArray array]; + int isNewLangActive = 0; for (LocalizationEditorLanguage* lang in _activeLanguages) { if([lang.name isEqualToString:newLangSelection]) { + isNewLangActive = 1; _currLang = lang; } [langTitles addObject:lang.name]; } [_popTranslateFrom addItemsWithTitles:langTitles]; - if (newLangSelection) + if(!isNewLangActive){ + _currLang = [_activeLanguages objectAtIndex:0]; + [_popTranslateFrom selectItemWithTitle:_currLang.name]; + } + else if (newLangSelection) { [_popTranslateFrom selectItemWithTitle:newLangSelection]; } @@ -133,6 +236,15 @@ - (void) updateLanguageSelectionMenu:(NSInteger)isReload [_languageTable reloadData]; [self updateCheckAll]; } + [self toggleTranslateFromInfo]; + +} + +/* + * Toggles whether or not you can see the 'Translate From Info' button + * depending on if there are languages that can still be activated. + */ +-(void)toggleTranslateFromInfo{ if(_activeLanguages.count == [_languages allKeys].count) { if(_translatePopOver.isShown) @@ -141,63 +253,95 @@ - (void) updateLanguageSelectionMenu:(NSInteger)isReload } [_translateFromInfo setHidden:1]; } - else{ + else + { [_translateFromInfo setHidden:0]; } } +#pragma mark Downloading Cost Estimate and word count /* - * Counts the number of words in a string, counting words - * as space-separated sets of letters, including - and '. - * TODO line this up with unbabel's way of delimiting - * what's a word and what's not + * 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. */ --(NSInteger) numWordsInPhrase:(NSString*) phrase{ - NSInteger l = phrase.length; - NSInteger words = 0; - NSInteger lastWasLetter = 0; - NSInteger firstLetterReached = 0; - NSMutableCharacterSet* letters = [NSMutableCharacterSet letterCharacterSet]; - [letters addCharactersInString:@"-'"]; - for(NSInteger i=0; i 0){ + [self requestIAPProducts]; + } + NSLog(@"Status code: %li", ((NSHTTPURLResponse *)response).statusCode); + } + else + { + NSLog(@"Error: %@", error.localizedDescription); + } + }]; + [task resume]; } /* * Goes through every LocalizationEditorTranslation, first seeing if there is a - * version of the phrase in the 'translate from' language. Then populating an array - * of the isoCodes for every translation which doesn't exist for the selected 'translate - * to' languages (or filling the array with every 'translate to' language if the user - * has selected not to ignore translation they have already input). If the array remains - * unpopulated, then we ignore this translation. We then count the number of words in the - * 'translate from' string and multiply that by the number of languages to translate to - * to find how many words need to be translated. Then we create a dictionary of the - * 'translate from' text, the context (if it exists), the source language, the languages - * to translate to and add that dictionary to an array of phrases. - * Return the number of words in the phrasesToTranlsate array. + * version of the phrase in the 'translate from' language. + * Then populating 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. We then add this + * number 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, 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 removeAllObjects]; _phrasesToTranslate = [[NSMutableArray alloc] init]; - NSInteger words = 0; for(LocalizationEditorTranslation* t in trans) { NSString* toTranslate = [t.translations objectForKey:_currLang.isoLangCode]; @@ -222,97 +366,35 @@ -(NSInteger)updatePhrasesToTranslate{ continue; } _numTransToDownload += langsToTranslate.count; - words += langsToTranslate.count*[self numWordsInPhrase:toTranslate]; NSDictionary *phrase; if(t.comment && ![t.comment isEqualToString:@""]) { phrase = [[NSDictionary alloc] initWithObjectsAndKeys: t.key, @"key", - [t.translations objectForKey:_currLang.isoLangCode], @"text", - t.comment, @"context", - _currLang.isoLangCode,@"source_language", - langsToTranslate,@"target_languages", - nil]; + [t.translations objectForKey:_currLang.isoLangCode], @"text", + t.comment, @"context", + _currLang.isoLangCode,@"source_language", + langsToTranslate,@"target_languages", + nil]; } else { phrase = [[NSDictionary alloc] initWithObjectsAndKeys: t.key, @"key", - [t.translations objectForKey:_currLang.isoLangCode], @"text", - _currLang.isoLangCode,@"source_language", - langsToTranslate,@"target_languages", - nil]; + [t.translations objectForKey:_currLang.isoLangCode], @"text", + _currLang.isoLangCode,@"source_language", + langsToTranslate,@"target_languages", + nil]; } [_phrasesToTranslate addObject:phrase]; } - return words; + return _phrasesToTranslate.count; } /* - * Gets the estimated cost of a translation request using the currrent user-set parameters. - * Updates phrases to translate, returning the number of words the user is asking to - * translate. Updates the numWords field in the window (if there are 0 words to translate, - * cost is 0 and we finish). - * - * 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. We then send that price tier to Apple to come up with - * the appropriate, localized price. - * TODO uncomment HTTP request. + * Parses the JSON response from a request for a cost estimate. Handles error and sets + * the translation tier and number of words. */ --(void)getCost{ - - NSInteger words = [self updatePhrasesToTranslate]; - _numWords.stringValue = [NSString stringWithFormat:@"%ld", words]; - if(_numWords.stringValue.intValue == 0) - { - _cost.stringValue = [NSString stringWithFormat:@"%ld", words]; - return; - } - [_translateFromTabView selectTabViewItemAtIndex:standardLangsIndex]; - [_costDownloading setHidden:0]; - [_costDownloadingText setHidden:0]; - [_costDownloading startAnimation:self]; - NSDictionary *JSONObject = [[NSDictionary alloc] initWithObjectsAndKeys: - _guid,@"key", - _phrasesToTranslate,@"phrases", - nil]; - if(![NSJSONSerialization isValidJSONObject:JSONObject]){ - NSLog(@"Not a JSON Object!!!"); - } - 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]; - } - NSLog(@"Status code: %li", ((NSHTTPURLResponse *)response).statusCode); - } - else - { - NSLog(@"Error: %@", error.localizedDescription); - } - }]; - [task resume]; - //_tierForTranslations = 1; - //[self requestIAPProducts]; -} - -(void)parseJSONEstimate:(NSData*)data{ NSError *JSONerror; NSDictionary* dataDict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&JSONerror]; @@ -327,6 +409,7 @@ -(void)parseJSONEstimate:(NSData*)data{ _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. */ @@ -335,96 +418,21 @@ -(void)requestIAPProducts{ NSArray *productIdentifiers = [NSArray arrayWithContentsOfURL:url]; NSSet* identifierSet = [NSSet setWithArray:productIdentifiers]; SKProductsRequest* request = [[SKProductsRequest alloc] initWithProductIdentifiers:identifierSet]; - request.delegate = self; + [request setDelegate:self]; [request start]; } - -/* - * Start the spinning download icon, disable and put a message in the menu and show the downloading text. - * 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. - */ --(void)getLanguagesFromServer{ - _popTranslateFrom.title = downloadingLangsString; - [_popTranslateFrom setEnabled:0]; - [_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(@"Status code: %li", ((NSHTTPURLResponse *)response).statusCode); - } - else - { - NSLog(@"Error: %@", error.localizedDescription); - } - }]; - [task resume]; -} - -/* - * 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 SpriteBuilder session. - */ --(void)parseJSONLanguages:(NSData *)data{ - NSError *JSONerror; - NSMutableDictionary* availableLanguagesDict = [NSJSONSerialization JSONObjectWithData:data - options:NSJSONReadingMutableContainers error:&JSONerror]; - if(JSONerror || [[[availableLanguagesDict allKeys] firstObject] isEqualToString:@"Error"]) - { - NSLog(@"%@", JSONerror ? [NSString stringWithFormat:@"JSONError: %@", JSONerror.localizedDescription] : - [NSString stringWithFormat:@"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 finishSetUp]; -} - -/* - * 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]; - } - } -} +#pragma mark Toggling/Clicking button events /* * Solicit a payment and set the cancel button to say 'Finish'. */ - (IBAction)buy:(id)sender { - //[_buy setState:NSOnState]; + if(!_products.count || !_phrasesToTranslate.count) + return; + [[SKPaymentQueue defaultQueue] addTransactionObserver:self]; SKPayment* payment = [SKPayment paymentWithProduct:[_products objectAtIndex:(_tierForTranslations -1)]]; [[SKPaymentQueue defaultQueue] addPayment:payment]; - _buy.title = @"Finish"; } /* @@ -439,7 +447,7 @@ - (IBAction)cancel:(id)sender { * they are seeking. */ - (IBAction)toggleIgnore:(id)sender { - [self getCost]; + [self getCostEstimate]; } /* @@ -448,7 +456,7 @@ - (IBAction)toggleIgnore:(id)sender { * user-click generated event. */ - (IBAction)selectedTranslateFromMenu:(id)sender { - [self updateLanguageSelectionMenu:0]; + [self updateLanguageSelectionMenu:1]; } /* @@ -464,6 +472,10 @@ - (IBAction)toggleCheckAll:(id)sender { [_languageTable reloadData]; } +/* + * Toggles the 'translate from' info popover according to when you click on the + * info button + */ - (IBAction)showInfo:(id)sender { [self updateMissingActiveLangs]; if(_translateFromInfo.intValue == 1){ @@ -473,21 +485,30 @@ - (IBAction)showInfo:(id)sender { } } +/* + * 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 getCost]; + [self getCostEstimate]; } +#pragma mark Response to events in the main Language Window /* * Once a new language is input to the Language Translate window's main * table, this is called to reload the cost in the translate window. */ - (void)reloadCost{ - [self getCost]; + [self getCostEstimate]; } /* @@ -495,11 +516,12 @@ - (void)reloadCost{ * event is being percolated by a no active languages message, flash that * message if the problem has not been fixed (e.g. they added a language * that isn't in the keys of the language dictionary) or hide the message - * and enable and update the menu. This situation is not considered a reload - * for the purposes of updateLangaugesSelectionMenu. If this is being called because of a - * missing languages message, hide that message if all possible active - * langauges are activated and then update the language menu. This situation - * is considered a reload. + * and enable and update the menu. + * + * If this is being called because of a missing languages message, hide that + * message if all possible active langauges are activated and then update + * the language menu. If the user has deleted all active languages, + * turn the tab view into a no active languages error. */ - (void)reloadLanguageMenu{ [self updateActiveLanguages]; @@ -520,6 +542,7 @@ - (void)reloadLanguageMenu{ }else{ if(!_activeLanguages.count) { + [self updateNoActiveLangsError]; [_translateFromTabView selectTabViewItemAtIndex:noActiveLangsIndex]; [_translateFromInfo setHidden:1]; [_popTranslateFrom setEnabled:0]; @@ -528,7 +551,7 @@ - (void)reloadLanguageMenu{ [_languageTable reloadData]; }else{ [self updateMissingActiveLangs]; - [self updateLanguageSelectionMenu: 1]; + [self updateLanguageSelectionMenu: 0]; } } } @@ -540,6 +563,8 @@ - (void)toggleNoActiveLangsAlpha { [_noActiveLangsError setHidden:(!_noActiveLangsError.isHidden)]; } +#pragma mark update error strings and the 'check all' button + /* * Put all the available but not inputted 'translate from' languages * in the missing active langs message @@ -573,12 +598,13 @@ -(void)updateNoActiveLangsError{ { if(![s isEqualToString:@""]) { - [s appendString:@", "]; + [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 @@ -610,9 +636,7 @@ -(void)updateCheckAll{ } } -/* - * Tableview delegate - */ +#pragma mark table view delegate /* * If there's no current language then there's going to be nothing to @@ -627,9 +651,8 @@ - (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView { return 0; } - [self getCost]; - NSInteger ret = ((NSArray*)[_languages objectForKey:_currLang]).count; - return ret; + [self getCostEstimate]; + return ((NSArray*)[_languages objectForKey:_currLang]).count; } /* @@ -639,7 +662,8 @@ - (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView */ - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex { - if(!_currLang){ + if(!_currLang) + { return 0; } if ([aTableColumn.identifier isEqualToString:@"enabled"]) @@ -656,7 +680,7 @@ - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColu } /* - * Update the check all box and get new cost when the user toggles one of the languages in the main language table.x + * 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 { @@ -665,25 +689,28 @@ - (void) tableView:(NSTableView *)tableView setObjectValue:(id)object forTableCo LocalizationEditorLanguage* lang = [((NSArray*)[_languages objectForKey:_currLang]) objectAtIndex:row]; lang.quickEdit = [object boolValue]; [self updateCheckAll]; - [self getCost]; + [self getCostEstimate]; } } -/* - * Request Delegate - */ +#pragma mark request delegate (and price display) +-(void)request:(SKRequest *)request didFailWithError:(NSError *)error{ + NSLog(@"Request failed"); +} +-(void)requestDidFinish:(SKRequest *)request{ + NSLog(@"Request finished"); +} /* * Takes in the products returned by apple, prints any invalid identifiers and displays * the price of those products. - * TODO get rid of invalid product identifiers! */ -(void) productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response{ + NSLog(@"Product Request"); _products = response.products; for(NSString *invalidIdentifier in response.invalidProductIdentifiers) { - [_costDownloading setHidden:1]; - [_costDownloadingText setHidden:1]; + [_translateFromTabView selectTabViewItemAtIndex:downloadCostErrorIndex]; [_costDownloading stopAnimation:self]; NSLog(@"Invalid Identifier: %@",invalidIdentifier); return; @@ -691,10 +718,6 @@ -(void) productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProdu [self displayPrice]; } -/* - * Payments, prices and receipts - */ - /* * Locally format the price of the current translation estimate, display it, * and hide the cost downloading message and spinning icon. @@ -711,6 +734,8 @@ -(void)displayPrice{ [_costDownloading stopAnimation:self]; } +#pragma mark payment transaction observer + /* * Ask for a receipt for any updated paymnent transactions. */ @@ -722,7 +747,7 @@ -(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)trans { case SKPaymentTransactionStatePurchased: receiptURL = [[NSBundle mainBundle] appStoreReceiptURL]; - NSData* receipt = [NSData dataWithContentsOfURL:receiptURL]; + NSString* receipt = [NSData dataWithContentsOfURL:receiptURL]; [_receipts setObject:receipt forKey:transaction.transactionIdentifier]; [self validateReceipt:receipt]; break; @@ -734,12 +759,8 @@ -(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)trans * Validates the receipt with our server. * TODO check for translations! */ --(void)validateReceipt:(NSData *)receipt{ - NSDictionary *JSONObject = [[NSDictionary alloc] initWithObjectsAndKeys: - _guid,@"key", - receipt,@"receipt", - _phrasesToTranslate,"@phrases", - nil]; +-(void)validateReceipt:(NSString *)receipt{ + NSDictionary *JSONObject = [[NSDictionary alloc] initWithObjectsAndKeys: _guid,@"key",_phrasesToTranslate,@"phrases",nil]; NSError *error; NSData *postdata2 = [NSJSONSerialization dataWithJSONObject:JSONObject options:0 error:&error]; NSURL *url = [NSURL URLWithString:receiptURL]; @@ -753,6 +774,7 @@ -(void)validateReceipt:(NSData *)receipt{ { if (!error) { + NSLog(@"Yo"); [self showTranslationsDownloading]; [self setLanguageWindowDownloading]; [self parseJSONTranslations:data]; @@ -761,6 +783,7 @@ -(void)validateReceipt:(NSData *)receipt{ } else { + NSLog(@"Yo1"); NSLog(@"Error: %@", error.localizedDescription); } }]; @@ -768,6 +791,7 @@ -(void)validateReceipt:(NSData *)receipt{ } -(void)showTranslationsDownloading{ + NSLog(@"Yo2"); [_translationsProgressBar startAnimation:self]; [_translationsProgressBar setMaxValue:_numTransToDownload]; [_translationsDownloadText setHidden:0]; @@ -775,6 +799,7 @@ -(void)showTranslationsDownloading{ } -(void)getTranslations{ + NSLog(@"Yo3"); NSString* URLstring = [NSString stringWithFormat:translationsURL, _guid]; NSURL* url = [NSURL URLWithString:URLstring]; @@ -799,11 +824,16 @@ -(void)getTranslations{ } -(void)setLanguageWindowDownloading{ + NSLog(@"Yo4"); LocalizationEditorHandler* handler = [AppDelegate appDelegate].localizationEditorHandler; NSArray* translations = handler.translations; - for(LocalizationEditorTranslation* t in translations){ - for(NSDictionary* d in _phrasesToTranslate){ - if([t.key isEqualToString:[d objectForKey:@"key"]]){ + for(LocalizationEditorTranslation* t in translations) + { + for(NSDictionary* d in _phrasesToTranslate) + { + if([t.key isEqualToString:[d objectForKey:@"key"]]) + { + [_parentWindow addLanguages:[d objectForKey:@"target_languages"]]; t.languagesDownloading = [d objectForKey:@"target_languages"]; break; } @@ -816,6 +846,7 @@ -(void)setLanguageWindowDownloading{ * only done once in the beginning of the SpriteBuilder session. */ -(void)parseJSONTranslations:(NSData *)data{ + NSLog(@"Yo5"); NSError *JSONerror; NSDictionary* initialTransDict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&JSONerror]; diff --git a/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.xib b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.xib index 9c0a2149a..4793e7f51 100644 --- a/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.xib +++ b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.xib @@ -1,5 +1,5 @@ - + @@ -16,6 +16,7 @@ + @@ -32,23 +33,23 @@ - - + - + + - + @@ -104,24 +105,18 @@ - + - - - - - - + @@ -165,24 +160,18 @@ Gw - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -376,26 +332,25 @@ Gw - + - - - You haven't added any languages that we can translate! The languages you can translate from are: English. Add at least one of them in the Language Editor window and fill in the phrases you would like to translate. - + + + - + - - + - - - - - - + + @@ -425,7 +376,7 @@ Gw - + @@ -434,19 +385,16 @@ Gw - - + + - - - - - - - - - - - - - - - - - - - - - - - - + - - - - + - - - - + - - - - - - - - + @@ -525,7 +441,7 @@ Gw - - + - - - - - + + @@ -574,7 +487,7 @@ Gw - + @@ -583,31 +496,25 @@ Gw - - + + - - - - - + + - - - - - - - - - - - - - - - - - - - - - - - - - From e2a1b304bebe81ad40f044513081c45db69d45dd Mon Sep 17 00:00:00 2001 From: Benjamin Koatz Date: Tue, 24 Jun 2014 18:18:16 -0700 Subject: [PATCH 09/39] Stylized the window better (read: more compactly). Also got receipt validation to work on client, end still waiting for server capabilities --- .../SpriteBuilder.xcodeproj/project.pbxproj | 6 + .../LocalizationEditorTextFieldCell.h | 16 ++ .../LocalizationEditorTextFieldCell.m | 25 ++ .../ccBuilder/LocalizationTranslateWindow.m | 21 +- .../ccBuilder/LocalizationTranslateWindow.xib | 257 ++++++++---------- 5 files changed, 177 insertions(+), 148 deletions(-) create mode 100644 SpriteBuilder/ccBuilder/LocalizationEditorTextFieldCell.h create mode 100644 SpriteBuilder/ccBuilder/LocalizationEditorTextFieldCell.m diff --git a/SpriteBuilder/SpriteBuilder.xcodeproj/project.pbxproj b/SpriteBuilder/SpriteBuilder.xcodeproj/project.pbxproj index 4afcdb590..a5f2c50b3 100644 --- a/SpriteBuilder/SpriteBuilder.xcodeproj/project.pbxproj +++ b/SpriteBuilder/SpriteBuilder.xcodeproj/project.pbxproj @@ -101,6 +101,7 @@ 77E7D04F138F78F600E8EE67 /* StageSizeWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = 77E7D04E138F78F600E8EE67 /* StageSizeWindow.m */; }; 7B3EF5DB195885F20023C169 /* LocalizationTranslateWindowHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 7B3EF5DA195885F20023C169 /* LocalizationTranslateWindowHandler.m */; }; 7B5135C21947CC2500DE177D /* LocalizationInAppPurchasesPIDs.plist in Resources */ = {isa = PBXBuildFile; fileRef = 7B5135C11947CC2500DE177D /* LocalizationInAppPurchasesPIDs.plist */; }; + 7B88AD47195A4846001BF73C /* LocalizationEditorTextFieldCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 7B88AD46195A4846001BF73C /* LocalizationEditorTextFieldCell.m */; }; 7BCC1C0D194904190062DF38 /* StoreKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7BCC1C0C194904190062DF38 /* StoreKit.framework */; }; 7BF55303193F8A7500183F09 /* LocalizationTranslateWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 7BF55302193F8A7500183F09 /* LocalizationTranslateWindow.xib */; }; 7BF55307193F912200183F09 /* LocalizationTranslateWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = 7BF55306193F912200183F09 /* LocalizationTranslateWindow.m */; }; @@ -1259,6 +1260,8 @@ 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 = ""; }; 7B5135C11947CC2500DE177D /* LocalizationInAppPurchasesPIDs.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = LocalizationInAppPurchasesPIDs.plist; path = ../ccBuilder/LocalizationInAppPurchasesPIDs.plist; 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 = ""; }; 7BCC1C0C194904190062DF38 /* StoreKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = StoreKit.framework; path = System/Library/Frameworks/StoreKit.framework; sourceTree = SDKROOT; }; 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 = ""; }; @@ -3455,6 +3458,8 @@ B7083E0317B32623006628C7 /* LocalizationEditorLanguageTableView.m */, B7083E0517B32DAD006628C7 /* LocalizationEditorTranslationTableView.h */, B7083E0617B32DAD006628C7 /* LocalizationEditorTranslationTableView.m */, + 7B88AD45195A4846001BF73C /* LocalizationEditorTextFieldCell.h */, + 7B88AD46195A4846001BF73C /* LocalizationEditorTextFieldCell.m */, ); name = "Localization Editor"; sourceTree = ""; @@ -6073,6 +6078,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 */, 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/LocalizationTranslateWindow.m b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.m index de8addb49..e3b8cf17d 100644 --- a/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.m +++ b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.m @@ -253,10 +253,10 @@ -(void)toggleTranslateFromInfo{ } [_translateFromInfo setHidden:1]; } - else + /*else { [_translateFromInfo setHidden:0]; - } + }*/ } #pragma mark Downloading Cost Estimate and word count @@ -747,9 +747,9 @@ -(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)trans { case SKPaymentTransactionStatePurchased: receiptURL = [[NSBundle mainBundle] appStoreReceiptURL]; - NSString* receipt = [NSData dataWithContentsOfURL:receiptURL]; + NSData* receipt = [NSData dataWithContentsOfURL:receiptURL]; [_receipts setObject:receipt forKey:transaction.transactionIdentifier]; - [self validateReceipt:receipt]; + [self validateReceipt:[[NSString alloc] initWithData:receipt encoding:NSASCIIStringEncoding]]; break; } } @@ -760,8 +760,12 @@ -(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)trans * TODO check for translations! */ -(void)validateReceipt:(NSString *)receipt{ - NSDictionary *JSONObject = [[NSDictionary alloc] initWithObjectsAndKeys: _guid,@"key",_phrasesToTranslate,@"phrases",nil]; + NSDictionary *JSONObject = [[NSDictionary alloc] initWithObjectsAndKeys: _guid,@"key",receipt,@"receipt",_phrasesToTranslate,@"phrases",nil]; NSError *error; + if(![NSJSONSerialization isValidJSONObject:JSONObject]){ + NSLog(@"Invalid JSON"); + return; + } NSData *postdata2 = [NSJSONSerialization dataWithJSONObject:JSONObject options:0 error:&error]; NSURL *url = [NSURL URLWithString:receiptURL]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; @@ -774,7 +778,6 @@ -(void)validateReceipt:(NSString *)receipt{ { if (!error) { - NSLog(@"Yo"); [self showTranslationsDownloading]; [self setLanguageWindowDownloading]; [self parseJSONTranslations:data]; @@ -783,7 +786,6 @@ -(void)validateReceipt:(NSString *)receipt{ } else { - NSLog(@"Yo1"); NSLog(@"Error: %@", error.localizedDescription); } }]; @@ -791,7 +793,6 @@ -(void)validateReceipt:(NSString *)receipt{ } -(void)showTranslationsDownloading{ - NSLog(@"Yo2"); [_translationsProgressBar startAnimation:self]; [_translationsProgressBar setMaxValue:_numTransToDownload]; [_translationsDownloadText setHidden:0]; @@ -799,7 +800,6 @@ -(void)showTranslationsDownloading{ } -(void)getTranslations{ - NSLog(@"Yo3"); NSString* URLstring = [NSString stringWithFormat:translationsURL, _guid]; NSURL* url = [NSURL URLWithString:URLstring]; @@ -824,7 +824,6 @@ -(void)getTranslations{ } -(void)setLanguageWindowDownloading{ - NSLog(@"Yo4"); LocalizationEditorHandler* handler = [AppDelegate appDelegate].localizationEditorHandler; NSArray* translations = handler.translations; for(LocalizationEditorTranslation* t in translations) @@ -846,7 +845,6 @@ -(void)setLanguageWindowDownloading{ * only done once in the beginning of the SpriteBuilder session. */ -(void)parseJSONTranslations:(NSData *)data{ - NSLog(@"Yo5"); NSError *JSONerror; NSDictionary* initialTransDict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&JSONerror]; @@ -883,4 +881,5 @@ -(void)parseJSONTranslations:(NSData *)data{ } + @end diff --git a/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.xib b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.xib index 4793e7f51..0d93c0917 100644 --- a/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.xib +++ b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.xib @@ -29,10 +29,6 @@ - - - - @@ -41,23 +37,23 @@ - + - + - + - + - - + + @@ -69,20 +65,20 @@ - + - + - + - - + + @@ -106,20 +102,20 @@ - + - - + + - + - + - + - + @@ -160,28 +156,19 @@ Gw - - - - - - - - - - - - + - + - + - + - + - + + + + + + + + + + @@ -329,13 +312,13 @@ Gw - + - + - + @@ -344,84 +327,84 @@ Gw - + - + - - + + - + - - + + - + - - + + - + - - + + - + - + - + - - + + @@ -429,24 +412,24 @@ Gw - + - + - - - + + + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - - - - - - - - - From bafbf72c3523920b244d51946cfd00c8dbc5f374 Mon Sep 17 00:00:00 2001 From: Benjamin Koatz Date: Tue, 24 Jun 2014 18:28:39 -0700 Subject: [PATCH 10/39] Started working on putting translation progress in the Language Window. And changed the name of the button from Translate! to Buy Translations --- .../ccBuilder/LocalizationEditorWindow.xib | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/SpriteBuilder/ccBuilder/LocalizationEditorWindow.xib b/SpriteBuilder/ccBuilder/LocalizationEditorWindow.xib index c3deddbf2..04067bb1e 100644 --- a/SpriteBuilder/ccBuilder/LocalizationEditorWindow.xib +++ b/SpriteBuilder/ccBuilder/LocalizationEditorWindow.xib @@ -360,7 +360,7 @@ + + From d4fcefebec73eec5c5f0ded15db1a13888c706e9 Mon Sep 17 00:00:00 2001 From: Benjamin Koatz Date: Wed, 25 Jun 2014 15:10:44 -0700 Subject: [PATCH 11/39] Finally got the translate window to be key and modal. Also did a bunch of context-based enabling/disabling and started working on the translation bar in the Language Window. --- .../ccBuilder/LocalizationEditorHandler.h | 1 - .../ccBuilder/LocalizationEditorWindow.h | 10 +- .../ccBuilder/LocalizationEditorWindow.m | 60 ++++++++--- .../ccBuilder/LocalizationEditorWindow.xib | 3 + .../ccBuilder/LocalizationTranslateWindow.m | 99 ++++++++++--------- .../ccBuilder/LocalizationTranslateWindow.xib | 6 +- .../LocalizationTranslateWindowHandler.m | 7 ++ 7 files changed, 122 insertions(+), 64 deletions(-) diff --git a/SpriteBuilder/ccBuilder/LocalizationEditorHandler.h b/SpriteBuilder/ccBuilder/LocalizationEditorHandler.h index e89b8fb37..a35719a02 100644 --- a/SpriteBuilder/ccBuilder/LocalizationEditorHandler.h +++ b/SpriteBuilder/ccBuilder/LocalizationEditorHandler.h @@ -12,7 +12,6 @@ @class LocalizationEditorWindow; @class LocalizationEditorLanguage; @class LocalizationEditorTranslation; - @interface LocalizationEditorHandler : NSObject { NSMutableArray* languages; diff --git a/SpriteBuilder/ccBuilder/LocalizationEditorWindow.h b/SpriteBuilder/ccBuilder/LocalizationEditorWindow.h index 03c2c110e..021827433 100644 --- a/SpriteBuilder/ccBuilder/LocalizationEditorWindow.h +++ b/SpriteBuilder/ccBuilder/LocalizationEditorWindow.h @@ -16,6 +16,9 @@ IBOutlet NSPopUpButton* popLanguageAdd; IBOutlet NSPopUpButton* popCurrentLanguage; IBOutlet NSTextView* textInspectorKey; + IBOutlet NSTextField* _translationProgressText; + IBOutlet NSProgressIndicator* _translationProgress; + IBOutlet NSButton* _translationsButton; LocalizationTranslateWindow* _ltw; } @@ -35,7 +38,12 @@ - (void)removeLanguagesAtIndexes:(NSIndexSet*)idxs; - (IBAction)selectedCurrentLanguage:(id)sender; - (void)addLanguages:(NSArray*)langs; -//- (void)removeLanguages:(NSArray*)langs; +- (void)removeLanguages:(NSArray*)langs; +- (void)setDownloadingTranslations:(double)numToTrans; +- (void)incrementTransByOne; +- (double)translationProgress; +- (void)finishDownloadingTranslations; + - (void)removeTranslationsAtIndexes:(NSIndexSet*)idxs; - (void) reload; diff --git a/SpriteBuilder/ccBuilder/LocalizationEditorWindow.m b/SpriteBuilder/ccBuilder/LocalizationEditorWindow.m index 04a038272..69b420287 100644 --- a/SpriteBuilder/ccBuilder/LocalizationEditorWindow.m +++ b/SpriteBuilder/ccBuilder/LocalizationEditorWindow.m @@ -12,13 +12,12 @@ #import "LocalizationEditorHandler.h" #import "LocalizationEditorTranslation.h" #import "LocalizationEditorLanguageTableView.h" +#import "LocalizationTranslateWindowHandler.h" #import "AppDelegate.h" #import "CCBTextFieldCell.h" #import "NSPasteboard+CCB.h" @implementation LocalizationEditorWindow - -#pragma mark Init and Updating stuff - +@synthesize temp; - (void) awakeFromNib { [tableTranslations registerForDraggedTypes:[NSArray arrayWithObject:@"com.cocosbuilder.LocalizationEditorTranslation"]]; @@ -199,16 +198,6 @@ - (IBAction)pressedAdd:(id)sender - (IBAction)pressedAddGroup:(id)sender {} -/* - * Just displays a translate window. - * TODO Make the window key and main - */ -- (IBAction)pressedTranslate:(id)sender { - _ltw = [[LocalizationTranslateWindow alloc] initWithWindowNibName:@"LocalizationTranslateWindow"]; - [_ltw setParentWindow:self]; - [[_ltw window] makeKeyAndOrderFront:nil]; -} - /* * If a language is added, do what is shown here but also reload the langauge menu on the * language translation window if there is one open. @@ -230,6 +219,23 @@ - (IBAction)selectedAddLanguage:(id)sender [handler setEdited]; } +/* + * Just displays a translate window. + * TODO Make the window key and main + */ +- (IBAction)pressedTranslate:(id)sender { + if([_translationsButton.title isEqualToString:@"Buy Translations"]){ + _ltw = [[LocalizationTranslateWindow alloc] initWithWindowNibName:@"LocalizationTranslateWindow"]; + [_ltw setParentWindow:self]; + [_ltw.window makeKeyAndOrderFront:sender]; + [NSApp runModalForWindow:_ltw.window]; + } + else + { + + } +} + /* * TO COMMENT */ @@ -253,6 +259,34 @@ - (void)addLanguages:(NSArray*)langs //[handler setEdited]; } +-(void)setDownloadingTranslations:(double)numToTrans{ + [_translationProgress setMaxValue:numToTrans]; + [_translationProgress setHidden:0]; + [_translationProgressText setHidden:0]; + [tableTranslations setEnabled:0]; + [tableLanguages setEnabled:0]; + [popLanguageAdd setEnabled:0]; + [popCurrentLanguage setEnabled:0]; + _translationsButton.title = @"Cancel Download"; +} + +-(void)incrementTransByOne{ + [_translationProgress incrementBy:1.0]; +} + +- (double)translationProgress{ + return _translationProgress.doubleValue; +} +-(void)finishDownloadingTranslations{ + [_translationProgress setHidden:1]; + [_translationProgressText setHidden:1]; + [tableTranslations setEnabled:1]; + [tableLanguages setEnabled:1]; + [popLanguageAdd setEnabled:1]; + [popCurrentLanguage setEnabled:1]; + _translationsButton.title = @"Buy Translations"; +} + - (void)removeLanguagesAtIndexes:(NSIndexSet*)idxs { LocalizationEditorHandler* handler = [AppDelegate appDelegate].localizationEditorHandler; diff --git a/SpriteBuilder/ccBuilder/LocalizationEditorWindow.xib b/SpriteBuilder/ccBuilder/LocalizationEditorWindow.xib index 04067bb1e..0431ccf74 100644 --- a/SpriteBuilder/ccBuilder/LocalizationEditorWindow.xib +++ b/SpriteBuilder/ccBuilder/LocalizationEditorWindow.xib @@ -7,6 +7,9 @@ + + + diff --git a/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.m b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.m index e3b8cf17d..5ff481362 100644 --- a/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.m +++ b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.m @@ -52,8 +52,10 @@ -(void) awakeFromNib [[_translateFromTabView tabViewItemAtIndex:standardLangsIndex] setView:_standardLangsView]; [[_translateFromTabView tabViewItemAtIndex:downloadCostErrorIndex] setView:_downloadingCostsErrorView]; [[_translateFromTabView tabViewItemAtIndex:downloadLangsErrorIndex] setView:_downloadingLangsErrorView]; - [_handler setPopOver:_translatePopOver button:_translateFromInfo]; + [((LocalizationTranslateWindowHandler*)self.window) setPopOver:_translatePopOver button:_translateFromInfo]; + [self disableAll]; [self getLanguagesFromServer]; + } #pragma mark Downloading and updating languages @@ -65,7 +67,6 @@ -(void) awakeFromNib */ -(void)getLanguagesFromServer{ _popTranslateFrom.title = downloadingLangsString; - [_popTranslateFrom setEnabled:0]; [_translateFromTabView selectTabViewItemAtIndex:downloadLangsIndex]; [_languagesDownloading startAnimation:self]; NSString* URLstring = @@ -89,6 +90,21 @@ -(void)getLanguagesFromServer{ [task resume]; } +-(void)disableAll{ + [_popTranslateFrom setEnabled:0]; + [_languageTable setEnabled:0]; + [_checkAll setEnabled:0]; + [_ignoreText setEnabled:0]; + [_cancel setEnabled:0]; +} + +-(void)enableAll{ + [_popTranslateFrom setEnabled:1]; + [_languageTable setEnabled:1]; + [_checkAll setEnabled:1]; + [_ignoreText setEnabled:1]; + [_cancel setEnabled:1]; +} /* * 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 @@ -154,7 +170,7 @@ -(void)finishSetUp{ LocalizationEditorLanguage* l = [_activeLanguages objectAtIndex:0]; _currLang = l; _popTranslateFrom.title = l.name; - [_popTranslateFrom setEnabled:1]; + [self enableAll]; [_translateFromTabView selectTabViewItemAtIndex:standardLangsIndex]; [self updateLanguageSelectionMenu:0]; } @@ -279,6 +295,7 @@ -(void)getCostEstimate{ if(phrases == 0) { _cost.stringValue = _numWords.stringValue = @"0"; + [_buy setEnabled:0]; return; } [_translateFromTabView selectTabViewItemAtIndex:standardLangsIndex]; @@ -310,7 +327,8 @@ -(void)getCostEstimate{ if (!error) { [self parseJSONEstimate:data]; - if(_tierForTranslations > 0){ + if(_tierForTranslations > 0) + { [self requestIAPProducts]; } NSLog(@"Status code: %li", ((NSHTTPURLResponse *)response).statusCode); @@ -439,7 +457,8 @@ - (IBAction)buy:(id)sender { * Close the window. */ - (IBAction)cancel:(id)sender { - [[sender window] close]; + [NSApp endSheet:self.window]; + [self.window close]; } /* @@ -732,6 +751,7 @@ -(void)displayPrice{ [_costDownloading setHidden:1]; [_costDownloadingText setHidden:1]; [_costDownloading stopAnimation:self]; + [_buy setEnabled:1]; } #pragma mark payment transaction observer @@ -778,7 +798,6 @@ -(void)validateReceipt:(NSString *)receipt{ { if (!error) { - [self showTranslationsDownloading]; [self setLanguageWindowDownloading]; [self parseJSONTranslations:data]; _timerTransDownload = [NSTimer scheduledTimerWithTimeInterval:300 target:self selector:@selector(getTranslations) userInfo:nil repeats:YES]; @@ -792,37 +811,6 @@ -(void)validateReceipt:(NSString *)receipt{ [task resume]; } --(void)showTranslationsDownloading{ - [_translationsProgressBar startAnimation:self]; - [_translationsProgressBar setMaxValue:_numTransToDownload]; - [_translationsDownloadText setHidden:0]; - [_translationsProgressBar setHidden:0]; -} - --(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) - { - - [self parseJSONTranslations:data]; - NSLog(@"Status code: %li", ((NSHTTPURLResponse *)response).statusCode); - } - else - { - NSLog(@"Error: %@", error.localizedDescription); - } - }]; - [task resume]; - -} - -(void)setLanguageWindowDownloading{ LocalizationEditorHandler* handler = [AppDelegate appDelegate].localizationEditorHandler; NSArray* translations = handler.translations; @@ -832,12 +820,13 @@ -(void)setLanguageWindowDownloading{ { if([t.key isEqualToString:[d objectForKey:@"key"]]) { - [_parentWindow addLanguages:[d objectForKey:@"target_languages"]]; t.languagesDownloading = [d objectForKey:@"target_languages"]; + [_parentWindow addLanguages:[d objectForKey:@"target_languages"]]; break; } } } + [_parentWindow setDownloadingTranslations:_numTransToDownload]; } /* * Turns the JSON response into a dictionary and fill the _languages global accordingly. @@ -867,19 +856,37 @@ -(void)parseJSONTranslations:(NSData *)data{ if([t.key isEqualToString:keyToTranslate] && [t.languagesDownloading containsObject:lang]){ [t.translations setObject:translation forKey:lang]; [t.languagesDownloading removeObject:lang]; - [_translationsProgressBar incrementBy:1]; + [_parentWindow incrementTransByOne]; } } } } - if(_translationsProgressBar.doubleValue == _numTransToDownload){ - [_timerTransDownload invalidate]; - [_translationsDownloadText setHidden:1]; - [_translationsProgressBar setHidden:1]; + if([_parentWindow translationProgress] == _numTransToDownload){ + [_parentWindow finishDownloadingTranslations]; } - [_languageTable reloadData]; } - - +-(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) + { + + [self parseJSONTranslations:data]; + NSLog(@"Status code: %li", ((NSHTTPURLResponse *)response).statusCode); + } + else + { + NSLog(@"Error: %@", error.localizedDescription); + } + }]; + [task resume]; + +} @end diff --git a/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.xib b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.xib index 0d93c0917..086a2119d 100644 --- a/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.xib +++ b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.xib @@ -16,7 +16,6 @@ - @@ -30,6 +29,7 @@ + @@ -113,7 +113,7 @@ + + + + + + + + + + + + + + + diff --git a/SpriteBuilder/ccBuilder/LocalizationEditorWindow.h b/SpriteBuilder/ccBuilder/LocalizationEditorWindow.h index 021827433..ed6f592e6 100644 --- a/SpriteBuilder/ccBuilder/LocalizationEditorWindow.h +++ b/SpriteBuilder/ccBuilder/LocalizationEditorWindow.h @@ -8,18 +8,20 @@ #import @class LocalizationTranslateWindow; - +@class LocalizationCancelTranslationsWindow; @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; + LocalizationCancelTranslationsWindow* _lctw; } @property (nonatomic,assign) BOOL inspectorEnabled; diff --git a/SpriteBuilder/ccBuilder/LocalizationEditorWindow.m b/SpriteBuilder/ccBuilder/LocalizationEditorWindow.m index c4e74abcd..b02c15ca9 100644 --- a/SpriteBuilder/ccBuilder/LocalizationEditorWindow.m +++ b/SpriteBuilder/ccBuilder/LocalizationEditorWindow.m @@ -13,9 +13,11 @@ #import "LocalizationEditorTranslation.h" #import "LocalizationEditorLanguageTableView.h" #import "LocalizationTranslateWindowHandler.h" +#import "LocalizationCancelTranslationsWindow.h" #import "AppDelegate.h" #import "CCBTextFieldCell.h" #import "NSPasteboard+CCB.h" + @implementation LocalizationEditorWindow - (void) awakeFromNib @@ -225,14 +227,21 @@ - (IBAction)selectedAddLanguage:(id)sender */ - (IBAction)pressedTranslate:(id)sender { if([_translationsButton.title isEqualToString:@"Buy Translations"]){ - _ltw = [[LocalizationTranslateWindow alloc] initWithWindowNibName:@"LocalizationTranslateWindow"]; + if(!_ltw) + { + _ltw = [[LocalizationTranslateWindow alloc] initWithWindowNibName:@"LocalizationTranslateWindow"]; + } [_ltw setParentWindow:self]; [_ltw.window makeKeyAndOrderFront:sender]; [NSApp runModalForWindow:_ltw.window]; } else { - + _lctw = [[LocalizationCancelTranslationsWindow alloc] initWithWindowNibName:@"LocalizationCancelTranslationsWindow"]; + [_lctw setEditorWindow:self]; + [_lctw setTranslateWindow:_ltw]; + [_lctw.window makeKeyAndOrderFront:sender]; + [NSApp runModalForWindow:_lctw.window]; } } @@ -261,6 +270,7 @@ - (void)addLanguages:(NSArray*)langs - (void)removeLanguages:(NSArray*)langs {} + -(void)setDownloadingTranslations:(double)numToTrans{ [_translationProgress setMaxValue:numToTrans]; [_translationProgress setHidden:0]; @@ -268,6 +278,7 @@ -(void)setDownloadingTranslations:(double)numToTrans{ [tableTranslations setEnabled:0]; [tableLanguages setEnabled:0]; [popLanguageAdd setEnabled:0]; + [_addTranslation setEnabled:0]; [popCurrentLanguage setEnabled:0]; _translationsButton.title = @"Cancel Download"; } @@ -286,6 +297,7 @@ -(void)finishDownloadingTranslations{ [tableLanguages setEnabled:1]; [popLanguageAdd setEnabled:1]; [popCurrentLanguage setEnabled:1]; + [_addTranslation setEnabled:1]; _translationsButton.title = @"Buy Translations"; } @@ -713,5 +725,4 @@ - (CGFloat) splitView:(NSSplitView *)splitView constrainMaxCoordinate:(CGFloat)p if (proposedMaximumPosition > max) return max; else return proposedMaximumPosition; } - @end diff --git a/SpriteBuilder/ccBuilder/LocalizationEditorWindow.xib b/SpriteBuilder/ccBuilder/LocalizationEditorWindow.xib index 0431ccf74..019c35f9d 100644 --- a/SpriteBuilder/ccBuilder/LocalizationEditorWindow.xib +++ b/SpriteBuilder/ccBuilder/LocalizationEditorWindow.xib @@ -7,9 +7,11 @@ + + diff --git a/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.h b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.h index 6a4d1fb2b..89fa58ce4 100644 --- a/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.h +++ b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.h @@ -80,6 +80,7 @@ - (IBAction)retryCost:(id)sender; - (void)reloadLanguageMenu; - (void)reloadCost; +- (void)cancelDownload; @property (nonatomic,strong) LocalizationEditorWindow* parentWindow; diff --git a/SpriteBuilder/ccBuilder/LocalizationTranslateWindowHandler.h b/SpriteBuilder/ccBuilder/LocalizationTranslateWindowHandler.h index 495a7b926..45d52e118 100644 --- a/SpriteBuilder/ccBuilder/LocalizationTranslateWindowHandler.h +++ b/SpriteBuilder/ccBuilder/LocalizationTranslateWindowHandler.h @@ -8,7 +8,7 @@ #import -@interface LocalizationTranslateWindowHandler : NSWindow +@interface LocalizationTranslateWindowHandler : NSWindow @property (nonatomic,strong) NSPopover* translatePopOver; @property (nonatomic,strong) NSButton* translateButton; -(void)setPopOver:(NSPopover*)p button:(NSButton*)b; diff --git a/SpriteBuilder/ccBuilder/LocalizationTranslateWindowHandler.m b/SpriteBuilder/ccBuilder/LocalizationTranslateWindowHandler.m index ea8e56f19..62dbcfa18 100644 --- a/SpriteBuilder/ccBuilder/LocalizationTranslateWindowHandler.m +++ b/SpriteBuilder/ccBuilder/LocalizationTranslateWindowHandler.m @@ -24,12 +24,6 @@ -(void)mouseUp:(NSEvent *)theEvent{ self.translateButton.intValue = 0; } --(id)copyWithZone:(NSZone *)zone{ - LocalizationTranslateWindowHandler* newHandler = [[[self class] allocWithZone:zone] init]; - newHandler->_translatePopOver = _translatePopOver; - return newHandler; -} - -(void)close{ if([self isModalPanel]){ [NSApp endSheet:self]; From 715dba85edfdc48916a8e4222b3e5bd83a1abba0 Mon Sep 17 00:00:00 2001 From: Benjamin Koatz Date: Thu, 26 Jun 2014 13:42:22 -0700 Subject: [PATCH 14/39] Got rid of (in my opinion) a lot of cool functionality, but functionality that depended on the translation window not being modal. Also some cancelation changes and general code cleaning. Weird bug in the purchasing mechanism but I think it's related to sandbox environment. Can't find examples online. --- .../LocalizationCancelTranslationsWindow.m | 2 + .../ccBuilder/LocalizationEditorWindow.m | 14 +- .../ccBuilder/LocalizationTranslateWindow.h | 15 -- .../ccBuilder/LocalizationTranslateWindow.m | 166 ++++++------------ .../ccBuilder/LocalizationTranslateWindow.xib | 57 +----- .../LocalizationTranslateWindowHandler.h | 3 - .../LocalizationTranslateWindowHandler.m | 13 -- 7 files changed, 65 insertions(+), 205 deletions(-) diff --git a/SpriteBuilder/ccBuilder/LocalizationCancelTranslationsWindow.m b/SpriteBuilder/ccBuilder/LocalizationCancelTranslationsWindow.m index 9073e3750..6e60b364e 100644 --- a/SpriteBuilder/ccBuilder/LocalizationCancelTranslationsWindow.m +++ b/SpriteBuilder/ccBuilder/LocalizationCancelTranslationsWindow.m @@ -17,6 +17,8 @@ @implementation LocalizationCancelTranslationsWindow - (IBAction)yes:(id)sender { [_editorWindow finishDownloadingTranslations]; [_translateWindow cancelDownload]; + [NSApp endSheet:self.window]; + [self.window orderOut:nil]; } - (IBAction)no:(id)sender { diff --git a/SpriteBuilder/ccBuilder/LocalizationEditorWindow.m b/SpriteBuilder/ccBuilder/LocalizationEditorWindow.m index b02c15ca9..ce6a73e9f 100644 --- a/SpriteBuilder/ccBuilder/LocalizationEditorWindow.m +++ b/SpriteBuilder/ccBuilder/LocalizationEditorWindow.m @@ -215,8 +215,6 @@ - (IBAction)selectedAddLanguage:(id)sender [self updateLanguageSelectionMenu]; [self updateQuickEditLangs]; [self updateInspector]; - if(_ltw) - [_ltw reloadLanguageMenu]; [handler setEdited]; } @@ -227,10 +225,10 @@ - (IBAction)selectedAddLanguage:(id)sender */ - (IBAction)pressedTranslate:(id)sender { if([_translationsButton.title isEqualToString:@"Buy Translations"]){ - if(!_ltw) - { + //if(!_ltw) + //{ _ltw = [[LocalizationTranslateWindow alloc] initWithWindowNibName:@"LocalizationTranslateWindow"]; - } + //} [_ltw setParentWindow:self]; [_ltw.window makeKeyAndOrderFront:sender]; [NSApp runModalForWindow:_ltw.window]; @@ -316,8 +314,6 @@ - (void)removeLanguagesAtIndexes:(NSIndexSet*)idxs [self updateLanguageSelectionMenu]; [self updateQuickEditLangs]; [self updateInspector]; - if(_ltw) - [_ltw reloadLanguageMenu]; [handler setEdited]; } @@ -505,7 +501,7 @@ - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColu } else { - if([translation.languagesDownloading containsObject:aTableColumn.identifier]){ + if(translation.languagesDownloading && [translation.languagesDownloading containsObject:aTableColumn.identifier]){ [[aTableColumn dataCellForRow:rowIndex] setEnabled:0]; return @"Downloading..."; }else{ @@ -585,8 +581,6 @@ - (void) tableView:(NSTableView *)tableView setObjectValue:(id)object forTableCo [tableTranslations reloadDataForRowIndexes:[NSIndexSet indexSetWithIndex:row] columnIndexes:[NSIndexSet indexSetWithIndex:0]]; [handler setEdited]; } - if(_ltw) - [_ltw reloadCost]; } [self updateInspector]; diff --git a/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.h b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.h index 89fa58ce4..c5496231f 100644 --- a/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.h +++ b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.h @@ -15,15 +15,6 @@ @interface LocalizationTranslateWindow : NSWindowController { - //info button - NSPopover *_translatePopOver; - NSTextView *_translateFromInfoV; - NSViewController *_translateInfoVC; - IBOutlet NSButton* _translateFromInfo; - - //Window Handler (To deal with mouse events) - IBOutlet LocalizationTranslateWindowHandler* _handler; - //tab views IBOutlet NSView* _noActiveLangsView; IBOutlet NSView* _standardLangsView; @@ -51,8 +42,6 @@ IBOutlet NSButton *_buy; //Translations downloading stuff - IBOutlet NSTextField* _translationsDownloadText; - IBOutlet NSProgressIndicator* _translationsProgressBar; NSInteger _numTransToDownload; NSTimer* _timerTransDownload; @@ -75,13 +64,9 @@ - (IBAction)toggleIgnore:(id)sender; - (IBAction)selectedTranslateFromMenu:(id)sender; - (IBAction)toggleCheckAll:(id)sender; -- (IBAction)showInfo:(id)sender; - (IBAction)retryLanguages:(id)sender; - (IBAction)retryCost:(id)sender; -- (void)reloadLanguageMenu; -- (void)reloadCost; - (void)cancelDownload; - @property (nonatomic,strong) LocalizationEditorWindow* parentWindow; @end \ No newline at end of file diff --git a/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.m b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.m index 5ff481362..3e4b509d7 100644 --- a/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.m +++ b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.m @@ -12,29 +12,28 @@ #import "LocalizationEditorLanguage.h" #import "LocalizationEditorTranslation.h" #import "LocalizationEditorWindow.h" -#import "LocalizationTranslateWindowHandler.h" @implementation LocalizationTranslateWindow @synthesize parentWindow = _parentWindow; -#pragma mark Standards for the tab view +//Standards for the tab view static int downloadLangsIndex = 0; static int noActiveLangsIndex = 1; static int standardLangsIndex = 2; static int downloadCostErrorIndex = 3; static int downloadLangsErrorIndex = 4; -#pragma mark URLs +//URLs static NSString* languageURL = @"http://spritebuilder-meteor.herokuapp.com/api/v1/translations/languages?key=%@"; static NSString* const estimateURL = @"http://spritebuilder-meteor.herokuapp.com/api/v1/translations/estimate"; static NSString* const receiptURL = @"http://spritebuilder-rails.herokuapp.com/translations"; static NSString* translationsURL = @"http://spritebuilder-rails.herokuapp.com/translations?key=%@"; +static NSString* const cancelURL = @"http://spritebuilder-rails.herokuapp.com/translations/cancel"; -#pragma mark Messages for the user +//Messages for the user static NSString* const noActiveLangsString = @"No Valid Languages"; static NSString* const downloadingLangsString = @"Downloading..."; -static NSString* missingActiveLangsErrorString = @"Additional translatable language(s): %@.\r\rTo activate, select \"Add Language\" in Language Translation window and add phrases you want to translate."; static NSString* noActiveLangsErrorString = @"We support translations from:\r\r%@."; #pragma mark Init @@ -52,10 +51,10 @@ -(void) awakeFromNib [[_translateFromTabView tabViewItemAtIndex:standardLangsIndex] setView:_standardLangsView]; [[_translateFromTabView tabViewItemAtIndex:downloadCostErrorIndex] setView:_downloadingCostsErrorView]; [[_translateFromTabView tabViewItemAtIndex:downloadLangsErrorIndex] setView:_downloadingLangsErrorView]; - [((LocalizationTranslateWindowHandler*)self.window) setPopOver:_translatePopOver button:_translateFromInfo]; [self disableAll]; [self getLanguagesFromServer]; + } #pragma mark Downloading and updating languages @@ -213,10 +212,10 @@ -(void)uncheckLanguageDict{ * 'translate from' language from the Langauge window, and just sets the current language * and language selection menu accordingly. */ -- (void) updateLanguageSelectionMenu:(NSInteger)userReselection +- (void) updateLanguageSelectionMenu:(int)userSelection { NSString* newLangSelection = _popTranslateFrom.selectedItem.title; - if(self.isWindowLoaded && _currLang && userReselection && [newLangSelection isEqualToString:_currLang.name]) + if(self.isWindowLoaded && _currLang && userSelection && [newLangSelection isEqualToString:_currLang.name]) { return; } @@ -252,29 +251,9 @@ - (void) updateLanguageSelectionMenu:(NSInteger)userReselection [_languageTable reloadData]; [self updateCheckAll]; } - [self toggleTranslateFromInfo]; } -/* - * Toggles whether or not you can see the 'Translate From Info' button - * depending on if there are languages that can still be activated. - */ --(void)toggleTranslateFromInfo{ - if(_activeLanguages.count == [_languages allKeys].count) - { - if(_translatePopOver.isShown) - { - [_translatePopOver close]; - } - [_translateFromInfo setHidden:1]; - } - /*else - { - [_translateFromInfo setHidden:0]; - }*/ -} - #pragma mark Downloading Cost Estimate and word count /* @@ -425,6 +404,10 @@ -(void)parseJSONEstimate:(NSData*)data{ return; } _tierForTranslations = [[dataDict objectForKey:@"iap_price_tier"] intValue]; + if(_tierForTranslations != 1){ + NSLog(@"Time to create a new IAP!!! Level: %ld", _tierForTranslations); + _tierForTranslations = 1; + } _numWords.stringValue = [[dataDict objectForKey:@"wordcount"] stringValue]; } @@ -491,18 +474,7 @@ - (IBAction)toggleCheckAll:(id)sender { [_languageTable reloadData]; } -/* - * Toggles the 'translate from' info popover according to when you click on the - * info button - */ -- (IBAction)showInfo:(id)sender { - [self updateMissingActiveLangs]; - if(_translateFromInfo.intValue == 1){ - [_translatePopOver showRelativeToRect:[_translateFromInfo bounds] ofView:_translateFromInfo preferredEdge:NSMaxYEdge]; - }else{ - [_translatePopOver close]; - } -} + /* * Clicked if there was an error in downloading languages and the user @@ -530,51 +502,6 @@ - (void)reloadCost{ [self getCostEstimate]; } -/* - * Update the active languages from the Language Translate window. If this - * event is being percolated by a no active languages message, flash that - * message if the problem has not been fixed (e.g. they added a language - * that isn't in the keys of the language dictionary) or hide the message - * and enable and update the menu. - * - * If this is being called because of a missing languages message, hide that - * message if all possible active langauges are activated and then update - * the language menu. If the user has deleted all active languages, - * turn the tab view into a no active languages error. - */ -- (void)reloadLanguageMenu{ - [self updateActiveLanguages]; - if([_translateFromTabView indexOfTabViewItem:[_translateFromTabView selectedTabViewItem]] - == noActiveLangsIndex) - { - if(!_activeLanguages.count) - { - NSTimer* timer = [NSTimer scheduledTimerWithTimeInterval:0 target:self selector:@selector(toggleNoActiveLangsAlpha) userInfo:nil repeats:NO]; - timer = [NSTimer scheduledTimerWithTimeInterval:.1 target:self selector:@selector(toggleNoActiveLangsAlpha) userInfo:nil repeats:NO]; - } - else - { - [_translateFromTabView selectTabViewItemAtIndex:standardLangsIndex]; - [_popTranslateFrom setEnabled:1]; - [self updateLanguageSelectionMenu: 0]; - } - }else{ - if(!_activeLanguages.count) - { - [self updateNoActiveLangsError]; - [_translateFromTabView selectTabViewItemAtIndex:noActiveLangsIndex]; - [_translateFromInfo setHidden:1]; - [_popTranslateFrom setEnabled:0]; - _popTranslateFrom.title = noActiveLangsString; - _currLang = NULL; - [_languageTable reloadData]; - }else{ - [self updateMissingActiveLangs]; - [self updateLanguageSelectionMenu: 0]; - } - } -} - /* * Flashes the no active langauges error. */ @@ -584,29 +511,6 @@ - (void)toggleNoActiveLangsAlpha { #pragma mark update error strings and the 'check all' button -/* - * Put all the available but not inputted 'translate from' languages - * in the missing active langs message - */ --(void)updateMissingActiveLangs{ - - NSMutableString* s = [[NSMutableString alloc] initWithString:@""]; - for(LocalizationEditorLanguage* l in [_languages allKeys]) - { - if(![_activeLanguages containsObject:l]) - { - if(![s isEqualToString:@""]) - { - [s appendString:@", "]; - } - [s appendString:l.name]; - } - } - NSString* info = [NSString stringWithFormat: missingActiveLangsErrorString, s]; - - _translateFromInfoV.string = info; -} - /* * Put all the available 'translate from' languages in the no active languages error */ @@ -800,7 +704,9 @@ -(void)validateReceipt:(NSString *)receipt{ { [self setLanguageWindowDownloading]; [self parseJSONTranslations:data]; - _timerTransDownload = [NSTimer scheduledTimerWithTimeInterval:300 target:self selector:@selector(getTranslations) userInfo:nil repeats:YES]; + NSLog(@"Yo1"); + _timerTransDownload = [NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(getTranslations) userInfo:nil repeats:YES]; + [self.window close]; NSLog(@"Status code: %li", ((NSHTTPURLResponse *)response).statusCode); } else @@ -867,6 +773,7 @@ -(void)parseJSONTranslations:(NSData *)data{ } -(void)getTranslations{ + NSLog(@"yo"); NSString* URLstring = [NSString stringWithFormat:translationsURL, _guid]; NSURL* url = [NSURL URLWithString:URLstring]; @@ -888,5 +795,46 @@ -(void)getTranslations{ }]; [task resume]; +} + +- (void)cancelDownload{ + LocalizationEditorHandler* handler = [AppDelegate appDelegate].localizationEditorHandler; + NSArray* handlerTranslations = handler.translations; + for(LocalizationEditorTranslation* t in handlerTranslations) + { + t.languagesDownloading = NULL; + } + [_timerTransDownload invalidate]; + [self sendCancelRequest]; +} + +-(void)sendCancelRequest{ + NSDictionary *JSONObject = [[NSDictionary alloc] initWithObjectsAndKeys: _guid,@"key",nil]; + NSError *error; + if(![NSJSONSerialization isValidJSONObject:JSONObject]){ + NSLog(@"Invalid JSON"); + return; + } + NSData *postdata2 = [NSJSONSerialization dataWithJSONObject:JSONObject options:0 error:&error]; + NSURL *url = [NSURL URLWithString:cancelURL]; + NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; + request.HTTPMethod = @"POST"; + request.HTTPBody = postdata2; + NSURLSessionDataTask *task = [[NSURLSession sharedSession] dataTaskWithRequest: request + completionHandler:^(NSData *data, + NSURLResponse *response, + NSError *error) + { + if (!error) + { + NSLog(@"Status code: %li", ((NSHTTPURLResponse *)response).statusCode); + } + else + { + NSLog(@"Error: %@", error.localizedDescription); + } + }]; + [task resume]; + } @end diff --git a/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.xib b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.xib index 086a2119d..833114625 100644 --- a/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.xib +++ b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.xib @@ -25,7 +25,6 @@ - @@ -174,9 +173,6 @@ Gw - - - @@ -216,7 +212,7 @@ Gw - + @@ -227,56 +223,7 @@ Gw - - - - - - - - - - - - - - - - - Additional translatable language(s): English. To activate, select "Add Language" in Language Translation window and add phrases you want to translate." - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + diff --git a/SpriteBuilder/ccBuilder/LocalizationTranslateWindowHandler.h b/SpriteBuilder/ccBuilder/LocalizationTranslateWindowHandler.h index 45d52e118..a375da938 100644 --- a/SpriteBuilder/ccBuilder/LocalizationTranslateWindowHandler.h +++ b/SpriteBuilder/ccBuilder/LocalizationTranslateWindowHandler.h @@ -9,8 +9,5 @@ #import @interface LocalizationTranslateWindowHandler : NSWindow -@property (nonatomic,strong) NSPopover* translatePopOver; -@property (nonatomic,strong) NSButton* translateButton; --(void)setPopOver:(NSPopover*)p button:(NSButton*)b; @end \ No newline at end of file diff --git a/SpriteBuilder/ccBuilder/LocalizationTranslateWindowHandler.m b/SpriteBuilder/ccBuilder/LocalizationTranslateWindowHandler.m index 62dbcfa18..abf100077 100644 --- a/SpriteBuilder/ccBuilder/LocalizationTranslateWindowHandler.m +++ b/SpriteBuilder/ccBuilder/LocalizationTranslateWindowHandler.m @@ -10,19 +10,6 @@ @implementation LocalizationTranslateWindowHandler --(void)setPopOver:(NSPopover*)p button:(NSButton*)b{ - - self.translateButton = b; - self.translatePopOver = p; - -} --(void)mouseUp:(NSEvent *)theEvent{ - [super mouseUp:theEvent]; - if([self.translatePopOver isShown]){ - [self.translatePopOver close]; - } - self.translateButton.intValue = 0; -} -(void)close{ if([self isModalPanel]){ From 17ef128f9cb6785165c6cf742c079b246cfd3244 Mon Sep 17 00:00:00 2001 From: Benjamin Koatz Date: Thu, 26 Jun 2014 22:42:38 -0700 Subject: [PATCH 15/39] Fixed payment mechanism even on edge cases --- .../ccBuilder/LocalizationEditorWindow.m | 16 ++++----- .../ccBuilder/LocalizationTranslateWindow.m | 35 ++++++++++++------- 2 files changed, 30 insertions(+), 21 deletions(-) diff --git a/SpriteBuilder/ccBuilder/LocalizationEditorWindow.m b/SpriteBuilder/ccBuilder/LocalizationEditorWindow.m index ce6a73e9f..484055717 100644 --- a/SpriteBuilder/ccBuilder/LocalizationEditorWindow.m +++ b/SpriteBuilder/ccBuilder/LocalizationEditorWindow.m @@ -225,21 +225,19 @@ - (IBAction)selectedAddLanguage:(id)sender */ - (IBAction)pressedTranslate:(id)sender { if([_translationsButton.title isEqualToString:@"Buy Translations"]){ - //if(!_ltw) - //{ - _ltw = [[LocalizationTranslateWindow alloc] initWithWindowNibName:@"LocalizationTranslateWindow"]; - //} + _ltw = [[LocalizationTranslateWindow alloc] initWithWindowNibName:@"LocalizationTranslateWindow"]; [_ltw setParentWindow:self]; [_ltw.window makeKeyAndOrderFront:sender]; [NSApp runModalForWindow:_ltw.window]; } else { - _lctw = [[LocalizationCancelTranslationsWindow alloc] initWithWindowNibName:@"LocalizationCancelTranslationsWindow"]; - [_lctw setEditorWindow:self]; - [_lctw setTranslateWindow:_ltw]; - [_lctw.window makeKeyAndOrderFront:sender]; - [NSApp runModalForWindow:_lctw.window]; + NSAlert* alert = [NSAlert alertWithMessageText:@"Cancel Download" defaultButton:@"OK" alternateButton:@"Cancel" otherButton:NULL informativeTextWithFormat:@"If you cancel your translations download, you will not get a refund."]; + NSInteger result = [alert runModal]; + if(result == NSAlertDefaultReturn){ + [self finishDownloadingTranslations]; + [_ltw cancelDownload]; + } } } diff --git a/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.m b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.m index 3e4b509d7..8c2d1fcda 100644 --- a/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.m +++ b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.m @@ -618,18 +618,11 @@ - (void) tableView:(NSTableView *)tableView setObjectValue:(id)object forTableCo #pragma mark request delegate (and price display) --(void)request:(SKRequest *)request didFailWithError:(NSError *)error{ - NSLog(@"Request failed"); -} --(void)requestDidFinish:(SKRequest *)request{ - NSLog(@"Request finished"); -} /* * 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{ - NSLog(@"Product Request"); _products = response.products; for(NSString *invalidIdentifier in response.invalidProductIdentifiers) { @@ -664,17 +657,32 @@ -(void)displayPrice{ * Ask for a receipt for any updated paymnent transactions. */ -(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions{ - NSURL* receiptURL; for (SKPaymentTransaction* transaction in transactions) { switch(transaction.transactionState) { + case SKPaymentTransactionStateFailed: + { + NSLog(@"Failed"); + [[SKPaymentQueue defaultQueue] finishTransaction:transaction]; + break; + } case SKPaymentTransactionStatePurchased: - receiptURL = [[NSBundle mainBundle] appStoreReceiptURL]; + { + NSURL* receiptURL = [[NSBundle mainBundle] appStoreReceiptURL]; NSData* receipt = [NSData dataWithContentsOfURL:receiptURL]; [_receipts setObject:receipt forKey:transaction.transactionIdentifier]; - [self validateReceipt:[[NSString alloc] initWithData:receipt encoding:NSASCIIStringEncoding]]; + [self validateReceipt:[[NSString alloc] initWithData:receipt encoding:NSUTF8StringEncoding] transaction:transaction]; + [[SKPaymentQueue defaultQueue] finishTransaction:transaction]; break; + } + case SKPaymentTransactionStateRestored: + { + NSLog(@"Restored"); + [[SKPaymentQueue defaultQueue] finishTransaction:transaction]; + break; + } + } } } @@ -683,7 +691,7 @@ -(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)trans * Validates the receipt with our server. * TODO check for translations! */ --(void)validateReceipt:(NSString *)receipt{ +-(void)validateReceipt:(NSString *)receipt transaction:(SKPaymentTransaction*)transaction{ NSDictionary *JSONObject = [[NSDictionary alloc] initWithObjectsAndKeys: _guid,@"key",receipt,@"receipt",_phrasesToTranslate,@"phrases",nil]; NSError *error; if(![NSJSONSerialization isValidJSONObject:JSONObject]){ @@ -702,15 +710,17 @@ -(void)validateReceipt:(NSString *)receipt{ { if (!error) { - [self setLanguageWindowDownloading]; [self parseJSONTranslations:data]; NSLog(@"Yo1"); _timerTransDownload = [NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(getTranslations) userInfo:nil repeats:YES]; + [[SKPaymentQueue defaultQueue] removeTransactionObserver:self]; [self.window close]; + [self setLanguageWindowDownloading]; NSLog(@"Status code: %li", ((NSHTTPURLResponse *)response).statusCode); } else { + [[SKPaymentQueue defaultQueue] finishTransaction:transaction]; NSLog(@"Error: %@", error.localizedDescription); } }]; @@ -805,6 +815,7 @@ - (void)cancelDownload{ t.languagesDownloading = NULL; } [_timerTransDownload invalidate]; + _timerTransDownload = nil; [self sendCancelRequest]; } From 41dea2c8c94928fba47e9c96b88ce32d9ae0590f Mon Sep 17 00:00:00 2001 From: Benjamin Koatz Date: Fri, 27 Jun 2014 12:50:56 -0700 Subject: [PATCH 16/39] fixed receipt uploading and parsing issues, and received the first valid response message to a translation request!! --- .../ccBuilder/LocalizationTranslateWindow.m | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.m b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.m index 8c2d1fcda..6e4e5e3cf 100644 --- a/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.m +++ b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.m @@ -25,11 +25,12 @@ @implementation LocalizationTranslateWindow static int downloadLangsErrorIndex = 4; //URLs -static NSString* languageURL = @"http://spritebuilder-meteor.herokuapp.com/api/v1/translations/languages?key=%@"; -static NSString* const estimateURL = @"http://spritebuilder-meteor.herokuapp.com/api/v1/translations/estimate"; -static NSString* const receiptURL = @"http://spritebuilder-rails.herokuapp.com/translations"; -static NSString* translationsURL = @"http://spritebuilder-rails.herokuapp.com/translations?key=%@"; -static NSString* const cancelURL = @"http://spritebuilder-rails.herokuapp.com/translations/cancel"; +static NSString* baseURL = @"http://spritebuilder-meteor.herokuapp.com/api/v1"; +static NSString* languageURL; +static NSString* estimateURL; +static NSString* receiptTranslationsURL; +static NSString* translationsURL; +static NSString* cancelURL; //Messages for the user static NSString* const noActiveLangsString = @"No Valid Languages"; @@ -44,6 +45,12 @@ @implementation LocalizationTranslateWindow */ -(void) awakeFromNib { + 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"]; + _guid = [[[NSUserDefaults standardUserDefaults] dictionaryRepresentation] objectForKey:@"sbUserID"]; _languages = [[NSMutableDictionary alloc] init]; [[_translateFromTabView tabViewItemAtIndex:downloadLangsIndex] setView:_downloadingLangsView]; @@ -669,10 +676,11 @@ -(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)trans } case SKPaymentTransactionStatePurchased: { + NSLog(@"Purchased"); NSURL* receiptURL = [[NSBundle mainBundle] appStoreReceiptURL]; NSData* receipt = [NSData dataWithContentsOfURL:receiptURL]; [_receipts setObject:receipt forKey:transaction.transactionIdentifier]; - [self validateReceipt:[[NSString alloc] initWithData:receipt encoding:NSUTF8StringEncoding] transaction:transaction]; + [self validateReceipt:[receipt base64EncodedStringWithOptions:0] transaction:transaction]; [[SKPaymentQueue defaultQueue] finishTransaction:transaction]; break; } @@ -699,10 +707,11 @@ -(void)validateReceipt:(NSString *)receipt transaction:(SKPaymentTransaction*)tr return; } NSData *postdata2 = [NSJSONSerialization dataWithJSONObject:JSONObject options:0 error:&error]; - NSURL *url = [NSURL URLWithString:receiptURL]; + 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, @@ -831,6 +840,7 @@ -(void)sendCancelRequest{ 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, From 40710096d8ba1b42fc76993fb51b7e8abb35f9ef Mon Sep 17 00:00:00 2001 From: Benjamin Koatz Date: Fri, 27 Jun 2014 18:55:00 -0700 Subject: [PATCH 17/39] Implemented more functionality for dealing with the server. Get translations not working yet but it will be, I have faith! Also a method in EditorLanguage that simplifies my life. --- .../ccBuilder/LocalizationEditorLanguage.h | 2 +- .../ccBuilder/LocalizationEditorLanguage.m | 27 ++++++++ .../ccBuilder/LocalizationTranslateWindow.h | 2 +- .../ccBuilder/LocalizationTranslateWindow.m | 68 ++++++++++++++----- 4 files changed, 81 insertions(+), 18 deletions(-) diff --git a/SpriteBuilder/ccBuilder/LocalizationEditorLanguage.h b/SpriteBuilder/ccBuilder/LocalizationEditorLanguage.h index d1a75d1bf..826afc1d7 100644 --- a/SpriteBuilder/ccBuilder/LocalizationEditorLanguage.h +++ b/SpriteBuilder/ccBuilder/LocalizationEditorLanguage.h @@ -15,5 +15,5 @@ @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 854556e5b..720e1ecd0 100644 --- a/SpriteBuilder/ccBuilder/LocalizationEditorLanguage.m +++ b/SpriteBuilder/ccBuilder/LocalizationEditorLanguage.m @@ -42,6 +42,33 @@ - (id) initWithIsoLangCode:(NSString*)code return self; } ++ (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 diff --git a/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.h b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.h index c5496231f..cd97db8fc 100644 --- a/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.h +++ b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.h @@ -54,7 +54,7 @@ NSArray* _products; NSString* _guid; NSMutableDictionary* _receipts; - + NSString* _latestRequestID; LocalizationEditorWindow* _parentWindow; } diff --git a/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.m b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.m index 6e4e5e3cf..982a3b64d 100644 --- a/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.m +++ b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.m @@ -719,10 +719,9 @@ -(void)validateReceipt:(NSString *)receipt transaction:(SKPaymentTransaction*)tr { if (!error) { - [self parseJSONTranslations:data]; + [self parseJSONConfirmation:data]; NSLog(@"Yo1"); _timerTransDownload = [NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(getTranslations) userInfo:nil repeats:YES]; - [[SKPaymentQueue defaultQueue] removeTransactionObserver:self]; [self.window close]; [self setLanguageWindowDownloading]; NSLog(@"Status code: %li", ((NSHTTPURLResponse *)response).statusCode); @@ -736,6 +735,17 @@ -(void)validateReceipt:(NSString *)receipt transaction:(SKPaymentTransaction*)tr [task resume]; } +-(void)parseJSONConfirmation:(NSData *)data{ + NSError *JSONerror; + NSDictionary* initialTransDict = [NSJSONSerialization JSONObjectWithData:data + options:NSJSONReadingMutableContainers error:&JSONerror]; + if(JSONerror) + { + NSLog(@"JSONError: %@", JSONerror.localizedDescription); + return; + } + _latestRequestID = [initialTransDict objectForKey:@"request_id"]; +} -(void)setLanguageWindowDownloading{ LocalizationEditorHandler* handler = [AppDelegate appDelegate].localizationEditorHandler; NSArray* translations = handler.translations; @@ -769,24 +779,37 @@ -(void)parseJSONTranslations:(NSData *)data{ } LocalizationEditorHandler* handler = [AppDelegate appDelegate].localizationEditorHandler; NSArray* handlerTranslations = handler.translations; - NSArray* initialTrans = [initialTransDict objectForKey:@"phrases"]; - for(NSDictionary* transForKeys in initialTrans) - { - NSString* keyToTranslate = [transForKeys.allKeys objectAtIndex:0]; - NSDictionary* transDict = [transForKeys objectForKey:keyToTranslate]; - for(NSString* lang in transDict.allKeys){ - NSString* translation = [transDict objectForKey:lang]; - for(LocalizationEditorTranslation* t in handlerTranslations) - { - if([t.key isEqualToString:keyToTranslate] && [t.languagesDownloading containsObject:lang]){ - [t.translations setObject:translation forKey:lang]; - [t.languagesDownloading removeObject:lang]; - [_parentWindow incrementTransByOne]; + NSArray* requests = [initialTransDict objectForKey:@"requests"]; + NSDictionary* request = [requests objectAtIndex:0]; + NSString* requestID = [request objectForKey:@"request_id"]; + if(![requestID isEqualToString:_latestRequestID]){ + NSLog(@"Something went wrong"); + } + 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* translations = [phrase objectForKey:@"translations"]; + for(NSDictionary* translation in translations){ + NSString* translationIso = [translation objectForKey:@"target_language"]; + NSString* translationStatus = [translation objectForKey:@"status"]; + NSString* translationText = [translation objectForKey:@"text"]; + if([translationStatus isEqualToString:@"completed"]){ + 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]; + [_parentWindow incrementTransByOne]; + } } } } } if([_parentWindow translationProgress] == _numTransToDownload){ + [self endDownload]; [_parentWindow finishDownloadingTranslations]; } } @@ -803,7 +826,6 @@ -(void)getTranslations{ { if (!error) { - [self parseJSONTranslations:data]; NSLog(@"Status code: %li", ((NSHTTPURLResponse *)response).statusCode); } @@ -815,6 +837,20 @@ -(void)getTranslations{ [task resume]; } +- (void)endDownload{ + LocalizationEditorHandler* handler = [AppDelegate appDelegate].localizationEditorHandler; + NSArray* handlerTranslations = handler.translations; + for(LocalizationEditorTranslation* t in handlerTranslations) + { + if(t.languagesDownloading.count) + { + NSLog(@"Oops, language still downloading"); + t.languagesDownloading = NULL; + } + } + [_timerTransDownload invalidate]; + _timerTransDownload = nil; +} - (void)cancelDownload{ LocalizationEditorHandler* handler = [AppDelegate appDelegate].localizationEditorHandler; From 1649ada1ddfbef7c205eab9fe487f9dda3d20aa0 Mon Sep 17 00:00:00 2001 From: Benjamin Koatz Date: Mon, 30 Jun 2014 18:10:00 -0700 Subject: [PATCH 18/39] Cached and serialized the data about downloading languages and updated the way the Language Window does bindings accordingly. Also made some minor UI changes in accordance with Apple's guidelines --- .../SpriteBuilder.xcodeproj/project.pbxproj | 10 ---- .../xcschemes/SpriteBuilder.xcscheme | 7 +++ .../ccBuilder/LocalizationEditorHandler.m | 8 ++- .../ccBuilder/LocalizationEditorTranslation.m | 4 +- .../ccBuilder/LocalizationEditorWindow.m | 34 ++++++++--- .../ccBuilder/LocalizationEditorWindow.xib | 12 ++-- .../ccBuilder/LocalizationTranslateWindow.m | 33 +++++++---- .../ccBuilder/LocalizationTranslateWindow.xib | 57 +++++++++---------- SpriteBuilder/ccBuilder/ProjectSettings.h | 2 + SpriteBuilder/ccBuilder/ProjectSettings.m | 4 +- 10 files changed, 99 insertions(+), 72 deletions(-) diff --git a/SpriteBuilder/SpriteBuilder.xcodeproj/project.pbxproj b/SpriteBuilder/SpriteBuilder.xcodeproj/project.pbxproj index c6ecd4c0e..a5f2c50b3 100644 --- a/SpriteBuilder/SpriteBuilder.xcodeproj/project.pbxproj +++ b/SpriteBuilder/SpriteBuilder.xcodeproj/project.pbxproj @@ -102,8 +102,6 @@ 7B3EF5DB195885F20023C169 /* LocalizationTranslateWindowHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 7B3EF5DA195885F20023C169 /* LocalizationTranslateWindowHandler.m */; }; 7B5135C21947CC2500DE177D /* LocalizationInAppPurchasesPIDs.plist in Resources */ = {isa = PBXBuildFile; fileRef = 7B5135C11947CC2500DE177D /* LocalizationInAppPurchasesPIDs.plist */; }; 7B88AD47195A4846001BF73C /* LocalizationEditorTextFieldCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 7B88AD46195A4846001BF73C /* LocalizationEditorTextFieldCell.m */; }; - 7B88AD4C195B8111001BF73C /* LocalizationCancelTranslationsWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 7B88AD4B195B8111001BF73C /* LocalizationCancelTranslationsWindow.xib */; }; - 7B88AD4F195B812C001BF73C /* LocalizationCancelTranslationsWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = 7B88AD4E195B812C001BF73C /* LocalizationCancelTranslationsWindow.m */; }; 7BCC1C0D194904190062DF38 /* StoreKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7BCC1C0C194904190062DF38 /* StoreKit.framework */; }; 7BF55303193F8A7500183F09 /* LocalizationTranslateWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 7BF55302193F8A7500183F09 /* LocalizationTranslateWindow.xib */; }; 7BF55307193F912200183F09 /* LocalizationTranslateWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = 7BF55306193F912200183F09 /* LocalizationTranslateWindow.m */; }; @@ -1264,9 +1262,6 @@ 7B5135C11947CC2500DE177D /* LocalizationInAppPurchasesPIDs.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = LocalizationInAppPurchasesPIDs.plist; path = ../ccBuilder/LocalizationInAppPurchasesPIDs.plist; 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 = ""; }; - 7B88AD4B195B8111001BF73C /* LocalizationCancelTranslationsWindow.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = LocalizationCancelTranslationsWindow.xib; sourceTree = ""; }; - 7B88AD4D195B812C001BF73C /* LocalizationCancelTranslationsWindow.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LocalizationCancelTranslationsWindow.h; sourceTree = ""; }; - 7B88AD4E195B812C001BF73C /* LocalizationCancelTranslationsWindow.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LocalizationCancelTranslationsWindow.m; sourceTree = ""; }; 7BCC1C0C194904190062DF38 /* StoreKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = StoreKit.framework; path = System/Library/Frameworks/StoreKit.framework; sourceTree = SDKROOT; }; 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 = ""; }; @@ -3446,9 +3441,6 @@ children = ( B7083DF717B1CBC8006628C7 /* LocalizationEditorHandler.h */, B7083DF817B1CBC8006628C7 /* LocalizationEditorHandler.m */, - 7B88AD4B195B8111001BF73C /* LocalizationCancelTranslationsWindow.xib */, - 7B88AD4D195B812C001BF73C /* LocalizationCancelTranslationsWindow.h */, - 7B88AD4E195B812C001BF73C /* LocalizationCancelTranslationsWindow.m */, 7B3EF5D9195885F20023C169 /* LocalizationTranslateWindowHandler.h */, 7B3EF5DA195885F20023C169 /* LocalizationTranslateWindowHandler.m */, 7BF55302193F8A7500183F09 /* LocalizationTranslateWindow.xib */, @@ -5481,7 +5473,6 @@ 92F0960518F8851300D47A94 /* inspector-body-connected.png in Resources */, E3C65106151A3B7C00D639C0 /* InspectorString.xib in Resources */, E3C65128151C7B9000D639C0 /* InspectorBlockCCControl.xib in Resources */, - 7B88AD4C195B8111001BF73C /* LocalizationCancelTranslationsWindow.xib in Resources */, E34E5D6A153585EC000201FB /* ruler-bg-horizontal.png in Resources */, E34E5D6B153585EC000201FB /* ruler-bg-vertical.png in Resources */, B7096E2B180CD98E00164A8A /* doc-scene.png in Resources */, @@ -6207,7 +6198,6 @@ B7C3533E17FA30BB005697C1 /* NodePhysicsBody.m in Sources */, E3C12B1B171DD386001EEDDB /* NSWindow+CCBAccessoryView.m in Sources */, E37FCAF4175D68FF009F81D6 /* ResourceManagerPreviewView.m in Sources */, - 7B88AD4F195B812C001BF73C /* LocalizationCancelTranslationsWindow.m in Sources */, E37FCAF9175FF70F009F81D6 /* CCBImageView.m in Sources */, B78DA3641773A89B00B85CC0 /* CCBButtonUnclickable.m in Sources */, B78DA3691773EA0E00B85CC0 /* NSPasteboard+CCB.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"> + + + + max) return max; else return proposedMaximumPosition; } + +-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{ + if([keyPath isEqualToString:@"hasOpenFile"]){ + if(((ProjectSettings*)[AppDelegate appDelegate].projectSettings).isDownloadingTranslations) + { + [self setDownloadingTranslations:0]; + }else{ + [self finishDownloadingTranslations]; + } + } + +} @end diff --git a/SpriteBuilder/ccBuilder/LocalizationEditorWindow.xib b/SpriteBuilder/ccBuilder/LocalizationEditorWindow.xib index 019c35f9d..442dd96cf 100644 --- a/SpriteBuilder/ccBuilder/LocalizationEditorWindow.xib +++ b/SpriteBuilder/ccBuilder/LocalizationEditorWindow.xib @@ -86,7 +86,6 @@ - @@ -331,7 +330,6 @@ - @@ -373,7 +371,6 @@ - @@ -397,13 +394,12 @@ - - + @@ -259,11 +258,11 @@ Gw - + - + @@ -274,11 +273,11 @@ Gw - + - + @@ -298,7 +297,7 @@ Gw - + @@ -307,7 +306,7 @@ Gw - + @@ -316,7 +315,7 @@ Gw - + @@ -325,7 +324,7 @@ Gw - + - + - + @@ -359,20 +358,20 @@ Gw - + - + - + - - - - - - - - - - - + + - + - - + + - + - - + + - + - @@ -349,7 +320,7 @@ Gw - + @@ -364,7 +335,7 @@ Gw - + @@ -384,20 +355,20 @@ Gw - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/SpriteBuilder/ccBuilder/ProjectSettings.h b/SpriteBuilder/ccBuilder/ProjectSettings.h index 6fb50b6f8..3a293d11e 100644 --- a/SpriteBuilder/ccBuilder/ProjectSettings.h +++ b/SpriteBuilder/ccBuilder/ProjectSettings.h @@ -93,6 +93,12 @@ typedef enum BOOL deviceOrientationLandscapeRight; int resourceAutoScaleFactor; + //Translations + BOOL isDownloadingTranslations; + double numToDownload; + double numDownloaded; + NSString* latestRequestID; + NSString* versionStr; BOOL needRepublish; @@ -143,6 +149,12 @@ typedef enum @property (nonatomic, assign) int resourceAutoScaleFactor; @property (nonatomic, assign) NSInteger publishEnvironment; +//TranslationDownloads +@property (nonatomic,assign) BOOL isDownloadingTranslations; +@property (nonatomic,readwrite) double numToDownload; +@property (nonatomic,assign) double numDownloaded; +@property (nonatomic,strong) NSString* latestRequestID; + // Temporary property, do not persist @property (nonatomic) BOOL canUpdateCocos2D; @property (nonatomic) NSMutableArray *cocos2dUpdateIgnoredVersions; @@ -159,8 +171,6 @@ typedef enum @property (nonatomic, readonly) CCBTargetEngine engine; -@property (nonatomic,assign) BOOL isDownloadingTranslations; - - (id) initWithSerialization:(id)dict; - (BOOL) store; - (id) serialize; diff --git a/SpriteBuilder/ccBuilder/ProjectSettings.m b/SpriteBuilder/ccBuilder/ProjectSettings.m index 7266140b9..b577b8720 100644 --- a/SpriteBuilder/ccBuilder/ProjectSettings.m +++ b/SpriteBuilder/ccBuilder/ProjectSettings.m @@ -68,6 +68,10 @@ @implementation ProjectSettings @synthesize versionStr; @synthesize needRepublish; @synthesize lastWarnings; +@synthesize isDownloadingTranslations; +@synthesize numDownloaded; +@synthesize numToDownload; +@synthesize latestRequestID; - (id) init { @@ -111,6 +115,12 @@ - (id) init 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]) @@ -147,7 +157,6 @@ - (id) initWithSerialization:(id)dict self.publishEnablediPhone = [[dict objectForKey:@"publishEnablediPhone"] boolValue]; self.publishEnabledAndroid = [[dict objectForKey:@"publishEnabledAndroid"] boolValue]; - self.isDownloadingTranslations = [[dict objectForKey:@"isDownloadingTranslations"] 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]; @@ -188,6 +197,12 @@ - (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"]; + // Check if we are running a new version of CocosBuilder // in which case the project needs to be republished NSString* oldVersionHash = [dict objectForKey:@"versionStr"]; @@ -256,7 +271,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"]; - [dict setObject:[NSNumber numberWithInt:self.isDownloadingTranslations] forKey:@"isDownloadingTranslations"]; + + //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"]; if (resourceProperties) From b7d1d93254089c7665a4735935be304940c4cf68 Mon Sep 17 00:00:00 2001 From: Benjamin Koatz Date: Wed, 2 Jul 2014 21:13:23 -0700 Subject: [PATCH 20/39] Add more error handling and working parsing for translations (though the server-side of the parsing is not working yet). Have to handle cancels with errors and more server interaction once that is ready. Also commented, cleaned and styled code. --- .../ccBuilder/LocalizationEditorHandler.m | 10 +- .../ccBuilder/LocalizationEditorLanguage.m | 3 + .../ccBuilder/LocalizationEditorWindow.h | 3 +- .../ccBuilder/LocalizationEditorWindow.m | 67 ++- .../ccBuilder/LocalizationTranslateWindow.h | 3 +- .../ccBuilder/LocalizationTranslateWindow.m | 526 ++++++++++-------- .../ccBuilder/LocalizationTranslateWindow.xib | 30 +- 7 files changed, 376 insertions(+), 266 deletions(-) diff --git a/SpriteBuilder/ccBuilder/LocalizationEditorHandler.m b/SpriteBuilder/ccBuilder/LocalizationEditorHandler.m index 6dbe8df76..2fb8119ee 100644 --- a/SpriteBuilder/ccBuilder/LocalizationEditorHandler.m +++ b/SpriteBuilder/ccBuilder/LocalizationEditorHandler.m @@ -280,6 +280,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) @@ -290,8 +294,10 @@ - (IBAction)openEditor:(id)sender windowController.hasOpenFile = (managedFile != NULL); if(((ProjectSettings*)[AppDelegate appDelegate].projectSettings).isDownloadingTranslations) { - [windowController setDownloadingTranslations:0]; - }else{ + [windowController setDownloadingTranslations]; + } + else + { [windowController finishDownloadingTranslations]; } } diff --git a/SpriteBuilder/ccBuilder/LocalizationEditorLanguage.m b/SpriteBuilder/ccBuilder/LocalizationEditorLanguage.m index 720e1ecd0..db9981bc0 100644 --- a/SpriteBuilder/ccBuilder/LocalizationEditorLanguage.m +++ b/SpriteBuilder/ccBuilder/LocalizationEditorLanguage.m @@ -42,6 +42,9 @@ - (id) initWithIsoLangCode:(NSString*)code return self; } +/* + * Returns the name of a language from the iso code. + */ + (NSString*) nameFromCode:(NSString*)code { NSString* name = NULL; diff --git a/SpriteBuilder/ccBuilder/LocalizationEditorWindow.h b/SpriteBuilder/ccBuilder/LocalizationEditorWindow.h index ab96932b3..2bb472485 100644 --- a/SpriteBuilder/ccBuilder/LocalizationEditorWindow.h +++ b/SpriteBuilder/ccBuilder/LocalizationEditorWindow.h @@ -40,8 +40,7 @@ - (void)removeLanguagesAtIndexes:(NSIndexSet*)idxs; - (IBAction)selectedCurrentLanguage:(id)sender; - (void)addLanguages:(NSArray*)langs; -- (void)removeLanguages:(NSArray*)langs; -- (void)setDownloadingTranslations:(double)numToTrans; +- (void)setDownloadingTranslations; - (void)incrementTransByOne; - (double)translationProgress; - (void)finishDownloadingTranslations; diff --git a/SpriteBuilder/ccBuilder/LocalizationEditorWindow.m b/SpriteBuilder/ccBuilder/LocalizationEditorWindow.m index e3a9cdfb7..10aeb5dea 100644 --- a/SpriteBuilder/ccBuilder/LocalizationEditorWindow.m +++ b/SpriteBuilder/ccBuilder/LocalizationEditorWindow.m @@ -18,8 +18,8 @@ #import "NSPasteboard+CCB.h" #import "ProjectSettings.h" @implementation LocalizationEditorWindow - @synthesize ltw = _ltw; + - (void) awakeFromNib { [tableTranslations registerForDraggedTypes:[NSArray arrayWithObject:@"com.cocosbuilder.LocalizationEditorTranslation"]]; @@ -200,10 +200,6 @@ - (IBAction)pressedAdd:(id)sender - (IBAction)pressedAddGroup:(id)sender {} -/* - * If a language is added, do what is shown here but also reload the langauge menu on the - * language translation window if there is one open. - */ - (IBAction)selectedAddLanguage:(id)sender { NSString* name = popLanguageAdd.selectedItem.title; @@ -220,13 +216,16 @@ - (IBAction)selectedAddLanguage:(id)sender } /* - * Just displays a translate window. - * TODO Make the window key and main + * If you are opening a new window and one doesn't exist, open it and make it modal. + * 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){ + if([_translationsButton.title isEqualToString:@"Buy Translations..."]) + { + if(!_ltw) + { _ltw = [[LocalizationTranslateWindow alloc] initWithWindowNibName:@"LocalizationTranslateWindow"]; } [_ltw setParentWindow:self]; @@ -237,22 +236,24 @@ - (IBAction)pressedTranslate:(id)sender { { NSAlert* alert = [NSAlert alertWithMessageText:@"Stop Download" defaultButton:@"Cancel" alternateButton:@"OK" otherButton:NULL informativeTextWithFormat:@"If you stop your translations download, you will not get a refund."]; NSInteger result = [alert runModal]; - if(result == NSAlertAlternateReturn){ + if(result == NSAlertAlternateReturn) + { [self finishDownloadingTranslations]; - [_ltw stopDownload]; + [_ltw cancelDownloadWithError:nil]; [tableLanguages reloadData]; - _ltw = nil; } } } /* - * TO COMMENT + * 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){ + for(NSString* iso in langs) + { if([iso isEqualToString:@"zh"]) { [handler addActiveLanguage:[handler getLanguageByIsoLangCode:@"zh-Hans"]]; @@ -266,23 +267,17 @@ - (void)addLanguages:(NSArray*)langs [self updateLanguageSelectionMenu]; [self updateQuickEditLangs]; [self updateInspector]; - //[handler setEdited]; } -- (void)removeLanguages:(NSArray*)langs -{} +/* + * 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:(double)numToTrans{ +-(void)setDownloadingTranslations{ ProjectSettings* ps = [AppDelegate appDelegate].projectSettings; ps.isDownloadingTranslations = 1; - if(numToTrans) - { - [_translationProgress setMaxValue:numToTrans]; - ps.numToDownload = numToTrans; - } - else{ - [_translationProgress setMaxValue:ps.numToDownload]; - } + [_translationProgress setMaxValue:ps.numToDownload]; [_translationProgress setDoubleValue:ps.numDownloaded]; [_translationProgress setHidden:0]; [_translationProgressText setHidden:0]; @@ -294,15 +289,27 @@ -(void)setDownloadingTranslations:(double)numToTrans{ _translationsButton.title = @"Stop Download..."; } +/* + * Make the translation progress bar increase by one + */ -(void)incrementTransByOne{ ProjectSettings* ps = [AppDelegate appDelegate].projectSettings; ps.numDownloaded++; [_translationProgress incrementBy:1.0]; } +/* + * 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{ ((ProjectSettings*)[AppDelegate appDelegate].projectSettings).isDownloadingTranslations=0; [_translationProgress setHidden:1]; @@ -741,6 +748,10 @@ - (CGFloat) splitView:(NSSplitView *)splitView constrainMaxCoordinate:(CGFloat)p else return proposedMaximumPosition; } +/* + * 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; if([keyPath isEqualToString:@"hasOpenFile"]){ @@ -748,11 +759,11 @@ -(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NS { _ltw = [[LocalizationTranslateWindow alloc] initWithDownload:ps.latestRequestID parentWindow:self numToDownload:ps.numToDownload]; [_ltw restartDownload]; - [self setDownloadingTranslations:ps.numToDownload]; + [self setDownloadingTranslations]; }else{ [_ltw pauseDownload]; - _ltw = nil; [self finishDownloadingTranslations]; + _ltw = nil; } } diff --git a/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.h b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.h index 685d4ce12..dcc56386d 100644 --- a/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.h +++ b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.h @@ -21,6 +21,7 @@ IBOutlet NSView* _downloadingLangsView; IBOutlet NSView* _downloadingLangsErrorView; IBOutlet NSView* _downloadingCostsErrorView; + IBOutlet NSView* _paymentErrorView; IBOutlet NSTabView* _translateFromTabView; //fields inside tab views @@ -67,7 +68,7 @@ - (IBAction)toggleCheckAll:(id)sender; - (IBAction)retryLanguages:(id)sender; - (IBAction)retryCost:(id)sender; -- (void)stopDownload; +- (void)cancelDownloadWithError:(NSError*)error; - (void)pauseDownload; - (void)restartDownload; @property (nonatomic,strong) LocalizationEditorWindow* parentWindow; diff --git a/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.m b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.m index 12ee6ef5a..0403b8774 100644 --- a/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.m +++ b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.m @@ -18,12 +18,14 @@ @implementation LocalizationTranslateWindow @synthesize parentWindow = _parentWindow; @synthesize guid = _guid; @synthesize languages = _languages; + //Standards for the tab view static int downloadLangsIndex = 0; static int noActiveLangsIndex = 1; static int standardLangsIndex = 2; static int downloadCostErrorIndex = 3; static int downloadLangsErrorIndex = 4; +static int paymentErrorIndex = 5; //URLs static NSString* baseURL = @"http://spritebuilder-meteor.herokuapp.com/api/v1"; @@ -38,64 +40,71 @@ @implementation LocalizationTranslateWindow static NSString* const downloadingLangsString = @"Downloading..."; static NSString* noActiveLangsErrorString = @"We support translations from:\r\r%@."; -#pragma mark Init --(id)init{ - self = [super init]; - 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]; - return self; -} +//Download time +//static double downloadRepeatInterval = 300; +static double downloadRepeatInterval = 5; + +#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:(NSString*)requestID parentWindow:(LocalizationEditorWindow*)pw numToDownload:(double)numTrans{ - self = [self init]; + self = [super init]; if (!self) return NULL; + [self setUpURLsAndGlobals]; _latestRequestID = requestID; _parentWindow = pw; _numTransToDownload = numTrans; return self; } + /* - * Set up the guid, the languages global dictionary, the tab views, the window handler - * and get the dictionary's contents from the server + * 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 { - 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"]; - - _guid = [[[NSUserDefaults standardUserDefaults] dictionaryRepresentation] objectForKey:@"sbUserID"]; - _languages = [[NSMutableDictionary alloc] init]; + [self setUpURLsAndGlobals]; [[_translateFromTabView tabViewItemAtIndex:downloadLangsIndex] setView:_downloadingLangsView]; [[_translateFromTabView tabViewItemAtIndex:noActiveLangsIndex] setView:_noActiveLangsView]; [[_translateFromTabView tabViewItemAtIndex:standardLangsIndex] setView:_standardLangsView]; [[_translateFromTabView tabViewItemAtIndex:downloadCostErrorIndex] setView:_downloadingCostsErrorView]; [[_translateFromTabView tabViewItemAtIndex:downloadLangsErrorIndex] setView:_downloadingLangsErrorView]; + [[_translateFromTabView tabViewItemAtIndex:paymentErrorIndex] setView:_paymentErrorView]; [self disableAll]; [self getLanguagesFromServer]; } -#pragma mark Downloading and updating languages +/* + * 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]; +} + +#pragma mark Downloading and Updating Languages /* - * Disable the translate from menu and show the downloading languages message. + * 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. + * 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]; + NSString* URLstring =[NSString stringWithFormat:languageURL, _guid]; NSURL* url = [NSURL URLWithString:URLstring]; NSURLSessionDataTask *task = [[NSURLSession sharedSession] dataTaskWithURL: url completionHandler:^(NSData *data, @@ -109,32 +118,19 @@ -(void)getLanguagesFromServer{ } else { + [_languagesDownloading stopAnimation:self]; + [_translateFromTabView selectTabViewItemAtIndex:downloadLangsErrorIndex]; NSLog(@"Error: %@", error.localizedDescription); } }]; [task resume]; } --(void)disableAll{ - [_popTranslateFrom setEnabled:0]; - [_languageTable setEnabled:0]; - [_checkAll setEnabled:0]; - [_ignoreText setEnabled:0]; -} --(void)enableAll{ - dispatch_async(dispatch_get_main_queue(), ^{ - [_popTranslateFrom setEnabled:1]; - [_languageTable setEnabled:1]; - [_checkAll setEnabled:1]; - [_ignoreText setEnabled:1]; - [_cancel setEnabled:1]; - }); -} /* * 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 SpriteBuilder session. Errors handled and + * only done once in the beginning of the session. Errors handled and * displayed. */ -(void)parseJSONLanguages:(NSData *)data{ @@ -159,7 +155,7 @@ -(void)parseJSONLanguages:(NSData *)data{ [_languages setObject:translateTo forKey:[[LocalizationEditorLanguage alloc] initWithIsoLangCode:lIso]]; } [self updateActiveLanguages]; - [self finishSetUp]; + [self finishLanguageSetUp]; } /* @@ -187,7 +183,7 @@ -(void)updateActiveLanguages{ * If there are no active languages that we can translate from * then a the pop-up menu is disabled, an error message with instructions is shown. */ --(void)finishSetUp{ +-(void)finishLanguageSetUp{ [_languagesDownloading stopAnimation:self]; [self uncheckLanguageDict]; @@ -209,41 +205,21 @@ -(void)finishSetUp{ } } -/* - * 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; - } -} - /* * 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 or reload after - * a language is added/deleted on the Language Translation window) everything is normal. But + * 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 if this isn't the initial - * update (e.g. if the window is already loaded and someone is selecting a new language - * to translate from) then update the main language table and the check all box accordingly. - * Finally, toggle the visibility of the 'Translate From Info' button. - * - * The 'isNewLangActive' variable handles the edge case where a user deletes an active - * 'translate from' language from the Langauge window, and just sets the current language - * and language selection menu accordingly. + * 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(self.isWindowLoaded && _currLang && userSelection && [newLangSelection isEqualToString:_currLang.name]) + if(userSelection && [newLangSelection isEqualToString:_currLang.name]) { return; } @@ -254,40 +230,30 @@ - (void) updateLanguageSelectionMenu:(int)userSelection [_popTranslateFrom removeAllItems]; NSMutableArray* langTitles = [NSMutableArray array]; - int isNewLangActive = 0; for (LocalizationEditorLanguage* lang in _activeLanguages) { if([lang.name isEqualToString:newLangSelection]) { - isNewLangActive = 1; _currLang = lang; } [langTitles addObject:lang.name]; } + [_popTranslateFrom addItemsWithTitles:langTitles]; - if(!isNewLangActive){ - _currLang = [_activeLanguages objectAtIndex:0]; - [_popTranslateFrom selectItemWithTitle:_currLang.name]; - } - else if (newLangSelection) + if (newLangSelection) { [_popTranslateFrom selectItemWithTitle:newLangSelection]; } - if([self isWindowLoaded]) - { - dispatch_async(dispatch_get_main_queue(), ^{ - [_languageTable reloadData]; - }); - [self updateCheckAll]; - } - - + dispatch_async(dispatch_get_main_queue(), ^{ + [_languageTable reloadData]; + }); + [self updateCheckAll]; } -#pragma mark Downloading Cost Estimate and word count +#pragma mark Downloading Cost Estimate and Word Count /* * Gets the estimated cost of a translation request using the currrent user-set parameters. @@ -318,12 +284,14 @@ -(void)getCostEstimate{ _guid,@"key", _phrasesToTranslate,@"phrases", nil]; - if(![NSJSONSerialization isValidJSONObject:JSONObject]){ + if(![NSJSONSerialization isValidJSONObject:JSONObject]) + { NSLog(@"Not a JSON Object!!!"); } NSError *error; NSData *postdata = [NSJSONSerialization dataWithJSONObject:JSONObject options:0 error:&error]; - if(error){ + if(error) + { NSLog(@"Error: %@", error); } NSURL *url = [NSURL URLWithString:estimateURL]; @@ -335,34 +303,42 @@ -(void)getCostEstimate{ completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) - { - if (!error) - { - [self parseJSONEstimate:data]; - if(_tierForTranslations > 0) - { - [self requestIAPProducts]; - } - NSLog(@"Status code: %li", ((NSHTTPURLResponse *)response).statusCode); - } - else - { - NSLog(@"Error: %@", error.localizedDescription); - } - }]; + { + if (!error) + { + [self parseJSONEstimate:data]; + if(_tierForTranslations > 0) + { + [self requestIAPProducts]; + } + else + { + [_costDownloading stopAnimation:self]; + [_translateFromTabView selectTabViewItemAtIndex:downloadCostErrorIndex]; + } + NSLog(@"Status code: %li", ((NSHTTPURLResponse *)response).statusCode); + } + else + { + [_costDownloading stopAnimation:self]; + [_translateFromTabView selectTabViewItemAtIndex:downloadCostErrorIndex]; + NSLog(@"Error: %@", error.localizedDescription); + } + }]; [task resume]; } /* * Goes through every LocalizationEditorTranslation, first seeing if there is a - * version of the phrase in the 'translate from' language. + * version of the phrase in the 'translate from' language that isn't null or just + * whitespace. * Then populating 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. We then add this - * number 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 + * 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, the languages to translate to and add that dictionary to an array * of phrases. * @@ -375,7 +351,9 @@ -(NSInteger)updatePhrasesToTranslate{ for(LocalizationEditorTranslation* t in trans) { NSString* toTranslate = [t.translations objectForKey:_currLang.isoLangCode]; - if(!toTranslate || [toTranslate isEqualToString:@""]) + NSCharacterSet *set = [NSCharacterSet whitespaceCharacterSet]; + if(!toTranslate || [toTranslate isEqualToString:@""] + || ([[toTranslate stringByTrimmingCharactersInSet: set] length] == 0)) { continue; } @@ -422,8 +400,10 @@ -(NSInteger)updatePhrasesToTranslate{ } /* - * Parses the JSON response from a request for a cost estimate. Handles error and sets - * the translation tier and number of words. + * 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. + * TODO add all the translation tiers. */ -(void)parseJSONEstimate:(NSData*)data{ NSError *JSONerror; @@ -437,7 +417,8 @@ -(void)parseJSONEstimate:(NSData*)data{ return; } _tierForTranslations = [[dataDict objectForKey:@"iap_price_tier"] intValue]; - if(_tierForTranslations != 1){ + if(_tierForTranslations != 1) + { NSLog(@"Time to create a new IAP!!! Level: %ld", _tierForTranslations); _tierForTranslations = 1; } @@ -456,14 +437,19 @@ -(void)requestIAPProducts{ [request start]; } -#pragma mark Toggling/Clicking button events +#pragma mark Toggling/Clicking Button Events /* * Solicit a payment and set the cancel button to say 'Finish'. */ - (IBAction)buy:(id)sender { if(!_products.count || !_phrasesToTranslate.count) + { + NSLog(@"Shouldn't have been able to click buy!!"); return; + } + for(int i = 0; i < 20; i++) + [[SKPaymentQueue defaultQueue] removeTransactionObserver:self]; [[SKPaymentQueue defaultQueue] addTransactionObserver:self]; SKPayment* payment = [SKPayment paymentWithProduct:[_products objectAtIndex:(_tierForTranslations -1)]]; [[SKPaymentQueue defaultQueue] addPayment:payment]; @@ -487,7 +473,7 @@ - (IBAction)toggleIgnore:(id)sender { /* * Update the langauge select menu if someone has selected the pop-up - * 'translate from' menu. Send 0 because this is not a reload, it is a + * 'translate from' menu. Send 1 because this is a * user-click generated event. */ - (IBAction)selectedTranslateFromMenu:(id)sender { @@ -503,12 +489,12 @@ - (IBAction)selectedTranslateFromMenu:(id)sender { - (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 @@ -525,24 +511,7 @@ - (IBAction)retryCost:(id)sender { [self getCostEstimate]; } -#pragma mark Response to events in the main Language Window - -/* - * Once a new language is input to the Language Translate window's main - * table, this is called to reload the cost in the translate window. - */ -- (void)reloadCost{ - [self getCostEstimate]; -} - -/* - * Flashes the no active langauges error. - */ -- (void)toggleNoActiveLangsAlpha { - [_noActiveLangsError setHidden:(!_noActiveLangsError.isHidden)]; -} - -#pragma mark update error strings and the 'check all' button +#pragma mark Update Error Strings and the 'Check All' Button /* * Put all the available 'translate from' languages in the no active languages error @@ -571,9 +540,13 @@ -(void)updateCheckAll{ for(LocalizationEditorLanguage* l in [_languages objectForKey:_currLang]) { if(!l.quickEdit) + { checkAllTrue = 0; + } else + { checkAllFalse = 1; + } } if(checkAllFalse && !checkAllTrue) { @@ -592,7 +565,7 @@ -(void)updateCheckAll{ } } -#pragma mark table view delegate +#pragma mark Table View Delegate /* * If there's no current language then there's going to be nothing to @@ -622,7 +595,7 @@ - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColu { return 0; } - if ([aTableColumn.identifier isEqualToString:@"enabled"]) + if ([aTableColumn.identifier isEqualToString:@"enabled"]) { LocalizationEditorLanguage* lang = [((NSArray*)[_languages objectForKey:_currLang]) objectAtIndex:rowIndex]; return [NSNumber numberWithBool:lang.quickEdit]; @@ -649,7 +622,16 @@ - (void) tableView:(NSTableView *)tableView setObjectValue:(id)object forTableCo } } -#pragma mark request delegate (and price display) +#pragma mark Product Request Delegate + +/* + * If product request fails, say that the cost estimate failed. + */ +-(void) request:(SKRequest *)request didFailWithError:(NSError *)error{ + [_costDownloading stopAnimation:self]; + [_translateFromTabView selectTabViewItemAtIndex:downloadCostErrorIndex]; + NSLog(@"Product Request Failed"); +} /* * Takes in the products returned by apple, prints any invalid identifiers and displays @@ -667,27 +649,11 @@ -(void) productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProdu [self displayPrice]; } -/* - * Locally format the price of the current translation estimate, display it, - * and hide the cost downloading message and spinning icon. - */ --(void)displayPrice{ - SKProduct* p = [_products objectAtIndex:(_tierForTranslations - 1)]; - NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init]; - [numberFormatter setNumberStyle:NSNumberFormatterCurrencyStyle]; - [numberFormatter setLocale:p.priceLocale]; - NSString *formattedString = [numberFormatter stringFromNumber:p.price]; - _cost.stringValue = formattedString; - [_costDownloading setHidden:1]; - [_costDownloadingText setHidden:1]; - [_costDownloading stopAnimation:self]; - [_buy setEnabled:1]; -} - -#pragma mark payment transaction observer +#pragma mark Payment Transaction Observer /* - * Ask for a receipt for any updated paymnent transactions. + * Ask for a receipt for any updated paymnent transactions. If it succeeds, + * validate the receipt with the server. */ -(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions{ for (SKPaymentTransaction* transaction in transactions) @@ -698,6 +664,7 @@ -(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)trans { NSLog(@"Failed"); [[SKPaymentQueue defaultQueue] finishTransaction:transaction]; + [_translateFromTabView selectTabViewItemAtIndex:paymentErrorIndex]; break; } case SKPaymentTransactionStatePurchased: @@ -710,25 +677,22 @@ -(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)trans [[SKPaymentQueue defaultQueue] finishTransaction:transaction]; break; } - case SKPaymentTransactionStateRestored: - { - NSLog(@"Restored"); - [[SKPaymentQueue defaultQueue] finishTransaction:transaction]; - break; - } - } } } +#pragma mark Validate Receipt and Set Up Downloading Translations + /* - * Validates the receipt with our server. - * TODO check for 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 transaction:(SKPaymentTransaction*)transaction{ NSDictionary *JSONObject = [[NSDictionary alloc] initWithObjectsAndKeys: _guid,@"key",receipt,@"receipt",_phrasesToTranslate,@"phrases",nil]; NSError *error; - if(![NSJSONSerialization isValidJSONObject:JSONObject]){ + if(![NSJSONSerialization isValidJSONObject:JSONObject]) + { NSLog(@"Invalid JSON"); return; } @@ -747,7 +711,7 @@ -(void)validateReceipt:(NSString *)receipt transaction:(SKPaymentTransaction*)tr { [self parseJSONConfirmation:data]; dispatch_async(dispatch_get_main_queue(), ^{ - _timerTransDownload = [NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(getTranslations) userInfo:nil repeats:YES]; + _timerTransDownload = [NSTimer scheduledTimerWithTimeInterval:downloadRepeatInterval target:self selector:@selector(getTranslations) userInfo:nil repeats:YES]; [self.window close]; [self setLanguageWindowDownloading]; LocalizationEditorHandler* handler = [AppDelegate appDelegate].localizationEditorHandler; @@ -758,18 +722,24 @@ -(void)validateReceipt:(NSString *)receipt transaction:(SKPaymentTransaction*)tr else { [[SKPaymentQueue defaultQueue] finishTransaction:transaction]; + [_translateFromTabView selectTabViewItemAtIndex:paymentErrorIndex]; NSLog(@"Error: %@", error.localizedDescription); } }]; [task resume]; } +/* + * JSON confirmation just gives latest request ID. Put that in the project settings. + * TODO handle failure + */ -(void)parseJSONConfirmation:(NSData *)data{ NSError *JSONerror; NSDictionary* initialTransDict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&JSONerror]; if(JSONerror) { + [_translateFromTabView selectTabViewItemAtIndex:paymentErrorIndex]; NSLog(@"JSONError: %@", JSONerror.localizedDescription); return; } @@ -777,6 +747,10 @@ -(void)parseJSONConfirmation:(NSData *)data{ ((ProjectSettings*)[AppDelegate appDelegate].projectSettings).latestRequestID = _latestRequestID; } +/* + * 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; @@ -792,12 +766,49 @@ -(void)setLanguageWindowDownloading{ } } } - [_parentWindow setDownloadingTranslations:_numTransToDownload]; + ((ProjectSettings*)[AppDelegate appDelegate].projectSettings).numToDownload = _numTransToDownload; + [_parentWindow setDownloadingTranslations]; } + +#pragma mark Download Translations + /* - * 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 SpriteBuilder session. + * 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) + { + [self parseJSONTranslations:data]; + NSLog(@"Status code: %li", ((NSHTTPURLResponse *)response).statusCode); + } + else + { + NSAlert* alert = [NSAlert alertWithMessageText:@"Download Failed" defaultButton:@"Okay" alternateButton:NULL otherButton:NULL informativeTextWithFormat:@"Your download has failed due to an error on our servers. You will not be charged. Please try again in a few minutes."]; + NSInteger result = [alert runModal]; + if(result == NSAlertDefaultReturn) + { + [_parentWindow finishDownloadingTranslations]; + [self cancelDownloadWithError:[[NSError alloc] init]]; + } + NSLog(@"Error: %@", error.localizedDescription); + } + }]; + [task resume]; +} + +/* + * 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. + * TODO use actual text */ -(void)parseJSONTranslations:(NSData *)data{ NSError *JSONerror; @@ -805,33 +816,48 @@ -(void)parseJSONTranslations:(NSData *)data{ options:NSJSONReadingMutableContainers error:&JSONerror]; if(JSONerror) { + NSAlert* alert = [NSAlert alertWithMessageText:@"Download Failed" defaultButton:@"Okay" alternateButton:NULL otherButton:NULL informativeTextWithFormat:@"Your download has failed due to an error on our servers. You will not be charged. Please try again in a few minutes."]; + NSInteger result = [alert runModal]; + if(result == NSAlertDefaultReturn) + { + [_parentWindow finishDownloadingTranslations]; + [self cancelDownloadWithError:[[NSError alloc] init]]; + } NSLog(@"JSONError: %@", JSONerror.localizedDescription); return; } LocalizationEditorHandler* handler = [AppDelegate appDelegate].localizationEditorHandler; NSArray* handlerTranslations = handler.translations; NSArray* requests = [initialTransDict objectForKey:@"requests"]; - NSDictionary* request = [requests objectAtIndex:0]; - NSString* requestID = [request objectForKey:@"request_id"]; - if(![requestID isEqualToString:_latestRequestID]){ - NSLog(@"Something went wrong"); + NSDictionary* request = NULL; + for(NSDictionary* r in requests) + { + if([[r objectForKey:@"id"] isEqualToString:_latestRequestID]) + { + request = r; + } } NSArray* phrases = [request objectForKey:@"phrases"]; - for(NSDictionary* phrase in phrases){ + for(NSDictionary* phrase in phrases) + { NSString* text = [phrase objectForKey:@"text"]; NSString* context = [phrase objectForKey:@"context"]; NSString* sourceLangIso = [phrase objectForKey:@"source_language"]; - NSArray* translations = [phrase objectForKey:@"translations"]; - for(NSDictionary* translation in translations){ + 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:@"text"]; - if([translationStatus isEqualToString:@"completed"]){ + 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]; + if([sourceText isEqualToString:text] && [t.comment isEqualToString:context] && [t.languagesDownloading containsObject:translationIso]) + { + //[t.translations setObject:translationText forKey:translationIso]; + [t.translations setObject:@"Completed!" forKey:translationIso]; [t.languagesDownloading removeObject:translationIso]; [_parentWindow incrementTransByOne]; } @@ -839,67 +865,59 @@ -(void)parseJSONTranslations:(NSData *)data{ } } } - if([_parentWindow translationProgress] == _numTransToDownload){ + if([_parentWindow translationProgress] == _numTransToDownload) + { [self endDownload]; [_parentWindow finishDownloadingTranslations]; } } --(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) - { - [self parseJSONTranslations:data]; - NSLog(@"Status code: %li", ((NSHTTPURLResponse *)response).statusCode); - } - else - { - NSLog(@"Error: %@", error.localizedDescription); - } - }]; - [task resume]; - -} - +/* + * 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{ [_timerTransDownload invalidate]; _timerTransDownload = nil; } +/* + * Restarts the timer for the download function. + */ +-(void)restartDownload{ + _timerTransDownload = [NSTimer scheduledTimerWithTimeInterval:downloadRepeatInterval target:self selector:@selector(getTranslations) userInfo:nil repeats:YES]; +} + +/* + * Ends the download cleanly in the translation window. + */ - (void)endDownload{ - LocalizationEditorHandler* handler = [AppDelegate appDelegate].localizationEditorHandler; - NSArray* handlerTranslations = handler.translations; - for(LocalizationEditorTranslation* t in handlerTranslations) - { - if(t.languagesDownloading.count) - { - NSLog(@"Oops, language still downloading"); - t.languagesDownloading = NULL; - } - } + _numTransToDownload = 0; + _latestRequestID = nil; [_timerTransDownload invalidate]; _timerTransDownload = nil; } -- (void)stopDownload{ - LocalizationEditorHandler* handler = [AppDelegate appDelegate].localizationEditorHandler; - NSArray* handlerTranslations = handler.translations; - for(LocalizationEditorTranslation* t in handlerTranslations) - { - t.languagesDownloading = NULL; - } +#pragma mark Cancel Download + +/* + * Stops the download after a cancellation request has been sent. + */ +- (void)cancelDownloadWithError:(NSError*)error{ + _numTransToDownload = 0; + _latestRequestID = nil; [_timerTransDownload invalidate]; _timerTransDownload = nil; - [self sendCancelRequest]; + if(!error){ + [self sendCancelRequest]; + } } +/* + * Sends cancel request to the server + * TODO actually make this do something + */ -(void)sendCancelRequest{ NSDictionary *JSONObject = [[NSDictionary alloc] initWithObjectsAndKeys: _guid,@"key",nil]; NSError *error; @@ -931,7 +949,63 @@ -(void)sendCancelRequest{ } --(void)restartDownload{ - _timerTransDownload = [NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(getTranslations) userInfo:nil repeats:YES]; + +#pragma mark Misc. helper funcs + +/* + * 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)disableAll{ + [_popTranslateFrom setEnabled:0]; + [_languageTable setEnabled:0]; + [_checkAll setEnabled:0]; + [_ignoreText setEnabled:0]; +} + +/* + * 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)enableAll{ + dispatch_async(dispatch_get_main_queue(), ^{ + [_popTranslateFrom setEnabled:1]; + [_languageTable setEnabled:1]; + [_checkAll setEnabled:1]; + [_ignoreText setEnabled:1]; + }); +} + +/* + * Locally format the price of the current translation estimate, display it, + * and hide the cost downloading message and spinning icon. + */ +-(void)displayPrice{ + SKProduct* p = [_products objectAtIndex:(_tierForTranslations - 1)]; + NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init]; + [numberFormatter setNumberStyle:NSNumberFormatterCurrencyStyle]; + [numberFormatter setLocale:p.priceLocale]; + NSString *formattedString = [numberFormatter stringFromNumber:p.price]; + _cost.stringValue = formattedString; + [_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 index 918df5536..b089da26a 100644 --- a/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.xib +++ b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.xib @@ -22,6 +22,7 @@ + @@ -248,7 +249,7 @@ Gw - + @@ -281,7 +282,7 @@ Gw - + @@ -290,7 +291,7 @@ Gw - + @@ -299,7 +300,7 @@ Gw - + @@ -380,5 +381,20 @@ Gw + + + + + + + + + + + + + + + From 97381332f79baa0eb24beeca723f8cf7771e7d5f Mon Sep 17 00:00:00 2001 From: Benjamin Koatz Date: Mon, 7 Jul 2014 10:35:58 -0700 Subject: [PATCH 21/39] Error handling for payment errors, fixed small bugs with project settings and some weird stuff about windows and alerts --- .../ccBuilder/LocalizationEditorTranslation.h | 2 +- .../ccBuilder/LocalizationEditorTranslation.m | 4 +- .../ccBuilder/LocalizationEditorWindow.m | 5 +- .../ccBuilder/LocalizationTranslateWindow.h | 1 + .../ccBuilder/LocalizationTranslateWindow.m | 99 ++++++++++++------- .../ccBuilder/LocalizationTranslateWindow.xib | 7 +- 6 files changed, 75 insertions(+), 43 deletions(-) diff --git a/SpriteBuilder/ccBuilder/LocalizationEditorTranslation.h b/SpriteBuilder/ccBuilder/LocalizationEditorTranslation.h index 5049760af..9590aae41 100644 --- a/SpriteBuilder/ccBuilder/LocalizationEditorTranslation.h +++ b/SpriteBuilder/ccBuilder/LocalizationEditorTranslation.h @@ -18,7 +18,7 @@ @property (nonatomic,copy) NSString* key; @property (nonatomic,copy) NSString* comment; -@property (nonatomic,copy) NSMutableArray* languagesDownloading; +@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 5c633e83c..6ab960dbc 100644 --- a/SpriteBuilder/ccBuilder/LocalizationEditorTranslation.m +++ b/SpriteBuilder/ccBuilder/LocalizationEditorTranslation.m @@ -33,7 +33,7 @@ - (id) initWithSerialization:(id)ser self.key = [dict objectForKey:@"key"]; self.comment = [dict objectForKey:@"comment"]; _translations = [[dict objectForKey:@"translations"] mutableCopy]; - _languagesDownloading = [[dict objectForKey:@"languagesDownloading"] 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"]; + if (self.languagesDownloading) [ser setObject:self.languagesDownloading forKey:@"languagesDownloading"]; return ser; } diff --git a/SpriteBuilder/ccBuilder/LocalizationEditorWindow.m b/SpriteBuilder/ccBuilder/LocalizationEditorWindow.m index 10aeb5dea..a99f08c4a 100644 --- a/SpriteBuilder/ccBuilder/LocalizationEditorWindow.m +++ b/SpriteBuilder/ccBuilder/LocalizationEditorWindow.m @@ -311,7 +311,10 @@ - (double)translationProgress{ * progress information. */ -(void)finishDownloadingTranslations{ - ((ProjectSettings*)[AppDelegate appDelegate].projectSettings).isDownloadingTranslations=0; + ProjectSettings* ps = [AppDelegate appDelegate].projectSettings; + ps.isDownloadingTranslations = 0; + ps.numDownloaded = 0; + ps.numToDownload = 0; [_translationProgress setHidden:1]; [_translationProgressText setHidden:1]; [tableTranslations setEnabled:1]; diff --git a/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.h b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.h index dcc56386d..2457d8fde 100644 --- a/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.h +++ b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.h @@ -74,4 +74,5 @@ @property (nonatomic,strong) LocalizationEditorWindow* parentWindow; @property (nonatomic,strong) NSString* guid; @property (nonatomic,strong) NSMutableDictionary* languages; +@property (nonatomic,strong) NSMutableDictionary* receipts; @end \ No newline at end of file diff --git a/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.m b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.m index 0403b8774..1d10112e8 100644 --- a/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.m +++ b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.m @@ -18,6 +18,7 @@ @implementation LocalizationTranslateWindow @synthesize parentWindow = _parentWindow; @synthesize guid = _guid; @synthesize languages = _languages; +@synthesize receipts = _receipts; //Standards for the tab view static int downloadLangsIndex = 0; @@ -41,6 +42,7 @@ @implementation LocalizationTranslateWindow static NSString* noActiveLangsErrorString = @"We support translations from:\r\r%@."; //Download time +//TODO use realistic interval //static double downloadRepeatInterval = 300; static double downloadRepeatInterval = 5; @@ -90,6 +92,7 @@ -(void)setUpURLsAndGlobals{ self.guid = [[[NSUserDefaults standardUserDefaults] dictionaryRepresentation] objectForKey:@"sbUserID"]; self.languages = [[NSMutableDictionary alloc] init]; + self.receipts = [[NSMutableDictionary alloc] init]; } #pragma mark Downloading and Updating Languages @@ -268,7 +271,7 @@ - (void) updateLanguageSelectionMenu:(int)userSelection * localized price. */ -(void)getCostEstimate{ - + [_translateFromTabView selectTabViewItemAtIndex:standardLangsIndex]; NSInteger phrases = [self updatePhrasesToTranslate]; if(phrases == 0) { @@ -276,7 +279,6 @@ -(void)getCostEstimate{ [_buy setEnabled:0]; return; } - [_translateFromTabView selectTabViewItemAtIndex:standardLangsIndex]; [_costDownloading setHidden:0]; [_costDownloadingText setHidden:0]; [_costDownloading startAnimation:self]; @@ -443,16 +445,13 @@ -(void)requestIAPProducts{ * Solicit a payment and set the cancel button to say 'Finish'. */ - (IBAction)buy:(id)sender { - if(!_products.count || !_phrasesToTranslate.count) - { - NSLog(@"Shouldn't have been able to click buy!!"); - return; - } - for(int i = 0; i < 20; i++) [[SKPaymentQueue defaultQueue] removeTransactionObserver:self]; [[SKPaymentQueue defaultQueue] addTransactionObserver:self]; SKPayment* payment = [SKPayment paymentWithProduct:[_products objectAtIndex:(_tierForTranslations -1)]]; [[SKPaymentQueue defaultQueue] addPayment:payment]; + [self disableAll]; + [_buy setEnabled:0]; + [_cancel setEnabled:0]; } /* @@ -656,12 +655,16 @@ -(void) productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProdu * validate the receipt with the server. */ -(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions{ + for (SKPaymentTransaction* transaction in transactions) { switch(transaction.transactionState) { case SKPaymentTransactionStateFailed: { + [self enableAll]; + [_buy setEnabled:1]; + [_cancel setEnabled:1]; NSLog(@"Failed"); [[SKPaymentQueue defaultQueue] finishTransaction:transaction]; [_translateFromTabView selectTabViewItemAtIndex:paymentErrorIndex]; @@ -669,12 +672,15 @@ -(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)trans } case SKPaymentTransactionStatePurchased: { + [self enableAll]; + [_buy setEnabled:1]; + [_cancel setEnabled:1]; NSLog(@"Purchased"); + [[SKPaymentQueue defaultQueue] finishTransaction:transaction]; NSURL* receiptURL = [[NSBundle mainBundle] appStoreReceiptURL]; NSData* receipt = [NSData dataWithContentsOfURL:receiptURL]; [_receipts setObject:receipt forKey:transaction.transactionIdentifier]; [self validateReceipt:[receipt base64EncodedStringWithOptions:0] transaction:transaction]; - [[SKPaymentQueue defaultQueue] finishTransaction:transaction]; break; } } @@ -694,6 +700,7 @@ -(void)validateReceipt:(NSString *)receipt transaction:(SKPaymentTransaction*)tr if(![NSJSONSerialization isValidJSONObject:JSONObject]) { NSLog(@"Invalid JSON"); + [_translateFromTabView selectTabViewItemAtIndex:paymentErrorIndex]; return; } NSData *postdata2 = [NSJSONSerialization dataWithJSONObject:JSONObject options:0 error:&error]; @@ -760,7 +767,7 @@ -(void)setLanguageWindowDownloading{ { if([t.key isEqualToString:[d objectForKey:@"key"]]) { - t.languagesDownloading = [d objectForKey:@"target_languages"]; + t.languagesDownloading = [NSMutableArray arrayWithArray:[d objectForKey:@"target_languages"]]; [_parentWindow addLanguages:[d objectForKey:@"target_languages"]]; break; } @@ -790,13 +797,15 @@ -(void)getTranslations{ } else { - NSAlert* alert = [NSAlert alertWithMessageText:@"Download Failed" defaultButton:@"Okay" alternateButton:NULL otherButton:NULL informativeTextWithFormat:@"Your download has failed due to an error on our servers. You will not be charged. Please try again in a few minutes."]; - NSInteger result = [alert runModal]; - if(result == NSAlertDefaultReturn) - { - [_parentWindow finishDownloadingTranslations]; - [self cancelDownloadWithError:[[NSError alloc] init]]; - } + dispatch_async(dispatch_get_main_queue(), ^{ + NSAlert* alert = [NSAlert alertWithMessageText:@"Download Failed" defaultButton:@"Okay" alternateButton:NULL otherButton:NULL informativeTextWithFormat:@"Your download has failed due to an error on our servers. You will not be charged. Please try again in a few minutes."]; + NSInteger result = [alert runModal]; + if(result == NSAlertDefaultReturn) + { + [_parentWindow finishDownloadingTranslations]; + [self cancelDownloadWithError:[[NSError alloc] init]]; + } + }); NSLog(@"Error: %@", error.localizedDescription); } }]; @@ -816,13 +825,15 @@ -(void)parseJSONTranslations:(NSData *)data{ options:NSJSONReadingMutableContainers error:&JSONerror]; if(JSONerror) { - NSAlert* alert = [NSAlert alertWithMessageText:@"Download Failed" defaultButton:@"Okay" alternateButton:NULL otherButton:NULL informativeTextWithFormat:@"Your download has failed due to an error on our servers. You will not be charged. Please try again in a few minutes."]; - NSInteger result = [alert runModal]; - if(result == NSAlertDefaultReturn) - { - [_parentWindow finishDownloadingTranslations]; - [self cancelDownloadWithError:[[NSError alloc] init]]; - } + dispatch_async(dispatch_get_main_queue(), ^{ + NSAlert* alert = [NSAlert alertWithMessageText:@"Download Failed" defaultButton:@"Okay" alternateButton:NULL otherButton:NULL informativeTextWithFormat:@"Your download has failed due to an error on our servers. You will not be charged. Please try again in a few minutes."]; + NSInteger result = [alert runModal]; + if(result == NSAlertDefaultReturn) + { + [_parentWindow finishDownloadingTranslations]; + [self cancelDownloadWithError:[[NSError alloc] init]]; + } + }); NSLog(@"JSONError: %@", JSONerror.localizedDescription); return; } @@ -835,6 +846,7 @@ -(void)parseJSONTranslations:(NSData *)data{ if([[r objectForKey:@"id"] isEqualToString:_latestRequestID]) { request = r; + break; } } NSArray* phrases = [request objectForKey:@"phrases"]; @@ -848,7 +860,7 @@ -(void)parseJSONTranslations:(NSData *)data{ { NSString* translationIso = [translation objectForKey:@"target_language"]; NSString* translationStatus = [translation objectForKey:@"status"]; - NSString* translationText = [translation objectForKey:@"text"]; + NSString* translationText = [translation objectForKey:@"translated_text"]; if([translationStatus isEqualToString:@"received"]) { for(LocalizationEditorTranslation* t in handlerTranslations) @@ -856,8 +868,7 @@ -(void)parseJSONTranslations:(NSData *)data{ 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.translations setObject:@"Completed!" forKey:translationIso]; + [t.translations setObject:translationText forKey:translationIso]; [t.languagesDownloading removeObject:translationIso]; [_parentWindow incrementTransByOne]; } @@ -868,7 +879,9 @@ -(void)parseJSONTranslations:(NSData *)data{ if([_parentWindow translationProgress] == _numTransToDownload) { [self endDownload]; - [_parentWindow finishDownloadingTranslations]; + dispatch_async(dispatch_get_main_queue(), ^{ + [_parentWindow finishDownloadingTranslations]; + }); } } @@ -903,29 +916,39 @@ - (void)endDownload{ /* * Stops the download after a cancellation request has been sent. + * TODO handle the error */ - (void)cancelDownloadWithError:(NSError*)error{ _numTransToDownload = 0; _latestRequestID = nil; [_timerTransDownload invalidate]; _timerTransDownload = nil; - if(!error){ - [self sendCancelRequest]; - } + [self sendCancelRequestWithError:error]; } /* - * Sends cancel request to the server - * TODO actually make this do something + * Sends cancel request to the server with an error if there was one + * TODO actually make this do something and handle errors */ --(void)sendCancelRequest{ - NSDictionary *JSONObject = [[NSDictionary alloc] initWithObjectsAndKeys: _guid,@"key",nil]; - NSError *error; - if(![NSJSONSerialization isValidJSONObject:JSONObject]){ +-(void)sendCancelRequestWithError:(NSError*)error{ + NSDictionary *JSONObject; + if(error) + { + JSONObject = [[NSDictionary alloc] initWithObjectsAndKeys: _guid,@"key", + _latestRequestID,@"id",error,@"error",nil]; + } + else + { + JSONObject = [[NSDictionary alloc] initWithObjectsAndKeys: _guid,@"key", + _latestRequestID,@"id",nil]; + } + NSError *JSONError; + if(![NSJSONSerialization isValidJSONObject:JSONObject]) + { NSLog(@"Invalid JSON"); return; } - NSData *postdata2 = [NSJSONSerialization dataWithJSONObject:JSONObject options:0 error:&error]; + NSData *postdata2 = [NSJSONSerialization dataWithJSONObject:JSONObject options:0 error:&JSONError]; NSURL *url = [NSURL URLWithString:cancelURL]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; request.HTTPMethod = @"POST"; diff --git a/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.xib b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.xib index b089da26a..ee2980210 100644 --- a/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.xib +++ b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.xib @@ -209,6 +209,11 @@ Gw + + + + + @@ -249,7 +254,7 @@ Gw - - - - - - @@ -305,7 +296,7 @@ Gw - + @@ -327,13 +318,13 @@ Gw - + - + - + @@ -348,7 +339,7 @@ Gw - + @@ -374,7 +365,7 @@ Gw - + @@ -400,7 +391,7 @@ Gw - + @@ -413,13 +404,13 @@ Gw - + - + - + From 5d076a287d1a99941ed965b7d2a25dcc6a085867 Mon Sep 17 00:00:00 2001 From: Benjamin Koatz Date: Thu, 14 Aug 2014 14:19:46 -0700 Subject: [PATCH 33/39] A bunch of stylistic and comment changes in preparation for pull request --- SpriteBuilder/ccBuilder/AppDelegate.m | 21 ++++++++++------- .../ccBuilder/LocalizationEditorHandler.m | 15 +++++++++++- .../ccBuilder/LocalizationEditorWindow.m | 11 +++++---- .../LocalizationTransactionObserver.m | 3 +++ .../ccBuilder/LocalizationTranslateWindow.m | 13 ++++------- .../LocalizationTranslateWindowHandler.h | 2 +- .../LocalizationTranslateWindowHandler.m | 6 ++++- SpriteBuilder/ccBuilder/TranslationSettings.m | 23 ++++++++++++++++++- 8 files changed, 69 insertions(+), 25 deletions(-) diff --git a/SpriteBuilder/ccBuilder/AppDelegate.m b/SpriteBuilder/ccBuilder/AppDelegate.m index ac42a72b6..02265e47d 100644 --- a/SpriteBuilder/ccBuilder/AppDelegate.m +++ b/SpriteBuilder/ccBuilder/AppDelegate.m @@ -2043,16 +2043,16 @@ - (BOOL) openProject:(NSString*) fileName self.window.representedFilename = [fileName stringByDeletingLastPathComponent]; - if(project.isDownloadingTranslations) + if(prjctSettings.isDownloadingTranslations) { TranslationSettings *translationSettings = [TranslationSettings translationSettings]; NSMutableArray *projectsDownloadingTranslations = translationSettings.projectsDownloadingTranslations; - if(![projectsDownloadingTranslations containsObject:project.projectPath]) + if(![projectsDownloadingTranslations containsObject:prjctSettings.projectPath]) { - [projectsDownloadingTranslations addObject:project.projectPath]; + [projectsDownloadingTranslations addObject:prjctSettings.projectPath]; [translationSettings writeTranslationSettings]; } - [localizationEditorHandler restartTranslationDownload:project]; + [localizationEditorHandler restartTranslationDownload:prjctSettings]; } return YES; } @@ -4705,6 +4705,9 @@ - (NSString*)getPathOfMenuItem:(NSMenuItem*)item return fullpath; } +/* + * Restarts project downloads + */ - (void)restartProjectDownloads { TranslationSettings* translationSettings = [TranslationSettings translationSettings]; @@ -4743,22 +4746,24 @@ - (void)restartProjectDownloads } else { - NSLog(@"No language file!"); + NSLog(@"No language file! Project Path: %@", ps.projectPath); } } else { - NSLog(@"Shouldn't have gotten here!"); + NSLog(@"Restarting a download in a project that isn't currently downloading translations! Project Path: %@", ps.projectPath); } } else { - NSLog(@"Project not at path"); + 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 { - NSLog(@"Project not at path"); + 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]; } } } diff --git a/SpriteBuilder/ccBuilder/LocalizationEditorHandler.m b/SpriteBuilder/ccBuilder/LocalizationEditorHandler.m index 185972bbf..bf2855eeb 100644 --- a/SpriteBuilder/ccBuilder/LocalizationEditorHandler.m +++ b/SpriteBuilder/ccBuilder/LocalizationEditorHandler.m @@ -156,6 +156,11 @@ - (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]; @@ -192,6 +197,11 @@ - (void) setManagedFileForBackgroundTranslationDownload:(NSString*) file } } +/* + * 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; @@ -359,7 +369,7 @@ - (IBAction)openEditor:(id)sender [windowController.window makeKeyAndOrderFront:sender]; windowController.hasOpenFile = (managedFile != NULL); if(((ProjectSettings*)[AppDelegate appDelegate].projectSettings).isDownloadingTranslations) - { + { [windowController setDownloadingTranslations]; } else @@ -425,6 +435,9 @@ - (void) createOrEditTranslationForKey:(NSString*)key } } +/* + * Restart translation download + */ - (void)restartTranslationDownload:(ProjectSettings *)ps{ if (!windowController) { diff --git a/SpriteBuilder/ccBuilder/LocalizationEditorWindow.m b/SpriteBuilder/ccBuilder/LocalizationEditorWindow.m index 74b1a887b..392a66d3e 100644 --- a/SpriteBuilder/ccBuilder/LocalizationEditorWindow.m +++ b/SpriteBuilder/ccBuilder/LocalizationEditorWindow.m @@ -227,7 +227,8 @@ - (IBAction)selectedAddLanguage:(id)sender } /* - * If you are opening a new window and one doesn't exist, open it and make it modal. + * 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. */ @@ -596,10 +597,6 @@ - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColu return NULL; } -/* - * If a translation is updated, update the tableView in the translation window if there - * is one open. - */ - (void) tableView:(NSTableView *)tableView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row { LocalizationEditorHandler* handler = [AppDelegate appDelegate].localizationEditorHandler; @@ -823,6 +820,10 @@ -(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NS } +#pragma mark Restart Translation Download +/* + * Restarts Translation Download + */ - (void)restartTranslationDownload:(ProjectSettings *)ps{ _ltw = [[LocalizationTranslateWindow alloc] initWithDownload:ps parentWindow:self]; [_ltw restartDownload]; diff --git a/SpriteBuilder/ccBuilder/LocalizationTransactionObserver.m b/SpriteBuilder/ccBuilder/LocalizationTransactionObserver.m index e2b957cb2..536a959f2 100644 --- a/SpriteBuilder/ccBuilder/LocalizationTransactionObserver.m +++ b/SpriteBuilder/ccBuilder/LocalizationTransactionObserver.m @@ -12,6 +12,9 @@ @implementation LocalizationTransactionObserver @synthesize ltw = _ltw; +/* + * Observes and handles responses from the paymentQueue + */ - (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions{ for (SKPaymentTransaction* transaction in transactions) diff --git a/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.m b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.m index fa955c945..cc0ad5cad 100644 --- a/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.m +++ b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.m @@ -290,7 +290,7 @@ - (void) updateLanguageSelectionMenu:(int)userSelection } /* - * Called when window reopened, just incase things were changed on the editor window + * Called when window reopened, just in case things were changed on the editor window */ -(void)refresh{ [self updateActiveLanguages]; @@ -484,7 +484,7 @@ -(void)requestIAPProducts{ #pragma mark Toggling/Clicking Button Events /* - * Solicit a payment and set the cancel button to say 'Finish'. + * Solicit a payment after showing a warning about long download times. */ - (IBAction)buy:(id)sender { NSInteger continueDownload; @@ -1008,9 +1008,7 @@ -(void)restartDownload{ dispatch_async(dispatch_get_main_queue(), ^{ if(_timerTransDownload) { - - [_timerTransDownload invalidate]; - + [_timerTransDownload invalidate]; } [self getTranslations]; _timerTransDownload = [NSTimer scheduledTimerWithTimeInterval:downloadRepeatInterval target:self selector:@selector(getTranslations) userInfo:nil repeats:YES]; @@ -1082,8 +1080,7 @@ - (void)cancelDownloadWithError:(NSError*)error{ } /* - * Sends cancel request to the server with an error if there was one - * TODO actually make this do something and handle errors + * Sends cancel notification to the server with an error if there was one */ -(void)sendCancelNotificationWithError:(NSError*)error{ NSDictionary *JSONObject; @@ -1137,7 +1134,7 @@ -(void)setPaymentError{ #pragma mark Misc. helper funcs -(void)cannotFindProjectAlert:(NSString*)projectPath{ - 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]; + 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]; } /* diff --git a/SpriteBuilder/ccBuilder/LocalizationTranslateWindowHandler.h b/SpriteBuilder/ccBuilder/LocalizationTranslateWindowHandler.h index a375da938..469c2bbce 100644 --- a/SpriteBuilder/ccBuilder/LocalizationTranslateWindowHandler.h +++ b/SpriteBuilder/ccBuilder/LocalizationTranslateWindowHandler.h @@ -1,5 +1,5 @@ // -// LocalizationTranslateWindowView.h +// LocalizationTranslateWindowHandler.h // SpriteBuilder // // Created by Benjamin Koatz on 6/23/14. diff --git a/SpriteBuilder/ccBuilder/LocalizationTranslateWindowHandler.m b/SpriteBuilder/ccBuilder/LocalizationTranslateWindowHandler.m index 3dcb2c3a2..f7069e784 100644 --- a/SpriteBuilder/ccBuilder/LocalizationTranslateWindowHandler.m +++ b/SpriteBuilder/ccBuilder/LocalizationTranslateWindowHandler.m @@ -1,5 +1,5 @@ // -// LocalizationTranslateWindowView.m +// LocalizationTranslateWindowHandler.m // SpriteBuilder // // Created by Benjamin Koatz on 6/23/14. @@ -11,6 +11,10 @@ @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]; diff --git a/SpriteBuilder/ccBuilder/TranslationSettings.m b/SpriteBuilder/ccBuilder/TranslationSettings.m index 3ba6cd78f..bc0cf2b46 100644 --- a/SpriteBuilder/ccBuilder/TranslationSettings.m +++ b/SpriteBuilder/ccBuilder/TranslationSettings.m @@ -17,6 +17,9 @@ @implementation TranslationSettings static TranslationSettings *singleton; +/* + * Creates singleton translation settings + */ + (TranslationSettings*) translationSettings { @synchronized([TranslationSettings class]) @@ -31,7 +34,9 @@ + (TranslationSettings*) translationSettings return nil; } - +/* + * Initializes, loads and then writes the translation settings + */ - (id)init { self = [super init]; @@ -50,11 +55,18 @@ - (id)init } +/* + * Writes and loads translation settings + */ - (void)updateTranslationSettings { [self writeTranslationSettings]; [self loadTranslationSettings]; } + +/* + * Loads translation settings + */ - (void)loadTranslationSettings { self.projectsDownloadingTranslations = [[[NSUserDefaults standardUserDefaults] objectForKey:@"projectsDownloadingTranslations"] mutableCopy]; @@ -66,11 +78,17 @@ - (void)loadTranslationSettings } } +/* + * 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) @@ -81,6 +99,9 @@ -(void)addObserver:(NSObject *)observer forKeyPath:(NSString *)keyPath options:( self.observer = observer; } +/* + * Removes an observer for a keyPath + */ -(void)removeObserver:(NSObject *)observer forKeyPath:(NSString *)keyPath{ [super removeObserver:observer forKeyPath:keyPath]; From 63638fbbcb40daa21ecd5d0f4fc28c672734a3c0 Mon Sep 17 00:00:00 2001 From: Benjamin Koatz Date: Thu, 14 Aug 2014 14:20:03 -0700 Subject: [PATCH 34/39] Added all 85 sprite builder translation tiers --- .../LocalizationInAppPurchasesPIDs.plist | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/SpriteBuilder/Resources/LocalizationInAppPurchasesPIDs.plist b/SpriteBuilder/Resources/LocalizationInAppPurchasesPIDs.plist index 65fd71937..073e9b529 100644 --- a/SpriteBuilder/Resources/LocalizationInAppPurchasesPIDs.plist +++ b/SpriteBuilder/Resources/LocalizationInAppPurchasesPIDs.plist @@ -12,5 +12,80 @@ 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 From de05d39c178f38596175d4bd3aaea1fb37efa280 Mon Sep 17 00:00:00 2001 From: Benjamin Koatz Date: Thu, 14 Aug 2014 16:34:47 -0700 Subject: [PATCH 35/39] Add pragma mark to app delegate for restarting project translation downloads --- SpriteBuilder/ccBuilder/AppDelegate.m | 1 + 1 file changed, 1 insertion(+) diff --git a/SpriteBuilder/ccBuilder/AppDelegate.m b/SpriteBuilder/ccBuilder/AppDelegate.m index a2f70dfd9..34215bc48 100644 --- a/SpriteBuilder/ccBuilder/AppDelegate.m +++ b/SpriteBuilder/ccBuilder/AppDelegate.m @@ -4696,6 +4696,7 @@ - (NSString*)getPathOfMenuItem:(NSMenuItem*)item return fullpath; } +#pragma mark restart project translation downloads /* * Restarts project downloads */ From f2fdc4230f9aaac200547aee60f638d8d1b030db Mon Sep 17 00:00:00 2001 From: Benjamin Koatz Date: Thu, 14 Aug 2014 16:36:16 -0700 Subject: [PATCH 36/39] Add ifdefs to handle the appropriate behavior for sprite builder v sprite builder pro Makes it so the buy translations button disappears on sprite builder pro, and translation downloads aren't attempted to be updated in the app delegate --- SpriteBuilder/ccBuilder/AppDelegate.m | 7 ++++--- SpriteBuilder/ccBuilder/LocalizationEditorWindow.m | 4 ++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/SpriteBuilder/ccBuilder/AppDelegate.m b/SpriteBuilder/ccBuilder/AppDelegate.m index 34215bc48..b8971452d 100644 --- a/SpriteBuilder/ccBuilder/AppDelegate.m +++ b/SpriteBuilder/ccBuilder/AppDelegate.m @@ -643,9 +643,9 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification //Transaction Observer for Translation Downloads lto = [[LocalizationTransactionObserver alloc] init]; [[SKPaymentQueue defaultQueue] addTransactionObserver:lto]; - + #ifndef SPRITEBUILDER_PRO [self restartProjectDownloads]; - + #endif if (delayOpenFiles) { [self openFiles:delayOpenFiles]; @@ -2035,7 +2035,7 @@ - (BOOL) openProject:(NSString*) fileName [cocos2dUpdater updateAndBypassIgnore:NO]; self.window.representedFilename = [fileName stringByDeletingLastPathComponent]; - + #ifndef SPRITEBUILDER_PRO if(prjctSettings.isDownloadingTranslations) { TranslationSettings *translationSettings = [TranslationSettings translationSettings]; @@ -2047,6 +2047,7 @@ - (BOOL) openProject:(NSString*) fileName } [localizationEditorHandler restartTranslationDownload:prjctSettings]; } + #endif return YES; } diff --git a/SpriteBuilder/ccBuilder/LocalizationEditorWindow.m b/SpriteBuilder/ccBuilder/LocalizationEditorWindow.m index 392a66d3e..4b1c870d6 100644 --- a/SpriteBuilder/ccBuilder/LocalizationEditorWindow.m +++ b/SpriteBuilder/ccBuilder/LocalizationEditorWindow.m @@ -24,6 +24,10 @@ @implementation LocalizationEditorWindow - (void) awakeFromNib { + #ifdef SPRITEBUILDER_PRO + [_translationsButton setHidden:YES]; + [_addTranslation setFrame:_translationsButton.frame]; + #endif [tableTranslations registerForDraggedTypes:[NSArray arrayWithObject:@"com.cocosbuilder.LocalizationEditorTranslation"]]; [self populateLanguageAddMenu]; [tableLanguages reloadData]; From b43ac934cfdbd2990c073410c2c8bbcb4fb571ed Mon Sep 17 00:00:00 2001 From: Benjamin Koatz Date: Thu, 14 Aug 2014 16:38:29 -0700 Subject: [PATCH 37/39] Change properties from strong to copy and weak where needed NSStrings became copies and parent-child references that would've resulted in retain cycles were fixed --- SpriteBuilder/ccBuilder/LocalizationTranslateWindow.h | 8 ++++---- SpriteBuilder/ccBuilder/ProjectSettings.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.h b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.h index d96d23fef..e3411e52a 100644 --- a/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.h +++ b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.h @@ -65,7 +65,7 @@ NSString* _latestRequestID; //Interaction with EditorWindow - LocalizationEditorWindow* _parentWindow; + LocalizationEditorWindow* __weak _parentWindow; NSAlert* _buyAlert; NSString* _projectPathDir; NSString* _projectPath; @@ -101,11 +101,11 @@ @property (nonatomic,strong) NSMutableArray* phrasesToTranslate; @property (nonatomic,readwrite) NSInteger tierForTranslations; @property (nonatomic,strong) SKProduct* product; -@property (nonatomic,strong) NSString* guid; +@property (nonatomic,copy) NSString* guid; @property (nonatomic,strong) NSMutableDictionary* receipts; -@property (nonatomic,strong) NSString* latestRequestID; +@property (nonatomic,copy) NSString* latestRequestID; -@property (nonatomic,strong) LocalizationEditorWindow* parentWindow; +@property (nonatomic,weak) LocalizationEditorWindow* parentWindow; @property (nonatomic,strong) NSAlert* buyAlert; @property (nonatomic,strong) NSString* projectPathDir; @property (nonatomic,strong) NSString* projectPath; diff --git a/SpriteBuilder/ccBuilder/ProjectSettings.h b/SpriteBuilder/ccBuilder/ProjectSettings.h index 63d76dd2b..df087090f 100644 --- a/SpriteBuilder/ccBuilder/ProjectSettings.h +++ b/SpriteBuilder/ccBuilder/ProjectSettings.h @@ -148,7 +148,7 @@ typedef NS_ENUM(int8_t, CCBTargetEngine) @property (nonatomic,assign) BOOL isDownloadingTranslations; @property (nonatomic,readwrite) double numToDownload; @property (nonatomic,assign) double numDownloaded; -@property (nonatomic,strong) NSString* latestRequestID; +@property (nonatomic,copy) NSString* latestRequestID; // Temporary property, do not persist @property (nonatomic) BOOL canUpdateCocos2D; From de1eacb575f8b22eda5a3c43461ebf7ca4dadf03 Mon Sep 17 00:00:00 2001 From: Benjamin Koatz Date: Fri, 15 Aug 2014 14:43:34 -0700 Subject: [PATCH 38/39] Deal with localization editor window state for closed v open projects in both Spritebuilder Pro and regular Spritebuilder Revolves around hasOpenFile and uses the fact whether project settings is null or not. --- .../ccBuilder/LocalizationEditorHandler.m | 8 --- .../ccBuilder/LocalizationEditorWindow.m | 49 ++++++++++++++++++- 2 files changed, 48 insertions(+), 9 deletions(-) diff --git a/SpriteBuilder/ccBuilder/LocalizationEditorHandler.m b/SpriteBuilder/ccBuilder/LocalizationEditorHandler.m index bf2855eeb..d4a4e1c20 100644 --- a/SpriteBuilder/ccBuilder/LocalizationEditorHandler.m +++ b/SpriteBuilder/ccBuilder/LocalizationEditorHandler.m @@ -368,14 +368,6 @@ - (IBAction)openEditor:(id)sender } [windowController.window makeKeyAndOrderFront:sender]; windowController.hasOpenFile = (managedFile != NULL); - if(((ProjectSettings*)[AppDelegate appDelegate].projectSettings).isDownloadingTranslations) - { - [windowController setDownloadingTranslations]; - } - else - { - [windowController finishDownloadingTranslations]; - } } - (NSString*) translationForKey:(NSString*)key diff --git a/SpriteBuilder/ccBuilder/LocalizationEditorWindow.m b/SpriteBuilder/ccBuilder/LocalizationEditorWindow.m index 4b1c870d6..82643180f 100644 --- a/SpriteBuilder/ccBuilder/LocalizationEditorWindow.m +++ b/SpriteBuilder/ccBuilder/LocalizationEditorWindow.m @@ -315,6 +315,7 @@ -(void)setDownloadingTranslations{ [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]]; } @@ -347,10 +348,41 @@ -(void)finishDownloadingTranslations{ [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; @@ -810,8 +842,22 @@ - (CGFloat) splitView:(NSSplitView *)splitView constrainMaxCoordinate:(CGFloat)p */ -(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.isDownloadingTranslations) + 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]; @@ -821,6 +867,7 @@ -(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NS _ltw = nil; } } + #endif } From 726726efee86ae2109f3d141796f6c7a4ed57985 Mon Sep 17 00:00:00 2001 From: Benjamin Koatz Date: Fri, 15 Aug 2014 14:46:56 -0700 Subject: [PATCH 39/39] Updates process for parsing translations into background translation request, now using resourcePaths --- .../ccBuilder/LocalizationTranslateWindow.m | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.m b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.m index cc0ad5cad..1623969eb 100644 --- a/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.m +++ b/SpriteBuilder/ccBuilder/LocalizationTranslateWindow.m @@ -883,15 +883,7 @@ -(int)parseJSONTranslations:(NSData *)data{ } else { - handler = [[LocalizationEditorHandler alloc] init]; - NSString* langFile = [[_projectPathDir stringByAppendingPathComponent:@"SpriteBuilder Resources"] stringByAppendingPathComponent:@"Strings.ccbLang"]; - if(!langFile) - { - [self cannotFindProjectAlert:_projectPath]; - [self pauseDownload]; - return -1; - } - [handler setManagedFileForBackgroundTranslationDownload:langFile]; + NSMutableDictionary* projectDict = [NSMutableDictionary dictionaryWithContentsOfFile:_projectPath]; if(!projectDict) { @@ -908,6 +900,23 @@ -(int)parseJSONTranslations:(NSData *)data{ } 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"];