Merge pull request #6473 from obrakmann/fix6422

Add chat tab to end-game dialog
This commit is contained in:
Matthias Mailänder
2014-09-20 14:45:47 +02:00
7 changed files with 393 additions and 90 deletions

View File

@@ -45,12 +45,16 @@ namespace OpenRA.Mods.D2k.Widgets.Logic
{
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();
Game.LoadWidget(world, "LEAVE_MAP_WIDGET", Ui.Root, new WidgetArgs());
showleaveMapWidget = true;
};
world.GameOver += ShowLeaveRestartDialog;
world.GameOver += ShowLeaveMapWidget;
}
void InitObserverWidgets()

View File

@@ -8,7 +8,9 @@
*/
#endregion
using System;
using System.Linq;
using System.Drawing;
using OpenRA.Traits;
using OpenRA.Widgets;
@@ -16,26 +18,63 @@ namespace OpenRA.Mods.RA.Widgets
{
class LeaveMapLogic
{
enum Tab { Objectives, Chat };
Tab currentTab;
bool newChatMessage;
[ObjectCreator.UseCtor]
public LeaveMapLogic(Widget widget, World world)
{
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 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);
dialog.IsVisible = () => !showStats;
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");
statsButton.IsVisible = () => !(world.Map.Type == "Mission" || world.Map.Type == "Campaign") || world.IsReplay;
statsButton.OnClick = () =>
{
showStats = true;
@@ -69,11 +108,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());
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());
Action ShowLeaveRestartDialog = () =>
var showLeaveMapWidget = false;
var leaveMapWidget = Game.LoadWidget(world, "LEAVE_MAP_WIDGET", Ui.Root, new WidgetArgs());
leaveMapWidget.IsVisible = () => showLeaveMapWidget;
Action ShowLeaveMapWidget = () =>
{
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();
bool teamChat;
bool inDialog;
[ObjectCreator.UseCtor]
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();
var chatPanel = (ContainerWidget)widget;
chatOverlay = chatPanel.Get<ContainerWidget>("CHAT_OVERLAY");
chatOverlayDisplay = chatOverlay.Get<ChatDisplayWidget>("CHAT_DISPLAY");
chatOverlay.Visible = false;
chatOverlay = chatPanel.GetOrNull<ContainerWidget>("CHAT_OVERLAY");
if (chatOverlay != null)
{
chatOverlayDisplay = chatOverlay.Get<ChatDisplayWidget>("CHAT_DISPLAY");
chatOverlay.Visible = false;
}
else
inDialog = true;
chatChrome = chatPanel.Get<ContainerWidget>("CHAT_CHROME");
chatChrome.Visible = true;
@@ -82,6 +88,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
trait.OnChat(orderManager.LocalClient.Name, text);
}
chatText.Text = "";
CloseChat();
return true;
};
@@ -94,26 +101,29 @@ namespace OpenRA.Mods.RA.Widgets.Logic
chatText.OnEscKey = () => { CloseChat(); return true; };
var chatClose = chatChrome.Get<ButtonWidget>("CHAT_CLOSE");
chatClose.OnClick += CloseChat;
chatPanel.OnKeyPress = e =>
if (!inDialog)
{
if (e.Event == KeyInputEvent.Up)
return false;
var chatClose = chatChrome.Get<ButtonWidget>("CHAT_CLOSE");
chatClose.OnClick += CloseChat;
if (!chatChrome.IsVisible() && (e.Key == Keycode.RETURN || e.Key == Keycode.KP_ENTER))
chatPanel.OnKeyPress = e =>
{
OpenChat();
return true;
}
if (e.Event == KeyInputEvent.Up)
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");
chatTemplate = chatScrollPanel.Get<ContainerWidget>("CHAT_TEMPLATE");
chatScrollPanel.RemoveChildren();
chatScrollPanel.ScrollToBottom();
Game.AddChatLine += AddChatLine;
Game.BeforeGameStart += UnregisterEvents;
@@ -130,22 +140,26 @@ namespace OpenRA.Mods.RA.Widgets.Logic
public void OpenChat()
{
chatText.Text = "";
chatOverlay.Visible = false;
chatChrome.Visible = true;
chatScrollPanel.ScrollToBottom();
chatText.TakeKeyboardFocus();
if (!inDialog)
chatOverlay.Visible = false;
}
public void CloseChat()
{
chatOverlay.Visible = true;
if (inDialog)
return;
chatChrome.Visible = false;
chatText.YieldKeyboardFocus();
chatOverlay.Visible = true;
}
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 nameLabel = template.Get<LabelWidget>("NAME");

View File

@@ -69,28 +69,97 @@ Container@LEAVE_MAP_WIDGET:
Width: PARENT_RIGHT
Height: PARENT_BOTTOM - 35
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:
Label@GAME_ENDED_LABEL:
X: 0
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
Button@OBJECTIVES_BUTTON:
Y: 1 - HEIGHT
Width: 140
Height: 35
Font: Bold
Text: Leave
Button@STATS_BUTTON:
Text: Objectives
Button@CHAT_BUTTON:
X: 150
Y: PARENT_BOTTOM - 1
Y: 1 - HEIGHT
Width: 140
Height: 35
Font: Bold
Text: Statistics
Container@OBJECTIVES:
Text: Chat
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
Y: (WINDOW_BOTTOM - HEIGHT) / 2
Width: 522
Height: 470
Height: 495
Visible: False
Children:
Background@LEAVE_MAP_BG:
Width: PARENT_RIGHT
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:
Label@GAME_ENDED_LABEL:
X: 20
Y: 20
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
Button@OBJECTIVES_BUTTON:
X: 0
Y: 50
Width: 120
Height: 25
Font: Bold
Text: Statistics
Button@LEAVE_BUTTON:
X: PARENT_RIGHT - WIDTH - 20
Y: PARENT_BOTTOM - 45
Text: Objectives
Button@CHAT_BUTTON:
X: 120
Y: 50
Width: 120
Height: 25
Font: Bold
Text: Leave
Container@OBJECTIVES:
Y: 40
Text: Chat
Button@STATS_BUTTON:
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
Y: (WINDOW_BOTTOM - HEIGHT) / 2
Width: 522
Height: 470
Height: 510
Visible: False
Children:
Background@LEAVE_MAP_BG:
Width: PARENT_RIGHT
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:
Label@GAME_ENDED_LABEL:
X: 20
Y: 20
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
Button@OBJECTIVES_BUTTON:
X: 0
Y: 50
Width: 120
Height: 25
Font: Bold
Text: Statistics
Button@LEAVE_BUTTON:
X: PARENT_RIGHT - WIDTH - 20
Y: PARENT_BOTTOM - 45
Text: Objectives
Button@CHAT_BUTTON:
X: 120
Y: 50
Width: 120
Height: 25
Font: Bold
Text: Leave
Container@OBJECTIVES:
Y: 40
Text: Chat
Button@STATS_BUTTON:
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