at least some of the new UIs are working

This commit is contained in:
minjaesong
2017-10-23 03:44:45 +09:00
parent 98a67c80c6
commit 77b563396e
26 changed files with 848 additions and 57 deletions

View File

@@ -1,14 +1,13 @@
package net.torvald.terrarum
import com.badlogic.gdx.Input
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.g2d.TextureRegion
import net.torvald.colourutil.CIELabUtil.darkerLab
import net.torvald.terrarum.itemproperties.GameItem
import net.torvald.terrarum.ui.UIInventory
import net.torvald.terrarum.ui.UIItem
import net.torvald.terrarum.ui.UIItemTextButton
import net.torvald.terrarum.ui.*
/***
* Note that the UI will not render if either item or itemImage is null.
@@ -16,27 +15,31 @@ import net.torvald.terrarum.ui.UIItemTextButton
* Created by minjaesong on 2017-03-16.
*/
class UIItemInventoryElem(
parentUI: UIInventory,
parentUI: UIInventoryFull,
override var posX: Int,
override var posY: Int,
override val width: Int,
var item: GameItem?,
var amount: Int,
var itemImage: TextureRegion?,
override var item: GameItem?,
override var amount: Int,
override var itemImage: TextureRegion?,
val mouseOverTextCol: Color = Color(0xfff066_ff.toInt()),
val mouseoverBackCol: Color = Color(0),
val mouseoverBackBlendMode: String = BlendMode.NORMAL,
val inactiveTextCol: Color = UIItemTextButton.defaultInactiveCol,
val backCol: Color = Color(0),
val backBlendMode: String = BlendMode.NORMAL,
var quickslot: Int? = null,
var equippedSlot: Int? = null,
override var quickslot: Int? = null,
override var equippedSlot: Int? = null,
val drawBackOnNull: Boolean = true
) : UIItem(parentUI) {
) : UIItemInventoryCellBase(parentUI, posX, posY, item, amount, itemImage, quickslot, equippedSlot) {
companion object {
val height = 48
val UNIQUE_ITEM_HAS_NO_AMOUNT = -1
internal val durabilityCol = Color(0x22ff11_ff)
internal val durabilityBack: Color; get() = durabilityCol.darkerLab(0.4f)
internal val durabilityBarThickness = 3f
}
private val inventoryUI = parentUI
@@ -49,8 +52,7 @@ class UIItemInventoryElem(
private val textOffsetY = 8f
private val durabilityCol = Color(0x22ff11_ff)
private val durabilityBack: Color; get() = durabilityCol.darkerLab(0.4f)
private val durabilityBarOffY = 35f
@@ -63,7 +65,7 @@ class UIItemInventoryElem(
private val fwsp = 0x3000.toChar()
override fun render(batch: SpriteBatch) {
override fun render(batch: SpriteBatch, camera: Camera) {
// mouseover background
if (item != null || drawBackOnNull) {
@@ -91,6 +93,7 @@ class UIItemInventoryElem(
// if mouse is over, text lights up
// this one-liner sets color
batch.color = item!!.nameColour mul if (mouseUp) mouseOverTextCol else inactiveTextCol
// draw name of the item
Terrarum.fontGame.draw(batch,
//"$item" + (if (amount > 0 && item!!.stackable) "$fwsp($amount)" else if (amount != 1) "$fwsp!!$amount!!" else "") +
item!!.name + (if (amount > 0 && item!!.stackable) "$fwsp($amount)" else if (amount != 1) "$fwsp!!$amount!!" else "") +
@@ -105,9 +108,9 @@ class UIItemInventoryElem(
val barOffset = posX + textOffsetX
if (item!!.maxDurability > 0.0) {
batch.color = durabilityBack
batch.drawStraightLine(barOffset, posY + durabilityBarOffY, barOffset + barFullLen, 3f, false)
batch.drawStraightLine(barOffset, posY + durabilityBarOffY, barOffset + barFullLen, durabilityBarThickness, false)
batch.color = durabilityCol
batch.drawStraightLine(barOffset, posY + durabilityBarOffY, barOffset + barFullLen * (item!!.durability / item!!.maxDurability), 3f, false)
batch.drawStraightLine(barOffset, posY + durabilityBarOffY, barOffset + barFullLen * (item!!.durability / item!!.maxDurability), durabilityBarThickness, false)
}
@@ -134,7 +137,7 @@ class UIItemInventoryElem(
val currentSlotItem = inventory?.getQuickBar(slot)
inventory?.setQuickBar(
inventory.setQuickBar(
slot,
if (currentSlotItem?.item != item)
item?.dynamicID // register
@@ -145,8 +148,8 @@ class UIItemInventoryElem(
// search for duplicates in the quickbar, except mine
// if there is, unregister the other
(0..9).minus(slot).forEach {
if (inventory?.getQuickBar(it)?.item == item) {
inventory?.setQuickBar(it, null)
if (inventory.getQuickBar(it)?.item == item) {
inventory.setQuickBar(it, null)
}
}
}
@@ -161,7 +164,7 @@ class UIItemInventoryElem(
val itemEquipSlot = item!!.equipPosition
val player = Terrarum.ingame!!.player
if (item != player.inventory?.itemEquipped?.get(itemEquipSlot)) { // if this item is unequipped, equip it
if (item != player.inventory.itemEquipped.get(itemEquipSlot)) { // if this item is unequipped, equip it
player.equipItem(item!!)
}
else { // if not, unequip it