Skip to content

Commit

Permalink
feat: better selection functionality for images
Browse files Browse the repository at this point in the history
Multiple images can now be selected for moving. Quests/quest links and images can
be selected and moved together.

Ctrl-A now includes images when selecting everything.

FTBTeam/FTB-Mods-Issues#1016
  • Loading branch information
desht committed Nov 29, 2023
1 parent 508ddc1 commit 3353453
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 12 deletions.
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 @@ -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 Down Expand Up @@ -463,6 +463,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 +624,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 +737,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 +778,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 @@ -122,6 +122,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 @@ -508,10 +512,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 Down

0 comments on commit 3353453

Please sign in to comment.