-
Notifications
You must be signed in to change notification settings - Fork 7
/
Mighty.cpp
314 lines (256 loc) · 8.26 KB
/
Mighty.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
// Mighty.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "Mighty.h"
#include "MightyToolTip.h"
#include "InfoBar.h"
#include "BmpMan.h"
#include "Board.h"
#include "BoardWrap.h"
#include "MainFrm.h"
#include "DSB.h"
#include "DEtc.h"
#include "DOption.h"
#include "DScoreBoard.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
// 유틸리티들
// 비트맵의 크기를 얻는다
CSize GetBitmapSize( UINT idBitmap )
{
// 자주 사용되는 IDB_SA 와 IDB_SPADE 는 미리 저장해 둔다
static CSize s_sz_IDB_SA(0,0);
static CSize s_sz_IDB_SPADE(0,0);
if ( idBitmap == IDB_SA && s_sz_IDB_SA.cy )
return s_sz_IDB_SA;
if ( idBitmap == IDB_SPADE && s_sz_IDB_SPADE.cy )
return s_sz_IDB_SPADE;
CBitmap bm;
BITMAP bmInfo;
VERIFY( bm.LoadBitmap( idBitmap ) );
VERIFY( bm.GetBitmap( &bmInfo ) );
if ( idBitmap == IDB_SA && !s_sz_IDB_SA.cx )
s_sz_IDB_SA.cx = bmInfo.bmWidth,
s_sz_IDB_SA.cy = bmInfo.bmHeight;
if ( idBitmap == IDB_SPADE && !s_sz_IDB_SPADE.cx )
s_sz_IDB_SPADE.cx = bmInfo.bmWidth,
s_sz_IDB_SPADE.cy = bmInfo.bmHeight;
VERIFY( bm.DeleteObject() );
return CSize( bmInfo.bmWidth, bmInfo.bmHeight );
}
// 비트맵을 그린다
void DrawBitmap( CDC* pDC, UINT idBitmap,
int xTarget, int yTarget,
int cxTarget, int cyTarget,
int xSource, int ySource,
int cxSource, int cySource )
{
CDC dc;
CBitmap bm, *pbmOld;
BITMAP bmInfo;
VERIFY( dc.CreateCompatibleDC( pDC ) );
VERIFY( bm.LoadBitmap( idBitmap ) );
VERIFY( bm.GetBitmap( &bmInfo ) );
pbmOld = dc.SelectObject( &bm );
pDC->SetTextColor( RGB(0,0,0) );
pDC->SetBkColor( RGB(255,255,255) );
VERIFY(
pDC->StretchBlt( xTarget, yTarget,
( cxTarget == -1 ? bmInfo.bmWidth : cxTarget ),
( cyTarget == -1 ? bmInfo.bmHeight : cyTarget ),
&dc,
( xSource == -1 ? 0 : xSource ),
( ySource == -1 ? 0 : ySource ),
( cxSource == -1 ? bmInfo.bmWidth : cxSource ),
( cySource == -1 ? bmInfo.bmHeight : cySource ),
SRCCOPY )
);
dc.SelectObject( pbmOld );
VERIFY( bm.DeleteObject() );
}
// 사운드를 연주한다
// ( bStop 이 참이면 이전의 소리를 멈추고 연주 )
void PlaySound( UINT idWave, BOOL bStop )
{
if ( Mo()->bUseSound )
PlaySound( MAKEINTRESOURCE(idWave), AfxGetApp()->m_hInstance,
SND_ASYNC|SND_NODEFAULT|SND_NOWAIT|SND_RESOURCE
| (!bStop?SND_NOSTOP:0) );
}
/////////////////////////////////////////////////////////////////////////////
// CMightyApp
BEGIN_MESSAGE_MAP(CMightyApp, CWinApp)
//{{AFX_MSG_MAP(CMightyApp)
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
ON_COMMAND(ID_APP_OPTION, OnAppOption)
ON_UPDATE_COMMAND_UI(ID_APP_SCOREBOARD, OnUpdateAppScoreboard)
ON_COMMAND(ID_APP_SCOREBOARD, OnAppScoreboard)
ON_COMMAND(ID_HELP, OnHelp)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMightyApp construction
CMightyApp::CMightyApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
m_pInfoBar = 0;
m_pToolTip = new CMightyToolTip;
m_bInBoss = false;
m_pScoreBoard = 0;
}
CMightyApp::~CMightyApp()
{
delete m_pToolTip;
delete m_pScoreBoard;
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CMightyApp object
CMightyApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CMightyApp initialization
BOOL CMightyApp::InitInstance()
{
WSADATA wd;
if ( WSAStartup( MAKEWORD( 1, 1 ), &wd ) != 0 ) {
AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
return FALSE;
}
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
// rule.txt에서 사용자 정의 기본 규칙을 로드한다.
CRule::LoadPreset();
// Change the registry key under which our settings are stored.
// TODO: You should modify this string to be something appropriate
// such as the name of your company or organization.
#ifdef _DEBUG
SetRegistryKey(_T("MightyDebug"));
#else
SetRegistryKey(_T("Mighty"));
#endif
Mo()->Load();
if(Mo()->nPreset > CRule::GetPresetCount()) Mo()->nPreset = 0;
// To create the main window, this code creates a new frame window
// object and then sets it as the application's main window object.
CMainFrame* pFrame = new CMainFrame;
m_pMainWnd = pFrame;
// create and load the frame with its resources
pFrame->LoadFrame(IDR_MAINFRAME,
WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, NULL,
NULL);
// The one and only window has been initialized, so show and update it.
pFrame->ShowWindow(SW_SHOW);
pFrame->UpdateWindow();
// 각 전역 컨트롤 요소를 얻고 생성한다
m_pInfoBar = (CInfoBar*)m_pMainWnd->GetDlgItem( AFX_IDW_STATUS_BAR );
m_pScoreBoard = new DScoreBoard;
m_pScoreBoard->Show(Mo()->bLastScoreboard);
pFrame->GetView()->GetWrapper()->SetMFSM(0);
// 처음으로 뜬 것이라면, 옵션을 보여준다
if ( Mo()->bInit ) {
Mo()->bInit = false;
PostMessage( pFrame->GetSafeHwnd(), WM_COMMAND, ID_APP_OPTION, 0 );
}
return TRUE;
}
int CMightyApp::ExitInstance()
{
VERIFY( WSACleanup() == 0 );
// 옵션 저장
Mo()->Save();
// 다른 쓰레드가 끝나도록 대기한다
#ifndef _DEBUG
Sleep(1000);
#endif
return CWinApp::ExitInstance();
}
/////////////////////////////////////////////////////////////////////////////
// CMightyApp message handlers
// App command to run the dialog
void CMightyApp::OnAppAbout()
{
(new DAbout(Mf()->GetView()->GetWrapper()))->Create();
}
void CMightyApp::OnAppOption()
{
// TODO: Add your command handler code here
DOption opt;
if ( opt.DoModal() == IDOK ) {
// 화면을 다시 Update 한다
CBoardWrap* pWrap = Mf()->GetView()->GetWrapper();
pWrap->ReloadPlayerNames();
pWrap->UpdatePlayer(-2);
}
}
void CMightyApp::OnHelp()
{
// TODO: Add your command handler code here
::WinHelp( 0, _T("Mighty.hlp"), HELP_CONTENTS, 0 );
}
void CMightyApp::OnUpdateAppScoreboard(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck( Mo()->bLastScoreboard ? TRUE : FALSE );
}
void CMightyApp::OnAppScoreboard()
{
// TODO: Add your command handler code here
if ( Mo()->bLastScoreboard ) m_pScoreBoard->Show(false);
else m_pScoreBoard->Show(true);
}
BOOL CMightyApp::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if ( ( pMsg->message == WM_LBUTTONDOWN || pMsg->message == WM_RBUTTONDOWN )
&& m_pToolTip->GetSafeHwnd() ) {
// 툴팁 중
m_pToolTip->PostMessage( WM_CLOSE );
return FALSE;
}
// 보스키 처리
else if ( pMsg && pMsg->message == WM_KEYDOWN
&& pMsg->wParam == VK_PAUSE && !m_bInBoss ) {
m_bInBoss = true;
int nSelector;
if ( Mo()->nBossType == 0 ) // 임의
nSelector = rand()%4;
else nSelector = Mo()->nBossType - 1;
CWnd* pWnd = AfxGetMainWnd();
if ( !pWnd ) return FALSE;
pWnd->ShowWindow( SW_MINIMIZE );
if ( nSelector < 2 ) {
pWnd->SetWindowText(_T("내 컴퓨터"));
pWnd->SetIcon( LoadIcon( IDI_MYCOM ), TRUE );
pWnd->MessageBox(
( nSelector % 2 ? _T("msimg32.dll을(를) 지울 수 없습니다: 공유 위반입니다.\n\n원본이나 대상 프로그램이 실행중인것 같습니다.")
: _T("현재 폴더가 가장 상위 폴더입니다.\n바탕 화면을 보려면 열려 있는 창을 아이콘 표시하십시오.") ),
_T("내 컴퓨터"), MB_OK|MB_ICONSTOP|MB_SETFOREGROUND );
}
else {
pWnd->SetWindowText(_T("Microsoft Internet Explorer"));
pWnd->SetIcon( LoadIcon( IDI_IEX ), TRUE );
if ( nSelector % 2 )
pWnd->MessageBox(
_T("다운로드 완료"),
_T("util.zip(www.microsoft.com)"),
MB_OK|MB_ICONINFORMATION|MB_SETFOREGROUND );
else
pWnd->MessageBox(
_T("http://www.microsoft.com 사이트를 열 수 없습니다.\n\n서버에 연결할 수 없습니다."),
_T("Microsoft Internet Explorer"),
MB_OK|MB_ICONSTOP|MB_SETFOREGROUND );
}
CString sTitle; sTitle.LoadString( IDR_MAINFRAME );
pWnd->SetIcon( LoadIcon( IDR_MAINFRAME ), TRUE );
pWnd->SetWindowText( sTitle );
pWnd->ShowWindow( SW_RESTORE );
m_bInBoss = false;
return FALSE;
}
return CWinApp::PreTranslateMessage(pMsg);
}