replacing min/max usage with kotlin's

This commit is contained in:
minjaesong
2023-07-11 01:54:46 +09:00
parent d96b7d1b84
commit 79f19120f2
66 changed files with 308 additions and 345 deletions

View File

@@ -8,6 +8,7 @@ import net.torvald.terrarum.Second
import net.torvald.terrarum.blendNormalStraightAlpha
import net.torvald.terrarum.ui.Toolkit
import net.torvald.terrarum.ui.UICanvas
import kotlin.math.max
/**
* Created by minjaesong on 2016-01-23.
@@ -56,7 +57,7 @@ class Notification : UICanvas() {
App.fontGame.getWidth(message[0])
else
message.map { App.fontGame.getWidth(it) }.sorted().last()
val displayedTextWidth = maxOf(240, realTextWidth)
val displayedTextWidth = max(240, realTextWidth)
// force the UI to the centre of the screen
this.posX = (App.scr.width - displayedTextWidth) / 2

View File

@@ -21,6 +21,8 @@ import net.torvald.terrarum.ui.UIItemSpinner
import net.torvald.terrarum.ui.UIItemTextButton
import net.torvald.unicode.getKeycapPC
import kotlin.math.ceil
import kotlin.math.max
import kotlin.math.min
/**
* This UI has inventory, but it's just there to display all craftable items and should not be serialised.
@@ -498,7 +500,7 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(), HasInventory {
if (full.actor.inventory.capacityMode == FixtureInventory.CAPACITY_MODE_NO_ENCUMBER)
1f
else // make sure 1px is always be seen
minOf(UIInventoryCells.weightBarWidth, maxOf(1f, UIInventoryCells.weightBarWidth * encumbrancePerc)),
min(UIInventoryCells.weightBarWidth, max(1f, UIInventoryCells.weightBarWidth * encumbrancePerc)),
UIInventoryFull.controlHelpHeight - 6f
)
// debug text

View File

@@ -7,10 +7,8 @@ import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.App
import net.torvald.terrarum.CommonResourcePool
import net.torvald.terrarum.INGAME
import net.torvald.terrarum.ceilInt
import net.torvald.terrarum.ceilToInt
import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.CELL_COL
import net.torvald.terrarum.ui.*
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
import net.torvald.unicode.TIMES
@@ -214,7 +212,7 @@ class UIGraphicsControlPanel(remoCon: UIRemoCon?) : UICanvas() {
batch.color = Toolkit.Theme.COL_MOUSE_UP
Toolkit.drawBoxBorder(batch, xstart + 1, 1, App.scr.chatWidth - 2, App.scr.height - 2)
val overlayResTxt = "${(App.scr.chatWidth * App.scr.magn).ceilInt()}$TIMES${App.scr.windowH}"
val overlayResTxt = "${(App.scr.chatWidth * App.scr.magn).ceilToInt()}$TIMES${App.scr.windowH}"
App.fontGame.draw(batch, overlayResTxt,
(xstart + (App.scr.chatWidth - App.fontGame.getWidth(overlayResTxt)) / 2).toFloat(),

View File

@@ -270,7 +270,7 @@ package net.torvald.terrarum.modulebasegame.ui
if (actor?.inventory?.capacityMode == CAPACITY_MODE_NO_ENCUMBER)
1f
else // make sure 1px is always be seen
minOf(weightBarWidth, maxOf(1f, weightBarWidth * encumbrancePerc)),
min(weightBarWidth, max(1f, weightBarWidth * encumbrancePerc)),
controlHelpHeight - 5f
)
}
@@ -347,7 +347,7 @@ package net.torvald.terrarum.modulebasegame.ui
}
itemPageCount = maxOf(1, 1 + (inventorySortList.size.minus(1) / items.size))
itemPageCount = max(1, 1 + (inventorySortList.size.minus(1) / items.size))
}
}

View File

@@ -17,6 +17,8 @@ import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryItemGrid.Companion.
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryItemGrid.Companion.createInvCellGenericTouchDownFun
import net.torvald.terrarum.ui.Toolkit
import net.torvald.terrarum.ui.UICanvas
import kotlin.math.max
import kotlin.math.min
internal class UIInventoryCells(
val full: UIInventoryFull
@@ -125,7 +127,7 @@ internal class UIInventoryCells(
if (full.actor.inventory.capacityMode == FixtureInventory.CAPACITY_MODE_NO_ENCUMBER)
1f
else // make sure 1px is always be seen
minOf(weightBarWidth, maxOf(1f, weightBarWidth * encumbrancePerc)),
min(weightBarWidth, max(1f, weightBarWidth * encumbrancePerc)),
controlHelpHeight - 6f
)
// debug text

View File

@@ -109,8 +109,8 @@ class UIInventoryMinimap(val full: UIInventoryFull) : UICanvas() {
}
if (Gdx.input.isKeyPressed(Input.Keys.NUM_3)) {
minimapZoom = 1f
minimapPanX = INGAME.actorNowPlaying?.intTilewiseHitbox?.centeredX?.round()?.toFloat() ?: (INGAME.world.width / 2f)
minimapPanY = INGAME.actorNowPlaying?.intTilewiseHitbox?.centeredY?.round()?.toFloat() ?: (INGAME.world.height / 2f)
minimapPanX = INGAME.actorNowPlaying?.intTilewiseHitbox?.centeredX?.roundToInt()?.toFloat() ?: (INGAME.world.width / 2f)
minimapPanY = INGAME.actorNowPlaying?.intTilewiseHitbox?.centeredY?.roundToInt()?.toFloat() ?: (INGAME.world.height / 2f)
dragStatus = 1
}
@@ -185,8 +185,8 @@ class UIInventoryMinimap(val full: UIInventoryFull) : UICanvas() {
val worldPos = it.hitbox
val cw = t.regionWidth * sf
val ch = t.regionHeight * sf
val cx = worldPos.centeredX.div(TILE_SIZEF).round().toFloat()
val cy = worldPos.startY.plus(headHeight * sf).div(TILE_SIZEF).round().toFloat()
val cx = worldPos.centeredX.div(TILE_SIZEF).roundToInt().toFloat()
val cy = worldPos.startY.plus(headHeight * sf).div(TILE_SIZEF).roundToInt().toFloat()
val dx = cx - oldPanX
val dy = cy - oldPanY
@@ -255,8 +255,8 @@ class UIInventoryMinimap(val full: UIInventoryFull) : UICanvas() {
override fun doClosing(delta: Float) {}
override fun endOpening(delta: Float) {
minimapPanX = INGAME.actorNowPlaying?.intTilewiseHitbox?.centeredX?.round()?.toFloat() ?: (INGAME.world.width / 2f)
minimapPanY = INGAME.actorNowPlaying?.intTilewiseHitbox?.centeredY?.round()?.toFloat() ?: (INGAME.world.height / 2f)
minimapPanX = INGAME.actorNowPlaying?.intTilewiseHitbox?.centeredX?.roundToInt()?.toFloat() ?: (INGAME.world.width / 2f)
minimapPanY = INGAME.actorNowPlaying?.intTilewiseHitbox?.centeredY?.roundToInt()?.toFloat() ?: (INGAME.world.height / 2f)
minimapRerenderInterval = 0.25f
}

View File

@@ -4,7 +4,7 @@ import net.torvald.terrarum.App.printdbg
import net.torvald.terrarum.CraftingRecipeCodex
import net.torvald.terrarum.ItemCodex
import net.torvald.terrarum.UIItemInventoryCatBar
import net.torvald.terrarum.ceilInt
import net.torvald.terrarum.ceilToInt
import net.torvald.terrarum.gameitems.GameItem
import net.torvald.terrarum.itemproperties.CraftingCodex
@@ -80,7 +80,7 @@ class UIItemCraftingCandidateGrid(
}
itemPageCount = (recipesSortList.size.toFloat() / items.size.toFloat()).ceilInt()
itemPageCount = (recipesSortList.size.toFloat() / items.size.toFloat()).ceilToInt()
rebuildList = false
}

View File

@@ -15,10 +15,8 @@ import net.torvald.terrarum.modulebasegame.gameactors.ActorInventory
import net.torvald.terrarum.modulebasegame.gameactors.FixtureInventory
import net.torvald.terrarum.modulebasegame.gameactors.InventoryPair
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellCommonRes.defaultInventoryCellTheme
import net.torvald.terrarum.ui.Toolkit
import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.ui.UIItem
import net.torvald.terrarum.ui.UIItemImageButton
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
import kotlin.math.floor
@@ -443,7 +441,7 @@ open class UIItemInventoryItemGrid(
}
itemPageCount = (inventorySortList.size.toFloat() / items.size.toFloat()).ceilInt()
itemPageCount = (inventorySortList.size.toFloat() / items.size.toFloat()).ceilToInt()
// ¤ 42g

View File

@@ -476,7 +476,7 @@ class UILoadDemoSavefiles(val remoCon: UIRemoCon) : Advanceable() {
}
private fun setCameraPosition(batch: SpriteBatch, camera: Camera, newX: Float, newY: Float) {
camera.position.set((-newX + App.scr.halfw).round(), (-newY + App.scr.halfh).round(), 0f)
camera.position.set((-newX + App.scr.halfw).roundToFloat(), (-newY + App.scr.halfh).roundToFloat(), 0f)
camera.update()
batch.projectionMatrix = camera.combined
}

View File

@@ -360,7 +360,7 @@ class UILoadSavegame(val remoCon: UIRemoCon) : Advanceable() {
}
internal fun setCameraPosition(batch: SpriteBatch, camera: Camera, newX: Float, newY: Float) {
camera.position.set((-newX + App.scr.halfw).round(), (-newY + App.scr.halfh).round(), 0f)
camera.position.set((-newX + App.scr.halfw).roundToFloat(), (-newY + App.scr.halfh).roundToFloat(), 0f)
camera.update()
batch.projectionMatrix = camera.combined
}

View File

@@ -7,7 +7,7 @@ import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.App
import net.torvald.terrarum.CommonResourcePool
import net.torvald.terrarum.ceilInt
import net.torvald.terrarum.ceilToInt
import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.ui.*
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
@@ -225,7 +225,7 @@ class UIPerformanceControlPanel(remoCon: UIRemoCon?) : UICanvas() {
batch.color = Toolkit.Theme.COL_MOUSE_UP
Toolkit.drawBoxBorder(batch, xstart + 1, 1, App.scr.chatWidth - 2, App.scr.height - 2)
val overlayResTxt = "${(App.scr.chatWidth * App.scr.magn).ceilInt()}$TIMES${App.scr.windowH}"
val overlayResTxt = "${(App.scr.chatWidth * App.scr.magn).ceilToInt()}$TIMES${App.scr.windowH}"
App.fontGame.draw(batch, overlayResTxt,
(xstart + (App.scr.chatWidth - App.fontGame.getWidth(overlayResTxt)) / 2).toFloat(),

View File

@@ -12,6 +12,8 @@ import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.getWidth
import net.torvald.terrarum.ui.Toolkit
import net.torvald.terrarum.ui.UICanvas
import net.torvald.unicode.getKeycapPC
import kotlin.math.max
import kotlin.math.min
/**
* Created by minjaesong on 2019-07-08.
@@ -219,7 +221,7 @@ internal class UIStorageChest : UICanvas(
if (getPlayerInventory().capacityMode == FixtureInventory.CAPACITY_MODE_NO_ENCUMBER)
1f
else // make sure 1px is always be seen
minOf(UIInventoryCells.weightBarWidth, maxOf(1f, UIInventoryCells.weightBarWidth * encumbrancePerc)),
min(UIInventoryCells.weightBarWidth, max(1f, UIInventoryCells.weightBarWidth * encumbrancePerc)),
UIInventoryFull.controlHelpHeight - 6f
)

View File

@@ -10,6 +10,7 @@ import net.torvald.terrarum.ui.Toolkit
import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.ui.UIItemTextButtonList
import kotlin.math.ceil
import kotlin.math.max
class UITitleLanguage(remoCon: UIRemoCon?) : UICanvas() {
@@ -26,7 +27,7 @@ class UITitleLanguage(remoCon: UIRemoCon?) : UICanvas() {
private val localeSecondHalf = localeList.subList(ceil(localeList.size / 2f).toInt(), localeList.size)
override var width = 480
override var height = maxOf(localeFirstHalf.size, localeSecondHalf.size) * textButtonLineHeight
override var height = max(localeFirstHalf.size, localeSecondHalf.size) * textButtonLineHeight
private val textArea1 = UIItemTextButtonList(this,

View File

@@ -261,7 +261,7 @@ class UITitleModules(val remoCon: UIRemoCon) : UICanvas() {
}
private fun setCameraPosition(batch: SpriteBatch, camera: Camera, newX: Float, newY: Float) {
camera.position.set((-newX + App.scr.halfw).round(), (-newY + App.scr.halfh).round(), 0f)
camera.position.set((-newX + App.scr.halfw).roundToFloat(), (-newY + App.scr.halfh).roundToFloat(), 0f)
camera.update()
batch.projectionMatrix = camera.combined
}

View File

@@ -71,7 +71,7 @@ class UIVitalMetre(
g.lineWidth = 2f
val ratio = minOf(1f, vitalGetterVal()!! / vitalGetterMax()!!)
val ratio = min(1f, vitalGetterVal()!! / vitalGetterMax()!!)
// background
g.color = backColor

View File

@@ -11,6 +11,8 @@ import net.torvald.terrarum.modulebasegame.gameactors.FixtureInventory
import net.torvald.terrarum.ui.Toolkit
import net.torvald.terrarum.ui.UICanvas
import net.torvald.unicode.getKeycapPC
import kotlin.math.max
import kotlin.math.min
class UIWorldPortalCargo(val full: UIWorldPortal) : UICanvas(), HasInventory {
@@ -211,7 +213,7 @@ class UIWorldPortalCargo(val full: UIWorldPortal) : UICanvas(), HasInventory {
if (getPlayerInventory().capacityMode == FixtureInventory.CAPACITY_MODE_NO_ENCUMBER)
1f
else // make sure 1px is always be seen
minOf(UIInventoryCells.weightBarWidth, maxOf(1f, UIInventoryCells.weightBarWidth * encumbrancePerc)),
min(UIInventoryCells.weightBarWidth, max(1f, UIInventoryCells.weightBarWidth * encumbrancePerc)),
UIInventoryFull.controlHelpHeight - 6f
)

View File

@@ -379,7 +379,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())).ceilInt(), buttonHeight)
Toolkit.fillArea(batch, memoryGaugeXpos, memoryGaugeYpos, (memoryGaugeWidth * (chunksUsed / chunksMax.toFloat())).ceilToInt(), buttonHeight)
batch.color = Color.WHITE
if (selected?.worldInfo != null) {
@@ -396,7 +396,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())).ceilInt(), buttonHeight)
Toolkit.fillArea(batch, memoryGaugeXpos, memoryGaugeYpos, (memoryGaugeWidth * (selected?.worldInfo!!.dimensionInChunks / chunksMax.toFloat())).ceilToInt(), buttonHeight)
// thumbnail
selected?.worldInfo?.screenshot?.let {