inventory UI wip update

Two columns, some marginal spaces to make it look better


Former-commit-id: c26d11e499970280b78193772d29937295916ae2
This commit is contained in:
Song Minjae
2017-03-27 02:58:52 +09:00
parent 816502df3d
commit cd710de280
8 changed files with 171 additions and 47 deletions

View File

@@ -25,10 +25,10 @@ class StateUITest : BasicGameState() {
val inventory = ActorInventory()
init {
ui = UIHandler(SimpleUI(inventory))
ui = UIHandler(SimpleUI(inventory, 800, Terrarum.HEIGHT - 160))
ui.posX = 50
ui.posY = 30
ui.posX = 0
ui.posY = 60
ui.isVisible = true
@@ -83,9 +83,11 @@ class StateUITest : BasicGameState() {
private class SimpleUI(val inventory: ActorInventory) : UICanvas {
override var width = 700
override var height = 480 // multiple of 40 (2 * font.lineHeight)
private class SimpleUI(
val inventory: ActorInventory,
override var width: Int,
override var height: Int
) : UICanvas {
override var handler: UIHandler? = null
override var openCloseTime: Int = UICanvas.OPENCLOSE_GENERIC
@@ -93,6 +95,8 @@ private class SimpleUI(val inventory: ActorInventory) : UICanvas {
val catButtonsToCatIdent = HashMap<String, String>()
val backgroundColour = Color(0x1c1c1c)
init {
catButtonsToCatIdent.put("GAME_INVENTORY_WEAPONS", InventoryItem.Category.WEAPON)
catButtonsToCatIdent.put("CONTEXT_ITEM_TOOL_PLURAL", InventoryItem.Category.TOOL)
@@ -109,7 +113,11 @@ private class SimpleUI(val inventory: ActorInventory) : UICanvas {
}
val buttons = UIItemTextButtonList(
val itemStripGutterV = 6
val itemStripGutterH = 8
val itemInterColGutter = 8
val catButtons = UIItemTextButtonList(
this,
arrayOf(
"MENU_LABEL_ALL",
@@ -126,31 +134,35 @@ private class SimpleUI(val inventory: ActorInventory) : UICanvas {
),
width = (width / 3 / 100) * 100, // chop to hundreds unit (100, 200, 300, ...) with the black magic of integer division
height = height,
verticalGutter = itemStripGutterH,
readFromLang = true,
textAreaWidth = 100,
defaultSelection = 0,
iconSpriteSheet = SpriteSheet("./assets/graphics/gui/inventory/category.tga", 20, 20),
iconSpriteSheetIndices = intArrayOf(9,0,1,2,3,4,5,6,7,8),
highlightBackCol = Color(0x202020),
highlightBackCol = backgroundColour screen Color(0x0c0c0c),
highlightBackBlendMode = BlendMode.NORMAL,
backgroundCol = Color(0x383838),
kinematic = true
)
val itemStripGutterV = 10
val itemStripGutterH = 48
val itemsStripWidth = width - buttons.width - 2 * itemStripGutterH
val items = Array(height / (UIItemInventoryElem.height + itemStripGutterV), { UIItemInventoryElem(
parentUI = this,
posX = buttons.width + itemStripGutterH,
posY = it * (UIItemInventoryElem.height + itemStripGutterV),
width = itemsStripWidth,
item = null,
amount = UIItemInventoryElem.UNIQUE_ITEM_HAS_NO_AMOUNT,
itemImage = null,
backCol = Color(255, 255, 255, 0x30)
) })
val itemsStripWidth = ((width - catButtons.width) - (2 * itemStripGutterH + itemInterColGutter)) / 2
val items = Array(
2 + height / (UIItemInventoryElem.height + itemStripGutterV) * 2, {
UIItemInventoryElem(
parentUI = this,
posX = catButtons.width + if (it % 2 == 0) itemStripGutterH else (itemStripGutterH + itemsStripWidth + itemInterColGutter),
posY = itemStripGutterH + it / 2 * (UIItemInventoryElem.height + itemStripGutterV),
width = itemsStripWidth,
item = null,
amount = UIItemInventoryElem.UNIQUE_ITEM_HAS_NO_AMOUNT,
itemImage = null,
mouseoverBackCol = Color(0x282828),
mouseoverBackBlendMode = BlendMode.SCREEN,
drawBackOnNull = false
//backCol = Color(0x101010),
//backBlendMode = BlendMode.SCREEN
) })
val itemsScrollOffset = 0
var inventorySortList = ArrayList<InventoryPair>()
@@ -159,19 +171,19 @@ private class SimpleUI(val inventory: ActorInventory) : UICanvas {
private var oldCatSelect = -1
override fun update(gc: GameContainer, delta: Int) {
Terrarum.gameLocale = "fiFI" // hot swap this to test
Terrarum.gameLocale = "koKR" // hot swap this to test
buttons.update(gc, delta)
catButtons.update(gc, delta)
// monitor and check if category selection has been changed
if (oldCatSelect != buttons.selectedIndex) {
if (oldCatSelect != catButtons.selectedIndex) {
rebuildList = true
}
if (rebuildList) {
val filter = catButtonsToCatIdent[buttons.selectedButton.labelText]
val filter = catButtonsToCatIdent[catButtons.selectedButton.labelText]
inventorySortList = ArrayList<InventoryPair>()
@@ -207,14 +219,14 @@ private class SimpleUI(val inventory: ActorInventory) : UICanvas {
}
oldCatSelect = buttons.selectedIndex
oldCatSelect = catButtons.selectedIndex
}
override fun render(gc: GameContainer, g: Graphics) {
g.color = Color(0x202020)
g.color = backgroundColour
g.fillRect(0f, 0f, width.toFloat(), height.toFloat())
buttons.render(gc, g)
catButtons.render(gc, g)
items.forEach {
@@ -240,4 +252,4 @@ private class SimpleUI(val inventory: ActorInventory) : UICanvas {
override fun endClosing(gc: GameContainer, delta: Int) {
UICanvas.endClosingFade(handler)
}
}
}

View File

@@ -635,3 +635,10 @@ operator fun Color.times(other: Color) = Color(
this.b * other.b,
this.a * other.a
)
operator fun Color.minus(other: Color) = Color(
this.r - other.r,
this.g - other.g,
this.b - other.b,
this.a - other.a
)

View File

@@ -23,10 +23,13 @@ class UIItemInventoryElem(
var item: InventoryItem?,
var amount: Int,
var itemImage: Image?,
val mouseoverBackCol: Color = Color(0,0,0,0),
val mouseoverBackBlendMode: String = BlendMode.NORMAL,
val backCol: Color = Color(0,0,0,0),
val backColBlendMode: String = BlendMode.NORMAL,
val backBlendMode: String = BlendMode.NORMAL,
var quickslot: Int? = null,
var equippedSlot: Int? = null
var equippedSlot: Int? = null,
val drawBackOnNull: Boolean = true
) : UIItem(parentUI) {
companion object {
@@ -38,7 +41,7 @@ class UIItemInventoryElem(
private val imgOffset: Float
get() = (this.height - itemImage!!.height).div(2).toFloat() // to snap to the pixel grid
private val textOffsetX = 52f
private val textOffsetX = 50f
private val textOffsetY = 8f
@@ -55,17 +58,23 @@ class UIItemInventoryElem(
}
override fun render(gc: GameContainer, g: Graphics) {
if (item != null && itemImage != null) {
g.font = Terrarum.fontGame
g.font = Terrarum.fontGame
if (item != null || drawBackOnNull) {
if (mouseUp) {
BlendMode.resolve(backColBlendMode)
g.color = backCol
g.fillRect(posX.toFloat(), posY.toFloat(), width.toFloat(), height.toFloat())
BlendMode.resolve(mouseoverBackBlendMode)
g.color = mouseoverBackCol
}
else {
BlendMode.resolve(backBlendMode)
g.color = backCol
}
g.fillRect(posX.toFloat(), posY.toFloat(), width.toFloat(), height.toFloat())
}
if (item != null && itemImage != null) {
blendNormal()
g.drawImage(itemImage!!, posX + imgOffset, posY + imgOffset)
@@ -80,7 +89,7 @@ class UIItemInventoryElem(
// durability metre
val barFullLen = (width - 20f) - textOffsetX
val barFullLen = (width - 8f) - textOffsetX
val barOffset = posX + textOffsetX
if (item!!.maxDurability > 0.0) {
g.color = durabilityBack

View File

@@ -99,7 +99,7 @@ object TilePropCSV {
"15"; "2";"TILE_SANDSTONE_RED" ; "33587232"; "25";"1900";"rock"; "0"; "1"; "1"; "0"; "15"; "2"; "0"; "0"; "N/A"; "0";"16"
"15"; "3";"TILE_SANDSTONE_DESERT" ; "33587232"; "25";"1900";"rock"; "0"; "1"; "1"; "0"; "15"; "3"; "0"; "0"; "N/A"; "0";"16"
"15"; "4";"TILE_SANDSTONE_BLACK" ; "33587232"; "25";"1900";"rock"; "0"; "1"; "1"; "0"; "15"; "4"; "0"; "0"; "N/A"; "0";"16"
"15"; "5";"TILE_SANDSTONE_BLACK" ; "33587232"; "25";"1900";"rock"; "0"; "1"; "1"; "0"; "15"; "5"; "0"; "0"; "N/A"; "0";"16"
"15"; "5";"TILE_SANDSTONE_GREEN" ; "33587232"; "25";"1900";"rock"; "0"; "1"; "1"; "0"; "15"; "5"; "0"; "0"; "N/A"; "0";"16"
"16"; "0";"TILE_LANTERN_IRON_REGULAR"; "8396808"; "0"; "N/A";"fxtr"; "0"; "0"; "0"; "267553792"; "16"; "0"; "0"; "0"; "N/A"; "0";"16"
"16"; "1";"TILE_SUNSTONE" ; "33587232"; "0"; "N/A";"rock"; "0"; "1"; "0"; "0"; "16"; "1"; "0"; "2"; "N/A"; "0";"16"
"16"; "2";"TILE_DAYLIGHT_CAPACITOR" ; "33587232"; "0"; "N/A";"glas"; "0"; "1"; "0"; "0"; "16"; "2"; "0"; "3"; "N/A"; "0";"16"

View File

@@ -18,6 +18,7 @@ class UIItemTextButtonList(
labelsList: Array<String>,
override val width: Int,
override val height: Int,
val verticalGutter: Int = 0,
val readFromLang: Boolean = false,
val defaultSelection: Int = 0,
@@ -27,13 +28,13 @@ class UIItemTextButtonList(
val iconSpriteSheetIndices: IntArray? = null,
// copied directly from UIItemTextButton
val activeCol: Color = Color.white,
val activeCol: Color = Color(0xffffff),
val activeBackCol: Color = Color(0,0,0,0),
val activeBackBlendMode: String = BlendMode.NORMAL,
val highlightCol: Color = Color(0x00f8ff),
val highlightBackCol: Color = Color(0xb0b0b0),
val highlightBackBlendMode: String = BlendMode.MULTIPLY,
val inactiveCol: Color = Color(0xc8c8c8),
val inactiveCol: Color = Color(0xc0c0c0),
val backgroundCol: Color = Color(0,0,0,0),
val backgroundBlendMode: String = BlendMode.NORMAL,
val kinematic: Boolean = false // more "kinetic" movement of selector
@@ -54,7 +55,7 @@ class UIItemTextButtonList(
UIItemTextButton(
parentUI, s,
posX = 0,
posY = (height / labelsList.size.minus(1).toFloat() * index).roundInt(),
posY = verticalGutter + ((height - 2 * verticalGutter) / labelsList.size.minus(1).toFloat() * index).roundInt(),
width = width,
readFromLang = readFromLang,
activeCol = activeCol,
@@ -72,12 +73,16 @@ class UIItemTextButtonList(
UIItemTextButton(
parentUI, s,
posX = 0,
posY = (height / labelsList.size.minus(1).toFloat() * index).roundInt(),
posY = verticalGutter + ((height - 2 * verticalGutter) / labelsList.size.minus(1).toFloat() * index).roundInt(),
width = width,
readFromLang = readFromLang,
activeBackCol = Color(0,0,0,0),
activeBackBlendMode = BlendMode.NORMAL,
highlightBackCol = Color(0,0,0,0),
activeCol = activeCol,
activeBackCol = activeBackCol,
activeBackBlendMode = activeBackBlendMode,
highlightCol = highlightCol,
highlightBackCol = activeBackCol, // we are using custom highlighter
highlightBackBlendMode = activeBackBlendMode, // we are using custom highlighter
inactiveCol = inactiveCol,
preGapX = pregap,
postGapX = postgap
)
@@ -157,6 +162,8 @@ class UIItemTextButtonList(
}
}
g.color = backgroundCol
}
override fun keyPressed(key: Int, c: Char) {