Implemented basic Axis Configuration Dialog box. Added Hat Switch (POV)
button compatibility.
This commit is contained in:
parent
42673882c9
commit
70e91c46a2
BIN
sigIRCv2.jar
BIN
sigIRCv2.jar
Binary file not shown.
@ -16,24 +16,25 @@ public class Button {
|
||||
double pct_width = 0;
|
||||
double pct_height = 0;
|
||||
Identifier ident;
|
||||
float value;
|
||||
Controller parent_controller;
|
||||
Color pressed_col;
|
||||
ControllerModule parent;
|
||||
boolean square;
|
||||
|
||||
public Button(Rectangle2D.Double rect, Controller parent_controller, Identifier button_identifier, Color col, ControllerModule module) {
|
||||
this(rect.getX(),rect.getY(),rect.getWidth(),rect.getHeight(),parent_controller,button_identifier,col,module,false);
|
||||
public Button(Rectangle2D.Double rect, Controller parent_controller, Identifier button_identifier, float 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, Color col, ControllerModule module, boolean square) {
|
||||
this(rect.getX(),rect.getY(),rect.getWidth(),rect.getHeight(),parent_controller,button_identifier,col,module,square);
|
||||
public Button(Rectangle2D.Double rect, Controller parent_controller, Identifier button_identifier, float 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, Color col, ControllerModule module) {
|
||||
this(pct_x,pct_y,pct_width,pct_height,parent_controller,button_identifier,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) {
|
||||
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, Color col, ControllerModule module, boolean 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, boolean square) {
|
||||
this.pct_x = pct_x;
|
||||
this.pct_y = pct_y;
|
||||
this.pct_width=pct_width;
|
||||
@ -43,10 +44,11 @@ public class Button {
|
||||
this.pressed_col=col;
|
||||
this.parent = module;
|
||||
this.square = square;
|
||||
this.value = button_val;
|
||||
}
|
||||
|
||||
public void draw(Graphics g) {
|
||||
if (parent_controller.getComponent(ident).getPollData()==1) {
|
||||
if (parent_controller.getComponent(ident).getPollData()==value) {
|
||||
Color col_identity = g.getColor();
|
||||
g.setColor(pressed_col);
|
||||
g.fillOval((int)(parent.getPosition().getX()
|
||||
@ -66,6 +68,7 @@ public class Button {
|
||||
sb.append(pct_width);sb.append(",");
|
||||
sb.append(pct_height);sb.append(",");
|
||||
sb.append(ident.getName());sb.append(",");
|
||||
sb.append(value);sb.append(",");
|
||||
sb.append(pressed_col.getRed());sb.append(",");
|
||||
sb.append(pressed_col.getGreen());sb.append(",");
|
||||
sb.append(pressed_col.getBlue());sb.append(",");
|
||||
@ -76,21 +79,23 @@ public class Button {
|
||||
|
||||
public static Button loadFromString(String s, Controller controller, ControllerModule module) {
|
||||
String[] split = s.split(",");
|
||||
int i=0;
|
||||
return new Button(
|
||||
Double.parseDouble(split[0]),
|
||||
Double.parseDouble(split[1]),
|
||||
Double.parseDouble(split[2]),
|
||||
Double.parseDouble(split[3]),
|
||||
Double.parseDouble(split[i++]),
|
||||
Double.parseDouble(split[i++]),
|
||||
Double.parseDouble(split[i++]),
|
||||
Double.parseDouble(split[i++]),
|
||||
controller,
|
||||
GrabIdentifierFromString(split[4],controller),
|
||||
GrabIdentifierFromString(split[i++],controller),
|
||||
Float.parseFloat(split[i++]),
|
||||
new Color(
|
||||
Integer.parseInt(split[5]),
|
||||
Integer.parseInt(split[6]),
|
||||
Integer.parseInt(split[7]),
|
||||
Integer.parseInt(split[8])
|
||||
Integer.parseInt(split[i++]),
|
||||
Integer.parseInt(split[i++]),
|
||||
Integer.parseInt(split[i++]),
|
||||
Integer.parseInt(split[i++])
|
||||
),
|
||||
module,
|
||||
Boolean.parseBoolean(split[9]));
|
||||
Boolean.parseBoolean(split[i++]));
|
||||
}
|
||||
|
||||
private static Identifier GrabIdentifierFromString(String string, Controller controller) {
|
||||
|
@ -1,10 +1,282 @@
|
||||
package sig.modules.Controller;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Checkbox;
|
||||
import java.awt.Color;
|
||||
import java.awt.Container;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.awt.event.WindowListener;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ControlConfigurationWindow extends JFrame{
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.Box;
|
||||
import javax.swing.BoxLayout;
|
||||
import javax.swing.ButtonGroup;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JLayeredPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JRadioButton;
|
||||
|
||||
import net.java.games.input.Component;
|
||||
import net.java.games.input.Controller;
|
||||
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<JCheckBox> analog_controller_component_labels = new ArrayList<JCheckBox>();
|
||||
ControllerModule module;
|
||||
DecimalFormat df = new DecimalFormat("0.000");
|
||||
PreviewPanel previewpanel;
|
||||
ActionListener checkboxListener = new ActionListener(){
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent ev) {
|
||||
int checkedamt=0;
|
||||
for (JCheckBox cb : analog_controller_component_labels) {
|
||||
checkedamt+=(cb.isSelected())?1:0;
|
||||
}
|
||||
if (previewpanel.twoAxis && checkedamt>1) {
|
||||
UncheckPreviouslyCheckedbox(ev);
|
||||
} else
|
||||
if (!previewpanel.twoAxis && checkedamt>2) {
|
||||
UncheckPreviouslyCheckedbox(ev);
|
||||
}
|
||||
}
|
||||
|
||||
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())) {
|
||||
analog_controller_component_labels.get(i).setSelected(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
ActionListener axisListener = new ActionListener(){
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent ev) {
|
||||
switch (ev.getActionCommand()) {
|
||||
case "four":{
|
||||
previewpanel.setAxis(false);
|
||||
}break;
|
||||
case "two":{
|
||||
previewpanel.setAxis(true);
|
||||
boolean firstBox=false;
|
||||
for (int i=0;i<analog_controller_components.size();i++) {
|
||||
if (analog_controller_component_labels.get(i).isSelected()) {
|
||||
if (!firstBox) {
|
||||
firstBox=true;
|
||||
} else {
|
||||
analog_controller_component_labels.get(i).setSelected(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public ControlConfigurationWindow() {
|
||||
public ControlConfigurationWindow(DialogType type, ControllerModule parent_module) {
|
||||
this.setVisible(true);
|
||||
this.module = parent_module;
|
||||
this.module.setConfigureWindow(this);
|
||||
this.dialog = type;
|
||||
switch (dialog) {
|
||||
case AXIS_OPTIONS:
|
||||
|
||||
break;
|
||||
case BUTTON_AXIS_SELECTION:
|
||||
JPanel container = new JPanel();
|
||||
JPanel axisPanel = new JPanel();
|
||||
ButtonGroup axisSelection = new ButtonGroup();
|
||||
axisPanel.setLayout(new BoxLayout(axisPanel,BoxLayout.LINE_AXIS));
|
||||
JPanel selectionFrame = new JPanel();
|
||||
selectionFrame.setLayout(new BoxLayout(selectionFrame,BoxLayout.LINE_AXIS));
|
||||
JPanel selectionPanel1 = new JPanel(){
|
||||
public void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
try {
|
||||
g.drawImage(ImageIO.read(new File(ControllerModule.CONTROLLERPATH+"4-way_axis.png")), 0, 0, this);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
};
|
||||
JPanel selectionPanel2 = new JPanel(){
|
||||
public void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
try {
|
||||
g.drawImage(ImageIO.read(new File(ControllerModule.CONTROLLERPATH+"2-way_axis.png")), 0, 0, this);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
};
|
||||
//selectionPanel.setLayout(new BoxLayout(selectionPanel,BoxLayout.LINE_AXIS));
|
||||
selectionFrame.add(selectionPanel1);
|
||||
JRadioButton four_axis_button = new JRadioButton("4-way Axis",true);
|
||||
four_axis_button.setActionCommand("four");
|
||||
four_axis_button.addActionListener(axisListener);
|
||||
selectionFrame.add(selectionPanel2);
|
||||
JRadioButton two_axis_button = new JRadioButton("2-way Axis");
|
||||
two_axis_button.setActionCommand("two");
|
||||
two_axis_button.addActionListener(axisListener);
|
||||
axisSelection.add(four_axis_button);
|
||||
axisSelection.add(two_axis_button);
|
||||
selectionPanel1.add(four_axis_button);
|
||||
selectionPanel2.add(two_axis_button);
|
||||
selectionPanel1.setBackground(new Color(0,0,255,96));
|
||||
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());
|
||||
component_checkbox.addActionListener(checkboxListener);
|
||||
analog_controller_component_labels.add(component_checkbox);
|
||||
axisPanel.add(component_checkbox);
|
||||
counter=Math.floorMod(counter+1, 5);
|
||||
if (counter==0) {
|
||||
panels.add(axisPanel);
|
||||
axisPanel = new JPanel();
|
||||
axisPanel.setLayout(new BoxLayout(axisPanel,BoxLayout.LINE_AXIS));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (JPanel panel : panels) {
|
||||
container.add(panel);
|
||||
}
|
||||
container.add(axisPanel);
|
||||
container.add(selectionFrame);
|
||||
|
||||
JComponent previewLabelPanel = new JPanel();
|
||||
JLabel previewLabel = new JLabel("Axis Preview: ");
|
||||
previewLabel.setVerticalAlignment(JLabel.TOP);
|
||||
previewLabel.setHorizontalAlignment(JLabel.RIGHT);
|
||||
previewLabelPanel.setPreferredSize(new Dimension(120,24));
|
||||
previewpanel = new PreviewPanel();
|
||||
previewpanel.setWindow(this);
|
||||
previewpanel.setPreferredSize(new Dimension(240,32));
|
||||
//previewpanel.add(previewLabel);
|
||||
|
||||
|
||||
previewLabelPanel.add(previewLabel,BorderLayout.NORTH);
|
||||
previewLabelPanel.add(previewpanel,BorderLayout.CENTER);
|
||||
//previewLabelPanel.setBackground(Color.BLUE);
|
||||
|
||||
|
||||
container.add(previewLabelPanel);
|
||||
container.setLayout(new BoxLayout(container,BoxLayout.PAGE_AXIS));
|
||||
|
||||
this.setMinimumSize(new Dimension(640,480));
|
||||
this.add(container);
|
||||
//this.pack();
|
||||
this.repaint();
|
||||
break;
|
||||
case BUTTON_OPTIONS:
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private String GetComponentValue(Component component) {
|
||||
return component.getName()+": "+df.format(component.getPollData())+" ";
|
||||
}
|
||||
|
||||
public void run() {
|
||||
switch (dialog) {
|
||||
case AXIS_OPTIONS:
|
||||
break;
|
||||
case BUTTON_AXIS_SELECTION:
|
||||
for (int i=0;i<analog_controller_components.size();i++) {
|
||||
JCheckBox mycheckbox = analog_controller_component_labels.get(i);
|
||||
mycheckbox.setText(GetComponentValue(analog_controller_components.get(i)));
|
||||
}
|
||||
break;
|
||||
case BUTTON_OPTIONS:
|
||||
break;
|
||||
}
|
||||
if (previewpanel!=null) {
|
||||
previewpanel.repaint();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowClosing(WindowEvent ev) {
|
||||
this.module.setConfigureWindow(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowActivated(WindowEvent arg0) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowClosed(WindowEvent arg0) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowDeactivated(WindowEvent arg0) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowDeiconified(WindowEvent arg0) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowIconified(WindowEvent arg0) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowOpened(WindowEvent arg0) {
|
||||
}
|
||||
}
|
||||
|
||||
class PreviewPanel extends JPanel{
|
||||
public boolean twoAxis=false;
|
||||
ControlConfigurationWindow window;
|
||||
public void setWindow(ControlConfigurationWindow window) {
|
||||
this.window=window;
|
||||
}
|
||||
public void setAxis(boolean twoAxis) {
|
||||
this.twoAxis=twoAxis;
|
||||
}
|
||||
public void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
if (twoAxis) {
|
||||
g.fillRect(0, 0, 32, 32);
|
||||
} else {
|
||||
double xval=0;
|
||||
double yval=0;
|
||||
for (int i=0;i<window.analog_controller_component_labels.size();i++) {
|
||||
if (window.analog_controller_component_labels.get(i).isSelected() &&
|
||||
window.analog_controller_component_labels.get(i).getText().contains("X")) {
|
||||
xval=window.analog_controller_components.get(i).getPollData();
|
||||
} else
|
||||
if (window.analog_controller_component_labels.get(i).isSelected() &&
|
||||
window.analog_controller_component_labels.get(i).getText().contains("Y")) {
|
||||
yval=window.analog_controller_components.get(i).getPollData();
|
||||
}
|
||||
}
|
||||
Color color_identity = g.getColor();
|
||||
g.setColor(Color.BLACK);
|
||||
g.fillOval(0, 0, 32, 32);
|
||||
g.setColor(Color.WHITE);
|
||||
g.drawOval((int)((xval+1)*12), (int)((yval+1)*12), 8, 8);
|
||||
g.setColor(color_identity);
|
||||
}
|
||||
}
|
||||
}
|
7
src/sig/modules/Controller/DialogType.java
Normal file
7
src/sig/modules/Controller/DialogType.java
Normal file
@ -0,0 +1,7 @@
|
||||
package sig.modules.Controller;
|
||||
|
||||
public enum DialogType {
|
||||
BUTTON_AXIS_SELECTION,
|
||||
AXIS_OPTIONS,
|
||||
BUTTON_OPTIONS
|
||||
}
|
@ -6,6 +6,7 @@ import java.awt.event.MouseEvent;
|
||||
import sig.modules.ControllerModule;
|
||||
import sig.modules.Controller.ClickableButton;
|
||||
import sig.modules.Controller.ControlConfigurationWindow;
|
||||
import sig.modules.Controller.DialogType;
|
||||
import sig.modules.Controller.EditMode;
|
||||
|
||||
public class CopyClickableButton extends ClickableButton{
|
||||
@ -18,7 +19,7 @@ public class CopyClickableButton extends ClickableButton{
|
||||
public void onClickEvent(MouseEvent ev) {
|
||||
super.onClickEvent(ev);
|
||||
if (mouseInsideBounds(ev)) {
|
||||
window = new ControlConfigurationWindow();
|
||||
window = new ControlConfigurationWindow(DialogType.BUTTON_AXIS_SELECTION,module);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ import sig.Module;
|
||||
import sig.sigIRC;
|
||||
import sig.modules.Controller.Button;
|
||||
import sig.modules.Controller.ClickableButton;
|
||||
import sig.modules.Controller.ControlConfigurationWindow;
|
||||
import sig.modules.Controller.EditMode;
|
||||
import sig.modules.Controller.clickablebutton.AddClickableButton;
|
||||
import sig.modules.Controller.clickablebutton.CopyClickableButton;
|
||||
@ -42,8 +43,10 @@ public class ControllerModule extends Module{
|
||||
Point start_drag,end_drag;
|
||||
Rectangle2D.Double stored_rect;
|
||||
Identifier stored_controller_button;
|
||||
float stored_controller_value;
|
||||
Color buttoncol;
|
||||
Controller controller;
|
||||
ControlConfigurationWindow configure_window;
|
||||
|
||||
public ControllerModule(Rectangle2D bounds, String moduleName) {
|
||||
super(bounds, moduleName);
|
||||
@ -76,6 +79,10 @@ public class ControllerModule extends Module{
|
||||
click_buttons.add(new ClickableButton(new Rectangle(
|
||||
97,(int)position.getHeight()-20,96,20),"Edit Button",this));
|
||||
}
|
||||
|
||||
public List<Controller> getControllers() {
|
||||
return controllers;
|
||||
}
|
||||
|
||||
public void resetDragPoints() {
|
||||
this.start_drag=null;
|
||||
@ -151,6 +158,10 @@ public class ControllerModule extends Module{
|
||||
public Rectangle2D getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
public void setConfigureWindow(ControlConfigurationWindow window) {
|
||||
this.configure_window=window;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
for (Controller c : controllers) {
|
||||
@ -193,8 +204,9 @@ public class ControllerModule extends Module{
|
||||
stored_controller_button=null;
|
||||
for (Controller c : controllers) {
|
||||
for (Component cp : c.getComponents()) {
|
||||
if (!cp.isAnalog() && cp.getPollData()==1.0f) {
|
||||
if (!cp.isAnalog() && cp.getPollData()!=0.0f) {
|
||||
stored_controller_button = cp.getIdentifier();
|
||||
stored_controller_value = cp.getPollData();
|
||||
controller=c;
|
||||
MODE=EditMode.COLORSET;
|
||||
buttoncol = PopupColorPanel();
|
||||
@ -208,6 +220,9 @@ public class ControllerModule extends Module{
|
||||
}
|
||||
}
|
||||
}
|
||||
if (configure_window!=null) {
|
||||
configure_window.run();
|
||||
}
|
||||
}
|
||||
|
||||
public Image getControllerImage() {
|
||||
@ -218,12 +233,12 @@ public class ControllerModule extends Module{
|
||||
super.draw(g);
|
||||
for (int i=0;i<controllers.get(0).getComponents().length;i++) {
|
||||
Component cp = controllers.get(0).getComponents()[i];
|
||||
if (!cp.isAnalog()) {
|
||||
/*if (!cp.isAnalog()) {
|
||||
if (cp.getPollData()!=0) {
|
||||
//System.out.println("Button "+cp.getIdentifier()+" held down!");
|
||||
//System.out.println("Button "+cp.getIdentifier()+" held down! Value: "+cp.getPollData());
|
||||
//DrawUtils.drawText(g,position.getX(),position.getY(),Color.BLACK,"Button "+cp.getIdentifier()+" held down!");
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
g.drawImage(controller_img, (int)(position.getX()), (int)(position.getY()), sigIRC.panel);
|
||||
DrawUtils.drawText(g, position.getX(), position.getY()+8, Color.BLACK, status);
|
||||
@ -262,7 +277,7 @@ public class ControllerModule extends Module{
|
||||
}
|
||||
|
||||
private void AddButton() {
|
||||
buttons.add(new Button(stored_rect,controller,stored_controller_button,buttoncol,this));
|
||||
buttons.add(new Button(stored_rect,controller,stored_controller_button,stored_controller_value,buttoncol,this));
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (Button b : buttons) {
|
||||
sb.append(b.getSaveString()+"\n");
|
||||
|
Loading…
x
Reference in New Issue
Block a user