Add a chat tab to end-game window

Fixes #6422
This commit is contained in:
Oliver Brakmann
2014-09-14 19:43:46 +02:00
parent 5fb2475b3c
commit 928ee9c625
7 changed files with 392 additions and 90 deletions

View File

@@ -45,12 +45,16 @@ namespace OpenRA.Mods.D2k.Widgets.Logic
{ {
Game.LoadWidget(world, "CHAT_PANEL", gameRoot, new WidgetArgs()); Game.LoadWidget(world, "CHAT_PANEL", gameRoot, new WidgetArgs());
Action ShowLeaveRestartDialog = () => var showleaveMapWidget = false;
var leaveMapWidget = Game.LoadWidget(world, "LEAVE_MAP_WIDGET", Ui.Root, new WidgetArgs());
leaveMapWidget.IsVisible = () => showleaveMapWidget;
Action ShowLeaveMapWidget = () =>
{ {
gameRoot.RemoveChildren(); gameRoot.RemoveChildren();
Game.LoadWidget(world, "LEAVE_MAP_WIDGET", Ui.Root, new WidgetArgs()); showleaveMapWidget = true;
}; };
world.GameOver += ShowLeaveRestartDialog; world.GameOver += ShowLeaveMapWidget;
} }
void InitObserverWidgets() void InitObserverWidgets()

View File

@@ -8,7 +8,9 @@
*/ */
#endregion #endregion
using System;
using System.Linq; using System.Linq;
using System.Drawing;
using OpenRA.Traits; using OpenRA.Traits;
using OpenRA.Widgets; using OpenRA.Widgets;
@@ -16,25 +18,61 @@ namespace OpenRA.Mods.RA.Widgets
{ {
class LeaveMapLogic class LeaveMapLogic
{ {
enum Tab { Objectives, Chat };
Tab currentTab;
bool newChatMessage;
[ObjectCreator.UseCtor] [ObjectCreator.UseCtor]
public LeaveMapLogic(Widget widget, World world) public LeaveMapLogic(Widget widget, World world)
{ {
widget.Get<LabelWidget>("VERSION_LABEL").Text = Game.modData.Manifest.Mod.Version; widget.Get<LabelWidget>("VERSION_LABEL").Text = Game.modData.Manifest.Mod.Version;
var panelName = "LEAVE_MAP_SIMPLE";
var iop = world.WorldActor.TraitsImplementing<IObjectivesPanel>().FirstOrDefault();
var showObjectives = iop != null && iop.PanelName != null && world.LocalPlayer != null;
if (showObjectives)
panelName = "LEAVE_MAP_FULL";
var showStats = false; var showStats = false;
var iop = world.WorldActor.TraitsImplementing<IObjectivesPanel>().FirstOrDefault();
var isMultiplayer = !world.LobbyInfo.IsSinglePlayer && !world.IsReplay;
var hasObjectives = iop != null && iop.PanelName != null && world.LocalPlayer != null;
var showTabs = hasObjectives && isMultiplayer;
currentTab = hasObjectives ? Tab.Objectives : Tab.Chat;
var panelName = hasObjectives || isMultiplayer ? "LEAVE_MAP_FULL" : "LEAVE_MAP_SIMPLE";
var dialog = widget.Get<ContainerWidget>(panelName); var dialog = widget.Get<ContainerWidget>(panelName);
dialog.IsVisible = () => !showStats; dialog.IsVisible = () => !showStats;
widget.IsVisible = () => Ui.CurrentWindow() == null; widget.IsVisible = () => Ui.CurrentWindow() == null;
if (hasObjectives || isMultiplayer)
{
var titleText = dialog.Get<LabelWidget>("GAME_ENDED_LABEL");
var titleTextNoTabs = dialog.GetOrNull<LabelWidget>("GAME_ENDED_LABEL_NO_TABS");
titleText.IsVisible = () => showTabs || (!showTabs && titleTextNoTabs == null);
if (titleTextNoTabs != null)
titleTextNoTabs.IsVisible = () => !showTabs;
var bg = dialog.Get<BackgroundWidget>("LEAVE_MAP_BG");
var bgNoTabs = dialog.GetOrNull<BackgroundWidget>("LEAVE_MAP_BG_NO_TABS");
bg.IsVisible = () => showTabs || (!showTabs && bgNoTabs == null);
if (bgNoTabs != null)
bgNoTabs.IsVisible = () => !showTabs;
var objButton = dialog.Get<ButtonWidget>("OBJECTIVES_BUTTON");
objButton.IsVisible = () => showTabs;
objButton.OnClick = () => currentTab = Tab.Objectives;
objButton.IsHighlighted = () => currentTab == Tab.Objectives;
var chatButton = dialog.Get<ButtonWidget>("CHAT_BUTTON");
chatButton.IsVisible = () => showTabs;
chatButton.OnClick = () =>
{
currentTab = Tab.Chat;
newChatMessage = false;
};
chatButton.IsHighlighted = () => currentTab == Tab.Chat || (newChatMessage && Game.LocalTick % 50 < 25);
Game.BeforeGameStart += UnregisterChatNotification;
Game.AddChatLine += NotifyNewChatMessage;
}
var statsButton = dialog.Get<ButtonWidget>("STATS_BUTTON"); var statsButton = dialog.Get<ButtonWidget>("STATS_BUTTON");
statsButton.OnClick = () => statsButton.OnClick = () =>
{ {
@@ -69,11 +107,30 @@ namespace OpenRA.Mods.RA.Widgets
}); });
}; };
if (showObjectives) if (hasObjectives)
{ {
var objectivesContainer = dialog.Get<ContainerWidget>("OBJECTIVES"); var objectivesContainer = dialog.Get<ContainerWidget>("OBJECTIVES_PANEL");
Game.LoadWidget(world, iop.PanelName, objectivesContainer, new WidgetArgs()); Game.LoadWidget(world, iop.PanelName, objectivesContainer, new WidgetArgs());
objectivesContainer.IsVisible = () => currentTab == Tab.Objectives;
} }
if (isMultiplayer)
{
var chatContainer = dialog.Get<ContainerWidget>("DIALOG_CHAT_PANEL");
chatContainer.IsVisible = () => currentTab == Tab.Chat;
}
}
void NotifyNewChatMessage(Color c, string s1, string s2)
{
if (currentTab != Tab.Chat)
newChatMessage = true;
}
void UnregisterChatNotification()
{
Game.AddChatLine -= NotifyNewChatMessage;
Game.BeforeGameStart -= UnregisterChatNotification;
} }
} }
} }

