Skip to content

Commit

Permalink
CATTY-377 Add new object choose image before title
Browse files Browse the repository at this point in the history
  • Loading branch information
amelak9 committed Jul 26, 2021
1 parent dce344b commit 72e3528
Showing 1 changed file with 45 additions and 37 deletions.
82 changes: 45 additions & 37 deletions src/Catty/ViewController/Continue&New/SceneTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -90,41 +90,9 @@ - (void)addObjectAction:(id)sender
{
[self.tableView setEditing:false animated:YES];

[[[[[[[AlertControllerBuilder textFieldAlertWithTitle:kLocalizedAddObject message:[NSString stringWithFormat:@"%@:", kLocalizedObjectName]]
placeholder:kLocalizedEnterYourObjectNameHere]
addCancelActionWithTitle:kLocalizedCancel handler:^{
[self cancelAddingObjectFromScriptEditor];
}]
addDefaultActionWithTitle:kLocalizedOK handler:^(NSString *name) {
[self addObjectActionWithName:name];
}]
valueValidator:^InputValidationResult *(NSString *name) {
InputValidationResult *result = [Util validationResultWithName:name
minLength:kMinNumOfObjectNameCharacters
maxlength:kMaxNumOfObjectNameCharacters];
if (!result.valid) {
return result;
}
// Alert for Objects with same name
if ([[self.scene allObjectNames] containsObject:name]) {
return [InputValidationResult invalidInputWithLocalizedMessage:kLocalizedObjectNameAlreadyExistsDescription];
}
return [InputValidationResult validInput];
}] build]
showWithController:self];
}

-(void)cancelAddingObjectFromScriptEditor
{
if (self.afterSafeBlock) {
self.afterSafeBlock(nil);
}
}

- (void)addObjectActionWithName:(NSString*)objectName
{
[self showLoadingView];
[self.scene addObjectWithName:[Util uniqueName:objectName existingNames:[self.scene allObjectNames]]];
SpriteObject * object = [SpriteObject alloc];
[self.scene addObject:object];
NSInteger numberOfRowsInLastSection = [self tableView:self.tableView numberOfRowsInSection:kObjectSectionIndex];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:(numberOfRowsInLastSection - 1) inSection:kObjectSectionIndex];
[self.tableView insertRowsAtIndexPaths:@[indexPath]
Expand All @@ -136,6 +104,42 @@ - (void)addObjectActionWithName:(NSString*)objectName
ltvc.showAddLookActionSheetAtStartForScriptEditor = NO;
ltvc.afterSafeBlock = ^(Look* look) {
[self.navigationController popViewControllerAnimated:YES];
NSString *initialText = @"";
if (look) {
if (![look.name isEqual: @"look"]) {
initialText = look.name;
}
}
[[[[[[[[AlertControllerBuilder textFieldAlertWithTitle:kLocalizedAddObject message:[NSString stringWithFormat:@"%@:", kLocalizedObjectName]]
placeholder:kLocalizedEnterYourObjectNameHere]
initialText:initialText]
addCancelActionWithTitle:kLocalizedCancel handler:^{
NSUInteger index = (kBackgroundObjects + indexPath.row);
SpriteObject *object = (SpriteObject*)[self.scene.objects objectAtIndex:index];
[self.scene removeObject:object];
[self.scene.project saveToDiskWithNotification:NO];
[self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:((indexPath.row != 0) ? UITableViewRowAnimationTop : UITableViewRowAnimationFade)];
[self cancelAddingObjectFromScriptEditor];
}]
addDefaultActionWithTitle:kLocalizedOK handler:^(NSString *name) {
[self renameObjectActionToName:name spriteObject:(SpriteObject*)[self.scene.objects objectAtIndex:(kBackgroundObjectIndex + indexPath.section + indexPath.row)]];
}]
valueValidator:^InputValidationResult *(NSString *name) {
InputValidationResult *result = [Util validationResultWithName:name
minLength:kMinNumOfObjectNameCharacters
maxlength:kMaxNumOfObjectNameCharacters];
if (!result.valid) {
return result;
}
// Alert for Objects with same name
if ([[self.scene allObjectNames] containsObject:name]) {
return [InputValidationResult invalidInputWithLocalizedMessage:kLocalizedObjectNameAlreadyExistsDescription];
}
return [InputValidationResult validInput];
}] build]
showWithController:self];
[self showPlaceHolder:!(BOOL)[self.scene numberOfNormalObjects]];
[self hideLoadingView];
if (!look) {
NSUInteger index = (kBackgroundObjects + indexPath.row);
SpriteObject *object = (SpriteObject*)[self.scene.objects objectAtIndex:index];
Expand All @@ -152,9 +156,13 @@ - (void)addObjectActionWithName:(NSString*)objectName
}
[self showPlaceHolder:!(BOOL)[self.scene numberOfNormalObjects]];
};
[self.navigationController pushViewController:ltvc animated:NO];
[self showPlaceHolder:!(BOOL)[self.scene numberOfNormalObjects]];
[self hideLoadingView];
[self.navigationController pushViewController:ltvc animated:NO];}

-(void)cancelAddingObjectFromScriptEditor
{
if (self.afterSafeBlock) {
self.afterSafeBlock(nil);
}
}

- (void)renameProjectActionForProjectWithName:(NSString*)newProjectName
Expand Down

0 comments on commit 72e3528

Please sign in to comment.