textselector/spinner/quickslot(!) selection change using scroll wheel

This commit is contained in:
minjaesong
2021-10-23 22:57:17 +09:00
parent 3be5ac96f2
commit a1bad044fd
4 changed files with 68 additions and 20 deletions

View File

@@ -18,6 +18,7 @@ import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.gameitem.GameItem
import net.torvald.terrarum.gameworld.fmod
import net.torvald.terrarum.modulebasegame.TerrarumIngame
import net.torvald.terrarum.modulebasegame.ui.UIQuickslotBar
import net.torvald.terrarum.worlddrawer.WorldCamera
import java.util.*
@@ -244,14 +245,17 @@ class IngameController(val terrarumIngame: TerrarumIngame) : InputAdapter() {
override fun scrolled(amountX: Float, amountY: Float): Boolean {
if (!terrarumIngame.paused) {
// quickslot by wheel
if (terrarumIngame.actorNowPlaying != null) {
terrarumIngame.actorNowPlaying!!.actorValue.set(
AVKey.__PLAYER_QUICKSLOTSEL,
(terrarumIngame.actorNowPlaying!!.actorValue.getAsInt(AVKey.__PLAYER_QUICKSLOTSEL)!! - amountY.toInt()) fmod terrarumIngame.actorNowPlaying!!.inventory.quickSlot.size
)
terrarumIngame.actorNowPlaying?.let {
var selection = it.actorValue.getAsInt(AVKey.__PLAYER_QUICKSLOTSEL)!!
if (amountX <= -1 || amountY <= -1)
selection -= 1
else if (amountX >= 1 || amountY >= 1)
selection += 1
it.actorValue.set(AVKey.__PLAYER_QUICKSLOTSEL, selection fmod UIQuickslotBar.SLOT_COUNT)
}
}
terrarumIngame.uiContainer.forEach { it?.scrolled(amountX, amountY) }
return true
}

View File

@@ -68,11 +68,11 @@ class UIQuickslotBar : UICanvas() {
override fun doOpening(delta: Float) {
handler.opacity = handler.openCloseCounter.toFloat() / openCloseTime
handler.opacity = handler.openCloseCounter / openCloseTime
}
override fun doClosing(delta: Float) {
handler.opacity = (openCloseTime - handler.openCloseCounter.toFloat()) / openCloseTime
handler.opacity = (openCloseTime - handler.openCloseCounter) / openCloseTime
}
override fun endOpening(delta: Float) {
@@ -83,14 +83,6 @@ class UIQuickslotBar : UICanvas() {
handler.opacity = 0f
}
override fun scrolled(amountX: Float, amountY: Float): Boolean {
// super.scrolled(amount) // no UIItems here
selection = selection.plus(if (amountY > 1) 1 else if (amountY < -1) -1 else 0).fmod(SLOT_COUNT)
return true
}
override fun dispose() {
}

View File

@@ -53,6 +53,8 @@ class UIItemSpinner(
1
else if (relativeMouseX in width - buttonW..width && relativeMouseY in 0..height)
2
else if (relativeMouseX in buttonW + 3..width - buttonW - 3 && relativeMouseY in 0..height)
3
else
0
@@ -93,8 +95,10 @@ class UIItemSpinner(
Toolkit.fillArea(batch, posX + width - buttonW, posY, buttonW, height)
// text area border
batch.color = Toolkit.Theme.COL_INACTIVE
Toolkit.drawBoxBorder(batch, posX - 1, posY - 1, width + 2, height + 2)
if (mouseOnButton != 3) {
batch.color = Toolkit.Theme.COL_INACTIVE
Toolkit.drawBoxBorder(batch, posX - 1, posY - 1, width + 2, height + 2)
}
// left button border
batch.color = if (mouseOnButton == 1 && mousePushed) Toolkit.Theme.COL_HIGHLIGHT
@@ -105,6 +109,12 @@ class UIItemSpinner(
batch.color = if (mouseOnButton == 2 && mousePushed) Toolkit.Theme.COL_HIGHLIGHT
else if (mouseOnButton == 2) Toolkit.Theme.COL_ACTIVE else Toolkit.Theme.COL_INACTIVE
Toolkit.drawBoxBorder(batch, posX + width - buttonW - 1, posY - 1, buttonW + 2, height + 2)
// text area border (again)
if (mouseOnButton == 3) {
batch.color = Toolkit.Theme.COL_ACTIVE
Toolkit.drawBoxBorder(batch, posX + buttonW + 2, posY - 1, width - 2*buttonW - 4, height + 2)
}
}
// left button icon
@@ -125,6 +135,22 @@ class UIItemSpinner(
super.render(batch, camera)
}
override fun scrolled(amountX: Float, amountY: Float): Boolean {
if (mouseUp) {
if (amountX <= -1 || amountY <= -1)
value = (value - step).coerceIn(min, max)
else if (amountX >= 1 || amountY >= 1)
value = (value + step).coerceIn(min, max)
selectionChangeListener(value)
fboUpdateLatch = true
return true
}
else {
return false
}
}
override fun dispose() {
fbo.dispose()
}

View File

@@ -54,6 +54,8 @@ class UIItemTextSelector(
1
else if (relativeMouseX in width - buttonW..width && relativeMouseY in 0..height)
2
else if (relativeMouseX in buttonW + 3..width - buttonW - 3 && relativeMouseY in 0..height)
3
else
0
@@ -94,8 +96,10 @@ class UIItemTextSelector(
Toolkit.fillArea(batch, posX + width - buttonW, posY, buttonW, height)
// text area border
batch.color = Toolkit.Theme.COL_INACTIVE
Toolkit.drawBoxBorder(batch, posX - 1, posY - 1, width + 2, height + 2)
if (mouseOnButton != 3) {
batch.color = Toolkit.Theme.COL_INACTIVE
Toolkit.drawBoxBorder(batch, posX - 1, posY - 1, width + 2, height + 2)
}
// left button border
batch.color = if (mouseOnButton == 1 && mousePushed) Toolkit.Theme.COL_HIGHLIGHT
@@ -106,6 +110,12 @@ class UIItemTextSelector(
batch.color = if (mouseOnButton == 2 && mousePushed) Toolkit.Theme.COL_HIGHLIGHT
else if (mouseOnButton == 2) Toolkit.Theme.COL_ACTIVE else Toolkit.Theme.COL_INACTIVE
Toolkit.drawBoxBorder(batch, posX + width - buttonW - 1, posY - 1, buttonW + 2, height + 2)
// text area border (again)
if (mouseOnButton == 3) {
batch.color = Toolkit.Theme.COL_ACTIVE
Toolkit.drawBoxBorder(batch, posX + buttonW + 2, posY - 1, width - 2*buttonW - 4, height + 2)
}
}
// left button icon
@@ -126,6 +136,22 @@ class UIItemTextSelector(
super.render(batch, camera)
}
override fun scrolled(amountX: Float, amountY: Float): Boolean {
if (mouseUp) {
if (amountX <= -1 || amountY <= -1)
selection = (selection - 1) fmod labelfuns.size
else if (amountX >= 1 || amountY >= 1)
selection = (selection + 1) fmod labelfuns.size
selectionChangeListener(selection)
fboUpdateLatch = true
return true
}
else {
return false
}
}
override fun dispose() {
fbo.dispose()
}