mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 20:31:51 +09:00
Ingame's Player is now mandatory; player spawn on right position
This commit is contained in:
9
.idea/artifacts/ModuleBasegame.xml
generated
Normal file
9
.idea/artifacts/ModuleBasegame.xml
generated
Normal file
@@ -0,0 +1,9 @@
|
||||
<component name="ArtifactManager">
|
||||
<artifact type="jar" name="ModuleBasegame">
|
||||
<output-path>$PROJECT_DIR$/out/artifacts/ModuleBasegame</output-path>
|
||||
<root id="archive" name="ModuleBasegame.jar">
|
||||
<element id="module-output" name="ingamemodule_basegame" />
|
||||
<element id="library" level="project" name="lib" />
|
||||
</root>
|
||||
</artifact>
|
||||
</component>
|
||||
1
.idea/modules.xml
generated
1
.idea/modules.xml
generated
@@ -3,6 +3,7 @@
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/Terrarum_renewed.iml" filepath="$PROJECT_DIR$/Terrarum_renewed.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/ingamemodule_basegame/ingamemodule_basegame.iml" filepath="$PROJECT_DIR$/ingamemodule_basegame/ingamemodule_basegame.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
Binary file not shown.
12
ingamemodule_basegame/ingamemodule_basegame.iml
Normal file
12
ingamemodule_basegame/ingamemodule_basegame.iml
Normal file
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="lib" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -82,6 +82,7 @@ object DefaultConfig {
|
||||
|
||||
jsonObject.addProperty("fullframelightupdate", false)
|
||||
|
||||
jsonObject.addProperty("useamericanunit", false) // Metric Masterrace -- Filthy imperials.
|
||||
|
||||
return jsonObject
|
||||
}
|
||||
|
||||
@@ -32,10 +32,10 @@ import javax.swing.JOptionPane
|
||||
|
||||
import com.badlogic.gdx.graphics.OrthographicCamera
|
||||
import net.torvald.random.HQRNG
|
||||
import net.torvald.terrarum.blockproperties.BlockCodex
|
||||
import net.torvald.terrarum.ui.*
|
||||
import net.torvald.terrarum.worldgenerator.RoguelikeRandomiser
|
||||
import net.torvald.terrarum.worldgenerator.WorldGenerator
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
|
||||
|
||||
/**
|
||||
@@ -65,10 +65,10 @@ class Ingame(val batch: SpriteBatch) : Screen {
|
||||
private val actorsRenderMidTop = ArrayList<ActorWithBody>(ACTORCONTAINER_INITIAL_SIZE)
|
||||
private val actorsRenderFront = ArrayList<ActorWithBody>(ACTORCONTAINER_INITIAL_SIZE)
|
||||
|
||||
var playableActorDelegate: PlayableActorDelegate? = null // DO NOT LATEINIT!
|
||||
lateinit var playableActorDelegate: PlayableActorDelegate // player must exist; use dummy player if there is none (required for camera)
|
||||
private set
|
||||
inline val player: ActorHumanoid? // currently POSSESSED actor :)
|
||||
get() = playableActorDelegate?.actor
|
||||
inline val player: ActorHumanoid // currently POSSESSED actor :)
|
||||
get() = playableActorDelegate.actor
|
||||
|
||||
var screenZoom = 1.0f
|
||||
val ZOOM_MAXIMUM = 4.0f
|
||||
@@ -80,12 +80,11 @@ class Ingame(val batch: SpriteBatch) : Screen {
|
||||
|
||||
|
||||
private val worldFBOformat = if (Terrarum.environment == RunningEnvironment.MOBILE) Pixmap.Format.RGBA4444 else Pixmap.Format.RGBA8888
|
||||
private val worldBlendFBOFormat = if (Terrarum.environment == RunningEnvironment.MOBILE) Pixmap.Format.RGBA4444 else Pixmap.Format.RGBA8888
|
||||
private val lightFBOformat = Pixmap.Format.RGB888
|
||||
|
||||
var worldDrawFrameBuffer = FrameBuffer(worldFBOformat, Terrarum.WIDTH, Terrarum.HEIGHT, false)
|
||||
var worldGlowFrameBuffer = FrameBuffer(worldFBOformat, Terrarum.WIDTH, Terrarum.HEIGHT, false)
|
||||
var worldBlendFrameBuffer = FrameBuffer(worldBlendFBOFormat, Terrarum.WIDTH, Terrarum.HEIGHT, false)
|
||||
var worldBlendFrameBuffer = FrameBuffer(worldFBOformat, Terrarum.WIDTH, Terrarum.HEIGHT, false)
|
||||
// RGB elements of Lightmap for Color Vec4(R, G, B, 1.0) 24-bit
|
||||
var lightmapFboA = FrameBuffer(lightFBOformat, Terrarum.WIDTH.div(lightmapDownsample.toInt()), Terrarum.HEIGHT.div(lightmapDownsample.toInt()), false)
|
||||
var lightmapFboB = FrameBuffer(lightFBOformat, Terrarum.WIDTH.div(lightmapDownsample.toInt()), Terrarum.HEIGHT.div(lightmapDownsample.toInt()), false)
|
||||
@@ -145,9 +144,10 @@ class Ingame(val batch: SpriteBatch) : Screen {
|
||||
//private val ingameDrawThread: ThreadIngameDraw // draw must be on the main thread
|
||||
|
||||
|
||||
var gameInitialised = false
|
||||
private set
|
||||
var gameFullyLoaded = false
|
||||
private set
|
||||
private var postInitDone = false
|
||||
|
||||
|
||||
//////////////
|
||||
@@ -226,7 +226,7 @@ class Ingame(val batch: SpriteBatch) : Screen {
|
||||
* Init instance by loading saved world
|
||||
*/
|
||||
private fun enter(gameSaveData: GameSaveData) {
|
||||
if (gameFullyLoaded) {
|
||||
if (gameInitialised) {
|
||||
println("[Ingame] loaded successfully.")
|
||||
}
|
||||
else {
|
||||
@@ -242,7 +242,7 @@ class Ingame(val batch: SpriteBatch) : Screen {
|
||||
|
||||
//initGame()
|
||||
|
||||
gameFullyLoaded = true
|
||||
gameInitialised = true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -250,7 +250,7 @@ class Ingame(val batch: SpriteBatch) : Screen {
|
||||
* Init instance by creating new world
|
||||
*/
|
||||
private fun enter(worldParams: NewWorldParameters) {
|
||||
if (gameFullyLoaded) {
|
||||
if (gameInitialised) {
|
||||
println("[Ingame] loaded successfully.")
|
||||
}
|
||||
else {
|
||||
@@ -285,7 +285,7 @@ class Ingame(val batch: SpriteBatch) : Screen {
|
||||
|
||||
//initGame()
|
||||
|
||||
gameFullyLoaded = true
|
||||
gameInitialised = true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -410,17 +410,35 @@ class Ingame(val batch: SpriteBatch) : Screen {
|
||||
override fun render(delta: Float) {
|
||||
// Q&D solution for LoadScreen and Ingame, where while LoadScreen is working, Ingame now no longer has GL Context
|
||||
// there's still things to load which needs GL context to be present
|
||||
if (!postInitDone) {
|
||||
if (!gameFullyLoaded) {
|
||||
|
||||
if (gameLoadMode == GameLoadMode.CREATE_NEW) {
|
||||
playableActorDelegate = PlayableActorDelegate(PlayerBuilderSigrid())
|
||||
addNewActor(player!!)
|
||||
|
||||
// determine spawn position
|
||||
val spawnX = world.width / 2
|
||||
var solidTileCounter = 0
|
||||
while (true) {
|
||||
if (BlockCodex[world.getTileFromTerrain(spawnX, solidTileCounter)].isSolid ||
|
||||
BlockCodex[world.getTileFromTerrain(spawnX - 1, solidTileCounter)].isSolid ||
|
||||
BlockCodex[world.getTileFromTerrain(spawnX + 1, solidTileCounter)].isSolid
|
||||
) break
|
||||
|
||||
solidTileCounter += 1
|
||||
}
|
||||
|
||||
player.setPosition(
|
||||
spawnX * FeaturesDrawer.TILE_SIZE.toDouble(),
|
||||
solidTileCounter * FeaturesDrawer.TILE_SIZE.toDouble()
|
||||
)
|
||||
|
||||
addNewActor(player)
|
||||
}
|
||||
|
||||
initGame()
|
||||
|
||||
|
||||
postInitDone = true
|
||||
gameFullyLoaded = true
|
||||
}
|
||||
|
||||
|
||||
@@ -1517,7 +1535,7 @@ class Ingame(val batch: SpriteBatch) : Screen {
|
||||
worldGlowFrameBuffer.dispose()
|
||||
worldGlowFrameBuffer = FrameBuffer(worldFBOformat, Terrarum.WIDTH, Terrarum.HEIGHT, false)
|
||||
worldBlendFrameBuffer.dispose()
|
||||
worldBlendFrameBuffer = FrameBuffer(worldBlendFBOFormat, Terrarum.WIDTH, Terrarum.HEIGHT, false)
|
||||
worldBlendFrameBuffer = FrameBuffer(worldFBOformat, Terrarum.WIDTH, Terrarum.HEIGHT, false)
|
||||
lightmapFboA.dispose()
|
||||
lightmapFboA = FrameBuffer(lightFBOformat, Terrarum.WIDTH.div(lightmapDownsample.toInt()), Terrarum.HEIGHT.div(lightmapDownsample.toInt()), false)
|
||||
lightmapFboB.dispose()
|
||||
@@ -1546,12 +1564,12 @@ class Ingame(val batch: SpriteBatch) : Screen {
|
||||
|
||||
|
||||
|
||||
if (gameFullyLoaded) {
|
||||
if (gameInitialised) {
|
||||
LightmapRenderer.fireRecalculateEvent()
|
||||
}
|
||||
|
||||
|
||||
if (postInitDone) {
|
||||
if (gameFullyLoaded) {
|
||||
// resize UIs
|
||||
|
||||
notifier.setPosition(
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package net.torvald.terrarum
|
||||
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.Screen
|
||||
import com.badlogic.gdx.ScreenAdapter
|
||||
import com.badlogic.gdx.graphics.*
|
||||
import com.badlogic.gdx.graphics.glutils.FrameBuffer
|
||||
@@ -127,7 +126,7 @@ object LoadScreen : ScreenAdapter() {
|
||||
|
||||
// change screen WHEN the timer is reset.
|
||||
// In other words, the arrow must hit the goal BEFORE context change take place
|
||||
if (screenToLoad?.gameFullyLoaded ?: false) {
|
||||
if (screenToLoad?.gameInitialised ?: false) {
|
||||
doContextChange = true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ class ActorInventory(val actor: Pocketed, var maxCapacity: Int, var capacityMode
|
||||
"These commands are NOT INTERCHANGEABLE; they handle things differently according to the context.")
|
||||
if (item.originalID == Player.PLAYER_REF_ID || item.originalID == 0x51621D) // do not delete this magic
|
||||
throw IllegalArgumentException("Attempted to put human player into the inventory.")
|
||||
if (Terrarum.ingame != null &&
|
||||
if ((Terrarum.ingame?.gameFullyLoaded ?: false) &&
|
||||
(item.originalID == Terrarum.ingame?.player?.referenceID))
|
||||
throw IllegalArgumentException("Attempted to put active player into the inventory.")
|
||||
if ((!item.stackable || item.dynamicID in ITEM_DYNAMIC) && count > 1)
|
||||
|
||||
@@ -65,8 +65,6 @@ object PlayerBuilderSigrid {
|
||||
|
||||
p.inventory = ActorInventory(p, 0, ActorInventory.CAPACITY_MODE_NO_ENCUMBER)
|
||||
|
||||
p.setPosition((4096 * FeaturesDrawer.TILE_SIZE).toDouble(), (300 * 16).toDouble())
|
||||
|
||||
p.faction.add(FactionFactory.create("basegame", "factions/FactionSigrid.json"))
|
||||
|
||||
|
||||
@@ -78,7 +76,10 @@ object PlayerBuilderSigrid {
|
||||
Block.PLANK_BIRCH, Block.PLANK_BLOODROSE, Block.PLANK_EBONY, Block.PLANK_NORMAL,
|
||||
Block.SANDSTONE, Block.SANDSTONE_BLACK, Block.SANDSTONE_GREEN,
|
||||
Block.SANDSTONE_RED, Block.STONE, Block.STONE_BRICKS,
|
||||
Block.STONE_QUARRIED, Block.STONE_TILE_WHITE, Block.TORCH
|
||||
Block.STONE_QUARRIED, Block.STONE_TILE_WHITE, Block.TORCH,
|
||||
Block.DAYLIGHT_CAPACITOR, Block.ICE_FRAGILE,
|
||||
Block.ILLUMINATOR_WHITE, Block.ILLUMINATOR_BLACK, Block.ILLUMINATOR_ORANGE,
|
||||
Block.ILLUMINATOR_GREEN
|
||||
)
|
||||
val walls = arrayOf(
|
||||
Block.AIR, Block.DIRT, Block.GLASS_CRUDE,
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
package net.torvald.terrarum.gameworld
|
||||
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import net.torvald.dataclass.Float16
|
||||
import net.torvald.terrarum.realestate.LandUtil
|
||||
import net.torvald.terrarum.blockproperties.BlockCodex
|
||||
import org.dyn4j.geometry.Vector2
|
||||
@@ -34,6 +35,7 @@ class GameWorld(val width: Int, val height: Int) {
|
||||
var gravitation: Vector2 = Vector2(0.0, 9.8)
|
||||
/** 0.0..1.0+ */
|
||||
var globalLight = Color(0f,0f,0f,0f)
|
||||
var averageTemperature = 288f // 15 deg celsius; simulates global warming
|
||||
|
||||
|
||||
|
||||
@@ -56,7 +58,7 @@ class GameWorld(val width: Int, val height: Int) {
|
||||
layerTerrainLowBits = PairedMapLayer(width, height)
|
||||
layerWallLowBits = PairedMapLayer(width, height)
|
||||
|
||||
layerThermal = MapLayerFloat(width / 2, height / 2)
|
||||
layerThermal = MapLayerFloat(width / 2, height / 2, averageTemperature)
|
||||
|
||||
|
||||
time = WorldTime(
|
||||
@@ -287,6 +289,12 @@ class GameWorld(val width: Int, val height: Int) {
|
||||
fun getWallDamage(x: Int, y: Int): Float =
|
||||
wallDamages[LandUtil.getBlockAddr(x, y)] ?: 0f
|
||||
|
||||
|
||||
fun getTemperature(worldTileX: Int, worldTileY: Int): Float? {
|
||||
return layerThermal.getValue((worldTileX fmod width) / 2, worldTileY / 2)
|
||||
}
|
||||
|
||||
|
||||
companion object {
|
||||
|
||||
@Transient val WALL = 0
|
||||
|
||||
@@ -10,6 +10,10 @@ import net.torvald.dataclass.Float16Bits
|
||||
*/
|
||||
class MapLayerFloat(val width: Int, val height: Int) : Iterable<Float16Bits> {
|
||||
|
||||
constructor(width: Int, height: Int, init: Float) : this(width, height) {
|
||||
data = Array(height) { Array(width, { Float16.fromFloat(init) }) }
|
||||
}
|
||||
|
||||
internal @Volatile var data: Array<Array<Float16Bits>> // in parallel programming: do not trust your register; always read freshly from RAM!
|
||||
|
||||
init {
|
||||
@@ -45,7 +49,7 @@ class MapLayerFloat(val width: Int, val height: Int) : Iterable<Float16Bits> {
|
||||
return if (x !in 0..width - 1 || y !in 0..height - 1)
|
||||
null
|
||||
else
|
||||
data[y][x].toFloat()
|
||||
Float16.toFloat(data[y][x])
|
||||
}
|
||||
|
||||
internal fun setValue(x: Int, y: Int, value: Float) {
|
||||
|
||||
@@ -155,6 +155,12 @@ object WorldSimulator {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun disperseHeat(delta: Float) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
fun drawFluidMapDebug(batch: SpriteBatch) {
|
||||
batch.color = colourWater
|
||||
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
package net.torvald.terrarum.modulebasegame.items
|
||||
|
||||
import net.torvald.point.Point2d
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.blockproperties.Block
|
||||
import net.torvald.terrarum.gameactors.AVKey
|
||||
import net.torvald.terrarum.gameactors.ActorWithPhysics
|
||||
import net.torvald.terrarum.itemproperties.Calculate
|
||||
import net.torvald.terrarum.itemproperties.GameItem
|
||||
import net.torvald.terrarum.itemproperties.ItemID
|
||||
import net.torvald.terrarum.itemproperties.Material
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2017-07-17.
|
||||
*/
|
||||
class PickaxeGeneric(override val originalID: ItemID) : GameItem() {
|
||||
|
||||
override var dynamicID: ItemID = originalID
|
||||
override val originalName = "PACKAGED_PICK"
|
||||
override var baseMass = 10.0
|
||||
override var baseToolSize: Double? = 10.0
|
||||
override var stackable = true
|
||||
override var maxDurability = 147
|
||||
override var durability = maxDurability.toFloat()
|
||||
override val equipPosition = 9
|
||||
override var inventoryCategory = Category.TOOL
|
||||
override val isUnique = false
|
||||
override val isDynamic = true
|
||||
override val material = Material(0,0,0,0,0,0,0,0,1,0.0)
|
||||
|
||||
init {
|
||||
super.name = "Builtin Pickaxe"
|
||||
}
|
||||
|
||||
override fun primaryUse(delta: Float): Boolean {
|
||||
val mouseTileX = Terrarum.mouseTileX
|
||||
val mouseTileY = Terrarum.mouseTileY
|
||||
|
||||
val mousePoint = Point2d(mouseTileX.toDouble(), mouseTileY.toDouble())
|
||||
val actorvalue = Terrarum.ingame!!.player!!.actorValue
|
||||
|
||||
using = true
|
||||
|
||||
// linear search filter (check for intersection with tilewise mouse point and tilewise hitbox)
|
||||
// return false if hitting actors
|
||||
Terrarum.ingame!!.actorContainer.forEach({
|
||||
if (it is ActorWithPhysics && it.tilewiseHitbox.intersects(mousePoint))
|
||||
return false
|
||||
})
|
||||
|
||||
// return false if here's no tile
|
||||
if (Block.AIR == Terrarum.ingame!!.world.getTileFromTerrain(mouseTileX, mouseTileY))
|
||||
return false
|
||||
|
||||
// filter passed, do the job
|
||||
val swingDmgToFrameDmg = delta.toDouble() / actorvalue.getAsDouble(AVKey.ACTION_INTERVAL)!!
|
||||
|
||||
Terrarum.ingame!!.world.inflictTerrainDamage(
|
||||
mouseTileX, mouseTileY,
|
||||
Calculate.pickaxePower(Terrarum.ingame!!.player!!, material) * swingDmgToFrameDmg
|
||||
)
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
override fun endPrimaryUse(delta: Float): Boolean {
|
||||
using = false
|
||||
// reset action timer to zero
|
||||
Terrarum.ingame!!.player!!.actorValue.set(AVKey.__ACTION_TIMER, 0.0)
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.gameactors.ActorHumanoid
|
||||
import net.torvald.terrarum.gameactors.Second
|
||||
import net.torvald.terrarum.gameactors.abs
|
||||
import net.torvald.terrarum.gameactors.roundInt
|
||||
import net.torvald.terrarum.imagefont.Watch7SegSmall
|
||||
import net.torvald.terrarum.worlddrawer.LightmapRenderer
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
@@ -44,7 +45,21 @@ class UIBasicNotifier(private val player: ActorHumanoid?) : UICanvas() {
|
||||
}
|
||||
|
||||
private val temperature: Int
|
||||
get() = -2
|
||||
get() {
|
||||
if (player != null) {
|
||||
val playerTilePos = player.tilewiseHitbox
|
||||
val tempCelsius = -273f + (Terrarum.ingame?.world?.getTemperature(playerTilePos.centeredX.toInt(), playerTilePos.centeredY.toInt()) ?: 288f)
|
||||
return if (Terrarum.getConfigBoolean("useamericanunit")) {
|
||||
tempCelsius.times(1.8f).plus(32f).roundInt()
|
||||
}
|
||||
else {
|
||||
tempCelsius.roundInt()
|
||||
}
|
||||
}
|
||||
else {
|
||||
return 888
|
||||
}
|
||||
}
|
||||
private val mailCount: Int
|
||||
get() = 0
|
||||
|
||||
@@ -65,7 +80,12 @@ class UIBasicNotifier(private val player: ActorHumanoid?) : UICanvas() {
|
||||
|
||||
sb.append(temperature.abs())
|
||||
|
||||
sb.append('"') // celsius superscript
|
||||
if (Terrarum.getConfigBoolean("useamericanunit")) {
|
||||
sb.append('#') // fahrenheit subscript
|
||||
}
|
||||
else {
|
||||
sb.append('"') // celsius superscript
|
||||
}
|
||||
|
||||
return sb.toString()
|
||||
}
|
||||
|
||||
@@ -124,12 +124,16 @@ class UIInventory(
|
||||
private val scrollLeftButton = UIItemImageButton(this,
|
||||
scrollImageButtonAtlas.get(0, 0),
|
||||
posX = categoryWidth,
|
||||
posY = (height - controlHelpHeight - scrollImageButtonAtlas.tileH) / 2
|
||||
posY = 0,//(height - controlHelpHeight - scrollImageButtonAtlas.tileH) / 2,
|
||||
width = scrollImageButtonAtlas.tileW,
|
||||
height = height - controlHelpHeight
|
||||
)
|
||||
private val scrollRightButton = UIItemImageButton(this,
|
||||
scrollImageButtonAtlas.get(1, 0),
|
||||
posX = width - scrollImageButtonAtlas.tileW,
|
||||
posY = (height - controlHelpHeight - scrollImageButtonAtlas.tileH) / 2
|
||||
posY = 0,//(height - controlHelpHeight - scrollImageButtonAtlas.tileH) / 2,
|
||||
width = scrollImageButtonAtlas.tileW,
|
||||
height = height - controlHelpHeight
|
||||
)
|
||||
var itemPage = 0
|
||||
var itemPageCount = 1 // TODO total size of current category / items.size
|
||||
@@ -139,7 +143,7 @@ class UIInventory(
|
||||
var inventorySortList = ArrayList<InventoryPair>()
|
||||
private var rebuildList = true
|
||||
|
||||
private val SP = "${0x3000.toChar()}${0x3000.toChar()}${0x3000.toChar()}"
|
||||
private val SP = "${0x3000.toChar()}${0x3000.toChar()}"
|
||||
val listControlHelp: String
|
||||
get() = if (Terrarum.environment == RunningEnvironment.PC)
|
||||
"${0xe006.toChar()} ${Lang["GAME_INVENTORY_USE"]}$SP" +
|
||||
@@ -161,23 +165,21 @@ class UIInventory(
|
||||
private var isEncumbered = false
|
||||
|
||||
|
||||
private val seekLeft: Int; get() = Terrarum.getConfigInt("keyleft") // to support in-screen keybind changing
|
||||
private val seekRight: Int; get() = Terrarum.getConfigInt("keyright") // to support in-screen keybind changing
|
||||
private val seekUp: Int; get() = Terrarum.getConfigInt("keyup") // to support in-screen keybind changing
|
||||
private val seekDown: Int; get() = Terrarum.getConfigInt("keydown") // to support in-screen keybind changing
|
||||
private val seekLeft: Int; get() = Terrarum.getConfigInt("keyleft") // getter used to support in-game keybind changing
|
||||
private val seekRight: Int; get() = Terrarum.getConfigInt("keyright") // getter used to support in-game keybind changing
|
||||
private val seekUp: Int; get() = Terrarum.getConfigInt("keyup") // getter used to support in-game keybind changing
|
||||
private val seekDown: Int; get() = Terrarum.getConfigInt("keydown") // getter used to support in-game keybind changing
|
||||
|
||||
|
||||
init {
|
||||
// assign actions to the buttons
|
||||
scrollLeftButton.clickOnceAction = { mouseX, mouseY, button -> // click once action doesn't work ?!
|
||||
scrollLeftButton.clickOnceListener = { mouseX, mouseY, button -> // click once action doesn't work ?!
|
||||
if (button == Input.Buttons.LEFT) {
|
||||
println("prevpage")
|
||||
itemPage = (itemPage - 1) fmod itemPageCount
|
||||
}
|
||||
}
|
||||
scrollRightButton.clickOnceAction = { mouseX, mouseY, button ->
|
||||
scrollRightButton.clickOnceListener = { mouseX, mouseY, button ->
|
||||
if (button == Input.Buttons.LEFT) {
|
||||
println("nextpage")
|
||||
itemPage = (itemPage + 1) fmod itemPageCount
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,39 +31,39 @@ abstract class UIItem(var parentUI: UICanvas) { // do not replace parentUI to UI
|
||||
|
||||
|
||||
// kind of listener implementation
|
||||
var updateAction: ((Float) -> Unit)? = null
|
||||
var keyDownAction: ((Int) -> Unit)? = null
|
||||
var keyUpAction: ((Int) -> Unit)? = null
|
||||
var mouseMovedAction: ((Int, Int) -> Unit)? = null
|
||||
var touchDraggedAction: ((Int, Int, Int) -> Unit)? = null
|
||||
var touchDownAction: ((Int, Int, Int, Int) -> Unit)? = null
|
||||
var touchUpAction: ((Int, Int, Int, Int) -> Unit)? = null
|
||||
var scrolledAction: ((Int) -> Unit)? = null
|
||||
var updateListener: ((Float) -> Unit)? = null
|
||||
var keyDownListener: ((Int) -> Unit)? = null
|
||||
var keyUpListener: ((Int) -> Unit)? = null
|
||||
var mouseMovedListener: ((Int, Int) -> Unit)? = null
|
||||
var touchDraggedListener: ((Int, Int, Int) -> Unit)? = null
|
||||
var touchDownListener: ((Int, Int, Int, Int) -> Unit)? = null
|
||||
var touchUpListener: ((Int, Int, Int, Int) -> Unit)? = null
|
||||
var scrolledListener: ((Int) -> Unit)? = null
|
||||
|
||||
var clickOnceAction: ((Int, Int, Int) -> Unit)? = null
|
||||
var clickOnceActionEngaged = false
|
||||
var clickOnceListener: ((Int, Int, Int) -> Unit)? = null
|
||||
var clickOnceListenerFired = false
|
||||
|
||||
|
||||
|
||||
open fun update(delta: Float) {
|
||||
if (updateAction != null) {
|
||||
updateAction!!.invoke(delta)
|
||||
if (updateListener != null) {
|
||||
updateListener!!.invoke(delta)
|
||||
}
|
||||
}
|
||||
abstract fun render(batch: SpriteBatch)
|
||||
|
||||
// keyboard controlled
|
||||
open fun keyDown(keycode: Int): Boolean {
|
||||
if (keyDownAction != null) {
|
||||
keyDownAction!!.invoke(keycode)
|
||||
if (keyDownListener != null) {
|
||||
keyDownListener!!.invoke(keycode)
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
open fun keyUp(keycode: Int): Boolean {
|
||||
if (keyUpAction != null) {
|
||||
keyUpAction!!.invoke(keycode)
|
||||
if (keyUpListener != null) {
|
||||
keyUpListener!!.invoke(keycode)
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -72,16 +72,16 @@ abstract class UIItem(var parentUI: UICanvas) { // do not replace parentUI to UI
|
||||
|
||||
// mouse controlled
|
||||
open fun mouseMoved(screenX: Int, screenY: Int): Boolean {
|
||||
if (mouseMovedAction != null) {
|
||||
mouseMovedAction!!.invoke(relativeMouseX, relativeMouseY)
|
||||
if (mouseMovedListener != null) {
|
||||
mouseMovedListener!!.invoke(relativeMouseX, relativeMouseY)
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
open fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean {
|
||||
if (touchDraggedAction != null) {
|
||||
touchDraggedAction!!.invoke(relativeMouseX, relativeMouseY, pointer)
|
||||
if (touchDraggedListener != null) {
|
||||
touchDraggedListener!!.invoke(relativeMouseX, relativeMouseY, pointer)
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -90,31 +90,31 @@ abstract class UIItem(var parentUI: UICanvas) { // do not replace parentUI to UI
|
||||
open fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
|
||||
var actionDone = false
|
||||
|
||||
if (touchDownAction != null) {
|
||||
touchDownAction!!.invoke(relativeMouseX, relativeMouseY, pointer, button)
|
||||
if (touchDownListener != null) {
|
||||
touchDownListener!!.invoke(relativeMouseX, relativeMouseY, pointer, button)
|
||||
actionDone = true
|
||||
}
|
||||
|
||||
if (!clickOnceActionEngaged && mouseUp) {
|
||||
clickOnceAction!!.invoke(relativeMouseX, relativeMouseY, button)
|
||||
if (!clickOnceListenerFired && mouseUp) {
|
||||
clickOnceListener!!.invoke(relativeMouseX, relativeMouseY, button)
|
||||
actionDone = true
|
||||
}
|
||||
|
||||
return actionDone
|
||||
}
|
||||
open fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
|
||||
clickOnceActionEngaged = false
|
||||
clickOnceListenerFired = false
|
||||
|
||||
if (touchUpAction != null) {
|
||||
touchUpAction!!.invoke(relativeMouseX, relativeMouseY, pointer, button)
|
||||
if (touchUpListener != null) {
|
||||
touchUpListener!!.invoke(relativeMouseX, relativeMouseY, pointer, button)
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
open fun scrolled(amount: Int): Boolean {
|
||||
if (scrolledAction != null) {
|
||||
scrolledAction!!.invoke(amount)
|
||||
if (scrolledListener != null) {
|
||||
scrolledListener!!.invoke(amount)
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user