Search function now brings up a window with a list of search results.

This commit is contained in:
Jeddunk 2020-08-24 15:27:34 +02:00
parent 4eda79211e
commit c2254856da
5 changed files with 244 additions and 61 deletions

View File

@ -19,10 +19,13 @@ import javafx.collections.FXCollections;
import javafx.concurrent.Service;
import javafx.concurrent.Task;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Label;
import javafx.scene.control.Tooltip;
import javafx.stage.FileChooser;
import javafx.stage.*;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.configuration2.ex.ConfigurationException;
import org.jsoup.HttpStatusException;
@ -38,6 +41,7 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@ -207,11 +211,28 @@ public class Controller {
}
public void getAppId() {
final App game = cache.findGame(game_name_textfield.getText());
if (game == null) {
//final App game = cache.findGame(game_name_textfield.getText());
final List<App> games = cache.findListOfGames(game_name_textfield.getText());
if (games.isEmpty()) {
appId_textfield.setText("-1");
} else {
appId_textfield.setText(String.valueOf(game.getAppId()));
try {
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("searchResultWindow.fxml"));
Parent root1 = fxmlLoader.load();
SearchResultWindowController c = fxmlLoader.getController();
c.initMe(games);
c.setParentController(this);
Stage stage = new Stage();
stage.initModality(Modality.APPLICATION_MODAL);
//stage.initStyle(StageStyle.UNDECORATED);
stage.setTitle("Choose game...");
stage.setScene(new Scene(root1));
stage.show();
} catch (IOException e) {
e.printStackTrace();
}
}
}

View File

@ -0,0 +1,103 @@
/*
* Auto-CreamAPI
* Copyright (C) 2020 Jeddunk
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see
* <https://www.gnu.org/licenses/>.
*/
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;
import javafx.stage.Stage;
import pojo.App;
import java.util.List;
public class SearchResultWindowController {
@FXML
public Button okButton;
@FXML
public Button cancelButton;
@FXML
public TableView<App> gameTable;
@FXML
public TableColumn<App, Integer> appIdCol;
@FXML
public TableColumn<App, String> nameCol;
public Controller parent;
private long lastTime;
private boolean isdblClicked;
public SearchResultWindowController() {
}
@FXML
public void initialize() {
}
public void initMe(List<App> games) {
ObservableList<App> data = FXCollections.observableArrayList(games);
try {
appIdCol.setCellValueFactory(new PropertyValueFactory<>("appId"));
nameCol.setCellValueFactory(new PropertyValueFactory<>("name"));
gameTable.setItems(data);
} catch (Exception e) {
e.printStackTrace();
}
}
public void confirm() {
App app = gameTable.getSelectionModel().getSelectedItem();
parent.game_name_textfield.setText(app.getName());
parent.appId_textfield.setText(String.valueOf(app.getAppId()));
Stage current = (Stage) okButton.getScene().getWindow();
current.close();
}
public void cancel() {
parent.game_name_textfield.setText("");
parent.appId_textfield.setText("-1");
Stage current = (Stage) cancelButton.getScene().getWindow();
current.close();
}
public void setParentController(Controller controller) {
parent = controller;
}
public void doubleclickConfirm(MouseEvent mouseEvent) {
if (mouseEvent.getButton() == MouseButton.PRIMARY) {
long diff;
long currentTime = System.currentTimeMillis();
if (lastTime != 0 && currentTime != 0) {
diff = currentTime - lastTime;
isdblClicked = (diff <= 215);
}
lastTime = currentTime;
if (isdblClicked) {
App app = gameTable.getSelectionModel().getSelectedItem();
parent.game_name_textfield.setText(app.getName());
parent.appId_textfield.setText(String.valueOf(app.getAppId()));
Stage current = (Stage) gameTable.getScene().getWindow();
current.close();
}
}
}
}

View File

