hedgewars/uInputHandler.pas
changeset 13132 52178e8ffdfc
parent 13131 f10f4bf5f84d
child 13343 93325e13d329
equal deleted inserted replaced
13131:f10f4bf5f84d 13132:52178e8ffdfc
   337 
   337 
   338     code:= KeyNameToCode(key);
   338     code:= KeyNameToCode(key);
   339 
   339 
   340     checkFails(code >= 0, 'unknown key', true);
   340     checkFails(code >= 0, 'unknown key', true);
   341 
   341 
   342     inc(binds.lastIndex);
   342     if binds.indices[code] > 0 then
   343     binds.indices[code]:= binds.lastIndex;
   343     begin
   344     binds.binds[binds.lastIndex]:= value
   344         binds.binds[binds.indices[code]]:= value
       
   345     end
       
   346     else begin
       
   347         inc(binds.lastIndex);
       
   348         binds.indices[code]:= binds.lastIndex;
       
   349         binds.binds[binds.indices[code]]:= value
       
   350     end;
   345 end;
   351 end;
   346 
   352 
   347 procedure InitDefaultBinds;
   353 procedure InitDefaultBinds;
   348 var i: Longword;
   354 var i: Longword;
   349 begin
   355 begin
   647 end;
   653 end;
   648 
   654 
   649 
   655 
   650 procedure addBind(var binds: TBinds; var id: shortstring);
   656 procedure addBind(var binds: TBinds; var id: shortstring);
   651 var KeyName, Modifier, tmp: shortstring;
   657 var KeyName, Modifier, tmp: shortstring;
   652     i, code, b: LongInt;
   658     i, newCode, code, b: LongInt;
   653 begin
   659 begin
   654 KeyName:= '';
   660     KeyName:= '';
   655 Modifier:= '';
   661     Modifier:= '';
   656 
   662 
   657 if(Pos('mod:', id) <> 0)then
   663     if(Pos('mod:', id) <> 0)then
       
   664         begin
       
   665         tmp:= '';
       
   666         SplitBySpace(id, tmp);
       
   667         Modifier:= id;
       
   668         id:= tmp;
       
   669         end;
       
   670 
       
   671     SplitBySpace(id, KeyName);
       
   672     if KeyName[1]='"' then
       
   673         Delete(KeyName, 1, 1);
       
   674     if KeyName[byte(KeyName[0])]='"' then
       
   675         Delete(KeyName, byte(KeyName[0]), 1);
       
   676     b:= KeyNameToCode(id, Modifier);
       
   677     if b = 0 then
       
   678         OutError(errmsgUnknownVariable + ' "' + id + '"', false)
       
   679     else
   658     begin
   680     begin
   659     tmp:= '';
   681         // add bind: first check if this cmd is already bound, and remove old bind
   660     SplitBySpace(id, tmp);
   682         i:= Low(binds.binds);
   661     Modifier:= id;
   683         while (i <= High(binds.binds)) and (binds.binds[i] <> KeyName) do
   662     id:= tmp;
   684             inc(i);
   663     end;
   685 
   664 
   686         if (i <= High(binds.binds)) then
   665 SplitBySpace(id, KeyName);
   687         begin
   666 if KeyName[1]='"' then
   688             code:= Low(binds.indices);
   667     Delete(KeyName, 1, 1);
   689             while (code <= High(binds.indices)) and (binds.indices[code] <> i) do
   668 if KeyName[byte(KeyName[0])]='"' then
   690                 inc(code);
   669     Delete(KeyName, byte(KeyName[0]), 1);
   691 
   670 b:= KeyNameToCode(id, Modifier);
   692             checkFails(code <= High(binds.indices), 'binds registry inconsistency', true);
   671 if b = 0 then
   693 
   672     OutError(errmsgUnknownVariable + ' "' + id + '"', false)
   694             binds.indices[code]:= 0;
   673 else
   695             binds.binds[i]:= ''
   674 begin
   696         end;
   675     // add bind: first check if this cmd is already bound, and remove old bind
   697 
   676     i:= Low(binds.binds);
   698         if binds.indices[b] > 0 then
   677     while (i <= High(binds.binds)) and (binds.binds[i] <> KeyName) do
   699             newCode:= binds.indices[b]
   678         inc(i);
   700         else if i >= High(binds.binds) then
   679 
   701             begin
   680     if (i <= High(binds.binds)) then
   702                 inc(binds.lastIndex);
   681     begin
   703                 checkFails(binds.lastIndex < High(binds.binds), 'too many binds', true);
   682         code:= Low(binds.indices);
   704                 newCode:= binds.lastIndex
   683         while (code <= High(binds.indices)) and (binds.indices[code] <> i) do
   705             end else
   684             inc(code);
   706                 newCode:= i;
   685 
   707 
   686         checkFails(code <= High(binds.indices), 'binds registry inconsistency', true);
   708 
   687 
   709     binds.indices[b]:= newCode;
   688         if allOk then
   710     binds.binds[binds.indices[b]]:= KeyName
   689             binds.indices[code]:= 0
       
   690     end else
       
   691     begin
       
   692     inc(binds.lastIndex);
       
   693     checkFails(binds.lastIndex < High(binds.binds), 'too many binds', true);
       
   694     i:= binds.lastIndex
       
   695     end;
       
   696 
       
   697     binds.indices[b]:= i;
       
   698     binds.binds[i]:= KeyName
       
   699     end
   711     end
   700 end;
   712 end;
   701 
   713 
   702 // Bind that isn't a team bind, but overrides defaultbinds.
   714 // Bind that isn't a team bind, but overrides defaultbinds.
   703 procedure chDefaultBind(var id: shortstring);
   715 procedure chDefaultBind(var id: shortstring);