Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.25 KB | None | 0 0
  1. package fr.zai.minepiece.launcher;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Graphics;
  5. import java.awt.Image;
  6. import java.io.File;
  7. import java.io.IOException;
  8.  
  9. import javax.swing.JFrame;
  10. import javax.swing.JLabel;
  11. import javax.swing.JOptionPane;
  12. import javax.swing.JPanel;
  13. import javax.swing.JPasswordField;
  14. import javax.swing.JTextField;
  15. import javax.swing.SwingConstants;
  16.  
  17. import fr.northenflo.auth.exception.DataEmptyException;
  18. import fr.northenflo.auth.exception.DataWrongException;
  19. import fr.northenflo.auth.exception.ServerNotFoundException;
  20. import fr.northenflo.auth.mineweb.AuthMineweb;
  21. import fr.northenflo.auth.mineweb.utils.TypeConnection;
  22. import fr.theshark34.openlauncherlib.LaunchException;
  23. import fr.theshark34.openlauncherlib.util.Saver;
  24. import fr.theshark34.openlauncherlib.util.ramselector.RamSelector;
  25. import fr.theshark34.swinger.Swinger;
  26. import fr.theshark34.swinger.animation.Animator;
  27. import fr.theshark34.swinger.colored.SColoredBar;
  28. import fr.theshark34.swinger.event.SwingerEvent;
  29. import fr.theshark34.swinger.event.SwingerEventListener;
  30. import fr.theshark34.swinger.textured.STexturedButton;
  31.  
  32. @SuppressWarnings("serial")
  33. public class LauncherPanel extends JPanel implements SwingerEventListener{
  34.  
  35. private Image background = Swinger.getResource("LauncherV2.3.png");
  36.  
  37. private Saver saver = new Saver(new File(launcher.MP_DIR, "launcher.properties"));
  38.  
  39. private JTextField usernameField = new JTextField(saver.get("username"));
  40.  
  41. private JTextField passwordField = new JPasswordField();
  42.  
  43.  
  44. public Boolean bReadParams = false;
  45.  
  46.  
  47. private STexturedButton playButton = new STexturedButton(Swinger.getResource("JouerV2.png"));
  48. private STexturedButton hideButton = new STexturedButton(Swinger.getResource("tiretV2.png"));
  49. private STexturedButton quitButton = new STexturedButton(Swinger.getResource("croixV2.png"));
  50. private static JLabel infoLabel = new JLabel("Clique sur Jouer !", SwingConstants.CENTER);
  51. private SColoredBar progressBar = new SColoredBar(Swinger.getTransparentWhite(100), Swinger.getTransparentWhite(175));
  52.  
  53.  
  54. public STexturedButton ramButton = new STexturedButton(Swinger.getResource("options.png"));
  55.  
  56.  
  57. public LauncherPanel() {
  58. this.setLayout(null);
  59.  
  60.  
  61.  
  62. usernameField.setFont(usernameField.getFont().deriveFont(20F));
  63. usernameField.setOpaque(false);
  64. usernameField.setBorder(null);
  65. usernameField.setBounds(340, 250, 290, 40);
  66. this.add(usernameField);
  67.  
  68. passwordField.setFont(usernameField.getFont() );
  69. passwordField.setOpaque(false);
  70. passwordField.setBorder(null);
  71. passwordField.setBounds(320, 390, 290, 40);
  72. this.add(passwordField);
  73.  
  74. playButton.setBounds(370, 350);
  75. playButton.addEventListener(this);
  76. this.add(playButton);
  77.  
  78. quitButton.setBounds(923,18);
  79. quitButton.addEventListener(this);
  80. this.add(quitButton);
  81.  
  82. hideButton.setBounds(880, 18);
  83. hideButton.addEventListener(this);
  84. this.add(hideButton);
  85.  
  86.  
  87. progressBar.setBounds(7, 593, 961, 20);
  88. this.add(progressBar);
  89.  
  90.  
  91. infoLabel.setForeground(Color.white);
  92. infoLabel.setFont(usernameField.getFont());
  93. infoLabel.setBounds(0, 560, 961, 25);
  94. this.add(infoLabel);
  95.  
  96. this.ramButton.setBounds(830, 18);
  97. ramButton.addEventListener(this);
  98.  
  99. this.add(ramButton);
  100.  
  101. }
  102.  
  103. @Override
  104. public void paintComponent(Graphics g) {
  105. super.paintComponent(g);
  106.  
  107. g.drawImage(background, 0, 0, this.getWidth(), this.getHeight(), this);
  108. }
  109.  
  110.  
  111.  
  112. @Override
  113. public void onEvent (SwingerEvent e) {
  114. if(e.getSource() == playButton) {
  115.  
  116. setFieldsEnabled(false);
  117.  
  118. if(usernameField.getText().replaceAll(" ", "").length() == 0 || passwordField.getText().length() == 00/*.length() == 0*/){
  119.  
  120. //JOptionPane.showMessageDialog(this, "Erreur, veuillez entre un pseudo et un mot de passe valide.", "Erreur", JOptionPane.ERROR_MESSAGE);
  121. setFieldsEnabled(true);
  122. return;
  123. }
  124.  
  125. Thread t = new Thread() {
  126. @Override
  127. public void run() {
  128. AuthMineweb.setTypeConnection(TypeConnection.launcher);
  129. AuthMineweb.setUrlRoot("https://minepiece.fr/");
  130. AuthMineweb.setUsername(usernameField.getText());
  131. AuthMineweb.setPassword(passwordField.getText());
  132. try{
  133. AuthMineweb.start();
  134. } catch(DataWrongException e1) {
  135. JOptionPane.showMessageDialog(LauncherPanel.this, "Erreur, veuillez entrer un pseudo et un mot de passe valides.");;
  136. setFieldsEnabled(true);
  137. e1.printStackTrace();
  138. return;
  139. } catch(DataEmptyException e1){
  140. JOptionPane.showMessageDialog(LauncherPanel.this, "Erreur, veuillez entrer un pseudo et un mot de passe valides.");;
  141. setFieldsEnabled(true);
  142. e1.printStackTrace();
  143. return;
  144. } catch(ServerNotFoundException e1){
  145. JOptionPane.showMessageDialog(LauncherPanel.this, "Erreur, veuillez entrer un pseudo et un mot de passe valides.");;
  146. setFieldsEnabled(true);
  147. e1.printStackTrace();
  148. return;
  149. } catch(IOException e1){
  150. JOptionPane.showMessageDialog(LauncherPanel.this, "Erreur, veuillez entrer un pseudo et un mot de passe valides.");;
  151. setFieldsEnabled(true);
  152. e1.printStackTrace();
  153. return;
  154. }
  155. if(AuthMineweb.isConnected())
  156. {
  157. Thread t = new Thread() {
  158. @Override
  159. public void run()
  160. {
  161. saver.set("username", usernameField.getText());
  162.  
  163. try {
  164. launcher.update();
  165. } catch (Exception e)
  166. {
  167.  
  168. launcher.interruptThread();
  169. LauncherFrame.crashReporter.catchError(e, "Impossible de mettre a jour: ");
  170. //JOptionPane.showMessageDialog(LauncherPanel.this, "Impossible de mettre a jour: " + e, "Erreur", JOptionPane.ERROR_MESSAGE);
  171. setFieldsEnabled(true);
  172. return;
  173. }
  174. try {
  175. launcher.launch();
  176.  
  177. } catch (LaunchException e)
  178. {
  179. LauncherFrame.crashReporter.catchError(e, "Impossible de lancer le jeu:");
  180. //JOptionPane.showMessageDialog(LauncherPanel.this, "Impossible de lancer le jeu: " + e, "Erreur", JOptionPane.ERROR_MESSAGE);
  181. setFieldsEnabled(true);
  182. }
  183. }
  184. };
  185. t.start();
  186. }
  187.  
  188.  
  189.  
  190. }
  191. };
  192. t.start();
  193.  
  194. }else if(e.getSource() == quitButton){
  195. Animator.fadeOutFrame(LauncherFrame.getInstance(), 6, new Runnable() {
  196.  
  197. @Override
  198. public void run() {
  199. discord.DeletePresence();
  200. System.exit(0);
  201.  
  202. }
  203.  
  204. });
  205.  
  206. }else if(e.getSource() == hideButton){
  207. LauncherFrame.getInstance().setState(JFrame.ICONIFIED);
  208.  
  209. }else if(e.getSource() == this.ramButton){
  210. launcher.ramSelectorr.display();
  211.  
  212. bReadParams = true;
  213. if(bReadParams == true) {
  214. //System.out.println("Sa MARCHEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE");
  215. }
  216.  
  217. }
  218.  
  219.  
  220. }
  221.  
  222.  
  223.  
  224. private void setFieldsEnabled(boolean enabled){
  225. usernameField.setEnabled(enabled);
  226. playButton.setEnabled(enabled);
  227. }
  228.  
  229. public SColoredBar GetProgressBar() {
  230. return progressBar;
  231. }
  232.  
  233. public void SetInfoText(String text) {
  234. infoLabel.setText(text);
  235. }
  236.  
  237. public RamSelector getRamSelector()
  238. {
  239. //launcher.ramSelectorr.save();
  240. return launcher.ramSelectorr;
  241.  
  242. }
  243.  
  244.  
  245. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement