Skip to content

Commit

Permalink
Moved autofire settings from Preferences to Configurator
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkwhoffmann committed Jul 22, 2024
1 parent 5dd1ae7 commit 33ac412
Show file tree
Hide file tree
Showing 7 changed files with 1,534 additions and 1,443 deletions.
52 changes: 51 additions & 1 deletion GUI/Dialogs/Configuration/Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,38 +104,47 @@ class Configuration {
precondition(0 <= n && n <= 3)
return amiga.get(.DRIVE_CONNECT, drive: n) != 0
}

func setDfnConnected(_ n: Int, connect: Bool) {
precondition(0 <= n && n <= 3)
amiga.set(.DRIVE_CONNECT, drive: n, enable: connect)
}

func dfnType(_ n: Int) -> Int {
precondition(0 <= n && n <= 3)
return amiga.get(.DRIVE_TYPE, drive: n)
}

func setDfnType(_ n: Int, type: Int) {
precondition(0 <= n && n <= 3)
amiga.set(.DRIVE_TYPE, drive: n, value: type)
}

func dfnRpm(_ n: Int) -> Int {
precondition(0 <= n && n <= 3)
return amiga.get(.DRIVE_RPM, drive: n)
}

func setDfnRpm(_ n: Int, type: Int) {
precondition(0 <= n && n <= 3)
amiga.set(.DRIVE_RPM, drive: n, value: type)
}

func hdnConnected(_ n: Int) -> Bool {
precondition(0 <= n && n <= 3)
return amiga.get(.HDC_CONNECT, drive: n) != 0
}

func setHdnConnected(_ n: Int, connect: Bool) {
precondition(0 <= n && n <= 3)
amiga.set(.HDC_CONNECT, drive: n, enable: connect)
}

func hdnType(_ n: Int) -> Int {
precondition(0 <= n && n <= 3)
return amiga.get(.HDR_TYPE, drive: n)
}

