OSDN Git Service

UIを調整
[kcd/KCD.git] / KCD / HMShipDetailViewController.m
1 //
2 //  HMShipDetailViewController.m
3 //  KCD
4 //
5 //  Created by Hori,Masaki on 2015/02/28.
6 //  Copyright (c) 2015年 Hori,Masaki. All rights reserved.
7 //
8
9 #import "HMShipDetailViewController.h"
10 #import "HMSuppliesView.h"
11
12 #import "HMServerDataStore.h"
13
14
15 #import "HMGuardEscapedView.h"
16 #import "HMGuardShelterCommand.h"
17 #import "HMDamageView.h"
18
19
20 @interface HMShipDetailViewController ()
21
22 @property (readonly) NSManagedObjectContext *managedObjectContext;
23
24 @property (nonatomic, weak) IBOutlet HMSuppliesView *supply;
25 @property (nonatomic, weak) IBOutlet HMGuardEscapedView *guardEscapedView;
26 @property (nonatomic, weak) IBOutlet HMDamageView *damageView;
27
28 @property (nonatomic, weak) IBOutlet NSObjectController *shipController;
29 @property (nonatomic, weak) IBOutlet NSTextField *slot00Field;
30 @property (nonatomic, weak) IBOutlet NSTextField *slot01Field;
31 @property (nonatomic, weak) IBOutlet NSTextField *slot02Field;
32 @property (nonatomic, weak) IBOutlet NSTextField *slot03Field;
33
34 @end
35
36 @implementation HMShipDetailViewController
37
38 - (id)init
39 {
40         self = [super initWithNibName:NSStringFromClass([self class]) bundle:nil];
41         if(self) {
42                 NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
43                 [nc addObserver:self
44                            selector:@selector(updateStatus:)
45                                    name:HMGuardShelterCommandDidUpdateGuardExcapeNotification
46                                  object:nil];
47         }
48         return self;
49 }
50
51 - (instancetype)initWithType:(HMShipDetailViewType)type
52 {
53         NSString *nibName = nil;
54         switch(type) {
55                 case full:
56                         nibName = @"HMShipDetailViewController";
57                         break;
58                 case medium:
59                         nibName = @"HMMediumShipViewController";
60                         break;
61                 case minimum:
62                         nibName = @"HMMediumShipViewController";
63                         break;
64         }
65         assert(nibName);
66         
67         self = [super initWithNibName:nibName bundle:nil];
68         if(self) {
69                 NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
70                 [nc addObserver:self
71                            selector:@selector(updateStatus:)
72                                    name:HMGuardShelterCommandDidUpdateGuardExcapeNotification
73                                  object:nil];
74         }
75         return self;
76 }
77 + (instancetype)viewControllerWithType:(HMShipDetailViewType)type
78 {
79         return [[self alloc] initWithType:type];
80 }
81 - (void)dealloc
82 {
83         NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
84         [nc removeObserver:self];
85         
86         [self.damageView unbind:@"damageType"];
87 }
88
89 - (void)updateStatus:(NSNotification *)notification
90 {
91         NSNumber *escaped = [self.shipController.content valueForKey:@"guardEscaped"];
92         self.guardEscaped = [escaped boolValue];
93 }
94
95
96 - (void)awakeFromNib
97 {
98         [self.damageView setFrameOrigin:NSZeroPoint];
99         [self.view addSubview:self.damageView];
100         [self.damageView bind:@"damageType"
101                                  toObject:self.shipController
102                           withKeyPath:@"selection.status"
103                                   options:@{
104                                                         NSRaisesForNotApplicableKeysBindingOption : @YES,
105                                                         }];
106         
107         [self.guardEscapedView setFrameOrigin:NSZeroPoint];
108         [self.view addSubview:self.guardEscapedView];
109         
110         [self.slot00Field bind:@"slotItemID"
111                                   toObject:self.shipController
112                            withKeyPath:@"selection.slot_0"
113                                    options:nil];
114         [self.slot01Field bind:@"slotItemID"
115                                   toObject:self.shipController
116                            withKeyPath:@"selection.slot_1"
117                                    options:nil];
118         [self.slot02Field bind:@"slotItemID"
119                                   toObject:self.shipController
120                            withKeyPath:@"selection.slot_2"
121                                    options:nil];
122         [self.slot03Field bind:@"slotItemID"
123                                   toObject:self.shipController
124                            withKeyPath:@"selection.slot_3"
125                                    options:nil];
126 }
127
128 - (NSManagedObjectContext *)managedObjectContext
129 {
130         return [HMServerDataStore defaultManager].managedObjectContext;
131 }
132
133 - (void)setShip:(HMKCShipObject *)ship
134 {
135         self.representedObject = ship;
136         
137         self.supply.shipStatus = ship;
138 }
139 - (HMKCShipObject *)ship
140 {
141         return self.representedObject;
142 }
143
144
145 - (void)setGuardEscaped:(BOOL)guardEscaped
146 {
147         self.guardEscapedView.hidden = !guardEscaped;
148         _guardEscaped = guardEscaped;
149 }
150
151 @end