Skip to content

Commit

Permalink
Merge pull request #761 from FTBTeam/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
desht authored Jan 24, 2025
2 parents a961710 + d7bd2c0 commit 38fd345
Show file tree
Hide file tree
Showing 14 changed files with 1,176 additions and 18 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,24 @@ 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
* Fixed Quest Barrier blocks crashing in SMP environments

## [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
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import dev.ftb.mods.ftbquests.util.TextUtils;
import dev.ftb.mods.ftbteams.api.FTBTeamsAPI;
import dev.ftb.mods.ftbteams.api.Team;
import dev.ftb.mods.ftbteams.api.client.ClientTeamManager;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.longs.Long2IntOpenHashMap;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
Expand Down Expand Up @@ -1111,8 +1112,17 @@ public TeamData getOrCreateTeamData(Entity player) {

@Override
public Optional<TeamData> getTeamData(Player player) {
return FTBTeamsAPI.api().getManager().getTeamForPlayerID(player.getUUID())
.map(this::getOrCreateTeamData);
return player.level().isClientSide ?
getClientTeamData(player) :
FTBTeamsAPI.api().getManager().getTeamForPlayerID(player.getUUID())
.map(this::getOrCreateTeamData);
}

private Optional<TeamData> getClientTeamData(Player player) {
ClientTeamManager mgr = FTBTeamsAPI.api().getClientManager();
return mgr.getKnownPlayer(player.getUUID())
.map(kcp -> mgr.getTeamByID(kcp.teamId()))
.flatMap(team -> team.map(this::getOrCreateTeamData));
}

@Override
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

0 comments on commit 38fd345

Please sign in to comment.