This repository has been archived by the owner on Jun 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 69
/
WhoUnit.pas
242 lines (215 loc) · 6.29 KB
/
WhoUnit.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
unit WhoUnit;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, ComCtrls, DB,
Menus, Buttons, JvExComCtrls, JvListView, FireDAC.Comp.Client;
type
TWhoQuestForm = class(TForm)
PageControl1: TPageControl;
tsSearch: TTabSheet;
pnSearch: TPanel;
edWhoID: TLabeledEdit;
edWhoName: TLabeledEdit;
btSearch: TButton;
lvWho: TJvListView;
rgTypeOfWho: TRadioGroup;
MyQuery: TFDQuery;
Panel1: TPanel;
btOK: TButton;
btCancel: TButton;
Panel2: TPanel;
Label1: TLabel;
btBrowseSite: TButton;
btEdit: TButton;
pmBrowseSite: TPopupMenu;
pmwowhead: TMenuItem;
pmthottbot: TMenuItem;
pmallakhazam: TMenuItem;
btBrowseQuesterPopup: TBitBtn;
pmwowdb: TMenuItem;
pmruwowhead: TMenuItem;
procedure btSearchClick(Sender: TObject);
procedure lvWhoChange(Sender: TObject; Item: TListItem;
Change: TItemChange);
procedure FormShow(Sender: TObject);
procedure btBrowseSiteClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure btEditClick(Sender: TObject);
procedure pmSiteClick(Sender: TObject);
procedure lvWhoDblClick(Sender: TObject);
procedure btBrowseQuesterPopupClick(Sender: TObject);
private
procedure Search();
public
procedure Prepare(Text: string);
end;
var
WhoQuestForm: TWhoQuestForm;
implementation
uses MainUnit, Functions, MyDataModule;
{$R *.dfm}
procedure TWhoQuestForm.btSearchClick(Sender: TObject);
begin
Search();
with lvWho do if Items.Count>0 then begin SetFocus; Selected:=Items[0]; end;
end;
procedure TWhoQuestForm.Search;
var
ID, WName, {WSubName,} QueryStr, WhereStr, TableName: string;
// key field name
kfname: string;
// name field name
nfname: string;
begin
ID:= edWhoID.Text;
case rgTypeOfWho.ItemIndex of
0: begin
TableName := 'creature_template';
kfname := 'entry';
nfname := 'name';
end;
1: begin
TableName := 'gameobject_template';
kfname := 'entry';
nfname := 'name';
end;
2: begin
TableName := 'item_template';
kfname := 'entry';
nfname := 'name';
end;
end;
WName:=edWhoName.Text;
WName:=StringReplace(WName, '''', '\''', [rfReplaceAll]);
WName:=StringReplace(WName, ' ', '%', [rfReplaceAll]);
WName:='%'+WName+'%';
QueryStr:='';
WhereStr:='';
if ID<>'' then
WhereStr:=Format('WHERE (`%s` = %s)',[kfname,ID]);
if WName<>'' then
begin
if WhereStr<> '' then
WhereStr:=Format('%s AND (`%s` LIKE ''%s'')',[WhereStr, nfname, WName])
else
WhereStr:=Format('WHERE (`%s` LIKE ''%s'')',[nfname, WName]);
end;
QueryStr:=Format('SELECT * FROM `%s` %s',[TableName, WhereStr]);
MyQuery.SQL.Text:=QueryStr;
lvWho.Items.BeginUpdate;
try
MyQuery.Open;
lvWho.Clear;
while not MyQuery.Eof do
begin
with lvWho.Items.Add do
begin
Caption:=MyQuery.FieldByName(kfname).AsString;
SubItems.Add(MyQuery.FieldByName(nfname).AsString);
MyQuery.Next;
end;
end;
finally
lvWho.Items.EndUpdate;
MyQuery.Close;
end;
end;
procedure TWhoQuestForm.lvWhoChange(Sender: TObject; Item: TListItem;
Change: TItemChange);
begin
btOK.Enabled:=Assigned(lvWho.Selected);
btBrowseSite.Enabled:=Assigned(lvWho.Selected);
btBrowseQuesterPopup.Enabled:=Assigned(lvWho.Selected);
btEdit.Enabled:=Assigned(lvWho.Selected);
end;
procedure TWhoQuestForm.lvWhoDblClick(Sender: TObject);
begin
if Assigned(TJvListView(Sender).Selected) then ModalResult:=mrOk;
end;
procedure TWhoQuestForm.Prepare(Text: string);
var
who, key: string;
begin
GetWhoAndKey(Text, who, key);
if who='creature' then rgTypeOfWho.ItemIndex:=0;
if who='gameobject' then rgTypeOfWho.ItemIndex:=1;
if who='item' then rgTypeOfWho.ItemIndex:=2;
edWhoID.Text:=key;
Search;
end;
procedure TWhoQuestForm.FormShow(Sender: TObject);
begin
with lvWho do if Items.Count>0 then begin SetFocus; Selected:=Items[0]; end
else edWhoID.SetFocus;
end;
procedure TWhoQuestForm.btBrowseQuesterPopupClick(Sender: TObject);
var
pt: TPoint;
begin
pt.X := TButton(Sender).Width;
pt.Y := 0;
pt := TButton(Sender).ClientToScreen(pt);
TButton(Sender).PopupMenu.PopupComponent := TButton(Sender);
TButton(Sender).PopupMenu.Popup(pt.X, pt.Y);
end;
procedure TWhoQuestForm.btBrowseSiteClick(Sender: TObject);
begin
if assigned(lvWho.Selected) then
begin
case rgTypeOfWho.ItemIndex of
0: dmMain.BrowseSite(ttNPC, StrToInt(lvWho.Selected.Caption));
1: dmMain.BrowseSite(ttObject, StrToInt(lvWho.Selected.Caption));
2: dmMain.BrowseSite(ttItem, StrToInt(lvWho.Selected.Caption));
end;
end;
end;
procedure TWhoQuestForm.FormCreate(Sender: TObject);
begin
dmMain.Translate.CreateDefaultTranslation(TForm(Self));
dmMain.Translate.TranslateForm(TForm(Self));
end;
procedure TWhoQuestForm.btEditClick(Sender: TObject);
begin
if (rgTypeOfWho.ItemIndex=0) and Assigned(lvWho.Selected) then
begin
ModalResult:=mrCancel;
MainForm.PageControl1.ActivePageIndex:=1;
MainForm.PageControl3.ActivePageIndex:=1;
MainForm.edctEntry.Text:=lvWho.Selected.Caption;
MainForm.edctEntry.Button.Click;
end;
if (rgTypeOfWho.ItemIndex=1) and Assigned(lvWho.Selected) then
begin
ModalResult:=mrCancel;
MainForm.PageControl1.ActivePageIndex:=2;
MainForm.PageControl4.ActivePageIndex:=1;
MainForm.edgtentry.Text:=IntToStr(abs(StrToInt(lvWho.Selected.Caption)));
MainForm.edgtentry.Button.Click;
end;
end;
procedure TWhoQuestForm.pmSiteClick(Sender: TObject);
var
par : TType;
begin
par:=ttNPC;
case rgTypeOfWho.ItemIndex of
0: par:=ttNPC;
1: par:=ttObject;
2: par:=ttItem;
end;
if Assigned(lvWho.Selected) then
begin
if TMenuItem(Sender).Name='pmwowhead' then
dmMain.wowhead(par, StrToInt(lvWho.Selected.Caption));
if TMenuItem(Sender).Name='pmruwowhead' then
dmMain.ruwowhead(par, StrToInt(lvWho.Selected.Caption));
if TMenuItem(Sender).Name='pmallakhazam' then
dmMain.allakhazam(par, StrToInt(lvWho.Selected.Caption));
if TMenuItem(Sender).Name='pmthottbot' then
dmMain.thottbot(par, StrToInt(lvWho.Selected.Caption));
if TMenuItem(Sender).Name='pmwowdb' then
dmMain.wowdb(par, StrToInt(lvWho.Selected.Caption));
end;
end;
end.