Changeset 334 for trunk


Ignore:
Timestamp:
Mar 31, 2021, 9:12:58 PM (4 years ago)
Author:
chronos
Message:
  • Fixed: Keep tile position under mouse cursor during after tile resize by mouse wheel.
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/LocalPlayer/Term.pas

    r330 r334  
    226226    procedure MovieSpeedBtnClick(Sender: TObject);
    227227  private
    228     xw: Integer;
    229     yw: Integer;
     228    xw: Integer; // Base map x
     229    yw: Integer; // Base map y
    230230    xwd: Integer;
    231231    ywd: Integer;
     
    288288    procedure NextUnit(NearLoc: integer; AutoTurn: boolean);
    289289    procedure Scroll(dx, dy: integer);
     290    procedure SetMapPos(Loc: integer; MapPos: TPoint);
    290291    procedure Centre(Loc: integer);
    291292    procedure SetTroopLoc(Loc: integer);
     
    312313    procedure SetDebugMap(p: integer);
    313314    procedure SetViewpoint(p: integer);
    314     function LocationOfScreenPixel(x, y: integer): integer;
    315     procedure SetTileSize(TileSize: TTileSize);
     315    function LocationOfScreenPixel(x, y: integer): Integer;
     316    function GetCenterLoc: Integer;
     317    procedure SetTileSizeCenter(TileSize: TTileSize);
     318    procedure SetTileSize(TileSize: TTileSize; Loc: Integer; MapPos: TPoint);
    316319    procedure RectInvalidate(Left, Top, Rigth, Bottom: integer);
    317320    procedure ShowEnemyShipChange(ShowShipChange: TShowShipChange);
     
    35563559procedure TMainScreen.FormMouseWheel(Sender: TObject; Shift: TShiftState;
    35573560  WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
     3561var
     3562  MouseLoc: Integer;
    35583563begin
    35593564  if sb.ProcessMouseWheel(WheelDelta) then begin
     
    35613566    Update;
    35623567  end else begin
    3563     if (WheelDelta > 0) and (MainMap.TileSize < High(TTileSize)) then
    3564       SetTileSize(Succ(MainMap.TileSize))
    3565     else if (WheelDelta < 0) and (MainMap.TileSize > Low(TTileSize)) then
    3566       SetTileSize(Pred(MainMap.TileSize));
     3568    if (WheelDelta > 0) and (MainMap.TileSize < High(TTileSize)) then begin
     3569      MouseLoc := LocationOfScreenPixel(MousePos.X, MousePos.Y);
     3570      SetTileSize(Succ(MainMap.TileSize), MouseLoc, Point(MousePos.X, MousePos.Y));
     3571    end
     3572    else if (WheelDelta < 0) and (MainMap.TileSize > Low(TTileSize)) then begin
     3573      MouseLoc := LocationOfScreenPixel(MousePos.X, MousePos.Y);
     3574      SetTileSize(Pred(MainMap.TileSize), MouseLoc, Point(MousePos.X, MousePos.Y));
     3575    end;
    35673576  end;
    35683577end;
     
    50715080end;
    50725081
    5073 procedure TMainScreen.Centre(Loc: integer);
     5082procedure TMainScreen.SetMapPos(Loc: integer; MapPos: TPoint);
    50745083begin
    50755084  with MainMap do begin
     
    50775086      Update;
    50785087    // necessary because ScrollDC for form canvas is called after
    5079     xw := (Loc mod G.lx - (MapWidth - xxt * 2 * ((Loc div G.lx) and 1))
    5080       div (xxt * 4) + G.lx) mod G.lx;
    5081     if ywmax <= 0 then
    5082       yw := ywcenter
     5088    xw := (Loc mod G.lx) - (MapPos.X - ((xxt * 2) * ((Loc div G.lx) and 1)) div 2)
     5089      div (xxt * 2);
     5090    xw := (xw + G.lx) mod G.lx;
     5091    if ywmax <= 0 then yw := ywcenter
    50835092    else begin
    5084       yw := (Loc div G.lx - MapHeight div (yyt * 2) + 1) and not 1;
    5085       if yw < 0 then
    5086         yw := 0
    5087       else if yw > ywmax then
    5088         yw := ywmax;
    5089     end;
    5090   end;
     5093      yw := (Loc div G.lx - (MapPos.Y * 2) div (yyt * 2) + 1) and not 1;
     5094      if yw < 0 then yw := 0
     5095        else if yw > ywmax then yw := ywmax;
     5096    end;
     5097  end;
     5098end;
     5099
     5100procedure TMainScreen.Centre(Loc: integer);
     5101begin
     5102  SetMapPos(Loc, Point(MapWidth div 2, MapHeight div 2));
    50915103end;
    50925104
     
    51215133end;
    51225134
    5123 function TMainScreen.LocationOfScreenPixel(x, y: integer): integer;
     5135function TMainScreen.LocationOfScreenPixel(x, y: integer): Integer;
    51245136var
    51255137  qx, qy: integer;
     
    51295141    qy := (y * (xxt * 2) - x * (yyt * 2) - xxt * yyt * 2 + 4000 * xxt * yyt)
    51305142      div (xxt * yyt * 4) - 999;
    5131     result := (xw + (qx - qy + 2048) div 2 - 1024 + G.lx) mod G.lx + G.lx *
     5143    Result := (xw + (qx - qy + 2048) div 2 - 1024 + G.lx) mod G.lx + G.lx *
    51325144      (yw + qx + qy);
    51335145  end;
     5146end;
     5147
     5148function TMainScreen.GetCenterLoc: Integer;
     5149begin
     5150  Result := (xw + MapWidth div (MainMap.xxt * 4)) mod G.lx +
     5151    (yw + MapHeight div (MainMap.yyt * 2)) * G.lx;
    51345152end;
    51355153
     
    79337951procedure TMainScreen.mSmallTilesClick(Sender: TObject);
    79347952begin
    7935   SetTileSize(tsSmall);
     7953  SetTileSizeCenter(tsSmall);
    79367954end;
    79377955
    79387956procedure TMainScreen.mNormalTilesClick(Sender: TObject);
    79397957begin
    7940   SetTileSize(tsMedium);
     7958  SetTileSizeCenter(tsMedium);
    79417959end;
    79427960
    79437961procedure TMainScreen.mBigTilesClick(Sender: TObject);
    79447962begin
    7945   SetTileSize(tsBig);
    7946 end;
    7947 
    7948 procedure TMainScreen.SetTileSize(TileSize: TTileSize);
     7963  SetTileSizeCenter(tsBig);
     7964end;
     7965
     7966procedure TMainScreen.SetTileSizeCenter(TileSize: TTileSize);
     7967begin
     7968  SetTileSize(TileSize, GetCenterLoc, Point(MapWidth div 2, MapHeight div 2));
     7969end;
     7970
     7971procedure TMainScreen.SetTileSize(TileSize: TTileSize; Loc: Integer; MapPos: TPoint);
    79497972var
    7950   i, CenterLoc: integer;
    7951 begin
    7952   CenterLoc := (xw + MapWidth div (MainMap.xxt * 4)) mod G.lx +
    7953     (yw + MapHeight div (MainMap.yyt * 2)) * G.lx;
     7973  i: integer;
     7974begin
    79547975  MainMap.TileSize := TileSize;
    79557976  NoMap.TileSize := TileSize;
    79567977  FormResize(nil);
    7957   Centre(CenterLoc);
     7978  SetMapPos(Loc, MapPos);
    79587979  PaintAllMaps;
    79597980  for i := 0 to Screen.FormCount - 1 do
  • trunk/Protocol.pas

    r328 r334  
    16711671
    16721672  TNewGameData = record
    1673     lx: Integer;
    1674     ly: Integer;
     1673    lx: Integer; // Map width
     1674    ly: Integer; // Map height
    16751675    LandMass: Integer;
    16761676    MaxTurn: Integer;
Note: See TracChangeset for help on using the changeset viewer.