Apply settings changes in real time

This commit is contained in:
UnicornFreedom 2022-05-10 16:55:52 +02:00
parent 0fb1ac2ead
commit c9b9398348
2 changed files with 31 additions and 19 deletions

View File

@ -12,17 +12,20 @@ class SettingsDialog extends ModalDialog {
private val menu = new VerticalMenu
menu.addEntry(new VerticalMenuButton("Sound", () => {}))
private val settingsData = new SettingsData()
settingsData.updateWith(Settings.get)
private val settingsBackup = new SettingsData(Settings.get)
private def applySettings(): Unit = {
Settings.get.updateWith(settingsData)
ResourceManager.forEach {
case soundSource: SoundSource => soundSource.setVolume(Settings.get.volumeEnvironment * Settings.get.volumeMaster)
case _ =>
}
}
private def resetSettings(): Unit = {
Settings.get.updateWith(settingsBackup)
applySettings()
}
children :+= new PaddingBox(new Widget {
override val layout = new LinearLayout(this, orientation = Orientation.Horizontal)
@ -34,19 +37,28 @@ class SettingsDialog extends ModalDialog {
children :+= new PaddingBox(new Widget {
override val layout = new LinearLayout(this, orientation = Orientation.Vertical)
children :+= new PaddingBox(new Slider(settingsData.volumeMaster, "Master Volume") {
children :+= new PaddingBox(new Slider(Settings.get.volumeMaster, "Master Volume") {
override def minimumSize: Size2D = Size2D(512, 24)
override def onValueChanged(value: Float): Unit = settingsData.volumeMaster = value
override def onValueChanged(value: Float): Unit = {
Settings.get.volumeMaster = value
applySettings()
}
}, Padding2D(bottom = 8))
children :+= new PaddingBox(new Slider(settingsData.volumeBeep, "Beep Volume") {
children :+= new PaddingBox(new Slider(Settings.get.volumeBeep, "Beep Volume") {
override def minimumSize: Size2D = Size2D(512, 24)
override def onValueChanged(value: Float): Unit = settingsData.volumeBeep = value
override def onValueChanged(value: Float): Unit = {
Settings.get.volumeBeep = value
applySettings()
}
}, Padding2D(bottom = 8))
children :+= new PaddingBox(new Slider(settingsData.volumeEnvironment, "Environment Volume") {
children :+= new PaddingBox(new Slider(Settings.get.volumeEnvironment, "Environment Volume") {
override def minimumSize: Size2D = Size2D(512, 24)
override def onValueChanged(value: Float): Unit = settingsData.volumeEnvironment = value
override def onValueChanged(value: Float): Unit = {
Settings.get.volumeEnvironment = value
applySettings()
}
}, Padding2D(bottom = 8))
children :+= new Widget {
@ -58,20 +70,15 @@ class SettingsDialog extends ModalDialog {
children :+= new Button {
override def text: String = "Ok"
override def onClick(): Unit = {
applySettings()
close()
}
override def onClick(): Unit = close()
}
children :+= new PaddingBox(new Button {
override def text: String = "Cancel"
override def onClick(): Unit = close()
}, Padding2D(left = 8))
children :+= new PaddingBox(new Button {
override def text: String = "Apply"
override def onClick(): Unit = applySettings()
override def onClick(): Unit = {
resetSettings()
close()
}
}, Padding2D(left = 8))
}
}, Padding2D(left = 8))

View File

@ -1,6 +1,11 @@
package ocelot.desktop.util
class SettingsData {
def this(data: SettingsData) {
this()
updateWith(data)
}
var volumeMaster: Float = 1f
var volumeBeep: Float = 1f
var volumeEnvironment: Float = 1f