Fix ingame menu tab display.

This commit is contained in:
Paul Chote
2021-07-05 21:11:56 +01:00
committed by Smittytron
parent 29f4f5a0cd
commit edd3a2eb75
5 changed files with 232 additions and 95 deletions

View File

@@ -10,6 +10,7 @@
#endregion #endregion
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using OpenRA.Mods.Common.Scripting; using OpenRA.Mods.Common.Scripting;
using OpenRA.Mods.Common.Traits; using OpenRA.Mods.Common.Traits;
@@ -21,61 +22,41 @@ namespace OpenRA.Mods.Common.Widgets.Logic
class GameInfoLogic : ChromeLogic class GameInfoLogic : ChromeLogic
{ {
[ObjectCreator.UseCtor] readonly World world;
public GameInfoLogic(Widget widget, World world, IngameInfoPanel activePanel, Action<bool> hideMenu) readonly Action<bool> hideMenu;
{ readonly IObjectivesPanel iop;
var lp = world.LocalPlayer; IngameInfoPanel activePanel;
var numTabs = 0; bool hasError;
widget.IsVisible = () => activePanel != IngameInfoPanel.AutoSelect; [ObjectCreator.UseCtor]
public GameInfoLogic(Widget widget, World world, IngameInfoPanel initialPanel, Action<bool> hideMenu)
{
var panels = new Dictionary<IngameInfoPanel, (string Panel, string Label, Action<ButtonWidget, Widget> Setup)>()
{
{ IngameInfoPanel.Objectives, ("OBJECTIVES_PANEL", "Objectives", SetupObjectivesPanel) },
{ IngameInfoPanel.Map, ("MAP_PANEL", "Briefing", SetupMapPanel) },
{ IngameInfoPanel.Debug, ("DEBUG_PANEL", "Debug", SetupDebugPanel) },
{ IngameInfoPanel.Chat, ("CHAT_PANEL", "Chat", SetupChatPanel) }
};
this.world = world;
this.hideMenu = hideMenu;
activePanel = initialPanel;
var visiblePanels = new List<IngameInfoPanel>();
// Objectives/Stats tab // Objectives/Stats tab
var scriptContext = world.WorldActor.TraitOrDefault<LuaScript>(); var scriptContext = world.WorldActor.TraitOrDefault<LuaScript>();
var hasError = scriptContext != null && scriptContext.FatalErrorOccurred; hasError = scriptContext != null && scriptContext.FatalErrorOccurred;
var iop = world.WorldActor.TraitsImplementing<IObjectivesPanel>().FirstOrDefault(); iop = world.WorldActor.TraitsImplementing<IObjectivesPanel>().FirstOrDefault();
var hasObjectivesPanel = hasError || (iop != null && iop.PanelName != null);
if (hasObjectivesPanel) if (hasError || (iop != null && iop.PanelName != null))
{ visiblePanels.Add(IngameInfoPanel.Objectives);
numTabs++;
var objectivesTabButton = widget.Get<ButtonWidget>(string.Concat("BUTTON", numTabs.ToString()));
objectivesTabButton.GetText = () => "Objectives";
objectivesTabButton.IsVisible = () => numTabs > 1 && !hasError;
objectivesTabButton.OnClick = () => activePanel = IngameInfoPanel.Objectives;
objectivesTabButton.IsHighlighted = () => activePanel == IngameInfoPanel.Objectives;
var panel = hasError ? "SCRIPT_ERROR_PANEL" : iop.PanelName;
var objectivesPanel = widget.Get<ContainerWidget>("OBJECTIVES_PANEL");
objectivesPanel.IsVisible = () => activePanel == IngameInfoPanel.Objectives;
Game.LoadWidget(world, panel, objectivesPanel, new WidgetArgs()
{
{ "hideMenu", hideMenu }
});
if (activePanel == IngameInfoPanel.AutoSelect)
activePanel = IngameInfoPanel.Objectives;
}
// Briefing tab // Briefing tab
var missionData = world.WorldActor.Info.TraitInfoOrDefault<MissionDataInfo>(); var missionData = world.WorldActor.Info.TraitInfoOrDefault<MissionDataInfo>();
if (missionData != null && !string.IsNullOrEmpty(missionData.Briefing)) if (missionData != null && !string.IsNullOrEmpty(missionData.Briefing))
{ visiblePanels.Add(IngameInfoPanel.Map);
numTabs++;
var mapTabButton = widget.Get<ButtonWidget>(string.Concat("BUTTON", numTabs.ToString()));
mapTabButton.Text = "Briefing";
mapTabButton.IsVisible = () => numTabs > 1 && !hasError;
mapTabButton.OnClick = () => activePanel = IngameInfoPanel.Map;
mapTabButton.IsHighlighted = () => activePanel == IngameInfoPanel.Map;
var mapPanel = widget.Get<ContainerWidget>("MAP_PANEL");
mapPanel.IsVisible = () => activePanel == IngameInfoPanel.Map;
Game.LoadWidget(world, "MAP_PANEL", mapPanel, new WidgetArgs());
if (activePanel == IngameInfoPanel.AutoSelect)
activePanel = IngameInfoPanel.Map;
}
// Debug/Cheats tab // Debug/Cheats tab
// Can't use DeveloperMode.Enabled because there is a hardcoded hack to *always* // Can't use DeveloperMode.Enabled because there is a hardcoded hack to *always*
@@ -83,45 +64,36 @@ namespace OpenRA.Mods.Common.Widgets.Logic
// if it has been explicitly enabled // if it has been explicitly enabled
var def = world.Map.Rules.Actors[SystemActors.Player].TraitInfo<DeveloperModeInfo>().CheckboxEnabled; var def = world.Map.Rules.Actors[SystemActors.Player].TraitInfo<DeveloperModeInfo>().CheckboxEnabled;
var developerEnabled = world.LobbyInfo.GlobalSettings.OptionOrDefault("cheats", def); var developerEnabled = world.LobbyInfo.GlobalSettings.OptionOrDefault("cheats", def);
if (lp != null && developerEnabled) if (world.LocalPlayer != null && developerEnabled)
{ visiblePanels.Add(IngameInfoPanel.Debug);
numTabs++;
var debugTabButton = widget.Get<ButtonWidget>(string.Concat("BUTTON", numTabs.ToString()));
debugTabButton.Text = "Debug";
debugTabButton.IsVisible = () => numTabs > 1 && !hasError;
debugTabButton.IsDisabled = () => world.IsGameOver;
debugTabButton.OnClick = () => activePanel = IngameInfoPanel.Debug;
debugTabButton.IsHighlighted = () => activePanel == IngameInfoPanel.Debug;
var debugPanelContainer = widget.Get<ContainerWidget>("DEBUG_PANEL");
debugPanelContainer.IsVisible = () => activePanel == IngameInfoPanel.Debug;
Game.LoadWidget(world, "DEBUG_PANEL", debugPanelContainer, new WidgetArgs());
if (activePanel == IngameInfoPanel.AutoSelect)
activePanel = IngameInfoPanel.Debug;
}
if (world.LobbyInfo.NonBotClients.Count() > 1) if (world.LobbyInfo.NonBotClients.Count() > 1)
{ visiblePanels.Add(IngameInfoPanel.Chat);
numTabs++;
var chatPanelContainer = widget.Get<ContainerWidget>("CHAT_PANEL");
var chatTabButton = widget.Get<ButtonWidget>(string.Concat("BUTTON", numTabs.ToString()));
chatTabButton.Text = "Chat";
chatTabButton.IsVisible = () => numTabs > 1 && !hasError;
chatTabButton.IsHighlighted = () => activePanel == IngameInfoPanel.Chat;
chatTabButton.OnClick = () =>
{
activePanel = IngameInfoPanel.Chat;
chatPanelContainer.Get<TextFieldWidget>("CHAT_TEXTFIELD").TakeKeyboardFocus();
};
chatPanelContainer.IsVisible = () => activePanel == IngameInfoPanel.Chat; var numTabs = visiblePanels.Count;
var tabContainer = !hasError ? widget.GetOrNull($"TAB_CONTAINER_{numTabs}") : null;
if (tabContainer != null)
tabContainer.IsVisible = () => true;
Game.LoadWidget(world, "CHAT_CONTAINER", chatPanelContainer, new WidgetArgs() { { "isMenuChat", true } }); for (var i = 0; i < numTabs; i++)
{
var type = visiblePanels[i];
var info = panels[type];
var tabButton = tabContainer?.Get<ButtonWidget>($"BUTTON{i + 1}");
if (tabButton != null)
{
tabButton.Text = info.Label;
tabButton.OnClick = () => activePanel = type;
tabButton.IsHighlighted = () => activePanel == type;
}
var panelContainer = widget.Get<ContainerWidget>(info.Panel);
panelContainer.IsVisible = () => activePanel == type;
info.Setup(tabButton, panelContainer);
if (activePanel == IngameInfoPanel.AutoSelect) if (activePanel == IngameInfoPanel.AutoSelect)
chatTabButton.OnClick(); activePanel = type;
} }
// Handle empty space when tabs aren't displayed // Handle empty space when tabs aren't displayed
@@ -148,5 +120,45 @@ namespace OpenRA.Mods.Common.Widgets.Logic
if (bgNoTabs != null) if (bgNoTabs != null)
bgNoTabs.IsVisible = () => numTabs == 1; bgNoTabs.IsVisible = () => numTabs == 1;
} }
void SetupObjectivesPanel(ButtonWidget objectivesTabButton, Widget objectivesPanelContainer)
{
var panel = hasError ? "SCRIPT_ERROR_PANEL" : iop.PanelName;
Game.LoadWidget(world, panel, objectivesPanelContainer, new WidgetArgs()
{
{ "hideMenu", hideMenu }
});
}
void SetupMapPanel(ButtonWidget mapTabButton, Widget mapPanelContainer)
{
Game.LoadWidget(world, "MAP_PANEL", mapPanelContainer, new WidgetArgs());
}
void SetupDebugPanel(ButtonWidget debugTabButton, Widget debugPanelContainer)
{
if (debugTabButton != null)
debugTabButton.IsDisabled = () => world.IsGameOver;
Game.LoadWidget(world, "DEBUG_PANEL", debugPanelContainer, new WidgetArgs());
if (activePanel == IngameInfoPanel.AutoSelect)
activePanel = IngameInfoPanel.Debug;
}
void SetupChatPanel(ButtonWidget chatTabButton, Widget chatPanelContainer)
{
if (chatTabButton != null)
{
var lastOnClick = chatTabButton.OnClick;
chatTabButton.OnClick = () =>
{
lastOnClick();
chatPanelContainer.Get<TextFieldWidget>("CHAT_TEXTFIELD").TakeKeyboardFocus();
};
}
Game.LoadWidget(world, "CHAT_CONTAINER", chatPanelContainer, new WidgetArgs() { { "isMenuChat", true } });
}
} }
} }

