-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSelectNewGameDialog.cpp
More file actions
171 lines (147 loc) · 4.56 KB
/
SelectNewGameDialog.cpp
File metadata and controls
171 lines (147 loc) · 4.56 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
// SelectNewGameDialog.cpp: ôàéë ðåàëèçàöèè
//
#include "stdafx.h"
#include "PlainInstead.h"
#include "SelectNewGameDialog.h"
#include "IniFile.h"
// äèàëîãîâîå îêíî CSelectNewGameDialog
IMPLEMENT_DYNAMIC(CSelectNewGameDialog, CDialog)
CSelectNewGameDialog::CSelectNewGameDialog(CString& selGameFile, CString& selName, bool& selLastGame, CWnd* pParent /*=NULL*/)
: CDialog(CSelectNewGameDialog::IDD, pParent),
m_selGameFile(selGameFile),
m_selName(selName),
m_bSelectLastGame(selLastGame)
{
}
CSelectNewGameDialog::~CSelectNewGameDialog()
{
}
void CSelectNewGameDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_LIST_GAMES, m_ListGames);
DDX_Control(pDX, IDC_EDIT_ABOUT, m_GamesDescr);
}
BEGIN_MESSAGE_MAP(CSelectNewGameDialog, CDialog)
ON_WM_SIZE()
ON_LBN_SELCHANGE(IDC_LIST_GAMES, &CSelectNewGameDialog::OnLbnSelchangeListGames)
ON_BN_CLICKED(IDOK, &CSelectNewGameDialog::OnBnClickedOk)
ON_BN_CLICKED(IDC_BUTTON_START_LAST_GAME, &CSelectNewGameDialog::OnBnClickedButtonStartLastGame)
END_MESSAGE_MAP()
// îáðàáîò÷èêè ñîîáùåíèé CSelectNewGameDialog
void CSelectNewGameDialog::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
// Àâòîìàñøòàáèðîâàíèå êîìïîíåíòîâ
const int contHeight = 20;
if (m_ListGames.m_hWnd) m_ListGames.SetWindowPos(NULL, 0, contHeight, cx, (cy-contHeight*2)/2, SWP_NOACTIVATE | SWP_NOZORDER);
if (m_GamesDescr.m_hWnd) m_GamesDescr.SetWindowPos(NULL, 0, (cy-contHeight*2)/2, cx, cy/2-contHeight, SWP_NOACTIVATE | SWP_NOZORDER);
}
static void ListFilesGamInDirectory(LPCTSTR dirName,std::vector<CString> & filepaths )
{
// Check input parameters
ASSERT( dirName != NULL );
// Clear filename list
filepaths.clear();
// Object to enumerate files
CFileFind finder;
// Build a string using wildcards *.*,
// to enumerate content of a directory
CString wildcard( dirName );
wildcard += _T("\\*.*");
// Init the file finding job
BOOL working = finder.FindFile( wildcard );
// For each file that is found:
while ( working )
{
// Update finder status with new file
working = finder.FindNextFile();
// Skip '.' and '..'
if ( finder.IsDots() )
{
continue;
}
// Skip sub-directories
if ( finder.IsDirectory() )
{
// Add file path to container
filepaths.push_back(finder.GetFileName());
continue;
}
}
// Cleanup file finder
finder.Close();
}
BOOL CSelectNewGameDialog::OnInitDialog()
{
CDialog::OnInitDialog();
std::vector< CString > filePaths;
//GetCurrentDirectory( MAX_PATH, CStrBuf(dir, MAX_PATH) );
TCHAR buff[MAX_PATH];
memset(buff, 0, MAX_PATH);
::GetModuleFileName(NULL, buff, sizeof(buff));
baseDir = buff;
baseDir = baseDir.Left(baseDir.ReverseFind(_T('\\')) + 1);
CString dir = baseDir + L"\\games";
ListFilesGamInDirectory( dir, filePaths );
//Îáíîâëåíèå ïîëÿ âûáîðà èãð
CIniFile iniFile(baseDir+L"\\games\\info.ini", 1024);
for ( size_t i = 0; i < filePaths.size(); i++ )
{
CString strName;
iniFile.GetString(L"game_name", filePaths[i], strName, L"");
if (strName.GetLength()>0)
{
m_ListGames.AddString(strName);
CString strDescr;
iniFile.GetString(L"game_desc", filePaths[i], strDescr, L"Íåò äàííûõ");
fileNameDescr.push_back(std::make_pair(filePaths[i],strDescr));
if (i==0)
{
m_GamesDescr.SetWindowTextW(strDescr);
}
}
else
{
m_ListGames.AddString(filePaths[i]);
fileNameDescr.push_back(std::make_pair(filePaths[i],L"Íåò äàííûõ"));
}
}
m_ListGames.SetCurSel(0);
m_ListGames.SetFocus();
return FALSE; // Âîçâðàòèòü TRUE, åñëè Âû íå óñòàíàâëèâàåòå ôîêóñ ââîäà ê ýëåìåíòó óïðàâëåíèÿ
}
void CSelectNewGameDialog::OnLbnSelchangeListGames()
{
// TODO: äîáàâüòå ñâîé êîä îáðàáîò÷èêà óâåäîìëåíèé
if (m_ListGames.GetCurSel()<fileNameDescr.size())
m_GamesDescr.SetWindowTextW(fileNameDescr[m_ListGames.GetCurSel()].second);
else
m_GamesDescr.SetWindowTextW(L"");
}
void CSelectNewGameDialog::OnBnClickedOk()
{
// TODO: äîáàâüòå ñâîé êîä îáðàáîò÷èêà óâåäîìëåíèé
if (m_ListGames.GetCurSel() >= 0 && m_ListGames.GetCurSel()<fileNameDescr.size())
{
m_selGameFile = baseDir + L"games\\";
m_selGameFile.Append(fileNameDescr[m_ListGames.GetCurSel()].first);
m_ListGames.GetText(m_ListGames.GetCurSel(),m_selName);
m_bSelectLastGame = false;
}
else
{
m_selGameFile = L"";
m_selName = L"";
}
OnOK();
}
void CSelectNewGameDialog::OnBnClickedButtonStartLastGame()
{
// TODO: äîáàâüòå ñâîé êîä îáðàáîò÷èêà óâåäîìëåíèé
m_bSelectLastGame = true;
CIniFile mainSettings;
mainSettings.GetString(L"main", L"lastGameFile", m_selGameFile, L"");
mainSettings.GetString(L"main", L"lastGameName", m_selName, L"");
OnOK();
}