mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 12:21:52 +09:00
less fancy inventory transition WIP
This commit is contained in:
@@ -15,10 +15,10 @@ import net.torvald.terrarum.ui.UIUtils
|
||||
*/
|
||||
class UIItemInventoryCatBar(
|
||||
parentUI: UIInventoryFull,
|
||||
override var posX: Int,
|
||||
override var posY: Int,
|
||||
initialX: Int,
|
||||
initialY: Int,
|
||||
override val width: Int
|
||||
) : UIItem(parentUI) {
|
||||
) : UIItem(parentUI, initialX, initialY) {
|
||||
|
||||
// deal with the moving position
|
||||
override var oldPosX = posX
|
||||
@@ -59,8 +59,8 @@ class UIItemInventoryCatBar(
|
||||
backgroundCol = Color(0),
|
||||
highlightBackCol = Color(0),
|
||||
activeBackBlendMode = BlendMode.NORMAL,
|
||||
posX = posX + iconPosX,
|
||||
posY = posY + iconPosY,
|
||||
initialX = posX + iconPosX,
|
||||
initialY = posY + iconPosY,
|
||||
highlightable = true
|
||||
)
|
||||
}
|
||||
@@ -91,8 +91,8 @@ class UIItemInventoryCatBar(
|
||||
backgroundCol = Color(0),
|
||||
highlightBackCol = Color(0),
|
||||
activeBackBlendMode = BlendMode.NORMAL,
|
||||
posX = iconPosX,
|
||||
posY = posY + iconPosY,
|
||||
initialX = iconPosX,
|
||||
initialY = posY + iconPosY,
|
||||
inactiveCol = if (index == 0 || index == 3) Color.WHITE else Color(0xffffff7f.toInt()),
|
||||
activeCol = if (index == 0 || index == 3) Color(0xfff066_ff.toInt()) else Color(0xffffff7f.toInt()),
|
||||
highlightable = (index == 0 || index == 3)
|
||||
|
||||
@@ -24,8 +24,8 @@ import net.torvald.terrarum.ui.UIItemTextButton
|
||||
*/
|
||||
class UIItemInventoryElem(
|
||||
parentUI: UIInventoryFull,
|
||||
override var posX: Int,
|
||||
override var posY: Int,
|
||||
initialX: Int,
|
||||
initialY: Int,
|
||||
override val width: Int,
|
||||
override var item: GameItem?,
|
||||
override var amount: Int,
|
||||
@@ -39,7 +39,7 @@ class UIItemInventoryElem(
|
||||
override var quickslot: Int? = null,
|
||||
override var equippedSlot: Int? = null,
|
||||
val drawBackOnNull: Boolean = true
|
||||
) : UIItemInventoryCellBase(parentUI, posX, posY, item, amount, itemImage, quickslot, equippedSlot) {
|
||||
) : UIItemInventoryCellBase(parentUI, initialX, initialY, item, amount, itemImage, quickslot, equippedSlot) {
|
||||
|
||||
// deal with the moving position
|
||||
override var oldPosX = posX
|
||||
|
||||
@@ -22,8 +22,8 @@ import net.torvald.terrarum.ui.UIItemTextButton
|
||||
*/
|
||||
class UIItemInventoryElemSimple(
|
||||
parentUI: UIInventoryFull,
|
||||
override var posX: Int,
|
||||
override var posY: Int,
|
||||
initialX: Int,
|
||||
initialY: Int,
|
||||
override var item: GameItem?,
|
||||
override var amount: Int,
|
||||
override var itemImage: TextureRegion?,
|
||||
@@ -37,7 +37,7 @@ class UIItemInventoryElemSimple(
|
||||
override var quickslot: Int? = null,
|
||||
override var equippedSlot: Int? = null,
|
||||
val drawBackOnNull: Boolean = true
|
||||
) : UIItemInventoryCellBase(parentUI, posX, posY, item, amount, itemImage, quickslot, equippedSlot) {
|
||||
) : UIItemInventoryCellBase(parentUI, initialX, initialY, item, amount, itemImage, quickslot, equippedSlot) {
|
||||
|
||||
// deal with the moving position
|
||||
override var oldPosX = posX
|
||||
|
||||
@@ -40,8 +40,8 @@ class UIBuildingMakerBlockChooser(val parent: BuildingMaker): UICanvas() {
|
||||
// initialise with terrain blocks
|
||||
UIItemImageButton(
|
||||
this, ItemCodex.getItemImage(it),
|
||||
posX = MENUBAR_SIZE + (it % 16) * TILESREGION_SIZE,
|
||||
posY = (it / 16) * TILESREGION_SIZE,
|
||||
initialX = MENUBAR_SIZE + (it % 16) * TILESREGION_SIZE,
|
||||
initialY = (it / 16) * TILESREGION_SIZE,
|
||||
highlightable = false,
|
||||
width = TILESREGION_SIZE,
|
||||
height = TILESREGION_SIZE,
|
||||
|
||||
@@ -57,8 +57,8 @@ class UIBuildingMakerPenMenu(val parent: BuildingMaker): UICanvas() {
|
||||
backgroundCol = Color(0),
|
||||
highlightBackCol = Color(0),
|
||||
activeBackCol = Color(0),
|
||||
posX = newvec.x.roundInt(),
|
||||
posY = newvec.y.roundInt(),
|
||||
initialX = newvec.x.roundInt(),
|
||||
initialY = newvec.y.roundInt(),
|
||||
width = ICON_SIZE, height = ICON_SIZE,
|
||||
highlightable = false
|
||||
)
|
||||
|
||||
@@ -11,13 +11,12 @@ import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
class UIBuildingMakerToolbox : UICanvas() {
|
||||
|
||||
val toolsTexture = TextureRegionPack(ModMgr.getGdxFile("basegame", "gui/building_maker_toolbox.tga"), 16, 16)
|
||||
val tools = Array(toolsTexture.verticalCount, { UIItemImageButton(
|
||||
val tools = Array(toolsTexture.verticalCount) { UIItemImageButton(
|
||||
this, toolsTexture.get(0, it),
|
||||
posX = 0,
|
||||
posY = 20 * it,
|
||||
initialX = 0,
|
||||
initialY = 20 * it,
|
||||
highlightable = true
|
||||
|
||||
) })
|
||||
) }
|
||||
|
||||
override var width = 16
|
||||
override var height = 20 * tools.size - 4
|
||||
|
||||
@@ -23,6 +23,7 @@ import net.torvald.terrarum.ui.UIItemTextButtonList
|
||||
import net.torvald.terrarum.ui.UIItemTextButtonList.Companion.DEFAULT_LINE_HEIGHT
|
||||
import net.torvald.terrarum.ui.UIUtils
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2017-10-21.
|
||||
@@ -36,7 +37,7 @@ class UIInventoryFull(
|
||||
doNotWarnConstant: Boolean = false
|
||||
) : UICanvas(toggleKeyLiteral, toggleButtonLiteral, customPositioning, doNotWarnConstant) {
|
||||
|
||||
private val debugvals = false
|
||||
private val debugvals = true
|
||||
|
||||
override var width: Int = AppLoader.screenW
|
||||
override var height: Int = AppLoader.screenH
|
||||
@@ -145,7 +146,7 @@ class UIInventoryFull(
|
||||
private val gameMenuListWidth = 400
|
||||
private val gameMenuButtons = UIItemTextButtonList(
|
||||
this, gameMenu,
|
||||
AppLoader.screenW + (AppLoader.screenW - gameMenuListWidth) / 2,
|
||||
(AppLoader.screenW - gameMenuListWidth) / 2,
|
||||
(itemList.height - gameMenuListHeight) / 2 + itemList.posY,
|
||||
gameMenuListWidth, gameMenuListHeight,
|
||||
readFromLang = true,
|
||||
@@ -157,11 +158,12 @@ class UIInventoryFull(
|
||||
defaultSelection = null
|
||||
)
|
||||
|
||||
private val SCREEN_MINIMAP = 2f
|
||||
private val SCREEN_MINIMAP = 0f
|
||||
private val SCREEN_INVENTORY = 1f
|
||||
private val SCREEN_MENU = 0f
|
||||
private val SCREEN_MENU = 2f
|
||||
|
||||
private var currentScreen = SCREEN_INVENTORY
|
||||
/** 0..2 where 0 is minimap, 1 is inventory, 2 is menu. Non-integer value means transition is on-going */
|
||||
private var currentScreenTransition = SCREEN_INVENTORY
|
||||
private var transitionRequested = false
|
||||
private var transitionOngoing = false
|
||||
private var transitionReqSource = SCREEN_INVENTORY
|
||||
@@ -173,18 +175,7 @@ class UIInventoryFull(
|
||||
private val transitionalUpdateUIs = ArrayList<UIItem>()
|
||||
private val transitionalUpdateUIoriginalPosX = ArrayList<Int>()
|
||||
|
||||
|
||||
private fun addToTransitionalGroup(item: UIItem) {
|
||||
transitionalUpdateUIs.add(item)
|
||||
transitionalUpdateUIoriginalPosX.add(item.posX)
|
||||
}
|
||||
|
||||
private fun updateTransitionalItems() {
|
||||
for (k in 0..transitionalUpdateUIs.lastIndex) {
|
||||
val intOff = inventoryScrOffX.roundInt()
|
||||
transitionalUpdateUIs[k].posX = transitionalUpdateUIoriginalPosX[k] + intOff
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
addItem(categoryBar)
|
||||
@@ -201,11 +192,6 @@ class UIInventoryFull(
|
||||
|
||||
rebuildList()
|
||||
|
||||
|
||||
addToTransitionalGroup(itemList)
|
||||
addToTransitionalGroup(equipped)
|
||||
addToTransitionalGroup(gameMenuButtons)
|
||||
|
||||
// make gameMenuButtons work
|
||||
gameMenuButtons.selectionChangeListener = { old, new ->
|
||||
if (new == 0) {
|
||||
@@ -233,11 +219,23 @@ class UIInventoryFull(
|
||||
|
||||
transitionalUpdateUIs.forEach { it.update(delta) }
|
||||
|
||||
if (currentScreen > 1f + epsilon) {
|
||||
// update map while visible
|
||||
if (currentScreenTransition > 1f + epsilon) {
|
||||
MinimapComposer.setWorld(Terrarum.ingame!!.world)
|
||||
MinimapComposer.update()
|
||||
}
|
||||
|
||||
// update inventory while visible
|
||||
if (currentScreenTransition in epsilon..2f - epsilon) {
|
||||
itemList.update(delta)
|
||||
equipped.update(delta)
|
||||
}
|
||||
|
||||
// update menu while visible
|
||||
if (currentScreenTransition < 1f - epsilon) {
|
||||
gameMenuButtons.update(delta)
|
||||
}
|
||||
|
||||
minimapRerenderTimer += Gdx.graphics.rawDeltaTime
|
||||
}
|
||||
|
||||
@@ -257,7 +255,7 @@ class UIInventoryFull(
|
||||
fun requestTransition(target: Int) {
|
||||
if (!transitionOngoing) {
|
||||
transitionRequested = true
|
||||
transitionReqSource = currentScreen.round()
|
||||
transitionReqSource = currentScreenTransition.round()
|
||||
transitionReqTarget = target.toFloat()
|
||||
}
|
||||
}
|
||||
@@ -273,21 +271,20 @@ class UIInventoryFull(
|
||||
if (transitionOngoing) {
|
||||
transitionTimer += Gdx.graphics.rawDeltaTime
|
||||
|
||||
currentScreen = UIUtils.moveQuick(transitionReqSource, transitionReqTarget, transitionTimer, transitionLength)
|
||||
currentScreenTransition = UIUtils.moveLinear(transitionReqSource, transitionReqTarget, transitionTimer, transitionLength)
|
||||
|
||||
if (transitionTimer > transitionLength) {
|
||||
transitionOngoing = false
|
||||
currentScreen = transitionReqTarget
|
||||
currentScreenTransition = transitionReqTarget
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// update at render time
|
||||
updateTransitionalItems()
|
||||
if (debugvals) {
|
||||
batch.color = Color.WHITE
|
||||
AppLoader.fontSmallNumbers.draw(batch, "screen:$currentScreen", 500f, 20f)
|
||||
AppLoader.fontSmallNumbers.draw(batch, "screen:$currentScreenTransition", 500f, 30f)
|
||||
}
|
||||
|
||||
|
||||
@@ -316,8 +313,8 @@ class UIInventoryFull(
|
||||
// UI items
|
||||
categoryBar.render(batch, camera)
|
||||
|
||||
|
||||
if (currentScreen > 1f + epsilon) {
|
||||
// render map while visible
|
||||
if (currentScreenTransition > 1f + epsilon) {
|
||||
renderScreenMinimap(batch, camera)
|
||||
|
||||
if (debugvals) {
|
||||
@@ -326,7 +323,8 @@ class UIInventoryFull(
|
||||
}
|
||||
}
|
||||
|
||||
if (currentScreen in epsilon..2f - epsilon) {
|
||||
// render inventory while visible
|
||||
if (currentScreenTransition in epsilon..2f - epsilon) {
|
||||
renderScreenInventory(batch, camera)
|
||||
|
||||
if (debugvals) {
|
||||
@@ -335,7 +333,8 @@ class UIInventoryFull(
|
||||
}
|
||||
}
|
||||
|
||||
if (currentScreen < 1f - epsilon) {
|
||||
// render menu while visible
|
||||
if (currentScreenTransition < 1f - epsilon) {
|
||||
renderScreenGamemenu(batch, camera)
|
||||
|
||||
if (debugvals) {
|
||||
@@ -346,7 +345,9 @@ class UIInventoryFull(
|
||||
|
||||
if (debugvals) {
|
||||
batch.color = Color.WHITE
|
||||
AppLoader.fontSmallNumbers.draw(batch, "inventoryScrOffX:$inventoryScrOffX", 500f, 10f)
|
||||
AppLoader.fontSmallNumbers.draw(batch, "minimap:$minimapScrOffX", 500f, 0f)
|
||||
AppLoader.fontSmallNumbers.draw(batch, "inven:$inventoryScrOffX", 500f, 10f)
|
||||
AppLoader.fontSmallNumbers.draw(batch, "menu:$menuScrOffX", 500f, 20f)
|
||||
}
|
||||
|
||||
|
||||
@@ -354,17 +355,24 @@ class UIInventoryFull(
|
||||
|
||||
private val epsilon = 0.001f
|
||||
|
||||
private val minimapScrOffX: Float
|
||||
get() = (currentScreen - 2f) * AppLoader.screenW
|
||||
/**
|
||||
* - 0 on inventory screen
|
||||
* - +WIDTH on minimap screen
|
||||
* - -WIDTH on gamemenu screen
|
||||
*/
|
||||
private val minimapScrOffX: Float
|
||||
get() = (currentScreenTransition - 2f) * AppLoader.screenW / 2f
|
||||
private val inventoryScrOffX: Float
|
||||
get() = (currentScreen - 1f) * AppLoader.screenW
|
||||
get() = (currentScreenTransition - 1f) * AppLoader.screenW / 2f
|
||||
private val menuScrOffX: Float
|
||||
get() = (currentScreen) * AppLoader.screenW
|
||||
get() = (currentScreenTransition - 0f) * AppLoader.screenW / 2f
|
||||
|
||||
private val minimapScrOpacity: Float
|
||||
get() = (currentScreenTransition - 2f).coerceIn(0f, 1f)
|
||||
private val inventoryScrOpacity: Float
|
||||
get() = (currentScreenTransition - 1f).coerceIn(0f, 1f)
|
||||
private val menuScrOpacity: Float
|
||||
get() = (currentScreenTransition - 0f).coerceIn(0f, 1f)
|
||||
|
||||
private val MINIMAP_WIDTH = 800f
|
||||
private val MINIMAP_HEIGHT = itemList.height.toFloat()
|
||||
@@ -377,11 +385,15 @@ class UIInventoryFull(
|
||||
private val minimapFBO = FrameBuffer(Pixmap.Format.RGBA8888, MINIMAP_WIDTH.toInt(), MINIMAP_HEIGHT.toInt(), false)
|
||||
private val minimapCamera = OrthographicCamera(MINIMAP_WIDTH, MINIMAP_HEIGHT)
|
||||
|
||||
|
||||
// TODO put 3 bare sub-UIs into proper UIcanvas to handle the motherfucking opacity
|
||||
|
||||
|
||||
private fun renderScreenMinimap(batch: SpriteBatch, camera: Camera) {
|
||||
blendNormal(batch)
|
||||
|
||||
// update map panning
|
||||
if (currentScreen >= 2f - epsilon) {
|
||||
if (currentScreenTransition >= 2f - epsilon) {
|
||||
// if left click is down and cursor is in the map area
|
||||
if (Gdx.input.isButtonPressed(AppLoader.getConfigInt("mouseprimary")) &&
|
||||
Terrarum.mouseScreenY in itemList.posY..itemList.posY + itemList.height) {
|
||||
@@ -455,9 +467,9 @@ class UIInventoryFull(
|
||||
}
|
||||
batch.begin()
|
||||
|
||||
|
||||
AppLoader.fontSmallNumbers.draw(batch, "$minimapPanX, $minimapPanY; x$minimapZoom", minimapScrOffX + (AppLoader.screenW - MINIMAP_WIDTH) / 2, -10f + itemList.posY)
|
||||
|
||||
if (debugvals) {
|
||||
AppLoader.fontSmallNumbers.draw(batch, "$minimapPanX, $minimapPanY; x$minimapZoom", minimapScrOffX + (AppLoader.screenW - MINIMAP_WIDTH) / 2, -10f + itemList.posY)
|
||||
}
|
||||
|
||||
batch.projectionMatrix = camera.combined
|
||||
// 1px stroke
|
||||
@@ -479,11 +491,14 @@ class UIInventoryFull(
|
||||
AppLoader.fontGame.draw(batch, gameMenuControlHelp, offsetX + menuScrOffX, yEnd - 20)
|
||||
|
||||
// text buttons
|
||||
gameMenuButtons.posX = gameMenuButtons.initialX + menuScrOffX.roundToInt()
|
||||
gameMenuButtons.render(batch, camera)
|
||||
}
|
||||
|
||||
private fun renderScreenInventory(batch: SpriteBatch, camera: Camera) {
|
||||
itemList.posX = itemList.initialX + inventoryScrOffX.roundToInt()
|
||||
itemList.render(batch, camera)
|
||||
equipped.posX = equipped.initialX + inventoryScrOffX.roundToInt()
|
||||
equipped.render(batch, camera)
|
||||
|
||||
|
||||
|
||||
@@ -18,14 +18,14 @@ import kotlin.math.roundToInt
|
||||
*/
|
||||
abstract class UIItemInventoryCellBase(
|
||||
parentUI: UIInventoryFull,
|
||||
override var posX: Int,
|
||||
override var posY: Int,
|
||||
initialX: Int,
|
||||
initialY: 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) {
|
||||
) : UIItem(parentUI, initialX, initialY) {
|
||||
abstract override fun update(delta: Float)
|
||||
abstract override fun render(batch: SpriteBatch, camera: Camera)
|
||||
}
|
||||
|
||||
@@ -31,13 +31,13 @@ import java.util.*
|
||||
class UIItemInventoryDynamicList(
|
||||
parentUI: UIInventoryFull,
|
||||
val inventory: ActorInventory, // when you're going to display List of Craftables, you could implement a Delegator...? Or just build a virtual inventory
|
||||
override var posX: Int,
|
||||
override var posY: Int,
|
||||
initialX: Int,
|
||||
initialY: Int,
|
||||
val horizontalCells: Int,
|
||||
val verticalCells: Int,
|
||||
val drawScrollOnRightside: Boolean = false,
|
||||
val drawWallet: Boolean = true
|
||||
) : UIItem(parentUI) {
|
||||
) : UIItem(parentUI, initialX, initialY) {
|
||||
|
||||
// deal with the moving position
|
||||
override var oldPosX = posX
|
||||
@@ -115,8 +115,8 @@ class UIItemInventoryDynamicList(
|
||||
private val itemGrid = Array<UIItemInventoryCellBase>(horizontalCells * verticalCells) {
|
||||
UIItemInventoryElemSimple(
|
||||
parentUI = inventoryUI,
|
||||
posX = this.posX + (UIItemInventoryElemSimple.height + listGap) * (it % horizontalCells),
|
||||
posY = this.posY + (UIItemInventoryElemSimple.height + listGap) * (it / horizontalCells),
|
||||
initialX = this.posX + (UIItemInventoryElemSimple.height + listGap) * (it % horizontalCells),
|
||||
initialY = this.posY + (UIItemInventoryElemSimple.height + listGap) * (it / horizontalCells),
|
||||
item = null,
|
||||
amount = UIItemInventoryElem.UNIQUE_ITEM_HAS_NO_AMOUNT,
|
||||
itemImage = null,
|
||||
@@ -132,8 +132,8 @@ class UIItemInventoryDynamicList(
|
||||
private val itemList = Array<UIItemInventoryCellBase>(verticalCells * 2) {
|
||||
UIItemInventoryElem(
|
||||
parentUI = inventoryUI,
|
||||
posX = this.posX + (largeListWidth + listGap) * (it % 2),
|
||||
posY = this.posY + (UIItemInventoryElem.height + listGap) * (it / 2),
|
||||
initialX = this.posX + (largeListWidth + listGap) * (it % 2),
|
||||
initialY = this.posY + (UIItemInventoryElem.height + listGap) * (it / 2),
|
||||
width = largeListWidth,
|
||||
item = null,
|
||||
amount = UIItemInventoryElem.UNIQUE_ITEM_HAS_NO_AMOUNT,
|
||||
@@ -174,8 +174,8 @@ class UIItemInventoryDynamicList(
|
||||
highlightBackCol = Color(0),
|
||||
activeBackBlendMode = BlendMode.NORMAL,
|
||||
activeCol = defaultActiveCol,
|
||||
posX = iconPosX,
|
||||
posY = getIconPosY(index),
|
||||
initialX = iconPosX,
|
||||
initialY = getIconPosY(index),
|
||||
highlightable = true
|
||||
)
|
||||
}
|
||||
@@ -187,8 +187,8 @@ class UIItemInventoryDynamicList(
|
||||
activeBackCol = Color(0),
|
||||
activeBackBlendMode = BlendMode.NORMAL,
|
||||
activeCol = defaultActiveCol,
|
||||
posX = iconPosX,
|
||||
posY = getIconPosY(2),
|
||||
initialX = iconPosX,
|
||||
initialY = getIconPosY(2),
|
||||
highlightable = false
|
||||
)
|
||||
|
||||
@@ -199,8 +199,8 @@ class UIItemInventoryDynamicList(
|
||||
activeBackCol = Color(0),
|
||||
activeBackBlendMode = BlendMode.NORMAL,
|
||||
activeCol = defaultActiveCol,
|
||||
posX = iconPosX,
|
||||
posY = getIconPosY(3),
|
||||
initialX = iconPosX,
|
||||
initialY = getIconPosY(3),
|
||||
highlightable = false
|
||||
)
|
||||
|
||||
|
||||
@@ -22,9 +22,9 @@ class UIItemInventoryEquippedView(
|
||||
parentUI: UIInventoryFull,
|
||||
val inventory: ActorInventory,
|
||||
val theActor: ActorWithBody,
|
||||
override var posX: Int,
|
||||
override var posY: Int
|
||||
) : UIItem(parentUI) {
|
||||
initialX: Int,
|
||||
initialY: Int
|
||||
) : UIItem(parentUI, initialX, initialY) {
|
||||
|
||||
|
||||
override val width = WIDTH
|
||||
@@ -53,8 +53,8 @@ class UIItemInventoryEquippedView(
|
||||
private val itemGrid = Array<UIItemInventoryCellBase>(2 * 6) {
|
||||
UIItemInventoryElemSimple(
|
||||
parentUI = parentUI,
|
||||
posX = this.posX + (UIItemInventoryElemSimple.height + listGap) * ((it + 4) % 2),
|
||||
posY = this.posY + (UIItemInventoryElemSimple.height + listGap) * ((it + 4) / 2),
|
||||
initialX = this.posX + (UIItemInventoryElemSimple.height + listGap) * ((it + 4) % 2),
|
||||
initialY = this.posY + (UIItemInventoryElemSimple.height + listGap) * ((it + 4) / 2),
|
||||
item = null,
|
||||
amount = UIItemInventoryElem.UNIQUE_ITEM_HAS_NO_AMOUNT,
|
||||
itemImage = null,
|
||||
|
||||
@@ -19,11 +19,11 @@ class UIItemPlayerInfoCell(
|
||||
parent: UICanvas,
|
||||
val saveInfo: ReadWorldInfo.SaveMetaData,
|
||||
override val width: Int,
|
||||
override var posX: Int,
|
||||
override var posY: Int,
|
||||
initialX: Int,
|
||||
initialY: Int,
|
||||
var highlightable: Boolean,
|
||||
var ingamePlayer: IngamePlayer? = null
|
||||
) : UIItem(parent) {
|
||||
) : UIItem(parent, initialX, initialY) {
|
||||
|
||||
// deal with the moving position
|
||||
override var oldPosX = posX
|
||||
|
||||
@@ -17,9 +17,9 @@ class UIItemSavegameInfoCell(
|
||||
parent: UICanvas,
|
||||
savefile: File,
|
||||
override val width: Int,
|
||||
override var posX: Int,
|
||||
override var posY: Int
|
||||
) : UIItem(parent) {
|
||||
initialX: Int,
|
||||
initialY: Int
|
||||
) : UIItem(parent, initialX, initialY) {
|
||||
|
||||
// deal with the moving position
|
||||
override var oldPosX = posX
|
||||
|
||||
@@ -45,13 +45,16 @@ import net.torvald.terrarum.Terrarum
|
||||
* As mentioned in [UICanvas], UIItems must be added to the Canvas to make listeners work without implementing
|
||||
* everything by yourself.
|
||||
*
|
||||
* @param initialX initial position of the item. Useful for making transition that requires the item to be moved
|
||||
* @param initialY initial position of the item. Useful for making transition that requires the item to be moved
|
||||
*
|
||||
* Created by minjaesong on 2015-12-31.
|
||||
*/
|
||||
abstract class UIItem(var parentUI: UICanvas): Disposable { // do not replace parentUI to UIHandler!
|
||||
abstract class UIItem(var parentUI: UICanvas, val initialX: Int, val initialY: Int): Disposable { // do not replace parentUI to UIHandler!
|
||||
|
||||
// X/Y Position relative to the containing canvas
|
||||
abstract var posX: Int
|
||||
abstract var posY: Int
|
||||
var posX: Int = initialX
|
||||
var posY: Int = initialY
|
||||
abstract val width: Int
|
||||
abstract val height: Int
|
||||
|
||||
|
||||
@@ -13,14 +13,14 @@ import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
*/
|
||||
class UIItemConfigKeycap(
|
||||
parent: UICanvas,
|
||||
override var posX: Int,
|
||||
override var posY: Int,
|
||||
initialX: Int,
|
||||
initialY: Int,
|
||||
|
||||
private val keySize: Int,
|
||||
|
||||
private val keycode: Int, // also used to draw key label
|
||||
private var keyItem: Int? = null // internal index for the key's behaviour, also used to choose appropriate icon
|
||||
) : UIItem(parent) {
|
||||
) : UIItem(parent, initialX, initialY) {
|
||||
|
||||
init {
|
||||
if (keySize < 3) throw IllegalArgumentException("Key size must be greater than 2 (got $keySize)")
|
||||
|
||||
@@ -32,14 +32,14 @@ open class UIItemImageButton(
|
||||
val backgroundCol: Color = UIItemTextButtonList.DEFAULT_BACKGROUNDCOL,
|
||||
val backgroundBlendMode: String = BlendMode.NORMAL,
|
||||
|
||||
override var posX: Int,
|
||||
override var posY: Int,
|
||||
initialX: Int,
|
||||
initialY: Int,
|
||||
override val width: Int = image.regionWidth,
|
||||
override val height: Int = image.regionHeight,
|
||||
|
||||
/** When clicked, toggle its "lit" status */
|
||||
var highlightable: Boolean
|
||||
) : UIItem(parent) {
|
||||
) : UIItem(parent, initialX, initialY) {
|
||||
|
||||
// deal with the moving position
|
||||
override var oldPosX = posX
|
||||
|
||||
@@ -12,13 +12,13 @@ import java.util.*
|
||||
*/
|
||||
class UIItemImageGallery(
|
||||
parentUI: UICanvas,
|
||||
override var posX: Int,
|
||||
override var posY: Int,
|
||||
initialX: Int,
|
||||
initialY: Int,
|
||||
override val width: Int,
|
||||
override val height: Int,
|
||||
val imageList: ArrayList<Texture>,
|
||||
val column: Int = 1
|
||||
) : UIItem(parentUI) {
|
||||
) : UIItem(parentUI, initialX, initialY) {
|
||||
|
||||
// deal with the moving position
|
||||
override var oldPosX = posX
|
||||
|
||||
@@ -13,8 +13,12 @@ import java.awt.Color
|
||||
class UIItemIntSlider(
|
||||
parent: UICanvas,
|
||||
initValue: Int,
|
||||
initialX: Int,
|
||||
initialY: Int,
|
||||
|
||||
override val width: Int,
|
||||
override val height: Int,
|
||||
|
||||
val minValue: Int,
|
||||
val maxValue: Int,
|
||||
val step: Int,
|
||||
@@ -38,11 +42,13 @@ class UIItemIntSlider(
|
||||
|
||||
val sliderUseColourMap: GdxColorMap? = null,
|
||||
val sliderUseTexture: Texture? = null
|
||||
) : UIItem(parent) {
|
||||
) : UIItem(parent, initialX, initialY) {
|
||||
|
||||
constructor(
|
||||
parent: UICanvas,
|
||||
initValue: Int,
|
||||
initialX: Int,
|
||||
initialY: Int,
|
||||
values: IntRange,
|
||||
width: Int,
|
||||
height: Int,
|
||||
@@ -60,6 +66,8 @@ class UIItemIntSlider(
|
||||
) : this(
|
||||
parent,
|
||||
initValue,
|
||||
initialX,
|
||||
initialY,
|
||||
values.first,
|
||||
values.last,
|
||||
values.step,
|
||||
@@ -84,12 +92,6 @@ class UIItemIntSlider(
|
||||
// TODO unimplemented
|
||||
|
||||
|
||||
override var posX: Int
|
||||
get() = TODO("not implemented") //To change initializer of created properties use File | Settings | File Templates.
|
||||
set(value) {}
|
||||
override var posY: Int
|
||||
get() = TODO("not implemented") //To change initializer of created properties use File | Settings | File Templates.
|
||||
set(value) {}
|
||||
override val mouseUp: Boolean
|
||||
get() = super.mouseUp
|
||||
override val mousePushed: Boolean
|
||||
|
||||
@@ -14,8 +14,8 @@ import net.torvald.terrarum.fillRect
|
||||
class UIItemList<Item: UIItem>(
|
||||
parentUI: UICanvas,
|
||||
val itemList: ArrayList<Item>,
|
||||
override var posX: Int,
|
||||
override var posY: Int,
|
||||
initialX: Int,
|
||||
initialY: Int,
|
||||
override val width: Int,
|
||||
override val height: Int,
|
||||
|
||||
@@ -34,7 +34,7 @@ class UIItemList<Item: UIItem>(
|
||||
val backgroundBlendMode: String = BlendMode.NORMAL,
|
||||
val kinematic: Boolean = false,
|
||||
val border: Int = 0
|
||||
) : UIItem(parentUI) {
|
||||
) : UIItem(parentUI, initialX, initialY) {
|
||||
|
||||
// deal with the moving position
|
||||
override var oldPosX = posX
|
||||
|
||||
@@ -12,9 +12,9 @@ class UIItemModuleInfoCell(
|
||||
parent: UICanvas,
|
||||
var moduleName: String,
|
||||
override val width: Int,
|
||||
override var posX: Int,
|
||||
override var posY: Int
|
||||
) : UIItem(parent) {
|
||||
initialX: Int,
|
||||
initialY: Int
|
||||
) : UIItem(parent, initialX, initialY) {
|
||||
|
||||
// deal with the moving position
|
||||
override var oldPosX = posX
|
||||
|
||||
@@ -8,14 +8,14 @@ import net.torvald.terrarum.ui.UIItemTextButton.Companion.Alignment
|
||||
|
||||
class UIItemTextArea(
|
||||
parentUI: UICanvas,
|
||||
override var posX: Int,
|
||||
override var posY: Int,
|
||||
initialX: Int,
|
||||
initialY: Int,
|
||||
override val width: Int,
|
||||
override val height: Int,
|
||||
val lineGap: Int = 0,
|
||||
val lineCount: Int = ((height + lineGap) / AppLoader.fontGame.lineHeight).toInt(),
|
||||
val align: Alignment = Alignment.LEFT
|
||||
) : UIItem(parentUI) {
|
||||
) : UIItem(parentUI, initialX, initialY) {
|
||||
|
||||
// deal with the moving position
|
||||
override var oldPosX = posX
|
||||
|
||||
@@ -18,8 +18,8 @@ open class UIItemTextButton(
|
||||
parentUI: UICanvas,
|
||||
/** Stored text (independent to the Langpack) */
|
||||
val labelText: String,
|
||||
override var posX: Int,
|
||||
override var posY: Int,
|
||||
initialX: Int,
|
||||
initialY: Int,
|
||||
override val width: Int,
|
||||
val readFromLang: Boolean = false,
|
||||
|
||||
@@ -46,7 +46,7 @@ open class UIItemTextButton(
|
||||
|
||||
val alignment: Alignment = Alignment.CENTRE,
|
||||
val hitboxSize: Int = UIItemTextButton.height
|
||||
) : UIItem(parentUI) {
|
||||
) : UIItem(parentUI, initialX, initialY) {
|
||||
|
||||
// deal with the moving position
|
||||
override var oldPosX = posX
|
||||
|
||||
@@ -12,8 +12,8 @@ import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
class UIItemTextButtonList(
|
||||
parentUI: UICanvas,
|
||||
labelsList: Array<String>,
|
||||
override var posX: Int,
|
||||
override var posY: Int,
|
||||
initialX: Int,
|
||||
initialY: Int,
|
||||
override var width: Int,
|
||||
override var height: Int = DEFAULT_LINE_HEIGHT * labelsList.size,
|
||||
val readFromLang: Boolean = false,
|
||||
@@ -48,7 +48,7 @@ class UIItemTextButtonList(
|
||||
|
||||
val alignment: UIItemTextButton.Companion.Alignment = UIItemTextButton.Companion.Alignment.CENTRE,
|
||||
val itemHitboxSize: Int = DEFAULT_LINE_HEIGHT
|
||||
) : UIItem(parentUI) {
|
||||
) : UIItem(parentUI, initialX, initialY) {
|
||||
|
||||
companion object {
|
||||
val DEFAULT_BACKGROUNDCOL = Color(0x242424_80)
|
||||
@@ -83,8 +83,8 @@ class UIItemTextButtonList(
|
||||
if (!kinematic) {
|
||||
UIItemTextButton(
|
||||
parentUI, s,
|
||||
posX = posX,
|
||||
posY = posY + vertOff,
|
||||
initialX = posX,
|
||||
initialY = posY + vertOff,
|
||||
width = width,
|
||||
readFromLang = readFromLang,
|
||||
activeCol = activeCol,
|
||||
@@ -105,8 +105,8 @@ class UIItemTextButtonList(
|
||||
else {
|
||||
UIItemTextButton(
|
||||
parentUI, s,
|
||||
posX = posX,
|
||||
posY = posY + vertOff,
|
||||
initialX = posX,
|
||||
initialY = posY + vertOff,
|
||||
width = width,
|
||||
readFromLang = readFromLang,
|
||||
activeCol = activeCol,
|
||||
@@ -126,7 +126,7 @@ class UIItemTextButtonList(
|
||||
}
|
||||
|
||||
|
||||
/*override var posX = 0
|
||||
/*initialX = 0
|
||||
set(value) {
|
||||
buttons.forEach {
|
||||
val oldPosX = field
|
||||
@@ -135,7 +135,7 @@ class UIItemTextButtonList(
|
||||
}
|
||||
field = value
|
||||
}
|
||||
override var posY = 0
|
||||
initialY = 0
|
||||
set(value) {
|
||||
buttons.forEach {
|
||||
val oldPosY = field
|
||||
|
||||
@@ -15,10 +15,10 @@ import kotlin.math.roundToInt
|
||||
*/
|
||||
class UIItemToggleButton(
|
||||
parent: UICanvas,
|
||||
override var posX: Int,
|
||||
override var posY: Int,
|
||||
initialX: Int,
|
||||
initialY: Int,
|
||||
private var status: Boolean = false
|
||||
) : UIItem(parent) {
|
||||
) : UIItem(parent, initialX, initialY) {
|
||||
|
||||
init {
|
||||
CommonResourcePool.addToLoadingList("ui_item_toggler_base") {
|
||||
|
||||
@@ -8,4 +8,6 @@ import net.torvald.terrarum.sqr
|
||||
object UIUtils {
|
||||
fun moveQuick(start: Float, end: Float, timer: Float, duration: Float) =
|
||||
(start - end) * ((timer / duration) - 1).sqr() + end
|
||||
fun moveLinear(start: Float, end: Float, timer: Float, duration: Float) =
|
||||
(start - end) * (1 - (timer / duration)) + end
|
||||
}
|
||||
Reference in New Issue
Block a user