Skip to content
Permalink
Browse files
Merge pull request #8975 from JosJuice/android-new-config
Android: Hook up the new config system
  • Loading branch information
JosJuice committed Sep 16, 2020
2 parents e4e5069 + 744c0b1 commit a7b9e68
Show file tree
Hide file tree
Showing 66 changed files with 2,071 additions and 923 deletions.
@@ -335,6 +335,8 @@ public static native void SetMotionSensorsEnabled(boolean accelerometerEnabled,

public static native int DefaultCPUCore();

public static native String GetDefaultGraphicsBackendName();

public static native int GetMaxLogLevel();

public static native void ReloadConfig();
@@ -34,6 +34,8 @@
import org.dolphinemu.dolphinemu.NativeLibrary;
import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.features.settings.model.Settings;
import org.dolphinemu.dolphinemu.features.settings.ui.MenuTag;
import org.dolphinemu.dolphinemu.features.settings.ui.SettingsActivity;
import org.dolphinemu.dolphinemu.features.settings.utils.SettingsFile;
import org.dolphinemu.dolphinemu.fragments.EmulationFragment;
import org.dolphinemu.dolphinemu.fragments.MenuFragment;
@@ -101,7 +103,8 @@ public final class EmulationActivity extends AppCompatActivity
MENU_ACTION_LOAD_SLOT6, MENU_ACTION_EXIT, MENU_ACTION_CHANGE_DISC,
MENU_ACTION_RESET_OVERLAY, MENU_SET_IR_SENSITIVITY, MENU_ACTION_CHOOSE_DOUBLETAP,
MENU_ACTION_SCREEN_ORIENTATION, MENU_ACTION_MOTION_CONTROLS, MENU_ACTION_PAUSE_EMULATION,
MENU_ACTION_UNPAUSE_EMULATION, MENU_ACTION_OVERLAY_CONTROLS})
MENU_ACTION_UNPAUSE_EMULATION, MENU_ACTION_OVERLAY_CONTROLS, MENU_ACTION_SETTINGS_CORE,
MENU_ACTION_SETTINGS_GRAPHICS})
public @interface MenuAction
{
}
@@ -140,6 +143,8 @@ public final class EmulationActivity extends AppCompatActivity
public static final int MENU_ACTION_PAUSE_EMULATION = 31;
public static final int MENU_ACTION_UNPAUSE_EMULATION = 32;
public static final int MENU_ACTION_OVERLAY_CONTROLS = 33;
public static final int MENU_ACTION_SETTINGS_CORE = 34;
public static final int MENU_ACTION_SETTINGS_GRAPHICS = 35;

private static SparseIntArray buttonsActionsMap = new SparseIntArray();

@@ -363,6 +368,13 @@ protected void onStop()
super.onStop();
}

@Override
protected void onDestroy()
{
super.onDestroy();
mSettings.close();
}

@Override
public void onBackPressed()
{
@@ -641,6 +653,14 @@ public void handleMenuAction(@MenuAction int menuAction)
showMotionControlsOptions();
return;

case MENU_ACTION_SETTINGS_CORE:
SettingsActivity.launch(this, MenuTag.CONFIG);
return;

case MENU_ACTION_SETTINGS_GRAPHICS:
SettingsActivity.launch(this, MenuTag.GRAPHICS);
return;

case MENU_ACTION_EXIT:
mEmulationFragment.stopEmulation();
finish();
@@ -855,7 +875,7 @@ private void chooseController()
{
editor.putInt("wiiController", indexSelected);

File wiimoteNewFile = SettingsFile.getSettingsFile(SettingsFile.FILE_NAME_WIIMOTE);
File wiimoteNewFile = SettingsFile.getSettingsFile(Settings.FILE_WIIMOTE);
IniFile wiimoteNewIni = new IniFile(wiimoteNewFile);
wiimoteNewIni.setString("Wiimote1", "Extension",
getResources().getStringArray(R.array.controllersValues)[indexSelected]);
@@ -889,7 +909,7 @@ private void showMotionControlsOptions()
else
mMotionListener.disable();

File wiimoteNewFile = SettingsFile.getSettingsFile(SettingsFile.FILE_NAME_WIIMOTE);
File wiimoteNewFile = SettingsFile.getSettingsFile(Settings.FILE_WIIMOTE);
IniFile wiimoteNewIni = new IniFile(wiimoteNewFile);
wiimoteNewIni.setBoolean("Wiimote1", "IMUIR/Enabled", indexSelected != 1);
wiimoteNewIni.save(wiimoteNewFile);
@@ -156,11 +156,12 @@ public boolean onLongClick(View view)
return true;
}

GamePropertiesDialog fragment =
GamePropertiesDialog
.newInstance(holder.gameFile.getPath(), gameId, holder.gameFile.getPlatform());
GamePropertiesDialog fragment = GamePropertiesDialog.newInstance(holder.gameFile.getPath(),
gameId, holder.gameFile.getRevision(), holder.gameFile.getPlatform());

((FragmentActivity) view.getContext()).getSupportFragmentManager().beginTransaction()
.add(fragment, GamePropertiesDialog.TAG).commit();

return true;
}

