Skip to content

Commit

Permalink
[MiiSelector] added default selection for Miis
Browse files Browse the repository at this point in the history
  • Loading branch information
amwatson committed Jan 21, 2024
1 parent 848b5cb commit 9b159ea
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,11 @@ private static void OnCoreErrorImpl(String title, String message) {

if (ErrorMessageLayer.instance != null) {
ErrorMessageLayer.showErrorWindow(title, message);
Log.error("[NativeLibrary] Core error: " + title + ": " + message);
} else {
assert !(emulationActivity instanceof VrActivity);
} else if (!(emulationActivity instanceof VrActivity)) {
CoreErrorDialogFragment fragment = CoreErrorDialogFragment.newInstance(title, message);
fragment.show(emulationActivity.getSupportFragmentManager(), "coreError");
} else {
Log.error("[NativeLibrary] Core error: " + title + ": " + message);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,17 @@
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;

import org.citra.citra_emu.NativeLibrary;
import org.citra.citra_emu.R;
import org.citra.citra_emu.activities.EmulationActivity;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Objects;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.DialogFragment;

import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Objects;
import org.citra.citra_emu.NativeLibrary;
import org.citra.citra_emu.R;
import org.citra.citra_emu.activities.EmulationActivity;

public final class MiiSelector {
public static class MiiSelectorConfig implements java.io.Serializable {
Expand Down Expand Up @@ -58,8 +54,8 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
final Activity emulationActivity = Objects.requireNonNull(getActivity());

MiiSelectorConfig config =
Objects.requireNonNull((MiiSelectorConfig) Objects.requireNonNull(getArguments())
.getSerializable("config"));
Objects.requireNonNull((MiiSelectorConfig)Objects.requireNonNull(getArguments())
.getSerializable("config"));

// Note: we intentionally leave out the Standard Mii in the native code so that
// the string can get translated
Expand All @@ -68,24 +64,22 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
list.addAll(Arrays.asList(config.mii_names));

final int initialIndex = config.initially_selected_mii_index < list.size()
? (int) config.initially_selected_mii_index
: 0;
? (int)config.initially_selected_mii_index
: 0;
data.index = initialIndex;
MaterialAlertDialogBuilder builder =
new MaterialAlertDialogBuilder(emulationActivity)
.setTitle(config.title.isEmpty()
? emulationActivity.getString(R.string.mii_selector)
: config.title)
.setSingleChoiceItems(list.toArray(new String[]{}), initialIndex,
(dialog, which) -> {
data.index = which;
})
.setPositiveButton(android.R.string.ok, (dialog, which) -> {
data.return_code = 0;
synchronized (finishLock) {
finishLock.notifyAll();
}
});
new MaterialAlertDialogBuilder(emulationActivity)
.setTitle(config.title.isEmpty()
? emulationActivity.getString(R.string.mii_selector)
: config.title)
.setSingleChoiceItems(list.toArray(new String[] {}), initialIndex,
(dialog, which) -> { data.index = which; })
.setPositiveButton(android.R.string.ok, (dialog, which) -> {
data.return_code = 0;
synchronized (finishLock) {
finishLock.notifyAll();
}
});
if (config.enable_cancel_button) {
builder.setNegativeButton(android.R.string.cancel, (dialog, which) -> {
data.return_code = 1;
Expand All @@ -111,16 +105,34 @@ private static void ExecuteImpl(MiiSelectorConfig config) {
fragment.show(emulationActivity.getSupportFragmentManager(), "mii_selector");
}

public static MiiSelectorData Execute(MiiSelectorConfig config) {
NativeLibrary.sEmulationActivity.get().runOnUiThread(() -> ExecuteImpl(config));
// FIXME VR does not currently implement Mii selection. Pick a default Mii
// or one the user has selected previously.
private static void vrExecuteImpl(MiiSelectorConfig config) {
data = new MiiSelectorData(0, 0);
ArrayList<String> list = new ArrayList<>();
list.add(NativeLibrary.sEmulationActivity.get().getString(R.string.standard_mii));
list.addAll(Arrays.asList(config.mii_names));

final int initialIndex = config.initially_selected_mii_index < list.size()
? (int)config.initially_selected_mii_index
: 0;
data.index = initialIndex;
data.return_code = 0;
}

synchronized (finishLock) {
try {
finishLock.wait();
} catch (Exception ignored) {
public static MiiSelectorData Execute(MiiSelectorConfig config) {
if (NativeLibrary.sEmulationActivity.get() instanceof org.citra.citra_emu.vr.VrActivity) {
vrExecuteImpl(config);
} else {
NativeLibrary.sEmulationActivity.get().runOnUiThread(() -> ExecuteImpl(config));

synchronized (finishLock) {
try {
finishLock.wait();
} catch (Exception ignored) {
}
}
}

return data;
}
}

0 comments on commit 9b159ea

Please sign in to comment.