Move themes to a new file, add color boost

This commit is contained in:
downthecrop 2024-10-22 21:26:54 -07:00
parent 2a059d1c02
commit 5948810ca7
3 changed files with 160 additions and 123 deletions

View file

@ -66,9 +66,15 @@ object SpriteToBufferedImage {
* @param sprite The sprite to be converted. * @param sprite The sprite to be converted.
* @param tint An optional Color to tint the image. * @param tint An optional Color to tint the image.
* @param grayscale If true, converts the image to grayscale. * @param grayscale If true, converts the image to grayscale.
* @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(sprite: BaseSprite, tint: Color? = null, grayscale: Boolean = false): BufferedImage { fun convertToBufferedImage(
sprite: BaseSprite,
tint: Color? = null,
grayscale: Boolean = false,
brightnessBoost: Float = 1.0f
): BufferedImage {
val width = sprite.width val width = sprite.width
val height = sprite.height val height = sprite.height
val image = BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB) val image = BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB)
@ -86,11 +92,11 @@ object SpriteToBufferedImage {
// Apply grayscale or tint if provided // Apply grayscale or tint if provided
val finalColor = if (grayscale) { val finalColor = if (grayscale) {
applyGrayscale(Color(color, true)) applyGrayscale(Color(color, true), brightnessBoost)
} else if (tint != null) { } else if (tint != null) {
applyTint(Color(color, true), tint) applyTint(Color(color, true), tint, brightnessBoost)
} else { } else {
Color(color, true) applyBrightness(Color(color, true), brightnessBoost)
} }
image.setRGB(x, y, finalColor.rgb) image.setRGB(x, y, finalColor.rgb)
@ -107,11 +113,11 @@ object SpriteToBufferedImage {
// Apply grayscale or tint if provided // Apply grayscale or tint if provided
val finalColor = if (grayscale) { val finalColor = if (grayscale) {
applyGrayscale(Color(color, true)) applyGrayscale(Color(color, true), brightnessBoost)
} else if (tint != null) { } else if (tint != null) {
applyTint(Color(color, true), tint) applyTint(Color(color, true), tint, brightnessBoost)
} else { } else {
Color(color, true) applyBrightness(Color(color, true), brightnessBoost)
} }
image.setRGB(x, y, finalColor.rgb) image.setRGB(x, y, finalColor.rgb)
@ -127,32 +133,44 @@ object SpriteToBufferedImage {
* Applies a tint to a given color using the tint's alpha value to control the intensity. * Applies a tint to a given color using the tint's alpha value to control the intensity.
* *
* @param original The original color. * @param original The original color.
* @param tint The tint color to be applied, with alpha controlling the intensity. * @param tint The tint color to be applied.
* @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): Color { fun applyTint(original: Color, tint: Color, brightnessBoost: Float): Color {
val alpha = tint.alpha / 255.0 // Normalize alpha to range [0, 1] val boostedColor = applyBrightness(original, brightnessBoost)
val invAlpha = 1.0 - alpha val r = (boostedColor.red * tint.red / 255).coerceIn(0, 255)
val g = (boostedColor.green * tint.green / 255).coerceIn(0, 255)
// Blend the tint with the original color based on the alpha val b = (boostedColor.blue * tint.blue / 255).coerceIn(0, 255)
val r = (original.red * invAlpha + tint.red * alpha).toInt().coerceIn(0, 255) return Color(r, g, b, boostedColor.alpha)
val g = (original.green * invAlpha + tint.green * alpha).toInt().coerceIn(0, 255) }
val b = (original.blue * invAlpha + tint.blue * alpha).toInt().coerceIn(0, 255)
/**
* Boosts the brightness of a given color.
*
* @param original The original color.
* @param factor The multiplier to boost the brightness.
* @return The color with boosted brightness.
*/
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()
return Color(r, g, b, original.alpha) return Color(r, g, b, original.alpha)
} }
/** /**
* Converts a color to grayscale. * Converts a color to grayscale and applies a brightness boost.
* *
* @param original The original color. * @param original The original color.
* @return The grayscale version of the color. * @param brightnessBoost A multiplier to boost the brightness.
* @return The grayscale version of the color with boosted brightness.
*/ */
fun applyGrayscale(original: Color): Color { 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()
return Color(grayValue, grayValue, grayValue, original.alpha) val boostedGray = (grayValue * brightnessBoost).coerceIn(0.0f, 255.0f).toInt()
return Color(boostedGray, boostedGray, boostedGray, original.alpha)
} }
/** /**
@ -161,14 +179,20 @@ object SpriteToBufferedImage {
* @param sprite The sprite object to be converted. * @param sprite The sprite object to be converted.
* @param tint An optional Color to tint the image. * @param tint An optional Color to tint the image.
* @param grayscale If true, converts the image to grayscale. * @param grayscale If true, converts the image to grayscale.
* @param brightnessBoost A multiplier to boost the brightness of the image.
* @return The BufferedImage created from the sprite or a default image if unsupported. * @return The BufferedImage created from the sprite or a default image if unsupported.
*/ */
fun getBufferedImageFromSprite(sprite: Any?, tint: Color? = null, grayscale: Boolean = false): BufferedImage { fun getBufferedImageFromSprite(
sprite: Any?,
tint: Color? = null,
grayscale: Boolean = false,
brightnessBoost: Float = 1.0f
): BufferedImage {
return when (sprite) { return when (sprite) {
is SoftwareSprite -> convertToBufferedImage(adaptSoftwareSprite(sprite), tint, grayscale) is SoftwareSprite -> convertToBufferedImage(adaptSoftwareSprite(sprite), tint, grayscale, brightnessBoost)
is SoftwareIndexedSprite -> convertToBufferedImage(adaptSoftwareIndexedSprite(sprite), tint, grayscale) is SoftwareIndexedSprite -> convertToBufferedImage(adaptSoftwareIndexedSprite(sprite), tint, grayscale, brightnessBoost)
is GlSprite -> convertToBufferedImage(adaptGlSprite(sprite), tint, grayscale) is GlSprite -> convertToBufferedImage(adaptGlSprite(sprite), tint, grayscale, brightnessBoost)
is GlIndexedSprite -> convertToBufferedImage(adaptGlIndexedSprite(sprite), tint, grayscale) is GlIndexedSprite -> convertToBufferedImage(adaptGlIndexedSprite(sprite), tint, grayscale, brightnessBoost)
else -> BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB) // Default empty image for unsupported types else -> BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB) // Default empty image for unsupported types
} }
} }

