Skip to content

Commit

Permalink
Merge pull request #703 from FTBTeam/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
desht authored Oct 25, 2023
2 parents 6505528 + d952b69 commit a5e8f36
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 38 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [2001.1.7]

### Added
* Added new editor mode hotkeys for copying & pasting selected quest (thanks @adamico)
* Ctrl-C copies the selected quest, if any. Note: currently requires exactly one quest to be selected, copying multiples is not supported at this time.
* Ctrl-V pastes the copied quest
* Ctrl-Shift-V pastes the copied quest without dependencies
* Ctrl-Alt-V pastes the copied quest as a quest link
* Added new editor mode hotkey Delete to delete selected quests
* Shift-Delete can also be used, to delete selected quests with no confirmation - beware

### Fixed
* Fixed "Hide Quest Details Until Startable" and "Hide Quests Until Dependencies Visible" chapter properties getting switched during server -> client sync
* Cleaned up stale kubjes support files (kubejs.classfilter.txt / kubejs.plugins.txt) - they're in FTB XMod Compat now
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public void onClicked(MouseButton button) {
this::bulkChangeSize));
contextMenu.add(new ContextMenuItem(Component.translatable("selectServer.delete"),
ThemeProperties.DELETE_ICON.get(quest),
this::deleteSelectedObjects)
questScreen::deleteSelectedObjects)
.setYesNoText(Component.translatable("delete_item", Component.translatable("ftbquests.quests").append(" [" + questScreen.selectedObjects.size() + "]"))));
}

Expand Down Expand Up @@ -248,20 +248,6 @@ private void openAddRewardContextMenu() {
getGui().openContextMenu(contextMenu2);
}

private void deleteSelectedObjects() {
questScreen.selectedObjects.forEach(movable -> {
if (movable instanceof Quest q) {
questScreen.file.deleteObject(q.id);
} else if (movable instanceof QuestLink ql) {
questScreen.file.deleteObject(ql.id);
} else if (movable instanceof ChapterImage img) {
img.getChapter().removeImage(img);
new EditObjectMessage(img.getChapter()).sendToServer();
}
});
questScreen.selectedObjects.clear();
}

