complete Studio core and JavaFX boundary migration
Intrepid/Prometeu/Studio/pipeline/pr-master Build started...
JaCoCo Coverage #### Project Overview
No changes detected, that affect the code coverage.
* Line Coverage: 64.01% (20482/31999)
* Branch Coverage: 54.22% (8240/15196)
* Lines of Code: 31999
* Cyclomatic Complexity: 13164
#### Quality Gates Summary
Output truncated.
Test / Build skipped: 15, passed: 715
Intrepid/Prometeu/Studio/pipeline/head This commit looks good
Intrepid/Prometeu/Studio/pipeline/pr-master Build started...
JaCoCo Coverage #### Project Overview
No changes detected, that affect the code coverage.
* Line Coverage: 64.01% (20482/31999)
* Branch Coverage: 54.22% (8240/15196)
* Lines of Code: 31999
* Cyclomatic Complexity: 13164
#### Quality Gates Summary
Output truncated.
Test / Build skipped: 15, passed: 715
Intrepid/Prometeu/Studio/pipeline/head This commit looks good
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
package p.studio.ui.javafx;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public final class StudioAppInfo {
|
||||
private static final String VERSION_PROPERTY = "prometeu.studio.version";
|
||||
private static final String FALLBACK_VERSION = "dev";
|
||||
|
||||
private StudioAppInfo() {
|
||||
}
|
||||
|
||||
public static String version() {
|
||||
final String explicit = System.getProperty(VERSION_PROPERTY);
|
||||
if (explicit != null && !explicit.isBlank()) {
|
||||
return explicit.trim();
|
||||
}
|
||||
|
||||
return Optional.ofNullable(StudioAppInfo.class.getPackage().getImplementationVersion())
|
||||
.filter(value -> !value.isBlank())
|
||||
.orElse(FALLBACK_VERSION);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package p.studio.ui.javafx;
|
||||
|
||||
public final class StudioJavaFx {
|
||||
private StudioJavaFx() {
|
||||
}
|
||||
}
|
||||
+253
@@ -0,0 +1,253 @@
|
||||
package p.studio.ui.javafx.controls;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.value.ChangeListener;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.geometry.Orientation;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.control.SplitPane;
|
||||
import javafx.scene.control.TitledPane;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public abstract class WorkspaceDockPane extends TitledPane {
|
||||
private static final double DEFAULT_MAXIMUM_DOCK_SHARE = 0.50;
|
||||
private static final double DEFAULT_FALLBACK_HEIGHT = 520.0;
|
||||
|
||||
private final double collapsedHeight;
|
||||
private final double minimumExpandedHeight;
|
||||
private final double defaultExpandedHeight;
|
||||
private final double maximumDockShare;
|
||||
private final ChangeListener<Number> dividerPositionListener = (ignored, previous, current) -> normalizeDivider();
|
||||
private boolean syncingDivider;
|
||||
private SplitPane dockSplit;
|
||||
private SplitPane.Divider observedDivider;
|
||||
private Double lastExpandedDividerPosition;
|
||||
|
||||
protected WorkspaceDockPane(
|
||||
final ObservableValue<String> titleBinding,
|
||||
final double collapsedHeight,
|
||||
final double minimumExpandedHeight,
|
||||
final double defaultExpandedHeight,
|
||||
final boolean expandedByDefault,
|
||||
final String... styleClasses) {
|
||||
this(titleBinding, collapsedHeight, minimumExpandedHeight, defaultExpandedHeight, DEFAULT_MAXIMUM_DOCK_SHARE, expandedByDefault, styleClasses);
|
||||
}
|
||||
|
||||
protected WorkspaceDockPane(
|
||||
final ObservableValue<String> titleBinding,
|
||||
final double collapsedHeight,
|
||||
final double minimumExpandedHeight,
|
||||
final double defaultExpandedHeight,
|
||||
final double maximumDockShare,
|
||||
final boolean expandedByDefault,
|
||||
final String... styleClasses) {
|
||||
this.collapsedHeight = collapsedHeight;
|
||||
this.minimumExpandedHeight = minimumExpandedHeight;
|
||||
this.defaultExpandedHeight = defaultExpandedHeight;
|
||||
this.maximumDockShare = maximumDockShare;
|
||||
|
||||
textProperty().bind(Objects.requireNonNull(titleBinding, "titleBinding"));
|
||||
getStyleClass().add("workspace-dock-pane");
|
||||
if (styleClasses != null && styleClasses.length > 0) {
|
||||
getStyleClass().addAll(styleClasses);
|
||||
}
|
||||
setCollapsible(true);
|
||||
setExpanded(expandedByDefault);
|
||||
setAnimated(false);
|
||||
setMinHeight(expandedByDefault ? minimumExpandedHeight : collapsedHeight);
|
||||
setPrefHeight(defaultExpandedHeight);
|
||||
setMaxHeight(expandedByDefault ? Double.MAX_VALUE : collapsedHeight);
|
||||
expandedProperty().addListener((ignored, previous, expanded) -> {
|
||||
if (expanded) {
|
||||
expandDock();
|
||||
} else {
|
||||
collapseDock();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public final double collapsedHeight() {
|
||||
return collapsedHeight;
|
||||
}
|
||||
|
||||
public final double minimumExpandedHeight() {
|
||||
return minimumExpandedHeight;
|
||||
}
|
||||
|
||||
public final double defaultExpandedHeight() {
|
||||
return defaultExpandedHeight;
|
||||
}
|
||||
|
||||
public final SplitPane createBottomDockLayout(final Node primaryContent, final String... splitStyleClasses) {
|
||||
final var split = new SplitPane(Objects.requireNonNull(primaryContent, "primaryContent"), this);
|
||||
split.setOrientation(Orientation.VERTICAL);
|
||||
split.getStyleClass().add("workspace-dock-split");
|
||||
if (splitStyleClasses != null && splitStyleClasses.length > 0) {
|
||||
split.getStyleClass().addAll(splitStyleClasses);
|
||||
}
|
||||
SplitPane.setResizableWithParent(primaryContent, true);
|
||||
SplitPane.setResizableWithParent(this, true);
|
||||
dockSplit = split;
|
||||
bindDividerPositionListener();
|
||||
dockSplit.heightProperty().addListener((ignored, previous, current) -> {
|
||||
if (isExpanded()) {
|
||||
normalizeDivider();
|
||||
} else {
|
||||
applyCollapsedDivider();
|
||||
}
|
||||
});
|
||||
dockSplit.getDividers().addListener((javafx.collections.ListChangeListener<? super SplitPane.Divider>) change -> {
|
||||
while (change.next()) {
|
||||
if (change.wasAdded() && !change.getAddedSubList().isEmpty()) {
|
||||
bindDividerPositionListener();
|
||||
}
|
||||
}
|
||||
});
|
||||
if (isExpanded()) {
|
||||
expandDock();
|
||||
} else {
|
||||
collapseDock();
|
||||
}
|
||||
return split;
|
||||
}
|
||||
|
||||
public final DockState captureDockState() {
|
||||
final double preferredExpandedDivider = lastExpandedDividerPosition != null
|
||||
? lastExpandedDividerPosition
|
||||
: currentDivider();
|
||||
return new DockState(isExpanded(), preferredExpandedDivider);
|
||||
}
|
||||
|
||||
public final void restoreDockState(final DockState dockState) {
|
||||
if (dockState == null) {
|
||||
return;
|
||||
}
|
||||
lastExpandedDividerPosition = dockState.dividerPosition();
|
||||
setExpanded(dockState.expanded());
|
||||
if (dockState.expanded()) {
|
||||
setDivider(clampExpandedDivider(dockState.dividerPosition()));
|
||||
} else if (dockSplit != null) {
|
||||
applyCollapsedDivider();
|
||||
}
|
||||
}
|
||||
|
||||
protected final void setDockContent(final Node content) {
|
||||
setContent(Objects.requireNonNull(content, "content"));
|
||||
}
|
||||
|
||||
private void expandDock() {
|
||||
setMinHeight(minimumExpandedHeight);
|
||||
setPrefHeight(defaultExpandedHeight);
|
||||
setMaxHeight(Double.MAX_VALUE);
|
||||
getStyleClass().remove("workspace-dock-pane-collapsed");
|
||||
if (dockSplit != null) {
|
||||
dockSplit.getStyleClass().remove("workspace-dock-split-collapsed");
|
||||
updateDividerInteractivity(false);
|
||||
final double restored = lastExpandedDividerPosition != null ? lastExpandedDividerPosition : defaultDividerPosition();
|
||||
setDivider(clampExpandedDivider(restored));
|
||||
}
|
||||
}
|
||||
|
||||
private void collapseDock() {
|
||||
setMinHeight(collapsedHeight);
|
||||
setPrefHeight(collapsedHeight);
|
||||
setMaxHeight(collapsedHeight);
|
||||
if (!getStyleClass().contains("workspace-dock-pane-collapsed")) {
|
||||
getStyleClass().add("workspace-dock-pane-collapsed");
|
||||
}
|
||||
if (dockSplit != null && !dockSplit.getStyleClass().contains("workspace-dock-split-collapsed")) {
|
||||
dockSplit.getStyleClass().add("workspace-dock-split-collapsed");
|
||||
}
|
||||
if (dockSplit != null) {
|
||||
applyCollapsedDivider();
|
||||
updateDividerInteractivity(true);
|
||||
}
|
||||
}
|
||||
|
||||
private void applyCollapsedDivider() {
|
||||
final double height = currentHeight();
|
||||
final double collapsedPosition = Math.max(0.0, 1.0 - (collapsedHeight / height));
|
||||
setDivider(Math.min(collapsedPosition, 0.985));
|
||||
}
|
||||
|
||||
private void normalizeDivider() {
|
||||
if (syncingDivider || dockSplit == null || dockSplit.getDividers().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
final double clamped = clampExpandedDivider(currentDivider());
|
||||
lastExpandedDividerPosition = clamped;
|
||||
if (Math.abs(clamped - currentDivider()) > 0.0001) {
|
||||
setDivider(clamped);
|
||||
}
|
||||
}
|
||||
|
||||
private double clampExpandedDivider(final double position) {
|
||||
final double minDivider = 1.0 - maximumDockShare;
|
||||
final double maxDivider = Math.max(minDivider, 1.0 - (minimumExpandedHeight / currentHeight()));
|
||||
if (position < minDivider) {
|
||||
return minDivider;
|
||||
}
|
||||
if (position > maxDivider) {
|
||||
return maxDivider;
|
||||
}
|
||||
return position;
|
||||
}
|
||||
|
||||
private double defaultDividerPosition() {
|
||||
final double preferred = 1.0 - (defaultExpandedHeight / currentHeight());
|
||||
return clampExpandedDivider(preferred);
|
||||
}
|
||||
|
||||
private double currentHeight() {
|
||||
if (dockSplit == null || dockSplit.getHeight() <= 0) {
|
||||
return DEFAULT_FALLBACK_HEIGHT;
|
||||
}
|
||||
return dockSplit.getHeight();
|
||||
}
|
||||
|
||||
private double currentDivider() {
|
||||
return dockSplit == null || dockSplit.getDividers().isEmpty() ? defaultDividerPosition() : dockSplit.getDividers().get(0).getPosition();
|
||||
}
|
||||
|
||||
private void setDivider(final double position) {
|
||||
if (dockSplit == null) {
|
||||
return;
|
||||
}
|
||||
syncingDivider = true;
|
||||
try {
|
||||
dockSplit.setDividerPositions(position);
|
||||
} finally {
|
||||
syncingDivider = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void bindDividerPositionListener() {
|
||||
if (dockSplit == null || dockSplit.getDividers().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
final var divider = dockSplit.getDividers().get(0);
|
||||
if (observedDivider == divider) {
|
||||
return;
|
||||
}
|
||||
if (observedDivider != null) {
|
||||
observedDivider.positionProperty().removeListener(dividerPositionListener);
|
||||
}
|
||||
observedDivider = divider;
|
||||
observedDivider.positionProperty().addListener(dividerPositionListener);
|
||||
}
|
||||
|
||||
private void updateDividerInteractivity(final boolean disabled) {
|
||||
if (dockSplit == null) {
|
||||
return;
|
||||
}
|
||||
Platform.runLater(() -> dockSplit.lookupAll(".split-pane-divider").forEach(node -> {
|
||||
node.setMouseTransparent(disabled);
|
||||
node.setVisible(!disabled);
|
||||
node.setManaged(!disabled);
|
||||
}));
|
||||
}
|
||||
|
||||
public record DockState(boolean expanded, double dividerPosition) {
|
||||
}
|
||||
}
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
package p.studio.ui.javafx.controls.banks;
|
||||
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import javafx.scene.layout.Priority;
|
||||
import javafx.scene.layout.Region;
|
||||
import javafx.scene.layout.VBox;
|
||||
|
||||
public final class StudioAssetCapacityMeter extends VBox {
|
||||
private static final String BASE_SEVERITY_CLASS = "studio-asset-capacity-meter-fill-";
|
||||
|
||||
private final AnchorPane track = new AnchorPane();
|
||||
private final Region fill = new Region();
|
||||
private final Label label = new Label();
|
||||
private final Label hint = new Label();
|
||||
|
||||
private double progress;
|
||||
private StudioAssetCapacitySeverity severity = StudioAssetCapacitySeverity.GREEN;
|
||||
|
||||
public StudioAssetCapacityMeter() {
|
||||
setAlignment(Pos.TOP_CENTER);
|
||||
setSpacing(8);
|
||||
getStyleClass().add("studio-asset-capacity-meter");
|
||||
|
||||
track.getStyleClass().add("studio-asset-capacity-meter-track");
|
||||
track.setMinWidth(28);
|
||||
track.setPrefWidth(28);
|
||||
track.setPrefHeight(180);
|
||||
VBox.setVgrow(track, Priority.ALWAYS);
|
||||
|
||||
fill.getStyleClass().addAll("studio-asset-capacity-meter-fill", BASE_SEVERITY_CLASS + severity.name().toLowerCase());
|
||||
AnchorPane.setLeftAnchor(fill, 0.0d);
|
||||
AnchorPane.setRightAnchor(fill, 0.0d);
|
||||
AnchorPane.setBottomAnchor(fill, 0.0d);
|
||||
track.getChildren().add(fill);
|
||||
|
||||
label.getStyleClass().add("studio-asset-capacity-meter-label");
|
||||
hint.getStyleClass().add("studio-asset-capacity-meter-hint");
|
||||
hint.setWrapText(true);
|
||||
|
||||
track.heightProperty().addListener((ignored, oldValue, newValue) -> refreshFillHeight(newValue.doubleValue()));
|
||||
|
||||
getChildren().setAll(track, label, hint);
|
||||
refreshFillHeight(track.getPrefHeight());
|
||||
}
|
||||
|
||||
public void setProgress(double progress) {
|
||||
this.progress = Math.max(0.0d, Math.min(1.0d, progress));
|
||||
refreshFillHeight(track.getHeight() <= 0.0d ? track.getPrefHeight() : track.getHeight());
|
||||
}
|
||||
|
||||
public void setSeverity(StudioAssetCapacitySeverity severity) {
|
||||
this.severity = severity == null ? StudioAssetCapacitySeverity.GREEN : severity;
|
||||
fill.getStyleClass().removeIf(styleClass -> styleClass.startsWith(BASE_SEVERITY_CLASS));
|
||||
fill.getStyleClass().add(BASE_SEVERITY_CLASS + this.severity.name().toLowerCase());
|
||||
}
|
||||
|
||||
public void setLabelText(String text) {
|
||||
label.setText(text == null ? "" : text);
|
||||
}
|
||||
|
||||
public void setHintText(String text) {
|
||||
final String safeText = text == null ? "" : text;
|
||||
hint.setText(safeText);
|
||||
hint.setVisible(!safeText.isBlank());
|
||||
hint.setManaged(!safeText.isBlank());
|
||||
}
|
||||
|
||||
private void refreshFillHeight(double trackHeight) {
|
||||
final double effectiveTrackHeight = Math.min(Math.max(0.0d, trackHeight), track.getPrefHeight());
|
||||
final double fillHeight = effectiveTrackHeight * progress;
|
||||
fill.setMinHeight(fillHeight);
|
||||
fill.setPrefHeight(fillHeight);
|
||||
fill.setMaxHeight(fillHeight);
|
||||
}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package p.studio.ui.javafx.controls.banks;
|
||||
|
||||
public enum StudioAssetCapacitySeverity {
|
||||
GREEN,
|
||||
ORANGE,
|
||||
RED
|
||||
}
|
||||
+294
@@ -0,0 +1,294 @@
|
||||
package p.studio.ui.javafx.controls.banks;
|
||||
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.input.MouseButton;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.ListCell;
|
||||
import javafx.scene.control.ListView;
|
||||
import javafx.scene.control.SelectionMode;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.Priority;
|
||||
import javafx.scene.layout.Region;
|
||||
import javafx.scene.layout.VBox;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.IntConsumer;
|
||||
|
||||
public abstract class StudioDualListView<T> extends HBox {
|
||||
private final ObservableList<T> leftItems = FXCollections.observableArrayList();
|
||||
private final ObservableList<T> rightItems = FXCollections.observableArrayList();
|
||||
private final ListView<T> leftListView = new ListView<>(leftItems);
|
||||
private final ListView<T> rightListView = new ListView<>(rightItems);
|
||||
private final Label leftTitleLabel = new Label("Available");
|
||||
private final Label rightTitleLabel = new Label("Selected");
|
||||
private final Button moveToRightButton = new Button(">");
|
||||
private final Button moveToLeftButton = new Button("<");
|
||||
private final Button moveUpButton = new Button("Up");
|
||||
private final Button moveDownButton = new Button("Down");
|
||||
|
||||
private Consumer<List<T>> onMoveToRight = ignored -> { };
|
||||
private Consumer<List<T>> onMoveToLeft = ignored -> { };
|
||||
private Consumer<T> onLeftSelectionChanged = ignored -> { };
|
||||
private Consumer<T> onRightSelectionChanged = ignored -> { };
|
||||
private Consumer<T> onLeftItemActivated = ignored -> { };
|
||||
private Consumer<T> onRightItemActivated = ignored -> { };
|
||||
private IntConsumer onMoveUp = ignored -> { };
|
||||
private IntConsumer onMoveDown = ignored -> { };
|
||||
private boolean interactionEnabled = true;
|
||||
private boolean moveToRightAllowed = true;
|
||||
|
||||
protected StudioDualListView() {
|
||||
setSpacing(12);
|
||||
setFillHeight(true);
|
||||
setMinHeight(Region.USE_PREF_SIZE);
|
||||
setPrefHeight(Region.USE_COMPUTED_SIZE);
|
||||
setMaxHeight(Double.MAX_VALUE);
|
||||
getStyleClass().add("studio-dual-list-view");
|
||||
|
||||
leftListView.getStyleClass().add("studio-dual-list-left");
|
||||
rightListView.getStyleClass().add("studio-dual-list-right");
|
||||
leftListView.setMaxHeight(Double.MAX_VALUE);
|
||||
rightListView.setMaxHeight(Double.MAX_VALUE);
|
||||
leftListView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
|
||||
rightListView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
|
||||
leftListView.setCellFactory(ignored -> createCell(false));
|
||||
rightListView.setCellFactory(ignored -> createCell(true));
|
||||
|
||||
final VBox leftColumn = createColumn(leftTitleLabel, leftListView);
|
||||
final VBox rightColumn = createColumn(rightTitleLabel, rightListView);
|
||||
final VBox centerActions = new VBox(8, moveToRightButton, moveToLeftButton, moveUpButton, moveDownButton);
|
||||
centerActions.setAlignment(Pos.CENTER);
|
||||
centerActions.setFillWidth(true);
|
||||
centerActions.setMinHeight(Region.USE_PREF_SIZE);
|
||||
centerActions.setMaxHeight(Double.MAX_VALUE);
|
||||
centerActions.getStyleClass().add("studio-dual-list-actions");
|
||||
|
||||
HBox.setHgrow(leftColumn, Priority.ALWAYS);
|
||||
HBox.setHgrow(rightColumn, Priority.ALWAYS);
|
||||
getChildren().setAll(leftColumn, centerActions, rightColumn);
|
||||
|
||||
moveToRightButton.getStyleClass().addAll("studio-button", "studio-button-secondary");
|
||||
moveToLeftButton.getStyleClass().addAll("studio-button", "studio-button-secondary");
|
||||
moveUpButton.getStyleClass().addAll("studio-button", "studio-button-secondary");
|
||||
moveDownButton.getStyleClass().addAll("studio-button", "studio-button-secondary");
|
||||
moveToRightButton.setFocusTraversable(false);
|
||||
moveToLeftButton.setFocusTraversable(false);
|
||||
moveUpButton.setFocusTraversable(false);
|
||||
moveDownButton.setFocusTraversable(false);
|
||||
|
||||
moveToRightButton.setOnAction(ignored -> onMoveToRight.accept(List.copyOf(leftListView.getSelectionModel().getSelectedItems())));
|
||||
moveToLeftButton.setOnAction(ignored -> onMoveToLeft.accept(List.copyOf(rightListView.getSelectionModel().getSelectedItems())));
|
||||
moveUpButton.setOnAction(ignored -> {
|
||||
final int selectedIndex = rightListView.getSelectionModel().getSelectedIndex();
|
||||
if (selectedIndex >= 0) {
|
||||
onMoveUp.accept(selectedIndex);
|
||||
}
|
||||
});
|
||||
moveDownButton.setOnAction(ignored -> {
|
||||
final int selectedIndex = rightListView.getSelectionModel().getSelectedIndex();
|
||||
if (selectedIndex >= 0) {
|
||||
onMoveDown.accept(selectedIndex);
|
||||
}
|
||||
});
|
||||
|
||||
updateActionState();
|
||||
leftListView.getSelectionModel().getSelectedItems().addListener((javafx.collections.ListChangeListener<? super T>) ignored -> updateActionState());
|
||||
rightListView.getSelectionModel().getSelectedItems().addListener((javafx.collections.ListChangeListener<? super T>) ignored -> updateActionState());
|
||||
leftListView.getSelectionModel().selectedItemProperty().addListener((ignored, oldValue, newValue) -> onLeftSelectionChanged.accept(newValue));
|
||||
rightListView.getSelectionModel().selectedItemProperty().addListener((ignored, oldValue, newValue) -> onRightSelectionChanged.accept(newValue));
|
||||
}
|
||||
|
||||
public void setLeftItems(List<T> items) {
|
||||
final List<T> previouslySelected = List.copyOf(leftListView.getSelectionModel().getSelectedItems());
|
||||
leftItems.setAll(Objects.requireNonNull(items, "items"));
|
||||
restoreSelection(leftListView, leftItems, previouslySelected);
|
||||
leftListView.refresh();
|
||||
updateActionState();
|
||||
}
|
||||
|
||||
public void setRightItems(List<T> items) {
|
||||
final List<T> previouslySelected = List.copyOf(rightListView.getSelectionModel().getSelectedItems());
|
||||
rightItems.setAll(Objects.requireNonNull(items, "items"));
|
||||
restoreSelection(rightListView, rightItems, previouslySelected);
|
||||
rightListView.refresh();
|
||||
updateActionState();
|
||||
}
|
||||
|
||||
public void setInteractionEnabled(boolean enabled) {
|
||||
interactionEnabled = enabled;
|
||||
leftListView.setDisable(!enabled);
|
||||
rightListView.setDisable(!enabled);
|
||||
updateActionState();
|
||||
}
|
||||
|
||||
public void setMoveToRightAllowed(boolean allowed) {
|
||||
moveToRightAllowed = allowed;
|
||||
updateActionState();
|
||||
}
|
||||
|
||||
public void setOnMoveToRight(Consumer<List<T>> onMoveToRight) {
|
||||
this.onMoveToRight = Objects.requireNonNull(onMoveToRight, "onMoveToRight");
|
||||
}
|
||||
|
||||
public void setOnMoveToLeft(Consumer<List<T>> onMoveToLeft) {
|
||||
this.onMoveToLeft = Objects.requireNonNull(onMoveToLeft, "onMoveToLeft");
|
||||
}
|
||||
|
||||
public void setOnLeftSelectionChanged(Consumer<T> onLeftSelectionChanged) {
|
||||
this.onLeftSelectionChanged = Objects.requireNonNull(onLeftSelectionChanged, "onLeftSelectionChanged");
|
||||
}
|
||||
|
||||
public void setOnRightSelectionChanged(Consumer<T> onRightSelectionChanged) {
|
||||
this.onRightSelectionChanged = Objects.requireNonNull(onRightSelectionChanged, "onRightSelectionChanged");
|
||||
}
|
||||
|
||||
public void setOnLeftItemActivated(Consumer<T> onLeftItemActivated) {
|
||||
this.onLeftItemActivated = Objects.requireNonNull(onLeftItemActivated, "onLeftItemActivated");
|
||||
}
|
||||
|
||||
public void setOnRightItemActivated(Consumer<T> onRightItemActivated) {
|
||||
this.onRightItemActivated = Objects.requireNonNull(onRightItemActivated, "onRightItemActivated");
|
||||
}
|
||||
|
||||
public void setOnMoveUp(IntConsumer onMoveUp) {
|
||||
this.onMoveUp = Objects.requireNonNull(onMoveUp, "onMoveUp");
|
||||
}
|
||||
|
||||
public void setOnMoveDown(IntConsumer onMoveDown) {
|
||||
this.onMoveDown = Objects.requireNonNull(onMoveDown, "onMoveDown");
|
||||
}
|
||||
|
||||
public void setLeftTitle(String title) {
|
||||
leftTitleLabel.setText(Objects.requireNonNull(title, "title"));
|
||||
}
|
||||
|
||||
public void setRightTitle(String title) {
|
||||
rightTitleLabel.setText(Objects.requireNonNull(title, "title"));
|
||||
}
|
||||
|
||||
public void selectLeftItem(T item) {
|
||||
selectItem(leftListView, leftItems, item);
|
||||
}
|
||||
|
||||
public void selectRightItem(T item) {
|
||||
selectItem(rightListView, rightItems, item);
|
||||
}
|
||||
|
||||
protected abstract String itemText(T item);
|
||||
|
||||
protected Node itemGraphic(T item) {
|
||||
return null;
|
||||
}
|
||||
|
||||
private VBox createColumn(Label titleLabel, ListView<T> listView) {
|
||||
titleLabel.getStyleClass().add("studio-dual-list-title");
|
||||
final VBox column = new VBox(8, titleLabel, listView);
|
||||
column.getStyleClass().add("studio-dual-list-column");
|
||||
column.setFillWidth(true);
|
||||
column.setMinHeight(Region.USE_PREF_SIZE);
|
||||
column.setMaxHeight(Double.MAX_VALUE);
|
||||
VBox.setVgrow(listView, Priority.ALWAYS);
|
||||
return column;
|
||||
}
|
||||
|
||||
private ListCell<T> createCell(boolean indexed) {
|
||||
return new ListCell<>() {
|
||||
{
|
||||
setOnMouseClicked(event -> {
|
||||
if (event.getButton() != MouseButton.PRIMARY || event.getClickCount() != 2 || getItem() == null) {
|
||||
return;
|
||||
}
|
||||
if (indexed) {
|
||||
onRightItemActivated.accept(getItem());
|
||||
} else {
|
||||
onLeftItemActivated.accept(getItem());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateItem(T item, boolean empty) {
|
||||
super.updateItem(item, empty);
|
||||
if (empty || item == null) {
|
||||
setText(null);
|
||||
setGraphic(null);
|
||||
return;
|
||||
}
|
||||
final Node graphic = itemGraphic(item);
|
||||
if (graphic != null) {
|
||||
setText(null);
|
||||
setGraphic(indexed ? createIndexedGraphic(graphic, getIndex()) : graphic);
|
||||
return;
|
||||
}
|
||||
final String text = indexed
|
||||
? getIndex() + ". " + itemText(item)
|
||||
: itemText(item);
|
||||
setText(text);
|
||||
setGraphic(null);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void updateActionState() {
|
||||
final boolean leftSelected = !leftListView.getSelectionModel().isEmpty();
|
||||
final int rightSelectedIndex = rightListView.getSelectionModel().getSelectedIndex();
|
||||
final boolean singleRightSelection = rightListView.getSelectionModel().getSelectedIndices().size() == 1;
|
||||
moveToRightButton.setDisable(!interactionEnabled || !moveToRightAllowed || !leftSelected || leftListView.isDisabled());
|
||||
moveToLeftButton.setDisable(!interactionEnabled || rightSelectedIndex < 0 || rightListView.isDisabled());
|
||||
moveUpButton.setDisable(!interactionEnabled || rightSelectedIndex <= 0 || rightListView.isDisabled() || !singleRightSelection);
|
||||
moveDownButton.setDisable(
|
||||
!interactionEnabled
|
||||
||
|
||||
rightSelectedIndex < 0
|
||||
|| rightSelectedIndex >= rightItems.size() - 1
|
||||
|| rightListView.isDisabled()
|
||||
|| !singleRightSelection);
|
||||
}
|
||||
|
||||
private void restoreSelection(ListView<T> listView, List<T> items, List<T> previouslySelected) {
|
||||
final var selectionModel = listView.getSelectionModel();
|
||||
selectionModel.clearSelection();
|
||||
for (T selectedItem : previouslySelected) {
|
||||
final int index = items.indexOf(selectedItem);
|
||||
if (index >= 0) {
|
||||
selectionModel.select(index);
|
||||
}
|
||||
}
|
||||
final int focusedIndex = selectionModel.getSelectedIndex();
|
||||
if (focusedIndex >= 0) {
|
||||
listView.scrollTo(focusedIndex);
|
||||
}
|
||||
}
|
||||
|
||||
private void selectItem(ListView<T> listView, List<T> items, T item) {
|
||||
final var selectionModel = listView.getSelectionModel();
|
||||
if (item == null) {
|
||||
selectionModel.clearSelection();
|
||||
return;
|
||||
}
|
||||
final int index = items.indexOf(item);
|
||||
if (index < 0) {
|
||||
selectionModel.clearSelection();
|
||||
return;
|
||||
}
|
||||
selectionModel.clearSelection();
|
||||
selectionModel.select(index);
|
||||
listView.scrollTo(index);
|
||||
}
|
||||
|
||||
private Node createIndexedGraphic(Node graphic, int index) {
|
||||
final Label chip = new Label(index + ".");
|
||||
chip.getStyleClass().add("studio-dual-list-index-chip");
|
||||
final HBox wrapper = new HBox(8, chip, graphic);
|
||||
wrapper.getStyleClass().add("studio-dual-list-indexed-cell");
|
||||
wrapper.setAlignment(Pos.CENTER_LEFT);
|
||||
HBox.setHgrow(graphic, Priority.ALWAYS);
|
||||
return wrapper;
|
||||
}
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
package p.studio.ui.javafx.controls.forms;
|
||||
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.layout.HBox;
|
||||
import p.studio.ui.javafx.utilities.i18n.I18n;
|
||||
import p.studio.ui.javafx.utilities.i18n.I18nService;
|
||||
|
||||
public final class StudioFormActionBar extends HBox {
|
||||
private final Button changeButton;
|
||||
private final Button applyButton;
|
||||
private final Button resetButton;
|
||||
private final Button cancelButton;
|
||||
|
||||
public StudioFormActionBar(
|
||||
I18nService i18n,
|
||||
Runnable onChange,
|
||||
Runnable onApply,
|
||||
Runnable onReset,
|
||||
Runnable onCancel) {
|
||||
changeButton = createButton(i18n, I18n.FORM_ACTION_CHANGE);
|
||||
applyButton = createButton(i18n, I18n.FORM_ACTION_APPLY);
|
||||
resetButton = createButton(i18n, I18n.FORM_ACTION_RESET);
|
||||
cancelButton = createButton(i18n, I18n.FORM_ACTION_CANCEL);
|
||||
setSpacing(8);
|
||||
getStyleClass().add("studio-form-actions");
|
||||
changeButton.getStyleClass().add("studio-button-secondary");
|
||||
applyButton.getStyleClass().add("studio-button-primary");
|
||||
resetButton.getStyleClass().add("studio-button-secondary");
|
||||
cancelButton.getStyleClass().add("studio-button-cancel");
|
||||
changeButton.setOnAction(ignored -> onChange.run());
|
||||
applyButton.setOnAction(ignored -> onApply.run());
|
||||
resetButton.setOnAction(ignored -> onReset.run());
|
||||
cancelButton.setOnAction(ignored -> onCancel.run());
|
||||
getChildren().setAll(changeButton, applyButton, resetButton, cancelButton);
|
||||
}
|
||||
|
||||
public void updateState(StudioFormMode mode, boolean dirty) {
|
||||
updateState(mode, dirty, true);
|
||||
}
|
||||
|
||||
public void updateState(StudioFormMode mode, boolean dirty, boolean canBeginEdit) {
|
||||
final boolean editing = mode == StudioFormMode.EDITING;
|
||||
setVisibleManaged(changeButton, !editing);
|
||||
setVisibleManaged(applyButton, editing);
|
||||
setVisibleManaged(resetButton, editing);
|
||||
setVisibleManaged(cancelButton, editing);
|
||||
changeButton.setDisable(!canBeginEdit);
|
||||
applyButton.setDisable(!dirty);
|
||||
resetButton.setDisable(!dirty);
|
||||
}
|
||||
|
||||
private Button createButton(I18nService i18n, I18n label) {
|
||||
final Button button = new Button();
|
||||
button.textProperty().bind(i18n.bind(label));
|
||||
button.getStyleClass().add("studio-button");
|
||||
return button;
|
||||
}
|
||||
|
||||
private void setVisibleManaged(Button button, boolean visible) {
|
||||
button.setVisible(visible);
|
||||
button.setManaged(visible);
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package p.studio.ui.javafx.controls.forms;
|
||||
|
||||
import p.studio.ui.javafx.events.StudioEvent;
|
||||
|
||||
public record StudioFormEditScopeChangedEvent(
|
||||
String scopeKey,
|
||||
String ownerSectionId) implements StudioEvent {
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
package p.studio.ui.javafx.controls.forms;
|
||||
|
||||
public enum StudioFormMode {
|
||||
READ_ONLY,
|
||||
EDITING
|
||||
}
|
||||
+172
@@ -0,0 +1,172 @@
|
||||
package p.studio.ui.javafx.controls.forms;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.control.ScrollPane;
|
||||
import javafx.scene.layout.Priority;
|
||||
import javafx.scene.layout.VBox;
|
||||
import p.studio.ui.javafx.events.StudioWorkspaceEventBus;
|
||||
import p.studio.ui.javafx.utilities.i18n.I18nService;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public abstract class StudioFormSection extends StudioSection {
|
||||
private final StudioFormActionBar actionBar;
|
||||
private final VBox contentHost = new VBox();
|
||||
private boolean editAllowed = true;
|
||||
private VBox mountedSection;
|
||||
|
||||
protected StudioFormSection(I18nService i18n) {
|
||||
super();
|
||||
actionBar = new StudioFormActionBar(i18n, this::handleBeginEdit, this::handleApply,
|
||||
this::handleReset, this::handleCancel);
|
||||
actionBar.getStyleClass().add("studio-form-section-actions");
|
||||
contentHost.setFillWidth(true);
|
||||
VBox.setVgrow(contentHost, Priority.ALWAYS);
|
||||
}
|
||||
|
||||
public static VBox createReadOnlySection(String title, Node content) {
|
||||
return StudioSection.createSection(title, content);
|
||||
}
|
||||
|
||||
public static VBox createEditableSection(String title, Node headerActions, Node content, StudioFormMode mode) {
|
||||
return StudioSection.createSection(title, headerActions, content, true, mode == StudioFormMode.EDITING, true);
|
||||
}
|
||||
|
||||
protected final void renderFormSection(Node content) {
|
||||
updateActionBarState();
|
||||
if (mountedSection == null) {
|
||||
mountedSection = createEditableSection(sectionTitle(), actionBar, contentHost, formMode());
|
||||
final String sectionStyleClass = sectionStyleClass();
|
||||
if (sectionStyleClass != null && !sectionStyleClass.isBlank()) {
|
||||
mountedSection.getStyleClass().add(sectionStyleClass);
|
||||
}
|
||||
getChildren().setAll(mountedSection);
|
||||
}
|
||||
syncMountedSectionState();
|
||||
contentHost.getChildren().setAll(content);
|
||||
}
|
||||
|
||||
protected final void clearRenderedSection() {
|
||||
contentHost.getChildren().clear();
|
||||
mountedSection = null;
|
||||
getChildren().clear();
|
||||
}
|
||||
|
||||
protected final void updateActionBarState() {
|
||||
actionBar.updateState(formMode(), isDirty(), editAllowed);
|
||||
}
|
||||
|
||||
protected final void setEditAllowed(boolean editAllowed) {
|
||||
this.editAllowed = editAllowed;
|
||||
updateActionBarState();
|
||||
}
|
||||
|
||||
protected final boolean isEditAllowed() {
|
||||
return editAllowed;
|
||||
}
|
||||
|
||||
protected abstract String formSectionId();
|
||||
|
||||
protected final void handleEditScopeChanged(StudioFormEditScopeChangedEvent event, String currentScopeKey) {
|
||||
if (!Objects.equals(currentScopeKey, event.scopeKey())) {
|
||||
setEditAllowed(true);
|
||||
return;
|
||||
}
|
||||
if (event.ownerSectionId() == null && formMode() == StudioFormMode.EDITING) {
|
||||
cancel();
|
||||
renderSection();
|
||||
return;
|
||||
}
|
||||
setEditAllowed(event.ownerSectionId() == null || formSectionId().equals(event.ownerSectionId()));
|
||||
}
|
||||
|
||||
protected final void publishEditScope(StudioWorkspaceEventBus workspaceBus, String scopeKey, String ownerSectionId) {
|
||||
setEditAllowed(ownerSectionId == null || formSectionId().equals(ownerSectionId));
|
||||
workspaceBus.publish(new StudioFormEditScopeChangedEvent(scopeKey, ownerSectionId));
|
||||
}
|
||||
|
||||
protected final void rerenderPreservingScrollPosition() {
|
||||
final ScrollPane scrollPane = findAncestorScrollPane();
|
||||
final double previousVvalue = scrollPane == null ? 0.0d : scrollPane.getVvalue();
|
||||
renderSection();
|
||||
if (scrollPane != null) {
|
||||
restoreScrollPosition(scrollPane, previousVvalue, 2);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void renderSection();
|
||||
|
||||
protected abstract String sectionTitle();
|
||||
|
||||
protected abstract StudioFormMode formMode();
|
||||
|
||||
protected abstract boolean isDirty();
|
||||
|
||||
protected abstract void beginEdit();
|
||||
|
||||
protected abstract void apply();
|
||||
|
||||
protected abstract void reset();
|
||||
|
||||
protected abstract void cancel();
|
||||
|
||||
protected String sectionStyleClass() {
|
||||
return null;
|
||||
}
|
||||
|
||||
private void handleBeginEdit() {
|
||||
if (!editAllowed) {
|
||||
return;
|
||||
}
|
||||
beginEdit();
|
||||
rerenderPreservingScrollPosition();
|
||||
}
|
||||
|
||||
private void handleApply() {
|
||||
apply();
|
||||
}
|
||||
|
||||
private void handleReset() {
|
||||
reset();
|
||||
rerenderPreservingScrollPosition();
|
||||
}
|
||||
|
||||
private void handleCancel() {
|
||||
cancel();
|
||||
rerenderPreservingScrollPosition();
|
||||
}
|
||||
|
||||
private void restoreScrollPosition(ScrollPane scrollPane, double vvalue, int remainingPasses) {
|
||||
Platform.runLater(() -> {
|
||||
scrollPane.applyCss();
|
||||
scrollPane.layout();
|
||||
scrollPane.setVvalue(vvalue);
|
||||
if (remainingPasses > 0) {
|
||||
restoreScrollPosition(scrollPane, vvalue, remainingPasses - 1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private ScrollPane findAncestorScrollPane() {
|
||||
Parent current = getParent();
|
||||
while (current != null) {
|
||||
if (current instanceof ScrollPane scrollPane) {
|
||||
return scrollPane;
|
||||
}
|
||||
current = current.getParent();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void syncMountedSectionState() {
|
||||
if (mountedSection == null) {
|
||||
return;
|
||||
}
|
||||
mountedSection.getStyleClass().remove("studio-form-section-editing");
|
||||
if (formMode() == StudioFormMode.EDITING) {
|
||||
mountedSection.getStyleClass().add("studio-form-section-editing");
|
||||
}
|
||||
}
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
package p.studio.ui.javafx.controls.forms;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.function.UnaryOperator;
|
||||
|
||||
public final class StudioFormSession<T> {
|
||||
private T source;
|
||||
private T draft;
|
||||
private StudioFormMode mode;
|
||||
|
||||
public StudioFormSession(T source) {
|
||||
replaceSource(source);
|
||||
}
|
||||
|
||||
public void replaceSource(T source) {
|
||||
this.source = Objects.requireNonNull(source, "source");
|
||||
this.draft = source;
|
||||
this.mode = StudioFormMode.READ_ONLY;
|
||||
}
|
||||
|
||||
public T source() {
|
||||
return source;
|
||||
}
|
||||
|
||||
public T draft() {
|
||||
return draft;
|
||||
}
|
||||
|
||||
public StudioFormMode mode() {
|
||||
return mode;
|
||||
}
|
||||
|
||||
public boolean isDirty() {
|
||||
return !Objects.equals(source, draft);
|
||||
}
|
||||
|
||||
public void beginEdit() {
|
||||
mode = StudioFormMode.EDITING;
|
||||
}
|
||||
|
||||
public void setDraft(T draft) {
|
||||
this.draft = Objects.requireNonNull(draft, "draft");
|
||||
}
|
||||
|
||||
public void updateDraft(UnaryOperator<T> update) {
|
||||
draft = Objects.requireNonNull(update, "update").apply(draft);
|
||||
draft = Objects.requireNonNull(draft, "draft");
|
||||
}
|
||||
|
||||
public void resetDraft() {
|
||||
draft = source;
|
||||
}
|
||||
|
||||
public void cancelEdit() {
|
||||
resetDraft();
|
||||
mode = StudioFormMode.READ_ONLY;
|
||||
}
|
||||
|
||||
public T apply() {
|
||||
source = draft;
|
||||
mode = StudioFormMode.READ_ONLY;
|
||||
return source;
|
||||
}
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
package p.studio.ui.javafx.controls.forms;
|
||||
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.Priority;
|
||||
import javafx.scene.layout.Region;
|
||||
import javafx.scene.layout.VBox;
|
||||
import p.studio.ui.javafx.controls.lifecycle.StudioControlLifecycle;
|
||||
import p.studio.ui.javafx.controls.lifecycle.StudioControlLifecycleSupport;
|
||||
|
||||
public abstract class StudioSection extends VBox implements StudioControlLifecycle {
|
||||
protected StudioSection() {
|
||||
StudioControlLifecycleSupport.install(this, this);
|
||||
}
|
||||
|
||||
public static VBox createSection(String title, Node content) {
|
||||
return createSection(title, null, content, false, false, true);
|
||||
}
|
||||
|
||||
public static VBox createSectionWithoutHeader(Node content) {
|
||||
return createSection(null, null, content, false, false, false);
|
||||
}
|
||||
|
||||
protected static VBox createSection(
|
||||
String title,
|
||||
Node headerActions,
|
||||
Node content,
|
||||
boolean editable,
|
||||
boolean editing,
|
||||
boolean showHeader) {
|
||||
final VBox section = new VBox(10);
|
||||
section.getStyleClass().add("studio-form-section");
|
||||
if (editable) {
|
||||
section.getStyleClass().add("studio-form-section-editable");
|
||||
}
|
||||
if (editing) {
|
||||
section.getStyleClass().add("studio-form-section-editing");
|
||||
}
|
||||
|
||||
if (showHeader) {
|
||||
final Label titleLabel = new Label(title == null ? "" : title);
|
||||
titleLabel.getStyleClass().add("studio-form-section-title");
|
||||
|
||||
final Region spacer = new Region();
|
||||
HBox.setHgrow(spacer, Priority.ALWAYS);
|
||||
|
||||
final HBox header = new HBox(12, titleLabel, spacer);
|
||||
header.getStyleClass().add("studio-form-section-header");
|
||||
if (headerActions != null) {
|
||||
header.getChildren().add(headerActions);
|
||||
}
|
||||
section.getChildren().add(header);
|
||||
}
|
||||
|
||||
section.getChildren().add(content);
|
||||
return section;
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package p.studio.ui.javafx.controls.lifecycle;
|
||||
|
||||
public interface StudioControlLifecycle {
|
||||
default void subscribe() {
|
||||
}
|
||||
|
||||
default void unsubscribe() {
|
||||
}
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
package p.studio.ui.javafx.controls.lifecycle;
|
||||
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.Scene;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public final class StudioControlLifecycleSupport {
|
||||
private StudioControlLifecycleSupport() {
|
||||
}
|
||||
|
||||
public static void install(Node node, StudioControlLifecycle lifecycle) {
|
||||
Objects.requireNonNull(node, "node");
|
||||
Objects.requireNonNull(lifecycle, "lifecycle");
|
||||
|
||||
node.sceneProperty().addListener((ignored, oldScene, newScene) -> {
|
||||
if (oldScene == null && newScene != null) {
|
||||
lifecycle.subscribe();
|
||||
return;
|
||||
}
|
||||
|
||||
if (oldScene != null && newScene == null) {
|
||||
lifecycle.unsubscribe();
|
||||
return;
|
||||
}
|
||||
|
||||
if (oldScene != null && oldScene != newScene) {
|
||||
lifecycle.unsubscribe();
|
||||
lifecycle.subscribe();
|
||||
}
|
||||
});
|
||||
|
||||
final Scene currentScene = node.getScene();
|
||||
if (currentScene != null) {
|
||||
lifecycle.subscribe();
|
||||
}
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package p.studio.ui.javafx.controls.shell;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public record StudioActivityEntry(
|
||||
String source,
|
||||
String message,
|
||||
StudioActivityEntrySeverity severity,
|
||||
boolean sticky) {
|
||||
|
||||
public StudioActivityEntry {
|
||||
source = Objects.requireNonNull(source, "source").trim();
|
||||
message = Objects.requireNonNull(message, "message").trim();
|
||||
Objects.requireNonNull(severity, "severity");
|
||||
if (source.isBlank() || message.isBlank()) {
|
||||
throw new IllegalArgumentException("source and message must not be blank");
|
||||
}
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package p.studio.ui.javafx.controls.shell;
|
||||
|
||||
public enum StudioActivityEntrySeverity {
|
||||
INFO,
|
||||
SUCCESS,
|
||||
WARNING,
|
||||
ERROR
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
package p.studio.ui.javafx.controls.shell;
|
||||
|
||||
import p.studio.ui.javafx.events.*;
|
||||
import p.studio.ui.javafx.workspaces.assets.messages.events.StudioAssetsWorkspaceRefreshFailedEvent;
|
||||
import p.studio.ui.javafx.workspaces.assets.messages.events.StudioAssetsWorkspaceRefreshStartedEvent;
|
||||
import p.studio.ui.javafx.workspaces.assets.messages.events.StudioAssetsWorkspaceRefreshedEvent;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public final class StudioActivityEventMapper {
|
||||
private StudioActivityEventMapper() {
|
||||
}
|
||||
|
||||
public static Optional<StudioActivityEntry> map(StudioEvent event) {
|
||||
return switch (event) {
|
||||
case StudioProjectOpenedEvent ignored ->
|
||||
Optional.of(new StudioActivityEntry("Studio", "Project opened", StudioActivityEntrySeverity.SUCCESS, false));
|
||||
case StudioProjectLoadingStartedEvent ignored ->
|
||||
Optional.of(new StudioActivityEntry("Studio", "Project loading started", StudioActivityEntrySeverity.INFO, false));
|
||||
case StudioProjectLoadingCompletedEvent ignored ->
|
||||
Optional.of(new StudioActivityEntry("Studio", "Project ready", StudioActivityEntrySeverity.SUCCESS, false));
|
||||
case StudioProjectLoadingFailedEvent failed ->
|
||||
Optional.of(new StudioActivityEntry("Studio", failed.message(), StudioActivityEntrySeverity.ERROR, true));
|
||||
case StudioAssetsWorkspaceRefreshStartedEvent ignored ->
|
||||
Optional.of(new StudioActivityEntry("Assets", "Asset scan started", StudioActivityEntrySeverity.INFO, false));
|
||||
case StudioAssetsWorkspaceRefreshedEvent refreshed ->
|
||||
Optional.of(new StudioActivityEntry("Assets", refreshed.assetCount() + " assets loaded", StudioActivityEntrySeverity.SUCCESS, false));
|
||||
case StudioAssetsWorkspaceRefreshFailedEvent failed ->
|
||||
Optional.of(new StudioActivityEntry("Assets", failed.message(), StudioActivityEntrySeverity.ERROR, true));
|
||||
case StudioPackerOperationEvent packerEvent ->
|
||||
Optional.of(new StudioActivityEntry("Assets", packerEvent.summary(), severity(packerEvent), packerEvent.kind() == StudioPackerOperationKind.ACTION_FAILED));
|
||||
case StudioExecutionLifecycleEvent executionEvent ->
|
||||
Optional.of(new StudioActivityEntry(executionEvent.source(), executionEvent.message(), executionEvent.severity(), executionEvent.sticky()));
|
||||
default -> Optional.empty();
|
||||
};
|
||||
}
|
||||
|
||||
private static StudioActivityEntrySeverity severity(StudioPackerOperationEvent event) {
|
||||
return switch (event.kind()) {
|
||||
case ACTION_APPLIED -> StudioActivityEntrySeverity.SUCCESS;
|
||||
case ACTION_FAILED -> StudioActivityEntrySeverity.ERROR;
|
||||
default -> StudioActivityEntrySeverity.INFO;
|
||||
};
|
||||
}
|
||||
}
|
||||
+208
@@ -0,0 +1,208 @@
|
||||
package p.studio.ui.javafx.controls.shell;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.ListCell;
|
||||
import javafx.scene.control.ListView;
|
||||
import javafx.scene.control.ProgressBar;
|
||||
import javafx.scene.layout.VBox;
|
||||
import p.studio.ui.javafx.controls.lifecycle.StudioControlLifecycle;
|
||||
import p.studio.ui.javafx.controls.lifecycle.StudioControlLifecycleSupport;
|
||||
import p.studio.ui.javafx.events.*;
|
||||
import p.studio.api.project.ProjectReference;
|
||||
import p.studio.api.preferences.ProjectActivityHistoryStore;
|
||||
import p.studio.ui.javafx.events.StudioEventSubscription;
|
||||
import p.studio.ui.javafx.utilities.i18n.I18n;
|
||||
import p.studio.ui.javafx.utilities.i18n.I18nService;
|
||||
import p.studio.ui.javafx.workspaces.assets.messages.events.StudioAssetsWorkspaceRefreshFailedEvent;
|
||||
import p.studio.ui.javafx.workspaces.assets.messages.events.StudioAssetsWorkspaceRefreshStartedEvent;
|
||||
import p.studio.ui.javafx.workspaces.assets.messages.events.StudioAssetsWorkspaceRefreshedEvent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public final class StudioActivityFeedControl extends VBox implements StudioControlLifecycle {
|
||||
private final ProjectReference projectReference;
|
||||
private final StudioActivityStorageService storageService;
|
||||
private final I18nService i18n;
|
||||
private final StudioEventBus eventBus;
|
||||
private final ObservableList<StudioActivityEntry> entries = FXCollections.observableArrayList();
|
||||
private final List<StudioEventSubscription> subscriptions = new ArrayList<>();
|
||||
private final Label progressLabel = new Label();
|
||||
private final ProgressBar progressBar = new ProgressBar();
|
||||
private final ListView<StudioActivityEntry> listView = new ListView<>(entries);
|
||||
|
||||
public StudioActivityFeedControl(ProjectReference projectReference, ProjectActivityHistoryStore historyStore,
|
||||
I18nService i18n, StudioEventBus eventBus) {
|
||||
this(projectReference, new StudioActivityStorageService(historyStore), i18n, eventBus);
|
||||
}
|
||||
|
||||
StudioActivityFeedControl(ProjectReference projectReference, StudioActivityStorageService storageService,
|
||||
I18nService i18n, StudioEventBus eventBus) {
|
||||
StudioControlLifecycleSupport.install(this, this);
|
||||
this.projectReference = Objects.requireNonNull(projectReference, "projectReference");
|
||||
this.storageService = Objects.requireNonNull(storageService, "storageService");
|
||||
this.i18n = Objects.requireNonNull(i18n, "i18n");
|
||||
this.eventBus = Objects.requireNonNull(eventBus, "eventBus");
|
||||
getStyleClass().add("studio-activity-feed");
|
||||
setSpacing(10);
|
||||
setPadding(new Insets(12));
|
||||
|
||||
progressLabel.setText(i18n.text(I18n.ACTIVITY_PROGRESS_IDLE));
|
||||
progressLabel.getStyleClass().add("studio-activity-progress-label");
|
||||
progressBar.getStyleClass().add("studio-activity-progress-bar");
|
||||
progressBar.setVisible(false);
|
||||
progressBar.setManaged(false);
|
||||
|
||||
listView.getStyleClass().add("studio-activity-list");
|
||||
listView.setCellFactory(ignored -> new ActivityCell());
|
||||
|
||||
entries.setAll(this.storageService.load(projectReference));
|
||||
getChildren().addAll(progressLabel, progressBar, listView);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void subscribe() {
|
||||
if (!subscriptions.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
subscriptions.add(eventBus.subscribe(StudioProjectOpenedEvent.class, this::onEvent));
|
||||
subscriptions.add(eventBus.subscribe(StudioProjectLoadingStartedEvent.class, this::onEvent));
|
||||
subscriptions.add(eventBus.subscribe(StudioProjectLoadingProgressEvent.class, this::onProjectLoadingProgress));
|
||||
subscriptions.add(eventBus.subscribe(StudioProjectLoadingCompletedEvent.class, this::onProjectLoadingCompleted));
|
||||
subscriptions.add(eventBus.subscribe(StudioProjectLoadingFailedEvent.class, this::onProjectLoadingFailed));
|
||||
subscriptions.add(eventBus.subscribe(StudioAssetsWorkspaceRefreshStartedEvent.class, this::onAssetsRefreshStarted));
|
||||
subscriptions.add(eventBus.subscribe(StudioAssetsWorkspaceRefreshedEvent.class, this::onAssetsRefreshFinished));
|
||||
subscriptions.add(eventBus.subscribe(StudioAssetsWorkspaceRefreshFailedEvent.class, this::onAssetsRefreshFailed));
|
||||
subscriptions.add(eventBus.subscribe(StudioPackerOperationEvent.class, this::onPackerOperation));
|
||||
subscriptions.add(eventBus.subscribe(StudioExecutionLifecycleEvent.class, this::onEvent));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unsubscribe() {
|
||||
subscriptions.forEach(StudioEventSubscription::unsubscribe);
|
||||
subscriptions.clear();
|
||||
}
|
||||
|
||||
private void onEvent(StudioEvent event) {
|
||||
StudioActivityEventMapper.map(event).ifPresent(this::appendEntry);
|
||||
}
|
||||
|
||||
private void onProjectLoadingProgress(StudioProjectLoadingProgressEvent event) {
|
||||
Platform.runLater(() -> {
|
||||
progressLabel.setText(event.message());
|
||||
progressBar.setVisible(true);
|
||||
progressBar.setManaged(true);
|
||||
if (event.indeterminate()) {
|
||||
progressBar.setProgress(ProgressBar.INDETERMINATE_PROGRESS);
|
||||
} else {
|
||||
progressBar.setProgress(event.progress());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void onProjectLoadingCompleted(StudioProjectLoadingCompletedEvent event) {
|
||||
onEvent(event);
|
||||
clearProgress();
|
||||
}
|
||||
|
||||
private void onProjectLoadingFailed(StudioProjectLoadingFailedEvent event) {
|
||||
onEvent(event);
|
||||
clearProgress();
|
||||
}
|
||||
|
||||
private void onAssetsRefreshStarted(StudioAssetsWorkspaceRefreshStartedEvent event) {
|
||||
onEvent(event);
|
||||
Platform.runLater(() -> {
|
||||
progressLabel.setText(i18n.text(I18n.ACTIVITY_PROGRESS_ASSETS_REFRESH));
|
||||
progressBar.setVisible(true);
|
||||
progressBar.setManaged(true);
|
||||
progressBar.setProgress(ProgressBar.INDETERMINATE_PROGRESS);
|
||||
});
|
||||
}
|
||||
|
||||
private void onAssetsRefreshFinished(StudioAssetsWorkspaceRefreshedEvent event) {
|
||||
onEvent(event);
|
||||
clearProgress();
|
||||
}
|
||||
|
||||
private void onAssetsRefreshFailed(StudioAssetsWorkspaceRefreshFailedEvent event) {
|
||||
onEvent(event);
|
||||
clearProgress();
|
||||
}
|
||||
|
||||
private void onPackerOperation(StudioPackerOperationEvent event) {
|
||||
onEvent(event);
|
||||
if (event.progress() != null) {
|
||||
Platform.runLater(() -> {
|
||||
progressLabel.setText(event.summary());
|
||||
progressBar.setVisible(true);
|
||||
progressBar.setManaged(true);
|
||||
progressBar.setProgress(event.indeterminate() ? ProgressBar.INDETERMINATE_PROGRESS : event.progress());
|
||||
});
|
||||
}
|
||||
if (event.kind() == StudioPackerOperationKind.ACTION_APPLIED
|
||||
|| event.kind() == StudioPackerOperationKind.ACTION_FAILED) {
|
||||
clearProgress();
|
||||
}
|
||||
}
|
||||
|
||||
private void clearProgress() {
|
||||
Platform.runLater(() -> {
|
||||
progressLabel.setText(i18n.text(I18n.ACTIVITY_PROGRESS_IDLE));
|
||||
progressBar.setVisible(false);
|
||||
progressBar.setManaged(false);
|
||||
});
|
||||
}
|
||||
|
||||
private void appendEntry(StudioActivityEntry entry) {
|
||||
Platform.runLater(() -> {
|
||||
if (!entries.isEmpty()) {
|
||||
final StudioActivityEntry latest = entries.getFirst();
|
||||
if (latest.source().equals(entry.source())
|
||||
&& latest.message().equals(entry.message())
|
||||
&& latest.severity() == entry.severity()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
entries.addFirst(entry);
|
||||
while (entries.size() > StudioActivityStorageService.MAX_HISTORY) {
|
||||
entries.removeLast();
|
||||
}
|
||||
storageService.save(projectReference, List.copyOf(entries));
|
||||
});
|
||||
}
|
||||
|
||||
private static final class ActivityCell extends ListCell<StudioActivityEntry> {
|
||||
@Override
|
||||
protected void updateItem(StudioActivityEntry item, boolean empty) {
|
||||
super.updateItem(item, empty);
|
||||
getStyleClass().removeAll(
|
||||
"studio-activity-cell-info",
|
||||
"studio-activity-cell-success",
|
||||
"studio-activity-cell-warning",
|
||||
"studio-activity-cell-error");
|
||||
|
||||
if (empty || item == null) {
|
||||
setText(null);
|
||||
setGraphic(null);
|
||||
return;
|
||||
}
|
||||
|
||||
final Label source = new Label(item.source());
|
||||
source.getStyleClass().add("studio-activity-cell-source");
|
||||
final Label message = new Label(item.message());
|
||||
message.getStyleClass().add("studio-activity-cell-message");
|
||||
message.setWrapText(true);
|
||||
final VBox content = new VBox(4, source, message);
|
||||
content.setAlignment(Pos.CENTER_LEFT);
|
||||
setGraphic(content);
|
||||
getStyleClass().add("studio-activity-cell-" + item.severity().name().toLowerCase());
|
||||
}
|
||||
}
|
||||
}
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
package p.studio.ui.javafx.controls.shell;
|
||||
|
||||
import p.studio.api.preferences.ProjectActivityHistoryStore;
|
||||
import p.studio.api.preferences.ProjectActivityRecord;
|
||||
import p.studio.api.project.ProjectReference;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public final class StudioActivityStorageService {
|
||||
public static final int MAX_HISTORY = 500;
|
||||
|
||||
private final ProjectActivityHistoryStore store;
|
||||
|
||||
public StudioActivityStorageService(ProjectActivityHistoryStore store) {
|
||||
this.store = Objects.requireNonNull(store, "store");
|
||||
}
|
||||
|
||||
public List<StudioActivityEntry> load(ProjectReference projectReference) {
|
||||
final List<StudioActivityEntry> entries = new ArrayList<>();
|
||||
for (ProjectActivityRecord persistedEntry : store.load(projectReference)) {
|
||||
final StudioActivityEntry mapped = map(persistedEntry);
|
||||
if (mapped != null) {
|
||||
entries.add(mapped);
|
||||
}
|
||||
}
|
||||
return bounded(entries);
|
||||
}
|
||||
|
||||
public void save(ProjectReference projectReference, List<StudioActivityEntry> entries) {
|
||||
final List<StudioActivityEntry> boundedEntries = bounded(entries);
|
||||
final List<ProjectActivityRecord> persistedEntries = boundedEntries.stream()
|
||||
.map(entry -> new ProjectActivityRecord(
|
||||
entry.source(),
|
||||
entry.message(),
|
||||
entry.severity().name(),
|
||||
entry.sticky()))
|
||||
.toList();
|
||||
store.save(projectReference, persistedEntries);
|
||||
}
|
||||
|
||||
public List<StudioActivityEntry> bounded(List<StudioActivityEntry> entries) {
|
||||
final List<StudioActivityEntry> normalized = List.copyOf(Objects.requireNonNull(entries, "entries"));
|
||||
if (normalized.size() <= MAX_HISTORY) {
|
||||
return normalized;
|
||||
}
|
||||
return List.copyOf(normalized.subList(0, MAX_HISTORY));
|
||||
}
|
||||
|
||||
private StudioActivityEntry map(ProjectActivityRecord persistedEntry) {
|
||||
if (persistedEntry == null
|
||||
|| persistedEntry.source() == null
|
||||
|| persistedEntry.message() == null
|
||||
|| persistedEntry.severity() == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return new StudioActivityEntry(
|
||||
persistedEntry.source(),
|
||||
persistedEntry.message(),
|
||||
StudioActivityEntrySeverity.valueOf(persistedEntry.severity().trim()),
|
||||
persistedEntry.sticky());
|
||||
} catch (RuntimeException ignored) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
package p.studio.ui.javafx.controls.shell;
|
||||
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.Tab;
|
||||
import javafx.scene.control.TabPane;
|
||||
import javafx.scene.layout.BorderPane;
|
||||
import javafx.scene.layout.VBox;
|
||||
import p.studio.ui.javafx.controls.lifecycle.StudioControlLifecycle;
|
||||
import p.studio.ui.javafx.controls.lifecycle.StudioControlLifecycleSupport;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public final class StudioRightUtilityPanelControl extends BorderPane implements StudioControlLifecycle {
|
||||
public StudioRightUtilityPanelControl(
|
||||
Node headerContent,
|
||||
ObservableValue<String> activityTitle,
|
||||
Node activityContent) {
|
||||
StudioControlLifecycleSupport.install(this, this);
|
||||
getStyleClass().add("studio-right-utility-panel");
|
||||
setPrefWidth(280);
|
||||
|
||||
final Tab activityTab = new Tab();
|
||||
activityTab.textProperty().bind(Objects.requireNonNull(activityTitle, "activityTitle"));
|
||||
activityTab.setClosable(false);
|
||||
activityTab.setContent(Objects.requireNonNull(activityContent, "activityContent"));
|
||||
|
||||
final TabPane tabs = new TabPane(activityTab);
|
||||
tabs.getStyleClass().add("studio-right-utility-tabs");
|
||||
final VBox layout = new VBox(10);
|
||||
layout.getStyleClass().add("studio-right-utility-layout");
|
||||
if (headerContent != null) {
|
||||
layout.getChildren().add(headerContent);
|
||||
}
|
||||
layout.getChildren().add(tabs);
|
||||
setCenter(layout);
|
||||
}
|
||||
|
||||
public static Label createPlaceholderContent(ObservableValue<String> text) {
|
||||
final Label label = new Label();
|
||||
label.textProperty().bind(Objects.requireNonNull(text, "text"));
|
||||
label.getStyleClass().add("studio-utility-placeholder");
|
||||
return label;
|
||||
}
|
||||
}
|
||||
+118
@@ -0,0 +1,118 @@
|
||||
package p.studio.ui.javafx.controls.shell;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.binding.Bindings;
|
||||
import javafx.beans.property.BooleanProperty;
|
||||
import javafx.beans.property.SimpleBooleanProperty;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.StackPane;
|
||||
import p.studio.ui.javafx.controls.lifecycle.StudioControlLifecycle;
|
||||
import p.studio.ui.javafx.controls.lifecycle.StudioControlLifecycleSupport;
|
||||
import p.studio.api.execution.ExecutionSession;
|
||||
import p.studio.api.execution.ExecutionSnapshot;
|
||||
import p.studio.api.execution.ExecutionState;
|
||||
import p.studio.api.operation.OperationSubscription;
|
||||
import p.studio.ui.javafx.utilities.i18n.I18n;
|
||||
import p.studio.ui.javafx.utilities.i18n.I18nService;
|
||||
|
||||
public final class StudioRunSurfaceControl extends HBox implements StudioControlLifecycle {
|
||||
private final BooleanProperty running = new SimpleBooleanProperty(false);
|
||||
private final ExecutionSession executionSessionService;
|
||||
private final Runnable playAction;
|
||||
private final Runnable stopAction;
|
||||
private final Button toggleButton = new Button();
|
||||
private OperationSubscription sessionSubscription;
|
||||
|
||||
public StudioRunSurfaceControl(
|
||||
final ExecutionSession executionSessionService,
|
||||
final Runnable playAction,
|
||||
final Runnable stopAction,
|
||||
final I18nService i18n) {
|
||||
StudioControlLifecycleSupport.install(this, this);
|
||||
this.executionSessionService = executionSessionService;
|
||||
this.playAction = playAction;
|
||||
this.stopAction = stopAction;
|
||||
getStyleClass().add("studio-run-surface");
|
||||
setSpacing(8);
|
||||
setAlignment(Pos.CENTER_LEFT);
|
||||
|
||||
final Label icon = new Label();
|
||||
icon.getStyleClass().add("studio-run-toggle-icon");
|
||||
icon.textProperty().bind(Bindings.when(running).then("\u25A0").otherwise("\u25B6"));
|
||||
|
||||
final StackPane iconShell = new StackPane(icon);
|
||||
iconShell.getStyleClass().add("studio-run-toggle-icon-shell");
|
||||
|
||||
final Label text = new Label();
|
||||
text.getStyleClass().add("studio-run-toggle-text");
|
||||
text.textProperty().bind(Bindings.createStringBinding(
|
||||
() -> i18n.text(running.get() ? I18n.TOOLBAR_STOP : I18n.TOOLBAR_PLAY),
|
||||
running));
|
||||
|
||||
final HBox content = new HBox(8, iconShell, text);
|
||||
content.setAlignment(Pos.CENTER_LEFT);
|
||||
|
||||
toggleButton.getStyleClass().add("studio-run-toggle-button");
|
||||
toggleButton.graphicProperty().set(content);
|
||||
toggleButton.setOnAction(ignored -> handleToggleRequested());
|
||||
|
||||
running.addListener((ignored, oldValue, newValue) -> {
|
||||
toggleButton.getStyleClass().removeAll("studio-run-toggle-play", "studio-run-toggle-stop");
|
||||
toggleButton.getStyleClass().add(newValue ? "studio-run-toggle-stop" : "studio-run-toggle-play");
|
||||
});
|
||||
toggleButton.getStyleClass().add("studio-run-toggle-play");
|
||||
|
||||
getChildren().add(toggleButton);
|
||||
}
|
||||
|
||||
public boolean isRunning() {
|
||||
return running.get();
|
||||
}
|
||||
|
||||
public BooleanProperty runningProperty() {
|
||||
return running;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void subscribe() {
|
||||
if (sessionSubscription != null) {
|
||||
return;
|
||||
}
|
||||
sessionSubscription = executionSessionService.subscribe(this::handleSessionUpdate);
|
||||
}
|
||||
|
||||
private void handleSessionUpdate(final ExecutionSnapshot snapshot) {
|
||||
if (Platform.isFxApplicationThread()) {
|
||||
running.set(isRunningState(snapshot.state()));
|
||||
return;
|
||||
}
|
||||
Platform.runLater(() -> running.set(isRunningState(snapshot.state())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unsubscribe() {
|
||||
if (sessionSubscription == null) {
|
||||
return;
|
||||
}
|
||||
sessionSubscription.unsubscribe();
|
||||
sessionSubscription = null;
|
||||
}
|
||||
|
||||
private void handleToggleRequested() {
|
||||
final ExecutionState state = executionSessionService.snapshot().state();
|
||||
if (isRunningState(state)) {
|
||||
stopAction.run();
|
||||
return;
|
||||
}
|
||||
playAction.run();
|
||||
}
|
||||
|
||||
private boolean isRunningState(final ExecutionState state) {
|
||||
return state == ExecutionState.PREPARING
|
||||
|| state == ExecutionState.CONNECTING
|
||||
|| state == ExecutionState.RUNNING;
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
package p.studio.ui.javafx.controls.shell;
|
||||
|
||||
import javafx.scene.control.Menu;
|
||||
import javafx.scene.control.MenuItem;
|
||||
import p.studio.ui.javafx.controls.lifecycle.StudioControlLifecycle;
|
||||
import p.studio.ui.javafx.controls.lifecycle.StudioControlLifecycleSupport;
|
||||
import p.studio.ui.javafx.utilities.i18n.I18n;
|
||||
import p.studio.ui.javafx.utilities.i18n.I18nService;
|
||||
|
||||
public final class StudioShellMenuBarControl extends javafx.scene.control.MenuBar implements StudioControlLifecycle {
|
||||
public StudioShellMenuBarControl(I18nService i18n) {
|
||||
StudioControlLifecycleSupport.install(this, this);
|
||||
getStyleClass().add("studio-shell-menu-bar");
|
||||
|
||||
final Menu fileMenu = new Menu();
|
||||
fileMenu.textProperty().bind(i18n.bind(I18n.MENU_FILE));
|
||||
|
||||
final MenuItem newProjectItem = new MenuItem();
|
||||
newProjectItem.textProperty().bind(i18n.bind(I18n.MENU_FILE_NEWPROJECT));
|
||||
newProjectItem.setOnAction(ignored -> { });
|
||||
|
||||
final MenuItem openItem = new MenuItem();
|
||||
openItem.textProperty().bind(i18n.bind(I18n.MENU_FILE_OPEN));
|
||||
openItem.setOnAction(ignored -> { });
|
||||
|
||||
final MenuItem saveItem = new MenuItem();
|
||||
saveItem.textProperty().bind(i18n.bind(I18n.MENU_FILE_SAVE));
|
||||
saveItem.setOnAction(ignored -> { });
|
||||
|
||||
fileMenu.getItems().addAll(newProjectItem, openItem, saveItem);
|
||||
|
||||
final Menu editMenu = new Menu();
|
||||
editMenu.textProperty().bind(i18n.bind(I18n.MENU_EDIT));
|
||||
|
||||
final Menu viewMenu = new Menu();
|
||||
viewMenu.textProperty().bind(i18n.bind(I18n.MENU_VIEW));
|
||||
|
||||
final Menu helpMenu = new Menu();
|
||||
helpMenu.textProperty().bind(i18n.bind(I18n.MENU_HELP));
|
||||
|
||||
getMenus().setAll(fileMenu, editMenu, viewMenu, helpMenu);
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package p.studio.ui.javafx.controls.shell;
|
||||
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.layout.BorderPane;
|
||||
import p.studio.ui.javafx.controls.lifecycle.StudioControlLifecycle;
|
||||
import p.studio.ui.javafx.controls.lifecycle.StudioControlLifecycleSupport;
|
||||
|
||||
public final class StudioShellTopBarControl extends BorderPane implements StudioControlLifecycle {
|
||||
public StudioShellTopBarControl(Node menuBar) {
|
||||
StudioControlLifecycleSupport.install(this, this);
|
||||
getStyleClass().add("studio-shell-top-bar");
|
||||
setLeft(menuBar);
|
||||
}
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
package p.studio.ui.javafx.controls.shell;
|
||||
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.scene.control.ToggleButton;
|
||||
import javafx.scene.control.ToggleGroup;
|
||||
import javafx.scene.control.Tooltip;
|
||||
import javafx.scene.layout.VBox;
|
||||
import p.studio.ui.javafx.controls.lifecycle.StudioControlLifecycle;
|
||||
import p.studio.ui.javafx.controls.lifecycle.StudioControlLifecycleSupport;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public final class StudioWorkspaceRailControl<T> extends VBox implements StudioControlLifecycle {
|
||||
private final Map<T, ToggleButton> buttons;
|
||||
private final ToggleGroup toggleGroup = new ToggleGroup();
|
||||
|
||||
public StudioWorkspaceRailControl(
|
||||
Collection<StudioWorkspaceRailItem<T>> items,
|
||||
Consumer<T> onSelect) {
|
||||
StudioControlLifecycleSupport.install(this, this);
|
||||
getStyleClass().add("studio-workspace-rail");
|
||||
setPadding(new Insets(8));
|
||||
setSpacing(8);
|
||||
setPrefWidth(64);
|
||||
|
||||
this.buttons = new HashMap<>();
|
||||
|
||||
for (StudioWorkspaceRailItem<T> item : items) {
|
||||
final ToggleButton button = new ToggleButton(item.icon());
|
||||
button.setToggleGroup(toggleGroup);
|
||||
button.setFocusTraversable(false);
|
||||
button.setPrefSize(44, 44);
|
||||
button.setMinSize(44, 44);
|
||||
button.setMaxSize(44, 44);
|
||||
button.getStyleClass().addAll(
|
||||
"studio-button",
|
||||
"studio-button-ghost",
|
||||
"studio-button-pill",
|
||||
"studio-button-icon",
|
||||
"studio-button-toggle",
|
||||
"studio-workspace-rail-button");
|
||||
button.setTooltip(new Tooltip());
|
||||
button.getTooltip().textProperty().bind(item.label());
|
||||
button.setOnAction(ignored -> Objects.requireNonNull(onSelect, "onSelect").accept(item.id()));
|
||||
|
||||
buttons.put(item.id(), button);
|
||||
getChildren().add(button);
|
||||
}
|
||||
}
|
||||
|
||||
public void select(T id) {
|
||||
final ToggleButton button = buttons.get(id);
|
||||
if (button != null) {
|
||||
button.setSelected(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package p.studio.ui.javafx.controls.shell;
|
||||
|
||||
import javafx.beans.value.ObservableValue;
|
||||
|
||||
public record StudioWorkspaceRailItem<T>(
|
||||
T id,
|
||||
String icon,
|
||||
ObservableValue<String> label) {
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package p.studio.ui.javafx.events;
|
||||
|
||||
public interface StudioEvent {
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package p.studio.ui.javafx.events;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public final class StudioEventBus {
|
||||
private final StudioTypedEventBus delegate = new StudioTypedEventBus();
|
||||
|
||||
public StudioEventBus() {
|
||||
}
|
||||
|
||||
public <T extends StudioEvent> StudioEventSubscription subscribe(Class<T> eventType, Consumer<? super T> consumer) {
|
||||
return delegate.subscribe(eventType, consumer);
|
||||
}
|
||||
|
||||
public void publish(StudioEvent event) {
|
||||
delegate.publish(event);
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package p.studio.ui.javafx.events;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface StudioEventSubscription extends AutoCloseable {
|
||||
void unsubscribe();
|
||||
|
||||
@Override
|
||||
default void close() {
|
||||
unsubscribe();
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package p.studio.ui.javafx.events;
|
||||
|
||||
import p.studio.ui.javafx.controls.shell.StudioActivityEntrySeverity;
|
||||
|
||||
public record StudioExecutionLifecycleEvent(
|
||||
String source,
|
||||
String message,
|
||||
StudioActivityEntrySeverity severity,
|
||||
boolean sticky) implements StudioEvent {
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package p.studio.ui.javafx.events;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public record StudioPackerOperationEvent(
|
||||
String operationId,
|
||||
StudioPackerOperationKind kind,
|
||||
String summary,
|
||||
Double progress,
|
||||
boolean indeterminate) implements StudioEvent {
|
||||
|
||||
public StudioPackerOperationEvent {
|
||||
operationId = Objects.requireNonNull(operationId, "operationId").trim();
|
||||
Objects.requireNonNull(kind, "kind");
|
||||
summary = Objects.requireNonNull(summary, "summary").trim();
|
||||
if (operationId.isBlank() || summary.isBlank()) {
|
||||
throw new IllegalArgumentException("operationId and summary must not be blank");
|
||||
}
|
||||
if (progress != null && !indeterminate && (progress < 0.0d || progress > 1.0d)) {
|
||||
throw new IllegalArgumentException("progress must be between 0.0 and 1.0 when determinate");
|
||||
}
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package p.studio.ui.javafx.events;
|
||||
|
||||
public enum StudioPackerOperationKind {
|
||||
ASSET_DISCOVERED,
|
||||
DIAGNOSTICS_UPDATED,
|
||||
ACTION_APPLIED,
|
||||
ACTION_FAILED
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
package p.studio.ui.javafx.events;
|
||||
|
||||
public record StudioProjectCreatedEvent() implements StudioEvent {
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
package p.studio.ui.javafx.events;
|
||||
|
||||
public record StudioProjectLoadingCompletedEvent() implements StudioEvent {
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package p.studio.ui.javafx.events;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public record StudioProjectLoadingFailedEvent(
|
||||
StudioProjectLoadingPhase phase,
|
||||
String message) implements StudioEvent {
|
||||
|
||||
public StudioProjectLoadingFailedEvent {
|
||||
Objects.requireNonNull(phase, "phase");
|
||||
Objects.requireNonNull(message, "message");
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package p.studio.ui.javafx.events;
|
||||
|
||||
public enum StudioProjectLoadingPhase {
|
||||
RESOLVING_PROJECT,
|
||||
RESTORING_WINDOW_STATE,
|
||||
RESTORING_WORKSPACES,
|
||||
INITIALIZING_SERVICES,
|
||||
READY
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
package p.studio.ui.javafx.events;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public record StudioProjectLoadingProgressEvent(
|
||||
StudioProjectLoadingPhase phase,
|
||||
String message,
|
||||
double progress,
|
||||
boolean indeterminate) implements StudioEvent {
|
||||
|
||||
public StudioProjectLoadingProgressEvent {
|
||||
Objects.requireNonNull(phase, "phase");
|
||||
Objects.requireNonNull(message, "message");
|
||||
if (!indeterminate && (progress < 0.0d || progress > 1.0d)) {
|
||||
throw new IllegalArgumentException("progress must be between 0.0 and 1.0 when determinate");
|
||||
}
|
||||
}
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
package p.studio.ui.javafx.events;
|
||||
|
||||
public record StudioProjectLoadingStartedEvent() implements StudioEvent {
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
package p.studio.ui.javafx.events;
|
||||
|
||||
public record StudioProjectOpenedEvent() implements StudioEvent {
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
package p.studio.ui.javafx.events;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
final class StudioTypedEventBus {
|
||||
private final AtomicLong nextSubscriptionId = new AtomicLong(1L);
|
||||
private final ConcurrentMap<Class<?>, ConcurrentMap<Long, Consumer<Object>>> subscriptionsByType =
|
||||
new ConcurrentHashMap<>();
|
||||
|
||||
<T extends StudioEvent> StudioEventSubscription subscribe(
|
||||
Class<T> eventType,
|
||||
Consumer<? super T> consumer) {
|
||||
Objects.requireNonNull(eventType, "eventType");
|
||||
Objects.requireNonNull(consumer, "consumer");
|
||||
|
||||
final long subscriptionId = nextSubscriptionId.getAndIncrement();
|
||||
final Consumer<Object> erasedConsumer = event -> consumer.accept(eventType.cast(event));
|
||||
final ConcurrentMap<Long, Consumer<Object>> subscriptions =
|
||||
subscriptionsByType.computeIfAbsent(eventType, ignored -> new ConcurrentHashMap<>());
|
||||
subscriptions.put(subscriptionId, erasedConsumer);
|
||||
|
||||
final AtomicBoolean active = new AtomicBoolean(true);
|
||||
return () -> {
|
||||
if (!active.compareAndSet(true, false)) {
|
||||
return;
|
||||
}
|
||||
final ConcurrentMap<Long, Consumer<Object>> currentSubscriptions = subscriptionsByType.get(eventType);
|
||||
if (currentSubscriptions == null) {
|
||||
return;
|
||||
}
|
||||
currentSubscriptions.remove(subscriptionId);
|
||||
if (currentSubscriptions.isEmpty()) {
|
||||
subscriptionsByType.remove(eventType, currentSubscriptions);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
void publish(StudioEvent event) {
|
||||
Objects.requireNonNull(event, "event");
|
||||
final ConcurrentMap<Long, Consumer<Object>> subscriptions = subscriptionsByType.get(event.getClass());
|
||||
if (subscriptions != null) {
|
||||
subscriptions.values().forEach(consumer -> consumer.accept(event));
|
||||
}
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package p.studio.ui.javafx.events;
|
||||
|
||||
import p.studio.ui.javafx.workspaces.WorkspaceId;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public final class StudioWorkspaceEventBus {
|
||||
private final WorkspaceId workspaceId;
|
||||
private final StudioEventBus globalBus;
|
||||
private final StudioTypedEventBus localBus;
|
||||
|
||||
public StudioWorkspaceEventBus(WorkspaceId workspaceId, StudioEventBus globalBus) {
|
||||
this.workspaceId = Objects.requireNonNull(workspaceId, "workspaceId");
|
||||
this.globalBus = Objects.requireNonNull(globalBus, "globalBus");
|
||||
this.localBus = new StudioTypedEventBus();
|
||||
}
|
||||
|
||||
public WorkspaceId workspaceId() {
|
||||
return workspaceId;
|
||||
}
|
||||
|
||||
public <T extends StudioEvent> StudioEventSubscription subscribe(Class<T> eventType, Consumer<? super T> consumer) {
|
||||
return localBus.subscribe(eventType, consumer);
|
||||
}
|
||||
|
||||
public void publish(StudioEvent event) {
|
||||
localBus.publish(event);
|
||||
globalBus.publish(event);
|
||||
}
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
package p.studio.ui.javafx.events;
|
||||
|
||||
import p.studio.ui.javafx.workspaces.WorkspaceId;
|
||||
|
||||
public record StudioWorkspaceSelectedEvent(WorkspaceId workspaceId) implements StudioEvent {
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
package p.studio.ui.javafx.utilities;
|
||||
|
||||
import javafx.scene.text.Font;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class ThemeService {
|
||||
private static final String THEME_PATH = "/themes/";
|
||||
private static final String DEFAULT_THEME = THEME_PATH + "default-prometeu.css";
|
||||
private static final String FONT_PATH = "/fonts/jetbrain-mono-3.2/fonts/ttf/";
|
||||
private static final String[] BUNDLED_FONTS = {
|
||||
"JetBrainsMono-Regular.ttf",
|
||||
"JetBrainsMono-Medium.ttf",
|
||||
"JetBrainsMono-Bold.ttf",
|
||||
"JetBrainsMono-Italic.ttf",
|
||||
"JetBrainsMono-MediumItalic.ttf",
|
||||
"JetBrainsMono-BoldItalic.ttf"
|
||||
};
|
||||
private static boolean fontsLoaded;
|
||||
|
||||
public String getDefaultTheme() {
|
||||
ensureBundledFontsLoaded();
|
||||
return Objects.requireNonNull(getClass().getResource(DEFAULT_THEME)).toExternalForm();
|
||||
}
|
||||
|
||||
private static synchronized void ensureBundledFontsLoaded() {
|
||||
if (fontsLoaded) {
|
||||
return;
|
||||
}
|
||||
for (final String fontFile : BUNDLED_FONTS) {
|
||||
try (final var stream = ThemeService.class.getResourceAsStream(FONT_PATH + fontFile)) {
|
||||
Font.loadFont(Objects.requireNonNull(stream, "missing bundled font: " + fontFile), 14);
|
||||
} catch (final Exception exception) {
|
||||
throw new IllegalStateException("unable to load bundled font: " + fontFile, exception);
|
||||
}
|
||||
}
|
||||
fontsLoaded = true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,379 @@
|
||||
package p.studio.ui.javafx.utilities.i18n;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
public enum I18n {
|
||||
APP_TITLE("app.title"),
|
||||
APP_PROJECT_TITLE("app.projectTitle"),
|
||||
SHIELD_LOADING_PROJECT("shield.loadingProject"),
|
||||
SHIELD_VERSION("shield.version"),
|
||||
SHIELD_STATUS_INDEXING("shield.status.indexing"),
|
||||
SHIELD_STATUS_RESTORING("shield.status.restoring"),
|
||||
SHIELD_PHASE_INDEXING("shield.phase.indexing"),
|
||||
SHIELD_PHASE_PREPARING("shield.phase.preparing"),
|
||||
SHIELD_PHASE_RESTORING("shield.phase.restoring"),
|
||||
SHIELD_TIP_SHORTCUTS("shield.tip.shortcuts"),
|
||||
SHIELD_TIP_WORKSPACES("shield.tip.workspaces"),
|
||||
SHIELD_TIP_ACTIVITY("shield.tip.activity"),
|
||||
|
||||
MENU_FILE("menu.file"),
|
||||
MENU_FILE_NEWPROJECT("menu.file.newProject"),
|
||||
MENU_FILE_OPEN("menu.file.open"),
|
||||
MENU_FILE_SAVE("menu.file.save"),
|
||||
|
||||
MENU_EDIT("menu.edit"),
|
||||
MENU_VIEW("menu.view"),
|
||||
MENU_HELP("menu.help"),
|
||||
|
||||
SHELL_ACTIVITY("shell.activity"),
|
||||
|
||||
LAUNCHER_TITLE("launcher.title"),
|
||||
LAUNCHER_SUBTITLE("launcher.subtitle"),
|
||||
LAUNCHER_EXISTING_PROJECTS("launcher.existingProjects"),
|
||||
LAUNCHER_OPEN_PROJECT("launcher.openProject"),
|
||||
LAUNCHER_ADD_PROJECT("launcher.addProject"),
|
||||
LAUNCHER_FORGET_PROJECT("launcher.forgetProject"),
|
||||
LAUNCHER_CREATE_PROJECT("launcher.createProject"),
|
||||
LAUNCHER_PROJECT_NAME_PROMPT("launcher.projectNamePrompt"),
|
||||
LAUNCHER_CREATE_BUTTON("launcher.createButton"),
|
||||
|
||||
WIZARD_TITLE("wizard.title"),
|
||||
WIZARD_BACK("wizard.back"),
|
||||
WIZARD_NEXT("wizard.next"),
|
||||
WIZARD_CREATE("wizard.create"),
|
||||
WIZARD_CANCEL("wizard.cancel"),
|
||||
WIZARD_BROWSE("wizard.browse"),
|
||||
WIZARD_STEP_NAME_TITLE("wizard.step.name.title"),
|
||||
WIZARD_STEP_NAME_DESCRIPTION("wizard.step.name.description"),
|
||||
WIZARD_STEP_LANGUAGE_TITLE("wizard.step.language.title"),
|
||||
WIZARD_STEP_LANGUAGE_DESCRIPTION("wizard.step.language.description"),
|
||||
WIZARD_STEP_LOCATION_TITLE("wizard.step.location.title"),
|
||||
WIZARD_STEP_LOCATION_DESCRIPTION("wizard.step.location.description"),
|
||||
WIZARD_STEP_DETAILS_TITLE("wizard.step.details.title"),
|
||||
WIZARD_STEP_DETAILS_DESCRIPTION("wizard.step.details.description"),
|
||||
WIZARD_STEP_CONFIRM_TITLE("wizard.step.confirm.title"),
|
||||
WIZARD_STEP_CONFIRM_DESCRIPTION("wizard.step.confirm.description"),
|
||||
WIZARD_LANGUAGE_LABEL("wizard.language.label"),
|
||||
WIZARD_STDLIB_LABEL("wizard.stdlib.label"),
|
||||
WIZARD_SOURCE_ROOT_LABEL("wizard.sourceRoot.label"),
|
||||
WIZARD_INDENTATION_LABEL("wizard.indentation.label"),
|
||||
WIZARD_RUNTIME_LABEL("wizard.runtime.label"),
|
||||
WIZARD_RUNTIME_PROMPT("wizard.runtime.prompt"),
|
||||
WIZARD_CONFIRM_NAME("wizard.confirm.name"),
|
||||
WIZARD_CONFIRM_LANGUAGE("wizard.confirm.language"),
|
||||
WIZARD_CONFIRM_STDLIB("wizard.confirm.stdlib"),
|
||||
WIZARD_CONFIRM_SOURCE_ROOT("wizard.confirm.sourceRoot"),
|
||||
WIZARD_CONFIRM_LOCATION("wizard.confirm.location"),
|
||||
WIZARD_CONFIRM_INDENTATION("wizard.confirm.indentation"),
|
||||
WIZARD_CONFIRM_RUNTIME("wizard.confirm.runtime"),
|
||||
WIZARD_CONFIRM_ROOT("wizard.confirm.root"),
|
||||
WIZARD_ERROR_NAME_REQUIRED("wizard.error.nameRequired"),
|
||||
WIZARD_ERROR_LANGUAGE_REQUIRED("wizard.error.languageRequired"),
|
||||
WIZARD_ERROR_STDLIB_REQUIRED("wizard.error.stdlibRequired"),
|
||||
WIZARD_ERROR_SOURCE_ROOT_REQUIRED("wizard.error.sourceRootRequired"),
|
||||
WIZARD_ERROR_LOCATION_REQUIRED("wizard.error.locationRequired"),
|
||||
WIZARD_ERROR_INDENTATION_REQUIRED("wizard.error.indentationRequired"),
|
||||
|
||||
TOOLBAR_PLAY("toolbar.play"),
|
||||
TOOLBAR_STOP("toolbar.stop"),
|
||||
TOOLBAR_EXPORT("toolbar.export"),
|
||||
|
||||
WORKSPACE_SHIPPER("workspace.shipper"),
|
||||
WORKSPACE_SHIPPER_LOGS("workspace.shipper.logs"),
|
||||
WORKSPACE_SHIPPER_BUTTON_RUN("workspace.shipper.button.run"),
|
||||
WORKSPACE_SHIPPER_BUTTON_CLEAR("workspace.shipper.button.clear"),
|
||||
WORKSPACE_DEBUG_STATE("workspace.debug.state"),
|
||||
WORKSPACE_DEBUG_LOGS("workspace.debug.logs"),
|
||||
WORKSPACE_DEBUG_STATUS_IDLE("workspace.debug.status.idle"),
|
||||
WORKSPACE_DEBUG_STATUS_PREPARING("workspace.debug.status.preparing"),
|
||||
WORKSPACE_DEBUG_STATUS_PREPARE_FAILED("workspace.debug.status.prepareFailed"),
|
||||
WORKSPACE_DEBUG_STATUS_CONNECTING("workspace.debug.status.connecting"),
|
||||
WORKSPACE_DEBUG_STATUS_RUNNING("workspace.debug.status.running"),
|
||||
WORKSPACE_DEBUG_STATUS_RUNTIME_FAILED("workspace.debug.status.runtimeFailed"),
|
||||
WORKSPACE_DEBUG_STATUS_STOPPED("workspace.debug.status.stopped"),
|
||||
|
||||
WORKSPACE_ASSETS("workspace.assets"),
|
||||
ASSETS_NAVIGATOR_TITLE("assets.navigator.title"),
|
||||
ASSETS_NAVIGATOR_ACTION_REFRESH("assets.navigator.action.refresh"),
|
||||
ASSETS_NAVIGATOR_ACTION_ADD("assets.navigator.action.add"),
|
||||
ASSETS_NAVIGATOR_ACTION_PACK("assets.navigator.action.pack"),
|
||||
ASSETS_SEARCH_PROMPT("assets.search.prompt"),
|
||||
ASSETS_FILTER_UNREGISTERED("assets.filter.unregistered"),
|
||||
ASSETS_FILTER_DIAGNOSTICS("assets.filter.diagnostics"),
|
||||
ASSETS_FILTER_PRELOAD("assets.filter.preload"),
|
||||
ASSETS_STATE_LOADING("assets.state.loading"),
|
||||
ASSETS_STATE_EMPTY("assets.state.empty"),
|
||||
ASSETS_STATE_NO_RESULTS("assets.state.noResults"),
|
||||
ASSETS_STATE_READY("assets.state.ready"),
|
||||
ASSETS_STATE_ERROR("assets.state.error"),
|
||||
ASSETS_BADGE_REGISTERED("assets.badge.registered"),
|
||||
ASSETS_BADGE_UNREGISTERED("assets.badge.unregistered"),
|
||||
ASSETS_BADGE_PRELOAD("assets.badge.preload"),
|
||||
ASSETS_BADGE_DIAGNOSTICS("assets.badge.diagnostics"),
|
||||
ASSETS_SECTION_SUMMARY("assets.section.summary"),
|
||||
ASSETS_SECTION_RUNTIME_CONTRACT("assets.section.runtimeContract"),
|
||||
ASSETS_SECTION_BANK_COMPOSITION("assets.section.bankComposition"),
|
||||
ASSETS_SECTION_SCENE_LAYERS("assets.section.sceneLayers"),
|
||||
ASSETS_SECTION_COLOR_SCHEMA_GROUPS("assets.section.colorSchemaGroups"),
|
||||
ASSETS_SECTION_LAYER_CONFIGURATION("assets.section.layerConfiguration"),
|
||||
ASSETS_SECTION_PALETTE_OVERHAULING("assets.section.paletteOverhauling"),
|
||||
ASSETS_SUBSECTION_CODEC_CONFIGURATION("assets.subsection.codecConfiguration"),
|
||||
ASSETS_SUBSECTION_METADATA("assets.subsection.metadata"),
|
||||
ASSETS_SECTION_INPUTS_PREVIEW("assets.section.inputsPreview"),
|
||||
ASSETS_SECTION_DIAGNOSTICS("assets.section.diagnostics"),
|
||||
ASSETS_SECTION_ACTIONS("assets.section.actions"),
|
||||
ASSETS_ACTIONS_EMPTY("assets.actions.empty"),
|
||||
ASSETS_ACTION_REGISTER("assets.action.register"),
|
||||
ASSETS_ACTION_ANALYSE("assets.action.analyse"),
|
||||
ASSETS_ACTION_EXPORT_TSX("assets.action.exportTsx"),
|
||||
ASSETS_ACTION_EXPORT_TMX("assets.action.exportTmx"),
|
||||
ASSETS_ACTION_IMPORT_TMX("assets.action.importTmx"),
|
||||
ASSETS_ACTION_VALIDATE_SCENE_BANK("assets.action.validateSceneBank"),
|
||||
ASSETS_ACTION_ACCEPT_SCENE_BANK("assets.action.acceptSceneBank"),
|
||||
ASSETS_ACTION_VALIDATE_LAYER("assets.action.validateLayer"),
|
||||
ASSETS_ACTION_ACCEPT_LAYER("assets.action.acceptLayer"),
|
||||
ASSETS_ACTION_DELETE("assets.action.delete"),
|
||||
ASSETS_ACTION_INCLUDE_IN_BUILD("assets.action.includeInBuild"),
|
||||
ASSETS_ACTION_EXCLUDE_FROM_BUILD("assets.action.excludeFromBuild"),
|
||||
ASSETS_ACTION_RELOCATE("assets.action.relocate"),
|
||||
ASSETS_ACTION_REMOVE("assets.action.remove"),
|
||||
ASSETS_DELETE_DIALOG_TITLE("assets.deleteDialog.title"),
|
||||
ASSETS_DELETE_DIALOG_DESCRIPTION("assets.deleteDialog.description"),
|
||||
ASSETS_DELETE_DIALOG_PROMPT("assets.deleteDialog.prompt"),
|
||||
ASSETS_DELETE_DIALOG_NOTE("assets.deleteDialog.note"),
|
||||
ASSETS_DELETE_DIALOG_CONFIRM("assets.deleteDialog.confirm"),
|
||||
ASSETS_MUTATION_PREVIEW_TITLE("assets.mutation.previewTitle"),
|
||||
ASSETS_MUTATION_SECTION_CHANGES("assets.mutation.section.changes"),
|
||||
ASSETS_MUTATION_SECTION_AFFECTED_ASSET("assets.mutation.section.affectedAsset"),
|
||||
ASSETS_MUTATION_SECTION_REGISTRY_IMPACT("assets.mutation.section.registryImpact"),
|
||||
ASSETS_MUTATION_SECTION_WORKSPACE_IMPACT("assets.mutation.section.workspaceImpact"),
|
||||
ASSETS_MUTATION_SECTION_BLOCKERS("assets.mutation.section.blockers"),
|
||||
ASSETS_MUTATION_SECTION_WARNINGS("assets.mutation.section.warnings"),
|
||||
ASSETS_MUTATION_SECTION_SAFE_FIXES("assets.mutation.section.safeFixes"),
|
||||
ASSETS_MUTATION_EMPTY_CHANGES("assets.mutation.empty.changes"),
|
||||
ASSETS_MUTATION_EMPTY_REGISTRY_IMPACT("assets.mutation.empty.registryImpact"),
|
||||
ASSETS_MUTATION_EMPTY_WORKSPACE_IMPACT("assets.mutation.empty.workspaceImpact"),
|
||||
ASSETS_MUTATION_EMPTY_BLOCKERS("assets.mutation.empty.blockers"),
|
||||
ASSETS_MUTATION_EMPTY_WARNINGS("assets.mutation.empty.warnings"),
|
||||
ASSETS_MUTATION_EMPTY_SAFE_FIXES("assets.mutation.empty.safeFixes"),
|
||||
ASSETS_MUTATION_CANCEL("assets.mutation.cancel"),
|
||||
ASSETS_MUTATION_APPLY("assets.mutation.apply"),
|
||||
ASSETS_MUTATION_CONFIRM_TITLE("assets.mutation.confirm.title"),
|
||||
ASSETS_MUTATION_CONFIRM_HEADER("assets.mutation.confirm.header"),
|
||||
FORM_ACTION_CHANGE("form.action.change"),
|
||||
FORM_ACTION_APPLY("form.action.apply"),
|
||||
FORM_ACTION_RESET("form.action.reset"),
|
||||
FORM_ACTION_CANCEL("form.action.cancel"),
|
||||
ASSETS_LABEL_NAME("assets.label.name"),
|
||||
ASSETS_LABEL_REGISTRATION("assets.label.registration"),
|
||||
ASSETS_LABEL_BUILD_PARTICIPATION("assets.label.buildParticipation"),
|
||||
ASSETS_LABEL_ASSET_ID("assets.label.assetId"),
|
||||
ASSETS_LABEL_TYPE("assets.label.type"),
|
||||
ASSETS_LABEL_STUDIO_ROLE("assets.label.studioRole"),
|
||||
ASSETS_LABEL_SCENE_STATUS("assets.label.sceneStatus"),
|
||||
ASSETS_LABEL_SCENE_LAYERS("assets.label.sceneLayers"),
|
||||
ASSETS_LABEL_SCENE_DIMENSIONS("assets.label.sceneDimensions"),
|
||||
ASSETS_LABEL_LAYER("assets.label.layer"),
|
||||
ASSETS_LABEL_LAYER_OVERVIEW("assets.label.layerOverview"),
|
||||
ASSETS_LABEL_TILEMAPS("assets.label.tilemaps"),
|
||||
ASSETS_LABEL_TILEMAP("assets.label.tilemap"),
|
||||
ASSETS_LABEL_TILESET("assets.label.tileset"),
|
||||
ASSETS_LABEL_PARALLAX("assets.label.parallax"),
|
||||
ASSETS_LABEL_DEFAULT_PALETTE("assets.label.defaultPalette"),
|
||||
ASSETS_LABEL_SUPPORT_FILE("assets.label.supportFile"),
|
||||
ASSETS_LABEL_USE_LAYER("assets.label.useLayer"),
|
||||
ASSETS_VALUE_NOT_CONFIGURED("assets.value.notConfigured"),
|
||||
ASSETS_VALUE_LAYER_OVERVIEW_PENDING("assets.value.layerOverviewPending"),
|
||||
ASSETS_TYPE_GLYPH_BANK("assets.type.glyphBank"),
|
||||
ASSETS_TYPE_SCENE_BANK("assets.type.sceneBank"),
|
||||
ASSETS_TYPE_PALETTE_BANK("assets.type.paletteBank"),
|
||||
ASSETS_TYPE_SOUND_BANK("assets.type.soundBank"),
|
||||
ASSETS_TYPE_UNKNOWN("assets.type.unknown"),
|
||||
ASSETS_SPECIALIZATION_NONE("assets.specialization.none"),
|
||||
ASSETS_SPECIALIZATION_TILESET("assets.specialization.tileset"),
|
||||
ASSETS_SPECIALIZATION_SPRITES("assets.specialization.sprites"),
|
||||
ASSETS_SPECIALIZATION_UI("assets.specialization.ui"),
|
||||
ASSETS_SCENE_STATUS_PENDING_VALIDATION("assets.sceneStatus.pendingValidation"),
|
||||
ASSETS_SCENE_STATUS_VALIDATED_PENDING_ACCEPTANCE("assets.sceneStatus.validatedPendingAcceptance"),
|
||||
ASSETS_SCENE_STATUS_READY("assets.sceneStatus.ready"),
|
||||
ASSETS_SCENE_STATUS_VALIDATION_FAILED("assets.sceneStatus.validationFailed"),
|
||||
ASSETS_LABEL_LOCATION("assets.label.location"),
|
||||
ASSETS_LABEL_BANK("assets.label.bank"),
|
||||
ASSETS_LABEL_TARGET_LOCATION("assets.label.targetLocation"),
|
||||
ASSETS_LABEL_FORMAT("assets.label.format"),
|
||||
ASSETS_LABEL_CODEC("assets.label.codec"),
|
||||
ASSETS_LABEL_PRELOAD("assets.label.preload"),
|
||||
ASSETS_VALUE_REGISTERED("assets.value.registered"),
|
||||
ASSETS_VALUE_UNREGISTERED("assets.value.unregistered"),
|
||||
ASSETS_VALUE_INCLUDED("assets.value.included"),
|
||||
ASSETS_VALUE_EXCLUDED("assets.value.excluded"),
|
||||
ASSETS_VALUE_YES("assets.value.yes"),
|
||||
ASSETS_VALUE_NO("assets.value.no"),
|
||||
ASSETS_PROGRESS_IDLE("assets.progress.idle"),
|
||||
ASSETS_PROGRESS_REFRESHING("assets.progress.refreshing"),
|
||||
ASSETS_PROGRESS_LOADING_DETAILS("assets.progress.loadingDetails"),
|
||||
ASSETS_LOGS_TITLE("assets.logs.title"),
|
||||
ASSETS_DIAGNOSTICS_EMPTY("assets.diagnostics.empty"),
|
||||
ASSETS_DIAGNOSTICS_DIALOG_TITLE("assets.diagnostics.dialog.title"),
|
||||
ASSETS_DIAGNOSTICS_DIALOG_SUMMARY("assets.diagnostics.dialog.summary"),
|
||||
ASSETS_DIAGNOSTICS_LABEL_CATEGORY("assets.diagnostics.label.category"),
|
||||
ASSETS_DIAGNOSTICS_LABEL_EVIDENCE("assets.diagnostics.label.evidence"),
|
||||
ASSETS_DIAGNOSTICS_LABEL_BLOCKING("assets.diagnostics.label.blocking"),
|
||||
ASSETS_PREVIEW_EMPTY("assets.preview.empty"),
|
||||
ASSETS_PREVIEW_ZOOM("assets.preview.zoom"),
|
||||
ASSETS_PREVIEW_TEXT_ERROR("assets.preview.textError"),
|
||||
ASSETS_PREVIEW_IMAGE_ERROR("assets.preview.imageError"),
|
||||
ASSETS_PREVIEW_AUDIO_PLACEHOLDER("assets.preview.audioPlaceholder"),
|
||||
ASSETS_PREVIEW_GENERIC_PLACEHOLDER("assets.preview.genericPlaceholder"),
|
||||
ACTIVITY_PROGRESS_IDLE("activity.progress.idle"),
|
||||
ACTIVITY_PROGRESS_ASSETS_REFRESH("activity.progress.assetsRefresh"),
|
||||
ASSETS_SUMMARY_LOADING("assets.summary.loading"),
|
||||
ASSETS_SUMMARY_EMPTY("assets.summary.empty"),
|
||||
ASSETS_SUMMARY_READY("assets.summary.ready"),
|
||||
ASSETS_SUMMARY_ERROR("assets.summary.error"),
|
||||
ASSETS_DETAILS_LOADING("assets.details.loading"),
|
||||
ASSETS_DETAILS_EMPTY("assets.details.empty"),
|
||||
ASSETS_DETAILS_READY("assets.details.ready"),
|
||||
ASSETS_DETAILS_NO_SELECTION("assets.details.noSelection"),
|
||||
ASSETS_DETAILS_BANK_COMPOSITION_AVAILABLE("assets.details.bankComposition.available"),
|
||||
ASSETS_DETAILS_BANK_COMPOSITION_SELECTED("assets.details.bankComposition.selected"),
|
||||
ASSETS_DETAILS_BANK_COMPOSITION_READONLY_HINT("assets.details.bankComposition.readonlyHint"),
|
||||
ASSETS_DETAILS_BANK_COMPOSITION_EDITING_HINT("assets.details.bankComposition.editingHint"),
|
||||
ASSETS_PALETTE_OVERHAULING_AVAILABLE("assets.paletteOverhauling.available"),
|
||||
ASSETS_PALETTE_OVERHAULING_SELECTED("assets.paletteOverhauling.selected"),
|
||||
ASSETS_PALETTE_OVERHAULING_TILE_SELECTOR("assets.paletteOverhauling.tileSelector"),
|
||||
ASSETS_PALETTE_OVERHAULING_APPLIED_PALETTE("assets.paletteOverhauling.appliedPalette"),
|
||||
ASSETS_PALETTE_OVERHAULING_PREVIEW_EMPTY("assets.paletteOverhauling.previewEmpty"),
|
||||
ASSETS_PALETTE_WIZARD_CREATE_TITLE("assets.paletteWizard.createTitle"),
|
||||
ASSETS_PALETTE_WIZARD_UPDATE_TITLE("assets.paletteWizard.updateTitle"),
|
||||
ASSETS_PALETTE_WIZARD_NAME("assets.paletteWizard.name"),
|
||||
ASSETS_PALETTE_WIZARD_SCHEMA("assets.paletteWizard.schema"),
|
||||
ASSETS_PALETTE_WIZARD_ORIGINAL("assets.paletteWizard.original"),
|
||||
ASSETS_PALETTE_WIZARD_EDITABLE("assets.paletteWizard.editable"),
|
||||
ASSETS_PALETTE_WIZARD_APPLY_COLOR("assets.paletteWizard.applyColor"),
|
||||
ASSETS_PALETTE_WIZARD_DUPLICATE("assets.paletteWizard.duplicate"),
|
||||
ASSETS_PALETTE_WIZARD_READY("assets.paletteWizard.ready"),
|
||||
ASSETS_COLOR_SCHEMA_EMPTY("assets.colorSchema.empty"),
|
||||
ASSETS_COLOR_SCHEMA_SUMMARY("assets.colorSchema.summary"),
|
||||
ASSETS_COLOR_SCHEMA_REMOVE_BLOCKED("assets.colorSchema.removeBlocked"),
|
||||
ASSETS_COLOR_SCHEMA_DIALOG_AVAILABLE_TILES("assets.colorSchema.dialog.availableTiles"),
|
||||
ASSETS_COLOR_SCHEMA_DIALOG_ASSIGNED_TILES("assets.colorSchema.dialog.assignedTiles"),
|
||||
ASSETS_COLOR_SCHEMA_DIALOG_COLOR_COUNT("assets.colorSchema.dialog.colorCount"),
|
||||
ASSETS_COLOR_SCHEMA_DIALOG_TOO_MANY_COLORS("assets.colorSchema.dialog.tooManyColors"),
|
||||
ASSETS_DETAILS_CODEC_CONFIGURATION_EMPTY("assets.details.codecConfiguration.empty"),
|
||||
ASSETS_DETAILS_METADATA_EMPTY("assets.details.metadata.empty"),
|
||||
ASSETS_ADD_WIZARD_TITLE("assets.addWizard.title"),
|
||||
ASSETS_ADD_WIZARD_DESCRIPTION("assets.addWizard.description"),
|
||||
ASSETS_ADD_WIZARD_STEP_ROOT_TITLE("assets.addWizard.step.root.title"),
|
||||
ASSETS_ADD_WIZARD_STEP_ROOT_DESCRIPTION("assets.addWizard.step.root.description"),
|
||||
ASSETS_ADD_WIZARD_STEP_DETAILS_TITLE("assets.addWizard.step.details.title"),
|
||||
ASSETS_ADD_WIZARD_STEP_DETAILS_DESCRIPTION("assets.addWizard.step.details.description"),
|
||||
ASSETS_ADD_WIZARD_STEP_SUMMARY_TITLE("assets.addWizard.step.summary.title"),
|
||||
ASSETS_ADD_WIZARD_STEP_SUMMARY_DESCRIPTION("assets.addWizard.step.summary.description"),
|
||||
ASSETS_ADD_WIZARD_LABEL_NAME("assets.addWizard.label.name"),
|
||||
ASSETS_ADD_WIZARD_LABEL_ROOT("assets.addWizard.label.root"),
|
||||
ASSETS_ADD_WIZARD_LABEL_TYPE("assets.addWizard.label.type"),
|
||||
ASSETS_ADD_WIZARD_LABEL_SPECIALIZATION("assets.addWizard.label.specialization"),
|
||||
ASSETS_ADD_WIZARD_LABEL_FORMAT("assets.addWizard.label.format"),
|
||||
ASSETS_ADD_WIZARD_LABEL_CODEC("assets.addWizard.label.codec"),
|
||||
ASSETS_ADD_WIZARD_LABEL_PRELOAD("assets.addWizard.label.preload"),
|
||||
ASSETS_ADD_WIZARD_PROMPT_TYPE("assets.addWizard.prompt.type"),
|
||||
ASSETS_ADD_WIZARD_PROMPT_SPECIALIZATION("assets.addWizard.prompt.specialization"),
|
||||
ASSETS_ADD_WIZARD_PROMPT_FORMAT("assets.addWizard.prompt.format"),
|
||||
ASSETS_ADD_WIZARD_PROMPT_CODEC("assets.addWizard.prompt.codec"),
|
||||
ASSETS_ADD_WIZARD_ASSETS_ROOT_HINT("assets.addWizard.assetsRootHint"),
|
||||
ASSETS_ADD_WIZARD_BROWSE_TITLE("assets.addWizard.browse.title"),
|
||||
ASSETS_ADD_WIZARD_NOTE("assets.addWizard.note"),
|
||||
ASSETS_ADD_WIZARD_BUTTON_CREATE("assets.addWizard.button.create"),
|
||||
ASSETS_ADD_WIZARD_ERROR_NAME("assets.addWizard.error.name"),
|
||||
ASSETS_ADD_WIZARD_ERROR_ROOT("assets.addWizard.error.root"),
|
||||
ASSETS_ADD_WIZARD_ERROR_ROOT_RELATIVE("assets.addWizard.error.rootRelative"),
|
||||
ASSETS_ADD_WIZARD_ERROR_ROOT_OUTSIDE_ASSETS("assets.addWizard.error.rootOutsideAssets"),
|
||||
ASSETS_ADD_WIZARD_ERROR_ROOT_ALREADY_ASSET("assets.addWizard.error.rootAlreadyAsset"),
|
||||
ASSETS_ADD_WIZARD_ERROR_TYPE("assets.addWizard.error.type"),
|
||||
ASSETS_ADD_WIZARD_ERROR_SPECIALIZATION("assets.addWizard.error.specialization"),
|
||||
ASSETS_ADD_WIZARD_ERROR_FORMAT("assets.addWizard.error.format"),
|
||||
ASSETS_ADD_WIZARD_ERROR_CODEC("assets.addWizard.error.codec"),
|
||||
ASSETS_ADD_WIZARD_ERROR_UNSUPPORTED_COMBINATION("assets.addWizard.error.unsupportedCombination"),
|
||||
ASSETS_RELOCATE_WIZARD_TITLE("assets.relocateWizard.title"),
|
||||
ASSETS_RELOCATE_WIZARD_DESCRIPTION("assets.relocateWizard.description"),
|
||||
ASSETS_RELOCATE_WIZARD_STEP_DESTINATION_TITLE("assets.relocateWizard.step.destination.title"),
|
||||
ASSETS_RELOCATE_WIZARD_STEP_DESTINATION_DESCRIPTION("assets.relocateWizard.step.destination.description"),
|
||||
ASSETS_RELOCATE_WIZARD_STEP_SUMMARY_TITLE("assets.relocateWizard.step.summary.title"),
|
||||
ASSETS_RELOCATE_WIZARD_STEP_SUMMARY_DESCRIPTION("assets.relocateWizard.step.summary.description"),
|
||||
ASSETS_RELOCATE_WIZARD_STEP_WAITING_TITLE("assets.relocateWizard.step.waiting.title"),
|
||||
ASSETS_RELOCATE_WIZARD_STEP_WAITING_DESCRIPTION("assets.relocateWizard.step.waiting.description"),
|
||||
ASSETS_RELOCATE_WIZARD_LABEL_CURRENT_ROOT("assets.relocateWizard.label.currentRoot"),
|
||||
ASSETS_RELOCATE_WIZARD_LABEL_DESTINATION_PARENT("assets.relocateWizard.label.destinationParent"),
|
||||
ASSETS_RELOCATE_WIZARD_LABEL_DESTINATION_NAME("assets.relocateWizard.label.destinationName"),
|
||||
ASSETS_RELOCATE_WIZARD_LABEL_TARGET_ROOT("assets.relocateWizard.label.targetRoot"),
|
||||
ASSETS_RELOCATE_WIZARD_PROMPT_DESTINATION_NAME("assets.relocateWizard.prompt.destinationName"),
|
||||
ASSETS_RELOCATE_WIZARD_ASSETS_ROOT_HINT("assets.relocateWizard.assetsRootHint"),
|
||||
ASSETS_RELOCATE_WIZARD_BROWSE_TITLE("assets.relocateWizard.browse.title"),
|
||||
ASSETS_RELOCATE_WIZARD_NOTE("assets.relocateWizard.note"),
|
||||
ASSETS_RELOCATE_WIZARD_BUTTON_CONFIRM("assets.relocateWizard.button.confirm"),
|
||||
ASSETS_RELOCATE_WIZARD_BUTTON_PREVIEW("assets.relocateWizard.button.preview"),
|
||||
ASSETS_RELOCATE_WIZARD_ERROR_PARENT("assets.relocateWizard.error.parent"),
|
||||
ASSETS_RELOCATE_WIZARD_ERROR_NAME("assets.relocateWizard.error.name"),
|
||||
ASSETS_RELOCATE_WIZARD_ERROR_OUTSIDE_ASSETS("assets.relocateWizard.error.outsideAssets"),
|
||||
ASSETS_RELOCATE_WIZARD_ERROR_TARGET_ALREADY_ASSET("assets.relocateWizard.error.targetAlreadyAsset"),
|
||||
ASSETS_RELOCATE_WIZARD_ERROR_TARGET_SAME("assets.relocateWizard.error.targetSame"),
|
||||
ASSETS_PACK_WIZARD_TITLE("assets.packWizard.title"),
|
||||
ASSETS_PACK_WIZARD_STEP_DEEP_SYNC_TITLE("assets.packWizard.step.deepSync.title"),
|
||||
ASSETS_PACK_WIZARD_STEP_DEEP_SYNC_DESCRIPTION("assets.packWizard.step.deepSync.description"),
|
||||
ASSETS_PACK_WIZARD_STEP_DEEP_SYNC_WAITING_TITLE("assets.packWizard.step.deepSyncWaiting.title"),
|
||||
ASSETS_PACK_WIZARD_STEP_DEEP_SYNC_WAITING_DESCRIPTION("assets.packWizard.step.deepSyncWaiting.description"),
|
||||
ASSETS_PACK_WIZARD_STEP_SUMMARY_TITLE("assets.packWizard.step.summary.title"),
|
||||
ASSETS_PACK_WIZARD_STEP_SUMMARY_DESCRIPTION("assets.packWizard.step.summary.description"),
|
||||
ASSETS_PACK_WIZARD_STEP_VALIDATION_TITLE("assets.packWizard.step.validation.title"),
|
||||
ASSETS_PACK_WIZARD_STEP_VALIDATION_DESCRIPTION("assets.packWizard.step.validation.description"),
|
||||
ASSETS_PACK_WIZARD_STEP_PACKING_TITLE("assets.packWizard.step.packing.title"),
|
||||
ASSETS_PACK_WIZARD_STEP_PACKING_DESCRIPTION("assets.packWizard.step.packing.description"),
|
||||
ASSETS_PACK_WIZARD_STEP_RESULT_TITLE("assets.packWizard.step.result.title"),
|
||||
ASSETS_PACK_WIZARD_STEP_RESULT_DESCRIPTION("assets.packWizard.step.result.description"),
|
||||
ASSETS_PACK_WIZARD_BUTTON_VALIDATE("assets.packWizard.button.validate"),
|
||||
ASSETS_PACK_WIZARD_BUTTON_PACK("assets.packWizard.button.pack"),
|
||||
ASSETS_PACK_WIZARD_BUTTON_CLOSE("assets.packWizard.button.close"),
|
||||
ASSETS_PACK_WIZARD_BUTTON_COPY_FAILURES("assets.packWizard.button.copyFailures"),
|
||||
ASSETS_PACK_WIZARD_LOADING_SUMMARY("assets.packWizard.loading.summary"),
|
||||
ASSETS_PACK_WIZARD_LOADING_DEEP_SYNC("assets.packWizard.loading.deepSync"),
|
||||
ASSETS_PACK_WIZARD_LOADING_VALIDATION("assets.packWizard.loading.validation"),
|
||||
ASSETS_PACK_WIZARD_LOADING_PACKING("assets.packWizard.loading.packing"),
|
||||
ASSETS_PACK_WIZARD_LABEL_CANONICAL_ARTIFACT("assets.packWizard.label.canonicalArtifact"),
|
||||
ASSETS_PACK_WIZARD_LABEL_INCLUDED_ASSETS("assets.packWizard.label.includedAssets"),
|
||||
ASSETS_PACK_WIZARD_LABEL_OUTSIDE_BUILD_SET("assets.packWizard.label.outsideBuildSet"),
|
||||
ASSETS_PACK_WIZARD_LABEL_TOTAL_IN_SCOPE("assets.packWizard.label.totalInScope"),
|
||||
ASSETS_PACK_WIZARD_LABEL_VALID_ASSETS("assets.packWizard.label.validAssets"),
|
||||
ASSETS_PACK_WIZARD_LABEL_BLOCKED_ASSETS("assets.packWizard.label.blockedAssets"),
|
||||
ASSETS_PACK_WIZARD_LABEL_STATUS("assets.packWizard.label.status"),
|
||||
ASSETS_PACK_WIZARD_LABEL_PACKED_ASSETS("assets.packWizard.label.packedAssets"),
|
||||
ASSETS_PACK_WIZARD_LABEL_ELAPSED("assets.packWizard.label.elapsed"),
|
||||
ASSETS_PACK_WIZARD_LABEL_EMITTED_ARTIFACTS("assets.packWizard.label.emittedArtifacts"),
|
||||
ASSETS_PACK_WIZARD_LABEL_MIN_ARTIFACTS("assets.packWizard.label.minArtifacts"),
|
||||
ASSETS_PACK_WIZARD_LABEL_MAX_ARTIFACTS("assets.packWizard.label.maxArtifacts"),
|
||||
ASSETS_PACK_WIZARD_LABEL_LAST_MODIFIED("assets.packWizard.label.lastModified"),
|
||||
ASSETS_PACK_WIZARD_STATUS_READY("assets.packWizard.status.ready"),
|
||||
ASSETS_PACK_WIZARD_STATUS_BLOCKED("assets.packWizard.status.blocked"),
|
||||
ASSETS_PACK_WIZARD_STATUS_RUNNING("assets.packWizard.status.running"),
|
||||
ASSETS_PACK_WIZARD_STATUS_FINISHED("assets.packWizard.status.finished"),
|
||||
ASSETS_PACK_WIZARD_VALIDATION_EMPTY("assets.packWizard.validation.empty"),
|
||||
ASSETS_PACK_WIZARD_RESULT_NO_ARTIFACTS("assets.packWizard.result.noArtifacts"),
|
||||
ASSETS_PACK_WIZARD_RESULT_COPY_FAILURES_HINT("assets.packWizard.result.copyFailuresHint"),
|
||||
ASSETS_PACK_WIZARD_DEEP_SYNC_NOTE("assets.packWizard.deepSync.note"),
|
||||
ASSETS_PACK_WIZARD_DEEP_SYNC_COMPLETED("assets.packWizard.deepSync.completed"),
|
||||
ASSETS_PACK_WIZARD_ERROR_SUMMARY("assets.packWizard.error.summary"),
|
||||
ASSETS_PACK_WIZARD_ERROR_DEEP_SYNC("assets.packWizard.error.deepSync"),
|
||||
ASSETS_PACK_WIZARD_ERROR_VALIDATION("assets.packWizard.error.validation"),
|
||||
ASSETS_PACK_WIZARD_ERROR_PACK("assets.packWizard.error.pack"),
|
||||
WORKSPACE_DEBUG("workspace.debug"),
|
||||
|
||||
|
||||
;
|
||||
|
||||
@Getter
|
||||
private final String key;
|
||||
|
||||
I18n(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
package p.studio.ui.javafx.utilities.i18n;
|
||||
|
||||
import javafx.beans.binding.Bindings;
|
||||
import javafx.beans.binding.StringBinding;
|
||||
import javafx.beans.property.ObjectProperty;
|
||||
import javafx.beans.property.SimpleObjectProperty;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Locale;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
public final class I18nService {
|
||||
private final ObjectProperty<Locale> locale = new SimpleObjectProperty<>(Locale.ENGLISH);
|
||||
|
||||
public ObjectProperty<Locale> localeProperty() { return locale; }
|
||||
public Locale getLocale() { return locale.get(); }
|
||||
public void setLocale(Locale l) { locale.set(l); }
|
||||
|
||||
private ResourceBundle bundle(Locale l) {
|
||||
return ResourceBundle.getBundle("i18n.messages", l);
|
||||
}
|
||||
|
||||
public String text(I18n i18n) {
|
||||
return bundle(getLocale()).getString(i18n.getKey());
|
||||
}
|
||||
|
||||
public String format(I18n i18n, Object... args) {
|
||||
return new MessageFormat(text(i18n), getLocale()).format(args);
|
||||
}
|
||||
|
||||
public StringBinding bind(I18n key) {
|
||||
return Bindings.createStringBinding(
|
||||
() -> text(key),
|
||||
locale
|
||||
);
|
||||
}
|
||||
|
||||
public StringBinding bind(I18n key, Object... args) {
|
||||
return Bindings.createStringBinding(
|
||||
() -> format(key, args),
|
||||
locale
|
||||
);
|
||||
}
|
||||
}
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
package p.studio.ui.javafx.utilities.logspane;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.scene.control.TextArea;
|
||||
import javafx.scene.control.TitledPane;
|
||||
import p.studio.ui.javafx.controls.WorkspaceDockPane;
|
||||
import p.studio.ui.javafx.controls.lifecycle.StudioControlLifecycle;
|
||||
import p.studio.ui.javafx.controls.lifecycle.StudioControlLifecycleSupport;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public abstract class LogsPane extends WorkspaceDockPane implements StudioControlLifecycle {
|
||||
private static final double COLLAPSED_HEIGHT = 34.0;
|
||||
private static final double MINIMUM_EXPANDED_HEIGHT = 120.0;
|
||||
private static final double DEFAULT_EXPANDED_HEIGHT = 180.0;
|
||||
|
||||
private final TextArea textArea;
|
||||
|
||||
protected LogsPane(
|
||||
ObservableValue<String> titleBinding,
|
||||
String workspace) {
|
||||
this(titleBinding, workspace, true);
|
||||
}
|
||||
|
||||
protected LogsPane(
|
||||
ObservableValue<String> titleBinding,
|
||||
String workspace,
|
||||
boolean installLifecycle) {
|
||||
super(
|
||||
Objects.requireNonNull(titleBinding, "titleBinding"),
|
||||
COLLAPSED_HEIGHT,
|
||||
MINIMUM_EXPANDED_HEIGHT,
|
||||
DEFAULT_EXPANDED_HEIGHT,
|
||||
true,
|
||||
"%s-workspace-logs-pane".formatted(normalizeWorkspaceName(workspace)));
|
||||
|
||||
final String workspaceName = Objects.requireNonNull(workspace, "workspace").trim();
|
||||
if (workspaceName.isBlank()) {
|
||||
throw new IllegalArgumentException("workspace must not be blank");
|
||||
}
|
||||
|
||||
this.textArea = new TextArea();
|
||||
textArea.setEditable(false);
|
||||
textArea.setWrapText(true);
|
||||
textArea.setPrefRowCount(8);
|
||||
textArea.getStyleClass().add("%s-workspace-logs".formatted(workspaceName));
|
||||
|
||||
setDockContent(textArea);
|
||||
if (installLifecycle) {
|
||||
StudioControlLifecycleSupport.install(this, this);
|
||||
}
|
||||
}
|
||||
|
||||
public final TitledPane getPane() {
|
||||
return this;
|
||||
}
|
||||
|
||||
protected final void appendLine(String line) {
|
||||
final String normalized = Objects.requireNonNullElse(line, "").stripTrailing();
|
||||
if (normalized.isBlank()) {
|
||||
return;
|
||||
}
|
||||
Platform.runLater(() -> textArea.appendText(normalized + System.lineSeparator()));
|
||||
}
|
||||
|
||||
protected final void clearLogs() {
|
||||
Platform.runLater(textArea::clear);
|
||||
}
|
||||
|
||||
private static String normalizeWorkspaceName(final String workspace) {
|
||||
final String workspaceName = Objects.requireNonNull(workspace, "workspace").trim();
|
||||
if (workspaceName.isBlank()) {
|
||||
throw new IllegalArgumentException("workspace must not be blank");
|
||||
}
|
||||
return workspaceName;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
package p.studio.ui.javafx.window;
|
||||
|
||||
import javafx.scene.layout.BorderPane;
|
||||
import p.studio.api.assets.AssetCatalog;
|
||||
import p.studio.api.assets.AssetCommands;
|
||||
import p.studio.api.assets.AssetPacking;
|
||||
import p.studio.api.assets.AssetDetails;
|
||||
import p.studio.api.assets.AssetCreationCatalog;
|
||||
import p.studio.api.assets.AssetWorkspaceStorage;
|
||||
import p.studio.api.assets.AssetCapacityPolicy;
|
||||
import p.studio.api.assets.schema.AssetColorSchemaFactory;
|
||||
import p.studio.api.assets.bank.AssetBankCompositionSessionFactory;
|
||||
import p.studio.api.assets.metadata.AssetMetadataService;
|
||||
import p.studio.api.assets.scene.SceneBankWorkflow;
|
||||
import p.studio.api.assets.tiled.TiledAssetService;
|
||||
import p.studio.ui.javafx.controls.shell.*;
|
||||
import p.studio.api.execution.ExecutionController;
|
||||
import p.studio.api.execution.ExecutionControllerFactory;
|
||||
import p.studio.api.project.ProjectLocalStudioSetup;
|
||||
import p.studio.ui.javafx.events.StudioWorkspaceSelectedEvent;
|
||||
import p.studio.api.project.ProjectLocalStudioState;
|
||||
import p.studio.api.project.ProjectReference;
|
||||
import p.studio.api.preferences.ProjectActivityHistoryStore;
|
||||
import p.studio.api.shipper.Shipper;
|
||||
import p.studio.api.session.ProjectSession;
|
||||
import p.studio.ui.javafx.utilities.i18n.I18n;
|
||||
import p.studio.ui.javafx.utilities.i18n.I18nService;
|
||||
import p.studio.ui.javafx.events.StudioEventBus;
|
||||
import p.studio.ui.javafx.workspaces.WorkspaceHost;
|
||||
import p.studio.ui.javafx.workspaces.WorkspaceId;
|
||||
import p.studio.ui.javafx.workspaces.assets.AssetWorkspace;
|
||||
import p.studio.ui.javafx.workspaces.builder.ShipperWorkspace;
|
||||
import p.studio.ui.javafx.workspaces.debug.DebugWorkspace;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public final class MainView extends BorderPane {
|
||||
private final WorkspaceHost host = new WorkspaceHost();
|
||||
private final ProjectReference projectReference;
|
||||
private final ProjectSession projectSession;
|
||||
private final AssetWorkspace assetWorkspace;
|
||||
private final StudioEventBus eventBus;
|
||||
private final StudioWorkspaceRailControl<WorkspaceId> workspaceRail;
|
||||
private final ExecutionController playStopCoordinator;
|
||||
private boolean initializing;
|
||||
private boolean workspaceLifecycleInitialized;
|
||||
|
||||
public MainView(final ProjectSession projectSession, final Shipper shipper,
|
||||
final ExecutionControllerFactory executionControllerFactory,
|
||||
final I18nService i18n,
|
||||
final StudioEventBus eventBus,
|
||||
final java.util.concurrent.Executor executor,
|
||||
final p.studio.ui.javafx.utilities.ThemeService theme,
|
||||
final AssetCatalog assetCatalog,
|
||||
final AssetCommands assetCommands,
|
||||
final AssetPacking assetPacking,
|
||||
final AssetDetails assetDetails,
|
||||
final AssetCreationCatalog assetCreationCatalog,
|
||||
final AssetMetadataService assetMetadataService,
|
||||
final AssetWorkspaceStorage assetWorkspaceStorage,
|
||||
final AssetCapacityPolicy assetCapacityPolicy,
|
||||
final AssetBankCompositionSessionFactory bankCompositionSessionFactory,
|
||||
final AssetColorSchemaFactory assetColorSchemaFactory,
|
||||
final TiledAssetService tiledAssetService,
|
||||
final SceneBankWorkflow sceneBankWorkflow,
|
||||
final ProjectActivityHistoryStore activityHistoryStore) {
|
||||
initializing = true;
|
||||
this.eventBus = eventBus;
|
||||
this.projectSession = projectSession;
|
||||
this.projectReference = projectSession.projectReference();
|
||||
final ProjectLocalStudioState persistedState = projectSession.projectLocalStudioState();
|
||||
final ProjectLocalStudioSetup projectSetup = projectSession.projectLocalStudioSetup();
|
||||
final var menuBar = new StudioShellMenuBarControl(i18n);
|
||||
playStopCoordinator = executionControllerFactory.create(
|
||||
projectReference,
|
||||
projectSetup,
|
||||
projectSession.executionSession());
|
||||
final var runSurface = new StudioRunSurfaceControl(
|
||||
projectSession.executionSession(),
|
||||
() -> {
|
||||
selectWorkspace(WorkspaceId.DEBUG);
|
||||
playStopCoordinator.play();
|
||||
},
|
||||
playStopCoordinator::stop,
|
||||
i18n);
|
||||
setTop(new StudioShellTopBarControl(menuBar));
|
||||
|
||||
assetWorkspace = new AssetWorkspace(projectReference, eventBus, i18n, executor, theme,
|
||||
assetCatalog, assetCommands, assetPacking, assetDetails, assetCreationCatalog, assetMetadataService,
|
||||
assetWorkspaceStorage, assetCapacityPolicy, bankCompositionSessionFactory, assetColorSchemaFactory,
|
||||
tiledAssetService, sceneBankWorkflow);
|
||||
host.register(assetWorkspace);
|
||||
assetWorkspace.restoreProjectLocalState(persistedState);
|
||||
assetWorkspace.setStateChangedAction(this::persistProjectLocalState);
|
||||
host.register(new DebugWorkspace(projectReference, projectSession.executionSession(), i18n, eventBus));
|
||||
host.register(new ShipperWorkspace(projectReference, shipper, i18n, eventBus));
|
||||
|
||||
workspaceRail = new StudioWorkspaceRailControl<>(
|
||||
List.of(
|
||||
new StudioWorkspaceRailItem<>(WorkspaceId.ASSETS, "📦", i18n.bind(I18n.WORKSPACE_ASSETS)),
|
||||
new StudioWorkspaceRailItem<>(WorkspaceId.DEBUG, "🎮", i18n.bind(I18n.WORKSPACE_DEBUG)),
|
||||
new StudioWorkspaceRailItem<>(WorkspaceId.SHIPPER, "⚙️", i18n.bind(I18n.WORKSPACE_SHIPPER))
|
||||
),
|
||||
this::loadWorkspace);
|
||||
setLeft(workspaceRail);
|
||||
setCenter(host);
|
||||
setRight(new StudioRightUtilityPanelControl(
|
||||
runSurface,
|
||||
i18n.bind(I18n.SHELL_ACTIVITY),
|
||||
new StudioActivityFeedControl(projectReference, activityHistoryStore, i18n, eventBus)));
|
||||
|
||||
final WorkspaceId initialWorkspace = restoreInitialWorkspace(persistedState.openShellState());
|
||||
workspaceRail.select(initialWorkspace);
|
||||
loadWorkspace(initialWorkspace);
|
||||
workspaceLifecycleInitialized = true;
|
||||
initializing = false;
|
||||
}
|
||||
|
||||
public ProjectReference projectReference() {
|
||||
return projectReference;
|
||||
}
|
||||
|
||||
public ProjectSession projectSession() {
|
||||
return projectSession;
|
||||
}
|
||||
|
||||
public void persistProjectLocalState() {
|
||||
if (initializing) {
|
||||
return;
|
||||
}
|
||||
final WorkspaceId selectedWorkspace = host.getCurrentWorkspaceId() == null ? WorkspaceId.ASSETS : host.getCurrentWorkspaceId();
|
||||
final ProjectLocalStudioState current = projectSession.projectLocalStudioState();
|
||||
projectSession.replaceProjectLocalStudioState(
|
||||
current.withOpenShellState(new ProjectLocalStudioState.OpenShellState(selectedWorkspace.name()))
|
||||
.withShellLayout(new ProjectLocalStudioState.ShellLayout(
|
||||
assetWorkspace.captureLayoutState())));
|
||||
}
|
||||
|
||||
public void reapplyProjectLocalLayout() {
|
||||
assetWorkspace.reapplyPendingLayoutState();
|
||||
}
|
||||
|
||||
public void close() {
|
||||
playStopCoordinator.shutdown();
|
||||
persistProjectLocalState();
|
||||
host.deactivateCurrentWorkspace();
|
||||
}
|
||||
|
||||
private void loadWorkspace(WorkspaceId workspaceId) {
|
||||
host.change(workspaceId);
|
||||
if (workspaceLifecycleInitialized) {
|
||||
persistProjectLocalState();
|
||||
projectSession.saveProjectLocalStudioState();
|
||||
}
|
||||
eventBus.publish(new StudioWorkspaceSelectedEvent(workspaceId));
|
||||
}
|
||||
|
||||
private void selectWorkspace(final WorkspaceId workspaceId) {
|
||||
workspaceRail.select(workspaceId);
|
||||
loadWorkspace(workspaceId);
|
||||
}
|
||||
|
||||
private WorkspaceId restoreInitialWorkspace(final ProjectLocalStudioState.OpenShellState openShellState) {
|
||||
if (openShellState.selectedWorkspaceId() == null) {
|
||||
return WorkspaceId.ASSETS;
|
||||
}
|
||||
try {
|
||||
return WorkspaceId.valueOf(openShellState.selectedWorkspaceId());
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
return WorkspaceId.ASSETS;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+438
@@ -0,0 +1,438 @@
|
||||
package p.studio.ui.javafx.window;
|
||||
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.ComboBox;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.Priority;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.stage.DirectoryChooser;
|
||||
import javafx.stage.Modality;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.stage.Window;
|
||||
import p.studio.api.project.ProjectTarget;
|
||||
import p.studio.api.project.ProjectCreationRequest;
|
||||
import p.studio.api.project.ProjectCatalog;
|
||||
import p.studio.api.project.ProjectLanguageCatalog;
|
||||
import p.studio.api.project.ProjectLanguageTemplate;
|
||||
import p.studio.api.project.ProjectReference;
|
||||
import p.studio.ui.javafx.utilities.ThemeService;
|
||||
import p.studio.ui.javafx.utilities.i18n.I18n;
|
||||
import p.studio.ui.javafx.utilities.i18n.I18nService;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
public final class NewProjectWizard {
|
||||
private final ProjectCatalog projectCatalogService;
|
||||
private final ProjectLanguageCatalog projectLanguageCatalogService;
|
||||
private final I18nService i18n;
|
||||
private final ThemeService theme;
|
||||
private final Stage stage;
|
||||
private final AtomicReference<ProjectReference> result = new AtomicReference<>();
|
||||
private final Label stepTitle = new Label();
|
||||
private final Label stepDescription = new Label();
|
||||
private final VBox stepBody = new VBox(12);
|
||||
private final Label feedbackLabel = new Label();
|
||||
private final Button backButton = new Button();
|
||||
private final Button nextButton = new Button();
|
||||
private final Button createButton = new Button();
|
||||
private final TextField projectNameField = new TextField();
|
||||
private final TextField locationField = new TextField();
|
||||
private final TextField runtimePathField = new TextField();
|
||||
private final ComboBox<String> languageCombo = new ComboBox<>();
|
||||
private final ComboBox<ProjectLanguageTemplate.StdlibOption> stdlibCombo = new ComboBox<>();
|
||||
private final ComboBox<String> sourceRootCombo = new ComboBox<>();
|
||||
private final ComboBox<Integer> indentationWidthCombo = new ComboBox<>();
|
||||
private final Map<String, ProjectLanguageTemplate> languageTemplatesById = new LinkedHashMap<>();
|
||||
private int stepIndex = 0;
|
||||
|
||||
private NewProjectWizard(
|
||||
Window owner,
|
||||
ProjectCatalog projectCatalogService,
|
||||
ProjectLanguageCatalog projectLanguageCatalogService,
|
||||
I18nService i18n,
|
||||
ThemeService theme) {
|
||||
this.projectCatalogService = Objects.requireNonNull(projectCatalogService, "projectCatalogService");
|
||||
this.projectLanguageCatalogService = Objects.requireNonNull(projectLanguageCatalogService, "projectLanguageCatalogService");
|
||||
this.i18n = Objects.requireNonNull(i18n, "i18n");
|
||||
this.theme = Objects.requireNonNull(theme, "theme");
|
||||
this.stage = new Stage();
|
||||
stage.initOwner(owner);
|
||||
stage.initModality(Modality.WINDOW_MODAL);
|
||||
stage.setTitle(i18n.text(I18n.WIZARD_TITLE));
|
||||
stage.setScene(new Scene(buildRoot(), 700, 420));
|
||||
stage.getScene().getStylesheets().add(theme.getDefaultTheme());
|
||||
|
||||
projectNameField.promptTextProperty().bind(i18n.bind(I18n.LAUNCHER_PROJECT_NAME_PROMPT));
|
||||
locationField.setText(projectCatalogService.projectsRoot().toString());
|
||||
runtimePathField.promptTextProperty().bind(i18n.bind(I18n.WIZARD_RUNTIME_PROMPT));
|
||||
indentationWidthCombo.getItems().setAll(2, 4, 8);
|
||||
indentationWidthCombo.getSelectionModel().select(Integer.valueOf(4));
|
||||
initializeLanguageTemplates();
|
||||
|
||||
renderStep();
|
||||
}
|
||||
|
||||
public static Optional<ProjectReference> showAndWait(
|
||||
Window owner,
|
||||
ProjectCatalog projectCatalogService,
|
||||
ProjectLanguageCatalog projectLanguageCatalogService,
|
||||
I18nService i18n,
|
||||
ThemeService theme) {
|
||||
final NewProjectWizard wizard = new NewProjectWizard(owner, projectCatalogService, projectLanguageCatalogService, i18n, theme);
|
||||
wizard.stage.showAndWait();
|
||||
return Optional.ofNullable(wizard.result.get());
|
||||
}
|
||||
|
||||
private VBox buildRoot() {
|
||||
stepTitle.getStyleClass().add("studio-launcher-section-title");
|
||||
stepDescription.getStyleClass().add("studio-launcher-subtitle");
|
||||
feedbackLabel.getStyleClass().add("studio-launcher-feedback");
|
||||
feedbackLabel.setWrapText(true);
|
||||
|
||||
backButton.textProperty().bind(i18n.bind(I18n.WIZARD_BACK));
|
||||
backButton.getStyleClass().addAll("studio-button", "studio-button-secondary");
|
||||
backButton.setOnAction(ignored -> goBack());
|
||||
|
||||
nextButton.textProperty().bind(i18n.bind(I18n.WIZARD_NEXT));
|
||||
nextButton.getStyleClass().addAll("studio-button", "studio-button-primary");
|
||||
nextButton.setOnAction(ignored -> goNext());
|
||||
|
||||
createButton.textProperty().bind(i18n.bind(I18n.WIZARD_CREATE));
|
||||
createButton.getStyleClass().addAll("studio-button", "studio-button-primary");
|
||||
createButton.setOnAction(ignored -> finishCreate());
|
||||
|
||||
final Button cancelButton = new Button();
|
||||
cancelButton.textProperty().bind(i18n.bind(I18n.WIZARD_CANCEL));
|
||||
cancelButton.getStyleClass().addAll("studio-button", "studio-button-cancel");
|
||||
cancelButton.setOnAction(ignored -> stage.close());
|
||||
|
||||
final HBox actions = new HBox(12, backButton, nextButton, createButton, cancelButton);
|
||||
actions.setAlignment(Pos.CENTER_RIGHT);
|
||||
|
||||
final VBox root = new VBox(16, stepTitle, stepDescription, stepBody, feedbackLabel, actions);
|
||||
root.setPadding(new Insets(24));
|
||||
VBox.setVgrow(stepBody, Priority.ALWAYS);
|
||||
return root;
|
||||
}
|
||||
|
||||
private void renderStep() {
|
||||
feedbackLabel.setText("");
|
||||
backButton.setDisable(stepIndex == 0);
|
||||
nextButton.setVisible(stepIndex < 4);
|
||||
nextButton.setManaged(stepIndex < 4);
|
||||
createButton.setVisible(stepIndex == 4);
|
||||
createButton.setManaged(stepIndex == 4);
|
||||
|
||||
switch (stepIndex) {
|
||||
case 0 -> renderNameStep();
|
||||
case 1 -> renderLanguageStep();
|
||||
case 2 -> renderDetailsStep();
|
||||
case 3 -> renderLocationStep();
|
||||
case 4 -> renderConfirmStep();
|
||||
default -> throw new IllegalStateException("unknown wizard step: " + stepIndex);
|
||||
}
|
||||
}
|
||||
|
||||
private void renderNameStep() {
|
||||
stepTitle.textProperty().unbind();
|
||||
stepDescription.textProperty().unbind();
|
||||
stepTitle.textProperty().bind(i18n.bind(I18n.WIZARD_STEP_NAME_TITLE));
|
||||
stepDescription.textProperty().bind(i18n.bind(I18n.WIZARD_STEP_NAME_DESCRIPTION));
|
||||
stepBody.getChildren().setAll(projectNameField);
|
||||
}
|
||||
|
||||
private void renderLanguageStep() {
|
||||
stepTitle.textProperty().unbind();
|
||||
stepDescription.textProperty().unbind();
|
||||
stepTitle.textProperty().bind(i18n.bind(I18n.WIZARD_STEP_LANGUAGE_TITLE));
|
||||
stepDescription.textProperty().bind(i18n.bind(I18n.WIZARD_STEP_LANGUAGE_DESCRIPTION));
|
||||
|
||||
final Label languageLabel = new Label(i18n.text(I18n.WIZARD_LANGUAGE_LABEL));
|
||||
final Label stdlibLabel = new Label(i18n.text(I18n.WIZARD_STDLIB_LABEL));
|
||||
final Label sourceRootLabel = new Label(i18n.text(I18n.WIZARD_SOURCE_ROOT_LABEL));
|
||||
|
||||
languageCombo.setMaxWidth(Double.MAX_VALUE);
|
||||
stdlibCombo.setMaxWidth(Double.MAX_VALUE);
|
||||
sourceRootCombo.setMaxWidth(Double.MAX_VALUE);
|
||||
|
||||
final VBox languageBox = new VBox(6, languageLabel, languageCombo);
|
||||
final VBox stdlibBox = new VBox(6, stdlibLabel, stdlibCombo);
|
||||
final VBox sourceRootBox = new VBox(6, sourceRootLabel, sourceRootCombo);
|
||||
stepBody.getChildren().setAll(languageBox, stdlibBox, sourceRootBox);
|
||||
}
|
||||
|
||||
private void renderLocationStep() {
|
||||
stepTitle.textProperty().unbind();
|
||||
stepDescription.textProperty().unbind();
|
||||
stepTitle.textProperty().bind(i18n.bind(I18n.WIZARD_STEP_LOCATION_TITLE));
|
||||
stepDescription.textProperty().bind(i18n.bind(I18n.WIZARD_STEP_LOCATION_DESCRIPTION));
|
||||
|
||||
final Button browseButton = new Button();
|
||||
browseButton.textProperty().bind(i18n.bind(I18n.WIZARD_BROWSE));
|
||||
browseButton.getStyleClass().addAll("studio-button", "studio-button-secondary");
|
||||
browseButton.setOnAction(ignored -> browseForLocation());
|
||||
|
||||
final HBox row = new HBox(12, locationField, browseButton);
|
||||
HBox.setHgrow(locationField, Priority.ALWAYS);
|
||||
row.setAlignment(Pos.CENTER_LEFT);
|
||||
stepBody.getChildren().setAll(row);
|
||||
}
|
||||
|
||||
private void renderConfirmStep() {
|
||||
stepTitle.textProperty().unbind();
|
||||
stepDescription.textProperty().unbind();
|
||||
stepTitle.textProperty().bind(i18n.bind(I18n.WIZARD_STEP_CONFIRM_TITLE));
|
||||
stepDescription.textProperty().bind(i18n.bind(I18n.WIZARD_STEP_CONFIRM_DESCRIPTION));
|
||||
|
||||
final Label projectName = new Label(i18n.format(I18n.WIZARD_CONFIRM_NAME, sanitizedName()));
|
||||
final Label projectLanguage = new Label(i18n.format(I18n.WIZARD_CONFIRM_LANGUAGE, selectedLanguageId()));
|
||||
final Label projectStdlib = new Label(i18n.format(I18n.WIZARD_CONFIRM_STDLIB, selectedStdlibLabel()));
|
||||
final Label projectSourceRoot = new Label(i18n.format(I18n.WIZARD_CONFIRM_SOURCE_ROOT, selectedSourceRoot()));
|
||||
final Label projectLocation = new Label(i18n.format(I18n.WIZARD_CONFIRM_LOCATION, locationField.getText().trim()));
|
||||
final Label projectIndentation = new Label(i18n.format(I18n.WIZARD_CONFIRM_INDENTATION, selectedIndentationLabel()));
|
||||
final Label projectRuntime = new Label(i18n.format(I18n.WIZARD_CONFIRM_RUNTIME, selectedRuntimePathLabel()));
|
||||
final Label projectRoot = new Label(i18n.format(I18n.WIZARD_CONFIRM_ROOT, resolvedProjectRoot().toString()));
|
||||
|
||||
stepBody.getChildren().setAll(
|
||||
projectName,
|
||||
projectLanguage,
|
||||
projectStdlib,
|
||||
projectSourceRoot,
|
||||
projectIndentation,
|
||||
projectRuntime,
|
||||
projectLocation,
|
||||
projectRoot);
|
||||
}
|
||||
|
||||
private void renderDetailsStep() {
|
||||
stepTitle.textProperty().unbind();
|
||||
stepDescription.textProperty().unbind();
|
||||
stepTitle.textProperty().bind(i18n.bind(I18n.WIZARD_STEP_DETAILS_TITLE));
|
||||
stepDescription.textProperty().bind(i18n.bind(I18n.WIZARD_STEP_DETAILS_DESCRIPTION));
|
||||
|
||||
final Label indentationLabel = new Label(i18n.text(I18n.WIZARD_INDENTATION_LABEL));
|
||||
final Label runtimeLabel = new Label(i18n.text(I18n.WIZARD_RUNTIME_LABEL));
|
||||
final Button runtimeBrowseButton = new Button();
|
||||
runtimeBrowseButton.textProperty().bind(i18n.bind(I18n.WIZARD_BROWSE));
|
||||
runtimeBrowseButton.getStyleClass().addAll("studio-button", "studio-button-secondary");
|
||||
runtimeBrowseButton.setOnAction(ignored -> browseForRuntimePath());
|
||||
indentationWidthCombo.setMaxWidth(Double.MAX_VALUE);
|
||||
runtimePathField.setMaxWidth(Double.MAX_VALUE);
|
||||
final VBox indentationBox = new VBox(6, indentationLabel, indentationWidthCombo);
|
||||
final HBox runtimeRow = new HBox(12, runtimePathField, runtimeBrowseButton);
|
||||
runtimeRow.setAlignment(Pos.CENTER_LEFT);
|
||||
HBox.setHgrow(runtimePathField, Priority.ALWAYS);
|
||||
final VBox runtimeBox = new VBox(6, runtimeLabel, runtimeRow);
|
||||
stepBody.getChildren().setAll(indentationBox, runtimeBox);
|
||||
}
|
||||
|
||||
private void goBack() {
|
||||
if (stepIndex == 0) {
|
||||
return;
|
||||
}
|
||||
stepIndex -= 1;
|
||||
renderStep();
|
||||
}
|
||||
|
||||
private void goNext() {
|
||||
if (!validateCurrentStep()) {
|
||||
return;
|
||||
}
|
||||
stepIndex += 1;
|
||||
renderStep();
|
||||
}
|
||||
|
||||
private boolean validateCurrentStep() {
|
||||
return switch (stepIndex) {
|
||||
case 0 -> validateName();
|
||||
case 1 -> validateLanguageSettings();
|
||||
case 2 -> validateDetails();
|
||||
case 3 -> validateLocation();
|
||||
default -> true;
|
||||
};
|
||||
}
|
||||
|
||||
private boolean validateName() {
|
||||
if (sanitizedName().isBlank()) {
|
||||
feedbackLabel.setText(i18n.text(I18n.WIZARD_ERROR_NAME_REQUIRED));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean validateLanguageSettings() {
|
||||
if (selectedLanguageId().isBlank()) {
|
||||
feedbackLabel.setText(i18n.text(I18n.WIZARD_ERROR_LANGUAGE_REQUIRED));
|
||||
return false;
|
||||
}
|
||||
if (selectedSourceRoot().isBlank()) {
|
||||
feedbackLabel.setText(i18n.text(I18n.WIZARD_ERROR_SOURCE_ROOT_REQUIRED));
|
||||
return false;
|
||||
}
|
||||
if (selectedStdlib() == null) {
|
||||
feedbackLabel.setText(i18n.text(I18n.WIZARD_ERROR_STDLIB_REQUIRED));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean validateLocation() {
|
||||
final String rawLocation = locationField.getText().trim();
|
||||
if (rawLocation.isBlank()) {
|
||||
feedbackLabel.setText(i18n.text(I18n.WIZARD_ERROR_LOCATION_REQUIRED));
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
Path.of(rawLocation);
|
||||
} catch (RuntimeException runtimeException) {
|
||||
feedbackLabel.setText(runtimeException.getMessage());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean validateDetails() {
|
||||
if (selectedIndentationWidth() <= 0) {
|
||||
feedbackLabel.setText(i18n.text(I18n.WIZARD_ERROR_INDENTATION_REQUIRED));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void finishCreate() {
|
||||
if (!validateName() || !validateLanguageSettings() || !validateLocation()) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
result.set(projectCatalogService.createProject(new ProjectCreationRequest(
|
||||
projectNameField.getText(),
|
||||
Path.of(locationField.getText().trim()),
|
||||
selectedLanguageId(),
|
||||
selectedStdlib().version(),
|
||||
ProjectTarget.Game, // hardcoded for now, we can add a separate step for this if needed
|
||||
selectedSourceRoot(),
|
||||
selectedIndentationWidth(),
|
||||
selectedRuntimePath())));
|
||||
stage.close();
|
||||
} catch (IllegalArgumentException exception) {
|
||||
feedbackLabel.setText(exception.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void browseForLocation() {
|
||||
final DirectoryChooser chooser = new DirectoryChooser();
|
||||
chooser.setTitle(i18n.text(I18n.WIZARD_BROWSE));
|
||||
|
||||
final String currentText = locationField.getText().trim();
|
||||
if (!currentText.isBlank()) {
|
||||
final File currentDirectory = Path.of(currentText).toFile();
|
||||
if (currentDirectory.isDirectory()) {
|
||||
chooser.setInitialDirectory(currentDirectory);
|
||||
}
|
||||
}
|
||||
|
||||
final File selected = chooser.showDialog(stage);
|
||||
if (selected != null) {
|
||||
locationField.setText(selected.toPath().toAbsolutePath().normalize().toString());
|
||||
}
|
||||
}
|
||||
|
||||
private void browseForRuntimePath() {
|
||||
final DirectoryChooser chooser = new DirectoryChooser();
|
||||
chooser.setTitle(i18n.text(I18n.WIZARD_RUNTIME_LABEL));
|
||||
|
||||
final String currentText = runtimePathField.getText().trim();
|
||||
if (!currentText.isBlank()) {
|
||||
final File currentDirectory = Path.of(currentText).toFile();
|
||||
if (currentDirectory.isDirectory()) {
|
||||
chooser.setInitialDirectory(currentDirectory);
|
||||
}
|
||||
}
|
||||
|
||||
final File selected = chooser.showDialog(stage);
|
||||
if (selected != null) {
|
||||
runtimePathField.setText(selected.toPath().toAbsolutePath().normalize().toString());
|
||||
}
|
||||
}
|
||||
|
||||
private String sanitizedName() {
|
||||
return projectNameField.getText() == null ? "" : projectNameField.getText().trim();
|
||||
}
|
||||
|
||||
private void initializeLanguageTemplates() {
|
||||
final List<ProjectLanguageTemplate> templates = projectLanguageCatalogService.listLanguageTemplates();
|
||||
for (ProjectLanguageTemplate template : templates) {
|
||||
languageTemplatesById.put(template.languageId(), template);
|
||||
}
|
||||
languageCombo.getItems().setAll(languageTemplatesById.keySet());
|
||||
languageCombo.getSelectionModel().selectedItemProperty().addListener((ignored, oldValue, newValue) -> applyLanguageTemplate(newValue));
|
||||
if (!templates.isEmpty()) {
|
||||
languageCombo.getSelectionModel().select(projectLanguageCatalogService.defaultTemplate().languageId());
|
||||
}
|
||||
}
|
||||
|
||||
private void applyLanguageTemplate(String languageId) {
|
||||
final ProjectLanguageTemplate template = languageTemplatesById.get(languageId);
|
||||
if (template == null) {
|
||||
stdlibCombo.getItems().clear();
|
||||
stdlibCombo.getSelectionModel().clearSelection();
|
||||
sourceRootCombo.getItems().clear();
|
||||
sourceRootCombo.getSelectionModel().clearSelection();
|
||||
return;
|
||||
}
|
||||
stdlibCombo.getItems().setAll(template.stdlibOptions());
|
||||
stdlibCombo.getSelectionModel().select(template.defaultStdlib());
|
||||
sourceRootCombo.getItems().setAll(template.sourceRoots());
|
||||
sourceRootCombo.getSelectionModel().select(template.defaultSourceRoot());
|
||||
}
|
||||
|
||||
private String selectedLanguageId() {
|
||||
return languageCombo.getValue() == null ? "" : languageCombo.getValue().trim();
|
||||
}
|
||||
|
||||
private String selectedSourceRoot() {
|
||||
return sourceRootCombo.getValue() == null ? "" : sourceRootCombo.getValue().trim();
|
||||
}
|
||||
|
||||
private ProjectLanguageTemplate.StdlibOption selectedStdlib() {
|
||||
return stdlibCombo.getValue();
|
||||
}
|
||||
|
||||
private String selectedStdlibLabel() {
|
||||
final ProjectLanguageTemplate.StdlibOption selectedStdlib = selectedStdlib();
|
||||
return selectedStdlib == null ? "" : selectedStdlib.toString();
|
||||
}
|
||||
|
||||
private int selectedIndentationWidth() {
|
||||
return indentationWidthCombo.getValue() == null ? 4 : indentationWidthCombo.getValue();
|
||||
}
|
||||
|
||||
private String selectedIndentationLabel() {
|
||||
return "Spaces: " + selectedIndentationWidth();
|
||||
}
|
||||
|
||||
private String selectedRuntimePath() {
|
||||
if (runtimePathField.getText() == null) {
|
||||
return null;
|
||||
}
|
||||
final String trimmed = runtimePathField.getText().trim();
|
||||
return trimmed.isBlank() ? null : trimmed;
|
||||
}
|
||||
|
||||
private String selectedRuntimePathLabel() {
|
||||
return selectedRuntimePath() == null ? "-" : selectedRuntimePath();
|
||||
}
|
||||
|
||||
private Path resolvedProjectRoot() {
|
||||
return Path.of(locationField.getText().trim()).toAbsolutePath().normalize().resolve(sanitizedName());
|
||||
}
|
||||
}
|
||||
+246
@@ -0,0 +1,246 @@
|
||||
package p.studio.ui.javafx.window;
|
||||
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.ListCell;
|
||||
import javafx.scene.control.ListView;
|
||||
import javafx.scene.input.MouseButton;
|
||||
import javafx.scene.layout.*;
|
||||
import javafx.stage.FileChooser;
|
||||
import p.studio.api.project.KnownProjects;
|
||||
import p.studio.api.project.ProjectCatalog;
|
||||
import p.studio.api.project.ProjectLanguageCatalog;
|
||||
import p.studio.api.project.ProjectReference;
|
||||
import p.studio.ui.javafx.utilities.i18n.I18n;
|
||||
import p.studio.ui.javafx.utilities.i18n.I18nService;
|
||||
import p.studio.ui.javafx.utilities.ThemeService;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public final class ProjectLauncherView extends BorderPane {
|
||||
private final KnownProjects knownProjectsService;
|
||||
private final ProjectCatalog projectCatalogService;
|
||||
private final ProjectLanguageCatalog languageCatalog;
|
||||
private final I18nService i18n;
|
||||
private final ThemeService theme;
|
||||
private final Consumer<ProjectReference> onOpenProject;
|
||||
private final Consumer<ProjectReference> onAddProject;
|
||||
private final Consumer<ProjectReference> onCreateProject;
|
||||
private final Consumer<ProjectReference> onForgetProject;
|
||||
private final ListView<ProjectReference> projectList = new ListView<>();
|
||||
private final Label feedbackLabel = new Label();
|
||||
|
||||
public ProjectLauncherView(
|
||||
KnownProjects knownProjectsService,
|
||||
ProjectCatalog projectCatalogService,
|
||||
ProjectLanguageCatalog languageCatalog,
|
||||
I18nService i18n,
|
||||
ThemeService theme,
|
||||
Consumer<ProjectReference> onOpenProject,
|
||||
Consumer<ProjectReference> onAddProject,
|
||||
Consumer<ProjectReference> onCreateProject,
|
||||
Consumer<ProjectReference> onForgetProject) {
|
||||
this.knownProjectsService = Objects.requireNonNull(knownProjectsService, "knownProjectsService");
|
||||
this.projectCatalogService = Objects.requireNonNull(projectCatalogService, "projectCatalogService");
|
||||
this.languageCatalog = Objects.requireNonNull(languageCatalog, "languageCatalog");
|
||||
this.i18n = Objects.requireNonNull(i18n, "i18n");
|
||||
this.theme = Objects.requireNonNull(theme, "theme");
|
||||
this.onOpenProject = Objects.requireNonNull(onOpenProject, "onOpenProject");
|
||||
this.onAddProject = Objects.requireNonNull(onAddProject, "onAddProject");
|
||||
this.onCreateProject = Objects.requireNonNull(onCreateProject, "onCreateProject");
|
||||
this.onForgetProject = Objects.requireNonNull(onForgetProject, "onForgetProject");
|
||||
|
||||
getStyleClass().add("studio-project-launcher");
|
||||
setPadding(new Insets(16));
|
||||
setCenter(buildCenteredContent());
|
||||
|
||||
reloadProjects();
|
||||
}
|
||||
|
||||
private StackPane buildCenteredContent() {
|
||||
final VBox content = buildContent();
|
||||
final StackPane wrapper = new StackPane(content);
|
||||
wrapper.setPadding(new Insets(8, 12, 8, 12));
|
||||
StackPane.setAlignment(content, Pos.CENTER);
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
private VBox buildContent() {
|
||||
final Label title = new Label();
|
||||
title.textProperty().bind(i18n.bind(I18n.LAUNCHER_TITLE));
|
||||
title.getStyleClass().add("studio-launcher-title");
|
||||
|
||||
final Label subtitle = new Label();
|
||||
subtitle.textProperty().bind(i18n.bind(I18n.LAUNCHER_SUBTITLE));
|
||||
subtitle.getStyleClass().add("studio-launcher-subtitle");
|
||||
|
||||
final Label listTitle = new Label();
|
||||
listTitle.textProperty().bind(i18n.bind(I18n.LAUNCHER_EXISTING_PROJECTS));
|
||||
listTitle.getStyleClass().add("studio-launcher-section-title");
|
||||
|
||||
projectList.getStyleClass().add("studio-project-list");
|
||||
projectList.setCellFactory(ignored -> new ProjectReferenceListCell());
|
||||
projectList.setOnMouseClicked(event -> {
|
||||
if (event.getButton() == MouseButton.PRIMARY && event.getClickCount() == 2) {
|
||||
openSelectedProject();
|
||||
}
|
||||
});
|
||||
VBox.setVgrow(projectList, Priority.ALWAYS);
|
||||
|
||||
final Button openButton = new Button();
|
||||
openButton.textProperty().bind(i18n.bind(I18n.LAUNCHER_OPEN_PROJECT));
|
||||
openButton.getStyleClass().addAll("studio-button", "studio-button-primary");
|
||||
openButton.disableProperty().bind(projectList.getSelectionModel().selectedItemProperty().isNull());
|
||||
openButton.setOnAction(ignored -> openSelectedProject());
|
||||
|
||||
final Button addButton = new Button();
|
||||
addButton.textProperty().bind(i18n.bind(I18n.LAUNCHER_ADD_PROJECT));
|
||||
addButton.getStyleClass().addAll("studio-button", "studio-button-secondary");
|
||||
addButton.setOnAction(ignored -> addExistingProject());
|
||||
|
||||
final Button forgetButton = new Button();
|
||||
forgetButton.textProperty().bind(i18n.bind(I18n.LAUNCHER_FORGET_PROJECT));
|
||||
forgetButton.getStyleClass().addAll("studio-button", "studio-button-warning");
|
||||
forgetButton.disableProperty().bind(projectList.getSelectionModel().selectedItemProperty().isNull());
|
||||
forgetButton.setOnAction(ignored -> forgetSelectedProject());
|
||||
|
||||
final HBox openRow = new HBox(10, openButton, addButton, forgetButton);
|
||||
openRow.setAlignment(Pos.CENTER_LEFT);
|
||||
|
||||
final Label createTitle = new Label();
|
||||
createTitle.textProperty().bind(i18n.bind(I18n.LAUNCHER_CREATE_PROJECT));
|
||||
createTitle.getStyleClass().add("studio-launcher-section-title");
|
||||
|
||||
final Button createButton = new Button();
|
||||
createButton.textProperty().bind(i18n.bind(I18n.LAUNCHER_CREATE_BUTTON));
|
||||
createButton.getStyleClass().addAll("studio-button", "studio-button-primary");
|
||||
createButton.setOnAction(ignored -> openCreateWizard());
|
||||
|
||||
final HBox createRow = new HBox(10, createButton);
|
||||
createRow.setAlignment(Pos.CENTER_LEFT);
|
||||
|
||||
feedbackLabel.getStyleClass().add("studio-launcher-feedback");
|
||||
feedbackLabel.setWrapText(true);
|
||||
|
||||
final VBox content = new VBox(12,
|
||||
title,
|
||||
subtitle,
|
||||
listTitle,
|
||||
projectList,
|
||||
openRow,
|
||||
createTitle,
|
||||
createRow,
|
||||
feedbackLabel);
|
||||
content.setMaxWidth(520);
|
||||
return content;
|
||||
}
|
||||
|
||||
public void reloadProjects() {
|
||||
projectList.setItems(FXCollections.observableArrayList(knownProjectsService.listKnownProjects()));
|
||||
if (!projectList.getItems().isEmpty()) {
|
||||
projectList.getSelectionModel().selectFirst();
|
||||
}
|
||||
}
|
||||
|
||||
private void openSelectedProject() {
|
||||
final ProjectReference selected = projectList.getSelectionModel().getSelectedItem();
|
||||
if (selected == null) {
|
||||
feedbackLabel.textProperty().unbind();
|
||||
feedbackLabel.setText("");
|
||||
return;
|
||||
}
|
||||
|
||||
feedbackLabel.setText("");
|
||||
onOpenProject.accept(selected);
|
||||
}
|
||||
|
||||
private void forgetSelectedProject() {
|
||||
final ProjectReference selected = projectList.getSelectionModel().getSelectedItem();
|
||||
if (selected == null) {
|
||||
feedbackLabel.setText("");
|
||||
return;
|
||||
}
|
||||
|
||||
feedbackLabel.textProperty().unbind();
|
||||
feedbackLabel.setText("");
|
||||
onForgetProject.accept(selected);
|
||||
}
|
||||
|
||||
private void openCreateWizard() {
|
||||
NewProjectWizard.showAndWait(getScene().getWindow(), projectCatalogService, languageCatalog, i18n, theme).ifPresent(created -> {
|
||||
reloadProjects();
|
||||
projectList.getSelectionModel().select(created);
|
||||
feedbackLabel.textProperty().unbind();
|
||||
feedbackLabel.setText("");
|
||||
onCreateProject.accept(created);
|
||||
});
|
||||
}
|
||||
|
||||
private void addExistingProject() {
|
||||
final FileChooser chooser = new FileChooser();
|
||||
chooser.setTitle(i18n.text(I18n.LAUNCHER_ADD_PROJECT));
|
||||
chooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("Prometeu Project", "prometeu.json"));
|
||||
chooser.setInitialFileName("prometeu.json");
|
||||
final File initialDirectory = projectCatalogService.projectsRoot().toFile();
|
||||
if (initialDirectory.isDirectory()) {
|
||||
chooser.setInitialDirectory(initialDirectory);
|
||||
}
|
||||
|
||||
final File selected = chooser.showOpenDialog(getScene().getWindow());
|
||||
if (selected == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
final ProjectReference project = projectCatalogService.openProjectManifest(Path.of(selected.toURI()));
|
||||
onAddProject.accept(project);
|
||||
reloadProjects();
|
||||
projectList.getSelectionModel().select(project);
|
||||
feedbackLabel.textProperty().unbind();
|
||||
feedbackLabel.setText("");
|
||||
} catch (IllegalArgumentException exception) {
|
||||
feedbackLabel.textProperty().unbind();
|
||||
feedbackLabel.setText(exception.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private static final class ProjectReferenceListCell extends ListCell<ProjectReference> {
|
||||
private final Label nameLabel = new Label();
|
||||
private final Label metadataLabel = new Label();
|
||||
private final Label pathLabel = new Label();
|
||||
private final VBox content = new VBox(3, nameLabel, metadataLabel, pathLabel);
|
||||
|
||||
private ProjectReferenceListCell() {
|
||||
nameLabel.getStyleClass().add("studio-project-list-name");
|
||||
metadataLabel.getStyleClass().add("studio-project-list-metadata");
|
||||
pathLabel.getStyleClass().add("studio-project-list-path");
|
||||
metadataLabel.setWrapText(true);
|
||||
pathLabel.setWrapText(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateItem(ProjectReference item, boolean empty) {
|
||||
super.updateItem(item, empty);
|
||||
if (empty || item == null) {
|
||||
setText(null);
|
||||
setGraphic(null);
|
||||
return;
|
||||
}
|
||||
|
||||
nameLabel.setText(item.name());
|
||||
metadataLabel.setText("v%s | %s | stdlib %d".formatted(
|
||||
item.version(),
|
||||
item.languageId(),
|
||||
item.stdlibVersion()));
|
||||
pathLabel.setText(item.rootPath().toString());
|
||||
setText(null);
|
||||
setGraphic(content);
|
||||
}
|
||||
}
|
||||
}
|
||||
+113
@@ -0,0 +1,113 @@
|
||||
package p.studio.ui.javafx.window;
|
||||
|
||||
import javafx.animation.KeyFrame;
|
||||
import javafx.animation.Timeline;
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.ProgressBar;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.Region;
|
||||
import javafx.scene.layout.StackPane;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.util.Duration;
|
||||
import p.studio.ui.javafx.StudioAppInfo;
|
||||
import p.studio.api.project.ProjectReference;
|
||||
import p.studio.ui.javafx.utilities.i18n.I18n;
|
||||
import p.studio.ui.javafx.utilities.i18n.I18nService;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public final class ProjectLoadingShieldView extends VBox {
|
||||
public ProjectLoadingShieldView(ProjectReference projectReference, I18nService i18n) {
|
||||
Objects.requireNonNull(projectReference, "projectReference");
|
||||
Objects.requireNonNull(i18n, "i18n");
|
||||
|
||||
getStyleClass().add("studio-project-loading-shield");
|
||||
setPadding(new Insets(28));
|
||||
setSpacing(14);
|
||||
setAlignment(Pos.CENTER_LEFT);
|
||||
|
||||
final Label markLabel = new Label("P");
|
||||
markLabel.getStyleClass().add("studio-project-loading-mark");
|
||||
|
||||
final Label appTitle = new Label(i18n.text(I18n.APP_TITLE));
|
||||
appTitle.getStyleClass().add("studio-project-loading-title");
|
||||
|
||||
final Label appVersion = new Label(i18n.format(I18n.SHIELD_VERSION, StudioAppInfo.version()));
|
||||
appVersion.getStyleClass().add("studio-project-loading-version");
|
||||
|
||||
final VBox brandBlock = new VBox(4, appTitle, appVersion);
|
||||
final HBox brandRow = new HBox(14, buildMark(markLabel), brandBlock);
|
||||
brandRow.setAlignment(Pos.CENTER_LEFT);
|
||||
|
||||
final Label projectLabel = new Label(projectReference.name());
|
||||
projectLabel.getStyleClass().add("studio-project-loading-project");
|
||||
|
||||
final Label statusLabel = new Label(i18n.format(I18n.SHIELD_LOADING_PROJECT, projectReference.name()));
|
||||
statusLabel.getStyleClass().add("studio-project-loading-status");
|
||||
|
||||
final ProgressBar progressBar = new ProgressBar(0.18);
|
||||
progressBar.getStyleClass().add("studio-project-loading-progress");
|
||||
progressBar.setMaxWidth(Double.MAX_VALUE);
|
||||
|
||||
final HBox phaseRow = new HBox(
|
||||
8,
|
||||
phasePill(i18n.text(I18n.SHIELD_PHASE_INDEXING), true),
|
||||
phasePill(i18n.text(I18n.SHIELD_PHASE_PREPARING), false),
|
||||
phasePill(i18n.text(I18n.SHIELD_PHASE_RESTORING), false));
|
||||
phaseRow.setAlignment(Pos.CENTER_LEFT);
|
||||
|
||||
final Label tipLabel = new Label(i18n.text(I18n.SHIELD_TIP_SHORTCUTS));
|
||||
tipLabel.getStyleClass().add("studio-project-loading-tip");
|
||||
tipLabel.setWrapText(true);
|
||||
|
||||
final Timeline timeline = new Timeline(
|
||||
new KeyFrame(Duration.ZERO, ignored -> {
|
||||
statusLabel.setText(i18n.format(I18n.SHIELD_LOADING_PROJECT, projectReference.name()));
|
||||
tipLabel.setText(i18n.text(I18n.SHIELD_TIP_SHORTCUTS));
|
||||
progressBar.setProgress(0.24);
|
||||
}),
|
||||
new KeyFrame(Duration.millis(500), ignored -> {
|
||||
statusLabel.setText(i18n.text(I18n.SHIELD_STATUS_INDEXING));
|
||||
tipLabel.setText(i18n.text(I18n.SHIELD_TIP_WORKSPACES));
|
||||
progressBar.setProgress(0.58);
|
||||
}),
|
||||
new KeyFrame(Duration.millis(1000), ignored -> {
|
||||
statusLabel.setText(i18n.text(I18n.SHIELD_STATUS_RESTORING));
|
||||
tipLabel.setText(i18n.text(I18n.SHIELD_TIP_ACTIVITY));
|
||||
progressBar.setProgress(0.86);
|
||||
}));
|
||||
timeline.setCycleCount(Timeline.INDEFINITE);
|
||||
timeline.play();
|
||||
|
||||
sceneProperty().addListener((ignored, oldScene, newScene) -> {
|
||||
if (newScene == null) {
|
||||
timeline.stop();
|
||||
}
|
||||
});
|
||||
|
||||
getChildren().addAll(
|
||||
brandRow,
|
||||
projectLabel,
|
||||
statusLabel,
|
||||
progressBar,
|
||||
phaseRow,
|
||||
tipLabel);
|
||||
}
|
||||
|
||||
private StackPane buildMark(Label markLabel) {
|
||||
final StackPane mark = new StackPane(markLabel);
|
||||
mark.getStyleClass().add("studio-project-loading-mark-shell");
|
||||
return mark;
|
||||
}
|
||||
|
||||
private Region phasePill(String text, boolean active) {
|
||||
final Label label = new Label(text);
|
||||
label.getStyleClass().add("studio-project-loading-phase");
|
||||
if (active) {
|
||||
label.getStyleClass().add("studio-project-loading-phase-active");
|
||||
}
|
||||
return label;
|
||||
}
|
||||
}
|
||||
+397
@@ -0,0 +1,397 @@
|
||||
package p.studio.ui.javafx.window;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.stage.StageStyle;
|
||||
import p.studio.api.assets.AssetCatalog;
|
||||
import p.studio.api.assets.AssetCommands;
|
||||
import p.studio.api.assets.AssetPacking;
|
||||
import p.studio.api.assets.AssetDetails;
|
||||
import p.studio.api.assets.AssetCreationCatalog;
|
||||
import p.studio.api.assets.AssetWorkspaceStorage;
|
||||
import p.studio.api.assets.AssetCapacityPolicy;
|
||||
import p.studio.api.assets.schema.AssetColorSchemaFactory;
|
||||
import p.studio.api.assets.bank.AssetBankCompositionSessionFactory;
|
||||
import p.studio.api.assets.metadata.AssetMetadataService;
|
||||
import p.studio.api.assets.scene.SceneBankWorkflow;
|
||||
import p.studio.api.assets.tiled.TiledAssetService;
|
||||
import p.studio.api.project.KnownProjects;
|
||||
import p.studio.api.project.ProjectCatalog;
|
||||
import p.studio.api.project.ProjectLanguageCatalog;
|
||||
import p.studio.ui.javafx.events.*;
|
||||
import p.studio.api.project.ProjectReference;
|
||||
import p.studio.api.shipper.Shipper;
|
||||
import p.studio.api.session.ProjectSession;
|
||||
import p.studio.api.session.ProjectSessionFactory;
|
||||
import p.studio.api.execution.ExecutionControllerFactory;
|
||||
import p.studio.api.project.ProjectWorkspaceInitializer;
|
||||
import p.studio.api.preferences.WindowStateStore;
|
||||
import p.studio.api.preferences.ProjectActivityHistoryStore;
|
||||
import p.studio.ui.javafx.utilities.i18n.I18n;
|
||||
import p.studio.ui.javafx.utilities.i18n.I18nService;
|
||||
import p.studio.ui.javafx.utilities.ThemeService;
|
||||
import p.studio.ui.javafx.events.StudioEventBus;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
public final class StudioWindowCoordinator implements AutoCloseable {
|
||||
private static final double LAUNCHER_WIDTH = 760;
|
||||
private static final double LAUNCHER_HEIGHT = 750;
|
||||
private static final double PROJECT_LOADING_WIDTH = 460;
|
||||
private static final double PROJECT_LOADING_HEIGHT = 250;
|
||||
private static final double PROJECT_WIDTH = 1280;
|
||||
private static final double PROJECT_HEIGHT = 840;
|
||||
|
||||
private final Stage launcherStage;
|
||||
private final ProjectCatalog projectCatalogService;
|
||||
private final KnownProjects knownProjectsService;
|
||||
private final WindowStateService windowStateService;
|
||||
private final ProjectLauncherView launcherView;
|
||||
private final ProjectSessionFactory projectSessionFactory;
|
||||
private final Shipper shipper;
|
||||
private final ExecutionControllerFactory executionControllerFactory;
|
||||
private final ProjectWorkspaceInitializer projectWorkspaceInitializer;
|
||||
private final Executor executor;
|
||||
private final I18nService i18n;
|
||||
private final ThemeService theme;
|
||||
private final StudioEventBus eventBus;
|
||||
private final AssetCatalog assetCatalog;
|
||||
private final AssetCommands assetCommands;
|
||||
private final AssetPacking assetPacking;
|
||||
private final AssetDetails assetDetails;
|
||||
private final AssetCreationCatalog assetCreationCatalog;
|
||||
private final AssetMetadataService assetMetadataService;
|
||||
private final AssetWorkspaceStorage assetWorkspaceStorage;
|
||||
private final AssetCapacityPolicy assetCapacityPolicy;
|
||||
private final AssetBankCompositionSessionFactory bankCompositionSessionFactory;
|
||||
private final AssetColorSchemaFactory assetColorSchemaFactory;
|
||||
private final TiledAssetService tiledAssetService;
|
||||
private final SceneBankWorkflow sceneBankWorkflow;
|
||||
private final ProjectActivityHistoryStore activityHistoryStore;
|
||||
private final Object lifecycleMonitor = new Object();
|
||||
private volatile boolean closed;
|
||||
private volatile ProjectSession pendingProjectSession;
|
||||
private Stage loadingStage;
|
||||
private Stage projectStage;
|
||||
private MainView mainView;
|
||||
private ProjectSession projectSession;
|
||||
|
||||
public StudioWindowCoordinator(
|
||||
Stage launcherStage,
|
||||
ProjectCatalog projectCatalogService,
|
||||
KnownProjects knownProjectsService,
|
||||
ProjectLanguageCatalog languageCatalog,
|
||||
ProjectSessionFactory projectSessionFactory,
|
||||
ExecutionControllerFactory executionControllerFactory,
|
||||
ProjectWorkspaceInitializer projectWorkspaceInitializer,
|
||||
Executor executor,
|
||||
I18nService i18n,
|
||||
ThemeService theme,
|
||||
StudioEventBus eventBus,
|
||||
Shipper shipper,
|
||||
AssetCatalog assetCatalog,
|
||||
AssetCommands assetCommands,
|
||||
AssetPacking assetPacking,
|
||||
AssetDetails assetDetails,
|
||||
AssetCreationCatalog assetCreationCatalog,
|
||||
AssetMetadataService assetMetadataService,
|
||||
AssetWorkspaceStorage assetWorkspaceStorage,
|
||||
AssetCapacityPolicy assetCapacityPolicy,
|
||||
AssetBankCompositionSessionFactory bankCompositionSessionFactory,
|
||||
AssetColorSchemaFactory assetColorSchemaFactory,
|
||||
TiledAssetService tiledAssetService,
|
||||
SceneBankWorkflow sceneBankWorkflow,
|
||||
WindowStateStore windowStateStore,
|
||||
ProjectActivityHistoryStore activityHistoryStore) {
|
||||
this.launcherStage = Objects.requireNonNull(launcherStage, "launcherStage");
|
||||
this.projectCatalogService = Objects.requireNonNull(projectCatalogService, "projectCatalogService");
|
||||
this.knownProjectsService = Objects.requireNonNull(knownProjectsService, "knownProjectsService");
|
||||
this.shipper = Objects.requireNonNull(shipper, "shipper");
|
||||
this.windowStateService = new WindowStateService(windowStateStore);
|
||||
this.projectSessionFactory = Objects.requireNonNull(projectSessionFactory, "projectSessionFactory");
|
||||
this.executionControllerFactory = Objects.requireNonNull(executionControllerFactory, "executionControllerFactory");
|
||||
this.projectWorkspaceInitializer = Objects.requireNonNull(projectWorkspaceInitializer, "projectWorkspaceInitializer");
|
||||
this.executor = Objects.requireNonNull(executor, "executor");
|
||||
this.i18n = Objects.requireNonNull(i18n, "i18n");
|
||||
this.theme = Objects.requireNonNull(theme, "theme");
|
||||
this.eventBus = Objects.requireNonNull(eventBus, "eventBus");
|
||||
this.assetCatalog = Objects.requireNonNull(assetCatalog, "assetCatalog");
|
||||
this.assetCommands = Objects.requireNonNull(assetCommands, "assetCommands");
|
||||
this.assetPacking = Objects.requireNonNull(assetPacking, "assetPacking");
|
||||
this.assetDetails = Objects.requireNonNull(assetDetails, "assetDetails");
|
||||
this.assetCreationCatalog = Objects.requireNonNull(assetCreationCatalog, "assetCreationCatalog");
|
||||
this.assetMetadataService = Objects.requireNonNull(assetMetadataService, "assetMetadataService");
|
||||
this.assetWorkspaceStorage = Objects.requireNonNull(assetWorkspaceStorage, "assetWorkspaceStorage");
|
||||
this.assetCapacityPolicy = Objects.requireNonNull(assetCapacityPolicy, "assetCapacityPolicy");
|
||||
this.bankCompositionSessionFactory = Objects.requireNonNull(bankCompositionSessionFactory, "bankCompositionSessionFactory");
|
||||
this.assetColorSchemaFactory = Objects.requireNonNull(assetColorSchemaFactory, "assetColorSchemaFactory");
|
||||
this.tiledAssetService = Objects.requireNonNull(tiledAssetService, "tiledAssetService");
|
||||
this.sceneBankWorkflow = Objects.requireNonNull(sceneBankWorkflow, "sceneBankWorkflow");
|
||||
this.activityHistoryStore = Objects.requireNonNull(activityHistoryStore, "activityHistoryStore");
|
||||
this.launcherView = new ProjectLauncherView(
|
||||
knownProjectsService,
|
||||
projectCatalogService,
|
||||
languageCatalog,
|
||||
i18n,
|
||||
theme,
|
||||
this::openProject,
|
||||
this::addProject,
|
||||
this::createProject,
|
||||
this::forgetProject);
|
||||
}
|
||||
|
||||
public void showLauncher() {
|
||||
if (closed) {
|
||||
throw new IllegalStateException("Studio window coordinator is closed");
|
||||
}
|
||||
final Scene scene = new Scene(launcherView, LAUNCHER_WIDTH, LAUNCHER_HEIGHT);
|
||||
scene.getStylesheets().add(theme.getDefaultTheme());
|
||||
|
||||
launcherStage.titleProperty().bind(i18n.bind(I18n.APP_TITLE));
|
||||
launcherStage.setScene(scene);
|
||||
windowStateService.installLauncherState(launcherStage, LAUNCHER_WIDTH, LAUNCHER_HEIGHT);
|
||||
launcherStage.setResizable(false);
|
||||
launcherStage.setWidth(LAUNCHER_WIDTH);
|
||||
launcherStage.setHeight(LAUNCHER_HEIGHT);
|
||||
launcherStage.setMinWidth(LAUNCHER_WIDTH);
|
||||
launcherStage.setMaxWidth(LAUNCHER_WIDTH);
|
||||
launcherStage.setMinHeight(LAUNCHER_HEIGHT);
|
||||
launcherStage.setMaxHeight(LAUNCHER_HEIGHT);
|
||||
launcherStage.show();
|
||||
launcherStage.centerOnScreen();
|
||||
launcherStage.toFront();
|
||||
}
|
||||
|
||||
private void openProject(ProjectReference projectReference) {
|
||||
final ProjectReference opened = projectCatalogService.openProject(projectReference.rootPath());
|
||||
knownProjectsService.remember(opened);
|
||||
eventBus.publish(new StudioProjectOpenedEvent());
|
||||
openProjectWindow(opened);
|
||||
}
|
||||
|
||||
private void createProject(ProjectReference projectReference) {
|
||||
knownProjectsService.remember(projectReference);
|
||||
eventBus.publish(new StudioProjectCreatedEvent());
|
||||
eventBus.publish(new StudioProjectOpenedEvent());
|
||||
openProjectWindow(projectReference);
|
||||
}
|
||||
|
||||
private void addProject(ProjectReference projectReference) {
|
||||
knownProjectsService.remember(projectReference);
|
||||
launcherView.reloadProjects();
|
||||
}
|
||||
|
||||
private void forgetProject(ProjectReference projectReference) {
|
||||
knownProjectsService.forget(projectReference);
|
||||
launcherView.reloadProjects();
|
||||
}
|
||||
|
||||
private void openProjectWindow(ProjectReference projectReference) {
|
||||
if (closed) {
|
||||
return;
|
||||
}
|
||||
final Stage projectLoadingStage = createProjectLoadingStage(projectReference);
|
||||
loadingStage = projectLoadingStage;
|
||||
launcherStage.hide();
|
||||
projectLoadingStage.show();
|
||||
projectLoadingStage.centerOnScreen();
|
||||
projectLoadingStage.toFront();
|
||||
publishProjectLoadingStarted(projectReference);
|
||||
executor.execute(() -> initializeProjectAndOpenWindow(projectReference, projectLoadingStage));
|
||||
}
|
||||
|
||||
private Stage createProjectLoadingStage(ProjectReference projectReference) {
|
||||
final Stage loadingStage = new Stage(StageStyle.UNDECORATED);
|
||||
loadingStage.initOwner(launcherStage);
|
||||
loadingStage.setResizable(false);
|
||||
|
||||
final Scene scene = new Scene(
|
||||
new ProjectLoadingShieldView(projectReference, i18n),
|
||||
PROJECT_LOADING_WIDTH,
|
||||
PROJECT_LOADING_HEIGHT);
|
||||
scene.getStylesheets().add(theme.getDefaultTheme());
|
||||
loadingStage.setScene(scene);
|
||||
return loadingStage;
|
||||
}
|
||||
|
||||
private void initializeProjectAndOpenWindow(ProjectReference projectReference, Stage loadingStage) {
|
||||
ProjectSession projectSession = null;
|
||||
try {
|
||||
eventBus.publish(new StudioProjectLoadingProgressEvent(
|
||||
StudioProjectLoadingPhase.INITIALIZING_SERVICES,
|
||||
i18n.text(I18n.SHIELD_STATUS_INDEXING),
|
||||
Progress.INITIALIZING_SERVICES,
|
||||
false));
|
||||
projectWorkspaceInitializer.initialize(projectReference);
|
||||
eventBus.publish(new StudioProjectLoadingProgressEvent(
|
||||
StudioProjectLoadingPhase.RESTORING_WORKSPACES,
|
||||
i18n.text(I18n.SHIELD_STATUS_RESTORING),
|
||||
Progress.RESTORING_WORKSPACES,
|
||||
false));
|
||||
projectSession = projectSessionFactory.open(projectReference);
|
||||
final ProjectSession readySession = projectSession;
|
||||
synchronized (lifecycleMonitor) {
|
||||
if (closed) {
|
||||
projectSession.close();
|
||||
return;
|
||||
}
|
||||
pendingProjectSession = readySession;
|
||||
}
|
||||
Platform.runLater(() -> finishProjectOpen(readySession, loadingStage));
|
||||
} catch (RuntimeException exception) {
|
||||
if (projectSession != null) {
|
||||
projectSession.close();
|
||||
}
|
||||
Platform.runLater(() -> failProjectOpen(projectReference, loadingStage, exception));
|
||||
}
|
||||
}
|
||||
|
||||
private void finishProjectOpen(ProjectSession projectSession, Stage loadingStage) {
|
||||
synchronized (lifecycleMonitor) {
|
||||
if (closed || pendingProjectSession != projectSession) {
|
||||
projectSession.close();
|
||||
loadingStage.close();
|
||||
return;
|
||||
}
|
||||
pendingProjectSession = null;
|
||||
}
|
||||
final ProjectReference projectReference = projectSession.projectReference();
|
||||
projectStage = new Stage();
|
||||
mainView = new MainView(projectSession, shipper, executionControllerFactory, i18n, eventBus,
|
||||
executor, theme, assetCatalog, assetCommands, assetPacking, assetDetails, assetCreationCatalog,
|
||||
assetMetadataService, assetWorkspaceStorage, assetCapacityPolicy, bankCompositionSessionFactory,
|
||||
assetColorSchemaFactory, tiledAssetService, sceneBankWorkflow,
|
||||
activityHistoryStore);
|
||||
this.projectSession = projectSession;
|
||||
final Scene scene = new Scene(mainView, PROJECT_WIDTH, PROJECT_HEIGHT);
|
||||
scene.getStylesheets().add(theme.getDefaultTheme());
|
||||
|
||||
projectStage.setTitle(i18n.format(I18n.APP_PROJECT_TITLE, projectReference.name()));
|
||||
projectStage.setScene(scene);
|
||||
windowStateService.installProjectShellState(projectStage, projectReference, PROJECT_WIDTH, PROJECT_HEIGHT);
|
||||
projectStage.setOnHidden(ignored -> closeProjectAndReturnToLauncher());
|
||||
|
||||
eventBus.publish(new StudioProjectLoadingProgressEvent(
|
||||
StudioProjectLoadingPhase.READY,
|
||||
i18n.format(I18n.APP_PROJECT_TITLE, projectReference.name()),
|
||||
Progress.READY,
|
||||
false));
|
||||
eventBus.publish(new StudioProjectLoadingCompletedEvent());
|
||||
loadingStage.close();
|
||||
this.loadingStage = null;
|
||||
projectStage.show();
|
||||
projectStage.toFront();
|
||||
Platform.runLater(mainView::reapplyProjectLocalLayout);
|
||||
}
|
||||
|
||||
private void failProjectOpen(
|
||||
ProjectReference projectReference,
|
||||
Stage loadingStage,
|
||||
RuntimeException exception) {
|
||||
final String message = "Unable to initialize project services for " + projectReference.name() + ".";
|
||||
eventBus.publish(new StudioProjectLoadingFailedEvent(
|
||||
StudioProjectLoadingPhase.INITIALIZING_SERVICES,
|
||||
message));
|
||||
loadingStage.close();
|
||||
this.loadingStage = null;
|
||||
launcherStage.show();
|
||||
launcherStage.centerOnScreen();
|
||||
launcherStage.toFront();
|
||||
}
|
||||
|
||||
private void publishProjectLoadingStarted(ProjectReference projectReference) {
|
||||
eventBus.publish(new StudioProjectLoadingStartedEvent());
|
||||
eventBus.publish(new StudioProjectLoadingProgressEvent(
|
||||
StudioProjectLoadingPhase.RESOLVING_PROJECT,
|
||||
i18n.format(I18n.SHIELD_LOADING_PROJECT, projectReference.name()),
|
||||
Progress.RESOLVING_PROJECT,
|
||||
false));
|
||||
}
|
||||
|
||||
private void closeProjectAndReturnToLauncher() {
|
||||
RuntimeException failure = closeActiveProject(null);
|
||||
if (!closed) {
|
||||
failure = attempt(launcherView::reloadProjects, failure);
|
||||
failure = attempt(launcherStage::show, failure);
|
||||
failure = attempt(launcherStage::centerOnScreen, failure);
|
||||
failure = attempt(launcherStage::toFront, failure);
|
||||
}
|
||||
if (failure != null) {
|
||||
throw failure;
|
||||
}
|
||||
}
|
||||
|
||||
private RuntimeException closeActiveProject(RuntimeException prior) {
|
||||
final MainView view = mainView;
|
||||
final ProjectSession session = projectSession;
|
||||
mainView = null;
|
||||
projectSession = null;
|
||||
projectStage = null;
|
||||
RuntimeException failure = prior;
|
||||
if (view != null) {
|
||||
failure = attempt(view::close, failure);
|
||||
}
|
||||
if (session != null) {
|
||||
failure = attempt(session::close, failure);
|
||||
}
|
||||
return failure;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
final ProjectSession pending;
|
||||
synchronized (lifecycleMonitor) {
|
||||
if (closed) {
|
||||
return;
|
||||
}
|
||||
closed = true;
|
||||
pending = pendingProjectSession;
|
||||
pendingProjectSession = null;
|
||||
}
|
||||
|
||||
RuntimeException failure = null;
|
||||
final Stage activeProjectStage = projectStage;
|
||||
if (activeProjectStage != null) {
|
||||
failure = attempt(() -> activeProjectStage.setOnHidden(null), failure);
|
||||
failure = attempt(activeProjectStage::close, failure);
|
||||
}
|
||||
failure = closeActiveProject(failure);
|
||||
if (pending != null) {
|
||||
failure = attempt(pending::close, failure);
|
||||
}
|
||||
if (loadingStage != null) {
|
||||
failure = attempt(loadingStage::close, failure);
|
||||
loadingStage = null;
|
||||
}
|
||||
failure = attempt(launcherStage::close, failure);
|
||||
if (failure != null) {
|
||||
throw failure;
|
||||
}
|
||||
}
|
||||
|
||||
private static RuntimeException attempt(Runnable action, RuntimeException prior) {
|
||||
try {
|
||||
action.run();
|
||||
return prior;
|
||||
} catch (RuntimeException failure) {
|
||||
if (prior == null) {
|
||||
return failure;
|
||||
}
|
||||
prior.addSuppressed(failure);
|
||||
return prior;
|
||||
}
|
||||
}
|
||||
|
||||
private static final class Progress {
|
||||
private static final double RESOLVING_PROJECT = 0.20d;
|
||||
private static final double INITIALIZING_SERVICES = 0.58d;
|
||||
private static final double RESTORING_WORKSPACES = 0.86d;
|
||||
private static final double READY = 1.0d;
|
||||
|
||||
private Progress() {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
package p.studio.ui.javafx.window;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.stage.Stage;
|
||||
import p.studio.api.preferences.WindowGeometry;
|
||||
import p.studio.api.preferences.WindowStateStore;
|
||||
import p.studio.api.project.ProjectReference;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public final class WindowStateService {
|
||||
private final WindowStateStore store;
|
||||
|
||||
public WindowStateService(WindowStateStore store) {
|
||||
this.store = Objects.requireNonNull(store, "store");
|
||||
}
|
||||
|
||||
public void installLauncherState(Stage stage, double defaultWidth, double defaultHeight) {
|
||||
stage.setWidth(defaultWidth);
|
||||
stage.setHeight(defaultHeight);
|
||||
|
||||
stage.maximizedProperty().addListener((ignored, oldValue, newValue) -> {
|
||||
if (Boolean.TRUE.equals(newValue)) {
|
||||
Platform.runLater(() -> stage.setMaximized(false));
|
||||
}
|
||||
});
|
||||
stage.fullScreenProperty().addListener((ignored, oldValue, newValue) -> {
|
||||
if (Boolean.TRUE.equals(newValue)) {
|
||||
Platform.runLater(() -> stage.setFullScreen(false));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void installProjectShellState(
|
||||
Stage stage,
|
||||
ProjectReference projectReference,
|
||||
double defaultWidth,
|
||||
double defaultHeight) {
|
||||
final WindowGeometry state = store.load(projectReference).orElse(null);
|
||||
applyState(stage, state, defaultWidth, defaultHeight);
|
||||
|
||||
stage.xProperty().addListener((ignored, oldValue, newValue) -> saveProjectState(projectReference, stage));
|
||||
stage.yProperty().addListener((ignored, oldValue, newValue) -> saveProjectState(projectReference, stage));
|
||||
stage.widthProperty().addListener((ignored, oldValue, newValue) -> saveProjectState(projectReference, stage));
|
||||
stage.heightProperty().addListener((ignored, oldValue, newValue) -> saveProjectState(projectReference, stage));
|
||||
stage.maximizedProperty().addListener((ignored, oldValue, newValue) -> saveProjectState(projectReference, stage));
|
||||
}
|
||||
|
||||
private void applyState(Stage stage, WindowGeometry state, double defaultWidth, double defaultHeight) {
|
||||
stage.setWidth(state != null && state.width() > 0 ? state.width() : defaultWidth);
|
||||
stage.setHeight(state != null && state.height() > 0 ? state.height() : defaultHeight);
|
||||
if (state != null && !Double.isNaN(state.x())) {
|
||||
stage.setX(state.x());
|
||||
}
|
||||
if (state != null && !Double.isNaN(state.y())) {
|
||||
stage.setY(state.y());
|
||||
}
|
||||
if (state != null && state.maximized()) {
|
||||
stage.setMaximized(true);
|
||||
}
|
||||
}
|
||||
|
||||
private void saveProjectState(ProjectReference projectReference, Stage stage) {
|
||||
store.save(projectReference, new WindowGeometry(
|
||||
stage.getX(),
|
||||
stage.getY(),
|
||||
stage.getWidth(),
|
||||
stage.getHeight(),
|
||||
stage.isMaximized()));
|
||||
}
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
package p.studio.ui.javafx.workspaces;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.value.ChangeListener;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.Scene;
|
||||
import p.studio.ui.javafx.controls.lifecycle.StudioControlLifecycle;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public final class StudioWorkspaceLifecycleSupport {
|
||||
private StudioWorkspaceLifecycleSupport() {
|
||||
}
|
||||
|
||||
public static void activate(Workspace workspace) {
|
||||
final Workspace target = Objects.requireNonNull(workspace, "workspace");
|
||||
final Node rootNode = target.rootNode();
|
||||
final Scene scene = rootNode.getScene();
|
||||
if (scene != null) {
|
||||
activateNow(target);
|
||||
return;
|
||||
}
|
||||
|
||||
rootNode.sceneProperty().addListener(new ChangeListener<>() {
|
||||
@Override
|
||||
public void changed(
|
||||
ObservableValue<? extends Scene> observable,
|
||||
Scene oldScene,
|
||||
Scene newScene) {
|
||||
if (newScene == null) {
|
||||
return;
|
||||
}
|
||||
rootNode.sceneProperty().removeListener(this);
|
||||
activateNow(target);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void deactivate(Workspace workspace) {
|
||||
final Workspace target = Objects.requireNonNull(workspace, "workspace");
|
||||
target.unLoad();
|
||||
final List<StudioControlLifecycle> participants = target.lifecycleParticipants();
|
||||
for (int index = participants.size() - 1; index >= 0; index--) {
|
||||
participants.get(index).unsubscribe();
|
||||
}
|
||||
}
|
||||
|
||||
private static void activateNow(Workspace workspace) {
|
||||
Platform.runLater(() -> {
|
||||
final List<StudioControlLifecycle> participants = workspace.lifecycleParticipants();
|
||||
for (StudioControlLifecycle participant : participants) {
|
||||
participant.subscribe();
|
||||
}
|
||||
workspace.load();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package p.studio.ui.javafx.workspaces;
|
||||
|
||||
import p.studio.ui.javafx.controls.lifecycle.StudioControlLifecycle;
|
||||
import p.studio.ui.javafx.events.StudioWorkspaceEventBus;
|
||||
import p.studio.api.project.ProjectReference;
|
||||
import p.studio.ui.javafx.utilities.i18n.I18n;
|
||||
import p.studio.ui.javafx.events.StudioEventBus;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class Workspace {
|
||||
protected final ProjectReference projectReference;
|
||||
protected final StudioWorkspaceEventBus workspaceEventBus;
|
||||
|
||||
public Workspace(final ProjectReference projectReference, final StudioEventBus eventBus) {
|
||||
this.projectReference = projectReference;
|
||||
this.workspaceEventBus = new StudioWorkspaceEventBus(workspaceId(), eventBus);
|
||||
}
|
||||
|
||||
public abstract WorkspaceId workspaceId();
|
||||
public abstract I18n title();
|
||||
public abstract javafx.scene.Node rootNode();
|
||||
public abstract void load();
|
||||
public abstract void unLoad();
|
||||
|
||||
public List<StudioControlLifecycle> lifecycleParticipants() {
|
||||
return List.of();
|
||||
}
|
||||
}
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
package p.studio.ui.javafx.workspaces;
|
||||
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.layout.StackPane;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
|
||||
public final class WorkspaceHost extends StackPane {
|
||||
private final Map<WorkspaceId, Workspace> workspaces = new EnumMap<>(WorkspaceId.class);
|
||||
@Getter
|
||||
private WorkspaceId currentWorkspaceId;
|
||||
|
||||
public void register(Workspace ws) {
|
||||
workspaces.put(ws.workspaceId(), ws);
|
||||
|
||||
Node r = ws.rootNode();
|
||||
r.setVisible(false);
|
||||
r.setManaged(false);
|
||||
getChildren().add(r);
|
||||
}
|
||||
|
||||
public void change(final WorkspaceId id) {
|
||||
if (currentWorkspaceId == id) return;
|
||||
|
||||
deactivateCurrentWorkspace();
|
||||
|
||||
final var nextWorkspace = workspaces.get(id);
|
||||
if (nextWorkspace == null) {
|
||||
throw new IllegalStateException("Workspace not registered: " + id);
|
||||
}
|
||||
|
||||
final var n = nextWorkspace.rootNode();
|
||||
n.setVisible(true);
|
||||
n.setManaged(true);
|
||||
|
||||
currentWorkspaceId = id;
|
||||
StudioWorkspaceLifecycleSupport.activate(nextWorkspace);
|
||||
}
|
||||
|
||||
public void deactivateCurrentWorkspace() {
|
||||
if (currentWorkspaceId == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final var oldWorkspace = workspaces.get(currentWorkspaceId);
|
||||
if (oldWorkspace != null) {
|
||||
StudioWorkspaceLifecycleSupport.deactivate(oldWorkspace);
|
||||
final var n = oldWorkspace.rootNode();
|
||||
n.setVisible(false);
|
||||
n.setManaged(false);
|
||||
}
|
||||
currentWorkspaceId = null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package p.studio.ui.javafx.workspaces;
|
||||
|
||||
public enum WorkspaceId {
|
||||
ASSETS,
|
||||
SHIPPER,
|
||||
DEBUG
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
package p.studio.ui.javafx.workspaces.assets;
|
||||
|
||||
import p.studio.ui.javafx.events.StudioEventBus;
|
||||
import p.studio.ui.javafx.events.StudioPackerOperationEvent;
|
||||
import p.studio.ui.javafx.events.StudioWorkspaceEventBus;
|
||||
import p.studio.ui.javafx.utilities.i18n.I18n;
|
||||
import p.studio.ui.javafx.utilities.i18n.I18nService;
|
||||
import p.studio.ui.javafx.utilities.logspane.LogsPane;
|
||||
import p.studio.ui.javafx.workspaces.assets.messages.events.StudioAssetLogEvent;
|
||||
import p.studio.ui.javafx.workspaces.assets.messages.events.StudioAssetsWorkspaceRefreshFailedEvent;
|
||||
import p.studio.ui.javafx.workspaces.assets.messages.events.StudioAssetsWorkspaceRefreshStartedEvent;
|
||||
import p.studio.ui.javafx.workspaces.assets.messages.events.StudioAssetsWorkspaceRefreshedEvent;
|
||||
import p.studio.ui.javafx.workspaces.framework.StudioEventAware;
|
||||
import p.studio.ui.javafx.workspaces.framework.StudioEventBindings;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public final class AssetLogsPane extends LogsPane implements StudioEventAware {
|
||||
private final StudioWorkspaceEventBus workspaceBus;
|
||||
private final StudioEventBus eventBus;
|
||||
private final StudioEventBindings eventBindings = new StudioEventBindings();
|
||||
|
||||
public AssetLogsPane(StudioWorkspaceEventBus workspaceBus, StudioEventBus eventBus, I18nService i18n) {
|
||||
super(Objects.requireNonNull(i18n, "i18n").bind(I18n.ASSETS_LOGS_TITLE), "assets", false);
|
||||
this.workspaceBus = Objects.requireNonNull(workspaceBus, "workspaceBus");
|
||||
this.eventBus = Objects.requireNonNull(eventBus, "eventBus");
|
||||
}
|
||||
|
||||
@Override
|
||||
public StudioEventBindings eventBindings() {
|
||||
return eventBindings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerEventSubscriptions() {
|
||||
eventBindings.listen(workspaceBus, StudioAssetLogEvent.class).handle(event -> {
|
||||
appendLine("[" + event.source() + "] " + event.message());
|
||||
});
|
||||
eventBindings.listen(workspaceBus, StudioAssetsWorkspaceRefreshStartedEvent.class).handle(event -> {
|
||||
appendLine("[refresh] Asset scan started.");
|
||||
});
|
||||
eventBindings.listen(workspaceBus, StudioAssetsWorkspaceRefreshedEvent.class).handle(event -> {
|
||||
appendLine("[refresh] " + event.assetCount() + " assets loaded.");
|
||||
});
|
||||
eventBindings.listen(workspaceBus, StudioAssetsWorkspaceRefreshFailedEvent.class).handle(event -> {
|
||||
appendLine("[error] " + event.message());
|
||||
});
|
||||
eventBindings.listen(eventBus, StudioPackerOperationEvent.class).handle(event -> {
|
||||
appendLine("[" + event.kind().name().toLowerCase() + "] " + event.summary());
|
||||
});
|
||||
}
|
||||
}
|
||||
+267
@@ -0,0 +1,267 @@
|
||||
package p.studio.ui.javafx.workspaces.assets;
|
||||
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.SplitPane;
|
||||
import javafx.scene.layout.BorderPane;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.Priority;
|
||||
import javafx.scene.layout.VBox;
|
||||
import p.studio.api.assets.AssetCatalog;
|
||||
import p.studio.api.assets.AssetCommands;
|
||||
import p.studio.api.assets.AssetPacking;
|
||||
import p.studio.api.assets.AssetDetails;
|
||||
import p.studio.api.assets.AssetCreationCatalog;
|
||||
import p.studio.api.assets.AssetWorkspaceStorage;
|
||||
import p.studio.api.assets.AssetCapacityPolicy;
|
||||
import p.studio.api.assets.schema.AssetColorSchemaFactory;
|
||||
import p.studio.api.assets.bank.AssetBankCompositionSessionFactory;
|
||||
import p.studio.api.assets.metadata.AssetMetadataService;
|
||||
import p.studio.api.assets.scene.SceneBankWorkflow;
|
||||
import p.studio.api.assets.tiled.TiledAssetService;
|
||||
import p.studio.api.project.ProjectLocalStudioState;
|
||||
import p.studio.api.project.ProjectReference;
|
||||
import p.studio.ui.javafx.utilities.i18n.I18n;
|
||||
import p.studio.ui.javafx.workspaces.Workspace;
|
||||
import p.studio.ui.javafx.workspaces.WorkspaceId;
|
||||
import p.studio.ui.javafx.workspaces.assets.details.AssetDetailsControl;
|
||||
import p.studio.ui.javafx.workspaces.assets.list.AssetListControl;
|
||||
import p.studio.ui.javafx.workspaces.assets.messages.events.StudioAssetsRefreshRequestedEvent;
|
||||
import p.studio.ui.javafx.workspaces.assets.messages.events.StudioAssetsWorkspaceSelectionRequestedEvent;
|
||||
import p.studio.ui.javafx.workspaces.assets.wizards.AddAssetWizard;
|
||||
import p.studio.ui.javafx.workspaces.assets.wizards.PackWorkspaceWizard;
|
||||
import p.studio.ui.javafx.events.StudioEventBus;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public final class AssetWorkspace extends Workspace {
|
||||
private final BorderPane root = new BorderPane();
|
||||
private final AssetListControl assetListControl;
|
||||
private final AssetDetailsControl detailsControl;
|
||||
private final AssetLogsPane logsPane;
|
||||
private SplitPane splitPane;
|
||||
private Runnable stateChangedAction = () -> { };
|
||||
private ProjectLocalStudioState.AssetsLayoutState pendingAssetsLayoutState = ProjectLocalStudioState.AssetsLayoutState.defaults();
|
||||
private boolean applyingPendingLayoutState;
|
||||
private final java.util.concurrent.Executor executor;
|
||||
private final p.studio.ui.javafx.utilities.i18n.I18nService i18n;
|
||||
private final p.studio.ui.javafx.utilities.ThemeService theme;
|
||||
private final AssetCommands assetCommands;
|
||||
private final AssetPacking assetPacking;
|
||||
private final AssetCreationCatalog assetCreationCatalog;
|
||||
private final AssetMetadataService assetMetadataService;
|
||||
private final AssetWorkspaceStorage assetWorkspaceStorage;
|
||||
private final AssetCapacityPolicy assetCapacityPolicy;
|
||||
|
||||
public AssetWorkspace(final ProjectReference projectReference, final StudioEventBus eventBus,
|
||||
final p.studio.ui.javafx.utilities.i18n.I18nService i18n,
|
||||
final java.util.concurrent.Executor executor,
|
||||
final p.studio.ui.javafx.utilities.ThemeService theme,
|
||||
final AssetCatalog assetCatalog,
|
||||
final AssetCommands assetCommands,
|
||||
final AssetPacking assetPacking,
|
||||
final AssetDetails assetDetails,
|
||||
final AssetCreationCatalog assetCreationCatalog,
|
||||
final AssetMetadataService assetMetadataService,
|
||||
final AssetWorkspaceStorage assetWorkspaceStorage,
|
||||
final AssetCapacityPolicy assetCapacityPolicy,
|
||||
final AssetBankCompositionSessionFactory bankCompositionSessionFactory,
|
||||
final AssetColorSchemaFactory assetColorSchemaFactory,
|
||||
final TiledAssetService tiledAssetService,
|
||||
final SceneBankWorkflow sceneBankWorkflow) {
|
||||
super(projectReference, eventBus);
|
||||
this.executor = executor;
|
||||
this.i18n = i18n;
|
||||
this.theme = theme;
|
||||
this.assetCommands = java.util.Objects.requireNonNull(assetCommands, "assetCommands");
|
||||
this.assetPacking = java.util.Objects.requireNonNull(assetPacking, "assetPacking");
|
||||
this.assetCreationCatalog = java.util.Objects.requireNonNull(assetCreationCatalog, "assetCreationCatalog");
|
||||
this.assetMetadataService = java.util.Objects.requireNonNull(assetMetadataService, "assetMetadataService");
|
||||
this.assetWorkspaceStorage = java.util.Objects.requireNonNull(assetWorkspaceStorage, "assetWorkspaceStorage");
|
||||
this.assetCapacityPolicy = java.util.Objects.requireNonNull(assetCapacityPolicy, "assetCapacityPolicy");
|
||||
this.assetListControl = new AssetListControl(this.projectReference, this.workspaceEventBus, i18n, executor, assetCatalog);
|
||||
this.detailsControl = new AssetDetailsControl(this.projectReference, this.workspaceEventBus, i18n, executor, theme,
|
||||
assetCatalog, assetCommands, assetDetails, assetMetadataService, assetCapacityPolicy,
|
||||
bankCompositionSessionFactory, assetColorSchemaFactory, tiledAssetService,
|
||||
sceneBankWorkflow);
|
||||
this.logsPane = new AssetLogsPane(this.workspaceEventBus, eventBus, i18n);
|
||||
root.getStyleClass().add("assets-workspace");
|
||||
root.setCenter(buildLayout());
|
||||
root.setBottom(logsPane.getPane());
|
||||
}
|
||||
|
||||
@Override
|
||||
public WorkspaceId workspaceId() {
|
||||
return WorkspaceId.ASSETS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public I18n title() {
|
||||
return I18n.WORKSPACE_ASSETS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Node rootNode() {
|
||||
return root;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
reapplyPendingLayoutState();
|
||||
schedulePendingLayoutReapply();
|
||||
workspaceEventBus.publish(new StudioAssetsRefreshRequestedEvent());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unLoad() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<p.studio.ui.javafx.controls.lifecycle.StudioControlLifecycle> lifecycleParticipants() {
|
||||
return List.of(assetListControl, detailsControl, logsPane);
|
||||
}
|
||||
|
||||
public void setStateChangedAction(final Runnable stateChangedAction) {
|
||||
this.stateChangedAction = java.util.Objects.requireNonNull(stateChangedAction, "stateChangedAction");
|
||||
}
|
||||
|
||||
public void restoreProjectLocalState(final ProjectLocalStudioState projectLocalStudioState) {
|
||||
pendingAssetsLayoutState = projectLocalStudioState.shellLayout().assetsLayout();
|
||||
reapplyPendingLayoutState();
|
||||
schedulePendingLayoutReapply();
|
||||
}
|
||||
|
||||
public void reapplyPendingLayoutState() {
|
||||
if (splitPane == null || pendingAssetsLayoutState.contentSplitDividers().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
applyingPendingLayoutState = true;
|
||||
splitPane.setDividerPositions(pendingAssetsLayoutState.contentSplitDividers().stream()
|
||||
.mapToDouble(Double::doubleValue)
|
||||
.toArray());
|
||||
javafx.application.Platform.runLater(() -> applyingPendingLayoutState = false);
|
||||
}
|
||||
|
||||
public ProjectLocalStudioState.AssetsLayoutState captureLayoutState() {
|
||||
if (splitPane == null || splitPane.getDividers().isEmpty()) {
|
||||
return ProjectLocalStudioState.AssetsLayoutState.defaults();
|
||||
}
|
||||
return new ProjectLocalStudioState.AssetsLayoutState(
|
||||
splitPane.getDividers().stream()
|
||||
.map(SplitPane.Divider::getPosition)
|
||||
.toList());
|
||||
}
|
||||
|
||||
private VBox buildLayout() {
|
||||
final var topProgress = createTopProgressBox();
|
||||
final var actionBar = createActionBar();
|
||||
final var splitPane = createAssetSplitPane();
|
||||
return new VBox(10, topProgress, actionBar, splitPane);
|
||||
}
|
||||
|
||||
private VBox createTopProgressBox() {
|
||||
final var topProgress = new VBox(6);
|
||||
topProgress.getStyleClass().add("assets-workspace-inline-progress");
|
||||
return topProgress;
|
||||
}
|
||||
|
||||
private HBox createActionBar() {
|
||||
final var refreshButton = createRefreshButton();
|
||||
final var addAssetButton = createAddAssetButton();
|
||||
final var packButton = createPackButton();
|
||||
final var workspaceActionBar = new HBox(8, refreshButton, addAssetButton, packButton);
|
||||
workspaceActionBar.setAlignment(Pos.CENTER_LEFT);
|
||||
workspaceActionBar.getStyleClass().add("assets-workspace-action-bar");
|
||||
return workspaceActionBar;
|
||||
}
|
||||
|
||||
private Button createRefreshButton() {
|
||||
final var refreshButton = new Button();
|
||||
refreshButton.textProperty().bind(i18n.bind(I18n.ASSETS_NAVIGATOR_ACTION_REFRESH));
|
||||
refreshButton.getStyleClass().addAll("studio-button", "studio-button-primary", "assets-workspace-action-button");
|
||||
refreshButton.setMaxWidth(Double.MAX_VALUE);
|
||||
refreshButton.setOnAction(event -> refreshAssets());
|
||||
return refreshButton;
|
||||
}
|
||||
|
||||
private void refreshAssets() {
|
||||
workspaceEventBus.publish(new StudioAssetsRefreshRequestedEvent(null, true));
|
||||
}
|
||||
|
||||
private Button createAddAssetButton() {
|
||||
final var addAssetButton = new Button();
|
||||
addAssetButton.textProperty().bind(i18n.bind(I18n.ASSETS_NAVIGATOR_ACTION_ADD));
|
||||
addAssetButton.getStyleClass().addAll(
|
||||
"studio-button",
|
||||
"studio-button-secondary",
|
||||
"studio-button-add-asset",
|
||||
"assets-workspace-action-button");
|
||||
addAssetButton.setOnAction(event -> openAddAssetWizard());
|
||||
return addAssetButton;
|
||||
}
|
||||
|
||||
private Button createPackButton() {
|
||||
final var packButton = new Button();
|
||||
packButton.textProperty().bind(i18n.bind(I18n.ASSETS_NAVIGATOR_ACTION_PACK));
|
||||
packButton.getStyleClass().addAll(
|
||||
"studio-button",
|
||||
"studio-button-secondary",
|
||||
"assets-workspace-action-button");
|
||||
packButton.setOnAction(event -> openPackWizard());
|
||||
return packButton;
|
||||
}
|
||||
|
||||
private void openAddAssetWizard() {
|
||||
if (root.getScene() == null) {
|
||||
return;
|
||||
}
|
||||
AddAssetWizard.showAndWait(root.getScene().getWindow(), projectReference, executor, i18n, theme,
|
||||
assetCommands, assetCreationCatalog, assetMetadataService, assetWorkspaceStorage).ifPresent(assetReference -> {
|
||||
workspaceEventBus.publish(new StudioAssetsRefreshRequestedEvent(assetReference));
|
||||
});
|
||||
}
|
||||
|
||||
private void openPackWizard() {
|
||||
if (root.getScene() == null) {
|
||||
return;
|
||||
}
|
||||
PackWorkspaceWizard.showAndWait(root.getScene().getWindow(), projectReference, i18n, theme,
|
||||
assetPacking, assetCapacityPolicy);
|
||||
}
|
||||
|
||||
private SplitPane createAssetSplitPane() {
|
||||
splitPane = new SplitPane(assetListControl, detailsControl);
|
||||
splitPane.setDividerPositions(0.34);
|
||||
splitPane.getStyleClass().add("assets-workspace-split");
|
||||
splitPane.getDividers().forEach(divider ->
|
||||
divider.positionProperty().addListener((ignored, previous, current) -> {
|
||||
if (applyingPendingLayoutState) {
|
||||
return;
|
||||
}
|
||||
pendingAssetsLayoutState = captureLayoutState();
|
||||
stateChangedAction.run();
|
||||
}));
|
||||
VBox.setVgrow(splitPane, Priority.ALWAYS);
|
||||
return splitPane;
|
||||
}
|
||||
|
||||
private void schedulePendingLayoutReapply() {
|
||||
if (splitPane == null) {
|
||||
return;
|
||||
}
|
||||
if (splitPane.getWidth() > 0) {
|
||||
javafx.application.Platform.runLater(this::reapplyPendingLayoutState);
|
||||
return;
|
||||
}
|
||||
final javafx.beans.value.ChangeListener<Number>[] listenerRef = new javafx.beans.value.ChangeListener[1];
|
||||
listenerRef[0] = (ignored, previous, current) -> {
|
||||
if (current == null || current.doubleValue() <= 0) {
|
||||
return;
|
||||
}
|
||||
splitPane.widthProperty().removeListener(listenerRef[0]);
|
||||
javafx.application.Platform.runLater(this::reapplyPendingLayoutState);
|
||||
};
|
||||
splitPane.widthProperty().addListener(listenerRef[0]);
|
||||
}
|
||||
}
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
package p.studio.ui.javafx.workspaces.assets;
|
||||
|
||||
import p.studio.api.assets.AssetReference;
|
||||
import p.studio.api.assets.workspace.AssetWorkspaceAssetSummary;
|
||||
import p.studio.ui.javafx.workspaces.assets.messages.AssetWorkspaceStatus;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
public record AssetWorkspaceState(
|
||||
AssetWorkspaceStatus status,
|
||||
List<AssetWorkspaceAssetSummary> assets,
|
||||
AssetReference selectedAssetReference,
|
||||
String errorMessage) {
|
||||
|
||||
public AssetWorkspaceState {
|
||||
Objects.requireNonNull(status, "status");
|
||||
assets = List.copyOf(Objects.requireNonNull(assets, "assets"));
|
||||
}
|
||||
|
||||
public static AssetWorkspaceState loading(AssetWorkspaceState previous) {
|
||||
if (previous == null) {
|
||||
return new AssetWorkspaceState(AssetWorkspaceStatus.LOADING, List.of(), null, null);
|
||||
}
|
||||
return new AssetWorkspaceState(AssetWorkspaceStatus.LOADING, previous.assets(), previous.selectedAssetReference(), null);
|
||||
}
|
||||
|
||||
public static AssetWorkspaceState ready(List<AssetWorkspaceAssetSummary> assets, AssetReference preferredAssetReference) {
|
||||
final List<AssetWorkspaceAssetSummary> normalizedAssets = normalizeAssets(assets);
|
||||
final AssetReference resolvedSelection = reconcileSelection(normalizedAssets, preferredAssetReference);
|
||||
final AssetWorkspaceStatus status = normalizedAssets.isEmpty() ? AssetWorkspaceStatus.EMPTY : AssetWorkspaceStatus.READY;
|
||||
return new AssetWorkspaceState(status, normalizedAssets, resolvedSelection, null);
|
||||
}
|
||||
|
||||
public static AssetWorkspaceState error(AssetWorkspaceState previous, String errorMessage) {
|
||||
return new AssetWorkspaceState(
|
||||
AssetWorkspaceStatus.ERROR,
|
||||
previous == null ? List.of() : previous.assets(),
|
||||
previous == null ? null : previous.selectedAssetReference(),
|
||||
Objects.requireNonNullElse(errorMessage, "Unknown asset workspace error"));
|
||||
}
|
||||
|
||||
public Optional<AssetWorkspaceAssetSummary> selectedAsset() {
|
||||
if (selectedAssetReference == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return assets.stream()
|
||||
.filter(asset -> asset.assetReference().equals(selectedAssetReference))
|
||||
.findFirst();
|
||||
}
|
||||
|
||||
public AssetWorkspaceState withSelection(AssetReference nextAssetReference) {
|
||||
final AssetReference resolvedSelection = reconcileSelection(assets, nextAssetReference);
|
||||
return new AssetWorkspaceState(status, assets, resolvedSelection, errorMessage);
|
||||
}
|
||||
|
||||
static AssetReference reconcileSelection(
|
||||
List<AssetWorkspaceAssetSummary> assets,
|
||||
AssetReference preferredAssetReference) {
|
||||
if (assets.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
if (preferredAssetReference != null) {
|
||||
for (AssetWorkspaceAssetSummary asset : assets) {
|
||||
if (asset.assetReference().equals(preferredAssetReference)) {
|
||||
return preferredAssetReference;
|
||||
}
|
||||
}
|
||||
}
|
||||
return assets.getFirst().assetReference();
|
||||
}
|
||||
|
||||
private static List<AssetWorkspaceAssetSummary> normalizeAssets(List<AssetWorkspaceAssetSummary> assets) {
|
||||
return List.copyOf(Objects.requireNonNull(assets, "assets").stream()
|
||||
.sorted(Comparator
|
||||
.comparing((AssetWorkspaceAssetSummary asset) -> asset.assetRoot().toString(), String.CASE_INSENSITIVE_ORDER)
|
||||
.thenComparing(AssetWorkspaceAssetSummary::assetName, String.CASE_INSENSITIVE_ORDER))
|
||||
.toList());
|
||||
}
|
||||
}
|
||||
+783
@@ -0,0 +1,783 @@
|
||||
package p.studio.ui.javafx.workspaces.assets.details;
|
||||
|
||||
import p.studio.api.assets.workspace.*;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.Priority;
|
||||
import javafx.scene.layout.VBox;
|
||||
import p.studio.api.assets.AssetDiagnostic;
|
||||
import p.studio.api.assets.AssetFamily;
|
||||
import p.studio.ui.javafx.controls.forms.StudioFormEditScopeChangedEvent;
|
||||
import p.studio.api.assets.AssetReference;
|
||||
import p.studio.api.assets.AssetCatalog;
|
||||
import p.studio.api.assets.AssetCommands;
|
||||
import p.studio.api.assets.AssetMutationResult;
|
||||
import p.studio.api.assets.AssetDetails;
|
||||
import p.studio.api.assets.AssetDetailsSnapshot;
|
||||
import p.studio.api.assets.AssetCapacityPolicy;
|
||||
import p.studio.api.assets.schema.AssetColorSchemaFactory;
|
||||
import p.studio.api.assets.bank.AssetBankCompositionSessionFactory;
|
||||
import p.studio.ui.javafx.controls.forms.StudioSection;
|
||||
import p.studio.ui.javafx.events.StudioWorkspaceEventBus;
|
||||
import p.studio.api.project.ProjectReference;
|
||||
import p.studio.ui.javafx.utilities.i18n.I18n;
|
||||
import p.studio.ui.javafx.workspaces.assets.details.bank.AssetDetailsBankCompositionControl;
|
||||
import p.studio.ui.javafx.workspaces.assets.details.contract.AssetDetailsContractControl;
|
||||
import p.studio.ui.javafx.workspaces.assets.details.palette.AssetDetailsPaletteOverhaulingControl;
|
||||
import p.studio.ui.javafx.workspaces.assets.details.scene.AssetDetailsSceneLayersControl;
|
||||
import p.studio.ui.javafx.workspaces.assets.details.schema.AssetDetailsColorSchemaGroupsControl;
|
||||
import p.studio.ui.javafx.workspaces.assets.details.summary.AssetDetailsSummaryControl;
|
||||
import p.studio.ui.javafx.workspaces.assets.dialogs.AssetDiagnosticsDialog;
|
||||
import p.studio.ui.javafx.workspaces.assets.messages.*;
|
||||
import p.studio.ui.javafx.workspaces.assets.messages.events.*;
|
||||
import p.studio.api.assets.metadata.AssetStudioGlyphSpecialization;
|
||||
import p.studio.api.assets.metadata.AssetMetadataService;
|
||||
import p.studio.api.assets.metadata.AssetStudioMetadataSnapshot;
|
||||
import p.studio.api.assets.scene.SceneBankWorkflow;
|
||||
import p.studio.api.assets.scene.SceneBankWorkflowResult;
|
||||
import p.studio.api.assets.tiled.SceneTmxExportDisposition;
|
||||
import p.studio.api.assets.tiled.TiledAssetGenerationResult;
|
||||
import p.studio.api.assets.tiled.TiledAssetService;
|
||||
import p.studio.ui.javafx.workspaces.assets.wizards.DeleteAssetDialog;
|
||||
import p.studio.ui.javafx.workspaces.assets.wizards.MoveAssetWizard;
|
||||
import p.studio.ui.javafx.workspaces.framework.StudioEventAware;
|
||||
import p.studio.ui.javafx.workspaces.framework.StudioEventBindings;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import static java.util.Comparator.comparingInt;
|
||||
|
||||
public final class AssetDetailsControl extends VBox implements StudioEventAware {
|
||||
private final ProjectReference projectReference;
|
||||
private final StudioWorkspaceEventBus workspaceBus;
|
||||
private final StudioEventBindings eventBindings = new StudioEventBindings();
|
||||
private final Label detailsTitleLabel = new Label();
|
||||
private final Label workspaceSummaryLabel = new Label();
|
||||
private final VBox detailsContent = new VBox(12);
|
||||
private final ScrollPane detailsScroll = new ScrollPane();
|
||||
private final AssetDetailsSummaryControl summaryControl;
|
||||
private final AssetDetailsContractControl contractControl;
|
||||
private final AssetDetailsBankCompositionControl bankCompositionControl;
|
||||
private final AssetDetailsColorSchemaGroupsControl colorSchemaGroupsControl;
|
||||
private final AssetDetailsPaletteOverhaulingControl paletteOverhaulingControl;
|
||||
private final AssetDetailsSceneLayersControl sceneLayersControl;
|
||||
private final AssetMetadataService studioMetadataService;
|
||||
private final TiledAssetService tiledGenerationService;
|
||||
private final SceneBankWorkflow sceneBankWorkflowService;
|
||||
private final VBox actionsContent = new VBox(10);
|
||||
private final ScrollPane actionsScroll = new ScrollPane();
|
||||
private final VBox actionsSection;
|
||||
private final HBox primarySectionsRow = new HBox(12);
|
||||
private final AtomicLong loadGeneration = new AtomicLong();
|
||||
private final java.util.concurrent.Executor executor;
|
||||
private final p.studio.ui.javafx.utilities.i18n.I18nService i18n;
|
||||
private final p.studio.ui.javafx.utilities.ThemeService theme;
|
||||
private final AssetCommands assetCommands;
|
||||
private final AssetDetails assetDetails;
|
||||
|
||||
private AssetWorkspaceDetailsViewState viewState = AssetDetailsViewStateFactory.empty();
|
||||
private boolean readyMounted;
|
||||
private boolean actionRunning;
|
||||
private String actionFeedbackMessage;
|
||||
|
||||
public AssetDetailsControl(
|
||||
ProjectReference projectReference,
|
||||
StudioWorkspaceEventBus workspaceBus,
|
||||
p.studio.ui.javafx.utilities.i18n.I18nService i18n,
|
||||
java.util.concurrent.Executor executor,
|
||||
p.studio.ui.javafx.utilities.ThemeService theme,
|
||||
AssetCatalog assetCatalog,
|
||||
AssetCommands assetCommands,
|
||||
AssetDetails assetDetails,
|
||||
AssetMetadataService assetMetadataService,
|
||||
AssetCapacityPolicy assetCapacityPolicy,
|
||||
AssetBankCompositionSessionFactory bankCompositionSessionFactory,
|
||||
AssetColorSchemaFactory assetColorSchemaFactory,
|
||||
TiledAssetService tiledAssetService,
|
||||
SceneBankWorkflow sceneBankWorkflow) {
|
||||
this.projectReference = Objects.requireNonNull(projectReference, "projectReference");
|
||||
this.workspaceBus = Objects.requireNonNull(workspaceBus, "workspaceBus");
|
||||
this.executor = Objects.requireNonNull(executor, "executor");
|
||||
this.i18n = Objects.requireNonNull(i18n, "i18n");
|
||||
this.theme = Objects.requireNonNull(theme, "theme");
|
||||
this.assetCommands = Objects.requireNonNull(assetCommands, "assetCommands");
|
||||
this.assetDetails = Objects.requireNonNull(assetDetails, "assetDetails");
|
||||
this.studioMetadataService = Objects.requireNonNull(assetMetadataService, "assetMetadataService");
|
||||
this.tiledGenerationService = Objects.requireNonNull(tiledAssetService, "tiledAssetService");
|
||||
this.sceneBankWorkflowService = Objects.requireNonNull(sceneBankWorkflow, "sceneBankWorkflow");
|
||||
this.summaryControl = new AssetDetailsSummaryControl(projectReference, workspaceBus, i18n);
|
||||
this.contractControl = new AssetDetailsContractControl(projectReference, workspaceBus, i18n, executor, assetCommands);
|
||||
this.bankCompositionControl = new AssetDetailsBankCompositionControl(projectReference, workspaceBus, i18n, executor,
|
||||
assetDetails, assetCommands, bankCompositionSessionFactory);
|
||||
this.colorSchemaGroupsControl = new AssetDetailsColorSchemaGroupsControl(projectReference, workspaceBus, i18n, executor,
|
||||
assetMetadataService, assetColorSchemaFactory);
|
||||
this.paletteOverhaulingControl = new AssetDetailsPaletteOverhaulingControl(projectReference, workspaceBus, i18n, executor, theme,
|
||||
assetCommands, assetMetadataService, assetColorSchemaFactory);
|
||||
this.sceneLayersControl = new AssetDetailsSceneLayersControl(projectReference, workspaceBus, i18n, executor, assetCatalog,
|
||||
assetMetadataService);
|
||||
this.actionsSection = createActionsSection();
|
||||
|
||||
getStyleClass().add("assets-workspace-pane");
|
||||
setSpacing(10);
|
||||
|
||||
detailsTitleLabel.getStyleClass().addAll("assets-workspace-pane-title", "assets-workspace-details-title");
|
||||
|
||||
workspaceSummaryLabel.getStyleClass().add("assets-workspace-summary");
|
||||
detailsContent.getStyleClass().add("assets-workspace-details-content");
|
||||
primarySectionsRow.getStyleClass().add("assets-details-summary-actions-row");
|
||||
primarySectionsRow.setFillHeight(true);
|
||||
HBox.setHgrow(summaryControl, Priority.ALWAYS);
|
||||
HBox.setHgrow(actionsSection, Priority.ALWAYS);
|
||||
summaryControl.setMaxWidth(Double.MAX_VALUE);
|
||||
actionsSection.setMaxWidth(Double.MAX_VALUE);
|
||||
contractControl.setMaxWidth(Double.MAX_VALUE);
|
||||
summaryControl.prefWidthProperty().bind(primarySectionsRow.widthProperty().multiply(0.70d));
|
||||
actionsSection.prefWidthProperty().bind(primarySectionsRow.widthProperty().multiply(0.30d));
|
||||
primarySectionsRow.getChildren().setAll(summaryControl, actionsSection);
|
||||
summaryControl.heightProperty().addListener((ignored, oldValue, newValue) -> syncActionsSectionHeight(newValue.doubleValue()));
|
||||
detailsScroll.setContent(detailsContent);
|
||||
detailsScroll.setFitToWidth(true);
|
||||
detailsScroll.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
|
||||
detailsScroll.getStyleClass().add("assets-workspace-details-scroll");
|
||||
|
||||
getChildren().addAll(detailsTitleLabel, workspaceSummaryLabel, detailsScroll);
|
||||
VBox.setVgrow(detailsScroll, Priority.ALWAYS);
|
||||
render();
|
||||
}
|
||||
|
||||
@Override
|
||||
public StudioEventBindings eventBindings() {
|
||||
return eventBindings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerEventSubscriptions() {
|
||||
eventBindings.listen(workspaceBus, StudioAssetsRefreshRequestedEvent.class).handle(event -> {
|
||||
if (event.preferredAssetReference() != null) {
|
||||
loadSelection(event.preferredAssetReference());
|
||||
return;
|
||||
}
|
||||
if (event.deepSync() && viewState.selectedAssetReference() != null) {
|
||||
loadSelection(viewState.selectedAssetReference());
|
||||
return;
|
||||
}
|
||||
clearSelection();
|
||||
});
|
||||
eventBindings.listen(workspaceBus, StudioAssetsWorkspaceSelectionRequestedEvent.class).handle(event -> {
|
||||
if (event.forceUpdate() || !isCurrentSelection(event.assetReference())) {
|
||||
loadSelection(event.assetReference());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void scrollToTop() {
|
||||
detailsScroll.setVvalue(0.0d);
|
||||
}
|
||||
|
||||
private void loadSelection(AssetReference assetReference) {
|
||||
final long generation = loadGeneration.incrementAndGet();
|
||||
actionRunning = false;
|
||||
actionFeedbackMessage = null;
|
||||
publishViewState(AssetDetailsViewStateFactory.loading(assetReference));
|
||||
executor.execute(() -> loadDetails(generation, assetReference));
|
||||
}
|
||||
|
||||
private void clearSelection() {
|
||||
loadGeneration.incrementAndGet();
|
||||
actionRunning = false;
|
||||
actionFeedbackMessage = null;
|
||||
publishViewState(AssetDetailsViewStateFactory.empty());
|
||||
}
|
||||
|
||||
private boolean isCurrentSelection(AssetReference assetReference) {
|
||||
if (!Objects.equals(viewState.selectedAssetReference(), assetReference)) {
|
||||
return false;
|
||||
}
|
||||
return viewState.detailsStatus() == AssetWorkspaceDetailsStatus.READY
|
||||
|| viewState.detailsStatus() == AssetWorkspaceDetailsStatus.LOADING;
|
||||
}
|
||||
|
||||
private void loadDetails(long generation, AssetReference assetReference) {
|
||||
try {
|
||||
final AssetWorkspaceAssetDetails details = mapDetails(assetDetails.get(projectReference, assetReference));
|
||||
Platform.runLater(() -> applyLoadedDetails(generation, assetReference, details));
|
||||
} catch (RuntimeException exception) {
|
||||
Platform.runLater(() -> applyLoadFailure(generation, assetReference, exception));
|
||||
}
|
||||
}
|
||||
|
||||
private void applyLoadedDetails(
|
||||
long generation,
|
||||
AssetReference assetReference,
|
||||
AssetWorkspaceAssetDetails details) {
|
||||
if (generation != loadGeneration.get()) {
|
||||
return;
|
||||
}
|
||||
publishViewState(AssetDetailsViewStateFactory.ready(assetReference, details));
|
||||
}
|
||||
|
||||
private void applyLoadFailure(
|
||||
long generation,
|
||||
AssetReference assetReference,
|
||||
RuntimeException exception) {
|
||||
if (generation != loadGeneration.get()) {
|
||||
return;
|
||||
}
|
||||
final String message = i18n.text(I18n.ASSETS_DETAILS_EMPTY);
|
||||
publishViewState(AssetDetailsViewStateFactory.error(assetReference, message));
|
||||
}
|
||||
|
||||
private void publishViewState(AssetWorkspaceDetailsViewState nextViewState) {
|
||||
final AssetReference previousAssetReference = viewState == null ? null : viewState.selectedAssetReference();
|
||||
final String previousScopeKey = previousAssetReference == null ? null : "asset-details:" + previousAssetReference;
|
||||
final boolean assetChanged = !Objects.equals(previousAssetReference, nextViewState.selectedAssetReference());
|
||||
viewState = Objects.requireNonNull(nextViewState, "nextViewState");
|
||||
if (assetChanged || nextViewState.detailsStatus() != AssetWorkspaceDetailsStatus.READY) {
|
||||
workspaceBus.publish(new StudioFormEditScopeChangedEvent(
|
||||
previousScopeKey,
|
||||
null));
|
||||
}
|
||||
render();
|
||||
if (assetChanged && nextViewState.selectedAssetReference() != null) {
|
||||
Platform.runLater(this::scrollToTop);
|
||||
}
|
||||
workspaceBus.publish(new StudioAssetsDetailsViewStateChangedEvent(nextViewState));
|
||||
}
|
||||
|
||||
private void render() {
|
||||
switch (viewState.detailsStatus()) {
|
||||
case EMPTY -> {
|
||||
readyMounted = false;
|
||||
setDetailsTitle(null);
|
||||
setWorkspaceSummary(i18n.text(I18n.ASSETS_SUMMARY_EMPTY));
|
||||
renderActions();
|
||||
detailsContent.getChildren().setAll(AssetDetailsUiSupport.createSectionMessage(i18n.text(I18n.ASSETS_DETAILS_NO_SELECTION)));
|
||||
}
|
||||
case LOADING -> {
|
||||
readyMounted = false;
|
||||
setDetailsTitle(null);
|
||||
setWorkspaceSummary(i18n.text(I18n.ASSETS_SUMMARY_LOADING));
|
||||
renderActions();
|
||||
detailsContent.getChildren().setAll(AssetDetailsUiSupport.createSectionMessage(i18n.text(I18n.ASSETS_DETAILS_LOADING)));
|
||||
}
|
||||
case ERROR -> {
|
||||
readyMounted = false;
|
||||
setDetailsTitle(null);
|
||||
setWorkspaceSummary(i18n.text(I18n.ASSETS_SUMMARY_ERROR));
|
||||
renderActions();
|
||||
detailsContent.getChildren().setAll(AssetDetailsUiSupport.createSectionMessage(
|
||||
Objects.requireNonNullElse(viewState.detailsErrorMessage(), i18n.text(I18n.ASSETS_DETAILS_EMPTY))));
|
||||
}
|
||||
case READY -> {
|
||||
if (viewState.selectedAssetDetails() == null) {
|
||||
readyMounted = false;
|
||||
setDetailsTitle(null);
|
||||
setWorkspaceSummary(null);
|
||||
renderActions();
|
||||
detailsContent.getChildren().setAll(AssetDetailsUiSupport.createSectionMessage(i18n.text(I18n.ASSETS_DETAILS_NO_SELECTION)));
|
||||
return;
|
||||
}
|
||||
|
||||
setDetailsTitle(viewState.selectedAssetDetails().summary().assetName());
|
||||
setWorkspaceSummary(null);
|
||||
renderActions();
|
||||
if (!readyMounted) {
|
||||
readyMounted = true;
|
||||
detailsContent.getChildren().setAll(buildDetailsSections());
|
||||
}
|
||||
syncActionsSectionHeight(summaryControl.getHeight());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Node[] buildDetailsSections() {
|
||||
final java.util.List<Node> sections = new java.util.ArrayList<>();
|
||||
sections.add(primarySectionsRow);
|
||||
sections.add(contractControl);
|
||||
if (showsSceneLayers(viewState.selectedAssetDetails())) {
|
||||
sections.add(sceneLayersControl);
|
||||
} else if (!hidesBankComposition(viewState.selectedAssetDetails())) {
|
||||
sections.add(bankCompositionControl);
|
||||
}
|
||||
if (showsColorSchemaGroups(viewState.selectedAssetDetails())) {
|
||||
sections.add(colorSchemaGroupsControl);
|
||||
}
|
||||
sections.add(paletteOverhaulingControl);
|
||||
return sections.toArray(Node[]::new);
|
||||
}
|
||||
|
||||
private boolean hidesBankComposition(AssetWorkspaceAssetDetails details) {
|
||||
return details != null && details.summary().assetFamily() == AssetFamily.SCENE_BANK;
|
||||
}
|
||||
|
||||
private boolean showsSceneLayers(AssetWorkspaceAssetDetails details) {
|
||||
return details != null
|
||||
&& details.summary().assetFamily() == AssetFamily.SCENE_BANK
|
||||
&& details.sceneBankMetadata() != null;
|
||||
}
|
||||
|
||||
private boolean showsColorSchemaGroups(AssetWorkspaceAssetDetails details) {
|
||||
return details != null && details.summary().assetFamily() == AssetFamily.GLYPH_BANK;
|
||||
}
|
||||
|
||||
private VBox createActionsSection() {
|
||||
actionsContent.getStyleClass().add("assets-details-actions-content");
|
||||
actionsScroll.setContent(actionsContent);
|
||||
actionsScroll.setFitToWidth(true);
|
||||
actionsScroll.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
|
||||
actionsScroll.getStyleClass().add("assets-details-actions-scroll");
|
||||
final VBox section = StudioSection.createSectionWithoutHeader(actionsScroll);
|
||||
section.getStyleClass().add("assets-details-actions-section");
|
||||
return section;
|
||||
}
|
||||
|
||||
private void syncActionsSectionHeight(double summaryHeight) {
|
||||
if (summaryHeight <= 0.0d) {
|
||||
return;
|
||||
}
|
||||
actionsSection.setMinHeight(summaryHeight);
|
||||
actionsSection.setPrefHeight(summaryHeight);
|
||||
actionsSection.setMaxHeight(summaryHeight);
|
||||
}
|
||||
|
||||
private void setDetailsTitle(String text) {
|
||||
detailsTitleLabel.setText(text == null ? "" : text);
|
||||
final boolean visible = text != null && !text.isBlank();
|
||||
detailsTitleLabel.setVisible(visible);
|
||||
detailsTitleLabel.setManaged(visible);
|
||||
}
|
||||
|
||||
private void setWorkspaceSummary(String text) {
|
||||
workspaceSummaryLabel.setText(text == null ? "" : text);
|
||||
final boolean visible = text != null && !text.isBlank();
|
||||
workspaceSummaryLabel.setVisible(visible);
|
||||
workspaceSummaryLabel.setManaged(visible);
|
||||
}
|
||||
|
||||
private void renderActions() {
|
||||
actionsContent.getChildren().setAll(buildActionNodes());
|
||||
}
|
||||
|
||||
private java.util.List<Node> buildActionNodes() {
|
||||
final java.util.List<Node> nodes = new java.util.ArrayList<>();
|
||||
if (viewState.selectedAssetDetails() == null) {
|
||||
nodes.add(AssetDetailsUiSupport.createSectionMessage(i18n.text(I18n.ASSETS_ACTIONS_EMPTY)));
|
||||
return nodes;
|
||||
}
|
||||
final var visibleActions = viewState.selectedAssetDetails().actions().stream()
|
||||
.filter(AssetWorkspaceAssetAction::visible)
|
||||
.toList();
|
||||
if (visibleActions.isEmpty()
|
||||
&& viewState.selectedAssetDetails().diagnostics().isEmpty()
|
||||
&& viewState.selectedAssetDetails().summary().state() == p.studio.api.assets.workspace.AssetWorkspaceAssetState.UNREGISTERED) {
|
||||
nodes.add(AssetDetailsUiSupport.createSectionMessage(i18n.text(I18n.ASSETS_ACTIONS_EMPTY)));
|
||||
return nodes;
|
||||
}
|
||||
final Button analyseButton = AssetDetailsUiSupport.createActionButton(i18n.text(I18n.ASSETS_ACTION_ANALYSE));
|
||||
AssetDetailsUiSupport.applyActionTone(analyseButton, "studio-button-warning");
|
||||
analyseButton.setDisable(actionRunning || viewState.selectedAssetDetails().diagnostics().isEmpty());
|
||||
analyseButton.setOnAction(ignored -> openDiagnosticsDialog());
|
||||
nodes.add(analyseButton);
|
||||
if (canGenerateTsx()) {
|
||||
final Button exportTsxButton = AssetDetailsUiSupport.createActionButton(i18n.text(I18n.ASSETS_ACTION_EXPORT_TSX));
|
||||
exportTsxButton.setDisable(actionRunning);
|
||||
exportTsxButton.setOnAction(ignored -> generateTsx());
|
||||
nodes.add(exportTsxButton);
|
||||
}
|
||||
if (canSceneTmxInteroperability()) {
|
||||
final Button importTmxButton = AssetDetailsUiSupport.createActionButton(i18n.text(I18n.ASSETS_ACTION_IMPORT_TMX));
|
||||
importTmxButton.setDisable(actionRunning);
|
||||
importTmxButton.setOnAction(ignored -> importTmx());
|
||||
nodes.add(importTmxButton);
|
||||
|
||||
final Button exportTmxButton = AssetDetailsUiSupport.createActionButton(i18n.text(I18n.ASSETS_ACTION_EXPORT_TMX));
|
||||
exportTmxButton.setDisable(actionRunning);
|
||||
exportTmxButton.setOnAction(ignored -> exportTmx());
|
||||
nodes.add(exportTmxButton);
|
||||
}
|
||||
final Button buildParticipationButton = AssetDetailsUiSupport.createActionButton(buildParticipationActionLabel());
|
||||
AssetDetailsUiSupport.applyActionTone(
|
||||
buildParticipationButton,
|
||||
currentBuildParticipation() == AssetWorkspaceBuildParticipation.INCLUDED
|
||||
? "studio-button-build-exclude"
|
||||
: "studio-button-build-include");
|
||||
buildParticipationButton.setDisable(actionRunning || !canToggleBuildParticipation());
|
||||
buildParticipationButton.setOnAction(ignored -> updateBuildParticipation());
|
||||
nodes.add(buildParticipationButton);
|
||||
|
||||
final var orderedActions = visibleActions.stream()
|
||||
.sorted(comparingInt(action -> switch (action.action()) {
|
||||
case "DELETE" -> 2;
|
||||
default -> 1;
|
||||
}))
|
||||
.toList();
|
||||
for (AssetWorkspaceAssetAction action : orderedActions) {
|
||||
final Button button = AssetDetailsUiSupport.createActionButton(AssetDetailsUiSupport.actionLabel(i18n, action.action()));
|
||||
if ("DELETE".equals(action.action())) {
|
||||
AssetDetailsUiSupport.applyActionTone(button, "studio-button-danger");
|
||||
}
|
||||
button.setDisable(actionRunning || !action.enabled());
|
||||
button.setOnAction(ignored -> executeAction(action));
|
||||
nodes.add(button);
|
||||
}
|
||||
return nodes;
|
||||
}
|
||||
|
||||
private void executeAction(AssetWorkspaceAssetAction action) {
|
||||
if (actionRunning || viewState.selectedAssetReference() == null) {
|
||||
return;
|
||||
}
|
||||
switch (action.action()) {
|
||||
case "REGISTER" -> {
|
||||
actionRunning = true;
|
||||
actionFeedbackMessage = null;
|
||||
renderActions();
|
||||
executor.execute(() -> registerSelectedAsset(viewState.selectedAssetReference()));
|
||||
}
|
||||
case "MOVE" -> openMoveWizard();
|
||||
case "DELETE" -> confirmDeleteAction();
|
||||
default -> throw new IllegalArgumentException("Unsupported asset action: " + action.action());
|
||||
}
|
||||
}
|
||||
|
||||
private void openMoveWizard() {
|
||||
if (viewState.selectedAssetDetails() == null || getScene() == null || viewState.selectedAssetReference() == null) {
|
||||
return;
|
||||
}
|
||||
MoveAssetWizard.showAndWait(
|
||||
getScene().getWindow(),
|
||||
projectReference,
|
||||
viewState.selectedAssetReference(),
|
||||
viewState.selectedAssetDetails().summary(),
|
||||
executor, i18n, theme, assetCommands).ifPresent(assetReference -> {
|
||||
workspaceBus.publish(new StudioAssetsRefreshRequestedEvent(assetReference));
|
||||
});
|
||||
}
|
||||
|
||||
private void confirmDeleteAction() {
|
||||
if (viewState.selectedAssetDetails() == null || getScene() == null) {
|
||||
return;
|
||||
}
|
||||
final boolean confirmed = DeleteAssetDialog.showAndWait(
|
||||
getScene().getWindow(),
|
||||
viewState.selectedAssetDetails().summary().assetName(), i18n, theme);
|
||||
if (!confirmed) {
|
||||
return;
|
||||
}
|
||||
actionRunning = true;
|
||||
actionFeedbackMessage = null;
|
||||
renderActions();
|
||||
final AssetReference assetReference = viewState.selectedAssetReference();
|
||||
executor.execute(() -> deleteSelectedAsset(assetReference));
|
||||
}
|
||||
|
||||
private void openDiagnosticsDialog() {
|
||||
if (viewState.selectedAssetDetails() == null || getScene() == null) {
|
||||
return;
|
||||
}
|
||||
AssetDiagnosticsDialog.showAndWait(
|
||||
getScene().getWindow(),
|
||||
projectReference,
|
||||
viewState.selectedAssetDetails().summary().assetName(),
|
||||
viewState.selectedAssetDetails().diagnostics(),
|
||||
i18n,
|
||||
theme);
|
||||
}
|
||||
|
||||
private boolean canToggleBuildParticipation() {
|
||||
return viewState.selectedAssetDetails() != null
|
||||
&& viewState.selectedAssetDetails().summary().state() == p.studio.api.assets.workspace.AssetWorkspaceAssetState.REGISTERED
|
||||
&& (!isSceneBankAwaitingActiveLayerForBuild());
|
||||
}
|
||||
|
||||
private boolean isSceneBankAwaitingActiveLayerForBuild() {
|
||||
return viewState.selectedAssetDetails() != null
|
||||
&& viewState.selectedAssetDetails().summary().assetFamily() == AssetFamily.SCENE_BANK
|
||||
&& currentBuildParticipation() != AssetWorkspaceBuildParticipation.INCLUDED
|
||||
&& (viewState.selectedAssetDetails().sceneBankMetadata() == null
|
||||
|| viewState.selectedAssetDetails().sceneBankMetadata().enabledLayerCount() == 0);
|
||||
}
|
||||
|
||||
private AssetWorkspaceBuildParticipation currentBuildParticipation() {
|
||||
return viewState.selectedAssetDetails().summary().buildParticipation();
|
||||
}
|
||||
|
||||
private String buildParticipationActionLabel() {
|
||||
return currentBuildParticipation() == AssetWorkspaceBuildParticipation.INCLUDED
|
||||
? i18n.text(I18n.ASSETS_ACTION_EXCLUDE_FROM_BUILD)
|
||||
: i18n.text(I18n.ASSETS_ACTION_INCLUDE_IN_BUILD);
|
||||
}
|
||||
|
||||
private void updateBuildParticipation() {
|
||||
if (actionRunning || viewState.selectedAssetReference() == null || !canToggleBuildParticipation()) {
|
||||
return;
|
||||
}
|
||||
actionRunning = true;
|
||||
actionFeedbackMessage = null;
|
||||
renderActions();
|
||||
final AssetReference assetReference = viewState.selectedAssetReference();
|
||||
final boolean includeInBuild = currentBuildParticipation() != AssetWorkspaceBuildParticipation.INCLUDED;
|
||||
executor.execute(() -> {
|
||||
try {
|
||||
final AssetMutationResult result = assetCommands.updateBuildParticipation(
|
||||
projectReference, assetReference, includeInBuild);
|
||||
Platform.runLater(() -> applyBuildParticipationResult(result));
|
||||
} catch (RuntimeException exception) {
|
||||
Platform.runLater(() -> applyBuildParticipationFailure(exception));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private boolean canGenerateTsx() {
|
||||
return viewState.selectedAssetDetails() != null
|
||||
&& viewState.selectedAssetDetails().summary().assetFamily() == AssetFamily.GLYPH_BANK
|
||||
&& viewState.selectedAssetDetails().summary().glyphSpecialization() == AssetStudioGlyphSpecialization.TILESET;
|
||||
}
|
||||
|
||||
private boolean canSceneTmxInteroperability() {
|
||||
return viewState.selectedAssetDetails() != null
|
||||
&& viewState.selectedAssetDetails().summary().assetFamily() == AssetFamily.SCENE_BANK
|
||||
&& viewState.selectedAssetDetails().sceneBankMetadata() != null;
|
||||
}
|
||||
|
||||
private void generateTsx() {
|
||||
if (actionRunning || viewState.selectedAssetDetails() == null) {
|
||||
return;
|
||||
}
|
||||
actionRunning = true;
|
||||
actionFeedbackMessage = null;
|
||||
renderActions();
|
||||
final AssetWorkspaceAssetDetails details = viewState.selectedAssetDetails();
|
||||
executor.execute(() -> {
|
||||
final TiledAssetGenerationResult result = tiledGenerationService.exportTilesetTsx(details);
|
||||
Platform.runLater(() -> applyTiledGenerationResult("glyph-bank-tileset-export", result));
|
||||
});
|
||||
}
|
||||
|
||||
private void exportTmx() {
|
||||
if (actionRunning || viewState.selectedAssetDetails() == null) {
|
||||
return;
|
||||
}
|
||||
final AssetWorkspaceAssetDetails details = viewState.selectedAssetDetails();
|
||||
final SceneTmxExportDisposition disposition = chooseSceneTmxExportDisposition(details);
|
||||
if (disposition == null) {
|
||||
return;
|
||||
}
|
||||
actionRunning = true;
|
||||
actionFeedbackMessage = null;
|
||||
executor.execute(() -> {
|
||||
final TiledAssetGenerationResult result = tiledGenerationService.exportSceneBankTmx(projectReference, details, disposition);
|
||||
Platform.runLater(() -> applyTiledGenerationResult("scene-bank-tmx-export", result));
|
||||
});
|
||||
}
|
||||
|
||||
private SceneTmxExportDisposition chooseSceneTmxExportDisposition(AssetWorkspaceAssetDetails details) {
|
||||
if (!tiledGenerationService.sceneTmxExists(details)) {
|
||||
return SceneTmxExportDisposition.OVERWRITE;
|
||||
}
|
||||
final Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
|
||||
if (getScene() != null) {
|
||||
alert.initOwner(getScene().getWindow());
|
||||
}
|
||||
final ButtonType overwriteButton = new ButtonType("Overwrite", ButtonBar.ButtonData.YES);
|
||||
final ButtonType keepBothButton = new ButtonType("Keep Both", ButtonBar.ButtonData.NO);
|
||||
final ButtonType cancelButton = new ButtonType("Cancel", ButtonBar.ButtonData.CANCEL_CLOSE);
|
||||
alert.setTitle("Export TMX");
|
||||
alert.setHeaderText(null);
|
||||
alert.setContentText("A scene.tmx file already exists. Choose how to proceed.");
|
||||
alert.getButtonTypes().setAll(overwriteButton, keepBothButton, cancelButton);
|
||||
final ButtonType result = alert.showAndWait().orElse(cancelButton);
|
||||
if (result == overwriteButton) {
|
||||
return SceneTmxExportDisposition.OVERWRITE;
|
||||
}
|
||||
if (result == keepBothButton) {
|
||||
return SceneTmxExportDisposition.KEEP_BOTH;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void importTmx() {
|
||||
if (actionRunning || viewState.selectedAssetDetails() == null) {
|
||||
return;
|
||||
}
|
||||
actionRunning = true;
|
||||
actionFeedbackMessage = null;
|
||||
final AssetWorkspaceAssetDetails details = viewState.selectedAssetDetails();
|
||||
executor.execute(() -> {
|
||||
final TiledAssetGenerationResult result = tiledGenerationService.importSceneBankTmx(projectReference, details);
|
||||
Platform.runLater(() -> applyTiledGenerationResult("scene-bank-tmx-import", result));
|
||||
});
|
||||
}
|
||||
|
||||
private void applyTiledGenerationResult(String source, TiledAssetGenerationResult result) {
|
||||
actionRunning = false;
|
||||
actionFeedbackMessage = result.message();
|
||||
workspaceBus.publish(new StudioAssetLogEvent(source, result.message()));
|
||||
if (result.success()) {
|
||||
if (result.updatedBindings() != null && !result.updatedBindings().isEmpty()) {
|
||||
final var sceneBankMetadata = viewState.selectedAssetDetails().sceneBankMetadata().withUpdatedBindings(result.updatedBindings());
|
||||
final var updatedAssetDetails = viewState.selectedAssetDetails().withSceneBankMetadata(sceneBankMetadata);
|
||||
viewState = viewState.withSelectedAssetReference(updatedAssetDetails);
|
||||
}
|
||||
workspaceBus.publish(new StudioAssetsWorkspaceDetailsSceneLayerChangedEvent(viewState));
|
||||
}
|
||||
}
|
||||
|
||||
private void applyBuildParticipationResult(AssetMutationResult result) {
|
||||
actionRunning = false;
|
||||
if (result.successful() && result.assetReference() != null) {
|
||||
actionFeedbackMessage = null;
|
||||
workspaceBus.publish(new StudioAssetsRefreshRequestedEvent(result.assetReference()));
|
||||
return;
|
||||
}
|
||||
actionFeedbackMessage = result.summary();
|
||||
renderActions();
|
||||
}
|
||||
|
||||
private void applyBuildParticipationFailure(RuntimeException exception) {
|
||||
actionRunning = false;
|
||||
actionFeedbackMessage = "Unable to update asset build participation.";
|
||||
renderActions();
|
||||
}
|
||||
|
||||
private void registerSelectedAsset(AssetReference assetReference) {
|
||||
try {
|
||||
final AssetMutationResult result = assetCommands.register(projectReference, assetReference);
|
||||
Platform.runLater(() -> applyRegisterResult(result));
|
||||
} catch (RuntimeException exception) {
|
||||
Platform.runLater(() -> applyRegisterFailure(exception));
|
||||
}
|
||||
}
|
||||
|
||||
private void applyRegisterResult(AssetMutationResult result) {
|
||||
actionRunning = false;
|
||||
if (result.successful() && result.assetReference() != null) {
|
||||
actionFeedbackMessage = null;
|
||||
workspaceBus.publish(new StudioAssetsRefreshRequestedEvent(result.assetReference()));
|
||||
return;
|
||||
}
|
||||
actionFeedbackMessage = Objects.requireNonNullElse(result.summary(), "Unable to register asset.");
|
||||
renderActions();
|
||||
}
|
||||
|
||||
private void applyRegisterFailure(RuntimeException exception) {
|
||||
actionRunning = false;
|
||||
actionFeedbackMessage = "Unable to register asset.";
|
||||
renderActions();
|
||||
}
|
||||
|
||||
private void deleteSelectedAsset(AssetReference assetReference) {
|
||||
try {
|
||||
final AssetMutationResult result = assetCommands.delete(projectReference, assetReference);
|
||||
Platform.runLater(() -> applyDeleteResult(result));
|
||||
} catch (RuntimeException exception) {
|
||||
Platform.runLater(() -> applyDeleteFailure(exception));
|
||||
}
|
||||
}
|
||||
|
||||
private void applyDeleteResult(AssetMutationResult result) {
|
||||
actionRunning = false;
|
||||
if (result.successful()) {
|
||||
actionFeedbackMessage = null;
|
||||
workspaceBus.publish(new StudioAssetsRefreshRequestedEvent());
|
||||
return;
|
||||
}
|
||||
actionFeedbackMessage = Objects.requireNonNullElse(result.summary(), "Unable to delete asset.");
|
||||
renderActions();
|
||||
}
|
||||
|
||||
private void applyDeleteFailure(RuntimeException exception) {
|
||||
actionRunning = false;
|
||||
actionFeedbackMessage = "Unable to delete asset.";
|
||||
renderActions();
|
||||
}
|
||||
|
||||
private AssetWorkspaceAssetDetails mapDetails(AssetDetailsSnapshot details) {
|
||||
final var baseSummary = AssetListMappings.mapSummary(details.summary());
|
||||
final AssetStudioMetadataSnapshot studioMetadata = studioMetadataService.read(
|
||||
baseSummary.assetRoot(),
|
||||
baseSummary.assetFamily());
|
||||
final java.util.List<AssetWorkspaceAssetAction> mappedActions = details.actions().stream()
|
||||
.map(action -> new AssetWorkspaceAssetAction(
|
||||
action.action(),
|
||||
action.enabled(),
|
||||
action.visible(),
|
||||
action.reason()))
|
||||
.toList();
|
||||
final p.studio.api.assets.workspace.AssetWorkspaceAssetSummary mappedSummary =
|
||||
new p.studio.api.assets.workspace.AssetWorkspaceAssetSummary(
|
||||
baseSummary.assetReference(),
|
||||
baseSummary.assetName(),
|
||||
baseSummary.state(),
|
||||
baseSummary.buildParticipation(),
|
||||
baseSummary.assetId(),
|
||||
baseSummary.assetFamily(),
|
||||
studioMetadata.glyphSpecialization(),
|
||||
baseSummary.assetRoot(),
|
||||
baseSummary.preload(),
|
||||
baseSummary.hasDiagnostics());
|
||||
final AssetWorkspaceBankCompositionDetails bankComposition = mapBankComposition(details.bankComposition());
|
||||
final var availableCodecs = details.availableOutputCodecs();
|
||||
final var codecFields = details.codecConfigurationFieldsByCodec();
|
||||
final var metadataFields = details.metadataFields();
|
||||
final AssetWorkspaceAssetDetails draftDetails = new AssetWorkspaceAssetDetails(
|
||||
mappedSummary,
|
||||
mappedActions,
|
||||
details.outputFormat(),
|
||||
details.outputCodec(),
|
||||
availableCodecs,
|
||||
codecFields,
|
||||
metadataFields,
|
||||
details.outputPipeline(),
|
||||
bankComposition,
|
||||
details.pipelinePalettes(),
|
||||
studioMetadata.glyphMaterialMetadata(),
|
||||
studioMetadata.sceneBankMetadata(),
|
||||
AssetWorkspaceSceneBankValidation.NOT_APPLICABLE,
|
||||
List.of());
|
||||
final SceneBankWorkflowResult sceneBankWorkflow = sceneBankWorkflowService.inspect(projectReference, draftDetails);
|
||||
final java.util.List<AssetDiagnostic> mergedDiagnostics = new java.util.ArrayList<>(details.diagnostics());
|
||||
for (AssetDiagnostic diagnostic : sceneBankWorkflow.diagnostics()) {
|
||||
if (!mergedDiagnostics.contains(diagnostic)) {
|
||||
mergedDiagnostics.add(diagnostic);
|
||||
}
|
||||
}
|
||||
return new AssetWorkspaceAssetDetails(
|
||||
mappedSummary,
|
||||
mappedActions,
|
||||
details.outputFormat(),
|
||||
details.outputCodec(),
|
||||
availableCodecs,
|
||||
codecFields,
|
||||
metadataFields,
|
||||
details.outputPipeline(),
|
||||
bankComposition,
|
||||
details.pipelinePalettes(),
|
||||
studioMetadata.glyphMaterialMetadata(),
|
||||
studioMetadata.sceneBankMetadata(),
|
||||
sceneBankWorkflow.validation(),
|
||||
mergedDiagnostics);
|
||||
}
|
||||
|
||||
private AssetWorkspaceBankCompositionDetails mapBankComposition(p.studio.api.assets.AssetBankComposition details) {
|
||||
return new AssetWorkspaceBankCompositionDetails(
|
||||
details.availableFiles().stream().map(this::mapBankCompositionFile).toList(),
|
||||
details.selectedFiles().stream().map(this::mapBankCompositionFile).toList(),
|
||||
details.measuredBankSizeBytes());
|
||||
}
|
||||
|
||||
private AssetWorkspaceBankCompositionFile mapBankCompositionFile(p.studio.api.assets.AssetBankFile file) {
|
||||
return new AssetWorkspaceBankCompositionFile(
|
||||
file.path(),
|
||||
file.displayName(),
|
||||
file.size(),
|
||||
file.lastModified(),
|
||||
file.fingerprint(),
|
||||
file.metadata());
|
||||
}
|
||||
}
|
||||
+194
@@ -0,0 +1,194 @@
|
||||
package p.studio.ui.javafx.workspaces.assets.details;
|
||||
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.Priority;
|
||||
import javafx.scene.layout.VBox;
|
||||
import p.studio.api.assets.AssetFamily;
|
||||
import p.studio.ui.javafx.controls.forms.StudioFormMode;
|
||||
import p.studio.ui.javafx.controls.forms.StudioFormSection;
|
||||
import p.studio.ui.javafx.controls.forms.StudioSection;
|
||||
import p.studio.api.project.ProjectReference;
|
||||
import p.studio.ui.javafx.utilities.i18n.I18n;
|
||||
import p.studio.ui.javafx.utilities.i18n.I18nService;
|
||||
import p.studio.api.assets.metadata.AssetStudioGlyphSpecialization;
|
||||
import p.studio.api.assets.workspace.AssetWorkspaceSceneBankStatus;
|
||||
import p.studio.api.assets.workspace.AssetWorkspaceAssetState;
|
||||
import p.studio.api.assets.workspace.AssetWorkspaceBuildParticipation;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
public final class AssetDetailsUiSupport {
|
||||
private AssetDetailsUiSupport() {
|
||||
}
|
||||
|
||||
public static VBox createSection(String title, Node content) {
|
||||
return StudioSection.createSection(title, content);
|
||||
}
|
||||
|
||||
public static VBox createSectionWithoutHeader(Node content) {
|
||||
return StudioSection.createSectionWithoutHeader(content);
|
||||
}
|
||||
|
||||
public static VBox createSection(String title, Node headerActions, Node content) {
|
||||
return StudioFormSection.createEditableSection(title, headerActions, content, StudioFormMode.READ_ONLY);
|
||||
}
|
||||
|
||||
public static VBox createEditableSection(String title, Node headerActions, Node content, StudioFormMode mode) {
|
||||
return StudioFormSection.createEditableSection(title, headerActions, content, mode);
|
||||
}
|
||||
|
||||
public static Node createSectionMessage(String text) {
|
||||
final Label label = new Label(text);
|
||||
label.setWrapText(true);
|
||||
label.getStyleClass().add("assets-details-section-message");
|
||||
return label;
|
||||
}
|
||||
|
||||
public static Node createKeyValueRow(String key, String value) {
|
||||
final Label valueLabel = new Label(value);
|
||||
valueLabel.getStyleClass().add("assets-details-value");
|
||||
valueLabel.setWrapText(true);
|
||||
return createKeyValueRow(key, valueLabel);
|
||||
}
|
||||
|
||||
public static Node createKeyValueRow(String key, Node valueNode) {
|
||||
final HBox row = new HBox(12);
|
||||
row.setAlignment(Pos.TOP_LEFT);
|
||||
final Label keyLabel = new Label(key);
|
||||
keyLabel.getStyleClass().add("assets-details-key");
|
||||
HBox.setHgrow(valueNode, Priority.ALWAYS);
|
||||
row.getChildren().addAll(keyLabel, valueNode);
|
||||
return row;
|
||||
}
|
||||
|
||||
public static Label createChip(String toneClass, String text) {
|
||||
final Label chip = new Label(text);
|
||||
chip.getStyleClass().addAll("assets-details-chip", toneClass);
|
||||
return chip;
|
||||
}
|
||||
|
||||
public static Label createChip(String toneClass, String text, String... extraClasses) {
|
||||
final Label chip = createChip(toneClass, text);
|
||||
if (extraClasses != null && extraClasses.length > 0) {
|
||||
chip.getStyleClass().addAll(extraClasses);
|
||||
}
|
||||
return chip;
|
||||
}
|
||||
|
||||
public static Button createActionButton(String text) {
|
||||
final Button button = new Button(text);
|
||||
button.getStyleClass().addAll("studio-button", "studio-button-primary", "assets-details-action-button");
|
||||
button.setMaxWidth(Double.MAX_VALUE);
|
||||
return button;
|
||||
}
|
||||
|
||||
public static void applyActionTone(Button button, String toneClass) {
|
||||
button.getStyleClass().removeAll(
|
||||
"studio-button-primary",
|
||||
"studio-button-warning",
|
||||
"studio-button-danger",
|
||||
"studio-button-build-include",
|
||||
"studio-button-build-exclude");
|
||||
button.getStyleClass().add(toneClass);
|
||||
}
|
||||
|
||||
public static String registrationLabel(I18nService i18n, AssetWorkspaceAssetState state) {
|
||||
return switch (state) {
|
||||
case REGISTERED -> i18n.text(I18n.ASSETS_VALUE_REGISTERED);
|
||||
case UNREGISTERED -> i18n.text(I18n.ASSETS_VALUE_UNREGISTERED);
|
||||
};
|
||||
}
|
||||
|
||||
public static String buildParticipationLabel(I18nService i18n, AssetWorkspaceBuildParticipation buildParticipation) {
|
||||
return switch (buildParticipation) {
|
||||
case INCLUDED -> i18n.text(I18n.ASSETS_VALUE_INCLUDED);
|
||||
case EXCLUDED -> i18n.text(I18n.ASSETS_VALUE_EXCLUDED);
|
||||
};
|
||||
}
|
||||
|
||||
public static String booleanLabel(I18nService i18n, boolean value) {
|
||||
return value
|
||||
? i18n.text(I18n.ASSETS_VALUE_YES)
|
||||
: i18n.text(I18n.ASSETS_VALUE_NO);
|
||||
}
|
||||
|
||||
public static String typeLabel(I18nService i18n, AssetFamily assetFamily) {
|
||||
return switch (assetFamily) {
|
||||
case GLYPH_BANK -> i18n.text(I18n.ASSETS_TYPE_GLYPH_BANK);
|
||||
case SCENE_BANK -> i18n.text(I18n.ASSETS_TYPE_SCENE_BANK);
|
||||
case SOUND_BANK -> i18n.text(I18n.ASSETS_TYPE_SOUND_BANK);
|
||||
case UNKNOWN -> i18n.text(I18n.ASSETS_TYPE_UNKNOWN);
|
||||
};
|
||||
}
|
||||
|
||||
public static String typeChipTone(AssetFamily assetFamily) {
|
||||
return switch (assetFamily) {
|
||||
case GLYPH_BANK -> "assets-details-chip-image";
|
||||
case SCENE_BANK -> "assets-details-chip-scene";
|
||||
case SOUND_BANK -> "assets-details-chip-audio";
|
||||
case UNKNOWN -> "assets-details-chip-generic";
|
||||
};
|
||||
}
|
||||
|
||||
public static String specializationLabel(I18nService i18n, AssetStudioGlyphSpecialization specialization) {
|
||||
return switch (specialization) {
|
||||
case NONE -> i18n.text(I18n.ASSETS_SPECIALIZATION_NONE);
|
||||
case TILESET -> i18n.text(I18n.ASSETS_SPECIALIZATION_TILESET);
|
||||
case SPRITES -> i18n.text(I18n.ASSETS_SPECIALIZATION_SPRITES);
|
||||
case UI -> i18n.text(I18n.ASSETS_SPECIALIZATION_UI);
|
||||
};
|
||||
}
|
||||
|
||||
public static String sceneBankStatusLabel(I18nService i18n, AssetWorkspaceSceneBankStatus status) {
|
||||
return switch (status) {
|
||||
case NOT_APPLICABLE -> "";
|
||||
case PENDING_VALIDATION -> i18n.text(I18n.ASSETS_SCENE_STATUS_PENDING_VALIDATION);
|
||||
case VALIDATED_PENDING_ACCEPTANCE -> i18n.text(I18n.ASSETS_SCENE_STATUS_VALIDATED_PENDING_ACCEPTANCE);
|
||||
case READY -> i18n.text(I18n.ASSETS_SCENE_STATUS_READY);
|
||||
case VALIDATION_FAILED -> i18n.text(I18n.ASSETS_SCENE_STATUS_VALIDATION_FAILED);
|
||||
};
|
||||
}
|
||||
|
||||
public static String actionLabel(I18nService i18n, String action) {
|
||||
return switch (action) {
|
||||
case "REGISTER" -> i18n.text(I18n.ASSETS_ACTION_REGISTER);
|
||||
case "MOVE" -> i18n.text(I18n.ASSETS_ACTION_RELOCATE);
|
||||
case "DELETE" -> i18n.text(I18n.ASSETS_ACTION_DELETE);
|
||||
default -> action;
|
||||
};
|
||||
}
|
||||
|
||||
public static String catalogLabel(String value) {
|
||||
if (value == null || value.isBlank()) {
|
||||
return "Unknown";
|
||||
}
|
||||
final String normalized = value.replace('_', ' ').toLowerCase(java.util.Locale.ROOT);
|
||||
return Character.toUpperCase(normalized.charAt(0)) + normalized.substring(1);
|
||||
}
|
||||
|
||||
public static String registrationChipTone(AssetWorkspaceAssetState state) {
|
||||
return switch (state) {
|
||||
case REGISTERED -> "assets-details-chip-registered";
|
||||
case UNREGISTERED -> "assets-details-chip-unregistered";
|
||||
};
|
||||
}
|
||||
|
||||
public static String buildChipTone(AssetWorkspaceBuildParticipation buildParticipation) {
|
||||
return switch (buildParticipation) {
|
||||
case INCLUDED -> "assets-details-chip-included";
|
||||
case EXCLUDED -> "assets-details-chip-excluded";
|
||||
};
|
||||
}
|
||||
|
||||
public static String projectRelativePath(ProjectReference projectReference, Path path) {
|
||||
try {
|
||||
return projectReference.rootPath().relativize(path.toAbsolutePath().normalize()).toString();
|
||||
} catch (RuntimeException runtimeException) {
|
||||
return path.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
package p.studio.ui.javafx.workspaces.assets.details;
|
||||
|
||||
import p.studio.api.assets.AssetReference;
|
||||
import p.studio.api.assets.workspace.AssetWorkspaceAssetDetails;
|
||||
import p.studio.ui.javafx.workspaces.assets.messages.AssetWorkspaceDetailsStatus;
|
||||
import p.studio.ui.javafx.workspaces.assets.messages.AssetWorkspaceDetailsViewState;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public final class AssetDetailsViewStateFactory {
|
||||
private AssetDetailsViewStateFactory() {
|
||||
}
|
||||
|
||||
public static AssetWorkspaceDetailsViewState empty() {
|
||||
return new AssetWorkspaceDetailsViewState(
|
||||
AssetWorkspaceDetailsStatus.EMPTY,
|
||||
null,
|
||||
null,
|
||||
null);
|
||||
}
|
||||
|
||||
public static AssetWorkspaceDetailsViewState loading(AssetReference assetReference) {
|
||||
return new AssetWorkspaceDetailsViewState(
|
||||
AssetWorkspaceDetailsStatus.LOADING,
|
||||
Objects.requireNonNull(assetReference, "assetReference"),
|
||||
null,
|
||||
null);
|
||||
}
|
||||
|
||||
public static AssetWorkspaceDetailsViewState ready(
|
||||
AssetReference assetReference,
|
||||
AssetWorkspaceAssetDetails details) {
|
||||
return new AssetWorkspaceDetailsViewState(
|
||||
AssetWorkspaceDetailsStatus.READY,
|
||||
Objects.requireNonNull(assetReference, "assetReference"),
|
||||
Objects.requireNonNull(details, "details"),
|
||||
null);
|
||||
}
|
||||
|
||||
public static AssetWorkspaceDetailsViewState error(
|
||||
AssetReference assetReference,
|
||||
String message) {
|
||||
return new AssetWorkspaceDetailsViewState(
|
||||
AssetWorkspaceDetailsStatus.ERROR,
|
||||
assetReference,
|
||||
null,
|
||||
Objects.requireNonNullElse(message, "Unknown asset details error"));
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package p.studio.ui.javafx.workspaces.assets.details;
|
||||
|
||||
import p.studio.api.assets.AssetSummary;
|
||||
import p.studio.api.assets.metadata.AssetStudioGlyphSpecialization;
|
||||
import p.studio.api.assets.workspace.AssetWorkspaceAssetState;
|
||||
import p.studio.api.assets.workspace.AssetWorkspaceAssetSummary;
|
||||
import p.studio.api.assets.workspace.AssetWorkspaceBuildParticipation;
|
||||
|
||||
public final class AssetListMappings {
|
||||
private AssetListMappings() {
|
||||
}
|
||||
|
||||
public static AssetWorkspaceAssetSummary mapSummary(AssetSummary summary) {
|
||||
return new AssetWorkspaceAssetSummary(
|
||||
summary.reference(),
|
||||
summary.name(),
|
||||
AssetWorkspaceAssetState.valueOf(summary.registrationState().name()),
|
||||
AssetWorkspaceBuildParticipation.valueOf(summary.buildParticipation().name()),
|
||||
summary.assetId(),
|
||||
summary.family(),
|
||||
AssetStudioGlyphSpecialization.NONE,
|
||||
summary.root(),
|
||||
summary.preload(),
|
||||
summary.hasDiagnostics());
|
||||
}
|
||||
}
|
||||
+307
@@ -0,0 +1,307 @@
|
||||
package p.studio.ui.javafx.workspaces.assets.details.bank;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.Priority;
|
||||
import javafx.scene.layout.Region;
|
||||
import javafx.scene.layout.VBox;
|
||||
import p.studio.api.assets.AssetCommands;
|
||||
import p.studio.api.assets.AssetDetails;
|
||||
import p.studio.api.assets.bank.AssetBankCompositionSession;
|
||||
import p.studio.api.assets.bank.AssetBankCompositionSessionFactory;
|
||||
import p.studio.api.assets.bank.AssetBankCompositionState;
|
||||
import p.studio.ui.javafx.controls.banks.StudioAssetCapacityMeter;
|
||||
import p.studio.ui.javafx.controls.banks.StudioAssetCapacitySeverity;
|
||||
import p.studio.ui.javafx.controls.forms.StudioFormEditScopeChangedEvent;
|
||||
import p.studio.ui.javafx.controls.forms.StudioFormMode;
|
||||
import p.studio.ui.javafx.controls.forms.StudioFormSection;
|
||||
import p.studio.ui.javafx.events.StudioWorkspaceEventBus;
|
||||
import p.studio.api.project.ProjectReference;
|
||||
import p.studio.ui.javafx.utilities.i18n.I18n;
|
||||
import p.studio.ui.javafx.utilities.i18n.I18nService;
|
||||
import p.studio.ui.javafx.workspaces.assets.messages.AssetWorkspaceDetailsViewState;
|
||||
import p.studio.api.assets.workspace.AssetWorkspaceBankCompositionDetails;
|
||||
import p.studio.api.assets.workspace.AssetWorkspaceBankCompositionFile;
|
||||
import p.studio.ui.javafx.workspaces.assets.messages.events.StudioAssetBankCompositionAppliedEvent;
|
||||
import p.studio.ui.javafx.workspaces.assets.messages.events.StudioAssetBankCompositionApplyFailedEvent;
|
||||
import p.studio.ui.javafx.workspaces.assets.messages.events.StudioAssetBankCompositionApplyRequestedEvent;
|
||||
import p.studio.ui.javafx.workspaces.assets.messages.events.StudioAssetBankCompositionCapacityChangedEvent;
|
||||
import p.studio.ui.javafx.workspaces.assets.messages.events.StudioAssetBankCompositionDraftChangedEvent;
|
||||
import p.studio.ui.javafx.workspaces.assets.messages.events.StudioBankCompositionChangedEvent;
|
||||
import p.studio.ui.javafx.workspaces.assets.messages.events.StudioAssetsDetailsViewStateChangedEvent;
|
||||
import p.studio.ui.javafx.workspaces.framework.StudioSubscriptionBag;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public final class AssetDetailsBankCompositionControl extends StudioFormSection {
|
||||
private static final double CAPACITY_METER_WIDTH = 180.0d;
|
||||
private static final String SECTION_ID = "asset-details.bank-composition";
|
||||
|
||||
private final ProjectReference projectReference;
|
||||
private final StudioWorkspaceEventBus workspaceBus;
|
||||
private final StudioSubscriptionBag subscriptions = new StudioSubscriptionBag();
|
||||
private final AssetDetailsBankCompositionDualListView dualListView;
|
||||
private final StudioAssetCapacityMeter capacityMeter = new StudioAssetCapacityMeter();
|
||||
private final AssetBankCompositionSession coordinator;
|
||||
private final HBox body;
|
||||
private final VBox content;
|
||||
|
||||
private AssetWorkspaceDetailsViewState viewState;
|
||||
private final java.util.concurrent.Executor executor;
|
||||
private final I18nService i18n;
|
||||
private final AssetDetails assetDetails;
|
||||
private final AssetCommands assetCommands;
|
||||
|
||||
public AssetDetailsBankCompositionControl(ProjectReference projectReference, StudioWorkspaceEventBus workspaceBus,
|
||||
I18nService i18n, java.util.concurrent.Executor executor, AssetDetails assetDetails,
|
||||
AssetCommands assetCommands, AssetBankCompositionSessionFactory sessionFactory) {
|
||||
super(i18n);
|
||||
this.i18n = Objects.requireNonNull(i18n, "i18n");
|
||||
this.executor = Objects.requireNonNull(executor, "executor");
|
||||
this.assetDetails = Objects.requireNonNull(assetDetails, "assetDetails");
|
||||
this.assetCommands = Objects.requireNonNull(assetCommands, "assetCommands");
|
||||
this.projectReference = Objects.requireNonNull(projectReference, "projectReference");
|
||||
this.workspaceBus = Objects.requireNonNull(workspaceBus, "workspaceBus");
|
||||
this.coordinator = Objects.requireNonNull(sessionFactory, "sessionFactory").createSession();
|
||||
this.dualListView = new AssetDetailsBankCompositionDualListView(i18n);
|
||||
this.body = new HBox(16, dualListView, capacityMeter);
|
||||
this.content = new VBox(12, body);
|
||||
capacityMeter.setMinWidth(CAPACITY_METER_WIDTH);
|
||||
capacityMeter.setPrefWidth(CAPACITY_METER_WIDTH);
|
||||
capacityMeter.setMaxWidth(CAPACITY_METER_WIDTH);
|
||||
capacityMeter.setMinHeight(Region.USE_PREF_SIZE);
|
||||
capacityMeter.setMaxHeight(Double.MAX_VALUE);
|
||||
body.getStyleClass().add("assets-details-bank-composition-body");
|
||||
body.setFillHeight(true);
|
||||
body.setMinHeight(0.0d);
|
||||
body.setMaxHeight(Double.MAX_VALUE);
|
||||
content.setFillWidth(true);
|
||||
content.setMinHeight(0.0d);
|
||||
content.setMaxHeight(Double.MAX_VALUE);
|
||||
VBox.setVgrow(body, Priority.ALWAYS);
|
||||
HBox.setHgrow(dualListView, Priority.ALWAYS);
|
||||
dualListView.setMaxWidth(Double.MAX_VALUE);
|
||||
dualListView.setMinHeight(0.0d);
|
||||
dualListView.setMaxHeight(Double.MAX_VALUE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void subscribe() {
|
||||
subscriptions.add(workspaceBus.subscribe(StudioAssetsDetailsViewStateChangedEvent.class, event -> {
|
||||
viewState = event.viewState();
|
||||
coordinator.replaceDetails(viewState == null ? null : viewState.selectedAssetDetails());
|
||||
if (viewState == null || viewState.selectedAssetReference() == null) {
|
||||
publishEditScope(workspaceBus, currentScopeKey(), null);
|
||||
}
|
||||
renderSection();
|
||||
publishStateNotifications();
|
||||
}));
|
||||
subscriptions.add(workspaceBus.subscribe(StudioFormEditScopeChangedEvent.class,
|
||||
event -> handleEditScopeChanged(event, currentScopeKey())));
|
||||
subscriptions.add(workspaceBus.subscribe(StudioBankCompositionChangedEvent.class, event -> {
|
||||
if (viewState == null || !Objects.equals(viewState.selectedAssetReference(), event.assetReference())) {
|
||||
return;
|
||||
}
|
||||
viewState = new AssetWorkspaceDetailsViewState(
|
||||
viewState.detailsStatus(),
|
||||
viewState.selectedAssetReference(),
|
||||
viewState.selectedAssetDetails().withBankComposition(event.bankComposition()),
|
||||
viewState.detailsErrorMessage());
|
||||
coordinator.replaceDetails(viewState.selectedAssetDetails());
|
||||
renderSection();
|
||||
publishStateNotifications();
|
||||
}));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unsubscribe() {
|
||||
subscriptions.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderSection() {
|
||||
if (viewState == null || viewState.selectedAssetDetails() == null) {
|
||||
clearRenderedSection();
|
||||
return;
|
||||
}
|
||||
if (!coordinator.ready()) {
|
||||
clearRenderedSection();
|
||||
return;
|
||||
}
|
||||
|
||||
final AssetBankCompositionState viewModel = coordinator.state();
|
||||
|
||||
dualListView.setAssetRoot(viewState.selectedAssetDetails().summary().assetRoot());
|
||||
dualListView.setLeftItems(viewModel.availableFiles());
|
||||
dualListView.setRightItems(viewModel.selectedFiles());
|
||||
dualListView.setInteractionEnabled(viewModel.editing());
|
||||
dualListView.setMoveToRightAllowed(!viewModel.capacityState().blocked());
|
||||
dualListView.setOnMoveToRight(items -> {
|
||||
coordinator.moveToSelected(items);
|
||||
rerenderPreservingScrollPosition();
|
||||
publishStateNotifications();
|
||||
});
|
||||
dualListView.setOnMoveToLeft(items -> {
|
||||
coordinator.moveToAvailable(items);
|
||||
rerenderPreservingScrollPosition();
|
||||
publishStateNotifications();
|
||||
});
|
||||
dualListView.setOnMoveUp(index -> {
|
||||
coordinator.moveUp(index);
|
||||
rerenderPreservingScrollPosition();
|
||||
publishStateNotifications();
|
||||
});
|
||||
dualListView.setOnMoveDown(index -> {
|
||||
coordinator.moveDown(index);
|
||||
rerenderPreservingScrollPosition();
|
||||
publishStateNotifications();
|
||||
});
|
||||
|
||||
capacityMeter.setProgress(viewModel.capacityState().progress());
|
||||
capacityMeter.setSeverity(visualSeverity(viewModel.capacityState()));
|
||||
capacityMeter.setLabelText("Bank Capacity");
|
||||
capacityMeter.setHintText("");
|
||||
|
||||
renderFormSection(content);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String sectionTitle() {
|
||||
return i18n.text(I18n.ASSETS_SECTION_BANK_COMPOSITION);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected StudioFormMode formMode() {
|
||||
return coordinator.ready() && coordinator.state().editing() ? StudioFormMode.EDITING : StudioFormMode.READ_ONLY;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isDirty() {
|
||||
return coordinator.ready() && coordinator.state().dirty();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String sectionStyleClass() {
|
||||
return "assets-details-bank-composition-section";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String formSectionId() {
|
||||
return SECTION_ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void beginEdit() {
|
||||
coordinator.beginEdit();
|
||||
publishEditScope(workspaceBus, currentScopeKey(), SECTION_ID);
|
||||
publishStateNotifications();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void apply() {
|
||||
if (viewState == null || viewState.selectedAssetReference() == null || !coordinator.ready()) {
|
||||
return;
|
||||
}
|
||||
final var assetReference = viewState.selectedAssetReference();
|
||||
final var selectedPaths = coordinator.state().selectedFiles().stream()
|
||||
.map(file -> file.path())
|
||||
.toList();
|
||||
workspaceBus.publish(new StudioAssetBankCompositionApplyRequestedEvent(assetReference));
|
||||
executor.execute(() -> {
|
||||
try {
|
||||
final var response = assetCommands.applyBankComposition(projectReference, assetReference, selectedPaths);
|
||||
Platform.runLater(() -> {
|
||||
if (response.success()) {
|
||||
publishEditScope(workspaceBus, currentScopeKey(), null);
|
||||
workspaceBus.publish(new StudioAssetBankCompositionAppliedEvent(assetReference));
|
||||
executor.execute(() -> publishAppliedBankComposition(assetReference));
|
||||
} else {
|
||||
workspaceBus.publish(new StudioAssetBankCompositionApplyFailedEvent(
|
||||
assetReference,
|
||||
response.errorMessage()));
|
||||
}
|
||||
});
|
||||
} catch (Exception exception) {
|
||||
Platform.runLater(() -> workspaceBus.publish(new StudioAssetBankCompositionApplyFailedEvent(
|
||||
assetReference,
|
||||
"Unable to apply bank composition.")));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void publishAppliedBankComposition(p.studio.api.assets.AssetReference assetReference) {
|
||||
try {
|
||||
final var detailsResult = assetDetails.get(projectReference, assetReference);
|
||||
final AssetWorkspaceBankCompositionDetails bankComposition = mapBankComposition(detailsResult.bankComposition());
|
||||
Platform.runLater(() -> workspaceBus.publish(new StudioBankCompositionChangedEvent(assetReference, bankComposition)));
|
||||
} catch (Exception exception) {
|
||||
Platform.runLater(() -> workspaceBus.publish(new StudioAssetBankCompositionApplyFailedEvent(
|
||||
assetReference,
|
||||
"Unable to reload bank composition.")));
|
||||
}
|
||||
}
|
||||
|
||||
private AssetWorkspaceBankCompositionDetails mapBankComposition(p.studio.api.assets.AssetBankComposition details) {
|
||||
return new AssetWorkspaceBankCompositionDetails(
|
||||
details.availableFiles().stream().map(this::mapBankCompositionFile).toList(),
|
||||
details.selectedFiles().stream().map(this::mapBankCompositionFile).toList(),
|
||||
details.measuredBankSizeBytes());
|
||||
}
|
||||
|
||||
private AssetWorkspaceBankCompositionFile mapBankCompositionFile(p.studio.api.assets.AssetBankFile file) {
|
||||
return new AssetWorkspaceBankCompositionFile(
|
||||
file.path(),
|
||||
file.displayName(),
|
||||
file.size(),
|
||||
file.lastModified(),
|
||||
file.fingerprint(),
|
||||
file.metadata());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void reset() {
|
||||
coordinator.reset();
|
||||
publishStateNotifications();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void cancel() {
|
||||
coordinator.cancel();
|
||||
publishEditScope(workspaceBus, currentScopeKey(), null);
|
||||
publishStateNotifications();
|
||||
}
|
||||
|
||||
private void publishStateNotifications() {
|
||||
if (viewState == null || viewState.selectedAssetReference() == null || !coordinator.ready()) {
|
||||
return;
|
||||
}
|
||||
final AssetBankCompositionState viewModel = coordinator.state();
|
||||
workspaceBus.publish(new StudioAssetBankCompositionDraftChangedEvent(
|
||||
viewState.selectedAssetReference(),
|
||||
viewModel.editing(),
|
||||
viewModel.dirty(),
|
||||
viewModel.availableFiles().size(),
|
||||
viewModel.selectedFiles().size()));
|
||||
workspaceBus.publish(new StudioAssetBankCompositionCapacityChangedEvent(
|
||||
viewState.selectedAssetReference(),
|
||||
viewModel.capacityState().progress(),
|
||||
visualSeverity(viewModel.capacityState()),
|
||||
viewModel.capacityState().blocked(),
|
||||
viewModel.capacityState().labelText(),
|
||||
viewModel.capacityState().hintText()));
|
||||
}
|
||||
|
||||
private String currentScopeKey() {
|
||||
return viewState == null || viewState.selectedAssetReference() == null
|
||||
? null
|
||||
: "asset-details:" + viewState.selectedAssetReference();
|
||||
}
|
||||
|
||||
private StudioAssetCapacitySeverity visualSeverity(p.studio.api.assets.AssetCapacityState state) {
|
||||
return switch (state.level()) {
|
||||
case SAFE -> StudioAssetCapacitySeverity.GREEN;
|
||||
case WARNING -> StudioAssetCapacitySeverity.ORANGE;
|
||||
case EXHAUSTED -> StudioAssetCapacitySeverity.RED;
|
||||
};
|
||||
}
|
||||
}
|
||||
+151
@@ -0,0 +1,151 @@
|
||||
package p.studio.ui.javafx.workspaces.assets.details.bank;
|
||||
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.Priority;
|
||||
import javafx.scene.layout.Region;
|
||||
import javafx.scene.layout.VBox;
|
||||
import p.studio.ui.javafx.controls.banks.StudioDualListView;
|
||||
import p.studio.ui.javafx.utilities.i18n.I18n;
|
||||
import p.studio.ui.javafx.utilities.i18n.I18nService;
|
||||
import p.studio.api.assets.workspace.AssetWorkspaceBankCompositionFile;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public final class AssetDetailsBankCompositionDualListView extends StudioDualListView<AssetWorkspaceBankCompositionFile> {
|
||||
private static final double THUMBNAIL_SIZE = 28.0d;
|
||||
|
||||
private Path assetRoot;
|
||||
|
||||
public AssetDetailsBankCompositionDualListView(I18nService i18n) {
|
||||
setLeftTitle(i18n.text(I18n.ASSETS_DETAILS_BANK_COMPOSITION_AVAILABLE));
|
||||
setRightTitle(i18n.text(I18n.ASSETS_DETAILS_BANK_COMPOSITION_SELECTED));
|
||||
}
|
||||
|
||||
public void setAssetRoot(Path assetRoot) {
|
||||
this.assetRoot = assetRoot == null ? null : assetRoot.toAbsolutePath().normalize();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String itemText(AssetWorkspaceBankCompositionFile item) {
|
||||
if (item.displayName().equals(item.path())) {
|
||||
return item.displayName();
|
||||
}
|
||||
return item.displayName() + " [" + item.path() + "]";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Node itemGraphic(AssetWorkspaceBankCompositionFile item) {
|
||||
final String dimensions = tileDimensions(item.metadata());
|
||||
final String colors = tileColorCount(item.metadata());
|
||||
if (dimensions == null && colors == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final Node thumbnail = createThumbnail(item);
|
||||
final Label nameLabel = new Label(item.displayName());
|
||||
nameLabel.getStyleClass().add("assets-details-bank-file-name");
|
||||
nameLabel.setWrapText(true);
|
||||
nameLabel.setMaxWidth(Double.MAX_VALUE);
|
||||
|
||||
final Region spacer = new Region();
|
||||
HBox.setHgrow(spacer, Priority.ALWAYS);
|
||||
|
||||
final VBox metaColumn = new VBox(2);
|
||||
metaColumn.setAlignment(Pos.CENTER_RIGHT);
|
||||
metaColumn.getStyleClass().add("assets-details-bank-file-meta");
|
||||
|
||||
if (dimensions != null) {
|
||||
final Label dimensionsLabel = new Label(dimensions);
|
||||
dimensionsLabel.getStyleClass().add("assets-details-bank-file-dimensions");
|
||||
metaColumn.getChildren().add(dimensionsLabel);
|
||||
}
|
||||
if (colors != null) {
|
||||
final Label colorsLabel = new Label(colors);
|
||||
colorsLabel.getStyleClass().add("assets-details-bank-file-colors");
|
||||
metaColumn.getChildren().add(colorsLabel);
|
||||
}
|
||||
|
||||
final HBox root = thumbnail == null
|
||||
? new HBox(10, nameLabel, spacer, metaColumn)
|
||||
: new HBox(10, nameLabel, spacer, thumbnail, metaColumn);
|
||||
root.setAlignment(Pos.CENTER_LEFT);
|
||||
root.getStyleClass().add("assets-details-bank-file-cell");
|
||||
return root;
|
||||
}
|
||||
|
||||
private Node createThumbnail(AssetWorkspaceBankCompositionFile item) {
|
||||
final Path filePath = assetRoot == null ? null : assetRoot.resolve(item.path()).toAbsolutePath().normalize();
|
||||
if (filePath == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
final Image image = new Image(filePath.toUri().toString(), THUMBNAIL_SIZE, THUMBNAIL_SIZE, true, true, true);
|
||||
if (image.isError()) {
|
||||
return null;
|
||||
}
|
||||
final ImageView imageView = new ImageView(image);
|
||||
imageView.setFitWidth(THUMBNAIL_SIZE);
|
||||
imageView.setFitHeight(THUMBNAIL_SIZE);
|
||||
imageView.setPreserveRatio(true);
|
||||
imageView.getStyleClass().add("assets-details-bank-file-thumbnail");
|
||||
return imageView;
|
||||
} catch (RuntimeException ignored) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private String tileDimensions(Map<String, Object> metadata) {
|
||||
final Map<String, Object> tile = nestedMap(metadata, "tile");
|
||||
if (tile == null) {
|
||||
return null;
|
||||
}
|
||||
final Integer width = asInteger(tile.get("width"));
|
||||
final Integer height = asInteger(tile.get("height"));
|
||||
if (width == null || height == null) {
|
||||
return null;
|
||||
}
|
||||
return width + "x" + height;
|
||||
}
|
||||
|
||||
private String tileColorCount(Map<String, Object> metadata) {
|
||||
final Map<String, Object> palette = nestedMap(metadata, "palette");
|
||||
if (palette == null) {
|
||||
return null;
|
||||
}
|
||||
final Object originalArgb8888 = palette.get("originalArgb8888");
|
||||
if (originalArgb8888 instanceof Collection<?> colors) {
|
||||
return colors.size() + " colors";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Map<String, Object> nestedMap(Map<String, Object> metadata, String key) {
|
||||
final Object value = metadata.get(key);
|
||||
if (value instanceof Map<?, ?> nested) {
|
||||
return (Map<String, Object>) nested;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Integer asInteger(Object value) {
|
||||
if (value instanceof Number number) {
|
||||
return number.intValue();
|
||||
}
|
||||
if (value instanceof String text) {
|
||||
try {
|
||||
return Integer.parseInt(text);
|
||||
} catch (NumberFormatException ignored) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+616
@@ -0,0 +1,616 @@
|
||||
package p.studio.ui.javafx.workspaces.assets.details.contract;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.control.CheckBox;
|
||||
import javafx.scene.control.ComboBox;
|
||||
import javafx.scene.control.Control;
|
||||
import javafx.scene.control.ScrollPane;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.Priority;
|
||||
import javafx.scene.layout.VBox;
|
||||
import p.studio.api.assets.AssetConfigurationField;
|
||||
import p.studio.api.assets.AssetCommands;
|
||||
import p.studio.ui.javafx.controls.forms.StudioFormEditScopeChangedEvent;
|
||||
import p.studio.ui.javafx.controls.forms.StudioFormMode;
|
||||
import p.studio.ui.javafx.controls.forms.StudioFormSession;
|
||||
import p.studio.ui.javafx.controls.forms.StudioFormSection;
|
||||
import p.studio.ui.javafx.controls.lifecycle.StudioControlLifecycle;
|
||||
import p.studio.ui.javafx.controls.lifecycle.StudioControlLifecycleSupport;
|
||||
import p.studio.ui.javafx.events.StudioWorkspaceEventBus;
|
||||
import p.studio.api.project.ProjectReference;
|
||||
import p.studio.ui.javafx.utilities.i18n.I18n;
|
||||
import p.studio.ui.javafx.workspaces.assets.details.AssetDetailsUiSupport;
|
||||
import p.studio.api.assets.workspace.AssetWorkspaceAssetDetails;
|
||||
import p.studio.ui.javafx.workspaces.assets.messages.AssetWorkspaceDetailsViewState;
|
||||
import p.studio.ui.javafx.workspaces.assets.messages.events.StudioAssetLogEvent;
|
||||
import p.studio.ui.javafx.workspaces.assets.messages.events.StudioAssetsDetailsViewStateChangedEvent;
|
||||
import p.studio.ui.javafx.workspaces.assets.messages.events.StudioAssetsRefreshRequestedEvent;
|
||||
import p.studio.ui.javafx.workspaces.assets.messages.events.StudioAssetsWorkspaceSelectionRequestedEvent;
|
||||
import p.studio.ui.javafx.workspaces.framework.StudioSubscriptionBag;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public final class AssetDetailsContractControl extends HBox implements StudioControlLifecycle {
|
||||
private final ProjectReference projectReference;
|
||||
private final StudioWorkspaceEventBus workspaceBus;
|
||||
private final StudioSubscriptionBag subscriptions = new StudioSubscriptionBag();
|
||||
|
||||
private final RuntimeContractSection runtimeSection;
|
||||
private final CodecSection codecSection;
|
||||
private final p.studio.ui.javafx.utilities.i18n.I18nService i18n;
|
||||
private final java.util.concurrent.Executor executor;
|
||||
private final AssetCommands assetCommands;
|
||||
|
||||
private AssetWorkspaceDetailsViewState viewState;
|
||||
|
||||
public AssetDetailsContractControl(ProjectReference projectReference, StudioWorkspaceEventBus workspaceBus,
|
||||
p.studio.ui.javafx.utilities.i18n.I18nService i18n, java.util.concurrent.Executor executor,
|
||||
AssetCommands assetCommands) {
|
||||
StudioControlLifecycleSupport.install(this, this);
|
||||
this.projectReference = Objects.requireNonNull(projectReference, "projectReference");
|
||||
this.workspaceBus = Objects.requireNonNull(workspaceBus, "workspaceBus");
|
||||
this.i18n = Objects.requireNonNull(i18n, "i18n");
|
||||
this.executor = Objects.requireNonNull(executor, "executor");
|
||||
this.assetCommands = Objects.requireNonNull(assetCommands, "assetCommands");
|
||||
this.runtimeSection = new RuntimeContractSection();
|
||||
this.codecSection = new CodecSection();
|
||||
getStyleClass().add("assets-details-contract-body");
|
||||
setSpacing(16);
|
||||
HBox.setHgrow(runtimeSection, Priority.ALWAYS);
|
||||
HBox.setHgrow(codecSection, Priority.ALWAYS);
|
||||
runtimeSection.setMaxWidth(Double.MAX_VALUE);
|
||||
codecSection.setMaxWidth(Double.MAX_VALUE);
|
||||
runtimeSection.prefWidthProperty().bind(widthProperty().subtract(16).multiply(0.5d));
|
||||
codecSection.prefWidthProperty().bind(widthProperty().subtract(16).multiply(0.5d));
|
||||
getChildren().setAll(runtimeSection, codecSection);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void subscribe() {
|
||||
subscriptions.add(workspaceBus.subscribe(StudioAssetsDetailsViewStateChangedEvent.class, event -> {
|
||||
viewState = event.viewState();
|
||||
runtimeSection.syncSession();
|
||||
codecSection.syncSession();
|
||||
runtimeSection.renderSection();
|
||||
codecSection.renderSection();
|
||||
}));
|
||||
subscriptions.add(workspaceBus.subscribe(StudioFormEditScopeChangedEvent.class, event -> {
|
||||
runtimeSection.handleExternalEditScopeChanged(event);
|
||||
codecSection.handleExternalEditScopeChanged(event);
|
||||
}));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unsubscribe() {
|
||||
subscriptions.clear();
|
||||
}
|
||||
|
||||
private String currentScopeKey() {
|
||||
return viewState == null || viewState.selectedAssetReference() == null
|
||||
? null
|
||||
: "asset-details:" + viewState.selectedAssetReference();
|
||||
}
|
||||
|
||||
private AssetWorkspaceAssetDetails selectedDetails() {
|
||||
return viewState == null ? null : viewState.selectedAssetDetails();
|
||||
}
|
||||
|
||||
private void requestRefresh() {
|
||||
if (viewState == null || viewState.selectedAssetReference() == null) {
|
||||
return;
|
||||
}
|
||||
workspaceBus.publish(new StudioAssetsWorkspaceSelectionRequestedEvent(viewState.selectedAssetReference(), true));
|
||||
}
|
||||
|
||||
private void logContractEvent(String message) {
|
||||
workspaceBus.publish(new StudioAssetLogEvent("ASSET DETAILS CONTRACT", message));
|
||||
}
|
||||
|
||||
private abstract class BaseContractSection<D> extends StudioFormSection {
|
||||
private final String sectionId;
|
||||
private final VBox content = new VBox(12);
|
||||
private StudioFormSession<D> formSession;
|
||||
|
||||
protected BaseContractSection(String sectionId) {
|
||||
super(i18n);
|
||||
this.sectionId = sectionId;
|
||||
getStyleClass().add("assets-details-contract-section-host");
|
||||
content.getStyleClass().add("assets-details-contract-column");
|
||||
}
|
||||
|
||||
protected abstract D sourceFromDetails(AssetWorkspaceAssetDetails details);
|
||||
|
||||
protected abstract Node buildContent(AssetWorkspaceAssetDetails details, D draft, boolean editing);
|
||||
|
||||
protected abstract void applyDraft(D draft);
|
||||
|
||||
protected final StudioFormSession<D> formSession() {
|
||||
return formSession;
|
||||
}
|
||||
|
||||
protected final void syncSession() {
|
||||
final AssetWorkspaceAssetDetails details = selectedDetails();
|
||||
if (details == null) {
|
||||
publishEditScope(workspaceBus, currentScopeKey(), null);
|
||||
formSession = null;
|
||||
return;
|
||||
}
|
||||
final D source = sourceFromDetails(details);
|
||||
if (formSession == null) {
|
||||
formSession = new StudioFormSession<>(source);
|
||||
return;
|
||||
}
|
||||
if (!Objects.equals(formSession.source(), source)) {
|
||||
publishEditScope(workspaceBus, currentScopeKey(), null);
|
||||
formSession.replaceSource(source);
|
||||
}
|
||||
}
|
||||
|
||||
protected final void handleExternalEditScopeChanged(StudioFormEditScopeChangedEvent event) {
|
||||
handleEditScopeChanged(event, currentScopeKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final void renderSection() {
|
||||
final AssetWorkspaceAssetDetails details = selectedDetails();
|
||||
if (details == null) {
|
||||
clearRenderedSection();
|
||||
return;
|
||||
}
|
||||
if (formSession == null) {
|
||||
syncSession();
|
||||
}
|
||||
if (formSession == null) {
|
||||
clearRenderedSection();
|
||||
return;
|
||||
}
|
||||
content.getChildren().setAll(buildContent(details, formSession.draft(), formSession.mode() == StudioFormMode.EDITING));
|
||||
renderFormSection(content);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final StudioFormMode formMode() {
|
||||
return formSession == null ? StudioFormMode.READ_ONLY : formSession.mode();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final boolean isDirty() {
|
||||
return formSession != null && formSession.isDirty();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final void beginEdit() {
|
||||
if (formSession == null) {
|
||||
return;
|
||||
}
|
||||
formSession.beginEdit();
|
||||
publishEditScope(workspaceBus, currentScopeKey(), sectionId);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final void apply() {
|
||||
if (formSession == null) {
|
||||
return;
|
||||
}
|
||||
applyDraft(formSession.draft());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final void reset() {
|
||||
if (formSession == null) {
|
||||
return;
|
||||
}
|
||||
formSession.resetDraft();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final void cancel() {
|
||||
if (formSession == null) {
|
||||
return;
|
||||
}
|
||||
formSession.cancelEdit();
|
||||
publishEditScope(workspaceBus, currentScopeKey(), null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final String formSectionId() {
|
||||
return sectionId;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final String sectionStyleClass() {
|
||||
return "assets-details-contract-section";
|
||||
}
|
||||
}
|
||||
|
||||
private final class RuntimeContractSection extends BaseContractSection<RuntimeContractDraft> {
|
||||
private static final String SECTION_ID = "asset-details.runtime-contract";
|
||||
|
||||
private RuntimeContractSection() {
|
||||
super(SECTION_ID);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected RuntimeContractDraft sourceFromDetails(AssetWorkspaceAssetDetails details) {
|
||||
return RuntimeContractDraft.fromDetails(details);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Node buildContent(AssetWorkspaceAssetDetails details, RuntimeContractDraft draft, boolean editing) {
|
||||
final VBox column = new VBox(8);
|
||||
column.getChildren().add(AssetDetailsUiSupport.createKeyValueRow(
|
||||
i18n.text(I18n.ASSETS_LABEL_PRELOAD),
|
||||
createPreloadEditor(draft, editing)));
|
||||
column.getChildren().add(AssetDetailsUiSupport.createKeyValueRow(
|
||||
i18n.text(I18n.ASSETS_LABEL_BANK),
|
||||
draft.bank()));
|
||||
column.getChildren().add(createRuntimeMetadataSection(details, draft, editing));
|
||||
return column;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String sectionTitle() {
|
||||
return i18n.text(I18n.ASSETS_SECTION_RUNTIME_CONTRACT);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void applyDraft(RuntimeContractDraft draft) {
|
||||
final AssetWorkspaceAssetDetails details = selectedDetails();
|
||||
if (details == null) {
|
||||
return;
|
||||
}
|
||||
executor.execute(() -> {
|
||||
try {
|
||||
final var response = assetCommands.updateContract(
|
||||
projectReference,
|
||||
draft.assetReference(),
|
||||
draft.preload(),
|
||||
details.outputCodec(),
|
||||
currentCodecFieldValues(details),
|
||||
draft.metadataFieldValues());
|
||||
Platform.runLater(() -> handleApplyResponse(response.success(), response.errorMessage()));
|
||||
} catch (Exception exception) {
|
||||
Platform.runLater(() -> handleApplyResponse(false, "Unable to update runtime contract."));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void handleApplyResponse(boolean success, String errorMessage) {
|
||||
if (success) {
|
||||
formSession().apply();
|
||||
publishEditScope(workspaceBus, currentScopeKey(), null);
|
||||
logContractEvent("Runtime contract updated");
|
||||
requestRefresh();
|
||||
renderSection();
|
||||
return;
|
||||
}
|
||||
logContractEvent(errorMessage);
|
||||
cancel();
|
||||
renderSection();
|
||||
}
|
||||
|
||||
private Node createPreloadEditor(RuntimeContractDraft draft, boolean editing) {
|
||||
final CheckBox checkBox = new CheckBox();
|
||||
checkBox.getStyleClass().add("assets-details-readonly-check");
|
||||
checkBox.setSelected(draft.preload());
|
||||
if (editing) {
|
||||
checkBox.selectedProperty().addListener((ignored, oldValue, newValue) -> {
|
||||
if (!Objects.equals(oldValue, newValue)) {
|
||||
formSession().updateDraft(current -> current.withPreload(newValue));
|
||||
updateActionBarState();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
configureReadOnlyControl(checkBox);
|
||||
}
|
||||
return checkBox;
|
||||
}
|
||||
|
||||
private Node createMetadataFieldControl(
|
||||
AssetConfigurationField field,
|
||||
RuntimeContractDraft draft,
|
||||
boolean editing) {
|
||||
return switch (field.fieldType()) {
|
||||
case "BOOLEAN" -> createMetadataBooleanField(field, draft, editing);
|
||||
case "ENUM" -> createMetadataEnumField(field, draft, editing);
|
||||
case "INTEGER", "TEXT" -> createMetadataTextField(field, draft, editing);
|
||||
default -> createMetadataTextField(field, draft, editing);
|
||||
};
|
||||
}
|
||||
|
||||
private Node createRuntimeMetadataSection(
|
||||
AssetWorkspaceAssetDetails details,
|
||||
RuntimeContractDraft draft,
|
||||
boolean editing) {
|
||||
final VBox content = new VBox(8);
|
||||
content.getStyleClass().add("assets-details-contract-metadata-content");
|
||||
if (details.metadataFields().isEmpty()) {
|
||||
content.getChildren().add(AssetDetailsUiSupport.createSectionMessage(
|
||||
i18n.text(I18n.ASSETS_DETAILS_METADATA_EMPTY)));
|
||||
return createCodecMetadataPane(content);
|
||||
}
|
||||
for (AssetConfigurationField field : details.metadataFields()) {
|
||||
content.getChildren().add(createLabeledFieldRow(
|
||||
field.label(),
|
||||
createMetadataFieldControl(field, draft, editing)));
|
||||
}
|
||||
return createCodecMetadataPane(content);
|
||||
}
|
||||
|
||||
private Node createMetadataBooleanField(AssetConfigurationField field, RuntimeContractDraft draft, boolean editing) {
|
||||
final CheckBox checkBox = new CheckBox();
|
||||
checkBox.getStyleClass().add("assets-details-readonly-check");
|
||||
checkBox.setSelected(Boolean.parseBoolean(draft.metadataFieldValue(field.key(), field.value())));
|
||||
if (editing) {
|
||||
checkBox.selectedProperty().addListener((ignored, oldValue, newValue) -> {
|
||||
if (!Objects.equals(oldValue, newValue)) {
|
||||
formSession().updateDraft(current -> current.withMetadataFieldValue(field.key(), Boolean.toString(newValue)));
|
||||
updateActionBarState();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
configureReadOnlyControl(checkBox);
|
||||
}
|
||||
return checkBox;
|
||||
}
|
||||
|
||||
private Node createMetadataEnumField(AssetConfigurationField field, RuntimeContractDraft draft, boolean editing) {
|
||||
final ComboBox<String> comboBox = new ComboBox<>(FXCollections.observableArrayList(field.options()));
|
||||
comboBox.getStyleClass().add("assets-details-combo");
|
||||
comboBox.setMaxWidth(Double.MAX_VALUE);
|
||||
comboBox.getSelectionModel().select(draft.metadataFieldValue(field.key(), field.value()));
|
||||
if (editing) {
|
||||
comboBox.valueProperty().addListener((ignored, oldValue, newValue) -> {
|
||||
if (newValue != null && !Objects.equals(oldValue, newValue)) {
|
||||
formSession().updateDraft(current -> current.withMetadataFieldValue(field.key(), newValue));
|
||||
updateActionBarState();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
configureReadOnlyControl(comboBox);
|
||||
}
|
||||
return comboBox;
|
||||
}
|
||||
|
||||
private Node createMetadataTextField(AssetConfigurationField field, RuntimeContractDraft draft, boolean editing) {
|
||||
final TextField textField = new TextField(draft.metadataFieldValue(field.key(), field.value()));
|
||||
textField.getStyleClass().add("assets-workspace-search");
|
||||
textField.setMaxWidth(Double.MAX_VALUE);
|
||||
if (editing) {
|
||||
textField.textProperty().addListener((ignored, oldValue, newValue) -> {
|
||||
if (!Objects.equals(oldValue, newValue)) {
|
||||
formSession().updateDraft(current -> current.withMetadataFieldValue(field.key(), Objects.requireNonNullElse(newValue, "")));
|
||||
updateActionBarState();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
textField.setEditable(false);
|
||||
configureReadOnlyControl(textField);
|
||||
}
|
||||
return textField;
|
||||
}
|
||||
}
|
||||
|
||||
private final class CodecSection extends BaseContractSection<CodecDraft> {
|
||||
private static final String SECTION_ID = "asset-details.codec";
|
||||
|
||||
private CodecSection() {
|
||||
super(SECTION_ID);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CodecDraft sourceFromDetails(AssetWorkspaceAssetDetails details) {
|
||||
return CodecDraft.fromDetails(details);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Node buildContent(AssetWorkspaceAssetDetails details, CodecDraft draft, boolean editing) {
|
||||
final VBox column = new VBox(8);
|
||||
column.getStyleClass().add("assets-details-contract-codec-column");
|
||||
column.getChildren().add(createCodecEditor(details, draft, editing));
|
||||
column.getChildren().add(createCodecConfigurationSection(details, draft, editing));
|
||||
return column;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String sectionTitle() {
|
||||
return i18n.text(I18n.ASSETS_LABEL_CODEC);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void applyDraft(CodecDraft draft) {
|
||||
final AssetWorkspaceAssetDetails details = selectedDetails();
|
||||
if (details == null) {
|
||||
return;
|
||||
}
|
||||
executor.execute(() -> {
|
||||
try {
|
||||
final var response = assetCommands.updateContract(
|
||||
projectReference,
|
||||
draft.assetReference(),
|
||||
details.summary().preload(),
|
||||
draft.selectedCodec(),
|
||||
draft.codecFieldValues(),
|
||||
currentMetadataFieldValues(details));
|
||||
Platform.runLater(() -> handleApplyResponse(response.success(), response.errorMessage()));
|
||||
} catch (Exception exception) {
|
||||
Platform.runLater(() -> handleApplyResponse(false, "Unable to update codec contract."));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void handleApplyResponse(boolean success, String errorMessage) {
|
||||
if (success) {
|
||||
formSession().apply();
|
||||
publishEditScope(workspaceBus, currentScopeKey(), null);
|
||||
logContractEvent("Codec updated");
|
||||
requestRefresh();
|
||||
renderSection();
|
||||
return;
|
||||
}
|
||||
logContractEvent(errorMessage);
|
||||
cancel();
|
||||
renderSection();
|
||||
}
|
||||
|
||||
private Node createCodecEditor(AssetWorkspaceAssetDetails details, CodecDraft draft, boolean editing) {
|
||||
final ComboBox<String> codecCombo = new ComboBox<>(FXCollections.observableArrayList(details.availableOutputCodecs()));
|
||||
codecCombo.getStyleClass().add("assets-details-combo");
|
||||
codecCombo.setMaxWidth(Double.MAX_VALUE);
|
||||
codecCombo.setCellFactory(ignored -> new javafx.scene.control.ListCell<>() {
|
||||
@Override
|
||||
protected void updateItem(String item, boolean empty) {
|
||||
super.updateItem(item, empty);
|
||||
setText(empty || item == null ? null : AssetDetailsUiSupport.catalogLabel(item));
|
||||
}
|
||||
});
|
||||
codecCombo.setButtonCell(new javafx.scene.control.ListCell<>() {
|
||||
@Override
|
||||
protected void updateItem(String item, boolean empty) {
|
||||
super.updateItem(item, empty);
|
||||
setText(empty || item == null ? null : AssetDetailsUiSupport.catalogLabel(item));
|
||||
}
|
||||
});
|
||||
codecCombo.getSelectionModel().select(draft.selectedCodec());
|
||||
if (editing) {
|
||||
codecCombo.valueProperty().addListener((ignored, oldValue, newValue) -> {
|
||||
if (newValue != null && !Objects.equals(oldValue, newValue)) {
|
||||
formSession().updateDraft(current -> current.withSelectedCodec(newValue));
|
||||
renderSection();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
configureReadOnlyControl(codecCombo);
|
||||
}
|
||||
return codecCombo;
|
||||
}
|
||||
|
||||
private Node createCodecConfigurationSection(AssetWorkspaceAssetDetails details, CodecDraft draft, boolean editing) {
|
||||
final VBox content = new VBox(8);
|
||||
content.getStyleClass().add("assets-details-contract-metadata-content");
|
||||
if ("NONE".equals(draft.selectedCodec()) || "UNKNOWN".equals(draft.selectedCodec())) {
|
||||
content.getChildren().add(AssetDetailsUiSupport.createSectionMessage(
|
||||
i18n.text(I18n.ASSETS_DETAILS_CODEC_CONFIGURATION_EMPTY)));
|
||||
return createCodecMetadataPane(content);
|
||||
}
|
||||
|
||||
final var fields = details.codecConfigurationFieldsByCodec().getOrDefault(draft.selectedCodec(), java.util.List.of());
|
||||
if (fields.isEmpty()) {
|
||||
content.getChildren().add(AssetDetailsUiSupport.createSectionMessage(
|
||||
i18n.text(I18n.ASSETS_DETAILS_CODEC_CONFIGURATION_EMPTY)));
|
||||
return createCodecMetadataPane(content);
|
||||
}
|
||||
|
||||
for (AssetConfigurationField field : fields) {
|
||||
content.getChildren().add(createCodecFieldControl(field, draft, editing));
|
||||
}
|
||||
return createCodecMetadataPane(content);
|
||||
}
|
||||
|
||||
private Node createCodecFieldControl(AssetConfigurationField field, CodecDraft draft, boolean editing) {
|
||||
final Node valueNode = switch (field.fieldType()) {
|
||||
case "BOOLEAN" -> createBooleanField(field, draft, editing);
|
||||
case "ENUM" -> createEnumField(field, draft, editing);
|
||||
case "INTEGER", "TEXT" -> createTextField(field, draft, editing);
|
||||
default -> createTextField(field, draft, editing);
|
||||
};
|
||||
if (valueNode instanceof TextField textField) {
|
||||
textField.setPromptText(field.label());
|
||||
}
|
||||
if (valueNode instanceof ComboBox<?> comboBox) {
|
||||
comboBox.setPromptText(field.label());
|
||||
}
|
||||
return valueNode;
|
||||
}
|
||||
|
||||
private Node createBooleanField(AssetConfigurationField field, CodecDraft draft, boolean editing) {
|
||||
final CheckBox checkBox = new CheckBox(field.label());
|
||||
checkBox.getStyleClass().add("assets-details-readonly-check");
|
||||
checkBox.setSelected(draft.codecFieldValue(draft.selectedCodec(), field.key(), field.value()).equalsIgnoreCase("true"));
|
||||
if (editing) {
|
||||
checkBox.selectedProperty().addListener((ignored, oldValue, newValue) -> {
|
||||
if (!Objects.equals(oldValue, newValue)) {
|
||||
formSession().updateDraft(current -> current.withCodecFieldValue(current.selectedCodec(), field.key(), Boolean.toString(newValue)));
|
||||
updateActionBarState();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
configureReadOnlyControl(checkBox);
|
||||
}
|
||||
return checkBox;
|
||||
}
|
||||
|
||||
private Node createEnumField(AssetConfigurationField field, CodecDraft draft, boolean editing) {
|
||||
final ComboBox<String> comboBox = new ComboBox<>(FXCollections.observableArrayList(field.options()));
|
||||
comboBox.getStyleClass().add("assets-details-combo");
|
||||
comboBox.setMaxWidth(Double.MAX_VALUE);
|
||||
comboBox.getSelectionModel().select(draft.codecFieldValue(draft.selectedCodec(), field.key(), field.value()));
|
||||
if (editing) {
|
||||
comboBox.valueProperty().addListener((ignored, oldValue, newValue) -> {
|
||||
if (newValue != null && !Objects.equals(oldValue, newValue)) {
|
||||
formSession().updateDraft(current -> current.withCodecFieldValue(current.selectedCodec(), field.key(), newValue));
|
||||
updateActionBarState();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
configureReadOnlyControl(comboBox);
|
||||
}
|
||||
return comboBox;
|
||||
}
|
||||
|
||||
private Node createTextField(AssetConfigurationField field, CodecDraft draft, boolean editing) {
|
||||
final TextField textField = new TextField(draft.codecFieldValue(draft.selectedCodec(), field.key(), field.value()));
|
||||
textField.getStyleClass().add("assets-workspace-search");
|
||||
textField.setMaxWidth(Double.MAX_VALUE);
|
||||
if (editing) {
|
||||
textField.textProperty().addListener((ignored, oldValue, newValue) -> {
|
||||
if (!Objects.equals(oldValue, newValue)) {
|
||||
formSession().updateDraft(current -> current.withCodecFieldValue(current.selectedCodec(), field.key(), Objects.requireNonNullElse(newValue, "")));
|
||||
updateActionBarState();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
textField.setEditable(false);
|
||||
configureReadOnlyControl(textField);
|
||||
}
|
||||
return textField;
|
||||
}
|
||||
}
|
||||
|
||||
private Node createLabeledFieldRow(String label, Node valueNode) {
|
||||
return AssetDetailsUiSupport.createKeyValueRow(label, valueNode);
|
||||
}
|
||||
|
||||
private Node createCodecMetadataPane(VBox content) {
|
||||
final ScrollPane scrollPane = new ScrollPane(content);
|
||||
scrollPane.setFitToWidth(true);
|
||||
scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
|
||||
scrollPane.getStyleClass().add("assets-details-contract-metadata-scroll");
|
||||
final VBox container = new VBox(scrollPane);
|
||||
VBox.setVgrow(scrollPane, Priority.ALWAYS);
|
||||
return container;
|
||||
}
|
||||
|
||||
private void configureReadOnlyControl(Control control) {
|
||||
control.setMouseTransparent(true);
|
||||
control.setFocusTraversable(false);
|
||||
}
|
||||
|
||||
private Map<String, String> currentMetadataFieldValues(AssetWorkspaceAssetDetails details) {
|
||||
final Map<String, String> values = new LinkedHashMap<>();
|
||||
details.metadataFields().forEach(field -> values.put(field.key(), field.value()));
|
||||
return Map.copyOf(values);
|
||||
}
|
||||
|
||||
private Map<String, String> currentCodecFieldValues(AssetWorkspaceAssetDetails details) {
|
||||
final Map<String, String> values = new LinkedHashMap<>();
|
||||
details.codecConfigurationFieldsByCodec().forEach((codec, fields) ->
|
||||
fields.forEach(field -> values.put(codec + ":" + field.key(), field.value())));
|
||||
return Map.copyOf(values);
|
||||
}
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
package p.studio.ui.javafx.workspaces.assets.details.contract;
|
||||
|
||||
import p.studio.api.assets.AssetReference;
|
||||
import p.studio.api.assets.workspace.AssetWorkspaceAssetDetails;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public record CodecDraft(
|
||||
AssetReference assetReference,
|
||||
String selectedCodec,
|
||||
Map<String, String> codecFieldValues) {
|
||||
|
||||
public CodecDraft {
|
||||
Objects.requireNonNull(assetReference, "assetReference");
|
||||
selectedCodec = Objects.requireNonNullElse(selectedCodec, "UNKNOWN");
|
||||
codecFieldValues = Map.copyOf(Objects.requireNonNull(codecFieldValues, "codecFieldValues"));
|
||||
}
|
||||
|
||||
public static CodecDraft fromDetails(AssetWorkspaceAssetDetails details) {
|
||||
final Map<String, String> codecFieldValues = new LinkedHashMap<>();
|
||||
details.codecConfigurationFieldsByCodec().forEach((codec, fields) ->
|
||||
fields.forEach(field -> codecFieldValues.put(keyOf(codec, field.key()), field.value())));
|
||||
return new CodecDraft(
|
||||
details.summary().assetReference(),
|
||||
details.outputCodec(),
|
||||
codecFieldValues);
|
||||
}
|
||||
|
||||
public CodecDraft withSelectedCodec(String selectedCodec) {
|
||||
return new CodecDraft(assetReference, selectedCodec, codecFieldValues);
|
||||
}
|
||||
|
||||
public CodecDraft withCodecFieldValue(String codec, String fieldKey, String value) {
|
||||
final Map<String, String> nextValues = new LinkedHashMap<>(codecFieldValues);
|
||||
nextValues.put(keyOf(codec, fieldKey), Objects.requireNonNullElse(value, ""));
|
||||
return new CodecDraft(assetReference, selectedCodec, nextValues);
|
||||
}
|
||||
|
||||
public String codecFieldValue(String codec, String fieldKey, String fallback) {
|
||||
return codecFieldValues.getOrDefault(keyOf(codec, fieldKey), Objects.requireNonNullElse(fallback, ""));
|
||||
}
|
||||
|
||||
private static String keyOf(String codec, String fieldKey) {
|
||||
return codec + ":" + fieldKey;
|
||||
}
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
package p.studio.ui.javafx.workspaces.assets.details.contract;
|
||||
|
||||
import p.studio.api.assets.AssetReference;
|
||||
import p.studio.api.assets.workspace.AssetWorkspaceAssetDetails;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public record RuntimeContractDraft(
|
||||
AssetReference assetReference,
|
||||
boolean preload,
|
||||
String bank,
|
||||
Map<String, String> metadataFieldValues) {
|
||||
|
||||
public RuntimeContractDraft {
|
||||
Objects.requireNonNull(assetReference, "assetReference");
|
||||
bank = Objects.requireNonNullElse(bank, "UNKNOWN");
|
||||
metadataFieldValues = Map.copyOf(Objects.requireNonNull(metadataFieldValues, "metadataFieldValues"));
|
||||
}
|
||||
|
||||
public static RuntimeContractDraft fromDetails(AssetWorkspaceAssetDetails details) {
|
||||
final Map<String, String> metadataFieldValues = new LinkedHashMap<>();
|
||||
details.metadataFields().forEach(field -> metadataFieldValues.put(field.key(), field.value()));
|
||||
return new RuntimeContractDraft(
|
||||
details.summary().assetReference(),
|
||||
details.summary().preload(),
|
||||
details.outputFormat(),
|
||||
metadataFieldValues);
|
||||
}
|
||||
|
||||
public RuntimeContractDraft withPreload(boolean preload) {
|
||||
return new RuntimeContractDraft(assetReference, preload, bank, metadataFieldValues);
|
||||
}
|
||||
|
||||
public RuntimeContractDraft withMetadataFieldValue(String fieldKey, String value) {
|
||||
final Map<String, String> nextValues = new LinkedHashMap<>(metadataFieldValues);
|
||||
nextValues.put(fieldKey, Objects.requireNonNullElse(value, ""));
|
||||
return new RuntimeContractDraft(assetReference, preload, bank, nextValues);
|
||||
}
|
||||
|
||||
public String metadataFieldValue(String fieldKey, String fallback) {
|
||||
return metadataFieldValues.getOrDefault(fieldKey, Objects.requireNonNullElse(fallback, ""));
|
||||
}
|
||||
}
|
||||
+368
@@ -0,0 +1,368 @@
|
||||
package p.studio.ui.javafx.workspaces.assets.details.palette;
|
||||
|
||||
import p.studio.api.assets.workspace.*;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.Priority;
|
||||
import javafx.scene.layout.VBox;
|
||||
import p.studio.api.assets.AssetCommands;
|
||||
import p.studio.ui.javafx.controls.forms.StudioFormEditScopeChangedEvent;
|
||||
import p.studio.ui.javafx.controls.forms.StudioFormMode;
|
||||
import p.studio.ui.javafx.controls.forms.StudioFormSection;
|
||||
import p.studio.ui.javafx.events.StudioPackerOperationEvent;
|
||||
import p.studio.ui.javafx.events.StudioPackerOperationKind;
|
||||
import p.studio.ui.javafx.events.StudioWorkspaceEventBus;
|
||||
import p.studio.api.project.ProjectReference;
|
||||
import p.studio.ui.javafx.utilities.ThemeService;
|
||||
import p.studio.ui.javafx.utilities.i18n.I18n;
|
||||
import p.studio.ui.javafx.utilities.i18n.I18nService;
|
||||
import p.studio.ui.javafx.workspaces.assets.messages.AssetWorkspaceDetailsViewState;
|
||||
import p.studio.ui.javafx.workspaces.assets.messages.events.StudioAssetLogEvent;
|
||||
import p.studio.ui.javafx.workspaces.assets.messages.events.StudioAssetsDetailsViewStateChangedEvent;
|
||||
import p.studio.ui.javafx.workspaces.assets.messages.events.StudioAssetsWorkspaceSelectionRequestedEvent;
|
||||
import p.studio.ui.javafx.workspaces.assets.messages.events.StudioGlyphMaterialMetadataChangedEvent;
|
||||
import p.studio.api.assets.metadata.AssetStudioGlyphMaterialMetadata;
|
||||
import p.studio.api.assets.metadata.AssetMetadataService;
|
||||
import p.studio.api.assets.schema.AssetColorSchemaFactory;
|
||||
import p.studio.api.assets.palette.AssetPaletteSession;
|
||||
import p.studio.api.assets.palette.AssetPaletteState;
|
||||
import p.studio.ui.javafx.workspaces.framework.StudioSubscriptionBag;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
public final class AssetDetailsPaletteOverhaulingControl extends StudioFormSection {
|
||||
private static final String SECTION_ID = "asset-details.palette-overhauling";
|
||||
|
||||
private final ProjectReference projectReference;
|
||||
private final StudioWorkspaceEventBus workspaceBus;
|
||||
private final StudioSubscriptionBag subscriptions = new StudioSubscriptionBag();
|
||||
private final AssetPaletteSession coordinator;
|
||||
private final AssetMetadataService metadataService;
|
||||
private final AssetDetailsPaletteOverhaulingDualListView dualListView;
|
||||
private final AssetDetailsPaletteOverhaulingPreviewPane previewPane;
|
||||
private final VBox paletteActions = new VBox(6);
|
||||
private final HBox listWithActions;
|
||||
private final HBox body;
|
||||
private final VBox content;
|
||||
|
||||
private AssetWorkspaceDetailsViewState viewState;
|
||||
private final java.util.concurrent.Executor executor;
|
||||
private final I18nService i18n;
|
||||
private final ThemeService theme;
|
||||
private final AssetCommands assetCommands;
|
||||
|
||||
public AssetDetailsPaletteOverhaulingControl(ProjectReference projectReference, StudioWorkspaceEventBus workspaceBus,
|
||||
I18nService i18n, java.util.concurrent.Executor executor, ThemeService theme,
|
||||
AssetCommands assetCommands, AssetMetadataService metadataService,
|
||||
AssetColorSchemaFactory colorSchemaFactory) {
|
||||
super(i18n);
|
||||
this.i18n = Objects.requireNonNull(i18n, "i18n");
|
||||
this.theme = Objects.requireNonNull(theme, "theme");
|
||||
this.assetCommands = Objects.requireNonNull(assetCommands, "assetCommands");
|
||||
this.metadataService = Objects.requireNonNull(metadataService, "metadataService");
|
||||
this.coordinator = Objects.requireNonNull(colorSchemaFactory, "colorSchemaFactory").createPaletteSession();
|
||||
this.executor = Objects.requireNonNull(executor, "executor");
|
||||
this.projectReference = Objects.requireNonNull(projectReference, "projectReference");
|
||||
this.workspaceBus = Objects.requireNonNull(workspaceBus, "workspaceBus");
|
||||
this.dualListView = new AssetDetailsPaletteOverhaulingDualListView(i18n);
|
||||
this.previewPane = new AssetDetailsPaletteOverhaulingPreviewPane(i18n);
|
||||
this.listWithActions = new HBox(8, paletteActions, dualListView);
|
||||
this.body = new HBox(16, listWithActions, previewPane);
|
||||
this.content = new VBox(12, body);
|
||||
body.getStyleClass().add("assets-details-palette-overhauling-body");
|
||||
paletteActions.getStyleClass().add("assets-details-palette-overhauling-toolbar");
|
||||
listWithActions.getStyleClass().add("assets-details-list-with-actions");
|
||||
content.setFillWidth(true);
|
||||
HBox.setHgrow(listWithActions, Priority.ALWAYS);
|
||||
HBox.setHgrow(previewPane, Priority.ALWAYS);
|
||||
HBox.setHgrow(dualListView, Priority.ALWAYS);
|
||||
dualListView.setMaxWidth(Double.MAX_VALUE);
|
||||
previewPane.setMaxWidth(Double.MAX_VALUE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void subscribe() {
|
||||
subscriptions.add(workspaceBus.subscribe(StudioAssetsDetailsViewStateChangedEvent.class, event -> {
|
||||
viewState = event.viewState();
|
||||
coordinator.replaceDetails(viewState == null ? null : viewState.selectedAssetDetails());
|
||||
if (viewState == null || viewState.selectedAssetReference() == null) {
|
||||
publishEditScope(workspaceBus, currentScopeKey(), null);
|
||||
}
|
||||
renderSection();
|
||||
}));
|
||||
subscriptions.add(workspaceBus.subscribe(StudioFormEditScopeChangedEvent.class,
|
||||
event -> handleEditScopeChanged(event, currentScopeKey())));
|
||||
subscriptions.add(workspaceBus.subscribe(StudioGlyphMaterialMetadataChangedEvent.class, event -> {
|
||||
if (viewState == null || !Objects.equals(viewState.selectedAssetReference(), event.assetReference())) {
|
||||
return;
|
||||
}
|
||||
coordinator.replaceMaterialMetadata(event.metadata());
|
||||
renderSection();
|
||||
}));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unsubscribe() {
|
||||
subscriptions.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderSection() {
|
||||
if (viewState == null || viewState.selectedAssetDetails() == null || !coordinator.ready()) {
|
||||
clearRenderedSection();
|
||||
return;
|
||||
}
|
||||
|
||||
final AssetPaletteState viewModel = coordinator.state();
|
||||
dualListView.setLeftItems(viewModel.availableFiles());
|
||||
dualListView.setRightItems(viewModel.selectedFiles());
|
||||
dualListView.setInteractionEnabled(viewModel.editing());
|
||||
dualListView.setMoveToRightAllowed(viewModel.selectedFiles().size() < 64);
|
||||
dualListView.setOnMoveToRight(items -> {
|
||||
coordinator.moveToSelected(items);
|
||||
rerenderPreservingScrollPosition();
|
||||
});
|
||||
dualListView.setOnMoveToLeft(items -> {
|
||||
coordinator.moveToAvailable(items);
|
||||
rerenderPreservingScrollPosition();
|
||||
});
|
||||
dualListView.setOnMoveUp(index -> { });
|
||||
dualListView.setOnMoveDown(index -> { });
|
||||
dualListView.setOnLeftSelectionChanged(item -> {
|
||||
if (item != null) {
|
||||
coordinator.selectPreviewPalette(item);
|
||||
previewPane.render(
|
||||
coordinator.state().previewTileFiles(),
|
||||
coordinator.state().previewTileFile(),
|
||||
coordinator.state().previewPaletteFile(),
|
||||
coordinator.state().renderableFileCount());
|
||||
}
|
||||
});
|
||||
dualListView.setOnRightSelectionChanged(item -> {
|
||||
if (item != null) {
|
||||
coordinator.selectPreviewPalette(item);
|
||||
previewPane.render(
|
||||
coordinator.state().previewTileFiles(),
|
||||
coordinator.state().previewTileFile(),
|
||||
coordinator.state().previewPaletteFile(),
|
||||
coordinator.state().renderableFileCount());
|
||||
}
|
||||
});
|
||||
dualListView.setOnLeftItemActivated(item -> openPaletteWizard(item));
|
||||
dualListView.setOnRightItemActivated(item -> openPaletteWizard(item));
|
||||
if (viewModel.previewPaletteFile() != null) {
|
||||
if (viewModel.selectedFiles().contains(viewModel.previewPaletteFile())) {
|
||||
dualListView.selectRightItem(viewModel.previewPaletteFile());
|
||||
} else {
|
||||
dualListView.selectLeftItem(viewModel.previewPaletteFile());
|
||||
}
|
||||
}
|
||||
|
||||
previewPane.setOnPreviewTileChanged(file -> {
|
||||
if (file != null) {
|
||||
coordinator.selectPreviewTile(file);
|
||||
previewPane.render(
|
||||
coordinator.state().previewTileFiles(),
|
||||
coordinator.state().previewTileFile(),
|
||||
coordinator.state().previewPaletteFile(),
|
||||
coordinator.state().renderableFileCount());
|
||||
}
|
||||
});
|
||||
previewPane.render(
|
||||
viewModel.previewTileFiles(),
|
||||
viewModel.previewTileFile(),
|
||||
viewModel.previewPaletteFile(),
|
||||
viewModel.renderableFileCount());
|
||||
|
||||
final Button addButton = new Button("+");
|
||||
addButton.getStyleClass().addAll("studio-button", "studio-button-secondary", "assets-details-mini-action-button");
|
||||
addButton.setDisable(!viewModel.editing() || viewState == null || viewState.selectedAssetDetails() == null);
|
||||
addButton.setOnAction(ignored -> openPaletteWizard(null));
|
||||
|
||||
final Button removeButton = new Button("-");
|
||||
removeButton.getStyleClass().addAll("studio-button", "studio-button-secondary", "assets-details-mini-action-button");
|
||||
removeButton.setDisable(!viewModel.editing() || viewModel.previewPaletteFile() == null);
|
||||
removeButton.setOnAction(ignored -> removePalette(coordinator.state().previewPaletteFile()));
|
||||
paletteActions.getChildren().setAll(addButton, removeButton);
|
||||
|
||||
renderFormSection(content);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String sectionTitle() {
|
||||
return i18n.text(I18n.ASSETS_SECTION_PALETTE_OVERHAULING);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected StudioFormMode formMode() {
|
||||
return coordinator.ready() && coordinator.state().editing() ? StudioFormMode.EDITING : StudioFormMode.READ_ONLY;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isDirty() {
|
||||
return coordinator.ready() && coordinator.state().dirty();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void beginEdit() {
|
||||
coordinator.beginEdit();
|
||||
publishEditScope(workspaceBus, currentScopeKey(), SECTION_ID);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void apply() {
|
||||
if (viewState == null || viewState.selectedAssetReference() == null || !coordinator.ready()) {
|
||||
return;
|
||||
}
|
||||
final var selectedPalettes = coordinator.state().selectedFiles().stream()
|
||||
.map(file -> palettePayload(file.metadata()))
|
||||
.filter(Objects::nonNull)
|
||||
.toList();
|
||||
if (selectedPalettes.isEmpty()) {
|
||||
workspaceBus.publish(new StudioAssetLogEvent("palette-overhauling", "Apply failed: no palette was selected."));
|
||||
workspaceBus.publish(new StudioPackerOperationEvent(
|
||||
UUID.randomUUID().toString(),
|
||||
StudioPackerOperationKind.ACTION_FAILED,
|
||||
"Palette overhauling apply failed: no palette was selected.",
|
||||
null,
|
||||
true));
|
||||
return;
|
||||
}
|
||||
|
||||
final var assetReference = viewState.selectedAssetReference();
|
||||
executor.execute(() -> {
|
||||
try {
|
||||
final var response = assetCommands.applyPaletteOverhauling(projectReference, assetReference, selectedPalettes);
|
||||
Platform.runLater(() -> {
|
||||
if (response.success()) {
|
||||
coordinator.apply();
|
||||
publishEditScope(workspaceBus, currentScopeKey(), null);
|
||||
renderSection();
|
||||
workspaceBus.publish(new StudioAssetsWorkspaceSelectionRequestedEvent(assetReference, true));
|
||||
} else {
|
||||
workspaceBus.publish(new StudioAssetLogEvent("palette-overhauling",
|
||||
"Apply failed: " + Objects.requireNonNullElse(response.errorMessage(), "unknown error")));
|
||||
}
|
||||
});
|
||||
} catch (Exception exception) {
|
||||
Platform.runLater(() -> workspaceBus.publish(new StudioAssetLogEvent(
|
||||
"palette-overhauling",
|
||||
"Apply failed due to an unexpected error.")));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void reset() {
|
||||
coordinator.reset();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void cancel() {
|
||||
coordinator.cancel();
|
||||
publishEditScope(workspaceBus, currentScopeKey(), null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String sectionStyleClass() {
|
||||
return "assets-details-palette-overhauling-section";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String formSectionId() {
|
||||
return SECTION_ID;
|
||||
}
|
||||
|
||||
private String currentScopeKey() {
|
||||
return viewState == null || viewState.selectedAssetReference() == null
|
||||
? null
|
||||
: "asset-details:" + viewState.selectedAssetReference();
|
||||
}
|
||||
|
||||
private void openPaletteWizard(p.studio.api.assets.workspace.AssetWorkspaceBankCompositionFile paletteFile) {
|
||||
if (getScene() == null || !coordinator.ready() || viewState == null || viewState.selectedAssetDetails() == null) {
|
||||
return;
|
||||
}
|
||||
if (coordinator.paletteIsOriginal(paletteFile)) {
|
||||
return;
|
||||
}
|
||||
final var result = AssetDetailsPaletteWizardDialog.showAndWait(
|
||||
getScene().getWindow(),
|
||||
coordinator,
|
||||
paletteFile,
|
||||
i18n,
|
||||
theme);
|
||||
result.ifPresent(edit -> executor.execute(() -> {
|
||||
try {
|
||||
final AssetStudioGlyphMaterialMetadata metadata = coordinator.upsertPalette(
|
||||
edit.paletteId(),
|
||||
edit.displayName(),
|
||||
edit.schemaId(),
|
||||
edit.colors());
|
||||
final var writeResult = metadataService.writeGlyphMaterialMetadata(
|
||||
viewState.selectedAssetDetails().summary().assetRoot(), metadata);
|
||||
if (!writeResult.successful()) {
|
||||
Platform.runLater(() -> workspaceBus.publish(new StudioAssetLogEvent(
|
||||
"palette-overhauling",
|
||||
"Unable to save palette: " + writeResult.message())));
|
||||
return;
|
||||
}
|
||||
Platform.runLater(() -> {
|
||||
workspaceBus.publish(new StudioAssetLogEvent("palette-overhauling", "Palette saved: " + edit.paletteId()));
|
||||
workspaceBus.publish(new StudioGlyphMaterialMetadataChangedEvent(viewState.selectedAssetReference(), metadata));
|
||||
});
|
||||
} catch (RuntimeException exception) {
|
||||
Platform.runLater(() -> workspaceBus.publish(new StudioAssetLogEvent(
|
||||
"palette-overhauling",
|
||||
"Unable to save palette.")));
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
private void removePalette(p.studio.api.assets.workspace.AssetWorkspaceBankCompositionFile paletteFile) {
|
||||
if (paletteFile == null || viewState == null || viewState.selectedAssetDetails() == null || viewState.selectedAssetReference() == null) {
|
||||
return;
|
||||
}
|
||||
if (coordinator.paletteIsOriginal(paletteFile)) {
|
||||
workspaceBus.publish(new StudioAssetLogEvent(
|
||||
"palette-overhauling",
|
||||
"Original schema palettes cannot be removed."));
|
||||
return;
|
||||
}
|
||||
final Object paletteIdValue = paletteFile.metadata().get("paletteId");
|
||||
if (!(paletteIdValue instanceof String paletteId) || paletteId.isBlank()) {
|
||||
return;
|
||||
}
|
||||
executor.execute(() -> {
|
||||
try {
|
||||
final AssetStudioGlyphMaterialMetadata metadata = coordinator.removePalette(paletteId);
|
||||
final var writeResult = metadataService.writeGlyphMaterialMetadata(
|
||||
viewState.selectedAssetDetails().summary().assetRoot(), metadata);
|
||||
if (!writeResult.successful()) {
|
||||
Platform.runLater(() -> workspaceBus.publish(new StudioAssetLogEvent(
|
||||
"palette-overhauling",
|
||||
"Unable to remove palette: " + writeResult.message())));
|
||||
return;
|
||||
}
|
||||
Platform.runLater(() -> {
|
||||
workspaceBus.publish(new StudioAssetLogEvent("palette-overhauling", "Palette removed: " + paletteId));
|
||||
workspaceBus.publish(new StudioGlyphMaterialMetadataChangedEvent(viewState.selectedAssetReference(), metadata));
|
||||
});
|
||||
} catch (Exception exception) {
|
||||
Platform.runLater(() -> workspaceBus.publish(new StudioAssetLogEvent(
|
||||
"palette-overhauling",
|
||||
"Unable to remove palette.")));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static Map<String, Object> palettePayload(Map<String, Object> metadata) {
|
||||
final Object palette = metadata.get("palette");
|
||||
return palette instanceof Map<?, ?> paletteMap ? (Map<String, Object>) paletteMap : null;
|
||||
}
|
||||
}
|
||||
+105
@@ -0,0 +1,105 @@
|
||||
package p.studio.ui.javafx.workspaces.assets.details.palette;
|
||||
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.Region;
|
||||
import javafx.scene.layout.VBox;
|
||||
import p.studio.ui.javafx.controls.banks.StudioDualListView;
|
||||
import p.studio.ui.javafx.utilities.i18n.I18n;
|
||||
import p.studio.ui.javafx.utilities.i18n.I18nService;
|
||||
import p.studio.api.assets.workspace.AssetWorkspaceBankCompositionFile;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public final class AssetDetailsPaletteOverhaulingDualListView extends StudioDualListView<AssetWorkspaceBankCompositionFile> {
|
||||
public AssetDetailsPaletteOverhaulingDualListView(I18nService i18n) {
|
||||
setLeftTitle(i18n.text(I18n.ASSETS_PALETTE_OVERHAULING_AVAILABLE));
|
||||
setRightTitle(i18n.text(I18n.ASSETS_PALETTE_OVERHAULING_SELECTED));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String itemText(AssetWorkspaceBankCompositionFile item) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Node itemGraphic(AssetWorkspaceBankCompositionFile item) {
|
||||
final Label hashLabel = new Label(item.displayName());
|
||||
hashLabel.getStyleClass().add("assets-details-palette-hash");
|
||||
final HBox strip = createPaletteStrip(item);
|
||||
final HBox top = new HBox(8, hashLabel, strip);
|
||||
top.getStyleClass().add("assets-details-palette-item");
|
||||
final Object invalidReason = item.metadata().get("invalidReason");
|
||||
if (!(invalidReason instanceof String reason) || reason.isBlank()) {
|
||||
return top;
|
||||
}
|
||||
final Label invalidLabel = new Label(reason);
|
||||
invalidLabel.getStyleClass().add("assets-details-palette-invalid");
|
||||
final VBox root = new VBox(4, top, invalidLabel);
|
||||
return root;
|
||||
}
|
||||
|
||||
private HBox createPaletteStrip(AssetWorkspaceBankCompositionFile item) {
|
||||
final HBox strip = new HBox(0);
|
||||
strip.getStyleClass().add("assets-details-palette-strip");
|
||||
final List<Integer> colors = paletteDisplayColors(item.metadata());
|
||||
for (int index = 0; index < 16; index++) {
|
||||
final Region swatch = new Region();
|
||||
swatch.getStyleClass().add("assets-details-palette-swatch");
|
||||
swatch.setMinSize(12.0d, 18.0d);
|
||||
swatch.setPrefSize(12.0d, 18.0d);
|
||||
swatch.setMaxSize(12.0d, 18.0d);
|
||||
swatch.setStyle("-fx-background-color: " + cssColor(colorAt(colors, index)) + ";");
|
||||
strip.getChildren().add(swatch);
|
||||
}
|
||||
return strip;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private List<Integer> paletteDisplayColors(Map<String, Object> metadata) {
|
||||
final Object paletteValue = metadata.get("palette");
|
||||
if (!(paletteValue instanceof Map<?, ?> palette)) {
|
||||
return List.of();
|
||||
}
|
||||
final Object convertedValue = palette.get("rgba8888");
|
||||
if (convertedValue instanceof List<?> converted) {
|
||||
return ((List<Integer>) converted).stream()
|
||||
.map(this::rgba8888ToArgb8888)
|
||||
.toList();
|
||||
}
|
||||
return List.of();
|
||||
}
|
||||
|
||||
private int colorAt(List<Integer> colors, int index) {
|
||||
if (index < 0 || index >= colors.size()) {
|
||||
return 0x00000000;
|
||||
}
|
||||
final Integer color = colors.get(index);
|
||||
return color == null ? 0x00000000 : color;
|
||||
}
|
||||
|
||||
private String cssColor(int argb) {
|
||||
final int alpha = (argb >>> 24) & 0xFF;
|
||||
if (alpha == 0) {
|
||||
return "transparent";
|
||||
}
|
||||
final int red = (argb >>> 16) & 0xFF;
|
||||
final int green = (argb >>> 8) & 0xFF;
|
||||
final int blue = argb & 0xFF;
|
||||
return String.format("#%02X%02X%02X", red, green, blue);
|
||||
}
|
||||
|
||||
private int rgba8888ToArgb8888(Integer rgba8888) {
|
||||
if (rgba8888 == null) {
|
||||
return 0x00000000;
|
||||
}
|
||||
final int value = rgba8888;
|
||||
final int red = (value >>> 24) & 0xFF;
|
||||
final int green = (value >>> 16) & 0xFF;
|
||||
final int blue = (value >>> 8) & 0xFF;
|
||||
final int alpha = value & 0xFF;
|
||||
return (alpha << 24) | (red << 16) | (green << 8) | blue;
|
||||
}
|
||||
}
|
||||
+324
@@ -0,0 +1,324 @@
|
||||
package p.studio.ui.javafx.workspaces.assets.details.palette;
|
||||
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.canvas.Canvas;
|
||||
import javafx.scene.canvas.GraphicsContext;
|
||||
import javafx.scene.control.ComboBox;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.Priority;
|
||||
import javafx.scene.layout.Region;
|
||||
import javafx.scene.layout.VBox;
|
||||
import p.studio.ui.javafx.utilities.i18n.I18n;
|
||||
import p.studio.ui.javafx.utilities.i18n.I18nService;
|
||||
import p.studio.api.assets.workspace.AssetWorkspaceBankCompositionFile;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public final class AssetDetailsPaletteOverhaulingPreviewPane extends VBox {
|
||||
private static final double PREVIEW_SIZE = 192.0d;
|
||||
private static final double PREVIEW_FRAME_SIZE = PREVIEW_SIZE + 16.0d;
|
||||
|
||||
private final Label selectorLabel;
|
||||
private final ComboBox<AssetWorkspaceBankCompositionFile> tileSelector = new ComboBox<>();
|
||||
private final Canvas tileCanvas = new Canvas(PREVIEW_SIZE, PREVIEW_SIZE);
|
||||
private final Label emptyLabel;
|
||||
private final Label paletteLabel;
|
||||
private final HBox paletteStrip = new HBox(0);
|
||||
|
||||
private Consumer<AssetWorkspaceBankCompositionFile> onPreviewTileChanged = ignored -> { };
|
||||
private boolean suppressSelectorEvents;
|
||||
|
||||
public AssetDetailsPaletteOverhaulingPreviewPane(I18nService i18n) {
|
||||
selectorLabel = new Label(i18n.text(I18n.ASSETS_PALETTE_OVERHAULING_TILE_SELECTOR));
|
||||
emptyLabel = new Label(i18n.text(I18n.ASSETS_PALETTE_OVERHAULING_PREVIEW_EMPTY));
|
||||
paletteLabel = new Label(i18n.text(I18n.ASSETS_PALETTE_OVERHAULING_APPLIED_PALETTE));
|
||||
getStyleClass().add("assets-details-palette-preview");
|
||||
setSpacing(10);
|
||||
setAlignment(Pos.TOP_CENTER);
|
||||
setMinWidth(PREVIEW_FRAME_SIZE);
|
||||
setPrefWidth(PREVIEW_FRAME_SIZE);
|
||||
setMaxWidth(PREVIEW_FRAME_SIZE);
|
||||
|
||||
selectorLabel.getStyleClass().add("assets-details-palette-preview-label");
|
||||
paletteLabel.getStyleClass().add("assets-details-palette-preview-label");
|
||||
selectorLabel.setMaxWidth(Double.MAX_VALUE);
|
||||
selectorLabel.setAlignment(Pos.CENTER_LEFT);
|
||||
paletteLabel.setMaxWidth(Double.MAX_VALUE);
|
||||
paletteLabel.setAlignment(Pos.CENTER);
|
||||
|
||||
tileSelector.setMinWidth(PREVIEW_FRAME_SIZE);
|
||||
tileSelector.setPrefWidth(PREVIEW_FRAME_SIZE);
|
||||
tileSelector.setMaxWidth(PREVIEW_FRAME_SIZE);
|
||||
tileSelector.setCellFactory(ignored -> new javafx.scene.control.ListCell<>() {
|
||||
@Override
|
||||
protected void updateItem(AssetWorkspaceBankCompositionFile item, boolean empty) {
|
||||
super.updateItem(item, empty);
|
||||
setText(empty || item == null ? null : item.displayName());
|
||||
}
|
||||
});
|
||||
tileSelector.setButtonCell(new javafx.scene.control.ListCell<>() {
|
||||
@Override
|
||||
protected void updateItem(AssetWorkspaceBankCompositionFile item, boolean empty) {
|
||||
super.updateItem(item, empty);
|
||||
setText(empty || item == null ? null : item.displayName());
|
||||
}
|
||||
});
|
||||
tileSelector.valueProperty().addListener((ignored, oldValue, newValue) -> {
|
||||
if (!suppressSelectorEvents && newValue != null) {
|
||||
onPreviewTileChanged.accept(newValue);
|
||||
}
|
||||
});
|
||||
|
||||
final VBox previewSurface = new VBox(emptyLabel, tileCanvas);
|
||||
previewSurface.getStyleClass().add("assets-details-palette-preview-surface");
|
||||
previewSurface.setAlignment(Pos.CENTER);
|
||||
previewSurface.setMinWidth(PREVIEW_FRAME_SIZE);
|
||||
previewSurface.setPrefWidth(PREVIEW_FRAME_SIZE);
|
||||
previewSurface.setMaxWidth(PREVIEW_FRAME_SIZE);
|
||||
previewSurface.setMinHeight(PREVIEW_FRAME_SIZE);
|
||||
previewSurface.setPrefHeight(PREVIEW_FRAME_SIZE);
|
||||
previewSurface.setMaxHeight(PREVIEW_FRAME_SIZE);
|
||||
VBox.setVgrow(previewSurface, Priority.ALWAYS);
|
||||
emptyLabel.getStyleClass().add("assets-details-section-message");
|
||||
|
||||
paletteStrip.getStyleClass().add("assets-details-palette-preview-strip");
|
||||
paletteStrip.setAlignment(Pos.CENTER);
|
||||
paletteStrip.setMinWidth(PREVIEW_FRAME_SIZE);
|
||||
paletteStrip.setPrefWidth(PREVIEW_FRAME_SIZE);
|
||||
paletteStrip.setMaxWidth(PREVIEW_FRAME_SIZE);
|
||||
for (int index = 0; index < 16; index++) {
|
||||
final Region swatch = new Region();
|
||||
swatch.getStyleClass().add("assets-details-palette-preview-swatch");
|
||||
swatch.setMinSize(16.0d, 26.0d);
|
||||
swatch.setPrefSize(16.0d, 26.0d);
|
||||
swatch.setMaxSize(16.0d, 26.0d);
|
||||
paletteStrip.getChildren().add(swatch);
|
||||
}
|
||||
|
||||
getChildren().addAll(selectorLabel, tileSelector, previewSurface, paletteLabel, paletteStrip);
|
||||
}
|
||||
|
||||
public void setOnPreviewTileChanged(Consumer<AssetWorkspaceBankCompositionFile> onPreviewTileChanged) {
|
||||
this.onPreviewTileChanged = Objects.requireNonNull(onPreviewTileChanged, "onPreviewTileChanged");
|
||||
}
|
||||
|
||||
public void render(
|
||||
List<AssetWorkspaceBankCompositionFile> previewFiles,
|
||||
AssetWorkspaceBankCompositionFile previewTileFile,
|
||||
AssetWorkspaceBankCompositionFile previewPaletteFile,
|
||||
int renderableFileCount) {
|
||||
suppressSelectorEvents = true;
|
||||
tileSelector.setItems(FXCollections.observableArrayList(previewFiles));
|
||||
tileSelector.setValue(previewTileFile);
|
||||
suppressSelectorEvents = false;
|
||||
|
||||
final boolean renderable = previewTileFile != null && previewPaletteFile != null;
|
||||
tileCanvas.setVisible(renderable);
|
||||
tileCanvas.setManaged(renderable);
|
||||
emptyLabel.setVisible(!renderable);
|
||||
emptyLabel.setManaged(!renderable);
|
||||
updatePaletteStrip(previewPaletteFile);
|
||||
if (renderable) {
|
||||
renderTile(tileCanvas.getGraphicsContext2D(), previewTileFile, previewPaletteFile);
|
||||
} else {
|
||||
clearCanvas(tileCanvas.getGraphicsContext2D());
|
||||
}
|
||||
}
|
||||
|
||||
private void updatePaletteStrip(AssetWorkspaceBankCompositionFile previewPaletteFile) {
|
||||
final List<Integer> colors = previewPaletteFile == null ? List.of() : paletteDisplayColors(previewPaletteFile.metadata());
|
||||
for (int index = 0; index < paletteStrip.getChildren().size(); index++) {
|
||||
final Region swatch = (Region) paletteStrip.getChildren().get(index);
|
||||
final int argb = colorAt(colors, index);
|
||||
swatch.setStyle("-fx-background-color: " + cssColor(argb) + ";");
|
||||
}
|
||||
}
|
||||
|
||||
private void renderTile(GraphicsContext graphics, AssetWorkspaceBankCompositionFile tileFile, AssetWorkspaceBankCompositionFile paletteFile) {
|
||||
clearCanvas(graphics);
|
||||
final Map<String, Object> tile = nestedMap(tileFile.metadata(), "tile");
|
||||
if (tile == null) {
|
||||
return;
|
||||
}
|
||||
final Integer width = asInteger(tile.get("width"));
|
||||
final Integer height = asInteger(tile.get("height"));
|
||||
final List<Integer> indices = paletteIndices(tile.get("paletteIndices"));
|
||||
final List<Integer> colors = paletteDisplayColors(paletteFile.metadata());
|
||||
final List<Integer> sourceColors = tileDisplayColors(tileFile.metadata());
|
||||
final Map<String, Integer> schemaIndicesByColor = schemaIndicesByColor(paletteFile.metadata());
|
||||
if (width == null || height == null || width <= 0 || height <= 0 || indices.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final double pixelWidth = PREVIEW_SIZE / width;
|
||||
final double pixelHeight = PREVIEW_SIZE / height;
|
||||
for (int index = 0; index < indices.size(); index++) {
|
||||
final int paletteIndex = schemaPaletteIndex(indices.get(index), sourceColors, schemaIndicesByColor);
|
||||
final int x = index % width;
|
||||
final int y = index / width;
|
||||
graphics.setFill(toFxColor(paletteIndexToArgb(colors, paletteIndex)));
|
||||
graphics.fillRect(x * pixelWidth, y * pixelHeight, pixelWidth, pixelHeight);
|
||||
}
|
||||
}
|
||||
|
||||
private void clearCanvas(GraphicsContext graphics) {
|
||||
final double cell = 12.0d;
|
||||
for (int y = 0; y < PREVIEW_SIZE / cell; y++) {
|
||||
for (int x = 0; x < PREVIEW_SIZE / cell; x++) {
|
||||
final boolean even = ((x + y) % 2) == 0;
|
||||
graphics.setFill(even
|
||||
? javafx.scene.paint.Color.rgb(20, 28, 38)
|
||||
: javafx.scene.paint.Color.rgb(28, 36, 48));
|
||||
graphics.fillRect(x * cell, y * cell, cell, cell);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Map<String, Object> nestedMap(Map<String, Object> metadata, String key) {
|
||||
final Object value = metadata.get(key);
|
||||
if (value instanceof Map<?, ?> nested) {
|
||||
return (Map<String, Object>) nested;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private List<Integer> paletteIndices(Object value) {
|
||||
if (value instanceof List<?> list) {
|
||||
return (List<Integer>) list;
|
||||
}
|
||||
return List.of();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private List<Integer> paletteDisplayColors(Map<String, Object> metadata) {
|
||||
final Map<String, Object> palette = nestedMap(metadata, "palette");
|
||||
if (palette == null) {
|
||||
return List.of();
|
||||
}
|
||||
final Object converted = palette.get("rgba8888");
|
||||
if (converted instanceof List<?> list) {
|
||||
return ((List<Integer>) list).stream()
|
||||
.map(this::rgba8888ToArgb8888)
|
||||
.toList();
|
||||
}
|
||||
return List.of();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private List<Integer> tileDisplayColors(Map<String, Object> metadata) {
|
||||
final Map<String, Object> palette = nestedMap(metadata, "palette");
|
||||
if (palette == null) {
|
||||
return List.of();
|
||||
}
|
||||
final Object rgba = palette.get("rgba8888");
|
||||
if (rgba instanceof List<?> list) {
|
||||
return ((List<Integer>) list).stream()
|
||||
.map(this::rgba8888ToArgb8888)
|
||||
.toList();
|
||||
}
|
||||
final Object original = palette.get("originalArgb8888");
|
||||
if (original instanceof List<?> list) {
|
||||
return (List<Integer>) list;
|
||||
}
|
||||
return List.of();
|
||||
}
|
||||
|
||||
private Map<String, Integer> schemaIndicesByColor(Map<String, Object> metadata) {
|
||||
final Object materialIndices = metadata.get("schemaMaterialIndices");
|
||||
if (!(materialIndices instanceof Map<?, ?> map)) {
|
||||
return Map.of();
|
||||
}
|
||||
final Map<String, Integer> indicesByColor = new java.util.LinkedHashMap<>();
|
||||
for (Map.Entry<?, ?> entry : map.entrySet()) {
|
||||
final Integer index = asInteger(entry.getKey());
|
||||
if (index == null || index < 0 || !(entry.getValue() instanceof String color) || color.isBlank()) {
|
||||
continue;
|
||||
}
|
||||
indicesByColor.put(color.trim().toUpperCase(), index);
|
||||
}
|
||||
return Map.copyOf(indicesByColor);
|
||||
}
|
||||
|
||||
private Integer asInteger(Object value) {
|
||||
if (value instanceof Number number) {
|
||||
return number.intValue();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private int paletteIndexToArgb(List<Integer> colors, int paletteIndex) {
|
||||
if (paletteIndex < 0) {
|
||||
return 0x00000000;
|
||||
}
|
||||
return colorAt(colors, paletteIndex);
|
||||
}
|
||||
|
||||
private int schemaPaletteIndex(int tilePaletteIndex, List<Integer> sourceColors, Map<String, Integer> schemaIndicesByColor) {
|
||||
if (tilePaletteIndex < 0 || sourceColors.isEmpty() || schemaIndicesByColor.isEmpty()) {
|
||||
return tilePaletteIndex;
|
||||
}
|
||||
if (tilePaletteIndex >= sourceColors.size()) {
|
||||
return 0;
|
||||
}
|
||||
return schemaIndicesByColor.getOrDefault(materialColorKey(sourceColors.get(tilePaletteIndex)), 0);
|
||||
}
|
||||
|
||||
private int colorAt(List<Integer> colors, int index) {
|
||||
if (index < 0 || index >= colors.size()) {
|
||||
return 0x00000000;
|
||||
}
|
||||
final Integer color = colors.get(index);
|
||||
return color == null ? 0x00000000 : color;
|
||||
}
|
||||
|
||||
private String cssColor(int argb) {
|
||||
final int alpha = (argb >>> 24) & 0xFF;
|
||||
if (alpha == 0) {
|
||||
return "transparent";
|
||||
}
|
||||
final int red = (argb >>> 16) & 0xFF;
|
||||
final int green = (argb >>> 8) & 0xFF;
|
||||
final int blue = argb & 0xFF;
|
||||
return String.format("#%02X%02X%02X", red, green, blue);
|
||||
}
|
||||
|
||||
private String materialColorKey(int argb) {
|
||||
final int alpha = (argb >>> 24) & 0xFF;
|
||||
final int red = (argb >>> 16) & 0xFF;
|
||||
final int green = (argb >>> 8) & 0xFF;
|
||||
final int blue = argb & 0xFF;
|
||||
return alpha == 0xFF
|
||||
? String.format("#%02X%02X%02X", red, green, blue)
|
||||
: String.format("#%02X%02X%02X%02X", red, green, blue, alpha);
|
||||
}
|
||||
|
||||
private javafx.scene.paint.Color toFxColor(int argb) {
|
||||
final int alpha = (argb >>> 24) & 0xFF;
|
||||
if (alpha == 0) {
|
||||
return javafx.scene.paint.Color.TRANSPARENT;
|
||||
}
|
||||
final int red = (argb >>> 16) & 0xFF;
|
||||
final int green = (argb >>> 8) & 0xFF;
|
||||
final int blue = argb & 0xFF;
|
||||
return javafx.scene.paint.Color.rgb(red, green, blue, alpha / 255.0d);
|
||||
}
|
||||
|
||||
private int rgba8888ToArgb8888(Integer rgba8888) {
|
||||
if (rgba8888 == null) {
|
||||
return 0x00000000;
|
||||
}
|
||||
final int value = rgba8888;
|
||||
final int red = (value >>> 24) & 0xFF;
|
||||
final int green = (value >>> 16) & 0xFF;
|
||||
final int blue = (value >>> 8) & 0xFF;
|
||||
final int alpha = value & 0xFF;
|
||||
return (alpha << 24) | (red << 16) | (green << 8) | blue;
|
||||
}
|
||||
}
|
||||
+289
@@ -0,0 +1,289 @@
|
||||
package p.studio.ui.javafx.workspaces.assets.details.palette;
|
||||
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.ColorPicker;
|
||||
import javafx.scene.control.ComboBox;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.ListView;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.Priority;
|
||||
import javafx.scene.layout.Region;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.stage.Modality;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.stage.Window;
|
||||
import p.studio.ui.javafx.utilities.ThemeService;
|
||||
import p.studio.ui.javafx.utilities.i18n.I18n;
|
||||
import p.studio.ui.javafx.utilities.i18n.I18nService;
|
||||
import p.studio.api.assets.workspace.AssetWorkspaceBankCompositionFile;
|
||||
import p.studio.api.assets.metadata.AssetStudioGlyphMaterialSchema;
|
||||
import p.studio.api.assets.palette.AssetPaletteSession;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
public final class AssetDetailsPaletteWizardDialog {
|
||||
private final Stage stage = new Stage();
|
||||
private final ComboBox<AssetStudioGlyphMaterialSchema> schemaComboBox = new ComboBox<>();
|
||||
private final TextField nameField = new TextField();
|
||||
private final ObservableList<String> editableColors = FXCollections.observableArrayList();
|
||||
private final ObservableList<String> indexItems = FXCollections.observableArrayList();
|
||||
private final ListView<String> indexListView = new ListView<>(indexItems);
|
||||
private final ColorPicker colorPicker = new ColorPicker(Color.WHITE);
|
||||
private final Label summaryLabel = new Label();
|
||||
private final HBox originalStrip = new HBox(4);
|
||||
private final HBox editableStrip = new HBox(4);
|
||||
|
||||
private PaletteEditResult result;
|
||||
private final String paletteId;
|
||||
private final boolean editing;
|
||||
private final I18nService i18n;
|
||||
|
||||
private AssetDetailsPaletteWizardDialog(
|
||||
Window owner,
|
||||
AssetPaletteSession coordinator,
|
||||
AssetWorkspaceBankCompositionFile paletteFile,
|
||||
I18nService i18n,
|
||||
ThemeService theme) {
|
||||
this.i18n = Objects.requireNonNull(i18n, "i18n");
|
||||
this.editing = paletteFile != null;
|
||||
this.paletteId = editing && paletteFile.metadata().get("paletteId") instanceof String id && !id.isBlank()
|
||||
? id
|
||||
: coordinator.nextPaletteId();
|
||||
stage.initOwner(owner);
|
||||
stage.initModality(Modality.WINDOW_MODAL);
|
||||
stage.setTitle(i18n.text(editing
|
||||
? I18n.ASSETS_PALETTE_WIZARD_UPDATE_TITLE
|
||||
: I18n.ASSETS_PALETTE_WIZARD_CREATE_TITLE));
|
||||
|
||||
final List<AssetStudioGlyphMaterialSchema> schemas = coordinator.readySchemas();
|
||||
schemaComboBox.getItems().setAll(schemas);
|
||||
schemaComboBox.setCellFactory(ignored -> new javafx.scene.control.ListCell<>() {
|
||||
@Override
|
||||
protected void updateItem(AssetStudioGlyphMaterialSchema item, boolean empty) {
|
||||
super.updateItem(item, empty);
|
||||
setText(empty || item == null ? null : item.schemaId());
|
||||
}
|
||||
});
|
||||
schemaComboBox.setButtonCell(schemaComboBox.getCellFactory().call(null));
|
||||
|
||||
final AssetStudioGlyphMaterialSchema initialSchema = resolveInitialSchema(coordinator, paletteFile, schemas);
|
||||
if (initialSchema != null) {
|
||||
schemaComboBox.getSelectionModel().select(initialSchema);
|
||||
}
|
||||
editableColors.setAll(initialEditableColors(paletteFile, initialSchema));
|
||||
nameField.setText(initialDisplayName(paletteFile));
|
||||
nameField.setPromptText(coordinator.generatedDisplayName(editableColors));
|
||||
schemaComboBox.valueProperty().addListener((ignored, previous, current) -> {
|
||||
if (current == null) {
|
||||
editableColors.clear();
|
||||
} else if (!editing || previous == null || !Objects.equals(previous.schemaId(), current.schemaId())) {
|
||||
editableColors.setAll(current.materialIndices().entrySet().stream()
|
||||
.sorted(Map.Entry.comparingByKey())
|
||||
.map(Map.Entry::getValue)
|
||||
.toList());
|
||||
}
|
||||
refreshPreview(coordinator);
|
||||
});
|
||||
nameField.textProperty().addListener((ignored, previous, current) -> refreshPreview(coordinator));
|
||||
indexListView.getSelectionModel().selectedIndexProperty().addListener((ignored, previous, current) -> {
|
||||
final int selected = current == null ? -1 : current.intValue();
|
||||
if (selected >= 0 && selected < editableColors.size()) {
|
||||
colorPicker.setValue(Color.web(editableColors.get(selected)));
|
||||
}
|
||||
});
|
||||
|
||||
final Button applyColorButton = new Button(i18n.text(I18n.ASSETS_PALETTE_WIZARD_APPLY_COLOR));
|
||||
applyColorButton.getStyleClass().addAll("studio-button", "studio-button-secondary");
|
||||
applyColorButton.setOnAction(ignored -> {
|
||||
final int index = indexListView.getSelectionModel().getSelectedIndex();
|
||||
if (index < 0 || index >= editableColors.size()) {
|
||||
return;
|
||||
}
|
||||
editableColors.set(index, toHtmlColor(colorPicker.getValue()));
|
||||
refreshPreview(coordinator);
|
||||
indexListView.getSelectionModel().select(index);
|
||||
});
|
||||
|
||||
final Button cancelButton = new Button(i18n.text(I18n.FORM_ACTION_CANCEL));
|
||||
cancelButton.getStyleClass().addAll("studio-button", "studio-button-secondary");
|
||||
cancelButton.setOnAction(ignored -> {
|
||||
result = null;
|
||||
stage.close();
|
||||
});
|
||||
final Button applyButton = new Button(i18n.text(I18n.FORM_ACTION_APPLY));
|
||||
applyButton.getStyleClass().addAll("studio-button", "studio-button-primary");
|
||||
applyButton.setOnAction(ignored -> {
|
||||
final AssetStudioGlyphMaterialSchema selectedSchema = schemaComboBox.getSelectionModel().getSelectedItem();
|
||||
if (selectedSchema == null || coordinator.duplicatePaletteExists(paletteId, selectedSchema.schemaId(), editableColors)) {
|
||||
return;
|
||||
}
|
||||
result = new PaletteEditResult(paletteId, normalizedDisplayName(coordinator), selectedSchema.schemaId(), List.copyOf(editableColors));
|
||||
stage.close();
|
||||
});
|
||||
final Region spacer = new Region();
|
||||
HBox.setHgrow(spacer, Priority.ALWAYS);
|
||||
final HBox actions = new HBox(8, spacer, cancelButton, applyButton);
|
||||
actions.getStyleClass().add("assets-details-palette-wizard-actions");
|
||||
|
||||
final Label schemaLabel = fieldLabel(I18n.ASSETS_PALETTE_WIZARD_SCHEMA);
|
||||
final Label nameLabel = fieldLabel(I18n.ASSETS_PALETTE_WIZARD_NAME);
|
||||
final Label originalLabel = fieldLabel(I18n.ASSETS_PALETTE_WIZARD_ORIGINAL);
|
||||
final Label editableLabel = fieldLabel(I18n.ASSETS_PALETTE_WIZARD_EDITABLE);
|
||||
final VBox colorEditor = new VBox(8, colorPicker, applyColorButton);
|
||||
colorEditor.getStyleClass().add("assets-details-palette-wizard-color-editor");
|
||||
final HBox editorBody = new HBox(12, indexListView, colorEditor);
|
||||
editorBody.getStyleClass().add("assets-details-palette-wizard-editor");
|
||||
final VBox root = new VBox(
|
||||
12,
|
||||
nameLabel,
|
||||
nameField,
|
||||
schemaLabel,
|
||||
schemaComboBox,
|
||||
originalLabel,
|
||||
originalStrip,
|
||||
editableLabel,
|
||||
editableStrip,
|
||||
editorBody,
|
||||
summaryLabel,
|
||||
actions);
|
||||
root.setPadding(new Insets(16));
|
||||
root.getStyleClass().add("assets-details-palette-wizard");
|
||||
originalStrip.getStyleClass().add("assets-details-palette-wizard-strip");
|
||||
editableStrip.getStyleClass().add("assets-details-palette-wizard-strip");
|
||||
summaryLabel.getStyleClass().add("assets-details-palette-wizard-summary");
|
||||
HBox.setHgrow(indexListView, Priority.ALWAYS);
|
||||
HBox.setHgrow(schemaComboBox, Priority.ALWAYS);
|
||||
HBox.setHgrow(nameField, Priority.ALWAYS);
|
||||
refreshPreview(coordinator);
|
||||
final Scene scene = new Scene(root, 620, 570);
|
||||
scene.getStylesheets().add(Objects.requireNonNull(theme, "theme").getDefaultTheme());
|
||||
stage.setScene(scene);
|
||||
stage.setOnShown(ignored -> stage.centerOnScreen());
|
||||
}
|
||||
|
||||
public static Optional<PaletteEditResult> showAndWait(
|
||||
Window owner,
|
||||
AssetPaletteSession coordinator,
|
||||
AssetWorkspaceBankCompositionFile paletteFile,
|
||||
I18nService i18n,
|
||||
ThemeService theme) {
|
||||
final AssetDetailsPaletteWizardDialog dialog = new AssetDetailsPaletteWizardDialog(owner, coordinator, paletteFile, i18n, theme);
|
||||
dialog.stage.showAndWait();
|
||||
return Optional.ofNullable(dialog.result);
|
||||
}
|
||||
|
||||
private Label fieldLabel(I18n label) {
|
||||
final Label node = new Label(i18n.text(label));
|
||||
node.getStyleClass().add("assets-details-palette-wizard-label");
|
||||
return node;
|
||||
}
|
||||
|
||||
private AssetStudioGlyphMaterialSchema resolveInitialSchema(
|
||||
AssetPaletteSession coordinator,
|
||||
AssetWorkspaceBankCompositionFile paletteFile,
|
||||
List<AssetStudioGlyphMaterialSchema> schemas) {
|
||||
if (paletteFile != null && paletteFile.metadata().get("schemaId") instanceof String schemaId) {
|
||||
return coordinator.readySchemas().stream()
|
||||
.filter(schema -> schema.schemaId().equals(schemaId))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
return schemas.isEmpty() ? null : schemas.getFirst();
|
||||
}
|
||||
|
||||
private List<String> initialEditableColors(
|
||||
AssetWorkspaceBankCompositionFile paletteFile,
|
||||
AssetStudioGlyphMaterialSchema initialSchema) {
|
||||
if (paletteFile != null) {
|
||||
@SuppressWarnings("unchecked")
|
||||
final Map<String, Object> palette = (Map<String, Object>) paletteFile.metadata().get("palette");
|
||||
final Object original = palette == null ? null : palette.get("originalArgb8888");
|
||||
if (original instanceof Iterable<?> iterable) {
|
||||
final List<String> colors = new ArrayList<>();
|
||||
for (Object value : iterable) {
|
||||
if (value instanceof Number number) {
|
||||
colors.add(String.format("#%06X", number.intValue() & 0x00FFFFFF));
|
||||
}
|
||||
}
|
||||
return List.copyOf(colors);
|
||||
}
|
||||
}
|
||||
if (initialSchema == null) {
|
||||
return List.of();
|
||||
}
|
||||
return initialSchema.materialIndices().entrySet().stream()
|
||||
.sorted(Map.Entry.comparingByKey())
|
||||
.map(Map.Entry::getValue)
|
||||
.toList();
|
||||
}
|
||||
|
||||
private String initialDisplayName(AssetWorkspaceBankCompositionFile paletteFile) {
|
||||
if (paletteFile == null) {
|
||||
return "";
|
||||
}
|
||||
final Object explicitName = paletteFile.metadata().get("explicitPaletteDisplayName");
|
||||
return explicitName instanceof String value ? value : "";
|
||||
}
|
||||
|
||||
private void refreshPreview(AssetPaletteSession coordinator) {
|
||||
final AssetStudioGlyphMaterialSchema schema = schemaComboBox.getSelectionModel().getSelectedItem();
|
||||
final List<String> originalColors = schema == null
|
||||
? List.of()
|
||||
: schema.materialIndices().entrySet().stream()
|
||||
.sorted(Map.Entry.comparingByKey())
|
||||
.map(Map.Entry::getValue)
|
||||
.toList();
|
||||
originalStrip.getChildren().setAll(originalColors.stream().map(this::swatch).toList());
|
||||
editableStrip.getChildren().setAll(editableColors.stream().map(this::swatch).toList());
|
||||
nameField.setPromptText(coordinator.generatedDisplayName(editableColors));
|
||||
indexItems.setAll(java.util.stream.IntStream.range(0, editableColors.size())
|
||||
.mapToObj(index -> index + " -> " + editableColors.get(index))
|
||||
.toList());
|
||||
final boolean duplicate = schema != null && coordinator.duplicatePaletteExists(paletteId, schema.schemaId(), editableColors);
|
||||
summaryLabel.setText(duplicate
|
||||
? i18n.text(I18n.ASSETS_PALETTE_WIZARD_DUPLICATE)
|
||||
: i18n.text(I18n.ASSETS_PALETTE_WIZARD_READY));
|
||||
}
|
||||
|
||||
private String normalizedDisplayName(AssetPaletteSession coordinator) {
|
||||
final String value = nameField.getText();
|
||||
return value == null || value.trim().isBlank()
|
||||
? coordinator.generatedDisplayName(editableColors)
|
||||
: value.trim();
|
||||
}
|
||||
|
||||
private Region swatch(String color) {
|
||||
final Region swatch = new Region();
|
||||
swatch.setMinSize(22, 22);
|
||||
swatch.setPrefSize(22, 22);
|
||||
swatch.setMaxSize(22, 22);
|
||||
swatch.getStyleClass().add("assets-details-palette-wizard-swatch");
|
||||
swatch.setStyle("-fx-background-color: " + color + ";");
|
||||
return swatch;
|
||||
}
|
||||
|
||||
private String toHtmlColor(Color color) {
|
||||
return String.format(
|
||||
"#%02X%02X%02X",
|
||||
(int) Math.round(color.getRed() * 255),
|
||||
(int) Math.round(color.getGreen() * 255),
|
||||
(int) Math.round(color.getBlue() * 255));
|
||||
}
|
||||
|
||||
public record PaletteEditResult(
|
||||
String paletteId,
|
||||
String displayName,
|
||||
String schemaId,
|
||||
List<String> colors) {
|
||||
}
|
||||
}
|
||||
+632
@@ -0,0 +1,632 @@
|
||||
package p.studio.ui.javafx.workspaces.assets.details.scene;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.Priority;
|
||||
import javafx.scene.layout.Region;
|
||||
import javafx.scene.layout.VBox;
|
||||
import p.studio.api.assets.AssetFamily;
|
||||
import p.studio.api.assets.AssetCatalog;
|
||||
import p.studio.api.assets.AssetFamily;
|
||||
import p.studio.ui.javafx.controls.forms.StudioFormMode;
|
||||
import p.studio.ui.javafx.controls.lifecycle.StudioControlLifecycle;
|
||||
import p.studio.ui.javafx.controls.lifecycle.StudioControlLifecycleSupport;
|
||||
import p.studio.ui.javafx.events.StudioWorkspaceEventBus;
|
||||
import p.studio.api.project.ProjectReference;
|
||||
import p.studio.ui.javafx.utilities.i18n.I18n;
|
||||
import p.studio.ui.javafx.utilities.i18n.I18nService;
|
||||
import p.studio.ui.javafx.workspaces.assets.details.AssetDetailsUiSupport;
|
||||
import p.studio.ui.javafx.workspaces.assets.messages.AssetWorkspaceDetailsViewState;
|
||||
import p.studio.ui.javafx.workspaces.assets.messages.events.StudioAssetLogEvent;
|
||||
import p.studio.ui.javafx.workspaces.assets.messages.events.StudioAssetsDetailsViewStateChangedEvent;
|
||||
import p.studio.ui.javafx.workspaces.assets.messages.events.StudioAssetsWorkspaceDetailsSceneLayerChangedEvent;
|
||||
import p.studio.ui.javafx.workspaces.assets.messages.events.StudioAssetsWorkspaceSelectionRequestedEvent;
|
||||
import p.studio.api.assets.metadata.*;
|
||||
import p.studio.ui.javafx.workspaces.framework.StudioSubscriptionBag;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public final class AssetDetailsSceneLayersControl extends VBox implements StudioControlLifecycle {
|
||||
private final ProjectReference projectReference;
|
||||
private final StudioWorkspaceEventBus workspaceBus;
|
||||
private final StudioSubscriptionBag subscriptions = new StudioSubscriptionBag();
|
||||
private final AssetMetadataService metadataService;
|
||||
|
||||
private AssetWorkspaceDetailsViewState viewState;
|
||||
private Integer editingLayerIndex;
|
||||
private LayerDraft editingDraft;
|
||||
private int selectedLayerIndex = 1;
|
||||
|
||||
private final java.util.concurrent.Executor executor;
|
||||
private final I18nService i18n;
|
||||
private final AssetCatalog assetCatalog;
|
||||
|
||||
public AssetDetailsSceneLayersControl(ProjectReference projectReference, StudioWorkspaceEventBus workspaceBus,
|
||||
I18nService i18n, java.util.concurrent.Executor executor, AssetCatalog assetCatalog,
|
||||
AssetMetadataService metadataService) {
|
||||
StudioControlLifecycleSupport.install(this, this);
|
||||
this.projectReference = Objects.requireNonNull(projectReference, "projectReference");
|
||||
this.workspaceBus = Objects.requireNonNull(workspaceBus, "workspaceBus");
|
||||
this.i18n = Objects.requireNonNull(i18n, "i18n");
|
||||
this.executor = Objects.requireNonNull(executor, "executor");
|
||||
this.assetCatalog = Objects.requireNonNull(assetCatalog, "assetCatalog");
|
||||
this.metadataService = Objects.requireNonNull(metadataService, "metadataService");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void subscribe() {
|
||||
subscriptions.add(workspaceBus.subscribe(StudioAssetsDetailsViewStateChangedEvent.class, event -> {
|
||||
viewState = event.viewState();
|
||||
render();
|
||||
}));
|
||||
subscriptions.add(workspaceBus.subscribe(StudioAssetsWorkspaceDetailsSceneLayerChangedEvent.class, event -> {
|
||||
viewState = event.viewState();
|
||||
render();
|
||||
}));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unsubscribe() {
|
||||
subscriptions.clear();
|
||||
}
|
||||
|
||||
private void render() {
|
||||
final AssetStudioSceneBankMetadata metadata = viewState == null || viewState.selectedAssetDetails() == null
|
||||
? null
|
||||
: viewState.selectedAssetDetails().sceneBankMetadata();
|
||||
if (metadata == null) {
|
||||
getChildren().clear();
|
||||
return;
|
||||
}
|
||||
|
||||
final VBox content = new VBox(10);
|
||||
content.getChildren().add(createLayerSelector(
|
||||
viewState.selectedAssetDetails().summary().assetRoot(),
|
||||
metadata));
|
||||
content.getStyleClass().add("assets-scene-layer-shell");
|
||||
|
||||
getChildren().setAll(AssetDetailsUiSupport.createSectionWithoutHeader(content));
|
||||
}
|
||||
|
||||
private Node createLayerSelector(Path sceneAssetRoot, AssetStudioSceneBankMetadata metadata) {
|
||||
if (selectedLayerIndex < 1 || selectedLayerIndex > metadata.layerCount()) {
|
||||
selectedLayerIndex = 1;
|
||||
}
|
||||
final HBox selector = new HBox(8);
|
||||
selector.getStyleClass().add("assets-scene-layer-selector");
|
||||
for (int index = 1; index <= 4; index += 1) {
|
||||
final int layerIndex = index;
|
||||
final Button button = new Button();
|
||||
button.textProperty().bind(i18n.bind(I18n.ASSETS_LABEL_LAYER, layerIndex));
|
||||
button.getStyleClass().addAll("studio-button", "assets-scene-layer-selector-button");
|
||||
if (layerIndex == selectedLayerIndex) {
|
||||
button.getStyleClass().add("assets-scene-layer-selector-button-active");
|
||||
}
|
||||
button.setOnAction(ignored -> {
|
||||
selectedLayerIndex = layerIndex;
|
||||
render();
|
||||
});
|
||||
selector.getChildren().add(button);
|
||||
}
|
||||
|
||||
final AssetStudioSceneLayerBinding binding = metadata.layerBindings().stream()
|
||||
.filter(candidate -> candidate.index() == selectedLayerIndex)
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
final VBox container = new VBox(10);
|
||||
container.getChildren().addAll(selector, createLayerCard(sceneAssetRoot, selectedLayerIndex, binding));
|
||||
return container;
|
||||
}
|
||||
|
||||
private Node createLayerCard(Path sceneAssetRoot, int layerIndex, AssetStudioSceneLayerBinding binding) {
|
||||
final boolean editing = Objects.equals(editingLayerIndex, layerIndex) && binding != null && editingDraft != null;
|
||||
final LayerDraft draft = editing ? editingDraft : LayerDraft.from(binding);
|
||||
final VBox formContent = buildLayerFormContent(sceneAssetRoot, binding, draft, editing);
|
||||
final VBox formSection = AssetDetailsUiSupport.createEditableSection(
|
||||
i18n.text(I18n.ASSETS_SECTION_LAYER_CONFIGURATION),
|
||||
createLayerFormHeaderActions(layerIndex, binding, editing),
|
||||
formContent,
|
||||
editing ? StudioFormMode.EDITING : StudioFormMode.READ_ONLY);
|
||||
formSection.getStyleClass().add("assets-scene-layer-config-section");
|
||||
|
||||
final VBox leftColumn = new VBox(10);
|
||||
leftColumn.getStyleClass().add("assets-scene-layer-config-column");
|
||||
leftColumn.getChildren().addAll(
|
||||
formSection,
|
||||
createLayerActions(sceneAssetRoot, layerIndex, draft));
|
||||
|
||||
final VBox overview = createLayerOverviewPlaceholder();
|
||||
final HBox layout = new HBox(12, leftColumn, overview);
|
||||
layout.getStyleClass().add("assets-scene-layer-layout");
|
||||
HBox.setHgrow(leftColumn, Priority.ALWAYS);
|
||||
return layout;
|
||||
}
|
||||
|
||||
private VBox buildLayerFormContent(Path sceneAssetRoot, AssetStudioSceneLayerBinding binding, LayerDraft draft, boolean editing) {
|
||||
final VBox card = new VBox(8);
|
||||
card.getStyleClass().addAll("assets-scene-layer-card", "assets-scene-layer-config");
|
||||
|
||||
final CheckBox enabledCheckBox = new CheckBox();
|
||||
enabledCheckBox.textProperty().bind(i18n.bind(I18n.ASSETS_LABEL_USE_LAYER));
|
||||
enabledCheckBox.setSelected(draft != null && draft.enabled());
|
||||
enabledCheckBox.getStyleClass().add("assets-scene-layer-enabled");
|
||||
enabledCheckBox.setDisable(!editing);
|
||||
enabledCheckBox.setOnAction(ignored -> {
|
||||
if (draft != null) {
|
||||
draft.setEnabled(enabledCheckBox.isSelected());
|
||||
}
|
||||
});
|
||||
card.getChildren().add(enabledCheckBox);
|
||||
|
||||
card.getChildren().addAll(
|
||||
AssetDetailsUiSupport.createKeyValueRow(
|
||||
i18n.text(I18n.ASSETS_LABEL_SCENE_DIMENSIONS),
|
||||
editing ? createLayerSizeEditor(draft) : new Label(draft.widthText() + " x " + draft.heightText())),
|
||||
AssetDetailsUiSupport.createKeyValueRow(
|
||||
i18n.text(I18n.ASSETS_LABEL_TILEMAP),
|
||||
binding == null
|
||||
? i18n.text(I18n.ASSETS_VALUE_NOT_CONFIGURED)
|
||||
: AssetDetailsUiSupport.projectRelativePath(projectReference, sceneAssetRoot.resolve(binding.tilemap()))),
|
||||
AssetDetailsUiSupport.createKeyValueRow(
|
||||
i18n.text(I18n.ASSETS_LABEL_TILESET),
|
||||
editing ? createTilesetCombo(draft, true) : createTilesetReadOnlyValue(binding, draft)),
|
||||
AssetDetailsUiSupport.createKeyValueRow(
|
||||
i18n.text(I18n.ASSETS_LABEL_PARALLAX),
|
||||
editing ? createParallaxEditor(draft) : new Label(draft.parallaxText())),
|
||||
AssetDetailsUiSupport.createKeyValueRow(
|
||||
i18n.text(I18n.ASSETS_LABEL_DEFAULT_PALETTE),
|
||||
editing ? createDefaultPaletteEditor(draft) : new Label(draft.defaultPaletteText())));
|
||||
return card;
|
||||
}
|
||||
|
||||
private VBox createLayerOverviewPlaceholder() {
|
||||
final VBox overview = new VBox(10);
|
||||
overview.getStyleClass().add("assets-scene-layer-overview");
|
||||
|
||||
final Label title = new Label(i18n.text(I18n.ASSETS_LABEL_LAYER_OVERVIEW));
|
||||
title.getStyleClass().add("assets-scene-layer-overview-title");
|
||||
|
||||
final Region surface = new Region();
|
||||
surface.getStyleClass().add("assets-scene-layer-overview-surface");
|
||||
VBox.setVgrow(surface, Priority.ALWAYS);
|
||||
|
||||
overview.getChildren().addAll(
|
||||
title,
|
||||
surface,
|
||||
AssetDetailsUiSupport.createSectionMessage(i18n.text(I18n.ASSETS_VALUE_LAYER_OVERVIEW_PENDING)));
|
||||
return overview;
|
||||
}
|
||||
|
||||
private Node createLayerFormHeaderActions(int layerIndex, AssetStudioSceneLayerBinding binding, boolean editing) {
|
||||
final HBox actions = new HBox(8);
|
||||
actions.getStyleClass().add("assets-scene-layer-form-actions");
|
||||
if (!editing) {
|
||||
final Button changeButton = createFormActionButton(I18n.FORM_ACTION_CHANGE);
|
||||
changeButton.setDisable(binding == null);
|
||||
changeButton.setOnAction(ignored -> beginEdit(layerIndex, binding));
|
||||
actions.getChildren().add(changeButton);
|
||||
return actions;
|
||||
}
|
||||
|
||||
final Button applyButton = createFormActionButton(I18n.FORM_ACTION_APPLY);
|
||||
applyButton.setOnAction(ignored -> applyEdit(layerIndex, binding));
|
||||
final Button resetButton = createFormActionButton(I18n.FORM_ACTION_RESET);
|
||||
resetButton.setOnAction(ignored -> resetEdit(binding));
|
||||
final Button cancelButton = createFormActionButton(I18n.FORM_ACTION_CANCEL);
|
||||
cancelButton.setOnAction(ignored -> cancelEdit());
|
||||
actions.getChildren().addAll(applyButton, resetButton, cancelButton);
|
||||
return actions;
|
||||
}
|
||||
|
||||
private Node createLayerActions(Path sceneAssetRoot, int layerIndex, LayerDraft draft) {
|
||||
final HBox actions = new HBox(8);
|
||||
actions.setAlignment(Pos.CENTER_LEFT);
|
||||
actions.getStyleClass().add("assets-scene-layer-actions");
|
||||
final Region spacer = new Region();
|
||||
HBox.setHgrow(spacer, Priority.ALWAYS);
|
||||
actions.getChildren().add(spacer);
|
||||
return actions;
|
||||
}
|
||||
|
||||
private Node createLayerSizeEditor(LayerDraft draft) {
|
||||
final HBox editor = new HBox(8);
|
||||
editor.getStyleClass().add("assets-scene-layer-size-editor");
|
||||
|
||||
final TextField widthField = createSizeField(draft.widthText(), draft::setWidthText);
|
||||
final Label separator = new Label("x");
|
||||
separator.getStyleClass().add("assets-scene-layer-size-separator");
|
||||
final TextField heightField = createSizeField(draft.heightText(), draft::setHeightText);
|
||||
|
||||
editor.getChildren().addAll(widthField, separator, heightField);
|
||||
return editor;
|
||||
}
|
||||
|
||||
private TextField createSizeField(String value, java.util.function.Consumer<String> updater) {
|
||||
final TextField textField = new TextField(value);
|
||||
textField.getStyleClass().add("assets-scene-layer-size-field");
|
||||
textField.textProperty().addListener((ignored, oldValue, newValue) -> updater.accept(newValue));
|
||||
return textField;
|
||||
}
|
||||
|
||||
private ComboBox<TilesetOption> createTilesetCombo(LayerDraft draft, boolean editing) {
|
||||
final ComboBox<TilesetOption> combo = new ComboBox<>();
|
||||
combo.setMaxWidth(Double.MAX_VALUE);
|
||||
combo.getStyleClass().add("assets-details-combo");
|
||||
final List<TilesetOption> options = loadTilesetOptions();
|
||||
combo.setItems(FXCollections.observableArrayList(options));
|
||||
combo.setCellFactory(ignored -> new ListCell<>() {
|
||||
@Override
|
||||
protected void updateItem(TilesetOption item, boolean empty) {
|
||||
super.updateItem(item, empty);
|
||||
setText(empty || item == null ? null : item.label());
|
||||
}
|
||||
});
|
||||
combo.setButtonCell(new ListCell<>() {
|
||||
@Override
|
||||
protected void updateItem(TilesetOption item, boolean empty) {
|
||||
super.updateItem(item, empty);
|
||||
setText(empty || item == null ? null : item.label());
|
||||
}
|
||||
});
|
||||
final String currentTileset = draft == null ? "" : draft.tilesetAssetRoot();
|
||||
options.stream()
|
||||
.filter(option -> option.relativeAssetRoot().equals(currentTileset))
|
||||
.findFirst()
|
||||
.ifPresentOrElse(
|
||||
combo.getSelectionModel()::select,
|
||||
() -> combo.getSelectionModel().clearSelection());
|
||||
combo.setDisable(!editing || draft == null);
|
||||
if (draft == null) {
|
||||
combo.setDisable(true);
|
||||
return combo;
|
||||
}
|
||||
combo.valueProperty().addListener((ignored, oldValue, newValue) -> {
|
||||
if (Objects.equals(oldValue, newValue)) {
|
||||
return;
|
||||
}
|
||||
draft.setTilesetAssetRoot(newValue == null ? "" : newValue.relativeAssetRoot());
|
||||
});
|
||||
return combo;
|
||||
}
|
||||
|
||||
private Node createParallaxEditor(LayerDraft draft) {
|
||||
final HBox editor = new HBox(8);
|
||||
editor.getStyleClass().add("assets-scene-layer-size-editor");
|
||||
final TextField xField = createSizeField(draft.parallaxXText(), draft::setParallaxXText);
|
||||
final Label separator = new Label(",");
|
||||
separator.getStyleClass().add("assets-scene-layer-size-separator");
|
||||
final TextField yField = createSizeField(draft.parallaxYText(), draft::setParallaxYText);
|
||||
editor.getChildren().addAll(xField, separator, yField);
|
||||
return editor;
|
||||
}
|
||||
|
||||
private Node createDefaultPaletteEditor(LayerDraft draft) {
|
||||
final TextField textField = new TextField(draft.defaultPaletteText());
|
||||
textField.getStyleClass().add("assets-scene-layer-size-field");
|
||||
textField.textProperty().addListener((ignored, oldValue, newValue) -> draft.setDefaultPaletteText(newValue));
|
||||
return textField;
|
||||
}
|
||||
|
||||
private Node createTilesetReadOnlyValue(AssetStudioSceneLayerBinding binding, LayerDraft draft) {
|
||||
final String value = binding == null || draft == null || draft.tilesetAssetRoot().isBlank()
|
||||
? i18n.text(I18n.ASSETS_VALUE_NOT_CONFIGURED)
|
||||
: tilesetPath(draft.tilesetAssetRoot());
|
||||
return new Label(value);
|
||||
}
|
||||
|
||||
private List<TilesetOption> loadTilesetOptions() {
|
||||
try {
|
||||
return assetCatalog.list(projectReference, false).stream()
|
||||
.filter(asset -> asset.family() == AssetFamily.GLYPH_BANK)
|
||||
.filter(asset -> metadataService
|
||||
.read(asset.root(), AssetFamily.GLYPH_BANK)
|
||||
.glyphSpecialization() == AssetStudioGlyphSpecialization.TILESET)
|
||||
.map(asset -> {
|
||||
final String relativeAssetRoot = projectReference.rootPath()
|
||||
.resolve("assets")
|
||||
.relativize(asset.root())
|
||||
.toString()
|
||||
.replace('\\', '/');
|
||||
return new TilesetOption(asset.name(), relativeAssetRoot);
|
||||
})
|
||||
.sorted(Comparator.comparing(TilesetOption::label, String.CASE_INSENSITIVE_ORDER))
|
||||
.toList();
|
||||
} catch (RuntimeException exception) {
|
||||
return List.of();
|
||||
}
|
||||
}
|
||||
|
||||
private void updateLayerBinding(
|
||||
int layerIndex,
|
||||
java.util.function.Function<AssetStudioSceneLayerBinding, AssetStudioSceneLayerBinding> mutator,
|
||||
String successMessage) {
|
||||
if (viewState == null || viewState.selectedAssetDetails() == null || viewState.selectedAssetDetails().sceneBankMetadata() == null) {
|
||||
return;
|
||||
}
|
||||
final AssetStudioSceneBankMetadata metadata = viewState.selectedAssetDetails().sceneBankMetadata();
|
||||
final java.util.List<AssetStudioSceneLayerBinding> updatedBindings = new ArrayList<>();
|
||||
for (AssetStudioSceneLayerBinding binding : metadata.layerBindings()) {
|
||||
if (binding.index() == layerIndex) {
|
||||
updatedBindings.add(mutator.apply(binding));
|
||||
} else {
|
||||
updatedBindings.add(binding);
|
||||
}
|
||||
}
|
||||
final AssetStudioSceneLayerBinding firstBinding = updatedBindings.getFirst();
|
||||
final AssetStudioSceneBankMetadata updatedMetadata = new AssetStudioSceneBankMetadata(
|
||||
firstBinding.width(),
|
||||
firstBinding.height(),
|
||||
metadata.layerCount(),
|
||||
updatedBindings,
|
||||
metadata.supportFile());
|
||||
executor.execute(() -> {
|
||||
final var writeResult = metadataService.writeSceneBankMetadata(
|
||||
viewState.selectedAssetDetails().summary().assetRoot(), updatedMetadata);
|
||||
if (writeResult.successful()) {
|
||||
Platform.runLater(() -> {
|
||||
workspaceBus.publish(new StudioAssetLogEvent("scene-bank-layer", successMessage));
|
||||
workspaceBus.publish(new StudioAssetsWorkspaceSelectionRequestedEvent(viewState.selectedAssetReference(), true));
|
||||
});
|
||||
} else {
|
||||
Platform.runLater(() -> workspaceBus.publish(
|
||||
new StudioAssetLogEvent("scene-bank-layer", "Unable to update layer " + layerIndex + ": " + writeResult.message())));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private String tilesetPath(AssetStudioSceneLayerBinding binding) {
|
||||
return tilesetPath(binding.tilesetAssetRoot());
|
||||
}
|
||||
|
||||
private String tilesetPath(String tilesetAssetRoot) {
|
||||
if (tilesetAssetRoot.isBlank()) {
|
||||
return "—";
|
||||
}
|
||||
return AssetDetailsUiSupport.projectRelativePath(
|
||||
projectReference,
|
||||
projectReference.rootPath().resolve("assets").resolve(tilesetAssetRoot));
|
||||
}
|
||||
|
||||
private void beginEdit(int layerIndex, AssetStudioSceneLayerBinding binding) {
|
||||
editingLayerIndex = layerIndex;
|
||||
editingDraft = LayerDraft.from(binding);
|
||||
render();
|
||||
}
|
||||
|
||||
private void applyEdit(int layerIndex, AssetStudioSceneLayerBinding binding) {
|
||||
if (binding == null || editingDraft == null || !editingDraft.hasValidState()) {
|
||||
workspaceBus.publish(new StudioAssetLogEvent(
|
||||
"scene-bank-layer",
|
||||
"Layer configuration must use positive dimensions, non-negative parallax, and a non-negative default palette before applying changes."));
|
||||
return;
|
||||
}
|
||||
final LayerDraft draft = editingDraft.copy();
|
||||
editingLayerIndex = null;
|
||||
editingDraft = null;
|
||||
render();
|
||||
updateLayerBinding(layerIndex, current -> new AssetStudioSceneLayerBinding(
|
||||
draft.enabled(),
|
||||
current.index(),
|
||||
current.layerName(),
|
||||
draft.widthValue(),
|
||||
draft.heightValue(),
|
||||
current.tilemap(),
|
||||
draft.tilesetAssetRoot(),
|
||||
draft.parallaxXValue(),
|
||||
draft.parallaxYValue(),
|
||||
draft.defaultPaletteValue(),
|
||||
preservedTilesOrBlank(current, draft)),
|
||||
"Updated layer " + layerIndex + " configuration.");
|
||||
}
|
||||
|
||||
private List<AssetStudioSceneTile> preservedTilesOrBlank(
|
||||
AssetStudioSceneLayerBinding current,
|
||||
LayerDraft draft) {
|
||||
if (current.width() == draft.widthValue() && current.height() == draft.heightValue()) {
|
||||
return current.tiles();
|
||||
}
|
||||
final int tileCount = draft.widthValue() * draft.heightValue();
|
||||
final List<AssetStudioSceneTile> tiles = new ArrayList<>(tileCount);
|
||||
for (int index = 0; index < tileCount; index += 1) {
|
||||
tiles.add(AssetStudioSceneTile.inactive(draft.defaultPaletteValue()));
|
||||
}
|
||||
return List.copyOf(tiles);
|
||||
}
|
||||
|
||||
private void resetEdit(AssetStudioSceneLayerBinding binding) {
|
||||
editingDraft = LayerDraft.from(binding);
|
||||
render();
|
||||
}
|
||||
|
||||
private void cancelEdit() {
|
||||
editingLayerIndex = null;
|
||||
editingDraft = null;
|
||||
render();
|
||||
}
|
||||
|
||||
private Button createFormActionButton(I18n textKey) {
|
||||
final Button button = new Button(i18n.text(textKey));
|
||||
button.getStyleClass().addAll("studio-button", "studio-button-secondary");
|
||||
return button;
|
||||
}
|
||||
|
||||
private record TilesetOption(String assetName, String relativeAssetRoot) {
|
||||
String label() {
|
||||
return assetName + " [" + relativeAssetRoot + "]";
|
||||
}
|
||||
}
|
||||
|
||||
private static final class LayerDraft {
|
||||
private boolean enabled;
|
||||
private String widthText;
|
||||
private String heightText;
|
||||
private String tilesetAssetRoot;
|
||||
private String parallaxXText;
|
||||
private String parallaxYText;
|
||||
private String defaultPaletteText;
|
||||
|
||||
private LayerDraft(
|
||||
boolean enabled,
|
||||
String widthText,
|
||||
String heightText,
|
||||
String tilesetAssetRoot,
|
||||
String parallaxXText,
|
||||
String parallaxYText,
|
||||
String defaultPaletteText) {
|
||||
this.enabled = enabled;
|
||||
this.widthText = widthText;
|
||||
this.heightText = heightText;
|
||||
this.tilesetAssetRoot = Objects.requireNonNullElse(tilesetAssetRoot, "").trim();
|
||||
this.parallaxXText = Objects.requireNonNullElse(parallaxXText, "").trim();
|
||||
this.parallaxYText = Objects.requireNonNullElse(parallaxYText, "").trim();
|
||||
this.defaultPaletteText = Objects.requireNonNullElse(defaultPaletteText, "").trim();
|
||||
}
|
||||
|
||||
static LayerDraft from(AssetStudioSceneLayerBinding binding) {
|
||||
if (binding == null) {
|
||||
return new LayerDraft(false, "16", "16", "", "1.0", "1.0", "0");
|
||||
}
|
||||
return new LayerDraft(
|
||||
binding.enabled(),
|
||||
Integer.toString(binding.width()),
|
||||
Integer.toString(binding.height()),
|
||||
binding.tilesetAssetRoot(),
|
||||
trimFloat(binding.parallaxFactorX()),
|
||||
trimFloat(binding.parallaxFactorY()),
|
||||
Integer.toString(binding.defaultPaletteId()));
|
||||
}
|
||||
|
||||
LayerDraft copy() {
|
||||
return new LayerDraft(enabled, widthText, heightText, tilesetAssetRoot, parallaxXText, parallaxYText, defaultPaletteText);
|
||||
}
|
||||
|
||||
boolean enabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
String widthText() {
|
||||
return widthText;
|
||||
}
|
||||
|
||||
void setWidthText(String widthText) {
|
||||
this.widthText = Objects.requireNonNullElse(widthText, "").trim();
|
||||
}
|
||||
|
||||
String heightText() {
|
||||
return heightText;
|
||||
}
|
||||
|
||||
void setHeightText(String heightText) {
|
||||
this.heightText = Objects.requireNonNullElse(heightText, "").trim();
|
||||
}
|
||||
|
||||
String tilesetAssetRoot() {
|
||||
return tilesetAssetRoot;
|
||||
}
|
||||
|
||||
void setTilesetAssetRoot(String tilesetAssetRoot) {
|
||||
this.tilesetAssetRoot = Objects.requireNonNullElse(tilesetAssetRoot, "").trim();
|
||||
}
|
||||
|
||||
String parallaxXText() {
|
||||
return parallaxXText;
|
||||
}
|
||||
|
||||
void setParallaxXText(String parallaxXText) {
|
||||
this.parallaxXText = Objects.requireNonNullElse(parallaxXText, "").trim();
|
||||
}
|
||||
|
||||
String parallaxYText() {
|
||||
return parallaxYText;
|
||||
}
|
||||
|
||||
void setParallaxYText(String parallaxYText) {
|
||||
this.parallaxYText = Objects.requireNonNullElse(parallaxYText, "").trim();
|
||||
}
|
||||
|
||||
String parallaxText() {
|
||||
return parallaxXText + ", " + parallaxYText;
|
||||
}
|
||||
|
||||
String defaultPaletteText() {
|
||||
return defaultPaletteText;
|
||||
}
|
||||
|
||||
void setDefaultPaletteText(String defaultPaletteText) {
|
||||
this.defaultPaletteText = Objects.requireNonNullElse(defaultPaletteText, "").trim();
|
||||
}
|
||||
|
||||
boolean hasValidState() {
|
||||
return parsePositiveInt(widthText) > 0
|
||||
&& parsePositiveInt(heightText) > 0
|
||||
&& parseNonNegativeFloat(parallaxXText) >= 0.0f
|
||||
&& parseNonNegativeFloat(parallaxYText) >= 0.0f
|
||||
&& parseNonNegativeInt(defaultPaletteText) >= 0;
|
||||
}
|
||||
|
||||
int widthValue() {
|
||||
return parsePositiveInt(widthText);
|
||||
}
|
||||
|
||||
int heightValue() {
|
||||
return parsePositiveInt(heightText);
|
||||
}
|
||||
|
||||
float parallaxXValue() {
|
||||
return parseNonNegativeFloat(parallaxXText);
|
||||
}
|
||||
|
||||
float parallaxYValue() {
|
||||
return parseNonNegativeFloat(parallaxYText);
|
||||
}
|
||||
|
||||
int defaultPaletteValue() {
|
||||
return parseNonNegativeInt(defaultPaletteText);
|
||||
}
|
||||
|
||||
private static int parsePositiveInt(String value) {
|
||||
try {
|
||||
return Integer.parseInt(Objects.requireNonNullElse(value, "").trim());
|
||||
} catch (NumberFormatException exception) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
private static int parseNonNegativeInt(String value) {
|
||||
try {
|
||||
final int parsed = Integer.parseInt(Objects.requireNonNullElse(value, "").trim());
|
||||
return parsed >= 0 ? parsed : -1;
|
||||
} catch (NumberFormatException exception) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
private static float parseNonNegativeFloat(String value) {
|
||||
try {
|
||||
final float parsed = Float.parseFloat(Objects.requireNonNullElse(value, "").trim());
|
||||
return Float.isFinite(parsed) && parsed >= 0.0f ? parsed : -1.0f;
|
||||
} catch (NumberFormatException exception) {
|
||||
return -1.0f;
|
||||
}
|
||||
}
|
||||
|
||||
private static String trimFloat(float value) {
|
||||
if (value == (long) value) {
|
||||
return Long.toString((long) value) + ".0";
|
||||
}
|
||||
return Float.toString(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
+484
@@ -0,0 +1,484 @@
|
||||
package p.studio.ui.javafx.workspaces.assets.details.schema;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.ListCell;
|
||||
import javafx.scene.control.ListView;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.Priority;
|
||||
import javafx.scene.layout.Region;
|
||||
import javafx.scene.layout.VBox;
|
||||
import p.studio.ui.javafx.controls.banks.StudioDualListView;
|
||||
import p.studio.ui.javafx.controls.forms.StudioFormEditScopeChangedEvent;
|
||||
import p.studio.ui.javafx.controls.forms.StudioFormMode;
|
||||
import p.studio.ui.javafx.controls.forms.StudioFormSection;
|
||||
import p.studio.ui.javafx.events.StudioWorkspaceEventBus;
|
||||
import p.studio.api.project.ProjectReference;
|
||||
import p.studio.ui.javafx.utilities.i18n.I18n;
|
||||
import p.studio.ui.javafx.utilities.i18n.I18nService;
|
||||
import p.studio.api.assets.workspace.AssetWorkspaceBankCompositionFile;
|
||||
import p.studio.api.assets.schema.AssetColorSchemaFactory;
|
||||
import p.studio.api.assets.schema.AssetColorSchemaRules;
|
||||
import p.studio.api.assets.schema.AssetColorSchemaSession;
|
||||
import p.studio.api.assets.schema.AssetColorSchemaState;
|
||||
import p.studio.ui.javafx.workspaces.assets.messages.AssetWorkspaceDetailsViewState;
|
||||
import p.studio.ui.javafx.workspaces.assets.messages.events.StudioAssetLogEvent;
|
||||
import p.studio.ui.javafx.workspaces.assets.messages.events.StudioAssetsDetailsViewStateChangedEvent;
|
||||
import p.studio.ui.javafx.workspaces.assets.messages.events.StudioGlyphMaterialMetadataChangedEvent;
|
||||
import p.studio.api.assets.metadata.AssetStudioGlyphMaterialMetadata;
|
||||
import p.studio.api.assets.metadata.AssetStudioGlyphMaterialSchema;
|
||||
import p.studio.api.assets.metadata.AssetStudioGlyphMaterialSchemaStatus;
|
||||
import p.studio.api.assets.metadata.AssetMetadataService;
|
||||
import p.studio.ui.javafx.workspaces.framework.StudioSubscriptionBag;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public final class AssetDetailsColorSchemaGroupsControl extends StudioFormSection {
|
||||
private static final String SECTION_ID = "asset-details.color-schema-groups";
|
||||
|
||||
private final StudioWorkspaceEventBus workspaceBus;
|
||||
private final StudioSubscriptionBag subscriptions = new StudioSubscriptionBag();
|
||||
private final AssetMetadataService metadataService;
|
||||
private final AssetColorSchemaSession coordinator;
|
||||
private final AssetColorSchemaRules schemaRules;
|
||||
private final ListView<SchemaListItem> schemaListView = new ListView<>();
|
||||
private final SchemaTileDualListView tileDualListView;
|
||||
private final VBox schemaActions = new VBox(6);
|
||||
private final HBox schemaListPane = new HBox(8, schemaActions, schemaListView);
|
||||
private final HBox paletteStrip = new HBox(4);
|
||||
private final Label summaryLabel = new Label();
|
||||
private final Label schemaTitleLabel = new Label();
|
||||
private final Label paletteCounterLabel = new Label();
|
||||
private final Label warningLabel = new Label();
|
||||
private final VBox editorPane = new VBox(10);
|
||||
private final HBox body = new HBox(16);
|
||||
private final VBox content = new VBox(12, body, summaryLabel);
|
||||
|
||||
private AssetWorkspaceDetailsViewState viewState;
|
||||
private String selectedSchemaId;
|
||||
private boolean selectingSchema;
|
||||
private final java.util.concurrent.Executor executor;
|
||||
private final I18nService i18n;
|
||||
|
||||
public AssetDetailsColorSchemaGroupsControl(ProjectReference projectReference, StudioWorkspaceEventBus workspaceBus,
|
||||
I18nService i18n, java.util.concurrent.Executor executor, AssetMetadataService metadataService,
|
||||
AssetColorSchemaFactory colorSchemaFactory) {
|
||||
super(i18n);
|
||||
this.i18n = Objects.requireNonNull(i18n, "i18n");
|
||||
this.metadataService = Objects.requireNonNull(metadataService, "metadataService");
|
||||
final AssetColorSchemaFactory factory = Objects.requireNonNull(colorSchemaFactory, "colorSchemaFactory");
|
||||
this.coordinator = factory.createSession();
|
||||
this.schemaRules = factory.rules();
|
||||
this.tileDualListView = new SchemaTileDualListView(i18n);
|
||||
this.executor = Objects.requireNonNull(executor, "executor");
|
||||
Objects.requireNonNull(projectReference, "projectReference");
|
||||
this.workspaceBus = Objects.requireNonNull(workspaceBus, "workspaceBus");
|
||||
schemaListView.getStyleClass().add("assets-details-color-schema-list");
|
||||
schemaListView.setCellFactory(ignored -> createSchemaCell());
|
||||
schemaListView.getSelectionModel().selectedItemProperty().addListener((ignored, previous, current) -> {
|
||||
if (selectingSchema) {
|
||||
return;
|
||||
}
|
||||
selectedSchemaId = current == null ? null : current.schemaId();
|
||||
coordinator.selectSchema(selectedSchemaId);
|
||||
renderSection();
|
||||
});
|
||||
schemaActions.getStyleClass().add("assets-details-color-schema-toolbar");
|
||||
schemaListPane.getStyleClass().add("assets-details-list-with-actions");
|
||||
content.getStyleClass().add("assets-details-color-schema-content");
|
||||
body.getStyleClass().add("assets-details-color-schema-body");
|
||||
paletteStrip.getStyleClass().add("assets-details-color-schema-strip");
|
||||
schemaTitleLabel.getStyleClass().add("assets-details-color-schema-title");
|
||||
paletteCounterLabel.getStyleClass().add("assets-details-color-schema-summary");
|
||||
summaryLabel.getStyleClass().add("assets-details-color-schema-summary");
|
||||
warningLabel.getStyleClass().add("assets-details-color-schema-warning");
|
||||
HBox.setHgrow(schemaListPane, Priority.ALWAYS);
|
||||
HBox.setHgrow(schemaListView, Priority.ALWAYS);
|
||||
HBox.setHgrow(editorPane, Priority.ALWAYS);
|
||||
schemaListView.setMaxWidth(Double.MAX_VALUE);
|
||||
editorPane.setMaxWidth(Double.MAX_VALUE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void subscribe() {
|
||||
subscriptions.add(workspaceBus.subscribe(StudioAssetsDetailsViewStateChangedEvent.class, event -> {
|
||||
viewState = event.viewState();
|
||||
coordinator.replaceDetails(viewState == null ? null : viewState.selectedAssetDetails());
|
||||
normalizeSelectedSchema();
|
||||
replaceFormSource();
|
||||
if (viewState == null || viewState.selectedAssetReference() == null) {
|
||||
publishEditScope(workspaceBus, currentScopeKey(), null);
|
||||
}
|
||||
renderSection();
|
||||
}));
|
||||
subscriptions.add(workspaceBus.subscribe(StudioFormEditScopeChangedEvent.class,
|
||||
event -> handleEditScopeChanged(event, currentScopeKey())));
|
||||
subscriptions.add(workspaceBus.subscribe(StudioGlyphMaterialMetadataChangedEvent.class, event -> {
|
||||
if (viewState == null || !Objects.equals(viewState.selectedAssetReference(), event.assetReference())) {
|
||||
return;
|
||||
}
|
||||
coordinator.replaceMaterialMetadata(event.metadata());
|
||||
if (formMode() != StudioFormMode.EDITING) {
|
||||
replaceFormSource();
|
||||
}
|
||||
renderSection();
|
||||
}));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unsubscribe() {
|
||||
subscriptions.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderSection() {
|
||||
if (viewState == null || viewState.selectedAssetDetails() == null || !coordinator.ready()) {
|
||||
clearRenderedSection();
|
||||
return;
|
||||
}
|
||||
|
||||
final AssetColorSchemaState draft = coordinator.state();
|
||||
renderSchemaList();
|
||||
renderSchemaActions(draft);
|
||||
renderEditor(draft);
|
||||
summaryLabel.setText(i18n.format(
|
||||
I18n.ASSETS_COLOR_SCHEMA_SUMMARY,
|
||||
coordinator.schemas().size(),
|
||||
coordinator.unassignedTileCount()));
|
||||
body.getChildren().setAll(schemaListPane, editorPane);
|
||||
renderFormSection(content);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String sectionTitle() {
|
||||
return i18n.text(I18n.ASSETS_SECTION_COLOR_SCHEMA_GROUPS);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected StudioFormMode formMode() {
|
||||
return coordinator.state().editing() ? StudioFormMode.EDITING : StudioFormMode.READ_ONLY;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isDirty() {
|
||||
return coordinator.state().dirty();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void beginEdit() {
|
||||
coordinator.beginEdit();
|
||||
selectedSchemaId = null;
|
||||
publishEditScope(workspaceBus, currentScopeKey(), SECTION_ID);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void apply() {
|
||||
if (viewState == null || viewState.selectedAssetDetails() == null || viewState.selectedAssetReference() == null || !coordinator.ready()) {
|
||||
return;
|
||||
}
|
||||
final AssetColorSchemaState draft = coordinator.state();
|
||||
if (!draft.selected()) {
|
||||
workspaceBus.publish(new StudioAssetLogEvent("color-schema-groups", "Apply failed: select or create a schema first."));
|
||||
return;
|
||||
}
|
||||
if (!draft.removeRequested()) {
|
||||
final List<String> orderedColors = draft.orderedColors();
|
||||
if (draft.assignedTiles().isEmpty() || orderedColors.isEmpty()) {
|
||||
workspaceBus.publish(new StudioAssetLogEvent("color-schema-groups", "Apply failed: schema must contain at least one tile."));
|
||||
return;
|
||||
}
|
||||
if (orderedColors.size() > 16) {
|
||||
workspaceBus.publish(new StudioAssetLogEvent(
|
||||
"color-schema-groups",
|
||||
i18n.text(I18n.ASSETS_COLOR_SCHEMA_DIALOG_TOO_MANY_COLORS)));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
final var assetDetails = viewState.selectedAssetDetails();
|
||||
final var assetReference = viewState.selectedAssetReference();
|
||||
executor.execute(() -> {
|
||||
try {
|
||||
final AssetStudioGlyphMaterialMetadata metadata = draft.removeRequested()
|
||||
? coordinator.removeSchema(draft.schemaId())
|
||||
: coordinator.upsertSchema(draft.schemaId(), draft.assignedTiles(), draft.orderedColors());
|
||||
final var writeResult = metadataService.writeGlyphMaterialMetadata(assetDetails.summary().assetRoot(), metadata);
|
||||
if (!writeResult.successful()) {
|
||||
Platform.runLater(() -> workspaceBus.publish(new StudioAssetLogEvent(
|
||||
"color-schema-groups",
|
||||
"Unable to save schema: " + writeResult.message())));
|
||||
return;
|
||||
}
|
||||
Platform.runLater(() -> {
|
||||
coordinator.apply();
|
||||
selectedSchemaId = draft.removeRequested() ? null : draft.schemaId();
|
||||
publishEditScope(workspaceBus, currentScopeKey(), null);
|
||||
workspaceBus.publish(new StudioAssetLogEvent(
|
||||
"color-schema-groups",
|
||||
draft.removeRequested() ? "Schema removed: " + draft.schemaId() : "Schema saved: " + draft.schemaId()));
|
||||
workspaceBus.publish(new StudioGlyphMaterialMetadataChangedEvent(assetReference, metadata));
|
||||
renderSection();
|
||||
});
|
||||
} catch (RuntimeException exception) {
|
||||
Platform.runLater(() -> workspaceBus.publish(new StudioAssetLogEvent(
|
||||
"color-schema-groups",
|
||||
"Unable to save schema.")));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void reset() {
|
||||
coordinator.reset();
|
||||
selectedSchemaId = coordinator.state().selected() ? coordinator.state().schemaId() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void cancel() {
|
||||
coordinator.cancel();
|
||||
selectedSchemaId = coordinator.state().selected() ? coordinator.state().schemaId() : null;
|
||||
publishEditScope(workspaceBus, currentScopeKey(), null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String sectionStyleClass() {
|
||||
return "assets-details-color-schema-section";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String formSectionId() {
|
||||
return SECTION_ID;
|
||||
}
|
||||
|
||||
private void renderSchemaList() {
|
||||
selectingSchema = true;
|
||||
schemaListView.getItems().setAll(schemaListItems());
|
||||
schemaListView.setDisable(false);
|
||||
if (selectedSchemaId != null) {
|
||||
schemaListView.getItems().stream()
|
||||
.filter(schema -> schema.schemaId().equals(selectedSchemaId))
|
||||
.findFirst()
|
||||
.ifPresentOrElse(
|
||||
schema -> schemaListView.getSelectionModel().select(schema),
|
||||
() -> schemaListView.getSelectionModel().clearSelection());
|
||||
} else {
|
||||
schemaListView.getSelectionModel().clearSelection();
|
||||
}
|
||||
selectingSchema = false;
|
||||
}
|
||||
|
||||
private void renderSchemaActions(AssetColorSchemaState draft) {
|
||||
final Button newButton = new Button("+");
|
||||
newButton.getStyleClass().addAll("studio-button", "studio-button-secondary", "assets-details-mini-action-button");
|
||||
newButton.setDisable(formMode() != StudioFormMode.EDITING);
|
||||
newButton.setOnAction(ignored -> {
|
||||
coordinator.createSchema();
|
||||
selectedSchemaId = coordinator.state().schemaId();
|
||||
rerenderPreservingScrollPosition();
|
||||
});
|
||||
|
||||
final Button removeButton = new Button("-");
|
||||
removeButton.getStyleClass().addAll("studio-button", "studio-button-secondary", "assets-details-mini-action-button");
|
||||
removeButton.setDisable(formMode() != StudioFormMode.EDITING || !draft.selected() || (draft.existingSchema() && !coordinator.canRemove(draft.schemaId())));
|
||||
removeButton.setOnAction(ignored -> {
|
||||
coordinator.markSelectedSchemaForRemoval();
|
||||
selectedSchemaId = coordinator.state().schemaId();
|
||||
rerenderPreservingScrollPosition();
|
||||
});
|
||||
if (draft.existingSchema() && !coordinator.canRemove(draft.schemaId())) {
|
||||
removeButton.setTooltip(new javafx.scene.control.Tooltip(
|
||||
i18n.format(I18n.ASSETS_COLOR_SCHEMA_REMOVE_BLOCKED, draft.schemaId())));
|
||||
}
|
||||
|
||||
schemaActions.getChildren().setAll(newButton, removeButton);
|
||||
}
|
||||
|
||||
private void renderEditor(AssetColorSchemaState draft) {
|
||||
editorPane.getChildren().clear();
|
||||
if (!draft.selected()) {
|
||||
tileDualListView.setLeftItems(List.of());
|
||||
tileDualListView.setRightItems(List.of());
|
||||
tileDualListView.setInteractionEnabled(false);
|
||||
paletteStrip.getChildren().clear();
|
||||
paletteCounterLabel.setText(i18n.format(I18n.ASSETS_COLOR_SCHEMA_DIALOG_COLOR_COUNT, 0));
|
||||
editorPane.getChildren().addAll(
|
||||
emptyMessage("Select a schema or create a new one to edit its tile group."),
|
||||
tileDualListView,
|
||||
paletteCounterLabel,
|
||||
paletteStrip);
|
||||
return;
|
||||
}
|
||||
if (draft.removeRequested()) {
|
||||
editorPane.getChildren().add(emptyMessage("Schema " + draft.schemaId() + " will be removed when you apply this form."));
|
||||
return;
|
||||
}
|
||||
|
||||
final List<String> orderedColors = draft.orderedColors();
|
||||
schemaTitleLabel.setText(draft.schemaId() + (draft.existingSchema() ? "" : " (new)"));
|
||||
paletteCounterLabel.setText(i18n.format(I18n.ASSETS_COLOR_SCHEMA_DIALOG_COLOR_COUNT, orderedColors.size()));
|
||||
warningLabel.setText(orderedColors.size() > 16
|
||||
? i18n.text(I18n.ASSETS_COLOR_SCHEMA_DIALOG_TOO_MANY_COLORS)
|
||||
: "");
|
||||
paletteStrip.getChildren().setAll(orderedColors.stream().map(this::swatch).toList());
|
||||
|
||||
tileDualListView.setLeftItems(draft.availableTiles());
|
||||
tileDualListView.setRightItems(draft.assignedTiles());
|
||||
tileDualListView.setInteractionEnabled(formMode() == StudioFormMode.EDITING && draft.selected());
|
||||
tileDualListView.setMoveToRightAllowed(true);
|
||||
tileDualListView.setOnMoveToRight(items -> updateDraft(() -> coordinator.moveToAssigned(items)));
|
||||
tileDualListView.setOnMoveToLeft(items -> updateDraft(() -> coordinator.moveToAvailable(items)));
|
||||
tileDualListView.setOnMoveUp(index -> updateDraft(() -> coordinator.moveAssignedUp(index)));
|
||||
tileDualListView.setOnMoveDown(index -> updateDraft(() -> coordinator.moveAssignedDown(index)));
|
||||
|
||||
editorPane.getChildren().addAll(schemaTitleLabel, tileDualListView, paletteCounterLabel, paletteStrip, warningLabel);
|
||||
VBox.setVgrow(tileDualListView, Priority.ALWAYS);
|
||||
}
|
||||
|
||||
private void updateDraft(Runnable update) {
|
||||
if (formMode() != StudioFormMode.EDITING) {
|
||||
return;
|
||||
}
|
||||
update.run();
|
||||
rerenderPreservingScrollPosition();
|
||||
}
|
||||
|
||||
private void replaceFormSource() {
|
||||
if (!coordinator.ready()) {
|
||||
return;
|
||||
}
|
||||
if (coordinator.state().editing()) {
|
||||
return;
|
||||
}
|
||||
final String schemaId = selectedSchemaId != null ? selectedSchemaId : defaultSchemaId();
|
||||
selectedSchemaId = schemaId;
|
||||
coordinator.selectSchema(schemaId);
|
||||
}
|
||||
|
||||
private void normalizeSelectedSchema() {
|
||||
if (selectedSchemaId == null || coordinator.findSchema(selectedSchemaId).isPresent()) {
|
||||
return;
|
||||
}
|
||||
selectedSchemaId = null;
|
||||
}
|
||||
|
||||
private String defaultSchemaId() {
|
||||
return coordinator.schemas().stream()
|
||||
.map(AssetStudioGlyphMaterialSchema::schemaId)
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
private List<SchemaListItem> schemaListItems() {
|
||||
final List<SchemaListItem> items = new java.util.ArrayList<>(coordinator.schemas().stream()
|
||||
.map(schema -> SchemaListItem.fromSchema(schema, coordinator.selectedTiles(), schemaRules))
|
||||
.toList());
|
||||
final AssetColorSchemaState state = coordinator.state();
|
||||
if (state.selected()
|
||||
&& !state.existingSchema()
|
||||
&& items.stream().noneMatch(item -> item.schemaId().equals(state.schemaId()))) {
|
||||
items.add(SchemaListItem.fromDraft(state));
|
||||
}
|
||||
return List.copyOf(items);
|
||||
}
|
||||
|
||||
private ListCell<SchemaListItem> createSchemaCell() {
|
||||
return new ListCell<>() {
|
||||
@Override
|
||||
protected void updateItem(SchemaListItem item, boolean empty) {
|
||||
super.updateItem(item, empty);
|
||||
if (empty || item == null) {
|
||||
setGraphic(null);
|
||||
setText(null);
|
||||
return;
|
||||
}
|
||||
final Label title = new Label(item.schemaId());
|
||||
title.getStyleClass().add("assets-details-color-schema-title");
|
||||
final Label version = new Label(item.existing() ? "v" + item.version() : "new");
|
||||
version.getStyleClass().add("assets-details-color-schema-version");
|
||||
final Label status = new Label(item.status());
|
||||
status.getStyleClass().addAll("studio-chip", Objects.equals(item.status(), AssetStudioGlyphMaterialSchemaStatus.OK.manifestValue())
|
||||
? "assets-details-color-schema-status-ok"
|
||||
: "assets-details-color-schema-status-inconsistent");
|
||||
final Region spacer = new Region();
|
||||
HBox.setHgrow(spacer, Priority.ALWAYS);
|
||||
final HBox top = new HBox(8, title, version, spacer, status);
|
||||
|
||||
final Label meta = new Label(item.tileCount() + " tiles · " + item.indexCount() + " indices");
|
||||
meta.getStyleClass().add("assets-details-color-schema-meta");
|
||||
final VBox root = new VBox(6, top, meta);
|
||||
root.getStyleClass().add("assets-details-color-schema-item");
|
||||
setGraphic(root);
|
||||
setText(null);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private Region swatch(String color) {
|
||||
final Region swatch = new Region();
|
||||
swatch.getStyleClass().add("assets-details-color-schema-swatch");
|
||||
swatch.setMinSize(20, 20);
|
||||
swatch.setPrefSize(20, 20);
|
||||
swatch.setMaxSize(20, 20);
|
||||
swatch.setStyle("-fx-background-color: " + color + ";");
|
||||
return swatch;
|
||||
}
|
||||
|
||||
private Node emptyMessage(String text) {
|
||||
final Label label = new Label(text);
|
||||
label.getStyleClass().add("assets-details-color-schema-empty");
|
||||
return label;
|
||||
}
|
||||
|
||||
private String currentScopeKey() {
|
||||
return viewState == null || viewState.selectedAssetReference() == null
|
||||
? null
|
||||
: "asset-details:" + viewState.selectedAssetReference();
|
||||
}
|
||||
|
||||
private static final class SchemaTileDualListView extends StudioDualListView<AssetWorkspaceBankCompositionFile> {
|
||||
private SchemaTileDualListView(I18nService i18n) {
|
||||
setLeftTitle(i18n.text(I18n.ASSETS_COLOR_SCHEMA_DIALOG_AVAILABLE_TILES));
|
||||
setRightTitle(i18n.text(I18n.ASSETS_COLOR_SCHEMA_DIALOG_ASSIGNED_TILES));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String itemText(AssetWorkspaceBankCompositionFile item) {
|
||||
return item.displayName();
|
||||
}
|
||||
}
|
||||
|
||||
private record SchemaListItem(
|
||||
String schemaId,
|
||||
boolean existing,
|
||||
int version,
|
||||
String status,
|
||||
int tileCount,
|
||||
int indexCount) {
|
||||
|
||||
private static SchemaListItem fromSchema(
|
||||
AssetStudioGlyphMaterialSchema schema,
|
||||
List<AssetWorkspaceBankCompositionFile> selectedTiles,
|
||||
AssetColorSchemaRules schemaRules) {
|
||||
return new SchemaListItem(
|
||||
schema.schemaId(),
|
||||
true,
|
||||
schema.version(),
|
||||
schemaRules.effectiveStatus(schema, selectedTiles).manifestValue(),
|
||||
schema.artifactBindings().size(),
|
||||
schema.materialIndices().size());
|
||||
}
|
||||
|
||||
private static SchemaListItem fromDraft(AssetColorSchemaState draft) {
|
||||
return new SchemaListItem(
|
||||
draft.schemaId(),
|
||||
false,
|
||||
0,
|
||||
AssetStudioGlyphMaterialSchemaStatus.OK.manifestValue(),
|
||||
draft.assignedTiles().size(),
|
||||
draft.orderedColors().size());
|
||||
}
|
||||
}
|
||||
}
|
||||
+92
@@ -0,0 +1,92 @@
|
||||
package p.studio.ui.javafx.workspaces.assets.details.summary;
|
||||
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.VBox;
|
||||
import p.studio.ui.javafx.controls.lifecycle.StudioControlLifecycle;
|
||||
import p.studio.ui.javafx.controls.lifecycle.StudioControlLifecycleSupport;
|
||||
import p.studio.ui.javafx.events.StudioWorkspaceEventBus;
|
||||
import p.studio.api.project.ProjectReference;
|
||||
import p.studio.ui.javafx.utilities.i18n.I18n;
|
||||
import p.studio.ui.javafx.utilities.i18n.I18nService;
|
||||
import p.studio.ui.javafx.workspaces.assets.details.AssetDetailsUiSupport;
|
||||
import p.studio.api.assets.metadata.AssetStudioGlyphSpecialization;
|
||||
import p.studio.api.assets.metadata.AssetStudioSceneBankMetadata;
|
||||
import p.studio.api.assets.workspace.AssetWorkspaceAssetSummary;
|
||||
import p.studio.ui.javafx.workspaces.assets.messages.AssetWorkspaceDetailsViewState;
|
||||
import p.studio.ui.javafx.workspaces.assets.messages.events.StudioAssetsDetailsViewStateChangedEvent;
|
||||
import p.studio.ui.javafx.workspaces.framework.StudioSubscriptionBag;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public final class AssetDetailsSummaryControl extends VBox implements StudioControlLifecycle {
|
||||
private final ProjectReference projectReference;
|
||||
private final StudioWorkspaceEventBus workspaceBus;
|
||||
private final I18nService i18n;
|
||||
private final StudioSubscriptionBag subscriptions = new StudioSubscriptionBag();
|
||||
|
||||
private AssetWorkspaceDetailsViewState viewState;
|
||||
|
||||
public AssetDetailsSummaryControl(ProjectReference projectReference, StudioWorkspaceEventBus workspaceBus, I18nService i18n) {
|
||||
StudioControlLifecycleSupport.install(this, this);
|
||||
this.projectReference = Objects.requireNonNull(projectReference, "projectReference");
|
||||
this.workspaceBus = Objects.requireNonNull(workspaceBus, "workspaceBus");
|
||||
this.i18n = Objects.requireNonNull(i18n, "i18n");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void subscribe() {
|
||||
subscriptions.add(workspaceBus.subscribe(StudioAssetsDetailsViewStateChangedEvent.class, event -> {
|
||||
viewState = event.viewState();
|
||||
render();
|
||||
}));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unsubscribe() {
|
||||
subscriptions.clear();
|
||||
}
|
||||
|
||||
private void render() {
|
||||
if (viewState == null || viewState.selectedAssetDetails() == null) {
|
||||
getChildren().clear();
|
||||
return;
|
||||
}
|
||||
final AssetWorkspaceAssetSummary summary = viewState.selectedAssetDetails().summary();
|
||||
if (summary == null) {
|
||||
getChildren().clear();
|
||||
return;
|
||||
}
|
||||
|
||||
final VBox content = new VBox(8);
|
||||
content.getChildren().setAll(
|
||||
AssetDetailsUiSupport.createKeyValueRow(i18n.text(I18n.ASSETS_LABEL_ASSET_ID), summary.assetId() == null ? "—" : String.valueOf(summary.assetId())),
|
||||
AssetDetailsUiSupport.createKeyValueRow(i18n.text(I18n.ASSETS_LABEL_LOCATION), AssetDetailsUiSupport.projectRelativePath(projectReference, summary.assetRoot())));
|
||||
final HBox typeBox = new HBox(8);
|
||||
typeBox.getStyleClass().add("assets-details-chips");
|
||||
typeBox.getChildren().add(AssetDetailsUiSupport.createChip(
|
||||
AssetDetailsUiSupport.typeChipTone(summary.assetFamily()),
|
||||
AssetDetailsUiSupport.typeLabel(i18n, summary.assetFamily())));
|
||||
if (summary.glyphSpecialization() != AssetStudioGlyphSpecialization.NONE) {
|
||||
typeBox.getChildren().add(AssetDetailsUiSupport.createChip(
|
||||
AssetDetailsUiSupport.typeChipTone(summary.assetFamily()),
|
||||
AssetDetailsUiSupport.specializationLabel(i18n, summary.glyphSpecialization()),
|
||||
"assets-details-chip-fixed"));
|
||||
}
|
||||
content.getChildren().add(AssetDetailsUiSupport.createKeyValueRow(
|
||||
i18n.text(I18n.ASSETS_LABEL_TYPE),
|
||||
typeBox));
|
||||
content.getChildren().add(AssetDetailsUiSupport.createKeyValueRow(
|
||||
i18n.text(I18n.ASSETS_LABEL_REGISTRATION),
|
||||
AssetDetailsUiSupport.createChip(
|
||||
AssetDetailsUiSupport.registrationChipTone(summary.state()),
|
||||
AssetDetailsUiSupport.registrationLabel(i18n, summary.state()))));
|
||||
content.getChildren().add(AssetDetailsUiSupport.createKeyValueRow(
|
||||
i18n.text(I18n.ASSETS_LABEL_BUILD_PARTICIPATION),
|
||||
AssetDetailsUiSupport.createChip(
|
||||
AssetDetailsUiSupport.buildChipTone(summary.buildParticipation()),
|
||||
AssetDetailsUiSupport.buildParticipationLabel(i18n, summary.buildParticipation()))));
|
||||
getChildren().setAll(AssetDetailsUiSupport.createSection(
|
||||
i18n.text(I18n.ASSETS_SECTION_SUMMARY),
|
||||
content));
|
||||
}
|
||||
}
|
||||
+253
@@ -0,0 +1,253 @@
|
||||
package p.studio.ui.javafx.workspaces.assets.dialogs;
|
||||
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.ScrollPane;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.Priority;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.stage.Modality;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.stage.Window;
|
||||
import p.studio.api.assets.AssetDiagnostic;
|
||||
import p.studio.api.project.ProjectReference;
|
||||
import p.studio.ui.javafx.utilities.ThemeService;
|
||||
import p.studio.ui.javafx.utilities.i18n.I18n;
|
||||
import p.studio.ui.javafx.utilities.i18n.I18nService;
|
||||
import p.studio.ui.javafx.workspaces.assets.details.AssetDetailsUiSupport;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public final class AssetDiagnosticsDialog {
|
||||
private static final String GENERAL_GROUP_KEY = "__general__";
|
||||
|
||||
private final Stage stage;
|
||||
private final ProjectReference projectReference;
|
||||
private final String assetName;
|
||||
private final List<AssetDiagnostic> diagnostics;
|
||||
private final Map<String, DiagnosticGroup> diagnosticsByGroup;
|
||||
private final I18nService i18n;
|
||||
|
||||
private final VBox groupList = new VBox(6);
|
||||
private final VBox diagnosticsContent = new VBox(10);
|
||||
private String selectedGroupKey;
|
||||
|
||||
private AssetDiagnosticsDialog(
|
||||
Window owner,
|
||||
ProjectReference projectReference,
|
||||
String assetName,
|
||||
List<AssetDiagnostic> diagnostics,
|
||||
I18nService i18n,
|
||||
ThemeService theme) {
|
||||
this.projectReference = Objects.requireNonNull(projectReference, "projectReference");
|
||||
this.assetName = Objects.requireNonNull(assetName, "assetName");
|
||||
this.diagnostics = List.copyOf(Objects.requireNonNull(diagnostics, "diagnostics"));
|
||||
this.i18n = Objects.requireNonNull(i18n, "i18n");
|
||||
this.diagnosticsByGroup = buildGroups(this.diagnostics);
|
||||
this.selectedGroupKey = diagnosticsByGroup.containsKey(GENERAL_GROUP_KEY)
|
||||
? GENERAL_GROUP_KEY
|
||||
: diagnosticsByGroup.keySet().stream().findFirst().orElse(GENERAL_GROUP_KEY);
|
||||
this.stage = new Stage();
|
||||
stage.initOwner(owner);
|
||||
stage.initModality(Modality.WINDOW_MODAL);
|
||||
stage.setTitle(i18n.text(I18n.ASSETS_DIAGNOSTICS_DIALOG_TITLE));
|
||||
stage.setScene(new Scene(buildRoot(), 720, 560));
|
||||
stage.getScene().getStylesheets().add(Objects.requireNonNull(theme, "theme").getDefaultTheme());
|
||||
}
|
||||
|
||||
public static void showAndWait(
|
||||
Window owner,
|
||||
ProjectReference projectReference,
|
||||
String assetName,
|
||||
List<AssetDiagnostic> diagnostics,
|
||||
I18nService i18n,
|
||||
ThemeService theme) {
|
||||
new AssetDiagnosticsDialog(owner, projectReference, assetName, diagnostics, i18n, theme).stage.showAndWait();
|
||||
}
|
||||
|
||||
private VBox buildRoot() {
|
||||
final Label title = new Label(i18n.text(I18n.ASSETS_DIAGNOSTICS_DIALOG_TITLE));
|
||||
title.getStyleClass().add("studio-launcher-section-title");
|
||||
|
||||
final Label subtitle = new Label(i18n.format(
|
||||
I18n.ASSETS_DIAGNOSTICS_DIALOG_SUMMARY,
|
||||
diagnostics.size(),
|
||||
assetName));
|
||||
subtitle.getStyleClass().add("studio-launcher-subtitle");
|
||||
subtitle.setWrapText(true);
|
||||
|
||||
diagnosticsContent.getStyleClass().add("assets-diagnostics-dialog-content");
|
||||
|
||||
final ScrollPane scrollPane = new ScrollPane(diagnosticsContent);
|
||||
scrollPane.setFitToWidth(true);
|
||||
scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
|
||||
scrollPane.getStyleClass().add("assets-diagnostics-dialog-scroll");
|
||||
|
||||
groupList.getStyleClass().add("assets-diagnostics-dialog-groups");
|
||||
final ScrollPane groupScroll = new ScrollPane(groupList);
|
||||
groupScroll.setFitToWidth(true);
|
||||
groupScroll.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
|
||||
groupScroll.getStyleClass().add("assets-diagnostics-dialog-groups-scroll");
|
||||
|
||||
final HBox browser = new HBox(16, groupScroll, scrollPane);
|
||||
browser.getStyleClass().add("assets-diagnostics-dialog-browser");
|
||||
HBox.setHgrow(scrollPane, Priority.ALWAYS);
|
||||
renderGroups();
|
||||
renderSelectedGroup();
|
||||
|
||||
final Button closeButton = new Button();
|
||||
closeButton.textProperty().bind(i18n.bind(I18n.WIZARD_CANCEL));
|
||||
closeButton.getStyleClass().addAll("studio-button", "studio-button-cancel");
|
||||
closeButton.setOnAction(ignored -> stage.close());
|
||||
|
||||
final HBox actions = new HBox(closeButton);
|
||||
actions.setAlignment(Pos.CENTER_RIGHT);
|
||||
|
||||
final VBox root = new VBox(16, title, subtitle, browser, actions);
|
||||
root.setPadding(new Insets(24));
|
||||
VBox.setVgrow(browser, Priority.ALWAYS);
|
||||
return root;
|
||||
}
|
||||
|
||||
private void renderGroups() {
|
||||
groupList.getChildren().clear();
|
||||
if (diagnosticsByGroup.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
for (DiagnosticGroup group : diagnosticsByGroup.values()) {
|
||||
final Button button = new Button(group.title() + " (" + group.diagnostics().size() + ")");
|
||||
button.getStyleClass().addAll("assets-diagnostics-dialog-group-button");
|
||||
if (Objects.equals(selectedGroupKey, group.key())) {
|
||||
button.getStyleClass().add("assets-diagnostics-dialog-group-button-selected");
|
||||
}
|
||||
button.setMaxWidth(Double.MAX_VALUE);
|
||||
button.setAlignment(Pos.CENTER_LEFT);
|
||||
button.setOnAction(ignored -> {
|
||||
selectedGroupKey = group.key();
|
||||
renderGroups();
|
||||
renderSelectedGroup();
|
||||
});
|
||||
groupList.getChildren().add(button);
|
||||
}
|
||||
}
|
||||
|
||||
private void renderSelectedGroup() {
|
||||
diagnosticsContent.getChildren().clear();
|
||||
final DiagnosticGroup group = diagnosticsByGroup.get(selectedGroupKey);
|
||||
if (group == null || group.diagnostics().isEmpty()) {
|
||||
diagnosticsContent.getChildren().add(AssetDetailsUiSupport.createSectionMessage(
|
||||
i18n.text(I18n.ASSETS_DIAGNOSTICS_EMPTY)));
|
||||
return;
|
||||
}
|
||||
|
||||
final Label groupTitle = new Label(group.title());
|
||||
groupTitle.getStyleClass().add("assets-diagnostics-dialog-group-title");
|
||||
diagnosticsContent.getChildren().add(groupTitle);
|
||||
group.diagnostics().forEach(diagnostic -> diagnosticsContent.getChildren().add(createDiagnosticCard(diagnostic)));
|
||||
}
|
||||
|
||||
private VBox createDiagnosticCard(AssetDiagnostic diagnostic) {
|
||||
final Label severity = new Label(severityLabel(diagnostic));
|
||||
severity.getStyleClass().add("assets-details-diagnostic-severity");
|
||||
|
||||
final Label message = new Label(diagnostic.message());
|
||||
message.getStyleClass().add("assets-details-diagnostic-message");
|
||||
message.setWrapText(true);
|
||||
|
||||
final VBox card = new VBox(8, severity, message);
|
||||
card.getStyleClass().addAll("assets-details-diagnostic-card", severityToneClass(diagnostic.severity()));
|
||||
|
||||
card.getChildren().add(AssetDetailsUiSupport.createKeyValueRow(
|
||||
i18n.text(I18n.ASSETS_DIAGNOSTICS_LABEL_CATEGORY),
|
||||
diagnostic.category()));
|
||||
card.getChildren().add(AssetDetailsUiSupport.createKeyValueRow(
|
||||
i18n.text(I18n.ASSETS_DIAGNOSTICS_LABEL_BLOCKING),
|
||||
AssetDetailsUiSupport.booleanLabel(i18n, diagnostic.blocking())));
|
||||
card.getChildren().add(AssetDetailsUiSupport.createKeyValueRow(
|
||||
i18n.text(I18n.ASSETS_DIAGNOSTICS_LABEL_EVIDENCE),
|
||||
evidenceLabel(diagnostic.evidencePath())));
|
||||
return card;
|
||||
}
|
||||
|
||||
private String severityLabel(AssetDiagnostic diagnostic) {
|
||||
return diagnostic.blocking()
|
||||
? diagnostic.severity() + " / BLOCKING"
|
||||
: diagnostic.severity();
|
||||
}
|
||||
|
||||
private String severityToneClass(String severity) {
|
||||
return switch (severity) {
|
||||
case "ERROR" -> "assets-details-diagnostic-blocker";
|
||||
case "WARNING" -> "assets-details-diagnostic-warning";
|
||||
default -> "assets-details-diagnostic-hint";
|
||||
};
|
||||
}
|
||||
|
||||
private String evidenceLabel(Path evidencePath) {
|
||||
if (evidencePath == null) {
|
||||
return "—";
|
||||
}
|
||||
return AssetDetailsUiSupport.projectRelativePath(projectReference, evidencePath);
|
||||
}
|
||||
|
||||
private Map<String, DiagnosticGroup> buildGroups(List<AssetDiagnostic> diagnostics) {
|
||||
final Map<String, DiagnosticGroup> grouped = new LinkedHashMap<>();
|
||||
for (AssetDiagnostic diagnostic : diagnostics) {
|
||||
final String key = groupKey(diagnostic.evidencePath());
|
||||
final String title = groupTitle(key, diagnostic.evidencePath());
|
||||
grouped.computeIfAbsent(key, ignored -> new DiagnosticGroup(key, title, new java.util.ArrayList<>()))
|
||||
.diagnostics()
|
||||
.add(diagnostic);
|
||||
}
|
||||
final Map<String, DiagnosticGroup> ordered = new LinkedHashMap<>();
|
||||
ordered.put(GENERAL_GROUP_KEY, grouped.getOrDefault(
|
||||
GENERAL_GROUP_KEY,
|
||||
new DiagnosticGroup(GENERAL_GROUP_KEY, "General", new java.util.ArrayList<>())));
|
||||
for (Map.Entry<String, DiagnosticGroup> entry : grouped.entrySet()) {
|
||||
if (!GENERAL_GROUP_KEY.equals(entry.getKey())) {
|
||||
ordered.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
return ordered.entrySet().stream()
|
||||
.filter(entry -> !entry.getValue().diagnostics().isEmpty() || GENERAL_GROUP_KEY.equals(entry.getKey()))
|
||||
.collect(java.util.stream.Collectors.toMap(
|
||||
Map.Entry::getKey,
|
||||
Map.Entry::getValue,
|
||||
(left, right) -> left,
|
||||
LinkedHashMap::new));
|
||||
}
|
||||
|
||||
private String groupKey(Path evidencePath) {
|
||||
if (evidencePath == null) {
|
||||
return GENERAL_GROUP_KEY;
|
||||
}
|
||||
final String relativePath = AssetDetailsUiSupport.projectRelativePath(projectReference, evidencePath);
|
||||
if (relativePath.endsWith("/asset.json") || relativePath.equals("asset.json")) {
|
||||
return GENERAL_GROUP_KEY;
|
||||
}
|
||||
return relativePath;
|
||||
}
|
||||
|
||||
private String groupTitle(String key, Path evidencePath) {
|
||||
if (GENERAL_GROUP_KEY.equals(key)) {
|
||||
return "General";
|
||||
}
|
||||
if (evidencePath == null) {
|
||||
return "General";
|
||||
}
|
||||
return evidencePath.getFileName() == null ? key : evidencePath.getFileName().toString();
|
||||
}
|
||||
|
||||
private record DiagnosticGroup(
|
||||
String key,
|
||||
String title,
|
||||
List<AssetDiagnostic> diagnostics) {
|
||||
}
|
||||
}
|
||||
+310
@@ -0,0 +1,310 @@
|
||||
package p.studio.ui.javafx.workspaces.assets.list;
|
||||
|
||||
import p.studio.api.assets.workspace.*;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.ScrollPane;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.control.ToggleButton;
|
||||
import javafx.scene.layout.FlowPane;
|
||||
import javafx.scene.layout.Priority;
|
||||
import javafx.scene.layout.VBox;
|
||||
import p.studio.api.assets.AssetCatalog;
|
||||
import p.studio.api.assets.AssetReference;
|
||||
import p.studio.api.assets.AssetSummary;
|
||||
import p.studio.ui.javafx.events.StudioWorkspaceEventBus;
|
||||
import p.studio.api.project.ProjectReference;
|
||||
import p.studio.ui.javafx.utilities.i18n.I18n;
|
||||
import p.studio.ui.javafx.utilities.i18n.I18nService;
|
||||
import p.studio.ui.javafx.workspaces.assets.AssetWorkspaceState;
|
||||
import p.studio.ui.javafx.workspaces.assets.details.AssetListMappings;
|
||||
import p.studio.ui.javafx.workspaces.assets.messages.*;
|
||||
import p.studio.ui.javafx.workspaces.assets.messages.events.*;
|
||||
import p.studio.ui.javafx.workspaces.framework.StudioEventAware;
|
||||
import p.studio.ui.javafx.workspaces.framework.StudioEventBindings;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
public final class AssetListControl extends VBox implements StudioEventAware {
|
||||
private final ProjectReference projectReference;
|
||||
private final StudioWorkspaceEventBus workspaceBus;
|
||||
private final StudioEventBindings eventBindings = new StudioEventBindings();
|
||||
private final VBox navigatorContent = new VBox(8);
|
||||
private final TextField searchField = new TextField();
|
||||
private final ToggleButton unregisteredFilterButton = new ToggleButton();
|
||||
private final ToggleButton diagnosticsFilterButton = new ToggleButton();
|
||||
private final ToggleButton preloadFilterButton = new ToggleButton();
|
||||
private final AtomicLong refreshGeneration = new AtomicLong();
|
||||
|
||||
private AssetListViewState viewState;
|
||||
private final java.util.concurrent.Executor executor;
|
||||
private final I18nService i18n;
|
||||
private final AssetCatalog assetCatalog;
|
||||
|
||||
public AssetListControl(
|
||||
ProjectReference projectReference,
|
||||
StudioWorkspaceEventBus workspaceBus,
|
||||
I18nService i18n,
|
||||
java.util.concurrent.Executor executor,
|
||||
AssetCatalog assetCatalog) {
|
||||
this.projectReference = Objects.requireNonNull(projectReference, "projectReference");
|
||||
this.workspaceBus = Objects.requireNonNull(workspaceBus, "workspaceBus");
|
||||
this.i18n = Objects.requireNonNull(i18n, "i18n");
|
||||
this.executor = Objects.requireNonNull(executor, "executor");
|
||||
this.assetCatalog = Objects.requireNonNull(assetCatalog, "assetCatalog");
|
||||
this.viewState = new AssetListViewState(AssetWorkspaceState.loading(null), null,
|
||||
this.i18n.text(I18n.ASSETS_STATE_LOADING));
|
||||
|
||||
getStyleClass().add("assets-workspace-pane");
|
||||
setSpacing(8);
|
||||
navigatorContent.getStyleClass().add("assets-workspace-navigator-content");
|
||||
getChildren().addAll(
|
||||
createNavigatorTitle(),
|
||||
createSearchField(),
|
||||
createFilterBar(),
|
||||
createNavigatorScroll());
|
||||
installProjectionInputs();
|
||||
render();
|
||||
}
|
||||
|
||||
@Override
|
||||
public StudioEventBindings eventBindings() {
|
||||
return eventBindings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerEventSubscriptions() {
|
||||
eventBindings.listen(workspaceBus, StudioAssetsRefreshRequestedEvent.class).handle(event -> {
|
||||
requestRefresh(event.preferredAssetReference(), event.deepSync());
|
||||
});
|
||||
eventBindings.listen(workspaceBus, StudioAssetsNavigatorViewStateChangedEvent.class).handle(event -> {
|
||||
viewState = event.viewState();
|
||||
render();
|
||||
});
|
||||
}
|
||||
|
||||
private Label createNavigatorTitle() {
|
||||
final var navigatorTitle = new Label();
|
||||
navigatorTitle.textProperty().bind(i18n.bind(I18n.ASSETS_NAVIGATOR_TITLE));
|
||||
navigatorTitle.getStyleClass().add("assets-workspace-pane-title");
|
||||
return navigatorTitle;
|
||||
}
|
||||
|
||||
private TextField createSearchField() {
|
||||
searchField.setPromptText(i18n.text(I18n.ASSETS_SEARCH_PROMPT));
|
||||
searchField.getStyleClass().add("assets-workspace-search");
|
||||
return searchField;
|
||||
}
|
||||
|
||||
private FlowPane createFilterBar() {
|
||||
final var filterBar = new FlowPane();
|
||||
filterBar.setHgap(6);
|
||||
filterBar.setVgap(6);
|
||||
filterBar.setPadding(new Insets(4, 0, 4, 0));
|
||||
filterBar.getStyleClass().add("assets-workspace-filter-bar");
|
||||
filterBar.getChildren().addAll(
|
||||
configureFilterButton(unregisteredFilterButton, I18n.ASSETS_FILTER_UNREGISTERED),
|
||||
configureFilterButton(diagnosticsFilterButton, I18n.ASSETS_FILTER_DIAGNOSTICS),
|
||||
configureFilterButton(preloadFilterButton, I18n.ASSETS_FILTER_PRELOAD));
|
||||
return filterBar;
|
||||
}
|
||||
|
||||
private ToggleButton configureFilterButton(ToggleButton button, I18n i18n) {
|
||||
button.textProperty().bind(this.i18n.bind(i18n));
|
||||
button.getStyleClass().addAll("studio-button", "studio-button-secondary", "studio-button-pill", "studio-button-toggle");
|
||||
return button;
|
||||
}
|
||||
|
||||
private ScrollPane createNavigatorScroll() {
|
||||
final var navigatorScroll = new ScrollPane(navigatorContent);
|
||||
navigatorScroll.setFitToWidth(true);
|
||||
navigatorScroll.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
|
||||
navigatorScroll.getStyleClass().add("assets-workspace-navigator-scroll");
|
||||
VBox.setVgrow(navigatorScroll, Priority.ALWAYS);
|
||||
return navigatorScroll;
|
||||
}
|
||||
|
||||
private void installProjectionInputs() {
|
||||
searchField.textProperty().addListener((ignored, oldValue, newValue) -> rebuildProjection());
|
||||
unregisteredFilterButton.setOnAction(ignored -> rebuildProjection());
|
||||
diagnosticsFilterButton.setOnAction(ignored -> rebuildProjection());
|
||||
preloadFilterButton.setOnAction(ignored -> rebuildProjection());
|
||||
}
|
||||
|
||||
private void requestRefresh(AssetReference preferredAssetReference, boolean deepSync) {
|
||||
if (!Platform.isFxApplicationThread()) {
|
||||
Platform.runLater(() -> requestRefresh(preferredAssetReference, deepSync));
|
||||
return;
|
||||
}
|
||||
|
||||
final AssetWorkspaceState previousState = viewState.workspaceState();
|
||||
final AssetReference assetReference = preferredAssetReference != null
|
||||
? preferredAssetReference
|
||||
: previousState.selectedAssetReference();
|
||||
final long generation = refreshGeneration.incrementAndGet();
|
||||
|
||||
publishNavigatorViewState(new AssetListViewState(
|
||||
AssetWorkspaceState.loading(previousState),
|
||||
null,
|
||||
i18n.text(I18n.ASSETS_STATE_LOADING)));
|
||||
workspaceBus.publish(new StudioAssetsWorkspaceRefreshStartedEvent());
|
||||
|
||||
executor.execute(() -> loadAssets(generation, assetReference, deepSync));
|
||||
}
|
||||
|
||||
private void loadAssets(
|
||||
long generation,
|
||||
AssetReference preferredAssetReference,
|
||||
boolean deepSync) {
|
||||
try {
|
||||
final List<AssetWorkspaceAssetSummary> assets = assetCatalog.list(projectReference, deepSync).stream()
|
||||
.map(this::mapAsset)
|
||||
.toList();
|
||||
final AssetWorkspaceState workspaceState = AssetWorkspaceState.ready(assets, preferredAssetReference);
|
||||
Platform.runLater(() -> applyRefreshResult(generation, workspaceState));
|
||||
} catch (RuntimeException exception) {
|
||||
Platform.runLater(() -> applyRefreshFailure(generation, exception));
|
||||
}
|
||||
}
|
||||
|
||||
private void applyRefreshResult(long generation, AssetWorkspaceState workspaceState) {
|
||||
if (generation != refreshGeneration.get()) {
|
||||
return;
|
||||
}
|
||||
final AssetListProjection projection = AssetListProjectionBuilder.build(
|
||||
workspaceState.assets(),
|
||||
projectReference.rootPath(),
|
||||
searchField.getText(),
|
||||
currentFilters());
|
||||
final AssetListViewState nextViewState = new AssetListViewState(
|
||||
workspaceState,
|
||||
projection,
|
||||
buildViewMessage(workspaceState, projection));
|
||||
publishNavigatorViewState(nextViewState);
|
||||
workspaceBus.publish(new StudioAssetsWorkspaceRefreshedEvent(
|
||||
nextViewState.workspaceState().assets().size()));
|
||||
}
|
||||
|
||||
private void applyRefreshFailure(long generation, RuntimeException exception) {
|
||||
if (generation != refreshGeneration.get()) {
|
||||
return;
|
||||
}
|
||||
final String message = i18n.text(I18n.ASSETS_STATE_ERROR);
|
||||
publishNavigatorViewState(new AssetListViewState(
|
||||
AssetWorkspaceState.error(viewState.workspaceState(), message),
|
||||
viewState.projection(),
|
||||
message));
|
||||
workspaceBus.publish(new StudioAssetsWorkspaceRefreshFailedEvent(message));
|
||||
}
|
||||
|
||||
private void rebuildProjection() {
|
||||
if (!Platform.isFxApplicationThread()) {
|
||||
Platform.runLater(this::rebuildProjection);
|
||||
return;
|
||||
}
|
||||
final AssetWorkspaceState workspaceState = viewState.workspaceState();
|
||||
if (workspaceState.status() == AssetWorkspaceStatus.LOADING || workspaceState.status() == AssetWorkspaceStatus.ERROR) {
|
||||
return;
|
||||
}
|
||||
|
||||
final AssetListProjection projection = AssetListProjectionBuilder.build(
|
||||
workspaceState.assets(),
|
||||
projectReference.rootPath(),
|
||||
searchField.getText(),
|
||||
currentFilters());
|
||||
publishNavigatorViewState(new AssetListViewState(
|
||||
workspaceState,
|
||||
projection,
|
||||
buildViewMessage(workspaceState, projection)));
|
||||
}
|
||||
|
||||
private void publishNavigatorViewState(AssetListViewState nextViewState) {
|
||||
viewState = Objects.requireNonNull(nextViewState, "nextViewState");
|
||||
workspaceBus.publish(new StudioAssetsNavigatorViewStateChangedEvent(nextViewState));
|
||||
}
|
||||
|
||||
private AssetWorkspaceAssetSummary mapAsset(AssetSummary summary) {
|
||||
return AssetListMappings.mapSummary(summary);
|
||||
}
|
||||
|
||||
private Set<AssetListFilter> currentFilters() {
|
||||
final EnumSet<AssetListFilter> filters = EnumSet.noneOf(AssetListFilter.class);
|
||||
if (unregisteredFilterButton.isSelected()) {
|
||||
filters.add(AssetListFilter.UNREGISTERED);
|
||||
}
|
||||
if (diagnosticsFilterButton.isSelected()) {
|
||||
filters.add(AssetListFilter.DIAGNOSTICS);
|
||||
}
|
||||
if (preloadFilterButton.isSelected()) {
|
||||
filters.add(AssetListFilter.PRELOAD);
|
||||
}
|
||||
return filters;
|
||||
}
|
||||
|
||||
private String buildViewMessage(AssetWorkspaceState workspaceState, AssetListProjection projection) {
|
||||
return switch (workspaceState.status()) {
|
||||
case LOADING -> i18n.text(I18n.ASSETS_STATE_LOADING);
|
||||
case EMPTY -> i18n.text(I18n.ASSETS_STATE_EMPTY);
|
||||
case ERROR -> workspaceState.errorMessage();
|
||||
case READY -> projection == null || projection.isEmpty()
|
||||
? i18n.text(I18n.ASSETS_STATE_NO_RESULTS)
|
||||
: i18n.text(I18n.ASSETS_STATE_READY);
|
||||
};
|
||||
}
|
||||
|
||||
private void render() {
|
||||
navigatorContent.getChildren().clear();
|
||||
final AssetWorkspaceStatus status = viewState.workspaceState().status();
|
||||
if (status == AssetWorkspaceStatus.LOADING) {
|
||||
navigatorContent.getChildren().setAll(createMessageNode(viewState.message()));
|
||||
return;
|
||||
}
|
||||
if (status == AssetWorkspaceStatus.ERROR) {
|
||||
navigatorContent.getChildren().setAll(createMessageNode(viewState.message()));
|
||||
return;
|
||||
}
|
||||
if (status == AssetWorkspaceStatus.EMPTY || !viewState.hasProjection()) {
|
||||
navigatorContent.getChildren().setAll(createMessageNode(viewState.message()));
|
||||
return;
|
||||
}
|
||||
|
||||
for (AssetListGroup group : viewState.projection().groups()) {
|
||||
final var groupBox = createGroupBox(group.label());
|
||||
for (AssetWorkspaceAssetSummary asset : group.assets()) {
|
||||
groupBox.getChildren().add(new AssetListItemControl(
|
||||
projectReference,
|
||||
workspaceBus,
|
||||
i18n,
|
||||
asset));
|
||||
}
|
||||
navigatorContent.getChildren().add(groupBox);
|
||||
}
|
||||
}
|
||||
|
||||
private VBox createGroupBox(String label) {
|
||||
final var groupBox = new VBox(6);
|
||||
groupBox.getStyleClass().add("assets-workspace-group");
|
||||
groupBox.getChildren().add(createGroupLabel(label));
|
||||
return groupBox;
|
||||
}
|
||||
|
||||
private Label createGroupLabel(String text) {
|
||||
final var groupLabel = new Label(text);
|
||||
groupLabel.getStyleClass().add("assets-workspace-group-label");
|
||||
return groupLabel;
|
||||
}
|
||||
|
||||
private Node createMessageNode(String text) {
|
||||
final var label = new Label(text);
|
||||
label.getStyleClass().add("assets-workspace-empty-state");
|
||||
label.setWrapText(true);
|
||||
return label;
|
||||
}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package p.studio.ui.javafx.workspaces.assets.list;
|
||||
|
||||
public enum AssetListFilter {
|
||||
UNREGISTERED,
|
||||
DIAGNOSTICS,
|
||||
PRELOAD
|
||||
}
|
||||
+133
@@ -0,0 +1,133 @@
|
||||
package p.studio.ui.javafx.workspaces.assets.list;
|
||||
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.Priority;
|
||||
import javafx.scene.layout.Region;
|
||||
import javafx.scene.layout.VBox;
|
||||
import p.studio.api.assets.AssetFamily;
|
||||
import p.studio.ui.javafx.events.StudioWorkspaceEventBus;
|
||||
import p.studio.api.project.ProjectReference;
|
||||
import p.studio.ui.javafx.utilities.i18n.I18n;
|
||||
import p.studio.ui.javafx.utilities.i18n.I18nService;
|
||||
import p.studio.api.assets.workspace.AssetWorkspaceAssetState;
|
||||
import p.studio.api.assets.workspace.AssetWorkspaceAssetSummary;
|
||||
import p.studio.api.assets.workspace.AssetWorkspaceBuildParticipation;
|
||||
import p.studio.ui.javafx.workspaces.assets.messages.events.StudioAssetsWorkspaceSelectionRequestedEvent;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.Objects;
|
||||
|
||||
public final class AssetListItemControl extends VBox {
|
||||
private final ProjectReference projectReference;
|
||||
private final Path projectRoot;
|
||||
private final StudioWorkspaceEventBus workspaceBus;
|
||||
private final I18nService i18n;
|
||||
|
||||
private AssetWorkspaceAssetSummary summary;
|
||||
|
||||
public AssetListItemControl(
|
||||
ProjectReference projectReference,
|
||||
StudioWorkspaceEventBus workspaceBus,
|
||||
I18nService i18n,
|
||||
AssetWorkspaceAssetSummary summary) {
|
||||
this.projectReference = Objects.requireNonNull(projectReference, "projectReference");
|
||||
this.projectRoot = this.projectReference.rootPath();
|
||||
this.workspaceBus = Objects.requireNonNull(workspaceBus, "workspaceBus");
|
||||
this.i18n = Objects.requireNonNull(i18n, "i18n");
|
||||
this.summary = Objects.requireNonNull(summary, "summary");
|
||||
render();
|
||||
}
|
||||
|
||||
private void render() {
|
||||
getChildren().clear();
|
||||
getStyleClass().setAll("assets-workspace-asset-row", assetRowToneClass(summary.assetFamily()));
|
||||
getChildren().setAll(createTopLine(), createPathLabel());
|
||||
setOnMouseClicked(event -> workspaceBus.publish(
|
||||
new StudioAssetsWorkspaceSelectionRequestedEvent(summary.assetReference(), false)));
|
||||
}
|
||||
|
||||
private HBox createTopLine() {
|
||||
final var topLine = new HBox(8);
|
||||
topLine.setAlignment(Pos.CENTER_LEFT);
|
||||
topLine.getChildren().addAll(
|
||||
createNameLabel(),
|
||||
createSpacer(),
|
||||
createBadgesBox());
|
||||
return topLine;
|
||||
}
|
||||
|
||||
private Label createNameLabel() {
|
||||
final var name = new Label(summary.assetName());
|
||||
name.getStyleClass().addAll("assets-workspace-asset-name", assetNameToneClass(summary.assetFamily()));
|
||||
return name;
|
||||
}
|
||||
|
||||
private Region createSpacer() {
|
||||
final var spacer = new Region();
|
||||
HBox.setHgrow(spacer, Priority.ALWAYS);
|
||||
return spacer;
|
||||
}
|
||||
|
||||
private HBox createBadgesBox() {
|
||||
final var badges = new HBox(6);
|
||||
badges.setAlignment(Pos.CENTER_RIGHT);
|
||||
badges.getStyleClass().add("assets-workspace-asset-badges");
|
||||
populateBadges(badges);
|
||||
return badges;
|
||||
}
|
||||
|
||||
private Label createPathLabel() {
|
||||
final var path = new Label(AssetListProjectionBuilder.relativeRoot(summary, projectRoot));
|
||||
path.getStyleClass().add("assets-workspace-asset-path");
|
||||
return path;
|
||||
}
|
||||
|
||||
private void populateBadges(HBox badges) {
|
||||
if (summary.state() == AssetWorkspaceAssetState.UNREGISTERED) {
|
||||
badges.getChildren().add(createBadge(i18n.text(I18n.ASSETS_BADGE_UNREGISTERED), "assets-workspace-badge-orphan"));
|
||||
} else if (summary.buildParticipation() == AssetWorkspaceBuildParticipation.INCLUDED) {
|
||||
badges.getChildren().add(createBadge(buildParticipationLabel(summary.buildParticipation()), "assets-workspace-badge-preload"));
|
||||
if (summary.preload()) {
|
||||
badges.getChildren().add(createBadge(i18n.text(I18n.ASSETS_BADGE_PRELOAD), "assets-workspace-badge-preload"));
|
||||
}
|
||||
} else {
|
||||
badges.getChildren().add(createBadge(buildParticipationLabel(summary.buildParticipation()), "assets-workspace-badge-diagnostics"));
|
||||
}
|
||||
if (summary.hasDiagnostics()) {
|
||||
badges.getChildren().add(createBadge(i18n.text(I18n.ASSETS_BADGE_DIAGNOSTICS), "assets-workspace-badge-diagnostics"));
|
||||
}
|
||||
}
|
||||
|
||||
private Label createBadge(String text, String styleClass) {
|
||||
final Label badge = new Label(text);
|
||||
badge.getStyleClass().addAll("assets-workspace-badge", styleClass);
|
||||
return badge;
|
||||
}
|
||||
|
||||
private String buildParticipationLabel(AssetWorkspaceBuildParticipation buildParticipation) {
|
||||
return switch (buildParticipation) {
|
||||
case INCLUDED -> i18n.text(I18n.ASSETS_VALUE_INCLUDED);
|
||||
case EXCLUDED -> i18n.text(I18n.ASSETS_VALUE_EXCLUDED);
|
||||
};
|
||||
}
|
||||
|
||||
private String assetRowToneClass(AssetFamily assetFamily) {
|
||||
return switch (assetFamily) {
|
||||
case GLYPH_BANK -> "assets-workspace-asset-row-tone-image";
|
||||
case SCENE_BANK -> "assets-workspace-asset-row-tone-scene";
|
||||
case SOUND_BANK -> "assets-workspace-asset-row-tone-audio";
|
||||
default -> "assets-workspace-asset-row-tone-generic";
|
||||
};
|
||||
}
|
||||
|
||||
private String assetNameToneClass(AssetFamily assetFamily) {
|
||||
return switch (assetFamily) {
|
||||
case GLYPH_BANK -> "assets-workspace-asset-name-tone-image";
|
||||
case SCENE_BANK -> "assets-workspace-asset-name-tone-scene";
|
||||
case SOUND_BANK -> "assets-workspace-asset-name-tone-audio";
|
||||
default -> "assets-workspace-asset-name-tone-generic";
|
||||
};
|
||||
}
|
||||
}
|
||||
+99
@@ -0,0 +1,99 @@
|
||||
package p.studio.ui.javafx.workspaces.assets.list;
|
||||
|
||||
import p.studio.ui.javafx.workspaces.assets.messages.AssetListGroup;
|
||||
import p.studio.ui.javafx.workspaces.assets.messages.AssetListProjection;
|
||||
import p.studio.api.assets.workspace.AssetWorkspaceAssetState;
|
||||
import p.studio.api.assets.workspace.AssetWorkspaceAssetSummary;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
|
||||
public final class AssetListProjectionBuilder {
|
||||
private AssetListProjectionBuilder() {
|
||||
}
|
||||
|
||||
public static AssetListProjection build(
|
||||
List<AssetWorkspaceAssetSummary> assets,
|
||||
Path projectRoot,
|
||||
String searchQuery,
|
||||
Set<AssetListFilter> filters) {
|
||||
Objects.requireNonNull(assets, "assets");
|
||||
final Path normalizedProjectRoot = Objects.requireNonNull(projectRoot, "projectRoot").toAbsolutePath().normalize();
|
||||
final String normalizedQuery = normalizeQuery(searchQuery);
|
||||
final Set<AssetListFilter> normalizedFilters = filters == null || filters.isEmpty()
|
||||
? EnumSet.noneOf(AssetListFilter.class)
|
||||
: EnumSet.copyOf(filters);
|
||||
|
||||
final Map<String, List<AssetWorkspaceAssetSummary>> grouped = new LinkedHashMap<>();
|
||||
for (AssetWorkspaceAssetSummary asset : assets) {
|
||||
if (!matchesFilters(asset, normalizedFilters) || !matchesQuery(asset, normalizedProjectRoot, normalizedQuery)) {
|
||||
continue;
|
||||
}
|
||||
grouped.computeIfAbsent(groupLabel(asset, normalizedProjectRoot), ignored -> new ArrayList<>())
|
||||
.add(asset);
|
||||
}
|
||||
|
||||
final List<AssetListGroup> groups = grouped.entrySet().stream()
|
||||
.map(entry -> new AssetListGroup(entry.getKey(), entry.getValue()))
|
||||
.toList();
|
||||
final int visibleAssetCount = groups.stream().mapToInt(group -> group.assets().size()).sum();
|
||||
return new AssetListProjection(groups, visibleAssetCount);
|
||||
}
|
||||
|
||||
public static String relativeRoot(AssetWorkspaceAssetSummary asset, Path projectRoot) {
|
||||
return relativize(asset.assetRoot(), projectRoot).toString().replace('\\', '/');
|
||||
}
|
||||
|
||||
private static boolean matchesFilters(AssetWorkspaceAssetSummary asset, Set<AssetListFilter> filters) {
|
||||
if (filters.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
final boolean includeUnregistered = filters.contains(AssetListFilter.UNREGISTERED);
|
||||
if (includeUnregistered) {
|
||||
final boolean stateMatches = asset.state() == AssetWorkspaceAssetState.UNREGISTERED;
|
||||
if (!stateMatches) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (filters.contains(AssetListFilter.DIAGNOSTICS) && !asset.hasDiagnostics()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (filters.contains(AssetListFilter.PRELOAD) && !asset.preload()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean matchesQuery(AssetWorkspaceAssetSummary asset, Path projectRoot, String normalizedQuery) {
|
||||
if (normalizedQuery.isBlank()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
final String relativeRoot = relativeRoot(asset, projectRoot);
|
||||
return asset.assetName().toLowerCase(Locale.ROOT).contains(normalizedQuery)
|
||||
|| asset.assetFamily().matchesQuery(normalizedQuery)
|
||||
|| relativeRoot.toLowerCase(Locale.ROOT).contains(normalizedQuery);
|
||||
}
|
||||
|
||||
private static String groupLabel(AssetWorkspaceAssetSummary asset, Path projectRoot) {
|
||||
final Path relativeRoot = relativize(asset.assetRoot(), projectRoot);
|
||||
final Path parent = relativeRoot.getParent();
|
||||
return Objects.requireNonNullElse(parent, relativeRoot).toString().replace('\\', '/');
|
||||
}
|
||||
|
||||
private static Path relativize(Path assetRoot, Path projectRoot) {
|
||||
try {
|
||||
return projectRoot.relativize(assetRoot.toAbsolutePath().normalize());
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
return assetRoot.getFileName();
|
||||
}
|
||||
}
|
||||
|
||||
private static String normalizeQuery(String query) {
|
||||
return query == null ? "" : query.trim().toLowerCase(Locale.ROOT);
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package p.studio.ui.javafx.workspaces.assets.messages;
|
||||
|
||||
import p.studio.api.assets.workspace.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public record AssetListGroup(String label, List<AssetWorkspaceAssetSummary> assets) {
|
||||
public AssetListGroup {
|
||||
label = Objects.requireNonNull(label, "label").trim();
|
||||
assets = List.copyOf(Objects.requireNonNull(assets, "assets"));
|
||||
if (label.isBlank()) {
|
||||
throw new IllegalArgumentException("group label must not be blank");
|
||||
}
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package p.studio.ui.javafx.workspaces.assets.messages;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public record AssetListProjection(List<AssetListGroup> groups, int visibleAssetCount) {
|
||||
public AssetListProjection {
|
||||
groups = List.copyOf(Objects.requireNonNull(groups, "groups"));
|
||||
if (visibleAssetCount < 0) {
|
||||
throw new IllegalArgumentException("visibleAssetCount must not be negative");
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return visibleAssetCount == 0;
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
package p.studio.ui.javafx.workspaces.assets.messages;
|
||||
|
||||
import p.studio.ui.javafx.workspaces.assets.AssetWorkspaceState;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public record AssetListViewState(
|
||||
AssetWorkspaceState workspaceState,
|
||||
AssetListProjection projection,
|
||||
String message) {
|
||||
|
||||
public AssetListViewState {
|
||||
Objects.requireNonNull(workspaceState, "workspaceState");
|
||||
Objects.requireNonNull(message, "message");
|
||||
}
|
||||
|
||||
public boolean hasProjection() {
|
||||
return projection != null && !projection.isEmpty();
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package p.studio.ui.javafx.workspaces.assets.messages;
|
||||
|
||||
public enum AssetWorkspaceDetailsStatus {
|
||||
EMPTY,
|
||||
LOADING,
|
||||
READY,
|
||||
ERROR
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package p.studio.ui.javafx.workspaces.assets.messages;
|
||||
|
||||
import p.studio.api.assets.workspace.*;
|
||||
|
||||
import p.studio.api.assets.AssetReference;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public record AssetWorkspaceDetailsViewState(
|
||||
AssetWorkspaceDetailsStatus detailsStatus,
|
||||
AssetReference selectedAssetReference,
|
||||
AssetWorkspaceAssetDetails selectedAssetDetails,
|
||||
String detailsErrorMessage) {
|
||||
|
||||
public AssetWorkspaceDetailsViewState {
|
||||
Objects.requireNonNull(detailsStatus, "detailsStatus");
|
||||
}
|
||||
|
||||
public AssetWorkspaceDetailsViewState withSelectedAssetReference(AssetWorkspaceAssetDetails selectedAssetDetails) {
|
||||
return new AssetWorkspaceDetailsViewState(detailsStatus, selectedAssetReference, selectedAssetDetails, detailsErrorMessage);
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package p.studio.ui.javafx.workspaces.assets.messages;
|
||||
|
||||
public enum AssetWorkspaceStatus {
|
||||
LOADING,
|
||||
READY,
|
||||
EMPTY,
|
||||
ERROR
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package p.studio.ui.javafx.workspaces.assets.messages.events;
|
||||
|
||||
import p.studio.api.assets.AssetReference;
|
||||
import p.studio.ui.javafx.events.StudioEvent;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public record StudioAssetBankCompositionAppliedEvent(
|
||||
AssetReference assetReference) implements StudioEvent {
|
||||
public StudioAssetBankCompositionAppliedEvent {
|
||||
Objects.requireNonNull(assetReference, "assetReference");
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package p.studio.ui.javafx.workspaces.assets.messages.events;
|
||||
|
||||
import p.studio.api.assets.AssetReference;
|
||||
import p.studio.ui.javafx.events.StudioEvent;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public record StudioAssetBankCompositionApplyFailedEvent(
|
||||
AssetReference assetReference,
|
||||
String message) implements StudioEvent {
|
||||
public StudioAssetBankCompositionApplyFailedEvent {
|
||||
Objects.requireNonNull(assetReference, "assetReference");
|
||||
message = Objects.requireNonNullElse(message, "");
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package p.studio.ui.javafx.workspaces.assets.messages.events;
|
||||
|
||||
import p.studio.api.assets.AssetReference;
|
||||
import p.studio.ui.javafx.events.StudioEvent;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public record StudioAssetBankCompositionApplyRequestedEvent(
|
||||
AssetReference assetReference) implements StudioEvent {
|
||||
public StudioAssetBankCompositionApplyRequestedEvent {
|
||||
Objects.requireNonNull(assetReference, "assetReference");
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package p.studio.ui.javafx.workspaces.assets.messages.events;
|
||||
|
||||
import p.studio.api.assets.AssetReference;
|
||||
import p.studio.ui.javafx.controls.banks.StudioAssetCapacitySeverity;
|
||||
import p.studio.ui.javafx.events.StudioEvent;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public record StudioAssetBankCompositionCapacityChangedEvent(
|
||||
AssetReference assetReference,
|
||||
double progress,
|
||||
StudioAssetCapacitySeverity severity,
|
||||
boolean blocked,
|
||||
String labelText,
|
||||
String hintText) implements StudioEvent {
|
||||
|
||||
public StudioAssetBankCompositionCapacityChangedEvent {
|
||||
Objects.requireNonNull(assetReference, "assetReference");
|
||||
severity = severity == null ? StudioAssetCapacitySeverity.GREEN : severity;
|
||||
if (progress < 0.0d || progress > 1.0d) {
|
||||
throw new IllegalArgumentException("progress must be in the 0..1 range");
|
||||
}
|
||||
labelText = Objects.requireNonNullElse(labelText, "");
|
||||
hintText = Objects.requireNonNullElse(hintText, "");
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package p.studio.ui.javafx.workspaces.assets.messages.events;
|
||||
|
||||
import p.studio.api.assets.AssetReference;
|
||||
import p.studio.ui.javafx.events.StudioEvent;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public record StudioAssetBankCompositionDraftChangedEvent(
|
||||
AssetReference assetReference,
|
||||
boolean editing,
|
||||
boolean dirty,
|
||||
int availableCount,
|
||||
int selectedCount) implements StudioEvent {
|
||||
|
||||
public StudioAssetBankCompositionDraftChangedEvent {
|
||||
Objects.requireNonNull(assetReference, "assetReference");
|
||||
if (availableCount < 0 || selectedCount < 0) {
|
||||
throw new IllegalArgumentException("counts must be non-negative");
|
||||
}
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package p.studio.ui.javafx.workspaces.assets.messages.events;
|
||||
|
||||
import p.studio.ui.javafx.events.StudioEvent;
|
||||
|
||||
public record StudioAssetLogEvent(
|
||||
String source,
|
||||
String message) implements StudioEvent {
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package p.studio.ui.javafx.workspaces.assets.messages.events;
|
||||
|
||||
import p.studio.ui.javafx.events.StudioEvent;
|
||||
import p.studio.ui.javafx.workspaces.assets.messages.AssetWorkspaceDetailsViewState;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public record StudioAssetsDetailsViewStateChangedEvent(
|
||||
AssetWorkspaceDetailsViewState viewState) implements StudioEvent {
|
||||
public StudioAssetsDetailsViewStateChangedEvent {
|
||||
Objects.requireNonNull(viewState, "viewState");
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package p.studio.ui.javafx.workspaces.assets.messages.events;
|
||||
|
||||
import p.studio.ui.javafx.events.StudioEvent;
|
||||
import p.studio.ui.javafx.workspaces.assets.messages.AssetListViewState;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public record StudioAssetsNavigatorViewStateChangedEvent(
|
||||
AssetListViewState viewState) implements StudioEvent {
|
||||
public StudioAssetsNavigatorViewStateChangedEvent {
|
||||
Objects.requireNonNull(viewState, "viewState");
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package p.studio.ui.javafx.workspaces.assets.messages.events;
|
||||
|
||||
import p.studio.api.assets.AssetReference;
|
||||
import p.studio.ui.javafx.events.StudioEvent;
|
||||
|
||||
public record StudioAssetsRefreshRequestedEvent(
|
||||
AssetReference preferredAssetReference,
|
||||
boolean deepSync) implements StudioEvent {
|
||||
public StudioAssetsRefreshRequestedEvent() {
|
||||
this(null, false);
|
||||
}
|
||||
|
||||
public StudioAssetsRefreshRequestedEvent(AssetReference preferredAssetReference) {
|
||||
this(preferredAssetReference, false);
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package p.studio.ui.javafx.workspaces.assets.messages.events;
|
||||
|
||||
import p.studio.ui.javafx.events.StudioEvent;
|
||||
import p.studio.ui.javafx.workspaces.assets.messages.AssetWorkspaceDetailsViewState;
|
||||
|
||||
public record StudioAssetsWorkspaceDetailsSceneLayerChangedEvent(
|
||||
AssetWorkspaceDetailsViewState viewState) implements StudioEvent {
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package p.studio.ui.javafx.workspaces.assets.messages.events;
|
||||
|
||||
import p.studio.ui.javafx.events.StudioEvent;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public record StudioAssetsWorkspaceRefreshFailedEvent(String message) implements StudioEvent {
|
||||
public StudioAssetsWorkspaceRefreshFailedEvent {
|
||||
Objects.requireNonNull(message, "message");
|
||||
}
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
package p.studio.ui.javafx.workspaces.assets.messages.events;
|
||||
|
||||
import p.studio.ui.javafx.events.StudioEvent;
|
||||
|
||||
public record StudioAssetsWorkspaceRefreshStartedEvent() implements StudioEvent {
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package p.studio.ui.javafx.workspaces.assets.messages.events;
|
||||
|
||||
import p.studio.ui.javafx.events.StudioEvent;
|
||||
|
||||
public record StudioAssetsWorkspaceRefreshedEvent(int assetCount) implements StudioEvent {
|
||||
public StudioAssetsWorkspaceRefreshedEvent {
|
||||
if (assetCount < 0) {
|
||||
throw new IllegalArgumentException("assetCount must not be negative");
|
||||
}
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package p.studio.ui.javafx.workspaces.assets.messages.events;
|
||||
|
||||
import p.studio.api.assets.AssetReference;
|
||||
import p.studio.ui.javafx.events.StudioEvent;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public record StudioAssetsWorkspaceSelectionRequestedEvent(
|
||||
AssetReference assetReference,
|
||||
boolean forceUpdate) implements StudioEvent {
|
||||
public StudioAssetsWorkspaceSelectionRequestedEvent {
|
||||
Objects.requireNonNull(assetReference, "assetReference");
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package p.studio.ui.javafx.workspaces.assets.messages.events;
|
||||
|
||||
import p.studio.api.assets.AssetReference;
|
||||
import p.studio.ui.javafx.events.StudioEvent;
|
||||
import p.studio.api.assets.workspace.AssetWorkspaceBankCompositionDetails;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public record StudioBankCompositionChangedEvent(
|
||||
AssetReference assetReference,
|
||||
AssetWorkspaceBankCompositionDetails bankComposition) implements StudioEvent {
|
||||
|
||||
public StudioBankCompositionChangedEvent {
|
||||
assetReference = Objects.requireNonNull(assetReference, "assetReference");
|
||||
bankComposition = Objects.requireNonNull(bankComposition, "bankComposition");
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user