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() {
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 keyPressed(e: KeyEvent) = relayKeyEvent { it.keyPressed(e) }
override fun keyReleased(e: KeyEvent) = relayKeyEvent { it.keyReleased(e) }
override fun keyTyped(e: KeyEvent) = relayKeyEvent { it.keyTyped(e) }
})
addMouseWheelListener(object : MouseWheelListener {
override fun mouseWheelMoved(e: MouseWheelEvent) = relayMouseWheelEvent(e)
})
addMouseWheelListener(MouseWheelListener { e -> relayMouseWheelEvent(e) })
}
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))
}
private fun relayKeyEvent(e: KeyEvent, action: (KeyListener) -> Unit) {
private fun relayKeyEvent(action: (KeyListener) -> Unit) {
for (listener in canvas.keyListeners) action(listener)
}

View file

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

View file

@ -75,8 +75,8 @@ object HiscoresView {
private var cursorVisible: Boolean = true
private val gson = Gson()
val bufferedImageSprite = getBufferedImageFromSprite(API.GetSprite(Constants.MAG_SPRITE))
val imageCanvas = bufferedImageSprite.let {
private val bufferedImageSprite = getBufferedImageFromSprite(API.GetSprite(Constants.MAG_SPRITE))
private val imageCanvas = bufferedImageSprite.let {
ImageCanvas(it).apply {
preferredSize = Constants.ICON_DIMENSION_SMALL
size = preferredSize
@ -241,7 +241,7 @@ object HiscoresView {
playerNameLabel?.revalidate()
playerNameLabel?.repaint()
if(data == null) return;
if(data == null) return
playerNameLabel?.removeAll()
@ -325,10 +325,6 @@ object HiscoresView {
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? {
for (component in container.components) {
if (name == component.name) {
@ -443,7 +439,7 @@ object HiscoresView {
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 {
fillColor = COLOR_BACKGROUND_DARK
@ -492,7 +488,7 @@ object HiscoresView {
hiscorePanel.add(totalCombatPanel)
hiscorePanel.add(Box.createVerticalStrut(10))
hiScoreView = hiscorePanel;
hiScoreView = hiscorePanel
}
data class HiscoresResponse(

View file

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

View file

@ -30,7 +30,7 @@ import kotlin.math.ceil
object ReflectiveEditorView {
var reflectiveEditorView: JPanel? = null
val loadedPlugins: MutableList<String> = mutableListOf()
private val loadedPlugins: MutableList<String> = mutableListOf()
const val VIEW_NAME = "REFLECTIVE_EDITOR_VIEW"
fun createReflectiveEditorView() {
val reflectiveEditorPanel = JPanel(BorderLayout())
@ -266,7 +266,7 @@ object ReflectiveEditorView {
}
}
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.
* @return The BufferedImage created from the sprite.
*/
fun convertToBufferedImage(
private fun convertToBufferedImage(
sprite: BaseSprite,
tint: Color? = null,
grayscale: Boolean = false,
@ -88,7 +88,7 @@ object SpriteToBufferedImage {
for (y in 0 until height) {
for (x in 0 until width) {
val index = pixels[y * width + x].toInt() and 0xFF
var color = palette[index]
val color = palette[index]
// Apply grayscale or tint if provided
val finalColor = if (grayscale) {
@ -109,7 +109,7 @@ object SpriteToBufferedImage {
// Manually set pixels directly
for (y in 0 until height) {
for (x in 0 until width) {
var color = pixels[y * width + x]
val color = pixels[y * width + x]
// Apply grayscale or tint if provided
val finalColor = if (grayscale) {
@ -137,7 +137,7 @@ object SpriteToBufferedImage {
* @param brightnessBoost A multiplier to boost the brightness of the image.
* @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 r = (boostedColor.red * tint.red / 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.
* @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 g = (original.green * 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.
* @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
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()

View file

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

View file

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