From 37d72fa40a2fb156b37c899cde250709e73c13c3 Mon Sep 17 00:00:00 2001 From: logarithm Date: Wed, 27 Nov 2019 12:02:10 +0200 Subject: [PATCH 1/6] skybox: add custom sky color options --- .../client/plugins/skybox/Skybox.java | 65 ++++++++++++++- .../client/plugins/skybox/SkyboxPlugin.java | 41 +++++++++- .../plugins/skybox/SkyboxPluginConfig.java | 80 +++++++++++++++++++ .../skybox/config/SkyOverrideMode.java | 44 ++++++++++ 4 files changed, 227 insertions(+), 3 deletions(-) create mode 100644 runelite-client/src/main/java/net/runelite/client/plugins/skybox/SkyboxPluginConfig.java create mode 100644 runelite-client/src/main/java/net/runelite/client/plugins/skybox/config/SkyOverrideMode.java diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/skybox/Skybox.java b/runelite-client/src/main/java/net/runelite/client/plugins/skybox/Skybox.java index aa770f37f8..8ab67de541 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/skybox/Skybox.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/skybox/Skybox.java @@ -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; diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/skybox/SkyboxPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/skybox/SkyboxPlugin.java index 55b1a37017..b282eb7013 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/skybox/SkyboxPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/skybox/SkyboxPlugin.java @@ -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), diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/skybox/SkyboxPluginConfig.java b/runelite-client/src/main/java/net/runelite/client/plugins/skybox/SkyboxPluginConfig.java new file mode 100644 index 0000000000..408abb1acb --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/skybox/SkyboxPluginConfig.java @@ -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); +} diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/skybox/config/SkyOverrideMode.java b/runelite-client/src/main/java/net/runelite/client/plugins/skybox/config/SkyOverrideMode.java new file mode 100644 index 0000000000..c4e9462348 --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/skybox/config/SkyOverrideMode.java @@ -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; + } +} From 650251f5046bfe2a2555fd53c1b63d5c8f9308bb Mon Sep 17 00:00:00 2001 From: logarithm Date: Thu, 28 Nov 2019 16:58:14 +0200 Subject: [PATCH 2/6] skybox: improve target color selection UX --- .../client/plugins/skybox/SkyboxPlugin.java | 1 + .../plugins/skybox/SkyboxPluginConfig.java | 32 +++++++++++++------ 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/skybox/SkyboxPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/skybox/SkyboxPlugin.java index b282eb7013..b56fded87e 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/skybox/SkyboxPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/skybox/SkyboxPlugin.java @@ -92,6 +92,7 @@ public class SkyboxPlugin extends Plugin config.setColorToOverride(c); } config.setOverrideMode(SkyOverrideMode.ONE); + config.setPickColorToOverride(false); } skybox.setOverrideColors(config.colorToOverride().getRGB(), config.customColor().getRGB()); diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/skybox/SkyboxPluginConfig.java b/runelite-client/src/main/java/net/runelite/client/plugins/skybox/SkyboxPluginConfig.java index 408abb1acb..01f6694238 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/skybox/SkyboxPluginConfig.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/skybox/SkyboxPluginConfig.java @@ -38,7 +38,10 @@ public interface SkyboxPluginConfig extends Config description = "Set a color here to use it with the options below", position = 1 ) - default Color customColor() { return Color.BLACK; } + default Color customColor() + { + return Color.BLACK; + } @ConfigItem( keyName = "skyOverrideMode", @@ -50,31 +53,40 @@ public interface SkyboxPluginConfig extends Config { return SkyOverrideMode.NONE; } + @ConfigItem( + keyName = "skyOverrideMode", name = "", description = "" + ) 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", + warning = "Are you sure that you want to set the target color to the current sky color and forget the previous one?", position = 3 ) - default boolean pickColorToOverride() { return false; } + default boolean pickColorToOverride() + { + return false; + } + @ConfigItem( + keyName = "pickColorToOverride", name = "", description = "" + ) + void setPickColorToOverride(boolean value); @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, + hidden = true, position = 4 ) - default Color colorToOverride() { return Color.BLACK; } - + 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 + keyName = "colorToOverride", name = "", description = "" ) void setColorToOverride(Color value); } From b0b328450c203b4267f6df7fdc7a97c0eceee708 Mon Sep 17 00:00:00 2001 From: logarithm Date: Thu, 28 Nov 2019 18:17:10 +0200 Subject: [PATCH 3/6] checkstyle: curly braces --- .../net/runelite/client/plugins/skybox/Skybox.java | 12 +++++++++--- .../runelite/client/plugins/skybox/SkyboxPlugin.java | 3 ++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/skybox/Skybox.java b/runelite-client/src/main/java/net/runelite/client/plugins/skybox/Skybox.java index 8ab67de541..de49782622 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/skybox/Skybox.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/skybox/Skybox.java @@ -87,10 +87,15 @@ class Skybox private final int stride; private boolean override; - public void setOverrideEnabled(boolean value) { override = value; } + public void setOverrideEnabled(boolean value) + { + override = value; + } + private int overrideTargetColor; private int overrideReplacementColor; - public void setOverrideColors(int before, int after){ + public void setOverrideColors(int before, int after) + { int cr, cg, cb; byte cco, tmp, ccg, cy; cr = before >> 16 & 0xFF; @@ -398,7 +403,8 @@ class Skybox return cv; } - private int chunkDataWithOverride(int cx, int cy, int plane, ChunkMapper chunkMapper){ + private int chunkDataWithOverride(int cx, int cy, int plane, ChunkMapper chunkMapper) + { int cv = chunkData(cx, cy, plane, chunkMapper); if (override && cv == ((0xFF000000 & cv) | overrideTargetColor)) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/skybox/SkyboxPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/skybox/SkyboxPlugin.java index b56fded87e..59cf52e0b8 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/skybox/SkyboxPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/skybox/SkyboxPlugin.java @@ -80,7 +80,8 @@ public class SkyboxPlugin extends Plugin @Subscribe public void onConfigChanged(ConfigChanged event) { - if (config.pickColorToOverride()) { + if (config.pickColorToOverride()) + { Player player = client.getLocalPlayer(); if (player != null) { From 233fd5653e40fe071707d3cffd44461be4aeeb99 Mon Sep 17 00:00:00 2001 From: logarithm Date: Thu, 28 Nov 2019 18:24:15 +0200 Subject: [PATCH 4/6] copyright --- .../net/runelite/client/plugins/skybox/SkyboxPluginConfig.java | 3 +++ .../runelite/client/plugins/skybox/config/SkyOverrideMode.java | 3 +++ 2 files changed, 6 insertions(+) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/skybox/SkyboxPluginConfig.java b/runelite-client/src/main/java/net/runelite/client/plugins/skybox/SkyboxPluginConfig.java index 01f6694238..2020536ce9 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/skybox/SkyboxPluginConfig.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/skybox/SkyboxPluginConfig.java @@ -1,4 +1,7 @@ /* + * Copyright (c) 2019 logarrhytmic + * All rights reserved. + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/skybox/config/SkyOverrideMode.java b/runelite-client/src/main/java/net/runelite/client/plugins/skybox/config/SkyOverrideMode.java index c4e9462348..1525f1d4b3 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/skybox/config/SkyOverrideMode.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/skybox/config/SkyOverrideMode.java @@ -1,4 +1,7 @@ /* + * Copyright (c) 2019 logarrhytmic + * All rights reserved. + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * From b20759b1d2c1432e9faeff9a26ff1c026552b611 Mon Sep 17 00:00:00 2001 From: logarithm Date: Mon, 2 Dec 2019 16:07:53 +0200 Subject: [PATCH 5/6] skybox: cut target replacement feature, to be implemented later --- .../client/plugins/skybox/Skybox.java | 68 +------------------ .../client/plugins/skybox/SkyboxPlugin.java | 39 +++-------- .../plugins/skybox/SkyboxPluginConfig.java | 40 +---------- .../skybox/config/SkyOverrideMode.java | 1 - 4 files changed, 15 insertions(+), 133 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/skybox/Skybox.java b/runelite-client/src/main/java/net/runelite/client/plugins/skybox/Skybox.java index de49782622..d589628fc3 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/skybox/Skybox.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/skybox/Skybox.java @@ -86,43 +86,6 @@ 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); @@ -403,33 +366,6 @@ class Skybox 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. * @@ -447,7 +383,7 @@ class Skybox int cx = (int) x; int cy = (int) y; - int centerChunkData = chunkDataWithOverride(px / 8, py / 8, plane, chunkMapper); + int centerChunkData = chunkData(px / 8, py / 8, plane, chunkMapper); if (centerChunkData == -1) { // No data in the center chunk? @@ -468,7 +404,7 @@ class Skybox { for (int ucy = ymin; ucy <= ymax; ucy++) { - int val = chunkDataWithOverride(ucx, ucy, plane, chunkMapper); + int val = chunkData(ucx, ucy, plane, chunkMapper); if (val == -1) { continue; diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/skybox/SkyboxPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/skybox/SkyboxPlugin.java index 59cf52e0b8..7f9854c722 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/skybox/SkyboxPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/skybox/SkyboxPlugin.java @@ -61,7 +61,6 @@ public class SkyboxPlugin extends Plugin public void startUp() throws IOException { skybox = new Skybox(SkyboxPlugin.class.getResourceAsStream("skybox.txt"), "skybox.txt"); - skybox.setOverrideColors(config.colorToOverride().getRGB(), config.customColor().getRGB()); } @Override @@ -77,29 +76,6 @@ public class SkyboxPlugin extends Plugin 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); - config.setPickColorToOverride(false); - } - - 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; @@ -129,6 +105,16 @@ public class SkyboxPlugin extends Plugin return; } + if ( + config.overrideMode() == SkyOverrideMode.ALL || + (config.overrideMode() == SkyOverrideMode.OVERWORLD && client.getLocalPlayer().getWorldLocation().getY() < 4200) + ) + { + client.setSkyboxColor(config.customColor().getRGB()); + return; + } + + int px, py; if (client.getOculusOrbState() == 1) { @@ -149,10 +135,7 @@ public class SkyboxPlugin extends Plugin int baseX = client.getBaseX(); int baseY = client.getBaseY(); - if (config.overrideMode() == SkyOverrideMode.ALL || (config.overrideMode() == SkyOverrideMode.OVERWORLD && baseY < 4200)) - client.setSkyboxColor(config.customColor().getRGB()); - else - client.setSkyboxColor(skybox.getColorForPoint( + client.setSkyboxColor(skybox.getColorForPoint( baseX + ((px + spx) / 128.f), baseY + ((py + spy) / 128.f), baseX + (px / 128), diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/skybox/SkyboxPluginConfig.java b/runelite-client/src/main/java/net/runelite/client/plugins/skybox/SkyboxPluginConfig.java index 2020536ce9..dea3e92341 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/skybox/SkyboxPluginConfig.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/skybox/SkyboxPluginConfig.java @@ -38,7 +38,7 @@ public interface SkyboxPluginConfig extends Config @ConfigItem( keyName = "customColor", name = "Custom sky color", - description = "Set a color here to use it with the options below", + description = "Set a color here to use for the sky", position = 1 ) default Color customColor() @@ -49,47 +49,11 @@ public interface SkyboxPluginConfig extends Config @ConfigItem( keyName = "skyOverrideMode", name = "Mode", - description = "Replace the sky color in regions of a certain target color, the overworld, or everywhere", + description = "Replace the sky color in just the overworld, or everywhere", position = 2 ) default SkyOverrideMode overrideMode() { return SkyOverrideMode.NONE; } - @ConfigItem( - keyName = "skyOverrideMode", name = "", description = "" - ) - 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", - warning = "Are you sure that you want to set the target color to the current sky color and forget the previous one?", - position = 3 - ) - default boolean pickColorToOverride() - { - return false; - } - @ConfigItem( - keyName = "pickColorToOverride", name = "", description = "" - ) - void setPickColorToOverride(boolean value); - - @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 = true, - position = 4 - ) - default Color colorToOverride() - { - return Color.BLACK; - } - @ConfigItem( - keyName = "colorToOverride", name = "", description = "" - ) - void setColorToOverride(Color value); } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/skybox/config/SkyOverrideMode.java b/runelite-client/src/main/java/net/runelite/client/plugins/skybox/config/SkyOverrideMode.java index 1525f1d4b3..b2599bb243 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/skybox/config/SkyOverrideMode.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/skybox/config/SkyOverrideMode.java @@ -33,7 +33,6 @@ import lombok.RequiredArgsConstructor; public enum SkyOverrideMode { NONE("None"), - ONE("Replace target sky color"), OVERWORLD("Overworld"), ALL("Everywhere"); From 8e96c25085514512422dd129bfa3e2026793d70a Mon Sep 17 00:00:00 2001 From: logarithm Date: Mon, 2 Dec 2019 17:18:41 +0200 Subject: [PATCH 6/6] skybox: cleanup --- .../net/runelite/client/plugins/skybox/SkyboxPlugin.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/skybox/SkyboxPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/skybox/SkyboxPlugin.java index 7f9854c722..a246d85a1e 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/skybox/SkyboxPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/skybox/SkyboxPlugin.java @@ -26,7 +26,6 @@ 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; @@ -36,7 +35,6 @@ 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; @@ -105,9 +103,10 @@ public class SkyboxPlugin extends Plugin return; } - if ( + if + ( config.overrideMode() == SkyOverrideMode.ALL || - (config.overrideMode() == SkyOverrideMode.OVERWORLD && client.getLocalPlayer().getWorldLocation().getY() < 4200) + (config.overrideMode() == SkyOverrideMode.OVERWORLD && client.getLocalPlayer().getWorldLocation().getY() < 4200) ) { client.setSkyboxColor(config.customColor().getRGB());