chatboxperformance: Toggle chatbox gradient (#1396)

* Toggle chatbox gradient

* Toggle chatbox gradient
This commit is contained in:
James
2019-08-19 12:47:39 -07:00
committed by GitHub
parent 904943440f
commit ae08917e77
2 changed files with 87 additions and 6 deletions

View File

@@ -0,0 +1,44 @@
/*
* Copyright (c) 2019, Alexander V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.client.plugins.chatboxperformance;
import net.runelite.client.config.Config;
import net.runelite.client.config.ConfigGroup;
import net.runelite.client.config.ConfigItem;
@ConfigGroup("chatboxperformance")
public interface ChatboxPerformanceConfig extends Config
{
@ConfigItem(
position = 1,
keyName = "Chatbox",
name = "Toggle gradient",
description = "Toggles the gradient inside the chatbox."
)
default boolean transparentChatBox()
{
return true; //default enabled, just like in game.
}
}

View File

@@ -26,9 +26,12 @@ package net.runelite.client.plugins.chatboxperformance;
import javax.inject.Inject;
import javax.inject.Singleton;
import com.google.inject.Provides;
import net.runelite.api.Client;
import net.runelite.api.GameState;
import net.runelite.api.ScriptID;
import net.runelite.api.events.ConfigChanged;
import net.runelite.api.events.ScriptCallbackEvent;
import net.runelite.api.widgets.Widget;
import net.runelite.api.widgets.WidgetInfo;
@@ -36,13 +39,13 @@ import net.runelite.api.widgets.WidgetPositionMode;
import net.runelite.api.widgets.WidgetSizeMode;
import net.runelite.api.widgets.WidgetType;
import net.runelite.client.callback.ClientThread;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.eventbus.EventBus;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor;
@PluginDescriptor(
name = "Chatbox performance",
hidden = true
name = "Chatbox performance"
)
@Singleton
public class ChatboxPerformancePlugin extends Plugin
@@ -56,10 +59,29 @@ public class ChatboxPerformancePlugin extends Plugin
@Inject
private EventBus eventBus;
@Inject
private ChatboxPerformanceConfig config;
private boolean transparentChatBox;
public void onConfigChanged(ConfigChanged event)
{
if (event.getGroup().equals("chatboxperformance"))
{
fixDarkBackground();
}
}
@Provides
ChatboxPerformanceConfig getConfig(ConfigManager configManager)
{
return configManager.getConfig(ChatboxPerformanceConfig.class);
}
@Override
public void startUp()
{
eventBus.subscribe(ScriptCallbackEvent.class, this, this::onScriptCallbackEvent);
addSubscriptions();
if (client.getGameState() == GameState.LOGGED_IN)
{
clientThread.invokeLater(() -> client.runScript(ScriptID.MESSAGE_LAYER_CLOSE, 0, 0));
@@ -76,6 +98,18 @@ public class ChatboxPerformancePlugin extends Plugin
eventBus.unregister(this);
}
private void addSubscriptions()
{
eventBus.subscribe(ConfigChanged.class, this, this::onConfigChanged);
eventBus.subscribe(ScriptCallbackEvent.class, this, this::onScriptCallbackEvent);
}
private void updateConfig()
{
this.transparentChatBox = config.transparentChatBox();
}
private void onScriptCallbackEvent(ScriptCallbackEvent ev)
{
if (!"chatboxBackgroundBuilt".equals(ev.getEventName()))
@@ -90,7 +124,7 @@ public class ChatboxPerformancePlugin extends Plugin
private void fixDarkBackground()
{
int currOpacity = 256;
int currOpacity = 255;
int prevY = 0;
Widget[] children = client.getWidget(WidgetInfo.CHATBOX_TRANSPARENT_BACKGROUND).getDynamicChildren();
Widget prev = null;
@@ -114,7 +148,10 @@ public class ChatboxPerformancePlugin extends Plugin
}
prevY = w.getRelativeY();
currOpacity -= 3; // Rough number, can't get exactly the same as Jagex because of rounding
if (config.transparentChatBox())
{
currOpacity -= 3;
}
prev = w;
}
if (prev != null)
@@ -125,7 +162,7 @@ public class ChatboxPerformancePlugin extends Plugin
private void fixWhiteLines(boolean upperLine)
{
int currOpacity = 256;
int currOpacity = 255;
int prevWidth = 0;
Widget[] children = client.getWidget(WidgetInfo.CHATBOX_TRANSPARENT_LINES).getDynamicChildren();
Widget prev = null;