mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-12 19:44:05 +09:00
textselector/spinner/quickslot(!) selection change using scroll wheel
This commit is contained in:
@@ -18,6 +18,7 @@ import net.torvald.terrarum.gameactors.AVKey
|
|||||||
import net.torvald.terrarum.gameitem.GameItem
|
import net.torvald.terrarum.gameitem.GameItem
|
||||||
import net.torvald.terrarum.gameworld.fmod
|
import net.torvald.terrarum.gameworld.fmod
|
||||||
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
||||||
|
import net.torvald.terrarum.modulebasegame.ui.UIQuickslotBar
|
||||||
import net.torvald.terrarum.worlddrawer.WorldCamera
|
import net.torvald.terrarum.worlddrawer.WorldCamera
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
@@ -244,14 +245,17 @@ class IngameController(val terrarumIngame: TerrarumIngame) : InputAdapter() {
|
|||||||
override fun scrolled(amountX: Float, amountY: Float): Boolean {
|
override fun scrolled(amountX: Float, amountY: Float): Boolean {
|
||||||
if (!terrarumIngame.paused) {
|
if (!terrarumIngame.paused) {
|
||||||
// quickslot by wheel
|
// quickslot by wheel
|
||||||
if (terrarumIngame.actorNowPlaying != null) {
|
terrarumIngame.actorNowPlaying?.let {
|
||||||
terrarumIngame.actorNowPlaying!!.actorValue.set(
|
var selection = it.actorValue.getAsInt(AVKey.__PLAYER_QUICKSLOTSEL)!!
|
||||||
AVKey.__PLAYER_QUICKSLOTSEL,
|
|
||||||
(terrarumIngame.actorNowPlaying!!.actorValue.getAsInt(AVKey.__PLAYER_QUICKSLOTSEL)!! - amountY.toInt()) fmod terrarumIngame.actorNowPlaying!!.inventory.quickSlot.size
|
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) }
|
terrarumIngame.uiContainer.forEach { it?.scrolled(amountX, amountY) }
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,11 +68,11 @@ class UIQuickslotBar : UICanvas() {
|
|||||||
|
|
||||||
|
|
||||||
override fun doOpening(delta: Float) {
|
override fun doOpening(delta: Float) {
|
||||||
handler.opacity = handler.openCloseCounter.toFloat() / openCloseTime
|
handler.opacity = handler.openCloseCounter / openCloseTime
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun doClosing(delta: Float) {
|
override fun doClosing(delta: Float) {
|
||||||
handler.opacity = (openCloseTime - handler.openCloseCounter.toFloat()) / openCloseTime
|
handler.opacity = (openCloseTime - handler.openCloseCounter) / openCloseTime
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun endOpening(delta: Float) {
|
override fun endOpening(delta: Float) {
|
||||||
@@ -83,14 +83,6 @@ class UIQuickslotBar : UICanvas() {
|
|||||||
handler.opacity = 0f
|
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() {
|
override fun dispose() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -53,6 +53,8 @@ class UIItemSpinner(
|
|||||||
1
|
1
|
||||||
else if (relativeMouseX in width - buttonW..width && relativeMouseY in 0..height)
|
else if (relativeMouseX in width - buttonW..width && relativeMouseY in 0..height)
|
||||||
2
|
2
|
||||||
|
else if (relativeMouseX in buttonW + 3..width - buttonW - 3 && relativeMouseY in 0..height)
|
||||||
|
3
|
||||||
else
|
else
|
||||||
0
|
0
|
||||||
|
|
||||||
@@ -93,8 +95,10 @@ class UIItemSpinner(
|
|||||||
Toolkit.fillArea(batch, posX + width - buttonW, posY, buttonW, height)
|
Toolkit.fillArea(batch, posX + width - buttonW, posY, buttonW, height)
|
||||||
|
|
||||||
// text area border
|
// text area border
|
||||||
batch.color = Toolkit.Theme.COL_INACTIVE
|
if (mouseOnButton != 3) {
|
||||||
Toolkit.drawBoxBorder(batch, posX - 1, posY - 1, width + 2, height + 2)
|
batch.color = Toolkit.Theme.COL_INACTIVE
|
||||||
|
Toolkit.drawBoxBorder(batch, posX - 1, posY - 1, width + 2, height + 2)
|
||||||
|
}
|
||||||
|
|
||||||
// left button border
|
// left button border
|
||||||
batch.color = if (mouseOnButton == 1 && mousePushed) Toolkit.Theme.COL_HIGHLIGHT
|
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
|
batch.color = if (mouseOnButton == 2 && mousePushed) Toolkit.Theme.COL_HIGHLIGHT
|
||||||
else if (mouseOnButton == 2) Toolkit.Theme.COL_ACTIVE else Toolkit.Theme.COL_INACTIVE
|
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)
|
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
|
// left button icon
|
||||||
@@ -125,6 +135,22 @@ class UIItemSpinner(
|
|||||||
super.render(batch, camera)
|
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() {
|
override fun dispose() {
|
||||||
fbo.dispose()
|
fbo.dispose()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,6 +54,8 @@ class UIItemTextSelector(
|
|||||||
1
|
1
|
||||||
else if (relativeMouseX in width - buttonW..width && relativeMouseY in 0..height)
|
else if (relativeMouseX in width - buttonW..width && relativeMouseY in 0..height)
|
||||||
2
|
2
|
||||||
|
else if (relativeMouseX in buttonW + 3..width - buttonW - 3 && relativeMouseY in 0..height)
|
||||||
|
3
|
||||||
else
|
else
|
||||||
0
|
0
|
||||||
|
|
||||||
@@ -94,8 +96,10 @@ class UIItemTextSelector(
|
|||||||
Toolkit.fillArea(batch, posX + width - buttonW, posY, buttonW, height)
|
Toolkit.fillArea(batch, posX + width - buttonW, posY, buttonW, height)
|
||||||
|
|
||||||
// text area border
|
// text area border
|
||||||
batch.color = Toolkit.Theme.COL_INACTIVE
|
if (mouseOnButton != 3) {
|
||||||
Toolkit.drawBoxBorder(batch, posX - 1, posY - 1, width + 2, height + 2)
|
batch.color = Toolkit.Theme.COL_INACTIVE
|
||||||
|
Toolkit.drawBoxBorder(batch, posX - 1, posY - 1, width + 2, height + 2)
|
||||||
|
}
|
||||||
|
|
||||||
// left button border
|
// left button border
|
||||||
batch.color = if (mouseOnButton == 1 && mousePushed) Toolkit.Theme.COL_HIGHLIGHT
|
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
|
batch.color = if (mouseOnButton == 2 && mousePushed) Toolkit.Theme.COL_HIGHLIGHT
|
||||||
else if (mouseOnButton == 2) Toolkit.Theme.COL_ACTIVE else Toolkit.Theme.COL_INACTIVE
|
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)
|
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
|
// left button icon
|
||||||
@@ -126,6 +136,22 @@ class UIItemTextSelector(
|
|||||||
super.render(batch, camera)
|
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() {
|
override fun dispose() {
|
||||||
fbo.dispose()
|
fbo.dispose()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user