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

Dev #761

Merged
merged 18 commits into from
Jan 24, 2025
Merged

Dev #761

Show file tree
Hide file tree
Changes from 14 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
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2101.1.3]

### Added
* Added "Hide Lock Icon" boolean quest property to allow the lock icon to be hidden on a per-quest basis
* Unicode escape sequences (e.g. `\u2022`) are now parsed in translation files
* Note however that a double escape is required, e.g. `\\u2022`
* Added zh_tw translation (thanks @sheiun)
* Added tr_tr translation (thanks @RuyaSavascisi)
* Added uk_ua translation (thanks @GIGABAIT93)

### Changed
* Quests with "Hide Dependency Lines" set to false will now show the dependency line when (and only when) hovered with the mouse pointer
* This is now consistent with the behaviour of "Hide Dependent Lines" and more useful in general, allowing dependency lines to be selectively shown

### Fixed
* Fixed quests in always-invisible chapters being searchable outside edit mode

## [2101.1.2]

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ public void addButtons(Panel panel) {

ClientQuestFile file = ClientQuestFile.INSTANCE;
for (QuestObjectBase objectBase : file.getAllObjects()) {
if (config.predicate.test(objectBase) && (file.canEdit() || (!(objectBase instanceof QuestObject qo) || qo.isVisible(file.selfTeamData)))) {
if (config.predicate.test(objectBase) &&
(file.canEdit() || (!(objectBase instanceof QuestObject qo) || qo.isSearchable(file.selfTeamData)))) {
list.add((T) objectBase);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ public void draw(GuiGraphics graphics, Theme theme, int x, int y, int w, int h)
poseStack.popPose();
}

if (!lockIcon.isEmpty()) {
if (!lockIcon.isEmpty() && !quest.shouldHideLockIcon()) {
int s = (int) (w / 8F * 3F);
poseStack.pushPose();
poseStack.translate(x + w - s, y + h - 1 - s, QuestScreen.Z_LEVEL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public void drawOffsetBackground(GuiGraphics graphics, Theme theme, int x, int y
// pass 1: render connections for all visible quests
float mu = (float) ((mt * ThemeProperties.DEPENDENCY_LINE_UNSELECTED_SPEED.get(questScreen.selectedChapter)) % 1D);
for (Widget widget : widgets) {
if (widget.shouldDraw() && widget instanceof QuestButton qb && !qb.quest.shouldHideDependencyLines()) {
if (widget.shouldDraw() && widget instanceof QuestButton qb && (!qb.quest.shouldHideDependencyLines() || qb.isMouseOver())) {
boolean unavailable = !questScreen.file.selfTeamData.canStartTasks(qb.quest);
boolean complete = !unavailable && questScreen.file.selfTeamData.isCompleted(qb.quest);
Color4I c = complete ?
Expand All @@ -211,7 +211,7 @@ public void drawOffsetBackground(GuiGraphics graphics, Theme theme, int x, int y
float ms = (float) ((mt * ThemeProperties.DEPENDENCY_LINE_SELECTED_SPEED.get(questScreen.selectedChapter)) % 1D);
List<QuestButton> toOutline = new ArrayList<>();
for (Widget widget : widgets) {
if (widget.shouldDraw() && widget instanceof QuestButton qb && !qb.quest.shouldHideDependencyLines()) {
if (widget.shouldDraw() && widget instanceof QuestButton qb && (!qb.quest.shouldHideDependencyLines() || qb.isMouseOver())) {
for (QuestButton button : qb.getDependencies()) {
if (button.shouldDraw()) {
if (button.quest == selectedQuest || button.isMouseOver()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ private void showList(Collection<QuestObject> c, boolean dependencies) {
}

for (QuestObject object : c) {
if (questScreen.file.canEdit() || object.isVisible(questScreen.file.selfTeamData)) {
if (questScreen.file.canEdit() || object.isSearchable(questScreen.file.selfTeamData)) {
MutableComponent title = object.getMutableTitle();
if (object.getQuestChapter() != null && object.getQuestChapter() != quest.getQuestChapter()) {
Component suffix = Component.literal(" [").append(object.getQuestChapter().getTitle()).append("]").withStyle(ChatFormatting.GRAY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,8 @@ public class FTBQuestsCommands {
public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
//noinspection ConstantValue
dispatcher.register(Commands.literal("ftbquests")
// s.getServer() *can* be null here, whatever the IDE thinks!
.requires(s -> s.getServer() != null && s.getServer().isSingleplayer() || hasEditorPermission(s))
.then(Commands.literal("editing_mode")
.requires(FTBQuestsCommands::isSSPOrEditor)
.executes(c -> editingMode(c.getSource(), c.getSource().getPlayerOrException(), null))
.then(Commands.argument("enabled", BoolArgumentType.bool())
.executes(c -> editingMode(c.getSource(), c.getSource().getPlayerOrException(), BoolArgumentType.getBool(c, "enabled")))
Expand All @@ -68,6 +67,7 @@ public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
)
)
.then(Commands.literal("locked")
.requires(FTBQuestsCommands::hasEditorPermission)
.executes(c -> locked(c.getSource(), c.getSource().getPlayerOrException(), null))
.then(Commands.argument("enabled", BoolArgumentType.bool())
.executes(c -> locked(c.getSource(), c.getSource().getPlayerOrException(), BoolArgumentType.getBool(c, "enabled")))
Expand All @@ -77,6 +77,7 @@ public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
)
)
.then(Commands.literal("delete_empty_reward_tables")
.requires(FTBQuestsCommands::hasEditorPermission)
.executes(context -> deleteEmptyRewardTables(context.getSource()))
)
.then(Commands.literal("change_progress")
Expand Down Expand Up @@ -131,13 +132,15 @@ public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
)
)
.then(Commands.literal("generate_chapter_with_all_items_in_game")
.requires(FTBQuestsCommands::hasEditorPermission)
.executes(context -> generateAllItemChapter(context.getSource()))
)
.then(Commands.literal("reload")
.requires(FTBQuestsCommands::hasEditorPermission)
.executes(context -> doReload(context.getSource()))
)
.then(Commands.literal("block_rewards")
.requires(FTBQuestsCommands::hasEditorPermission)
.executes(c -> toggleRewardBlocking(c.getSource(), c.getSource().getPlayerOrException(), null))
.then(Commands.argument("enabled", BoolArgumentType.bool())
.executes(c -> toggleRewardBlocking(c.getSource(), c.getSource().getPlayerOrException(), BoolArgumentType.getBool(c, "enabled")))
Expand All @@ -159,6 +162,12 @@ public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
);
}

private static boolean isSSPOrEditor(CommandSourceStack s) {
// s.getServer() *can* be null here, whatever the IDE thinks!
//noinspection ConstantValue
return s.getServer() != null && s.getServer().isSingleplayer() || hasEditorPermission(s);
}

private static boolean hasEditorPermission(CommandSourceStack stack) {
//noinspection DataFlowIssue
return stack.hasPermission(2)
Expand Down
20 changes: 19 additions & 1 deletion common/src/main/java/dev/ftb/mods/ftbquests/quest/Quest.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public final class Quest extends QuestObject implements Movable {
private int invisibleUntilTasks; // invisible until at least X number of tasks have been completed
private Tristate requireSequentialTasks;
private double iconScale;
private boolean hideLockIcon;

private Component cachedSubtitle = null;
private List<Component> cachedDescription = null;
Expand Down Expand Up @@ -110,6 +111,7 @@ public Quest(long id, Chapter chapter) {
dependantIDs = new HashSet<>();
requireSequentialTasks = Tristate.DEFAULT;
iconScale = 1d;
hideLockIcon = false;
}

@Override
Expand Down Expand Up @@ -304,6 +306,10 @@ public void writeData(CompoundTag nbt, HolderLookup.Provider provider) {

hideDetailsUntilStartable.write(nbt, "hide_details_until_startable");
requireSequentialTasks.write(nbt, "require_sequential_tasks");

if (hideLockIcon) {
nbt.putBoolean("hide_lock_icon", true);
}
}

@Override
Expand Down Expand Up @@ -366,6 +372,7 @@ public void readData(CompoundTag nbt, HolderLookup.Provider provider) {
progressionMode = ProgressionMode.NAME_MAP.get(nbt.getString("progression_mode"));
hideDetailsUntilStartable = Tristate.read(nbt, "hide_details_until_startable");
requireSequentialTasks = Tristate.read(nbt, "require_sequential_tasks");
hideLockIcon = nbt.getBoolean("hide_lock_icon");
}

@Override
Expand All @@ -389,6 +396,7 @@ public void writeNetData(RegistryFriendlyByteBuf buffer) {
flags = Bits.setFlag(flags, 0x8000, requireSequentialTasks != Tristate.DEFAULT);
flags = Bits.setFlag(flags, 0x10000, requireSequentialTasks == Tristate.TRUE);
flags = Bits.setFlag(flags, 0x20000, iconScale != 1f);
flags = Bits.setFlag(flags, 0x40000, hideLockIcon);
buffer.writeVarInt(flags);

hideUntilDepsComplete.write(buffer);
Expand Down Expand Up @@ -470,7 +478,7 @@ public void readNetData(RegistryFriendlyByteBuf buffer) {
invisibleUntilTasks = Bits.getFlag(flags, 0x400) ? buffer.readVarInt() : 0;
hideDetailsUntilStartable = Bits.getFlag(flags, 0x800) ? Bits.getFlag(flags, 0x1000) ? Tristate.TRUE : Tristate.FALSE : Tristate.DEFAULT;
requireSequentialTasks = Bits.getFlag(flags, 0x8000) ? Bits.getFlag(flags, 0x10000) ? Tristate.TRUE : Tristate.FALSE : Tristate.DEFAULT;

hideLockIcon = Bits.getFlag(flags, 0x40000);
progressionMode = ProgressionMode.NAME_MAP.read(buffer);
}

Expand Down Expand Up @@ -654,6 +662,7 @@ public void onClicked(Widget clicked, MouseButton button, ConfigCallback callbac
visibility.addInt("invisible_until_tasks", invisibleUntilTasks, v -> invisibleUntilTasks = v, 0, 0, Integer.MAX_VALUE).setCanEdit(invisible);
visibility.addTristate("hide_details_until_startable", hideDetailsUntilStartable, v -> hideDetailsUntilStartable = v);
visibility.addTristate("hide_text_until_complete", hideTextUntilComplete, v -> hideTextUntilComplete = v);
visibility.addBool("hide_lock_icon", hideLockIcon, v -> hideLockIcon = v, false);

Predicate<QuestObjectBase> depTypes = object -> object != chapter.file && object != chapter && object instanceof QuestObject;// && !(object instanceof Task);
removeInvalidDependencies();
Expand All @@ -678,6 +687,10 @@ public boolean shouldHideDependencyLines() {
return hideDependencyLines.get(chapter.defaultHideDependencyLines);
}

public boolean shouldHideLockIcon() {
return hideLockIcon;
}

@Override
public long getMovableID() {
return id;
Expand Down Expand Up @@ -740,6 +753,11 @@ public boolean isVisible(TeamData data) {
return streamDependencies().anyMatch(object -> object.isVisible(data));
}

@Override
public boolean isSearchable(TeamData data) {
return !chapter.isAlwaysInvisible() && super.isSearchable(data);
}

@Override
public void clearCachedData() {
super.clearCachedData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ public boolean isVisible(TeamData data) {
return true;
}

public boolean isSearchable(TeamData data) {
return isVisible(data);
}

public void onStarted(QuestProgressEventData<?> data) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.StringTag;
import net.minecraft.nbt.Tag;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.codec.ByteBufCodecs;
import net.minecraft.network.codec.StreamCodec;
import org.apache.commons.lang3.StringEscapeUtils;

import java.util.HashMap;
import java.util.List;
Expand All @@ -33,12 +33,14 @@ public TranslationTable() {
this.map = new HashMap<>();
}

// deprecated StringEscapeUtils, but we don't have Apache Commons Text available to us, so whatever...
@SuppressWarnings("deprecation")
public static TranslationTable fromNBT(CompoundTag tag) {
Map<String, Either<String, List<String>>> map = new HashMap<>();
tag.getAllKeys().forEach(k -> {
switch (tag.get(k)) {
case StringTag str -> map.put(k, Either.left(str.getAsString()));
case ListTag list -> map.put(k, Either.right(list.stream().map(Tag::getAsString).toList()));
case StringTag str -> map.put(k, Either.left(StringEscapeUtils.unescapeJava(str.getAsString())));
case ListTag list -> map.put(k, Either.right(list.stream().map(tag1 -> StringEscapeUtils.unescapeJava(tag1.getAsString())).toList()));
case null, default -> { }
}
});
Expand Down
2 changes: 2 additions & 0 deletions common/src/main/resources/assets/ftbquests/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@
"ftbquests.quest.min_required_dependencies.tooltip": "If you set this to anything more than 0, it becomes an OR quest, where only certain amount of dependencies is required for it to unlock",
"ftbquests.quest.visibility.hide_text_until_complete": "Hide Text Until Quest is Completed",
"ftbquests.quest.visibility.hide_text_until_complete.tooltip": "Quest details can be opened, but no description text is displayed until the quest is completed",
"ftbquests.quest.visibility.hide_lock_icon": "Hide Lock Icon",
"ftbquests.quest.visibility.hide_lock_icon.tooltip": "Hide the lock icon that is normally shown when quest is locked due to a dependency",
"ftbquests.quest.misc.disable_jei": "Disable JEI Recipe",
"ftbquests.quest.misc.optional": "Optional Quest",
"ftbquests.quest.locked": "Locked: uncompleted dependencies",
Expand Down
Loading