Mac用艦これ専用ブラウザ おまけ機能付き
Revision | d5c3eef26711b6728d5aaf68eb108d24fc35d7cf (tree) |
---|---|
Time | 2015-08-20 22:04:28 |
Author | masakih <masakih@user...> |
Commiter | masakih |
装備のレベルと熟練度を表示するビューを追加
@@ -73,6 +73,7 @@ | ||
73 | 73 | F471784D1B6FA18800F5E59D /* HMKCResource.m in Sources */ = {isa = PBXBuildFile; fileRef = F471784C1B6FA18800F5E59D /* HMKCResource.m */; }; |
74 | 74 | F47178501B6FA1B300F5E59D /* HMResourceHistoryDataStore.m in Sources */ = {isa = PBXBuildFile; fileRef = F471784F1B6FA1B300F5E59D /* HMResourceHistoryDataStore.m */; }; |
75 | 75 | F47B78B218A7B42B0011386E /* HMJSONViewWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = F47B78B018A7B42B0011386E /* HMJSONViewWindowController.m */; }; |
76 | + F47E895D1B80DB9F00B2E552 /* HMSlotItemLevelView.m in Sources */ = {isa = PBXBuildFile; fileRef = F47E895C1B80DB9F00B2E552 /* HMSlotItemLevelView.m */; }; | |
76 | 77 | F48F7B021907D7B800E78AE1 /* HMPortCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = F48F7B011907D7B800E78AE1 /* HMPortCommand.m */; }; |
77 | 78 | F494DC5F18C30AE100AE97E4 /* HMMissionStatus.m in Sources */ = {isa = PBXBuildFile; fileRef = F494DC5E18C30AE100AE97E4 /* HMMissionStatus.m */; }; |
78 | 79 | F494DC6318C608C100AE97E4 /* HMShipViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F494DC6118C608C100AE97E4 /* HMShipViewController.m */; }; |
@@ -339,6 +340,8 @@ | ||
339 | 340 | F471784F1B6FA1B300F5E59D /* HMResourceHistoryDataStore.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMResourceHistoryDataStore.m; sourceTree = "<group>"; }; |
340 | 341 | F47B78AF18A7B42B0011386E /* HMJSONViewWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMJSONViewWindowController.h; sourceTree = "<group>"; }; |
341 | 342 | F47B78B018A7B42B0011386E /* HMJSONViewWindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMJSONViewWindowController.m; sourceTree = "<group>"; }; |
343 | + F47E895B1B80DB9F00B2E552 /* HMSlotItemLevelView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMSlotItemLevelView.h; sourceTree = "<group>"; }; | |
344 | + F47E895C1B80DB9F00B2E552 /* HMSlotItemLevelView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMSlotItemLevelView.m; sourceTree = "<group>"; }; | |
342 | 345 | F48F7B001907D7B800E78AE1 /* HMPortCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMPortCommand.h; sourceTree = "<group>"; }; |
343 | 346 | F48F7B011907D7B800E78AE1 /* HMPortCommand.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMPortCommand.m; sourceTree = "<group>"; }; |
344 | 347 | F494DC5618C23E4300AE97E4 /* ja */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ja; path = ja.lproj/MainMenu.strings; sourceTree = "<group>"; }; |
@@ -901,6 +904,8 @@ | ||
901 | 904 | F4BEF00A1B11A5DE004702B8 /* HMShipDetailViewController.xib */, |
902 | 905 | F4ED5D281B78D0CA00D1BDEF /* HMHaihiView.h */, |
903 | 906 | F4ED5D291B78D0CA00D1BDEF /* HMHaihiView.m */, |
907 | + F47E895B1B80DB9F00B2E552 /* HMSlotItemLevelView.h */, | |
908 | + F47E895C1B80DB9F00B2E552 /* HMSlotItemLevelView.m */, | |
904 | 909 | F4D6BCB71AA32BEA00742FEB /* HMFleetViewController.h */, |
905 | 910 | F4D6BCB81AA32BEA00742FEB /* HMFleetViewController.m */, |
906 | 911 | F4BEF0071B11A5D3004702B8 /* HMFleetViewController.xib */, |
@@ -1361,6 +1366,7 @@ | ||
1361 | 1366 | F4B414EC18B0A7D600468DAF /* HMMasterUseItemCommand.m in Sources */, |
1362 | 1367 | F4513EF318B991F800073552 /* HMMemberBasicCommand.m in Sources */, |
1363 | 1368 | F4268009193AF4E000B2C27F /* HMUserDefaults.m in Sources */, |
1369 | + F47E895D1B80DB9F00B2E552 /* HMSlotItemLevelView.m in Sources */, | |
1364 | 1370 | F44AB20019E050F600F217AF /* HMKCDeck.m in Sources */, |
1365 | 1371 | F43F3D4F1A34ACCD00D6DAF7 /* HMKCShipObject.m in Sources */, |
1366 | 1372 | F448F9951B70E9BE004901AD /* HMKCMaterial.m in Sources */, |
@@ -0,0 +1,15 @@ | ||
1 | +// | |
2 | +// HMSlotItemLevelView.h | |
3 | +// KCD | |
4 | +// | |
5 | +// Created by Hori,Masaki on 2015/08/16. | |
6 | +// Copyright (c) 2015年 Hori,Masaki. All rights reserved. | |
7 | +// | |
8 | + | |
9 | +#import <Cocoa/Cocoa.h> | |
10 | + | |
11 | +@interface HMSlotItemLevelView : NSTextField | |
12 | + | |
13 | +@property (nonatomic, strong) NSNumber *slotItemID; | |
14 | + | |
15 | +@end |
@@ -0,0 +1,389 @@ | ||
1 | +// | |
2 | +// HMSlotItemLevelView.m | |
3 | +// KCD | |
4 | +// | |
5 | +// Created by Hori,Masaki on 2015/08/16. | |
6 | +// Copyright (c) 2015年 Hori,Masaki. All rights reserved. | |
7 | +// | |
8 | + | |
9 | +#import "HMSlotItemLevelView.h" | |
10 | + | |
11 | +#import "HMServerDataStore.h" | |
12 | +#import "HMKCSlotItemObject+Extensions.h" | |
13 | + | |
14 | +#import "HMPortNotifyCommand.h" | |
15 | + | |
16 | + | |
17 | +static NSColor *sContentColor = nil; | |
18 | + | |
19 | +@interface HMSlotItemLevelView () | |
20 | + | |
21 | +@property (strong) HMKCSlotItemObject *slotItem; | |
22 | + | |
23 | +@end | |
24 | + | |
25 | +@implementation HMSlotItemLevelView | |
26 | + | |
27 | +- (void)awakeFromNib | |
28 | +{ | |
29 | + NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; | |
30 | + [nc addObserver:self | |
31 | + selector:@selector(didAlivalPort:) | |
32 | + name:@"HMPortAPIRecieveNotification" | |
33 | + object:nil]; | |
34 | +} | |
35 | + | |
36 | +- (void)calcContentColor | |
37 | +{ | |
38 | + NSRect rect = NSMakeRect(1, 1, 2, 2); | |
39 | + NSBitmapImageRep *rep = [[NSBitmapImageRep alloc] initWithFocusedViewRect:rect]; | |
40 | + sContentColor = [rep colorAtX:1 y:1]; | |
41 | +} | |
42 | +- (void)drawRect:(NSRect)dirtyRect { | |
43 | + | |
44 | + [super drawRect:dirtyRect]; | |
45 | + | |
46 | + if(!sContentColor) [self calcContentColor]; | |
47 | + | |
48 | + if(!self.slotItemID) return; | |
49 | + if(self.slotItemID.integerValue == 0) return; | |
50 | + if(self.slotItemID.integerValue == -1) return; | |
51 | + | |
52 | + NSNumber *aLevel = [self slotItemAlv]; | |
53 | + if([aLevel isKindOfClass:[NSNumber class]]) { | |
54 | + [[self colorForALevel:aLevel] set]; | |
55 | + [[self shadowForALevel:aLevel] set]; | |
56 | + [[self bezierPathForALevel:aLevel] stroke]; | |
57 | + } else { | |
58 | + [self drawLevel]; | |
59 | + } | |
60 | +} | |
61 | + | |
62 | +- (void)didAlivalPort:(NSNotification *)notification | |
63 | +{ | |
64 | + self.needsDisplay = YES; | |
65 | +} | |
66 | + | |
67 | +#pragma mark - Air Level | |
68 | + | |
69 | +- (CGFloat)offset | |
70 | +{ | |
71 | + return 4; | |
72 | +} | |
73 | +- (CGFloat)padding | |
74 | +{ | |
75 | + return 4.0; | |
76 | +} | |
77 | +- (CGFloat)slideOffset | |
78 | +{ | |
79 | + return 3.5; | |
80 | +} | |
81 | +- (NSBezierPath *)levelOneBezierPath | |
82 | +{ | |
83 | + NSRect frame = NSInsetRect(self.frame, 0, 1); | |
84 | + frame.origin = NSZeroPoint; | |
85 | + NSBezierPath *path = [NSBezierPath bezierPath]; | |
86 | + [path moveToPoint:NSMakePoint(frame.size.width - self.offset, 0)]; | |
87 | + [path lineToPoint:NSMakePoint(frame.size.width - self.offset, frame.size.height)]; | |
88 | + path.lineWidth = 1; | |
89 | + | |
90 | + return path; | |
91 | +} | |
92 | +- (NSBezierPath *)levelTwoBezierPath | |
93 | +{ | |
94 | + NSRect frame = NSInsetRect(self.frame, 0, 1); | |
95 | + frame.origin = NSZeroPoint; | |
96 | + NSBezierPath *path = [NSBezierPath bezierPath]; | |
97 | + [path moveToPoint:NSMakePoint(frame.size.width - self.offset, 0)]; | |
98 | + [path lineToPoint:NSMakePoint(frame.size.width - self.offset, frame.size.height)]; | |
99 | + | |
100 | + [path moveToPoint:NSMakePoint(frame.size.width - self.offset - 3.0, 0)]; | |
101 | + [path lineToPoint:NSMakePoint(frame.size.width - self.offset - 3.0, frame.size.height)]; | |
102 | + | |
103 | + path.lineWidth = 1; | |
104 | + | |
105 | + return path; | |
106 | +} | |
107 | +- (NSBezierPath *)levelThreeBezierPath | |
108 | +{ | |
109 | + NSRect frame = NSInsetRect(self.frame, 0, 1); | |
110 | + frame.origin = NSZeroPoint; | |
111 | + NSBezierPath *path = [NSBezierPath bezierPath]; | |
112 | + [path moveToPoint:NSMakePoint(frame.size.width - self.offset, 0)]; | |
113 | + [path lineToPoint:NSMakePoint(frame.size.width - self.offset, frame.size.height)]; | |
114 | + | |
115 | + [path moveToPoint:NSMakePoint(frame.size.width - self.offset - 3.0, 0)]; | |
116 | + [path lineToPoint:NSMakePoint(frame.size.width - self.offset - 3.0, frame.size.height)]; | |
117 | + | |
118 | + [path moveToPoint:NSMakePoint(frame.size.width - self.offset - 3.0 * 2, 0)]; | |
119 | + [path lineToPoint:NSMakePoint(frame.size.width - self.offset - 3.0 * 2, frame.size.height)]; | |
120 | + | |
121 | + path.lineWidth = 1; | |
122 | + | |
123 | + return path; | |
124 | +} | |
125 | +- (NSBezierPath *)levelFourBezierPath | |
126 | +{ | |
127 | + NSRect frame = NSInsetRect(self.frame, 0, 1); | |
128 | + frame.origin = NSZeroPoint; | |
129 | + NSBezierPath *path = [NSBezierPath bezierPath]; | |
130 | + [path moveToPoint:NSMakePoint(frame.size.width - self.offset - self.slideOffset, 0)]; | |
131 | + [path lineToPoint:NSMakePoint(frame.size.width - self.offset, frame.size.height)]; | |
132 | + | |
133 | + path.lineWidth = 2; | |
134 | + | |
135 | + return path; | |
136 | +} | |
137 | +- (NSBezierPath *)levelFiveBezierPath | |
138 | +{ | |
139 | + NSRect frame = NSInsetRect(self.frame, 0, 1); | |
140 | + frame.origin = NSZeroPoint; | |
141 | + NSBezierPath *path = [NSBezierPath bezierPath]; | |
142 | + [path moveToPoint:NSMakePoint(frame.size.width - self.offset - self.slideOffset, 0)]; | |
143 | + [path lineToPoint:NSMakePoint(frame.size.width - self.offset, frame.size.height)]; | |
144 | + | |
145 | + [path moveToPoint:NSMakePoint(frame.size.width - self.offset - self.slideOffset - self.padding, 0)]; | |
146 | + [path lineToPoint:NSMakePoint(frame.size.width - self.offset - self.padding, frame.size.height)]; | |
147 | + | |
148 | + path.lineWidth = 2; | |
149 | + | |
150 | + return path; | |
151 | +} | |
152 | +- (NSBezierPath *)levelSixBezierPath | |
153 | +{ | |
154 | + NSRect frame = NSInsetRect(self.frame, 0, 1); | |
155 | + frame.origin = NSZeroPoint; | |
156 | + NSBezierPath *path = [NSBezierPath bezierPath]; | |
157 | + [path moveToPoint:NSMakePoint(frame.size.width - self.offset - self.slideOffset, 0)]; | |
158 | + [path lineToPoint:NSMakePoint(frame.size.width - self.offset, frame.size.height)]; | |
159 | + | |
160 | + [path moveToPoint:NSMakePoint(frame.size.width - self.offset - self.slideOffset - self.padding, 0)]; | |
161 | + [path lineToPoint:NSMakePoint(frame.size.width - self.offset - self.padding, frame.size.height)]; | |
162 | + | |
163 | + [path moveToPoint:NSMakePoint(frame.size.width - self.offset - self.slideOffset - self.padding * 2, 0)]; | |
164 | + [path lineToPoint:NSMakePoint(frame.size.width - self.offset - self.padding * 2, frame.size.height)]; | |
165 | + | |
166 | + path.lineWidth = 2; | |
167 | + | |
168 | + return path; | |
169 | +} | |
170 | +- (NSBezierPath *)levelSevenBezierPath | |
171 | +{ | |
172 | + NSRect frame = NSInsetRect(self.frame, 0, 1); | |
173 | + frame.origin = NSZeroPoint; | |
174 | + NSBezierPath *path = [NSBezierPath bezierPath]; | |
175 | + [path moveToPoint:NSMakePoint(frame.size.width - self.offset - 4.0, 0)]; | |
176 | + [path lineToPoint:NSMakePoint(frame.size.width - self.offset, frame.size.height * 0.5)]; | |
177 | + [path lineToPoint:NSMakePoint(frame.size.width - self.offset - 4.0, frame.size.height)]; | |
178 | + | |
179 | + [path moveToPoint:NSMakePoint(frame.size.width - self.offset - 4.0 - self.padding, 0)]; | |
180 | + [path lineToPoint:NSMakePoint(frame.size.width - self.offset - self.padding, frame.size.height * 0.5)]; | |
181 | + [path lineToPoint:NSMakePoint(frame.size.width - self.offset - 4.0 - self.padding, frame.size.height)]; | |
182 | + | |
183 | + path.lineWidth = 2; | |
184 | + | |
185 | + return path; | |
186 | +} | |
187 | + | |
188 | + | |
189 | +- (NSBezierPath *)bezierPathForALevel:(NSNumber *)level | |
190 | +{ | |
191 | + NSBezierPath *path = nil; | |
192 | + switch (level.integerValue) { | |
193 | + case 0: | |
194 | + return nil; | |
195 | + case 1: | |
196 | + path = [self levelOneBezierPath]; | |
197 | + break; | |
198 | + case 2: | |
199 | + path = [self levelTwoBezierPath]; | |
200 | + break; | |
201 | + case 3: | |
202 | + path = [self levelThreeBezierPath]; | |
203 | + break; | |
204 | + case 4: | |
205 | + path = [self levelFourBezierPath]; | |
206 | + break; | |
207 | + case 5: | |
208 | + path = [self levelFiveBezierPath]; | |
209 | + break; | |
210 | + case 6: | |
211 | + path = [self levelSixBezierPath]; | |
212 | + break; | |
213 | + case 7: | |
214 | + path = [self levelSevenBezierPath]; | |
215 | + break; | |
216 | + default: | |
217 | + return nil; | |
218 | + } | |
219 | + | |
220 | + return path; | |
221 | +} | |
222 | + | |
223 | +- (NSColor *)colorForALevel:(NSNumber *)level | |
224 | +{ | |
225 | + switch (level.integerValue) { | |
226 | + case 0: | |
227 | + return nil; | |
228 | + case 1: | |
229 | + case 2: | |
230 | + case 3: | |
231 | + return [NSColor colorWithCalibratedRed:0.332 green:0.543 blue:0.646 alpha:1.000]; | |
232 | + case 4: | |
233 | + case 5: | |
234 | + case 6: | |
235 | + case 7: | |
236 | + return [NSColor colorWithCalibratedRed:200/255.0 green:140/255.0 blue:0.000 alpha:1.000]; | |
237 | + default: | |
238 | + return nil; | |
239 | + } | |
240 | + return nil; | |
241 | +} | |
242 | +- (NSShadow *)shadowForALevel:(NSNumber *)level | |
243 | +{ | |
244 | + NSShadow *shadow = [NSShadow new]; | |
245 | + switch (level.integerValue) { | |
246 | + case 0: | |
247 | + return nil; | |
248 | + case 1: | |
249 | + case 2: | |
250 | + case 3: | |
251 | + shadow.shadowColor = [NSColor colorWithCalibratedRed:0.152 green:0.501 blue:0.853 alpha:1.000]; | |
252 | + shadow.shadowBlurRadius = 4; | |
253 | + break; | |
254 | + case 4: | |
255 | + case 5: | |
256 | + case 6: | |
257 | + case 7: | |
258 | + shadow.shadowColor = [NSColor yellowColor]; | |
259 | + shadow.shadowBlurRadius = 3; | |
260 | + break; | |
261 | + default: | |
262 | + return nil; | |
263 | + } | |
264 | + return shadow; | |
265 | +} | |
266 | + | |
267 | +- (NSNumber *)slotItemAlv | |
268 | +{ | |
269 | + if(!self.slotItemID) return nil; | |
270 | + | |
271 | + if(!self.slotItem) { | |
272 | + [self fetchSlotItem]; | |
273 | + } | |
274 | + | |
275 | + return self.slotItem.alv; | |
276 | +} | |
277 | + | |
278 | + | |
279 | +#pragma mark - Level | |
280 | + | |
281 | +- (NSColor *)levelColor | |
282 | +{ | |
283 | + return [NSColor colorWithCalibratedRed:0.135 green:0.522 blue:0.619 alpha:1.000]; | |
284 | +} | |
285 | +- (void)drawLevel | |
286 | +{ | |
287 | + NSNumber *level = self.slotItemLevel; | |
288 | + if(!level || [level isKindOfClass:[NSNull class]]) return; | |
289 | + if(level.integerValue == 0) return; | |
290 | + | |
291 | + NSString *string = [NSString stringWithFormat:@"★+%@", level]; | |
292 | + if(level.integerValue == 10) { | |
293 | + string = @"max"; | |
294 | + } | |
295 | + NSFont *font = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]; | |
296 | + | |
297 | + NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:string | |
298 | + attributes:@{ | |
299 | + NSFontAttributeName : font, | |
300 | + NSForegroundColorAttributeName : [self levelColor], | |
301 | + } | |
302 | + ]; | |
303 | + NSRect boundingRect = [attrString boundingRectWithSize:self.frame.size options:0]; | |
304 | + NSRect rect = self.frame; | |
305 | + rect.origin.x = self.frame.size.width - boundingRect.size.width * 2; | |
306 | + rect.origin.y = 0; | |
307 | + rect.size.width = boundingRect.size.width * 2; | |
308 | + | |
309 | + | |
310 | + NSGradient *gradient = [[NSGradient alloc] initWithColorsAndLocations: | |
311 | + [NSColor colorWithCalibratedWhite:1 alpha:0.000], 0.0, | |
312 | + sContentColor, 0.5, | |
313 | + sContentColor, 1.0, | |
314 | + nil]; | |
315 | + | |
316 | + [gradient drawInRect:rect angle:0.0]; | |
317 | + | |
318 | + rect = self.frame; | |
319 | + rect.origin.x = self.frame.size.width - boundingRect.size.width - 1.0; | |
320 | + rect.origin.y = 0; | |
321 | + | |
322 | + | |
323 | + [attrString drawInRect:rect]; | |
324 | +} | |
325 | + | |
326 | +- (NSNumber *)slotItemLevel | |
327 | +{ | |
328 | + if(!self.slotItemID) return nil; | |
329 | + | |
330 | + if(!self.slotItem) { | |
331 | + [self fetchSlotItem]; | |
332 | + } | |
333 | + | |
334 | + return self.slotItem.level; | |
335 | +} | |
336 | + | |
337 | +#pragma mark - property | |
338 | + | |
339 | +- (void)fetchSlotItem | |
340 | +{ | |
341 | + if(!self.slotItemID || [self.slotItemID isEqual:@(-1)]) { | |
342 | + self.slotItem = nil; | |
343 | + return; | |
344 | + } | |
345 | + | |
346 | + HMServerDataStore *store = [HMServerDataStore defaultManager]; | |
347 | + NSError *error = nil; | |
348 | + NSArray *array = [store objectsWithEntityName:@"SlotItem" | |
349 | + error:&error | |
350 | + predicateFormat:@"id = %@", self.slotItemID]; | |
351 | + if(error) { | |
352 | + NSLog(@"SlotItem is invalid -> %@", error); | |
353 | + self.slotItem = nil; | |
354 | + return; | |
355 | + } | |
356 | + if(array.count == 0) { | |
357 | + NSLog(@"Can not find slotItem for %@", self.slotItemID); | |
358 | + self.slotItem = nil; | |
359 | + return; | |
360 | + } | |
361 | + | |
362 | + [self.slotItem removeObserver:self forKeyPath:@"level"]; | |
363 | + [self.slotItem removeObserver:self forKeyPath:@"alv"]; | |
364 | + | |
365 | + self.slotItem = array[0]; | |
366 | + | |
367 | + [self.slotItem addObserver:self forKeyPath:@"level" options:0 context:NULL]; | |
368 | + [self.slotItem addObserver:self forKeyPath:@"alv" options:0 context:NULL]; | |
369 | +} | |
370 | +- (void)setSlotItemID:(NSNumber *)slotItemID | |
371 | +{ | |
372 | + if([self.slotItemID isEqual:slotItemID]) return; | |
373 | + self.slotItem = nil; | |
374 | + _slotItemID = slotItemID; | |
375 | + [self fetchSlotItem]; | |
376 | + self.needsDisplay = YES; | |
377 | +} | |
378 | + | |
379 | +- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context | |
380 | +{ | |
381 | + if([keyPath isEqualToString:@"level"] || [keyPath isEqualToString:@"alv"]) { | |
382 | + self.needsDisplay = YES; | |
383 | + return; | |
384 | + } | |
385 | + | |
386 | + [super observeValueForKeyPath:keyPath ofObject:object change:change context:context]; | |
387 | +} | |
388 | + | |
389 | +@end |