String Editor Plugin – Arma Reforger
Jump to navigation
Jump to search
Lou Montana (talk | contribs) (Add LocalizationEditorPlugin info) |
Lou Montana (talk | contribs) m (Text replacement - "[[OFPEC_tags" to "[[Scripting Tags") |
||
Line 8: | Line 8: | ||
* Open [[Arma_Reforger:Script_Editor|Script Editor]] | * Open [[Arma_Reforger:Script_Editor|Script Editor]] | ||
* In an addon, create a new script in {{hl|WorkbenchGame/LocalizationEditor}} - name it {{hl|[[ | * In an addon, create a new script in {{hl|WorkbenchGame/LocalizationEditor}} - name it {{hl|[[Scripting Tags|TAG_]]TutorialPlugin.c}} (must end with {{hl|Plugin}} by convention) | ||
* Double-click the file to open it | * Double-click the file to open it | ||
* Press {{Controls|Ctrl|T}} to use the {{Link|Arma Reforger:Script Editor: Fill From Template Plugin|Script Template plugin}} | * Press {{Controls|Ctrl|T}} to use the {{Link|Arma Reforger:Script Editor: Fill From Template Plugin|Script Template plugin}} | ||
Line 17: | Line 17: | ||
* In the <enforce inline>Run()</enforce> method, write <enforce inline>Workbench.Dialog("Does it?", "It works!");</enforce> (the String Editor not having a log console) and save the file | * In the <enforce inline>Run()</enforce> method, write <enforce inline>Workbench.Dialog("Does it?", "It works!");</enforce> (the String Editor not having a log console) and save the file | ||
* Reload Workbench scripts via '''Reload WB Scripts''' option located in '''Plugins → Settings''' (default shortcut: {{Controls|Ctrl|Shift|R}}) | * Reload Workbench scripts via '''Reload WB Scripts''' option located in '''Plugins → Settings''' (default shortcut: {{Controls|Ctrl|Shift|R}}) | ||
* The {{hl|[[ | * The {{hl|[[Scripting Tags|TAG_]]TutorialPlugin}} plugin should appear in the String Editor's Plugins list, available in the top bar - click on the plugin entry | ||
* The "It works!" modal appears on screen. | * The "It works!" modal appears on screen. | ||
Latest revision as of 12:01, 2 October 2024
This tutorial teaches how to create a String Editor-specific plugin.
Setup
- Open Script Editor
- In an addon, create a new script in WorkbenchGame
/LocalizationEditor - name it TAG_TutorialPlugin.c (must end with Plugin by convention) - Double-click the file to open it
- Press Ctrl + T to use the Script Template plugin
- In its window, select "Class Type: WorkbenchPlugin", set the parent class to LocalizationEditorPlugin and leave the other fields blank/default
- A Workbench plugin skeleton is inserted.
- In the WorkbenchPluginAttribute, replace wbModules: { "ResourceManager" } by wbModules: { "LocalizationEditor" }
- Make the plugin inherit from LocalizationEditorPlugin instead of WorkbenchPlugin
- In the Run() method, write Workbench.Dialog("Does it?", "It works!"); (the String Editor not having a log console) and save the file
- Reload Workbench scripts via Reload WB Scripts option located in Plugins → Settings (default shortcut: Ctrl + ⇧ Shift + R)
- The TAG_TutorialPlugin plugin should appear in the String Editor's Plugins list, available in the top bar - click on the plugin entry
- The "It works!" modal appears on screen.
LocalizationEditorPlugin API
LocalizationEditor Module API
The String Editor API allows In the below code:
- the GetTable method is used to grab the table as a BaseContainerList
- the OnSelectionChanged method is used to Print the currently selected row IDs.
[WorkbenchPluginAttribute(name: "Tutorial Plugin", shortcut: "Ctrl+Shift+H", wbModules: { "LocalizationEditor" }, awesomeFontCode: 0xF188)]
class TAG_TutorialPlugin : LocalizationEditorPlugin
{
[Attribute(defvalue: "", desc: "If no username is provided, the Windows username will be used")]
protected string m_sAuthorName;
protected ref array<ResourceName> m_aResourceNames;
protected ref array<string> m_aFilePaths;
//------------------------------------------------------------------------------------------------
override void Run()
{
LocalizationEditor stringEditor = Workbench.GetModule(LocalizationEditor);
array<int> rows = {};
stringEditor.GetSelectedRows(rows);
if (rows.IsEmpty())
{
Workbench.Dialog("Input Error", "Please enter a valid author name");
return;
}
BaseContainer stringTable = stringEditor.GetTable();
if (!stringTable)
{
Print("No string table opened", LogLevel.WARNING);
return;
}
BaseContainerList items = stringTable.GetObjectArray("Items"); // entries - cannot be empty since rows are selected
if (Workbench.ScriptDialog("Author", "Please input the wanted author's name for these entries.", this) == 0)
return; // on Cancel
m_sAuthorName.Trim();
if (m_sAuthorName.IsEmpty())
{
Workbench.GetUserName(m_sAuthorName);
if (m_sAuthorName.IsEmpty())
{
Workbench.Dialog("Input Error", "Please enter a valid author name");
return;
}
}
BaseContainer item;
string itemId, itemAuthor;
stringEditor.BeginModify("RowEdit"); // prepare the Undo operation
foreach (int row : rows)
{
item = items.Get(row);
item.Get("Id", itemId);
item.Get("Author", itemAuthor);
Print("Changing #" + itemId + "'s Author from '" + itemAuthor + "' to '" + m_sAuthorName + "'", LogLevel.NORMAL); // log for manual Undo if needed
stringEditor.ModifyProperty(item, item.GetVarIndex("Author"), m_sAuthorName);
}
stringEditor.EndModify(); // wrap the Undo operation
// stringEditor.Save(); // we allow the user to save, let's not override data ourselves
}
//------------------------------------------------------------------------------------------------
override void OnSelectionChanged()
{
LocalizationEditor stringEditor = Workbench.GetModule(LocalizationEditor);
array<int> rows = {};
stringEditor.GetSelectedRows(rows);
Print("Selected rows: " + rows, LogLevel.NORMAL);
}
//------------------------------------------------------------------------------------------------
[ButtonAttribute("OK", true)]
bool ButtonOK()
{
return true;
}
//------------------------------------------------------------------------------------------------
[ButtonAttribute("Cancel")]
bool ButtonCancel()
{
return false;
}
}