Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package fr.nathanael2611.projectz.launcher;
- import fr.nathanael2611.nlib.NLib;
- import fr.theshark34.openauth.AuthenticationException;
- import fr.theshark34.openlauncherlib.LaunchException;
- import fr.theshark34.openlauncherlib.util.Saver;
- import fr.theshark34.openlauncherlib.util.ramselector.RamSelector;
- import fr.theshark34.swinger.Swinger;
- import fr.theshark34.swinger.colored.SColoredBar;
- import fr.theshark34.swinger.colored.SColoredButton;
- import fr.theshark34.swinger.event.SwingerEvent;
- import fr.theshark34.swinger.event.SwingerEventListener;
- import fr.theshark34.swinger.textured.STexturedButton;
- import fr.theshark34.swinger.textured.STexturedProgressBar;
- import sun.awt.image.PixelConverter;
- import javax.swing.*;
- import java.applet.Applet;
- import java.applet.AudioClip;
- import java.awt.*;
- import java.awt.image.BufferedImage;
- import java.io.*;
- import java.net.URL;
- import java.nio.Buffer;
- public class LauncherPanel extends JPanel implements SwingerEventListener {
- private Image background = Swinger.getResource("background.png");
- private Saver saver = new Saver(new File(Launcher.PZ_DIR, "launcher.properties"));
- private JTextField usernameField = new JTextField();
- private JPasswordField passwordField = new JPasswordField(saver.get("mdp"));
- private JTextField userField = new JTextField();
- private SColoredButton playButton = new SColoredButton(Swinger.TRANSPARENT);
- private SColoredButton ramButton = new SColoredButton(Swinger.TRANSPARENT, Swinger.TRANSPARENT);
- private SColoredButton closeButton = new SColoredButton(Swinger.TRANSPARENT, Swinger.TRANSPARENT);
- private SColoredButton reducButton = new SColoredButton(Swinger.TRANSPARENT, Swinger.TRANSPARENT);
- /*private SColoredButton discordButton = new SColoredButton(Swinger.TRANSPARENT, Swinger.TRANSPARENT);
- private SColoredButton webButton = new SColoredButton(Swinger.TRANSPARENT, Swinger.TRANSPARENT);
- */
- private SColoredBar pb = new SColoredBar(new Color(100, 100, 100, 10), new Color(171, 34, 33));
- private Image crackon = Swinger.getResource("crackon.png");
- private Image crackoff = Swinger.getResource("crackoff.png");
- private STexturedButton crackbutton = new STexturedButton((BufferedImage) crackoff, (BufferedImage)crackoff);
- private RamSelector ramSelector = new RamSelector(new File(Launcher.PZ_DIR, "ram.txt"));
- public LauncherPanel() {
- File iscrackfile = new File(Launcher.PZ_DIR, "iscrack.txt");
- String iscrackvalue = "";
- try
- {
- BufferedInputStream in = new BufferedInputStream(new FileInputStream(iscrackfile));
- StringWriter out = new StringWriter();
- int b;
- while ((b=in.read()) != -1)
- out.write(b);
- out.flush();
- out.close();
- in.close();
- iscrackvalue = out.toString();
- }
- catch (FileNotFoundException exception)
- {
- System.out.println ("Le fichier n'a pas été trouvé");
- } catch (IOException e) {
- e.printStackTrace();
- }
- crackbutton.setBounds(0, 5, 150, 29);
- crackbutton.addEventListener(this);
- this.add(crackbutton);
- this.setBackground(Swinger.TRANSPARENT);
- this.setLayout(null);
- usernameField.setForeground(Color.WHITE);
- usernameField.setFont(usernameField.getFont().deriveFont(20F));
- usernameField.setCaretColor(Color.WHITE);
- usernameField.setOpaque(false);
- usernameField.setBorder(null);
- usernameField.setBounds(417, 247, 346, 52);
- this.add(usernameField);
- passwordField.setForeground(Color.WHITE);
- passwordField.setFont(usernameField.getFont().deriveFont(20F));
- passwordField.setCaretColor(Color.WHITE);
- passwordField.setOpaque(false);
- passwordField.setBorder(null);
- passwordField.setBounds(417, 309, 346, 52);
- this.add(passwordField);
- if(Launcher.IS_CRACK == true){
- passwordField.setEnabled(false);
- }
- playButton.setBounds(479, 378, 228, 92);
- playButton.addEventListener(this);
- this.add(playButton);
- File usernamefile = new File(Launcher.PZ_DIR, "username.txt");
- try
- {
- BufferedInputStream in = new BufferedInputStream(new FileInputStream(usernamefile));
- StringWriter out = new StringWriter();
- int b;
- while ((b=in.read()) != -1)
- out.write(b);
- out.flush();
- out.close();
- in.close();
- usernameField.setText(out.toString());
- }
- catch (FileNotFoundException exception)
- {
- System.out.println ("Le fichier n'a pas été trouvé");
- } catch (IOException e) {
- e.printStackTrace();
- }
- ramButton.setBounds(628, 6, 44, 44);
- ramButton.addEventListener(this);
- this.add(ramButton);
- closeButton.setBounds(759, 13, 27, 29);
- closeButton.addEventListener(this);
- this.add(closeButton);
- reducButton.setBounds(703, 13, 27, 29);
- reducButton.addEventListener(this);
- this.add(reducButton);
- /*discordButton.setBounds(135, 240, 91, 60);
- discordButton.addEventListener(this);
- this.add(discordButton);
- webButton.setBounds(135, 140, 91, 80);
- webButton.addEventListener(this);
- this.add(webButton);*/
- pb.setStringPainted(true);
- pb.setBounds(133, 448, 345, 37);
- this.add(pb);
- if(iscrackvalue.equals("true")){
- Launcher.IS_CRACK = true;
- crackbutton.setTexture(crackon);
- crackbutton.setTextureHover(crackon);
- passwordField.setText("");
- passwordField.setEnabled(false);
- }
- }
- public void onEvent(SwingerEvent e) {
- if(e.getSource() == playButton){
- File usernamefile = new File(Launcher.PZ_DIR, "username.txt");
- try (PrintWriter output = new PrintWriter(usernamefile)){
- output.print(usernameField.getText());
- } catch (FileNotFoundException e1) {
- e1.printStackTrace();
- }
- File iscrackfile = new File(Launcher.PZ_DIR, "iscrack.txt");
- try (PrintWriter output = new PrintWriter(iscrackfile)){
- output.print(Launcher.IS_CRACK);
- } catch (FileNotFoundException e1) {
- e1.printStackTrace();
- }
- LauncherPanel.this.ramSelector.save();
- NLib.playAudioClip(Launcher.class, "resources/balle.wav");
- setFieldsEnabled(false);
- if(Launcher.IS_CRACK == false) {
- if (usernameField.getText().replaceAll(" ", "").length() == 0 || passwordField.getText().length() == 0) {
- JOptionPane.showMessageDialog(this, "Veuillez rentrer un e-mail et un mot de passe valide.", "Erreur !", JOptionPane.ERROR_MESSAGE);
- setFieldsEnabled(true);
- return;
- }
- }else{
- if (usernameField.getText().replaceAll(" ", "").length() == 0) {
- JOptionPane.showMessageDialog(this, "Veuillez rentrer un pseudonyme valide !.", "Erreur !", JOptionPane.ERROR_MESSAGE);
- usernameField.setEnabled(true);
- passwordField.setEnabled(false);
- return;
- }
- }
- Thread t = new Thread() {
- @Override
- public void run() {
- LauncherPanel.this.ramSelector.save();
- try {
- Launcher.auth(usernameField.getText(), passwordField.getText());
- System.out.println("f");
- } catch (AuthenticationException e) {
- JOptionPane.showMessageDialog(LauncherPanel.this, "Impossible de se connecter !" + e.getErrorModel().getErrorMessage(), "Erreur !", JOptionPane.ERROR_MESSAGE);
- setFieldsEnabled(true);
- System.out.println("f");
- return;
- }
- try {
- Launcher.update();
- } catch (Exception e) {
- Launcher.InterruptThread();
- JOptionPane.showMessageDialog(LauncherPanel.this, "Impossible de Mettre le jeu à jour ! !" + e, "Erreur !", JOptionPane.ERROR_MESSAGE);
- setFieldsEnabled(true);
- return;
- }
- try {
- Launcher.launch();
- } catch (LaunchException e) {
- JOptionPane.showMessageDialog(LauncherPanel.this, "Impossible de lancer le jeu." + e, "Erreur !", JOptionPane.ERROR_MESSAGE);
- setFieldsEnabled(true);
- return;
- }
- System.out.println("t");
- }
- };
- t.start();
- }
- else if (e.getSource() == this.ramButton) {
- ramSelector.display();
- System.out.println("hey");
- }else if(e.getSource() == this.closeButton){
- System.exit(0);
- }else if(e.getSource() == this.reducButton){
- LauncherFrame.getInstance().setState(Frame.ICONIFIED);
- }/*else if(e.getSource() == this.webButton){
- BrowserControl.displayURL("http://kyrgon.revhost.fr");
- }else if(e.getSource() == this.discordButton){
- BrowserControl.displayURL("paste discord link here");
- }*/
- else if (e.getSource() == this.crackbutton){
- if(Launcher.IS_CRACK == false){
- Launcher.IS_CRACK = true;
- crackbutton.setTexture(crackon);
- crackbutton.setTextureHover(crackon);
- passwordField.setText("");
- passwordField.setEnabled(false);
- }else{
- Launcher.IS_CRACK = false;
- crackbutton.setTexture(crackoff);
- crackbutton.setTextureHover(crackoff);
- passwordField.setEnabled(true);
- }
- }
- }
- @Override
- public void paintComponent(Graphics g) {
- super.paintComponent(g);
- g.drawImage(background, 0, 0, this.getWidth(), this.getHeight(), this);
- }
- private void setFieldsEnabled(boolean enabled) {
- usernameField.setEnabled(enabled);
- passwordField.setEnabled(enabled);
- playButton.setEnabled(enabled);
- }
- public SColoredBar getProgressBar() {
- return pb;
- }
- public RamSelector getRamSelector(){
- return ramSelector;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement