2 // AirPlanInfoView.swift
5 // Created by Hori,Masaki on 2017/04/29.
6 // Copyright © 2017年 Hori,Masaki. All rights reserved.
11 final class AirPlanInfoView: NSTableCellView {
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))
27 @IBOutlet private var planNameVew: SlotItemLevelView!
28 @IBOutlet private var conditionBox: NSBox!
29 @IBOutlet private var needSupplyField: NSTextField!
31 @objc dynamic var condition: Int = 1 {
35 guard let cond = Condition(rawValue: condition) else {
40 conditionBox.fillColor = conditionColor(cond)
41 conditionBox.borderColor = borderColor(cond)
45 @objc dynamic var slotId: NSNumber? {
47 didSet { planNameVew.slotItemID = slotId }
50 @objc dynamic var maxCount: Int = 0 {
52 didSet { needSupplyField.isHidden = !needSupply() }
55 @objc dynamic var count: Int = 0 {
57 didSet { needSupplyField.isHidden = !needSupply() }
60 private func conditionColor(_ cond: Condition) -> NSColor {
64 case .normal: return ColorSet.current[.airPlanInforViewNormal]
66 case .tired: return ColorSet.current[.airPlanInforViewTired]
68 case .bad: return ColorSet.current[.airPlanInforViewBad]
73 private func borderColor(_ cond: Condition) -> NSColor {
77 case .normal: return ColorSet.current[.airPlanInforViewBoarderNormal]
79 case .tired: return ColorSet.current[.airPlanInforViewBoarderTired]
81 case .bad: return ColorSet.current[.airPlanInforViewBoarderBad]
86 private func needSupply() -> Bool {
88 return (maxCount - count != 0)
91 required init?(coder: NSCoder) {
93 super.init(coder: coder)
98 unbind(AirPlanInfoView.conditionBindingName)
99 unbind(AirPlanInfoView.slotIDBindingName)
100 unbind(AirPlanInfoView.maxCountBindingName)
101 unbind(AirPlanInfoView.countBindingName)
104 override func awakeFromNib() {
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")