View File

@@ -43,12 +43,16 @@ namespace OpenRA.Mods.RA.Widgets.Logic
Game.LoadWidget(world, "CHAT_PANEL", ingameRoot, new WidgetArgs()); Game.LoadWidget(world, "CHAT_PANEL", ingameRoot, new WidgetArgs());
Action ShowLeaveRestartDialog = () => var showLeaveMapWidget = false;
var leaveMapWidget = Game.LoadWidget(world, "LEAVE_MAP_WIDGET", Ui.Root, new WidgetArgs());
leaveMapWidget.IsVisible = () => showLeaveMapWidget;
Action ShowLeaveMapWidget = () =>
{ {
ingameRoot.RemoveChildren(); ingameRoot.RemoveChildren();
Game.LoadWidget(world, "LEAVE_MAP_WIDGET", Ui.Root, new WidgetArgs()); showLeaveMapWidget = true;
}; };
world.GameOver += ShowLeaveRestartDialog; world.GameOver += ShowLeaveMapWidget;
} }
} }
} }

View File

@@ -33,6 +33,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
readonly TabCompletionLogic tabCompletion = new TabCompletionLogic(); readonly TabCompletionLogic tabCompletion = new TabCompletionLogic();
bool teamChat; bool teamChat;
bool inDialog;
[ObjectCreator.UseCtor] [ObjectCreator.UseCtor]
public IngameChatLogic(Widget widget, OrderManager orderManager, World world, Ruleset modRules) public IngameChatLogic(Widget widget, OrderManager orderManager, World world, Ruleset modRules)
@@ -49,9 +50,14 @@ namespace OpenRA.Mods.RA.Widgets.Logic
tabCompletion.Names = orderManager.LobbyInfo.Clients.Select(c => c.Name).Distinct().ToList(); tabCompletion.Names = orderManager.LobbyInfo.Clients.Select(c => c.Name).Distinct().ToList();
var chatPanel = (ContainerWidget)widget; var chatPanel = (ContainerWidget)widget;
chatOverlay = chatPanel.Get<ContainerWidget>("CHAT_OVERLAY"); chatOverlay = chatPanel.GetOrNull<ContainerWidget>("CHAT_OVERLAY");
chatOverlayDisplay = chatOverlay.Get<ChatDisplayWidget>("CHAT_DISPLAY"); if (chatOverlay != null)
chatOverlay.Visible = false; {
chatOverlayDisplay = chatOverlay.Get<ChatDisplayWidget>("CHAT_DISPLAY");
chatOverlay.Visible = false;
}
else
inDialog = true;
chatChrome = chatPanel.Get<ContainerWidget>("CHAT_CHROME"); chatChrome = chatPanel.Get<ContainerWidget>("CHAT_CHROME");
chatChrome.Visible = true; chatChrome.Visible = true;
@@ -82,6 +88,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
trait.OnChat(orderManager.LocalClient.Name, text); trait.OnChat(orderManager.LocalClient.Name, text);
} }
chatText.Text = "";
CloseChat(); CloseChat();
return true; return true;
}; };
@@ -94,26 +101,29 @@ namespace OpenRA.Mods.RA.Widgets.Logic
chatText.OnEscKey = () => { CloseChat(); return true; }; chatText.OnEscKey = () => { CloseChat(); return true; };
var chatClose = chatChrome.Get<ButtonWidget>("CHAT_CLOSE"); if (!inDialog)
chatClose.OnClick += CloseChat;
chatPanel.OnKeyPress = e =>
{ {
if (e.Event == KeyInputEvent.Up) var chatClose = chatChrome.Get<ButtonWidget>("CHAT_CLOSE");
return false; chatClose.OnClick += CloseChat;
if (!chatChrome.IsVisible() && (e.Key == Keycode.RETURN || e.Key == Keycode.KP_ENTER)) chatPanel.OnKeyPress = e =>
{ {
OpenChat(); if (e.Event == KeyInputEvent.Up)
return true; return false;
}
return false; if (!chatChrome.IsVisible() && (e.Key == Keycode.RETURN || e.Key == Keycode.KP_ENTER))
}; {
OpenChat();
return true;
}
return false;
};
}
chatScrollPanel = chatChrome.Get<ScrollPanelWidget>("CHAT_SCROLLPANEL"); chatScrollPanel = chatChrome.Get<ScrollPanelWidget>("CHAT_SCROLLPANEL");
chatTemplate = chatScrollPanel.Get<ContainerWidget>("CHAT_TEMPLATE"); chatTemplate = chatScrollPanel.Get<ContainerWidget>("CHAT_TEMPLATE");
chatScrollPanel.RemoveChildren(); chatScrollPanel.RemoveChildren();
chatScrollPanel.ScrollToBottom();
Game.AddChatLine += AddChatLine; Game.AddChatLine += AddChatLine;
Game.BeforeGameStart += UnregisterEvents; Game.BeforeGameStart += UnregisterEvents;
@@ -130,22 +140,26 @@ namespace OpenRA.Mods.RA.Widgets.Logic
public void OpenChat() public void OpenChat()
{ {
chatText.Text = ""; chatText.Text = "";
chatOverlay.Visible = false;
chatChrome.Visible = true; chatChrome.Visible = true;
chatScrollPanel.ScrollToBottom(); chatScrollPanel.ScrollToBottom();
chatText.TakeKeyboardFocus(); chatText.TakeKeyboardFocus();
if (!inDialog)
chatOverlay.Visible = false;
} }
public void CloseChat() public void CloseChat()
{ {
chatOverlay.Visible = true; if (inDialog)
return;
chatChrome.Visible = false; chatChrome.Visible = false;
chatText.YieldKeyboardFocus(); chatText.YieldKeyboardFocus();
chatOverlay.Visible = true;
} }
public void AddChatLine(Color c, string from, string text) public void AddChatLine(Color c, string from, string text)
{ {
chatOverlayDisplay.AddLine(c, from, text); if (!inDialog)
chatOverlayDisplay.AddLine(c, from, text);
var template = chatTemplate.Clone(); var template = chatTemplate.Clone();
var nameLabel = template.Get<LabelWidget>("NAME"); var nameLabel = template.Get<LabelWidget>("NAME");

View File

@@ -69,28 +69,97 @@ Container@LEAVE_MAP_WIDGET:
Width: PARENT_RIGHT Width: PARENT_RIGHT
Height: PARENT_BOTTOM - 35 Height: PARENT_BOTTOM - 35
Background: panel-black Background: panel-black
Label@GAME_ENDED_LABEL:
X: 0
Y: 0 - 60
Width: PARENT_RIGHT
Font: BigBold
Align: Center
Text: The game has ended
Contrast: True
Label@GAME_ENDED_LABEL_NO_TABS:
X: 0
Y: 0 - 25
Width: PARENT_RIGHT
Font: BigBold
Align: Center
Text: The game has ended
Contrast: True
Container@TAB_CONTAINER:
Width: 290
Children: Children:
Label@GAME_ENDED_LABEL: Button@OBJECTIVES_BUTTON:
X: 0 Y: 1 - HEIGHT
Y: 0 - 25
Width: PARENT_RIGHT
Font: BigBold
Align: Center
Text: The game has ended
Contrast: True
Button@LEAVE_BUTTON:
X: 0
Y: PARENT_BOTTOM - 1
Width: 140 Width: 140
Height: 35 Height: 35
Font: Bold Font: Bold
Text: Leave Text: Objectives
Button@STATS_BUTTON: Button@CHAT_BUTTON:
X: 150 X: 150
Y: PARENT_BOTTOM - 1 Y: 1 - HEIGHT
Width: 140 Width: 140
Height: 35 Height: 35
Font: Bold Font: Bold
Text: Statistics Text: Chat
Container@OBJECTIVES: Button@LEAVE_BUTTON:
X: 0
Y: PARENT_BOTTOM - 36
Width: 140
Height: 35
Font: Bold
Text: Leave
Button@STATS_BUTTON:
X: 150
Y: PARENT_BOTTOM - 36
Width: 140
Height: 35
Font: Bold
Text: Statistics
Container@OBJECTIVES_PANEL:
Container@DIALOG_CHAT_PANEL:
X: 15
Y: 15
Width: PARENT_RIGHT - 30
Height: 365
Logic: IngameChatLogic
Visible: False
Children:
Container@CHAT_CHROME:
Width: PARENT_RIGHT
Height: PARENT_BOTTOM
Children:
Button@CHAT_MODE:
Y: PARENT_BOTTOM - HEIGHT - 20
Width: 50
Height: 25
Text: Team
Font: Bold
TextField@CHAT_TEXTFIELD:
X: 55
Y: PARENT_BOTTOM - HEIGHT - 20
Width: 427
Height: 25
ScrollPanel@CHAT_SCROLLPANEL:
Y: PARENT_BOTTOM - HEIGHT - 50
Width: 482
Height: 315
ItemSpacing: 4
Align: Bottom
Children:
Container@CHAT_TEMPLATE:
X: 2
Width: PARENT_RIGHT-27
Height: 16
Children:
Label@NAME:
X: 3
Width: 50
Height: 15
VAlign: Top
Label@TEXT:
X: 12
Width: PARENT_RIGHT - 17
Height: 15
WordWrap: true
VAlign: Top

View File

@@ -56,35 +56,112 @@ Container@LEAVE_MAP_WIDGET:
X: (WINDOW_RIGHT - WIDTH) / 2 X: (WINDOW_RIGHT - WIDTH) / 2
Y: (WINDOW_BOTTOM - HEIGHT) / 2 Y: (WINDOW_BOTTOM - HEIGHT) / 2
Width: 522 Width: 522
Height: 470 Height: 495
Visible: False Visible: False
Children: Children:
Background@LEAVE_MAP_BG: Background@LEAVE_MAP_BG:
Width: PARENT_RIGHT Width: PARENT_RIGHT
Height: PARENT_BOTTOM Height: PARENT_BOTTOM
Visible: False
Background@LEAVE_MAP_BG_NO_TABS:
Y: 25
Width: PARENT_RIGHT
Height: PARENT_BOTTOM - 25
Visible: False
Label@GAME_ENDED_LABEL:
X: 20
Y: 20
Width: PARENT_RIGHT - 40
Height: 25
Font: Bold
Align: Center
Text: The game has ended
Label@GAME_ENDED_LABEL_NO_TABS:
X: 20
Y: 45
Width: PARENT_RIGHT - 40
Height: 25
Font: Bold
Align: Center
Text: The game has ended
Container@TAB_CONTAINER:
X: (PARENT_RIGHT - WIDTH) / 2
Width: 240
Height: 25
Children: Children:
Label@GAME_ENDED_LABEL: Button@OBJECTIVES_BUTTON:
X: 20 X: 0
Y: 20 Y: 50
Width: PARENT_RIGHT - 40
Height: 25
Font: Bold
Align: Center
Text: The game has ended
Button@STATS_BUTTON:
X: PARENT_RIGHT - 2 * (WIDTH + 20)
Y: PARENT_BOTTOM - 45
Width: 120 Width: 120
Height: 25 Height: 25
Font: Bold Font: Bold
Text: Statistics Text: Objectives
Button@LEAVE_BUTTON: Button@CHAT_BUTTON:
X: PARENT_RIGHT - WIDTH - 20 X: 120
Y: PARENT_BOTTOM - 45 Y: 50
Width: 120 Width: 120
Height: 25 Height: 25
Font: Bold Font: Bold
Text: Leave Text: Chat
Container@OBJECTIVES: Button@STATS_BUTTON:
Y: 40 X: PARENT_RIGHT - 2 * (WIDTH + 20)
Y: PARENT_BOTTOM - 45
Width: 120
Height: 25
Font: Bold
Text: Statistics
Button@LEAVE_BUTTON:
X: PARENT_RIGHT - WIDTH - 20
Y: PARENT_BOTTOM - 45
Width: 120
Height: 25
Font: Bold
Text: Leave
Container@OBJECTIVES_PANEL:
Y: 65
Container@DIALOG_CHAT_PANEL:
X: 20
Y: 65
Width: PARENT_RIGHT - 40
Height: 370
Logic: IngameChatLogic
Visible: False
Children:
Container@CHAT_CHROME:
Width: PARENT_RIGHT
Height: PARENT_BOTTOM
Children:
Button@CHAT_MODE:
Y: PARENT_BOTTOM - HEIGHT
Width: 50
Height: 25
Text: Team
Font: Bold
TextField@CHAT_TEXTFIELD:
X: 55
Y: PARENT_BOTTOM - HEIGHT
Width: 427
Height: 25
ScrollPanel@CHAT_SCROLLPANEL:
Y: PARENT_BOTTOM - HEIGHT - 30
Width: 482
Height: 315
ItemSpacing: 4
Align: Bottom
Children:
Container@CHAT_TEMPLATE:
X: 2
Width: PARENT_RIGHT-27
Height: 16
Children:
Label@NAME:
X: 3
Width: 50
Height: 15
VAlign: Top
Label@TEXT:
X: 12
Width: PARENT_RIGHT - 17
Height: 15
WordWrap: true
VAlign: Top

View File

@@ -63,35 +63,112 @@ Container@LEAVE_MAP_WIDGET:
X: (WINDOW_RIGHT - WIDTH) / 2 X: (WINDOW_RIGHT - WIDTH) / 2
Y: (WINDOW_BOTTOM - HEIGHT) / 2 Y: (WINDOW_BOTTOM - HEIGHT) / 2
Width: 522 Width: 522
Height: 470 Height: 510
Visible: False Visible: False
Children: Children:
Background@LEAVE_MAP_BG: Background@LEAVE_MAP_BG:
Width: PARENT_RIGHT Width: PARENT_RIGHT
Height: PARENT_BOTTOM Height: PARENT_BOTTOM
Visible: False
Background@LEAVE_MAP_BG_NO_TABS:
Y: 25
Width: PARENT_RIGHT
Height: PARENT_BOTTOM - 25
Visible: False
Label@GAME_ENDED_LABEL:
X: 20
Y: 20
Width: PARENT_RIGHT - 40
Height: 25
Font: Bold
Align: Center
Text: The game has ended
Label@GAME_ENDED_LABEL_NO_TABS:
X: 20
Y: 45
Width: PARENT_RIGHT - 40
Height: 25
Font: Bold
Align: Center
Text: The game has ended
Container@TAB_CONTAINER:
X: (PARENT_RIGHT - WIDTH) / 2
Width: 240
Height: 25
Children: Children:
Label@GAME_ENDED_LABEL: Button@OBJECTIVES_BUTTON:
X: 20 X: 0
Y: 20 Y: 50
Width: PARENT_RIGHT - 40
Height: 25
Font: Bold
Align: Center
Text: The game has ended
Button@STATS_BUTTON:
X: PARENT_RIGHT - 2 * (WIDTH + 20)
Y: PARENT_BOTTOM - 45
Width: 120 Width: 120
Height: 25 Height: 25
Font: Bold Font: Bold
Text: Statistics Text: Objectives
Button@LEAVE_BUTTON: Button@CHAT_BUTTON:
X: PARENT_RIGHT - WIDTH - 20 X: 120
Y: PARENT_BOTTOM - 45 Y: 50
Width: 120 Width: 120
Height: 25 Height: 25
Font: Bold Font: Bold
Text: Leave Text: Chat
Container@OBJECTIVES: Button@STATS_BUTTON:
Y: 40 X: PARENT_RIGHT - 2 * (WIDTH + 20)
Y: PARENT_BOTTOM - 45
Width: 120
Height: 25
Font: Bold
Text: Statistics
Button@LEAVE_BUTTON:
X: PARENT_RIGHT - WIDTH - 20
Y: PARENT_BOTTOM - 45
Width: 120
Height: 25
Font: Bold
Text: Leave
Container@OBJECTIVES_PANEL:
Y: 65
Container@DIALOG_CHAT_PANEL:
X: 20
Y: 65
Width: PARENT_RIGHT - 40
Height: 370
Logic: IngameChatLogic
Visible: False
Children:
Container@CHAT_CHROME:
Width: PARENT_RIGHT
Height: PARENT_BOTTOM
Children:
Button@CHAT_MODE:
Y: PARENT_BOTTOM - HEIGHT
Width: 50
Height: 25
Text: Team
Font: Bold
TextField@CHAT_TEXTFIELD:
X: 55
Y: PARENT_BOTTOM - HEIGHT
Width: 427
Height: 25
ScrollPanel@CHAT_SCROLLPANEL:
Y: PARENT_BOTTOM - HEIGHT - 30
Width: 482
Height: 315
ItemSpacing: 4
Align: Bottom
Children:
Container@CHAT_TEMPLATE:
X: 2
Width: PARENT_RIGHT-27
Height: 16
Children:
Label@NAME:
X: 3
Width: 50
Height: 15
VAlign: Top
Label@TEXT:
X: 12
Width: PARENT_RIGHT - 17
Height: 15
WordWrap: true
VAlign: Top