mirror of
https://gitlab.com/2009scape/rt4-client.git
synced 2025-12-09 16:45:46 -07:00
greatly reduce flickering
This commit is contained in:
parent
15deb6216f
commit
71afb2b385
4 changed files with 131 additions and 80 deletions
|
|
@ -79,12 +79,6 @@ public final class DisplayMode {
|
|||
|
||||
@OriginalMember(owner = "client!pm", name = "a", descriptor = "(ZIZIZII)V")
|
||||
public static void setWindowMode(@OriginalArg(0) boolean replaceCanvas, @OriginalArg(1) int newMode, @OriginalArg(2) boolean useHD, @OriginalArg(3) int currentMode, @OriginalArg(5) int width, @OriginalArg(6) int height) {
|
||||
if(!GameShell.canvas.isShowing()){
|
||||
GameShell.frame.add(GameShell.canvas);
|
||||
GameShell.canvas.revalidate();
|
||||
GameShell.frame.revalidate();
|
||||
GameShell.canvas.repaint();
|
||||
}
|
||||
if (useHD) {
|
||||
GlRenderer.quit();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,9 +7,7 @@ import KondoKit.Helpers.formatHtmlLabelText
|
|||
import KondoKit.Helpers.getSpriteId
|
||||
import KondoKit.Helpers.showToast
|
||||
import KondoKit.SpriteToBufferedImage.getBufferedImageFromSprite
|
||||
import KondoKit.plugin.Companion.POPUP_BACKGROUND
|
||||
import KondoKit.plugin.Companion.POPUP_FOREGROUND
|
||||
import KondoKit.plugin.Companion.TITLE_BAR_COLOR
|
||||
import KondoKit.plugin.Companion.TOOLTIP_BACKGROUND
|
||||
import KondoKit.plugin.Companion.VIEW_BACKGROUND_COLOR
|
||||
import KondoKit.plugin.Companion.WIDGET_COLOR
|
||||
|
|
@ -112,8 +110,10 @@ object HiscoresView {
|
|||
} else {
|
||||
text += e.keyChar
|
||||
}
|
||||
SwingUtilities.invokeLater {
|
||||
repaint()
|
||||
}
|
||||
}
|
||||
override fun keyPressed(e: KeyEvent) {
|
||||
if (e.isControlDown) {
|
||||
when (e.keyCode) {
|
||||
|
|
@ -125,26 +125,32 @@ object HiscoresView {
|
|||
val clipboard = Toolkit.getDefaultToolkit().systemClipboard
|
||||
val pasteText = clipboard.getData(DataFlavor.stringFlavor) as String
|
||||
text += pasteText
|
||||
SwingUtilities.invokeLater {
|
||||
repaint()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
addMouseListener(object : MouseAdapter() {
|
||||
override fun mouseClicked(e: MouseEvent) {
|
||||
if (e.x > width - 20 && e.y < 20) {
|
||||
text = ""
|
||||
SwingUtilities.invokeLater {
|
||||
repaint()
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
Timer(500) {
|
||||
cursorVisible = !cursorVisible
|
||||
if(focusedView == VIEW_NAME)
|
||||
SwingUtilities.invokeLater {
|
||||
repaint()
|
||||
}
|
||||
}.start()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import java.awt.Rectangle
|
|||
import java.awt.event.*
|
||||
import java.util.*
|
||||
import javax.swing.JPanel
|
||||
import javax.swing.SwingUtilities
|
||||
|
||||
class ScrollablePanel(private val content: JPanel) : JPanel() {
|
||||
private var lastMouseY = 0
|
||||
|
|
@ -80,6 +81,7 @@ class ScrollablePanel(private val content: JPanel) : JPanel() {
|
|||
}
|
||||
|
||||
private fun handleResize() {
|
||||
SwingUtilities.invokeLater{
|
||||
// Ensure the ScrollablePanel resizes with the frame
|
||||
bounds = Rectangle(0, 0, 242, frame.height)
|
||||
|
||||
|
|
@ -95,6 +97,7 @@ class ScrollablePanel(private val content: JPanel) : JPanel() {
|
|||
revalidate()
|
||||
repaint()
|
||||
}
|
||||
}
|
||||
|
||||
private fun scrollContent(deltaY: Int) {
|
||||
if (!showScrollbar) {
|
||||
|
|
@ -102,7 +105,7 @@ class ScrollablePanel(private val content: JPanel) : JPanel() {
|
|||
content.setLocation(0, currentOffsetY)
|
||||
return
|
||||
}
|
||||
|
||||
SwingUtilities.invokeLater {
|
||||
currentOffsetY += deltaY
|
||||
|
||||
// Apply buffer to maxOffset
|
||||
|
|
@ -116,11 +119,12 @@ class ScrollablePanel(private val content: JPanel) : JPanel() {
|
|||
val scrollableRatio = viewHeight.toDouble() / contentHeight
|
||||
scrollbarY = ((-currentOffsetY / contentHeight.toDouble()) * viewHeight).toInt()
|
||||
scrollbarHeight = (viewHeight * scrollableRatio).toInt().coerceAtLeast(20)
|
||||
|
||||
repaint()
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateScrollbar() {
|
||||
SwingUtilities.invokeLater {
|
||||
showScrollbar = content.height > frame.height
|
||||
|
||||
val contentHeight = content.height
|
||||
|
|
@ -134,9 +138,9 @@ class ScrollablePanel(private val content: JPanel) : JPanel() {
|
|||
scrollbarY = 0
|
||||
scrollbarHeight = 0
|
||||
}
|
||||
|
||||
repaint()
|
||||
}
|
||||
}
|
||||
|
||||
override fun paintComponent(g: Graphics) {
|
||||
super.paintComponent(g)
|
||||
|
|
|
|||
|
|
@ -147,7 +147,8 @@ class plugin : Plugin() {
|
|||
}
|
||||
lastLogin = Player.usernameInput.toString()
|
||||
}
|
||||
class AltCanvas() : JPanel() {
|
||||
|
||||
class AltCanvas : Canvas() {
|
||||
private var gameImage: VolatileImage? = null
|
||||
private var scaleX = 1.0
|
||||
private var scaleY = 1.0
|
||||
|
|
@ -207,15 +208,19 @@ class plugin : Plugin() {
|
|||
requestFocusInWindow()
|
||||
}
|
||||
|
||||
override fun update(g: Graphics) {
|
||||
paint(g)
|
||||
}
|
||||
|
||||
private fun validateGameImage() {
|
||||
val gc = GraphicsEnvironment.getLocalGraphicsEnvironment().defaultScreenDevice.defaultConfiguration
|
||||
if (gameImage == null) {
|
||||
gameImage = gc.createCompatibleVolatileImage(765, 503, Transparency.TRANSLUCENT)
|
||||
gameImage = gc.createCompatibleVolatileImage(765, 503, Transparency.OPAQUE)
|
||||
renderGameImage()
|
||||
} else {
|
||||
val status = gameImage!!.validate(gc)
|
||||
if (status == VolatileImage.IMAGE_INCOMPATIBLE) {
|
||||
gameImage = gc.createCompatibleVolatileImage(765, 503, Transparency.TRANSLUCENT)
|
||||
gameImage = gc.createCompatibleVolatileImage(765, 503, Transparency.OPAQUE)
|
||||
renderGameImage()
|
||||
} else if (status == VolatileImage.IMAGE_RESTORED) {
|
||||
renderGameImage()
|
||||
|
|
@ -237,20 +242,35 @@ class plugin : Plugin() {
|
|||
}
|
||||
}
|
||||
|
||||
override fun paintComponent(g: Graphics) {
|
||||
super.paintComponent(g)
|
||||
override fun paint(g: Graphics) {
|
||||
val g2d = g as Graphics2D
|
||||
|
||||
// Set the desired background fill color here
|
||||
g2d.color = Color.BLACK
|
||||
g2d.fillRect(0, 0, width, height)
|
||||
|
||||
validateGameImage()
|
||||
// Validate image within paint to ensure compatibility with GraphicsConfiguration
|
||||
var valid = false
|
||||
do {
|
||||
val gc = GraphicsEnvironment.getLocalGraphicsEnvironment().defaultScreenDevice.defaultConfiguration
|
||||
if (gameImage == null) {
|
||||
gameImage = gc.createCompatibleVolatileImage(765, 503, Transparency.OPAQUE)
|
||||
renderGameImage()
|
||||
} else {
|
||||
val status = gameImage!!.validate(gc)
|
||||
when (status) {
|
||||
VolatileImage.IMAGE_INCOMPATIBLE -> {
|
||||
gameImage = gc.createCompatibleVolatileImage(765, 503, Transparency.OPAQUE)
|
||||
renderGameImage()
|
||||
}
|
||||
VolatileImage.IMAGE_RESTORED -> renderGameImage()
|
||||
VolatileImage.IMAGE_OK -> valid = true
|
||||
}
|
||||
}
|
||||
} while (!valid)
|
||||
|
||||
// Continue with rendering the image
|
||||
gameImage?.let { image ->
|
||||
g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR)
|
||||
|
||||
// Calculate aspect-ratio-preserving scale
|
||||
// Scaling and centering
|
||||
val imageAspect = image.width.toDouble() / image.height.toDouble()
|
||||
val panelAspect = width.toDouble() / height.toDouble()
|
||||
|
||||
|
|
@ -289,7 +309,6 @@ class plugin : Plugin() {
|
|||
canvas, e.id, e.`when`, e.modifiersEx,
|
||||
originalX, originalY, e.clickCount, e.isPopupTrigger, e.button
|
||||
)
|
||||
|
||||
canvas.dispatchEvent(newEvent)
|
||||
}
|
||||
|
||||
|
|
@ -383,9 +402,12 @@ class plugin : Plugin() {
|
|||
}
|
||||
}
|
||||
rightPanelWrapper?.preferredSize = Dimension(currentScrollPaneWidth, frame.height)
|
||||
rightPanelWrapper?.let { it.isDoubleBuffered = true }
|
||||
rightPanelWrapper?.revalidate()
|
||||
SwingUtilities.invokeLater {
|
||||
rightPanelWrapper?.repaint()
|
||||
}
|
||||
}
|
||||
|
||||
fun OnKondoValueUpdated(){
|
||||
StoreData("kondoUseRemoteGE", useLiveGEPrices)
|
||||
|
|
@ -446,9 +468,7 @@ class plugin : Plugin() {
|
|||
frame.remove(rightPanelWrapper)
|
||||
frame.layout = BorderLayout()
|
||||
frame.add(rightPanelWrapper, BorderLayout.EAST)
|
||||
|
||||
frame.revalidate()
|
||||
frame.repaint()
|
||||
pluginsReloaded = true
|
||||
reloadInterfaces = true
|
||||
return true
|
||||
|
|
@ -476,7 +496,9 @@ class plugin : Plugin() {
|
|||
|
||||
xpTrackerView?.revalidate()
|
||||
if(focusedView == XPTrackerView.VIEW_NAME)
|
||||
SwingUtilities.invokeLater {
|
||||
xpTrackerView?.repaint()
|
||||
}
|
||||
|
||||
updateWidget(xpWidget, xp)
|
||||
}
|
||||
|
|
@ -522,22 +544,35 @@ class plugin : Plugin() {
|
|||
}
|
||||
|
||||
override fun LateDraw(timeDelta: Long){
|
||||
// Clear original canvas for scaled
|
||||
if(!initialized) return
|
||||
SwingUtilities.invokeLater {
|
||||
var p = Point(-1000,-1000)
|
||||
if (GetWindowMode() == WindowMode.FIXED) {
|
||||
if (canvas.location != p) {
|
||||
println("Moving canvas offscreen");
|
||||
canvas.location = p;
|
||||
if (canvas.parent !== hiddenFrame?.contentPane) {
|
||||
println("Moving canvas to hidden frame")
|
||||
initializeHiddenFrame()
|
||||
frame.remove(canvas) // Remove from main frame if necessary
|
||||
hiddenFrame?.contentPane?.add(canvas)
|
||||
hiddenFrame?.pack()
|
||||
}
|
||||
}
|
||||
}
|
||||
altCanvas?.updateGameImage() // Update the game image as needed
|
||||
}
|
||||
} else {
|
||||
|
||||
private var hiddenFrame: JFrame? = null
|
||||
|
||||
fun initializeHiddenFrame() {
|
||||
if (hiddenFrame == null) {
|
||||
hiddenFrame = JFrame().apply {
|
||||
isUndecorated = true
|
||||
isVisible = false // Keep it hidden
|
||||
setSize(1, 1) // Minimal size
|
||||
defaultCloseOperation = JFrame.DO_NOTHING_ON_CLOSE
|
||||
}
|
||||
}
|
||||
altCanvas?.updateGameImage()
|
||||
}
|
||||
|
||||
|
||||
private fun initKondoUI(){
|
||||
DrawText(FontType.LARGE, fromColor(Color(16777215)), TextModifier.CENTER, "KondoKit Loading Sprites...", GameShell.canvasWidth/2, GameShell.canvasHeight/2)
|
||||
if(!allSpritesLoaded()) return;
|
||||
|
|
@ -683,8 +718,10 @@ class plugin : Plugin() {
|
|||
val formattedXpPerHour = formatNumber(xpPerHour)
|
||||
xpWidget.xpPerHourLabel.text =
|
||||
formatHtmlLabelText("XP /hr: ", primaryColor, formattedXpPerHour, secondaryColor)
|
||||
SwingUtilities.invokeLater{
|
||||
xpWidget.container.repaint()
|
||||
}
|
||||
}
|
||||
|
||||
totalXP?.let { totalXPWidget ->
|
||||
val elapsedTime = (System.currentTimeMillis() - totalXPWidget.startTime) / 1000.0 / 60.0 / 60.0
|
||||
|
|
@ -692,9 +729,11 @@ class plugin : Plugin() {
|
|||
val formattedTotalXpPerHour = formatNumber(totalXPPerHour)
|
||||
totalXPWidget.xpPerHourLabel.text =
|
||||
formatHtmlLabelText("XP /hr: ", primaryColor, formattedTotalXpPerHour, secondaryColor)
|
||||
SwingUtilities.invokeLater{
|
||||
totalXPWidget.container.repaint()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun OnKillingBlowNPC(npcID: Int, x: Int, z: Int) {
|
||||
val preDeathSnapshot = takeGroundSnapshot(Pair(x,z))
|
||||
|
|
@ -717,11 +756,14 @@ class plugin : Plugin() {
|
|||
|
||||
// Revalidate and repaint necessary panels
|
||||
mainContentPanel.revalidate()
|
||||
mainContentPanel.repaint()
|
||||
rightPanelWrapper?.revalidate()
|
||||
rightPanelWrapper?.repaint()
|
||||
frame?.revalidate()
|
||||
|
||||
SwingUtilities.invokeLater{
|
||||
mainContentPanel.repaint()
|
||||
rightPanelWrapper?.repaint()
|
||||
frame?.repaint()
|
||||
}
|
||||
|
||||
focusedView = viewName
|
||||
}
|
||||
|
|
@ -784,17 +826,22 @@ class plugin : Plugin() {
|
|||
override fun mouseEntered(e: MouseEvent?) {
|
||||
background = WIDGET_COLOR.darker()
|
||||
imageCanvas.fillColor = WIDGET_COLOR.darker()
|
||||
SwingUtilities.invokeLater{
|
||||
imageCanvas.repaint()
|
||||
repaint()
|
||||
}
|
||||
}
|
||||
|
||||
override fun mouseExited(e: MouseEvent?) {
|
||||
background = WIDGET_COLOR
|
||||
imageCanvas.fillColor = WIDGET_COLOR
|
||||
SwingUtilities.invokeLater{
|
||||
imageCanvas.repaint()
|
||||
repaint()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
override fun mouseClicked(e: MouseEvent?) {
|
||||
actionListener.actionPerformed(null)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue