diff --git a/src/net/torvald/terrarum/DefaultConfig.kt b/src/net/torvald/terrarum/DefaultConfig.kt index 8c7b53549..cb9e0ab76 100644 --- a/src/net/torvald/terrarum/DefaultConfig.kt +++ b/src/net/torvald/terrarum/DefaultConfig.kt @@ -12,7 +12,6 @@ object DefaultConfig { val hashMap = hashMapOf( "jvm_xmx" to 4, "jvm_extra_cmd" to "", - "testvalue" to 1, "displayfps" to 0, // 0: no limit, non-zero: limit "displayfpsidle" to 0, // 0: no limit, non-zero: limit @@ -120,6 +119,12 @@ object DefaultConfig { "debug_deltat_benchmark_sample_sizes" to 2048, + "mastervolume" to 1.0, + "musicvolume" to 1.0, + "bgmvolume" to 1.0, + "sfxvolume" to 1.0, + + // settings regarding debugger /*"buildingmakerfavs" to arrayOf( diff --git a/src/net/torvald/terrarum/modulebasegame/ui/ControlPanelCommon.kt b/src/net/torvald/terrarum/modulebasegame/ui/ControlPanelCommon.kt index 98639369e..5a8f09c46 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/ControlPanelCommon.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/ControlPanelCommon.kt @@ -1,20 +1,35 @@ package net.torvald.terrarum.modulebasegame.ui +import com.badlogic.gdx.Gdx import com.badlogic.gdx.Input +import com.badlogic.gdx.graphics.Color +import com.badlogic.gdx.graphics.g2d.SpriteBatch import net.torvald.terrarum.App +import net.torvald.terrarum.CommonResourcePool import net.torvald.terrarum.ui.* +import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack + +typealias ControlPanelOptions = Array> /** * Created by minjaesong on 2023-07-14. */ object ControlPanelCommon { + init { + CommonResourcePool.addToLoadingList("gui_hrule") { + TextureRegionPack(Gdx.files.internal("assets/graphics/gui/hrule.tga"), 216, 20) + } + CommonResourcePool.loadAll() + } + var CONFIG_SPINNER_WIDTH = 140 var CONFIG_TYPEIN_WIDTH = 240 + var CONFIG_SLIDER_WIDTH = 240 // @return Pair of fun makeButton(parent: UICanvas, args: String, x: Int, y: Int, optionName: String): Pair Unit> { - return if (args.startsWith("h1") || args.startsWith("p")) { + return if (args.equals("h1") || args.equals("p")) { (object : UIItem(parent, x, y) { override val width = 1 override val height = 1 @@ -47,7 +62,7 @@ object ControlPanelCommon { } else if (args.startsWith("sliderd,")) { val arg = args.split(',') - UIItemHorzSlider(parent, x, y, App.getConfigDouble(optionName), arg[1].toDouble(), arg[2].toDouble(), CONFIG_SPINNER_WIDTH) to { it: UIItem, optionStr: String -> + UIItemHorzSlider(parent, x, y, App.getConfigDouble(optionName), arg[1].toDouble(), arg[2].toDouble(), CONFIG_SLIDER_WIDTH) to { it: UIItem, optionStr: String -> (it as UIItemHorzSlider).selectionChangeListener = { App.setConfig(optionStr, it) } @@ -107,4 +122,91 @@ object ControlPanelCommon { else throw IllegalArgumentException(args) } + private val linegap = 14 + private val panelgap = 20 + + private val rowheight = 20 + linegap + + private val h1MarginTop = 16 + private val h1MarginBottom = 4 + + private val optionsYposCache = HashMap() + private val optionsCache = HashMap() + + fun register(ui: UICanvas, width: Int, identifier: String, options: ControlPanelOptions) { + optionsCache[identifier] = options + val optionsYpos = IntArray(options.size + 1) + var akku = 0 + options.forEachIndexed { index, row -> + val option = row[2] + + if (index > 0 && option == "h1") { + akku += h1MarginTop + } + + optionsYpos[index] = akku + + akku += when (option) { + "h1" -> rowheight + h1MarginBottom + else -> rowheight + } + } + optionsYpos[optionsYpos.lastIndex] = akku + optionsYposCache[identifier] = optionsYpos + + val height = optionsYpos.last() + val drawX = (App.scr.width - width) / 2 + val drawY = (App.scr.height - height) / 2 + + options.forEachIndexed { index, args -> + val (item, job) = makeButton( + ui, args[2] as String, + drawX + width / 2 + panelgap, + drawY - 2 + optionsYpos[index], + args[0] as String + ) + job.invoke(item, args[0] as String) + ui.addUIitem(item) + } + } + + private val hrule = CommonResourcePool.getAsTextureRegionPack("gui_hrule") + + fun getMenuHeight(identifier: String) = optionsYposCache[identifier]!!.last() + + fun render(identifier: String, width: Int, batch: SpriteBatch) { + val height = optionsYposCache[identifier]!!.last() + val drawX = (App.scr.width - width) / 2 + val drawY = (App.scr.height - height) / 2 + + val optionsYpos = optionsYposCache[identifier]!! + optionsCache[identifier]!!.forEachIndexed { index, args -> + val mode = args[2] + + val font = if (mode == "h1") App.fontUITitle else App.fontGame + + val label = (args[1] as () -> String).invoke() + val labelWidth = font.getWidth(label) + batch.color = when (mode) { + "h1" -> Toolkit.Theme.COL_MOUSE_UP + "p" -> Color.LIGHT_GRAY + else -> Color.WHITE + } + + val xpos = if (mode == "p" || mode == "h1") + drawX + (width - labelWidth)/2 // centre-aligned + else + drawX + width/2 - panelgap - labelWidth // right aligned at the middle of the panel, offsetted by panelgap + + font.draw(batch, label, xpos.toFloat(), drawY + optionsYpos[index] - 2f) + + // draw hrule + if (mode == "h1") { + val ruleWidth = ((width - 24 - labelWidth) / 2).toFloat() + batch.draw(hrule.get(0,0), xpos - 24f - ruleWidth, drawY + optionsYpos[index].toFloat(), ruleWidth, hrule.tileH.toFloat()) + batch.draw(hrule.get(0,1), xpos + 24f + labelWidth, drawY + optionsYpos[index].toFloat(), ruleWidth, hrule.tileH.toFloat()) + } + } + } + } \ No newline at end of file diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIGraphicsControlPanel.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIGraphicsControlPanel.kt index dedf3ed7b..a73d98738 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIGraphicsControlPanel.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIGraphicsControlPanel.kt @@ -19,119 +19,33 @@ import net.torvald.unicode.TIMES */ class UIGraphicsControlPanel(remoCon: UIRemoCon?) : UICanvas() { + override var width = 560 - private val linegap = 14 - private val panelgap = 20 - - private val rowheight = 20 + linegap - - private val h1MarginTop = 16 - private val h1MarginBottom = 4 - - private val options = arrayOf( - arrayOf("", { Lang["CREDITS_VFX"] }, "h1"), + init { + ControlPanelCommon.register(this, width, "basegame.graphicscontrolpanel", arrayOf( + arrayOf("", { Lang["CREDITS_VFX"] }, "h1"), arrayOf("fx_dither", { Lang["MENU_OPTIONS_DITHER"] }, "toggle"), arrayOf("fx_backgroundblur", { Lang["MENU_OPTIONS_BLUR"] }, "toggle"), arrayOf("maxparticles", { Lang["MENU_OPTIONS_PARTICLES"] }, "spinner,256,1024,256"), - arrayOf("", { Lang["MENU_OPTIONS_DISPLAY"] }, "h1"), + arrayOf("", { Lang["MENU_OPTIONS_DISPLAY"] }, "h1"), arrayOf("screenwidth,screenheight", { Lang["MENU_OPTIONS_RESOLUTION"] }, "typeinres"), arrayOf("screenmagnifying", { Lang["GAME_ACTION_ZOOM"] }, "spinnerd,1.0,2.0,0.05"), arrayOf("displayfps", { Lang["MENU_LABEL_FRAMESPERSEC"] }, "spinner,0,300,2"), arrayOf("usevsync", { Lang["MENU_OPTIONS_VSYNC"] }, "toggle"), arrayOf("", { "(${Lang["MENU_LABEL_RESTART_REQUIRED"]})" }, "p"), - arrayOf("", { Lang["MENU_LABEL_STREAMING"] }, "h1"), + arrayOf("", { Lang["MENU_LABEL_STREAMING"] }, "h1"), arrayOf("fx_streamerslayout", { Lang["MENU_OPTIONS_STREAMERS_LAYOUT"] }, "toggle"), - ) - - private val optionsYpos = IntArray(options.size + 1) - - init { - CommonResourcePool.addToLoadingList("gui_hrule") { - TextureRegionPack(Gdx.files.internal("assets/graphics/gui/hrule.tga"), 216, 20) - } - CommonResourcePool.loadAll() - - - - var akku = 0 - options.forEachIndexed { index, row -> - val option = row[2] - - if (index > 0 && option == "h1") { - akku += h1MarginTop - } - - optionsYpos[index] = akku - - akku += when (option) { - "h1" -> rowheight + h1MarginBottom - else -> rowheight - } - } - optionsYpos[optionsYpos.lastIndex] = akku - } - override var width = 560 - override var height = optionsYpos.last() - - private val hrule = CommonResourcePool.getAsTextureRegionPack("gui_hrule") - - private val spinnerWidth = 140 - private val drawX = (Toolkit.drawWidth - width) / 2 - private val drawY = (App.scr.height - height) / 2 - - private val optionControllers: List Unit>> = options.mapIndexed { index, strings -> - makeButton(this, options[index][2] as String, - drawX + width / 2 + panelgap, - drawY - 2 + optionsYpos[index], - options[index][0] as String - ) + )) } - init { - optionControllers.forEachIndexed { i, it -> - it.second.invoke(it.first, options[i][0] as String) - addUIitem(it.first) - } - } + override var height = ControlPanelCommon.getMenuHeight("basegame.graphicscontrolpanel") override fun updateUI(delta: Float) { uiItems.forEach { it.update(delta) } } override fun renderUI(batch: SpriteBatch, camera: Camera) { - /*batch.color = Toolkit.Theme.COL_INACTIVE - Toolkit.drawBoxBorder(batch, drawX, drawY, width, height) - - batch.color = CELL_COL - Toolkit.fillArea(batch, drawX, drawY, width, height)*/ - - options.forEachIndexed { index, strings -> - val mode = strings[2] - - val font = if (mode == "h1") App.fontUITitle else App.fontGame - - val label = (strings[1] as () -> String).invoke() - val labelWidth = font.getWidth(label) - batch.color = when (mode) { - "h1" -> Toolkit.Theme.COL_MOUSE_UP - "p" -> Color.LIGHT_GRAY - else -> Color.WHITE - } - - val xpos = if (mode == "p" || mode == "h1") - drawX + (width - labelWidth)/2 // centre-aligned - else - drawX + width/2 - panelgap - labelWidth // right aligned at the middle of the panel, offsetted by panelgap - - font.draw(batch, label, xpos.toFloat(), drawY + optionsYpos[index] - 2f) - - // draw hrule - if (mode == "h1") { - val ruleWidth = ((width - 24 - labelWidth) / 2).toFloat() - batch.draw(hrule.get(0,0), xpos - 24f - ruleWidth, drawY + optionsYpos[index].toFloat(), ruleWidth, hrule.tileH.toFloat()) - batch.draw(hrule.get(0,1), xpos + 24f + labelWidth, drawY + optionsYpos[index].toFloat(), ruleWidth, hrule.tileH.toFloat()) - } - } + ControlPanelCommon.render("basegame.graphicscontrolpanel", width, batch) uiItems.forEach { it.render(batch, camera) } if (App.getConfigBoolean("fx_streamerslayout")) { @@ -152,14 +66,6 @@ class UIGraphicsControlPanel(remoCon: UIRemoCon?) : UICanvas() { } } - override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean { - return super.touchDown(screenX, screenY, pointer, button) - } - - override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean { - return super.touchUp(screenX, screenY, pointer, button) - } - override fun dispose() { } } \ No newline at end of file diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIPerformanceControlPanel.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIPerformanceControlPanel.kt index 124441603..aeec25a2a 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIPerformanceControlPanel.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIPerformanceControlPanel.kt @@ -19,134 +19,29 @@ import net.torvald.unicode.TIMES */ class UIPerformanceControlPanel(remoCon: UIRemoCon?) : UICanvas() { - - private val linegap = 14 - private val panelgap = 20 - - private val rowheight = 20 + linegap - - private val h1MarginTop = 16 - private val h1MarginBottom = 4 - - private val options = arrayOf( - arrayOf("", { Lang["MENU_OPTIONS_GAMEPLAY"] }, "h1"), - arrayOf("autosaveinterval", { Lang["MENU_OPTIONS_AUTOSAVE"] + " (${Lang["CONTEXT_TIME_MINUTE_PLURAL"]})" }, "spinnerimul,1,120,1,60000"), - arrayOf("notificationshowuptime", { Lang["MENU_OPTIONS_NOTIFICATION_DISPLAY_DURATION"] + " (${Lang["CONTEXT_TIME_SECOND_PLURAL"]})" }, "spinnerimul,2,10,1,1000"), -// arrayOf("testvalue", { "TestValue" }, "sliderd,1,100,1"), - arrayOf("", { Lang["MENU_LABEL_JVM_DNT"] }, "h1"), - arrayOf("jvm_xmx", { Lang["MENU_OPTIONS_JVM_HEAP_MAX"] + " (GB)" }, "spinner,2,32,1"), - arrayOf("jvm_extra_cmd", { Lang["MENU_LABEL_EXTRA_JVM_ARGUMENTS"] }, "typein"), - arrayOf("", { "(${Lang["MENU_LABEL_RESTART_REQUIRED"]})" }, "p"), - ) - - private val optionsYpos = IntArray(options.size + 1) - - init { - CommonResourcePool.addToLoadingList("gui_hrule") { - TextureRegionPack(Gdx.files.internal("assets/graphics/gui/hrule.tga"), 216, 20) - } - CommonResourcePool.loadAll() - - - - var akku = 0 - options.forEachIndexed { index, row -> - val option = row[2] - - if (index > 0 && option == "h1") { - akku += h1MarginTop - } - - optionsYpos[index] = akku - - akku += when (option) { - "h1" -> rowheight + h1MarginBottom - else -> rowheight - } - } - optionsYpos[optionsYpos.lastIndex] = akku - } override var width = 560 - override var height = optionsYpos.last() - - private val hrule = CommonResourcePool.getAsTextureRegionPack("gui_hrule") - - private val spinnerWidth = 140 - private val typeinWidth = 240 - private val drawX = (Toolkit.drawWidth - width) / 2 - private val drawY = (App.scr.height - height) / 2 - - private val optionControllers: List Unit>> = options.mapIndexed { index, strings -> - makeButton(this, options[index][2] as String, - drawX + width / 2 + panelgap, - drawY - 2 + optionsYpos[index], - options[index][0] as String - ) - } init { - optionControllers.forEachIndexed { i, it -> - it.second.invoke(it.first, options[i][0] as String) - addUIitem(it.first) - } + ControlPanelCommon.register(this, width, "basegame.performancecontrolpanel", arrayOf( + arrayOf("", { Lang["MENU_OPTIONS_GAMEPLAY"] }, "h1"), + arrayOf("autosaveinterval", { Lang["MENU_OPTIONS_AUTOSAVE"] + " (${Lang["CONTEXT_TIME_MINUTE_PLURAL"]})" }, "spinnerimul,1,120,1,60000"), + arrayOf("notificationshowuptime", { Lang["MENU_OPTIONS_NOTIFICATION_DISPLAY_DURATION"] + " (${Lang["CONTEXT_TIME_SECOND_PLURAL"]})" }, "spinnerimul,2,10,1,1000"), + arrayOf("", { Lang["MENU_LABEL_JVM_DNT"] }, "h1"), + arrayOf("jvm_xmx", { Lang["MENU_OPTIONS_JVM_HEAP_MAX"] + " (GB)" }, "spinner,2,32,1"), + arrayOf("jvm_extra_cmd", { Lang["MENU_LABEL_EXTRA_JVM_ARGUMENTS"] }, "typein"), + arrayOf("", { "(${Lang["MENU_LABEL_RESTART_REQUIRED"]})" }, "p"), + )) } + override var height = ControlPanelCommon.getMenuHeight("basegame.performancecontrolpanel") + override fun updateUI(delta: Float) { uiItems.forEach { it.update(delta) } } override fun renderUI(batch: SpriteBatch, camera: Camera) { - /*batch.color = Toolkit.Theme.COL_INACTIVE - Toolkit.drawBoxBorder(batch, drawX, drawY, width, height) - - batch.color = CELL_COL - Toolkit.fillArea(batch, drawX, drawY, width, height)*/ - - options.forEachIndexed { index, strings -> - val mode = strings[2] - - val font = if (mode == "h1") App.fontUITitle else App.fontGame - - val label = (strings[1] as () -> String).invoke() - val labelWidth = font.getWidth(label) - batch.color = when (mode) { - "h1" -> Toolkit.Theme.COL_MOUSE_UP - "p" -> Color.LIGHT_GRAY - else -> Color.WHITE - } - - val xpos = if (mode == "p" || mode == "h1") - drawX + (width - labelWidth)/2 // centre-aligned - else - drawX + width/2 - panelgap - labelWidth // right aligned at the middle of the panel, offsetted by panelgap - - font.draw(batch, label, xpos.toFloat(), drawY + optionsYpos[index] - 2f) - - // draw hrule - if (mode == "h1") { - val ruleWidth = ((width - 24 - labelWidth) / 2).toFloat() - batch.draw(hrule.get(0,0), xpos - 24f - ruleWidth, drawY + optionsYpos[index].toFloat(), ruleWidth, hrule.tileH.toFloat()) - batch.draw(hrule.get(0,1), xpos + 24f + labelWidth, drawY + optionsYpos[index].toFloat(), ruleWidth, hrule.tileH.toFloat()) - } - } + ControlPanelCommon.render("basegame.performancecontrolpanel", width, batch) uiItems.forEach { it.render(batch, camera) } - - if (App.getConfigBoolean("fx_streamerslayout")) { - val xstart = App.scr.width - App.scr.chatWidth - - batch.color = Color(0x00f8ff_40) - Toolkit.fillArea(batch, xstart + 1, 1, App.scr.chatWidth - 2, App.scr.height - 2) - - batch.color = Toolkit.Theme.COL_MOUSE_UP - Toolkit.drawBoxBorder(batch, xstart + 1, 1, App.scr.chatWidth - 2, App.scr.height - 2) - - val overlayResTxt = "${(App.scr.chatWidth * App.scr.magn).ceilToInt()}$TIMES${App.scr.windowH}" - - App.fontGame.draw(batch, overlayResTxt, - (xstart + (App.scr.chatWidth - App.fontGame.getWidth(overlayResTxt)) / 2).toFloat(), - ((App.scr.height - App.fontGame.lineHeight) / 2).toFloat() - ) - } } override fun dispose() { diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UISoundControlPanel.kt b/src/net/torvald/terrarum/modulebasegame/ui/UISoundControlPanel.kt new file mode 100644 index 000000000..3c134b9e8 --- /dev/null +++ b/src/net/torvald/terrarum/modulebasegame/ui/UISoundControlPanel.kt @@ -0,0 +1,41 @@ +package net.torvald.terrarum.modulebasegame.ui + +import com.badlogic.gdx.graphics.Camera +import com.badlogic.gdx.graphics.g2d.SpriteBatch +import net.torvald.terrarum.langpack.Lang +import net.torvald.terrarum.ui.UICanvas + +/** + * Created by minjaesong on 2023-07-15. + */ +class UISoundControlPanel(remoCon: UIRemoCon?) : UICanvas() { + + override var width = 560 + + init { + ControlPanelCommon.register(this, width, "basegame.soundcontrolpanel", arrayOf( + arrayOf("mastervolume", { Lang["MENU_OPTIONS_SOUND_VOLUME"] }, "sliderd,0,1"), + arrayOf("", { "" }, "p"), + arrayOf("bgmvolume", { Lang["MENU_LABEL_BACKGROUND_MUSIC"] }, "sliderd,0,1"), + arrayOf("", { "" }, "p"), + arrayOf("musicvolume", { Lang["MENU_LABEL_MUSIC"] }, "sliderd,0,1"), + arrayOf("", { "" }, "p"), + arrayOf("sfxvolume", { Lang["CREDITS_SFX"] }, "sliderd,0,1"), + + )) + } + + override var height = ControlPanelCommon.getMenuHeight("basegame.soundcontrolpanel") + + override fun updateUI(delta: Float) { + uiItems.forEach { it.update(delta) } + } + + override fun renderUI(batch: SpriteBatch, camera: Camera) { + ControlPanelCommon.render("basegame.soundcontrolpanel", width, batch) + uiItems.forEach { it.render(batch, camera) } + } + + override fun dispose() { + } +} \ No newline at end of file diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UITitleRemoConYaml.kt b/src/net/torvald/terrarum/modulebasegame/ui/UITitleRemoConYaml.kt index a71b40508..0ea233807 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UITitleRemoConYaml.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UITitleRemoConYaml.kt @@ -17,6 +17,7 @@ object UITitleRemoConYaml { - MENU_LABEL_GRAPHICS : net.torvald.terrarum.modulebasegame.ui.UIGraphicsControlPanel - MENU_OPTIONS_CONTROLS : net.torvald.terrarum.modulebasegame.ui.UIKeyboardControlPanel - MENU_LABEL_IME : net.torvald.terrarum.modulebasegame.ui.UIIMEConfig + - MENU_LABEL_SOUND : net.torvald.terrarum.modulebasegame.ui.UISoundControlPanel - MENU_LABEL_LANGUAGE : net.torvald.terrarum.modulebasegame.ui.UITitleLanguage - GAME_GENRE_MISC : net.torvald.terrarum.modulebasegame.ui.UIPerformanceControlPanel - MENU_MODULES : net.torvald.terrarum.ModOptionsHost diff --git a/src/net/torvald/terrarum/ui/UIItemHorzSlider.kt b/src/net/torvald/terrarum/ui/UIItemHorzSlider.kt index 89168b0dd..1ef44c0b2 100644 --- a/src/net/torvald/terrarum/ui/UIItemHorzSlider.kt +++ b/src/net/torvald/terrarum/ui/UIItemHorzSlider.kt @@ -35,7 +35,7 @@ class UIItemHorzSlider( private var mouseOnHandle = false private val handleTravelDist = width - handleWidth - private var handlePos = 0.0 + private var handlePos = (initialValue / max).times(handleTravelDist).coerceIn(0.0, handleTravelDist.toDouble()) var value: Double = initialValue; private set var selectionChangeListener: (Double) -> Unit = {} diff --git a/src/net/torvald/terrarum/weather/WeatherMixer.kt b/src/net/torvald/terrarum/weather/WeatherMixer.kt index c2c1bb150..b4c809043 100644 --- a/src/net/torvald/terrarum/weather/WeatherMixer.kt +++ b/src/net/torvald/terrarum/weather/WeatherMixer.kt @@ -184,7 +184,7 @@ internal object WeatherMixer : RNGConsumer { // println(parallax) // parallax value works as intended. gdxBlendNormalStraightAlpha() - + val degThis = solarElev.floorToDouble() val degNext = degThis + if (timeNow < HALF_DAY) 1 else -1 // Skybox.get has internal coerceIn