Merge remote-tracking branch 'barotrauma/master' into new-netcode

# Conflicts:
#	Subsurface/Source/Characters/Character.cs
#	Subsurface/Source/Items/Components/Machines/Steering.cs
#	Subsurface/Source/Map/Structure.cs
#	Subsurface/Source/Networking/GameClient.cs
#	Subsurface/Source/Networking/GameServer.cs
This commit is contained in:
juanjp600
2016-11-05 18:09:44 -03:00
42 changed files with 431 additions and 177 deletions

View File

@@ -22,7 +22,7 @@ namespace Barotrauma.Items.Components
public Deconstructor(Item item, XElement element)
: base(item, element)
{
progressBar = new GUIProgressBar(new Rectangle(0,0,200,20), Color.Green, 0.0f, Alignment.BottomCenter, GuiFrame);
progressBar = new GUIProgressBar(new Rectangle(0,0,200,20), Color.Green, GUI.Style, 0.0f, Alignment.BottomCenter, GuiFrame);
activateButton = new GUIButton(new Rectangle(0, 0, 200, 20), "Deconstruct", Alignment.TopCenter, GUI.Style, GuiFrame);
activateButton.OnClicked = ToggleActive;

View File

@@ -91,6 +91,10 @@ namespace Barotrauma.Items.Components
private FabricableItem fabricatedItem;
private float timeUntilReady;
//used for checking if contained items have changed
//(in which case we need to recheck which items can be fabricated)
private Item[] prevContainedItems;
private float lastNetworkUpdate;
public Fabricator(Item item, XElement element)
@@ -110,7 +114,6 @@ namespace Barotrauma.Items.Components
itemList = new GUIListBox(new Rectangle(0,0,GuiFrame.Rect.Width/2-20,0), GUI.Style, GuiFrame);
itemList.OnSelected = SelectItem;
//structureList.CheckSelected = MapEntityPrefab.GetSelected;
foreach (FabricableItem fi in fabricableItems)
{
@@ -131,6 +134,7 @@ namespace Barotrauma.Items.Components
Color.Transparent, Color.White,
Alignment.Left, Alignment.Left,
null, frame);
textBlock.ToolTip = fi.TargetItem.Description;
textBlock.Padding = new Vector4(5.0f, 0.0f, 5.0f, 0.0f);
if (fi.TargetItem.sprite != null)
@@ -138,6 +142,7 @@ namespace Barotrauma.Items.Components
GUIImage img = new GUIImage(new Rectangle(0, 0, 40, 40), fi.TargetItem.sprite, Alignment.Left, frame);
img.Scale = Math.Min(Math.Min(40.0f / img.SourceRect.Width, 40.0f / img.SourceRect.Height), 1.0f);
img.Color = fi.TargetItem.SpriteColor;
img.ToolTip = fi.TargetItem.Description;
}
}
@@ -151,7 +156,7 @@ namespace Barotrauma.Items.Components
if (selectedItemFrame != null) GuiFrame.RemoveChild(selectedItemFrame);
//int width = 200, height = 150;
selectedItemFrame = new GUIFrame(new Rectangle(0, 0, (int)(GuiFrame.Rect.Width * 0.4f), 250), Color.Black * 0.8f, Alignment.CenterY | Alignment.Right, null, GuiFrame);
selectedItemFrame = new GUIFrame(new Rectangle(0, 0, (int)(GuiFrame.Rect.Width * 0.4f), 300), Color.Black * 0.8f, Alignment.CenterY | Alignment.Right, null, GuiFrame);
selectedItemFrame.Padding = new Vector4(10.0f, 10.0f, 10.0f, 10.0f);
@@ -160,6 +165,8 @@ namespace Barotrauma.Items.Components
if (targetItem.TargetItem.sprite != null)
{
int y = 0;
GUIImage img = new GUIImage(new Rectangle(10, 0, 40, 40), targetItem.TargetItem.sprite, Alignment.TopLeft, selectedItemFrame);
img.Scale = Math.Min(Math.Min(40.0f / img.SourceRect.Width, 40.0f / img.SourceRect.Height), 1.0f);
img.Color = targetItem.TargetItem.SpriteColor;
@@ -172,12 +179,24 @@ namespace Barotrauma.Items.Components
Alignment.TopLeft, null,
selectedItemFrame, true);
y += 40;
if (!string.IsNullOrWhiteSpace(targetItem.TargetItem.Description))
{
var description = new GUITextBlock(
new Rectangle(0, y, 0, 0),
targetItem.TargetItem.Description,
GUI.Style, Alignment.TopLeft, Alignment.TopLeft,
selectedItemFrame, true, GUI.SmallFont);
y += description.Rect.Height + 10;
}
List<Skill> inadequateSkills = new List<Skill>();
if (Character.Controlled != null)
{
inadequateSkills = targetItem.RequiredSkills.FindAll(skill => Character.Controlled.GetSkillLevel(skill.Name) < skill.Level);
}
@@ -204,7 +223,7 @@ namespace Barotrauma.Items.Components
}
new GUITextBlock(
new Rectangle(0, 50, 0, 25),
new Rectangle(0, y, 0, 25),
text,
Color.Transparent, textColor,
Alignment.TopLeft,
@@ -222,11 +241,13 @@ namespace Barotrauma.Items.Components
public override bool Select(Character character)
{
CheckFabricableItems(character);
if (itemList.Selected != null)
{
SelectItem(itemList.Selected, itemList.Selected.UserData);
SelectItem(itemList.Selected, itemList.Selected.UserData);
}
return base.Select(character);
}
@@ -235,6 +256,30 @@ namespace Barotrauma.Items.Components
return (picker != null);
}
/// <summary>
/// check which of the items can be fabricated by the character
/// and update the text colors of the item list accordingly
/// </summary>
private void CheckFabricableItems(Character character)
{
foreach (GUIComponent child in itemList.children)
{
var itemPrefab = child.UserData as FabricableItem;
if (itemPrefab == null) continue;
bool canBeFabricated = CanBeFabricated(itemPrefab, character);
child.GetChild<GUITextBlock>().TextColor = Color.White * (canBeFabricated ? 1.0f : 0.5f);
child.GetChild<GUIImage>().Color = itemPrefab.TargetItem.SpriteColor * (canBeFabricated ? 1.0f : 0.5f);
}
var itemContainer = item.GetComponent<ItemContainer>();
prevContainedItems = new Item[itemContainer.Inventory.Items.Length];
itemContainer.Inventory.Items.CopyTo(prevContainedItems, 0);
}
private bool StartButtonClicked(GUIButton button, object obj)
{
if (fabricatedItem == null)
@@ -344,6 +389,30 @@ namespace Barotrauma.Items.Components
activateButton.Enabled = CanBeFabricated(targetItem, character);
}
if (character != null)
{
bool itemsChanged = false;
if (prevContainedItems == null)
{
itemsChanged = true;
}
else
{
var itemContainer = item.GetComponent<ItemContainer>();
for (int i = 0; i < itemContainer.Inventory.Items.Length; i++)
{
if (prevContainedItems[i] != itemContainer.Inventory.Items[i])
{
itemsChanged = true;
break;
}
}
}
if (itemsChanged) CheckFabricableItems(character);
}
GuiFrame.Update((float)Timing.Step);
}

