OSDN Git Service

不要となっていたプロパティを削除
[kcd/KCD.git] / KCD / DamageView.swift
1 //
2 //  DamageView.swift
3 //  KCD
4 //
5 //  Created by Hori,Masaki on 2017/01/01.
6 //  Copyright © 2017年 Hori,Masaki. All rights reserved.
7 //
8
9 import Cocoa
10
11 enum DamageType: Int {
12     
13     case none = 0
14     case slightly
15     case modest
16     case badly
17 }
18
19 final class DamageView: NSView {
20     
21     @objc dynamic var damageType: Int = 0 {
22         
23         willSet {
24             
25             guard let v = DamageType(rawValue: newValue) else {
26                 
27                 Logger.shared.log("Can not set damageType")
28                 
29                 return
30             }
31             
32             if innerDamageType != v {
33                 
34                 needsDisplay = true
35             }
36             
37             innerDamageType = v
38         }
39     }
40     
41     var controlSize: NSControl.ControlSize = .regular
42     private var innerDamageType: DamageType = .none
43     private var color: NSColor? {
44         
45         switch innerDamageType {
46             
47         case .none: return nil
48             
49         case .slightly: return ColorSetManager.current[.damageViewInnerSlightly]
50             
51         case .modest: return ColorSetManager.current[.damageViewInnerModest]
52             
53         case .badly: return ColorSetManager.current[.damageViewInnerBadly]
54             
55         }
56     }
57     
58     private var borderColor: NSColor? {
59                 
60         switch innerDamageType {
61             
62         case .none: return nil
63             
64         case .slightly: return ColorSetManager.current[.damageViewBoarderSlightly]
65             
66         case .modest: return ColorSetManager.current[.damageViewBoarderModest]
67             
68         case .badly: return ColorSetManager.current[.damageViewBoarderBadly]
69             
70         }
71     }
72     
73     private var path: Polygon? {
74         
75         switch controlSize {
76             
77         case .regular:
78             
79             return pathForRegular
80             
81         case .small, .mini:
82             
83             return pathForSmall
84             
85         }
86     }
87     
88     private var pathForRegular: Polygon? {
89         
90         let height = bounds.height
91         
92         switch innerDamageType {
93             
94         case .none:
95             
96             return nil
97             
98         case .slightly:
99             
100             return Polygon()
101                 .move(to: NSPoint(x: 35.0, y: height - 2.0))
102                 .line(to: NSPoint(x: 0.0, y: height - 2.0))
103                 .line(to: NSPoint(x: 0.0, y: height - 35.0))
104                 .close()
105             
106         case .modest:
107             
108             return Polygon()
109                 .move(to: NSPoint(x: 50.0, y: height - 2.0))
110                 .line(to: NSPoint(x: 25.0, y: height - 2.0))
111                 .line(to: NSPoint(x: 0.0, y: height - 25.0))
112                 .line(to: NSPoint(x: 0.0, y: height - 50.0))
113                 .close()
114             
115         case .badly:
116             
117             return Polygon()
118                 .move(to: NSPoint(x: 60.0, y: height - 2.0))
119                 .line(to: NSPoint(x: 53.0, y: height - 2.0))
120                 .line(to: NSPoint(x: 0.0, y: height - 53.0))
121                 .line(to: NSPoint(x: 0.0, y: height - 60.0))
122                 .close()
123                 .move(to: NSPoint(x: 47.0, y: height - 2.0))
124                 .line(to: NSPoint(x: 23.0, y: height - 2.0))
125                 .line(to: NSPoint(x: 0.0, y: height - 23.0))
126                 .line(to: NSPoint(x: 0.0, y: height - 47.0))
127                 .close()
128             
129         }
130     }
131     
132     private var pathForSmall: Polygon? {
133         
134         let height = bounds.height
135         
136         switch innerDamageType {
137             
138         case .none:
139             
140             return nil
141             
142         case .slightly:
143             
144             return Polygon()
145                 .move(to: NSPoint(x: 35.0, y: height - 2.0))
146                 .line(to: NSPoint(x: 0.0, y: height - 2.0))
147                 .line(to: NSPoint(x: 0.0, y: height - 35.0))
148                 .close()
149             
150         case .modest:
151             
152             return Polygon()
153                 .move(to: NSPoint(x: 50.0, y: height - 2.0))
154                 .line(to: NSPoint(x: 25.0, y: height - 2.0))
155                 .line(to: NSPoint(x: 0.0, y: height - 25.0))
156                 .line(to: NSPoint(x: 0.0, y: height - 50.0))
157                 .close()
158             
159         case .badly:
160             
161             return Polygon()
162                 .move(to: NSPoint(x: 55.0, y: height - 2.0))
163                 .line(to: NSPoint(x: 48.0, y: height - 2.0))
164                 .line(to: NSPoint(x: 0.0, y: height - 48.0))
165                 .line(to: NSPoint(x: 0.0, y: height - 55.0))
166                 .close()
167                 .move(to: NSPoint(x: 42.0, y: height - 2.0))
168                 .line(to: NSPoint(x: 20.0, y: height - 2.0))
169                 .line(to: NSPoint(x: 0.0, y: height - 20.0))
170                 .line(to: NSPoint(x: 0.0, y: height - 42.0))
171                 .close()
172             
173         }
174     }
175     
176     override func draw(_ dirtyRect: NSRect) {
177         
178         super.draw(dirtyRect)
179         
180         color?.setFill()
181         borderColor?.setStroke()
182         path?.fill()
183         path?.stroke()
184     }
185 }