大换血,重写挑选器部分

main
lensfrex 3 years ago
parent 4199a269fd
commit e889b75605
No known key found for this signature in database
GPG Key ID: E10FF75B77E1924D
  1. 2
      Dogename/dogename.iml
  2. 2
      Dogename/src/main/java/me/lensferno/dogename/Main.java
  3. 356
      Dogename/src/main/java/me/lensferno/dogename/choose/Chooser.java
  4. 219
      Dogename/src/main/java/me/lensferno/dogename/configs/MainConfig.java
  5. 115
      Dogename/src/main/java/me/lensferno/dogename/controllers/MainInterfaceController.java
  6. 80
      Dogename/src/main/java/me/lensferno/dogename/controllers/MiniPaneController.java
  7. 4
      Dogename/src/main/java/me/lensferno/dogename/controllers/NumberSettingsPaneController.java
  8. 22
      Dogename/src/main/java/me/lensferno/dogename/controllers/SettingsPaneController.java
  9. 3
      Dogename/src/main/java/me/lensferno/dogename/data/History.java
  10. 68
      Dogename/src/main/java/me/lensferno/dogename/data/NameData.java
  11. 104
      Dogename/src/main/java/me/lensferno/dogename/select/Selector.java
  12. 203
      Dogename/src/main/java/me/lensferno/dogename/select/core/Worker.java
  13. 8
      Dogename/src/main/java/me/lensferno/dogename/utils/HtmlRequseter.java
  14. 32
      Dogename/src/main/java/me/lensferno/dogename/utils/Random.java
  15. 53
      Dogename/src/main/java/me/lensferno/dogename/voice/TokenManager.java
  16. 14
      Dogename/src/main/java/me/lensferno/dogename/voice/VoicePlayer.java
  17. 14
      Dogename/src/main/resources/me/lensferno/dogename/FXMLs/MainInterface.fxml

@ -15,7 +15,7 @@
<orderEntry type="library" name="Maven: com.jfoenix:jfoenix:8.0.9" level="project" /> <orderEntry type="library" name="Maven: com.jfoenix:jfoenix:8.0.9" level="project" />
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-core:2.13.2" level="project" /> <orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-core:2.13.2" level="project" />
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-api:2.13.2" level="project" /> <orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-api:2.13.2" level="project" />
<orderEntry type="library" name="Maven: commons-io:commons-io:2.6" level="project" /> <orderEntry type="library" name="Maven: commons-io:commons-io:2.7" level="project" />
<orderEntry type="library" name="Maven: com.squareup.okhttp3:okhttp:4.2.2" level="project" /> <orderEntry type="library" name="Maven: com.squareup.okhttp3:okhttp:4.2.2" level="project" />
<orderEntry type="library" name="Maven: com.squareup.okio:okio:2.2.2" level="project" /> <orderEntry type="library" name="Maven: com.squareup.okio:okio:2.2.2" level="project" />
<orderEntry type="library" name="Maven: org.jetbrains.kotlin:kotlin-stdlib:1.3.50" level="project" /> <orderEntry type="library" name="Maven: org.jetbrains.kotlin:kotlin-stdlib:1.3.50" level="project" />

