mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 12:21:52 +09:00
buildingmaker block marking
This commit is contained in:
Binary file not shown.
@@ -11,7 +11,6 @@ import net.torvald.terrarum.ui.ConsoleWindow
|
||||
import java.util.*
|
||||
import java.util.concurrent.locks.Lock
|
||||
import java.util.concurrent.locks.ReentrantLock
|
||||
import javax.swing.JOptionPane
|
||||
|
||||
/**
|
||||
* Although the game (as product) can have infinitely many stages/planets/etc., those stages must be manually managed by YOU;
|
||||
@@ -144,11 +143,11 @@ open class IngameInstance(val batch: SpriteBatch) : Screen {
|
||||
index = actorContainerInactive.binarySearch(ID)
|
||||
|
||||
if (index < 0) {
|
||||
JOptionPane.showMessageDialog(
|
||||
/*JOptionPane.showMessageDialog(
|
||||
null,
|
||||
"Actor with ID $ID does not exist.",
|
||||
null, JOptionPane.ERROR_MESSAGE
|
||||
)
|
||||
)*/
|
||||
throw IllegalArgumentException("Actor with ID $ID does not exist.")
|
||||
}
|
||||
else
|
||||
|
||||
@@ -8,7 +8,7 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
* Created by minjaesong on 2017-01-21.
|
||||
*/
|
||||
abstract class ActorWithBody(renderOrder: RenderOrder) : Actor(renderOrder) {
|
||||
open val hitbox = Hitbox(0.0, 0.0, 0.0, 0.0)
|
||||
abstract val hitbox: Hitbox
|
||||
abstract fun drawBody(batch: SpriteBatch)
|
||||
abstract fun drawGlow(batch: SpriteBatch)
|
||||
open var tooltipText: String? = null // null: display nothing
|
||||
|
||||
@@ -45,7 +45,7 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
- Eyedropper : net.torvald.terrarum.modulebasegame.YamlCommandToolEyedropper
|
||||
- Add Selection : net.torvald.terrarum.modulebasegame.YamlCommandToolMarquee
|
||||
- Remove Sel. : net.torvald.terrarum.modulebasegame.YamlCommandToolMarqueeErase
|
||||
- Clear Sel.
|
||||
- Clear Sel. : net.torvald.terrarum.modulebasegame.YamlCommandToolMarqueeClear
|
||||
- Move Selected
|
||||
- Undo
|
||||
- Redo
|
||||
@@ -102,10 +102,11 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
|
||||
val selection = ArrayList<Point2i>()
|
||||
|
||||
val blockMarkings = TextureRegionPack(Gdx.files.internal("assets/graphics/blocks/block_markings_common.tga"), 16, 16)
|
||||
|
||||
val blockPointingCursor = object : ActorWithBody(Actor.RenderOrder.OVERLAY) {
|
||||
|
||||
override var referenceID: ActorID? = Terrarum.generateUniqueReferenceID(renderOrder)
|
||||
val body = TextureRegionPack(Gdx.files.internal("assets/graphics/blocks/block_markings_common.tga"), 16, 16)
|
||||
override var referenceID: ActorID? = 1048575 // custom refID
|
||||
override val hitbox = Hitbox(0.0, 0.0, 16.0, 16.0)
|
||||
|
||||
|
||||
@@ -116,13 +117,12 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
|
||||
override fun drawBody(batch: SpriteBatch) {
|
||||
batch.color = toolCursorColour[currentPenMode]
|
||||
batch.draw(body.get(currentPenMode, 0), hitbox.startX.toFloat(), hitbox.startY.toFloat())
|
||||
batch.draw(blockMarkings.get(currentPenMode, 0), hitbox.startX.toFloat(), hitbox.startY.toFloat())
|
||||
}
|
||||
|
||||
override fun drawGlow(batch: SpriteBatch) { }
|
||||
|
||||
override fun dispose() {
|
||||
body.dispose()
|
||||
}
|
||||
|
||||
override fun update(delta: Float) {
|
||||
@@ -139,6 +139,56 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
}
|
||||
}
|
||||
|
||||
private val blockMarkerColour = Color(0xe0e0e0ff.toInt())
|
||||
|
||||
internal fun blockPosToRefID(x: Int, y: Int) = 1048576 + (y * gameWorld.width + x)
|
||||
|
||||
private fun generateNewBlockMarkerVisible(x: Int, y: Int) = object : ActorWithBody(Actor.RenderOrder.OVERLAY) {
|
||||
override var referenceID: ActorID? = blockPosToRefID(x, y) // custom refID
|
||||
override val hitbox = Hitbox(x * 16.0, y * 16.0, 16.0, 16.0)
|
||||
|
||||
override fun drawBody(batch: SpriteBatch) {
|
||||
batch.color = blockMarkerColour
|
||||
batch.draw(blockMarkings.get(2,0), hitbox.startX.toFloat(), hitbox.startY.toFloat())
|
||||
}
|
||||
|
||||
override fun drawGlow(batch: SpriteBatch) { }
|
||||
|
||||
override fun update(delta: Float) { }
|
||||
|
||||
override fun onActorValueChange(key: String, value: Any?) { }
|
||||
|
||||
override fun run() {
|
||||
TODO("not implemented")
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
internal fun addBlockMarker(x: Int, y: Int) {
|
||||
try {
|
||||
val a = generateNewBlockMarkerVisible(x, y)
|
||||
addNewActor(a)
|
||||
actorsRenderOverlay.add(a)
|
||||
selection.add(Point2i(x, y))
|
||||
}
|
||||
catch (e: Error) { }
|
||||
}
|
||||
|
||||
internal fun removeBlockMarker(x: Int, y: Int) {
|
||||
try {
|
||||
val a = getActorByID(blockPosToRefID(x, y))
|
||||
removeActor(a)
|
||||
actorsRenderOverlay.remove(a)
|
||||
selection.remove(Point2i(x, y))
|
||||
}
|
||||
catch (e: IllegalArgumentException) {
|
||||
// no actor to erase, do nothing
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val PENMODE_PENCIL = 0
|
||||
const val PENMODE_PENCIL_ERASE = 1
|
||||
@@ -156,15 +206,18 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
Color.MAGENTA,
|
||||
Color.WHITE
|
||||
)
|
||||
|
||||
const val DEFAULT_POI_NAME = "The Yucky Panopticon"
|
||||
}
|
||||
|
||||
private val actorsRenderOverlay = ArrayList<ActorWithBody>()
|
||||
private val actorsRenderOverlay = ArrayList<ActorWithBody>() // can be hidden (e.g. hide sel.)
|
||||
private val essentialOverlays = ArrayList<ActorWithBody>()
|
||||
|
||||
init {
|
||||
gameWorld.time.setTimeOfToday(WorldTime.HOUR_SEC * 10)
|
||||
gameWorld.globalLight = Color(.8f,.8f,.8f,.8f)
|
||||
|
||||
actorsRenderOverlay.add(blockPointingCursor)
|
||||
essentialOverlays.add(blockPointingCursor)
|
||||
|
||||
uiContainer.add(uiToolbox)
|
||||
uiContainer.add(uiPaletteSelector)
|
||||
@@ -273,7 +326,7 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
}
|
||||
|
||||
private fun renderGame() {
|
||||
IngameRenderer.invoke(world as GameWorldExtension, actorsRenderOverlay = actorsRenderOverlay, uisToDraw = uiContainer)
|
||||
IngameRenderer.invoke(world as GameWorldExtension, actorsRenderOverlay = actorsRenderOverlay + essentialOverlays, uisToDraw = uiContainer)
|
||||
}
|
||||
|
||||
override fun resize(width: Int, height: Int) {
|
||||
@@ -292,7 +345,7 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
blockPointingCursor.dispose()
|
||||
blockMarkings.dispose()
|
||||
uiPenMenu.dispose()
|
||||
}
|
||||
|
||||
@@ -320,6 +373,12 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
else
|
||||
world.getTileFromTerrain(x, y)!!
|
||||
}
|
||||
PENMODE_MARQUEE -> {
|
||||
addBlockMarker(x, y)
|
||||
}
|
||||
PENMODE_MARQUEE_ERASE -> {
|
||||
removeBlockMarker(x, y)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -450,7 +509,7 @@ class YamlCommandToolPencilEraseWall : YamlInvokable {
|
||||
class YamlCommandToolEyedropper : YamlInvokable {
|
||||
override fun invoke(args: Array<Any>) {
|
||||
(args[0] as BuildingMaker).currentPenMode = BuildingMaker.PENMODE_EYEDROPPER
|
||||
(args[0] as BuildingMaker).currentPenTarget = BuildingMaker.PENTARGET_TERRAIN
|
||||
(args[0] as BuildingMaker).currentPenTarget = BuildingMaker.PENTARGET_TERRAIN + BuildingMaker.PENTARGET_WALL
|
||||
}
|
||||
}
|
||||
|
||||
@@ -465,3 +524,11 @@ class YamlCommandToolMarqueeErase : YamlInvokable {
|
||||
(args[0] as BuildingMaker).currentPenMode = BuildingMaker.PENMODE_MARQUEE_ERASE
|
||||
}
|
||||
}
|
||||
|
||||
class YamlCommandToolMarqueeClear : YamlInvokable {
|
||||
override fun invoke(args: Array<Any>) {
|
||||
(args[0] as BuildingMaker).selection.toList().forEach {
|
||||
(args[0] as BuildingMaker).removeBlockMarker(it.x, it.y)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,11 @@ object PlayerBuilderTestSubject1 {
|
||||
|
||||
PlayerBuilderSigrid.fillTestInventory(p.inventory)
|
||||
|
||||
p.actorValue[AVKey.LUMR] = 0.84
|
||||
p.actorValue[AVKey.LUMG] = 0.93
|
||||
p.actorValue[AVKey.LUMB] = 1.37
|
||||
p.actorValue[AVKey.LUMA] = 1.93
|
||||
|
||||
return p
|
||||
}
|
||||
}
|
||||
@@ -350,7 +350,7 @@ object LightmapRenderer {
|
||||
for (x in lightBoxX.div(TILE_SIZE).floorInt()
|
||||
..lightBoxX.plus(lightBoxW).div(TILE_SIZE).floorInt()) {
|
||||
|
||||
val normalisedColor = it.color.cpy().mul(DIV_FLOAT)
|
||||
val normalisedColor = it.color//.cpy().mul(DIV_FLOAT)
|
||||
|
||||
lanternMap[LandUtil.getBlockAddr(world, x, y)] = normalisedColor
|
||||
//lanternMap[Point2i(x, y)] = normalisedColor
|
||||
|
||||
Reference in New Issue
Block a user