mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-13 12:04:06 +09:00
weatherbox is now owned by the world
This commit is contained in:
79
src/net/torvald/terrarum/modulebasegame/ui/UIShare.kt
Normal file
79
src/net/torvald/terrarum/modulebasegame/ui/UIShare.kt
Normal file
@@ -0,0 +1,79 @@
|
||||
package net.torvald.terrarum.modulebasegame.ui
|
||||
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.OrthographicCamera
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import net.torvald.terrarum.App
|
||||
import net.torvald.terrarum.INGAME
|
||||
import net.torvald.terrarum.imagefont.BigAlphNum
|
||||
import net.torvald.terrarum.langpack.Lang
|
||||
import net.torvald.terrarum.serialise.toBig64
|
||||
import net.torvald.terrarum.ui.Toolkit
|
||||
import net.torvald.terrarum.ui.UICanvas
|
||||
import net.torvald.terrarum.utils.PasswordBase32
|
||||
|
||||
class UIShare : UICanvas() {
|
||||
|
||||
override var width = 434
|
||||
override var height = 480
|
||||
|
||||
private val drawX = (Toolkit.drawWidth - width) / 2
|
||||
private val drawY = (App.scr.height - height) / 2
|
||||
|
||||
override fun updateUI(delta: Float) {
|
||||
uiItems.forEach { it.update(delta) }
|
||||
}
|
||||
|
||||
private var shareCode = ""
|
||||
private var dash = ' '
|
||||
|
||||
override fun show() {
|
||||
shareCode = PasswordBase32.encode(
|
||||
INGAME.world.worldIndex.mostSignificantBits.toBig64() +
|
||||
INGAME.world.worldIndex.mostSignificantBits.toBig64()
|
||||
).let { it.substring(0, it.indexOf('=')) }.let {
|
||||
"${it.substring(0..3)}$dash${it.substring(4..5)}$dash${it.substring(6..10)}$dash${it.substring(11..15)}$dash${it.substring(16..20)}$dash${it.substring(21)}"
|
||||
}
|
||||
|
||||
App.printdbg(this, shareCode)
|
||||
|
||||
wotKeys = (1..4).map { Lang["CONTEXT_WORLD_CODE_SHARE_$it", false] }
|
||||
}
|
||||
|
||||
private lateinit var wotKeys: List<String>
|
||||
|
||||
override fun renderUI(batch: SpriteBatch, camera: OrthographicCamera) {
|
||||
batch.color = Color.WHITE
|
||||
|
||||
val textY = drawY + (height/2) - App.fontGame.lineHeight.toInt() * 4 - 2
|
||||
val codeY = textY + App.fontGame.lineHeight.toInt() * 5
|
||||
|
||||
// share code background
|
||||
batch.color = Toolkit.Theme.COL_INVENTORY_CELL_BORDER
|
||||
Toolkit.drawBoxBorder(batch, drawX - 1, codeY - 1, width + 2, BigAlphNum.H + 12)
|
||||
batch.color = Toolkit.Theme.COL_CELL_FILL
|
||||
Toolkit.fillArea(batch, drawX, codeY, width, BigAlphNum.H + 10)
|
||||
|
||||
// share code
|
||||
batch.color = Toolkit.Theme.COL_MOUSE_UP
|
||||
Toolkit.drawTextCentered(batch, App.fontBigNumbers, shareCode, width, drawX, codeY + 5)
|
||||
|
||||
// texts
|
||||
batch.color = Color.WHITE
|
||||
|
||||
val textboxWidth = wotKeys.maxOf { App.fontGame.getWidth(it) }
|
||||
val tx = drawX + (width - textboxWidth) / 2
|
||||
wotKeys.forEachIndexed { i, s ->
|
||||
App.fontGame.draw(batch, s, tx, textY + App.fontGame.lineHeight.toInt() * i)
|
||||
}
|
||||
|
||||
|
||||
uiItems.forEach { it.render(batch, camera) }
|
||||
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user