single screen ui for world portal

This commit is contained in:
minjaesong
2023-06-18 01:28:51 +09:00
parent 376595d7cd
commit 6b8798a19e
14 changed files with 272 additions and 88 deletions

View File

@@ -19,5 +19,6 @@
"GAME_CRAFTABLE_ITEMS": "Craftable Items",
"CONTEXT_WORLD_SEARCH": "World Search",
"CONTEXT_WORLD_LIST": "Worlds List",
"MENU_LABEL_RENAME": "Rename"
"MENU_LABEL_RENAME": "Rename",
"GAME_ACTION_TELEPORT": "Teleport"
}

View File

@@ -16,13 +16,13 @@ class FixtureWorldPortal : FixtureBase {
BlockBox(BlockBox.NO_COLLISION, 5, 2),
nameFun = { Lang["ITEM_WORLD_PORTAL"] },
mainUI = UIWorldPortal(),
inventory = FixtureInventory(200, CAPACITY_MODE_WEIGHT)
// inventory = FixtureInventory(200, CAPACITY_MODE_WEIGHT)
) {
// TODO do something with (mainUI as UIWorldPortal).***
(mainUI as UIWorldPortal).let { ui ->
ui.transitionalCargo.chestInventory = this.inventory!!
ui.transitionalCargo.chestNameFun = this.nameFun
}
// (mainUI as UIWorldPortal).let { ui ->
// ui.transitionalCargo.chestInventory = this.inventory!!
// ui.transitionalCargo.chestNameFun = this.nameFun
// }
}

View File

