/
ResourceListDoc.cpp
174 lines (137 loc) · 4.39 KB
/
ResourceListDoc.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
// ResourceListDoc.cpp : implementation file
//
#include "stdafx.h"
#include "SCIPicEditor.h"
#include "ResourceListDoc.h"
// ResourceListDoc
IMPLEMENT_DYNCREATE(CResourceListDoc, CDocument)
CResourceListDoc::CResourceListDoc()
{
// Add ourselves as a sync
CResourceMap &map = theApp.GetResourceMap();
map.AddSync(this);
_shownResourceType = RS_NONE;
}
BOOL CResourceListDoc::OnOpenDocument(LPCTSTR lpszPathName)
{
BOOL fRet = __super::OnOpenDocument(lpszPathName);
theApp.GenerateBrowseInfo();
return fRet;
}
BOOL CResourceListDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
theApp.GenerateBrowseInfo();
return TRUE;
}
void CResourceListDoc::OnCloseDocument()
{
std::string strEmpty;
theApp.GetResourceMap().SetGameFolder(strEmpty);
// Remove ourselves as a sync
CResourceMap &map = theApp.GetResourceMap();
map.RemoveSync((ISyncResourceMap*)this);
theApp.ResetClassBrowser();
theApp.ClearResourceManagerDoc();
__super::OnCloseDocument();
}
CResourceListDoc::~CResourceListDoc()
{
}
BEGIN_MESSAGE_MAP(CResourceListDoc, CDocument)
ON_UPDATE_COMMAND_UI(ID_FILE_CLOSE, OnDisableCommand)
ON_UPDATE_COMMAND_UI(ID_FILE_SAVE, OnDisableCommand)
ON_UPDATE_COMMAND_UI(ID_FILE_SAVE_AS, OnDisableCommand)
END_MESSAGE_MAP()
// Always disable certain commands when this doc has focus.
// You can't save/saveas or close a resource doc
void CResourceListDoc::OnDisableCommand(CCmdUI *pCmdUI)
{
pCmdUI->Enable(FALSE);
}
HRESULT CResourceListDoc::OnResourceAdded(const ResourceBlob *pData)
{
// Add this as the most recent resource of this type/number/package
theApp._resourceRecency.AddResourceToRecency(pData);
// Heinous re-interpret cast.
UpdateAllViews(NULL, VIEWUPDATEHINT_RESOURCEADDED, reinterpret_cast<CObject*>(const_cast<ResourceBlob*>(pData)));
return S_OK;
}
HRESULT CResourceListDoc::OnResourceDeleted(const ResourceBlob *pDataDeleted)
{
// Delete this from the recency
// It is crucial that this come before the update below. We will check the recency list
// for the ResourceBlob passed to UpdateAllViews, and at this point, we want to not find
// it in the list.
theApp._resourceRecency.DeleteResourceFromRecency(pDataDeleted);
// Cast away constness...
UpdateAllViews(NULL, VIEWUPDATEHINT_RESOURCEDELETED, (CObject*)(LPARAM)pDataDeleted);
return S_OK;
}
HRESULT CResourceListDoc::OnResourceMapReloaded()
{
UpdateAllViews(NULL, VIEWUPDATEHINT_RESOURCEMAPCHANGED);
return S_OK;
}
HRESULT CResourceListDoc::OnResourceTypeReloaded(int iType)
{
CResourceTypeWrap resourceType(iType);
UpdateAllViews(NULL, VIEWUPDATEHINT_RESOURCETYPECHANGED, &resourceType);
return S_OK;
}
void CResourceListDoc::ShowResourceType(ResourceType iType)
{
if (iType != _shownResourceType)
{
char sz[200];
StringCchPrintf(sz, ARRAYSIZE(sz), "Setting to type %x\n", iType);
OutputDebugString(sz);
_shownResourceType = iType;
CResourceTypeWrap resourceType(iType);
UpdateAllViewsAndNonViews(NULL, VIEWUPDATEHINT_SHOWRESOURCETYPE, &resourceType);
}
}
// ResourceListDoc diagnostics
#ifdef _DEBUG
void CResourceListDoc::AssertValid() const
{
CDocument::AssertValid();
}
void CResourceListDoc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG
// ResourceListDoc serialization
void CResourceListDoc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
// There is nothing to save.
int x = 0;
}
else
{
CFile *pFile = ar.GetFile();
// Set the current directory, so we know where to look for the resource files.
// If not, clicking on an item in the recent documents list won't work
CString path = pFile->GetFilePath();
path.MakeLower();
int iFileOffset = path.Find(TEXT("\\resource.map"));
if (iFileOffset > 0)
{
path.SetAt(iFileOffset, 0); // Null terminate it
// Set this folder as our new game folder
CResourceMap &map = theApp.GetResourceMap();
map.SetGameFolder((PCSTR)path);
theApp.LogInfo(TEXT("Open game: %s"), (PCTSTR)path);
UpdateAllViews(NULL, VIEWUPDATEHINT_RESOURCEMAPCHANGED, pFile);
}
else
{
AfxMessageBox(TEXT("SCI game resources must be called resource.map"), MB_OK | MB_ICONEXCLAMATION);
}
}
}
// ResourceListDoc commands