Skip to content

Commit

Permalink
Add New Features
Browse files Browse the repository at this point in the history
  • Loading branch information
isHarryh committed Apr 4, 2023
1 parent f576ede commit 5b5970c
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 19 deletions.
3 changes: 2 additions & 1 deletion assets/UI/Homepage.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,8 @@
</styleClass>
</JFXButton>
<JFXButton fx:id="manageModelVerify" mnemonicParsing="false"
prefHeight="35.0" prefWidth="100.0" text=" 验证完整性">
prefHeight="35.0" prefWidth="100.0" text=" 验证完整性"
visible="false">
<graphic>
<AnchorPane prefHeight="25.0" prefWidth="16.0"
styleClass="btn-icon">
Expand Down
28 changes: 26 additions & 2 deletions core/src/cn/harryh/arkpets/ArkPets.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public class ArkPets extends ApplicationAdapter implements InputProcessor {

public Vector2 WD_poscur; // Window Current Position
public Vector2 WD_postar; // Window Target Position
public EasingLinearVector2 WD_poseas; // Window Postion Easing
public EasingLinear WD_alpha; // Window Opacity Easing
public EasingLinearVector2 WD_poseas; // Window Position Easing
private int OFFSET_Y = 0;

public ArkPets(String $title) {
Expand All @@ -73,6 +74,7 @@ public void create() {
WD_poscur = new Vector2(0, 0);
WD_postar = new Vector2(0, 0);
WD_poseas = new EasingLinearVector2(new EasingLinear(0, 1, linearEasingDuration));
WD_alpha = new EasingLinear(0, 1, linearEasingDuration);
WD_SCALE = config.display_scale;
WD_W = (int)(WD_SCALE * cha.flexibleLayout.getWidth());
WD_H = (int)(WD_SCALE * cha.flexibleLayout.getHeight());
Expand Down Expand Up @@ -146,6 +148,7 @@ public void render() {
newAnim = tray.keepAnim;
}
changeAnimation(newAnim); // Apply the new anim.
setWindowAlphaCur(Gdx.graphics.getDeltaTime());
}

@Override
Expand Down Expand Up @@ -255,8 +258,29 @@ private void intiWindow(int x, int y) {
x, y, WD_W, WD_H,
WinUser.SWP_SHOWWINDOW | WinUser.SWP_NOACTIVATE
);
setWindowTransparent(false);
}

public void setWindowTransparent(boolean $transparent) {
Logger.debug("Window", "JNA SetWindowLong returns " +
Integer.toHexString(User32.INSTANCE.SetWindowLong(HWND_MINE, WinUser.GWL_EXSTYLE, 0x00000088)));
Integer.toHexString(User32.INSTANCE.SetWindowLong(HWND_MINE, WinUser.GWL_EXSTYLE,
windowLongDefault | ($transparent ? WinUser.WS_EX_TRANSPARENT : 0))));
}

private void setWindowAlpha(float $alpha) {
$alpha = Math.max(0, Math.min(1, $alpha));
User32.INSTANCE.SetLayeredWindowAttributes(HWND_MINE, 0, (byte)((int)($alpha * 255) & 0xFF), User32.LWA_ALPHA);
}

public void setWindowAlphaTar(float $alpha) {
WD_alpha.update($alpha);
}

private void setWindowAlphaCur(float $deltaTime) {
if (WD_alpha.curValue == WD_alpha.TO)
return;
WD_alpha.step($deltaTime);
setWindowAlpha(WD_alpha.curValue);
}

