Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_GenerateControlsSchemePlugin.c
Go to the documentation of this file.
1#ifdef WORKBENCH
2[WorkbenchPluginAttribute(name: "Generate Controls Scheme", wbModules: { "ResourceManager" }, awesomeFontCode: 0xF11B)]
3class SCR_GenerateControlsSchemePlugin : WorkbenchPlugin
4{
5 [Attribute(desc: "A list of contexts to be exported. Actions from all contexts will be merged into one image.")]
6 protected ref array<string> m_aContextNames;
7
8 [Attribute(defvalue: "$profile:GenerateControlsScheme/", desc: "Directory at which the scheme will be saved")]
9 protected string m_sDirectory;
10
11 //[Attribute("2", UIWidgets.ComboBox, "", enumType: SCR_EGenerateControlsSchemeType)]
12 protected SCR_EGenerateControlsSchemeType m_eType = SCR_EGenerateControlsSchemeType.GAMEPAD;
13
14 [Attribute(defvalue: "1", desc: "Font size multiplier. Use a smaller font when action names are too long and overflow from the image.")]
15 protected float m_fFontSize;
16
17 [Attribute(defvalue: "1", desc: "True to label actions that are not used in given contexts. Unassigned actions will be shown in faded color.")]
18 protected bool m_bShowUnassigned;
19
20 //------------------------------------------------------------------------------------------------
22 bool ProcessBinding_Gamepad(map<string, ref array<string>> allBindings, string fullPath, string contextTitle)
23 {
24 bool didCopy = FileIO.CopyFile("scripts/WorkbenchGame/GenerateControlsScheme_Gamepad.txt", fullPath);
25 if (!didCopy)
26 {
27 Print(string.Format("Cannot copy header to '%1'!", fullPath), LogLevel.ERROR);
28 return false;
29 }
30
31 FileHandle file = FileIO.OpenFile(fullPath, FileMode.APPEND);
32 if (!file)
33 {
34 Print(string.Format("Cannot open file at '%1'!", fullPath), LogLevel.ERROR);
35 return false;
36 }
37
38 const float tL1 = 280;
39 const float lL1 = 290;
40 const float lL2 = 370;
41
42 const float tR1 = 800;
43 const float lR1 = 790;
44 const float lR2 = 710;
45
47 labels.Insert("gamepad0:view", new SCR_GenerateControlsSchemeGamepadLabel("end", 500, 040, 510, 510, 035, 510, 245));
48 labels.Insert("gamepad0:menu", new SCR_GenerateControlsSchemeGamepadLabel("start", 580, 040, 572, 572, 035, 572, 245));
49
50 labels.Insert("gamepad0:left_trigger", new SCR_GenerateControlsSchemeGamepadLabel("end", tL1, 070, lL1, lL2, 065, 450, 171));
51 labels.Insert("gamepad0:shoulder_left", new SCR_GenerateControlsSchemeGamepadLabel("end", tL1, 130, lL1, lL2, 125, 420, 185));
52 labels.Insert("gamepad0:left_thumb_horizontal", new SCR_GenerateControlsSchemeGamepadLabel("end", tL1, 250, lL1, lL2, 275, 420, 250, "⭤"));
53 labels.Insert("gamepad0:left_thumb_vertical", new SCR_GenerateControlsSchemeGamepadLabel("end", tL1, 280, lL1, lL2, 275, 420, 250, "⭥"));
54 labels.Insert("gamepad0:thumb_left", new SCR_GenerateControlsSchemeGamepadLabel("end", tL1, 310, lL1, lL2, 275, 420, 250, "●"));
55 labels.Insert("gamepad0:pad_up", new SCR_GenerateControlsSchemeGamepadLabel("end", tL1, 360, lL1, lL2, 400, 460, 320, "▲"));//355, 480, 295, "▲"));
56 labels.Insert("gamepad0:pad_left", new SCR_GenerateControlsSchemeGamepadLabel("end", tL1, 390, lL1, lL2, 400, 460, 320, "◄"));//385, 460, 325, "◄"));
57 labels.Insert("gamepad0:pad_right", new SCR_GenerateControlsSchemeGamepadLabel("end", tL1, 420, lL1, lL2, 400, 460, 320, "►"));//415, 505, 320, "►"));
58 labels.Insert("gamepad0:pad_down", new SCR_GenerateControlsSchemeGamepadLabel("end", tL1, 450, lL1, lL2, 400, 460, 320, "▼"));//445, 490, 345, "▼"));
59
60 labels.Insert("gamepad0:right_trigger", new SCR_GenerateControlsSchemeGamepadLabel("start", tR1, 070, lR1, lR2, 065, 630, 171));
61 labels.Insert("gamepad0:shoulder_right", new SCR_GenerateControlsSchemeGamepadLabel("start", tR1, 130, lR1, lR2, 125, 660, 185));
62 labels.Insert("gamepad0:y", new SCR_GenerateControlsSchemeGamepadLabel("start", tR1, 190, lR1, lR2, 185, 660, 220));
63 labels.Insert("gamepad0:x", new SCR_GenerateControlsSchemeGamepadLabel("start", tR1, 220, lR1, lR2, 215, 630, 250));
64 labels.Insert("gamepad0:b", new SCR_GenerateControlsSchemeGamepadLabel("start", tR1, 250, lR1, lR2, 245, 690, 250));
65 labels.Insert("gamepad0:a", new SCR_GenerateControlsSchemeGamepadLabel("start", tR1, 280, lR1, lR2, 275, 660, 280));
66 labels.Insert("gamepad0:right_thumb_horizontal", new SCR_GenerateControlsSchemeGamepadLabel("start", tR1, 360, lR1, lR2, 385, 610, 320, "⭤"));
67 labels.Insert("gamepad0:right_thumb_vertical", new SCR_GenerateControlsSchemeGamepadLabel("start", tR1, 390, lR1, lR2, 385, 610, 320, "⭥"));
68 labels.Insert("gamepad0:thumb_right", new SCR_GenerateControlsSchemeGamepadLabel("start", tR1, 420, lR1, lR2, 385, 610, 320, "●"));
69
70 string texts = string.Format("<text x='20' y='570' text-anchor='start' font-size='25' font-weight='bold'>%1</text>\n", contextTitle);
71 string lines;
72 string textsDisabled;
73 string linesDisabled;
74 SCR_GenerateControlsSchemeGamepadLabel label;
75 array<string> bindings;
76 for (int l, countL = labels.Count(); l < countL; l++)
77 {
78 label = labels.GetElement(l);
79 if (allBindings.Find(labels.GetKey(l), bindings))
80 {
81 label.AddText(texts, bindings[0]);
82 label.AddLines(lines);
83 }
84 else if (m_bShowUnassigned)
85 {
86 label.AddText(textsDisabled, "N/A");
87 label.AddLines(linesDisabled);
88 }
89 }
90
91 file.WriteLine(string.Format("<g font-family='Roboto' font-size='%1' fill='#ccc'>", 20 * m_fFontSize));
92 file.WriteLine(textsDisabled);
93 file.WriteLine("</g>");
94
95 file.WriteLine(string.Format("<g font-family='Roboto' font-size='%1' fill='black'>", 20 * m_fFontSize));
96 file.WriteLine(texts);
97 file.WriteLine("</g>");
98
99 file.WriteLine("<g stroke='black' stroke-width='2' opacity='0.1' transform='translate(0.5,0.5)'>");
100 file.WriteLine(linesDisabled);
101 file.WriteLine("</g>");
102
103 file.WriteLine("<g stroke='black' stroke-width='2' opacity='1' transform='translate(0.5,0.5)'>");
104 file.WriteLine(lines);
105 file.WriteLine("</g>");
106
107 file.WriteLine("</svg>");
108
109 file.Close();
110
111 return true;
112 }
113
114 //------------------------------------------------------------------------------------------------
116 protected bool ProcessBinding_Keyboard(map<string, ref array<string>> allBindings, string fileName, string contextTitle)
117 {
118 return false;
119 }
120
121 //------------------------------------------------------------------------------------------------
123 protected bool ProcessBinding_Mouse(map<string, ref array<string>> allBindings, string fileName, string contextTitle)
124 {
125 return false;
126 }
127
128 //------------------------------------------------------------------------------------------------
130 protected void Generate()
131 {
132 if (!m_aContextNames)
133 return;
134
135 InputBinding input = GetGame().GetInputManager().CreateUserBinding();
136
137 //--- Whitelist specific keys based on selected input m_eType
138 array<string> whitelist = {};
139 switch (m_eType)
140 {
141 case SCR_EGenerateControlsSchemeType.KEYBOARD:
142 break;
143
144 case SCR_EGenerateControlsSchemeType.MOUSE:
145 break;
146
147 case SCR_EGenerateControlsSchemeType.GAMEPAD:
148 whitelist.Insert("gamepad0:menu");
149 whitelist.Insert("gamepad0:view");
150 whitelist.Insert("gamepad0:a");
151 whitelist.Insert("gamepad0:b");
152 whitelist.Insert("gamepad0:x");
153 whitelist.Insert("gamepad0:y");
154 whitelist.Insert("gamepad0:pad_up");
155 whitelist.Insert("gamepad0:pad_down");
156 whitelist.Insert("gamepad0:pad_left");
157 whitelist.Insert("gamepad0:pad_right");
158 whitelist.Insert("gamepad0:shoulder_left");
159 whitelist.Insert("gamepad0:shoulder_right");
160 whitelist.Insert("gamepad0:thumb_left");
161 whitelist.Insert("gamepad0:thumb_right");
162 whitelist.Insert("gamepad0:left_thumb_horizontal");
163 whitelist.Insert("gamepad0:left_thumb_vertical");
164 whitelist.Insert("gamepad0:right_thumb_horizontal");
165 whitelist.Insert("gamepad0:right_thumb_vertical");
166 whitelist.Insert("gamepad0:left_trigger");
167 whitelist.Insert("gamepad0:right_trigger");
168 break;
169 }
170
171 //--- Find relevant actions
172 map<string, ref array<string>> allBindings = new map <string, ref array<string>>();
173 string contextTitle;
174 foreach (string contextName : m_aContextNames)
175 {
176 BaseContainer context = input.FindContext(contextName);
177 if (!context)
178 {
179 Print(string.Format("Context '%1' not found!", contextName), LogLevel.ERROR);
180 continue;
181 }
182
183 array<string> actionNames = {};
184 if (!context.Get("ActionRefs", actionNames))
185 continue;
186
187 foreach (string actionName : actionNames)
188 {
189 array<string> bindings = {};
190 if (!input.GetBindings(actionName, bindings, EInputDeviceType.MOUSE))
191 continue;
192
193 if (!input.GetBindings(actionName, bindings, EInputDeviceType.KEYBOARD))
194 continue;
195
196 if (!input.GetBindings(actionName, bindings, EInputDeviceType.GAMEPAD))
197 continue;
198
199 if (!input.GetBindings(actionName, bindings, EInputDeviceType.JOYSTICK))
200 continue;
201
202 foreach (string binding : bindings)
203 {
204 if (whitelist.Find(binding) < 0)
205 continue;
206
207 array<string> currentBindings;
208 allBindings.Find(binding, currentBindings);
209 if (!currentBindings)
210 currentBindings = {};
211
212 currentBindings.Insert(actionName);
213 allBindings.Insert(binding, currentBindings);
214 }
215 }
216
217 if (contextTitle != "")
218 contextTitle += ", ";
219
220 contextTitle += contextName;
221 }
222
223 string fileName;
224 foreach (string contextName : m_aContextNames)
225 {
226 fileName += "_" + contextName;
227 }
228
229 string directoryLocal = m_sDirectory;
230 if (!directoryLocal.EndsWith("/"))
231 directoryLocal += "/";
232
233 string fullPath;
234 bool succeeded;
235 switch (m_eType)
236 {
237 case SCR_EGenerateControlsSchemeType.KEYBOARD:
238 {
239 fullPath = directoryLocal + "keyboard" + fileName + ".svg";
240 succeeded = ProcessBinding_Keyboard(allBindings, fullPath, contextTitle);
241 break;
242 }
243 case SCR_EGenerateControlsSchemeType.MOUSE:
244 {
245 fullPath = directoryLocal + "mouse" + fileName + ".svg";
246 succeeded = ProcessBinding_Mouse(allBindings, fullPath, contextTitle);
247 break;
248 }
249 case SCR_EGenerateControlsSchemeType.GAMEPAD:
250 {
251 fullPath = directoryLocal + "gamepad" + fileName + ".svg";
252 succeeded = ProcessBinding_Gamepad(allBindings, fullPath, contextTitle);
253 break;
254 }
255 }
256
257 if (succeeded)
258 Print(string.Format("Controls scheme generated in '%1'", fullPath), LogLevel.DEBUG);
259 }
260
262 //--- Default functions
264
265 //------------------------------------------------------------------------------------------------
266 override void Run()
267 {
268 if (Workbench.ScriptDialog("Generate Controls Scheme", "Generate a *.svg file which lists all actions in given contexts.\nThe file can be attached to Confluence page to showcase a control scheme.", this))
269 Generate();
270 }
271
272 //------------------------------------------------------------------------------------------------
273 [ButtonAttribute("OK")]
274 protected bool ButtonOK()
275 {
276 return true;
277 }
278
279 //------------------------------------------------------------------------------------------------
280 [ButtonAttribute("Cancel")]
281 protected bool ButtonCancel()
282 {
283 return false;
284 }
285}
286
287enum SCR_EGenerateControlsSchemeType
288{
289 KEYBOARD,
290 MOUSE,
291 GAMEPAD
292}
293
294class SCR_GenerateControlsSchemeGamepadLabel
295{
296 protected string m_sAnchor;
297 protected float m_fTextX;
298 protected float m_fTextY;
299 protected float m_fLineX1;
300 protected float m_fLineX2;
301 protected float m_fLineY;
302 protected float m_fTargetX;
303 protected float m_fTargetY;
304 protected string m_sSymbol;
305
306 //------------------------------------------------------------------------------------------------
307 // constructor
317 void SCR_GenerateControlsSchemeGamepadLabel(string anchor, float textX, float textY, float lineX1, float lineX2, float lineY, float targetX, float targetY, string symbol = "")
318 {
319 m_sAnchor = anchor;
320 m_fTextX = textX;
321 m_fTextY = textY;
322 m_fLineX1 = lineX1;
323 m_fLineX2 = lineX2;
324 m_fLineY = lineY;
325 m_fTargetX = targetX;
326 m_fTargetY = targetY;
327 m_sSymbol = symbol;
328 }
329
330 //------------------------------------------------------------------------------------------------
334 void AddText(out string text, string binding)
335 {
336 if (m_sSymbol != "")
337 {
338 if (m_sAnchor == "end")
339 binding = binding + " " + m_sSymbol;
340 else
341 binding = m_sSymbol + " " + binding;
342 }
343
344 text += string.Format("<text x='%3' y='%4' text-anchor='%2'>%1</text>\n", binding, m_sAnchor, m_fTextX, m_fTextY);
345 }
346
347 //------------------------------------------------------------------------------------------------
350 void AddLines(out string text)
351 {
352 //text += string.Format("<text x='%3' y='%4' text-anchor='%2'>%1</text>\n", binding, m_sAnchor, m_fTextX, m_fTextY);
353 text += string.Format("<line x1='%1' x2='%2' y1='%3' y2='%3' />\n", m_fLineX1, m_fLineX2, m_fLineY, m_fTargetX, m_fTargetY);
354 text += string.Format("<line x1='%2' x2='%4' y1='%3' y2='%5' />\n", m_fLineX1, m_fLineX2, m_fLineY, m_fTargetX, m_fTargetY);
355 }
356}
357#endif // WORKBENCH
GenerateFlowMaps WorkbenchPlugin WorkbenchPluginAttribute("Regenerate river flow-maps", "Generate and save/overwrite river flow-maps", "", "", {"WorldEditor"}, "", 0xf773)
Definition FlowmapTool.c:59
ArmaReforgerScripted GetGame()
Definition game.c:1398
enum EModularButtonEventFlag KEYBOARD
Flags for device input types.
enum EModularButtonEventFlag GAMEPAD
enum EModularButtonEventFlag MOUSE
SCR_ECampaignBaseType m_eType
override void Run()
bool ButtonCancel()
bool ButtonOK()
void Generate()
string m_sDirectory
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
class WorkbenchDialog_AbortRetryIgnore ButtonAttribute("OK", true)
Manages input key bindings, presets, contexts, and device calibration. Provides functions for creatin...
Definition Types.c:486
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