mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-08 12:51:51 +09:00
fix: non-pausing UIs AND the ingame control are both getting input processed
This commit is contained in:
@@ -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 uiContainer = UIContainer()
|
||||
|
||||
init {
|
||||
consoleHandler.setPosition(0, 0)
|
||||
notifier.setPosition(
|
||||
|
||||
@@ -32,6 +32,7 @@ import net.torvald.terrarum.itemproperties.MaterialCodex
|
||||
import net.torvald.terrarum.savegame.DiskSkimmer
|
||||
import net.torvald.terrarum.serialise.Common
|
||||
import net.torvald.terrarum.ui.UICanvas
|
||||
import net.torvald.terrarum.ui.UINotControllable
|
||||
import net.torvald.terrarum.worlddrawer.WorldCamera
|
||||
import net.torvald.terrarumsansbitmap.gdx.TerrarumSansBitmap
|
||||
import net.torvald.unsafe.UnsafeHelper
|
||||
@@ -40,6 +41,7 @@ import org.dyn4j.geometry.Vector2
|
||||
import java.io.File
|
||||
import java.io.PrintStream
|
||||
import kotlin.math.*
|
||||
import kotlin.reflect.full.findAnnotation
|
||||
|
||||
|
||||
typealias RGBA8888 = Int
|
||||
@@ -750,6 +752,26 @@ class UIContainer {
|
||||
fun <T> map(transformation: (UICanvas?) -> T) = iterator().asSequence().map(transformation)
|
||||
|
||||
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 {
|
||||
|
||||
@@ -144,7 +144,14 @@ object TerrarumPostProcessor : Disposable {
|
||||
if (KeyToggler.isOn(Input.Keys.F10)) {
|
||||
batch.color = Color.WHITE
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,10 +10,12 @@ import com.jme3.math.FastMath
|
||||
import net.torvald.random.HQRNG
|
||||
import net.torvald.terrarum.ui.Toolkit
|
||||
import net.torvald.terrarum.ui.UICanvas
|
||||
import net.torvald.terrarum.ui.UINotControllable
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2021-09-09.
|
||||
*/
|
||||
@UINotControllable
|
||||
class UIFakeGradOverlay : UICanvas() {
|
||||
init {
|
||||
handler.allowESCtoClose = false
|
||||
@@ -68,6 +70,7 @@ class UIFakeGradOverlay : UICanvas() {
|
||||
override fun dispose() {}
|
||||
}
|
||||
|
||||
@UINotControllable
|
||||
class UIFakeBlurOverlay(val blurRadius: Float, val nodarken: Boolean) : UICanvas() {
|
||||
init {
|
||||
handler.allowESCtoClose = false
|
||||
|
||||
@@ -16,6 +16,7 @@ import net.torvald.terrarum.gameworld.fmod
|
||||
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.DroppedItem
|
||||
import net.torvald.terrarum.modulebasegame.ui.UIQuickslotBar
|
||||
import net.torvald.terrarum.ui.UICanvas
|
||||
import net.torvald.terrarum.worlddrawer.WorldCamera
|
||||
import org.dyn4j.geometry.Vector2
|
||||
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)
|
||||
// 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 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
|
||||
@@ -159,7 +160,6 @@ class IngameController(val terrarumIngame: TerrarumIngame) : InputAdapter() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
updateKeyboard()
|
||||
}
|
||||
|
||||
@@ -272,7 +272,7 @@ class IngameController(val terrarumIngame: TerrarumIngame) : InputAdapter() {
|
||||
}
|
||||
|
||||
override fun scrolled(amountX: Float, amountY: Float): Boolean {
|
||||
if (!terrarumIngame.paused) {
|
||||
if (!terrarumIngame.paused && terrarumIngame.uiContainer.hasNoUIsUnderMouse) {
|
||||
// quickslot by wheel
|
||||
terrarumIngame.actorNowPlaying?.let {
|
||||
var selection = it.actorValue.getAsInt(AVKey.__PLAYER_QUICKSLOTSEL)!!
|
||||
|
||||
@@ -87,8 +87,6 @@ class BuildingMaker(batch: FlippingSpriteBatch) : IngameInstance(batch) {
|
||||
|
||||
val uiGetPoiName = UIBuildingMakerGetFilename() // used for both import and export
|
||||
|
||||
val uiContainer = UIContainer()
|
||||
|
||||
val keyboardUsedByTextInput: Boolean
|
||||
get() = uiGetPoiName.textInput.isEnabled
|
||||
|
||||
|
||||
@@ -88,7 +88,6 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
|
||||
//val ACTORCONTAINER_INITIAL_SIZE = 64
|
||||
val PARTICLES_MAX = App.getConfigInt("maxparticles")
|
||||
val particlesContainer = CircularArray<ParticleBase>(PARTICLES_MAX, true)
|
||||
val uiContainer = UIContainer()
|
||||
|
||||
// these are required because actors always change their position
|
||||
private var visibleActorsRenderBehind: ArrayList<ActorWithBody> = ArrayList(1)
|
||||
|
||||
@@ -146,7 +146,6 @@ class TitleScreen(batch: FlippingSpriteBatch) : IngameInstance(batch) {
|
||||
private val gradWhiteBottom = Color(0xd8d8d8ff.toInt())
|
||||
|
||||
|
||||
val uiContainer = UIContainer()
|
||||
internal lateinit var uiRemoCon: UIRemoCon
|
||||
internal lateinit var uiFakeBlurOverlay: UICanvas
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ import net.torvald.terrarum.gameworld.fmod
|
||||
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
||||
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellCommonRes.toItemCountText
|
||||
import net.torvald.terrarum.ui.UICanvas
|
||||
import net.torvald.terrarum.ui.UINotControllable
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
/**
|
||||
@@ -18,6 +19,7 @@ import kotlin.math.roundToInt
|
||||
*
|
||||
* Created by minjaesong on 2016-07-20.
|
||||
*/
|
||||
@UINotControllable
|
||||
class UIQuickslotBar : UICanvas() {
|
||||
|
||||
init {
|
||||
|
||||
@@ -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.ui.Toolkit
|
||||
import net.torvald.terrarum.ui.UICanvas
|
||||
import net.torvald.terrarum.ui.UINotControllable
|
||||
import org.dyn4j.geometry.Vector2
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
@@ -21,6 +22,7 @@ import kotlin.math.roundToInt
|
||||
*
|
||||
* Created by minjaesong on 2016-07-20.
|
||||
*/
|
||||
@UINotControllable
|
||||
class UIQuickslotPie : UICanvas() {
|
||||
|
||||
init {
|
||||
|
||||
@@ -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.ui.Movement
|
||||
import net.torvald.terrarum.ui.UICanvas
|
||||
import net.torvald.terrarum.ui.UINotControllable
|
||||
import net.torvald.unicode.EMDASH
|
||||
import net.torvald.unicode.getKeycapPC
|
||||
import kotlin.math.roundToInt
|
||||
@@ -19,6 +20,7 @@ import kotlin.math.roundToInt
|
||||
*
|
||||
* Created by minjaesong on 2019-08-11.
|
||||
*/
|
||||
@UINotControllable
|
||||
class UIScreenZoom : UICanvas(
|
||||
"control_key_zoom"
|
||||
) {
|
||||
|
||||
@@ -9,10 +9,12 @@ import net.torvald.terrarum.Second
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.ui.Toolkit
|
||||
import net.torvald.terrarum.ui.UICanvas
|
||||
import net.torvald.terrarum.ui.UINotControllable
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2017-11-25.
|
||||
*/
|
||||
@UINotControllable
|
||||
class UITooltip : UICanvas() {
|
||||
|
||||
init {
|
||||
|
||||
@@ -10,6 +10,7 @@ import net.torvald.terrarum.gameworld.WorldTime
|
||||
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
||||
import net.torvald.terrarum.ui.Toolkit
|
||||
import net.torvald.terrarum.ui.UICanvas
|
||||
import net.torvald.terrarum.ui.UINotControllable
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
import kotlin.math.cos
|
||||
import kotlin.math.roundToInt
|
||||
@@ -18,6 +19,7 @@ import kotlin.math.sin
|
||||
/**
|
||||
* Created by minjaesong on 2023-09-09.
|
||||
*/
|
||||
@UINotControllable
|
||||
class UIWatchLargeAnalogue() : UICanvas() {
|
||||
|
||||
override var width = 76
|
||||
|
||||
@@ -10,12 +10,14 @@ import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.gameworld.WorldTime
|
||||
import net.torvald.terrarum.modulebasegame.imagefont.WatchFont
|
||||
import net.torvald.terrarum.ui.UICanvas
|
||||
import net.torvald.terrarum.ui.UINotControllable
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2017-06-11.
|
||||
*/
|
||||
@UINotControllable
|
||||
class UIWatchLargeDigital() : UICanvas() {
|
||||
override var width = 162
|
||||
override var height = 25
|
||||
|
||||
@@ -12,6 +12,7 @@ import kotlin.math.roundToInt
|
||||
/**
|
||||
* Created by minjaesong on 2021-10-01.
|
||||
*/
|
||||
@UINotControllable
|
||||
class UIAutosaveNotifier : UICanvas() {
|
||||
|
||||
init {
|
||||
|
||||
@@ -431,3 +431,10 @@ abstract class UICanvas(
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user