2[
WorkbenchPluginAttribute(name:
"Fill from Template", shortcut:
"Ctrl+T", wbModules: {
"ScriptEditor" }, awesomeFontCode: 0xF1C9)]
3class SCR_ScriptTemplatePlugin : WorkbenchPlugin
9 [
Attribute(defvalue: SCR_EScriptTemplateType.None.ToString(),
desc:
"Template type to be used", uiwidget:
UIWidgets.ComboBox, enumType: SCR_EScriptTemplateType,
category:
"General")]
10 protected SCR_EScriptTemplateType m_eClassType;
13 protected string m_sClassName;
15 [
Attribute(
desc:
"Parent class name - if left empty, default for given script type will be used",
category:
"General")]
24 protected ResourceName m_sConfig =
"{51BB186E949A991B}Configs/Workbench/ScriptTemplatePlugin/ScriptTemplateConfig.conf";
27 protected override void Run()
29 ScriptEditor scriptEditor = Workbench.GetModule(ScriptEditor);
31 if (!scriptEditor.GetCurrentFile(className))
33 Print(
"Cannot insert script template, no file is opened!",
LogLevel.WARNING);
37 if (!Workbench.ScriptDialog(
"Fill from Template",
"Insert a template of given class type to selected line in currently opened file.",
this) && Workbench.OpenModule(ScriptEditor))
42 if (!configResource.IsValid())
44 Debug.Error2(
Type().
ToString(),
string.Format(
"Cannot load config '%1'!", m_sConfig));
48 SCR_ScriptTemplateConfig config = SCR_ScriptTemplateConfig.Cast(
BaseContainerTools.CreateInstanceFromContainer(configResource.GetResource().ToBaseContainer()));
51 Debug.Error2(
Type().
ToString(),
string.Format(
"Cannot load config '%1'!", m_sConfig));
55 if (!config.m_aEntries)
57 Debug.Error2(
Type().
ToString(),
string.Format(
"Config '%1' has null entries!", m_sConfig));
62 string template, defaultParentName, suffix;
63 foreach (SCR_ScriptTemplateConfigEntry entry : config.m_aEntries)
65 if (entry.m_eType == m_eClassType)
67 template = entry.m_sTemplate;
68 defaultParentName = entry.m_sDefaultParentName;
69 suffix = entry.m_sSuffix;
75 if (m_sClassName.IsEmpty())
78 className = m_sClassName;
80 if (!className.EndsWith(suffix))
86 parentName = defaultParentName;
91 parentName =
" : " + parentName;
94 int lineNumber = scriptEditor.GetCurrentLine();
95 scriptEditor.InsertLine(
string.Format(
template, className, parentName), lineNumber);
100 protected bool ButtonConfirm()
114class SCR_ScriptTemplateConfig
117 ref array<ref SCR_ScriptTemplateConfigEntry> m_aEntries;
121class SCR_ScriptTemplateConfigEntry
124 SCR_EScriptTemplateType
m_eType;
126 [
Attribute(uiwidget:
UIWidgets.EditBoxMultiline,
desc:
"Template text that will be added to the file. Variables are:\n%1 - class name\n%2 - parent class name")]
129 [
Attribute(
desc:
"When defined, this parent class name will be used when user does not set any in the plugin.")]
130 string m_sDefaultParentName;
132 [
Attribute(
desc:
"Define the class' mandatory suffix (e.g xxxEntity, xxxPlugin, xxxTool)")]
136enum SCR_EScriptTemplateType
SCR_AIAnimation_Loitering BaseContainerProps
Commanding menu commanding element class.
class SCR_CampaignHintStorage SCR_BaseContainerCustomTitleEnum(EHint, "m_eHintId")
SCR_ECampaignBaseType m_eType
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
class WorkbenchDialog_AbortRetryIgnore ButtonAttribute("OK", true)
Object holding reference to resource. In destructor release the resource.
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
SCR_FieldOfViewSettings Attribute
proto external string ToString()
Plain C++ pointer, no weak pointers, no memory management.