I noticed that the otherwise magnificent Controlconfigdefaults.tbl doesn't have a way to disable certain binds entirely (for example, FotG won't have glide so we don't want the glide-related binds to clutter up the control config screen and confuse people), so I wrote a patch to allow that. Disabling a bind both removes it from the control config screen and prevents the associated action from triggering in-game.
One thing to codereview is whether it's acceptable to not initialize the disabled bool member to false; I didn't, because I didn't find any suitable place to do it. Also, if there are other places in the game where the removed binds might be displayed to the user, I wouldn't mind hearing about them.
Patch:
Index: controlconfig/controlsconfig.cpp
===================================================================
--- controlconfig/controlsconfig.cpp (revision 9143)
+++ controlconfig/controlsconfig.cpp (working copy)
@@ -387,7 +387,7 @@
void control_config_conflict_check()
{
- int i, j, a, b, c, shift = -1, alt = -1;
+ int i, j, shift = -1, alt = -1;
for (i=0; i<CCFG_MAX; i++) {
Conflicts[i].key = Conflicts[i].joy = -1;
@@ -410,11 +410,16 @@
for (i=0; i<CCFG_MAX-1; i++) {
for (j=i+1; j<CCFG_MAX; j++) {
- if (Control_config[i].key_id >= 0) {
- c = 0;
- a = Control_config[i].key_id;
- b = Control_config[j].key_id;
- if (a == b) {
+ if ((Control_config[i].key_id >= 0) && (Control_config[i].key_id == Control_config[j].key_id)) {
+ // If one of the conflicting keys is disabled, then this silently clears
+ // the disabled key to prevent the conflict; a conflict is recorded only
+ // if both keys are enabled
+
+ if (Control_config[i].disabled)
+ Control_config[i].key_id = (short) -1;
+ else if (Control_config[j].disabled)
+ Control_config[j].key_id = (short) -1;
+ else {
Conflicts[i].key = j;
Conflicts[j].key = i;
Conflicts_tabs[ Control_config[i].tab ] = 1;
@@ -423,10 +428,18 @@
}
if ((Control_config[i].joy_id >= 0) && (Control_config[i].joy_id == Control_config[j].joy_id)) {
- Conflicts[i].joy = j;
- Conflicts[j].joy = i;
- Conflicts_tabs[ Control_config[i].tab ] = 1;
- Conflicts_tabs[ Control_config[j].tab ] = 1;
+ // Same as above
+
+ if (Control_config[i].disabled)
+ Control_config[i].joy_id = (short) -1;
+ else if (Control_config[j].disabled)
+ Control_config[j].joy_id = (short) -1;
+ else {
+ Conflicts[i].joy = j;
+ Conflicts[j].joy = i;
+ Conflicts_tabs[ Control_config[i].tab ] = 1;
+ Conflicts_tabs[ Control_config[j].tab ] = 1;
+ }
}
}
}
@@ -454,7 +467,7 @@
Num_cc_lines = y = z = 0;
while (z < CCFG_MAX) {
- if (Control_config[z].tab == Tab) {
+ if (Control_config[z].tab == Tab && !Control_config[z].disabled) {
k = Control_config[z].key_id;
j = Control_config[z].joy_id;
@@ -2117,6 +2130,9 @@
return 0;
}
+ if (Control_config[id].disabled)
+ return 0;
+
if (Control_config[id].type == CC_TYPE_CONTINUOUS) {
if (joy_down(Control_config[id].joy_id) || joy_down_count(Control_config[id].joy_id, 1)) {
control_used(id);
Index: controlconfig/controlsconfig.h
===================================================================
--- controlconfig/controlsconfig.h (revision 9143)
+++ controlconfig/controlsconfig.h (working copy)
@@ -46,6 +46,7 @@
short key_id; // actual key bound to action
short joy_id; // joystick button bound to action
int used; // has control been used yet in mission? If so, this is the timestamp
+ bool disabled; // whether this action should be available at all
} config_item;
/**
Index: controlconfig/controlsconfigcommon.cpp
===================================================================
--- controlconfig/controlsconfigcommon.cpp (revision 9143)
+++ controlconfig/controlsconfigcommon.cpp (working copy)
@@ -625,6 +625,14 @@
if (optional_string("$Type:"))
{stuff_string(szTempBuffer, F_NAME, iBufferLength);
r_ccConfig.type = (char)mEnumNameToVal[szTempBuffer];}
+
+ if (optional_string("+Disable")) {
+ r_ccConfig.key_id = (short)-1;
+ r_ccConfig.joy_id = (short)-1;
+
+ r_ccConfig.disabled = true;
+ } else
+ r_ccConfig.disabled = false;
// Nerf the buffer now.
szTempBuffer[0] = '\0';
Index: fred2/sexp_tree.cpp
===================================================================
--- fred2/sexp_tree.cpp (revision 9143)
+++ fred2/sexp_tree.cpp (working copy)
@@ -5476,7 +5476,7 @@
sexp_list_item head;
for (i=0; i<CCFG_MAX; i++) {
- if (Control_config[i].key_default > 0) {
+ if (Control_config[i].key_default > 0 && !Control_config[i].disabled) {
head.add_data_dup(textify_scancode(Control_config[i].key_default));
}
}
Index: io/keycontrol.cpp
===================================================================
--- io/keycontrol.cpp (revision 9143)
+++ io/keycontrol.cpp (working copy)
@@ -2040,6 +2040,9 @@
{
Assert(n >= 0);
+ if (Control_config[n].disabled)
+ return 0;
+
// check if the button has been set to be ignored by a SEXP
if (Ignored_keys[n]) {
if (Ignored_keys[n] > 0) {
Example tabling:
#ControlConfigOverride
$Bind Name: Cycle Forward Primary Weapon
+Disable
#End