2 // HMShipDetailViewController.m
5 // Created by Hori,Masaki on 2015/02/28.
6 // Copyright (c) 2015年 Hori,Masaki. All rights reserved.
9 #import "HMShipDetailViewController.h"
10 #import "HMSuppliesView.h"
12 #import "HMServerDataStore.h"
15 #import "HMGuardEscapedView.h"
16 #import "HMGuardShelterCommand.h"
17 #import "HMDamageView.h"
20 @interface HMShipDetailViewController ()
22 @property (readonly) NSManagedObjectContext *managedObjectContext;
24 @property (nonatomic, weak) IBOutlet HMSuppliesView *supply;
25 @property (nonatomic, weak) IBOutlet HMGuardEscapedView *guardEscapedView;
26 @property (nonatomic, weak) IBOutlet HMDamageView *damageView;
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;
36 @implementation HMShipDetailViewController
40 self = [super initWithNibName:NSStringFromClass([self class]) bundle:nil];
42 NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
44 selector:@selector(updateStatus:)
45 name:HMGuardShelterCommandDidUpdateGuardExcapeNotification
51 - (instancetype)initWithType:(HMShipDetailViewType)type
53 NSString *nibName = nil;
56 nibName = @"HMShipDetailViewController";
59 nibName = @"HMMediumShipViewController";
62 nibName = @"HMMediumShipViewController";
67 self = [super initWithNibName:nibName bundle:nil];
69 NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
71 selector:@selector(updateStatus:)
72 name:HMGuardShelterCommandDidUpdateGuardExcapeNotification
77 + (instancetype)viewControllerWithType:(HMShipDetailViewType)type
79 return [[self alloc] initWithType:type];
83 NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
84 [nc removeObserver:self];
86 [self.damageView unbind:@"damageType"];
89 - (void)updateStatus:(NSNotification *)notification
91 NSNumber *escaped = [self.shipController.content valueForKey:@"guardEscaped"];
92 self.guardEscaped = [escaped boolValue];
98 [self.damageView setFrameOrigin:NSZeroPoint];
99 [self.view addSubview:self.damageView];
100 [self.damageView bind:@"damageType"
101 toObject:self.shipController
102 withKeyPath:@"selection.status"
104 NSRaisesForNotApplicableKeysBindingOption : @YES,
107 [self.guardEscapedView setFrameOrigin:NSZeroPoint];
108 [self.view addSubview:self.guardEscapedView];
110 [self.slot00Field bind:@"slotItemID"
111 toObject:self.shipController
112 withKeyPath:@"selection.slot_0"
114 [self.slot01Field bind:@"slotItemID"
115 toObject:self.shipController
116 withKeyPath:@"selection.slot_1"
118 [self.slot02Field bind:@"slotItemID"
119 toObject:self.shipController
120 withKeyPath:@"selection.slot_2"
122 [self.slot03Field bind:@"slotItemID"
123 toObject:self.shipController
124 withKeyPath:@"selection.slot_3"
128 - (NSManagedObjectContext *)managedObjectContext
130 return [HMServerDataStore defaultManager].managedObjectContext;
133 - (void)setShip:(HMKCShipObject *)ship
135 self.representedObject = ship;
137 self.supply.shipStatus = ship;
139 - (HMKCShipObject *)ship
141 return self.representedObject;
145 - (void)setGuardEscaped:(BOOL)guardEscaped
147 self.guardEscapedView.hidden = !guardEscaped;
148 _guardEscaped = guardEscaped;