2 // HMResourceViewController.m
5 // Created by Hori,Masaki on 2015/12/06.
6 // Copyright (c) 2015年 Hori,Masaki. All rights reserved.
9 #import "HMResourceViewController.h"
11 #import "HMUserDefaults.h"
13 #import "HMServerDataStore.h"
15 @interface HMResourceViewController ()
16 @property (readonly) NSManagedObjectContext *managedObjectContext;
18 @property (nonatomic, strong) IBOutlet NSArrayController *shipController;
19 @property (nonatomic, strong) IBOutlet NSObjectController *basicController;
20 @property (nonatomic, strong) NSNumber *maxChara;
21 @property (nonatomic, strong) NSNumber *shipCount;
22 @property (readonly) NSColor *shipNumberColor;
23 @property NSInteger minimumColoredShipCount;
26 @implementation HMResourceViewController
30 self = [super initWithNibName:NSStringFromClass([self class]) bundle:nil];
36 [self bind:@"maxChara" toObject:self.basicController withKeyPath:@"selection.max_chara" options:nil];
37 [self bind:@"shipCount" toObject:self.shipController withKeyPath:@"arrangedObjects.@count" options:nil];
40 + (NSSet *)keyPathsForValuesAffectingShipNumberColor
42 return [NSSet setWithObjects:@"maxChara", @"shipCount", @"minimumColoredShipCount", nil];
45 - (NSManagedObjectContext *)managedObjectContext
47 return [HMServerDataStore defaultManager].managedObjectContext;
50 - (NSColor *)shipNumberColor
52 NSInteger max = self.maxChara.integerValue;
53 NSInteger current = self.shipCount.integerValue;
55 if(current > max - self.minimumColoredShipCount) {
56 return [NSColor orangeColor];
59 return [NSColor controlTextColor];
61 - (void)setMinimumColoredShipCount:(NSInteger)minimumColoredShipCount
63 HMStandardDefaults.minimumColoredShipCount = minimumColoredShipCount;
65 - (NSInteger)minimumColoredShipCount
67 return HMStandardDefaults.minimumColoredShipCount;