OSDN Git Service

基地航空隊ウインドウに階級、改修度、疲労度、補充の必要性を表示するようにした
[kcd/KCD.git] / KCD / AirPlanInfoView.swift
diff --git a/KCD/AirPlanInfoView.swift b/KCD/AirPlanInfoView.swift
new file mode 100644 (file)
index 0000000..238a046
--- /dev/null
@@ -0,0 +1,82 @@
+//
+//  AirPlanInfoView.swift
+//  KCD
+//
+//  Created by Hori,Masaki on 2017/04/29.
+//  Copyright © 2017年 Hori,Masaki. All rights reserved.
+//
+
+import Cocoa
+
+class AirPlanInfoView: NSTableCellView {
+    
+    enum Condition: Int {
+        case normal = 1
+        case tired = 2
+        case bad = 3
+    }
+    
+    @IBOutlet var planNameVew: SlotItemLevelView!
+    @IBOutlet var conditionBox: NSBox!
+    @IBOutlet var needSupplyField: NSTextField!
+    
+    dynamic var condition: Int = 1 {
+        didSet {
+            guard let cond = Condition(rawValue: condition)
+                else { return }
+            conditionBox.fillColor = conditionColor(cond)
+            conditionBox.borderColor = borderColor(cond)
+        }
+    }
+    dynamic var slotId: NSNumber? {
+        didSet { planNameVew.slotItemID = slotId }
+    }
+    dynamic var maxCount: Int = 0 {
+        didSet { needSupplyField.isHidden = !needSupply() }
+    }
+    dynamic var count: Int = 0 {
+        didSet { needSupplyField.isHidden = !needSupply() }
+    }
+    private func conditionColor(_ cond: Condition) -> NSColor {
+        switch cond {
+        case .normal: return .clear
+        case .tired: return #colorLiteral(red: 1, green: 0.7233425379, blue: 0.1258574128, alpha: 0.8239436619)
+        case .bad: return #colorLiteral(red: 0.7320367694, green: 0.07731548697, blue: 0.06799335033, alpha: 1)
+        }
+    }
+    private func borderColor(_ cond: Condition) -> NSColor {
+        switch cond {
+        case .normal: return .clear
+        case .tired: return #colorLiteral(red: 0.458858192, green: 0.3335277438, blue: 0.07979661971, alpha: 1)
+        case .bad: return #colorLiteral(red: 0.5462518334, green: 0.04599834234, blue: 0.04913448542, alpha: 1)
+        }
+    }
+    private func needSupply() -> Bool {
+        return (maxCount - count != 0)
+    }
+    
+    required init?(coder: NSCoder) {
+        super.init(coder: coder)
+    }
+    deinit {
+        unbind(#keyPath(AirPlanInfoView.condition))
+        unbind(#keyPath(AirPlanInfoView.slotId))
+        unbind(#keyPath(AirPlanInfoView.maxCount))
+        unbind(#keyPath(AirPlanInfoView.count))
+    }
+    
+    override func awakeFromNib() {
+        bind(#keyPath(AirPlanInfoView.condition),
+             to: self,
+             withKeyPath: "objectValue.cond")
+        bind(#keyPath(AirPlanInfoView.slotId),
+             to: self,
+             withKeyPath: "objectValue.slotid")
+        bind(#keyPath(AirPlanInfoView.maxCount),
+             to: self,
+             withKeyPath: "objectValue.max_count")
+        bind(#keyPath(AirPlanInfoView.count),
+             to: self,
+             withKeyPath: "objectValue.count")
+    }
+}