func setHdnType(_ n: Int, type: Int) {
precondition(0 <= n && n <= 3)
amiga.set(.HDR_TYPE, drive: n, value: type)
Expand All @@ -145,83 +154,101 @@ class Configuration {
get { return dfnConnected(0) }
set { setDfnConnected(0, connect: newValue) }
}

var df0Type: Int {
get { return dfnType(0) }
set { setDfnType(0, type: newValue) }
}

var df0Rpm: Int {
get { return dfnRpm(0) }
set { setDfnRpm(0, type: newValue) }
}

var df1Connected: Bool {
get { return dfnConnected(1) }
set { setDfnConnected(1, connect: newValue) }
}

var df1Type: Int {
get { return dfnType(1) }
set { setDfnType(1, type: newValue) }
}

var df1Rpm: Int {
get { return dfnRpm(1) }
set { setDfnRpm(1, type: newValue) }
}

var df2Connected: Bool {
get { return dfnConnected(2) }
set { setDfnConnected(2, connect: newValue) }
}

var df2Type: Int {
get { return dfnType(2) }
set { setDfnType(2, type: newValue) }
}

var df2Rpm: Int {
get { return dfnRpm(2) }
set { setDfnRpm(2, type: newValue) }
}

var df3Connected: Bool {
get { return dfnConnected(3) }
set { setDfnConnected(3, connect: newValue) }
}

var df3Type: Int {
get { return dfnType(3) }
set { setDfnType(3, type: newValue) }
}

var df3Rpm: Int {
get { return dfnRpm(3) }
set { setDfnRpm(3, type: newValue) }
}

var hd0Connected: Bool {
get { return hdnConnected(0) }
set { setHdnConnected(0, connect: newValue) }
}

var hd0Type: Int {
get { return hdnType(0) }
set { setHdnType(0, type: newValue) }
}

var hd1Connected: Bool {
get { return hdnConnected(1) }
set { setHdnConnected(1, connect: newValue) }
}

var hd1Type: Int {
get { return hdnType(1) }
set { setHdnType(1, type: newValue) }
}

var hd2Connected: Bool {
get { return hdnConnected(2) }
set { setHdnConnected(2, connect: newValue) }
}

var hd2Type: Int {
get { return hdnType(2) }
set { setHdnType(2, type: newValue) }
}

var hd3Connected: Bool {
get { return hdnConnected(3) }
set { setHdnConnected(3, connect: newValue) }
}

var hd3Type: Int {
get { return hdnType(3) }
set { setHdnType(3, type: newValue) }
}
// var hdPersist = [ false, false, false, false ]

var gameDevice1 = -1 {
didSet {
Expand All @@ -237,6 +264,7 @@ class Configuration {
parent.toolbar.validateVisibleItems()
}
}

var gameDevice2 = -1 {
didSet {

Expand All @@ -251,10 +279,32 @@ class Configuration {
parent.toolbar.validateVisibleItems()
}
}

var autofire: Bool {
get { return amiga.get(.JOY_AUTOFIRE, id: 1) != 0 }
set { amiga.set(.JOY_AUTOFIRE, enable: newValue) }
}

var autofireBursts: Bool {
get { return amiga.get(.JOY_AUTOFIRE_BURSTS, id: 1) != 0 }
set { amiga.set(.JOY_AUTOFIRE_BURSTS, enable: newValue) }
}

var autofireBullets: Int {
get { return amiga.get(.JOY_AUTOFIRE_BULLETS, id: 1) }
set { amiga.set(.JOY_AUTOFIRE_BULLETS, value: newValue) }
}

var autofireFrequency: Int {
get { return amiga.get(.JOY_AUTOFIRE_DELAY, id: 1) }
set { amiga.set(.JOY_AUTOFIRE_DELAY, value: newValue) }
}

var serialDevice: Int {
get { return amiga.get(.SER_DEVICE) }
set { amiga.set(.SER_DEVICE, value: newValue) }
}

var serialDevicePort: Int {
get { return amiga.get(.SRV_PORT, id: ServerType.SER.rawValue) }
set { amiga.set(.SRV_PORT, id: ServerType.SER.rawValue, value: newValue) }
Expand Down
34 changes: 34 additions & 0 deletions GUI/Dialogs/Configuration/ConfigurationController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,17 @@ class ConfigurationController: DialogController {
@IBOutlet weak var perSerialPort: NSTextField!
@IBOutlet weak var perSerialPortText: NSTextField!

// Joystick
@IBOutlet weak var perAutofire: NSButton!
@IBOutlet weak var perAutofireText: NSTextField!
@IBOutlet weak var perAutofireFrequency: NSSlider!
@IBOutlet weak var perAutofireFrequencyText1: NSTextField!
@IBOutlet weak var perAutofireFrequencyText2: NSTextField!
@IBOutlet weak var perAutofireCease: NSButton!
@IBOutlet weak var perAutofireCeaseText: NSTextField!
@IBOutlet weak var perAutofireBullets: NSTextField!
@IBOutlet weak var perAutofireBulletsText: NSTextField!

// Lock
@IBOutlet weak var perLockImage: NSButton!
@IBOutlet weak var perLockInfo1: NSTextField!
Expand Down Expand Up @@ -390,3 +401,26 @@ extension ConfigurationController: NSTabViewDelegate {
refresh()
}
}

extension ConfigurationController: NSTextFieldDelegate {

func controlTextDidChange(_ obj: Notification) {

if let view = obj.object as? NSTextField {

let formatter = view.formatter as? NumberFormatter

switch view {

case perAutofireBullets:

if formatter?.number(from: view.stringValue) != nil {
perAutofireBulletsAction(view)
}

default:
break
}
}
}
}
42 changes: 42 additions & 0 deletions GUI/Dialogs/Configuration/PeripheralsConf.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ extension ConfigurationController {

func refreshPeripheralsTab() {

func update(_ component: NSTextField, enable: Bool) {
component.textColor = enable ? .controlTextColor : .disabledControlTextColor
component.isEnabled = enable
}
func update(_ component: NSControl, enable: Bool) {
component.isEnabled = enable
}

let poweredOff = emu.poweredOff

// Floppy drives
Expand Down Expand Up @@ -43,6 +51,20 @@ extension ConfigurationController {
perSerialPort.isHidden = config.serialDevice != nullmodem
perSerialPortText.isHidden = config.serialDevice != nullmodem

// Joysticks
let enable = config.autofire
perAutofire.state = enable ? .on : .off
perAutofireCease.state = config.autofireBursts ? .on : .off
perAutofireBullets.integerValue = config.autofireBullets
perAutofireFrequency.integerValue = config.autofireFrequency
update(perAutofireFrequency, enable: enable)
update(perAutofireFrequencyText1, enable: enable)
update(perAutofireFrequencyText2, enable: enable)
update(perAutofireCease, enable: enable)
update(perAutofireCeaseText, enable: enable)
update(perAutofireBullets, enable: enable && perAutofireCease.state == .on)
update(perAutofireBulletsText, enable: enable && perAutofireCease.state == .on)

// Lock controls if emulator is powered on
perDf1Connect.isEnabled = poweredOff
perDf2Connect.isEnabled = poweredOff && perDf1Connect.state == .on
Expand Down Expand Up @@ -120,6 +142,26 @@ extension ConfigurationController {
}
}

@IBAction func perAutofireAction(_ sender: NSButton!) {

config.autofire = (sender.state == .on)
}

@IBAction func perAutofireCeaseAction(_ sender: NSButton!) {

config.autofireBursts = (sender.state == .on)
}

@IBAction func perAutofireBulletsAction(_ sender: NSTextField!) {

config.autofireBullets = sender.integerValue
}

@IBAction func perAutofireFrequencyAction(_ sender: NSSlider!) {

config.autofireFrequency = sender.integerValue
}

@IBAction func perSerialDeviceAction(_ sender: NSPopUpButton!) {

config.serialDevice = sender.selectedTag()
Expand Down
34 changes: 0 additions & 34 deletions GUI/Dialogs/Preferences/ControlsPrefs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,6 @@ extension PreferencesController {

conDisconnectKeys.state = pref.disconnectJoyKeys ? .on : .off

// Joystick buttons
conAutofire.state = pref.autofire ? .on : .off
conAutofireCease.state = pref.autofireBursts ? .on : .off
conAutofireBullets.integerValue = pref.autofireBullets
conAutofireFrequency.integerValue = pref.autofireFrequency
conAutofireCease.isEnabled = conAutofire.state == .on
conAutofireCeaseText.textColor = conAutofire.state == .on ? .controlTextColor : .disabledControlTextColor
conAutofireBullets.isEnabled = conAutofire.state == .on && conAutofireCease.state == .on
conAutofireFrequency.isEnabled = conAutofire.state == .on

// Mouse
conRetainMouseKeyComb.selectItem(withTag: pref.retainMouseKeyComb)
conRetainMouseKeyComb.isEnabled = pref.retainMouseWithKeys
Expand Down Expand Up @@ -141,30 +131,6 @@ extension PreferencesController {
pref.keyMaps[sender.tag] = [:]
refresh()
}

@IBAction func conAutofireAction(_ sender: NSButton!) {

pref.autofire = sender.state == .on
refresh()
}

@IBAction func conAutofireCeaseAction(_ sender: NSButton!) {

pref.autofireBursts = sender.state == .on
refresh()
}

@IBAction func conAutofireBulletsAction(_ sender: NSTextField!) {

pref.autofireBullets = sender.integerValue
refresh()
}

@IBAction func conAutofireFrequencyAction(_ sender: NSSlider!) {

pref.autofireFrequency = sender.integerValue
refresh()
}

@IBAction func conRetainMouseKeyCombAction(_ sender: NSPopUpButton!) {

Expand Down
15 changes: 1 addition & 14 deletions GUI/Dialogs/Preferences/PreferencesController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,6 @@ class PreferencesController: DialogController {
@IBOutlet weak var conReleaseMouseWithKeys: NSButton!
@IBOutlet weak var conReleaseMouseByShaking: NSButton!

// Joystick
@IBOutlet weak var conAutofire: NSButton!
@IBOutlet weak var conAutofireCease: NSButton!
@IBOutlet weak var conAutofireCeaseText: NSTextField!
@IBOutlet weak var conAutofireBullets: NSTextField!
@IBOutlet weak var conAutofireFrequency: NSSlider!

//
// Devices
//
Expand Down Expand Up @@ -247,13 +240,7 @@ extension PreferencesController: NSTextFieldDelegate {
if formatter?.number(from: view.stringValue) != nil {
genSnapshotIntervalAction(view)
}

case conAutofireBullets:

if formatter?.number(from: view.stringValue) != nil {
conAutofireBulletsAction(view)
}


default:
break
}
Expand Down
Loading

0 comments on commit 33ac412

Please sign in to comment.