Changeset 268 for trunk


Ignore:
Timestamp:
Jan 20, 2019, 9:32:16 PM (6 years ago)
Author:
chronos
Message:
  • Added: New menu action show/hide map grid lines.
  • Modified: Draw cell polygons without a gap so it can be drawn as solid surface without grid lines.
Location:
trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormClient.pas

    r265 r268  
    254254              )
    255255            );
     256            Client.DrawCities(PaintBox1.Canvas, TempView);
     257          end;
     258        end;
     259        for Y := 0 to CountP.Y do begin
     260          for X := 0 to CountP.X do begin
     261            TempView.Assign(View);
     262            TempView.DestRect := TRect.Create(
     263              TPoint.Create(
     264                -StartP.X + R.Size.X * X,
     265                -StartP.Y + R.Size.Y * Y
     266              ),
     267              TPoint.Create(
     268                -StartP.X + R.Size.X * X + View.DestRect.Size.X,
     269                -StartP.Y + R.Size.Y * Y + View.DestRect.Size.Y
     270              )
     271            );
     272            Client.DrawSelection(PaintBox1.Canvas, TempView);
     273          end;
     274        end;
     275        TempView.Free;
     276        for Y := 0 to CountP.Y do begin
     277          for X := 0 to CountP.X do begin
     278            TempView.Assign(View);
     279            TempView.DestRect := TRect.Create(
     280              TPoint.Create(
     281                -StartP.X + R.Size.X * X,
     282                -StartP.Y + R.Size.Y * Y
     283              ),
     284              TPoint.Create(
     285                -StartP.X + R.Size.X * X + View.DestRect.Size.X,
     286                -StartP.Y + R.Size.Y * Y + View.DestRect.Size.Y
     287              )
     288            );
    256289            Client.DrawArrows(PaintBox1.Canvas, TempView);
    257290          end;
    258291        end;
    259         TempView.Free;
    260292      end else begin
    261293        Client.DrawCellLinks(PaintBox1.Canvas, View);
    262294        Client.Paint(PaintBox1.Canvas, View);
     295        Client.DrawCities(PaintBox1.Canvas, View);
     296        Client.DrawSelection(PaintBox1.Canvas, View);
    263297        Client.DrawArrows(PaintBox1.Canvas, View);
    264298      end;
     
    316350    FClient.OnNextPlayer := DoNextPlayer;
    317351    FClient.View.DestRect := TRect.CreateBounds(TPoint.Create(0, 0), TPoint.Create(PaintBox1.Width, PaintBox1.Height));
     352    FClient.ShowCellGrid := Core.ShowCellGrid;
    318353  end;
    319354  Redraw;
  • trunk/Forms/UFormMain.lfm

    r250 r268  
    1515  OnKeyUp = FormKeyUp
    1616  OnShow = FormShow
    17   LCLVersion = '1.8.2.0'
     17  LCLVersion = '1.8.4.0'
    1818  WindowState = wsMaximized
    1919  object ToolBar1: TToolBar
     
    146146        Caption = '-'
    147147      end
     148      object MenuItem33: TMenuItem
     149        Action = AMapGridVisible
     150      end
    148151      object MenuItem21: TMenuItem
    149152        Action = AToolBarVisible
     
    218221      OnExecute = AStatusBarVisibleExecute
    219222    end
     223    object AMapGridVisible: TAction
     224      Caption = 'Map grid visible'
     225      OnExecute = AMapGridVisibleExecute
     226    end
    220227  end
    221228  object PopupMenuToolbar: TPopupMenu
  • trunk/Forms/UFormMain.pas

    r253 r268  
    1818
    1919  TFormMain = class(TForm)
     20    AMapGridVisible: TAction;
    2021    AStatusBarVisible: TAction;
    2122    AToolBarVisible: TAction;
     
    4748    MenuItem30: TMenuItem;
    4849    MenuItem32: TMenuItem;
     50    MenuItem33: TMenuItem;
    4951    MenuItemDebug: TMenuItem;
    5052    MenuItem31: TMenuItem;
     
    7072    ToolButton5: TToolButton;
    7173    ToolButton9: TToolButton;
     74    procedure AMapGridVisibleExecute(Sender: TObject);
    7275    procedure AStatusBarVisibleExecute(Sender: TObject);
    7376    procedure AToolBarBigIconsExecute(Sender: TObject);
     
    178181end;
    179182
     183procedure TFormMain.AMapGridVisibleExecute(Sender: TObject);
     184begin
     185  AMapGridVisible.Checked := not AMapGridVisible.Checked;
     186  UpdateClientForms;
     187end;
     188
    180189procedure TFormMain.AToolBarBigIconsExecute(Sender: TObject);
    181190begin
     
    211220  Core.PersistentForm.Save(Self);
    212221  SaveConfig(Core.XMLConfig1, 'FormMain');
     222  Core.ShowCellGrid := AMapGridVisible.Checked;
    213223  Core.Done;
    214224end;
     
    234244  FormClient.AStatusBarVisible.Checked := AStatusBarVisible.Checked;
    235245  FormClient.AStatusBarVisible.Update;
     246  Core.ShowCellGrid := AMapGridVisible.Checked;
     247  if Assigned(FormClient.Client) then
     248    FormClient.Client.ShowCellGrid := Core.ShowCellGrid;
     249  FormClient.Redraw;
    236250  for I := 0 to Core.FormClients.Count - 1 do begin
    237251    Core.FormClients[I].AToolBarBigIcons.Checked := AToolBarBigIcons.Checked;
     
    241255    Core.FormClients[I].AStatusBarVisible.Checked := AStatusBarVisible.Checked;
    242256    Core.FormClients[I].AStatusBarVisible.Update;
     257    if Assigned(Core.FormClients[I].Client) then
     258      Core.FormClients[I].Client.ShowCellGrid := Core.ShowCellGrid;
     259    Core.FormClients[I].Redraw;
    243260  end;
    244261end;
     
    248265  if not FormShown then begin
    249266    Core.LoadConfig;
     267    AMapGridVisible.Checked := Core.ShowCellGrid;
    250268    Core.ScaleDPI;
    251269    Core.PersistentForm.Load(Self, True);
  • trunk/Forms/UFormNew.lfm

    r266 r268  
    2121    Top = 4
    2222    Width = 749
    23     ActivePage = TabSheetRules
     23    ActivePage = TabSheetMode
    2424    Align = alClient
    2525    BorderSpacing.Around = 4
    26     TabIndex = 3
     26    TabIndex = 0
    2727    TabOrder = 0
    2828    object TabSheetMode: TTabSheet
     
    3232      object Panel3: TPanel
    3333        Left = 0
    34         Height = 651
     34        Height = 655
    3535        Top = 0
    36         Width = 743
     36        Width = 739
    3737        Align = alClient
    3838        BevelOuter = bvNone
    39         ClientHeight = 651
    40         ClientWidth = 743
     39        ClientHeight = 655
     40        ClientWidth = 739
    4141        TabOrder = 0
    4242        object RadioButtonModeLocal: TRadioButton
     
    4444          Height = 30
    4545          Top = 14
    46           Width = 68
     46          Width = 70
    4747          Caption = 'Local'
    4848          Checked = True
     
    5555          Height = 30
    5656          Top = 48
    57           Width = 154
     57          Width = 156
    5858          Caption = 'Network server'
    5959          OnChange = RadioButtonModeLocalChange
     
    6464          Height = 30
    6565          Top = 152
    66           Width = 149
     66          Width = 151
    6767          Caption = 'Network client'
    6868          OnChange = RadioButtonModeLocalChange
     
    7171        object EditServerAddress: TEdit
    7272          Left = 24
    73           Height = 36
     73          Height = 43
    7474          Top = 112
    7575          Width = 220
     
    7878        object SpinEditServerPort: TSpinEdit
    7979          Left = 256
    80           Height = 36
     80          Height = 43
    8181          Top = 112
    8282          Width = 79
     
    102102        object ListViewServers: TListView
    103103          Left = 26
    104           Height = 419
     104          Height = 423
    105105          Top = 181
    106106          Width = 334
     
    130130          Left = 27
    131131          Height = 31
    132           Top = 612
     132          Top = 616
    133133          Width = 94
    134134          Action = AServerAdd
     
    139139          Left = 240
    140140          Height = 31
    141           Top = 612
     141          Top = 616
    142142          Width = 94
    143143          Action = AServerRemove
     
    148148          Left = 136
    149149          Height = 30
    150           Top = 612
     150          Top = 616
    151151          Width = 94
    152152          Action = AServerModify
     
    324324        object ComboBoxGridType: TComboBox
    325325          Left = 146
    326           Height = 42
     326          Height = 38
    327327          Top = 104
    328328          Width = 208
     
    340340        object ComboBoxMapShape: TComboBox
    341341          Left = 146
    342           Height = 42
     342          Height = 38
    343343          Top = 144
    344344          Width = 208
  • trunk/Languages/xtactics.cs.po

    r265 r268  
    230230msgstr "Vykonat"
    231231
     232#: tformmain.amapgridvisible.caption
     233msgid "Map grid visible"
     234msgstr "Mřížka mapy viditelná"
     235
     236#: tformmain.astatusbarvisible.caption
     237msgid "Status bar visible"
     238msgstr "Stavová lišta viditelná"
     239
    232240#: tformmain.atoolbarbigicons.caption
    233241msgctxt "tformmain.atoolbarbigicons.caption"
     
    274282msgid "Help"
    275283msgstr "Nápověda"
    276 
    277 #: tformmain.menuitem22.caption
    278 msgctxt "tformmain.menuitem22.caption"
    279 msgid "Statusbar visible"
    280 msgstr "Viditelná stavová lišta"
    281284
    282285#: tformmain.menuitem8.caption
     
    707710#: tformsettings.checkboxreopenlastfile.caption
    708711msgid "Reopen last game on start"
    709 msgstr "Znovuotevřít poslední hru při startu"
     712msgstr "Znovu otevřít poslední hru při startu"
    710713
    711714#: tformsettings.label1.caption
  • trunk/Languages/xtactics.po

    r265 r268  
    220220msgstr ""
    221221
     222#: tformmain.amapgridvisible.caption
     223msgid "Map grid visible"
     224msgstr ""
     225
     226#: tformmain.astatusbarvisible.caption
     227msgid "Status bar visible"
     228msgstr ""
     229
    222230#: tformmain.atoolbarbigicons.caption
    223231msgctxt "tformmain.atoolbarbigicons.caption"
     
    263271msgctxt "tformmain.menuitem16.caption"
    264272msgid "Help"
    265 msgstr ""
    266 
    267 #: tformmain.menuitem22.caption
    268 msgctxt "tformmain.menuitem22.caption"
    269 msgid "Statusbar visible"
    270273msgstr ""
    271274
  • trunk/UClientGUI.pas

    r267 r268  
    4848  public
    4949    View: TView;
     50    ShowCellGrid: Boolean;
    5051    procedure DrawArrow(Canvas: TCanvas; Pos: TPoint; Angle: Double;
    5152      Text: string; View: TView);
     
    5859    procedure DrawCellLinks(Canvas: TCanvas; View: TView);
    5960    procedure DrawNeighborLinks(Canvas: TCanvas; View: TView);
     61    procedure DrawCities(Canvas: TCanvas; View: TView);
     62    procedure DrawSelection(Canvas: TCanvas; View: TView);
    6063    procedure Paint(Canvas: TCanvas; View: TView);
    6164    constructor Create; override;
     
    107110  end;
    108111  with Canvas do begin
    109     if Assigned(View.FocusedCell) and (View.FocusedCell = Cell) then begin
    110       Pen.Color := clYellow;
    111       Pen.Style := psSolid;
    112       Pen.Width := 1;
    113     end else
    114     if Cell.MapCell.Terrain = ttCity then begin
    115       // Cannot set clear border as it will display shifted on gtk2
    116       //Pen.Style := psClear;
     112    // Cannot set clear border as it will display shifted on gtk2
     113    //Pen.Style := psClear;
     114    Pen.Style := psSolid;
     115    if ShowCellGrid then begin
    117116      Pen.Color := clBlack;
    118       Pen.Style := psSolid;
    119       Pen.Width := 3;
     117      Pen.Width := Round(2 * View.Zoom);
    120118    end else begin
    121       // Cannot set clear border as it will display shifted on gtk2
    122       //Pen.Style := psClear;
    123119      Pen.Color := Brush.Color;
    124       Pen.Style := psSolid;
    125120      Pen.Width := 0;
    126121    end;
     122
    127123    // Transform view
    128124    SetLength(Points, Length(Cell.MapCell.Polygon.Points));
     
    130126      Points[I] := PointToStdPoint(View.CellToCanvasPos(Cell.MapCell.Polygon.Points[I]));
    131127    Brush.Style := bsSolid;
    132     //Polygon(Points, False, 0, Length(Points));
    133128    TCanvasEx.PolygonEx(Canvas, Points, False);
    134     //MoveTo(Points[0].X, Points[0].Y);
    135     //LineTo(Points[1].X, Points[1].Y);
    136129
    137130    // Show cell text
     
    237230        not ControlPlayer.PlayerMap.Cells.SearchCell(Move.CellTo.MapCell).InVisibleRange then
    238231        Continue;
    239       if Move.CountRepeat > 0 then Pen.Width := 2
    240         else Pen.Width := 1;
     232      if Move.CountRepeat > 0 then Pen.Width := Round(2 * View.Zoom)
     233        else Pen.Width := Round(1 * View.Zoom);
    241234      Angle := ArcTan2(PosTo.Y - PosFrom.Y, PosTo.X - PosFrom.X);
    242235      if (Angle > +Pi) or (Angle < -Pi) then
     
    312305  MapCell: TCell;
    313306  CellText: string;
     307  Points: array of Classes.TPoint;
     308  I: Integer;
    314309begin
    315310  with Canvas, View do begin
     
    404399end;
    405400
     401procedure TClientGUI.DrawCities(Canvas: TCanvas; View: TView);
     402var
     403  Cell: TPlayerCell;
     404  MapCell: TCell;
     405  CellText: string;
     406  Points: array of Classes.TPoint;
     407  I: Integer;
     408begin
     409  with Canvas, View do begin
     410    if Assigned(ControlPlayer) then begin
     411      for Cell in ControlPlayer.PlayerMap.Cells do begin
     412        if (Cell.MapCell.Terrain <> ttVoid) and View.IsCellVisible(Cell.MapCell) then begin
     413          if Cell.MapCell.Terrain = ttCity then begin
     414            // Cannot set clear border as it will display shifted on gtk2
     415            //Pen.Style := psClear;
     416            Pen.Color := clBlack;
     417            Pen.Style := psSolid;
     418            Pen.Width := Round(6 * View.Zoom);
     419
     420            // Transform view
     421            SetLength(Points, Length(Cell.MapCell.Polygon.Points) + 1);
     422            for I := 0 to Length(Cell.MapCell.Polygon.Points) - 1 do
     423              Points[I] := PointToStdPoint(View.CellToCanvasPos(Cell.MapCell.Polygon.Points[I]));
     424            Points[Length(Points) - 1] := Points[0];
     425            TCanvasEx.PolyLineEx(Canvas, Points);
     426          end;
     427        end;
     428      end;
     429    end else begin
     430      for MapCell in TGame(Game).Map.Cells do begin
     431        if (MapCell.Terrain <> ttVoid) and View.IsCellVisible(MapCell) then begin
     432          if View.IsCellVisible(MapCell) and (MapCell.Terrain <> ttVoid) then begin
     433            if MapCell.Terrain = ttCity then begin
     434              // Cannot set clear border as it will display shifted on gtk2
     435              //Pen.Style := psClear;
     436              Pen.Color := clBlack;
     437              Pen.Style := psSolid;
     438              Pen.Width := Round(6 * View.Zoom);
     439
     440              // Transform view
     441              SetLength(Points, Length(MapCell.Polygon.Points) + 1);
     442              for I := 0 to Length(MapCell.Polygon.Points) - 1 do
     443                Points[I] := PointToStdPoint(View.CellToCanvasPos(MapCell.Polygon.Points[I]));
     444              Points[Length(Points) - 1] := Points[0];
     445              TCanvasEx.PolyLineEx(Canvas, Points);
     446            end;
     447          end;
     448        end;
     449      end;
     450    end;
     451  end;
     452end;
     453
     454procedure TClientGUI.DrawSelection(Canvas: TCanvas; View: TView);
     455var
     456  Cell: TPlayerCell;
     457  MapCell: TCell;
     458  CellText: string;
     459  Points: array of Classes.TPoint;
     460  I: Integer;
     461begin
     462  with Canvas, View do begin
     463    if Assigned(ControlPlayer) then begin
     464      if Assigned(View.FocusedCell) then begin
     465        Pen.Color := clYellow;
     466        Pen.Style := psSolid;
     467        Pen.Width := Round(2 * View.Zoom);
     468
     469        // Transform view
     470        SetLength(Points, Length(View.FocusedCell.MapCell.Polygon.Points) + 1);
     471        for I := 0 to Length(View.FocusedCell.MapCell.Polygon.Points) - 1 do
     472          Points[I] := PointToStdPoint(View.CellToCanvasPos(View.FocusedCell.MapCell.Polygon.Points[I]));
     473        Points[Length(Points) - 1] := Points[0];
     474        TCanvasEx.PolyLineEx(Canvas, Points);
     475      end;
     476    end;
     477  end;
     478end;
     479
    406480{ TView }
    407481
  • trunk/UCore.pas

    r265 r268  
    9595    DevelMode: Boolean;
    9696    AnimationSpeed: Integer;
     97    ShowCellGrid: Boolean;
    9798    AutoSaveEnabled: Boolean;
    9899    ReopenLastFile: Boolean;
     
    202203  ScaleDPI1.AutoDetect := XMLConfig1.GetValue('DPIAuto', True);
    203204  FormNewTabIndex := XMLConfig1.GetValue('FormNewTabIndex', 0);
     205  ShowCellGrid := XMLConfig1.GetValue('ShowCellGrid', True);
    204206end;
    205207
     
    217219  XMLConfig1.SetValue('DPIAuto', ScaleDPI1.AutoDetect);
    218220  XMLConfig1.SetValue('FormNewTabIndex', FormNewTabIndex);
     221  XMLConfig1.SetValue('ShowCellGrid', ShowCellGrid);
    219222end;
    220223
  • trunk/UGame.pas

    r265 r268  
    2323    class procedure TextOutEx(Canvas: TCanvas; X,Y: Integer; const Text: string; MovePen: Boolean = True);
    2424    class procedure PolygonEx(Canvas: TCanvas; const Points: array of Classes.TPoint; Winding: Boolean);
     25    class procedure PolyLineEx(Canvas: TCanvas; const Points: array of Classes.TPoint);
    2526  end;
    2627
     
    180181end;
    181182
     183class procedure TCanvasEx.PolyLineEx(Canvas: TCanvas;
     184  const Points: array of Classes.TPoint);
     185begin
     186  LCLIntf.Polyline(Canvas.Handle, @Points[0], Length(Points));
     187end;
     188
    182189{ TGame }
    183190
  • trunk/UMapType.pas

    r258 r268  
    2020  private
    2121    const
    22       CellMulX = 1.12;
    23       CellMulY = 1.292;
     22      CellMulX = 1.12 * 1.028;
     23      CellMulY = 1.292 * 1.03;
    2424    function IsCellsPosNeighbor(CellPos1, CellPos2: TPoint): Boolean;
    2525    procedure GetCellPosNeighbors(CellPos: TPoint; Cell: TCell);
     
    3838  TSquareMap = class(TMap)
    3939  private
    40     const
    41       CellMulX = 1.05;
    42       CellMulY = 1.05;
    4340    function GetSquarePolygon(Pos: TPoint; Size: TPoint): TPolygon;
    4441  public
    4542    procedure Generate; override;
    46     function CalculatePixelRect: TRect; override;
    4743  end;
    4844
     
    5248  private
    5349    const
    54       CellMulX = 0.55;
    55       CellMulY = 1.05;
     50      CellMulX = 0.5;
     51      CellMulY = 1;
    5652    function GetTrianglePolygon(Pos: TPoint; Size: TPoint; Reverse: Boolean): TPolygon;
    5753  protected
     
    7672  private
    7773    const
    78       CellMulX = 0.95;
    79       CellMulY = 3.35;
     74      CellMulX = 1;
     75      CellMulY = 3.5;
    8076    function GetTilePolygon(Pos: TPoint; Size: TPoint): TPolygon;
    8177  protected
     
    173169  Result := inherited CalculatePixelRect;
    174170  Result.P2 := Result.P2 - TPoint.Create(
    175     Trunc(0.45 * DefaultCellSize.X / CellMulX),
    176     Trunc(0.90 * DefaultCellSize.Y / CellMulY)
     171    Trunc(0.5 * DefaultCellSize.X / CellMulX),
     172    Trunc(DefaultCellSize.Y / CellMulY)
    177173  );
    178174end;
     
    212208  Shift := TPointF.Create(0.5, 0.5) * TPointF.Create(Cos(Angle), Sin(Angle));
    213209  Result.P2 := Result.P2 - TPoint.Create(
    214     Trunc(0.47 * DefaultCellSize.X / CellMulX),
    215     Trunc(1.2 * Shift.Y * DefaultCellSize.Y / CellMulY)
     210    Trunc(0.5 * DefaultCellSize.X / CellMulX),
     211    Trunc(1.35 * Shift.Y * DefaultCellSize.Y / CellMulY)
    216212  );
    217213end;
     
    344340    NewCell := TCell.Create;
    345341    NewCell.Map := Self;
    346     NewCell.PosPx := TPoint.Create(Trunc(X * DefaultCellSize.X * CellMulX),
    347       Trunc(Y * DefaultCellSize.Y * CellMulY));
     342    NewCell.PosPx := TPoint.Create(Trunc(X * DefaultCellSize.X),
     343      Trunc(Y * DefaultCellSize.Y));
    348344    NewCell.Polygon := GetSquarePolygon(NewCell.PosPx, DefaultCellSize);
    349345    NewCell.Id := GetNewCellId;
     
    382378
    383379  FPixelRect := CalculatePixelRect;
    384 end;
    385 
    386 function TSquareMap.CalculatePixelRect: TRect;
    387 begin
    388   Result := inherited CalculatePixelRect;
    389   Result.P2 := Result.P2 + TPoint.Create(
    390     Trunc(0.05 * DefaultCellSize.X / CellMulX),
    391     Trunc(0.05 * DefaultCellSize.Y / CellMulY)
    392   );
    393380end;
    394381
     
    424411  AreaSize: TPoint;
    425412const
    426   CellGapWidth = 4;
     413  LinkTolerance = 8;
    427414begin
    428415  Clear;
     
    457444        LinkLine := TLine.Create(Cell.PosPx, Cell2.PosPx +
    458445          TPoint.Create(X * AreaSize.X, Y * AreaSize.Y));
    459         LinkLine.Distance := LinkLine.Distance - CellGapWidth;
     446        LinkLine.Distance := LinkLine.Distance;
    460447        MP := LinkLine.GetMiddle;
    461448        // Create half plane vector
     
    473460      if Cell2 <> Cell then begin
    474461        LinkLine := TLine.Create(Cell.PosPx, Cell2.PosPx);
    475         LinkLine.Distance := LinkLine.Distance - CellGapWidth;
     462        LinkLine.Distance := LinkLine.Distance;
    476463        MP := LinkLine.GetMiddle;
    477464        // Create half plane vector
     
    493480        P := Cells[J].Polygon;
    494481        P.Move(TPoint.Create(X * AreaSize.X, Y * AreaSize.Y));
    495         if Cells[I].Polygon.EdgeDistance(P) < 2 * CellGapWidth then
     482        if Cells[I].Polygon.EdgeDistance(P) < LinkTolerance then
    496483          Cells[I].ConnectTo(Cells[J]);
    497484      end;
     
    500487    for I := 0 to Cells.Count - 1 do begin
    501488      for J := I + 1 to Cells.Count - 1 do begin
    502         if Cells[I].Polygon.EdgeDistance(Cells[J].Polygon) < 2 * CellGapWidth then
     489        if Cells[I].Polygon.EdgeDistance(Cells[J].Polygon) < LinkTolerance then
    503490          Cells[I].ConnectTo(Cells[J]);
    504491      end;
     
    603590  Result := inherited CalculatePixelRect;
    604591  Result.P2 := Result.P2 + TPoint.Create(
    605     Trunc(0.05 * DefaultCellSize.X / CellMulX - 0.30 * DefaultCellSize.X / CellMulX),
    606     Trunc(0.05 * DefaultCellSize.Y / CellMulY)
     592    Trunc(- 0.25 * DefaultCellSize.X / CellMulX),
     593    0
    607594  );
    608595end;
Note: See TracChangeset for help on using the changeset viewer.