Changeset 269 for trunk


Ignore:
Timestamp:
Jan 21, 2019, 12:38:20 AM (6 years ago)
Author:
chronos
Message:
  • Added: Map random preview in New game form.
Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormClient.pas

    r268 r269  
    106106  FormClient: TFormClient;
    107107
     108const
     109  MapBackgroundColor = $404040;
     110
    108111implementation
    109112
     
    180183  X, Y: Integer;
    181184  TempView: TView;
    182 const
    183   BackgroundColor = $404040;
    184185begin
    185186  DrawStart := Now;
     
    189190    if csOpaque in PaintBox1.ControlStyle then begin
    190191      TempBitmap.SetSize(PaintBox1.Width, PaintBox1.Height);
    191       TempBitmap.Canvas.Brush.Color := BackGroundColor; //clBackground; //PaintBox1.GetColorResolvingParent;
     192      TempBitmap.Canvas.Brush.Color := MapBackGroundColor; //clBackground; //PaintBox1.GetColorResolvingParent;
    192193      TempBitmap.Canvas.FillRect(0, 0, PaintBox1.Width, PaintBox1.Height);
    193194      Client.Paint(TempBitmap.Canvas, View);
     
    238239              )
    239240            );
    240             Client.Paint(PaintBox1.Canvas, TempView);
     241            Client.DrawCells(PaintBox1.Canvas, TempView);
    241242          end;
    242243        end;
     
    291292        end;
    292293      end else begin
    293         Client.DrawCellLinks(PaintBox1.Canvas, View);
    294294        Client.Paint(PaintBox1.Canvas, View);
    295         Client.DrawCities(PaintBox1.Canvas, View);
    296         Client.DrawSelection(PaintBox1.Canvas, View);
    297         Client.DrawArrows(PaintBox1.Canvas, View);
    298295      end;
    299296    end;
     
    436433
    437434procedure TFormClient.AZoomAllExecute(Sender: TObject);
    438 var
    439   Factor: TPointF;
    440   MapRect: TRect;
    441   NewZoom: Single;
    442435begin
    443436  with Core, Game, Client, View do begin
    444     MapRect := Map.CalculatePixelRect;
    445     Factor := TPointF.Create(DestRect.Size.X / MapRect.Size.X,
    446       DestRect.Size.Y / MapRect.Size.Y);
    447     if Factor.X < Factor.Y then NewZoom := Factor.X
    448       else NewZoom := Factor.Y;
    449     if NewZoom = 0 then NewZoom := 1;
    450     Zoom := NewZoom;
    451     CenterMap;
     437    ZoomAll;
    452438  end;
    453439  Redraw;
  • trunk/Forms/UFormNew.lfm

    r268 r269  
    11object FormNew: TFormNew
    22  Left = 546
    3   Height = 748
    4   Top = 181
    5   Width = 1154
     3  Height = 745
     4  Top = 184
     5  Width = 1211
    66  Caption = 'New game'
    7   ClientHeight = 748
    8   ClientWidth = 1154
     7  ClientHeight = 745
     8  ClientWidth = 1211
    99  Constraints.MinHeight = 501
    1010  Constraints.MinWidth = 667
     
    1818  object PageControl1: TPageControl
    1919    Left = 4
    20     Height = 695
     20    Height = 692
    2121    Top = 4
    22     Width = 749
    23     ActivePage = TabSheetMode
     22    Width = 806
     23    ActivePage = TabSheetMap
    2424    Align = alClient
    2525    BorderSpacing.Around = 4
    26     TabIndex = 0
     26    TabIndex = 2
    2727    TabOrder = 0
     28    OnChange = PageControl1Change
    2829    object TabSheetMode: TTabSheet
    2930      Caption = 'Mode'
    30       ClientHeight = 655
    31       ClientWidth = 739
     31      ClientHeight = 652
     32      ClientWidth = 796
    3233      object Panel3: TPanel
    3334        Left = 0
     
    158159    object TabSheetPlayers: TTabSheet
    159160      Caption = 'Players'
    160       ClientHeight = 655
    161       ClientWidth = 739
     161      ClientHeight = 652
     162      ClientWidth = 796
    162163      object Panel2: TPanel
    163164        Left = 0
    164         Height = 655
     165        Height = 652
    165166        Top = 0
    166         Width = 739
     167        Width = 796
    167168        Align = alClient
    168169        BevelOuter = bvNone
    169         ClientHeight = 655
    170         ClientWidth = 739
     170        ClientHeight = 652
     171        ClientWidth = 796
    171172        TabOrder = 0
    172173        object ListViewPlayers: TListView
    173174          Left = 4
    174           Height = 605
     175          Height = 602
    175176          Top = 4
    176           Width = 731
     177          Width = 788
    177178          Align = alTop
    178179          Anchors = [akTop, akLeft, akRight, akBottom]
     
    212213          Left = 16
    213214          Height = 25
    214           Top = 617
     215          Top = 614
    215216          Width = 83
    216217          Action = APlayerAdd
     
    221222          Left = 120
    222223          Height = 25
    223           Top = 617
     224          Top = 614
    224225          Width = 83
    225226          Action = APlayerModify
     
    230231          Left = 224
    231232          Height = 25
    232           Top = 617
     233          Top = 614
    233234          Width = 83
    234235          Action = APlayerRemove
     
    240241    object TabSheetMap: TTabSheet
    241242      Caption = 'Map'
    242       ClientHeight = 655
    243       ClientWidth = 739
     243      ClientHeight = 652
     244      ClientWidth = 796
     245      OnShow = TabSheetMapShow
    244246      object Panel1: TPanel
    245247        Left = 0
    246         Height = 655
     248        Height = 652
    247249        Top = 0
    248         Width = 739
     250        Width = 796
    249251        Align = alClient
    250252        BevelOuter = bvNone
    251         ClientHeight = 655
    252         ClientWidth = 739
     253        ClientHeight = 652
     254        ClientWidth = 796
    253255        TabOrder = 0
    254256        object Label1: TLabel
     
    292294          Height = 58
    293295          Top = 8
    294           Width = 488
     296          Width = 545
    295297          Max = 100
    296298          Min = 2
     
    305307          Height = 58
    306308          Top = 49
    307           Width = 488
     309          Width = 545
    308310          Max = 100
    309311          Min = 2
     
    335337            'Isometric'
    336338          )
     339          OnChange = ComboBoxGridTypeChange
    337340          Style = csDropDownList
    338341          TabOrder = 4
     
    362365        end
    363366        object CheckBoxSymetricMap: TCheckBox
    364           Left = 472
     367          Left = 8
    365368          Height = 27
    366           Top = 110
    367           Width = 251
     369          Top = 248
     370          Width = 308
    368371          Anchors = [akTop, akLeft, akRight]
    369372          AutoSize = False
    370373          Caption = 'Symetric map'
     374          OnChange = CheckBoxSymetricMapChange
    371375          TabOrder = 6
    372376        end
     
    374378          Left = 216
    375379          Height = 43
    376           Top = 224
     380          Top = 315
    377381          Width = 106
    378382          MinValue = 1
     383          OnChange = SpinEditVoidPercentChange
    379384          TabOrder = 7
    380385          Value = 1
     
    383388          Left = 8
    384389          Height = 30
    385           Top = 232
     390          Top = 324
    386391          Width = 189
    387392          Caption = 'Inaccessible places'
     
    392397          Left = 8
    393398          Height = 30
    394           Top = 272
     399          Top = 368
    395400          Width = 73
    396401          Caption = 'Cities'
     
    401406          Left = 216
    402407          Height = 43
    403           Top = 272
     408          Top = 360
    404409          Width = 106
    405410          MinValue = 1
     411          OnChange = SpinEditCityPercentChange
    406412          TabOrder = 10
    407413          Value = 1
     
    410416          Left = 331
    411417          Height = 26
    412           Top = 272
     418          Top = 368
    413419          Width = 15
    414420          Caption = '%'
     
    418424          Left = 331
    419425          Height = 26
    420           Top = 232
     426          Top = 324
    421427          Width = 15
    422428          Caption = '%'
     
    424430        end
    425431        object SpinEditNeutralUnits: TSpinEdit
    426           Left = 408
     432          Left = 312
    427433          Height = 43
    428           Top = 384
     434          Top = 488
    429435          Width = 98
    430436          MaxValue = 99
     437          OnChange = SpinEditNeutralUnitsChange
    431438          TabOrder = 11
    432439          Value = 12
     
    435442          Left = 8
    436443          Height = 26
    437           Top = 384
     444          Top = 496
    438445          Width = 227
    439446          Caption = 'Max random neutral units:'
     
    444451          Height = 43
    445452          Top = 184
    446           Width = 472
     453          Width = 529
    447454          Anchors = [akTop, akLeft, akRight]
     455          OnChange = EditImageFileChange
    448456          TabOrder = 12
    449457        end
    450458        object ButtonImageBrowse: TButton
    451           Left = 624
    452           Height = 25
    453           Top = 192
     459          Left = 680
     460          Height = 38
     461          Top = 189
    454462          Width = 99
    455463          Anchors = [akTop, akRight]
     
    461469          Left = 8
    462470          Height = 26
    463           Top = 184
     471          Top = 191
    464472          Width = 90
    465473          Caption = 'Image file:'
     
    469477          Left = 8
    470478          Height = 30
    471           Top = 310
     479          Top = 408
    472480          Width = 212
    473481          Caption = 'Bridges between cells'
     482          OnChange = CheckBoxBridgesChange
    474483          TabOrder = 14
    475484        end
    476485        object SpinEditMaxPower: TSpinEdit
    477           Left = 408
     486          Left = 312
    478487          Height = 43
    479           Top = 344
     488          Top = 440
    480489          Width = 98
    481490          MaxValue = 1000000
     
    488497          Left = 8
    489498          Height = 26
    490           Top = 344
     499          Top = 448
    491500          Width = 156
    492501          Caption = 'Max units per cell:'
     
    494503        end
    495504        object CheckBoxCyclicMap: TCheckBox
    496           Left = 472
     505          Left = 8
    497506          Height = 27
    498           Top = 137
    499           Width = 251
     507          Top = 283
     508          Width = 308
    500509          Anchors = [akTop, akLeft, akRight]
    501510          AutoSize = False
    502511          Caption = 'Cyclic map'
     512          OnChange = CheckBoxCyclicMapChange
    503513          TabOrder = 16
     514        end
     515        object Image1: TImage
     516          Left = 419
     517          Height = 316
     518          Top = 272
     519          Width = 359
     520        end
     521        object Label15: TLabel
     522          Left = 419
     523          Height = 26
     524          Top = 240
     525          Width = 147
     526          Caption = 'Random preview:'
     527          ParentColor = False
    504528        end
    505529      end
     
    507531    object TabSheetRules: TTabSheet
    508532      Caption = 'Rules'
    509       ClientHeight = 655
    510       ClientWidth = 739
     533      ClientHeight = 652
     534      ClientWidth = 796
    511535      object Panel4: TPanel
    512536        Left = 0
     
    612636          object TabSheetCaptureCells: TTabSheet
    613637            ClientHeight = 74
    614             ClientWidth = 706
     638            ClientWidth = 712
    615639            object Label14: TLabel
    616640              Left = 8
     
    634658          object TabSheetStayAliveTurns: TTabSheet
    635659            ClientHeight = 74
    636             ClientWidth = 706
     660            ClientWidth = 712
    637661            object Label13: TLabel
    638662              Left = 8
     
    673697    Left = 0
    674698    Height = 45
    675     Top = 703
    676     Width = 1154
     699    Top = 700
     700    Width = 1211
    677701    Align = alBottom
    678702    BevelOuter = bvNone
    679703    ClientHeight = 45
    680     ClientWidth = 1154
     704    ClientWidth = 1211
    681705    TabOrder = 1
    682706    object ButtonOk: TButton
    683       Left = 966
     707      Left = 1023
    684708      Height = 25
    685709      Top = 6
     
    691715    end
    692716    object ButtonCancel: TButton
    693       Left = 1070
     717      Left = 1127
    694718      Height = 25
    695719      Top = 6
     
    702726  end
    703727  object PanelChat: TPanel
    704     Left = 763
    705     Height = 703
     728    Left = 820
     729    Height = 700
    706730    Top = 0
    707731    Width = 391
     
    711735  end
    712736  object Splitter1: TSplitter
    713     Left = 757
    714     Height = 703
     737    Left = 814
     738    Height = 700
    715739    Top = 0
    716740    Width = 6
     
    720744  object ActionList1: TActionList
    721745    Images = Core.ImageListSmall
    722     left = 464
    723     top = 464
     746    left = 864
     747    top = 216
    724748    object APlayerModify: TAction
    725749      Caption = 'Modify'
     
    748772  end
    749773  object OpenPictureDialog1: TOpenPictureDialog
    750     left = 602
    751     top = 464
     774    left = 864
     775    top = 360
    752776  end
    753777  object PopupMenuPlayers: TPopupMenu
    754     left = 312
    755     top = 464
     778    left = 864
     779    top = 288
    756780    object MenuItem1: TMenuItem
    757781      Action = APlayerAdd
     
    766790  end
    767791  object PopupMenuServers: TPopupMenu
    768     left = 176
    769     top = 464
     792    left = 864
     793    top = 136
    770794    object MenuItem4: TMenuItem
    771795      Action = AServerAdd
     
    778802    end
    779803  end
     804  object TimerMapPreview: TTimer
     805    Interval = 500
     806    OnTimer = TimerMapPreviewTimer
     807    left = 864
     808    top = 446
     809  end
    780810end
  • trunk/Forms/UFormNew.pas

    r266 r269  
    4343    EditImageFile: TEdit;
    4444    EditServerAddress: TEdit;
     45    Image1: TImage;
    4546    Label1: TLabel;
    4647    Label10: TLabel;
     
    4950    Label13: TLabel;
    5051    Label14: TLabel;
     52    Label15: TLabel;
    5153    Label2: TLabel;
    5254    Label3: TLabel;
     
    7274    Panel3: TPanel;
    7375    Panel4: TPanel;
     76    Panel5: TPanel;
    7477    PanelButtons: TPanel;
    7578    PanelChat: TPanel;
     
    9194    SpinEditVoidPercent: TSpinEdit;
    9295    Splitter1: TSplitter;
     96    TabSheetUnits: TTabSheet;
    9397    TabSheetCaptureEntireMap: TTabSheet;
    9498    TabSheetNone: TTabSheet;
     
    101105    TabSheetMode: TTabSheet;
    102106    TabSheetStayAliveTurns: TTabSheet;
     107    TimerMapPreview: TTimer;
    103108    TrackBarSizeX: TTrackBar;
    104109    TrackBarSizeY: TTrackBar;
     
    110115    procedure AServerRemoveExecute(Sender: TObject);
    111116    procedure ButtonImageBrowseClick(Sender: TObject);
     117    procedure CheckBoxBridgesChange(Sender: TObject);
    112118    procedure CheckBoxCityChange(Sender: TObject);
     119    procedure CheckBoxCyclicMapChange(Sender: TObject);
     120    procedure CheckBoxSymetricMapChange(Sender: TObject);
    113121    procedure CheckBoxVoidChange(Sender: TObject);
     122    procedure ComboBoxGridTypeChange(Sender: TObject);
    114123    procedure ComboBoxMapShapeChange(Sender: TObject);
    115124    procedure ComboBoxWinObjectiveChange(Sender: TObject);
     125    procedure EditImageFileChange(Sender: TObject);
    116126    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
    117127    procedure FormCreate(Sender: TObject);
     
    132142    procedure ListViewServersSelectItem(Sender: TObject; Item: TListItem;
    133143      Selected: Boolean);
     144    procedure PageControl1Change(Sender: TObject);
    134145    procedure RadioButtonModeLocalChange(Sender: TObject);
     146    procedure SpinEditCityPercentChange(Sender: TObject);
    135147    procedure SpinEditMapSizeXChange(Sender: TObject);
    136148    procedure SpinEditMapSizeYChange(Sender: TObject);
    137149    procedure SpinEditMaxPowerChange(Sender: TObject);
     150    procedure SpinEditNeutralUnitsChange(Sender: TObject);
     151    procedure SpinEditVoidPercentChange(Sender: TObject);
     152    procedure TabSheetMapShow(Sender: TObject);
     153    procedure TimerMapPreviewTimer(Sender: TObject);
    138154    procedure TrackBarSizeYChange(Sender: TObject);
    139155    procedure TrackBarSizeXChange(Sender: TObject);
     
    141157    Players: TPlayers;
    142158    ServerList: TServerList;
     159    GamePreview: TGame;
     160    MapPreviewRedrawPending: Boolean;
     161    procedure LoadGame(Game: TGame);
     162    procedure SaveGame(Game: TGame);
     163    procedure MapPreviewPaint;
     164    procedure MapPreviewRedraw;
    143165  public
    144166    procedure Translate;
     
    152174  FormNew: TFormNew;
    153175
     176
    154177implementation
    155178
     
    157180
    158181uses
    159   UFormPlayer, UFormChat, UCore, UFormServer;
     182  UFormPlayer, UFormChat, UCore, UFormServer, UClientGUI, UFormClient;
    160183
    161184resourcestring
     
    240263end;
    241264
     265procedure TFormNew.PageControl1Change(Sender: TObject);
     266begin
     267  MapPreviewRedraw;
     268end;
     269
    242270procedure TFormNew.RadioButtonModeLocalChange(Sender: TObject);
    243271begin
     
    245273end;
    246274
     275procedure TFormNew.SpinEditCityPercentChange(Sender: TObject);
     276begin
     277  MapPreviewRedraw;
     278end;
     279
    247280procedure TFormNew.SpinEditMapSizeXChange(Sender: TObject);
    248281begin
    249282  TrackBarSizeX.Position := SpinEditMapSizeX.Value;
     283  MapPreviewRedraw;
    250284end;
    251285
     
    253287begin
    254288  TrackBarSizeY.Position := SpinEditMapSizeY.Value;
     289  MapPreviewRedraw;
    255290end;
    256291
     
    260295end;
    261296
     297procedure TFormNew.SpinEditNeutralUnitsChange(Sender: TObject);
     298begin
     299  MapPreviewRedraw;
     300end;
     301
     302procedure TFormNew.SpinEditVoidPercentChange(Sender: TObject);
     303begin
     304  MapPreviewRedraw;
     305end;
     306
     307procedure TFormNew.TabSheetMapShow(Sender: TObject);
     308begin
     309  MapPreviewRedraw;
     310end;
     311
     312procedure TFormNew.TimerMapPreviewTimer(Sender: TObject);
     313begin
     314  if MapPreviewRedrawPending then begin
     315    MapPreviewPaint;
     316    MapPreviewRedrawPending := False;
     317  end;
     318end;
     319
    262320procedure TFormNew.TrackBarSizeYChange(Sender: TObject);
    263321begin
     
    270328end;
    271329
    272 procedure TFormNew.Translate;
    273 var
    274   LastIndex: Integer;
    275 begin
    276   with ComboBoxGridType do begin
    277     LastIndex := ItemIndex;
    278     Clear;
    279     Items.Add(SGridTypeHexagon);
    280     Items.Add(SGridTypeSquare);
    281     Items.Add(SGridTypeTriangle);
    282     Items.Add(SGridTypeRandom);
    283     Items.Add(SGridTypeIsometric);
    284     ItemIndex := LastIndex;
    285   end;
    286   with ComboBoxWinObjective do begin
    287     LastIndex := ItemIndex;
    288     Clear;
    289     Items.Add(SWinObjectiveNone);
    290     Items.Add(SWinObjectiveDefeatAllOponents);
    291     Items.Add(SWinObjectiveDefeatAllCities);
    292     Items.Add(SWinObjectiveCapturePosition);
    293     Items.Add(SWinObjectiveStayAliveForTurns);
    294     Items.Add(SWinObjectiveCaptureEntireMap);
    295     ItemIndex := LastIndex;
    296   end;
    297   with ComboBoxMapShape do begin
    298     LastIndex := ItemIndex;
    299     Clear;
    300     Items.Add(SRectangular);
    301     Items.Add(SFromImageFile);
    302     Items.Add(SRounded);
    303     ItemIndex := LastIndex;
    304   end;
    305   with RadioGroupGrowCells do begin
    306     LastIndex := ItemIndex;
    307     Items.Clear;
    308     Items.Add(SGrowNone);
    309     Items.Add(SGrowPlayerCities);
    310     Items.Add(SGrowPlayerAllCells);
    311     ItemIndex := LastIndex;
    312   end;
    313   with RadioGroupGrowAmount do begin
    314     LastIndex := ItemIndex;
    315     Items.Clear;
    316     Items.Add(SGrowAmountByOne);
    317     Items.Add(SGrowAmountBySquareRoot);
    318     ItemIndex := LastIndex;
    319   end;
    320   Core.CoolTranslator1.TranslateComponentRecursive(Self);
    321 end;
    322 
    323 procedure TFormNew.ReloadView;
    324 begin
    325   ListViewPlayers.Items.Count := Players.Count;
    326   ListViewPlayers.Refresh;
    327   ListViewServers.Items.Count := ServerList.Items.Count;
    328   ListViewServers.Refresh;
    329   Translate;
    330   UpdateInterface;
    331 end;
    332 
    333 procedure TFormNew.UpdateInterface;
    334 var
    335   WinObjective: TWinObjective;
    336 begin
    337   APlayerRemove.Enabled := Assigned(ListViewPlayers.Selected) and (Players.Count > MinPlayerCount);
    338   APlayerAdd.Enabled := Players.Count < MaxPlayerCount;
    339   APlayerModify.Enabled := Assigned(ListViewPlayers.Selected);
    340   EditImageFile.Enabled := ComboBoxMapShape.ItemIndex = Integer(msImage);
    341   ButtonImageBrowse.Enabled := ComboBoxMapShape.ItemIndex = Integer(msImage);
    342   EditServerAddress.Enabled := RadioButtonModeNetworkServer.Checked;
    343   SpinEditServerPort.Enabled := RadioButtonModeNetworkServer.Checked;
    344   ListViewServers.Enabled := RadioButtonModeNetworkClient.Checked;
    345   PanelChat.Visible := RadioButtonModeNetworkClient.Checked or RadioButtonModeNetworkServer.Checked;
    346   SpinEditNeutralUnits.MaxValue := SpinEditMaxPower.Value;
    347   AServerRemove.Enabled := RadioButtonModeNetworkClient.Checked and Assigned(ListViewServers.Selected);
    348   AServerAdd.Enabled := RadioButtonModeNetworkClient.Checked;
    349   AServerModify.Enabled := RadioButtonModeNetworkClient.Checked;
    350   WinObjective := TWinObjective(ComboBoxWinObjective.ItemIndex);
    351   case WinObjective of
    352     woNone: PageControlWinObjective.TabIndex := PageControlWinObjective.IndexOf(TabSheetNone);
    353     woDefeatAllOponents: PageControlWinObjective.TabIndex := PageControlWinObjective.IndexOf(TabSheetDefeatEnemies);
    354     woDefeatAllOponentsCities: PageControlWinObjective.TabIndex := PageControlWinObjective.IndexOf(TabSheetCaptureCities);
    355     woSpecialCaptureCell: PageControlWinObjective.TabIndex := PageControlWinObjective.IndexOf(TabSheetCaptureCells);
    356     woStayAliveForDefinedTurns: PageControlWinObjective.TabIndex := PageControlWinObjective.IndexOf(TabSheetStayAliveTurns);
    357     woCaptureEntireMap: PageControlWinObjective.TabIndex := PageControlWinObjective.IndexOf(TabSheetCaptureEntireMap);
    358   end;
    359 end;
    360 
    361 procedure TFormNew.FormShow(Sender: TObject);
    362 begin
    363   Core.PersistentForm.Load(Self);
    364   Core.ThemeManager1.UseTheme(Self);
    365   ReloadView;
    366   //Height := Trunc(1.5 * Height);
    367   //PageControl1.TabIndex := 0;
    368   {$IFNDEF DEBUG}
    369   TabSheetMode.TabVisible := False;
    370   TabSheetMode.Enabled := False;
    371   {$ENDIF}
    372 end;
    373 
    374 procedure TFormNew.ListViewPlayersCustomDrawSubItem(Sender: TCustomListView;
    375   Item: TListItem; SubItem: Integer; State: TCustomDrawState;
    376   var DefaultDraw: Boolean);
    377 begin
    378   if SubItem = 2 then
    379   with ListViewPlayers.Canvas do begin
    380     Brush.Color := TPlayer(Item.Data).Color;
    381     Brush.Style := bsSolid;
    382     FillRect(Item.DisplayRectSubItem(2, drBounds));
    383   end;
    384 end;
    385 
    386 procedure TFormNew.FormCreate(Sender: TObject);
    387 begin
    388   Players := TPlayers.Create;
    389   ServerList := TServerList.Create;
    390   FormChat := TFormChat.Create(nil);
    391   FormChat.ManualDock(PanelChat, nil, alClient);
    392   FormChat.Align := alClient;
    393   FormChat.Show;
    394   Translate;
    395 end;
    396 
    397 procedure TFormNew.CheckBoxCityChange(Sender: TObject);
    398 begin
    399   SpinEditCityPercent.Enabled := CheckBoxCity.Checked;
    400 end;
    401 
    402 procedure TFormNew.CheckBoxVoidChange(Sender: TObject);
    403 begin
    404   SpinEditVoidPercent.Enabled := CheckBoxVoid.Checked;
    405 end;
    406 
    407 procedure TFormNew.ComboBoxMapShapeChange(Sender: TObject);
    408 begin
    409   ReloadView;
    410 end;
    411 
    412 procedure TFormNew.ComboBoxWinObjectiveChange(Sender: TObject);
    413 begin
    414   UpdateInterface;
    415 end;
    416 
    417 procedure TFormNew.FormClose(Sender: TObject; var CloseAction: TCloseAction);
    418 begin
    419   Core.PersistentForm.Save(Self);
    420 end;
    421 
    422 procedure TFormNew.APlayerModifyExecute(Sender: TObject);
    423 begin
    424   FormPlayer := TFormPlayer.Create(nil);
    425   try
    426     if Assigned(ListViewPlayers.Selected) then begin
    427       FormPlayer.Load(TPlayer(ListViewPlayers.Selected.Data));
    428        if FormPlayer.ShowModal = mrOk then begin
    429          FormPlayer.Save(TPlayer(ListViewPlayers.Selected.Data));
    430          ReloadView;
    431       end;
    432     end;
    433   finally
    434     FormPlayer.Free;
    435   end;
    436 end;
    437 
    438 procedure TFormNew.APlayerRemoveExecute(Sender: TObject);
    439 var
    440   I: Integer;
    441 begin
    442   for I := ListViewPlayers.Items.Count - 1 downto 0 do
    443   if ListViewPlayers.Items[I].Selected then begin
    444     Players.Remove(ListViewPlayers.Items[I].Data);
    445     if Players.Count <= MinPlayerCount then Break;
    446   end;
    447   ReloadView;
    448 end;
    449 
    450 procedure TFormNew.AServerAddExecute(Sender: TObject);
    451 var
    452   NewServer: TServerInfo;
    453 begin
    454   FormServer := TFormServer.Create(nil);
    455   NewServer := TServerInfo.Create;
    456   FormServer.Load(NewServer);
    457   if FormServer.ShowModal = mrOK then begin
    458     FormServer.Save(NewServer);
    459     ServerList.Items.Add(NewServer);
    460     ReloadView;
    461   end else NewServer.Free;
    462   FormServer.Free;
    463 end;
    464 
    465 procedure TFormNew.AServerModifyExecute(Sender: TObject);
    466 var
    467   Server: TServerInfo;
    468 begin
    469   FormServer := TFormServer.Create(nil);
    470   Server := TServerInfo(ListViewServers.Selected.Data);
    471   FormServer.Load(Server);
    472   if FormServer.ShowModal = mrOK then begin
    473     FormServer.Save(Server);
    474     ReloadView;
    475   end;
    476   FormServer.Free;
    477 end;
    478 
    479 procedure TFormNew.AServerRemoveExecute(Sender: TObject);
    480 var
    481   I: Integer;
    482 begin
    483   if MessageDlg(SRemoveServer, SRemoveServerQuery,
    484   TMsgDlgType.mtConfirmation, [mbCancel, mbOk], 0) = mrOk then begin
    485     for I := ListViewServers.Items.Count - 1 downto 0 do
    486     if ListViewServers.Items[I].Selected then
    487       ServerList.Items.Delete(I);
    488     ReloadView;
    489   end;
    490 end;
    491 
    492 procedure TFormNew.ButtonImageBrowseClick(Sender: TObject);
    493 begin
    494   OpenPictureDialog1.FileName := EditImageFile.Text;
    495   if OpenPictureDialog1.Execute then begin
    496     EditImageFile.Text := OpenPictureDialog1.FileName;
    497   end;
    498 end;
    499 
    500 procedure TFormNew.APlayerAddExecute(Sender: TObject);
    501 var
    502   NewPlayer: TPlayer;
    503 begin
    504   if Players.Count <= (MaxPlayerCount - 1) then begin
    505     NewPlayer := TPlayer.Create;
    506     NewPlayer.Id := Players.GetNewId;
    507     NewPlayer.Name := SPlayer + ' ' + IntToStr(NewPlayer.Id);
    508     NewPlayer.Color := PlayerColors[Players.Count];
    509     NewPlayer.Mode := pmComputer;
    510     NewPlayer.Agressivity := caMedium;
    511     Players.Add(NewPlayer);
    512     ReloadView;
    513   end;
    514 end;
    515 
    516 procedure TFormNew.FormDestroy(Sender: TObject);
    517 begin
    518   FreeAndNil(ServerList);
    519   FreeAndNil(Players);
    520   FreeAndNil(FormChat);
    521 end;
    522 
    523 procedure TFormNew.Load(Server: TServer);
    524 begin
    525   with Server do begin
    526     RadioButtonModeLocal.Checked := Mode = smLocal;
    527     RadioButtonModeNetworkClient.Checked := Mode = smNetworkClient;
    528     RadioButtonModeNetworkServer.Checked := Mode = smNetworkServer;
    529     EditServerAddress.Text := LocalNetworkAddress;
    530     SpinEditServerPort.Value := LocalNetworkPort;
    531   end;
    532   ServerList.Assign(Core.ServerList);
    533   Players.Assign(Core.GameSettings.Players);
    534   with Core.GameSettings do begin
     330procedure TFormNew.LoadGame(Game: TGame);
     331begin
     332  Players.Assign(Game.Players);
     333  with Game do begin
    535334    CheckBoxSymetricMap.Checked := SymetricMap;
    536335    CheckBoxCyclicMap.Checked := CyclicMap;
     
    560359end;
    561360
    562 procedure TFormNew.Save(Server: TServer);
    563 begin
    564   with Server do begin
    565     if RadioButtonModeLocal.Checked then Mode := smLocal
    566     else if RadioButtonModeNetworkClient.Checked then Mode := smNetworkClient
    567     else if RadioButtonModeNetworkServer.Checked then Mode := smNetworkServer;
    568     LocalNetworkAddress := EditServerAddress.Text;
    569     LocalNetworkPort := SpinEditServerPort.Value;
    570     if Assigned(ListViewServers.Selected) then begin
    571       RemoteNetworkAddress := TServerInfo(ListViewServers.Selected.Data).Address;
    572       RemoteNetworkPort := TServerInfo(ListViewServers.Selected.Data).Port;
    573     end else begin
    574       RemoteNetworkAddress := '';
    575       RemoteNetworkPort := 0;
    576     end;
    577   end;
    578   Core.GameSettings.Players.Assign(Players);
    579   Core.ServerList.Assign(ServerList);
    580   with Core.GameSettings do begin
     361procedure TFormNew.SaveGame(Game: TGame);
     362begin
     363  Game.Players.Assign(Players);
     364  with Game do begin
    581365    SymetricMap := CheckBoxSymetricMap.Checked;
    582366    CyclicMap := CheckBoxCyclicMap.Checked;
     
    603387end;
    604388
     389procedure TFormNew.MapPreviewRedraw;
     390begin
     391  MapPreviewRedrawPending := True;
     392end;
     393
     394procedure TFormNew.MapPreviewPaint;
     395var
     396  Client: TClientGUI;
     397  Bitmap: TBitmap;
     398begin
     399  GamePreview.GameSystem := Core.GameSystems.First;
     400  SaveGame(GamePreview);
     401  GamePreview.PostConfig;
     402  GamePreview.New;
     403  GamePreview.CurrentPlayer := GamePreview.Players.First;
     404  Bitmap := Image1.Picture.Bitmap;
     405  Bitmap.SetSize(Image1.Width, Image1.Height);
     406  Client := TClientGUI.Create;
     407  Client.Game := GamePreview;
     408  Client.View.Game := GamePreview;
     409  Client.View.DestRect := TRect.Create(TPoint.Create(0, 0), TPoint.Create(Image1.Width, Image1.Height));
     410  Client.View.ZoomAll;
     411  Client.ControlPlayer := GamePreview.Players.First;
     412  Client.ShowCellGrid := True;
     413  Bitmap.Canvas.Brush.Color := MapBackgroundColor; //clBackground; //PaintBox1.GetColorResolvingParent;
     414  Bitmap.Canvas.FillRect(0, 0, Bitmap.Width, Bitmap.Height);
     415  Client.Paint(Bitmap.Canvas, Client.View);
     416  Client.Free;
     417end;
     418
     419procedure TFormNew.Translate;
     420var
     421  LastIndex: Integer;
     422begin
     423  with ComboBoxGridType do begin
     424    LastIndex := ItemIndex;
     425    Clear;
     426    Items.Add(SGridTypeHexagon);
     427    Items.Add(SGridTypeSquare);
     428    Items.Add(SGridTypeTriangle);
     429    Items.Add(SGridTypeRandom);
     430    Items.Add(SGridTypeIsometric);
     431    ItemIndex := LastIndex;
     432  end;
     433  with ComboBoxWinObjective do begin
     434    LastIndex := ItemIndex;
     435    Clear;
     436    Items.Add(SWinObjectiveNone);
     437    Items.Add(SWinObjectiveDefeatAllOponents);
     438    Items.Add(SWinObjectiveDefeatAllCities);
     439    Items.Add(SWinObjectiveCapturePosition);
     440    Items.Add(SWinObjectiveStayAliveForTurns);
     441    Items.Add(SWinObjectiveCaptureEntireMap);
     442    ItemIndex := LastIndex;
     443  end;
     444  with ComboBoxMapShape do begin
     445    LastIndex := ItemIndex;
     446    Clear;
     447    Items.Add(SRectangular);
     448    Items.Add(SFromImageFile);
     449    Items.Add(SRounded);
     450    ItemIndex := LastIndex;
     451  end;
     452  with RadioGroupGrowCells do begin
     453    LastIndex := ItemIndex;
     454    Items.Clear;
     455    Items.Add(SGrowNone);
     456    Items.Add(SGrowPlayerCities);
     457    Items.Add(SGrowPlayerAllCells);
     458    ItemIndex := LastIndex;
     459  end;
     460  with RadioGroupGrowAmount do begin
     461    LastIndex := ItemIndex;
     462    Items.Clear;
     463    Items.Add(SGrowAmountByOne);
     464    Items.Add(SGrowAmountBySquareRoot);
     465    ItemIndex := LastIndex;
     466  end;
     467  Core.CoolTranslator1.TranslateComponentRecursive(Self);
     468end;
     469
     470procedure TFormNew.ReloadView;
     471begin
     472  ListViewPlayers.Items.Count := Players.Count;
     473  ListViewPlayers.Refresh;
     474  ListViewServers.Items.Count := ServerList.Items.Count;
     475  ListViewServers.Refresh;
     476  Translate;
     477  UpdateInterface;
     478end;
     479
     480procedure TFormNew.UpdateInterface;
     481var
     482  WinObjective: TWinObjective;
     483begin
     484  APlayerRemove.Enabled := Assigned(ListViewPlayers.Selected) and (Players.Count > MinPlayerCount);
     485  APlayerAdd.Enabled := Players.Count < MaxPlayerCount;
     486  APlayerModify.Enabled := Assigned(ListViewPlayers.Selected);
     487  EditImageFile.Enabled := ComboBoxMapShape.ItemIndex = Integer(msImage);
     488  ButtonImageBrowse.Enabled := ComboBoxMapShape.ItemIndex = Integer(msImage);
     489  EditServerAddress.Enabled := RadioButtonModeNetworkServer.Checked;
     490  SpinEditServerPort.Enabled := RadioButtonModeNetworkServer.Checked;
     491  ListViewServers.Enabled := RadioButtonModeNetworkClient.Checked;
     492  PanelChat.Visible := RadioButtonModeNetworkClient.Checked or RadioButtonModeNetworkServer.Checked;
     493  SpinEditNeutralUnits.MaxValue := SpinEditMaxPower.Value;
     494  AServerRemove.Enabled := RadioButtonModeNetworkClient.Checked and Assigned(ListViewServers.Selected);
     495  AServerAdd.Enabled := RadioButtonModeNetworkClient.Checked;
     496  AServerModify.Enabled := RadioButtonModeNetworkClient.Checked;
     497  WinObjective := TWinObjective(ComboBoxWinObjective.ItemIndex);
     498  case WinObjective of
     499    woNone: PageControlWinObjective.TabIndex := PageControlWinObjective.IndexOf(TabSheetNone);
     500    woDefeatAllOponents: PageControlWinObjective.TabIndex := PageControlWinObjective.IndexOf(TabSheetDefeatEnemies);
     501    woDefeatAllOponentsCities: PageControlWinObjective.TabIndex := PageControlWinObjective.IndexOf(TabSheetCaptureCities);
     502    woSpecialCaptureCell: PageControlWinObjective.TabIndex := PageControlWinObjective.IndexOf(TabSheetCaptureCells);
     503    woStayAliveForDefinedTurns: PageControlWinObjective.TabIndex := PageControlWinObjective.IndexOf(TabSheetStayAliveTurns);
     504    woCaptureEntireMap: PageControlWinObjective.TabIndex := PageControlWinObjective.IndexOf(TabSheetCaptureEntireMap);
     505  end;
     506end;
     507
     508procedure TFormNew.FormShow(Sender: TObject);
     509begin
     510  Core.PersistentForm.Load(Self);
     511  Core.ThemeManager1.UseTheme(Self);
     512  ReloadView;
     513  //Height := Trunc(1.5 * Height);
     514  //PageControl1.TabIndex := 0;
     515  {$IFNDEF DEBUG}
     516  TabSheetMode.TabVisible := False;
     517  TabSheetMode.Enabled := False;
     518  {$ENDIF}
     519end;
     520
     521procedure TFormNew.ListViewPlayersCustomDrawSubItem(Sender: TCustomListView;
     522  Item: TListItem; SubItem: Integer; State: TCustomDrawState;
     523  var DefaultDraw: Boolean);
     524begin
     525  if SubItem = 2 then
     526  with ListViewPlayers.Canvas do begin
     527    Brush.Color := TPlayer(Item.Data).Color;
     528    Brush.Style := bsSolid;
     529    FillRect(Item.DisplayRectSubItem(2, drBounds));
     530  end;
     531end;
     532
     533procedure TFormNew.FormCreate(Sender: TObject);
     534begin
     535  GamePreview := TGame.Create;
     536  Players := TPlayers.Create;
     537  ServerList := TServerList.Create;
     538  FormChat := TFormChat.Create(nil);
     539  FormChat.ManualDock(PanelChat, nil, alClient);
     540  FormChat.Align := alClient;
     541  FormChat.Show;
     542  Translate;
     543end;
     544
     545procedure TFormNew.CheckBoxCityChange(Sender: TObject);
     546begin
     547  SpinEditCityPercent.Enabled := CheckBoxCity.Checked;
     548  MapPreviewRedraw;
     549end;
     550
     551procedure TFormNew.CheckBoxCyclicMapChange(Sender: TObject);
     552begin
     553  MapPreviewRedraw;
     554end;
     555
     556procedure TFormNew.CheckBoxSymetricMapChange(Sender: TObject);
     557begin
     558  MapPreviewRedraw;
     559end;
     560
     561procedure TFormNew.CheckBoxVoidChange(Sender: TObject);
     562begin
     563  SpinEditVoidPercent.Enabled := CheckBoxVoid.Checked;
     564  MapPreviewRedraw;
     565end;
     566
     567procedure TFormNew.ComboBoxGridTypeChange(Sender: TObject);
     568begin
     569  MapPreviewRedraw;
     570end;
     571
     572procedure TFormNew.ComboBoxMapShapeChange(Sender: TObject);
     573begin
     574  ReloadView;
     575  MapPreviewRedraw;
     576end;
     577
     578procedure TFormNew.ComboBoxWinObjectiveChange(Sender: TObject);
     579begin
     580  UpdateInterface;
     581end;
     582
     583procedure TFormNew.EditImageFileChange(Sender: TObject);
     584begin
     585  MapPreviewRedraw;
     586end;
     587
     588procedure TFormNew.FormClose(Sender: TObject; var CloseAction: TCloseAction);
     589begin
     590  Core.PersistentForm.Save(Self);
     591end;
     592
     593procedure TFormNew.APlayerModifyExecute(Sender: TObject);
     594begin
     595  FormPlayer := TFormPlayer.Create(nil);
     596  try
     597    if Assigned(ListViewPlayers.Selected) then begin
     598      FormPlayer.Load(TPlayer(ListViewPlayers.Selected.Data));
     599       if FormPlayer.ShowModal = mrOk then begin
     600         FormPlayer.Save(TPlayer(ListViewPlayers.Selected.Data));
     601         ReloadView;
     602      end;
     603    end;
     604  finally
     605    FormPlayer.Free;
     606  end;
     607end;
     608
     609procedure TFormNew.APlayerRemoveExecute(Sender: TObject);
     610var
     611  I: Integer;
     612begin
     613  for I := ListViewPlayers.Items.Count - 1 downto 0 do
     614  if ListViewPlayers.Items[I].Selected then begin
     615    Players.Remove(ListViewPlayers.Items[I].Data);
     616    if Players.Count <= MinPlayerCount then Break;
     617  end;
     618  ReloadView;
     619end;
     620
     621procedure TFormNew.AServerAddExecute(Sender: TObject);
     622var
     623  NewServer: TServerInfo;
     624begin
     625  FormServer := TFormServer.Create(nil);
     626  NewServer := TServerInfo.Create;
     627  FormServer.Load(NewServer);
     628  if FormServer.ShowModal = mrOK then begin
     629    FormServer.Save(NewServer);
     630    ServerList.Items.Add(NewServer);
     631    ReloadView;
     632  end else NewServer.Free;
     633  FormServer.Free;
     634end;
     635
     636procedure TFormNew.AServerModifyExecute(Sender: TObject);
     637var
     638  Server: TServerInfo;
     639begin
     640  FormServer := TFormServer.Create(nil);
     641  Server := TServerInfo(ListViewServers.Selected.Data);
     642  FormServer.Load(Server);
     643  if FormServer.ShowModal = mrOK then begin
     644    FormServer.Save(Server);
     645    ReloadView;
     646  end;
     647  FormServer.Free;
     648end;
     649
     650procedure TFormNew.AServerRemoveExecute(Sender: TObject);
     651var
     652  I: Integer;
     653begin
     654  if MessageDlg(SRemoveServer, SRemoveServerQuery,
     655  TMsgDlgType.mtConfirmation, [mbCancel, mbOk], 0) = mrOk then begin
     656    for I := ListViewServers.Items.Count - 1 downto 0 do
     657    if ListViewServers.Items[I].Selected then
     658      ServerList.Items.Delete(I);
     659    ReloadView;
     660  end;
     661end;
     662
     663procedure TFormNew.ButtonImageBrowseClick(Sender: TObject);
     664begin
     665  OpenPictureDialog1.FileName := EditImageFile.Text;
     666  if OpenPictureDialog1.Execute then begin
     667    EditImageFile.Text := OpenPictureDialog1.FileName;
     668  end;
     669end;
     670
     671procedure TFormNew.CheckBoxBridgesChange(Sender: TObject);
     672begin
     673  MapPreviewRedraw;
     674end;
     675
     676procedure TFormNew.APlayerAddExecute(Sender: TObject);
     677var
     678  NewPlayer: TPlayer;
     679begin
     680  if Players.Count <= (MaxPlayerCount - 1) then begin
     681    NewPlayer := TPlayer.Create;
     682    NewPlayer.Id := Players.GetNewId;
     683    NewPlayer.Name := SPlayer + ' ' + IntToStr(NewPlayer.Id);
     684    NewPlayer.Color := PlayerColors[Players.Count];
     685    NewPlayer.Mode := pmComputer;
     686    NewPlayer.Agressivity := caMedium;
     687    Players.Add(NewPlayer);
     688    ReloadView;
     689  end;
     690end;
     691
     692procedure TFormNew.FormDestroy(Sender: TObject);
     693begin
     694  FreeAndNil(ServerList);
     695  FreeAndNil(Players);
     696  FreeAndNil(FormChat);
     697  FreeAndNil(GamePreview);
     698end;
     699
     700procedure TFormNew.Load(Server: TServer);
     701begin
     702  with Server do begin
     703    RadioButtonModeLocal.Checked := Mode = smLocal;
     704    RadioButtonModeNetworkClient.Checked := Mode = smNetworkClient;
     705    RadioButtonModeNetworkServer.Checked := Mode = smNetworkServer;
     706    EditServerAddress.Text := LocalNetworkAddress;
     707    SpinEditServerPort.Value := LocalNetworkPort;
     708  end;
     709  ServerList.Assign(Core.ServerList);
     710  LoadGame(Core.GameSettings);
     711end;
     712
     713procedure TFormNew.Save(Server: TServer);
     714begin
     715  with Server do begin
     716    if RadioButtonModeLocal.Checked then Mode := smLocal
     717    else if RadioButtonModeNetworkClient.Checked then Mode := smNetworkClient
     718    else if RadioButtonModeNetworkServer.Checked then Mode := smNetworkServer;
     719    LocalNetworkAddress := EditServerAddress.Text;
     720    LocalNetworkPort := SpinEditServerPort.Value;
     721    if Assigned(ListViewServers.Selected) then begin
     722      RemoteNetworkAddress := TServerInfo(ListViewServers.Selected.Data).Address;
     723      RemoteNetworkPort := TServerInfo(ListViewServers.Selected.Data).Port;
     724    end else begin
     725      RemoteNetworkAddress := '';
     726      RemoteNetworkPort := 0;
     727    end;
     728  end;
     729  Core.ServerList.Assign(ServerList);
     730  SaveGame(Core.GameSettings);
     731end;
     732
    605733end.
    606734
  • trunk/Languages/xtactics.cs.po

    r268 r269  
    457457msgid "Special cells count:"
    458458msgstr "Počet speciálních buněk:"
     459
     460#: tformnew.label15.caption
     461msgid "Random preview:"
     462msgstr "Náhodný náhled:"
    459463
    460464#: tformnew.label2.caption
  • trunk/Languages/xtactics.po

    r268 r269  
    442442#: tformnew.label14.caption
    443443msgid "Special cells count:"
     444msgstr ""
     445
     446#: tformnew.label15.caption
     447msgid "Random preview:"
    444448msgstr ""
    445449
  • trunk/UClientGUI.pas

    r268 r269  
    3030    procedure CenterMap;
    3131    procedure CenterPlayerCity(Player: TPlayer);
     32    procedure ZoomAll;
    3233    function CanvasToCellPos(Pos: TPoint): TPoint;
    3334    function CellToCanvasPos(Pos: TPoint): TPoint;
     
    7677procedure TClientGUI.Paint(Canvas: TCanvas; View: TView);
    7778begin
     79  DrawCellLinks(Canvas, View);
    7880  DrawCells(Canvas, View);
     81  DrawCities(Canvas, View);
     82  DrawSelection(Canvas, View);
     83  DrawArrows(Canvas, View);
    7984  if TGame(Game).DevelMode then DrawNeighborLinks(Canvas, View);
    8085end;
     
    305310  MapCell: TCell;
    306311  CellText: string;
    307   Points: array of Classes.TPoint;
    308   I: Integer;
    309312begin
    310313  with Canvas, View do begin
     
    403406  Cell: TPlayerCell;
    404407  MapCell: TCell;
    405   CellText: string;
    406408  Points: array of Classes.TPoint;
    407409  I: Integer;
     
    454456procedure TClientGUI.DrawSelection(Canvas: TCanvas; View: TView);
    455457var
    456   Cell: TPlayerCell;
    457   MapCell: TCell;
    458   CellText: string;
    459458  Points: array of Classes.TPoint;
    460459  I: Integer;
     
    641640end;
    642641
     642procedure TView.ZoomAll;
     643var
     644  Factor: TPointF;
     645  MapRect: TRect;
     646  NewZoom: Single;
     647begin
     648  MapRect := TGame(Game).Map.CalculatePixelRect;
     649  Factor := TPointF.Create(DestRect.Size.X / MapRect.Size.X,
     650    DestRect.Size.Y / MapRect.Size.Y);
     651  if Factor.X < Factor.Y then NewZoom := Factor.X
     652    else NewZoom := Factor.Y;
     653  if NewZoom = 0 then NewZoom := 1;
     654  Zoom := NewZoom;
     655  CenterMap;
     656end;
     657
    643658function TView.IsCellVisible(Cell: TCell): Boolean;
    644659var
Note: See TracChangeset for help on using the changeset viewer.