Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_ScriptTemplatePlugin.c
Go to the documentation of this file.
1#ifdef WORKBENCH
2[WorkbenchPluginAttribute(name: "Fill from Template", shortcut: "Ctrl+T", wbModules: { "ScriptEditor" }, awesomeFontCode: 0xF1C9)]
3class SCR_ScriptTemplatePlugin : WorkbenchPlugin
4{
5 /*
6 Category: General
7 */
8
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;
11
12 [Attribute(desc: "Full classname - if left empty, file name will be used", category: "General")]
13 protected string m_sClassName;
14
15 [Attribute(desc: "Parent class name - if left empty, default for given script type will be used", category: "General")]
16 protected string m_sParentName;
17
18 /*
19 Category: Advanced
20 */
21
22 //--- Let's not expose this, could be overwhelming for the user
23 // [Attribute("{51BB186E949A991B}Configs/Workbench/ScriptTemplatePlugin/ScriptTemplateConfig.conf", params: "conf class=SCR_ScriptTemplateConfig", category: "Advanced")]
24 protected ResourceName m_sConfig = "{51BB186E949A991B}Configs/Workbench/ScriptTemplatePlugin/ScriptTemplateConfig.conf";
25
26 //------------------------------------------------------------------------------------------------
27 protected override void Run()
28 {
29 ScriptEditor scriptEditor = Workbench.GetModule(ScriptEditor);
30 string className;
31 if (!scriptEditor.GetCurrentFile(className))
32 {
33 Print("Cannot insert script template, no file is opened!", LogLevel.WARNING);
34 return;
35 }
36
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))
38 return;
39
40 //--- Load config
41 Resource configResource = Resource.Load(m_sConfig);
42 if (!configResource.IsValid())
43 {
44 Debug.Error2(Type().ToString(), string.Format("Cannot load config '%1'!", m_sConfig));
45 return;
46 }
47
48 SCR_ScriptTemplateConfig config = SCR_ScriptTemplateConfig.Cast(BaseContainerTools.CreateInstanceFromContainer(configResource.GetResource().ToBaseContainer()));
49 if (!config)
50 {
51 Debug.Error2(Type().ToString(), string.Format("Cannot load config '%1'!", m_sConfig));
52 return;
53 }
54
55 if (!config.m_aEntries)
56 {
57 Debug.Error2(Type().ToString(), string.Format("Config '%1' has null entries!", m_sConfig));
58 return;
59 }
60
61 //--- Get template
62 string template, defaultParentName, suffix;
63 foreach (SCR_ScriptTemplateConfigEntry entry : config.m_aEntries)
64 {
65 if (entry.m_eType == m_eClassType)
66 {
67 template = entry.m_sTemplate;
68 defaultParentName = entry.m_sDefaultParentName;
69 suffix = entry.m_sSuffix;
70 break;
71 }
72 }
73
74 //--- Get script class
75 if (m_sClassName.IsEmpty())
76 className = FilePath.StripExtension(FilePath.StripPath(className));
77 else
78 className = m_sClassName;
79
80 if (!className.EndsWith(suffix))
81 className += suffix;
82
83 //--- Get parent class
84 string parentName;
85 if (m_sParentName.IsEmpty())
86 parentName = defaultParentName;
87 else
88 parentName = m_sParentName;
89
90 if (parentName)
91 parentName = " : " + parentName;
92
93 //--- Copy template into the script
94 int lineNumber = scriptEditor.GetCurrentLine();
95 scriptEditor.InsertLine(string.Format(template, className, parentName), lineNumber);
96 }
97
98 //------------------------------------------------------------------------------------------------
99 [ButtonAttribute("Fill", true)]
100 protected bool ButtonConfirm()
101 {
102 return true;
103 }
104
105 //------------------------------------------------------------------------------------------------
106 [ButtonAttribute("Cancel")]
107 protected bool ButtonCancel()
108 {
109 return false;
110 }
111}
112
113[BaseContainerProps(configRoot: true)]
114class SCR_ScriptTemplateConfig
115{
116 [Attribute()]
117 ref array<ref SCR_ScriptTemplateConfigEntry> m_aEntries;
118}
119
120[BaseContainerProps(), SCR_BaseContainerCustomTitleEnum(SCR_EScriptTemplateType, "m_eType")]
121class SCR_ScriptTemplateConfigEntry
122{
123 [Attribute(uiwidget: UIWidgets.ComboBox, desc: "Template type", enumType: SCR_EScriptTemplateType)]
124 SCR_EScriptTemplateType m_eType;
125
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")]
127 string m_sTemplate;
128
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;
131
132 [Attribute(desc: "Define the class' mandatory suffix (e.g xxxEntity, xxxPlugin, xxxTool)")]
133 string m_sSuffix;
134}
135
136enum SCR_EScriptTemplateType
137{
138 None,
139 Entity,
140 Component,
141 WidgetComponent,
144 UIMenu,
145 ConfigRoot,
146 WorkbenchPlugin,
147 ScriptEditorPlugin,
148 WorldEditorPlugin,
149 WorldEditorTool,
150 TEST_SUITE,
151 TEST_CASE,
152}
153#endif // WORKBENCH
GenerateFlowMaps WorkbenchPlugin WorkbenchPluginAttribute("Regenerate river flow-maps", "Generate and save/overwrite river flow-maps", "", "", {"WorldEditor"}, "", 0xf773)
Definition FlowmapTool.c:59
string m_sParentName
SCR_AIAnimation_Loitering BaseContainerProps
Commanding menu commanding element class.
class SCR_CampaignHintStorage SCR_BaseContainerCustomTitleEnum(EHint, "m_eHintId")
SCR_ECampaignBaseType m_eType
override void Run()
bool ButtonCancel()
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
int Type
class WorkbenchDialog_AbortRetryIgnore ButtonAttribute("OK", true)
Definition Debug.c:13
Object holding reference to resource. In destructor release the resource.
Definition Resource.c:25
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14
SCR_FieldOfViewSettings Attribute
proto external string ToString()
Plain C++ pointer, no weak pointers, no memory management.
ScriptInvokerBase< func > ScriptInvoker
Definition tools.c:134