27[
WorkbenchPluginAttribute(name:
"Autocomplete", description:
"Helps autocompleting keywords, adding [Attribute()] decorators, cast nullchecks etc.", shortcut:
"Ctrl+Return" , wbModules: {
"ScriptEditor" }, awesomeFontCode: 0xE2CA)]
28class SCR_AutocompletePlugin : WorkbenchPlugin
34 [
Attribute(defvalue:
"1",
desc:
"Add class constructor on \"" + CONSTRUCTOR_KEYWORD +
"\" keyword",
category:
"General")]
35 protected bool m_bAddConstructor;
37 [
Attribute(defvalue:
"1",
desc:
"Add class destructor on \"" + DESTRUCTOR_KEYWORD +
"\" keyword",
category:
"General")]
38 protected bool m_bAddDestructor;
40 [
Attribute(defvalue:
"1",
desc:
"Autocomplete \" = new\" statements, e.g:"
41 +
"\n- array<int> myArray = new → array<int> myArray = {};"
42 +
"\n- array<ref SCR_MyClass> myArray = new → array<ref SCR_MyClass> myArray = {};"
43 +
"\n- map<int, ref SCR_MySuperClass> myMap = new → map<int, ref SCR_MySuperClass> myMap = new map<int, ref SCR_MySuperClass>();"
44 +
"\n- bool m_bMyVar = new → bool m_bMyVar;",
category:
"General")]
45 protected bool m_bAddInstantiation;
48 protected int m_iInstantiationTrigger;
51 +
"\n- SCR_MyClass instance = new SCR_MyClass; → SCR_MyClass instance = new SCR_MyClass();"
52 +
"\n- array<string> instance = new array<string>(); → array<string> instance = {};",
category:
"General")]
53 protected bool m_bFixInstantiation;
55 [
Attribute(defvalue:
"1",
desc:
"Add a nullcheck below a \"Class a = Class.Cast(b)\" statement if not present",
category:
"General")]
56 protected bool m_bAddCastNullcheck;
58 [
Attribute(defvalue:
"1",
desc:
"Add (or fix) a validity check below a \"Resource.Load\" statement if not present",
category:
"General")]
59 protected bool m_bAddOrFixResourceLoadValidityCheck;
61 [
Attribute(defvalue:
LogLevel.NORMAL.ToString(),
desc:
"Add a LogLevel to a Print or PrintFormat if not present", enums: {
62 new ParamEnum(
"Disabled",
"-1",
"Do not add log level to Print/PrintFormat missing it"),
63 new ParamEnum(
"LogLevel.NORMAL", LogLevel.NORMAL.ToString()),
64 new ParamEnum(
"LogLevel.WARNING", LogLevel.WARNING.ToString()),
65 new ParamEnum(
"LogLevel.ERROR", LogLevel.ERROR.ToString()),
66 new ParamEnum(
"LogLevel.FATAL", LogLevel.FATAL.ToString()),
68 protected LogLevel m_eAddPrintLogLevel;
71 protected bool m_bKeepCommentIndentation =
true;
78 protected bool m_bUseToolKeywords;
80 [
Attribute(
desc:
"Tool-defined keyword-replacement pairs - editable and resettable",
category:
"Keywords")]
81 protected ref array<ref SCR_AutocompletePlugin_KeywordData> m_aToolKeywords;
83 [
Attribute(defvalue:
"1",
desc:
"Use the user-defined keyword list below - this list will never be touched or reset in any way by the tool",
category:
"Keywords")]
84 protected bool m_bUseUserKeywords;
87 protected ref array<ref SCR_AutocompletePlugin_KeywordData> m_aUserKeywords;
94 protected bool m_bUseToolAttributeDecorators;
96 [
Attribute(
desc:
"Tool-defined [Attribute()] decorators - editable and resettable",
category:
"Attribute Decorators")]
97 protected ref array<ref SCR_AutocompletePlugin_AttributeData> m_aToolAttributeDecorators;
99 [
Attribute(defvalue:
"1",
desc:
"Use the user-defined [Attribute()] decorator list below - this list will never be touched or reset in any way by the tool",
category:
"Attribute Decorators")]
100 protected bool m_bUseUserAttributeDecorators;
103 protected ref array<ref SCR_AutocompletePlugin_AttributeData> m_aUserAttributeDecorators;
108 protected static const string SEP_NL =
SCR_StringHelper.DOUBLE_SLASH +
"------------------------------------------------------------------------------------------------\n";
109 protected static const string CONSTRUCTOR_KEYWORD =
"ctor";
110 protected static const string DESTRUCTOR_KEYWORD =
"dtor";
111 protected static const string ENTITY_SUFFIX =
"Entity";
113 protected static const ref array<string> NATIVE_TYPES = {
114 "bool",
"float",
"int",
"string",
"typename",
"vector",
115 "FactionKey",
"LocalizedString",
"ResourceName",
121 AutoCompleteCurrentLine();
125 protected void AutoCompleteCurrentLine()
127 ScriptEditor scriptEditor = Workbench.GetModule(ScriptEditor);
130 PrintFormat(
"[SCR_AutocompletePlugin.AutoCompleteCurrentLine] Script Editor is unavailable?! (%1 L%2)", __FILE__, __LINE__, level:
LogLevel.ERROR);
135 if (!scriptEditor.GetCurrentFile(currentLine))
144 if (!scriptEditor.GetLineText(currentLine))
146 PrintFormat(
"[SCR_AutocompletePlugin.AutoCompleteCurrentLine] Script Editor cannot read the current line (%1 L%2)", __FILE__, __LINE__, level:
LogLevel.ERROR);
151 SCR_BasicCodeFormatterPlugin.GetIndentAndLineContent(currentLine, indentation, currentLine);
154 if (commentIndex == 0)
157 string indentedComment;
158 if (commentIndex > 0)
160 if (m_bKeepCommentIndentation)
162 string codeAndCommentLine = currentLine;
163 currentLine = currentLine.Substring(0, commentIndex);
164 currentLine.TrimInPlace();
165 indentedComment = codeAndCommentLine.Substring(currentLine.Length(), codeAndCommentLine.Length() - currentLine.Length());
170 indentedComment = currentLine.Substring(commentIndex, currentLine.Length() - commentIndex);
171 indentedComment.TrimInPlace();
173 currentLine = currentLine.Substring(0, commentIndex);
177 currentLine.TrimInPlace();
181 if (m_bAddInstantiation)
183 if (((m_iInstantiationTrigger == 0 || m_iInstantiationTrigger == 2) && currentLine.EndsWith(
" ="))
184 || ((m_iInstantiationTrigger == 0 || m_iInstantiationTrigger == 1) && currentLine.EndsWith(
" = new")))
186 if (AddNewType(scriptEditor, indentation, currentLine, indentedComment))
191 if (m_bFixInstantiation)
193 if (FixInstantiation(scriptEditor, indentation, currentLine, indentedComment))
197 if (m_bAddCastNullcheck && currentLine.Contains(
".Cast("))
199 if (AddCastCheck(scriptEditor, indentation, currentLine))
203 if (m_bAddOrFixResourceLoadValidityCheck && currentLine.Contains(
"Resource.Load("))
205 if (AddResourceLoadValidityCheck(scriptEditor, indentation, currentLine))
209 if (m_eAddPrintLogLevel > -1
210 && (currentLine.StartsWith(
"Print(") || currentLine.StartsWith(
"PrintFormat("))
211 && currentLine.EndsWith(
");"))
213 if (AddPrintLogLevel(scriptEditor, indentation, currentLine, indentedComment))
217 string lineLC = currentLine;
220 if (m_bAddConstructor && lineLC == CONSTRUCTOR_KEYWORD)
222 if (AddConstructorDestructor(scriptEditor,
true, indentation, indentedComment))
226 if (m_bAddDestructor && lineLC == DESTRUCTOR_KEYWORD)
228 if (AddConstructorDestructor(scriptEditor,
false, indentation, indentedComment))
235 && currentLine.EndsWith(
";")
236 && !currentLine.Contains(
"="))
238 CheckToolAttributeDecorators();
239 FillAttributeDecoratorMap();
240 if (AddAttributeDecorator(scriptEditor, indentation, currentLine))
249 SCR_AutocompletePlugin_KeywordData
data = m_mKeywords.Get(currentLine);
251 scriptEditor.SetLineText(AddIndentation(
string.Format(
data.m_sValue, indentedComment), indentation));
261 protected bool AddNewType(notnull ScriptEditor scriptEditor,
string indentation,
string currentLine,
string comment)
266 array<string> tokens = {};
269 int tokensCount = tokens.Count();
270 if (m_iInstantiationTrigger == 1)
282 if (tokens.Count() < 2)
285 tokens.RemoveItemOrdered(
"auto");
286 tokens.RemoveItemOrdered(
"autoptr");
287 tokens.RemoveItemOrdered(
"protected");
288 tokens.RemoveItemOrdered(
"private");
289 tokens.RemoveItemOrdered(
"static");
290 if (tokens.IsEmpty())
293 if (tokens[0] ==
"ref")
295 tokens.RemoveOrdered(0);
297 if (indentation !=
SCR_StringHelper.TAB && currentLine.StartsWith(
"ref ") && currentLine !=
"ref ")
299 currentLine = currentLine.Substring(4, currentLine.Length() - 4);
300 currentLine.TrimInPlace();
304 tokensCount = tokens.Count();
309 if (tokensCount == 2)
311 newVarType = tokens[0];
315 tokens.Remove(tokensCount - 1);
319 currentLine.Replace(
" = new",
" =");
321 if (NATIVE_TYPES.Contains(newVarType))
323 currentLine.Replace(
" =",
string.Empty);
324 currentLine.TrimInPlace();
327 scriptEditor.SetLineText(
string.Format(
"%1%2%3", indentation, currentLine, comment));
331 if (newVarType.StartsWith(
"array<"))
332 currentLine +=
" {};";
334 currentLine +=
" new " + newVarType +
"();";
336 scriptEditor.SetLineText(
string.Format(
"%1%2%3", indentation, currentLine, comment));
346 protected bool FixInstantiation(notnull ScriptEditor scriptEditor,
string indentation,
string currentLine,
string comment)
348 if (!currentLine.Contains(
" = new "))
351 array<string> tokens = {};
354 int tokensCount = tokens.Count();
355 if (m_iInstantiationTrigger == 1)
367 if (tokens.Count() < 2)
370 array<string> keywords;
374 tokens.RemoveItemOrdered(
"auto");
375 tokens.RemoveItemOrdered(
"autoptr");
378 if (tokens.RemoveItemOrdered(
"protected"))
379 keywords.Insert(
"protected");
381 if (tokens.RemoveItemOrdered(
"private"))
382 keywords.Insert(
"private");
385 if (!tokens.IsEmpty() && tokens[0] ==
"ref")
387 tokens.RemoveOrdered(0);
389 keywords.Insert(
"ref");
392 tokensCount = tokens.Count();
396 string varType, varName;
397 if (tokensCount == 2)
404 varName = tokens[tokensCount - 1];
405 tokens.Remove(tokensCount - 1);
410 if (NATIVE_TYPES.Contains(varType))
412 newLine =
string.Format(
"%1 %2;", varType, varName);
414 keywords.RemoveItemOrdered(
"ref");
418 if (varType.StartsWith(
"array<"))
419 newLine =
string.Format(
"%1 %2 = {};", varType, varName);
421 newLine =
string.Format(
"%1 %2 = new %1();", varType, varName);
424 if (keywords && !keywords.IsEmpty())
427 if (currentLine == newLine)
430 scriptEditor.SetLineText(
string.Format(
"%1%2%3", indentation, newLine, comment));
439 protected bool AddCastCheck(notnull ScriptEditor scriptEditor,
string indentation,
string currentLine)
441 array<string> tokens = {};
444 int tokensCount = tokens.Count();
449 if (tokensCount == 3)
454 if (tokens[varIndex + 1] !=
"=")
457 string varName = tokens[varIndex];
460 int currentLineNumber = scriptEditor.GetCurrentLine();
461 if (!scriptEditor.GetLineText(belowLine, currentLineNumber + 1))
464 belowLine.TrimInPlace();
465 if (belowLine.StartsWith(
"if (!" + varName +
")"))
468 string insert =
"if (!" + varName +
")\n\treturn;";
472 scriptEditor.InsertLine(AddIndentation(insert, indentation), scriptEditor.GetCurrentLine() + 1);
481 protected bool AddResourceLoadValidityCheck(notnull ScriptEditor scriptEditor,
string indentation,
string currentLine)
483 array<string> tokens = {};
486 if (tokens[0] ==
"Resource")
487 tokens.RemoveOrdered(0);
489 if (tokens.Count() < 3)
492 if (tokens[1] !=
"=")
496 int nextLineNumber = scriptEditor.GetCurrentLine() + 1;
497 if (!scriptEditor.GetLineText(belowLine, nextLineNumber))
500 string varName = tokens[0];
501 belowLine.TrimInPlace();
502 if (belowLine.StartsWith(
"if (!" + varName +
".IsValid())"))
505 string nullCheck =
"if (!" + varName +
")";
506 if (belowLine.StartsWith(nullCheck))
508 if (belowLine == nullCheck)
510 scriptEditor.SetLineText(indentation +
"if (!" + varName +
".IsValid())", nextLineNumber)
514 string restOfTheLine = belowLine.Substring(nullCheck.Length(), belowLine.Length() - nullCheck.Length());
515 scriptEditor.SetLineText(indentation +
"if (!" + varName +
".IsValid())" + restOfTheLine, nextLineNumber);
521 string insert =
"if (!" + varName +
".IsValid())\n\treturn;";
525 scriptEditor.InsertLine(AddIndentation(insert, indentation), nextLineNumber);
536 protected bool AddPrintLogLevel(notnull ScriptEditor scriptEditor,
string indentation,
string currentLine,
string comment)
538 if (currentLine.StartsWith(
"Print("))
540 if (currentLine.Contains(
"LogLevel.") || currentLine.EndsWith(
", level);") || currentLine.EndsWith(
", logLevel);"))
543 scriptEditor.SetLineText(
544 string.Format(
"%1%2, LogLevel.%3);%4",
546 currentLine.Substring(0, currentLine.Length() - 2),
547 typename.EnumToString(
LogLevel, m_eAddPrintLogLevel),
553 if (currentLine.StartsWith(
"PrintFormat("))
555 if (currentLine.Contains(
"level: "))
558 if (currentLine.Contains(
"LogLevel."))
559 scriptEditor.SetLineText(indentation +
SCR_StringHelper.
InsertAt(currentLine,
"level: ", currentLine.LastIndexOf(
"LogLevel.")) + comment);
561 scriptEditor.SetLineText(
562 string.Format(
"%1%2, level: LogLevel.%3);%4",
564 currentLine.Substring(0, currentLine.Length() - 2),
565 typename.EnumToString(
LogLevel, m_eAddPrintLogLevel),
579 protected bool AddAttributeDecorator(notnull ScriptEditor scriptEditor,
string indentation,
string currentLine)
581 int currentLineNumber = scriptEditor.GetCurrentLine();
582 if (currentLineNumber > 0)
585 if (!scriptEditor.GetLineText(aboveLine, currentLineNumber - 1) || aboveLine.StartsWith(
"\t[Attribute("))
589 array<string> tokens = {};
592 tokens.RemoveItemOrdered(
"protected");
593 tokens.RemoveItemOrdered(
"private");
594 tokens.RemoveItemOrdered(
"ref");
596 int count = tokens.Count();
602 if (tokens[0] ==
"array<ref")
605 tokens.RemoveOrdered(1);
610 if (count > 2 && tokens[2] !=
"=")
613 string name = tokens[1];
614 if (!name.StartsWith(
"m_"))
617 int nameLength = name.Length();
621 string hungarianPrefix = name[2];
623 hungarianPrefix =
string.Empty;
625 string typeStr = tokens[0];
628 SCR_AutocompletePlugin_AttributeData
data = m_mAttributeDecorators.Get(typeStr);
629 if (
data && hungarianPrefix ==
data.m_sPrefix)
631 scriptEditor.InsertLine(indentation +
string.Format(
data.m_sValue, friendlyName, typeStr));
637 typename type = typeStr.ToType();
644 if (typeStr.StartsWith(
"array<") || (
type &&
type.IsInherited(array)))
646 if (hungarianPrefix ==
"a")
648 data = m_mAttributeDecorators.Get(
"array");
650 scriptEditor.InsertLine(indentation +
string.Format(
data.m_sValue, friendlyName, typeStr));
652 scriptEditor.InsertLine(indentation +
string.Format(
"[Attribute(desc: \"%1\")]", friendlyName, typeStr));
659 if (hungarianPrefix ==
"e")
661 int length = typeStr.Length();
662 bool isEnum = length > 2 && typeStr[0] ==
"E" &&
SCR_StringHelper.UPPERCASE.Contains(typeStr[1]);
665 int index = typeStr.IndexOf(
"_E");
672 data = m_mAttributeDecorators.Get(
"enum");
674 scriptEditor.InsertLine(indentation +
string.Format(
data.m_sValue, friendlyName, typeStr));
676 scriptEditor.InsertLine(indentation +
string.Format(
"[Attribute(desc: \"%1\", uiwidget: UIWidgets.CheckBox, enumType: %2)]", friendlyName, typeStr));
683 if (
type &&
type.IsInherited(Managed))
685 scriptEditor.InsertLine(indentation +
string.Format(
"[Attribute(desc: \"%1\")]", friendlyName, typeStr));
697 protected string AddIndentation(
string input,
string indentation)
699 array<string> lines = {};
705 foreach (
int i,
string line : lines)
708 lines[i] = indentation + line;
720 protected bool AddConstructorDestructor(notnull ScriptEditor scriptEditor,
bool isConstructor,
string indentation,
string comment)
724 if (!SCR_CopyClassAndMethodPlugin.GetCursorClassAndMethodNames(scriptEditor, className, methodName))
730 className =
"DefaultClassName";
736 if (className.EndsWith(ENTITY_SUFFIX))
737 text =
string.Format(SEP_NL +
SCR_StringHelper.DOUBLE_SLASH +
" constructor\nvoid %1(IEntitySource src, IEntity parent)%2\n{\n\t\n}", className, comment);
739 text =
string.Format(SEP_NL +
SCR_StringHelper.DOUBLE_SLASH +
" constructor\nvoid %1()%2\n{\n\t\n}", className, comment);
743 text =
string.Format(SEP_NL +
SCR_StringHelper.DOUBLE_SLASH +
" destructor\nvoid ~%1()%2\n{\n\t\n}", className, comment);
746 scriptEditor.SetLineText(AddIndentation(text, indentation));
751 protected void CheckToolKeywords()
753 set<string> keywords =
new set<string>();
754 SCR_AutocompletePlugin_KeywordData tmpData;
755 for (
int i = m_aToolKeywords.Count() - 1; i >= 0; i--)
757 tmpData = m_aToolKeywords[i];
759 m_aToolKeywords.RemoveOrdered(i);
761 keywords.Insert(tmpData.m_sKeyword);
765 if (!keywords.Contains(
"if")) m_aToolKeywords.Insert(SCR_AutocompletePlugin_KeywordData.Create(
"if",
"if (condition)%1\n{\n\t\n}"));
766 if (!keywords.Contains(
"ife")) m_aToolKeywords.Insert(SCR_AutocompletePlugin_KeywordData.Create(
"ife",
"if (condition)%1\n{\n\t\n}\nelse\n{\n\t\n}"));
767 if (!keywords.Contains(
"for")) m_aToolKeywords.Insert(SCR_AutocompletePlugin_KeywordData.Create(
"for",
"for (int i, count = arr.Count(); i < count; i++)%1\n{\n\t\n}"));
768 if (!keywords.Contains(
"forr")) m_aToolKeywords.Insert(SCR_AutocompletePlugin_KeywordData.Create(
"forr",
"for (int i = arr.Count() - 1; i >= 0; i--)%1\n{\n\t\n}"));
769 if (!keywords.Contains(
"foreach")) m_aToolKeywords.Insert(SCR_AutocompletePlugin_KeywordData.Create(
"foreach",
"foreach (string item : items)%1\n{\n\t\n}"));
770 if (!keywords.Contains(
"foreachi")) m_aToolKeywords.Insert(SCR_AutocompletePlugin_KeywordData.Create(
"foreachi",
"foreach (int i, SCR_Class item : items)%1\n{\n\t\n}"));
771 if (!keywords.Contains(
"switch")) m_aToolKeywords.Insert(SCR_AutocompletePlugin_KeywordData.Create(
"switch",
"switch (value)%1\n{\n\tcase 0:\n\t\tbreak;\n\n\tdefault:\n\t\tbreak;\n}"));
772 if (!keywords.Contains(
"while")) m_aToolKeywords.Insert(SCR_AutocompletePlugin_KeywordData.Create(
"while",
"while (condition)%1\n{\n\t\n}"));
775 if (!keywords.Contains(
"class")) m_aToolKeywords.Insert(SCR_AutocompletePlugin_KeywordData.Create(
"class",
"class SCR_MyClass%1\n{\n\tprotected string m_sValue = \"Generated class\";\n\n\t" + SEP_NL +
"\t/" +
"/! constructor\n\tvoid SCR_MyClass()\n\t{\n\t\t\n\t}\n}"));
776 if (!keywords.Contains(
"func")) m_aToolKeywords.Insert(SCR_AutocompletePlugin_KeywordData.Create(
"func", SEP_NL +
SCR_StringHelper.DOUBLE_SLASH +
"! \\param[in] parameter\n" +
"protected void Method(int parameter)%1\n{\n\t\n}"));
777 if (!keywords.Contains(
"method")) m_aToolKeywords.Insert(SCR_AutocompletePlugin_KeywordData.Create(
"method", SEP_NL +
SCR_StringHelper.DOUBLE_SLASH +
"! \\param[in] parameter\n" +
"protected void Method(int parameter)%1\n{\n\t\n}"));
784 if (!keywords.Contains(
"findcomp")) m_aToolKeywords.Insert(SCR_AutocompletePlugin_KeywordData.Create(
"findcomp",
"SCR_ComponentClass component = SCR_ComponentClass.Cast(entity.FindComponent(SCR_ComponentClass));%1\nif (!comp)\n\treturn;"));
785 if (!keywords.Contains(
"print")) m_aToolKeywords.Insert(SCR_AutocompletePlugin_KeywordData.Create(
"print",
"Print(\"fill\", LogLevel.NORMAL);"));
789 protected void FillKeywordsMap()
793 if (m_bUseToolKeywords)
795 foreach (SCR_AutocompletePlugin_KeywordData
data : m_aToolKeywords)
798 if (
data.m_bEnabled && !m_mKeywords.Contains(
data.m_sKeyword))
799 m_mKeywords.Insert(
data.m_sKeyword,
data);
803 if (m_bUseUserKeywords)
805 foreach (SCR_AutocompletePlugin_KeywordData
data : m_aUserKeywords)
808 if (
data.m_bEnabled && !m_mKeywords.Contains(
data.m_sKeyword))
809 m_mKeywords.Insert(
data.m_sKeyword,
data);
815 protected void CheckToolAttributeDecorators()
817 set<string> attributeDecorators =
new set<string>();
818 SCR_AutocompletePlugin_AttributeData tmpData;
819 for (
int i = m_aToolAttributeDecorators.Count() - 1; i >= 0; i--)
821 tmpData = m_aToolAttributeDecorators[i];
823 m_aToolAttributeDecorators.RemoveOrdered(i);
825 attributeDecorators.Insert(tmpData.m_sType);
828 if (!attributeDecorators.Contains(
"array")) m_aToolAttributeDecorators.Insert(SCR_AutocompletePlugin_AttributeData.Create(
"array",
"a",
"[Attribute(defvalue: \"" +
"\", desc: \"%1\")]"));
829 if (!attributeDecorators.Contains(
"bool")) m_aToolAttributeDecorators.Insert(SCR_AutocompletePlugin_AttributeData.Create(
"bool",
"b",
"[Attribute(defvalue: \"1\", desc: \"%1\")]"));
830 if (!attributeDecorators.Contains(
"Color")) m_aToolAttributeDecorators.Insert(SCR_AutocompletePlugin_AttributeData.Create(
"Color",
"",
"[Attribute(defvalue: \"1 1 1 1\", desc: \"%1\")]"));
831 if (!attributeDecorators.Contains(
"enum")) m_aToolAttributeDecorators.Insert(SCR_AutocompletePlugin_AttributeData.Create(
"enum",
"e",
"[Attribute(defvalue: \"0\", desc: \"%1\", uiwidget: UIWidgets.ComboBox, enumType: %2)]"));
832 if (!attributeDecorators.Contains(
"float")) m_aToolAttributeDecorators.Insert(SCR_AutocompletePlugin_AttributeData.Create(
"float",
"f",
"[Attribute(defvalue: \"0\", desc: \"%1\", params: \"0 inf 0.01\")]"));
833 if (!attributeDecorators.Contains(
"int")) m_aToolAttributeDecorators.Insert(SCR_AutocompletePlugin_AttributeData.Create(
"int",
"i",
"[Attribute(defvalue: \"0\", desc: \"%1\", params: \"0 inf\")]"));
834 if (!attributeDecorators.Contains(
"LocalizedString")) m_aToolAttributeDecorators.Insert(SCR_AutocompletePlugin_AttributeData.Create(
"string",
"s",
"[Attribute(defvalue: \"#AR-Something\", desc: \"%1\")]"));
835 if (!attributeDecorators.Contains(
"ResourceName")) m_aToolAttributeDecorators.Insert(SCR_AutocompletePlugin_AttributeData.Create(
"ResourceName",
"s",
"[Attribute(defvalue: \"" +
"\", desc: \"%1\", uiwidget: UIWidgets.ResourcePickerThumbnail, params: \"edds et wav\")]"));
836 if (!attributeDecorators.Contains(
"string")) m_aToolAttributeDecorators.Insert(SCR_AutocompletePlugin_AttributeData.Create(
"string",
"s",
"[Attribute(defvalue: \"Default value\", desc: \"%1\")]"));
837 if (!attributeDecorators.Contains(
"vector")) m_aToolAttributeDecorators.Insert(SCR_AutocompletePlugin_AttributeData.Create(
"vector",
"v",
"[Attribute(defvalue: \"0 0 0\", desc: \"%1\")]"));
841 protected void FillAttributeDecoratorMap()
843 m_mAttributeDecorators.Clear();
845 if (m_bUseToolAttributeDecorators)
847 foreach (SCR_AutocompletePlugin_AttributeData
data : m_aToolAttributeDecorators)
849 if (
data.m_bEnabled && !m_mAttributeDecorators.Contains(
data.m_sType))
850 m_mAttributeDecorators.Insert(
data.m_sType,
data);
854 if (m_bUseUserAttributeDecorators)
856 foreach (SCR_AutocompletePlugin_AttributeData
data : m_aUserAttributeDecorators)
858 if (
data.m_bEnabled && !m_mAttributeDecorators.Contains(
data.m_sType))
859 m_mAttributeDecorators.Insert(
data.m_sType,
data);
868 CheckToolAttributeDecorators();
869 Workbench.ScriptDialog(
"Autocomplete Plugin",
"Autocompletion settings",
this);
874 protected int ButtonClose()
881class SCR_AutocompletePlugin_KeywordData
883 [
Attribute(defvalue:
"1",
desc:
"Enable this keyword-text pair")]
886 [
Attribute(defvalue:
"keyword",
desc:
"Keyword to be detected - case-sensitive")]
889 [
Attribute(defvalue:
"protected string m_sKeyword = \"keyword\";",
desc:
"Text replacing the detected keyword\n- \\n for line return\n- \\t for tabulation\n- %1 for the in-line comment that was after the keyword (if any)", uiwidget: UIWidgets.EditBoxMultiline)]
898 static SCR_AutocompletePlugin_KeywordData Create(
string keyword,
string value,
bool enabled =
true)
900 SCR_AutocompletePlugin_KeywordData result =
new SCR_AutocompletePlugin_KeywordData();
902 result.m_bEnabled = enabled;
903 result.m_sKeyword = keyword;
904 result.m_sValue = value;
911class SCR_AutocompletePlugin_AttributeData
913 [
Attribute(defvalue:
"1",
desc:
"Enable this attribute decorator")]
916 [
Attribute(defvalue:
"array<ref SCR_Bird>",
desc:
"Classname or native type")]
919 [
Attribute(defvalue:
"a",
desc:
"The 'x' in the m_xName prefix (e.g i for int, b for bool etc)\nCan be empty",
precision: 1)]
922 [
Attribute(defvalue:
"[Attribute(defvalue: \"0\", desc: \"%1\")]",
desc:
"Value\n%1 = friendly variable name (e.g 'm_bCheckThis' → 'Check This')\n%2 = value type (e.g 'array<ref SCR_MyClass>')")]
931 static SCR_AutocompletePlugin_AttributeData Create(
string type,
string prefix,
string value,
bool enabled =
true)
933 SCR_AutocompletePlugin_AttributeData result =
new SCR_AutocompletePlugin_AttributeData();
935 result.m_sType =
type.Trim();
937 prefix.TrimInPlace();
939 result.m_sPrefix = prefix[0];
942 result.m_sValue = value;
943 result.m_bEnabled = enabled;
SCR_AIAnimation_Loitering BaseContainerProps
Commanding menu commanding element class.
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
Get all prefabs that have the spawner data
SCR_Faction ScriptedFaction SCR_BaseContainerCustomTitleField("m_sCallsign")
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
class WorkbenchDialog_AbortRetryIgnore ButtonAttribute("OK", true)
static ParamEnumArray FromString(string input)
static string FormatValueNameToUserFriendly(string valueName)
static bool IsEmptyOrWhiteSpace(string input)
static string TrimRight(string input)
static string Join(string separator, notnull array< string > pieces, bool joinEmptyEntries=true)
static string InsertAt(string input, string insertion, int insertionIndex=0)
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
proto void PrintFormat(string fmt, void param1=NULL, void param2=NULL, void param3=NULL, void param4=NULL, void param5=NULL, void param6=NULL, void param7=NULL, void param8=NULL, void param9=NULL, LogLevel level=LogLevel.NORMAL)
SCR_FieldOfViewSettings Attribute