Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_NewScriptPlugin.c
Go to the documentation of this file.
1#ifdef WORKBENCH
2[WorkbenchPluginAttribute(name: "Create New Script", shortcut: "CTRL+N", wbModules: { "ScriptEditor" }, awesomeFontCode: 0xF1C9)]
3class SCR_NewScriptPlugin : WorkbenchPlugin
4{
5 [Attribute(defvalue: "1", uiwidget: UIWidgets.ComboBox, desc: "File system where the new script file will be created", enums: SCR_ParamEnumArray.FromAddons(titleFormat: 2, hideCoreModules: 2), category: "General")]
6 protected int m_iAddon;
7
8 [Attribute(defvalue: "scripts/Game", desc: "File destination - the path can be selected in an addon (typically the Arma project) and the directory tree will then be created in said targeted addon", params: "unregFolders", category: "General")]
9 protected ResourceName m_sLastAbsoluteDestinationDirectory;
10
11 protected static const string SCRIPT_EXTENSION = ".c";
12 protected static const string ALLOWED_CLASSNAME_CHARS = SCR_StringHelper.LETTERS + SCR_StringHelper.DIGITS + SCR_StringHelper.UNDERSCORE;
13
14 //------------------------------------------------------------------------------------------------
15 override void Run()
16 {
17 ScriptEditor scriptEditor = Workbench.GetModule(ScriptEditor);
18 if (!scriptEditor)
19 return;
20
21 string currentFilePath;
22 bool createRelative = scriptEditor.GetCurrentFile(currentFilePath);
23
24 string relativeDirectory;
25 string fileName;
26 if (createRelative)
27 {
28 SCR_NewScriptPlugin_RelativeUI ui = new SCR_NewScriptPlugin_RelativeUI();
29 ui.m_iAddon = m_iAddon; // restore save
30 ui.m_sDestinationDirectory = FilePath.StripFileName(currentFilePath);
31 if (!Workbench.ScriptDialog("Script Creation", "Define the new file's settings.", ui))
32 return;
33
34 m_iAddon = ui.m_iAddon; // saves AND stores for later in script
35 fileName = ui.m_sFileName;
36 if (fileName.EndsWith(SCRIPT_EXTENSION))
37 fileName.Substring(0, fileName.Length() - SCRIPT_EXTENSION.Length());
38
39 relativeDirectory = ui.m_sDestinationDirectory;
40 }
41 else
42 {
43 SCR_NewScriptPlugin_AbsoluteUI ui = new SCR_NewScriptPlugin_AbsoluteUI();
44 ui.m_iAddon = m_iAddon; // restore save
45 ui.m_sDestinationDirectory = m_sLastAbsoluteDestinationDirectory;
46 if (!Workbench.ScriptDialog("Script Creation", "Define the new file's settings.", ui))
47 return;
48
49 m_iAddon = ui.m_iAddon; // saves AND stores for later in script
50 fileName = ui.m_sFileName;
51 if (fileName.EndsWith(SCRIPT_EXTENSION))
52 fileName.Substring(0, fileName.Length() - SCRIPT_EXTENSION.Length());
53
54 relativeDirectory = ui.m_sDestinationDirectory.GetPath();
55 }
56
57 string absoluteDirectory;
58 if (!SCR_AddonTool.GetAddonAbsolutePath(m_iAddon, relativeDirectory, absoluteDirectory, false))
59 {
60 Print("Cannot Get absolute directory for " + relativeDirectory, LogLevel.WARNING);
61 return;
62 }
63
64 if (!FileIO.FileExists(absoluteDirectory))
65 {
66 if (!FileIO.MakeDirectory(absoluteDirectory))
67 {
68 Print("Cannot create " + absoluteDirectory);
69 return;
70 }
71 }
72
73 if (!absoluteDirectory.EndsWith(SCR_StringHelper.SLASH))
74 absoluteDirectory += SCR_StringHelper.SLASH;
75
76 fileName = SCR_StringHelper.Filter(fileName, ALLOWED_CLASSNAME_CHARS, false);
77
78 int i;
79 while (!fileName || FileIO.FileExists(absoluteDirectory + fileName))
80 {
81 fileName = "NewScriptFile_" + ++i;
82 if (!fileName.EndsWith(SCRIPT_EXTENSION))
83 fileName += SCRIPT_EXTENSION;
84 }
85
86 if (!fileName.EndsWith(SCRIPT_EXTENSION))
87 fileName += SCRIPT_EXTENSION;
88
89 string absoluteFilePath = absoluteDirectory + fileName;
90
91 FileHandle file = FileIO.OpenFile(absoluteFilePath, FileMode.WRITE);
92 if (!file)
93 {
94 Workbench.Dialog("Script Creation error", "\"" + absoluteFilePath + "\" could not be created.");
95 return;
96 }
97
98 file.Close();
99
100 Sleep(1);
101 Workbench.GetModule(ScriptEditor).SetOpenedResource(absoluteFilePath);
102 }
103}
104
105class SCR_NewScriptPlugin_RelativeUI
106{
107 [Attribute(defvalue: "1", uiwidget: UIWidgets.ComboBox, desc: "File system where the new script file will be created", enums: SCR_ParamEnumArray.FromAddons(titleFormat: 2, hideCoreModules: 0))]
108 int m_iAddon;
109
110 [Attribute(defvalue: "", desc: "File destination - the path can be selected in an addon (typically the Arma project) and Addon be defined to something else, the directory tree will then be created in said targeted addon")]
111 string m_sDestinationDirectory;
112
113 [Attribute(desc: "Allowed characters: a-z, A-Z, 0-9, _")]
114 string m_sFileName;
115
116 //------------------------------------------------------------------------------------------------
117 [ButtonAttribute("OK", true)]
118 protected int ButtonOK()
119 {
120 return 1;
121 }
122
123 //------------------------------------------------------------------------------------------------
124 [ButtonAttribute("Cancel")]
125 protected int ButtonCancel()
126 {
127 return 0;
128 }
129}
130
131class SCR_NewScriptPlugin_AbsoluteUI
132{
133 [Attribute(defvalue: "1", uiwidget: UIWidgets.ComboBox, desc: "File system where the new script file will be created", enums: SCR_ParamEnumArray.FromAddons(titleFormat: 2, hideCoreModules: 2))]
134 int m_iAddon;
135
136 [Attribute(defvalue: "", desc: "File destination - the path can be selected in an addon (typically the Arma project) and Addon be defined to something else, the directory tree will then be created in said targeted addon", params: "unregFolders")]
137 ResourceName m_sDestinationDirectory;
138
139 [Attribute(desc: "Allowed characters: a-z, A-Z, 0-9, _")]
140 string m_sFileName;
141
142 //------------------------------------------------------------------------------------------------
143 [ButtonAttribute("OK")]
144 protected int ButtonOK()
145 {
146 return 1;
147 }
148
149 //------------------------------------------------------------------------------------------------
150 [ButtonAttribute("Cancel")]
151 protected int ButtonCancel()
152 {
153 return 0;
154 }
155}
156#endif // WORKBENCH
GenerateFlowMaps WorkbenchPlugin WorkbenchPluginAttribute("Regenerate river flow-maps", "Generate and save/overwrite river flow-maps", "", "", {"WorldEditor"}, "", 0xf773)
Definition FlowmapTool.c:59
override void Run()
bool ButtonCancel()
bool ButtonOK()
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
string m_sFileName
class WorkbenchDialog_AbortRetryIgnore ButtonAttribute("OK", true)
static ParamEnumArray FromAddons(int titleFormat=2, int hideCoreModules=0)
static string Filter(string input, string characters, bool useCharactersAsBlacklist=false)
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
FileMode
Mode for opening file. See FileSystem::Open.
Definition FileMode.c:14