Re-implemented controller input system using LWJGL instead. Controller

inputs now work outside of window focus.
dev
sigonasr2 7 years ago
parent 93e062ad42
commit e203715025
  1. 10
      .classpath
  2. BIN
      lib/jinput-2.0.5.jar
  3. BIN
      lib/jutils-1.0.0.jar
  4. BIN
      lib/lwjgl-glfw-natives-linux.jar
  5. BIN
      lib/lwjgl-glfw-natives-macos.jar
  6. BIN
      lib/lwjgl-glfw-natives-windows.jar
  7. BIN
      lib/lwjgl-glfw.jar
  8. BIN
      lib/lwjgl-natives-linux.jar
  9. BIN
      lib/lwjgl-natives-macos.jar
  10. BIN
      lib/lwjgl-natives-windows.jar
  11. BIN
      lib/lwjgl.jar
  12. 10
      projectBuilder.xml
  13. 3
      sigIRCv2.bat
  14. BIN
      sigIRCv2.jar
  15. 134
      src/sig/modules/Controller/Axis.java
  16. 33
      src/sig/modules/Controller/Button.java
  17. 25
      src/sig/modules/Controller/Component.java
  18. 87
      src/sig/modules/Controller/ControlConfigurationWindow.java
  19. 80
      src/sig/modules/Controller/Controller.java
  20. 11
      src/sig/modules/Controller/Identifier.java
  21. 5
      src/sig/modules/Controller/Type.java
  22. 75
      src/sig/modules/ControllerModule.java
  23. 12
      src/sig/sigIRC.java

@ -5,7 +5,13 @@
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="lib" path="lib/commons-io-2.5.jar"/>
<classpathentry kind="lib" path="lib/twitch-api-wrapper-0.3-jar-with-dependencies.jar"/>
<classpathentry kind="lib" path="C:/Users/Joshua Sigona/git/sigIRCv2/lib/jinput-2.0.5.jar"/>
<classpathentry kind="lib" path="C:/Users/Joshua Sigona/git/sigIRCv2/lib/jutils-1.0.0.jar"/>
<classpathentry kind="lib" path="C:/Users/Joshua Sigona/git/sigIRCv2/lib/lwjgl-glfw.jar"/>
<classpathentry kind="lib" path="C:/Users/Joshua Sigona/git/sigIRCv2/lib/lwjgl-glfw-natives-linux.jar"/>
<classpathentry kind="lib" path="C:/Users/Joshua Sigona/git/sigIRCv2/lib/lwjgl-glfw-natives-macos.jar"/>
<classpathentry kind="lib" path="C:/Users/Joshua Sigona/git/sigIRCv2/lib/lwjgl-glfw-natives-windows.jar"/>
<classpathentry kind="lib" path="C:/Users/Joshua Sigona/git/sigIRCv2/lib/lwjgl.jar"/>
<classpathentry kind="lib" path="C:/Users/Joshua Sigona/git/sigIRCv2/lib/lwjgl-natives-linux.jar"/>
<classpathentry kind="lib" path="C:/Users/Joshua Sigona/git/sigIRCv2/lib/lwjgl-natives-macos.jar"/>
<classpathentry kind="lib" path="C:/Users/Joshua Sigona/git/sigIRCv2/lib/lwjgl-natives-windows.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -15,8 +15,14 @@
<fileset dir="${dir.jarfile}/bin"/>
<zipfileset excludes="META-INF/*.SF" src="lib/commons-io-2.5.jar"/>
<zipfileset excludes="META-INF/*.SF" src="lib/twitch-api-wrapper-0.3-jar-with-dependencies.jar"/>
<zipfileset excludes="META-INF/*.SF" src="lib/jinput-2.0.5.jar"/>
<zipfileset excludes="META-INF/*.SF" src="lib/jutils-1.0.0.jar"/>
<zipfileset excludes="META-INF/*.SF" src="lib/lwjgl-glfw.jar"/>
<zipfileset excludes="META-INF/*.SF" src="lib/lwjgl-glfw-natives-linux.jar"/>
<zipfileset excludes="META-INF/*.SF" src="lib/lwjgl-glfw-natives-windows.jar"/>
<zipfileset excludes="META-INF/*.SF" src="lib/lwjgl-glfw-natives-macos.jar"/>
<zipfileset excludes="META-INF/*.SF" src="lib/lwjgl.jar"/>
<zipfileset excludes="META-INF/*.SF" src="lib/lwjgl-natives-linux.jar"/>
<zipfileset excludes="META-INF/*.SF" src="lib/lwjgl-natives-windows.jar"/>
<zipfileset excludes="META-INF/*.SF" src="lib/lwjgl-natives-macos.jar"/>
</jar>
</target>
</project>

