You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
2.4 KiB
Kotlin

package net.idylls.tickle
import org.slf4j.LoggerFactory
import javax.inject.Inject
import java.awt.GridLayout
import java.awt.BorderLayout
import java.awt.event.ActionEvent
import java.awt.event.FocusEvent
import java.awt.event.FocusListener
import java.awt.Color
import javax.swing.AbstractAction
import javax.swing.BorderFactory
import javax.swing.BoxLayout
import javax.swing.JPanel
import javax.swing.JLabel
import net.runelite.client.ui.ColorScheme
import net.runelite.client.ui.PluginPanel
import net.runelite.api.Client
import net.runelite.client.ui.FontManager
class CurrentWorldPanel
constructor(
val plugin: TicklePlugin,
) : JPanel() {
val lastTickTime = JLabel()
val averageTickTime = JLabel()
val goodTickPercentage = JLabel()
val worstTickDeviation = JLabel()
init {
this.setLayout(BoxLayout(this, BoxLayout.Y_AXIS))
this.setBackground(ColorScheme.DARKER_GRAY_COLOR)
averageTickTime.setForeground(Color.WHITE);
averageTickTime.setFont(FontManager.getRunescapeFont());
worstTickDeviation.setForeground(Color.WHITE);
worstTickDeviation.setFont(FontManager.getRunescapeFont());
lastTickTime.setForeground(Color.WHITE);
lastTickTime.setFont(FontManager.getRunescapeFont());
goodTickPercentage.setForeground(Color.WHITE);
goodTickPercentage.setFont(FontManager.getRunescapeFont());
this.add(lastTickTime)
this.add(averageTickTime)
this.add(goodTickPercentage)
this.add(worstTickDeviation)
}
fun update() {
val current = plugin.worldsStats.current()
if (current == null) {
return
}
this.lastTickTime.setText("Last tick time: ${current.lastTickTime}ms")
this.averageTickTime.setText("Avg tick time: ${current.averageTickTime}ms")
this.goodTickPercentage.setText("Good tick %: ${(
((current.tickCount - current.badTickCount).toDouble()
/ current.tickCount.toDouble()) * 100.0
)}%")
this.worstTickDeviation.setText("Worst dev: ${current.worstTickDeviation}ms")
}
}
class Panel
@Inject constructor(
val client: Client,
val plugin: TicklePlugin,
) : PluginPanel() {
val log = LoggerFactory.getLogger(Panel::class.java)
val currentWorldPanel = CurrentWorldPanel(plugin)
init {
this.setLayout(BorderLayout())
this.setBorder(BorderFactory.createEmptyBorder(10, 10, 0, 10))
this.setBackground(ColorScheme.DARK_GRAY_COLOR)
this.log.info("Initialized Tickle panel")
this.add(this.currentWorldPanel)
}
fun updateCurrentPanel() {
this.currentWorldPanel.update()
}
}