View File

@@ -39,7 +39,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
[ObjectCreator.UseCtor] [ObjectCreator.UseCtor]
public IngameMenuLogic(Widget widget, ModData modData, World world, Action onExit, WorldRenderer worldRenderer, public IngameMenuLogic(Widget widget, ModData modData, World world, Action onExit, WorldRenderer worldRenderer,
IngameInfoPanel activePanel, Dictionary<string, MiniYaml> logicArgs) IngameInfoPanel initialPanel, Dictionary<string, MiniYaml> logicArgs)
{ {
this.modData = modData; this.modData = modData;
this.world = world; this.world = world;
@@ -103,7 +103,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
Action<bool> requestHideMenu = h => hideMenu = h; Action<bool> requestHideMenu = h => hideMenu = h;
var gameInfoPanel = Game.LoadWidget(world, "GAME_INFO_PANEL", panelRoot, new WidgetArgs() var gameInfoPanel = Game.LoadWidget(world, "GAME_INFO_PANEL", panelRoot, new WidgetArgs()
{ {
{ "activePanel", activePanel }, { "initialPanel", initialPanel },
{ "hideMenu", requestHideMenu } { "hideMenu", requestHideMenu }
}); });

View File

@@ -47,7 +47,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
blinking = false; blinking = false;
OpenMenuPanel(options, new WidgetArgs() OpenMenuPanel(options, new WidgetArgs()
{ {
{ "activePanel", IngameInfoPanel.AutoSelect } { "initialPanel", IngameInfoPanel.AutoSelect }
}); });
}; };
options.IsHighlighted = () => blinking && Game.LocalTick % 50 < 25; options.IsHighlighted = () => blinking && Game.LocalTick % 50 < 25;
@@ -79,7 +79,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
debug.IsDisabled = () => disableSystemButtons; debug.IsDisabled = () => disableSystemButtons;
debug.OnClick = () => OpenMenuPanel(debug, new WidgetArgs() debug.OnClick = () => OpenMenuPanel(debug, new WidgetArgs()
{ {
{ "activePanel", IngameInfoPanel.Debug } { "initialPanel", IngameInfoPanel.Debug }
}); });
} }

