OSDN Git Service

洋上補給の補強増設用のショートネームをつけた
[kcd/KCD.git] / KCD / SuppliesView.swift
1 //
2 //  SuppliesView.swift
3 //  KCD
4 //
5 //  Created by Hori,Masaki on 2017/01/02.
6 //  Copyright © 2017年 Hori,Masaki. All rights reserved.
7 //
8
9 import Cocoa
10
11 private var pShipStatusContext: Int = 0
12
13 final class SuppliesView: NSControl {
14     
15     private let suppliesCell: SuppliesCell
16     
17     private var fuelObservation: NSKeyValueObservation?
18     private var maxFuelObservation: NSKeyValueObservation?
19     private var bullObservation: NSKeyValueObservation?
20     private var maxBullObservation: NSKeyValueObservation?
21
22     override init(frame: NSRect) {
23         
24         suppliesCell = SuppliesCell()
25         
26         super.init(frame: frame)
27         
28         self.cell = suppliesCell
29     }
30     
31     required init?(coder: NSCoder) {
32         
33         suppliesCell = SuppliesCell()
34         
35         super.init(coder: coder)
36         
37         self.cell = suppliesCell
38     }
39     
40     
41     @objc var ship: Ship? {
42         
43         get { return suppliesCell.ship }
44         set {
45             suppliesCell.ship = newValue
46             
47             fuelObservation = suppliesCell.ship?.observe(\Ship.fuel, changeHandler: updateDisplay)
48             maxFuelObservation = suppliesCell.ship?.observe(\Ship.maxFuel, changeHandler: updateDisplay)
49             bullObservation = suppliesCell.ship?.observe(\Ship.bull, changeHandler: updateDisplay)
50             maxBullObservation = suppliesCell.ship?.observe(\Ship.maxBull, changeHandler: updateDisplay)
51
52             needsDisplay = true
53         }
54     }
55     
56     private func updateDisplay(ship: Ship, _: Any) {
57         
58         needsDisplay = true
59     }
60 }