fix: non-pausing UIs AND the ingame control are both getting input processed

This commit is contained in:
minjaesong
2024-01-03 15:46:52 +09:00
parent 38ecf8d19c
commit ccd36ffdbd
18 changed files with 63 additions and 17 deletions

View File

@@ -1,4 +1,4 @@
Copyright (C) 2013-2023 Minjae Song ("CuriousTorvald") Copyright (C) 2013-2024 Minjae Song ("CuriousTorvald")
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by

View File

@@ -1,12 +1,13 @@
The playlists (or albums) are stored under (userdata)/Custom/Music/(album name) The playlists (or albums) are stored under (userdata)/Custom/Music/(album name)
The name of the directory is used as the album title, and the lexicographic sorting of the files is used The lexicographic sorting of the files is used as the playing order, so it is advised to name your
as the playing order, so it is advised to name your files as 01.ogg, 02.ogg, 03.ogg, etc. files as 01.ogg, 02.ogg, 03.ogg, etc.
To actually give titles to the files, you must write `playlist.json` with following format: To actually give titles to the files, you must write `playlist.json` with following format:
```json ```json
{ {
"albumName": "Totally Awesome Playlist 2024",
"diskJockeyingMode": "continuous", /* "continuous" allows the Gapless Playback, "intermittent" will put random length of pause (in a range of 30 to 60 seconds) between tracks */ "diskJockeyingMode": "continuous", /* "continuous" allows the Gapless Playback, "intermittent" will put random length of pause (in a range of 30 to 60 seconds) between tracks */
"shuffled": false, /* self-explanatory, often used with "diskJockeyingMode": "intermittent" */ "shuffled": false, /* self-explanatory, often used with "diskJockeyingMode": "intermittent" */
"titles": { "titles": {
@@ -19,9 +20,4 @@ To actually give titles to the files, you must write `playlist.json` with follow
} }
``` ```
- `albumName` may be omitted, in which the name of the directory will be substituted as the album title.
### Limitations
On certain filesystem and platform combination, you cannot use non-ASCII character on the album title
due to an incompatibility with the Java's File implementation. Song titles on `playlist.json` has no
such limitation.

View File

@@ -88,6 +88,8 @@ open class IngameInstance(val batch: FlippingSpriteBatch, val isMultiplayer: Boo
val deltaTeeBenchmarks = CircularArray<Float>(App.getConfigInt("debug_deltat_benchmark_sample_sizes"), true) val deltaTeeBenchmarks = CircularArray<Float>(App.getConfigInt("debug_deltat_benchmark_sample_sizes"), true)
val uiContainer = UIContainer()
init { init {
consoleHandler.setPosition(0, 0) consoleHandler.setPosition(0, 0)
notifier.setPosition( notifier.setPosition(

View File

@@ -32,6 +32,7 @@ import net.torvald.terrarum.itemproperties.MaterialCodex
import net.torvald.terrarum.savegame.DiskSkimmer import net.torvald.terrarum.savegame.DiskSkimmer
import net.torvald.terrarum.serialise.Common import net.torvald.terrarum.serialise.Common
import net.torvald.terrarum.ui.UICanvas import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.ui.UINotControllable
import net.torvald.terrarum.worlddrawer.WorldCamera import net.torvald.terrarum.worlddrawer.WorldCamera
import net.torvald.terrarumsansbitmap.gdx.TerrarumSansBitmap import net.torvald.terrarumsansbitmap.gdx.TerrarumSansBitmap
import net.torvald.unsafe.UnsafeHelper import net.torvald.unsafe.UnsafeHelper
@@ -40,6 +41,7 @@ import org.dyn4j.geometry.Vector2
import java.io.File import java.io.File
import java.io.PrintStream import java.io.PrintStream
import kotlin.math.* import kotlin.math.*
import kotlin.reflect.full.findAnnotation
typealias RGBA8888 = Int typealias RGBA8888 = Int
@@ -750,6 +752,26 @@ class UIContainer {
fun <T> map(transformation: (UICanvas?) -> T) = iterator().asSequence().map(transformation) fun <T> map(transformation: (UICanvas?) -> T) = iterator().asSequence().map(transformation)
fun filter(predicate: (Any) -> Boolean) = data.filter(predicate) fun filter(predicate: (Any) -> Boolean) = data.filter(predicate)
fun filterNotNull(): List<UICanvas> = data.filter {
if (it is UICanvas) true
else if (it is Id_UICanvasNullable) it.get() != null
else false
}.map {
if (it is UICanvas) it
else if (it is Id_UICanvasNullable) it.get()!!
else throw InternalError()
}
val UIsUnderMouse: List<UICanvas>
get() = filterNotNull().filter { it.isVisible && it.mouseUp && it::class.findAnnotation<UINotControllable>() == null }
val hasNoUIsUnderMouse: Boolean
get() = UIsUnderMouse.isEmpty()
val hasUIunderMouse: Boolean
get() = UIsUnderMouse.isNotEmpty()
} }
interface Id_UICanvasNullable { interface Id_UICanvasNullable {

View File

@@ -144,7 +144,14 @@ object TerrarumPostProcessor : Disposable {
if (KeyToggler.isOn(Input.Keys.F10)) { if (KeyToggler.isOn(Input.Keys.F10)) {
batch.color = Color.WHITE batch.color = Color.WHITE
batch.inUse { batch.inUse {
App.fontSmallNumbers.draw(it, "Wire draw class: ${(Terrarum.ingame as? net.torvald.terrarum.modulebasegame.TerrarumIngame)?.selectedWireRenderClass}", 2f, 2f) // print wire draw class
App.fontSmallNumbers.draw(it, "${ccY}Wire draw class: $ccG${(Terrarum.ingame as? net.torvald.terrarum.modulebasegame.TerrarumIngame)?.selectedWireRenderClass}", 2f, 2f)
// print UIs under cursor
App.fontSmallNumbers.draw(it, "${ccY}UIs under mouse:", 2f, 15f)
Terrarum.ingame?.uiContainer?.UIsUnderMouse?.forEachIndexed { i, ui ->
App.fontSmallNumbers.draw(it, "${ccY}-$ccG ${ui.javaClass.simpleName}", 2f, 28f + 13*i)
}
} }
} }

View File

@@ -10,10 +10,12 @@ import com.jme3.math.FastMath
import net.torvald.random.HQRNG import net.torvald.random.HQRNG
import net.torvald.terrarum.ui.Toolkit import net.torvald.terrarum.ui.Toolkit
import net.torvald.terrarum.ui.UICanvas import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.ui.UINotControllable
/** /**
* Created by minjaesong on 2021-09-09. * Created by minjaesong on 2021-09-09.
*/ */
@UINotControllable
class UIFakeGradOverlay : UICanvas() { class UIFakeGradOverlay : UICanvas() {
init { init {
handler.allowESCtoClose = false handler.allowESCtoClose = false
@@ -68,6 +70,7 @@ class UIFakeGradOverlay : UICanvas() {
override fun dispose() {} override fun dispose() {}
} }
@UINotControllable
class UIFakeBlurOverlay(val blurRadius: Float, val nodarken: Boolean) : UICanvas() { class UIFakeBlurOverlay(val blurRadius: Float, val nodarken: Boolean) : UICanvas() {
init { init {
handler.allowESCtoClose = false handler.allowESCtoClose = false

View File

@@ -16,6 +16,7 @@ import net.torvald.terrarum.gameworld.fmod
import net.torvald.terrarum.modulebasegame.TerrarumIngame import net.torvald.terrarum.modulebasegame.TerrarumIngame
import net.torvald.terrarum.modulebasegame.gameactors.DroppedItem import net.torvald.terrarum.modulebasegame.gameactors.DroppedItem
import net.torvald.terrarum.modulebasegame.ui.UIQuickslotBar import net.torvald.terrarum.modulebasegame.ui.UIQuickslotBar
import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.worlddrawer.WorldCamera import net.torvald.terrarum.worlddrawer.WorldCamera
import org.dyn4j.geometry.Vector2 import org.dyn4j.geometry.Vector2
import java.util.* import java.util.*
@@ -131,7 +132,7 @@ class IngameController(val terrarumIngame: TerrarumIngame) : InputAdapter() {
// Use item: assuming the player has only one effective grip (EquipPosition.HAND_GRIP) // Use item: assuming the player has only one effective grip (EquipPosition.HAND_GRIP)
// don't separate Player from this! Physics will break, esp. airborne manoeuvre // don't separate Player from this! Physics will break, esp. airborne manoeuvre
if (!terrarumIngame.paused) { if (!terrarumIngame.paused && terrarumIngame.uiContainer.hasNoUIsUnderMouse) {
val actor = terrarumIngame.actorNowPlaying val actor = terrarumIngame.actorNowPlaying
val itemOnGrip = terrarumIngame.actorNowPlaying?.inventory?.itemEquipped?.get(GameItem.EquipPosition.HAND_GRIP) val itemOnGrip = terrarumIngame.actorNowPlaying?.inventory?.itemEquipped?.get(GameItem.EquipPosition.HAND_GRIP)
// fire world click events; the event is defined as Ingame's (or any others') WorldClick event // fire world click events; the event is defined as Ingame's (or any others') WorldClick event
@@ -159,7 +160,6 @@ class IngameController(val terrarumIngame: TerrarumIngame) : InputAdapter() {
} }
updateKeyboard() updateKeyboard()
} }
@@ -272,7 +272,7 @@ class IngameController(val terrarumIngame: TerrarumIngame) : InputAdapter() {
} }
override fun scrolled(amountX: Float, amountY: Float): Boolean { override fun scrolled(amountX: Float, amountY: Float): Boolean {
if (!terrarumIngame.paused) { if (!terrarumIngame.paused && terrarumIngame.uiContainer.hasNoUIsUnderMouse) {
// quickslot by wheel // quickslot by wheel
terrarumIngame.actorNowPlaying?.let { terrarumIngame.actorNowPlaying?.let {
var selection = it.actorValue.getAsInt(AVKey.__PLAYER_QUICKSLOTSEL)!! var selection = it.actorValue.getAsInt(AVKey.__PLAYER_QUICKSLOTSEL)!!

View File

@@ -87,8 +87,6 @@ class BuildingMaker(batch: FlippingSpriteBatch) : IngameInstance(batch) {
val uiGetPoiName = UIBuildingMakerGetFilename() // used for both import and export val uiGetPoiName = UIBuildingMakerGetFilename() // used for both import and export
val uiContainer = UIContainer()
val keyboardUsedByTextInput: Boolean val keyboardUsedByTextInput: Boolean
get() = uiGetPoiName.textInput.isEnabled get() = uiGetPoiName.textInput.isEnabled

View File

@@ -88,7 +88,6 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
//val ACTORCONTAINER_INITIAL_SIZE = 64 //val ACTORCONTAINER_INITIAL_SIZE = 64
val PARTICLES_MAX = App.getConfigInt("maxparticles") val PARTICLES_MAX = App.getConfigInt("maxparticles")
val particlesContainer = CircularArray<ParticleBase>(PARTICLES_MAX, true) val particlesContainer = CircularArray<ParticleBase>(PARTICLES_MAX, true)
val uiContainer = UIContainer()
// these are required because actors always change their position // these are required because actors always change their position
private var visibleActorsRenderBehind: ArrayList<ActorWithBody> = ArrayList(1) private var visibleActorsRenderBehind: ArrayList<ActorWithBody> = ArrayList(1)

View File

@@ -146,7 +146,6 @@ class TitleScreen(batch: FlippingSpriteBatch) : IngameInstance(batch) {
private val gradWhiteBottom = Color(0xd8d8d8ff.toInt()) private val gradWhiteBottom = Color(0xd8d8d8ff.toInt())
val uiContainer = UIContainer()
internal lateinit var uiRemoCon: UIRemoCon internal lateinit var uiRemoCon: UIRemoCon
internal lateinit var uiFakeBlurOverlay: UICanvas internal lateinit var uiFakeBlurOverlay: UICanvas

View File

@@ -11,6 +11,7 @@ import net.torvald.terrarum.gameworld.fmod
import net.torvald.terrarum.modulebasegame.TerrarumIngame import net.torvald.terrarum.modulebasegame.TerrarumIngame
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellCommonRes.toItemCountText import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellCommonRes.toItemCountText
import net.torvald.terrarum.ui.UICanvas import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.ui.UINotControllable
import kotlin.math.roundToInt import kotlin.math.roundToInt
/** /**
@@ -18,6 +19,7 @@ import kotlin.math.roundToInt
* *
* Created by minjaesong on 2016-07-20. * Created by minjaesong on 2016-07-20.
*/ */
@UINotControllable
class UIQuickslotBar : UICanvas() { class UIQuickslotBar : UICanvas() {
init { init {

View File

@@ -13,6 +13,7 @@ import net.torvald.terrarum.modulebasegame.ui.UIQuickslotBar.Companion.COMMON_OP
import net.torvald.terrarum.modulebasegame.ui.UIQuickslotBar.Companion.SLOT_COUNT import net.torvald.terrarum.modulebasegame.ui.UIQuickslotBar.Companion.SLOT_COUNT
import net.torvald.terrarum.ui.Toolkit import net.torvald.terrarum.ui.Toolkit
import net.torvald.terrarum.ui.UICanvas import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.ui.UINotControllable
import org.dyn4j.geometry.Vector2 import org.dyn4j.geometry.Vector2
import kotlin.math.roundToInt import kotlin.math.roundToInt
@@ -21,6 +22,7 @@ import kotlin.math.roundToInt
* *
* Created by minjaesong on 2016-07-20. * Created by minjaesong on 2016-07-20.
*/ */
@UINotControllable
class UIQuickslotPie : UICanvas() { class UIQuickslotPie : UICanvas() {
init { init {

View File

@@ -10,6 +10,7 @@ import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.modulebasegame.ui.UIQuickslotBar.Companion.COMMON_OPEN_CLOSE import net.torvald.terrarum.modulebasegame.ui.UIQuickslotBar.Companion.COMMON_OPEN_CLOSE
import net.torvald.terrarum.ui.Movement import net.torvald.terrarum.ui.Movement
import net.torvald.terrarum.ui.UICanvas import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.ui.UINotControllable
import net.torvald.unicode.EMDASH import net.torvald.unicode.EMDASH
import net.torvald.unicode.getKeycapPC import net.torvald.unicode.getKeycapPC
import kotlin.math.roundToInt import kotlin.math.roundToInt
@@ -19,6 +20,7 @@ import kotlin.math.roundToInt
* *
* Created by minjaesong on 2019-08-11. * Created by minjaesong on 2019-08-11.
*/ */
@UINotControllable
class UIScreenZoom : UICanvas( class UIScreenZoom : UICanvas(
"control_key_zoom" "control_key_zoom"
) { ) {

View File

@@ -9,10 +9,12 @@ import net.torvald.terrarum.Second
import net.torvald.terrarum.Terrarum import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.ui.Toolkit import net.torvald.terrarum.ui.Toolkit
import net.torvald.terrarum.ui.UICanvas import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.ui.UINotControllable
/** /**
* Created by minjaesong on 2017-11-25. * Created by minjaesong on 2017-11-25.
*/ */
@UINotControllable
class UITooltip : UICanvas() { class UITooltip : UICanvas() {
init { init {

View File

@@ -10,6 +10,7 @@ import net.torvald.terrarum.gameworld.WorldTime
import net.torvald.terrarum.modulebasegame.TerrarumIngame import net.torvald.terrarum.modulebasegame.TerrarumIngame
import net.torvald.terrarum.ui.Toolkit import net.torvald.terrarum.ui.Toolkit
import net.torvald.terrarum.ui.UICanvas import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.ui.UINotControllable
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
import kotlin.math.cos import kotlin.math.cos
import kotlin.math.roundToInt import kotlin.math.roundToInt
@@ -18,6 +19,7 @@ import kotlin.math.sin
/** /**
* Created by minjaesong on 2023-09-09. * Created by minjaesong on 2023-09-09.
*/ */
@UINotControllable
class UIWatchLargeAnalogue() : UICanvas() { class UIWatchLargeAnalogue() : UICanvas() {
override var width = 76 override var width = 76

View File

@@ -10,12 +10,14 @@ import net.torvald.terrarum.*
import net.torvald.terrarum.gameworld.WorldTime import net.torvald.terrarum.gameworld.WorldTime
import net.torvald.terrarum.modulebasegame.imagefont.WatchFont import net.torvald.terrarum.modulebasegame.imagefont.WatchFont
import net.torvald.terrarum.ui.UICanvas import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.ui.UINotControllable
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
import kotlin.math.roundToInt import kotlin.math.roundToInt
/** /**
* Created by minjaesong on 2017-06-11. * Created by minjaesong on 2017-06-11.
*/ */
@UINotControllable
class UIWatchLargeDigital() : UICanvas() { class UIWatchLargeDigital() : UICanvas() {
override var width = 162 override var width = 162
override var height = 25 override var height = 25

View File

@@ -12,6 +12,7 @@ import kotlin.math.roundToInt
/** /**
* Created by minjaesong on 2021-10-01. * Created by minjaesong on 2021-10-01.
*/ */
@UINotControllable
class UIAutosaveNotifier : UICanvas() { class UIAutosaveNotifier : UICanvas() {
init { init {

View File

@@ -431,3 +431,10 @@ abstract class UICanvas(
override fun toString(): String = "${this.javaClass.simpleName}@${this.hashCode().toString(16)}" override fun toString(): String = "${this.javaClass.simpleName}@${this.hashCode().toString(16)}"
} }
/**
* Annotation added to the UI that is not meant to have a user interaction in any way, so that even if
* the mouse cursor is above it, the UI is not recognised as such. This is useful on UIs that spawn a
* tooltip and the said UI is checking if the mouse cursor is NOT above any other overlaid UI (e.g. a message box)
*/
annotation class UINotControllable