38f1ddb...178a853: v0.8.9.1, removed content folder
This commit is contained in:
@@ -13,36 +13,53 @@ namespace Barotrauma.Networking
|
||||
|
||||
public GUIComponent CreateBanFrame(GUIComponent parent)
|
||||
{
|
||||
banFrame = new GUIListBox(new Rectangle(0, 0, 0, 0), "", parent);
|
||||
banFrame = new GUIListBox(new RectTransform(Vector2.One, parent.RectTransform, Anchor.Center));
|
||||
|
||||
foreach (BannedPlayer bannedPlayer in bannedPlayers)
|
||||
{
|
||||
GUITextBlock textBlock = new GUITextBlock(
|
||||
new Rectangle(0, 0, 0, 55),
|
||||
bannedPlayer.IP + " (" + bannedPlayer.Name + ")",
|
||||
"",
|
||||
Alignment.Left, Alignment.TopLeft, banFrame);
|
||||
textBlock.Padding = new Vector4(10.0f, 10.0f, 10.0f, 10.0f);
|
||||
textBlock.UserData = banFrame;
|
||||
var playerFrame = new GUIFrame(new RectTransform(new Vector2(1.0f, 0.25f), ((GUIListBox)banFrame).Content.RectTransform) { MinSize = new Point(0, 70) }, style: null)
|
||||
{
|
||||
UserData = banFrame
|
||||
};
|
||||
|
||||
var removeButton = new GUIButton(new Rectangle(0, 0, 80, 20), "Remove", Alignment.TopRight, "", textBlock);
|
||||
removeButton.UserData = bannedPlayer;
|
||||
removeButton.OnClicked = RemoveBan;
|
||||
var paddedPlayerFrame = new GUILayoutGroup(new RectTransform(new Vector2(0.95f, 0.85f), playerFrame.RectTransform, Anchor.Center))
|
||||
{
|
||||
Stretch = true,
|
||||
RelativeSpacing = 0.05f
|
||||
};
|
||||
|
||||
GUITextBlock textBlock = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.3f), paddedPlayerFrame.RectTransform),
|
||||
bannedPlayer.IP + " (" + bannedPlayer.Name + ")");
|
||||
|
||||
var removeButton = new GUIButton(new RectTransform(new Vector2(0.2f, 0.4f), paddedPlayerFrame.RectTransform, Anchor.TopRight), TextManager.Get("BanListRemove"))
|
||||
{
|
||||
UserData = bannedPlayer,
|
||||
IgnoreLayoutGroups = true,
|
||||
OnClicked = RemoveBan
|
||||
};
|
||||
if (bannedPlayer.IP.IndexOf(".x") <= -1)
|
||||
{
|
||||
var rangeBanButton = new GUIButton(new Rectangle(-85, 0, 90, 20), "Ban range", Alignment.TopRight, "", textBlock);
|
||||
rangeBanButton.UserData = bannedPlayer;
|
||||
rangeBanButton.OnClicked = RangeBan;
|
||||
var rangeBanButton = new GUIButton(new RectTransform(new Vector2(0.25f, 0.4f), paddedPlayerFrame.RectTransform, Anchor.TopRight) { RelativeOffset = new Vector2(0.22f, 0.0f) }, TextManager.Get("BanRange"))
|
||||
{
|
||||
UserData = bannedPlayer,
|
||||
IgnoreLayoutGroups = true,
|
||||
OnClicked = RangeBan
|
||||
};
|
||||
}
|
||||
|
||||
var reasonText = new GUITextBlock(new Rectangle(0, 0, 170, 20),
|
||||
string.IsNullOrEmpty(bannedPlayer.Reason) ? "Reason: none" : ToolBox.LimitString("Reason: " + bannedPlayer.Reason, GUI.SmallFont, 170),
|
||||
"", Alignment.BottomLeft, Alignment.TopLeft, textBlock, false, GUI.SmallFont);
|
||||
reasonText.ToolTip = bannedPlayer.Reason;
|
||||
new GUITextBlock(new RectTransform(new Vector2(0.6f, 0.0f), paddedPlayerFrame.RectTransform),
|
||||
bannedPlayer.ExpirationTime == null ?
|
||||
TextManager.Get("BanPermanent") : TextManager.Get("BanExpires").Replace("[time]", bannedPlayer.ExpirationTime.Value.ToString()),
|
||||
font: GUI.SmallFont);
|
||||
|
||||
var reasonText = new GUITextBlock(new RectTransform(new Vector2(0.6f, 0.0f), paddedPlayerFrame.RectTransform),
|
||||
TextManager.Get("BanReason") +
|
||||
(string.IsNullOrEmpty(bannedPlayer.Reason) ? TextManager.Get("None") : ToolBox.LimitString(bannedPlayer.Reason, GUI.SmallFont, 170)),
|
||||
font: GUI.SmallFont, wrap: true)
|
||||
{
|
||||
ToolTip = bannedPlayer.Reason
|
||||
};
|
||||
|
||||
new GUITextBlock(new Rectangle(0, 0, 100, 20),
|
||||
bannedPlayer.ExpirationTime == null ? "Permanent" : "Expires " + bannedPlayer.ExpirationTime.Value.ToString(),
|
||||
"", Alignment.BottomRight, Alignment.TopRight, textBlock, false, GUI.SmallFont);
|
||||
|
||||
}
|
||||
|
||||
@@ -58,8 +75,9 @@ namespace Barotrauma.Networking
|
||||
|
||||
if (banFrame != null)
|
||||
{
|
||||
banFrame.Parent.RemoveChild(banFrame);
|
||||
CreateBanFrame(banFrame.Parent);
|
||||
var parent = banFrame.Parent;
|
||||
parent.RemoveChild(banFrame);
|
||||
CreateBanFrame(parent);
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -74,8 +92,9 @@ namespace Barotrauma.Networking
|
||||
|
||||
if (banFrame != null)
|
||||
{
|
||||
banFrame.Parent.RemoveChild(banFrame);
|
||||
CreateBanFrame(banFrame.Parent);
|
||||
var parent = banFrame.Parent;
|
||||
parent.RemoveChild(banFrame);
|
||||
CreateBanFrame(parent);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -5,10 +5,11 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
partial class ChatMessage
|
||||
{
|
||||
public void ClientWrite(NetOutgoingMessage msg)
|
||||
public virtual void ClientWrite(NetOutgoingMessage msg)
|
||||
{
|
||||
msg.Write((byte)ClientNetObject.CHAT_MESSAGE);
|
||||
msg.Write(NetStateID);
|
||||
msg.Write((byte)Type);
|
||||
msg.Write(Text);
|
||||
}
|
||||
|
||||
@@ -16,7 +17,12 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
UInt16 ID = msg.ReadUInt16();
|
||||
ChatMessageType type = (ChatMessageType)msg.ReadByte();
|
||||
string txt = msg.ReadString();
|
||||
string txt = "";
|
||||
|
||||
if (type != ChatMessageType.Order)
|
||||
{
|
||||
txt = msg.ReadString();
|
||||
}
|
||||
|
||||
string senderName = msg.ReadString();
|
||||
Character senderCharacter = null;
|
||||
@@ -30,6 +36,54 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
}
|
||||
|
||||
if (type == ChatMessageType.Order)
|
||||
{
|
||||
int orderIndex = msg.ReadByte();
|
||||
UInt16 targetCharacterID = msg.ReadUInt16();
|
||||
Character targetCharacter = Entity.FindEntityByID(targetCharacterID) as Character;
|
||||
Entity targetEntity = Entity.FindEntityByID(msg.ReadUInt16());
|
||||
int optionIndex = msg.ReadByte();
|
||||
|
||||
Order order = null;
|
||||
if (orderIndex < 0 || orderIndex >= Order.PrefabList.Count)
|
||||
{
|
||||
DebugConsole.ThrowError("Invalid order message - order index out of bounds.");
|
||||
if (NetIdUtils.IdMoreRecent(ID, LastID)) LastID = ID;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
order = Order.PrefabList[orderIndex];
|
||||
}
|
||||
string orderOption = "";
|
||||
if (optionIndex >= 0 && optionIndex < order.Options.Length)
|
||||
{
|
||||
orderOption = order.Options[optionIndex];
|
||||
}
|
||||
txt = order.GetChatMessage(targetCharacter?.Name, senderCharacter?.CurrentHull?.RoomName, orderOption);
|
||||
|
||||
if (order.TargetAllCharacters)
|
||||
{
|
||||
GameMain.GameSession?.CrewManager?.AddOrder(
|
||||
new Order(order.Prefab, targetEntity, (targetEntity as Item)?.GetComponent<Items.Components.ItemComponent>()),
|
||||
order.Prefab.FadeOutTime);
|
||||
}
|
||||
else if (targetCharacter != null)
|
||||
{
|
||||
targetCharacter.SetOrder(
|
||||
new Order(order.Prefab, targetEntity, (targetEntity as Item)?.GetComponent<Items.Components.ItemComponent>()),
|
||||
orderOption, senderCharacter);
|
||||
}
|
||||
|
||||
if (NetIdUtils.IdMoreRecent(ID, LastID))
|
||||
{
|
||||
GameMain.Client.AddChatMessage(
|
||||
new OrderChatMessage(order, orderOption, txt, targetEntity, targetCharacter, senderCharacter));
|
||||
LastID = ID;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (NetIdUtils.IdMoreRecent(ID, LastID))
|
||||
{
|
||||
switch (type)
|
||||
@@ -51,9 +105,8 @@ namespace Barotrauma.Networking
|
||||
GameMain.Client.AddChatMessage(txt, type, senderName, senderCharacter);
|
||||
break;
|
||||
}
|
||||
|
||||
LastID = ID;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,7 +98,14 @@ namespace Barotrauma.Networking
|
||||
|
||||
public void ReadBytes(NetIncomingMessage inc)
|
||||
{
|
||||
byte[] all = inc.ReadBytes(inc.LengthBytes - inc.PositionInBytes);
|
||||
int bytesToRead = inc.LengthBytes - inc.PositionInBytes;
|
||||
if (Received + (ulong)(bytesToRead) > FileSize)
|
||||
{
|
||||
//strip out excess bytes
|
||||
bytesToRead -= (int)((Received + (ulong)bytesToRead) - FileSize);
|
||||
}
|
||||
|
||||
byte[] all = inc.ReadBytes(bytesToRead);
|
||||
Received += (ulong)all.Length;
|
||||
WriteStream.Write(all, 0, all.Length);
|
||||
|
||||
@@ -259,10 +266,15 @@ namespace Barotrauma.Networking
|
||||
return;
|
||||
}
|
||||
|
||||
if (activeTransfer.Received + (ulong)(inc.LengthBytes - inc.PositionInBytes) > activeTransfer.FileSize)
|
||||
//allow one extra byte at the end for the 0 that identifies non-compressed messages
|
||||
if (activeTransfer.Received + (ulong)(inc.LengthBytes - inc.PositionInBytes) > activeTransfer.FileSize + 1)
|
||||
{
|
||||
GameMain.Client.CancelFileTransfer(inc.SequenceChannel);
|
||||
DebugConsole.ThrowError("File transfer error: Received more data than expected");
|
||||
DebugConsole.ThrowError("File transfer error: Received more data than expected (total received: " + activeTransfer.Received +
|
||||
", msg received: " + (inc.LengthBytes - inc.PositionInBytes) +
|
||||
", msg length: " + inc.LengthBytes +
|
||||
", msg read: " + inc.PositionInBytes +
|
||||
", filesize: " + activeTransfer.FileSize);
|
||||
activeTransfer.Status = FileTransferStatus.Error;
|
||||
StopTransfer(activeTransfer);
|
||||
return;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -13,42 +13,54 @@ namespace Barotrauma.Networking
|
||||
|
||||
void InitProjSpecific()
|
||||
{
|
||||
var endRoundButton = new GUIButton(new Rectangle(GameMain.GraphicsWidth - 170, 20, 150, 20), "End round", Alignment.TopLeft, "", inGameHUD);
|
||||
endRoundButton.OnClicked = (btn, userdata) => { EndGame(); return true; };
|
||||
|
||||
GUIButton settingsButton = new GUIButton(new Rectangle(GameMain.GraphicsWidth - 170 - 170 - 170, 20, 150, 20), "Settings", Alignment.TopLeft, "", inGameHUD);
|
||||
settingsButton.OnClicked = ToggleSettingsFrame;
|
||||
settingsButton.UserData = "settingsButton";
|
||||
var buttonContainer = new GUILayoutGroup(HUDLayoutSettings.ToRectTransform(HUDLayoutSettings.ButtonAreaTop, inGameHUD.RectTransform),
|
||||
isHorizontal: true, childAnchor: Anchor.CenterRight)
|
||||
{
|
||||
CanBeFocused = false
|
||||
};
|
||||
|
||||
var endRoundButton = new GUIButton(new RectTransform(new Vector2(0.1f, 0.6f), buttonContainer.RectTransform) { MinSize = new Point(150, 0) },
|
||||
TextManager.Get("EndRound"))
|
||||
{
|
||||
OnClicked = (btn, userdata) => { EndGame(); return true; }
|
||||
};
|
||||
|
||||
showLogButton = new GUIButton(new RectTransform(new Vector2(0.1f, 0.6f), buttonContainer.RectTransform) { MinSize = new Point(150, 0) },
|
||||
TextManager.Get("ServerLog"))
|
||||
{
|
||||
OnClicked = (GUIButton button, object userData) =>
|
||||
{
|
||||
if (ServerLog.LogFrame == null)
|
||||
{
|
||||
ServerLog.CreateLogFrame();
|
||||
}
|
||||
else
|
||||
{
|
||||
ServerLog.LogFrame = null;
|
||||
GUI.KeyboardDispatcher.Subscriber = null;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
GUIButton settingsButton = new GUIButton(new RectTransform(new Vector2(0.1f, 0.6f), buttonContainer.RectTransform) { MinSize = new Point(150, 0) },
|
||||
TextManager.Get("ServerSettingsButton"))
|
||||
{
|
||||
OnClicked = ToggleSettingsFrame,
|
||||
UserData = "settingsButton"
|
||||
};
|
||||
}
|
||||
|
||||
public override void AddToGUIUpdateList()
|
||||
{
|
||||
if (GUI.DisableHUD) return;
|
||||
base.AddToGUIUpdateList();
|
||||
if (settingsFrame != null) settingsFrame.AddToGUIUpdateList();
|
||||
settingsFrame?.AddToGUIUpdateList();
|
||||
}
|
||||
|
||||
public override void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch)
|
||||
{
|
||||
base.Draw(spriteBatch);
|
||||
|
||||
if (settingsFrame != null)
|
||||
{
|
||||
settingsFrame.Draw(spriteBatch);
|
||||
}
|
||||
else if (ServerLog.LogFrame != null)
|
||||
{
|
||||
ServerLog.LogFrame.Draw(spriteBatch);
|
||||
}
|
||||
|
||||
if (Screen.Selected == GameMain.GameScreen && !GUI.DisableHUD)
|
||||
{
|
||||
if (EndVoteCount > 0)
|
||||
{
|
||||
GUI.DrawString(spriteBatch, new Vector2(GameMain.GraphicsWidth - 180.0f, 40),
|
||||
"Votes to end the round (y/n): " + EndVoteCount + "/" + (EndVoteMax - EndVoteCount), Color.White, null, 0, GUI.SmallFont);
|
||||
}
|
||||
}
|
||||
|
||||
if (!ShowNetStats) return;
|
||||
|
||||
GUI.Font.DrawString(spriteBatch, "Unique Events: " + entityEventManager.UniqueEvents.Count, new Vector2(10, 50), Color.White);
|
||||
@@ -56,13 +68,11 @@ namespace Barotrauma.Networking
|
||||
int width = 200, height = 300;
|
||||
int x = GameMain.GraphicsWidth - width, y = (int)(GameMain.GraphicsHeight * 0.3f);
|
||||
|
||||
|
||||
if (clientListScrollBar == null)
|
||||
{
|
||||
clientListScrollBar = new GUIScrollBar(new Rectangle(x + width - 10, y, 10, height), "", 1.0f);
|
||||
clientListScrollBar = new GUIScrollBar(new RectTransform(new Point(10, height), GUI.Canvas) { AbsoluteOffset = new Point(x + width - 10, y) });
|
||||
}
|
||||
|
||||
|
||||
GUI.DrawRectangle(spriteBatch, new Rectangle(x, y, width, height), Color.Black * 0.7f, true);
|
||||
GUI.Font.DrawString(spriteBatch, "Network statistics:", new Vector2(x + 10, y + 10), Color.White);
|
||||
|
||||
@@ -101,8 +111,8 @@ namespace Barotrauma.Networking
|
||||
y += 40;
|
||||
}
|
||||
|
||||
clientListScrollBar.Update(1.0f / 60.0f);
|
||||
clientListScrollBar.Draw(spriteBatch);
|
||||
clientListScrollBar.UpdateManually(1.0f / 60.0f);
|
||||
clientListScrollBar.DrawManually(spriteBatch);
|
||||
|
||||
netStats.AddValue(NetStats.NetStatType.ResentMessages, Math.Max(resentMessages, 0));
|
||||
netStats.AddValue(NetStats.NetStatType.SentBytes, server.Statistics.SentBytes);
|
||||
@@ -116,36 +126,52 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
var transfers = fileSender.ActiveTransfers.FindAll(t => t.Connection == client.Connection);
|
||||
|
||||
var clientNameBox = GameMain.NetLobbyScreen.PlayerList.FindChild(client.Name);
|
||||
var clientNameBox = GameMain.NetLobbyScreen.PlayerList.Content.FindChild(client.Name);
|
||||
|
||||
var clientInfo = clientNameBox.FindChild("filetransfer");
|
||||
if (clientInfo == null)
|
||||
{
|
||||
clientNameBox.ClearChildren();
|
||||
clientInfo = new GUIFrame(new Rectangle(0, 0, 180, 0), Color.Transparent, Alignment.TopRight, null, clientNameBox);
|
||||
clientInfo.UserData = "filetransfer";
|
||||
clientInfo = new GUIFrame(new RectTransform(new Vector2(0.4f, 0.9f), clientNameBox.RectTransform, Anchor.CenterRight) { RelativeOffset = new Vector2(0.1f, 0.0f) }, style: null)
|
||||
{
|
||||
UserData = "filetransfer"
|
||||
};
|
||||
var textBlock = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.5f), clientInfo.RectTransform),
|
||||
"", textAlignment: Alignment.CenterRight, font: GUI.SmallFont)
|
||||
{
|
||||
TextScale = 0.8f,
|
||||
TextGetter = () =>
|
||||
{
|
||||
string txt = "";
|
||||
if (transfers.Count > 0)
|
||||
{
|
||||
txt += transfers[0].FileName + " ";
|
||||
if (transfers.Count > 1) txt += "+ " + (transfers.Count - 1) + " others ";
|
||||
}
|
||||
txt += "(" + MathUtils.GetBytesReadable(transfers.Sum(t => t.SentOffset)) + " / " + MathUtils.GetBytesReadable(transfers.Sum(t => t.Data.Length)) + ")";
|
||||
return txt;
|
||||
}
|
||||
};
|
||||
|
||||
var progressBar = new GUIProgressBar(new RectTransform(new Vector2(0.8f, 0.5f), clientInfo.RectTransform, Anchor.BottomLeft),
|
||||
barSize: 0.0f, color: Color.Green)
|
||||
{
|
||||
IsHorizontal = true,
|
||||
ProgressGetter = () => { return transfers.Sum(t => t.Progress) / transfers.Count; }
|
||||
};
|
||||
|
||||
var cancelButton = new GUIButton(new RectTransform(new Vector2(0.2f, 0.5f), clientInfo.RectTransform, Anchor.BottomRight), "X")
|
||||
{
|
||||
OnClicked = (GUIButton button, object userdata) =>
|
||||
{
|
||||
transfers.ForEach(t => fileSender.CancelTransfer(t));
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
else if (transfers.Count == 0)
|
||||
{
|
||||
clientInfo.Parent.RemoveChild(clientInfo);
|
||||
}
|
||||
|
||||
clientInfo.ClearChildren();
|
||||
|
||||
var progressBar = new GUIProgressBar(new Rectangle(0, 4, 160, clientInfo.Rect.Height - 8), Color.Green, "", 0.0f, Alignment.Left, clientInfo);
|
||||
progressBar.IsHorizontal = true;
|
||||
progressBar.ProgressGetter = () => { return transfers.Sum(t => t.Progress) / transfers.Count; };
|
||||
|
||||
var textBlock = new GUITextBlock(new Rectangle(0, 2, 160, 0), "", "", Alignment.TopLeft, Alignment.Left | Alignment.CenterY, clientInfo, true, GUI.SmallFont);
|
||||
textBlock.TextGetter = () =>
|
||||
{ return MathUtils.GetBytesReadable(transfers.Sum(t => t.SentOffset)) + " / " + MathUtils.GetBytesReadable(transfers.Sum(t => t.Data.Length)); };
|
||||
|
||||
var cancelButton = new GUIButton(new Rectangle(-5, 0, 14, 0), "X", Alignment.Right, "", clientInfo);
|
||||
cancelButton.OnClicked = (GUIButton button, object userdata) =>
|
||||
{
|
||||
transfers.ForEach(t => fileSender.CancelTransfer(t));
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
public override bool SelectCrewCharacter(Character character, GUIComponent characterFrame)
|
||||
@@ -154,17 +180,24 @@ namespace Barotrauma.Networking
|
||||
|
||||
if (character != myCharacter)
|
||||
{
|
||||
var banButton = new GUIButton(new Rectangle(0, 0, 100, 20), "Ban", Alignment.BottomRight, "", characterFrame);
|
||||
banButton.UserData = character.Name;
|
||||
banButton.OnClicked += GameMain.NetLobbyScreen.BanPlayer;
|
||||
|
||||
var rangebanButton = new GUIButton(new Rectangle(0, -25, 100, 20), "Ban range", Alignment.BottomRight, "", characterFrame);
|
||||
rangebanButton.UserData = character.Name;
|
||||
rangebanButton.OnClicked += GameMain.NetLobbyScreen.BanPlayerRange;
|
||||
|
||||
var kickButton = new GUIButton(new Rectangle(0, 0, 100, 20), "Kick", Alignment.BottomLeft, "", characterFrame);
|
||||
kickButton.UserData = character.Name;
|
||||
kickButton.OnClicked += GameMain.NetLobbyScreen.KickPlayer;
|
||||
var banButton = new GUIButton(new RectTransform(new Vector2(0.45f, 0.15f), characterFrame.RectTransform, Anchor.BottomRight),
|
||||
TextManager.Get("Ban"))
|
||||
{
|
||||
UserData = character.Name,
|
||||
OnClicked = GameMain.NetLobbyScreen.BanPlayer
|
||||
};
|
||||
var rangebanButton = new GUIButton(new RectTransform(new Vector2(0.45f, 0.15f), characterFrame.RectTransform, Anchor.BottomRight) { RelativeOffset = new Vector2(0.0f, 0.16f) },
|
||||
TextManager.Get("BanRange"))
|
||||
{
|
||||
UserData = character.Name,
|
||||
OnClicked = GameMain.NetLobbyScreen.BanPlayerRange
|
||||
};
|
||||
var kickButton = new GUIButton(new RectTransform(new Vector2(0.45f, 0.15f), characterFrame.RectTransform, Anchor.BottomLeft),
|
||||
TextManager.Get("Kick"))
|
||||
{
|
||||
UserData = character.Name,
|
||||
OnClicked = GameMain.NetLobbyScreen.KickPlayer
|
||||
};
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -173,9 +206,9 @@ namespace Barotrauma.Networking
|
||||
private GUIMessageBox upnpBox;
|
||||
void InitUPnP()
|
||||
{
|
||||
server.UPnP.ForwardPort(config.Port, "barotrauma");
|
||||
server.UPnP.ForwardPort(NetPeerConfiguration.Port, "barotrauma");
|
||||
|
||||
upnpBox = new GUIMessageBox("Please wait...", "Attempting UPnP port forwarding", new string[] { "Cancel" });
|
||||
upnpBox = new GUIMessageBox(TextManager.Get("PleaseWaitUPnP"), TextManager.Get("AttemptingUPnP"), new string[] { TextManager.Get("Cancel") });
|
||||
upnpBox.Buttons[0].OnClicked = upnpBox.Close;
|
||||
}
|
||||
|
||||
@@ -190,11 +223,11 @@ namespace Barotrauma.Networking
|
||||
|
||||
if (server.UPnP.Status == UPnPStatus.NotAvailable)
|
||||
{
|
||||
new GUIMessageBox("Error", "UPnP not available");
|
||||
new GUIMessageBox(TextManager.Get("Error"), TextManager.Get("UPnPUnavailable"));
|
||||
}
|
||||
else if (server.UPnP.Status == UPnPStatus.Discovering)
|
||||
{
|
||||
new GUIMessageBox("Error", "UPnP discovery timed out");
|
||||
new GUIMessageBox(TextManager.Get("Error"), TextManager.Get("UPnPTimedOut"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,187 +7,228 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
partial class GameServer : NetworkMember, ISerializableEntity
|
||||
{
|
||||
private GUIFrame settingsFrame;
|
||||
private GUIButton settingsFrame;
|
||||
private GUIFrame[] settingsTabs;
|
||||
private int settingsTabIndex;
|
||||
|
||||
enum SettingsTab
|
||||
{
|
||||
Rounds,
|
||||
Server,
|
||||
Banlist,
|
||||
Whitelist
|
||||
}
|
||||
|
||||
private void CreateSettingsFrame()
|
||||
{
|
||||
settingsFrame = new GUIFrame(new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight), Color.Black * 0.5f, null);
|
||||
settingsFrame = new GUIButton(new RectTransform(Vector2.One, GUI.Canvas), style: "GUIBackgroundBlocker")
|
||||
{
|
||||
OnClicked = (btn, userdata) => { if (GUI.MouseOn == btn || GUI.MouseOn == btn.TextBlock) ToggleSettingsFrame(btn, userdata); return true; }
|
||||
};
|
||||
new GUIButton(new RectTransform(Vector2.One, settingsFrame.RectTransform), "", style: null)
|
||||
{
|
||||
OnClicked = ToggleSettingsFrame
|
||||
};
|
||||
|
||||
GUIFrame innerFrame = new GUIFrame(new Rectangle(0, 0, 400, 430), null, Alignment.Center, "", settingsFrame);
|
||||
innerFrame.Padding = new Vector4(20.0f, 20.0f, 20.0f, 20.0f);
|
||||
GUIFrame innerFrame = new GUIFrame(new RectTransform(new Vector2(0.3f, 0.7f), settingsFrame.RectTransform, Anchor.Center) { MinSize = new Point(400, 430) });
|
||||
GUIFrame paddedFrame = new GUIFrame(new RectTransform(new Vector2(0.9f, 0.9f), innerFrame.RectTransform, Anchor.Center), style: null);
|
||||
|
||||
new GUITextBlock(new Rectangle(0, -5, 0, 20), "Settings", "", innerFrame, GUI.LargeFont);
|
||||
new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.1f), paddedFrame.RectTransform), "Settings", font: GUI.LargeFont);
|
||||
|
||||
string[] tabNames = { "Rounds", "Server", "Banlist", "Whitelist" };
|
||||
var buttonArea = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.07f), paddedFrame.RectTransform) { RelativeOffset = new Vector2(0.0f, 0.1f) }, isHorizontal: true)
|
||||
{
|
||||
Stretch = true,
|
||||
RelativeSpacing = 0.01f
|
||||
};
|
||||
|
||||
var tabValues = Enum.GetValues(typeof(SettingsTab)).Cast<SettingsTab>().ToArray();
|
||||
string[] tabNames = new string[tabValues.Count()];
|
||||
for (int i = 0; i < tabNames.Length; i++)
|
||||
{
|
||||
tabNames[i] = TextManager.Get("ServerSettings" + tabValues[i] + "Tab");
|
||||
}
|
||||
settingsTabs = new GUIFrame[tabNames.Length];
|
||||
for (int i = 0; i < tabNames.Length; i++)
|
||||
{
|
||||
settingsTabs[i] = new GUIFrame(new Rectangle(0, 15, 0, innerFrame.Rect.Height - 120), null, Alignment.Center, "InnerFrame", innerFrame);
|
||||
settingsTabs[i].Padding = new Vector4(40.0f, 20.0f, 40.0f, 40.0f);
|
||||
settingsTabs[i] = new GUIFrame(new RectTransform(new Vector2(1.0f, 0.79f), paddedFrame.RectTransform, Anchor.Center) { RelativeOffset = new Vector2(0.0f, 0.05f) },
|
||||
style: "InnerFrame");
|
||||
|
||||
var tabButton = new GUIButton(new Rectangle(85 * i, 35, 80, 20), tabNames[i], "", innerFrame);
|
||||
tabButton.UserData = i;
|
||||
tabButton.OnClicked = SelectSettingsTab;
|
||||
var tabButton = new GUIButton(new RectTransform(new Vector2(0.2f, 1.0f), buttonArea.RectTransform), tabNames[i])
|
||||
{
|
||||
UserData = i,
|
||||
OnClicked = SelectSettingsTab
|
||||
};
|
||||
}
|
||||
|
||||
settingsTabs[2].Padding = Vector4.Zero;
|
||||
|
||||
|
||||
SelectSettingsTab(null, 0);
|
||||
|
||||
var closeButton = new GUIButton(new Rectangle(10, 0, 100, 20), "Close", Alignment.BottomRight, "", innerFrame);
|
||||
closeButton.OnClicked = ToggleSettingsFrame;
|
||||
var closeButton = new GUIButton(new RectTransform(new Vector2(0.25f, 0.05f), paddedFrame.RectTransform, Anchor.BottomRight), TextManager.Get("Close"))
|
||||
{
|
||||
OnClicked = ToggleSettingsFrame
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
// game settings
|
||||
//--------------------------------------------------------------------------------
|
||||
|
||||
int y = 0;
|
||||
|
||||
settingsTabs[0].Padding = new Vector4(40.0f, 5.0f, 40.0f, 40.0f);
|
||||
|
||||
new GUITextBlock(new Rectangle(0, y, 100, 20), "Submarine selection:", "", settingsTabs[0]);
|
||||
var selectionFrame = new GUIFrame(new Rectangle(0, y + 20, 300, 20), null, settingsTabs[0]);
|
||||
for (int i = 0; i < 3; i++)
|
||||
|
||||
var roundsTab = new GUILayoutGroup(new RectTransform(new Vector2(0.95f, 0.95f), settingsTabs[(int)SettingsTab.Rounds].RectTransform, Anchor.Center))
|
||||
{
|
||||
var selectionTick = new GUITickBox(new Rectangle(i * 100, 0, 20, 20), ((SelectionMode)i).ToString(), Alignment.Left, selectionFrame);
|
||||
selectionTick.Selected = i == (int)subSelectionMode;
|
||||
selectionTick.OnSelected = SwitchSubSelection;
|
||||
selectionTick.UserData = (SelectionMode)i;
|
||||
}
|
||||
|
||||
y += 45;
|
||||
|
||||
new GUITextBlock(new Rectangle(0, y, 100, 20), "Mode selection:", "", settingsTabs[0]);
|
||||
selectionFrame = new GUIFrame(new Rectangle(0, y + 20, 300, 20), null, settingsTabs[0]);
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
var selectionTick = new GUITickBox(new Rectangle(i * 100, 0, 20, 20), ((SelectionMode)i).ToString(), Alignment.Left, selectionFrame);
|
||||
selectionTick.Selected = i == (int)modeSelectionMode;
|
||||
selectionTick.OnSelected = SwitchModeSelection;
|
||||
selectionTick.UserData = (SelectionMode)i;
|
||||
}
|
||||
|
||||
y += 60;
|
||||
|
||||
var endBox = new GUITickBox(new Rectangle(0, y, 20, 20), "End round when destination reached", Alignment.Left, settingsTabs[0]);
|
||||
endBox.Selected = EndRoundAtLevelEnd;
|
||||
endBox.OnSelected = (GUITickBox) => { EndRoundAtLevelEnd = GUITickBox.Selected; return true; };
|
||||
|
||||
y += 25;
|
||||
|
||||
var endVoteBox = new GUITickBox(new Rectangle(0, y, 20, 20), "End round by voting", Alignment.Left, settingsTabs[0]);
|
||||
endVoteBox.Selected = Voting.AllowEndVoting;
|
||||
endVoteBox.OnSelected = (GUITickBox) =>
|
||||
{
|
||||
Voting.AllowEndVoting = !Voting.AllowEndVoting;
|
||||
GameMain.Server.UpdateVoteStatus();
|
||||
return true;
|
||||
Stretch = true,
|
||||
RelativeSpacing = 0.02f
|
||||
};
|
||||
|
||||
|
||||
var votesRequiredText = new GUITextBlock(new Rectangle(20, y + 15, 20, 20), "Votes required: 50 %", "", settingsTabs[0], GUI.SmallFont);
|
||||
|
||||
var votesRequiredSlider = new GUIScrollBar(new Rectangle(150, y + 22, 100, 15), "", 0.1f, settingsTabs[0]);
|
||||
votesRequiredSlider.UserData = votesRequiredText;
|
||||
votesRequiredSlider.Step = 0.2f;
|
||||
votesRequiredSlider.BarScroll = (EndVoteRequiredRatio - 0.5f) * 2.0f;
|
||||
votesRequiredSlider.OnMoved = (GUIScrollBar scrollBar, float barScroll) =>
|
||||
new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.05f), roundsTab.RectTransform), TextManager.Get("ServerSettingsSubSelection"));
|
||||
var selectionFrame = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.05f), roundsTab.RectTransform), isHorizontal: true)
|
||||
{
|
||||
GUITextBlock voteText = scrollBar.UserData as GUITextBlock;
|
||||
Stretch = true,
|
||||
RelativeSpacing = 0.05f
|
||||
};
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
var selectionTick = new GUITickBox(new RectTransform(new Vector2(0.3f, 1.0f), selectionFrame.RectTransform), ((SelectionMode)i).ToString(), font: GUI.SmallFont)
|
||||
{
|
||||
Selected = i == (int)subSelectionMode,
|
||||
OnSelected = SwitchSubSelection,
|
||||
UserData = (SelectionMode)i,
|
||||
};
|
||||
}
|
||||
GUITickBox.CreateRadioButtonGroup(selectionFrame.Children.Select(c => c as GUITickBox));
|
||||
|
||||
new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.05f), roundsTab.RectTransform), TextManager.Get("ServerSettingsModeSelection"));
|
||||
selectionFrame = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.05f), roundsTab.RectTransform), isHorizontal: true)
|
||||
{
|
||||
Stretch = true,
|
||||
RelativeSpacing = 0.05f
|
||||
};
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
var selectionTick = new GUITickBox(new RectTransform(new Vector2(0.3f, 1.0f), selectionFrame.RectTransform), ((SelectionMode)i).ToString(), font: GUI.SmallFont)
|
||||
{
|
||||
Selected = i == (int)modeSelectionMode,
|
||||
OnSelected = SwitchModeSelection,
|
||||
UserData = (SelectionMode)i
|
||||
};
|
||||
}
|
||||
GUITickBox.CreateRadioButtonGroup(selectionFrame.Children.Select(c => c as GUITickBox));
|
||||
|
||||
var endBox = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.05f), roundsTab.RectTransform),
|
||||
TextManager.Get("ServerSettingsEndRoundWhenDestReached"))
|
||||
{
|
||||
Selected = EndRoundAtLevelEnd,
|
||||
OnSelected = (GUITickBox) => { EndRoundAtLevelEnd = GUITickBox.Selected; return true; }
|
||||
};
|
||||
|
||||
var endVoteBox = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.05f), roundsTab.RectTransform),
|
||||
TextManager.Get("ServerSettingsEndRoundVoting"))
|
||||
{
|
||||
Selected = Voting.AllowEndVoting,
|
||||
OnSelected = (GUITickBox) =>
|
||||
{
|
||||
Voting.AllowEndVoting = !Voting.AllowEndVoting;
|
||||
GameMain.Server.UpdateVoteStatus();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
CreateLabeledSlider(roundsTab, "ServerSettingsEndRoundVotesRequired", out GUIScrollBar slider, out GUITextBlock sliderLabel);
|
||||
|
||||
string endRoundLabel = sliderLabel.Text;
|
||||
slider.Step = 0.2f;
|
||||
slider.BarScroll = (EndVoteRequiredRatio - 0.5f) * 2.0f;
|
||||
slider.OnMoved = (GUIScrollBar scrollBar, float barScroll) =>
|
||||
{
|
||||
EndVoteRequiredRatio = barScroll / 2.0f + 0.5f;
|
||||
voteText.Text = "Votes required: " + (int)MathUtils.Round(EndVoteRequiredRatio * 100.0f, 10.0f) + " %";
|
||||
((GUITextBlock)scrollBar.UserData).Text = endRoundLabel + (int)MathUtils.Round(EndVoteRequiredRatio * 100.0f, 10.0f) + " %";
|
||||
return true;
|
||||
};
|
||||
votesRequiredSlider.OnMoved(votesRequiredSlider, votesRequiredSlider.BarScroll);
|
||||
|
||||
y += 35;
|
||||
|
||||
var respawnBox = new GUITickBox(new Rectangle(0, y, 20, 20), "Allow respawning", Alignment.Left, settingsTabs[0]);
|
||||
respawnBox.Selected = AllowRespawn;
|
||||
respawnBox.OnSelected = (GUITickBox) =>
|
||||
slider.OnMoved(slider, slider.BarScroll);
|
||||
|
||||
var respawnBox = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.05f), roundsTab.RectTransform),
|
||||
TextManager.Get("ServerSettingsAllowRespawning"))
|
||||
{
|
||||
AllowRespawn = !AllowRespawn;
|
||||
return true;
|
||||
Selected = AllowRespawn,
|
||||
OnSelected = (GUITickBox) =>
|
||||
{
|
||||
AllowRespawn = !AllowRespawn;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
var respawnIntervalText = new GUITextBlock(new Rectangle(20, y + 13, 20, 20), "Respawn interval", "", settingsTabs[0], GUI.SmallFont);
|
||||
|
||||
var respawnIntervalSlider = new GUIScrollBar(new Rectangle(150, y + 20, 100, 15), "", 0.1f, settingsTabs[0]);
|
||||
respawnIntervalSlider.UserData = respawnIntervalText;
|
||||
respawnIntervalSlider.Step = 0.05f;
|
||||
respawnIntervalSlider.BarScroll = RespawnInterval / 600.0f;
|
||||
respawnIntervalSlider.OnMoved = (GUIScrollBar scrollBar, float barScroll) =>
|
||||
CreateLabeledSlider(roundsTab, "ServerSettingsRespawnInterval", out slider, out sliderLabel);
|
||||
string intervalLabel = sliderLabel.Text;
|
||||
slider.Step = 0.05f;
|
||||
slider.BarScroll = RespawnInterval / 600.0f;
|
||||
slider.OnMoved = (GUIScrollBar scrollBar, float barScroll) =>
|
||||
{
|
||||
GUITextBlock text = scrollBar.UserData as GUITextBlock;
|
||||
|
||||
RespawnInterval = Math.Max(barScroll * 600.0f, 10.0f);
|
||||
text.Text = "Interval: " + ToolBox.SecondsToReadableTime(RespawnInterval);
|
||||
text.Text = intervalLabel + ToolBox.SecondsToReadableTime(RespawnInterval);
|
||||
return true;
|
||||
};
|
||||
respawnIntervalSlider.OnMoved(respawnIntervalSlider, respawnIntervalSlider.BarScroll);
|
||||
|
||||
y += 35;
|
||||
|
||||
var minRespawnText = new GUITextBlock(new Rectangle(0, y, 200, 20), "Minimum players to respawn", "", settingsTabs[0]);
|
||||
minRespawnText.ToolTip = "What percentage of players has to be dead/spectating until a respawn shuttle is dispatched";
|
||||
|
||||
var minRespawnSlider = new GUIScrollBar(new Rectangle(150, y + 20, 100, 15), "", 0.1f, settingsTabs[0]);
|
||||
minRespawnSlider.ToolTip = minRespawnText.ToolTip;
|
||||
minRespawnSlider.UserData = minRespawnText;
|
||||
minRespawnSlider.Step = 0.1f;
|
||||
minRespawnSlider.BarScroll = MinRespawnRatio;
|
||||
minRespawnSlider.OnMoved = (GUIScrollBar scrollBar, float barScroll) =>
|
||||
slider.OnMoved(slider, slider.BarScroll);
|
||||
|
||||
var minRespawnText = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.05f), roundsTab.RectTransform), "")
|
||||
{
|
||||
GUITextBlock txt = scrollBar.UserData as GUITextBlock;
|
||||
ToolTip = TextManager.Get("ServerSettingsMinRespawnToolTip")
|
||||
};
|
||||
|
||||
string minRespawnLabel = TextManager.Get("ServerSettingsMinRespawn");
|
||||
CreateLabeledSlider(roundsTab, "", out slider, out sliderLabel);
|
||||
slider.ToolTip = minRespawnText.ToolTip;
|
||||
slider.UserData = minRespawnText;
|
||||
slider.Step = 0.1f;
|
||||
slider.BarScroll = MinRespawnRatio;
|
||||
slider.OnMoved = (GUIScrollBar scrollBar, float barScroll) =>
|
||||
{
|
||||
MinRespawnRatio = barScroll;
|
||||
txt.Text = "Minimum players to respawn: " + (int)MathUtils.Round(MinRespawnRatio * 100.0f, 10.0f) + " %";
|
||||
((GUITextBlock)scrollBar.UserData).Text = minRespawnLabel + (int)MathUtils.Round(MinRespawnRatio * 100.0f, 10.0f) + " %";
|
||||
return true;
|
||||
};
|
||||
minRespawnSlider.OnMoved(minRespawnSlider, MinRespawnRatio);
|
||||
|
||||
y += 30;
|
||||
|
||||
var respawnDurationText = new GUITextBlock(new Rectangle(0, y, 200, 20), "Duration of respawn transport", "", settingsTabs[0]);
|
||||
respawnDurationText.ToolTip = "The amount of time respawned players have to navigate the respawn shuttle to the main submarine. " +
|
||||
"After the duration expires, the shuttle will automatically head back out of the level.";
|
||||
|
||||
var respawnDurationSlider = new GUIScrollBar(new Rectangle(150, y + 20, 100, 15), "", 0.1f, settingsTabs[0]);
|
||||
respawnDurationSlider.ToolTip = minRespawnText.ToolTip;
|
||||
respawnDurationSlider.UserData = respawnDurationText;
|
||||
respawnDurationSlider.Step = 0.1f;
|
||||
respawnDurationSlider.BarScroll = MaxTransportTime <= 0.0f ? 1.0f : (MaxTransportTime - 60.0f) / 600.0f;
|
||||
respawnDurationSlider.OnMoved = (GUIScrollBar scrollBar, float barScroll) =>
|
||||
slider.OnMoved(slider, MinRespawnRatio);
|
||||
|
||||
var respawnDurationText = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.05f), roundsTab.RectTransform), "")
|
||||
{
|
||||
GUITextBlock txt = scrollBar.UserData as GUITextBlock;
|
||||
ToolTip = TextManager.Get("ServerSettingsRespawnDurationToolTip")
|
||||
};
|
||||
|
||||
string respawnDurationLabel = TextManager.Get("ServerSettingsRespawnDuration");
|
||||
CreateLabeledSlider(roundsTab, "", out slider, out sliderLabel);
|
||||
slider.ToolTip = respawnDurationText.ToolTip;
|
||||
slider.UserData = respawnDurationText;
|
||||
slider.Step = 0.1f;
|
||||
slider.BarScroll = MaxTransportTime <= 0.0f ? 1.0f : (MaxTransportTime - 60.0f) / 600.0f;
|
||||
slider.OnMoved = (GUIScrollBar scrollBar, float barScroll) =>
|
||||
{
|
||||
if (barScroll == 1.0f)
|
||||
{
|
||||
MaxTransportTime = 0;
|
||||
txt.Text = "Duration of respawn transport: unlimited";
|
||||
((GUITextBlock)scrollBar.UserData).Text = respawnDurationLabel + "unlimited";
|
||||
}
|
||||
else
|
||||
{
|
||||
MaxTransportTime = barScroll * 600.0f + 60.0f;
|
||||
txt.Text = "Duration of respawn transport: " + ToolBox.SecondsToReadableTime(MaxTransportTime);
|
||||
((GUITextBlock)scrollBar.UserData).Text = respawnDurationLabel + ToolBox.SecondsToReadableTime(MaxTransportTime);
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
respawnDurationSlider.OnMoved(respawnDurationSlider, respawnDurationSlider.BarScroll);
|
||||
slider.OnMoved(slider, slider.BarScroll);
|
||||
|
||||
var buttonHolder = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.07f), roundsTab.RectTransform), isHorizontal: true)
|
||||
{
|
||||
Stretch = true,
|
||||
RelativeSpacing = 0.05f
|
||||
};
|
||||
|
||||
y += 35;
|
||||
|
||||
var monsterButton = new GUIButton(new Rectangle(0, y, 130, 20), "Monster Spawns", "", settingsTabs[0]);
|
||||
monsterButton.Enabled = !GameStarted;
|
||||
var monsterFrame = new GUIListBox(new Rectangle(-290, 60, 280, 250), "", settingsTabs[0]);
|
||||
monsterFrame.Visible = false;
|
||||
monsterFrame.ClampMouseRectToParent = false;
|
||||
var monsterButton = new GUIButton(new RectTransform(new Vector2(0.5f, 1.0f), buttonHolder.RectTransform),
|
||||
TextManager.Get("ServerSettingsMonsterSpawns"))
|
||||
{
|
||||
Enabled = !GameStarted
|
||||
};
|
||||
var monsterFrame = new GUIListBox(new RectTransform(new Vector2(0.6f, 0.7f), settingsTabs[(int)SettingsTab.Rounds].RectTransform, Anchor.BottomLeft, Pivot.BottomRight))
|
||||
{
|
||||
Visible = false
|
||||
};
|
||||
monsterButton.UserData = monsterFrame;
|
||||
monsterButton.OnClicked = (button, obj) =>
|
||||
{
|
||||
@@ -203,36 +244,33 @@ namespace Barotrauma.Networking
|
||||
List<string> monsterNames = monsterEnabled.Keys.ToList();
|
||||
foreach (string s in monsterNames)
|
||||
{
|
||||
GUITextBlock textBlock = new GUITextBlock(
|
||||
new Rectangle(0, 0, 260, 25),
|
||||
s,
|
||||
"",
|
||||
Alignment.Left, Alignment.Left, monsterFrame);
|
||||
textBlock.Padding = new Vector4(35.0f, 3.0f, 0.0f, 0.0f);
|
||||
textBlock.UserData = monsterFrame;
|
||||
textBlock.CanBeFocused = false;
|
||||
|
||||
var monsterEnabledBox = new GUITickBox(new Rectangle(-25, 0, 20, 20), "", Alignment.Left, textBlock);
|
||||
monsterEnabledBox.Selected = monsterEnabled[s];
|
||||
monsterEnabledBox.OnSelected = (GUITickBox) =>
|
||||
var monsterEnabledBox = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.1f), monsterFrame.Content.RectTransform) { MinSize = new Point(0, 25) },
|
||||
label: s)
|
||||
{
|
||||
if (gameStarted)
|
||||
Selected = monsterEnabled[s],
|
||||
OnSelected = (GUITickBox) =>
|
||||
{
|
||||
monsterFrame.Visible = false;
|
||||
monsterButton.Enabled = false;
|
||||
if (gameStarted)
|
||||
{
|
||||
monsterFrame.Visible = false;
|
||||
monsterButton.Enabled = false;
|
||||
return true;
|
||||
}
|
||||
monsterEnabled[s] = !monsterEnabled[s];
|
||||
return true;
|
||||
}
|
||||
monsterEnabled[s] = !monsterEnabled[s];
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
var cargoButton = new GUIButton(new Rectangle(160, y, 130, 20), "Additional Cargo", "", settingsTabs[0]);
|
||||
cargoButton.Enabled = !GameStarted;
|
||||
|
||||
var cargoFrame = new GUIListBox(new Rectangle(300, 60, 280, 250), "", settingsTabs[0]);
|
||||
cargoFrame.Visible = false;
|
||||
cargoFrame.ClampMouseRectToParent = false;
|
||||
var cargoButton = new GUIButton(new RectTransform(new Vector2(0.5f, 1.0f), buttonHolder.RectTransform),
|
||||
TextManager.Get("ServerSettingsAdditionalCargo"))
|
||||
{
|
||||
Enabled = !GameStarted
|
||||
};
|
||||
var cargoFrame = new GUIListBox(new RectTransform(new Vector2(0.6f, 0.7f), settingsTabs[(int)SettingsTab.Rounds].RectTransform, Anchor.BottomRight, Pivot.BottomLeft))
|
||||
{
|
||||
Visible = false
|
||||
};
|
||||
cargoButton.UserData = cargoFrame;
|
||||
cargoButton.OnClicked = (button, obj) =>
|
||||
{
|
||||
@@ -250,31 +288,32 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
ItemPrefab ip = pf as ItemPrefab;
|
||||
|
||||
if (ip == null || (ip.Price <= 0.0f && !ip.Tags.Contains("smallitem"))) continue;
|
||||
|
||||
GUITextBlock textBlock = new GUITextBlock(
|
||||
new Rectangle(0, 0, 260, 25),
|
||||
ip.Name, "",
|
||||
Alignment.Left, Alignment.CenterLeft, cargoFrame, false, GUI.SmallFont);
|
||||
textBlock.Padding = new Vector4(40.0f, 3.0f, 0.0f, 0.0f);
|
||||
textBlock.UserData = cargoFrame;
|
||||
textBlock.CanBeFocused = false;
|
||||
if (ip == null || (!ip.CanBeBought && !ip.Tags.Contains("smallitem"))) continue;
|
||||
|
||||
GUITextBlock textBlock = new GUITextBlock(new RectTransform(new Vector2(0.9f, 0.15f), cargoFrame.Content.RectTransform) { MinSize = new Point(0, 30) },
|
||||
ip.Name, font: GUI.SmallFont)
|
||||
{
|
||||
Padding = new Vector4(40.0f, 3.0f, 0.0f, 0.0f),
|
||||
UserData = cargoFrame,
|
||||
CanBeFocused = false
|
||||
};
|
||||
|
||||
if (ip.sprite != null)
|
||||
{
|
||||
float scale = Math.Min(Math.Min(30.0f / ip.sprite.SourceRect.Width, 30.0f / ip.sprite.SourceRect.Height), 1.0f);
|
||||
GUIImage img = new GUIImage(new Rectangle(-20 - (int)(ip.sprite.SourceRect.Width * scale * 0.5f), 12 - (int)(ip.sprite.SourceRect.Height * scale * 0.5f), 40, 40), ip.sprite, Alignment.Left, textBlock);
|
||||
img.Color = ip.SpriteColor;
|
||||
img.Scale = scale;
|
||||
GUIImage img = new GUIImage(new RectTransform(new Point(textBlock.Rect.Height), textBlock.RectTransform), ip.sprite, scaleToFit: true)
|
||||
{
|
||||
Color = ip.SpriteColor
|
||||
};
|
||||
}
|
||||
|
||||
int cargoVal = 0;
|
||||
extraCargo.TryGetValue(ip, out cargoVal);
|
||||
var amountInput = new GUINumberInput(new Rectangle(160, 0, 50, 20), "", GUINumberInput.NumberType.Int, textBlock);
|
||||
amountInput.MinValueInt = 0;
|
||||
amountInput.MaxValueInt = 100;
|
||||
amountInput.IntValue = cargoVal;
|
||||
|
||||
extraCargo.TryGetValue(ip, out int cargoVal);
|
||||
var amountInput = new GUINumberInput(new RectTransform(new Vector2(0.3f, 1.0f), textBlock.RectTransform, Anchor.CenterRight),
|
||||
GUINumberInput.NumberType.Int)
|
||||
{
|
||||
MinValueInt = 0,
|
||||
MaxValueInt = 100,
|
||||
IntValue = cargoVal
|
||||
};
|
||||
amountInput.OnValueChanged += (numberInput) =>
|
||||
{
|
||||
if (extraCargo.ContainsKey(ip))
|
||||
@@ -292,195 +331,193 @@ namespace Barotrauma.Networking
|
||||
//--------------------------------------------------------------------------------
|
||||
// server settings
|
||||
//--------------------------------------------------------------------------------
|
||||
|
||||
y = 0;
|
||||
|
||||
|
||||
var startIntervalText = new GUITextBlock(new Rectangle(-10, y, 100, 20), "Autorestart delay", "", settingsTabs[1]);
|
||||
var startIntervalSlider = new GUIScrollBar(new Rectangle(10, y + 22, 100, 15), "", 0.1f, settingsTabs[1]);
|
||||
startIntervalSlider.UserData = startIntervalText;
|
||||
startIntervalSlider.Step = 0.05f;
|
||||
startIntervalSlider.BarScroll = AutoRestartInterval / 300.0f;
|
||||
startIntervalSlider.OnMoved = (GUIScrollBar scrollBar, float barScroll) =>
|
||||
|
||||
var serverTab = new GUILayoutGroup(new RectTransform(new Vector2(0.95f, 0.95f), settingsTabs[(int)SettingsTab.Server].RectTransform, Anchor.Center))
|
||||
{
|
||||
GUITextBlock text = scrollBar.UserData as GUITextBlock;
|
||||
Stretch = true,
|
||||
RelativeSpacing = 0.02f
|
||||
};
|
||||
|
||||
AutoRestartInterval = Math.Max(barScroll * 300.0f, 10.0f);
|
||||
|
||||
text.Text = "Autorestart delay: " + ToolBox.SecondsToReadableTime(AutoRestartInterval);
|
||||
return true;
|
||||
string autoRestartDelayLabel = TextManager.Get("ServerSettingsAutoRestartDelay");
|
||||
var startIntervalText = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.05f), serverTab.RectTransform), autoRestartDelayLabel);
|
||||
var startIntervalSlider = new GUIScrollBar(new RectTransform(new Vector2(1.0f, 0.05f), serverTab.RectTransform), barSize: 0.1f)
|
||||
{
|
||||
UserData = startIntervalText,
|
||||
Step = 0.05f,
|
||||
BarScroll = AutoRestartInterval / 300.0f,
|
||||
OnMoved = (GUIScrollBar scrollBar, float barScroll) =>
|
||||
{
|
||||
GUITextBlock text = scrollBar.UserData as GUITextBlock;
|
||||
AutoRestartInterval = Math.Max(barScroll * 300.0f, 10.0f);
|
||||
text.Text = autoRestartDelayLabel + ToolBox.SecondsToReadableTime(AutoRestartInterval);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
startIntervalSlider.OnMoved(startIntervalSlider, startIntervalSlider.BarScroll);
|
||||
|
||||
y += 45;
|
||||
//***********************************************
|
||||
|
||||
var allowSpecBox = new GUITickBox(new Rectangle(0, y, 20, 20), "Allow spectating", Alignment.Left, settingsTabs[1]);
|
||||
allowSpecBox.Selected = AllowSpectating;
|
||||
allowSpecBox.OnSelected = (GUITickBox) =>
|
||||
var startWhenClientsReady = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.05f), serverTab.RectTransform),
|
||||
TextManager.Get("ServerSettingsStartWhenClientsReady"))
|
||||
{
|
||||
AllowSpectating = GUITickBox.Selected;
|
||||
GameMain.NetLobbyScreen.LastUpdateID++;
|
||||
return true;
|
||||
Selected = StartWhenClientsReady,
|
||||
OnSelected = (tickBox) =>
|
||||
{
|
||||
StartWhenClientsReady = tickBox.Selected;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
y += 20;
|
||||
|
||||
var voteKickBox = new GUITickBox(new Rectangle(0, y, 20, 20), "Allow vote kicking", Alignment.Left, settingsTabs[1]);
|
||||
voteKickBox.Selected = Voting.AllowVoteKick;
|
||||
voteKickBox.OnSelected = (GUITickBox) =>
|
||||
CreateLabeledSlider(serverTab, "ServerSettingsStartWhenClientsReadyRatio", out slider, out sliderLabel);
|
||||
string clientsReadyRequiredLabel = sliderLabel.Text;
|
||||
slider.Step = 0.2f;
|
||||
slider.BarScroll = (StartWhenClientsReadyRatio - 0.5f) * 2.0f;
|
||||
slider.OnMoved = (GUIScrollBar scrollBar, float barScroll) =>
|
||||
{
|
||||
Voting.AllowVoteKick = !Voting.AllowVoteKick;
|
||||
GameMain.Server.UpdateVoteStatus();
|
||||
StartWhenClientsReadyRatio = barScroll / 2.0f + 0.5f;
|
||||
((GUITextBlock)scrollBar.UserData).Text = clientsReadyRequiredLabel.Replace("[percentage]", ((int)MathUtils.Round(StartWhenClientsReadyRatio * 100.0f, 10.0f)).ToString());
|
||||
return true;
|
||||
};
|
||||
slider.OnMoved(slider, slider.BarScroll);
|
||||
|
||||
var kickVotesRequiredText = new GUITextBlock(new Rectangle(20, y + 20, 20, 20), "Votes required: 50 %", "", settingsTabs[1], GUI.SmallFont);
|
||||
//***********************************************
|
||||
|
||||
var kickVoteSlider = new GUIScrollBar(new Rectangle(150, y + 22, 100, 15), "", 0.1f, settingsTabs[1]);
|
||||
kickVoteSlider.UserData = kickVotesRequiredText;
|
||||
kickVoteSlider.Step = 0.2f;
|
||||
kickVoteSlider.BarScroll = (KickVoteRequiredRatio - 0.5f) * 2.0f;
|
||||
kickVoteSlider.OnMoved = (GUIScrollBar scrollBar, float barScroll) =>
|
||||
var allowSpecBox = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.05f), serverTab.RectTransform), TextManager.Get("ServerSettingsAllowSpectating"))
|
||||
{
|
||||
GUITextBlock voteText = scrollBar.UserData as GUITextBlock;
|
||||
Selected = AllowSpectating,
|
||||
OnSelected = (GUITickBox) =>
|
||||
{
|
||||
AllowSpectating = GUITickBox.Selected;
|
||||
GameMain.NetLobbyScreen.LastUpdateID++;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
var voteKickBox = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.05f), serverTab.RectTransform), TextManager.Get("ServerSettingsAllowVoteKick"))
|
||||
{
|
||||
Selected = Voting.AllowVoteKick,
|
||||
OnSelected = (GUITickBox) =>
|
||||
{
|
||||
Voting.AllowVoteKick = !Voting.AllowVoteKick;
|
||||
GameMain.Server.UpdateVoteStatus();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
CreateLabeledSlider(serverTab, "ServerSettingsKickVotesRequired", out slider, out sliderLabel);
|
||||
string votesRequiredLabel = sliderLabel.Text;
|
||||
slider.Step = 0.2f;
|
||||
slider.BarScroll = (KickVoteRequiredRatio - 0.5f) * 2.0f;
|
||||
slider.OnMoved = (GUIScrollBar scrollBar, float barScroll) =>
|
||||
{
|
||||
KickVoteRequiredRatio = barScroll / 2.0f + 0.5f;
|
||||
voteText.Text = "Votes required: " + (int)MathUtils.Round(KickVoteRequiredRatio * 100.0f, 10.0f) + " %";
|
||||
((GUITextBlock)scrollBar.UserData).Text = votesRequiredLabel + (int)MathUtils.Round(KickVoteRequiredRatio * 100.0f, 10.0f) + " %";
|
||||
return true;
|
||||
};
|
||||
kickVoteSlider.OnMoved(kickVoteSlider, kickVoteSlider.BarScroll);
|
||||
slider.OnMoved(slider, slider.BarScroll);
|
||||
|
||||
y += 20;
|
||||
|
||||
var autobanTimeText = new GUITextBlock(new Rectangle(20, y + 20, 20, 20), $"Auto ban time: " + ToolBox.SecondsToReadableTime(AutoBanTime), "", settingsTabs[1], GUI.SmallFont);
|
||||
|
||||
var autobanTimeSlider = new GUIScrollBar(new Rectangle(150, y + 22, 100, 15), "", 0.1f, settingsTabs[1]);
|
||||
autobanTimeSlider.UserData = autobanTimeText;
|
||||
autobanTimeSlider.Step = 0.05f;
|
||||
autobanTimeSlider.BarScroll = AutoBanTime / MaxAutoBanTime;
|
||||
autobanTimeSlider.OnMoved = (GUIScrollBar scrollBar, float barScroll) =>
|
||||
CreateLabeledSlider(serverTab, "ServerSettingsAutobanTime", out slider, out sliderLabel);
|
||||
string autobanLabel = sliderLabel.Text;
|
||||
slider.Step = 0.05f;
|
||||
slider.BarScroll = AutoBanTime / MaxAutoBanTime;
|
||||
slider.OnMoved = (GUIScrollBar scrollBar, float barScroll) =>
|
||||
{
|
||||
GUITextBlock voteText = scrollBar.UserData as GUITextBlock;
|
||||
AutoBanTime = Math.Max(barScroll * MaxAutoBanTime, 0);
|
||||
voteText.Text = "Auto ban time: " + ToolBox.SecondsToReadableTime(AutoBanTime);
|
||||
((GUITextBlock)scrollBar.UserData).Text = autobanLabel + ToolBox.SecondsToReadableTime(AutoBanTime);
|
||||
return true;
|
||||
};
|
||||
autobanTimeSlider.OnMoved(autobanTimeSlider, autobanTimeSlider.BarScroll);
|
||||
slider.OnMoved(slider, slider.BarScroll);
|
||||
|
||||
y += 45;
|
||||
|
||||
var shareSubsBox = new GUITickBox(new Rectangle(0, y, 20, 20), "Share submarine files with players", Alignment.Left, settingsTabs[1]);
|
||||
shareSubsBox.Selected = AllowFileTransfers;
|
||||
shareSubsBox.OnSelected = (GUITickBox) =>
|
||||
var shareSubsBox = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.05f), serverTab.RectTransform), TextManager.Get("ServerSettingsShareSubFiles"))
|
||||
{
|
||||
AllowFileTransfers = GUITickBox.Selected;
|
||||
return true;
|
||||
Selected = AllowFileTransfers,
|
||||
OnSelected = (GUITickBox) =>
|
||||
{
|
||||
AllowFileTransfers = GUITickBox.Selected;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
y += 20;
|
||||
|
||||
var randomizeLevelBox = new GUITickBox(new Rectangle(0, y, 20, 20), "Randomize level seed between rounds", Alignment.Left, settingsTabs[1]);
|
||||
randomizeLevelBox.Selected = RandomizeSeed;
|
||||
randomizeLevelBox.OnSelected = (GUITickBox) =>
|
||||
var randomizeLevelBox = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.05f), serverTab.RectTransform), TextManager.Get("ServerSettingsRandomizeSeed"))
|
||||
{
|
||||
RandomizeSeed = GUITickBox.Selected;
|
||||
return true;
|
||||
Selected = RandomizeSeed,
|
||||
OnSelected = (GUITickBox) =>
|
||||
{
|
||||
RandomizeSeed = GUITickBox.Selected;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
y += 20;
|
||||
|
||||
var saveLogsBox = new GUITickBox(new Rectangle(0, y, 20, 20), "Save server logs", Alignment.Left, settingsTabs[1]);
|
||||
saveLogsBox.Selected = SaveServerLogs;
|
||||
saveLogsBox.OnSelected = (GUITickBox) =>
|
||||
var saveLogsBox = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.05f), serverTab.RectTransform), TextManager.Get("ServerSettingsSaveLogs"))
|
||||
{
|
||||
SaveServerLogs = GUITickBox.Selected;
|
||||
showLogButton.Visible = SaveServerLogs;
|
||||
return true;
|
||||
Selected = SaveServerLogs,
|
||||
OnSelected = (GUITickBox) =>
|
||||
{
|
||||
SaveServerLogs = GUITickBox.Selected;
|
||||
showLogButton.Visible = SaveServerLogs;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
y += 20;
|
||||
|
||||
var ragdollButtonBox = new GUITickBox(new Rectangle(0, y, 20, 20), "Allow ragdoll button", Alignment.Left, settingsTabs[1]);
|
||||
ragdollButtonBox.Selected = AllowRagdollButton;
|
||||
ragdollButtonBox.OnSelected = (GUITickBox) =>
|
||||
var ragdollButtonBox = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.05f), serverTab.RectTransform), TextManager.Get("ServerSettingsAllowRagdollButton"))
|
||||
{
|
||||
AllowRagdollButton = GUITickBox.Selected;
|
||||
return true;
|
||||
Selected = AllowRagdollButton,
|
||||
OnSelected = (GUITickBox) =>
|
||||
{
|
||||
AllowRagdollButton = GUITickBox.Selected;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
var traitorRatioBox = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.05f), serverTab.RectTransform), TextManager.Get("ServerSettingsUseTraitorRatio"));
|
||||
|
||||
y += 20;
|
||||
|
||||
var traitorRatioBox = new GUITickBox(new Rectangle(0, y, 20, 20), "Use % of players for max traitors", Alignment.Left, settingsTabs[1]);
|
||||
var traitorRatioText = new GUITextBlock(new Rectangle(20, y + 20, 20, 20), "Traitor ratio: 20 %", "", settingsTabs[1], GUI.SmallFont);
|
||||
var traitorRatioSlider = new GUIScrollBar(new Rectangle(150, y + 22, 100, 15), "", 0.1f, settingsTabs[1]);
|
||||
//Prepare the slider before the tick box
|
||||
if (TraitorUseRatio)
|
||||
{
|
||||
traitorRatioSlider.UserData = traitorRatioText;
|
||||
traitorRatioSlider.Step = 0.01f; //Lots of fine-tuning
|
||||
traitorRatioSlider.BarScroll = (TraitorRatio - 0.1f) / 0.9f;
|
||||
}
|
||||
else
|
||||
{
|
||||
traitorRatioSlider.UserData = traitorRatioText;
|
||||
traitorRatioSlider.Step = 1f / (maxPlayers-1);
|
||||
traitorRatioSlider.BarScroll = MathUtils.Round(TraitorRatio, 1f);
|
||||
}
|
||||
//Slider END
|
||||
|
||||
CreateLabeledSlider(serverTab, "", out slider, out sliderLabel);
|
||||
/*var traitorRatioText = new GUITextBlock(new Rectangle(20, y + 20, 20, 20), "Traitor ratio: 20 %", "", settingsTabs[1], GUI.SmallFont);
|
||||
var traitorRatioSlider = new GUIScrollBar(new Rectangle(150, y + 22, 100, 15), "", 0.1f, settingsTabs[1]);*/
|
||||
var traitorRatioSlider = slider;
|
||||
traitorRatioBox.Selected = TraitorUseRatio;
|
||||
traitorRatioBox.OnSelected = (GUITickBox) =>
|
||||
{
|
||||
TraitorUseRatio = GUITickBox.Selected;
|
||||
//Affect the slider graphics
|
||||
if (TraitorUseRatio)
|
||||
{
|
||||
traitorRatioSlider.UserData = traitorRatioText;
|
||||
traitorRatioSlider.Step = 0.01f; //Lots of fine-tuning
|
||||
traitorRatioSlider.BarScroll = 0.2f; //default values
|
||||
traitorRatioSlider.OnMoved(traitorRatioSlider, traitorRatioSlider.BarScroll); //Update the scroll bar
|
||||
}
|
||||
else
|
||||
{
|
||||
traitorRatioSlider.UserData = traitorRatioText;
|
||||
traitorRatioSlider.Step = 1f / (maxPlayers-1);
|
||||
traitorRatioSlider.BarScroll = 1; //default values
|
||||
traitorRatioSlider.OnMoved(traitorRatioSlider, traitorRatioSlider.BarScroll); //Update the scroll bar
|
||||
}
|
||||
traitorRatioSlider.Step = TraitorUseRatio ? 0.01f : 1f / (maxPlayers - 1);
|
||||
traitorRatioSlider.OnMoved(traitorRatioSlider, traitorRatioSlider.BarScroll);
|
||||
return true;
|
||||
};
|
||||
|
||||
string traitorRatioLabel = TextManager.Get("ServerSettingsTraitorRatio");
|
||||
string traitorCountLabel = TextManager.Get("ServerSettingsTraitorCount");
|
||||
traitorRatioSlider.OnMoved = (GUIScrollBar scrollBar, float barScroll) =>
|
||||
{
|
||||
GUITextBlock traitorText = scrollBar.UserData as GUITextBlock;
|
||||
if (TraitorUseRatio)
|
||||
{
|
||||
TraitorRatio = barScroll * 0.9f + 0.1f;
|
||||
traitorText.Text = "Traitor ratio: " + (int)MathUtils.Round(TraitorRatio * 100.0f, 1.0f) + " %";
|
||||
traitorText.Text = traitorRatioLabel + (int)MathUtils.Round(TraitorRatio * 100.0f, 1.0f) + " %";
|
||||
}
|
||||
else
|
||||
{
|
||||
TraitorRatio = MathUtils.Round(barScroll * (maxPlayers-1), 1f) + 1;
|
||||
traitorText.Text = "Traitor count: " + TraitorRatio;
|
||||
traitorText.Text = traitorCountLabel + TraitorRatio;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
traitorRatioSlider.OnMoved(traitorRatioSlider, traitorRatioSlider.BarScroll);
|
||||
|
||||
y += 45;
|
||||
|
||||
var karmaButtonBox = new GUITickBox(new Rectangle(0, y, 20, 20), "Use Karma", Alignment.Left, settingsTabs[1]);
|
||||
karmaButtonBox.Selected = KarmaEnabled;
|
||||
karmaButtonBox.OnSelected = (GUITickBox) =>
|
||||
traitorRatioBox.OnSelected(traitorRatioBox);
|
||||
|
||||
new GUITickBox(new RectTransform(new Vector2(1.0f, 0.05f), serverTab.RectTransform), TextManager.Get("ServerSettingsUseKarma"))
|
||||
{
|
||||
KarmaEnabled = GUITickBox.Selected;
|
||||
return true;
|
||||
Selected = KarmaEnabled,
|
||||
OnSelected = (GUITickBox) =>
|
||||
{
|
||||
KarmaEnabled = GUITickBox.Selected;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
// banlist
|
||||
//--------------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
banList.CreateBanFrame(settingsTabs[2]);
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
@@ -491,24 +528,30 @@ namespace Barotrauma.Networking
|
||||
|
||||
}
|
||||
|
||||
private void CreateLabeledSlider(GUIComponent parent, string labelTag, out GUIScrollBar slider, out GUITextBlock label)
|
||||
{
|
||||
var container = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.05f), parent.RectTransform), isHorizontal: true)
|
||||
{
|
||||
Stretch = true,
|
||||
RelativeSpacing = 0.05f
|
||||
};
|
||||
|
||||
slider = new GUIScrollBar(new RectTransform(new Vector2(0.5f, 0.8f), container.RectTransform), barSize: 0.1f);
|
||||
label = new GUITextBlock(new RectTransform(new Vector2(0.5f, 0.8f), container.RectTransform),
|
||||
string.IsNullOrEmpty(labelTag) ? "" : TextManager.Get(labelTag), font: GUI.SmallFont);
|
||||
|
||||
//slider has a reference to the label to change the text when it's used
|
||||
slider.UserData = label;
|
||||
}
|
||||
|
||||
private bool SwitchSubSelection(GUITickBox tickBox)
|
||||
{
|
||||
subSelectionMode = (SelectionMode)tickBox.UserData;
|
||||
|
||||
foreach (GUIComponent otherTickBox in tickBox.Parent.children)
|
||||
{
|
||||
if (otherTickBox == tickBox) continue;
|
||||
((GUITickBox)otherTickBox).Selected = false;
|
||||
}
|
||||
|
||||
Voting.AllowSubVoting = subSelectionMode == SelectionMode.Vote;
|
||||
|
||||
if (subSelectionMode == SelectionMode.Random)
|
||||
{
|
||||
GameMain.NetLobbyScreen.SubList.Select(Rand.Range(0, GameMain.NetLobbyScreen.SubList.CountChildren));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -527,20 +570,11 @@ namespace Barotrauma.Networking
|
||||
private bool SwitchModeSelection(GUITickBox tickBox)
|
||||
{
|
||||
modeSelectionMode = (SelectionMode)tickBox.UserData;
|
||||
|
||||
foreach (GUIComponent otherTickBox in tickBox.Parent.children)
|
||||
{
|
||||
if (otherTickBox == tickBox) continue;
|
||||
((GUITickBox)otherTickBox).Selected = false;
|
||||
}
|
||||
|
||||
Voting.AllowModeVoting = modeSelectionMode == SelectionMode.Vote;
|
||||
|
||||
if (modeSelectionMode == SelectionMode.Random)
|
||||
{
|
||||
GameMain.NetLobbyScreen.ModeList.Select(Rand.Range(0, GameMain.NetLobbyScreen.ModeList.CountChildren));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -562,38 +596,40 @@ namespace Barotrauma.Networking
|
||||
|
||||
public void ManagePlayersFrame(GUIFrame infoFrame)
|
||||
{
|
||||
GUIListBox cList = new GUIListBox(new Rectangle(0, 0, 0, 300), Color.White * 0.7f, "", infoFrame);
|
||||
cList.Padding = new Vector4(10.0f, 10.0f, 10.0f, 10.0f);
|
||||
//crewList.OnSelected = SelectCrewCharacter;
|
||||
|
||||
GUIListBox cList = new GUIListBox(new RectTransform(Vector2.One, infoFrame.RectTransform));
|
||||
foreach (Client c in ConnectedClients)
|
||||
{
|
||||
GUIFrame frame = new GUIFrame(new Rectangle(0, 0, 0, 40), Color.Transparent, null, cList);
|
||||
frame.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f);
|
||||
frame.Color = (c.InGame && c.Character != null && !c.Character.IsDead) ? Color.Gold * 0.2f : Color.Transparent;
|
||||
frame.HoverColor = Color.LightGray * 0.5f;
|
||||
frame.SelectedColor = Color.Gold * 0.5f;
|
||||
var frame = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.15f), cList.Content.RectTransform),
|
||||
c.Name + " (" + c.Connection.RemoteEndPoint.Address.ToString() + ")", style: "ListBoxElement")
|
||||
{
|
||||
Color = (c.InGame && c.Character != null && !c.Character.IsDead) ? Color.Gold * 0.2f : Color.Transparent,
|
||||
HoverColor = Color.LightGray * 0.5f,
|
||||
SelectedColor = Color.Gold * 0.5f
|
||||
};
|
||||
|
||||
var buttonArea = new GUILayoutGroup(new RectTransform(new Vector2(0.45f, 0.85f), frame.RectTransform, Anchor.CenterRight) { RelativeOffset = new Vector2(0.05f, 0.0f) },
|
||||
isHorizontal: true);
|
||||
|
||||
var kickButton = new GUIButton(new RectTransform(new Vector2(0.25f, 1.0f), buttonArea.RectTransform),
|
||||
TextManager.Get("Kick"))
|
||||
{
|
||||
UserData = c.Name,
|
||||
OnClicked = GameMain.NetLobbyScreen.KickPlayer
|
||||
};
|
||||
|
||||
GUITextBlock textBlock = new GUITextBlock(
|
||||
new Rectangle(40, 0, 0, 25),
|
||||
c.Name + " (" + c.Connection.RemoteEndPoint.Address.ToString() + ")",
|
||||
Color.Transparent, Color.White,
|
||||
Alignment.Left, Alignment.Left,
|
||||
null, frame);
|
||||
var banButton = new GUIButton(new RectTransform(new Vector2(0.25f, 1.0f), buttonArea.RectTransform),
|
||||
TextManager.Get("Ban"))
|
||||
{
|
||||
UserData = c.Name,
|
||||
OnClicked = GameMain.NetLobbyScreen.BanPlayer
|
||||
};
|
||||
|
||||
var banButton = new GUIButton(new Rectangle(-110, 0, 100, 20), "Ban", Alignment.Right | Alignment.CenterY, "", frame);
|
||||
banButton.UserData = c.Name;
|
||||
banButton.OnClicked = GameMain.NetLobbyScreen.BanPlayer;
|
||||
|
||||
var rangebanButton = new GUIButton(new Rectangle(-220, 0, 100, 20), "Ban range", Alignment.Right | Alignment.CenterY, "", frame);
|
||||
rangebanButton.UserData = c.Name;
|
||||
rangebanButton.OnClicked = GameMain.NetLobbyScreen.BanPlayerRange;
|
||||
|
||||
var kickButton = new GUIButton(new Rectangle(0, 0, 100, 20), "Kick", Alignment.Right | Alignment.CenterY, "", frame);
|
||||
kickButton.UserData = c.Name;
|
||||
kickButton.OnClicked = GameMain.NetLobbyScreen.KickPlayer;
|
||||
|
||||
textBlock.Padding = new Vector4(5.0f, 0.0f, 5.0f, 0.0f);
|
||||
var rangebanButton = new GUIButton(new RectTransform(new Vector2(0.25f, 1.0f), buttonArea.RectTransform),
|
||||
TextManager.Get("BanRange"))
|
||||
{
|
||||
UserData = c.Name,
|
||||
OnClicked = GameMain.NetLobbyScreen.BanPlayerRange
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -74,7 +74,7 @@ namespace Barotrauma.Networking
|
||||
//find the index of the first event the server hasn't received
|
||||
int startIndex = events.Count;
|
||||
while (startIndex > 0 &&
|
||||
NetIdUtils.IdMoreRecent(events[startIndex-1].ID,thisClient.LastSentEntityEventID))
|
||||
NetIdUtils.IdMoreRecent(events[startIndex - 1].ID, thisClient.LastSentEntityEventID))
|
||||
{
|
||||
startIndex--;
|
||||
}
|
||||
@@ -154,7 +154,7 @@ namespace Barotrauma.Networking
|
||||
UInt16 thisEventID = (UInt16)(firstEventID + (UInt16)i);
|
||||
UInt16 entityID = msg.ReadUInt16();
|
||||
|
||||
if (entityID == 0)
|
||||
if (entityID == Entity.NullEntityID)
|
||||
{
|
||||
if (GameSettings.VerboseLogging)
|
||||
{
|
||||
|
||||
@@ -94,82 +94,4 @@ namespace Barotrauma.Networking
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
class Graph
|
||||
{
|
||||
public const int ArraySize = 100;
|
||||
|
||||
private float[] values;
|
||||
|
||||
public Graph()
|
||||
{
|
||||
values = new float[ArraySize];
|
||||
}
|
||||
|
||||
public float LargestValue()
|
||||
{
|
||||
float maxValue = 0.0f;
|
||||
for (int i = 0; i < values.Length; i++)
|
||||
{
|
||||
if (values[i] > maxValue) maxValue = values[i];
|
||||
}
|
||||
return maxValue;
|
||||
}
|
||||
|
||||
public float Average()
|
||||
{
|
||||
return values.Length == 0 ? 0.0f : values.Average();
|
||||
}
|
||||
|
||||
public void Update(float newValue)
|
||||
{
|
||||
for (int i = values.Length-1; i > 0; i--)
|
||||
{
|
||||
values[i] = values[i - 1];
|
||||
}
|
||||
values[0] = newValue;
|
||||
}
|
||||
|
||||
public void Draw(SpriteBatch spriteBatch, Rectangle rect, float? maxVal, float xOffset, Color color)
|
||||
{
|
||||
float graphMaxVal = 1.0f;
|
||||
if (maxVal == null)
|
||||
{
|
||||
graphMaxVal = LargestValue();
|
||||
}
|
||||
else if (maxVal > 0.0f)
|
||||
{
|
||||
graphMaxVal = (float)maxVal;
|
||||
}
|
||||
|
||||
GUI.DrawRectangle(spriteBatch, rect, Color.White);
|
||||
|
||||
if (values.Length == 0) return;
|
||||
|
||||
float lineWidth = (float)rect.Width / (float)(values.Length - 2);
|
||||
float yScale = (float)rect.Height / graphMaxVal;
|
||||
|
||||
Vector2 prevPoint = new Vector2(rect.Right, rect.Bottom - (values[1] + (values[0] - values[1]) * xOffset) * yScale);
|
||||
|
||||
float currX = rect.Right - ((xOffset - 1.0f) * lineWidth);
|
||||
|
||||
for (int i = 1; i < values.Length - 1; i++)
|
||||
{
|
||||
currX -= lineWidth;
|
||||
|
||||
Vector2 newPoint = new Vector2(currX, rect.Bottom - values[i] * yScale);
|
||||
|
||||
GUI.DrawLine(spriteBatch, prevPoint, newPoint - new Vector2(1.0f, 0), color);
|
||||
|
||||
prevPoint = newPoint;
|
||||
}
|
||||
|
||||
Vector2 lastPoint = new Vector2(rect.X,
|
||||
rect.Bottom - (values[values.Length - 1] + (values[values.Length - 2] - values[values.Length - 1]) * xOffset) * yScale);
|
||||
|
||||
GUI.DrawLine(spriteBatch, prevPoint, lastPoint, color);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Barotrauma.Items.Components;
|
||||
using Microsoft.Xna.Framework;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace Barotrauma.Networking
|
||||
{
|
||||
abstract partial class NetworkMember
|
||||
{
|
||||
protected CharacterInfo characterInfo;
|
||||
|
||||
protected Character myCharacter;
|
||||
|
||||
public CharacterInfo CharacterInfo
|
||||
@@ -22,79 +23,67 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
|
||||
protected GUIFrame inGameHUD;
|
||||
protected GUIListBox chatBox;
|
||||
protected GUITextBox chatMsgBox;
|
||||
protected ChatBox chatBox;
|
||||
protected GUIButton showLogButton;
|
||||
protected GUITickBox cameraFollowsSub;
|
||||
|
||||
private float myCharacterFrameOpenState;
|
||||
|
||||
public GUIFrame InGameHUD
|
||||
{
|
||||
get { return inGameHUD; }
|
||||
}
|
||||
|
||||
|
||||
public ChatBox ChatBox
|
||||
{
|
||||
get { return chatBox; }
|
||||
}
|
||||
|
||||
private void InitProjSpecific()
|
||||
{
|
||||
inGameHUD = new GUIFrame(new Rectangle(0, 0, 0, 0), null, null);
|
||||
inGameHUD.CanBeFocused = false;
|
||||
|
||||
showLogButton = new GUIButton(new Rectangle(GameMain.GraphicsWidth - 170 - 170, 20, 150, 20), "Server Log", Alignment.TopLeft, "", inGameHUD)
|
||||
inGameHUD = new GUIFrame(new RectTransform(Vector2.One, GUI.Canvas), style: null)
|
||||
{
|
||||
OnClicked = (GUIButton button, object userData) =>
|
||||
CanBeFocused = false
|
||||
};
|
||||
|
||||
cameraFollowsSub = new GUITickBox(new RectTransform(new Vector2(0.05f, 0.05f), inGameHUD.RectTransform, anchor: Anchor.TopCenter)
|
||||
{
|
||||
AbsoluteOffset = new Point(0, 5),
|
||||
MaxSize = new Point(25, 25)
|
||||
}, TextManager.Get("CamFollowSubmarine"))
|
||||
{
|
||||
Selected = Camera.FollowSub,
|
||||
OnSelected = (tbox) =>
|
||||
{
|
||||
if (ServerLog.LogFrame == null)
|
||||
{
|
||||
ServerLog.CreateLogFrame();
|
||||
}
|
||||
else
|
||||
{
|
||||
ServerLog.LogFrame = null;
|
||||
GUIComponent.KeyboardDispatcher.Subscriber = null;
|
||||
}
|
||||
Camera.FollowSub = tbox.Selected;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
cameraFollowsSub.OnSelected(cameraFollowsSub);
|
||||
|
||||
int width = (int)MathHelper.Clamp(GameMain.GraphicsWidth * 0.35f, 350, 500);
|
||||
int height = (int)MathHelper.Clamp(GameMain.GraphicsHeight * 0.15f, 100, 200);
|
||||
chatBox = new GUIListBox(new Rectangle(
|
||||
GameMain.GraphicsWidth - 20 - width,
|
||||
GameMain.GraphicsHeight - 40 - 25 - height,
|
||||
width, height),
|
||||
Color.White * 0.5f, "", inGameHUD);
|
||||
chatBox.Padding = Vector4.Zero;
|
||||
chatBox = new ChatBox(inGameHUD, isSinglePlayer: false);
|
||||
chatBox.OnEnterMessage += EnterChatMessage;
|
||||
chatBox.InputBox.OnTextChanged += TypingChatMessage;
|
||||
}
|
||||
|
||||
chatMsgBox = new GUITextBox(
|
||||
new Rectangle(chatBox.Rect.X, chatBox.Rect.Y + chatBox.Rect.Height + 20, chatBox.Rect.Width, 25),
|
||||
Color.White * 0.5f, Color.Black, Alignment.TopLeft, Alignment.Left, "", inGameHUD);
|
||||
chatMsgBox.Font = GUI.SmallFont;
|
||||
chatMsgBox.MaxTextLength = ChatMessage.MaxLength;
|
||||
chatMsgBox.Padding = Vector4.Zero;
|
||||
chatMsgBox.OnEnterPressed = EnterChatMessage;
|
||||
chatMsgBox.OnTextChanged = TypingChatMessage;
|
||||
protected void SetRadioButtonColor()
|
||||
{
|
||||
if (Character.Controlled == null || Character.Controlled.SpeechImpediment >= 100.0f)
|
||||
{
|
||||
chatBox.RadioButton.GetChild<GUIImage>().Color = new Color(60, 60, 60, 255);
|
||||
}
|
||||
else
|
||||
{
|
||||
var radioItem = Character.Controlled?.Inventory?.Items.FirstOrDefault(i => i?.GetComponent<WifiComponent>() != null);
|
||||
chatBox.RadioButton.GetChild<GUIImage>().Color =
|
||||
(radioItem != null && Character.Controlled.HasEquippedItem(radioItem) && radioItem.GetComponent<WifiComponent>().CanTransmit()) ?
|
||||
Color.White : new Color(60, 60, 60, 255);
|
||||
}
|
||||
}
|
||||
|
||||
public bool TypingChatMessage(GUITextBox textBox, string text)
|
||||
{
|
||||
string tempStr;
|
||||
string command = ChatMessage.GetChatMessageCommand(text, out tempStr);
|
||||
switch (command)
|
||||
{
|
||||
case "r":
|
||||
case "radio":
|
||||
textBox.TextColor = ChatMessage.MessageColor[(int)ChatMessageType.Radio];
|
||||
break;
|
||||
case "d":
|
||||
case "dead":
|
||||
textBox.TextColor = ChatMessage.MessageColor[(int)ChatMessageType.Dead];
|
||||
break;
|
||||
default:
|
||||
if (command != "") //PMing
|
||||
textBox.TextColor = ChatMessage.MessageColor[(int)ChatMessageType.Private];
|
||||
else
|
||||
textBox.TextColor = ChatMessage.MessageColor[(int)ChatMessageType.Default];
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
return chatBox.TypingChatMessage(textBox, text);
|
||||
}
|
||||
|
||||
public bool EnterChatMessage(GUITextBox textBox, string message)
|
||||
@@ -103,7 +92,7 @@ namespace Barotrauma.Networking
|
||||
|
||||
if (string.IsNullOrWhiteSpace(message))
|
||||
{
|
||||
if (textBox == chatMsgBox) textBox.Deselect();
|
||||
if (textBox == chatBox.InputBox) textBox.Deselect();
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -116,96 +105,178 @@ namespace Barotrauma.Networking
|
||||
GameMain.Client.SendChatMessage(message);
|
||||
}
|
||||
|
||||
if (textBox == chatMsgBox) textBox.Deselect();
|
||||
textBox.Deselect();
|
||||
textBox.Text = "";
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public virtual void AddToGUIUpdateList()
|
||||
{
|
||||
if (gameStarted && Screen.Selected == GameMain.GameScreen)
|
||||
if (GUI.DisableHUD) return;
|
||||
|
||||
if (gameStarted &&
|
||||
Screen.Selected == GameMain.GameScreen)
|
||||
{
|
||||
inGameHUD.AddToGUIUpdateList();
|
||||
|
||||
if (Character.Controlled == null)
|
||||
{
|
||||
GameMain.NetLobbyScreen.MyCharacterFrame.AddToGUIUpdateList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateHUD(float deltaTime)
|
||||
{
|
||||
GUITextBox msgBox = (Screen.Selected == GameMain.GameScreen ? chatBox.InputBox : GameMain.NetLobbyScreen.TextBox);
|
||||
if (gameStarted && Screen.Selected == GameMain.GameScreen)
|
||||
{
|
||||
if (!GUI.DisableHUD)
|
||||
{
|
||||
inGameHUD.UpdateManually(deltaTime);
|
||||
chatBox.Update(deltaTime);
|
||||
UpdateFollowSubTickBox();
|
||||
|
||||
if (Character.Controlled == null)
|
||||
{
|
||||
myCharacterFrameOpenState = GameMain.NetLobbyScreen.MyCharacterFrameOpen ? myCharacterFrameOpenState + deltaTime * 5 : myCharacterFrameOpenState - deltaTime * 5;
|
||||
myCharacterFrameOpenState = MathHelper.Clamp(myCharacterFrameOpenState, 0.0f, 1.0f);
|
||||
|
||||
var myCharFrame = GameMain.NetLobbyScreen.MyCharacterFrame;
|
||||
int padding = GameMain.GraphicsWidth - myCharFrame.Parent.Rect.Right;
|
||||
|
||||
myCharFrame.RectTransform.AbsoluteOffset =
|
||||
Vector2.SmoothStep(new Vector2(-myCharFrame.Rect.Width - padding, 0.0f), new Vector2(-padding, 0), myCharacterFrameOpenState).ToPoint();
|
||||
}
|
||||
}
|
||||
if (Character.Controlled == null || Character.Controlled.IsDead)
|
||||
{
|
||||
GameMain.GameScreen.Cam.TargetPos = Vector2.Zero;
|
||||
GameMain.LightManager.LosEnabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//tab doesn't autoselect the chatbox when debug console is open,
|
||||
//because tab is used for autocompleting console commands
|
||||
if ((PlayerInput.KeyHit(InputType.Chat) || PlayerInput.KeyHit(InputType.RadioChat)) &&
|
||||
!DebugConsole.IsOpen && (Screen.Selected != GameMain.GameScreen || msgBox.Visible))
|
||||
{
|
||||
if (msgBox.Selected)
|
||||
{
|
||||
msgBox.Text = "";
|
||||
msgBox.Deselect();
|
||||
}
|
||||
else
|
||||
{
|
||||
msgBox.Select();
|
||||
if (Screen.Selected == GameMain.GameScreen && PlayerInput.KeyHit(InputType.RadioChat))
|
||||
{
|
||||
msgBox.Text = "r; ";
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ServerLog.LogFrame != null) ServerLog.LogFrame.AddToGUIUpdateList();
|
||||
}
|
||||
|
||||
protected void UpdateFollowSubTickBox()
|
||||
{
|
||||
cameraFollowsSub.Visible = Character.Controlled == null;
|
||||
}
|
||||
|
||||
public virtual void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch)
|
||||
{
|
||||
if (GUI.DisableHUD) return;
|
||||
if (!gameStarted || Screen.Selected != GameMain.GameScreen || GUI.DisableHUD) return;
|
||||
|
||||
if (gameStarted && Screen.Selected == GameMain.GameScreen)
|
||||
{
|
||||
GameMain.GameSession.CrewManager.Draw(spriteBatch);
|
||||
inGameHUD.DrawManually(spriteBatch);
|
||||
|
||||
inGameHUD.Draw(spriteBatch);
|
||||
if (EndVoteCount > 0)
|
||||
{
|
||||
GUI.DrawString(spriteBatch, new Vector2(GameMain.GraphicsWidth - 180.0f, 40),
|
||||
TextManager.Get("EndRoundVotes").Replace("[y]", EndVoteCount.ToString()).Replace("[n]", (EndVoteMax - EndVoteCount).ToString()),
|
||||
Color.White,
|
||||
font: GUI.SmallFont);
|
||||
}
|
||||
|
||||
if (respawnManager != null)
|
||||
{
|
||||
string respawnInfo = "";
|
||||
if (respawnManager.CurrentState == RespawnManager.State.Waiting &&
|
||||
respawnManager.CountdownStarted)
|
||||
{
|
||||
respawnInfo = TextManager.Get(respawnManager.UsingShuttle ? "RespawnShuttleDispatching" : "RespawningIn");
|
||||
respawnInfo = respawnInfo.Replace("[time]", ToolBox.SecondsToReadableTime(respawnManager.RespawnTimer));
|
||||
}
|
||||
else if (respawnManager.CurrentState == RespawnManager.State.Transporting)
|
||||
{
|
||||
respawnInfo = respawnManager.TransportTimer <= 0.0f ?
|
||||
"" :
|
||||
TextManager.Get("RespawnShuttleLeavingIn").Replace("[time]", ToolBox.SecondsToReadableTime(respawnManager.TransportTimer));
|
||||
}
|
||||
|
||||
if (respawnManager != null)
|
||||
{
|
||||
string respawnInfo = "";
|
||||
|
||||
if (respawnManager.CurrentState == RespawnManager.State.Waiting &&
|
||||
respawnManager.CountdownStarted)
|
||||
{
|
||||
respawnInfo = respawnManager.UsingShuttle ? "Respawn Shuttle dispatching in " : "Respawning players in ";
|
||||
respawnInfo = respawnManager.RespawnTimer <= 0.0f ? "" : respawnInfo + ToolBox.SecondsToReadableTime(respawnManager.RespawnTimer);
|
||||
}
|
||||
else if (respawnManager.CurrentState == RespawnManager.State.Transporting)
|
||||
{
|
||||
respawnInfo = respawnManager.TransportTimer <= 0.0f ? "" : "Shuttle leaving in " + ToolBox.SecondsToReadableTime(respawnManager.TransportTimer);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(respawnInfo))
|
||||
{
|
||||
GUI.DrawString(spriteBatch,
|
||||
new Vector2(120.0f, 10),
|
||||
respawnInfo, Color.White, null, 0, GUI.SmallFont);
|
||||
}
|
||||
GUI.DrawString(spriteBatch,
|
||||
new Vector2(120.0f, 10),
|
||||
respawnInfo, Color.White, null, 0, GUI.SmallFont);
|
||||
}
|
||||
}
|
||||
|
||||
ServerLog.LogFrame?.Draw(spriteBatch);
|
||||
}
|
||||
|
||||
public virtual bool SelectCrewCharacter(Character character, GUIComponent characterFrame)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public void CreateKickReasonPrompt(string clientName, bool ban, bool rangeBan = false)
|
||||
{
|
||||
var banReasonPrompt = new GUIMessageBox(ban ? "Reason for the ban?" : "Reason for kicking?", "", new string[] { "OK", "Cancel" }, 400, 300);
|
||||
var banReasonBox = new GUITextBox(new Rectangle(0, 30, 0, 50), Alignment.TopCenter, "", banReasonPrompt.children[0]);
|
||||
banReasonBox.Wrap = true;
|
||||
banReasonBox.MaxTextLength = 100;
|
||||
var banReasonPrompt = new GUIMessageBox(
|
||||
TextManager.Get(ban ? "BanReasonPrompt" : "KickReasonPrompt"),
|
||||
"", new string[] { TextManager.Get("OK"), TextManager.Get("Cancel") }, 400, 300);
|
||||
|
||||
var content = new GUILayoutGroup(new RectTransform(new Vector2(0.9f, 0.6f), banReasonPrompt.InnerFrame.RectTransform, Anchor.Center));
|
||||
var banReasonBox = new GUITextBox(new RectTransform(new Vector2(1.0f, 0.3f), content.RectTransform))
|
||||
{
|
||||
Wrap = true,
|
||||
MaxTextLength = 100
|
||||
};
|
||||
|
||||
GUINumberInput durationInputDays = null, durationInputHours = null;
|
||||
GUITickBox permaBanTickBox = null;
|
||||
|
||||
if (ban)
|
||||
{
|
||||
new GUITextBlock(new Rectangle(0, 80, 0, 0), "Duration:", "", banReasonPrompt.children[0]);
|
||||
permaBanTickBox = new GUITickBox(new Rectangle(0, 110, 15, 15), "Permanent", Alignment.TopLeft, banReasonPrompt.children[0]);
|
||||
permaBanTickBox.Selected = true;
|
||||
new GUITextBlock(new RectTransform(new Vector2(0.8f, 0.15f), content.RectTransform), TextManager.Get("BanDuration"));
|
||||
permaBanTickBox = new GUITickBox(new RectTransform(new Vector2(0.8f, 0.15f), content.RectTransform) { RelativeOffset = new Vector2(0.05f, 0.0f) },
|
||||
TextManager.Get("BanPermanent"))
|
||||
{
|
||||
Selected = true
|
||||
};
|
||||
|
||||
var durationContainer = new GUIFrame(new Rectangle(0, 130, 0, 40), null, banReasonPrompt.children[0]);
|
||||
durationContainer.Visible = false;
|
||||
var durationContainer = new GUILayoutGroup(new RectTransform(new Vector2(0.8f, 0.15f), content.RectTransform), isHorizontal: true)
|
||||
{
|
||||
Visible = false
|
||||
};
|
||||
|
||||
permaBanTickBox.OnSelected += (tickBox) =>
|
||||
{
|
||||
durationContainer.Visible = !tickBox.Selected;
|
||||
return true;
|
||||
};
|
||||
|
||||
new GUITextBlock(new Rectangle(0, 0, 30, 20), "Days:", "", Alignment.TopLeft, Alignment.CenterLeft, durationContainer);
|
||||
durationInputDays = new GUINumberInput(new Rectangle(40, 0, 50, 20), "", GUINumberInput.NumberType.Int, durationContainer);
|
||||
durationInputDays.MinValueInt = 0;
|
||||
durationInputDays.MaxValueFloat = 1000;
|
||||
|
||||
new GUITextBlock(new Rectangle(100, 0, 30, 20), "Hours:", "", Alignment.TopLeft, Alignment.CenterLeft, durationContainer);
|
||||
durationInputHours = new GUINumberInput(new Rectangle(150, 0, 50, 20), "", GUINumberInput.NumberType.Int, durationContainer);
|
||||
durationInputDays.MinValueInt = 0;
|
||||
durationInputDays.MaxValueFloat = 24;
|
||||
durationInputDays = new GUINumberInput(new RectTransform(new Vector2(0.2f, 1.0f), durationContainer.RectTransform), GUINumberInput.NumberType.Int)
|
||||
{
|
||||
MinValueInt = 0,
|
||||
MaxValueFloat = 1000
|
||||
};
|
||||
new GUITextBlock(new RectTransform(new Vector2(0.2f, 1.0f), durationContainer.RectTransform), TextManager.Get("Days"));
|
||||
durationInputHours = new GUINumberInput(new RectTransform(new Vector2(0.2f, 1.0f), durationContainer.RectTransform), GUINumberInput.NumberType.Int)
|
||||
{
|
||||
MinValueInt = 0,
|
||||
MaxValueFloat = 24
|
||||
};
|
||||
new GUITextBlock(new RectTransform(new Vector2(0.2f, 1.0f), durationContainer.RectTransform), TextManager.Get("Hours"));
|
||||
}
|
||||
|
||||
banReasonPrompt.Buttons[0].OnClicked += (btn, userData) =>
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
using Lidgren.Network;
|
||||
using System;
|
||||
|
||||
namespace Barotrauma.Networking
|
||||
{
|
||||
partial class OrderChatMessage : ChatMessage
|
||||
{
|
||||
public override void ClientWrite(NetOutgoingMessage msg)
|
||||
{
|
||||
msg.Write((byte)ClientNetObject.CHAT_MESSAGE);
|
||||
msg.Write(NetStateID);
|
||||
msg.Write((byte)ChatMessageType.Order);
|
||||
msg.Write((byte)Order.PrefabList.IndexOf(Order.Prefab));
|
||||
|
||||
msg.Write(TargetCharacter == null ? (UInt16)0 : TargetCharacter.ID);
|
||||
msg.Write(TargetEntity == null ? (UInt16)0 : TargetEntity.ID);
|
||||
msg.Write((byte)Array.IndexOf(Order.Prefab.Options, OrderOption));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
using Barotrauma.Steam;
|
||||
using Microsoft.Xna.Framework;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Barotrauma.Networking
|
||||
{
|
||||
partial class ServerInfo
|
||||
{
|
||||
public void CreatePreviewWindow(GUIMessageBox messageBox)
|
||||
{
|
||||
var title = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), messageBox.Content.RectTransform), ServerName, textAlignment: Alignment.Center, font: GUI.LargeFont, wrap: true);
|
||||
|
||||
var serverMsg = new GUIListBox(new RectTransform(new Vector2(1.0f, 0.2f), messageBox.Content.RectTransform));
|
||||
new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), serverMsg.Content.RectTransform), ServerMessage, wrap: true);
|
||||
|
||||
var columnContainer = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.5f), messageBox.Content.RectTransform), isHorizontal: true)
|
||||
{
|
||||
Stretch = true,
|
||||
RelativeSpacing = 0.05f
|
||||
};
|
||||
|
||||
var columnLeft = new GUILayoutGroup(new RectTransform(new Vector2(0.5f, 1.0f), columnContainer.RectTransform))
|
||||
{
|
||||
RelativeSpacing = 0.02f,
|
||||
Stretch = true
|
||||
};
|
||||
var columnRight = new GUILayoutGroup(new RectTransform(new Vector2(0.5f, 1.0f), columnContainer.RectTransform))
|
||||
{
|
||||
RelativeSpacing = 0.02f,
|
||||
Stretch = true
|
||||
};
|
||||
|
||||
float elementHeight = 0.1f;
|
||||
|
||||
// left column -----------------------------------------------------------------------------
|
||||
|
||||
//new GUITextBlock(new RectTransform(new Vector2(1.0f, elementHeight), columnLeft.RectTransform), IP + ":" + Port);
|
||||
new GUITextBlock(new RectTransform(new Vector2(1.0f, elementHeight), columnLeft.RectTransform),
|
||||
TextManager.Get("ServerListVersion") + ": " + (string.IsNullOrEmpty(GameVersion) ? TextManager.Get("Unknown") : GameVersion));
|
||||
new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), columnLeft.RectTransform),
|
||||
TextManager.Get("ServerListContentPackages"));
|
||||
|
||||
var contentPackageList = new GUIListBox(new RectTransform(new Vector2(1.0f, 0.7f), columnLeft.RectTransform));
|
||||
if (ContentPackageNames.Count == 0)
|
||||
{
|
||||
new GUITextBlock(new RectTransform(Vector2.One, contentPackageList.Content.RectTransform), TextManager.Get("Unknown"), textAlignment: Alignment.Center)
|
||||
{
|
||||
CanBeFocused = false
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
List<string> availableWorkshopUrls = new List<string>();
|
||||
for (int i = 0; i < ContentPackageNames.Count; i++)
|
||||
{
|
||||
var packageText = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.15f), contentPackageList.Content.RectTransform) { MinSize = new Point(0, 15) },
|
||||
ContentPackageNames[i])
|
||||
{
|
||||
Enabled = false
|
||||
};
|
||||
if (i < ContentPackageHashes.Count)
|
||||
{
|
||||
if (GameMain.Config.SelectedContentPackages.Any(cp => cp.MD5hash.Hash == ContentPackageHashes[i]))
|
||||
{
|
||||
packageText.Selected = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
//matching content package found, but it hasn't been enabled
|
||||
if (ContentPackage.List.Any(cp => cp.MD5hash.Hash == ContentPackageHashes[i]))
|
||||
{
|
||||
packageText.TextColor = Color.Orange;
|
||||
packageText.ToolTip = TextManager.Get("ServerListContentPackageNotEnabled")
|
||||
.Replace("[contentpackage]", ContentPackageNames[i]);
|
||||
}
|
||||
//workshop download link found
|
||||
else if (i < ContentPackageWorkshopUrls.Count && !string.IsNullOrEmpty(ContentPackageWorkshopUrls[i]))
|
||||
{
|
||||
availableWorkshopUrls.Add(ContentPackageWorkshopUrls[i]);
|
||||
packageText.TextColor = Color.Yellow;
|
||||
packageText.ToolTip = TextManager.Get("ServerListIncompatibleContentPackageWorkshopAvailable")
|
||||
.Replace("[contentpackage]", ContentPackageNames[i]);
|
||||
}
|
||||
else //no package or workshop download link found, tough luck
|
||||
{
|
||||
packageText.TextColor = Color.Red;
|
||||
packageText.ToolTip = TextManager.Get("ServerListIncompatibleContentPackage")
|
||||
.Replace("[contentpackage]", ContentPackageNames[i])
|
||||
.Replace("[hash]", ContentPackageHashes[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (availableWorkshopUrls.Count > 0 )
|
||||
{
|
||||
var workshopBtn = new GUIButton(new RectTransform(new Vector2(1.0f, 0.15f), columnLeft.RectTransform), TextManager.Get("ServerListSubscribeMissingPackages"))
|
||||
{
|
||||
ToolTip = TextManager.Get(SteamManager.IsInitialized ? "ServerListSubscribeMissingPackagesTooltip" : "ServerListSubscribeMissingPackagesTooltipNoSteam"),
|
||||
Enabled = SteamManager.IsInitialized,
|
||||
OnClicked = (btn, userdata) =>
|
||||
{
|
||||
GameMain.SteamWorkshopScreen.SubscribeToPackages(availableWorkshopUrls);
|
||||
GameMain.SteamWorkshopScreen.Select();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
workshopBtn.TextBlock.AutoScale = true;
|
||||
}
|
||||
}
|
||||
|
||||
// right column -----------------------------------------------------------------------------
|
||||
|
||||
var playerCount = new GUITextBlock(new RectTransform(new Vector2(1.0f, elementHeight), columnRight.RectTransform), TextManager.Get("ServerListPlayers"));
|
||||
new GUITextBlock(new RectTransform(Vector2.One, playerCount.RectTransform), PlayerCount + "/" + MaxPlayers, textAlignment: Alignment.Right);
|
||||
|
||||
|
||||
new GUITickBox(new RectTransform(new Vector2(1, elementHeight), columnRight.RectTransform), "Round running")
|
||||
{
|
||||
Selected = GameStarted,
|
||||
CanBeFocused = false
|
||||
};
|
||||
|
||||
var gameMode = new GUITextBlock(new RectTransform(new Vector2(1.0f, elementHeight), columnRight.RectTransform), TextManager.Get("GameMode"));
|
||||
new GUITextBlock(new RectTransform(Vector2.One, gameMode.RectTransform), string.IsNullOrEmpty(GameMode) ? "Unknown" : GameMode, textAlignment: Alignment.Right);
|
||||
|
||||
var traitors = new GUITextBlock(new RectTransform(new Vector2(1.0f, elementHeight), columnRight.RectTransform), TextManager.Get("Traitors"));
|
||||
new GUITextBlock(new RectTransform(Vector2.One, traitors.RectTransform), !TraitorsEnabled.HasValue ? "Unknown" : TraitorsEnabled.Value.ToString(), textAlignment: Alignment.Right);
|
||||
|
||||
|
||||
var subSelection = new GUITextBlock(new RectTransform(new Vector2(1.0f, elementHeight), columnRight.RectTransform), TextManager.Get("ServerListSubSelection"));
|
||||
new GUITextBlock(new RectTransform(Vector2.One, subSelection.RectTransform), !SubSelectionMode.HasValue ? "Unknown" : SubSelectionMode.Value.ToString(), textAlignment: Alignment.Right);
|
||||
|
||||
var modeSelection = new GUITextBlock(new RectTransform(new Vector2(1.0f, elementHeight), columnRight.RectTransform), TextManager.Get("ServerListModeSelection"));
|
||||
new GUITextBlock(new RectTransform(Vector2.One, modeSelection.RectTransform), (!ModeSelectionMode.HasValue ? "Unknown" : ModeSelectionMode.Value.ToString()), textAlignment: Alignment.Right);
|
||||
|
||||
var allowSpectating = new GUITickBox(new RectTransform(new Vector2(1, elementHeight), columnRight.RectTransform), TextManager.Get("ServerListAllowSpectating"))
|
||||
{
|
||||
CanBeFocused = false
|
||||
};
|
||||
if (!AllowSpectating.HasValue)
|
||||
new GUITextBlock(new RectTransform(new Vector2(0.8f, 0.8f), allowSpectating.Box.RectTransform, Anchor.Center), "?", textAlignment: Alignment.Center);
|
||||
else
|
||||
allowSpectating.Selected = AllowSpectating.Value;
|
||||
|
||||
var allowRespawn = new GUITickBox(new RectTransform(new Vector2(1, elementHeight), columnRight.RectTransform), "Allow respawn")
|
||||
{
|
||||
CanBeFocused = false
|
||||
};
|
||||
if (!AllowRespawn.HasValue)
|
||||
new GUITextBlock(new RectTransform(new Vector2(0.8f, 0.8f), allowRespawn.Box.RectTransform, Anchor.Center), "?", textAlignment: Alignment.Center);
|
||||
else
|
||||
allowRespawn.Selected = AllowRespawn.Value;
|
||||
|
||||
new GUITickBox(new RectTransform(new Vector2(1.0f, elementHeight), columnRight.RectTransform), TextManager.Get("ServerListHasPassword"))
|
||||
{
|
||||
Selected = HasPassword,
|
||||
CanBeFocused = false
|
||||
};
|
||||
|
||||
var usingWhiteList = new GUITickBox(new RectTransform(new Vector2(1, elementHeight), columnRight.RectTransform), TextManager.Get("ServerListUsingWhitelist"))
|
||||
{
|
||||
CanBeFocused = false
|
||||
};
|
||||
if (!UsingWhiteList.HasValue)
|
||||
new GUITextBlock(new RectTransform(new Vector2(0.8f, 0.8f), usingWhiteList.Box.RectTransform, Anchor.Center), "?", textAlignment: Alignment.Center);
|
||||
else
|
||||
usingWhiteList.Selected = UsingWhiteList.Value;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
foreach (GUIComponent c in columnLeft.Children)
|
||||
{
|
||||
if (c is GUITextBlock textBlock) textBlock.Padding = Vector4.Zero;
|
||||
}
|
||||
foreach (GUIComponent c in columnRight.Children)
|
||||
{
|
||||
if (c is GUITextBlock textBlock) textBlock.Padding = Vector4.Zero;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,41 +6,52 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
partial class ServerLog
|
||||
{
|
||||
public GUIFrame LogFrame;
|
||||
|
||||
public GUIButton LogFrame;
|
||||
private GUIListBox listBox;
|
||||
|
||||
public void CreateLogFrame()
|
||||
{
|
||||
LogFrame = new GUIFrame(new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight), Color.Black * 0.5f);
|
||||
LogFrame = new GUIButton(new RectTransform(Vector2.One, GUI.Canvas), style: "GUIBackgroundBlocker")
|
||||
{
|
||||
OnClicked = (btn, userdata) => { if (GUI.MouseOn == btn || GUI.MouseOn == btn.TextBlock) LogFrame = null; return true; }
|
||||
};
|
||||
new GUIButton(new RectTransform(Vector2.One, LogFrame.RectTransform), "", style: null).OnClicked += (btn, userData) =>
|
||||
{
|
||||
LogFrame = null;
|
||||
return true;
|
||||
};
|
||||
|
||||
GUIFrame innerFrame = new GUIFrame(new Rectangle(0, 0, 600, 420), null, Alignment.Center, "", LogFrame);
|
||||
innerFrame.Padding = new Vector4(10.0f, 20.0f, 10.0f, 20.0f);
|
||||
GUIFrame innerFrame = new GUIFrame(new RectTransform(new Vector2(0.3f, 0.4f), LogFrame.RectTransform, Anchor.Center) { MinSize = new Point(600, 420) });
|
||||
GUIFrame paddedFrame = new GUIFrame(new RectTransform(new Vector2(0.9f, 0.85f), innerFrame.RectTransform, Anchor.Center) { RelativeOffset = new Vector2(0.0f, -0.03f) }, style: null);
|
||||
|
||||
new GUITextBlock(new Rectangle(-200, 0, 100, 15), "Filter", "", Alignment.TopRight, Alignment.CenterRight, innerFrame, false, GUI.SmallFont);
|
||||
|
||||
GUITextBox searchBox = new GUITextBox(new Rectangle(-20, 0, 180, 15), Alignment.TopRight, "", innerFrame);
|
||||
searchBox.Font = GUI.SmallFont;
|
||||
searchBox.OnTextChanged = (textBox, text) =>
|
||||
new GUITextBlock(new RectTransform(new Vector2(0.75f, 0.05f), paddedFrame.RectTransform, Anchor.TopRight), "Filter", font: GUI.SmallFont);
|
||||
GUITextBox searchBox = new GUITextBox(new RectTransform(new Vector2(0.6f, 0.05f), paddedFrame.RectTransform, Anchor.TopRight), font: GUI.SmallFont);
|
||||
searchBox.OnTextChanged += (textBox, text) =>
|
||||
{
|
||||
msgFilter = text;
|
||||
FilterMessages();
|
||||
return true;
|
||||
};
|
||||
GUIComponent.KeyboardDispatcher.Subscriber = searchBox;
|
||||
GUI.KeyboardDispatcher.Subscriber = searchBox;
|
||||
|
||||
var clearButton = new GUIButton(new Rectangle(0, 0, 15, 15), "x", Alignment.TopRight, "", innerFrame);
|
||||
clearButton.OnClicked = ClearFilter;
|
||||
clearButton.UserData = searchBox;
|
||||
var clearButton = new GUIButton(new RectTransform(new Vector2(0.05f, 0.05f), paddedFrame.RectTransform, Anchor.TopRight), "x")
|
||||
{
|
||||
OnClicked = ClearFilter,
|
||||
UserData = searchBox
|
||||
};
|
||||
|
||||
listBox = new GUIListBox(new Rectangle(0, 30, 450, 340), "", Alignment.TopRight, innerFrame);
|
||||
listBox = new GUIListBox(new RectTransform(new Vector2(0.75f, 0.95f), paddedFrame.RectTransform, Anchor.BottomRight));
|
||||
|
||||
var tickBoxContainer = new GUILayoutGroup(new RectTransform(new Vector2(0.2f, 0.95f), paddedFrame.RectTransform, Anchor.BottomLeft));
|
||||
|
||||
int y = 30;
|
||||
foreach (MessageType msgType in Enum.GetValues(typeof(MessageType)))
|
||||
{
|
||||
var tickBox = new GUITickBox(new Rectangle(0, y, 20, 20), messageTypeName[(int)msgType], Alignment.TopLeft, GUI.SmallFont, innerFrame);
|
||||
tickBox.Selected = true;
|
||||
tickBox.TextColor = messageColor[(int)msgType];
|
||||
var tickBox = new GUITickBox(new RectTransform(new Point(20, 20), tickBoxContainer.RectTransform), messageTypeName[(int)msgType], font: GUI.SmallFont)
|
||||
{
|
||||
Selected = true,
|
||||
TextColor = messageColor[(int)msgType]
|
||||
};
|
||||
|
||||
tickBox.OnSelected += (GUITickBox tb) =>
|
||||
{
|
||||
@@ -66,7 +77,7 @@ namespace Barotrauma.Networking
|
||||
|
||||
if (listBox.BarScroll == 0.0f || listBox.BarScroll == 1.0f) listBox.BarScroll = 1.0f;
|
||||
|
||||
GUIButton closeButton = new GUIButton(new Rectangle(-100, 10, 100, 15), "Close", Alignment.BottomRight, "", innerFrame);
|
||||
GUIButton closeButton = new GUIButton(new RectTransform(new Vector2(0.25f, 0.05f), innerFrame.RectTransform, Anchor.BottomRight) { RelativeOffset = new Vector2(0.02f, 0.03f) }, "Close");
|
||||
closeButton.OnClicked = (button, userData) =>
|
||||
{
|
||||
LogFrame = null;
|
||||
@@ -80,8 +91,8 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
float prevSize = listBox.BarSize;
|
||||
|
||||
var textBlock = new GUITextBlock(new Rectangle(0, 0, 0, 0), line.Text, "", Alignment.TopLeft, Alignment.TopLeft, listBox, true, GUI.SmallFont);
|
||||
textBlock.Rect = new Rectangle(textBlock.Rect.X, textBlock.Rect.Y, textBlock.Rect.Width, Math.Max(13, textBlock.Rect.Height));
|
||||
var textBlock = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), listBox.Content.RectTransform),
|
||||
line.Text, wrap: true, font: GUI.SmallFont);
|
||||
textBlock.TextColor = messageColor[(int)line.Type];
|
||||
textBlock.Visible = !msgTypeHidden[(int)line.Type];
|
||||
textBlock.CanBeFocused = false;
|
||||
@@ -94,7 +105,7 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
string filter = msgFilter == null ? "" : msgFilter.ToLower();
|
||||
|
||||
foreach (GUIComponent child in listBox.children)
|
||||
foreach (GUIComponent child in listBox.Content.Children)
|
||||
{
|
||||
var textBlock = child as GUITextBlock;
|
||||
if (textBlock == null) continue;
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace Barotrauma
|
||||
GameMain.NetLobbyScreen.InfoFrame.FindChild("modevotes", true).Visible = value;
|
||||
|
||||
//gray out modes that can't be voted
|
||||
foreach (GUITextBlock comp in GameMain.NetLobbyScreen.ModeList.children)
|
||||
foreach (GUITextBlock comp in GameMain.NetLobbyScreen.ModeList.Content.Children)
|
||||
{
|
||||
comp.TextColor =
|
||||
new Color(comp.TextColor.R, comp.TextColor.G, comp.TextColor.B,
|
||||
@@ -67,36 +67,71 @@ namespace Barotrauma
|
||||
|
||||
public void UpdateVoteTexts(List<Client> clients, VoteType voteType)
|
||||
{
|
||||
GUIListBox listBox = (voteType == VoteType.Sub) ?
|
||||
GameMain.NetLobbyScreen.SubList : GameMain.NetLobbyScreen.ModeList;
|
||||
|
||||
foreach (GUIComponent comp in listBox.children)
|
||||
switch (voteType)
|
||||
{
|
||||
GUITextBlock voteText = comp.FindChild("votes") as GUITextBlock;
|
||||
if (voteText != null) comp.RemoveChild(voteText);
|
||||
}
|
||||
case VoteType.Sub:
|
||||
case VoteType.Mode:
|
||||
GUIListBox listBox = (voteType == VoteType.Sub) ?
|
||||
GameMain.NetLobbyScreen.SubList : GameMain.NetLobbyScreen.ModeList;
|
||||
|
||||
if (clients != null)
|
||||
{
|
||||
List<Pair<object, int>> voteList = GetVoteList(voteType, clients);
|
||||
foreach (Pair<object, int> votable in voteList)
|
||||
{
|
||||
SetVoteText(listBox, votable.First, votable.Second);
|
||||
}
|
||||
foreach (GUIComponent comp in listBox.Content.Children)
|
||||
{
|
||||
if (comp.FindChild("votes") is GUITextBlock voteText) comp.RemoveChild(voteText);
|
||||
}
|
||||
|
||||
if (clients == null) return;
|
||||
|
||||
List<Pair<object, int>> voteList = GetVoteList(voteType, clients);
|
||||
foreach (Pair<object, int> votable in voteList)
|
||||
{
|
||||
SetVoteText(listBox, votable.First, votable.Second);
|
||||
}
|
||||
break;
|
||||
case VoteType.StartRound:
|
||||
if (clients == null) return;
|
||||
foreach (Client client in clients)
|
||||
{
|
||||
var clientNameBox = GameMain.NetLobbyScreen.PlayerList.Content.FindChild(client.Name);
|
||||
if (clientNameBox == null) continue;
|
||||
|
||||
var clientReady = clientNameBox.FindChild("clientready");
|
||||
if (!client.GetVote<bool>(VoteType.StartRound))
|
||||
{
|
||||
if (clientReady != null) clientReady.Parent.RemoveChild(clientReady);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (clientReady == null)
|
||||
{
|
||||
new GUITickBox(new RectTransform(new Vector2(0.05f, 0.6f), clientNameBox.RectTransform, Anchor.CenterRight) { RelativeOffset = new Vector2(0.05f, 0.0f) }, "")
|
||||
{
|
||||
Selected = true,
|
||||
Enabled = false,
|
||||
ToolTip = "Ready to start",
|
||||
UserData = "clientready"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void SetVoteText(GUIListBox listBox, object userData, int votes)
|
||||
{
|
||||
if (userData == null) return;
|
||||
foreach (GUIComponent comp in listBox.children)
|
||||
foreach (GUIComponent comp in listBox.Content.Children)
|
||||
{
|
||||
if (comp.UserData != userData) continue;
|
||||
GUITextBlock voteText = comp.FindChild("votes") as GUITextBlock;
|
||||
if (voteText == null)
|
||||
{
|
||||
voteText = new GUITextBlock(new Rectangle(0, 0, 30, 0), "", "", Alignment.Right, Alignment.Right, comp);
|
||||
voteText.UserData = "votes";
|
||||
voteText = new GUITextBlock(new RectTransform(new Point(30, comp.Rect.Height), comp.RectTransform, Anchor.CenterRight),
|
||||
"", textAlignment: Alignment.CenterRight)
|
||||
{
|
||||
UserData = "votes"
|
||||
};
|
||||
}
|
||||
|
||||
voteText.Text = votes == 0 ? "" : votes.ToString();
|
||||
@@ -120,12 +155,10 @@ namespace Barotrauma
|
||||
case VoteType.Mode:
|
||||
GameModePreset gameMode = data as GameModePreset;
|
||||
if (gameMode == null) return;
|
||||
|
||||
msg.Write(gameMode.Name);
|
||||
msg.Write(gameMode.Identifier);
|
||||
break;
|
||||
case VoteType.EndRound:
|
||||
if (!(data is bool)) return;
|
||||
|
||||
msg.Write((bool)data);
|
||||
break;
|
||||
case VoteType.Kick:
|
||||
@@ -134,6 +167,10 @@ namespace Barotrauma
|
||||
|
||||
msg.Write(votedClient.ID);
|
||||
break;
|
||||
case VoteType.StartRound:
|
||||
if (!(data is bool)) return;
|
||||
msg.Write((bool)data);
|
||||
break;
|
||||
}
|
||||
|
||||
msg.WritePadBits();
|
||||
@@ -153,7 +190,7 @@ namespace Barotrauma
|
||||
int votes = inc.ReadByte();
|
||||
string subName = inc.ReadString();
|
||||
List<Submarine> serversubs = new List<Submarine>();
|
||||
foreach (GUIComponent item in GameMain.NetLobbyScreen?.SubList?.children)
|
||||
foreach (GUIComponent item in GameMain.NetLobbyScreen?.SubList?.Content?.Children)
|
||||
{
|
||||
if (item.UserData != null && item.UserData is Submarine) serversubs.Add(item.UserData as Submarine);
|
||||
}
|
||||
@@ -169,8 +206,8 @@ namespace Barotrauma
|
||||
for (int i = 0; i < votableCount; i++)
|
||||
{
|
||||
int votes = inc.ReadByte();
|
||||
string modeName = inc.ReadString();
|
||||
GameModePreset mode = GameModePreset.list.Find(m => m.Name == modeName);
|
||||
string modeIdentifier = inc.ReadString();
|
||||
GameModePreset mode = GameModePreset.List.Find(m => m.Identifier == modeIdentifier);
|
||||
SetVoteText(GameMain.NetLobbyScreen.ModeList, mode, votes);
|
||||
}
|
||||
}
|
||||
@@ -182,6 +219,16 @@ namespace Barotrauma
|
||||
}
|
||||
AllowVoteKick = inc.ReadBoolean();
|
||||
|
||||
GameMain.NetworkMember.ConnectedClients.ForEach(c => c.SetVote(VoteType.StartRound, false));
|
||||
byte readyClientCount = inc.ReadByte();
|
||||
for (int i = 0; i < readyClientCount; i++)
|
||||
{
|
||||
byte clientID = inc.ReadByte();
|
||||
var matchingClient = GameMain.NetworkMember.ConnectedClients.Find(c => c.ID == clientID);
|
||||
matchingClient?.SetVote(VoteType.StartRound, true);
|
||||
}
|
||||
UpdateVoteTexts(GameMain.NetworkMember.ConnectedClients, VoteType.StartRound);
|
||||
|
||||
inc.ReadPadBits();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,8 @@ namespace Barotrauma.Networking
|
||||
|
||||
private GUITextBox nameBox;
|
||||
private GUITextBox ipBox;
|
||||
|
||||
private GUIButton addNewButton;
|
||||
|
||||
public GUIComponent CreateWhiteListFrame(GUIComponent parent)
|
||||
{
|
||||
if (whitelistFrame != null)
|
||||
@@ -18,60 +19,96 @@ namespace Barotrauma.Networking
|
||||
whitelistFrame = null;
|
||||
}
|
||||
|
||||
parent.Padding = new Vector4(10.0f, 10.0f, 10.0f, 10.0f);
|
||||
|
||||
var enabledTick = new GUITickBox(new Rectangle(0, 0, 20, 20), "Enabled", Alignment.TopLeft, parent);
|
||||
enabledTick.Selected = Enabled;
|
||||
enabledTick.OnSelected = (GUITickBox box) =>
|
||||
whitelistFrame = new GUILayoutGroup(new RectTransform(new Vector2(0.95f, 0.95f), parent.RectTransform, Anchor.Center))
|
||||
{
|
||||
Enabled = !Enabled;
|
||||
|
||||
if (Enabled)
|
||||
{
|
||||
foreach (Client c in GameMain.Server.ConnectedClients)
|
||||
{
|
||||
if (!IsWhiteListed(c.Name, c.Connection.RemoteEndPoint.Address.ToString()))
|
||||
{
|
||||
whitelistedPlayers.Add(new WhiteListedPlayer(c.Name, c.Connection.RemoteEndPoint.Address.ToString()));
|
||||
if (whitelistFrame != null) CreateWhiteListFrame(whitelistFrame.Parent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Save();
|
||||
return true;
|
||||
Stretch = true,
|
||||
RelativeSpacing = 0.02f
|
||||
};
|
||||
|
||||
new GUITextBlock(new Rectangle(0, -35, 90, 20), "Name:", "", Alignment.BottomLeft, Alignment.CenterLeft, parent, false, GUI.Font);
|
||||
nameBox = new GUITextBox(new Rectangle(100, -35, 170, 20), Alignment.BottomLeft, "", parent);
|
||||
nameBox.Font = GUI.Font;
|
||||
var enabledTick = new GUITickBox(new RectTransform(new Vector2(0.1f, 0.1f), whitelistFrame.RectTransform), TextManager.Get("WhiteListEnabled"))
|
||||
{
|
||||
Selected = Enabled,
|
||||
UpdateOrder = 1,
|
||||
OnSelected = (GUITickBox box) =>
|
||||
{
|
||||
Enabled = !Enabled;
|
||||
|
||||
new GUITextBlock(new Rectangle(0, 0, 90, 20), "IP Address:", "", Alignment.BottomLeft, Alignment.CenterLeft, parent, false, GUI.Font);
|
||||
ipBox = new GUITextBox(new Rectangle(100, 0, 170, 20), Alignment.BottomLeft, "", parent);
|
||||
ipBox.Font = GUI.Font;
|
||||
nameBox.Text = "";
|
||||
nameBox.Enabled = Enabled;
|
||||
ipBox.Text = "";
|
||||
ipBox.Enabled = Enabled;
|
||||
addNewButton.Enabled = false;
|
||||
|
||||
var addnewButton = new GUIButton(new Rectangle(0, 35, 150, 20), "Add to whitelist", Alignment.BottomLeft, "", parent);
|
||||
addnewButton.OnClicked = AddToWhiteList;
|
||||
if (Enabled)
|
||||
{
|
||||
foreach (Client c in GameMain.Server.ConnectedClients)
|
||||
{
|
||||
if (!IsWhiteListed(c.Name, c.Connection.RemoteEndPoint.Address.ToString()))
|
||||
{
|
||||
whitelistedPlayers.Add(new WhiteListedPlayer(c.Name, c.Connection.RemoteEndPoint.Address.ToString()));
|
||||
if (whitelistFrame != null) CreateWhiteListFrame(whitelistFrame.Parent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
whitelistFrame = new GUIListBox(new Rectangle(0, 30, 0, parent.Rect.Height - 110), "", parent);
|
||||
Save();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
var listBox = new GUIListBox(new RectTransform(new Vector2(1.0f, 0.7f), whitelistFrame.RectTransform));
|
||||
foreach (WhiteListedPlayer wlp in whitelistedPlayers)
|
||||
{
|
||||
string blockText = wlp.Name;
|
||||
if (!string.IsNullOrWhiteSpace(wlp.IP)) blockText += " (" + wlp.IP + ")";
|
||||
GUITextBlock textBlock = new GUITextBlock(
|
||||
new Rectangle(0, 0, 0, 25),
|
||||
blockText,
|
||||
"",
|
||||
Alignment.Left, Alignment.Left, whitelistFrame);
|
||||
textBlock.Padding = new Vector4(10.0f, 10.0f, 0.0f, 0.0f);
|
||||
textBlock.UserData = wlp;
|
||||
GUITextBlock textBlock = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.2f), listBox.Content.RectTransform),
|
||||
blockText)
|
||||
{
|
||||
UserData = wlp
|
||||
};
|
||||
|
||||
var removeButton = new GUIButton(new Rectangle(0, 0, 100, 20), "Remove", Alignment.Right | Alignment.CenterY, "", textBlock);
|
||||
removeButton.UserData = wlp;
|
||||
removeButton.OnClicked = RemoveFromWhiteList;
|
||||
var removeButton = new GUIButton(new RectTransform(new Vector2(0.3f, 0.8f), textBlock.RectTransform, Anchor.CenterRight), TextManager.Get("WhiteListRemove"))
|
||||
{
|
||||
UserData = wlp,
|
||||
OnClicked = RemoveFromWhiteList
|
||||
};
|
||||
}
|
||||
|
||||
var nameArea = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.15f), whitelistFrame.RectTransform), isHorizontal: true)
|
||||
{
|
||||
Stretch = true,
|
||||
RelativeSpacing = 0.05f
|
||||
};
|
||||
new GUITextBlock(new RectTransform(new Vector2(0.3f, 1.0f), nameArea.RectTransform), TextManager.Get("WhiteListName"));
|
||||
nameBox = new GUITextBox(new RectTransform(new Vector2(0.7f, 1.0f), nameArea.RectTransform), "");
|
||||
nameBox.OnTextChanged += (textBox, text) =>
|
||||
{
|
||||
addNewButton.Enabled = !string.IsNullOrEmpty(ipBox.Text) && !string.IsNullOrEmpty(nameBox.Text);
|
||||
return true;
|
||||
};
|
||||
|
||||
var ipArea = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.15f), whitelistFrame.RectTransform), isHorizontal: true)
|
||||
{
|
||||
Stretch = true,
|
||||
RelativeSpacing = 0.05f
|
||||
};
|
||||
new GUITextBlock(new RectTransform(new Vector2(0.3f, 1.0f), ipArea.RectTransform), TextManager.Get("WhiteListIP"));
|
||||
ipBox = new GUITextBox(new RectTransform(new Vector2(0.7f, 1.0f), ipArea.RectTransform), "");
|
||||
ipBox.OnTextChanged += (textBox, text) =>
|
||||
{
|
||||
addNewButton.Enabled = !string.IsNullOrEmpty(ipBox.Text) && !string.IsNullOrEmpty(nameBox.Text);
|
||||
return true;
|
||||
};
|
||||
|
||||
addNewButton = new GUIButton(new RectTransform(new Vector2(0.4f, 0.1f), whitelistFrame.RectTransform), TextManager.Get("WhiteListAdd"))
|
||||
{
|
||||
OnClicked = AddToWhiteList
|
||||
};
|
||||
|
||||
nameBox.Enabled = Enabled;
|
||||
ipBox.Enabled = Enabled;
|
||||
addNewButton.Enabled = false;
|
||||
|
||||
return parent;
|
||||
}
|
||||
|
||||
@@ -84,7 +121,6 @@ namespace Barotrauma.Networking
|
||||
|
||||
if (whitelistFrame != null)
|
||||
{
|
||||
whitelistFrame.Parent.ClearChildren();
|
||||
CreateWhiteListFrame(whitelistFrame.Parent);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user