private void editDependency(Quest quest, QuestObject object, boolean add) {
List<QuestObject> prevDeps = quest.streamDependencies().toList();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public class QuestPanel extends Panel {
private static final ImageIcon DEFAULT_DEPENDENCY_LINE_TEXTURE = (ImageIcon) Icon.getIcon(FTBQuestsAPI.MOD_ID + ":textures/gui/dependency.png");

private final QuestScreen questScreen;
private double questX = 0;
private double questY = 0;
protected double questX = 0;
protected double questY = 0;
double centerQuestX = 0;
double centerQuestY = 0;
QuestButton mouseOverQuest = null;
Expand Down Expand Up @@ -591,7 +591,6 @@ public boolean keyPressed(Key key) {
questScreen.addZoom(key.is(GLFW.GLFW_KEY_MINUS) ? -1D : 1D);
return true;
}

return super.keyPressed(key);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@
import dev.ftb.mods.ftbquests.api.FTBQuestsAPI;
import dev.ftb.mods.ftbquests.client.ClientQuestFile;
import dev.ftb.mods.ftbquests.client.FTBQuestsClient;
import dev.ftb.mods.ftbquests.client.gui.CustomToast;
import dev.ftb.mods.ftbquests.client.gui.FTBQuestsTheme;
import dev.ftb.mods.ftbquests.client.gui.SelectQuestObjectScreen;
import dev.ftb.mods.ftbquests.net.ChangeProgressMessage;
import dev.ftb.mods.ftbquests.net.CopyQuestMessage;
import dev.ftb.mods.ftbquests.net.CreateObjectMessage;
import dev.ftb.mods.ftbquests.net.EditObjectMessage;
import dev.ftb.mods.ftbquests.quest.*;
import dev.ftb.mods.ftbquests.quest.reward.RandomReward;
Expand All @@ -31,6 +34,7 @@
import net.minecraft.client.gui.components.toasts.SystemToast;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.renderer.Rect2i;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.util.Mth;
Expand Down Expand Up @@ -175,10 +179,6 @@ public void toggleSelected(Movable movable) {
}
}

public void addObjectMenuItems(List<ContextMenuItem> contextMenu, Runnable gui, QuestObjectBase object) {
addObjectMenuItems(contextMenu, gui, object, object instanceof Movable m ? m : null);
}

/**
* Add any relevant context menu entries for the given quest object
*
Expand All @@ -198,12 +198,10 @@ public void addObjectMenuItems(List<ContextMenuItem> contextMenu, Runnable gui,
);

if (object instanceof QuestLink link) {
link.getQuest().ifPresent(quest -> {
contextMenu.add(new ContextMenuItem(Component.translatable("ftbquests.gui.edit_linked_quest"),
ThemeProperties.EDIT_ICON.get(),
() -> quest.onEditButtonClicked(gui))
);
});
link.getQuest().ifPresent(quest -> contextMenu.add(new ContextMenuItem(Component.translatable("ftbquests.gui.edit_linked_quest"),
ThemeProperties.EDIT_ICON.get(),
() -> quest.onEditButtonClicked(gui))
));
}

if (!subGroup.getValues().isEmpty()) {
Expand Down Expand Up @@ -318,6 +316,67 @@ private boolean moveSelectedQuests(double x, double y) {
return true;
}

private boolean copySelectedQuests() {
Collection<Quest> quests = getSelectedQuests();

if (quests.size() > 1) {
Minecraft.getInstance().getToasts().addToast(new CustomToast(Component.translatable("ftbquests.gui.error"), Icons.BARRIER, Component.translatable("ftbquests.quest.cannot_copy_many")));
return false;
}
for (Quest q : quests) {
setClipboardString(q.getCodeString());
Minecraft.getInstance().getToasts().addToast(new CustomToast(Component.translatable("ftbquests.quest.copied"), Icons.INFO, Component.literal(q.getTitle().getString())));
}

return true;
}

private boolean pasteSelectedQuests(boolean withDeps) {
String clip = getClipboardString();
if (clip.isEmpty()) return false;

Quest quest = file.getQuest(Long.valueOf(clip, 16));
if (quest == null) return false;

double snap = 1D / file.getGridScale();
double qx = Mth.floor(questPanel.questX * snap + 0.5D) / snap;
double qy = Mth.floor(questPanel.questY * snap + 0.5D) / snap;

new CopyQuestMessage(quest, selectedChapter, qx, qy, withDeps).sendToServer();
return true;
}

private boolean pasteSelectedQuestLinks() {
String clip = getClipboardString();
if (clip.isEmpty()) return false;

long questId = Long.valueOf(clip, 16);
if (file.getQuest(Long.valueOf(clip, 16)) == null) return false;

double snap = 1D / file.getGridScale();
double qx = Mth.floor(questPanel.questX * snap + 0.5D) / snap;
double qy = Mth.floor(questPanel.questY * snap + 0.5D) / snap;

QuestLink link = new QuestLink(0L, selectedChapter, questId);
link.setPosition(qx, qy);
new CreateObjectMessage(link, new CompoundTag(), false).sendToServer();
return true;
}

void deleteSelectedObjects() {
selectedObjects.forEach(movable -> {
if (movable instanceof Quest q) {
file.deleteObject(q.id);
} else if (movable instanceof QuestLink ql) {
file.deleteObject(ql.id);
} else if (movable instanceof ChapterImage img) {
img.getChapter().removeImage(img);
new EditObjectMessage(img.getChapter()).sendToServer();
}
});
selectedObjects.clear();
}

@Override
public boolean keyPressed(Key key) {
if (key.esc()) {
Expand Down Expand Up @@ -380,13 +439,28 @@ public boolean keyPressed(Key key) {
return true;
}

if (key.modifiers.control() && selectedChapter != null && file.canEdit()) {
if (!file.canEdit()) {
return false;
}

// all edit-mode keybinds handled below here

if (key.is(GLFW.GLFW_KEY_DELETE) && !selectedObjects.isEmpty()) {
if (!isShiftKeyDown()) {
Component title = Component.translatable("delete_item", Component.translatable("ftbquests.objects", selectedObjects.size()));
getGui().openYesNo(title, Component.empty(), this::deleteSelectedObjects);
} else {
deleteSelectedObjects();
}
} else if (key.modifiers.control()) {
double step = key.modifiers.shift() ? 0.1D : 0.5D;

switch (key.keyCode) {
case GLFW.GLFW_KEY_A -> {
selectedObjects.addAll(selectedChapter.getQuests());
selectedObjects.addAll(selectedChapter.getQuestLinks());
if (selectedChapter != null) {
selectedObjects.addAll(selectedChapter.getQuests());
selectedObjects.addAll(selectedChapter.getQuestLinks());
}
return true;
}
case GLFW.GLFW_KEY_D -> {
Expand All @@ -405,6 +479,16 @@ public boolean keyPressed(Key key) {
case GLFW.GLFW_KEY_RIGHT -> {
return moveSelectedQuests(step, 0D);
}
case GLFW.GLFW_KEY_C -> {
return copySelectedQuests();
}
case GLFW.GLFW_KEY_V -> {
if (key.modifiers.alt()) {
return pasteSelectedQuestLinks();
} else {
return pasteSelectedQuests(!key.modifiers.shift());
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,42 @@
import dev.ftb.mods.ftbquests.quest.QuestObjectType;
import dev.ftb.mods.ftbquests.quest.ServerQuestFile;
import dev.ftb.mods.ftbquests.util.NetUtils;
import net.minecraft.Util;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.TickTask;
import net.minecraft.server.level.ServerPlayer;
import org.jetbrains.annotations.Nullable;

/**
* @author LatvianModder
*/
public class CreateObjectMessage extends BaseC2SMessage {
private final long parent;
private final QuestObjectType type;
private final boolean openScreen;
private final CompoundTag nbt;
private final CompoundTag extra;

CreateObjectMessage(FriendlyByteBuf buffer) {
parent = buffer.readLong();
type = QuestObjectType.NAME_MAP.read(buffer);
openScreen = buffer.readBoolean();
nbt = buffer.readNbt();
extra = buffer.readNbt();
}

public CreateObjectMessage(QuestObjectBase o, @Nullable CompoundTag e) {
public CreateObjectMessage(QuestObjectBase o, @Nullable CompoundTag e, boolean openScreen) {
parent = o.getParentID();
type = o.getObjectType();
this.openScreen = openScreen;
nbt = new CompoundTag();
o.writeData(nbt);
extra = e;
}

public CreateObjectMessage(QuestObjectBase o, @Nullable CompoundTag e) {
this(o, e, true);
}

@Override
public MessageType getType() {
return FTBQuestsNetHandler.CREATE_OBJECT;
Expand All @@ -47,6 +52,7 @@ public MessageType getType() {
public void write(FriendlyByteBuf buffer) {
buffer.writeLong(parent);
QuestObjectType.NAME_MAP.write(buffer, type);
buffer.writeBoolean(openScreen);
buffer.writeNbt(nbt);
buffer.writeNbt(extra);
}
Expand All @@ -61,7 +67,7 @@ public void handle(NetworkManager.PacketContext context) {
object.getQuestFile().clearCachedData();
object.getQuestFile().markDirty();

new CreateObjectResponseMessage(object, extra, sp.getUUID()).sendToAll(sp.getServer());
new CreateObjectResponseMessage(object, extra, openScreen ? sp.getUUID() : Util.NIL_UUID).sendToAll(sp.getServer());
}
}
}
7 changes: 5 additions & 2 deletions common/src/main/resources/assets/ftbquests/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@
"ftbquests.quest": "Quest",
"ftbquests.quests": "Quests",
"ftbquests.quest.completed": "Quest completed!",
"ftbquests.quest.copied": "Copied quest:",
"ftbquests.quest.cannot_copy_many": "Copying many quests is not implemented!",
"ftbquests.quest.appearance": "Appearance",
"ftbquests.quest.dependencies": "Dependencies",
"ftbquests.quest.misc": "Misc",
Expand Down Expand Up @@ -288,7 +290,7 @@
"ftbquests.gui.page_break": "Add Page Break",
"ftbquests.gui.key_reference": "Key Reference",
"ftbquests.gui.key_reference.player": "General Controls\n-;Zoom out\n+;Zoom in\n0;Reset Zoom\nTab;Next Chapter\nShift + Tab;Previous Chapter\n1 - 9;Go to Chapter\nSpace;Recenter View\nCtrl + F;Search\nF1;While hovering quest, show extended info\nLeft Mouse;View Quest Details\nMouse Wheel;Scroll Up/Down\nShift + Mouse Wheel;Scroll Left/Right\nCtrl + Mouse Wheel;Zoom In/Out",
"ftbquests.gui.key_reference.editor": "Editor Mode\nCtrl + Left Mouse;Toggle Selection\nMiddle Mouse;Move Selected Quest(s)\nRight Mouse;Context Menu\nMiddle Mouse: Drag;Select Quests in Drag Box\nCtrl + Middle Mouse: Drag;Toggle Selection in Box\nCtrl + A;Select All\nCtrl + D;Select None\nCtrl + Up/Down/Left/Right;Move Selected Quests\nCtrl + R;Toggle Crosshairs\n\nQuest View Panel\nT;Edit Quest Title\nS;Edit Quest Subtitle\nD;Edit Quest Description",
"ftbquests.gui.key_reference.editor": "Editor Mode\nCtrl + Left Mouse;Toggle Selection\nMiddle Mouse;Move Selected Quest(s)\nRight Mouse;Context Menu\nMiddle Mouse: Drag;Select Quests in Drag Box\nCtrl + Middle Mouse: Drag;Toggle Selection in Box\nCtrl + A;Select All\nCtrl + D;Select None\nCtrl + Up/Down/Left/Right;Move Selected Quests\nCtrl + R;Toggle Crosshairs\nCtrl + C;Copy Selected Quest\nCtrl + V;Paste Quest\nCtrl + Shift + V;Paste Quest (no dependencies)\nCtrl + Alt + V;Paste Quest Link\n\nQuest View Panel\nT;Edit Quest Title\nS;Edit Quest Subtitle\nD;Edit Quest Description",
"ftbquests.task": "Task",
"ftbquests.tasks": "Tasks",
"ftbquests.task.completed": "Task completed!",
Expand Down Expand Up @@ -500,5 +502,6 @@
"commands.ftbquests.export_rewards_to_chest.usage": "/ftbquests export_rewards_to_chest <reward_table>",
"commands.ftbquests.export_rewards_to_chest.text": "Exported %s / %s items from '%s'",
"ftbquests.ui.old_scroll_wheel": "Old-style Scroll Wheel Behavior",
"ftbquests.ui.old_scroll_wheel.tooltip": "When false, scroll wheel scrolls up & down; hold Shift to pan, Ctrl to zoom\nWhen true, scroll wheel only zooms (1.19 and earlier behavior)"
"ftbquests.ui.old_scroll_wheel.tooltip": "When false, scroll wheel scrolls up & down; hold Shift to pan, Ctrl to zoom\nWhen true, scroll wheel only zooms (1.19 and earlier behavior)",
"ftbquests.objects": "%d object(s)"
}

0 comments on commit a5e8f36

Please sign in to comment.