I'm a self-taught programmer and I haven't really followed industry-standard coding classes. I'm currently coding my own game engine for android, though and I was wondering if my coding style could run me into big troubles. Here's my newly written custom button class:
package com.glu.engine.GUI;
import android.opengl.Matrix;
import android.util.Log;
import com.glu.engine.vectors.Matrix4f;
import com.glu.engine.vectors.Vector2f;
import com.glu.engine.vectors.Vector3f;
import java.util.ArrayList;
public class Button{
//One thing to note is that I preffer setting my variables to public to get and set them.
//I ran some tests of my own and this practice is more performant than using methods.
//just custom quads to actually render the button.
public GUIBase stateDefault;
public GUIBase statePressed;
public GUIBase stateReleased;
//I'm using arraylists to make it so that I can instance the button.
public ArrayList<Boolean> isPressed = new ArrayList<>();
public ArrayList<Boolean> hasBeenPressed = new ArrayList<>();
public ArrayList<Boolean> isHovering = new ArrayList<>();
public ArrayList<Boolean> hasClickedOff = new ArrayList<>();
public ArrayList<Vector2f> position = new ArrayList<>();
public ArrayList<Vector2f> size = new ArrayList<>();
public ArrayList<String> name = new ArrayList<>();
public int pressNumber;
public int doOnClick;
public int doOnClickRelease;
public int doOnPass;
public int doOnRelease;
public static final int CANNOT_PRESS = 0; // can't press the button
public static final int PRESS_ONCE = 1; // can only press the button once
public static final int PRESS_MTONCE = 2; // can press the button more than once
public static final int STAY_ON_CLICK = 3; // doesn't change on click
public static final int CHANGE_ON_CLICK = 4; // change on click
public static final int STAY_ON_RELEASE = 3; // stay on the pressed state at release
public static final int RETURN_ON_RELEASE = 4; // return to the default state at release
public static final int CHANGE_ON_RELEASE = 5; // change to the released state at release
public static final int NTG_ON_PASS = 6; // don't react when the finger goes over the button
public static final int PREVIEW_ON_PASS = 7; // change to pressed icon when the finger goes over the button
public static final int CHANGE_ON_PASS = 8; // change to released icon when the finger goes over the button
public static final int CLICK_ON_PASS = 9; // click the button when the finger goes over the button
public static final int NTG_ON_RELEASE = 10; // don't react if the finger releases when going over the button
public static final int CLICK_ON_RELEASE = 11; // click the button if the finger releases when going over it
public ArrayList<Integer> state = new ArrayList<>();
public static final int STATE_DEFAULT = 12;
public static final int STATE_PRESSED = 13;
public static final int STATE_RELEASED = 14;
public Button(GUIBase stateDefault, GUIBase statePressed){
this.stateDefault = (stateDefault);
this.statePressed = (statePressed);
this.stateReleased = (null);
position.add(new Vector2f(0,0));
this.size.add(new Vector2f(1,1));
this.stateDefault.position.set(0,this.position.get(0));
this.stateDefault.scale.get(0).multiply(this.size.get(0));
this.stateDefault.show.set(0,true);
this.statePressed.position.set(0,this.position.get(0));
this.statePressed.scale.get(0).multiply(this.size.get(0));
this.statePressed.show.set(0,false);
isPressed.add(false);
hasBeenPressed.add(false);
isHovering.add(false);
hasClickedOff.add(false);
pressNumber = PRESS_MTONCE;
doOnClick = CHANGE_ON_CLICK;
doOnClickRelease = RETURN_ON_RELEASE;
doOnPass = NTG_ON_PASS;
doOnRelease = NTG_ON_RELEASE;
state.add(STATE_DEFAULT);
name.add("button"+(name.size()));
}
public Button(GUIBase stateDefault, GUIBase statePressed, GUIBase stateReleased){
this.stateDefault = (stateDefault);
this.statePressed = (statePressed);
this.stateReleased = (stateReleased);
position.add(new Vector2f(0,0));
this.size.add(new Vector2f(1,1));
this.stateDefault.position.set(0,this.position.get(0));
this.stateDefault.scale.get(0).multiply(this.size.get(0));
this.stateDefault.show.set(0,true);
this.statePressed.position.set(0,this.position.get(0));
this.statePressed.scale.get(0).multiply(this.size.get(0));
this.statePressed.show.set(0,false);
this.stateReleased.position.set(0,this.position.get(0));
this.stateReleased.scale.get(0).multiply(this.size.get(0));
this.stateReleased.show.set(0,false);
isPressed.add(false);
hasBeenPressed.add(false);
isHovering.add(false);
hasClickedOff.add(false);
pressNumber = PRESS_MTONCE;
doOnClick = CHANGE_ON_CLICK;
doOnClickRelease = RETURN_ON_RELEASE;
doOnPass = NTG_ON_PASS;
doOnRelease = NTG_ON_RELEASE;
state.add(STATE_DEFAULT);
name.add("button"+(name.size()));
}
public Button(GUIBase stateDefault, GUIBase statePressed, Vector2f position){
this.stateDefault = (stateDefault);
this.statePressed = (statePressed);
this.stateReleased = (null);
this.position.add(position);
this.size.add(new Vector2f(1,1));
this.stateDefault.position.set(0,this.position.get(0));
this.stateDefault.scale.get(0).multiply(this.size.get(0));
this.stateDefault.show.set(0,true);
this.statePressed.position.set(0,this.position.get(0));
this.statePressed.scale.get(0).multiply(this.size.get(0));
this.statePressed.show.set(0,false);
isPressed.add(false);
hasBeenPressed.add(false);
isHovering.add(false);
hasClickedOff.add(false);
pressNumber = PRESS_MTONCE;
doOnClick = CHANGE_ON_CLICK;
doOnClickRelease = RETURN_ON_RELEASE;
doOnPass = NTG_ON_PASS;
doOnRelease = NTG_ON_RELEASE;
state.add(STATE_DEFAULT);
name.add("button"+(name.size()));
}
public Button(GUIBase stateDefault, GUIBase statePressed, Vector2f position, Vector2f size){
this.stateDefault = (stateDefault);
this.statePressed = (statePressed);
this.stateReleased = (null);
this.position.add(position);
this.size.add(size);
this.stateDefault.position.set(0,this.position.get(0));
this.stateDefault.scale.get(0).multiply(this.size.get(0));
this.stateDefault.show.set(0,true);
this.statePressed.position.set(0,this.position.get(0));
this.statePressed.scale.get(0).multiply(this.size.get(0));
this.statePressed.show.set(0,false);
isPressed.add(false);
hasBeenPressed.add(false);
isHovering.add(false);
hasClickedOff.add(false);
pressNumber = PRESS_MTONCE;
doOnClick = CHANGE_ON_CLICK;
doOnClickRelease = RETURN_ON_RELEASE;
doOnPass = NTG_ON_PASS;
doOnRelease = NTG_ON_RELEASE;
state.add(STATE_DEFAULT);
name.add("button"+(name.size()));
}
public Button(GUIBase stateDefault, GUIBase statePressed, GUIBase stateReleased, Vector2f position){
this.stateDefault = (stateDefault);
this.statePressed = (statePressed);
this.stateReleased = (stateReleased);
this.position.add(position);
this.size.add(new Vector2f(1,1));
this.stateDefault.position.set(0,this.position.get(0));
this.stateDefault.scale.get(0).multiply(this.size.get(0));
this.stateDefault.show.set(0,true);
this.statePressed.position.set(0,this.position.get(0));
this.statePressed.scale.get(0).multiply(this.size.get(0));
this.statePressed.show.set(0,false);
this.stateReleased.position.set(0,this.position.get(0));
this.stateReleased.scale.get(0).multiply(this.size.get(0));
this.stateReleased.show.set(0,false);
isPressed.add(false);
hasBeenPressed.add(false);
isHovering.add(false);
hasClickedOff.add(false);
pressNumber = PRESS_MTONCE;
doOnClick = CHANGE_ON_CLICK;
doOnClickRelease = RETURN_ON_RELEASE;
doOnPass = NTG_ON_PASS;
doOnRelease = NTG_ON_RELEASE;
state.add(STATE_DEFAULT);
name.add("button"+(name.size()));
}
public Button(GUIBase stateDefault, GUIBase statePressed, GUIBase stateReleased, Vector2f position, Vector2f size){
this.stateDefault = (stateDefault);
this.statePressed = (statePressed);
this.stateReleased = (stateReleased);
this.position.add(position);
this.size.add(size);
this.stateDefault.position.set(0,this.position.get(0));
this.stateDefault.scale.get(0).multiply(this.size.get(0));
this.stateDefault.show.set(0,true);
this.statePressed.position.set(0,this.position.get(0));
this.statePressed.scale.get(0).multiply(this.size.get(0));
this.statePressed.show.set(0,false);
this.stateReleased.position.set(0,this.position.get(0));
this.stateReleased.scale.get(0).multiply(this.size.get(0));
this.stateReleased.show.set(0,false);
isPressed.add(false);
hasBeenPressed.add(false);
isHovering.add(false);
hasClickedOff.add(false);
pressNumber = PRESS_MTONCE;
doOnClick = CHANGE_ON_CLICK;
doOnClickRelease = RETURN_ON_RELEASE;
doOnPass = NTG_ON_PASS;
doOnRelease = NTG_ON_RELEASE;
state.add(STATE_DEFAULT);
name.add("button"+(name.size()));
}
public Button(GUIBase stateDefault, GUIBase statePressed, int pressNumber,int doOnClick, int doOnClickRelease, int doOnPass, int doOnRelease){
this.stateDefault = (stateDefault);
this.statePressed = (statePressed);
this.stateReleased = (null);
this.position.add(new Vector2f(0,0));
this.size.add(new Vector2f(1,1));
this.stateDefault.position.set(0,this.position.get(0));
this.stateDefault.scale.get(0).multiply(this.size.get(0));
this.stateDefault.show.set(0,true);
this.statePressed.position.set(0,this.position.get(0));
this.statePressed.scale.get(0).multiply(this.size.get(0));
this.statePressed.show.set(0,false);
isPressed.add(false);
hasBeenPressed.add(false);
isHovering.add(false);
hasClickedOff.add(false);
this.pressNumber = pressNumber;
this.doOnClick = doOnClick;
this.doOnClickRelease = doOnClickRelease;
this.doOnPass = doOnPass;
this.doOnRelease = doOnRelease;
state.add(STATE_DEFAULT);
name.add("button"+(name.size()));
}
public Button(GUIBase stateDefault, GUIBase statePressed, GUIBase stateReleased, int pressNumber,int doOnClick, int doOnClickRelease, int doOnPass, int doOnRelease){
this.stateDefault = (stateDefault);
this.statePressed = (statePressed);
this.stateReleased = (stateReleased);
position.add(new Vector2f(0,0));
this.size.add(new Vector2f(1,1));
this.stateDefault.position.set(0,this.position.get(0));
this.stateDefault.scale.get(0).multiply(this.size.get(0));
this.stateDefault.show.set(0,true);
this.statePressed.position.set(0,this.position.get(0));
this.statePressed.scale.get(0).multiply(this.size.get(0));
this.statePressed.show.set(0,false);
this.stateReleased.position.set(0,this.position.get(0));
this.stateReleased.scale.get(0).multiply(this.size.get(0));
this.stateReleased.show.set(0,false);
isPressed.add(false);
hasBeenPressed.add(false);
isHovering.add(false);
hasClickedOff.add(false);
this.pressNumber = pressNumber;
this.doOnClick = doOnClick;
this.doOnClickRelease = doOnClickRelease;
this.doOnPass = doOnPass;
this.doOnRelease = doOnRelease;
state.add(STATE_DEFAULT);
name.add("button"+(name.size()));
}
public Button(GUIBase stateDefault, GUIBase statePressed, Vector2f position, int pressNumber,int doOnClick, int doOnClickRelease, int doOnPass, int doOnRelease){
this.stateDefault = (stateDefault);
this.statePressed = (statePressed);
this.stateReleased = (null);
this.position.add(position);
this.size.add(new Vector2f(1,1));
this.stateDefault.position.set(0,this.position.get(0));
this.stateDefault.scale.get(0).multiply(this.size.get(0));
this.stateDefault.show.set(0,true);
this.statePressed.position.set(0,this.position.get(0));
this.statePressed.scale.get(0).multiply(this.size.get(0));
this.statePressed.show.set(0,false);
isPressed.add(false);
hasBeenPressed.add(false);
isHovering.add(false);
hasClickedOff.add(false);
this.pressNumber = pressNumber;
this.doOnClick = doOnClick;
this.doOnClickRelease = doOnClickRelease;
this.doOnPass = doOnPass;
this.doOnRelease = doOnRelease;
state.add(STATE_DEFAULT);
name.add("button"+(name.size()));
}
public Button(GUIBase stateDefault, GUIBase statePressed, Vector2f position, Vector2f size, int pressNumber,int doOnClick, int doOnClickRelease, int doOnPass, int doOnRelease){
this.stateDefault = stateDefault;
this.statePressed = statePressed;
this.stateReleased = null;
this.position.add(position);
this.size.add(size);
this.stateDefault.position.set(0,this.position.get(0));
this.stateDefault.scale.get(0).multiply(this.size.get(0));
this.stateDefault.show.set(0,true);
this.statePressed.position.set(0,this.position.get(0));
this.statePressed.scale.get(0).multiply(this.size.get(0));
this.statePressed.show.set(0,false);
isPressed.add(false);
hasBeenPressed.add(false);
isHovering.add(false);
hasClickedOff.add(false);
this.pressNumber = pressNumber;
this.doOnClick = doOnClick;
this.doOnClickRelease = doOnClickRelease;
this.doOnPass = doOnPass;
this.doOnRelease = doOnRelease;
state.add(STATE_DEFAULT);
name.add("button"+(name.size()));
}
public Button(GUIBase stateDefault, GUIBase statePressed, GUIBase stateReleased, Vector2f position, int pressNumber,int doOnClick, int doOnClickRelease, int doOnPass, int doOnRelease){
this.stateDefault = (stateDefault);
this.statePressed = (statePressed);
this.stateReleased = (stateReleased);
this.position.add(position);
this.size.add(new Vector2f(1,1));
this.stateDefault.position.set(0,this.position.get(0));
this.stateDefault.scale.get(0).multiply(this.size.get(0));
this.stateDefault.show.set(0,true);
this.statePressed.position.set(0,this.position.get(0));
this.statePressed.scale.get(0).multiply(this.size.get(0));
this.statePressed.show.set(0,false);
this.stateReleased.position.set(0,this.position.get(0));
this.stateReleased.scale.get(0).multiply(this.size.get(0));
this.stateReleased.show.set(0,false);
isPressed.add(false);
hasBeenPressed.add(false);
isHovering.add(false);
hasClickedOff.add(false);
this.pressNumber = pressNumber;
this.doOnClick = doOnClick;
this.doOnClickRelease = doOnClickRelease;
this.doOnPass = doOnPass;
this.doOnRelease = doOnRelease;
state.add(STATE_DEFAULT);
name.add("button"+(name.size()));
}
public Button(GUIBase stateDefault, GUIBase statePressed, GUIBase stateReleased, Vector2f position, Vector2f size, int pressNumber,int doOnClick, int doOnClickRelease, int doOnPass, int doOnRelease){
this.stateDefault = (stateDefault);
this.statePressed = (statePressed);
this.stateReleased = (stateReleased);
this.position.add(position);
this.size.add(size);
this.stateDefault.position.set(0,this.position.get(0));
this.stateDefault.scale.get(0).multiply(this.size.get(0));
this.stateDefault.show.set(0,true);
this.statePressed.position.set(0,this.position.get(0));
this.statePressed.scale.get(0).multiply(this.size.get(0));
this.statePressed.show.set(0,false);
this.stateReleased.position.set(0,this.position.get(0));
this.stateReleased.scale.get(0).multiply(this.size.get(0));
this.stateReleased.show.set(0,false);
isPressed.add(false);
hasBeenPressed.add(false);
isHovering.add(false);
hasClickedOff.add(false);
this.pressNumber = pressNumber;
this.doOnClick = doOnClick;
this.doOnClickRelease = doOnClickRelease;
this.doOnPass = doOnPass;
this.doOnRelease = doOnRelease;
state.add(STATE_DEFAULT);
name.add("button"+(name.size()));
}
public void setBehavior( int pressNumber,int doOnClick, int doOnClickRelease, int doOnPass, int doOnRelease){
this.pressNumber = pressNumber;
this.doOnClick = doOnClick;
this.doOnClickRelease = doOnClickRelease;
this.doOnPass = doOnPass;
this.doOnRelease = doOnRelease;
}
public void setName(int index,String name){this.name.set(index,name);}
public void checkClickAt(Vector2f click,int index){
Vector2f pos = Vector2f.scale(Vector2f.sub(click,Vector2f.scale(stateDefault.screenDimensions,0.5f)),2f);
if(((pos.x>position.get(index).x-size.get(index).x)&&(pos.x<position.get(index).x+size.get(index).x))&&
((pos.y>position.get(index).y-size.get(index).y)&&(pos.y<position.get(index).y+size.get(index).y))){
if(!hasClickedOff.get(index)) {
click(index);
}
}else {
}
}
public void checkClickAt(Vector2f click){
Vector2f pos = Vector2f.scale(Vector2f.sub(click,Vector2f.scale(stateDefault.screenDimensions,0.5f)),2f);
for (int i = 0; i < name.size(); i++) {
if (((pos.x > position.get(i).x - size.get(i).x) && (pos.x < position.get(i).x + size.get(i).x)) &&
((pos.y > position.get(i).y - size.get(i).y) && (pos.y < position.get(i).y + size.get(i).y))) {
if(!hasClickedOff.get(i)){
click(i);
}
}else {
boolean tmp = false;
if(isPressed.get(i)) {
tmp = true;
release(i);
}
if(tmp){hasClickedOff.set(i,true);}
}
}
}
public void checkPassAt(Vector2f click,int index){
Vector2f pos = Vector2f.scale(Vector2f.sub(click,Vector2f.scale(stateDefault.screenDimensions,0.5f)),2f);
if(((pos.x>position.get(index).x-size.get(index).x)&&(pos.x<position.get(index).x+size.get(index).x))&&
((pos.y>position.get(index).y-size.get(index).y)&&(pos.y<position.get(index).y+size.get(index).y))){
if(!hasClickedOff.get(index)) {
passOn(index);
}
}else{if(isHovering.get(index)){
passOff(index);
}}
}
public void checkPassAt(Vector2f click){
Vector2f pos = Vector2f.scale(Vector2f.sub(click,Vector2f.scale(stateDefault.screenDimensions,0.5f)),2f);
for (int i = 0; i < name.size(); i++) {
if (((pos.x > position.get(i).x - size.get(i).x) && (pos.x < position.get(i).x + size.get(i).x)) &&
((pos.y > position.get(i).y - size.get(i).y) && (pos.y < position.get(i).y + size.get(i).y))) {
if(!hasClickedOff.get(i)) {
passOn(i);
}
}else{if(isHovering.get(i)){passOff(i);}}
}
}
public void checkReleaseIn(Vector2f click,int index){
Vector2f pos = Vector2f.scale(Vector2f.sub(click,Vector2f.scale(stateDefault.screenDimensions,0.5f)),2f);
if(((pos.x>position.get(index).x-size.get(index).x)&&(pos.x<position.get(index).x+size.get(index).x))&&
((pos.y>position.get(index).y-size.get(index).y)&&(pos.y<position.get(index).y+size.get(index).y))) {
release(index);
}
}
public void checkReleaseIn(Vector2f click){
Vector2f pos = Vector2f.scale(Vector2f.sub(click,Vector2f.scale(stateDefault.screenDimensions,0.5f)),2f);
for (int i = 0; i < name.size(); i++) {
if (((pos.x > position.get(i).x - size.get(i).x) && (pos.x < position.get(i).x + size.get(i).x)) &&
((pos.y > position.get(i).y - size.get(i).y) && (pos.y < position.get(i).y + size.get(i).y))) {
release(i);
}
}
}
public void checkReleaseOut(Vector2f click,int index){
Vector2f pos = Vector2f.scale(Vector2f.sub(click,Vector2f.scale(stateDefault.screenDimensions,0.5f)),2f);
if(((pos.x<position.get(index).x-size.get(index).x)||(pos.x>position.get(index).x+size.get(index).x))||
((pos.y<position.get(index).y-size.get(index).y)||(pos.y>position.get(index).y+size.get(index).y))) {
boolean tmp = false;
if(isPressed.get(index)){
tmp = true;
release(index);
}
if(tmp){hasClickedOff.set(index,true);}
}
}
public void checkReleaseOut(Vector2f click){
Vector2f pos = Vector2f.scale(Vector2f.sub(click,Vector2f.scale(stateDefault.screenDimensions,0.5f)),2f);
for (int i = 0; i < name.size(); i++) {
if (((pos.x < position.get(i).x - size.get(i).x) || (pos.x > position.get(i).x + size.get(i).x)) ||
((pos.y > position.get(i).y - size.get(i).y) || (pos.y < position.get(i).y + size.get(i).y))) {
boolean tmp = false;
if(isPressed.get(i)){
tmp = true;
release(i);
}
if(tmp){hasClickedOff.set(i,true);}
}
}
}
public void click(int index){
switch (pressNumber){
case CANNOT_PRESS:
Log.w("clickButton","You can't press this button!");
break;
case PRESS_ONCE:
switch (doOnClick){
case STAY_ON_CLICK:
if(!hasBeenPressed.get(index)){
isPressed.set(index,true);
hasBeenPressed.set(index,true);
}
break;
case CHANGE_ON_CLICK:
if(!hasBeenPressed.get(index)){
isPressed.set(index,true);
hasBeenPressed.set(index,true);
state.set(index,STATE_PRESSED);
}
break;
default:
Log.e("clickButton","doOnClick can't be : " + doOnClick + ", it must either be STAY_ON_CLICK or CHANGE_ON_CLICK.");
break;
}
break;
case PRESS_MTONCE:
switch (doOnClick){
case STAY_ON_CLICK:
isPressed.set(index,true);
hasBeenPressed.set(index,true);
break;
case CHANGE_ON_CLICK:
isPressed.set(index,true);
hasBeenPressed.set(index,true);
state.set(index,STATE_PRESSED);
break;
default:
Log.e("clickButton","invalid value for doOnClick : "+doOnClick);
break;
}
break;
default:
Log.e("clickButton","invalid value for pressNumber : "+pressNumber);
break;
}
updateIcon(index);
}
public void release(int index){
if(isPressed.get(index)){
switch (doOnClickRelease){
case STAY_ON_RELEASE:
isPressed.set(index,false);
hasBeenPressed.set(index,true);
state.set(index,STATE_PRESSED);
break;
case CHANGE_ON_RELEASE:
isPressed.set(index,false);
hasBeenPressed.set(index,true);
state.set(index,STATE_RELEASED);
break;
case RETURN_ON_RELEASE:
isPressed.set(index,false);
hasBeenPressed.set(index,true);
state.set(index,STATE_DEFAULT);
break;
default:
Log.e("releaseButton","invalid value for doOnClickRelease : "+doOnClickRelease);
break;
}
updateIcon(index);
}else {
switch (doOnRelease){
case NTG_ON_RELEASE:
state.set(index,STATE_DEFAULT);
break;
case CLICK_ON_RELEASE:
click(index);
release(index);
break;
default:
Log.e("releaseButton","invalid value for doOnRelease : "+doOnRelease);
break;
}
}
isHovering.set(index,true);
hasClickedOff.set(index,false);
}
public void passOn(int index){
switch (doOnPass){
case NTG_ON_PASS:
isHovering.set(index,true);
break;
case PREVIEW_ON_PASS:
state.set(index,STATE_PRESSED);
isHovering.set(index,true);
break;
case CHANGE_ON_PASS:
state.set(index,STATE_RELEASED);
isHovering.set(index,true);
break;
case CLICK_ON_PASS:
click(index);
isHovering.set(index,true);
break;
default:
Log.e("passOnButton","invalid value for doOnPass : "+doOnPass);
break;
}
updateIcon(index);
}
public void passOff(int index){
Log.w("passOff","passOff");
if(doOnPass != CLICK_ON_PASS){
Log.w("checkPassAt","!ClickOnPass");
state.set(index,STATE_DEFAULT);
isHovering.set(index,false);
}
updateIcon(index);
}
public void updateIcon(int index){
//Log.w("updateButtonIcon","state : "+state.get(index));
switch (state.get(index)){
case STATE_DEFAULT:
stateDefault.show.set(index,true);
statePressed.show.set(index,false);
if(stateReleased != null){stateReleased.show.set(index,false);}
break;
case STATE_PRESSED:
stateDefault.show.set(index,false);
statePressed.show.set(index,true);
if(stateReleased != null){stateReleased.show.set(index,false);}
break;
case STATE_RELEASED:
stateDefault.show.set(index,false);
statePressed.show.set(index,false);
if (stateReleased!= null){stateReleased.show.set(index,true);}else
{Log.e("updateButtonIcon",name.get(index)+" has no stateReleased icon!");}
break;
default:
throw new IllegalStateException("Unexpected value: " + state.get(index));
}
stateDefault.position.set(index,position.get(index));
statePressed.position.set(index,position.get(index));
if(stateReleased != null) {
stateReleased.position.set(index, position.get(index));
}
}
public Button copy(){
Button button = new Button(stateDefault,statePressed,stateReleased,pressNumber,doOnClick,doOnClickRelease,doOnPass,doOnRelease);
button.position = new ArrayList<>(position);
button.size = new ArrayList<>(size);
button.state = new ArrayList<>(state);
button.isPressed = new ArrayList<>(isPressed);
button.hasBeenPressed = new ArrayList<>(isPressed);
button.name = new ArrayList<>(name);
button.isHovering = new ArrayList<>(isHovering);
return button;
}
public void addInstance(){
isPressed.add(false);
hasBeenPressed.add(false);
position.add(new Vector2f(0,0));
size.add(new Vector2f(1,1));
state.add(STATE_DEFAULT);
stateDefault.instance(0);
stateDefault.position.set(stateDefault.position.size()-1,new Vector2f(0,0));
statePressed.instance(0);
statePressed.position.set(statePressed.position.size()-1,new Vector2f(0,0));
stateReleased.instance(0);
stateReleased.position.set(stateReleased.position.size()-1,new Vector2f(0,0));
Log.w("addInstance","added instance");
}
public void addInstance(Vector2f position,Vector2f size){
isPressed.add(false);
hasBeenPressed.add(false);
this.position.add(position);
size.add(size);
state.add(STATE_DEFAULT);
stateDefault.addInstance(position,0,size);
statePressed.addInstance(position,0,size);
stateReleased.addInstance(position,0,size);
Log.w("addInstance","added instance");
}
public void instance(int index){
isPressed.add(isPressed.get(index));
hasBeenPressed.add(hasBeenPressed.get(index));
this.position.add(position.get(index));
size.add(size.get(index));
state.add(state.get(index));
stateDefault.instance(index);
statePressed.instance(index);
stateReleased.instance(index);
Log.w("Instance","instanced"+index);
}
public void removeInstance(int index){
isPressed.remove(index);
hasBeenPressed.remove(index);
this.position.remove(index);
size.remove(index);
state.remove(index);
stateDefault.removeInstance(index);
statePressed.removeInstance(index);
stateReleased.removeInstance(index);
Log.w("removedInstance","instance removed "+index);
}
public void reset(int index){
isPressed.set(index,false);
hasBeenPressed.set(index,false);
state.set(index,STATE_DEFAULT);
}
public void setPosition(int index, Vector2f pos){
position.set(index,pos);
stateDefault.position.set(index,pos);
statePressed.position.set(index,pos);
stateReleased.position.set(index,pos);
}
public void setSize(int index, Vector2f s){
size.set(index,s);
stateDefault.scale.set(index,s);
statePressed.scale.set(index,s);
stateReleased.scale.set(index,s);
}
}
If anything is unclear, please tell me in the comments, I will update as soon as possible.
I would like to know what improvements I should do and if my code has some overly complex stuff. I'm especially looking at the amount of initialisers and if there's a better way to do this and som tips as to what I should include in the initialisation.