Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 47 additions & 2 deletions HMCL/src/main/java/org/jackhuang/hmcl/setting/StyleSheets.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,25 @@
*/
package org.jackhuang.hmcl.setting;

import com.jfoenix.transitions.CachedTransition;
import javafx.animation.KeyFrame;
import javafx.animation.KeyValue;
import javafx.animation.Timeline;
import javafx.animation.Transition;
import javafx.beans.binding.Bindings;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.util.Duration;
import org.glavo.monetfx.Brightness;
import org.glavo.monetfx.ColorRole;
import org.glavo.monetfx.ColorScheme;
import org.jackhuang.hmcl.theme.ResolvedTheme;
import org.jackhuang.hmcl.theme.ThemeColor;
import org.jackhuang.hmcl.theme.Themes;
import org.jackhuang.hmcl.ui.Controllers;
import org.jackhuang.hmcl.ui.animation.Motion;

import java.nio.charset.StandardCharsets;
import java.util.Arrays;
Expand All @@ -54,9 +62,46 @@ public final class StyleSheets {
stylesheets = FXCollections.observableList(Arrays.asList(array));

FontManager.fontProperty().addListener(o -> stylesheets.set(FONT_STYLE_SHEET_INDEX, getFontStyleSheet()));

Transition animation;
if (!SettingsManager.settings().isAnimationDisabled()) {
var mask = Controllers.getDecorator().getMask();
animation = new CachedTransition(mask, new Timeline(
new KeyFrame(Duration.ZERO,
new KeyValue(mask.visibleProperty(), false, Motion.LINEAR)
),
new KeyFrame(Duration.millis(10),
new KeyValue(mask.visibleProperty(), true, Motion.LINEAR),
new KeyValue(mask.opacityProperty(), 0D, Motion.EMPHASIZED_DECELERATE)
),
new KeyFrame(Motion.LONG2,
new KeyValue(mask.visibleProperty(), true, Motion.LINEAR),
new KeyValue(mask.opacityProperty(), 1D, Motion.EMPHASIZED_DECELERATE)
))
) {
{
setCycleDuration(Motion.MEDIUM2);
setDelay(Duration.ZERO);
}
};
} else {
animation = null;
}
Themes.colorSchemeProperty().addListener(o -> {
stylesheets.set(THEME_STYLE_SHEET_INDEX, getThemeStyleSheet());
stylesheets.set(BRIGHTNESS_SHEET_INDEX, getBrightnessStyleSheet());
if (animation != null) {
animation.setRate(1D);
animation.setOnFinished(e -> {
stylesheets.set(THEME_STYLE_SHEET_INDEX, getThemeStyleSheet());
stylesheets.set(BRIGHTNESS_SHEET_INDEX, getBrightnessStyleSheet());
animation.setOnFinished(null);
animation.setRate(-1D);
animation.play();
});
animation.play();
} else {
stylesheets.set(THEME_STYLE_SHEET_INDEX, getThemeStyleSheet());
stylesheets.set(BRIGHTNESS_SHEET_INDEX, getBrightnessStyleSheet());
}
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@
import javafx.scene.input.KeyEvent;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill;
import javafx.scene.layout.Region;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.stage.Screen;
import javafx.stage.Stage;
Expand Down Expand Up @@ -330,6 +327,10 @@ public StackPane getDialogContainer() {
return mainWindowPane;
}

public Pane getMask() {
return mainWindowPane.getMask();
}

/// Returns the navigation stack rendered by the main window.
///
/// @return this decorator's navigator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ final class MainWindowPane extends StackPane {
/// The transition container used when the title-bar state changes.
private final TransitionPane navBarPane;

/// The mask layer that covers the stage when changing color scheme.
private final Pane mask;

/// Retains listener delegates that are registered through weak listener wrappers.
@SuppressWarnings("FieldCanBeLocal")
private final WeakListenerHolder holder = new WeakListenerHolder();
Expand Down Expand Up @@ -133,7 +136,17 @@ final class MainWindowPane extends StackPane {

decorator.capableDraggingWindow(titleBar);

getChildren().setAll(backgroundNode, frame);
mask = new StackPane();
mask.setBackground(new Background(new BackgroundFill(Color.gray(0.5D), null, null)));
mask.setVisible(false);
mask.setOpacity(0D);
mask.setPickOnBounds(false);

getChildren().setAll(backgroundNode, frame, mask);
}

public Pane getMask() {
return mask;
}

/// Updates the content-corner shape for an edge-to-edge window state.
Expand Down