Barotrauma/BarotraumaShared/Source/Items/Components/ItemComponent.cs
This commit is contained in:
juanjp600
2017-12-20 19:46:53 -03:00
75 changed files with 2109 additions and 596 deletions
@@ -15,6 +15,8 @@ namespace Barotrauma
{
protected float soundTimer;
protected float soundInterval;
protected float nameTimer;
protected bool nameVisible;
private List<CharacterSound> sounds;
@@ -202,6 +204,34 @@ namespace Barotrauma
if (Lights.LightManager.ViewTarget == this) Lights.LightManager.ViewTarget = null;
}
partial void UpdateProjSpecific(float deltaTime, Camera cam)
{
if (info != null)
{
nameTimer -= deltaTime;
if (nameTimer <= 0.0f)
{
if (controlled == null)
{
nameVisible = true;
}
//if the character is not in the camera view, the name can't be visible and we can avoid the expensive visibility checks
else if (WorldPosition.X < cam.WorldView.X || WorldPosition.X > cam.WorldView.Right ||
WorldPosition.Y > cam.WorldView.Y || WorldPosition.Y < cam.WorldView.Y - cam.WorldView.Height)
{
nameVisible = false;
}
else
{
//Ideally it shouldn't send the character entirely if we can't see them but /shrug, this isn't the most hacker-proof game atm
nameVisible = controlled.CanSeeCharacter(this);
}
nameTimer = Rand.Range(0.5f, 1.0f);
}
}
}
public static void AddAllToGUIUpdateList()
{
for (int i = 0; i < CharacterList.Count; i++)
@@ -240,48 +270,7 @@ namespace Barotrauma
if (aiTarget != null) aiTarget.Draw(spriteBatch);
}
/*if (memPos != null && memPos.Count > 0 && controlled == this)
{
PosInfo serverPos = memPos.Last();
Vector2 remoteVec = ConvertUnits.ToDisplayUnits(serverPos.Position);
if (Submarine != null)
{
remoteVec += Submarine.DrawPosition;
}
remoteVec.Y = -remoteVec.Y;
PosInfo localPos = memLocalPos.Find(m => m.ID == serverPos.ID);
int mpind = memLocalPos.FindIndex(lp => lp.ID == localPos.ID);
PosInfo localPos1 = mpind > 0 ? memLocalPos[mpind - 1] : null;
PosInfo localPos2 = mpind < memLocalPos.Count-1 ? memLocalPos[mpind + 1] : null;
Vector2 localVec = ConvertUnits.ToDisplayUnits(localPos.Position);
Vector2 localVec1 = localPos1 != null ? ConvertUnits.ToDisplayUnits(((PosInfo)localPos1).Position) : Vector2.Zero;
Vector2 localVec2 = localPos2 != null ? ConvertUnits.ToDisplayUnits(((PosInfo)localPos2).Position) : Vector2.Zero;
if (Submarine != null)
{
localVec += Submarine.DrawPosition;
localVec1 += Submarine.DrawPosition;
localVec2 += Submarine.DrawPosition;
}
localVec.Y = -localVec.Y;
localVec1.Y = -localVec1.Y;
localVec2.Y = -localVec2.Y;
//GUI.DrawLine(spriteBatch, remoteVec, localVec, Color.Yellow, 0, 10);
if (localPos1 != null) GUI.DrawLine(spriteBatch, remoteVec, localVec1, Color.Lime, 0, 2);
if (localPos2 != null) GUI.DrawLine(spriteBatch, remoteVec + Vector2.One, localVec2 + Vector2.One, Color.Red, 0, 2);
}
Vector2 mouseDrawPos = CursorWorldPosition;
mouseDrawPos.Y = -mouseDrawPos.Y;
GUI.DrawLine(spriteBatch, mouseDrawPos - new Vector2(0, 5), mouseDrawPos + new Vector2(0, 5), Color.Red, 0, 10);
Vector2 closestItemPos = closestItem != null ? closestItem.DrawPosition : Vector2.Zero;
closestItemPos.Y = -closestItemPos.Y;
GUI.DrawLine(spriteBatch, closestItemPos - new Vector2(0, 5), closestItemPos + new Vector2(0, 5), Color.Lime, 0, 10);*/
if (this == controlled || GUI.DisableHUD) return;
Vector2 pos = DrawPosition;
@@ -291,30 +280,33 @@ namespace Barotrauma
{
GUI.SpeechBubbleIcon.Draw(spriteBatch, pos - Vector2.UnitY * 100.0f,
speechBubbleColor * Math.Min(speechBubbleTimer, 1.0f), 0.0f,
Math.Min((float)speechBubbleTimer, 1.0f));
Math.Min(speechBubbleTimer, 1.0f));
}
if (this == controlled) return;
if (info != null)
if (nameVisible && info != null)
{
string name = Info.DisplayName;
if (controlled == null && name != Info.Name) name += " (Disguised)";
Vector2 namePos = new Vector2(pos.X, pos.Y - 110.0f - (5.0f / cam.Zoom)) - GUI.Font.MeasureString(Info.Name) * 0.5f / cam.Zoom;
Vector2 screenSize = new Vector2(GameMain.GraphicsWidth, GameMain.GraphicsHeight);
Vector2 viewportSize = new Vector2(cam.WorldView.Width, cam.WorldView.Height);
namePos.X -= cam.WorldView.X; namePos.Y += cam.WorldView.Y;
namePos *= screenSize / viewportSize;
namePos.X = (float)Math.Floor(namePos.X); namePos.Y = (float)Math.Floor(namePos.Y);
namePos *= viewportSize / screenSize;
namePos.X += cam.WorldView.X; namePos.Y -= cam.WorldView.Y;
Vector2 screenSize = new Vector2(GameMain.GraphicsWidth, GameMain.GraphicsHeight);
Vector2 viewportSize = new Vector2(cam.WorldView.Width, cam.WorldView.Height);
namePos.X -= cam.WorldView.X; namePos.Y += cam.WorldView.Y;
namePos *= screenSize / viewportSize;
namePos.X = (float)Math.Floor(namePos.X); namePos.Y = (float)Math.Floor(namePos.Y);
namePos *= viewportSize / screenSize;
namePos.X += cam.WorldView.X; namePos.Y -= cam.WorldView.Y;
Color nameColor = Color.White;
if (Character.Controlled != null && TeamID != Character.Controlled.TeamID)
if (Controlled != null && TeamID != Controlled.TeamID)
{
nameColor = Color.Red;
}
GUI.Font.DrawString(spriteBatch, Info.Name, namePos + new Vector2(1.0f / cam.Zoom, 1.0f / cam.Zoom), Color.Black, 0.0f, Vector2.Zero, 1.0f / cam.Zoom, SpriteEffects.None, 0.001f);
GUI.Font.DrawString(spriteBatch, Info.Name, namePos, nameColor, 0.0f, Vector2.Zero, 1.0f / cam.Zoom, SpriteEffects.None, 0.0f);
GUI.Font.DrawString(spriteBatch, name, namePos + new Vector2(1.0f / cam.Zoom, 1.0f / cam.Zoom), Color.Black, 0.0f, Vector2.Zero, 1.0f / cam.Zoom, SpriteEffects.None, 0.001f);
GUI.Font.DrawString(spriteBatch, name, namePos, nameColor, 0.0f, Vector2.Zero, 1.0f / cam.Zoom, SpriteEffects.None, 0.0f);
if (GameMain.DebugDraw)
{
@@ -13,6 +13,8 @@ namespace Barotrauma
private static Sprite noiseOverlay, damageOverlay;
private static GUIButton cprButton;
private static GUIButton grabHoldButton;
private static GUIButton suicideButton;
@@ -41,6 +43,8 @@ namespace Barotrauma
if (cprButton != null && cprButton.Visible) cprButton.AddToGUIUpdateList();
if (grabHoldButton != null && cprButton.Visible) grabHoldButton.AddToGUIUpdateList();
if (suicideButton != null && suicideButton.Visible) suicideButton.AddToGUIUpdateList();
if (!character.IsUnconscious && character.Stun <= 0.0f)
@@ -89,6 +93,8 @@ namespace Barotrauma
if (cprButton != null && cprButton.Visible) cprButton.Update(deltaTime);
if (grabHoldButton != null && grabHoldButton.Visible) grabHoldButton.Update(deltaTime);
if (suicideButton != null && suicideButton.Visible) suicideButton.Update(deltaTime);
if (damageOverlayTimer > 0.0f) damageOverlayTimer -= deltaTime;
@@ -195,9 +201,37 @@ namespace Barotrauma
};
}
if (grabHoldButton == null)
{
grabHoldButton = new GUIButton(
new Rectangle(character.SelectedCharacter.Inventory.SlotPositions[0].ToPoint() + new Point(320, -60), new Point(130, 20)),
"Grabbing: " + (character.AnimController.GrabLimb == LimbType.Torso ? "Torso" : "Hands"), "");
grabHoldButton.OnClicked = (button, userData) =>
{
if (Character.Controlled == null || Character.Controlled.SelectedCharacter == null) return false;
Character.Controlled.AnimController.GrabLimb = Character.Controlled.AnimController.GrabLimb == LimbType.None ? LimbType.Torso : LimbType.None;
foreach (Limb limb in Character.Controlled.SelectedCharacter.AnimController.Limbs)
{
limb.pullJoint.Enabled = false;
}
if (GameMain.Client != null)
{
GameMain.Client.CreateEntityEvent(Character.Controlled, new object[] { NetEntityEvent.Type.Control });
}
grabHoldButton.Text = "Grabbing: " + (Character.Controlled.AnimController.GrabLimb == LimbType.Torso ? "Torso" : "Hands");
return true;
};
}
//cprButton.Visible = character.GetSkillLevel("Medical") > 20.0f;
if (cprButton.Visible) cprButton.Draw(spriteBatch);
if (grabHoldButton.Visible) grabHoldButton.Draw(spriteBatch);
}
if (character.FocusedCharacter != null && character.FocusedCharacter.CanBeSelected)
@@ -208,7 +242,7 @@ namespace Barotrauma
string focusName = character.FocusedCharacter.SpeciesName;
if (character.FocusedCharacter.Info != null)
{
focusName = character.FocusedCharacter.Info.Name;
focusName = character.FocusedCharacter.Info.DisplayName;
}
Vector2 textPos = startPos;
textPos -= new Vector2(GUI.Font.MeasureString(focusName).X / 2, 20);
@@ -17,15 +17,19 @@ namespace Barotrauma
switch ((NetEntityEvent.Type)extraData[0])
{
case NetEntityEvent.Type.InventoryState:
msg.WriteRangedInteger(0, 2, 0);
msg.WriteRangedInteger(0, 3, 0);
inventory.ClientWrite(msg, extraData);
break;
case NetEntityEvent.Type.Repair:
msg.WriteRangedInteger(0, 2, 1);
msg.WriteRangedInteger(0, 3, 1);
msg.Write(AnimController.Anim == AnimController.Animation.CPR);
break;
case NetEntityEvent.Type.Status:
msg.WriteRangedInteger(0, 2, 2);
msg.WriteRangedInteger(0, 3, 2);
break;
case NetEntityEvent.Type.Control:
msg.WriteRangedInteger(0, 3, 3);
msg.Write((UInt16)AnimController.GrabLimb);
break;
}
}
@@ -91,6 +95,7 @@ namespace Barotrauma
bool crouching = msg.ReadBoolean();
keys[(int)InputType.Crouch].Held = crouching;
keys[(int)InputType.Crouch].SetState(false, crouching);
AnimController.GrabLimb = (LimbType)msg.ReadUInt16();
}
bool hasAttackLimb = msg.ReadBoolean();
@@ -367,6 +372,9 @@ namespace Barotrauma
SetStun(0.0f, true, true);
}
bool ragdolled = msg.ReadBoolean();
IsRagdolled = ragdolled;
bool huskInfected = msg.ReadBoolean();
if (huskInfected)
{
@@ -15,6 +15,8 @@ namespace Barotrauma
private static Queue<ColoredText> queuedMessages = new Queue<ColoredText>();
private static GUITextBlock activeQuestionText;
public static bool IsOpen
{
get
@@ -69,6 +71,13 @@ namespace Barotrauma
}
}
if (activeQuestionText != null &&
(listBox.children.Count == 0 || listBox.children[listBox.children.Count - 1] != activeQuestionText))
{
listBox.children.Remove(activeQuestionText);
listBox.children.Add(activeQuestionText);
}
if (PlayerInput.KeyHit(Keys.F3))
{
isOpen = !isOpen;
@@ -105,7 +114,7 @@ namespace Barotrauma
if (PlayerInput.KeyHit(Keys.Enter))
{
ExecuteCommand(textBox.Text, game);
ExecuteCommand(textBox.Text);
textBox.Text = "";
}
}
@@ -134,7 +143,7 @@ namespace Barotrauma
case "entitylist":
return true;
default:
return false;
return client.HasConsoleCommandPermission(command);
}
}
@@ -177,13 +186,6 @@ namespace Barotrauma
}
selectedIndex = Messages.Count;
if (activeQuestionText != null)
{
//make sure the active question stays at the bottom of the list
listBox.children.Remove(activeQuestionText);
listBox.children.Add(activeQuestionText);
}
}
private static void InitProjectSpecific()
@@ -549,6 +549,9 @@ namespace Barotrauma
}
}
/// <summary>
/// Displays a message at the center of the screen, automatically preventing overlapping with other centered messages
/// </summary>
public static void AddMessage(string message, Color color, float lifeTime = 3.0f, bool playSound = true)
{
if (messages.Count > 0 && messages[messages.Count - 1].Text == message)
@@ -558,12 +561,15 @@ namespace Barotrauma
}
Vector2 pos = new Vector2(GameMain.GraphicsWidth / 2.0f, GameMain.GraphicsHeight * 0.7f);
pos.Y += messages.FindAll(m => m.Centered).Count * 30;
pos.Y += messages.FindAll(m => m.AutoCenter).Count * 30;
messages.Add(new GUIMessage(message, color, pos, lifeTime, Alignment.Center, true));
if (playSound) PlayUISound(GUISoundType.Message);
}
/// <summary>
/// Display and automatically fade out a piece of text at an arbitrary position on the screen
/// </summary>
public static void AddMessage(string message, Vector2 position, Alignment alignment, Color color, float lifeTime = 3.0f, bool playSound = true)
{
if (messages.Count > 0 && messages[messages.Count - 1].Text == message)
@@ -602,7 +608,7 @@ namespace Barotrauma
alpha -= 1.0f - msg.LifeTime;
}
if (msg.Centered)
if (msg.AutoCenter)
{
msg.Pos = MathUtils.SmoothStep(msg.Pos, currPos, deltaTime * 20.0f);
currPos.Y += 30.0f;
@@ -115,10 +115,11 @@ namespace Barotrauma
listBox.AddChild(child);
}
public void AddItem(string text, object userData = null)
public void AddItem(string text, object userData = null, string toolTip = "")
{
GUITextBlock textBlock = new GUITextBlock(new Rectangle(0,0,0,20), text, "ListBoxElement", Alignment.TopLeft, Alignment.CenterLeft, listBox);
textBlock.UserData = userData;
textBlock.ToolTip = toolTip;
}
public override void ClearChildren()
@@ -171,12 +171,12 @@ namespace Barotrauma
{
for (int i = 0; i < children.Count; i++)
{
if (!children[i].UserData.Equals(userData)) continue;
Select(i, force);
//if (OnSelected != null) OnSelected(Selected, Selected.UserData);
if (!SelectMultiple) return;
if ((children[i].UserData != null && children[i].UserData.Equals(userData)) ||
(children[i].UserData == null && userData == null))
{
Select(i, force);
if (!SelectMultiple) return;
}
}
}
@@ -46,14 +46,21 @@ namespace Barotrauma
private set;
}
public bool Centered;
public GUIMessage(string text, Color color, Vector2 position, float lifeTime, Alignment textAlignment, bool centered)
/// <summary>
/// Autocentered messages are automatically placed at the center of the screen and prevented from overlapping with each other
/// </summary>
public bool AutoCenter;
public GUIMessage(string text, Color color, Vector2 position, float lifeTime, Alignment textAlignment, bool autoCenter)
{
coloredText = new ColoredText(text, color, false);
pos = position;
this.lifeTime = lifeTime;
this.Alignment = textAlignment;
this.AutoCenter = autoCenter;
size = GUI.Font.MeasureString(text);
if (textAlignment.HasFlag(Alignment.Left))
Origin.X += size.X * 0.5f;
@@ -67,14 +74,10 @@ namespace Barotrauma
if (textAlignment.HasFlag(Alignment.Bottom))
Origin.Y -= size.Y * 0.5f;
if (centered)
if (autoCenter)
{
Origin = new Vector2((int)(0.5f * size.X), (int)(0.5f * size.Y));
}
else
{
size = GUI.Font.MeasureString(text);
}
}
}
}
@@ -7,12 +7,8 @@ namespace Barotrauma
{
public static List<GUIComponent> MessageBoxes = new List<GUIComponent>();
const int DefaultWidth=400, DefaultHeight=250;
//public delegate bool OnClickedHandler(GUIButton button, object obj);
//public OnClickedHandler OnClicked;
//GUIFrame frame;
public const int DefaultWidth = 400, DefaultHeight = 250;
public GUIButton[] Buttons;
public static GUIComponent VisibleBox
@@ -50,8 +50,8 @@ namespace Barotrauma
{
base.Rect = value;
box.Rect = new Rectangle(value.X,value.Y,box.Rect.Width,box.Rect.Height);
text.Rect = new Rectangle(box.Rect.Right, box.Rect.Y + 2, 20, box.Rect.Height);
if (box != null) box.Rect = new Rectangle(value.X,value.Y,box.Rect.Width,box.Rect.Height);
if (text != null) text.Rect = new Rectangle(box.Rect.Right, box.Rect.Y + 2, 20, box.Rect.Height);
}
}
@@ -39,7 +39,7 @@ namespace Barotrauma
case 3:
case 4:
SlotPositions[i] = new Vector2(
spacing * 2 + rectWidth + (spacing + rectWidth) * (i - 2),
spacing * 2 + rectWidth + (spacing + rectWidth) * (i - 1),
GameMain.GraphicsHeight - (spacing + rectHeight) * 3);
useOnSelfButton[i - 3] = new GUIButton(
@@ -52,16 +52,24 @@ namespace Barotrauma
break;
//face
case 5:
SlotPositions[i] = new Vector2(
spacing * 2 + rectWidth + (spacing + rectWidth) * (i - 5),
GameMain.GraphicsHeight - (spacing + rectHeight) * 3);
break;
//id card
case 6:
SlotPositions[i] = new Vector2(
spacing * 2 + rectWidth + (spacing + rectWidth) * (i - 5),
GameMain.GraphicsHeight - (spacing + rectHeight) * 3);
break;
default:
SlotPositions[i] = new Vector2(
spacing * 2 + rectWidth + (spacing + rectWidth) * ((i - 6) % 5),
GameMain.GraphicsHeight - (spacing + rectHeight) * ((i > 10) ? 2 : 1));
spacing * 2 + rectWidth + (spacing + rectWidth) * ((i - 7) % 5),
GameMain.GraphicsHeight - (spacing + rectHeight) * ((i > 11) ? 2 : 1));
break;
}
}
@@ -247,6 +255,13 @@ namespace Barotrauma
new Vector2(15.0f, 16.0f), Vector2.One,
SpriteEffects.None, 0.1f);
}
else if (i == 6)
{
spriteBatch.Draw(icons, new Vector2(slotRect.Center.X, slotRect.Center.Y),
new Rectangle(62, 36, 22, 18), Color.White * 0.7f, 0.0f,
new Vector2(11.0f, 9.0f), Vector2.One,
SpriteEffects.None, 0.1f);
}
}
base.Draw(spriteBatch);
@@ -7,7 +7,7 @@ using System;
namespace Barotrauma.Items.Components
{
partial class Door : ItemComponent, IDrawableComponent, IServerSerializable
partial class Door : Pickable, IDrawableComponent, IServerSerializable
{
private ConvexHull convexHull;
private ConvexHull convexHull2;
@@ -20,7 +20,7 @@ namespace Barotrauma.Items.Components
if (GameMain.Server != null)
{
item.CreateServerEvent(this);
GameServer.Log(Character.Controlled + (IsActive ? " turned on " : " turned off ") + item.Name, ServerLog.MessageType.ItemInteraction);
GameServer.Log(Character.Controlled.LogName + (IsActive ? " turned on " : " turned off ") + item.Name, ServerLog.MessageType.ItemInteraction);
}
else if (GameMain.Client != null)
{
@@ -39,7 +39,7 @@ namespace Barotrauma.Items.Components
if (GameMain.Server != null)
{
item.CreateServerEvent(this);
GameServer.Log(Character.Controlled + " set the pumping speed of " + item.Name + " to " + (int)(flowPercentage) + " %", ServerLog.MessageType.ItemInteraction);
GameServer.Log(Character.Controlled.LogName + " set the pumping speed of " + item.Name + " to " + (int)(flowPercentage) + " %", ServerLog.MessageType.ItemInteraction);
}
else if (GameMain.Client != null)
{
@@ -58,7 +58,7 @@ namespace Barotrauma.Items.Components
if (GameMain.Server != null)
{
item.CreateServerEvent(this);
GameServer.Log(Character.Controlled + " set the pumping speed of " + item.Name + " to " + (int)(flowPercentage) + " %", ServerLog.MessageType.ItemInteraction);
GameServer.Log(Character.Controlled.LogName + " set the pumping speed of " + item.Name + " to " + (int)(flowPercentage) + " %", ServerLog.MessageType.ItemInteraction);
}
else if (GameMain.Client != null)
{
@@ -19,7 +19,7 @@ namespace Barotrauma.Items.Components
if (GameMain.Server != null)
{
item.CreateServerEvent(this);
GameServer.Log(Character.Controlled + " set the recharge speed of " + item.Name + " to " + (int)((rechargeSpeed / maxRechargeSpeed) * 100.0f) + " %", ServerLog.MessageType.ItemInteraction);
GameServer.Log(Character.Controlled.LogName + " set the recharge speed of " + item.Name + " to " + (int)((rechargeSpeed / maxRechargeSpeed) * 100.0f) + " %", ServerLog.MessageType.ItemInteraction);
}
else if (GameMain.Client != null)
{
@@ -38,7 +38,7 @@ namespace Barotrauma.Items.Components
if (GameMain.Server != null)
{
item.CreateServerEvent(this);
GameServer.Log(Character.Controlled + " set the recharge speed of " + item.Name + " to " + (int)((rechargeSpeed / maxRechargeSpeed) * 100.0f) + " %", ServerLog.MessageType.ItemInteraction);
GameServer.Log(Character.Controlled.LogName + " set the recharge speed of " + item.Name + " to " + (int)((rechargeSpeed / maxRechargeSpeed) * 100.0f) + " %", ServerLog.MessageType.ItemInteraction);
}
else if (GameMain.Client != null)
{
@@ -174,12 +174,12 @@ namespace Barotrauma.Items.Components
var otherConnection = draggingConnected.OtherConnection(this);
if (otherConnection == null)
{
GameServer.Log(Character.Controlled + " connected a wire to " +
GameServer.Log(Character.Controlled.LogName + " connected a wire to " +
Item.Name + " (" + Name + ")", ServerLog.MessageType.ItemInteraction);
}
else
{
GameServer.Log(Character.Controlled + " connected a wire from " +
GameServer.Log(Character.Controlled.LogName + " connected a wire from " +
Item.Name + " (" + Name + ") to " + otherConnection.item.Name + " (" + otherConnection.Name + ")", ServerLog.MessageType.ItemInteraction);
}
@@ -296,9 +296,26 @@ namespace Barotrauma
}
else
{
toolTip = string.IsNullOrEmpty(Items[i].Description) ?
string description = Items[i].Description;
if (Items[i].Prefab.NameMatches("ID Card"))
{
string[] readTags = Items[i].Tags.Split(',');
string idName = null;
string idJob = null;
foreach (string tag in readTags)
{
string[] s = tag.Split(':');
if (s[0] == "name")
idName = s[1];
if (s[0] == "job")
idJob = s[1];
}
if (idName != null)
description = "This belongs to " + idName + (idJob != null ? ", the " + idJob + ".\n" : ".\n") + description;
}
toolTip = string.IsNullOrEmpty(description) ?
Items[i].Name :
Items[i].Name + '\n' + Items[i].Description;
Items[i].Name + '\n' + description;
}
DrawToolTip(spriteBatch, toolTip, slots[i].Rect);
@@ -106,6 +106,16 @@ namespace Barotrauma
return true;
}
private bool EnterIDCardDesc(GUITextBox textBox, string text)
{
IdCardDesc = text;
textBox.Text = text;
textBox.Color = Color.Green;
textBox.Deselect();
return true;
}
private bool EnterIDCardTags(GUITextBox textBox, string text)
{
IdCardTags = text.Split(',');
@@ -143,7 +153,7 @@ namespace Barotrauma
private GUIComponent CreateEditingHUD(bool inGame = false)
{
int width = 500;
int height = spawnType == SpawnType.Path ? 100 : 140;
int height = spawnType == SpawnType.Path ? 100 : 200;
int x = GameMain.GraphicsWidth / 2 - width / 2, y = 10;
editingHUD = new GUIFrame(new Rectangle(x, y, width, height), Color.Black * 0.5f);
@@ -172,8 +182,19 @@ namespace Barotrauma
y = 40 + 20;
new GUITextBlock(new Rectangle(0, y, 100, 20), "ID Card desc:", Color.Transparent, Color.White, Alignment.TopLeft, null, editingHUD);
GUITextBox propertyBox = new GUITextBox(new Rectangle(100, y, 350, 20), "", editingHUD);
propertyBox.MaxTextLength = 150;
propertyBox.Text = idCardDesc;
propertyBox.OnEnterPressed = EnterIDCardDesc;
propertyBox.OnTextChanged = TextBoxChanged;
propertyBox.ToolTip = "Characters spawning at this spawnpoint will have the specified description added to their ID card. This can be used to describe additional access levels their card has on the sub.";
y = y + 30;
new GUITextBlock(new Rectangle(0, y, 100, 20), "ID Card tags:", Color.Transparent, Color.White, Alignment.TopLeft, null, editingHUD);
GUITextBox propertyBox = new GUITextBox(new Rectangle(100, y, 200, 20), "", editingHUD);
propertyBox = new GUITextBox(new Rectangle(100, y, 350, 20), "", editingHUD);
propertyBox.MaxTextLength = 60;
propertyBox.Text = string.Join(", ", idCardTags);
propertyBox.OnEnterPressed = EnterIDCardTags;
propertyBox.OnTextChanged = TextBoxChanged;
@@ -182,7 +203,8 @@ namespace Barotrauma
y = y + 30;
new GUITextBlock(new Rectangle(0, y, 100, 20), "Assigned job:", Color.Transparent, Color.White, Alignment.TopLeft, null, editingHUD);
propertyBox = new GUITextBox(new Rectangle(100, y, 200, 20), "", editingHUD);
propertyBox = new GUITextBox(new Rectangle(100, y, 350, 20), "", editingHUD);
propertyBox.MaxTextLength = 60;
propertyBox.Text = (assignedJob == null) ? "None" : assignedJob.Name;
propertyBox.OnEnterPressed = EnterAssignedJob;
propertyBox.OnTextChanged = TextBoxChanged;
@@ -1,9 +1,5 @@
using Lidgren.Network;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Barotrauma.Networking
{
@@ -40,6 +36,10 @@ namespace Barotrauma.Networking
{
new GUIMessageBox("", txt);
}
else if (type == ChatMessageType.Console)
{
DebugConsole.NewMessage(txt, MessageColor[(int)ChatMessageType.Console]);
}
else
{
GameMain.Client.AddChatMessage(txt, type, senderName, senderCharacter);
@@ -19,6 +19,7 @@ namespace Barotrauma.Networking
private GUITickBox endVoteTickBox;
private ClientPermissions permissions = ClientPermissions.None;
private List<string> permittedConsoleCommands = new List<string>();
private bool connected;
@@ -598,16 +599,28 @@ namespace Barotrauma.Networking
private void ReadPermissions(NetIncomingMessage inc)
{
List<string> permittedConsoleCommands = new List<string>();
ClientPermissions newPermissions = (ClientPermissions)inc.ReadByte();
if (newPermissions != permissions)
if (newPermissions.HasFlag(ClientPermissions.ConsoleCommands))
{
SetPermissions(newPermissions);
}
UInt16 consoleCommandCount = inc.ReadUInt16();
for (int i = 0; i < consoleCommandCount; i++)
{
permittedConsoleCommands.Add(inc.ReadString());
}
}
SetPermissions(newPermissions, permittedConsoleCommands);
}
private void SetPermissions(ClientPermissions newPermissions)
private void SetPermissions(ClientPermissions newPermissions, List<string> permittedConsoleCommands)
{
if (newPermissions == permissions) return;
if (!(this.permittedConsoleCommands.Any(c => !permittedConsoleCommands.Contains(c)) ||
permittedConsoleCommands.Any(c => !this.permittedConsoleCommands.Contains(c))))
{
if (newPermissions == permissions) return;
}
GUIMessageBox.MessageBoxes.RemoveAll(mb => mb.UserData as string == "permissions");
string msg = "";
@@ -626,8 +639,22 @@ namespace Barotrauma.Networking
msg += " - " + attributes[0].Description + "\n";
}
}
permissions = newPermissions;
new GUIMessageBox("Permissions changed", msg).UserData = "permissions";
this.permittedConsoleCommands = new List<string>(permittedConsoleCommands);
GUIMessageBox msgBox = new GUIMessageBox("Permissions changed", msg, GUIMessageBox.DefaultWidth, 0);
msgBox.UserData = "permissions";
if (newPermissions.HasFlag(ClientPermissions.ConsoleCommands))
{
int listBoxWidth = (int)(msgBox.InnerFrame.Rect.Width - msgBox.InnerFrame.Padding.X - msgBox.InnerFrame.Padding.Z) / 2 - 30;
new GUITextBlock(new Rectangle(0, 0, listBoxWidth, 15), "Permitted console commands:", "", Alignment.TopRight, Alignment.TopLeft, msgBox.InnerFrame, true, GUI.SmallFont);
var commandList = new GUIListBox(new Rectangle(0, 20, listBoxWidth, 0), "", Alignment.BottomRight, msgBox.InnerFrame);
foreach (string permittedCommand in permittedConsoleCommands)
{
new GUITextBlock(new Rectangle(0, 0, 0, 15), permittedCommand, "", commandList, GUI.SmallFont).CanBeFocused = false;
}
}
GameMain.NetLobbyScreen.SubList.Enabled = Voting.AllowSubVoting || HasPermission(ClientPermissions.SelectSub);
GameMain.NetLobbyScreen.ModeList.Enabled = Voting.AllowModeVoting || HasPermission(ClientPermissions.SelectMode);
@@ -805,7 +832,7 @@ namespace Barotrauma.Networking
gameStarted = inc.ReadBoolean();
bool allowSpectating = inc.ReadBoolean();
SetPermissions((ClientPermissions)inc.ReadByte());
ReadPermissions(inc);
if (gameStarted)
{
@@ -1169,6 +1196,14 @@ namespace Barotrauma.Networking
return permissions.HasFlag(permission);
}
public bool HasConsoleCommandPermission(string command)
{
if (!permissions.HasFlag(ClientPermissions.ConsoleCommands)) return false;
command = command.ToLowerInvariant();
return permittedConsoleCommands.Any(c => c.ToLowerInvariant() == command);
}
public override void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch)
{
base.Draw(spriteBatch);
@@ -1359,6 +1394,25 @@ namespace Barotrauma.Networking
client.SendMessage(msg, NetDeliveryMethod.ReliableUnordered);
}
public void SendConsoleCommand(string command)
{
if (string.IsNullOrWhiteSpace(command))
{
DebugConsole.ThrowError("Cannot send an empty console command to the server!\n" + Environment.StackTrace);
return;
}
NetOutgoingMessage msg = client.CreateMessage();
msg.Write((byte)ClientPacketHeader.SERVER_COMMAND);
msg.Write((byte)ClientPermissions.ConsoleCommands);
msg.Write(command);
Vector2 cursorWorldPos = GameMain.GameScreen.Cam.ScreenToWorld(PlayerInput.MousePosition);
msg.Write(cursorWorldPos.X);
msg.Write(cursorWorldPos.Y);
client.SendMessage(msg, NetDeliveryMethod.ReliableUnordered);
}
/// <summary>
/// Tell the server to select a submarine (permission required)
/// </summary>
@@ -320,7 +320,7 @@ namespace Barotrauma.Networking
return true;
};
y += 40;
y += 20;
var voteKickBox = new GUITickBox(new Rectangle(0, y, 20, 20), "Allow vote kicking", Alignment.Left, settingsTabs[1]);
voteKickBox.Selected = Voting.AllowVoteKick;
@@ -357,7 +357,7 @@ namespace Barotrauma.Networking
return true;
};
y += 40;
y += 20;
var randomizeLevelBox = new GUITickBox(new Rectangle(0, y, 20, 20), "Randomize level seed between rounds", Alignment.Left, settingsTabs[1]);
randomizeLevelBox.Selected = RandomizeSeed;
@@ -367,7 +367,7 @@ namespace Barotrauma.Networking
return true;
};
y += 40;
y += 20;
var saveLogsBox = new GUITickBox(new Rectangle(0, y, 20, 20), "Save server logs", Alignment.Left, settingsTabs[1]);
saveLogsBox.Selected = SaveServerLogs;
@@ -378,6 +378,83 @@ namespace Barotrauma.Networking
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) =>
{
AllowRagdollButton = GUITickBox.Selected;
return true;
};
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
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
}
return true;
};
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) + " %";
}
else
{
TraitorRatio = MathUtils.Round(barScroll * (maxPlayers-1), 1f) + 1;
traitorText.Text = "Traitor count: " + 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) =>
{
KarmaEnabled = GUITickBox.Selected;
return true;
};
//--------------------------------------------------------------------------------
// banlist
@@ -882,24 +882,54 @@ namespace Barotrauma
playerFrame = new GUIFrame(new Rectangle(0, 0, 0, 0), Color.Black * 0.6f);
var playerFrameInner = new GUIFrame(new Rectangle(0, 0, 300, 280), null, Alignment.Center, "", playerFrame);
var playerFrameInner = new GUIFrame(GameMain.Server != null ? new Rectangle(0, 0, 450, 370) : new Rectangle(0, 0, 450, 150), null, Alignment.Center, "", playerFrame);
playerFrameInner.Padding = new Vector4(20.0f, 20.0f, 20.0f, 20.0f);
new GUITextBlock(new Rectangle(0, 0, 200, 20), component.UserData.ToString(),
new GUITextBlock(new Rectangle(0, 0, 200, 20), obj.ToString(),
"", Alignment.TopLeft, Alignment.TopLeft,
playerFrameInner, false, GUI.LargeFont);
if (GameMain.Server != null)
{
var selectedClient = GameMain.Server.ConnectedClients.Find(c => c.Name == component.UserData.ToString());
var selectedClient = GameMain.Server.ConnectedClients.Find(c => c.Name == obj.ToString());
playerFrame.UserData = selectedClient;
new GUITextBlock(new Rectangle(0, 25, 150, 15), selectedClient.Connection.RemoteEndPoint.Address.ToString(), "", playerFrameInner);
var permissionsBox = new GUIFrame(new Rectangle(0, 60, 0, 90), null, playerFrameInner);
new GUITextBlock(new Rectangle(0, 45, 0, 15), "Rank", "", playerFrameInner);
var rankDropDown = new GUIDropDown(new Rectangle(0, 70, 150, 20), "Rank", "", playerFrameInner);
rankDropDown.UserData = selectedClient;
foreach (PermissionPreset permissionPreset in PermissionPreset.List)
{
rankDropDown.AddItem(permissionPreset.Name, permissionPreset, permissionPreset.Description);
}
rankDropDown.AddItem("Custom", null);
PermissionPreset currentPreset = PermissionPreset.List.Find(p =>
p.Permissions == selectedClient.Permissions &&
p.PermittedCommands.Count == selectedClient.PermittedConsoleCommands.Count && !p.PermittedCommands.Except(selectedClient.PermittedConsoleCommands).Any());
rankDropDown.SelectItem(currentPreset);
rankDropDown.OnSelected += (c, userdata) =>
{
PermissionPreset selectedPreset = (PermissionPreset)userdata;
if (selectedPreset != null)
{
var client = playerFrame.UserData as Client;
client.SetPermissions(selectedPreset.Permissions, selectedPreset.PermittedCommands);
GameMain.Server.UpdateClientPermissions(client);
playerFrame = null;
SelectPlayer(null, client.Name);
}
return true;
};
var permissionsBox = new GUIFrame(new Rectangle(0, 125, (int)(playerFrameInner.Rect.Width * 0.5f), 160), null, playerFrameInner);
permissionsBox.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f);
permissionsBox.UserData = selectedClient;
new GUITextBlock(new Rectangle(0, 0, 0, 15), "Permissions:", "", permissionsBox);
new GUITextBlock(new Rectangle(0, 100, permissionsBox.Rect.Width, 15), "Permissions:", "", playerFrameInner);
int x = 0, y = 0;
foreach (ClientPermissions permission in Enum.GetValues(typeof(ClientPermissions)))
{
@@ -910,13 +940,16 @@ namespace Barotrauma
string permissionStr = attributes.Length > 0 ? attributes[0].Description : permission.ToString();
var permissionTick = new GUITickBox(new Rectangle(x, y + 25, 15, 15), permissionStr, Alignment.TopLeft, GUI.SmallFont, permissionsBox);
var permissionTick = new GUITickBox(new Rectangle(x, y, 15, 15), permissionStr, Alignment.TopLeft, GUI.SmallFont, permissionsBox);
permissionTick.UserData = permission;
permissionTick.Selected = selectedClient.HasPermission(permission);
permissionTick.OnSelected = (tickBox) =>
{
var client = tickBox.Parent.UserData as Client;
//reset rank to custom
rankDropDown.SelectItem(null);
var client = playerFrame.UserData as Client;
if (client == null) return false;
var thisPermission = (ClientPermissions)tickBox.UserData;
@@ -931,19 +964,50 @@ namespace Barotrauma
return true;
};
y += 20;
if (y >= permissionsBox.Rect.Height - 40)
if (y >= permissionsBox.Rect.Height - 15)
{
y = 0;
x += 100;
x += 120;
}
}
new GUITextBlock(new Rectangle(0, 100, (int)(playerFrameInner.Rect.Width * 0.5f), 15), "Permitted console commands:", "", Alignment.TopRight, Alignment.TopLeft, playerFrameInner, true);
var commandList = new GUIListBox(new Rectangle(0, 125, (int)(playerFrameInner.Rect.Width * 0.5f), 160), "", Alignment.TopRight, playerFrameInner);
commandList.UserData = selectedClient;
foreach (DebugConsole.Command command in DebugConsole.Commands)
{
var commandTickBox = new GUITickBox(new Rectangle(0, 0, 15, 15), command.names[0], Alignment.TopLeft, GUI.SmallFont, commandList);
commandTickBox.Selected = selectedClient.PermittedConsoleCommands.Contains(command);
commandTickBox.ToolTip = command.help;
commandTickBox.UserData = command;
commandTickBox.OnSelected += (GUITickBox tickBox) =>
{
//reset rank to custom
rankDropDown.SelectItem(null);
Client client = playerFrame.UserData as Client;
DebugConsole.Command selectedCommand = tickBox.UserData as DebugConsole.Command;
if (client == null) return false;
if (!tickBox.Selected)
{
client.PermittedConsoleCommands.Remove(selectedCommand);
}
else if (!client.PermittedConsoleCommands.Contains(selectedCommand))
{
client.PermittedConsoleCommands.Add(selectedCommand);
}
GameMain.Server.UpdateClientPermissions(client);
return true;
};
}
}
if (GameMain.Server != null || GameMain.Client.HasPermission(ClientPermissions.Kick))
{
var kickButton = new GUIButton(new Rectangle(0, -50, 100, 20), "Kick", Alignment.BottomLeft, "", playerFrameInner);
var kickButton = new GUIButton(new Rectangle(0, 0, 80, 20), "Kick", Alignment.BottomLeft, "", playerFrameInner);
kickButton.UserData = obj;
kickButton.OnClicked += KickPlayer;
kickButton.OnClicked += ClosePlayerFrame;
@@ -951,12 +1015,12 @@ namespace Barotrauma
if (GameMain.Server != null || GameMain.Client.HasPermission(ClientPermissions.Ban))
{
var banButton = new GUIButton(new Rectangle(0, 0, 100, 20), "Ban", Alignment.BottomLeft, "", playerFrameInner);
var banButton = new GUIButton(new Rectangle(90, 0, 80, 20), "Ban", Alignment.BottomLeft, "", playerFrameInner);
banButton.UserData = obj;
banButton.OnClicked += BanPlayer;
banButton.OnClicked += ClosePlayerFrame;
var rangebanButton = new GUIButton(new Rectangle(0, -25, 100, 20), "Ban range", Alignment.BottomLeft, "", playerFrameInner);
var rangebanButton = new GUIButton(new Rectangle(180, 0, 80, 20), "Ban range", Alignment.BottomLeft, "", playerFrameInner);
rangebanButton.UserData = obj;
rangebanButton.OnClicked += BanPlayerRange;
rangebanButton.OnClicked += ClosePlayerFrame;
@@ -453,10 +453,11 @@ namespace Barotrauma
{
damage = MathHelper.Clamp(damage+Rand.Range(-10.0f, 10.0f), 0.0f, 100.0f);
var sounds = damageSounds.FindAll(s =>
damage >= s.damageRange.X &&
damage <= s.damageRange.Y &&
s.damageRange == null ||
(damage >= s.damageRange.X &&
damage <= s.damageRange.Y) &&
s.damageType == damageType &&
(string.IsNullOrEmpty(s.requiredTag) || (tags != null && tags.Contains(s.requiredTag))));
(tags == null ? string.IsNullOrEmpty(s.requiredTag) : tags.Contains(s.requiredTag)));
if (!sounds.Any()) return;