Add listener to appid textfield

Added "Get DLCs for AppID" button (inactive)
This commit is contained in:
Jeddunk 2019-11-04 18:58:40 +01:00
parent aa057fca91
commit 0eedf452d7
4 changed files with 38 additions and 9 deletions

5
.idea/vcs.xml generated
View File

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="" />
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
</project>

View File

@ -1,19 +1,18 @@
import com.ibasco.agql.protocols.valve.steam.webapi.pojos.SteamApp;
import com.jfoenix.controls.*;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.scene.control.Tooltip;
import javafx.stage.FileChooser;
import org.apache.commons.configuration2.ex.ConfigurationException;
import javax.swing.*;
import java.io.File;
import java.io.IOException;
public class Controller {
public JFXButton path_button;
private CreamApiConfig config = CreamApiConfig.getInstance();
private SteamAppsListCache cache = new SteamAppsListCache();
@FXML public JFXTextField path_textfield;
@ -27,14 +26,18 @@ public class Controller {
@FXML public JFXButton reset_button;
@FXML public JFXButton save_button;
@FXML public JFXButton getAppId_button;
@FXML public JFXButton path_button;
@FXML public JFXButton retrieveDlcList_button;
public Controller() {}
@FXML
public void initialize() {
read();
appId_textfield.textProperty().addListener(appIdChangesGameName());
retrieveDlcList_button.setDisable(true); // WIP
generate_tooltips();
fix_dlc_textarea_prompt_text();
read();
}
private void read() {
@ -59,6 +62,23 @@ public class Controller {
Tooltip.install(extra_protection_checkbox, extra_protection_tooltip);
}
private ChangeListener<String> appIdChangesGameName() {
return (observable, oldValue, newValue) -> {
int appId;
try {
appId = Integer.parseInt(newValue);
final SteamApp game = cache.getGame(appId);
if (game != null) {
game_name_textfield.setText(game.getName());
} else {
game_name_textfield.setText("");
}
} catch (NumberFormatException e) {
game_name_textfield.setText("");
}
};
}
public void reset() {
config.read();
read();
@ -79,7 +99,7 @@ public class Controller {
}
public void getAppId() {
final SteamApp game = cache.getGame(game_name_textfield.getText());
final SteamApp game = cache.searchGame(game_name_textfield.getText());
if (game == null) {
appId_textfield.setText("-1");
} else {

View File

@ -49,6 +49,15 @@ public class SteamAppsListCache {
return null;
}
public SteamApp searchGame(String name) {
for (SteamApp app : list.steamAppsList) {
if (app.getName().toLowerCase().contains(name.toLowerCase())) {
return app;
}
}
return null;
}
private void getListFromApi() {
SteamWebApiClient client = new SteamWebApiClient();
SteamApps steamApps = new SteamApps(client);

View File

@ -39,7 +39,7 @@
<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" GridPane.columnIndex="1" GridPane.rowIndex="1">
<graphic>
<FontAwesomeIconView glyphName="ARROW_RIGHT" glyphSize="24" />
<FontAwesomeIconView glyphName="SEARCH" glyphSize="24" />
</graphic>
</JFXButton>
<JFXTextField fx:id="appId_textfield" prefWidth="299.0" promptText="Steam AppID..." GridPane.columnIndex="2" GridPane.rowIndex="1" />
@ -48,6 +48,7 @@
<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" 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" text="Save" GridPane.columnIndex="1" GridPane.rowIndex="7" />
<JFXButton fx:id="reset_button" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" onAction="#reset" text="Reset" GridPane.columnIndex="2" GridPane.rowIndex="7" />
</GridPane>