mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-08 04:41:51 +09:00
almost working jukebox ui except for the 'q' key
This commit is contained in:
@@ -1338,8 +1338,9 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
|
||||
uiAutosaveNotifier.setAsClose()
|
||||
autosaveTimer = 0f
|
||||
|
||||
debugTimers.put("Last Autosave Duration", System.nanoTime() - start)
|
||||
printdbg(this, "Last Autosave Duration: ${(System.nanoTime() - start) / 1000000000} s")
|
||||
val timeDiff = System.nanoTime() - start
|
||||
debugTimers.put("Last Autosave Duration", timeDiff)
|
||||
printdbg(this, "Last Autosave Duration: ${(timeDiff) / 1000000000} s")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -379,7 +379,7 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange {
|
||||
}
|
||||
|
||||
/** force disable despawn when inventory is not empty */
|
||||
val canBeDespawned: Boolean get() = inventory?.isEmpty() ?: true
|
||||
open val canBeDespawned: Boolean get() = inventory?.isEmpty() ?: true
|
||||
|
||||
@Transient open var despawnHook: (FixtureBase) -> Unit = {}
|
||||
|
||||
|
||||
@@ -20,9 +20,8 @@ import net.torvald.terrarum.modulebasegame.MusicContainer
|
||||
import net.torvald.terrarum.modulebasegame.TerrarumMusicGovernor
|
||||
import net.torvald.terrarum.modulebasegame.gameitems.FixtureItemBase
|
||||
import net.torvald.terrarum.modulebasegame.gameitems.ItemFileRef
|
||||
import net.torvald.terrarum.modulebasegame.gameitems.MusicDiscHelper
|
||||
import net.torvald.terrarum.modulebasegame.ui.UIJukebox
|
||||
import net.torvald.terrarum.modulebasegame.ui.UIJukebox.Companion.SLOT_SIZE
|
||||
import net.torvald.terrarum.utils.JsonFetcher
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
import org.dyn4j.geometry.Vector2
|
||||
|
||||
@@ -42,7 +41,7 @@ class FixtureJukebox : Electric {
|
||||
|
||||
@Transient private val backLamp: SheetSpriteAnimation
|
||||
|
||||
internal val discInventory = arrayOfNulls<ItemID>(SLOT_SIZE)
|
||||
internal val discInventory = ArrayList<ItemID>()
|
||||
|
||||
val musicIsPlaying: Boolean
|
||||
get() = musicNowPlaying != null
|
||||
@@ -73,6 +72,9 @@ class FixtureJukebox : Electric {
|
||||
|
||||
private var waitAkku = 0f
|
||||
|
||||
override val canBeDespawned: Boolean
|
||||
get() = discInventory.isEmpty()
|
||||
|
||||
override fun update(delta: Float) {
|
||||
super.update(delta)
|
||||
|
||||
@@ -84,27 +86,27 @@ class FixtureJukebox : Electric {
|
||||
|
||||
|
||||
fun playDisc(index: Int) {
|
||||
if (index !in discInventory.indices) return
|
||||
|
||||
|
||||
printdbg(this, "Play disc $index!")
|
||||
|
||||
val disc = discInventory[index]
|
||||
val musicFile = (ItemCodex[disc] as? ItemFileRef)?.getAsGdxFile()
|
||||
|
||||
if (musicFile != null) {
|
||||
val musicdbFile = musicFile.sibling("_musicdb.json")
|
||||
val musicdb = JsonFetcher.invoke(musicdbFile.file())
|
||||
val propForThisFile = musicdb.get(musicFile.name())
|
||||
|
||||
val artist = propForThisFile.get("artist").asString()
|
||||
val title = propForThisFile.get("title").asString()
|
||||
val (title, artist) = MusicDiscHelper.getMetadata(musicFile)
|
||||
|
||||
printdbg(this, "Title: $title, artist: $artist")
|
||||
|
||||
|
||||
musicNowPlaying = MusicContainer(title, musicFile.file(), Gdx.audio.newMusic(musicFile)) {
|
||||
unloadConvolver(musicNowPlaying)
|
||||
discCurrentlyPlaying = null
|
||||
musicNowPlaying?.gdxMusic?.tryDispose()
|
||||
musicNowPlaying = null
|
||||
|
||||
printdbg(this, "Stop music $title - $artist")
|
||||
|
||||
(INGAME.musicGovernor as TerrarumMusicGovernor).stopMusic(pauseLen = Math.random().toFloat() * 30f + 30f)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,20 +1,47 @@
|
||||
package net.torvald.terrarum.modulebasegame.gameitems
|
||||
|
||||
import com.badlogic.gdx.files.FileHandle
|
||||
import net.torvald.terrarum.ModMgr
|
||||
import net.torvald.terrarum.gameitems.ItemID
|
||||
import net.torvald.terrarum.utils.JsonFetcher
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2024-01-13.
|
||||
*/
|
||||
class MusicDisc01(originalID: ItemID) : ItemFileRef(originalID) {
|
||||
init {
|
||||
name = "Thousands of Shards"
|
||||
author = "Orstphone"
|
||||
}
|
||||
data class MusicDiscMetadata(val title: String, val author: String)
|
||||
|
||||
override var refPath = "audio/music/discs/01 Thousands of Shards.ogg"
|
||||
override var refModuleName = "basegame"
|
||||
object MusicDiscHelper {
|
||||
fun getMetadata(musicFile: FileHandle): MusicDiscMetadata {
|
||||
val musicdbFile = musicFile.sibling("_musicdb.json")
|
||||
val musicdb = JsonFetcher.invoke(musicdbFile.file())
|
||||
val propForThisFile = musicdb.get(musicFile.name())
|
||||
|
||||
val artist = propForThisFile.get("artist").asString()
|
||||
val title = propForThisFile.get("title").asString()
|
||||
|
||||
return MusicDiscMetadata(title, artist)
|
||||
}
|
||||
}
|
||||
|
||||
open class MusicDiscPrototype(originalID: ItemID, module: String, path: String) : ItemFileRef(originalID) {
|
||||
override var refPath = path
|
||||
override var refModuleName = module
|
||||
override val isDynamic = false
|
||||
@Transient override var ref = ModMgr.getFile(refModuleName, refPath)
|
||||
override var mediumIdentifier = "music_disc"
|
||||
}
|
||||
|
||||
init {
|
||||
val meta = MusicDiscHelper.getMetadata(getAsGdxFile())
|
||||
name = meta.title
|
||||
author = meta.author
|
||||
}
|
||||
}
|
||||
|
||||
class MusicDisc01(originalID: ItemID) : MusicDiscPrototype(originalID, "basegame", "audio/music/discs/01 Thousands of Shards.ogg")
|
||||
class MusicDisc02(originalID: ItemID) : MusicDiscPrototype(originalID, "basegame", "audio/music/discs/02 Glitter.ogg")
|
||||
class MusicDisc03(originalID: ItemID) : MusicDiscPrototype(originalID, "basegame", "audio/music/discs/03 Digital Foliage.ogg")
|
||||
class MusicDisc04(originalID: ItemID) : MusicDiscPrototype(originalID, "basegame", "audio/music/discs/04 HDMA.ogg")
|
||||
class MusicDisc05(originalID: ItemID) : MusicDiscPrototype(originalID, "basegame", "audio/music/discs/05 Welded.ogg")
|
||||
class MusicDisc06(originalID: ItemID) : MusicDiscPrototype(originalID, "basegame", "audio/music/discs/06 Cyllindrical.ogg")
|
||||
class MusicDisc07(originalID: ItemID) : MusicDiscPrototype(originalID, "basegame", "audio/music/discs/07 Plastic Pop.ogg")
|
||||
class MusicDisc08(originalID: ItemID) : MusicDiscPrototype(originalID, "basegame", "audio/music/discs/08 Gateway 509.ogg")
|
||||
|
||||
@@ -55,7 +55,7 @@ class UIJukebox : UICanvas(
|
||||
listOf(transitionalDiscInventory)
|
||||
)
|
||||
|
||||
internal val discInventory: Array<ItemID?>
|
||||
internal val discInventory: ArrayList<ItemID>
|
||||
get() = parent.discInventory
|
||||
|
||||
init {
|
||||
|
||||
@@ -4,10 +4,7 @@ import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.OrthographicCamera
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.App.printdbg
|
||||
import net.torvald.terrarum.gameitems.GameItem
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.ActorInventory
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.IngamePlayer
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.InventoryPair
|
||||
import net.torvald.terrarum.modulebasegame.gameitems.ItemFileRef
|
||||
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellCommonRes.defaultInventoryCellTheme
|
||||
@@ -59,14 +56,9 @@ class UIJukeboxInventory(val parent: UIJukebox) : UICanvas() {
|
||||
|
||||
// remove the disc
|
||||
fixtureDiscCell[index].item = null
|
||||
parent.discInventory[index] = null
|
||||
parent.discInventory.removeAt(index)
|
||||
playerInventory.add(gameItem)
|
||||
|
||||
// shift discs
|
||||
for (i in index + 1 until SLOT_SIZE) {
|
||||
parent.discInventory[i - 1] = parent.discInventory[i]
|
||||
}
|
||||
parent.discInventory[SLOT_SIZE - 1] = null
|
||||
|
||||
rebuild()
|
||||
}
|
||||
@@ -79,12 +71,9 @@ class UIJukeboxInventory(val parent: UIJukebox) : UICanvas() {
|
||||
|
||||
private val playerInventoryUI = UITemplateHalfInventory(this, false).also {
|
||||
it.itemListTouchDownFun = { gameItem, _, _, _, _ ->
|
||||
val currentFreeSlot = parent.discInventory.filterNotNull().size
|
||||
|
||||
if (operatedByTheInstaller && currentFreeSlot < SLOT_SIZE && gameItem != null) {
|
||||
fixtureDiscCell[currentFreeSlot].item = gameItem
|
||||
fixtureDiscCell[currentFreeSlot].itemImage = gameItem.itemImage
|
||||
parent.discInventory[currentFreeSlot] = gameItem.dynamicID
|
||||
if (operatedByTheInstaller && parent.discInventory.size < SLOT_SIZE && gameItem != null) {
|
||||
parent.discInventory.add(gameItem.dynamicID)
|
||||
playerInventory.remove(gameItem)
|
||||
|
||||
rebuild()
|
||||
@@ -119,6 +108,19 @@ class UIJukeboxInventory(val parent: UIJukebox) : UICanvas() {
|
||||
|
||||
private fun rebuild() {
|
||||
playerInventoryUI.rebuild(playerInventoryFilterFun)
|
||||
|
||||
for (index in 0 until SLOT_SIZE) {
|
||||
if (index in parent.discInventory.indices) {
|
||||
val itemID = parent.discInventory[index]
|
||||
val gameItem = ItemCodex[itemID]
|
||||
fixtureDiscCell[index].item = gameItem
|
||||
fixtureDiscCell[index].itemImage = gameItem?.itemImage
|
||||
}
|
||||
else {
|
||||
fixtureDiscCell[index].item = null
|
||||
fixtureDiscCell[index].itemImage = null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -168,10 +170,16 @@ class UIJukeboxSonglistPanel(val parent: UIJukebox) : UICanvas() {
|
||||
fun rebuild() {
|
||||
|
||||
jukeboxPlayButtons.forEachIndexed { index, button ->
|
||||
parent.discInventory[index].let {
|
||||
val item = ItemCodex[it] as? ItemFileRef
|
||||
button.title = item?.name ?: ""
|
||||
button.artist = item?.author ?: ""
|
||||
if (index in parent.discInventory.indices) {
|
||||
parent.discInventory[index].let {
|
||||
val item = ItemCodex[it] as? ItemFileRef
|
||||
button.title = item?.name ?: ""
|
||||
button.artist = item?.author ?: ""
|
||||
}
|
||||
}
|
||||
else {
|
||||
button.title = ""
|
||||
button.artist = ""
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -235,8 +243,6 @@ class UIItemJukeboxSonglist(
|
||||
/** Custom highlight rule to highlight this button to secondary accent colour (yellow by default). Set to `null` to use default rule (which does nothing). */
|
||||
var customHighlightRule2: ((UIItemJukeboxSonglist) -> Boolean)? = null
|
||||
|
||||
var forceHighlighted = false
|
||||
|
||||
|
||||
override fun keyDown(keycode: Int): Boolean {
|
||||
keyDownFun(index, keycode, this)
|
||||
@@ -259,7 +265,8 @@ class UIItemJukeboxSonglist(
|
||||
override fun render(frameDelta: Float, batch: SpriteBatch, camera: OrthographicCamera) {
|
||||
blendNormalStraightAlpha(batch)
|
||||
|
||||
highlightToMainCol = customHighlightRuleMain?.invoke(this) ?: false || forceHighlighted
|
||||
val isPlaying = (index == (parentUI as UIJukeboxSonglistPanel).parent.parent.discCurrentlyPlaying)
|
||||
highlightToMainCol = customHighlightRuleMain?.invoke(this) ?: false || isPlaying
|
||||
highlightToSubCol = customHighlightRule2?.invoke(this) ?: false
|
||||
|
||||
// cell background
|
||||
@@ -277,13 +284,13 @@ class UIItemJukeboxSonglist(
|
||||
if (title.isNotEmpty()) {
|
||||
blendNormalStraightAlpha(batch)
|
||||
|
||||
|
||||
// if mouse is over, text lights up
|
||||
// highlight item name and count (blocks/walls) if the item is equipped
|
||||
batch.color =
|
||||
if (highlightToMainCol) colourTheme.textHighlightMainCol
|
||||
else if (highlightToSubCol) colourTheme.textHighlightSubCol
|
||||
else if (mouseUp && title.isNotEmpty()) colourTheme.textHighlightMouseUpCol
|
||||
else colourTheme.textHighlightNormalCol
|
||||
batch.color = if (highlightToMainCol) colourTheme.textHighlightMainCol
|
||||
else if (highlightToSubCol) colourTheme.textHighlightSubCol
|
||||
else if (mouseUp && title.isNotEmpty()) colourTheme.textHighlightMouseUpCol
|
||||
else colourTheme.textHighlightNormalCol
|
||||
|
||||
// draw title
|
||||
Toolkit.drawTextCentered(batch, App.fontGame, title, width, posX, posY + textOffsetY)
|
||||
|
||||
Reference in New Issue
Block a user