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 {
20 @IBOutlet var planNameVew: SlotItemLevelView!
21 @IBOutlet var conditionBox: NSBox!
22 @IBOutlet var needSupplyField: NSTextField!
24 @objc dynamic var condition: Int = 1 {
27 guard let cond = Condition(rawValue: condition) else { return }
29 conditionBox.fillColor = conditionColor(cond)
30 conditionBox.borderColor = borderColor(cond)
34 @objc dynamic var slotId: NSNumber? {
36 didSet { planNameVew.slotItemID = slotId }
39 @objc dynamic var maxCount: Int = 0 {
41 didSet { needSupplyField.isHidden = !needSupply() }
44 @objc dynamic var count: Int = 0 {
46 didSet { needSupplyField.isHidden = !needSupply() }
49 private func conditionColor(_ cond: Condition) -> NSColor {
52 case .normal: return .clear
53 case .tired: return #colorLiteral(red: 1, green: 0.7233425379, blue: 0.1258574128, alpha: 0.8239436619)
54 case .bad: return #colorLiteral(red: 0.7320367694, green: 0.07731548697, blue: 0.06799335033, alpha: 1)
58 private func borderColor(_ cond: Condition) -> NSColor {
61 case .normal: return .clear
62 case .tired: return #colorLiteral(red: 0.458858192, green: 0.3335277438, blue: 0.07979661971, alpha: 1)
63 case .bad: return #colorLiteral(red: 0.5462518334, green: 0.04599834234, blue: 0.04913448542, alpha: 1)
67 private func needSupply() -> Bool {
69 return (maxCount - count != 0)
72 required init?(coder: NSCoder) {
74 super.init(coder: coder)
79 unbind(NSBindingName(#keyPath(AirPlanInfoView.condition)))
80 unbind(NSBindingName(#keyPath(AirPlanInfoView.slotId)))
81 unbind(NSBindingName(#keyPath(AirPlanInfoView.maxCount)))
82 unbind(NSBindingName(#keyPath(AirPlanInfoView.count)))
85 override func awakeFromNib() {
87 bind(NSBindingName(#keyPath(AirPlanInfoView.condition)),
89 withKeyPath: "objectValue.cond")
90 bind(NSBindingName(#keyPath(AirPlanInfoView.slotId)),
92 withKeyPath: "objectValue.slotid")
93 bind(NSBindingName(#keyPath(AirPlanInfoView.maxCount)),
95 withKeyPath: "objectValue.max_count")
96 bind(NSBindingName(#keyPath(AirPlanInfoView.count)),
98 withKeyPath: "objectValue.count")