From 015e27daa0224ef3527ca749aaa6ba06ffde6aae Mon Sep 17 00:00:00 2001 From: artdeell Date: Mon, 10 Jan 2022 17:38:16 +0300 Subject: [PATCH] Make the profile settings from the previous commit user-editable --- .../net/kdt/pojavlaunch/BaseMainActivity.java | 1 + .../pojavlaunch/profiles/ProfileEditor.java | 46 ++++++++++++++++++- .../res/layout/version_profile_editor.xml | 45 +++++++++++++++++- .../src/main/res/values/strings.xml | 2 + 4 files changed, 91 insertions(+), 3 deletions(-) diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/BaseMainActivity.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/BaseMainActivity.java index ad1c72f5e..7026b52ec 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/BaseMainActivity.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/BaseMainActivity.java @@ -103,6 +103,7 @@ public class BaseMainActivity extends BaseActivity { } } if(prof.__P_renderer_name != null) { + Log.i("RdrDebug","__P_renderer="+prof.__P_renderer_name); Tools.LOCAL_RENDERER = prof.__P_renderer_name; } } diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/profiles/ProfileEditor.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/profiles/ProfileEditor.java index d785a9e43..bb845f9f0 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/profiles/ProfileEditor.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/profiles/ProfileEditor.java @@ -7,6 +7,7 @@ import android.content.DialogInterface; import android.util.Log; import android.view.LayoutInflater; import android.view.View; +import android.widget.ArrayAdapter; import android.widget.ImageView; import android.widget.Spinner; import android.widget.TextView; @@ -17,12 +18,18 @@ import androidx.annotation.Nullable; import net.kdt.pojavlaunch.BaseLauncherActivity; import net.kdt.pojavlaunch.PojavLauncherActivity; import net.kdt.pojavlaunch.R; +import net.kdt.pojavlaunch.Tools; import net.kdt.pojavlaunch.extra.ExtraCore; import net.kdt.pojavlaunch.extra.ExtraListener; +import net.kdt.pojavlaunch.multirt.MultiRTUtils; +import net.kdt.pojavlaunch.multirt.RTSpinnerAdapter; import net.kdt.pojavlaunch.value.launcherprofiles.LauncherProfiles; import net.kdt.pojavlaunch.value.launcherprofiles.MinecraftProfile; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import java.util.Map; import java.util.UUID; @@ -31,6 +38,10 @@ public class ProfileEditor implements ExtraListener> { TextView profileNameView; ImageView profileIconView; Spinner versionSpinner; + Spinner javaRuntimeSpinner; + Spinner rendererSpinner; + List runtimes; + List renderNames; AlertDialog dialog; Context context; String selectedVersionId; @@ -51,6 +62,15 @@ public class ProfileEditor implements ExtraListener> { bldr.setView(mainView); profileNameView = mainView.findViewById(R.id.vprof_editior_profile_name); versionSpinner = mainView.findViewById(R.id.vprof_editor_version_spinner); + javaRuntimeSpinner = mainView.findViewById(R.id.vprof_editor_spinner_runtime); + rendererSpinner = mainView.findViewById(R.id.vprof_editor_profile_renderer); + { + List renderList = new ArrayList<>(); + Collections.addAll(renderList, context.getResources().getStringArray(R.array.renderer)); + renderList.add("Default"); + renderNames = Arrays.asList(context.getResources().getStringArray(R.array.renderer_values)); + rendererSpinner.setAdapter(new ArrayAdapter<>(context, android.R.layout.simple_spinner_dropdown_item,renderList)); + } profileIconView = mainView.findViewById(R.id.vprof_editor_icon); bldr.setPositiveButton(R.string.global_save,this::save); bldr.setNegativeButton(android.R.string.cancel,(dialog,which)->destroy(dialog)); @@ -75,7 +95,21 @@ public class ProfileEditor implements ExtraListener> { } editingProfile = uuid; } - + runtimes = MultiRTUtils.getRuntimes(); + javaRuntimeSpinner.setAdapter(new RTSpinnerAdapter(context, runtimes)); + int jvm_index = runtimes.indexOf(new MultiRTUtils.Runtime("")); + int rnd_index = rendererSpinner.getAdapter().getCount()-1; + if (prof.javaDir != null) { + String selectedRuntime = prof.javaDir.substring(Tools.LAUNCHERPROFILES_RTPREFIX.length()); + int nindex = runtimes.indexOf(new MultiRTUtils.Runtime(selectedRuntime)); + if (nindex != -1) jvm_index = nindex; + } + if(prof.__P_renderer_name != null) { + int nindex = renderNames.indexOf(prof.__P_renderer_name); + if(nindex != -1) rnd_index = nindex; + } + javaRuntimeSpinner.setSelection(jvm_index); + rendererSpinner.setSelection(rnd_index); ExtraCore.addExtraListener("lac_version_list",this); profileNameView.setText(prof.name); if(ProfileAdapter.iconCache.containsKey(profile)) { @@ -126,6 +160,16 @@ public class ProfileEditor implements ExtraListener> { } prof.name = profileNameView.getText().toString(); prof.lastVersionId = (String)versionSpinner.getSelectedItem(); + MultiRTUtils.Runtime selectedRuntime = (MultiRTUtils.Runtime) javaRuntimeSpinner.getSelectedItem(); + if(selectedRuntime.name.equals("")) { + prof.javaDir = null; + }else if(selectedRuntime.versionString == null) { + prof.javaDir = null; + }else{ + prof.javaDir = Tools.LAUNCHERPROFILES_RTPREFIX+selectedRuntime.name; + } + if(rendererSpinner.getSelectedItemPosition() == renderNames.size()) prof.__P_renderer_name = null; + else prof.__P_renderer_name = renderNames.get(rendererSpinner.getSelectedItemPosition()); LauncherProfiles.mainProfileJson.profiles.put(editingProfile,prof); cb.onSave(editingProfile,isNew, false); destroy(dialog); diff --git a/app_pojavlauncher/src/main/res/layout/version_profile_editor.xml b/app_pojavlauncher/src/main/res/layout/version_profile_editor.xml index cea30c2f7..60cbfd9e0 100644 --- a/app_pojavlauncher/src/main/res/layout/version_profile_editor.xml +++ b/app_pojavlauncher/src/main/res/layout/version_profile_editor.xml @@ -1,6 +1,9 @@ - + @@ -57,6 +60,7 @@ android:layout_marginStart="16dp" android:layout_marginTop="32dp" android:layout_marginEnd="16dp" + android:minHeight="48dp" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/vprof_editior_profile_name" /> @@ -69,4 +73,41 @@ app:layout_constraintBottom_toTopOf="@+id/vprof_editor_version_spinner" app:layout_constraintStart_toStartOf="@+id/vprof_editor_version_spinner" /> - \ No newline at end of file + + + + + + + + + + \ No newline at end of file diff --git a/app_pojavlauncher/src/main/res/values/strings.xml b/app_pojavlauncher/src/main/res/values/strings.xml index f6f51f13b..01b0482e1 100644 --- a/app_pojavlauncher/src/main/res/values/strings.xml +++ b/app_pojavlauncher/src/main/res/values/strings.xml @@ -294,4 +294,6 @@ Disable VBOs Help with compatibility on some old versions Delete + Java Runtime + Renderer