DEADSOFTWARE

Movement: Improve and simplify WASD control
authorStas'M <x86corez@gmail.com>
Sat, 6 Oct 2018 15:34:47 +0000 (18:34 +0300)
committerStas'M <x86corez@gmail.com>
Sat, 6 Oct 2018 15:34:47 +0000 (18:34 +0300)
src/editor/f_main.pas
src/editor/g_map.pas

index ea7b4a9f7ed7e9e06909419ab9de7680ff8e377d..339fbcf095c2bde9e415b606f646037c78786c43 100644 (file)
@@ -442,7 +442,6 @@ var
   MouseRDown: Boolean;
   MouseLDownPos: Types.TPoint;
   MouseRDownPos: Types.TPoint;
-  WASDOffset: TPoint;
 
   SelectFlag: Byte = SELECTFLAG_NONE;
   MouseAction: Byte = MOUSEACTION_NONE;
@@ -4108,10 +4107,8 @@ begin
       if MouseAction = MOUSEACTION_MOVEOBJ then
         begin
           MoveSelectedObjects(ssShift in Shift, ssCtrl in Shift,
-                              MousePos.X-LastMovePoint.X+WASDOffset.X,
-                              MousePos.Y-LastMovePoint.Y+WASDOffset.Y);
-          WASDOffset.X := 0;
-          WASDOffset.Y := 0;
+                              MousePos.X-LastMovePoint.X,
+                              MousePos.Y-LastMovePoint.Y);
         end
       else
       // Меняем размер выделенного объекта:
@@ -4120,10 +4117,8 @@ begin
           if (SelectedObjectCount = 1) and
              (SelectedObjects[GetFirstSelected].Live) then
           begin
-            dWidth := MousePos.X-LastMovePoint.X+WASDOffset.X;
-            dHeight := MousePos.Y-LastMovePoint.Y+WASDOffset.Y;
-            WASDOffset.X := 0;
-            WASDOffset.Y := 0;
+            dWidth := MousePos.X-LastMovePoint.X;
+            dHeight := MousePos.Y-LastMovePoint.Y;
 
             case ResizeType of
               RESIZETYPE_VERTICAL: dWidth := 0;
@@ -4135,11 +4130,10 @@ begin
               RESIZEDIR_LEFT: dWidth := -dWidth;
             end;
 
-            ResizeObject(SelectedObjects[GetFirstSelected].ObjectType,
-                         SelectedObjects[GetFirstSelected].ID,
-                         dWidth, dHeight, ResizeDirection);
-
-            LastMovePoint := MousePos;
+            if ResizeObject(SelectedObjects[GetFirstSelected].ObjectType,
+                           SelectedObjects[GetFirstSelected].ID,
+                           dWidth, dHeight, ResizeDirection) then
+              LastMovePoint := MousePos;
           end;
         end;
   end;
@@ -4382,7 +4376,7 @@ begin
               Inc(MouseLDownPos.y, DotStep);
               Inc(MouseRDownPos.y, DotStep);
             end;
-            Dec(WASDOffset.Y, DotStep);
+            Inc(LastMovePoint.Y, DotStep);
             RenderPanelMouseMove(Sender, Shift, RenderMousePos().X, RenderMousePos().Y);
           end;
           Position := IfThen(Position > DotStep, Position-DotStep, 0);
@@ -4398,7 +4392,7 @@ begin
               Dec(MouseLDownPos.y, DotStep);
               Dec(MouseRDownPos.y, DotStep);
             end;
-            Inc(WASDOffset.Y, DotStep);
+            Dec(LastMovePoint.Y, DotStep);
             RenderPanelMouseMove(Sender, Shift, RenderMousePos().X, RenderMousePos().Y);
           end;
           Position := IfThen(Position+DotStep < Max, Position+DotStep, Max);
@@ -4418,7 +4412,7 @@ begin
               Inc(MouseLDownPos.x, DotStep);
               Inc(MouseRDownPos.x, DotStep);
             end;
-            Dec(WASDOffset.X, DotStep);
+            Inc(LastMovePoint.X, DotStep);
             RenderPanelMouseMove(Sender, Shift, RenderMousePos().X, RenderMousePos().Y);
           end;
           Position := IfThen(Position > DotStep, Position-DotStep, 0);
@@ -4434,7 +4428,7 @@ begin
               Dec(MouseLDownPos.x, DotStep);
               Dec(MouseRDownPos.x, DotStep);
             end;
-            Inc(WASDOffset.X, DotStep);
+            Dec(LastMovePoint.X, DotStep);
             RenderPanelMouseMove(Sender, Shift, RenderMousePos().X, RenderMousePos().Y);
           end;
           Position := IfThen(Position+DotStep < Max, Position+DotStep, Max);
index 008c1a49ae09f0740e6c03f38beed5fbcbbe2f79..4c94a1938a170069bfe2d38815bf10d5de605380 100644 (file)
@@ -221,7 +221,7 @@ function  ObjectCollideLevel(fID: DWORD; ObjectType: Byte; dX, dY: Integer): Boo
 function  ObjectCollide(ObjectType: Byte; ID: DWORD; fX, fY: Integer; fWidth, fHeight: Word): Boolean;
 function  ObjectGetRect(ObjectType: Byte; ID: DWORD): TRectWH;
 procedure MoveObject(ObjectType: Byte; ID: DWORD; dX, dY: Integer);
-procedure ResizeObject(ObjectType: Byte; ID: DWORD; dWidth, dHeight: Integer; ResizeDir: Byte);
+function ResizeObject(ObjectType: Byte; ID: DWORD; dWidth, dHeight: Integer; ResizeDir: Byte): Boolean;
 function  ObjectSelected(ObjectType: Byte; ID: DWORD): Boolean;
 
 function  GetPanelName(PanelType: Word): String;
@@ -864,8 +864,9 @@ begin
   end;
 end;
 
-procedure ResizeObject(ObjectType: Byte; ID: DWORD; dWidth, dHeight: Integer; ResizeDir: Byte);
+function ResizeObject(ObjectType: Byte; ID: DWORD; dWidth, dHeight: Integer; ResizeDir: Byte): Boolean;
 begin
+  Result := True;
   case ObjectType of
     OBJECT_PANEL:
       with gPanels[ID] do
@@ -875,6 +876,7 @@ begin
         else
           begin
             Width := 0;
+            Result := False;
             Exit;
           end;
    
@@ -883,6 +885,7 @@ begin
         else
           begin
             Height := 0;
+            Result := False;
             Exit;
           end;
 
@@ -903,6 +906,7 @@ begin
         else
           begin
             Width := 0;
+            Result := False;
             Exit;
           end;
 
@@ -911,6 +915,7 @@ begin
         else
           begin
             Height := 0;
+            Result := False;
             Exit;
           end;