DEADSOFTWARE

Movement: Implement WASD move/resize
[d2df-editor.git] / src / editor / f_main.pas
index 8e186cee06aa4e4f8d85c5adc6b3c56b7c1b13c2..63f31f4a83d7edc3aaa77513e34b171e75e1f2e1 100644 (file)
@@ -311,7 +311,7 @@ var
 
   LayerEnabled: Array [LAYER_BACK..LAYER_TRIGGERS] of Boolean =
     (True, True, True, True, True, True, True, True, True);
-  PreviewMode: Boolean = False;
+  PreviewMode: Byte = 0;
   gLanguage: String;
 
   FormCaption: String;
@@ -435,6 +435,7 @@ var
   MouseRDown: Boolean;
   MouseLDownPos: Types.TPoint;
   MouseRDownPos: Types.TPoint;
+  WASDOffset: TPoint;
 
   SelectFlag: Byte = SELECTFLAG_NONE;
   MouseAction: Byte = MOUSEACTION_NONE;
@@ -2773,7 +2774,7 @@ begin
   end;
 
 // Рисуем сетку:
-  if DotEnable and (not PreviewMode) then
+  if DotEnable and (PreviewMode = 0) then
   begin
     if DotSize = 2 then
       a := -1
@@ -2790,7 +2791,7 @@ begin
 
 // Превью текстуры:
   if (lbTextureList.ItemIndex <> -1) and (cbPreview.Checked) and
-     (not IsSpecialTextureSel()) and (not PreviewMode) then
+     (not IsSpecialTextureSel()) and (PreviewMode = 0) then
   begin
     if not g_GetTexture(SelectedTexture(), ID) then
       g_GetTexture('NOTEXTURE', ID);
@@ -3982,8 +3983,10 @@ begin
       if MouseAction = MOUSEACTION_MOVEOBJ then
         begin
           MoveSelectedObjects(ssShift in Shift, ssCtrl in Shift,
-                              MousePos.X-LastMovePoint.X,
-                              MousePos.Y-LastMovePoint.Y);
+                              MousePos.X-LastMovePoint.X+WASDOffset.X,
+                              MousePos.Y-LastMovePoint.Y+WASDOffset.Y);
+          WASDOffset.X := 0;
+          WASDOffset.Y := 0;
         end
       else
       // Меняем размер выделенного объекта:
@@ -3992,8 +3995,10 @@ begin
           if (SelectedObjectCount = 1) and
              (SelectedObjects[GetFirstSelected].Live) then
           begin
-            dWidth := MousePos.X-LastMovePoint.X;
-            dHeight := MousePos.Y-LastMovePoint.Y;
+            dWidth := MousePos.X-LastMovePoint.X+WASDOffset.X;
+            dHeight := MousePos.Y-LastMovePoint.Y+WASDOffset.Y;
+            WASDOffset.X := 0;
+            WASDOffset.Y := 0;
 
             case ResizeType of
               RESIZETYPE_VERTICAL: dWidth := 0;
@@ -4203,17 +4208,34 @@ begin
 
     if not (ssCtrl in Shift) then
     begin
+    // Быстрое превью карты:
+      if Key = Ord('E') then
+      begin
+        if PreviewMode = 0 then
+          PreviewMode := 2;
+      end;
+
     // Вертикальный скролл карты:
       with sbVertical do
       begin
         if Key = Ord('W') then
         begin
+          if (MouseLDown or MouseRDown) and (Position >= DotStep) then
+          begin
+            Dec(WASDOffset.Y, DotStep);
+            RenderPanelMouseMove(Sender, Shift, LastMovePoint.X, LastMovePoint.Y);
+          end;
           Position := IfThen(Position > DotStep, Position-DotStep, 0);
           MapOffset.Y := -Round(Position/16) * 16;
         end;
 
         if Key = Ord('S') then
         begin
+          if (MouseLDown or MouseRDown) and (Position+DotStep <= Max) then
+          begin
+            Inc(WASDOffset.Y, DotStep);
+            RenderPanelMouseMove(Sender, Shift, LastMovePoint.X, LastMovePoint.Y);
+          end;
           Position := IfThen(Position+DotStep < Max, Position+DotStep, Max);
           MapOffset.Y := -Round(Position/16) * 16;
         end;
@@ -4224,12 +4246,22 @@ begin
       begin
         if Key = Ord('A') then
         begin
+          if (MouseLDown or MouseRDown) and (Position >= DotStep) then
+          begin
+            Dec(WASDOffset.X, DotStep);
+            RenderPanelMouseMove(Sender, Shift, LastMovePoint.X, LastMovePoint.Y);
+          end;
           Position := IfThen(Position > DotStep, Position-DotStep, 0);
           MapOffset.X := -Round(Position/16) * 16;
         end;
 
         if Key = Ord('D') then
         begin
+          if (MouseLDown or MouseRDown) and (Position+DotStep <= Max) then
+          begin
+            Inc(WASDOffset.X, DotStep);
+            RenderPanelMouseMove(Sender, Shift, LastMovePoint.X, LastMovePoint.Y);
+          end;
           Position := IfThen(Position+DotStep < Max, Position+DotStep, Max);
           MapOffset.X := -Round(Position/16) * 16;
         end;
@@ -6170,7 +6202,10 @@ end;
 
 procedure TMainForm.miMapPreviewClick(Sender: TObject);
 begin
-  if not PreviewMode then
+  if PreviewMode = 2 then
+    Exit;
+
+  if PreviewMode = 0 then
     begin
       Splitter2.Visible := False;
       Splitter1.Visible := False;
@@ -6193,8 +6228,8 @@ begin
       sbVertical.Visible := True;
     end;
 
-  PreviewMode := not PreviewMode;
-  (Sender as TMenuItem).Checked := PreviewMode;
+  PreviewMode := PreviewMode xor 1;
+  (Sender as TMenuItem).Checked := PreviewMode > 0;
 
   FormResize(Self);
 end;
@@ -6497,6 +6532,12 @@ begin
        (Key = Ord('V')) then
       FillProperty();
   end;
+// Быстрое превью карты:
+  if Key = Ord('E') then
+  begin
+    if PreviewMode = 2 then
+      PreviewMode := 0;
+  end;
 end;
 
 end.