@@ -66,7 +66,7 @@ class UIBuildingMakerBlockChooser(val parent: BuildingMaker): UICanvas() {
activeCol = Color.WHITE
)
paletteItem.clickOnceListener = { _, _, _ ->
paletteItem.clickOnceListener = { _, _ ->
parent.setPencilColour(prop.id)
}

View File

@@ -100,11 +100,9 @@ class UIBuildingMakerPenMenu(val parent: BuildingMaker): UICanvas() {
toolButtons.forEachIndexed { index, button ->
uiItems.add(button)
button.clickOnceListener = { _, _, b ->
if (b == App.getConfigInt("config_mouseprimary")) {
toolButtonsJob[index].invoke()
closeGracefully()
}
button.clickOnceListener = { _, _ ->
toolButtonsJob[index].invoke()
closeGracefully()
}
}
}

View File

@@ -90,7 +90,7 @@ class UIGraphicsControlPanel(remoCon: UIRemoCon?) : UICanvas() {
}
else if (args.startsWith("toggle")) {
UIItemToggleButton(this, x, y, spinnerWidth, App.getConfigBoolean(optionName)) to { it: UIItem, optionStr: String ->
(it as UIItemToggleButton).clickOnceListener = { _, _, _ ->
(it as UIItemToggleButton).clickOnceListener = { _, _ ->
it.toggle()
App.setConfig(optionStr, it.getStatus())
}

View File

@@ -91,11 +91,11 @@ class UIItemListNavBarVertical(
gridButtonListener(this, gridModeButtons[1])
}
scrollUpButton.clickOnceListener = { _, _, _ ->
scrollUpButton.clickOnceListener = { _, _ ->
scrollUpButton.highlighted = false
scrollUpListener(this, scrollUpButton)
}
scrollDownButton.clickOnceListener = { _, _, _ ->
scrollDownButton.clickOnceListener = { _, _ ->
scrollDownButton.highlighted = false
scrollDownListener(this, scrollDownButton)
}

View File

@@ -122,7 +122,7 @@ class UIKeyboardControlPanel(remoCon: UIRemoCon?) : UICanvas() {
keycaps.values.forEach { addUIitem(it) }
updateKeycaps()
buttonReset.clickOnceListener = { x, y, button ->
buttonReset.clickOnceListener = { x, y ->
resetKeyConfig()
updateKeycaps()
}

View File

@@ -478,7 +478,7 @@ class UIItemPlayerCells(
override val width = SAVE_CELL_WIDTH
override val height = SAVE_CELL_HEIGHT
override var clickOnceListener: ((Int, Int, Int) -> Unit)? = { _: Int, _: Int, _: Int ->
override var clickOnceListener: ((Int, Int) -> Unit)? = { _: Int, _: Int ->
UILoadGovernor.playerDisk = skimmer
parent.advanceMode()
}
@@ -739,7 +739,7 @@ class UIItemWorldCells(
private var highlightCol: Color = Toolkit.Theme.COL_LIST_DEFAULT
override var clickOnceListener: ((Int, Int, Int) -> Unit)? = { _: Int, _: Int, _: Int ->
override var clickOnceListener: ((Int, Int) -> Unit)? = { _: Int, _: Int ->
UILoadGovernor.worldDisk = skimmer
parent.advanceMode()
}

View File

@@ -37,25 +37,6 @@ class UIWorldPortal : UICanvas(
val controlHelpHeight = App.fontGame.lineHeight
private var panelTransitionLocked = false
fun lockTransition() {
panelTransitionLocked = true
}
fun unlockTransition() {
panelTransitionLocked = false
}
fun requestTransition(target: Int) = transitionPanel.requestTransition(target)
val catBar = UIItemWorldPortalTopBar(
this,
0,
42 - YPOS_CORRECTION + (App.scr.height - internalHeight) / 2,
) { i ->
if (!panelTransitionLocked) requestTransition(i ushr 1)
}
private val SP = "\u3000 "
val portalListingControlHelp: String
@@ -67,27 +48,22 @@ class UIWorldPortal : UICanvas(
"$SP${App.gamepadLabelRT} ${Lang["GAME_INVENTORY"]}"
val transitionalSearch = UIWorldPortalSearch(this)
// val transitionalSearch = UIWorldPortalSearch(this)
val transitionalListing = UIWorldPortalListing(this)
val transitionalCargo = UIWorldPortalCargo(this)
// val transitionalCargo = UIWorldPortalCargo(this)
private val transitionPanel = UIItemHorizontalFadeSlide(
this,
(width - internalWidth) / 2,
INVENTORY_CELLS_OFFSET_Y(),
width,
App.scr.height,
1f,
transitionalSearch, transitionalListing, transitionalCargo
0f,
transitionalListing
)
init {
addUIitem(catBar)
addUIitem(transitionPanel)
catBar.selectionChangeListener = { old, new ->
}
}
internal var xEnd = (width + internalWidth).div(2).toFloat()
@@ -99,7 +75,6 @@ class UIWorldPortal : UICanvas(
override fun updateUI(delta: Float) {
catBar.update(delta)
transitionPanel.update(delta)
}
@@ -107,7 +82,6 @@ class UIWorldPortal : UICanvas(
drawBackground(batch, handler.opacity)
// UI items
catBar.render(batch, camera)
transitionPanel.render(batch, camera)
}
@@ -122,7 +96,6 @@ class UIWorldPortal : UICanvas(
}
override fun dispose() {
catBar.dispose()
transitionPanel.dispose()
}

View File

@@ -1,13 +1,16 @@
package net.torvald.terrarum.modulebasegame.ui
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.App
import net.torvald.terrarum.INGAME
import net.torvald.terrarum.*
import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.gameitems.GameItem
import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.modulebasegame.gameactors.FixtureInventory
import net.torvald.terrarum.ui.Toolkit
import net.torvald.terrarum.ui.UICanvas
import net.torvald.unicode.getKeycapPC
class UIWorldPortalCargo(val full: UIWorldPortal) : UICanvas(), HasInventory {
@@ -33,12 +36,217 @@ class UIWorldPortalCargo(val full: UIWorldPortal) : UICanvas(), HasInventory {
override fun getFixtureInventory(): FixtureInventory = chestInventory
override fun getPlayerInventory(): FixtureInventory = INGAME.actorNowPlaying!!.inventory
override fun updateUI(delta: Float) {
private val catBar: UIItemInventoryCatBar
private val itemListChest: UIItemInventoryItemGrid
private val itemListPlayer: UIItemInventoryItemGrid
private var encumbrancePerc = 0f
private var isEncumbered = false
private var halfSlotOffset = (UIItemInventoryElemSimple.height + UIItemInventoryItemGrid.listGap * 2) / 2
init {
catBar = UIItemInventoryCatBar(
this,
(width - UIInventoryFull.catBarWidth) / 2,
42 - UIInventoryFull.YPOS_CORRECTION + (App.scr.height - UIInventoryFull.internalHeight) / 2,
UIInventoryFull.internalWidth,
UIInventoryFull.catBarWidth,
false
)
catBar.selectionChangeListener = { old, new -> itemListUpdate() }
itemListChest = UIItemInventoryItemGrid(
this,
catBar,
{ getFixtureInventory() },
Toolkit.hdrawWidth - UIInventoryFull.getWidthOfCells(6) - halfSlotOffset,
UIInventoryFull.INVENTORY_CELLS_OFFSET_Y(),
6, UIInventoryFull.CELLS_VRT,
drawScrollOnRightside = false,
drawWallet = false,
keyDownFun = { _, _, _, _, _ -> Unit },
touchDownFun = { gameItem, amount, button, _, _ ->
if (button == App.getConfigInt("config_mouseprimary")) {
if (gameItem != null) {
negotiator.reject(getFixtureInventory(), getPlayerInventory(), gameItem, amount)
}
itemListUpdate()
}
}
)
// make grid mode buttons work together
itemListChest.navRemoCon.listButtonListener = { _,_ -> setCompact(false) }
itemListChest.navRemoCon.gridButtonListener = { _,_ -> setCompact(true) }
itemListPlayer = UIItemInventoryItemGrid(
this,
catBar,
{ INGAME.actorNowPlaying!!.inventory }, // literally a player's inventory
Toolkit.hdrawWidth + halfSlotOffset,
UIInventoryFull.INVENTORY_CELLS_OFFSET_Y(),
6, UIInventoryFull.CELLS_VRT,
drawScrollOnRightside = true,
drawWallet = false,
keyDownFun = { _, _, _, _, _ -> Unit },
touchDownFun = { gameItem, amount, button, _, _ ->
if (button == App.getConfigInt("config_mouseprimary")) {
if (gameItem != null) {
negotiator.accept(getPlayerInventory(), getFixtureInventory(), gameItem, amount)
}
itemListUpdate()
}
}
)
itemListPlayer.navRemoCon.listButtonListener = { _,_ -> setCompact(false) }
itemListPlayer.navRemoCon.gridButtonListener = { _,_ -> setCompact(true) }
handler.allowESCtoClose = true
addUIitem(itemListChest)
addUIitem(itemListPlayer)
}
override fun renderUI(batch: SpriteBatch, camera: Camera) {
private var openingClickLatched = false
override fun show() {
itemListPlayer.getInventory = { INGAME.actorNowPlaying!!.inventory }
itemListUpdate()
openingClickLatched = Terrarum.mouseDown
UIItemInventoryItemGrid.tooltipShowing.clear()
INGAME.setTooltipMessage(null)
}
private fun itemListUpdate() {
itemListChest.rebuild(catBar.catIconsMeaning[catBar.selectedIcon])
itemListPlayer.rebuild(catBar.catIconsMeaning[catBar.selectedIcon])
encumbrancePerc = getPlayerInventory().capacity.toFloat() / getPlayerInventory().maxCapacity
isEncumbered = getPlayerInventory().isEncumbered
}
private fun setCompact(yes: Boolean) {
itemListChest.isCompactMode = yes
itemListChest.navRemoCon.gridModeButtons[0].highlighted = !yes
itemListChest.navRemoCon.gridModeButtons[1].highlighted = yes
itemListChest.itemPage = 0
itemListChest.rebuild(catBar.catIconsMeaning[catBar.selectedIcon])
itemListPlayer.isCompactMode = yes
itemListPlayer.navRemoCon.gridModeButtons[0].highlighted = !yes
itemListPlayer.navRemoCon.gridModeButtons[1].highlighted = yes
itemListPlayer.itemPage = 0
itemListPlayer.rebuild(catBar.catIconsMeaning[catBar.selectedIcon])
itemListUpdate()
}
override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
if (!openingClickLatched) {
return super.touchDown(screenX, screenY, pointer, button)
}
return false
}
override fun updateUI(delta: Float) {
catBar.update(delta)
itemListChest.update(delta)
itemListPlayer.update(delta)
if (openingClickLatched && !Terrarum.mouseDown) openingClickLatched = false
}
private val thisOffsetX = Toolkit.hdrawWidth - UIInventoryFull.getWidthOfCells(6) - halfSlotOffset
private val thisOffsetX2 = thisOffsetX + (UIItemInventoryItemGrid.listGap + UIItemInventoryElemWide.height) * 7
private val thisOffsetY = UIInventoryFull.INVENTORY_CELLS_OFFSET_Y()
private val cellsWidth = (UIItemInventoryItemGrid.listGap + UIItemInventoryElemWide.height) * 6 - UIItemInventoryItemGrid.listGap
private val controlHelp: String
get() = if (App.environment == RunningEnvironment.PC)
"${getKeycapPC(App.getConfigInt("control_key_inventory"))} ${Lang["GAME_ACTION_CLOSE"]}"
else
"${App.gamepadLabelStart} ${Lang["GAME_ACTION_CLOSE"]} "
override fun renderUI(batch: SpriteBatch, camera: Camera) {
// background fill
UIInventoryFull.drawBackground(batch, handler.opacity)
// UI items
batch.color = Color.WHITE
catBar.render(batch, camera)
itemListChest.render(batch, camera)
itemListPlayer.render(batch, camera)
blendNormalStraightAlpha(batch)
// encumbrance meter
val encumbranceText = Lang["GAME_INVENTORY_ENCUMBRANCE"]
val chestName = chestNameFun()
val playerName = INGAME.actorNowPlaying!!.actorValue.getAsString(AVKey.NAME).orEmpty().let { it.ifBlank { Lang["GAME_INVENTORY"] } }
val encumbBarXPos = itemListPlayer.posX + itemListPlayer.width - UIInventoryCells.weightBarWidth + 36
val encumbBarTextXPos = encumbBarXPos - 6 - App.fontGame.getWidth(encumbranceText)
val yEnd = -UIInventoryFull.YPOS_CORRECTION + (App.scr.height + UIInventoryFull.internalHeight).div(2).toFloat() // directly copied from UIInventoryFull.yEnd
val encumbBarYPos = yEnd - 20 + 3 // dunno why but extra 3 px is needed
val encumbCol = UIItemInventoryCellCommonRes.getHealthMeterColour(1f - encumbrancePerc, 0f, 1f)
val encumbBack = encumbCol mul UIItemInventoryCellCommonRes.meterBackDarkening
// encumbrance bar background
batch.color = encumbBack
Toolkit.fillArea(
batch,
encumbBarXPos,
encumbBarYPos,
UIInventoryCells.weightBarWidth,
UIInventoryFull.controlHelpHeight - 6f
)
// encumbrance bar
batch.color = encumbCol
Toolkit.fillArea(
batch,
encumbBarXPos, encumbBarYPos,
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)),
UIInventoryFull.controlHelpHeight - 6f
)
// chest name text
batch.color = Color.WHITE
App.fontGame.draw(batch, chestName, thisOffsetX + (cellsWidth - App.fontGame.getWidth(chestName)) / 2, thisOffsetY - 30)
App.fontGame.draw(batch, playerName, thisOffsetX2 + (cellsWidth - App.fontGame.getWidth(playerName)) / 2, thisOffsetY - 30)
// control hint
App.fontGame.draw(batch, controlHelp, thisOffsetX - 34f, encumbBarYPos - 3)
// encumb text
batch.color = Color.WHITE
App.fontGame.draw(batch, encumbranceText, encumbBarTextXPos, encumbBarYPos - 3f)
}
override fun doOpening(delta: Float) {
INGAME.pause()
INGAME.setTooltipMessage(null)
}
override fun doClosing(delta: Float) {
INGAME.resume()
INGAME.setTooltipMessage(null)
}
override fun endOpening(delta: Float) {
}
override fun endClosing(delta: Float) {
UIItemInventoryItemGrid.tooltipShowing.clear()
INGAME.setTooltipMessage(null) // required!
}
override fun dispose() {
}
}

View File

@@ -49,7 +49,7 @@ class UIWorldPortalListing(val full: UIWorldPortal) : UICanvas() {
private val textAreaW = thumbw - 32
private val thumbh = 252
private val hx = Toolkit.drawWidth.div(2)
private val y = INVENTORY_CELLS_OFFSET_Y() + 1
private val y = INVENTORY_CELLS_OFFSET_Y() + 1 - 34
private val listCount = getCellCountVertically(UIItemWorldCellsSimple.height, gridGap)
private val listHeight = UIItemWorldCellsSimple.height + (listCount - 1) * (UIItemWorldCellsSimple.height + gridGap)
@@ -57,18 +57,10 @@ class UIWorldPortalListing(val full: UIWorldPortal) : UICanvas() {
private val memoryGaugeWidth = textAreaW
private val deleteButtonWidth = (thumbw - gridGap) / 2
private val buttonsY = y + listHeight + gridGap
private val buttonDeleteWorld = UIItemTextButton(this,
"MENU_LABEL_DELETE",
hx - gridGap/2 - deleteButtonWidth,
buttonsY,
deleteButtonWidth,
readFromLang = true,
hasBorder = true,
alignment = UIItemTextButton.Companion.Alignment.CENTRE
)
private val buttonRenameWorld = UIItemTextButton(this,
"MENU_LABEL_RENAME",
buttonDeleteWorld.posX - gridGap - deleteButtonWidth,
private val buttonSearch = UIItemTextButton(this,
"CONTEXT_WORLD_SEARCH",
hx - gridGap/2 - 2*deleteButtonWidth - gridGap,
buttonsY,
deleteButtonWidth,
readFromLang = true,
@@ -76,7 +68,16 @@ class UIWorldPortalListing(val full: UIWorldPortal) : UICanvas() {
alignment = UIItemTextButton.Companion.Alignment.CENTRE
)
private val buttonTeleport = UIItemTextButton(this,
"CONTEXT_GAME_TELEPORT",
"GAME_ACTION_TELEPORT",
hx - gridGap/2 - deleteButtonWidth,
buttonsY,
deleteButtonWidth,
readFromLang = true,
hasBorder = true,
alignment = UIItemTextButton.Companion.Alignment.CENTRE
)
private val buttonRename = UIItemTextButton(this,
"MENU_LABEL_RENAME",
hx + gridGap/2,
buttonsY,
deleteButtonWidth,
@@ -84,21 +85,15 @@ class UIWorldPortalListing(val full: UIWorldPortal) : UICanvas() {
hasBorder = true,
alignment = UIItemTextButton.Companion.Alignment.CENTRE
)
private val buttonCancel = UIItemTextButton(this,
"MENU_LABEL_CANCEL",
private val buttonDelete = UIItemTextButton(this,
"MENU_LABEL_DELETE",
hx + gridGap/2 + deleteButtonWidth + gridGap,
buttonsY,
deleteButtonWidth,
readFromLang = true,
hasBorder = true,
alignment = UIItemTextButton.Companion.Alignment.CENTRE
).also {
it.clickOnceListener = { _, _, _ ->
selected = null
selectedIndex = null
updateUIbyButtonSelection()
}
}
)
private val navRemoCon = UIItemListNavBarVertical(full, hx + 6 + UIItemWorldCellsSimple.width, y + 7, listHeight + 2, false)
@@ -117,6 +112,12 @@ class UIWorldPortalListing(val full: UIWorldPortal) : UICanvas() {
}
}
private fun highlightListEditButtons(state: Boolean) {
buttonRename.isActive = state
buttonDelete.isActive = state
buttonTeleport.isActive = state
}
init {
CommonResourcePool.addToLoadingList("terrarum-basegame-worldportalicons") {
TextureRegionPack(ModMgr.getGdxFile("basegame", "gui/worldportal_catbar.tga"), 30, 20)
@@ -126,10 +127,10 @@ class UIWorldPortalListing(val full: UIWorldPortal) : UICanvas() {
navRemoCon.scrollUpListener = { _,_ -> scrollItemPage(-1) }
navRemoCon.scrollDownListener = { _,_ -> scrollItemPage(1) }
addUIitem(buttonRenameWorld)
addUIitem(buttonDeleteWorld)
addUIitem(buttonDelete)
addUIitem(buttonRename)
addUIitem(buttonTeleport)
addUIitem(buttonCancel)
addUIitem(buttonSearch)
addUIitem(navRemoCon)
}
@@ -212,9 +213,10 @@ class UIWorldPortalListing(val full: UIWorldPortal) : UICanvas() {
worldList.getOrNull(it),
worldList.getOrNull(it)?.diskSkimmer?.getDiskName(Common.CHARSET)
).also { button ->
button.clickOnceListener = { _, _, _ ->
button.clickOnceListener = { _, _ ->
selected = button
selectedIndex = it
highlightListEditButtons(it in worldList.indices)
updateUIbyButtonSelection()
}
}
@@ -232,6 +234,7 @@ class UIWorldPortalListing(val full: UIWorldPortal) : UICanvas() {
worldCells.forEach { it.show() }
selected = null
highlightListEditButtons(false)
updateUIbyButtonSelection()
}
@@ -354,7 +357,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 + 8).toInt())
App.fontGame.draw(batch, full.portalListingControlHelp, hx - thumbw - gridGap/2 + 2, (full.yEnd - 20).toInt())
}
override fun hide() {

View File

@@ -111,7 +111,7 @@ class DummyTogglePane : UICanvas() {
private var timer = 0f
init {
button1.clickOnceListener = { _,_,_ ->
button1.clickOnceListener = { _,_ ->
button1.toggle()
}
uiItems.add(button1)

View File

@@ -3,6 +3,7 @@ package net.torvald.terrarum.ui
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.utils.Disposable
import net.torvald.terrarum.App
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gamecontroller.TerrarumKeyboardEvent
@@ -113,11 +114,11 @@ abstract class UIItem(var parentUI: UICanvas, val initialX: Int, val initialY: I
open var touchUpListener: ((Int, Int, Int, Int) -> Unit)? = null
/** Parameters: amountX, amountY */
open var scrolledListener: ((Float, Float) -> Unit)? = null
/** Parameters: relative mouseX, relative mouseY, button
*
/** Parameters: relative mouseX, relative mouseY
* ClickOnce listeners are only fired when clicked with primary mouse button
* PROTIP: if clickOnceListener does not seem to work, make sure your parent UI is handling touchDown() and touchUp() events!
*/
open var clickOnceListener: ((Int, Int, Int) -> Unit)? = null
open var clickOnceListener: ((Int, Int) -> Unit)? = null
open var clickOnceListenerFired = false
@@ -221,8 +222,8 @@ abstract class UIItem(var parentUI: UICanvas, val initialX: Int, val initialY: I
actionDone = true
}
if (clickOnceListener != null && !clickOnceListenerFired && mouseUp) {
clickOnceListener!!.invoke(itemRelativeMouseX, itemRelativeMouseY, button)
if (clickOnceListener != null && !clickOnceListenerFired && mouseUp && button == App.getConfigInt("config_mouseprimary")) {
clickOnceListener!!.invoke(itemRelativeMouseX, itemRelativeMouseY)
actionDone = true
}
}

View File

@@ -115,7 +115,7 @@ class UIItemIntSlider(
override var scrolledListener: ((Float, Float) -> Unit)?
get() = super.scrolledListener
set(_) {}
override var clickOnceListener: ((Int, Int, Int) -> Unit)?
override var clickOnceListener: ((Int, Int) -> Unit)?
get() = super.clickOnceListener
set(_) {}
override var clickOnceListenerFired: Boolean