mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 12:21:52 +09:00
jukebox ui wip
This commit is contained in:
BIN
assets/mods/basegame/gui/jukebox_caticons.tga
LFS
Normal file
BIN
assets/mods/basegame/gui/jukebox_caticons.tga
LFS
Normal file
Binary file not shown.
@@ -72,4 +72,6 @@ id;classname
|
||||
|
||||
320;net.torvald.terrarum.modulebasegame.gameitems.ItemWorldPortal
|
||||
|
||||
65536;net.torvald.terrarum.modulebasegame.gameitems.MusicDisc01
|
||||
|
||||
999999;net.torvald.terrarum.modulebasegame.gameitems.ItemTapestry
|
||||
|
||||
|
@@ -22,6 +22,7 @@ import net.torvald.terrarum.langpack.Lang
|
||||
import net.torvald.terrarum.modulebasegame.MusicContainer
|
||||
import net.torvald.terrarum.modulebasegame.TerrarumMusicGovernor
|
||||
import net.torvald.terrarum.modulebasegame.gameitems.FixtureItemBase
|
||||
import net.torvald.terrarum.modulebasegame.ui.UIJukebox
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
import org.dyn4j.geometry.Vector2
|
||||
|
||||
@@ -32,7 +33,8 @@ class FixtureJukebox : Electric {
|
||||
|
||||
constructor() : super(
|
||||
BlockBox(BlockBox.NO_COLLISION, 2, 3),
|
||||
nameFun = { Lang["ITEM_JUKEBOX"] }
|
||||
nameFun = { Lang["ITEM_JUKEBOX"] },
|
||||
mainUI = UIJukebox()
|
||||
)
|
||||
|
||||
@Transient private var discCurrentlyPlaying: Int? = null
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
package net.torvald.terrarum.modulebasegame.gameitems
|
||||
|
||||
import net.torvald.terrarum.gameitems.GameItem
|
||||
import net.torvald.terrarum.gameitems.ItemID
|
||||
import java.io.File
|
||||
import java.util.UUID
|
||||
|
||||
/**
|
||||
* The base class for anything that holds a file like disc/disks
|
||||
*
|
||||
* Created by minjaesong on 2024-01-13.
|
||||
*/
|
||||
open class ItemFileRef(originalID: ItemID) : GameItem(originalID) {
|
||||
|
||||
open var uuid: UUID = UUID(0, 0)
|
||||
|
||||
/**
|
||||
* String of path within the module (if not refIsShared), or path under savedir/Shared/
|
||||
*/
|
||||
open var refPath: String = ""
|
||||
|
||||
/**
|
||||
* Module name (if not refIsShared), or empty string
|
||||
*/
|
||||
open var refModuleName: String = ""
|
||||
|
||||
/**
|
||||
* If the file must be found under `savedir/Shared`
|
||||
*/
|
||||
open var refIsShared: Boolean = false
|
||||
|
||||
@Transient open lateinit var ref: File
|
||||
|
||||
/**
|
||||
* Application-defined.
|
||||
*
|
||||
* For Terrarum:
|
||||
* - "music_disc" for music discs used by Jukebox
|
||||
*
|
||||
* For dwarventech:
|
||||
* - "floppy_oem" (oem: for "commercial" software)
|
||||
* - "floppy_small"
|
||||
* - "floppy_mid"
|
||||
* - "floppy_large"
|
||||
* - "floppy_debug"
|
||||
* - "floppy_homebrew"
|
||||
* - "harddisk_small"
|
||||
* - "harddisk_mid"
|
||||
* - "harddisk_large"
|
||||
* - "harddisk_debug"
|
||||
* - "eeprom_bios" (bios chips only)
|
||||
* - "eeprom_64k" (extra rom for custom motherboards)
|
||||
*
|
||||
*/
|
||||
open var mediumIdentifier = ""
|
||||
|
||||
|
||||
override var baseMass = 1.0
|
||||
override var baseToolSize: Double? = null
|
||||
override var inventoryCategory = Category.GENERIC
|
||||
override val isDynamic = true
|
||||
override val materialId = ""
|
||||
override var equipPosition = EquipPosition.HAND_GRIP
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package net.torvald.terrarum.modulebasegame.gameitems
|
||||
|
||||
import net.torvald.terrarum.ModMgr
|
||||
import net.torvald.terrarum.gameitems.ItemID
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2024-01-13.
|
||||
*/
|
||||
class MusicDisc01(originalID: ItemID) : ItemFileRef(originalID) {
|
||||
override var refPath = "audio/music/discs/01 Thousands of Shards.ogg"
|
||||
override var refModuleName = "basegame"
|
||||
override val isDynamic = false
|
||||
@Transient override var ref = ModMgr.getFile(refModuleName, refPath)
|
||||
override var mediumIdentifier = "music_disc"
|
||||
}
|
||||
@@ -10,8 +10,8 @@ import net.torvald.terrarum.modulebasegame.gameactors.FixtureInventory
|
||||
abstract class InventoryTransactionNegotiator {
|
||||
/** Retrieve item filter to be used to show only the acceptable items when player's own inventory is being displayed */
|
||||
open fun getItemFilter(): List<String> = listOf(CAT_ALL) // GameItem.Category
|
||||
/** Accepts item from the player and pass it to right inventory (object), slot (UI), etc... */
|
||||
/** Called when the item is being accepted from the player and moved to the right inventory (object), slot (UI), etc... */
|
||||
abstract fun accept(player: FixtureInventory, fixture: FixtureInventory, item: GameItem, amount: Long = 1L)
|
||||
/** Rejects item and perhaps returns it back to the player, or make explosion, etc... */
|
||||
abstract fun reject(fixture: FixtureInventory, player: FixtureInventory, item: GameItem, amount: Long = 1L)
|
||||
/** Called when the item is being removed from the fixture to returns it back to the player, or make explosion, etc... */
|
||||
abstract fun refund(fixture: FixtureInventory, player: FixtureInventory, item: GameItem, amount: Long = 1L)
|
||||
}
|
||||
@@ -35,7 +35,7 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(), HasInventory {
|
||||
override var width = App.scr.width
|
||||
override var height = App.scr.height
|
||||
|
||||
private val playerThings = CraftingPlayerInventory(full, this).also {
|
||||
private val playerThings = UITemplateHalfInventory(this, false).also {
|
||||
it.itemListTouchDownFun = { gameItem, _, _, _, _ -> recipeClicked?.let { recipe -> gameItem?.let { gameItem ->
|
||||
val itemID = gameItem.dynamicID
|
||||
// don't rely on highlightedness of the button to determine the item on the button is the selected
|
||||
@@ -77,7 +77,7 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(), HasInventory {
|
||||
// TODO()
|
||||
}
|
||||
|
||||
override fun reject(fixture: FixtureInventory, player: FixtureInventory, item: GameItem, amount: Long) {
|
||||
override fun refund(fixture: FixtureInventory, player: FixtureInventory, item: GameItem, amount: Long) {
|
||||
// TODO()
|
||||
}
|
||||
}
|
||||
@@ -126,7 +126,6 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(), HasInventory {
|
||||
// ingredient list
|
||||
itemListIngredients = UIItemInventoryItemGrid(
|
||||
this,
|
||||
catBar,
|
||||
{ ingredients },
|
||||
thisOffsetX,
|
||||
thisOffsetY + LAST_LINE_IN_GRID,
|
||||
|
||||
@@ -44,7 +44,6 @@ internal class UIInventoryCells(
|
||||
internal val itemList: UIItemInventoryItemGrid =
|
||||
UIItemInventoryItemGrid(
|
||||
full,
|
||||
full.catBar,
|
||||
{ full.actor.inventory },
|
||||
INVENTORY_CELLS_OFFSET_X(),
|
||||
INVENTORY_CELLS_OFFSET_Y(),
|
||||
|
||||
@@ -21,7 +21,7 @@ class UIItemCraftingCandidateGrid(
|
||||
keyDownFun: (GameItem?, Long, Int, Any?, UIItemInventoryCellBase) -> Unit, // Item, Amount, Keycode, extra info, keyed button
|
||||
touchDownFun: (GameItem?, Long, Int, Any?, UIItemInventoryCellBase) -> Unit // Item, Amount, Button, extra info, clicked button
|
||||
) : UIItemInventoryItemGrid(
|
||||
parentUI, catBar,
|
||||
parentUI,
|
||||
{ TODO() /* UNUSED and MUST NOT BE USED! */ },
|
||||
initialX, initialY,
|
||||
horizontalCells, verticalCells,
|
||||
|
||||
@@ -32,7 +32,6 @@ import kotlin.math.floor
|
||||
*/
|
||||
open class UIItemInventoryItemGrid(
|
||||
parentUI: UICanvas,
|
||||
val catBar: UIItemCatBar,
|
||||
var getInventory: () -> FixtureInventory, // when you're going to display List of Craftables, you could implement a Delegator...? Or just build a virtual inventory
|
||||
initialX: Int,
|
||||
initialY: Int,
|
||||
@@ -189,10 +188,6 @@ open class UIItemInventoryItemGrid(
|
||||
parentUI = inventoryUI,
|
||||
initialX = this.posX + (UIItemInventoryElemSimple.height + listGap) * (it % horizontalCells),
|
||||
initialY = this.posY + (UIItemInventoryElemSimple.height + listGap) * (it / horizontalCells),
|
||||
item = null,
|
||||
amount = UIItemInventoryElemWide.UNIQUE_ITEM_HAS_NO_AMOUNT,
|
||||
itemImage = null,
|
||||
drawBackOnNull = true,
|
||||
keyDownFun = keyDownFun,
|
||||
touchDownFun = touchDownFun,
|
||||
highlightEquippedItem = highlightEquippedItem,
|
||||
@@ -209,10 +204,6 @@ open class UIItemInventoryItemGrid(
|
||||
initialX = this.posX + (largeListWidth + listGap) * (it % itemListColumnCount),
|
||||
initialY = this.posY + (UIItemInventoryElemWide.height + listGap) * (it / itemListColumnCount),
|
||||
width = largeListWidth,
|
||||
item = null,
|
||||
amount = UIItemInventoryElemWide.UNIQUE_ITEM_HAS_NO_AMOUNT,
|
||||
itemImage = null,
|
||||
drawBackOnNull = true,
|
||||
keyDownFun = keyDownFun,
|
||||
touchDownFun = touchDownFun,
|
||||
highlightEquippedItem = highlightEquippedItem,
|
||||
|
||||
84
src/net/torvald/terrarum/modulebasegame/ui/UIJukebox.kt
Normal file
84
src/net/torvald/terrarum/modulebasegame/ui/UIJukebox.kt
Normal file
@@ -0,0 +1,84 @@
|
||||
package net.torvald.terrarum.modulebasegame.ui
|
||||
|
||||
import com.badlogic.gdx.graphics.OrthographicCamera
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.ui.*
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2024-01-13.
|
||||
*/
|
||||
class UIJukebox : UICanvas(
|
||||
toggleKeyLiteral = "control_key_inventory",
|
||||
toggleButtonLiteral = "control_gamepad_start",
|
||||
) {
|
||||
|
||||
init {
|
||||
CommonResourcePool.addToLoadingList("basegame-gui-jukebox_caticons") {
|
||||
TextureRegionPack(ModMgr.getGdxFile("basegame", "gui/jukebox_caticons.tga"), 20, 20)
|
||||
}
|
||||
CommonResourcePool.loadAll()
|
||||
}
|
||||
|
||||
override var width = Toolkit.drawWidth
|
||||
override var height = App.scr.height
|
||||
|
||||
private val catbar = UITemplateCatBar(
|
||||
this, false,
|
||||
CommonResourcePool.getAsTextureRegionPack("basegame-gui-jukebox_caticons"),
|
||||
intArrayOf(0, 1),
|
||||
emptyList(),
|
||||
listOf({ "" }, { "" })
|
||||
)
|
||||
|
||||
private val transitionalSonglistPanel = UIJukeboxSonglistPanel(this)
|
||||
private val transitionalDiscInventory = UIJukeboxInventory(this)
|
||||
|
||||
private val transitionPanel = UIItemHorizontalFadeSlide(
|
||||
this,
|
||||
0, 0, width, height, 0f,
|
||||
listOf(transitionalSonglistPanel),
|
||||
listOf(transitionalDiscInventory)
|
||||
)
|
||||
|
||||
init {
|
||||
addUIitem(catbar)
|
||||
addUIitem(transitionPanel)
|
||||
}
|
||||
|
||||
private var openingClickLatched = false
|
||||
|
||||
override fun show() {
|
||||
openingClickLatched = Terrarum.mouseDown
|
||||
transitionPanel.show()
|
||||
UIItemInventoryItemGrid.tooltipShowing.clear()
|
||||
INGAME.setTooltipMessage(null)
|
||||
}
|
||||
|
||||
override fun hide() {
|
||||
transitionPanel.hide()
|
||||
}
|
||||
|
||||
override fun updateUI(delta: Float) {
|
||||
uiItems.forEach { it.update(delta) }
|
||||
|
||||
if (openingClickLatched && !Terrarum.mouseDown) openingClickLatched = false
|
||||
}
|
||||
|
||||
override fun renderUI(frameDelta: Float, batch: SpriteBatch, camera: OrthographicCamera) {
|
||||
UIInventoryFull.drawBackground(batch, 1f)
|
||||
uiItems.forEach { it.render(frameDelta, batch, camera) }
|
||||
}
|
||||
|
||||
override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
|
||||
if (!openingClickLatched) {
|
||||
return super.touchDown(screenX, screenY, pointer, button)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
}
|
||||
|
||||
}
|
||||
112
src/net/torvald/terrarum/modulebasegame/ui/UIJukeboxInventory.kt
Normal file
112
src/net/torvald/terrarum/modulebasegame/ui/UIJukeboxInventory.kt
Normal file
@@ -0,0 +1,112 @@
|
||||
package net.torvald.terrarum.modulebasegame.ui
|
||||
|
||||
import com.badlogic.gdx.graphics.OrthographicCamera
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import net.torvald.terrarum.App
|
||||
import net.torvald.terrarum.gameitems.GameItem
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.FixtureInventory
|
||||
import net.torvald.terrarum.modulebasegame.gameitems.ItemFileRef
|
||||
import net.torvald.terrarum.ui.Toolkit
|
||||
import net.torvald.terrarum.ui.UICanvas
|
||||
import net.torvald.terrarum.ui.UIItemInventoryElemSimple
|
||||
import net.torvald.terrarum.ui.UIItemInventoryElemWide
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2024-01-13.
|
||||
*/
|
||||
class UIJukeboxInventory(val parent: UICanvas) : UICanvas(), HasInventory {
|
||||
|
||||
override var width = Toolkit.drawWidth
|
||||
override var height = App.scr.height
|
||||
|
||||
private val negotiator = object : InventoryTransactionNegotiator() {
|
||||
override fun accept(player: FixtureInventory, fixture: FixtureInventory, item: GameItem, amount: Long) {
|
||||
if (item is ItemFileRef && item.mediumIdentifier == "music_disc") {
|
||||
player.remove(item, amount)
|
||||
fixture.add(item, amount)
|
||||
}
|
||||
}
|
||||
|
||||
override fun refund(fixture: FixtureInventory, player: FixtureInventory, item: GameItem, amount: Long) {
|
||||
fixture.remove(item, amount)
|
||||
player.add(item, amount)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private val thisInventory = FixtureInventory()
|
||||
|
||||
private var halfSlotOffset = (UIItemInventoryElemSimple.height + UIItemInventoryItemGrid.listGap) / 2
|
||||
private val thisOffsetX = UIInventoryFull.INVENTORY_CELLS_OFFSET_X() + UIItemInventoryElemSimple.height + UIItemInventoryItemGrid.listGap - halfSlotOffset
|
||||
private val thisOffsetY = UIInventoryFull.INVENTORY_CELLS_OFFSET_Y()
|
||||
|
||||
private val fixtureInventoryCells = (0..7).map {
|
||||
UIItemInventoryElemWide(this,
|
||||
thisOffsetX, thisOffsetY + (UIItemInventoryElemSimple.height + UIItemInventoryItemGrid.listGap) * it,
|
||||
6 * UIItemInventoryElemSimple.height + 5 * UIItemInventoryItemGrid.listGap,
|
||||
keyDownFun = { _, _, _, _, _ -> Unit },
|
||||
touchDownFun = { gameItem, amount, button, _, _ ->
|
||||
if (button == App.getConfigInt("config_mouseprimary")) {
|
||||
if (gameItem != null) {
|
||||
negotiator.refund(getFixtureInventory(), getPlayerInventory(), gameItem, amount)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
private val playerInventoryUI = UITemplateHalfInventory(this, false)
|
||||
|
||||
init {
|
||||
fixtureInventoryCells.forEach {
|
||||
addUIitem(it)
|
||||
}
|
||||
addUIitem(playerInventoryUI)
|
||||
}
|
||||
|
||||
override fun updateUI(delta: Float) {
|
||||
uiItems.forEach { it.update(delta) }
|
||||
}
|
||||
|
||||
override fun renderUI(frameDelta: Float, batch: SpriteBatch, camera: OrthographicCamera) {
|
||||
uiItems.forEach { it.render(frameDelta, batch, camera) }
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
}
|
||||
|
||||
override fun getNegotiator() = negotiator
|
||||
|
||||
override fun getFixtureInventory(): FixtureInventory {
|
||||
TODO()
|
||||
}
|
||||
|
||||
override fun getPlayerInventory(): FixtureInventory {
|
||||
TODO()
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
class UIJukeboxSonglistPanel(val parent: UICanvas) : UICanvas() {
|
||||
|
||||
override var width = Toolkit.drawWidth
|
||||
override var height = App.scr.height
|
||||
|
||||
|
||||
|
||||
override fun updateUI(delta: Float) {
|
||||
uiItems.forEach { it.update(delta) }
|
||||
}
|
||||
|
||||
override fun renderUI(frameDelta: Float, batch: SpriteBatch, camera: OrthographicCamera) {
|
||||
uiItems.forEach { it.render(frameDelta, batch, camera) }
|
||||
}
|
||||
|
||||
|
||||
override fun dispose() {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ internal class UIStorageChest : UICanvas(
|
||||
fixture.add(item, amount)
|
||||
}
|
||||
|
||||
override fun reject(fixture: FixtureInventory, player: FixtureInventory, item: GameItem, amount: Long) {
|
||||
override fun refund(fixture: FixtureInventory, player: FixtureInventory, item: GameItem, amount: Long) {
|
||||
fixture.remove(item, amount)
|
||||
player.add(item, amount)
|
||||
}
|
||||
@@ -45,8 +45,8 @@ internal class UIStorageChest : UICanvas(
|
||||
override fun getPlayerInventory(): FixtureInventory = INGAME.actorNowPlaying!!.inventory
|
||||
|
||||
private val catBar: UIItemCatBar
|
||||
private val itemListChest: UIItemInventoryItemGrid
|
||||
private val itemListPlayer: UIItemInventoryItemGrid
|
||||
private val itemListChest: UITemplateHalfInventory
|
||||
private val itemListPlayer: UITemplateHalfInventory
|
||||
|
||||
private var encumbrancePerc = 0f
|
||||
private var isEncumbered = false
|
||||
@@ -93,40 +93,27 @@ internal class UIStorageChest : UICanvas(
|
||||
|
||||
)
|
||||
catBar.selectionChangeListener = { old, new -> itemListUpdate() }
|
||||
itemListChest = UIItemInventoryItemGrid(
|
||||
this,
|
||||
catBar,
|
||||
{ getFixtureInventory() },
|
||||
Toolkit.hdrawWidth - getWidthOfCells(6) - halfSlotOffset,
|
||||
UIInventoryFull.INVENTORY_CELLS_OFFSET_Y(),
|
||||
6, UIInventoryFull.CELLS_VRT,
|
||||
drawScrollOnRightside = false,
|
||||
drawWallet = false,
|
||||
keyDownFun = { _, _, _, _, _ -> Unit },
|
||||
touchDownFun = { gameItem, amount, button, _, _ ->
|
||||
|
||||
|
||||
itemListChest = UITemplateHalfInventory(this, true) { getFixtureInventory() }.also {
|
||||
it.itemListKeyDownFun = { _, _, _, _, _ -> Unit }
|
||||
it.itemListTouchDownFun = { gameItem, amount, button, _, _ ->
|
||||
if (button == App.getConfigInt("config_mouseprimary")) {
|
||||
if (gameItem != null) {
|
||||
negotiator.reject(getFixtureInventory(), getPlayerInventory(), gameItem, amount)
|
||||
negotiator.refund(getFixtureInventory(), getPlayerInventory(), gameItem, amount)
|
||||
}
|
||||
itemListUpdate()
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
// make grid mode buttons work together
|
||||
itemListChest.navRemoCon.listButtonListener = { _,_ -> setCompact(false) }
|
||||
itemListChest.navRemoCon.gridButtonListener = { _,_ -> setCompact(true) }
|
||||
itemListChest.itemList.navRemoCon.listButtonListener = { _,_ -> setCompact(false) }
|
||||
itemListChest.itemList.navRemoCon.gridButtonListener = { _,_ -> setCompact(true) }
|
||||
|
||||
itemListPlayer = UIItemInventoryItemGrid(
|
||||
this,
|
||||
catBar,
|
||||
{ INGAME.actorNowPlaying!!.inventory }, // literally a player's inventory
|
||||
Toolkit.hdrawWidth + halfSlotOffset,
|
||||
UIInventoryFull.INVENTORY_CELLS_OFFSET_Y(),
|
||||
6, UIInventoryFull.CELLS_VRT,
|
||||
drawScrollOnRightside = true,
|
||||
drawWallet = false,
|
||||
keyDownFun = { _, _, _, _, _ -> Unit },
|
||||
touchDownFun = { gameItem, amount, button, _, _ ->
|
||||
|
||||
itemListPlayer = UITemplateHalfInventory(this, false).also {
|
||||
it.itemListKeyDownFun = { _, _, _, _, _ -> Unit }
|
||||
it.itemListTouchDownFun = { gameItem, amount, button, _, _ ->
|
||||
if (button == App.getConfigInt("config_mouseprimary")) {
|
||||
if (gameItem != null) {
|
||||
negotiator.accept(getPlayerInventory(), getFixtureInventory(), gameItem, amount)
|
||||
@@ -134,9 +121,9 @@ internal class UIStorageChest : UICanvas(
|
||||
itemListUpdate()
|
||||
}
|
||||
}
|
||||
)
|
||||
itemListPlayer.navRemoCon.listButtonListener = { _,_ -> setCompact(false) }
|
||||
itemListPlayer.navRemoCon.gridButtonListener = { _,_ -> setCompact(true) }
|
||||
}
|
||||
itemListPlayer.itemList.navRemoCon.listButtonListener = { _,_ -> setCompact(false) }
|
||||
itemListPlayer.itemList.navRemoCon.gridButtonListener = { _,_ -> setCompact(true) }
|
||||
|
||||
handler.allowESCtoClose = true
|
||||
|
||||
@@ -148,7 +135,7 @@ internal class UIStorageChest : UICanvas(
|
||||
private var openingClickLatched = false
|
||||
|
||||
override fun show() {
|
||||
itemListPlayer.getInventory = { INGAME.actorNowPlaying!!.inventory }
|
||||
itemListPlayer.itemList.getInventory = { INGAME.actorNowPlaying!!.inventory }
|
||||
|
||||
itemListUpdate()
|
||||
|
||||
@@ -167,16 +154,16 @@ internal class UIStorageChest : UICanvas(
|
||||
}
|
||||
|
||||
private fun setCompact(yes: Boolean) {
|
||||
itemListChest.isCompactMode = yes
|
||||
itemListChest.navRemoCon.gridModeButtons[0].highlighted = !yes
|
||||
itemListChest.navRemoCon.gridModeButtons[1].highlighted = yes
|
||||
itemListChest.itemPage = 0
|
||||
itemListChest.itemList.isCompactMode = yes
|
||||
itemListChest.itemList.navRemoCon.gridModeButtons[0].highlighted = !yes
|
||||
itemListChest.itemList.navRemoCon.gridModeButtons[1].highlighted = yes
|
||||
itemListChest.itemList.itemPage = 0
|
||||
itemListChest.rebuild(catBar.catIconsMeaning[catBar.selectedIndex])
|
||||
|
||||
itemListPlayer.isCompactMode = yes
|
||||
itemListPlayer.navRemoCon.gridModeButtons[0].highlighted = !yes
|
||||
itemListPlayer.navRemoCon.gridModeButtons[1].highlighted = yes
|
||||
itemListPlayer.itemPage = 0
|
||||
itemListPlayer.itemList.isCompactMode = yes
|
||||
itemListPlayer.itemList.navRemoCon.gridModeButtons[0].highlighted = !yes
|
||||
itemListPlayer.itemList.navRemoCon.gridModeButtons[1].highlighted = yes
|
||||
itemListPlayer.itemList.itemPage = 0
|
||||
itemListPlayer.rebuild(catBar.catIconsMeaning[catBar.selectedIndex])
|
||||
|
||||
itemListUpdate()
|
||||
|
||||
@@ -1,18 +1,29 @@
|
||||
package net.torvald.terrarum.modulebasegame.ui
|
||||
|
||||
import com.badlogic.gdx.graphics.OrthographicCamera
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.gameitems.GameItem
|
||||
import net.torvald.terrarum.gameitems.ItemID
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.ActorInventory
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.FixtureInventory
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.InventoryPair
|
||||
import net.torvald.terrarum.ui.*
|
||||
|
||||
/**
|
||||
* Suite of objects for showing player inventory for various crafting UIs.
|
||||
* Suite of objects for showing player inventory for various UIs involving inventory management.
|
||||
*
|
||||
* @param parent the parent UI
|
||||
* @param drawOnLeft if the inventory should be drawn on the left panel
|
||||
* @param getInventoryFun function that returns an inventory. Default value is for player's
|
||||
*
|
||||
* Created by minjaesong on 2023-10-04.
|
||||
*/
|
||||
class CraftingPlayerInventory(val full: UIInventoryFull, val crafting: UICanvas) : UITemplate(crafting) {
|
||||
class UITemplateHalfInventory(
|
||||
parent: UICanvas,
|
||||
drawOnLeft: Boolean,
|
||||
getInventoryFun: () -> FixtureInventory = { INGAME.actorNowPlaying!!.inventory }
|
||||
) : UITemplate(parent) {
|
||||
|
||||
val itemList: UIItemInventoryItemGrid
|
||||
|
||||
@@ -30,13 +41,12 @@ class CraftingPlayerInventory(val full: UIInventoryFull, val crafting: UICanvas)
|
||||
|
||||
init {
|
||||
itemList = UIItemInventoryItemGrid(
|
||||
crafting,
|
||||
full.catBar,
|
||||
{ INGAME.actorNowPlaying!!.inventory }, // literally a player's inventory
|
||||
thisOffsetX2,
|
||||
parent,
|
||||
getInventoryFun,
|
||||
if (drawOnLeft) thisOffsetX else thisOffsetX2,
|
||||
thisOffsetY,
|
||||
6, UIInventoryFull.CELLS_VRT,
|
||||
drawScrollOnRightside = true,
|
||||
drawScrollOnRightside = !drawOnLeft,
|
||||
drawWallet = false,
|
||||
highlightEquippedItem = false,
|
||||
keyDownFun = { a, b, c, d, e -> itemListKeyDownFun(a, b, c, d, e) },
|
||||
@@ -68,6 +78,20 @@ class CraftingPlayerInventory(val full: UIInventoryFull, val crafting: UICanvas)
|
||||
itemList.getInventory = getter
|
||||
}
|
||||
|
||||
inline fun update(delta: Float) = itemList.update(delta)
|
||||
inline fun render(frameDelta: Float, batch: SpriteBatch, camera: OrthographicCamera) = itemList.render(frameDelta, batch, camera)
|
||||
|
||||
var posX: Int
|
||||
get() = itemList.posX
|
||||
set(value) { itemList.posX = value }
|
||||
var posY: Int
|
||||
get() = itemList.posY
|
||||
set(value) { itemList.posY = value }
|
||||
val width: Int
|
||||
get() = itemList.width
|
||||
val height: Int
|
||||
get() = itemList.height
|
||||
|
||||
override fun getUIitems(): List<UIItem> {
|
||||
return listOf(itemList)
|
||||
}
|
||||
@@ -27,7 +27,7 @@ class UIWorldPortalCargo(val full: UIWorldPortal) : UICanvas(), HasInventory {
|
||||
fixture.add(item, amount)
|
||||
}
|
||||
|
||||
override fun reject(fixture: FixtureInventory, player: FixtureInventory, item: GameItem, amount: Long) {
|
||||
override fun refund(fixture: FixtureInventory, player: FixtureInventory, item: GameItem, amount: Long) {
|
||||
fixture.remove(item, amount)
|
||||
player.add(item, amount)
|
||||
}
|
||||
@@ -88,7 +88,6 @@ class UIWorldPortalCargo(val full: UIWorldPortal) : UICanvas(), HasInventory {
|
||||
catBar.selectionChangeListener = { old, new -> itemListUpdate() }
|
||||
itemListChest = UIItemInventoryItemGrid(
|
||||
this,
|
||||
catBar,
|
||||
{ getFixtureInventory() },
|
||||
Toolkit.hdrawWidth - UIInventoryFull.getWidthOfCells(6) - halfSlotOffset,
|
||||
UIInventoryFull.INVENTORY_CELLS_OFFSET_Y(),
|
||||
@@ -99,7 +98,7 @@ class UIWorldPortalCargo(val full: UIWorldPortal) : UICanvas(), HasInventory {
|
||||
touchDownFun = { gameItem, amount, button, _, _ ->
|
||||
if (button == App.getConfigInt("config_mouseprimary")) {
|
||||
if (gameItem != null) {
|
||||
negotiator.reject(getFixtureInventory(), getPlayerInventory(), gameItem, amount)
|
||||
negotiator.refund(getFixtureInventory(), getPlayerInventory(), gameItem, amount)
|
||||
}
|
||||
itemListUpdate()
|
||||
}
|
||||
@@ -111,7 +110,6 @@ class UIWorldPortalCargo(val full: UIWorldPortal) : UICanvas(), HasInventory {
|
||||
|
||||
itemListPlayer = UIItemInventoryItemGrid(
|
||||
this,
|
||||
catBar,
|
||||
{ INGAME.actorNowPlaying!!.inventory }, // literally a player's inventory
|
||||
Toolkit.hdrawWidth + halfSlotOffset,
|
||||
UIInventoryFull.INVENTORY_CELLS_OFFSET_Y(),
|
||||
|
||||
@@ -44,7 +44,7 @@ class UIItemCatBar(
|
||||
// val selectedIcon: Int
|
||||
// get() = catArrangement[selectedIndex]
|
||||
|
||||
private val sideButtons: Array<UIItemImageButton>
|
||||
private lateinit var sideButtons: Array<UIItemImageButton>
|
||||
|
||||
// set up all the buttons
|
||||
init {
|
||||
@@ -71,30 +71,32 @@ class UIItemCatBar(
|
||||
}
|
||||
|
||||
|
||||
// side buttons
|
||||
// NOTE: < > arrows must "highlightable = false"; "true" otherwise
|
||||
// determine gaps: hacky way exploiting that we already know the catbar is always at the c of the ui
|
||||
val relativeStartX = posX - (uiInternalWidth - width) / 2
|
||||
val sideButtonsGap = (((uiInternalWidth - width) / 2) - 2f * catIcons.tileW) / 3f
|
||||
val iconIndex = arrayOf(
|
||||
catIcons.get(9,1),
|
||||
catIcons.get(16,0),
|
||||
catIcons.get(17,0),
|
||||
catIcons.get(13,0)
|
||||
)
|
||||
if (showSideButtons) {
|
||||
|
||||
// side buttons
|
||||
// NOTE: < > arrows must "highlightable = false"; "true" otherwise
|
||||
// determine gaps: hacky way exploiting that we already know the catbar is always at the c of the ui
|
||||
val relativeStartX = posX - (uiInternalWidth - width) / 2
|
||||
val sideButtonsGap = (((uiInternalWidth - width) / 2) - 2f * catIcons.tileW) / 3f
|
||||
val iconIndex = arrayOf(
|
||||
catIcons.get(9, 1),
|
||||
catIcons.get(16, 0),
|
||||
catIcons.get(17, 0),
|
||||
catIcons.get(13, 0)
|
||||
)
|
||||
|
||||
|
||||
//println("[UIItemInventoryCatBar] relativeStartX: $relativeStartX")
|
||||
//println("[UIItemInventoryCatBar] posX: $posX")
|
||||
//println("[UIItemInventoryCatBar] relativeStartX: $relativeStartX")
|
||||
//println("[UIItemInventoryCatBar] posX: $posX")
|
||||
|
||||
sideButtons = Array(iconIndex.size) { index ->
|
||||
val iconPosX = if (index < 2)
|
||||
(relativeStartX + sideButtonsGap + (sideButtonsGap + catIcons.tileW) * index).roundToInt()
|
||||
else
|
||||
(relativeStartX + width + 2 * sideButtonsGap + (sideButtonsGap + catIcons.tileW) * index).roundToInt()
|
||||
val iconPosY = 0
|
||||
sideButtons = Array(iconIndex.size) { index ->
|
||||
val iconPosX = if (index < 2)
|
||||
(relativeStartX + sideButtonsGap + (sideButtonsGap + catIcons.tileW) * index).roundToInt()
|
||||
else
|
||||
(relativeStartX + width + 2 * sideButtonsGap + (sideButtonsGap + catIcons.tileW) * index).roundToInt()
|
||||
val iconPosY = 0
|
||||
|
||||
UIItemImageButton(
|
||||
UIItemImageButton(
|
||||
inventoryUI,
|
||||
iconIndex[index],
|
||||
activeBackCol = Color(0),
|
||||
@@ -106,7 +108,8 @@ class UIItemCatBar(
|
||||
inactiveCol = if (index == 0 || index == 3) Color.WHITE else Color(0xffffff7f.toInt()),
|
||||
activeCol = if (index == 0 || index == 3) Toolkit.Theme.COL_MOUSE_UP else Color(0xffffff7f.toInt()),
|
||||
highlightable = (index == 0 || index == 3)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,9 +139,9 @@ class UIItemCatBar(
|
||||
if (n !in 0..2) throw IllegalArgumentException("$n")
|
||||
selectedPanel = n
|
||||
|
||||
sideButtons[0].highlighted = (n == 0)
|
||||
if (showSideButtons) sideButtons[0].highlighted = (n == 0)
|
||||
mainButtons[selectedIndex].highlighted = (n == 1)
|
||||
sideButtons[3].highlighted = (n == 2)
|
||||
if (showSideButtons) sideButtons[3].highlighted = (n == 2)
|
||||
}
|
||||
|
||||
|
||||
@@ -214,8 +217,10 @@ class UIItemCatBar(
|
||||
if (selectedPanel == 1) {
|
||||
btn.highlighted = (index == selectedIndex) // forcibly highlight if this.highlighted != null
|
||||
|
||||
sideButtons[0].highlighted = false
|
||||
sideButtons[3].highlighted = false
|
||||
if (showSideButtons) {
|
||||
sideButtons[0].highlighted = false
|
||||
sideButtons[3].highlighted = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,9 +22,9 @@ class UIItemInventoryElemSimple(
|
||||
parentUI: UICanvas,
|
||||
initialX: Int,
|
||||
initialY: Int,
|
||||
override var item: GameItem?,
|
||||
override var amount: Long,
|
||||
override var itemImage: TextureRegion?,
|
||||
override var item: GameItem? = null,
|
||||
override var amount: Long = UIItemInventoryElemWide.UNIQUE_ITEM_HAS_NO_AMOUNT,
|
||||
override var itemImage: TextureRegion? = null,
|
||||
override var quickslot: Int? = null,
|
||||
override var equippedSlot: Int? = null, // remnants of wide cell displaying slot number and highlighting; in this style of cell this field only determines highlightedness at render
|
||||
val drawBackOnNull: Boolean = true,
|
||||
|
||||
@@ -24,9 +24,9 @@ class UIItemInventoryElemWide(
|
||||
initialX: Int,
|
||||
initialY: Int,
|
||||
override val width: Int,
|
||||
override var item: GameItem?,
|
||||
override var amount: Long,
|
||||
override var itemImage: TextureRegion?,
|
||||
override var item: GameItem? = null,
|
||||
override var amount: Long = UIItemInventoryElemWide.UNIQUE_ITEM_HAS_NO_AMOUNT,
|
||||
override var itemImage: TextureRegion? = null,
|
||||
override var quickslot: Int? = null,
|
||||
override var equippedSlot: Int? = null,
|
||||
val drawBackOnNull: Boolean = true,
|
||||
|
||||
@@ -12,6 +12,7 @@ import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
*/
|
||||
class UITemplateCatBar(
|
||||
parent: UICanvas,
|
||||
showSidebuttons: Boolean,
|
||||
|
||||
catIcons: TextureRegionPack = CommonResourcePool.getAsTextureRegionPack("inventory_category"),
|
||||
catArrangement: IntArray, // icon order
|
||||
@@ -26,7 +27,7 @@ class UITemplateCatBar(
|
||||
42 - UIInventoryFull.YPOS_CORRECTION + (App.scr.height - UIInventoryFull.internalHeight) / 2,
|
||||
UIInventoryFull.internalWidth,
|
||||
UIInventoryFull.catBarWidth,
|
||||
true,
|
||||
showSidebuttons,
|
||||
catIcons, catArrangement, catIconsMeaning, catIconsLabels
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user