From df824ebedae90d492781927988d3dffc4b97a0e5 Mon Sep 17 00:00:00 2001 From: Song Minjae Date: Fri, 31 Mar 2017 17:26:44 +0900 Subject: [PATCH] inventory now shows equipped position Former-commit-id: 10950ffc409accfa914b9f531193b2fac0783f7d --- src/net/torvald/terrarum/Terrarum.kt | 45 +++++++++---------- .../torvald/terrarum/UIItemInventoryElem.kt | 3 +- .../terrarum/gameitem/InventoryItem.kt | 15 ++++++- src/net/torvald/terrarum/ui/UIInventory.kt | 13 +++++- 4 files changed, 50 insertions(+), 26 deletions(-) diff --git a/src/net/torvald/terrarum/Terrarum.kt b/src/net/torvald/terrarum/Terrarum.kt index 1b23ef1c2..38de3b0d1 100644 --- a/src/net/torvald/terrarum/Terrarum.kt +++ b/src/net/torvald/terrarum/Terrarum.kt @@ -36,6 +36,17 @@ object Terrarum : StateBasedGame(GAME_NAME) { ////////////////////////////// // GLOBAL IMMUTABLE CONFIGS // ////////////////////////////// + var WIDTH = 1072 + var HEIGHT = 742 // IMAX ratio + + var VSYNC = true + val VSYNC_TRIGGER_THRESHOLD = 56 + + val HALFW: Int + get() = WIDTH.ushr(1) + val HALFH: Int + get() = HEIGHT.ushr(1) + val QUICKSLOT_MAX = 10 /** @@ -67,15 +78,6 @@ object Terrarum : StateBasedGame(GAME_NAME) { lateinit var appgc: AppGameContainer - var WIDTH = 1072 - var HEIGHT = 742 // IMAX ratio - var VSYNC = true - val VSYNC_TRIGGER_THRESHOLD = 56 - val HALFW: Int - get() = WIDTH.ushr(1) - val HALFH: Int - get() = HEIGHT.ushr(1) - var gameStarted = false var ingame: StateInGame? = null @@ -102,33 +104,28 @@ object Terrarum : StateBasedGame(GAME_NAME) { val environment: RunningEnvironment private val localeSimple = arrayOf("de", "en", "es", "it") - var gameLocale = "####" // lateinit placeholder + var gameLocale = "lateinit" set(value) { if (localeSimple.contains(value.substring(0..1))) field = value.substring(0..1) else field = value - if (fontGame != null) (fontGame as GameFontImpl).reload() + (fontGame as GameFontImpl).reload() } - var fontGame: Font = object : Font { + private val nullFont = object : Font { override fun getHeight(str: String?) = 0 override fun drawString(x: Float, y: Float, text: String?) {} override fun drawString(x: Float, y: Float, text: String?, col: Color?) {} override fun drawString(x: Float, y: Float, text: String?, col: Color?, startIndex: Int, endIndex: Int) {} override fun getWidth(str: String?) = 0 override fun getLineHeight() = 0 - } // null font + } + + var fontGame: Font = nullFont private set - var fontSmallNumbers: Font = object : Font { - override fun getHeight(str: String?) = 0 - override fun drawString(x: Float, y: Float, text: String?) {} - override fun drawString(x: Float, y: Float, text: String?, col: Color?) {} - override fun drawString(x: Float, y: Float, text: String?, col: Color?, startIndex: Int, endIndex: Int) {} - override fun getWidth(str: String?) = 0 - override fun getLineHeight() = 0 - } // null font + var fontSmallNumbers: Font = nullFont private set var joypadLabelStart: Char = 0xE000.toChar() // lateinit @@ -306,7 +303,7 @@ object Terrarum : StateBasedGame(GAME_NAME) { gc.graphics.clear() // clean up any 'dust' in the buffer - //addState(StateVTTest()) + addState(StateVTTest()) //addState(StateGraphicComputerTest()) //addState(StateTestingLightning()) //addState(StateSplash()) @@ -316,7 +313,7 @@ object Terrarum : StateBasedGame(GAME_NAME) { //addState(StateBlurTest()) //addState(StateShaderTest()) //addState(StateNoiseTester()) - addState(StateUITest()) + //addState(StateUITest()) //addState(StateControllerRumbleTest()) //addState(StateMidiInputTest()) //addState(StateNewRunesTest()) @@ -652,3 +649,5 @@ operator fun Color.minus(other: Color) = Color( this.b - other.b, this.a - other.a ) + +fun Int.toHex() = Integer.toHexString(this) diff --git a/src/net/torvald/terrarum/UIItemInventoryElem.kt b/src/net/torvald/terrarum/UIItemInventoryElem.kt index ad41c26a3..36453ef0c 100644 --- a/src/net/torvald/terrarum/UIItemInventoryElem.kt +++ b/src/net/torvald/terrarum/UIItemInventoryElem.kt @@ -83,7 +83,8 @@ class UIItemInventoryElem( // if mouse is over, text lights up g.color = item!!.nameColour * if (mouseUp) mouseOverTextCol else UIItemTextButton.defaultInactiveCol g.drawString( - item!!.name + (if (amount > 0 && !item!!.isUnique) "${0x3000.toChar()}($amount)" else "") + item!!.name + (if (amount > 0 && !item!!.isUnique) "${0x3000.toChar()}($amount)" else "") + + (if (equippedSlot != null) " " else "") , posX + textOffsetX , posY + textOffsetY ) diff --git a/src/net/torvald/terrarum/gameitem/InventoryItem.kt b/src/net/torvald/terrarum/gameitem/InventoryItem.kt index 1ff7d0267..25e1a9ff8 100644 --- a/src/net/torvald/terrarum/gameitem/InventoryItem.kt +++ b/src/net/torvald/terrarum/gameitem/InventoryItem.kt @@ -1,6 +1,7 @@ package net.torvald.terrarum.gameitem import net.torvald.terrarum.ItemValue +import net.torvald.terrarum.gameactors.Pocketed import net.torvald.terrarum.itemproperties.Material import net.torvald.terrarum.langpack.Lang import org.newdawn.slick.Color @@ -91,7 +92,8 @@ abstract class InventoryItem : Comparable { * Set to zero if durability not applicable */ open var maxDurability: Double = 0.0 - open var durability: Double = maxDurability + + open var durability: Double = 0.0 /** * Effects applied continuously while in pocket @@ -152,6 +154,17 @@ abstract class InventoryItem : Comparable { fun Int.sign(): Int = if (this > 0) 1 else if (this < 0) -1 else 0 + infix fun equipTo(actor: Pocketed) { + if (equipPosition == EquipPosition.NULL) + throw IllegalArgumentException("Item is not supposed to be equipped (equipPosition is NULL") + + if (!actor.inventory.hasItem(this.id)) { + actor.inventory.add(this) + } + + actor.itemEquipped[this.equipPosition] = this + } + object EquipPosition { const val NULL = -1 diff --git a/src/net/torvald/terrarum/ui/UIInventory.kt b/src/net/torvald/terrarum/ui/UIInventory.kt index 7ee5310fd..7cc8a7318 100644 --- a/src/net/torvald/terrarum/ui/UIInventory.kt +++ b/src/net/torvald/terrarum/ui/UIInventory.kt @@ -142,13 +142,24 @@ class UIInventory( // set quickslot number for (qs in 1..QUICKSLOT_MAX) { - if (sortListItem.item.id == actorValue.getAsInt(AVKey.__PLAYER_QSPREFIX + qs)) { + if (-sortListItem.item.id == actorValue.getAsInt(AVKey.__PLAYER_QSPREFIX + qs)) { items[k].quickslot = qs % 10 // 10 -> 0, 1..9 -> 1..9 break } else items[k].quickslot = null } + + for (eq in 0..actor.itemEquipped.size - 1) { + if (eq < actor.itemEquipped.size) { + if (actor.itemEquipped[eq] == items[k].item) { + items[k].equippedSlot = eq + break + } + else + items[k].equippedSlot = null + } + } } catch (e: IndexOutOfBoundsException) { items[k].item = null