Skip to content

Commit

Permalink
Fix[control]: GUI button showing buttons that shouldn't be visible
Browse files Browse the repository at this point in the history
  • Loading branch information
Vera-Firefly authored Aug 7, 2023
1 parent 8cda5d8 commit fb2128b
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import static net.kdt.pojavlaunch.MainActivity.mControlLayout;
import static net.kdt.pojavlaunch.Tools.currentDisplayMetrics;

import static org.lwjgl.glfw.CallbackBridge.isGrabbing;

import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Build;
Expand Down Expand Up @@ -239,7 +241,7 @@ public void setControlVisible(boolean isVisible) {

mControlVisible = isVisible;
for(ControlInterface button : getButtonChildren()){
button.setVisible(isVisible);
button.setVisible(((button.getProperties().displayInGame && isGrabbing()) || (button.getProperties().displayInMenu && !isGrabbing())) && isVisible);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,6 @@ public void setProperties(ControlData properties, boolean changePos) {
setText(properties.name);
}

public void setVisible(boolean isVisible){
if(mProperties.isHideable)
setVisibility(isVisible ? VISIBLE : GONE);
}

@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.annotation.SuppressLint;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

Expand Down Expand Up @@ -46,13 +47,14 @@ public void addButton(ControlSubButton button){
}

private void setControlButtonVisibility(ControlButton button, boolean isVisible){
post(() -> button.setVisible(isVisible));
button.getControlView().setVisibility(isVisible ? VISIBLE : GONE);
}

private void switchButtonVisibility(){
areButtonsVisible = !areButtonsVisible;
int visibility = areButtonsVisible ? VISIBLE : GONE;
for(ControlButton button : buttons){
button.setVisible(areButtonsVisible);
button.getControlView().setVisibility(visibility);
}
}

Expand Down Expand Up @@ -129,7 +131,7 @@ public void setVisible(boolean isVisible) {
setVisibility(visibility);
if(visibility == GONE || areButtonsVisible) {
for(ControlSubButton button : buttons){
button.setVisible(isVisible);
button.getControlView().setVisibility(isVisible ? VISIBLE : (!mProperties.isHideable && getVisibility() == GONE) ? VISIBLE : View.GONE);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package net.kdt.pojavlaunch.customcontrols.buttons;

import static android.view.View.GONE;
import static android.view.View.VISIBLE;
import static net.kdt.pojavlaunch.prefs.LauncherPreferences.PREF_BUTTONSIZE;

import android.annotation.SuppressLint;
Expand Down Expand Up @@ -49,7 +51,10 @@ default void setProperties(ControlData properties) {
*/
void cloneButton();

void setVisible(boolean isVisible);
default void setVisible(boolean isVisible) {
if(getProperties().isHideable)
getControlView().setVisibility(isVisible ? VISIBLE : GONE);
}

void sendKeyPresses(boolean isDown);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public ControlData getProperties() {
@Override
public void setProperties(ControlData properties, boolean changePos) {
mControlData = (ControlJoystickData) properties;
mControlData.isHideable = true;
ControlInterface.super.setProperties(properties, changePos);
postDelayed(() -> setForwardLockDistance(mControlData.forwardLock ? (int) Tools.dpToPx(60) : 0), 10);
}
Expand All @@ -105,10 +106,6 @@ public void cloneButton() {
getControlLayoutParent().addJoystickButton((ControlJoystickData) data);
}

@Override
public void setVisible(boolean isVisible) {
setVisibility(isVisible ? VISIBLE : GONE);
}

@Override
public void setBackground() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ private void filterProperties(){

@Override
public void setVisible(boolean isVisible) {
setVisibility(isVisible ? VISIBLE : (!mProperties.isHideable && parentDrawer.getVisibility() == GONE) ? VISIBLE : View.GONE);
// STUB, visibility handled by the ControlDrawer
//setVisibility(isVisible ? VISIBLE : (!mProperties.isHideable && parentDrawer.getVisibility() == GONE) ? VISIBLE : View.GONE);
}

@Override
Expand Down Expand Up @@ -92,6 +93,6 @@ public void snapAndAlign(float x, float y) {

@Override
public void loadEditValues(EditControlPopup editControlPopup) {
editControlPopup.loadSubButtonValues(getProperties());
editControlPopup.loadSubButtonValues(getProperties(), parentDrawer.drawerData.orientation);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,11 @@ public void appearColor(boolean fromRight, int color) {
}
}

// Adjust the color selector to have the same size as the control settings
ViewGroup.LayoutParams params = mColorSelector.getRootView().getLayoutParams();
params.height = mScrollView.getHeight();
mColorSelector.getRootView().setLayoutParams(params);

mDisplayingColor = true;
mColorSelector.show(color == -1 ? Color.WHITE : color);
}
Expand Down Expand Up @@ -351,14 +356,16 @@ public void loadJoystickValues(ControlJoystickData data) {
/**
* Load values for sub buttons
*/
public void loadSubButtonValues(ControlData data) {
public void loadSubButtonValues(ControlData data, ControlDrawerData.Orientation drawerOrientation) {
loadValues(data);

// Size linked to the parent drawer
mSizeTextview.setVisibility(GONE);
mSizeXTextView.setVisibility(GONE);
mWidthEditText.setVisibility(GONE);
mHeightEditText.setVisibility(GONE);
// Size linked to the parent drawer depending on the drawer settings
if(drawerOrientation != ControlDrawerData.Orientation.FREE){
mSizeTextview.setVisibility(GONE);
mSizeXTextView.setVisibility(GONE);
mWidthEditText.setVisibility(GONE);
mHeightEditText.setVisibility(GONE);
}

// No conditional, already depends on the parent drawer visibility
mVisibilityTextView.setVisibility(GONE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
android:paddingHorizontal="@dimen/padding_moderate"
android:paddingVertical="@dimen/padding_moderate"
android:id="@+id/color_picker_layout"
android:layout_marginVertical="@dimen/padding_heavy">
android:layout_marginVertical="@dimen/padding_heavy"
android:layout_gravity="center_vertical"
>

<net.kdt.pojavlaunch.colorselector.SVRectangleView
android:id="@+id/color_selector_rectangle_view"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="@dimen/_280sdp"
android:layout_height="match_parent"
android:layout_height="wrap_content"
android:layout_marginVertical="@dimen/padding_heavy"
android:background="@drawable/background_control_editor">
android:background="@drawable/background_control_editor"
android:layout_gravity="center_vertical"
>

<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/edit_layout"
Expand Down

0 comments on commit fb2128b

Please sign in to comment.