Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 48 additions & 15 deletions LazyNethack/App/Resources/PreferencesWindow.xib
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,19 @@
<rect key="frame" x="0.0" y="0.0" width="480" height="270"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<segmentedControl verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="WXP-79-gTT">
<rect key="frame" x="91" y="234" width="135" height="24"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<segmentedCell key="cell" borderStyle="border" alignment="left" style="rounded" trackingMode="selectOne" id="fU5-XR-yEO">
<font key="font" metaFont="system"/>
<segments>
<segment label="Dynamic" width="70"/>
<segment label="Static" selected="YES"/>
</segments>
</segmentedCell>
<connections>
<action selector="rowWidthChanged:" target="gQW-yC-Zpt" id="bJD-iO-S25"/>
</connections>
</segmentedControl>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="LGc-e6-3tB">
<rect key="frame" x="10" y="238" width="77" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Row width" id="Y5B-4h-BRK">
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Font" id="Y5B-4h-BRK">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="RhC-9P-poq">
<rect key="frame" x="10" y="204" width="98" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Nethack Server" id="WtQ-8E-bAm">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
Expand All @@ -51,6 +46,44 @@
</connections>
</buttonCell>
</button>
<popUpButton verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="9WP-mD-ES8">
<rect key="frame" x="112" y="233" width="225" height="26"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<popUpButtonCell key="cell" type="push" title="Item 1" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" state="on" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" selectedItem="K9Z-ct-0he" id="Uha-wP-ibT">
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="menu"/>
<menu key="menu" id="3p3-5J-srl">
<items>
<menuItem title="Item 1" state="on" id="K9Z-ct-0he"/>
<menuItem title="Item 2" id="KsN-GE-YM6"/>
<menuItem title="Item 3" id="WIk-lc-Yfw"/>
</items>
</menu>
</popUpButtonCell>
</popUpButton>
<textField verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="7zE-hG-jZk">
<rect key="frame" x="114" y="204" width="220" height="22"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" drawsBackground="YES" id="OKj-dq-Ndj">
<font key="font" metaFont="system"/>
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<segmentedControl verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="WXP-79-gTT">
<rect key="frame" x="273" y="137" width="135" height="24"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<segmentedCell key="cell" borderStyle="border" alignment="left" style="rounded" trackingMode="selectOne" id="fU5-XR-yEO">
<font key="font" metaFont="system"/>
<segments>
<segment label="Dynamic" width="70"/>
<segment label="Static" selected="YES"/>
</segments>
</segmentedCell>
<connections>
<action selector="rowWidthChanged:" target="gQW-yC-Zpt" id="bJD-iO-S25"/>
</connections>
</segmentedControl>
</subviews>
</view>
</window>
Expand Down
18 changes: 18 additions & 0 deletions LazyNethack/Source/Controllers/PreferencesWindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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`
}
}
}
26 changes: 25 additions & 1 deletion LazyNethack/Source/Models/Preferences.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions LazyNethack/Source/Views/LazyNethackView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class LazyNethackView: ScreenSaverView,
func setup() {
autoresizingMask = [NSView.AutoresizingMask.width, NSView.AutoresizingMask.height]
autoresizesSubviews = true
// startAnimation()
startAnimation()
}

fileprivate func loadNethack() {
Expand All @@ -69,7 +69,7 @@ class LazyNethackView: ScreenSaverView,
}

override func startAnimation() {
super.startAnimation()
// super.startAnimation()
if isPreview { return }

webView = WebView(frame: self.bounds)
Expand Down