mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-11 11:04:05 +09:00
UINSMenu is working again
This commit is contained in:
@@ -262,6 +262,8 @@ object Terrarum : Disposable {
|
|||||||
get() = 1.0 / Gdx.graphics.deltaTime
|
get() = 1.0 / Gdx.graphics.deltaTime
|
||||||
val mouseDown: Boolean
|
val mouseDown: Boolean
|
||||||
get() = Gdx.input.isButtonPressed(App.getConfigInt("config_mouseprimary"))
|
get() = Gdx.input.isButtonPressed(App.getConfigInt("config_mouseprimary"))
|
||||||
|
val mouseJustDown: Boolean
|
||||||
|
get() = Gdx.input.isButtonJustPressed(App.getConfigInt("config_mouseprimary"))
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -4,10 +4,7 @@ import com.badlogic.gdx.graphics.Camera
|
|||||||
import com.badlogic.gdx.graphics.Color
|
import com.badlogic.gdx.graphics.Color
|
||||||
import com.badlogic.gdx.graphics.OrthographicCamera
|
import com.badlogic.gdx.graphics.OrthographicCamera
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||||
import net.torvald.terrarum.BlockCodex
|
import net.torvald.terrarum.*
|
||||||
import net.torvald.terrarum.ItemCodex
|
|
||||||
import net.torvald.terrarum.Terrarum
|
|
||||||
import net.torvald.terrarum.blendNormalStraightAlpha
|
|
||||||
import net.torvald.terrarum.modulebasegame.BuildingMaker
|
import net.torvald.terrarum.modulebasegame.BuildingMaker
|
||||||
import net.torvald.terrarum.modulebasegame.ui.ItemSlotImageFactory.CELLCOLOUR_WHITE
|
import net.torvald.terrarum.modulebasegame.ui.ItemSlotImageFactory.CELLCOLOUR_WHITE
|
||||||
import net.torvald.terrarum.ui.Toolkit
|
import net.torvald.terrarum.ui.Toolkit
|
||||||
@@ -23,7 +20,7 @@ import kotlin.math.roundToInt
|
|||||||
class UIBuildingMakerBlockChooser(val parent: BuildingMaker): UICanvas() {
|
class UIBuildingMakerBlockChooser(val parent: BuildingMaker): UICanvas() {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val TILES_X = 16
|
const val TILES_X = 8
|
||||||
const val TILES_Y = 14
|
const val TILES_Y = 14
|
||||||
|
|
||||||
const val TILESREGION_SIZE = 24
|
const val TILESREGION_SIZE = 24
|
||||||
@@ -64,11 +61,11 @@ class UIBuildingMakerBlockChooser(val parent: BuildingMaker): UICanvas() {
|
|||||||
catch (e: NullPointerException) {
|
catch (e: NullPointerException) {
|
||||||
null
|
null
|
||||||
}) != null
|
}) != null
|
||||||
}.forEachIndexed { index, prop ->
|
}.filter { !it.hasTag("INTERNAL") }.forEachIndexed { index, prop ->
|
||||||
val paletteItem = UIItemImageButton(
|
val paletteItem = UIItemImageButton(
|
||||||
this, ItemCodex.getItemImage(prop.id)!!,
|
this, ItemCodex.getItemImage(prop.id)!!,
|
||||||
initialX = MENUBAR_SIZE + (index % 16) * TILESREGION_SIZE,
|
initialX = MENUBAR_SIZE + (index % TILES_X) * TILESREGION_SIZE,
|
||||||
initialY = (index / 16) * TILESREGION_SIZE,
|
initialY = (index / TILES_X) * TILESREGION_SIZE,
|
||||||
highlightable = false,
|
highlightable = false,
|
||||||
width = TILESREGION_SIZE,
|
width = TILESREGION_SIZE,
|
||||||
height = TILESREGION_SIZE,
|
height = TILESREGION_SIZE,
|
||||||
@@ -172,7 +169,10 @@ class UIBuildingMakerBlockChooser(val parent: BuildingMaker): UICanvas() {
|
|||||||
override fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean {
|
override fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean {
|
||||||
if (mouseOnDragHandle()) {
|
if (mouseOnDragHandle()) {
|
||||||
if (dragForReal) {
|
if (dragForReal) {
|
||||||
handler.setPosition(screenX - dragOriginX, screenY - dragOriginY)
|
handler.setPosition(
|
||||||
|
(screenX / App.scr.magn - dragOriginX).roundToInt(),
|
||||||
|
(screenY / App.scr.magn - dragOriginY).roundToInt()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import net.torvald.terrarum.modulebasegame.ui.ItemSlotImageFactory.CELLCOLOUR_BL
|
|||||||
import net.torvald.terrarum.ui.Toolkit
|
import net.torvald.terrarum.ui.Toolkit
|
||||||
import net.torvald.terrarum.ui.UICanvas
|
import net.torvald.terrarum.ui.UICanvas
|
||||||
import net.torvald.terrarum.ui.UINSMenu
|
import net.torvald.terrarum.ui.UINSMenu
|
||||||
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by minjaesong on 2019-02-03.
|
* Created by minjaesong on 2019-02-03.
|
||||||
@@ -128,8 +129,10 @@ class UIPaletteSelector(val parent: BuildingMaker) : UICanvas() {
|
|||||||
override fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean {
|
override fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean {
|
||||||
if (mouseInScreen(screenX, screenY)) {
|
if (mouseInScreen(screenX, screenY)) {
|
||||||
if (dragForReal) {
|
if (dragForReal) {
|
||||||
handler.setPosition(screenX - dragOriginX, screenY - dragOriginY)
|
handler.setPosition(
|
||||||
//println("drag $screenX, $screenY")
|
(screenX / App.scr.magn - dragOriginX).roundToInt(),
|
||||||
|
(screenY / App.scr.magn - dragOriginY).roundToInt()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -91,71 +91,74 @@ open class UIRemoCon(val parent: TitleScreen, val treeRoot: QNDTreeNode<String>)
|
|||||||
private var openUI: UICanvas? = null
|
private var openUI: UICanvas? = null
|
||||||
|
|
||||||
override fun updateUI(delta: Float) {
|
override fun updateUI(delta: Float) {
|
||||||
if (mouseActionAvailable && Terrarum.mouseDown) {
|
if (mouseActionAvailable) {
|
||||||
mouseActionAvailable = false
|
mouseActionAvailable = false
|
||||||
|
|
||||||
remoConTray.update(delta)
|
remoConTray.update(delta)
|
||||||
|
|
||||||
val selectedItem = remoConTray.selectedItem
|
if (Terrarum.mouseDown) {
|
||||||
val selectedIndex = remoConTray.selectedIndex
|
val selectedItem = remoConTray.selectedItem
|
||||||
|
val selectedIndex = remoConTray.selectedIndex
|
||||||
|
|
||||||
if (!handler.uiToggleLocked) {
|
if (!handler.uiToggleLocked) {
|
||||||
selectedItem?.let { if (selectedItem != oldSelectedItem) {
|
selectedItem?.let {
|
||||||
oldSelectedItem?.highlighted = false
|
if (selectedItem != oldSelectedItem) {
|
||||||
|
oldSelectedItem?.highlighted = false
|
||||||
|
|
||||||
// selection change
|
// selection change
|
||||||
if (it.textfun() == Lang["MENU_LABEL_QUIT"]) {
|
if (it.textfun() == Lang["MENU_LABEL_QUIT"]) {
|
||||||
//System.exit(0)
|
//System.exit(0)
|
||||||
Gdx.app.exit()
|
Gdx.app.exit()
|
||||||
}
|
}
|
||||||
else if (it.textfun() == Lang["MENU_LABEL_RETURN"]) {
|
else if (it.textfun() == Lang["MENU_LABEL_RETURN"]) {
|
||||||
val tag = it.tags
|
val tag = it.tags
|
||||||
if (tag.contains("WRITETOCONFIG")) WriteConfig()
|
if (tag.contains("WRITETOCONFIG")) WriteConfig()
|
||||||
|
|
||||||
if (IS_DEVELOPMENT_BUILD) print("[UIRemoCon] Returning from ${currentRemoConContents.data}")
|
if (IS_DEVELOPMENT_BUILD) print("[UIRemoCon] Returning from ${currentRemoConContents.data}")
|
||||||
|
|
||||||
if (currentRemoConContents.parent != null) {
|
if (currentRemoConContents.parent != null) {
|
||||||
remoConTray.consume()
|
remoConTray.consume()
|
||||||
|
|
||||||
currentRemoConContents = currentRemoConContents.parent!!
|
currentRemoConContents = currentRemoConContents.parent!!
|
||||||
currentlySelectedRemoConItem = currentRemoConContents.data
|
currentlySelectedRemoConItem = currentRemoConContents.data
|
||||||
remoConTray = generateNewRemoCon(currentRemoConContents)
|
remoConTray = generateNewRemoCon(currentRemoConContents)
|
||||||
|
|
||||||
parent.uiFakeBlurOverlay.setAsClose()
|
parent.uiFakeBlurOverlay.setAsClose()
|
||||||
|
|
||||||
if (IS_DEVELOPMENT_BUILD) println(" to ${currentlySelectedRemoConItem}")
|
if (IS_DEVELOPMENT_BUILD) println(" to ${currentlySelectedRemoConItem}")
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw NullPointerException("No parent node to return")
|
throw NullPointerException("No parent node to return")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// check if target exists
|
// check if target exists
|
||||||
if (IS_DEVELOPMENT_BUILD) {
|
if (IS_DEVELOPMENT_BUILD) {
|
||||||
//println("current node: ${currentRemoConContents.data}")
|
//println("current node: ${currentRemoConContents.data}")
|
||||||
//currentRemoConContents.children.forEach { println("- ${it.data}") }
|
//currentRemoConContents.children.forEach { println("- ${it.data}") }
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentRemoConContents.children.size > selectedIndex ?: 0x7FFFFFFF) {
|
if (currentRemoConContents.children.size > selectedIndex ?: 0x7FFFFFFF) {
|
||||||
setNewRemoConContents(currentRemoConContents.children[selectedIndex!!])
|
setNewRemoConContents(currentRemoConContents.children[selectedIndex!!])
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw RuntimeException("Index: $selectedIndex, Size: ${currentRemoConContents.children.size}")
|
throw RuntimeException("Index: $selectedIndex, Size: ${currentRemoConContents.children.size}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// do something with the actual selection
|
||||||
|
//printdbg(this, "$currentlySelectedRemoConItem")
|
||||||
|
openUI(currentlySelectedRemoConItem)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// do something with the actual selection
|
oldSelectedItem = remoConTray.selectedItem
|
||||||
//printdbg(this, "$currentlySelectedRemoConItem")
|
|
||||||
openUI(currentlySelectedRemoConItem)
|
|
||||||
} }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
oldSelectedItem = remoConTray.selectedItem
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
openUI?.update(delta)
|
openUI?.update(delta)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -92,6 +92,8 @@ abstract class UIItem(var parentUI: UICanvas, val initialX: Int, val initialY: I
|
|||||||
/** If mouse is hovering over it and mouse is down */
|
/** If mouse is hovering over it and mouse is down */
|
||||||
val mousePushed: Boolean
|
val mousePushed: Boolean
|
||||||
get() = mouseUp && Terrarum.mouseDown
|
get() = mouseUp && Terrarum.mouseDown
|
||||||
|
val mouseJustPushed: Boolean
|
||||||
|
get() = mouseUp && Terrarum.mouseJustDown
|
||||||
val mouseDown: Boolean
|
val mouseDown: Boolean
|
||||||
get() = Terrarum.mouseDown
|
get() = Terrarum.mouseDown
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import com.badlogic.gdx.graphics.OrthographicCamera
|
|||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||||
import net.torvald.terrarum.BlendMode
|
import net.torvald.terrarum.BlendMode
|
||||||
import net.torvald.terrarum.Second
|
import net.torvald.terrarum.Second
|
||||||
|
import net.torvald.terrarum.Terrarum
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -57,8 +58,18 @@ class UIItemList<Item: UIItem>(
|
|||||||
/** (oldIndex: Int?, newIndex: Int) -> Unit */
|
/** (oldIndex: Int?, newIndex: Int) -> Unit */
|
||||||
var selectionChangeListener: ((Int?, Int) -> Unit)? = null
|
var selectionChangeListener: ((Int?, Int) -> Unit)? = null
|
||||||
|
|
||||||
|
private var clickLatched = false
|
||||||
|
|
||||||
|
override fun show() {
|
||||||
|
clickLatched = true
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
override fun update(delta: Float) {
|
override fun update(delta: Float) {
|
||||||
|
val posXDelta = posX - oldPosX
|
||||||
|
itemList.forEach { it.posX += posXDelta }
|
||||||
|
|
||||||
|
|
||||||
if (highlighterMoving) {
|
if (highlighterMoving) {
|
||||||
highlighterMoveTimer += delta
|
highlighterMoveTimer += delta
|
||||||
|
|
||||||
@@ -83,7 +94,7 @@ class UIItemList<Item: UIItem>(
|
|||||||
item.update(delta)
|
item.update(delta)
|
||||||
|
|
||||||
|
|
||||||
if (item.mousePushed && index != selectedIndex) {
|
if (!clickLatched && item.mousePushed) {
|
||||||
val oldIndex = selectedIndex
|
val oldIndex = selectedIndex
|
||||||
|
|
||||||
if (kinematic) {
|
if (kinematic) {
|
||||||
@@ -102,6 +113,12 @@ class UIItemList<Item: UIItem>(
|
|||||||
//item.highlighted = (index == selectedIndex) // forcibly highlight if this.highlighted != null
|
//item.highlighted = (index == selectedIndex) // forcibly highlight if this.highlighted != null
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!Terrarum.mouseDown) {
|
||||||
|
clickLatched = false
|
||||||
|
}
|
||||||
|
|
||||||
|
oldPosX = posX
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun render(batch: SpriteBatch, camera: OrthographicCamera) {
|
override fun render(batch: SpriteBatch, camera: OrthographicCamera) {
|
||||||
|
|||||||
@@ -197,7 +197,8 @@ class UIItemTextButtonList(
|
|||||||
btn.update(delta)
|
btn.update(delta)
|
||||||
|
|
||||||
|
|
||||||
if (!clickLatched && btn.mousePushed && index != selectedIndex) {
|
if (!clickLatched && btn.mousePushed) {
|
||||||
|
clickLatched = true
|
||||||
val oldIndex = selectedIndex
|
val oldIndex = selectedIndex
|
||||||
|
|
||||||
// if (kinematic) {
|
// if (kinematic) {
|
||||||
@@ -214,10 +215,9 @@ class UIItemTextButtonList(
|
|||||||
selectionChangeListener?.invoke(oldIndex, index)
|
selectionChangeListener?.invoke(oldIndex, index)
|
||||||
}
|
}
|
||||||
btn.highlighted = (index == selectedIndex) // forcibly highlight if this.highlighted != null
|
btn.highlighted = (index == selectedIndex) // forcibly highlight if this.highlighted != null
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Terrarum.mouseDown) {
|
if (clickLatched && !Terrarum.mouseDown) {
|
||||||
clickLatched = false
|
clickLatched = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import com.badlogic.gdx.graphics.OrthographicCamera
|
|||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||||
import net.torvald.terrarum.*
|
import net.torvald.terrarum.*
|
||||||
import kotlin.math.max
|
import kotlin.math.max
|
||||||
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Nextstep-themed menu bar with mandatory title line
|
* Nextstep-themed menu bar with mandatory title line
|
||||||
@@ -102,14 +103,14 @@ class UINSMenu(
|
|||||||
|
|
||||||
val list = UIItemTextButtonList(
|
val list = UIItemTextButtonList(
|
||||||
this,
|
this,
|
||||||
UIItemTextButtonList.DEFAULT_LINE_HEIGHT,
|
LINE_HEIGHT,
|
||||||
stringsFromTree,
|
stringsFromTree,
|
||||||
width, LINE_HEIGHT,
|
width, LINE_HEIGHT,
|
||||||
uiWidth, listHeight,
|
uiWidth, listHeight,
|
||||||
textAreaWidth = listWidth,
|
textAreaWidth = listWidth,
|
||||||
alignment = UIItemTextButton.Companion.Alignment.LEFT,
|
alignment = UIItemTextButton.Companion.Alignment.LEFT,
|
||||||
inactiveCol = Color(.94f, .94f, .94f, 1f),
|
inactiveCol = Color(.94f, .94f, .94f, 1f),
|
||||||
itemHitboxSize = LINE_HEIGHT,
|
itemHitboxSize = LINE_HEIGHT - 2,
|
||||||
backgroundCol = UIItemTextButtonList.DEFAULT_BACKGROUNDCOL
|
backgroundCol = UIItemTextButtonList.DEFAULT_BACKGROUNDCOL
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -129,13 +130,18 @@ class UINSMenu(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 2. push the new menu
|
// 2. push the new menu
|
||||||
if (tree.children[new].children.isNotEmpty()) {
|
if (old != new) {
|
||||||
addSubMenu(tree.children[new])
|
if (tree.children[new].children.isNotEmpty()) {
|
||||||
}
|
addSubMenu(tree.children[new])
|
||||||
|
}
|
||||||
|
|
||||||
// invoke whatever command there is
|
// invoke whatever command there is
|
||||||
//printdbg(this, "Selected: ${tree.children[new].data?.second}")
|
//printdbg(this, "Selected: ${tree.children[new].data?.second}")
|
||||||
tree.children[new].data?.second?.invoke(invocationArgument)
|
tree.children[new].data?.second?.invoke(invocationArgument)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
list.selectedIndex = null // deselect if old == new
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// END List selection change listener
|
// END List selection change listener
|
||||||
|
|
||||||
@@ -216,8 +222,10 @@ class UINSMenu(
|
|||||||
|
|
||||||
if (mouseInScreen(screenX, screenY)) {
|
if (mouseInScreen(screenX, screenY)) {
|
||||||
if (dragForReal) {
|
if (dragForReal) {
|
||||||
handler.setPosition(screenX - dragOriginX, screenY - dragOriginY)
|
handler.setPosition(
|
||||||
//println("drag $screenX, $screenY")
|
(screenX / App.scr.magn - dragOriginX).roundToInt(),
|
||||||
|
(screenY / App.scr.magn - dragOriginY).roundToInt()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user