-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathieditable.cpp
279 lines (232 loc) · 5.33 KB
/
ieditable.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
#include "StdAfx.h"
// TEXT
const WCHAR rgwzTypeName[][18] = {L"Wall",
L"Flipper",
L"Timer",
L"Plunger",
L"Textbox",
L"Bumper",
L"Trigger",
L"Light",
L"Kicker",
L"Decal",
L"Gate",
L"Spinner",
L"Ramp",
L"DispReel", //>>> added by Chris
L"Primitive",
L"Flasher",
};
IEditable::IEditable()
{
m_phittimer = NULL;
m_wzVBAName = NULL;
m_wzVBACode = NULL;
m_fBackglass = fFalse;
isVisible = true;
VariantInit(&m_uservalue);
}
IEditable::~IEditable()
{
if (m_wzVBAName)
delete [] m_wzVBAName;
if (m_wzVBACode)
delete [] m_wzVBACode;
}
Hitable *IEditable::GetIHitable()
{
return NULL;
}
void IEditable::SetDirtyDraw()
{
GetPTable()->SetDirtyDraw();
}
void IEditable::ClearForOverwrite()
{
}
void IEditable::Delete()
{
GetPTable()->m_vedit.RemoveElement((IEditable *)this);
MarkForDelete();
APCPROJECTUNDEFINE
GetPTable()->m_pcv->RemoveItem(GetScriptable());
for (int i=0;i<m_vCollection.Size();i++)
{
Collection *pcollection = m_vCollection.ElementAt(i);
pcollection->m_visel.RemoveElement(GetISelect());
}
}
void IEditable::Uncreate()
{
GetPTable()->m_vedit.RemoveElement((IEditable *)this);
APCPROJECTUNDEFINE
GetPTable()->m_pcv->RemoveItem(GetScriptable());
}
HRESULT IEditable::put_TimerEnabled(VARIANT_BOOL newVal, BOOL *pte)
{
STARTUNDO
BOOL fNew = VBTOF(newVal);
if (fNew != *pte)
{
if (m_phittimer)
{
if (fNew)
{
m_phittimer->m_nextfire = g_pplayer->m_time_msec + m_phittimer->m_interval;
g_pplayer->m_vht.AddElement(m_phittimer);
}
else
g_pplayer->m_vht.RemoveElement(m_phittimer);
}
}
*pte = fNew;
STOPUNDO
return S_OK;
}
HRESULT IEditable::put_TimerInterval(long newVal, int *pti)
{
STARTUNDO
*pti = newVal;
if (m_phittimer)
{
m_phittimer->m_interval = newVal;
m_phittimer->m_nextfire = g_pplayer->m_time_msec + m_phittimer->m_interval;
}
STOPUNDO
return S_OK;
}
HRESULT IEditable::get_UserValue(VARIANT *pVal)
{
VariantClear(pVal);
VariantCopy(pVal, &m_uservalue);
return S_OK;
}
HRESULT IEditable::put_UserValue(VARIANT *newVal)
{
STARTUNDO
VariantInit(&m_uservalue);
VariantClear(&m_uservalue);
/*const HRESULT hr =*/ VariantCopy(&m_uservalue, newVal);
STOPUNDO
return S_OK;
}
void IEditable::BeginPlay()
{
m_vEventCollection.RemoveAllElements();
m_viEventCollection.RemoveAllElements();
m_fSingleEvents = fTrue;
for(int i=0;i<m_vCollection.Size();i++)
{
Collection *pcol = m_vCollection.ElementAt(i);
if (pcol->m_fFireEvents)
{
m_vEventCollection.AddElement(pcol);
m_viEventCollection.AddElement(m_viCollection.ElementAt(i));
}
if (pcol->m_fStopSingleEvents)
m_fSingleEvents = fFalse;
}
}
void IEditable::EndPlay()
{
if (m_phittimer)
{
delete m_phittimer;
m_phittimer = NULL;
}
}
void IEditable::RenderBlueprint(Sur *psur)
{
Render(psur);
}
void IEditable::RenderShadow(ShadowSur * const psur, const float height)
{
}
void IEditable::BeginUndo()
{
GetPTable()->BeginUndo();
}
void IEditable::EndUndo()
{
GetPTable()->EndUndo();
}
void IEditable::MarkForUndo()
{
GetPTable()->m_undo.MarkForUndo(this);
}
void IEditable::MarkForDelete()
{
GetPTable()->m_undo.BeginUndo();
GetPTable()->m_undo.MarkForDelete(this);
#ifdef VBA
CComBSTR bstr;
if (GetIApcProjectItem())
{
GetIApcProjectItem()->get_Name(&bstr);
int len = bstr.Length();
// len+1 for trailing null terminator
m_wzVBAName = new WCHAR[len+1];
memcpy(m_wzVBAName, (WCHAR *)bstr, (len+1)*sizeof(WCHAR));
_VBComponent* pComponent;
VBIDE::_CodeModule* pCodeModule;
// Gets the corresponding VBComponent
GetIApcProjectItem()->get_VBComponent(&pComponent);
// Gets the corresponding CodeModule
pComponent->get_CodeModule((VBIDE::CodeModule**)&pCodeModule);
pComponent->Release();
CComBSTR bstrCode;
long count;
pCodeModule->get_CountOfLines(&count);
// Lines are 1-based
HRESULT hr = pCodeModule->get_Lines(1, count, &bstrCode);
len = bstrCode.Length();
if (len > 0)
{
m_wzVBACode = new WCHAR[len+1];
memcpy(m_wzVBACode, (WCHAR *)bstrCode, (len+1)*sizeof(WCHAR));
}
}
#endif
GetPTable()->m_undo.EndUndo();
}
void IEditable::Undelete()
{
#ifdef VBA
InitVBA(fTrue, 0, m_wzVBAName);
#else
InitVBA(fTrue, 0, (WCHAR *)this);
#endif
for (int i=0;i<m_vCollection.Size();i++)
{
Collection *pcollection = m_vCollection.ElementAt(i);
pcollection->m_visel.AddElement(GetISelect());
}
if (!m_wzVBAName)
// Not a project item (Decal)
return;
delete [] m_wzVBAName;
m_wzVBAName = NULL;
#ifdef VBA
if (m_wzVBACode)
{
_VBComponent* pComponent;
VBIDE::_CodeModule* pCodeModule;
// Gets the corresponding VBComponent
GetIApcProjectItem()->get_VBComponent(&pComponent);
// Gets the corresponding CodeModule
pComponent->get_CodeModule((VBIDE::CodeModule**)&pCodeModule);
pComponent->Release();
CComBSTR bstrCode = m_wzVBACode;
HRESULT hr = pCodeModule->InsertLines(1, bstrCode);
delete [] m_wzVBACode;
m_wzVBACode = NULL;
}
#endif
}
void IEditable::InitScript()
{
if (lstrlenW(GetScriptable()->m_wzName) == 0)
// Just in case something screws up - not good having a null script name
swprintf_s(GetScriptable()->m_wzName, L"%d", (long)this);
GetPTable()->m_pcv->AddItem(GetScriptable(), fFalse);
}