mirror of
https://gitlab.com/2009scape/tools/2009scape-map-viewer.git
synced 2026-08-01 14:39:25 -06:00
multi-object rendering
This commit is contained in:
parent
548622e2c0
commit
f699eb91f3
2 changed files with 137 additions and 98 deletions
|
|
@ -172,7 +172,7 @@ object Rs2MapEditor {
|
|||
|
||||
val sceneryHere = sceneries.filter { it.x == column && it.y == flippedY && it.plane == plane }.toList()
|
||||
if(sceneryHere.isNotEmpty()){
|
||||
mapCell.flagScenery(sceneryHere.first())
|
||||
sceneryHere.forEach(mapCell::flagScenery)
|
||||
}
|
||||
|
||||
val npcsHere = npcs.filter { it.x == column && it.y == flippedY && it.plane == plane }.toList()
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ import javax.swing.SwingUtilities
|
|||
|
||||
class MapCell : JPanel() {
|
||||
var defaultBackground: Color = background
|
||||
var scenery: Scenery = Scenery(-1, -1, -1, -1, -1, -1)
|
||||
val scenery = ArrayList<Scenery>()
|
||||
override fun getPreferredSize(): Dimension {
|
||||
return Dimension(Rs2MapEditor.cellX, Rs2MapEditor.cellY)
|
||||
}
|
||||
|
|
@ -209,12 +209,16 @@ class MapCell : JPanel() {
|
|||
string.append("</tbody></table><br/>")
|
||||
}
|
||||
|
||||
if(cell.scenery.id != -1){
|
||||
if(scenery.isNotEmpty()) {
|
||||
string.append("<h3>Scenery Info</h3>")
|
||||
string.append("${cell.scenery.definition.name} [ID: ${cell.scenery.id}]<br/>")
|
||||
string.append("Type: ${cell.scenery.type}<br/>")
|
||||
string.append("Rotation: ${cell.scenery.rotation}<br/>")
|
||||
string.append("")
|
||||
for(sc in scenery) {
|
||||
if (sc.id != -1) {
|
||||
string.append("${sc.definition.name} [ID: ${sc.id}]<br/>")
|
||||
string.append("Type: ${sc.type}<br/>")
|
||||
string.append("Rotation: ${sc.rotation}<br/>")
|
||||
string.append("---------------------<br/>")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Rs2MapEditor.underlayInfo.text = String.format("<html><body style=\"text-align: center;\">%s</body></html>", string.toString())
|
||||
|
|
@ -225,109 +229,144 @@ class MapCell : JPanel() {
|
|||
}
|
||||
|
||||
fun flagScenery(scenery: Scenery){
|
||||
this.scenery = scenery
|
||||
this.scenery.add(scenery)
|
||||
}
|
||||
|
||||
override fun paintComponent(g: Graphics) {
|
||||
if(this.defaultBackground == Color(0,0,0,0)) return
|
||||
super.paintComponent(g)
|
||||
var pointX1 = 0
|
||||
var pointY1 = 0
|
||||
var pointX2 = 0
|
||||
var pointY2 = 0
|
||||
val color = g.color
|
||||
val rotationOdd = scenery.rotation % 2 != 0
|
||||
when(scenery.type){
|
||||
10 -> g.drawOval(5,5,this.width - 10, this.height - 10)
|
||||
4 ->{
|
||||
val offSetX = if(!rotationOdd) (scenery.rotation * 0.375 * width).toInt() else (0.35 * width).toInt()
|
||||
val offSetY = if(!rotationOdd) (0.65 * height).toInt() else (scenery.rotation * 0.375 * height).toInt()
|
||||
g.drawString("=", offSetX, offSetY)
|
||||
}
|
||||
11 -> {
|
||||
g.color = Color(255, 255, 255, 75)
|
||||
g.drawString("⛝",(0.25 * width).toInt(),(0.75 * height).toInt())
|
||||
g.color = color
|
||||
}
|
||||
22 -> {
|
||||
g.color = Color(255, 255, 255, 55)
|
||||
g.drawString("⛆",(0.15 * width).toInt(),(0.65 * height).toInt())
|
||||
g.color = color
|
||||
}
|
||||
0,5 -> {
|
||||
if(scenery.id == 85) return
|
||||
when(scenery.rotation){
|
||||
0 -> {pointX1 = 2; pointY1 = this.height; pointX2 = 2; pointY2 = 0}
|
||||
1 -> {pointX1 = 0; pointY1 = 2; pointX2 = this.width; pointY2 = 2}
|
||||
2 -> {pointX1 = this.width - 2; pointY1 = 0; pointX2 = this.width - 2; pointY2 = this.height}
|
||||
3 -> {pointX1 = 0; pointY1 = this.height - 2; pointX2 = this.width; pointY2 = this.height - 2}
|
||||
for(sc in scenery) {
|
||||
var pointX1 = 0
|
||||
var pointY1 = 0
|
||||
var pointX2 = 0
|
||||
var pointY2 = 0
|
||||
val color = g.color
|
||||
val rotationOdd = sc.rotation % 2 != 0
|
||||
when (sc.type) {
|
||||
10 -> g.drawOval(5, 5, this.width - 10, this.height - 10)
|
||||
4 -> {
|
||||
val offSetX =
|
||||
if (!rotationOdd) (sc.rotation * 0.375 * width).toInt() else (0.35 * width).toInt()
|
||||
val offSetY =
|
||||
if (!rotationOdd) (0.65 * height).toInt() else (sc.rotation * 0.375 * height).toInt()
|
||||
g.drawString("=", offSetX, offSetY)
|
||||
}
|
||||
if(scenery.definition.interactive == 1){
|
||||
g.color = Color.RED
|
||||
11 -> {
|
||||
g.color = Color(255, 255, 255, 75)
|
||||
g.drawString("⛝", (0.25 * width).toInt(), (0.75 * height).toInt())
|
||||
g.color = color
|
||||
}
|
||||
g.drawLine(pointX1, pointY1, pointX2, pointY2)
|
||||
g.color = color
|
||||
}
|
||||
|
||||
2 -> {
|
||||
val nPoints = 4
|
||||
var xArray: IntArray = intArrayOf(0,0,0,0)
|
||||
var yArray: IntArray = intArrayOf(0,0,0,0)
|
||||
when(scenery.rotation){
|
||||
0 -> {xArray = intArrayOf(2,2,2,this.width); yArray = intArrayOf(2,this.height,2,2)}
|
||||
1 -> {xArray = intArrayOf(0, this.width, this.width - 2, this.width - 2); yArray = intArrayOf(2, 2, 2, this.height)}
|
||||
2 -> {xArray = intArrayOf(0, this.width, this.width, this.width); yArray = intArrayOf(this.height - 2, this.height - 2, 0, this.height - 2)}
|
||||
3 -> {xArray = intArrayOf(0, 0, 0, this.width); intArrayOf(0, this.height - 2, this.height - 2, this.height - 2)}
|
||||
22 -> {
|
||||
g.color = Color(255, 255, 255, 55)
|
||||
g.drawString("⛆", (0.15 * width).toInt(), (0.65 * height).toInt())
|
||||
g.color = color
|
||||
}
|
||||
if(scenery.definition.interactive == 1){
|
||||
g.color = Color.RED
|
||||
}
|
||||
g.drawPolyline(xArray, yArray, nPoints)
|
||||
g.color = color
|
||||
}
|
||||
|
||||
9,7,6,8 -> {
|
||||
if(scenery.id == 85 || scenery.id == 83) return
|
||||
when(scenery.rotation){
|
||||
0,2 -> {pointX1 = 0; pointY1 = height; pointX2 = width; pointY2 = 0}
|
||||
1,3 -> {pointX1 = 0; pointY1 = 0; pointX2 = width; pointY2 = height}
|
||||
}
|
||||
|
||||
val overlayNorth = getOverlayId(scenery.x + 1, scenery.y)
|
||||
val overlaySouth = getOverlayId(scenery.x - 1, scenery.y)
|
||||
val northWest = getOverlayId(scenery.x - 1, scenery.y + 1)
|
||||
val north = getOverlayId(scenery.x, scenery.y + 1)
|
||||
val northEast = getOverlayId(scenery.x + 1, scenery.y + 1)
|
||||
val east = getOverlayId(scenery.x + 1, scenery.y)
|
||||
val southWest = getOverlayId(scenery.x - 1, scenery.y - 1)
|
||||
val south = getOverlayId(scenery.x, scenery.y - 1)
|
||||
val southEast = getOverlayId(scenery.x + 1, scenery.y - 1)
|
||||
val west = getOverlayId(scenery.x - 1, scenery.y)
|
||||
|
||||
var backFillVertice = Pair(0,0)
|
||||
when(scenery.rotation){
|
||||
0, 2 -> {
|
||||
val sumA = getOverlaySum(north, northWest, west)
|
||||
val sumB = getOverlaySum(south, southEast, east)
|
||||
backFillVertice = if(sumA > sumB) Pair(width,height)
|
||||
else if (sumA == sumB) Pair(-1,-1)
|
||||
else Pair(0,0)
|
||||
0, 5 -> {
|
||||
if (sc.id == 85) return
|
||||
when (sc.rotation) {
|
||||
0 -> {
|
||||
pointX1 = 2; pointY1 = this.height; pointX2 = 2; pointY2 = 0
|
||||
}
|
||||
1 -> {
|
||||
pointX1 = 0; pointY1 = 2; pointX2 = this.width; pointY2 = 2
|
||||
}
|
||||
2 -> {
|
||||
pointX1 = this.width - 2; pointY1 = 0; pointX2 = this.width - 2; pointY2 = this.height
|
||||
}
|
||||
3 -> {
|
||||
pointX1 = 0; pointY1 = this.height - 2; pointX2 = this.width; pointY2 = this.height - 2
|
||||
}
|
||||
}
|
||||
1,3 -> {
|
||||
val sumA = getOverlaySum(north, northEast, east)
|
||||
val sumB = getOverlaySum(south, southWest, west)
|
||||
backFillVertice = if(sumA > sumB) Pair(0,height)
|
||||
else if (sumA == sumB) Pair(-1,-1)
|
||||
else Pair(width,0)
|
||||
if (sc.definition.interactive == 1 && sc.type == 0) {
|
||||
g.color = Color.RED
|
||||
}
|
||||
g.drawLine(pointX1, pointY1, pointX2, pointY2)
|
||||
g.color = color
|
||||
}
|
||||
|
||||
val fluDef = getUnderlayColor(scenery.x, scenery.y)
|
||||
g.color = fluDef
|
||||
if(overlaySouth != overlayNorth && backFillVertice.first != -1)
|
||||
g.fillPolygon(intArrayOf(pointX1, pointX2, backFillVertice.first), intArrayOf(pointY1, pointY2, backFillVertice.second), 3)
|
||||
g.color = color
|
||||
g.drawLine(pointX1, pointY1, pointX2, pointY2)
|
||||
2 -> {
|
||||
val nPoints = 4
|
||||
var xArray: IntArray = intArrayOf(0, 0, 0, 0)
|
||||
var yArray: IntArray = intArrayOf(0, 0, 0, 0)
|
||||
when (sc.rotation) {
|
||||
0 -> {
|
||||
xArray = intArrayOf(2, 2, 2, this.width); yArray = intArrayOf(2, this.height, 2, 2)
|
||||
}
|
||||
1 -> {
|
||||
xArray = intArrayOf(0, this.width, this.width - 2, this.width - 2); yArray =
|
||||
intArrayOf(2, 2, 2, this.height)
|
||||
}
|
||||
2 -> {
|
||||
xArray = intArrayOf(0, this.width, this.width, this.width); yArray =
|
||||
intArrayOf(this.height - 2, this.height - 2, 0, this.height - 2)
|
||||
}
|
||||
3 -> {
|
||||
xArray = intArrayOf(0, 0, 0, this.width); intArrayOf(
|
||||
0,
|
||||
this.height - 2,
|
||||
this.height - 2,
|
||||
this.height - 2
|
||||
)
|
||||
}
|
||||
}
|
||||
if (sc.definition.interactive == 1) {
|
||||
g.color = Color.RED
|
||||
}
|
||||
g.drawPolyline(xArray, yArray, nPoints)
|
||||
g.color = color
|
||||
}
|
||||
|
||||
9, 7, 6, 8 -> {
|
||||
if (sc.id == 85 || sc.id == 83) return
|
||||
when (sc.rotation) {
|
||||
0, 2 -> {
|
||||
pointX1 = 0; pointY1 = height; pointX2 = width; pointY2 = 0
|
||||
}
|
||||
1, 3 -> {
|
||||
pointX1 = 0; pointY1 = 0; pointX2 = width; pointY2 = height
|
||||
}
|
||||
}
|
||||
|
||||
val overlayNorth = getOverlayId(sc.x + 1, sc.y)
|
||||
val overlaySouth = getOverlayId(sc.x - 1, sc.y)
|
||||
val northWest = getOverlayId(sc.x - 1, sc.y + 1)
|
||||
val north = getOverlayId(sc.x, sc.y + 1)
|
||||
val northEast = getOverlayId(sc.x + 1, sc.y + 1)
|
||||
val east = getOverlayId(sc.x + 1, sc.y)
|
||||
val southWest = getOverlayId(sc.x - 1, sc.y - 1)
|
||||
val south = getOverlayId(sc.x, sc.y - 1)
|
||||
val southEast = getOverlayId(sc.x + 1, sc.y - 1)
|
||||
val west = getOverlayId(sc.x - 1, sc.y)
|
||||
|
||||
var backFillVertice = Pair(0, 0)
|
||||
when (sc.rotation) {
|
||||
0, 2 -> {
|
||||
val sumA = getOverlaySum(north, northWest, west)
|
||||
val sumB = getOverlaySum(south, southEast, east)
|
||||
backFillVertice = if (sumA > sumB) Pair(width, height)
|
||||
else if (sumA == sumB) Pair(-1, -1)
|
||||
else Pair(0, 0)
|
||||
}
|
||||
1, 3 -> {
|
||||
val sumA = getOverlaySum(north, northEast, east)
|
||||
val sumB = getOverlaySum(south, southWest, west)
|
||||
backFillVertice = if (sumA > sumB) Pair(0, height)
|
||||
else if (sumA == sumB) Pair(-1, -1)
|
||||
else Pair(width, 0)
|
||||
}
|
||||
}
|
||||
|
||||
val fluDef = getUnderlayColor(sc.x, sc.y)
|
||||
g.color = fluDef
|
||||
if (overlaySouth != overlayNorth && backFillVertice.first != -1)
|
||||
g.fillPolygon(
|
||||
intArrayOf(pointX1, pointX2, backFillVertice.first),
|
||||
intArrayOf(pointY1, pointY2, backFillVertice.second),
|
||||
3
|
||||
)
|
||||
g.color = color
|
||||
g.drawLine(pointX1, pointY1, pointX2, pointY2)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue