mirror of
https://gitlab.com/cc-ru/ocelot/ocelot-desktop.git
synced 2025-12-20 02:59:19 +01:00
88 lines
3.0 KiB
Scala
88 lines
3.0 KiB
Scala
package ocelot.desktop.ui.widget
|
|
|
|
import ocelot.desktop.Settings
|
|
import ocelot.desktop.audio.SoundSource
|
|
import ocelot.desktop.geometry.{Padding2D, Size2D}
|
|
import ocelot.desktop.ui.layout.LinearLayout
|
|
import ocelot.desktop.ui.widget.modal.ModalDialog
|
|
import ocelot.desktop.ui.widget.verticalmenu.{VerticalMenu, VerticalMenuButton, VerticalMenuFiller}
|
|
import ocelot.desktop.util.{Orientation, ResourceManager, SettingsData}
|
|
|
|
class SettingsDialog extends ModalDialog {
|
|
private val menu = new VerticalMenu
|
|
menu.addEntry(new VerticalMenuButton("Sound", () => {}))
|
|
|
|
private val settingsBackup = new SettingsData(Settings.get)
|
|
|
|
private def applySettings(): Unit = {
|
|
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)
|
|
|
|
children :+= new Widget {
|
|
override val layout = new LinearLayout(this, orientation = Orientation.Vertical)
|
|
children :+= menu
|
|
children :+= new VerticalMenuFiller()
|
|
}
|
|
|
|
children :+= new PaddingBox(new Widget {
|
|
override val layout = new LinearLayout(this, orientation = Orientation.Vertical)
|
|
|
|
children :+= new PaddingBox(new Slider(Settings.get.volumeMaster, "Master Volume") {
|
|
override def minimumSize: Size2D = Size2D(512, 24)
|
|
override def onValueChanged(value: Float): Unit = {
|
|
Settings.get.volumeMaster = value
|
|
applySettings()
|
|
}
|
|
}, Padding2D(bottom = 8))
|
|
|
|
children :+= new PaddingBox(new Slider(Settings.get.volumeBeep, "Beep Volume") {
|
|
override def minimumSize: Size2D = Size2D(512, 24)
|
|
override def onValueChanged(value: Float): Unit = {
|
|
Settings.get.volumeBeep = value
|
|
applySettings()
|
|
}
|
|
}, Padding2D(bottom = 8))
|
|
|
|
children :+= new PaddingBox(new Slider(Settings.get.volumeEnvironment, "Environment Volume") {
|
|
override def minimumSize: Size2D = Size2D(512, 24)
|
|
override def onValueChanged(value: Float): Unit = {
|
|
Settings.get.volumeEnvironment = value
|
|
applySettings()
|
|
}
|
|
}, Padding2D(bottom = 8))
|
|
|
|
children :+= new Widget {
|
|
override val layout = new LinearLayout(this, orientation = Orientation.Horizontal)
|
|
|
|
children :+= new Widget {
|
|
override def maximumSize: Size2D = Size2D(Float.PositiveInfinity, 1)
|
|
}
|
|
|
|
children :+= new Button {
|
|
override def text: String = "Ok"
|
|
override def onClick(): Unit = close()
|
|
}
|
|
|
|
children :+= new PaddingBox(new Button {
|
|
override def text: String = "Cancel"
|
|
override def onClick(): Unit = {
|
|
resetSettings()
|
|
close()
|
|
}
|
|
}, Padding2D(left = 8))
|
|
}
|
|
}, Padding2D(left = 8))
|
|
}, Padding2D.equal(16))
|
|
}
|