mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-13 12:04:06 +09:00
list scroll for portallisting
This commit is contained in:
@@ -17,7 +17,7 @@ import net.torvald.terrarum.ui.UIItemImageButton
|
|||||||
class UIItemListNavBarVertical(
|
class UIItemListNavBarVertical(
|
||||||
parentUI: UICanvas, initialX: Int, initialY: Int,
|
parentUI: UICanvas, initialX: Int, initialY: Int,
|
||||||
override val height: Int,
|
override val height: Int,
|
||||||
hasGridModeButtons: Boolean, initialModeSelection: Int = 0,
|
val hasGridModeButtons: Boolean, initialModeSelection: Int = 0,
|
||||||
private val colourTheme: InventoryCellColourTheme = UIItemInventoryCellCommonRes.defaultInventoryCellTheme,
|
private val colourTheme: InventoryCellColourTheme = UIItemInventoryCellCommonRes.defaultInventoryCellTheme,
|
||||||
var extraDrawOpOnBottom: (UIItemListNavBarVertical, SpriteBatch) -> Unit = { _,_ -> }
|
var extraDrawOpOnBottom: (UIItemListNavBarVertical, SpriteBatch) -> Unit = { _,_ -> }
|
||||||
) : UIItem(parentUI, initialX, initialY) {
|
) : UIItem(parentUI, initialX, initialY) {
|
||||||
@@ -130,7 +130,7 @@ class UIItemListNavBarVertical(
|
|||||||
batch.color = colourTheme.cellHighlightNormalCol
|
batch.color = colourTheme.cellHighlightNormalCol
|
||||||
Toolkit.drawBoxBorder(batch, iconPosX - 4, getIconPosY(0) - 8, width, height)
|
Toolkit.drawBoxBorder(batch, iconPosX - 4, getIconPosY(0) - 8, width, height)
|
||||||
|
|
||||||
gridModeButtons.forEach { it.render(batch, camera) }
|
if (hasGridModeButtons) gridModeButtons.forEach { it.render(batch, camera) }
|
||||||
scrollUpButton.render(batch, camera)
|
scrollUpButton.render(batch, camera)
|
||||||
scrollDownButton.render(batch, camera)
|
scrollDownButton.render(batch, camera)
|
||||||
|
|
||||||
@@ -155,7 +155,7 @@ class UIItemListNavBarVertical(
|
|||||||
|
|
||||||
override fun update(delta: Float) {
|
override fun update(delta: Float) {
|
||||||
|
|
||||||
gridModeButtons.forEach { it.update(delta) }
|
if (hasGridModeButtons) gridModeButtons.forEach { it.update(delta) }
|
||||||
scrollUpButton.update(delta)
|
scrollUpButton.update(delta)
|
||||||
scrollDownButton.update(delta)
|
scrollDownButton.update(delta)
|
||||||
|
|
||||||
@@ -163,7 +163,7 @@ class UIItemListNavBarVertical(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
|
override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
|
||||||
gridModeButtons.forEach { if (it.mouseUp) it.touchDown(screenX, screenY, pointer, button) }
|
if (hasGridModeButtons) gridModeButtons.forEach { if (it.mouseUp) it.touchDown(screenX, screenY, pointer, button) }
|
||||||
if (scrollUpButton.mouseUp) scrollUpButton.touchDown(screenX, screenY, pointer, button)
|
if (scrollUpButton.mouseUp) scrollUpButton.touchDown(screenX, screenY, pointer, button)
|
||||||
if (scrollDownButton.mouseUp) scrollDownButton.touchDown(screenX, screenY, pointer, button)
|
if (scrollDownButton.mouseUp) scrollDownButton.touchDown(screenX, screenY, pointer, button)
|
||||||
return super.touchDown(screenX, screenY, pointer, button)
|
return super.touchDown(screenX, screenY, pointer, button)
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import com.badlogic.gdx.graphics.g2d.TextureRegion
|
|||||||
import com.badlogic.gdx.utils.GdxRuntimeException
|
import com.badlogic.gdx.utils.GdxRuntimeException
|
||||||
import net.torvald.terrarum.*
|
import net.torvald.terrarum.*
|
||||||
import net.torvald.terrarum.gameactors.AVKey
|
import net.torvald.terrarum.gameactors.AVKey
|
||||||
|
import net.torvald.terrarum.gameworld.fmod
|
||||||
import net.torvald.terrarum.langpack.Lang
|
import net.torvald.terrarum.langpack.Lang
|
||||||
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.INVENTORY_CELLS_OFFSET_Y
|
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.INVENTORY_CELLS_OFFSET_Y
|
||||||
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.getCellCountVertically
|
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.getCellCountVertically
|
||||||
@@ -28,6 +29,7 @@ import java.time.Instant
|
|||||||
import java.time.format.DateTimeFormatter
|
import java.time.format.DateTimeFormatter
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import java.util.zip.GZIPInputStream
|
import java.util.zip.GZIPInputStream
|
||||||
|
import kotlin.math.ceil
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by minjaesong on 2023-05-19.
|
* Created by minjaesong on 2023-05-19.
|
||||||
@@ -98,6 +100,8 @@ class UIWorldPortalListing(val full: UIWorldPortal) : UICanvas() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val navRemoCon = UIItemListNavBarVertical(full, hx + 6 + UIItemWorldCellsSimple.width, y + 7, listHeight, false)
|
||||||
|
|
||||||
private val worldList = ArrayList<WorldInfo>()
|
private val worldList = ArrayList<WorldInfo>()
|
||||||
data class WorldInfo(
|
data class WorldInfo(
|
||||||
val uuid: UUID,
|
val uuid: UUID,
|
||||||
@@ -119,23 +123,21 @@ class UIWorldPortalListing(val full: UIWorldPortal) : UICanvas() {
|
|||||||
}
|
}
|
||||||
CommonResourcePool.loadAll()
|
CommonResourcePool.loadAll()
|
||||||
|
|
||||||
|
navRemoCon.scrollUpListener = { _,_ -> scrollItemPage(-1) }
|
||||||
|
navRemoCon.scrollDownListener = { _,_ -> scrollItemPage(1) }
|
||||||
|
|
||||||
addUIitem(buttonRenameWorld)
|
addUIitem(buttonRenameWorld)
|
||||||
addUIitem(buttonDeleteWorld)
|
addUIitem(buttonDeleteWorld)
|
||||||
addUIitem(buttonTeleport)
|
addUIitem(buttonTeleport)
|
||||||
addUIitem(buttonCancel)
|
addUIitem(buttonCancel)
|
||||||
|
addUIitem(navRemoCon)
|
||||||
}
|
}
|
||||||
|
|
||||||
private var chunksUsed = 0
|
fun scrollItemPage(relativeAmount: Int) {
|
||||||
private val chunksMax = 100000
|
listPage = if (listPageCount == 0) 0 else (listPage + relativeAmount).fmod(listPageCount)
|
||||||
|
}
|
||||||
|
|
||||||
private lateinit var worldCells: Array<UIItemWorldCellsSimple>
|
private fun readWorldList() {
|
||||||
|
|
||||||
private var selected: UIItemWorldCellsSimple? = null
|
|
||||||
private var selectedIndex: Int? = null
|
|
||||||
|
|
||||||
override fun show() {
|
|
||||||
worldList.clear()
|
worldList.clear()
|
||||||
(INGAME.actorGamer.actorValue.getAsString(AVKey.WORLD_PORTAL_DICT) ?: "").split(",").filter { it.isNotBlank() }.map {
|
(INGAME.actorGamer.actorValue.getAsString(AVKey.WORLD_PORTAL_DICT) ?: "").split(",").filter { it.isNotBlank() }.map {
|
||||||
it.ascii85toUUID().let { it to App.savegameWorlds[it] }
|
it.ascii85toUUID().let { it to App.savegameWorlds[it] }
|
||||||
@@ -175,16 +177,38 @@ class UIWorldPortalListing(val full: UIWorldPortal) : UICanvas() {
|
|||||||
}.let {
|
}.let {
|
||||||
worldList.addAll(it)
|
worldList.addAll(it)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
chunksUsed = worldList.sumOf { it.dimensionInChunks }
|
chunksUsed = worldList.sumOf { it.dimensionInChunks }
|
||||||
|
listPageCount = ceil(worldList.size.toDouble() / listCount).toInt()
|
||||||
|
}
|
||||||
|
|
||||||
worldCells = Array(maxOf(worldList.size, listCount)) {
|
private var chunksUsed = 0
|
||||||
|
private val chunksMax = 100000
|
||||||
|
|
||||||
|
private lateinit var worldCells: Array<UIItemWorldCellsSimple>
|
||||||
|
|
||||||
|
private var selected: UIItemWorldCellsSimple? = null
|
||||||
|
private var selectedIndex: Int? = null
|
||||||
|
|
||||||
|
var listPage
|
||||||
|
set(value) {
|
||||||
|
navRemoCon.itemPage = if (listPageCount == 0) 0 else (value).fmod(listPageCount)
|
||||||
|
rebuildList()
|
||||||
|
}
|
||||||
|
get() = navRemoCon.itemPage
|
||||||
|
|
||||||
|
var listPageCount // TODO total size of current category / items.size
|
||||||
|
protected set(value) {
|
||||||
|
navRemoCon.itemPageCount = value
|
||||||
|
}
|
||||||
|
get() = navRemoCon.itemPageCount
|
||||||
|
|
||||||
|
private fun rebuildList() {
|
||||||
|
worldCells = Array(listCount) { it0 ->
|
||||||
|
val it = it0 + listCount * listPage
|
||||||
UIItemWorldCellsSimple(
|
UIItemWorldCellsSimple(
|
||||||
this,
|
this,
|
||||||
hx + gridGap / 2,
|
hx + gridGap / 2,
|
||||||
y + (gridGap + UIItemWorldCellsSimple.height) * it,
|
y + (gridGap + UIItemWorldCellsSimple.height) * it0,
|
||||||
worldList.getOrNull(it),
|
worldList.getOrNull(it),
|
||||||
worldList.getOrNull(it)?.diskSkimmer?.getDiskName(Common.CHARSET)
|
worldList.getOrNull(it)?.diskSkimmer?.getDiskName(Common.CHARSET)
|
||||||
).also { button ->
|
).also { button ->
|
||||||
@@ -195,6 +219,14 @@ class UIWorldPortalListing(val full: UIWorldPortal) : UICanvas() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun show() {
|
||||||
|
listPage = 0
|
||||||
|
|
||||||
|
readWorldList()
|
||||||
|
|
||||||
|
rebuildList()
|
||||||
|
|
||||||
uiItems.forEach { it.show() }
|
uiItems.forEach { it.show() }
|
||||||
worldCells.forEach { it.show() }
|
worldCells.forEach { it.show() }
|
||||||
@@ -358,11 +390,21 @@ class UIWorldPortalListing(val full: UIWorldPortal) : UICanvas() {
|
|||||||
}
|
}
|
||||||
else return false
|
else return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun scrolled(amountX: Float, amountY: Float): Boolean {
|
||||||
|
if (this.isVisible) {
|
||||||
|
uiItems.forEach { it.scrolled(amountX, amountY) }
|
||||||
|
worldCells.forEach { it.scrolled(amountX, amountY) }
|
||||||
|
handler.subUIs.forEach { it.scrolled(amountX, amountY) }
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
else return false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class UIItemWorldCellsSimple(
|
class UIItemWorldCellsSimple(
|
||||||
parent: UIWorldPortalListing,
|
val parent: UIWorldPortalListing,
|
||||||
initialX: Int,
|
initialX: Int,
|
||||||
initialY: Int,
|
initialY: Int,
|
||||||
internal val worldInfo: UIWorldPortalListing.WorldInfo? = null,
|
internal val worldInfo: UIWorldPortalListing.WorldInfo? = null,
|
||||||
@@ -423,6 +465,15 @@ class UIItemWorldCellsSimple(
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun scrolled(amountX: Float, amountY: Float): Boolean {
|
||||||
|
|
||||||
|
if (mouseUp) {
|
||||||
|
parent.scrollItemPage(amountY.toInt())
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
override fun dispose() {
|
override fun dispose() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user