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

QoL update #6338

Merged
merged 5 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app_pojavlauncher/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ dependencies {
implementation 'com.github.PojavLauncherTeam:portrait-ssp:6c02fd739b'
implementation 'com.github.Mathias-Boulay:ExtendedView:1.0.0'
implementation 'com.github.Mathias-Boulay:android_gamepad_remapper:2.0.3'
implementation 'com.github.Mathias-Boulay:virtual-joystick-android:2e7aa25e50'
implementation 'com.github.Mathias-Boulay:virtual-joystick-android:1.14'

// implementation 'com.intuit.sdp:sdp-android:1.0.5'
// implementation 'com.intuit.ssp:ssp-android:1.0.5'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ public CustomControls(Context ctx) {
this.mControlDataList.add(new ControlData(ctx, R.string.control_jump, new int[]{LwjglGlfwKeycode.GLFW_KEY_SPACE}, "${right} - ${margin} * 2 - ${width}", "${bottom} - ${margin} * 2 - ${height}", true));

//The default controls are conform to the V3
version = 7;
version = 8;
}


public void save(String path) throws IOException {
//Current version is the V3.1 so the version as to be marked as 7 !
version = 7;
//Current version is the V3.2 so the version as to be marked as 8 !
version = 8;

Tools.write(path, Tools.GLOBAL_GSON.toJson(this));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,35 +24,64 @@ public static CustomControls loadAndConvertIfNecessary(String jsonPath) throws I
CustomControls layout = LayoutConverter.convertV1Layout(layoutJobj);
layout.save(jsonPath);
return layout;
} else if (layoutJobj.getInt("version") == 2) {
CustomControls layout = LayoutConverter.convertV2Layout(layoutJobj);
layout.save(jsonPath);
return layout;
}else if (layoutJobj.getInt("version") >= 3 && layoutJobj.getInt("version") <= 5) {
return LayoutConverter.convertV3_4Layout(layoutJobj);
} else if (layoutJobj.getInt("version") == 6 || layoutJobj.getInt("version") == 7) {
return Tools.GLOBAL_GSON.fromJson(jsonLayoutData, CustomControls.class);
} else {
return null;
int version = layoutJobj.getInt("version");
if (version == 2) {
CustomControls layout = LayoutConverter.convertV2Layout(layoutJobj);
layout.save(jsonPath);
return layout;
}
if (version == 3 || version == 4 || version == 5) {
return LayoutConverter.convertV3_4Layout(layoutJobj);
}
if (version == 6 || version == 7) {
return convertV6_7Layout(layoutJobj);
}
else if (version == 8) {
return Tools.GLOBAL_GSON.fromJson(jsonLayoutData, CustomControls.class);
}
}
return null;
} catch (JSONException e) {
throw new JsonSyntaxException("Failed to load", e);
}
}


/**
* Normalize the layout to v8 from v6/7. An issue from the joystick height and position has to be fixed.
* @param oldLayoutJson The old layout
* @return The new layout with the fixed joystick height
*/
public static CustomControls convertV6_7Layout(JSONObject oldLayoutJson) {
CustomControls layout = Tools.GLOBAL_GSON.fromJson(oldLayoutJson.toString(), CustomControls.class);
for (ControlJoystickData data : layout.mJoystickDataList) {
if (data.getHeight() > data.getWidth()) {
// Make the size square, adjust the dynamic position related to height
float ratio = data.getHeight() / data.getWidth();

data.dynamicX = data.dynamicX.replace("${height}", "(" + ratio + " * ${height})");
data.dynamicY = data.dynamicY.replace("${height}", "(" + ratio + " * ${height})") + " + (" + (ratio-1) + " * ${height})";

data.setHeight(data.getWidth());
}
}
layout.version = 8;
return layout;
}

