2[
WorkbenchPluginAttribute(name:
"Create New Script", shortcut:
"CTRL+N", wbModules: {
"ScriptEditor" }, awesomeFontCode: 0xF1C9)]
3class SCR_NewScriptPlugin : WorkbenchPlugin
6 protected int m_iAddon;
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;
11 protected static const string SCRIPT_EXTENSION =
".c";
17 ScriptEditor scriptEditor = Workbench.GetModule(ScriptEditor);
21 string currentFilePath;
22 bool createRelative = scriptEditor.GetCurrentFile(currentFilePath);
24 string relativeDirectory;
28 SCR_NewScriptPlugin_RelativeUI ui =
new SCR_NewScriptPlugin_RelativeUI();
29 ui.m_iAddon = m_iAddon;
30 ui.m_sDestinationDirectory =
FilePath.StripFileName(currentFilePath);
31 if (!Workbench.ScriptDialog(
"Script Creation",
"Define the new file's settings.", ui))
34 m_iAddon = ui.m_iAddon;
35 fileName = ui.m_sFileName;
36 if (fileName.EndsWith(SCRIPT_EXTENSION))
37 fileName.Substring(0, fileName.Length() - SCRIPT_EXTENSION.Length());
39 relativeDirectory = ui.m_sDestinationDirectory;
43 SCR_NewScriptPlugin_AbsoluteUI ui =
new SCR_NewScriptPlugin_AbsoluteUI();
44 ui.m_iAddon = m_iAddon;
45 ui.m_sDestinationDirectory = m_sLastAbsoluteDestinationDirectory;
46 if (!Workbench.ScriptDialog(
"Script Creation",
"Define the new file's settings.", ui))
49 m_iAddon = ui.m_iAddon;
50 fileName = ui.m_sFileName;
51 if (fileName.EndsWith(SCRIPT_EXTENSION))
52 fileName.Substring(0, fileName.Length() - SCRIPT_EXTENSION.Length());
54 relativeDirectory = ui.m_sDestinationDirectory.GetPath();
57 string absoluteDirectory;
58 if (!SCR_AddonTool.GetAddonAbsolutePath(m_iAddon, relativeDirectory, absoluteDirectory,
false))
60 Print(
"Cannot Get absolute directory for " + relativeDirectory,
LogLevel.WARNING);
64 if (!
FileIO.FileExists(absoluteDirectory))
66 if (!
FileIO.MakeDirectory(absoluteDirectory))
68 Print(
"Cannot create " + absoluteDirectory);
79 while (!fileName ||
FileIO.FileExists(absoluteDirectory + fileName))
81 fileName =
"NewScriptFile_" + ++i;
82 if (!fileName.EndsWith(SCRIPT_EXTENSION))
83 fileName += SCRIPT_EXTENSION;
86 if (!fileName.EndsWith(SCRIPT_EXTENSION))
87 fileName += SCRIPT_EXTENSION;
89 string absoluteFilePath = absoluteDirectory + fileName;
94 Workbench.Dialog(
"Script Creation error",
"\"" + absoluteFilePath +
"\" could not be created.");
101 Workbench.GetModule(ScriptEditor).SetOpenedResource(absoluteFilePath);
105class SCR_NewScriptPlugin_RelativeUI
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))]
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;
131class SCR_NewScriptPlugin_AbsoluteUI
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))]
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;
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
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.
SCR_FieldOfViewSettings Attribute
FileMode
Mode for opening file. See FileSystem::Open.