String Editor Plugin – Arma Reforger
Jump to navigation
Jump to search
Lou Montana (talk | contribs) (Page creation) |
Lou Montana (talk | contribs) m (Some wiki formatting) |
||
Line 104: | Line 104: | ||
} | } | ||
//------------------------------------------------------------------------------------------------ | |||
[ButtonAttribute("OK", true)] | [ButtonAttribute("OK", true)] | ||
bool ButtonOK() | bool ButtonOK() | ||
Line 110: | Line 111: | ||
} | } | ||
//------------------------------------------------------------------------------------------------ | |||
[ButtonAttribute("Cancel")] | [ButtonAttribute("Cancel")] | ||
bool ButtonCancel() | bool ButtonCancel() |
Revision as of 16:41, 29 April 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: { "LocalizationEditor" } by wbModules: { "LocalizationEditor" }
- In the Run() method, write Workbench.Dialog("Does it?", "It works!"); (the String Editor not having a log console) and save the file
- Press Ctrl + ⇧ Shift + R to reload scripts
- 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.
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;
}
}