View File

@@ -20,31 +20,84 @@ Container@GAME_INFO_PANEL:
Align: Center Align: Center
Font: BigBold Font: BigBold
Contrast: true Contrast: true
Container@TAB_CONTAINER: Container@TAB_CONTAINER_2:
Visible: False
Children: Children:
Button@BUTTON1: Button@BUTTON1:
Y: 5 Y: 5
Width: 140 Width: 140
Height: 35 Height: 35
Visible: False
Button@BUTTON2: Button@BUTTON2:
X: 150 X: 150
Y: 5 Y: 5
Width: 140 Width: 140
Height: 35 Height: 35
Container@TAB_CONTAINER_3:
Visible: False Visible: False
Children:
Button@BUTTON1:
Y: 5
Width: 140
Height: 35
Button@BUTTON2:
X: 150
Y: 5
Width: 140
Height: 35
Button@BUTTON3: Button@BUTTON3:
X: 300 X: 300
Y: 5 Y: 5
Width: 140 Width: 140
Height: 35 Height: 35
Container@TAB_CONTAINER_4:
Visible: False Visible: False
Button@BUTTON4: Children:
X: 450 Button@BUTTON1:
Y: 5 Y: 5
Width: 140 Width: 121
Height: 35 Height: 35
Button@BUTTON2:
X: 131
Y: 5
Width: 120
Height: 35
Button@BUTTON3:
X: 261
Y: 5
Width: 120
Height: 35
Button@BUTTON4:
X: 391
Y: 5
Width: 121
Height: 35
Container@TAB_CONTAINER_5:
Visible: False Visible: False
Children:
Button@BUTTON1:
Y: 5
Width: 99
Height: 35
Button@BUTTON2:
X: 104
Y: 5
Width: 98
Height: 35
Button@BUTTON3:
X: 207
Y: 5
Width: 98
Height: 35
Button@BUTTON4:
X: 310
Y: 5
Width: 98
Height: 35
Button@BUTTON5:
X: 413
Y: 5
Width: 99
Height: 35
Background@BACKGROUND: Background@BACKGROUND:
Y: 39 Y: 39
Width: PARENT_RIGHT Width: PARENT_RIGHT

