mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-14 20:44:05 +09:00
briefy showing item name to the quickslot when the selection has changed
This commit is contained in:
@@ -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