mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-08 12:51:51 +09:00
inventory grid mode buttons working highlight
This commit is contained in:
@@ -7,6 +7,7 @@ import net.torvald.terrarum.itemproperties.GameItem
|
||||
import net.torvald.terrarum.itemproperties.ItemCodex
|
||||
import net.torvald.terrarum.blockproperties.BlockCodex
|
||||
import net.torvald.terrarum.langpack.Lang
|
||||
import net.torvald.terrarum.utils.JsonFetcher
|
||||
import org.apache.commons.csv.CSVFormat
|
||||
import org.apache.commons.csv.CSVParser
|
||||
import java.io.File
|
||||
@@ -35,6 +36,8 @@ object ModMgr {
|
||||
val groovyEngine = ScriptEngineManager().getEngineByExtension("groovy")!!
|
||||
val groovyInvocable = groovyEngine as Invocable
|
||||
|
||||
val metaFilename = "metadata.properties"
|
||||
val defaultConfigFilename = "default.json"
|
||||
|
||||
data class ModuleMetadata(
|
||||
val order: Int,
|
||||
@@ -74,7 +77,16 @@ object ModMgr {
|
||||
|
||||
try {
|
||||
val modMetadata = Properties()
|
||||
modMetadata.load(FileInputStream("$modDir/$moduleName/metadata.properties"))
|
||||
modMetadata.load(FileInputStream("$modDir/$moduleName/$metaFilename"))
|
||||
|
||||
if (File("$modDir/$moduleName/$defaultConfigFilename").exists()) {
|
||||
val defaultConfig = JsonFetcher("$modDir/$moduleName/$defaultConfigFilename")
|
||||
// read config and store it to the game
|
||||
|
||||
// write to user's config file
|
||||
}
|
||||
|
||||
|
||||
|
||||
val properName = modMetadata.getProperty("propername")
|
||||
val description = modMetadata.getProperty("description")
|
||||
|
||||
@@ -106,15 +106,58 @@ class UIItemInventoryDynamicList(
|
||||
}
|
||||
)
|
||||
|
||||
private val items: Array<UIItemInventoryCellBase>
|
||||
get() = if (catArrangement[selection] in compactViewCat) itemGrid else itemList
|
||||
private var items: Array<UIItemInventoryCellBase>
|
||||
= if (catArrangement[selection] in compactViewCat) itemGrid else itemList // this is INIT code
|
||||
|
||||
var isCompactView = (catArrangement[selection] in compactViewCat) // this is INIT code
|
||||
set(value) {
|
||||
items = if (value) itemGrid else itemList
|
||||
|
||||
rebuild()
|
||||
|
||||
field = value
|
||||
}
|
||||
|
||||
private val gridModeButtons = Array<UIItemImageButton>(2, { index ->
|
||||
val iconPosX = posX - 12 - parentUI.catIcons.tileW + 2
|
||||
val iconPosY = posY - 2 + (4 + UIItemInventoryElem.height - parentUI.catIcons.tileH) * index
|
||||
|
||||
UIItemImageButton(
|
||||
parentUI,
|
||||
parentUI.catIcons.get(index + 14, 0),
|
||||
activeBackCol = Color(0),
|
||||
activeBackBlendMode = BlendMode.NORMAL,
|
||||
posX = iconPosX,
|
||||
posY = iconPosY,
|
||||
highlightable = true
|
||||
)
|
||||
})
|
||||
|
||||
init {
|
||||
// initially highlight grid mode buttons
|
||||
gridModeButtons[if (isCompactView) 1 else 0].highlighted = true
|
||||
|
||||
|
||||
gridModeButtons[0].touchDownListener = { _, _, _, _ ->
|
||||
isCompactView = false
|
||||
gridModeButtons[0].highlighted = true
|
||||
gridModeButtons[1].highlighted = false
|
||||
}
|
||||
gridModeButtons[1].touchDownListener = { _, _, _, _ ->
|
||||
isCompactView = true
|
||||
gridModeButtons[0].highlighted = false
|
||||
gridModeButtons[1].highlighted = true
|
||||
}
|
||||
|
||||
// if (is.mouseUp) handled by this.touchDown()
|
||||
}
|
||||
|
||||
|
||||
override fun render(batch: SpriteBatch, camera: Camera) {
|
||||
|
||||
items.forEach { it.render(batch, camera) }
|
||||
|
||||
gridModeButtons.forEach { it.render(batch, camera) }
|
||||
|
||||
super.render(batch, camera)
|
||||
}
|
||||
@@ -124,6 +167,8 @@ class UIItemInventoryDynamicList(
|
||||
super.update(delta)
|
||||
|
||||
items.forEach { it.update(delta) }
|
||||
|
||||
gridModeButtons.forEach { it.update(delta) }
|
||||
}
|
||||
|
||||
|
||||
@@ -190,12 +235,14 @@ class UIItemInventoryDynamicList(
|
||||
override fun dispose() {
|
||||
itemList.forEach { it.dispose() }
|
||||
itemGrid.forEach { it.dispose() }
|
||||
gridModeButtons.forEach { it.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) }
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user