@interface HMFleetViewController : NSViewController
@property (strong) HMKCDeck* fleet;
+@property NSInteger fleetNumber;
+@property (readonly) NSNumber *totalSakuteki;
+@property (readonly) NSNumber *totalSeiku;
@end
#import "HMFleetViewController.h"
#import "HMShipDetailViewController.h"
+#import "HMKCShipObject+Extensions.h"
#import "HMKCDeck+Extension.h"
#import "HMServerDataStore.h"
@property (strong) HMShipDetailViewController *detail05;
@property (strong) HMShipDetailViewController *detail06;
-
-@property (nonatomic, weak) IBOutlet NSTextField *fleetID;
-- (IBAction)changeFleet:(id)sender;
@end
@implementation HMFleetViewController
+@synthesize fleetNumber = _fleetNumber;
+
- (id)init
{
self = [super initWithNibName:NSStringFromClass([self class]) bundle:nil];
NSString *detailKey = [NSString stringWithFormat:@"detail%02ld", i];
NSString *placeholderKey = [NSString stringWithFormat:@"placeholder%02ld", i];
HMShipDetailViewController *detail = [HMShipDetailViewController new];
+ detail.title = [NSString stringWithFormat:@"%ld", i];
[self setValue:detail forKey:detailKey];
NSView *view = [self valueForKey:placeholderKey];
[detail.view setAutoresizingMask:[view autoresizingMask]];
[[view superview] replaceSubview:view with:detail.view];
}
+
+ self.fleetNumber = 1;
+}
+
+- (void)setShipID:(NSInteger)shipId toDetail:(HMShipDetailViewController *)detail
+{
+ HMServerDataStore *store = [HMServerDataStore defaultManager];
+ NSError *error = nil;
+ HMKCShipObject *ship = nil;
+ NSArray *array = [store objectsWithEntityName:@"Ship"
+ error:&error
+ predicateFormat:@"id = %ld", shipId];
+ if(error) {
+ NSLog(@"%s error: %@", __PRETTY_FUNCTION__, error);
+ }
+ if(array.count != 0) {
+ ship = array[0];
+ }
+ detail.ship = ship;
}
- (void)setFleet:(HMKCDeck *)fleet
{
- self.representedObject = fleet;
+ for(NSInteger i = 0; i < 6; i++) {
+ [self.representedObject removeObserver:self
+ forKeyPath:[NSString stringWithFormat:@"ship_%ld", i]];
+ }
+ for(NSInteger i = 0; i < 6; i++) {
+ [fleet addObserver:self
+ forKeyPath:[NSString stringWithFormat:@"ship_%ld", i]
+ options:0
+ context:NULL];
+ }
+
+ self.representedObject = fleet;
- HMServerDataStore *store = [HMServerDataStore defaultManager];
for(NSInteger i = 1; i < 7; i++) {
NSString *shipID = [self.fleet valueForKey:[NSString stringWithFormat:@"ship_%ld", i - 1]];
-
- HMKCShipObject *ship = nil;
- NSArray *array = [store objectsWithEntityName:@"Ship"
- error:NULL
- predicateFormat:@"id = %@", shipID];
- if(array.count != 0) {
- ship = array[0];
- }
HMShipDetailViewController *detail = [self valueForKey:[NSString stringWithFormat:@"detail%02ld", i]];
- detail.ship = ship;
+ [self setShipID:shipID.integerValue toDetail:detail];
}
}
- (HMKCDeck *)fleet
return self.representedObject;
}
-- (IBAction)changeFleet:(id)sender
+- (void)setFleetNumber:(NSInteger)fleetNumber
{
- NSInteger fleetID = self.fleetID.integerValue;
-
HMServerDataStore *store = [HMServerDataStore defaultManager];
-
+ NSError *error = nil;
NSArray *array = [store objectsWithEntityName:@"Deck"
error:NULL
- predicateFormat:@"id = %ld", fleetID];
+ predicateFormat:@"id = %ld", fleetNumber];
+ if(error) {
+ NSLog(@"%s error: %@", __PRETTY_FUNCTION__, error);
+ return;
+ }
if(array.count == 0) {
return;
}
self.fleet = array[0];
+ _fleetNumber = fleetNumber;
+}
+- (NSInteger)fleetNumber
+{
+ return _fleetNumber;
+}
+
++ (NSSet *)keyPathsForValuesAffectingTotalSakuteki
+{
+ return [NSSet setWithObjects:
+ @"detail01.ship.sakuteki_0",
+ @"detail02.ship.sakuteki_0",
+ @"detail03.ship.sakuteki_0",
+ @"detail04.ship.sakuteki_0",
+ @"detail05.ship.sakuteki_0",
+ @"detail06.ship.sakuteki_0",
+ nil];
+}
+- (NSNumber *)totalSakuteki
+{
+ NSInteger total = 0;
+ for(NSInteger i = 1; i < 7; i++) {
+ HMShipDetailViewController *detail = [self valueForKey:[NSString stringWithFormat:@"detail%02ld", i]];
+ HMKCShipObject *ship = detail.ship;
+ total += ship.sakuteki_0.integerValue;
+ }
+ return @(total);
+}
+
++ (NSSet *)keyPathsForValuesAffectingTotalSeiku
+{
+ return [NSSet setWithObjects:
+ @"detail01.ship.seiku",
+ @"detail02.ship.seiku",
+ @"detail03.ship.seiku",
+ @"detail04.ship.seiku",
+ @"detail05.ship.seiku",
+ @"detail06.ship.seiku",
+ nil];
+}
+- (NSNumber *)totalSeiku
+{
+ NSInteger total = 0;
+ for(NSInteger i = 1; i < 7; i++) {
+ HMShipDetailViewController *detail = [self valueForKey:[NSString stringWithFormat:@"detail%02ld", i]];
+ HMKCShipObject *ship = detail.ship;
+ total += ship.seiku.integerValue;
+ }
+ return @(total);
+}
+
+- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
+{
+ if([keyPath isEqualToString:@"ship_0"]) {
+ [self setShipID:[[object valueForKey:keyPath] integerValue] toDetail:self.detail01];
+ return;
+ }
+ if([keyPath isEqualToString:@"ship_1"]) {
+ [self setShipID:[[object valueForKey:keyPath] integerValue] toDetail:self.detail02];
+ return;
+ }
+ if([keyPath isEqualToString:@"ship_2"]) {
+ [self setShipID:[[object valueForKey:keyPath] integerValue] toDetail:self.detail03];
+ return;
+ }
+ if([keyPath isEqualToString:@"ship_3"]) {
+ [self setShipID:[[object valueForKey:keyPath] integerValue] toDetail:self.detail04];
+ return;
+ }
+ if([keyPath isEqualToString:@"ship_4"]) {
+ [self setShipID:[[object valueForKey:keyPath] integerValue] toDetail:self.detail05];
+ return;
+ }
+ if([keyPath isEqualToString:@"ship_5"]) {
+ [self setShipID:[[object valueForKey:keyPath] integerValue] toDetail:self.detail06];
+ return;
+ }
+
+ return [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
@end
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="HMFleetViewController">
<connections>
- <outlet property="fleetID" destination="BTK-fL-XIh" id="QMG-fa-pLp"/>
<outlet property="placeholder01" destination="oKZ-TQ-Oxl" id="ZIM-JB-14x"/>
<outlet property="placeholder02" destination="BeT-FP-eCr" id="IqG-AT-ntX"/>
<outlet property="placeholder03" destination="GpH-v8-Nvl" id="yMy-Gb-lsc"/>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<customView id="Hz6-mo-xeY">
- <rect key="frame" x="0.0" y="-1" width="889" height="302"/>
+ <rect key="frame" x="0.0" y="-1" width="807" height="296"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<customView id="BeT-FP-eCr">
- <rect key="frame" x="20" y="14" width="255" height="129"/>
+ <rect key="frame" x="20" y="8" width="263" height="129"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
</customView>
<customView id="eru-mj-cKl">
- <rect key="frame" x="274" y="14" width="255" height="129"/>
+ <rect key="frame" x="282" y="8" width="263" height="129"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
</customView>
<customView id="jG7-Xp-ypT">
- <rect key="frame" x="528" y="14" width="255" height="129"/>
+ <rect key="frame" x="544" y="8" width="263" height="129"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
</customView>
<customView id="oKZ-TQ-Oxl">
- <rect key="frame" x="20" y="142" width="255" height="129"/>
+ <rect key="frame" x="20" y="136" width="263" height="129"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
</customView>
<customView id="GpH-v8-Nvl">
- <rect key="frame" x="274" y="142" width="255" height="129"/>
+ <rect key="frame" x="282" y="136" width="263" height="129"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
</customView>
<customView id="uFG-Qe-q4v">
- <rect key="frame" x="528" y="142" width="255" height="129"/>
+ <rect key="frame" x="544" y="136" width="263" height="129"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
</customView>
<matrix verticalHuggingPriority="750" allowsEmptySelection="NO" autorecalculatesCellSize="YES" id="EJt-sg-Fk4">
- <rect key="frame" x="21" y="276" width="308" height="18"/>
+ <rect key="frame" x="21" y="270" width="308" height="18"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
<size key="cellSize" width="74" height="18"/>
</buttonCell>
<cells>
<column>
- <buttonCell type="radio" title="第一艦隊" imagePosition="left" alignment="left" inset="2" id="lXZ-hG-VWw">
+ <buttonCell type="radio" title="第一艦隊" imagePosition="left" alignment="left" tag="1" inset="2" id="lXZ-hG-VWw">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
</column>
<column>
- <buttonCell type="radio" title="第二艦隊" imagePosition="left" alignment="left" inset="2" id="8TJ-gQ-73y">
+ <buttonCell type="radio" title="第二艦隊" imagePosition="left" alignment="left" tag="2" inset="2" id="8TJ-gQ-73y">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
</column>
<column>
- <buttonCell type="radio" title="第三艦隊" imagePosition="left" alignment="left" inset="2" id="NQM-mT-j56">
+ <buttonCell type="radio" title="第三艦隊" imagePosition="left" alignment="left" tag="3" inset="2" id="NQM-mT-j56">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
</column>
<column>
- <buttonCell type="radio" title="第四艦隊" imagePosition="left" alignment="left" inset="2" id="BT4-MN-fdg">
+ <buttonCell type="radio" title="第四艦隊" imagePosition="left" alignment="left" tag="4" inset="2" id="BT4-MN-fdg">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
</column>
</cells>
+ <connections>
+ <binding destination="-2" name="selectedTag" keyPath="fleetNumber" id="4gQ-71-HFy"/>
+ </connections>
</matrix>
- <textField verticalHuggingPriority="750" id="BTK-fL-XIh">
- <rect key="frame" x="835" y="20" width="34" height="22"/>
+ <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" id="f8W-G4-mOr">
+ <rect key="frame" x="420" y="271" width="56" height="17"/>
+ <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
+ <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="索敵値:" id="vA3-9F-FLk">
+ <font key="font" size="13" name="AquaKana"/>
+ <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
+ <color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
+ </textFieldCell>
+ </textField>
+ <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" id="mUy-1k-ALk">
+ <rect key="frame" x="471" y="271" width="29" height="17"/>
+ <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
+ <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="999" id="HeX-Wd-ikA">
+ <numberFormatter key="formatter" formatterBehavior="default10_4" usesGroupingSeparator="NO" groupingSize="0" minimumIntegerDigits="0" maximumIntegerDigits="42" id="ntt-Mj-4hA"/>
+ <font key="font" metaFont="system"/>
+ <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
+ <color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
+ </textFieldCell>
+ <connections>
+ <binding destination="-2" name="value" keyPath="totalSakuteki" id="1H9-FR-9Aw"/>
+ </connections>
+ </textField>
+ <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" id="ee5-Xk-4iW">
+ <rect key="frame" x="510" y="271" width="56" height="17"/>
+ <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
+ <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="制空値:" id="dS3-tO-y1s">
+ <font key="font" size="13" name="AquaKana"/>
+ <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
+ <color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
+ </textFieldCell>
+ </textField>
+ <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" id="Jhy-EA-ust">
+ <rect key="frame" x="561" y="271" width="29" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
- <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" drawsBackground="YES" id="eG9-fQ-xJE">
+ <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="999" id="ytq-FR-96e">
+ <numberFormatter key="formatter" formatterBehavior="default10_4" usesGroupingSeparator="NO" groupingSize="0" minimumIntegerDigits="0" maximumIntegerDigits="42" id="NZH-vE-NqR"/>
<font key="font" metaFont="system"/>
- <color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
- <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
+ <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
+ <color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
<connections>
- <action selector="changeFleet:" target="-2" id="TyD-eH-IWh"/>
+ <binding destination="-2" name="value" keyPath="totalSeiku" id="rv3-ob-Fyz"/>
</connections>
</textField>
</subviews>
- <point key="canvasLocation" x="501.5" y="387"/>
+ <point key="canvasLocation" x="460.5" y="384"/>
</customView>
</objects>
</document>