View File

@@ -25,38 +25,110 @@ Container@GAME_INFO_PANEL:
Height: 25 Height: 25
Align: Center Align: Center
Font: Bold Font: Bold
Container@TAB_CONTAINER: Container@TAB_CONTAINER_2:
X: (PARENT_RIGHT - WIDTH) / 2
Width: 280
Height: 25
Visible: False
Children:
Button@BUTTON1:
Y: 50
Width: 140
Height: 25
Font: Bold
Button@BUTTON2:
X: 140
Y: 50
Width: 140
Height: 25
Font: Bold
Container@TAB_CONTAINER_3:
X: (PARENT_RIGHT - WIDTH) / 2 X: (PARENT_RIGHT - WIDTH) / 2
Width: 360 Width: 360
Height: 25 Height: 25
Visible: False
Children: Children:
Button@BUTTON1: Button@BUTTON1:
Y: 50 Y: 50
Width: 120 Width: 120
Height: 25 Height: 25
Font: Bold Font: Bold
Visible: False
Button@BUTTON2: Button@BUTTON2:
X: 120 X: 120
Y: 50 Y: 50
Width: 120 Width: 120
Height: 25 Height: 25
Font: Bold Font: Bold
Visible: False
Button@BUTTON3: Button@BUTTON3:
X: 240 X: 240
Y: 50 Y: 50
Width: 120 Width: 120
Height: 25 Height: 25
Font: Bold Font: Bold
Container@TAB_CONTAINER_4:
X: (PARENT_RIGHT - WIDTH) / 2
Width: 480
Height: 25
Visible: False Visible: False
Children:
Button@BUTTON1:
Y: 50
Width: 120
Height: 25
Font: Bold
Button@BUTTON2:
X: 120
Y: 50
Width: 120
Height: 25
Font: Bold
Button@BUTTON3:
X: 240
Y: 50
Width: 120
Height: 25
Font: Bold
Button@BUTTON4: Button@BUTTON4:
X: 360 X: 360
Y: 50 Y: 50
Width: 120 Width: 120
Height: 25 Height: 25
Font: Bold Font: Bold
Container@TAB_CONTAINER_5:
X: (PARENT_RIGHT - WIDTH) / 2
Width: 480
Height: 25
Visible: False Visible: False
Children:
Button@BUTTON1:
Y: 50
Width: 96
Height: 25
Font: Bold
Button@BUTTON2:
X: 96
Y: 50
Width: 96
Height: 25
Font: Bold
Button@BUTTON3:
X: 192
Y: 50
Width: 96
Height: 25
Font: Bold
Button@BUTTON4:
X: 288
Y: 50
Width: 96
Height: 25
Font: Bold
Button@BUTTON5:
X: 384
Y: 50
Width: 96
Height: 25
Font: Bold
Container@STATS_PANEL: Container@STATS_PANEL:
Y: 65 Y: 65
Container@MAP_PANEL: Container@MAP_PANEL: