2 // InformationTabViewController.swift
5 // Created by Hori,Masaki on 2018/02/04.
6 // Copyright © 2018年 Hori,Masaki. All rights reserved.
12 enum ShipTabType: Int {
22 case aircraftCarrier = 4
31 private let shipTypeCategories: [[Int]] = [
34 [3, 4], // leght cruiser
35 [5, 6], // heavy crusier
36 [7, 11, 16, 18], // aircraft carrier
37 [8, 9, 10, 12], // battle ship
38 [13, 14], // submarine
39 [1, 15, 17, 19, 20, 21, 22]
42 func shipTypePredicte(for type: ShipTabType) -> NSPredicate? {
50 case .destroyer, .lightCruiser, .heavyCruiser,
51 .aircraftCarrier, .battleShip, .submarine:
53 return NSPredicate(#keyPath(Ship.master_ship.stype.id), valuesIn: shipTypeCategories[type.rawValue])
56 let omitTypes = shipTypeCategories
59 .filter { $0.offset != 0 && $0.offset != 7 }
60 .flatMap { $0.element }
62 return .not(NSPredicate(#keyPath(Ship.master_ship.stype.id), valuesIn: omitTypes))
67 class InformationTabViewController: NSViewController {
69 @objc private(set) dynamic var hasShipTypeSelector: Bool = false
70 @objc private(set) dynamic var selectedShipType: ShipTabType = .all {
73 guard case 0..<tabViewItemViewControllers.count = selectionIndex else {
77 tabViewItemViewControllers[selectionIndex].selectedShipType = selectedShipType
80 @objc dynamic var selectionIndex: Int = 0 {
84 unbind(NSBindingName("selectedShipType"))
89 guard case 0..<tabViewItemViewControllers.count = selectionIndex else {
93 hasShipTypeSelector = tabViewItemViewControllers[selectionIndex].hasShipTypeSelector
95 bind(NSBindingName("selectedShipType"),
96 to: tabViewItemViewControllers[selectionIndex],
97 withKeyPath: #keyPath(MainTabVIewItemViewController.selectedShipType))
99 selectionDidChangeHandler?()
103 @IBOutlet private var informations: NSTabView!
105 var selectionDidChangeHandler: (() -> Void)?
107 private var tabViewItemViewControllers: [MainTabVIewItemViewController] = []
109 override var nibName: NSNib.Name {
111 return .nibName(instanceOf: self)
114 override func viewDidLoad() {
118 tabViewItemViewControllers = [
119 DocksViewController(),
120 ShipViewController(),
121 PowerUpSupportViewController(),
122 StrengthenListViewController(),
123 RepairListViewController()
125 tabViewItemViewControllers.enumerated().forEach {
128 let item = informations.tabViewItem(at: $0.offset)
129 item.viewController = $0.element