@@ -100,9 +100,9 @@ public void onBindViewHolder(ViewHolder viewHolder, Object item)
return true;
}

GamePropertiesDialog fragment =
GamePropertiesDialog.newInstance(holder.gameFile.getPath(), gameId,
holder.gameFile.getPlatform());
GamePropertiesDialog fragment = GamePropertiesDialog.newInstance(holder.gameFile.getPath(),
gameId, holder.gameFile.getRevision(), holder.gameFile.getPlatform());

((FragmentActivity) view.getContext()).getSupportFragmentManager().beginTransaction()
.add(fragment, GamePropertiesDialog.TAG).commit();

@@ -8,15 +8,13 @@
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.DialogFragment;

import org.dolphinemu.dolphinemu.NativeLibrary;
import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.features.settings.model.Settings;
import org.dolphinemu.dolphinemu.features.settings.model.StringSetting;
import org.dolphinemu.dolphinemu.features.settings.ui.MenuTag;
import org.dolphinemu.dolphinemu.features.settings.ui.SettingsActivity;
import org.dolphinemu.dolphinemu.features.settings.utils.SettingsFile;
import org.dolphinemu.dolphinemu.ui.platform.Platform;
import org.dolphinemu.dolphinemu.utils.DirectoryInitialization;
import org.dolphinemu.dolphinemu.utils.IniFile;
import org.dolphinemu.dolphinemu.utils.Log;

import java.io.File;
@@ -26,15 +24,18 @@ public class GamePropertiesDialog extends DialogFragment
public static final String TAG = "GamePropertiesDialog";
public static final String ARG_PATH = "path";
public static final String ARG_GAMEID = "game_id";
public static final String ARG_REVISION = "revision";
public static final String ARG_PLATFORM = "platform";

