mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-09 18:14:06 +09:00
still wip modularisation, game somehow boots
This commit is contained in:
35
src/net/torvald/terrarum/modulebasegame/ui/AmmoMeterProxy.kt
Normal file
35
src/net/torvald/terrarum/modulebasegame/ui/AmmoMeterProxy.kt
Normal file
@@ -0,0 +1,35 @@
|
||||
package net.torvald.terrarum.modulebasegame.ui
|
||||
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.ActorHumanoid
|
||||
import net.torvald.terrarum.itemproperties.GameItem
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2017-04-21.
|
||||
*/
|
||||
object AmmoMeterProxy {
|
||||
|
||||
operator fun invoke(actor: ActorHumanoid, meter: UIVitalMetre) {
|
||||
val currentItem = actor.inventory.itemEquipped[GameItem.EquipPosition.HAND_GRIP]
|
||||
|
||||
if (currentItem == null) {
|
||||
meter.vitalGetterMax = { null }
|
||||
meter.vitalGetterVal = { null }
|
||||
}
|
||||
else {
|
||||
meter.vitalGetterVal = {
|
||||
if (currentItem.stackable && currentItem.maxDurability == GameItem.DURABILITY_NA) {
|
||||
actor.inventory.getByDynamicID(currentItem.dynamicID)!!.amount.toFloat()
|
||||
}
|
||||
else
|
||||
currentItem.durability
|
||||
}
|
||||
|
||||
meter.vitalGetterMax = {
|
||||
if (currentItem.stackable && currentItem.maxDurability == GameItem.DURABILITY_NA)
|
||||
500f
|
||||
else
|
||||
currentItem.maxDurability.toFloat()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package net.torvald.terrarum.modulebasegame.ui
|
||||
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.Texture
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||
import net.torvald.terrarum.gameactors.ai.toInt
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
|
||||
|
||||
/**
|
||||
* Make item slot image with number on bottom-right
|
||||
*
|
||||
* Created by minjaesong on 2016-07-20.
|
||||
*/
|
||||
object ItemSlotImageBuilder {
|
||||
|
||||
// FIXME it leaks mem waaaaagh
|
||||
|
||||
val colourBlack = Color(0x404040_FF)
|
||||
val colourWhite = Color(0xC0C0C0_FF.toInt())
|
||||
|
||||
val slotImage = TextureRegionPack(Gdx.files.internal("./assets/graphics/gui/quickbar/item_slots_atlas.tga"), 38, 38) // must have same w/h as slotLarge
|
||||
|
||||
|
||||
private val imageDict = HashMap<Long, Texture>()
|
||||
|
||||
|
||||
fun produce(isBlack: Boolean, number: Int = 10): TextureRegion {
|
||||
return slotImage.get(number, 0 or isBlack.toInt().shl(1))
|
||||
}
|
||||
|
||||
fun produceLarge(isBlack: Boolean, number: Int = 10): TextureRegion {
|
||||
return slotImage.get(number, 1 or isBlack.toInt().shl(1))
|
||||
}
|
||||
|
||||
|
||||
fun dispose() {
|
||||
slotImage.dispose()
|
||||
}
|
||||
|
||||
}
|
||||
79
src/net/torvald/terrarum/modulebasegame/ui/MessageWindow.kt
Normal file
79
src/net/torvald/terrarum/modulebasegame/ui/MessageWindow.kt
Normal file
@@ -0,0 +1,79 @@
|
||||
package net.torvald.terrarum.modulebasegame.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
|
||||
import net.torvald.terrarum.blendNormal
|
||||
import net.torvald.terrarum.Second
|
||||
import net.torvald.terrarum.ui.UICanvas
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2016-01-27.
|
||||
*/
|
||||
class MessageWindow(override var width: Int, isBlackVariant: Boolean) : UICanvas() {
|
||||
|
||||
private val segment = if (isBlackVariant) SEGMENT_BLACK else SEGMENT_WHITE
|
||||
|
||||
var messagesList = arrayOf("", "")
|
||||
override var height: Int = 0
|
||||
|
||||
private var fontCol: Color = if (!isBlackVariant) Color.BLACK else Color.WHITE
|
||||
private val GLYPH_HEIGHT = Terrarum.fontGame.lineHeight
|
||||
|
||||
override var openCloseTime: Second = OPEN_CLOSE_TIME
|
||||
|
||||
private val LRmargin = 0f // there's "base value" of 8 px for LR (width of segment tile)
|
||||
|
||||
|
||||
fun setMessage(messagesList: Array<String>) {
|
||||
this.messagesList = messagesList
|
||||
}
|
||||
|
||||
override fun updateUI(delta: Float) {
|
||||
}
|
||||
|
||||
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
||||
blendNormal()
|
||||
|
||||
val textWidth = messagesList.map { Terrarum.fontGame.getWidth(it) }.sorted()[1]
|
||||
|
||||
batch.color = Color.WHITE
|
||||
|
||||
batch.draw(segment.get(1, 0), segment.tileW.toFloat(), 0f, 2 * LRmargin + textWidth, segment.tileH.toFloat())
|
||||
batch.draw(segment.get(0, 0), 0f, 0f)
|
||||
batch.draw(segment.get(2, 0), 2 * LRmargin + textWidth, 0f)
|
||||
|
||||
messagesList.forEachIndexed { index, s ->
|
||||
Terrarum.fontGame.draw(batch, s, segment.tileW + LRmargin, (segment.tileH - Terrarum.fontGame.lineHeight) / 2f)
|
||||
}
|
||||
}
|
||||
|
||||
override fun doOpening(delta: Float) {
|
||||
}
|
||||
|
||||
override fun doClosing(delta: Float) {
|
||||
}
|
||||
|
||||
override fun endOpening(delta: Float) {
|
||||
}
|
||||
|
||||
override fun endClosing(delta: Float) {
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
}
|
||||
|
||||
companion object {
|
||||
// private int messagesShowingIndex = 0;
|
||||
val MESSAGES_DISPLAY = 2
|
||||
val OPEN_CLOSE_TIME = 0.16f
|
||||
|
||||
|
||||
// will be disposed by Terrarum (application main instance)
|
||||
val SEGMENT_BLACK = TextureRegionPack("assets/graphics/gui/message_black.tga", 8, 56)
|
||||
val SEGMENT_WHITE = TextureRegionPack("assets/graphics/gui/message_white.tga", 8, 56)
|
||||
}
|
||||
}
|
||||
71
src/net/torvald/terrarum/modulebasegame/ui/Notification.kt
Normal file
71
src/net/torvald/terrarum/modulebasegame/ui/Notification.kt
Normal file
@@ -0,0 +1,71 @@
|
||||
package net.torvald.terrarum.modulebasegame.ui
|
||||
|
||||
import com.badlogic.gdx.graphics.Camera
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.Second
|
||||
import net.torvald.terrarum.ui.UICanvas
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2016-01-23.
|
||||
*/
|
||||
class Notification : UICanvas() {
|
||||
|
||||
private val SHOWUP_MAX = 15000
|
||||
|
||||
override var width: Int = 500
|
||||
|
||||
internal var msgUI = MessageWindow(width, true)
|
||||
|
||||
override var height: Int = msgUI.height
|
||||
private val visibleTime = Math.min(
|
||||
Terrarum.getConfigInt("notificationshowuptime"),
|
||||
SHOWUP_MAX
|
||||
)
|
||||
private var displayTimer = 0f
|
||||
|
||||
internal var message: Array<String> = Array(MessageWindow.MESSAGES_DISPLAY, { "" })
|
||||
|
||||
override var openCloseTime: Second = MessageWindow.OPEN_CLOSE_TIME
|
||||
|
||||
override fun updateUI(delta: Float) {
|
||||
if (handler.isOpened)
|
||||
displayTimer += delta
|
||||
|
||||
if (displayTimer >= visibleTime) {
|
||||
handler.setAsClose()
|
||||
displayTimer = 0f
|
||||
}
|
||||
}
|
||||
|
||||
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
||||
msgUI.render(batch, camera)
|
||||
}
|
||||
|
||||
override fun doOpening(delta: Float) {
|
||||
doOpeningFade(this, openCloseTime)
|
||||
}
|
||||
|
||||
override fun doClosing(delta: Float) {
|
||||
doClosingFade(this, openCloseTime)
|
||||
}
|
||||
|
||||
override fun endOpening(delta: Float) {
|
||||
endOpeningFade(this)
|
||||
}
|
||||
|
||||
override fun endClosing(delta: Float) {
|
||||
endClosingFade(this)
|
||||
}
|
||||
|
||||
fun sendNotification(message: Array<String>) {
|
||||
this.message = message
|
||||
msgUI.setMessage(this.message)
|
||||
handler.openCloseCounter = 0f
|
||||
handler.opacity = 0f
|
||||
handler.setAsOpen()
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
}
|
||||
}
|
||||
35
src/net/torvald/terrarum/modulebasegame/ui/NullUI.kt
Normal file
35
src/net/torvald/terrarum/modulebasegame/ui/NullUI.kt
Normal file
@@ -0,0 +1,35 @@
|
||||
package net.torvald.terrarum.modulebasegame.ui
|
||||
|
||||
import com.badlogic.gdx.graphics.Camera
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import net.torvald.terrarum.ui.UICanvas
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2017-03-13.
|
||||
*/
|
||||
class NullUI : UICanvas() {
|
||||
override var width: Int = 0
|
||||
override var height: Int = 0
|
||||
override var openCloseTime = 0f
|
||||
|
||||
override fun updateUI(delta: Float) {
|
||||
}
|
||||
|
||||
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
||||
}
|
||||
|
||||
override fun doOpening(delta: Float) {
|
||||
}
|
||||
|
||||
override fun doClosing(delta: Float) {
|
||||
}
|
||||
|
||||
override fun endOpening(delta: Float) {
|
||||
}
|
||||
|
||||
override fun endClosing(delta: Float) {
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
}
|
||||
}
|
||||
157
src/net/torvald/terrarum/modulebasegame/ui/UIBasicNotifier.kt
Normal file
157
src/net/torvald/terrarum/modulebasegame/ui/UIBasicNotifier.kt
Normal file
@@ -0,0 +1,157 @@
|
||||
package net.torvald.terrarum.modulebasegame.ui
|
||||
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.graphics.Camera
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.ActorHumanoid
|
||||
import net.torvald.terrarum.Second
|
||||
import net.torvald.terrarum.abs
|
||||
import net.torvald.terrarum.modulebasegame.Ingame
|
||||
import net.torvald.terrarum.roundInt
|
||||
import net.torvald.terrarum.modulebasegame.imagefont.Watch7SegSmall
|
||||
import net.torvald.terrarum.ui.UICanvas
|
||||
import net.torvald.terrarum.worlddrawer.LightmapRenderer
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2017-06-10.
|
||||
*/
|
||||
class UIBasicNotifier(private val player: ActorHumanoid?) : UICanvas() {
|
||||
override var width = 116
|
||||
override var height = 24
|
||||
override var openCloseTime: Second = 0f
|
||||
|
||||
private var ELuptimer = 10f // to make the light turned off by default
|
||||
private val ELuptime = 4f
|
||||
private var ELon = false
|
||||
|
||||
private var atlas = TextureRegionPack(ModMgr.getPath("basegame", "gui/basic_meter_atlas.tga"), width, height)
|
||||
|
||||
private var font = Watch7SegSmall
|
||||
|
||||
override fun updateUI(delta: Float) {
|
||||
if (ELon) {
|
||||
ELuptimer += delta
|
||||
}
|
||||
|
||||
if (mouseUp || Gdx.input.isKeyPressed(Terrarum.getConfigInt("keyinteract"))) {
|
||||
ELuptimer = 0f
|
||||
ELon = true
|
||||
}
|
||||
|
||||
if (ELuptimer >= ELuptime) {
|
||||
ELon = false
|
||||
}
|
||||
}
|
||||
|
||||
private val temperature: Int
|
||||
get() {
|
||||
if (player != null) {
|
||||
val playerTilePos = player.hIntTilewiseHitbox
|
||||
val tempCelsius = -273f + ((Terrarum.ingame as? Ingame)?.world?.getTemperature(playerTilePos.centeredX.toInt(), playerTilePos.centeredY.toInt()) ?: 288f)
|
||||
return if (Terrarum.getConfigBoolean("useamericanunit")) {
|
||||
tempCelsius.times(1.8f).plus(32f).roundInt()
|
||||
}
|
||||
else {
|
||||
tempCelsius.roundInt()
|
||||
}
|
||||
}
|
||||
else {
|
||||
return 888
|
||||
}
|
||||
}
|
||||
private val mailCount: Int
|
||||
get() = 0
|
||||
|
||||
private val lcdLitCol = Color(0x141414_ff)
|
||||
|
||||
fun getTempStr(): String {
|
||||
val sb = StringBuilder()
|
||||
|
||||
if (temperature < 100) {
|
||||
if (temperature < 0)
|
||||
sb.append("-")
|
||||
else
|
||||
sb.append(" ")
|
||||
|
||||
if (temperature.abs() < 10)
|
||||
sb.append(" ")
|
||||
}
|
||||
|
||||
sb.append(temperature.abs())
|
||||
|
||||
if (Terrarum.getConfigBoolean("useamericanunit")) {
|
||||
sb.append('#') // fahrenheit subscript
|
||||
}
|
||||
else {
|
||||
sb.append('"') // celsius superscript
|
||||
}
|
||||
|
||||
return sb.toString()
|
||||
}
|
||||
|
||||
fun getMailStr(): String {
|
||||
val sb = StringBuilder()
|
||||
|
||||
if (mailCount < 10)
|
||||
sb.append(" ")
|
||||
|
||||
sb.append(mailCount)
|
||||
|
||||
return sb.toString()
|
||||
}
|
||||
|
||||
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
||||
// light overlay or EL
|
||||
if (ELon) {
|
||||
blendNormal()
|
||||
batch.draw(atlas.get(0, 2), 0f, 0f)
|
||||
}
|
||||
else {
|
||||
val lightLevel: Color
|
||||
|
||||
if (player != null) {
|
||||
val playerPos = player.hIntTilewiseHitbox
|
||||
lightLevel = (LightmapRenderer.getLight(playerPos.centeredX.toInt(), playerPos.centeredY.toInt()) ?:
|
||||
(Terrarum.ingame!! as Ingame).world.globalLight
|
||||
)
|
||||
}
|
||||
else {
|
||||
lightLevel = (Terrarum.ingame!! as Ingame).world.globalLight
|
||||
}
|
||||
|
||||
|
||||
// backplate
|
||||
batch.color = Color(lightLevel.r, lightLevel.g, lightLevel.b, 1f)
|
||||
batch.draw(atlas.get(0, 0), 0f, 0f)
|
||||
}
|
||||
|
||||
// LCD back
|
||||
blendNormal()
|
||||
batch.draw(atlas.get(0, 3), 0f, 0f)
|
||||
|
||||
|
||||
// LCD contents
|
||||
batch.color = lcdLitCol
|
||||
font.draw(batch, getTempStr(), 21f, 5f)
|
||||
font.draw(batch, getMailStr(), 93f, 5f)
|
||||
}
|
||||
|
||||
override fun doOpening(delta: Float) {
|
||||
}
|
||||
|
||||
override fun doClosing(delta: Float) {
|
||||
}
|
||||
|
||||
override fun endOpening(delta: Float) {
|
||||
}
|
||||
|
||||
override fun endClosing(delta: Float) {
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
atlas.dispose()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package net.torvald.terrarum.modulebasegame.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
|
||||
import net.torvald.terrarum.fillRect
|
||||
import net.torvald.terrarum.Second
|
||||
import net.torvald.terrarum.langpack.Lang
|
||||
import net.torvald.terrarum.ui.UICanvas
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2017-12-06.
|
||||
*/
|
||||
class UICheatDetected : UICanvas() {
|
||||
|
||||
override var width: Int
|
||||
get() = Terrarum.WIDTH
|
||||
set(value) { throw UnsupportedOperationException() }
|
||||
|
||||
override var height: Int
|
||||
get() = Terrarum.HEIGHT
|
||||
set(value) { throw UnsupportedOperationException() }
|
||||
|
||||
override var openCloseTime: Second = 0f
|
||||
|
||||
|
||||
|
||||
private val backgroundCol = Color(0x181818C0)
|
||||
|
||||
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
||||
Terrarum.ingame?.consoleHandler?.setAsClose()
|
||||
Terrarum.ingame?.consoleHandler?.isVisible = false
|
||||
|
||||
batch.color = backgroundCol
|
||||
batch.fillRect(0f, 0f, width.toFloat(), height.toFloat())
|
||||
|
||||
batch.color = Color.WHITE
|
||||
val txt = Lang["ERROR_GENERIC_CHEATING"]
|
||||
val txtW = Terrarum.fontGame.getWidth(txt)
|
||||
val txtH = Terrarum.fontGame.lineHeight.toInt()
|
||||
|
||||
Terrarum.fontGame.draw(batch, txt, width.minus(txtW).ushr(1).toFloat(), height.minus(txtH).ushr(1).toFloat())
|
||||
}
|
||||
|
||||
override fun updateUI(delta: Float) {
|
||||
}
|
||||
|
||||
override fun doOpening(delta: Float) {
|
||||
}
|
||||
|
||||
override fun doClosing(delta: Float) {
|
||||
}
|
||||
|
||||
override fun endOpening(delta: Float) {
|
||||
}
|
||||
|
||||
override fun endClosing(delta: Float) {
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
}
|
||||
}
|
||||
415
src/net/torvald/terrarum/modulebasegame/ui/UIInventory.kt
Normal file
415
src/net/torvald/terrarum/modulebasegame/ui/UIInventory.kt
Normal file
@@ -0,0 +1,415 @@
|
||||
package net.torvald.terrarum.modulebasegame.ui
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2017-03-13.
|
||||
*/
|
||||
/*class UIInventory(
|
||||
var actor: Pocketed?,
|
||||
override var width: Int,
|
||||
override var height: Int,
|
||||
var categoryWidth: Int,
|
||||
|
||||
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) {
|
||||
|
||||
val inventory: ActorInventory?
|
||||
get() = actor?.inventory
|
||||
//val actorValue: ActorValue
|
||||
// get() = (actor as Actor).actorValue
|
||||
|
||||
override var openCloseTime: Second = 0.12f
|
||||
|
||||
val catButtonsToCatIdent = HashMap<String, String>()
|
||||
|
||||
val backgroundColour = Color(0x242424_80)
|
||||
val defaultTextColour = Color(0xeaeaea_ff.toInt())
|
||||
|
||||
init {
|
||||
catButtonsToCatIdent.put("GAME_INVENTORY_WEAPONS", GameItem.Category.WEAPON)
|
||||
catButtonsToCatIdent.put("CONTEXT_ITEM_TOOL_PLURAL", GameItem.Category.TOOL)
|
||||
catButtonsToCatIdent.put("CONTEXT_ITEM_ARMOR", GameItem.Category.ARMOUR)
|
||||
catButtonsToCatIdent.put("GAME_INVENTORY_INGREDIENTS", GameItem.Category.GENERIC)
|
||||
catButtonsToCatIdent.put("GAME_INVENTORY_POTIONS", GameItem.Category.POTION)
|
||||
catButtonsToCatIdent.put("CONTEXT_ITEM_MAGIC", GameItem.Category.MAGIC)
|
||||
catButtonsToCatIdent.put("GAME_INVENTORY_BLOCKS", GameItem.Category.BLOCK)
|
||||
catButtonsToCatIdent.put("GAME_INVENTORY_WALLS", GameItem.Category.WALL)
|
||||
catButtonsToCatIdent.put("GAME_GENRE_MISC", GameItem.Category.MISC)
|
||||
|
||||
// special filter
|
||||
catButtonsToCatIdent.put("MENU_LABEL_ALL", "__all__")
|
||||
|
||||
}
|
||||
|
||||
val itemStripGutterV = 6
|
||||
val itemStripGutterH = 8
|
||||
val itemInterColGutter = 8
|
||||
|
||||
val controlHelpHeight = Terrarum.fontGame.lineHeight.toInt()
|
||||
|
||||
val pageButtonExtraGap = 32
|
||||
|
||||
val pageButtonRealWidth = pageButtonExtraGap + itemStripGutterH
|
||||
|
||||
private val catButtons = UIItemTextButtonList(
|
||||
this,
|
||||
arrayOf(
|
||||
"MENU_LABEL_ALL",
|
||||
"GAME_INVENTORY_BLOCKS",
|
||||
"GAME_INVENTORY_WALLS",
|
||||
"CONTEXT_ITEM_TOOL_PLURAL",
|
||||
"GAME_INVENTORY_WEAPONS",
|
||||
"CONTEXT_ITEM_ARMOR",
|
||||
"GAME_INVENTORY_INGREDIENTS",
|
||||
"GAME_INVENTORY_POTIONS",
|
||||
"CONTEXT_ITEM_MAGIC",
|
||||
"GAME_GENRE_MISC"
|
||||
//"GAME_INVENTORY_FAVORITES",
|
||||
),
|
||||
posX = 0,
|
||||
posY = 0,
|
||||
width = categoryWidth,
|
||||
height = height - controlHelpHeight,
|
||||
verticalGutter = itemStripGutterH,
|
||||
readFromLang = true,
|
||||
textAreaWidth = 100,
|
||||
defaultSelection = 0,
|
||||
iconSpriteSheet = TextureRegionPack("./assets/graphics/gui/inventory/category.tga", 20, 20),
|
||||
iconSpriteSheetIndices = intArrayOf(9,6,7,1,0,2,3,4,5,8),
|
||||
iconCol = defaultTextColour,
|
||||
highlightBackCol = Color(0xb8b8b8_ff.toInt()),
|
||||
highlightBackBlendMode = BlendMode.MULTIPLY,
|
||||
backgroundCol = Color(0), // will use custom background colour!
|
||||
backgroundBlendMode = BlendMode.NORMAL,
|
||||
kinematic = true,
|
||||
inactiveCol = defaultTextColour
|
||||
)
|
||||
|
||||
val itemsStripWidth = ((width - catButtons.width) - (2 * itemStripGutterH + itemInterColGutter)) / 2 - pageButtonExtraGap
|
||||
private val items = Array(
|
||||
((height - controlHelpHeight) / (UIItemInventoryElem.height + itemStripGutterV)) * 2, {
|
||||
UIItemInventoryElem(
|
||||
parentUI = this,
|
||||
posX = pageButtonExtraGap + 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_ff),
|
||||
mouseoverBackBlendMode = BlendMode.SCREEN,
|
||||
backCol = Color(0xd4d4d4_ff.toInt()),
|
||||
backBlendMode = BlendMode.MULTIPLY,
|
||||
drawBackOnNull = true,
|
||||
inactiveTextCol = defaultTextColour
|
||||
) })
|
||||
|
||||
|
||||
private val scrollImageButtonAtlas = TextureRegionPack(
|
||||
Gdx.files.internal("assets/graphics/gui/inventory/page_arrow_button.tga"),
|
||||
40, 54
|
||||
)
|
||||
private val scrollLeftButton = UIItemImageButton(this,
|
||||
scrollImageButtonAtlas.get(0, 0),
|
||||
posX = categoryWidth,
|
||||
posY = 0,//(height - controlHelpHeight - scrollImageButtonAtlas.tileH) / 2,
|
||||
width = scrollImageButtonAtlas.tileW,
|
||||
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,
|
||||
highlightable = false
|
||||
)
|
||||
var itemPage = 0
|
||||
var itemPageCount = 1 // TODO total size of current category / items.size
|
||||
|
||||
|
||||
|
||||
var inventorySortList = ArrayList<InventoryPair>()
|
||||
private var rebuildList = true
|
||||
|
||||
private val SP = "${0x3000.toChar()}${0x3000.toChar()}"
|
||||
val listControlHelp: String
|
||||
get() = if (Terrarum.environment == RunningEnvironment.PC)
|
||||
"${0xe006.toChar()} ${Lang["GAME_INVENTORY_USE"]}$SP" +
|
||||
"${0xe011.toChar()}..${0xe010.toChar()} ${Lang["GAME_INVENTORY_REGISTER"]}$SP" +
|
||||
"${0xe034.toChar()} ${Lang["GAME_INVENTORY_DROP"]}"
|
||||
else
|
||||
"$joypadLabelNinY ${Lang["GAME_INVENTORY_USE"]}$SP" +
|
||||
"${0xe011.toChar()}${0xe010.toChar()} ${Lang["GAME_INVENTORY_REGISTER"]}$SP" +
|
||||
"$joypadLabelNinA ${Lang["GAME_INVENTORY_DROP"]}"
|
||||
val listControlClose: String
|
||||
get() = if (Terrarum.environment == RunningEnvironment.PC)
|
||||
"${0xe037.toChar()} ${Lang["GAME_ACTION_CLOSE"]}"
|
||||
else
|
||||
"${0xe069.toChar()} ${Lang["GAME_ACTION_CLOSE"]}"
|
||||
|
||||
private var oldCatSelect: Int? = null
|
||||
|
||||
private var encumbrancePerc = 0f
|
||||
private var isEncumbered = false
|
||||
|
||||
|
||||
private val seekLeft: Int; get() = Terrarum.getConfigInt("keyleft") // getter used to support in-game keybind changing
|
||||
private val seekRight: Int; get() = Terrarum.getConfigInt("keyright") // getter used to support in-game keybind changing
|
||||
private val seekUp: Int; get() = Terrarum.getConfigInt("keyup") // getter used to support in-game keybind changing
|
||||
private val seekDown: Int; get() = Terrarum.getConfigInt("keydown") // getter used to support in-game keybind changing
|
||||
|
||||
|
||||
init {
|
||||
// assign actions to the buttons
|
||||
scrollLeftButton.clickOnceListener = { mouseX, mouseY, button -> // click once action doesn't work ?!
|
||||
if (button == Input.Buttons.LEFT) {
|
||||
itemPage = (itemPage - 1) fmod itemPageCount
|
||||
}
|
||||
}
|
||||
scrollRightButton.clickOnceListener = { mouseX, mouseY, button ->
|
||||
if (button == Input.Buttons.LEFT) {
|
||||
itemPage = (itemPage + 1) fmod itemPageCount
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
addItem(scrollLeftButton)
|
||||
addItem(scrollRightButton)
|
||||
}
|
||||
|
||||
|
||||
override fun updateUI(delta: Float) {
|
||||
|
||||
catButtons.update(delta)
|
||||
|
||||
scrollLeftButton.update(delta)
|
||||
scrollRightButton.update(delta)
|
||||
|
||||
if (actor != null && inventory != null) {
|
||||
// monitor and check if category selection has been changed
|
||||
// OR UI is being opened from closed state
|
||||
if (oldCatSelect != catButtons.selectedIndex ||
|
||||
!rebuildList && handler.openFired) {
|
||||
rebuildList = true
|
||||
}
|
||||
|
||||
// reset item page to start
|
||||
if (oldCatSelect != catButtons.selectedIndex) {
|
||||
itemPage = 0
|
||||
}
|
||||
|
||||
if (rebuildList) {
|
||||
shutUpAndRebuild()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
oldCatSelect = catButtons.selectedIndex
|
||||
}
|
||||
|
||||
private val weightBarWidth = 60f
|
||||
|
||||
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
||||
// background
|
||||
blendNormal()
|
||||
batch.color = backgroundColour
|
||||
batch.fillRect(0f, 0f, width.toFloat(), height.toFloat())
|
||||
|
||||
|
||||
// cat bar background
|
||||
blendMul()
|
||||
batch.color = Color(0xcccccc_ff.toInt())
|
||||
batch.fillRect(0f, 0f, catButtons.width.toFloat(), height.toFloat())
|
||||
|
||||
catButtons.render(batch, camera)
|
||||
|
||||
// left/right page mover
|
||||
scrollLeftButton.render(batch, camera)
|
||||
scrollRightButton.render(batch, camera)
|
||||
|
||||
items.forEach {
|
||||
it.render(batch, camera)
|
||||
}
|
||||
|
||||
// texts
|
||||
blendNormal()
|
||||
batch.color = defaultTextColour
|
||||
// W - close
|
||||
Terrarum.fontGame.draw(batch, listControlClose, 4f, height - controlHelpHeight.toFloat())
|
||||
// MouseL - Use ; 1.9 - Register ; T - Drop
|
||||
Terrarum.fontGame.draw(batch, listControlHelp, catButtons.width + 4f, height - controlHelpHeight.toFloat())
|
||||
// encumbrance
|
||||
if (inventory != null) {
|
||||
val encumbranceText = Lang["GAME_INVENTORY_ENCUMBRANCE"]
|
||||
|
||||
Terrarum.fontGame.draw(batch,
|
||||
encumbranceText,
|
||||
width - 9 - Terrarum.fontGame.getWidth(encumbranceText) - weightBarWidth,
|
||||
height - controlHelpHeight.toFloat()
|
||||
)
|
||||
|
||||
// encumbrance bar background
|
||||
blendMul()
|
||||
batch.color = Color(0xa0a0a0_ff.toInt())
|
||||
batch.fillRect(
|
||||
width - 3 - weightBarWidth,
|
||||
height - controlHelpHeight + 3f,
|
||||
weightBarWidth,
|
||||
controlHelpHeight - 6f
|
||||
)
|
||||
// encumbrance bar
|
||||
blendNormal()
|
||||
batch.color = if (isEncumbered) Color(0xff0000_cc.toInt()) else Color(0x00ff00_cc.toInt())
|
||||
batch.fillRect(
|
||||
width - 3 - weightBarWidth,
|
||||
height - controlHelpHeight + 3f,
|
||||
if (actor?.inventory?.capacityMode == CAPACITY_MODE_NO_ENCUMBER)
|
||||
1f
|
||||
else // make sure 1px is always be seen
|
||||
minOf(weightBarWidth, maxOf(1f, weightBarWidth * encumbrancePerc)),
|
||||
controlHelpHeight - 5f
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/** Persuade the UI to rebuild its item list */
|
||||
fun rebuildList() {
|
||||
rebuildList = true
|
||||
}
|
||||
|
||||
|
||||
fun shutUpAndRebuild() {
|
||||
if (catButtons.selectedButton != null) {
|
||||
val filter = catButtonsToCatIdent[catButtons.selectedButton!!.labelText]
|
||||
|
||||
// encumbrance
|
||||
encumbrancePerc = inventory!!.capacity.toFloat() / inventory!!.maxCapacity
|
||||
isEncumbered = inventory!!.isEncumbered
|
||||
|
||||
|
||||
|
||||
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 == actor?.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..actor!!.inventory.itemEquipped.size - 1) {
|
||||
if (eq < actor!!.inventory.itemEquipped.size) {
|
||||
if (actor!!.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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
itemPageCount = maxOf(1, 1 + (inventorySortList.size.minus(1) / items.size))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////
|
||||
// Inputs //
|
||||
////////////
|
||||
|
||||
|
||||
override fun doOpening(delta: Float) {
|
||||
UICanvas.doOpeningPopOut(this, openCloseTime, UICanvas.Companion.Position.LEFT)
|
||||
}
|
||||
|
||||
override fun doClosing(delta: Float) {
|
||||
UICanvas.doClosingPopOut(this, openCloseTime, UICanvas.Companion.Position.LEFT)
|
||||
}
|
||||
|
||||
override fun endOpening(delta: Float) {
|
||||
UICanvas.endOpeningPopOut(this, UICanvas.Companion.Position.LEFT)
|
||||
}
|
||||
|
||||
override fun endClosing(delta: Float) {
|
||||
UICanvas.endClosingPopOut(this, UICanvas.Companion.Position.LEFT)
|
||||
}
|
||||
|
||||
override fun keyDown(keycode: Int): Boolean {
|
||||
super.keyDown(keycode)
|
||||
|
||||
items.forEach { if (it.mouseUp) it.keyDown(keycode) }
|
||||
shutUpAndRebuild()
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
override fun keyUp(keycode: Int): Boolean {
|
||||
super.keyUp(keycode)
|
||||
|
||||
items.forEach { if (it.mouseUp) it.keyUp(keycode) }
|
||||
shutUpAndRebuild()
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
|
||||
super.touchDown(screenX, screenY, pointer, button)
|
||||
|
||||
items.forEach { if (it.mouseUp) it.touchDown(screenX, screenY, pointer, button) }
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
|
||||
items.forEach { if (it.mouseUp) it.touchUp(screenX, screenY, pointer, button) }
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
catButtons.dispose()
|
||||
items.forEach { it.dispose() }
|
||||
scrollImageButtonAtlas.dispose()
|
||||
}
|
||||
}
|
||||
*/
|
||||
290
src/net/torvald/terrarum/modulebasegame/ui/UIInventoryFull.kt
Normal file
290
src/net/torvald/terrarum/modulebasegame/ui/UIInventoryFull.kt
Normal file
@@ -0,0 +1,290 @@
|
||||
package net.torvald.terrarum.modulebasegame.ui
|
||||
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.graphics.Camera
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.GL20
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.ActorWithPhysics
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.ActorInventory.Companion.CAPACITY_MODE_NO_ENCUMBER
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.Pocketed
|
||||
import net.torvald.terrarum.Second
|
||||
import net.torvald.terrarum.langpack.Lang
|
||||
import net.torvald.terrarum.modulebasegame.Ingame
|
||||
import net.torvald.terrarum.ui.UICanvas
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
||||
|
||||
|
||||
internal val catIcons: TextureRegionPack = TextureRegionPack("./assets/graphics/gui/inventory/category.tga", 20, 20)
|
||||
internal val catArrangement: IntArray = intArrayOf(9,6,7,1,0,2,3,4,5,8)
|
||||
|
||||
|
||||
|
||||
private val SP = "${0x3000.toChar()}${0x3000.toChar()}"
|
||||
val listControlHelp: String
|
||||
get() = if (Terrarum.environment == RunningEnvironment.PC)
|
||||
"${0xe031.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
|
||||
|
||||
private var encumbrancePerc = 0f
|
||||
private var isEncumbered = false
|
||||
|
||||
|
||||
val catBarWidth = 330
|
||||
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 = 0.0f
|
||||
|
||||
|
||||
private val itemList: UIItemInventoryDynamicList? =
|
||||
if (actor != null) {
|
||||
UIItemInventoryDynamicList(
|
||||
this,
|
||||
actor!!.inventory,
|
||||
0 + (Terrarum.WIDTH - internalWidth) / 2,
|
||||
109 + (Terrarum.HEIGHT - internalHeight) / 2
|
||||
)
|
||||
}
|
||||
else null
|
||||
|
||||
|
||||
private val equipped: UIItemInventoryEquippedView? =
|
||||
if (actor != null) {
|
||||
UIItemInventoryEquippedView(
|
||||
this,
|
||||
actor!!.inventory,
|
||||
actor as ActorWithPhysics,
|
||||
internalWidth - UIItemInventoryEquippedView.width + (Terrarum.WIDTH - internalWidth) / 2,
|
||||
109 + (Terrarum.HEIGHT - internalHeight) / 2
|
||||
)
|
||||
}
|
||||
else null
|
||||
|
||||
|
||||
|
||||
init {
|
||||
addItem(catBar)
|
||||
itemList?.let { addItem(it) }
|
||||
equipped?.let { addItem(it) }
|
||||
|
||||
|
||||
catBar.selectionChangeListener = { old, new -> rebuildList() }
|
||||
|
||||
|
||||
|
||||
rebuildList()
|
||||
|
||||
}
|
||||
|
||||
private var offsetX = ((Terrarum.WIDTH - internalWidth) / 2).toFloat()
|
||||
private var offsetY = ((Terrarum.HEIGHT - internalHeight) / 2).toFloat()
|
||||
|
||||
|
||||
|
||||
override fun updateUI(delta: Float) {
|
||||
if (handler.openFired) {
|
||||
rebuildList()
|
||||
}
|
||||
|
||||
|
||||
catBar.update(delta)
|
||||
itemList?.update(delta)
|
||||
equipped?.update(delta)
|
||||
}
|
||||
|
||||
private val gradStartCol = Color(0x404040_60)
|
||||
private val gradEndCol = Color(0x000000_70)
|
||||
private val shapeRenderer = ShapeRenderer()
|
||||
private val gradHeight = 48f
|
||||
|
||||
private val weightBarWidth = 60f
|
||||
|
||||
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
||||
val xEnd = (Terrarum.WIDTH + internalWidth).div(2).toFloat()
|
||||
val yEnd = (Terrarum.HEIGHT + internalHeight).div(2).toFloat()
|
||||
|
||||
|
||||
// background fill
|
||||
batch.end()
|
||||
Gdx.gl.glEnable(GL20.GL_BLEND) // ending the batch disables blend
|
||||
|
||||
val gradTopStart = (Terrarum.HEIGHT - internalHeight).div(2).toFloat()
|
||||
val gradBottomEnd = Terrarum.HEIGHT - gradTopStart
|
||||
|
||||
shapeRenderer.inUse {
|
||||
shapeRenderer.rect(0f, gradTopStart, Terrarum.WIDTH.toFloat(), gradHeight, gradStartCol, gradStartCol, gradEndCol, gradEndCol)
|
||||
shapeRenderer.rect(0f, gradBottomEnd, Terrarum.WIDTH.toFloat(), -gradHeight, gradStartCol, gradStartCol, gradEndCol, gradEndCol)
|
||||
|
||||
shapeRenderer.rect(0f, gradTopStart + gradHeight, Terrarum.WIDTH.toFloat(), internalHeight - (2 * gradHeight), gradEndCol, gradEndCol, gradEndCol, gradEndCol)
|
||||
|
||||
shapeRenderer.rect(0f, 0f, Terrarum.WIDTH.toFloat(), gradTopStart, gradStartCol, gradStartCol, gradStartCol, gradStartCol)
|
||||
shapeRenderer.rect(0f, Terrarum.HEIGHT.toFloat(), Terrarum.WIDTH.toFloat(), -(Terrarum.HEIGHT.toFloat() - gradBottomEnd), gradStartCol, gradStartCol, gradStartCol, gradStartCol)
|
||||
}
|
||||
|
||||
|
||||
batch.begin()
|
||||
|
||||
// UI items
|
||||
catBar.render(batch, camera)
|
||||
itemList?.render(batch, camera)
|
||||
equipped?.render(batch, camera)
|
||||
|
||||
|
||||
// control hints
|
||||
blendNormal(batch)
|
||||
batch.color = Color.WHITE
|
||||
Terrarum.fontGame.draw(batch, listControlHelp, offsetX, offsetY + internalHeight)
|
||||
|
||||
|
||||
// encumbrance meter
|
||||
if (actor != null) {
|
||||
val encumbranceText = Lang["GAME_INVENTORY_ENCUMBRANCE"]
|
||||
|
||||
Terrarum.fontGame.draw(batch,
|
||||
encumbranceText,
|
||||
xEnd - 9 - Terrarum.fontGame.getWidth(encumbranceText) - weightBarWidth,
|
||||
yEnd
|
||||
)
|
||||
|
||||
// encumbrance bar background
|
||||
blendMul()
|
||||
batch.color = Color(0xa0a0a0_ff.toInt())
|
||||
batch.fillRect(
|
||||
xEnd - 3 - weightBarWidth,
|
||||
yEnd + 3f,
|
||||
weightBarWidth,
|
||||
controlHelpHeight - 6f
|
||||
)
|
||||
// encumbrance bar
|
||||
blendNormal()
|
||||
batch.color = if (isEncumbered) Color(0xff0000_cc.toInt()) else Color(0x00ff00_cc.toInt())
|
||||
batch.fillRect(
|
||||
xEnd - 3 - weightBarWidth,
|
||||
yEnd + 3f,
|
||||
if (actor?.inventory?.capacityMode == CAPACITY_MODE_NO_ENCUMBER)
|
||||
1f
|
||||
else // make sure 1px is always be seen
|
||||
minOf(weightBarWidth, maxOf(1f, weightBarWidth * encumbrancePerc)),
|
||||
controlHelpHeight - 5f
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
fun rebuildList() {
|
||||
itemList?.rebuild()
|
||||
equipped?.rebuild()
|
||||
|
||||
actor?.let {
|
||||
encumbrancePerc = actor!!.inventory.capacity.toFloat() / actor!!.inventory.maxCapacity
|
||||
isEncumbered = actor!!.inventory.isEncumbered
|
||||
}
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
catBar.dispose()
|
||||
itemList?.dispose()
|
||||
equipped?.dispose()
|
||||
}
|
||||
|
||||
|
||||
|
||||
override fun doOpening(delta: Float) {
|
||||
(Terrarum.ingame as? Ingame)?.setTooltipMessage(null)
|
||||
}
|
||||
|
||||
override fun doClosing(delta: Float) {
|
||||
(Terrarum.ingame as? Ingame)?.setTooltipMessage(null)
|
||||
}
|
||||
|
||||
override fun endOpening(delta: Float) {
|
||||
}
|
||||
|
||||
override fun endClosing(delta: Float) {
|
||||
(Terrarum.ingame as? Ingame)?.setTooltipMessage(null) // required!!
|
||||
}
|
||||
|
||||
|
||||
|
||||
override fun resize(width: Int, height: Int) {
|
||||
super.resize(width, height)
|
||||
|
||||
offsetX = ((Terrarum.WIDTH - internalWidth) / 2).toFloat()
|
||||
offsetY = ((Terrarum.HEIGHT - internalHeight) / 2).toFloat()
|
||||
}
|
||||
|
||||
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package net.torvald.terrarum.modulebasegame.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
|
||||
import net.torvald.terrarum.ui.UIItem
|
||||
|
||||
/**
|
||||
* 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)
|
||||
}
|
||||
@@ -0,0 +1,370 @@
|
||||
package net.torvald.terrarum.modulebasegame.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.modulebasegame.gameactors.ActorInventory
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.InventoryPair
|
||||
import net.torvald.terrarum.ceilInt
|
||||
import net.torvald.terrarum.gameworld.fmod
|
||||
import net.torvald.terrarum.itemproperties.GameItem
|
||||
import net.torvald.terrarum.itemproperties.ItemCodex
|
||||
import net.torvald.terrarum.modulebasegame.Ingame
|
||||
import net.torvald.terrarum.ui.UIItem
|
||||
import net.torvald.terrarum.ui.UIItemImageButton
|
||||
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
|
||||
|
||||
private val catArrangement = parentUI.catArrangement
|
||||
|
||||
|
||||
|
||||
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(3, 4, 6, 7, 9) // ingredients, potions, blocks, walls, all (spritesheet order)
|
||||
|
||||
var itemPage = 0
|
||||
var itemPageCount = 1 // TODO total size of current category / items.size
|
||||
private set
|
||||
|
||||
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(0x404040_88),
|
||||
backBlendMode = BlendMode.NORMAL,
|
||||
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(0x404040_88),
|
||||
backBlendMode = BlendMode.NORMAL,
|
||||
drawBackOnNull = true,
|
||||
inactiveTextCol = defaultTextColour
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
private var items: Array<UIItemInventoryCellBase>
|
||||
= if (catArrangement[selection] in compactViewCat) itemGrid else itemList // this is INIT code
|
||||
|
||||
var isCompactMode = (catArrangement[selection] in compactViewCat) // this is INIT code
|
||||
set(value) {
|
||||
items = if (value) itemGrid else itemList
|
||||
|
||||
rebuild()
|
||||
|
||||
field = value
|
||||
}
|
||||
|
||||
|
||||
private val iconPosX = posX - 12 - parentUI.catIcons.tileW + 2
|
||||
private fun getIconPosY(index: Int) =
|
||||
posY - 2 + (4 + UIItemInventoryElem.height - (parentUI as UIInventoryFull).catIcons.tileH) * index
|
||||
|
||||
/** Long/compact mode buttons */
|
||||
private val gridModeButtons = Array<UIItemImageButton>(2, { index ->
|
||||
UIItemImageButton(
|
||||
parentUI,
|
||||
parentUI.catIcons.get(index + 14, 0),
|
||||
activeBackCol = Color(0),
|
||||
activeBackBlendMode = BlendMode.NORMAL,
|
||||
posX = iconPosX,
|
||||
posY = getIconPosY(index),
|
||||
highlightable = true
|
||||
)
|
||||
})
|
||||
|
||||
private val scrollUpButton = UIItemImageButton(
|
||||
parentUI,
|
||||
parentUI.catIcons.get(18, 0),
|
||||
activeBackCol = Color(0),
|
||||
activeBackBlendMode = BlendMode.NORMAL,
|
||||
posX = iconPosX,
|
||||
posY = getIconPosY(2),
|
||||
highlightable = false
|
||||
)
|
||||
|
||||
private val scrollDownButton = UIItemImageButton(
|
||||
parentUI,
|
||||
parentUI.catIcons.get(19, 0),
|
||||
activeBackCol = Color(0),
|
||||
activeBackBlendMode = BlendMode.NORMAL,
|
||||
posX = iconPosX,
|
||||
posY = getIconPosY(3),
|
||||
highlightable = false
|
||||
)
|
||||
|
||||
|
||||
init {
|
||||
// initially highlight grid mode buttons
|
||||
gridModeButtons[if (isCompactMode) 1 else 0].highlighted = true
|
||||
|
||||
|
||||
gridModeButtons[0].touchDownListener = { _, _, _, _ ->
|
||||
isCompactMode = false
|
||||
gridModeButtons[0].highlighted = true
|
||||
gridModeButtons[1].highlighted = false
|
||||
itemPage = 0
|
||||
rebuild()
|
||||
}
|
||||
gridModeButtons[1].touchDownListener = { _, _, _, _ ->
|
||||
isCompactMode = true
|
||||
gridModeButtons[0].highlighted = false
|
||||
gridModeButtons[1].highlighted = true
|
||||
itemPage = 0
|
||||
rebuild()
|
||||
}
|
||||
|
||||
scrollUpButton.clickOnceListener = { _, _, _ ->
|
||||
itemPage = (itemPage - 1).fmod(itemPageCount)
|
||||
scrollUpButton.highlighted = false
|
||||
rebuild()
|
||||
}
|
||||
scrollDownButton.clickOnceListener = { _, _, _ ->
|
||||
itemPage = (itemPage + 1).fmod(itemPageCount)
|
||||
scrollDownButton.highlighted = false
|
||||
rebuild()
|
||||
}
|
||||
|
||||
// if (is.mouseUp) handled by this.touchDown()
|
||||
}
|
||||
|
||||
|
||||
private val upDownButtonGapToDots = 7 // apparent gap may vary depend on the texture itself
|
||||
|
||||
override fun render(batch: SpriteBatch, camera: Camera) {
|
||||
fun getScrollDotYHeight(i: Int) = scrollUpButton.posY + 10 + upDownButtonGapToDots + 10 * i
|
||||
|
||||
scrollDownButton.posY = getScrollDotYHeight(itemPageCount) + upDownButtonGapToDots
|
||||
|
||||
|
||||
|
||||
items.forEach { it.render(batch, camera) }
|
||||
|
||||
gridModeButtons.forEach { it.render(batch, camera) }
|
||||
scrollUpButton.render(batch, camera)
|
||||
scrollDownButton.render(batch, camera)
|
||||
|
||||
// draw scroll dots
|
||||
for (i in 0 until itemPageCount) {
|
||||
val colour = if (i == itemPage) Color.WHITE else Color(0xffffff7f.toInt())
|
||||
|
||||
batch.color = colour
|
||||
batch.draw(
|
||||
(parentUI as UIInventoryFull).catIcons.get(20,0),
|
||||
scrollUpButton.posX.toFloat(),
|
||||
getScrollDotYHeight(i).toFloat()
|
||||
)
|
||||
}
|
||||
|
||||
super.render(batch, camera)
|
||||
}
|
||||
|
||||
|
||||
override fun update(delta: Float) {
|
||||
super.update(delta)
|
||||
|
||||
var tooltipSet = false
|
||||
|
||||
|
||||
|
||||
items.forEach {
|
||||
it.update(delta)
|
||||
|
||||
|
||||
// set tooltip accordingly
|
||||
if (isCompactMode && it.mouseUp && !tooltipSet) {
|
||||
(Terrarum.ingame as? Ingame)?.setTooltipMessage(it.item?.name)
|
||||
tooltipSet = true
|
||||
}
|
||||
}
|
||||
|
||||
if (!tooltipSet) {
|
||||
(Terrarum.ingame as? Ingame)?.setTooltipMessage(null)
|
||||
}
|
||||
|
||||
|
||||
|
||||
gridModeButtons.forEach { it.update(delta) }
|
||||
scrollUpButton.update(delta)
|
||||
scrollDownButton.update(delta)
|
||||
}
|
||||
|
||||
|
||||
|
||||
internal fun rebuild() {
|
||||
//println("Rebuilt inventory")
|
||||
//println("rebuild: actual itempage: $itemPage")
|
||||
|
||||
|
||||
val filter = catIconsMeaning[selectedIcon]
|
||||
|
||||
inventorySortList = ArrayList<InventoryPair>()
|
||||
|
||||
// filter items
|
||||
inventory.forEach {
|
||||
if (it.item.inventoryCategory == filter || filter == "__all__")
|
||||
inventorySortList.add(it)
|
||||
}
|
||||
|
||||
// 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
|
||||
items[k].equippedSlot = null
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
itemPageCount = (inventorySortList.size.toFloat() / items.size.toFloat()).ceilInt()
|
||||
|
||||
|
||||
rebuildList = false
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
itemList.forEach { it.dispose() }
|
||||
itemGrid.forEach { it.dispose() }
|
||||
gridModeButtons.forEach { it.dispose() }
|
||||
scrollUpButton.dispose()
|
||||
scrollDownButton.dispose()
|
||||
}
|
||||
|
||||
override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
|
||||
super.touchDown(screenX, screenY, pointer, button)
|
||||
|
||||
items.forEach { if (it.mouseUp) it.touchDown(screenX, screenY, pointer, button) }
|
||||
gridModeButtons.forEach { if (it.mouseUp) it.touchDown(screenX, screenY, pointer, button) }
|
||||
if (scrollUpButton.mouseUp) scrollUpButton.touchDown(screenX, screenY, pointer, button)
|
||||
if (scrollDownButton.mouseUp) scrollDownButton.touchDown(screenX, screenY, pointer, button)
|
||||
return true
|
||||
}
|
||||
|
||||
override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
|
||||
items.forEach { if (it.mouseUp) it.touchUp(screenX, screenY, pointer, button) }
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
override fun keyDown(keycode: Int): Boolean {
|
||||
super.keyDown(keycode)
|
||||
|
||||
items.forEach { if (it.mouseUp) it.keyDown(keycode) }
|
||||
rebuild()
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
override fun keyUp(keycode: Int): Boolean {
|
||||
super.keyUp(keycode)
|
||||
|
||||
items.forEach { if (it.mouseUp) it.keyUp(keycode) }
|
||||
rebuild()
|
||||
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
package net.torvald.terrarum.modulebasegame.ui
|
||||
|
||||
import com.badlogic.gdx.graphics.Camera
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.ActorInventory
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.ActorWithPhysics
|
||||
import net.torvald.terrarum.itemproperties.GameItem
|
||||
import net.torvald.terrarum.itemproperties.ItemCodex
|
||||
import net.torvald.terrarum.ui.UIItem
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2017-10-28.
|
||||
*/
|
||||
class UIItemInventoryEquippedView(
|
||||
parentUI: UIInventoryFull,
|
||||
val inventory: ActorInventory,
|
||||
val theActor: ActorWithPhysics,
|
||||
override var posX: Int,
|
||||
override var posY: Int
|
||||
) : UIItem(parentUI) {
|
||||
|
||||
override val width = 104
|
||||
override val height = 384
|
||||
|
||||
companion object {
|
||||
val width = 104
|
||||
val height = 384
|
||||
}
|
||||
|
||||
private val listGap = 8
|
||||
|
||||
var itemPage = 0
|
||||
var itemPageCount = 1 // TODO total size of current category / itemGrid.size
|
||||
|
||||
lateinit var inventorySortList: Array<GameItem?>
|
||||
private var rebuildList = true
|
||||
|
||||
val spriteViewBackCol: Color; get() = Color(0x404040_88.toInt())//Color(0xd4d4d4_ff.toInt())
|
||||
|
||||
private val itemGrid = Array<UIItemInventoryCellBase>(
|
||||
2 * 5, {
|
||||
UIItemInventoryElemSimple(
|
||||
parentUI = parentUI,
|
||||
posX = this.posX + (UIItemInventoryElemSimple.height + listGap) * ((it + 4) % 2),
|
||||
posY = this.posY + (UIItemInventoryElemSimple.height + listGap) * ((it + 4) / 2),
|
||||
item = null,
|
||||
amount = UIItemInventoryElem.UNIQUE_ITEM_HAS_NO_AMOUNT,
|
||||
itemImage = null,
|
||||
mouseoverBackCol = Color(0x282828_ff),
|
||||
mouseoverBackBlendMode = BlendMode.SCREEN,
|
||||
backCol = Color(0x404040_88),
|
||||
backBlendMode = BlendMode.NORMAL,
|
||||
drawBackOnNull = true
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
override fun update(delta: Float) {
|
||||
itemGrid.forEach { it.update(delta) }
|
||||
}
|
||||
|
||||
override fun render(batch: SpriteBatch, camera: Camera) {
|
||||
// sprite background
|
||||
blendNormal()
|
||||
batch.color = spriteViewBackCol
|
||||
batch.fillRect(
|
||||
posX.toFloat(), posY.toFloat(),
|
||||
width.toFloat(), width.toFloat()
|
||||
)
|
||||
|
||||
// sprite
|
||||
val sprite = theActor.sprite
|
||||
sprite?.let {
|
||||
blendNormal(batch)
|
||||
|
||||
it.render(
|
||||
batch,
|
||||
posX + (width - it.cellWidth).div(2).toFloat(),
|
||||
posY + (width - it.cellHeight).div(2).toFloat()
|
||||
) }
|
||||
|
||||
|
||||
itemGrid.forEach { it.render(batch, camera) }
|
||||
}
|
||||
|
||||
|
||||
internal fun rebuild() {
|
||||
inventorySortList = inventory.itemEquipped.clone()
|
||||
|
||||
|
||||
|
||||
rebuildList = false
|
||||
|
||||
// sort by equip position
|
||||
|
||||
// fill the grid from fastest index, make no gap in-between of slots
|
||||
var listPushCnt = 0
|
||||
for (k in 0 until itemGrid.size) {
|
||||
val it = inventorySortList[k]
|
||||
|
||||
if (it != null) {
|
||||
val itemRecord = inventory.getByDynamicID(it.dynamicID)!!
|
||||
|
||||
itemGrid[listPushCnt].item = it
|
||||
itemGrid[listPushCnt].amount = itemRecord.amount
|
||||
itemGrid[listPushCnt].itemImage = ItemCodex.getItemImage(it)
|
||||
itemGrid[listPushCnt].quickslot = null // don't need to be displayed
|
||||
itemGrid[listPushCnt].equippedSlot = null // don't need to be displayed
|
||||
|
||||
listPushCnt++
|
||||
}
|
||||
}
|
||||
|
||||
// empty out un-filled grids from previous garbage
|
||||
for (m in listPushCnt until itemGrid.size) {
|
||||
itemGrid[m].item = null
|
||||
itemGrid[m].amount = 0
|
||||
itemGrid[m].itemImage = null
|
||||
itemGrid[m].quickslot = null
|
||||
itemGrid[m].equippedSlot = null
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override fun dispose() {
|
||||
itemGrid.forEach { it.dispose() }
|
||||
}
|
||||
|
||||
override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
|
||||
super.touchDown(screenX, screenY, pointer, button)
|
||||
|
||||
itemGrid.forEach { if (it.mouseUp) it.touchDown(screenX, screenY, pointer, button) }
|
||||
return true
|
||||
}
|
||||
|
||||
override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
|
||||
itemGrid.forEach { if (it.mouseUp) it.touchUp(screenX, screenY, pointer, button) }
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
override fun keyDown(keycode: Int): Boolean {
|
||||
super.keyDown(keycode)
|
||||
|
||||
itemGrid.forEach { if (it.mouseUp) it.keyDown(keycode) }
|
||||
rebuild()
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
override fun keyUp(keycode: Int): Boolean {
|
||||
super.keyUp(keycode)
|
||||
|
||||
itemGrid.forEach { if (it.mouseUp) it.keyUp(keycode) }
|
||||
rebuild()
|
||||
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
package net.torvald.terrarum.modulebasegame.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
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.blendNormal
|
||||
import net.torvald.terrarum.floor
|
||||
import net.torvald.terrarum.ui.UICanvas
|
||||
import net.torvald.terrarum.ui.UIItem
|
||||
|
||||
class UIItemModuleInfoCell(
|
||||
parent: UICanvas,
|
||||
var moduleName: String,
|
||||
override val width: Int,
|
||||
override var posX: Int,
|
||||
override var posY: Int
|
||||
) : UIItem(parent) {
|
||||
|
||||
override val height: Int = Terrarum.fontGame.lineHeight.toInt() * 2
|
||||
|
||||
private val numberAreaWidth = Terrarum.fontSmallNumbers.W * 3 + 4
|
||||
|
||||
override fun render(batch: SpriteBatch, camera: Camera) {
|
||||
blendNormal()
|
||||
|
||||
if (ModMgr.moduleInfo.containsKey(moduleName)) {
|
||||
val modInfo = ModMgr.moduleInfo[moduleName]!!
|
||||
|
||||
// print load order index
|
||||
batch.color = Color(0xccccccff.toInt())
|
||||
var strlen = Terrarum.fontSmallNumbers.getWidth(modInfo.order.toString())
|
||||
Terrarum.fontSmallNumbers.draw(batch,
|
||||
modInfo.order.toString(),
|
||||
posX + (numberAreaWidth - strlen).div(2f).floor(),
|
||||
posY + (height - Terrarum.fontSmallNumbers.H).div(2f).floor()
|
||||
)
|
||||
|
||||
// print module name
|
||||
batch.color = Color.WHITE
|
||||
Terrarum.fontGame.draw(batch,
|
||||
"${modInfo.properName} (${modInfo.version})",
|
||||
posX + numberAreaWidth.toFloat(),
|
||||
posY.toFloat()
|
||||
)
|
||||
|
||||
// print author name
|
||||
strlen = Terrarum.fontGame.getWidth(modInfo.author)
|
||||
Terrarum.fontGame.draw(batch,
|
||||
modInfo.author,
|
||||
posX + width - strlen.toFloat(),
|
||||
posY.toFloat()
|
||||
)
|
||||
|
||||
// print description
|
||||
Terrarum.fontGame.draw(batch,
|
||||
modInfo.description,
|
||||
posX + numberAreaWidth.toFloat(),
|
||||
posY + Terrarum.fontGame.lineHeight
|
||||
)
|
||||
|
||||
// print releasedate
|
||||
strlen = Terrarum.fontGame.getWidth(modInfo.releaseDate)
|
||||
Terrarum.fontGame.draw(batch,
|
||||
modInfo.releaseDate,
|
||||
posX + width - strlen.toFloat(),
|
||||
posY + Terrarum.fontGame.lineHeight
|
||||
)
|
||||
|
||||
}
|
||||
else {
|
||||
batch.color = Color(0xff8080_ff.toInt())
|
||||
val str = "InternalError: no such module: '$moduleName'"
|
||||
val strlen = Terrarum.fontSmallNumbers.getWidth(str)
|
||||
Terrarum.fontSmallNumbers.draw(batch,
|
||||
str,
|
||||
posX + (width - numberAreaWidth - strlen).div(2f).floor() + numberAreaWidth,
|
||||
posY + (height - Terrarum.fontSmallNumbers.H).div(2f).floor()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
}
|
||||
}
|
||||
125
src/net/torvald/terrarum/modulebasegame/ui/UIPieMenu.kt
Normal file
125
src/net/torvald/terrarum/modulebasegame/ui/UIPieMenu.kt
Normal file
@@ -0,0 +1,125 @@
|
||||
package net.torvald.terrarum.modulebasegame.ui
|
||||
|
||||
import com.badlogic.gdx.graphics.Camera
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import com.jme3.math.FastMath
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.AVKey
|
||||
import net.torvald.terrarum.Second
|
||||
import net.torvald.terrarum.itemproperties.ItemCodex
|
||||
import net.torvald.terrarum.modulebasegame.Ingame
|
||||
import net.torvald.terrarum.modulebasegame.ui.UIQuickBar.Companion.CELL_SIZE
|
||||
import net.torvald.terrarum.modulebasegame.ui.UIQuickBar.Companion.SLOT_COUNT
|
||||
import net.torvald.terrarum.ui.UICanvas
|
||||
import org.dyn4j.geometry.Vector2
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2016-07-20.
|
||||
*/
|
||||
class UIPieMenu : UICanvas() {
|
||||
private val cellSize = UIQuickBar.CELL_SIZE
|
||||
|
||||
private val slotCount = UIQuickBar.SLOT_COUNT
|
||||
|
||||
private val slotDistanceFromCentre: Double
|
||||
get() = cellSize * 2.8 * handler.scale
|
||||
override var width: Int = cellSize * 7
|
||||
override var height: Int = width
|
||||
|
||||
|
||||
/**
|
||||
* In milliseconds
|
||||
*/
|
||||
override var openCloseTime: Second = 0.16f
|
||||
|
||||
private val smallenSize = 0.93f
|
||||
|
||||
var selection: Int = -1
|
||||
|
||||
override fun updateUI(delta: Float) {
|
||||
if (selection >= 0)
|
||||
(Terrarum.ingame!! as Ingame).player.actorValue[AVKey.__PLAYER_QUICKSLOTSEL] =
|
||||
selection % slotCount
|
||||
|
||||
|
||||
// update controls
|
||||
if (handler.isOpened || handler.isOpening) {
|
||||
val cursorPos = Vector2(Terrarum.mouseScreenX.toDouble(), Terrarum.mouseScreenY.toDouble())
|
||||
val centre = Vector2(Terrarum.HALFW.toDouble(), Terrarum.HALFH.toDouble())
|
||||
val deg = -(centre - cursorPos).direction.toFloat()
|
||||
|
||||
selection = Math.round(deg * slotCount / FastMath.TWO_PI)
|
||||
if (selection < 0) selection += SLOT_COUNT
|
||||
|
||||
// TODO add gamepad support
|
||||
}
|
||||
}
|
||||
|
||||
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
||||
// draw radial thingies
|
||||
for (i in 0..slotCount - 1) {
|
||||
// set position
|
||||
val angle = Math.PI * 2.0 * (i.toDouble() / slotCount) + Math.PI // 180 deg monitor-wise
|
||||
val slotCentrePoint = Vector2(0.0, slotDistanceFromCentre).setDirection(-angle) // NOTE: NOT a center of circle!
|
||||
|
||||
// draw cells
|
||||
val image = if (i == selection)
|
||||
ItemSlotImageBuilder.produceLarge(false, (i + 1) % SLOT_COUNT)
|
||||
else
|
||||
ItemSlotImageBuilder.produce(true, (i + 1) % SLOT_COUNT)
|
||||
|
||||
val slotSize = image.regionWidth
|
||||
|
||||
val slotX = slotCentrePoint.x.toFloat() - (slotSize / 2)
|
||||
val slotY = slotCentrePoint.y.toFloat() - (slotSize / 2)
|
||||
|
||||
batch.color = Color(1f, 1f, 1f, handler.opacity * UIQuickBar.finalOpacity)
|
||||
batch.draw(
|
||||
image,
|
||||
slotX,
|
||||
slotY
|
||||
)
|
||||
|
||||
|
||||
// draw item
|
||||
val itemPair = (Terrarum.ingame!! as Ingame).player.inventory.getQuickBar(i)
|
||||
|
||||
if (itemPair != null) {
|
||||
val itemImage = ItemCodex.getItemImage(itemPair.item)
|
||||
val itemW = itemImage.regionWidth
|
||||
val itemH = itemImage.regionHeight
|
||||
|
||||
batch.color = Color(1f, 1f, 1f, handler.opacity)
|
||||
batch.draw(
|
||||
itemImage, // using fixed CELL_SIZE for reasons
|
||||
slotX + (CELL_SIZE - itemW) / 2f,
|
||||
slotY + (CELL_SIZE - itemH) / 2f
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun doOpening(delta: Float) {
|
||||
doOpeningFade(this, openCloseTime)
|
||||
handler.scale = smallenSize + (1f.minus(smallenSize) * handler.opacity)
|
||||
}
|
||||
|
||||
override fun doClosing(delta: Float) {
|
||||
doClosingFade(this, openCloseTime)
|
||||
handler.scale = smallenSize + (1f.minus(smallenSize) * handler.opacity)
|
||||
}
|
||||
|
||||
override fun endOpening(delta: Float) {
|
||||
endOpeningFade(this)
|
||||
handler.scale = 1f
|
||||
}
|
||||
|
||||
override fun endClosing(delta: Float) {
|
||||
endClosingFade(this)
|
||||
handler.scale = 1f
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
}
|
||||
}
|
||||
127
src/net/torvald/terrarum/modulebasegame/ui/UIQuickBar.kt
Normal file
127
src/net/torvald/terrarum/modulebasegame/ui/UIQuickBar.kt
Normal file
@@ -0,0 +1,127 @@
|
||||
package net.torvald.terrarum.modulebasegame.ui
|
||||
|
||||
import com.badlogic.gdx.Input
|
||||
import com.badlogic.gdx.graphics.Camera
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.AVKey
|
||||
import net.torvald.terrarum.Second
|
||||
import net.torvald.terrarum.gameworld.fmod
|
||||
import net.torvald.terrarum.itemproperties.ItemCodex
|
||||
import net.torvald.terrarum.modulebasegame.Ingame
|
||||
import net.torvald.terrarum.ui.UICanvas
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2016-07-20.
|
||||
*/
|
||||
class UIQuickBar : UICanvas() {
|
||||
private val gutter = 8
|
||||
override var width: Int = (ItemSlotImageBuilder.slotImage.tileW + gutter) * SLOT_COUNT
|
||||
override var height: Int = ItemSlotImageBuilder.slotImage.tileH + 4 + Terrarum.fontGame.lineHeight.toInt()
|
||||
/**
|
||||
* In milliseconds
|
||||
*/
|
||||
override var openCloseTime: Second = 0.16f
|
||||
|
||||
private val startPointX = ItemSlotImageBuilder.slotImage.tileW / 2
|
||||
private val startPointY = ItemSlotImageBuilder.slotImage.tileH / 2
|
||||
|
||||
private var selection: Int
|
||||
get() = (Terrarum.ingame!! as Ingame).player.actorValue.getAsInt(AVKey.__PLAYER_QUICKSLOTSEL) ?: 0
|
||||
set(value) { (Terrarum.ingame!! as Ingame).player.actorValue.set(AVKey.__PLAYER_QUICKSLOTSEL, value.fmod(SLOT_COUNT)) }
|
||||
|
||||
override fun updateUI(delta: Float) {
|
||||
}
|
||||
|
||||
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
||||
|
||||
for (i in 0..SLOT_COUNT - 1) {
|
||||
val image = if (i == selection)
|
||||
ItemSlotImageBuilder.produceLarge(false, (i + 1) % SLOT_COUNT)
|
||||
else
|
||||
ItemSlotImageBuilder.produce(true, (i + 1) % SLOT_COUNT)
|
||||
|
||||
val slotX = startPointX + (CELL_SIZE + gutter).times(i).toFloat()
|
||||
val slotY = startPointY.toFloat()
|
||||
|
||||
// draw slots
|
||||
batch.color = Color(1f, 1f, 1f, handler.opacity * finalOpacity)
|
||||
batch.draw(
|
||||
image,
|
||||
slotX,
|
||||
slotY
|
||||
)
|
||||
|
||||
// draw item
|
||||
val itemPair = (Terrarum.ingame!! as Ingame).player.inventory.getQuickBar(i)
|
||||
|
||||
if (itemPair != null) {
|
||||
val itemImage = ItemCodex.getItemImage(itemPair.item)
|
||||
val itemW = itemImage.regionWidth
|
||||
val itemH = itemImage.regionHeight
|
||||
|
||||
batch.color = Color(1f, 1f, 1f, handler.opacity)
|
||||
batch.draw(
|
||||
itemImage, // using fixed CELL_SIZE for reasons
|
||||
slotX + (CELL_SIZE - itemW) / 2f,
|
||||
slotY + (CELL_SIZE - itemH) / 2f
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override fun doOpening(delta: Float) {
|
||||
handler.opacity = handler.openCloseCounter.toFloat() / openCloseTime
|
||||
}
|
||||
|
||||
override fun doClosing(delta: Float) {
|
||||
handler.opacity = (openCloseTime - handler.openCloseCounter.toFloat()) / openCloseTime
|
||||
}
|
||||
|
||||
override fun endOpening(delta: Float) {
|
||||
handler.opacity = 1f
|
||||
}
|
||||
|
||||
override fun endClosing(delta: Float) {
|
||||
handler.opacity = 0f
|
||||
}
|
||||
|
||||
override fun scrolled(amount: Int): Boolean {
|
||||
// super.scrolled(amount) // no UIItems here
|
||||
|
||||
selection = selection.plus(if (amount > 1) 1 else if (amount < -1) -1 else 0).fmod(SLOT_COUNT)
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
override fun keyDown(keycode: Int): Boolean {
|
||||
selection = when (keycode) {
|
||||
Input.Keys.NUM_1 -> 0
|
||||
Input.Keys.NUM_2 -> 1
|
||||
Input.Keys.NUM_3 -> 2
|
||||
Input.Keys.NUM_4 -> 3
|
||||
Input.Keys.NUM_5 -> 4
|
||||
Input.Keys.NUM_6 -> 5
|
||||
Input.Keys.NUM_7 -> 6
|
||||
Input.Keys.NUM_8 -> 7
|
||||
Input.Keys.NUM_9 -> 8
|
||||
Input.Keys.NUM_0 -> 9
|
||||
else -> return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
}
|
||||
|
||||
|
||||
companion object {
|
||||
val finalOpacity = 0.8f
|
||||
|
||||
const val SLOT_COUNT = 10
|
||||
const val CELL_SIZE = 32
|
||||
}
|
||||
}
|
||||
128
src/net/torvald/terrarum/modulebasegame/ui/UITierOneWatch.kt
Normal file
128
src/net/torvald/terrarum/modulebasegame/ui/UITierOneWatch.kt
Normal file
@@ -0,0 +1,128 @@
|
||||
package net.torvald.terrarum.modulebasegame.ui
|
||||
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.graphics.Camera
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.ActorHumanoid
|
||||
import net.torvald.terrarum.Second
|
||||
import net.torvald.terrarum.modulebasegame.Ingame
|
||||
import net.torvald.terrarum.roundInt
|
||||
import net.torvald.terrarum.modulebasegame.gameworld.WorldTime
|
||||
import net.torvald.terrarum.modulebasegame.imagefont.Watch7SegMain
|
||||
import net.torvald.terrarum.modulebasegame.imagefont.Watch7SegSmall
|
||||
import net.torvald.terrarum.modulebasegame.imagefont.WatchDotAlph
|
||||
import net.torvald.terrarum.ui.UICanvas
|
||||
import net.torvald.terrarum.worlddrawer.LightmapRenderer
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2017-06-11.
|
||||
*/
|
||||
class UITierOneWatch(private val player: ActorHumanoid?) : UICanvas() {
|
||||
override var width = 85
|
||||
override var height = 52
|
||||
override var openCloseTime: Second = 0f
|
||||
|
||||
private var ELuptimer = 10f // to make the light turned off by default
|
||||
private val ELuptime = 4f
|
||||
private var ELon = false
|
||||
|
||||
private var atlas = TextureRegionPack(ModMgr.getPath("basegame", "gui/watchface_atlas.tga"), width, height)
|
||||
|
||||
private var littleFont = Watch7SegSmall
|
||||
private var timeFont = Watch7SegMain
|
||||
private var textFont = WatchDotAlph
|
||||
private var moonDial = TextureRegionPack(ModMgr.getPath("basegame", "fonts/watch_17pxmoondial.tga"), 17, 17)
|
||||
private var moonDialCount = moonDial.horizontalCount
|
||||
|
||||
private val lcdLitCol = Color(0x141414_ff)
|
||||
|
||||
private val worldTime: WorldTime
|
||||
get() = (Terrarum.ingame!! as Ingame).world.time
|
||||
|
||||
|
||||
override fun updateUI(delta: Float) {
|
||||
if (ELon) {
|
||||
ELuptimer += delta
|
||||
}
|
||||
|
||||
if (mouseUp || Gdx.input.isKeyPressed(Terrarum.getConfigInt("keyinteract"))) {
|
||||
ELuptimer = 0f
|
||||
ELon = true
|
||||
}
|
||||
|
||||
if (ELuptimer >= ELuptime) {
|
||||
ELon = false
|
||||
}
|
||||
}
|
||||
|
||||
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
||||
// light overlay or EL
|
||||
if (ELon) {
|
||||
blendNormal()
|
||||
batch.draw(atlas.get(0, 2), 0f, 0f)
|
||||
}
|
||||
else {
|
||||
val lightLevel: Color
|
||||
|
||||
if (player != null) {
|
||||
val playerPos = player.hIntTilewiseHitbox
|
||||
lightLevel = (LightmapRenderer.getLight(playerPos.centeredX.toInt(), playerPos.centeredY.toInt()) ?:
|
||||
(Terrarum.ingame!! as Ingame).world.globalLight
|
||||
)
|
||||
}
|
||||
else {
|
||||
lightLevel = (Terrarum.ingame!! as Ingame).world.globalLight
|
||||
}
|
||||
|
||||
// backplate
|
||||
batch.color = Color(lightLevel.r, lightLevel.g, lightLevel.b, 1f)
|
||||
batch.draw(atlas.get(0, 0), 0f, 0f)
|
||||
}
|
||||
|
||||
// LCD back
|
||||
blendNormal()
|
||||
batch.draw(atlas.get(0, 3), 0f, 0f)
|
||||
|
||||
|
||||
|
||||
// day name
|
||||
batch.color = lcdLitCol
|
||||
textFont.draw(batch, worldTime.getDayNameShort().toUpperCase(), 7f, 7f)
|
||||
|
||||
// month
|
||||
littleFont.draw(batch, worldTime.months.toString().padStart(2, ' '), 40f, 6f)
|
||||
// day
|
||||
littleFont.draw(batch, worldTime.days.toString().padStart(2, ' '), 62f, 6f)
|
||||
|
||||
// hour
|
||||
timeFont.draw(batch, worldTime.hours.toString().padStart(2, '/'), 30f, 28f)
|
||||
// minute
|
||||
timeFont.draw(batch, worldTime.minutes.toString().padStart(2, '0'), 58f, 28f)
|
||||
|
||||
|
||||
// moon dial
|
||||
val moonPhase = (worldTime.moonPhase * moonDialCount).roundInt() % moonDialCount
|
||||
batch.color = lcdLitCol
|
||||
batch.draw(moonDial.get(moonPhase, 0), 4f, 22f)
|
||||
}
|
||||
|
||||
override fun doOpening(delta: Float) {
|
||||
}
|
||||
|
||||
override fun doClosing(delta: Float) {
|
||||
}
|
||||
|
||||
override fun endOpening(delta: Float) {
|
||||
}
|
||||
|
||||
override fun endClosing(delta: Float) {
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
atlas.dispose()
|
||||
moonDial.dispose()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
package net.torvald.terrarum.modulebasegame.ui
|
||||
|
||||
import com.badlogic.gdx.graphics.Camera
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import net.torvald.terrarum.CreditSingleton
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.Second
|
||||
import net.torvald.terrarum.ui.UICanvas
|
||||
import net.torvald.terrarum.ui.UIItemTextArea
|
||||
import net.torvald.terrarum.ui.UIItemTextButtonList
|
||||
|
||||
class UITitleRemoConCredits(val superMenu: UICanvas) : UICanvas() {
|
||||
|
||||
|
||||
val menuLabels = arrayOf(
|
||||
"MENU_LABEL_CREDITS",
|
||||
"MENU_CREDIT_GPL_DNT",
|
||||
"MENU_LABEL_RETURN"
|
||||
)
|
||||
|
||||
|
||||
override var width: Int = UITitleRemoConRoot.remoConWidth
|
||||
override var height: Int = UITitleRemoConRoot.getRemoConHeight(menuLabels)
|
||||
override var openCloseTime: Second = 0f
|
||||
|
||||
|
||||
private val textAreaHMargin = 48
|
||||
private val textAreaWidth = (Terrarum.WIDTH * 0.75).toInt()
|
||||
private val textAreaHeight = Terrarum.HEIGHT - textAreaHMargin * 2
|
||||
private val textArea = UIItemTextArea(this,
|
||||
Terrarum.WIDTH - textAreaWidth, textAreaHMargin,
|
||||
textAreaWidth, textAreaHeight
|
||||
)
|
||||
private var drawTextArea = true
|
||||
|
||||
|
||||
private val menubar = UIItemTextButtonList(
|
||||
this,
|
||||
menuLabels,
|
||||
0, UITitleRemoConRoot.menubarOffY,
|
||||
this.width, this.height,
|
||||
textAreaWidth = this.width,
|
||||
readFromLang = true,
|
||||
activeBackCol = Color(0),
|
||||
highlightBackCol = Color(0),
|
||||
backgroundCol = Color(0),
|
||||
inactiveCol = Color.WHITE,
|
||||
defaultSelection = 0 // show CREDITS
|
||||
)
|
||||
|
||||
init {
|
||||
uiItems.add(menubar)
|
||||
uiItems.add(textArea)
|
||||
|
||||
|
||||
|
||||
////////////////////////////
|
||||
|
||||
|
||||
|
||||
// attach listeners
|
||||
menubar.buttons[menuLabels.indexOf("MENU_LABEL_RETURN")].clickOnceListener = { _, _, _ ->
|
||||
this.setAsClose()
|
||||
Thread.sleep(50)
|
||||
menubar.selectedIndex = menubar.defaultSelection
|
||||
superMenu.setAsOpen()
|
||||
}
|
||||
|
||||
menubar.selectionChangeListener = { _, newIndex ->
|
||||
textArea.scrollPos = 0
|
||||
|
||||
if (newIndex == menuLabels.indexOf("MENU_LABEL_CREDITS")) {
|
||||
textArea.setWallOfText(CreditSingleton.credit)
|
||||
drawTextArea = true
|
||||
}
|
||||
else if (newIndex == menuLabels.indexOf("MENU_CREDIT_GPL_DNT")) {
|
||||
textArea.setWallOfText(CreditSingleton.gpl3)
|
||||
drawTextArea = true
|
||||
}
|
||||
else {
|
||||
drawTextArea = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun updateUI(delta: Float) {
|
||||
menubar.update(delta)
|
||||
if (drawTextArea) {
|
||||
textArea.update(delta)
|
||||
}
|
||||
}
|
||||
|
||||
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
||||
menubar.render(batch, camera)
|
||||
if (drawTextArea) {
|
||||
batch.color = Color.WHITE
|
||||
textArea.render(batch, camera)
|
||||
}
|
||||
}
|
||||
|
||||
override fun doOpening(delta: Float) {
|
||||
}
|
||||
|
||||
override fun doClosing(delta: Float) {
|
||||
}
|
||||
|
||||
override fun endOpening(delta: Float) {
|
||||
}
|
||||
|
||||
override fun endClosing(delta: Float) {
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
package net.torvald.terrarum.modulebasegame.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
|
||||
import net.torvald.terrarum.AppLoader
|
||||
import net.torvald.terrarum.Second
|
||||
import net.torvald.terrarum.langpack.Lang
|
||||
import net.torvald.terrarum.ui.UICanvas
|
||||
import net.torvald.terrarum.ui.UIItemTextButtonList
|
||||
|
||||
class UITitleRemoConLanguage(val superMenu: UICanvas) : UICanvas() {
|
||||
|
||||
val menuLabels = arrayOf(
|
||||
"MENU_LABEL_RETURN"
|
||||
)
|
||||
|
||||
|
||||
override var width: Int = UITitleRemoConRoot.remoConWidth
|
||||
override var height: Int = UITitleRemoConRoot.getRemoConHeight(menuLabels)
|
||||
override var openCloseTime: Second = 0f
|
||||
|
||||
|
||||
private val menubar = UIItemTextButtonList(
|
||||
this,
|
||||
menuLabels,
|
||||
0, UITitleRemoConRoot.menubarOffY,
|
||||
this.width, this.height,
|
||||
textAreaWidth = this.width,
|
||||
readFromLang = true,
|
||||
activeBackCol = Color(0),
|
||||
highlightBackCol = Color(0),
|
||||
backgroundCol = Color(0),
|
||||
inactiveCol = Color.WHITE,
|
||||
defaultSelection = null
|
||||
)
|
||||
|
||||
|
||||
private val textAreaHMargin = 48
|
||||
private val textAreaWidth = (Terrarum.WIDTH * 0.75).toInt()
|
||||
private val textAreaHeight = Terrarum.HEIGHT - textAreaHMargin * 2
|
||||
/*private val textArea = UIItemTextArea(this,
|
||||
Terrarum.WIDTH - textAreaWidth, textAreaHMargin,
|
||||
textAreaWidth, textAreaHeight,
|
||||
align = UIItemTextArea.Align.CENTRE
|
||||
)*/
|
||||
private val localeList = Lang.languageList.toList().sorted()
|
||||
private val textArea = UIItemTextButtonList(this,
|
||||
localeList.map { Lang.langpack["MENU_LANGUAGE_THIS_$it"] ?: "!ERR: $it" }.toTypedArray(),
|
||||
Terrarum.WIDTH - textAreaWidth, textAreaHMargin,
|
||||
textAreaWidth, textAreaHeight,
|
||||
textAreaWidth = textAreaWidth,
|
||||
readFromLang = false,
|
||||
activeBackCol = Color(0),
|
||||
highlightBackCol = Color(0),
|
||||
backgroundCol = Color(0),
|
||||
inactiveCol = Color.WHITE,
|
||||
defaultSelection = null
|
||||
)
|
||||
|
||||
|
||||
init {
|
||||
uiItems.add(menubar)
|
||||
|
||||
|
||||
//textArea.entireText = Lang.languageList.toList().sorted().map { Lang.langpack["MENU_LANGUAGE_THIS_$it"] ?: "!ERR: $it" }
|
||||
|
||||
////////////////////////////
|
||||
|
||||
|
||||
|
||||
|
||||
// attach listeners
|
||||
textArea.selectionChangeListener = { _, newSelectionIndex ->
|
||||
AppLoader.GAME_LOCALE = localeList[newSelectionIndex]
|
||||
}
|
||||
|
||||
menubar.buttons[menuLabels.indexOf("MENU_LABEL_RETURN")].clickOnceListener = { _, _, _ ->
|
||||
this.setAsClose()
|
||||
Thread.sleep(50)
|
||||
menubar.selectedIndex = menubar.defaultSelection
|
||||
superMenu.setAsOpen()
|
||||
}
|
||||
}
|
||||
|
||||
override fun updateUI(delta: Float) {
|
||||
menubar.update(delta)
|
||||
textArea.update(delta)
|
||||
}
|
||||
|
||||
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
||||
menubar.render(batch, camera)
|
||||
|
||||
batch.color = Color.WHITE
|
||||
textArea.render(batch, camera)
|
||||
}
|
||||
|
||||
override fun doOpening(delta: Float) {
|
||||
}
|
||||
|
||||
override fun doClosing(delta: Float) {
|
||||
}
|
||||
|
||||
override fun endOpening(delta: Float) {
|
||||
}
|
||||
|
||||
override fun endClosing(delta: Float) {
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
package net.torvald.terrarum.modulebasegame.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
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.blendNormal
|
||||
import net.torvald.terrarum.Second
|
||||
import net.torvald.terrarum.ui.UICanvas
|
||||
import net.torvald.terrarum.ui.UIItemList
|
||||
import net.torvald.terrarum.ui.UIItemTextButtonList
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2017-08-01.
|
||||
*/
|
||||
class UITitleRemoConModules(val superMenu: UICanvas) : UICanvas() {
|
||||
|
||||
val menuLabels = arrayOf(
|
||||
"MENU_LABEL_RETURN"
|
||||
)
|
||||
|
||||
|
||||
override var width: Int = UITitleRemoConRoot.remoConWidth
|
||||
override var height: Int = UITitleRemoConRoot.getRemoConHeight(menuLabels)
|
||||
override var openCloseTime: Second = 0f
|
||||
|
||||
|
||||
private val menubar = UIItemTextButtonList(
|
||||
this,
|
||||
menuLabels,
|
||||
0, UITitleRemoConRoot.menubarOffY,
|
||||
this.width, this.height,
|
||||
textAreaWidth = this.width,
|
||||
readFromLang = true,
|
||||
activeBackCol = Color(0),
|
||||
highlightBackCol = Color(0),
|
||||
backgroundCol = Color(0),
|
||||
inactiveCol = Color.WHITE,
|
||||
defaultSelection = null
|
||||
)
|
||||
|
||||
|
||||
private val moduleAreaHMargin = 48
|
||||
|
||||
private val moduleAreaBorder = 8
|
||||
|
||||
private val moduleAreaWidth = (Terrarum.WIDTH * 0.75).toInt() - moduleAreaHMargin
|
||||
private val moduleAreaHeight = Terrarum.HEIGHT - moduleAreaHMargin * 2
|
||||
|
||||
private val moduleInfoCells = ArrayList<UIItemModuleInfoCell>()
|
||||
// build module list
|
||||
init {
|
||||
ModMgr.moduleInfo.toList().sortedBy { it.second.order }.forEachIndexed { index, it ->
|
||||
moduleInfoCells.add(UIItemModuleInfoCell(
|
||||
this,
|
||||
it.first,
|
||||
moduleAreaWidth - 2 * moduleAreaBorder,
|
||||
0, 0 // placeholder
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
private val mouduleArea = UIItemList<UIItemModuleInfoCell>(
|
||||
this,
|
||||
moduleInfoCells,
|
||||
(Terrarum.WIDTH * 0.25f).toInt(), moduleAreaHMargin,
|
||||
moduleAreaWidth,
|
||||
moduleAreaHeight,
|
||||
inactiveCol = Color.WHITE,
|
||||
border = moduleAreaBorder
|
||||
)
|
||||
|
||||
|
||||
init {
|
||||
uiItems.add(menubar)
|
||||
uiItems.add(mouduleArea)
|
||||
|
||||
|
||||
////////////////////////////
|
||||
|
||||
|
||||
|
||||
|
||||
// attach listeners
|
||||
|
||||
menubar.buttons[menuLabels.indexOf("MENU_LABEL_RETURN")].clickOnceListener = { _, _, _ ->
|
||||
this.setAsClose()
|
||||
Thread.sleep(50)
|
||||
menubar.selectedIndex = menubar.defaultSelection
|
||||
superMenu.setAsOpen()
|
||||
}
|
||||
}
|
||||
|
||||
override fun updateUI(delta: Float) {
|
||||
menubar.update(delta)
|
||||
mouduleArea.update(delta)
|
||||
}
|
||||
|
||||
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
||||
menubar.render(batch, camera)
|
||||
|
||||
batch.color = Color.WHITE
|
||||
blendNormal()
|
||||
mouduleArea.render(batch, camera)
|
||||
}
|
||||
|
||||
override fun doOpening(delta: Float) {
|
||||
}
|
||||
|
||||
override fun doClosing(delta: Float) {
|
||||
}
|
||||
|
||||
override fun endOpening(delta: Float) {
|
||||
}
|
||||
|
||||
override fun endClosing(delta: Float) {
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
}
|
||||
|
||||
}
|
||||
138
src/net/torvald/terrarum/modulebasegame/ui/UITitleRemoConRoot.kt
Normal file
138
src/net/torvald/terrarum/modulebasegame/ui/UITitleRemoConRoot.kt
Normal file
@@ -0,0 +1,138 @@
|
||||
package net.torvald.terrarum.modulebasegame.ui
|
||||
|
||||
import com.badlogic.gdx.graphics.Camera
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import net.torvald.random.HQRNG
|
||||
import net.torvald.terrarum.modulebasegame.Ingame
|
||||
import net.torvald.terrarum.LoadScreen
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.ui.UICanvas
|
||||
import net.torvald.terrarum.ui.UIItemTextButtonList
|
||||
|
||||
class UITitleRemoConRoot : UICanvas() {
|
||||
|
||||
companion object {
|
||||
val remoConWidth = 240
|
||||
fun getRemoConHeight(menu: Array<String>) = 36 * menu.size.plus(1)
|
||||
val menubarOffY: Int; get() = Terrarum.HEIGHT / 2 - (Terrarum.fontGame.lineHeight * 1.5).toInt()
|
||||
}
|
||||
|
||||
|
||||
/** Contains STRING_IDs */
|
||||
val menuLabels = arrayOf(
|
||||
"MENU_MODE_SINGLEPLAYER",
|
||||
"MENU_OPTIONS",
|
||||
"MENU_MODULES",
|
||||
"MENU_LABEL_LANGUAGE",
|
||||
"MENU_LABEL_CREDITS",
|
||||
"MENU_LABEL_QUIT"
|
||||
)
|
||||
|
||||
|
||||
override var width: Int = remoConWidth
|
||||
override var height: Int = getRemoConHeight(menuLabels)
|
||||
override var openCloseTime = 0f
|
||||
|
||||
|
||||
private val menubar = UIItemTextButtonList(
|
||||
this,
|
||||
menuLabels,
|
||||
0, menubarOffY,
|
||||
this.width, this.height,
|
||||
textAreaWidth = this.width,
|
||||
readFromLang = true,
|
||||
activeBackCol = Color(0),
|
||||
highlightBackCol = Color(0),
|
||||
backgroundCol = Color(0),
|
||||
inactiveCol = Color.WHITE,
|
||||
defaultSelection = null
|
||||
)
|
||||
|
||||
|
||||
private val remoConCredits = UITitleRemoConCredits(this)
|
||||
private val remoConLanguage = UITitleRemoConLanguage(this)
|
||||
private val remoConModules = UITitleRemoConModules(this)
|
||||
|
||||
init {
|
||||
remoConLanguage.setPosition(0, 0)
|
||||
remoConCredits.setPosition(0, 0)
|
||||
remoConModules.setPosition(0, 0)
|
||||
|
||||
|
||||
|
||||
addSubUI(remoConLanguage)
|
||||
addSubUI(remoConCredits)
|
||||
addSubUI(remoConModules)
|
||||
|
||||
|
||||
////////////////////////////
|
||||
|
||||
uiItems.add(menubar)
|
||||
|
||||
|
||||
|
||||
// attach listeners
|
||||
|
||||
// TEST TEST TEST
|
||||
menubar.buttons[menuLabels.indexOf("MENU_MODE_SINGLEPLAYER")].clickOnceListener = { _, _, _ ->
|
||||
this.setAsClose()
|
||||
Thread.sleep(50)
|
||||
|
||||
Terrarum.ingame = Ingame(Terrarum.batch)
|
||||
(Terrarum.ingame!! as Ingame).gameLoadInfoPayload = Ingame.NewWorldParameters(2400, 800, HQRNG().nextLong())
|
||||
(Terrarum.ingame!! as Ingame).gameLoadMode = Ingame.GameLoadMode.CREATE_NEW
|
||||
LoadScreen.screenToLoad = (Terrarum.ingame!! as Ingame)
|
||||
Terrarum.setScreen(LoadScreen)
|
||||
}
|
||||
|
||||
|
||||
|
||||
menubar.buttons[menuLabels.indexOf("MENU_MODULES")].clickOnceListener = { _, _, _ ->
|
||||
this.setAsClose()
|
||||
Thread.sleep(50)
|
||||
remoConModules.setAsOpen()
|
||||
}
|
||||
menubar.buttons[menuLabels.indexOf("MENU_LABEL_LANGUAGE")].clickOnceListener = { _, _, _ ->
|
||||
this.setAsClose()
|
||||
Thread.sleep(50)
|
||||
remoConLanguage.setAsOpen()
|
||||
}
|
||||
menubar.buttons[menuLabels.indexOf("MENU_LABEL_CREDITS")].clickOnceListener = { _, _, _ ->
|
||||
this.setAsClose()
|
||||
Thread.sleep(50)
|
||||
remoConCredits.setAsOpen()
|
||||
}
|
||||
menubar.buttons[menuLabels.indexOf("MENU_LABEL_QUIT")].clickOnceListener = { _, _, _ -> Thread.sleep(50); System.exit(0) }
|
||||
}
|
||||
|
||||
override fun updateUI(delta: Float) {
|
||||
menubar.update(delta)
|
||||
//println("UITitleRemoConRoot bro u even updatez")
|
||||
}
|
||||
|
||||
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
||||
menubar.render(batch, camera)
|
||||
}
|
||||
|
||||
override fun doOpening(delta: Float) {
|
||||
|
||||
}
|
||||
|
||||
override fun doClosing(delta: Float) {
|
||||
|
||||
}
|
||||
|
||||
override fun endOpening(delta: Float) {
|
||||
|
||||
}
|
||||
|
||||
override fun endClosing(delta: Float) {
|
||||
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
73
src/net/torvald/terrarum/modulebasegame/ui/UITooltip.kt
Normal file
73
src/net/torvald/terrarum/modulebasegame/ui/UITooltip.kt
Normal file
@@ -0,0 +1,73 @@
|
||||
package net.torvald.terrarum.modulebasegame.ui
|
||||
|
||||
import com.badlogic.gdx.graphics.Camera
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.Texture
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.Second
|
||||
import net.torvald.terrarum.ui.UICanvas
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2017-11-25.
|
||||
*/
|
||||
class UITooltip : UICanvas() {
|
||||
|
||||
override var openCloseTime: Second = 0f
|
||||
|
||||
var message: String = ""
|
||||
|
||||
private val textures = TextureRegionPack("assets/graphics/gui/tooltip_black.tga", 8, 36)
|
||||
|
||||
private val font = Terrarum.fontGame
|
||||
|
||||
val textMarginX = 4
|
||||
|
||||
override var width: Int
|
||||
get() = font.getWidth(message) + (textMarginX + textures.tileW) * 2
|
||||
set(value) { throw Error("You are not supposed to set the width of the tooltip manually.") }
|
||||
override var height: Int
|
||||
get() = textures.tileH
|
||||
set(value) { throw Error("You are not supposed to set the height of the tooltip manually.") }
|
||||
|
||||
|
||||
init {
|
||||
textures.texture.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest)
|
||||
}
|
||||
|
||||
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
||||
val mouseX = Terrarum.mouseScreenX.toFloat() + 4
|
||||
val mouseY = Terrarum.mouseScreenY.toFloat() - 6
|
||||
|
||||
val tooltipY = mouseY - textures.tileH
|
||||
|
||||
val txtW = font.getWidth(message) + 2f * textMarginX
|
||||
|
||||
batch.color = Color.WHITE
|
||||
batch.draw(textures.get(0, 0), mouseX, tooltipY)
|
||||
batch.draw(textures.get(1, 0), mouseX + textures.tileW, tooltipY, txtW, height.toFloat())
|
||||
batch.draw(textures.get(2, 0), mouseX + textures.tileW + txtW, tooltipY)
|
||||
font.draw(batch, message, mouseX + textures.tileW + textMarginX, mouseY - textures.tileH + (textures.tileH - font.lineHeight) / 2)
|
||||
}
|
||||
|
||||
override fun updateUI(delta: Float) {
|
||||
}
|
||||
|
||||
override fun doOpening(delta: Float) {
|
||||
}
|
||||
|
||||
override fun doClosing(delta: Float) {
|
||||
}
|
||||
|
||||
override fun endOpening(delta: Float) {
|
||||
}
|
||||
|
||||
override fun endClosing(delta: Float) {
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
textures.dispose()
|
||||
}
|
||||
|
||||
}
|
||||
138
src/net/torvald/terrarum/modulebasegame/ui/UIVitalMetre.kt
Normal file
138
src/net/torvald/terrarum/modulebasegame/ui/UIVitalMetre.kt
Normal file
@@ -0,0 +1,138 @@
|
||||
package net.torvald.terrarum.modulebasegame.ui
|
||||
|
||||
import com.badlogic.gdx.graphics.Camera
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import com.jme3.math.FastMath
|
||||
import net.torvald.colourutil.CIELabUtil.darkerLab
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.ActorHumanoid
|
||||
import net.torvald.terrarum.Second
|
||||
import net.torvald.terrarum.ui.UICanvas
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2017-03-03.
|
||||
*/
|
||||
class UIVitalMetre(
|
||||
var player: ActorHumanoid,
|
||||
var vitalGetterVal: () -> Float?,
|
||||
var vitalGetterMax: () -> Float?,
|
||||
var color: Color?,
|
||||
val order: Int
|
||||
) : UICanvas() {
|
||||
|
||||
init {
|
||||
// semitransparent
|
||||
color?.a = 0.91f
|
||||
}
|
||||
|
||||
private val margin = 25
|
||||
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 ?: 0 * 3 + margin; set(value) { throw Error("operation not permitted") }
|
||||
|
||||
override var openCloseTime: Second = 0.05f
|
||||
|
||||
//private val relativePX = width / 2f
|
||||
private val offsetY: 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
|
||||
|
||||
private val backColor: Color
|
||||
get(): Color {
|
||||
val c = (color?.darkerLab(0.33f) ?: Color.BLACK)
|
||||
c.a = 0.7f
|
||||
return c
|
||||
}
|
||||
|
||||
override fun updateUI(delta: Float) {
|
||||
handler.setPosition(
|
||||
Terrarum.HALFW,
|
||||
Terrarum.HALFH
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* g must be same as World Graphics!
|
||||
*/
|
||||
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
||||
// TODO now that we just can't draw arcs, we need to re-think about this
|
||||
|
||||
/*if (vitalGetterVal() != null && vitalGetterMax() != null && player != null) {
|
||||
g.translate(
|
||||
Terrarum.ingame!!.screenZoom * (player.centrePosPoint.x.toFloat() - (WorldCamera.x)),
|
||||
Terrarum.ingame!!.screenZoom * (player.centrePosPoint.y.toFloat() - (WorldCamera.y))
|
||||
)
|
||||
|
||||
|
||||
g.lineWidth = 2f
|
||||
|
||||
|
||||
val ratio = minOf(1f, vitalGetterVal()!! / vitalGetterMax()!!)
|
||||
|
||||
// background
|
||||
g.color = backColor
|
||||
g.drawArc(
|
||||
-circleRadius - order * gap,
|
||||
-circleRadius - order * gap - offsetY,
|
||||
circleRadius * 2f + order * gap * 2,
|
||||
circleRadius * 2f + order * gap * 2,
|
||||
90f - halfTheta,
|
||||
90f + halfTheta - theta * ratio
|
||||
)
|
||||
|
||||
g.color = color
|
||||
g.drawArc(
|
||||
-circleRadius - order * gap,
|
||||
-circleRadius - order * gap - offsetY,
|
||||
circleRadius * 2f + order * gap * 2,
|
||||
circleRadius * 2f + order * gap * 2,
|
||||
90f + halfTheta - theta * ratio,
|
||||
90f + halfTheta
|
||||
)
|
||||
|
||||
|
||||
|
||||
g.flush()
|
||||
}*/
|
||||
}
|
||||
|
||||
override fun doOpening(delta: Float) {
|
||||
doOpeningFade(this, openCloseTime)
|
||||
}
|
||||
|
||||
override fun doClosing(delta: Float) {
|
||||
doClosingFade(this, openCloseTime)
|
||||
}
|
||||
|
||||
override fun endOpening(delta: Float) {
|
||||
endOpeningFade(this)
|
||||
}
|
||||
|
||||
override fun endClosing(delta: Float) {
|
||||
endClosingFade(this)
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
}
|
||||
}
|
||||
|
||||
fun Float.abs() = FastMath.abs(this)
|
||||
|
||||
/*
|
||||
|
||||
+-------------+ (84)
|
||||
| |
|
||||
| |
|
||||
| X |
|
||||
| @ |
|
||||
|, ,|
|
||||
| ''-------'' |
|
||||
+-------------+
|
||||
|
||||
X: UICanvas position
|
||||
|
||||
*/
|
||||
Reference in New Issue
Block a user