mirror of
https://gitlab.com/2009scape/tools/2009scape-map-viewer.git
synced 2026-08-01 14:39:25 -06:00
Multiplane support, improved state management
This commit is contained in:
parent
72a0a43706
commit
c108a129e9
6 changed files with 62 additions and 51 deletions
|
|
@ -31,7 +31,7 @@ class NPCSpawnPanel : JPanel() {
|
|||
remove(it)
|
||||
}
|
||||
Rs2MapEditor.npcRows.clear()
|
||||
Rs2MapEditor.npcs.forEach {
|
||||
Rs2MapEditor.npcs.filter { it.plane == Rs2MapEditor.plane }.forEach {
|
||||
val row = NPCRow(it, this)
|
||||
row.border = rowBorder
|
||||
Rs2MapEditor.npcRows.add(row)
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ object Rs2MapEditor {
|
|||
var npcsUpdated = false
|
||||
var itemsUpdated = false
|
||||
var tileDataUpdated = false
|
||||
var plane = 0
|
||||
lateinit var mapPanel: MapPane
|
||||
lateinit var npcPanel: NPCSpawnPanel
|
||||
lateinit var itemPanel: ItemSpawnPanel
|
||||
|
|
@ -121,47 +122,7 @@ object Rs2MapEditor {
|
|||
gbc.fill = GridBagConstraints.NONE
|
||||
gbc.weightx = 1.0
|
||||
SwingUtilities.invokeLater {
|
||||
for (row in 0 until mapHeight) {
|
||||
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.GRAY
|
||||
)
|
||||
val flippedY = (64 - row) - 1
|
||||
val point = Point(column, flippedY)
|
||||
colorPointMap[point] = MapTileParser.definition.getTile(column, flippedY, 0).underlayId
|
||||
val mapCell = MapCell()
|
||||
|
||||
val overlayID = MapTileParser.definition.getTile(column, flippedY, 0).overlayId
|
||||
val floDef = overlayMap[overlayID]!!
|
||||
|
||||
if (overlayID == 0) {
|
||||
mapCell.background = underlayMap[MapTileParser.definition.getTile(column, flippedY, 0).underlayId]!!.getRGB()
|
||||
} else {
|
||||
mapCell.background = overlayMap[overlayID]!!.getRGB()
|
||||
}
|
||||
|
||||
mapCell.border = border
|
||||
val npcsHere = npcs.filter { it.x == column && it.y == flippedY && it.plane == 0 }.toList()
|
||||
if (npcsHere.isNotEmpty()) {
|
||||
mapCell.layout = BorderLayout()
|
||||
mapCell.add(JLabel(YELLOW_DOT))
|
||||
}
|
||||
val itemSpawnsHere = items.filter { it.x == column && it.y == flippedY && it.plane == 0 }.toList()
|
||||
if (itemSpawnsHere.isNotEmpty()) {
|
||||
mapCell.layout = BorderLayout()
|
||||
mapCell.add(JLabel(RED_DOT))
|
||||
}
|
||||
componentPointMap[point] = mapCell
|
||||
add(mapCell, gbc)
|
||||
}
|
||||
}
|
||||
repaintMap()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -174,23 +135,45 @@ object Rs2MapEditor {
|
|||
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.GRAY)
|
||||
MatteBorder(
|
||||
1,
|
||||
1,
|
||||
if (row == mapHeight) 1 else 0,
|
||||
if (column == mapWidth) 1 else 0,
|
||||
Color.GRAY
|
||||
)
|
||||
val flippedY = (64 - row) - 1
|
||||
val point = Point(column, flippedY)
|
||||
colorPointMap[point] = MapTileParser.definition.getTile(column, flippedY, 0).underlayId
|
||||
colorPointMap[point] = MapTileParser.definition.getTile(column, flippedY, plane).underlayId
|
||||
val mapCell = MapCell()
|
||||
mapCell.background =
|
||||
underlayMap[MapTileParser.definition.getTile(column, flippedY, 0).underlayId]!!.getRGB()
|
||||
|
||||
val overlayID = MapTileParser.definition.getTile(column, flippedY, plane).overlayId
|
||||
val floDef = overlayMap[overlayID]!!
|
||||
|
||||
if (overlayID == 0) {
|
||||
mapCell.background = underlayMap[MapTileParser.definition.getTile(column, flippedY, plane).underlayId]!!.getRGB()
|
||||
} else {
|
||||
mapCell.background = overlayMap[overlayID]!!.getRGB()
|
||||
}
|
||||
|
||||
mapCell.border = border
|
||||
val npcsHere = npcs.filter { it.x == column && it.y == flippedY && it.plane == 0 }.toList()
|
||||
val npcsHere = npcs.filter { it.x == column && it.y == flippedY && it.plane == plane }.toList()
|
||||
if (npcsHere.isNotEmpty()) {
|
||||
mapCell.layout = BorderLayout()
|
||||
mapCell.add(JLabel(YELLOW_DOT))
|
||||
}
|
||||
val itemSpawnsHere = items.filter { it.x == column && it.y == flippedY && it.plane == plane }.toList()
|
||||
if (itemSpawnsHere.isNotEmpty()) {
|
||||
mapCell.layout = BorderLayout()
|
||||
mapCell.add(JLabel(RED_DOT))
|
||||
}
|
||||
componentPointMap[point] = mapCell
|
||||
add(mapCell, gbc)
|
||||
}
|
||||
}
|
||||
SwingUtilities.invokeLater {
|
||||
this.repaint()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -248,7 +231,7 @@ object Rs2MapEditor {
|
|||
return
|
||||
}
|
||||
|
||||
val npc = NPC(id, selectedPointX, selectedPointY, 0)
|
||||
val npc = NPC(id, selectedPointX, selectedPointY, plane)
|
||||
npcs.add(npc)
|
||||
componentPointMap.filter { it.key.x == selectedPointX && it.key.y == selectedPointY }.forEach {(_, cell) ->
|
||||
var hasLabel = false
|
||||
|
|
@ -269,7 +252,7 @@ object Rs2MapEditor {
|
|||
return
|
||||
}
|
||||
|
||||
val item = Item(id, selectedPointX, selectedPointY, 0, respawnTime, amount)
|
||||
val item = Item(id, selectedPointX, selectedPointY, plane, respawnTime, amount)
|
||||
items.add(item)
|
||||
componentPointMap.filter { it.key.x == selectedPointX && it.key.y == selectedPointY }.forEach {(_, cell) ->
|
||||
var hasLabel = false
|
||||
|
|
@ -516,6 +499,25 @@ object Rs2MapEditor {
|
|||
add(RegionMenuOption())
|
||||
add(PrefMenuOption())
|
||||
add(ToolsMenuOption())
|
||||
add(JSeparator(JSeparator.VERTICAL))
|
||||
add(JLabel("Plane: "))
|
||||
add(PlaneButton(0))
|
||||
add(PlaneButton(1))
|
||||
add(PlaneButton(2))
|
||||
add(PlaneButton(3))
|
||||
}
|
||||
}
|
||||
|
||||
class PlaneButton(val plane: Int) : JButton(plane.toString()){
|
||||
init {
|
||||
addActionListener {
|
||||
if(Rs2MapEditor.plane != this.plane){
|
||||
Rs2MapEditor.plane = this.plane
|
||||
npcPanel.redrawRows()
|
||||
itemPanel.redrawRows()
|
||||
mapPanel.repaintMap()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -533,6 +535,7 @@ object Rs2MapEditor {
|
|||
NPCSearchTool.caller = { id, _ ->
|
||||
npcIdInput.text = id.toString()
|
||||
infoPane.selectedIndex = 3
|
||||
state = EditorState.ADD_NPC
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -545,6 +548,7 @@ object Rs2MapEditor {
|
|||
ItemSearchTool.caller = {id, _ ->
|
||||
itemIdInput.text = id.toString()
|
||||
infoPane.selectedIndex = 4
|
||||
state = EditorState.ADD_GROUNDITEM
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import Rs2MapEditor
|
|||
import cacheops.cache.definition.decoder.Item
|
||||
import const.Indices
|
||||
import java.nio.ByteBuffer
|
||||
import javax.swing.JOptionPane
|
||||
|
||||
object GroundItemEncoder {
|
||||
|
||||
|
|
@ -33,6 +34,8 @@ object GroundItemEncoder {
|
|||
if (dataArray != null) {
|
||||
Rs2MapEditor.library.put(Indices.LANDSCAPES, "i${x}_${y}", dataArray, intArrayOf(0,0,0,0))
|
||||
Rs2MapEditor.library.update()
|
||||
JOptionPane.showMessageDialog(Rs2MapEditor.mapPanel, "Items written to cache [✓]")
|
||||
Rs2MapEditor.itemsUpdated = false
|
||||
} else {
|
||||
System.err.println("Panic! Something went VERY wrong!")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ object NPCSpawnEncoder {
|
|||
if (dataArray != null) {
|
||||
Rs2MapEditor.library.put(Indices.LANDSCAPES, "n${x}_${y}", dataArray, intArrayOf(0,0,0,0))
|
||||
Rs2MapEditor.library.update()
|
||||
JOptionPane.showMessageDialog(Rs2MapEditor.mapPanel, "NPCs written to cache. [✓]")
|
||||
JOptionPane.showMessageDialog(Rs2MapEditor.mapPanel, "NPCs written to cache [✓]")
|
||||
Rs2MapEditor.npcsUpdated = false
|
||||
} else {
|
||||
System.err.println("Panic! Something went VERY wrong!")
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package misc
|
||||
|
||||
import cacheops.cache.definition.encoder.GroundItemEncoder
|
||||
import cacheops.cache.definition.encoder.NPCSpawnEncoder
|
||||
import java.awt.Event
|
||||
import java.awt.event.KeyEvent
|
||||
|
|
@ -29,6 +30,9 @@ object GlobalKeybinds{
|
|||
if(Rs2MapEditor.npcsUpdated){
|
||||
NPCSpawnEncoder.write(Rs2MapEditor.npcs)
|
||||
}
|
||||
if(Rs2MapEditor.itemsUpdated){
|
||||
GroundItemEncoder.write(Rs2MapEditor.items)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ class ItemSpawnPanel : JPanel() {
|
|||
remove(it)
|
||||
}
|
||||
Rs2MapEditor.itemRows.clear()
|
||||
Rs2MapEditor.items.forEach {
|
||||
Rs2MapEditor.items.filter { it.plane == Rs2MapEditor.plane }.forEach {
|
||||
val row = ItemRow(it, this)
|
||||
row.border = rowBorder
|
||||
Rs2MapEditor.itemRows.add(row)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue