2 // ShipDetailViewController.swift
5 // Created by Hori,Masaki on 2016/12/25.
6 // Copyright © 2016年 Hori,Masaki. All rights reserved.
11 enum ShipDetailViewType {
17 private func nibNameFor(_ type: ShipDetailViewType) -> String {
20 return "ShipDetailViewController"
22 return "MediumShipViewController"
24 return "MediumShipViewController"
28 class ShipDetailViewController: NSViewController {
29 let type: ShipDetailViewType
30 let managedObjectContext = ServerDataStore.default.managedObjectContext
32 init?(type: ShipDetailViewType) {
34 super.init(nibName: nibNameFor(type), bundle: nil)
38 .addObserver(forName: .DidUpdateGuardEscape,
40 queue: nil) { [unowned self] _ in
41 self.guardEscaped = self.ship?.guardEscaped ?? false
44 required init?(coder: NSCoder) {
45 fatalError("not implemented")
48 NotificationCenter.default.removeObserver(self)
49 damageView.unbind("damageType")
50 supply.unbind("shipStatus")
51 [slot00Field, slot01Field, slot02Field, slot03Field]
52 .forEach { $0?.unbind("slotItemID") }
56 @IBOutlet weak var supply: SuppliesView!
57 @IBOutlet weak var guardEscapedView: GuardEscapedView!
58 @IBOutlet weak var damageView: DamageView!
59 @IBOutlet weak var slot00Field: NSTextField!
60 @IBOutlet weak var slot01Field: NSTextField!
61 @IBOutlet weak var slot02Field: NSTextField!
62 @IBOutlet weak var slot03Field: NSTextField!
63 @IBOutlet var shipController: NSObjectController!
65 dynamic var guardEscaped: Bool = false {
67 guardEscapedView.isHidden = !guardEscaped
70 dynamic var ship: KCShipObject? {
72 return shipController.content as? KCShipObject
75 shipController.fetchPredicate = NSPredicate(format: "id = %ld", newValue?.id ?? 0)
79 override func viewDidLoad() {
82 damageView.setFrameOrigin(.zero)
83 view.addSubview(damageView)
84 damageView.bind("damageType", to: shipController, withKeyPath: "selection.status", options: nil)
86 supply.bind("shipStatus", to: shipController, withKeyPath: "selection.self", options: nil)
88 guardEscapedView.setFrameOrigin(.zero)
89 view.addSubview(guardEscapedView)
91 case .medium, .minimum:
92 guardEscapedView.controlSize = .mini
96 let fields = [slot00Field, slot01Field, slot02Field, slot03Field]
97 let keypath = ["selection.slot_0", "selection.slot_1", "selection.slot_2", "selection.slot_3"]
98 zip(fields, keypath).forEach {
99 $0.0?.bind("slotItemID", to: shipController, withKeyPath: $0.1, options: nil)