worldportal: showing tooltip to tell why the button is disabled

This commit is contained in:
minjaesong
2023-06-30 03:07:45 +09:00
parent e5e02681b8
commit 7c1806946b
6 changed files with 52 additions and 81 deletions

View File

@@ -17,8 +17,7 @@
"GAME_ACTION_CRAFT": "Craft",
"GAME_CRAFTING": "Crafting",
"GAME_CRAFTABLE_ITEMS": "Craftable Items",
"CONTEXT_WORLD_SEARCH": "World Search",
"CONTEXT_WORLD_LIST": "Worlds List",
"MENU_LABEL_RENAME": "Rename",
"GAME_ACTION_TELEPORT": "Teleport"
"GAME_ACTION_TELEPORT": "Teleport",
"CONTEXT_THIS_IS_A_WORLD_CURRENTLY_PLAYING": "This is a world currently playing."
}

View File

@@ -17,5 +17,8 @@
"GAME_ACTION_QUICKSEL": "빠른 선택",
"GAME_ACTION_CRAFT": "제작하기",
"GAME_CRAFTING": "제작",
"GAME_CRAFTABLE_ITEMS": "제작 가능한 아이템"
"GAME_CRAFTABLE_ITEMS": "제작 가능한 아이템",
"MENU_LABEL_RENAME": "이름 바꾸기",
"GAME_ACTION_TELEPORT": "텔레포트하기",
"CONTEXT_THIS_IS_A_WORLD_CURRENTLY_PLAYING": "현재 플레이 중인 월드입니다."
}

View File

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

View File

