diff --git a/sigIRCv2.jar b/sigIRCv2.jar index 7cd43f2..5341094 100644 Binary files a/sigIRCv2.jar and b/sigIRCv2.jar differ diff --git a/src/sig/modules/Controller/Axis.java b/src/sig/modules/Controller/Axis.java index 4e62ec3..d38038d 100644 --- a/src/sig/modules/Controller/Axis.java +++ b/src/sig/modules/Controller/Axis.java @@ -93,6 +93,16 @@ public class Axis extends Element{ pct_height*parent.getControllerImage().getHeight(sigIRC.panel)); } } + + public void drawIndicator(Graphics g) { + if (visible) { + GetAxisIndicatorDisplay(g,this, + parent.getPosition().getX()+pct_x*parent.getControllerImage().getWidth(sigIRC.panel), + parent.getPosition().getY()+pct_y*parent.getControllerImage().getHeight(sigIRC.panel), + pct_width*parent.getControllerImage().getWidth(sigIRC.panel), + pct_height*parent.getControllerImage().getHeight(sigIRC.panel)); + } + } public Color getSelectionColor() { return backgroundColor; @@ -224,18 +234,38 @@ public class Axis extends Element{ Color color_identity = g.getColor(); g.setColor(a.backgroundColor); g.fillOval((int)x, (int)y, (int)xscale, (int)yscale); - g.setColor(a.indicatorColor); - for (int i=-1;i<2;i++) { - for (int j=-1;j<2;j++) { - g.drawOval((int)(((xval+1)*12*(xscale/32d))+i+x), (int)(((yval+1)*12*(yscale/32d))+j+y), (int)(8d*(xscale/32d)), (int)(8d*(yscale/32d))); - } - } g.setColor(color_identity); } } + public static void GetAxisIndicatorDisplay(Graphics g, Axis a, double x, double y, double xscale, double yscale) { + if (!a.twoWayAxis) { + double xval=0; + double yval=0; + 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); + } + DrawIndicator(g, a, x, y, xscale, yscale, xval, yval); + } + } + + private static void DrawIndicator(Graphics g, Axis a, double x, double y, double xscale, double yscale, double xval, + double yval) { + g.setColor(a.indicatorColor); + for (int i=-1;i<2;i++) { + for (int j=-1;j<2;j++) { + g.drawOval((int)(((xval+1)*12*(xscale/32d))+i+x), (int)(((yval+1)*12*(yscale/32d))+j+y), (int)(8d*(xscale/32d)), (int)(8d*(yscale/32d))); + } + } + } + + + public String getSaveString() { StringBuilder sb = new StringBuilder(); sb.append(pct_x);sb.append(","); diff --git a/src/sig/modules/Controller/ControlConfigurationWindow.java b/src/sig/modules/Controller/ControlConfigurationWindow.java index 493d73c..a501432 100644 --- a/src/sig/modules/Controller/ControlConfigurationWindow.java +++ b/src/sig/modules/Controller/ControlConfigurationWindow.java @@ -30,6 +30,7 @@ import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JLayeredPane; +import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JRadioButton; import javax.swing.JTextField; @@ -41,6 +42,7 @@ import javax.swing.event.DocumentListener; import sig.ColorPanel; import sig.sigIRC; import sig.modules.ControllerModule; +import sig.utils.TextUtils; public class ControlConfigurationWindow extends JFrame implements WindowListener{ DialogType dialog; @@ -59,6 +61,8 @@ public class ControlConfigurationWindow extends JFrame implements WindowListener int axis_width=32,axis_height=32; JButton backgroundColor,indicatorColor; boolean x_invert,y_invert,axis_invert; + public static Color lastpicked_back_col = Color.BLACK; + public static Color lastpicked_indicator_col = Color.WHITE; 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; @@ -119,8 +123,9 @@ public class ControlConfigurationWindow extends JFrame implements WindowListener ActionListener backgroundColorListener = new ActionListener(){ @Override public void actionPerformed(ActionEvent e) { - Color selectedcol = sigIRC.colorpanel.getBackgroundColor(null); + Color selectedcol = sigIRC.colorpanel.getBackgroundColor(lastpicked_back_col); if (selectedcol!=null) { + lastpicked_back_col = selectedcol; axis_background_col = selectedcol; backgroundColor.setBackground(axis_background_col); } @@ -129,8 +134,9 @@ public class ControlConfigurationWindow extends JFrame implements WindowListener ActionListener indicatorColorListener = new ActionListener(){ @Override public void actionPerformed(ActionEvent e) { - Color selectedcol = sigIRC.colorpanel.getBackgroundColor(null); + Color selectedcol = sigIRC.colorpanel.getBackgroundColor(lastpicked_indicator_col); if (selectedcol!=null) { + lastpicked_indicator_col = selectedcol; axis_indicator_col = selectedcol; indicatorColor.setBackground(axis_indicator_col); } @@ -145,7 +151,8 @@ public class ControlConfigurationWindow extends JFrame implements WindowListener ActionListener createbuttonListener = new ActionListener(){ @Override public void actionPerformed(ActionEvent ev) { - if (DataIsValid()) { + DataValidationReason err_check = DataIsValid(); + if (err_check == DataValidationReason.GOOD) { Axis a = ConstructTemporaryAxis(); module.setTemporaryAxis(a); module.setMode(EditMode.DRAGAXISSELECTION); @@ -153,11 +160,41 @@ public class ControlConfigurationWindow extends JFrame implements WindowListener module.getConfigurationWindow().dispatchEvent(new WindowEvent(module.getConfigurationWindow(),WindowEvent.WINDOW_CLOSING)); //module.getConfigurationWindow().setVisible(false); //module.getConfigurationWindow().dispose(); + } else { + DisplayError(err_check); + } + } + + private void DisplayError(DataValidationReason err_check) { + switch (err_check) { + case AXIS_MISSING: + JOptionPane.showMessageDialog(module.getConfigurationWindow(), "You did not select the correct number of axes to make this axis control!", "Error", JOptionPane.WARNING_MESSAGE); + break; + case INVALID_RANGE_SIZE: + JOptionPane.showMessageDialog(module.getConfigurationWindow(), "You did not specify valid range numbers for your axis. (Usually it's between -1.0 and 1.0. Make sure the box is not red.)", "Error", JOptionPane.WARNING_MESSAGE); + break; } } - private boolean DataIsValid() { - return true; + private DataValidationReason DataIsValid() { + if ((!TextUtils.isNumeric(twowayAxis_range1.getTextField().getText()) || + !TextUtils.isNumeric(twowayAxis_range2.getTextField().getText())) && + two_axis_button.isSelected()) { + return DataValidationReason.INVALID_RANGE_SIZE; + } else + { + int numb_checked = 0; + int requirement = (two_axis_button.isSelected())?1:2; + for (JCheckBox cb : analog_controller_component_labels) { + if (cb.isSelected()) { + numb_checked++; + } + } + if (numb_checked!=requirement) { + return DataValidationReason.AXIS_MISSING; + } + } + return DataValidationReason.GOOD; } }; ActionListener invertListener = new ActionListener(){ @@ -176,6 +213,7 @@ public class ControlConfigurationWindow extends JFrame implements WindowListener switch (ev.getActionCommand()) { case "add_button":{ module.setMode(EditMode.DRAGSELECTION); + //System.out.println("Called Drag Selection mode."); sigIRC.panel.grabFocus(); module.getConfigurationWindow().dispatchEvent(new WindowEvent(module.getConfigurationWindow(),WindowEvent.WINDOW_CLOSING)); }break; @@ -554,8 +592,8 @@ public class ControlConfigurationWindow extends JFrame implements WindowListener a = new Axis(new Rectangle2D.Double(), module.getControllers().get(0), ident, - Double.parseDouble(twowayAxis_range1.getTextField().getText()), - Double.parseDouble(twowayAxis_range2.getTextField().getText()), + Double.parseDouble((!TextUtils.isNumeric(twowayAxis_range1.getTextField().getText())?Double.toString(-1):twowayAxis_range1.getTextField().getText())), + Double.parseDouble((!TextUtils.isNumeric(twowayAxis_range2.getTextField().getText())?Double.toString(1):twowayAxis_range2.getTextField().getText())), orientation, axis_background_col, axis_indicator_col, diff --git a/src/sig/modules/Controller/DataValidationReason.java b/src/sig/modules/Controller/DataValidationReason.java new file mode 100644 index 0000000..567c8b5 --- /dev/null +++ b/src/sig/modules/Controller/DataValidationReason.java @@ -0,0 +1,7 @@ +package sig.modules.Controller; + +public enum DataValidationReason { + GOOD, + INVALID_RANGE_SIZE, + AXIS_MISSING; +} diff --git a/src/sig/modules/Controller/Element.java b/src/sig/modules/Controller/Element.java index a25e728..9e8a696 100644 --- a/src/sig/modules/Controller/Element.java +++ b/src/sig/modules/Controller/Element.java @@ -5,6 +5,7 @@ import java.awt.Image; import java.awt.geom.Rectangle2D; import sig.sigIRC; +import sig.modules.ControllerModule; public class Element { protected double pct_x = 0; @@ -37,4 +38,14 @@ public class Element { } return null; } + public void remove(ControllerModule module) { + if (this instanceof Button) { + module.getButtons().remove(this); + module.SaveButtonData(); + } else + if (this instanceof Axis) { + module.getAxes().remove(this); + module.SaveAxisData(); + } + } } diff --git a/src/sig/modules/Controller/RepeatedKey.java b/src/sig/modules/Controller/RepeatedKey.java new file mode 100644 index 0000000..63c7b23 --- /dev/null +++ b/src/sig/modules/Controller/RepeatedKey.java @@ -0,0 +1,79 @@ +package sig.modules.Controller; + +import sig.modules.ControllerModule; +import sig.utils.FileUtils; + +public class RepeatedKey { + int keycode; + boolean isKeyPressed; + Thread schedulerThread; + Runnable action; + Element element; + ControllerModule module; + boolean held_down=false,repeat=false; + final static int HOLD_DELAY=500; + final static int REPEAT_DELAY=100; + + public RepeatedKey(int keycode, ControllerModule module, + Runnable action) { + this.keycode=keycode; + this.module=module; + this.action=action; + } + + public int getKeyCode() { + return keycode; + } + + public boolean isKeyPressed() { + return this.isKeyPressed; + } + + public void setHeldStatus(boolean heldDown) { + this.held_down=heldDown; + } + + public void setRepeatStatus(boolean repeat) { + this.repeat = repeat; + } + + public void setKeyPressed(boolean isPressed) { + this.isKeyPressed=isPressed; + if (!held_down) { + held_down=true; + schedulerThread = new Thread() { + public void run() { + try { + Thread.sleep(HOLD_DELAY); + if (!isKeyPressed()) { + setHeldStatus(false); + } else { + setRepeatStatus(true); + } + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + }; + } else { + if (repeat) { + schedulerThread = new Thread() { + public void run() { + try { + while (repeat) { + action.run(); + Thread.sleep(REPEAT_DELAY); + if (!isKeyPressed()) { + repeat=false; + held_down=false; + } + } + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + }; + } + } + } +} \ No newline at end of file diff --git a/src/sig/modules/ControllerModule.java b/src/sig/modules/ControllerModule.java index cb60349..d5b61f4 100644 --- a/src/sig/modules/ControllerModule.java +++ b/src/sig/modules/ControllerModule.java @@ -6,6 +6,7 @@ import java.awt.Graphics; import java.awt.Image; import java.awt.Point; import java.awt.Rectangle; +import java.awt.event.KeyEvent; import java.awt.event.MouseEvent; import java.awt.event.WindowEvent; import java.awt.geom.Rectangle2D; @@ -15,6 +16,7 @@ import java.util.ArrayList; import java.util.List; import javax.imageio.ImageIO; +import javax.swing.JOptionPane; import org.lwjgl.glfw.GLFW; @@ -29,6 +31,7 @@ import sig.modules.Controller.Controller; import sig.modules.Controller.EditMode; import sig.modules.Controller.Element; import sig.modules.Controller.Identifier; +import sig.modules.Controller.RepeatedKey; import sig.modules.Controller.Type; import sig.modules.Controller.clickablebutton.AddClickableButton; import sig.modules.Controller.clickablebutton.CopyClickableButton; @@ -38,7 +41,7 @@ import sig.utils.FileUtils; public class ControllerModule extends Module{ public final static String CONTROLLERPATH = sigIRC.BASEDIR+"sigIRC/controller/"; List controllers = new ArrayList(); - Image controller_img; + Image controller_img,controller_overlay_img; double imgratio = 1; List