mirror of
https://gitlab.com/cc-ru/ocelot/ocelot-desktop.git
synced 2026-01-06 11:12:39 +01:00
Apply settings changes in real time
This commit is contained in:
parent
0fb1ac2ead
commit
c9b9398348
@ -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))
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user