/
PortraitsDlg.cpp
336 lines (270 loc) · 8.93 KB
/
PortraitsDlg.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
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
// PortraitsDlg.cpp : implementation file
//
/************************************************************************************
Copyright (c) 2000 Aaron O'Neil
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1) Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2) Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3) Redistributions in binary form must reproduce the above copyright notice on
program startup. Additional credits for program modification are acceptable
but original copyright and credits must be visible at startup.
4) You may charge a reasonable copying fee for any distribution of Shadow Keeper.
You may charge any fee you choose for support of Shadow Keeper. You may not
charge a fee for Shadow Keeper itself.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**************************************************************************************/
#include "stdafx.h"
#include "dalekeeper.h"
#include "PortraitsDlg.h"
#include "InfKey.h"
#include "Global.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CPortraitsDlg dialog
CPortraitsDlg::CPortraitsDlg(CWnd* pParent /*=NULL*/)
: CDialog(CPortraitsDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CPortraitsDlg)
//}}AFX_DATA_INIT
}
void CPortraitsDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPortraitsDlg)
DDX_Control(pDX, IDC_SMALL_PORTRAITS, m_lbSmall);
DDX_Control(pDX, IDC_EXTRACT_SMALL, m_btnExtractSmall);
DDX_Control(pDX, IDC_EXTRACT_LARGE, m_btnExtractLarge);
DDX_Control(pDX, IDC_LARGE_PORTRAITS, m_lbLarge);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CPortraitsDlg, CDialog)
//{{AFX_MSG_MAP(CPortraitsDlg)
ON_LBN_SELCHANGE(IDC_LARGE_PORTRAITS, OnSelchangeLargePortraits)
ON_LBN_SELCHANGE(IDC_SMALL_PORTRAITS, OnSelchangeSmallPortraits)
ON_BN_CLICKED(IDC_EXTRACT_LARGE, OnExtractLarge)
ON_BN_CLICKED(IDC_EXTRACT_SMALL, OnExtractSmall)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPortraitsDlg message handlers
BOOL CPortraitsDlg::OnInitDialog()
{
CDialog::OnInitDialog();
CRect rLarge;
m_lbLarge.GetWindowRect(&rLarge);
ScreenToClient(&rLarge);
CRect rBmpLarge;
rBmpLarge.left = rLarge.right+7;
rBmpLarge.top = rLarge.top;
rBmpLarge.right = rBmpLarge.left + 110 + 1;
rBmpLarge.bottom = rBmpLarge.top + 170 + 1;
m_bwLarge.Create(rBmpLarge,this,1000);
CRect rExtract;
m_btnExtractLarge.GetWindowRect(&rExtract);
ScreenToClient(&rExtract);
int nButtonHeight = rExtract.Height();
rExtract.left = rBmpLarge.left;
rExtract.right = rBmpLarge.right;
rExtract.bottom = rLarge.bottom;
rExtract.top = rLarge.bottom - nButtonHeight;
m_btnExtractLarge.MoveWindow(&rExtract);
CRect rSmall;
m_lbSmall.GetWindowRect(&rSmall);
ScreenToClient(&rSmall);
CRect rBmpSmall;
rBmpSmall.left = rSmall.right+7;
rBmpSmall.top = rSmall.top;
rBmpSmall.right = rBmpSmall.left + 38 + 1;
rBmpSmall.bottom = rBmpSmall.top + 60 + 1;
m_bwSmall.Create(rBmpSmall,this,1001);
m_btnExtractSmall.GetWindowRect(&rExtract);
ScreenToClient(&rExtract);
rExtract.bottom = rSmall.bottom;
rExtract.top = rExtract.bottom - nButtonHeight;
m_btnExtractSmall.MoveWindow(&rExtract);
FillLists();
m_lbLarge.SelectString(-1,m_strLarge);
OnSelchangeLargePortraits();
m_lbSmall.SelectString(-1,m_strSmall);
OnSelchangeSmallPortraits();
return TRUE;
}
void CPortraitsDlg::GetResourceList(CListBox &lb, char chSize, int nWidth, int nHeight)
{
CObList *pList;
if (!_infKey.GetResList(RESTYPE_BMP,pList))
return;
ASSERT(pList);
chSize = toupper(chSize);
int nIndex;
BMPTOP top;
CResInfo *pResInfo;
CInfBifFile *pBmpFile;
POSITION pos = pList->GetHeadPosition();
while(pos)
{
pResInfo = (CResInfo*)pList->GetNext(pos);
// According to the docs, all large portraits end with an 'L'. I'm going to
// assume all the resources follow this rule.
if (pResInfo->strName.IsEmpty() || toupper(pResInfo->strName.GetAt(pResInfo->strName.GetLength()-1)) != chSize)
continue;
// Make sure the size is agreeable.
pBmpFile = _infKey.GetBifFile(pResInfo);
if (!pBmpFile || !pBmpFile->IsValid())
continue;
if (pBmpFile->GetData(pResInfo,&top,sizeof(BMPTOP)) == -1)
continue;
if (top.bih.biWidth != nWidth || top.bih.biHeight != nHeight)
continue;
nIndex = lb.AddString(pResInfo->strName);
lb.SetItemData(nIndex,1); // Set to 1 for in-game resources.
}
}
void CPortraitsDlg::GetPortraitList(CListBox &lb, char chSize, int nWidth, int nHeight)
{
char szSearch[MAX_PATH+1];
char szPath[MAX_PATH+1];
char szFilename[MAX_PATH+1];
sprintf(szPath,"%s%s",(const char *)_strInstallPath,DIR_PORTRAITS);
sprintf(szSearch,"%s*%c.bmp",szPath,chSize);
WIN32_FIND_DATA fd;
HANDLE hFile = ::FindFirstFile(szSearch,&fd);
if (hFile == INVALID_HANDLE_VALUE)
return;
char szFile[MAX_PATH+1];
CFile file;
BMPTOP top;
int nIndex;
BOOL bFoundAnother = TRUE;
while(bFoundAnother)
{
strcpy(szFile,fd.cFileName);
bFoundAnother = ::FindNextFile(hFile,&fd);
if (strlen(szFile)-4 > 8)
continue;
sprintf(szFilename,"%s%s",szPath,szFile);
if (!file.Open(szFilename,CFile::modeRead|CFile::shareDenyNone|CFile::typeBinary))
continue;
if (file.Read(&top,sizeof(BMPTOP)) != sizeof(BMPTOP))
continue;
file.Close();
if (top.bih.biWidth != nWidth || top.bih.biHeight != nHeight)
continue;
szFile[strlen(szFile)-4] = '\x0';
// Make sure it isn't alreadyin the list. If it is, then there is a BMP called
// the same thing as one of hte internal resources.
if (lb.FindString(-1,szFile) != LB_ERR)
continue;
nIndex = lb.AddString(szFile);
lb.SetItemData(nIndex,0);
}
}
void CPortraitsDlg::FillLists()
{
m_lbLarge.ResetContent();
m_bwLarge.SetBitmap(NULL);
GetResourceList(m_lbLarge,'M',110,170);
GetPortraitList(m_lbLarge,'L',110,170);
m_lbSmall.ResetContent();
m_bwSmall.SetBitmap(NULL);
GetResourceList(m_lbSmall,'S',38,60);
GetPortraitList(m_lbSmall,'S',38,60);
}
void CPortraitsDlg::OnSelchangeLargePortraits()
{
int nIndex = m_lbLarge.GetCurSel();
if (nIndex == LB_ERR)
return;
if (m_lbLarge.GetItemData(nIndex))
m_btnExtractLarge.EnableWindow(TRUE);
else
m_btnExtractLarge.EnableWindow(FALSE);
CString strName;
m_lbLarge.GetText(nIndex,strName);
HBITMAP hBitmap;
GetResourceBitmap(strName,hBitmap,110,170);
m_bwLarge.SetBitmap(hBitmap);
}
void CPortraitsDlg::OnSelchangeSmallPortraits()
{
int nIndex = m_lbSmall.GetCurSel();
if (nIndex == LB_ERR)
return;
if (m_lbSmall.GetItemData(nIndex))
m_btnExtractSmall.EnableWindow(TRUE);
else
m_btnExtractSmall.EnableWindow(FALSE);
CString strName;
m_lbSmall.GetText(nIndex,strName);
HBITMAP hBitmap;
GetResourceBitmap(strName,hBitmap,38,60);
m_bwSmall.SetBitmap(hBitmap);
}
void CPortraitsDlg::OnExtractLarge()
{
int nIndex = m_lbLarge.GetCurSel();
if (nIndex == LB_ERR || !m_lbLarge.GetItemData(nIndex))
return;
CString strRes;
m_lbLarge.GetText(nIndex,strRes);
if (ExtractResource(RESTYPE_BMP,strRes,_strInstallPath+DIR_PORTRAITS))
AfxMessageBox("Bitmap extracted.");
}
void CPortraitsDlg::OnExtractSmall()
{
int nIndex = m_lbSmall.GetCurSel();
if (nIndex == LB_ERR || !m_lbSmall.GetItemData(nIndex))
return;
CString strRes;
m_lbSmall.GetText(nIndex,strRes);
if (ExtractResource(RESTYPE_BMP,strRes,_strInstallPath+DIR_PORTRAITS))
AfxMessageBox("Bitmap extracted.");
}
void CPortraitsDlg::OnOK()
{
CString strMessage = "You must make a selection from both lists before saving changes.";
int nIndex = m_lbLarge.GetCurSel();
if (nIndex == LB_ERR)
{
AfxMessageBox(strMessage);
return;
}
m_lbLarge.GetText(nIndex,m_strLarge);
if (m_strLarge.IsEmpty())
{
AfxMessageBox(strMessage);
return;
}
nIndex = m_lbSmall.GetCurSel();
if (nIndex == LB_ERR)
{
AfxMessageBox(strMessage);
return;
}
m_lbSmall.GetText(nIndex,m_strSmall);
if (m_strSmall.IsEmpty())
{
AfxMessageBox(strMessage);
return;
}
CDialog::OnOK();
}