inventory now shows equipped position

Former-commit-id: 10950ffc409accfa914b9f531193b2fac0783f7d
This commit is contained in:
Song Minjae
2017-03-31 17:26:44 +09:00
parent 84f91e6a7a
commit 5bfc5c3a38
4 changed files with 50 additions and 26 deletions

View File

@@ -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)

View File

@@ -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) " <eq $equippedSlot>" else "")
, posX + textOffsetX
, posY + textOffsetY
)

View File

@@ -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<InventoryItem> {
* 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<InventoryItem> {
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

View File

@@ -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