From 86d754f5d23e9c23ab071f98efb1073324b04e74 Mon Sep 17 00:00:00 2001 From: Vera-Firefly <1964762970@qq.com> Date: Wed, 9 Oct 2024 16:38:26 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=9F=E8=83=BD[=E6=98=BE=E7=A4=BA]:=20?= =?UTF-8?q?=E6=B8=B8=E6=88=8F=E5=86=85=E4=BF=AE=E6=94=B9=E5=88=86=E8=BE=A8?= =?UTF-8?q?=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/firefly/utils/ResolutionAdjuster.java | 99 +++++++++++++++++++ .../net/kdt/pojavlaunch/MainActivity.java | 5 + .../kdt/pojavlaunch/MinecraftGLSurface.java | 3 +- .../src/main/res/values/headings_array.xml | 1 + 4 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 app_pojavlauncher/src/main/java/com/firefly/utils/ResolutionAdjuster.java diff --git a/app_pojavlauncher/src/main/java/com/firefly/utils/ResolutionAdjuster.java b/app_pojavlauncher/src/main/java/com/firefly/utils/ResolutionAdjuster.java new file mode 100644 index 000000000..4fb5e9fac --- /dev/null +++ b/app_pojavlauncher/src/main/java/com/firefly/utils/ResolutionAdjuster.java @@ -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(); + } + +} \ No newline at end of file diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/MainActivity.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/MainActivity.java index 388624e85..d76989cb6 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/MainActivity.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/MainActivity.java @@ -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; @@ -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(); }; diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/MinecraftGLSurface.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/MinecraftGLSurface.java index b51dd68e4..e805f6945 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/MinecraftGLSurface.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/MinecraftGLSurface.java @@ -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)); @@ -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(); diff --git a/app_pojavlauncher/src/main/res/values/headings_array.xml b/app_pojavlauncher/src/main/res/values/headings_array.xml index f7f48b9eb..18eeef0fe 100644 --- a/app_pojavlauncher/src/main/res/values/headings_array.xml +++ b/app_pojavlauncher/src/main/res/values/headings_array.xml @@ -40,6 +40,7 @@ @string/mcl_setting_title_mousespeed @string/preference_gyro_sensitivity_title @string/mcl_option_customcontrol + @string/mcl_setting_title_resolution_scaler