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 {
24 guard let v = DamageType(rawValue: newValue) else { return Logger.shared.log("Can not set damageType") }
26 if innerDamageType != v { needsDisplay = true }
32 var controlSize: NSControl.ControlSize = .regular
33 private var innerDamageType: DamageType = .none
34 private var color: NSColor? {
36 switch innerDamageType {
41 return #colorLiteral(red: 1.000, green: 0.956, blue: 0.012, alpha: 0.5)
44 return NSColor.orange.withAlphaComponent(0.5)
47 return NSColor.red.withAlphaComponent(0.5)
51 private var borderColor: NSColor? {
53 switch innerDamageType {
58 return NSColor.orange.withAlphaComponent(0.5)
61 return NSColor.orange.withAlphaComponent(0.9)
64 return NSColor.red.withAlphaComponent(0.9)
68 private var path: Polygon? {
79 private var pathForRegular: Polygon? {
81 let height = bounds.height
83 switch innerDamageType {
89 .move(to: NSPoint(x: 35.0, y: height - 2.0))
90 .line(to: NSPoint(x: 0.0, y: height - 2.0))
91 .line(to: NSPoint(x: 0.0, y: height - 35.0))
96 .move(to: NSPoint(x: 50.0, y: height - 2.0))
97 .line(to: NSPoint(x: 25.0, y: height - 2.0))
98 .line(to: NSPoint(x: 0.0, y: height - 25.0))
99 .line(to: NSPoint(x: 0.0, y: height - 50.0))
104 .move(to: NSPoint(x: 60.0, y: height - 2.0))
105 .line(to: NSPoint(x: 53.0, y: height - 2.0))
106 .line(to: NSPoint(x: 0.0, y: height - 53.0))
107 .line(to: NSPoint(x: 0.0, y: height - 60.0))
109 .move(to: NSPoint(x: 47.0, y: height - 2.0))
110 .line(to: NSPoint(x: 23.0, y: height - 2.0))
111 .line(to: NSPoint(x: 0.0, y: height - 23.0))
112 .line(to: NSPoint(x: 0.0, y: height - 47.0))
117 private var pathForSmall: Polygon? {
119 let height = bounds.height
121 switch innerDamageType {
127 .move(to: NSPoint(x: 35.0, y: height - 2.0))
128 .line(to: NSPoint(x: 0.0, y: height - 2.0))
129 .line(to: NSPoint(x: 0.0, y: height - 35.0))
134 .move(to: NSPoint(x: 50.0, y: height - 2.0))
135 .line(to: NSPoint(x: 25.0, y: height - 2.0))
136 .line(to: NSPoint(x: 0.0, y: height - 25.0))
137 .line(to: NSPoint(x: 0.0, y: height - 50.0))
142 .move(to: NSPoint(x: 55.0, y: height - 2.0))
143 .line(to: NSPoint(x: 48.0, y: height - 2.0))
144 .line(to: NSPoint(x: 0.0, y: height - 48.0))
145 .line(to: NSPoint(x: 0.0, y: height - 55.0))
147 .move(to: NSPoint(x: 42.0, y: height - 2.0))
148 .line(to: NSPoint(x: 20.0, y: height - 2.0))
149 .line(to: NSPoint(x: 0.0, y: height - 20.0))
150 .line(to: NSPoint(x: 0.0, y: height - 42.0))
155 override func draw(_ dirtyRect: NSRect) {
157 super.draw(dirtyRect)
160 borderColor?.setStroke()