View File

@@ -20,10 +20,7 @@ namespace Barotrauma.Items.Components
private List<RadarBlip> radarBlips;
private float prevPingRadius;
public static string StartMarker = "Start";
public static string EndMarker = "End";
[HasDefaultValue(10000.0f, false)]
public float Range
{
@@ -265,11 +262,11 @@ namespace Barotrauma.Items.Components
DrawMarker(spriteBatch,
(GameMain.GameSession.Map == null) ? StartMarker : GameMain.GameSession.Map.CurrentLocation.Name,
GameMain.GameSession.StartLocation.Name,
(Level.Loaded.StartPosition - item.WorldPosition), displayScale, center, (rect.Width * 0.5f));
DrawMarker(spriteBatch,
(GameMain.GameSession.Map == null) ? EndMarker : GameMain.GameSession.Map.SelectedLocation.Name,
GameMain.GameSession.EndLocation.Name,
(Level.Loaded.EndPosition - item.WorldPosition), displayScale, center, (rect.Width * 0.5f));
if (GameMain.GameSession.Mission != null)
@@ -397,12 +394,15 @@ namespace Barotrauma.Items.Components
if (dir.X < 0.0f) markerPos.X -= GUI.SmallFont.MeasureString(label).X+10;
GUI.DrawString(spriteBatch, new Vector2(markerPos.X + 10, markerPos.Y), label, Color.LightGreen * textAlpha, Color.Black * textAlpha*0.5f, 2, GUI.SmallFont);
string wrappedLabel = ToolBox.WrapText(label, 150, GUI.SmallFont);
GUI.DrawString(spriteBatch, new Vector2(markerPos.X + 10, markerPos.Y + 15), (int)(dist * Physics.DisplayToRealWorldRatio) + " m",
Color.LightGreen * textAlpha,
Color.Black * textAlpha, 2, GUI.SmallFont);
wrappedLabel += "\n"+((int)(dist * Physics.DisplayToRealWorldRatio) + " m");
GUI.DrawString(spriteBatch,
new Vector2(markerPos.X + 10, markerPos.Y),
wrappedLabel,
Color.LightGreen * textAlpha, Color.Black * textAlpha * 0.5f,
2, GUI.SmallFont);
}
protected override void RemoveComponentSpecific()

