// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved.
using System.Collections.Generic;
using FlaxEditor.Content;
using FlaxEditor.CustomEditors;
using FlaxEditor.GUI;
using FlaxEngine;
using FlaxEngine.GUI;
namespace FlaxEditor.Windows.Assets
{
///
/// Editor window to view/modify asset.
///
///
///
public sealed class LocalizedStringTableWindow : AssetEditorWindowBase
{
private readonly CustomEditorPresenter _presenter;
private readonly ToolStripButton _saveButton;
private Proxy _proxy;
private class Proxy
{
[EditorOrder(0), Tooltip("The locale of the localized string table (eg. pl-PL).")]
public string Locale;
[EditorOrder(10), Tooltip("The string table. Maps the message id into the localized text. For plural messages the list contains separate items for value numbers.")]
public Dictionary Entries;
}
///
public LocalizedStringTableWindow(Editor editor, AssetItem item)
: base(editor, item)
{
// Toolstrip
_saveButton = (ToolStripButton)_toolstrip.AddButton(editor.Icons.Save32, Save).LinkTooltip("Save");
// Panel
var panel = new Panel(ScrollBars.Vertical)
{
AnchorPreset = AnchorPresets.StretchAll,
Offsets = new Margin(0, 0, _toolstrip.Bottom, 0),
Parent = this
};
// Properties
_presenter = new CustomEditorPresenter(null, "Loading...");
_presenter.Panel.Parent = panel;
_presenter.Modified += MarkAsEdited;
}
///
public override void Save()
{
if (!IsEdited)
return;
_asset.Locale = _proxy.Locale;
_asset.Entries = _proxy.Entries;
if (_asset.Save(_item.Path))
{
Editor.LogError("Cannot save asset.");
return;
}
ClearEditedFlag();
}
///
protected override void UpdateToolstrip()
{
_saveButton.Enabled = IsEdited;
base.UpdateToolstrip();
}
///
protected override void OnAssetLoaded()
{
_proxy = new Proxy
{
Locale = _asset.Locale,
Entries = _asset.Entries,
};
_presenter.Select(_proxy);
ClearEditedFlag();
base.OnAssetLoaded();
}
///
public override void OnItemReimported(ContentItem item)
{
// Refresh the properties (will get new data in OnAssetLoaded)
_presenter.Deselect();
ClearEditedFlag();
base.OnItemReimported(item);
}
}
}