mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 12:21:52 +09:00
setting up the inventory using builder (during init) requires ingame.player to be nullable, lateinit won't work
This commit is contained in:
@@ -71,9 +71,10 @@ class StateInGame : BasicGameState() {
|
||||
lateinit var debugWindow: UIHandler
|
||||
lateinit var notifier: UIHandler
|
||||
|
||||
private lateinit var playableActorDelegate: PlayableActorDelegate // player is necessity in this engine, even if the player is just a camera
|
||||
internal val player: ActorHumanoid // currently POSSESSED actor :)
|
||||
get() = playableActorDelegate.actor
|
||||
|
||||
private var playableActorDelegate: PlayableActorDelegate? = null // DO NOT LATEINIT!
|
||||
internal val player: ActorHumanoid? // currently POSSESSED actor :)
|
||||
get() = playableActorDelegate?.actor
|
||||
|
||||
var screenZoom = 1.0f
|
||||
val ZOOM_MAX = 2.0f
|
||||
@@ -141,9 +142,9 @@ class StateInGame : BasicGameState() {
|
||||
|
||||
|
||||
// add new player and put it to actorContainer
|
||||
//playableActorDelegate = PlayableActorDelegate(PlayerBuilderSigrid())
|
||||
playableActorDelegate = PlayableActorDelegate(PlayerBuilderTestSubject1())
|
||||
addNewActor(player)
|
||||
playableActorDelegate = PlayableActorDelegate(PlayerBuilderSigrid())
|
||||
//playableActorDelegate = PlayableActorDelegate(PlayerBuilderTestSubject1())
|
||||
addNewActor(player!!)
|
||||
|
||||
|
||||
// test actor
|
||||
@@ -342,10 +343,10 @@ class StateInGame : BasicGameState() {
|
||||
}
|
||||
|
||||
// take care of old delegate
|
||||
playableActorDelegate.actor.collisionType = HumanoidNPC.DEFAULT_COLLISION_TYPE
|
||||
playableActorDelegate!!.actor.collisionType = HumanoidNPC.DEFAULT_COLLISION_TYPE
|
||||
// accept new delegate
|
||||
playableActorDelegate = PlayableActorDelegate(getActorByID(refid) as ActorHumanoid)
|
||||
playableActorDelegate.actor.collisionType = ActorWithSprite.COLLISION_KINEMATIC
|
||||
playableActorDelegate!!.actor.collisionType = ActorWithSprite.COLLISION_KINEMATIC
|
||||
WorldSimulator(player, UPDATE_DELTA)
|
||||
}
|
||||
|
||||
@@ -392,7 +393,7 @@ class StateInGame : BasicGameState() {
|
||||
/////////////////
|
||||
actorsRenderMiddle.forEach { it.drawBody(worldG) }
|
||||
actorsRenderMidTop.forEach { it.drawBody(worldG) }
|
||||
player.drawBody(worldG)
|
||||
player?.drawBody(worldG)
|
||||
actorsRenderFront.forEach { it.drawBody(worldG) }
|
||||
// --> Change of blend mode <-- introduced by ActorVisible //
|
||||
|
||||
@@ -419,7 +420,7 @@ class StateInGame : BasicGameState() {
|
||||
//////////////////////
|
||||
actorsRenderMiddle.forEach { it.drawGlow(worldG) }
|
||||
actorsRenderMidTop.forEach { it.drawGlow(worldG) }
|
||||
player.drawGlow(worldG)
|
||||
player?.drawGlow(worldG)
|
||||
actorsRenderFront.forEach { it.drawGlow(worldG) }
|
||||
// --> blendLightenOnly() <-- introduced by ActorVisible //
|
||||
|
||||
@@ -521,7 +522,7 @@ class StateInGame : BasicGameState() {
|
||||
GameController.keyPressed(key, c)
|
||||
|
||||
if (canPlayerMove) {
|
||||
player.keyPressed(key, c)
|
||||
player?.keyPressed(key, c)
|
||||
}
|
||||
|
||||
if (Terrarum.getConfigIntArray("keyquickselalt").contains(key)
|
||||
@@ -747,7 +748,8 @@ class StateInGame : BasicGameState() {
|
||||
* This is how remove function of [java.util.ArrayList] is defined.
|
||||
*/
|
||||
fun removeActor(actor: Actor) {
|
||||
if (actor.referenceID == player.referenceID) throw RuntimeException("Attempted to remove player.")
|
||||
if (actor.referenceID == player?.referenceID || actor.referenceID == 0x51621D) // do not delete this magic
|
||||
throw RuntimeException("Attempted to remove player.")
|
||||
val indexToDelete = actorContainer.binarySearch(actor.referenceID)
|
||||
if (indexToDelete >= 0) {
|
||||
actorContainer.removeAt(indexToDelete)
|
||||
|
||||
@@ -138,11 +138,11 @@ class UIItemInventoryElem(
|
||||
val itemEquipSlot = item!!.equipPosition
|
||||
val player = Terrarum.ingame!!.player
|
||||
|
||||
if (item != player.inventory.itemEquipped[itemEquipSlot]) { // if this item is unequipped, equip it
|
||||
player.equipItem(item!!)
|
||||
if (item != player?.inventory?.itemEquipped?.get(itemEquipSlot)) { // if this item is unequipped, equip it
|
||||
player?.equipItem(item!!)
|
||||
}
|
||||
else { // if not, unequip it
|
||||
player.unequipItem(item!!)
|
||||
player?.unequipItem(item!!)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ internal object ExportAV : ConsoleCommand {
|
||||
if (args.size == 2) {
|
||||
try {
|
||||
JsonWriter.writeToFile(
|
||||
Terrarum.ingame!!.player.actorValue,
|
||||
Terrarum.ingame!!.player!!.actorValue,
|
||||
Terrarum.defaultDir + "/Exports/" + args[1] + ".json")
|
||||
|
||||
Echo("ExportAV: exported to " + args[1] + ".json")
|
||||
|
||||
@@ -17,9 +17,9 @@ internal object GetAV : ConsoleCommand {
|
||||
|
||||
override fun execute(args: Array<String>) {
|
||||
try {
|
||||
if (args.size == 1) {
|
||||
if (args.size == 1 && Terrarum.ingame!!.player != null) {
|
||||
// print all actorvalue of player
|
||||
val av = Terrarum.ingame!!.player.actorValue
|
||||
val av = Terrarum.ingame!!.player!!.actorValue
|
||||
val keyset = av.keySet
|
||||
|
||||
Echo("$ccW== ActorValue list for ${ccY}player $ccW==")
|
||||
@@ -37,14 +37,14 @@ internal object GetAV : ConsoleCommand {
|
||||
if (!args[1].isNum()) { // args[1] is ActorValue name
|
||||
Echo("${ccW}player.$ccM${args[1]} $ccW= " +
|
||||
ccG +
|
||||
Terrarum.ingame!!.player.actorValue[args[1]] +
|
||||
Terrarum.ingame!!.player!!.actorValue[args[1]] +
|
||||
" $ccO" +
|
||||
Terrarum.ingame!!.player.actorValue[args[1]]!!.javaClass.simpleName
|
||||
Terrarum.ingame!!.player!!.actorValue[args[1]]!!.javaClass.simpleName
|
||||
)
|
||||
println("[GetAV] player.${args[1]} = " +
|
||||
Terrarum.ingame!!.player.actorValue[args[1]] +
|
||||
Terrarum.ingame!!.player!!.actorValue[args[1]] +
|
||||
" " +
|
||||
Terrarum.ingame!!.player.actorValue[args[1]]!!.javaClass.simpleName
|
||||
Terrarum.ingame!!.player!!.actorValue[args[1]]!!.javaClass.simpleName
|
||||
)
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -11,7 +11,7 @@ import net.torvald.terrarum.itemproperties.ItemCodex
|
||||
*/
|
||||
internal object Inventory : ConsoleCommand {
|
||||
|
||||
private var target: Pocketed = Terrarum.ingame!!.player
|
||||
private var target: Pocketed? = Terrarum.ingame!!.player
|
||||
|
||||
override fun execute(args: Array<String>) {
|
||||
if (args.size == 1) {
|
||||
@@ -30,15 +30,17 @@ internal object Inventory : ConsoleCommand {
|
||||
}
|
||||
|
||||
private fun listInventory() {
|
||||
if (target.inventory.getTotalUniqueCount() == 0) {
|
||||
Echo("(inventory empty)")
|
||||
}
|
||||
else {
|
||||
target.inventory.forEach {
|
||||
if (it.amount == 0) {
|
||||
EchoError("Unexpected zero-amounted item: ID ${it.item.id}")
|
||||
if (target != null) {
|
||||
if (target!!.inventory.getTotalUniqueCount() == 0) {
|
||||
Echo("(inventory empty)")
|
||||
}
|
||||
else {
|
||||
target!!.inventory.forEach {
|
||||
if (it.amount == 0) {
|
||||
EchoError("Unexpected zero-amounted item: ID ${it.item.id}")
|
||||
}
|
||||
Echo("ID ${it.item.id}${if (it.amount > 1) " ($it.second)" else ""}")
|
||||
}
|
||||
Echo("ID ${it.item.id}${if (it.amount > 1) " ($it.second)" else ""}")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -54,18 +56,22 @@ internal object Inventory : ConsoleCommand {
|
||||
}
|
||||
|
||||
private fun addItem(refId: Int, amount: Int = 1) {
|
||||
target.inventory.add(ItemCodex[refId], amount)
|
||||
if (target != null) {
|
||||
target!!.inventory.add(ItemCodex[refId], amount)
|
||||
}
|
||||
}
|
||||
|
||||
private fun equipItem(refId: Int) {
|
||||
val item = ItemCodex[refId]
|
||||
if (target != null) {
|
||||
val item = ItemCodex[refId]
|
||||
|
||||
// if the item does not exist, add it first
|
||||
if (!target.inventory.hasItem(item)) {
|
||||
target.inventory.add(item)
|
||||
// if the item does not exist, add it first
|
||||
if (!target!!.inventory.hasItem(item)) {
|
||||
target!!.inventory.add(item)
|
||||
}
|
||||
|
||||
target!!.inventory.itemEquipped[item.equipPosition] = item
|
||||
}
|
||||
|
||||
target.inventory.itemEquipped[item.equipPosition] = item
|
||||
}
|
||||
|
||||
override fun printUsage() {
|
||||
|
||||
@@ -66,7 +66,7 @@ internal object SetAV : ConsoleCommand {
|
||||
return
|
||||
}
|
||||
|
||||
Terrarum.ingame!!.player.actorValue[args[1]] = newValue
|
||||
Terrarum.ingame!!.player!!.actorValue[args[1]] = newValue
|
||||
Echo("${ccW}Set $ccM${args[1]} ${ccW}for ${ccY}player ${ccW}to $ccG$newValue")
|
||||
println("[SetAV] set ActorValue '${args[1]}' for player to '$newValue'.")
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ object SetScale : ConsoleCommand {
|
||||
override fun execute(args: Array<String>) {
|
||||
if (args.size == 2 || args.size == 3) {
|
||||
try {
|
||||
val targetID = if (args.size == 3) args[1].toInt() else Terrarum.ingame!!.player.referenceID
|
||||
val targetID = if (args.size == 3) args[1].toInt() else Terrarum.ingame!!.player!!.referenceID
|
||||
val scale = args[if (args.size == 3) 2 else 1].toDouble()
|
||||
|
||||
val target = Terrarum.ingame!!.getActorByID(targetID)
|
||||
|
||||
@@ -24,7 +24,7 @@ internal object Teleport : ConsoleCommand {
|
||||
return
|
||||
}
|
||||
|
||||
Terrarum.ingame!!.player.setPosition(x.toDouble(), y.toDouble())
|
||||
Terrarum.ingame!!.player!!.setPosition(x.toDouble(), y.toDouble())
|
||||
}
|
||||
else if (args.size == 4) {
|
||||
if (args[2].toLowerCase() != "to") {
|
||||
@@ -36,7 +36,7 @@ internal object Teleport : ConsoleCommand {
|
||||
try {
|
||||
val fromActorID = args[1].toInt()
|
||||
val targetActorID = if (args[3].toLowerCase() == "player")
|
||||
Terrarum.ingame!!.player.referenceID
|
||||
Terrarum.ingame!!.player!!.referenceID
|
||||
else
|
||||
args[3].toInt()
|
||||
|
||||
|
||||
@@ -8,9 +8,9 @@ import net.torvald.terrarum.Terrarum
|
||||
*/
|
||||
internal object ToggleNoClip : ConsoleCommand {
|
||||
override fun execute(args: Array<String>) {
|
||||
val status = Terrarum.ingame!!.player.isNoClip()
|
||||
val status = Terrarum.ingame!!.player!!.isNoClip()
|
||||
|
||||
Terrarum.ingame!!.player.setNoClip(!status)
|
||||
Terrarum.ingame!!.player!!.setNoClip(!status)
|
||||
Echo("Set no-clip status to " + (!status).toString())
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ import javax.swing.*
|
||||
*/
|
||||
class ActorValueTracker constructor() : JFrame() {
|
||||
|
||||
constructor(actor: Actor) : this() {
|
||||
constructor(actor: Actor?) : this() {
|
||||
setTrackingActor(actor)
|
||||
}
|
||||
|
||||
@@ -146,8 +146,8 @@ class ActorValueTracker constructor() : JFrame() {
|
||||
this.isVisible = true
|
||||
}
|
||||
|
||||
fun setTrackingActor(actor: Actor) {
|
||||
this.actorValue = actor.actorValue
|
||||
fun setTrackingActor(actor: Actor?) {
|
||||
this.actorValue = actor?.actorValue
|
||||
|
||||
this.title = "AVTracker — $actor"
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import java.util.concurrent.locks.ReentrantLock
|
||||
* Created by minjaesong on 16-03-15.
|
||||
*/
|
||||
|
||||
class ActorInventory(val actor: Pocketed, var maxCapacity: Int, private var capacityMode: Int) {
|
||||
class ActorInventory(val actor: Pocketed, var maxCapacity: Int, var capacityMode: Int) {
|
||||
|
||||
companion object {
|
||||
@Transient val CAPACITY_MODE_NO_ENCUMBER = 0
|
||||
@@ -34,10 +34,10 @@ class ActorInventory(val actor: Pocketed, var maxCapacity: Int, private var capa
|
||||
|
||||
fun add(itemID: Int, count: Int = 1) = add(ItemCodex[itemID], count)
|
||||
fun add(item: InventoryItem, count: Int = 1) {
|
||||
if (item.id == Player.PLAYER_REF_ID)
|
||||
if (item.id == Player.PLAYER_REF_ID || item.id == 0x51621D) // do not delete this magic
|
||||
throw IllegalArgumentException("Attempted to put human player into the inventory.")
|
||||
if (Terrarum.ingame != null &&
|
||||
item.id == Terrarum.ingame!!.player.referenceID)
|
||||
(item.id == Terrarum.ingame?.player?.referenceID))
|
||||
throw IllegalArgumentException("Attempted to put active player into the inventory.")
|
||||
|
||||
// If we already have the item, increment the amount
|
||||
@@ -67,10 +67,10 @@ class ActorInventory(val actor: Pocketed, var maxCapacity: Int, private var capa
|
||||
add(item, -count)
|
||||
}
|
||||
else {
|
||||
// depleted item; remove entry from inventory
|
||||
itemList.remove(existingItem)
|
||||
// unequip, if applicable
|
||||
actor.unequipItem(existingItem.item)
|
||||
// depleted item; remove entry from inventory
|
||||
itemList.remove(existingItem)
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -75,7 +75,7 @@ object PlayerBuilderSigrid {
|
||||
|
||||
|
||||
// Test fill up inventory
|
||||
p.inventory.add(16)
|
||||
p.inventory.add(16, 512)
|
||||
p.equipItem(ItemCodex[16])
|
||||
|
||||
|
||||
|
||||
@@ -70,15 +70,17 @@ object GameController {
|
||||
///////////////////
|
||||
|
||||
// Use item: assuming the player has only one effective grip (EquipPosition.HAND_GRIP)
|
||||
if (input.isMouseButtonDown(Terrarum.getConfigInt("mouseprimary")) || input.isMouseButtonDown(Terrarum.getConfigInt("mousesecondary"))) {
|
||||
val itemOnGrip = ingame.player.inventory.itemEquipped[InventoryItem.EquipPosition.HAND_GRIP]
|
||||
if (ingame.player != null) {
|
||||
if (input.isMouseButtonDown(Terrarum.getConfigInt("mouseprimary")) || input.isMouseButtonDown(Terrarum.getConfigInt("mousesecondary"))) {
|
||||
val itemOnGrip = ingame.player!!.inventory.itemEquipped[InventoryItem.EquipPosition.HAND_GRIP]
|
||||
|
||||
if (itemOnGrip != null) {
|
||||
if (input.isMouseButtonDown(Terrarum.getConfigInt("mouseprimary"))) {
|
||||
ingame.player.consumePrimary(itemOnGrip)
|
||||
}
|
||||
else if (input.isMouseButtonDown(Terrarum.getConfigInt("mousesecondary"))) {
|
||||
ingame.player.consumeSecondary(itemOnGrip)
|
||||
if (itemOnGrip != null) {
|
||||
if (input.isMouseButtonDown(Terrarum.getConfigInt("mouseprimary"))) {
|
||||
ingame.player!!.consumePrimary(itemOnGrip)
|
||||
}
|
||||
else if (input.isMouseButtonDown(Terrarum.getConfigInt("mousesecondary"))) {
|
||||
ingame.player!!.consumeSecondary(itemOnGrip)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,6 +113,8 @@ abstract class InventoryItem : Comparable<InventoryItem> {
|
||||
* The item will NOT be consumed, so you will want to consume it yourself by inventory.consumeItem(item)
|
||||
*
|
||||
* @return true when used successfully, false otherwise
|
||||
*
|
||||
* note: DO NOT super(gc, g) this!
|
||||
*/
|
||||
open fun primaryUse(gc: GameContainer, delta: Int): Boolean = false
|
||||
|
||||
@@ -121,6 +123,8 @@ abstract class InventoryItem : Comparable<InventoryItem> {
|
||||
* The item will NOT be consumed, so you will want to consume it yourself by inventory.consumeItem(item)
|
||||
*
|
||||
* @return true when used successfully, false otherwise
|
||||
*
|
||||
* note: DO NOT super(gc, g) this!
|
||||
*/
|
||||
open fun secondaryUse(gc: GameContainer, delta: Int): Boolean = false
|
||||
|
||||
|
||||
@@ -34,9 +34,9 @@ object MapCamera {
|
||||
|
||||
// position - (WH / 2)
|
||||
x = Math.round(// X only: ROUNDWORLD implementation
|
||||
player.hitbox.centeredX.toFloat() - width / 2)
|
||||
(player?.hitbox?.centeredX?.toFloat() ?: 0f) - width / 2)
|
||||
y = Math.round(FastMath.clamp(
|
||||
player.hitbox.centeredY.toFloat() - height / 2,
|
||||
(player?.hitbox?.centeredY?.toFloat() ?: 0f) - height / 2,
|
||||
TILE_SIZE.toFloat(),
|
||||
world!!.height * TILE_SIZE - height - TILE_SIZE.toFloat()
|
||||
))
|
||||
|
||||
@@ -34,9 +34,9 @@ object TileStats {
|
||||
val renderHeight = FastMath.ceil(Terrarum.HEIGHT.toFloat())
|
||||
|
||||
val noZoomCameraX = Math.round(FastMath.clamp(
|
||||
player.hitbox.centeredX.toFloat() - renderWidth / 2, TSIZE.toFloat(), map.width * TSIZE - renderWidth - TSIZE.toFloat()))
|
||||
(player?.hitbox?.centeredX?.toFloat() ?: 0f) - renderWidth / 2, TSIZE.toFloat(), map.width * TSIZE - renderWidth - TSIZE.toFloat()))
|
||||
val noZoomCameraY = Math.round(FastMath.clamp(
|
||||
player.hitbox.centeredY.toFloat() - renderHeight / 2, TSIZE.toFloat(), map.width * TSIZE - renderHeight - TSIZE.toFloat()))
|
||||
(player?.hitbox?.centeredY?.toFloat() ?: 0f) - renderHeight / 2, TSIZE.toFloat(), map.width * TSIZE - renderHeight - TSIZE.toFloat()))
|
||||
|
||||
val for_x_start = noZoomCameraX / TSIZE
|
||||
val for_y_start = noZoomCameraY / TSIZE
|
||||
|
||||
@@ -45,13 +45,13 @@ class BasicDebugInfoWindow : UICanvas {
|
||||
|
||||
override fun update(gc: GameContainer, delta: Int) {
|
||||
val player = Terrarum.ingame!!.player
|
||||
val hitbox = player.hitbox
|
||||
val hitbox = player?.hitbox
|
||||
|
||||
xdelta = hitbox.pointedX - prevPlayerX
|
||||
ydelta = hitbox.pointedY - prevPlayerY
|
||||
xdelta = hitbox?.pointedX ?: 0 - prevPlayerX
|
||||
ydelta = hitbox?.pointedY ?: 0 - prevPlayerY
|
||||
|
||||
prevPlayerX = hitbox.pointedX
|
||||
prevPlayerY = hitbox.pointedY
|
||||
prevPlayerX = hitbox?.pointedX ?: 0.0
|
||||
prevPlayerY = hitbox?.pointedY ?: 0.0
|
||||
}
|
||||
|
||||
override fun render(gc: GameContainer, g: Graphics) {
|
||||
@@ -67,8 +67,8 @@ class BasicDebugInfoWindow : UICanvas {
|
||||
g.font = Terrarum.fontSmallNumbers
|
||||
g.color = GameFontBase.codeToCol["y"]
|
||||
|
||||
val hitbox = player.hitbox
|
||||
val nextHitbox = player.nextHitbox
|
||||
val hitbox = player?.hitbox
|
||||
val nextHitbox = player?.nextHitbox
|
||||
|
||||
/**
|
||||
* First column
|
||||
@@ -76,25 +76,25 @@ class BasicDebugInfoWindow : UICanvas {
|
||||
|
||||
printLine(g, 1, "posX "
|
||||
+ ccG
|
||||
+ "${hitbox.pointedX}"
|
||||
+ "${hitbox?.pointedX}"
|
||||
+ " ("
|
||||
+ "${(hitbox.pointedX / FeaturesDrawer.TILE_SIZE).toInt()}"
|
||||
+ "${(hitbox?.pointedX?.div(FeaturesDrawer.TILE_SIZE))?.toInt()}"
|
||||
+ ")")
|
||||
printLine(g, 2, "posY "
|
||||
+ ccG
|
||||
+ hitbox.pointedY.toString()
|
||||
+ hitbox?.pointedY.toString()
|
||||
+ " ("
|
||||
+ (hitbox.pointedY / FeaturesDrawer.TILE_SIZE).toInt().toString()
|
||||
+ (hitbox?.pointedY?.div(FeaturesDrawer.TILE_SIZE))?.toInt().toString()
|
||||
+ ")")
|
||||
|
||||
printLine(g, 3, "veloX reported $ccG${player.moveDelta.x}")
|
||||
printLine(g, 4, "veloY reported $ccG${player.moveDelta.y}")
|
||||
printLine(g, 3, "veloX reported $ccG${player?.moveDelta?.x}")
|
||||
printLine(g, 4, "veloY reported $ccG${player?.moveDelta?.y}")
|
||||
|
||||
printLineColumn(g, 2, 3, "veloX measured $ccG${xdelta}")
|
||||
printLineColumn(g, 2, 4, "veloY measured $ccG${ydelta}")
|
||||
|
||||
printLine(g, 5, "grounded $ccG${player.grounded}")
|
||||
printLine(g, 6, "noClip $ccG${player.noClip}")
|
||||
printLine(g, 5, "grounded $ccG${player?.grounded}")
|
||||
printLine(g, 6, "noClip $ccG${player?.noClip}")
|
||||
|
||||
//printLine(g, 7, "jump $ccG${player.jumpAcc}")
|
||||
|
||||
@@ -129,10 +129,10 @@ class BasicDebugInfoWindow : UICanvas {
|
||||
printLineColumn(g, 2, 2, "Env colour temp $ccG" + FeaturesDrawer.colTemp)
|
||||
printLineColumn(g, 2, 5, "Time $ccG${Terrarum.ingame!!.world.time.todaySeconds.toString().padStart(5, '0')}" +
|
||||
" (${Terrarum.ingame!!.world.time.getFormattedTime()})")
|
||||
printLineColumn(g, 2, 6, "Mass $ccG${player.mass}")
|
||||
printLineColumn(g, 2, 6, "Mass $ccG${player?.mass}")
|
||||
|
||||
printLineColumn(g, 2, 7, "p_WalkX $ccG${player.walkX}")
|
||||
printLineColumn(g, 2, 8, "p_WalkY $ccG${player.walkY}")
|
||||
printLineColumn(g, 2, 7, "p_WalkX $ccG${player?.walkX}")
|
||||
printLineColumn(g, 2, 8, "p_WalkY $ccG${player?.walkY}")
|
||||
|
||||
|
||||
drawHistogram(g, LightmapRenderer.histogram,
|
||||
|
||||
@@ -5,6 +5,7 @@ import net.torvald.terrarum.Terrarum.QUICKSLOT_MAX
|
||||
import net.torvald.terrarum.Terrarum.joypadLabelNinA
|
||||
import net.torvald.terrarum.Terrarum.joypadLabelNinY
|
||||
import net.torvald.terrarum.gameactors.*
|
||||
import net.torvald.terrarum.gameactors.ActorInventory.Companion.CAPACITY_MODE_NO_ENCUMBER
|
||||
import net.torvald.terrarum.gameitem.InventoryItem
|
||||
import net.torvald.terrarum.itemproperties.ItemCodex
|
||||
import net.torvald.terrarum.langpack.Lang
|
||||
@@ -125,6 +126,9 @@ class UIInventory(
|
||||
|
||||
private var oldCatSelect = -1
|
||||
|
||||
private var encumbrancePerc = 0f
|
||||
private var isEncumbered = false
|
||||
|
||||
override fun update(gc: GameContainer, delta: Int) {
|
||||
catButtons.update(gc, delta)
|
||||
|
||||
@@ -140,6 +144,12 @@ class UIInventory(
|
||||
if (rebuildList) {
|
||||
val filter = catButtonsToCatIdent[catButtons.selectedButton.labelText]
|
||||
|
||||
// encumbrance
|
||||
encumbrancePerc = inventory!!.capacity.toFloat() / inventory!!.maxCapacity
|
||||
isEncumbered = inventory!!.isEncumbered
|
||||
|
||||
|
||||
|
||||
inventorySortList = ArrayList<InventoryPair>()
|
||||
|
||||
// filter items
|
||||
@@ -250,12 +260,14 @@ class UIInventory(
|
||||
)
|
||||
// encumbrance bar
|
||||
blendNormal()
|
||||
val encumbPerc = inventory!!.capacity.toFloat() / inventory!!.maxCapacity
|
||||
g.color = if (inventory!!.isEncumbered) Color(0xccff0000.toInt()) else Color(0xcc00ff00.toInt())
|
||||
g.color = if (isEncumbered) Color(0xccff0000.toInt()) else Color(0xcc00ff00.toInt())
|
||||
g.fillRect(
|
||||
width - 3 - weightBarWidth,
|
||||
height - controlHelpHeight + 3f,
|
||||
minOf(weightBarWidth, maxOf(1f, weightBarWidth * encumbPerc)), // make sure 1px is always be seen
|
||||
if (actor?.inventory?.capacityMode == CAPACITY_MODE_NO_ENCUMBER)
|
||||
1f
|
||||
else // make sure 1px is always be seen
|
||||
minOf(weightBarWidth, maxOf(1f, weightBarWidth * encumbrancePerc)),
|
||||
controlHelpHeight - 5f
|
||||
)
|
||||
}
|
||||
|
||||
@@ -34,11 +34,11 @@ class UIPieMenu : UICanvas {
|
||||
var selection: Int = -1
|
||||
|
||||
override fun update(gc: GameContainer, delta: Int) {
|
||||
if (selection >= 0)
|
||||
Terrarum.ingame!!.player.actorValue[AVKey.__PLAYER_QUICKSLOTSEL] =
|
||||
selection % slotCount
|
||||
|
||||
|
||||
if (Terrarum.ingame!!.player != null) {
|
||||
if (selection >= 0)
|
||||
Terrarum.ingame!!.player!!.actorValue[AVKey.__PLAYER_QUICKSLOTSEL] =
|
||||
selection % slotCount
|
||||
}
|
||||
}
|
||||
|
||||
override fun render(gc: GameContainer, g: Graphics) {
|
||||
|
||||
@@ -25,8 +25,8 @@ class UIQuickBar : UICanvas, MouseControlled {
|
||||
override var handler: UIHandler? = null
|
||||
|
||||
private var selection: Int
|
||||
get() = Terrarum.ingame!!.player.actorValue.getAsInt(AVKey.__PLAYER_QUICKSLOTSEL) ?: 0
|
||||
set(value) { Terrarum.ingame!!.player.actorValue[AVKey.__PLAYER_QUICKSLOTSEL] = value }
|
||||
get() = Terrarum.ingame!!.player?.actorValue?.getAsInt(AVKey.__PLAYER_QUICKSLOTSEL) ?: 0
|
||||
set(value) { Terrarum.ingame!!.player?.actorValue?.set(AVKey.__PLAYER_QUICKSLOTSEL, value) }
|
||||
|
||||
override fun update(gc: GameContainer, delta: Int) {
|
||||
}
|
||||
|
||||
@@ -81,17 +81,20 @@ object WeatherMixer {
|
||||
currentWeather = weatherList[WEATHER_GENERIC]!![0]
|
||||
|
||||
|
||||
// test rain toggled by F2
|
||||
if (KeyToggler.isOn(Key.F2)) {
|
||||
val playerPos = Terrarum.ingame!!.player.centrePosPoint
|
||||
kotlin.repeat(4) { // 4 seems good
|
||||
val rainParticle = ParticleTestRain(
|
||||
playerPos.x + HQRNG().nextInt(Terrarum.WIDTH) - Terrarum.HALFW,
|
||||
playerPos.y - Terrarum.HALFH
|
||||
)
|
||||
Terrarum.ingame!!.addParticle(rainParticle)
|
||||
if (Terrarum.ingame!!.player != null) {
|
||||
// test rain toggled by F2
|
||||
if (KeyToggler.isOn(Key.F2)) {
|
||||
val playerPos = Terrarum.ingame!!.player!!.centrePosPoint
|
||||
kotlin.repeat(4) {
|
||||
// 4 seems good
|
||||
val rainParticle = ParticleTestRain(
|
||||
playerPos.x + HQRNG().nextInt(Terrarum.WIDTH) - Terrarum.HALFW,
|
||||
playerPos.y - Terrarum.HALFH
|
||||
)
|
||||
Terrarum.ingame!!.addParticle(rainParticle)
|
||||
}
|
||||
globalLightNow.set(getGlobalLightOfTime(world.time.todaySeconds).darker(0.3f))
|
||||
}
|
||||
globalLightNow.set(getGlobalLightOfTime(world.time.todaySeconds).darker(0.3f))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user