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

@@ -296,4 +296,5 @@ abstract class UICanvas(
LEFT, RIGHT, TOP, BOTTOM
}
}
}

View File

@@ -20,7 +20,7 @@ import java.util.*
/**
* Created by minjaesong on 2017-03-13.
*/
class UIInventory(
/*class UIInventory(
var actor: Pocketed?,
override var width: Int,
override var height: Int,
@@ -133,14 +133,16 @@ class UIInventory(
posX = categoryWidth,
posY = 0,//(height - controlHelpHeight - scrollImageButtonAtlas.tileH) / 2,
width = scrollImageButtonAtlas.tileW,
height = height - controlHelpHeight
height = height - controlHelpHeight,
highlightable = false
)
private val scrollRightButton = UIItemImageButton(this,
scrollImageButtonAtlas.get(1, 0),
posX = width - scrollImageButtonAtlas.tileW,
posY = 0,//(height - controlHelpHeight - scrollImageButtonAtlas.tileH) / 2,
width = scrollImageButtonAtlas.tileW,
height = height - controlHelpHeight
height = height - controlHelpHeight,
highlightable = false
)
var itemPage = 0
var itemPageCount = 1 // TODO total size of current category / items.size
@@ -240,14 +242,14 @@ class UIInventory(
batch.color = Color(0xcccccc_ff.toInt())
batch.fillRect(0f, 0f, catButtons.width.toFloat(), height.toFloat())
catButtons.render(batch)
catButtons.render(batch, camera)
// left/right page mover
scrollLeftButton.render(batch)
scrollRightButton.render(batch)
scrollLeftButton.render(batch, camera)
scrollRightButton.render(batch, camera)
items.forEach {
it.render(batch)
it.render(batch, camera)
}
// texts
@@ -322,7 +324,7 @@ class UIInventory(
inventorySortList.sortBy { it.item.name }
// map sortList to item list
for (k in 0..items.size - 1) {
for (k in 0 until items.size) {
// we have an item
try {
val sortListItem = inventorySortList[k + itemPage * items.size]
@@ -427,3 +429,4 @@ class UIInventory(
scrollImageButtonAtlas.dispose()
}
}
*/

View File

@@ -0,0 +1,164 @@
package net.torvald.terrarum.ui
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.RunningEnvironment
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.UIItemInventoryCatBar
import net.torvald.terrarum.gameactors.InventoryPair
import net.torvald.terrarum.gameactors.Pocketed
import net.torvald.terrarum.gameactors.Second
import net.torvald.terrarum.itemproperties.GameItem
import net.torvald.terrarum.langpack.Lang
import java.util.ArrayList
/**
* Created by minjaesong on 2017-10-21.
*/
class UIInventoryFull(
var actor: Pocketed?,
toggleKeyLiteral: Int? = null, toggleButtonLiteral: Int? = null,
// UI positions itself? (you must g.flush() yourself after the g.translate(Int, Int))
customPositioning: Boolean = false, // mainly used by vital meter
doNotWarnConstant: Boolean = false
) : UICanvas(toggleKeyLiteral, toggleButtonLiteral, customPositioning, doNotWarnConstant) {
override var width: Int = Terrarum.WIDTH
override var height: Int = Terrarum.HEIGHT
val internalWidth: Int = 630
val internalHeight: Int = 558 // grad_begin..grad_end..contents..grad_begin..grad_end
private val SP = "${0x3000.toChar()}${0x3000.toChar()}"
val listControlHelp: String
get() = if (Terrarum.environment == RunningEnvironment.PC)
"${0xe037.toChar()} ${Lang["GAME_ACTION_CLOSE"]}$SP" +
"${0xe006.toChar()} ${Lang["GAME_INVENTORY_USE"]}$SP" +
"${0xe011.toChar()}..${0xe010.toChar()} ${Lang["GAME_INVENTORY_REGISTER"]}$SP" +
"${0xe034.toChar()} ${Lang["GAME_INVENTORY_DROP"]}"
else
"${0xe069.toChar()} ${Lang["GAME_ACTION_CLOSE"]}$SP" +
"${Terrarum.joypadLabelNinY} ${Lang["GAME_INVENTORY_USE"]}$SP" +
"${0xe011.toChar()}${0xe010.toChar()} ${Lang["GAME_INVENTORY_REGISTER"]}$SP" +
"${Terrarum.joypadLabelNinA} ${Lang["GAME_INVENTORY_DROP"]}"
val controlHelpHeight = Terrarum.fontGame.lineHeight.toInt()
private var encumbrancePerc = 0f
private var isEncumbered = false
val catBarWidth = 328
val catBar = UIItemInventoryCatBar(
this,
(Terrarum.WIDTH - catBarWidth) / 2,
66 + (Terrarum.HEIGHT - internalHeight) / 2,
catBarWidth
)
val catSelection: Int
get() = catBar.selectedIndex
val catSelectedIcon: Int
get() = catBar.selectedIcon
override var openCloseTime: Second = 1f
private val itemList: UIItemInventoryDynamicList? =
if (actor != null) {
UIItemInventoryDynamicList(
this,
actor!!.inventory,
0 + (Terrarum.WIDTH - internalWidth) / 2,
109 + (Terrarum.HEIGHT - internalHeight) / 2
)
}
else null
init {
addItem(catBar)
itemList?.let {
addItem(it)
}
}
override fun updateUI(delta: Float) {
}
override fun renderUI(batch: SpriteBatch, camera: Camera) {
catBar.render(batch, camera)
itemList?.render(batch, camera)
}
fun rebuildList() {
itemList?.rebuild()
}
override fun dispose() {
catBar.dispose()
itemList?.dispose()
}
override fun doOpening(delta: Float) {
}
override fun doClosing(delta: Float) {
}
override fun endOpening(delta: Float) {
}
override fun endClosing(delta: Float) {
}
override fun resize(width: Int, height: Int) {
super.resize(width, height)
}
override fun keyDown(keycode: Int): Boolean {
return super.keyDown(keycode)
}
override fun keyTyped(character: Char): Boolean {
return super.keyTyped(character)
}
override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
return super.touchDown(screenX, screenY, pointer, button)
}
override fun keyUp(keycode: Int): Boolean {
return super.keyUp(keycode)
}
override fun mouseMoved(screenX: Int, screenY: Int): Boolean {
return super.mouseMoved(screenX, screenY)
}
override fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean {
return super.touchDragged(screenX, screenY, pointer)
}
override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
return super.touchUp(screenX, screenY, pointer, button)
}
override fun scrolled(amount: Int): Boolean {
return super.scrolled(amount)
}
}

