(98ad00fa2) v0.9.1.0
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -9,6 +9,7 @@ using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
@@ -736,6 +737,7 @@ namespace Barotrauma
|
||||
string arguments = "-name \"" + name.Replace("\\", "\\\\").Replace("\"", "\\\"") + "\"" +
|
||||
" -port " + port.ToString() +
|
||||
" -queryport " + queryPort.ToString() +
|
||||
" -public " + isPublicBox.Selected.ToString() +
|
||||
" -password \"" + passwordBox.Text.Replace("\\", "\\\\").Replace("\"", "\\\"") + "\"" +
|
||||
" -upnp " + useUpnpBox.Selected +
|
||||
" -maxplayers " + maxPlayersBox.Text +
|
||||
@@ -940,6 +942,20 @@ namespace Barotrauma
|
||||
#region UI Methods
|
||||
private void CreateHostServerFields()
|
||||
{
|
||||
int port = NetConfig.DefaultPort;
|
||||
int queryPort = NetConfig.DefaultQueryPort;
|
||||
int maxPlayers = 8;
|
||||
if (File.Exists(ServerSettings.SettingsFile))
|
||||
{
|
||||
XDocument settingsDoc = XMLExtensions.TryLoadXml(ServerSettings.SettingsFile);
|
||||
if (settingsDoc?.Root != null)
|
||||
{
|
||||
port = settingsDoc.Root.GetAttributeInt("port", port);
|
||||
queryPort = settingsDoc.Root.GetAttributeInt("queryport", queryPort);
|
||||
maxPlayers = settingsDoc.Root.GetAttributeInt("maxplayers", maxPlayers);
|
||||
}
|
||||
}
|
||||
|
||||
Vector2 textLabelSize = new Vector2(1.0f, 0.1f);
|
||||
Alignment textAlignment = Alignment.CenterLeft;
|
||||
Vector2 textFieldSize = new Vector2(0.5f, 1.0f);
|
||||
@@ -954,12 +970,16 @@ namespace Barotrauma
|
||||
new GUITextBlock(new RectTransform(textLabelSize, parent.RectTransform), TextManager.Get("HostServerButton"), textAlignment: Alignment.Center, font: GUI.LargeFont) { ForceUpperCase = true };
|
||||
|
||||
var label = new GUITextBlock(new RectTransform(textLabelSize, parent.RectTransform), TextManager.Get("ServerName"), textAlignment: textAlignment);
|
||||
serverNameBox = new GUITextBox(new RectTransform(textFieldSize, label.RectTransform, Anchor.CenterRight), textAlignment: textAlignment);
|
||||
serverNameBox = new GUITextBox(new RectTransform(textFieldSize, label.RectTransform, Anchor.CenterRight), textAlignment: textAlignment)
|
||||
{
|
||||
MaxTextLength = NetConfig.ServerNameMaxLength,
|
||||
OverflowClip = true
|
||||
};
|
||||
|
||||
label = new GUITextBlock(new RectTransform(textLabelSize, parent.RectTransform), TextManager.Get("ServerPort"), textAlignment: textAlignment);
|
||||
portBox = new GUITextBox(new RectTransform(textFieldSize, label.RectTransform, Anchor.CenterRight), textAlignment: textAlignment)
|
||||
{
|
||||
Text = NetConfig.DefaultPort.ToString(),
|
||||
Text = port.ToString(),
|
||||
ToolTip = TextManager.Get("ServerPortToolTip")
|
||||
};
|
||||
|
||||
@@ -968,7 +988,7 @@ namespace Barotrauma
|
||||
label = new GUITextBlock(new RectTransform(textLabelSize, parent.RectTransform), TextManager.Get("ServerQueryPort"), textAlignment: textAlignment);
|
||||
queryPortBox = new GUITextBox(new RectTransform(textFieldSize, label.RectTransform, Anchor.CenterRight), textAlignment: textAlignment)
|
||||
{
|
||||
Text = NetConfig.DefaultQueryPort.ToString(),
|
||||
Text = queryPort.ToString(),
|
||||
ToolTip = TextManager.Get("ServerQueryPortToolTip")
|
||||
};
|
||||
}
|
||||
@@ -987,7 +1007,7 @@ namespace Barotrauma
|
||||
|
||||
maxPlayersBox = new GUITextBox(new RectTransform(new Vector2(0.6f, 1.0f), buttonContainer.RectTransform), textAlignment: Alignment.Center)
|
||||
{
|
||||
Text = "8",
|
||||
Text = maxPlayers.ToString(),
|
||||
Enabled = false
|
||||
};
|
||||
new GUIButton(new RectTransform(new Vector2(0.2f, 1.0f), buttonContainer.RectTransform), "+", textAlignment: Alignment.Center)
|
||||
|
||||
@@ -335,8 +335,12 @@ namespace Barotrauma
|
||||
new GUIFrame(new RectTransform(new Vector2(1.0f, 0.03f), rightInfoColumn.RectTransform), style: null);
|
||||
|
||||
//server info ------------------------------------------------------------------
|
||||
|
||||
ServerName = new GUITextBox(new RectTransform(new Vector2(0.3f, 0.05f), infoFrameContent.RectTransform));
|
||||
|
||||
ServerName = new GUITextBox(new RectTransform(new Vector2(infoColumnContainer.RectTransform.RelativeSize.X, 0.05f), infoFrameContent.RectTransform))
|
||||
{
|
||||
MaxTextLength = NetConfig.ServerNameMaxLength,
|
||||
OverflowClip = true
|
||||
};
|
||||
ServerName.OnDeselected += (textBox, key) =>
|
||||
{
|
||||
GameMain.Client.ServerSettings.ClientAdminWrite(ServerSettings.NetFlags.Name);
|
||||
@@ -1608,13 +1612,13 @@ namespace Barotrauma
|
||||
public void BanPlayer(Client client)
|
||||
{
|
||||
if (GameMain.NetworkMember == null || client == null) { return; }
|
||||
GameMain.Client.CreateKickReasonPrompt(client.Name, true);
|
||||
GameMain.Client.CreateKickReasonPrompt(client.Name, ban: true, rangeBan: false);
|
||||
}
|
||||
|
||||
public void BanPlayerRange(Client client)
|
||||
{
|
||||
if (GameMain.NetworkMember == null || client == null) { return; }
|
||||
GameMain.Client.CreateKickReasonPrompt(client.Name, true, true);
|
||||
GameMain.Client.CreateKickReasonPrompt(client.Name, ban: true, rangeBan: true);
|
||||
}
|
||||
|
||||
public override void AddToGUIUpdateList()
|
||||
|
||||
@@ -1,333 +0,0 @@
|
||||
using FarseerPhysics;
|
||||
using FarseerPhysics.Dynamics.Joints;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
class OldCharacterEditorScreen : Screen
|
||||
{
|
||||
private Camera cam;
|
||||
|
||||
private GUIComponent GUIpanel;
|
||||
private GUIButton physicsButton;
|
||||
|
||||
private GUIListBox limbList, jointList;
|
||||
|
||||
private GUIFrame limbPanel;
|
||||
|
||||
private Character editingCharacter;
|
||||
private Limb editingLimb;
|
||||
|
||||
private List<Texture2D> textures;
|
||||
private List<string> texturePaths;
|
||||
|
||||
private bool physicsEnabled;
|
||||
|
||||
public override Camera Cam
|
||||
{
|
||||
get { return cam; }
|
||||
}
|
||||
|
||||
public override void Select()
|
||||
{
|
||||
base.Select();
|
||||
|
||||
GameMain.DebugDraw = true;
|
||||
|
||||
cam = new Camera();
|
||||
|
||||
/*GUIpanel = new GUIFrame(new Rectangle(0, 0, 300, GameMain.GraphicsHeight), "");
|
||||
//GUIpanel.Padding = new Vector4(10.0f, 10.0f, 10.0f, 10.0f);
|
||||
|
||||
physicsButton = new GUIButton(new Rectangle(0, 50, 200, 25), "Physics", Alignment.Left, "", GUIpanel);
|
||||
physicsButton.OnClicked += TogglePhysics;
|
||||
|
||||
new GUITextBlock(new Rectangle(0, 80, 0, 25), "Limbs:", "", GUIpanel);
|
||||
limbList = new GUIListBox(new Rectangle(0, 110, 0, 250), Color.White * 0.7f, "", GUIpanel);
|
||||
limbList.OnSelected = SelectLimb;
|
||||
|
||||
new GUITextBlock(new Rectangle(0, 360, 0, 25), "Joints:", "", GUIpanel);
|
||||
jointList = new GUIListBox(new Rectangle(0, 390, 0, 250), Color.White * 0.7f, "", GUIpanel);*/
|
||||
|
||||
while (Character.CharacterList.Count > 1)
|
||||
{
|
||||
Character.CharacterList.First().Remove();
|
||||
}
|
||||
|
||||
if (Character.CharacterList.Count == 1)
|
||||
{
|
||||
if (editingCharacter != Character.CharacterList[0]) UpdateLimbLists(Character.CharacterList[0]);
|
||||
editingCharacter = Character.CharacterList[0];
|
||||
|
||||
Vector2 camPos = editingCharacter.AnimController.Limbs[0].body.SimPosition;
|
||||
camPos = ConvertUnits.ToDisplayUnits(camPos);
|
||||
camPos.Y = -camPos.Y;
|
||||
cam.TargetPos = camPos;
|
||||
|
||||
if (physicsEnabled)
|
||||
{
|
||||
editingCharacter.Control(1.0f, cam);
|
||||
}
|
||||
else
|
||||
{
|
||||
cam.TargetPos = Vector2.Zero;
|
||||
}
|
||||
}
|
||||
|
||||
textures = new List<Texture2D>();
|
||||
texturePaths = new List<string>();
|
||||
foreach (Limb limb in editingCharacter.AnimController.Limbs)
|
||||
{
|
||||
if (limb.ActiveSprite==null || texturePaths.Contains(limb.ActiveSprite.FilePath)) continue;
|
||||
textures.Add(limb.ActiveSprite.Texture);
|
||||
texturePaths.Add(limb.ActiveSprite.FilePath);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Allows the game to run logic such as updating the world,
|
||||
/// checking for collisions, gathering input, and playing audio.
|
||||
/// </summary>
|
||||
public override void Update(double deltaTime)
|
||||
{
|
||||
cam.MoveCamera((float)deltaTime);
|
||||
|
||||
GUIpanel.UpdateManually((float)deltaTime);
|
||||
|
||||
if (physicsEnabled)
|
||||
{
|
||||
Character.UpdateAnimAll((float)deltaTime);
|
||||
|
||||
Ragdoll.UpdateAll((float)deltaTime, cam);
|
||||
|
||||
GameMain.World.Step((float)deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
public override void AddToGUIUpdateList()
|
||||
{
|
||||
GUIpanel.AddToGUIUpdateList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is called when the game should draw itself.
|
||||
/// </summary>
|
||||
public override void Draw(double deltaTime, GraphicsDevice graphics, SpriteBatch spriteBatch)
|
||||
{
|
||||
//cam.UpdateTransform();
|
||||
|
||||
graphics.Clear(Color.CornflowerBlue);
|
||||
|
||||
spriteBatch.Begin(SpriteSortMode.BackToFront,
|
||||
BlendState.AlphaBlend,
|
||||
null, null, null, null,
|
||||
cam.Transform);
|
||||
|
||||
Submarine.Draw(spriteBatch, true);
|
||||
|
||||
spriteBatch.End();
|
||||
|
||||
spriteBatch.Begin(SpriteSortMode.BackToFront,
|
||||
BlendState.AlphaBlend,
|
||||
null, null, null, null,
|
||||
cam.Transform);
|
||||
|
||||
//if (EntityPrefab.Selected != null) EntityPrefab.Selected.UpdatePlacing(spriteBatch, cam);
|
||||
|
||||
//Entity.DrawSelecting(spriteBatch, cam);
|
||||
|
||||
if (editingCharacter!=null)
|
||||
editingCharacter.Draw(spriteBatch, Cam);
|
||||
|
||||
spriteBatch.End();
|
||||
|
||||
//-------------------- HUD -----------------------------
|
||||
|
||||
spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, GameMain.ScissorTestEnable);
|
||||
|
||||
GUIpanel.DrawManually(spriteBatch);
|
||||
|
||||
EditLimb(spriteBatch);
|
||||
|
||||
|
||||
int y = 0;
|
||||
for (int i = 0; i < textures.Count; i++ )
|
||||
{
|
||||
int x = GameMain.GraphicsWidth - textures[i].Width;
|
||||
spriteBatch.Draw(textures[i], new Vector2(x, y), Color.White);
|
||||
|
||||
foreach (Limb limb in editingCharacter.AnimController.Limbs)
|
||||
{
|
||||
if (limb.ActiveSprite == null || limb.ActiveSprite.FilePath != texturePaths[i]) continue;
|
||||
Rectangle rect = limb.ActiveSprite.SourceRect;
|
||||
rect.X += x;
|
||||
rect.Y += y;
|
||||
|
||||
GUI.DrawRectangle(spriteBatch, rect, Color.Red);
|
||||
|
||||
Vector2 limbBodyPos = new Vector2(
|
||||
rect.X + limb.ActiveSprite.Origin.X,
|
||||
rect.Y + limb.ActiveSprite.Origin.Y);
|
||||
|
||||
DrawJoints(spriteBatch, limb, limbBodyPos);
|
||||
|
||||
//if (limb.BodyShapeTexture == null) continue;
|
||||
|
||||
//spriteBatch.Draw(limb.BodyShapeTexture, limbBodyPos,
|
||||
// null, Color.White, 0.0f,
|
||||
// new Vector2(limb.BodyShapeTexture.Width, limb.BodyShapeTexture.Height) / 2,
|
||||
// 1.0f, SpriteEffects.None, 0.0f);
|
||||
|
||||
GUI.DrawLine(spriteBatch, limbBodyPos + Vector2.UnitY * 5.0f, limbBodyPos - Vector2.UnitY * 5.0f, Color.White);
|
||||
GUI.DrawLine(spriteBatch, limbBodyPos + Vector2.UnitX * 5.0f, limbBodyPos - Vector2.UnitX * 5.0f, Color.White);
|
||||
|
||||
if (Vector2.Distance(PlayerInput.MousePosition, limbBodyPos)<5.0f && PlayerInput.LeftButtonHeld())
|
||||
{
|
||||
limb.ActiveSprite.Origin += PlayerInput.MouseSpeed;
|
||||
}
|
||||
}
|
||||
|
||||
y += textures[i].Height;
|
||||
}
|
||||
|
||||
|
||||
GUI.Draw(Cam, spriteBatch);
|
||||
|
||||
//EntityPrefab.DrawList(spriteBatch, new Vector2(20,50));
|
||||
|
||||
//Entity.Edit(spriteBatch, cam);
|
||||
|
||||
spriteBatch.End();
|
||||
}
|
||||
|
||||
private void UpdateLimbLists(Character character)
|
||||
{
|
||||
limbList.ClearChildren();
|
||||
/*foreach (Limb limb in character.AnimController.Limbs)
|
||||
{
|
||||
GUITextBlock textBlock = new GUITextBlock(
|
||||
new Rectangle(0,0,0,25),
|
||||
limb.type.ToString(),
|
||||
Color.Transparent,
|
||||
Color.White,
|
||||
Alignment.Left, null,
|
||||
limbList);
|
||||
textBlock.Padding = new Vector4(10.0f, 0.0f, 0.0f, 0.0f);
|
||||
textBlock.UserData = limb;
|
||||
}
|
||||
|
||||
jointList.ClearChildren();
|
||||
foreach (RevoluteJoint joint in character.AnimController.LimbJoints)
|
||||
{
|
||||
Limb limb1 = (Limb)(joint.BodyA.UserData);
|
||||
Limb limb2 = (Limb)(joint.BodyB.UserData);
|
||||
|
||||
GUITextBlock textBlock = new GUITextBlock(
|
||||
new Rectangle(0, 0, 0, 25),
|
||||
limb1.type.ToString() + " - " + limb2.type.ToString(),
|
||||
Color.Transparent,
|
||||
Color.White,
|
||||
Alignment.Left, null,
|
||||
jointList);
|
||||
textBlock.Padding = new Vector4(10.0f, 0.0f, 0.0f, 0.0f);
|
||||
textBlock.UserData = joint;
|
||||
}*/
|
||||
}
|
||||
|
||||
private void DrawJoints(SpriteBatch spriteBatch, Limb limb, Vector2 limbBodyPos)
|
||||
{
|
||||
foreach (var joint in editingCharacter.AnimController.LimbJoints)
|
||||
{
|
||||
Vector2 jointPos = Vector2.Zero;
|
||||
|
||||
if (joint.BodyA == limb.body.FarseerBody)
|
||||
{
|
||||
jointPos = ConvertUnits.ToDisplayUnits(joint.LocalAnchorA);
|
||||
|
||||
}
|
||||
else if (joint.BodyB == limb.body.FarseerBody)
|
||||
{
|
||||
jointPos = ConvertUnits.ToDisplayUnits(joint.LocalAnchorB);
|
||||
}
|
||||
else
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
Vector2 tformedJointPos = jointPos /= limb.Scale;
|
||||
tformedJointPos.Y = -tformedJointPos.Y;
|
||||
tformedJointPos += limbBodyPos;
|
||||
|
||||
if (joint.BodyA == limb.body.FarseerBody)
|
||||
{
|
||||
float a1 = joint.UpperLimit - MathHelper.PiOver2;
|
||||
float a2 = joint.LowerLimit - MathHelper.PiOver2;
|
||||
float a3 = (a1 + a2) / 2.0f;
|
||||
GUI.DrawLine(spriteBatch, tformedJointPos, tformedJointPos + new Vector2((float)Math.Cos(a1), -(float)Math.Sin(a1)) * 30.0f, Color.Green);
|
||||
GUI.DrawLine(spriteBatch, tformedJointPos, tformedJointPos + new Vector2((float)Math.Cos(a2), -(float)Math.Sin(a2)) * 30.0f, Color.DarkGreen);
|
||||
|
||||
GUI.DrawLine(spriteBatch, tformedJointPos, tformedJointPos + new Vector2((float)Math.Cos(a3), -(float)Math.Sin(a3)) * 30.0f, Color.LightGray);
|
||||
}
|
||||
|
||||
GUI.DrawRectangle(spriteBatch, tformedJointPos, new Vector2(5.0f, 5.0f), Color.Red, true);
|
||||
if (Vector2.Distance(PlayerInput.MousePosition, tformedJointPos) < 10.0f)
|
||||
{
|
||||
GUI.DrawString(spriteBatch, tformedJointPos + Vector2.One*10.0f, jointPos.ToString(), Color.White, Color.Black * 0.5f);
|
||||
GUI.DrawRectangle(spriteBatch, tformedJointPos - new Vector2(3.0f, 3.0f), new Vector2(11.0f, 11.0f), Color.Red, false);
|
||||
if (PlayerInput.LeftButtonHeld())
|
||||
{
|
||||
Vector2 speed = ConvertUnits.ToSimUnits(PlayerInput.MouseSpeed);
|
||||
speed.Y = -speed.Y;
|
||||
if (joint.BodyA == limb.body.FarseerBody)
|
||||
{
|
||||
joint.LocalAnchorA += speed;
|
||||
}
|
||||
else
|
||||
{
|
||||
joint.LocalAnchorB += speed;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool SelectLimb(GUIComponent component, object selection)
|
||||
{
|
||||
/*try
|
||||
{
|
||||
editingLimb = (Limb)selection;
|
||||
limbPanel = new GUIFrame(new Rectangle(300, 0, 500, 100), Color.Gray*0.8f);
|
||||
//limbPanel.Padding = new Vector4(10.0f,10.0f,10.0f,10.0f);
|
||||
new GUITextBlock(new Rectangle(0, 0, 200, 25), editingLimb.type.ToString(), Color.Transparent, Color.Black, Alignment.Left, null, limbPanel);
|
||||
|
||||
//spriteOrigin = new GUITextBlock(new Rectangle(0, 25, 200, 25), "Sprite origin: ", Color.White, Color.Black, Alignment.Left, limbPanel);
|
||||
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}*/
|
||||
return true;
|
||||
}
|
||||
|
||||
private void EditLimb(SpriteBatch spriteBatch)
|
||||
{
|
||||
if (editingLimb == null) return;
|
||||
|
||||
limbPanel.DrawManually(spriteBatch);
|
||||
}
|
||||
|
||||
private bool TogglePhysics(GUIButton button, object selection)
|
||||
{
|
||||
physicsEnabled = !physicsEnabled;
|
||||
|
||||
physicsButton.Text = (physicsEnabled) ? "Disable physics" : "Enable physics";
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,73 +19,87 @@ namespace Barotrauma
|
||||
//how often the client is allowed to refresh servers
|
||||
private TimeSpan AllowedRefreshInterval = new TimeSpan(0, 0, 3);
|
||||
|
||||
private GUIFrame menu;
|
||||
private readonly GUIFrame menu;
|
||||
|
||||
private GUIListBox serverList;
|
||||
private GUIListBox serverPreview;
|
||||
private readonly GUIListBox serverList;
|
||||
private readonly GUIFrame serverPreview;
|
||||
|
||||
private GUIButton joinButton;
|
||||
private readonly GUIButton joinButton;
|
||||
|
||||
private GUITextBox clientNameBox, ipBox;
|
||||
private readonly GUITextBox clientNameBox, ipBox;
|
||||
|
||||
private bool masterServerResponded;
|
||||
private IRestResponse masterServerResponse;
|
||||
|
||||
private GUIButton refreshButton;
|
||||
|
||||
private float[] columnRelativeWidth;
|
||||
|
||||
private readonly float[] columnRelativeWidth = new float[] { 0.1f, 0.1f, 0.7f, 0.12f, 0.08f, 0.08f };
|
||||
private readonly string[] columnLabel = new string[] { "ServerListCompatible", "ServerListHasPassword", "ServerListName", "ServerListRoundStarted", "ServerListPlayers", "ServerListPing" };
|
||||
|
||||
private readonly GUILayoutGroup labelHolder;
|
||||
private readonly List<GUITextBlock> labelTexts = new List<GUITextBlock>();
|
||||
|
||||
//filters
|
||||
private GUITextBox searchBox;
|
||||
private GUITickBox filterPassword;
|
||||
private GUITickBox filterIncompatible;
|
||||
private GUITickBox filterFull;
|
||||
private GUITickBox filterEmpty;
|
||||
private readonly GUITextBox searchBox;
|
||||
private readonly GUITickBox filterPassword;
|
||||
private readonly GUITickBox filterIncompatible;
|
||||
private readonly GUITickBox filterFull;
|
||||
private readonly GUITickBox filterEmpty;
|
||||
|
||||
//a timer for
|
||||
private string sortedBy;
|
||||
|
||||
private readonly GUIButton serverPreviewToggleButton;
|
||||
|
||||
//a timer for preventing the client from spamming the refresh button faster than AllowedRefreshInterval
|
||||
private DateTime refreshDisableTimer;
|
||||
private bool waitingForRefresh;
|
||||
|
||||
|
||||
public ServerListScreen()
|
||||
{
|
||||
GameMain.Instance.OnResolutionChanged += OnResolutionChanged;
|
||||
|
||||
menu = new GUIFrame(new RectTransform(new Vector2(0.7f, 0.8f), GUI.Canvas, Anchor.Center) { MinSize = new Point(GameMain.GraphicsHeight, 0) });
|
||||
menu = new GUIFrame(new RectTransform(new Vector2(0.95f, 0.85f), GUI.Canvas, Anchor.Center) { MinSize = new Point(GameMain.GraphicsHeight, 0) });
|
||||
|
||||
var paddedFrame = new GUILayoutGroup(new RectTransform(new Vector2(0.97f, 0.95f), menu.RectTransform, Anchor.Center), isHorizontal: true)
|
||||
{ Stretch = true, RelativeSpacing = 0.02f };
|
||||
|
||||
//-------------------------------------------------------------------------------------
|
||||
//left column
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
var leftColumn = new GUILayoutGroup(new RectTransform(new Vector2(0.25f, 1.0f), paddedFrame.RectTransform, Anchor.CenterLeft)) { Stretch = true, RelativeSpacing = 0.5f };
|
||||
|
||||
var infoHolder = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.5f), leftColumn.RectTransform)) { RelativeSpacing = 0.05f };
|
||||
|
||||
new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.3f), infoHolder.RectTransform, Anchor.Center), TextManager.Get("JoinServer"), font: GUI.LargeFont)
|
||||
var paddedFrame = new GUILayoutGroup(new RectTransform(new Vector2(0.97f, 0.95f), menu.RectTransform, Anchor.Center))
|
||||
{
|
||||
RelativeSpacing = 0.02f,
|
||||
Stretch = true
|
||||
};
|
||||
|
||||
//-------------------------------------------------------------------------------------
|
||||
//Top row
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
var topRow = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.15f), paddedFrame.RectTransform)) { Stretch = true };
|
||||
|
||||
var title = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.33f), topRow.RectTransform), TextManager.Get("JoinServer"), font: GUI.LargeFont)
|
||||
{
|
||||
Padding = Vector4.Zero,
|
||||
ForceUpperCase = true,
|
||||
AutoScale = true
|
||||
};
|
||||
|
||||
new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), infoHolder.RectTransform), TextManager.Get("YourName"));
|
||||
clientNameBox = new GUITextBox(new RectTransform(new Vector2(1.0f, 0.13f), infoHolder.RectTransform), "")
|
||||
var infoHolder = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.33f), topRow.RectTransform), isHorizontal: true) { RelativeSpacing = 0.05f, Stretch = true };
|
||||
|
||||
var clientNameHolder = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 1.0f), infoHolder.RectTransform)) { RelativeSpacing = 0.05f };
|
||||
|
||||
new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), clientNameHolder.RectTransform), TextManager.Get("YourName"));
|
||||
clientNameBox = new GUITextBox(new RectTransform(new Vector2(1.0f, 0.5f), clientNameHolder.RectTransform), "")
|
||||
{
|
||||
Text = GameMain.Config.DefaultPlayerName,
|
||||
MaxTextLength = Client.MaxNameLength,
|
||||
OverflowClip = true
|
||||
};
|
||||
|
||||
if (string.IsNullOrEmpty(clientNameBox.Text))
|
||||
{
|
||||
clientNameBox.Text = SteamManager.GetUsername();
|
||||
}
|
||||
clientNameBox.OnTextChanged += RefreshJoinButtonState;
|
||||
|
||||
new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), infoHolder.RectTransform), TextManager.Get("ServerIP"));
|
||||
ipBox = new GUITextBox(new RectTransform(new Vector2(1.0f, 0.13f), infoHolder.RectTransform), "");
|
||||
ipBox.OnTextChanged += RefreshJoinButtonState;
|
||||
ipBox.OnSelected += (sender, key) =>
|
||||
var ipBoxHolder = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 1.0f), infoHolder.RectTransform)) { RelativeSpacing = 0.05f };
|
||||
|
||||
new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), ipBoxHolder.RectTransform), TextManager.Get("ServerIP"));
|
||||
ipBox = new GUITextBox(new RectTransform(new Vector2(1.0f, 0.5f), ipBoxHolder.RectTransform), "");
|
||||
ipBox.OnTextChanged += (textBox, text) => { joinButton.Enabled = !string.IsNullOrEmpty(text); return true; };
|
||||
ipBox.OnSelected += (sender, key) =>
|
||||
{
|
||||
if (sender.UserData is ServerInfo)
|
||||
{
|
||||
@@ -94,93 +108,357 @@ namespace Barotrauma
|
||||
}
|
||||
};
|
||||
|
||||
var filterHolder = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.5f), leftColumn.RectTransform)) { RelativeSpacing = 0.05f };
|
||||
|
||||
new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), filterHolder.RectTransform), TextManager.Get("FilterServers"));
|
||||
searchBox = new GUITextBox(new RectTransform(new Vector2(1.0f, 0.13f), filterHolder.RectTransform), "");
|
||||
|
||||
var tickBoxHolder = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.5f), filterHolder.RectTransform));
|
||||
|
||||
searchBox.OnTextChanged += (txtBox, txt) => { FilterServers(); return true; };
|
||||
filterPassword = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.27f), tickBoxHolder.RectTransform), TextManager.Get("FilterPassword"));
|
||||
filterPassword.OnSelected += (tickBox) => { FilterServers(); return true; };
|
||||
filterIncompatible = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.27f), tickBoxHolder.RectTransform), TextManager.Get("FilterIncompatibleServers"));
|
||||
filterIncompatible.OnSelected += (tickBox) => { FilterServers(); return true; };
|
||||
|
||||
filterFull = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.27f), tickBoxHolder.RectTransform), TextManager.Get("FilterFullServers"));
|
||||
filterFull.OnSelected += (tickBox) => { FilterServers(); return true; };
|
||||
filterEmpty = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.27f), tickBoxHolder.RectTransform), TextManager.Get("FilterEmptyServers"));
|
||||
filterEmpty.OnSelected += (tickBox) => { FilterServers(); return true; };
|
||||
|
||||
//-------------------------------------------------------------------------------------
|
||||
//right column
|
||||
// Bottom row
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
var rightColumn = new GUILayoutGroup(new RectTransform(new Vector2(1.0f - leftColumn.RectTransform.RelativeSize.X - 0.017f, 1.0f),
|
||||
var bottomRow = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 1.0f - topRow.RectTransform.RelativeSize.Y),
|
||||
paddedFrame.RectTransform, Anchor.CenterRight))
|
||||
{
|
||||
RelativeSpacing = 0.02f,
|
||||
Stretch = true
|
||||
};
|
||||
|
||||
var serverListHolder = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 1.0f), rightColumn.RectTransform)) { Stretch = true, RelativeSpacing = 0.02f };
|
||||
|
||||
serverList = new GUIListBox(new RectTransform(new Vector2(1.0f, 1.0f), serverListHolder.RectTransform, Anchor.Center))
|
||||
var serverListHolder = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 1.0f), bottomRow.RectTransform), isHorizontal: true)
|
||||
{
|
||||
OnSelected = (btn, obj) => {
|
||||
if (obj is ServerInfo)
|
||||
Stretch = true
|
||||
};
|
||||
|
||||
// filters -------------------------------------------
|
||||
|
||||
var filters = new GUIFrame(new RectTransform(new Vector2(0.25f, 1.0f), serverListHolder.RectTransform, Anchor.Center), style: null)
|
||||
{
|
||||
Color = new Color(12, 14, 15, 255) * 0.5f,
|
||||
OutlineColor = Color.Black
|
||||
};
|
||||
var filterToggle = new GUIButton(new RectTransform(new Vector2(0.02f, 1.0f), serverListHolder.RectTransform, Anchor.CenterRight) { MinSize = new Point(20, 0) }, style: "UIToggleButton")
|
||||
{
|
||||
OnClicked = (btn, userdata) =>
|
||||
{
|
||||
filters.RectTransform.RelativeSize = new Vector2(0.25f, 1.0f);
|
||||
filters.Visible = !filters.Visible;
|
||||
filters.IgnoreLayoutGroups = !filters.Visible;
|
||||
serverListHolder.Recalculate();
|
||||
btn.Children.ForEach(c => c.SpriteEffects = !filters.Visible ? SpriteEffects.None : SpriteEffects.FlipHorizontally);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
filterToggle.Children.ForEach(c => c.SpriteEffects = SpriteEffects.FlipHorizontally);
|
||||
|
||||
var filterContainer = new GUILayoutGroup(new RectTransform(new Vector2(0.95f, 0.99f), filters.RectTransform, Anchor.Center))
|
||||
{
|
||||
Stretch = true,
|
||||
RelativeSpacing = 0.015f
|
||||
};
|
||||
|
||||
var filterTitle = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), filterContainer.RectTransform), TextManager.Get("FilterServers"), font: GUI.LargeFont)
|
||||
{
|
||||
Padding = Vector4.Zero,
|
||||
AutoScale = true
|
||||
};
|
||||
|
||||
float elementHeight = 0.05f;
|
||||
|
||||
var searchHolder = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, elementHeight), filterContainer.RectTransform), isHorizontal: true) { Stretch = true };
|
||||
|
||||
var searchTitle = new GUITextBlock(new RectTransform(new Vector2(0.001f, 1.0f), searchHolder.RectTransform), TextManager.Get("Search") + "...");
|
||||
searchBox = new GUITextBox(new RectTransform(new Vector2(1.0f, 1.0f), searchHolder.RectTransform), "");
|
||||
searchBox.OnSelected += (sender, userdata) => { searchTitle.Visible = false; };
|
||||
searchBox.OnDeselected += (sender, userdata) => { searchTitle.Visible = true; };
|
||||
searchBox.OnTextChanged += (txtBox, txt) => { FilterServers(); return true; };
|
||||
|
||||
var filterHolder = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 1.0f), filterContainer.RectTransform)) { RelativeSpacing = 0.005f };
|
||||
|
||||
List<GUITextBlock> filterTextList = new List<GUITextBlock>();
|
||||
filterPassword = new GUITickBox(new RectTransform(new Vector2(1.0f, elementHeight), filterHolder.RectTransform), TextManager.Get("FilterPassword"))
|
||||
{
|
||||
ToolTip = TextManager.Get("FilterPassword"),
|
||||
OnSelected = (tickBox) => { FilterServers(); return true; }
|
||||
};
|
||||
filterTextList.Add(filterPassword.TextBlock);
|
||||
filterIncompatible = new GUITickBox(new RectTransform(new Vector2(1.0f, elementHeight), filterHolder.RectTransform), TextManager.Get("FilterIncompatibleServers"))
|
||||
{
|
||||
ToolTip = TextManager.Get("FilterIncompatibleServers"),
|
||||
OnSelected = (tickBox) => { FilterServers(); return true; }
|
||||
};
|
||||
filterTextList.Add(filterIncompatible.TextBlock);
|
||||
filterFull = new GUITickBox(new RectTransform(new Vector2(1.0f, elementHeight), filterHolder.RectTransform), TextManager.Get("FilterFullServers"))
|
||||
{
|
||||
ToolTip = TextManager.Get("FilterFullServers"),
|
||||
OnSelected = (tickBox) => { FilterServers(); return true; }
|
||||
};
|
||||
filterTextList.Add(filterFull.TextBlock);
|
||||
filterEmpty = new GUITickBox(new RectTransform(new Vector2(1.0f, elementHeight), filterHolder.RectTransform), TextManager.Get("FilterEmptyServers"))
|
||||
{
|
||||
ToolTip = TextManager.Get("FilterEmptyServers"),
|
||||
OnSelected = (tickBox) => { FilterServers(); return true; }
|
||||
};
|
||||
filterTextList.Add(filterEmpty.TextBlock);
|
||||
|
||||
filterContainer.RectTransform.SizeChanged += () =>
|
||||
{
|
||||
filterContainer.RectTransform.RecalculateChildren(true, true);
|
||||
filterTextList.ForEach(t => t.Text = t.ToolTip);
|
||||
GUITextBlock.AutoScaleAndNormalize(filterTextList);
|
||||
if (filterTextList[0].TextScale < 0.8f)
|
||||
{
|
||||
filterTextList.ForEach(t => t.TextScale = 1.0f);
|
||||
filterTextList.ForEach(t => t.Text = ToolBox.LimitString(t.Text, t.Font, (int)(filterContainer.Rect.Width * 0.8f)));
|
||||
}
|
||||
};
|
||||
|
||||
// server list ---------------------------------------------------------------------
|
||||
|
||||
var serverListContainer = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 1.0f), serverListHolder.RectTransform)) { Stretch = true };
|
||||
|
||||
labelHolder = new GUILayoutGroup(new RectTransform(new Vector2(0.99f, 0.05f), serverListContainer.RectTransform) { MinSize = new Point(0, 15) },
|
||||
isHorizontal: true)
|
||||
{
|
||||
Stretch = true
|
||||
};
|
||||
|
||||
for (int i = 0; i < columnRelativeWidth.Length; i++)
|
||||
{
|
||||
var btn = new GUIButton(new RectTransform(new Vector2(columnRelativeWidth[i], 1.0f), labelHolder.RectTransform),
|
||||
text: TextManager.Get(columnLabel[i]), textAlignment: Alignment.Center, style: null)
|
||||
{
|
||||
Color = new Color(12, 14, 15, 255) * 0.5f,
|
||||
HoverColor = new Color(12, 14, 15, 255) * 2.5f,
|
||||
SelectedColor = Color.Gray * 0.7f,
|
||||
PressedColor = Color.Gray * 0.7f,
|
||||
OutlineColor = Color.Black,
|
||||
ToolTip = TextManager.Get(columnLabel[i]),
|
||||
ForceUpperCase = true,
|
||||
UserData = columnLabel[i],
|
||||
OnClicked = SortList
|
||||
};
|
||||
labelTexts.Add(btn.TextBlock);
|
||||
|
||||
new GUIImage(new RectTransform(new Vector2(0.5f, 0.3f), btn.RectTransform, Anchor.BottomCenter, scaleBasis: ScaleBasis.BothHeight), style: "GUIButtonVerticalArrow", scaleToFit: true)
|
||||
{
|
||||
CanBeFocused = false,
|
||||
UserData = "arrowup",
|
||||
Visible = false
|
||||
};
|
||||
new GUIImage(new RectTransform(new Vector2(0.5f, 0.3f), btn.RectTransform, Anchor.BottomCenter, scaleBasis: ScaleBasis.BothHeight), style: "GUIButtonVerticalArrow", scaleToFit: true)
|
||||
{
|
||||
CanBeFocused = false,
|
||||
UserData = "arrowdown",
|
||||
SpriteEffects = SpriteEffects.FlipVertically,
|
||||
Visible = false
|
||||
};
|
||||
}
|
||||
|
||||
serverList = new GUIListBox(new RectTransform(new Vector2(1.0f, 1.0f), serverListContainer.RectTransform, Anchor.Center))
|
||||
{
|
||||
ScrollBarVisible = true,
|
||||
OnSelected = (btn, obj) =>
|
||||
{
|
||||
if (obj is ServerInfo serverInfo)
|
||||
{
|
||||
ServerInfo serverInfo = (ServerInfo)obj;
|
||||
joinButton.Enabled = true;
|
||||
ipBox.UserData = serverInfo;
|
||||
ipBox.Text = serverInfo.ServerName;
|
||||
if (!serverPreview.Visible)
|
||||
{
|
||||
serverPreview.RectTransform.RelativeSize = new Vector2(0.3f, 1.0f);
|
||||
serverPreviewToggleButton.Visible = true;
|
||||
serverPreviewToggleButton.IgnoreLayoutGroups = false;
|
||||
serverPreview.Visible = true;
|
||||
serverPreview.IgnoreLayoutGroups = false;
|
||||
serverListHolder.Recalculate();
|
||||
}
|
||||
serverInfo.CreatePreviewWindow(serverPreview);
|
||||
btn.Children.ForEach(c => c.SpriteEffects = serverPreview.Visible ? SpriteEffects.None : SpriteEffects.FlipHorizontally);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
serverList.OnSelected += SelectServer;
|
||||
//server preview panel --------------------------------------------------
|
||||
|
||||
serverPreview = new GUIListBox(new RectTransform(new Vector2(1.0f, 1.0f), serverListHolder.RectTransform, Anchor.Center));
|
||||
serverPreviewToggleButton = new GUIButton(new RectTransform(new Vector2(0.02f, 1.0f), serverListHolder.RectTransform, Anchor.CenterRight) { MinSize = new Point(20, 0) }, style: "UIToggleButton")
|
||||
{
|
||||
Visible = false,
|
||||
OnClicked = (btn, userdata) =>
|
||||
{
|
||||
serverPreview.RectTransform.RelativeSize = new Vector2(0.25f, 1.0f);
|
||||
serverPreview.Visible = !serverPreview.Visible;
|
||||
serverPreview.IgnoreLayoutGroups = !serverPreview.Visible;
|
||||
serverListHolder.Recalculate();
|
||||
btn.Children.ForEach(c => c.SpriteEffects = serverPreview.Visible ? SpriteEffects.None : SpriteEffects.FlipHorizontally);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
columnRelativeWidth = new float[] { 0.04f, 0.02f, 0.044f, 0.77f, 0.02f, 0.075f, 0.06f };
|
||||
serverPreview = new GUIFrame(new RectTransform(new Vector2(0.3f, 1.0f), serverListHolder.RectTransform, Anchor.Center), style: null)
|
||||
{
|
||||
Color = new Color(12, 14, 15, 255) * 0.5f,
|
||||
OutlineColor = Color.Black,
|
||||
IgnoreLayoutGroups = true,
|
||||
Visible = false
|
||||
};
|
||||
|
||||
var buttonContainer = new GUIFrame(new RectTransform(new Vector2(1.0f, 0.075f), rightColumn.RectTransform), style: null);
|
||||
// Spacing
|
||||
new GUIFrame(new RectTransform(new Vector2(1.0f, 0.02f), bottomRow.RectTransform), style: null);
|
||||
|
||||
GUIButton button = new GUIButton(new RectTransform(new Vector2(0.25f, 0.9f), buttonContainer.RectTransform, Anchor.TopLeft),
|
||||
var buttonContainer = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.075f), bottomRow.RectTransform, Anchor.Center), isHorizontal: true)
|
||||
{
|
||||
RelativeSpacing = 0.02f,
|
||||
Stretch = true
|
||||
};
|
||||
|
||||
GUIButton button = new GUIButton(new RectTransform(new Vector2(0.25f, 0.9f), buttonContainer.RectTransform),
|
||||
TextManager.Get("Back"), style: "GUIButtonLarge")
|
||||
{
|
||||
OnClicked = GameMain.MainMenuScreen.ReturnToMainMenu
|
||||
};
|
||||
|
||||
refreshButton = new GUIButton(new RectTransform(new Vector2(buttonContainer.Rect.Height / (float)buttonContainer.Rect.Width, 0.9f), buttonContainer.RectTransform, Anchor.Center),
|
||||
"", style: "GUIButtonRefresh") {
|
||||
|
||||
ToolTip = TextManager.Get("ServerListRefresh"),
|
||||
OnClicked = RefreshServers
|
||||
new GUIButton(new RectTransform(new Vector2(0.25f, 0.9f), buttonContainer.RectTransform),
|
||||
TextManager.Get("ServerListRefresh"), style: "GUIButtonLarge")
|
||||
{
|
||||
OnClicked = (btn, userdata) => { RefreshServers(); return true; }
|
||||
};
|
||||
|
||||
joinButton = new GUIButton(new RectTransform(new Vector2(0.25f, 0.9f), buttonContainer.RectTransform, Anchor.TopRight),
|
||||
/*var directJoinButton = new GUIButton(new RectTransform(new Vector2(0.25f, 0.9f), buttonContainer.RectTransform),
|
||||
TextManager.Get("serverlistdirectjoin"), style: "GUIButtonLarge")
|
||||
{
|
||||
OnClicked = (btn, userdata) => { ShowDirectJoinPrompt(); return true; }
|
||||
};*/
|
||||
|
||||
joinButton = new GUIButton(new RectTransform(new Vector2(0.25f, 0.9f), buttonContainer.RectTransform),
|
||||
TextManager.Get("ServerListJoin"), style: "GUIButtonLarge")
|
||||
{
|
||||
OnClicked = JoinServer,
|
||||
OnClicked = (btn, userdata) =>
|
||||
{
|
||||
if (ipBox.UserData is ServerInfo selectedServer)
|
||||
{
|
||||
JoinServer(selectedServer.IP + ":" + selectedServer.Port, selectedServer.ServerName);
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(ipBox.Text))
|
||||
{
|
||||
JoinServer(ipBox.Text, "");
|
||||
}
|
||||
return true;
|
||||
},
|
||||
Enabled = false
|
||||
};
|
||||
|
||||
//--------------------------------------------------------
|
||||
|
||||
button.SelectedColor = button.Color;
|
||||
bottomRow.Recalculate();
|
||||
serverListHolder.Recalculate();
|
||||
serverListContainer.Recalculate();
|
||||
labelHolder.RectTransform.MaxSize = new Point(serverList.Content.Rect.Width, int.MaxValue);
|
||||
labelHolder.Recalculate();
|
||||
|
||||
serverList.Content.RectTransform.SizeChanged += () =>
|
||||
{
|
||||
labelHolder.RectTransform.MaxSize = new Point(serverList.Content.Rect.Width, int.MaxValue);
|
||||
labelHolder.Recalculate();
|
||||
foreach (GUITextBlock labelText in labelTexts)
|
||||
{
|
||||
labelText.Text = ToolBox.LimitString(labelText.ToolTip, labelText.Font, labelText.Rect.Width);
|
||||
}
|
||||
};
|
||||
|
||||
button.SelectedColor = button.Color;
|
||||
refreshDisableTimer = DateTime.Now;
|
||||
}
|
||||
|
||||
private void OnResolutionChanged()
|
||||
{
|
||||
menu.RectTransform.MinSize = new Point(GameMain.GraphicsHeight, 0);
|
||||
labelHolder.RectTransform.MaxSize = new Point(serverList.Content.Rect.Width, int.MaxValue);
|
||||
foreach (GUITextBlock labelText in labelTexts)
|
||||
{
|
||||
labelText.Text = ToolBox.LimitString(labelText.ToolTip, labelText.Font, labelText.Rect.Width);
|
||||
}
|
||||
}
|
||||
|
||||
private bool SortList(GUIButton button, object obj)
|
||||
{
|
||||
if (!(obj is string sortBy)) { return false; }
|
||||
SortList(sortBy, toggle: true);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void SortList(string sortBy, bool toggle)
|
||||
{
|
||||
GUIButton button = labelHolder.GetChildByUserData(sortBy) as GUIButton;
|
||||
if (button == null) { return; }
|
||||
|
||||
sortedBy = sortBy;
|
||||
|
||||
var arrowUp = button.GetChildByUserData("arrowup");
|
||||
var arrowDown = button.GetChildByUserData("arrowdown");
|
||||
|
||||
//disable arrow buttons in other labels
|
||||
foreach (var child in button.Parent.Children)
|
||||
{
|
||||
if (child != button)
|
||||
{
|
||||
child.GetChildByUserData("arrowup").Visible = false;
|
||||
child.GetChildByUserData("arrowdown").Visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
bool ascending = arrowUp.Visible;
|
||||
if (toggle)
|
||||
{
|
||||
ascending = !ascending;
|
||||
}
|
||||
|
||||
arrowUp.Visible = ascending;
|
||||
arrowDown.Visible = !ascending;
|
||||
serverList.Content.RectTransform.SortChildren((c1, c2) =>
|
||||
{
|
||||
ServerInfo s1 = c1.GUIComponent.UserData as ServerInfo;
|
||||
ServerInfo s2 = c2.GUIComponent.UserData as ServerInfo;
|
||||
|
||||
switch (sortBy)
|
||||
{
|
||||
case "ServerListCompatible":
|
||||
bool? s1Compatible = NetworkMember.IsCompatible(GameMain.Version.ToString(), s1.GameVersion);
|
||||
if (!s1.ContentPackageHashes.Any()) { s1Compatible = null; }
|
||||
if (s1Compatible.HasValue) { s1Compatible = s1Compatible.Value && s1.ContentPackagesMatch(GameMain.SelectedPackages); };
|
||||
|
||||
bool? s2Compatible = NetworkMember.IsCompatible(GameMain.Version.ToString(), s2.GameVersion);
|
||||
if (!s2.ContentPackageHashes.Any()) { s2Compatible = null; }
|
||||
if (s2Compatible.HasValue) { s2Compatible = s2Compatible.Value && s2.ContentPackagesMatch(GameMain.SelectedPackages); };
|
||||
|
||||
//convert to int to make sorting easier
|
||||
//1 Compatible
|
||||
//0 Unknown
|
||||
//-1 Incompatible
|
||||
int s1CompatibleInt = s1Compatible.HasValue ?
|
||||
(s1Compatible.Value ? 1 : -1) :
|
||||
0;
|
||||
int s2CompatibleInt = s2Compatible.HasValue ?
|
||||
(s2Compatible.Value ? 1 : -1) :
|
||||
0;
|
||||
return s2CompatibleInt.CompareTo(s1CompatibleInt) * (ascending ? 1 : -1);
|
||||
case "ServerListHasPassword":
|
||||
if (s1.HasPassword == s2.HasPassword) { return 0; }
|
||||
return (s1.HasPassword ? 1 : -1) * (ascending ? 1 : -1);
|
||||
case "ServerListName":
|
||||
return s1.ServerName.CompareTo(s2.ServerName) * (ascending ? 1 : -1);
|
||||
case "ServerListRoundStarted":
|
||||
if (s1.GameStarted == s2.GameStarted) { return 0; }
|
||||
return (s1.GameStarted ? 1 : -1) * (ascending ? 1 : -1);
|
||||
case "ServerListPlayers":
|
||||
return s2.PlayerCount.CompareTo(s1.PlayerCount) * (ascending ? 1 : -1);
|
||||
case "ServerListPing":
|
||||
return s2.Ping.CompareTo(s1.Ping) * (ascending ? 1 : -1);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public override void Select()
|
||||
{
|
||||
base.Select();
|
||||
RefreshServers(null, null);
|
||||
RefreshServers();
|
||||
}
|
||||
|
||||
private void FilterServers()
|
||||
@@ -192,9 +470,15 @@ namespace Barotrauma
|
||||
if (!(child.UserData is ServerInfo)) continue;
|
||||
ServerInfo serverInfo = (ServerInfo)child.UserData;
|
||||
|
||||
Version remoteVersion = null;
|
||||
if (!string.IsNullOrEmpty(serverInfo.GameVersion))
|
||||
{
|
||||
Version.TryParse(serverInfo.GameVersion, out remoteVersion);
|
||||
}
|
||||
|
||||
bool incompatible =
|
||||
(!serverInfo.ContentPackageHashes.Any() && serverInfo.ContentPackagesMatch(GameMain.Config.SelectedContentPackages)) ||
|
||||
(!string.IsNullOrEmpty(serverInfo.GameVersion) && serverInfo.GameVersion != GameMain.Version.ToString());
|
||||
(remoteVersion != null && !NetworkMember.IsCompatible(GameMain.Version, remoteVersion));
|
||||
|
||||
child.Visible =
|
||||
serverInfo.ServerName.ToLowerInvariant().Contains(searchBox.Text.ToLowerInvariant()) &&
|
||||
@@ -216,59 +500,48 @@ namespace Barotrauma
|
||||
serverList.UpdateScrollBarSize();
|
||||
}
|
||||
|
||||
private bool RefreshJoinButtonState(GUIComponent component, object obj)
|
||||
/*private void ShowDirectJoinPrompt()
|
||||
{
|
||||
if (obj == null || waitingForRefresh) { return false; }
|
||||
var msgBox = new GUIMessageBox(TextManager.Get("ServerListDirectJoin"), "", new string[] { TextManager.Get("OK"), TextManager.Get("Cancel") },
|
||||
relativeSize: new Vector2(0.25f, 0.2f), minSize: new Point(400, 150));
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(clientNameBox.Text) && !string.IsNullOrWhiteSpace(ipBox.Text))
|
||||
var content = new GUILayoutGroup(new RectTransform(new Vector2(0.8f, 0.3f), msgBox.InnerFrame.RectTransform, Anchor.Center) { MinSize = new Point(0, 50) })
|
||||
{
|
||||
joinButton.Enabled = true;
|
||||
}
|
||||
else
|
||||
IgnoreLayoutGroups = true,
|
||||
Stretch = true,
|
||||
RelativeSpacing = 0.05f
|
||||
};
|
||||
|
||||
new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.5f), content.RectTransform), TextManager.Get("ServerIP"));
|
||||
var ipBox = new GUITextBox(new RectTransform(new Vector2(1.0f, 0.5f), content.RectTransform));
|
||||
|
||||
var okButton = msgBox.Buttons[0];
|
||||
okButton.Enabled = false;
|
||||
okButton.OnClicked = (btn, userdata) =>
|
||||
{
|
||||
joinButton.Enabled = false;
|
||||
}
|
||||
JoinServer(ipBox.Text, "");
|
||||
msgBox.Close();
|
||||
return true;
|
||||
};
|
||||
|
||||
return true;
|
||||
}
|
||||
var cancelButton = msgBox.Buttons[1];
|
||||
cancelButton.OnClicked = msgBox.Close;
|
||||
|
||||
private bool SelectServer(GUIComponent component, object obj)
|
||||
ipBox.OnTextChanged += (textBox, text) =>
|
||||
{
|
||||
okButton.Enabled = !string.IsNullOrEmpty(text);
|
||||
return true;
|
||||
};
|
||||
}*/
|
||||
|
||||
private void RefreshServers()
|
||||
{
|
||||
if (obj == null || waitingForRefresh || (!(obj is ServerInfo))) { return false; }
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(clientNameBox.Text))
|
||||
{
|
||||
joinButton.Enabled = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
clientNameBox.Flash();
|
||||
joinButton.Enabled = false;
|
||||
}
|
||||
|
||||
ServerInfo serverInfo;
|
||||
try
|
||||
{
|
||||
serverInfo = (ServerInfo)obj;
|
||||
ipBox.UserData = serverInfo;
|
||||
ipBox.Text = ToolBox.LimitString(serverInfo.ServerName, ipBox.Font, ipBox.Rect.Width);
|
||||
}
|
||||
catch (InvalidCastException)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool RefreshServers(GUIButton button, object obj)
|
||||
{
|
||||
if (waitingForRefresh) { return false; }
|
||||
if (waitingForRefresh) { return; }
|
||||
serverList.ClearChildren();
|
||||
serverPreview.ClearChildren();
|
||||
|
||||
ipBox.Text = null;
|
||||
joinButton.Enabled = false;
|
||||
ipBox.UserData = null;
|
||||
ipBox.Text = "";
|
||||
|
||||
new GUITextBlock(new RectTransform(new Vector2(1.0f, 1.0f), serverList.Content.RectTransform),
|
||||
TextManager.Get("RefreshingServerList"), textAlignment: Alignment.Center)
|
||||
@@ -277,8 +550,6 @@ namespace Barotrauma
|
||||
};
|
||||
|
||||
CoroutineManager.StartCoroutine(WaitForRefresh());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private IEnumerable<object> WaitForRefresh()
|
||||
@@ -392,12 +663,15 @@ namespace Barotrauma
|
||||
{
|
||||
UserData = serverInfo
|
||||
};
|
||||
var serverContent = new GUILayoutGroup(new RectTransform(new Vector2(0.98f, 1.0f), serverFrame.RectTransform), isHorizontal: true, childAnchor: Anchor.CenterLeft)
|
||||
new GUILayoutGroup(new RectTransform(new Vector2(0.98f, 1.0f), serverFrame.RectTransform, Anchor.Center), isHorizontal: true, childAnchor: Anchor.CenterLeft)
|
||||
{
|
||||
Stretch = true,
|
||||
RelativeSpacing = 0.02f
|
||||
//RelativeSpacing = 0.02f
|
||||
};
|
||||
UpdateServerInfo(serverInfo);
|
||||
|
||||
SortList(sortedBy, toggle: false);
|
||||
FilterServers();
|
||||
}
|
||||
|
||||
private void UpdateServerInfo(ServerInfo serverInfo)
|
||||
@@ -405,7 +679,7 @@ namespace Barotrauma
|
||||
var serverFrame = serverList.Content.FindChild(serverInfo);
|
||||
if (serverFrame == null) return;
|
||||
|
||||
var serverContent = serverFrame.Children.First();
|
||||
var serverContent = serverFrame.Children.First() as GUILayoutGroup;
|
||||
serverContent.ClearChildren();
|
||||
|
||||
var compatibleBox = new GUITickBox(new RectTransform(new Vector2(columnRelativeWidth[0], 0.9f), serverContent.RectTransform, Anchor.Center), label: "")
|
||||
@@ -425,21 +699,22 @@ namespace Barotrauma
|
||||
UserData = "password"
|
||||
};
|
||||
|
||||
var serverName = new GUITextBlock(new RectTransform(new Vector2(columnRelativeWidth[3], 1.0f), serverContent.RectTransform), serverInfo.ServerName, style: "GUIServerListTextBox");
|
||||
var gameStartedBox = new GUITickBox(new RectTransform(new Vector2(columnRelativeWidth[4], 0.4f), serverContent.RectTransform, Anchor.Center),
|
||||
label: "", style: "GUIServerListRoundStartedTickBox") {
|
||||
var serverName = new GUITextBlock(new RectTransform(new Vector2(columnRelativeWidth[2] * 1.1f, 1.0f), serverContent.RectTransform), serverInfo.ServerName, style: "GUIServerListTextBox");
|
||||
|
||||
new GUITickBox(new RectTransform(new Vector2(columnRelativeWidth[3], 0.9f), serverContent.RectTransform, Anchor.Center), label: "")
|
||||
{
|
||||
ToolTip = TextManager.Get((serverInfo.GameStarted) ? "ServerListRoundStarted" : "ServerListRoundNotStarted"),
|
||||
Selected = serverInfo.GameStarted,
|
||||
Enabled = false
|
||||
};
|
||||
|
||||
var serverPlayers = new GUITextBlock(new RectTransform(new Vector2(columnRelativeWidth[5], 1.0f), serverContent.RectTransform),
|
||||
var serverPlayers = new GUITextBlock(new RectTransform(new Vector2(columnRelativeWidth[4], 1.0f), serverContent.RectTransform),
|
||||
serverInfo.PlayerCount + "/" + serverInfo.MaxPlayers, style: "GUIServerListTextBox", textAlignment: Alignment.Right)
|
||||
{
|
||||
ToolTip = TextManager.Get("ServerListPlayers")
|
||||
};
|
||||
|
||||
var serverPingText = new GUITextBlock(new RectTransform(new Vector2(columnRelativeWidth[6], 1.0f), serverContent.RectTransform), "?",
|
||||
var serverPingText = new GUITextBlock(new RectTransform(new Vector2(columnRelativeWidth[5], 1.0f), serverContent.RectTransform), "?",
|
||||
style: "GUIServerListTextBox", textColor: Color.White * 0.5f, textAlignment: Alignment.Right)
|
||||
{
|
||||
ToolTip = TextManager.Get("ServerListPing")
|
||||
@@ -448,6 +723,7 @@ namespace Barotrauma
|
||||
if (serverInfo.PingChecked)
|
||||
{
|
||||
serverPingText.Text = serverInfo.Ping > -1 ? serverInfo.Ping.ToString() : "?";
|
||||
serverPingText.TextColor = GetPingTextColor(serverInfo.Ping);
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(serverInfo.IP))
|
||||
{
|
||||
@@ -501,6 +777,8 @@ namespace Barotrauma
|
||||
serverPlayers.TextColor *= 0.5f;
|
||||
}
|
||||
|
||||
serverContent.Recalculate();
|
||||
SortList(sortedBy, toggle: false);
|
||||
FilterServers();
|
||||
}
|
||||
|
||||
@@ -594,37 +872,17 @@ namespace Barotrauma
|
||||
masterServerResponded = true;
|
||||
}
|
||||
|
||||
private bool JoinServer(GUIButton button, object obj)
|
||||
private bool JoinServer(string ip, string serverName)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(clientNameBox.Text))
|
||||
{
|
||||
clientNameBox.Flash();
|
||||
joinButton.Enabled = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
GameMain.Config.DefaultPlayerName = clientNameBox.Text;
|
||||
GameMain.Config.SaveNewPlayerConfig();
|
||||
|
||||
string ip = null;
|
||||
string serverName = null;
|
||||
if (ipBox.UserData is ServerInfo serverInfo)
|
||||
{
|
||||
ip = serverInfo.IP + ":" + serverInfo.Port;
|
||||
serverName = serverInfo.ServerName;
|
||||
}
|
||||
else if (!string.IsNullOrWhiteSpace(ipBox.Text))
|
||||
{
|
||||
ip = ipBox.Text;
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(ip))
|
||||
{
|
||||
ipBox.Flash();
|
||||
joinButton.Enabled = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
CoroutineManager.StartCoroutine(ConnectToServer(ip, serverName));
|
||||
|
||||
return true;
|
||||
@@ -671,18 +929,7 @@ namespace Barotrauma
|
||||
{
|
||||
if (serverInfo.Ping != -1)
|
||||
{
|
||||
if (serverInfo.Ping < 50)
|
||||
{
|
||||
serverPingText.TextColor = Color.Green * 1.75f;
|
||||
}
|
||||
else if (serverInfo.Ping < 150)
|
||||
{
|
||||
serverPingText.TextColor = Color.Yellow * 0.85f;
|
||||
}
|
||||
else
|
||||
{
|
||||
serverPingText.TextColor = Color.Red * 0.75f;
|
||||
}
|
||||
serverPingText.TextColor = GetPingTextColor(serverInfo.Ping);
|
||||
}
|
||||
serverPingText.Text = serverInfo.Ping > -1 ? serverInfo.Ping.ToString() : "?";
|
||||
yield return CoroutineStatus.Success;
|
||||
@@ -693,6 +940,12 @@ namespace Barotrauma
|
||||
yield return CoroutineStatus.Success;
|
||||
}
|
||||
|
||||
private Color GetPingTextColor(int ping)
|
||||
{
|
||||
if (ping < 0) { return Color.DarkRed; }
|
||||
return ToolBox.GradientLerp(ping / 200.0f, Color.LightGreen, Color.Yellow * 0.8f, Color.Red * 0.75f);
|
||||
}
|
||||
|
||||
public void PingServer(ServerInfo serverInfo, int timeOut)
|
||||
{
|
||||
if (serverInfo?.IP == null)
|
||||
|
||||
@@ -755,7 +755,7 @@ namespace Barotrauma
|
||||
for (int i = 0; i < item.Tags.Length && i < 5; i++)
|
||||
{
|
||||
if (string.IsNullOrEmpty(item.Tags[i])) { continue; }
|
||||
string tag = TextManager.Get("Workshop.ContentTag." + item.Tags[i], true);
|
||||
string tag = TextManager.Get("Workshop.ContentTag." + item.Tags[i].Replace(" ", ""), true);
|
||||
if (string.IsNullOrEmpty(tag)) { tag = item.Tags[i].CapitaliseFirstInvariant(); }
|
||||
tags.Add(tag);
|
||||
}
|
||||
@@ -1393,9 +1393,20 @@ namespace Barotrauma
|
||||
}
|
||||
else
|
||||
{
|
||||
new GUIMessageBox(
|
||||
TextManager.Get("Error"),
|
||||
TextManager.GetWithVariable("WorkshopItemPublishFailed", "[itemname]", TextManager.EnsureUTF8(item.Title)) + item.Error);
|
||||
string errorMsg = item.ErrorCode.HasValue ?
|
||||
TextManager.Get("WorkshopPublishError." + item.ErrorCode.Value.ToString(), returnNull: true) :
|
||||
null;
|
||||
|
||||
if (errorMsg == null)
|
||||
{
|
||||
new GUIMessageBox(
|
||||
TextManager.Get("Error"),
|
||||
TextManager.GetWithVariable("WorkshopItemPublishFailed", "[itemname]", TextManager.EnsureUTF8(item.Title)) + item.Error);
|
||||
}
|
||||
else
|
||||
{
|
||||
new GUIMessageBox(TextManager.Get("Error"), errorMsg);
|
||||
}
|
||||
}
|
||||
|
||||
createItemFrame.ClearChildren();
|
||||
|
||||
Reference in New Issue
Block a user