@@ -8,6 +8,7 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.g2d.TextureRegion
import com.badlogic.gdx.utils.GdxRuntimeException
import net.torvald.terrarum.*
import net.torvald.terrarum.App.printdbg
import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.gameworld.fmod
import net.torvald.terrarum.langpack.Lang
@@ -94,6 +95,7 @@ class UIWorldPortalListing(val full: UIWorldPortal) : UICanvas() {
selected?.worldInfo?.diskSkimmer, null
)
full.setAsClose()
printdbg(this, "Teleport target set: ${full.host.teleportRequest}")
}
}
}
@@ -137,6 +139,7 @@ class UIWorldPortalListing(val full: UIWorldPortal) : UICanvas() {
buttonRename.isActive = false
buttonDelete.isActive = false
buttonTeleport.isActive = false
currentWorldSelected = false
}
private fun highlightListEditButtons(info: WorldInfo?) {
@@ -147,9 +150,12 @@ class UIWorldPortalListing(val full: UIWorldPortal) : UICanvas() {
buttonRename.isActive = true
buttonDelete.isActive = info.uuid != INGAME.world.worldIndex
buttonTeleport.isActive = info.uuid != INGAME.world.worldIndex
currentWorldSelected = info.uuid == INGAME.world.worldIndex
}
}
private var currentWorldSelected = false
init {
CommonResourcePool.addToLoadingList("terrarum-basegame-worldportalicons") {
TextureRegionPack(ModMgr.getGdxFile("basegame", "gui/worldportal_catbar.tga"), 30, 20)
@@ -296,6 +302,10 @@ class UIWorldPortalListing(val full: UIWorldPortal) : UICanvas() {
override fun updateUI(delta: Float) {
uiItems.forEach { it.update(delta) }
if (::worldCells.isInitialized) worldCells.forEach { it.update(delta) }
if (currentWorldSelected) {
INGAME.setTooltipMessage(if (buttonTeleport.mouseUp || buttonDelete.mouseUp) Lang["CONTEXT_THIS_IS_A_WORLD_CURRENTLY_PLAYING"] else null)
}
}
private val iconGap = 12f

View File

@@ -96,32 +96,33 @@ abstract class UIItem(var parentUI: UICanvas, val initialX: Int, val initialY: I
protected var mouseLatched = Terrarum.mouseDown
/** UI to call (show up) while mouse is up */
open val mouseOverCall: UICanvas? = null
open var mouseOverCall: UICanvas? = null
// kind of listener implementation
/** Fired once for every update
* Parameter: delta */
open var updateListener: ((Float) -> Unit)? = null
open var updateListener: ((Float) -> Unit) = {}
/** Parameter: keycode */
open var keyDownListener: ((Int) -> Unit)? = null
open var keyDownListener: ((Int) -> Unit) = {}
/** Parameter: keycode */
open var keyUpListener: ((Int) -> Unit)? = null
open var keyTypedListener: ((Char) -> Unit)? = null
open var touchDraggedListener: ((Int, Int, Int) -> Unit)? = null
open var keyUpListener: ((Int) -> Unit) = {}
open var keyTypedListener: ((Char) -> Unit) = {}
open var touchDraggedListener: ((Int, Int, Int) -> Unit) = { _,_,_ -> }
/** Parameters: screenX, screenY, pointer, button */
@Deprecated("Not really deprecated but you MOST DEFINITELY want to use clickOnceListener(mouseX, mouseY) instead.")
open var touchDownListener: ((Int, Int, Int, Int) -> Unit)? = null
open var touchUpListener: ((Int, Int, Int, Int) -> Unit)? = null
open var touchDownListener: ((Int, Int, Int, Int) -> Unit) = { _,_,_,_ -> }
open var touchUpListener: ((Int, Int, Int, Int) -> Unit) = { _,_,_,_ -> }
/** Parameters: amountX, amountY */
open var scrolledListener: ((Float, Float) -> Unit)? = null
open var scrolledListener: ((Float, Float) -> Unit) = { _,_ -> }
/** 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) -> Unit)? = null
open var clickOnceListener: ((Int, Int) -> Unit) = { _,_ -> }
open var clickOnceListenerFired = false
/** Parameters: relative mouseX, mouseY */
open var mouseUpListener: ((Int, Int) -> Unit) = { _,_, -> }
/** Since gamepads can't just choose which UIItem to control, this variable is used to allow processing of
* gamepad button events for one or more UIItems in one or more UICanvases. */
@@ -139,11 +140,9 @@ abstract class UIItem(var parentUI: UICanvas, val initialX: Int, val initialY: I
open fun update(delta: Float) {
if (parentUI.isVisible) {
if (updateListener != null) {
updateListener!!.invoke(delta)
}
updateListener.invoke(delta)
if (isActive) {
// if (isActive) {
mouseOverCall?.update(delta)
if (mouseUp) {
@@ -152,13 +151,14 @@ abstract class UIItem(var parentUI: UICanvas, val initialX: Int, val initialY: I
}
mouseOverCall?.updateUI(delta)
mouseUpListener.invoke(itemRelativeMouseX, itemRelativeMouseY)
}
else {
if (mouseOverCall?.isVisible == true) {
mouseOverCall?.setAsClose()
}
}
}
// }
if (!mouseUp) mouseLatched = false
}
@@ -169,36 +169,36 @@ abstract class UIItem(var parentUI: UICanvas, val initialX: Int, val initialY: I
*/
open fun render(batch: SpriteBatch, camera: Camera) {
if (parentUI.isVisible) {
if (isActive) {
// if (isActive) {
mouseOverCall?.render(batch, camera)
if (mouseUp) {
mouseOverCall?.renderUI(batch, camera)
}
}
// }
}
}
// keyboard controlled
open fun keyDown(keycode: Int): Boolean {
if (parentUI.isVisible && keyDownListener != null && isActive) {
keyDownListener!!.invoke(keycode)
if (parentUI.isVisible && isActive) {
keyDownListener.invoke(keycode)
return true
}
return false
}
open fun keyUp(keycode: Int): Boolean {
if (parentUI.isVisible && keyUpListener != null && isActive) {
keyUpListener!!.invoke(keycode)
if (parentUI.isVisible && isActive) {
keyUpListener.invoke(keycode)
return true
}
return false
}
open fun keyTyped(character: Char): Boolean {
if (parentUI.isVisible && keyTypedListener != null && isActive) {
keyTypedListener!!.invoke(character)
if (parentUI.isVisible && isActive) {
keyTypedListener.invoke(character)
return true
}
@@ -207,26 +207,24 @@ abstract class UIItem(var parentUI: UICanvas, val initialX: Int, val initialY: I
// mouse controlled
open fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean {
if (parentUI.isVisible && touchDraggedListener != null && isActive) {
touchDraggedListener!!.invoke(itemRelativeMouseX, itemRelativeMouseY, pointer)
if (parentUI.isVisible && isActive) {
touchDraggedListener.invoke(itemRelativeMouseX, itemRelativeMouseY, pointer)
return true
}
return false
}
open fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
// FIXME does not work with magnified screen
var actionDone = false
if (parentUI.isVisible && isActive) {
if (touchDownListener != null && mouseUp) {
touchDownListener!!.invoke(itemRelativeMouseX, itemRelativeMouseY, pointer, button)
if (mouseUp) {
touchDownListener.invoke(itemRelativeMouseX, itemRelativeMouseY, pointer, button)
actionDone = true
}
if (clickOnceListener != null && !clickOnceListenerFired && mouseUp && button == App.getConfigInt("config_mouseprimary")) {
clickOnceListener!!.invoke(itemRelativeMouseX, itemRelativeMouseY)
if (!clickOnceListenerFired && mouseUp && button == App.getConfigInt("config_mouseprimary")) {
clickOnceListener.invoke(itemRelativeMouseX, itemRelativeMouseY)
actionDone = true
}
}
@@ -236,16 +234,16 @@ abstract class UIItem(var parentUI: UICanvas, val initialX: Int, val initialY: I
open fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
clickOnceListenerFired = false
if (parentUI.isVisible && touchUpListener != null && mouseUp) {
touchUpListener!!.invoke(itemRelativeMouseX, itemRelativeMouseY, pointer, button)
if (parentUI.isVisible && mouseUp) {
touchUpListener.invoke(itemRelativeMouseX, itemRelativeMouseY, pointer, button)
return true
}
return false
}
open fun scrolled(amountX: Float, amountY: Float): Boolean {
if (parentUI.isVisible && scrolledListener != null && mouseUp && isActive) {
scrolledListener!!.invoke(amountX, amountY)
if (parentUI.isVisible && mouseUp && isActive) {
scrolledListener.invoke(amountX, amountY)
return true
}

View File

@@ -85,45 +85,6 @@ class UIItemIntSlider(
}
// TODO unimplemented
override val mouseUp: Boolean
get() = super.mouseUp
override val mousePushed: Boolean
get() = super.mousePushed
override val mouseOverCall: UICanvas?
get() = super.mouseOverCall
override var updateListener: ((Float) -> Unit)?
get() = super.updateListener
set(_) {}
override var keyDownListener: ((Int) -> Unit)?
get() = super.keyDownListener
set(_) {}
override var keyUpListener: ((Int) -> Unit)?
get() = super.keyUpListener
set(_) {}
override var touchDraggedListener: ((Int, Int, Int) -> Unit)?
get() = super.touchDraggedListener
set(_) {}
override var touchDownListener: ((Int, Int, Int, Int) -> Unit)?
get() = super.touchDownListener
set(_) {}
override var touchUpListener: ((Int, Int, Int, Int) -> Unit)?
get() = super.touchUpListener
set(_) {}
override var scrolledListener: ((Float, Float) -> Unit)?
get() = super.scrolledListener
set(_) {}
override var clickOnceListener: ((Int, Int) -> Unit)?
get() = super.clickOnceListener
set(_) {}
override var clickOnceListenerFired: Boolean
get() = super.clickOnceListenerFired
set(_) {}
override var controllerInFocus: Boolean
get() = super.controllerInFocus
set(_) {}
override fun dispose() {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.