login screen: add custom login screen support
@@ -68,4 +68,24 @@ public interface LoginScreenConfig extends Config
|
||||
description = ""
|
||||
)
|
||||
void username(String key);
|
||||
|
||||
@ConfigItem(
|
||||
keyName = "loginScreen",
|
||||
name = "Custom Background",
|
||||
description = "Force the login screen to use an image from the past instead of the current one."
|
||||
)
|
||||
default LoginScreenOverride loginScreen()
|
||||
{
|
||||
return LoginScreenOverride.OFF;
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
keyName = "showLoginFire",
|
||||
name = "Display Fire",
|
||||
description = "Whether or not the fire in the braziers at the sides of the login screen should be on fire."
|
||||
)
|
||||
default boolean showLoginFire()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (c) 2020, Hydrox6 <ikada@protonmail.ch>
|
||||
* 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.loginscreen;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
public enum LoginScreenOverride
|
||||
{
|
||||
OFF,
|
||||
NORMAL("normal.jpg"),
|
||||
OLD("old.jpg"),
|
||||
CHRISTMAS("christmas.jpg"),
|
||||
CHAMBERS_OF_XERIC("cox.jpg"),
|
||||
DRAGON_SLAYER_2("ds2.jpg"),
|
||||
FOSSIL_ISLAND("fossil_island.jpg"),
|
||||
HALLOWEEN("halloween.jpg"),
|
||||
HALLOWEEN_2019("halloween_2019.jpg"),
|
||||
INFERNO("inferno.jpg"),
|
||||
KEBOS("kebos.jpg"),
|
||||
MONKEY_MADNESS_2("mm2.jpg"),
|
||||
PRIFDDINAS("prifddinas.jpg"),
|
||||
THEATRE_OF_BLOOD("tob.jpg"),
|
||||
CUSTOM;
|
||||
|
||||
@Getter
|
||||
private final String fileName;
|
||||
|
||||
LoginScreenOverride()
|
||||
{
|
||||
this.fileName = null;
|
||||
}
|
||||
|
||||
LoginScreenOverride(String fileName)
|
||||
{
|
||||
this.fileName = fileName;
|
||||
}
|
||||
}
|
||||
@@ -30,12 +30,20 @@ import java.awt.Toolkit;
|
||||
import java.awt.datatransfer.DataFlavor;
|
||||
import java.awt.datatransfer.UnsupportedFlavorException;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.inject.Inject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.Constants;
|
||||
import net.runelite.api.GameState;
|
||||
import net.runelite.api.SpritePixels;
|
||||
import net.runelite.api.events.GameStateChanged;
|
||||
import net.runelite.client.RuneLite;
|
||||
import net.runelite.client.callback.ClientThread;
|
||||
import net.runelite.client.events.ConfigChanged;
|
||||
import net.runelite.client.events.SessionOpen;
|
||||
import net.runelite.client.config.ConfigManager;
|
||||
import net.runelite.client.eventbus.Subscribe;
|
||||
@@ -43,6 +51,7 @@ import net.runelite.client.input.KeyListener;
|
||||
import net.runelite.client.input.KeyManager;
|
||||
import net.runelite.client.plugins.Plugin;
|
||||
import net.runelite.client.plugins.PluginDescriptor;
|
||||
import net.runelite.client.util.ImageUtil;
|
||||
import net.runelite.client.util.OSType;
|
||||
|
||||
@PluginDescriptor(
|
||||
@@ -54,10 +63,14 @@ public class LoginScreenPlugin extends Plugin implements KeyListener
|
||||
{
|
||||
private static final int MAX_USERNAME_LENGTH = 254;
|
||||
private static final int MAX_PIN_LENGTH = 6;
|
||||
private static final File CUSTOM_LOGIN_SCREEN_FILE = new File(RuneLite.RUNELITE_DIR, "login.png");
|
||||
|
||||
@Inject
|
||||
private Client client;
|
||||
|
||||
@Inject
|
||||
private ClientThread clientThread;
|
||||
|
||||
@Inject
|
||||
private LoginScreenConfig config;
|
||||
|
||||
@@ -71,6 +84,7 @@ public class LoginScreenPlugin extends Plugin implements KeyListener
|
||||
{
|
||||
applyUsername();
|
||||
keyManager.registerKeyListener(this);
|
||||
clientThread.invoke(this::overrideLoginScreen);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -82,6 +96,7 @@ public class LoginScreenPlugin extends Plugin implements KeyListener
|
||||
}
|
||||
|
||||
keyManager.unregisterKeyListener(this);
|
||||
clientThread.invoke(this::restoreLoginScreen);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@@ -90,6 +105,15 @@ public class LoginScreenPlugin extends Plugin implements KeyListener
|
||||
return configManager.getConfig(LoginScreenConfig.class);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onConfigChanged(ConfigChanged event)
|
||||
{
|
||||
if (event.getGroup().equals("loginscreen"))
|
||||
{
|
||||
clientThread.invoke(this::overrideLoginScreen);
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onGameStateChanged(GameStateChanged event)
|
||||
{
|
||||
@@ -214,4 +238,74 @@ public class LoginScreenPlugin extends Plugin implements KeyListener
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void overrideLoginScreen()
|
||||
{
|
||||
client.setShouldRenderLoginScreenFire(config.showLoginFire());
|
||||
|
||||
if (config.loginScreen() == LoginScreenOverride.OFF)
|
||||
{
|
||||
restoreLoginScreen();
|
||||
return;
|
||||
}
|
||||
|
||||
SpritePixels pixels = null;
|
||||
if (config.loginScreen() == LoginScreenOverride.CUSTOM)
|
||||
{
|
||||
if (CUSTOM_LOGIN_SCREEN_FILE.exists())
|
||||
{
|
||||
try
|
||||
{
|
||||
BufferedImage image;
|
||||
synchronized (ImageIO.class)
|
||||
{
|
||||
image = ImageIO.read(CUSTOM_LOGIN_SCREEN_FILE);
|
||||
}
|
||||
|
||||
if (image.getHeight() > Constants.GAME_FIXED_HEIGHT)
|
||||
{
|
||||
final double scalar = Constants.GAME_FIXED_HEIGHT / (double) image.getHeight();
|
||||
image = ImageUtil.resizeImage(image, (int) (image.getWidth() * scalar), Constants.GAME_FIXED_HEIGHT);
|
||||
}
|
||||
pixels = ImageUtil.getImageSpritePixels(image, client);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
log.error("error loading custom login screen", e);
|
||||
restoreLoginScreen();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
pixels = getFileSpritePixels(config.loginScreen().getFileName());
|
||||
}
|
||||
|
||||
if (pixels != null)
|
||||
{
|
||||
client.setLoginScreen(pixels);
|
||||
}
|
||||
}
|
||||
|
||||
private void restoreLoginScreen()
|
||||
{
|
||||
client.setLoginScreen(null);
|
||||
}
|
||||
|
||||
private SpritePixels getFileSpritePixels(String file)
|
||||
{
|
||||
try
|
||||
{
|
||||
log.debug("Loading: {}", file);
|
||||
BufferedImage image = ImageUtil.getResourceStreamFromClass(this.getClass(), file);
|
||||
return ImageUtil.getImageSpritePixels(image, client);
|
||||
}
|
||||
catch (RuntimeException ex)
|
||||
{
|
||||
log.debug("Unable to load image: ", ex);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 17 KiB |
|
After Width: | Height: | Size: 102 KiB |
|
After Width: | Height: | Size: 109 KiB |
|
After Width: | Height: | Size: 111 KiB |
|
After Width: | Height: | Size: 98 KiB |
|
After Width: | Height: | Size: 111 KiB |
|
After Width: | Height: | Size: 44 KiB |
|
After Width: | Height: | Size: 97 KiB |
|
After Width: | Height: | Size: 68 KiB |
|
After Width: | Height: | Size: 80 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 60 KiB |
|
After Width: | Height: | Size: 58 KiB |