mirror of
https://github.com/peterosterlund2/droidfish.git
synced 2025-12-13 01:22:41 +01:00
DroidFish: Added a configurable button action to set engine options.
This commit is contained in:
@@ -205,6 +205,7 @@ you are not actively using the program.\
|
|||||||
<string name="stockfish_engine">Stockfish</string>
|
<string name="stockfish_engine">Stockfish</string>
|
||||||
<string name="cuckoochess_engine">CuckooChess</string>
|
<string name="cuckoochess_engine">CuckooChess</string>
|
||||||
<string name="select_engine">Select Engine</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="set_engine_options">Set options</string>
|
||||||
<string name="configure_network_engine">Configure Network Engine</string>
|
<string name="configure_network_engine">Configure Network Engine</string>
|
||||||
<string name="create_network_engine">Create 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/toggle_blind_mode</item>
|
||||||
<item>@string/load_last_file</item>
|
<item>@string/load_last_file</item>
|
||||||
<item>@string/select_engine</item>
|
<item>@string/select_engine</item>
|
||||||
|
<item>@string/engine_options</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
<string-array name="button_action_values">
|
<string-array name="button_action_values">
|
||||||
<item></item>
|
<item></item>
|
||||||
@@ -652,5 +654,6 @@ you are not actively using the program.\
|
|||||||
<item>blindMode</item>
|
<item>blindMode</item>
|
||||||
<item>loadLastFile</item>
|
<item>loadLastFile</item>
|
||||||
<item>selectEngine</item>
|
<item>selectEngine</item>
|
||||||
|
<item>engineOptions</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -389,7 +389,7 @@
|
|||||||
android:title="@string/prefs_button_action_2_title"
|
android:title="@string/prefs_button_action_2_title"
|
||||||
android:entryValues="@array/button_action_values"
|
android:entryValues="@array/button_action_values"
|
||||||
android:entries="@array/button_action_texts"
|
android:entries="@array/button_action_texts"
|
||||||
android:defaultValue="">
|
android:defaultValue="engineOptions">
|
||||||
</ListPreference>
|
</ListPreference>
|
||||||
<ListPreference
|
<ListPreference
|
||||||
android:key="button_action_custom2_3"
|
android:key="button_action_custom2_3"
|
||||||
|
|||||||
@@ -370,6 +370,15 @@ public class DroidFish extends Activity implements GUIInterface {
|
|||||||
showDialog(SELECT_ENGINE_DIALOG_NOMANAGE);
|
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
|
@Override
|
||||||
@@ -2826,20 +2835,9 @@ public class DroidFish extends Activity implements GUIInterface {
|
|||||||
List<CharSequence> lst = new ArrayList<CharSequence>();
|
List<CharSequence> lst = new ArrayList<CharSequence>();
|
||||||
List<Integer> actions = new ArrayList<Integer>();
|
List<Integer> actions = new ArrayList<Integer>();
|
||||||
lst.add(getString(R.string.select_engine)); actions.add(SELECT_ENGINE);
|
lst.add(getString(R.string.select_engine)); actions.add(SELECT_ENGINE);
|
||||||
if (ctrl.computerIdle()) {
|
if (canSetEngineOptions()) {
|
||||||
UCIOptions uciOpts = ctrl.getUCIOptions();
|
lst.add(getString(R.string.set_engine_options));
|
||||||
if (uciOpts != null) {
|
actions.add(SET_ENGINE_OPTIONS);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
lst.add(getString(R.string.configure_network_engine)); actions.add(CONFIG_NET_ENGINE);
|
lst.add(getString(R.string.configure_network_engine)); actions.add(CONFIG_NET_ENGINE);
|
||||||
final List<Integer> finalActions = actions;
|
final List<Integer> finalActions = actions;
|
||||||
@@ -2852,15 +2850,9 @@ public class DroidFish extends Activity implements GUIInterface {
|
|||||||
removeDialog(SELECT_ENGINE_DIALOG);
|
removeDialog(SELECT_ENGINE_DIALOG);
|
||||||
showDialog(SELECT_ENGINE_DIALOG);
|
showDialog(SELECT_ENGINE_DIALOG);
|
||||||
break;
|
break;
|
||||||
case SET_ENGINE_OPTIONS: {
|
case SET_ENGINE_OPTIONS:
|
||||||
Intent i = new Intent(DroidFish.this, EditOptions.class);
|
setEngineOptions();
|
||||||
UCIOptions uciOpts = ctrl.getUCIOptions();
|
|
||||||
if (uciOpts != null) {
|
|
||||||
i.putExtra("org.petero.droidfish.ucioptions", uciOpts);
|
|
||||||
startActivityForResult(i, RESULT_EDITOPTIONS);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
case CONFIG_NET_ENGINE:
|
case CONFIG_NET_ENGINE:
|
||||||
removeDialog(NETWORK_ENGINE_DIALOG);
|
removeDialog(NETWORK_ENGINE_DIALOG);
|
||||||
showDialog(NETWORK_ENGINE_DIALOG);
|
showDialog(NETWORK_ENGINE_DIALOG);
|
||||||
@@ -2872,6 +2864,29 @@ public class DroidFish extends Activity implements GUIInterface {
|
|||||||
return alert;
|
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() {
|
private final Dialog networkEngineDialog() {
|
||||||
String[] fileNames = findFilesInDirectory(engineDir, new FileNameFilter() {
|
String[] fileNames = findFilesInDirectory(engineDir, new FileNameFilter() {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user