@ -92,32 +92,38 @@ public class SteamAppsListCache {
.filter(app -> app.getName().equalsIgnoreCase(name)).findFirst().orElse(null);
}
public App findGame(String name) {
List<BoundExtractedResult<App>> match = FuzzySearch.extractTop(name, list.getSteamAppsList(), app ->
app.getName().toLowerCase().replaceAll("[^a-zA-Z0-9\\s+]", ""), 25);
System.out.println("\n\n\n==== Top 25 results for \"" + name + "\": ====");
for (BoundExtractedResult<App> result : match) {
System.out.println(result.getReferent().getName() + " - " +
result.getIndex() + " - " +
result.getScore());
}
System.out.println("\n\n\n");
return match.get(0).getReferent();
/*for (App app : list.getSteamAppsList()) {
if (app.getName().toLowerCase().replaceAll("[^a-zA-Z0-9\\s+]", "")
.startsWith(name.toLowerCase().replaceAll("[^a-zA-Z0-9\\s+]", ""))) {
return app;
}
}
for (App app : list.getSteamAppsList()) {
if (app.getName().toLowerCase().replaceAll("[^a-zA-Z0-9\\s+]", "")
.contains(name.toLowerCase().replaceAll("[^a-zA-Z0-9\\s+]", ""))) {
return app;
}
}*/
//return null;
public List<App> findListOfGames(String name) {
List<BoundExtractedResult<App>> match = FuzzySearch.extractSorted(name, list.getSteamAppsList(), app ->
app.getName().toLowerCase().replaceAll("[^a-zA-Z0-9\\s+]", ""), 80);
return match.stream().map(BoundExtractedResult::getReferent).collect(Collectors.toList());
}
// public App findGame(String name) {
// List<BoundExtractedResult<App>> match = FuzzySearch.extractSorted(name, list.getSteamAppsList(), app ->
// app.getName().toLowerCase().replaceAll("[^a-zA-Z0-9\\s+]", ""), 80);
// /*System.out.println("\n\n\n==== Top 25 results for \"" + name + "\": ====");
// for (BoundExtractedResult<App> result : match) {
// System.out.println(result.getReferent().getName() + " - " +
// result.getIndex() + " - " +
// result.getScore());
// }
// System.out.println("\n\n\n");*/
// return match.get(0).getReferent();
// /*for (App app : list.getSteamAppsList()) {
// if (app.getName().toLowerCase().replaceAll("[^a-zA-Z0-9\\s+]", "")
// .startsWith(name.toLowerCase().replaceAll("[^a-zA-Z0-9\\s+]", ""))) {
// return app;
// }
// }
// for (App app : list.getSteamAppsList()) {
// if (app.getName().toLowerCase().replaceAll("[^a-zA-Z0-9\\s+]", "")
// .contains(name.toLowerCase().replaceAll("[^a-zA-Z0-9\\s+]", ""))) {
// return app;
// }
// }*/
// //return null;
// }
private void getListFromApi() {
System.out.println("Trying to get SteamAppList from API...");
List<App> apps = getApps();

View File

@ -27,7 +27,8 @@
~ <https://www.gnu.org/licenses/>.
-->
<GridPane hgap="10.0" minHeight="400.0" minWidth="655.0" vgap="10.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="Controller">
<GridPane hgap="10.0" minHeight="400.0" minWidth="655.0" vgap="10.0" xmlns="http://javafx.com/javafx/8.0.171"
xmlns:fx="http://javafx.com/fxml/1" fx:controller="Controller">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="1.7976931348623157E308" minWidth="-Infinity" prefWidth="375.0"/>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="-Infinity" minWidth="-Infinity" prefWidth="120.0"/>
@ -48,25 +49,42 @@
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0"/>
</padding>
<JFXTextField fx:id="path_textfield" promptText="Path to game's steam_api(64).dll..." GridPane.columnSpan="2"/>
<JFXButton fx:id="path_button" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" onAction="#openFileChooser" ripplerFill="BLACK" style="-fx-background-color: #ddd;" GridPane.columnIndex="2">
<JFXButton fx:id="path_button" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308"
minHeight="-Infinity" minWidth="-Infinity" onAction="#openFileChooser" ripplerFill="BLACK"
style="-fx-background-color: #ddd;" GridPane.columnIndex="2">
<graphic>
<FontAwesomeIconView glyphName="FOLDER_OPEN" glyphSize="24"/>
</graphic>
</JFXButton>
<JFXTextField fx:id="game_name_textfield" promptText="Game..." GridPane.rowIndex="1"/>
<JFXButton fx:id="getAppId_button" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" onAction="#getAppId" ripplerFill="BLACK" style="-fx-background-color: #ddd;" GridPane.columnIndex="1" GridPane.rowIndex="1">
<JFXButton fx:id="getAppId_button" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308"
minHeight="-Infinity" minWidth="-Infinity" onAction="#getAppId" ripplerFill="BLACK"
style="-fx-background-color: #ddd;" GridPane.columnIndex="1" GridPane.rowIndex="1">
<graphic>
<FontAwesomeIconView glyphName="SEARCH" glyphSize="24"/>
</graphic>
</JFXButton>
<JFXTextField fx:id="appId_textfield" prefWidth="299.0" promptText="Steam AppID..." GridPane.columnIndex="2" GridPane.rowIndex="1" />
<JFXComboBox fx:id="language_combobox" editable="true" promptText="Language" GridPane.columnSpan="2147483647" GridPane.rowIndex="2" />
<JFXCheckBox fx:id="offline_checkbox" text="Force offline mode" GridPane.columnSpan="2147483647" GridPane.rowIndex="3" />
<JFXCheckBox fx:id="extra_protection_checkbox" text="Try to bypass game-specific protection" GridPane.columnSpan="2147483647" GridPane.rowIndex="4" />
<JFXCheckBox fx:id="unlock_all_checkbox" onAction="#unlockAll_disableDlcTextArea" text="Unlock all DLC (if possible)" GridPane.columnSpan="2147483647" GridPane.rowIndex="5" />
<JFXTextArea fx:id="dlc_textarea" promptText="List of DLC..." GridPane.columnSpan="2147483647" GridPane.rowIndex="6" />
<JFXButton fx:id="retrieveDlcList_button" maxHeight="1.7976931348623157E308" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" onAction="#getDlcList" ripplerFill="BLACK" style="-fx-background-color: #ddd;" text="Get DLCs for AppID" GridPane.rowIndex="7" />
<JFXButton fx:id="save_button" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" onAction="#save" ripplerFill="BLACK" style="-fx-background-color: #ddd;" text="Save" GridPane.columnIndex="1" GridPane.rowIndex="7" />
<JFXButton fx:id="reset_button" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" onAction="#resetFromButton" ripplerFill="BLACK" style="-fx-background-color: #ddd;" text="Reset" GridPane.columnIndex="2" GridPane.rowIndex="7" />
<Label fx:id="state_label" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" GridPane.columnSpan="2147483647" GridPane.rowIndex="8" />
<JFXTextField fx:id="appId_textfield" prefWidth="299.0" promptText="Steam AppID..." GridPane.columnIndex="2"
GridPane.rowIndex="1"/>
<JFXComboBox fx:id="language_combobox" editable="true" promptText="Language" GridPane.columnSpan="2147483647"
GridPane.rowIndex="2"/>
<JFXCheckBox fx:id="offline_checkbox" text="Force offline mode" GridPane.columnSpan="2147483647"
GridPane.rowIndex="3"/>
<JFXCheckBox fx:id="extra_protection_checkbox" text="Try to bypass game-specific protection"
GridPane.columnSpan="2147483647" GridPane.rowIndex="4"/>
<JFXCheckBox fx:id="unlock_all_checkbox" onAction="#unlockAll_disableDlcTextArea"
text="Unlock all DLC (if possible)" GridPane.columnSpan="2147483647" GridPane.rowIndex="5"/>
<JFXTextArea fx:id="dlc_textarea" promptText="List of DLC..." GridPane.columnSpan="2147483647"
GridPane.rowIndex="6"/>
<JFXButton fx:id="retrieveDlcList_button" maxHeight="1.7976931348623157E308" maxWidth="-Infinity"
minHeight="-Infinity" minWidth="-Infinity" onAction="#getDlcList" ripplerFill="BLACK"
style="-fx-background-color: #ddd;" text="Get DLCs for AppID" GridPane.rowIndex="7"/>
<JFXButton fx:id="save_button" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308"
minHeight="-Infinity" minWidth="-Infinity" onAction="#save" ripplerFill="BLACK"
style="-fx-background-color: #ddd;" text="Save" GridPane.columnIndex="1" GridPane.rowIndex="7"/>
<JFXButton fx:id="reset_button" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308"
minHeight="-Infinity" minWidth="-Infinity" onAction="#resetFromButton" ripplerFill="BLACK"
style="-fx-background-color: #ddd;" text="Reset" GridPane.columnIndex="2" GridPane.rowIndex="7"/>
<Label fx:id="state_label" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308"
minHeight="-Infinity" minWidth="-Infinity" GridPane.columnSpan="2147483647" GridPane.rowIndex="8"/>
</GridPane>

View File

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<VBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="655.0"
prefWidth="420.0" xmlns="http://javafx.com/javafx/10.0.2-internal" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="SearchResultWindowController">
<opaqueInsets>
<Insets/>
</opaqueInsets>
<padding>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0"/>
</padding>
<Label maxWidth="1.7976931348623157E308" text="Choose a game from the list below:"/>
<TableView fx:id="gameTable" maxHeight="1.7976931348623157E308" onMouseClicked="#doubleclickConfirm"
prefHeight="570.0" prefWidth="400.0">
<columns>
<TableColumn fx:id="appIdCol" editable="false" maxWidth="100.0" minWidth="100.0" prefWidth="100.0"
text="AppID"/>
<TableColumn fx:id="nameCol" editable="false" maxWidth="285.0" minWidth="285.0" prefWidth="285.0"
text="Name"/>
</columns>
<VBox.margin>
<Insets bottom="10.0" top="10.0"/>
</VBox.margin>
</TableView>
<ButtonBar prefHeight="40.0" prefWidth="200.0">
<buttons>
<Button fx:id="okButton" mnemonicParsing="false" onAction="#confirm" text="OK"/>
<Button fx:id="cancelButton" mnemonicParsing="false" onAction="#cancel" text="Cancel"/>
</buttons>
</ButtonBar>
</VBox>