Implemented button detection / presses and scaling controller image
template. Setup framework for configuration window.
This commit is contained in:
parent
42ab9d857f
commit
42673882c9
BIN
sigIRCv2.jar
BIN
sigIRCv2.jar
Binary file not shown.
@ -44,9 +44,11 @@ public class BackgroundColorButton {
|
|||||||
if (ev.getX()>=x && ev.getX()<=x+buttonimg.getWidth() &&
|
if (ev.getX()>=x && ev.getX()<=x+buttonimg.getWidth() &&
|
||||||
ev.getY()>=y && ev.getY()<=y+buttonimg.getHeight()) {
|
ev.getY()>=y && ev.getY()<=y+buttonimg.getHeight()) {
|
||||||
sigIRC.backgroundcol=sigIRC.colorpanel.getBackgroundColor();
|
sigIRC.backgroundcol=sigIRC.colorpanel.getBackgroundColor();
|
||||||
sigIRC.config.setProperty("backgroundColor", Integer.toString(sigIRC.backgroundcol.getRGB()));
|
if (sigIRC.backgroundcol!=null) {
|
||||||
sigIRC.config.saveProperties();
|
sigIRC.config.setProperty("backgroundColor", Integer.toString(sigIRC.backgroundcol.getRGB()));
|
||||||
sigIRC.panel.setBackground(sigIRC.backgroundcol);
|
sigIRC.config.saveProperties();
|
||||||
|
sigIRC.panel.setBackground(sigIRC.backgroundcol);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ public class ColorPanel extends JPanel{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Color getBackgroundColor() {
|
public Color getBackgroundColor() {
|
||||||
return JColorChooser.showDialog(this, "Background Color Picker", Color.CYAN);
|
return JColorChooser.showDialog(this, "Background Color Picker", sigIRC.backgroundcol);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Dimension getPreferredSize() {
|
public Dimension getPreferredSize() {
|
||||||
|
@ -39,8 +39,8 @@ public class MyPanel extends JPanel implements MouseListener, ActionListener, Mo
|
|||||||
final public static Font programFont = new Font(sigIRC.messageFont,0,24);
|
final public static Font programFont = new Font(sigIRC.messageFont,0,24);
|
||||||
final public static Font userFont = new Font(sigIRC.usernameFont,0,16);
|
final public static Font userFont = new Font(sigIRC.usernameFont,0,16);
|
||||||
final public static Font smallFont = new Font(sigIRC.touhoumotherConsoleFont,0,12);
|
final public static Font smallFont = new Font(sigIRC.touhoumotherConsoleFont,0,12);
|
||||||
int lastMouseX = 0;
|
public int lastMouseX = 0;
|
||||||
int lastMouseY = 0;
|
public int lastMouseY = 0;
|
||||||
|
|
||||||
public MyPanel() {
|
public MyPanel() {
|
||||||
//setBorder(BorderFactory.createLineBorder(Color.black));
|
//setBorder(BorderFactory.createLineBorder(Color.black));
|
||||||
|
@ -2,9 +2,12 @@ package sig.modules.Controller;
|
|||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
|
import java.awt.geom.Rectangle2D;
|
||||||
|
|
||||||
import net.java.games.input.Component.Identifier;
|
import net.java.games.input.Component.Identifier;
|
||||||
|
import net.java.games.input.Component;
|
||||||
import net.java.games.input.Controller;
|
import net.java.games.input.Controller;
|
||||||
|
import sig.sigIRC;
|
||||||
import sig.modules.ControllerModule;
|
import sig.modules.ControllerModule;
|
||||||
|
|
||||||
public class Button {
|
public class Button {
|
||||||
@ -18,11 +21,19 @@ public class Button {
|
|||||||
ControllerModule parent;
|
ControllerModule parent;
|
||||||
boolean square;
|
boolean square;
|
||||||
|
|
||||||
public Button(double pct_x, double pct_width, double pct_y, double pct_height, Controller parent_controller, Identifier button_identifier, Color col, ControllerModule module) {
|
public Button(Rectangle2D.Double rect, Controller parent_controller, Identifier button_identifier, Color col, ControllerModule module) {
|
||||||
this(pct_x,pct_width,pct_y,pct_height,parent_controller,button_identifier,col,module,false);
|
this(rect.getX(),rect.getY(),rect.getWidth(),rect.getHeight(),parent_controller,button_identifier,col,module,false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Button(double pct_x, double pct_width, double pct_y, double pct_height, Controller parent_controller, Identifier button_identifier, Color col, ControllerModule module, boolean square) {
|
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(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, Color col, ControllerModule module, boolean square) {
|
||||||
this.pct_x = pct_x;
|
this.pct_x = pct_x;
|
||||||
this.pct_y = pct_y;
|
this.pct_y = pct_y;
|
||||||
this.pct_width=pct_width;
|
this.pct_width=pct_width;
|
||||||
@ -39,12 +50,56 @@ public class Button {
|
|||||||
Color col_identity = g.getColor();
|
Color col_identity = g.getColor();
|
||||||
g.setColor(pressed_col);
|
g.setColor(pressed_col);
|
||||||
g.fillOval((int)(parent.getPosition().getX()
|
g.fillOval((int)(parent.getPosition().getX()
|
||||||
+parent.getPosition().getWidth()*pct_x)
|
+parent.getControllerImage().getWidth(sigIRC.panel)*pct_x)
|
||||||
,(int)(parent.getPosition().getY()
|
,(int)(parent.getPosition().getY()
|
||||||
+parent.getPosition().getWidth()*pct_y)
|
+parent.getControllerImage().getHeight(sigIRC.panel)*pct_y)
|
||||||
,(int)(parent.getPosition().getWidth()*pct_width),
|
,(int)(parent.getControllerImage().getWidth(sigIRC.panel)*pct_width),
|
||||||
(int)(parent.getPosition().getWidth()*pct_height));
|
(int)(parent.getControllerImage().getHeight(sigIRC.panel)*pct_height));
|
||||||
g.setColor(col_identity);
|
g.setColor(col_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(ident.getName());sb.append(",");
|
||||||
|
sb.append(pressed_col.getRed());sb.append(",");
|
||||||
|
sb.append(pressed_col.getGreen());sb.append(",");
|
||||||
|
sb.append(pressed_col.getBlue());sb.append(",");
|
||||||
|
sb.append(pressed_col.getAlpha());sb.append(",");
|
||||||
|
sb.append(square);
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Button loadFromString(String s, Controller controller, ControllerModule module) {
|
||||||
|
String[] split = s.split(",");
|
||||||
|
return new Button(
|
||||||
|
Double.parseDouble(split[0]),
|
||||||
|
Double.parseDouble(split[1]),
|
||||||
|
Double.parseDouble(split[2]),
|
||||||
|
Double.parseDouble(split[3]),
|
||||||
|
controller,
|
||||||
|
GrabIdentifierFromString(split[4],controller),
|
||||||
|
new Color(
|
||||||
|
Integer.parseInt(split[5]),
|
||||||
|
Integer.parseInt(split[6]),
|
||||||
|
Integer.parseInt(split[7]),
|
||||||
|
Integer.parseInt(split[8])
|
||||||
|
),
|
||||||
|
module,
|
||||||
|
Boolean.parseBoolean(split[9]));
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,9 +11,9 @@ import sig.utils.DrawUtils;
|
|||||||
import sig.utils.TextUtils;
|
import sig.utils.TextUtils;
|
||||||
|
|
||||||
public class ClickableButton {
|
public class ClickableButton {
|
||||||
int x,y,width,height;
|
protected int x,y,width,height;
|
||||||
String label;
|
protected String label;
|
||||||
ControllerModule module;
|
protected ControllerModule module;
|
||||||
|
|
||||||
public ClickableButton(Rectangle position, String button_label, ControllerModule parent_module) {
|
public ClickableButton(Rectangle position, String button_label, ControllerModule parent_module) {
|
||||||
this.x = (int)position.getX();
|
this.x = (int)position.getX();
|
||||||
@ -25,14 +25,14 @@ public class ClickableButton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void onClickEvent(MouseEvent ev) {
|
public void onClickEvent(MouseEvent ev) {
|
||||||
if (mouseInsideBounds(ev)) {
|
/*if (mouseInsideBounds(ev)) {
|
||||||
System.out.println("Click performed!");
|
//System.out.println("Click performed!");
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean mouseInsideBounds(MouseEvent ev) {
|
protected boolean mouseInsideBounds(MouseEvent ev) {
|
||||||
return ev.getX()>=x && ev.getX()<=x+width &&
|
return ev.getX()>=module.getPosition().getX()+x && ev.getX()<=module.getPosition().getX()+x+width &&
|
||||||
ev.getY()>=y && ev.getY()<=y+height;
|
ev.getY()>=module.getPosition().getY()+y && ev.getY()<=module.getPosition().getY()+y+height;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void draw(Graphics g) {
|
public void draw(Graphics g) {
|
||||||
|
10
src/sig/modules/Controller/ControlConfigurationWindow.java
Normal file
10
src/sig/modules/Controller/ControlConfigurationWindow.java
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
package sig.modules.Controller;
|
||||||
|
|
||||||
|
import javax.swing.JFrame;
|
||||||
|
|
||||||
|
public class ControlConfigurationWindow extends JFrame{
|
||||||
|
|
||||||
|
public ControlConfigurationWindow() {
|
||||||
|
this.setVisible(true);
|
||||||
|
}
|
||||||
|
}
|
10
src/sig/modules/Controller/EditMode.java
Normal file
10
src/sig/modules/Controller/EditMode.java
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
package sig.modules.Controller;
|
||||||
|
|
||||||
|
public enum EditMode {
|
||||||
|
DRAGSELECTION, //Drag to set size of button.
|
||||||
|
SELECTION, //Selects a button for editing
|
||||||
|
DELETESELECTION, //Delete a button.
|
||||||
|
BUTTONSET, //Asks for a controller button to set this button to.
|
||||||
|
COLORSET,
|
||||||
|
DEFAULT;
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
package sig.modules.Controller.clickablebutton;
|
||||||
|
|
||||||
|
import java.awt.Rectangle;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
|
||||||
|
import sig.modules.ControllerModule;
|
||||||
|
import sig.modules.Controller.ClickableButton;
|
||||||
|
import sig.modules.Controller.EditMode;
|
||||||
|
|
||||||
|
public class AddClickableButton extends ClickableButton{
|
||||||
|
|
||||||
|
public AddClickableButton(Rectangle position, String button_label, ControllerModule parent_module) {
|
||||||
|
super(position, button_label, parent_module);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onClickEvent(MouseEvent ev) {
|
||||||
|
super.onClickEvent(ev);
|
||||||
|
if (mouseInsideBounds(ev)) {
|
||||||
|
module.setMode(EditMode.DRAGSELECTION);
|
||||||
|
module.resetDragPoints();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
package sig.modules.Controller.clickablebutton;
|
||||||
|
|
||||||
|
import java.awt.Rectangle;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
|
||||||
|
import sig.modules.ControllerModule;
|
||||||
|
import sig.modules.Controller.ClickableButton;
|
||||||
|
import sig.modules.Controller.ControlConfigurationWindow;
|
||||||
|
import sig.modules.Controller.EditMode;
|
||||||
|
|
||||||
|
public class CopyClickableButton extends ClickableButton{
|
||||||
|
ControlConfigurationWindow window;
|
||||||
|
|
||||||
|
public CopyClickableButton(Rectangle position, String button_label, ControllerModule parent_module) {
|
||||||
|
super(position, button_label, parent_module);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onClickEvent(MouseEvent ev) {
|
||||||
|
super.onClickEvent(ev);
|
||||||
|
if (mouseInsideBounds(ev)) {
|
||||||
|
window = new ControlConfigurationWindow();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,8 +1,10 @@
|
|||||||
package sig.modules;
|
package sig.modules;
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
|
import java.awt.Cursor;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.Image;
|
import java.awt.Image;
|
||||||
|
import java.awt.Point;
|
||||||
import java.awt.Rectangle;
|
import java.awt.Rectangle;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
import java.awt.geom.Rectangle2D;
|
import java.awt.geom.Rectangle2D;
|
||||||
@ -22,6 +24,9 @@ import sig.Module;
|
|||||||
import sig.sigIRC;
|
import sig.sigIRC;
|
||||||
import sig.modules.Controller.Button;
|
import sig.modules.Controller.Button;
|
||||||
import sig.modules.Controller.ClickableButton;
|
import sig.modules.Controller.ClickableButton;
|
||||||
|
import sig.modules.Controller.EditMode;
|
||||||
|
import sig.modules.Controller.clickablebutton.AddClickableButton;
|
||||||
|
import sig.modules.Controller.clickablebutton.CopyClickableButton;
|
||||||
import sig.utils.DrawUtils;
|
import sig.utils.DrawUtils;
|
||||||
import sig.utils.FileUtils;
|
import sig.utils.FileUtils;
|
||||||
|
|
||||||
@ -32,6 +37,13 @@ public class ControllerModule extends Module{
|
|||||||
double imgratio = 1;
|
double imgratio = 1;
|
||||||
List<Button> buttons = new ArrayList<Button>();
|
List<Button> buttons = new ArrayList<Button>();
|
||||||
List<ClickableButton> click_buttons = new ArrayList<ClickableButton>();
|
List<ClickableButton> click_buttons = new ArrayList<ClickableButton>();
|
||||||
|
EditMode MODE = EditMode.DEFAULT;
|
||||||
|
String status = "";
|
||||||
|
Point start_drag,end_drag;
|
||||||
|
Rectangle2D.Double stored_rect;
|
||||||
|
Identifier stored_controller_button;
|
||||||
|
Color buttoncol;
|
||||||
|
Controller controller;
|
||||||
|
|
||||||
public ControllerModule(Rectangle2D bounds, String moduleName) {
|
public ControllerModule(Rectangle2D bounds, String moduleName) {
|
||||||
super(bounds, moduleName);
|
super(bounds, moduleName);
|
||||||
@ -49,19 +61,91 @@ public class ControllerModule extends Module{
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
controller_img = ImageIO.read(new File(CONTROLLERPATH+"controller_template.png")).getScaledInstance((int)position.getWidth(), -1, 0);
|
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));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
buttons.add(new Button(0.1,0.05,0.1,0.05,controllers.get(0),Identifier.Button._3,Color.RED,this));
|
//buttons.add(new Button(0.1,0.05,0.1,0.05,controllers.get(0),Identifier.Button._3,Color.RED,this));
|
||||||
|
LoadButtonData();
|
||||||
|
click_buttons.add(new AddClickableButton(new Rectangle(
|
||||||
|
0,(int)position.getHeight()-41,96,20),"Add Button",this));
|
||||||
|
click_buttons.add(new CopyClickableButton(new Rectangle(
|
||||||
|
97,(int)position.getHeight()-41,96,20),"Copy Button",this));
|
||||||
click_buttons.add(new ClickableButton(new Rectangle(
|
click_buttons.add(new ClickableButton(new Rectangle(
|
||||||
0,0,96,20),"Test",this));
|
0,(int)position.getHeight()-20,96,20),"Delete Button",this));
|
||||||
|
click_buttons.add(new ClickableButton(new Rectangle(
|
||||||
|
97,(int)position.getHeight()-20,96,20),"Edit Button",this));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void resetDragPoints() {
|
||||||
|
this.start_drag=null;
|
||||||
|
this.end_drag=null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDragPoints(Point startpoint,Point endpoint) {
|
||||||
|
this.start_drag=startpoint;
|
||||||
|
this.end_drag=endpoint;
|
||||||
|
}
|
||||||
|
|
||||||
|
public EditMode getMode() {
|
||||||
|
return MODE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMode(EditMode mode) {
|
||||||
|
MODE = mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ApplyConfigWindowProperties() {
|
||||||
|
sigIRC.controllermodule_X=(int)position.getX();
|
||||||
|
sigIRC.controllermodule_Y=(int)position.getY();
|
||||||
|
sigIRC.config.setInteger("CONTROLLER_module_X", sigIRC.controllermodule_X);
|
||||||
|
sigIRC.config.setInteger("CONTROLLER_module_Y", sigIRC.controllermodule_Y);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void mousePressed(MouseEvent ev) {
|
public void mousePressed(MouseEvent ev) {
|
||||||
super.mousePressed(ev);
|
if (mouseInsideBounds(ev)) {
|
||||||
for (ClickableButton cb : click_buttons) {
|
switch (MODE) {
|
||||||
cb.onClickEvent(ev);
|
case DRAGSELECTION:{
|
||||||
|
if (start_drag==null) {
|
||||||
|
start_drag = new Point((int)(ev.getX()-getPosition().getX()),(int)(ev.getY()-getPosition().getY()));
|
||||||
|
}
|
||||||
|
}break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
super.mousePressed(ev);
|
||||||
|
if (MODE==EditMode.DEFAULT) {
|
||||||
|
for (ClickableButton cb : click_buttons) {
|
||||||
|
cb.onClickEvent(ev);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void mouseReleased(MouseEvent ev) {
|
||||||
|
super.mouseReleased(ev);
|
||||||
|
if (mouseInsideBounds(ev)) {
|
||||||
|
switch (MODE) {
|
||||||
|
case DRAGSELECTION:{
|
||||||
|
if (start_drag!=null) {
|
||||||
|
end_drag = new Point((int)(ev.getX()-getPosition().getX()),(int)(ev.getY()-getPosition().getY()));
|
||||||
|
double width = (end_drag.getX()-start_drag.getX())/controller_img.getWidth(sigIRC.panel);
|
||||||
|
double height = (end_drag.getY()-start_drag.getY())/controller_img.getHeight(sigIRC.panel);
|
||||||
|
stored_rect = new Rectangle2D.Double(
|
||||||
|
(width<0)?end_drag.getX()/controller_img.getWidth(sigIRC.panel):start_drag.getX()/controller_img.getWidth(sigIRC.panel),
|
||||||
|
(height<0)?end_drag.getY()/controller_img.getHeight(sigIRC.panel):start_drag.getY()/controller_img.getHeight(sigIRC.panel),
|
||||||
|
Math.abs((end_drag.getX()-start_drag.getX())/controller_img.getWidth(sigIRC.panel)),
|
||||||
|
Math.abs((end_drag.getY()-start_drag.getY())/controller_img.getHeight(sigIRC.panel)));
|
||||||
|
//buttons.add(new Button(pct_rect.getX(),pct_rect.getY(),pct_rect.getWidth(),pct_rect.getHeight(),controllers.get(0),Identifier.Button._3,Color.RED,this));
|
||||||
|
//resetDragPoints();
|
||||||
|
MODE=EditMode.BUTTONSET;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean mouseInsideBounds(MouseEvent ev) {
|
||||||
|
return ev.getX()>=getPosition().getX() && ev.getX()<=getPosition().getX()+getPosition().getWidth() &&
|
||||||
|
ev.getY()>=getPosition().getY() && ev.getY()<=getPosition().getY()+getPosition().getHeight();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Rectangle2D getPosition() {
|
public Rectangle2D getPosition() {
|
||||||
@ -69,7 +153,6 @@ public class ControllerModule extends Module{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
super.run();
|
|
||||||
for (Controller c : controllers) {
|
for (Controller c : controllers) {
|
||||||
//System.out.println("Data for "+c.getName()+" ("+c.getType()+"):");
|
//System.out.println("Data for "+c.getName()+" ("+c.getType()+"):");
|
||||||
c.poll();
|
c.poll();
|
||||||
@ -82,6 +165,53 @@ public class ControllerModule extends Module{
|
|||||||
}
|
}
|
||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
|
switch (MODE) {
|
||||||
|
case DRAGSELECTION:{
|
||||||
|
int cursortype = sigIRC.panel.getCursor().getType();
|
||||||
|
if (cursortype!=Cursor.CROSSHAIR_CURSOR) {
|
||||||
|
sigIRC.panel.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
|
||||||
|
}
|
||||||
|
status="Drag a button onto the controller template.";
|
||||||
|
}break;
|
||||||
|
case BUTTONSET:{
|
||||||
|
sigIRC.panel.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
|
||||||
|
status="Press controller button to set button";
|
||||||
|
}break;
|
||||||
|
case COLORSET:{
|
||||||
|
status="Select a color from the panel.";
|
||||||
|
}break;
|
||||||
|
default:{
|
||||||
|
status="";
|
||||||
|
int cursortype = sigIRC.panel.getCursor().getType();
|
||||||
|
if (cursortype!=Cursor.DEFAULT_CURSOR) {
|
||||||
|
sigIRC.panel.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
super.run();
|
||||||
|
if (MODE==EditMode.BUTTONSET) {
|
||||||
|
stored_controller_button=null;
|
||||||
|
for (Controller c : controllers) {
|
||||||
|
for (Component cp : c.getComponents()) {
|
||||||
|
if (!cp.isAnalog() && cp.getPollData()==1.0f) {
|
||||||
|
stored_controller_button = cp.getIdentifier();
|
||||||
|
controller=c;
|
||||||
|
MODE=EditMode.COLORSET;
|
||||||
|
buttoncol = PopupColorPanel();
|
||||||
|
AddButton();
|
||||||
|
MODE=EditMode.DEFAULT;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (stored_controller_button!=null) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Image getControllerImage() {
|
||||||
|
return controller_img;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void draw(Graphics g) {
|
public void draw(Graphics g) {
|
||||||
@ -95,12 +225,56 @@ public class ControllerModule extends Module{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
g.drawImage(controller_img, (int)(position.getX()+1), (int)(position.getY()+8), sigIRC.panel);
|
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) {
|
for (Button b : buttons) {
|
||||||
b.draw(g);
|
b.draw(g);
|
||||||
}
|
}
|
||||||
for (ClickableButton cb : click_buttons) {
|
for (ClickableButton cb : click_buttons) {
|
||||||
cb.draw(g);
|
cb.draw(g);
|
||||||
}
|
}
|
||||||
|
if (MODE==EditMode.DRAGSELECTION) {
|
||||||
|
if (start_drag!=null) {
|
||||||
|
Color color_identity = g.getColor();
|
||||||
|
g.setColor(Color.GRAY);
|
||||||
|
int width = sigIRC.panel.lastMouseX-
|
||||||
|
((int)position.getX()+(int)start_drag.getX());
|
||||||
|
int height = sigIRC.panel.lastMouseY-
|
||||||
|
((int)position.getY()+(int)start_drag.getY());
|
||||||
|
g.fillOval(
|
||||||
|
(width<0)?sigIRC.panel.lastMouseX:(int)position.getX()+(int)start_drag.getX(),
|
||||||
|
(height<0)?sigIRC.panel.lastMouseY:(int)position.getY()+(int)start_drag.getY(),
|
||||||
|
Math.abs(width), Math.abs(height));
|
||||||
|
g.setColor(color_identity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LoadButtonData() {
|
||||||
|
String[] buttondata = FileUtils.readFromFile(CONTROLLERPATH+"button_data.txt");
|
||||||
|
if (controllers.size()>0) {
|
||||||
|
for (String s : buttondata) {
|
||||||
|
if (s.length()>0) {
|
||||||
|
buttons.add(Button.loadFromString(s, controllers.get(0), this));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void AddButton() {
|
||||||
|
buttons.add(new Button(stored_rect,controller,stored_controller_button,buttoncol,this));
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
for (Button b : buttons) {
|
||||||
|
sb.append(b.getSaveString()+"\n");
|
||||||
|
}
|
||||||
|
FileUtils.writetoFile(new String[]{sb.toString()}, CONTROLLERPATH+"button_data.txt");
|
||||||
|
}
|
||||||
|
|
||||||
|
private Color PopupColorPanel() {
|
||||||
|
Color col=null;
|
||||||
|
do {
|
||||||
|
col=sigIRC.colorpanel.getBackgroundColor();
|
||||||
|
} while (col==null);
|
||||||
|
return col;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -43,16 +43,20 @@ public class DrawUtils {
|
|||||||
g2.drawString(as.getIterator(),(int)x,(int)y);
|
g2.drawString(as.getIterator(),(int)x,(int)y);
|
||||||
}
|
}
|
||||||
public static void drawText(Graphics g, double x, double y, Color color, String message) {
|
public static void drawText(Graphics g, double x, double y, Color color, String message) {
|
||||||
AttributedString as = new AttributedString(message);
|
if (message.length()>0) {
|
||||||
as.addAttribute(TextAttribute.FONT, MyPanel.programFont);
|
AttributedString as = new AttributedString(message);
|
||||||
g.setColor(color);
|
as.addAttribute(TextAttribute.FONT, MyPanel.programFont);
|
||||||
g.drawString(as.getIterator(),(int)x,(int)y);
|
g.setColor(color);
|
||||||
|
g.drawString(as.getIterator(),(int)x,(int)y);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public static void drawTextFont(Graphics g, Font font, double x, double y, Color color, String message) {
|
public static void drawTextFont(Graphics g, Font font, double x, double y, Color color, String message) {
|
||||||
AttributedString as = new AttributedString(message);
|
if (message.length()>0) {
|
||||||
as.addAttribute(TextAttribute.FONT, font);
|
AttributedString as = new AttributedString(message);
|
||||||
g.setColor(color);
|
as.addAttribute(TextAttribute.FONT, font);
|
||||||
g.drawString(as.getIterator(),(int)x,(int)y);
|
g.setColor(color);
|
||||||
|
g.drawString(as.getIterator(),(int)x,(int)y);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public static void drawHealthbar(Graphics g, Rectangle bounds, double pct, Color healthbarcol) {
|
public static void drawHealthbar(Graphics g, Rectangle bounds, double pct, Color healthbarcol) {
|
||||||
g.setColor(Color.BLACK);
|
g.setColor(Color.BLACK);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user