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