Tools: one toolbar button for all tools, styled tool windows
- ToolBox: instead of a text button per tool (which did not fit the 60x60 icon row and overlapped the icons) the HUD gets one "tools" icon button with a popup listing every visible tool, sorted by localized name. - ToolWindow: chrome that follows the UI style guide (title on the left, close on the right, drag-to-move, double-click/maximize, edge resize), a status bar with buffered status/hint text, dirty-state confirmation and keyboard shortcuts (Ctrl+S in _Input, other keys only when no focused control consumed them). - ToolTheme: denser copy of the game theme for editor toolbars; ToolStatusKind: status bar message kinds. - New tools icon and the tool window texts (unsaved changes, maximize, close, menu title) in en/ru.
This commit is contained in:
1 parent
6884cd5374
commit
b2a0f1c10a
7 files changed
+430
-151
No files matched your search
+33
-16
@@ -89,29 +89,46 @@ namespace Cthangover.Mods.Interface.Tool
|
||||
return button;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds one "tools" toolbar button whose popup lists every visible
|
||||
/// <see cref="IToolBoxButton"/>. Tools used to get a text button each,
|
||||
/// which did not fit the 60×60 icon row and overlapped its icons; a
|
||||
/// single icon keeps the HUD row uniform no matter how many tools are
|
||||
/// installed. Nothing is added when no tool button is visible.
|
||||
/// </summary>
|
||||
private void AddToolButtons(HBoxContainer container)
|
||||
{
|
||||
if (container == null)
|
||||
return;
|
||||
|
||||
foreach (var buttonDef in ToolBoxButtonFactory.Instance.GetVisible())
|
||||
var visible = new List<IToolBoxButton>(ToolBoxButtonFactory.Instance.GetVisible());
|
||||
if (visible.Count == 0)
|
||||
return;
|
||||
|
||||
visible.Sort((a, b) => string.Compare(
|
||||
TranslationServer.Translate(a.LocaleKey), TranslationServer.Translate(b.LocaleKey),
|
||||
System.StringComparison.CurrentCulture));
|
||||
|
||||
var btn = CreateToolbarButton(TranslationServer.Translate("tools/menu_title"), UIIconFactory.Instance.Get("tools"));
|
||||
var menu = new PopupMenu { Theme = ToolTheme.Get() };
|
||||
foreach (var buttonDef in visible)
|
||||
menu.AddItem(TranslationServer.Translate(buttonDef.LocaleKey));
|
||||
menu.IndexPressed += index => OpenTool(visible[(int)index].ToolId);
|
||||
btn.AddChild(menu);
|
||||
btn.Pressed += () =>
|
||||
{
|
||||
var toolId = buttonDef.ToolId;
|
||||
var title = TranslationServer.Translate(buttonDef.LocaleKey);
|
||||
var rect = btn.GetGlobalRect();
|
||||
menu.Position = new Vector2I((int)rect.Position.X, (int)rect.End.Y + UiTokens.Space1);
|
||||
menu.Popup();
|
||||
};
|
||||
container.AddChild(btn);
|
||||
}
|
||||
|
||||
Texture2D icon = null;
|
||||
if (!string.IsNullOrEmpty(buttonDef.IconPath) && ResourceLoader.Exists(buttonDef.IconPath))
|
||||
icon = ResourceLoader.Load<Texture2D>(buttonDef.IconPath);
|
||||
|
||||
var btn = CreateToolbarButton(title, icon);
|
||||
btn.Pressed += () =>
|
||||
{
|
||||
var tool = ToolFactory.Instance.Get(toolId);
|
||||
if (tool != null)
|
||||
ToolWindow.ShowWindow(tool.CreateWindow());
|
||||
};
|
||||
container.AddChild(btn);
|
||||
}
|
||||
private static void OpenTool(string toolId)
|
||||
{
|
||||
var tool = ToolFactory.Instance.Get(toolId);
|
||||
if (tool != null)
|
||||
ToolWindow.ShowWindow(tool.CreateWindow());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in new issue
Block a user