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

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.