Picking items from outside the sub, replcaed fabricator.png with separate sprites for each machine, descriptions moved from itemprefab to the mapentityprefab base class, editortutorial progress

This commit is contained in:
Regalis
2016-01-15 17:10:21 +02:00
parent 0fc085c86d
commit e3ebc28afb
34 changed files with 203 additions and 78 deletions

View File

@@ -158,7 +158,7 @@ namespace Barotrauma
foreach (Controller controller in buttons)
{
if (Vector2.Distance(controller.Item.SimPosition, character.SimPosition) > controller.Item.PickDistance * 2.0f) continue;
if (Vector2.Distance(controller.Item.Position, character.Position) > controller.Item.PickDistance * 2.0f) continue;
controller.Item.Pick(character, false, true);
break;

View File

@@ -64,7 +64,7 @@ namespace Barotrauma
}
else
{
if (Vector2.Distance(character.SimPosition, container.Item.SimPosition) > container.Item.PickDistance
if (Vector2.Distance(character.Position, container.Item.Position) > container.Item.PickDistance
&& !container.Item.IsInsideTrigger(character.Position))
{
AddSubObjective(new AIObjectiveGoTo(container.Item, character));

View File

@@ -54,7 +54,7 @@ namespace Barotrauma
{
if (targetItem != null)
{
if (Vector2.Distance(character.SimPosition, targetItem.SimPosition) < targetItem.PickDistance)
if (Vector2.Distance(character.Position, targetItem.Position) < targetItem.PickDistance)
{
int targetSlot = -1;
if (equip)

View File

@@ -108,7 +108,7 @@ namespace Barotrauma
if (item != null)
{
allowedDistance = Math.Max(item.PickDistance, allowedDistance);
allowedDistance = Math.Max(ConvertUnits.ToSimUnits(item.PickDistance), allowedDistance);
if (item.IsInsideTrigger(character.WorldPosition)) completed = true;
}

View File

@@ -47,7 +47,7 @@ namespace Barotrauma
{
if (component.CanBeSelected)
{
if (Vector2.Distance(character.SimPosition, component.Item.SimPosition) < component.Item.PickDistance
if (Vector2.Distance(character.Position, component.Item.Position) < component.Item.PickDistance
|| component.Item.IsInsideTrigger(character.WorldPosition))
{
if (character.SelectedConstruction != component.Item && component.CanBeSelected)

View File

@@ -383,7 +383,7 @@ namespace Barotrauma
avgVelocity = avgVelocity / Limbs.Count();
float impact = Vector2.Dot((f1.Body.LinearVelocity + avgVelocity) / 2.0f, -normal);
float impact = Vector2.Dot(avgVelocity, -normal);
if (GameMain.Server != null) impact = impact / 2.0f;

View File

@@ -676,8 +676,15 @@ namespace Barotrauma
if (torso == null) return null;
Vector2 pos = (torso.body.TargetPosition != Vector2.Zero) ? torso.body.TargetPosition : torso.SimPosition;
Vector2 pickPos = selectedConstruction == null ? mouseSimPos : selectedConstruction.SimPosition;
return Item.FindPickable(pos, selectedConstruction == null ? mouseSimPos : selectedConstruction.SimPosition, AnimController.CurrentHull, selectedItems);
if (Submarine != null)
{
pos += Submarine.SimPosition;
pickPos += Submarine.SimPosition;
}
return Item.FindPickable(pos, pickPos, AnimController.CurrentHull, selectedItems);
}
private Character FindClosestCharacter(Vector2 mouseSimPos, float maxDist = 150.0f)

View File

@@ -210,7 +210,7 @@ namespace Barotrauma
body.CollidesWith = Physics.CollisionAll & ~Physics.CollisionCharacter & ~Physics.CollisionMisc;
}
impactTolerance = ToolBox.GetAttributeFloat(element, "impacttolerance", character.IsHumanoid ? 15.0f : 50.0f);
impactTolerance = ToolBox.GetAttributeFloat(element, "impacttolerance", character.IsHumanoid ? 10.0f : 50.0f);
body.UserData = this;

View File

@@ -340,6 +340,12 @@ namespace Barotrauma
break;
case "tutorial":
TutorialMode.StartTutorial(Tutorials.TutorialType.TutorialTypes[0]);
break;
case "editortutorial":
GameMain.EditMapScreen.Select();
GameMain.EditMapScreen.StartTutorial();
break;
case "lobbyscreen":
case "lobby":

View File

@@ -15,7 +15,7 @@ namespace Barotrauma.Tutorials
}
protected override IEnumerable<object> UpdateState()
public override IEnumerable<object> UpdateState()
{
Submarine.Loaded.SetPosition(new Vector2(Submarine.Loaded.Position.X, 38500.0f));

View File

@@ -0,0 +1,47 @@
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Barotrauma.Tutorials
{
class EditorTutorial : TutorialType
{
public EditorTutorial(string name)
: base (name)
{
}
public override IEnumerable<object> UpdateState()
{
infoBox = CreateInfoFrame("Use the mouse wheel to zoom in and out, and WASD to move the camera around.", true);
while (infoBox!=null)
{
yield return CoroutineStatus.Running;
}
infoBox = CreateInfoFrame("Press ''Structure'' at the left side of the screen to start placing some walls.");
while (GameMain.EditMapScreen.SelectedTab != (int)MapEntityCategory.Structure)
{
yield return CoroutineStatus.Running;
}
infoBox = CreateInfoFrame("Select ''topwall'' from the list.", true);
while (MapEntityPrefab.Selected == null || MapEntityPrefab.Selected.Name != "topwall")
{
yield return CoroutineStatus.Running;
}
infoBox = CreateInfoFrame("You can now create a horizontal wall by clicking and dragging. When you're done, right click to stop creating walls.");
yield return CoroutineStatus.Success;
}
}
}

View File

@@ -14,6 +14,8 @@ namespace Barotrauma.Tutorials
protected GUIComponent infoBox;
Character character;
public string Name
{
@@ -26,6 +28,7 @@ namespace Barotrauma.Tutorials
TutorialTypes = new List<TutorialType>();
TutorialTypes.Add(new BasicTutorial("Basic tutorial"));
}
public TutorialType(string name)
@@ -58,7 +61,7 @@ namespace Barotrauma.Tutorials
CharacterInfo charInfo = new CharacterInfo(Character.HumanConfigFile, "", Gender.None, JobPrefab.List.Find(jp => jp.Name == "Engineer"));
Character character = Character.Create(charInfo, wayPoint.WorldPosition);
character = Character.Create(charInfo, wayPoint.WorldPosition);
Character.Controlled = character;
character.GiveJobItems(null);
@@ -72,27 +75,30 @@ namespace Barotrauma.Tutorials
public virtual void Update(float deltaTime)
{
if (Character.Controlled==null)
if (character!=null)
{
CoroutineManager.StopCoroutine("TutorialMode.UpdateState");
infoBox = null;
}
else if (Character.Controlled.IsDead)
{
Character.Controlled = null;
if (Character.Controlled==null)
{
CoroutineManager.StopCoroutine("TutorialMode.UpdateState");
infoBox = null;
}
else if (Character.Controlled.IsDead)
{
Character.Controlled = null;
CoroutineManager.StopCoroutine("TutorialMode.UpdateState");
infoBox = null;
CoroutineManager.StartCoroutine(Dead());
CoroutineManager.StopCoroutine("TutorialMode.UpdateState");
infoBox = null;
CoroutineManager.StartCoroutine(Dead());
}
}
//CrewManager.Update(deltaTime);
if (infoBox != null) infoBox.Update(deltaTime);
}
protected virtual IEnumerable<object> UpdateState()
public virtual IEnumerable<object> UpdateState()
{
yield return CoroutineStatus.Success;
}

View File

@@ -20,6 +20,18 @@ namespace Barotrauma.Items.Components
ConvexHull convexHull;
ConvexHull convexHull2;
private bool isOpen;
private float openState;
private PhysicsBody body;
private Sprite doorSprite, weldedSprite;
private bool isHorizontal;
private bool isStuck;
private float stuck;
public float Stuck
{
@@ -33,8 +45,6 @@ namespace Barotrauma.Items.Components
}
}
private bool isStuck;
Gap LinkedGap
{
get
@@ -53,10 +63,6 @@ namespace Barotrauma.Items.Components
}
}
bool isOpen;
float openState;
[HasDefaultValue("0.0,0.0,0.0,0.0", false)]
public string Window
{
@@ -97,10 +103,6 @@ namespace Barotrauma.Items.Components
UpdateConvexHulls();
}
}
PhysicsBody body;
Sprite doorSprite, weldedSprite;
public Door(Item item, XElement element)
: base(item, element)

View File

@@ -54,7 +54,7 @@ namespace Barotrauma.Items.Components
if (character == null || reloadTimer>0.0f) return false;
if (!character.IsKeyDown(InputType.Aim) || hitting) return false;
user = character;
SetUser(character);
if (hitPos < MathHelper.Pi * 0.69f) return false;
@@ -154,9 +154,36 @@ namespace Barotrauma.Items.Components
hitting = false;
}
}
}
}
private void SetUser(Character character)
{
if (user == character) return;
if (user != null)
{
foreach (Limb limb in user.AnimController.Limbs)
{
try
{
item.body.FarseerBody.RestoreCollisionWith(limb.body.FarseerBody);
}
catch
{
continue;
}
}
}
foreach (Limb limb in character.AnimController.Limbs)
{
item.body.FarseerBody.IgnoreCollisionWith(limb.body.FarseerBody);
}
user = character;
}
private void RestoreCollision()
{

View File

@@ -69,7 +69,7 @@ namespace Barotrauma.Items.Components
if (character == null
|| character.SelectedConstruction != item
|| Vector2.Distance(character.SimPosition, item.SimPosition) > item.PickDistance * 1.5f)
|| Vector2.Distance(character.Position, item.Position) > item.PickDistance * 1.5f)
{
if (character != null)
{

View File

@@ -895,7 +895,7 @@ namespace Barotrauma
foreach (Rectangle trigger in item.prefab.Triggers)
{
Rectangle transformedTrigger = item.TransformTrigger(trigger);
Rectangle transformedTrigger = item.TransformTrigger(trigger, true);
if (!Submarine.RectContains(transformedTrigger, displayPos)) continue;
@@ -917,16 +917,16 @@ namespace Barotrauma
}
}
if (item.prefab.PickDistance == 0.0f) continue;
if (Vector2.Distance(position, item.SimPosition) > item.prefab.PickDistance) continue;
if (item.prefab.PickDistance == 0.0f) continue;
if (Vector2.Distance(displayPos, item.WorldPosition) > item.prefab.PickDistance) continue;
if (!item.prefab.PickThroughWalls)
{
Body body = Submarine.CheckVisibility(position, item.SimPosition);
Body body = Submarine.CheckVisibility(item.Submarine == null ? position : position - item.Submarine.SimPosition, item.SimPosition);
if (body != null && body.UserData as Item != item) continue;
}
dist = Vector2.Distance(pickPosition, item.SimPosition);
dist = Vector2.Distance(displayPickPos, item.WorldPosition);
if (dist < item.prefab.PickDistance && (closest == null || dist < closestDist))
{
closest = item;

View File

@@ -38,12 +38,6 @@ namespace Barotrauma
get { return configFile; }
}
public string Description
{
get;
private set;
}
public List<string> DeconstructItems
{
get;
@@ -189,7 +183,7 @@ namespace Barotrauma
Description = ToolBox.GetAttributeString(element, "description", "");
pickThroughWalls = ToolBox.GetAttributeBool(element, "pickthroughwalls", false);
pickDistance = ConvertUnits.ToSimUnits(ToolBox.GetAttributeFloat(element, "pickdistance", 0.0f));
pickDistance = ToolBox.GetAttributeFloat(element, "pickdistance", 0.0f);
isLinkable = ToolBox.GetAttributeBool(element, "linkable", false);
@@ -221,7 +215,13 @@ namespace Barotrauma
switch (subElement.Name.ToString().ToLower())
{
case "sprite":
sprite = new Sprite(subElement, Path.GetDirectoryName(filePath));
string spriteFolder = "";
if (!ToolBox.GetAttributeString(subElement, "texture", "").Contains("/"))
{
spriteFolder = Path.GetDirectoryName(filePath);
}
sprite = new Sprite(subElement, spriteFolder);
size = sprite.size;
break;
case "deconstruct":

View File

@@ -47,6 +47,13 @@ namespace Barotrauma
set { selected = value; }
}
public string Description
{
get;
protected set;
}
public virtual bool IsLinkable
{
get { return isLinkable; }
@@ -83,6 +90,7 @@ namespace Barotrauma
{
MapEntityPrefab ep = new MapEntityPrefab();
ep.name = "hull";
ep.Description = "Hulls determine which parts are considered to be ''inside the sub''. Generally every room should be enclosed by a hull.";
ep.constructor = typeof(Hull).GetConstructor(new Type[] { typeof(Rectangle) });
ep.resizeHorizontal = true;
ep.resizeVertical = true;
@@ -90,6 +98,7 @@ namespace Barotrauma
ep = new MapEntityPrefab();
ep.name = "gap";
ep.Description = "Gaps allow water and air to flow between two hulls. ";
ep.constructor = typeof(Gap).GetConstructor(new Type[] { typeof(Rectangle) });
ep.resizeHorizontal = true;
ep.resizeVertical = true;

View File

@@ -89,6 +89,8 @@ namespace Barotrauma
if (ToolBox.GetAttributeBool(element, "flipvertical", false)) sp.sprite.effects = SpriteEffects.FlipVertically;
}
sp.Description = ToolBox.GetAttributeString(element, "description", "");
sp.size = Vector2.Zero;
sp.size.X = ToolBox.GetAttributeFloat(element, "width", 0.0f);
sp.size.Y = ToolBox.GetAttributeFloat(element, "height", 0.0f);

View File

@@ -9,7 +9,7 @@ namespace Barotrauma
{
private Camera cam;
private GUIComponent GUIpanel;
public GUIComponent GUIpanel;
private GUIComponent[] GUItabs;
private int selectedTab;
@@ -21,11 +21,18 @@ namespace Barotrauma
private bool characterMode;
private Tutorials.EditorTutorial tutorial;
public Camera Cam
{
get { return cam; }
}
public int SelectedTab
{
get { return selectedTab; }
}
//public string GetSubName()
//{
// return ((Submarine.Loaded == null) ? "" : Submarine.Loaded.Name);
@@ -125,10 +132,9 @@ namespace Barotrauma
null, frame);
textBlock.Padding = new Vector4(5.0f, 0.0f, 5.0f, 0.0f);
ItemPrefab ip = ep as ItemPrefab;
if (ip != null && !string.IsNullOrWhiteSpace(ip.Description))
if (!string.IsNullOrWhiteSpace(ep.Description))
{
textBlock.ToolTip = ip.Description;
textBlock.ToolTip = ep.Description;
}
if (ep.sprite != null)
@@ -163,6 +169,13 @@ namespace Barotrauma
}
public void StartTutorial()
{
tutorial = new Tutorials.EditorTutorial("EditorTutorial");
CoroutineManager.StartCoroutine(tutorial.UpdateState());
}
public override void Select()
{
base.Select();
@@ -302,6 +315,7 @@ namespace Barotrauma
/// <param name="gameTime">Provides a snapshot of timing values.</param>
public override void Update(double deltaTime)
{
if (tutorial!=null) tutorial.Update((float)deltaTime);
if (GUIComponent.MouseOn == null)
{
@@ -420,6 +434,8 @@ namespace Barotrauma
MapEntity.Edit(spriteBatch, cam);
}
if (tutorial != null) tutorial.Draw(spriteBatch);
GUI.Draw((float)deltaTime, spriteBatch, cam);
if (!PlayerInput.LeftButtonDown()) Inventory.draggingItem = null;