OSDN Git Service

バージョンを1.9b33に更新
[kcd/KCD.git] / KCD / ResourceViewController.swift
1 //
2 //  ResourceViewController.swift
3 //  KCD
4 //
5 //  Created by Hori,Masaki on 2016/12/25.
6 //  Copyright © 2016年 Hori,Masaki. All rights reserved.
7 //
8
9 import Cocoa
10
11 final class ResourceViewController: NSViewController {
12     
13     @objc override class func keyPathsForValuesAffectingValue(forKey key: String) -> Set<String> {
14         
15         switch key {
16             
17         case #keyPath(shipNumberColor): return [#keyPath(maxChara), #keyPath(shipCount), #keyPath(minimumColoredShipCount)]
18             
19         default: return []
20         }
21     }
22     
23     @objc let managedObjectContext = ServerDataStore.default.context
24     
25     deinit {
26         
27         unbind(NSBindingName(#keyPath(maxChara)))
28         unbind(NSBindingName(#keyPath(shipCount)))
29     }
30     
31     @IBOutlet var shipController: NSArrayController!
32     @IBOutlet var basicController: NSObjectController!
33     
34     @objc dynamic var maxChara: Int = 0
35     @objc dynamic var shipCount: Int = 0
36     @objc dynamic var shipNumberColor: NSColor {
37         
38         if shipCount > maxChara - minimumColoredShipCount {
39             
40             return .orange
41         }
42         
43         return .controlTextColor
44     }
45     
46     @objc dynamic var minimumColoredShipCount: Int {
47         
48         get { return UserDefaults.standard[.minimumColoredShipCount] }
49         set { UserDefaults.standard[.minimumColoredShipCount] = newValue }
50     }
51     
52     override var nibName: NSNib.Name {
53         
54         return .nibName(instanceOf: self)
55     }
56     
57     override func viewDidLoad() {
58         
59         super.viewDidLoad()
60         
61         bind(NSBindingName(#keyPath(maxChara)), to: basicController, withKeyPath: "selection.max_chara", options: nil)
62         bind(NSBindingName(#keyPath(shipCount)), to: shipController, withKeyPath: "arrangedObjects.@count", options: nil)
63     }
64 }