Rydder opp i IPAddressScreen

Retter tekst som blir vist når en server ikke kan kobles til
Legger til manglende kommentarer
Fjerner unødvendige feltvariabler
This commit is contained in:
Kristian Knarvik 2020-04-07 14:10:44 +02:00
parent d8e180cc8e
commit e37adf77d8

View File

@ -1,4 +1,4 @@
package inf112.fiasko.roborally.game_wrapper; package inf112.fiasko.roborally.game_wrapper.screens;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.GL20;
@ -11,28 +11,30 @@ import com.badlogic.gdx.scenes.scene2d.ui.TextField;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.utils.viewport.FitViewport; import com.badlogic.gdx.utils.viewport.FitViewport;
import com.badlogic.gdx.utils.viewport.Viewport; import com.badlogic.gdx.utils.viewport.Viewport;
import inf112.fiasko.roborally.game_wrapper.RoboRallyWrapper;
import inf112.fiasko.roborally.networking.RoboRallyClient; import inf112.fiasko.roborally.networking.RoboRallyClient;
import javax.swing.*; import javax.swing.*;
import java.io.IOException; import java.io.IOException;
/**
* This screen allows the user to enter the ip address to connect to
*/
public class IPAddressScreen extends AbstractScreen { public class IPAddressScreen extends AbstractScreen {
private final RoboRallyWrapper roboRallyWrapper; private final RoboRallyWrapper roboRallyWrapper;
private final OrthographicCamera camera; private final OrthographicCamera camera;
private final Viewport viewport; private final Viewport viewport;
private final Stage stage; private final Stage stage;
private final int applicationWidth = 600;
private final int applicationHeight = 800;
private TextField txtinput; private TextField txtinput;
private TextButton loginbutton;
public IPAddressScreen(final RoboRallyWrapper roboRallyWrapper) { public IPAddressScreen(final RoboRallyWrapper roboRallyWrapper) {
stage = new Stage(); stage = new Stage();
Skin skin =new Skin(Gdx.files.internal("uiskin.json")); Skin skin = new Skin(Gdx.files.internal("uiskin.json"));
loginbutton = new TextButton("click",skin); TextButton loginbutton = new TextButton("click", skin);
loginbutton.setSize(300,60); loginbutton.setSize(300,60);
loginbutton.setPosition(300,300); loginbutton.setPosition(300,300);
loginbutton.addListener(new ClickListener(){ loginbutton.addListener(new ClickListener(){
@ -43,7 +45,8 @@ public class IPAddressScreen extends AbstractScreen {
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getUsernameScreen(roboRallyWrapper)); roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getUsernameScreen(roboRallyWrapper));
} catch (IOException ex) { } catch (IOException ex) {
ex.printStackTrace(); ex.printStackTrace();
JOptionPane.showMessageDialog(null, "A basic JOptionPane message dialog"); JOptionPane.showMessageDialog(null, "Could not connect to the server."
+ " Please make sure the ip address you typed is correct, and that the server is online.");
} }
} }
}); });
@ -70,8 +73,8 @@ public class IPAddressScreen extends AbstractScreen {
roboRallyWrapper.batch.setProjectionMatrix(camera.combined); roboRallyWrapper.batch.setProjectionMatrix(camera.combined);
roboRallyWrapper.batch.begin(); roboRallyWrapper.batch.begin();
roboRallyWrapper.font.draw(roboRallyWrapper.batch, "Click the button to enter IP to join server", roboRallyWrapper.font.draw(roboRallyWrapper.batch, "Enter IP address and click the button to join a server",
applicationWidth/2f-380/2f,applicationHeight/2f + 100,380, 1, true); applicationWidth / 2f - 380 / 2f,applicationHeight / 2f + 100,380, 1, true);
roboRallyWrapper.batch.end(); roboRallyWrapper.batch.end();
stage.draw(); stage.draw();