mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 12:21:52 +09:00
disposable singletons to an array in loader; single float for both notification and tooltip
This commit is contained in:
8
.idea/markdown-exported-files.xml
generated
Normal file
8
.idea/markdown-exported-files.xml
generated
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="MarkdownExportedFiles">
|
||||||
|
<htmlFiles />
|
||||||
|
<imageFiles />
|
||||||
|
<otherFiles />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@@ -38,7 +38,7 @@
|
|||||||
<property name="caretWidth" class="java.lang.Integer" />
|
<property name="caretWidth" class="java.lang.Integer" />
|
||||||
</properties>
|
</properties>
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_10" default="false" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="false" project-jdk-name="13-incubate" project-jdk-type="JavaSDK">
|
||||||
<output url="file://$PROJECT_DIR$/out" />
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
@@ -13,20 +13,19 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
|||||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||||
import com.badlogic.gdx.graphics.glutils.FrameBuffer;
|
import com.badlogic.gdx.graphics.glutils.FrameBuffer;
|
||||||
import com.badlogic.gdx.graphics.glutils.ShaderProgram;
|
import com.badlogic.gdx.graphics.glutils.ShaderProgram;
|
||||||
|
import com.badlogic.gdx.utils.Disposable;
|
||||||
import com.badlogic.gdx.utils.ScreenUtils;
|
import com.badlogic.gdx.utils.ScreenUtils;
|
||||||
import com.github.strikerx3.jxinput.XInputDevice;
|
import com.github.strikerx3.jxinput.XInputDevice;
|
||||||
import com.google.gson.JsonArray;
|
import com.google.gson.JsonArray;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.google.gson.JsonPrimitive;
|
import com.google.gson.JsonPrimitive;
|
||||||
import net.torvald.getcpuname.GetCpuName;
|
import net.torvald.getcpuname.GetCpuName;
|
||||||
import net.torvald.terrarum.blockstats.MinimapComposer;
|
|
||||||
import net.torvald.terrarum.controller.GdxControllerAdapter;
|
import net.torvald.terrarum.controller.GdxControllerAdapter;
|
||||||
import net.torvald.terrarum.controller.TerrarumController;
|
import net.torvald.terrarum.controller.TerrarumController;
|
||||||
import net.torvald.terrarum.controller.XinputControllerAdapter;
|
import net.torvald.terrarum.controller.XinputControllerAdapter;
|
||||||
import net.torvald.terrarum.gamecontroller.KeyToggler;
|
import net.torvald.terrarum.gamecontroller.KeyToggler;
|
||||||
import net.torvald.terrarum.imagefont.TinyAlphNum;
|
import net.torvald.terrarum.imagefont.TinyAlphNum;
|
||||||
import net.torvald.terrarum.modulebasegame.Ingame;
|
import net.torvald.terrarum.modulebasegame.Ingame;
|
||||||
import net.torvald.terrarum.modulebasegame.IngameRenderer;
|
|
||||||
import net.torvald.terrarum.utils.JsonFetcher;
|
import net.torvald.terrarum.utils.JsonFetcher;
|
||||||
import net.torvald.terrarum.utils.JsonWriter;
|
import net.torvald.terrarum.utils.JsonWriter;
|
||||||
import net.torvald.terrarum.worlddrawer.BlocksDrawer;
|
import net.torvald.terrarum.worlddrawer.BlocksDrawer;
|
||||||
@@ -286,6 +285,7 @@ public class AppLoader implements ApplicationListener {
|
|||||||
|
|
||||||
public static CommonResourcePool resourcePool;
|
public static CommonResourcePool resourcePool;
|
||||||
public static HashSet<File> tempFilePool = new HashSet();
|
public static HashSet<File> tempFilePool = new HashSet();
|
||||||
|
public static HashSet<Disposable> disposableSingletonsPool = new HashSet();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void create() {
|
public void create() {
|
||||||
@@ -517,11 +517,12 @@ public class AppLoader implements ApplicationListener {
|
|||||||
screen.dispose();
|
screen.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
IngameRenderer.INSTANCE.dispose();
|
//IngameRenderer.INSTANCE.dispose();
|
||||||
PostProcessor.INSTANCE.dispose();
|
//PostProcessor.INSTANCE.dispose();
|
||||||
MinimapComposer.INSTANCE.dispose();
|
//MinimapComposer.INSTANCE.dispose();
|
||||||
|
//FloatDrawer.INSTANCE.dispose();
|
||||||
|
|
||||||
Terrarum.INSTANCE.dispose();
|
//Terrarum.INSTANCE.dispose();
|
||||||
|
|
||||||
shaderBayerSkyboxFill.dispose();
|
shaderBayerSkyboxFill.dispose();
|
||||||
shaderHicolour.dispose();
|
shaderHicolour.dispose();
|
||||||
@@ -539,6 +540,8 @@ public class AppLoader implements ApplicationListener {
|
|||||||
textureWhiteCircle.dispose();
|
textureWhiteCircle.dispose();
|
||||||
logo.getTexture().dispose();
|
logo.getTexture().dispose();
|
||||||
|
|
||||||
|
disposableSingletonsPool.forEach(Disposable::dispose);
|
||||||
|
|
||||||
ModMgr.INSTANCE.disposeMods();
|
ModMgr.INSTANCE.disposeMods();
|
||||||
|
|
||||||
deleteTempfiles();
|
deleteTempfiles();
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import com.badlogic.gdx.graphics.glutils.FrameBuffer
|
|||||||
import com.badlogic.gdx.graphics.glutils.ShaderProgram
|
import com.badlogic.gdx.graphics.glutils.ShaderProgram
|
||||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer
|
import com.badlogic.gdx.graphics.glutils.ShapeRenderer
|
||||||
import com.badlogic.gdx.math.Matrix4
|
import com.badlogic.gdx.math.Matrix4
|
||||||
|
import com.badlogic.gdx.utils.Disposable
|
||||||
import net.torvald.terrarum.gamecontroller.KeyToggler
|
import net.torvald.terrarum.gamecontroller.KeyToggler
|
||||||
import net.torvald.terrarum.ui.BasicDebugInfoWindow
|
import net.torvald.terrarum.ui.BasicDebugInfoWindow
|
||||||
import net.torvald.terrarum.worlddrawer.BlocksDrawer
|
import net.torvald.terrarum.worlddrawer.BlocksDrawer
|
||||||
@@ -18,7 +19,7 @@ import net.torvald.terrarum.worlddrawer.BlocksDrawer
|
|||||||
/**
|
/**
|
||||||
* Must be called by the App Loader
|
* Must be called by the App Loader
|
||||||
*/
|
*/
|
||||||
object PostProcessor {
|
object PostProcessor : Disposable {
|
||||||
|
|
||||||
private lateinit var batch: SpriteBatch // not nulling to save some lines of code
|
private lateinit var batch: SpriteBatch // not nulling to save some lines of code
|
||||||
private lateinit var shapeRenderer: ShapeRenderer
|
private lateinit var shapeRenderer: ShapeRenderer
|
||||||
@@ -40,7 +41,11 @@ object PostProcessor {
|
|||||||
|
|
||||||
private var functionRowHelper = Texture(Gdx.files.internal("assets/graphics/function_row_help.png"))
|
private var functionRowHelper = Texture(Gdx.files.internal("assets/graphics/function_row_help.png"))
|
||||||
|
|
||||||
fun dispose() {
|
init {
|
||||||
|
AppLoader.disposableSingletonsPool.add(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun dispose() {
|
||||||
batch.dispose()
|
batch.dispose()
|
||||||
shapeRenderer.dispose()
|
shapeRenderer.dispose()
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
|||||||
import com.badlogic.gdx.graphics.glutils.FrameBuffer
|
import com.badlogic.gdx.graphics.glutils.FrameBuffer
|
||||||
import com.badlogic.gdx.graphics.glutils.ShaderProgram
|
import com.badlogic.gdx.graphics.glutils.ShaderProgram
|
||||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer
|
import com.badlogic.gdx.graphics.glutils.ShapeRenderer
|
||||||
|
import com.badlogic.gdx.utils.Disposable
|
||||||
import com.badlogic.gdx.utils.GdxRuntimeException
|
import com.badlogic.gdx.utils.GdxRuntimeException
|
||||||
import com.jme3.math.FastMath
|
import com.jme3.math.FastMath
|
||||||
import net.torvald.random.HQRNG
|
import net.torvald.random.HQRNG
|
||||||
@@ -37,7 +38,7 @@ typealias RGBA8888 = Int
|
|||||||
*
|
*
|
||||||
* LibGDX Version Created by minjaesong on 2017-06-15.
|
* LibGDX Version Created by minjaesong on 2017-06-15.
|
||||||
*/
|
*/
|
||||||
object Terrarum : Screen {
|
object Terrarum : Screen, Disposable {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* All singleplayer "Player" must have this exact reference ID.
|
* All singleplayer "Player" must have this exact reference ID.
|
||||||
@@ -212,6 +213,9 @@ object Terrarum : Screen {
|
|||||||
|
|
||||||
setGamepadButtonLabels()
|
setGamepadButtonLabels()
|
||||||
|
|
||||||
|
|
||||||
|
AppLoader.disposableSingletonsPool.add(this)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setGamepadButtonLabels() {
|
private fun setGamepadButtonLabels() {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package net.torvald.terrarum.blockstats
|
|||||||
|
|
||||||
import com.badlogic.gdx.graphics.Pixmap
|
import com.badlogic.gdx.graphics.Pixmap
|
||||||
import com.badlogic.gdx.graphics.Texture
|
import com.badlogic.gdx.graphics.Texture
|
||||||
|
import com.badlogic.gdx.utils.Disposable
|
||||||
import com.badlogic.gdx.utils.GdxRuntimeException
|
import com.badlogic.gdx.utils.GdxRuntimeException
|
||||||
import com.badlogic.gdx.utils.Queue
|
import com.badlogic.gdx.utils.Queue
|
||||||
import net.torvald.terrarum.AppLoader
|
import net.torvald.terrarum.AppLoader
|
||||||
@@ -12,7 +13,7 @@ import net.torvald.terrarum.gameworld.GameWorld
|
|||||||
import net.torvald.terrarum.worlddrawer.BlocksDrawer
|
import net.torvald.terrarum.worlddrawer.BlocksDrawer
|
||||||
import net.torvald.terrarum.worlddrawer.CreateTileAtlas
|
import net.torvald.terrarum.worlddrawer.CreateTileAtlas
|
||||||
|
|
||||||
object MinimapComposer {
|
object MinimapComposer : Disposable {
|
||||||
|
|
||||||
// strategy: mosaic the textures, maximum texture size is 4 096.
|
// strategy: mosaic the textures, maximum texture size is 4 096.
|
||||||
|
|
||||||
@@ -66,6 +67,8 @@ object MinimapComposer {
|
|||||||
init {
|
init {
|
||||||
totalWidth = minimap.width
|
totalWidth = minimap.width
|
||||||
totalHeight = minimap.height
|
totalHeight = minimap.height
|
||||||
|
|
||||||
|
AppLoader.disposableSingletonsPool.add(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun update() {
|
fun update() {
|
||||||
@@ -147,7 +150,7 @@ object MinimapComposer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun dispose() {
|
override fun dispose() {
|
||||||
liveTiles.forEach { it.dispose() }
|
liveTiles.forEach { it.dispose() }
|
||||||
minimap.dispose()
|
minimap.dispose()
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -602,10 +602,16 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Send message to notifier UI and toggle the UI as opened. */
|
/** Send message to notifier UI and toggle the UI as opened. */
|
||||||
fun sendNotification(msg1: String, msg2: String? = null) {
|
fun sendNotification(messages: Array<String>) {
|
||||||
(notifier as Notification).sendNotification(if (msg2 != null) arrayOf(msg1, msg2) else arrayOf(msg1))
|
(notifier as Notification).sendNotification(messages.toList())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun sendNotification(messages: List<String>) {
|
||||||
|
(notifier as Notification).sendNotification(messages)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun sendNotification(singleMessage: String) = sendNotification(listOf(singleMessage))
|
||||||
|
|
||||||
fun wakeDormantActors() {
|
fun wakeDormantActors() {
|
||||||
var actorContainerSize = actorContainerInactive.size
|
var actorContainerSize = actorContainerInactive.size
|
||||||
var i = 0
|
var i = 0
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import com.badlogic.gdx.Input
|
|||||||
import com.badlogic.gdx.graphics.*
|
import com.badlogic.gdx.graphics.*
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||||
import com.badlogic.gdx.graphics.glutils.FrameBuffer
|
import com.badlogic.gdx.graphics.glutils.FrameBuffer
|
||||||
|
import com.badlogic.gdx.utils.Disposable
|
||||||
import com.badlogic.gdx.utils.ScreenUtils
|
import com.badlogic.gdx.utils.ScreenUtils
|
||||||
import net.torvald.terrarum.*
|
import net.torvald.terrarum.*
|
||||||
import net.torvald.terrarum.gameactors.ActorWithBody
|
import net.torvald.terrarum.gameactors.ActorWithBody
|
||||||
@@ -23,7 +24,7 @@ import javax.swing.JFileChooser
|
|||||||
*
|
*
|
||||||
* For the entire render path, see AppLoader.
|
* For the entire render path, see AppLoader.
|
||||||
*/
|
*/
|
||||||
object IngameRenderer {
|
object IngameRenderer : Disposable {
|
||||||
/** for non-private use, use with care! */
|
/** for non-private use, use with care! */
|
||||||
lateinit var batch: SpriteBatch
|
lateinit var batch: SpriteBatch
|
||||||
private lateinit var camera: OrthographicCamera
|
private lateinit var camera: OrthographicCamera
|
||||||
@@ -61,6 +62,10 @@ object IngameRenderer {
|
|||||||
|
|
||||||
private var debugMode = 0
|
private var debugMode = 0
|
||||||
|
|
||||||
|
init {
|
||||||
|
AppLoader.disposableSingletonsPool.add(this)
|
||||||
|
}
|
||||||
|
|
||||||
operator fun invoke(
|
operator fun invoke(
|
||||||
gamePaused: Boolean,
|
gamePaused: Boolean,
|
||||||
world: GameWorldExtension,
|
world: GameWorldExtension,
|
||||||
@@ -604,7 +609,7 @@ object IngameRenderer {
|
|||||||
|
|
||||||
private val TILE_SIZEF = CreateTileAtlas.TILE_SIZE.toFloat()
|
private val TILE_SIZEF = CreateTileAtlas.TILE_SIZE.toFloat()
|
||||||
|
|
||||||
fun dispose() {
|
override fun dispose() {
|
||||||
fboRGB.dispose()
|
fboRGB.dispose()
|
||||||
fboA.dispose()
|
fboA.dispose()
|
||||||
fboRGB_lightMixed.dispose()
|
fboRGB_lightMixed.dispose()
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package net.torvald.terrarum.modulebasegame.console
|
|||||||
|
|
||||||
import net.torvald.terrarum.Terrarum
|
import net.torvald.terrarum.Terrarum
|
||||||
import net.torvald.terrarum.console.ConsoleCommand
|
import net.torvald.terrarum.console.ConsoleCommand
|
||||||
import net.torvald.terrarum.langpack.Lang
|
|
||||||
import net.torvald.terrarum.modulebasegame.Ingame
|
import net.torvald.terrarum.modulebasegame.Ingame
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -10,19 +9,14 @@ import net.torvald.terrarum.modulebasegame.Ingame
|
|||||||
*/
|
*/
|
||||||
internal object SetBulletin : ConsoleCommand {
|
internal object SetBulletin : ConsoleCommand {
|
||||||
override fun execute(args: Array<String>) {
|
override fun execute(args: Array<String>) {
|
||||||
send(Lang["ERROR_SAVE_CORRUPTED"], Lang["MENU_LABEL_CONTINUE_QUESTION"])
|
//send(Lang["ERROR_SAVE_CORRUPTED"], Lang["MENU_LABEL_CONTINUE_QUESTION"])
|
||||||
|
|
||||||
|
(Terrarum.ingame!! as Ingame).sendNotification(args.sliceArray(1..args.lastIndex))
|
||||||
|
println("sent notifinator")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun printUsage() {
|
override fun printUsage() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Actually send notifinator
|
|
||||||
* @param message real message
|
|
||||||
*/
|
|
||||||
fun send(msg1: String, msg2: String? = null) {
|
|
||||||
(Terrarum.ingame!! as Ingame).sendNotification(msg1, msg2)
|
|
||||||
println("sent notifinator")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
43
src/net/torvald/terrarum/modulebasegame/ui/FloatDrawer.kt
Normal file
43
src/net/torvald/terrarum/modulebasegame/ui/FloatDrawer.kt
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
package net.torvald.terrarum.modulebasegame.ui
|
||||||
|
|
||||||
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||||
|
import com.badlogic.gdx.utils.Disposable
|
||||||
|
import net.torvald.terrarum.AppLoader
|
||||||
|
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by minjaesong on 2019-05-24.
|
||||||
|
*/
|
||||||
|
object FloatDrawer : Disposable {
|
||||||
|
|
||||||
|
val tile = TextureRegionPack("assets/graphics/gui/message_black_tileable.tga", 8, 8)
|
||||||
|
|
||||||
|
init {
|
||||||
|
AppLoader.disposableSingletonsPool.add(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draws the Float at given position in given size. The size is that of the centre area, excluding the edges. Size of the edges are 8x8 pixels.
|
||||||
|
*/
|
||||||
|
operator fun invoke(batch: SpriteBatch, x: Float, y: Float, w: Float, h: Float) {
|
||||||
|
// centre area
|
||||||
|
batch.draw(tile.get(1, 1), x, y, w, h)
|
||||||
|
|
||||||
|
// edges
|
||||||
|
batch.draw(tile.get(1, 0), x, y - tile.tileH, w, tile.tileH.toFloat())
|
||||||
|
batch.draw(tile.get(1, 2), x, y + h, w, tile.tileH.toFloat())
|
||||||
|
batch.draw(tile.get(0, 1), x - tile.tileW, y, tile.tileW.toFloat(), h)
|
||||||
|
batch.draw(tile.get(2, 1), x + w, y, tile.tileW.toFloat(), h)
|
||||||
|
|
||||||
|
// corners
|
||||||
|
batch.draw(tile.get(0, 0), x - tile.tileW, y - tile.tileH)
|
||||||
|
batch.draw(tile.get(2, 0), x + w, y - tile.tileH)
|
||||||
|
batch.draw(tile.get(2, 2), x + w, y + h)
|
||||||
|
batch.draw(tile.get(0, 2), x - tile.tileW, y + h)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun dispose() {
|
||||||
|
tile.dispose()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -8,15 +8,12 @@ import net.torvald.terrarum.Second
|
|||||||
import net.torvald.terrarum.Terrarum
|
import net.torvald.terrarum.Terrarum
|
||||||
import net.torvald.terrarum.blendNormal
|
import net.torvald.terrarum.blendNormal
|
||||||
import net.torvald.terrarum.ui.UICanvas
|
import net.torvald.terrarum.ui.UICanvas
|
||||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by minjaesong on 2016-01-23.
|
* Created by minjaesong on 2016-01-23.
|
||||||
*/
|
*/
|
||||||
class Notification : UICanvas() {
|
class Notification : UICanvas() {
|
||||||
|
|
||||||
private val segment = SEGMENT_BLACK
|
|
||||||
|
|
||||||
private var fontCol: Color = Color.WHITE // assuming alpha of 1.0
|
private var fontCol: Color = Color.WHITE // assuming alpha of 1.0
|
||||||
|
|
||||||
override var openCloseTime: Second = OPEN_CLOSE_TIME
|
override var openCloseTime: Second = OPEN_CLOSE_TIME
|
||||||
@@ -28,14 +25,14 @@ class Notification : UICanvas() {
|
|||||||
|
|
||||||
override var width: Int = 500
|
override var width: Int = 500
|
||||||
|
|
||||||
override var height: Int = segment.tileH
|
override var height: Int = 0
|
||||||
private val visibleTime = Math.min(
|
private val visibleTime = Math.min(
|
||||||
AppLoader.getConfigInt("notificationshowuptime"),
|
AppLoader.getConfigInt("notificationshowuptime"),
|
||||||
SHOWUP_MAX
|
SHOWUP_MAX
|
||||||
) / 1000f
|
) / 1000f
|
||||||
private var displayTimer = 0f
|
private var displayTimer = 0f
|
||||||
|
|
||||||
internal var message: Array<String> = Array(MESSAGES_DISPLAY) { "" }
|
internal var message: List<String> = listOf("")
|
||||||
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
@@ -51,9 +48,6 @@ class Notification : UICanvas() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private val textAreaHeight = 48f
|
|
||||||
private val imageToTextAreaDelta = (segment.tileH - textAreaHeight) / 2
|
|
||||||
|
|
||||||
private val drawColor = Color(1f,1f,1f,1f)
|
private val drawColor = Color(1f,1f,1f,1f)
|
||||||
|
|
||||||
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
||||||
@@ -64,26 +58,22 @@ class Notification : UICanvas() {
|
|||||||
val realTextWidth = 12 + if (message.size == 1)
|
val realTextWidth = 12 + if (message.size == 1)
|
||||||
Terrarum.fontGame.getWidth(message[0])
|
Terrarum.fontGame.getWidth(message[0])
|
||||||
else
|
else
|
||||||
maxOf(Terrarum.fontGame.getWidth(message[0]), Terrarum.fontGame.getWidth(message[1]))
|
message.map { Terrarum.fontGame.getWidth(it) }.sorted().last()
|
||||||
val displayedTextWidth = maxOf(240, realTextWidth)
|
val displayedTextWidth = maxOf(240, realTextWidth)
|
||||||
|
|
||||||
// force the UI to the centre of the screen
|
// force the UI to the centre of the screen
|
||||||
this.posX = (Terrarum.WIDTH - displayedTextWidth) / 2
|
this.posX = (Terrarum.WIDTH - displayedTextWidth) / 2
|
||||||
|
|
||||||
|
val textHeight = message.size * Terrarum.fontGame.lineHeight
|
||||||
|
|
||||||
batch.color = drawColor
|
batch.color = drawColor
|
||||||
|
|
||||||
batch.draw(segment.get(0, 0), -segment.tileW.toFloat(), 0f)
|
FloatDrawer(batch, 0f, -textHeight, displayedTextWidth.toFloat(), textHeight)
|
||||||
batch.draw(segment.get(1, 0), 0f, 0f, displayedTextWidth.toFloat(), segment.tileH.toFloat())
|
|
||||||
batch.draw(segment.get(2, 0), displayedTextWidth.toFloat(), 0f)
|
|
||||||
|
|
||||||
batch.color = fontCol
|
batch.color = fontCol
|
||||||
message.forEachIndexed { index, s ->
|
message.forEachIndexed { index, s ->
|
||||||
val xoff = 6 + (displayedTextWidth - realTextWidth) / 2
|
val xoff = 6 + (displayedTextWidth - realTextWidth) / 2
|
||||||
val y = if (message.size == 1)
|
val y = -textHeight + Terrarum.fontGame.lineHeight * index
|
||||||
-2 + imageToTextAreaDelta + 0.5f * (textAreaHeight / 2) + (textAreaHeight / 2 - Terrarum.fontGame.lineHeight) / 2
|
|
||||||
else
|
|
||||||
-1 + imageToTextAreaDelta + index * (textAreaHeight / 2) + (textAreaHeight / 2 - Terrarum.fontGame.lineHeight) / 2
|
|
||||||
Terrarum.fontGame.draw(batch, s, LRmargin + xoff, y)
|
Terrarum.fontGame.draw(batch, s, LRmargin + xoff, y)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,7 +99,7 @@ class Notification : UICanvas() {
|
|||||||
endClosingFade(this)
|
endClosingFade(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun sendNotification(message: Array<String>) {
|
fun sendNotification(message: List<String>) {
|
||||||
this.message = message
|
this.message = message
|
||||||
handler.openCloseCounter = 0f
|
handler.openCloseCounter = 0f
|
||||||
handler.opacity = 0f
|
handler.opacity = 0f
|
||||||
@@ -121,12 +111,6 @@ class Notification : UICanvas() {
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
// private int messagesShowingIndex = 0;
|
// private int messagesShowingIndex = 0;
|
||||||
val MESSAGES_DISPLAY = 2
|
|
||||||
val OPEN_CLOSE_TIME = 0.16f
|
val OPEN_CLOSE_TIME = 0.16f
|
||||||
|
|
||||||
|
|
||||||
// will be disposed by Terrarum (application main instance)
|
|
||||||
val SEGMENT_BLACK = TextureRegionPack("assets/graphics/gui/message_black.tga", 8, 56)
|
|
||||||
val SEGMENT_WHITE = TextureRegionPack("assets/graphics/gui/message_white.tga", 8, 56)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,12 +2,10 @@ package net.torvald.terrarum.modulebasegame.ui
|
|||||||
|
|
||||||
import com.badlogic.gdx.graphics.Camera
|
import com.badlogic.gdx.graphics.Camera
|
||||||
import com.badlogic.gdx.graphics.Color
|
import com.badlogic.gdx.graphics.Color
|
||||||
import com.badlogic.gdx.graphics.Texture
|
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||||
import net.torvald.terrarum.Second
|
import net.torvald.terrarum.Second
|
||||||
import net.torvald.terrarum.Terrarum
|
import net.torvald.terrarum.Terrarum
|
||||||
import net.torvald.terrarum.ui.UICanvas
|
import net.torvald.terrarum.ui.UICanvas
|
||||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by minjaesong on 2017-11-25.
|
* Created by minjaesong on 2017-11-25.
|
||||||
@@ -22,38 +20,33 @@ class UITooltip : UICanvas() {
|
|||||||
msgWidth = font.getWidth(value)
|
msgWidth = font.getWidth(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
private val textures = TextureRegionPack("assets/graphics/gui/tooltip_black.tga", 8, 36)
|
|
||||||
|
|
||||||
private val font = Terrarum.fontGame
|
private val font = Terrarum.fontGame
|
||||||
private var msgWidth = 0
|
private var msgWidth = 0
|
||||||
|
|
||||||
val textMarginX = 4
|
val textMarginX = 4
|
||||||
|
|
||||||
override var width: Int
|
override var width: Int
|
||||||
get() = msgWidth + (textMarginX + textures.tileW) * 2
|
get() = msgWidth + (textMarginX + FloatDrawer.tile.tileW) * 2
|
||||||
set(value) { throw Error("You are not supposed to set the width of the tooltip manually.") }
|
set(value) { throw Error("You are not supposed to set the width of the tooltip manually.") }
|
||||||
override var height: Int
|
override var height: Int
|
||||||
get() = textures.tileH
|
get() = FloatDrawer.tile.tileH * 2 + font.lineHeight.toInt()
|
||||||
set(value) { throw Error("You are not supposed to set the height of the tooltip manually.") }
|
set(value) { throw Error("You are not supposed to set the height of the tooltip manually.") }
|
||||||
|
|
||||||
|
|
||||||
init {
|
|
||||||
textures.texture.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
||||||
val mouseX = 4f
|
val mouseX = 4f
|
||||||
val mouseY = 6f
|
val mouseY = 6f
|
||||||
|
|
||||||
val tooltipY = mouseY - textures.tileH
|
val tooltipY = mouseY - height
|
||||||
|
|
||||||
val txtW = msgWidth + 2f * textMarginX
|
val txtW = msgWidth + 2f * textMarginX
|
||||||
|
|
||||||
batch.color = Color.WHITE
|
batch.color = Color.WHITE
|
||||||
batch.draw(textures.get(0, 0), mouseX, tooltipY)
|
|
||||||
batch.draw(textures.get(1, 0), mouseX + textures.tileW, tooltipY, txtW, height.toFloat())
|
FloatDrawer(batch, mouseX - textMarginX, tooltipY, txtW, font.lineHeight)
|
||||||
batch.draw(textures.get(2, 0), mouseX + textures.tileW + txtW, tooltipY)
|
font.draw(batch, message,
|
||||||
font.draw(batch, message, mouseX + textures.tileW + textMarginX, mouseY - textures.tileH + (textures.tileH - font.lineHeight) / 2)
|
mouseX,
|
||||||
|
mouseY - height
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun updateUI(delta: Float) {
|
override fun updateUI(delta: Float) {
|
||||||
@@ -73,7 +66,6 @@ class UITooltip : UICanvas() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun dispose() {
|
override fun dispose() {
|
||||||
textures.dispose()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -2,10 +2,10 @@
|
|||||||
<module type="JAVA_MODULE" version="4">
|
<module type="JAVA_MODULE" version="4">
|
||||||
<component name="FacetManager">
|
<component name="FacetManager">
|
||||||
<facet type="kotlin-language" name="Kotlin">
|
<facet type="kotlin-language" name="Kotlin">
|
||||||
<configuration version="3" platform="JVM 1.8">
|
<configuration version="3" platform="JVM 9">
|
||||||
<compilerSettings />
|
<compilerSettings />
|
||||||
<compilerArguments>
|
<compilerArguments>
|
||||||
<option name="jvmTarget" value="1.8" />
|
<option name="jvmTarget" value="11" />
|
||||||
</compilerArguments>
|
</compilerArguments>
|
||||||
</configuration>
|
</configuration>
|
||||||
</facet>
|
</facet>
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/net/torvald/terrarum/tests" isTestSource="true" />
|
<sourceFolder url="file://$MODULE_DIR$/src/net/torvald/terrarum/tests" isTestSource="true" />
|
||||||
</content>
|
</content>
|
||||||
<orderEntry type="jdk" jdkName="11" jdkType="JavaSDK" />
|
<orderEntry type="inheritedJdk" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
|
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
|
||||||
<orderEntry type="library" name="lib" level="project" />
|
<orderEntry type="library" name="lib" level="project" />
|
||||||
|
|||||||
Reference in New Issue
Block a user