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         
17         case tired = 2
18         
19         case bad = 3
20     }
21     
22     static let conditionBindingName = NSBindingName(#keyPath(AirPlanInfoView.condition))
23     static let slotIDBindingName = NSBindingName(#keyPath(AirPlanInfoView.slotId))
24     static let maxCountBindingName = NSBindingName(#keyPath(AirPlanInfoView.maxCount))
25     static let countBindingName = NSBindingName(#keyPath(AirPlanInfoView.count))
26     
27     @IBOutlet private var planNameVew: SlotItemLevelView!
28     @IBOutlet private var conditionBox: NSBox!
29     @IBOutlet private var needSupplyField: NSTextField!
30     
31     @objc dynamic var condition: Int = 1 {
32         
33         didSet {
34             
35             guard let cond = Condition(rawValue: condition) else {
36                 
37                 return
38             }
39             
40             conditionBox.fillColor = conditionColor(cond)
41             conditionBox.borderColor = borderColor(cond)
42         }
43     }
44     
45     @objc dynamic var slotId: NSNumber? {
46         
47         didSet { planNameVew.slotItemID = slotId }
48     }
49     
50     @objc dynamic var maxCount: Int = 0 {
51         
52         didSet { needSupplyField.isHidden = !needSupply() }
53     }
54     
55     @objc dynamic var count: Int = 0 {
56         
57         didSet { needSupplyField.isHidden = !needSupply() }
58     }
59     
60     private func conditionColor(_ cond: Condition) -> NSColor {
61         
62         switch cond {
63             
64         case .normal: return ColorSet.current[.airPlanInforViewNormal]
65             
66         case .tired: return ColorSet.current[.airPlanInforViewTired]
67             
68         case .bad: return ColorSet.current[.airPlanInforViewBad]
69             
70         }
71     }
72     
73     private func borderColor(_ cond: Condition) -> NSColor {
74         
75         switch cond {
76             
77         case .normal: return ColorSet.current[.airPlanInforViewBoarderNormal]
78             
79         case .tired: return ColorSet.current[.airPlanInforViewBoarderTired]
80             
81         case .bad: return ColorSet.current[.airPlanInforViewBoarderBad]
82             
83         }
84     }
85     
86     private func needSupply() -> Bool {
87         
88         return (maxCount - count != 0)
89     }
90     
91     required init?(coder: NSCoder) {
92         
93         super.init(coder: coder)
94     }
95     
96     deinit {
97         
98         unbind(AirPlanInfoView.conditionBindingName)
99         unbind(AirPlanInfoView.slotIDBindingName)
100         unbind(AirPlanInfoView.maxCountBindingName)
101         unbind(AirPlanInfoView.countBindingName)
102     }
103     
104     override func awakeFromNib() {
105         
106         bind(AirPlanInfoView.conditionBindingName, to: self, withKeyPath: "objectValue.cond")
107         bind(AirPlanInfoView.slotIDBindingName, to: self, withKeyPath: "objectValue.slotid")
108         bind(AirPlanInfoView.maxCountBindingName, to: self, withKeyPath: "objectValue.max_count")
109         bind(AirPlanInfoView.countBindingName, to: self, withKeyPath: "objectValue.count")
110     }
111 }