public static GamePropertiesDialog newInstance(String path, String gameId, int platform)
public static GamePropertiesDialog newInstance(String path, String gameId, int revision,
int platform)
{
GamePropertiesDialog fragment = new GamePropertiesDialog();

Bundle arguments = new Bundle();
arguments.putString(ARG_PATH, path);
arguments.putString(ARG_GAMEID, gameId);
arguments.putInt(ARG_REVISION, revision);
arguments.putInt(ARG_PLATFORM, platform);
fragment.setArguments(arguments);

@@ -50,6 +51,7 @@ public Dialog onCreateDialog(Bundle savedInstanceState)

String path = requireArguments().getString(ARG_PATH);
String gameId = requireArguments().getString(ARG_GAMEID);
int revision = requireArguments().getInt(ARG_REVISION);
int platform = requireArguments().getInt(ARG_PLATFORM);

builder.setTitle(requireContext()
@@ -65,30 +67,28 @@ public Dialog onCreateDialog(Bundle savedInstanceState)
.getSupportFragmentManager(), "game_details");
break;
case 1:
File dolphinFile = SettingsFile.getSettingsFile(SettingsFile.FILE_NAME_DOLPHIN);
IniFile dolphinIni = new IniFile(dolphinFile);
dolphinIni.setString(Settings.SECTION_INI_CORE, SettingsFile.KEY_DEFAULT_ISO,
path);
dolphinIni.save(dolphinFile);

NativeLibrary.ReloadConfig();
Toast.makeText(getContext(), "Default ISO set", Toast.LENGTH_SHORT).show();
try (Settings settings = new Settings())
{
settings.loadSettings(null);
StringSetting.MAIN_DEFAULT_ISO.setString(settings, path);
settings.saveSettings(null, getContext());
}
break;
case 2:
SettingsActivity.launch(getContext(), MenuTag.CONFIG, gameId);
SettingsActivity.launch(getContext(), MenuTag.CONFIG, gameId, revision);
break;
case 3:
SettingsActivity.launch(getContext(), MenuTag.GRAPHICS, gameId);
SettingsActivity.launch(getContext(), MenuTag.GRAPHICS, gameId, revision);
break;
case 4:
SettingsActivity.launch(getContext(), MenuTag.GCPAD_TYPE, gameId);
SettingsActivity.launch(getContext(), MenuTag.GCPAD_TYPE, gameId, revision);
break;
case 5:
// Clear option for GC, Wii controls for else
if (platform == Platform.GAMECUBE.toInt())
clearGameSettings(gameId);
else
SettingsActivity.launch(getActivity(), MenuTag.WIIMOTE, gameId);
SettingsActivity.launch(getActivity(), MenuTag.WIIMOTE, gameId, revision);
break;
case 6:
clearGameSettings(gameId);
@@ -0,0 +1,8 @@
package org.dolphinemu.dolphinemu.features.settings.model;

public interface AbstractBooleanSetting extends AbstractSetting
{
boolean getBoolean(Settings settings);

void setBoolean(Settings settings, boolean newValue);
}
@@ -0,0 +1,8 @@
package org.dolphinemu.dolphinemu.features.settings.model;

public interface AbstractFloatSetting extends AbstractSetting
{
float getFloat(Settings settings);

void setFloat(Settings settings, float newValue);
}
@@ -0,0 +1,8 @@
package org.dolphinemu.dolphinemu.features.settings.model;

public interface AbstractIntSetting extends AbstractSetting
{
int getInt(Settings settings);

void setInt(Settings settings, int newValue);
}
@@ -0,0 +1,33 @@
package org.dolphinemu.dolphinemu.features.settings.model;

public class AbstractLegacySetting implements AbstractSetting
{
protected final String mFile;
protected final String mSection;
protected final String mKey;

public AbstractLegacySetting(String file, String section, String key)
{
mFile = file;
mSection = section;
mKey = key;
}

@Override
public boolean isOverridden(Settings settings)
{
return settings.isGameSpecific() && settings.getSection(mFile, mSection).exists(mKey);
}

@Override
public boolean isRuntimeEditable()
{
return false;
}

@Override
public boolean delete(Settings settings)
{
return settings.getSection(mFile, mSection).delete(mKey);
}
}
@@ -0,0 +1,10 @@
package org.dolphinemu.dolphinemu.features.settings.model;

public interface AbstractSetting
{
boolean isOverridden(Settings settings);

boolean isRuntimeEditable();

boolean delete(Settings settings);
}
@@ -0,0 +1,8 @@
package org.dolphinemu.dolphinemu.features.settings.model;

public interface AbstractStringSetting extends AbstractSetting
{
String getString(Settings settings);

void setString(Settings settings, String newValue);
}
@@ -0,0 +1,52 @@
package org.dolphinemu.dolphinemu.features.settings.model;

public class AdHocBooleanSetting implements AbstractBooleanSetting
{
private final String mFile;
private final String mSection;
private final String mKey;
private final boolean mDefaultValue;

public AdHocBooleanSetting(String file, String section, String key, boolean defaultValue)
{
mFile = file;
mSection = section;
mKey = key;
mDefaultValue = defaultValue;

if (!NativeConfig.isSettingSaveable(file, section, key))
{
throw new IllegalArgumentException("File/section/key is unknown or legacy");
}
}

@Override
public boolean isOverridden(Settings settings)
{
return NativeConfig.isOverridden(mFile, mSection, mKey);
}

@Override
public boolean isRuntimeEditable()
{
return true;
}

@Override
public boolean delete(Settings settings)
{
return NativeConfig.deleteKey(settings.getActiveLayer(), mFile, mSection, mKey);
}

@Override
public boolean getBoolean(Settings settings)
{
return NativeConfig.getBoolean(settings.getActiveLayer(), mFile, mSection, mKey, mDefaultValue);
}

@Override
public void setBoolean(Settings settings, boolean newValue)
{
NativeConfig.setBoolean(settings.getActiveLayer(), mFile, mSection, mKey, newValue);
}
}

0 comments on commit a7b9e68

Please sign in to comment.