diff --git a/LazyNethack/App/Resources/PreferencesWindow.xib b/LazyNethack/App/Resources/PreferencesWindow.xib index 5460f88..2f462e7 100644 --- a/LazyNethack/App/Resources/PreferencesWindow.xib +++ b/LazyNethack/App/Resources/PreferencesWindow.xib @@ -17,24 +17,19 @@ - - - - - - - - - - - - - - - + + + + + + + + + + @@ -51,6 +46,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/LazyNethack/Source/Controllers/PreferencesWindowController.swift b/LazyNethack/Source/Controllers/PreferencesWindowController.swift index c926c2a..6592ec4 100644 --- a/LazyNethack/Source/Controllers/PreferencesWindowController.swift +++ b/LazyNethack/Source/Controllers/PreferencesWindowController.swift @@ -11,6 +11,8 @@ import Cocoa @objc(PreferencesWindowController) class PreferencesWindowController: NSWindowController { @IBOutlet weak var rowWidthSegment: NSSegmentedControl! + @IBOutlet weak var fontSegment: NSSegmentedControl! + @IBOutlet weak var serverURLSegment: NSSegmentedControl! override func awakeFromNib() { super.awakeFromNib() @@ -29,4 +31,20 @@ class PreferencesWindowController: NSWindowController { Preferences.rowWidth = .`static` } } + + @IBAction func fontChanged(_ sender: Any) { + if rowWidthSegment.selectedSegment == 0 { + Preferences.font = .dynamic + } else { + Preferences.font = .`static` + } + } + + @IBAction func serverURLChanged(_ sender: Any) { + if serverURLSegment.selectedSegment == 0 { + Preferences.serverURL = .dynamic + } else { + Preferences.serverURL = .`static` + } + } } diff --git a/LazyNethack/Source/Models/Preferences.swift b/LazyNethack/Source/Models/Preferences.swift index b809bc1..2b9c1a2 100644 --- a/LazyNethack/Source/Models/Preferences.swift +++ b/LazyNethack/Source/Models/Preferences.swift @@ -13,7 +13,9 @@ private var userDefaults: UserDefaults = { let ud = ScreenSaverDefaults(forModuleWithName: "org.tessenow.LazyNethack") ?? UserDefaults() ud.register(defaults: [ - Preferences.Key.rowWidth.rawValue: Preferences.RowWidth.dynamic.rawValue + Preferences.Key.rowWidth.rawValue: Preferences.RowWidth.dynamic.rawValue, + Preferences.Key.serverURL.rawValue: Preferences.RowWidth.dynamic.rawValue, + Preferences.Key.font.rawValue: Preferences.RowWidth.dynamic.rawValue ]) return ud @@ -22,6 +24,8 @@ private var userDefaults: UserDefaults = { struct Preferences { fileprivate enum Key: String { case rowWidth = "rowWidth-type" + case font = "font-type" + case serverURL = "serverURL-type" } enum RowWidth: Int { @@ -38,6 +42,26 @@ struct Preferences { set(value: newValue.rawValue, key: .rowWidth) } } + + static var font: Font { + get { + guard let width = Font(rawValue: userDefaults.integer(forKey: Key.rowWidth.rawValue)) else { return .dynamic } + return width + } + set { + set(value: newValue.rawValue, key: .font) + } + } + + static var serverURL: ServerURL { + get { + guard let width = ServerURL(rawValue: userDefaults.integer(forKey: Key.rowWidth.rawValue)) else { return .dynamic } + return width + } + set { + set(value: newValue.rawValue, key: .serverURL) + } + } private static func set(value: Any, key: Key) { userDefaults.set(value, forKey: key.rawValue) diff --git a/LazyNethack/Source/Views/LazyNethackView.swift b/LazyNethack/Source/Views/LazyNethackView.swift index d0ba94a..df204a3 100644 --- a/LazyNethack/Source/Views/LazyNethackView.swift +++ b/LazyNethack/Source/Views/LazyNethackView.swift @@ -58,7 +58,7 @@ class LazyNethackView: ScreenSaverView, func setup() { autoresizingMask = [NSView.AutoresizingMask.width, NSView.AutoresizingMask.height] autoresizesSubviews = true - // startAnimation() + startAnimation() } fileprivate func loadNethack() { @@ -69,7 +69,7 @@ class LazyNethackView: ScreenSaverView, } override func startAnimation() { - super.startAnimation() +// super.startAnimation() if isPreview { return } webView = WebView(frame: self.bounds)