skybox: add custom sky color options

This commit is contained in:
logarithm
2019-11-27 12:02:10 +02:00
parent 0d27667720
commit 37d72fa40a
4 changed files with 227 additions and 3 deletions

View File

@@ -86,6 +86,38 @@ class Skybox
private final int y2;
private final int stride;
private boolean override;
public void setOverrideEnabled(boolean value) { override = value; }
private int overrideTargetColor;
private int overrideReplacementColor;
public void setOverrideColors(int before, int after){
int cr, cg, cb;
byte cco, tmp, ccg, cy;
cr = before >> 16 & 0xFF;
cg = before >> 8 & 0xFF;
cb = before & 0xFF;
// Convert to YCoCg24
cco = (byte) (cb - cr);
tmp = (byte) (cr + (cco >> 1));
ccg = (byte) (tmp - cg);
cy = (byte) (cg + (ccg >> 1));
overrideTargetColor = (cy & 0xFF) << 16 | (cco & 0xFF) << 8 | (ccg & 0xFF);
cr = after >> 16 & 0xFF;
cg = after >> 8 & 0xFF;
cb = after & 0xFF;
// Convert to YCoCg24
cco = (byte) (cb - cr);
tmp = (byte) (cr + (cco >> 1));
ccg = (byte) (tmp - cg);
cy = (byte) (cg + (ccg >> 1));
overrideReplacementColor = (cy & 0xFF) << 16 | (cco & 0xFF) << 8 | (ccg & 0xFF);
}
public Skybox(InputStream is, String filename) throws IOException
{
this(new InputStreamReader(is), filename);
@@ -352,17 +384,46 @@ class Skybox
}
int cv = chunks[(stride * (cy - y1)) + (cx - x1)];
if (cv == -1)
{
return -1;
}
if ((cv & 0x8000_0000) != 0)
{
cv = planeOverrides[(cv & 0x7FFF_FFFF) | plane];
}
return cv;
}
private int chunkDataWithOverride(int cx, int cy, int plane, ChunkMapper chunkMapper){
int cv = chunkData(cx, cy, plane, chunkMapper);
if (override && cv == ((0xFF000000 & cv) | overrideTargetColor))
cv = ((0xFF000000 & cv) | overrideReplacementColor);
return cv;
}
public Color getCentralColorForPoint(int px, int py, int plane, ChunkMapper chunkMapper)
{
int ycocg = chunkData(px / 8, py / 8, plane, chunkMapper);
byte y = (byte) (ycocg >>> 16 & 0xFF);
byte co = (byte) (ycocg >>> 8);
byte cg = (byte) ycocg;
// convert back to rgb from YCoCg24
int g = (y - (cg >> 1)) & 0xFF;
int tmp = (g + cg) & 0xFF;
int r = (tmp - (co >> 1)) & 0xFF;
int b = (r + co) & 0xFF;
return new Color(r, g, b);
}
/**
* Calculates the RGB color for a specific world coordinate. Arguments are floats for sub-tile accuracy.
*
@@ -380,7 +441,7 @@ class Skybox
int cx = (int) x;
int cy = (int) y;
int centerChunkData = chunkData(px / 8, py / 8, plane, chunkMapper);
int centerChunkData = chunkDataWithOverride(px / 8, py / 8, plane, chunkMapper);
if (centerChunkData == -1)
{
// No data in the center chunk?
@@ -401,7 +462,7 @@ class Skybox
{
for (int ucy = ymin; ucy <= ymax; ucy++)
{
int val = chunkData(ucx, ucy, plane, chunkMapper);
int val = chunkDataWithOverride(ucx, ucy, plane, chunkMapper);
if (val == -1)
{
continue;

View File

@@ -25,6 +25,8 @@
package net.runelite.client.plugins.skybox;
import com.google.inject.Inject;
import com.google.inject.Provides;
import java.awt.Color;
import java.io.IOException;
import net.runelite.api.Client;
import net.runelite.api.GameState;
@@ -32,9 +34,12 @@ import net.runelite.api.Player;
import net.runelite.api.coords.LocalPoint;
import net.runelite.api.events.BeforeRender;
import net.runelite.api.events.GameStateChanged;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.eventbus.Subscribe;
import net.runelite.client.events.ConfigChanged;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.plugins.skybox.config.SkyOverrideMode;
@PluginDescriptor(
name = "Skybox",
@@ -47,12 +52,16 @@ public class SkyboxPlugin extends Plugin
@Inject
private Client client;
@Inject
private SkyboxPluginConfig config;
private Skybox skybox;
@Override
public void startUp() throws IOException
{
skybox = new Skybox(SkyboxPlugin.class.getResourceAsStream("skybox.txt"), "skybox.txt");
skybox.setOverrideColors(config.colorToOverride().getRGB(), config.customColor().getRGB());
}
@Override
@@ -62,6 +71,33 @@ public class SkyboxPlugin extends Plugin
skybox = null;
}
@Provides
SkyboxPluginConfig provideConfig(ConfigManager configManager)
{
return configManager.getConfig(SkyboxPluginConfig.class);
}
@Subscribe
public void onConfigChanged(ConfigChanged event)
{
if (config.pickColorToOverride()) {
Player player = client.getLocalPlayer();
if (player != null)
{
Color c = skybox.getCentralColorForPoint(
player.getWorldLocation().getX(),
player.getWorldLocation().getY(),
client.getPlane(),
client.isInInstancedRegion() ? this::mapChunk : null);
config.setColorToOverride(c);
}
config.setOverrideMode(SkyOverrideMode.ONE);
}
skybox.setOverrideColors(config.colorToOverride().getRGB(), config.customColor().getRGB());
skybox.setOverrideEnabled(config.overrideMode() == SkyOverrideMode.ONE);
}
private int mapChunk(int cx, int cy, int plane)
{
cx -= client.getBaseX() / 8;
@@ -111,7 +147,10 @@ public class SkyboxPlugin extends Plugin
int baseX = client.getBaseX();
int baseY = client.getBaseY();
client.setSkyboxColor(skybox.getColorForPoint(
if (config.overrideMode() == SkyOverrideMode.ALL || (config.overrideMode() == SkyOverrideMode.OVERWORLD && baseY < 4200))
client.setSkyboxColor(config.customColor().getRGB());
else
client.setSkyboxColor(skybox.getColorForPoint(
baseX + ((px + spx) / 128.f),
baseY + ((py + spy) / 128.f),
baseX + (px / 128),

View File

@@ -0,0 +1,80 @@
/*
* 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.skybox;
import net.runelite.client.config.Config;
import net.runelite.client.config.ConfigGroup;
import net.runelite.client.config.ConfigItem;
import java.awt.Color;
import net.runelite.client.plugins.skybox.config.SkyOverrideMode;
@ConfigGroup("skybox")
public interface SkyboxPluginConfig extends Config
{
@ConfigItem(
keyName = "customColor",
name = "Custom sky color",
description = "Set a color here to use it with the options below",
position = 1
)
default Color customColor() { return Color.BLACK; }
@ConfigItem(
keyName = "skyOverrideMode",
name = "Mode",
description = "Replace the sky color in regions of a certain target color, the overworld, or everywhere",
position = 2
)
default SkyOverrideMode overrideMode()
{
return SkyOverrideMode.NONE;
}
void setOverrideMode(SkyOverrideMode value);
@ConfigItem(
keyName = "pickColorToOverride",
name = "Set current sky as target",
description = "Sets target color to current chunk's sky color when switched on",
position = 3
)
default boolean pickColorToOverride() { return false; }
@ConfigItem(
keyName = "colorToOverride",
name = "Target color",
description = "Changing this manually is not recommended, but copying the value for tweaking is useful. Note that the value will not update when you enable the picker, until you re-enter the config panel.",
hidden = false,
position = 4
)
default Color colorToOverride() { return Color.BLACK; }
@ConfigItem(
keyName = "colorToOverride",
name = "Target color",
description = "Changing this manually is not recommended, but copying the value for tweaking is useful. Note that the value will not update when you enable the picker, until you re-enter the config panel.",
hidden = false,
position = 4
)
void setColorToOverride(Color value);
}

View File

@@ -0,0 +1,44 @@
/*
* 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.skybox.config;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
@Getter
@RequiredArgsConstructor
public enum SkyOverrideMode
{
NONE("None"),
ONE("Replace target sky color"),
OVERWORLD("Overworld"),
ALL("Everywhere");
private final String name;
@Override
public String toString()
{
return name;
}
}