View file

@ -0,0 +1,94 @@
package KondoKit
import java.awt.Color
object Themes {
enum class ThemeType {
RUNELITE,
DARKER_RUNELITE,
SARADOMIN,
ORION,
}
fun getTheme(themeType: ThemeType): Theme {
return when (themeType) {
ThemeType.RUNELITE -> Theme(
widgetColor = Color(30, 30, 30),
titleBarColor = Color(21, 21, 21),
viewBackgroundColor = Color(40, 40, 40),
primaryColor = Color(165, 165, 165),
secondaryColor = Color(255, 255, 255),
popupBackground = Color(45, 45, 45),
popupForeground = Color(220, 220, 220),
tooltipBackground = Color(50, 50, 50),
scrollBarColor = Color(64, 64, 64),
progressBarFill = Color(61, 56, 49),
navTint = null,
navGreyScale = false,
boost = 1f
)
ThemeType.DARKER_RUNELITE -> Theme(
widgetColor = Color(15, 15, 15),
titleBarColor = Color(10, 10, 10),
viewBackgroundColor = Color(20, 20, 20),
primaryColor = Color(140, 140, 140),
secondaryColor = Color(210, 210, 210),
popupBackground = Color(25, 25, 25),
popupForeground = Color(200, 200, 200),
tooltipBackground = Color(30, 30, 30),
scrollBarColor = Color(40, 40, 40),
progressBarFill = Color(45, 40, 35),
navTint = null,
navGreyScale = false,
boost = 0.8f
)
ThemeType.ORION -> Theme(
widgetColor = Color(50, 50, 50),
titleBarColor = Color(35, 35, 35),
viewBackgroundColor = Color(60, 60, 60),
primaryColor = Color(180, 180, 180),
secondaryColor = Color(210, 210, 210),
popupBackground = Color(45, 45, 45),
popupForeground = Color(230, 230, 230),
tooltipBackground = Color(55, 55, 55),
scrollBarColor = Color(75, 75, 75),
progressBarFill = Color(100, 100, 100),
navTint = null,
navGreyScale = true,
boost = 1.3f
)
ThemeType.SARADOMIN -> Theme(
widgetColor = Color(62, 53, 41),
titleBarColor = Color(111, 93, 69).darker(),
viewBackgroundColor = Color(111, 93, 69),
primaryColor = Color(180, 150, 120),
secondaryColor = Color(230, 210, 190),
popupBackground = Color(70, 56, 42),
popupForeground = Color(220, 200, 180),
tooltipBackground = Color(80, 65, 50),
scrollBarColor = Color(100, 85, 70),
progressBarFill = Color(130, 110, 90),
navTint = null,
navGreyScale = false,
boost = 1f
)
}
}
data class Theme(
val widgetColor: Color,
val titleBarColor: Color,
val viewBackgroundColor: Color,
val primaryColor: Color,
val secondaryColor: Color,
val popupBackground: Color,
val popupForeground: Color,
val tooltipBackground: Color,
val scrollBarColor: Color,
val progressBarFill: Color,
val navTint: Color?,
val navGreyScale: Boolean,
val boost: Float
)
}

