mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 20:31:51 +09:00
adjusting disposing behavs so that we can go back and forth the ingame and titlescr
This commit is contained in:
@@ -435,6 +435,11 @@ public class AppLoader implements ApplicationListener {
|
||||
IngameRenderer.INSTANCE.dispose();
|
||||
if (Controllers.isCreated()) Controllers.destroy();
|
||||
|
||||
Terrarum.INSTANCE.dispose();
|
||||
|
||||
fontGame.dispose();
|
||||
fontSmallNumbers.dispose();
|
||||
|
||||
// delete temp files
|
||||
new File("./tmp_wenquanyi.tga").delete(); // FIXME this is pretty much ad-hoc
|
||||
}
|
||||
|
||||
@@ -313,7 +313,6 @@ object LoadScreen : ScreenAdapter() {
|
||||
}
|
||||
|
||||
override fun hide() {
|
||||
dispose()
|
||||
}
|
||||
|
||||
override fun resize(width: Int, height: Int) {
|
||||
|
||||
@@ -401,24 +401,15 @@ object Terrarum : Screen {
|
||||
AppLoader.getINSTANCE().screen.resume()
|
||||
}
|
||||
|
||||
/** Don't call this! Call AppLoader.dispose() */
|
||||
override fun dispose() {
|
||||
AppLoader.getINSTANCE().screen.dispose()
|
||||
|
||||
fontGame.dispose()
|
||||
fontSmallNumbers.dispose()
|
||||
|
||||
|
||||
//dispose any other resources used in this level
|
||||
|
||||
|
||||
shaderBayer.dispose()
|
||||
shaderSkyboxFill.dispose()
|
||||
shaderBlur.dispose()
|
||||
shaderBlendGlow.dispose()
|
||||
|
||||
|
||||
shapeRender.dispose()
|
||||
batch.dispose()
|
||||
ingame?.dispose()
|
||||
}
|
||||
|
||||
override fun hide() {
|
||||
|
||||
@@ -105,7 +105,7 @@ class UIItemInventoryCatBar(
|
||||
|
||||
private val highlighterYPos = catIcons.tileH + 4f
|
||||
private var highlighterMoving = false
|
||||
private val highlighterMoveDuration: Second = 0.1f
|
||||
private val highlighterMoveDuration: Second = 0.15f
|
||||
private var highlighterMoveTimer: Second = 0f
|
||||
|
||||
private var transitionFired = false
|
||||
|
||||
@@ -123,7 +123,10 @@ inline class Yaml(val text: String) {
|
||||
val nodeString = it.drop(2)
|
||||
val nodeNameAndInvocation = nodeString.split(SEPARATOR)
|
||||
val nodeName = nodeNameAndInvocation[0]
|
||||
val nodeInvocation = loadClass(nodeNameAndInvocation[1])
|
||||
val nodeInvocation = if (nodeNameAndInvocation.size == 2)
|
||||
loadClass(nodeNameAndInvocation[1])
|
||||
else
|
||||
null
|
||||
|
||||
val nameInvokePair = nodeName to nodeInvocation
|
||||
|
||||
@@ -193,5 +196,5 @@ inline class Yaml(val text: String) {
|
||||
*
|
||||
*/
|
||||
interface YamlInvokable {
|
||||
operator fun invoke()
|
||||
operator fun invoke(vararg args: Any?)
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.torvald.terrarum.console
|
||||
|
||||
import net.torvald.terrarum.console.ConsoleCommand
|
||||
import com.badlogic.gdx.Gdx
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2016-01-15.
|
||||
@@ -8,7 +8,7 @@ import net.torvald.terrarum.console.ConsoleCommand
|
||||
internal object QuitApp : ConsoleCommand {
|
||||
|
||||
override fun execute(args: Array<String>) {
|
||||
System.exit(1)
|
||||
Gdx.app.exit()
|
||||
}
|
||||
|
||||
override fun printUsage() {
|
||||
|
||||
@@ -4,10 +4,7 @@ import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.InputAdapter
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import net.torvald.terrarum.AppLoader
|
||||
import net.torvald.terrarum.IngameInstance
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.Yaml
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.blockproperties.Block
|
||||
import net.torvald.terrarum.gameactors.*
|
||||
import net.torvald.terrarum.gamecontroller.KeyToggler
|
||||
@@ -20,7 +17,6 @@ import net.torvald.terrarum.ui.UINSMenu
|
||||
import net.torvald.terrarum.worlddrawer.LightmapRenderer
|
||||
import net.torvald.terrarum.worlddrawer.WorldCamera
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
import kotlin.system.measureNanoTime
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2018-07-06.
|
||||
@@ -35,6 +31,7 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
- Import…
|
||||
- Save world…
|
||||
- Load world…
|
||||
- Exit to Title : net.torvald.terrarum.modulebasegame.YamlCommandExit
|
||||
- Tool
|
||||
- Pencil
|
||||
- Eyedropper
|
||||
@@ -135,6 +132,7 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
|
||||
uiToolbox.setPosition(0, 0)
|
||||
uiToolbox.isVisible = true
|
||||
|
||||
notifier.setPosition(
|
||||
(Terrarum.WIDTH - notifier.width) / 2, Terrarum.HEIGHT - notifier.height)
|
||||
|
||||
@@ -259,4 +257,10 @@ class MovableWorldCamera : ActorHumanoid(0, usePhysics = false) {
|
||||
override fun onActorValueChange(key: String, value: Any?) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class YamlCommandExit : YamlInvokable {
|
||||
override fun invoke(vararg args: Any?) {
|
||||
Terrarum.setScreen(TitleScreen(Terrarum.batch))
|
||||
}
|
||||
}
|
||||
@@ -22,8 +22,6 @@ import net.torvald.terrarum.modulebasegame.gameactors.*
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.physicssolver.CollisionSolver
|
||||
import net.torvald.terrarum.modulebasegame.gameworld.GameWorldExtension
|
||||
import net.torvald.terrarum.modulebasegame.gameworld.WorldSimulator
|
||||
import net.torvald.terrarum.modulebasegame.imagefont.Watch7SegMain
|
||||
import net.torvald.terrarum.modulebasegame.imagefont.WatchDotAlph
|
||||
import net.torvald.terrarum.modulebasegame.ui.*
|
||||
import net.torvald.terrarum.modulebasegame.weather.WeatherMixer
|
||||
import net.torvald.terrarum.modulebasegame.worldgenerator.RoguelikeRandomiser
|
||||
@@ -890,7 +888,7 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
}
|
||||
|
||||
override fun hide() {
|
||||
dispose()
|
||||
uiContainer.forEach { it.handler.dispose() }
|
||||
}
|
||||
|
||||
|
||||
@@ -943,26 +941,16 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
IngameRenderer.dispose()
|
||||
|
||||
actorsRenderBehind.forEach { it.dispose() }
|
||||
actorsRenderMiddle.forEach { it.dispose() }
|
||||
actorsRenderMidTop.forEach { it.dispose() }
|
||||
actorsRenderFront.forEach { it.dispose() }
|
||||
actorsRenderOverlay.forEach { it.dispose() }
|
||||
|
||||
uiAliases.forEach { it.dispose() }
|
||||
uiAliasesPausing.forEach { it.dispose() }
|
||||
|
||||
|
||||
WatchDotAlph.dispose()
|
||||
Watch7SegMain.dispose()
|
||||
WatchDotAlph.dispose()
|
||||
|
||||
ItemSlotImageFactory.dispose()
|
||||
|
||||
MessageWindow.SEGMENT_BLACK.dispose()
|
||||
MessageWindow.SEGMENT_WHITE.dispose()
|
||||
uiContainer.forEach {
|
||||
it.handler.dispose()
|
||||
it.dispose()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -135,7 +135,7 @@ class UIInventoryFull(
|
||||
private var transitionReqSource = SCREEN_INVENTORY
|
||||
private var transitionReqTarget = SCREEN_INVENTORY
|
||||
private var transitionTimer = 0f
|
||||
private val transitionLength = 0.333f
|
||||
private val transitionLength = 0.212f
|
||||
|
||||
|
||||
private val transitionalUpdateUIs = ArrayList<UIItem>()
|
||||
@@ -174,6 +174,16 @@ class UIInventoryFull(
|
||||
addToTransitionalGroup(itemList)
|
||||
addToTransitionalGroup(equipped)
|
||||
addToTransitionalGroup(gameMenuButtons)
|
||||
|
||||
// make gameMenuButtons work
|
||||
gameMenuButtons.selectionChangeListener = { old, new ->
|
||||
if (new == 0) {
|
||||
Terrarum.setScreen(TitleScreen(Terrarum.batch))
|
||||
}
|
||||
else if (new == 1) {
|
||||
Gdx.app.exit()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var offsetX = ((Terrarum.WIDTH - internalWidth) / 2).toFloat()
|
||||
|
||||
@@ -3,6 +3,7 @@ package net.torvald.terrarum.ui
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.graphics.Camera
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import com.badlogic.gdx.utils.Disposable
|
||||
import net.torvald.terrarum.AppLoader
|
||||
import net.torvald.terrarum.Second
|
||||
import net.torvald.terrarum.Terrarum
|
||||
@@ -21,7 +22,7 @@ abstract class UICanvas(
|
||||
// UI positions itself? (you must g.flush() yourself after the g.translate(Int, Int))
|
||||
customPositioning: Boolean = false, // mainly used by vital meter
|
||||
doNotWarnConstant: Boolean = false
|
||||
) {
|
||||
): Disposable {
|
||||
|
||||
abstract var width: Int
|
||||
abstract var height: Int
|
||||
@@ -36,7 +37,7 @@ abstract class UICanvas(
|
||||
/**
|
||||
* Usage: (in StateInGame:) uiHandlerField.ui.handler = uiHandlerField
|
||||
*/
|
||||
protected val handler = UIHandler(toggleKeyLiteral, toggleButtonLiteral, customPositioning, doNotWarnConstant)
|
||||
val handler = UIHandler(toggleKeyLiteral, toggleButtonLiteral, customPositioning, doNotWarnConstant)
|
||||
|
||||
init {
|
||||
|
||||
@@ -111,7 +112,7 @@ abstract class UICanvas(
|
||||
*/
|
||||
abstract fun endClosing(delta: Float)
|
||||
|
||||
abstract fun dispose()
|
||||
abstract override fun dispose()
|
||||
|
||||
fun addItem(uiItem: UIItem) {
|
||||
uiItems.add(uiItem)
|
||||
|
||||
@@ -3,8 +3,9 @@ package net.torvald.terrarum.ui
|
||||
import com.badlogic.gdx.graphics.Camera
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import net.torvald.terrarum.modulebasegame.Ingame
|
||||
import com.badlogic.gdx.utils.Disposable
|
||||
import net.torvald.terrarum.gamecontroller.KeyToggler
|
||||
import net.torvald.terrarum.modulebasegame.Ingame
|
||||
|
||||
/**
|
||||
* UIHandler is a handler for UICanvas. It opens/closes the attached UI, moves the "window" (or "canvas")
|
||||
@@ -20,7 +21,7 @@ class UIHandler(//var UI: UICanvas,
|
||||
// UI positions itself? (you must g.flush() yourself after the g.translate(Int, Int))
|
||||
var customPositioning: Boolean = false, // mainly used by vital meter
|
||||
var doNotWarnConstant: Boolean = false
|
||||
) {
|
||||
): Disposable {
|
||||
|
||||
// X/Y Position relative to the game window.
|
||||
var posX: Int = 0
|
||||
@@ -341,4 +342,10 @@ class UIHandler(//var UI: UICanvas,
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/** Don't dispose common assets, this function is called when the ingame does hide() */
|
||||
override fun dispose() {
|
||||
toggleKey?.let { KeyToggler.forceSet(it, false) }
|
||||
toggleButton?.let { /* ButtonToggler.forceSet(it, false) */ }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import net.torvald.terrarum.*
|
||||
class UINSMenu(
|
||||
var title: String = "",
|
||||
val minimumWidth: Int,
|
||||
/** Optional instance of YamlInvokable can be used */
|
||||
treeRepresentation: Yaml,
|
||||
|
||||
val titleBackCol: Color = Color(0f,0f,0f,.77f),
|
||||
@@ -29,7 +30,7 @@ class UINSMenu(
|
||||
val CHILD_ARROW = "${0x2023.toChar()}"
|
||||
|
||||
|
||||
val tree = treeRepresentation.parse()
|
||||
val tree = treeRepresentation.parseAsYamlInvokable()
|
||||
override var width = 0
|
||||
override var height = 0
|
||||
//override var width = maxOf(minimumWidth, tree.getLevelData(1).map { Terrarum.fontGame.getWidth(it ?: "") }.max() ?: 0)
|
||||
@@ -53,10 +54,10 @@ class UINSMenu(
|
||||
addSubMenu(tree)
|
||||
}
|
||||
|
||||
private fun addSubMenu(tree: QNDTreeNode<String>) {
|
||||
val menuTitle = tree.data ?: title
|
||||
private fun addSubMenu(tree: QNDTreeNode<Pair<String, YamlInvokable?>>) {
|
||||
val menuTitle = tree.data?.first ?: title
|
||||
val stringsFromTree = Array<String>(tree.children.size) {
|
||||
tree.children[it].toString() + if (tree.children[it].children.isNotEmpty()) " $CHILD_ARROW" else ""
|
||||
tree.children[it].data?.first + if (tree.children[it].children.isNotEmpty()) " $CHILD_ARROW" else ""
|
||||
}
|
||||
|
||||
val listWidth = maxOf(
|
||||
@@ -98,6 +99,10 @@ class UINSMenu(
|
||||
if (tree.children[new].children.isNotEmpty()) {
|
||||
addSubMenu(tree.children[new])
|
||||
}
|
||||
|
||||
// invoke whatever command there is
|
||||
//printdbg(this, "Selected: ${tree.children[new].data?.second}")
|
||||
tree.children[new].data?.second?.invoke()
|
||||
}
|
||||
// END List selection change listener
|
||||
|
||||
|
||||
Reference in New Issue
Block a user