Skip to content

Commit

Permalink
Add New Features
Browse files Browse the repository at this point in the history
  • Loading branch information
isHarryh committed Aug 4, 2023
1 parent 423c211 commit 8de6ff2
Show file tree
Hide file tree
Showing 4 changed files with 220 additions and 21 deletions.
25 changes: 13 additions & 12 deletions assets/UI/Homepage.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@
<Pane id="Search-models-bar" layoutX="15.0" layoutY="40.0" prefHeight="38.0" prefWidth="430.0">
<JFXTextField id="Search-models-input" fx:id="searchModelInput" layoutX="70.0" layoutY="6.0"
prefHeight="23.0" prefWidth="170.0"/>
<JFXButton fx:id="searchModelConfirm" layoutX="8.0" layoutY="5.0"
maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity"
mnemonicParsing="false" prefHeight="28.0" prefWidth="55.0" text="搜索">
<JFXButton fx:id="searchModelConfirm" layoutX="8.0" layoutY="5.0" maxHeight="-Infinity" maxWidth="-Infinity"
minHeight="-Infinity" minWidth="-Infinity" mnemonicParsing="false" prefHeight="28.0"
prefWidth="55.0" text="搜索">
<font>
<Font size="12.0"/>
</font>
Expand All @@ -149,9 +149,9 @@
<String fx:value="btn-with-icon"/>
</styleClass>
</JFXButton>
<JFXButton fx:id="searchModelReset" layoutX="248.0" layoutY="5.0"
maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity"
mnemonicParsing="false" prefHeight="28.0" prefWidth="55.0" text="清空">
<JFXButton fx:id="searchModelReset" layoutX="248.0" layoutY="5.0" maxHeight="-Infinity" maxWidth="-Infinity"
minHeight="-Infinity" minWidth="-Infinity" mnemonicParsing="false" prefHeight="28.0"
prefWidth="55.0" text="清空">
<font>
<Font size="12.0"/>
</font>
Expand All @@ -168,9 +168,9 @@
<String fx:value="btn-with-icon"/>
</styleClass>
</JFXButton>
<JFXButton fx:id="searchModelRandom" layoutX="308.0" layoutY="5.0"
maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity"
mnemonicParsing="false" prefHeight="28.0" prefWidth="55.0" text="随机">
<JFXButton fx:id="searchModelRandom" layoutX="308.0" layoutY="5.0" maxHeight="-Infinity"
maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" mnemonicParsing="false"
prefHeight="28.0" prefWidth="55.0" text="随机">
<font>
<Font size="12.0"/>
</font>
Expand All @@ -187,9 +187,9 @@
<String fx:value="btn-with-icon"/>
</styleClass>
</JFXButton>
<JFXButton fx:id="searchModelReload" layoutX="368.0" layoutY="5.0"
maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity"
mnemonicParsing="false" prefHeight="28.0" prefWidth="55.0" text="重载">
<JFXButton fx:id="searchModelReload" layoutX="368.0" layoutY="5.0" maxHeight="-Infinity"
maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" mnemonicParsing="false"
prefHeight="28.0" prefWidth="55.0" text="重载">
<font>
<Font size="12.0"/>
</font>
Expand Down Expand Up @@ -345,6 +345,7 @@
<children>
<VBox>
<children>
<VBox fx:id="noticeBox"/>
<Label styleClass="config-group-title" text="显示设置"/>
<HBox>
<children>
Expand Down
8 changes: 5 additions & 3 deletions core/src/cn/harryh/arkpets/Const.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ public final class Const {
public static final String desktopTitle = "ArkPets Launcher " + appVersion;

// IO presets
public static final int zipBufferSizeDefault = 8 * 1024;
public static final int httpBufferSizeDefault = 8 * 1024;
public static final int httpTimeoutDefault = 30 * 1000;
public static final int zipBufferSizeDefault = 8 * 1024;
public static final int httpBufferSizeDefault = 8 * 1024;
public static final int httpTimeoutDefault = 30 * 1000;
public static final long diskFreeSpaceRecommended = 1024 * 1024 * 1024L;

// Graphics presets
public static final int fpsDefault = 30;
Expand Down Expand Up @@ -65,6 +66,7 @@ public final class Const {
*/
public static class PathConfig {
public static final String urlApi = "https://arkpets.harryh.cn/p/arkpets/client/api.php";
public static final String urlDownload = "https://arkpets.harryh.cn/p/arkpets/?from=client#/download";
public static final String urlOfficial = "https://arkpets.harryh.cn/p/arkpets/?from=client";
public static final String urlReadme = "https://github.com/isHarryh/Ark-Pets#readme";
public static final String urlLicense = "https://github.com/isHarryh/Ark-Pets";
Expand Down
108 changes: 102 additions & 6 deletions desktop/src/cn/harryh/arkpets/controllers/Homepage.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class Homepage {
private boolean isNoFilter = true;
private boolean isHttpsTrustAll = false;
private boolean isUpdateAvailable = false;
private boolean isDatasetIncompatible = false;
public boolean isNewcomer = false;
public PopupUtils.Handbook trayExitHandbook = new TrayExitHandBook();
public JavaProcess.UnexpectedExitCodeException lastLaunchFailed = null;
Expand Down Expand Up @@ -141,6 +142,8 @@ public class Homepage {
@FXML
private Label configPhysicRestore;

@FXML
private Pane noticeBox;
@FXML
private JFXComboBox<Float> configDisplayScale;
@FXML
Expand Down Expand Up @@ -172,6 +175,9 @@ public class Homepage {

public ArkConfig config;
public JSONObject modelsDatasetFull;
private NoticeBar appVersionNotice;
private NoticeBar diskFreeSpaceNotice;
private NoticeBar datasetIncompatibleNotice;
private Logger.RealtimeInspector inspector = new Logger.RealtimeInspector(Logger.getCurrentLogFilePath());

public Homepage() {
Expand All @@ -193,6 +199,7 @@ public void initialize() {
initConfigDisplay();
initConfigAdvanced();
initAbout();
initNoticeBox();
initLaunchingStatusListener();
initScheduledListener();

Expand Down Expand Up @@ -280,7 +287,21 @@ private boolean initModelDataset(boolean $doPopNotice) {
throw new DatasetException("The key 'storageDirectory' may not in the dataset.");
if (!modelsDatasetFull.containsKey("sortTags"))
throw new DatasetException("The key 'sortTags' may not in the dataset.");
// TODO check dataset compatibility
try {
// Check dataset compatibility
if (!modelsDatasetFull.containsKey("arkPetsCompatibility"))
throw new DatasetException("The key 'arkPetsCompatibility' may not in the dataset.");
int[] acVersionResult = modelsDatasetFull.getObject("arkPetsCompatibility", int[].class);
Version acVersion = new Version(acVersionResult);
if (appVersion.lessThan(acVersion)) {
isDatasetIncompatible = true;
Logger.warn("ModelManager", "The model dataset may be incompatible (required " + acVersion + " or newer)");
} else {
isDatasetIncompatible = false;
}
} catch (Exception ex) {
Logger.warn("ModelManager", "Failed to get the compatibility of the model database.");
}
Logger.debug("ModelManager", "Initialized model dataset successfully.");
return true;
} catch (Exception e) {
Expand Down Expand Up @@ -541,6 +562,83 @@ private void initAbout() {
aboutGitHub.setOnMouseClicked (e -> NetUtils.browseWebpage(PathConfig.urlLicense));
}

private void initNoticeBox() {
appVersionNotice = new NoticeBar(noticeBox) {
@Override
protected boolean getActivated() {
return isUpdateAvailable;
}

@Override
protected String getColorString() {
return COLOR_INFO;
}

@Override
protected String getIconSVGPath() {
return IconUtil.ICON_INFO_ALT;
}

@Override
protected String getText() {
return "ArkPets 有新版本可用!点击此处前往下载~";
}

@Override
protected void onClick(MouseEvent event) {
NetUtils.browseWebpage(PathConfig.urlDownload);
}
};
diskFreeSpaceNotice = new NoticeBar(noticeBox) {
@Override
protected boolean getActivated() {
long freeSpace = new File(".").getFreeSpace();
return freeSpace < diskFreeSpaceRecommended && freeSpace > 0;
}

@Override
protected String getColorString() {
return COLOR_WARNING;
}

@Override
protected String getIconSVGPath() {
return IconUtil.ICON_WARNING_ALT;
}

@Override
protected String getText() {
return "当前磁盘存储空间不足,可能影响使用体验。";
}
};
datasetIncompatibleNotice = new NoticeBar(noticeBox) {
@Override
protected boolean getActivated() {
return isDatasetIncompatible;
}

@Override
protected String getColorString() {
return COLOR_WARNING;
}

@Override
protected String getIconSVGPath() {
return IconUtil.ICON_WARNING_ALT;
}

@Override
protected String getText() {
return "模型库可能不兼容当前的 ArkPets 版本,请更新软件。";
}

@Override
protected void onClick(MouseEvent event) {
NetUtils.browseWebpage(PathConfig.urlDownload);
}
};
}

private void initLaunchingStatusListener() {
ScheduledService<Boolean> ss = new ScheduledService<>() {
@Override
Expand Down Expand Up @@ -577,11 +675,9 @@ protected Boolean call() {
}
};
task.setOnSucceeded(e -> {
if (isUpdateAvailable) {
aboutQueryUpdate.setStyle("-fx-text-fill:" + COLOR_DANGER);
} else {
aboutQueryUpdate.setStyle("");
}
appVersionNotice.refresh();
diskFreeSpaceNotice.refresh();
datasetIncompatibleNotice.refresh();
configDeployMultiMonitorsStatus.setText("检测到 " + ArkConfig.Monitor.getMonitors().length + " 个显示屏");
});
return task;
Expand Down
100 changes: 100 additions & 0 deletions desktop/src/cn/harryh/arkpets/utils/ControlUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,23 @@
*/
package cn.harryh.arkpets.utils;

import javafx.animation.ScaleTransition;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.DoublePropertyBase;
import javafx.beans.value.ChangeListener;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.Label;
import javafx.scene.control.Labeled;
import javafx.scene.control.Slider;
import javafx.scene.control.Tooltip;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.scene.shape.SVGPath;
import javafx.scene.text.Font;

import cn.harryh.arkpets.Const;


public class ControlUtils {
Expand Down Expand Up @@ -127,4 +138,93 @@ protected Integer adjustValue(double rawValue) {
}
}
}


abstract public static class NoticeBar {
protected static final double borderRadius = 8;
protected static final double internalSpacing = 8;
protected static final double iconScale = 0.75;
protected static final double margin = 4;
protected static final double widthScale = 0.9;
protected final Pane container;
protected Pane noticeBar;

public NoticeBar(Pane root) {
container = root;
}

public final void refresh() {
if (getActivated() && noticeBar == null) {
noticeBar = getNoticeBar(getWidth(), getHeight());
container.getChildren().add(noticeBar);
ScaleTransition transition = new ScaleTransition(Const.durationFast, noticeBar);
transition.setFromY(0.1);
transition.setToY(1);
transition.play();
} else if (!getActivated() && noticeBar != null) {
final Pane finalNoticeBar = noticeBar;
noticeBar = null;
ScaleTransition transition = new ScaleTransition(Const.durationFast, finalNoticeBar);
transition.setFromY(1);
transition.setToY(0.1);
transition.setOnFinished(e -> container.getChildren().remove(finalNoticeBar));
transition.play();
}
}

abstract protected boolean getActivated();

abstract protected String getColorString();

abstract protected String getIconSVGPath();

abstract protected String getText();

protected double getHeight() {
return Font.getDefault().getSize() * 3;
}

protected double getWidth() {
Region region = (Region)container.getParent();
double regionWidth = region.getWidth() - region.getInsets().getLeft() - region.getInsets().getRight();
return regionWidth * widthScale;
}

protected Pane getNoticeBar(double width, double height) {
// Colors
Color color = Color.valueOf(getColorString());
BackgroundFill bgFill = new BackgroundFill(
color.deriveColor(0, 0.62, 1.62, 0.38),
new CornerRadii(borderRadius),
new Insets(margin)
);
// Layouts
HBox bar = new HBox(internalSpacing);
bar.setBackground(new Background(bgFill));
bar.setMaxSize(width, height);
bar.setAlignment(Pos.CENTER_LEFT);
bar.setOnMouseClicked(this::onClick);
SVGPath icon = new SVGPath();
icon.setContent(getIconSVGPath());
icon.setFill(color);
icon.setScaleX(iconScale);
icon.setScaleY(iconScale);
icon.setTranslateX(margin);
Label label = new Label(getText());
label.setTextFill(color);
label.setMinWidth(width * widthScale * widthScale);
bar.getChildren().addAll(icon, label);
// Click event
try {
if (!NoticeBar.class.equals(getClass().getMethod("onClick").getDeclaringClass())) {
bar.setOnMouseClicked(this::onClick);
}
} catch (Exception ignored) {
}
return bar;
}

protected void onClick(MouseEvent event) {
}
}
}

0 comments on commit 8de6ff2

Please sign in to comment.