-
Notifications
You must be signed in to change notification settings - Fork 1
/
Pick.cpp
204 lines (175 loc) · 5.52 KB
/
Pick.cpp
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
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Pick.h"
#include "MyStrUtil.h"
#include "DrawMTGC.h"
#include "db.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
//#pragma link "JpgImg"
#pragma link "Placemnt"
#pragma resource "*.dfm"
//TfmPick *fmPick;
bool ShowPictures = false;
bool BreakDraft;
//---------------------------------------------------------------------------
__fastcall TfmPick::TfmPick(TComponent* Owner,
const TCardPile& aBooster, const TCardPile& aPicked, bool aStudyMode)
: TForm(Owner), Booster(aBooster), Picked(aPicked), StudyMode(aStudyMode)
{
TimeLeft = 40 - (7-Booster.size()/2)*5;
if (TimeLeft < 5) TimeLeft = 5;
}
//---------------------------------------------------------------------------
int GetUserPick(TCardPile& Booster, const TCardPile& Picked,
bool StudyMode, std::vector<double> Values)
{
TfmPick *fmPick = new TfmPick(Application, Booster, Picked, StudyMode);
fmPick->FormStorage1->RestoreProperties();
if (fmPick->cbViewPicked->Checked
&& (Picked.size() > 0)
&& (Picked.size() % 15 == 0))
{
fmPick->Timer1->Enabled = false;
ViewPile(Picked);
fmPick->Timer1->Enabled = true;
}
if (StudyMode)
{
fmPick->liValues->Visible = true;
}
for (unsigned int i=0; i<Booster.size(); i++)
{
fmPick->liBooster->Items->Add(Booster[i]->Name.c_str());
}
for (unsigned int i=0; i<Values.size(); i++)
{
fmPick->liValues->Items->Add(Values[i]);
}
//liBooster->Selected[random(liBooster->Items->Count)] = true;
fmPick->ShowModal();
int Result = fmPick->GetChoice();
delete fmPick;
return Result;
}
int TfmPick::GetChoice()
{
for (int i=0; i<liBooster->Items->Count; i++)
{
if (liBooster->Selected[i])
{
return i;
}
}
return random(liBooster->Items->Count);
}
void __fastcall TfmPick::btTakeClick(TObject *Sender)
{
ModalResult = mrOk;
}
//---------------------------------------------------------------------------
void TfmPick::PaintCard()
{
const TCardData* c = Booster[GetChoice()];
edText->Lines->Clear();
edText->Lines->Add(c->Name.c_str());
edText->Lines->Add(c->ManaCost.c_str());
edText->Lines->Add(TCardData::Rarities[c->Rarity].c_str());
if (c->SubTypes.empty())
{
edText->Lines->Add(c->Type.c_str());
}
else
{
edText->Lines->Add((c->Type + " - " + c->SubTypes).c_str());
edText->Lines->Add((c->Power + "/" + c->Toughness).c_str());
}
string Text = c->Text;
while (!Text.empty())
{
string Line = ExtractWord(Text, "\n");
edText->Lines->Add(Trim(Line.c_str()));
}
if (cbPicture->Checked)
{
imCard->Invalidate();
DrawCard(c->Name.c_str(), c->Edition.c_str(), "no", *GetAllCards(),
imCard->Canvas);
}
}
//---------------------------------------------------------------------------
void __fastcall TfmPick::liBoosterClick(TObject *Sender)
{
PaintCard();
}
//---------------------------------------------------------------------------
void __fastcall TfmPick::liBoosterMouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
PaintCard();
}
//---------------------------------------------------------------------------
void __fastcall TfmPick::Timer1Timer(TObject *Sender)
{
if (TimeLeft > 0) TimeLeft--;
StatusBar1->Panels->Items[0]->Text = "Âðåìÿ: " + IntToStr(TimeLeft);
if (TimeLeft <= 5)
{
la54321->Visible = true;
la54321->Caption = IntToStr(TimeLeft);
}
if (!StudyMode && (TimeLeft == 0))
{
ModalResult = mrOk;
}
}
//---------------------------------------------------------------------------
void __fastcall TfmPick::btBreakClick(TObject *Sender)
{
BreakDraft = true;
ModalResult = mrCancel;
}
//---------------------------------------------------------------------------
void __fastcall TfmPick::btPauseClick(TObject *Sender)
{
btTake->Enabled = !btPause->Down;
Timer1->Enabled = !btPause->Down;
liBooster->Enabled = !btPause->Down;
}
//---------------------------------------------------------------------------
void __fastcall TfmPick::cbPictureClick(TObject *Sender)
{
ShowPictures = cbPicture->Checked;
imCard->Visible = ShowPictures;
edText->Visible = !ShowPictures;
}
//---------------------------------------------------------------------------
void ViewPile(const TCardPile& Picked)
{
TfmPick *fmPick = new TfmPick(Application, Picked, Picked, false);
fmPick->Caption = "Ñìîòðèì íàãðàáëåííîå";
fmPick->btTake->Caption = "Close";
fmPick->btPause->Visible = false;
fmPick->cbViewPicked->Visible = false;
fmPick->Timer1->Enabled = false;
fmPick->btBreak->Visible = false;
for (unsigned int i=0; i<Picked.size(); i++)
{
fmPick->liBooster->Items->Add(Picked[i]->Name.c_str());
}
fmPick->ShowModal();
delete fmPick;
}
//---------------------------------------------------------------------------
void __fastcall TfmPick::FormShow(TObject *Sender)
{
cbPicture->Checked = ShowPictures;
cbPictureClick(this);
}
//---------------------------------------------------------------------------
void __fastcall TfmPick::FormResize(TObject *Sender)
{
//imCard->Canvas->ClipRect = imCard->ClientRect;
}
//---------------------------------------------------------------------------