From 7993ccd2e5fd58e4aac19931df28641d52acfea0 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Wed, 12 Jul 2023 21:30:50 +0900 Subject: [PATCH] memory gauge on teleporter world search --- .../modulebasegame/ui/UILoadManage.kt | 5 +- .../terrarum/modulebasegame/ui/UINewWorld.kt | 15 ++-- .../modulebasegame/ui/UIWorldPortal.kt | 18 +++-- .../modulebasegame/ui/UIWorldPortalDelete.kt | 5 ++ .../modulebasegame/ui/UIWorldPortalListing.kt | 18 ++--- .../modulebasegame/ui/UIWorldPortalRename.kt | 5 +- .../modulebasegame/ui/UIWorldPortalSearch.kt | 68 ++++++++++++++++--- 7 files changed, 96 insertions(+), 38 deletions(-) diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UILoadManage.kt b/src/net/torvald/terrarum/modulebasegame/ui/UILoadManage.kt index 741daef5b..8973f74e5 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UILoadManage.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UILoadManage.kt @@ -132,7 +132,10 @@ class UILoadManage(val full: UILoadSavegame) : UICanvas() { full.playerButtonSelected?.let { button -> screencap?.texture?.tryDispose() button.savegameThumbnailPixmap?.let { - screencap = TextureRegion(Texture(it)) + Texture(it).also { + it.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear) + screencap = TextureRegion(it) + } } } } diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UINewWorld.kt b/src/net/torvald/terrarum/modulebasegame/ui/UINewWorld.kt index 058d0c8ef..0ae18449b 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UINewWorld.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UINewWorld.kt @@ -46,8 +46,8 @@ class UINewWorld(val remoCon: UIRemoCon) : UICanvas() { private val drawX = (Toolkit.drawWidth - width) / 2 private val drawY = (App.scr.height - height) / 2 - private val radioCellWidth = 116 - private val inputWidth = 340 + private val radioCellWidth = 120 + private val inputWidth = 350 private val radioX = (width - (radioCellWidth * NEW_WORLD_SIZE.size + 9)) / 2 private val inputX = width - inputWidth @@ -76,12 +76,15 @@ class UINewWorld(val remoCon: UIRemoCon) : UICanvas() { private val rng = HQRNG() + private val inputLineY1 = 90 + private val inputLineY2 = 130 + private val nameInput = UIItemTextLineInput(this, - drawX + width - inputWidth, drawY + sizeSelY + 80, inputWidth, + drawX + width - inputWidth + 5, drawY + sizeSelY + inputLineY1, inputWidth, { RandomWordsName(4) }, InputLenCap(VirtualDisk.NAME_LENGTH, InputLenCap.CharLenUnit.UTF8_BYTES)) private val seedInput = UIItemTextLineInput(this, - drawX + width - inputWidth, drawY + sizeSelY + 120, inputWidth, + drawX + width - inputWidth + 5, drawY + sizeSelY + inputLineY2, inputWidth, { rng.nextLong().toString() }, InputLenCap(256, InputLenCap.CharLenUnit.CODEPOINTS)) private val goButtonWidth = 180 @@ -161,8 +164,8 @@ class UINewWorld(val remoCon: UIRemoCon) : UICanvas() { App.fontGame.draw(batch, sizestr, drawX + (width - App.fontGame.getWidth(sizestr)).div(2).toFloat(), drawY + sizeSelY - 40f) // name/seed input labels - App.fontGame.draw(batch, Lang["MENU_NAME"], drawX, drawY + sizeSelY + 80) - App.fontGame.draw(batch, Lang["CONTEXT_GENERATOR_SEED"], drawX, drawY + sizeSelY + 120) + App.fontGame.draw(batch, Lang["MENU_NAME"], drawX - 4, drawY + sizeSelY + inputLineY1) + App.fontGame.draw(batch, Lang["CONTEXT_GENERATOR_SEED"], drawX - 4, drawY + sizeSelY + inputLineY2) uiItems.forEach { it.render(batch, camera) } } diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIWorldPortal.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIWorldPortal.kt index 9b0b9333c..291a6ba5f 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIWorldPortal.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIWorldPortal.kt @@ -40,6 +40,13 @@ class UIWorldPortal : UICanvas( internal lateinit var host: FixtureWorldPortal + init { + CommonResourcePool.addToLoadingList("terrarum-basegame-worldportalicons") { + TextureRegionPack(ModMgr.getGdxFile("basegame", "gui/worldportal_catbar.tga"), 30, 20) + } + CommonResourcePool.loadAll() + } + val controlHelpHeight = App.fontGame.lineHeight @@ -54,6 +61,10 @@ class UIWorldPortal : UICanvas( "$SP${App.gamepadLabelRT} ${Lang["GAME_INVENTORY"]}" + + internal var chunksUsed = 0 + internal val chunksMax = 100000 + val transitionalSearch = UIWorldPortalSearch(this) val transitionalListing = UIWorldPortalListing(this) val transitionalDelete = UIWorldPortalDelete(this) @@ -251,13 +262,6 @@ class UIItemWorldPortalTopBar( override val width = 580 override val height = 25 - init { - CommonResourcePool.addToLoadingList("terrarum-basegame-worldportalicons") { - TextureRegionPack(ModMgr.getGdxFile("basegame", "gui/worldportal_catbar.tga"), 30, 20) - } - CommonResourcePool.loadAll() - } - private val genericIcons: TextureRegionPack = CommonResourcePool.getAsTextureRegionPack("inventory_category") private val icons = CommonResourcePool.getAsTextureRegionPack("terrarum-basegame-worldportalicons") /*private val catIconImages = listOf( diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIWorldPortalDelete.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIWorldPortalDelete.kt index 0f9684016..8b0fcada3 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIWorldPortalDelete.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIWorldPortalDelete.kt @@ -61,6 +61,11 @@ class UIWorldPortalDelete(private val full: UIWorldPortal) : UICanvas() { // Toolkit.drawTextCentered(batch, App.fontGame, Lang["MENU_LABEL_SAVE_WILL_BE_DELETED"], Toolkit.drawWidth, 0, (App.scr.tvSafeGraphicsHeight + 172 + 36) - 46) Toolkit.drawTextCentered(batch, App.fontGame, Lang["MENU_LABEL_ARE_YOU_SURE"], Toolkit.drawWidth, 0, (App.scr.tvSafeGraphicsHeight + 172 + 36) + UIItemWorldCellsSimple.height + 36) + + + // control hints + batch.color = Color.WHITE + App.fontGame.draw(batch, full.portalListingControlHelp, (Toolkit.drawWidth - width)/2 + 2, (full.yEnd - 20).toInt()) } override fun dispose() { diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIWorldPortalListing.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIWorldPortalListing.kt index 6e5803087..c7d44de50 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIWorldPortalListing.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIWorldPortalListing.kt @@ -167,11 +167,6 @@ class UIWorldPortalListing(val full: UIWorldPortal) : UICanvas() { private var currentWorldSelected = false init { - CommonResourcePool.addToLoadingList("terrarum-basegame-worldportalicons") { - TextureRegionPack(ModMgr.getGdxFile("basegame", "gui/worldportal_catbar.tga"), 30, 20) - } - CommonResourcePool.loadAll() - navRemoCon.scrollUpListener = { _,_ -> scrollItemPage(-1) } navRemoCon.scrollDownListener = { _,_ -> scrollItemPage(1) } @@ -229,13 +224,10 @@ class UIWorldPortalListing(val full: UIWorldPortal) : UICanvas() { }.let { worldList.addAll(it) } - chunksUsed = worldList.sumOf { it.dimensionInChunks } + full.chunksUsed = worldList.sumOf { it.dimensionInChunks } listPageCount = ceil(worldList.size.toDouble() / listCount).toInt() } - private var chunksUsed = 0 - private val chunksMax = 100000 - private lateinit var worldCells: Array private var selected: UIItemWorldCellsSimple? = null @@ -365,11 +357,11 @@ class UIWorldPortalListing(val full: UIWorldPortal) : UICanvas() { // memory gauge - val barCol = UIItemInventoryCellCommonRes.getHealthMeterColour(chunksMax - chunksUsed, 0, chunksMax) + val barCol = UIItemInventoryCellCommonRes.getHealthMeterColour(full.chunksMax - full.chunksUsed, 0, full.chunksMax) val barBack = barCol mul UIItemInventoryCellCommonRes.meterBackDarkening batch.color = Toolkit.Theme.COL_CELL_FILL - Toolkit.fillArea(batch, (memoryGaugeXpos - iconSizeGap + 10).toInt(), memoryGaugeYpos, buttonHeight + 6, buttonHeight) + Toolkit.fillArea(batch, (memoryGaugeXpos - iconSizeGap + 10).toInt(), memoryGaugeYpos, buttonHeight + 5, buttonHeight) batch.color = Toolkit.Theme.COL_INACTIVE Toolkit.drawBoxBorder(batch, (memoryGaugeXpos - iconSizeGap + 10).toInt() - 1, memoryGaugeYpos - 1, buttonHeight + 7, buttonHeight + 2) batch.color = Color.WHITE @@ -380,7 +372,7 @@ class UIWorldPortalListing(val full: UIWorldPortal) : UICanvas() { batch.color = barBack Toolkit.fillArea(batch, memoryGaugeXpos, memoryGaugeYpos, memoryGaugeWidth, buttonHeight) batch.color = barCol - Toolkit.fillArea(batch, memoryGaugeXpos, memoryGaugeYpos, (memoryGaugeWidth * (chunksUsed / chunksMax.toFloat())).ceilToInt(), buttonHeight) + Toolkit.fillArea(batch, memoryGaugeXpos, memoryGaugeYpos, (memoryGaugeWidth * (full.chunksUsed / full.chunksMax.toFloat())).ceilToInt(), buttonHeight) batch.color = Color.WHITE if (selected?.worldInfo != null) { @@ -397,7 +389,7 @@ class UIWorldPortalListing(val full: UIWorldPortal) : UICanvas() { App.fontGame.draw(batch, str, textXpos + 6f, y + thumbh + 3+10 + textualListHeight * index - 2f) } // size indicator on the memory gauge - Toolkit.fillArea(batch, memoryGaugeXpos, memoryGaugeYpos, (memoryGaugeWidth * (selected?.worldInfo!!.dimensionInChunks / chunksMax.toFloat())).ceilToInt(), buttonHeight) + Toolkit.fillArea(batch, memoryGaugeXpos, memoryGaugeYpos, (memoryGaugeWidth * (selected?.worldInfo!!.dimensionInChunks / full.chunksMax.toFloat())).ceilToInt(), buttonHeight) // thumbnail selected?.worldInfo?.screenshot?.let { diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIWorldPortalRename.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIWorldPortalRename.kt index 9330a9508..976ad09bd 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIWorldPortalRename.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIWorldPortalRename.kt @@ -80,8 +80,11 @@ class UIWorldPortalRename(private val full: UIWorldPortal) : UICanvas() { it.render(batch, camera, buttonXdelta, buttonYdelta) } - uiItems.forEach { it.render(batch, camera) } + // control hints + batch.color = Color.WHITE + App.fontGame.draw(batch, full.portalListingControlHelp, (Toolkit.drawWidth - width)/2 + 2, (full.yEnd - 20).toInt()) + uiItems.forEach { it.render(batch, camera) } oldPosX = posX } diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIWorldPortalSearch.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIWorldPortalSearch.kt index 9fd478606..d4b66e5db 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIWorldPortalSearch.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIWorldPortalSearch.kt @@ -7,9 +7,7 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.g2d.TextureRegion import net.torvald.random.HQRNG import net.torvald.random.XXHash64 -import net.torvald.terrarum.App -import net.torvald.terrarum.ModMgr -import net.torvald.terrarum.Terrarum +import net.torvald.terrarum.* import net.torvald.terrarum.gamecontroller.TerrarumKeyboardEvent import net.torvald.terrarum.langpack.Lang import net.torvald.terrarum.modulebasegame.TerrarumIngame @@ -18,6 +16,7 @@ import net.torvald.terrarum.modulebasegame.gameactors.FixtureWorldPortal import net.torvald.terrarum.modulebasegame.gameactors.IngamePlayer import net.torvald.terrarum.modulebasegame.serialise.ReadActor import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.INVENTORY_CELLS_OFFSET_Y +import net.torvald.terrarum.realestate.LandUtil import net.torvald.terrarum.savegame.ByteArray64Reader import net.torvald.terrarum.savegame.VDFileID import net.torvald.terrarum.savegame.VirtualDisk @@ -48,8 +47,8 @@ class UIWorldPortalSearch(val full: UIWorldPortal) : UICanvas() { private val drawX = (Toolkit.drawWidth - width) / 2 private val drawY = (App.scr.height - height) / 2 - private val radioCellWidth = 116 - private val inputWidth = 340 + private val radioCellWidth = 120 + private val inputWidth = 350 private val radioX = (width - (radioCellWidth * tex.size + 9)) / 2 private val sizeSelY = 186 + 40 @@ -66,13 +65,16 @@ class UIWorldPortalSearch(val full: UIWorldPortal) : UICanvas() { private val rng = HQRNG() + private val inputLineY1 = 90 + private val inputLineY2 = 130 + private val nameInput = UIItemTextLineInput(this, - drawX + width - inputWidth, drawY + sizeSelY + 80, inputWidth, + drawX + width - inputWidth + 5, drawY + sizeSelY + inputLineY1, inputWidth, { RandomWordsName(4) }, InputLenCap(VirtualDisk.NAME_LENGTH, InputLenCap.CharLenUnit.UTF8_BYTES) ) private val seedInput = UIItemTextLineInput(this, - drawX + width - inputWidth, drawY + sizeSelY + 120, inputWidth, + drawX + width - inputWidth + 5, drawY + sizeSelY + inputLineY2, inputWidth, { rng.nextLong().toString() }, InputLenCap(256, InputLenCap.CharLenUnit.CODEPOINTS) ) @@ -123,7 +125,20 @@ class UIWorldPortalSearch(val full: UIWorldPortal) : UICanvas() { uiItems.forEach { it.update(delta) } } + + private val memoryGaugeWidth = radioCellWidth * 4 + 3 * 3 + private val hx = Toolkit.drawWidth.div(2) + private val iconGap = 12f + private val iconSize = 30f + private val iconSizeGap = iconSize + iconGap + private val buttonHeight = 24 + val icons = CommonResourcePool.getAsTextureRegionPack("terrarum-basegame-worldportalicons") + + override fun renderUI(batch: SpriteBatch, camera: Camera) { + val memoryGaugeXpos = hx - memoryGaugeWidth/2 + val memoryGaugeYpos = drawY + sizeSelY + buttonHeight + 10 + val textXpos = memoryGaugeXpos + 3 val posXDelta = posX - oldPosX // ugh why won't you just scroll along?? @@ -152,12 +167,45 @@ class UIWorldPortalSearch(val full: UIWorldPortal) : UICanvas() { App.fontGame.draw(batch, sizestr, drawX + (width - App.fontGame.getWidth(sizestr)).div(2).toFloat(), drawY + sizeSelY - 40f) // name/seed input labels - App.fontGame.draw(batch, Lang["MENU_NAME"], drawX, drawY + sizeSelY + 80) - App.fontGame.draw(batch, Lang["CONTEXT_PLACE_COORDINATE"], drawX, drawY + sizeSelY + 120) + App.fontGame.draw(batch, Lang["MENU_NAME"], drawX - 4, drawY + sizeSelY + inputLineY1) + App.fontGame.draw(batch, Lang["CONTEXT_PLACE_COORDINATE"], drawX - 4, drawY + sizeSelY + inputLineY2) + + + // memory gauge + val chunksUsed = full.chunksUsed + val barCol = UIItemInventoryCellCommonRes.getHealthMeterColour(full.chunksMax - chunksUsed, 0, full.chunksMax) + val barBack = barCol mul UIItemInventoryCellCommonRes.meterBackDarkening + val (wx, wy) = TerrarumIngame.WORLDPORTAL_NEW_WORLD_SIZE[sizeSelector.selection] + val selectedSizeChunks = (wx / LandUtil.CHUNK_W) * (wy / LandUtil.CHUNK_H) + val gaugeUsedWidth = (memoryGaugeWidth * (chunksUsed / full.chunksMax.toFloat())).ceilToInt() + val gaugeEstimatedFullWidth = (memoryGaugeWidth * ((chunksUsed + selectedSizeChunks) / full.chunksMax.toFloat())).ceilToInt() + val gaugeExtraWidth = (gaugeEstimatedFullWidth - gaugeUsedWidth)//.coerceIn(0 .. (memoryGaugeWidth - gaugeUsedWidth)) // deliberately NOT coercing + + // memory icon + batch.color = Toolkit.Theme.COL_CELL_FILL + Toolkit.fillArea(batch, (memoryGaugeXpos - iconSizeGap + 10).toInt(), memoryGaugeYpos, buttonHeight + 5, buttonHeight) + batch.color = Toolkit.Theme.COL_INACTIVE + Toolkit.drawBoxBorder(batch, (memoryGaugeXpos - iconSizeGap + 10).toInt() - 1, memoryGaugeYpos - 1, buttonHeight + 7, buttonHeight + 2) + batch.color = Color.WHITE + batch.draw(icons.get(2, 2), textXpos - iconSizeGap, memoryGaugeYpos + 2f) + // the gauge + batch.color = barBack + Toolkit.fillArea(batch, memoryGaugeXpos, memoryGaugeYpos, memoryGaugeWidth, buttonHeight) + batch.color = barCol + Toolkit.fillArea(batch, memoryGaugeXpos, memoryGaugeYpos, gaugeUsedWidth, buttonHeight) + // extra gauge to show estimated memory usage + batch.color = Color.WHITE + Toolkit.fillArea(batch, memoryGaugeXpos + gaugeUsedWidth, memoryGaugeYpos, gaugeExtraWidth, buttonHeight) + // gauge border + batch.color = Toolkit.Theme.COL_INACTIVE + Toolkit.drawBoxBorder(batch, memoryGaugeXpos - 1, memoryGaugeYpos - 1, memoryGaugeWidth + 2, buttonHeight + 2) + + // control hints + batch.color = Color.WHITE + App.fontGame.draw(batch, full.portalListingControlHelp, (Toolkit.drawWidth - width)/2 + 2, (full.yEnd - 20).toInt()) uiItems.forEach { it.render(batch, camera) } - oldPosX = posX }