@ -1 +1,2 @@
java -jar ./sigIRCv2.jar -Djava.library.path=lib/
cd "C:\Users\Joshua Sigona\git\sigIRCv2\"
java -jar sigIRCv2.jar -Djinput.useDefaultPlugin=false -Djinput.plugins=net.java.games.input.DirectInputEnvironmentPlugin

Binary file not shown.

@ -6,14 +6,11 @@ import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
import java.util.List;
import net.java.games.input.Component;
import net.java.games.input.Controller;
import net.java.games.input.Component.Identifier;
import sig.sigIRC;
import sig.modules.ControllerModule;
public class Axis {
List<Identifier> identifiers = new ArrayList<Identifier>();
List<Integer> identifiers = new ArrayList<Integer>();
boolean twoWayAxis = false; //True = 4-way, False = 2-way
Color backgroundColor=Color.BLACK,indicatorColor=Color.WHITE;
double pct_x = 0;
@ -25,16 +22,20 @@ public class Axis {
double range1,range2; //Range of motion.
int orientation; //0=Left-to-Right, 1=Right-to-Left, 2=Bottom-to-Top, 3=Top-to-Bottom
boolean visible=false;
boolean x_invert,y_invert,axis_invert;
/**
* 4-way axis Constructor.
*/
public Axis(Rectangle2D.Double rect,
Controller parent_controller,
Identifier identifier,
Identifier identifier2,
Integer identifier,
Integer identifier2,
Color background_color,
Color indicator_color,
boolean x_invert,
boolean y_invert,
boolean axis_invert,
ControllerModule module) {
this.twoWayAxis=false;
this.pct_x = rect.getX();
@ -51,6 +52,9 @@ public class Axis {
this.parent = module;
this.backgroundColor = background_color;
this.indicatorColor = indicator_color;
this.x_invert = x_invert;
this.y_invert = y_invert;
this.axis_invert = axis_invert;
}
/**
@ -58,12 +62,13 @@ public class Axis {
*/
public Axis(Rectangle2D.Double rect,
Controller parent_controller,
Identifier identifier,
Integer identifier,
double starting_range,
double ending_range,
int orientation,
Color background_color,
Color indicator_color,
boolean x_invert,
ControllerModule module) {
this.twoWayAxis=true;
this.pct_x = rect.getX();
@ -80,6 +85,7 @@ public class Axis {
this.orientation = orientation;
this.backgroundColor = background_color;
this.indicatorColor = indicator_color;
this.x_invert = x_invert;
}
public void draw(Graphics g) {
@ -92,6 +98,18 @@ public class Axis {
}
}
public boolean is_Xinverted() {
return x_invert;
}
public boolean is_Yinverted() {
return y_invert;
}
public boolean is_Axisinverted() {
return axis_invert;
}
public void setupBoundsRectangle(Rectangle2D.Double rect) {
this.pct_x = rect.getX();
this.pct_y = rect.getY();
@ -107,7 +125,7 @@ public class Axis {
return backgroundColor;
}
public List<Identifier> getIdentifiers() {
public List<Integer> getIdentifiers() {
return identifiers;
}
@ -166,8 +184,9 @@ public class Axis {
g.fillRect((int)x, (int)y, (int)xscale, (int)yscale);
g.setColor(a.indicatorColor);
double val = 0;
if (a.identifiers.size()>=1) {
val=a.parent_controller.getComponent(a.identifiers.get(0)).getPollData();
if (a.identifiers.size()>=1 && a.identifiers.get(0)!=-1) {
val=a.parent_controller.getAxisValue(a.identifiers.get(0))*((a.x_invert)?-1:1);
//val=a.parent_controller.getComponent(a.identifiers.get(0)).getPollData();
}
double val1 = a.range1;
double val2 = a.range2;
@ -196,16 +215,11 @@ public class Axis {
} else {
double xval=0;
double yval=0;
for (int i=0;i<a.identifiers.size();i++) {
Identifier ident = a.identifiers.get(i);
if (ident.getName().contains("x") ||
ident.getName().contains("X")) {
xval = a.parent_controller.getComponent(ident).getPollData();
} else
if (ident.getName().contains("y") ||
ident.getName().contains("Y")) {
yval = a.parent_controller.getComponent(ident).getPollData();
if (a.identifiers.size()>0 && a.identifiers.get(0)!=null) {
xval = a.parent_controller.getAxisValue(a.identifiers.get(0))*((a.x_invert)?-1:1);
}
if (a.identifiers.size()>1 && a.identifiers.get(1)!=null) {
yval = a.parent_controller.getAxisValue(a.identifiers.get(1))*((a.y_invert)?-1:1);
}
Color color_identity = g.getColor();
g.setColor(a.backgroundColor);
@ -219,4 +233,86 @@ public class Axis {
g.setColor(color_identity);
}
}
public String getSaveString() {
StringBuilder sb = new StringBuilder();
sb.append(pct_x);sb.append(",");
sb.append(pct_y);sb.append(",");
sb.append(pct_width);sb.append(",");
sb.append(pct_height);sb.append(",");
sb.append(twoWayAxis);sb.append(",");
if (twoWayAxis) {
sb.append((identifiers.size()>0 &&
identifiers.get(0)!=null)?identifiers.get(0):"null");sb.append(",");
sb.append(range1);sb.append(",");
sb.append(range2);sb.append(",");
sb.append(orientation);sb.append(",");
} else {
sb.append((identifiers.size()>0 &&
identifiers.get(0)!=null)?identifiers.get(0):"null");sb.append(",");
sb.append((identifiers.size()>1 &&
identifiers.get(1)!=null)?identifiers.get(1):"null");sb.append(",");
}
sb.append(backgroundColor.getRed());sb.append(",");
sb.append(backgroundColor.getGreen());sb.append(",");
sb.append(backgroundColor.getBlue());sb.append(",");
sb.append(backgroundColor.getAlpha());sb.append(",");
sb.append(indicatorColor.getRed());sb.append(",");
sb.append(indicatorColor.getGreen());sb.append(",");
sb.append(indicatorColor.getBlue());sb.append(",");
sb.append(indicatorColor.getAlpha());sb.append(",");
sb.append(x_invert);sb.append(",");
if (!twoWayAxis) {
sb.append(y_invert);sb.append(",");
sb.append(axis_invert);
}
return sb.toString();
}
public static Axis loadFromString(String s, Controller controller, ControllerModule module) {
String[] split = s.split(",");
int i=0;
Rectangle2D.Double rect = new Rectangle2D.Double(Double.parseDouble(split[i++]), Double.parseDouble(split[i++]), Double.parseDouble(split[i++]), Double.parseDouble(split[i++]));
boolean twoway = Boolean.parseBoolean(split[i++]);
if (twoway) {
return new Axis(rect,controller,
Integer.parseInt(split[i++]),
Double.parseDouble(split[i++]),
Double.parseDouble(split[i++]),
Integer.parseInt(split[i++]),
new Color(Integer.parseInt(split[i++]),Integer.parseInt(split[i++]),Integer.parseInt(split[i++]),Integer.parseInt(split[i++])),
new Color(Integer.parseInt(split[i++]),Integer.parseInt(split[i++]),Integer.parseInt(split[i++]),Integer.parseInt(split[i++])),
Boolean.parseBoolean(split[i++]),
module
);
} else {
return new Axis(rect,controller,
Integer.parseInt(split[i++]),
Integer.parseInt(split[i++]),
new Color(Integer.parseInt(split[i++]),Integer.parseInt(split[i++]),Integer.parseInt(split[i++]),Integer.parseInt(split[i++])),
new Color(Integer.parseInt(split[i++]),Integer.parseInt(split[i++]),Integer.parseInt(split[i++]),Integer.parseInt(split[i++])),
Boolean.parseBoolean(split[i++]),
Boolean.parseBoolean(split[i++]),
Boolean.parseBoolean(split[i++]),
module
);
}
/*Double.parseDouble(split[i++]),
Double.parseDouble(split[i++]),
Double.parseDouble(split[i++]),
Double.parseDouble(split[i++]),
controller,
GrabIdentifierFromString(split[i++],controller),
Float.parseFloat(split[i++]),
new Color(
Integer.parseInt(split[i++]),
Integer.parseInt(split[i++]),
Integer.parseInt(split[i++]),
Integer.parseInt(split[i++])
),
module,
Boolean.parseBoolean(split[i++]));*/
}
}

@ -4,9 +4,6 @@ import java.awt.Color;
import java.awt.Graphics;
import java.awt.geom.Rectangle2D;
import net.java.games.input.Component.Identifier;
import net.java.games.input.Component;
import net.java.games.input.Controller;
import sig.sigIRC;
import sig.modules.ControllerModule;
@ -15,26 +12,26 @@ public class Button {
double pct_y = 0;
double pct_width = 0;
double pct_height = 0;
Identifier ident;
float value;
int ident;
byte value;
Controller parent_controller;
Color pressed_col;
ControllerModule parent;
boolean square;
public Button(Rectangle2D.Double rect, Controller parent_controller, Identifier button_identifier, float button_val, Color col, ControllerModule module) {
public Button(Rectangle2D.Double rect, Controller parent_controller, int button_identifier, byte button_val, Color col, ControllerModule module) {
this(rect.getX(),rect.getY(),rect.getWidth(),rect.getHeight(),parent_controller,button_identifier,button_val,col,module,false);
}
public Button(Rectangle2D.Double rect, Controller parent_controller, Identifier button_identifier, float button_val, Color col, ControllerModule module, boolean square) {
public Button(Rectangle2D.Double rect, Controller parent_controller, int button_identifier, byte button_val, Color col, ControllerModule module, boolean square) {
this(rect.getX(),rect.getY(),rect.getWidth(),rect.getHeight(),parent_controller,button_identifier,button_val,col,module,square);
}
public Button(double pct_x, double pct_y, double pct_width, double pct_height, Controller parent_controller, Identifier button_identifier, float button_val, Color col, ControllerModule module) {
public Button(double pct_x, double pct_y, double pct_width, double pct_height, Controller parent_controller, int button_identifier, byte button_val, Color col, ControllerModule module) {
this(pct_x,pct_y,pct_width,pct_height,parent_controller,button_identifier,button_val,col,module,false);
}
public Button(double pct_x, double pct_y, double pct_width, double pct_height, Controller parent_controller, Identifier button_identifier, float button_val, Color col, ControllerModule module, boolean square) {
public Button(double pct_x, double pct_y, double pct_width, double pct_height, Controller parent_controller, int button_identifier, byte button_val, Color col, ControllerModule module, boolean square) {
this.pct_x = pct_x;
this.pct_y = pct_y;
this.pct_width=pct_width;
@ -48,7 +45,7 @@ public class Button {
}
public void draw(Graphics g) {
if (parent_controller.getComponent(ident).getPollData()==value) {
if (parent_controller.getButtonValue(ident)==value) {
Color col_identity = g.getColor();
g.setColor(pressed_col);
if (square) {
@ -76,7 +73,7 @@ public class Button {
sb.append(pct_y);sb.append(",");
sb.append(pct_width);sb.append(",");
sb.append(pct_height);sb.append(",");
sb.append(ident.getName());sb.append(",");
sb.append(ident);sb.append(",");
sb.append(value);sb.append(",");
sb.append(pressed_col.getRed());sb.append(",");
sb.append(pressed_col.getGreen());sb.append(",");
@ -95,8 +92,8 @@ public class Button {
Double.parseDouble(split[i++]),
Double.parseDouble(split[i++]),
controller,
GrabIdentifierFromString(split[i++],controller),
Float.parseFloat(split[i++]),
Integer.parseInt(split[i++]),
Byte.parseByte(split[i++]),
new Color(
Integer.parseInt(split[i++]),
Integer.parseInt(split[i++]),
@ -106,14 +103,4 @@ public class Button {
module,
Boolean.parseBoolean(split[i++]));
}
private static Identifier GrabIdentifierFromString(String string, Controller controller) {
for (Component cp : controller.getComponents()) {
Identifier id = cp.getIdentifier();
if (id.getName().equals(string)) {
return id;
}
}
return null;
}
}

@ -0,0 +1,25 @@
package sig.modules.Controller;
public class Component {
public boolean isAnalog() {
// TODO Auto-generated method stub
return false;
}
public float getPollData() {
// TODO Auto-generated method stub
return 0;
}
public Identifier getIdentifier() {
// TODO Auto-generated method stub
return null;
}
public String getName() {
// TODO Auto-generated method stub
return null;
}
}

@ -37,9 +37,6 @@ import javax.swing.border.Border;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import net.java.games.input.Component;
import net.java.games.input.Component.Identifier;
import net.java.games.input.Controller;
import sig.ColorPanel;
import sig.sigIRC;
import sig.modules.ControllerModule;
@ -47,7 +44,7 @@ import sig.modules.ControllerModule;
public class ControlConfigurationWindow extends JFrame implements WindowListener{
DialogType dialog;
List<JPanel> panels = new ArrayList<JPanel>();
List<Component> analog_controller_components = new ArrayList<Component>();
List<Integer> analog_controller_components = new ArrayList<Integer>();
List<JCheckBox> analog_controller_component_labels = new ArrayList<JCheckBox>();
ControllerModule module;
DecimalFormat df = new DecimalFormat("0.000");
@ -60,7 +57,10 @@ public class ControlConfigurationWindow extends JFrame implements WindowListener
Color axis_indicator_col = Color.WHITE;
int axis_width=32,axis_height=32;
JButton backgroundColor,indicatorColor;
boolean x_invert,y_invert,axis_invert;
int orientation=0; //0=Left-to-Right, 1=Right-to-Left, 2=Bottom-to-Top, 3=Top-to-Bottom
JCheckBox width_invert,height_invert;
java.awt.Component extra_space;
ActionListener checkboxListener = new ActionListener(){
@Override
public void actionPerformed(ActionEvent ev) {
@ -78,7 +78,7 @@ public class ControlConfigurationWindow extends JFrame implements WindowListener
private void UncheckPreviouslyCheckedbox(ActionEvent ev) {
for (int i=0;i<analog_controller_components.size();i++) {
if (analog_controller_components.get(i).getName().equals(ev.getActionCommand())) {
if (Integer.toString(analog_controller_components.get(i)).equals(ev.getActionCommand())) {
analog_controller_component_labels.get(i).setSelected(false);
}
}
@ -93,6 +93,7 @@ public class ControlConfigurationWindow extends JFrame implements WindowListener
previewpanel.setAxis(false);
twowayAxis_adjustContainer.setVisible(false);
twowayAxis_adjustOrientationContainer.setVisible(false);
height_invert.setVisible(true);
}break;
case "two":{
previewpanel.setAxis(true);
@ -108,8 +109,10 @@ public class ControlConfigurationWindow extends JFrame implements WindowListener
}
twowayAxis_adjustContainer.setVisible(true);
twowayAxis_adjustOrientationContainer.setVisible(true);
height_invert.setVisible(false);
}break;
}
extra_space.setVisible(two_axis_button.isSelected());
}
};
ActionListener backgroundColorListener = new ActionListener(){
@ -156,6 +159,16 @@ public class ControlConfigurationWindow extends JFrame implements WindowListener
return true;
}
};
ActionListener invertListener = new ActionListener(){
@Override
public void actionPerformed(ActionEvent ev) {
if (ev.getActionCommand().equals("x")) {
x_invert=width_invert.isSelected();
} else {
y_invert=height_invert.isSelected();
}
}
};
public ControlConfigurationWindow(DialogType type, ControllerModule parent_module) {
this.setVisible(true);
@ -222,11 +235,11 @@ public class ControlConfigurationWindow extends JFrame implements WindowListener
selectionPanel2.setBackground(new Color(0,0,255,96));
int counter=0;
for (Controller c : module.getControllers()) {
for (Component cp : c.getComponents()) {
if (cp.isAnalog()) {
analog_controller_components.add(cp);
JCheckBox component_checkbox = new JCheckBox(GetComponentValue(cp),false);
component_checkbox.setActionCommand(cp.getName());
for (int i=0;i<c.getAxes().length;i++) {
float axis = c.getAxisValue(i);
analog_controller_components.add(i);
JCheckBox component_checkbox = new JCheckBox(GetComponentValue(i),false);
component_checkbox.setActionCommand(Integer.toString(i));
component_checkbox.addActionListener(checkboxListener);
analog_controller_component_labels.add(component_checkbox);
axisPanel.add(component_checkbox);
@ -238,7 +251,6 @@ public class ControlConfigurationWindow extends JFrame implements WindowListener
}
}
}
}
for (JPanel panel : panels) {
container.add(panel);
}
@ -284,21 +296,45 @@ public class ControlConfigurationWindow extends JFrame implements WindowListener
Container sizePanel = new Container();
sizePanel.setLayout(new BoxLayout(sizePanel,BoxLayout.PAGE_AXIS));
JPanel widthPanel = new JPanel();
widthPanel.setLayout(new BoxLayout(widthPanel,BoxLayout.LINE_AXIS));
widthPanel.setPreferredSize(new Dimension(164,20));
JPanel heightPanel = new JPanel();
heightPanel.setPreferredSize(new Dimension(164,20));
heightPanel.setLayout(new BoxLayout(heightPanel,BoxLayout.LINE_AXIS));
JLabel widthLabel = new JLabel("Width: ");
JTextField width_field = new JTextField("32",3);
width_field.setPreferredSize(new Dimension(32,20));
width_field.setMaximumSize(new Dimension(32,20));
width_invert = new JCheckBox("Inverted");
width_invert.addActionListener(invertListener);
width_invert.setActionCommand("x");
ResizeTextField width_field_listener = new ResizeTextField(width_field,this,SizeType.WIDTH);
width_field.getDocument().addDocumentListener(width_field_listener);
JLabel heightLabel = new JLabel("Height: ");
JTextField height_field = new JTextField("32",3);
height_field.setPreferredSize(new Dimension(32,20));
height_field.setMaximumSize(new Dimension(32,20));
height_invert = new JCheckBox("Inverted");
height_invert.addActionListener(invertListener);
extra_space = Box.createRigidArea(height_invert.getMaximumSize());
extra_space.setVisible(two_axis_button.isSelected());
width_invert.setActionCommand("y");
ResizeTextField height_field_listener = new ResizeTextField(height_field,this,SizeType.HEIGHT);
height_field.getDocument().addDocumentListener(height_field_listener);
sizePanel.add(widthLabel);
sizePanel.add(width_field);
sizePanel.add(Box.createRigidArea(new Dimension(4,0)));
sizePanel.add(heightLabel);
sizePanel.add(height_field);
sizePanel.setPreferredSize(new Dimension(56,96));
widthPanel.add(widthLabel);
widthPanel.add(width_field);
widthPanel.add(width_invert);
heightPanel.add(heightLabel);
heightPanel.add(height_field);
heightPanel.add(height_invert);
heightPanel.add(extra_space);
sizePanel.add(widthPanel);
sizePanel.add(Box.createRigidArea(new Dimension(0,8)));
sizePanel.add(heightPanel);
sizePanel.setPreferredSize(new Dimension(164,64));
ButtonGroup twoWayAxisOrientationGroup = new ButtonGroup();
JRadioButton twoWayAxis_LeftToRight = new JRadioButton("Left-to-Right",true);
@ -389,8 +425,9 @@ public class ControlConfigurationWindow extends JFrame implements WindowListener
}
}
private String GetComponentValue(Component component) {
return component.getName()+": "+df.format(component.getPollData())+" ";
private String GetComponentValue(int axis) {
float val = module.getControllers().get(0).getAxisValue(axis);
return "Axis "+axis+": "+df.format(val)+" ";
}
public void run() {
@ -443,10 +480,10 @@ public class ControlConfigurationWindow extends JFrame implements WindowListener
protected Axis ConstructTemporaryAxis() {
Axis a;
if (two_axis_button.isSelected()) {
Identifier ident=null;
int ident=-1;
for (int i=0;i<analog_controller_component_labels.size();i++) {
if (analog_controller_component_labels.get(i).isSelected()) {
ident=analog_controller_components.get(i).getIdentifier();
ident=analog_controller_components.get(i);
break;
}
}
@ -458,15 +495,16 @@ public class ControlConfigurationWindow extends JFrame implements WindowListener
orientation,
axis_background_col,
axis_indicator_col,
x_invert,
module);
} else {
List<Identifier> ident=new ArrayList<Identifier>();
List<Integer> ident=new ArrayList<Integer>();
ident.add(null);
ident.add(null);
int count=0;
for (int i=0;i<analog_controller_component_labels.size();i++) {
if (analog_controller_component_labels.get(i).isSelected()) {
ident.set(count++,analog_controller_components.get(i).getIdentifier());
ident.set(count++,analog_controller_components.get(i));
}
}
a = new Axis(new Rectangle2D.Double(),
@ -475,6 +513,9 @@ public class ControlConfigurationWindow extends JFrame implements WindowListener
ident.get(1),
axis_background_col,
axis_indicator_col,
x_invert,
y_invert,
axis_invert,
module);
}
return a;

@ -0,0 +1,80 @@
package sig.modules.Controller;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import java.util.Arrays;
import org.lwjgl.glfw.GLFW;
public class Controller {
int identifier;
float[] axes;
byte[] buttons;
public Controller(int identifier) {
this.identifier=identifier;
FloatBuffer axisBuffer = GLFW.glfwGetJoystickAxes(identifier);
axes = new float[axisBuffer.limit()];
axisBuffer.get(axes);
ByteBuffer buttonBuffer = GLFW.glfwGetJoystickButtons(identifier);
buttons = new byte[buttonBuffer.limit()];
buttonBuffer.get(buttons);
}
public String outputAxes() {
return Arrays.toString(axes);
}
public String outputButtons() {
return Arrays.toString(buttons);
}
public float[] getAxes() {
return axes;
}
public byte[] getButtons() {
return buttons;
}
public float getAxisValue(int axisNumber) {
return axes[axisNumber];
}
public byte getButtonValue(int buttonNumber) {
return buttons[buttonNumber];
}
@Deprecated
public Type getType() {
return null;
}
@Deprecated
public String getName() {
return null;
}
public void poll() {
//System.out.println(Glfw.glfwGetJoystickParam(identifier, 1));
FloatBuffer axisBuffer = GLFW.glfwGetJoystickAxes(identifier);
axes = new float[axisBuffer.limit()];
axisBuffer.get(axes);
ByteBuffer buttonBuffer = GLFW.glfwGetJoystickButtons(identifier);
buttons = new byte[buttonBuffer.limit()];
buttonBuffer.get(buttons);
//System.out.println(outputAxes()+","+outputButtons());
}
@Deprecated
public Component[] getComponents() {
return new Component[]{};
}
@Deprecated
public Component getComponent(Identifier identifier2) {
return null;
}
}

@ -0,0 +1,11 @@
package sig.modules.Controller;
import java.awt.geom.RectangularShape;
public class Identifier {
public String getName() {
return null;
}
}

@ -0,0 +1,5 @@
package sig.modules.Controller;
public enum Type {
GAMEPAD
}

@ -7,6 +7,7 @@ import java.awt.Image;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.MouseEvent;
import java.awt.event.WindowEvent;
import java.awt.geom.Rectangle2D;
import java.io.File;
import java.io.IOException;
@ -15,18 +16,19 @@ import java.util.List;
import javax.imageio.ImageIO;
import net.java.games.input.Component;
import net.java.games.input.Component.Identifier;
import net.java.games.input.Controller;
import net.java.games.input.Controller.Type;
import net.java.games.input.ControllerEnvironment;
import org.lwjgl.glfw.GLFW;
import sig.Module;
import sig.sigIRC;
import sig.modules.Controller.Axis;
import sig.modules.Controller.Button;
import sig.modules.Controller.ClickableButton;
import sig.modules.Controller.Component;
import sig.modules.Controller.ControlConfigurationWindow;
import sig.modules.Controller.Controller;
import sig.modules.Controller.EditMode;
import sig.modules.Controller.Identifier;
import sig.modules.Controller.Type;
import sig.modules.Controller.clickablebutton.AddClickableButton;
import sig.modules.Controller.clickablebutton.CopyClickableButton;
import sig.utils.DrawUtils;
@ -44,7 +46,7 @@ public class ControllerModule extends Module{
String status = "";
Point start_drag,end_drag;
Rectangle2D.Double stored_rect;
Identifier stored_controller_button;
int stored_controller_button;
float stored_controller_value;
Color buttoncol;
Controller controller;
@ -54,18 +56,21 @@ public class ControllerModule extends Module{
public ControllerModule(Rectangle2D bounds, String moduleName) {
super(bounds, moduleName);
Controller[] ca = ControllerEnvironment.getDefaultEnvironment().getControllers();
for (Controller c : ca) {
if (c.getType()==Type.GAMEPAD) {
controllers.add(c);
System.out.println("Recognized "+c.getName()+": "+c.getType());
//System.out.println("Components: ");
/*for (Component cp : c.getComponents()) {
System.out.println(" "+cp.getName()+" ("+cp.getIdentifier().getName()+")");
}*/
if (!GLFW.glfwInit()) {
System.out.println("Failed to initialize GLFW!");
} else {
System.out.println("Successfully initialized GLFW.");
}
//System.out.println(c.getName()+": "+c.getType());
List<Controller> ca = new ArrayList<Controller>();
for (int i=0;i<GLFW.GLFW_JOYSTICK_LAST;i++) {
//System.out.println("Joystick "+i+": "+GLFW.glfwGetJoystickName(i));
if (GLFW.glfwGetJoystickName(i)!=null) {
Controller c = new Controller(i);
ca.add(c);
System.out.println("Recognized "+GLFW.glfwGetJoystickName(i)+": "+c.outputAxes()+","+c.outputButtons());
}
}
controllers.addAll(ca);
try {
controller_img = ImageIO.read(new File(CONTROLLERPATH+"controller_template.png")).getScaledInstance((int)position.getWidth(), -1, 0);
//System.out.println("Size of controller: "+controller_img.getWidth(sigIRC.panel)+","+controller_img.getHeight(sigIRC.panel));
@ -73,7 +78,7 @@ public class ControllerModule extends Module{
e.printStackTrace();
}
//buttons.add(new Button(0.1,0.05,0.1,0.05,controllers.get(0),Identifier.Button._3,Color.RED,this));
LoadButtonData();
LoadButtonAndAxisData();
click_buttons.add(new AddClickableButton(new Rectangle(
0,(int)position.getHeight()-41,96,20),"Add Button",this));
click_buttons.add(new CopyClickableButton(new Rectangle(
@ -236,12 +241,13 @@ public class ControllerModule extends Module{
}
super.run();
if (MODE==EditMode.BUTTONSET) {
stored_controller_button=null;
stored_controller_button=-1;
for (Controller c : controllers) {
for (Component cp : c.getComponents()) {
if (!cp.isAnalog() && cp.getPollData()!=0.0f) {
stored_controller_button = cp.getIdentifier();
stored_controller_value = cp.getPollData();
for (int i=0;i<c.getButtons().length;i++) {
byte b = c.getButtonValue(i);
if (b!=(byte)0) {
stored_controller_button = i;
stored_controller_value = b;
controller=c;
MODE=EditMode.COLORSET;
buttoncol = PopupColorPanel();
@ -250,7 +256,7 @@ public class ControllerModule extends Module{
break;
}
}
if (stored_controller_button!=null) {
if (stored_controller_button!=-1) {
break;
}
}
@ -266,6 +272,8 @@ public class ControllerModule extends Module{
public void draw(Graphics g) {
super.draw(g);
if (controllers.size()>0) {
//System.out.println(controllers.get(0).outputAxes()+","+controllers.get(0).outputButtons());
for (int i=0;i<controllers.get(0).getComponents().length;i++) {
Component cp = controllers.get(0).getComponents()[i];
/*if (!cp.isAnalog()) {
@ -276,6 +284,7 @@ public class ControllerModule extends Module{
}*/
}
g.drawImage(controller_img, (int)(position.getX()), (int)(position.getY()), sigIRC.panel);
}
DrawUtils.drawText(g, position.getX(), position.getY()+8, Color.BLACK, status);
for (Button b : buttons) {
b.draw(g);
@ -325,7 +334,7 @@ public class ControllerModule extends Module{
}
}
private void LoadButtonData() {
private void LoadButtonAndAxisData() {
String[] buttondata = FileUtils.readFromFile(CONTROLLERPATH+"button_data.txt");
if (controllers.size()>0) {
for (String s : buttondata) {
@ -334,6 +343,17 @@ public class ControllerModule extends Module{
}
}
}
String[] axisdata = FileUtils.readFromFile(CONTROLLERPATH+"axis_data.txt");
if (controllers.size()>0) {
for (String s : axisdata) {
if (s.length()>0) {
//System.out.println("Creating new axis using string "+s+".");
Axis a = Axis.loadFromString(s, controllers.get(0), this);
a.setVisible(true);
axes.add(a);
}
}
}
}
private void AddAxis() {
@ -341,10 +361,15 @@ public class ControllerModule extends Module{
temporary_axis.setVisible(true);
axes.add(temporary_axis);
temporary_axis=null;
StringBuilder sb = new StringBuilder();
for (Axis a : axes) {
sb.append(a.getSaveString()+"\n");
}
FileUtils.writetoFile(new String[]{sb.toString()}, CONTROLLERPATH+"axis_data.txt");
}
private void AddButton() {
buttons.add(new Button(stored_rect,controller,stored_controller_button,stored_controller_value,buttoncol,this));
buttons.add(new Button(stored_rect,controller,stored_controller_button,(byte)stored_controller_value,buttoncol,this));
StringBuilder sb = new StringBuilder();
for (Button b : buttons) {
sb.append(b.getSaveString()+"\n");

@ -267,16 +267,6 @@ public class sigIRC{
manager = new FileManager("update.png"); manager.verifyAndFetchFileFromServer();
manager = new FileManager("backcolor.png"); manager.verifyAndFetchFileFromServer();
manager = new FileManager("drag_bar.png"); manager.verifyAndFetchFileFromServer();
if (controllermodule_enabled) {
manager = new FileManager("jinput-dx8.dll"); manager.verifyAndFetchFileFromServer();
manager = new FileManager("jinput-dx8_64.dll"); manager.verifyAndFetchFileFromServer();
manager = new FileManager("jinput-raw.dll"); manager.verifyAndFetchFileFromServer();
manager = new FileManager("jinput-raw_64.dll"); manager.verifyAndFetchFileFromServer();
manager = new FileManager("jinput-wintab.dll"); manager.verifyAndFetchFileFromServer();
manager = new FileManager("libjinput-linux.so"); manager.verifyAndFetchFileFromServer();
manager = new FileManager("libjinput-linux64.so"); manager.verifyAndFetchFileFromServer();
manager = new FileManager("libjinput-osx.jnilib"); manager.verifyAndFetchFileFromServer();
}
DownloadProgramUpdate();
System.out.println("Downloaded Dependencies. ");
}
@ -542,6 +532,8 @@ public class sigIRC{
}
System.setProperty("sun.java2d.opengl", Boolean.toString(sigIRC.hardwareAcceleration));
JFrame f = new JFrame("sigIRCv2");
f.setAutoRequestFocus(true);
f.toFront();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
if (sigIRC.overlayMode && !sigIRC.showWindowControls) {
f.setUndecorated(true);

Loading…
Cancel
Save