Skip to content

Commit 75ecba4

Browse files
committed
Toggle library mods when clicking their cards
1 parent 4e477d4 commit 75ecba4

2 files changed

Lines changed: 53 additions & 26 deletions

File tree

launcher/src/main/java/net/modtale/launcher/ui/library/LibraryWorldRenderer.java

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -345,17 +345,16 @@ private Node projectRow(HytaleWorld world, LibraryWorldProjectModel model, List<
345345
shell.getChildren().add(contentsCard);
346346
}
347347
ProjectCardInteraction.addHoverAnimationWithIndependentContent(shell, icon);
348-
ProjectSummary target = navigationTarget(model);
349-
if (target != null) {
348+
if (!toggle.isDisabled()) {
350349
shell.setCursor(Cursor.HAND);
351-
shell.setOnMouseClicked(event -> {
352-
if (event.getButton() == MouseButton.PRIMARY && event.isStillSincePress()
353-
&& !isNestedControl(event.getTarget(), shell)) {
354-
openProject.accept(target);
355-
event.consume();
356-
}
357-
});
358350
}
351+
shell.setOnMouseClicked(event -> {
352+
if (event.getButton() == MouseButton.PRIMARY && event.isStillSincePress()
353+
&& !isNestedControl(event.getTarget(), shell)) {
354+
toggle.fire();
355+
event.consume();
356+
}
357+
});
359358
return shell;
360359
}
361360

@@ -364,8 +363,7 @@ static boolean isNestedControl(Object target, Node card) {
364363
while (node != null && node != card) {
365364
if (node instanceof ButtonBase || node instanceof ComboBoxBase<?> || node instanceof LibraryToggleBox
366365
|| node.getStyleClass().contains("author-link")
367-
|| node.getStyleClass().contains("library-world-version-row")
368-
|| node.getStyleClass().contains("library-world-content-card")) {
366+
|| node.getStyleClass().contains("library-world-project-title")) {
369367
return true;
370368
}
371369
node = node.getParent();
@@ -403,6 +401,16 @@ private VBox projectCopy(LibraryWorldProjectModel model) {
403401
copy.setAlignment(Pos.CENTER_LEFT);
404402
Label title = new Label(display.title());
405403
title.getStyleClass().add("library-world-project-title");
404+
ProjectSummary target = navigationTarget(model);
405+
if (target != null) {
406+
title.setCursor(Cursor.HAND);
407+
title.setOnMouseClicked(event -> {
408+
if (event.getButton() == MouseButton.PRIMARY && event.isStillSincePress()) {
409+
openProject.accept(target);
410+
event.consume();
411+
}
412+
});
413+
}
406414

407415
String subtitleText = projectMetaLine(model);
408416
HBox subtitle = new HBox(4);
@@ -585,16 +593,6 @@ private Node contentsCard(LibraryWorldProjectModel model, List<ConfigFile> confi
585593
header.getStyleClass().add("library-world-content-header");
586594
header.setAlignment(Pos.CENTER_LEFT);
587595
header.setPickOnBounds(true);
588-
header.setOnMouseClicked(event -> {
589-
Node target = event.getTarget() instanceof Node node ? node : null;
590-
while (target != null && target != header) {
591-
if (target == toggle) {
592-
return;
593-
}
594-
target = target.getParent();
595-
}
596-
toggleModpackContents.accept(model.installed());
597-
});
598596

599597
VBox card = new VBox(8);
600598
card.getStyleClass().add("library-world-content-card");

launcher/src/test/java/net/modtale/launcher/ui/library/LibraryCardInteractionTest.java

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ void providerRoutesPreserveIdentityAndRejectLocalFiles() {
4646
}
4747

4848
@Test
49-
void cardAndAuthorRouteSeparatelyAndNestedActionsStayInLibrary() throws Exception {
49+
void cardTogglesWhileTitleAuthorAndControlsKeepTheirActions() throws Exception {
5050
FutureTask<Void> task = new FutureTask<>(() -> {
5151
AtomicInteger pages = new AtomicInteger();
5252
AtomicInteger creators = new AtomicInteger();
@@ -96,21 +96,50 @@ void cardAndAuthorRouteSeparatelyAndNestedActionsStayInLibrary() throws Exceptio
9696
toggle.setOnAction(toggles::incrementAndGet);
9797
click(toggle, MouseButton.PRIMARY);
9898
assertEquals(1, toggles.get());
99-
assertEquals(1, pages.get());
99+
assertTrue(toggle.isSelected());
100+
click(card, MouseButton.PRIMARY);
101+
assertEquals(2, toggles.get());
102+
assertFalse(toggle.isSelected());
103+
click(card.lookup(".library-world-project-copy"), MouseButton.PRIMARY);
104+
assertEquals(3, toggles.get());
105+
assertTrue(toggle.isSelected());
106+
click(card, MouseButton.SECONDARY);
107+
assertEquals(3, toggles.get());
108+
click(card.lookup(".library-world-project-title"), MouseButton.PRIMARY);
109+
click(card.lookup(".author-link"), MouseButton.PRIMARY);
110+
for (Node button : card.lookupAll(".library-icon-action")) {
111+
click(button, MouseButton.PRIMARY);
112+
}
113+
assertEquals(3, toggles.get());
114+
assertEquals(2, pages.get());
115+
assertEquals(2, creators.get());
116+
toggle.setDisable(true);
117+
click(card, MouseButton.PRIMARY);
118+
assertEquals(3, toggles.get());
119+
toggle.setDisable(false);
100120
ComboBox<String> combo = new ComboBox<>();
101121
VBox controls = new VBox(combo);
102122
controls.getStyleClass().add("library-world-version-row");
103123
VBox contents = new VBox();
104124
contents.getStyleClass().add("library-world-content-card");
105125
card.getChildren().addAll(controls, contents);
106-
for (Node nested : List.of(combo, controls, contents)) {
126+
click(combo, MouseButton.PRIMARY);
127+
assertEquals(3, toggles.get());
128+
for (Node nested : List.of(controls, contents)) {
107129
click(nested, MouseButton.PRIMARY);
108-
assertEquals(1, pages.get());
130+
assertEquals(2, pages.get());
109131
}
132+
assertEquals(5, toggles.get());
110133
VBox local = (VBox) method.invoke(renderer, null, model("local:file", "LOCAL"), List.of());
111134
assertNull(local.lookup(".author-link"));
112135
click(local.lookup(".library-world-project-title"), MouseButton.PRIMARY);
113-
assertEquals(1, pages.get());
136+
assertEquals(2, pages.get());
137+
var localToggle = (LibraryToggleBox) local.lookup(".library-toggle-box");
138+
localToggle.setDisable(false);
139+
localToggle.setOnAction(toggles::incrementAndGet);
140+
click(local, MouseButton.PRIMARY);
141+
assertTrue(localToggle.isSelected());
142+
assertEquals(6, toggles.get());
114143
return null;
115144
});
116145
Platform.runLater(task);

0 commit comments

Comments
 (0)