-
Notifications
You must be signed in to change notification settings - Fork 3
/
ConFileProperties.pas
319 lines (267 loc) · 9.52 KB
/
ConFileProperties.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
unit ConFileProperties;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Samples.Spin, Vcl.ComCtrls, Vcl.ExtCtrls,
Conversation.Classes, vcl.GraphUtil, system.Types, ConEditPlus.Consts, system.Generics.Collections,
system.UITypes;
type
TfrmConvoFileProperties = class(TForm)
btnOk: TButton;
Panel1: TPanel;
PageControl1: TPageControl;
tsMissions: TTabSheet;
Label5: TLabel;
Label11: TLabel;
tsFlags: TTabSheet;
Label10: TLabel;
tsStats: TTabSheet;
tsInfo: TTabSheet;
btnCancel: TButton;
lstThisFileMissions: TListBox;
lstAllMissions: TListBox;
btnAddToLeft: TButton;
btnAllAddToLeft: TButton;
btnRemove: TButton;
btnRemoveAll: TButton;
mmoConvFileNotes: TMemo;
edtConvoFileAudioPackage: TEdit;
lbl1: TLabel;
lvStatistics: TListView;
lbl2: TLabel;
Label6: TLabel;
edtConFileVersion: TEdit;
edtConFileLastModifiedBy: TEdit;
Label9: TLabel;
Label8: TLabel;
edtConFileLastModifiedOn: TEdit;
edtConFileCreatedBy: TEdit;
Label7: TLabel;
Label1: TLabel;
edtConFileCreatedOn: TEdit;
btnFillStats: TButton;
lbl3: TLabel;
procedure btnCancelClick(Sender: TObject);
procedure btnAddToLeftClick(Sender: TObject);
procedure btnRemoveClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
// new procedures
procedure CheckIfCorrect();
procedure UpdateConParameters();
procedure FillMissionList();
procedure ResetAll();
procedure LoadAfterCreation();
procedure FillStats(); //
procedure FormShow(Sender: TObject);
procedure edtConvoFileAudioPackageChange(Sender: TObject);
procedure PageControl1Change(Sender: TObject);
procedure btnOkClick(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure lstAllMissionsDrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState);
procedure btnFillStatsClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmConvoFileProperties: TfrmConvoFileProperties;
implementation
uses MainWindow;
{$R *.dfm}
procedure TfrmConvoFileProperties.LoadAfterCreation(); // fill from conParameters
begin
with frmMain.conFileParameters do
begin
edtConvoFileAudioPackage.Text := fpAudioPackage;
edtConFileVersion.Text := fpFileVersion.ToString;
edtConFileCreatedOn.Text := fpCreatedByDate;
edtConFileCreatedBy.Text := fpCreatedByName;
edtConFileLastModifiedOn.Text := fpModifiedByDate;
edtConFileLastModifiedBy.Text := fpModifiedByName;
mmoConvFileNotes.Text := fpNotes;
for var i:=0 to lstAllMissions.Items.Count -1 do
begin
for var mc:= 0 to High(fpMissions) do
if lstAllMissions.Items.ValueFromIndex[i].ToInteger = fpMissions[mc] then
begin
frmMain.AddLog(lstAllMissions.Items.ValueFromIndex[i]);
lstAllMissions.Selected[i] := True; // select items we have saved before
end;
end;
end;
btnAddToLeftClick(btnAddToLeft); // "click" the button to add items from right list.
end;
procedure TfrmConvoFileProperties.FillStats(); // Note: choices must be also included
begin
if frmMain.ConversationsList.Count < 1 then
begin
MessageDlg(strStatsEmptyFile, mtWarning, [mbOK], 0);
Exit();
end;
lvStatistics.Clear(); // clear ListView
var CounterDict:= TDictionary<string, Integer>.Create();
for var con in frmMain.ConversationsList do
begin
for var i:= 0 to High(con.Events) do
begin
if con.Events[i] is TConEventSpeech then
begin
var SpeechEvent := TConEventSpeech(con.Events[i]);
if CounterDict.ContainsKey(SpeechEvent.ActorValue) = False then
CounterDict.Add(SpeechEvent.ActorValue, 0);
CounterDict[SpeechEvent.ActorValue] := CounterDict[SpeechEvent.ActorValue] + 1;
end;
if con.Events[i] is TConEventChoice then
begin
var Choice := TConEventChoice(con.Events[i]);
if CounterDict.ContainsKey(PLAYER_BINDNAME) = False then
CounterDict.Add(PLAYER_BINDNAME, 0);
CounterDict[PLAYER_BINDNAME] := CounterDict[PLAYER_BINDNAME] + Length(Choice.Choices);
end;
end;
end;
for var ActorVal in CounterDict.Keys do
begin
var Counter := CounterDict[ActorVal];
var ListItem := lvStatistics.Items.Add();
ListItem.Caption := ActorVal;
ListItem.SubItems.Add(Counter.ToString);
end;
CounterDict.Free();
end;
procedure TfrmConvoFileProperties.lstAllMissionsDrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState);
begin
var ItemText, ItemText2: String;
var EqualsPos: Byte;
var tempRect := Rect;
tempRect.Left := Rect.Left + 4;
ItemText := (Control as TListBox).Items[Index];
EqualsPos := Pos('=', ItemText);
ItemText2 := Copy(ItemText, 1, EqualsPos -1);
with (Control as TListBox).Canvas do
begin
if odSelected in State then
begin
Brush.Style := bsClear;
GradientFillCanvas((Control as TListBox).Canvas, clPurple, clBlack, Rect, gdHorizontal);
Font.Color := clWhite;
DrawText(Handle, ItemText2, -1, tempRect, DT_LEFT);
end else
begin
FillRect(Rect);
Font.Color := clBlack;
DrawText(Handle, ItemText2, -1, tempRect, DT_LEFT);
end;
end;
end;
procedure TfrmConvoFileProperties.ResetAll();
begin
lstThisFileMissions.Clear();
edtConvoFileAudioPackage.Clear();
mmoConvFileNotes.Clear();
lvStatistics.Clear();
FillMissionList();
PageControl1.ActivePageIndex := 0;
end;
procedure TfrmConvoFileProperties.FillMissionList();
begin
with lstAllMissions do
begin
Clear();
Items.AddPair('EndGame', '99');
Items.AddPair('Intro', '98');
for var i:= 0 to 97 do
Items.AddPair(Format(strMissionsInList, [i]), i.ToString);
end;
end;
procedure TfrmConvoFileProperties.UpdateConParameters();
begin
with frmMain do
begin
SetLength(conFileParameters.fpMissions, 0);
SetLength(conFileParameters.fpMissions, lstThisFileMissions.Items.Count);
for var i:= 0 to lstThisFileMissions.Items.Count -1 do
begin
conFileParameters.fpMissions[i] := lstThisFileMissions.Items.ValueFromIndex[i].ToInteger;
end;
conFileParameters.fpCreatedByName := edtConFileCreatedBy.Text;
conFileParameters.fpCreatedByDate := edtConFileCreatedOn.Text;
conFileParameters.fpModifiedByName := edtConFileLastModifiedBy.Text;
conFileParameters.fpModifiedByDate := edtConFileLastModifiedOn.Text;
conFileParameters.fpAudioPackage := edtConvoFileAudioPackage.Text;
conFileParameters.fpNotes := mmoConvFileNotes.Text;
ToggleMenusPanels(True); // show tree and EventList
end;
end;
procedure TfrmConvoFileProperties.CheckIfCorrect();
begin
btnOk.Enabled := (lstThisFileMissions.Items.Count > 0) and (Length(Trim(edtConvoFileAudioPackage.Text)) > 0);
end;
procedure TfrmConvoFileProperties.edtConvoFileAudioPackageChange(Sender: TObject);
begin
CheckIfCorrect();
end;
procedure TfrmConvoFileProperties.btnAddToLeftClick(Sender: TObject); // add from all
begin
for var i := lstAllMissions.Items.Count -1 downto 0 do
if lstAllMissions.Selected[i] then
begin
lstThisFileMissions.Items.Add(lstAllMissions.Items[i]);
lstAllMissions.Items.Delete(i);
end;
CheckIfCorrect();
end;
procedure TfrmConvoFileProperties.btnCancelClick(Sender: TObject);
begin
Close();
end;
procedure TfrmConvoFileProperties.btnFillStatsClick(Sender: TObject);
begin
FillStats();
end;
procedure TfrmConvoFileProperties.btnOkClick(Sender: TObject);
begin
UpdateConParameters();
Close();
end;
procedure TfrmConvoFileProperties.btnRemoveClick(Sender: TObject);
begin
for var i := lstThisFileMissions.Items.Count -1 downto 0 do
if lstThisFileMissions.Selected[i] then
begin
lstAllMissions.Items.Add(lstThisFileMissions.Items[i]);
lstThisFileMissions.Items.Delete(i);
end;
CheckIfCorrect();
end;
procedure TfrmConvoFileProperties.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if btnOk.Enabled = False then
begin
frmMain.Caption := strAppTitle;
frmMain.ToggleMenusPanels(False);
end;
ResetAll();
end;
procedure TfrmConvoFileProperties.FormCreate(Sender: TObject);
begin
lstAllMissions.Sorted := True;
lstThisFileMissions.Sorted := True;
CheckIfCorrect();
FillMissionList();
end;
procedure TfrmConvoFileProperties.FormShow(Sender: TObject);
begin
CheckIfCorrect();
end;
procedure TfrmConvoFileProperties.PageControl1Change(Sender: TObject);
begin
CheckIfCorrect();
case PageControl1.TabIndex of
1: edtConvoFileAudioPackage.SetFocus();
2: lvStatistics.SetFocus();
3: PageControl1.SetFocus();
end;
end;
end.