Commit f88f5a5e authored by Huot Mathieu's avatar Huot Mathieu

improved input and start of configpanel

parent 6ed013af
......@@ -22,7 +22,7 @@ public abstract class GraphicsMasterAbstraction {
protected boolean guiLaunched = false;
//The different states the GUI can be in.
public enum GUIStates {UNINITIALISED, MAIN_MENU_PANEL, GAME_PANEL, SINGLEPLAYERPANEL, MULTIPLAYERPANEL};
public enum GUIStates {UNINITIALISED, MAIN_MENU_PANEL, GAME_PANEL, SINGLEPLAYERPANEL, MULTIPLAYERPANEL, INPUT_CONFIG_PANEL};
//This map indicates to graphicsMaster which GUIPanel is associated to each GUIState, it is filled in Graphicsmaster's constructor
protected HashMap<GUIStates, PanelAbstraction> mapGUIStatesToGUIPanel = new HashMap<GUIStates, PanelAbstraction>();
//The current state of the GUI
......
package graphics.guiSkeleton.GUIPanel;
import graphics.guiSkeleton.GUIColorsAndFonts;
import graphics.guiSkeleton.GraphicsMaster;
import graphics.ingame_input_listener.Input;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
/**
* Created by zobi on 25/11/15.
*/
public class ConfigurationPanel extends GUIPanel {
public ConfigurationPanel(GraphicsMaster graphicsMaster) {
super(graphicsMaster);
/** Creation of the colours used in the following **/
Color darkSlateBlue = new Color(75,51,138);
Color tawnyPort = new Color(106,27,73);
Color gamboge = new Color(217,161,14);
Color darkRaspberry = new Color(138,28,98);
/** Creation of the fonts used in the following **/
Font inconsolata_40_bold = new Font("Inconsolata", Font.BOLD, 40);
Font purisa_30_bold = new Font("Purisa", Font.BOLD, 30);
Font arial_20 = new Font("Arial", Font.PLAIN, 20);
/**###################################################**/
/** Creation of the content of the ConfigurationPanel **/
/**###################################################**/
setLayout(new GridBagLayout());
GridBagConstraints c;
/** Creation of the titlePanel **/
JPanel titlePanel = new JPanel();
titlePanel.setOpaque(true);
titlePanel.setBackground(darkSlateBlue);
//TODO: move the titleLabel to the center of the titlePanel
JLabel titleLabel = new JLabel("MultiPlayer");
titleLabel.setForeground(gamboge);
titleLabel.setFont(inconsolata_40_bold);
titlePanel.add(titleLabel);
// Create the GridBagConstraint for titlePanel in mainMenuPanel
c = new GridBagConstraints();
c.gridx=0; c.gridy=0; c.gridwidth=1; c.gridheight=1;c.weightx=1;c.weighty=0.5;c.fill=GridBagConstraints.BOTH;
// Add the titlePanel to the mainMenuPanel
add(titlePanel, c);
/** Creation of the buttonPanel **/
// Creation of the list of the definition of the buttons of the buttonPanel
// To add a button, just add an element to buttonDefList
// Note: Do not to put more than 15 button
ArrayList<buttonPanelButtonDefinition> buttonDefList = new ArrayList<buttonPanelButtonDefinition>();
buttonDefList.add(new buttonPanelButtonDefinition("move up",configUpListener));
buttonDefList.add(new buttonPanelButtonDefinition("move down",configDownListener));
buttonDefList.add(new buttonPanelButtonDefinition("move right",configLeftListener));
buttonDefList.add(new buttonPanelButtonDefinition("move left",configRightListener));
buttonDefList.add(new buttonPanelButtonDefinition("back",backButtonListener));
JPanel buttonPanel = makeButtonPanel(buttonDefList);
// Create the GridBagConstraint for buttonPanel in mainMenuPanel
c = new GridBagConstraints();
c.gridx=0; c.gridy=1; c.gridwidth=1; c.gridheight=1;c.weightx=1;c.weighty=10;c.fill=GridBagConstraints.BOTH;
// Add the buttonPanel to the mainMenuPanel
add(buttonPanel, c);
/** Creation of the ensLabelPanel **/
JPanel ensLabelPanel = new JPanel();
ensLabelPanel.setLayout(new BorderLayout());
ensLabelPanel.setOpaque(true);
ensLabelPanel.setBackground(tawnyPort);
//ENSLabel
JLabel ensLabel = new JLabel();
ensLabel.setFont(arial_20);
ensLabel.setText("V1.0 - ENS team");
ensLabel.setForeground(gamboge);
ensLabelPanel.add(ensLabel, BorderLayout.LINE_START);
// Create the GridBagConstraint for andLabelPanel in mainMenuPanel
c = new GridBagConstraints();
c.gridx=0; c.gridy=2; c.gridwidth=1; c.gridheight=1;c.weightx=0;c.weighty=0;c.fill=GridBagConstraints.BOTH;
// Add the buttonPanel to the mainMenuPanel
add(ensLabelPanel, c);
}
/**
* This class defines the buttons that can be displayed in the central row of the MainMenuPanel
*/
private class buttonPanelButtonDefinition {
private String buttonText;
private ActionListener buttonActionListener;
buttonPanelButtonDefinition(String buttonText, ActionListener buttonActionListener) {
this.buttonText = buttonText;
this.buttonActionListener = buttonActionListener;
}
public String getButtonText() {
return buttonText;
}
public ActionListener getButtonActionListener() {
return buttonActionListener;
}
}
/**
* This method creates a buttonPanel to be displayed on the MainMenuPanel
* @param buttonDefList: A list of buttonPanelButtonDefinition
* @return A JPanel with all the asked buttons in the central row (buttonPanel)
*/
private JPanel makeButtonPanel(ArrayList<buttonPanelButtonDefinition> buttonDefList) {
JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new GridBagLayout());
buttonPanel.setOpaque(true);
buttonPanel.setBackground(GUIColorsAndFonts.backGround1);
ArrayList<Component> verticalBoxesList = new ArrayList<Component>();
ArrayList<Component> horizontalBoxesList = new ArrayList<Component>();
ArrayList<JComponent> buttonList = new ArrayList<JComponent>();
/** Create vertical boxes **/
//Add an initial verticalBox, but do not put it in verticalBoxesList.
Component firstVerticalBox = Box.createVerticalGlue();
//For each buttonDef in buttonDefList, create a verticalBox
for (int i = 0;i < buttonDefList.size();i++) {
verticalBoxesList.add(Box.createVerticalGlue());
}
/** Create horizontal boxes **/
//For each buttonDef in buttonDefList, create 2 horizontallBox (one on each side of the button
for (int i = 0;i < buttonDefList.size(); i++) {
horizontalBoxesList.add(Box.createHorizontalGlue());
horizontalBoxesList.add(Box.createHorizontalGlue());
}
/** Create buttons **/
//Create all the button whose definition are in buttonDefList
JButton buttonUnderConstruction;
for (buttonPanelButtonDefinition buttonDef : buttonDefList) {
buttonUnderConstruction = new JButton();
buttonUnderConstruction.setFont(GUIColorsAndFonts.buttonFont1);
buttonUnderConstruction.setText(buttonDef.getButtonText());
buttonUnderConstruction.setForeground(GUIColorsAndFonts.fontColor1);
buttonUnderConstruction.setOpaque(true);
buttonUnderConstruction.setBackground(GUIColorsAndFonts.buttonBackground1);
buttonUnderConstruction.addActionListener(buttonDef.getButtonActionListener());
buttonList.add(buttonUnderConstruction);
}
/** Compute the weight of the components **/
int buttonWeightX = 1;
int buttonWeightY = 1;
int verticalBoxWeightX = 1;
int verticalBoxWeightY = (15 * (buttonWeightY * buttonDefList.size())) / (buttonDefList.size() + 1);
int horizontalBoxWeightX = 3;
int horizontalBoxWeightY = 1;
/** Create the gridBagConstraints templates **/
//hbc -> horizontalBoxConstraint
GridBagConstraints hbc = new GridBagConstraints();
hbc.gridwidth=1;hbc.gridheight=1;hbc.weightx=horizontalBoxWeightX;hbc.weighty=horizontalBoxWeightY;
//vbc -> verticalBoxConstraint
GridBagConstraints vbc = new GridBagConstraints();
vbc.gridwidth=1;vbc.gridheight=1;vbc.weightx=verticalBoxWeightX;vbc.weighty=verticalBoxWeightY;
//bc -> buttonBoxConstraint
GridBagConstraints bc = new GridBagConstraints();
bc.gridwidth=1;bc.gridheight=1;bc.weightx=buttonWeightX;bc.weighty=buttonWeightY;bc.fill=GridBagConstraints.BOTH;
/** Add all the component to the buttonPanel **/
//Add the first vertical box
vbc.gridx = 1; vbc.gridy = 0;
buttonPanel.add(firstVerticalBox, vbc);
//Add the other components
for (int i = 0; i < buttonDefList.size(); i++) {
hbc.gridx = 0; hbc.gridy = 2*i+1;
buttonPanel.add(horizontalBoxesList.get(2*i), hbc);
hbc.gridx = 2; hbc.gridy = 2*i+1;
buttonPanel.add(horizontalBoxesList.get(2*i + 1), hbc);
bc.gridx = 1; bc.gridy = 2*i+1;
buttonPanel.add(buttonList.get(i), bc);
vbc.gridx = 1; vbc.gridy = 2*i+2;
buttonPanel.add(verticalBoxesList.get(i), vbc);
}
return buttonPanel;
}
private ActionListener configUpListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
}
};
private ActionListener configDownListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
}
};
private ActionListener configRightListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
}
};
private ActionListener configLeftListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
}
};
private ActionListener backButtonListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
getGraphicsMaster().changeGUIStateTo(GraphicsMaster.GUIStates.MAIN_MENU_PANEL);
}
};
@Override
public void keyPressedHandler(Input e) {
}
@Override
public void keyReleasedHandler(Input e) {
}
@Override
public void keyTypedHandler(Input e) {
}
@Override
public void initialise() {
}
@Override
public void finalise() {
}
}
\ No newline at end of file
......@@ -2,6 +2,7 @@ package graphics.guiSkeleton.GUIPanel;
import gameloop.DummyLocalGameLoop;
import gameloop.DummyServerLoop;
import graphics.graphical_abstraction.GraphicsMasterAbstraction;
import graphics.guiSkeleton.CoreProcesses.GameType;
import graphics.guiSkeleton.GUIColorsAndFonts;
import graphics.guiSkeleton.GraphicsMaster;
......@@ -78,6 +79,7 @@ public class MainMenuPanel extends GUIPanel{
ArrayList<buttonPanelButtonDefinition> buttonDefList = new ArrayList<buttonPanelButtonDefinition>();
buttonDefList.add(new buttonPanelButtonDefinition("single player",singlePlayerButtonListener));
buttonDefList.add(new buttonPanelButtonDefinition("multi player",multiPlayerButtonListener));
buttonDefList.add(new buttonPanelButtonDefinition("configuration",configurationButtonListener));
buttonDefList.add(new buttonPanelButtonDefinition("exit",exitButtonListener));
JPanel buttonPanel = makeButtonPanel(buttonDefList);
......@@ -227,7 +229,6 @@ public class MainMenuPanel extends GUIPanel{
DummyLocalGameLoop.getInstance().startGame(GameType.SINGLEPLAYER);
//this is start not run like in the DummyServer, because here we are dealing with a thread
DummyServerLoop.getInstance().start();
}
};
......@@ -236,7 +237,13 @@ public class MainMenuPanel extends GUIPanel{
public void actionPerformed(ActionEvent actionEvent) {
getGraphicsMaster().changeGUIStateTo(GraphicsMaster.GUIStates.MULTIPLAYERPANEL);
DummyLocalGameLoop.getInstance().startGame(GameType.MULTIPLAYER);
}
};
private ActionListener configurationButtonListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
getGraphicsMaster().changeGUIStateTo(GraphicsMaster.GUIStates.INPUT_CONFIG_PANEL);
}
};
......
......@@ -38,9 +38,9 @@ public class SinglePlayerPanel extends GUIPanel{
Font purisa_30_bold = new Font("Purisa", Font.BOLD, 30);
Font arial_20 = new Font("Arial", Font.PLAIN, 20);
/**##############################################**/
/** Creation of the content of the MainMenuPanel **/
/**##############################################**/
/**##################################################**/
/** Creation of the content of the SinglePlayerPanel **/
/**##################################################**/
setLayout(new GridBagLayout());
......
......@@ -34,6 +34,7 @@ public class GraphicsMaster extends GraphicsMasterAbstraction {
mapGUIStatesToGUIPanel.put(GUIStates.GAME_PANEL, new GamePanel(this));
mapGUIStatesToGUIPanel.put(GUIStates.SINGLEPLAYERPANEL, new SinglePlayerPanel(this));
mapGUIStatesToGUIPanel.put(GUIStates.MULTIPLAYERPANEL, new MultiPlayerPanel(this));
mapGUIStatesToGUIPanel.put(GUIStates.INPUT_CONFIG_PANEL, new ConfigurationPanel(this));
}
......
......@@ -2,6 +2,7 @@ package graphics.guiSkeleton;
import graphics.graphical_abstraction.FrameKeyListenerAbstraction;
import graphics.ingame_input_listener.Input;
import graphics.ingame_input_listener.InputConfiguration;
import graphics.sprites.TileSprite;
import java.awt.event.KeyEvent;
......@@ -25,6 +26,27 @@ public class MainFrameKeyListener implements KeyListener,FrameKeyListenerAbstrac
* @param e: the KeyEvent that was recorded by the mainFrame
*/
public final void keyPressed(KeyEvent e) {
graphicsMaster.keyPressedHandler(InputConfiguration.GetInput(e));}
/**
* This method relays the keyReleased KeyEvent recorded by the mainFrame to GraphicsMaster
* @param e: the KeyEvent that was recorded by the mainFrame
*/
public final void keyReleased(KeyEvent e) {graphicsMaster.keyReleasedHandler(InputConfiguration.GetInput(e));}
/**
* This method relays the keyTyped KeyEvent recorded by the mainFrame to GraphicsMaster
* @param e: the KeyEvent that was recorded by the mainFrame
*/
public final void keyTyped(KeyEvent e) {graphicsMaster.keyTypedHandler(InputConfiguration.GetInput(e));}
}
/* *//**
* This method relays the keyPressed KeyEvent recorded by the mainFrame to GraphicsMaster
* @param e: the KeyEvent that was recorded by the mainFrame
*//*
public final void keyPressed(KeyEvent e) {
//Input i = null;
......@@ -48,10 +70,10 @@ public class MainFrameKeyListener implements KeyListener,FrameKeyListenerAbstrac
//graphicsMaster.keyPressedHandler(i);
}
/**
*//**
* This method relays the keyReleased KeyEvent recorded by the mainFrame to GraphicsMaster
* @param e: the KeyEvent that was recorded by the mainFrame
*/
*//*
public final void keyReleased(KeyEvent e) {
//Input i = null;
if(e.getKeyCode() == 27) { // 27 -> Escape
......@@ -71,11 +93,11 @@ public class MainFrameKeyListener implements KeyListener,FrameKeyListenerAbstrac
}
}
/**
*//**
* This method relays the keyTyped KeyEvent recorded by the mainFrame to GraphicsMaster
* @param e: the KeyEvent that was recorded by the mainFrame
*/
*//*
public final void keyTyped(KeyEvent e) {
//graphicsMaster.keyTypedHandler(e);
}
}
}*/
......@@ -4,6 +4,6 @@ package graphics.ingame_input_listener;
* Created by zobi on 18/11/15.
*/
public enum Input {
SQUARE, TRIANGLE, CIRCLE, LEFT_ARROW ,RIGHT_ARROW ,UP_ARROW , DOWN_ARROW, ESCAPE
SQUARE, TRIANGLE, CIRCLE, LEFT_ARROW ,RIGHT_ARROW ,UP_ARROW , DOWN_ARROW, ESCAPE, EXCEPTION
}
......@@ -6,42 +6,30 @@ import java.awt.event.KeyEvent;
* Created by etouss on 09/11/2015.
*/
public class InputConfiguration {
/*Wont stay final*/
public static final int square = KeyEvent.VK_K;
public static final int circle = KeyEvent.VK_L;
public static final int cross = KeyEvent.VK_M;
public static int square = KeyEvent.VK_K;
public static int circle = KeyEvent.VK_L;
public static int triangle = KeyEvent.VK_M;
public static int escape = KeyEvent.VK_ESCAPE;
public static final int up = KeyEvent.VK_Z;
public static final int down = KeyEvent.VK_S;
public static final int right = KeyEvent.VK_D;
public static final int left = KeyEvent.VK_Q;
}
public static int up = KeyEvent.VK_Z;
public static int down = KeyEvent.VK_S;
public static int right = KeyEvent.VK_D;
public static int left = KeyEvent.VK_Q;
/*public class InputConfiguration{
Input input;
)
public InputConfig(Input input){
this.input = input;
}
public static Input GetInput(KeyEvent e){
int event=e.getKeyCode();
if (event==square){return Input.SQUARE;}
if (event==circle){return Input.CIRCLE;}
if (event==triangle){return Input.TRIANGLE;}
if (event==escape){return Input.ESCAPE;}
if (event==up){return Input.UP_ARROW;}
if (event==down){return Input.DOWN_ARROW;}
if (event==right){return Input.RIGHT_ARROW;}
if (event==left){return Input.LEFT_ARROW;}
else return Input.EXCEPTION;
public void InputConfig(){
switch (input){
case SQUARE:
break;
case TRIANGLE:
break;
case CIRCLE:
break;
case LEFT_ARROW:
break;
case RIGHT_ARROW:
break;
case UP_ARROW:
break;
case DOWN_ARROW:
break;
}
}
}
*/
\ No newline at end of file
public InputConfiguration(){}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment