Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow hiding just split dms from screenshots #630

Merged
merged 4 commits into from
Dec 29, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## Unreleased

- Minor: Allow hiding just split private chat from screenshots. (#630)

## 1.10.19

- Bugfix: Use latest dynamic config when queried, rather than the cached value from okhttp. (#625)
Expand Down
17 changes: 13 additions & 4 deletions src/main/java/dinkplugin/DinkPluginConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import dinkplugin.domain.AchievementDiary;
import dinkplugin.domain.ChatNotificationType;
import dinkplugin.domain.ChatPrivacyMode;
import dinkplugin.domain.ClueTier;
import dinkplugin.domain.CombatAchievementTier;
import dinkplugin.domain.ConfigImportPolicy;
Expand Down Expand Up @@ -330,17 +331,25 @@ default PlayerLookupService playerLookupService() {
}

@ConfigItem(
keyName = "screenshotHideChat",
keyName = "chatPrivacy",
name = "Hide Chat in Images",
description = "Whether to hide the chat box and private messages when capturing screenshots.<br/>" +
"Note: visually you may notice the chat box momentarily flicker as it is hidden for the screenshot.",
"Note: visually you may notice the chat box momentarily flicker as it is hidden for the screenshot.<br/>" +
"Warning: 'Hide Split PMs' has no effect if 'Split friends private chat' is not enabled in the game settings",
position = 1010,
section = advancedSection
)
default boolean screenshotHideChat() {
return false;
default ChatPrivacyMode chatPrivacy() {
return ChatPrivacyMode.HIDE_SPLIT_PM;
Felanbird marked this conversation as resolved.
Show resolved Hide resolved
}

@ConfigItem(
keyName = "chatPrivacy",
name = "",
description = ""
)
void setChatPrivacy(ChatPrivacyMode mode);

@ConfigItem(
keyName = "sendDiscordUser",
name = "Send Discord Profile",
Expand Down
16 changes: 10 additions & 6 deletions src/main/java/dinkplugin/SettingsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.common.collect.ImmutableSet;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import dinkplugin.domain.ChatPrivacyMode;
import dinkplugin.domain.ConfigImportPolicy;
import dinkplugin.domain.FilterMode;
import dinkplugin.domain.SeasonalPolicy;
Expand Down Expand Up @@ -57,6 +58,8 @@
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -125,7 +128,9 @@ public boolean isNamePermitted(String name) {

@VisibleForTesting
public void init() {
migrateSeasonal();
migrateBoolean("ignoreSeasonalWorlds", ignoreSeasonal -> ignoreSeasonal ? SeasonalPolicy.REJECT : SeasonalPolicy.ACCEPT, config::setSeasonalPolicy);
migrateBoolean("screenshotHideChat", hide -> hide ? ChatPrivacyMode.HIDE_ALL : ChatPrivacyMode.HIDE_NONE, config::setChatPrivacy);

setFilteredNames(config.filteredNames());
configManager.getConfigDescriptor(config).getItems().forEach(item -> {
String key = item.key();
Expand Down Expand Up @@ -389,11 +394,10 @@ private void setFilteredNames(String configValue) {
log.debug("Updated RSN Filter List to: {}", filteredNames);
}

private void migrateSeasonal() {
String key = "ignoreSeasonalWorlds";
Boolean ignoreSeasonal = configManager.getConfiguration(CONFIG_GROUP, key, Boolean.TYPE);
if (ignoreSeasonal == null) return;
config.setSeasonalPolicy(ignoreSeasonal ? SeasonalPolicy.REJECT : SeasonalPolicy.ACCEPT);
private <T> void migrateBoolean(String key, Function<Boolean, T> transform, Consumer<T> consumer) {
Boolean bool = configManager.getConfiguration(CONFIG_GROUP, key, Boolean.TYPE);
if (bool == null) return;
consumer.accept(transform.apply(bool));
configManager.unsetConfiguration(CONFIG_GROUP, key);
}

Expand Down
17 changes: 17 additions & 0 deletions src/main/java/dinkplugin/domain/ChatPrivacyMode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package dinkplugin.domain;

import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
public enum ChatPrivacyMode {
HIDE_NONE("Show All"),
HIDE_SPLIT_PM("Hide Split PMs"),
HIDE_ALL("Hide All");

private final String displayName;

@Override
public String toString() {
return this.displayName;
}
}
6 changes: 4 additions & 2 deletions src/main/java/dinkplugin/util/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.google.gson.reflect.TypeToken;
import dinkplugin.DinkPluginConfig;
import dinkplugin.domain.AccountType;
import dinkplugin.domain.ChatPrivacyMode;
import lombok.experimental.UtilityClass;
import lombok.extern.slf4j.Slf4j;
import net.runelite.api.Client;
Expand Down Expand Up @@ -311,8 +312,9 @@ public byte[] convertImageToByteArray(BufferedImage bufferedImage, String format
}

public void captureScreenshot(Client client, ClientThread clientThread, DrawManager drawManager, ImageCapture imageCapture, ExecutorService executor, DinkPluginConfig config, Consumer<Image> consumer) {
boolean chatHidden = hideWidget(config.screenshotHideChat(), client, ComponentID.CHATBOX_FRAME);
boolean whispersHidden = hideWidget(config.screenshotHideChat(), client, PRIVATE_CHAT_WIDGET);
ChatPrivacyMode privacyMode = config.chatPrivacy();
boolean chatHidden = hideWidget(privacyMode == ChatPrivacyMode.HIDE_ALL, client, ComponentID.CHATBOX_FRAME);
boolean whispersHidden = hideWidget(privacyMode != ChatPrivacyMode.HIDE_NONE, client, PRIVATE_CHAT_WIDGET);
drawManager.requestNextFrameListener(frame -> {
if (config.includeClientFrame()) {
executor.execute(() -> consumer.accept(imageCapture.addClientFrame(frame)));
Expand Down
Loading