general cleanup

This commit is contained in:
downthecrop 2024-10-28 12:43:29 -07:00
parent 52d07d5795
commit 1cca6611ee
8 changed files with 46 additions and 65 deletions

View file

@ -40,14 +40,12 @@ class AltCanvas : Canvas() {
}) })
addKeyListener(object : KeyAdapter() { addKeyListener(object : KeyAdapter() {
override fun keyPressed(e: KeyEvent) = relayKeyEvent(e) { it.keyPressed(e) } override fun keyPressed(e: KeyEvent) = relayKeyEvent { it.keyPressed(e) }
override fun keyReleased(e: KeyEvent) = relayKeyEvent(e) { it.keyReleased(e) } override fun keyReleased(e: KeyEvent) = relayKeyEvent { it.keyReleased(e) }
override fun keyTyped(e: KeyEvent) = relayKeyEvent(e) { it.keyTyped(e) } override fun keyTyped(e: KeyEvent) = relayKeyEvent { it.keyTyped(e) }
}) })
addMouseWheelListener(object : MouseWheelListener { addMouseWheelListener(MouseWheelListener { e -> relayMouseWheelEvent(e) })
override fun mouseWheelMoved(e: MouseWheelEvent) = relayMouseWheelEvent(e)
})
} }
override fun update(g: Graphics) = paint(g) override fun update(g: Graphics) = paint(g)
@ -115,7 +113,7 @@ class AltCanvas : Canvas() {
canvas.dispatchEvent(MouseEvent(this, e.id, e.`when`, e.modifiersEx, adjustedX, adjustedY, e.clickCount, e.isPopupTrigger, e.button)) 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) { private fun relayKeyEvent(action: (KeyListener) -> Unit) {
for (listener in canvas.keyListeners) action(listener) for (listener in canvas.keyListeners) action(listener)
} }

View file

