-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathShopSelectForm.pas
More file actions
760 lines (684 loc) · 26.4 KB
/
ShopSelectForm.pas
File metadata and controls
760 lines (684 loc) · 26.4 KB
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
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
unit ShopSelectForm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, StdCtrls, ComCtrls, Menus,
InflatablesList_ShopSelectArray,
InflatablesList_Manager;
const
IL_WM_USER_LVITEMSELECTED = WM_USER + 234;
type
TfShopSelectForm = class(TForm)
lvShops: TListView;
lblShops: TLabel;
lblItems: TLabel;
lblItemsHint: TLabel;
lbItems: TListBox;
pmnItems: TPopupMenu;
mniIT_EditTextTag: TMenuItem;
mniIT_EditNumTag: TMenuItem;
N1: TMenuItem;
mniIT_EditTextTagSelected: TMenuItem;
mniIT_EditNumTagSelected: TMenuItem;
N2: TMenuItem;
mniIT_EditTextTagAvailable: TMenuItem;
mniIT_EditNumTagAvailable: TMenuItem;
N3: TMenuItem;
mniIT_EditTextTagAll: TMenuItem;
mniIT_EditNumTagAll: TMenuItem;
grbItemShops: TGroupBox;
lvItemShops: TListView;
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure lvShopsSelectItem(Sender: TObject; Item: TListItem;
Selected: Boolean);
procedure lbItemsDrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
procedure lbItemsClick(Sender: TObject);
procedure lbItemsDblClick(Sender: TObject);
procedure lbItemsMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure pmnItemsPopup(Sender: TObject);
procedure mniIT_EditTextTagClick(Sender: TObject);
procedure mniIT_EditNumTagClick(Sender: TObject);
procedure mniIT_EditTextTagSelectedClick(Sender: TObject);
procedure mniIT_EditNumTagSelectedClick(Sender: TObject);
procedure mniIT_EditTextTagAvailableClick(Sender: TObject);
procedure mniIT_EditNumTagAvailableClick(Sender: TObject);
procedure mniIT_EditTextTagAllClick(Sender: TObject);
procedure mniIT_EditNumTagAllClick(Sender: TObject);
procedure lvItemShopsDblClick(Sender: TObject);
private
{ Private declarations }
fDrawBuffer: TBitmap;
fILManager: TILManager;
fShopTable: TILCountedDynArraySelectionShops;
fCurrentShopIndex: Integer;
protected
procedure BuildTable;
procedure FillShops;
procedure FillItems;
procedure FillItemShop;
procedure RecountAndFillSelected;
procedure ListViewItemSelected(var Msg: TMessage); overload; message IL_WM_USER_LVITEMSELECTED;
procedure ListViewItemSelected; overload;
procedure ShopsListSelect(ItemIndex: Integer);
procedure UpdateShopIndex;
procedure UpdateItemIndex;
public
{ Public declarations }
procedure Initialize(ILManager: TILManager);
procedure Finalize;
procedure ShowSelection;
end;
var
fShopSelectForm: TfShopSelectForm;
implementation
{$R *.dfm}
uses
InflatablesList_Types,
InflatablesList_Utils,
InflatablesList_LocalStrings,
InflatablesList_ShopSelectItemsArray,
InflatablesList_Item,
PromptForm;
procedure TfShopSelectForm.BuildTable;
var
i,j: Integer;
Index: Integer;
Temp: TILSelectionShopEntry;
Entry: TILShopSelectItemEntry;
begin
CDA_Init(fShopTable);
For i := fILManager.ItemLowIndex to fILManager.ItemHighIndex do
If fILManager[i].DataAccessible then
For j := fILManager[i].ShopLowIndex to fILManager[i].ShopHighIndex do
begin
Temp.ShopName := fILManager[i][j].Name;
Index := CDA_IndexOf(fShopTable,Temp);
If not CDA_CheckIndex(fShopTable,Index) then
begin
// shop is not in the table, add it
CDA_Init(Temp.Items);
Temp.Available := 0;
Temp.Selected := 0;
Temp.PriceOfSel := 0;
Index := CDA_Add(fShopTable,Temp);
end;
Entry.ItemObject := fILManager[i];
Entry.Available := fILManager[i][j].IsAvailableHere(True);
Entry.Selected := fILManager[i][j].Selected;
Entry.Index := i;
Entry.Price := fILManager[i][j].Price;
CDA_Add(CDA_GetItemPtr(fShopTable,Index)^.Items,Entry);
If fILManager[i][j].Available <> 0 then
Inc(CDA_GetItemPtr(fShopTable,Index)^.Available);
If fILManager[i][j].Selected then
begin
Inc(CDA_GetItemPtr(fShopTable,Index)^.Selected);
Inc(CDA_GetItemPtr(fShopTable,Index)^.PriceOfSel,fILManager[i][j].Price);
end;
end;
CDA_Sort(fShopTable);
For i := CDA_Low(fShopTable) to CDA_High(fShopTable) do
CDA_Sort(CDA_GetItemPtr(fShopTable,i)^.Items);
end;
//------------------------------------------------------------------------------
procedure TfShopSelectForm.FillShops;
var
i: Integer;
begin
lvShops.Items.BeginUpdate;
try
lvShops.Clear;
For i := CDA_Low(fShopTable) to CDA_High(fShopTable) do
with lvShops.Items.Add do
begin
Caption := CDA_GetItem(fShopTable,i).ShopName;
SubItems.Add(IntToStr(CDA_Count(CDA_GetItem(fShopTable,i).Items)));
SubItems.Add(IntToStr(CDA_GetItem(fShopTable,i).Available));
SubItems.Add(IntToStr(CDA_GetItem(fShopTable,i).Selected));
If CDA_GetItem(fShopTable,i).PriceOfSel > 0 then
SubItems.Add(IL_Format('%d %s',[CDA_GetItem(fShopTable,i).PriceOfSel,IL_CURRENCY_SYMBOL]))
else
SubItems.Add('');
end;
finally
lvShops.Items.EndUpdate;
end;
ShopsListSelect(0);
end;
//------------------------------------------------------------------------------
procedure TfShopSelectForm.FillItems;
var
i: Integer;
VScroll: Boolean;
Temp: Integer;
begin
VScroll := lbItems.Count > (lbItems.ClientHeight div lbItems.ItemHeight);
lbItems.Items.BeginUpdate;
try
lbItems.Clear;
If CDA_CheckIndex(fShopTable,fCurrentShopIndex) then
begin
CDA_Sort(CDA_GetItemPtr(fShopTable,fCurrentShopIndex)^.Items);
For i := CDA_Low(CDA_GetItem(fShopTable,fCurrentShopIndex).Items) to
CDA_High(CDA_GetItem(fShopTable,fCurrentShopIndex).Items) do
lbItems.Items.Add(IntToStr(i));
end;
// get width for drawing
If (lbItems.Count > (lbItems.ClientHeight div lbItems.ItemHeight)) then
begin
If VScroll then
Temp := lbItems.ClientWidth
else
Temp := lbItems.ClientWidth - GetSystemMetrics(SM_CXVSCROLL);
end
else
begin
If VScroll then
Temp := lbItems.ClientWidth + GetSystemMetrics(SM_CXVSCROLL)
else
Temp := lbItems.ClientWidth;
end;
// reinit draw size only for items that are shown, not for everything in the list
If CDA_CheckIndex(fShopTable,fCurrentShopIndex) then
For i := CDA_Low(CDA_GetItem(fShopTable,fCurrentShopIndex).Items) to
CDA_High(CDA_GetItem(fShopTable,fCurrentShopIndex).Items) do
with CDA_GetItem(CDA_GetItem(fShopTable,fCurrentShopIndex).Items,i).ItemObject do
begin
BeginUpdate;
try
ReinitSmallDrawSize(Temp,lbItems.ItemHeight,lbItems.Font);
ChangeSmallStripSize(-1);
finally
EndUpdate;
end;
end;
finally
lbItems.Items.EndUpdate;
end;
If lbItems.Count > 0 then
lbItems.ItemIndex := 0
else
lbItems.ItemIndex := -1;
lbItems.OnClick(nil);
lbItems.Invalidate;
end;
//------------------------------------------------------------------------------
procedure TfShopSelectForm.FillItemShop;
var
i: Integer;
TempStr: String;
begin
lvItemShops.Items.BeginUpdate;
try
lvItemShops.Clear;
If CDA_CheckIndex(fShopTable,fCurrentShopIndex) then
If CDA_CheckIndex(CDA_GetItem(fShopTable,fCurrentShopIndex).Items,lbItems.ItemIndex) then
with CDA_GetItemPtr(CDA_GetItem(fShopTable,fCurrentShopIndex).Items,lbItems.ItemIndex)^ do
begin
// adjust count
If lvItemShops.Items.Count < ItemObject.ShopCount then
For i := lvItemShops.Items.Count to Pred(ItemObject.ShopCount) do
with lvItemShops.Items.Add do
begin
SubItems.Add(''); // name
SubItems.Add(''); // url
SubItems.Add(''); // avail
SubItems.Add(''); // price
end
else If lvItemShops.Items.Count > ItemObject.ShopCount then
For i := Pred(lvItemShops.Items.Count) downto ItemObject.ShopCount do
lvItemShops.Items.Delete(i);
// fill the list
For i := ItemObject.ShopLowIndex to ItemObject.ShopHighIndex do
with lvItemShops.Items[i] do
begin
// don't mark worst result here, it is pointless
Caption := IL_Format('%s%s',[
IL_BoolToStr(ItemObject[i].Selected,'','*'),
IL_BoolToStr(ItemObject[i].Untracked,'','^')]);
SubItems[0] := ItemObject[i].Name;
SubItems[1] := ItemObject[i].ItemURL;
// avail
If ItemObject[i].Available < 0 then
SubItems[2] := IL_Format('more than %d',[Abs(ItemObject[i].Available)])
else If ItemObject[i].Available > 0 then
SubItems[2] := IL_Format('%d',[Abs(ItemObject[i].Available)])
else
SubItems[2] := '-';
// price
If ItemObject[i].Price > 0 then
SubItems[3] := IL_Format('%d %s',[ItemObject[i].Price,IL_CURRENCY_SYMBOL])
else
SubItems[3] := '-';
end;
end;
finally
lvItemShops.Items.EndUpdate;
end;
If lvItemShops.Items.Count > 0 then
begin
TempStr := IL_Format('Item shops for %s',[
// if there is something in the list, indices were already successfully checked
CDA_GetItem(CDA_GetItem(fShopTable,fCurrentShopIndex).Items,lbItems.ItemIndex).ItemObject.TitleStr]);
If lvItemShops.Items.Count > 1 then
TempStr := IL_Format('%s (%d)',[TempStr,lvItemShops.Items.Count]);
end
else TempStr := 'Item shops';
grbItemShops.Caption := TempStr;
end;
//------------------------------------------------------------------------------
procedure TfShopSelectForm.RecountAndFillSelected;
var
i,j: Integer;
Index: Integer;
begin
For i := CDA_Low(fShopTable) to CDA_High(fShopTable) do
begin
CDA_GetItemPtr(fShopTable,i)^.Selected := 0;
CDA_GetItemPtr(fShopTable,i)^.PriceOfSel := 0;
For j := CDA_Low(CDA_GetItem(fShopTable,i).Items) to CDA_High(CDA_GetItem(fShopTable,i).Items) do
begin
Index := CDA_GetItem(CDA_GetItem(fShopTable,i).Items,j).ItemObject.ShopIndexOf(CDA_GetItem(fShopTable,i).ShopName);
If Index >= 0 then
begin
CDA_GetItemPtr(CDA_GetItem(fShopTable,i).Items,j)^.Selected :=
CDA_GetItem(CDA_GetItem(fShopTable,i).Items,j).ItemObject.Shops[Index].Selected;
If CDA_GetItem(CDA_GetItem(fShopTable,i).Items,j).Selected then
begin
Inc(CDA_GetItemPtr(fShopTable,i)^.Selected);
Inc(CDA_GetItemPtr(fShopTable,i)^.PriceOfSel,
CDA_GetItem(CDA_GetItem(fShopTable,i).Items,j).Price);
end;
end
else raise Exception.Create('Some weird things are happening...');
end;
lvShops.Items[i].SubItems[2] := IntToStr(CDA_GetItem(fShopTable,i).Selected);
If CDA_GetItem(fShopTable,i).PriceOfSel > 0 then
lvShops.Items[i].SubItems[3] := IL_Format('%d %s',[CDA_GetItem(fShopTable,i).PriceOfSel,IL_CURRENCY_SYMBOL])
else
lvShops.Items[i].SubItems[3] := '';
end;
end;
//------------------------------------------------------------------------------
procedure TfShopSelectForm.ListViewItemSelected(var Msg: TMessage);
begin
If Msg.Msg = IL_WM_USER_LVITEMSELECTED then
ListViewItemSelected;
end;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
procedure TfShopSelectForm.ListViewItemSelected;
begin
If lvShops.ItemIndex <> fCurrentShopIndex then
begin
fCurrentShopIndex := lvShops.ItemIndex;
FillItems;
end;
If (lvShops.ItemIndex >= 0) and Assigned(lvShops.Selected) then
lvShops.Selected.MakeVisible(False);
UpdateShopIndex;
end;
//------------------------------------------------------------------------------
procedure TfShopSelectForm.ShopsListSelect(ItemIndex: Integer);
begin
If (ItemIndex >= 0) and (ItemIndex < lvShops.Items.Count) then
begin
with lvShops.Items[ItemIndex] do
begin
Focused := True;
Selected := True;
end;
lvShops.ItemIndex := ItemIndex;
end
else lvShops.ItemIndex := -1;
end;
//------------------------------------------------------------------------------
procedure TfShopSelectForm.UpdateShopIndex;
begin
If lvShops.ItemIndex < 0 then
begin
If lvShops.Items.Count > 0 then
lblShops.Caption := IL_Format('Shops (%d):',[lvShops.Items.Count])
else
lblShops.Caption := 'Shops:';
end
else lblShops.Caption := IL_Format('Shops (%d/%d):',[lvShops.ItemIndex + 1,lvShops.Items.Count]);
end;
//------------------------------------------------------------------------------
procedure TfShopSelectForm.UpdateItemIndex;
begin
If lbItems.ItemIndex < 0 then
begin
If lbItems.Items.Count > 0 then
lblItems.Caption := IL_Format('Items available in the selected shop (%d):',[lbItems.Items.Count])
else
lblItems.Caption := 'Items available in the selected shop:';
end
else lblItems.Caption := IL_Format('Items available in the selected shop (%d/%d):',[lbItems.ItemIndex + 1,lbItems.Items.Count]);
end;
//==============================================================================
procedure TfShopSelectForm.Initialize(ILManager: TILManager);
begin
fILManager := ILManager;
end;
//------------------------------------------------------------------------------
procedure TfShopSelectForm.Finalize;
begin
// nothing to do here
end;
//------------------------------------------------------------------------------
procedure TfShopSelectForm.ShowSelection;
begin
fCurrentShopIndex := -2; // must be below -1
BuildTable;
FillShops;
ShowModal;
end;
//==============================================================================
procedure TfShopSelectForm.FormCreate(Sender: TObject);
begin
fDrawBuffer := TBitmap.Create;
fDrawBuffer.PixelFormat := pf24bit;
fDrawBuffer.Canvas.Font.Assign(lbItems.Font);
lvShops.DoubleBuffered := True;
lbItems.DoubleBuffered := True;
lvItemShops.DoubleBuffered := True;
end;
//------------------------------------------------------------------------------
procedure TfShopSelectForm.FormShow(Sender: TObject);
begin
lvShops.SetFocus;
end;
//------------------------------------------------------------------------------
procedure TfShopSelectForm.FormDestroy(Sender: TObject);
begin
FreeAndNil(fDrawBuffer);
end;
//------------------------------------------------------------------------------
procedure TfShopSelectForm.lvShopsSelectItem(Sender: TObject;
Item: TListItem; Selected: Boolean);
begin
//this deffers reaction to change and prevents flickering
PostMessage(Handle,IL_WM_USER_LVITEMSELECTED,Ord(Selected),0);
end;
//------------------------------------------------------------------------------
procedure TfShopSelectForm.lbItemsDrawItem(Control: TWinControl;
Index: Integer; Rect: TRect; State: TOwnerDrawState);
var
TempStr: String;
BoundsRect: TRect;
TempItem: TILShopSelectItemEntry;
begin
// draw on bitmap and then copy it using copyrect, this flickers
If CDA_CheckIndex(fShopTable,fCurrentShopIndex) and Assigned(fDrawBuffer) then
If CDA_CheckIndex(CDA_GetItem(fShopTable,fCurrentShopIndex).Items,Index) then
begin
// adjust draw buffer size
If fDrawBuffer.Width < (Rect.Right - Rect.Left) then
fDrawBuffer.Width := Rect.Right - Rect.Left;
If fDrawBuffer.Height < (Rect.Bottom - Rect.Top) then
fDrawBuffer.Height := Rect.Bottom - Rect.Top;
BoundsRect := Classes.Rect(0,0,Rect.Right - Rect.Left,Rect.Bottom - Rect.Top);
with fDrawBuffer.Canvas do
begin
TempItem := CDA_GetItem(CDA_GetItem(fShopTable,fCurrentShopIndex).Items,Index);
// content
Draw(BoundsRect.Left,BoundsRect.Top,TempItem.ItemObject.RenderSmall);
TempItem.ItemObject.RenderSmall.Dormant;
// separator line
Pen.Style := psSolid;
Pen.Color := clSilver;
MoveTo(BoundsRect.Left,Pred(BoundsRect.Bottom));
LineTo(BoundsRect.Right,Pred(BoundsRect.Bottom));
// marker
Pen.Style := psClear;
Brush.Style := bsSolid;
If TempItem.Selected then
begin
If TempItem.Available then
Brush.Color := clBlue
else
Brush.Color := $00F8BD6D;
end
else If TempItem.Available then
Brush.Color := $00D5FFD2
else
Brush.Color := $00F7F7F7;
Rectangle(BoundsRect.Left,BoundsRect.Top,BoundsRect.Left +
TempItem.ItemObject.SmallStrip,BoundsRect.Bottom);
// shop price
TempStr := IL_Format('%d %s',[TempItem.Price,IL_CURRENCY_SYMBOL]);
Brush.Style := bsClear;
Font.Style := [fsBold];
Font.Color := clWindowText;
Font.Size := 10;
TextOut(BoundsRect.Right - TextWidth(TempStr) - 64,BoundsRect.Top + 2,TempStr);
// states
If odSelected in State then
begin
Pen.Style := psClear;
Brush.Style := bsSolid;
Brush.Color := clLime;
Rectangle(BoundsRect.Left,BoundsRect.Top,BoundsRect.Left + 11,BoundsRect.Bottom);
end;
end;
// move drawbuffer to the canvas
lbItems.Canvas.CopyRect(Rect,fDrawBuffer.Canvas,BoundsRect);
// as focus rect is drawn automatically, following pretty much removes it (it looks ugly)
If odFocused in State then
lbItems.Canvas.DrawFocusRect(Rect);
end;
end;
//------------------------------------------------------------------------------
procedure TfShopSelectForm.lbItemsClick(Sender: TObject);
begin
UpdateItemIndex;
FillItemShop;
end;
//------------------------------------------------------------------------------
procedure TfShopSelectForm.lbItemsDblClick(Sender: TObject);
var
LocalItemObject: TILItem;
ShopIndex: Integer;
begin
If CDA_CheckIndex(fShopTable,fCurrentShopIndex) then
If CDA_CheckIndex(CDA_GetItem(fShopTable,fCurrentShopIndex).Items,lbItems.ItemIndex) then
with CDA_GetItemPtr(CDA_GetItem(fShopTable,fCurrentShopIndex).Items,lbItems.ItemIndex)^ do
begin
LocalItemObject := ItemObject;
ShopIndex := LocalItemObject.ShopIndexOf(CDA_GetItem(fShopTable,fCurrentShopIndex).ShopName);
If ShopIndex >= 0 then
begin
LocalItemObject[ShopIndex].Selected := not LocalItemObject[ShopIndex].Selected;
Selected := LocalItemObject[ShopIndex].Selected;
CDA_Sort(CDA_GetItemPtr(fShopTable,fCurrentShopIndex)^.Items);
RecountAndFillSelected;
lbItems.Invalidate;
// get new index of the double-clicked item
lbItems.ItemIndex := CDA_IndexOfObject(CDA_GetItem(fShopTable,fCurrentShopIndex).Items,LocalItemObject);
lbItems.OnClick(nil); // calls FillItemShop
end;
end;
end;
//------------------------------------------------------------------------------
procedure TfShopSelectForm.lbItemsMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
Index: Integer;
begin
If Button = mbRight then
begin
Index := lbItems.ItemAtPos(Point(X,Y),True);
If Index >= 0 then
begin
lbItems.ItemIndex := Index;
lbItems.OnClick(nil);
end;
end;
end;
//------------------------------------------------------------------------------
procedure TfShopSelectForm.pmnItemsPopup(Sender: TObject);
begin
mniIT_EditTextTag.Enabled := lbItems.ItemIndex >= 0;
mniIT_EditNumTag.Enabled := lbItems.ItemIndex >= 0;
If CDA_CheckIndex(fShopTable,fCurrentShopIndex) then
begin
mniIT_EditTextTagSelected.Enabled := (lbItems.Count > 0) and (CDA_GetItem(fShopTable,fCurrentShopIndex).Selected > 0);
mniIT_EditNumTagSelected.Enabled := mniIT_EditTextTagSelected.Enabled;
mniIT_EditTextTagAvailable.Enabled := (lbItems.Count > 0) and (CDA_GetItem(fShopTable,fCurrentShopIndex).Available > 0);
mniIT_EditNumTagAvailable.Enabled := mniIT_EditTextTagAvailable.Enabled;
mniIT_EditTextTagAll.Enabled := (lbItems.Count > 0) and (CDA_Count(CDA_GetItem(fShopTable,fCurrentShopIndex).Items) > 0);
mniIT_EditNumTagAll.Enabled := mniIT_EditTextTagAll.Enabled;
end
else
begin
mniIT_EditTextTagSelected.Enabled := False;
mniIT_EditNumTagSelected.Enabled := False;
mniIT_EditTextTagAvailable.Enabled := False;
mniIT_EditNumTagAvailable.Enabled := False;
mniIT_EditTextTagAll.Enabled := False;
mniIT_EditNumTagAll.Enabled := False;
end;
end;
//------------------------------------------------------------------------------
procedure TfShopSelectForm.mniIT_EditTextTagClick(Sender: TObject);
var
Temp: String;
begin
If CDA_CheckIndex(fShopTable,fCurrentShopIndex) then
If CDA_CheckIndex(CDA_GetItem(fShopTable,fCurrentShopIndex).Items,lbItems.ItemIndex) then
with CDA_GetItemPtr(CDA_GetItem(fShopTable,fCurrentShopIndex).Items,lbItems.ItemIndex)^ do
begin
Temp := ItemObject.TextTag;
If IL_InputQuery(IL_Format('Edit textual tag of %s',[ItemObject.TitleStr]),'Textual tag:',Temp) then
begin
ItemObject.TextTag := Temp;
lbItems.Invalidate;
end;
end;
end;
//------------------------------------------------------------------------------
procedure TfShopSelectForm.mniIT_EditNumTagClick(Sender: TObject);
var
Temp: Integer;
begin
If CDA_CheckIndex(fShopTable,fCurrentShopIndex) then
If CDA_CheckIndex(CDA_GetItem(fShopTable,fCurrentShopIndex).Items,lbItems.ItemIndex) then
with CDA_GetItemPtr(CDA_GetItem(fShopTable,fCurrentShopIndex).Items,lbItems.ItemIndex)^ do
begin
Temp := Integer(ItemObject.NumTag);
If IL_InputQuery(IL_Format('Edit numerical tag of %s',[ItemObject.TitleStr]),
'Numerical tag:',Temp,IL_ITEM_NUM_TAG_MIN,IL_ITEM_NUM_TAG_MAX) then
begin
ItemObject.NumTag := Temp;
lbItems.Invalidate;
end;
end;
end;
//------------------------------------------------------------------------------
procedure TfShopSelectForm.mniIT_EditTextTagSelectedClick(Sender: TObject);
var
Temp: String;
i: Integer;
begin
// note that fCurrentShopIndex was checked on menu popup
Temp := '';
If IL_InputQuery('Edit textual tag of selected items','Textual tag:',Temp) then
begin
For i := CDA_Low(CDA_GetItem(fShopTable,fCurrentShopIndex).Items) to
CDA_High(CDA_GetItem(fShopTable,fCurrentShopIndex).Items) do
If CDA_GetItem(CDA_GetItem(fShopTable,fCurrentShopIndex).Items,i).Selected then
CDA_GetItem(CDA_GetItem(fShopTable,fCurrentShopIndex).Items,i).ItemObject.TextTag := Temp;
lbItems.Invalidate;
end;
end;
//------------------------------------------------------------------------------
procedure TfShopSelectForm.mniIT_EditNumTagSelectedClick(Sender: TObject);
var
Temp: Integer;
i: Integer;
begin
Temp := 0;
If IL_InputQuery('Edit numerical tag of selected items','Numerical tag:',Temp,IL_ITEM_NUM_TAG_MIN,IL_ITEM_NUM_TAG_MAX) then
begin
For i := CDA_Low(CDA_GetItem(fShopTable,fCurrentShopIndex).Items) to
CDA_High(CDA_GetItem(fShopTable,fCurrentShopIndex).Items) do
If CDA_GetItem(CDA_GetItem(fShopTable,fCurrentShopIndex).Items,i).Selected then
CDA_GetItem(CDA_GetItem(fShopTable,fCurrentShopIndex).Items,i).ItemObject.NumTag := Temp;
lbItems.Invalidate;
end;
end;
//------------------------------------------------------------------------------
procedure TfShopSelectForm.mniIT_EditTextTagAvailableClick(Sender: TObject);
var
Temp: String;
i: Integer;
begin
Temp := '';
If IL_InputQuery('Edit textual tag of available items','Textual tag:',Temp) then
begin
For i := CDA_Low(CDA_GetItem(fShopTable,fCurrentShopIndex).Items) to
CDA_High(CDA_GetItem(fShopTable,fCurrentShopIndex).Items) do
If CDA_GetItem(CDA_GetItem(fShopTable,fCurrentShopIndex).Items,i).Available then
CDA_GetItem(CDA_GetItem(fShopTable,fCurrentShopIndex).Items,i).ItemObject.TextTag := Temp;
lbItems.Invalidate;
end;
end;
//------------------------------------------------------------------------------
procedure TfShopSelectForm.mniIT_EditNumTagAvailableClick(Sender: TObject);
var
Temp: Integer;
i: Integer;
begin
Temp := 0;
If IL_InputQuery('Edit numerical tag of available items','Numerical tag:',Temp,IL_ITEM_NUM_TAG_MIN,IL_ITEM_NUM_TAG_MAX) then
begin
For i := CDA_Low(CDA_GetItem(fShopTable,fCurrentShopIndex).Items) to
CDA_High(CDA_GetItem(fShopTable,fCurrentShopIndex).Items) do
If CDA_GetItem(CDA_GetItem(fShopTable,fCurrentShopIndex).Items,i).Available then
CDA_GetItem(CDA_GetItem(fShopTable,fCurrentShopIndex).Items,i).ItemObject.NumTag := Temp;
lbItems.Invalidate;
end;
end;
//------------------------------------------------------------------------------
procedure TfShopSelectForm.mniIT_EditTextTagAllClick(Sender: TObject);
var
Temp: String;
i: Integer;
begin
Temp := '';
If IL_InputQuery('Edit textual tag of all items','Textual tag:',Temp) then
begin
For i := CDA_Low(CDA_GetItem(fShopTable,fCurrentShopIndex).Items) to
CDA_High(CDA_GetItem(fShopTable,fCurrentShopIndex).Items) do
CDA_GetItem(CDA_GetItem(fShopTable,fCurrentShopIndex).Items,i).ItemObject.TextTag := Temp;
lbItems.Invalidate;
end;
end;
//------------------------------------------------------------------------------
procedure TfShopSelectForm.mniIT_EditNumTagAllClick(Sender: TObject);
var
Temp: Integer;
i: Integer;
begin
Temp := 0;
If IL_InputQuery('Edit numerical tag of all items','Numerical tag:',Temp,IL_ITEM_NUM_TAG_MIN,IL_ITEM_NUM_TAG_MAX) then
begin
For i := CDA_Low(CDA_GetItem(fShopTable,fCurrentShopIndex).Items) to
CDA_High(CDA_GetItem(fShopTable,fCurrentShopIndex).Items) do
CDA_GetItem(CDA_GetItem(fShopTable,fCurrentShopIndex).Items,i).ItemObject.NumTag := Temp;
lbItems.Invalidate;
end;
end;
//------------------------------------------------------------------------------
procedure TfShopSelectForm.lvItemShopsDblClick(Sender: TObject);
begin
If CDA_CheckIndex(fShopTable,fCurrentShopIndex) then
If CDA_CheckIndex(CDA_GetItem(fShopTable,fCurrentShopIndex).Items,lbItems.ItemIndex) then
with CDA_GetItemPtr(CDA_GetItem(fShopTable,fCurrentShopIndex).Items,lbItems.ItemIndex)^ do
If ItemObject.CheckIndex(lvItemShops.ItemIndex) then
IL_ShellOpen(Self.Handle,ItemObject[lvItemShops.ItemIndex].ItemURL);
end;
end.