Advertisement
Guest User

Untitled

a guest
May 21st, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.93 KB | None | 0 0
  1. package fr.pacito2.launcher;
  2.  
  3. import static fr.theshark34.swinger.Swinger.drawFullsizedImage;
  4. import static fr.theshark34.swinger.Swinger.getResource;
  5. import static fr.theshark34.swinger.Swinger.getTransparentWhite;
  6.  
  7. import java.awt.Color;
  8. import java.awt.Desktop;
  9. import java.awt.Graphics;
  10. import java.awt.Image;
  11. import java.io.File;
  12. import java.io.IOException;
  13. import java.net.URI;
  14. import java.net.URISyntaxException;
  15.  
  16. import javax.swing.JFrame;
  17. import javax.swing.JLabel;
  18. import javax.swing.JOptionPane;
  19. import javax.swing.JPanel;
  20. import javax.swing.JPasswordField;
  21. import javax.swing.JTextField;
  22. import javax.swing.SwingConstants;
  23.  
  24. import fr.theshark34.openlauncherlib.util.CrashReporter;
  25. import fr.theshark34.openauth.AuthenticationException;
  26. import fr.theshark34.openlauncherlib.LaunchException;
  27. import fr.theshark34.openlauncherlib.util.Saver;
  28. import fr.theshark34.openlauncherlib.util.ramselector.RamSelector;
  29. import fr.theshark34.swinger.colored.SColoredBar;
  30. import fr.theshark34.swinger.event.SwingerEvent;
  31. import fr.theshark34.swinger.event.SwingerEventListener;
  32. import fr.theshark34.swinger.textured.STexturedButton;
  33.  
  34. @SuppressWarnings("serial")
  35. public class LauncherPanel extends JPanel implements SwingerEventListener{
  36.  
  37. private Image background = getResource("background.png");
  38.  
  39. private Saver saver = new Saver(new File(Launcher.SC_DIR, "launcher.properties"));
  40.  
  41. private JTextField usernameField = new JTextField(saver.get("username"));
  42.  
  43.  
  44. private STexturedButton playButton = new STexturedButton(getResource("play3.png"));
  45. private STexturedButton playButton2 = new STexturedButton(getResource("play3.png"));
  46. private STexturedButton playButton3 = new STexturedButton(getResource("play3.png"));
  47. private STexturedButton playButton4 = new STexturedButton(getResource("play3.png"));
  48. private STexturedButton Site = new STexturedButton(getResource("Site.png"));
  49. private STexturedButton Boutique = new STexturedButton(getResource("Boutique.png"));
  50. private STexturedButton Forum = new STexturedButton(getResource("Forum.png"));
  51. private STexturedButton Support = new STexturedButton(getResource("Support.png"));
  52. private STexturedButton Hide = new STexturedButton(getResource("Hide.png"));
  53. private STexturedButton Close = new STexturedButton(getResource("close.png"));
  54. private STexturedButton ramButton = new STexturedButton(getResource("ram.png"));
  55.  
  56. private SColoredBar progressBar = new SColoredBar(getTransparentWhite(100), getTransparentWhite(175));
  57. private JLabel infoLabel = new JLabel("Entre ton pseudo et clique sur Play Now !", SwingConstants.CENTER);
  58.  
  59. private RamSelector ramSelector = new RamSelector(new File(Launcher.SC_DIR, "Ram.txt"));
  60.  
  61. public LauncherPanel(){
  62. this.setLayout(null);
  63.  
  64. usernameField.setForeground(Color.BLACK);
  65. usernameField.setFont(usernameField.getFont().deriveFont(18F));
  66. usernameField.setCaretColor(Color.GRAY);
  67. usernameField.setOpaque(false);
  68. usernameField.setBorder(null);
  69. usernameField.setBounds(413, 71, 172, 15);
  70. this.add(usernameField);
  71.  
  72.  
  73. playButton.setBounds(60, 410);
  74. playButton.addEventListener(this);
  75. this.add(playButton);
  76.  
  77. playButton2.setBounds(765, 410);
  78. playButton2.addEventListener(this);
  79. this.add(playButton2);
  80.  
  81. playButton3.setBounds(250, 447);
  82. playButton3.addEventListener(this);
  83. this.add(playButton3);
  84.  
  85. playButton4.setBounds(575, 447);
  86. playButton4.addEventListener(this);
  87. this.add(playButton4);
  88.  
  89. Site.setBounds(810, 460);
  90. Site.addEventListener(this);
  91. this.add(Site);
  92.  
  93. Boutique.setBounds(70, 463);
  94. Boutique.addEventListener(this);
  95. this.add(Boutique);
  96.  
  97. Forum.setBounds(220, 490);
  98. Forum.addEventListener(this);
  99. this.add(Forum);
  100.  
  101. Support.setBounds(673, 488);
  102. Support.addEventListener(this);
  103. this.add(Support);
  104.  
  105. Hide.setBounds(930, 1);
  106. Hide.addEventListener(this);
  107. this.add(Hide);
  108.  
  109. Close.setBounds(960, 1);
  110. Close.addEventListener(this);
  111. this.add(Close);
  112.  
  113. ramButton.setBounds(900, 1);
  114. ramButton.addEventListener(this);
  115. this.add(ramButton);
  116.  
  117. progressBar.setBounds(348, 110, 292, 15);
  118. this.add(progressBar);
  119.  
  120. infoLabel.setForeground(Color.WHITE);
  121. infoLabel.setBounds(348, 110, 292, 15);
  122. this.add(infoLabel);
  123. }
  124.  
  125. @Override
  126. public void onEvent(SwingerEvent e){
  127.  
  128. if(e.getSource() == playButton){
  129. setFieldsEnabled(false);
  130.  
  131.  
  132. if(usernameField.getText().replaceAll(" ", "").length() == 0){
  133. JOptionPane.showMessageDialog(this, "Pseudo invalide !", "AmethystGames", JOptionPane.ERROR_MESSAGE);
  134. setFieldsEnabled(true);
  135. return;
  136. }
  137.  
  138. Thread t = new Thread(){
  139. @Override
  140. public void run(){
  141. try{
  142. Launcher.auth(usernameField.getText());
  143. } catch (AuthenticationException e){
  144. JOptionPane.showMessageDialog(LauncherPanel.this, "Erreur : "+ e.getErrorModel().getErrorMessage(), "MineWest", JOptionPane.ERROR_MESSAGE);
  145. setFieldsEnabled(true);
  146. return;
  147. }
  148. saver.set("username", usernameField.getText());
  149.  
  150. try{
  151. Launcher.update();
  152. } catch (Exception e){
  153. Launcher.interruptThread();
  154. LauncherFrame.getCrashReporter().catchError(e, "Impossible de mettre a joure TitanCraft");
  155. }
  156.  
  157. try{
  158. Launcher.launch();
  159. } catch (LaunchException e){
  160. LauncherFrame.getCrashReporter().catchError(e, "Impossible de lancer TitanCraft");
  161. }
  162.  
  163.  
  164.  
  165. }
  166. };
  167. t.start();
  168. }
  169. else if(e.getSource() == playButton2){
  170. setFieldsEnabled(false);
  171.  
  172. if(usernameField.getText().replaceAll(" ", "").length() == 0){
  173. JOptionPane.showMessageDialog(this, "Pseudo invalide !", "AmethystGames", JOptionPane.ERROR_MESSAGE);
  174. setFieldsEnabled(true);
  175. return;
  176. }
  177.  
  178. Thread t = new Thread(){
  179. @Override
  180. public void run(){
  181. try{
  182. Launcher2.auth(usernameField.getText());
  183. } catch (AuthenticationException e){
  184. JOptionPane.showMessageDialog(LauncherPanel.this, "Erreur : "+ e.getErrorModel().getErrorMessage(), "MineWest", JOptionPane.ERROR_MESSAGE);
  185. setFieldsEnabled(true);
  186. return;
  187. }
  188. saver.set("username", usernameField.getText());
  189.  
  190. try{
  191. Launcher2.update();
  192. } catch (Exception e){
  193. Launcher2.interruptThread();
  194. LauncherFrame.getCrashReporter().catchError(e, "Impossible de mettre a joure Sindoria");
  195. }
  196.  
  197. try{
  198. Launcher2.launch();
  199. } catch (LaunchException e){
  200. LauncherFrame.getCrashReporter().catchError(e, "Impossible de lancer Sindoria");
  201. }
  202.  
  203.  
  204.  
  205. }
  206. };
  207. t.start();
  208. }
  209. else if(e.getSource() == playButton3){
  210. setFieldsEnabled(false);
  211.  
  212.  
  213. if(usernameField.getText().replaceAll(" ", "").length() == 0){
  214. JOptionPane.showMessageDialog(this, "Pseudo invalide !", "AmethystGames", JOptionPane.ERROR_MESSAGE);
  215. setFieldsEnabled(true);
  216. return;
  217. }
  218.  
  219. Thread t = new Thread(){
  220. @Override
  221. public void run(){
  222. try{
  223. Launcher3.auth(usernameField.getText());
  224. } catch (AuthenticationException e){
  225. JOptionPane.showMessageDialog(LauncherPanel.this, "Erreur : "+ e.getErrorModel().getErrorMessage(), "MineWest", JOptionPane.ERROR_MESSAGE);
  226. setFieldsEnabled(true);
  227. return;
  228. }
  229. saver.set("username", usernameField.getText());
  230.  
  231. try{
  232. Launcher3.update();
  233. } catch (Exception e){
  234. Launcher3.interruptThread();
  235. LauncherFrame.getCrashReporter().catchError(e, "Impossible de mettre a joure DecayedPrison");
  236. }
  237.  
  238. try{
  239. Launcher3.launch();
  240. } catch (LaunchException e){
  241. LauncherFrame.getCrashReporter().catchError(e, "Impossible de lancer DecayedPrison");
  242. }
  243.  
  244.  
  245.  
  246. }
  247. };
  248. t.start();
  249. }
  250. else if(e.getSource() == playButton4){
  251. setFieldsEnabled(false);
  252.  
  253.  
  254. if(usernameField.getText().replaceAll(" ", "").length() == 0){
  255. JOptionPane.showMessageDialog(this, "Pseudo invalide !", "AmethystGames", JOptionPane.ERROR_MESSAGE);
  256. setFieldsEnabled(true);
  257. return;
  258. }
  259.  
  260. Thread t = new Thread(){
  261. @Override
  262. public void run(){
  263. try{
  264. Launcher4.auth(usernameField.getText());
  265. } catch (AuthenticationException e){
  266. JOptionPane.showMessageDialog(LauncherPanel.this, "Erreur : "+ e.getErrorModel().getErrorMessage(), "MineWest", JOptionPane.ERROR_MESSAGE);
  267. setFieldsEnabled(true);
  268. return;
  269. }
  270. saver.set("username", usernameField.getText());
  271.  
  272. try{
  273. Launcher4.update();
  274. } catch (Exception e){
  275. Launcher4.interruptThread();
  276. LauncherFrame.getCrashReporter().catchError(e, "Impossible de mettre a joure LastZ");
  277. }
  278.  
  279. try{
  280. Launcher4.launch();
  281. } catch (LaunchException e){
  282. LauncherFrame.getCrashReporter().catchError(e, "Impossible de lancer LastZ");
  283. }
  284.  
  285.  
  286.  
  287. }
  288. };
  289. t.start();
  290. }
  291.  
  292. else if(e.getSource() == Close)
  293. System.exit(0);
  294. else if(e.getSource() == Hide)
  295. LauncherFrame.getInstance().setState(JFrame.ICONIFIED);
  296. else if(e.getSource() == ramButton)
  297. ramSelector.display();
  298.  
  299. else if(e.getSource() == Support)
  300. try {
  301. Desktop.getDesktop().browse(new URI("http://amethystgames.fr/Support"));
  302. } catch (IOException e1) {
  303. e1.printStackTrace();
  304. } catch (URISyntaxException e1) {
  305. e1.printStackTrace();
  306. }
  307. else if(e.getSource() == Forum)
  308. try {
  309. Desktop.getDesktop().browse(new URI("http://amethystgames.fr/Forum"));
  310. } catch (IOException e1) {
  311. e1.printStackTrace();
  312. } catch (URISyntaxException e1) {
  313. e1.printStackTrace();
  314. }
  315. else if(e.getSource() == Boutique)
  316. try {
  317. Desktop.getDesktop().browse(new URI("http://amethystgames.fr/Boutique"));
  318. } catch (IOException e1) {
  319. e1.printStackTrace();
  320. } catch (URISyntaxException e1) {
  321. e1.printStackTrace();
  322. }
  323. else if(e.getSource() == Site)
  324. try {
  325. Desktop.getDesktop().browse(new URI("http://amethystgames.fr/"));
  326. } catch (IOException e1) {
  327. e1.printStackTrace();
  328. } catch (URISyntaxException e1) {
  329. e1.printStackTrace();
  330. }
  331. }
  332. @Override
  333. public void paintComponent(Graphics graphics){
  334. super.paintComponent(graphics);
  335.  
  336. drawFullsizedImage(graphics, this, background);
  337. }
  338.  
  339. private void setFieldsEnabled(boolean enabled){
  340. usernameField.setEnabled(enabled);
  341. playButton.setEnabled(enabled);
  342. playButton2.setEnabled(enabled);
  343. playButton3.setEnabled(enabled);
  344. playButton4.setEnabled(enabled);
  345. Hide.setEnabled(enabled);
  346. Close.setEnabled(enabled);
  347. }
  348.  
  349. public SColoredBar getProgressBar(){
  350. return progressBar;
  351. }
  352.  
  353. public void setInfoText(String text){
  354. infoLabel.setText(text);
  355. }
  356. public RamSelector getRamSelector()
  357. {
  358. return ramSelector;
  359. }
  360. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement