OSDN Git Service

HMSuppliesCellクラスをSwiftで書き換え
authormasakih <masakih@users.sourceforge.jp>
Mon, 29 Dec 2014 13:55:13 +0000 (22:55 +0900)
committermasakih <masakih@users.sourceforge.jp>
Mon, 29 Dec 2014 13:55:13 +0000 (22:55 +0900)
KCD.xcodeproj/project.pbxproj
KCD/HMSuppliesCell.h [deleted file]
KCD/HMSuppliesCell.m [deleted file]
KCD/HMSuppliesCell.swift [new file with mode: 0644]
KCD/KCD-Bridging-Header.h

index 4a15aaf..2ae5d34 100644 (file)
@@ -74,7 +74,6 @@
                F4AA0607192E3B6200844688 /* HMMapStartCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = F4AA0606192E3B6200844688 /* HMMapStartCommand.m */; };
                F4AA060D1930E69200844688 /* HMMidnightBattleCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = F4AA060C1930E69200844688 /* HMMidnightBattleCommand.m */; };
                F4AA06101931869E00844688 /* HMBattleResultCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = F4AA060F1931869E00844688 /* HMBattleResultCommand.m */; };
-               F4B1E30819C73B6A00805879 /* HMSuppliesCell.m in Sources */ = {isa = PBXBuildFile; fileRef = F4B1E30419C73B6A00805879 /* HMSuppliesCell.m */; };
                F4B1E30C19D1C06900805879 /* HMHokyuChargeCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = F4B1E30B19D1C06900805879 /* HMHokyuChargeCommand.m */; };
                F4B1E30F19D1C9C400805879 /* HMApplySuppliesCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = F4B1E30E19D1C9C400805879 /* HMApplySuppliesCommand.m */; };
                F4B2A0901A1F9C2100D2EF12 /* HMExternalBrowserWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = F4B2A08E1A1F9C2100D2EF12 /* HMExternalBrowserWindowController.xib */; };
                F4E7802B18DC3A820011BC4C /* HMLocalDataStore.m in Sources */ = {isa = PBXBuildFile; fileRef = F4E7802A18DC3A820011BC4C /* HMLocalDataStore.m */; };
                F4E7802E18DC3AF00011BC4C /* LocalData.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = F4E7802C18DC3AF00011BC4C /* LocalData.xcdatamodeld */; };
                F4E802071A50F8A100016781 /* HMSuppliesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4E802061A50F8A100016781 /* HMSuppliesView.swift */; };
