Fix switching tabs not yielding keyboard focus

And some extra polish
This commit is contained in:
Gustas
2024-08-06 13:36:10 +03:00
committed by Paul Chote
parent 87850378c7
commit e2b26754fe

View File

@@ -15,24 +15,24 @@ namespace OpenRA.Mods.Common.Widgets.Logic
{
public class MapEditorTabsLogic : ChromeLogic
{
readonly Widget widget;
enum MenuType { Select, Tiles, Layers, Actors, Tools, History }
readonly Widget panelContainer;
readonly Widget tabContainer;
readonly EditorViewportControllerWidget editor;
protected enum MenuType { Select, Tiles, Layers, Actors, Tools, History }
protected MenuType menuType = MenuType.Tiles;
readonly Widget tabContainer;
MenuType menuType = MenuType.Tiles;
MenuType lastSelectedTab = MenuType.Tiles;
[ObjectCreator.UseCtor]
public MapEditorTabsLogic(Widget widget)
{
this.widget = widget;
panelContainer = widget.Parent;
tabContainer = widget.Get("MAP_EDITOR_TAB_CONTAINER");
editor = widget.Parent.Parent.Get<EditorViewportControllerWidget>("MAP_EDITOR");
editor.DefaultBrush.UpdateSelectedTab += HandleUpdateSelectedTab;
tabContainer = widget.Get("MAP_EDITOR_TAB_CONTAINER");
SetupTab("SELECT_TAB", "SELECT_WIDGETS", MenuType.Select);
SetupTab("TILES_TAB", "TILE_WIDGETS", MenuType.Tiles);
SetupTab("OVERLAYS_TAB", "LAYER_WIDGETS", MenuType.Layers);
@@ -50,28 +50,27 @@ namespace OpenRA.Mods.Common.Widgets.Logic
void SetupTab(string buttonId, string tabId, MenuType tabType)
{
if (buttonId != null)
var tab = tabContainer.Get<ButtonWidget>(buttonId);
tab.IsHighlighted = () => menuType == tabType;
tab.OnClick = () =>
{
var tab = tabContainer.Get<ButtonWidget>(buttonId);
tab.IsHighlighted = () => menuType == tabType;
tab.OnClick = () => menuType = SelectTab(tabType);
if (tabType != MenuType.Select)
lastSelectedTab = tabType;
if (tabType == MenuType.Select)
tab.IsDisabled = () => !editor.DefaultBrush.Selection.HasSelection;
}
menuType = tabType;
var container = widget.Parent.Get<ContainerWidget>(tabId);
// Clear keyboard focus when switching tabs.
Ui.KeyboardFocusWidget = null;
};
// Selection tab is special, it can only be selected if a selection exists.
if (tabType == MenuType.Select)
tab.IsDisabled = () => !editor.DefaultBrush.Selection.HasSelection;
var container = panelContainer.Get<ContainerWidget>(tabId);
container.IsVisible = () => menuType == tabType;
}
MenuType SelectTab(MenuType newMenuType)
{
if (newMenuType != MenuType.Select)
lastSelectedTab = newMenuType;
return newMenuType;
}
void HandleUpdateSelectedTab()
{
var hasSelection = editor.DefaultBrush.Selection.HasSelection;