Reducing usage of #if CLIENT / #elif SERVER
The server will implement some classes it probably shouldn't need because certain items or game states depend on them.
@@ -12,7 +12,6 @@ using Microsoft.Xna.Framework.Input;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
#if CLIENT
|
||||
class GameMain : Game
|
||||
{
|
||||
public static bool DebugDraw;
|
||||
@@ -414,7 +413,5 @@ namespace Barotrauma
|
||||
|
||||
base.OnExiting(sender, args);
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
}
|
||||
555
BarotraumaClient/Source/Items/Item.cs
Normal file
@@ -0,0 +1,555 @@
|
||||
using Barotrauma.Items.Components;
|
||||
using Barotrauma.Networking;
|
||||
using FarseerPhysics;
|
||||
using FarseerPhysics.Dynamics;
|
||||
using FarseerPhysics.Dynamics.Contacts;
|
||||
using Lidgren.Network;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
partial class Item : MapEntity, IDamageable, IPropertyObject, IServerSerializable, IClientSerializable
|
||||
{
|
||||
public override Sprite Sprite
|
||||
{
|
||||
get { return prefab.sprite; }
|
||||
}
|
||||
|
||||
|
||||
public override void Draw(SpriteBatch spriteBatch, bool editing, bool back = true)
|
||||
{
|
||||
if (!Visible) return;
|
||||
Color color = (IsSelected && editing) ? color = Color.Red : spriteColor;
|
||||
if (isHighlighted) color = Color.Orange;
|
||||
|
||||
SpriteEffects oldEffects = prefab.sprite.effects;
|
||||
prefab.sprite.effects ^= SpriteEffects;
|
||||
|
||||
if (prefab.sprite != null)
|
||||
{
|
||||
float depth = Sprite.Depth;
|
||||
depth += (ID % 255) * 0.000001f;
|
||||
|
||||
if (body == null)
|
||||
{
|
||||
if (prefab.ResizeHorizontal || prefab.ResizeVertical || SpriteEffects.HasFlag(SpriteEffects.FlipHorizontally) || SpriteEffects.HasFlag(SpriteEffects.FlipVertically))
|
||||
{
|
||||
prefab.sprite.DrawTiled(spriteBatch, new Vector2(DrawPosition.X - rect.Width / 2, -(DrawPosition.Y + rect.Height / 2)), new Vector2(rect.Width, rect.Height), color);
|
||||
}
|
||||
else
|
||||
{
|
||||
prefab.sprite.Draw(spriteBatch, new Vector2(DrawPosition.X, -DrawPosition.Y), color, 0.0f, 1.0f, SpriteEffects.None, depth);
|
||||
}
|
||||
|
||||
}
|
||||
else if (body.Enabled)
|
||||
{
|
||||
var holdable = GetComponent<Holdable>();
|
||||
if (holdable != null && holdable.Picker?.AnimController != null)
|
||||
{
|
||||
if (holdable.Picker.SelectedItems[0] == this)
|
||||
{
|
||||
depth = holdable.Picker.AnimController.GetLimb(LimbType.RightHand).sprite.Depth + 0.000001f;
|
||||
}
|
||||
else if (holdable.Picker.SelectedItems[1] == this)
|
||||
{
|
||||
depth = holdable.Picker.AnimController.GetLimb(LimbType.LeftArm).sprite.Depth - 0.000001f;
|
||||
}
|
||||
|
||||
body.Draw(spriteBatch, prefab.sprite, color, depth);
|
||||
}
|
||||
else
|
||||
{
|
||||
body.Draw(spriteBatch, prefab.sprite, color, depth);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
prefab.sprite.effects = oldEffects;
|
||||
|
||||
List<IDrawableComponent> staticDrawableComponents = new List<IDrawableComponent>(drawableComponents); //static list to compensate for drawable toggling
|
||||
for (int i = 0; i < staticDrawableComponents.Count; i++)
|
||||
{
|
||||
staticDrawableComponents[i].Draw(spriteBatch, editing);
|
||||
}
|
||||
|
||||
if (GameMain.DebugDraw && aiTarget != null) aiTarget.Draw(spriteBatch);
|
||||
|
||||
if (!editing || (body != null && !body.Enabled))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (IsSelected || isHighlighted)
|
||||
{
|
||||
GUI.DrawRectangle(spriteBatch, new Vector2(DrawPosition.X - rect.Width / 2, -(DrawPosition.Y + rect.Height / 2)), new Vector2(rect.Width, rect.Height), Color.Green, false, 0, (int)Math.Max((1.5f / GameScreen.Selected.Cam.Zoom), 1.0f));
|
||||
|
||||
foreach (Rectangle t in prefab.Triggers)
|
||||
{
|
||||
Rectangle transformedTrigger = TransformTrigger(t);
|
||||
|
||||
Vector2 rectWorldPos = new Vector2(transformedTrigger.X, transformedTrigger.Y);
|
||||
if (Submarine != null) rectWorldPos += Submarine.Position;
|
||||
rectWorldPos.Y = -rectWorldPos.Y;
|
||||
|
||||
GUI.DrawRectangle(spriteBatch,
|
||||
rectWorldPos,
|
||||
new Vector2(transformedTrigger.Width, transformedTrigger.Height),
|
||||
Color.Green,
|
||||
false,
|
||||
0,
|
||||
(int)Math.Max((1.5f / GameScreen.Selected.Cam.Zoom), 1.0f));
|
||||
}
|
||||
}
|
||||
|
||||
if (!ShowLinks) return;
|
||||
|
||||
foreach (MapEntity e in linkedTo)
|
||||
{
|
||||
GUI.DrawLine(spriteBatch,
|
||||
new Vector2(WorldPosition.X, -WorldPosition.Y),
|
||||
new Vector2(e.WorldPosition.X, -e.WorldPosition.Y),
|
||||
Color.Red * 0.3f);
|
||||
}
|
||||
}
|
||||
|
||||
public override void UpdateEditing(Camera cam)
|
||||
{
|
||||
if (editingHUD == null || editingHUD.UserData as Item != this)
|
||||
{
|
||||
editingHUD = CreateEditingHUD(Screen.Selected != GameMain.EditMapScreen);
|
||||
}
|
||||
|
||||
editingHUD.Update((float)Timing.Step);
|
||||
|
||||
if (Screen.Selected != GameMain.EditMapScreen) return;
|
||||
|
||||
if (!prefab.IsLinkable) return;
|
||||
|
||||
if (!PlayerInput.LeftButtonClicked() || !PlayerInput.KeyDown(Keys.Space)) return;
|
||||
|
||||
Vector2 position = cam.ScreenToWorld(PlayerInput.MousePosition);
|
||||
|
||||
foreach (MapEntity entity in mapEntityList)
|
||||
{
|
||||
if (entity == this || !entity.IsHighlighted) continue;
|
||||
if (linkedTo.Contains(entity)) continue;
|
||||
if (!entity.IsMouseOn(position)) continue;
|
||||
|
||||
linkedTo.Add(entity);
|
||||
if (entity.IsLinkable && entity.linkedTo != null) entity.linkedTo.Add(this);
|
||||
}
|
||||
}
|
||||
|
||||
public override void DrawEditing(SpriteBatch spriteBatch, Camera cam)
|
||||
{
|
||||
if (editingHUD != null) editingHUD.Draw(spriteBatch);
|
||||
}
|
||||
|
||||
private GUIComponent CreateEditingHUD(bool inGame = false)
|
||||
{
|
||||
List<ObjectProperty> editableProperties = inGame ? GetProperties<InGameEditable>() : GetProperties<Editable>();
|
||||
|
||||
int requiredItemCount = 0;
|
||||
if (!inGame)
|
||||
{
|
||||
foreach (ItemComponent ic in components)
|
||||
{
|
||||
requiredItemCount += ic.requiredItems.Count;
|
||||
}
|
||||
}
|
||||
|
||||
int width = 450;
|
||||
int height = 80 + requiredItemCount * 20;
|
||||
int x = GameMain.GraphicsWidth / 2 - width / 2, y = 10;
|
||||
foreach (var objectProperty in editableProperties)
|
||||
{
|
||||
var editable = objectProperty.Attributes.OfType<Editable>().FirstOrDefault();
|
||||
if (editable != null) height += (int)(Math.Ceiling(editable.MaxLength / 40.0f) * 18.0f) + 5;
|
||||
}
|
||||
|
||||
editingHUD = new GUIFrame(new Rectangle(x, y, width, height), "");
|
||||
editingHUD.Padding = new Vector4(10, 10, 0, 0);
|
||||
editingHUD.UserData = this;
|
||||
|
||||
new GUITextBlock(new Rectangle(0, 0, 100, 20), prefab.Name, "",
|
||||
Alignment.TopLeft, Alignment.TopLeft, editingHUD, false, GUI.LargeFont);
|
||||
|
||||
y += 25;
|
||||
|
||||
if (!inGame)
|
||||
{
|
||||
if (prefab.IsLinkable)
|
||||
{
|
||||
new GUITextBlock(new Rectangle(0, 5, 0, 20), "Hold space to link to another item",
|
||||
"", Alignment.TopRight, Alignment.TopRight, editingHUD).Font = GUI.SmallFont;
|
||||
}
|
||||
foreach (ItemComponent ic in components)
|
||||
{
|
||||
foreach (RelatedItem relatedItem in ic.requiredItems)
|
||||
{
|
||||
new GUITextBlock(new Rectangle(0, y, 100, 15), ic.Name + ": " + relatedItem.Type.ToString() + " required", "", Alignment.TopLeft, Alignment.CenterLeft, editingHUD, false, GUI.SmallFont);
|
||||
GUITextBox namesBox = new GUITextBox(new Rectangle(-10, y, 160, 15), Alignment.Right, "", editingHUD);
|
||||
namesBox.Font = GUI.SmallFont;
|
||||
|
||||
PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(relatedItem);
|
||||
PropertyDescriptor property = properties.Find("JoinedNames", false);
|
||||
|
||||
namesBox.Text = relatedItem.JoinedNames;
|
||||
namesBox.UserData = new ObjectProperty(property, relatedItem);
|
||||
namesBox.OnEnterPressed = EnterProperty;
|
||||
namesBox.OnTextChanged = PropertyChanged;
|
||||
|
||||
y += 20;
|
||||
}
|
||||
}
|
||||
if (requiredItemCount > 0) y += 10;
|
||||
}
|
||||
|
||||
foreach (var objectProperty in editableProperties)
|
||||
{
|
||||
int boxHeight = 18;
|
||||
var editable = objectProperty.Attributes.OfType<Editable>().FirstOrDefault();
|
||||
if (editable != null) boxHeight = (int)(Math.Ceiling(editable.MaxLength / 40.0f) * 18.0f);
|
||||
|
||||
object value = objectProperty.GetValue();
|
||||
|
||||
if (value is bool)
|
||||
{
|
||||
GUITickBox propertyTickBox = new GUITickBox(new Rectangle(10, y, 18, 18), objectProperty.Name,
|
||||
Alignment.Left, editingHUD);
|
||||
propertyTickBox.Font = GUI.SmallFont;
|
||||
|
||||
propertyTickBox.Selected = (bool)value;
|
||||
|
||||
propertyTickBox.UserData = objectProperty;
|
||||
propertyTickBox.OnSelected = EnterProperty;
|
||||
}
|
||||
else
|
||||
{
|
||||
new GUITextBlock(new Rectangle(0, y, 100, 18), objectProperty.Name, "", Alignment.TopLeft, Alignment.Left, editingHUD, false, GUI.SmallFont);
|
||||
|
||||
GUITextBox propertyBox = new GUITextBox(new Rectangle(180, y, 250, boxHeight), "", editingHUD);
|
||||
propertyBox.Font = GUI.SmallFont;
|
||||
if (boxHeight > 18) propertyBox.Wrap = true;
|
||||
|
||||
if (value != null)
|
||||
{
|
||||
if (value is float)
|
||||
{
|
||||
propertyBox.Text = ((float)value).ToString("G", System.Globalization.CultureInfo.InvariantCulture);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
propertyBox.Text = value.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
propertyBox.UserData = objectProperty;
|
||||
propertyBox.OnEnterPressed = EnterProperty;
|
||||
propertyBox.OnTextChanged = PropertyChanged;
|
||||
|
||||
}
|
||||
y = y + boxHeight + 5;
|
||||
|
||||
}
|
||||
return editingHUD;
|
||||
}
|
||||
public virtual void DrawHUD(SpriteBatch spriteBatch, Camera cam, Character character)
|
||||
{
|
||||
if (condition <= 0.0f)
|
||||
{
|
||||
FixRequirement.DrawHud(spriteBatch, this, character);
|
||||
return;
|
||||
}
|
||||
|
||||
if (HasInGameEditableProperties)
|
||||
{
|
||||
DrawEditing(spriteBatch, cam);
|
||||
}
|
||||
|
||||
foreach (ItemComponent ic in components)
|
||||
{
|
||||
if (ic.CanBeSelected) ic.DrawHUD(spriteBatch, character);
|
||||
}
|
||||
}
|
||||
|
||||
public override void AddToGUIUpdateList()
|
||||
{
|
||||
if (Screen.Selected is EditMapScreen)
|
||||
{
|
||||
if (editingHUD != null) editingHUD.AddToGUIUpdateList();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (HasInGameEditableProperties)
|
||||
{
|
||||
if (editingHUD != null) editingHUD.AddToGUIUpdateList();
|
||||
}
|
||||
}
|
||||
|
||||
if (Character.Controlled != null && Character.Controlled.SelectedConstruction == this)
|
||||
{
|
||||
if (condition <= 0.0f)
|
||||
{
|
||||
FixRequirement.AddToGUIUpdateList();
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (ItemComponent ic in components)
|
||||
{
|
||||
if (ic.CanBeSelected) ic.AddToGUIUpdateList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool EnterProperty(GUITickBox tickBox)
|
||||
{
|
||||
var objectProperty = tickBox.UserData as ObjectProperty;
|
||||
if (objectProperty == null) return false;
|
||||
|
||||
objectProperty.TrySetValue(tickBox.Selected);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool EnterProperty(GUITextBox textBox, string text)
|
||||
{
|
||||
textBox.Color = Color.DarkGreen;
|
||||
|
||||
var objectProperty = textBox.UserData as ObjectProperty;
|
||||
if (objectProperty == null) return false;
|
||||
|
||||
object prevValue = objectProperty.GetValue();
|
||||
|
||||
textBox.Deselect();
|
||||
|
||||
if (objectProperty.TrySetValue(text))
|
||||
{
|
||||
textBox.Text = text;
|
||||
|
||||
if (GameMain.Server != null)
|
||||
{
|
||||
GameMain.Server.CreateEntityEvent(this, new object[] { NetEntityEvent.Type.ChangeProperty, objectProperty });
|
||||
}
|
||||
else if (GameMain.Client != null)
|
||||
{
|
||||
GameMain.Client.CreateEntityEvent(this, new object[] { NetEntityEvent.Type.ChangeProperty, objectProperty });
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (prevValue != null)
|
||||
{
|
||||
textBox.Text = prevValue.ToString();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private bool PropertyChanged(GUITextBox textBox, string text)
|
||||
{
|
||||
textBox.Color = Color.Red;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override XElement Save(XElement parentElement)
|
||||
{
|
||||
XElement element = new XElement("Item");
|
||||
|
||||
element.Add(new XAttribute("name", prefab.Name),
|
||||
new XAttribute("ID", ID));
|
||||
|
||||
System.Diagnostics.Debug.Assert(Submarine != null);
|
||||
|
||||
if (ResizeHorizontal || ResizeVertical)
|
||||
{
|
||||
element.Add(new XAttribute("rect",
|
||||
(int)(rect.X - Submarine.HiddenSubPosition.X) + "," +
|
||||
(int)(rect.Y - Submarine.HiddenSubPosition.Y) + "," +
|
||||
rect.Width + "," + rect.Height));
|
||||
}
|
||||
else
|
||||
{
|
||||
element.Add(new XAttribute("rect",
|
||||
(int)(rect.X - Submarine.HiddenSubPosition.X) + "," +
|
||||
(int)(rect.Y - Submarine.HiddenSubPosition.Y)));
|
||||
}
|
||||
|
||||
if (linkedTo != null && linkedTo.Count > 0)
|
||||
{
|
||||
string[] linkedToIDs = new string[linkedTo.Count];
|
||||
|
||||
for (int i = 0; i < linkedTo.Count; i++)
|
||||
{
|
||||
linkedToIDs[i] = linkedTo[i].ID.ToString();
|
||||
}
|
||||
|
||||
element.Add(new XAttribute("linked", string.Join(",", linkedToIDs)));
|
||||
}
|
||||
|
||||
|
||||
ObjectProperty.SaveProperties(this, element);
|
||||
|
||||
foreach (ItemComponent ic in components)
|
||||
{
|
||||
ic.Save(element);
|
||||
}
|
||||
|
||||
parentElement.Add(element);
|
||||
|
||||
return element;
|
||||
}
|
||||
|
||||
|
||||
public void ClientRead(ServerNetObject type, NetBuffer msg, float sendingTime)
|
||||
{
|
||||
if (type == ServerNetObject.ENTITY_POSITION)
|
||||
{
|
||||
ClientReadPosition(type, msg, sendingTime);
|
||||
return;
|
||||
}
|
||||
|
||||
NetEntityEvent.Type eventType =
|
||||
(NetEntityEvent.Type)msg.ReadRangedInteger(0, Enum.GetValues(typeof(NetEntityEvent.Type)).Length - 1);
|
||||
|
||||
switch (eventType)
|
||||
{
|
||||
case NetEntityEvent.Type.ComponentState:
|
||||
int componentIndex = msg.ReadRangedInteger(0, components.Count - 1);
|
||||
(components[componentIndex] as IServerSerializable).ClientRead(type, msg, sendingTime);
|
||||
break;
|
||||
case NetEntityEvent.Type.InventoryState:
|
||||
ownInventory.ClientRead(type, msg, sendingTime);
|
||||
break;
|
||||
case NetEntityEvent.Type.Status:
|
||||
condition = msg.ReadRangedSingle(0.0f, 100.0f, 8);
|
||||
|
||||
if (FixRequirements.Count > 0)
|
||||
{
|
||||
if (Condition <= 0.0f)
|
||||
{
|
||||
for (int i = 0; i < FixRequirements.Count; i++)
|
||||
FixRequirements[i].Fixed = msg.ReadBoolean();
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < FixRequirements.Count; i++)
|
||||
FixRequirements[i].Fixed = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case NetEntityEvent.Type.ApplyStatusEffect:
|
||||
ActionType actionType = (ActionType)msg.ReadRangedInteger(0, Enum.GetValues(typeof(ActionType)).Length - 1);
|
||||
ushort targetID = msg.ReadUInt16();
|
||||
|
||||
Character target = FindEntityByID(targetID) as Character;
|
||||
ApplyStatusEffects(actionType, (float)Timing.Step, target, true);
|
||||
break;
|
||||
case NetEntityEvent.Type.ChangeProperty:
|
||||
ReadPropertyChange(msg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void ClientWrite(NetBuffer msg, object[] extraData = null)
|
||||
{
|
||||
if (extraData == null || extraData.Length == 0 || !(extraData[0] is NetEntityEvent.Type))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
NetEntityEvent.Type eventType = (NetEntityEvent.Type)extraData[0];
|
||||
msg.WriteRangedInteger(0, Enum.GetValues(typeof(NetEntityEvent.Type)).Length - 1, (int)eventType);
|
||||
switch (eventType)
|
||||
{
|
||||
case NetEntityEvent.Type.ComponentState:
|
||||
int componentIndex = (int)extraData[1];
|
||||
msg.WriteRangedInteger(0, components.Count - 1, componentIndex);
|
||||
|
||||
(components[componentIndex] as IClientSerializable).ClientWrite(msg, extraData);
|
||||
break;
|
||||
case NetEntityEvent.Type.InventoryState:
|
||||
ownInventory.ClientWrite(msg, extraData);
|
||||
break;
|
||||
case NetEntityEvent.Type.Repair:
|
||||
if (FixRequirements.Count > 0)
|
||||
{
|
||||
int requirementIndex = (int)extraData[1];
|
||||
msg.WriteRangedInteger(0, FixRequirements.Count - 1, requirementIndex);
|
||||
}
|
||||
break;
|
||||
case NetEntityEvent.Type.ApplyStatusEffect:
|
||||
//no further data needed, the server applies the effect
|
||||
//on the character of the client who sent the message
|
||||
break;
|
||||
case NetEntityEvent.Type.ChangeProperty:
|
||||
WritePropertyChange(msg, extraData);
|
||||
break;
|
||||
}
|
||||
msg.WritePadBits();
|
||||
}
|
||||
|
||||
public void ClientReadPosition(ServerNetObject type, NetBuffer msg, float sendingTime)
|
||||
{
|
||||
Vector2 newPosition = new Vector2(msg.ReadFloat(), msg.ReadFloat());
|
||||
float newRotation = msg.ReadRangedSingle(0.0f, MathHelper.TwoPi, 7);
|
||||
bool awake = msg.ReadBoolean();
|
||||
Vector2 newVelocity = Vector2.Zero;
|
||||
|
||||
if (awake)
|
||||
{
|
||||
newVelocity = new Vector2(
|
||||
msg.ReadRangedSingle(-MaxVel, MaxVel, 12),
|
||||
msg.ReadRangedSingle(-MaxVel, MaxVel, 12));
|
||||
}
|
||||
|
||||
if (body == null)
|
||||
{
|
||||
DebugConsole.ThrowError("Received a position update for an item with no physics body (" + Name + ")");
|
||||
return;
|
||||
}
|
||||
|
||||
body.FarseerBody.Awake = awake;
|
||||
if (body.FarseerBody.Awake)
|
||||
{
|
||||
if ((newVelocity - body.LinearVelocity).Length() > 8.0f) body.LinearVelocity = newVelocity;
|
||||
}
|
||||
else
|
||||
{
|
||||
body.FarseerBody.Enabled = false;
|
||||
}
|
||||
|
||||
if ((newPosition - SimPosition).Length() > body.LinearVelocity.Length() * 2.0f)
|
||||
{
|
||||
body.SetTransform(newPosition, newRotation);
|
||||
|
||||
Vector2 displayPos = ConvertUnits.ToDisplayUnits(body.SimPosition);
|
||||
rect.X = (int)(displayPos.X - rect.Width / 2.0f);
|
||||
rect.Y = (int)(displayPos.Y + rect.Height / 2.0f);
|
||||
}
|
||||
}
|
||||
|
||||
public void CreateClientEvent<T>(T ic) where T : ItemComponent, IClientSerializable
|
||||
{
|
||||
if (GameMain.Client == null) return;
|
||||
|
||||
int index = components.IndexOf(ic);
|
||||
if (index == -1) return;
|
||||
|
||||
GameMain.Client.CreateEntityEvent(this, new object[] { NetEntityEvent.Type.ComponentState, index });
|
||||
}
|
||||
}
|
||||
}
|
||||
647
BarotraumaClient/Source/Map/MapEntity.cs
Normal file
@@ -0,0 +1,647 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
using FarseerPhysics;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
using System.Collections.ObjectModel;
|
||||
using Barotrauma.Items.Components;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
abstract partial class MapEntity
|
||||
{
|
||||
protected static Vector2 selectionPos = Vector2.Zero;
|
||||
protected static Vector2 selectionSize = Vector2.Zero;
|
||||
|
||||
protected static Vector2 startMovingPos = Vector2.Zero;
|
||||
|
||||
//which entities have been selected for editing
|
||||
private static List<MapEntity> selectedList = new List<MapEntity>();
|
||||
public static List<MapEntity> SelectedList
|
||||
{
|
||||
get
|
||||
{
|
||||
return selectedList;
|
||||
}
|
||||
}
|
||||
private static List<MapEntity> copiedList = new List<MapEntity>();
|
||||
|
||||
private static List<MapEntity> highlightedList = new List<MapEntity>();
|
||||
|
||||
private static float highlightTimer;
|
||||
|
||||
private static GUIListBox highlightedListBox;
|
||||
public static GUIListBox HighlightedListBox
|
||||
{
|
||||
get { return highlightedListBox; }
|
||||
}
|
||||
|
||||
|
||||
protected static GUIComponent editingHUD;
|
||||
public static GUIComponent EditingHUD
|
||||
{
|
||||
get
|
||||
{
|
||||
return editingHUD;
|
||||
}
|
||||
}
|
||||
|
||||
//is the mouse inside the rect
|
||||
protected bool isHighlighted;
|
||||
|
||||
//protected bool isSelected;
|
||||
|
||||
private static bool disableSelect;
|
||||
public static bool DisableSelect
|
||||
{
|
||||
get { return disableSelect; }
|
||||
set
|
||||
{
|
||||
disableSelect = value;
|
||||
if (disableSelect)
|
||||
{
|
||||
startMovingPos = Vector2.Zero;
|
||||
selectionSize = Vector2.Zero;
|
||||
selectionPos = Vector2.Zero;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static bool SelectedAny
|
||||
{
|
||||
get { return selectedList.Count > 0; }
|
||||
}
|
||||
|
||||
|
||||
public bool IsHighlighted
|
||||
{
|
||||
get { return isHighlighted; }
|
||||
set { isHighlighted = value; }
|
||||
}
|
||||
|
||||
public bool IsSelected
|
||||
{
|
||||
get { return selectedList.Contains(this); }
|
||||
}
|
||||
|
||||
protected bool ResizeHorizontal
|
||||
{
|
||||
get { return prefab != null && prefab.ResizeHorizontal; }
|
||||
}
|
||||
protected bool ResizeVertical
|
||||
{
|
||||
get { return prefab != null && prefab.ResizeVertical; }
|
||||
}
|
||||
|
||||
public virtual void Draw(SpriteBatch spriteBatch, bool editing, bool back = true) { }
|
||||
|
||||
public virtual void DrawDamage(SpriteBatch spriteBatch, Effect damageEffect) { }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Update the selection logic in submarine editor
|
||||
/// </summary>
|
||||
public static void UpdateSelecting(Camera cam)
|
||||
{
|
||||
if (resizing)
|
||||
{
|
||||
if (selectedList.Count == 0) resizing = false;
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (MapEntity e in mapEntityList)
|
||||
{
|
||||
e.isHighlighted = false;
|
||||
}
|
||||
|
||||
if (DisableSelect)
|
||||
{
|
||||
DisableSelect = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (GUIComponent.MouseOn != null || !PlayerInput.MouseInsideWindow)
|
||||
{
|
||||
if (highlightedListBox == null ||
|
||||
(GUIComponent.MouseOn != highlightedListBox && !highlightedListBox.IsParentOf(GUIComponent.MouseOn)))
|
||||
{
|
||||
UpdateHighlightedListBox(null);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (MapEntityPrefab.Selected != null)
|
||||
{
|
||||
selectionPos = Vector2.Zero;
|
||||
selectedList.Clear();
|
||||
return;
|
||||
}
|
||||
|
||||
if (PlayerInput.KeyDown(Keys.Delete))
|
||||
{
|
||||
selectedList.ForEach(e => e.Remove());
|
||||
selectedList.Clear();
|
||||
}
|
||||
|
||||
if (PlayerInput.KeyDown(Keys.LeftControl) || PlayerInput.KeyDown(Keys.RightControl))
|
||||
{
|
||||
if (PlayerInput.GetKeyboardState.IsKeyDown(Keys.C) &&
|
||||
PlayerInput.GetOldKeyboardState.IsKeyUp(Keys.C))
|
||||
{
|
||||
CopyEntities(selectedList);
|
||||
}
|
||||
else if (PlayerInput.GetKeyboardState.IsKeyDown(Keys.X) &&
|
||||
PlayerInput.GetOldKeyboardState.IsKeyUp(Keys.X))
|
||||
{
|
||||
CopyEntities(selectedList);
|
||||
|
||||
selectedList.ForEach(e => e.Remove());
|
||||
selectedList.Clear();
|
||||
}
|
||||
else if (copiedList.Count > 0 &&
|
||||
PlayerInput.GetKeyboardState.IsKeyDown(Keys.V) &&
|
||||
PlayerInput.GetOldKeyboardState.IsKeyUp(Keys.V))
|
||||
{
|
||||
var clones = Clone(copiedList);
|
||||
|
||||
Vector2 center = Vector2.Zero;
|
||||
clones.ForEach(c => center += c.WorldPosition);
|
||||
center = Submarine.VectorToWorldGrid(center / clones.Count);
|
||||
|
||||
Vector2 moveAmount = Submarine.VectorToWorldGrid(cam.WorldViewCenter - center);
|
||||
|
||||
selectedList = new List<MapEntity>(clones);
|
||||
foreach (MapEntity clone in selectedList)
|
||||
{
|
||||
clone.Move(moveAmount);
|
||||
clone.Submarine = Submarine.MainSub;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Vector2 position = cam.ScreenToWorld(PlayerInput.MousePosition);
|
||||
|
||||
MapEntity highLightedEntity = null;
|
||||
|
||||
if (startMovingPos == Vector2.Zero)
|
||||
{
|
||||
List<MapEntity> highlightedEntities = new List<MapEntity>();
|
||||
if (highlightedListBox != null && highlightedListBox.IsParentOf(GUIComponent.MouseOn))
|
||||
{
|
||||
highLightedEntity = GUIComponent.MouseOn.UserData as MapEntity;
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (MapEntity e in mapEntityList)
|
||||
{
|
||||
if (!e.SelectableInEditor) continue;
|
||||
|
||||
if (e.IsMouseOn(position))
|
||||
{
|
||||
int i = 0;
|
||||
while (i < highlightedEntities.Count &&
|
||||
e.Sprite != null &&
|
||||
(highlightedEntities[i].Sprite == null || highlightedEntities[i].Sprite.Depth < e.Sprite.Depth))
|
||||
{
|
||||
i++;
|
||||
}
|
||||
|
||||
highlightedEntities.Insert(i, e);
|
||||
|
||||
if (i == 0) highLightedEntity = e;
|
||||
}
|
||||
}
|
||||
|
||||
if (PlayerInput.MouseSpeed.LengthSquared() > 10)
|
||||
{
|
||||
highlightTimer = 0.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
bool mouseNearHighlightBox = false;
|
||||
|
||||
if (highlightedListBox != null)
|
||||
{
|
||||
Rectangle expandedRect = highlightedListBox.Rect;
|
||||
expandedRect.Inflate(20, 20);
|
||||
mouseNearHighlightBox = expandedRect.Contains(PlayerInput.MousePosition);
|
||||
if (!mouseNearHighlightBox) highlightedListBox = null;
|
||||
}
|
||||
|
||||
highlightTimer += (float)Timing.Step;
|
||||
if (highlightTimer > 1.0f)
|
||||
{
|
||||
if (!mouseNearHighlightBox)
|
||||
{
|
||||
UpdateHighlightedListBox(highlightedEntities);
|
||||
highlightTimer = 0.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (highLightedEntity != null) highLightedEntity.isHighlighted = true;
|
||||
}
|
||||
|
||||
//started moving selected entities
|
||||
if (startMovingPos != Vector2.Zero)
|
||||
{
|
||||
if (PlayerInput.LeftButtonReleased())
|
||||
{
|
||||
//mouse released -> move the entities to the new position of the mouse
|
||||
|
||||
Vector2 moveAmount = position - startMovingPos;
|
||||
moveAmount = Submarine.VectorToWorldGrid(moveAmount);
|
||||
|
||||
if (moveAmount != Vector2.Zero)
|
||||
{
|
||||
//clone
|
||||
if (PlayerInput.KeyDown(Keys.LeftControl) || PlayerInput.KeyDown(Keys.RightControl))
|
||||
{
|
||||
var clones = Clone(selectedList);
|
||||
selectedList = clones;
|
||||
selectedList.ForEach(c => c.Move(moveAmount));
|
||||
}
|
||||
else // move
|
||||
{
|
||||
foreach (MapEntity e in selectedList) e.Move(moveAmount);
|
||||
}
|
||||
}
|
||||
|
||||
startMovingPos = Vector2.Zero;
|
||||
}
|
||||
|
||||
}
|
||||
//started dragging a "selection rectangle"
|
||||
else if (selectionPos != Vector2.Zero)
|
||||
{
|
||||
selectionSize.X = position.X - selectionPos.X;
|
||||
selectionSize.Y = selectionPos.Y - position.Y;
|
||||
|
||||
List<MapEntity> newSelection = new List<MapEntity>();// FindSelectedEntities(selectionPos, selectionSize);
|
||||
if (Math.Abs(selectionSize.X) > Submarine.GridSize.X || Math.Abs(selectionSize.Y) > Submarine.GridSize.Y)
|
||||
{
|
||||
newSelection = FindSelectedEntities(selectionPos, selectionSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (highLightedEntity != null) newSelection.Add(highLightedEntity);
|
||||
}
|
||||
|
||||
if (PlayerInput.LeftButtonReleased())
|
||||
{
|
||||
if (PlayerInput.KeyDown(Keys.LeftControl) ||
|
||||
PlayerInput.KeyDown(Keys.RightControl))
|
||||
{
|
||||
foreach (MapEntity e in newSelection)
|
||||
{
|
||||
if (selectedList.Contains(e))
|
||||
selectedList.Remove(e);
|
||||
else
|
||||
selectedList.Add(e);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
selectedList = newSelection;
|
||||
}
|
||||
|
||||
//select wire if both items it's connected to are selected
|
||||
var selectedItems = selectedList.Where(e => e is Item).Cast<Item>().ToList();
|
||||
foreach (Item item in selectedItems)
|
||||
{
|
||||
if (item.Connections == null) continue;
|
||||
foreach (Connection c in item.Connections)
|
||||
{
|
||||
foreach (Wire w in c.Wires)
|
||||
{
|
||||
if (w == null || selectedList.Contains(w.Item)) continue;
|
||||
|
||||
if (w.OtherConnection(c) != null && selectedList.Contains(w.OtherConnection(c).Item))
|
||||
{
|
||||
selectedList.Add(w.Item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
selectionPos = Vector2.Zero;
|
||||
selectionSize = Vector2.Zero;
|
||||
}
|
||||
}
|
||||
//default, not doing anything specific yet
|
||||
else
|
||||
{
|
||||
if (PlayerInput.LeftButtonHeld() &&
|
||||
PlayerInput.KeyUp(Keys.Space) &&
|
||||
(highlightedListBox == null || (GUIComponent.MouseOn != highlightedListBox && !highlightedListBox.IsParentOf(GUIComponent.MouseOn))))
|
||||
{
|
||||
//if clicking a selected entity, start moving it
|
||||
foreach (MapEntity e in selectedList)
|
||||
{
|
||||
if (e.IsMouseOn(position)) startMovingPos = position;
|
||||
}
|
||||
|
||||
selectionPos = position;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void UpdateHighlightedListBox(List<MapEntity> highlightedEntities)
|
||||
{
|
||||
if (highlightedEntities == null || highlightedEntities.Count < 2)
|
||||
{
|
||||
highlightedListBox = null;
|
||||
return;
|
||||
}
|
||||
if (highlightedListBox != null)
|
||||
{
|
||||
if (GUIComponent.MouseOn == highlightedListBox || highlightedListBox.IsParentOf(GUIComponent.MouseOn)) return;
|
||||
if (highlightedEntities.SequenceEqual(highlightedList)) return;
|
||||
}
|
||||
|
||||
highlightedList = highlightedEntities;
|
||||
|
||||
highlightedListBox = new GUIListBox(
|
||||
new Rectangle((int)PlayerInput.MousePosition.X + 15, (int)PlayerInput.MousePosition.Y + 15, 150, highlightedEntities.Count * 18 + 5),
|
||||
null, Alignment.TopLeft, "GUIToolTip", null, false);
|
||||
|
||||
foreach (MapEntity entity in highlightedEntities)
|
||||
{
|
||||
var textBlock = new GUITextBlock(
|
||||
new Rectangle(0, 0, highlightedListBox.Rect.Width, 18),
|
||||
ToolBox.LimitString(entity.Name, GUI.SmallFont, 140), "", Alignment.TopLeft, Alignment.CenterLeft, highlightedListBox, false, GUI.SmallFont);
|
||||
|
||||
textBlock.UserData = entity;
|
||||
}
|
||||
|
||||
highlightedListBox.OnSelected = (GUIComponent component, object obj) =>
|
||||
{
|
||||
MapEntity entity = obj as MapEntity;
|
||||
|
||||
if (PlayerInput.KeyDown(Keys.LeftControl) ||
|
||||
PlayerInput.KeyDown(Keys.RightControl))
|
||||
{
|
||||
if (selectedList.Contains(entity))
|
||||
selectedList.Remove(entity);
|
||||
else
|
||||
selectedList.Add(entity);
|
||||
}
|
||||
else
|
||||
{
|
||||
SelectEntity(entity);
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Draw the "selection rectangle" and outlines of entities that are being dragged (if any)
|
||||
/// </summary>
|
||||
public static void DrawSelecting(SpriteBatch spriteBatch, Camera cam)
|
||||
{
|
||||
if (GUIComponent.MouseOn != null) return;
|
||||
|
||||
Vector2 position = PlayerInput.MousePosition;
|
||||
position = cam.ScreenToWorld(position);
|
||||
|
||||
if (startMovingPos != Vector2.Zero)
|
||||
{
|
||||
Vector2 moveAmount = position - startMovingPos;
|
||||
moveAmount = Submarine.VectorToWorldGrid(moveAmount);
|
||||
moveAmount.Y = -moveAmount.Y;
|
||||
//started moving the selected entities
|
||||
if (moveAmount != Vector2.Zero)
|
||||
{
|
||||
foreach (MapEntity e in selectedList)
|
||||
GUI.DrawRectangle(spriteBatch,
|
||||
new Vector2(e.WorldRect.X, -e.WorldRect.Y) + moveAmount,
|
||||
new Vector2(e.rect.Width, e.rect.Height),
|
||||
Color.DarkRed, false, 0, (int)Math.Max(1.5f / GameScreen.Selected.Cam.Zoom, 1.0f));
|
||||
|
||||
//stop dragging the "selection rectangle"
|
||||
selectionPos = Vector2.Zero;
|
||||
}
|
||||
}
|
||||
if (selectionPos != null && selectionPos != Vector2.Zero)
|
||||
{
|
||||
GUI.DrawRectangle(spriteBatch, new Vector2(selectionPos.X, -selectionPos.Y), selectionSize, Color.DarkRed, false, 0, (int)Math.Max(1.5f / GameScreen.Selected.Cam.Zoom, 1.0f));
|
||||
}
|
||||
}
|
||||
|
||||
public static void UpdateEditor(Camera cam)
|
||||
{
|
||||
if (highlightedListBox != null) highlightedListBox.Update((float)Timing.Step);
|
||||
|
||||
if (selectedList.Count == 1)
|
||||
{
|
||||
selectedList[0].UpdateEditing(cam);
|
||||
|
||||
if (selectedList[0].ResizeHorizontal || selectedList[0].ResizeVertical)
|
||||
{
|
||||
selectedList[0].UpdateResizing(cam);
|
||||
}
|
||||
}
|
||||
|
||||
if (editingHUD != null)
|
||||
{
|
||||
if (selectedList.Count == 0 || editingHUD.UserData != selectedList[0])
|
||||
{
|
||||
foreach (GUIComponent component in editingHUD.children)
|
||||
{
|
||||
var textBox = component as GUITextBox;
|
||||
if (textBox == null) continue;
|
||||
|
||||
textBox.Deselect();
|
||||
}
|
||||
|
||||
editingHUD = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void DrawEditor(SpriteBatch spriteBatch, Camera cam)
|
||||
{
|
||||
if (selectedList.Count == 1)
|
||||
{
|
||||
selectedList[0].DrawEditing(spriteBatch, cam);
|
||||
|
||||
if (selectedList[0].ResizeHorizontal || selectedList[0].ResizeVertical)
|
||||
{
|
||||
selectedList[0].DrawResizing(spriteBatch, cam);
|
||||
}
|
||||
}
|
||||
|
||||
if (highlightedListBox != null)
|
||||
{
|
||||
highlightedListBox.Draw(spriteBatch);
|
||||
}
|
||||
}
|
||||
|
||||
public static void DeselectAll()
|
||||
{
|
||||
selectedList.Clear();
|
||||
}
|
||||
|
||||
|
||||
public static void SelectEntity(MapEntity entity)
|
||||
{
|
||||
DeselectAll();
|
||||
|
||||
selectedList.Add(entity);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// copies a list of entities to the "clipboard" (copiedList)
|
||||
/// </summary>
|
||||
private static void CopyEntities(List<MapEntity> entities)
|
||||
{
|
||||
List<MapEntity> prevEntities = new List<MapEntity>(mapEntityList);
|
||||
|
||||
copiedList = Clone(entities);
|
||||
|
||||
//find all new entities created during cloning
|
||||
var newEntities = mapEntityList.Except(prevEntities).ToList();
|
||||
|
||||
//do a "shallow remove" (removes the entities from the game without removing links between them)
|
||||
// -> items will stay in their containers
|
||||
newEntities.ForEach(e => e.ShallowRemove());
|
||||
}
|
||||
|
||||
public virtual void AddToGUIUpdateList()
|
||||
{
|
||||
if (editingHUD != null && editingHUD.UserData == this) editingHUD.AddToGUIUpdateList();
|
||||
}
|
||||
|
||||
public virtual void UpdateEditing(Camera cam) { }
|
||||
|
||||
public virtual void DrawEditing(SpriteBatch spriteBatch, Camera cam) { }
|
||||
|
||||
private void UpdateResizing(Camera cam)
|
||||
{
|
||||
isHighlighted = true;
|
||||
|
||||
int startX = ResizeHorizontal ? -1 : 0;
|
||||
int StartY = ResizeVertical ? -1 : 0;
|
||||
|
||||
for (int x = startX; x < 2; x += 2)
|
||||
{
|
||||
for (int y = StartY; y < 2; y += 2)
|
||||
{
|
||||
Vector2 handlePos = cam.WorldToScreen(Position + new Vector2(x * (rect.Width * 0.5f + 5), y * (rect.Height * 0.5f + 5)));
|
||||
|
||||
bool highlighted = Vector2.Distance(PlayerInput.MousePosition, handlePos) < 5.0f;
|
||||
|
||||
if (highlighted && PlayerInput.LeftButtonDown())
|
||||
{
|
||||
selectionPos = Vector2.Zero;
|
||||
resizeDirX = x;
|
||||
resizeDirY = y;
|
||||
resizing = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (resizing)
|
||||
{
|
||||
Vector2 placePosition = new Vector2(rect.X, rect.Y);
|
||||
Vector2 placeSize = new Vector2(rect.Width, rect.Height);
|
||||
|
||||
Vector2 mousePos = Submarine.MouseToWorldGrid(cam, Submarine.MainSub);
|
||||
|
||||
if (resizeDirX > 0)
|
||||
{
|
||||
mousePos.X = Math.Max(mousePos.X, rect.X + Submarine.GridSize.X);
|
||||
placeSize.X = mousePos.X - placePosition.X;
|
||||
}
|
||||
else if (resizeDirX < 0)
|
||||
{
|
||||
mousePos.X = Math.Min(mousePos.X, rect.Right - Submarine.GridSize.X);
|
||||
|
||||
placeSize.X = (placePosition.X + placeSize.X) - mousePos.X;
|
||||
placePosition.X = mousePos.X;
|
||||
}
|
||||
if (resizeDirY < 0)
|
||||
{
|
||||
mousePos.Y = Math.Min(mousePos.Y, rect.Y - Submarine.GridSize.Y);
|
||||
placeSize.Y = placePosition.Y - mousePos.Y;
|
||||
}
|
||||
else if (resizeDirY > 0)
|
||||
{
|
||||
mousePos.Y = Math.Max(mousePos.Y, rect.Y - rect.Height + Submarine.GridSize.X);
|
||||
|
||||
placeSize.Y = mousePos.Y - (rect.Y - rect.Height);
|
||||
placePosition.Y = mousePos.Y;
|
||||
}
|
||||
|
||||
if ((int)placePosition.X != rect.X || (int)placePosition.Y != rect.Y || (int)placeSize.X != rect.Width || (int)placeSize.Y != rect.Height)
|
||||
{
|
||||
Rect = new Rectangle((int)placePosition.X, (int)placePosition.Y, (int)placeSize.X, (int)placeSize.Y);
|
||||
}
|
||||
|
||||
if (!PlayerInput.LeftButtonHeld())
|
||||
{
|
||||
resizing = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawResizing(SpriteBatch spriteBatch, Camera cam)
|
||||
{
|
||||
isHighlighted = true;
|
||||
|
||||
int startX = ResizeHorizontal ? -1 : 0;
|
||||
int StartY = ResizeVertical ? -1 : 0;
|
||||
|
||||
for (int x = startX; x < 2; x += 2)
|
||||
{
|
||||
for (int y = StartY; y < 2; y += 2)
|
||||
{
|
||||
Vector2 handlePos = cam.WorldToScreen(Position + new Vector2(x * (rect.Width * 0.5f + 5), y * (rect.Height * 0.5f + 5)));
|
||||
|
||||
bool highlighted = Vector2.Distance(PlayerInput.MousePosition, handlePos) < 5.0f;
|
||||
|
||||
GUI.DrawRectangle(spriteBatch,
|
||||
handlePos - new Vector2(3.0f, 3.0f),
|
||||
new Vector2(6.0f, 6.0f),
|
||||
Color.White * (highlighted ? 1.0f : 0.6f),
|
||||
true, 0,
|
||||
(int)Math.Max(1.5f / GameScreen.Selected.Cam.Zoom, 1.0f));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Find entities whose rect intersects with the "selection rect"
|
||||
/// </summary>
|
||||
public static List<MapEntity> FindSelectedEntities(Vector2 pos, Vector2 size)
|
||||
{
|
||||
List<MapEntity> foundEntities = new List<MapEntity>();
|
||||
|
||||
Rectangle selectionRect = Submarine.AbsRect(pos, size);
|
||||
|
||||
foreach (MapEntity e in mapEntityList)
|
||||
{
|
||||
if (!e.SelectableInEditor) continue;
|
||||
|
||||
if (Submarine.RectsOverlap(selectionRect, e.rect)) foundEntities.Add(e);
|
||||
}
|
||||
|
||||
return foundEntities;
|
||||
}
|
||||
|
||||
|
||||
public virtual XElement Save(XElement parentElement)
|
||||
{
|
||||
DebugConsole.ThrowError("Saving entity " + GetType() + " failed.");
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
50
BarotraumaClient/Source/Map/MapEntityPrefab.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
partial class MapEntityPrefab
|
||||
{
|
||||
public virtual void DrawPlacing(SpriteBatch spriteBatch, Camera cam)
|
||||
{
|
||||
Vector2 placeSize = Submarine.GridSize;
|
||||
|
||||
if (placePosition == Vector2.Zero)
|
||||
{
|
||||
Vector2 position = Submarine.MouseToWorldGrid(cam, Submarine.MainSub);
|
||||
|
||||
GUI.DrawLine(spriteBatch, new Vector2(position.X - GameMain.GraphicsWidth, -position.Y), new Vector2(position.X + GameMain.GraphicsWidth, -position.Y), Color.White, 0, (int)(2.0f / cam.Zoom));
|
||||
|
||||
GUI.DrawLine(spriteBatch, new Vector2(position.X, -(position.Y - GameMain.GraphicsHeight)), new Vector2(position.X, -(position.Y + GameMain.GraphicsHeight)), Color.White, 0, (int)(2.0f / cam.Zoom));
|
||||
}
|
||||
else
|
||||
{
|
||||
Vector2 position = Submarine.MouseToWorldGrid(cam, Submarine.MainSub);
|
||||
|
||||
if (resizeHorizontal) placeSize.X = position.X - placePosition.X;
|
||||
if (resizeVertical) placeSize.Y = placePosition.Y - position.Y;
|
||||
|
||||
Rectangle newRect = Submarine.AbsRect(placePosition, placeSize);
|
||||
newRect.Width = (int)Math.Max(newRect.Width, Submarine.GridSize.X);
|
||||
newRect.Height = (int)Math.Max(newRect.Height, Submarine.GridSize.Y);
|
||||
|
||||
if (Submarine.MainSub != null)
|
||||
{
|
||||
newRect.Location -= Submarine.MainSub.Position.ToPoint();
|
||||
}
|
||||
|
||||
newRect.Y = -newRect.Y;
|
||||
GUI.DrawRectangle(spriteBatch, newRect, Color.DarkBlue);
|
||||
}
|
||||
}
|
||||
|
||||
public void DrawListLine(SpriteBatch spriteBatch, Vector2 pos, Color color)
|
||||
{
|
||||
GUI.Font.DrawString(spriteBatch, name, pos, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
166
BarotraumaClient/Source/PlayerInput.cs
Normal file
@@ -0,0 +1,166 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
public static class PlayerInput
|
||||
{
|
||||
static MouseState mouseState, oldMouseState;
|
||||
static MouseState latestMouseState; //the absolute latest state, do NOT use for player interaction
|
||||
static KeyboardState keyboardState, oldKeyboardState;
|
||||
|
||||
static double timeSinceClick;
|
||||
|
||||
const double doubleClickDelay = 0.4;
|
||||
|
||||
static bool doubleClicked;
|
||||
|
||||
public static Keys selectKey = Keys.E;
|
||||
|
||||
public static Vector2 MousePosition
|
||||
{
|
||||
get { return new Vector2(mouseState.Position.X, mouseState.Position.Y); }
|
||||
}
|
||||
|
||||
public static Vector2 LatestMousePosition
|
||||
{
|
||||
get { return new Vector2(latestMouseState.Position.X, latestMouseState.Position.Y); }
|
||||
}
|
||||
|
||||
//public static MouseState GetMouseState
|
||||
//{
|
||||
// get { return mouseState; }
|
||||
//}
|
||||
//public static MouseState GetOldMouseState
|
||||
//{
|
||||
// get { return oldMouseState; }
|
||||
//}
|
||||
|
||||
public static bool MouseInsideWindow
|
||||
{
|
||||
get { return new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight).Contains(MousePosition); }
|
||||
}
|
||||
|
||||
public static Vector2 MouseSpeed
|
||||
{
|
||||
get
|
||||
{
|
||||
return GameMain.WindowActive ? MousePosition - new Vector2(oldMouseState.X, oldMouseState.Y) : Vector2.Zero;
|
||||
}
|
||||
}
|
||||
|
||||
public static KeyboardState GetKeyboardState
|
||||
{
|
||||
get { return keyboardState; }
|
||||
}
|
||||
|
||||
public static KeyboardState GetOldKeyboardState
|
||||
{
|
||||
get { return oldKeyboardState; }
|
||||
}
|
||||
|
||||
public static int ScrollWheelSpeed
|
||||
{
|
||||
get { return GameMain.WindowActive ? mouseState.ScrollWheelValue - oldMouseState.ScrollWheelValue : 0; }
|
||||
|
||||
}
|
||||
|
||||
public static bool LeftButtonHeld()
|
||||
{
|
||||
return GameMain.WindowActive && mouseState.LeftButton == ButtonState.Pressed;
|
||||
}
|
||||
|
||||
public static bool LeftButtonDown()
|
||||
{
|
||||
return GameMain.WindowActive &&
|
||||
oldMouseState.LeftButton == ButtonState.Released &&
|
||||
mouseState.LeftButton == ButtonState.Pressed;
|
||||
}
|
||||
|
||||
public static bool LeftButtonReleased()
|
||||
{
|
||||
return GameMain.WindowActive && mouseState.LeftButton == ButtonState.Released;
|
||||
}
|
||||
|
||||
|
||||
public static bool LeftButtonClicked()
|
||||
{
|
||||
return (GameMain.WindowActive &&
|
||||
oldMouseState.LeftButton == ButtonState.Pressed
|
||||
&& mouseState.LeftButton == ButtonState.Released);
|
||||
}
|
||||
|
||||
public static bool RightButtonHeld()
|
||||
{
|
||||
return GameMain.WindowActive && mouseState.RightButton == ButtonState.Pressed;
|
||||
}
|
||||
|
||||
public static bool RightButtonClicked()
|
||||
{
|
||||
return (GameMain.WindowActive &&
|
||||
oldMouseState.RightButton == ButtonState.Pressed
|
||||
&& mouseState.RightButton == ButtonState.Released);
|
||||
}
|
||||
|
||||
public static bool DoubleClicked()
|
||||
{
|
||||
return GameMain.WindowActive && doubleClicked;
|
||||
}
|
||||
|
||||
public static bool KeyHit(InputType inputType)
|
||||
{
|
||||
return GameMain.WindowActive && GameMain.Config.KeyBind(inputType).IsHit();
|
||||
}
|
||||
|
||||
public static bool KeyDown(InputType inputType)
|
||||
{
|
||||
return GameMain.WindowActive && GameMain.Config.KeyBind(inputType).IsDown();
|
||||
}
|
||||
|
||||
public static bool KeyUp(InputType inputType)
|
||||
{
|
||||
return GameMain.WindowActive && !GameMain.Config.KeyBind(inputType).IsDown();
|
||||
}
|
||||
|
||||
public static bool KeyHit(Keys button)
|
||||
{
|
||||
return (GameMain.WindowActive && oldKeyboardState.IsKeyDown(button) && keyboardState.IsKeyUp(button));
|
||||
}
|
||||
|
||||
public static bool KeyDown(Keys button)
|
||||
{
|
||||
return (GameMain.WindowActive && keyboardState.IsKeyDown(button));
|
||||
}
|
||||
|
||||
public static bool KeyUp(Keys button)
|
||||
{
|
||||
return GameMain.WindowActive && keyboardState.IsKeyUp(button);
|
||||
}
|
||||
|
||||
public static void Update(double deltaTime)
|
||||
{
|
||||
timeSinceClick += deltaTime;
|
||||
|
||||
oldMouseState = mouseState;
|
||||
mouseState = latestMouseState;
|
||||
UpdateVariable();
|
||||
|
||||
oldKeyboardState = keyboardState;
|
||||
keyboardState = Keyboard.GetState();
|
||||
|
||||
doubleClicked = false;
|
||||
if (LeftButtonClicked())
|
||||
{
|
||||
if (timeSinceClick < doubleClickDelay) doubleClicked = true;
|
||||
timeSinceClick = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
public static void UpdateVariable()
|
||||
{
|
||||
//do NOT use this for actual interaction with the game, this is to be used for debugging and rendering ONLY
|
||||
|
||||
latestMouseState = Mouse.GetState();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,42 +6,33 @@ using Microsoft.Xna.Framework.Input;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
class GameScreen : Screen
|
||||
partial class GameScreen : Screen
|
||||
{
|
||||
private Camera cam;
|
||||
|
||||
private Color waterColor = new Color(0.75f, 0.8f, 0.9f, 1.0f);
|
||||
|
||||
private BlurEffect lightBlur;
|
||||
|
||||
readonly RenderTarget2D renderTargetBackground;
|
||||
readonly RenderTarget2D renderTarget;
|
||||
readonly RenderTarget2D renderTargetWater;
|
||||
readonly RenderTarget2D renderTargetAir;
|
||||
|
||||
private BlurEffect lightBlur;
|
||||
|
||||
private Effect damageEffect;
|
||||
|
||||
private Texture2D damageStencil;
|
||||
|
||||
public BackgroundCreatureManager BackgroundCreatureManager;
|
||||
|
||||
public override Camera Cam
|
||||
{
|
||||
get { return cam; }
|
||||
}
|
||||
|
||||
|
||||
public GameScreen(GraphicsDevice graphics, ContentManager content)
|
||||
{
|
||||
cam = new Camera();
|
||||
cam.Translate(new Vector2(-10.0f, 50.0f));
|
||||
|
||||
renderTargetBackground = new RenderTarget2D(graphics, GameMain.GraphicsWidth, GameMain.GraphicsHeight);
|
||||
renderTarget = new RenderTarget2D(graphics, GameMain.GraphicsWidth, GameMain.GraphicsHeight);
|
||||
renderTargetWater = new RenderTarget2D(graphics, GameMain.GraphicsWidth, GameMain.GraphicsHeight);
|
||||
renderTargetAir = new RenderTarget2D(graphics, GameMain.GraphicsWidth, GameMain.GraphicsHeight);
|
||||
renderTargetBackground = new RenderTarget2D(graphics, GameMain.GraphicsWidth, GameMain.GraphicsHeight);
|
||||
renderTarget = new RenderTarget2D(graphics, GameMain.GraphicsWidth, GameMain.GraphicsHeight);
|
||||
renderTargetWater = new RenderTarget2D(graphics, GameMain.GraphicsWidth, GameMain.GraphicsHeight);
|
||||
renderTargetAir = new RenderTarget2D(graphics, GameMain.GraphicsWidth, GameMain.GraphicsHeight);
|
||||
|
||||
var files = GameMain.SelectedPackage.GetFilesOfType(ContentType.BackgroundCreaturePrefabs);
|
||||
if(files.Count > 0)
|
||||
if (files.Count > 0)
|
||||
BackgroundCreatureManager = new BackgroundCreatureManager(files);
|
||||
else
|
||||
BackgroundCreatureManager = new BackgroundCreatureManager("Content/BackgroundSprites/BackgroundCreaturePrefabs.xml");
|
||||
@@ -61,33 +52,7 @@ namespace Barotrauma
|
||||
|
||||
lightBlur = new BlurEffect(blurEffect, 0.001f, 0.001f);
|
||||
}
|
||||
|
||||
public override void Select()
|
||||
{
|
||||
base.Select();
|
||||
|
||||
if (Character.Controlled!=null)
|
||||
{
|
||||
cam.Position = Character.Controlled.WorldPosition;
|
||||
cam.UpdateTransform();
|
||||
}
|
||||
else if (Submarine.MainSub != null)
|
||||
{
|
||||
cam.Position = Submarine.MainSub.WorldPosition;
|
||||
cam.UpdateTransform();
|
||||
}
|
||||
|
||||
foreach (MapEntity entity in MapEntity.mapEntityList)
|
||||
entity.IsHighlighted = false;
|
||||
}
|
||||
|
||||
public override void Deselect()
|
||||
{
|
||||
base.Deselect();
|
||||
|
||||
Sounds.SoundManager.LowPassHFGain = 1.0f;
|
||||
}
|
||||
|
||||
|
||||
public override void AddToGUIUpdateList()
|
||||
{
|
||||
if (Character.Controlled != null && Character.Controlled.SelectedConstruction != null)
|
||||
@@ -103,92 +68,7 @@ namespace Barotrauma
|
||||
Character.AddAllToGUIUpdateList();
|
||||
}
|
||||
|
||||
/// <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)
|
||||
{
|
||||
|
||||
#if DEBUG
|
||||
if (GameMain.GameSession != null && GameMain.GameSession.Level != null && GameMain.GameSession.Submarine != null &&
|
||||
!DebugConsole.IsOpen)
|
||||
{
|
||||
var closestSub = Submarine.FindClosest(cam.WorldViewCenter);
|
||||
if (closestSub == null) closestSub = GameMain.GameSession.Submarine;
|
||||
|
||||
Vector2 targetMovement = Vector2.Zero;
|
||||
if (PlayerInput.KeyDown(Keys.I)) targetMovement.Y += 1.0f;
|
||||
if (PlayerInput.KeyDown(Keys.K)) targetMovement.Y -= 1.0f;
|
||||
if (PlayerInput.KeyDown(Keys.J)) targetMovement.X -= 1.0f;
|
||||
if (PlayerInput.KeyDown(Keys.L)) targetMovement.X += 1.0f;
|
||||
|
||||
if (targetMovement != Vector2.Zero)
|
||||
closestSub.ApplyForce(targetMovement * closestSub.SubBody.Body.Mass * 100.0f);
|
||||
}
|
||||
#endif
|
||||
|
||||
foreach (MapEntity e in MapEntity.mapEntityList)
|
||||
{
|
||||
e.IsHighlighted = false;
|
||||
}
|
||||
|
||||
if (GameMain.GameSession != null) GameMain.GameSession.Update((float)deltaTime);
|
||||
|
||||
if (Level.Loaded != null) Level.Loaded.Update((float)deltaTime);
|
||||
|
||||
if (Character.Controlled != null && Character.Controlled.SelectedConstruction != null)
|
||||
{
|
||||
if (Character.Controlled.SelectedConstruction == Character.Controlled.ClosestItem)
|
||||
{
|
||||
Character.Controlled.SelectedConstruction.UpdateHUD(cam, Character.Controlled);
|
||||
}
|
||||
}
|
||||
Character.UpdateAll(cam, (float)deltaTime);
|
||||
|
||||
BackgroundCreatureManager.Update(cam, (float)deltaTime);
|
||||
|
||||
GameMain.ParticleManager.Update((float)deltaTime);
|
||||
|
||||
StatusEffect.UpdateAll((float)deltaTime);
|
||||
|
||||
if (Character.Controlled != null && Lights.LightManager.ViewTarget != null)
|
||||
{
|
||||
cam.TargetPos = Lights.LightManager.ViewTarget.WorldPosition;
|
||||
}
|
||||
|
||||
GameMain.LightManager.Update((float)deltaTime);
|
||||
cam.MoveCamera((float)deltaTime);
|
||||
|
||||
foreach (Submarine sub in Submarine.Loaded)
|
||||
{
|
||||
sub.SetPrevTransform(sub.Position);
|
||||
}
|
||||
|
||||
foreach (PhysicsBody pb in PhysicsBody.list)
|
||||
{
|
||||
pb.SetPrevTransform(pb.SimPosition, pb.Rotation);
|
||||
}
|
||||
|
||||
MapEntity.UpdateAll(cam, (float)deltaTime);
|
||||
|
||||
Character.UpdateAnimAll((float)deltaTime);
|
||||
|
||||
Ragdoll.UpdateAll(cam, (float)deltaTime);
|
||||
|
||||
foreach (Submarine sub in Submarine.Loaded)
|
||||
{
|
||||
sub.Update((float)deltaTime);
|
||||
}
|
||||
|
||||
GameMain.World.Step((float)deltaTime);
|
||||
|
||||
if (!PlayerInput.LeftButtonHeld())
|
||||
{
|
||||
Inventory.draggingSlot = null;
|
||||
Inventory.draggingItem = null;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Draw(double deltaTime, GraphicsDevice graphics, SpriteBatch spriteBatch)
|
||||
{
|
||||
@@ -222,9 +102,9 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
GUI.Draw((float)deltaTime, spriteBatch, cam);
|
||||
|
||||
|
||||
spriteBatch.End();
|
||||
}
|
||||
|
||||
@@ -251,7 +131,7 @@ namespace Barotrauma
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
||||
graphics.SetRenderTarget(renderTargetBackground);
|
||||
|
||||
|
||||
if (Level.Loaded == null)
|
||||
{
|
||||
graphics.Clear(new Color(11, 18, 26, 255));
|
||||
@@ -367,7 +247,7 @@ namespace Barotrauma
|
||||
Submarine.DrawFront(spriteBatch, false, s => s is Structure);
|
||||
|
||||
spriteBatch.End();
|
||||
|
||||
|
||||
GameMain.LightManager.DrawLOS(spriteBatch, lightBlur.Effect, true);
|
||||
}
|
||||
|
||||
@@ -387,7 +267,7 @@ namespace Barotrauma
|
||||
}
|
||||
|
||||
Hull.renderer.Render(graphics, cam, renderTargetAir, Cam.ShaderTransform);
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
//3. draw the sections of the map that are on top of the water
|
||||
//----------------------------------------------------------------------------------------
|
||||
@@ -398,17 +278,17 @@ namespace Barotrauma
|
||||
cam.Transform);
|
||||
|
||||
Submarine.DrawFront(spriteBatch, false, null);
|
||||
|
||||
|
||||
spriteBatch.End();
|
||||
|
||||
|
||||
spriteBatch.Begin(SpriteSortMode.Immediate,
|
||||
BlendState.NonPremultiplied, SamplerState.LinearWrap,
|
||||
null, null,
|
||||
null, null,
|
||||
damageEffect,
|
||||
cam.Transform);
|
||||
|
||||
Submarine.DrawDamageable(spriteBatch, damageEffect, false);
|
||||
|
||||
|
||||
spriteBatch.End();
|
||||
|
||||
GameMain.LightManager.DrawLightMap(spriteBatch, lightBlur.Effect);
|
||||
@@ -418,22 +298,22 @@ namespace Barotrauma
|
||||
null, null, null,
|
||||
cam.Transform);
|
||||
|
||||
if (Level.Loaded != null) Level.Loaded.DrawFront(spriteBatch);
|
||||
if (Level.Loaded != null) Level.Loaded.DrawFront(spriteBatch);
|
||||
|
||||
foreach (Character c in Character.CharacterList) c.DrawFront(spriteBatch,cam);
|
||||
foreach (Character c in Character.CharacterList) c.DrawFront(spriteBatch, cam);
|
||||
|
||||
spriteBatch.End();
|
||||
|
||||
if (Character.Controlled != null && GameMain.LightManager.LosEnabled)
|
||||
{
|
||||
GameMain.LightManager.DrawLOS(spriteBatch, lightBlur.Effect,false);
|
||||
GameMain.LightManager.DrawLOS(spriteBatch, lightBlur.Effect, false);
|
||||
|
||||
spriteBatch.Begin(SpriteSortMode.Immediate,
|
||||
BlendState.AlphaBlend, SamplerState.LinearWrap, DepthStencilState.None, RasterizerState.CullNone, null);
|
||||
|
||||
float r = Math.Min(CharacterHUD.damageOverlayTimer * 0.5f, 0.5f);
|
||||
spriteBatch.Draw(renderTarget, new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight),
|
||||
Color.Lerp(GameMain.LightManager.AmbientLight*0.5f, Color.Red, r));
|
||||
Color.Lerp(GameMain.LightManager.AmbientLight * 0.5f, Color.Red, r));
|
||||
|
||||
spriteBatch.End();
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ using System.ComponentModel;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
class NetLobbyScreen : Screen
|
||||
partial class NetLobbyScreen : Screen
|
||||
{
|
||||
private GUIFrame menu;
|
||||
private GUIFrame infoFrame;
|
||||
@@ -29,7 +29,7 @@ namespace Barotrauma
|
||||
|
||||
private GUIButton[] missionTypeButtons;
|
||||
private GUIComponent missionTypeBlock;
|
||||
|
||||
|
||||
private GUIListBox jobList;
|
||||
|
||||
private GUITextBox textBox, seedBox;
|
||||
@@ -44,15 +44,6 @@ namespace Barotrauma
|
||||
|
||||
private GUIDropDown shuttleList;
|
||||
|
||||
public bool IsServer;
|
||||
public string ServerName = "Server";
|
||||
|
||||
private UInt16 lastUpdateID;
|
||||
public UInt16 LastUpdateID
|
||||
{
|
||||
get { if (GameMain.Server != null && lastUpdateID < 1) lastUpdateID++; return lastUpdateID; }
|
||||
set { if (GameMain.Server != null) return; lastUpdateID = value; }
|
||||
}
|
||||
|
||||
private Sprite backgroundSprite;
|
||||
|
||||
@@ -115,12 +106,7 @@ namespace Barotrauma
|
||||
set { missionTypeBlock.UserData = value; }
|
||||
}
|
||||
|
||||
//for guitextblock delegate
|
||||
public string GetServerName()
|
||||
{
|
||||
return ServerName;
|
||||
}
|
||||
|
||||
|
||||
public List<JobPrefab> JobPreferences
|
||||
{
|
||||
get
|
||||
@@ -136,8 +122,6 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
private string levelSeed;
|
||||
|
||||
public string LevelSeed
|
||||
{
|
||||
get
|
||||
@@ -154,26 +138,13 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
private float autoRestartTimer;
|
||||
|
||||
public string AutoRestartText()
|
||||
{
|
||||
if (GameMain.Server != null)
|
||||
{
|
||||
if (!GameMain.Server.AutoRestart) return "";
|
||||
return "Restarting in " + ToolBox.SecondsToReadableTime(Math.Max(GameMain.Server.AutoRestartTimer, 0));
|
||||
}
|
||||
|
||||
if (autoRestartTimer == 0.0f) return "";
|
||||
return "Restarting in " + ToolBox.SecondsToReadableTime(Math.Max(autoRestartTimer, 0));
|
||||
}
|
||||
|
||||
public NetLobbyScreen()
|
||||
{
|
||||
int width = Math.Min(GameMain.GraphicsWidth - 80, 1500);
|
||||
int height = Math.Min(GameMain.GraphicsHeight - 80, 800);
|
||||
|
||||
Rectangle panelRect = new Rectangle(0,0,width,height);
|
||||
Rectangle panelRect = new Rectangle(0, 0, width, height);
|
||||
|
||||
menu = new GUIFrame(panelRect, Color.Transparent, Alignment.Center, null);
|
||||
//menu.Padding = GUI.style.smallPadding;
|
||||
@@ -182,7 +153,7 @@ namespace Barotrauma
|
||||
|
||||
infoFrame = new GUIFrame(new Rectangle(0, 0, (int)(panelRect.Width * 0.7f), (int)(panelRect.Height * 0.6f)), "", menu);
|
||||
infoFrame.Padding = new Vector4(20.0f, 20.0f, 20.0f, 20.0f);
|
||||
|
||||
|
||||
//chatbox ----------------------------------------------------------------------
|
||||
GUIFrame chatFrame = new GUIFrame(
|
||||
new Rectangle(0, (int)(panelRect.Height * 0.6f + 20),
|
||||
@@ -191,7 +162,7 @@ namespace Barotrauma
|
||||
"", menu);
|
||||
chatFrame.Padding = new Vector4(20.0f, 20.0f, 20.0f, 40.0f);
|
||||
|
||||
chatBox = new GUIListBox(new Rectangle(0,0,0,chatFrame.Rect.Height-80), Color.White, "", chatFrame);
|
||||
chatBox = new GUIListBox(new Rectangle(0, 0, 0, chatFrame.Rect.Height - 80), Color.White, "", chatFrame);
|
||||
textBox = new GUITextBox(new Rectangle(0, 25, 0, 25), Alignment.Bottom, "", chatFrame);
|
||||
textBox.MaxTextLength = ChatMessage.MaxLength;
|
||||
textBox.Font = GUI.SmallFont;
|
||||
@@ -213,7 +184,7 @@ namespace Barotrauma
|
||||
|
||||
playerListFrame.Padding = new Vector4(20.0f, 20.0f, 20.0f, 40.0f);
|
||||
|
||||
playerList = new GUIListBox(new Rectangle(0,0,0,0), null, "", playerListFrame);
|
||||
playerList = new GUIListBox(new Rectangle(0, 0, 0, 0), null, "", playerListFrame);
|
||||
playerList.OnSelected = SelectPlayer;
|
||||
|
||||
//submarine list ------------------------------------------------------------------
|
||||
@@ -238,14 +209,14 @@ namespace Barotrauma
|
||||
|
||||
new GUITextBlock(new Rectangle(columnX, 120, 20, 20), "Respawn shuttle:", "", infoFrame);
|
||||
shuttleList = new GUIDropDown(new Rectangle(columnX, 150, 200, 20), "", "", infoFrame);
|
||||
|
||||
|
||||
|
||||
//gamemode ------------------------------------------------------------------
|
||||
|
||||
new GUITextBlock(new Rectangle(columnX, 180, 0, 30), "Game mode: ", "", infoFrame);
|
||||
modeList = new GUIListBox(new Rectangle(columnX, 200, columnWidth, infoFrame.Rect.Height - 300), "", infoFrame);
|
||||
modeList.OnSelected = VotableClicked;
|
||||
|
||||
|
||||
voteText = new GUITextBlock(new Rectangle(columnX, 120, columnWidth, 30), "Votes: ", "", Alignment.TopLeft, Alignment.TopRight, infoFrame);
|
||||
voteText.UserData = "modevotes";
|
||||
voteText.Visible = false;
|
||||
@@ -263,13 +234,13 @@ namespace Barotrauma
|
||||
textBlock.Padding = new Vector4(10.0f, 0.0f, 0.0f, 0.0f);
|
||||
textBlock.UserData = mode;
|
||||
}
|
||||
|
||||
|
||||
//mission type ------------------------------------------------------------------
|
||||
|
||||
missionTypeBlock = new GUITextBlock(new Rectangle(columnX, -10, 300, 20), "Mission type:", "", Alignment.BottomLeft, Alignment.CenterLeft, infoFrame);
|
||||
missionTypeBlock.Padding = Vector4.Zero;
|
||||
missionTypeBlock.UserData = 0;
|
||||
|
||||
|
||||
missionTypeButtons = new GUIButton[2];
|
||||
|
||||
missionTypeButtons[0] = new GUIButton(new Rectangle(100, 0, 20, 20), "<", Alignment.BottomLeft, "", missionTypeBlock);
|
||||
@@ -279,13 +250,13 @@ namespace Barotrauma
|
||||
|
||||
missionTypeButtons[1] = new GUIButton(new Rectangle(200, 0, 20, 20), ">", Alignment.BottomLeft, "", missionTypeBlock);
|
||||
missionTypeButtons[1].UserData = 1;
|
||||
|
||||
|
||||
missionTypeBlock.Visible = false;
|
||||
|
||||
columnX += columnWidth + 20;
|
||||
|
||||
//gamemode description ------------------------------------------------------------------
|
||||
|
||||
|
||||
//var modeDescription = new GUITextBlock(
|
||||
// new Rectangle(columnX, 150, (int)(columnWidth * 1.2f), infoFrame.Rect.Height - 150 - 80),
|
||||
// "", "", Alignment.TopLeft, Alignment.TopLeft, infoFrame, true, GUI.SmallFont);
|
||||
@@ -296,11 +267,11 @@ namespace Barotrauma
|
||||
//columnX += modeDescription.Rect.Width + 20;
|
||||
|
||||
//seed ------------------------------------------------------------------
|
||||
|
||||
|
||||
new GUITextBlock(new Rectangle(columnX, 120, 180, 20),
|
||||
"Level Seed: ", "", Alignment.Left, Alignment.TopLeft, infoFrame);
|
||||
|
||||
seedBox = new GUITextBox(new Rectangle(columnX, 150, columnWidth/2, 20),
|
||||
seedBox = new GUITextBox(new Rectangle(columnX, 150, columnWidth / 2, 20),
|
||||
Alignment.TopLeft, "", infoFrame);
|
||||
seedBox.OnTextChanged = SelectSeed;
|
||||
LevelSeed = ToolBox.RandomSeed(8);
|
||||
@@ -314,7 +285,7 @@ namespace Barotrauma
|
||||
traitorProbabilityButtons[0] = new GUIButton(new Rectangle(columnX, 205, 20, 20), "<", "", infoFrame);
|
||||
traitorProbabilityButtons[0].UserData = -1;
|
||||
|
||||
traitorProbabilityText = new GUITextBlock(new Rectangle(columnX+20, 205, 80, 20), "No", null,null, Alignment.Center, "", infoFrame);
|
||||
traitorProbabilityText = new GUITextBlock(new Rectangle(columnX + 20, 205, 80, 20), "No", null, null, Alignment.Center, "", infoFrame);
|
||||
|
||||
traitorProbabilityButtons[1] = new GUIButton(new Rectangle(columnX + 100, 205, 20, 20), ">", "", infoFrame);
|
||||
traitorProbabilityButtons[1].UserData = 1;
|
||||
@@ -330,7 +301,7 @@ namespace Barotrauma
|
||||
restartText.TextGetter = AutoRestartText;
|
||||
|
||||
//server info ------------------------------------------------------------------
|
||||
|
||||
|
||||
var serverName = new GUITextBox(new Rectangle(0, 0, 200, 20), null, null, Alignment.TopLeft, Alignment.TopLeft, "", infoFrame);
|
||||
serverName.TextGetter = GetServerName;
|
||||
serverName.Enabled = GameMain.Server != null;
|
||||
@@ -339,7 +310,7 @@ namespace Barotrauma
|
||||
serverMessage = new GUITextBox(new Rectangle(0, 30, 360, 70), null, null, Alignment.TopLeft, Alignment.TopLeft, "", infoFrame);
|
||||
serverMessage.Wrap = true;
|
||||
serverMessage.OnTextChanged = UpdateServerMessage;
|
||||
|
||||
|
||||
var showLogButton = new GUIButton(new Rectangle(0, 0, 100, 20), "Server Log", Alignment.TopRight, "", infoFrame);
|
||||
showLogButton.UserData = "showlog";
|
||||
showLogButton.OnClicked = (GUIButton button, object userData) =>
|
||||
@@ -367,22 +338,22 @@ namespace Barotrauma
|
||||
if (GameMain.NetworkMember == null) return;
|
||||
|
||||
GameMain.LightManager.LosEnabled = false;
|
||||
|
||||
|
||||
textBox.Select();
|
||||
|
||||
|
||||
textBox.OnEnterPressed = GameMain.NetworkMember.EnterChatMessage;
|
||||
textBox.OnTextChanged = GameMain.NetworkMember.TypingChatMessage;
|
||||
|
||||
Character.Controlled = null;
|
||||
//GameMain.GameScreen.Cam.TargetPos = Vector2.Zero;
|
||||
|
||||
subList.Enabled = GameMain.Server != null || GameMain.NetworkMember.Voting.AllowSubVoting;
|
||||
shuttleList.Enabled = subList.Enabled;
|
||||
subList.Enabled = GameMain.Server != null || GameMain.NetworkMember.Voting.AllowSubVoting;
|
||||
shuttleList.Enabled = subList.Enabled;
|
||||
//playerList.Enabled = GameMain.Server != null;
|
||||
modeList.Enabled = GameMain.Server != null || GameMain.NetworkMember.Voting.AllowModeVoting;
|
||||
seedBox.Enabled = GameMain.Server != null;
|
||||
serverMessage.Enabled = GameMain.Server != null;
|
||||
autoRestartBox.Enabled = GameMain.Server != null;
|
||||
modeList.Enabled = GameMain.Server != null || GameMain.NetworkMember.Voting.AllowModeVoting;
|
||||
seedBox.Enabled = GameMain.Server != null;
|
||||
serverMessage.Enabled = GameMain.Server != null;
|
||||
autoRestartBox.Enabled = GameMain.Server != null;
|
||||
|
||||
traitorProbabilityButtons[0].Enabled = GameMain.Server != null;
|
||||
traitorProbabilityButtons[1].Enabled = GameMain.Server != null;
|
||||
@@ -434,7 +405,7 @@ namespace Barotrauma
|
||||
if (shuttleList.Selected == null)
|
||||
{
|
||||
var shuttles = shuttleList.GetChildren().FindAll(c => c.UserData is Submarine && ((Submarine)c.UserData).HasTag(SubmarineTag.Shuttle));
|
||||
if (prevSelectedShuttle==-1 && shuttles.Any())
|
||||
if (prevSelectedShuttle == -1 && shuttles.Any())
|
||||
{
|
||||
shuttleList.SelectItem(shuttles[0].UserData);
|
||||
}
|
||||
@@ -542,9 +513,9 @@ namespace Barotrauma
|
||||
int i = 1;
|
||||
foreach (JobPrefab job in JobPrefab.List)
|
||||
{
|
||||
GUITextBlock jobText = new GUITextBlock(new Rectangle(0, 0, 0, 20), i + ". " + job.Name+" ",
|
||||
"",Alignment.Left, Alignment.Right, jobList, false,
|
||||
GameMain.GraphicsWidth<1000 ? GUI.SmallFont : GUI.Font);
|
||||
GUITextBlock jobText = new GUITextBlock(new Rectangle(0, 0, 0, 20), i + ". " + job.Name + " ",
|
||||
"", Alignment.Left, Alignment.Right, jobList, false,
|
||||
GameMain.GraphicsWidth < 1000 ? GUI.SmallFont : GUI.Font);
|
||||
jobText.UserData = job;
|
||||
|
||||
GUIButton infoButton = new GUIButton(new Rectangle(0, 2, 15, 15), "?", "", jobText);
|
||||
@@ -554,12 +525,12 @@ namespace Barotrauma
|
||||
GUIButton upButton = new GUIButton(new Rectangle(30, 2, 15, 15), "", "", jobText);
|
||||
//TODO: make GUIImages align correctly when scaled/rotated
|
||||
//so there's no need to do this ↓
|
||||
new GUIImage(new Rectangle(3,2,0,0), GUI.Arrow, Alignment.Center, upButton).Scale = 0.6f;
|
||||
new GUIImage(new Rectangle(3, 2, 0, 0), GUI.Arrow, Alignment.Center, upButton).Scale = 0.6f;
|
||||
upButton.UserData = -1;
|
||||
upButton.OnClicked += ChangeJobPreference;
|
||||
|
||||
GUIButton downButton = new GUIButton(new Rectangle(50, 2, 15, 15), "", "", jobText);
|
||||
var downArrow = new GUIImage(new Rectangle(13,14,0,0), GUI.Arrow, Alignment.Center, downButton);
|
||||
var downArrow = new GUIImage(new Rectangle(13, 14, 0, 0), GUI.Arrow, Alignment.Center, downButton);
|
||||
downArrow.Rotation = MathHelper.Pi;
|
||||
downArrow.Scale = 0.6f;
|
||||
|
||||
@@ -606,7 +577,7 @@ namespace Barotrauma
|
||||
private bool ToggleAutoRestart(GUITickBox tickBox)
|
||||
{
|
||||
if (GameMain.Server == null) return false;
|
||||
|
||||
|
||||
GameMain.Server.AutoRestart = tickBox.Selected;
|
||||
|
||||
lastUpdateID++;
|
||||
@@ -629,8 +600,8 @@ namespace Barotrauma
|
||||
int missionTypeIndex = (int)missionTypeBlock.UserData;
|
||||
missionTypeIndex += (int)userData;
|
||||
|
||||
if (missionTypeIndex<0) missionTypeIndex = Mission.MissionTypes.Count-1;
|
||||
if (missionTypeIndex>=Mission.MissionTypes.Count) missionTypeIndex=0;
|
||||
if (missionTypeIndex < 0) missionTypeIndex = Mission.MissionTypes.Count - 1;
|
||||
if (missionTypeIndex >= Mission.MissionTypes.Count) missionTypeIndex = 0;
|
||||
|
||||
SetMissionType(missionTypeIndex);
|
||||
|
||||
@@ -641,39 +612,10 @@ namespace Barotrauma
|
||||
|
||||
public bool ToggleTraitorsEnabled(GUIButton button, object userData)
|
||||
{
|
||||
if (GameMain.Server == null) return false;
|
||||
|
||||
lastUpdateID++;
|
||||
|
||||
int dir = (int)userData;
|
||||
|
||||
int index = (int)GameMain.Server.TraitorsEnabled + dir;
|
||||
if (index < 0) index = 2;
|
||||
if (index > 2) index = 0;
|
||||
|
||||
SetTraitorsEnabled((YesNoMaybe)index);
|
||||
|
||||
|
||||
ToggleTraitorsEnabled((int)userData);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void SetTraitorsEnabled(YesNoMaybe enabled)
|
||||
{
|
||||
if (GameMain.Server != null) GameMain.Server.TraitorsEnabled = enabled;
|
||||
(traitorProbabilityText as GUITextBlock).Text = enabled.ToString();
|
||||
}
|
||||
|
||||
public List<Submarine> GetSubList()
|
||||
{
|
||||
List<Submarine> subs = new List<Submarine>();
|
||||
foreach (GUIComponent component in subList.children)
|
||||
{
|
||||
if (component.UserData is Submarine) subs.Add((Submarine)component.UserData);
|
||||
}
|
||||
|
||||
return subs;
|
||||
}
|
||||
|
||||
|
||||
private bool SelectSub(GUIComponent component, object obj)
|
||||
{
|
||||
if (GameMain.Server == null) return false;
|
||||
@@ -681,14 +623,14 @@ namespace Barotrauma
|
||||
lastUpdateID++;
|
||||
|
||||
var hash = obj is Submarine ? ((Submarine)obj).MD5Hash.Hash : "";
|
||||
|
||||
|
||||
//hash will be null if opening the sub file failed -> don't select the sub
|
||||
if (string.IsNullOrWhiteSpace(hash))
|
||||
{
|
||||
(component as GUITextBlock).TextColor = Color.DarkRed * 0.8f;
|
||||
component.CanBeFocused = false;
|
||||
|
||||
StartButton.Enabled = false;
|
||||
|
||||
StartButton.Enabled = false;
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -708,7 +650,7 @@ namespace Barotrauma
|
||||
{
|
||||
DebugConsole.ThrowError("No submarines found!");
|
||||
}
|
||||
|
||||
|
||||
foreach (Submarine sub in submarines)
|
||||
{
|
||||
AddSubmarine(subList, sub);
|
||||
@@ -755,8 +697,7 @@ namespace Barotrauma
|
||||
shuttleText.ToolTip = subTextBlock.ToolTip;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public bool VotableClicked(GUIComponent component, object userData)
|
||||
{
|
||||
if (GameMain.Client == null) return false;
|
||||
@@ -803,7 +744,7 @@ namespace Barotrauma
|
||||
public void AddPlayer(string name)
|
||||
{
|
||||
GUITextBlock textBlock = new GUITextBlock(
|
||||
new Rectangle(0, 0, playerList.Rect.Width-20, 25), name,
|
||||
new Rectangle(0, 0, playerList.Rect.Width - 20, 25), name,
|
||||
"", Alignment.Left, Alignment.Left,
|
||||
playerList);
|
||||
|
||||
@@ -868,25 +809,25 @@ namespace Barotrauma
|
||||
permissionTick.Selected = selectedClient.HasPermission(permission);
|
||||
|
||||
permissionTick.OnSelected = (tickBox) =>
|
||||
{
|
||||
var client = tickBox.Parent.UserData as Client;
|
||||
if (client == null) return false;
|
||||
{
|
||||
var client = tickBox.Parent.UserData as Client;
|
||||
if (client == null) return false;
|
||||
|
||||
var thisPermission = (ClientPermissions)tickBox.UserData;
|
||||
var thisPermission = (ClientPermissions)tickBox.UserData;
|
||||
|
||||
if (tickBox.Selected)
|
||||
client.GivePermission(thisPermission);
|
||||
else
|
||||
client.RemovePermission(thisPermission);
|
||||
if (tickBox.Selected)
|
||||
client.GivePermission(thisPermission);
|
||||
else
|
||||
client.RemovePermission(thisPermission);
|
||||
|
||||
GameMain.Server.UpdateClientPermissions(client);
|
||||
GameMain.Server.UpdateClientPermissions(client);
|
||||
|
||||
return true;
|
||||
};
|
||||
return true;
|
||||
};
|
||||
|
||||
|
||||
y += 20;
|
||||
if (y >= permissionsBox.Rect.Height-40)
|
||||
if (y >= permissionsBox.Rect.Height - 40)
|
||||
{
|
||||
y = 0;
|
||||
x += 100;
|
||||
@@ -932,15 +873,15 @@ namespace Barotrauma
|
||||
{
|
||||
if (userData == null) return false;
|
||||
|
||||
if (GameMain.Server!=null)
|
||||
if (GameMain.Server != null)
|
||||
{
|
||||
GameMain.Server.KickPlayer(userData.ToString(), false);
|
||||
}
|
||||
else if (GameMain.Client != null && GameMain.Client.HasPermission(ClientPermissions.Kick))
|
||||
{
|
||||
GameMain.Client.KickPlayer(userData.ToString(), false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1000,11 +941,22 @@ namespace Barotrauma
|
||||
menu.AddToGUIUpdateList();
|
||||
}
|
||||
}
|
||||
|
||||
public List<Submarine> GetSubList()
|
||||
{
|
||||
List<Submarine> subs = new List<Submarine>();
|
||||
foreach (GUIComponent component in subList.children)
|
||||
{
|
||||
if (component.UserData is Submarine) subs.Add((Submarine)component.UserData);
|
||||
}
|
||||
|
||||
return subs;
|
||||
}
|
||||
|
||||
public override void Update(double deltaTime)
|
||||
{
|
||||
base.Update(deltaTime);
|
||||
|
||||
|
||||
if (jobInfoFrame != null)
|
||||
{
|
||||
jobInfoFrame.Update((float)deltaTime);
|
||||
@@ -1023,28 +975,27 @@ namespace Barotrauma
|
||||
autoRestartTimer = Math.Max(autoRestartTimer - (float)deltaTime, 0.0f);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Draw(double deltaTime, GraphicsDevice graphics, SpriteBatch spriteBatch)
|
||||
{
|
||||
graphics.Clear(Color.Black);
|
||||
|
||||
|
||||
spriteBatch.Begin(SpriteSortMode.Immediate, null, null, null, GameMain.ScissorTestEnable);
|
||||
|
||||
if (backgroundSprite!=null)
|
||||
if (backgroundSprite != null)
|
||||
{
|
||||
spriteBatch.Draw(backgroundSprite.Texture, Vector2.Zero, null, Color.White, 0.0f, Vector2.Zero,
|
||||
Math.Max((float)GameMain.GraphicsWidth / backgroundSprite.SourceRect.Width, (float)GameMain.GraphicsHeight / backgroundSprite.SourceRect.Height),
|
||||
Math.Max((float)GameMain.GraphicsWidth / backgroundSprite.SourceRect.Width, (float)GameMain.GraphicsHeight / backgroundSprite.SourceRect.Height),
|
||||
SpriteEffects.None, 0.0f);
|
||||
}
|
||||
|
||||
menu.Draw(spriteBatch);
|
||||
|
||||
|
||||
if (jobInfoFrame != null) jobInfoFrame.Draw(spriteBatch);
|
||||
|
||||
//if (previewPlayer!=null) previewPlayer.Draw(spriteBatch);
|
||||
|
||||
if (playerFrame != null) playerFrame.Draw(spriteBatch);
|
||||
|
||||
|
||||
GUI.Draw((float)deltaTime, spriteBatch, null);
|
||||
|
||||
spriteBatch.End();
|
||||
@@ -1058,10 +1009,10 @@ namespace Barotrauma
|
||||
{
|
||||
chatBox.RemoveChild(chatBox.children[1]);
|
||||
}
|
||||
|
||||
GUITextBlock msg = new GUITextBlock(new Rectangle(0, 0, chatBox.Rect.Width-20, 0),
|
||||
message.TextWithSender,
|
||||
((chatBox.CountChildren % 2) == 0) ? Color.Transparent : Color.Black*0.1f, message.Color,
|
||||
|
||||
GUITextBlock msg = new GUITextBlock(new Rectangle(0, 0, chatBox.Rect.Width - 20, 0),
|
||||
message.TextWithSender,
|
||||
((chatBox.CountChildren % 2) == 0) ? Color.Transparent : Color.Black * 0.1f, message.Color,
|
||||
Alignment.Left, Alignment.TopLeft, "", null, true, GUI.SmallFont);
|
||||
msg.UserData = message;
|
||||
msg.CanBeFocused = false;
|
||||
@@ -1098,7 +1049,7 @@ namespace Barotrauma
|
||||
{
|
||||
Gender gender = (Gender)obj;
|
||||
GameMain.NetworkMember.CharacterInfo.Gender = gender;
|
||||
|
||||
|
||||
UpdatePreviewPlayer(GameMain.NetworkMember.CharacterInfo);
|
||||
return true;
|
||||
}
|
||||
@@ -1107,7 +1058,7 @@ namespace Barotrauma
|
||||
{
|
||||
modeList.Select(modeIndex, true);
|
||||
|
||||
missionTypeBlock.Visible = SelectedMode != null && SelectedMode.Name == "Mission";
|
||||
missionTypeBlock.Visible = SelectedMode != null && SelectedMode.Name == "Mission";
|
||||
}
|
||||
|
||||
private bool SelectMode(GUIComponent component, object obj)
|
||||
@@ -1128,7 +1079,6 @@ namespace Barotrauma
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private bool SelectSeed(GUITextBox textBox, string seed)
|
||||
{
|
||||
if (GameMain.Server == null) return false;
|
||||
@@ -1167,7 +1117,7 @@ namespace Barotrauma
|
||||
if (jobPrefab == null) return false;
|
||||
|
||||
jobInfoFrame = jobPrefab.CreateInfoFrame();
|
||||
GUIButton closeButton = new GUIButton(new Rectangle(0,0,100,20), "Close", Alignment.BottomRight, "", jobInfoFrame.children[0]);
|
||||
GUIButton closeButton = new GUIButton(new Rectangle(0, 0, 100, 20), "Close", Alignment.BottomRight, "", jobInfoFrame.children[0]);
|
||||
closeButton.OnClicked = CloseJobInfo;
|
||||
return true;
|
||||
}
|
||||
@@ -1209,9 +1159,9 @@ namespace Barotrauma
|
||||
listBox.children[i].HoverColor = color;
|
||||
listBox.children[i].SelectedColor = color;
|
||||
|
||||
(listBox.children[i] as GUITextBlock).Text = (i+1) + ". " + (listBox.children[i].UserData as JobPrefab).Name;
|
||||
(listBox.children[i] as GUITextBlock).Text = (i + 1) + ". " + (listBox.children[i].UserData as JobPrefab).Name;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public bool TrySelectSub(string subName, string md5Hash, GUIListBox subList)
|
||||
@@ -1260,7 +1210,7 @@ namespace Barotrauma
|
||||
//already showing a message about the same sub
|
||||
if (GUIMessageBox.MessageBoxes.Any(mb => mb.UserData as string == "request" + subName))
|
||||
{
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
var requestFileBox = new GUIMessageBox("Submarine not found!", errorMsg, new string[] { "Yes", "No" }, 400, 300);
|
||||
@@ -1268,18 +1218,18 @@ namespace Barotrauma
|
||||
requestFileBox.Buttons[0].UserData = new string[] { subName, md5Hash };
|
||||
requestFileBox.Buttons[0].OnClicked += requestFileBox.Close;
|
||||
requestFileBox.Buttons[0].OnClicked += (GUIButton button, object userdata) =>
|
||||
{
|
||||
string[] fileInfo = (string[])userdata;
|
||||
GameMain.Client.RequestFile(FileTransferType.Submarine, fileInfo[0], fileInfo[1]);
|
||||
return true;
|
||||
};
|
||||
{
|
||||
string[] fileInfo = (string[])userdata;
|
||||
GameMain.Client.RequestFile(FileTransferType.Submarine, fileInfo[0], fileInfo[1]);
|
||||
return true;
|
||||
};
|
||||
requestFileBox.Buttons[1].OnClicked += requestFileBox.Close;
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,42 +5,12 @@ using System.Collections.Generic;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
class Screen
|
||||
partial class Screen
|
||||
{
|
||||
private static Screen selected;
|
||||
|
||||
public static Screen Selected
|
||||
{
|
||||
get { return selected; }
|
||||
}
|
||||
|
||||
public virtual void Deselect()
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void Select()
|
||||
{
|
||||
if (selected != null && selected != this)
|
||||
{
|
||||
selected.Deselect();
|
||||
GUIComponent.KeyboardDispatcher.Subscriber = null;
|
||||
}
|
||||
selected = this;
|
||||
}
|
||||
|
||||
public virtual Camera Cam
|
||||
{
|
||||
get { return null; }
|
||||
}
|
||||
|
||||
public virtual void AddToGUIUpdateList()
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void Update(double deltaTime)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void Draw(double deltaTime, GraphicsDevice graphics, SpriteBatch spriteBatch)
|
||||
{
|
||||
}
|
||||
@@ -94,6 +64,5 @@ namespace Barotrauma
|
||||
GUI.Arrow.Draw(spriteBatch, iconPos + arrowOffset, color, MathUtils.VectorToAngle(arrowOffset) + MathHelper.PiOver2);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,130 +7,15 @@ using System.Xml.Linq;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
public class Sprite
|
||||
public partial class Sprite
|
||||
{
|
||||
static List<Sprite> list = new List<Sprite>();
|
||||
//the file from which the texture is loaded
|
||||
//if two sprites use the same file, they share the same texture
|
||||
string file;
|
||||
|
||||
protected Texture2D texture;
|
||||
|
||||
//the area in the texture that is supposed to be drawn
|
||||
Rectangle sourceRect;
|
||||
|
||||
//the offset used when drawing the sprite
|
||||
protected Vector2 offset;
|
||||
|
||||
protected Vector2 origin;
|
||||
|
||||
//the size of the drawn sprite, if larger than the source,
|
||||
//the sprite is tiled to fill the target size
|
||||
public Vector2 size;
|
||||
|
||||
public float rotation;
|
||||
|
||||
public SpriteEffects effects;
|
||||
|
||||
protected float depth;
|
||||
|
||||
public Rectangle SourceRect
|
||||
{
|
||||
get { return sourceRect; }
|
||||
set { sourceRect = value; }
|
||||
}
|
||||
|
||||
public float Depth
|
||||
{
|
||||
get { return depth; }
|
||||
set { depth = MathHelper.Clamp(value, 0.0f, 1.0f); }
|
||||
}
|
||||
|
||||
public Vector2 Origin
|
||||
{
|
||||
get { return origin; }
|
||||
set { origin = value; }
|
||||
}
|
||||
|
||||
public Texture2D Texture
|
||||
{
|
||||
get { return texture; }
|
||||
}
|
||||
|
||||
public string FilePath
|
||||
{
|
||||
get { return file; }
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return FilePath + ": " + sourceRect;
|
||||
}
|
||||
|
||||
public Sprite(XElement element, string path = "", string file = "")
|
||||
{
|
||||
if (file == "")
|
||||
{
|
||||
file = ToolBox.GetAttributeString(element, "texture", "");
|
||||
}
|
||||
|
||||
if (file == "")
|
||||
{
|
||||
DebugConsole.ThrowError("Sprite " + element + " doesn't have a texture specified!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(path))
|
||||
{
|
||||
if (!path.EndsWith("/")) path += "/";
|
||||
}
|
||||
|
||||
this.file = path + file;
|
||||
|
||||
texture = LoadTexture(this.file);
|
||||
|
||||
if (texture == null) return;
|
||||
|
||||
Vector4 sourceVector = ToolBox.GetAttributeVector4(element, "sourcerect", Vector4.Zero);
|
||||
|
||||
if (sourceVector.Z == 0.0f) sourceVector.Z = texture.Width;
|
||||
if (sourceVector.W == 0.0f) sourceVector.W = texture.Height;
|
||||
|
||||
sourceRect = new Rectangle(
|
||||
(int)sourceVector.X, (int)sourceVector.Y,
|
||||
(int)sourceVector.Z, (int)sourceVector.W);
|
||||
|
||||
origin = ToolBox.GetAttributeVector2(element, "origin", new Vector2(0.5f, 0.5f));
|
||||
origin.X = origin.X * sourceRect.Width;
|
||||
origin.Y = origin.Y * sourceRect.Height;
|
||||
|
||||
size = ToolBox.GetAttributeVector2(element, "size", Vector2.One);
|
||||
size.X *= sourceRect.Width;
|
||||
size.Y *= sourceRect.Height;
|
||||
|
||||
Depth = ToolBox.GetAttributeFloat(element, "depth", 0.0f);
|
||||
|
||||
list.Add(this);
|
||||
}
|
||||
|
||||
public Sprite(string newFile, Vector2 newOrigin)
|
||||
{
|
||||
file = newFile;
|
||||
texture = LoadTexture(file);
|
||||
|
||||
if (texture == null) return;
|
||||
|
||||
sourceRect = new Rectangle(0, 0, texture.Width, texture.Height);
|
||||
|
||||
size = new Vector2(sourceRect.Width, sourceRect.Height);
|
||||
|
||||
origin = new Vector2((float)texture.Width * newOrigin.X, (float)texture.Height * newOrigin.Y);
|
||||
|
||||
effects = SpriteEffects.None;
|
||||
|
||||
list.Add(this);
|
||||
}
|
||||
|
||||
public Sprite(Texture2D texture, Rectangle? sourceRectangle, Vector2? newOffset, float newRotation = 0.0f)
|
||||
{
|
||||
this.texture = texture;
|
||||
@@ -150,51 +35,53 @@ namespace Barotrauma
|
||||
list.Add(this);
|
||||
}
|
||||
|
||||
public Sprite(string newFile, Rectangle? sourceRectangle, Vector2? newOffset, float newRotation = 0.0f)
|
||||
private void LoadTexture(ref Vector4 sourceVector,ref bool shouldReturn)
|
||||
{
|
||||
file = newFile;
|
||||
texture = LoadTexture(file);
|
||||
texture = LoadTexture(this.file);
|
||||
|
||||
sourceRect = sourceRectangle ?? new Rectangle(0, 0, texture.Width, texture.Height);
|
||||
|
||||
offset = newOffset ?? Vector2.Zero;
|
||||
|
||||
size = new Vector2(sourceRect.Width, sourceRect.Height);
|
||||
if (texture == null)
|
||||
{
|
||||
shouldReturn = true;
|
||||
return;
|
||||
}
|
||||
|
||||
origin = Vector2.Zero;
|
||||
|
||||
rotation = newRotation;
|
||||
|
||||
list.Add(this);
|
||||
if (sourceVector.Z == 0.0f) sourceVector.Z = texture.Width;
|
||||
if (sourceVector.W == 0.0f) sourceVector.W = texture.Height;
|
||||
}
|
||||
|
||||
|
||||
private void CalculateSourceRect()
|
||||
{
|
||||
sourceRect = new Rectangle(0, 0, texture.Width, texture.Height);
|
||||
}
|
||||
|
||||
|
||||
public static Texture2D LoadTexture(string file)
|
||||
{
|
||||
foreach (Sprite s in list)
|
||||
{
|
||||
if (s.file == file) return s.texture;
|
||||
if (s.file == file) return s.texture;
|
||||
}
|
||||
|
||||
|
||||
if (File.Exists(file))
|
||||
{
|
||||
return TextureLoader.FromFile(file);
|
||||
}
|
||||
else
|
||||
{
|
||||
DebugConsole.ThrowError("Sprite \""+file+"\" not found!");
|
||||
DebugConsole.ThrowError("Sprite \"" + file + "\" not found!");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void Draw(SpriteBatch spriteBatch, Vector2 pos, float rotate=0.0f, float scale=1.0f, SpriteEffects spriteEffect = SpriteEffects.None)
|
||||
public void Draw(SpriteBatch spriteBatch, Vector2 pos, float rotate = 0.0f, float scale = 1.0f, SpriteEffects spriteEffect = SpriteEffects.None)
|
||||
{
|
||||
this.Draw(spriteBatch, pos, Color.White, rotate, scale, spriteEffect);
|
||||
}
|
||||
|
||||
public void Draw(SpriteBatch spriteBatch, Vector2 pos, Color color, float rotate = 0.0f, float scale = 1.0f, SpriteEffects spriteEffect = SpriteEffects.None, float? depth = null)
|
||||
{
|
||||
this.Draw(spriteBatch, pos, color, this.origin, rotate, new Vector2(scale,scale), spriteEffect, depth);
|
||||
this.Draw(spriteBatch, pos, color, this.origin, rotate, new Vector2(scale, scale), spriteEffect, depth);
|
||||
}
|
||||
|
||||
public void Draw(SpriteBatch spriteBatch, Vector2 pos, Color color, Vector2 origin, float rotate = 0.0f, float scale = 1.0f, SpriteEffects spriteEffect = SpriteEffects.None, float? depth = null)
|
||||
@@ -217,12 +104,12 @@ namespace Barotrauma
|
||||
|
||||
spriteBatch.Draw(texture, pos + offset, sourceRect, color, rotation + rotate, origin, scale, spriteEffect, depth == null ? this.depth : (float)depth);
|
||||
}
|
||||
|
||||
|
||||
public void DrawTiled(SpriteBatch spriteBatch, Vector2 pos, Vector2 targetSize, Color color)
|
||||
{
|
||||
DrawTiled(spriteBatch, pos, targetSize, Vector2.Zero, color);
|
||||
}
|
||||
|
||||
|
||||
public void DrawTiled(SpriteBatch spriteBatch, Vector2 pos, Vector2 targetSize, Color color, Point offset, float? overrideDepth = null)
|
||||
{
|
||||
//how many times the texture needs to be drawn on the x-axis
|
||||
@@ -242,12 +129,12 @@ namespace Barotrauma
|
||||
|
||||
float top = pos.Y;
|
||||
texPerspective.Height = (int)Math.Min(targetSize.Y, sourceRect.Height);
|
||||
|
||||
|
||||
for (int y = 0; y < yTiles; y++)
|
||||
{
|
||||
var movementY = texPerspective.Height;
|
||||
texPerspective.Height = Math.Min((int)(targetSize.Y - texPerspective.Height * y), texPerspective.Height);
|
||||
|
||||
|
||||
float left = pos.X;
|
||||
texPerspective.Width = (int)Math.Min(targetSize.X, sourceRect.Width);
|
||||
|
||||
@@ -303,16 +190,16 @@ namespace Barotrauma
|
||||
{
|
||||
DrawTiled(spriteBatch, pos, targetSize, startOffset, sourceRect, color);
|
||||
}
|
||||
|
||||
|
||||
public void DrawTiled(SpriteBatch spriteBatch, Vector2 pos, Vector2 targetSize, Vector2 startOffset, Rectangle sourceRect, Color color)
|
||||
{
|
||||
//pos.X = (int)pos.X;
|
||||
//pos.Y = (int)pos.Y;
|
||||
|
||||
//how many times the texture needs to be drawn on the x-axis
|
||||
int xTiles = (int)Math.Ceiling((targetSize.X+startOffset.X) / sourceRect.Width);
|
||||
int xTiles = (int)Math.Ceiling((targetSize.X + startOffset.X) / sourceRect.Width);
|
||||
//how many times the texture needs to be drawn on the y-axis
|
||||
int yTiles = (int)Math.Ceiling((targetSize.Y+startOffset.Y) / sourceRect.Height);
|
||||
int yTiles = (int)Math.Ceiling((targetSize.Y + startOffset.Y) / sourceRect.Height);
|
||||
|
||||
Vector2 position = pos - startOffset;
|
||||
Rectangle drawRect = sourceRect;
|
||||
@@ -372,13 +259,10 @@ namespace Barotrauma
|
||||
|
||||
position.X += sourceRect.Width;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void Remove()
|
||||
private void DisposeTexture()
|
||||
{
|
||||
list.Remove(this);
|
||||
|
||||
//check if another sprite is using the same texture
|
||||
foreach (Sprite s in list)
|
||||
{
|
||||
@@ -392,7 +276,6 @@ namespace Barotrauma
|
||||
texture = null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -34,6 +34,7 @@
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="MonoGame.Framework, Version=3.5.1.1679, Culture=neutral, processorArchitecture=MSIL" />
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
@@ -44,11 +45,31 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="GameMain.cs" />
|
||||
<Compile Include="PlayerInput.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Farseer Physics Engine 3.5\Farseer Physics MonoGame.csproj">
|
||||
<Project>{0aad36e3-51a5-4a07-ab60-5c8a66bd38b7}</Project>
|
||||
<Name>Farseer Physics MonoGame</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Hyper.ComponentModel\Hyper.ComponentModel.csproj">
|
||||
<Project>{3b8f9edb-6e5e-450c-abc2-ec49075d0b50}</Project>
|
||||
<Name>Hyper.ComponentModel</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Lidgren.Network\Lidgren.Network.csproj">
|
||||
<Project>{49ba1c69-6104-41ac-a5d8-b54fa9f696e8}</Project>
|
||||
<Name>Lidgren.Network</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="NewFolder1\" />
|
||||
</ItemGroup>
|
||||
<Import Project="..\BarotraumaShared\BarotraumaShared.projitems" Label="Shared" />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
|
||||
12
BarotraumaServer/BarotraumaServer.csproj.rej
Normal file
@@ -0,0 +1,12 @@
|
||||
diff a/BarotraumaServer/BarotraumaServer.csproj b/BarotraumaServer/BarotraumaServer.csproj (rejected hunks)
|
||||
@@ -34,6 +34,10 @@
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
+ <Reference Include="MonoGame.Framework, Version=3.5.1.1679, Culture=neutral, processorArchitecture=MSIL" />
|
||||
+ <Reference Include="RestSharp">
|
||||
+ <HintPath>..\packages\RestSharp.105.2.3\lib\net45\RestSharp.dll</HintPath>
|
||||
+ </Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
235
BarotraumaServer/Source/Camera.cs
Normal file
@@ -0,0 +1,235 @@
|
||||
using System;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
using System.Linq;
|
||||
//TODO: this class still does things that the server doesn't need, cleanup
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
public class Camera
|
||||
{
|
||||
public static bool FollowSub = true;
|
||||
|
||||
const float DefaultZoom = 1.0f;
|
||||
const float ZoomSmoothness = 8.0f;
|
||||
const float MoveSmoothness = 8.0f;
|
||||
|
||||
private float zoom;
|
||||
|
||||
private float offsetAmount;
|
||||
|
||||
private Matrix transform, shaderTransform, viewMatrix;
|
||||
private Vector2 position;
|
||||
private float rotation;
|
||||
|
||||
private Vector2 prevPosition;
|
||||
private float prevZoom;
|
||||
|
||||
public float Shake;
|
||||
private Vector2 shakePosition;
|
||||
private Vector2 shakeTargetPosition;
|
||||
|
||||
//the area of the world inside the camera view
|
||||
private Rectangle worldView;
|
||||
|
||||
private Point resolution;
|
||||
|
||||
private Vector2 targetPos;
|
||||
|
||||
public float Zoom
|
||||
{
|
||||
get { return zoom; }
|
||||
set
|
||||
{
|
||||
zoom = value;
|
||||
|
||||
Vector2 center = WorldViewCenter;
|
||||
float newWidth = resolution.X / zoom;
|
||||
float newHeight = resolution.Y / zoom;
|
||||
|
||||
worldView = new Rectangle(
|
||||
(int)(center.X - newWidth / 2.0f),
|
||||
(int)(center.Y + newHeight / 2.0f),
|
||||
(int)newWidth,
|
||||
(int)newHeight);
|
||||
|
||||
//UpdateTransform();
|
||||
}
|
||||
}
|
||||
|
||||
public float Rotation
|
||||
{
|
||||
get { return rotation; }
|
||||
set { rotation = value; }
|
||||
}
|
||||
|
||||
public float OffsetAmount
|
||||
{
|
||||
get { return offsetAmount; }
|
||||
set { offsetAmount = value; }
|
||||
}
|
||||
|
||||
public Point Resolution
|
||||
{
|
||||
get { return resolution; }
|
||||
}
|
||||
|
||||
public Rectangle WorldView
|
||||
{
|
||||
get { return worldView; }
|
||||
}
|
||||
|
||||
public Vector2 WorldViewCenter
|
||||
{
|
||||
get
|
||||
{
|
||||
return new Vector2(
|
||||
worldView.X + worldView.Width / 2.0f,
|
||||
worldView.Y - worldView.Height / 2.0f);
|
||||
}
|
||||
}
|
||||
|
||||
public Matrix Transform
|
||||
{
|
||||
get { return transform; }
|
||||
}
|
||||
|
||||
public Matrix ShaderTransform
|
||||
{
|
||||
get { return shaderTransform; }
|
||||
}
|
||||
|
||||
public Camera()
|
||||
{
|
||||
zoom = 1.0f;
|
||||
rotation = 0.0f;
|
||||
position = Vector2.Zero;
|
||||
|
||||
worldView = new Rectangle(0,0,
|
||||
1,
|
||||
1);
|
||||
|
||||
resolution = new Point(1,1);
|
||||
|
||||
viewMatrix =
|
||||
Matrix.CreateTranslation(new Vector3(0.5f, 0.5f, 0));
|
||||
|
||||
UpdateTransform();
|
||||
}
|
||||
|
||||
public Vector2 TargetPos
|
||||
{
|
||||
get { return targetPos; }
|
||||
set { targetPos = value; }
|
||||
}
|
||||
|
||||
// Auxiliary function to move the camera
|
||||
public void Translate(Vector2 amount)
|
||||
{
|
||||
position += amount;
|
||||
|
||||
}
|
||||
|
||||
public void UpdateTransform(bool interpolate = true, bool clampPos = false)
|
||||
{
|
||||
Vector2 interpolatedPosition = interpolate ? Timing.Interpolate(prevPosition, position) : position;
|
||||
|
||||
float interpolatedZoom = interpolate ? Timing.Interpolate(prevZoom, zoom) : zoom;
|
||||
|
||||
worldView.X = (int)(interpolatedPosition.X - worldView.Width / 2.0);
|
||||
worldView.Y = (int)(interpolatedPosition.Y + worldView.Height / 2.0);
|
||||
|
||||
if (Level.Loaded != null && clampPos)
|
||||
{
|
||||
position.Y -= Math.Max(worldView.Y - Level.Loaded.Size.Y, 0.0f);
|
||||
interpolatedPosition.Y -= Math.Max(worldView.Y - Level.Loaded.Size.Y, 0.0f);
|
||||
|
||||
worldView.Y = Math.Min((int)Level.Loaded.Size.Y, worldView.Y);
|
||||
}
|
||||
|
||||
transform = Matrix.CreateTranslation(
|
||||
new Vector3(-interpolatedPosition.X, interpolatedPosition.Y, 0)) *
|
||||
Matrix.CreateScale(new Vector3(interpolatedZoom, interpolatedZoom, 1)) *
|
||||
viewMatrix;
|
||||
|
||||
shaderTransform = Matrix.CreateTranslation(
|
||||
new Vector3(
|
||||
-interpolatedPosition.X - resolution.X / interpolatedZoom / 2.0f,
|
||||
-interpolatedPosition.Y - resolution.Y / interpolatedZoom / 2.0f, 0)) *
|
||||
Matrix.CreateScale(new Vector3(interpolatedZoom, interpolatedZoom, 1)) *
|
||||
viewMatrix;
|
||||
|
||||
if (!interpolate)
|
||||
{
|
||||
prevPosition = position;
|
||||
prevZoom = zoom;
|
||||
}
|
||||
}
|
||||
|
||||
public void MoveCamera(float deltaTime, bool allowMove = true, bool allowZoom = true)
|
||||
{
|
||||
prevPosition = position;
|
||||
prevZoom = zoom;
|
||||
|
||||
float moveSpeed = 20.0f/zoom;
|
||||
|
||||
Vector2 moveCam = Vector2.Zero;
|
||||
if (targetPos == Vector2.Zero)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
Vector2 mousePos = PlayerInput.MousePosition;
|
||||
|
||||
Vector2 offset = mousePos - new Vector2(resolution.X / 2.0f, resolution.Y / 2.0f);
|
||||
|
||||
offset.X = offset.X / (resolution.X * 0.4f);
|
||||
offset.Y = -offset.Y / (resolution.Y * 0.3f);
|
||||
|
||||
if (offset.Length() > 1.0f) offset.Normalize();
|
||||
|
||||
offset = offset * offsetAmount;
|
||||
|
||||
float newZoom = Math.Min(DefaultZoom - Math.Min(offset.Length() / resolution.Y, 1.0f),1.0f);
|
||||
Zoom += (newZoom - zoom) / ZoomSmoothness;
|
||||
|
||||
Vector2 diff = (targetPos + offset) - position;
|
||||
|
||||
moveCam = diff / MoveSmoothness;
|
||||
}
|
||||
|
||||
shakeTargetPosition = Rand.Vector(Shake);
|
||||
shakePosition = Vector2.Lerp(shakePosition, shakeTargetPosition, 0.5f);
|
||||
Shake = MathHelper.Lerp(Shake, 0.0f, deltaTime * 2.0f);
|
||||
|
||||
Translate(moveCam + shakePosition);
|
||||
}
|
||||
|
||||
public Vector2 Position
|
||||
{
|
||||
get { return position; }
|
||||
set
|
||||
{
|
||||
if (!MathUtils.IsValid(value))
|
||||
{
|
||||
return;
|
||||
}
|
||||
position = value;
|
||||
}
|
||||
}
|
||||
|
||||
public Vector2 ScreenToWorld(Vector2 coords)
|
||||
{
|
||||
Vector2 worldCoords = Vector2.Transform(coords, Matrix.Invert(transform));
|
||||
return new Vector2(worldCoords.X, -worldCoords.Y);
|
||||
}
|
||||
|
||||
public Vector2 WorldToScreen(Vector2 coords)
|
||||
{
|
||||
coords.Y = -coords.Y;
|
||||
//Vector2 screenCoords = Vector2.Transform(coords, transform);
|
||||
return Vector2.Transform(coords, transform);
|
||||
}
|
||||
}
|
||||
}
|
||||
35
BarotraumaServer/Source/GameMain.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Reflection;
|
||||
using FarseerPhysics;
|
||||
using FarseerPhysics.Dynamics;
|
||||
using Barotrauma.Networking;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.Xna.Framework;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
class GameMain
|
||||
{
|
||||
public static World World;
|
||||
|
||||
public static GameServer Server;
|
||||
|
||||
public static GameSession GameSession;
|
||||
|
||||
public static GameClient Client
|
||||
{
|
||||
get { return null; }
|
||||
}
|
||||
|
||||
public static NetworkMember NetworkMember
|
||||
{
|
||||
get { return Server as NetworkMember; }
|
||||
}
|
||||
|
||||
public static Screen EditMapScreen
|
||||
{
|
||||
get { return null; }
|
||||
}
|
||||
}
|
||||
}
|
||||
19
BarotraumaServer/Source/Networking/GameClient.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using Lidgren.Network;
|
||||
using Microsoft.Xna.Framework;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
|
||||
namespace Barotrauma.Networking
|
||||
{
|
||||
class GameClient : NetworkMember
|
||||
{
|
||||
public GameClient(string newName)
|
||||
{
|
||||
throw new Exception("Tried to create GameClient in dedicated server build");
|
||||
}
|
||||
}
|
||||
}
|
||||
134
BarotraumaServer/Source/PlayerInput.cs
Normal file
@@ -0,0 +1,134 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
public static class PlayerInput
|
||||
{
|
||||
public static Keys selectKey = Keys.E;
|
||||
|
||||
public static Vector2 MousePosition
|
||||
{
|
||||
get { return Vector2.Zero; }
|
||||
}
|
||||
|
||||
public static Vector2 LatestMousePosition
|
||||
{
|
||||
get { return Vector2.Zero; }
|
||||
}
|
||||
|
||||
//public static MouseState GetMouseState
|
||||
//{
|
||||
// get { return mouseState; }
|
||||
//}
|
||||
//public static MouseState GetOldMouseState
|
||||
//{
|
||||
// get { return oldMouseState; }
|
||||
//}
|
||||
|
||||
public static bool MouseInsideWindow
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public static Vector2 MouseSpeed
|
||||
{
|
||||
get
|
||||
{
|
||||
return Vector2.Zero;
|
||||
}
|
||||
}
|
||||
|
||||
public static KeyboardState GetKeyboardState
|
||||
{
|
||||
get { return new KeyboardState(); }
|
||||
}
|
||||
|
||||
public static KeyboardState GetOldKeyboardState
|
||||
{
|
||||
get { return new KeyboardState(); }
|
||||
}
|
||||
|
||||
public static int ScrollWheelSpeed
|
||||
{
|
||||
get { return 0; }
|
||||
|
||||
}
|
||||
|
||||
public static bool LeftButtonHeld()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool LeftButtonDown()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool LeftButtonReleased()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public static bool LeftButtonClicked()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool RightButtonHeld()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool RightButtonClicked()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool DoubleClicked()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool KeyHit(InputType inputType)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool KeyDown(InputType inputType)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool KeyUp(InputType inputType)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool KeyHit(Keys button)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool KeyDown(Keys button)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool KeyUp(Keys button)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void Update(double deltaTime)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public static void UpdateVariable()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
174
BarotraumaServer/Source/Program.cs
Normal file
@@ -0,0 +1,174 @@
|
||||
#region Using Statements
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
|
||||
#if WINDOWS
|
||||
using System.Management;
|
||||
using System.Windows.Forms;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
#endif
|
||||
|
||||
#endregion
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
#if WINDOWS || LINUX
|
||||
/// <summary>
|
||||
/// The main class.
|
||||
/// </summary>
|
||||
public static class Program
|
||||
{
|
||||
private static int restartAttempts;
|
||||
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
using (var game = new GameMain())
|
||||
{
|
||||
#if DEBUG
|
||||
game.Run();
|
||||
#else
|
||||
bool attemptRestart = false;
|
||||
|
||||
do
|
||||
{
|
||||
try
|
||||
{
|
||||
game.Run();
|
||||
attemptRestart = false;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if (restartAttempts < 5 && CheckException(game, e))
|
||||
{
|
||||
attemptRestart = true;
|
||||
restartAttempts++;
|
||||
}
|
||||
else
|
||||
{
|
||||
CrashDump(game, "crashreport.txt", e);
|
||||
attemptRestart = false;
|
||||
}
|
||||
|
||||
}
|
||||
} while (attemptRestart);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
private static bool CheckException(GameMain game, Exception e)
|
||||
{
|
||||
#if WINDOWS
|
||||
|
||||
if (e is SharpDX.SharpDXException)
|
||||
{
|
||||
switch ((uint)((SharpDX.SharpDXException)e).ResultCode.Code)
|
||||
{
|
||||
case 0x887A0022: //DXGI_ERROR_NOT_CURRENTLY_AVAILABLE
|
||||
switch (restartAttempts)
|
||||
{
|
||||
case 0:
|
||||
//just wait and try again
|
||||
System.Threading.Thread.Sleep(100);
|
||||
return true;
|
||||
case 1:
|
||||
//force focus to this window
|
||||
var myForm = (System.Windows.Forms.Form)System.Windows.Forms.Form.FromHandle(game.Window.Handle);
|
||||
myForm.Focus();
|
||||
return true;
|
||||
case 2:
|
||||
//try disabling hardware mode switch
|
||||
if (GameMain.Config.WindowMode == WindowMode.Fullscreen)
|
||||
{
|
||||
DebugConsole.NewMessage("Failed to set fullscreen mode, switching configuration to borderless windowed", Microsoft.Xna.Framework.Color.Red);
|
||||
GameMain.Config.WindowMode = WindowMode.BorderlessWindowed;
|
||||
GameMain.Config.Save("config.xml");
|
||||
}
|
||||
return false;
|
||||
default:
|
||||
return false;
|
||||
|
||||
}
|
||||
case 0x80070057: //E_INVALIDARG/Invalid Arguments
|
||||
DebugConsole.NewMessage("Invalid graphics settings, attempting to fix", Microsoft.Xna.Framework.Color.Red);
|
||||
|
||||
GameMain.Config.GraphicsWidth = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width;
|
||||
GameMain.Config.GraphicsHeight = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height;
|
||||
game.ApplyGraphicsSettings();
|
||||
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void CrashMessageBox(string message)
|
||||
{
|
||||
#if WINDOWS
|
||||
MessageBox.Show(message, "Oops! Barotrauma just crashed.", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void CrashDump(GameMain game, string filePath, Exception exception)
|
||||
{
|
||||
StreamWriter sw = new StreamWriter(filePath);
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.AppendLine("Barotrauma crash report (generated on " + DateTime.Now + ")");
|
||||
sb.AppendLine("\n");
|
||||
sb.AppendLine("Barotrauma seems to have crashed. Sorry for the inconvenience! ");
|
||||
sb.AppendLine("If you'd like to help fix the bug that caused the crash, please send this file to the developers on the Undertow Games forums.");
|
||||
sb.AppendLine("\n");
|
||||
sb.AppendLine("Game version " + GameMain.Version);
|
||||
sb.AppendLine("Graphics mode: " + GameMain.Config.GraphicsWidth + "x" + GameMain.Config.GraphicsHeight + " (" + GameMain.Config.WindowMode.ToString() + ")");
|
||||
sb.AppendLine("Selected content package: " + GameMain.SelectedPackage.Name);
|
||||
sb.AppendLine("Level seed: " + ((Level.Loaded == null) ? "no level loaded" : Level.Loaded.Seed));
|
||||
sb.AppendLine("Loaded submarine: " + ((Submarine.MainSub == null) ? "None" : Submarine.MainSub.Name + " (" + Submarine.MainSub.MD5Hash + ")"));
|
||||
sb.AppendLine("Selected screen: " + (Screen.Selected == null ? "None" : Screen.Selected.ToString()));
|
||||
|
||||
if (GameMain.Server != null)
|
||||
{
|
||||
sb.AppendLine("Server (" + (GameMain.Server.GameStarted ? "Round had started)" : "Round hadn't been started)"));
|
||||
}
|
||||
else if (GameMain.Client != null)
|
||||
{
|
||||
sb.AppendLine("Client (" + (GameMain.Client.GameStarted ? "Round had started)" : "Round hadn't been started)"));
|
||||
}
|
||||
|
||||
sb.AppendLine("\n");
|
||||
sb.AppendLine("System info:");
|
||||
sb.AppendLine(" Operating system: " + System.Environment.OSVersion + (System.Environment.Is64BitOperatingSystem ? " 64 bit" : " x86"));
|
||||
sb.AppendLine("\n");
|
||||
sb.AppendLine("Exception: "+exception.Message);
|
||||
sb.AppendLine("Target site: " +exception.TargetSite.ToString());
|
||||
sb.AppendLine("Stack trace: ");
|
||||
sb.AppendLine(exception.StackTrace);
|
||||
sb.AppendLine("\n");
|
||||
|
||||
sb.AppendLine("Last debug messages:");
|
||||
for (int i = DebugConsole.Messages.Count - 1; i > 0 && i > DebugConsole.Messages.Count - 15; i-- )
|
||||
{
|
||||
sb.AppendLine(" "+DebugConsole.Messages[i].Time+" - "+DebugConsole.Messages[i].Text);
|
||||
}
|
||||
|
||||
|
||||
sw.WriteLine(sb.ToString());
|
||||
sw.Close();
|
||||
|
||||
CrashMessageBox( "A crash report (\"crashreport.txt\") was saved in the root folder of the game."+
|
||||
" If you'd like to help fix this bug, please post the report on the Undertow Games forums.");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
25
BarotraumaServer/Source/Sprite/Sprite.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Xna.Framework;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
public partial class Sprite
|
||||
{
|
||||
private void LoadTexture(ref Vector4 sourceVector,ref bool shouldReturn)
|
||||
{
|
||||
//do nothing
|
||||
}
|
||||
|
||||
private void CalculateSourceRect()
|
||||
{
|
||||
//do nothing
|
||||
}
|
||||
|
||||
private void DisposeTexture()
|
||||
{
|
||||
//do nothing
|
||||
}
|
||||
|
Before Width: | Height: | Size: 70 KiB After Width: | Height: | Size: 70 KiB |
|
Before Width: | Height: | Size: 917 KiB After Width: | Height: | Size: 917 KiB |
|
Before Width: | Height: | Size: 1.1 MiB After Width: | Height: | Size: 1.1 MiB |
|
Before Width: | Height: | Size: 1.2 MiB After Width: | Height: | Size: 1.2 MiB |
|
Before Width: | Height: | Size: 1.2 MiB After Width: | Height: | Size: 1.2 MiB |
|
Before Width: | Height: | Size: 1.0 MiB After Width: | Height: | Size: 1.0 MiB |
|
Before Width: | Height: | Size: 903 KiB After Width: | Height: | Size: 903 KiB |
|
Before Width: | Height: | Size: 597 KiB After Width: | Height: | Size: 597 KiB |
|
Before Width: | Height: | Size: 609 KiB After Width: | Height: | Size: 609 KiB |
|
Before Width: | Height: | Size: 404 KiB After Width: | Height: | Size: 404 KiB |
|
Before Width: | Height: | Size: 34 KiB After Width: | Height: | Size: 34 KiB |
|
Before Width: | Height: | Size: 1005 KiB After Width: | Height: | Size: 1005 KiB |
|
Before Width: | Height: | Size: 188 KiB After Width: | Height: | Size: 188 KiB |
|
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 4.8 KiB After Width: | Height: | Size: 4.8 KiB |
|
Before Width: | Height: | Size: 3.6 KiB After Width: | Height: | Size: 3.6 KiB |
|
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 2.2 KiB |
|
Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 1.9 KiB |
|
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 2.4 KiB |
|
Before Width: | Height: | Size: 2.3 KiB After Width: | Height: | Size: 2.3 KiB |
|
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 2.1 KiB |
|
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 2.1 KiB |
|
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
|
Before Width: | Height: | Size: 6.8 KiB After Width: | Height: | Size: 6.8 KiB |
|
Before Width: | Height: | Size: 5.8 KiB After Width: | Height: | Size: 5.8 KiB |
|
Before Width: | Height: | Size: 6.4 KiB After Width: | Height: | Size: 6.4 KiB |
|
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 2.0 KiB |
|
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.7 KiB |
|
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 2.2 KiB |
|
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 2.1 KiB |
|
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 2.0 KiB |
|
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 2.0 KiB |
|
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 2.0 KiB |
|
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 1.9 KiB |
|
Before Width: | Height: | Size: 7.2 KiB After Width: | Height: | Size: 7.2 KiB |
|
Before Width: | Height: | Size: 6.6 KiB After Width: | Height: | Size: 6.6 KiB |
|
Before Width: | Height: | Size: 6.7 KiB After Width: | Height: | Size: 6.7 KiB |