Inventory UI on ingame

This commit is contained in:
Song Minjae
2017-04-09 03:35:18 +09:00
parent c5367f8f1c
commit 671048e1e1
20 changed files with 245 additions and 267 deletions

View File

@@ -55,11 +55,11 @@ interface UICanvas {
const val OPENCLOSE_GENERIC = 200
fun doOpeningFade(handler: UIHandler?, openCloseTime: Int) {
handler!!.opacity = handler!!.openCloseCounter.toFloat() / openCloseTime
handler!!.opacity = handler.openCloseCounter.toFloat() / openCloseTime
}
fun doClosingFade(handler: UIHandler?, openCloseTime: Int) {
handler!!.opacity = (openCloseTime - handler!!.openCloseCounter.toFloat()) / openCloseTime
handler!!.opacity = (openCloseTime - handler.openCloseCounter.toFloat()) / openCloseTime
}
fun endOpeningFade(handler: UIHandler?) {

View File

@@ -3,6 +3,7 @@ package net.torvald.terrarum.ui
import net.torvald.terrarum.mapdrawer.TilesDrawer
import net.torvald.terrarum.Terrarum
import com.jme3.math.FastMath
import net.torvald.terrarum.gamecontroller.KeyToggler
import org.lwjgl.opengl.GL11
import org.newdawn.slick.*
import org.newdawn.slick.state.StateBasedGame
@@ -16,7 +17,9 @@ import org.newdawn.slick.state.StateBasedGame
*
* Created by minjaesong on 15-12-31.
*/
class UIHandler(val UI: UICanvas) {
class UIHandler(val UI: UICanvas,
val toggleKey: Int? = null, val toggleButton: Int? = null
) {
// X/Y Position to the game window.
var posX: Int = 0
@@ -62,6 +65,18 @@ class UIHandler(val UI: UICanvas) {
fun update(gc: GameContainer, delta: Int) {
// open/close UI by key pressed
if (toggleKey != null) {
if (KeyToggler.isOn(toggleKey)) {
setAsOpen()
}
else {
setAsClose()
}
}
if (isVisible || alwaysVisible) {
UI.update(gc, delta)
}

View File

@@ -11,18 +11,18 @@ import java.util.*
* Created by SKYHi14 on 2017-03-13.
*/
class UIInventory(
val actor: Pocketed,
var actor: Pocketed?,
override var width: Int,
override var height: Int
) : UICanvas {
val inventory: ActorInventory
get() = actor.inventory
val inventory: ActorInventory?
get() = actor?.inventory
val actorValue: ActorValue
get() = (actor as Actor).actorValue
override var handler: UIHandler? = null
override var openCloseTime: Int = UICanvas.OPENCLOSE_GENERIC
override var openCloseTime: Int = 120
val itemImagePlaceholder = Image("./assets/item_kari_24.tga")
@@ -104,68 +104,68 @@ class UIInventory(
private var oldCatSelect = -1
override fun update(gc: GameContainer, delta: Int) {
Terrarum.gameLocale = "koKR" // hot swap this to test
catButtons.update(gc, delta)
// monitor and check if category selection has been changed
if (oldCatSelect != catButtons.selectedIndex) {
rebuildList = true
}
if (rebuildList) {
val filter = catButtonsToCatIdent[catButtons.selectedButton.labelText]
inventorySortList = ArrayList<InventoryPair>()
// filter items
inventory.forEach {
if (it.item.category == filter || filter == "__all__")
inventorySortList.add(it)
if (actor != null && inventory != null) {
// monitor and check if category selection has been changed
if (oldCatSelect != catButtons.selectedIndex) {
rebuildList = true
}
rebuildList = false
// sort if needed
// test sort by name
inventorySortList.sortBy { it.item.name }
if (rebuildList) {
val filter = catButtonsToCatIdent[catButtons.selectedButton.labelText]
// map sortList to item list
for (k in 0..items.size - 1) {
try {
val sortListItem = inventorySortList[k + itemsScrollOffset]
items[k].item = sortListItem.item
items[k].amount = sortListItem.amount
items[k].itemImage = itemImagePlaceholder
inventorySortList = ArrayList<InventoryPair>()
// set quickslot number
for (qs in 1..QUICKSLOT_MAX) {
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
}
// filter items
inventory?.forEach {
if (it.item.category == filter || filter == "__all__")
inventorySortList.add(it)
}
for (eq in 0..actor.itemEquipped.size - 1) {
if (eq < actor.itemEquipped.size) {
if (actor.itemEquipped[eq] == items[k].item) {
items[k].equippedSlot = eq
rebuildList = false
// sort if needed
// test sort by name
inventorySortList.sortBy { it.item.name }
// map sortList to item list
for (k in 0..items.size - 1) {
try {
val sortListItem = inventorySortList[k + itemsScrollOffset]
items[k].item = sortListItem.item
items[k].amount = sortListItem.amount
items[k].itemImage = itemImagePlaceholder
// set quickslot number
for (qs in 1..QUICKSLOT_MAX) {
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].equippedSlot = null
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
items[k].amount = 0
items[k].itemImage = null
items[k].quickslot = null
catch (e: IndexOutOfBoundsException) {
items[k].item = null
items[k].amount = 0
items[k].itemImage = null
items[k].quickslot = null
}
}
}
}
@@ -190,18 +190,26 @@ class UIInventory(
}
override fun doOpening(gc: GameContainer, delta: Int) {
UICanvas.doOpeningFade(handler, openCloseTime)
handler!!.posX = Movement.fastPullOut(
handler!!.openCloseCounter.toFloat() / openCloseTime,
-width.toFloat(),
0f
).roundInt()
}
override fun doClosing(gc: GameContainer, delta: Int) {
UICanvas.doClosingFade(handler, openCloseTime)
handler!!.posX = Movement.fastPullOut(
handler!!.openCloseCounter.toFloat() / openCloseTime,
0f,
-width.toFloat()
).roundInt()
}
override fun endOpening(gc: GameContainer, delta: Int) {
UICanvas.endOpeningFade(handler)
handler!!.posX = 0
}
override fun endClosing(gc: GameContainer, delta: Int) {
UICanvas.endClosingFade(handler)
handler!!.posX = -width
}
}

View File

@@ -13,7 +13,7 @@ import org.newdawn.slick.Input
class UIQuickBar : UICanvas, MouseControlled {
private val gutter = 8
override var width: Int = (ItemSlotImageBuilder.slotImageSize + gutter) * SLOT_COUNT
override var height: Int = ItemSlotImageBuilder.slotImageSize + 4 + Terrarum.fontGame!!.lineHeight
override var height: Int = ItemSlotImageBuilder.slotImageSize + 4 + Terrarum.fontGame.lineHeight
/**
* In milliseconds
*/
@@ -84,7 +84,7 @@ class UIQuickBar : UICanvas, MouseControlled {
}
override fun mouseWheelMoved(change: Int) {
selection = selection.plus(if (change > 1) 1 else if (change < -1) -1 else 0).mod(SLOT_COUNT)
selection = selection.plus(if (change > 1) 1 else if (change < -1) -1 else 0).rem(SLOT_COUNT)
if (selection < 0) selection += SLOT_COUNT
}

View File

@@ -14,7 +14,7 @@ import org.newdawn.slick.Input
* Created by SKYHi14 on 2017-03-03.
*/
class UIVitalMetre(
var player: ActorHumanoid,
var player: ActorHumanoid?,
var vitalGetterVal: () -> Float?,
var vitalGetterMax: () -> Float?,
var color: Color?,
@@ -25,13 +25,13 @@ class UIVitalMetre(
private val gap = 4f
override var width: Int = 80 + 2 * margin; set(value) { throw Error("operation not permitted") }
override var height: Int; get() = player.baseHitboxH * 3 + margin; set(value) { throw Error("operation not permitted") }
override var height: Int; get() = player?.baseHitboxH ?: 0 * 3 + margin; set(value) { throw Error("operation not permitted") }
override var handler: UIHandler? = null
override var openCloseTime: Int = 50
private val relativePX = width / 2f
private val relativePY: Float; get() = player.baseHitboxH * 1.5f
private val circleRadius: Float; get() = player.baseHitboxH * 3f
private val relativePY: Float; get() = (player?.baseHitboxH ?: 0) * 1.5f
private val circleRadius: Float; get() = (player?.baseHitboxH ?: 0) * 3f
private val theta = 33f
private val halfTheta = theta / 2f