mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-12 14:51:51 +09:00
found a bug on uiFixture and the only solution would be creating a cut-down copy of the original ui
This commit is contained in:
@@ -713,7 +713,7 @@ fun printStackTrace(obj: Any, out: PrintStream = System.out) {
|
||||
}
|
||||
|
||||
class UIContainer {
|
||||
private val data = ArrayList<Any>()
|
||||
internal val data = ArrayList<Any>()
|
||||
fun add(vararg things: Any) {
|
||||
things.forEach {
|
||||
if (it is UICanvas || it is Id_UICanvasNullable)
|
||||
@@ -741,8 +741,28 @@ class UIContainer {
|
||||
else throw IllegalArgumentException("Unacceptable type ${it.javaClass.name}, instance of ${it.javaClass.superclass.name}")
|
||||
}
|
||||
}
|
||||
fun iterator2() = object : Iterator<Pair<Int, UICanvas?>> {
|
||||
private var cursor = 0
|
||||
|
||||
override fun hasNext() = cursor < data.size
|
||||
|
||||
override fun next(): Pair<Int, UICanvas?> {
|
||||
val it = data[cursor]
|
||||
// whatever the fucking reason when() does not work
|
||||
if (it is UICanvas) {
|
||||
cursor += 1
|
||||
return (cursor - 1) to it
|
||||
}
|
||||
else if (it is Id_UICanvasNullable) {
|
||||
cursor += 1
|
||||
return (cursor - 1) to it.get()
|
||||
}
|
||||
else throw IllegalArgumentException("Unacceptable type ${it.javaClass.name}, instance of ${it.javaClass.superclass.name}")
|
||||
}
|
||||
}
|
||||
|
||||
fun forEach(operation: (UICanvas?) -> Unit) = iterator().forEach(operation)
|
||||
fun forEachIndexed(operation: (Pair<Int, UICanvas?>) -> Unit) = iterator2().forEach(operation)
|
||||
fun countVisible(): Int {
|
||||
var c = 0
|
||||
forEach { if (it?.isVisible == true) c += 1 }
|
||||
|
||||
@@ -11,9 +11,11 @@ import com.jme3.math.FastMath
|
||||
import net.torvald.random.HQRNG
|
||||
import net.torvald.terrarum.App.IS_DEVELOPMENT_BUILD
|
||||
import net.torvald.terrarum.gamecontroller.KeyToggler
|
||||
import net.torvald.terrarum.savegame.toHex
|
||||
import net.torvald.terrarum.ui.BasicDebugInfoWindow
|
||||
import net.torvald.terrarum.ui.Toolkit
|
||||
import net.torvald.terrarum.weather.WeatherMixer
|
||||
import net.torvald.unsafe.UnsafeHelper
|
||||
|
||||
/**
|
||||
* Must be called by the App Loader
|
||||
@@ -150,7 +152,7 @@ object TerrarumPostProcessor : Disposable {
|
||||
// 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)
|
||||
App.fontSmallNumbers.draw(it, "${ccY}-$ccG ${ui.javaClass.simpleName} (0x${UnsafeHelper.addressOf(ui).toHex()})", 2f, 28f + 13*i)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1011,6 +1011,8 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
|
||||
filterVisibleActors()
|
||||
}
|
||||
|
||||
if (uiInventoryPlayer == uiFixture) throw IllegalStateException("Do NOT use InventoryPlayer as a UIFixture, the engine cannot handle this situation XwX")
|
||||
|
||||
uiContainer.forEach {
|
||||
|
||||
// suppress inventory opening if fixture inventory is opened
|
||||
|
||||
@@ -58,6 +58,20 @@ internal object UnsafeHelper {
|
||||
* @return offset from the array's base memory address (aka pointer) that the actual data begins.
|
||||
*/
|
||||
fun getArrayOffset(obj: Any) = unsafe.arrayBaseOffset(obj.javaClass).toLong()
|
||||
|
||||
|
||||
fun addressOf(o: Any): Long {
|
||||
val array = arrayOf(o)
|
||||
|
||||
val baseOffset = unsafe.arrayBaseOffset(Array<Any>::class.java).toLong()
|
||||
val addressSize = unsafe.addressSize()
|
||||
val objectAddress = when (addressSize) {
|
||||
4 -> unsafe.getInt(array, baseOffset).toLong()
|
||||
8 -> unsafe.getLong(array, baseOffset)
|
||||
else -> throw Error("unsupported address size: $addressSize")
|
||||
}
|
||||
return (objectAddress)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user