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: Settings Screen Redesign #2335

Merged
merged 31 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
8e52b22
feat: Settings screen redesign
ShadowCat117 Jan 25, 2024
ded8c5f
feat: Overlay selection screen redesign
ShadowCat117 Feb 8, 2024
ab27cba
feat: Overlay management screen redesign
ShadowCat117 Feb 20, 2024
dfe58e1
feat: Custom names for info boxes & custom bars
ShadowCat117 Feb 20, 2024
f7f931a
refactor: Introduce CustomNamedOverlay
ShadowCat117 Feb 20, 2024
2897d44
feat: Crowd Sourcing screen redesign
ShadowCat117 Feb 23, 2024
49c8e63
feat: Import and export configs
ShadowCat117 Feb 24, 2024
bbf7a0a
refactor: CustomNamedOverlay -> CustomNameProperty
ShadowCat117 Feb 26, 2024
76e25d5
chore: Better copied response
ShadowCat117 Feb 26, 2024
d9a51fa
refactor: Move import/export to ConfigManager, use setValue
ShadowCat117 Feb 26, 2024
3d50dfa
feat: Correctly handle horizontal alignment in renderScrollingText. U…
ShadowCat117 Feb 26, 2024
f119336
ci: spotless formatting
Feb 26, 2024
a931288
chore: Undo change to Config
ShadowCat117 Feb 26, 2024
90815e1
fix: Fix crash when configData is null in import
ShadowCat117 Mar 3, 2024
964b25b
feat: Settings Screen redesign
ShadowCat117 May 21, 2024
1f48a17
ci: spotless formatting
May 21, 2024
684c672
feat: Settings screen redesign
ShadowCat117 Jan 25, 2024
46e5657
Merge branch 'content-book-redesign' of https://github.com/JamieCalla…
ShadowCat117 May 21, 2024
dbb1af3
ci: spotless formatting
May 21, 2024
3c2d8cd
fix: Don't scroll configs up when importing
ShadowCat117 May 21, 2024
c91aa45
chore: Remove redundant calls to populateConfigs
ShadowCat117 May 21, 2024
62bb272
chore: Remove unused textures
ShadowCat117 May 21, 2024
0513d2b
chore: Remove reset textures
ShadowCat117 May 21, 2024
b75acf1
chore: Remove unused i18n
ShadowCat117 May 21, 2024
952e026
fix: Don't scroll to matching configs when already selected configurable
ShadowCat117 May 21, 2024
0257ac6
move everything to new branch
Rafii2198 May 22, 2024
8827994
Optimize new textures
Rafii2198 May 22, 2024
6f8f32a
feat: Separate Search Widget
ShadowCat117 May 23, 2024
e9c5f6c
Final touches
Rafii2198 May 23, 2024
6606e2d
Merge pull request #4 from Rafii2198/textures2
ShadowCat117 May 25, 2024
e2a1bee
Merge branch 'main' into content-book-redesign
kristofbolyai May 28, 2024
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
Original file line number Diff line number Diff line change
@@ -1,32 +1,40 @@
/*
* Copyright © Wynntils 2022-2023.
* Copyright © Wynntils 2022-2024.
* This file is released under LGPLv3. See LICENSE for full license details.
*/
package com.wynntils.core.persisted.config;

import com.wynntils.utils.render.Texture;
import java.util.Locale;
import net.minecraft.client.resources.language.I18n;