private void setWindowPos(int x, int y, boolean override) {
Expand Down
42 changes: 35 additions & 7 deletions core/src/cn/harryh/arkpets/ArkTray.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class ArkTray {
private final TrayIcon icon;
private final JDialog popWindow;
private final JPopupMenu pop;
private boolean isDisplaying = false;
public String name;
public AnimData keepAnim;

Expand All @@ -51,7 +52,7 @@ public ArkTray(ArkPets boundArkPets) {

// Load tray icon image.
Image image = Toolkit.getDefaultToolkit().createImage(ClassLoader.getSystemResource(iconFilePng));
icon = new TrayIcon(image, name + " - " + coreTitle);
icon = new TrayIcon(image, name + " - " + appName);
icon.setImageAutoSize(true);

popWindow = new JDialog(); // JDialog is the container of JPopupMenu.
Expand All @@ -67,7 +68,9 @@ public void firePopupMenuWillBecomeInvisible() {

// Menu options:
JMenuItem optKeepAnimEn = new JMenuItem("保持动作");
JMenuItem optKeepAnimDis = new JMenuItem("解除保持");
JMenuItem optKeepAnimDis = new JMenuItem("取消保持");
JMenuItem optTransparentEn = new JMenuItem("透明模式");
JMenuItem optTransparentDis = new JMenuItem("取消透明");
JMenuItem optExit = new JMenuItem("退出");
optKeepAnimEn.addActionListener(e -> {
Logger.info("Tray", "Keep-Anim enabled");
Expand All @@ -81,11 +84,32 @@ public void firePopupMenuWillBecomeInvisible() {
pop.remove(optKeepAnimDis);
pop.add(optKeepAnimEn, 0);
});
optTransparentEn.addActionListener(e -> {
Logger.info("Tray", "Transparent enabled");
arkPets.setWindowAlphaTar(0.618f);
arkPets.setWindowTransparent(true);
pop.remove(optTransparentEn);
pop.add(optTransparentDis, 1);
});
optTransparentDis.addActionListener(e -> {
Logger.info("Tray", "Transparent disabled");
arkPets.setWindowAlphaTar(1);
arkPets.setWindowTransparent(false);
pop.remove(optTransparentDis);
pop.add(optTransparentEn, 1);
});
optExit.addActionListener(e -> {
Logger.info("Tray","Request to exit");
Gdx.app.exit();
arkPets.setWindowAlphaTar(0);
remove();
try {
Thread.sleep((long)(linearEasingDuration * 1000));
Gdx.app.exit();
} catch (InterruptedException ignored) {
}
});
pop.add(optKeepAnimEn);
pop.add(optTransparentEn);
pop.add(optExit);
pop.setSize(100, 24 * pop.getSubElements().length);

Expand Down Expand Up @@ -113,16 +137,20 @@ public void mouseReleased(MouseEvent e) {
// Add the icon to system tray.
try {
tray.add(icon);
isDisplaying = true;
} catch (AWTException e) {
Logger.error("Tray", "Unable to apply tray icon.", e);
Logger.error("Tray", "Unable to apply tray icon, details see below", e);
}
}

/** Remove the icon from system tray.
*/
public void remove() {
tray.remove(icon);
pop.removeAll();
popWindow.dispose();
if (isDisplaying) {
tray.remove(icon);
pop.removeAll();
popWindow.dispose();
}
isDisplaying = false;
}
}
7 changes: 4 additions & 3 deletions core/src/cn/harryh/arkpets/Const.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ public final class Const {
public static final float skelBaseScale = 0.33333f;
public static final float linearEasingDuration = 0.2f;

public static final String coreTitle = "ArkPets";
public static final String desktopTitle = coreTitle + " Launcher " + appVersionStr;
public static final String appName = "ArkPets";
public static final String coreTitle = "ArkPets Core";
public static final String desktopTitle = "ArkPets Launcher " + appVersionStr;

public static final Duration durationFast = new Duration(150);
public static final Duration durationNormal = new Duration(300);
Expand All @@ -53,8 +54,8 @@ public static class PathConfig {
public static final String tempDirPath = "temp/";
public static final String tempModelsUnzipDirPath = tempDirPath + "models_unzipped/";
public static final String tempModelsZipCachePath = tempDirPath + "ArkModels.zip";
public static final String fileModelsDataPath = "models_data.json";
public static final String tempQueryVersionCachePath = tempDirPath + "ApiQueryVersionCache";
public static final String fileModelsDataPath = "models_data.json";
}


Expand Down
2 changes: 2 additions & 0 deletions core/src/cn/harryh/arkpets/utils/AssetCtrl.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
package cn.harryh.arkpets.utils;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import java.io.File;
Expand All @@ -21,6 +22,7 @@ public class AssetCtrl {
public String appellation;
public String skinGroupId;
public String skinGroupName;
public JSONArray sortTags;
public JSONObject checksum;
static final String separator = File.separator;
static final String[] extensions = {".atlas", ".png", ".skel"};
Expand Down
15 changes: 9 additions & 6 deletions desktop/src/cn/harryh/arkpets/controllers/Homepage.java
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,9 @@ private void initModelSearch() {
searchModelFilter.getItems().setAll("全部");
searchModelFilter.getSelectionModel().select(0);
if (initModelAssets(false)) {
Set<String> filterTags = modelsDatasetFull.getJSONObject("storageDirectory").keySet();
Set<String> filterTags = modelsDatasetFull.getJSONObject("sortTags").keySet();
for (String s : filterTags) {
searchModelFilter.getItems().add(s);
searchModelFilter.getItems().add(modelsDatasetFull.getJSONObject("sortTags").getString(s));
}
}
searchModelFilter.valueProperty().addListener(observable -> {
Expand Down Expand Up @@ -749,7 +749,7 @@ public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) {
}
});
if (flag[0] || this.isCancelled()) {
Logger.info("Checker", "Model repo check finished (may modified)");
Logger.info("Checker", "Model repo check finished (may modified or lost)");
return false;
}
Thread.sleep(100);
Expand All @@ -768,7 +768,7 @@ public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) {
Thread.sleep(100);
this.updateProgress(1, 1);
if (flag[0] || this.isCancelled()) {
Logger.info("Checker", "Model repo check finished (not integral)");
Logger.info("Checker", "Model repo check finished (not integral or cancelled)");
return false;
}
dialogGraphic[0] = IconUtil.getIcon(IconUtil.ICON_SUCCESS_ALT, COLOR_SUCCESS);
Expand Down Expand Up @@ -1017,7 +1017,6 @@ public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) th
if (Files.exists(dir.getFileName()))
IOUtils.FileUtil.delete(dir.getFileName(), false);
Files.move(dir, dir.getFileName(), StandardCopyOption.REPLACE_EXISTING);
//System.out.println("Moved:" + dir.getFileName());
return FileVisitResult.SKIP_SUBTREE;
}
return FileVisitResult.CONTINUE;
Expand All @@ -1039,10 +1038,14 @@ private void dealModelSearch(String $keyWords) {
searchModelList.getItems().clear();
AssetCtrl[] result = AssetCtrl.searchByKeyWords($keyWords, foundModelAssets);
String[] assetIdList = AssetCtrl.getAssetIdList(result);
String tag = "";
for (String s : modelsDatasetFull.getJSONObject("sortTags").keySet())
if (searchModelFilter.getValue().equals(modelsDatasetFull.getJSONObject("sortTags").getString(s)))
tag = s;
for (JFXListCell<AssetCtrl> item : foundModelItems) {
for (String assetId : assetIdList) {
if (item.getId().equals(assetId) &&
(isNoFilter || searchModelFilter.getValue().equals(item.getItem().type))) {
(isNoFilter || (item.getItem().sortTags != null && item.getItem().sortTags.contains(tag)))) {
searchModelList.getItems().add(item);
break;
}
Expand Down

0 comments on commit 5b5970c

Please sign in to comment.