mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-11 19:14:05 +09:00
world portal share code
This commit is contained in:
@@ -69,6 +69,7 @@ class UIWorldPortal : UICanvas(
|
||||
val transitionalListing = UIWorldPortalListing(this)
|
||||
val transitionalDelete = UIWorldPortalDelete(this)
|
||||
val transitionalRename = UIWorldPortalRename(this)
|
||||
val transitionalShare = UIWorldPortalShare(this)
|
||||
// val transitionalCargo = UIWorldPortalCargo(this)
|
||||
private val transitionPanel = UIItemHorizontalFadeSlide(
|
||||
this,
|
||||
@@ -78,7 +79,7 @@ class UIWorldPortal : UICanvas(
|
||||
App.scr.height,
|
||||
0f,
|
||||
listOf(transitionalListing),
|
||||
listOf(transitionalSearch, transitionalDelete, transitionalRename),
|
||||
listOf(transitionalSearch, transitionalDelete, transitionalRename, transitionalShare),
|
||||
listOf()
|
||||
)
|
||||
|
||||
@@ -87,6 +88,7 @@ class UIWorldPortal : UICanvas(
|
||||
internal fun queueUpSearchScr() { transitionPanel.setCentreUIto(0) }
|
||||
internal fun queueUpDeleteScr() { transitionPanel.setCentreUIto(1) }
|
||||
internal fun queueUpRenameScr() { transitionPanel.setCentreUIto(2) }
|
||||
internal fun queueUpShareScr() { transitionPanel.setCentreUIto(3) }
|
||||
|
||||
internal fun changePanelTo(index: Int) {
|
||||
transitionPanel.requestTransition(index)
|
||||
|
||||
@@ -4,7 +4,6 @@ import com.badlogic.gdx.graphics.*
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||
import com.badlogic.gdx.utils.Disposable
|
||||
import com.badlogic.gdx.utils.GdxRuntimeException
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.App.printdbg
|
||||
import net.torvald.terrarum.gameactors.AVKey
|
||||
@@ -23,7 +22,6 @@ import net.torvald.terrarum.ui.UICanvas
|
||||
import net.torvald.terrarum.ui.UIItem
|
||||
import net.torvald.terrarum.ui.UIItemTextButton
|
||||
import net.torvald.terrarum.utils.JsonFetcher
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
import net.torvald.unicode.EMDASH
|
||||
import java.time.Instant
|
||||
import java.time.format.DateTimeFormatter
|
||||
@@ -52,9 +50,9 @@ class UIWorldPortalListing(val full: UIWorldPortal) : UICanvas() {
|
||||
|
||||
|
||||
|
||||
private val thumbw = 378
|
||||
private val thumbw = 400
|
||||
private val textAreaW = thumbw - 32
|
||||
private val thumbh = 252
|
||||
private val thumbh = 268
|
||||
private val hx = Toolkit.drawWidth.div(2)
|
||||
private val y = INVENTORY_CELLS_OFFSET_Y() + 1 - 34
|
||||
|
||||
@@ -62,14 +60,16 @@ class UIWorldPortalListing(val full: UIWorldPortal) : UICanvas() {
|
||||
private val listHeight = UIItemWorldCellsSimple.height + (listCount - 1) * (UIItemWorldCellsSimple.height + gridGap)
|
||||
|
||||
private val memoryGaugeWidth = textAreaW
|
||||
private val deleteButtonWidth = (thumbw - gridGap) / 2
|
||||
private val buttonWidth = (UIItemWorldCellsSimple.width + thumbw - 3 * gridGap) / 5 // thumbw + cellw + gridgap = 4*gridgap + 5x
|
||||
private val buttonsY = y + listHeight + gridGap
|
||||
|
||||
private val screencapX = hx - thumbw - gridGap/2
|
||||
|
||||
private val buttonSearch = UIItemTextButton(this,
|
||||
{ Lang["CONTEXT_WORLD_NEW"] },
|
||||
hx - gridGap/2 - 2*deleteButtonWidth - gridGap,
|
||||
screencapX,
|
||||
buttonsY,
|
||||
deleteButtonWidth,
|
||||
buttonWidth,
|
||||
hasBorder = true,
|
||||
alignment = UIItemTextButton.Companion.Alignment.CENTRE
|
||||
).also {
|
||||
@@ -80,9 +80,9 @@ class UIWorldPortalListing(val full: UIWorldPortal) : UICanvas() {
|
||||
}
|
||||
private val buttonTeleport = UIItemTextButton(this,
|
||||
{ Lang["GAME_ACTION_TELEPORT"] },
|
||||
hx - gridGap/2 - deleteButtonWidth,
|
||||
screencapX + buttonWidth + gridGap,
|
||||
buttonsY,
|
||||
deleteButtonWidth,
|
||||
buttonWidth,
|
||||
hasBorder = true,
|
||||
alignment = UIItemTextButton.Companion.Alignment.CENTRE
|
||||
).also {
|
||||
@@ -98,9 +98,9 @@ class UIWorldPortalListing(val full: UIWorldPortal) : UICanvas() {
|
||||
}
|
||||
private val buttonRename = UIItemTextButton(this,
|
||||
{ Lang["MENU_LABEL_RENAME"] },
|
||||
hx + gridGap/2,
|
||||
screencapX + (buttonWidth + gridGap) * 2,
|
||||
buttonsY,
|
||||
deleteButtonWidth,
|
||||
buttonWidth,
|
||||
hasBorder = true,
|
||||
alignment = UIItemTextButton.Companion.Alignment.CENTRE
|
||||
).also {
|
||||
@@ -111,9 +111,9 @@ class UIWorldPortalListing(val full: UIWorldPortal) : UICanvas() {
|
||||
}
|
||||
private val buttonDelete = UIItemTextButton(this,
|
||||
{ Lang["MENU_LABEL_DELETE_WORLD"] },
|
||||
hx + gridGap/2 + deleteButtonWidth + gridGap,
|
||||
screencapX + (buttonWidth + gridGap) * 3,
|
||||
buttonsY,
|
||||
deleteButtonWidth,
|
||||
buttonWidth,
|
||||
hasBorder = true,
|
||||
alignment = UIItemTextButton.Companion.Alignment.CENTRE,
|
||||
inactiveCol = Toolkit.Theme.COL_RED, activeCol = Toolkit.Theme.COL_REDD
|
||||
@@ -123,6 +123,19 @@ class UIWorldPortalListing(val full: UIWorldPortal) : UICanvas() {
|
||||
full.changePanelTo(1)
|
||||
}
|
||||
}
|
||||
private val buttonShare = UIItemTextButton(this,
|
||||
{ Lang["MENU_LABEL_SHARE"] },
|
||||
screencapX + (buttonWidth + gridGap) * 4,
|
||||
buttonsY,
|
||||
buttonWidth,
|
||||
hasBorder = true,
|
||||
alignment = UIItemTextButton.Companion.Alignment.CENTRE,
|
||||
).also {
|
||||
it.clickOnceListener = { _,_ ->
|
||||
full.queueUpShareScr()
|
||||
full.changePanelTo(1)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private val navRemoCon = UIItemListNavBarVertical(full, hx + 6 + UIItemWorldCellsSimple.width, y + 7, listHeight + 2, false)
|
||||
@@ -146,6 +159,7 @@ class UIWorldPortalListing(val full: UIWorldPortal) : UICanvas() {
|
||||
buttonRename.isEnabled = false
|
||||
buttonDelete.isEnabled = false
|
||||
buttonTeleport.isEnabled = false
|
||||
buttonShare.isEnabled = false
|
||||
currentWorldSelected = false
|
||||
}
|
||||
|
||||
@@ -157,6 +171,7 @@ class UIWorldPortalListing(val full: UIWorldPortal) : UICanvas() {
|
||||
buttonRename.isEnabled = true
|
||||
buttonDelete.isEnabled = info.uuid != INGAME.world.worldIndex
|
||||
buttonTeleport.isEnabled = info.uuid != INGAME.world.worldIndex
|
||||
buttonShare.isEnabled = true
|
||||
currentWorldSelected = info.uuid == INGAME.world.worldIndex
|
||||
}
|
||||
}
|
||||
@@ -171,6 +186,7 @@ class UIWorldPortalListing(val full: UIWorldPortal) : UICanvas() {
|
||||
addUIitem(buttonRename)
|
||||
addUIitem(buttonTeleport)
|
||||
addUIitem(buttonSearch)
|
||||
addUIitem(buttonShare)
|
||||
addUIitem(navRemoCon)
|
||||
}
|
||||
|
||||
@@ -344,13 +360,13 @@ class UIWorldPortalListing(val full: UIWorldPortal) : UICanvas() {
|
||||
// draw background //
|
||||
// screencap panel
|
||||
batch.color = UIInventoryFull.CELL_COL
|
||||
Toolkit.fillArea(batch, hx - thumbw - gridGap/2, y, thumbw, thumbh)
|
||||
Toolkit.fillArea(batch, screencapX, y, thumbw, thumbh)
|
||||
|
||||
|
||||
// draw border //
|
||||
// screencap panel
|
||||
batch.color = if (selected?.worldInfo == null) Toolkit.Theme.COL_INVENTORY_CELL_BORDER else Toolkit.Theme.COL_INACTIVE
|
||||
Toolkit.drawBoxBorder(batch, hx - thumbw - gridGap/2 - 1, y - 1, thumbw + 2, thumbh + 2)
|
||||
Toolkit.drawBoxBorder(batch, screencapX - 1, y - 1, thumbw + 2, thumbh + 2)
|
||||
|
||||
|
||||
// memory gauge
|
||||
@@ -375,9 +391,9 @@ class UIWorldPortalListing(val full: UIWorldPortal) : UICanvas() {
|
||||
if (selected?.worldInfo != null) {
|
||||
// background for texts panel
|
||||
batch.color = Toolkit.Theme.COL_CELL_FILL
|
||||
Toolkit.fillArea(batch, hx - thumbw - gridGap/2, y + thumbh + 3, thumbw, 10 + worldTexts.size * textualListHeight.toInt())
|
||||
Toolkit.fillArea(batch, screencapX, y + thumbh + 3, thumbw, 10 + worldTexts.size * textualListHeight.toInt())
|
||||
batch.color = Toolkit.Theme.COL_INACTIVE
|
||||
Toolkit.drawBoxBorder(batch, hx - thumbw - gridGap/2 - 1, y + thumbh + 2, thumbw + 2, 10 + worldTexts.size * textualListHeight.toInt() + 2)
|
||||
Toolkit.drawBoxBorder(batch, screencapX - 1, y + thumbh + 2, thumbw + 2, 10 + worldTexts.size * textualListHeight.toInt() + 2)
|
||||
|
||||
// some texts
|
||||
batch.color = Color.WHITE
|
||||
@@ -390,7 +406,7 @@ class UIWorldPortalListing(val full: UIWorldPortal) : UICanvas() {
|
||||
|
||||
// thumbnail
|
||||
selected?.worldInfo?.screenshot?.let {
|
||||
batch.draw(it, (hx - thumbw - gridGap/2).toFloat(), y.toFloat(), thumbw.toFloat(), thumbh.toFloat())
|
||||
batch.draw(it, (screencapX).toFloat(), y.toFloat(), thumbw.toFloat(), thumbh.toFloat())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -402,7 +418,7 @@ class UIWorldPortalListing(val full: UIWorldPortal) : UICanvas() {
|
||||
|
||||
// control hints
|
||||
batch.color = Color.WHITE
|
||||
App.fontGame.draw(batch, full.portalListingControlHelp, hx - thumbw - gridGap/2 + 2, (full.yEnd - 20).toInt())
|
||||
App.fontGame.draw(batch, full.portalListingControlHelp, screencapX + 2, (full.yEnd - 20).toInt())
|
||||
}
|
||||
|
||||
override fun hide() {
|
||||
@@ -485,11 +501,11 @@ class UIItemWorldCellsSimple(
|
||||
var forceMouseDown = false
|
||||
|
||||
companion object {
|
||||
const val width = 378
|
||||
const val width = 400
|
||||
const val height = 46
|
||||
}
|
||||
|
||||
override val width: Int = 378
|
||||
override val width: Int = 400
|
||||
override val height: Int = 46
|
||||
|
||||
private val icons = CommonResourcePool.getAsTextureRegionPack("terrarum-basegame-worldportalicons")
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
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.App.printdbg
|
||||
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.ui.UIItemTextButton
|
||||
import net.torvald.terrarum.utils.PasswordBase32
|
||||
|
||||
class UIWorldPortalShare(private val full: UIWorldPortal) : UICanvas() {
|
||||
|
||||
override var width = 426
|
||||
override var height = 400
|
||||
|
||||
private val drawX = (Toolkit.drawWidth - width) / 2
|
||||
private val drawY = (App.scr.height - height) / 2
|
||||
private val goButtonWidth = 180
|
||||
private val buttonY = drawY + height - 24
|
||||
|
||||
|
||||
private val backButton = UIItemTextButton(this,
|
||||
{ Lang["MENU_LABEL_BACK"] }, drawX + (width - goButtonWidth) / 2, buttonY, goButtonWidth, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true).also {
|
||||
it.clickOnceListener = { _,_ ->
|
||||
|
||||
|
||||
full.changePanelTo(0)
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
addUIitem(backButton)
|
||||
}
|
||||
|
||||
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)}"
|
||||
}
|
||||
|
||||
printdbg(this, shareCode)
|
||||
}
|
||||
|
||||
override fun renderUI(batch: SpriteBatch, camera: OrthographicCamera) {
|
||||
batch.color = Color.WHITE
|
||||
|
||||
// share code background
|
||||
batch.color = Toolkit.Theme.COL_INVENTORY_CELL_BORDER
|
||||
Toolkit.drawBoxBorder(batch, drawX - 1, drawY + (height / 2) - 6, width + 2, BigAlphNum.H + 12)
|
||||
batch.color = Toolkit.Theme.COL_CELL_FILL
|
||||
Toolkit.fillArea(batch, drawX, drawY + (height / 2) - 5, width, BigAlphNum.H + 10)
|
||||
|
||||
// share code
|
||||
batch.color = Toolkit.Theme.COL_MOUSE_UP
|
||||
Toolkit.drawTextCentered(batch, App.fontBigNumbers, shareCode, width, drawX, drawY + (height / 2))
|
||||
|
||||
// ui title
|
||||
batch.color = Color.WHITE
|
||||
val titlestr = Lang["MENU_LABEL_SHARE"]
|
||||
App.fontUITitle.draw(batch, titlestr, drawX + (width - App.fontUITitle.getWidth(titlestr)).div(2).toFloat(), UIInventoryFull.INVENTORY_CELLS_OFFSET_Y() - 36f)
|
||||
|
||||
// control hints
|
||||
App.fontGame.draw(batch, full.portalListingControlHelp, (Toolkit.drawWidth - width)/2 + 2, (full.yEnd - 20).toInt())
|
||||
|
||||
uiItems.forEach { it.render(batch, camera) }
|
||||
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
}
|
||||
|
||||
override fun doOpening(delta: Float) {
|
||||
full.selectedButton?.forceMouseDown = true
|
||||
}
|
||||
|
||||
override fun doClosing(delta: Float) {
|
||||
full.selectedButton?.forceMouseDown = false
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user