close Warning: Can't synchronize with repository "(default)" (No changeset 184 in the repository). Look in the Trac log for more information.

source: trunk/Forms/UFormCharts.pas

Last change on this file was 181, checked in by chronos, 6 years ago
  • Added: New window with players statistics.
File size: 2.3 KB
Line 
1unit UFormCharts;
2
3{$mode delphi}
4
5interface
6
7uses
8 Classes, SysUtils, FileUtil, TAGraph, TASeries, Forms, Controls, Graphics,
9 Dialogs, StdCtrls;
10
11type
12
13 { TFormCharts }
14
15 TFormCharts = class(TForm)
16 Chart1: TChart;
17 ComboBox1: TComboBox;
18 procedure ComboBox1Change(Sender: TObject);
19 procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
20 procedure FormShow(Sender: TObject);
21 private
22 { private declarations }
23 public
24 procedure Redraw;
25 procedure Translate;
26 end;
27
28var
29 FormCharts: TFormCharts;
30
31implementation
32
33{$R *.lfm}
34
35uses
36 UCore, UGame;
37
38resourcestring
39 SOccupiedCells = 'Occupied cells';
40 SMilitaryPower = 'Military power';
41 SDiscoveredCells = 'Discovered cells';
42 SCitiesCount = 'Cities count';
43
44
45{ TFormCharts }
46
47procedure TFormCharts.ComboBox1Change(Sender: TObject);
48begin
49 Redraw;
50end;
51
52procedure TFormCharts.FormClose(Sender: TObject; var CloseAction: TCloseAction);
53begin
54 Core.PersistentForm.Save(Self);
55end;
56
57procedure TFormCharts.FormShow(Sender: TObject);
58begin
59 Core.PersistentForm.Load(Self);
60 if (ComboBox1.ItemIndex = -1) and (ComboBox1.Items.Count > 0) then
61 ComboBox1.ItemIndex := 0;
62 Redraw;
63 Translate;
64end;
65
66procedure TFormCharts.Redraw;
67var
68 I: Integer;
69 X: Integer;
70 NewSeries: TLineSeries;
71begin
72 Chart1.Series.Clear;
73 for I := 0 to Core.Game.Players.Count - 1 do
74 with TPlayer(Core.Game.Players[I]) do begin
75 NewSeries := TLineSeries.Create(nil);
76 NewSeries.LinePen.Color := Color;
77 for X := 0 to TurnStats.Count - 1 do begin
78 if ComboBox1.ItemIndex = 0 then NewSeries.AddXY(X, TGameTurnStat(TurnStats[X]).OccupiedCells)
79 else if ComboBox1.ItemIndex = 1 then NewSeries.AddXY(X, TGameTurnStat(TurnStats[X]).Units)
80 else if ComboBox1.ItemIndex = 2 then NewSeries.AddXY(X, TGameTurnStat(TurnStats[X]).DiscoveredCells)
81 else if ComboBox1.ItemIndex = 3 then NewSeries.AddXY(X, TGameTurnStat(TurnStats[X]).Cities);
82 end;
83 Chart1.AddSeries(NewSeries);
84 end;
85end;
86
87procedure TFormCharts.Translate;
88var
89 LastIndex: Integer;
90begin
91 Core.CoolTranslator1.TranslateComponentRecursive(Self);
92 with ComboBox1 do begin
93 LastIndex := ItemIndex;
94 Clear;
95 Items.Add(SOccupiedCells);
96 Items.Add(SMilitaryPower);
97 Items.Add(SDiscoveredCells);
98 Items.Add(SCitiesCount);
99 ItemIndex := LastIndex;
100 end;
101end;
102
103end.
104
Note: See TracBrowser for help on using the repository browser.