2 // CombileViewController.swift
5 // Created by Hori,Masaki on 2016/12/25.
6 // Copyright © 2016年 Hori,Masaki. All rights reserved.
11 final class CombileViewController: NSViewController {
13 let fleet1 = FleetViewController(viewType: .miniVierticalType)!
14 let fleet2 = FleetViewController(viewType: .miniVierticalType)!
16 @IBOutlet weak var placeholder1: NSView!
17 @IBOutlet weak var placeholder2: NSView!
19 @objc dynamic var fleet1TPValue: Int = 0 {
21 willChangeValue(forKey: #keyPath(TPValue))
22 willChangeValue(forKey: #keyPath(BRankTPValue))
25 didChangeValue(forKey: #keyPath(TPValue))
26 didChangeValue(forKey: #keyPath(BRankTPValue))
29 @objc dynamic var fleet2TPValue: Int = 0 {
31 willChangeValue(forKey: #keyPath(TPValue))
32 willChangeValue(forKey: #keyPath(BRankTPValue))
35 didChangeValue(forKey: #keyPath(TPValue))
36 didChangeValue(forKey: #keyPath(BRankTPValue))
39 @objc dynamic var TPValue: Int { return fleet1TPValue + fleet2TPValue }
40 @objc dynamic var BRankTPValue: Int { return Int(floor(Double(TPValue) * 0.7)) }
42 @objc dynamic var fleet1Seiku: Int = 0 {
44 willChangeValue(forKey: #keyPath(seiku))
47 didChangeValue(forKey: #keyPath(seiku))
50 @objc dynamic var fleet2Seiku: Int = 0 {
52 willChangeValue(forKey: #keyPath(seiku))
55 didChangeValue(forKey: #keyPath(seiku))
58 @objc dynamic var seiku: Int { return fleet1Seiku + fleet2Seiku }
60 @objc dynamic var fleet1CalculatedSeiku: Int = 0 {
62 willChangeValue(forKey: #keyPath(seiku))
65 didChangeValue(forKey: #keyPath(seiku))
68 @objc dynamic var fleet2CalculatedSeiku: Int = 0 {
70 willChangeValue(forKey: #keyPath(calculatedSeiku))
73 didChangeValue(forKey: #keyPath(calculatedSeiku))
76 @objc dynamic var calculatedSeiku: Int { return fleet1CalculatedSeiku + fleet2CalculatedSeiku }
78 override var nibName: NSNib.Name {
80 return .nibName(instanceOf: self)
83 override func viewDidLoad() {
87 let placeholders: [NSView] = [placeholder1, placeholder2]
88 let fleets = [fleet1, fleet2]
89 zip(placeholders, fleets).enumerated().forEach {
91 $0.element.1.view.frame = $0.element.0.frame
92 $0.element.1.view.autoresizingMask = $0.element.0.autoresizingMask
93 $0.element.0.superview?.replaceSubview($0.element.0, with: $0.element.1.view)
94 $0.element.1.fleetNumber = $0.offset + 1
97 bind(NSBindingName(#keyPath(fleet1TPValue)), to: fleet1, withKeyPath: #keyPath(FleetViewController.totalTPValue))
98 bind(NSBindingName(#keyPath(fleet2TPValue)), to: fleet2, withKeyPath: #keyPath(FleetViewController.totalTPValue))
100 bind(NSBindingName(#keyPath(fleet1Seiku)), to: fleet1, withKeyPath: #keyPath(FleetViewController.totalSeiku))
101 bind(NSBindingName(#keyPath(fleet2Seiku)), to: fleet2, withKeyPath: #keyPath(FleetViewController.totalSeiku))
103 bind(NSBindingName(#keyPath(fleet1CalculatedSeiku)), to: fleet1, withKeyPath: #keyPath(FleetViewController.totalCalclatedSeiku))
104 bind(NSBindingName(#keyPath(fleet2CalculatedSeiku)), to: fleet2, withKeyPath: #keyPath(FleetViewController.totalCalclatedSeiku))
109 unbind(NSBindingName(#keyPath(fleet1TPValue)))
110 unbind(NSBindingName(#keyPath(fleet2TPValue)))
112 unbind(NSBindingName(#keyPath(fleet1Seiku)))
113 unbind(NSBindingName(#keyPath(fleet2Seiku)))
115 unbind(NSBindingName(#keyPath(fleet1CalculatedSeiku)))
116 unbind(NSBindingName(#keyPath(fleet2CalculatedSeiku)))