Add toggleable height visualization

This commit is contained in:
ceikry 2021-11-07 19:24:38 -06:00
parent fd735d3dc3
commit d7a64e9774
2 changed files with 64 additions and 2 deletions

View file

@ -1,6 +1,7 @@
import cacheops.cache.definition.data.OverlayDefinition
import cacheops.cache.definition.data.UnderlayDefinition
import cacheops.cache.definition.data.MapTile
import cacheops.cache.definition.decoder.*
import com.displee.cache.CacheLibrary
import com.formdev.flatlaf.FlatDarculaLaf
@ -29,6 +30,8 @@ object Rs2MapEditor {
var itemsUpdated = false
var tileDataUpdated = false
var plane = 0
var visualizeHeight = false
var previousHeight = -1
lateinit var mapPanel: MapPane
lateinit var npcPanel: NPCSpawnPanel
lateinit var itemPanel: ItemSpawnPanel
@ -132,12 +135,13 @@ object Rs2MapEditor {
for (column in 0 until mapWidth) {
gbc.gridx = column
gbc.gridy = row
val border: Border = MatteBorder(1, 1, if (row == mapHeight) 1 else 0, if (column == mapWidth) 1 else 0, Color(255,255,255,25))
var border: Border = MatteBorder(1, 1, if (row == mapHeight) 1 else 0, if (column == mapWidth) 1 else 0, Color(255,255,255,25))
val flippedY = (64 - row) - 1
val point = Point(column, flippedY)
colorPointMap[point] = MapTileParser.definition.getTile(column, flippedY, plane).underlayId - 1
val mapCell = MapCell()
val tileDef = MapTileParser.definition.getTile(column, flippedY, plane)
var overlayID = (MapTileParser.definition.getTile(column, flippedY, plane).overlayId - 1)
var underlayID = (MapTileParser.definition.getTile(column, flippedY, plane).underlayId - 1)
@ -168,7 +172,43 @@ object Rs2MapEditor {
mapCell.background = floDef.getRGB()
}
mapCell.border = border
if(visualizeHeight){
val height = tileDef.height
val otherTiles: List<MapTile> = Pair(column, flippedY).getSurroundingTiles()
val borderSizes = intArrayOf(0,0,0,0)
var borderColor = Color(0,0,0,0)
for(tileIndex in otherTiles.indices){
val tile = otherTiles[tileIndex]
if(height > tile.height){
val tileDiff = height - tile.height
val alpha = Math.min(tileDiff * 8, 255)
val color: Color
try {
color = Color(0,0,0, alpha)
} catch (e: Exception){
println("Invalid alpha value: $alpha")
return
}
val borderIndex = when(tileIndex){
0 -> 0
3 -> 1
2 -> 2
1 -> 3
else -> -1
}
borderSizes[borderIndex] = 3
if(color.alpha > borderColor.alpha) borderColor = color
}
}
mapCell.border = MatteBorder(borderSizes[0], borderSizes[1], borderSizes[2], borderSizes[3], borderColor)
} else {
mapCell.border = border
}
val sceneryHere = sceneries.filter { it.x == column && it.y == flippedY && it.plane == plane }.toList()
if(sceneryHere.isNotEmpty()){
@ -341,6 +381,16 @@ object Rs2MapEditor {
add(DisplaySceneryItem())
addSeparator()
add(DisplayHeightItem())
add(visualizeHeightItem())
}
}
class visualizeHeightItem : JCheckBoxMenuItem("Visualize Heights", false) {
init {
addActionListener {
Rs2MapEditor.visualizeHeight = !Rs2MapEditor.visualizeHeight
mapPanel.repaintMap()
}
}
}

View file

@ -0,0 +1,12 @@
import cacheops.cache.definition.data.MapTile
import cacheops.cache.definition.decoder.MapTileParser
fun Pair<Int,Int>.getSurroundingTiles() : List<MapTile> {
val list = ArrayList<MapTile>()
list.add(MapTileParser.definition.getTile(first, second + 1, Rs2MapEditor.plane))
list.add(MapTileParser.definition.getTile(first + 1, second, Rs2MapEditor.plane))
list.add(MapTileParser.definition.getTile(first, second - 1, Rs2MapEditor.plane))
list.add(MapTileParser.definition.getTile(first - 1, second, Rs2MapEditor.plane))
return list
}