Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
EBTConfig.c
Go to the documentation of this file.
1#ifdef WORKBENCH
2
3
4[WorkbenchPluginAttribute(name: "EBT: Config", wbModules: { "ResourceManager" }, awesomeFontCode: 0xf013)]
5class EBTConfigPlugin : WorkbenchPlugin
6{
7
8 [Attribute("0", UIWidgets.ComboBox, "", "", enums: GetRegisteredBlenderExecutables(), category: "Paths")]
9 int m_iDefaultPath;
10
11 [Attribute("", UIWidgets.Auto, "Blender Executables", category: "Paths")]
12 protected ref array<ref BlenderPathContainer> m_aBlenderPaths;
13
14 [Attribute("True", UIWidgets.CheckBox, "Check this option to print output to clipboard.", category : "Development")]
15 protected bool m_bCopyToClipboard = false;
16
17 protected bool shouldReload = true;
18
19 protected static EBTConfigPlugin s_Instance;
20
21 protected static const ref ParamEnum NO_EXECUTABLE_ENUM = new ParamEnum("None", "0");
22
23 protected static ref ParamEnumArray s_RegisteredBlenderExecutables = {NO_EXECUTABLE_ENUM};
24
25 static ref ParamEnumArray GetRegisteredBlenderExecutables()
26 {
27 return s_RegisteredBlenderExecutables;
28 }
29
30 void EBTConfigPlugin()
31 {
32 if(!s_Instance)
33 s_Instance = this;
34 }
35
36 static bool CopyToClipboard()
37 {
38 return s_Instance.m_bCopyToClipboard;
39 }
40
41 static void UpdateRegisteredBlenderExecutables()
42 {
43 s_RegisteredBlenderExecutables.Clear();
44
45 int len = s_Instance.m_aBlenderPaths.Count();
46
47 if (len == 0)
48 {
49 s_RegisteredBlenderExecutables.Insert(NO_EXECUTABLE_ENUM);
50 return;
51 }
52
53 for (int i = 0; i < len; i++)
54 {
55 string path = s_Instance.m_aBlenderPaths[i].m_sPath;
56 if (path != string.Empty)
57 {
58 string title;
59 if (BlenderPathContainer.GetTitleFromPath(path, title))
60 s_RegisteredBlenderExecutables.Insert(new ParamEnum(title, i.ToString()));
61 }
62 }
63
64 if (s_RegisteredBlenderExecutables.Count() == 0)
65 {
66 s_RegisteredBlenderExecutables.Insert(NO_EXECUTABLE_ENUM);
67 }
68 }
69
70 static bool HasBlenderRegistered()
71 {
72 UpdateRegisteredBlenderExecutables();
73
74
75 if (s_RegisteredBlenderExecutables[0].m_Key == "None")
76 {
77 Print("No blender executable set! Please set one in EBT Config!", LogLevel.WARNING);
78 return false;
79 }
80
81 return true;
82 }
83
84 // it returns bool in case user in any way makes path to executable invalid in the meantime from its registration
85 // and caller doesn't check for HasBlenderRegistered
86 static bool GetBlenderPathFromEnumIndex(int index, out string path)
87 {
88 ref array<ref BlenderPathContainer> pathContainers = s_Instance.m_aBlenderPaths;
89
90 if (!FileIO.FileExists(pathContainers[index].m_sPath))
91 {
92 Print(pathContainers[index].m_sPath + " does not exist! Please select a valid path in EBT Config.", LogLevel.WARNING);
93 return false;
94 }
95
96 path = pathContainers[index].m_sPath;
97 return true;
98 }
99
100 static bool GetDefaultBlenderPath(out string path)
101 {
102 return GetBlenderPathFromEnumIndex(s_Instance.m_iDefaultPath, path);
103 }
104
105 [ButtonAttribute("OK")]
106 protected void ButtonOK() {}
107
108 [ButtonAttribute("Update Menu")]
109 protected void ButtonUpdateDropdownMenu()
110 {
111 shouldReload = true;
112 return;
113 }
114
115 override void Configure()
116 {
117 while(shouldReload)
118 {
119 EBTConfigPlugin.HasBlenderRegistered();
120 shouldReload = false;
121 Workbench.ScriptDialog("EBT Config", "", this);
122 }
123 shouldReload = true;
124 }
125
126 static void Update()
127 {
128 Print("updated");
129 }
130}
131
132class BaseContainerCustomTitleBlenderVersion : BaseContainerCustomTitle
133{
134 protected string m_sPropertyName;
135
136 //------------------------------------------------------------------------------------------------
137 void BaseContainerCustomTitleBlenderVersion(string propertyName)
138 {
139 m_sPropertyName = propertyName;
140 }
141
142 //------------------------------------------------------------------------------------------------
143 override bool _WB_GetCustomTitle(BaseContainer source, out string title)
144 {
145 string path;
146 if (!source.Get(m_sPropertyName, path))
147 return false;
148
149 BlenderPathContainer.GetTitleFromPath(path, title);
150 EBTConfigPlugin.HasBlenderRegistered();
151
152 return true;
153 }
154}
155
156[BaseContainerProps(), BaseContainerCustomTitleBlenderVersion("m_sPath")]
157class BlenderPathContainer
158{
159 [Attribute("", uiwidget: UIWidgets.FileNamePicker, desc: "Absolute path to your blender.exe", params: "exe FileNameFormat=absolute", category: "Path")]
160 string m_sPath;
161
162
163 //------------------------------------------------------------------------------------------------
164 static bool GetTitleFromPath(string path, out string title)
165 {
166 if (!path)
167 {
168 title = "Unassigned";
169 return false;
170 }
171
172 if (!FileIO.FileExists(path))
173 {
174 title = "Non Existing";
175 return false;
176 }
177
178 array<string> splitString = {};
179 path.Split("\\", splitString, true);
180
181 if (splitString.Count() < 2)
182 {
183 title = "Invalid Path";
184
185 return false;
186 }
187
188 title = splitString[splitString.Count() - 2];
189
190 return true;
191 }
192}
193
194
195#endif
string path
void ParamEnum(string key, string value, string desc="")
Definition attributes.c:25
string m_Key
Definition attributes.c:21
GenerateFlowMaps WorkbenchPlugin WorkbenchPluginAttribute("Regenerate river flow-maps", "Generate and save/overwrite river flow-maps", "", "", {"WorldEditor"}, "", 0xf773)
Definition FlowmapTool.c:59
BaseContainerCustomCheckIntWithFlagTitleField m_sPropertyName
Attribute for setting UIInfo's name property as (Localized) custom title.
SCR_AIAnimation_Loitering BaseContainerProps
Commanding menu commanding element class.
void CopyToClipboard()
Copy currently generated text to clipboard.
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
bool ButtonOK()
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
override void Configure()
class WorkbenchDialog_AbortRetryIgnore ButtonAttribute("OK", true)
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
class SCR_BaseManualCameraComponent _WB_GetCustomTitle(BaseContainer source, out string title)