1 | {$INCLUDE Switches.inc}
|
---|
2 | unit Log;
|
---|
3 |
|
---|
4 | interface
|
---|
5 |
|
---|
6 | uses
|
---|
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 |
|
---|
11 | type
|
---|
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 |
|
---|
42 | var
|
---|
43 | LogDlg: TLogDlg;
|
---|
44 |
|
---|
45 |
|
---|
46 | implementation
|
---|
47 |
|
---|
48 | uses
|
---|
49 | ClientTools, Tribes;
|
---|
50 |
|
---|
51 | {$R *.lfm}
|
---|
52 |
|
---|
53 | const
|
---|
54 | MaxLines = 1000;
|
---|
55 |
|
---|
56 | procedure TLogDlg.FormCreate(Sender: TObject);
|
---|
57 | begin
|
---|
58 | MaxLevel := 0;
|
---|
59 | end;
|
---|
60 |
|
---|
61 | procedure TLogDlg.mLogClick(Sender: TObject);
|
---|
62 | begin
|
---|
63 | MaxLevel := TMenuItem(Sender).Tag;
|
---|
64 | TMenuItem(Sender).Checked := True;
|
---|
65 | end;
|
---|
66 |
|
---|
67 | procedure TLogDlg.Add(Level, Turn: Integer; Text: PChar);
|
---|
68 | begin
|
---|
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;
|
---|
80 | end;
|
---|
81 |
|
---|
82 | procedure TLogDlg.mClearClick(Sender: TObject);
|
---|
83 | begin
|
---|
84 | List.Clear;
|
---|
85 | end;
|
---|
86 |
|
---|
87 | procedure TLogDlg.mSlotClick(Sender: TObject);
|
---|
88 | const
|
---|
89 | SlotNo: array [0 .. 2, 0 .. 2] of Integer = ((8, 1, 2), (7, 0, 3), (6, 5, 4));
|
---|
90 | var
|
---|
91 | X, Y: Integer;
|
---|
92 | S: string;
|
---|
93 | begin
|
---|
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);
|
---|
116 | end;
|
---|
117 |
|
---|
118 | procedure TLogDlg.FormKeyDown(Sender: TObject; var Key: Word;
|
---|
119 | Shift: TShiftState);
|
---|
120 | begin
|
---|
121 | if Host <> nil then
|
---|
122 | Host.OnKeyDown(Sender, Key, Shift);
|
---|
123 | end;
|
---|
124 |
|
---|
125 | procedure TLogDlg.Toggle(Sender: TObject);
|
---|
126 | begin
|
---|
127 | TMenuItem(Sender).Checked := not TMenuItem(Sender).Checked;
|
---|
128 | end;
|
---|
129 |
|
---|
130 | procedure TLogDlg.ListMouseDown(Sender: TObject; Button: TMouseButton;
|
---|
131 | Shift: TShiftState; X, Y: Integer);
|
---|
132 | begin
|
---|
133 | if Button = TMouseButton.mbRight then
|
---|
134 | LogPopup.Popup(Left + X, Top + Y);
|
---|
135 | end;
|
---|
136 |
|
---|
137 | procedure TLogDlg.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
|
---|
138 | begin
|
---|
139 | if Host <> nil then
|
---|
140 | Host.OnKeyUp(Sender, Key, Shift);
|
---|
141 | end;
|
---|
142 |
|
---|
143 | end.
|
---|