mirror of
https://gitlab.com/2009scape/rt4-client.git
synced 2025-12-09 16:45:46 -07:00
cleanup files
This commit is contained in:
parent
07f4dc9349
commit
c24df5ab46
2 changed files with 162 additions and 152 deletions
153
plugin-playground/src/main/kotlin/KondoKit/AltCanvas.kt
Normal file
153
plugin-playground/src/main/kotlin/KondoKit/AltCanvas.kt
Normal file
|
|
@ -0,0 +1,153 @@
|
||||||
|
package KondoKit
|
||||||
|
|
||||||
|
import KondoKit.plugin.Companion.FIXED_HEIGHT
|
||||||
|
import KondoKit.plugin.Companion.FIXED_WIDTH
|
||||||
|
import plugin.api.API.IsHD
|
||||||
|
import rt4.GameShell.canvas
|
||||||
|
import rt4.GlRenderer
|
||||||
|
import rt4.SoftwareRaster
|
||||||
|
import java.awt.*
|
||||||
|
import java.awt.event.*
|
||||||
|
import java.awt.geom.AffineTransform
|
||||||
|
import java.awt.image.AffineTransformOp
|
||||||
|
import java.awt.image.BufferedImage
|
||||||
|
import java.awt.image.VolatileImage
|
||||||
|
|
||||||
|
class AltCanvas : Canvas() {
|
||||||
|
private var gameImage: VolatileImage? = null
|
||||||
|
private var op: AffineTransformOp? = null
|
||||||
|
private var transform: AffineTransform? = null
|
||||||
|
|
||||||
|
private var flippedImage: BufferedImage? = null
|
||||||
|
private var bufferImage = BufferedImage(FIXED_WIDTH, FIXED_HEIGHT, BufferedImage.TYPE_INT_BGR)
|
||||||
|
|
||||||
|
private var lastImageWidth = -1
|
||||||
|
private var lastImageHeight = -1
|
||||||
|
|
||||||
|
init {
|
||||||
|
isFocusable = true
|
||||||
|
requestFocusInWindow()
|
||||||
|
|
||||||
|
addMouseListener(object : MouseAdapter() {
|
||||||
|
override fun mousePressed(e: MouseEvent) = relayMouseEvent(e)
|
||||||
|
override fun mouseReleased(e: MouseEvent) = relayMouseEvent(e)
|
||||||
|
override fun mouseClicked(e: MouseEvent) = relayMouseEvent(e)
|
||||||
|
})
|
||||||
|
|
||||||
|
addMouseMotionListener(object : MouseMotionAdapter() {
|
||||||
|
override fun mouseMoved(e: MouseEvent) = relayMouseEvent(e)
|
||||||
|
override fun mouseDragged(e: MouseEvent) = relayMouseEvent(e)
|
||||||
|
})
|
||||||
|
|
||||||
|
addKeyListener(object : KeyAdapter() {
|
||||||
|
override fun keyPressed(e: KeyEvent) = relayKeyEvent(e) { it.keyPressed(e) }
|
||||||
|
override fun keyReleased(e: KeyEvent) = relayKeyEvent(e) { it.keyReleased(e) }
|
||||||
|
override fun keyTyped(e: KeyEvent) = relayKeyEvent(e) { it.keyTyped(e) }
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun update(g: Graphics) = paint(g)
|
||||||
|
|
||||||
|
override fun addNotify() {
|
||||||
|
super.addNotify()
|
||||||
|
createBufferStrategy(2) // Double-buffering
|
||||||
|
validateGameImage()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun validateGameImage() {
|
||||||
|
val gc = GraphicsEnvironment.getLocalGraphicsEnvironment().defaultScreenDevice.defaultConfiguration
|
||||||
|
gameImage?.let {
|
||||||
|
when (it.validate(gc)) {
|
||||||
|
VolatileImage.IMAGE_INCOMPATIBLE -> createGameImage(gc)
|
||||||
|
VolatileImage.IMAGE_RESTORED -> renderGameImage()
|
||||||
|
}
|
||||||
|
} ?: createGameImage(gc)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun createGameImage(gc: GraphicsConfiguration) {
|
||||||
|
gameImage = gc.createCompatibleVolatileImage(FIXED_WIDTH, FIXED_HEIGHT, Transparency.OPAQUE)
|
||||||
|
renderGameImage()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun renderGameImage() {
|
||||||
|
gameImage?.createGraphics()?.apply {
|
||||||
|
color = Color.DARK_GRAY
|
||||||
|
fillRect(0, 0, gameImage!!.width, gameImage!!.height)
|
||||||
|
color = Color.BLACK
|
||||||
|
drawString("KondoKit Scaled Fixed Canvas", 20, 20)
|
||||||
|
dispose()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
override fun paint(g: Graphics) {
|
||||||
|
bufferStrategy?.let { strategy ->
|
||||||
|
val g2d = strategy.drawGraphics as? Graphics2D ?: return
|
||||||
|
|
||||||
|
g2d.color = Color.BLACK
|
||||||
|
g2d.fillRect(0, 0, width, height)
|
||||||
|
|
||||||
|
gameImage?.let { image ->
|
||||||
|
val scale = minOf(width.toDouble() / image.width, height.toDouble() / image.height)
|
||||||
|
val x = ((width - image.width * scale) / 2).toInt()
|
||||||
|
val y = ((height - image.height * scale) / 2).toInt()
|
||||||
|
g2d.drawImage(image, x, y, (image.width * scale).toInt(), (image.height * scale).toInt(), null)
|
||||||
|
}
|
||||||
|
|
||||||
|
g2d.dispose() // Release the graphics context
|
||||||
|
strategy.show() // Display the buffer
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun relayMouseEvent(e: MouseEvent) {
|
||||||
|
requestFocusInWindow()
|
||||||
|
val scale = minOf(width.toDouble() / gameImage!!.width, height.toDouble() / gameImage!!.height)
|
||||||
|
val xOffset = ((width - gameImage!!.width * scale) / 2)
|
||||||
|
val yOffset = ((height - gameImage!!.height * scale) / 2)
|
||||||
|
|
||||||
|
val adjustedX = ((e.x - xOffset) / scale).toInt().coerceIn(0, gameImage!!.width - 1)
|
||||||
|
val adjustedY = ((e.y - yOffset) / scale).toInt().coerceIn(0, gameImage!!.height - 1)
|
||||||
|
|
||||||
|
canvas.dispatchEvent(MouseEvent(this, e.id, e.`when`, e.modifiersEx, adjustedX, adjustedY, e.clickCount, e.isPopupTrigger, e.button))
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun relayKeyEvent(e: KeyEvent, action: (KeyListener) -> Unit) {
|
||||||
|
for (listener in canvas.keyListeners) action(listener)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun updateGameImage() {
|
||||||
|
if (IsHD()) renderGlRaster() else renderSoftwareRaster()
|
||||||
|
repaint()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun renderGlRaster() {
|
||||||
|
val width = gameImage!!.width
|
||||||
|
val height = gameImage!!.height
|
||||||
|
|
||||||
|
bufferImage.setRGB(0, 0, width, height, GlRenderer.pixelData, 0, width)
|
||||||
|
|
||||||
|
if (width != lastImageWidth || height != lastImageHeight) {
|
||||||
|
transform = AffineTransform.getScaleInstance(1.0, -1.0).apply {
|
||||||
|
translate(0.0, -height.toDouble())
|
||||||
|
}
|
||||||
|
op = AffineTransformOp(transform, AffineTransformOp.TYPE_NEAREST_NEIGHBOR)
|
||||||
|
flippedImage = BufferedImage(width, height, bufferImage.type)
|
||||||
|
lastImageWidth = width
|
||||||
|
lastImageHeight = height
|
||||||
|
}
|
||||||
|
|
||||||
|
op!!.filter(bufferImage, flippedImage)
|
||||||
|
|
||||||
|
gameImage?.createGraphics()?.apply {
|
||||||
|
drawImage(flippedImage, 0, 0, null)
|
||||||
|
dispose()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun renderSoftwareRaster() {
|
||||||
|
gameImage?.createGraphics()?.apply {
|
||||||
|
SoftwareRaster.frameBuffer.draw(this)
|
||||||
|
dispose()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -42,11 +42,9 @@ import rt4.client.js5Archive8
|
||||||
import rt4.client.mainLoadState
|
import rt4.client.mainLoadState
|
||||||
import java.awt.*
|
import java.awt.*
|
||||||
import java.awt.Font
|
import java.awt.Font
|
||||||
import java.awt.event.*
|
import java.awt.event.ActionListener
|
||||||
import java.awt.geom.AffineTransform
|
import java.awt.event.MouseAdapter
|
||||||
import java.awt.image.AffineTransformOp
|
import java.awt.event.MouseEvent
|
||||||
import java.awt.image.BufferedImage
|
|
||||||
import java.awt.image.VolatileImage
|
|
||||||
import javax.swing.*
|
import javax.swing.*
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -96,8 +94,8 @@ class plugin : Plugin() {
|
||||||
@Exposed("Stretched/Scaled Fixed Mode Support")
|
@Exposed("Stretched/Scaled Fixed Mode Support")
|
||||||
var useAltCanvas = false
|
var useAltCanvas = false
|
||||||
|
|
||||||
private const val FIXED_WIDTH = 765
|
const val FIXED_WIDTH = 765
|
||||||
private const val FIXED_HEIGHT = 503
|
const val FIXED_HEIGHT = 503
|
||||||
private const val NAVBAR_WIDTH = 30
|
private const val NAVBAR_WIDTH = 30
|
||||||
private const val MAIN_CONTENT_WIDTH = 242
|
private const val MAIN_CONTENT_WIDTH = 242
|
||||||
private const val WRENCH_ICON = 907
|
private const val WRENCH_ICON = 907
|
||||||
|
|
@ -157,146 +155,6 @@ class plugin : Plugin() {
|
||||||
lastLogin = Player.usernameInput.toString()
|
lastLogin = Player.usernameInput.toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
class AltCanvas : Canvas() {
|
|
||||||
private var gameImage: VolatileImage? = null
|
|
||||||
private var op: AffineTransformOp? = null
|
|
||||||
private var transform: AffineTransform? = null
|
|
||||||
|
|
||||||
private var flippedImage: BufferedImage? = null
|
|
||||||
private var bufferImage = BufferedImage(FIXED_WIDTH, FIXED_HEIGHT, BufferedImage.TYPE_INT_BGR)
|
|
||||||
|
|
||||||
private var lastImageWidth = -1
|
|
||||||
private var lastImageHeight = -1
|
|
||||||
|
|
||||||
init {
|
|
||||||
isFocusable = true
|
|
||||||
requestFocusInWindow()
|
|
||||||
|
|
||||||
addMouseListener(object : MouseAdapter() {
|
|
||||||
override fun mousePressed(e: MouseEvent) = relayMouseEvent(e)
|
|
||||||
override fun mouseReleased(e: MouseEvent) = relayMouseEvent(e)
|
|
||||||
override fun mouseClicked(e: MouseEvent) = relayMouseEvent(e)
|
|
||||||
})
|
|
||||||
|
|
||||||
addMouseMotionListener(object : MouseMotionAdapter() {
|
|
||||||
override fun mouseMoved(e: MouseEvent) = relayMouseEvent(e)
|
|
||||||
override fun mouseDragged(e: MouseEvent) = relayMouseEvent(e)
|
|
||||||
})
|
|
||||||
|
|
||||||
addKeyListener(object : KeyAdapter() {
|
|
||||||
override fun keyPressed(e: KeyEvent) = relayKeyEvent(e) { it.keyPressed(e) }
|
|
||||||
override fun keyReleased(e: KeyEvent) = relayKeyEvent(e) { it.keyReleased(e) }
|
|
||||||
override fun keyTyped(e: KeyEvent) = relayKeyEvent(e) { it.keyTyped(e) }
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun update(g: Graphics) = paint(g)
|
|
||||||
|
|
||||||
override fun addNotify() {
|
|
||||||
super.addNotify()
|
|
||||||
createBufferStrategy(2) // Double-buffering
|
|
||||||
validateGameImage()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun validateGameImage() {
|
|
||||||
val gc = GraphicsEnvironment.getLocalGraphicsEnvironment().defaultScreenDevice.defaultConfiguration
|
|
||||||
gameImage?.let {
|
|
||||||
when (it.validate(gc)) {
|
|
||||||
VolatileImage.IMAGE_INCOMPATIBLE -> createGameImage(gc)
|
|
||||||
VolatileImage.IMAGE_RESTORED -> renderGameImage()
|
|
||||||
}
|
|
||||||
} ?: createGameImage(gc)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun createGameImage(gc: GraphicsConfiguration) {
|
|
||||||
gameImage = gc.createCompatibleVolatileImage(FIXED_WIDTH, FIXED_HEIGHT, Transparency.OPAQUE)
|
|
||||||
renderGameImage()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun renderGameImage() {
|
|
||||||
gameImage?.createGraphics()?.apply {
|
|
||||||
color = Color.RED
|
|
||||||
fillRect(0, 0, gameImage!!.width, gameImage!!.height)
|
|
||||||
color = Color.BLACK
|
|
||||||
drawString("Game Frame", 20, 20)
|
|
||||||
dispose()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
override fun paint(g: Graphics) {
|
|
||||||
bufferStrategy?.let { strategy ->
|
|
||||||
val g2d = strategy.drawGraphics as? Graphics2D ?: return
|
|
||||||
|
|
||||||
g2d.color = Color.BLACK
|
|
||||||
g2d.fillRect(0, 0, width, height)
|
|
||||||
|
|
||||||
gameImage?.let { image ->
|
|
||||||
val scale = minOf(width.toDouble() / image.width, height.toDouble() / image.height)
|
|
||||||
val x = ((width - image.width * scale) / 2).toInt()
|
|
||||||
val y = ((height - image.height * scale) / 2).toInt()
|
|
||||||
g2d.drawImage(image, x, y, (image.width * scale).toInt(), (image.height * scale).toInt(), null)
|
|
||||||
}
|
|
||||||
|
|
||||||
g2d.dispose() // Release the graphics context
|
|
||||||
strategy.show() // Display the buffer
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun relayMouseEvent(e: MouseEvent) {
|
|
||||||
requestFocusInWindow()
|
|
||||||
val scale = minOf(width.toDouble() / gameImage!!.width, height.toDouble() / gameImage!!.height)
|
|
||||||
val xOffset = ((width - gameImage!!.width * scale) / 2)
|
|
||||||
val yOffset = ((height - gameImage!!.height * scale) / 2)
|
|
||||||
|
|
||||||
val adjustedX = ((e.x - xOffset) / scale).toInt().coerceIn(0, gameImage!!.width - 1)
|
|
||||||
val adjustedY = ((e.y - yOffset) / scale).toInt().coerceIn(0, gameImage!!.height - 1)
|
|
||||||
|
|
||||||
canvas.dispatchEvent(MouseEvent(this, e.id, e.`when`, e.modifiersEx, adjustedX, adjustedY, e.clickCount, e.isPopupTrigger, e.button))
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun relayKeyEvent(e: KeyEvent, action: (KeyListener) -> Unit) {
|
|
||||||
for (listener in canvas.keyListeners) action(listener)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun updateGameImage() {
|
|
||||||
if (IsHD()) renderGlRaster() else renderSoftwareRaster()
|
|
||||||
repaint()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun renderGlRaster() {
|
|
||||||
val width = gameImage!!.width
|
|
||||||
val height = gameImage!!.height
|
|
||||||
|
|
||||||
bufferImage.setRGB(0, 0, width, height, GlRenderer.pixelData, 0, width)
|
|
||||||
|
|
||||||
if (width != lastImageWidth || height != lastImageHeight) {
|
|
||||||
transform = AffineTransform.getScaleInstance(1.0, -1.0).apply {
|
|
||||||
translate(0.0, -height.toDouble())
|
|
||||||
}
|
|
||||||
op = AffineTransformOp(transform, AffineTransformOp.TYPE_NEAREST_NEIGHBOR)
|
|
||||||
flippedImage = BufferedImage(width, height, bufferImage.type)
|
|
||||||
lastImageWidth = width
|
|
||||||
lastImageHeight = height
|
|
||||||
}
|
|
||||||
|
|
||||||
op!!.filter(bufferImage, flippedImage)
|
|
||||||
|
|
||||||
gameImage?.createGraphics()?.apply {
|
|
||||||
drawImage(flippedImage, 0, 0, null)
|
|
||||||
dispose()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun renderSoftwareRaster() {
|
|
||||||
gameImage?.createGraphics()?.apply {
|
|
||||||
SoftwareRaster.frameBuffer.draw(this)
|
|
||||||
dispose()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
override fun Init() {
|
override fun Init() {
|
||||||
// Disable Font AA
|
// Disable Font AA
|
||||||
System.setProperty("sun.java2d.opengl", "false")
|
System.setProperty("sun.java2d.opengl", "false")
|
||||||
|
|
@ -313,6 +171,7 @@ class plugin : Plugin() {
|
||||||
moveAltCanvasToFront()
|
moveAltCanvasToFront()
|
||||||
frame.setComponentZOrder(rightPanelWrapper, 2)
|
frame.setComponentZOrder(rightPanelWrapper, 2)
|
||||||
}
|
}
|
||||||
|
UpdateDisplaySettings()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun UpdateDisplaySettings() {
|
private fun UpdateDisplaySettings() {
|
||||||
|
|
@ -328,9 +187,9 @@ class plugin : Plugin() {
|
||||||
if(useAltCanvas){
|
if(useAltCanvas){
|
||||||
GameShell.leftMargin = 0
|
GameShell.leftMargin = 0
|
||||||
canvas.setLocation(0,canvas.y)
|
canvas.setLocation(0,canvas.y)
|
||||||
altCanvas?.size = Dimension(difference, frame.height - canvas.y)
|
altCanvas?.size = Dimension(difference + uiOffset/2, frame.height - canvas.y)
|
||||||
} else {
|
} else {
|
||||||
GameShell.leftMargin = difference / 2
|
GameShell.leftMargin = (difference + uiOffset) / 2
|
||||||
canvas.setLocation(GameShell.leftMargin - (FIXED_WIDTH/2), canvas.y)
|
canvas.setLocation(GameShell.leftMargin - (FIXED_WIDTH/2), canvas.y)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -361,7 +220,6 @@ class plugin : Plugin() {
|
||||||
StoreData("kondoScaleFixed", useAltCanvas)
|
StoreData("kondoScaleFixed", useAltCanvas)
|
||||||
if(altCanvas == null && useAltCanvas){
|
if(altCanvas == null && useAltCanvas){
|
||||||
InitAltCanvas()
|
InitAltCanvas()
|
||||||
UpdateDisplaySettings()
|
|
||||||
} else if(altCanvas != null && !useAltCanvas){
|
} else if(altCanvas != null && !useAltCanvas){
|
||||||
frame.remove(altCanvas)
|
frame.remove(altCanvas)
|
||||||
altCanvas = null
|
altCanvas = null
|
||||||
|
|
@ -535,7 +393,6 @@ class plugin : Plugin() {
|
||||||
val frame: Frame? = GameShell.frame
|
val frame: Frame? = GameShell.frame
|
||||||
if (frame != null) {
|
if (frame != null) {
|
||||||
restoreSettings()
|
restoreSettings()
|
||||||
loadFont()
|
|
||||||
theme = ThemeType.valueOf(themeName)
|
theme = ThemeType.valueOf(themeName)
|
||||||
applyTheme(getTheme(theme))
|
applyTheme(getTheme(theme))
|
||||||
appliedTheme = theme
|
appliedTheme = theme
|
||||||
|
|
@ -596,7 +453,6 @@ class plugin : Plugin() {
|
||||||
}
|
}
|
||||||
if(useAltCanvas) {
|
if(useAltCanvas) {
|
||||||
InitAltCanvas()
|
InitAltCanvas()
|
||||||
UpdateDisplaySettings()
|
|
||||||
}
|
}
|
||||||
initialized = true
|
initialized = true
|
||||||
pluginsReloaded = true
|
pluginsReloaded = true
|
||||||
|
|
@ -740,6 +596,7 @@ class plugin : Plugin() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun configureLookAndFeel(){
|
private fun configureLookAndFeel(){
|
||||||
|
loadFont()
|
||||||
try {
|
try {
|
||||||
UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel")
|
UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel")
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue