mirror of
https://gitlab.com/2009scape/rt4-client.git
synced 2025-12-20 05:20:24 -07:00
More helpers/DRY
This commit is contained in:
parent
573e579643
commit
47e545cbc7
17 changed files with 264 additions and 289 deletions
|
|
@ -8,6 +8,7 @@ import KondoKit.Helpers.getProgressBarColor
|
|||
import KondoKit.Helpers.getSpriteId
|
||||
import KondoKit.SpriteToBufferedImage.getBufferedImageFromSprite
|
||||
import KondoKit.ViewConstants
|
||||
import KondoKit.setFixedSize
|
||||
import KondoKit.XPTable
|
||||
import KondoKit.components.PopupMenuComponent
|
||||
import KondoKit.components.ProgressBar
|
||||
|
|
@ -18,8 +19,6 @@ import KondoKit.plugin.Companion.TOTAL_XP_WIDGET_SIZE
|
|||
import KondoKit.plugin.Companion.WIDGET_COLOR
|
||||
import KondoKit.plugin.Companion.WIDGET_SIZE
|
||||
import KondoKit.plugin
|
||||
import KondoKit.plugin.Companion.POPUP_BACKGROUND
|
||||
import KondoKit.plugin.Companion.POPUP_FOREGROUND
|
||||
import KondoKit.plugin.Companion.playerXPMultiplier
|
||||
import KondoKit.plugin.Companion.primaryColor
|
||||
import KondoKit.plugin.Companion.secondaryColor
|
||||
|
|
@ -126,12 +125,6 @@ object XPTrackerView : View, OnUpdateCallback, OnXPUpdateCallback {
|
|||
}
|
||||
}
|
||||
|
||||
private fun createMenuItem(text: String): JMenuItem = JMenuItem(text).apply {
|
||||
font = widgetFont
|
||||
background = POPUP_BACKGROUND
|
||||
foreground = POPUP_FOREGROUND
|
||||
}
|
||||
|
||||
private fun getSkillIcon(skillId: Int): BufferedImage {
|
||||
return skillIconCache[skillId] ?: getBufferedImageFromSprite(API.GetSprite(getSpriteId(skillId))).also {
|
||||
skillIconCache[skillId] = it
|
||||
|
|
@ -366,24 +359,16 @@ object XPTrackerView : View, OnUpdateCallback, OnXPUpdateCallback {
|
|||
|
||||
fun createResetMenu(): JPopupMenu {
|
||||
val popupMenu = PopupMenuComponent()
|
||||
|
||||
val resetItem = createMenuItem("Reset Tracker")
|
||||
popupMenu.add(resetItem)
|
||||
|
||||
resetItem.addActionListener { plugin.registerDrawAction { resetXPTracker(xpTrackerView!!) } }
|
||||
popupMenu.addMenuItem("Reset Tracker") {
|
||||
plugin.registerDrawAction { resetXPTracker(xpTrackerView!!) }
|
||||
}
|
||||
return popupMenu
|
||||
}
|
||||
|
||||
fun removeXPWidgetMenu(toRemove: Container, skillId: Int): JPopupMenu {
|
||||
val popupMenu = PopupMenuComponent()
|
||||
|
||||
val resetItem = createMenuItem("Reset")
|
||||
popupMenu.add(resetItem)
|
||||
|
||||
val removeItem = createMenuItem("Remove")
|
||||
popupMenu.add(removeItem)
|
||||
|
||||
resetItem.addActionListener {
|
||||
popupMenu.addMenuItem("Reset") {
|
||||
xpWidgets[skillId]?.let { widget ->
|
||||
// Baseline at current XP and clear per-widget counters
|
||||
initialXP[skillId] = widget.previousXp
|
||||
|
|
@ -395,7 +380,7 @@ object XPTrackerView : View, OnUpdateCallback, OnXPUpdateCallback {
|
|||
}
|
||||
}
|
||||
|
||||
removeItem.addActionListener {
|
||||
popupMenu.addMenuItem("Remove") {
|
||||
// Reset the per-skill baseline to the current XP so next widget starts fresh
|
||||
xpWidgets[skillId]?.let { widget ->
|
||||
initialXP[skillId] = widget.previousXp
|
||||
|
|
@ -440,9 +425,7 @@ object XPTrackerView : View, OnUpdateCallback, OnXPUpdateCallback {
|
|||
val actionsLabel = createMetricLabel(actionsTitle)
|
||||
|
||||
val progressBar = ProgressBar(0.0, getProgressBarColor(skillId)).apply {
|
||||
preferredSize = Dimension(160, 22)
|
||||
minimumSize = preferredSize
|
||||
maximumSize = preferredSize
|
||||
setFixedSize(160, 22)
|
||||
}
|
||||
|
||||
val progressPanel = JPanel(BorderLayout()).apply {
|
||||
|
|
@ -484,15 +467,11 @@ object XPTrackerView : View, OnUpdateCallback, OnXPUpdateCallback {
|
|||
)
|
||||
val outerPanel = JPanel(GridBagLayout()).apply {
|
||||
background = WIDGET_COLOR
|
||||
preferredSize = outerPanelSize
|
||||
maximumSize = outerPanelSize
|
||||
minimumSize = outerPanelSize
|
||||
setFixedSize(outerPanelSize)
|
||||
}
|
||||
val innerPanel = JPanel(BorderLayout()).apply {
|
||||
background = WIDGET_COLOR
|
||||
preferredSize = component.preferredSize
|
||||
maximumSize = component.preferredSize
|
||||
minimumSize = component.preferredSize
|
||||
setFixedSize(component.preferredSize)
|
||||
add(component, BorderLayout.CENTER)
|
||||
}
|
||||
val gbc = GridBagConstraints().apply {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue