general uKey refactor in preparaiton of two new shortcuts 0.9.15
authorkoda
Fri, 14 Jan 2011 00:31:21 +0100
branch0.9.15
changeset 4744 ecc2c757d0df
parent 4742 0317c797195a
child 4746 3ae448aebe7e
general uKey refactor in preparaiton of two new shortcuts
hedgewars/hwengine.pas
hedgewars/uCommandHandlers.pas
hedgewars/uKeys.pas
hedgewars/uVariables.pas
--- a/hedgewars/hwengine.pas	Thu Jan 13 04:25:20 2011 +0100
+++ b/hedgewars/hwengine.pas	Fri Jan 14 00:31:21 2011 +0100
@@ -156,8 +156,8 @@
                         cHasFocus:= true;
 {$ELSE}
                     KeyPressChat(event.key.keysym.unicode);
-                SDL_MOUSEBUTTONDOWN: if event.button.button = SDL_BUTTON_WHEELDOWN then uKeys.wheelDown:= true;
-                SDL_MOUSEBUTTONUP: if event.button.button = SDL_BUTTON_WHEELUP then uKeys.wheelUp:= true;
+                SDL_MOUSEBUTTONDOWN: if event.button.button = SDL_BUTTON_WHEELDOWN then wheelDown:= true;
+                SDL_MOUSEBUTTONUP: if event.button.button = SDL_BUTTON_WHEELUP then wheelUp:= true;
                 SDL_ACTIVEEVENT:
                     if (event.active.state and SDL_APPINPUTFOCUS) <> 0 then
                         cHasFocus:= event.active.gain = 1;
--- a/hedgewars/uCommandHandlers.pas	Thu Jan 13 04:25:20 2011 +0100
+++ b/hedgewars/uCommandHandlers.pas	Fri Jan 14 00:31:21 2011 +0100
@@ -32,6 +32,13 @@
         GameState:= prevGState
 end;
 
+procedure chForceQuit(var s: shortstring);
+begin
+    s:= s; // avoid compiler hint
+    SendIPC('Q');
+    GameState:= gsExit
+end;
+
 procedure chConfirm(var s: shortstring);
 begin
 s:= s; // avoid compiler hint
@@ -582,6 +589,7 @@
     RegisterVariable('grave'   , vtCommand, @chGrave        , false);
     RegisterVariable('hat'     , vtCommand, @chSetHat       , false);
     RegisterVariable('quit'    , vtCommand, @chQuit         , true );
+    RegisterVariable('forcequit', vtCommand, @chForceQuit   , true );
     RegisterVariable('confirm' , vtCommand, @chConfirm      , true );
     RegisterVariable('+speedup', vtCommand, @chSpeedup_p    , true );
     RegisterVariable('-speedup', vtCommand, @chSpeedup_m    , true );
--- a/hedgewars/uKeys.pas	Thu Jan 13 04:25:20 2011 +0100
+++ b/hedgewars/uKeys.pas	Fri Jan 14 00:31:21 2011 +0100
@@ -40,47 +40,10 @@
 procedure ControllerHatEvent(joy, hat, value: Byte);
 procedure ControllerButtonEvent(joy, button: Byte; pressed: Boolean);
 
-var hideAmmoMenu: boolean;
-    wheelUp: boolean;
-    wheelDown: boolean;
-
-    ControllerNumControllers: Integer;
-    ControllerEnabled: Integer;
-    ControllerNumAxes: array[0..5] of Integer;
-    //ControllerNumBalls: array[0..5] of Integer;
-    ControllerNumHats: array[0..5] of Integer;
-    ControllerNumButtons: array[0..5] of Integer;
-    ControllerAxes: array[0..5] of array[0..19] of Integer;
-    //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;
-
-    DefaultBinds, CurrentBinds: TBinds;
-
-    coeff: LongInt;
-{$IFDEF HWLIBRARY}
-    leftClick: boolean;
-    middleClick: boolean;
-    rightClick: boolean;
-
-    upKey: boolean;
-    downKey: boolean;
-    rightKey: boolean;
-    leftKey: boolean;
-    preciseKey: boolean;
-
-    backspaceKey: boolean;
-    spaceKey: boolean;
-    enterKey: boolean;
-    tabKey: boolean;
-
-    chatAction: boolean;
-    pauseAction: boolean;
-
 {$IFDEF IPHONEOS}
 procedure setiPhoneBinds;
 {$ENDIF}
-{$ENDIF}
+
 implementation
 uses uConsole, uCommands, uMisc, uVariables, uConsts, uUtils, uDebug;
 
@@ -109,7 +72,7 @@
 
 // move cursor/camera
 // TODO: Scale on screen dimensions and/or axis value (game controller)?
-movecursor(coeff * CursorMovementX, coeff * CursorMovementY);
+movecursor(5 * CursorMovementX, 5 * CursorMovementY);
 
 k:= SDL_GetMouseState(nil, nil);
 
@@ -139,8 +102,7 @@
 
 {$IFDEF IPHONEOS}
 setiPhoneBinds();
-{$ENDIF}
-
+{$ELSE}
 // Controller(s)
 k:= j; // should we test k for hitting the limit? sounds rather unlikely to ever reach it
 for j:= 0 to Pred(ControllerNumControllers) do
@@ -165,6 +127,18 @@
         inc(k, 1);
         end;
     end;
+{$ENDIF}
+
+// ctrl/cmd + w/q to close engine and/or frontend
+{$IFDEF DARWIN}
+    if ((tkbdn[KeyNameToCode('left_meta')] = 1) or (tkbdn[KeyNameToCode('right_meta')] = 1)) then
+{$ELSE}
+    if ((tkbdn[KeyNameToCode('left_ctrl')] = 1) or (tkbdn[KeyNameToCode('right_ctrl')] = 1)) then
+{$ENDIF}
+    begin
+        if tkbdn[KeyNameToCode('q')] = 1 then writelntoconsole ('cmd+q pressed')
+        else if tkbdn[KeyNameToCode('w')] = 1 then writelntoconsole ('cmd+w pressed')
+    end;
 
 // now process strokes
 for i:= 0 to cKeyMaxIndex do
@@ -222,8 +196,7 @@
 
 {$IFDEF IPHONEOS}
 setiPhoneBinds();
-{$ENDIF}
-
+{$ELSE}
 // Controller(s)
 k:= j; // should we test k for hitting the limit? sounds rather unlikely to ever reach it
 for j:= 0 to Pred(ControllerNumControllers) do
@@ -248,6 +221,7 @@
         inc(k, 1);
         end;
     end;
+{$ENDIF}
 
 for t:= 0 to cKeyMaxIndex do
     tkbd[i]:= tkbdn[i]
@@ -350,6 +324,7 @@
 DefaultBinds[KeyNameToCode('right')]:= '+right';
 DefaultBinds[KeyNameToCode('left_shift')]:= '+precise';
 {$ENDIF}
+DefaultBinds[1000]:= 'forcequit';
 
 for i:= 1 to 10 do DefaultBinds[KeyNameToCode('f'+IntToStr(i))]:= 'slot '+IntToStr(i);
 
@@ -502,7 +477,6 @@
 begin
     wheelUp:= false;
     wheelDown:= false;
-    coeff:= 5;
 {$IFDEF HWLIBRARY}
     // this function is called by HW_allKeysUp so be careful
 
--- a/hedgewars/uVariables.pas	Thu Jan 13 04:25:20 2011 +0100
+++ b/hedgewars/uVariables.pas	Fri Jan 14 00:31:21 2011 +0100
@@ -2109,7 +2109,6 @@
 
     DefaultBinds, CurrentBinds: TBinds;
 
-    coeff: LongInt;
 {$IFDEF HWLIBRARY}
     leftClick: boolean;
     middleClick: boolean;