DroidFish: Added a configurable button action to set engine options.

This commit is contained in:
Peter Osterlund
2015-05-24 00:31:52 +02:00
parent f284180da8
commit 1435cb0ce2
3 changed files with 41 additions and 23 deletions

View File

@@ -205,6 +205,7 @@ you are not actively using the program.\
<string name="stockfish_engine">Stockfish</string>
<string name="cuckoochess_engine">CuckooChess</string>
<string name="select_engine">Select Engine</string>
<string name="engine_options">Engine Options</string>
<string name="set_engine_options">Set options</string>
<string name="configure_network_engine">Configure Network Engine</string>
<string name="create_network_engine">Create Network Engine</string>
@@ -638,6 +639,7 @@ you are not actively using the program.\
<item>@string/toggle_blind_mode</item>
<item>@string/load_last_file</item>
<item>@string/select_engine</item>
<item>@string/engine_options</item>
</string-array>
<string-array name="button_action_values">
<item></item>
@@ -652,5 +654,6 @@ you are not actively using the program.\
<item>blindMode</item>
<item>loadLastFile</item>
<item>selectEngine</item>
<item>engineOptions</item>
</string-array>
</resources>

View File

@@ -389,7 +389,7 @@
android:title="@string/prefs_button_action_2_title"
android:entryValues="@array/button_action_values"
android:entries="@array/button_action_texts"
android:defaultValue="">
android:defaultValue="engineOptions">
</ListPreference>
<ListPreference
android:key="button_action_custom2_3"

View File

@@ -370,6 +370,15 @@ public class DroidFish extends Activity implements GUIInterface {
showDialog(SELECT_ENGINE_DIALOG_NOMANAGE);
}
});
addAction(new UIAction() {
public String getId() { return "engineOptions"; }
public int getName() { return R.string.engine_options; }
public int getIcon() { return R.raw.custom; }
public boolean enabled() { return canSetEngineOptions(); }
public void run() {
setEngineOptions();
}
});
}
@Override
@@ -2826,20 +2835,9 @@ public class DroidFish extends Activity implements GUIInterface {
List<CharSequence> lst = new ArrayList<CharSequence>();
List<Integer> actions = new ArrayList<Integer>();
lst.add(getString(R.string.select_engine)); actions.add(SELECT_ENGINE);
if (ctrl.computerIdle()) {
UCIOptions uciOpts = ctrl.getUCIOptions();
if (uciOpts != null) {
boolean visible = false;
for (String name : uciOpts.getOptionNames())
if (uciOpts.getOption(name).visible) {
visible = true;
break;
}
if (visible) {
lst.add(getString(R.string.set_engine_options));
actions.add(SET_ENGINE_OPTIONS);
}
}
if (canSetEngineOptions()) {
lst.add(getString(R.string.set_engine_options));
actions.add(SET_ENGINE_OPTIONS);
}
lst.add(getString(R.string.configure_network_engine)); actions.add(CONFIG_NET_ENGINE);
final List<Integer> finalActions = actions;
@@ -2852,15 +2850,9 @@ public class DroidFish extends Activity implements GUIInterface {
removeDialog(SELECT_ENGINE_DIALOG);
showDialog(SELECT_ENGINE_DIALOG);
break;
case SET_ENGINE_OPTIONS: {
Intent i = new Intent(DroidFish.this, EditOptions.class);
UCIOptions uciOpts = ctrl.getUCIOptions();
if (uciOpts != null) {
i.putExtra("org.petero.droidfish.ucioptions", uciOpts);
startActivityForResult(i, RESULT_EDITOPTIONS);
}
case SET_ENGINE_OPTIONS:
setEngineOptions();
break;
}
case CONFIG_NET_ENGINE:
removeDialog(NETWORK_ENGINE_DIALOG);
showDialog(NETWORK_ENGINE_DIALOG);
@@ -2872,6 +2864,29 @@ public class DroidFish extends Activity implements GUIInterface {
return alert;
}
/** Return true if engine UCI options can be set now. */
private final boolean canSetEngineOptions() {
if (!ctrl.computerIdle())
return false;
UCIOptions uciOpts = ctrl.getUCIOptions();
if (uciOpts == null)
return false;
for (String name : uciOpts.getOptionNames())
if (uciOpts.getOption(name).visible)
return true;
return false;
}
/** Start activity to set engine options. */
private final void setEngineOptions() {
Intent i = new Intent(DroidFish.this, EditOptions.class);
UCIOptions uciOpts = ctrl.getUCIOptions();
if (uciOpts != null) {
i.putExtra("org.petero.droidfish.ucioptions", uciOpts);
startActivityForResult(i, RESULT_EDITOPTIONS);
}
}
private final Dialog networkEngineDialog() {
String[] fileNames = findFilesInDirectory(engineDir, new FileNameFilter() {
@Override