View File

@@ -19,7 +19,8 @@ namespace Barotrauma.Items.Components
private Vector2 targetVelocity;
private GUITickBox autopilotTickBox, maintainPosTickBox;
private GUITickBox levelEndTickBox, levelStartTickBox;
private bool autoPilot;
private Vector2? posToMaintain;
@@ -47,21 +48,23 @@ namespace Barotrauma.Items.Components
if (value == autoPilot) return;
autoPilot = value;
autopilotTickBox.Selected = value;
maintainPosTickBox.Enabled = autoPilot;
levelEndTickBox.Enabled = autoPilot;
levelStartTickBox.Enabled = autoPilot;
if (autoPilot)
{
if (pathFinder==null) pathFinder = new PathFinder(WayPoint.WayPointList, false);
steeringPath = pathFinder.FindPath(
ConvertUnits.ToSimUnits(item.WorldPosition),
TargetPosition == null ? ConvertUnits.ToSimUnits(Level.Loaded.EndPosition) : (Vector2)TargetPosition);
if (pathFinder == null) pathFinder = new PathFinder(WayPoint.WayPointList, false);
ToggleMaintainPosition(maintainPosTickBox);
}
else
{
maintainPosTickBox.Selected = false;
levelEndTickBox.Selected = false;
levelStartTickBox.Selected = false;
posToMaintain = null;
}
}
@@ -114,15 +117,28 @@ namespace Barotrauma.Items.Components
return true;
};
maintainPosTickBox = new GUITickBox(new Rectangle(0, 50, 20, 20), "Maintain position", Alignment.TopLeft, GuiFrame);
maintainPosTickBox = new GUITickBox(new Rectangle(5, 50, 15, 15), "Maintain position", Alignment.TopLeft, GUI.SmallFont, GuiFrame);
maintainPosTickBox.Enabled = false;
maintainPosTickBox.OnSelected = ToggleMaintainPosition;
levelStartTickBox = new GUITickBox(
new Rectangle(5, 70, 15, 15),
GameMain.GameSession == null ? "" : ToolBox.LimitString(GameMain.GameSession.StartLocation.Name, 20),
Alignment.TopLeft, GUI.SmallFont, GuiFrame);
levelStartTickBox.Enabled = false;
levelStartTickBox.OnSelected = SelectDestination;
levelEndTickBox = new GUITickBox(
new Rectangle(5, 90, 15, 15),
GameMain.GameSession == null ? "" : ToolBox.LimitString(GameMain.GameSession.StartLocation.Name, 20),
Alignment.TopLeft, GUI.SmallFont, GuiFrame);
levelEndTickBox.Enabled = false;
levelEndTickBox.OnSelected = SelectDestination;
}
public override void Update(float deltaTime, Camera cam)
{
//base.Update(deltaTime, cam);
if (valueChanged)
{
networkUpdateTimer -= deltaTime;
@@ -331,6 +347,28 @@ namespace Barotrauma.Items.Components
}
private void UpdatePath()
{
Vector2 target;
if (TargetPosition != null)
{
target = (Vector2)TargetPosition;
}
else
{
if (levelEndTickBox.Selected)
{
target = ConvertUnits.ToSimUnits(Level.Loaded.EndPosition);
}
else
{
target = ConvertUnits.ToSimUnits(Level.Loaded.StartPosition);
}
}
steeringPath = pathFinder.FindPath(ConvertUnits.ToSimUnits(item.WorldPosition), target);
}
private void SteerTowardsPosition(Vector2 worldPosition)
{
float prediction = 10.0f;
@@ -345,7 +383,7 @@ namespace Barotrauma.Items.Components
}
else
{
TargetVelocity = targetSpeed/5.0f;
TargetVelocity = targetSpeed / 5.0f;
}
}
@@ -353,21 +391,42 @@ namespace Barotrauma.Items.Components
{
valueChanged = true;
if (tickBox.Selected)
{
if (item.Submarine == null)
{
posToMaintain = null;
}
else
{
posToMaintain = item.Submarine.WorldPosition;
}
}
else
levelStartTickBox.Selected = false;
levelEndTickBox.Selected = false;
if (item.Submarine == null)
{
posToMaintain = null;
}
else
{
posToMaintain = item.Submarine.WorldPosition;
}
tickBox.Selected = true;
return true;
}
private bool SelectDestination(GUITickBox tickBox)
{
valueChanged = true;
if (tickBox == levelStartTickBox)
{
levelEndTickBox.Selected = false;
}
else
{
levelStartTickBox.Selected = false;
}
maintainPosTickBox.Selected = false;
posToMaintain = null;
UpdatePath();
tickBox.Selected = true;
return true;
}
@@ -397,6 +456,16 @@ namespace Barotrauma.Items.Components
else
{
msg.Write(posToMaintain != null);
message.Write(posToMaintain != null);
if (posToMaintain != null)
{
message.Write(((Vector2)posToMaintain).X);
message.Write(((Vector2)posToMaintain).Y);
}
else
{
message.Write(levelStartTickBox.Selected);
}
}
}
@@ -420,6 +489,17 @@ namespace Barotrauma.Items.Components
{
posToMaintain = null;
maintainPosTickBox.Selected = false;
bool maintainPos = message.ReadBoolean();
if (maintainPos)
{
newPosToMaintain = new Vector2(
message.ReadFloat(),
message.ReadFloat());
}
else
{
headingToStart = message.ReadBoolean();
}
}
}
}
@@ -467,6 +547,22 @@ namespace Barotrauma.Items.Components
maintainPosTickBox.Selected = false;
}
}
maintainPosTickBox.Selected = newPosToMaintain != null;
posToMaintain = newPosToMaintain;
if (posToMaintain == null && autoPilot)
{
levelStartTickBox.Selected = headingToStart;
levelEndTickBox.Selected = !headingToStart;
UpdatePath();
}
else
{
levelStartTickBox.Selected = false;
levelEndTickBox.Selected = false;
}
}
}
}