2 // AirPlanInfoView.swift
5 // Created by Hori,Masaki on 2017/04/29.
6 // Copyright © 2017年 Hori,Masaki. All rights reserved.
11 class AirPlanInfoView: NSTableCellView {
19 @IBOutlet var planNameVew: SlotItemLevelView!
20 @IBOutlet var conditionBox: NSBox!
21 @IBOutlet var needSupplyField: NSTextField!
23 dynamic var condition: Int = 1 {
25 guard let cond = Condition(rawValue: condition)
27 conditionBox.fillColor = conditionColor(cond)
28 conditionBox.borderColor = borderColor(cond)
31 dynamic var slotId: NSNumber? {
32 didSet { planNameVew.slotItemID = slotId }
34 dynamic var maxCount: Int = 0 {
35 didSet { needSupplyField.isHidden = !needSupply() }
37 dynamic var count: Int = 0 {
38 didSet { needSupplyField.isHidden = !needSupply() }
40 private func conditionColor(_ cond: Condition) -> NSColor {
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)
47 private func borderColor(_ cond: Condition) -> NSColor {
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)
54 private func needSupply() -> Bool {
55 return (maxCount - count != 0)
58 required init?(coder: NSCoder) {
59 super.init(coder: coder)
62 unbind(#keyPath(AirPlanInfoView.condition))
63 unbind(#keyPath(AirPlanInfoView.slotId))
64 unbind(#keyPath(AirPlanInfoView.maxCount))
65 unbind(#keyPath(AirPlanInfoView.count))
68 override func awakeFromNib() {
69 bind(#keyPath(AirPlanInfoView.condition),
71 withKeyPath: "objectValue.cond")
72 bind(#keyPath(AirPlanInfoView.slotId),
74 withKeyPath: "objectValue.slotid")
75 bind(#keyPath(AirPlanInfoView.maxCount),
77 withKeyPath: "objectValue.max_count")
78 bind(#keyPath(AirPlanInfoView.count),
80 withKeyPath: "objectValue.count")