Skip to content

Commit

Permalink
Add New Feature
Browse files Browse the repository at this point in the history
  • Loading branch information
isHarryh committed May 18, 2023
1 parent 5d024f9 commit 627d16d
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 30 deletions.
33 changes: 17 additions & 16 deletions core/src/cn/harryh/arkpets/ArkConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class ArkConfig {
new File(configCustomPath);
private static final InputStream configDefault =
Objects.requireNonNull(ArkConfig.class.getResourceAsStream(configDefaultPath));
private static boolean isNewcomer = false;

// The following is the config items
public int behavior_ai_activation;
Expand All @@ -50,38 +51,24 @@ public class ArkConfig {
private ArkConfig() {
}

/** Get the config in String format.
* @return All the content in the config file.
*/
public String readConfig() {
return JSON.toJSONString(this, true);
}

/** Save the config into the custom file.
*/
public void saveConfig() {
try {
IOUtils.FileUtil.writeString(configCustom, charsetDefault, readConfig(), false);
IOUtils.FileUtil.writeString(configCustom, charsetDefault, JSON.toJSONString(this, true), false);
} catch (IOException e) {
Logger.error("Config", "Config saving failed, details see below.", e);
}
}

/** Update the monitors' config.
* @return The count of detected monitors.
*/
public int updateMonitorsConfig() {
display_monitors_data = Monitor.toJSONArray(Monitor.getMonitors());
return display_monitors_data.size();
}

/** Instantiate an ArkConfig object.
* @return ArkConfig object.
*/
public static ArkConfig getConfig() {
if (!configCustom.isFile()) {
try {
Files.copy(configDefault, configCustom.toPath(), StandardCopyOption.REPLACE_EXISTING);
isNewcomer = true;
Logger.info("Config", "Default config was copied successfully.");
} catch (IOException e) {
Logger.error("Config", "Default config copying failed, details see below.", e);
Expand All @@ -95,6 +82,20 @@ public static ArkConfig getConfig() {
}
}

/** Update the monitors' config.
* @return The count of detected monitors.
*/
public int updateMonitorsConfig() {
display_monitors_data = Monitor.toJSONArray(Monitor.getMonitors());
return display_monitors_data.size();
}

/** @return Whether the config file was generated newly.
*/
public boolean isNewcomer() {
return isNewcomer;
}


/** Only available in Windows OS.
*/
Expand Down
8 changes: 8 additions & 0 deletions desktop/src/cn/harryh/arkpets/ArkHomeFX.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import cn.harryh.arkpets.controllers.Homepage;
import cn.harryh.arkpets.utils.ArgPending;
import cn.harryh.arkpets.utils.Handbook;
import cn.harryh.arkpets.utils.Logger;
import cn.harryh.arkpets.utils.JavaProcess;
import javafx.application.Application;
Expand Down Expand Up @@ -45,9 +46,16 @@ public void start(Stage stage) throws Exception {
if (ctrl.config.character_asset != null && !ctrl.config.character_asset.isEmpty()) {
ctrl.popLoading(ev -> {
try {
// Do launch ArkPets core.
Thread.sleep(100);
startArkPets();
Thread.sleep(1200);
if (ctrl.isNewcomer && !ctrl.trayExitHandbook.hasShown()) {
// Show handbook.
Handbook b = ctrl.trayExitHandbook;
ctrl.popNotice(b.getIcon(), b.getTitle(), b.getHeader(), b.getContent(), null).show();
b.setShown();
}
} catch (InterruptedException ignored) {
}
});
Expand Down
20 changes: 20 additions & 0 deletions desktop/src/cn/harryh/arkpets/controllers/Homepage.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
public class Homepage {
private boolean isHttpsTrustAll = false;
private boolean isNoFilter = true;
public boolean isNewcomer = false;
public Handbook trayExitHandbook = new TrayExitHandBook();
public JavaProcess.UnexpectedExitCodeException lastLaunchFailed = null;

@FXML
Expand Down Expand Up @@ -161,6 +163,7 @@ public void initialize() {
wrapper0.setVisible(true);
popLoading(e -> {
config = Objects.requireNonNull(ArkConfig.getConfig(), "ArkConfig returns a null instance, please check the config file.");
isNewcomer = config.isNewcomer();
initMenuBtn(menuBtn1, 1);
initMenuBtn(menuBtn2, 2);
initMenuBtn(menuBtn3, 3);
Expand Down Expand Up @@ -1207,4 +1210,21 @@ public DatasetException(String msg) {
super(msg);
}
}

public static class TrayExitHandBook extends Handbook {
@Override
public String getTitle() {
return "使用提示";
}

@Override
public String getHeader() {
return "如需关闭桌宠,请右键系统托盘图标后选择退出。";
}

@Override
public String getContent() {
return "看来你已经启动了你的第一个 ArkPets 桌宠!尽情享受 ArkPets 吧!";
}
}
}
32 changes: 32 additions & 0 deletions desktop/src/cn/harryh/arkpets/utils/Handbook.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/** Copyright (c) 2022-2023, Harry Huang
* At GPL-3.0 License
*/
package cn.harryh.arkpets.utils;

import javafx.scene.shape.SVGPath;


abstract public class Handbook {
public boolean hasShown = false;

public Handbook() {
}

abstract public String getTitle();

abstract public String getHeader();

abstract public String getContent();

public SVGPath getIcon() {
return PopupUtils.IconUtil.getIcon(PopupUtils.IconUtil.ICON_HELP_ALT, PopupUtils.COLOR_INFO);
}

public boolean hasShown() {
return hasShown;
}

public void setShown() {
hasShown = true;
}
}
30 changes: 16 additions & 14 deletions desktop/src/cn/harryh/arkpets/utils/PopupUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,27 @@


public class PopupUtils {
public static final String COLOR_INFO = "#37B";
public static final String COLOR_SUCCESS = "#5B5";
public static final String COLOR_WARNING = "#E93";
public static final String COLOR_DANGER = "#F54";
public static final String COLOR_WHITE = "#FFF";
public static final String COLOR_BLACK = "#000";
public static final String COLOR_DARK_GRAY = "#222";
public static final String COLOR_GRAY = "#444";
public static final String COLOR_INFO = "#37B";
public static final String COLOR_SUCCESS = "#5B5";
public static final String COLOR_WARNING = "#E93";
public static final String COLOR_DANGER = "#F54";
public static final String COLOR_WHITE = "#FFF";
public static final String COLOR_BLACK = "#000";
public static final String COLOR_DARK_GRAY = "#222";
public static final String COLOR_GRAY = "#444";
public static final String COLOR_LIGHT_GRAY = "#666";

public static class IconUtil {
public static final String ICON_INFO = "m12 2c5.514 0 10 4.486 10 10s-4.486 10-10 10-10-4.486-10-10 4.486-10 10-10zm0-2c-6.627 0-12 5.373-12 12s5.373 12 12 12 12-5.373 12-12-5.373-12-12-12zm-.001 5.75c.69 0 1.251.56 1.251 1.25s-.561 1.25-1.251 1.25-1.249-.56-1.249-1.25.559-1.25 1.249-1.25zm2.001 12.25h-4v-1c.484-.179 1-.201 1-.735v-4.467c0-.534-.516-.618-1-.797v-1h3v6.265c0 .535.517.558 1 .735v.999z";
public static final String ICON_INFO_ALT = "m12 0c-6.627 0-12 5.373-12 12s5.373 12 12 12 12-5.373 12-12-5.373-12-12-12zm-.001 5.75c.69 0 1.251.56 1.251 1.25s-.561 1.25-1.251 1.25-1.249-.56-1.249-1.25.559-1.25 1.249-1.25zm2.001 12.25h-4v-1c.484-.179 1-.201 1-.735v-4.467c0-.534-.516-.618-1-.797v-1h3v6.265c0 .535.517.558 1 .735v.999z";
public static final String ICON_SUCCESS = "m12 2c5.514 0 10 4.486 10 10s-4.486 10-10 10-10-4.486-10-10 4.486-10 10-10zm0-2c-6.627 0-12 5.373-12 12s5.373 12 12 12 12-5.373 12-12-5.373-12-12-12zm4.393 7.5l-5.643 5.784-2.644-2.506-1.856 1.858 4.5 4.364 7.5-7.643-1.857-1.857z";
public static final String ICON_INFO = "m12 2c5.514 0 10 4.486 10 10s-4.486 10-10 10-10-4.486-10-10 4.486-10 10-10zm0-2c-6.627 0-12 5.373-12 12s5.373 12 12 12 12-5.373 12-12-5.373-12-12-12zm-.001 5.75c.69 0 1.251.56 1.251 1.25s-.561 1.25-1.251 1.25-1.249-.56-1.249-1.25.559-1.25 1.249-1.25zm2.001 12.25h-4v-1c.484-.179 1-.201 1-.735v-4.467c0-.534-.516-.618-1-.797v-1h3v6.265c0 .535.517.558 1 .735v.999z";
public static final String ICON_INFO_ALT = "m12 0c-6.627 0-12 5.373-12 12s5.373 12 12 12 12-5.373 12-12-5.373-12-12-12zm-.001 5.75c.69 0 1.251.56 1.251 1.25s-.561 1.25-1.251 1.25-1.249-.56-1.249-1.25.559-1.25 1.249-1.25zm2.001 12.25h-4v-1c.484-.179 1-.201 1-.735v-4.467c0-.534-.516-.618-1-.797v-1h3v6.265c0 .535.517.558 1 .735v.999z";
public static final String ICON_HELP = "m12 2c5.514 0 10 4.486 10 10s-4.486 10-10 10-10-4.486-10-10 4.486-10 10-10zm0-2c-6.627 0-12 5.373-12 12s5.373 12 12 12 12-5.373 12-12-5.373-12-12-12zm1.25 17c0 .69-.559 1.25-1.25 1.25-.689 0-1.25-.56-1.25-1.25s.561-1.25 1.25-1.25c.691 0 1.25.56 1.25 1.25zm1.393-9.998c-.608-.616-1.515-.955-2.551-.955-2.18 0-3.59 1.55-3.59 3.95h2.011c0-1.486.829-2.013 1.538-2.013.634 0 1.307.421 1.364 1.226.062.847-.39 1.277-.962 1.821-1.412 1.343-1.438 1.993-1.432 3.468h2.005c-.013-.664.03-1.203.935-2.178.677-.73 1.519-1.638 1.536-3.022.011-.924-.284-1.719-.854-2.297z";
public static final String ICON_HELP_ALT = "m12 0c-6.627 0-12 5.373-12 12s5.373 12 12 12 12-5.373 12-12-5.373-12-12-12zm0 18.25c-.69 0-1.25-.56-1.25-1.25s.56-1.25 1.25-1.25c.691 0 1.25.56 1.25 1.25s-.559 1.25-1.25 1.25zm1.961-5.928c-.904.975-.947 1.514-.935 2.178h-2.005c-.007-1.475.02-2.125 1.431-3.468.573-.544 1.025-.975.962-1.821-.058-.805-.73-1.226-1.365-1.226-.709 0-1.538.527-1.538 2.013h-2.01c0-2.4 1.409-3.95 3.59-3.95 1.036 0 1.942.339 2.55.955.57.578.865 1.372.854 2.298-.016 1.383-.857 2.291-1.534 3.021z";
public static final String ICON_SUCCESS = "m12 2c5.514 0 10 4.486 10 10s-4.486 10-10 10-10-4.486-10-10 4.486-10 10-10zm0-2c-6.627 0-12 5.373-12 12s5.373 12 12 12 12-5.373 12-12-5.373-12-12-12zm4.393 7.5l-5.643 5.784-2.644-2.506-1.856 1.858 4.5 4.364 7.5-7.643-1.857-1.857z";
public static final String ICON_SUCCESS_ALT = "m12 0c-6.627 0-12 5.373-12 12s5.373 12 12 12 12-5.373 12-12-5.373-12-12-12zm-1.25 17.292l-4.5-4.364 1.857-1.858 2.643 2.506 5.643-5.784 1.857 1.857-7.5 7.643z";
public static final String ICON_WARNING = "m12 5.177l8.631 15.823h-17.262l8.631-15.823zm0-4.177l-12 22h24l-12-22zm-1 9h2v6h-2v-6zm1 9.75c-.689 0-1.25-.56-1.25-1.25s.561-1.25 1.25-1.25 1.25.56 1.25 1.25-.561 1.25-1.25 1.25z";
public static final String ICON_WARNING = "m12 5.177l8.631 15.823h-17.262l8.631-15.823zm0-4.177l-12 22h24l-12-22zm-1 9h2v6h-2v-6zm1 9.75c-.689 0-1.25-.56-1.25-1.25s.561-1.25 1.25-1.25 1.25.56 1.25 1.25-.561 1.25-1.25 1.25z";
public static final String ICON_WARNING_ALT = "m12 1l-12 22h24l-12-22zm-1 8h2v7h-2v-7zm1 11.25c-.69 0-1.25-.56-1.25-1.25s.56-1.25 1.25-1.25 1.25.56 1.25 1.25-.56 1.25-1.25 1.25z";
public static final String ICON_DANGER = "m16.142 2l5.858 5.858v8.284l-5.858 5.858h-8.284l-5.858-5.858v-8.284l5.858-5.858h8.284zm.829-2h-9.942l-7.029 7.029v9.941l7.029 7.03h9.941l7.03-7.029v-9.942l-7.029-7.029zm-8.482 16.992l3.518-3.568 3.554 3.521 1.431-1.43-3.566-3.523 3.535-3.568-1.431-1.432-3.539 3.583-3.581-3.457-1.418 1.418 3.585 3.473-3.507 3.566 1.419 1.417z";
public static final String ICON_DANGER_ALT = "m16.971 0h-9.942l-7.029 7.029v9.941l7.029 7.03h9.941l7.03-7.029v-9.942l-7.029-7.029zm-1.402 16.945l-3.554-3.521-3.518 3.568-1.418-1.418 3.507-3.566-3.586-3.472 1.418-1.417 3.581 3.458 3.539-3.583 1.431 1.431-3.535 3.568 3.566 3.522-1.431 1.43z";
public static final String ICON_DANGER = "m16.142 2l5.858 5.858v8.284l-5.858 5.858h-8.284l-5.858-5.858v-8.284l5.858-5.858h8.284zm.829-2h-9.942l-7.029 7.029v9.941l7.029 7.03h9.941l7.03-7.029v-9.942l-7.029-7.029zm-8.482 16.992l3.518-3.568 3.554 3.521 1.431-1.43-3.566-3.523 3.535-3.568-1.431-1.432-3.539 3.583-3.581-3.457-1.418 1.418 3.585 3.473-3.507 3.566 1.419 1.417z";
public static final String ICON_DANGER_ALT = "m16.971 0h-9.942l-7.029 7.029v9.941l7.029 7.03h9.941l7.03-7.029v-9.942l-7.029-7.029zm-1.402 16.945l-3.554-3.521-3.518 3.568-1.418-1.418 3.507-3.566-3.586-3.472 1.418-1.417 3.581 3.458 3.539-3.583 1.431 1.431-3.535 3.568 3.566 3.522-1.431 1.43z";

/** Get a SVGPath Node using the given path string and color.
* @param svg The SVG path string.
Expand Down

0 comments on commit 627d16d

Please sign in to comment.