OSDN Git Service

Doutaku を 1.0 にアップデート
[kcd/KCD.git] / KCD / DamageView.swift
index c9632b1..5f5e076 100644 (file)
@@ -21,12 +21,18 @@ final class DamageView: NSView {
     @objc dynamic var damageType: Int = 0 {
         
         willSet {
+            
             guard let v = DamageType(rawValue: newValue) else {
-                print("Can not set damageType")
+                
+                Logger.shared.log("Can not set damageType")
+                
                 return
             }
             
-            if innerDamageType != v { needsDisplay = true }
+            if innerDamageType != v {
+                
+                needsDisplay = true
+            }
             
             innerDamageType = v
         }
@@ -37,135 +43,133 @@ final class DamageView: NSView {
     private var color: NSColor? {
         
         switch innerDamageType {
-        case .none:
-            return nil
             
-        case .slightly:
-            return #colorLiteral(red: 1.000, green: 0.956, blue: 0.012, alpha: 0.5)
+        case .none: return nil
             
-        case .modest:
-            return NSColor.orange.withAlphaComponent(0.5)
+        case .slightly: return ColorSetManager.current[.damageViewInnerSlightly]
+            
+        case .modest: return ColorSetManager.current[.damageViewInnerModest]
+            
+        case .badly: return ColorSetManager.current[.damageViewInnerBadly]
             
-        case .badly:
-            return NSColor.red.withAlphaComponent(0.5)
         }
     }
     
     private var borderColor: NSColor? {
-        
+                
         switch innerDamageType {
-        case .none:
-            return nil
             
-        case .slightly:
-            return NSColor.orange.withAlphaComponent(0.5)
+        case .none: return nil
             
-        case .modest:
-            return NSColor.orange.withAlphaComponent(0.9)
+        case .slightly: return ColorSetManager.current[.damageViewBoarderSlightly]
+            
+        case .modest: return ColorSetManager.current[.damageViewBoarderModest]
+            
+        case .badly: return ColorSetManager.current[.damageViewBoarderBadly]
             
-        case .badly:
-            return NSColor.red.withAlphaComponent(0.9)
         }
     }
     
-    private var path: NSBezierPath? {
+    private var path: Polygon? {
         
         switch controlSize {
+            
         case .regular:
+            
             return pathForRegular
             
         case .small, .mini:
+            
             return pathForSmall
+            
         }
     }
     
-    private var pathForRegular: NSBezierPath? {
+    private var pathForRegular: Polygon? {
         
         let height = bounds.height
         
         switch innerDamageType {
+            
         case .none:
+            
             return nil
             
         case .slightly:
-            return polygon(points:
-                [
-                    NSPoint(x: 35.0, y: height - 2.0),
-                    NSPoint(x: 0.0, y: height - 2.0),
-                    NSPoint(x: 0.0, y: height - 35.0)
-                ])
+            
+            return Polygon()
+                .move(to: NSPoint(x: 35.0, y: height - 2.0))
+                .line(to: NSPoint(x: 0.0, y: height - 2.0))
+                .line(to: NSPoint(x: 0.0, y: height - 35.0))
+                .close()
             
         case .modest:
-            return polygon(points:
-                [
-                    NSPoint(x: 50.0, y: height - 2.0),
-                    NSPoint(x: 25.0, y: height - 2.0),
-                    NSPoint(x: 0.0, y: height - 25.0),
-                    NSPoint(x: 0.0, y: height - 50.0)
-                ])
+            
+            return Polygon()
+                .move(to: NSPoint(x: 50.0, y: height - 2.0))
+                .line(to: NSPoint(x: 25.0, y: height - 2.0))
+                .line(to: NSPoint(x: 0.0, y: height - 25.0))
+                .line(to: NSPoint(x: 0.0, y: height - 50.0))
+                .close()
             
         case .badly:
-            let p = polygon(points:
-                [
-                    NSPoint(x: 60.0, y: height - 2.0),
-                    NSPoint(x: 53.0, y: height - 2.0),
-                    NSPoint(x: 0.0, y: height - 53.0),
-                    NSPoint(x: 0.0, y: height - 60.0)
-                ])
-            polygon(points:
-                [
-                    NSPoint(x: 47.0, y: height - 2.0),
-                    NSPoint(x: 23.0, y: height - 2.0),
-                    NSPoint(x: 0.0, y: height - 23.0),
-                    NSPoint(x: 0.0, y: height - 47.0)
-                ])
-                .map { p?.append($0) }
-            return p
+            
+            return Polygon()
+                .move(to: NSPoint(x: 60.0, y: height - 2.0))
+                .line(to: NSPoint(x: 53.0, y: height - 2.0))
+                .line(to: NSPoint(x: 0.0, y: height - 53.0))
+                .line(to: NSPoint(x: 0.0, y: height - 60.0))
+                .close()
+                .move(to: NSPoint(x: 47.0, y: height - 2.0))
+                .line(to: NSPoint(x: 23.0, y: height - 2.0))
+                .line(to: NSPoint(x: 0.0, y: height - 23.0))
+                .line(to: NSPoint(x: 0.0, y: height - 47.0))
+                .close()
+            
         }
     }
     
-    private var pathForSmall: NSBezierPath? {
+    private var pathForSmall: Polygon? {
         
         let height = bounds.height
         
         switch innerDamageType {
+            
         case .none:
+            
             return nil
             
         case .slightly:
-            return polygon(points:
-                [
-                    NSPoint(x: 35.0, y: height - 2.0),
-                    NSPoint(x: 0.0, y: height - 2.0),
-                    NSPoint(x: 0.0, y: height - 35.0)
-                ])
+            
+            return Polygon()
+                .move(to: NSPoint(x: 35.0, y: height - 2.0))
+                .line(to: NSPoint(x: 0.0, y: height - 2.0))
+                .line(to: NSPoint(x: 0.0, y: height - 35.0))
+                .close()
             
         case .modest:
-            return polygon(points:
-                [
-                    NSPoint(x: 50.0, y: height - 2.0),
-                    NSPoint(x: 25.0, y: height - 2.0),
-                    NSPoint(x: 0.0, y: height - 25.0),
-                    NSPoint(x: 0.0, y: height - 50.0)
-                ])
+            
+            return Polygon()
+                .move(to: NSPoint(x: 50.0, y: height - 2.0))
+                .line(to: NSPoint(x: 25.0, y: height - 2.0))
+                .line(to: NSPoint(x: 0.0, y: height - 25.0))
+                .line(to: NSPoint(x: 0.0, y: height - 50.0))
+                .close()
             
         case .badly:
-            let p = polygon(points:
-                [
-                    NSPoint(x: 55.0, y: height - 2.0),
-                    NSPoint(x: 48.0, y: height - 2.0),
-                    NSPoint(x: 0.0, y: height - 48.0),
-                    NSPoint(x: 0.0, y: height - 55.0)
-                ])
-            polygon(points:
-                [
-                    NSPoint(x: 42.0, y: height - 2.0),
-                    NSPoint(x: 20.0, y: height - 2.0),
-                    NSPoint(x: 0.0, y: height - 20.0),
-                    NSPoint(x: 0.0, y: height - 42.0)
-                ])
-                .map { p?.append($0) }
-            return p
+            
+            return Polygon()
+                .move(to: NSPoint(x: 55.0, y: height - 2.0))
+                .line(to: NSPoint(x: 48.0, y: height - 2.0))
+                .line(to: NSPoint(x: 0.0, y: height - 48.0))
+                .line(to: NSPoint(x: 0.0, y: height - 55.0))
+                .close()
+                .move(to: NSPoint(x: 42.0, y: height - 2.0))
+                .line(to: NSPoint(x: 20.0, y: height - 2.0))
+                .line(to: NSPoint(x: 0.0, y: height - 20.0))
+                .line(to: NSPoint(x: 0.0, y: height - 42.0))
+                .close()
+            
         }
     }