mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-10 18:44:05 +09:00
working inventory clicking ingame
This commit is contained in:
@@ -3,6 +3,7 @@ package net.torvald.terrarum.gameactors
|
|||||||
import net.torvald.terrarum.Terrarum
|
import net.torvald.terrarum.Terrarum
|
||||||
import net.torvald.terrarum.gameitem.InventoryItem
|
import net.torvald.terrarum.gameitem.InventoryItem
|
||||||
import net.torvald.terrarum.itemproperties.ItemCodex
|
import net.torvald.terrarum.itemproperties.ItemCodex
|
||||||
|
import net.torvald.terrarum.ui.UIInventory
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import java.util.concurrent.locks.Lock
|
import java.util.concurrent.locks.Lock
|
||||||
import java.util.concurrent.locks.ReentrantLock
|
import java.util.concurrent.locks.ReentrantLock
|
||||||
|
|||||||
@@ -125,3 +125,7 @@ val GameContainer.mouseTileX: Int
|
|||||||
/** currently pointing tile coordinate */
|
/** currently pointing tile coordinate */
|
||||||
val GameContainer.mouseTileY: Int
|
val GameContainer.mouseTileY: Int
|
||||||
get() = GameController.mouseTileY
|
get() = GameController.mouseTileY
|
||||||
|
val GameContainer.mouseScreenX: Int
|
||||||
|
get() = Terrarum.appgc.input.mouseX
|
||||||
|
val GameContainer.mouseScreenY: Int
|
||||||
|
get() = Terrarum.appgc.input.mouseY
|
||||||
|
|||||||
@@ -20,7 +20,8 @@ import org.newdawn.slick.state.StateBasedGame
|
|||||||
class UIHandler(val UI: UICanvas,
|
class UIHandler(val UI: UICanvas,
|
||||||
val toggleKey: Int? = null, val toggleButton: Int? = null,
|
val toggleKey: Int? = null, val toggleButton: Int? = null,
|
||||||
// UI positions itself? (you must g.flush() yourself after the g.translate(Int, Int))
|
// UI positions itself? (you must g.flush() yourself after the g.translate(Int, Int))
|
||||||
var customPositioning: Boolean = false
|
var customPositioning: Boolean = false,
|
||||||
|
val doNotWarnConstant: Boolean = false
|
||||||
) {
|
) {
|
||||||
|
|
||||||
// X/Y Position relative to the game window.
|
// X/Y Position relative to the game window.
|
||||||
@@ -48,6 +49,12 @@ class UIHandler(val UI: UICanvas,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* being TRUE for only one frame when the UI is told to open
|
||||||
|
*/
|
||||||
|
var openFired = false
|
||||||
|
var closeFired = false
|
||||||
|
|
||||||
var opacity = 1f
|
var opacity = 1f
|
||||||
var scale = 1f
|
var scale = 1f
|
||||||
|
|
||||||
@@ -70,6 +77,9 @@ class UIHandler(val UI: UICanvas,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (openFired && openCloseCounter > 9) openFired = false
|
||||||
|
if (closeFired && openCloseCounter > 9) closeFired = false
|
||||||
|
|
||||||
|
|
||||||
if (isVisible || alwaysVisible) {
|
if (isVisible || alwaysVisible) {
|
||||||
UI.update(gc, delta)
|
UI.update(gc, delta)
|
||||||
@@ -142,7 +152,7 @@ class UIHandler(val UI: UICanvas,
|
|||||||
* Send OPEN signal to the attached UI.
|
* Send OPEN signal to the attached UI.
|
||||||
*/
|
*/
|
||||||
fun setAsOpen() {
|
fun setAsOpen() {
|
||||||
if (alwaysVisible) {
|
if (alwaysVisible && !doNotWarnConstant) {
|
||||||
throw RuntimeException("[UIHandler] Tried to 'open' constant UI")
|
throw RuntimeException("[UIHandler] Tried to 'open' constant UI")
|
||||||
}
|
}
|
||||||
if (!isOpened && !isOpening) {
|
if (!isOpened && !isOpening) {
|
||||||
@@ -150,6 +160,8 @@ class UIHandler(val UI: UICanvas,
|
|||||||
isOpening = true
|
isOpening = true
|
||||||
isClosing = false
|
isClosing = false
|
||||||
isVisible = true
|
isVisible = true
|
||||||
|
|
||||||
|
openFired = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,13 +169,15 @@ class UIHandler(val UI: UICanvas,
|
|||||||
* Send CLOSE signal to the attached UI.
|
* Send CLOSE signal to the attached UI.
|
||||||
*/
|
*/
|
||||||
fun setAsClose() {
|
fun setAsClose() {
|
||||||
if (alwaysVisible) {
|
if (alwaysVisible && !doNotWarnConstant) {
|
||||||
throw RuntimeException("[UIHandler] Tried to 'close' constant UI")
|
throw RuntimeException("[UIHandler] Tried to 'close' constant UI")
|
||||||
}
|
}
|
||||||
if ((isOpening || isOpened) && !isClosing && isVisible) {
|
if ((isOpening || isOpened) && !isClosing && isVisible) {
|
||||||
isOpened = false
|
isOpened = false
|
||||||
isClosing = true
|
isClosing = true
|
||||||
isOpening = false
|
isOpening = false
|
||||||
|
|
||||||
|
closeFired = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,7 +185,7 @@ class UIHandler(val UI: UICanvas,
|
|||||||
get() = !isOpened && !isClosing && !isOpening
|
get() = !isOpened && !isClosing && !isOpening
|
||||||
|
|
||||||
fun toggleOpening() {
|
fun toggleOpening() {
|
||||||
if (alwaysVisible) {
|
if (alwaysVisible && !doNotWarnConstant) {
|
||||||
throw RuntimeException("[UIHandler] Tried to 'toggle opening of' constant UI")
|
throw RuntimeException("[UIHandler] Tried to 'toggle opening of' constant UI")
|
||||||
}
|
}
|
||||||
if (isVisible) {
|
if (isVisible) {
|
||||||
|
|||||||
@@ -105,10 +105,11 @@ class UIInventory(
|
|||||||
override fun update(gc: GameContainer, delta: Int) {
|
override fun update(gc: GameContainer, delta: Int) {
|
||||||
catButtons.update(gc, delta)
|
catButtons.update(gc, delta)
|
||||||
|
|
||||||
|
|
||||||
if (actor != null && inventory != null) {
|
if (actor != null && inventory != null) {
|
||||||
// monitor and check if category selection has been changed
|
// monitor and check if category selection has been changed
|
||||||
if (oldCatSelect != catButtons.selectedIndex) {
|
// OR UI is being opened from closed state
|
||||||
|
if (oldCatSelect != catButtons.selectedIndex ||
|
||||||
|
!rebuildList && handler!!.openFired) {
|
||||||
rebuildList = true
|
rebuildList = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ package net.torvald.terrarum.ui
|
|||||||
|
|
||||||
import net.torvald.terrarum.Terrarum
|
import net.torvald.terrarum.Terrarum
|
||||||
import net.torvald.terrarum.gameactors.roundInt
|
import net.torvald.terrarum.gameactors.roundInt
|
||||||
import net.torvald.terrarum.gamecontroller.mouseX
|
import net.torvald.terrarum.gamecontroller.mouseScreenX
|
||||||
import net.torvald.terrarum.gamecontroller.mouseY
|
import net.torvald.terrarum.gamecontroller.mouseScreenY
|
||||||
import org.newdawn.slick.GameContainer
|
import org.newdawn.slick.GameContainer
|
||||||
import org.newdawn.slick.Graphics
|
import org.newdawn.slick.Graphics
|
||||||
|
|
||||||
@@ -19,9 +19,9 @@ abstract class UIItem(var parentUI: UICanvas) { // do not replace parentUI to UI
|
|||||||
abstract val height: Int
|
abstract val height: Int
|
||||||
|
|
||||||
protected val relativeMouseX: Int
|
protected val relativeMouseX: Int
|
||||||
get() = (Terrarum.appgc.mouseX - (parentUI.handler?.posX ?: 0) - this.posX).roundInt()
|
get() = (Terrarum.appgc.mouseScreenX - (parentUI.handler?.posX ?: 0) - this.posX)
|
||||||
protected val relativeMouseY: Int
|
protected val relativeMouseY: Int
|
||||||
get() = (Terrarum.appgc.mouseY - (parentUI.handler?.posY ?: 0) - this.posY).roundInt()
|
get() = (Terrarum.appgc.mouseScreenY - (parentUI.handler?.posY ?: 0) - this.posY)
|
||||||
|
|
||||||
open val mouseUp: Boolean
|
open val mouseUp: Boolean
|
||||||
get() = relativeMouseX in 0..width - 1 && relativeMouseY in 0..height - 1
|
get() = relativeMouseX in 0..width - 1 && relativeMouseY in 0..height - 1
|
||||||
|
|||||||
@@ -52,8 +52,6 @@ class UIVitalMetre(
|
|||||||
Terrarum.HALFW,
|
Terrarum.HALFW,
|
||||||
Terrarum.HALFH
|
Terrarum.HALFH
|
||||||
)
|
)
|
||||||
|
|
||||||
handler!!.customPositioning = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user