Fix switching tabs not yielding keyboard focus
And some extra polish
This commit is contained in:
@@ -15,24 +15,24 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
{
|
{
|
||||||
public class MapEditorTabsLogic : ChromeLogic
|
public class MapEditorTabsLogic : ChromeLogic
|
||||||
{
|
{
|
||||||
readonly Widget widget;
|
enum MenuType { Select, Tiles, Layers, Actors, Tools, History }
|
||||||
|
|
||||||
|
readonly Widget panelContainer;
|
||||||
|
readonly Widget tabContainer;
|
||||||
readonly EditorViewportControllerWidget editor;
|
readonly EditorViewportControllerWidget editor;
|
||||||
|
|
||||||
protected enum MenuType { Select, Tiles, Layers, Actors, Tools, History }
|
MenuType menuType = MenuType.Tiles;
|
||||||
protected MenuType menuType = MenuType.Tiles;
|
|
||||||
readonly Widget tabContainer;
|
|
||||||
|
|
||||||
MenuType lastSelectedTab = MenuType.Tiles;
|
MenuType lastSelectedTab = MenuType.Tiles;
|
||||||
|
|
||||||
[ObjectCreator.UseCtor]
|
[ObjectCreator.UseCtor]
|
||||||
public MapEditorTabsLogic(Widget widget)
|
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 = widget.Parent.Parent.Get<EditorViewportControllerWidget>("MAP_EDITOR");
|
||||||
editor.DefaultBrush.UpdateSelectedTab += HandleUpdateSelectedTab;
|
editor.DefaultBrush.UpdateSelectedTab += HandleUpdateSelectedTab;
|
||||||
|
|
||||||
tabContainer = widget.Get("MAP_EDITOR_TAB_CONTAINER");
|
|
||||||
|
|
||||||
SetupTab("SELECT_TAB", "SELECT_WIDGETS", MenuType.Select);
|
SetupTab("SELECT_TAB", "SELECT_WIDGETS", MenuType.Select);
|
||||||
SetupTab("TILES_TAB", "TILE_WIDGETS", MenuType.Tiles);
|
SetupTab("TILES_TAB", "TILE_WIDGETS", MenuType.Tiles);
|
||||||
SetupTab("OVERLAYS_TAB", "LAYER_WIDGETS", MenuType.Layers);
|
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)
|
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);
|
if (tabType != MenuType.Select)
|
||||||
tab.IsHighlighted = () => menuType == tabType;
|
lastSelectedTab = tabType;
|
||||||
tab.OnClick = () => menuType = SelectTab(tabType);
|
|
||||||
|
|
||||||
if (tabType == MenuType.Select)
|
menuType = tabType;
|
||||||
tab.IsDisabled = () => !editor.DefaultBrush.Selection.HasSelection;
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
container.IsVisible = () => menuType == tabType;
|
||||||
}
|
}
|
||||||
|
|
||||||
MenuType SelectTab(MenuType newMenuType)
|
|
||||||
{
|
|
||||||
if (newMenuType != MenuType.Select)
|
|
||||||
lastSelectedTab = newMenuType;
|
|
||||||
|
|
||||||
return newMenuType;
|
|
||||||
}
|
|
||||||
|
|
||||||
void HandleUpdateSelectedTab()
|
void HandleUpdateSelectedTab()
|
||||||
{
|
{
|
||||||
var hasSelection = editor.DefaultBrush.Selection.HasSelection;
|
var hasSelection = editor.DefaultBrush.Selection.HasSelection;
|
||||||
|
|||||||
Reference in New Issue
Block a user