+               F4E802091A511F5900016781 /* HMSuppliesCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4E802081A511F5900016781 /* HMSuppliesCell.swift */; };
                F4FCFD44191F4C1D000640A1 /* HMKenzoMarkCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = F4FCFD43191F4C1D000640A1 /* HMKenzoMarkCommand.m */; };
                F4FDF2411A3D50420033E0AD /* HMShipMasterDetailWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = F4FDF23F1A3D50420033E0AD /* HMShipMasterDetailWindowController.m */; };
                F4FDF2421A3D50420033E0AD /* HMShipMasterDetailWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = F4FDF2401A3D50420033E0AD /* HMShipMasterDetailWindowController.xib */; };
                F4AA060C1930E69200844688 /* HMMidnightBattleCommand.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMMidnightBattleCommand.m; sourceTree = "<group>"; };
                F4AA060E1931869E00844688 /* HMBattleResultCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMBattleResultCommand.h; sourceTree = "<group>"; };
                F4AA060F1931869E00844688 /* HMBattleResultCommand.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMBattleResultCommand.m; sourceTree = "<group>"; };
-               F4B1E30319C73B6A00805879 /* HMSuppliesCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMSuppliesCell.h; sourceTree = "<group>"; };
-               F4B1E30419C73B6A00805879 /* HMSuppliesCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMSuppliesCell.m; sourceTree = "<group>"; };
                F4B1E30A19D1C06900805879 /* HMHokyuChargeCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMHokyuChargeCommand.h; sourceTree = "<group>"; };
                F4B1E30B19D1C06900805879 /* HMHokyuChargeCommand.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMHokyuChargeCommand.m; sourceTree = "<group>"; };
                F4B1E30D19D1C9C400805879 /* HMApplySuppliesCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMApplySuppliesCommand.h; sourceTree = "<group>"; };
                F4E7802A18DC3A820011BC4C /* HMLocalDataStore.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMLocalDataStore.m; sourceTree = "<group>"; };
                F4E7802D18DC3AF00011BC4C /* LocalData.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = LocalData.xcdatamodel; sourceTree = "<group>"; };
                F4E802061A50F8A100016781 /* HMSuppliesView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMSuppliesView.swift; sourceTree = "<group>"; };
+               F4E802081A511F5900016781 /* HMSuppliesCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMSuppliesCell.swift; sourceTree = "<group>"; };
                F4FCFD42191F4C1D000640A1 /* HMKenzoMarkCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMKenzoMarkCommand.h; sourceTree = "<group>"; };
                F4FCFD43191F4C1D000640A1 /* HMKenzoMarkCommand.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMKenzoMarkCommand.m; sourceTree = "<group>"; };
                F4FDF23E1A3D50420033E0AD /* HMShipMasterDetailWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMShipMasterDetailWindowController.h; sourceTree = "<group>"; };
                                F4A3AD8D19BB220000FDBF80 /* HMMaskInfomation.m */,
                                F4551BE31A48379F00BB0235 /* HMDeckViewController.swift */,
                                F4B2D03518F83CC800542742 /* HMDeckViewController.xib */,
-                               F4B1E30319C73B6A00805879 /* HMSuppliesCell.h */,
-                               F4B1E30419C73B6A00805879 /* HMSuppliesCell.m */,
+                               F4E802081A511F5900016781 /* HMSuppliesCell.swift */,
                                F4E802061A50F8A100016781 /* HMSuppliesView.swift */,
                                F4E1BC091A4FA4E20089A82D /* HMStrokeTextFieldCell.swift */,
                                F4B30CF11A458AF2008E3D79 /* HMSlotItemWindowController.swift */,
                                F4B414FB18B1FB6C00468DAF /* HMMasterMapCellCommand.m in Sources */,
                                F4C118FA18A67B1C005D5B25 /* CacheStoragePolicy.m in Sources */,
                                F4B3DC2118DECF570011B4FC /* HMTSVSupport.m in Sources */,
-                               F4B1E30819C73B6A00805879 /* HMSuppliesCell.m in Sources */,
                                F4A3AD8E19BB220000FDBF80 /* HMMaskInfomation.m in Sources */,
                                F4551BF41A49843500BB0235 /* HMPreferencePanelController.swift in Sources */,
                                F4E7802E18DC3AF00011BC4C /* LocalData.xcdatamodeld in Sources */,
                                F4B30CFC1A4687E7008E3D79 /* HMIgnoreZeroTransformer.swift in Sources */,
                                F43F3D4C1A34AC8000D6DAF7 /* HMKCMasterShipObject.m in Sources */,
                                F4268031194D1B1A00B2C27F /* HMChangeHenseiCommand.m in Sources */,
+                               F4E802091A511F5900016781 /* HMSuppliesCell.swift in Sources */,
                                F4551BE61A48711D00BB0235 /* HMScreenshotInformation.swift in Sources */,
                                F494DC6D18CC054800AE97E4 /* HMNyukyoDockStatus.m in Sources */,
                                F43BA4A1197BE22200CFF788 /* HMDestroyShipCommand.m in Sources */,
