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 dynamic var condition: Int = 1 {
27 guard let cond = Condition(rawValue: condition)
30 conditionBox.fillColor = conditionColor(cond)
31 conditionBox.borderColor = borderColor(cond)
35 dynamic var slotId: NSNumber? {
37 didSet { planNameVew.slotItemID = slotId }
40 dynamic var maxCount: Int = 0 {
42 didSet { needSupplyField.isHidden = !needSupply() }
45 dynamic var count: Int = 0 {
47 didSet { needSupplyField.isHidden = !needSupply() }
50 private func conditionColor(_ cond: Condition) -> NSColor {
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)
59 private func borderColor(_ cond: Condition) -> NSColor {
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)
68 private func needSupply() -> Bool {
70 return (maxCount - count != 0)
73 required init?(coder: NSCoder) {
75 super.init(coder: coder)
80 unbind(#keyPath(AirPlanInfoView.condition))
81 unbind(#keyPath(AirPlanInfoView.slotId))
82 unbind(#keyPath(AirPlanInfoView.maxCount))
83 unbind(#keyPath(AirPlanInfoView.count))
86 override func awakeFromNib() {
88 bind(#keyPath(AirPlanInfoView.condition),
90 withKeyPath: "objectValue.cond")
91 bind(#keyPath(AirPlanInfoView.slotId),
93 withKeyPath: "objectValue.slotid")
94 bind(#keyPath(AirPlanInfoView.maxCount),
96 withKeyPath: "objectValue.max_count")
97 bind(#keyPath(AirPlanInfoView.count),
99 withKeyPath: "objectValue.count")