mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 20:31:51 +09:00
item count and durability meter on the quickslot
This commit is contained in:
Binary file not shown.
@@ -92,12 +92,11 @@ class UIItemInventoryElemSimple(
|
||||
val percentage = item!!.durability / item!!.maxDurability
|
||||
val durabilityCol = UIItemInventoryCellCommonRes.getHealthMeterColour(percentage, 0f, 1f)
|
||||
val durabilityBack = durabilityCol mul UIItemInventoryCellCommonRes.meterBackDarkening
|
||||
if (item!!.maxDurability > 0.0) {
|
||||
batch.color = durabilityBack
|
||||
Toolkit.drawStraightLine(batch, barOffset, posY + height - thickness, barOffset + barFullLen, thickness, false)
|
||||
batch.color = durabilityCol
|
||||
Toolkit.drawStraightLine(batch, barOffset, posY + height - thickness, barOffset + (barFullLen * percentage).roundToInt(), thickness, false)
|
||||
}
|
||||
|
||||
batch.color = durabilityBack
|
||||
Toolkit.drawStraightLine(batch, barOffset, posY + height - thickness, barOffset + barFullLen, thickness, false)
|
||||
batch.color = durabilityCol
|
||||
Toolkit.drawStraightLine(batch, barOffset, posY + height - thickness, barOffset + (barFullLen * percentage).roundToInt(), thickness, false)
|
||||
}
|
||||
// draw item count when applicable
|
||||
else if (item!!.stackable) {
|
||||
|
||||
@@ -4,10 +4,10 @@ import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||
import net.torvald.terrarum.ItemCodex
|
||||
import net.torvald.terrarum.gameitems.GameItem
|
||||
import net.torvald.terrarum.toInt
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
import net.torvald.terrarum.*
|
||||
|
||||
|
||||
/**
|
||||
@@ -27,7 +27,7 @@ object ItemSlotImageFactory {
|
||||
/** Blend mode: screen */
|
||||
val CELLCOLOUR_BLACK_ACTIVE = Color(0x282828ff)
|
||||
|
||||
val slotImage = TextureRegionPack(Gdx.files.internal("./assets/graphics/gui/quickbar/item_slots_atlas2.tga"), 38, 38) // must have same w/h as slotLarge
|
||||
val slotImage = TextureRegionPack(Gdx.files.internal("./assets/graphics/gui/quickbar/item_slots_atlas2.tga"), 38, 42) // must have same w/h as slotLarge
|
||||
|
||||
fun produce(isBlack: Boolean, number: Int = 10, item: GameItem?): ItemSlotImage {
|
||||
return ItemSlotImage(slotImage.get(number, 0 or isBlack.toInt().shl(1)), ItemCodex.getItemImage(item))
|
||||
|
||||
@@ -4,14 +4,13 @@ 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
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.gameactors.AVKey
|
||||
import net.torvald.terrarum.gameworld.fmod
|
||||
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
||||
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellCommonRes.toItemCountText
|
||||
import net.torvald.terrarum.ui.UICanvas
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
/**
|
||||
* A bar-shaped representation of the Quickslot.
|
||||
@@ -78,11 +77,14 @@ class UIQuickslotBar : UICanvas() {
|
||||
|
||||
private val drawColor = Color(1f, 1f, 1f, 1f)
|
||||
|
||||
private val itemCntTextCol = Color(0x404040ff)
|
||||
|
||||
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
||||
|
||||
(Terrarum.ingame!! as TerrarumIngame).actorNowPlaying?.let { actor ->
|
||||
for (i in 0..SLOT_COUNT - 1) {
|
||||
val item = ItemCodex[actor.inventory.getQuickslotItem(i)?.itm]
|
||||
for (i in 0 until SLOT_COUNT) {
|
||||
val qs = actor.inventory.getQuickslotItem(i)
|
||||
val item = ItemCodex[qs?.itm]
|
||||
|
||||
val image = if (i == selection)
|
||||
ItemSlotImageFactory.produceLarge(false, (i + 1) % SLOT_COUNT, item)
|
||||
@@ -97,6 +99,31 @@ class UIQuickslotBar : UICanvas() {
|
||||
drawColor.a = handler.opacity * DISPLAY_OPACITY
|
||||
batch.color = drawColor
|
||||
image.draw(batch, slotX, slotY)
|
||||
|
||||
// durability meter/item count for the selected cell
|
||||
if (i == selection && item != null) {
|
||||
if (item.maxDurability > 0.0) {
|
||||
val percentage = item.durability / item.maxDurability
|
||||
val barCol = UIItemInventoryCellCommonRes.getHealthMeterColour(percentage, 0f, 1f)
|
||||
val barBack = barCol mul UIItemInventoryCellCommonRes.meterBackDarkening
|
||||
val durabilityIndex = percentage.times(36).roundToInt()
|
||||
|
||||
// draw bar background
|
||||
batch.color = barBack
|
||||
batch.draw(ItemSlotImageFactory.slotImage.get(6,7), slotX - 19f, slotY - 21f)
|
||||
// draw bar foreground
|
||||
batch.color = barCol
|
||||
batch.draw(ItemSlotImageFactory.slotImage.get(durabilityIndex % 10,4 + durabilityIndex / 10), slotX - 19f, slotY - 21f)
|
||||
}
|
||||
else if (item.stackable) {
|
||||
val amountString = qs!!.qty.toItemCountText()
|
||||
batch.color = Color(0xfff066_ff.toInt())
|
||||
val textLen = amountString.length * App.fontSmallNumbers.W
|
||||
val y = slotY + 23 - App.fontSmallNumbers.H
|
||||
val x = slotX - 19 + (38 - textLen) / 2
|
||||
App.fontSmallNumbers.draw(batch, amountString, x.toFloat(), y.toFloat())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (nameShowupAlpha > 0f) {
|
||||
|
||||
@@ -4,17 +4,16 @@ 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
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.gameactors.AVKey
|
||||
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
||||
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellCommonRes.toItemCountText
|
||||
import net.torvald.terrarum.modulebasegame.ui.UIQuickslotBar.Companion.COMMON_OPEN_CLOSE
|
||||
import net.torvald.terrarum.modulebasegame.ui.UIQuickslotBar.Companion.SLOT_COUNT
|
||||
import net.torvald.terrarum.ui.Toolkit
|
||||
import net.torvald.terrarum.ui.UICanvas
|
||||
import org.dyn4j.geometry.Vector2
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
/**
|
||||
* The Sims styled pie representation of the Quickslot.
|
||||
@@ -64,8 +63,9 @@ class UIQuickslotPie : UICanvas() {
|
||||
|
||||
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
||||
// draw radial thingies
|
||||
for (i in 0..slotCount - 1) {
|
||||
val item = ItemCodex[(Terrarum.ingame!! as TerrarumIngame).actorNowPlaying?.inventory?.getQuickslotItem(i)?.itm]
|
||||
for (i in 0 until slotCount) {
|
||||
val qs = (Terrarum.ingame!! as TerrarumIngame).actorNowPlaying?.inventory?.getQuickslotItem(i)
|
||||
val item = ItemCodex[qs?.itm]
|
||||
|
||||
// set position
|
||||
val angle = Math.PI * 2.0 * (i.toDouble() / slotCount) + Math.PI // 180 deg monitor-wise
|
||||
@@ -84,6 +84,30 @@ class UIQuickslotPie : UICanvas() {
|
||||
batch.color = drawColor
|
||||
image.draw(batch, slotX, slotY)
|
||||
|
||||
// durability meter/item count for the selected cell
|
||||
if (i == selection && item != null) {
|
||||
if (item.maxDurability > 0.0) {
|
||||
val percentage = item.durability / item.maxDurability
|
||||
val barCol = UIItemInventoryCellCommonRes.getHealthMeterColour(percentage, 0f, 1f)
|
||||
val barBack = barCol mul UIItemInventoryCellCommonRes.meterBackDarkening
|
||||
val durabilityIndex = percentage.times(36).roundToInt()
|
||||
|
||||
// draw bar background
|
||||
batch.color = barBack
|
||||
batch.draw(ItemSlotImageFactory.slotImage.get(6,7), slotX - 19f, slotY - 21f)
|
||||
// draw bar foreground
|
||||
batch.color = barCol
|
||||
batch.draw(ItemSlotImageFactory.slotImage.get(durabilityIndex % 10,4 + durabilityIndex / 10), slotX - 19f, slotY - 21f)
|
||||
}
|
||||
else if (item.stackable) {
|
||||
val amountString = qs!!.qty.toItemCountText()
|
||||
batch.color = Color(0xfff066_ff.toInt())
|
||||
val textLen = amountString.length * App.fontSmallNumbers.W
|
||||
val y = slotY + 23 - App.fontSmallNumbers.H
|
||||
val x = slotX - 19 + (38 - textLen) / 2
|
||||
App.fontSmallNumbers.draw(batch, amountString, x.toFloat(), y.toFloat())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user