3class SCR_LocLinkImagePlugin : LocalizationEditorPlugin
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;
8 [
Attribute(defvalue:
"png",
desc:
"Image extensions which will replace *.edds")]
9 protected string m_sExtension;
12 override void OnChange(
BaseContainer stringTableItem,
string propName,
string propValue)
14 if (propName !=
"SourceFile")
17 LocalizationEditor locEditor = Workbench.GetModule(LocalizationEditor);
21 UpdateItem(stringTableItem, locEditor);
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))
30 LocalizationEditor locEditor = Workbench.GetModule(LocalizationEditor);
31 locEditor.BeginModify(
"LocLinkImagePlugin");
34 WBProgressDialog progress =
new WBProgressDialog(
"Processing...", locEditor);
37 array<int> indexes = {};
38 locEditor.GetSelectedRows(indexes);
40 float prevProgress, currProgress;
41 for (
int i = 0, count = indexes.Count(); i < count; i++)
43 item = items.Get(indexes[i]);
44 if (UpdateItem(item, locEditor))
47 currProgress = i / count;
48 if (currProgress - prevProgress >= 0.01)
50 progress.SetProgress(currProgress);
51 prevProgress = currProgress;
55 locEditor.EndModify();
58 Workbench.ScriptDialog(
"Generate Image Links",
string.Format(
"%1 key(s) processed, %2 linked.", indexes.Count(), linkedCount),
new SCR_LocLinkImagePluginResult());
62 protected bool UpdateItem(
BaseContainer item, LocalizationEditor locEditor)
65 item.Get(
"SourceFile", sourceFile);
66 if (!sourceFile.IsEmpty())
69 if (resource.IsValid())
80 image =
FilePath.ReplaceExtension(image, m_sExtension);
81 image = m_sPath +
FilePath.StripPath(image);
82 locEditor.ModifyProperty(item, item.GetVarIndex(
"ImageLink"), image);
92 Print(
string.Format(
"Unable to load source file '%1' of '%2'!", sourceFile,
id),
LogLevel.WARNING);
97 if (item.IsVariableSetDirectly(
"ImageLink"))
98 locEditor.ModifyProperty(item, item.GetVarIndex(
"ImageLink"),
"");
118class SCR_LocLinkImagePluginResult
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.
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