Changeset 269 for trunk/Forms/UFormNew.pas
- Timestamp:
- Jan 21, 2019, 12:38:20 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Forms/UFormNew.pas
r266 r269 43 43 EditImageFile: TEdit; 44 44 EditServerAddress: TEdit; 45 Image1: TImage; 45 46 Label1: TLabel; 46 47 Label10: TLabel; … … 49 50 Label13: TLabel; 50 51 Label14: TLabel; 52 Label15: TLabel; 51 53 Label2: TLabel; 52 54 Label3: TLabel; … … 72 74 Panel3: TPanel; 73 75 Panel4: TPanel; 76 Panel5: TPanel; 74 77 PanelButtons: TPanel; 75 78 PanelChat: TPanel; … … 91 94 SpinEditVoidPercent: TSpinEdit; 92 95 Splitter1: TSplitter; 96 TabSheetUnits: TTabSheet; 93 97 TabSheetCaptureEntireMap: TTabSheet; 94 98 TabSheetNone: TTabSheet; … … 101 105 TabSheetMode: TTabSheet; 102 106 TabSheetStayAliveTurns: TTabSheet; 107 TimerMapPreview: TTimer; 103 108 TrackBarSizeX: TTrackBar; 104 109 TrackBarSizeY: TTrackBar; … … 110 115 procedure AServerRemoveExecute(Sender: TObject); 111 116 procedure ButtonImageBrowseClick(Sender: TObject); 117 procedure CheckBoxBridgesChange(Sender: TObject); 112 118 procedure CheckBoxCityChange(Sender: TObject); 119 procedure CheckBoxCyclicMapChange(Sender: TObject); 120 procedure CheckBoxSymetricMapChange(Sender: TObject); 113 121 procedure CheckBoxVoidChange(Sender: TObject); 122 procedure ComboBoxGridTypeChange(Sender: TObject); 114 123 procedure ComboBoxMapShapeChange(Sender: TObject); 115 124 procedure ComboBoxWinObjectiveChange(Sender: TObject); 125 procedure EditImageFileChange(Sender: TObject); 116 126 procedure FormClose(Sender: TObject; var CloseAction: TCloseAction); 117 127 procedure FormCreate(Sender: TObject); … … 132 142 procedure ListViewServersSelectItem(Sender: TObject; Item: TListItem; 133 143 Selected: Boolean); 144 procedure PageControl1Change(Sender: TObject); 134 145 procedure RadioButtonModeLocalChange(Sender: TObject); 146 procedure SpinEditCityPercentChange(Sender: TObject); 135 147 procedure SpinEditMapSizeXChange(Sender: TObject); 136 148 procedure SpinEditMapSizeYChange(Sender: TObject); 137 149 procedure SpinEditMaxPowerChange(Sender: TObject); 150 procedure SpinEditNeutralUnitsChange(Sender: TObject); 151 procedure SpinEditVoidPercentChange(Sender: TObject); 152 procedure TabSheetMapShow(Sender: TObject); 153 procedure TimerMapPreviewTimer(Sender: TObject); 138 154 procedure TrackBarSizeYChange(Sender: TObject); 139 155 procedure TrackBarSizeXChange(Sender: TObject); … … 141 157 Players: TPlayers; 142 158 ServerList: TServerList; 159 GamePreview: TGame; 160 MapPreviewRedrawPending: Boolean; 161 procedure LoadGame(Game: TGame); 162 procedure SaveGame(Game: TGame); 163 procedure MapPreviewPaint; 164 procedure MapPreviewRedraw; 143 165 public 144 166 procedure Translate; … … 152 174 FormNew: TFormNew; 153 175 176 154 177 implementation 155 178 … … 157 180 158 181 uses 159 UFormPlayer, UFormChat, UCore, UFormServer ;182 UFormPlayer, UFormChat, UCore, UFormServer, UClientGUI, UFormClient; 160 183 161 184 resourcestring … … 240 263 end; 241 264 265 procedure TFormNew.PageControl1Change(Sender: TObject); 266 begin 267 MapPreviewRedraw; 268 end; 269 242 270 procedure TFormNew.RadioButtonModeLocalChange(Sender: TObject); 243 271 begin … … 245 273 end; 246 274 275 procedure TFormNew.SpinEditCityPercentChange(Sender: TObject); 276 begin 277 MapPreviewRedraw; 278 end; 279 247 280 procedure TFormNew.SpinEditMapSizeXChange(Sender: TObject); 248 281 begin 249 282 TrackBarSizeX.Position := SpinEditMapSizeX.Value; 283 MapPreviewRedraw; 250 284 end; 251 285 … … 253 287 begin 254 288 TrackBarSizeY.Position := SpinEditMapSizeY.Value; 289 MapPreviewRedraw; 255 290 end; 256 291 … … 260 295 end; 261 296 297 procedure TFormNew.SpinEditNeutralUnitsChange(Sender: TObject); 298 begin 299 MapPreviewRedraw; 300 end; 301 302 procedure TFormNew.SpinEditVoidPercentChange(Sender: TObject); 303 begin 304 MapPreviewRedraw; 305 end; 306 307 procedure TFormNew.TabSheetMapShow(Sender: TObject); 308 begin 309 MapPreviewRedraw; 310 end; 311 312 procedure TFormNew.TimerMapPreviewTimer(Sender: TObject); 313 begin 314 if MapPreviewRedrawPending then begin 315 MapPreviewPaint; 316 MapPreviewRedrawPending := False; 317 end; 318 end; 319 262 320 procedure TFormNew.TrackBarSizeYChange(Sender: TObject); 263 321 begin … … 270 328 end; 271 329 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 330 procedure TFormNew.LoadGame(Game: TGame); 331 begin 332 Players.Assign(Game.Players); 333 with Game do begin 535 334 CheckBoxSymetricMap.Checked := SymetricMap; 536 335 CheckBoxCyclicMap.Checked := CyclicMap; … … 560 359 end; 561 360 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 361 procedure TFormNew.SaveGame(Game: TGame); 362 begin 363 Game.Players.Assign(Players); 364 with Game do begin 581 365 SymetricMap := CheckBoxSymetricMap.Checked; 582 366 CyclicMap := CheckBoxCyclicMap.Checked; … … 603 387 end; 604 388 389 procedure TFormNew.MapPreviewRedraw; 390 begin 391 MapPreviewRedrawPending := True; 392 end; 393 394 procedure TFormNew.MapPreviewPaint; 395 var 396 Client: TClientGUI; 397 Bitmap: TBitmap; 398 begin 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; 417 end; 418 419 procedure TFormNew.Translate; 420 var 421 LastIndex: Integer; 422 begin 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); 468 end; 469 470 procedure TFormNew.ReloadView; 471 begin 472 ListViewPlayers.Items.Count := Players.Count; 473 ListViewPlayers.Refresh; 474 ListViewServers.Items.Count := ServerList.Items.Count; 475 ListViewServers.Refresh; 476 Translate; 477 UpdateInterface; 478 end; 479 480 procedure TFormNew.UpdateInterface; 481 var 482 WinObjective: TWinObjective; 483 begin 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; 506 end; 507 508 procedure TFormNew.FormShow(Sender: TObject); 509 begin 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} 519 end; 520 521 procedure TFormNew.ListViewPlayersCustomDrawSubItem(Sender: TCustomListView; 522 Item: TListItem; SubItem: Integer; State: TCustomDrawState; 523 var DefaultDraw: Boolean); 524 begin 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; 531 end; 532 533 procedure TFormNew.FormCreate(Sender: TObject); 534 begin 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; 543 end; 544 545 procedure TFormNew.CheckBoxCityChange(Sender: TObject); 546 begin 547 SpinEditCityPercent.Enabled := CheckBoxCity.Checked; 548 MapPreviewRedraw; 549 end; 550 551 procedure TFormNew.CheckBoxCyclicMapChange(Sender: TObject); 552 begin 553 MapPreviewRedraw; 554 end; 555 556 procedure TFormNew.CheckBoxSymetricMapChange(Sender: TObject); 557 begin 558 MapPreviewRedraw; 559 end; 560 561 procedure TFormNew.CheckBoxVoidChange(Sender: TObject); 562 begin 563 SpinEditVoidPercent.Enabled := CheckBoxVoid.Checked; 564 MapPreviewRedraw; 565 end; 566 567 procedure TFormNew.ComboBoxGridTypeChange(Sender: TObject); 568 begin 569 MapPreviewRedraw; 570 end; 571 572 procedure TFormNew.ComboBoxMapShapeChange(Sender: TObject); 573 begin 574 ReloadView; 575 MapPreviewRedraw; 576 end; 577 578 procedure TFormNew.ComboBoxWinObjectiveChange(Sender: TObject); 579 begin 580 UpdateInterface; 581 end; 582 583 procedure TFormNew.EditImageFileChange(Sender: TObject); 584 begin 585 MapPreviewRedraw; 586 end; 587 588 procedure TFormNew.FormClose(Sender: TObject; var CloseAction: TCloseAction); 589 begin 590 Core.PersistentForm.Save(Self); 591 end; 592 593 procedure TFormNew.APlayerModifyExecute(Sender: TObject); 594 begin 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; 607 end; 608 609 procedure TFormNew.APlayerRemoveExecute(Sender: TObject); 610 var 611 I: Integer; 612 begin 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; 619 end; 620 621 procedure TFormNew.AServerAddExecute(Sender: TObject); 622 var 623 NewServer: TServerInfo; 624 begin 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; 634 end; 635 636 procedure TFormNew.AServerModifyExecute(Sender: TObject); 637 var 638 Server: TServerInfo; 639 begin 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; 648 end; 649 650 procedure TFormNew.AServerRemoveExecute(Sender: TObject); 651 var 652 I: Integer; 653 begin 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; 661 end; 662 663 procedure TFormNew.ButtonImageBrowseClick(Sender: TObject); 664 begin 665 OpenPictureDialog1.FileName := EditImageFile.Text; 666 if OpenPictureDialog1.Execute then begin 667 EditImageFile.Text := OpenPictureDialog1.FileName; 668 end; 669 end; 670 671 procedure TFormNew.CheckBoxBridgesChange(Sender: TObject); 672 begin 673 MapPreviewRedraw; 674 end; 675 676 procedure TFormNew.APlayerAddExecute(Sender: TObject); 677 var 678 NewPlayer: TPlayer; 679 begin 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; 690 end; 691 692 procedure TFormNew.FormDestroy(Sender: TObject); 693 begin 694 FreeAndNil(ServerList); 695 FreeAndNil(Players); 696 FreeAndNil(FormChat); 697 FreeAndNil(GamePreview); 698 end; 699 700 procedure TFormNew.Load(Server: TServer); 701 begin 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); 711 end; 712 713 procedure TFormNew.Save(Server: TServer); 714 begin 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); 731 end; 732 605 733 end. 606 734
Note:
See TracChangeset
for help on using the changeset viewer.