2 // HMSlotItemWindowController.m
5 // Created by Hori,Masaki on 2014/04/29.
6 // Copyright (c) 2014年 Hori,Masaki. All rights reserved.
9 #import "HMSlotItemWindowController.h"
10 #import "HMUserDefaults.h"
12 #import "HMServerDataStore.h"
14 @interface HMSlotItemWindowController ()
18 @implementation HMSlotItemWindowController
22 self = [super initWithWindowNibName:NSStringFromClass([self class])];
28 [self.slotItemController fetchWithRequest:nil merge:YES error:NULL];
29 [self.slotItemController setSortDescriptors:HMStandardDefaults.slotItemSortDescriptors];
30 [self.slotItemController addObserver:self
31 forKeyPath:NSSortDescriptorsBinding
36 self.showEquipmentType = self.showEquipmentType;
38 - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
40 if([keyPath isEqualToString:NSSortDescriptorsBinding]) {
41 HMStandardDefaults.slotItemSortDescriptors = [self.slotItemController sortDescriptors];
45 [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
48 - (NSManagedObjectContext *)managedObjectContext
50 return [HMServerDataStore defaultManager].managedObjectContext;
53 + (NSSet *)keyPathsForValuesAffectingFilterPredicate
55 return [NSSet setWithObject:@"showEquipmentType"];
57 + (NSSet *)keyPathsForValuesAffectingShowEquipmentTypeTitle
59 return [NSSet setWithObject:@"showEquipmentType"];
61 - (void)setShowEquipmentType:(NSNumber *)showEquipmentType
63 HMStandardDefaults.showEquipmentType = showEquipmentType;
64 self.slotItemController.fetchPredicate = self.filterPredicate;
66 - (NSNumber *)showEquipmentType
68 return HMStandardDefaults.showEquipmentType;
71 - (NSPredicate *)filterPredicate
73 NSInteger type = HMStandardDefaults.showEquipmentType.integerValue;
78 return [NSPredicate predicateWithFormat:@"equippedShip.lv = NULL"];
81 return [NSPredicate predicateWithFormat:@"equippedShip.lv != NULL"];
88 - (NSString *)showEquipmentTypeTitle
90 NSInteger type = HMStandardDefaults.showEquipmentType.integerValue;
93 return NSLocalizedString(@"All", @"show equipment type All");
96 return NSLocalizedString(@"Unequiped", @"show equipment type Unequiped");
99 return NSLocalizedString(@"Equiped", @"show equipment type Equiped");