Add option for transparent frame to runeliteplus config

This commit is contained in:
Lucas
2019-05-15 17:06:36 +02:00
parent 853e565ace
commit cc438d340c
3 changed files with 100 additions and 15 deletions

View File

@@ -30,8 +30,6 @@ import net.runelite.client.config.Config;
import net.runelite.client.config.ConfigGroup;
import net.runelite.client.config.ConfigItem;
import java.awt.*;
@ConfigGroup("runeliteplus")
public interface RuneLitePlusConfig extends Config
{
@@ -43,4 +41,26 @@ public interface RuneLitePlusConfig extends Config
)
default boolean customPresence() { return false; }
@ConfigItem(
keyName = "enableOpacity",
name = "Enable opacity",
description = "Enables opacity for the whole window.<br>NOTE: This only stays enabled if your pc supports this!",
position = 1
)
default boolean enableOpacity()
{
return false;
}
@ConfigItem(
keyName = "opacityPercentage",
name = "Opacity percentage",
description = "Changes the opacity of the window if opacity is enabled",
position = 2
)
default int opacityPercentage()
{
return 100;
}
}

View File

@@ -29,27 +29,21 @@ package net.runelite.client.plugins.runeliteplus;
import com.google.inject.Provides;
import lombok.extern.slf4j.Slf4j;
import net.runelite.api.Client;
import net.runelite.api.events.ConfigChanged;
import net.runelite.client.RuneLite;
import net.runelite.client.RuneLiteProperties;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.discord.DiscordPresence;
import net.runelite.client.discord.DiscordService;
import net.runelite.client.eventbus.Subscribe;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.plugins.PluginType;
import net.runelite.client.plugins.discord.DiscordPlugin;
import net.runelite.client.ui.ClientUI;
import net.runelite.client.ui.overlay.OverlayManager;
import javax.inject.Inject;
@PluginDescriptor(
loadWhenOutdated = true, // prevent users from disabling
hidden = true, // prevent users from disabling
loadWhenOutdated = true, // prevent users from disabling
hidden = true, // prevent users from disabling
name = "RuneLitePlus",
description = "Configures various aspects of RuneLitePlus",
type = PluginType.EXTERNAL
@@ -61,17 +55,16 @@ public class RuneLitePlusPlugin extends Plugin
public static boolean customPresenceEnabled = false;
public static String rlPlusDiscordApp = "560644885250572289";
public static String rlDiscordApp = "409416265891971072";
@Inject
public RuneLitePlusConfig config;
@Inject
private OverlayManager overlayManager;
@Inject
private ConfigManager configManager;
@Inject
public DiscordService discordService;
@Inject
private Client client;
@Provides
RuneLitePlusConfig getConfig(ConfigManager configManager)

View File

@@ -35,14 +35,21 @@ import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import static java.awt.GraphicsDevice.WindowTranslucency.TRANSLUCENT;
import java.awt.GraphicsEnvironment;
import java.awt.LayoutManager;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.TrayIcon;
import java.awt.Window;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import javax.annotation.Nullable;
import javax.inject.Inject;
import javax.inject.Provider;
@@ -101,8 +108,11 @@ import org.pushingpixels.substance.internal.utils.SubstanceTitlePaneUtilities;
public class ClientUI
{
private static final String CONFIG_GROUP = "runelite";
private static final String PLUS_CONFIG_GROUP = "runeliteplus";
private static final String CONFIG_CLIENT_BOUNDS = "clientBounds";
private static final String CONFIG_CLIENT_MAXIMIZED = "clientMaximized";
private static final String CONFIG_OPACITY = "enableOpacity";
private static final String CONFIG_OPACITY_AMOUNT = "opacityPercentage";
private static final int CLIENT_WELL_HIDDEN_MARGIN = 160;
private static final int CLIENT_WELL_HIDDEN_MARGIN_TOP = 10;
public static boolean allowInput = false;
@@ -136,6 +146,9 @@ public class ClientUI
private NavigationButton sidebarNavigationButton;
private JButton sidebarNavigationJButton;
private Dimension lastClientSize;
private Field opacityField;
private Field peerField;
private Method setOpacityMethod;
@Inject
private ClientUI(
@@ -159,7 +172,10 @@ public class ClientUI
@Subscribe
public void onConfigChanged(ConfigChanged event)
{
if (!event.getGroup().equals("runelite") ||
if (!event.getGroup().equals(CONFIG_GROUP)
&& !(event.getGroup().equals(PLUS_CONFIG_GROUP)
&& event.getKey().equals(CONFIG_OPACITY) ||
event.getKey().equals(CONFIG_OPACITY_AMOUNT)) ||
event.getKey().equals(CONFIG_CLIENT_MAXIMIZED) ||
event.getKey().equals(CONFIG_CLIENT_BOUNDS))
{
@@ -860,6 +876,26 @@ public class ClientUI
configManager.unsetConfiguration(CONFIG_GROUP, CONFIG_CLIENT_BOUNDS);
}
if (configManager.getConfiguration(PLUS_CONFIG_GROUP, CONFIG_OPACITY, boolean.class))
{
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd = ge.getDefaultScreenDevice();
if (gd.isWindowTranslucencySupported(TRANSLUCENT))
{
setOpacity();
}
else
{
log.warn("Opacity isn't supported on your system!");
configManager.setConfiguration(PLUS_CONFIG_GROUP, CONFIG_OPACITY, false);
}
}
else if (frame.getOpacity() != 1F)
{
frame.setOpacity(1F);
}
if (client == null)
{
return;
@@ -916,4 +952,40 @@ public class ClientUI
configManager.setConfiguration(CONFIG_GROUP, CONFIG_CLIENT_BOUNDS, bounds);
}
}
private void setOpacity()
{
SwingUtilities.invokeLater(() ->
{
try
{
if (opacityField == null)
{
opacityField = Window.class.getDeclaredField("opacity");
opacityField.setAccessible(true);
}
if (peerField == null)
{
peerField = Component.class.getDeclaredField("peer");
peerField.setAccessible(true);
}
if (setOpacityMethod == null)
{
setOpacityMethod = Class.forName("java.awt.peer.WindowPeer").getDeclaredMethod("setOpacity", float.class);
}
final float opacity = Float.parseFloat(configManager.getConfiguration(PLUS_CONFIG_GROUP, CONFIG_OPACITY_AMOUNT)) / 100F;
assert opacity > 0F && opacity <= 1F : "I don't know who you are, I don't know why you tried, and I don't know how you tried, but this is NOT what you're supposed to do and you should honestly feel terrible about what you did, so I want you to take a nice long amount of time to think about what you just tried to do so you are not gonna do this in the future.";
opacityField.setFloat(frame, opacity);
setOpacityMethod.invoke(peerField.get(frame), opacity);
}
catch (NoSuchFieldException | NoSuchMethodException | ClassNotFoundException | IllegalAccessException | InvocationTargetException e)
{
e.printStackTrace();
}
});
}
}