mirror of
https://gitlab.com/2009scape/rt4-client.git
synced 2025-12-10 10:20:44 -07:00
Add API methods for controlling audio
Hook up Update() callback Add Audio QOL plugin with mute/unmute hotkey and better settings persistence
This commit is contained in:
parent
7a7be2a54b
commit
ec255eea52
5 changed files with 130 additions and 4 deletions
67
plugin-playground/src/main/kotlin/AudioQOL/plugin.kt
Normal file
67
plugin-playground/src/main/kotlin/AudioQOL/plugin.kt
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
package AudioQOL
|
||||
|
||||
import plugin.Plugin
|
||||
import plugin.annotations.PluginMeta
|
||||
import plugin.api.API
|
||||
import plugin.api.FontColor
|
||||
import plugin.api.FontType
|
||||
import plugin.api.TextModifier
|
||||
import rt4.Keyboard
|
||||
import java.awt.event.KeyAdapter
|
||||
import java.awt.event.KeyEvent
|
||||
|
||||
@PluginMeta(
|
||||
author = "Ceikry",
|
||||
description = "Provides some QOL for audio, including better settings persistence",
|
||||
version = 1.0
|
||||
)
|
||||
class plugin : Plugin() {
|
||||
var isMute = false
|
||||
var lastVolumes: Triple<Int,Int,Int>? = null
|
||||
|
||||
override fun Update() {
|
||||
if (isMute) return
|
||||
API.StoreData("sound-vol", API.GetSoundVolume())
|
||||
API.StoreData("music-vol", API.GetMusicVolume())
|
||||
API.StoreData("amb-vol", API.GetAmbientVolume())
|
||||
}
|
||||
|
||||
override fun Init() {
|
||||
val soundVol = API.GetData("sound-vol") as? Int ?: 255
|
||||
val musicVol = API.GetData("music-vol") as? Int ?: 127
|
||||
val ambVol = API.GetData("amb-vol") as? Int ?: 127
|
||||
API.SetMusicVolume(soundVol)
|
||||
API.SetAmbientVolume(musicVol)
|
||||
API.SetSoundVolume(ambVol)
|
||||
|
||||
API.AddKeyboardListener(object : KeyAdapter() {
|
||||
override fun keyPressed(e: KeyEvent) {
|
||||
if (API.IsKeyPressed(Keyboard.KEY_CTRL) && e.keyCode == KeyEvent.VK_M) {
|
||||
toggleMute()
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun toggleMute() {
|
||||
isMute = !isMute
|
||||
if (isMute) {
|
||||
lastVolumes = Triple(API.GetMusicVolume(), API.GetSoundVolume(), API.GetAmbientVolume())
|
||||
API.SetMusicVolume(0)
|
||||
API.SetSoundVolume(0)
|
||||
API.SetAmbientVolume(0)
|
||||
API.SendMessage("Audio Muted.")
|
||||
if (API.IsMusicPlaying()) {
|
||||
API.PlayMusic(0, -1)
|
||||
}
|
||||
} else {
|
||||
API.SetMusicVolume(lastVolumes?.first ?: 255)
|
||||
API.SetSoundVolume(lastVolumes?.second ?: 127)
|
||||
API.SetAmbientVolume(lastVolumes?.third ?: 127)
|
||||
API.SendMessage("Audio Unmuted.")
|
||||
if ((lastVolumes?.first ?: 255) > 0) {
|
||||
API.RequestNewSong()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue