mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-13 23:26:07 +09:00
briefy showing item name to the quickslot when the selection has changed
This commit is contained in:
@@ -76,7 +76,7 @@ class ItemWearableWorldRadar(originalID: String) : GameItem(originalID) {
|
||||
|
||||
}
|
||||
|
||||
override fun effectWhenEquipped(actor: ActorWithBody, delta: Float) {
|
||||
override fun effectWhileEquipped(actor: ActorWithBody, delta: Float) {
|
||||
(Terrarum.ingame!! as TerrarumIngame).wearableDeviceUI = ui
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ object DefaultConfig {
|
||||
|
||||
"language" to App.getSysLang(),
|
||||
"notificationshowuptime" to 4096, // 4s
|
||||
"selecteditemnameshowuptime" to 4096, // 4s
|
||||
"autosaveinterval" to 262144, // 4m22s
|
||||
"multithread" to true,
|
||||
|
||||
|
||||
@@ -46,6 +46,11 @@ abstract class GameItem(val originalID: ItemID) : Comparable<GameItem>, Cloneabl
|
||||
var newName: String = "I AM VITUN PLACEHOLDER"
|
||||
private set
|
||||
|
||||
/**
|
||||
* If custom name is configured, its name (`newName`) is returned; otherwise the `originalName` is returned.
|
||||
*
|
||||
* Assigning value to this field will set the `newName`
|
||||
*/
|
||||
var name: String
|
||||
set(value) {
|
||||
newName = value
|
||||
@@ -180,9 +185,9 @@ abstract class GameItem(val originalID: ItemID) : Comparable<GameItem>, Cloneabl
|
||||
open fun effectWhileInPocket(actor: ActorWithBody, delta: Float) { }
|
||||
|
||||
/**
|
||||
* Effects applied immediately only once if picked up
|
||||
* Effects applied immediately only once when picked up
|
||||
*/
|
||||
open fun effectWhenPickedUp(actor: ActorWithBody, delta: Float) { }
|
||||
open fun effectOnPickup(actor: ActorWithBody, delta: Float) { }
|
||||
|
||||
/**
|
||||
* Apply effects (continuously or not) while primary button is down.
|
||||
@@ -217,17 +222,17 @@ abstract class GameItem(val originalID: ItemID) : Comparable<GameItem>, Cloneabl
|
||||
//open fun startSecondaryUse(delta: Float): Boolean = false
|
||||
|
||||
open fun endPrimaryUse(actor: ActorWithBody, delta: Float): Boolean = false
|
||||
open fun endSecondaryUse(actor: ActorWithBody, delta: Float): Boolean = false
|
||||
//open fun endSecondaryUse(actor: ActorWithBody, delta: Float): Boolean = false
|
||||
|
||||
/**
|
||||
* Effects applied immediately only once if thrown (discarded) from pocket
|
||||
* Effects applied immediately only once when thrown (discarded) from pocket
|
||||
*/
|
||||
open fun effectWhenThrown(actor: ActorWithBody, delta: Float) { }
|
||||
open fun effectOnThrow(actor: ActorWithBody, delta: Float) { }
|
||||
|
||||
/**
|
||||
* Effects applied (continuously or not) when equipped (drawn/pulled out)
|
||||
* Effects applied (continuously or not) while being equipped (drawn/pulled out)
|
||||
*/
|
||||
open fun effectWhenEquipped(actor: ActorWithBody, delta: Float) { }
|
||||
open fun effectWhileEquipped(actor: ActorWithBody, delta: Float) { }
|
||||
|
||||
/**
|
||||
* Effects applied only once when unequipped
|
||||
|
||||
@@ -98,7 +98,7 @@ class EntryPoint : ModuleEntryPoint() {
|
||||
return BlockBase.blockStartPrimaryUse(actor, this, dynamicID, delta)
|
||||
}
|
||||
|
||||
override fun effectWhenEquipped(actor: ActorWithBody, delta: Float) {
|
||||
override fun effectWhileEquipped(actor: ActorWithBody, delta: Float) {
|
||||
BlockBase.blockEffectWhenEquipped(actor, delta)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1048,7 +1048,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
it.inventory.forEach { inventoryEntry ->
|
||||
ItemCodex[inventoryEntry.itm]!!.effectWhileInPocket(it as ActorWithBody, delta) // kind of an error checking because all Pocketed must be ActorWithBody
|
||||
if (it.equipped(inventoryEntry.itm)) {
|
||||
ItemCodex[inventoryEntry.itm]!!.effectWhenEquipped(it as ActorWithBody, delta)
|
||||
ItemCodex[inventoryEntry.itm]!!.effectWhileEquipped(it as ActorWithBody, delta)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -220,7 +220,7 @@ open class ActorHumanoid : ActorWithBody, Controllable, Pocketed, Factionable, L
|
||||
ItemCodex[it.itm]!!.effectWhileInPocket(this, delta)
|
||||
}
|
||||
else { // equipped
|
||||
ItemCodex[it.itm]!!.effectWhenEquipped(this, delta)
|
||||
ItemCodex[it.itm]!!.effectWhileEquipped(this, delta)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,9 +27,14 @@ class ActorInventory() : FixtureInventory() {
|
||||
|
||||
/**
|
||||
* List of all equipped items (tools, armours, rings, necklaces, etc.)
|
||||
*
|
||||
* The ItemID must be `dynamicID`
|
||||
*/
|
||||
val itemEquipped = Array<ItemID?>(GameItem.EquipPosition.INDEX_MAX) { null }
|
||||
|
||||
/**
|
||||
* The ItemID must be `dynamicID`
|
||||
*/
|
||||
val quickSlot = Array<ItemID?>(UIQuickslotBar.SLOT_COUNT) { null } // 0: Slot 1, 9: Slot 10
|
||||
|
||||
|
||||
|
||||
@@ -164,23 +164,40 @@ class IngamePlayer : ActorHumanoid {
|
||||
return spriteHeadTexture
|
||||
}
|
||||
|
||||
override fun equipItem(item: GameItem) {
|
||||
super.equipItem(item)
|
||||
private var unequipNoSpriteUpdate = false
|
||||
|
||||
// TODO redraw sprite with held item sprite (use sprite joint "HELD_ITEM")
|
||||
if (item.equipPosition == GameItem.EquipPosition.HAND_GRIP) {
|
||||
override fun equipItem(item: GameItem) {
|
||||
val oldItemID = inventory.itemEquipped[item.equipPosition]
|
||||
|
||||
unequipNoSpriteUpdate = true
|
||||
super.equipItem(item) // also calls unequipItem internally
|
||||
|
||||
// redraw sprite with held item sprite (use sprite joint "HELD_ITEM")
|
||||
if (item.dynamicID != oldItemID && item.equipPosition == GameItem.EquipPosition.HAND_GRIP) {
|
||||
rebuildfun(item)
|
||||
animDescGlow?.let { rebuildfunGlow(item) }
|
||||
}
|
||||
|
||||
unequipNoSpriteUpdate = false
|
||||
|
||||
// println("IngamePlayer.equipItem")
|
||||
// printStackTrace(this)
|
||||
}
|
||||
|
||||
override fun unequipItem(item: GameItem?) {
|
||||
super.unequipItem(item)
|
||||
|
||||
// redraw sprite without held item sprite (use sprite joint "HELD_ITEM")
|
||||
item?.let { item -> if (item.equipPosition == GameItem.EquipPosition.HAND_GRIP) {
|
||||
rebuildfun(null)
|
||||
animDescGlow?.let { rebuildfunGlow(null) }
|
||||
} }
|
||||
if (!unequipNoSpriteUpdate) {
|
||||
item?.let { item ->
|
||||
if (item.equipPosition == GameItem.EquipPosition.HAND_GRIP) {
|
||||
rebuildfun(null)
|
||||
animDescGlow?.let { rebuildfunGlow(null) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// println("IngamePlayer.unequipItem")
|
||||
// printStackTrace(this)
|
||||
}
|
||||
}
|
||||
@@ -57,17 +57,21 @@ interface Pocketed {
|
||||
* Equips an item. If the item is not in the inventory, adds the item first.
|
||||
*/
|
||||
fun equipItem(item: GameItem) {
|
||||
val oldItemID = inventory.itemEquipped[item.equipPosition]
|
||||
|
||||
if (!inventory.contains(item)) {
|
||||
println("[Pocketed] Item does not exist; adding one before equipped")
|
||||
inventory.add(item)
|
||||
}
|
||||
|
||||
// unequip item that's already there
|
||||
unequipSlot(item.equipPosition)
|
||||
if (item.dynamicID != oldItemID) {
|
||||
unequipSlot(item.equipPosition) // also fires effectOnUnequip unconditionally
|
||||
}
|
||||
|
||||
if (item.equipPosition >= 0) {
|
||||
inventory.itemEquipped[item.equipPosition] = item.dynamicID
|
||||
item.effectWhenEquipped(this as ActorWithBody, App.UPDATE_RATE)
|
||||
item.effectWhileEquipped(this as ActorWithBody, App.UPDATE_RATE)
|
||||
}
|
||||
// else do nothing
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ open class FixtureItemBase(originalID: ItemID, val makeFixture: () -> FixtureBas
|
||||
get() = CommonResourcePool.getAsTextureRegion("itemplaceholder_32")
|
||||
override var baseToolSize: Double? = baseMass
|
||||
|
||||
override fun effectWhenEquipped(actor: ActorWithBody, delta: Float) {
|
||||
override fun effectWhileEquipped(actor: ActorWithBody, delta: Float) {
|
||||
(INGAME as TerrarumIngame).blockMarkingActor.let {
|
||||
it.setGhost(ghostItem)
|
||||
it.isVisible = true
|
||||
|
||||
@@ -27,8 +27,8 @@ class ItemLogicSignalEmitter(originalID: ItemID) : FixtureItemBase(originalID, {
|
||||
equipPosition = EquipPosition.HAND_GRIP
|
||||
}
|
||||
|
||||
override fun effectWhenEquipped(actor: ActorWithBody, delta: Float) {
|
||||
super.effectWhenEquipped(actor, delta)
|
||||
override fun effectWhileEquipped(actor: ActorWithBody, delta: Float) {
|
||||
super.effectWhileEquipped(actor, delta)
|
||||
(Terrarum.ingame!! as TerrarumIngame).selectedWireRenderClass = "signal"
|
||||
}
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ class WireCutterAll(originalID: ItemID) : GameItem(originalID) {
|
||||
true
|
||||
}
|
||||
|
||||
override fun effectWhenEquipped(actor: ActorWithBody, delta: Float) {
|
||||
override fun effectWhileEquipped(actor: ActorWithBody, delta: Float) {
|
||||
(Terrarum.ingame!! as TerrarumIngame).selectedWireRenderClass = "wire_render_all"
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ class WireGraphDebugger(originalID: ItemID) : GameItem(originalID) {
|
||||
private val sb = StringBuilder()
|
||||
private val blockMarker = CommonResourcePool.get("blockmarking_actor") as BlockMarkerActor
|
||||
|
||||
override fun effectWhenEquipped(actor: ActorWithBody, delta: Float) {
|
||||
override fun effectWhileEquipped(actor: ActorWithBody, delta: Float) {
|
||||
(Terrarum.ingame!! as TerrarumIngame).selectedWireRenderClass = "wire_render_all"
|
||||
|
||||
blockMarker.markerShape = 3
|
||||
|
||||
@@ -34,7 +34,7 @@ class WirePieceSignalWire(originalID: ItemID, private val atlasID: String, priva
|
||||
return BlockBase.wireStartPrimaryUse(actor,this, delta)
|
||||
}
|
||||
|
||||
override fun effectWhenEquipped(actor: ActorWithBody, delta: Float) {
|
||||
override fun effectWhileEquipped(actor: ActorWithBody, delta: Float) {
|
||||
BlockBase.wireEffectWhenEquipped(this, delta)
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package net.torvald.terrarum.modulebasegame.ui
|
||||
import com.badlogic.gdx.graphics.Camera
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import com.jme3.math.FastMath
|
||||
import net.torvald.terrarum.App
|
||||
import net.torvald.terrarum.ItemCodex
|
||||
import net.torvald.terrarum.Second
|
||||
@@ -28,9 +29,11 @@ class UIQuickslotBar : UICanvas() {
|
||||
*/
|
||||
override var openCloseTime: Second = COMMON_OPEN_CLOSE
|
||||
|
||||
private var selection: Int
|
||||
get() = (Terrarum.ingame!! as TerrarumIngame).actorNowPlaying?.actorValue?.getAsInt(AVKey.__PLAYER_QUICKSLOTSEL) ?: 0
|
||||
set(value) { (Terrarum.ingame!! as TerrarumIngame).actorNowPlaying?.actorValue?.set(AVKey.__PLAYER_QUICKSLOTSEL, value.fmod(SLOT_COUNT)) }
|
||||
private var selection: Int = -1
|
||||
set(value) {
|
||||
(Terrarum.ingame!! as TerrarumIngame).actorNowPlaying?.actorValue?.set(AVKey.__PLAYER_QUICKSLOTSEL, value.fmod(SLOT_COUNT))
|
||||
field = value
|
||||
}
|
||||
|
||||
|
||||
companion object {
|
||||
@@ -41,29 +44,77 @@ class UIQuickslotBar : UICanvas() {
|
||||
|
||||
|
||||
override fun updateUI(delta: Float) {
|
||||
val newSelection = (Terrarum.ingame!! as TerrarumIngame).actorNowPlaying?.actorValue?.getAsInt(AVKey.__PLAYER_QUICKSLOTSEL) ?: 0
|
||||
|
||||
if (selection != newSelection) {
|
||||
nameShowupFired = true
|
||||
nameShowupTimer = 0f
|
||||
nameShowupAlpha = 1f
|
||||
showupTime = App.getConfigInt("selecteditemnameshowuptime").div(1000f) // refresh game config
|
||||
}
|
||||
|
||||
if (nameShowupFired) {
|
||||
|
||||
nameShowupTimer += delta
|
||||
|
||||
if (nameShowupTimer >= NAME_SHOWUP_DECAY + showupTime) {
|
||||
nameShowupAlpha = 0f
|
||||
nameShowupFired = false
|
||||
}
|
||||
else if (nameShowupTimer >= showupTime) {
|
||||
val a = (nameShowupTimer - showupTime) / NAME_SHOWUP_DECAY
|
||||
nameShowupAlpha = FastMath.interpolateLinear(a, 1f, 0f)
|
||||
}
|
||||
}
|
||||
|
||||
selection = newSelection
|
||||
}
|
||||
|
||||
private val NAME_SHOWUP_DECAY = COMMON_OPEN_CLOSE
|
||||
private var nameShowupAlpha = 0f
|
||||
private var nameShowupTimer = 0f
|
||||
private var nameShowupFired = false
|
||||
private var showupTime = App.getConfigInt("selecteditemnameshowuptime").div(1000f)
|
||||
|
||||
private val drawColor = Color(1f, 1f, 1f, 1f)
|
||||
|
||||
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
||||
|
||||
for (i in 0..SLOT_COUNT - 1) {
|
||||
val item = ItemCodex[(Terrarum.ingame!! as TerrarumIngame).actorNowPlaying?.inventory?.getQuickslot(i)?.itm]
|
||||
(Terrarum.ingame!! as TerrarumIngame).actorNowPlaying?.let { actor ->
|
||||
for (i in 0..SLOT_COUNT - 1) {
|
||||
val item = ItemCodex[actor.inventory.getQuickslot(i)?.itm]
|
||||
|
||||
val image = if (i == selection)
|
||||
ItemSlotImageFactory.produceLarge(false, (i + 1) % SLOT_COUNT, item)
|
||||
else
|
||||
ItemSlotImageFactory.produce(true, (i + 1) % SLOT_COUNT, item)
|
||||
val image = if (i == selection)
|
||||
ItemSlotImageFactory.produceLarge(false, (i + 1) % SLOT_COUNT, item)
|
||||
else
|
||||
ItemSlotImageFactory.produce(true, (i + 1) % SLOT_COUNT, item)
|
||||
|
||||
val slotX = cellSize / 2 + (cellSize + gutter) * i
|
||||
val slotY = cellSize / 2
|
||||
val slotX = cellSize / 2 + (cellSize + gutter) * i
|
||||
val slotY = cellSize / 2
|
||||
|
||||
// draw slots
|
||||
drawColor.a = handler.opacity * DISPLAY_OPACITY
|
||||
batch.color = drawColor
|
||||
image.draw(batch, slotX, slotY)
|
||||
// draw slots
|
||||
drawColor.set(-1)
|
||||
drawColor.a = handler.opacity * DISPLAY_OPACITY
|
||||
batch.color = drawColor
|
||||
image.draw(batch, slotX, slotY)
|
||||
}
|
||||
|
||||
if (nameShowupAlpha > 0f) {
|
||||
val selection = actor.actorValue.getAsInt(AVKey.__PLAYER_QUICKSLOTSEL) ?: return
|
||||
actor.inventory.getQuickslot(selection)?.let {
|
||||
val item = ItemCodex[it.itm]
|
||||
val quantity = it.qty
|
||||
val text = "${item?.name}" + (if (item?.isUnique == true) "" else " ($quantity)")
|
||||
val textWidth = App.fontGame.getWidth(text)
|
||||
|
||||
drawColor.set(item?.nameColour ?: Color.WHITE)
|
||||
drawColor.a = nameShowupAlpha
|
||||
batch.color = drawColor
|
||||
App.fontGame.draw(batch, text, (width - textWidth) / 2, height - 20)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user