AeAssetEditor.c++
6.06 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
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
337
338
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <Xm/Xm.h>
#include <Vk/VkQuestionDialog.h>
#include "GList.h"
#include "AeAssetEditor.h"
#include "AeAssetBase.h"
#include "AeAssetBin.h"
#include "AeAssetBinUI.h"
#include "AeAssetUI.h"
#include "AeAssetWindow.h"
#include "AeBinView.h"
#include "AePlayer.h"
#include "AeN64Driver.h"
#include "AeFile.h"
#include "AeInstFile.h"
#include "AeBankEditor.h"
#include "AeErr.h"
AeAssetEditor::AeAssetEditor (void) : AeBinEditor ()
{
fWindow = NULL;
fFile = NULL;
fSaveNeeded = False;
}
AeAssetEditor::~AeAssetEditor (void)
{
if (fWindow)
delete fWindow;
if (fFile)
delete fFile;
}
void
AeAssetEditor::SetAssetBase (AeAssetBase * assetBase)
{
assert (assetBase); // must be non-NULL
AeBinEditor::SetAssetBase (assetBase);
// create and init all the UI objects for this editor
createBinUIs ();
initBinUIs ();
createAssetUIs ();
initChildBinUIs ();
// default to editing the first bin in the list
fBinUI = (*fBinUIList)[0];
// now that we have data, create a window to display it
fWindow = new AeAssetWindow ("Asset Catalog", this);
fWindow->show();
fView = fWindow->GetView ();
fView->TabSetLabels (); // update the view's bin labels
if (fPlayer)
fPlayer->BuildMenu (fWindow);
}
void
AeAssetEditor::CreateAsset (AeAsset * asset, Boolean suspended)
{
if (asset->IsBankComponent ())
fSaveNeeded = True;
AeBinEditor::CreateAsset (asset, suspended);
}
void
AeAssetEditor::UpdateAsset (AeAsset * asset, Boolean suspended)
{
if (asset->IsBankComponent ())
fSaveNeeded = True;
AeBinEditor::UpdateAsset (asset, suspended);
}
void
AeAssetEditor::DeleteAsset (AeAsset * asset, Boolean suspended)
{
if (asset->IsBankComponent ())
fSaveNeeded = True;
AeBinEditor::DeleteAsset (asset, suspended);
}
void
AeAssetEditor::SaveFile (void)
{
AeErr err;
assert (fFile);
if (fFile)
{
if (!(err = fFile->Write (fAssetBase)))
fSaveNeeded = False;
}
}
void
AeAssetEditor::SaveAsFile (const char * name)
{
if (fFile)
fFile->SetFullName ((char *)name);
else
fFile = (AeAssetFile *)new AeInstFile ((char *)name);
if (fFile)
{
SaveFile ();
fView->setTitle (fFile->GetFileName ());
}
}
//
// This routine opens and reads the named file
// and if successful, it adds its assets to the database
// and saves the file reference.
//
void
AeAssetEditor::OpenFile (const char * name)
{
AeAssetFile * file;
AeAsset * asset;
if (fFile)
CloseFile ();
assert (fFile == NULL);
if (file = getAndReadFile (name, False))
{
fFile = file;
fView->setTitle (fFile->GetFileName ());
}
fSaveNeeded = False;
}
void
AeAssetEditor::CloseFile (void)
{
// if there's a file, see if the user wants it saved
if (fFile)
{
if (fSaveNeeded)
{
AeDialogReply reply = postSaveQuestion ();
if (reply == CANCEL)
return;
if (reply == YES)
SaveFile ();
}
}
// delete all the bank assets and specially notify the player
DeleteAllBankAssets ();
((AeN64Driver *)fPlayer)->CloseBank (); // hack
// if there is a file, then delete it
if (fFile)
{
delete fFile;
fFile = NULL;
fSaveNeeded = False;
}
}
//
// Import assets from the given file name.
// Some files, like inst files, don't need to
// keep the file object around so it can be deleted.
// But other files, like wave files, need their
// file object so it can't be deleted. For now
// never delete the file object, although we're
// wasting memory when importing inst files.
//
void
AeAssetEditor::ImportAsset (const char * name)
{
getAndReadFile (name, True);
}
//
// Open an asset-specific editor.
//
void
AeAssetEditor::OpenEditor (AeAsset * asset)
{
AeEditor * editor;
switch (asset->GetType ())
{
case kBankType:
editor = (AeEditor *)new AeBankEditor;
editor->SetAssetBase (fAssetBase);
((AeBankEditor *)editor)->SetBankAsset ((AeBankAsset *)asset);
break;
}
}
//
// create a new file based on the name and
// then read the file and add its assets to
// the asset base. if an error occurs, abort
// the whole process by deleting the file and
// returning NULL.
//
AeAssetFile *
AeAssetEditor::getAndReadFile (const char * name, Boolean importing)
{
AeAssetFile * file;
GList<AeAsset *> * assetList = NULL;
if (file = AeAssetFile::NewAssetFile ((char *)name))
{
if (file->ReadList (assetList) == kAeNoErr)
{
if (importing)
removeBankAsset (assetList);
fAssetBase->NotifySuspend ();
fAssetBase->AppendAssetList (assetList);
fAssetBase->NotifyResume ();
}
else
{
delete file;
file = NULL;
}
}
if (assetList)
delete assetList;
return file;
}
void
AeAssetEditor::removeBankAsset (GList<AeAsset *> * list)
{
AeAsset * asset;
int i;
list->Start (i);
while (list->Next (i, asset))
{
if (asset->GetType () == kBankType)
{
list->Remove (asset);
break;
}
}
}
Boolean
AeAssetEditor::binHasUI (AeAssetBin * bin)
{
switch (bin->GetType ())
{
case kLoopType:
case kADPCMBookType:
return False;
}
return True;
}
void
AeAssetEditor::createAssetUIs (void)
{
GList<AeAssetBin *> * binList;
AeAssetBin * bin;
GList<AeAsset *> * assetList;
AeAsset * asset;
int i, j;
binList = fAssetBase->GetBinList ();
binList->Start (i);
while (binList->Next (i, bin))
{
assetList = bin->GetAssetList ();
assetList->Start (j);
while (assetList->Next (j, asset))
createAssetUI (asset);
}
}
AeAssetEditor::AeDialogReply
AeAssetEditor::postSaveQuestion (void)
{
VkDialogManager::VkDialogReason reason;
AeDialogReply reply;
theQuestionDialog->setTitle ("Unsaved Changes");
theQuestionDialog->setButtonLabels ("Yes", "Cancel", "No");
reason = theQuestionDialog->postAndWait ("Save changes before closing?",
TRUE, TRUE, TRUE);
if (reason == VkDialogManager::OK)
reply = YES;
else if (reason == VkDialogManager::APPLY)
reply = NO;
else
reply = CANCEL;
return reply;
}