Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add disable/enable virtual buttons feature #1247

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public static class ControllerInputContext {
public enum ControllerMode {
Active,
MoveButtons,
ResizeButtons
ResizeButtons,
DisableEnableButtons,
}

private static final boolean _PRINT_DEBUG_INFORMATION = false;
Expand Down Expand Up @@ -74,8 +75,13 @@ public VirtualController(final ControllerHandler controllerHandler, FrameLayout
public void onClick(View v) {
String message;

if (currentMode == ControllerMode.Active){
if (currentMode == ControllerMode.Active) {
currentMode = ControllerMode.DisableEnableButtons;
showElements();
message = "Entering configuration mode (Disable/Enable buttons)";
} else if (currentMode == ControllerMode.DisableEnableButtons){
currentMode = ControllerMode.MoveButtons;
showEnabledElements();
message = "Entering configuration mode (Move buttons)";
} else if (currentMode == ControllerMode.MoveButtons) {
currentMode = ControllerMode.ResizeButtons;
Expand Down Expand Up @@ -111,11 +117,21 @@ public void hide() {
}

public void show() {
for (VirtualControllerElement element : elements) {
showEnabledElements();

buttonConfigure.setVisibility(View.VISIBLE);
}

public void showElements(){
for(VirtualControllerElement element : elements){
element.setVisibility(View.VISIBLE);
}
}

buttonConfigure.setVisibility(View.VISIBLE);
public void showEnabledElements(){
for(VirtualControllerElement element: elements){
element.setVisibility( element.enabled ? View.VISIBLE : View.INVISIBLE );
}
}

public void removeElements() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public abstract class VirtualControllerElement extends View {
private int configMoveColor = 0xF0FF0000;
private int configResizeColor = 0xF0FF00FF;
private int configSelectedColor = 0xF000FF00;
private int configDisabledColor = 0xF0AAAAAA;

protected int startSize_x;
protected int startSize_y;
Expand All @@ -61,6 +62,8 @@ private enum Mode {

private Mode currentMode = Mode.Normal;

public boolean enabled = true;

protected VirtualControllerElement(VirtualController controller, Context context, int elementId) {
super(context);

Expand Down Expand Up @@ -151,6 +154,10 @@ protected void actionEnableResize() {
currentMode = Mode.Resize;
}

protected void actionDisableEnableButton(){
enabled = !enabled;
}

protected void actionCancel() {
currentMode = Mode.Normal;
invalidate();
Expand All @@ -161,6 +168,8 @@ protected int getDefaultColor() {
return configMoveColor;
else if (virtualController.getControllerMode() == VirtualController.ControllerMode.ResizeButtons)
return configResizeColor;
else if (virtualController.getControllerMode() == VirtualController.ControllerMode.DisableEnableButtons)
return enabled ? configSelectedColor: configDisabledColor;
else
return normalColor;
}
Expand Down Expand Up @@ -247,6 +256,8 @@ public boolean onTouchEvent(MotionEvent event) {
actionEnableMove();
else if (virtualController.getControllerMode() == VirtualController.ControllerMode.ResizeButtons)
actionEnableResize();
else if (virtualController.getControllerMode() == VirtualController.ControllerMode.DisableEnableButtons)
actionDisableEnableButton();

return true;
}
Expand Down Expand Up @@ -330,6 +341,8 @@ public JSONObject getConfiguration() throws JSONException {
configuration.put("WIDTH", layoutParams.width);
configuration.put("HEIGHT", layoutParams.height);

configuration.put("ENABLED", enabled);

return configuration;
}

Expand All @@ -341,6 +354,9 @@ public void loadConfiguration(JSONObject configuration) throws JSONException {
layoutParams.width = configuration.getInt("WIDTH");
layoutParams.height = configuration.getInt("HEIGHT");

enabled = configuration.getBoolean("ENABLED");
setVisibility(enabled ? VISIBLE: INVISIBLE);

requestLayout();
}
}