Move chat display into a widget
This commit is contained in:
@@ -1,71 +0,0 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
|
||||
* This file is part of OpenRA.
|
||||
*
|
||||
* OpenRA is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* OpenRA is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.Traits;
|
||||
using System.Text;
|
||||
|
||||
namespace OpenRA
|
||||
{
|
||||
class Chat
|
||||
{
|
||||
const int logLength = 10;
|
||||
public List<ChatLine> recentLines = new List<ChatLine>();
|
||||
|
||||
public void AddLine(Session.Client p, string text)
|
||||
{
|
||||
AddLine(Game.world.PlayerColors()[p.PaletteIndex].Color, p.Name, text);
|
||||
}
|
||||
|
||||
public void AddLine(Color c, string from, string text)
|
||||
{
|
||||
var sizeOwner = Game.chrome.renderer.RegularFont.Measure(from);
|
||||
var sizeText = Game.chrome.renderer.RegularFont.Measure(text);
|
||||
|
||||
if (sizeOwner.X + sizeText.X + 10 <= Chrome.ChatWidth)
|
||||
recentLines.Add(new ChatLine { Color = c, Owner = from, Text = text });
|
||||
else
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
foreach (var w in text.Split(' '))
|
||||
{
|
||||
if ( Game.chrome.renderer.RegularFont.Measure(sb.ToString() + ' ' + w).X > Chrome.ChatWidth )
|
||||
{
|
||||
recentLines.Add(new ChatLine { Color = c, Owner = from, Text = sb.ToString() } );
|
||||
sb = new StringBuilder();
|
||||
sb.Append(w);
|
||||
}
|
||||
else
|
||||
sb.Append( ' ' + w);
|
||||
}
|
||||
if (sb.Length != 0)
|
||||
recentLines.Add(new ChatLine { Color = c, Owner = from, Text = sb.ToString() } );
|
||||
}
|
||||
|
||||
var eva = Rules.Info["world"].Traits.Get<EvaAlertsInfo>();
|
||||
Sound.Play(eva.ChatBeep);
|
||||
while (recentLines.Count > logLength) recentLines.RemoveAt(0);
|
||||
}
|
||||
}
|
||||
|
||||
class ChatLine { public Color Color = Color.White; public string Owner, Text; public bool wrapped = false; }
|
||||
}
|
||||
@@ -61,6 +61,7 @@ namespace OpenRA
|
||||
|
||||
public static Widget rootWidget = null;
|
||||
public static Widget selectedWidget;
|
||||
public static ChatDisplayWidget chatWidget;
|
||||
|
||||
public void Tick(World world)
|
||||
{
|
||||
@@ -75,10 +76,6 @@ namespace OpenRA
|
||||
{
|
||||
buttons.Clear();
|
||||
renderer.Device.DisableScissor();
|
||||
|
||||
var typingArea = new Rectangle(240, Game.viewport.Height - 30, Game.viewport.Width - 420, 30);
|
||||
var chatLogArea = new Rectangle(240, Game.viewport.Height - 500, Game.viewport.Width - 420, 500 - 40);
|
||||
DrawChat(typingArea, chatLogArea);
|
||||
}
|
||||
|
||||
void AddUiButton(int2 pos, string text, Action<bool> a)
|
||||
@@ -165,17 +162,6 @@ namespace OpenRA
|
||||
currentMap = null;
|
||||
else
|
||||
currentMap = Game.AvailableMaps[ Game.LobbyInfo.GlobalSettings.Map ];
|
||||
|
||||
var w = 800;
|
||||
var h = 600;
|
||||
var r = new Rectangle( (Game.viewport.Width - w) / 2, (Game.viewport.Height - h) / 2, w, h );
|
||||
|
||||
var typingBox = new Rectangle(r.Left + 20, r.Bottom - 77, r.Width - 40, 27);
|
||||
var chatBox = new Rectangle(r.Left + 20, r.Bottom - 269, r.Width - 40, 190);
|
||||
|
||||
DrawDialogBackground(chatBox, "dialog3");
|
||||
|
||||
DrawChat(typingBox, chatBox);
|
||||
}
|
||||
|
||||
void AddButton(RectangleF r, Action<bool> b) { buttons.Add(Pair.New(r, b)); }
|
||||
@@ -185,30 +171,6 @@ namespace OpenRA
|
||||
WidgetUtils.DrawPanel(collection, r);
|
||||
}
|
||||
|
||||
void DrawChat(Rectangle typingArea, Rectangle chatLogArea)
|
||||
{
|
||||
|
||||
var chatpos = new int2(chatLogArea.X + 10, chatLogArea.Bottom - 6);
|
||||
ChatWidth = chatLogArea.Width - 10;
|
||||
|
||||
renderer.Device.EnableScissor(chatLogArea.Left, chatLogArea.Top, chatLogArea.Width, chatLogArea.Height);
|
||||
foreach (var line in Game.chat.recentLines.AsEnumerable().Reverse())
|
||||
{
|
||||
chatpos.Y -= 20;
|
||||
RenderChatLine(line, chatpos);
|
||||
}
|
||||
|
||||
rgbaRenderer.Flush();
|
||||
renderer.Device.DisableScissor();
|
||||
}
|
||||
|
||||
void RenderChatLine(ChatLine line, int2 p)
|
||||
{
|
||||
var size = renderer.RegularFont.Measure(line.Owner);
|
||||
renderer.RegularFont.DrawText(line.Owner, p, line.Color);
|
||||
renderer.RegularFont.DrawText(line.Text, p + new int2(size.X + 10, 0), Color.White);
|
||||
}
|
||||
|
||||
public int ticksSinceLastMove = 0;
|
||||
public int2 lastMousePos;
|
||||
public bool HandleInput(World world, MouseInput mi)
|
||||
|
||||
@@ -201,9 +201,6 @@ namespace OpenRA
|
||||
}
|
||||
|
||||
internal static int RenderFrame = 0;
|
||||
|
||||
internal static Chat chat = new Chat();
|
||||
|
||||
internal static int LocalTick = 0;
|
||||
const int NetTickScale = 3; // 120ms net tick for 40ms local tick
|
||||
|
||||
@@ -618,7 +615,7 @@ namespace OpenRA
|
||||
|
||||
public static void Exit() { quit = true; }
|
||||
|
||||
public static void Debug(string s) { chat.AddLine(Color.White, "Debug", s); }
|
||||
public static void Debug(string s) { Chrome.chatWidget.AddLine(Color.White, "Debug", s); }
|
||||
|
||||
public static void Disconnect()
|
||||
{
|
||||
|
||||
@@ -33,27 +33,29 @@ namespace OpenRA.Network
|
||||
case "Chat":
|
||||
{
|
||||
var client = Game.LobbyInfo.Clients.FirstOrDefault(c => c.Index == clientId);
|
||||
if (client != null)
|
||||
Game.chat.AddLine(client, order.TargetString);
|
||||
if (client != null && Chrome.chatWidget != null)
|
||||
Chrome.chatWidget.AddLine(client, order.TargetString);
|
||||
break;
|
||||
}
|
||||
case "TeamChat":
|
||||
{
|
||||
var client = Game.LobbyInfo.Clients.FirstOrDefault(c => c.Index == clientId);
|
||||
if (client != null)
|
||||
if (client != null && Chrome.chatWidget != null)
|
||||
{
|
||||
var player = Game.world.players.Values.FirstOrDefault(p => p.Index == client.Index);
|
||||
var isAlly = player != null && Game.world.LocalPlayer != null
|
||||
&& player.Stances[Game.world.LocalPlayer] == Stance.Ally;
|
||||
|
||||
if (isAlly)
|
||||
Game.chat.AddLine(client, "(Team) " + order.TargetString);
|
||||
Chrome.chatWidget.AddLine(client, "(Team) " + order.TargetString);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "StartGame":
|
||||
{
|
||||
Game.chat.AddLine(Color.White, "Server", "The game has started.");
|
||||
if (Chrome.chatWidget != null)
|
||||
Chrome.chatWidget.AddLine(Color.White, "Server", "The game has started.");
|
||||
|
||||
Game.StartGame();
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -75,7 +75,6 @@
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Chat.cs" />
|
||||
<Compile Include="Chrome.cs" />
|
||||
<Compile Include="GameRules\WeaponInfo.cs" />
|
||||
<Compile Include="Group.cs" />
|
||||
@@ -226,6 +225,7 @@
|
||||
<Compile Include="Traits\World\AircraftInfluence.cs" />
|
||||
<Compile Include="Traits\World\HazardLayer.cs" />
|
||||
<Compile Include="Widgets\TextFieldWidget.cs" />
|
||||
<Compile Include="Widgets\ChatDisplayWidget.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||
|
||||
@@ -25,8 +25,6 @@ namespace OpenRA.Traits
|
||||
{
|
||||
// Sound effects
|
||||
public readonly string TabClick = "ramenu1.aud";
|
||||
|
||||
public readonly string ChatBeep = "rabeep1.aud";
|
||||
public readonly string RadarUp = "radaron2.aud";
|
||||
public readonly string RadarDown = "radardn1.aud";
|
||||
|
||||
|
||||
@@ -68,6 +68,7 @@ namespace OpenRA.Widgets.Delegates
|
||||
};
|
||||
|
||||
Game.LobbyInfoChanged += UpdatePlayerList;
|
||||
Chrome.chatWidget = lobby.GetWidget("CHAT_DISPLAY") as ChatDisplayWidget;
|
||||
}
|
||||
|
||||
void UpdatePlayerList()
|
||||
|
||||
@@ -102,7 +102,6 @@ namespace OpenRA.Widgets
|
||||
TextBuffer += c;
|
||||
}
|
||||
|
||||
|
||||
int blinkCycle = 10;
|
||||
bool showCursor = true;
|
||||
public override void Tick(World world)
|
||||
|
||||
@@ -491,6 +491,15 @@ Container:
|
||||
Width:120
|
||||
Height:25
|
||||
Text:Change Map
|
||||
ChatDisplay@CHAT_DISPLAY:
|
||||
Id:CHAT_DISPLAY
|
||||
Visible:true
|
||||
X:20
|
||||
Y:PARENT_BOTTOM - 269
|
||||
Width:PARENT_RIGHT - 40
|
||||
Height:190
|
||||
Notification: beepy2.aud
|
||||
#rabeep1.aud for ra
|
||||
Label@LABEL_LOBBY_TEAM:
|
||||
Id:LABEL_LOBBY_TEAM
|
||||
Width:70
|
||||
|
||||
@@ -205,7 +205,6 @@ World:
|
||||
SpawnDefaultUnits:
|
||||
EvaAlerts:
|
||||
TabClick: button.aud
|
||||
ChatBeep: beepy2.aud
|
||||
RadarUp: comcntr1.aud
|
||||
RadarDown: powrdn1.aud
|
||||
BuildPaletteOpen: appear1.aud
|
||||
|
||||
Reference in New Issue
Block a user