Menu button

This commit is contained in:
artdeell 2023-01-24 21:34:54 +03:00
parent a197b906a2
commit c4880416e6
5 changed files with 43 additions and 2 deletions

View File

@ -44,7 +44,7 @@ import net.kdt.pojavlaunch.value.launcherprofiles.MinecraftProfile;
import org.lwjgl.glfw.*;
import android.net.*;
public class MainActivity extends BaseActivity {
public class MainActivity extends BaseActivity implements ControlButtonMenuListener{
public static volatile ClipboardManager GLOBAL_CLIPBOARD;
public static final String INTENT_MINECRAFT_VERSION = "intent_version";
@ -116,6 +116,7 @@ public class MainActivity extends BaseActivity {
protected void initLayout(int resId) {
setContentView(resId);
bindValues();
mControlLayout.setMenuListener(this);
mDrawerPullButton.setOnClickListener(v -> drawerLayout.openDrawer(navDrawer));
drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
@ -210,6 +211,7 @@ public class MainActivity extends BaseActivity {
} catch (Throwable th) {
Tools.showError(this, th);
}
mDrawerPullButton.setVisibility(mControlLayout.hasMenuButton() ? View.GONE : View.VISIBLE);
mControlLayout.toggleControlVisible();
}
@ -405,6 +407,7 @@ public class MainActivity extends BaseActivity {
minecraftProfile.controlFile == null
? LauncherPreferences.PREF_DEFAULTCTRL_PATH
: Tools.CTRLMAP_PATH + "/" + minecraftProfile.controlFile);
mDrawerPullButton.setVisibility(mControlLayout.hasMenuButton() ? View.GONE : View.VISIBLE);
} catch (IOException e) {
Tools.showError(this,e);
}
@ -515,4 +518,9 @@ public class MainActivity extends BaseActivity {
}
});
}
@Override
public void onClickedMenu() {
drawerLayout.openDrawer(navDrawer);
}
}

View File

@ -0,0 +1,5 @@
package net.kdt.pojavlaunch.customcontrols;
public interface ControlButtonMenuListener {
void onClickedMenu();
}

View File

@ -29,6 +29,7 @@ public class ControlData {
public static final int SPECIALBTN_MOUSEMID = -6;
public static final int SPECIALBTN_SCROLLUP = -7;
public static final int SPECIALBTN_SCROLLDOWN = -8;
public static final int SPECIALBTN_MENU = -9;
private static ControlData[] SPECIAL_BUTTONS;
private static String[] SPECIAL_BUTTON_NAME_ARRAY;
@ -65,7 +66,8 @@ public class ControlData {
new ControlData("MID", new int[]{SPECIALBTN_MOUSEMID}, "${margin}", "${margin}"),
new ControlData("SCROLLUP", new int[]{SPECIALBTN_SCROLLUP}, "${margin}", "${margin}"),
new ControlData("SCROLLDOWN", new int[]{SPECIALBTN_SCROLLDOWN}, "${margin}", "${margin}")
new ControlData("SCROLLDOWN", new int[]{SPECIALBTN_SCROLLDOWN}, "${margin}", "${margin}"),
new ControlData("MENU", new int[]{SPECIALBTN_MENU}, "${margin}", "${margin}")
};
}

View File

@ -32,6 +32,7 @@ public class ControlLayout extends FrameLayout {
private EditControlPopup mControlPopup = null;
private ControlHandleView mHandleView;
private ControlButtonMenuListener mMenuListener;
public ActionRow actionRow = null;
public ControlLayout(Context ctx) {
@ -367,4 +368,22 @@ public class ControlLayout extends FrameLayout {
mLayout.save(path);
} catch (IOException e) {Log.e("ControlLayout", "Failed to save the layout at:" + path);}
}
public boolean hasMenuButton() {
for(ControlInterface controlInterface : getButtonChildren()){
for (int keycode : controlInterface.getProperties().keycodes) {
if (keycode == ControlData.SPECIALBTN_MENU) return true;
}
}
return false;
}
public void setMenuListener(ControlButtonMenuListener menuListener) {
this.mMenuListener = menuListener;
}
public void notifyAppMenu() {
if(mMenuListener != null) mMenuListener.onClickedMenu();
}
}

View File

@ -7,6 +7,7 @@ import android.view.*;
import android.widget.*;
import net.kdt.pojavlaunch.customcontrols.ControlButtonMenuListener;
import net.kdt.pojavlaunch.customcontrols.ControlData;
import net.kdt.pojavlaunch.customcontrols.ControlLayout;
import net.kdt.pojavlaunch.customcontrols.handleview.*;
@ -22,12 +23,14 @@ import static org.lwjgl.glfw.CallbackBridge.sendMouseButton;
public class ControlButton extends TextView implements ControlInterface {
private final Paint mRectPaint = new Paint();
protected ControlData mProperties;
private final ControlLayout mControlLayout;
protected boolean mIsToggled = false;
protected boolean mIsPointerOutOfBounds = false;
public ControlButton(ControlLayout layout, ControlData properties) {
super(layout.getContext());
mControlLayout = layout;
setGravity(Gravity.CENTER);
setAllCaps(true);
setTextColor(Color.WHITE);
@ -183,6 +186,7 @@ public class ControlButton extends TextView implements ControlInterface {
sendKeyPress(keycode, CallbackBridge.getCurrentMods(), isDown);
CallbackBridge.setModifiers(keycode, isDown);
}else{
Log.i("punjabilauncher", "sendSpecialKey("+keycode+","+isDown+")");
sendSpecialKey(keycode, isDown);
}
}
@ -221,6 +225,9 @@ public class ControlButton extends TextView implements ControlInterface {
case ControlData.SPECIALBTN_SCROLLUP:
if (!isDown) CallbackBridge.sendScroll(0, -1d);
break;
case ControlData.SPECIALBTN_MENU:
mControlLayout.notifyAppMenu();
break;
}
}