View file

@ -5,7 +5,6 @@ import KondoKit.Helpers.formatHtmlLabelText
import KondoKit.Helpers.formatNumber import KondoKit.Helpers.formatNumber
import KondoKit.Helpers.getSpriteId import KondoKit.Helpers.getSpriteId
import KondoKit.Helpers.showAlert import KondoKit.Helpers.showAlert
import KondoKit.Helpers.showToast
import KondoKit.HiscoresView.createHiscoreSearchView import KondoKit.HiscoresView.createHiscoreSearchView
import KondoKit.HiscoresView.hiScoreView import KondoKit.HiscoresView.hiScoreView
import KondoKit.LootTrackerView.BAG_ICON import KondoKit.LootTrackerView.BAG_ICON
@ -18,6 +17,9 @@ import KondoKit.ReflectiveEditorView.addPlugins
import KondoKit.ReflectiveEditorView.createReflectiveEditorView import KondoKit.ReflectiveEditorView.createReflectiveEditorView
import KondoKit.ReflectiveEditorView.reflectiveEditorView import KondoKit.ReflectiveEditorView.reflectiveEditorView
import KondoKit.SpriteToBufferedImage.getBufferedImageFromSprite import KondoKit.SpriteToBufferedImage.getBufferedImageFromSprite
import KondoKit.Themes.Theme
import KondoKit.Themes.ThemeType
import KondoKit.Themes.getTheme
import KondoKit.XPTrackerView.createXPTrackerView import KondoKit.XPTrackerView.createXPTrackerView
import KondoKit.XPTrackerView.createXPWidget import KondoKit.XPTrackerView.createXPWidget
import KondoKit.XPTrackerView.initialXP import KondoKit.XPTrackerView.initialXP
@ -28,7 +30,6 @@ import KondoKit.XPTrackerView.wrappedWidget
import KondoKit.XPTrackerView.xpTrackerView import KondoKit.XPTrackerView.xpTrackerView
import KondoKit.XPTrackerView.xpWidgets import KondoKit.XPTrackerView.xpWidgets
import KondoKit.plugin.StateManager.focusedView import KondoKit.plugin.StateManager.focusedView
import com.sun.org.apache.xpath.internal.operations.Bool
import plugin.Plugin import plugin.Plugin
import plugin.api.* import plugin.api.*
import plugin.api.API.* import plugin.api.API.*
@ -70,6 +71,7 @@ class plugin : Plugin() {
var PROGRESS_BAR_FILL = Color(61, 56, 49) var PROGRESS_BAR_FILL = Color(61, 56, 49)
var NAV_TINT: Color? = null var NAV_TINT: Color? = null
var NAV_GREYSCALE = false var NAV_GREYSCALE = false
var BOOST = 1f
var appliedTheme = ThemeType.RUNELITE var appliedTheme = ThemeType.RUNELITE
@ -105,10 +107,10 @@ class plugin : Plugin() {
private var pluginsReloaded = false private var pluginsReloaded = false
private var loginScreen = 160 private var loginScreen = 160
private var lastLogin = "" private var lastLogin = ""
private var initialized = false; private var initialized = false
private var lastClickTime = 0L private var lastClickTime = 0L
private var lastUIOffset = 0 private var lastUIOffset = 0
private const val HIDDEN_VIEW = "HIDDEN"; private const val HIDDEN_VIEW = "HIDDEN"
private val drawActions = mutableListOf<() -> Unit>() private val drawActions = mutableListOf<() -> Unit>()
fun registerDrawAction(action: () -> Unit) { fun registerDrawAction(action: () -> Unit) {
@ -123,19 +125,19 @@ class plugin : Plugin() {
try{ try{
for (i in 0 until 24) { for (i in 0 until 24) {
if(!js5Archive8.isFileReady(getSpriteId(i))){ if(!js5Archive8.isFileReady(getSpriteId(i))){
return false; return false
} }
} }
val otherIcons = arrayOf(LVL_ICON, MAG_SPRITE, LOOT_ICON, WRENCH_ICON, COMBAT_LVL_SPRITE, BAG_ICON); val otherIcons = arrayOf(LVL_ICON, MAG_SPRITE, LOOT_ICON, WRENCH_ICON, COMBAT_LVL_SPRITE, BAG_ICON)
for (icon in otherIcons) { for (icon in otherIcons) {
if(!js5Archive8.isFileReady(icon)){ if(!js5Archive8.isFileReady(icon)){
return false; return false
} }
} }
} catch (e : Exception){ } catch (e : Exception){
return false; return false
} }
return true; return true
} }
override fun OnLogin() { override fun OnLogin() {
@ -149,9 +151,9 @@ class plugin : Plugin() {
override fun Init() { override fun Init() {
// Disable Font AA // Disable Font AA
System.setProperty("sun.java2d.opengl", "false"); System.setProperty("sun.java2d.opengl", "false")
System.setProperty("awt.useSystemAAFontSettings", "off"); System.setProperty("awt.useSystemAAFontSettings", "off")
System.setProperty("swing.aatext", "false"); System.setProperty("swing.aatext", "false")
} }
private fun UpdateDisplaySettings() { private fun UpdateDisplaySettings() {
@ -465,7 +467,7 @@ class plugin : Plugin() {
} }
private fun createNavButton(spriteId: Int, viewName: String): JPanel { private fun createNavButton(spriteId: Int, viewName: String): JPanel {
val bufferedImageSprite = getBufferedImageFromSprite(GetSprite(spriteId), NAV_TINT, NAV_GREYSCALE) val bufferedImageSprite = getBufferedImageFromSprite(GetSprite(spriteId), NAV_TINT, NAV_GREYSCALE, BOOST)
val buttonSize = Dimension(NAVBAR_WIDTH, 32) val buttonSize = Dimension(NAVBAR_WIDTH, 32)
val imageSize = Dimension((bufferedImageSprite.width / 1.2f).toInt(), (bufferedImageSprite.height / 1.2f).toInt()) val imageSize = Dimension((bufferedImageSprite.width / 1.2f).toInt(), (bufferedImageSprite.height / 1.2f).toInt())
val cooldownDuration = 100L val cooldownDuration = 100L
@ -581,89 +583,6 @@ class plugin : Plugin() {
PROGRESS_BAR_FILL = theme.progressBarFill PROGRESS_BAR_FILL = theme.progressBarFill
NAV_TINT = theme.navTint NAV_TINT = theme.navTint
NAV_GREYSCALE = theme.navGreyScale NAV_GREYSCALE = theme.navGreyScale
BOOST = theme.boost
} }
enum class ThemeType {
RUNELITE,
DARKER_RUNELITE,
SARADOMIN,
ORION,
}
fun getTheme(themeType: ThemeType): Theme {
return when (themeType) {
ThemeType.RUNELITE -> Theme(
widgetColor = Color(30, 30, 30),
titleBarColor = Color(21, 21, 21),
viewBackgroundColor = Color(40, 40, 40),
primaryColor = Color(165, 165, 165),
secondaryColor = Color(255, 255, 255),
popupBackground = Color(45, 45, 45),
popupForeground = Color(220, 220, 220),
tooltipBackground = Color(50, 50, 50),
scrollBarColor = Color(64, 64, 64),
progressBarFill = Color(61, 56, 49),
navTint = null,
navGreyScale = false
)
ThemeType.DARKER_RUNELITE -> Theme(
widgetColor = Color(15, 15, 15), // Darker widget backgrounds
titleBarColor = Color(10, 10, 10), // Even darker title bar
viewBackgroundColor = Color(20, 20, 20), // Very dark background for the view
primaryColor = Color(140, 140, 140), // Darker shade for primary text
secondaryColor = Color(210, 210, 210), // Slightly muted white for secondary text
popupBackground = Color(25, 25, 25), // Very dark popup backgrounds
popupForeground = Color(200, 200, 200), // Slightly muted light gray for popup text
tooltipBackground = Color(30, 30, 30), // Darker tooltips background
scrollBarColor = Color(40, 40, 40), // Darker scroll bar
progressBarFill = Color(45, 40, 35), // Darker progress bar fill
navTint = null, //Color(20, 20, 20, 60), // No specific tint applied
navGreyScale = false // Navigation retains color (if applicable)
)
ThemeType.ORION -> Theme(
widgetColor = Color(50, 50, 50), // Darker gray for widget backgrounds
titleBarColor = Color(35, 35, 35), // Very dark gray for the title bar
viewBackgroundColor = Color(60, 60, 60), // Medium-dark gray for view background
primaryColor = Color(180, 180, 180), // Lighter gray for primary text or highlights
secondaryColor = Color(210, 210, 210), // Light gray for secondary text
popupBackground = Color(45, 45, 45), // Dark gray for popup backgrounds
popupForeground = Color(230, 230, 230), // Light gray for popup text
tooltipBackground = Color(55, 55, 55), // Slightly darker gray for tooltips
scrollBarColor = Color(75, 75, 75), // Dark gray for scroll bars
progressBarFill = Color(100, 100, 100), // Medium gray for progress bar fill
navTint = null,
navGreyScale = true
)
ThemeType.SARADOMIN -> Theme(
widgetColor = Color(75, 60, 45),
titleBarColor = Color(60, 48, 36),
viewBackgroundColor = Color(95, 76, 58),
primaryColor = Color(180, 150, 120),
secondaryColor = Color(230, 210, 190),
popupBackground = Color(70, 56, 42),
popupForeground = Color(220, 200, 180),
tooltipBackground = Color(80, 65, 50),
scrollBarColor = Color(100, 85, 70),
progressBarFill = Color(130, 110, 90),
navTint = null,
navGreyScale = false
)
}
}
data class Theme(
val widgetColor: Color,
val titleBarColor: Color,
val viewBackgroundColor: Color,
val primaryColor: Color,
val secondaryColor: Color,
val popupBackground: Color,
val popupForeground: Color,
val tooltipBackground: Color,
val scrollBarColor: Color,
val progressBarFill: Color,
val navTint: Color?,
val navGreyScale: Boolean
)
} }