Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_LocLinkPlugin.c
Go to the documentation of this file.
1#ifdef WORKBENCH
2[WorkbenchPluginAttribute(name: "Generate Image Links", wbModules: { "LocalizationEditor"}, awesomeFontCode: 0xF1B2)]
3class SCR_LocLinkImagePlugin : LocalizationEditorPlugin
4{
5 [Attribute(defvalue: "https://bohemiainteractive.sharepoint.com/:i:/r/sites/reforger/translations/Images/", desc: "Internet path added in front of the image file.")]
6 protected string m_sPath;
7
8 [Attribute(defvalue: "png", desc: "Image extensions which will replace *.edds")]
9 protected string m_sExtension;
10
11 //------------------------------------------------------------------------------------------------
12 override void OnChange(BaseContainer stringTableItem, string propName, string propValue)
13 {
14 if (propName != "SourceFile")
15 return;
16
17 LocalizationEditor locEditor = Workbench.GetModule(LocalizationEditor);
18 if (!locEditor)
19 return;
20
21 UpdateItem(stringTableItem, locEditor);
22 }
23
24 //------------------------------------------------------------------------------------------------
25 override void Run()
26 {
27 if (!Workbench.ScriptDialog("Generate Image Links", "Set 'Image Link' attribute for all selected items based on their 'Source File' prefab.\n\nCurrently it recognizes images used by in-game editor.", this))
28 return;
29
30 LocalizationEditor locEditor = Workbench.GetModule(LocalizationEditor);
31 locEditor.BeginModify("LocLinkImagePlugin");
32 BaseContainerList items = locEditor.GetTable().GetObjectArray("Items");
33
34 WBProgressDialog progress = new WBProgressDialog("Processing...", locEditor);
35
36 int linkedCount = 0;
37 array<int> indexes = {};
38 locEditor.GetSelectedRows(indexes);
39 BaseContainer item;
40 float prevProgress, currProgress;
41 for (int i = 0, count = indexes.Count(); i < count; i++)
42 {
43 item = items.Get(indexes[i]);
44 if (UpdateItem(item, locEditor))
45 linkedCount++;
46
47 currProgress = i / count;
48 if (currProgress - prevProgress >= 0.01) // min 1%
49 {
50 progress.SetProgress(currProgress); // expensive
51 prevProgress = currProgress;
52 }
53 }
54
55 locEditor.EndModify();
56 progress = null;
57
58 Workbench.ScriptDialog("Generate Image Links", string.Format("%1 key(s) processed, %2 linked.", indexes.Count(), linkedCount), new SCR_LocLinkImagePluginResult());
59 }
60
61 //------------------------------------------------------------------------------------------------
62 protected bool UpdateItem(BaseContainer item, LocalizationEditor locEditor)
63 {
64 ResourceName sourceFile;
65 item.Get("SourceFile", sourceFile);
66 if (!sourceFile.IsEmpty())
67 {
68 Resource resource = Resource.Load(sourceFile);
69 if (resource.IsValid())
70 {
71 IEntityComponentSource component = SCR_BaseContainerTools.FindComponentSource(resource, SCR_EditableEntityComponent);
72 if (component)
73 {
75 if (info)
76 {
77 string image = info.GetImage();
78 if (!image.IsEmpty())
79 {
80 image = FilePath.ReplaceExtension(image, m_sExtension);
81 image = m_sPath + FilePath.StripPath(image);
82 locEditor.ModifyProperty(item, item.GetVarIndex("ImageLink"), image);
83 return true;
84 }
85 }
86 }
87 }
88 else
89 {
90 string id;
91 item.Get("Id", id);
92 Print(string.Format("Unable to load source file '%1' of '%2'!", sourceFile, id), LogLevel.WARNING);
93 }
94 }
95
96 //--- Set to empty only if the variable is already defined (i.e., don't *create* empty entries)
97 if (item.IsVariableSetDirectly("ImageLink"))
98 locEditor.ModifyProperty(item, item.GetVarIndex("ImageLink"), "");
99
100 return false;
101 }
102
103 //------------------------------------------------------------------------------------------------
104 [ButtonAttribute("Run")]
105 bool ButtonRun()
106 {
107 return true;
108 }
109
110 //------------------------------------------------------------------------------------------------
111 [ButtonAttribute("Close")]
112 bool ButtonClose()
113 {
114 return false;
115 }
116}
117
118class SCR_LocLinkImagePluginResult
119{
120 //------------------------------------------------------------------------------------------------
121 [ButtonAttribute("Close")]
122 bool ButtonClose()
123 {
124 return false;
125 }
126}
127#endif // WORKBENCH
AddonBuildInfoTool id
GenerateFlowMaps WorkbenchPlugin WorkbenchPluginAttribute("Regenerate river flow-maps", "Generate and save/overwrite river flow-maps", "", "", {"WorldEditor"}, "", 0xf773)
Definition FlowmapTool.c:59
override void Run()
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
class WorkbenchDialog_AbortRetryIgnore ButtonAttribute("OK", true)
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