-
Notifications
You must be signed in to change notification settings - Fork 5
/
AGiliTyDoc.cpp
153 lines (128 loc) · 3.6 KB
/
AGiliTyDoc.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
/////////////////////////////////////////////////////////////////////////////
//
// AGiliTy AGT Interpreter
// Visual C++ MFC Windows interface by David Kinder
//
// AGiliTyDoc.cpp: Implementation of document class
//
/////////////////////////////////////////////////////////////////////////////
#include "StdAfx.h"
#include "AGiliTy.h"
#include "AGiliTyDoc.h"
#include "AGiliTyView.h"
extern "C"
{
#include ".\generic\agility.h"
#include ".\generic\interp.h"
}
extern BOOL bResetCursor;
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAGiliTyDoc
/////////////////////////////////////////////////////////////////////////////
IMPLEMENT_DYNCREATE(CAGiliTyDoc, CDocument)
BEGIN_MESSAGE_MAP(CAGiliTyDoc, CDocument)
//{{AFX_MSG_MAP(CAGiliTyDoc)
ON_COMMAND(ID_FILE_RESTORE_GAME, OnFileRestoreGame)
ON_COMMAND(ID_FILE_SAVE_GAME, OnFileSaveGame)
ON_UPDATE_COMMAND_UI(ID_FILE_RESTORE_GAME, OnUpdateFileRestoreGame)
ON_UPDATE_COMMAND_UI(ID_FILE_SAVE_GAME, OnUpdateFileSaveGame)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
CAGiliTyDoc::CAGiliTyDoc()
{
}
CAGiliTyDoc::~CAGiliTyDoc()
{
}
BOOL CAGiliTyDoc::OnOpenDocument(LPCTSTR lpszPathName)
{
if (!CDocument::OnOpenDocument(lpszPathName))
return FALSE;
CString& strGame = ((CAGiliTyApp*)AfxGetApp())->m_strGameFile;
if (strGame.IsEmpty())
strGame = lpszPathName;
else
{
CString strGameArg;
strGame = lpszPathName;
int iExtPos = strGame.ReverseFind('.');
if (iExtPos > 0)
strGameArg = strGame.Left(iExtPos);
else
strGameArg = strGame;
agt_newgame(init_file_context(strGameArg.GetBuffer(256),fNONE));
strGameArg.ReleaseBuffer();
CAGiliTyView* pView = CAGiliTyView::GetView();
if (pView)
pView->SendMessage(WM_CHAR,(TCHAR)0x0D);
}
CAGiliTyApp* pApp = (CAGiliTyApp*)AfxGetApp();
ASSERT_VALID(pApp);
CString strPathName(lpszPathName);
int iPos = strPathName.ReverseFind('\\');
if (iPos > 0)
pApp->m_strFilePath = strPathName.Left(iPos);
else
pApp->m_strFilePath.Empty();
bResetCursor = TRUE;
return TRUE;
}
void CAGiliTyDoc::OnCloseDocument()
{
CString& strGame = ((CAGiliTyApp*)AfxGetApp())->m_strGameFile;
if (strGame.IsEmpty() == FALSE)
{
agt_quit();
quitflag = 1;
}
CDocument::OnCloseDocument();
}
void CAGiliTyDoc::OnFileRestoreGame()
{
CString& strGame = ((CAGiliTyApp*)AfxGetApp())->m_strGameFile;
if (strGame.IsEmpty() == FALSE)
{
agt_restore();
CAGiliTyView* pView = CAGiliTyView::GetView();
if (pView)
pView->SendMessage(WM_CHAR,(TCHAR)0x0D);
}
bResetCursor = TRUE;
}
void CAGiliTyDoc::OnUpdateFileRestoreGame(CCmdUI* pCmdUI)
{
CString& strGame = ((CAGiliTyApp*)AfxGetApp())->m_strGameFile;
pCmdUI->Enable(strGame.IsEmpty() == FALSE);
}
void CAGiliTyDoc::OnFileSaveGame()
{
CString& strGame = ((CAGiliTyApp*)AfxGetApp())->m_strGameFile;
if (strGame.IsEmpty() == FALSE)
{
agt_save();
CAGiliTyView* pView = CAGiliTyView::GetView();
if (pView)
pView->SendMessage(WM_CHAR,(TCHAR)0x0D);
}
bResetCursor = TRUE;
}
void CAGiliTyDoc::OnUpdateFileSaveGame(CCmdUI* pCmdUI)
{
CString& strGame = ((CAGiliTyApp*)AfxGetApp())->m_strGameFile;
pCmdUI->Enable(strGame.IsEmpty() == FALSE);
}
#ifdef _DEBUG
void CAGiliTyDoc::AssertValid() const
{
CDocument::AssertValid();
}
void CAGiliTyDoc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG