5 // Created by Hori,Masaki on 2017/01/01.
6 // Copyright © 2017年 Hori,Masaki. All rights reserved.
11 enum DamageType: Int {
19 final class DamageView: NSView {
21 @objc dynamic var damageType: Int = 0 {
25 guard let v = DamageType(rawValue: newValue) else {
27 Logger.shared.log("Can not set damageType")
32 if innerDamageType != v {
41 var controlSize: NSControl.ControlSize = .regular
42 private var innerDamageType: DamageType = .none
43 private var color: NSColor? {
45 switch innerDamageType {
47 case .none: return nil
49 case .slightly: return ColorSetManager.current[.damageViewInnerSlightly]
51 case .modest: return ColorSetManager.current[.damageViewInnerModest]
53 case .badly: return ColorSetManager.current[.damageViewInnerBadly]
58 private var borderColor: NSColor? {
60 switch innerDamageType {
62 case .none: return nil
64 case .slightly: return ColorSetManager.current[.damageViewBoarderSlightly]
66 case .modest: return ColorSetManager.current[.damageViewBoarderModest]
68 case .badly: return ColorSetManager.current[.damageViewBoarderBadly]
73 private var path: Polygon? {
88 private var pathForRegular: Polygon? {
90 let height = bounds.height
92 switch innerDamageType {
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))
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))
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))
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))
132 private var pathForSmall: Polygon? {
134 let height = bounds.height
136 switch innerDamageType {
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))
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))
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))
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))
176 override func draw(_ dirtyRect: NSRect) {
178 super.draw(dirtyRect)
181 borderColor?.setStroke()