// Copyright (c) 2012-2024 Wojciech Figat. All rights reserved.
using System;
using System.Collections.Generic;
using FlaxEditor.CustomEditors;
using FlaxEditor.GUI;
using FlaxEditor.GUI.Tabs;
using FlaxEditor.Options;
using FlaxEngine;
using FlaxEngine.GUI;
using FlaxEngine.Json;
using FlaxEngine.Utilities;
namespace FlaxEditor.Windows
{
///
/// Editor window for changing the options.
///
///
public sealed class EditorOptionsWindow : EditorWindow
{
private bool _isDataDirty;
private Tabs _tabs;
private EditorOptions _options;
private ToolStripButton _saveButton;
private readonly Undo _undo;
private readonly List _customTabs = new List();
///
/// Initializes a new instance of the class.
///
/// The editor.
public EditorOptionsWindow(Editor editor)
: base(editor, true, ScrollBars.None)
{
Title = "Editor Options";
// Undo
_undo = new Undo();
_undo.UndoDone += OnUndoRedo;
_undo.RedoDone += OnUndoRedo;
_undo.ActionDone += OnUndoRedo;
var toolstrip = new ToolStrip
{
Parent = this
};
_saveButton = (ToolStripButton)toolstrip.AddButton(editor.Icons.Save64, SaveData).LinkTooltip("Save");
_saveButton.Enabled = false;
_tabs = new Tabs
{
Orientation = Orientation.Vertical,
AnchorPreset = AnchorPresets.StretchAll,
Offsets = new Margin(0, 0, toolstrip.Bottom, 0),
TabsSize = new Float2(120, 32),
UseScroll = true,
Parent = this
};
CreateTab("General", () => _options.General);
CreateTab("Interface", () => _options.Interface);
CreateTab("Input", () => _options.Input);
CreateTab("Viewport", () => _options.Viewport);
CreateTab("Visual", () => _options.Visual);
CreateTab("Source Code", () => _options.SourceCode);
CreateTab("Theme", () => _options.Theme);
// Setup input actions
InputActions.Add(options => options.Undo, _undo.PerformUndo);
InputActions.Add(options => options.Redo, _undo.PerformRedo);
InputActions.Add(options => options.Save, SaveData);
_tabs.SelectedTabIndex = 0;
}
private void OnUndoRedo(IUndoAction action)
{
MarkAsEdited();
}
private Tab CreateTab(string name, Func