@ -95,10 +95,8 @@ object Helpers {
} }
private fun convertToColor(value: String): Color {
fun convertToColor(value: String): Color { return Color.decode(value)
val color = Color.decode(value) // Assumes value is in format "#RRGGBB" or "0xRRGGBB"
return color
} }
fun colorToHex(color: Color): String { fun colorToHex(color: Color): String {
@ -134,11 +132,7 @@ object Helpers {
class FieldNotifier(private val plugin: Any) { class FieldNotifier(private val plugin: Any) {
private val observers = mutableListOf<FieldObserver>() private val observers = mutableListOf<FieldObserver>()
fun addObserver(observer: FieldObserver) { private fun notifyFieldChange(field: Field, newValue: Any?) {
observers.add(observer)
}
fun notifyFieldChange(field: Field, newValue: Any?) {
for (observer in observers) { for (observer in observers) {
observer.onFieldChange(field, newValue) observer.onFieldChange(field, newValue)
} }

View file

@ -75,8 +75,8 @@ object HiscoresView {
private var cursorVisible: Boolean = true private var cursorVisible: Boolean = true
private val gson = Gson() private val gson = Gson()
val bufferedImageSprite = getBufferedImageFromSprite(API.GetSprite(Constants.MAG_SPRITE)) private val bufferedImageSprite = getBufferedImageFromSprite(API.GetSprite(Constants.MAG_SPRITE))
val imageCanvas = bufferedImageSprite.let { private val imageCanvas = bufferedImageSprite.let {
ImageCanvas(it).apply { ImageCanvas(it).apply {
preferredSize = Constants.ICON_DIMENSION_SMALL preferredSize = Constants.ICON_DIMENSION_SMALL
size = preferredSize size = preferredSize
@ -241,7 +241,7 @@ object HiscoresView {
playerNameLabel?.revalidate() playerNameLabel?.revalidate()
playerNameLabel?.repaint() playerNameLabel?.repaint()
if(data == null) return; if(data == null) return
playerNameLabel?.removeAll() playerNameLabel?.removeAll()
@ -325,10 +325,6 @@ object HiscoresView {
return Math.round((base + maxCombatType + summoningFactor) * 1000.0) / 1000.0 return Math.round((base + maxCombatType + summoningFactor) * 1000.0) / 1000.0
} }
private fun showError(message: String) {
JOptionPane.showMessageDialog(null, message, "Error", JOptionPane.ERROR_MESSAGE)
}
private fun findComponentByName(container: Container, name: String): Component? { private fun findComponentByName(container: Container, name: String): Component? {
for (component in container.components) { for (component in container.components) {
if (name == component.name) { if (name == component.name) {
@ -443,7 +439,7 @@ object HiscoresView {
minimumSize = preferredSize minimumSize = preferredSize
} }
val bufferedImageSprite = getBufferedImageFromSprite(API.GetSprite(Constants.LVL_BAR_SPRITE)); val bufferedImageSprite = getBufferedImageFromSprite(API.GetSprite(Constants.LVL_BAR_SPRITE))
val totalLevelIcon = ImageCanvas(bufferedImageSprite).apply { val totalLevelIcon = ImageCanvas(bufferedImageSprite).apply {
fillColor = COLOR_BACKGROUND_DARK fillColor = COLOR_BACKGROUND_DARK
@ -492,7 +488,7 @@ object HiscoresView {
hiscorePanel.add(totalCombatPanel) hiscorePanel.add(totalCombatPanel)
hiscorePanel.add(Box.createVerticalStrut(10)) hiscorePanel.add(Box.createVerticalStrut(10))
hiScoreView = hiscorePanel; hiScoreView = hiscorePanel
} }
data class HiscoresResponse( data class HiscoresResponse(

View file

@ -32,15 +32,15 @@ import kotlin.math.ceil
object LootTrackerView { object LootTrackerView {
private const val SNAPSHOT_LIFESPAN = 10 private const val SNAPSHOT_LIFESPAN = 10
const val BAG_ICON = 900; const val BAG_ICON = 900
val npcDeathSnapshots = mutableMapOf<Int, GroundSnapshot>() val npcDeathSnapshots = mutableMapOf<Int, GroundSnapshot>()
var gePriceMap = loadGEPrices() var gePriceMap = loadGEPrices()
const val VIEW_NAME = "LOOT_TRACKER_VIEW"; const val VIEW_NAME = "LOOT_TRACKER_VIEW"
private val lootItemPanels = mutableMapOf<String, MutableMap<Int, Int>>() private val lootItemPanels = mutableMapOf<String, MutableMap<Int, Int>>()
private val npcKillCounts = mutableMapOf<String, Int>() private val npcKillCounts = mutableMapOf<String, Int>()
private var totalTrackerWidget: XPWidget? = null private var totalTrackerWidget: XPWidget? = null
var lastConfirmedKillNpcId = -1 var lastConfirmedKillNpcId = -1
var customToolTipWindow: JWindow? = null private var customToolTipWindow: JWindow? = null
var lootTrackerView: JPanel? = null var lootTrackerView: JPanel? = null
fun loadGEPrices(): Map<String, String> { fun loadGEPrices(): Map<String, String> {
@ -283,7 +283,7 @@ object LootTrackerView {
// Function to show the custom tooltip // Function to show the custom tooltip
fun showCustomToolTip(location: Point, itemId: Int, quantity: Int, parentComponent: ImageCanvas) { fun showCustomToolTip(location: Point, itemId: Int, quantity: Int, parentComponent: ImageCanvas) {
var itemDef = ObjTypeList.get(itemId) val itemDef = ObjTypeList.get(itemId)
val gePricePerItem = gePriceMap[itemDef.id.toString()]?.toInt() ?: 0 val gePricePerItem = gePriceMap[itemDef.id.toString()]?.toInt() ?: 0
val totalGePrice = gePricePerItem * quantity val totalGePrice = gePricePerItem * quantity
val totalHaPrice = itemDef.cost * quantity val totalHaPrice = itemDef.cost * quantity
@ -382,7 +382,7 @@ object LootTrackerView {
if (newDrops.isNotEmpty()) { if (newDrops.isNotEmpty()) {
val npcName = NpcTypeList.get(npcId).name val npcName = NpcTypeList.get(npcId).name
lastConfirmedKillNpcId = npcId; lastConfirmedKillNpcId = npcId
handleNewDrops(npcName.toString(), newDrops, lootTrackerView) handleNewDrops(npcName.toString(), newDrops, lootTrackerView)
toRemove.add(npcId) toRemove.add(npcId)
} else if (snapshot.age >= SNAPSHOT_LIFESPAN) { } else if (snapshot.age >= SNAPSHOT_LIFESPAN) {
@ -501,7 +501,7 @@ object LootTrackerView {
return childFramePanel return childFramePanel
} }
fun removeLootFrameMenu(toRemove: JPanel, npcName: String): JPopupMenu { private fun removeLootFrameMenu(toRemove: JPanel, npcName: String): JPopupMenu {
// Create a popup menu // Create a popup menu
val popupMenu = JPopupMenu() val popupMenu = JPopupMenu()
val rFont = Font("RuneScape Small", Font.TRUETYPE_FONT, 16) val rFont = Font("RuneScape Small", Font.TRUETYPE_FONT, 16)
@ -538,7 +538,7 @@ object LootTrackerView {
} }
fun resetLootTrackerMenu(): JPopupMenu { private fun resetLootTrackerMenu(): JPopupMenu {
// Create a popup menu // Create a popup menu
val popupMenu = JPopupMenu() val popupMenu = JPopupMenu()
val rFont = Font("RuneScape Small", Font.TRUETYPE_FONT, 16) val rFont = Font("RuneScape Small", Font.TRUETYPE_FONT, 16)

View file

@ -30,7 +30,7 @@ import kotlin.math.ceil
object ReflectiveEditorView { object ReflectiveEditorView {
var reflectiveEditorView: JPanel? = null var reflectiveEditorView: JPanel? = null
val loadedPlugins: MutableList<String> = mutableListOf() private val loadedPlugins: MutableList<String> = mutableListOf()
const val VIEW_NAME = "REFLECTIVE_EDITOR_VIEW" const val VIEW_NAME = "REFLECTIVE_EDITOR_VIEW"
fun createReflectiveEditorView() { fun createReflectiveEditorView() {
val reflectiveEditorPanel = JPanel(BorderLayout()) val reflectiveEditorPanel = JPanel(BorderLayout())
@ -266,7 +266,7 @@ object ReflectiveEditorView {
} }
} }
else { else {
loadedPlugins.add(plugin.javaClass.`package`.name); loadedPlugins.add(plugin.javaClass.`package`.name)
} }
} }

View file

@ -69,7 +69,7 @@ object SpriteToBufferedImage {
* @param brightnessBoost A multiplier to boost the brightness of the image. * @param brightnessBoost A multiplier to boost the brightness of the image.
* @return The BufferedImage created from the sprite. * @return The BufferedImage created from the sprite.
*/ */
fun convertToBufferedImage( private fun convertToBufferedImage(
sprite: BaseSprite, sprite: BaseSprite,
tint: Color? = null, tint: Color? = null,
grayscale: Boolean = false, grayscale: Boolean = false,
@ -88,7 +88,7 @@ object SpriteToBufferedImage {
for (y in 0 until height) { for (y in 0 until height) {
for (x in 0 until width) { for (x in 0 until width) {
val index = pixels[y * width + x].toInt() and 0xFF val index = pixels[y * width + x].toInt() and 0xFF
var color = palette[index] val color = palette[index]
// Apply grayscale or tint if provided // Apply grayscale or tint if provided
val finalColor = if (grayscale) { val finalColor = if (grayscale) {
@ -109,7 +109,7 @@ object SpriteToBufferedImage {
// Manually set pixels directly // Manually set pixels directly
for (y in 0 until height) { for (y in 0 until height) {
for (x in 0 until width) { for (x in 0 until width) {
var color = pixels[y * width + x] val color = pixels[y * width + x]
// Apply grayscale or tint if provided // Apply grayscale or tint if provided
val finalColor = if (grayscale) { val finalColor = if (grayscale) {
@ -137,7 +137,7 @@ object SpriteToBufferedImage {
* @param brightnessBoost A multiplier to boost the brightness of the image. * @param brightnessBoost A multiplier to boost the brightness of the image.
* @return The tinted color. * @return The tinted color.
*/ */
fun applyTint(original: Color, tint: Color, brightnessBoost: Float): Color { private fun applyTint(original: Color, tint: Color, brightnessBoost: Float): Color {
val boostedColor = applyBrightness(original, brightnessBoost) val boostedColor = applyBrightness(original, brightnessBoost)
val r = (boostedColor.red * tint.red / 255).coerceIn(0, 255) val r = (boostedColor.red * tint.red / 255).coerceIn(0, 255)
val g = (boostedColor.green * tint.green / 255).coerceIn(0, 255) val g = (boostedColor.green * tint.green / 255).coerceIn(0, 255)
@ -152,7 +152,7 @@ object SpriteToBufferedImage {
* @param factor The multiplier to boost the brightness. * @param factor The multiplier to boost the brightness.
* @return The color with boosted brightness. * @return The color with boosted brightness.
*/ */
fun applyBrightness(original: Color, factor: Float): Color { private fun applyBrightness(original: Color, factor: Float): Color {
val r = (original.red * factor).coerceIn(0.0f, 255.0f).toInt() val r = (original.red * factor).coerceIn(0.0f, 255.0f).toInt()
val g = (original.green * factor).coerceIn(0.0f, 255.0f).toInt() val g = (original.green * factor).coerceIn(0.0f, 255.0f).toInt()
val b = (original.blue * factor).coerceIn(0.0f, 255.0f).toInt() val b = (original.blue * factor).coerceIn(0.0f, 255.0f).toInt()
@ -166,7 +166,7 @@ object SpriteToBufferedImage {
* @param brightnessBoost A multiplier to boost the brightness. * @param brightnessBoost A multiplier to boost the brightness.
* @return The grayscale version of the color with boosted brightness. * @return The grayscale version of the color with boosted brightness.
*/ */
fun applyGrayscale(original: Color, brightnessBoost: Float): Color { private fun applyGrayscale(original: Color, brightnessBoost: Float): Color {
// Calculate the grayscale value using the luminosity method // Calculate the grayscale value using the luminosity method
val grayValue = (0.3 * original.red + 0.59 * original.green + 0.11 * original.blue).toInt() val grayValue = (0.3 * original.red + 0.59 * original.green + 0.11 * original.blue).toInt()
val boostedGray = (grayValue * brightnessBoost).coerceIn(0.0f, 255.0f).toInt() val boostedGray = (grayValue * brightnessBoost).coerceIn(0.0f, 255.0f).toInt()

View file

@ -6,9 +6,9 @@ import rt4.Node
object XPTable { object XPTable {
const val MAX_LEVEL = 99 private const val MAX_LEVEL = 99
const val INVALID_LEVEL = -1 private const val INVALID_LEVEL = -1
const val SKILLS_XP_TABLE = 716 private const val SKILLS_XP_TABLE = 716
private var xpTable: MutableList<Int> = mutableListOf() private var xpTable: MutableList<Int> = mutableListOf()

View file

@ -107,7 +107,7 @@ class plugin : Plugin() {
private var rightPanelWrapper: JScrollPane? = null private var rightPanelWrapper: JScrollPane? = null
private var accumulatedTime = 0L private var accumulatedTime = 0L
private var reloadInterfaces = false private var reloadInterfaces = false
private const val tickInterval = 600L private const val TICK_INTERVAL = 600L
private var pluginsReloaded = false private var pluginsReloaded = false
private var loginScreen = 160 private var loginScreen = 160
private var lastLogin = "" private var lastLogin = ""
@ -126,7 +126,7 @@ class plugin : Plugin() {
} }
} }
fun allSpritesLoaded() : Boolean { private fun allSpritesLoaded() : Boolean {
// Check all skill sprites // Check all skill sprites
try{ try{
for (i in 0 until 24) { for (i in 0 until 24) {
@ -171,10 +171,10 @@ class plugin : Plugin() {
moveAltCanvasToFront() moveAltCanvasToFront()
frame.setComponentZOrder(rightPanelWrapper, 2) frame.setComponentZOrder(rightPanelWrapper, 2)
} }
UpdateDisplaySettings() updateDisplaySettings()
} }
private fun UpdateDisplaySettings() { private fun updateDisplaySettings() {
val mode = GetWindowMode() val mode = GetWindowMode()
val currentScrollPaneWidth = if (mainContentPanel.isVisible) NAVBAR_WIDTH + MAIN_CONTENT_WIDTH else NAVBAR_WIDTH val currentScrollPaneWidth = if (mainContentPanel.isVisible) NAVBAR_WIDTH + MAIN_CONTENT_WIDTH else NAVBAR_WIDTH
lastUIOffset = uiOffset lastUIOffset = uiOffset
@ -233,7 +233,7 @@ class plugin : Plugin() {
destroyAltCanvas() destroyAltCanvas()
} }
if(lastUIOffset != uiOffset){ if(lastUIOffset != uiOffset){
UpdateDisplaySettings() updateDisplaySettings()
reloadInterfaces = true reloadInterfaces = true
} }
} }
@ -242,7 +242,7 @@ class plugin : Plugin() {
moveCanvasToFront() moveCanvasToFront()
frame.remove(altCanvas) frame.remove(altCanvas)
altCanvas = null altCanvas = null
UpdateDisplaySettings() updateDisplaySettings()
} }
override fun OnMiniMenuCreate(currentEntries: Array<out MiniMenuEntry>?) { override fun OnMiniMenuCreate(currentEntries: Array<out MiniMenuEntry>?) {
@ -278,10 +278,10 @@ class plugin : Plugin() {
override fun OnPluginsReloaded(): Boolean { override fun OnPluginsReloaded(): Boolean {
if (!initialized) return true if (!initialized) return true
UpdateDisplaySettings() updateDisplaySettings()
frame.remove(rightPanelWrapper) frame.remove(rightPanelWrapper)
frame.layout = BorderLayout() frame.layout = BorderLayout()
frame.add(rightPanelWrapper, BorderLayout.EAST) rightPanelWrapper?.let { frame.add(it, BorderLayout.EAST) }
frame.revalidate() frame.revalidate()
pluginsReloaded = true pluginsReloaded = true
reloadInterfaces = true reloadInterfaces = true
@ -332,7 +332,7 @@ class plugin : Plugin() {
} }
accumulatedTime += timeDelta accumulatedTime += timeDelta
if (accumulatedTime >= tickInterval) { if (accumulatedTime >= TICK_INTERVAL) {
lootTrackerView?.let { onPostClientTick(it) } lootTrackerView?.let { onPostClientTick(it) }
accumulatedTime = 0L accumulatedTime = 0L
} }
@ -374,21 +374,14 @@ class plugin : Plugin() {
} }
private fun moveAltCanvasToFront(){ private fun moveAltCanvasToFront(){
if(altCanvas == null) { if(altCanvas == null) return
println("WARNING: altcanvas is null")
return
}
frame.setComponentZOrder(canvas, 2) frame.setComponentZOrder(canvas, 2)
frame.setComponentZOrder(altCanvas, 1) frame.setComponentZOrder(altCanvas, 1)
frame.setComponentZOrder(rightPanelWrapper, 0) frame.setComponentZOrder(rightPanelWrapper, 0)
} }
private fun moveCanvasToFront(){ private fun moveCanvasToFront(){
if(altCanvas == null) { if(altCanvas == null) return
println("WARNING: altcanvas is null")
return
}
frame.setComponentZOrder(altCanvas, 2) frame.setComponentZOrder(altCanvas, 2)
frame.setComponentZOrder(canvas, 1) frame.setComponentZOrder(canvas, 1)
frame.setComponentZOrder(rightPanelWrapper, 0) frame.setComponentZOrder(rightPanelWrapper, 0)
@ -401,7 +394,7 @@ class plugin : Plugin() {
val osName = System.getProperty("os.name").toLowerCase() val osName = System.getProperty("os.name").toLowerCase()
uiOffset = (GetData("kondoUIOffset") as? Int) ?: if (osName.contains("win")) 16 else 0 uiOffset = (GetData("kondoUIOffset") as? Int) ?: if (osName.contains("win")) 16 else 0
launchMinimized = (GetData("kondoLaunchMinimized") as? Boolean) ?: false launchMinimized = (GetData("kondoLaunchMinimized") as? Boolean) ?: false
useScaledFixed = (GetData("kondoScaleFixed") as? Boolean) ?: false useScaledFixed = (GetData("kondoScaledFixed") as? Boolean) ?: false
} }
private fun initKondoUI(){ private fun initKondoUI(){
@ -517,7 +510,7 @@ class plugin : Plugin() {
} }
reloadInterfaces = true reloadInterfaces = true
UpdateDisplaySettings() updateDisplaySettings()
// Revalidate and repaint necessary panels // Revalidate and repaint necessary panels
mainContentPanel.revalidate() mainContentPanel.revalidate()
@ -674,7 +667,7 @@ class plugin : Plugin() {
} }
} }
fun loadFont(): Font? { private fun loadFont(): Font? {
val fontStream = plugin::class.java.getResourceAsStream("res/runescape_small.ttf") val fontStream = plugin::class.java.getResourceAsStream("res/runescape_small.ttf")
return if (fontStream != null) { return if (fontStream != null) {
try { try {
@ -696,7 +689,7 @@ class plugin : Plugin() {
var focusedView: String = "" var focusedView: String = ""
} }
fun applyTheme(theme: Theme) { private fun applyTheme(theme: Theme) {
WIDGET_COLOR = theme.widgetColor WIDGET_COLOR = theme.widgetColor
TITLE_BAR_COLOR = theme.titleBarColor TITLE_BAR_COLOR = theme.titleBarColor
VIEW_BACKGROUND_COLOR = theme.viewBackgroundColor VIEW_BACKGROUND_COLOR = theme.viewBackgroundColor