source: tags/1.3.6/Log.pas

Last change on this file was 531, checked in by chronos, 8 months ago
  • Modified: Code cleanup.
File size: 3.7 KB
Line 
1{$INCLUDE Switches.inc}
2unit Log;
3
4interface
5
6uses
7 LCLIntf, LCLType, Messages, SysUtils, Classes,
8 {$IFDEF DPI}Dpi.Graphics, Dpi.Controls, Dpi.Forms, Dpi.StdCtrls, Dpi.Menus{$ELSE}
9 Graphics, Controls, Forms, StdCtrls, Menus{$ENDIF};
10
11type
12 TLogDlg = class(TForm)
13 LogPopup: TPopupMenu;
14 mLog0: TMenuItem;
15 mLog1: TMenuItem;
16 mLog2: TMenuItem;
17 mLog3: TMenuItem;
18 N1: TMenuItem;
19 mClear: TMenuItem;
20 mSlot: TMenuItem;
21 N2: TMenuItem;
22 mInvalid: TMenuItem;
23 mTime: TMenuItem;
24 List: TMemo;
25 mNegotiation: TMenuItem;
26 procedure mLogClick(Sender: TObject);
27 procedure FormCreate(Sender: TObject);
28 procedure mClearClick(Sender: TObject);
29 procedure mSlotClick(Sender: TObject);
30 procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
31 procedure Toggle(Sender: TObject);
32 procedure ListMouseDown(Sender: TObject; Button: TMouseButton;
33 Shift: TShiftState; X, Y: Integer);
34 procedure FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
35 public
36 Host: TForm;
37 procedure Add(Level, Turn: Integer; Text: PChar);
38 private
39 MaxLevel: Integer;
40 end;
41
42var
43 LogDlg: TLogDlg;
44
45
46implementation
47
48uses
49 ClientTools, Tribes;
50
51{$R *.lfm}
52
53const
54 MaxLines = 1000;
55
56procedure TLogDlg.FormCreate(Sender: TObject);
57begin
58 MaxLevel := 0;
59end;
60
61procedure TLogDlg.mLogClick(Sender: TObject);
62begin
63 MaxLevel := TMenuItem(Sender).Tag;
64 TMenuItem(Sender).Checked := True;
65end;
66
67procedure TLogDlg.Add(Level, Turn: Integer; Text: PChar);
68begin
69 if (MaxLevel > 0) and (Level <= MaxLevel) or (Level = 1 shl 16 + 1) and
70 mInvalid.Checked or (Level = 1 shl 16 + 2) and mTime.Checked or
71 (Level = 1 shl 16 + 3) and mNegotiation.Checked then
72 begin
73 if List.Lines.Count = MaxLines then
74 List.Lines.Delete(0);
75 List.Lines.Add(Char(48 + Turn div 100 mod 10) +
76 Char(48 + Turn div 10 mod 10) + Char(48 + Turn mod 10) + ' ' + Text);
77 PostMessage(List.Handle, WM_VSCROLL, SB_BOTTOM, 0);
78 Update;
79 end;
80end;
81
82procedure TLogDlg.mClearClick(Sender: TObject);
83begin
84 List.Clear;
85end;
86
87procedure TLogDlg.mSlotClick(Sender: TObject);
88const
89 SlotNo: array [0 .. 2, 0 .. 2] of Integer = ((8, 1, 2), (7, 0, 3), (6, 5, 4));
90var
91 X, Y: Integer;
92 S: string;
93begin
94 for Y := 0 to 2 do
95 begin
96 S := '| ';
97 for X := 0 to 2 do
98 if G.Difficulty[SlotNo[Y, X]] = 0 then
99 S := S + 'SUP |'
100 else if G.Difficulty[SlotNo[Y, X]] < 0 then
101 S := S + '--- |'
102 else
103 begin
104 if SlotNo[Y, X] in [6 .. 8] then
105 begin // check multi control
106 if G.Difficulty[SlotNo[Y, X] + 3] >= 0 then
107 S := S + Tribe[SlotNo[Y, X] + 3].TPhrase('SHORTNAME') + '+';
108 if G.Difficulty[SlotNo[Y, X] + 6] >= 0 then
109 S := S + Tribe[SlotNo[Y, X] + 6].TPhrase('SHORTNAME') + '+';
110 end;
111 S := S + Tribe[SlotNo[Y, X]].TPhrase('SHORTNAME') + ' | ';
112 end;
113 List.Lines.Add(S);
114 end;
115 PostMessage(List.Handle, WM_VSCROLL, SB_BOTTOM, 0);
116end;
117
118procedure TLogDlg.FormKeyDown(Sender: TObject; var Key: Word;
119 Shift: TShiftState);
120begin
121 if Host <> nil then
122 Host.OnKeyDown(Sender, Key, Shift);
123end;
124
125procedure TLogDlg.Toggle(Sender: TObject);
126begin
127 TMenuItem(Sender).Checked := not TMenuItem(Sender).Checked;
128end;
129
130procedure TLogDlg.ListMouseDown(Sender: TObject; Button: TMouseButton;
131 Shift: TShiftState; X, Y: Integer);
132begin
133 if Button = TMouseButton.mbRight then
134 LogPopup.Popup(Left + X, Top + Y);
135end;
136
137procedure TLogDlg.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
138begin
139 if Host <> nil then
140 Host.OnKeyUp(Sender, Key, Shift);
141end;
142
143end.
Note: See TracBrowser for help on using the repository browser.