public enum Category {
UNCATEGORIZED,
CHAT,
COMBAT,
COMMANDS,
DEBUG,
EMBELLISHMENTS,
INVENTORY,
MAP,
OVERLAYS,
PLAYERS,
REDIRECTS,
TOOLTIPS,
TRADEMARKET,
UI,
UTILITIES,
WYNNTILS;
UNCATEGORIZED(Texture.UNCATEGORIZED_CONFIG_ICON),
CHAT(Texture.CHAT_CONFIG_ICON),
COMBAT(Texture.COMBAT_CONFIG_ICON),
COMMANDS(Texture.COMMANDS_CONFIG_ICON),
DEBUG(Texture.DEBUG_CONFIG_ICON),
EMBELLISHMENTS(Texture.EMBELLISHMENTS_CONFIG_ICON),
INVENTORY(Texture.INVENTORY_CONFIG_ICON),
MAP(Texture.MAP_CONFIG_ICON),
OVERLAYS(Texture.OVERLAYS_CONFIG_ICON),
PLAYERS(Texture.PLAYERS_CONFIG_ICON),
REDIRECTS(Texture.REDIRECTS_CONFIG_ICON),
TOOLTIPS(Texture.TOOLTIPS_CONFIG_ICON),
TRADEMARKET(Texture.TRADE_MARKET_CONFIG_ICON),
UI(Texture.UI_CONFIG_ICON),
UTILITIES(Texture.UTILITIES_CONFIG_ICON),
WYNNTILS(Texture.WYNNTILS_CONFIG_ICON);

Category() {
private final Texture categoryIcon;

Category(Texture categoryIcon) {
assert !toString().startsWith("core.wynntils");
this.categoryIcon = categoryIcon;
}

public Texture getCategoryIcon() {
return categoryIcon;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
*/
package com.wynntils.core.persisted.config;

import com.google.common.reflect.TypeToken;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonSyntaxException;
import com.mojang.util.UndashedUuid;
import com.wynntils.core.WynntilsMod;
import com.wynntils.core.components.Manager;
Expand All @@ -24,8 +26,10 @@
import java.io.File;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.stream.Stream;
Expand Down Expand Up @@ -267,4 +271,66 @@ public Stream<Config<?>> getConfigsForOwner(PersistedOwner owner) {
return getConfigs()
.filter(config -> Managers.Persisted.getMetadata(config).owner() == owner);
}

public boolean importConfig(String jsonInput, List<Configurable> configsToImport) {
try {
Map<String, Object> configData =
Managers.Json.GSON.fromJson(jsonInput, new TypeToken<HashMap<String, Object>>() {}.getType());

if (configData == null) {
WynntilsMod.warn("Unable to import config due to invalid input");
return false;
}

// Loop through all features chosen to import to
for (Configurable feature : configsToImport) {
// Loop through the visible configs only as they are the only configs to be imported
for (Config<?> configOption : feature.getVisibleConfigOptions()) {
String configOptionName = configOption.getJsonName();

// If the config data contains this config option, then it can be imported
if (configData.containsKey(configOptionName)) {
Object configOptionValue = configData.get(configOptionName);
setConfigValue(configOption, configOptionValue);
}
}
}

return true;
} catch (JsonSyntaxException ex) {
kristofbolyai marked this conversation as resolved.
Show resolved Hide resolved
WynntilsMod.warn("Failed to import config ", ex);
return false;
}
}

public String exportConfig(List<Configurable> featuresToExport) {
Map<String, Object> configData = new HashMap<>();

// Loop through all features to be exported
for (Configurable feature : featuresToExport) {
List<Config<?>> visibleConfigOptions = feature.getVisibleConfigOptions();

// Loop through visible config options, as we don't want this to export
// hidden configs since they should be exportable in their
// own features, like favorites and waypoints
for (Config<?> configOption : visibleConfigOptions) {
String configOptionName = configOption.getJsonName();
Object configOptionValue = configOption.get();

// Save the config option to the map
configData.put(configOptionName, configOptionValue);
}
}

// Return the json string of the exported settings
return Managers.Json.GSON.toJson(configData);
}

private <T> void setConfigValue(Config<T> config, Object value) {
T typedValue = config.tryParseStringValue(value.toString());

if (typedValue != null) {
config.setValue(typedValue);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © Wynntils 2022-2023.
* Copyright © Wynntils 2022-2024.
* This file is released under LGPLv3. See LICENSE for full license details.
*/
package com.wynntils.screens.chattabs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,8 @@ public void populateOverlays() {

setSelectedOverlay(newSelected);
}

scrollOverlays(overlayScrollOffset);
}

public void setSelectedOverlay(Overlay selectedOverlay) {
Expand Down Expand Up @@ -604,6 +606,8 @@ private void populateConfigs() {

renderY += 43;
}

scrollConfigs(configScrollOffset);
}

private void togglePreview(boolean enabled) {
Expand Down
Loading
Loading