diff --git a/KCD/HMSuppliesCell.h b/KCD/HMSuppliesCell.h
deleted file mode 100644 (file)
index 89bb018..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-//
-//  HMSuppliesCell.h
-//  UITest
-//
-//  Created by Hori,Masaki on 2014/07/08.
-//  Copyright (c) 2014年 Hori,Masaki. All rights reserved.
-//
-
-#import <Cocoa/Cocoa.h>
-
-#import "HMKCShipObject.h"
-
-@interface HMSuppliesCell : NSCell
-
-@property (nonatomic, strong) HMKCShipObject *shipStatus;
-
-@end
diff --git a/KCD/HMSuppliesCell.m b/KCD/HMSuppliesCell.m
deleted file mode 100644 (file)
index c35b31f..0000000
+++ /dev/null
@@ -1,149 +0,0 @@
-//
-//  HMSuppliesCell.m
-//  UITest
-//
-//  Created by Hori,Masaki on 2014/07/08.
-//  Copyright (c) 2014年 Hori,Masaki. All rights reserved.
-//
-
-#import "HMSuppliesCell.h"
-
-#import "HMKCShipObject+Extensions.h"
-
-@implementation HMSuppliesCell
-
-- (NSColor *)redColor
-{
-       return [NSColor colorWithCalibratedWhite:0.79 alpha:1.000];
-}
-- (NSColor *)orangeColor
-{
-       return [NSColor colorWithCalibratedWhite:0.7 alpha:1.000];
-}
-- (NSColor *)yellowColor
-{
-       return [NSColor colorWithCalibratedWhite:0.55 alpha:1.000];
-}
-- (NSColor *)greenColor
-{
-       return [NSColor colorWithCalibratedWhite:0.39 alpha:1.000];
-}
-
-- (void)drawBackgroundWithFrame:(NSRect)cellFrame
-{
-       NSBezierPath *path = [NSBezierPath bezierPathWithRect:cellFrame];
-       [[NSColor colorWithCalibratedWhite:0.632 alpha:1.000] set];
-       [path fill];
-}
-- (void)drawFuelInteriorWithFrame:(NSRect)cellFrame
-{
-       NSRect cellRect;
-       cellRect.origin = NSZeroPoint;
-       cellRect.size.height = cellFrame.size.height;
-       cellRect.size.width = (cellFrame.size.width - numberOfCell - 1) / numberOfCell;
-       
-       cellRect.size.height = (cellRect.size.height - 3) / 2;
-       cellRect.origin.y = cellRect.size.height + 2;
-       
-       for(NSInteger i = 0; i < self.numberOfFuelColoredCell; i++) {
-               cellRect.origin.x = 1 + i + cellRect.size.width * i;
-               NSBezierPath *path = [NSBezierPath bezierPathWithRect:cellRect];
-               
-               [self.fuelStatusColor set];
-               [path fill];
-       }
-       for(NSInteger i = self.numberOfFuelColoredCell; i < 10; i++) {
-               cellRect.origin.x = 1 + i + cellRect.size.width * i;
-               NSBezierPath *path = [NSBezierPath bezierPathWithRect:cellRect];
-               
-               [[NSColor colorWithCalibratedWhite:0.948 alpha:1.000] set];
-               [path fill];
-       }
-}
-- (void)drawBullInteriorWithFrame:(NSRect)cellFrame
-{
-       NSRect cellRect;
-       cellRect.origin = NSZeroPoint;
-       cellRect.size.height = cellFrame.size.height;
-       cellRect.size.width = (cellFrame.size.width - numberOfCell - 1) / numberOfCell;
-       
-       cellRect.size.height = (cellRect.size.height - 3) / 2;
-       cellRect.origin.y = 1;
-       
-       for(NSInteger i = 0; i < self.numberOgBullColoredCell; i++) {
-               cellRect.origin.x = 1 + i + cellRect.size.width * i;
-               NSBezierPath *path = [NSBezierPath bezierPathWithRect:cellRect];
-               
-               [self.bullStatusColor set];
-               [path fill];
-       }
-       for(NSInteger i = self.numberOgBullColoredCell; i < 10; i++) {
-               cellRect.origin.x = 1 + i + cellRect.size.width * i;
-               NSBezierPath *path = [NSBezierPath bezierPathWithRect:cellRect];
-               
-               [[NSColor colorWithCalibratedWhite:0.948 alpha:1.000] set];
-               [path fill];
-       }
-}
-const NSInteger numberOfCell = 10;
-
-- (NSColor *)statusColorWithValue:(NSNumber *)value maxValue:(NSNumber *)maxValue
-{
-       NSColor *color = self.greenColor;
-       
-       switch([self numberOfColoredCellWithValue:value maxValue:maxValue]) {
-               case 1:
-               case 2:
-               case 3:
-                       color = self.redColor;
-                       break;
-               case 4:
-               case 5:
-               case 6:
-               case 7:
-                       color = self.orangeColor;
-                       break;
-               case 8:
-               case 9:
-                       color = self.yellowColor;
-                       break;
-       }
-       return color;
-}
-- (NSInteger)numberOfColoredCellWithValue:(NSNumber *)value maxValue:(NSNumber *)maxValue
-{
-       if(!value || [value isEqual:[NSNull null]]) return 0;
-       
-       CGFloat maxFuel = [maxValue integerValue];
-       CGFloat fuel = [value integerValue];
-       if(fuel >= maxFuel) return 10;
-       
-       CGFloat result = ceil(fuel / maxFuel * numberOfCell);
-       if(result > 9) return 9;
-       return result;
-}
-
-- (NSInteger)numberOfFuelColoredCell
-{
-       return [self numberOfColoredCellWithValue:self.shipStatus.fuel maxValue:self.shipStatus.maxFuel];
-}
-- (NSColor *)fuelStatusColor
-{
-       return [self statusColorWithValue:self.shipStatus.fuel maxValue:self.shipStatus.maxFuel];
-}
-- (NSInteger)numberOgBullColoredCell
-{
-       return [self numberOfColoredCellWithValue:self.shipStatus.bull maxValue:self.shipStatus.maxBull];
-}
-- (NSColor *)bullStatusColor
-{
-       return [self statusColorWithValue:self.shipStatus.bull maxValue:self.shipStatus.maxBull];
-}
-
-- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
-{
-       [self drawBackgroundWithFrame:cellFrame];
-       [self drawFuelInteriorWithFrame:cellFrame];
-       [self drawBullInteriorWithFrame:cellFrame];
-}
-@end
diff --git a/KCD/HMSuppliesCell.swift b/KCD/HMSuppliesCell.swift
new file mode 100644 (file)
index 0000000..66eb725
--- /dev/null
@@ -0,0 +1,108 @@
+//
+//  HMSuppliesCell.swift
+//  KCD
+//
+//  Created by Hori,Masaki on 2014/12/29.
+//  Copyright (c) 2014年 Hori,Masaki. All rights reserved.
+//
+
+import Cocoa
+
+class HMSuppliesCell: NSCell
+{
+       var redColor: NSColor {
+               return NSColor(calibratedWhite: 0.790, alpha: 1.000)
+       }
+       var orangeColor: NSColor {
+               return NSColor(calibratedWhite: 0.700, alpha: 1.000)
+       }
+       var yellowColor: NSColor {
+               return NSColor(calibratedWhite: 0.550, alpha: 1.000)
+       }
+       var greenColor: NSColor {
+               return NSColor(calibratedWhite: 0.390, alpha: 1.000)
+       }
+       var shipStatus: HMKCShipObject?
+       let numberOfCell = 10
+       func numberOfColoredCell(value: NSNumber?, maxValue: NSNumber?) -> Int {
+               if value == nil { return 0 }
+               if value!.integerValue >= maxValue!.integerValue { return 10 }
+               let result: Double = ceil(value!.doubleValue / maxValue!.doubleValue * Double(numberOfCell))
+               if result > 9 { return 9 }
+               return Int(result)
+       }
+       var numberOfFuelColoredCell: Int {
+               return numberOfColoredCell(shipStatus?.fuel, maxValue: shipStatus?.maxFuel)
+       }
+       var numberOfBullColoredCell: Int {
+               return numberOfColoredCell(shipStatus?.bull, maxValue: shipStatus?.maxBull)
+       }
+       func statusColor(value: NSNumber?, maxValue: NSNumber?) -> NSColor {
+               var color = greenColor
+               switch numberOfColoredCell(value, maxValue: maxValue) {
+               case 1, 2, 3:
+                       color = redColor
+               case 4, 5, 6, 7:
+                       color = orangeColor
+               case 8, 9:
+                       color = yellowColor
+               case 10:
+                       color = greenColor
+               default:
+                       println(__FUNCTION__, " unknown type")
+               }
+               return color
+       }
+       var fuelStatusColor: NSColor {
+               return statusColor(shipStatus?.fuel, maxValue: shipStatus?.maxFuel)
+       }
+       var bullStatusColor: NSColor {
+               return statusColor(shipStatus?.bull, maxValue: shipStatus?.maxBull)
+       }
+       
+       func drawBackground(frame: NSRect) {
+               NSColor(calibratedWhite: 0.632, alpha: 1.000).set()
+               NSBezierPath(rect: frame).fill()
+       }
+       func drawFuelInterior(frame: NSRect) {
+               var cellRect = NSRect()
+               cellRect.origin = NSZeroPoint
+               cellRect.size.width = (frame.size.width - CGFloat(numberOfCell) - 1.0) / CGFloat(numberOfCell)
+               cellRect.size.height = (frame.size.height - 3.0) / 2.0
+               cellRect.origin.y = cellRect.size.height + 2
+               
+               fuelStatusColor.set()
+               for i in 0..<numberOfFuelColoredCell {
+                       cellRect.origin.x = CGFloat(1 + i) + cellRect.size.width * CGFloat(i)
+                       NSBezierPath(rect: cellRect).fill()
+               }
+               NSColor(calibratedWhite: 0.948, alpha: 1.000).set()
+               for i in numberOfFuelColoredCell..<10 {
+                       cellRect.origin.x = CGFloat(1 + i) + cellRect.size.width * CGFloat(i)
+                       NSBezierPath(rect: cellRect).fill()
+               }
+       }
+       func drawBullInterior(frame: NSRect) {
+               var cellRect = NSRect()
+               cellRect.origin = NSZeroPoint
+               cellRect.size.width = (frame.size.width - CGFloat(numberOfCell) - 1.0) / CGFloat(numberOfCell)
+               cellRect.size.height = (frame.size.height - 3.0) / 2.0
+               cellRect.origin.y = 1
+               
+               bullStatusColor.set()
+               for i in 0..<numberOfBullColoredCell {
+                       cellRect.origin.x = CGFloat(1 + i) + cellRect.size.width * CGFloat(i)
+                       NSBezierPath(rect: cellRect).fill()
+               }
+               NSColor(calibratedWhite: 0.948, alpha: 1.000).set()
+               for i in numberOfBullColoredCell..<10 {
+                       cellRect.origin.x = CGFloat(1 + i) + cellRect.size.width * CGFloat(i)
+                       NSBezierPath(rect: cellRect).fill()
+               }
+       }
+       override func drawInteriorWithFrame(cellFrame: NSRect, inView controlView: NSView) {
+               drawBackground(cellFrame)
+               drawFuelInterior(cellFrame)
+               drawBullInterior(cellFrame)
+       }
+}
index 1ddf70e..694e9bc 100644 (file)
@@ -9,12 +9,13 @@
 #import "HMLocalDataStore.h"
 #import "HMTemporaryDataStore.h"
 
+#import "HMKCShipObject+Extensions.h"
+
 #import "HMMissionStatus.h"
 #import "HMNyukyoDockStatus.h"
 #import "HMKenzoDockStatus.h"
 #import "HMFleetInformation.h"
 
-#import "HMSuppliesCell.h"
 #import "HMMaskSelectView.h"