forked from uesp/skyedit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SrFunctionDlg.cpp
326 lines (248 loc) · 8.61 KB
/
SrFunctionDlg.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
/*
* File: SrConditiondlg.CPP
* Author: Dave Humphrey ([email protected])
* Created On: 3 Decemberr 2011
*
* Description
*
*=========================================================================*/
/* Include Files */
#include "stdafx.h"
#include "resource.h"
#include "sredit.h"
#include "SrFunctionDlg.h"
#include "afxdialogex.h"
#include "modfile/srfunctions.h"
/*===========================================================================
*
* Begin Local Definitions
*
*=========================================================================*/
IMPLEMENT_DYNAMIC(CSrFunctionDlg, CDialogEx)
/*===========================================================================
* End of Local Definitions
*=========================================================================*/
/*===========================================================================
*
* Begin Message Map
*
*=========================================================================*/
BEGIN_MESSAGE_MAP(CSrFunctionDlg, CDialogEx)
ON_COMMAND(ID_HELP, &CSrFunctionDlg::OnHelp)
ON_NOTIFY(LVN_ITEMCHANGING, IDC_FUNCTION_LIST, &CSrFunctionDlg::OnLvnItemchangingFunctionList)
ON_NOTIFY(NM_DBLCLK, IDC_FUNCTION_LIST, OnDblclk)
ON_EN_CHANGE(IDC_FILTER_TEXT, &CSrFunctionDlg::OnEnChangeFilterText)
ON_BN_CLICKED(ID_CLEAR_FILTER, &CSrFunctionDlg::OnBnClickedClearFilter)
ON_WM_HELPINFO()
END_MESSAGE_MAP()
/*===========================================================================
* End of Message Map
*=========================================================================*/
int CALLBACK l_fnSortFunctionList(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
{
srfunction_t* pFunc1 = (srfunction_t *) lParam1;
srfunction_t* pFunc2 = (srfunction_t *) lParam2;
if (pFunc1 == NULL || pFunc2 == NULL) return 0;
switch (lParamSort)
{
case SR_FUNCDLG_SORTNAME:
return stricmp(pFunc1->Name, pFunc2->Name);
break;
}
return 0;
}
CSrFunctionDlg::CSrFunctionDlg(CWnd* pParent)
: CDialogEx(CSrFunctionDlg::IDD, pParent)
{
m_FunctionMask = 0;
}
CSrFunctionDlg::~CSrFunctionDlg()
{
}
void CSrFunctionDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Control(pDX, IDC_PREVIOUS_TEXT, m_PreviousValue);
DDX_Control(pDX, IDC_CURRENT_TEXT, m_CurrentValue);
DDX_Control(pDX, IDC_FUNCTION_LIST, m_FunctionList);
DDX_Control(pDX, IDC_FILTER_TEXT, m_Filter);
}
void CSrFunctionDlg::FillFunctionList (void)
{
CString Buffer;
int Index;
int SelIndex = -1;
m_FunctionList.SetRedraw(FALSE);
m_FunctionList.DeleteAllItems();
for (dword i = 0; i < g_SrFunctionCount; ++i)
{
srfunction_t* pFunc = &g_SrFunctions[i];
if ((pFunc->Flags & m_FunctionMask) != m_FunctionMask) continue;
if (CheckFlagBits(pFunc->Flags, SR_FUNCTION_FLAG_IGNORE)) continue;
if (!m_FilterString.IsEmpty())
{
if (stristr(pFunc->Name, m_FilterString) == NULL) continue;
}
Index = m_FunctionList.InsertItem(i, pFunc->Name);
if (Index >= 0)
{
Buffer = "";
if (CheckFlagBits(pFunc->Flags, SR_FUNCTION_FLAG_BLOCK)) Buffer = "Block";
else if (CheckFlagBits(pFunc->Flags, SR_FUNCTION_FLAG_CONSOLE)) Buffer = "Console";
else if (CheckFlagBits(pFunc->Flags, SR_FUNCTION_FLAG_SCRIPT)) Buffer = "Script";
m_FunctionList.SetItemText(Index, SR_FUNCDLG_SUBITEM_TYPE, Buffer);
m_FunctionList.SetItemData(Index, (DWORD) pFunc);
if (pFunc->NumParams >= 1)
{
m_FunctionList.SetItemText(Index, SR_FUNCDLG_SUBITEM_PARAM1, GetSrFunctionParamTypeString(pFunc->Params[0].Type));
}
if (pFunc->NumParams >= 2)
{
m_FunctionList.SetItemText(Index, SR_FUNCDLG_SUBITEM_PARAM2, GetSrFunctionParamTypeString(pFunc->Params[1].Type));
}
if (pFunc->NumParams >= 3)
{
m_FunctionList.SetItemText(Index, SR_FUNCDLG_SUBITEM_PARAM3, GetSrFunctionParamTypeString(pFunc->Params[2].Type));
}
}
}
m_FunctionList.SortItems(l_fnSortFunctionList, SR_FUNCDLG_SORTNAME);
m_FunctionList.SetRedraw(TRUE);
LVFINDINFO FindInfo;
FindInfo.flags = LVFI_STRING;
FindInfo.psz = m_OrigFunction;
SelIndex = m_FunctionList.FindItem(&FindInfo);
if (SelIndex < 0) SelIndex = 0;
m_FunctionList.SetItemState(SelIndex, LVIS_SELECTED, LVIS_SELECTED);
m_FunctionList.EnsureVisible(SelIndex, FALSE);
}
void CSrFunctionDlg::SetupFunctionList (void)
{
m_FunctionList.InsertColumn(SR_FUNCDLG_SUBITEM_NAME, "Function", LVCFMT_CENTER, 180, SR_FUNCDLG_SUBITEM_NAME);
m_FunctionList.InsertColumn(SR_FUNCDLG_SUBITEM_PARAM1, "Param1", LVCFMT_CENTER, 100, SR_FUNCDLG_SUBITEM_PARAM1);
m_FunctionList.InsertColumn(SR_FUNCDLG_SUBITEM_PARAM2, "Param2", LVCFMT_CENTER, 100, SR_FUNCDLG_SUBITEM_PARAM2);
m_FunctionList.InsertColumn(SR_FUNCDLG_SUBITEM_PARAM3, "Param3", LVCFMT_CENTER, 100, SR_FUNCDLG_SUBITEM_PARAM3);
m_FunctionList.InsertColumn(SR_FUNCDLG_SUBITEM_TYPE, "Type", LVCFMT_CENTER, 60, SR_FUNCDLG_SUBITEM_TYPE);
}
BOOL CSrFunctionDlg::OnInitDialog()
{
LVFINDINFO FindInfo;
CDialogEx::OnInitDialog();
m_FunctionList.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES );
SetupFunctionList();
FillFunctionList();
m_CurrentFunction = m_OrigFunction;
m_PreviousValue.SetWindowText(m_OrigFunction);
m_CurrentValue.SetWindowText(m_OrigFunction);
FindInfo.flags = LVFI_STRING;
FindInfo.psz = m_OrigFunction;
int Index = m_FunctionList.FindItem(&FindInfo);
if (Index >= 0) m_FunctionList.SetItemState(Index, LVIS_SELECTED, LVIF_STATE);
m_Filter.SetFocus();
return FALSE;
}
void CSrFunctionDlg::OnOK()
{
CWnd* pWnd = GetFocus();
if (pWnd == &m_Filter)
{
CString Buffer;
m_Filter.GetWindowText(Buffer);
Buffer.Trim(" \n\t\r");
srfunction_t* pFunc = GetSrFunction(Buffer);
if (pFunc == NULL)
{
if (m_FunctionList.GetItemCount() > 1) return;
if (m_FunctionList.GetItemCount() < 1) return;
m_CurrentFunction = m_FunctionList.GetItemText(0, SR_FUNCDLG_SUBITEM_NAME);
}
else
{
m_CurrentFunction = Buffer;
}
}
else if (pWnd == &m_CurrentValue)
{
m_CurrentValue.GetWindowText(m_CurrentFunction);
m_CurrentFunction.Trim(" \n\t\r");
srfunction_t* pFunc = GetSrFunction(m_CurrentFunction);
if (pFunc == NULL)
{
if (m_FunctionList.GetItemCount() > 1) return;
if (m_FunctionList.GetItemCount() < 1) return;
m_CurrentFunction = m_FunctionList.GetItemText(0, SR_FUNCDLG_SUBITEM_NAME);
}
}
CDialogEx::OnOK();
}
bool CSrFunctionDlg::DoModal (CString& Function, const dword Mask)
{
m_OrigFunction = Function;
m_FunctionMask = Mask;
int Result = CDialogEx::DoModal();
if (Result != IDOK) return false;
Function = m_CurrentFunction;
return true;
}
void CSrFunctionDlg::OnLvnItemchangingFunctionList(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
*pResult = 0;
if ((pNMLV->uNewState & LVIS_SELECTED) == 0) return;
srfunction_t* pFunc = (srfunction_t *) m_FunctionList.GetItemData(pNMLV->iItem);
if (pFunc == NULL) return;
m_CurrentFunction = pFunc->Name;
m_CurrentValue.SetWindowText(pFunc->Name);
}
/*===========================================================================
*
* Class CSrFunctionDlg Event - void OnDblclk (pNMHDR, pResult);
*
*=========================================================================*/
void CSrFunctionDlg::OnDblclk (NMHDR* pNMHDR, LRESULT* pResult)
{
*pResult = 0;
OnOK();
EndModalLoop(IDOK);
}
/*===========================================================================
* End of Class Event CSrFunctionDlg::OnDblclk()
*=========================================================================*/
void CSrFunctionDlg::OnEnChangeFilterText()
{
m_Filter.GetWindowText(m_FilterString);
FillFunctionList();
}
void CSrFunctionDlg::OnBnClickedClearFilter()
{
m_Filter.SetWindowText("");
m_FilterString.Empty();
FillFunctionList();
}
bool SrSelectFunctionScript (CString& Function)
{
CSrFunctionDlg FuncDlg;
return FuncDlg.DoModal(Function, SR_FUNCTION_FLAG_SCRIPT);
}
bool SrSelectFunctionCondition (CString& Function)
{
CSrFunctionDlg FuncDlg;
return FuncDlg.DoModal(Function, SR_FUNCTION_FLAG_SCRIPT | SR_FUNCTION_FLAG_CONDITION);
}
/*===========================================================================
*
* Class CSrFunctionDlg Event - void OnHelp (void);
*
*=========================================================================*/
void CSrFunctionDlg::OnHelp (void)
{
GetSrEditApp().OpenWebHelp("Tes5Mod:SkyEdit/User_Interface/Functions", "Functions");
}
/*===========================================================================
* End of Class Event CSrFunctionDlg::OnHelp()
*=========================================================================*/
BOOL CSrFunctionDlg::OnHelpInfo(HELPINFO* pHelpInfo)
{
GetSrEditApp().OpenWebHelp("Tes5Mod:SkyEdit/User_Interface/Functions", "Functions");
return true;
}