View File

@@ -1,6 +1,7 @@
package net.torvald.terrarum.ui
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.Terrarum
@@ -55,6 +56,9 @@ abstract class UIItem(var parentUI: UICanvas) { // do not replace parentUI to UI
get() = mouseUp && Gdx.input.isButtonPressed(Terrarum.getConfigInt("mouseprimary")!!)
/** UI to call (show up) while mouse is up */
open val mouseOverCall: UICanvas? = null
// kind of listener implementation
var updateListener: ((Float) -> Unit)? = null
@@ -76,9 +80,33 @@ abstract class UIItem(var parentUI: UICanvas) { // do not replace parentUI to UI
if (updateListener != null) {
updateListener!!.invoke(delta)
}
mouseOverCall?.update(delta)
if (mouseUp) {
if (mouseOverCall?.isVisible ?: false) {
mouseOverCall?.setAsOpen()
}
mouseOverCall?.updateUI(delta)
}
else {
if (mouseOverCall?.isVisible ?: false) {
mouseOverCall?.setAsClose()
}
}
}
}
open fun render(batch: SpriteBatch, camera: Camera) {
if (parentUI.isVisible) {
mouseOverCall?.render(batch, camera)
if (mouseUp) {
mouseOverCall?.renderUI(batch, camera)
}
}
}
abstract fun render(batch: SpriteBatch)
// keyboard controlled
open fun keyDown(keycode: Int): Boolean {

View File

@@ -1,5 +1,6 @@
package net.torvald.terrarum.ui
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
@@ -22,14 +23,21 @@ open class UIItemImageButton(
val activeBackCol: Color = Color(0xb0b0b0_ff.toInt()),
val activeBackBlendMode: String = BlendMode.MULTIPLY,
val highlightCol: Color = Color(0x00f8ff_ff),
val highlightBackCol: Color = Color(0xb0b0b0_ff.toInt()),
val highlightBackBlendMode: String = BlendMode.MULTIPLY,
override var posX: Int,
override var posY: Int,
override val width: Int = image.regionWidth,
override val height: Int = image.regionHeight
override val height: Int = image.regionHeight,
var highlightable: Boolean
) : UIItem(parent) {
var highlighted = false
override fun render(batch: SpriteBatch) {
override fun render(batch: SpriteBatch, camera: Camera) {
// draw background
if (mouseUp) {
BlendMode.resolve(activeBackBlendMode)
@@ -46,7 +54,10 @@ open class UIItemImageButton(
// draw image
blendNormal()
batch.color = if (mouseUp) activeCol else buttonCol
batch.color = if (highlighted) highlightCol
else if (mouseUp) activeCol
else buttonCol
batch.draw(image, (posX + (width - image.regionWidth) / 2).toFloat(), (posY + (height - image.regionHeight) / 2).toFloat())
}
@@ -71,6 +82,10 @@ open class UIItemImageButton(
}
override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
if (mouseUp) {
highlighted = !highlighted
}
return super.touchDown(screenX, screenY, pointer, button)
}

View File

@@ -1,5 +1,6 @@
package net.torvald.terrarum.ui
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Texture
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.gameactors.roundInt
@@ -22,7 +23,7 @@ class UIItemImageGallery(
override fun update(delta: Float) {
}
override fun render(batch: SpriteBatch) {
override fun render(batch: SpriteBatch, camera: Camera) {
fun column(i: Int) = i % column
fun row(i: Int) = i / column

View File

@@ -0,0 +1,25 @@
package net.torvald.terrarum.ui
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.g2d.TextureRegion
import net.torvald.terrarum.itemproperties.GameItem
/**
* Cross section of two inventory cell types
*
* Created by minjaesong on 2017-10-22.
*/
abstract class UIItemInventoryCellBase(
parentUI: UIInventoryFull,
override var posX: Int,
override var posY: Int,
open var item: GameItem?,
open var amount: Int,
open var itemImage: TextureRegion?,
open var quickslot: Int? = null,
open var equippedSlot: Int? = null
) : UIItem(parentUI) {
abstract override fun update(delta: Float)
abstract override fun render(batch: SpriteBatch, camera: Camera)
}

View File

@@ -0,0 +1,192 @@
package net.torvald.terrarum.ui
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.BlendMode
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.UIItemInventoryElem
import net.torvald.terrarum.UIItemInventoryElemSimple
import net.torvald.terrarum.console.Inventory
import net.torvald.terrarum.gameactors.ActorInventory
import net.torvald.terrarum.gameactors.InventoryPair
import net.torvald.terrarum.itemproperties.GameItem
import net.torvald.terrarum.itemproperties.ItemCodex
import java.util.ArrayList
/**
* Display either extended or compact list
*
* Note: everything is pretty much fixed size.
*
* Dimension of the whole area: 496x384
* Number of grids: 9x7
* Number of lists: 2x7
*
* Created by minjaesong on 2017-10-21.
*/
class UIItemInventoryDynamicList(
parentUI: UIInventoryFull,
val inventory: ActorInventory,
override var posX: Int,
override var posY: Int
) : UIItem(parentUI) {
override val width = 496
override val height = 384
val catIconsMeaning = listOf( // sortedBy: catArrangement
GameItem.Category.WEAPON,
GameItem.Category.TOOL,
GameItem.Category.ARMOUR,
GameItem.Category.GENERIC,
GameItem.Category.POTION,
GameItem.Category.MAGIC,
GameItem.Category.BLOCK,
GameItem.Category.WALL,
GameItem.Category.MISC,
"__all__"
)
private val inventoryUI = parentUI
private val selection: Int
get() = inventoryUI.catSelection
private val selectedIcon: Int
get() = inventoryUI.catSelectedIcon
private val compactViewCat = setOf(6, 7, 9) // blocks, walls, all (spritesheet order)
var itemPage = 0
var itemPageCount = 1 // TODO total size of current category / items.size
var inventorySortList = ArrayList<InventoryPair>()
private var rebuildList = true
val defaultTextColour = Color(0xeaeaea_ff.toInt())
private val listGap = 8
private val itemList = Array<UIItemInventoryCellBase>(
7 * 2, {
UIItemInventoryElem(
parentUI = inventoryUI,
posX = this.posX + (244 + listGap) * (it % 2),
posY = this.posY + (UIItemInventoryElem.height + listGap) * (it / 2),
width = 244,
item = null,
amount = UIItemInventoryElem.UNIQUE_ITEM_HAS_NO_AMOUNT,
itemImage = null,
mouseoverBackCol = Color(0x282828_ff),
mouseoverBackBlendMode = BlendMode.SCREEN,
backCol = Color(0xd4d4d4_ff.toInt()),
backBlendMode = BlendMode.MULTIPLY,
drawBackOnNull = true,
inactiveTextCol = defaultTextColour
) })
private val itemGrid = Array<UIItemInventoryCellBase>(
7 * 9, {
UIItemInventoryElemSimple(
parentUI = inventoryUI,
posX = this.posX + (UIItemInventoryElemSimple.height + listGap) * (it % 9),
posY = this.posY + (UIItemInventoryElemSimple.height + listGap) * (it / 9),
item = null,
amount = UIItemInventoryElem.UNIQUE_ITEM_HAS_NO_AMOUNT,
itemImage = null,
mouseoverBackCol = Color(0x282828_ff),
mouseoverBackBlendMode = BlendMode.SCREEN,
backCol = Color(0xd4d4d4_ff.toInt()),
backBlendMode = BlendMode.MULTIPLY,
drawBackOnNull = true,
inactiveTextCol = defaultTextColour
)
}
)
private val items: Array<UIItemInventoryCellBase>
get() = if (selection in compactViewCat) itemGrid else itemList
override fun render(batch: SpriteBatch, camera: Camera) {
items.forEach { it.render(batch, camera) }
super.render(batch, camera)
}
override fun update(delta: Float) {
super.update(delta)
items.forEach { it.update(delta) }
}
internal fun rebuild() {
val filter = catIconsMeaning[selectedIcon]
inventorySortList = ArrayList<InventoryPair>()
// filter items
inventory.forEach {
if (it.item.inventoryCategory == filter || filter == "__all__")
inventorySortList.add(it)
}
rebuildList = false
// sort if needed
// test sort by name
inventorySortList.sortBy { it.item.name }
// map sortList to item list
for (k in 0 until items.size) {
// we have an item
try {
val sortListItem = inventorySortList[k + itemPage * items.size]
items[k].item = sortListItem.item
items[k].amount = sortListItem.amount
items[k].itemImage = ItemCodex.getItemImage(sortListItem.item)
// set quickslot number
for (qs in 1..UIQuickBar.SLOT_COUNT) {
if (sortListItem.item == inventory.getQuickBar(qs - 1)?.item) {
items[k].quickslot = qs % 10 // 10 -> 0, 1..9 -> 1..9
break
}
else
items[k].quickslot = null
}
// set equippedslot number
for (eq in 0 until inventory.itemEquipped.size) {
if (eq < inventory.itemEquipped.size) {
if (inventory.itemEquipped[eq] == items[k].item) {
items[k].equippedSlot = eq
break
}
else
items[k].equippedSlot = null
}
}
}
// we do not have an item, empty the slot
catch (e: IndexOutOfBoundsException) {
items[k].item = null
items[k].amount = 0
items[k].itemImage = null
items[k].quickslot = null
}
}
}
override fun dispose() {
itemList.forEach { it.dispose() }
itemGrid.forEach { it.dispose() }
}
}

View File

@@ -1,5 +1,6 @@
package net.torvald.terrarum.ui
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.BlendMode
@@ -103,7 +104,7 @@ class UIItemList<Item: UIItem>(
}
}
override fun render(batch: SpriteBatch) {
override fun render(batch: SpriteBatch, camera: Camera) {
batch.color = backgroundCol
BlendMode.resolve(backgroundBlendMode)
batch.fillRect(posX.toFloat(), posY.toFloat(), width.toFloat(), height.toFloat())
@@ -114,7 +115,7 @@ class UIItemList<Item: UIItem>(
batch.fillRect(posX.toFloat(), highlightY!!.toFloat(), width.toFloat(), UIItemTextButton.height.toFloat())
}
itemList.forEach { it.render(batch) }
itemList.forEach { it.render(batch, camera) }
batch.color = backgroundCol
}

View File

@@ -1,5 +1,6 @@
package net.torvald.terrarum.ui
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.ModMgr
@@ -19,7 +20,7 @@ class UIItemModuleInfoCell(
private val numberAreaWidth = Terrarum.fontSmallNumbers.W * 3 + 4
override fun render(batch: SpriteBatch) {
override fun render(batch: SpriteBatch, camera: Camera) {
blendNormal()
if (ModMgr.moduleInfo.containsKey(moduleName)) {

View File

@@ -1,5 +1,6 @@
package net.torvald.terrarum.ui
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.Terrarum
@@ -38,7 +39,7 @@ class UIItemTextArea(
if (scrollPos < 0) scrollPos = 0
}
override fun render(batch: SpriteBatch) {
override fun render(batch: SpriteBatch, camera: Camera) {
for (i in scrollPos until minOf(lineCount + scrollPos, entireText.size)) {
val yPtr = i - scrollPos

View File

@@ -1,5 +1,6 @@
package net.torvald.terrarum.ui
import com.badlogic.gdx.graphics.Camera
import net.torvald.terrarum.*
import net.torvald.terrarum.langpack.Lang
import com.badlogic.gdx.graphics.Color
@@ -46,7 +47,7 @@ open class UIItemTextButton(
private val glyphLayout = GlyphLayout()
override fun render(batch: SpriteBatch) {
override fun render(batch: SpriteBatch, camera: Camera) {
val textW = font.getWidth(label)

View File

@@ -1,5 +1,6 @@
package net.torvald.terrarum.ui
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.glutils.ShapeRenderer
@@ -175,7 +176,7 @@ class UIItemTextButtonList(
}
}
override fun render(batch: SpriteBatch) {
override fun render(batch: SpriteBatch, camera: Camera) {
batch.color = backgroundCol
BlendMode.resolve(backgroundBlendMode)
@@ -187,7 +188,7 @@ class UIItemTextButtonList(
batch.fillRect(posX.toFloat(), highlightY!!.toFloat(), width.toFloat(), UIItemTextButton.height.toFloat())
}
buttons.forEach { it.render(batch) }
buttons.forEach { it.render(batch, camera) }
if (iconSpriteSheet != null) {

View File

@@ -89,10 +89,10 @@ class UITitleRemoConCredits(val superMenu: UICanvas) : UICanvas() {
}
override fun renderUI(batch: SpriteBatch, camera: Camera) {
menubar.render(batch)
menubar.render(batch, camera)
if (drawTextArea) {
batch.color = Color.WHITE
textArea.render(batch)
textArea.render(batch, camera)
}
}

View File

@@ -87,10 +87,10 @@ class UITitleRemoConLanguage(val superMenu: UICanvas) : UICanvas() {
}
override fun renderUI(batch: SpriteBatch, camera: Camera) {
menubar.render(batch)
menubar.render(batch, camera)
batch.color = Color.WHITE
textArea.render(batch)
textArea.render(batch, camera)
}
override fun doOpening(delta: Float) {

View File

@@ -96,11 +96,11 @@ class UITitleRemoConModules(val superMenu: UICanvas) : UICanvas() {
}
override fun renderUI(batch: SpriteBatch, camera: Camera) {
menubar.render(batch)
menubar.render(batch, camera)
batch.color = Color.WHITE
blendNormal()
mouduleArea.render(batch)
mouduleArea.render(batch, camera)
}
override fun doOpening(delta: Float) {

View File

@@ -110,7 +110,7 @@ class UITitleRemoConRoot : UICanvas() {
}
override fun renderUI(batch: SpriteBatch, camera: Camera) {
menubar.render(batch)
menubar.render(batch, camera)
}
override fun doOpening(delta: Float) {