Commit 13111efc authored by Huot Mathieu's avatar Huot Mathieu

functionnal inputConfiguration !

parent 97fc3b7e
......@@ -6,6 +6,7 @@ import graphics.guiSkeleton.guiPanel.*;
import graphics.guiSkeleton.guiPanel.menuPanel.*;
import graphics.guiSkeleton.guiPanel.menuPanel.characterChoice.MultiPlayer_CharacterChoicePanel;
import graphics.guiSkeleton.guiPanel.menuPanel.characterChoice.SinglePlayer_CharacterChoicePanel;
import graphics.guiSkeleton.guiPanel.menuPanel.configuration.ConfigurationPanel;
import graphics.guiSkeleton.guiPanel.menuPanel.gameCreation.MultiPlayer_GameCreationPanel;
import graphics.guiSkeleton.guiPanel.menuPanel.gameCreation.SinglePlayer_GameCreationPanel;
import graphics.guiSkeleton.guiPanel.menuPanel.gameLoad.SinglePlayer_LoadGamePanel;
......
package graphics.guiSkeleton.guiPanel.menuPanel;
package graphics.guiSkeleton.guiPanel.menuPanel.configuration;
import graphics.guiSkeleton.GUIColorsAndFonts;
import graphics.guiSkeleton.GraphicsMaster;
......@@ -17,19 +17,9 @@ import java.awt.event.ActionListener;
public class ConfigurationPanel extends MenuPanel {
private static final long serialVersionUID = 1L;
//TODO use those variable
/**
* if one configuration button is pressed then the corresponding variable
* is modified to true showing we are currently modifying it
*/
private static boolean escape = false;
private static boolean circle = false;
private static boolean square = false;
private static boolean triangle = false;
private static boolean moveUp = false;
private static boolean moveDown = false;
private static boolean moveRight = false;
private static boolean moveLeft = false;
private static Input InputBeingChanged = Input.NONE;
public static Input GetInputBeingChanged(){return InputBeingChanged;}
/** create a key Labels */
private JLabel makeKeyLabel(Input input){
......@@ -44,51 +34,77 @@ public class ConfigurationPanel extends MenuPanel {
super(graphicsMaster);
setTitlePanel("Configuration");
addToCentralColumn(ButtonMaker.makeButton("move up: " + (InputConfiguration.GetFormalInputString(Input.UP_ARROW)), configUpListener),1,1);
addToCentralColumn(ButtonMaker.makeButton("move up: ", configUpListener),1,1);
addToCentralColumn(ButtonMaker.makeButton("move down: ", configDownListener),1,1);
addToCentralColumn(ButtonMaker.makeButton("move right: ", configLeftListener),1,1);
addToCentralColumn(ButtonMaker.makeButton("move left: ", configRightListener),1,1);
addToCentralColumn(ButtonMaker.makeButton("attack: ", configAttackListener),1,1);
addToCentralColumn(ButtonMaker.makeButton("ability 1: ", configAbility1Listener),1,1);
addToCentralColumn(ButtonMaker.makeButton("ability 2: ", configAbility2Listener),1,1);
addToCentralColumn(ButtonMaker.makeButton("ability 3: ", configAbility3Listener),1,1);
addToCentralColumn(ButtonMaker.makeButton("back: ", backButtonListener),1,1);
//TODO: not working for now
/*// Creation of the list of the keys linked with the buttons previously created
ArrayList<JPanel> keyList = new ArrayList<JPanel>();
keyList.add(makeKeyLabel(Input.UP_ARROW));*/
}
/**###################################**/
/** List of the configuration buttons **/
/**###################################**/
private ActionListener configUpListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
moveUp=true;System.out.println(moveUp);
InputBeingChanged=Input.UP_ARROW;
InputChangeFrame.main("Move Up: current control: "+(InputConfiguration.GetFormalInputString(Input.UP_ARROW)));
}
};
private ActionListener configDownListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
moveDown=true;
InputBeingChanged=Input.DOWN_ARROW;
InputChangeFrame.main("Move Down: current control: "+(InputConfiguration.GetFormalInputString(Input.DOWN_ARROW)));
}
};
private ActionListener configLeftListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
InputBeingChanged=Input.LEFT_ARROW;
InputChangeFrame.main("Move Left: current control: "+(InputConfiguration.GetFormalInputString(Input.LEFT_ARROW)));
}
};
private ActionListener configRightListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
moveRight=true;
InputBeingChanged=Input.RIGHT_ARROW;
InputChangeFrame.main("Move Right: current control: "+(InputConfiguration.GetFormalInputString(Input.RIGHT_ARROW)));
}
};
private ActionListener configLeftListener = new ActionListener() {
private ActionListener configAttackListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
moveLeft=true;
InputBeingChanged=Input.ATTACK;
InputChangeFrame.main("Attack: current control: "+(InputConfiguration.GetFormalInputString(Input.ATTACK)));
}
};
private ActionListener configAbility1Listener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
InputBeingChanged=Input.ABILITY_1;
InputChangeFrame.main("First Ability: current control: "+(InputConfiguration.GetFormalInputString(Input.ABILITY_1)));
}
};
private ActionListener configAbility2Listener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
InputBeingChanged=Input.ABILITY_2;
InputChangeFrame.main("Second Ability: current control: "+(InputConfiguration.GetFormalInputString(Input.ABILITY_2)));}
};
private ActionListener configAbility3Listener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
InputBeingChanged=Input.ABILITY_3;
InputChangeFrame.main("Third Ability: current control: "+(InputConfiguration.GetFormalInputString(Input.ABILITY_3)));
}
};
private ActionListener backButtonListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
......@@ -100,24 +116,11 @@ public class ConfigurationPanel extends MenuPanel {
/** necessary as extension of guiPanel **/
/**###################################**/
@Override
public void keyPressedHandler(Input e) {
//TODO: find a way to do this : change Input e into KeyEvent e
/*if(moveUp==true){moveUp=false;System.out.println(moveUp);InputConfiguration.ChangeKey(Input.UP_ARROW,KeyEvent.VK_B);System.out.println(InputConfiguration.up);}
if (escape) {escape=false; InputConfiguration.ChangeInput(e,Input.ESCAPE);}
if (moveUp){moveUp=false; InputConfiguration.ChangeInput(e,Input.UP_ARROW);}
if (moveDown){moveDown=false; InputConfiguration.ChangeInput(e,Input.DOWN_ARROW);}
if (moveLeft) {moveLeft=false; InputConfiguration.ChangeInput(e,Input.LEFT_ARROW);}
if (moveRight){moveRight=false; InputConfiguration.ChangeInput(e,Input.RIGHT_ARROW);}
*/
}
public void keyPressedHandler(Input e) {}
@Override
public void keyReleasedHandler(Input e) {
// if(moveUp==true){moveUp=false; InputConfiguration.ChangeKey(Input.UP_ARROW,KeyEvent.VK_B);System.out.println(InputConfiguration.up);}
}
public void keyReleasedHandler(Input e) {}
@Override
public void keyTypedHandler(Input e) {
//if(moveUp==true){moveUp=false; InputConfiguration.ChangeKey(Input.UP_ARROW,KeyEvent.VK_B);System.out.println(InputConfiguration.up);}
}
public void keyTypedHandler(Input e) {}
@Override
public void initialise() {}
@Override
......
package graphics.guiSkeleton.guiPanel.menuPanel.configuration;
import graphics.ingame_input_listener.InputConfiguration;
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;
/**
* Created by zobi on 02/01/16.
*/
public class InputChangeFrame extends Frame implements ActionListener{
private ArrayList<Button> b= new ArrayList<Button>();
public static void main(String string) {
InputChangeFrame myWindow = new InputChangeFrame(string);
myWindow.setSize(600, 600);
myWindow.setVisible(true);
}
public InputChangeFrame(String title) {
super(title);
setLayout(new GridLayout(13, 2));
String alphabet="abcdefghijklmnopqrstuvwxyz";
for (int i=0;i<alphabet.length();i++) {
b.add(new Button(Character.toString(alphabet.charAt(i))));
b.get(i).addActionListener(this);
add(b.get(i));
}
}
public void actionPerformed(ActionEvent e) {
Object source=e.getSource();
for(int i=0;i<b.size();i++){
if(source==b.get(i)){
InputConfiguration.ChangeInput(ConfigurationPanel.GetInputBeingChanged(),b.get(i).getLabel());
dispose();
}
}
}
}
\ No newline at end of file
......@@ -211,6 +211,41 @@ public class InputConfiguration {
}
}
/**
*
* @param string a one character string representing a keyboard input
* @return the int linked to the keyEvent linked with the input underlying the string
*/
public static int GetIntFromString(String string){
if (string.equals("a")){return KeyEvent.VK_A;}
if (string.equals("b")){return KeyEvent.VK_B;}
if (string.equals("c")){return KeyEvent.VK_C;}
if (string.equals("d")){return KeyEvent.VK_D;}
if (string.equals("e")){return KeyEvent.VK_E;}
if (string.equals("f")){return KeyEvent.VK_F;}
if (string.equals("g")){return KeyEvent.VK_G;}
if (string.equals("j")){return KeyEvent.VK_J;}
if (string.equals("k")){return KeyEvent.VK_K;}
if (string.equals("l")){return KeyEvent.VK_L;}
if (string.equals("m")){return KeyEvent.VK_M;}
if (string.equals("n")){return KeyEvent.VK_N;}
if (string.equals("m")){return KeyEvent.VK_M;}
if (string.equals("n")){return KeyEvent.VK_N;}
if (string.equals("o")){return KeyEvent.VK_O;}
if (string.equals("p")){return KeyEvent.VK_P;}
if (string.equals("q")){return KeyEvent.VK_Q;}
if (string.equals("r")){return KeyEvent.VK_R;}
if (string.equals("s")){return KeyEvent.VK_S;}
if (string.equals("t")){return KeyEvent.VK_T;}
if (string.equals("u")){return KeyEvent.VK_U;}
if (string.equals("v")){return KeyEvent.VK_V;}
if (string.equals("w")){return KeyEvent.VK_W;}
if (string.equals("x")){return KeyEvent.VK_X;}
if (string.equals("y")){return KeyEvent.VK_Y;}
if (string.equals("z")){return KeyEvent.VK_Z;}
throw new IllegalStateException("Unknown input : "+ string);
}
/**
* @param input : a formal Input
* @return the string of the character linked to input
......@@ -275,38 +310,39 @@ public class InputConfiguration {
}
/**
* @param e : a key pressed
* @param input : a formal input
* @param string : a letter representing the key to which we want to link the input
* the key pressed linked to "input" is changed to "e"
*/
public static void ChangeInput(KeyEvent e, Input input){
public static void ChangeInput(Input input, String string){
int j=GetIntFromString(string);
switch (input){
case ATTACK:
attack=e.getKeyCode();
attack=j;
break;
case ABILITY_1:
ability1 =e.getKeyCode();
ability1 =j;
break;
case ABILITY_2:
ability2=e.getKeyCode();
ability2=j;
break;
case ABILITY_3:
ability3=e.getKeyCode();
ability3=j;
break;
case ESCAPE:
escape=e.getKeyCode();
escape=j;
break;
case UP_ARROW:
up=e.getKeyCode();
up=j;
break;
case DOWN_ARROW:
down=e.getKeyCode();
down=j;
break;
case RIGHT_ARROW:
right=e.getKeyCode();
right=j;
break;
case LEFT_ARROW:
left=e.getKeyCode();
left=j;
break;
case NONE:
return;
......
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