Skip to content

Commit

Permalink
Now has a config value of "develop" (default to false)
Browse files Browse the repository at this point in the history
If true, it will show up the dialog box to choose the old or new GUI
  • Loading branch information
JFCaron authored and JFCaron committed Aug 9, 2016
1 parent cd62c62 commit 9ae123c
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 19 deletions.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
33 changes: 30 additions & 3 deletions src/me/corriekay/pokegoutil/BlossomsPoGoManager.java
@@ -1,6 +1,9 @@
package me.corriekay.pokegoutil;

import java.io.IOException;
import java.net.URL;

import javax.swing.SwingUtilities;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
Expand All @@ -9,6 +12,10 @@
import javafx.scene.image.Image;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import me.corriekay.pokegoutil.controllers.AccountController;
import me.corriekay.pokegoutil.utils.Config;
import me.corriekay.pokegoutil.utils.Console;
import me.corriekay.pokegoutil.utils.Utilities;


public class BlossomsPoGoManager extends Application{
Expand All @@ -23,20 +30,40 @@ public static void main(String[] args) {
@Override
public void start(Stage primaryStage){
//@SuppressWarnings("static-access")
openGUIChooser(primaryStage);
if (Config.getConfig().getBool("develop", false))
openGUIChooser(primaryStage);
else
openOldGui();
}

private void openOldGui() {
SwingUtilities.invokeLater(new Runnable() {
private Console console;

@Override
public void run() {
Utilities.setNativeLookAndFeel();
console = new Console("Console", 0, 0, true);
console.setVisible(false);
AccountController.initialize(console);
AccountController.logOn();
}
});
}

public void openGUIChooser(Stage primaryStage) {
if (primaryStage!=null) {
Parent root;
ClassLoader classLoader = getClass().getClassLoader();
try {
root = (Parent) FXMLLoader.load(getClass().getClassLoader().getResource("resources/layout/ChooseGUIWindow.fxml"));
root = (Parent) FXMLLoader.load(classLoader.getResource("layout/ChooseGUIWindow.fxml"));
} catch (IOException e) {
System.err.println("Problem loading .fxml file: " + e.toString());
return;
}
primaryStage.setScene(new Scene(root));
primaryStage.getIcons().add(new Image("resources/icon/PokeBall-icon.png"));
URL image = classLoader.getResource("icon/PokeBall-icon.png");
primaryStage.getIcons().add(new Image(image.toExternalForm()));
primaryStage.setTitle("Choose a GUI");
primaryStage.initStyle(StageStyle.UTILITY);
primaryStage.show();
Expand Down
Expand Up @@ -21,6 +21,8 @@

public class ChooseGuiWindowController extends Pane{

private ClassLoader classLoader;

@FXML
private ResourceBundle resources;

Expand All @@ -35,25 +37,26 @@ public class ChooseGuiWindowController extends Pane{

@FXML
void initialize() {
classLoader = getClass().getClassLoader();
}

@FXML
void onNewGuiBtnClicked(ActionEvent event){
oldGuiBtn.getScene().getWindow().hide();

//@SuppressWarnings("static-access")
Parent root;
try {
root = (Parent) FXMLLoader.load(ChooseGuiWindowController.class.getClassLoader().getResource("resources/layout/Login.fxml"));
root = (Parent) FXMLLoader.load(classLoader.getResource("layout/Login.fxml"));
} catch (IOException e) {
System.err.println("Error loading resource: resources/layout/Login.fxml" );
System.err.println("Error loading resource: layout/Login.fxml" );
return;
}
Scene scene = new Scene(root);

Stage mainWindow = new Stage();

mainWindow.getIcons().add(new Image("/resources/icon/PokeBall-icon.png"));
URL image = classLoader.getResource("icon/PokeBall-icon.png");
mainWindow.getIcons().add(new Image(image.toExternalForm()));
mainWindow.setTitle("Login");
mainWindow.initStyle(StageStyle.UTILITY);

Expand All @@ -75,8 +78,7 @@ public void run() {
console = new Console("Console", 0, 0, true);
console.setVisible(false);
AccountController.initialize(console);
AccountController.logOn();

AccountController.logOn();
}
});
}
Expand Down
11 changes: 8 additions & 3 deletions src/me/corriekay/pokegoutil/GUI/controller/LoginController.java
@@ -1,6 +1,7 @@
package me.corriekay.pokegoutil.GUI.controller;

import java.io.IOException;
import java.net.URL;
import java.text.NumberFormat;

import com.pokegoapi.api.player.PlayerProfile;
Expand All @@ -24,6 +25,8 @@

public class LoginController extends StackPane{

private ClassLoader classLoader;

@FXML
private TextField user;

Expand All @@ -41,6 +44,7 @@ public class LoginController extends StackPane{

@FXML
private void initialize(){
classLoader = getClass().getClassLoader();
AccountController.initialize();
}

Expand All @@ -62,16 +66,17 @@ void openMainWindow() {
ptcLoginBtn.getScene().getWindow().hide();
Parent root;
try {
root = (Parent) FXMLLoader.load(ChooseGuiWindowController.class.getClassLoader().getResource("resources/layout/MainWindow.fxml"));
root = (Parent) FXMLLoader.load(classLoader.getResource("layout/MainWindow.fxml"));
} catch (IOException e1) {
System.err.println("Error loading resource: resources/layout/MainWindow.fxml");
System.err.println("Error loading resource: layout/MainWindow.fxml");
return;
}
Scene scene = new Scene(root);

Stage mainWindow = new Stage();

mainWindow.getIcons().add(new Image("resources/icon/PokeBall-icon.png"));
URL image = classLoader.getResource("icon/PokeBall-icon.png");
mainWindow.getIcons().add(new Image(image.toExternalForm()));
try {
NumberFormat f = NumberFormat.getInstance();
PlayerProfile pp = AccountController.getPlayerProfile();
Expand Down
12 changes: 9 additions & 3 deletions src/me/corriekay/pokegoutil/controllers/AccountController.java
Expand Up @@ -23,6 +23,8 @@
import com.pokegoapi.auth.CredentialProvider;
import com.pokegoapi.auth.GoogleUserCredentialProvider;
import com.pokegoapi.auth.PtcCredentialProvider;
import com.pokegoapi.exceptions.LoginFailedException;
import com.pokegoapi.exceptions.RemoteServerException;

import me.corriekay.pokegoutil.utils.Browser;
import me.corriekay.pokegoutil.utils.Config;
Expand Down Expand Up @@ -75,7 +77,7 @@ public static void initialize() {
}

@Deprecated
public static void logOn() throws Exception{
public static void logOn() {
if (!sIsInit) {
throw new ExceptionInInitializerError("AccountController needs to be initialized before logging on");
}
Expand Down Expand Up @@ -195,8 +197,12 @@ public static void logOn() throws Exception{
UIManager.put("OptionPane.cancelButtonText", "Cancel");

if (cp != null)
go = new PokemonGo(cp, http);
else
try {
go = new PokemonGo(cp, http);
} catch (LoginFailedException | RemoteServerException e) {
e.printStackTrace();
}
else
throw new IllegalStateException();
S_INSTANCE.logged = true;
}
Expand Down
6 changes: 2 additions & 4 deletions src/me/corriekay/pokegoutil/windows/PokemonGoMainWindow.java
Expand Up @@ -30,9 +30,7 @@ public class PokemonGoMainWindow extends JFrame {
public static PokemonGoMainWindow window = null;
private Config config = Config.getConfig();

public PokemonGo getPoGo() {
return go;
}
public PokemonGo getPoGo() { return go; }

private final JTabbedPane tab = new JTabbedPane();

Expand All @@ -54,7 +52,7 @@ public PokemonGoMainWindow(PokemonGo pkmngo, Console console) {
}
setLayout(new BorderLayout());
refreshTitle();
setIconImage(Utilities.loadImage("resources/icon/PokeBall-icon.png"));
setIconImage(Utilities.loadImage("icon/PokeBall-icon.png"));
setBounds(0, 0, config.getInt("options.window.width", 800), config.getInt("options.window.height", 650));
// add EventHandler to save new window size and position to
// config for the app to remember over restarts
Expand Down

0 comments on commit 9ae123c

Please sign in to comment.