buildingmaker: better handling of mouse latching for pens

This commit is contained in:
minjaesong
2023-10-25 13:46:28 +09:00
parent 98d7c9f326
commit 9a233b8c55

View File

@@ -10,6 +10,7 @@ import net.torvald.terrarum.App.printdbg
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
import net.torvald.terrarum.blockproperties.Block import net.torvald.terrarum.blockproperties.Block
import net.torvald.terrarum.blockproperties.BlockPropUtil import net.torvald.terrarum.blockproperties.BlockPropUtil
import net.torvald.terrarum.blockstats.TileSurvey
import net.torvald.terrarum.gameactors.* import net.torvald.terrarum.gameactors.*
import net.torvald.terrarum.gamecontroller.TerrarumKeyboardEvent import net.torvald.terrarum.gamecontroller.TerrarumKeyboardEvent
import net.torvald.terrarum.gameitems.ItemID import net.torvald.terrarum.gameitems.ItemID
@@ -18,6 +19,7 @@ import net.torvald.terrarum.gameworld.BlockLayerI16
import net.torvald.terrarum.gameworld.GameWorld import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.gameworld.GameWorld.Companion.TERRAIN import net.torvald.terrarum.gameworld.GameWorld.Companion.TERRAIN
import net.torvald.terrarum.gameworld.GameWorld.Companion.WALL import net.torvald.terrarum.gameworld.GameWorld.Companion.WALL
import net.torvald.terrarum.gameworld.WorldSimulator
import net.torvald.terrarum.modulebasegame.gameactors.ActorHumanoid import net.torvald.terrarum.modulebasegame.gameactors.ActorHumanoid
import net.torvald.terrarum.gameworld.WorldTime import net.torvald.terrarum.gameworld.WorldTime
import net.torvald.terrarum.modulebasegame.ui.UIBuildingMakerBlockChooser import net.torvald.terrarum.modulebasegame.ui.UIBuildingMakerBlockChooser
@@ -31,6 +33,7 @@ import net.torvald.terrarum.weather.WeatherMixer
import net.torvald.terrarum.ui.UINSMenu import net.torvald.terrarum.ui.UINSMenu
import net.torvald.terrarum.utils.OrePlacement import net.torvald.terrarum.utils.OrePlacement
import net.torvald.terrarum.worlddrawer.BlocksDrawer import net.torvald.terrarum.worlddrawer.BlocksDrawer
import net.torvald.terrarum.worlddrawer.LightmapRenderer
import net.torvald.terrarum.worlddrawer.WorldCamera import net.torvald.terrarum.worlddrawer.WorldCamera
import net.torvald.util.CircularArray import net.torvald.util.CircularArray
import java.io.File import java.io.File
@@ -339,7 +342,6 @@ class BuildingMaker(batch: FlippingSpriteBatch) : IngameInstance(batch) {
private val updateGame = { delta: Float -> private val updateGame = { delta: Float ->
WeatherMixer.update(delta, actorNowPlaying, gameWorld)
blockPointingCursor.update(delta) blockPointingCursor.update(delta)
if (!keyboardUsedByTextInput) { if (!keyboardUsedByTextInput) {
@@ -388,11 +390,68 @@ class BuildingMaker(batch: FlippingSpriteBatch) : IngameInstance(batch) {
BlockPropUtil.dynamicLumFuncTickClock() BlockPropUtil.dynamicLumFuncTickClock()
WeatherMixer.update(delta, actorNowPlaying, gameWorld)
if (WORLD_UPDATE_TIMER % 2 == 1) {
fillUpWiresBuffer()
}
musicGovernor.update(this, delta) musicGovernor.update(this, delta)
} }
private val maxRenderableWires = ReferencingRanges.ACTORS_WIRES.last - ReferencingRanges.ACTORS_WIRES.first + 1
private val wireActorsContainer = Array(maxRenderableWires) { WireActor(ReferencingRanges.ACTORS_WIRES.first + it).let {
forceAddActor(it)
/*^let*/ it
} }
var selectedWireRenderClass = ""
private var oldSelectedWireRenderClass = ""
private fun fillUpWiresBuffer() {
val for_y_start = (WorldCamera.y.toFloat() / TILE_SIZE).floorToInt() - LightmapRenderer.LIGHTMAP_OVERRENDER
val for_y_end = for_y_start + BlocksDrawer.tilesInVertical + 2* LightmapRenderer.LIGHTMAP_OVERRENDER
val for_x_start = (WorldCamera.x.toFloat() / TILE_SIZE).floorToInt() - LightmapRenderer.LIGHTMAP_OVERRENDER
val for_x_end = for_x_start + BlocksDrawer.tilesInHorizontal + 2* LightmapRenderer.LIGHTMAP_OVERRENDER
var wiringCounter = 0
for (y in for_y_start..for_y_end) {
for (x in for_x_start..for_x_end) {
if (wiringCounter >= maxRenderableWires) break
val (wires, nodes) = world.getAllWiresFrom(x, y)
wires?.forEach {
val wireActor = wireActorsContainer[wiringCounter]
wireActor.setWire(it, x, y, nodes!![it]!!.cnx)
if (WireCodex[it].renderClass == selectedWireRenderClass || selectedWireRenderClass == "wire_render_all") {
wireActor.renderOrder = Actor.RenderOrder.OVERLAY
}
else {
wireActor.renderOrder = Actor.RenderOrder.BEHIND
}
wireActor.isUpdate = true
wireActor.isVisible = true
wireActor.forceDormant = false
wiringCounter += 1
}
}
}
for (i in wiringCounter until maxRenderableWires) {
wireActorsContainer[i].isUpdate = false
wireActorsContainer[i].isVisible = false
wireActorsContainer[i].forceDormant = true
}
}
private val particles = CircularArray<ParticleBase>(16, true) private val particles = CircularArray<ParticleBase>(16, true)
private val renderGame = { delta: Float -> private val renderGame = { delta: Float ->
@@ -500,6 +559,7 @@ class BuildingMaker(batch: FlippingSpriteBatch) : IngameInstance(batch) {
val world = gameWorld val world = gameWorld
val palSelection = uiPaletteSelector.fore val palSelection = uiPaletteSelector.fore
if (!mousePrimaryClickLatched) {
when (currentPenMode) { when (currentPenMode) {
// test paint terrain layer // test paint terrain layer
PENMODE_PENCIL -> { PENMODE_PENCIL -> {
@@ -517,6 +577,7 @@ class BuildingMaker(batch: FlippingSpriteBatch) : IngameInstance(batch) {
else else
world.setTileTerrain(x, y, palSelection, true) world.setTileTerrain(x, y, palSelection, true)
} }
PENMODE_PENCIL_ERASE -> { PENMODE_PENCIL_ERASE -> {
if (currentPenTarget and PENTARGET_TERRAIN != 0) if (currentPenTarget and PENTARGET_TERRAIN != 0)
world.setTileTerrain(x, y, Block.AIR, true) world.setTileTerrain(x, y, Block.AIR, true)
@@ -525,20 +586,23 @@ class BuildingMaker(batch: FlippingSpriteBatch) : IngameInstance(batch) {
if (currentPenTarget and PENTARGET_ORE != 0) if (currentPenTarget and PENTARGET_ORE != 0)
world.setTileOre(x, y, Block.NULL, 0) world.setTileOre(x, y, Block.NULL, 0)
} }
PENMODE_EYEDROPPER -> { PENMODE_EYEDROPPER -> {
uiPaletteSelector.fore = if (world.getTileFromTerrain(x, y) == Block.AIR) uiPaletteSelector.fore = if (world.getTileFromTerrain(x, y) == Block.AIR)
"wall@" + world.getTileFromWall(x, y) "wall@" + world.getTileFromWall(x, y)
else else
world.getTileFromTerrain(x, y) world.getTileFromTerrain(x, y)
} }
PENMODE_MARQUEE -> { PENMODE_MARQUEE -> {
addBlockMarker(x, y) addBlockMarker(x, y)
} }
PENMODE_MARQUEE_ERASE -> { PENMODE_MARQUEE_ERASE -> {
removeBlockMarker(x, y) removeBlockMarker(x, y)
} }
PENMODE_IMPORT -> { PENMODE_IMPORT -> {
if (!mousePrimaryClickLatched) {
importPoi(x, y) importPoi(x, y)
mousePrimaryClickLatched = true mousePrimaryClickLatched = true
} }