hedgewars/uInputHandler.pas
branchflibqtfrontend
changeset 8363 0b4ac686fc44
parent 8346 3443e0de2c9d
child 8370 0c79946e96f8
--- a/hedgewars/uInputHandler.pas	Tue Dec 18 20:48:37 2012 +0400
+++ b/hedgewars/uInputHandler.pas	Fri Jan 04 21:44:40 2013 +0400
@@ -39,6 +39,7 @@
 
 procedure SetBinds(var binds: TBinds);
 procedure SetDefaultBinds;
+procedure chDefaultBind(var id: shortstring);
 
 procedure ControllerInit;
 procedure ControllerAxisEvent(joy, axis: Byte; value: Integer);
@@ -70,6 +71,7 @@
     //ControllerBalls: array[0..5] of array[0..19] of array[0..1] of Integer;
     ControllerHats: array[0..5] of array[0..19] of Byte;
     ControllerButtons: array[0..5] of array[0..19] of Byte;
+    usingDBinds: boolean;
 
 function  KeyNameToCode(name: shortstring): LongInt; inline;
 begin
@@ -329,9 +331,9 @@
     binds:= binds; // avoid hint
     CurrentBinds:= DefaultBinds;
 {$ELSE}
-for t:= 0 to cKbdMaxIndex do
-    if (CurrentBinds[t] <> binds[t]) and tkbd[t] then
-        ProcessKey(t, False);
+    for t:= 0 to cKbdMaxIndex do
+        if (CurrentBinds[t] <> binds[t]) and tkbd[t] then
+            ProcessKey(t, False);
 
     CurrentBinds:= binds;
 {$ENDIF}
@@ -450,8 +452,45 @@
     ProcessKey(k +  ControllerNumAxes[joy]*2 + ControllerNumHats[joy]*4 + button, pressed);
 end;
 
+// Bind that isn't a team bind, but overrides defaultbinds.
+// When first called, DefaultBinds is cleared, because we assume we are getting a full list of dbinds.
+procedure chDefaultBind(var id: shortstring);
+var KeyName, Modifier, tmp: shortstring;
+    b: LongInt;
+begin
+KeyName:= '';
+Modifier:= '';
+
+if (not usingDBinds) then
+    begin
+    usingDBinds:= true;
+    FillByte(DefaultBinds, SizeOf(DefaultBinds), 0);
+    end;
+
+if (Pos('mod:', id) <> 0) then
+    begin
+    tmp:= '';
+    SplitBySpace(id, tmp);
+    Modifier:= id;
+    id:= tmp;
+    end;
+
+SplitBySpace(id, KeyName);
+if KeyName[1]='"' then
+    Delete(KeyName, 1, 1);
+if KeyName[byte(KeyName[0])]='"' then
+    Delete(KeyName, byte(KeyName[0]), 1);
+b:= KeyNameToCode(id, Modifier);
+if b = 0 then
+    OutError(errmsgUnknownVariable + ' "' + id + '"', false)
+else
+    DefaultBinds[b]:= KeyName;
+end;
+
 procedure initModule;
 begin
+    usingDBinds:= false;
+    RegisterVariable('dbind', @chDefaultBind, true );
 end;
 
 procedure freeModule;