fixing mouseUp on NSMenu; making pen on buildingmaker work

This commit is contained in:
minjaesong
2019-02-03 23:53:46 +09:00
parent 8da8fdb863
commit 072f6564fe
8 changed files with 96 additions and 31 deletions

View File

@@ -202,12 +202,29 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
}
private fun updateGame(delta: Float) {
var mouseOnUI = false
WeatherMixer.update(delta, actorNowPlaying, gameWorld)
blockPointingCursor.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)
// make pen work HERE
if (Gdx.input.isTouched && !mouseOnUI) {
makePenWork(Terrarum.mouseTileX, Terrarum.mouseTileY)
// TODO drag support using bresenham's algo
}
}
private fun renderGame() {
@@ -226,6 +243,18 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
override fun 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() {
@@ -254,6 +283,7 @@ class BuildingMakerController(val screen: BuildingMaker) : InputAdapter() {
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 {
screen.uiContainer.forEach { it.touchDragged(screenX, screenY, pointer) }
return true

View File

@@ -11,7 +11,6 @@ import net.torvald.terrarum.blockproperties.Block
import net.torvald.terrarum.fillRect
import net.torvald.terrarum.itemproperties.ItemCodex
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.UINSMenu
@@ -32,7 +31,7 @@ class UIEditorPalette : UICanvas() {
relativeMouseX in 0 until width && relativeMouseY in 0 until LINE_HEIGHT
var fore = Block.STONE_BRICKS
var back = Block.DIRT
var back = Block.GLASS_CRUDE
private val titleText = "Pal."
@@ -40,29 +39,30 @@ class UIEditorPalette : UICanvas() {
init {
// make swap icon, because I can't be bothered to make yet another tga
val swapIconPixmap = Pixmap(12, 12, Pixmap.Format.RGBA8888)
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
val clut = intArrayOf(0, 0xaaaaaaff.toInt(), -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)
swapIconPixmap.dispose()
@@ -92,7 +92,7 @@ class UIEditorPalette : UICanvas() {
// draw swap icon
batch.color = Color.WHITE
batch.draw(swapIcon, 18f, 26f)
batch.draw(swapIcon, 22f, 26f)
}