-
Notifications
You must be signed in to change notification settings - Fork 8
/
CustomDialogProcs.cpp
495 lines (403 loc) · 15.1 KB
/
CustomDialogProcs.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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
#include "CustomDialogProcs.h"
#include "Construction Set Extender_Resource.h"
#include "Hooks\Hooks-AssetSelector.h"
#include "Achievements.h"
namespace cse
{
namespace uiManager
{
BOOL CALLBACK AssetSelectorDlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_GETMINMAXINFO:
{
MINMAXINFO* SizeInfo = (MINMAXINFO*)lParam;
SizeInfo->ptMaxTrackSize.x = SizeInfo->ptMinTrackSize.x = 189;
SizeInfo->ptMaxTrackSize.y = SizeInfo->ptMinTrackSize.y = 240;
break;
}
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDC_ASSETSELECTOR_FILEBROWSER:
EndDialog(hWnd, hooks::e_FileBrowser);
return TRUE;
case IDC_ASSETSELECTOR_ARCHIVEBROWSER:
achievements::kPowerUser->UnlockTool(achievements::AchievementPowerUser::kTool_AssetSelection);
EndDialog(hWnd, hooks::e_BSABrowser);
return TRUE;
case IDC_ASSETSELECTOR_PATHEDITOR:
achievements::kPowerUser->UnlockTool(achievements::AchievementPowerUser::kTool_AssetSelection);
EndDialog(hWnd, hooks::e_EditPath);
return TRUE;
case IDC_ASSETSELECTOR_CLEARPATH:
achievements::kPowerUser->UnlockTool(achievements::AchievementPowerUser::kTool_AssetSelection);
EndDialog(hWnd, hooks::e_ClearPath);
return TRUE;
case IDC_ASSETSELECTOR_ASSETEXTRACTOR:
achievements::kPowerUser->UnlockTool(achievements::AchievementPowerUser::kTool_AssetSelection);
EndDialog(hWnd, hooks::e_ExtractPath);
return TRUE;
case IDC_ASSETSELECTOR_OPENASSET:
EndDialog(hWnd, hooks::e_OpenPath);
return TRUE;
case IDC_CSE_CANCEL:
EndDialog(hWnd, hooks::e_Close);
return TRUE;
}
break;
}
return FALSE;
}
BOOL CALLBACK TextEditDlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_COMMAND:
{
InitDialogMessageParamT<UInt32>* InitParam = (InitDialogMessageParamT<UInt32>*)GetWindowLongPtr(hWnd, GWL_USERDATA);
switch (LOWORD(wParam))
{
case IDC_CSE_OK:
GetDlgItemText(hWnd, IDC_TEXTEDIT_TEXT, InitParam->Buffer, sizeof(InitParam->Buffer));
EndDialog(hWnd, 1);
return TRUE;
case IDC_CSE_CANCEL:
EndDialog(hWnd, NULL);
return TRUE;
}
}
break;
case WM_INITDIALOG:
SetWindowLongPtr(hWnd, GWL_USERDATA, (LONG_PTR)lParam);
SetDlgItemText(hWnd, IDC_TEXTEDIT_TEXT, ((InitDialogMessageParamT<UInt32>*)lParam)->Buffer);
break;
}
return FALSE;
}
BOOL CALLBACK TESFileSaveDlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDC_TESFILESAVE_SAVEESP:
EndDialog(hWnd, 0);
return TRUE;
case IDC_TESFILESAVE_SAVEESM:
achievements::kPowerUser->UnlockTool(achievements::AchievementPowerUser::kTool_SaveAsESM);
EndDialog(hWnd, 1);
return TRUE;
}
break;
}
return FALSE;
}
BOOL CALLBACK TESComboBoxDlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
HWND ComboBox = GetDlgItem(hWnd, IDC_TESCOMBOBOX_FORMLIST);
switch (uMsg)
{
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDC_CSE_OK:
{
TESForm* SelectedForm = (TESForm*)TESComboBox::GetSelectedItemData(ComboBox);
EndDialog(hWnd, (INT_PTR)SelectedForm);
return TRUE;
}
case IDC_CSE_CANCEL:
EndDialog(hWnd, 0);
return TRUE;
}
break;
case WM_INITDIALOG:
TESComboBox::PopulateWithForms(ComboBox, lParam, true, false);
TESComboBox::SetSelectedItemByIndex(ComboBox, 0);
break;
}
return FALSE;
}
LRESULT CALLBACK CreateGlobalScriptDlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDC_CSE_OK:
{
char QuestID[0x200] = { 0 };
char ScriptID[0x200] = { 0 };
char Delay[8] = { 0 };
char Buffer[0x200] = { 0 };
GetDlgItemText(hWnd, IDC_GLOBALSCRIPT_QUESTID, QuestID, sizeof(QuestID));
GetDlgItemText(hWnd, IDC_GLOBALSCRIPT_SCRIPTID, ScriptID, sizeof(ScriptID));
GetDlgItemText(hWnd, IDC_GLOBALSCRIPT_DELAY, Delay, sizeof(Delay));
TESForm* Form = nullptr;
TESQuest* Quest = nullptr;
Script* QuestScript = nullptr;
Form = TESForm::LookupByEditorID(QuestID);
if (Form)
{
if (Form->formType == TESForm::kFormType_Quest)
{
if (BGSEEUI->MsgBoxW(hWnd,
MB_YESNO,
"Quest '%s' already exists. Do you want to replace its script with a newly created one?",
QuestID) != IDYES)
{
return TRUE;
}
}
else
{
BGSEEUI->MsgBoxE(hWnd, 0, "EditorID '%s' is already in use.", QuestID);
return TRUE;
}
Quest = CS_CAST(Form, TESForm, TESQuest);
}
else
{
Quest = CS_CAST(TESForm::CreateInstance(TESForm::kFormType_Quest), TESForm, TESQuest);
Quest->SetFromActiveFile(true);
Quest->SetEditorID(QuestID);
_DATAHANDLER->quests.AddAt(Quest, eListEnd);
}
if (strlen(ScriptID) < 1)
FORMAT_STR(ScriptID, "%sScript", QuestID);
Form = TESForm::LookupByEditorID(ScriptID);
if (Form)
{
BGSEEUI->MsgBoxE(hWnd, 0, "EditorID '%s' is already in use.", ScriptID);
return TRUE;
}
else
{
QuestScript = CS_CAST(TESForm::CreateInstance(TESForm::kFormType_Script), TESForm, Script);
QuestScript->info.type = Script::kScriptType_Quest;
QuestScript->SetFromActiveFile(true);
if (strlen(Delay))
FORMAT_STR(Buffer, "scn %s\n\nfloat fQuestDelayTime\n\nBegin GameMode\n\tset fQuestDelayTime to %s\n\nend", ScriptID, Delay);
else
FORMAT_STR(Buffer, "scn %s\n\nBegin GameMode\n\nEnd", ScriptID);
QuestScript->SetText(Buffer);
QuestScript->SetEditorID(ScriptID);
_DATAHANDLER->scripts.AddAt(QuestScript, eListEnd);
_DATAHANDLER->SortScripts();
}
Quest->script = QuestScript;
Quest->LinkForm();
QuestScript->LinkForm();
Quest->UpdateUsageInfo();
QuestScript->UpdateUsageInfo();
QuestScript->AddCrossReference(Quest);
achievements::kPowerUser->UnlockTool(achievements::AchievementPowerUser::kTool_GlobalScript);
TESDialog::ShowScriptEditorDialog(TESForm::LookupByEditorID(ScriptID));
DestroyWindow(hWnd);
return TRUE;
}
case IDC_CSE_CANCEL:
DestroyWindow(hWnd);
return TRUE;
}
break;
}
return FALSE;
}
BOOL CALLBACK BindScriptDlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
HWND EditorIDBox = GetDlgItem(hWnd, IDC_BINDSCRIPT_NEWFORMEDITORID);
HWND RefIDBox = GetDlgItem(hWnd, IDC_BINDSCRIPT_NEWREFEDITORID);
HWND ExistFormList = GetDlgItem(hWnd, IDC_BINDSCRIPT_EXISTINGFORMLIST);
HWND SelParentCellBtn = GetDlgItem(hWnd, IDC_BINDSCRIPT_SELECTPARENTCELL);
switch (uMsg)
{
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDC_BINDSCRIPT_SELECTPARENTCELL:
{
TESForm* Selection = (TESForm*)BGSEEUI->ModalDialog(BGSEEMAIN->GetExtenderHandle(),
MAKEINTRESOURCE(IDD_TESCOMBOBOX),
hWnd,
(DLGPROC)TESComboBoxDlgProc,
(LPARAM)TESForm::kFormType_Cell);
if (Selection)
{
char Buffer[0x200] = { 0 };
FORMAT_STR(Buffer, "%s (%08X)", Selection->editorID.c_str(), Selection->formID);
SetWindowText(SelParentCellBtn, (LPCSTR)Buffer);
SetWindowLongPtr(SelParentCellBtn, GWL_USERDATA, (LONG_PTR)Selection);
}
break;
}
case IDC_CSE_OK:
{
if (IsDlgButtonChecked(hWnd, IDC_BINDSCRIPT_BINDEXISTFORM))
{
TESForm* SelectedForm = (TESForm*)TESComboBox::GetSelectedItemData(ExistFormList);
if (SelectedForm)
{
EndDialog(hWnd, (INT_PTR)SelectedForm);
return TRUE;
}
else
BGSEEUI->MsgBoxE(hWnd, 0, "Invalid existing form selected");
}
else
{
char BaseEditorID[0x200] = { 0 };
char RefEditorID[0x200] = { 0 };
char Buffer[0x200] = { 0 };
Edit_GetText(EditorIDBox, BaseEditorID, 0x200);
if (TESForm::LookupByEditorID(BaseEditorID))
BGSEEUI->MsgBoxE(hWnd, 0, "EditorID '%s' is already in use.", BaseEditorID);
else
{
if (IsDlgButtonChecked(hWnd, IDC_BINDSCRIPT_QUESTFORM))
{
bool StartGameEnabledFlag = IsDlgButtonChecked(hWnd, IDC_BINDSCRIPT_QUESTSTARTGAMEENABLED);
bool RepeatedStagesFlag = IsDlgButtonChecked(hWnd, IDC_BINDSCRIPT_QUESTREPEATEDSTAGES);
TESQuest* Quest = CS_CAST(TESForm::CreateInstance(TESForm::kFormType_Quest), TESForm, TESQuest);
Quest->SetFromActiveFile(true);
Quest->SetEditorID(BaseEditorID);
Quest->SetStartGameEnabledFlag(StartGameEnabledFlag);
Quest->SetAllowedRepeatedStagesFlag(RepeatedStagesFlag);
_DATAHANDLER->quests.AddAt(Quest, eListEnd);
TESDialog::ResetFormListControls();
EndDialog(hWnd, (INT_PTR)Quest);
return TRUE;
}
else
{
if (IsDlgButtonChecked(hWnd, IDC_BINDSCRIPT_OBJECTTOKEN))
{
bool QuestItem = IsDlgButtonChecked(hWnd, IDC_BINDSCRIPT_OBJECTTOKENQUESTITEM);
TESObjectCLOT* Token = CS_CAST(TESForm::CreateInstance(TESForm::kFormType_Clothing), TESForm, TESObjectCLOT);
Token->SetFromActiveFile(true);
Token->SetEditorID(BaseEditorID);
_DATAHANDLER->AddTESObject(Token);
SME::MiscGunk::ToggleFlag(&Token->bipedModelFlags, TESBipedModelForm::kBipedModelFlags_NotPlayable, true);
SME::MiscGunk::ToggleFlag(&Token->formFlags, TESForm::kFormFlags_QuestItem, QuestItem);
TESDialog::ResetFormListControls();
EndDialog(hWnd, (INT_PTR)Token);
return TRUE;
}
else
{
Edit_GetText(RefIDBox, RefEditorID, 0x200);
if (TESForm::LookupByEditorID(RefEditorID))
BGSEEUI->MsgBoxE(hWnd, 0, "EditorID '%s' is already in use.", BaseEditorID);
else
{
bool InitiallyDisabled = IsDlgButtonChecked(hWnd, IDC_BINDSCRIPT_OBJECTREFERENCEDISABLED);
TESObjectCELL* ParentCell = CS_CAST(GetWindowLongPtr(SelParentCellBtn, GWL_USERDATA), TESForm, TESObjectCELL);
if (!ParentCell || ParentCell->IsInterior() == 0)
BGSEEUI->MsgBoxE(hWnd, 0, "Invalid/exterior cell selected as parent.");
else
{
TESObjectACTI* Activator = CS_CAST(TESForm::CreateInstance(TESForm::kFormType_Activator),
TESForm, TESObjectACTI);
Activator->SetFromActiveFile(true);
Activator->SetEditorID(BaseEditorID);
_DATAHANDLER->AddTESObject(Activator);
static Vector3 ZeroVector(0.0, 0.0, 0.0);
TESObjectREFR* Ref = _DATAHANDLER->PlaceObjectRef(Activator,
&ZeroVector,
&ZeroVector,
CS_CAST(ParentCell, TESForm, TESObjectCELL),
nullptr,
nullptr);
SME::MiscGunk::ToggleFlag(&Ref->formFlags, TESForm::kFormFlags_Disabled, InitiallyDisabled);
SME::MiscGunk::ToggleFlag(&Ref->formFlags, TESForm::kFormFlags_QuestItem, true);
Ref->SetEditorID(RefEditorID);
TESDialog::ResetFormListControls();
EndDialog(hWnd, (INT_PTR)Activator);
return TRUE;
}
}
}
}
}
}
return FALSE;
}
case IDC_CSE_CANCEL:
EndDialog(hWnd, 0);
return TRUE;
}
break;
case WM_INITDIALOG:
// show icon in taskbar
auto WindowStyle = GetWindowLongPtr(hWnd, GWL_EXSTYLE);
SetWindowLongPtr(hWnd, GWL_EXSTYLE, WindowStyle | WS_EX_APPWINDOW);
Edit_SetText(EditorIDBox, "Base Form EditorID");
Edit_SetText(RefIDBox, "Ref EditorID");
TESComboBox::PopulateWithForms(ExistFormList, TESForm::kFormType_Activator, true, false);
TESComboBox::PopulateWithForms(ExistFormList, TESForm::kFormType_Apparatus, false, false);
TESComboBox::PopulateWithForms(ExistFormList, TESForm::kFormType_Armor, false, false);
TESComboBox::PopulateWithForms(ExistFormList, TESForm::kFormType_Book, false, false);
TESComboBox::PopulateWithForms(ExistFormList, TESForm::kFormType_Clothing, false, false);
TESComboBox::PopulateWithForms(ExistFormList, TESForm::kFormType_Container, false, false);
TESComboBox::PopulateWithForms(ExistFormList, TESForm::kFormType_Door, false, false);
TESComboBox::PopulateWithForms(ExistFormList, TESForm::kFormType_Ingredient, false, false);
TESComboBox::PopulateWithForms(ExistFormList, TESForm::kFormType_Light, false, false);
TESComboBox::PopulateWithForms(ExistFormList, TESForm::kFormType_Misc, false, false);
TESComboBox::PopulateWithForms(ExistFormList, TESForm::kFormType_Furniture, false, false);
TESComboBox::PopulateWithForms(ExistFormList, TESForm::kFormType_Weapon, false, false);
TESComboBox::PopulateWithForms(ExistFormList, TESForm::kFormType_Ammo, false, false);
TESComboBox::PopulateWithForms(ExistFormList, TESForm::kFormType_NPC, false, false);
TESComboBox::PopulateWithForms(ExistFormList, TESForm::kFormType_Creature, false, false);
TESComboBox::PopulateWithForms(ExistFormList, TESForm::kFormType_SoulGem, false, false);
TESComboBox::PopulateWithForms(ExistFormList, TESForm::kFormType_Key, false, false);
TESComboBox::PopulateWithForms(ExistFormList, TESForm::kFormType_AlchemyItem, false, false);
TESComboBox::PopulateWithForms(ExistFormList, TESForm::kFormType_SigilStone, false, false);
TESComboBox::PopulateWithForms(ExistFormList, TESForm::kFormType_Quest, false, false);
TESComboBox::SetSelectedItemByIndex(ExistFormList, 0);
CheckDlgButton(hWnd, IDC_BINDSCRIPT_BINDEXISTFORM, BST_CHECKED);
CheckDlgButton(hWnd, IDC_BINDSCRIPT_QUESTFORM, BST_CHECKED);
CheckDlgButton(hWnd, IDC_BINDSCRIPT_OBJECTTOKEN, BST_CHECKED);
SetWindowLongPtr(SelParentCellBtn, GWL_USERDATA, (LONG_PTR)0);
break;
}
return FALSE;
}
BOOL CALLBACK EditResultScriptDlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDC_CSE_CANCEL:
EndDialog(hWnd, NULL);
return TRUE;
case IDC_EDITRESULTSCRIPT_COMPILE:
case IDC_EDITRESULTSCRIPT_SAVE:
char Buffer[0x1000] = { 0 };
HWND Parent = (HWND)GetWindowLongPtr(hWnd, GWL_USERDATA);
GetDlgItemText(hWnd, IDC_EDITRESULTSCRIPT_SCRIPTTEXT, Buffer, sizeof(Buffer));
SetDlgItemText(Parent, kDialogEditor_ResultScriptTextBox, (LPSTR)Buffer);
if (LOWORD(wParam) == IDC_EDITRESULTSCRIPT_COMPILE)
EndDialog(hWnd, 1);
else
EndDialog(hWnd, NULL);
return TRUE;
}
break;
case WM_INITDIALOG:
SetWindowLongPtr(hWnd, GWL_USERDATA, (LONG_PTR)lParam);
HWND ResultScriptEditBox = GetDlgItem((HWND)lParam, kDialogEditor_ResultScriptTextBox);
char Buffer[0x1000] = { 0 };
GetWindowText(ResultScriptEditBox, Buffer, sizeof(Buffer));
SetDlgItemText(hWnd, IDC_EDITRESULTSCRIPT_SCRIPTTEXT, (LPSTR)Buffer);
break;
}
return FALSE;
}
}
}