/**
* Normalize the layout to v6 from v3/4: The stroke width is no longer dependant on the button size
*/
public static CustomControls convertV3_4Layout(JSONObject oldLayoutJson) {
private static CustomControls convertV3_4Layout(JSONObject oldLayoutJson) {
CustomControls layout = Tools.GLOBAL_GSON.fromJson(oldLayoutJson.toString(), CustomControls.class);
convertStrokeWidth(layout);
layout.version = 6;
return layout;
}


public static CustomControls convertV2Layout(JSONObject oldLayoutJson) throws JSONException {
private static CustomControls convertV2Layout(JSONObject oldLayoutJson) throws JSONException {
CustomControls layout = Tools.GLOBAL_GSON.fromJson(oldLayoutJson.toString(), CustomControls.class);
JSONArray layoutMainArray = oldLayoutJson.getJSONArray("mControlDataList");
layout.mControlDataList = new ArrayList<>(layoutMainArray.length());
Expand Down Expand Up @@ -95,7 +124,7 @@ public static CustomControls convertV2Layout(JSONObject oldLayoutJson) throws JS
return layout;
}

public static CustomControls convertV1Layout(JSONObject oldLayoutJson) throws JSONException {
private static CustomControls convertV1Layout(JSONObject oldLayoutJson) throws JSONException {
CustomControls empty = new CustomControls();
JSONArray layoutMainArray = oldLayoutJson.getJSONArray("mControlDataList");
for (int i = 0; i < layoutMainArray.length(); i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,22 @@ public class DrawerPullButton extends View {
public DrawerPullButton(Context context) {super(context); init();}
public DrawerPullButton(Context context, @Nullable AttributeSet attrs) {super(context, attrs); init();}

private final Paint mPaint = new Paint();
private final Paint mBackgroundPaint = new Paint();
private VectorDrawableCompat mDrawable;

private void init(){
mDrawable = VectorDrawableCompat.create(getContext().getResources(), R.drawable.ic_sharp_settings_24, null);
setAlpha(0.33f);
mBackgroundPaint.setColor(Color.BLACK);
}

@Override
protected void onDraw(Canvas canvas) {
mPaint.setColor(Color.BLACK);
canvas.drawArc(0,-getHeight(),getWidth(), getHeight(), 0, 180, true, mPaint);
canvas.drawArc(getPaddingLeft(),-getHeight() + getPaddingBottom(),getWidth() - getPaddingRight(), getHeight() - getPaddingBottom(), 0, 180, true, mBackgroundPaint);

mPaint.setColor(Color.WHITE);
mDrawable.setBounds(0, 0, getHeight(), getHeight());
mDrawable.setBounds(getPaddingLeft()/2, getPaddingTop()/2, getHeight() - getPaddingRight()/2, getHeight() - getPaddingBottom()/2);
canvas.save();
canvas.translate((getWidth()-getHeight())/2f, 0);
canvas.translate((getWidth()-getHeight())/2f, -getPaddingBottom()/2f);
mDrawable.draw(canvas);
canvas.restore();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ private void bindLayout() {
/**
* A long function linking all the displayed data on the popup and,
* the currently edited mCurrentlyEditedButton
* @noinspection SuspiciousNameCombination
*/
private void setupRealTimeListeners() {
mNameEditText.addTextChangedListener((SimpleTextWatcher) s -> {
Expand All @@ -349,6 +350,10 @@ private void setupRealTimeListeners() {
float width = safeParseFloat(s.toString());
if (width >= 0) {
mCurrentlyEditedButton.getProperties().setWidth(width);
if (mCurrentlyEditedButton.getProperties() instanceof ControlJoystickData) {
// Joysticks are square
mCurrentlyEditedButton.getProperties().setHeight(width);
}
mCurrentlyEditedButton.updateProperties();
}
});
Expand All @@ -359,6 +364,10 @@ private void setupRealTimeListeners() {
float height = safeParseFloat(s.toString());
if (height >= 0) {
mCurrentlyEditedButton.getProperties().setHeight(height);
if (mCurrentlyEditedButton.getProperties() instanceof ControlJoystickData) {
// Joysticks are square
mCurrentlyEditedButton.getProperties().setWidth(height);
}
mCurrentlyEditedButton.updateProperties();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import androidx.annotation.Nullable;

import net.kdt.pojavlaunch.GrabListener;
import net.kdt.pojavlaunch.LwjglGlfwKeycode;
import net.kdt.pojavlaunch.prefs.LauncherPreferences;
import net.kdt.pojavlaunch.utils.MCOptionUtils;
Expand All @@ -26,8 +27,16 @@ public class HotbarView extends View implements MCOptionUtils.MCOptionListener,
LwjglGlfwKeycode.GLFW_KEY_4, LwjglGlfwKeycode.GLFW_KEY_5, LwjglGlfwKeycode.GLFW_KEY_6,
LwjglGlfwKeycode.GLFW_KEY_7, LwjglGlfwKeycode.GLFW_KEY_8, LwjglGlfwKeycode.GLFW_KEY_9};
private final DropGesture mDropGesture = new DropGesture(new Handler(Looper.getMainLooper()));
private final GrabListener mGrabListener = new GrabListener() {
@Override
public void onGrabState(boolean isGrabbing) {
mLastIndex = -1;
mDropGesture.cancel();
}
};

private int mWidth;
private int mLastIndex;
private int mLastIndex = -1;
private int mGuiScale;

public HotbarView(Context context) {
Expand Down Expand Up @@ -66,6 +75,13 @@ protected void onAttachedToWindow() {
}
mGuiScale = MCOptionUtils.getMcScale();
repositionView();
CallbackBridge.addGrabListener(mGrabListener);
}

@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
CallbackBridge.removeGrabListener(mGrabListener);
}

private void repositionView() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,12 @@ public boolean processTouchEvent(MotionEvent motionEvent) {
case MotionEvent.ACTION_MOVE:
mTracker.trackEvent(motionEvent);
float[] motionVector = mTracker.getMotionVector();
CallbackBridge.mouseX += (float) (motionVector[0] * mSensitivity);
CallbackBridge.mouseY += (float) (motionVector[1] * mSensitivity);
float deltaX = (float) (motionVector[0] * mSensitivity);
float deltaY = (float) (motionVector[1] * mSensitivity);
mLeftClickGesture.setMotion(deltaX, deltaY);
mRightClickGesture.setMotion(deltaX, deltaY);
CallbackBridge.mouseX += deltaX;
CallbackBridge.mouseY += deltaY;
CallbackBridge.sendCursorPos(CallbackBridge.mouseX, CallbackBridge.mouseY);
if(LauncherPreferences.PREF_DISABLE_GESTURES) break;
checkGestures();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

public class LeftClickGesture extends ValidatorGesture {
public static final int FINGER_STILL_THRESHOLD = (int) Tools.dpToPx(9);
private float mGestureStartX, mGestureStartY;
private float mGestureStartX, mGestureStartY, mGestureEndX, mGestureEndY;
private boolean mMouseActivated;

public LeftClickGesture(Handler handler) {
Expand All @@ -22,14 +22,14 @@ public LeftClickGesture(Handler handler) {

public final void inputEvent() {
if(submit()) {
mGestureStartX = CallbackBridge.mouseX;
mGestureStartY = CallbackBridge.mouseY;
mGestureStartX = mGestureEndX = CallbackBridge.mouseX;
mGestureStartY = mGestureEndY = CallbackBridge.mouseY;
}
}

@Override
public boolean checkAndTrigger() {
boolean fingerStill = LeftClickGesture.isFingerStill(mGestureStartX, mGestureStartY, FINGER_STILL_THRESHOLD);
boolean fingerStill = LeftClickGesture.isFingerStill(mGestureStartX, mGestureStartY, mGestureEndX, mGestureEndY, FINGER_STILL_THRESHOLD);
// If the finger is still, fire the gesture.
if(fingerStill) {
sendMouseButton(LwjglGlfwKeycode.GLFW_MOUSE_BUTTON_LEFT, true);
Expand All @@ -47,6 +47,11 @@ public void onGestureCancelled(boolean isSwitching) {
}
}

public void setMotion(float deltaX, float deltaY) {
mGestureEndX += deltaX;
mGestureEndY += deltaY;
}

/**
* Check if the finger is still when compared to mouseX/mouseY in CallbackBridge.
* @param startX the starting X of the gesture
Expand All @@ -61,4 +66,13 @@ public static boolean isFingerStill(float startX, float startY, float threshold)
startY
) <= threshold;
}

public static boolean isFingerStill(float startX, float startY, float endX, float endY, float threshold) {
return MathUtils.dist(
endX,
endY,
startX,
startY
) <= threshold;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
public class RightClickGesture extends ValidatorGesture{
private boolean mGestureEnabled = true;
private boolean mGestureValid = true;
private float mGestureStartX, mGestureStartY;
private float mGestureStartX, mGestureStartY, mGestureEndX, mGestureEndY;
public RightClickGesture(Handler mHandler) {
super(mHandler, 150);
}
Expand All @@ -24,6 +24,11 @@ public final void inputEvent() {
}
}

public void setMotion(float deltaX, float deltaY) {
mGestureEndX += deltaX;
mGestureEndY += deltaY;
}

@Override
public boolean checkAndTrigger() {
// If the validate() method was called, it means that the user held on for too long. The cancellation should be ignored.
Expand All @@ -38,7 +43,7 @@ public boolean checkAndTrigger() {
public void onGestureCancelled(boolean isSwitching) {
mGestureEnabled = true;
if(!mGestureValid || isSwitching) return;
boolean fingerStill = LeftClickGesture.isFingerStill(mGestureStartX, mGestureStartY, LeftClickGesture.FINGER_STILL_THRESHOLD);
boolean fingerStill = LeftClickGesture.isFingerStill(mGestureStartX, mGestureStartY, mGestureEndX, mGestureEndY, LeftClickGesture.FINGER_STILL_THRESHOLD);
if(!fingerStill) return;
CallbackBridge.sendMouseButton(LwjglGlfwKeycode.GLFW_MOUSE_BUTTON_RIGHT, true);
CallbackBridge.sendMouseButton(LwjglGlfwKeycode.GLFW_MOUSE_BUTTON_RIGHT, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,28 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
Tools.removeCurrentFragment(requireActivity());
});

mGameDirButton.setOnClickListener(v -> {

View.OnClickListener gameDirListener = getGameDirListener();
mGameDirButton.setOnClickListener(gameDirListener);
mDefaultPath.setOnClickListener(gameDirListener);

View.OnClickListener controlSelectListener = getControlSelectListener();
mControlSelectButton.setOnClickListener(controlSelectListener);
mDefaultControl.setOnClickListener(controlSelectListener);

// Setup the expendable list behavior
View.OnClickListener versionSelectListener = getVersionSelectListener();
mVersionSelectButton.setOnClickListener(versionSelectListener);
mDefaultVersion.setOnClickListener(versionSelectListener);

// Set up the icon change click listener
mProfileIcon.setOnClickListener(v -> CropperUtils.startCropper(mCropperLauncher));

loadValues(LauncherPreferences.DEFAULT_PREF.getString(LauncherPreferences.PREF_KEY_CURRENT_PROFILE, ""), view.getContext());
}

private View.OnClickListener getGameDirListener() {
return v -> {
Bundle bundle = new Bundle(2);
bundle.putBoolean(FileSelectorFragment.BUNDLE_SELECT_FOLDER, true);
bundle.putString(FileSelectorFragment.BUNDLE_ROOT_PATH, Tools.DIR_GAME_HOME);
Expand All @@ -116,30 +137,26 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat

Tools.swapFragment(requireActivity(),
FileSelectorFragment.class, FileSelectorFragment.TAG, bundle);
});
};
}

mControlSelectButton.setOnClickListener(v -> {
private View.OnClickListener getControlSelectListener() {
return v -> {
Bundle bundle = new Bundle(3);
bundle.putBoolean(FileSelectorFragment.BUNDLE_SELECT_FOLDER, false);
bundle.putString(FileSelectorFragment.BUNDLE_ROOT_PATH, Tools.CTRLMAP_PATH);
mValueToConsume = FileSelectorFragment.BUNDLE_SELECT_FILE;

Tools.swapFragment(requireActivity(),
FileSelectorFragment.class, FileSelectorFragment.TAG, bundle);
});
};
}

// Setup the expendable list behavior
mVersionSelectButton.setOnClickListener(v -> VersionSelectorDialog.open(v.getContext(), false, (id, snapshot)->{
private View.OnClickListener getVersionSelectListener() {
return v -> VersionSelectorDialog.open(v.getContext(), false, (id, snapshot)-> {
mTempProfile.lastVersionId = id;
mDefaultVersion.setText(id);
}));

// Set up the icon change click listener
mProfileIcon.setOnClickListener(v -> CropperUtils.startCropper(mCropperLauncher));



loadValues(LauncherPreferences.DEFAULT_PREF.getString(LauncherPreferences.PREF_KEY_CURRENT_PROFILE, ""), view.getContext());
});
}


Expand Down
5 changes: 3 additions & 2 deletions app_pojavlauncher/src/main/res/layout/activity_basemain.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@

<net.kdt.pojavlaunch.customcontrols.handleview.DrawerPullButton
android:id="@+id/drawer_button"
android:layout_width="24dp"
android:layout_height="12dp"
android:layout_width="40dp"
android:layout_height="20dp"
android:padding="8dp"
android:elevation="10dp"
android:layout_gravity="center_horizontal"/>
<net.kdt.pojavlaunch.customcontrols.mouse.HotbarView
Expand Down
Loading
Loading