Cell highlighting

This commit is contained in:
ceikry 2021-10-27 16:59:55 -05:00
parent 75afb08d9c
commit d567863949
2 changed files with 22 additions and 6 deletions

View file

@ -13,7 +13,7 @@ import kotlin.system.exitProcess
object Rs2MapEditor {
val library = CacheLibrary.create("K:\\RSPSDev\\RS-2009Toolset\\data\\cache578_preservation")
val library = CacheLibrary.create("/home/ceikry/IdeaProjects/rs09-remake/Server/data/cache/")
@JvmStatic
fun main(args: Array<String>) {
@ -34,10 +34,12 @@ object Rs2MapEditor {
get() = (64 - field) - 1
// Stores the underlay ID for each point
var colorPointMap: MutableMap<Point, Int> = mutableMapOf()
var colorPointMap: HashMap<Point, Int> = hashMapOf()
val componentPointMap = hashMapOf<Point, CellPane>()
// Stores the underlay ID with the Underlay Definition
lateinit var underlayMap: MutableMap<Int, UnderlayDefinition>
lateinit var underlayMap: HashMap<Int, UnderlayDefinition>
var selectedUnderlayId: Int? = null
@ -88,10 +90,12 @@ object Rs2MapEditor {
gbc.gridy = row
val border: Border = MatteBorder(1, 1, if (row == height) 1 else 0, if (column == width) 1 else 0, Color.GRAY)
val flippedY = (64 - row) - 1
colorPointMap[Point(column, flippedY)] = MapTileParser.definition.getTile(column, flippedY, 0).underlayId
val point = Point(column, flippedY)
colorPointMap[point] = MapTileParser.definition.getTile(column, flippedY, 0).underlayId
val cellPane = CellPane()
cellPane.background = underlayMap[MapTileParser.definition.getTile(column, flippedY, 0).underlayId]!!.getRGB()
cellPane.border = border
componentPointMap[point] = cellPane
add(cellPane, gbc)
}
}
@ -234,6 +238,18 @@ object Rs2MapEditor {
init {
underlayMap.forEach {
val underlay = UnderlaySquarePanel(it.value.getRGB(),30, it.key)
underlay.addMouseListener(object : MouseAdapter(){
val border: Border = MatteBorder(1, 1, 1, 1, Color.GRAY)
val highlight: Border = MatteBorder(1, 1, 1, 1, Color.YELLOW)
override fun mouseEntered(e: MouseEvent?) {
colorPointMap.filter { it.value == underlay.id }.forEach{ componentPointMap[it.key]!!.border = highlight}
}
override fun mouseExited(e: MouseEvent?) {
colorPointMap.filter { it.value == underlay.id }.forEach{ componentPointMap[it.key]!!.border = border}
}
})
add(underlay)
}
val addAnUnderlay = UnderlaySquarePanel(Color.darkGray,30, "+")
@ -241,7 +257,7 @@ object Rs2MapEditor {
}
}
class UnderlaySquarePanel(color: Color, size: Int, id: Any) : JPanel() {
class UnderlaySquarePanel(color: Color, size: Int, val id: Any) : JPanel() {
init {
when (id) {
is Int -> {

View file

@ -10,7 +10,7 @@ object FloorUnderlayConfiguration {
val cache = Rs2MapEditor.library.index(Indices.CONFIGURATION).archive(Archives.FLOOR_UNDERLAYS)
var floorUnderlays = mutableMapOf<Int, UnderlayDefinition>()
var floorUnderlays = hashMapOf<Int, UnderlayDefinition>()
@JvmStatic
fun main(args: Array<String>) {