Skip to content

Commit

Permalink
Add New Features
Browse files Browse the repository at this point in the history
  • Loading branch information
isHarryh committed May 4, 2024
1 parent fcb5111 commit 1af28e6
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 27 deletions.
3 changes: 2 additions & 1 deletion assets/ArkPetsConfigDefault.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@
"physic_gravity_acc":800.0,
"physic_speed_limit_x":1000.0,
"physic_speed_limit_y":1000.0,
"physic_static_friction_acc":500.0
"physic_static_friction_acc":500.0,
"window_style_toolwindow":true
}
5 changes: 5 additions & 0 deletions assets/UI/SettingsModule.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<HBox>
<Label text="窗口边界"/>
<JFXComboBox fx:id="configCanvasSize" prefWidth="100.0"/>
<JFXButton fx:id="configCanvasSizeHelp"/>
</HBox>
<Separator/>
<Label styleClass="config-group-title" text="高级设置"/>
Expand All @@ -38,6 +39,10 @@
<HBox>
<JFXCheckBox fx:id="configSolidExit" mnemonicParsing="false" text="退出程序时也退出桌宠"/>
</HBox>
<HBox>
<JFXCheckBox fx:id="configWindowToolwindow" mnemonicParsing="false" text="桌宠作为后台程序启动"/>
<JFXButton fx:id="configWindowToolwindowHelp"/>
</HBox>
<HBox>
<Label text="日志级别"/>
<JFXComboBox fx:id="configLoggingLevel" prefWidth="100.0"/>
Expand Down
2 changes: 2 additions & 0 deletions core/src/cn/harryh/arkpets/ArkConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ public class ArkConfig implements Serializable {
public float physic_speed_limit_x;
/** @since ArkPets 2.2 */ @JSONField(defaultValue = "1000.0")
public float physic_speed_limit_y;
/** @since ArkPets 3.2 */ @JSONField(defaultValue = "true")
public boolean window_style_toolwindow;

private ArkConfig() {
}
Expand Down
3 changes: 2 additions & 1 deletion core/src/cn/harryh/arkpets/ArkPets.java
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ private void refreshMonitorInfo() {
}

private void promiseToolwindowStyle(int maxRetries) {
if (!isToolwindowStyle) {
if (config.window_style_toolwindow && !isToolwindowStyle) {
// Make sure ArkPets has been set as foreground window once
for (int i = 0; ; i++) {
if (hWndMine.isForeground()) {
Expand Down Expand Up @@ -469,6 +469,7 @@ private static class LoopCtrl {
*/
public LoopCtrl(float minIntervalTime) {
this.minIntervalTime = minIntervalTime;
this.accumTime = minIntervalTime;
}

/** Returns true if the loop is executable now.
Expand Down
12 changes: 2 additions & 10 deletions desktop/src/cn/harryh/arkpets/controllers/RootModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -240,16 +240,8 @@ private void initLaunchButton() {
startArkPetsCore();
Thread.sleep(1200);
// Show handbook in the first-run.
if (isNewcomer && !trayExitHandbook.hasShown()) {
Handbook b = trayExitHandbook;
GuiPrefabs.DialogUtil.createCommonDialog(app.root,
b.getIcon(),
b.getTitle(),
b.getHeader(),
b.getContent(),
null).show();
b.setShown();
}
if (isNewcomer && !trayExitHandbook.hasShown())
trayExitHandbook.show(app.root);
} catch (InterruptedException ignored) {
} finally {
launchBtn.setDisable(false);
Expand Down
76 changes: 65 additions & 11 deletions desktop/src/cn/harryh/arkpets/controllers/SettingsModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import cn.harryh.arkpets.guitasks.CheckAppUpdateTask;
import cn.harryh.arkpets.guitasks.GuiTask;
import cn.harryh.arkpets.utils.*;
import cn.harryh.arkpets.utils.GuiComponents.NamedItem;
import cn.harryh.arkpets.utils.GuiComponents.*;
import com.jfoenix.controls.*;
import javafx.concurrent.ScheduledService;
import javafx.concurrent.Task;
Expand All @@ -36,7 +36,7 @@ public final class SettingsModule implements Controller<ArkHomeFX> {
@FXML
private JFXComboBox<NamedItem<Integer>> configDisplayFps;
@FXML
public JFXComboBox<NamedItem<Integer>> configCanvasSize;
private JFXComboBox<NamedItem<Integer>> configCanvasSize;
@FXML
private JFXComboBox<String> configLoggingLevel;
@FXML
Expand All @@ -50,6 +50,12 @@ public final class SettingsModule implements Controller<ArkHomeFX> {
@FXML
private JFXCheckBox configSolidExit;
@FXML
private JFXButton configCanvasSizeHelp;
@FXML
private JFXCheckBox configWindowToolwindow;
@FXML
private JFXButton configWindowToolwindowHelp;
@FXML
private Label aboutQueryUpdate;
@FXML
private Label aboutVisitWebsite;
Expand All @@ -58,9 +64,9 @@ public final class SettingsModule implements Controller<ArkHomeFX> {
@FXML
private Label aboutGitHub;

private GuiComponents.NoticeBar appVersionNotice;
private GuiComponents.NoticeBar diskFreeSpaceNotice;
private GuiComponents.NoticeBar fpsUnreachableNotice;
private NoticeBar appVersionNotice;
private NoticeBar diskFreeSpaceNotice;
private NoticeBar fpsUnreachableNotice;

private ArkHomeFX app;

Expand All @@ -75,7 +81,7 @@ public void initializeWith(ArkHomeFX app) {
}

private void initConfigDisplay() {
new GuiComponents.ComboBoxSetup<>(configDisplayScale).setItems(new NamedItem<>("x0.5", 0.5f),
new ComboBoxSetup<>(configDisplayScale).setItems(new NamedItem<>("x0.5", 0.5f),
new NamedItem<>("x0.75", 0.75f),
new NamedItem<>("x1.0", 1f),
new NamedItem<>("x1.25", 1.25f),
Expand All @@ -88,7 +94,7 @@ private void initConfigDisplay() {
app.config.display_scale = newValue.value();
app.config.save();
});
new GuiComponents.ComboBoxSetup<>(configDisplayFps).setItems(new NamedItem<>("25", 25),
new ComboBoxSetup<>(configDisplayFps).setItems(new NamedItem<>("25", 25),
new NamedItem<>("30", 30),
new NamedItem<>("45", 45),
new NamedItem<>("60", 60),
Expand All @@ -99,7 +105,7 @@ private void initConfigDisplay() {
app.config.save();
fpsUnreachableNotice.refresh();
});
new GuiComponents.ComboBoxSetup<>(configCanvasSize).setItems(new NamedItem<>("最宽", 4),
new ComboBoxSetup<>(configCanvasSize).setItems(new NamedItem<>("最宽", 4),
new NamedItem<>("较宽", 8),
new NamedItem<>("标准", 16),
new NamedItem<>("较窄", 32),
Expand All @@ -109,6 +115,17 @@ private void initConfigDisplay() {
app.config.canvas_fitting_samples = newValue.value();
app.config.save();
});
new HandbookEntrance(app.root, configCanvasSizeHelp) {
@Override
public Handbook getHandbook() {
return new ControlHandbook((Labeled)configCanvasSize.getParent().getChildrenUnmodifiable().get(0)) {
@Override
public String getContent() {
return "桌宠窗口边界的相对大小。更宽的边界能够防止动画溢出;更窄的边界能够防止鼠标误触。";
}
};
}
};
}

private void initConfigAdvanced() {
Expand Down Expand Up @@ -208,6 +225,23 @@ else if (args.contains(Const.LogConfig.debugArg))
app.config.launcher_solid_exit = configSolidExit.isSelected();
app.config.save();
});

configWindowToolwindow.setSelected(app.config.window_style_toolwindow);
configWindowToolwindow.setOnAction(e -> {
app.config.window_style_toolwindow = configWindowToolwindow.isSelected();
app.config.save();
});
new HandbookEntrance(app.root, configWindowToolwindowHelp) {
@Override
public Handbook getHandbook() {
return new ControlHandbook(configWindowToolwindow) {
@Override
public String getContent() {
return "桌宠将以后台工具程序的样式启动。启用时,桌宠不会在任务栏中显示程序图标。禁用时,作为普通程序的桌宠可以被直播流软件捕获。";
}
};
}
};
}

private void initAbout() {
Expand All @@ -221,7 +255,7 @@ private void initAbout() {
}

private void initNoticeBox() {
appVersionNotice = new GuiComponents.NoticeBar(noticeBox) {
appVersionNotice = new NoticeBar(noticeBox) {
@Override
protected boolean isToActivate() {
return isUpdateAvailable;
Expand All @@ -247,7 +281,7 @@ protected void onClick(MouseEvent event) {
NetUtils.browseWebpage(Const.PathConfig.urlDownload);
}
};
diskFreeSpaceNotice = new GuiComponents.NoticeBar(noticeBox) {
diskFreeSpaceNotice = new NoticeBar(noticeBox) {
@Override
protected boolean isToActivate() {
long freeSpace = new File(".").getFreeSpace();
Expand All @@ -269,7 +303,7 @@ protected String getText() {
return "当前磁盘存储空间不足,可能影响使用体验。";
}
};
fpsUnreachableNotice = new GuiComponents.NoticeBar(noticeBox) {
fpsUnreachableNotice = new NoticeBar(noticeBox) {
@Override
protected boolean isToActivate() {
for (ArkConfig.Monitor i : ArkConfig.Monitor.getMonitors())
Expand Down Expand Up @@ -317,4 +351,24 @@ protected Boolean call() {
ss.setRestartOnFailure(true);
ss.start();
}


abstract private static class ControlHandbook extends Handbook {
private final Labeled control;

public ControlHandbook(Labeled control) {
super();
this.control = control;
}

@Override
public String getTitle() {
return "选项说明";
}

@Override
public String getHeader() {
return control.getText();
}
}
}
37 changes: 33 additions & 4 deletions desktop/src/cn/harryh/arkpets/utils/GuiComponents.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package cn.harryh.arkpets.utils;

import cn.harryh.arkpets.Const;
import com.jfoenix.controls.*;
import javafx.animation.ScaleTransition;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.DoublePropertyBase;
Expand Down Expand Up @@ -419,13 +420,13 @@ abstract public static class Handbook {
public Handbook() {
}

abstract public String getTitle();
abstract protected String getTitle();

abstract public String getHeader();
abstract protected String getHeader();

abstract public String getContent();
abstract protected String getContent();

public SVGPath getIcon() {
protected SVGPath getIcon() {
return GuiPrefabs.Icons.getIcon(GuiPrefabs.Icons.ICON_HELP_ALT, GuiPrefabs.Colors.COLOR_INFO);
}

Expand All @@ -436,5 +437,33 @@ public boolean hasShown() {
public void setShown() {
hasShown = true;
}

public void show(StackPane root) {
GuiPrefabs.DialogUtil.createCommonDialog(root,
getIcon(),
getTitle(),
getHeader(),
getContent(),
null
).show();
setShown();
}
}


abstract public static class HandbookEntrance {
private static final double scale = 2.0 / 3;

public HandbookEntrance(StackPane root, JFXButton target) {
SVGPath graphic = GuiPrefabs.Icons.getIcon(GuiPrefabs.Icons.ICON_HELP, GuiPrefabs.Colors.COLOR_INFO);
graphic.setScaleX(scale);
graphic.setScaleY(scale);
target.setText("");
target.setGraphic(graphic);
target.setRipplerFill(Color.GRAY);
target.setOnAction(e -> getHandbook().show(root));
}

abstract protected Handbook getHandbook();
}
}

0 comments on commit 1af28e6

Please sign in to comment.