From dbfdb5927b81db33482df4ac84740e64966eaf19 Mon Sep 17 00:00:00 2001 From: ac-stef Date: Fri, 25 Mar 2016 17:27:17 +0100 Subject: [PATCH] omit unchanged default binds from saved.cfg omitunchangeddefaultbinds n 0 print 1 print, but commented out 2 omit The new var _defaultbinds is used to mark default binds in resetbinds.cfg. DOCREF omitunchangeddefaultbinds --- config/resetbinds.cfg | 4 ++++ source/src/console.cpp | 18 +++++++++++++----- source/src/protos.h | 4 ++-- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/config/resetbinds.cfg b/config/resetbinds.cfg index 9c9aaf5e..8f746f58 100644 --- a/config/resetbinds.cfg +++ b/config/resetbinds.cfg @@ -31,6 +31,8 @@ alias key_commandline [ saycommand / ] alias key_prevweapon [ weapon (prevweapon) ] alias key_editmeta2 [ editmeta2down = 1 ; onrelease [ editmeta2down = 0 ] ] +_defaultbinds 1 // do not save the following binds to saved.cfg + bind MOUSE1 attack bind MOUSE2 altaction editbind MOUSE2 [ showmenu editing ] @@ -226,6 +228,8 @@ bind SYSREQ [] bind BREAK [] bind MENU [] +_defaultbinds 0 + omitunchangeddefaults 1 // switch to a clean saved.cfg when keybinds are reset persistidents 1 diff --git a/source/src/console.cpp b/source/src/console.cpp index 4886165e..b0eec651 100644 --- a/source/src/console.cpp +++ b/source/src/console.cpp @@ -211,12 +211,17 @@ COMMAND(findkeycode, "s"); keym *keypressed = NULL; char *keyaction = NULL; +VAR(_defaultbinds, 0, 0, 1); + bool bindkey(keym *km, const char *action, int type) { - if(!km) return false; - if(type < keym::ACTION_DEFAULT || type >= keym::NUMACTIONS) { conoutf("invalid bind type \"%i\"", type); return false; } - if(!keypressed || keyaction!=km->actions[type]) delete[] km->actions[type]; - km->actions[type] = newstring(action); + if(!km || type < keym::ACTION_DEFAULT || type >= keym::NUMACTIONS) return false; + if(strcmp(action, km->actions[type])) + { + if(!keypressed || keyaction!=km->actions[type]) delete[] km->actions[type]; + km->actions[type] = newstring(action); + km->unchangeddefault[type] = _defaultbinds != 0; + } return true; } @@ -601,12 +606,15 @@ char *getcurcommand() return saycommandon ? cmdline.buf : NULL; } +VARP(omitunchangeddefaultbinds, 0, 1, 2); + void writebinds(stream *f) { loopv(keyms) { keym *km = &keyms[i]; - loopj(3) if(*km->actions[j]) f->printf("%s \"%s\" %s\n", keycmd(j), km->name, escapestring(km->actions[j])); + loopj(3) if(*km->actions[j] && (!km->unchangeddefault[j] || omitunchangeddefaultbinds < 2)) + f->printf("%s%s \"%s\" %s\n", km->unchangeddefault[j] && omitunchangeddefaultbinds ? "//" : "", keycmd(j), km->name, escapestring(km->actions[j])); } } diff --git a/source/src/protos.h b/source/src/protos.h index 123fb8b7..18b864bd 100644 --- a/source/src/protos.h +++ b/source/src/protos.h @@ -148,9 +148,9 @@ struct keym }; char *name, *actions[NUMACTIONS]; - bool pressed; + bool pressed, unchangeddefault[NUMACTIONS]; - keym() : code(-1), name(NULL), pressed(false) { loopi(NUMACTIONS) actions[i] = newstring(""); } + keym() : code(-1), name(NULL), pressed(false) { loopi(NUMACTIONS) { actions[i] = newstring(""); unchangeddefault[i] = false; } } ~keym() { DELETEA(name); loopi(NUMACTIONS) DELETEA(actions[i]); } };