mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 20:31:51 +09:00
new basicinfo ui; each module should be dispose()-able
This commit is contained in:
BIN
assets/mods/basegame/gui/basic_info1.tga
LFS
Normal file
BIN
assets/mods/basegame/gui/basic_info1.tga
LFS
Normal file
Binary file not shown.
@@ -519,6 +519,8 @@ public class AppLoader implements ApplicationListener {
|
||||
fontGame.dispose();
|
||||
fontSmallNumbers.dispose();
|
||||
|
||||
ModMgr.INSTANCE.disposeMods();
|
||||
|
||||
// delete temp files
|
||||
new File("./tmp_wenquanyi.tga").delete(); // FIXME this is pretty much ad-hoc
|
||||
}
|
||||
|
||||
@@ -4,24 +4,20 @@ import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.files.FileHandle
|
||||
import net.torvald.terrarum.AppLoader.printdbg
|
||||
import net.torvald.terrarum.AppLoader.printdbgerr
|
||||
import net.torvald.terrarum.utils.CSVFetcher
|
||||
import net.torvald.terrarum.blockproperties.BlockCodex
|
||||
import net.torvald.terrarum.itemproperties.GameItem
|
||||
import net.torvald.terrarum.itemproperties.ItemCodex
|
||||
import net.torvald.terrarum.blockproperties.BlockCodex
|
||||
import net.torvald.terrarum.itemproperties.ItemID
|
||||
import net.torvald.terrarum.langpack.Lang
|
||||
import net.torvald.terrarum.modulebasegame.EntryPoint
|
||||
import net.torvald.terrarum.utils.CSVFetcher
|
||||
import net.torvald.terrarum.utils.JsonFetcher
|
||||
import org.apache.commons.csv.CSVFormat
|
||||
import org.apache.commons.csv.CSVParser
|
||||
import java.io.File
|
||||
import java.io.FileInputStream
|
||||
import java.io.FileNotFoundException
|
||||
import java.io.FileReader
|
||||
import java.nio.file.FileSystems
|
||||
import java.util.*
|
||||
import javax.script.ScriptEngineManager
|
||||
import javax.script.Invocable
|
||||
|
||||
|
||||
|
||||
@@ -63,6 +59,7 @@ object ModMgr {
|
||||
|
||||
/** Module name (directory name), ModuleMetadata */
|
||||
val moduleInfo = HashMap<String, ModuleMetadata>()
|
||||
val entryPointClasses = ArrayList<ModuleEntryPoint>()
|
||||
|
||||
init {
|
||||
// load modules
|
||||
@@ -112,8 +109,8 @@ object ModMgr {
|
||||
val newClassConstructor = newClass.getConstructor(/* no args defined */)
|
||||
val newClassInstance = newClassConstructor.newInstance(/* no args defined */)
|
||||
|
||||
entryPointClasses.add(newClassInstance as ModuleEntryPoint)
|
||||
(newClassInstance as ModuleEntryPoint).invoke()
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -210,6 +207,9 @@ object ModMgr {
|
||||
return filesList.toList()
|
||||
}
|
||||
|
||||
fun disposeMods() {
|
||||
entryPointClasses.forEach { it.dispose() }
|
||||
}
|
||||
|
||||
|
||||
object GameBlockLoader {
|
||||
|
||||
@@ -5,4 +5,5 @@ package net.torvald.terrarum
|
||||
*/
|
||||
abstract class ModuleEntryPoint {
|
||||
abstract fun invoke()
|
||||
abstract fun dispose()
|
||||
}
|
||||
@@ -105,7 +105,7 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
lateinit var uiVitalSecondary: UICanvas
|
||||
lateinit var uiVitalItem: UICanvas // itemcount/durability of held block or active ammo of held gun. As for the block, max value is 500.
|
||||
|
||||
private lateinit var uiWatchBasic: UICanvas
|
||||
private lateinit var uiBasicInfo: UICanvas
|
||||
private lateinit var uiWatchTierOne: UICanvas
|
||||
|
||||
private lateinit var uiTooltip: UITooltip
|
||||
@@ -314,11 +314,6 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
//uiVitalItem = UIVitalMetre(player, { null }, { null }, Color(0xffcc00), 0, customPositioning = true)
|
||||
//uiVitalItem.setAsAlwaysVisible()
|
||||
|
||||
// basic watch-style notification bar (temperature, new mail)
|
||||
uiWatchBasic = UIBasicNotifier(actorNowPlaying)
|
||||
uiWatchBasic.setAsAlwaysVisible()
|
||||
uiWatchBasic.setPosition(Terrarum.WIDTH - uiWatchBasic.width, 0)
|
||||
|
||||
uiWatchTierOne = UITierOneWatch(actorNowPlaying)
|
||||
uiWatchTierOne.setAsAlwaysVisible()
|
||||
uiWatchTierOne.setPosition(
|
||||
@@ -326,6 +321,11 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
AppLoader.getTvSafeGraphicsHeight() + 8
|
||||
)
|
||||
|
||||
// basic watch-style notification bar (temperature, new mail)
|
||||
uiBasicInfo = UIBasicInfo(actorNowPlaying)
|
||||
uiBasicInfo.setAsAlwaysVisible()
|
||||
uiBasicInfo.setPosition((uiQuickBar.posX - uiBasicInfo.width - AppLoader.getTvSafeActionWidth()) / 2 + AppLoader.getTvSafeActionWidth(), uiWatchTierOne.posY)
|
||||
|
||||
|
||||
uiTooltip = UITooltip()
|
||||
|
||||
@@ -342,7 +342,7 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
|
||||
uiPieMenu,
|
||||
uiQuickBar,
|
||||
uiWatchBasic,
|
||||
uiBasicInfo,
|
||||
uiWatchTierOne,
|
||||
uiTooltip
|
||||
// drawn last
|
||||
@@ -927,7 +927,7 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
|
||||
|
||||
// basic watch-style notification bar (temperature, new mail)
|
||||
uiWatchBasic.setPosition(Terrarum.WIDTH - uiWatchBasic.width, 0)
|
||||
uiBasicInfo.setPosition(Terrarum.WIDTH - uiBasicInfo.width, 0)
|
||||
uiWatchTierOne.setPosition(
|
||||
((Terrarum.WIDTH - AppLoader.getTvSafeGraphicsWidth()) - (uiQuickBar.posX + uiQuickBar.width) - uiWatchTierOne.width) / 2 + (uiQuickBar.posX + uiQuickBar.width),
|
||||
AppLoader.getTvSafeGraphicsHeight() + 8
|
||||
|
||||
110
src/net/torvald/terrarum/modulebasegame/ui/UIBasicInfo.kt
Normal file
110
src/net/torvald/terrarum/modulebasegame/ui/UIBasicInfo.kt
Normal file
@@ -0,0 +1,110 @@
|
||||
package net.torvald.terrarum.modulebasegame.ui
|
||||
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.graphics.Camera
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.modulebasegame.Ingame
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.ActorHumanoid
|
||||
import net.torvald.terrarum.modulebasegame.imagefont.Watch7SegSmall
|
||||
import net.torvald.terrarum.modulebasegame.imagefont.WatchFont
|
||||
import net.torvald.terrarum.ui.UICanvas
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2017-06-10.
|
||||
*/
|
||||
class UIBasicInfo(private val player: ActorHumanoid?) : UICanvas() {
|
||||
override var width = 93
|
||||
override var height = 23
|
||||
override var openCloseTime: Second = 0f
|
||||
|
||||
private var ELuptimer = 10f // to make the light turned off by default
|
||||
private val ELuptime = 4f
|
||||
private var ELon = false
|
||||
|
||||
private var watchFont = WatchFont
|
||||
private var atlas = TextureRegionPack(ModMgr.getPath("basegame", "gui/basic_info1.tga"), width, height)
|
||||
|
||||
private var font = Watch7SegSmall
|
||||
|
||||
private val TEMP_AMERICAN = -1
|
||||
private val TEMP_KELVIN = 0
|
||||
private val TEMP_CELCIUS = 1
|
||||
|
||||
override fun updateUI(delta: Float) {
|
||||
if (ELon) {
|
||||
ELuptimer += delta
|
||||
}
|
||||
|
||||
if (mouseUp || Gdx.input.isKeyPressed(AppLoader.getConfigInt("keyinteract"))) {
|
||||
ELuptimer = 0f
|
||||
ELon = true
|
||||
}
|
||||
|
||||
if (ELuptimer >= ELuptime) {
|
||||
ELon = false
|
||||
}
|
||||
}
|
||||
|
||||
private val temperature: Int
|
||||
get() {
|
||||
if (player != null) {
|
||||
val playerTilePos = player.hIntTilewiseHitbox
|
||||
val tempCelsius = -273f + ((Terrarum.ingame as? Ingame)?.world?.getTemperature(playerTilePos.centeredX.toInt(), playerTilePos.centeredY.toInt()) ?: 288f)
|
||||
|
||||
return if (tempCelsius < -10)
|
||||
0
|
||||
else if (tempCelsius < 10)
|
||||
1
|
||||
else if (tempCelsius < 30)
|
||||
2
|
||||
else if (tempCelsius < 50)
|
||||
3
|
||||
else
|
||||
4
|
||||
}
|
||||
else {
|
||||
return 2
|
||||
}
|
||||
}
|
||||
private val mailCount: Int
|
||||
get() = 0 // cap things at 99
|
||||
|
||||
private val drawCol = Color(1f,1f,1f,UIQuickslotBar.DISPLAY_OPACITY)
|
||||
private val lcdLitColELoff = Color(0xc0c0c0ff.toInt()) mul drawCol
|
||||
private val lcdLitColELon = Color(0x404040ff) mul drawCol
|
||||
|
||||
private val lcdLitCol: Color = lcdLitColELoff
|
||||
|
||||
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
||||
batch.color = drawCol
|
||||
batch.draw(atlas.get(0, 0), 0f, 0f)
|
||||
|
||||
// mail count
|
||||
batch.color = lcdLitCol
|
||||
watchFont.draw(batch, mailCount.toString().padStart(2, '0'), 69f, 7f)
|
||||
|
||||
// temperature
|
||||
if (temperature != 0) {
|
||||
batch.draw(atlas.get(1, temperature - 1), 0f, 0f)
|
||||
}
|
||||
}
|
||||
|
||||
override fun doOpening(delta: Float) {
|
||||
}
|
||||
|
||||
override fun doClosing(delta: Float) {
|
||||
}
|
||||
|
||||
override fun endOpening(delta: Float) {
|
||||
}
|
||||
|
||||
override fun endClosing(delta: Float) {
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
atlas.dispose()
|
||||
}
|
||||
}
|
||||
@@ -1,152 +0,0 @@
|
||||
package net.torvald.terrarum.modulebasegame.ui
|
||||
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.graphics.Camera
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.modulebasegame.Ingame
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.ActorHumanoid
|
||||
import net.torvald.terrarum.modulebasegame.imagefont.Watch7SegSmall
|
||||
import net.torvald.terrarum.ui.UICanvas
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2017-06-10.
|
||||
*/
|
||||
class UIBasicNotifier(private val player: ActorHumanoid?) : UICanvas() {
|
||||
override var width = 116
|
||||
override var height = 24
|
||||
override var openCloseTime: Second = 0f
|
||||
|
||||
private var ELuptimer = 10f // to make the light turned off by default
|
||||
private val ELuptime = 4f
|
||||
private var ELon = false
|
||||
|
||||
private var atlas = TextureRegionPack(ModMgr.getPath("basegame", "gui/basic_meter_atlas.tga"), width, height)
|
||||
|
||||
private var font = Watch7SegSmall
|
||||
|
||||
private val TEMP_AMERICAN = -1
|
||||
private val TEMP_KELVIN = 0
|
||||
private val TEMP_CELCIUS = 1
|
||||
|
||||
override fun updateUI(delta: Float) {
|
||||
if (ELon) {
|
||||
ELuptimer += delta
|
||||
}
|
||||
|
||||
if (mouseUp || Gdx.input.isKeyPressed(AppLoader.getConfigInt("keyinteract"))) {
|
||||
ELuptimer = 0f
|
||||
ELon = true
|
||||
}
|
||||
|
||||
if (ELuptimer >= ELuptime) {
|
||||
ELon = false
|
||||
}
|
||||
}
|
||||
|
||||
private val temperature: Int
|
||||
get() {
|
||||
if (player != null) {
|
||||
val playerTilePos = player.hIntTilewiseHitbox
|
||||
val tempCelsius = -273f + ((Terrarum.ingame as? Ingame)?.world?.getTemperature(playerTilePos.centeredX.toInt(), playerTilePos.centeredY.toInt()) ?: 288f)
|
||||
|
||||
return when (AppLoader.getConfigInt("temperatureunit")) {
|
||||
TEMP_KELVIN -> tempCelsius.times(1.8f).plus(32f).roundInt()
|
||||
TEMP_CELCIUS -> tempCelsius.roundInt()
|
||||
else -> tempCelsius.plus(273.15f).roundInt()
|
||||
}
|
||||
}
|
||||
else {
|
||||
return 888
|
||||
}
|
||||
}
|
||||
private val mailCount: Int
|
||||
get() = 0
|
||||
|
||||
private val drawCol = Color(1f,1f,1f,0.5f)
|
||||
private val lcdLitColELoff = Color(0x141414_aa)
|
||||
private val lcdLitColELon = Color(0x141414_ff)
|
||||
|
||||
private val lcdLitCol: Color
|
||||
get() = if (ELon) lcdLitColELon else lcdLitColELoff
|
||||
|
||||
fun getTempStr(): String {
|
||||
val sb = StringBuilder()
|
||||
|
||||
if (temperature < 100) {
|
||||
if (temperature < 0)
|
||||
sb.append("-")
|
||||
else
|
||||
sb.append(" ")
|
||||
|
||||
if (temperature.abs() < 10)
|
||||
sb.append(" ")
|
||||
}
|
||||
|
||||
sb.append(temperature.abs())
|
||||
|
||||
if (AppLoader.getConfigInt("temperatureunit") == 1) {
|
||||
sb.append('"') // celsius superscript
|
||||
}
|
||||
else if (AppLoader.getConfigInt("temperatureunit") == -1) {
|
||||
sb.append('#') // fahrenheit subscript
|
||||
}
|
||||
else {
|
||||
sb.append(' ') // display nothing for kelvin
|
||||
}
|
||||
|
||||
return sb.toString()
|
||||
}
|
||||
|
||||
fun getMailStr(): String {
|
||||
val sb = StringBuilder()
|
||||
|
||||
if (mailCount < 10)
|
||||
sb.append(" ")
|
||||
|
||||
sb.append(mailCount)
|
||||
|
||||
return sb.toString()
|
||||
}
|
||||
|
||||
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
||||
// light overlay or EL
|
||||
if (ELon) {
|
||||
blendNormal(batch)
|
||||
batch.draw(atlas.get(0, 2), 0f, 0f)
|
||||
}
|
||||
else {
|
||||
// backplate
|
||||
batch.color = drawCol
|
||||
batch.draw(atlas.get(0, 0), 0f, 0f)
|
||||
}
|
||||
|
||||
// LCD back
|
||||
blendNormal(batch)
|
||||
batch.draw(atlas.get(0, 3), 0f, 0f)
|
||||
|
||||
|
||||
// LCD contents
|
||||
batch.color = lcdLitCol
|
||||
font.draw(batch, getTempStr(), 21f, 5f)
|
||||
font.draw(batch, getMailStr(), 93f, 5f)
|
||||
}
|
||||
|
||||
override fun doOpening(delta: Float) {
|
||||
}
|
||||
|
||||
override fun doClosing(delta: Float) {
|
||||
}
|
||||
|
||||
override fun endOpening(delta: Float) {
|
||||
}
|
||||
|
||||
override fun endClosing(delta: Float) {
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
atlas.dispose()
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Reference in New Issue
Block a user