mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-09 18:14:06 +09:00
fixing mouseUp on NSMenu; making pen on buildingmaker work
This commit is contained in:
@@ -10,5 +10,5 @@ uniform sampler2D u_texture;
|
|||||||
|
|
||||||
|
|
||||||
void main(void) {
|
void main(void) {
|
||||||
gl_FragColor = texture2D(u_texture, v_texCoords);
|
gl_FragColor = vec4(texture2D(u_texture, v_texCoords).rgb, 1.0);
|
||||||
}
|
}
|
||||||
@@ -239,6 +239,7 @@ public class AppLoader implements ApplicationListener {
|
|||||||
|
|
||||||
private static ShaderProgram shaderBayerSkyboxFill;
|
private static ShaderProgram shaderBayerSkyboxFill;
|
||||||
public static ShaderProgram shaderHicolour;
|
public static ShaderProgram shaderHicolour;
|
||||||
|
public static ShaderProgram shaderPassthru;
|
||||||
public static ShaderProgram shaderColLUT;
|
public static ShaderProgram shaderColLUT;
|
||||||
|
|
||||||
public static Mesh fullscreenQuad;
|
public static Mesh fullscreenQuad;
|
||||||
@@ -293,6 +294,7 @@ public class AppLoader implements ApplicationListener {
|
|||||||
// set GL graphics constants
|
// set GL graphics constants
|
||||||
shaderBayerSkyboxFill = loadShader("assets/4096.vert", "assets/4096_bayer_skyboxfill.frag");
|
shaderBayerSkyboxFill = loadShader("assets/4096.vert", "assets/4096_bayer_skyboxfill.frag");
|
||||||
shaderHicolour = loadShader("assets/4096.vert", "assets/hicolour.frag");
|
shaderHicolour = loadShader("assets/4096.vert", "assets/hicolour.frag");
|
||||||
|
shaderPassthru = loadShader("assets/4096.vert", "assets/passthru.frag");
|
||||||
shaderColLUT = loadShader("assets/4096.vert", "assets/passthru.frag");
|
shaderColLUT = loadShader("assets/4096.vert", "assets/passthru.frag");
|
||||||
|
|
||||||
fullscreenQuad = new Mesh(
|
fullscreenQuad = new Mesh(
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ object PostProcessor {
|
|||||||
if (AppLoader.getConfigBoolean("fxdither"))
|
if (AppLoader.getConfigBoolean("fxdither"))
|
||||||
AppLoader.shaderHicolour
|
AppLoader.shaderHicolour
|
||||||
else
|
else
|
||||||
null
|
AppLoader.shaderPassthru
|
||||||
|
|
||||||
fbo.colorBufferTexture.bind(0)
|
fbo.colorBufferTexture.bind(0)
|
||||||
|
|
||||||
|
|||||||
@@ -202,12 +202,29 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun updateGame(delta: Float) {
|
private fun updateGame(delta: Float) {
|
||||||
|
var mouseOnUI = false
|
||||||
|
|
||||||
|
|
||||||
WeatherMixer.update(delta, actorNowPlaying, gameWorld)
|
WeatherMixer.update(delta, actorNowPlaying, gameWorld)
|
||||||
blockPointingCursor.update(delta)
|
blockPointingCursor.update(delta)
|
||||||
actorNowPlaying?.update(delta)
|
actorNowPlaying?.update(delta)
|
||||||
uiContainer.forEach { it.update(delta) }
|
uiContainer.forEach {
|
||||||
|
it.update(delta)
|
||||||
|
if (it.isVisible && it.mouseUp) {
|
||||||
|
mouseOnUI = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
WorldCamera.update(world, actorNowPlaying)
|
WorldCamera.update(world, actorNowPlaying)
|
||||||
|
|
||||||
|
|
||||||
|
// make pen work HERE
|
||||||
|
if (Gdx.input.isTouched && !mouseOnUI) {
|
||||||
|
|
||||||
|
makePenWork(Terrarum.mouseTileX, Terrarum.mouseTileY)
|
||||||
|
// TODO drag support using bresenham's algo
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun renderGame() {
|
private fun renderGame() {
|
||||||
@@ -226,6 +243,18 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
override fun dispose() {
|
override fun dispose() {
|
||||||
blockPointingCursor.dispose()
|
blockPointingCursor.dispose()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun makePenWork(worldTileX: Int, worldTileY: Int) {
|
||||||
|
val world = gameWorld
|
||||||
|
val palSelection = uiPalette.fore
|
||||||
|
|
||||||
|
when (currentPenMode) {
|
||||||
|
// test paint terrain layer
|
||||||
|
PENMODE_PENCIL -> {
|
||||||
|
world.setTileTerrain(worldTileX, worldTileY, palSelection)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class BuildingMakerController(val screen: BuildingMaker) : InputAdapter() {
|
class BuildingMakerController(val screen: BuildingMaker) : InputAdapter() {
|
||||||
@@ -254,6 +283,7 @@ class BuildingMakerController(val screen: BuildingMaker) : InputAdapter() {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// let left mouse button to paint, because that's how graphic tablets work
|
||||||
override fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean {
|
override fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean {
|
||||||
screen.uiContainer.forEach { it.touchDragged(screenX, screenY, pointer) }
|
screen.uiContainer.forEach { it.touchDragged(screenX, screenY, pointer) }
|
||||||
return true
|
return true
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import net.torvald.terrarum.blockproperties.Block
|
|||||||
import net.torvald.terrarum.fillRect
|
import net.torvald.terrarum.fillRect
|
||||||
import net.torvald.terrarum.itemproperties.ItemCodex
|
import net.torvald.terrarum.itemproperties.ItemCodex
|
||||||
import net.torvald.terrarum.modulebasegame.ui.ItemSlotImageFactory.CELLCOLOUR_BLACK
|
import net.torvald.terrarum.modulebasegame.ui.ItemSlotImageFactory.CELLCOLOUR_BLACK
|
||||||
import net.torvald.terrarum.serialise.toLittle
|
|
||||||
import net.torvald.terrarum.ui.UICanvas
|
import net.torvald.terrarum.ui.UICanvas
|
||||||
import net.torvald.terrarum.ui.UINSMenu
|
import net.torvald.terrarum.ui.UINSMenu
|
||||||
|
|
||||||
@@ -32,7 +31,7 @@ class UIEditorPalette : UICanvas() {
|
|||||||
relativeMouseX in 0 until width && relativeMouseY in 0 until LINE_HEIGHT
|
relativeMouseX in 0 until width && relativeMouseY in 0 until LINE_HEIGHT
|
||||||
|
|
||||||
var fore = Block.STONE_BRICKS
|
var fore = Block.STONE_BRICKS
|
||||||
var back = Block.DIRT
|
var back = Block.GLASS_CRUDE
|
||||||
|
|
||||||
private val titleText = "Pal."
|
private val titleText = "Pal."
|
||||||
|
|
||||||
@@ -40,29 +39,30 @@ class UIEditorPalette : UICanvas() {
|
|||||||
|
|
||||||
init {
|
init {
|
||||||
// make swap icon, because I can't be bothered to make yet another tga
|
// make swap icon, because I can't be bothered to make yet another tga
|
||||||
val swapIconPixmap = Pixmap(12, 12, Pixmap.Format.RGBA8888)
|
val clut = intArrayOf(0, 0xaaaaaaff.toInt(), -1, -1)
|
||||||
swapIconPixmap.pixels.rewind()
|
|
||||||
arrayOf(
|
|
||||||
0b001000000000,
|
|
||||||
0b011000000000,
|
|
||||||
0b111111111100,
|
|
||||||
0b011000000100,
|
|
||||||
0b001000000100,
|
|
||||||
0b000000000100,
|
|
||||||
0b000000000100,
|
|
||||||
0b000000000100,
|
|
||||||
0b000000000100,
|
|
||||||
0b000000011111,
|
|
||||||
0b000000001110,
|
|
||||||
0b000000000100
|
|
||||||
).reversed().forEachIndexed { index, bits ->
|
|
||||||
for (shiftmask in 11 downTo 0) {
|
|
||||||
val bit = bits.ushr(shiftmask).and(1) == 1
|
|
||||||
|
|
||||||
swapIconPixmap.pixels.put((if (bit) -1 else 0).toLittle())
|
val swapIconPixmap = Pixmap(13, 13, Pixmap.Format.RGBA8888)
|
||||||
|
arrayOf(
|
||||||
|
0b00_00_11_01_00_00_00_00_00_00_00_00_00,
|
||||||
|
0b00_11_11_01_00_00_00_00_00_00_00_00_00,
|
||||||
|
0b11_11_11_11_11_11_11_11_11_11_01_00_00,
|
||||||
|
0b01_11_11_01_01_01_01_01_01_11_01_00_00,
|
||||||
|
0b00_01_11_01_00_00_00_00_00_11_01_00_00,
|
||||||
|
0b00_00_01_01_00_00_00_00_00_11_01_00_00,
|
||||||
|
0b00_00_00_00_00_00_00_00_00_11_01_00_00,
|
||||||
|
0b00_00_00_00_00_00_00_00_00_11_01_00_00,
|
||||||
|
0b00_00_00_00_00_00_00_00_00_11_01_00_00,
|
||||||
|
0b00_00_00_00_00_00_00_11_11_11_11_11_01,
|
||||||
|
0b00_00_00_00_00_00_00_01_11_11_11_01_01,
|
||||||
|
0b00_00_00_00_00_00_00_00_01_11_01_01_00,
|
||||||
|
0b00_00_00_00_00_00_00_00_00_01_01_00_00
|
||||||
|
).reversed().forEachIndexed { index, bits ->
|
||||||
|
for (shiftmask in 12 downTo 0) {
|
||||||
|
val bit = bits.ushr(shiftmask * 2).and(3)
|
||||||
|
|
||||||
|
swapIconPixmap.drawPixel(12 - shiftmask, index, clut[bit])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
swapIconPixmap.pixels.rewind()
|
|
||||||
|
|
||||||
swapIcon = Texture(swapIconPixmap)
|
swapIcon = Texture(swapIconPixmap)
|
||||||
swapIconPixmap.dispose()
|
swapIconPixmap.dispose()
|
||||||
@@ -92,7 +92,7 @@ class UIEditorPalette : UICanvas() {
|
|||||||
|
|
||||||
// draw swap icon
|
// draw swap icon
|
||||||
batch.color = Color.WHITE
|
batch.color = Color.WHITE
|
||||||
batch.draw(swapIcon, 18f, 26f)
|
batch.draw(swapIcon, 22f, 26f)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -60,12 +60,14 @@ abstract class UICanvas(
|
|||||||
get() = Terrarum.mouseScreenY - handler.posY
|
get() = Terrarum.mouseScreenY - handler.posY
|
||||||
|
|
||||||
/** If mouse is hovering over it regardless of its visibility */
|
/** If mouse is hovering over it regardless of its visibility */
|
||||||
val mouseUp: Boolean
|
open val mouseUp: Boolean
|
||||||
get() = relativeMouseX in 0..width - 1 && relativeMouseY in 0..height - 1
|
get() = _mouseUpThis || handler.mouseUp
|
||||||
/** 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 && Gdx.input.isButtonPressed(AppLoader.getConfigInt("mouseprimary"))
|
get() = mouseUp && Gdx.input.isButtonPressed(AppLoader.getConfigInt("mouseprimary"))
|
||||||
|
|
||||||
|
private val _mouseUpThis: Boolean
|
||||||
|
get() = relativeMouseX in 0..width - 1 && relativeMouseY in 0..height - 1
|
||||||
|
|
||||||
/** Called by the screen */
|
/** Called by the screen */
|
||||||
fun update(delta: Float) {
|
fun update(delta: Float) {
|
||||||
|
|||||||
@@ -76,6 +76,15 @@ class UIHandler(//var UI: UICanvas,
|
|||||||
|
|
||||||
val subUIs = ArrayList<UICanvas>()
|
val subUIs = ArrayList<UICanvas>()
|
||||||
|
|
||||||
|
val mouseUp: Boolean
|
||||||
|
get() {
|
||||||
|
for (k in 0 until subUIs.size) {
|
||||||
|
val ret2 = subUIs[k].mouseUp
|
||||||
|
if (ret2) return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
fun addSubUI(ui: UICanvas) {
|
fun addSubUI(ui: UICanvas) {
|
||||||
if (subUIs.contains(ui))
|
if (subUIs.contains(ui))
|
||||||
throw IllegalArgumentException(
|
throw IllegalArgumentException(
|
||||||
|
|||||||
@@ -43,12 +43,19 @@ class UINSMenu(
|
|||||||
|
|
||||||
|
|
||||||
private val listStack = ArrayList<MenuPack>()
|
private val listStack = ArrayList<MenuPack>()
|
||||||
|
/** cached version of listStack.size */
|
||||||
private var currentDepth = 0
|
private var currentDepth = 0
|
||||||
|
|
||||||
private data class MenuPack(val title: String, val ui: UIItemTextButtonList)
|
private data class MenuPack(val title: String, val ui: UIItemTextButtonList)
|
||||||
|
|
||||||
private fun ArrayList<MenuPack>.push(item: MenuPack) { this.add(item) }
|
private fun ArrayList<MenuPack>.push(item: MenuPack) {
|
||||||
private fun ArrayList<MenuPack>.pop() = this.removeAt(this.lastIndex)
|
currentDepth += 1
|
||||||
|
this.add(item)
|
||||||
|
}
|
||||||
|
private fun ArrayList<MenuPack>.pop(): MenuPack {
|
||||||
|
currentDepth -= 1
|
||||||
|
return this.removeAt(this.lastIndex)
|
||||||
|
}
|
||||||
private fun ArrayList<MenuPack>.peek() = this.last()
|
private fun ArrayList<MenuPack>.peek() = this.last()
|
||||||
|
|
||||||
|
|
||||||
@@ -61,6 +68,22 @@ class UINSMenu(
|
|||||||
addSubMenu(tree)
|
addSubMenu(tree)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override val mouseUp: Boolean
|
||||||
|
get() {
|
||||||
|
for (sp in 0 until currentDepth) {
|
||||||
|
val subList = listStack[sp].ui
|
||||||
|
|
||||||
|
val _mouseUp = relativeMouseX in subList.posX..subList.posX + subList.width &&
|
||||||
|
relativeMouseY in subList.posY - LINE_HEIGHT..subList.posY + subList.height
|
||||||
|
|
||||||
|
if (_mouseUp) return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME mouseUp doesn't work here
|
||||||
|
|
||||||
private fun addSubMenu(tree: QNDTreeNode<Pair<String, YamlInvokable?>>) {
|
private fun addSubMenu(tree: QNDTreeNode<Pair<String, YamlInvokable?>>) {
|
||||||
val menuTitle = tree.data?.first ?: title
|
val menuTitle = tree.data?.first ?: title
|
||||||
val stringsFromTree = Array<String>(tree.children.size) {
|
val stringsFromTree = Array<String>(tree.children.size) {
|
||||||
@@ -118,7 +141,6 @@ class UINSMenu(
|
|||||||
listStack.push(MenuPack(menuTitle, list))
|
listStack.push(MenuPack(menuTitle, list))
|
||||||
// increment the memoized width
|
// increment the memoized width
|
||||||
width += uiWidth
|
width += uiWidth
|
||||||
currentDepth += 1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun popSubMenu() {
|
private fun popSubMenu() {
|
||||||
|
|||||||
Reference in New Issue
Block a user