OSDN Git Service

コード整形
[kcd/KCD.git] / KCD / AirPlanInfoView.swift
1 //
2 //  AirPlanInfoView.swift
3 //  KCD
4 //
5 //  Created by Hori,Masaki on 2017/04/29.
6 //  Copyright © 2017年 Hori,Masaki. All rights reserved.
7 //
8
9 import Cocoa
10
11 final class AirPlanInfoView: NSTableCellView {
12     
13     enum Condition: Int {
14         
15         case normal = 1
16         case tired = 2
17         case bad = 3
18     }
19     
20     @IBOutlet var planNameVew: SlotItemLevelView!
21     @IBOutlet var conditionBox: NSBox!
22     @IBOutlet var needSupplyField: NSTextField!
23     
24     dynamic var condition: Int = 1 {
25         
26         didSet {
27             guard let cond = Condition(rawValue: condition)
28                 else { return }
29             
30             conditionBox.fillColor = conditionColor(cond)
31             conditionBox.borderColor = borderColor(cond)
32         }
33     }
34     
35     dynamic var slotId: NSNumber? {
36         
37         didSet { planNameVew.slotItemID = slotId }
38     }
39     
40     dynamic var maxCount: Int = 0 {
41         
42         didSet { needSupplyField.isHidden = !needSupply() }
43     }
44     
45     dynamic var count: Int = 0 {
46         
47         didSet { needSupplyField.isHidden = !needSupply() }
48     }
49     
50     private func conditionColor(_ cond: Condition) -> NSColor {
51         
52         switch cond {
53         case .normal: return .clear
54         case .tired: return #colorLiteral(red: 1, green: 0.7233425379, blue: 0.1258574128, alpha: 0.8239436619)
55         case .bad: return #colorLiteral(red: 0.7320367694, green: 0.07731548697, blue: 0.06799335033, alpha: 1)
56         }
57     }
58     
59     private func borderColor(_ cond: Condition) -> NSColor {
60         
61         switch cond {
62         case .normal: return .clear
63         case .tired: return #colorLiteral(red: 0.458858192, green: 0.3335277438, blue: 0.07979661971, alpha: 1)
64         case .bad: return #colorLiteral(red: 0.5462518334, green: 0.04599834234, blue: 0.04913448542, alpha: 1)
65         }
66     }
67     
68     private func needSupply() -> Bool {
69         
70         return (maxCount - count != 0)
71     }
72     
73     required init?(coder: NSCoder) {
74         
75         super.init(coder: coder)
76     }
77     
78     deinit {
79         
80         unbind(#keyPath(AirPlanInfoView.condition))
81         unbind(#keyPath(AirPlanInfoView.slotId))
82         unbind(#keyPath(AirPlanInfoView.maxCount))
83         unbind(#keyPath(AirPlanInfoView.count))
84     }
85     
86     override func awakeFromNib() {
87         
88         bind(#keyPath(AirPlanInfoView.condition),
89              to: self,
90              withKeyPath: "objectValue.cond")
91         bind(#keyPath(AirPlanInfoView.slotId),
92              to: self,
93              withKeyPath: "objectValue.slotid")
94         bind(#keyPath(AirPlanInfoView.maxCount),
95              to: self,
96              withKeyPath: "objectValue.max_count")
97         bind(#keyPath(AirPlanInfoView.count),
98              to: self,
99              withKeyPath: "objectValue.count")
100     }
101 }