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 class AirPlanInfoView: NSTableCellView {
12     
13     enum Condition: Int {
14         case normal = 1
15         case tired = 2
16         case bad = 3
17     }
18     
19     @IBOutlet var planNameVew: SlotItemLevelView!
20     @IBOutlet var conditionBox: NSBox!
21     @IBOutlet var needSupplyField: NSTextField!
22     
23     dynamic var condition: Int = 1 {
24         didSet {
25             guard let cond = Condition(rawValue: condition)
26                 else { return }
27             conditionBox.fillColor = conditionColor(cond)
28             conditionBox.borderColor = borderColor(cond)
29         }
30     }
31     dynamic var slotId: NSNumber? {
32         didSet { planNameVew.slotItemID = slotId }
33     }
34     dynamic var maxCount: Int = 0 {
35         didSet { needSupplyField.isHidden = !needSupply() }
36     }
37     dynamic var count: Int = 0 {
38         didSet { needSupplyField.isHidden = !needSupply() }
39     }
40     private func conditionColor(_ cond: Condition) -> NSColor {
41         switch cond {
42         case .normal: return .clear
43         case .tired: return #colorLiteral(red: 1, green: 0.7233425379, blue: 0.1258574128, alpha: 0.8239436619)
44         case .bad: return #colorLiteral(red: 0.7320367694, green: 0.07731548697, blue: 0.06799335033, alpha: 1)
45         }
46     }
47     private func borderColor(_ cond: Condition) -> NSColor {
48         switch cond {
49         case .normal: return .clear
50         case .tired: return #colorLiteral(red: 0.458858192, green: 0.3335277438, blue: 0.07979661971, alpha: 1)
51         case .bad: return #colorLiteral(red: 0.5462518334, green: 0.04599834234, blue: 0.04913448542, alpha: 1)
52         }
53     }
54     private func needSupply() -> Bool {
55         return (maxCount - count != 0)
56     }
57     
58     required init?(coder: NSCoder) {
59         super.init(coder: coder)
60     }
61     deinit {
62         unbind(#keyPath(AirPlanInfoView.condition))
63         unbind(#keyPath(AirPlanInfoView.slotId))
64         unbind(#keyPath(AirPlanInfoView.maxCount))
65         unbind(#keyPath(AirPlanInfoView.count))
66     }
67     
68     override func awakeFromNib() {
69         bind(#keyPath(AirPlanInfoView.condition),
70              to: self,
71              withKeyPath: "objectValue.cond")
72         bind(#keyPath(AirPlanInfoView.slotId),
73              to: self,
74              withKeyPath: "objectValue.slotid")
75         bind(#keyPath(AirPlanInfoView.maxCount),
76              to: self,
77              withKeyPath: "objectValue.max_count")
78         bind(#keyPath(AirPlanInfoView.count),
79              to: self,
80              withKeyPath: "objectValue.count")
81     }
82 }