5 // Created by Hori,Masaki on 2017/01/01.
6 // Copyright © 2017年 Hori,Masaki. All rights reserved.
11 enum DamageType: Int {
18 class DamageView: NSView {
19 dynamic var damageType: Int = 0 {
21 guard let v = DamageType(rawValue: newValue) else {
22 self.print("Can not set damageType")
25 if innerDamageType != v { needsDisplay = true }
29 var controlSize: NSControlSize = .regular
30 private var innerDamageType: DamageType = .none
31 private var color: NSColor? {
32 switch innerDamageType {
36 return #colorLiteral(red: 1.000, green: 0.956, blue: 0.012, alpha: 0.5)
38 return NSColor.orange.withAlphaComponent(0.5)
40 return NSColor.red.withAlphaComponent(0.5)
43 private var borderColor: NSColor? {
44 switch innerDamageType {
48 return NSColor.orange.withAlphaComponent(0.5)
50 return NSColor.orange.withAlphaComponent(0.9)
52 return NSColor.red.withAlphaComponent(0.9)
55 private var path: NSBezierPath? {
63 private var pathForRegular: NSBezierPath? {
64 let height = bounds.height
65 switch innerDamageType {
71 .appended { NSPoint(x: 35.0, y: height - 2.0) }
72 .appended { NSPoint(x: 0.0, y: height - 2.0) }
73 .appended { NSPoint(x: 0.0, y: height - 35.0) }
78 .appended { NSPoint(x: 50.0, y: height - 2.0) }
79 .appended { NSPoint(x: 25.0, y: height - 2.0) }
80 .appended { NSPoint(x: 0.0, y: height - 25.0) }
81 .appended { NSPoint(x: 0.0, y: height - 50.0) }
86 .appended { NSPoint(x: 60.0, y: height - 2.0) }
87 .appended { NSPoint(x: 53.0, y: height - 2.0) }
88 .appended { NSPoint(x: 0.0, y: height - 53.0) }
89 .appended { NSPoint(x: 0.0, y: height - 60.0) }
93 .appended { NSPoint(x: 47.0, y: height - 2.0) }
94 .appended { NSPoint(x: 23.0, y: height - 2.0) }
95 .appended { NSPoint(x: 0.0, y: height - 23.0) }
96 .appended { NSPoint(x: 0.0, y: height - 47.0) }
98 .map { p?.append($0) }
102 private var pathForSmall: NSBezierPath? {
103 let height = bounds.height
104 switch innerDamageType {
110 .appended { NSPoint(x: 35.0, y: height - 2.0) }
111 .appended { NSPoint(x: 0.0, y: height - 2.0) }
112 .appended { NSPoint(x: 0.0, y: height - 35.0) }
117 .appended { NSPoint(x: 50.0, y: height - 2.0) }
118 .appended { NSPoint(x: 25.0, y: height - 2.0) }
119 .appended { NSPoint(x: 0.0, y: height - 25.0) }
120 .appended { NSPoint(x: 0.0, y: height - 50.0) }
125 .appended { NSPoint(x: 55.0, y: height - 2.0) }
126 .appended { NSPoint(x: 48.0, y: height - 2.0) }
127 .appended { NSPoint(x: 0.0, y: height - 48.0) }
128 .appended { NSPoint(x: 0.0, y: height - 55.0) }
132 .appended { NSPoint(x: 42.0, y: height - 2.0) }
133 .appended { NSPoint(x: 20.0, y: height - 2.0) }
134 .appended { NSPoint(x: 0.0, y: height - 20.0) }
135 .appended { NSPoint(x: 0.0, y: height - 42.0) }
137 .map { p?.append($0) }
142 override func draw(_ dirtyRect: NSRect) {
143 super.draw(dirtyRect)
146 borderColor?.setStroke()