[25ea8d]: ItemPicker.cpp  Maximize  Restore  History

Download this file

356 lines (327 with data), 7.6 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
// ItemPicker.cpp : implementation file
//
#include "stdafx.h"
#include "chitem.h"
#include "options.h"
#include "2da.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CItemPicker dialog
CItemPicker::CItemPicker(CWnd* pParent /*=NULL*/)
: CDialog(CItemPicker::IDD, pParent)
{
//{{AFX_DATA_INIT(CItemPicker)
m_text = _T("");
//}}AFX_DATA_INIT
m_restype=-1;
m_oldrestype=-1;
}
void CItemPicker::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CItemPicker)
DDX_Control(pDX, IDC_PICK, m_pick_control);
DDX_Text(pDX, IDC_TEXT, m_text);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CItemPicker, CDialog)
//{{AFX_MSG_MAP(CItemPicker)
ON_LBN_DBLCLK(IDC_PICK, OnDblclkPick)
ON_BN_CLICKED(IDC_SEARCH, OnSearch)
ON_BN_CLICKED(IDC_RESOLVE, OnResolve)
ON_BN_CLICKED(IDC_PREVIEW, OnPreview)
ON_LBN_SELCHANGE(IDC_PICK, OnSelchangePick)
ON_BN_CLICKED(IDC_PLAY, OnPlay)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CItemPicker message handlers
void CItemPicker::OnOK()
{
int sel;
int x;
UpdateData(UD_RETRIEVE);
sel=m_pick_control.GetCurSel();
if(sel==-1) OnSearch();
sel=m_pick_control.GetCurSel();
if(sel>=0 && sel<m_pick_control.GetCount())
{
m_pick_control.GetText(sel,m_picked);
x=m_picked.Find(" ");
if(x>0) m_picked=m_picked.Left(x);
CDialog::OnOK();
}
else OnCancel();
}
void CItemPicker::OnDblclkPick()
{
OnOK();
}
void CItemPicker::Preview(CString &key, loc_entry &fileloc, int restype)
{
CString tmpstr;
int fhandle;
int fc;
switch(restype)
{
case REF_BMP:
case REF_BAM:
case REF_ITM:
case REF_SPL:
m_preview.InitView(IW_NOREDRAW); //don't add the 'back' button
if(editflg&PREVIEW)
{
m_preview.ShowWindow(false);
return;
}
m_preview.SetWindowText(key);
switch(restype)
{
case REF_ITM: case REF_SPL:
fhandle=locate_file(fileloc, 0);
if(restype==REF_ITM) tmpstr=my_item.RetrieveResourceRef(fhandle);
else tmpstr=my_spell.RetrieveResourceRef(fhandle);
break;
case REF_BMP: case REF_BAM:
tmpstr=key;
break;
}
if(restype==REF_BMP) fc=read_bmp(tmpstr, &my_bam);
else fc=read_bam(tmpstr,&my_bam);
if(!fc)
{
fc=my_bam.GetFrameIndex(0,0);
if(restype!=REF_SPL) my_bam.MakeBitmap(fc,RGB(32,32,32),m_preview.m_bm,BM_RESIZE,32,32);
else my_bam.MakeBitmap(fc,RGB(255,198,128),m_preview.m_bm,BM_RESIZE,32,32);
}
else
{
if(m_preview.m_bm)
{
DeleteObject(m_preview.m_bm);
m_preview.m_bm=0;
}
}
m_preview.RedrawContent();
m_preview.ShowWindow(true);
break;
case REF_ARE:
case REF_MOS:
if(editflg&PREVIEW)
{
m_preview.ShowWindow(false);
return;
}
m_preview.SetWindowText(key);
if(restype==REF_ARE)
{
fhandle=locate_file(fileloc, 0);
tmpstr=my_area.RetrieveMosRef(fhandle);
}
else tmpstr=key;
if(read_mos(tmpstr,&my_mos,true))
{
my_mos.new_mos();
}
else
{
if(m_preview.m_bm)
{
DeleteObject(m_preview.m_bm);
m_preview.m_bm=0;
}
}
m_preview.m_maxextentx=m_preview.m_maxextenty=8;
my_mos.m_tileheaders=NULL;
m_preview.InitView(0, &my_mos);
m_preview.RedrawContent();
m_preview.ShowWindow(true);
break;
}
}
void CItemPicker::ResolveKey(CString &key, loc_entry &fileloc, int restype)
{
long nameref;
CString tmpstr;
int fhandle;
if(editflg&RESOLVE) return;
switch(restype)
{
case REF_ARE:
if(!the_2da.rows) return;
nameref=atoi(the_2da.FindValue(key,1));
break;
case REF_ITM:
fhandle=locate_file(fileloc, 0);
nameref=my_item.RetrieveNameRef(fhandle);
break;
case REF_CRE:
fhandle=locate_file(fileloc, 0);
nameref=my_creature.RetrieveNameRef(fhandle);
break;
case REF_SPL:
fhandle=locate_file(fileloc, 0);
nameref=my_spell.RetrieveNameRef(fhandle);
break;
case REF_STO:
fhandle=locate_file(fileloc, 0);
nameref=my_store.RetrieveNameRef(fhandle);
break;
default:
return;
}
if(nameref<=0) tmpstr=" (?)";
tmpstr=CString(" (")+resolve_tlk_text(nameref)+")";
key+=tmpstr;
}
void CItemPicker::FillList(int restype, CListBox &list)
{
POSITION pos;
CString key;
loc_entry fileloc;
int idx;
list.ResetContent();
idx=determinetype(restype);
if(!idx)
{
MessageBox("Internal error (no method for filling listbox)","Error",MB_OK);
return;
}
else pos=resources[idx]->GetStartPosition();
while(pos)
{
resources[idx]->GetNextAssoc(pos,key,fileloc);
ResolveKey(key,fileloc,restype);
list.AddString(key);
}
}
void CItemPicker::RefreshDialog()
{
CString tmp;
CRect rect;
int flg;
tmp.LoadString(idstrings[determinetype(m_restype)]);
tmp="Pick "+tmp;
if(readonly) tmp+=" (read only)";
SetWindowText(tmp);
FillList(m_restype,m_pick_control);
flg=!(editflg&RESOLVE);
((CButton *) GetDlgItem(IDC_RESOLVE))->SetCheck(flg);
flg=!(editflg&PREVIEW);
((CButton *) GetDlgItem(IDC_PREVIEW))->SetCheck(flg);
}
BOOL CItemPicker::OnInitDialog()
{
CString tmp;
CRect rect;
CDialog::OnInitDialog();
switch(m_restype)
{
case REF_ARE:
the_2da.new_2da();
read_2da("MAPNAME");
//falling through
case REF_BMP:
case REF_BAM:
case REF_ITM:
case REF_SPL:
case REF_MOS:
GetDlgItem(IDC_PREVIEW)->ShowWindow(true);
m_preview.Create(IDD_IMAGEVIEW,this);
GetWindowRect(rect);
m_preview.SetWindowPos(0,rect.right,rect.top,0,0,SWP_NOACTIVATE|SWP_NOZORDER|SWP_HIDEWINDOW|SWP_NOSIZE);
break;
case REF_WAV:
case REF_ACM:
GetDlgItem(IDC_PLAY)->ShowWindow(true);
break;
}
RefreshDialog();
m_pick_control.SelectString(0,m_picked);
OnSelchangePick();
return TRUE;
}
void CItemPicker::OnSearch()
{
CString tmpstr;
int cnt;
int i;
UpdateData(UD_RETRIEVE);
if(m_pick_control.SelectString(m_pick_control.GetCurSel(),m_text)==-1)
{
cnt=m_pick_control.GetCount();
i=m_pick_control.GetCurSel()+1;
if(m_text.GetLength())
{
m_text.MakeLower();
if(m_text.GetAt(0)=='*') m_text=m_text.Mid(1);
for(i=m_pick_control.GetCurSel()+1;i<cnt;i++)
{
m_pick_control.GetText(i,tmpstr);
tmpstr.MakeLower();
if(tmpstr.Find(m_text)!=-1)
{
break;
}
}
}
if(i==cnt)
{
m_pick_control.SetCurSel(0);
}
else
{
m_pick_control.SetCurSel(i);
}
}
OnSelchangePick();
}
void CItemPicker::OnResolve()
{
editflg^=RESOLVE;
RefreshDialog();
}
void CItemPicker::OnPreview()
{
editflg^=PREVIEW;
OnSelchangePick();
}
void CItemPicker::OnPlay()
{
int sel;
CString key;
sel=m_pick_control.GetCurSel();
if(sel>=0 && sel<m_pick_control.GetCount())
{
m_pick_control.GetText(sel,key);
}
play_acm(key,m_restype==REF_ACM,0);
}
void CItemPicker::OnSelchangePick()
{
int sel;
int x;
int idx;
CString key;
loc_entry fileloc;
sel=m_pick_control.GetCurSel();
if(sel>=0 && sel<m_pick_control.GetCount())
{
m_pick_control.GetText(sel,key);
x=key.Find(" ");
if(x>0) key=key.Left(x);
}
idx=determinetype(m_restype);
resources[idx]->Lookup(key,fileloc);
Preview(key,fileloc,m_restype);
}
void CItemPicker::PostNcDestroy()
{
my_bam.new_bam();
my_mos.new_mos();
CDialog::PostNcDestroy();
}