mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-10 18:44:05 +09:00
UINSMenu is working again
This commit is contained in:
@@ -4,10 +4,7 @@ import com.badlogic.gdx.graphics.Camera
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.OrthographicCamera
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import net.torvald.terrarum.BlockCodex
|
||||
import net.torvald.terrarum.ItemCodex
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.blendNormalStraightAlpha
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.modulebasegame.BuildingMaker
|
||||
import net.torvald.terrarum.modulebasegame.ui.ItemSlotImageFactory.CELLCOLOUR_WHITE
|
||||
import net.torvald.terrarum.ui.Toolkit
|
||||
@@ -23,7 +20,7 @@ import kotlin.math.roundToInt
|
||||
class UIBuildingMakerBlockChooser(val parent: BuildingMaker): UICanvas() {
|
||||
|
||||
companion object {
|
||||
const val TILES_X = 16
|
||||
const val TILES_X = 8
|
||||
const val TILES_Y = 14
|
||||
|
||||
const val TILESREGION_SIZE = 24
|
||||
@@ -64,11 +61,11 @@ class UIBuildingMakerBlockChooser(val parent: BuildingMaker): UICanvas() {
|
||||
catch (e: NullPointerException) {
|
||||
null
|
||||
}) != null
|
||||
}.forEachIndexed { index, prop ->
|
||||
}.filter { !it.hasTag("INTERNAL") }.forEachIndexed { index, prop ->
|
||||
val paletteItem = UIItemImageButton(
|
||||
this, ItemCodex.getItemImage(prop.id)!!,
|
||||
initialX = MENUBAR_SIZE + (index % 16) * TILESREGION_SIZE,
|
||||
initialY = (index / 16) * TILESREGION_SIZE,
|
||||
initialX = MENUBAR_SIZE + (index % TILES_X) * TILESREGION_SIZE,
|
||||
initialY = (index / TILES_X) * TILESREGION_SIZE,
|
||||
highlightable = false,
|
||||
width = 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 {
|
||||
if (mouseOnDragHandle()) {
|
||||
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.UICanvas
|
||||
import net.torvald.terrarum.ui.UINSMenu
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
/**
|
||||
* 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 {
|
||||
if (mouseInScreen(screenX, screenY)) {
|
||||
if (dragForReal) {
|
||||
handler.setPosition(screenX - dragOriginX, screenY - dragOriginY)
|
||||
//println("drag $screenX, $screenY")
|
||||
handler.setPosition(
|
||||
(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
|
||||
|
||||
override fun updateUI(delta: Float) {
|
||||
if (mouseActionAvailable && Terrarum.mouseDown) {
|
||||
if (mouseActionAvailable) {
|
||||
mouseActionAvailable = false
|
||||
|
||||
remoConTray.update(delta)
|
||||
|
||||
val selectedItem = remoConTray.selectedItem
|
||||
val selectedIndex = remoConTray.selectedIndex
|
||||
if (Terrarum.mouseDown) {
|
||||
val selectedItem = remoConTray.selectedItem
|
||||
val selectedIndex = remoConTray.selectedIndex
|
||||
|
||||
if (!handler.uiToggleLocked) {
|
||||
selectedItem?.let { if (selectedItem != oldSelectedItem) {
|
||||
oldSelectedItem?.highlighted = false
|
||||
if (!handler.uiToggleLocked) {
|
||||
selectedItem?.let {
|
||||
if (selectedItem != oldSelectedItem) {
|
||||
oldSelectedItem?.highlighted = false
|
||||
|
||||
// selection change
|
||||
if (it.textfun() == Lang["MENU_LABEL_QUIT"]) {
|
||||
//System.exit(0)
|
||||
Gdx.app.exit()
|
||||
}
|
||||
else if (it.textfun() == Lang["MENU_LABEL_RETURN"]) {
|
||||
val tag = it.tags
|
||||
if (tag.contains("WRITETOCONFIG")) WriteConfig()
|
||||
// selection change
|
||||
if (it.textfun() == Lang["MENU_LABEL_QUIT"]) {
|
||||
//System.exit(0)
|
||||
Gdx.app.exit()
|
||||
}
|
||||
else if (it.textfun() == Lang["MENU_LABEL_RETURN"]) {
|
||||
val tag = it.tags
|
||||
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) {
|
||||
remoConTray.consume()
|
||||
if (currentRemoConContents.parent != null) {
|
||||
remoConTray.consume()
|
||||
|
||||
currentRemoConContents = currentRemoConContents.parent!!
|
||||
currentlySelectedRemoConItem = currentRemoConContents.data
|
||||
remoConTray = generateNewRemoCon(currentRemoConContents)
|
||||
currentRemoConContents = currentRemoConContents.parent!!
|
||||
currentlySelectedRemoConItem = currentRemoConContents.data
|
||||
remoConTray = generateNewRemoCon(currentRemoConContents)
|
||||
|
||||
parent.uiFakeBlurOverlay.setAsClose()
|
||||
parent.uiFakeBlurOverlay.setAsClose()
|
||||
|
||||
if (IS_DEVELOPMENT_BUILD) println(" to ${currentlySelectedRemoConItem}")
|
||||
}
|
||||
else {
|
||||
throw NullPointerException("No parent node to return")
|
||||
}
|
||||
}
|
||||
else {
|
||||
// check if target exists
|
||||
if (IS_DEVELOPMENT_BUILD) {
|
||||
//println("current node: ${currentRemoConContents.data}")
|
||||
//currentRemoConContents.children.forEach { println("- ${it.data}") }
|
||||
}
|
||||
|
||||
if (currentRemoConContents.children.size > selectedIndex ?: 0x7FFFFFFF) {
|
||||
setNewRemoConContents(currentRemoConContents.children[selectedIndex!!])
|
||||
}
|
||||
else {
|
||||
throw RuntimeException("Index: $selectedIndex, Size: ${currentRemoConContents.children.size}")
|
||||
if (IS_DEVELOPMENT_BUILD) println(" to ${currentlySelectedRemoConItem}")
|
||||
}
|
||||
else {
|
||||
throw NullPointerException("No parent node to return")
|
||||
}
|
||||
}
|
||||
else {
|
||||
// check if target exists
|
||||
if (IS_DEVELOPMENT_BUILD) {
|
||||
//println("current node: ${currentRemoConContents.data}")
|
||||
//currentRemoConContents.children.forEach { println("- ${it.data}") }
|
||||
}
|
||||
|
||||
if (currentRemoConContents.children.size > selectedIndex ?: 0x7FFFFFFF) {
|
||||
setNewRemoConContents(currentRemoConContents.children[selectedIndex!!])
|
||||
}
|
||||
else {
|
||||
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
|
||||
//printdbg(this, "$currentlySelectedRemoConItem")
|
||||
openUI(currentlySelectedRemoConItem)
|
||||
} }
|
||||
oldSelectedItem = remoConTray.selectedItem
|
||||
}
|
||||
|
||||
|
||||
oldSelectedItem = remoConTray.selectedItem
|
||||
}
|
||||
|
||||
|
||||
openUI?.update(delta)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user