Skip to content

Commit

Permalink
Fix[RendererPlugin]: fix renderer plugin loading error
Browse files Browse the repository at this point in the history
  • Loading branch information
ShirosakiMio committed Oct 18, 2024
1 parent e200c0b commit a0f1254
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 102 deletions.
75 changes: 75 additions & 0 deletions FCL/src/main/java/com/mio/util/RendererUtil.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package com.mio.util

import android.content.Context
import android.transition.Slide
import android.view.Gravity
import android.view.View
import android.widget.ArrayAdapter
import android.widget.ListView
import android.widget.PopupWindow
import com.tungsten.fcl.R
import com.tungsten.fcl.setting.Profiles
import com.tungsten.fclauncher.FCLConfig
import com.tungsten.fclauncher.plugins.RendererPlugin
import java.util.function.Consumer

class RendererUtil {
companion object {
@JvmStatic
fun openRendererMenu(
context: Context,
view: View,
width: Int,
height: Int,
callback: Consumer<String>
) {
val listView = ListView(context)
var popupWindow: PopupWindow? = null
listView.adapter =
ArrayAdapter(context, R.layout.item_renderer, mutableListOf<String>().apply {
add(context.getString(R.string.settings_fcl_renderer_gl4es))
add(context.getString(R.string.settings_fcl_renderer_virgl))
add(context.getString(R.string.settings_fcl_renderer_ltw))
add(context.getString(R.string.settings_fcl_renderer_vgpu))
add(context.getString(R.string.settings_fcl_renderer_zink))
add(context.getString(R.string.settings_fcl_renderer_freedreno))
RendererPlugin.rendererList.forEach {
add(it.des)
}
})
listView.setOnItemClickListener { _, _, position, _ ->
val versionSetting =
Profiles.getSelectedProfile().versionSetting
val rendererList = mutableListOf<FCLConfig.Renderer>().apply {
add(FCLConfig.Renderer.RENDERER_GL4ES)
add(FCLConfig.Renderer.RENDERER_VIRGL)
add(FCLConfig.Renderer.RENDERER_LTW)
add(FCLConfig.Renderer.RENDERER_VGPU)
add(FCLConfig.Renderer.RENDERER_ZINK)
add(FCLConfig.Renderer.RENDERER_FREEDRENO)
}
if (position > rendererList.size - 1) {
versionSetting.renderer = FCLConfig.Renderer.RENDERER_CUSTOM
RendererPlugin.selected =
RendererPlugin.rendererList[position - rendererList.size]
versionSetting.customRenderer = RendererPlugin.selected!!.des
} else {
versionSetting.renderer = rendererList[position]
}
popupWindow?.dismiss()
callback.accept(listView.adapter.getItem(position).toString())
}
popupWindow = PopupWindow(
listView,
width,
height
).apply {
isClippingEnabled = false
isOutsideTouchable = true
enterTransition = Slide(Gravity.TOP)
exitTransition = Slide(Gravity.TOP)
showAsDropDown(view)
}
}
}
}
47 changes: 4 additions & 43 deletions FCL/src/main/java/com/tungsten/fcl/activity/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import com.mio.util.AnimUtil
import com.mio.util.AnimUtil.Companion.interpolator
import com.mio.util.AnimUtil.Companion.startAfter
import com.mio.util.GuideUtil
import com.mio.util.RendererUtil
import com.tungsten.fcl.R
import com.tungsten.fcl.databinding.ActivityMainBinding
import com.tungsten.fcl.game.JarExecutorHelper
Expand Down Expand Up @@ -479,51 +480,11 @@ class MainActivity : FCLActivity(), OnSelectListener, View.OnClickListener {
}

