Skip to content

Commit

Permalink
功能[显示]: 游戏内修改分辨率
Browse files Browse the repository at this point in the history
  • Loading branch information
Vera-Firefly committed Oct 9, 2024
1 parent 5826a6f commit 86d754f
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package com.firefly.utils;

import android.app.AlertDialog;
import android.content.Context;
import android.widget.SeekBar;
import android.widget.TextView;
import android.view.Gravity;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.util.Log;

import net.kdt.pojavlaunch.MinecraftGLSurface;
import net.kdt.pojavlaunch.prefs.LauncherPreferences;
import net.kdt.pojavlaunch.R;
import net.kdt.pojavlaunch.Tools;

public class ResolutionAdjuster {

private float mScaleFactor;
private final Context context;
private MinecraftGLSurface glSurface;

// 构造函数,传入Context
public ResolutionAdjuster(Context context) {
this.context = context;
}
public ResolutionAdjuster(Context context, MinecraftGLSurface glSurface) {
this.context = context;
this.glSurface = glSurface;
}

// 显示滑动条弹窗
public void showSeekBarDialog() {
if (glSurface == null) {
glSurface = new MinecraftGLSurface(context);
}
mScaleFactor = glSurface.mScaleFactor;
int percentage = Math.round(mScaleFactor * 100);
// 动态创建一个LinearLayout作为容器
// 什么?为什么不用.xml来构建?
// 因为麻烦
LinearLayout layout = new LinearLayout(context);
layout.setOrientation(LinearLayout.VERTICAL);
layout.setPadding(50, 40, 50, 40);
layout.setGravity(Gravity.CENTER);

// 动态创建一个TextView,用于显示缩放因子
final TextView scaleTextView = new TextView(context);
scaleTextView.setText(percentage + "%");
scaleTextView.setTextSize(18);
layout.addView(scaleTextView);

// 动态创建一个SeekBar,用于调整缩放因子
final SeekBar scaleSeekBar = new SeekBar(context);
scaleSeekBar.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));

// 设置滑动条的最大值和初始进度
int maxScaleFactor = Math.max(LauncherPreferences.PREF_SCALE_FACTOR, 100);
scaleSeekBar.setMax(maxScaleFactor - 25);
scaleSeekBar.setProgress((int) (mScaleFactor * 100) - 25);
layout.addView(scaleSeekBar);

// 设置滑动条监听器
scaleSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
// 更新缩放因子
mScaleFactor = (progress + 25) / 100f;
glSurface.mScaleFactor = mScaleFactor;
int scaleFactor = Math.round(mScaleFactor * 100);
// 实时更新显示的缩放因子
scaleTextView.setText(scaleFactor + "%");

// 新分辨率
if (glSurface != null) glSurface.refreshSize();
}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// Nothing to do here
}

@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// Nothing to do here
}
});

// 创建并显示弹窗
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(context.getString(R.string.mcl_setting_title_resolution_scaler));
builder.setView(layout);
builder.setCancelable(false); // 不允许点击外部关闭弹窗,防止进程错误
// 设置确认按钮,点击关闭弹窗
builder.setPositiveButton(android.R.string.ok, (d, i) -> d.dismiss());
builder.show();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import androidx.core.content.ContextCompat;
import androidx.drawerlayout.widget.DrawerLayout;

import com.firefly.utils.ResolutionAdjuster;
import com.kdt.LoggerView;
import com.movtery.feature.ProfileLanguageSelector;
import com.movtery.ui.subassembly.customprofilepath.ProfilePathManager;
Expand Down Expand Up @@ -220,6 +221,10 @@ protected void initLayout(int resId) {
case 5:
openCustomControls();
break;
case 6:{
ResolutionAdjuster adjuster = new ResolutionAdjuster(this, minecraftGLView);
adjuster.showSeekBarDialog();
} break;
}
drawerLayout.closeDrawers();
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public class MinecraftGLSurface extends View implements GrabListener {
.remapDpad(true));

/* Resolution scaler option, allow downsizing a window */
private final float mScaleFactor = LauncherPreferences.PREF_SCALE_FACTOR / 100f;
public float mScaleFactor = LauncherPreferences.PREF_SCALE_FACTOR / 100f;
/* Sensitivity, adjusted according to screen size */
private final double mSensitivityFactor = (1.4 * (1080f / Tools.getDisplayMetrics((Activity) getContext()).heightPixels));

Expand All @@ -92,6 +92,7 @@ public MinecraftGLSurface(Context context, AttributeSet attributeSet) {
setFocusable(true);
}


@RequiresApi(api = Build.VERSION_CODES.O)
private void setUpPointerCapture(AbstractTouchpad touchpad) {
if (mPointerCapture != null) mPointerCapture.detach();
Expand Down
1 change: 1 addition & 0 deletions app_pojavlauncher/src/main/res/values/headings_array.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<item>@string/mcl_setting_title_mousespeed</item>
<item>@string/preference_gyro_sensitivity_title</item>
<item>@string/mcl_option_customcontrol</item>
<item>@string/mcl_setting_title_resolution_scaler</item>
</string-array>

<string-array name="renderer_values">
Expand Down

0 comments on commit 86d754f

Please sign in to comment.