@ -67,6 +67,8 @@ public class Main extends Application {
mainInterfaceController.setImg(DataReleaser.getMainPicStream()); mainInterfaceController.setImg(DataReleaser.getMainPicStream());
mainInterfaceController.init();
primaryStage.setOnCloseRequest(event -> { primaryStage.setOnCloseRequest(event -> {
configLoader.writeAllConfigToFile(configLoader.getMainConfigLocation(), configLoader.getVoiceConfigLocation()); configLoader.writeAllConfigToFile(configLoader.getMainConfigLocation(), configLoader.getVoiceConfigLocation());
System.exit(0); System.exit(0);

@ -1,356 +0,0 @@
package me.lensferno.dogename.choose;
import com.jfoenix.controls.JFXButton;
import javafx.animation.AnimationTimer;
import javafx.beans.property.StringProperty;
import me.lensferno.dogename.configs.VoiceConfig;
import me.lensferno.dogename.data.History;
import me.lensferno.dogename.data.NameData;
import me.lensferno.dogename.voice.Token;
import me.lensferno.dogename.voice.VoicePlayer;
import java.security.SecureRandom;
import java.util.Random;
import java.util.logging.Logger;
/*
_
  
       
          
          
            
     ___
         
   
      
           
                 
            
/___          
          
___    
    
     
*/
//一坨屎山,有待修改😒
public final class Chooser {
Logger log =Logger.getLogger("ChooserLogger");
final int UPPER_LABEL_ID = 1;
final int UNDER_LABEL_ID = 2;
Token token;
VoicePlayer voicePlayer;
VoiceConfig voiceConfig;
Random random =new Random();
public short minNumber;
public short maxNumber;
boolean voicePlay=true;
int totalMaxCount =120;
int cycleMaxCount =0;
int totalCount =0;
int totalCycleCount =0;
int shownLabelId =1;
String chosenName;
boolean cycleEnd =true;
boolean ignoreTimesOut=false;
boolean ignorePast=true;
boolean equalMode=true;
boolean forceStop =false;
boolean newAlgo=true;
public JFXButton anpaiBtn;
public short speed;
NameData nameData;
boolean isRunning;
StringProperty upLabelText;
StringProperty downLabelText;
History history;
String speaker,speakSpeed,intonation;
void writeIgnoreList(){
nameData.writeIgnoreList("");
}
AnimationTimer timer =new AnimationTimer() {
@Override
public void handle(long now) {
if(forceStop){
totalCount = totalMaxCount +1;
}
try{
Thread.sleep(speed);
}catch (Exception e){e.printStackTrace(); }
if(totalCount >= totalMaxCount){
if(!nameData.getIgnoreNameList().contains(chosenName)||!ignorePast||forceStop){
forceStop=false;
if(ignorePast)
nameData.getIgnoreNameList().add(chosenName);
if(equalMode)
writeIgnoreList();
cycleEnd=true;
totalCount =0;
totalCycleCount =0;
ignoreTimesOut=false;
switch (shownLabelId){
case UPPER_LABEL_ID:{
if(downLabelText.get().contains("→")||downLabelText.get().contains("←"))
downLabelText.set(downLabelText.get().replace("→ ","").replace(" ←",""));
upLabelText.set("→ "+chosenName+" ←");
break;
}
case UNDER_LABEL_ID:{
if(upLabelText.get().contains("→")||upLabelText.get().contains("←"))
upLabelText.set(upLabelText.get().replace("→ ","").replace(" ←",""));
downLabelText.set("→ "+chosenName+" ←");
break;
}
}
isRunning=false;
anpaiBtn.setText("安排一下");
stop();
System.gc();
history.addHistory(chosenName);
if(voicePlay)
voicePlayer.playVoice(chosenName,speaker,intonation,speakSpeed);
return;
}else
ignoreTimesOut=true;
}
if(totalCycleCount >= cycleMaxCount &&!ignoreTimesOut){
cycleEnd=true;
totalCycleCount =0;
}
if(cycleEnd){
//times=(int)(1+Math.random()*(chosenTime-already));
cycleMaxCount =1+random.nextInt(totalMaxCount - totalCount +1);
cycleEnd=false;
//showWhich=(int)(1+Math.random()*2);
shownLabelId =1+random.nextInt(2);
}
switch (shownLabelId){
case UPPER_LABEL_ID:{
chosenName= nameData.randomGet();
upLabelText.set(chosenName);
totalCount++;
totalCycleCount++;
break;
}
case UNDER_LABEL_ID:{
chosenName= nameData.randomGet();
downLabelText.set(chosenName);
totalCount++;
totalCycleCount++;
break;
}
}
}
};
//---------------------------------------------------------------------------------------
SecureRandom secRandom =new SecureRandom();
AnimationTimer numbTimer =new AnimationTimer() {
@Override
public void handle(long now) {
if(forceStop){
totalCount = totalMaxCount +1;
}
try{
Thread.sleep(speed);
}catch (Exception e){e.printStackTrace(); }
if(totalCount >= totalMaxCount){
if(!nameData.getIgnoreNumberList().contains(chosenName)||!ignorePast||forceStop){
forceStop=false;
if(ignorePast)
nameData.getIgnoreNumberList().add(chosenName);
if(equalMode)
writeIgnoreList();
cycleEnd=true;
totalCount =0;
totalCycleCount =0;
ignoreTimesOut=false;
switch (shownLabelId){
case UPPER_LABEL_ID:{
if(downLabelText.get().contains("→")||downLabelText.get().contains("←"))
downLabelText.set(downLabelText.get().replace("→ ","").replace(" ←",""));
upLabelText.set("→ "+chosenName+" ←");
break;
}
case UNDER_LABEL_ID:{
if(upLabelText.get().contains("→")||upLabelText.get().contains("←"))
upLabelText.set(upLabelText.get().replace("→ ","").replace(" ←",""));
downLabelText.set("→ "+chosenName+" ←");
break;
}
}
isRunning=false;
anpaiBtn.setText("安排一下");
stop();
System.gc();
history.addHistory(chosenName);
if(voicePlay)
voicePlayer.playVoice(chosenName,speaker,intonation,speakSpeed);
return;
}else
ignoreTimesOut=true;
}
shownLabelId =1+random.nextInt(2);
//speed=(short)(65+random.nextInt(100));
switch (shownLabelId){
case UPPER_LABEL_ID:{
if(newAlgo)
chosenName=String.valueOf(minNumber+random.nextInt(maxNumber-minNumber+1));
else
chosenName=String.valueOf(minNumber+secRandom.nextInt(maxNumber-minNumber+1));
upLabelText.set(chosenName);
totalCount++;
totalCycleCount++;
break;
}
case UNDER_LABEL_ID:{
if(newAlgo)
chosenName=String.valueOf(minNumber+random.nextInt(maxNumber-minNumber+1));
else
chosenName=String.valueOf(minNumber+secRandom.nextInt(maxNumber-minNumber+1));
downLabelText.set(chosenName);
totalCount++;
totalCycleCount++;
break;
}
}
}
};
public void forceStop(){
}
public void run(short speed,int chosenTime,boolean ignorePast,boolean equalMode,boolean voicePlay){
this.speed = speed;
this.totalMaxCount = chosenTime;
this.ignorePast = ignorePast;
this.equalMode = equalMode;
this.voicePlay = voicePlay;
isRunning=true;
timer.start();
}
public void run(short maxNumber,short minNumber,short speed,int chosenTime,boolean ignorePast,boolean equalMode,boolean voicePlay){
this.maxNumber = maxNumber;
this.minNumber = minNumber;
this.speed = speed;
this.totalMaxCount = chosenTime;
this.ignorePast = ignorePast;
this.equalMode = equalMode;
this.voicePlay = voicePlay;
isRunning=true;
numbTimer.start();
}
public void set(StringProperty upLabelText, StringProperty downLabelText, JFXButton anpaiBtn, History history, NameData nameData, Token token, VoiceConfig voiceConfig){
this.upLabelText=upLabelText;
this.downLabelText=downLabelText;
this.anpaiBtn = anpaiBtn;
this.history = history;
this.nameData = nameData;
this.token=token;
this.voicePlayer=new VoicePlayer(token);
this.voiceConfig=voiceConfig;
this.speaker=String.valueOf(voiceConfig.getSpeaker());
this.speakSpeed=String.valueOf(voiceConfig.getSpeed());
this.intonation=String.valueOf(voiceConfig.getIntonation());
this.speaker=voiceConfig.getSpeaker();
}
public void setChoose(JFXButton anpaiBtn) {
this.anpaiBtn = anpaiBtn;
}
public boolean isRunning() {
return isRunning;
}
public void setForceStop(boolean forceStop) {
this.forceStop = forceStop;
}
}

@ -5,214 +5,207 @@ import javafx.beans.property.*;
public class MainConfig { public class MainConfig {
// ConfigValuesBean configValuesBean =new ConfigValuesBean();
// ---------------------- Default values --------------------------------------------------------- // ---------------------- Default values ---------------------------------------------------------
@Expose private final int currentVersion = 3;
private final String NEWEST_CONFIG_VERSION = "2";
private String currentConfigVersion = null;
@Expose @Expose
public final boolean DEFAULT_NAME_CHOOSE = true; public static final boolean DEFAULT_NAME_CHOOSE = true;
public final int METHOD_NAME = 0; // 名字挑选法 public static final int METHOD_NAME = 0; // 名字挑选法
public final int METHOD_NUMBER = 1; // 数字挑选法 public static final int METHOD_NUMBER = 1; // 数字挑选法
public final int DEFAULT_CYCLE_TIMES = 120; // 默认轮回次数:120 public static final int DEFAULT_MAX_TOTAL_COUNT = 120; // 默认轮回次数:120
public final int DEFAULT_SPEED = 80; // 默认速度:20ms,对应滑动条80的位置 public static final int DEFAULT_SPEED = 80; // 默认速度:20ms,对应滑动条80的位置
public final boolean DEFAULT_RANDOM_TIMES = true; // 默认挑选轮回次数是否随机:ture public static final boolean DEFAULT_RANDOM_TIMES = true; // 默认挑选轮回次数是否随机:ture
public final boolean DEFAULT_IGNORE_PAST = true; // 默认忽略已经点过的名字:ture public static final boolean DEFAULT_IGNORE_PAST = true; // 默认忽略已经点过的名字:ture
public final boolean DEFAULT_EQUAL_MODE = true; // 默认开启"机会均等" public static final boolean DEFAULT_EQUAL_MODE = true; // 默认开启"机会均等"
public final boolean DEFAULT_NEW_ALGO = true; // 默认使用新算法"Java sec random" public static final boolean DEFAULT_NEW_ALGO = true; // 默认使用新算法"Java sec random"
public final boolean DEFAULT_VOICE_PLAY = true; // 默认使用语音播报 public static final boolean DEFAULT_VOICE_PLAY = true; // 默认使用语音播报
public final boolean DEFAULT_SHOW_SAYING = true; public static final boolean DEFAULT_SHOW_SAYING = true;
// ----------------------Properties---------------------------------------------------------------- // ----------------------Properties----------------------------------------------------------------
private SimpleBooleanProperty nameChooseProperty; private SimpleBooleanProperty nameChoose;
private SimpleBooleanProperty randomTimesProperty; // 挑选次数是否随机 private SimpleBooleanProperty randomCount; // 挑选次数是否随机
private SimpleBooleanProperty ignorePastProperty; // 是否忽略已经被点过的名字 private SimpleBooleanProperty passSelectedResult; // 是否忽略已经被点过的名字/数
private SimpleIntegerProperty chooseMethodProperty; // 挑选方式: 0->名字挑选法 1->数字挑选法 private SimpleIntegerProperty chooseMethod; // 挑选方式: 0->名字挑选法 1->数字挑选法
private SimpleIntegerProperty cycleTimesProperty; // 挑选轮回次数,旧称"chosenTime" private SimpleIntegerProperty maxTotalCount; // 挑选轮回次数
private SimpleIntegerProperty speedProperty; // 速度 private SimpleIntegerProperty speed; // 速度
private SimpleStringProperty minNumberProperty; // 最小值 private SimpleStringProperty minNumber; // 最小值
private SimpleStringProperty maxNumberProperty; // 最大值 private SimpleStringProperty maxNumber; // 最大值
private SimpleBooleanProperty equalModeProperty; // 是否开启"机会均等" private SimpleBooleanProperty equalMode; // 是否开启"机会均等"
private SimpleBooleanProperty newAlgoProperty; // 是否使用新算法 private SimpleBooleanProperty secureRandom; // 是否使用secure random
private SimpleBooleanProperty voicePlayProperty; // 是否使用语音播报 private SimpleBooleanProperty voicePlay; // 是否使用语音播报
private SimpleBooleanProperty showSaying; private SimpleBooleanProperty showSaying;
// -------------------------- 初始化 -------------------------------------------------------------- // -------------------------- 初始化 --------------------------------------------------------------
public MainConfig() { public MainConfig() {
randomTimesProperty = new SimpleBooleanProperty(DEFAULT_RANDOM_TIMES); randomCount = new SimpleBooleanProperty(DEFAULT_RANDOM_TIMES);
ignorePastProperty = new SimpleBooleanProperty(DEFAULT_IGNORE_PAST); passSelectedResult = new SimpleBooleanProperty(DEFAULT_IGNORE_PAST);
chooseMethodProperty = new SimpleIntegerProperty(METHOD_NAME); chooseMethod = new SimpleIntegerProperty(METHOD_NAME);
nameChooseProperty = new SimpleBooleanProperty(DEFAULT_NAME_CHOOSE); nameChoose = new SimpleBooleanProperty(DEFAULT_NAME_CHOOSE);
cycleTimesProperty = new SimpleIntegerProperty(DEFAULT_CYCLE_TIMES); maxTotalCount = new SimpleIntegerProperty(DEFAULT_MAX_TOTAL_COUNT);
speedProperty = new SimpleIntegerProperty(DEFAULT_SPEED); speed = new SimpleIntegerProperty(DEFAULT_SPEED);
minNumberProperty = new SimpleStringProperty("0"); minNumber = new SimpleStringProperty("0");
maxNumberProperty = new SimpleStringProperty("10"); maxNumber = new SimpleStringProperty("10");
equalModeProperty = new SimpleBooleanProperty(DEFAULT_EQUAL_MODE); equalMode = new SimpleBooleanProperty(DEFAULT_EQUAL_MODE);
newAlgoProperty = new SimpleBooleanProperty(DEFAULT_NEW_ALGO); secureRandom = new SimpleBooleanProperty(DEFAULT_NEW_ALGO);
voicePlayProperty = new SimpleBooleanProperty(DEFAULT_VOICE_PLAY); voicePlay = new SimpleBooleanProperty(DEFAULT_VOICE_PLAY);
showSaying = new SimpleBooleanProperty(DEFAULT_SHOW_SAYING); showSaying = new SimpleBooleanProperty(DEFAULT_SHOW_SAYING);
currentConfigVersion = NEWEST_CONFIG_VERSION;
} }
// -------------------------- Getters and Setters --------------------------------------------- // -------------------------- Getters and Setters ---------------------------------------------
public boolean isNameChooseProperty() { public boolean getNameChoose() {
return nameChooseProperty.get(); return nameChoose.get();
} }
public SimpleBooleanProperty nameChoosePropertyProperty() { public SimpleBooleanProperty nameChooseProperty() {
return nameChooseProperty; return nameChoose;
} }
public void setNameChooseProperty(boolean nameChooseProperty) { public void setNameChoose(boolean nameChoose) {
this.nameChooseProperty.set(nameChooseProperty); this.nameChoose.set(nameChoose);
} }
public boolean isRandomTimesProperty() { public boolean getRandomCount() {
return randomTimesProperty.get(); return randomCount.get();
} }
public SimpleBooleanProperty randomTimesPropertyProperty() { public SimpleBooleanProperty randomCountProperty() {
return randomTimesProperty; return randomCount;
} }
public void setRandomTimesProperty(boolean randomTimesProperty) { public void setRandomCount(boolean randomCount) {
this.randomTimesProperty.set(randomTimesProperty); this.randomCount.set(randomCount);
} }
public boolean isIgnorePastProperty() { public boolean getPassSelectedResult() {
return ignorePastProperty.get(); return passSelectedResult.get();
} }
public SimpleBooleanProperty ignorePastPropertyProperty() { public SimpleBooleanProperty passSelectedResultProperty() {
return ignorePastProperty; return passSelectedResult;
} }
public void setIgnorePastProperty(boolean ignorePastProperty) { public void setPassSelectedResult(boolean passSelectedResult) {
this.ignorePastProperty.set(ignorePastProperty); this.passSelectedResult.set(passSelectedResult);
} }
public int getChooseMethodProperty() { public int getChooseMethod() {
return chooseMethodProperty.get(); return chooseMethod.get();
} }
public SimpleIntegerProperty chooseMethodPropertyProperty() { public SimpleIntegerProperty chooseMethodProperty() {
return chooseMethodProperty; return chooseMethod;
} }
public void setChooseMethodProperty(int chooseMethodProperty) { public void setChooseMethod(int chooseMethod) {
this.chooseMethodProperty.set(chooseMethodProperty); this.chooseMethod.set(chooseMethod);
} }
public int getCycleTimesProperty() { public int getMaxTotalCount() {
return cycleTimesProperty.get(); return maxTotalCount.get();
} }
public SimpleIntegerProperty cycleTimesPropertyProperty() { public SimpleIntegerProperty maxTotalCountProperty() {
return cycleTimesProperty; return maxTotalCount;
} }
public void setCycleTimesProperty(int cycleTimesProperty) { public void setMaxTotalCount(int maxTotalCount) {
this.cycleTimesProperty.set(cycleTimesProperty); this.maxTotalCount.set(maxTotalCount);
} }
public int getSpeedProperty() { public int getSpeed() {
return speedProperty.get(); return speed.get();
} }
public SimpleIntegerProperty speedPropertyProperty() { public SimpleIntegerProperty speedProperty() {
return speedProperty; return speed;
} }
public void setSpeedProperty(int speedProperty) { public void setSpeed(int speed) {
this.speedProperty.set(speedProperty); this.speed.set(speed);
} }
public String getMinNumberProperty() { public String getMinNumber() {
return minNumberProperty.get(); return minNumber.get();
} }
public SimpleStringProperty minNumberPropertyProperty() { public SimpleStringProperty minNumberProperty() {
return minNumberProperty; return minNumber;
} }
public void setMinNumberProperty(String minNumberProperty) { public void setMinNumber(String minNumber) {
this.minNumberProperty.set(minNumberProperty); this.minNumber.set(minNumber);
} }
public String getMaxNumberProperty() { public String getMaxNumber() {
return maxNumberProperty.get(); return maxNumber.get();
} }
public SimpleStringProperty maxNumberPropertyProperty() { public SimpleStringProperty maxNumberProperty() {
return maxNumberProperty; return maxNumber;
} }
public void setMaxNumberProperty(String maxNumberProperty) { public void setMaxNumber(String maxNumber) {
this.maxNumberProperty.set(maxNumberProperty); this.maxNumber.set(maxNumber);
} }
public boolean isEqualModeProperty() { public boolean getEqualMode() {
return equalModeProperty.get(); return equalMode.get();
} }
public SimpleBooleanProperty equalModePropertyProperty() { public SimpleBooleanProperty equalModeProperty() {
return equalModeProperty; return equalMode;
} }
public void setEqualModeProperty(boolean equalModeProperty) { public void setEqualMode(boolean equalMode) {
this.equalModeProperty.set(equalModeProperty); this.equalMode.set(equalMode);
} }
public boolean isNewAlgoProperty() { public boolean getSecureRandom() {
return newAlgoProperty.get(); return secureRandom.get();
} }
public SimpleBooleanProperty newAlgoPropertyProperty() { public SimpleBooleanProperty secureRandomProperty() {
return newAlgoProperty; return secureRandom;
} }
public void setNewAlgoProperty(boolean newAlgoProperty) { public void setSecureRandom(boolean secureRandom) {
this.newAlgoProperty.set(newAlgoProperty); this.secureRandom.set(secureRandom);
} }
public boolean isVoicePlayProperty() { public boolean getVoicePlay() {
return voicePlayProperty.get(); return voicePlay.get();
} }
public SimpleBooleanProperty voicePlayPropertyProperty() { public SimpleBooleanProperty voicePlayProperty() {
return voicePlayProperty; return voicePlay;
} }
public void setVoicePlayProperty(boolean voicePlayProperty) { public void setVoicePlay(boolean voicePlay) {
this.voicePlayProperty.set(voicePlayProperty); this.voicePlay.set(voicePlay);
} }
public boolean isShowSaying() { public boolean isShowSaying() {
@ -227,16 +220,8 @@ public class MainConfig {
this.showSaying.set(showSaying); this.showSaying.set(showSaying);
} }
public String getCurrentConfigVersion() { public int getCurrentConfigVersion() {
return currentConfigVersion; return currentVersion;
}
public void setCurrentConfigVersion(String currentConfigVersion) {
this.currentConfigVersion = currentConfigVersion;
}
public String getNewestConfigVersion() {
return NEWEST_CONFIG_VERSION;
} }
} }

@ -12,16 +12,14 @@ import javafx.scene.image.ImageView;
import javafx.scene.layout.Pane; import javafx.scene.layout.Pane;
import javafx.stage.Stage; import javafx.stage.Stage;
import javafx.stage.StageStyle; import javafx.stage.StageStyle;
import me.lensferno.dogename.select.Selector;
import me.lensferno.dogename.utils.DialogMaker; import me.lensferno.dogename.utils.DialogMaker;
import me.lensferno.dogename.choose.Chooser;
import me.lensferno.dogename.configs.ConfigLoader; import me.lensferno.dogename.configs.ConfigLoader;
import me.lensferno.dogename.configs.MainConfig; import me.lensferno.dogename.configs.MainConfig;
import me.lensferno.dogename.configs.VoiceConfig; import me.lensferno.dogename.configs.VoiceConfig;
import me.lensferno.dogename.data.History; import me.lensferno.dogename.data.History;
import me.lensferno.dogename.data.NameData; import me.lensferno.dogename.data.NameData;
import me.lensferno.dogename.ocr.Ocr; import me.lensferno.dogename.ocr.Ocr;
import me.lensferno.dogename.voice.Token;
import me.lensferno.dogename.voice.TokenManager;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
@ -35,11 +33,6 @@ public final class MainInterfaceController {
public JFXTextArea message; public JFXTextArea message;
//ConfigLoader configLoader=new ConfigLoader();
Token token;
TokenManager tokenManager=new TokenManager();
Ocr ocrTool=null; Ocr ocrTool=null;
History history=new History(); History history=new History();
@ -59,9 +52,6 @@ public final class MainInterfaceController {
@FXML @FXML
private JFXButton anPaiBtn; private JFXButton anPaiBtn;
@FXML
private JFXButton anPaiX10Btn;
@FXML @FXML
private Pane mainPane; private Pane mainPane;
@ -72,7 +62,7 @@ public final class MainInterfaceController {
private JFXButton showNameMangerButton; private JFXButton showNameMangerButton;
@FXML @FXML
private Label chosen_1; private Label upperLabel;
@FXML @FXML
private ImageView mainView; private ImageView mainView;
@ -81,35 +71,27 @@ public final class MainInterfaceController {
private JFXButton miniModeBtn; private JFXButton miniModeBtn;
@FXML @FXML
private Label chosen_2; private Label downLabel;
public MainInterfaceController(){ public MainInterfaceController(){
history.loadHistory(); history.loadHistory();
nameData.readIgnoreList(); nameData.readIgnoreList();
tokenManager.init();
this.ignoreNameList=nameData.getIgnoreNameList(); this.ignoreNameList=nameData.getIgnoreNameList();
this.ignoreNumberList=nameData.getIgnoreNumberList(); this.ignoreNumberList=nameData.getIgnoreNumberList();
if(tokenManager.getTokenStatus().equals("ok")){
token=tokenManager.getToken();
}
} }
MainConfig mainConfig; MainConfig mainConfig;
VoiceConfig voiceConfig; VoiceConfig voiceConfig;
public void bindProperties(){ public void bindProperties(){
nameChoose.selectedProperty().bindBidirectional(mainConfig.nameChoosePropertyProperty()); nameChoose.selectedProperty().bindBidirectional(mainConfig.nameChooseProperty());
//mainConfig.nameChoosePropertyProperty().not()
numbChoose.selectedProperty().bind(mainConfig.nameChoosePropertyProperty().not()); numbChoose.selectedProperty().bind(mainConfig.nameChooseProperty().not());
numbChoose.selectedProperty().unbind(); numbChoose.selectedProperty().unbind();
/* mainConfig.nameChooseProperty().addListener((observable, oldValue, newValue) -> {
mainConfig.nameChoosePropertyProperty().addListener((observable, oldValue, newValue) -> { mainConfig.setChooseMethod(mainConfig.getNameChoose() ? MainConfig.METHOD_NAME : MainConfig.METHOD_NUMBER);
//numbChoose.selectedProperty().unbind(); });
numbChoose.setSelected(oldValue);
});*/
} }
public void setImg(InputStream stream){ public void setImg(InputStream stream){
@ -130,7 +112,7 @@ public final class MainInterfaceController {
@FXML @FXML
void showNameManger(ActionEvent event) { void showNameManger(ActionEvent event) {
if (chooser.isRunning()){ if (selector.isWorkerRunning()){
new DialogMaker(rootPane).createMessageDialog("(・。・)","安排中......\n为保证运行的稳定,此时还不能进行该操作哦。"); new DialogMaker(rootPane).createMessageDialog("(・。・)","安排中......\n为保证运行的稳定,此时还不能进行该操作哦。");
return; return;
} }
@ -138,12 +120,10 @@ public final class MainInterfaceController {
new DialogMaker(rootPane).createDialogWithOneBtn("名单管理",nameManagerPaneController); new DialogMaker(rootPane).createDialogWithOneBtn("名单管理",nameManagerPaneController);
} }
@FXML @FXML
void showNunberSetting(ActionEvent event) { void showNunberSetting(ActionEvent event) {
if (chooser.isRunning()){ if (selector.isWorkerRunning()){
new DialogMaker(rootPane).createMessageDialog("(・。・)","安排中......\n为保证运行的稳定,此时还不能进行该操作哦。"); new DialogMaker(rootPane).createMessageDialog("(・。・)","安排中......\n为保证运行的稳定,此时还不能进行该操作哦。");
return; return;
} }
@ -172,7 +152,7 @@ public final class MainInterfaceController {
miniStage.initStyle(StageStyle.UNDECORATED); miniStage.initStyle(StageStyle.UNDECORATED);
MiniPaneController miniPaneController=loader.getController(); MiniPaneController miniPaneController=loader.getController();
miniPaneController.setBase(history,nameData,token,voiceConfig,mainConfig); miniPaneController.setBase(nameData, mainConfig, selector);
Stage currentStage=(Stage)anPaiBtn.getScene().getWindow(); Stage currentStage=(Stage)anPaiBtn.getScene().getWindow();
miniPaneController.setForwStage(currentStage); miniPaneController.setForwStage(currentStage);
@ -184,7 +164,6 @@ public final class MainInterfaceController {
miniStage.show(); miniStage.show();
currentStage.hide(); currentStage.hide();
} }
@FXML @FXML
@ -218,48 +197,58 @@ public final class MainInterfaceController {
HashSet<String> ignoreNumberList; HashSet<String> ignoreNumberList;
NameData nameData=new NameData(); NameData nameData=new NameData();
//boolean isRunning=false;
Chooser chooser=new Chooser(); Selector selector =new Selector();
public void init(){
selector.initialVariable(mainConfig, nameData, history, upperLabel.textProperty(), downLabel.textProperty());
selector.addStoppedEventListener((observableValue, oldValue, stop)->{
if (stop) {
anPaiBtn.setText("安排一下");
} else {
anPaiBtn.setText("不玩了!");
}
});
}
@FXML @FXML
void anPai() { void anPai() {
if(chooser.isRunning()){ if(selector.isWorkerRunning()){
chooser.setForceStop(true); selector.forceStop();
anPaiBtn.setText("安排一下"); anPaiBtn.setText("安排一下");
return; return;
} }
if(mainConfig.isRandomTimesProperty()) { if(mainConfig.getRandomCount()) {
mainConfig.setCycleTimesProperty(100+random.nextInt(151)); mainConfig.setMaxTotalCount(100+random.nextInt(151));
} }
if(mainConfig.isNameChooseProperty()){ if(mainConfig.getNameChoose()){
runNameMode(chooser); runNameMode();
}else { }else {
runNumberMode(chooser); runNumberMode();
} }
} }
public void setToggleGroup(){ public void setToggleGroup(){
ToggleGroup toggleGroup =new ToggleGroup(); ToggleGroup toggleGroup =new ToggleGroup();
nameChoose.setToggleGroup(toggleGroup); nameChoose.setToggleGroup(toggleGroup);
numbChoose.setToggleGroup(toggleGroup); numbChoose.setToggleGroup(toggleGroup);
} }
private void runNameMode(Chooser chooser){ private void runNameMode(){
if(nameData.isEmpty()){ if(nameData.isEmpty()){
new DialogMaker(rootPane).createMessageDialog("哦霍~","现在名单还是空的捏~请前往名单管理添加名字 或 使用数字挑选法。"); new DialogMaker(rootPane).createMessageDialog("哦霍~","现在名单还是空的捏~请前往名单管理添加名字 或 使用数字挑选法。");
return; return;
} }
if((nameData.getIgnoreNameList().size()>=nameData.getSize())&&mainConfig.isIgnorePastProperty()){ if((nameData.getIgnoreNameList().size() >= nameData.getSize()) && mainConfig.getPassSelectedResult()){
if(mainConfig.isEqualModeProperty()) { if(mainConfig.getEqualMode()) {
new DialogMaker(rootPane).createDialogWithOKAndCancel("啊?", "全部名字都被点完啦!\n要把名字的忽略列表重置吗?", e ->nameData.clearNameIgnoreList()); new DialogMaker(rootPane).createDialogWithOKAndCancel("啊?", "全部名字都被点完啦!\n要把名字的忽略列表重置吗?", e ->nameData.clearNameIgnoreList());
}else { }else {
new DialogMaker(rootPane).createMessageDialog("啊?", "全部名字都被点完啦!\n请多添加几个名字 或 点击“机会均等”的“重置”按钮。"); new DialogMaker(rootPane).createMessageDialog("啊?", "全部名字都被点完啦!\n请多添加几个名字 或 点击“机会均等”的“重置”按钮。");
@ -269,33 +258,23 @@ public final class MainInterfaceController {
anPaiBtn.setText("不玩了!"); anPaiBtn.setText("不玩了!");
chooser.set(chosen_1.textProperty(),chosen_2.textProperty(),anPaiBtn,history,nameData,token,voiceConfig); selector.run();
chooser.run(
(short)(100-mainConfig.getSpeedProperty()) ,
mainConfig.getCycleTimesProperty(),
mainConfig.isIgnorePastProperty(),
mainConfig.isEqualModeProperty(),
mainConfig.isVoicePlayProperty()
);
} }
private void runNumberMode(){
private void runNumberMode(Chooser chooser){
try{ try{
int minNumber=Integer.parseInt(mainConfig.getMinNumberProperty()); int minNumber=Integer.parseInt(mainConfig.getMinNumber());
int maxNumber=Integer.parseInt(mainConfig.getMaxNumberProperty()); int maxNumber=Integer.parseInt(mainConfig.getMaxNumber());
if(maxNumber-minNumber<=0){ if(maxNumber-minNumber <= 0){
new DialogMaker(rootPane).createMessageDialog("嗯哼?","数字要前小后大啊~"); new DialogMaker(rootPane).createMessageDialog("嗯哼?","数字要前小后大啊~");
return; return;
} }
if(nameData.getIgnoreNumberList().size()>=(maxNumber-minNumber+1) && mainConfig.isIgnorePastProperty()){ if(nameData.getIgnoreNumberList().size() >= (maxNumber-minNumber+1) && mainConfig.getPassSelectedResult()){
if(mainConfig.isEqualModeProperty()) { if(mainConfig.getEqualMode()) {
new DialogMaker(rootPane).createDialogWithOKAndCancel("啊?", "全部数字都被点完啦!\n要把数字的忽略列表重置吗?", e ->nameData.clearNumberIgnoreList()); new DialogMaker(rootPane).createDialogWithOKAndCancel("啊?", "全部数字都被点完啦!\n要把数字的忽略列表重置吗?", e ->nameData.clearNumberIgnoreList());
}else { }else {
new DialogMaker(rootPane).createMessageDialog("啊?", "全部数字都被点完啦!\n请扩大数字范围 或 点击“机会均等”的“重置”按钮。"); new DialogMaker(rootPane).createMessageDialog("啊?", "全部数字都被点完啦!\n请扩大数字范围 或 点击“机会均等”的“重置”按钮。");
@ -310,17 +289,7 @@ public final class MainInterfaceController {
anPaiBtn.setText("不玩了!"); anPaiBtn.setText("不玩了!");
chooser.set(chosen_1.textProperty(),chosen_2.textProperty(),anPaiBtn,history,nameData,token,voiceConfig); selector.run();
chooser.run(
Short.parseShort(mainConfig.getMaxNumberProperty()),
Short.parseShort(mainConfig.getMinNumberProperty()),
(short)(100-mainConfig.getSpeedProperty()) ,
mainConfig.getCycleTimesProperty(),
mainConfig.isIgnorePastProperty(),
mainConfig.isEqualModeProperty(),
mainConfig.isVoicePlayProperty()
);
} }
public Label getTopBar() { public Label getTopBar() {

@ -8,15 +8,12 @@ import javafx.scene.Scene;
import javafx.scene.control.Label; import javafx.scene.control.Label;
import javafx.scene.input.MouseEvent; import javafx.scene.input.MouseEvent;
import javafx.scene.input.TouchEvent; import javafx.scene.input.TouchEvent;
import javafx.scene.layout.Pane;
import javafx.stage.Stage; import javafx.stage.Stage;
import me.lensferno.dogename.utils.DialogMaker; import me.lensferno.dogename.select.Selector;
import me.lensferno.dogename.choose.Chooser;
import me.lensferno.dogename.configs.MainConfig; import me.lensferno.dogename.configs.MainConfig;
import me.lensferno.dogename.configs.VoiceConfig; import me.lensferno.dogename.configs.VoiceConfig;
import me.lensferno.dogename.controllers.WindowListeners.MoveWindowByMouse; import me.lensferno.dogename.controllers.WindowListeners.MoveWindowByMouse;
import me.lensferno.dogename.controllers.WindowListeners.MoveWindowByTouch; import me.lensferno.dogename.controllers.WindowListeners.MoveWindowByTouch;
import me.lensferno.dogename.data.History;
import me.lensferno.dogename.data.NameData; import me.lensferno.dogename.data.NameData;
import me.lensferno.dogename.voice.Token; import me.lensferno.dogename.voice.Token;
@ -45,10 +42,6 @@ public class MiniPaneController {
private Random random=new Random(); private Random random=new Random();
private NameData nameData; private NameData nameData;
private Pane rootPane;
private History history;
private Token token;
private VoiceConfig voiceConfig;
Stage currentStage; Stage currentStage;
Scene currentScene; Scene currentScene;
@ -61,17 +54,10 @@ public class MiniPaneController {
this.currentStage = currentStage; this.currentStage = currentStage;
} }
public void setBase(History history, NameData nameData, Token token, VoiceConfig voiceConfig, MainConfig mainConfig){ public void setBase(NameData nameData, MainConfig mainConfig, Selector selector){
this.history = history;
this.nameData = nameData; this.nameData = nameData;
this.token=token;
this.voiceConfig=voiceConfig;
this.mainConfig=mainConfig; this.mainConfig=mainConfig;
this.selector = selector;
} }
@FXML @FXML
@ -102,90 +88,66 @@ public class MiniPaneController {
miniModeBtn.setOnTouchMoved(touchHandler); miniModeBtn.setOnTouchMoved(touchHandler);
} }
private MainConfig mainConfig; private MainConfig mainConfig;
Chooser chooser=new Chooser(); private Selector selector =new Selector();
@FXML @FXML
void anPai() { void anPai() {
if(chooser.isRunning()){
chooser.setForceStop(true); if(selector.isWorkerRunning()){
selector.forceStop();
anPaiBtn.setText("安排一下"); anPaiBtn.setText("安排一下");
return; return;
} }
if(mainConfig.isRandomTimesProperty()) { if(mainConfig.getRandomCount()) {
mainConfig.setCycleTimesProperty(100+random.nextInt(151)); mainConfig.setMaxTotalCount(100+random.nextInt(151));
} }
if(mainConfig.isNameChooseProperty()){ if(mainConfig.getNameChoose()){
runNameMode(chooser); runNameMode();
}else { } else {
runNumberMode(chooser); runNumberMode();
} }
} }
private void runNameMode(){
private void runNameMode(Chooser chooser){
if(nameData.isEmpty()){ if(nameData.isEmpty()){
return; return;
} }
if((nameData.getIgnoreNameList().size()>=nameData.getSize())&&mainConfig.isIgnorePastProperty()){ if((nameData.getIgnoreNameList().size()>=nameData.getSize())&&mainConfig.getPassSelectedResult()){
return; return;
} }
anPaiBtn.setText("不玩了!"); anPaiBtn.setText("不玩了!");
chooser.set(chosenNameLabel.textProperty(),chosenNameLabel.textProperty(),anPaiBtn,history,nameData,token,voiceConfig); selector.run();
chooser.run(
(short)(100-mainConfig.getSpeedProperty()) ,
mainConfig.getCycleTimesProperty(),
mainConfig.isIgnorePastProperty(),
mainConfig.isEqualModeProperty(),
mainConfig.isVoicePlayProperty()
);
} }
private void runNumberMode(){
private void runNumberMode(Chooser chooser){
try{ try{
int minNumber=Integer.parseInt(mainConfig.getMinNumberProperty()); int minNumber=Integer.parseInt(mainConfig.getMinNumber());
int maxNumber=Integer.parseInt(mainConfig.getMaxNumberProperty()); int maxNumber=Integer.parseInt(mainConfig.getMaxNumber());
if(maxNumber-minNumber<=0){ if(maxNumber-minNumber<=0){
return; return;
} }
if(nameData.getIgnoreNumberList().size()>=(maxNumber-minNumber+1) && mainConfig.isIgnorePastProperty()){ if(nameData.getIgnoreNumberList().size()>=(maxNumber-minNumber+1) && mainConfig.getPassSelectedResult()){
return; return;
} }
}catch (Exception e){ }catch (Exception e){
new DialogMaker(rootPane).createMessageDialog("嗯哼?","倒是输入个有效的数字啊~");
return; return;
} }
anPaiBtn.setText("不玩了!"); anPaiBtn.setText("不玩了!");
chooser.set(chosenNameLabel.textProperty(),chosenNameLabel.textProperty(),anPaiBtn,history,nameData,token,voiceConfig); selector.run();
chooser.run(
Short.parseShort(mainConfig.getMaxNumberProperty()),
Short.parseShort(mainConfig.getMinNumberProperty()),
(short)(100-mainConfig.getSpeedProperty()) ,
mainConfig.getCycleTimesProperty(),
mainConfig.isIgnorePastProperty(),
mainConfig.isEqualModeProperty(),
mainConfig.isVoicePlayProperty()
);
} }
} }

@ -29,10 +29,10 @@ public class NumberSettingsPaneController extends VBox {
public void bindProperties(MainConfig mainConfig){ public void bindProperties(MainConfig mainConfig){
minValueField.textProperty().bindBidirectional(mainConfig.minNumberPropertyProperty()); minValueField.textProperty().bindBidirectional(mainConfig.minNumberProperty());
minValueField.textProperty().addListener((observable, oldValue, newValue) -> nameData.clearNumberIgnoreList() ); minValueField.textProperty().addListener((observable, oldValue, newValue) -> nameData.clearNumberIgnoreList() );
maxValueField.textProperty().bindBidirectional(mainConfig.maxNumberPropertyProperty()); maxValueField.textProperty().bindBidirectional(mainConfig.maxNumberProperty());
maxValueField.textProperty().addListener((observable, oldValue, newValue) -> nameData.clearNumberIgnoreList() ); maxValueField.textProperty().addListener((observable, oldValue, newValue) -> nameData.clearNumberIgnoreList() );
} }

@ -84,25 +84,25 @@ public class SettingsPaneController extends VBox {
public void bindProperties(MainConfig mainConfig){ public void bindProperties(MainConfig mainConfig){
setMainConfig(mainConfig); setMainConfig(mainConfig);
ignoreOnce.selectedProperty().bindBidirectional(mainConfig.ignorePastPropertyProperty()); ignoreOnce.selectedProperty().bindBidirectional(mainConfig.passSelectedResultProperty());
chooseOnce.setSelected(!mainConfig.isIgnorePastProperty()); chooseOnce.setSelected(!mainConfig.getPassSelectedResult());
randomTimes.selectedProperty().bindBidirectional(mainConfig.randomTimesPropertyProperty()); randomTimes.selectedProperty().bindBidirectional(mainConfig.randomCountProperty());
fixedTimes.setSelected(!mainConfig.isRandomTimesProperty()); fixedTimes.setSelected(!mainConfig.getRandomCount());
equalModeBtn.selectedProperty().bindBidirectional(mainConfig.equalModePropertyProperty()); equalModeBtn.selectedProperty().bindBidirectional(mainConfig.equalModeProperty());
newAlgoBtn.selectedProperty().bindBidirectional(mainConfig.newAlgoPropertyProperty()); newAlgoBtn.selectedProperty().bindBidirectional(mainConfig.secureRandomProperty());
voicePlayBtn.selectedProperty().bindBidirectional(mainConfig.voicePlayPropertyProperty()); voicePlayBtn.selectedProperty().bindBidirectional(mainConfig.voicePlayProperty());
cycleTimesBar.valueProperty().bindBidirectional(mainConfig.cycleTimesPropertyProperty()); cycleTimesBar.valueProperty().bindBidirectional(mainConfig.maxTotalCountProperty());
speedBar.valueProperty().bindBidirectional(mainConfig.speedPropertyProperty()); speedBar.valueProperty().bindBidirectional(mainConfig.speedProperty());
showSayingBtn.selectedProperty().bindBidirectional(mainConfig.showSayingProperty()); showSayingBtn.selectedProperty().bindBidirectional(mainConfig.showSayingProperty());
mainConfig.ignorePastPropertyProperty().addListener((observable, oldValue, isIgnorePast) -> { mainConfig.passSelectedResultProperty().addListener((observable, oldValue, isIgnorePast) -> {
if(!isIgnorePast) if(!isIgnorePast)
{ {
//如果 忽略被点过的名字 被取消后就把机会均等模式的按钮给取消掉 //如果 忽略被点过的名字 被取消后就把机会均等模式的按钮给取消掉
@ -145,7 +145,7 @@ public class SettingsPaneController extends VBox {
@FXML @FXML
void equalBtnAction(ActionEvent event) { void equalBtnAction(ActionEvent event) {
if(!mainConfig.isIgnorePastProperty()){ if(!mainConfig.getPassSelectedResult()){
equalModeBtn.setSelected(false); equalModeBtn.setSelected(false);
new DialogMaker(rootPane).createMessageDialog("且慢","无法在“概率均分”的模式下使用,如需使用请在“人人有份”模式下启用。"); new DialogMaker(rootPane).createMessageDialog("且慢","无法在“概率均分”的模式下使用,如需使用请在“人人有份”模式下启用。");
} }

@ -53,8 +53,7 @@ public class History {
if(history.size()>2000) { if(history.size()>2000) {
history.clear(); history.clear();
} }
history.add((history.size() + 1) +". "+name); history.add(String.format("%d. %s", (history.size() + 1), name));
writeHistory(); writeHistory();
} }

@ -17,6 +17,9 @@ public class NameData {
private List<String> chooseList; private List<String> chooseList;
private int listSize = 0; private int listSize = 0;
public static final int NAME_ONLY = 0;
public static final int NUMBER_ONLY = 1;
HashSet<String> ignoreNameList=new HashSet<>(); HashSet<String> ignoreNameList=new HashSet<>();
@ -33,30 +36,37 @@ public class NameData {
File nameIgnoreFile =new File("files"+File.separator+"IgnoredNameList.data"); File nameIgnoreFile =new File("files"+File.separator+"IgnoredNameList.data");
File numbIgnoreFile =new File("files"+File.separator+"IgnoredNumberList.data"); File numbIgnoreFile =new File("files"+File.separator+"IgnoredNumberList.data");
public void writeIgnoreList(String switchy){ public void writeIgnoreList(int switchy){
switch (switchy) {
if(!switchy.equals("not name")) { case NAME_ONLY:
try { writeNameIgnoreList();
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(nameIgnoreFile)); case NUMBER_ONLY:
oos.writeObject(ignoreNameList); writeNumberIgnoreList();
oos.close(); default:
} catch (Exception e) { writeNumberIgnoreList();
e.printStackTrace(); writeNameIgnoreList();
}
} }
}
if(!switchy.equals("not number")) { private void writeNameIgnoreList() {
try { try {
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(numbIgnoreFile)); ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(nameIgnoreFile));
oos.writeObject(ignoreNumberList); oos.writeObject(ignoreNameList);
oos.close(); oos.close();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
}
} }
} }
private void writeNumberIgnoreList() {
try {
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(numbIgnoreFile));
oos.writeObject(ignoreNumberList);
oos.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public void readIgnoreList(){ public void readIgnoreList(){
@ -66,7 +76,7 @@ public class NameData {
nameIgnoreFile.getParentFile().mkdirs(); nameIgnoreFile.getParentFile().mkdirs();
nameIgnoreFile.createNewFile(); nameIgnoreFile.createNewFile();
ignoreNameList= new HashSet<>(); ignoreNameList= new HashSet<>();
writeIgnoreList("not number"); writeIgnoreList(NAME_ONLY);
return; return;
} }
@ -76,10 +86,10 @@ public class NameData {
}catch (EOFException e){ }catch (EOFException e){
ignoreNameList=new HashSet<>(); ignoreNameList=new HashSet<>();
log.warn("Past name list is empty."); log.warn("Past name list is empty.");
writeIgnoreList("not number"); writeIgnoreList(NAME_ONLY);
}catch (Exception e){ }catch (Exception e){
ignoreNameList=new HashSet<>(); ignoreNameList=new HashSet<>();
writeIgnoreList("not number"); writeIgnoreList(NAME_ONLY);
log.warn("Failed to load past name list:"+e.toString()); log.warn("Failed to load past name list:"+e.toString());
e.printStackTrace(); e.printStackTrace();
} }
@ -90,7 +100,7 @@ public class NameData {
numbIgnoreFile.getParentFile().mkdirs(); numbIgnoreFile.getParentFile().mkdirs();
numbIgnoreFile.createNewFile(); numbIgnoreFile.createNewFile();
ignoreNumberList= new HashSet<>(); ignoreNumberList= new HashSet<>();
writeIgnoreList("not name"); writeIgnoreList(NUMBER_ONLY);
return; return;
} }
@ -100,11 +110,11 @@ public class NameData {
}catch (EOFException e){ }catch (EOFException e){
ignoreNumberList=new HashSet<>(); ignoreNumberList=new HashSet<>();
log.warn("Ignored number list is empty."); log.warn("Ignored number list is empty.");
writeIgnoreList("not name"); writeIgnoreList(NUMBER_ONLY);
}catch (Exception e){ }catch (Exception e){
ignoreNumberList=new HashSet<>(); ignoreNumberList=new HashSet<>();
log.warn("Failed to load ignored number list"); log.warn("Failed to load ignored number list");
writeIgnoreList("not name"); writeIgnoreList(NUMBER_ONLY);
e.printStackTrace(); e.printStackTrace();
} }
@ -114,12 +124,12 @@ public class NameData {
public void clearNameIgnoreList(){ public void clearNameIgnoreList(){
ignoreNameList.clear(); ignoreNameList.clear();
writeIgnoreList("not number"); writeIgnoreList(NAME_ONLY);
} }
public void clearNumberIgnoreList(){ public void clearNumberIgnoreList(){
ignoreNumberList.clear(); ignoreNumberList.clear();
writeIgnoreList("not name"); writeIgnoreList(NUMBER_ONLY);
} }
@ -316,8 +326,8 @@ public class NameData {
Random random =new Random(); Random random =new Random();
//------------------------------------------------------ //------------------------------------------------------
public String randomGet(){ public String randomGet(boolean secureRandom){
if(newAlgo) if(secureRandom)
return nameList.get(secRandom.nextInt(nameList.size())); return nameList.get(secRandom.nextInt(nameList.size()));
else else
return nameList.get(random.nextInt(nameList.size())); return nameList.get(random.nextInt(nameList.size()));

@ -0,0 +1,104 @@
package me.lensferno.dogename.select;
import javafx.animation.AnimationTimer;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.StringProperty;
import javafx.beans.value.ChangeListener;
import me.lensferno.dogename.configs.MainConfig;
import me.lensferno.dogename.configs.VoiceConfig;
import me.lensferno.dogename.data.History;
import me.lensferno.dogename.data.NameData;
import me.lensferno.dogename.select.core.Worker;
import me.lensferno.dogename.voice.TokenManager;
import me.lensferno.dogename.voice.VoicePlayer;
public final class Selector {
Processor processor = new Processor();
private VoicePlayer voicePlayer = null;
public Selector() {
initialVoicePlayer();
}
public void initialVoicePlayer() {
TokenManager tokenManager = new TokenManager();
VoiceConfig voiceConfig = new VoiceConfig();
tokenManager.init();
if (tokenManager.getTokenStatus() == TokenManager.TOKEN_OK) {
voicePlayer = new VoicePlayer(tokenManager.getToken(), voiceConfig);
}
}
public void run() {
processor.setNumberRange();
processor.updateNewValue();
processor.stoppedIndicatorProperty().set(false);
processor.start();
}
public void forceStop() {
processor.stopProcess();
}
public void initialVariable(MainConfig config, NameData nameData, History history, StringProperty... labelTexts) {
processor.initialVariable(config, voicePlayer, nameData, history, labelTexts);
}
public boolean isWorkerRunning() {
return processor.isWorkerRunning();
}
public void addStoppedEventListener(ChangeListener<? super Boolean> listener) {
processor.stoppedIndicatorProperty().addListener(listener);
}
// ---------------------------------------------------
static class Processor extends AnimationTimer {
private Worker coreWorker;
MainConfig config = null;
protected void initialVariable(MainConfig config, VoicePlayer voicePlayer, NameData nameData, History history, StringProperty... labelTexts) {
coreWorker = new Worker(labelTexts, config, nameData, history, voicePlayer);
this.config = config;
}
protected void updateNewValue() {
coreWorker.setSpeed(100 - config.getSpeed());
coreWorker.setMaxTotalCount(config.getMaxTotalCount());
}
protected SimpleBooleanProperty stoppedIndicatorProperty() {
return coreWorker.stoppedIndicatorProperty();
}
@Override
public void handle(long time) {
coreWorker.displaySelectedResult();
if (coreWorker.getStoppedIndicator()) {
this.stop();
}
}
public void stopProcess() {
coreWorker.setForceStop(true);
}
public boolean isWorkerRunning() {
return !coreWorker.getStoppedIndicator();
}
public void setNumberRange() {
int minNumber = Integer.parseInt(config.getMinNumber());
int maxNumber = Integer.parseInt(config.getMaxNumber());
coreWorker.setNumberRange(minNumber, maxNumber);
}
}
}

@ -0,0 +1,203 @@
package me.lensferno.dogename.select.core;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.StringProperty;
import me.lensferno.dogename.configs.MainConfig;
import me.lensferno.dogename.data.History;
import me.lensferno.dogename.data.NameData;
import me.lensferno.dogename.utils.Random;
import me.lensferno.dogename.voice.VoicePlayer;
public final class Worker {
private final Random randomNumber = new Random();
private final StringProperty[] labelTexts;
private final SimpleBooleanProperty stoppedIndicator = new SimpleBooleanProperty(true);
private final MainConfig config;
//挑选方法
private final int selectMethod = MainConfig.METHOD_NAME;
private final NameData nameData;
private final History history;
private final VoicePlayer voicePlayer;
private int speed = 0;
//数值范围最大最小值
private final int[] numberRange = new int[2];
private final int MIN_NUMBER = 0;
private final int MAX_NUMBER = 1;
//挑选次数和每一轮的挑选次数
private int maxTotalCount = MainConfig.DEFAULT_MAX_TOTAL_COUNT;
private int maxCycleCount = 0;
//已经挑选了多少次
private int totalCount = 0;
private int cycleCount = 0;
private boolean finalResult = true;
private boolean forceStop = false;
private String selectedResult;
private boolean continueSelecting = false;
private int resultLabelId = 0;
private final Counter counter = new Counter();
public Worker(StringProperty[] labelTexts, MainConfig config, NameData nameData, History history, VoicePlayer voicePlayer) {
this.labelTexts = labelTexts;
this.config = config;
this.nameData = nameData;
this.history = history;
this.voicePlayer = voicePlayer;
}
private void select() {
// try的位置待定(前面or后面)
// 延时用,用于调整挑选速度
try {
Thread.sleep(speed);
} catch (Exception e) {
e.printStackTrace();
}
stoppedIndicator.set(false);
// 若 计数已达最大总数(挑选次数)或强制停止,进入停止分支,
if (totalCount >= maxTotalCount || forceStop) {
// 任意三种情况就停止:已忽略名单中没有该名字;不考虑忽略名单;强制停止
// 如果不是这三种情况就选到符合其中一种情况为止
// 由于后两者在安排进程中不可能改变,因此继续挑选后只有选中的结果不在忽略名单中才会结束挑选
// 若忽略名单已满(名单中数量=总的名单数量),点击“安排一下”时会提示已满,无法再进行挑选,因此在运行时总有 忽略名单<总名单,总有名字不在忽略列表中,不会死循环,放心吧
boolean resultIgnored = (config.getChooseMethod() == MainConfig.METHOD_NAME) ? (nameData.getIgnoreNameList().contains(selectedResult)) : (nameData.getIgnoreNumberList().contains(selectedResult));
if (!resultIgnored || !config.getPassSelectedResult() || forceStop) {
this.stopSelect();
finalResult = true;
return;
} else {
continueSelecting = true;
}
}
counter.count();
resultLabelId = counter.getNewResultLabelId();
finalResult = false;
this.selectedResult = this.pick(config.getChooseMethod());
}
public void stopSelect() {
if (config.getPassSelectedResult()) {
nameData.getIgnoreNameList().add(selectedResult);
}
if (config.getEqualMode()) {
nameData.writeIgnoreList(NameData.NAME_ONLY);
}
history.addHistory(selectedResult);
if (config.getVoicePlay() && voicePlayer != null) {
voicePlayer.playVoice(selectedResult);
}
counter.resetCounter();
stoppedIndicator.set(true);
forceStop = false;
System.gc();
}
private String pick(int selectMethod) {
switch (selectMethod) {
case MainConfig.METHOD_NAME:
return nameData.randomGet(config.getSecureRandom());
case MainConfig.METHOD_NUMBER:
randomNumber.setUseSecureRandom(config.getSecureRandom());
return String.valueOf(randomNumber.getRandomNumber(numberRange[MIN_NUMBER], numberRange[MAX_NUMBER]));
default:
return "(´・ω・`)?";
}
}
public void displaySelectedResult() {
this.select();
if (!finalResult) {
labelTexts[resultLabelId].set(selectedResult);
} else {
for (StringProperty labelText : labelTexts) {
if (labelText.get().contains("→")) {
labelText.set(labelText.get().replace("→", "").replace("←", ""));
}
}
labelTexts[resultLabelId].set(String.format("→%s←", selectedResult));
}
}
// 这里有个内部类Counter计数菌
final class Counter {
private int newResultLabelId = 0;
protected void count() {
newResultLabelId = resultLabelId;
// 每一轮的计数到达最大时并且不强制继续这轮挑选时,重置这一轮的挑选,并指派新的显示label
// 否则这一轮的计数直接+1
if (cycleCount >= maxCycleCount && !continueSelecting) {
cycleCount = 0;
maxCycleCount = randomNumber.getRandomNumber(1, maxTotalCount - totalCount);
newResultLabelId = randomNumber.getRandomNumber(labelTexts.length - 1);
} else {
cycleCount++;
}
totalCount++;
}
protected void resetCounter() {
totalCount = 0;
cycleCount = 0;
maxCycleCount = 0;
continueSelecting = false;
}
protected int getNewResultLabelId() {
return newResultLabelId;
}
}
public boolean getStoppedIndicator() {
return stoppedIndicator.get();
}
public SimpleBooleanProperty stoppedIndicatorProperty() {
return stoppedIndicator;
}
public void setNumberRange(int minNumber, int maxNumber) {
this.numberRange[MIN_NUMBER] = minNumber;
this.numberRange[MAX_NUMBER] = maxNumber;
}
public void setForceStop(boolean forceStop) {
this.forceStop = forceStop;
}
public void setMaxTotalCount(int maxTotalCount) {
this.maxTotalCount = maxTotalCount;
}
public void setSpeed(int speed) {
this.speed = speed;
}
}

@ -17,6 +17,10 @@ public class HtmlRequseter {
static Logger log = LogManager.getLogger(); static Logger log = LogManager.getLogger();
public static String getHtml(String address) {
return getHtml(address, false);
}
public static String getHtml(String address,boolean output) public static String getHtml(String address,boolean output)
{ {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
@ -29,10 +33,6 @@ public class HtmlRequseter {
conn.setRequestProperty("Accept-Encoding", "gzip,deflate"); conn.setRequestProperty("Accept-Encoding", "gzip,deflate");
conn.connect(); conn.connect();
System.out.println("--------------------------------------------------------------------");
System.out.println("[INFO]Getting:"+conn.getURL());
System.out.println("[INFO]Content compress type:"+conn.getContentEncoding());
InputStream is = conn.getInputStream(); InputStream is = conn.getInputStream();
String connEncoding=conn.getContentEncoding(); String connEncoding=conn.getContentEncoding();

@ -0,0 +1,32 @@
package me.lensferno.dogename.utils;
import java.security.SecureRandom;
public final class Random {
private final java.util.Random random = new java.util.Random();
private final java.util.Random secRandom = new SecureRandom();
private boolean useSecureRandom = true;
public void setUseSecureRandom(boolean useSecureRandom) {
this.useSecureRandom = useSecureRandom;
}
public int getRandomNumber (int minNumber, int maxNumber) {
if (useSecureRandom){
return minNumber + secRandom.nextInt(maxNumber - minNumber + 1);
} else {
return minNumber + random.nextInt(maxNumber - minNumber + 1);
}
}
public int getRandomNumber (int maxNumber) {
if (useSecureRandom){
return secRandom.nextInt(maxNumber + 1);
} else {
return random.nextInt(maxNumber + 1);
}
}
}

@ -14,12 +14,14 @@ public class TokenManager {
Logger log= LogManager.getLogger(); Logger log= LogManager.getLogger();
public static final String separator=File.separator; public static final String separator=File.separator;
String cachedVoicePath="caches\\voice\\";
final private int TOKEN_NULL = -2; private final int TOKEN_NULL = -2;
final private int TOKEN_EXPIRED = -1; private final int TOKEN_EXPIRED = -1;
final private int TOKEN_OK = 0;
public static final int TOKEN_OK = 0;
public static final int TOKEN_BAD = 1;
private int tokenStatus = TOKEN_OK;
final String API_KEY="dIHCtamVdD0ERO1yyFir2iI4"; final String API_KEY="dIHCtamVdD0ERO1yyFir2iI4";
final String SEC_KEY="HmpBQY3gG4PyZ0cmudnCbMeoMcMejuuW"; final String SEC_KEY="HmpBQY3gG4PyZ0cmudnCbMeoMcMejuuW";
@ -28,36 +30,33 @@ public class TokenManager {
File tokenFile=new File("API_voice.token"); File tokenFile=new File("API_voice.token");
private Token token=null; private Token token = null;
String tokenStatus="ok";
private void updateTokenStatus(int statusCode){ private void updateTokenStatus(int statusCode){
switch(statusCode){ switch(statusCode){
case TOKEN_OK: case TOKEN_OK:
tokenStatus="ok"; tokenStatus = TOKEN_OK;
break; break;
case TOKEN_EXPIRED:
if(netAvailable()){ refreshToken();}
if(checkTokenAvailable()!=0){ tokenStatus="not ok";} case TOKEN_EXPIRED:
break;
case TOKEN_NULL:
if(netAvailable()){ refreshToken();}
if(checkTokenAvailable()!=0){ tokenStatus="not ok";} case TOKEN_NULL:
break; if(netAvailable()){
refreshToken();
default : }
tokenStatus="not ok";
if(checkTokenAvailable()!=0){
tokenStatus = TOKEN_BAD;
}
break;
default :
tokenStatus = TOKEN_BAD;
break; break;
} }
} }
private void refreshToken(){ private void refreshToken(){
fetchToken(); fetchToken();
writeToken(); writeToken();
} }
@ -78,13 +77,13 @@ public class TokenManager {
updateTokenStatus(checkTokenAvailable()); updateTokenStatus(checkTokenAvailable());
}else { }else {
tokenStatus="not ok"; tokenStatus = TOKEN_BAD;
} }
} }
} }
public String getTokenStatus() { public int getTokenStatus() {
return tokenStatus; return tokenStatus;
} }

@ -1,6 +1,7 @@
package me.lensferno.dogename.voice; package me.lensferno.dogename.voice;
import javazoom.spi.mpeg.sampled.file.MpegAudioFileReader; import javazoom.spi.mpeg.sampled.file.MpegAudioFileReader;
import me.lensferno.dogename.configs.VoiceConfig;
import me.lensferno.dogename.utils.FileProcessor; import me.lensferno.dogename.utils.FileProcessor;
import okhttp3.*; import okhttp3.*;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
@ -23,12 +24,13 @@ public class VoicePlayer {
Logger log= LogManager.getLogger("VoicePlayerLogger"); Logger log= LogManager.getLogger("VoicePlayerLogger");
private final String VOICE_API="https://tsn.baidu.com/text2audio"; private final String VOICE_API="https://tsn.baidu.com/text2audio";
private VoiceConfig voiceConfig = null;
Token token; Token token;
public VoicePlayer(Token token){ public VoicePlayer(Token token, VoiceConfig voiceConfig){
this.token=token; this.token = token;
this.voiceConfig = voiceConfig;
} }
String cachedVoicePath="caches"+separator+"voice"+separator; String cachedVoicePath="caches"+separator+"voice"+separator;
@ -42,10 +44,14 @@ public class VoicePlayer {
.build(); .build();
public void playVoice(String name,String speaker,String intonation,String speed) { public void playVoice(String name) {
String speaker = voiceConfig.getSpeaker();
String intonation = String.valueOf(voiceConfig.getIntonation());
String speed = String.valueOf(voiceConfig.getSpeed());
String cachedVoiceName; String cachedVoiceName;
cachedVoiceName = name + "_" + speaker+ "_" + speed +"_"+intonation; cachedVoiceName = name + "_" + speaker+ "_" + speed +"_"+intonation;
cachedVoiceName = String.format("%s_%s_%s_%s", name, speaker, speed,intonation);
File cachedVoice = new File(cachedVoicePath + cachedVoiceName + ".mp3"); File cachedVoice = new File(cachedVoicePath + cachedVoiceName + ".mp3");

@ -1,28 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.*?>
<?import javafx.scene.effect.*?>
<?import javafx.scene.paint.*?>
<?import java.lang.*?>
<?import javafx.scene.*?> <?import javafx.scene.*?>
<?import javafx.scene.control.*?> <?import javafx.scene.control.*?>
<?import javafx.scene.image.*?> <?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?> <?import javafx.scene.layout.*?>
<?import javafx.scene.shape.*?> <?import javafx.scene.shape.*?>
<?import com.jfoenix.controls.*?> <?import com.jfoenix.controls.*?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.Cursor?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.shape.Line?>
<?import javafx.scene.text.*?> <?import javafx.scene.text.*?>
<Pane fx:id="rootPane" prefHeight="711.0" prefWidth="1007.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="me.lensferno.dogename.controllers.MainInterfaceController"> <Pane fx:id="rootPane" prefHeight="711.0" prefWidth="1007.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="me.lensferno.dogename.controllers.MainInterfaceController">
<children> <children>
<Pane fx:id="mainPane" prefHeight="710.0" prefWidth="1007.0"> <Pane fx:id="mainPane" prefHeight="710.0" prefWidth="1007.0">
<children> <children>
<Label fx:id="chosen_1" alignment="CENTER" layoutX="194.0" layoutY="60.0" prefHeight="117.0" prefWidth="650.0" text="(´□`川)" textAlignment="CENTER" wrapText="true"> <Label fx:id="upperLabel" alignment="CENTER" layoutX="194.0" layoutY="60.0" prefHeight="117.0" prefWidth="650.0" text="(´□`川)" textAlignment="CENTER" wrapText="true">
<font> <font>
<Font name="Microsoft YaHei" size="86.0" /> <Font name="Microsoft YaHei" size="86.0" />
</font> </font>
@ -31,7 +21,7 @@
<font> <font>
<Font name="Microsoft YaHei" size="14.0" /> <Font name="Microsoft YaHei" size="14.0" />
</font></JFXButton> </font></JFXButton>
<Label fx:id="chosen_2" alignment="CENTER" layoutX="194.0" layoutY="177.0" prefHeight="117.0" prefWidth="650.0" text="✋( ˙0˙)" textAlignment="CENTER" wrapText="true"> <Label fx:id="downLabel" alignment="CENTER" layoutX="194.0" layoutY="177.0" prefHeight="117.0" prefWidth="650.0" text="✋( ˙0˙)" textAlignment="CENTER" wrapText="true">
<font> <font>
<Font name="Microsoft YaHei" size="86.0" /> <Font name="Microsoft YaHei" size="86.0" />
</font> </font>

Loading…
Cancel
Save