-
Notifications
You must be signed in to change notification settings - Fork 0
/
Users.m
87 lines (72 loc) · 2.87 KB
/
Users.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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
76
77
78
79
80
81
82
//
// Users.m
//
// Created by : Michael Heirendt
// Project : Crush
// Date : 1/28/16
//
// Copyright (c) 2016 Apportable.
// All rights reserved.
//
// -----------------------------------------------------------------
#import "Users.h"
#import "UsersTable.h"
#import "GameData.h"
#import "AlertView.h"
// -----------------------------------------------------------------
@implementation Users{
CCButton *createButton;
CCButton *cancelButton;
}
// -----------------------------------------------------------------
- (instancetype)init
{
self = [super init];
NSAssert(self, @"Unable to create class %@", [self class]);
UsersTable *table = [UsersTable node];
table.contentSizeType = CCSizeTypeNormalized;
table.positionType = CCPositionTypeNormalized;
table.position = ccp(.2f,-0.01f);
table.contentSize = CGSizeMake(1, 1);
table.zOrder = 1000;
[self addChild:table];
return self;
}
-(void)createUser{
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Person" inManagedObjectContext:[GameData sharedGameData].managedObjectContext];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:entity];
NSString *currentUser = [[NSUserDefaults standardUserDefaults]
stringForKey:@"defaultUser"];
NSEntityDescription *entity1 = [NSEntityDescription entityForName:@"Person" inManagedObjectContext:[GameData sharedGameData].managedObjectContext];
NSFetchRequest *request1 = [[NSFetchRequest alloc] init];
[request1 setEntity:entity1];
NSPredicate *predicate1 = [NSPredicate predicateWithFormat:@"name != %@", currentUser];
[request1 setPredicate:predicate1];
NSSortDescriptor *sort = [NSSortDescriptor sortDescriptorWithKey:@"name" ascending:YES];
[request1 setSortDescriptors:[NSArray arrayWithObjects:sort, nil]];
NSError *error = nil;
NSUInteger count = [[GameData sharedGameData].managedObjectContext countForFetchRequest:request1 error:&error];
CCLOG(@"count:%d",(int)count);
if (count + 1 <= 10){
[GameData sharedGameData].tableID = 3;
CCScene *gameplayScene = [CCBReader loadAsScene:@"SignIn"];
[[CCDirector sharedDirector] pushScene:gameplayScene];
}
else{
cancelButton.enabled = false;
createButton.enabled = false;
self.userInteractionEnabled = false;
id block = ^(void){
cancelButton.enabled = true;
createButton.enabled = true;
self.userInteractionEnabled = true;
};
[AlertView ShowAlert:@"You may only create 11 users. Play as an existing user or delete unnecessary users." onLayer:self withOpt1:@"Okay" withOpt1Block:block andOpt2:nil withOpt2Block:nil];
}
}
-(void)backPressed{
[[CCDirector sharedDirector] popScene];
}
// -----------------------------------------------------------------
@end