diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/ControlData.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/ControlData.java index 4d50ba983..e132b8a12 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/ControlData.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/ControlData.java @@ -100,6 +100,9 @@ public class ControlData { public float cornerRadius; //0-100% public boolean isSwipeable; + public boolean displayInGame; + public boolean displayInMenu; + public ControlData() { this("button"); } @@ -142,10 +145,10 @@ public class ControlData { } public ControlData(String name, int[] keycodes, String dynamicX, String dynamicY, float width, float height, boolean isToggle){ - this(name, keycodes, dynamicX, dynamicY, width, height, isToggle, 1,0x4D000000, 0xFFFFFFFF,0,0); + this(name, keycodes, dynamicX, dynamicY, width, height, isToggle, 1,0x4D000000, 0xFFFFFFFF,0,0, true, true); } - public ControlData(String name, int[] keycodes, String dynamicX, String dynamicY, float width, float height, boolean isToggle, float opacity, int bgColor, int strokeColor, int strokeWidth, float cornerRadius) { + public ControlData(String name, int[] keycodes, String dynamicX, String dynamicY, float width, float height, boolean isToggle, float opacity, int bgColor, int strokeColor, int strokeWidth, float cornerRadius, boolean displayInGame, boolean displayInMenu) { this.name = name; this.keycodes = inflateKeycodeArray(keycodes); this.dynamicX = dynamicX; @@ -159,6 +162,8 @@ public class ControlData { this.strokeColor = strokeColor; this.strokeWidth = strokeWidth; this.cornerRadius = cornerRadius; + this.displayInGame = displayInGame; + this.displayInMenu = displayInMenu; } //Deep copy constructor @@ -175,7 +180,9 @@ public class ControlData { controlData.bgColor, controlData.strokeColor, controlData.strokeWidth, - controlData.cornerRadius + controlData.cornerRadius, + controlData.displayInGame, + controlData.displayInMenu ); } diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/ControlLayout.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/ControlLayout.java index 3f4dd7f7b..98a5d3638 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/ControlLayout.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/ControlLayout.java @@ -247,6 +247,12 @@ public class ControlLayout extends FrameLayout { removeEditWindow(); } mModifiable = isModifiable; + if(isModifiable){ + // In edit mode, all controls have to be shown + for(ControlInterface button : getButtonChildren()){ + button.setVisible(true); + } + } } public boolean getModifiable(){ diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/buttons/ControlInterface.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/buttons/ControlInterface.java index 3f3e6fae9..274880f92 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/buttons/ControlInterface.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/buttons/ControlInterface.java @@ -4,14 +4,17 @@ import static net.kdt.pojavlaunch.prefs.LauncherPreferences.PREF_BUTTONSIZE; import android.annotation.SuppressLint; import android.graphics.drawable.GradientDrawable; +import android.util.Log; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.widget.FrameLayout; import androidx.annotation.CallSuper; +import androidx.annotation.NonNull; import androidx.core.math.MathUtils; +import net.kdt.pojavlaunch.GrabListener; import net.kdt.pojavlaunch.Tools; import net.kdt.pojavlaunch.customcontrols.ControlData; import net.kdt.pojavlaunch.customcontrols.ControlLayout; @@ -24,7 +27,7 @@ import org.lwjgl.glfw.CallbackBridge; * Most of the injected behavior is editing behavior, * sending keys has to be implemented by sub classes. */ -public interface ControlInterface extends View.OnLongClickListener { +public interface ControlInterface extends View.OnLongClickListener, GrabListener { View getControlView(); ControlData getProperties(); @@ -45,8 +48,13 @@ public interface ControlInterface extends View.OnLongClickListener { /** Load the values and hide non useful forms */ void loadEditValues(EditControlPopup editControlPopup); + @Override + default void onGrabState(boolean isGrabbing) { + if(getControlLayoutParent() != null && getControlLayoutParent().getModifiable()) return; // Disable when edited + setVisible((getProperties().displayInGame && isGrabbing) || (getProperties().displayInMenu && !isGrabbing)); + } - default ControlLayout getControlLayoutParent(){ + default ControlLayout getControlLayoutParent() { return (ControlLayout) getControlView().getParent(); } @@ -269,6 +277,31 @@ public interface ControlInterface extends View.OnLongClickListener { injectProperties(); injectTouchEventBehavior(); injectLayoutParamBehavior(); + injectGrabListenerBehavior(); + } + + /** Inject the grab listener, remove it when the view is gone */ + default void injectGrabListenerBehavior(){ + if(getControlView() == null){ + Log.e(ControlInterface.class.toString(), "Failed to inject grab listener behavior !"); + return; + } + + + getControlView().addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() { + @Override + public void onViewAttachedToWindow(@NonNull View v) { + CallbackBridge.addGrabListener(ControlInterface.this); + } + + @Override + public void onViewDetachedFromWindow(@NonNull View v) { + getControlView().removeOnAttachStateChangeListener(this); + CallbackBridge.removeGrabListener(ControlInterface.this); + } + }); + + } default void injectProperties(){ diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/handleview/EditControlPopup.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/handleview/EditControlPopup.java index d2ef00e7a..365023351 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/handleview/EditControlPopup.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/handleview/EditControlPopup.java @@ -19,6 +19,8 @@ import android.view.animation.AccelerateDecelerateInterpolator; import android.view.animation.Interpolator; import android.widget.AdapterView; import android.widget.ArrayAdapter; +import android.widget.CheckBox; +import android.widget.CompoundButton; import android.widget.EditText; import android.widget.SeekBar; import android.widget.Spinner; @@ -84,6 +86,7 @@ public class EditControlPopup { protected TextView mSelectBackgroundColor, mSelectStrokeColor; protected ArrayAdapter mAdapter; protected List mSpecialArray; + protected CheckBox mDisplayInGameCheckbox, mDisplayInMenuCheckbox; // Decorative textviews private TextView mOrientationTextView, mMappingTextView, mNameTextView, mCornerRadiusTextView; @@ -269,6 +272,9 @@ public class EditControlPopup { mPassthroughSwitch.setChecked(data.passThruEnabled); mSwipeableSwitch.setChecked(data.isSwipeable); + mDisplayInGameCheckbox.setChecked(data.displayInGame); + mDisplayInMenuCheckbox.setChecked(data.displayInMenu); + for(int i = 0; i< data.keycodes.length; i++){ if (data.keycodes[i] < 0) { mKeycodeSpinners[i].setSelection(data.keycodes[i] + mSpecialArray.size()); @@ -343,6 +349,8 @@ public class EditControlPopup { mStrokePercentTextView = mScrollView.findViewById(R.id.editStrokeWidth_textView_percent); mAlphaPercentTextView = mScrollView.findViewById(R.id.editButtonOpacity_textView_percent); mCornerRadiusPercentTextView = mScrollView.findViewById(R.id.editCornerRadius_textView_percent); + mDisplayInGameCheckbox = mScrollView.findViewById(R.id.visibility_game_checkbox); + mDisplayInMenuCheckbox = mScrollView.findViewById(R.id.visibility_menu_checkbox); //Decorative stuff mMappingTextView = mScrollView.findViewById(R.id.editMapping_textView); @@ -504,6 +512,15 @@ public class EditControlPopup { public void onNothingSelected(AdapterView parent) {} }); + mDisplayInGameCheckbox.setOnCheckedChangeListener((buttonView, isChecked) -> { + if(internalChanges) return; + mCurrentlyEditedButton.getProperties().displayInGame = isChecked; + }); + + mDisplayInMenuCheckbox.setOnCheckedChangeListener((buttonView, isChecked) -> { + if(internalChanges) return; + mCurrentlyEditedButton.getProperties().displayInMenu = isChecked; + }); mSelectStrokeColor.setOnClickListener(v -> { mColorSelector.setAlphaEnabled(false); diff --git a/app_pojavlauncher/src/main/res/layout/dialog_control_button_setting.xml b/app_pojavlauncher/src/main/res/layout/dialog_control_button_setting.xml index 11d0b862a..daf40f55f 100644 --- a/app_pojavlauncher/src/main/res/layout/dialog_control_button_setting.xml +++ b/app_pojavlauncher/src/main/res/layout/dialog_control_button_setting.xml @@ -220,7 +220,7 @@ @@ -390,6 +388,31 @@ app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toTopOf="@id/editButtonOpacity_textView" /> + + + + + + +