OSDN Git Service

UIを調整
[kcd/KCD.git] / KCD / HMSlotItemWindowController.m
1 //
2 //  HMSlotItemWindowController.m
3 //  KCD
4 //
5 //  Created by Hori,Masaki on 2014/04/29.
6 //  Copyright (c) 2014年 Hori,Masaki. All rights reserved.
7 //
8
9 #import "HMSlotItemWindowController.h"
10 #import "HMUserDefaults.h"
11
12 #import "HMServerDataStore.h"
13
14 @interface HMSlotItemWindowController ()
15
16 @end
17
18 @implementation HMSlotItemWindowController
19
20 - (id)init
21 {
22         self = [super initWithWindowNibName:NSStringFromClass([self class])];
23         return self;
24 }
25
26 - (void)awakeFromNib
27 {
28         [self.slotItemController fetchWithRequest:nil merge:YES error:NULL];
29         [self.slotItemController setSortDescriptors:HMStandardDefaults.slotItemSortDescriptors];
30         [self.slotItemController addObserver:self
31                                                   forKeyPath:NSSortDescriptorsBinding
32                                                          options:0
33                                                          context:NULL];
34         
35         // refresh filter
36         self.showEquipmentType = self.showEquipmentType;
37 }
38 - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
39 {
40         if([keyPath isEqualToString:NSSortDescriptorsBinding]) {
41                 HMStandardDefaults.slotItemSortDescriptors = [self.slotItemController sortDescriptors];
42                 return;
43         }
44         
45         [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
46 }
47
48 - (NSManagedObjectContext *)managedObjectContext
49 {
50         return [HMServerDataStore defaultManager].managedObjectContext;
51 }
52
53 + (NSSet *)keyPathsForValuesAffectingFilterPredicate
54 {
55         return [NSSet setWithObject:@"showEquipmentType"];
56 }
57 + (NSSet *)keyPathsForValuesAffectingShowEquipmentTypeTitle
58 {
59         return [NSSet setWithObject:@"showEquipmentType"];
60 }
61 - (void)setShowEquipmentType:(NSNumber *)showEquipmentType
62 {
63         HMStandardDefaults.showEquipmentType = showEquipmentType;
64         self.slotItemController.fetchPredicate = self.filterPredicate;
65 }
66 - (NSNumber *)showEquipmentType
67 {
68         return HMStandardDefaults.showEquipmentType;
69 }
70
71 - (NSPredicate *)filterPredicate
72 {
73         NSInteger type = HMStandardDefaults.showEquipmentType.integerValue;
74         switch (type) {
75                 case -1:
76                         break;
77                 case 0:
78                         return [NSPredicate predicateWithFormat:@"equippedShip.lv = NULL"];
79                         break;
80                 case 1:
81                         return [NSPredicate predicateWithFormat:@"equippedShip.lv != NULL"];
82                         break;
83                 default:
84                         break;
85         }
86         return nil;
87 }
88 - (NSString *)showEquipmentTypeTitle
89 {
90         NSInteger type = HMStandardDefaults.showEquipmentType.integerValue;
91         switch (type) {
92                 case -1:
93                         return NSLocalizedString(@"All", @"show equipment type All");
94                         break;
95                 case 0:
96                         return NSLocalizedString(@"Unequiped", @"show equipment type Unequiped");
97                         break;
98                 case 1:
99                         return NSLocalizedString(@"Equiped", @"show equipment type Equiped");
100                         break;
101                 default:
102                         break;
103         }
104         return @"";
105 }
106
107 @end