Skip to content

Commit

Permalink
1.支持明暗主题切换
Browse files Browse the repository at this point in the history
2.修复游玩时长统计,当跨天时所有时长会保存至新的一天的问题
3.修复配置信息无法保存的问题
4.修复部分情况下默认字体存在异常的问题
5.UI调整
  • Loading branch information
leck995 committed Jul 14, 2024
1 parent b91f44f commit 9aa3a6c
Show file tree
Hide file tree
Showing 25 changed files with 9,836 additions and 182 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@
- [x] 查询宝箱获取数量
- [x] 库街区鸣潮签到
- [x] 抽卡分析(已支持国际服账号)
- [x] 明暗色主题
- [ ] 地图探索进度分析
- [ ] 角色数据分析
- [ ] 挑战数据分析

## 运行截图
![image.png](https://github.com/leck995/WutheringWavesTool/blob/master/temp/img01.png)

![image.png](https://github.com/leck995/WutheringWavesTool/blob/master/temp/img04.png)

![image.png](https://github.com/leck995/WutheringWavesTool/blob/master/temp/img02.png)

![image.png](https://github.com/leck995/WutheringWavesTool/blob/master/temp/img03.png)
Expand Down
14 changes: 0 additions & 14 deletions src/main/java/cn/tealc/wutheringwavestool/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public class Config {
public static final String version="1.1.2";
public static final String appTitle="鸣潮助手";
public static Setting setting;
public static Map<String, String> headers = new HashMap<>();
public static String currentRoleId;

static {
Expand All @@ -37,19 +36,6 @@ public class Config {
if (setting == null){
setting=new Setting();
}

File headerFile = new File("assets/data/header.json");
if (headerFile.exists()){
try {
headers=mapper.readValue(headerFile, new TypeReference<HashMap<String, String>>() {});
} catch (IOException e) {
throw new RuntimeException(e);
}
}
if (headers == null){
headers=new HashMap<>();
}

}


Expand Down
6 changes: 0 additions & 6 deletions src/main/java/cn/tealc/wutheringwavestool/Main.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
package cn.tealc.wutheringwavestool;

import cn.tealc.wutheringwavestool.jna.GameAppListener;
import com.sun.jna.platform.win32.User32;
import javafx.application.Application;

import java.time.LocalDate;

/**
* @program: WutheringWavesTool
* @description:
Expand All @@ -14,7 +9,6 @@
*/
public class Main {
public static void main(String[] args) {

Application.launch(MainApplication.class,args);
}
}
47 changes: 36 additions & 11 deletions src/main/java/cn/tealc/wutheringwavestool/MainApplication.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package cn.tealc.wutheringwavestool;

import atlantafx.base.theme.PrimerLight;
import cn.tealc.teafx.stage.RoundStage;
import cn.tealc.wutheringwavestool.dao.JdbcUtils;
import cn.tealc.wutheringwavestool.jna.GameAppListener;
import cn.tealc.wutheringwavestool.theme.PrimerDark;
import cn.tealc.wutheringwavestool.theme.PrimerLight;
import cn.tealc.wutheringwavestool.ui.AnalysisPoolView;
import cn.tealc.wutheringwavestool.ui.AnalysisPoolViewModel;
import cn.tealc.wutheringwavestool.ui.MainView;
Expand All @@ -24,10 +25,16 @@
import javafx.scene.control.CheckMenuItem;
import javafx.scene.control.MenuItem;
import javafx.scene.image.Image;
import javafx.scene.text.Font;
import javafx.stage.Stage;
import org.kordamp.ikonli.javafx.FontIcon;
import org.kordamp.ikonli.material2.Material2AL;
import org.kordamp.ikonli.material2.Material2MZ;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;

Expand All @@ -38,19 +45,23 @@ public class MainApplication extends Application {
public GameAppListener appListener;
private static FXTrayIcon fxTrayIcon;



@Override
public void start(Stage stage) throws IOException {
stage.close();
JdbcUtils.init();
System.setProperty("prism.lcdtext", "false");
RoundStage roundStage=new RoundStage();
window=roundStage;
roundStage.setWidth(1300.0);
roundStage.setHeight(750.0);
roundStage.setTitle("鸣潮助手");
roundStage.getIcons().add(new Image(MainApplication.class.getResourceAsStream("image/icon.png")));
Application.setUserAgentStylesheet(new PrimerLight().getUserAgentStylesheet());
initFont();
if (Config.setting.isTheme()){
Application.setUserAgentStylesheet(new PrimerDark().getUserAgentStylesheet());
}else {
Application.setUserAgentStylesheet(new PrimerLight().getUserAgentStylesheet());
}

ViewTuple<MainView, MainViewModel> viewTuple = FluentViewLoader.fxmlView(MainView.class).load();
roundStage.setContent(viewTuple.getView());
Expand All @@ -61,7 +72,24 @@ public void start(Stage stage) throws IOException {
roundStage.show();
createTrayIcon();
initExceptionHandler();
}

private void initFont(){
boolean contains = Font.getFamilies().contains("Microsoft YaHei");
if (!contains){
LOG.info("默认字体不存在,加载内置字体");
Font.loadFont(
MainApplication.class.getResourceAsStream("/cn/tealc/wutheringwavestool/font/HarmonyOS_Sans_SC_Regular.ttf"),
12);
Font.loadFont(
MainApplication.class.getResourceAsStream("/cn/tealc/wutheringwavestool/font/HarmonyOS_Sans_SC_Bold.ttf"),
12);
window.getScene().getRoot().setStyle("-fx-font-family: \"HarmonyOS Sans SC\"");
}else {
window.getScene().getRoot().setStyle("-fx-font-family: \"Microsoft YaHei\"");
LOG.info("默认字体存在");
}
LOG.info("系统默认字体:{}",Font.getDefault().getFamily());
}

private void initExceptionHandler(){
Expand All @@ -76,18 +104,15 @@ public void uncaughtException(Thread t, Throwable e) {
});
}

@Override
public void stop() throws Exception {
super.stop();



public static void exit(){
if (gameAppListener != null) {
User32.INSTANCE.UnhookWinEvent(gameAppListener);
}
JdbcUtils.exit();
Config.save();
}


public static void exit(){
window.close();
System.exit(0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/
public class NotificationKey {
public static final String MESSAGE="MESSAGE";
public static final String DIALOG="DIALOG";
public static final String SIGN_USER_DELETE="SIGN_USER_DELETE";
public static final String SIGN_USER_UPDATE="SIGN_USER_UPDATE";

Expand Down
68 changes: 57 additions & 11 deletions src/main/java/cn/tealc/wutheringwavestool/jna/GameAppListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
import org.slf4j.LoggerFactory;

import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.Date;

/**
Expand Down Expand Up @@ -68,19 +69,64 @@ public void callback(WinNT.HANDLE handle, WinDef.DWORD dword, WinDef.HWND hwnd,
start=false;
long endGameTime = System.currentTimeMillis(); //游戏结束时间
long totalGameTime = endGameTime - startGameTime;//总共游玩时间

//获取游戏开始时间日期
Instant instant = Instant.ofEpochMilli(startGameTime);
ZoneId zone = ZoneId.systemDefault();
ZonedDateTime zdt = instant.atZone(zone);
LocalDateTime startDateTime = zdt.toLocalDateTime();
LocalDate startDate = zdt.toLocalDate();

//获取结束日期
LocalDate localDate = LocalDate.now();

DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
GameTime gameTime=new GameTime();
if (Config.currentRoleId != null){
gameTime.setRoleId(Config.currentRoleId);
}
gameTime.setGameDate(dateTimeFormatter.format(localDate));
gameTime.setStartTime(startGameTime);
gameTime.setEndTime(endGameTime);
gameTime.setDuration(totalGameTime);
GameTimeDao dao=new GameTimeDao();
dao.addTime(gameTime);
LOG.info("检测到鸣潮已经结束,保存时间{}",gameTime);



if (startDate.isBefore(localDate)){ //跨天
LocalDateTime endOfDay = startDate.plusDays(1).atStartOfDay();
long millisecondsUntilEndOfDay = ChronoUnit.MILLIS.between(startDateTime, endOfDay);
GameTime gameTime1=new GameTime();
if (Config.currentRoleId != null){
gameTime1.setRoleId(Config.currentRoleId);
}
gameTime1.setGameDate(dateTimeFormatter.format(startDate));
gameTime1.setStartTime(startGameTime);
gameTime1.setEndTime(startGameTime + millisecondsUntilEndOfDay);
gameTime1.setDuration(millisecondsUntilEndOfDay);
dao.addTime(gameTime1);
LOG.info("检测到鸣潮已经结束且跨天,保存昨天时间{}",gameTime1);


GameTime gameTime=new GameTime();
if (Config.currentRoleId != null){
gameTime.setRoleId(Config.currentRoleId);
}
gameTime.setGameDate(dateTimeFormatter.format(localDate));
long todayMillis = totalGameTime - millisecondsUntilEndOfDay;
gameTime.setStartTime(endGameTime-todayMillis);
gameTime.setEndTime(endGameTime);
gameTime.setDuration(todayMillis);

dao.addTime(gameTime);
LOG.info("检测到鸣潮已经结束且跨天,保存今天时间{}",gameTime);

}else {
GameTime gameTime=new GameTime();
if (Config.currentRoleId != null){
gameTime.setRoleId(Config.currentRoleId);
}
gameTime.setGameDate(dateTimeFormatter.format(localDate));
gameTime.setStartTime(startGameTime);
gameTime.setEndTime(endGameTime);
gameTime.setDuration(totalGameTime);

dao.addTime(gameTime);
LOG.info("检测到鸣潮已经结束,保存时间{}",gameTime);
}

}
}
}
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/cn/tealc/wutheringwavestool/model/Setting.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* @create: 2024-07-03 00:38
*/
public class Setting {
private SimpleBooleanProperty theme=new SimpleBooleanProperty(false);
public SimpleStringProperty gameRootDir=new SimpleStringProperty();
private SimpleBooleanProperty firstViewWithPoolAnalysis=new SimpleBooleanProperty(false);

Expand All @@ -36,4 +37,16 @@ public SimpleBooleanProperty firstViewWithPoolAnalysisProperty() {
public void setFirstViewWithPoolAnalysis(boolean firstViewWithPoolAnalysis) {
this.firstViewWithPoolAnalysis.set(firstViewWithPoolAnalysis);
}

public boolean isTheme() {
return theme.get();
}

public SimpleBooleanProperty themeProperty() {
return theme;
}

public void setTheme(boolean theme) {
this.theme.set(theme);
}
}
29 changes: 29 additions & 0 deletions src/main/java/cn/tealc/wutheringwavestool/theme/PrimerDark.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package cn.tealc.wutheringwavestool.theme;

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

import atlantafx.base.theme.Theme;

public final class PrimerDark implements Theme {
public PrimerDark() {
}

public String getName() {
return "Primer Dark";
}

public String getUserAgentStylesheet() {
return "/cn/tealc/wutheringwavestool/css/Dark.css";
}

public String getUserAgentStylesheetBSS() {
return null;
}

public boolean isDarkMode() {
return true;
}
}
29 changes: 29 additions & 0 deletions src/main/java/cn/tealc/wutheringwavestool/theme/PrimerLight.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package cn.tealc.wutheringwavestool.theme;

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

import atlantafx.base.theme.Theme;

public final class PrimerLight implements Theme {
public PrimerLight() {
}

public String getName() {
return "Primer Light";
}

public String getUserAgentStylesheet() {
return "/cn/tealc/wutheringwavestool/css/Light.css";
}

public String getUserAgentStylesheetBSS() {
return null;
}

public boolean isDarkMode() {
return false;
}
}
Loading

0 comments on commit 9aa3a6c

Please sign in to comment.