From dc60cf647faabdf1df8165f14d01802529629a90 Mon Sep 17 00:00:00 2001 From: litwak913 Date: Thu, 23 Jan 2025 22:18:14 +0800 Subject: [PATCH 01/11] feat: macOS style titlebar --- assets/UI/Main.css | 9 ++ assets/UI/RootModule.fxml | 38 +---- assets/UI/Titlebar.fxml | 76 ++++++++++ assets/icons/macos/close.png | Bin 0 -> 2014 bytes assets/icons/macos/minimize.png | Bin 0 -> 1422 bytes desktop/src/cn/harryh/arkpets/ArkHomeFX.java | 8 +- .../arkpets/controllers/RootModule.java | 47 +----- .../harryh/arkpets/controllers/Titlebar.java | 142 ++++++++++++++++++ 8 files changed, 238 insertions(+), 82 deletions(-) create mode 100644 assets/UI/Titlebar.fxml create mode 100644 assets/icons/macos/close.png create mode 100644 assets/icons/macos/minimize.png create mode 100644 desktop/src/cn/harryh/arkpets/controllers/Titlebar.java diff --git a/assets/UI/Main.css b/assets/UI/Main.css index e483f2e7..00bdef2a 100644 --- a/assets/UI/Main.css +++ b/assets/UI/Main.css @@ -523,6 +523,15 @@ ProgressBar:indeterminate>.bar { -fx-background-color: #305890; } +#Title-minimize-btn-mac, +#Title-close-btn-mac { + -fx-fill: inherit; +} + +#Title-close-btn-mac { + -fx-background-radius: 8px 0 0 0; +} + #Title-close-btn:hover, #Title-close-btn:focused { -fx-background-color: #CC2211; diff --git a/assets/UI/RootModule.fxml b/assets/UI/RootModule.fxml index e9746a79..7615c11b 100644 --- a/assets/UI/RootModule.fxml +++ b/assets/UI/RootModule.fxml @@ -140,41 +140,7 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - + diff --git a/assets/UI/Titlebar.fxml b/assets/UI/Titlebar.fxml new file mode 100644 index 00000000..b24120f7 --- /dev/null +++ b/assets/UI/Titlebar.fxml @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/assets/icons/macos/close.png b/assets/icons/macos/close.png new file mode 100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FTo7v@)2Y&*B^vexhGhPidu!%Ef5{p9jH5r1%Q{!4)T zJW6VWY)W{v;Z0DF-(Nlc=D(K1@#yI2YPnp_RVtPH%3rBeU|Ci!o6WA@BkO-p9M1F@ zdOmIFy3$lu0x5CJcAXX5%l+WOwV76%|7ZA6CT$q`bi&Zprm`AHiDK1pR%|bK;Nn}Y z`QwLQB$WIffWB3J6%fBTaQ>fvZnZc&JDW)+llfFCr8k#F&N)h@l4Ds`?&QgnGh6-) zef0Fxd!Pkl$(WjrlUk``QY_zP!4wz%WTWLy_B$LT8(=@YTsSAQ& w*>RjH&+{fj%l}`rbD2kC=Q5APzR5HG2T#?{ht0=aSO5S307*qoM6N<$g0dCTDgXcg literal 0 HcmV?d00001 diff --git a/assets/icons/macos/minimize.png b/assets/icons/macos/minimize.png new file mode 100644 index 0000000000000000000000000000000000000000..4da14e9e762a7aa66b26ccce005b5c379a5e9704 GIT binary patch literal 1422 zcmV;91#$X`P)EX>4Tx04R}tkv&MmP!xqvQ>7vm2aAX}1guVWQ4z;lg(6f4wL+^7CNKSiCJjl7 zi=*ILaPVib>fqw6tAnc`2>yULJ2)x2NQw6)g%&Yhc)XAE?m4`7A0RX;OtZS;fTr7K zI++l&xm7XriZBKdz$hRy%b1g-6nyLJo;s=SVm!;g@6YN}^A-aFB5|Ax##3oQp0CJTqcu((}X-VzJo4N(Zx&sS!^TM^#Oyd?D+x z%6W^kR;jVpJ^2g6d3|M>>$FCY#3Gg;L4<-D%Ba9bjCP$A3u!t}`1prizeFyDTxBqF zET9Svvg-%`gWt2Y3R9C_QaAy0zc|jv7!cY8nsvwdK6aeu2@re+uJpFQ+5l!hNw2rH z=n>Gr4P0EeHDwRD+yRE34B3=jDM(8w6oB_L`lcK(a0~RVd2?%>$N#%rQ#K{DG+Rqa;|55hI zOR{MB*3M~miQmr7e`jY2{Kt(9PW-0dj7yZR$D%YPGIEUr=yZ7b(D90n$2ab0_p0L- zybNCS=_5|~0|2+W(>oyiRR`EQkI(1xaY>Ta=jP^8jInC~;JR-4`1rW!IL<~oovw}) z;Pum_mRMl=Rh2~q;bUz)kKMJR`vCr%CNbLM*7C2xCj8X?pm3zpV`> zF)iOszA&sR2aFRy8x)~bDrxa}ybz1U#=^F3qh7CTfe0ihyCrqz?b6~*WRiPRu68~& zYVP%~a=W$5;%7M79dq)7W-$-RfY0ai@kAo=R#nxB;y0Vk50y&gdN!M_Q2>xAUB9Zb z$fS+q%4cjABG!WOw7lrkM)q?S~JSY6S3-s?E6OBewgLi(MQA#06k_G?_03wWh9yYu077Dz_$ob<??Ma!+8tg2@MV|<+8w`g>YwsIeZLTz2e1d=4gf5FBTu@8 zz0)Vw3%&m?b5a3^$6nF%CRfq*0L%6Zy~lY<9)!QVK>fW4+@qtTqVM}*l856sg`NP8 z$2Z^IsD7wBd%o|f+bTL2D2{J)x1q+7lCjDYW({x&`)@DzD``Nu} z?ZC}6P48T|VY;Xqe&%j^ryk5*22X%o|GggHdq}RIPp8vW%d#@IZJ!I c|6AAo1>A-Ka#dmHV*mgE07*qoM6N<$f?FG{LI3~& literal 0 HcmV?d00001 diff --git a/desktop/src/cn/harryh/arkpets/ArkHomeFX.java b/desktop/src/cn/harryh/arkpets/ArkHomeFX.java index eba26adf..facacf15 100644 --- a/desktop/src/cn/harryh/arkpets/ArkHomeFX.java +++ b/desktop/src/cn/harryh/arkpets/ArkHomeFX.java @@ -9,6 +9,7 @@ import cn.harryh.arkpets.controllers.ModelsModule; import cn.harryh.arkpets.controllers.RootModule; import cn.harryh.arkpets.controllers.SettingsModule; +import cn.harryh.arkpets.controllers.Titlebar; import cn.harryh.arkpets.tray.HostTray; import cn.harryh.arkpets.utils.FXMLHelper; import cn.harryh.arkpets.utils.FXMLHelper.LoadFXMLResult; @@ -44,6 +45,7 @@ public class ArkHomeFX extends Application { public ModelsModule modelsModule; public BehaviorModule behaviorModule; public SettingsModule settingsModule; + public Titlebar titleBar; static { FontsConfig.loadFontsToJavafx(); @@ -60,6 +62,10 @@ public void start(Stage stage) throws Exception { fxml0.initializeWith(this); rootModule = (RootModule)fxml0.controller(); body = rootModule.body; + LoadFXMLResult fxmlTitlebar = FXMLHelper.loadFXML(getClass().getResource("/UI/Titlebar.fxml")); + fxmlTitlebar.initializeWith(this); + titleBar = (Titlebar) fxmlTitlebar.controller(); + fxmlTitlebar.addToNode(rootModule.wrapper4); // Setup scene and primary stage. Logger.info("Launcher", "Creating main scene"); @@ -71,7 +77,7 @@ public void start(Stage stage) throws Exception { stage.setResizable(false); stage.setScene(scene); stage.setTitle(desktopTitle); - rootModule.titleText.setText(desktopTitle); + titleBar.titleText.setText(desktopTitle); // After the stage is shown, do initialization. stage.show(); diff --git a/desktop/src/cn/harryh/arkpets/controllers/RootModule.java b/desktop/src/cn/harryh/arkpets/controllers/RootModule.java index a154af0f..c27e3aaf 100644 --- a/desktop/src/cn/harryh/arkpets/controllers/RootModule.java +++ b/desktop/src/cn/harryh/arkpets/controllers/RootModule.java @@ -21,12 +21,10 @@ import javafx.fxml.FXML; import javafx.scene.control.*; import javafx.scene.image.ImageView; -import javafx.scene.input.MouseEvent; import javafx.scene.layout.AnchorPane; import javafx.scene.layout.Pane; import javafx.scene.layout.StackPane; import javafx.scene.shape.SVGPath; -import javafx.scene.text.Text; import javafx.util.Duration; import java.util.ArrayList; @@ -58,6 +56,8 @@ public final class RootModule implements Controller { @FXML public AnchorPane wrapper3; @FXML + public Pane wrapper4; + @FXML private Pane loadingMask; @FXML private Pane splashScreen; @@ -75,18 +75,7 @@ public final class RootModule implements Controller { @FXML public JFXButton launchBtn; - @FXML - public AnchorPane titleBar; - @FXML - public Text titleText; - @FXML - private JFXButton titleMinimizeBtn; - @FXML - private JFXButton titleCloseBtn; - private ArkHomeFX app; - private double xOffset; - private double yOffset; @Override public void initializeWith(ArkHomeFX app) { @@ -198,38 +187,6 @@ public void exit() { }, durationFast, durationNormal); } - @FXML - public void titleBarPressed(MouseEvent event) { - xOffset = event.getSceneX(); - yOffset = event.getSceneY(); - } - - @FXML - public void titleBarDragged(MouseEvent event) { - app.stage.setX(event.getScreenX() - xOffset); - app.stage.setY(event.getScreenY() - yOffset); - } - - @FXML - public void windowMinimize(MouseEvent event) { - GuiPrefabs.fadeOutWindow(app.stage, durationFast, e -> { - app.stage.hide(); - app.stage.setIconified(true); - }); - } - - @FXML - public void windowClose(MouseEvent event) { - String solidExitTip = (app.config != null && app.config.launcher_solid_exit) ? - "退出程序将会同时退出已启动的桌宠。" : "退出程序后已启动的桌宠将会保留。"; - GuiPrefabs.Dialogs.createConfirmDialog(body, - GuiPrefabs.Icons.getIcon(GuiPrefabs.Icons.SVG_HELP_ALT, GuiPrefabs.COLOR_INFO), - "确认退出", - "现在退出 " + appName + " 吗?", - "根据您的设置," + solidExitTip + "\n使用最小化 [-] 按钮可以隐藏窗口到系统托盘。", - this::exit).show(); - } - private void initLaunchButton() { // Set handler for internal start button. launchBtn.setOnAction(e -> { diff --git a/desktop/src/cn/harryh/arkpets/controllers/Titlebar.java b/desktop/src/cn/harryh/arkpets/controllers/Titlebar.java new file mode 100644 index 00000000..20f47efc --- /dev/null +++ b/desktop/src/cn/harryh/arkpets/controllers/Titlebar.java @@ -0,0 +1,142 @@ +package cn.harryh.arkpets.controllers; + +import cn.harryh.arkpets.ArkHomeFX; +import cn.harryh.arkpets.utils.GuiPrefabs; +import javafx.fxml.FXML; +import javafx.geometry.Rectangle2D; +import javafx.scene.image.ImageView; +import javafx.scene.input.MouseEvent; +import javafx.scene.layout.AnchorPane; +import javafx.scene.layout.HBox; +import javafx.scene.text.Text; + +import static cn.harryh.arkpets.Const.appName; +import static cn.harryh.arkpets.Const.durationFast; + + +public class Titlebar implements Controller { + @FXML + public Text titleText; + @FXML + public HBox macTitleButtons; + @FXML + public HBox titleButtons; + @FXML + public HBox title; + @FXML + public ImageView titleMacCloseImage; + @FXML + public ImageView titleMacMinimizeImage; + + private ArkHomeFX app; + private double xOffset; + private double yOffset; + private final Rectangle2D area = new Rectangle2D(0, 0, 16, 16); + private final Rectangle2D hoverArea = new Rectangle2D(16, 0, 16, 16); + private final Rectangle2D activeArea = new Rectangle2D(32, 0, 16, 16); + private final Rectangle2D disableArea = new Rectangle2D(48, 0, 16, 16); + private boolean inHBox; + private boolean focused; + + @Override + public void initializeWith(ArkHomeFX app) { + this.app = app; + if (System.getProperty("arkpets.mactitlebar", "").equals("true") || com.sun.jna.Platform.isMac()) + initMacTitlebar(); + } + + @FXML + public void titleBarPressed(MouseEvent event) { + xOffset = event.getSceneX(); + yOffset = event.getSceneY(); + } + + @FXML + public void titleBarDragged(MouseEvent event) { + app.stage.setX(event.getScreenX() - xOffset); + app.stage.setY(event.getScreenY() - yOffset); + } + + @FXML + public void windowMinimize(MouseEvent event) { + GuiPrefabs.fadeOutWindow(app.stage, durationFast, e -> { + app.stage.hide(); + app.stage.setIconified(true); + }); + } + + @FXML + public void windowClose(MouseEvent event) { + String solidExitTip = (app.config != null && app.config.launcher_solid_exit) ? + "退出程序将会同时退出已启动的桌宠。" : "退出程序后已启动的桌宠将会保留。"; + GuiPrefabs.Dialogs.createConfirmDialog(app.body, + GuiPrefabs.Icons.getIcon(GuiPrefabs.Icons.SVG_HELP_ALT, GuiPrefabs.COLOR_INFO), + "确认退出", + "现在退出 " + appName + " 吗?", + "根据您的设置," + solidExitTip + "\n使用最小化 [-] 按钮可以隐藏窗口到系统托盘。", + app.rootModule::exit).show(); + } + + @FXML + public void mouseEnterBtnBoxMac() { + if (focused) { + titleMacCloseImage.setViewport(hoverArea); + titleMacMinimizeImage.setViewport(hoverArea); + inHBox = true; + } + } + + @FXML + public void mouseExitBtnBoxMac() { + if (focused) { + titleMacCloseImage.setViewport(area); + titleMacMinimizeImage.setViewport(area); + inHBox = false; + } + } + + @FXML + public void closePressedMac() { + titleMacCloseImage.setViewport(activeArea); + } + + @FXML + public void closeReleasedMac() { + if (inHBox) { + titleMacCloseImage.setViewport(hoverArea); + } else { + titleMacCloseImage.setViewport(area); + } + } + + @FXML + public void minimizePressedMac() { + titleMacMinimizeImage.setViewport(activeArea); + } + + @FXML + public void minimizeReleasedMac() { + if (inHBox) { + titleMacMinimizeImage.setViewport(hoverArea); + } else { + titleMacMinimizeImage.setViewport(area); + } + } + + private void initMacTitlebar() { + AnchorPane.setLeftAnchor(title, 52.0); + macTitleButtons.setVisible(true); + AnchorPane.setRightAnchor(titleButtons, null); + titleButtons.setVisible(false); + app.stage.focusedProperty().addListener((e, oldValue, newValue) -> { + focused = newValue; + if (!newValue) { + titleMacCloseImage.setViewport(disableArea); + titleMacMinimizeImage.setViewport(disableArea); + } else { + titleMacCloseImage.setViewport(area); + titleMacMinimizeImage.setViewport(area); + } + }); + } +} From bdaddf8566f1c56032d0b174c38ba9c9f4de8ae9 Mon Sep 17 00:00:00 2001 From: litwak913 Date: Sun, 29 Dec 2024 09:27:16 +0800 Subject: [PATCH 02/11] feat: envcheck --- assets/UI/SettingsModule.fxml | 3 + core/src/cn/harryh/arkpets/utils/IOUtils.java | 31 ++++ .../arkpets/controllers/RootModule.java | 58 +++++-- .../arkpets/controllers/SettingsModule.java | 10 +- .../envchecker/ConfirmTestCheckTask.java | 43 +++++ .../arkpets/envchecker/DWMEnvCheckTask.java | 45 +++++ .../arkpets/envchecker/EnvCheckTask.java | 47 ++++++ .../arkpets/envchecker/SleepEnvCheckTask.java | 38 +++++ .../envchecker/WinGraphicsEnvCheckTask.java | 114 +++++++++++++ .../guitasks/CheckEnvironmentTask.java | 138 +++++++++++++++ .../cn/harryh/arkpets/utils/NVAPIWrapper.java | 157 ++++++++++++++++++ 11 files changed, 667 insertions(+), 17 deletions(-) create mode 100644 desktop/src/cn/harryh/arkpets/envchecker/ConfirmTestCheckTask.java create mode 100644 desktop/src/cn/harryh/arkpets/envchecker/DWMEnvCheckTask.java create mode 100644 desktop/src/cn/harryh/arkpets/envchecker/EnvCheckTask.java create mode 100644 desktop/src/cn/harryh/arkpets/envchecker/SleepEnvCheckTask.java create mode 100644 desktop/src/cn/harryh/arkpets/envchecker/WinGraphicsEnvCheckTask.java create mode 100644 desktop/src/cn/harryh/arkpets/guitasks/CheckEnvironmentTask.java create mode 100644 desktop/src/cn/harryh/arkpets/utils/NVAPIWrapper.java diff --git a/assets/UI/SettingsModule.fxml b/assets/UI/SettingsModule.fxml index 17cd05dc..70f6ebd7 100644 --- a/assets/UI/SettingsModule.fxml +++ b/assets/UI/SettingsModule.fxml @@ -157,6 +157,9 @@