1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
| package xyz.thecoalition.thecoalition.launcher;
import static fr.theshark34.swinger.Swinger.drawFullsizedImage;
import static fr.theshark34.swinger.Swinger.getResource;
import static fr.theshark34.swinger.Swinger.getTransparentWhite;
import java.awt.Color;
import java.awt.Desktop;
import java.awt.Graphics;
import java.awt.Image;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
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.animation.Animator;
import fr.theshark34.swinger.colored.SColoredBar;
import fr.theshark34.swinger.event.SwingerEvent;
import fr.theshark34.swinger.event.SwingerEventListener;
import fr.theshark34.swinger.textured.STexturedButton;
@SuppressWarnings("serial")
public class LauncherPanel extends JPanel implements SwingerEventListener {
private Image background = getResource("background.png");
private Saver saver = new Saver(new File(Launcher.TC_DIR, "launcher.properties"));
private JTextField usernameField = new JTextField(saver.get("Username"));
private JPasswordField passwordField = new JPasswordField();
private STexturedButton playButton = new STexturedButton(getResource("play.png"));
private STexturedButton quitButton = new STexturedButton(getResource("quit.png"));
private STexturedButton hideButton = new STexturedButton(getResource("hide.png"));
private STexturedButton ramButton = new STexturedButton(getResource("option.png"));
private STexturedButton siteButton = new STexturedButton(getResource("site.png"));
private STexturedButton ytButton = new STexturedButton(getResource("yt.png"));
private STexturedButton dcButton = new STexturedButton(getResource("dc.png"));
private SColoredBar progressBar = new SColoredBar(getTransparentWhite(100), getTransparentWhite(175));
private JLabel infoLabel = new JLabel("Connectez-vous avec votre compte Minecraft pour jouer !", SwingConstants.CENTER);
private RamSelector ramSelector = new RamSelector(new File(Launcher.TC_DIR, "ram.txt"));
public LauncherPanel() {
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(379, 274, 294, 51);
this.add(usernameField);
passwordField.setForeground(Color.WHITE);
passwordField.setFont(usernameField.getFont());
passwordField.setCaretColor(Color.WHITE);
passwordField.setOpaque(false);
passwordField.setBorder(null);
passwordField.setBounds(379, 395, 294, 51);
this.add(passwordField);
playButton.setBounds(710, 329);
playButton.addEventListener(this);
this.add(playButton);
quitButton.setBounds(929, 19);
quitButton.addEventListener(this);
this.add(quitButton);
hideButton.setBounds(895, 19);
hideButton.addEventListener(this);
this.add(hideButton);
ramButton.addEventListener(this);
this.ramButton.setBounds(22, 16);
this.add(ramButton);
siteButton.addEventListener(this);
this.siteButton.setBounds(840, 407);
this.add(siteButton);
ytButton.addEventListener(this);
this.ytButton.setBounds(795, 407);
this.add(ytButton);
dcButton.addEventListener(this);
this.dcButton.setBounds(749, 407);
this.add(dcButton);
progressBar.setBounds(25, 580, 924, 20);
this.add(progressBar);
infoLabel.setForeground(Color.WHITE);
infoLabel.setFont(infoLabel.getFont() .deriveFont(15F));
infoLabel.setBounds(25, 557, 924, 25);
this.add(infoLabel);
}
@SuppressWarnings("deprecation")
@Override
public void onEvent(SwingerEvent e) {
if(e.getSource() == playButton) {
setFieldsEnabled(false);
if(usernameField.getText().replaceAll(" ", "").length() == 0 || passwordField.getText().length() == 0) {
JOptionPane.showMessageDialog(this, "Erreur, veuillez entrer un pseudo et un mot de passe valides.", "Erreur", JOptionPane.ERROR_MESSAGE);
setFieldsEnabled(true);
return;
}
Thread t = new Thread() {
@Override
public void run() {
try{
Launcher.auth(usernameField.getText(), passwordField.getText());
} catch (AuthenticationException e) {
JOptionPane.showMessageDialog(LauncherPanel.this, "Erreur, impossible de se connecter : " + e.getErrorModel().getErrorMessage(), "Erreur", JOptionPane.ERROR_MESSAGE);
setFieldsEnabled(true);
return;
}
saver.set("Username", usernameField.getText());
ramSelector.save();
try {
Launcher.update();
} catch (Exception e) {
Launcher.interruptThread();
LauncherFrame.getCrashReporter().catchError(e, "Impossible de mettre le jeux a jour");
}
try {
Launcher.launch();
} catch (LaunchException e) {
LauncherFrame.getCrashReporter().catchError(e, "Impossible de lancer le jeux");
}
}
};
t.start();
}
else if (e.getSource() == this.siteButton){
if(Desktop.isDesktopSupported()){
if(Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)){
URI uri;
try {
uri = new URI("https://thecoalition.xyz");
try {
Desktop.getDesktop().browse(uri);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
} catch (URISyntaxException arg0) {
arg0.printStackTrace();
}
}
}
}
else if (e.getSource() == this.ytButton){
if(Desktop.isDesktopSupported()){
if(Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)){
URI uri;
try {
uri = new URI("https://www.youtube.com/channel/UC-CRAFRF5ehmNnxaWGHgLVg");
try {
Desktop.getDesktop().browse(uri);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
} catch (URISyntaxException arg0) {
arg0.printStackTrace();
}
}
}
}
else if (e.getSource() == this.dcButton){
if(Desktop.isDesktopSupported()){
if(Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)){
URI uri;
try {
uri = new URI("https://dis cord.gg/E5PzFWZ");
try {
Desktop.getDesktop().browse(uri);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
} catch (URISyntaxException arg0) {
arg0.printStackTrace();
}
}
}
}
else if(e.getSource() == quitButton)
Animator.fadeOutFrame(LauncherFrame.getInstance(), 2, new Runnable() {
@Override
public void run() {
System.exit(0);
}
});
else if(e.getSource() == hideButton)
LauncherFrame.getInstance().setState(1);
else if (e.getSource() == this.ramButton)
ramSelector.display();
}
@Override
public void paintComponent(Graphics graphics) {
super.paintComponent(graphics);
drawFullsizedImage(graphics, this, background);
}
private void setFieldsEnabled(boolean enabled) {
usernameField.setEnabled(enabled);
passwordField.setEnabled(enabled);
playButton.setEnabled(enabled);
}
public SColoredBar getProgressBar() {
return progressBar;
}
public void setInfoText(String text) {
infoLabel.setText(text);
}
public RamSelector getRamSelector()
{
return ramSelector;
}
} |
Partager