Skip to content

Commit

Permalink
Merge pull request #708 from FTBTeam/1.20.1/dev
Browse files Browse the repository at this point in the history
1.20.1/dev
  • Loading branch information
desht authored Dec 1, 2023
2 parents ee0b4c5 + 3169b4f commit 108503d
Show file tree
Hide file tree
Showing 13 changed files with 210 additions and 64 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ 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).

## [2001.2.1]

### Added
* Images can now be multiply-selected and moved in the editor GUI, same as quest and quest link buttons
* Ctrl-A now selects all images in the chapter in addition to quests and quest links

### Fixed
* When a reward is a simple item reward, the reward button tooltip shows proper tooltip data now (e.g. including enchanted book tooltips etc.)
* Fixed flawed implementation of the Task Screen item/fluid/energy handlers on Fabric
* Fixed occasional client-side crash related to the Observation task (possibly triggered by dimension changing) - thanks @RaphaelT7

## [2001.2.0]

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import dev.ftb.mods.ftbquests.api.FTBQuestsAPI;
import dev.ftb.mods.ftbquests.net.EditObjectMessage;
import dev.ftb.mods.ftbquests.quest.ChapterImage;
import dev.ftb.mods.ftbquests.quest.Movable;
import dev.ftb.mods.ftbquests.quest.theme.property.ThemeProperties;
import net.minecraft.ChatFormatting;
import net.minecraft.client.gui.GuiGraphics;
Expand Down Expand Up @@ -158,7 +159,7 @@ public void draw(GuiGraphics graphics, Theme theme, int x, int y, int w, int h)
image = image.withColor(chapterImage.getColor().withAlpha(chapterImage.getAlpha()));
}

GuiHelper.setupDrawing();
// GuiHelper.setupDrawing();
PoseStack poseStack = graphics.pose();
poseStack.pushPose();

Expand All @@ -167,11 +168,19 @@ public void draw(GuiGraphics graphics, Theme theme, int x, int y, int w, int h)
poseStack.mulPose(Axis.ZP.rotationDegrees((float) chapterImage.getRotation()));
poseStack.scale(w, h, 1);
image.draw(graphics, 0, 0, 1, 1);
if (questScreen.selectedObjects.contains(moveAndDeleteFocus())) {
Color4I col = Color4I.WHITE.withAlpha((int) (128D + Math.sin(System.currentTimeMillis() * 0.003D) * 50D));
col.draw(graphics, 0, 0, 1, 1);
}
} else {
poseStack.translate((int) (x + w / 2D), (int) (y + h / 2D), 0);
poseStack.mulPose(Axis.ZP.rotationDegrees((float) chapterImage.getRotation()));
poseStack.scale(w / 2F, h / 2F, 1);
image.draw(graphics, -1, -1, 2, 2);
if (questScreen.selectedObjects.contains(moveAndDeleteFocus())) {
Color4I col = Color4I.WHITE.withAlpha((int) (128D + Math.sin(System.currentTimeMillis() * 0.003D) * 50D));
col.draw(graphics, -1, -1, 2, 2);
}
}

poseStack.popPose();
Expand All @@ -186,4 +195,9 @@ public Position getPosition() {
public int compareTo(@NotNull ChapterImageButton o) {
return Integer.compare(chapterImage.getOrder(), o.chapterImage.getOrder());
}

@Override
public Movable moveAndDeleteFocus() {
return chapterImage;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ public void onClicked(MouseButton button) {

if (chapterPanel.questScreen.selectedChapter != chapter) {
chapterPanel.questScreen.open(chapter, false);
chapter.getAutofocus().ifPresent(chapterPanel.questScreen::scrollTo);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ protected QuestObject theQuestObject() {
* The focus object as a Movable (which will definitely be the case, so the cast is safe)
* @return a Movable; can be used for moving the button, and also deleting the quest object
*/
@Override
public Movable moveAndDeleteFocus() {
return (Movable) theQuestObject();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public void addWidgets() {
return;
}

questScreen.selectedChapter.images()
questScreen.selectedChapter.getImages().stream()
.filter(image -> questScreen.file.canEdit() || image.shouldShowImage(questScreen.file.selfTeamData))
.sorted(Comparator.comparingInt(ChapterImage::getOrder))
.forEach(image -> add(new ChapterImageButton(this, image)));
Expand Down Expand Up @@ -409,7 +409,9 @@ private void drawStatusBar(GuiGraphics graphics, Theme theme, PoseStack poseStac
String cStr = String.format("Center: [%.2f, %.2f]", centerQuestX, centerQuestY);
theme.drawString(graphics, cStr, statusWidth * 2 - theme.getStringWidth(cStr) - 6, 0, Theme.SHADOW);

int total = questScreen.selectedChapter.getQuests().size() + questScreen.selectedChapter.getQuestLinks().size();
int total = questScreen.selectedChapter.getQuests().size()
+ questScreen.selectedChapter.getQuestLinks().size()
+ questScreen.selectedChapter.getImages().size();
String sStr = String.format("Selected: %d / %d", questScreen.selectedObjects.size(), total);
theme.drawString(graphics, sStr, statusWidth / 2, 0, Theme.SHADOW);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package dev.ftb.mods.ftbquests.client.gui.quests;

@FunctionalInterface
import dev.ftb.mods.ftbquests.quest.Movable;

public interface QuestPositionableButton {
Position getPosition();

Movable moveAndDeleteFocus();

record Position(double x, double y, double w, double h) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public boolean onInit() {

@Override
public void onClosed() {
file.setPersistedScreenInfo(new PersistedData(this));
file.setPersistedScreenInfo(getPersistedScreenData());
super.onClosed();
}

Expand All @@ -150,6 +150,10 @@ public void selectChapter(@Nullable Chapter chapter) {
}
}

public void scrollTo(Movable movable) {
questPanel.scrollTo(movable.getX(), movable.getY());
}

public void viewQuest(Quest quest) {
viewQuestPanel.setViewedQuest(quest);
}
Expand Down Expand Up @@ -248,13 +252,29 @@ public void addObjectMenuItems(List<ContextMenuItem> contextMenu, Runnable gui,
new Component[] {
Component.literal(QuestObjectBase.getCodeString(object))
};
if (selectedChapter != null) {
if (selectedChapter.isAutofocus(object.id)) {
contextMenu.add(new ContextMenuItem(Component.translatable("ftbquest.gui.clear_autofocused"),
Icons.MARKER,
() -> setAutofocusedId(0L)));
} else if (object instanceof Quest || object instanceof QuestLink) {
contextMenu.add(new ContextMenuItem(Component.translatable("ftbquest.gui.set_autofocused"),
Icons.MARKER,
() -> setAutofocusedId(object.id)));
}
}
contextMenu.add(new TooltipContextMenuItem(Component.translatable("ftbquests.gui.copy_id"),
ThemeProperties.WIKI_ICON.get(),
() -> setClipboardString(object.getCodeString()),
tooltip)
);
}

private void setAutofocusedId(long id) {
selectedChapter.setAutofocus(id);
new EditObjectMessage(selectedChapter).sendToServer();
}

private List<ContextMenuItem> scanForConfigEntries(List<ContextMenuItem> res, QuestObjectBase object, ConfigGroup g) {
for (ConfigValue<?> value : g.getValues()) {
if (value instanceof ConfigWithVariants) {
Expand Down Expand Up @@ -400,12 +420,14 @@ public boolean keyPressed(Key key) {
return true;
}

List<Chapter> visibleChapters = file.getVisibleChapters(file.selfTeamData);

if (key.is(GLFW.GLFW_KEY_TAB)) {
if (selectedChapter != null && file.getVisibleChapters(file.selfTeamData).size() > 1) {
List<Chapter> visibleChapters = file.getVisibleChapters(file.selfTeamData);

if (!visibleChapters.isEmpty()) {
selectChapter(visibleChapters.get(MathUtils.mod(visibleChapters.indexOf(selectedChapter) + (isShiftKeyDown() ? -1 : 1), visibleChapters.size())));
selectedChapter.getAutofocus().ifPresent(this::scrollTo);
}
}

Expand Down Expand Up @@ -435,8 +457,9 @@ public boolean keyPressed(Key key) {
if (key.keyCode >= GLFW.GLFW_KEY_1 && key.keyCode <= GLFW.GLFW_KEY_9) {
int i = key.keyCode - GLFW.GLFW_KEY_1;

if (i < file.getVisibleChapters(file.selfTeamData).size()) {
selectChapter(file.getVisibleChapters(file.selfTeamData).get(i));
if (i < visibleChapters.size()) {
selectChapter(visibleChapters.get(i));
selectedChapter.getAutofocus().ifPresent(this::scrollTo);
}

return true;
Expand All @@ -463,6 +486,7 @@ public boolean keyPressed(Key key) {
if (selectedChapter != null) {
selectedObjects.addAll(selectedChapter.getQuests());
selectedObjects.addAll(selectedChapter.getQuestLinks());
selectedObjects.addAll(selectedChapter.getImages());
}
return true;
}
Expand Down Expand Up @@ -623,7 +647,7 @@ void selectAllQuestsInBox(int mouseX, int mouseY, double scrollX, double scrollY
if (!Screen.hasControlDown()) selectedObjects.clear();

questPanel.getWidgets().forEach(w -> {
if (w instanceof QuestButton qb && rect.contains((int) (w.getX() - scrollX), (int) (w.getY() - scrollY))) {
if (w instanceof QuestPositionableButton qb && rect.contains((int) (w.getX() - scrollX), (int) (w.getY() - scrollY))) {
toggleSelected(qb.moveAndDeleteFocus());
}
});
Expand Down Expand Up @@ -736,7 +760,7 @@ public Collection<Quest> getSelectedQuests() {
}

public PersistedData getPersistedScreenData() {
return new PersistedData(this);
return pendingPersistedData != null ? pendingPersistedData : new PersistedData(this);
}

private void restorePersistedScreenData(BaseQuestFile file, PersistedData persistedData) {
Expand Down Expand Up @@ -777,7 +801,7 @@ private PersistedData(QuestScreen questScreen) {
scrollX = questScreen.questPanel.centerQuestX;
scrollY = questScreen.questPanel.centerQuestY;
selectedChapter = questScreen.selectedChapter == null ? 0L : questScreen.selectedChapter.id;
selectedQuests = questScreen.selectedObjects.stream().map(Movable::getMovableID).toList();
selectedQuests = questScreen.selectedObjects.stream().map(Movable::getMovableID).filter(id -> id != 0).toList();
chaptersExpanded = questScreen.chapterPanel.expanded;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@
import dev.ftb.mods.ftblibrary.util.TooltipList;
import dev.ftb.mods.ftblibrary.util.client.PositionedIngredient;
import dev.ftb.mods.ftbquests.client.ClientQuestFile;
import dev.ftb.mods.ftbquests.client.FTBQClientProxy;
import dev.ftb.mods.ftbquests.client.FTBQuestsClient;
import dev.ftb.mods.ftbquests.client.gui.ContextMenuBuilder;
import dev.ftb.mods.ftbquests.quest.reward.ItemReward;
import dev.ftb.mods.ftbquests.quest.reward.Reward;
import dev.ftb.mods.ftbquests.quest.theme.property.ThemeProperties;
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.network.chat.Component;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -46,7 +50,13 @@ public void addMouseOverText(TooltipList list) {
questScreen.addInfoTooltip(list, reward);

if (reward.addTitleInMouseOverText()) {
list.add(getTitle());
if (reward instanceof ItemReward itemReward) {
TooltipFlag.Default flag = Minecraft.getInstance().options.advancedItemTooltips ? TooltipFlag.ADVANCED : TooltipFlag.NORMAL;
itemReward.getItem().getTooltipLines(FTBQuestsClient.getClientPlayer(), flag)
.forEach(list::add);
} else {
list.add(getTitle());
}
}

if (reward.isTeamReward() || questScreen.file.selfTeamData.isRewardBlocked(reward)) {
Expand Down
42 changes: 37 additions & 5 deletions common/src/main/java/dev/ftb/mods/ftbquests/quest/Chapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@
import net.minecraft.network.chat.MutableComponent;

import java.util.*;
import java.util.stream.Stream;
import java.util.regex.Pattern;

public final class Chapter extends QuestObject {
private static final Pattern HEX_STRING = Pattern.compile("^([a-fA-F0-9]+)?$");

public final BaseQuestFile file;

private ChapterGroup group;
Expand All @@ -44,6 +46,7 @@ public final class Chapter extends QuestObject {
private boolean defaultRepeatable;
private Tristate consumeItems;
private boolean requireSequentialTasks;
private String autoFocusId;

public Chapter(long id, BaseQuestFile file, ChapterGroup group) {
this(id, file, group, "");
Expand All @@ -69,6 +72,7 @@ public Chapter(long id, BaseQuestFile file, ChapterGroup group, String filename)
defaultRepeatable = false;
consumeItems = Tristate.DEFAULT;
requireSequentialTasks = false;
autoFocusId = "";
}

public void setDefaultQuestShape(String defaultQuestShape) {
Expand Down Expand Up @@ -122,6 +126,10 @@ public List<QuestLink> getQuestLinks() {
return Collections.unmodifiableList(questLinks);
}

public List<ChapterImage> getImages() {
return Collections.unmodifiableList(images);
}

public void addQuest(Quest quest) {
quests.add(quest);
}
Expand Down Expand Up @@ -181,6 +189,8 @@ public void writeData(CompoundTag nbt) {
if (hideQuestUntilDepsVisible) nbt.putBoolean("hide_quest_until_deps_visible", true);
if (defaultRepeatable) nbt.putBoolean("default_repeatable_quest", true);
if (requireSequentialTasks) nbt.putBoolean("require_sequential_tasks", true);

if (!autoFocusId.isEmpty()) nbt.putString("autofocus_id", autoFocusId);
}

@Override
Expand Down Expand Up @@ -225,6 +235,7 @@ public void readData(CompoundTag nbt) {
hideQuestUntilDepsVisible = nbt.getBoolean("hide_quest_until_deps_visible");
defaultRepeatable = nbt.getBoolean("default_repeatable_quest");
requireSequentialTasks = nbt.getBoolean("require_sequential_tasks");
autoFocusId = nbt.getString("autofocus_id");
}

@Override
Expand All @@ -247,7 +258,10 @@ public void writeNetData(FriendlyByteBuf buffer) {
flags = Bits.setFlag(flags, 0x20, consumeItems != Tristate.DEFAULT);
flags = Bits.setFlag(flags, 0x40, consumeItems == Tristate.TRUE);
flags = Bits.setFlag(flags, 0x80, requireSequentialTasks);
flags = Bits.setFlag(flags, 0x100, !autoFocusId.isEmpty());
buffer.writeVarInt(flags);

if (!autoFocusId.isEmpty()) buffer.writeLong(QuestObjectBase.parseHexId(autoFocusId).orElse(0L));
}

@Override
Expand All @@ -273,6 +287,8 @@ public void readNetData(FriendlyByteBuf buffer) {
defaultRepeatable = Bits.getFlag(flags, 0x10);
consumeItems = Bits.getFlag(flags, 0x20) ? Bits.getFlag(flags, 0x40) ? Tristate.TRUE : Tristate.FALSE : Tristate.DEFAULT;
requireSequentialTasks = Bits.getFlag(flags, 0x80);

autoFocusId = Bits.getFlag(flags, 0x100) ? QuestObjectBase.getCodeString(buffer.readLong()) : "";
}

public int getIndex() {
Expand Down Expand Up @@ -427,6 +443,7 @@ public void fillConfigGroup(ConfigGroup config) {
visibility.addBool("hide_quest_until_deps_visible", hideQuestUntilDepsVisible, v -> hideQuestUntilDepsVisible = v, false);

ConfigGroup misc = config.getOrCreateSubgroup("misc").setNameKey("ftbquests.quest.misc");
misc.addString("autofocus_id", autoFocusId, v -> autoFocusId = v, "", HEX_STRING);
misc.addEnum("progression_mode", progressionMode, v -> progressionMode = v, ProgressionMode.NAME_MAP);
misc.addBool("default_repeatable", defaultRepeatable, v -> defaultRepeatable = v, false);
misc.addTristate("consume_items", consumeItems, v -> consumeItems = v);
Expand Down Expand Up @@ -508,10 +525,6 @@ public void removeImage(ChapterImage image) {
images.remove(image);
}

public Stream<ChapterImage> images() {
return images.stream();
}

public void addQuestLink(QuestLink link) {
questLinks.add(link);
}
Expand All @@ -535,4 +548,23 @@ public double getDefaultQuestSize() {
public boolean hasAnyVisibleChildren() {
return !quests.isEmpty() || !questLinks.isEmpty();
}

public Optional<Movable> getAutofocus() {
if (autoFocusId != null && !autoFocusId.isEmpty()) {
return QuestObjectBase.parseHexId(autoFocusId)
.flatMap(id -> file.get(id) instanceof Movable m && m.getChapter() == this ?
Optional.of(m) :
Optional.empty()
);
}
return Optional.empty();
}

public void setAutofocus(long id) {
autoFocusId = id == 0L ? "" : QuestObjectBase.getCodeString(id);
}

public boolean isAutofocus(long id) {
return id == getAutofocus().map(Movable::getMovableID).orElse(0L);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ public boolean observe(Player player, HitResult result) {
BlockInWorld blockInWorld = new BlockInWorld(player.level(), blockResult.getBlockPos(), false);

BlockState state = blockInWorld.getState();
if (state == null) {
return false;
}

Block block = state.getBlock();
BlockEntity blockEntity = blockInWorld.getEntity();

Expand Down
Loading

0 comments on commit 108503d

Please sign in to comment.