private fun openRendererMenu(view: View) {
val listView = ListView(this)
var popupWindow: PopupWindow? = null
listView.adapter =
ArrayAdapter(this, R.layout.item_renderer, mutableListOf<String>().apply {
add(getString(R.string.settings_fcl_renderer_gl4es))
add(getString(R.string.settings_fcl_renderer_virgl))
add(getString(R.string.settings_fcl_renderer_ltw))
add(getString(R.string.settings_fcl_renderer_vgpu))
add(getString(R.string.settings_fcl_renderer_zink))
add(getString(R.string.settings_fcl_renderer_freedreno))
RendererPlugin.rendererList.forEach {
add(it.des)
}
})
listView.setOnItemClickListener { _, _, position, _ ->
val selectedProfile = Profiles.getSelectedProfile()
val versionSetting = selectedProfile.getVersionSetting(selectedProfile.selectedVersion)
val rendererList = mutableListOf<FCLConfig.Renderer>().apply {
add(FCLConfig.Renderer.RENDERER_GL4ES)
add(FCLConfig.Renderer.RENDERER_VIRGL)
add(FCLConfig.Renderer.RENDERER_LTW)
add(FCLConfig.Renderer.RENDERER_VGPU)
add(FCLConfig.Renderer.RENDERER_ZINK)
add(FCLConfig.Renderer.RENDERER_FREEDRENO)
}
if (position > rendererList.size - 1) {
versionSetting.renderer = FCLConfig.Renderer.RENDERER_CUSTOM
RendererPlugin.selected = RendererPlugin.rendererList[position - rendererList.size]
} else {
versionSetting.renderer = rendererList[position]
}
popupWindow?.dismiss()
RendererUtil.openRendererMenu(
this, view, bind.rightMenu.width, bind.launch.y.toInt()
) {
onClick(view)
}
popupWindow = PopupWindow(
listView,
bind.rightMenu.width,
bind.launch.y.toInt()
).apply {
isClippingEnabled = false
isOutsideTouchable = true
enterTransition = Slide(Gravity.TOP)
exitTransition = Slide(Gravity.TOP)
showAsDropDown(view)
}
}

private fun playAnim() {
Expand Down
4 changes: 4 additions & 0 deletions FCL/src/main/java/com/tungsten/fcl/setting/Profile.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ public VersionSetting getVersionSetting(String id) {
return repository.getVersionSetting(id);
}

public VersionSetting getVersionSetting() {
return repository.getVersionSetting(getSelectedVersion());
}

@Override
public String toString() {
return new ToStringBuilder(this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.view.inputmethod.EditorInfo;
import android.widget.ArrayAdapter;

import com.mio.util.RendererUtil;
import com.tungsten.fcl.R;
import com.tungsten.fcl.control.SelectControllerDialog;
import com.tungsten.fcl.game.FCLGameRepository;
Expand Down Expand Up @@ -51,6 +52,7 @@
import com.tungsten.fcllibrary.component.view.FCLSwitch;
import com.tungsten.fcllibrary.component.view.FCLTextView;
import com.tungsten.fcllibrary.component.view.FCLUILayout;
import com.tungsten.fcllibrary.util.ConvertUtils;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -86,11 +88,13 @@ public class VersionSettingPage extends FCLCommonPage implements ManageUI.Versio
private FCLSwitch noJVMCheckSwitch;

private FCLSpinner<String> javaSpinner;
private FCLSpinner<FCLConfig.Renderer> rendererSpinner;

private FCLImageButton editIconButton;
private FCLImageButton deleteIconButton;
private FCLImageButton controllerButton;
private FCLImageButton rendererButton;

private FCLTextView rendererText;

private final InvalidationListener specificSettingsListener;
private final StringProperty selectedVersion = new SimpleStringProperty();
Expand Down Expand Up @@ -134,7 +138,6 @@ private void create() {
isolateWorkingDirSwitch.disableProperty().bind(modpack);

javaSpinner = findViewById(R.id.edit_java);
rendererSpinner = findViewById(R.id.edit_renderer);

FCLTextView scaleFactorText = findViewById(R.id.scale_factor_text);

Expand All @@ -150,15 +153,6 @@ private void create() {
javaVersionDataList.add(JavaVersion.JAVA_21.getVersionName());
javaSpinner.setDataList(javaVersionDataList);

ArrayList<FCLConfig.Renderer> rendererDataList = new ArrayList<>();
rendererDataList.add(FCLConfig.Renderer.RENDERER_GL4ES);
rendererDataList.add(FCLConfig.Renderer.RENDERER_VIRGL);
rendererDataList.add(FCLConfig.Renderer.RENDERER_LTW);
rendererDataList.add(FCLConfig.Renderer.RENDERER_VGPU);
rendererDataList.add(FCLConfig.Renderer.RENDERER_ZINK);
rendererDataList.add(FCLConfig.Renderer.RENDERER_FREEDRENO);
rendererSpinner.setDataList(rendererDataList);

// add spinner text
ArrayList<String> javaVersionList = new ArrayList<>();
javaVersionList.add(getContext().getString(R.string.settings_game_java_version_auto));
Expand All @@ -170,35 +164,17 @@ private void create() {
javaAdapter.setDropDownViewResource(R.layout.item_spinner_dropdown);
javaSpinner.setAdapter(javaAdapter);

ArrayList<String> rendererList = new ArrayList<>();
rendererList.add(getContext().getString(R.string.settings_fcl_renderer_gl4es));
rendererList.add(getContext().getString(R.string.settings_fcl_renderer_virgl));
rendererList.add(getContext().getString(R.string.settings_fcl_renderer_ltw));
rendererList.add(getContext().getString(R.string.settings_fcl_renderer_vgpu));
rendererList.add(getContext().getString(R.string.settings_fcl_renderer_zink));
rendererList.add(getContext().getString(R.string.settings_fcl_renderer_freedreno));
RendererPlugin.getRendererList().forEach(renderer -> {
rendererList.add(renderer.getDes());
});
ArrayAdapter<String> rendererAdapter = new ArrayAdapter<>(getContext(), R.layout.item_spinner_auto_tint, rendererList);
rendererAdapter.setDropDownViewResource(R.layout.item_spinner_dropdown);
rendererSpinner.setAdapter(rendererAdapter);
rendererSpinner.setListener(pos -> {
int targetIndex = FCLConfig.Renderer.values().length - 1;
if (pos >= targetIndex) {
lastVersionSetting.setRenderer(FCLConfig.Renderer.RENDERER_CUSTOM);
lastVersionSetting.setCustomRenderer(RendererPlugin.getRendererList().get(pos - targetIndex).getDes());
RendererPlugin.setSelected(RendererPlugin.getRendererList().get(pos - targetIndex));
}
});

editIconButton = findViewById(R.id.edit_icon);
deleteIconButton = findViewById(R.id.delete_icon);
controllerButton = findViewById(R.id.edit_controller);
rendererButton = findViewById(R.id.edit_renderer);

editIconButton.setOnClickListener(this);
deleteIconButton.setOnClickListener(this);
controllerButton.setOnClickListener(this);
rendererButton.setOnClickListener(this);

rendererText = findViewById(R.id.renderer);

FCLProgressBar memoryBar = findViewById(R.id.memory_bar);

Expand Down Expand Up @@ -327,7 +303,6 @@ public void loadVersion(Profile profile, String versionId) {
FXUtils.unbindBoolean(beGestureSwitch, lastVersionSetting.getBeGestureProperty());
FXUtils.unbindBoolean(vulkanDriverSystemSwitch, lastVersionSetting.getVkDriverSystemProperty());
FXUtils.unbindSelection(javaSpinner, lastVersionSetting.getJavaProperty());
FXUtils.unbindSelection(rendererSpinner, lastVersionSetting.getRendererProperty());
scaleFactorSeekbar.percentProgressProperty().unbindBidirectional(lastVersionSetting.getScaleFactorProperty());
maxMemory.unbindBidirectional(lastVersionSetting.getMaxMemoryProperty());

Expand All @@ -350,9 +325,14 @@ public void loadVersion(Profile profile, String versionId) {
FXUtils.bindBoolean(beGestureSwitch, versionSetting.getBeGestureProperty());
FXUtils.bindBoolean(vulkanDriverSystemSwitch, versionSetting.getVkDriverSystemProperty());
FXUtils.bindSelection(javaSpinner, versionSetting.getJavaProperty());
FXUtils.bindSelection(rendererSpinner, versionSetting.getRendererProperty());
scaleFactorSeekbar.percentProgressProperty().bindBidirectional(versionSetting.getScaleFactorProperty());
maxMemory.bindBidirectional(versionSetting.getMaxMemoryProperty());
FCLConfig.Renderer renderer = versionSetting.getRenderer();
if (renderer == FCLConfig.Renderer.RENDERER_CUSTOM) {
rendererText.setText(versionSetting.getCustomRenderer());
} else {
rendererText.setText(renderer.toString());
}

versionSetting.getUsesGlobalProperty().addListener(specificSettingsListener);
if (versionId != null)
Expand Down Expand Up @@ -433,5 +413,10 @@ public void onClick(View view) {
SelectControllerDialog dialog = new SelectControllerDialog(getContext(), lastVersionSetting.getController(), controller -> lastVersionSetting.setController(controller.getId()));
dialog.show();
}
if (view == rendererButton) {
RendererUtil.openRendererMenu(getContext(), view, ConvertUtils.dip2px(getContext(), 400), ConvertUtils.dip2px(getContext(), 300), name -> {
rendererText.setText(name);
});
}
}
}
13 changes: 12 additions & 1 deletion FCL/src/main/res/layout/page_version_setting.xml
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,18 @@
android:layout_height="0dp"
android:layout_weight="1"/>

<com.tungsten.fcllibrary.component.view.FCLSpinner
<com.tungsten.fcllibrary.component.view.FCLTextView
android:id="@+id/renderer"
app:auto_text_tint="true"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>

<com.tungsten.fcllibrary.component.view.FCLImageButton
app:no_padding="true"
app:auto_tint="true"
android:layout_marginStart="5dp"
android:src="@drawable/ic_baseline_settings_24"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,30 @@
import android.util.AttributeSet;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatSpinner;

import com.tungsten.fclauncher.plugins.RendererPlugin;
import com.tungsten.fclcore.fakefx.beans.property.BooleanProperty;
import com.tungsten.fclcore.fakefx.beans.property.BooleanPropertyBase;
import com.tungsten.fclcore.fakefx.beans.property.ObjectProperty;
import com.tungsten.fclcore.fakefx.beans.property.ObjectPropertyBase;
import com.tungsten.fclcore.task.Schedulers;

import java.util.ArrayList;
import java.util.function.Consumer;

public class FCLSpinner<T> extends AppCompatSpinner {

private boolean fromUserOrSystem = false;
private ArrayList<T> dataList;
private ObjectProperty<T> selectedItemProperty;
private BooleanProperty visibilityProperty;
private Consumer<Integer> listener;

public void addSelectListener() {
setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
if (listener != null && dataList != null && i > dataList.size() - 1) {
listener.accept(i);
return;
}
if (dataList != null && dataList.size() > i) {
fromUserOrSystem = true;
selectedItemProperty().set(dataList.get(i));
Expand All @@ -51,10 +43,6 @@ public void onNothingSelected(AdapterView<?> adapterView) {
});
}

public void setListener(Consumer<Integer> listener) {
this.listener = listener;
}

public FCLSpinner(@NonNull Context context) {
super(context);
}
Expand Down Expand Up @@ -99,17 +87,6 @@ public void invalidated() {
Schedulers.androidUIThread().execute(() -> {
if (!fromUserOrSystem) {
T data = get();
//fix renderer plugin
if (!dataList.contains(data) && listener != null) {
ArrayAdapter<String> adapter = (ArrayAdapter<String>) getAdapter();
RendererPlugin.getRendererList().forEach(renderer -> {
int position = adapter.getPosition(renderer.getDes());
if (position != -1) {
setSelection(position);
}
});
return;
}
setSelection(dataList.indexOf(data));
}
});
Expand Down

0 comments on commit a0f1254

Please sign in to comment.