Set orders stay in CrewCommander interface after reopening, minor changes to the interface layout

This commit is contained in:
Regalis
2015-12-17 19:35:14 +02:00
parent fa5cceb903
commit eb0e08c8ee
9 changed files with 107 additions and 451 deletions

View File

@@ -77,7 +77,9 @@
<Compile Include="Source\Characters\AI\PathFinder.cs" />
<Compile Include="Source\Characters\Animation\AnimController.cs" />
<Compile Include="Source\Characters\Attack.cs" />
<Compile Include="Source\Characters\BackgroundSprite\BackgroundSprite.cs" />
<Compile Include="Source\Characters\BackgroundSprite\BackgroundCreature.cs" />
<Compile Include="Source\Characters\BackgroundSprite\BackgroundCreatureManager.cs" />
<Compile Include="Source\Characters\BackgroundSprite\BackgroundCreaturePrefab.cs" />
<Compile Include="Source\Characters\BackgroundSprite\BackgroundSpriteManager.cs" />
<Compile Include="Source\Characters\BackgroundSprite\BackgroundSpritePrefab.cs" />
<Compile Include="Source\Characters\Character.cs" />
@@ -285,6 +287,9 @@
<Content Include="changelog.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\BackgroundSprites\BackgroundCreaturePrefabs.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\BackgroundSprites\BackgroundSpritePrefabs.xml">
<SubType>Designer</SubType>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
@@ -292,6 +297,9 @@
<Content Include="Content\BackgroundSprites\bgFish1.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\BackgroundSprites\vegetation.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\Characters\Coelanth\Coelanth.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
@@ -591,6 +599,9 @@
<Content Include="Content\Map\iceSurface.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\Map\iceWall.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\Map\locationNames.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>

View File

@@ -38,20 +38,20 @@ namespace Barotrauma
if (IsOpen)
{
CreateGUIFrame();
if (frame == null) CreateGUIFrame();
UpdateCharacters();
}
}
private void CreateGUIFrame()
{
frame = new GUIFrame(Rectangle.Empty, Color.Black * 0.3f);
frame = new GUIFrame(Rectangle.Empty, Color.Black * 0.6f);
frame.Padding = new Vector4(200.0f, 100.0f, 200.0f, 100.0f);
//UpdateCharacters();
int buttonWidth = 130;
int spacing = 10;
int spacing = 20;
int y = 250;
@@ -88,13 +88,16 @@ namespace Barotrauma
i++;
}
y += 80;
y += 100;
}
}
private GUIButton CreateOrderButton(Rectangle rect, Order order, bool createSymbol = true)
{
var orderButton = new GUIButton(rect, order.Name, Color.Black * 0.5f, Alignment.TopCenter, Alignment.Right, null, frame);
var orderButton = new GUIButton(rect, order.Name, Color.Black * 0.7f, Alignment.TopCenter, Alignment.Center, null, frame);
orderButton.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f);
orderButton.TextColor = Color.White;
orderButton.Color = Color.Black * 0.5f;
orderButton.HoverColor = Color.LightGray * 0.5f;
orderButton.OutlineColor = Color.LightGray * 0.8f;
orderButton.UserData = order;
@@ -102,10 +105,10 @@ namespace Barotrauma
if (createSymbol)
{
var symbol = new GUIImage(new Rectangle(-5,0,64,64), order.SymbolSprite, Alignment.Left | Alignment.CenterY, orderButton);
var symbol = new GUIImage(new Rectangle(0,-60,64,64), order.SymbolSprite, Alignment.TopCenter, orderButton);
symbol.Color = order.Color;
orderButton.children.Insert(1, symbol);
orderButton.children.Insert(0, symbol);
orderButton.children.RemoveAt(orderButton.children.Count-1);
}
@@ -123,7 +126,7 @@ namespace Barotrauma
prevCharacterFrames.Add(child);
}
foreach (GUIComponent child in prevCharacterFrames)
{
frame.RemoveChild(child);
@@ -183,6 +186,12 @@ namespace Barotrauma
new GUIImage(new Rectangle(-5, -5, 0, 0), character.AnimController.Limbs[0].sprite, Alignment.Left, characterButton);
var humanAi = character.AIController as HumanAIController;
if (humanAi.CurrentOrder != null)
{
CreateCharacterOrderFrame(characterButton, humanAi.CurrentOrder, humanAi.CurrentOrderOption);
}
i++;
}
}
@@ -200,30 +209,9 @@ namespace Barotrauma
if (!characterButton.Selected) continue;
characterButton.Selected = false;
var character = child.UserData as Character;
if (character == null) continue;
CreateCharacterOrderFrame(characterButton, order, "");
var humanAi = character.AIController as HumanAIController;
if (humanAi == null) continue;
var existingOrder = characterButton.children.Find(c => c.UserData as Order != null);
if (existingOrder != null) characterButton.RemoveChild(existingOrder);
var orderFrame = new GUIFrame(new Rectangle(0, characterButton.Rect.Height, 0, 30 + order.Options.Length*15), null, characterButton);
orderFrame.OutlineColor = Color.LightGray * 0.8f;
orderFrame.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f);
orderFrame.UserData = order;
new GUITextBlock(new Rectangle(0,0,0,20), order.DoingText, GUI.Style, Alignment.TopLeft, Alignment.TopCenter, orderFrame);
var optionList = new GUIListBox(new Rectangle(0,20,0,80), Color.Transparent, null, orderFrame);
optionList.UserData = order;
optionList.OnSelected = SelectOrderOption;
foreach (string option in order.Options)
{
var optionBox = new GUITextBlock(new Rectangle(0,0,0,15), option, GUI.Style, optionList);
optionBox.Font = GUI.SmallFont;
optionBox.UserData = option;
}
var humanAi = (characterButton.UserData as Character).AIController as HumanAIController;
humanAi.SetOrder(order, "");
}
@@ -233,6 +221,41 @@ namespace Barotrauma
return true;
}
private void CreateCharacterOrderFrame(GUIComponent characterFrame, Order order, string selectedOption)
{
var character = characterFrame.UserData as Character;
if (character == null) return;
var humanAi = character.AIController as HumanAIController;
if (humanAi == null) return;
var existingOrder = characterFrame.children.Find(c => c.UserData as Order != null);
if (existingOrder != null) characterFrame.RemoveChild(existingOrder);
var orderFrame = new GUIFrame(new Rectangle(0, characterFrame.Rect.Height, 0, 30 + order.Options.Length * 15), null, characterFrame);
orderFrame.OutlineColor = Color.LightGray * 0.8f;
orderFrame.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f);
orderFrame.UserData = order;
new GUITextBlock(new Rectangle(0, 0, 0, 20), order.DoingText, GUI.Style, Alignment.TopLeft, Alignment.TopCenter, orderFrame);
var optionList = new GUIListBox(new Rectangle(0, 20, 0, 80), Color.Transparent, null, orderFrame);
optionList.UserData = order;
for (int i = 0; i < order.Options.Length; i++ )
{
var optionBox = new GUITextBlock(new Rectangle(0, 0, 0, 15), order.Options[i], GUI.Style, optionList);
optionBox.Font = GUI.SmallFont;
optionBox.UserData = order.Options[i];
if (selectedOption == order.Options[i])
{
optionList.Select(i);
}
}
optionList.OnSelected = SelectOrderOption;
}
private bool SelectOrderOption(GUIComponent component, object userData)
{
string option = userData.ToString();

View File

@@ -20,6 +20,18 @@ namespace Barotrauma
private float updateObjectiveTimer;
public Order CurrentOrder
{
get;
private set;
}
public string CurrentOrderOption
{
get;
private set;
}
public HumanAIController(Character c) : base(c)
{
indoorsSteeringManager = new IndoorsSteeringManager(this, true);
@@ -77,6 +89,8 @@ namespace Barotrauma
public void SetOrder(Order order, string option)
{
CurrentOrderOption = option;
CurrentOrder = order;
objectiveManager.SetOrder(order, option);
}

View File

@@ -14,13 +14,13 @@ namespace Barotrauma
private Character character;
private AIObjective currentOrder;
private AIObjective currentObjective;
public AIObjective CurrentObjective
{
get
{
if (currentOrder != null) return currentOrder;
if (currentObjective != null) return currentObjective;
return objectives.Any() ? objectives[0] : null;
}
}
@@ -41,7 +41,7 @@ namespace Barotrauma
public float GetCurrentPriority(Character character)
{
if (currentOrder != null) return OrderPriority;
if (currentObjective != null) return OrderPriority;
return (CurrentObjective == null) ? 0.0f : CurrentObjective.GetPriority(character);
}
@@ -69,9 +69,9 @@ namespace Barotrauma
public void DoCurrentObjective(float deltaTime)
{
if (currentOrder != null && (!objectives.Any() || objectives[0].GetPriority(character)<OrderPriority))
if (currentObjective != null && (!objectives.Any() || objectives[0].GetPriority(character)<OrderPriority))
{
currentOrder.TryComplete(deltaTime);
currentObjective.TryComplete(deltaTime);
return;
}
@@ -81,20 +81,20 @@ namespace Barotrauma
public void SetOrder(Order order, string option)
{
currentOrder = null;
currentObjective = null;
switch (order.Name.ToLower())
{
case "follow":
currentOrder = new AIObjectiveGoTo(Character.Controlled, character, true);
currentObjective = new AIObjectiveGoTo(Character.Controlled, character, true);
break;
case "wait":
currentOrder = new AIObjectiveGoTo(character.SimPosition, character, true);
currentObjective = new AIObjectiveGoTo(character.SimPosition, character, true);
break;
default:
if (order.TargetItem == null) return;
currentOrder = new AIObjectiveOperateItem(order.TargetItem, character, option);
currentObjective = new AIObjectiveOperateItem(order.TargetItem, character, option);
break;
}

View File

@@ -76,11 +76,23 @@ namespace Barotrauma
Color = new Color(ToolBox.GetAttributeVector4(orderElement, "color", new Vector4(1.0f, 1.0f, 1.0f, 1.0f)));
Options = ToolBox.GetAttributeString(orderElement, "options", "").Split(',');
for (int i = 0; i<Options.Length; i++)
string optionStr = ToolBox.GetAttributeString(orderElement, "options", "");
if (string.IsNullOrWhiteSpace(optionStr))
{
Options[i] = Options[i].Trim();
Options = new string[0];
}
else
{
Options = optionStr.Split(',');
for (int i = 0; i<Options.Length; i++)
{
Options[i] = Options[i].Trim();
}
}
foreach (XElement subElement in orderElement.Elements())
{

View File

@@ -1,404 +0,0 @@
using FarseerPhysics;
using FarseerPhysics.Collision;
using FarseerPhysics.Common;
using FarseerPhysics.Common.Decomposition;
using FarseerPhysics.Dynamics;
using FarseerPhysics.Dynamics.Contacts;
using FarseerPhysics.Factories;
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using Voronoi2;
namespace Barotrauma
{
class SubmarineBody
{
public const float DamageDepth = -30000.0f;
const float PressureDamageMultiplier = 0.001f;
//structure damage = impact * damageMultiplier
const float DamageMultiplier = 50.0f;
const float Friction = 0.2f, Restitution = 0.0f;
public List<Vector2> HullVertices
{
get;
private set;
}
private float depthDamageTimer;
private Submarine submarine;
private Body body;
private Vector2 targetPosition;
float mass = 10000.0f;
//private Vector2? lastContactPoint;
//private VoronoiCell lastContactCell;
public Rectangle Borders
{
get;
private set;
}
public Vector2 Velocity
{
get { return body.LinearVelocity; }
set
{
if (!MathUtils.IsValid(value)) return;
body.LinearVelocity = value;
}
}
public Vector2 TargetPosition
{
get { return targetPosition; }
set
{
if (!MathUtils.IsValid(value)) return;
targetPosition = value;
}
}
public Vector2 Position
{
get { return ConvertUnits.ToDisplayUnits(body.Position); }
}
public Vector2 Center
{
get { return new Vector2(Borders.X + Borders.Width / 2, Borders.Y - Borders.Height / 2); }
}
public bool AtDamageDepth
{
get { return Position.Y < DamageDepth; }
}
public SubmarineBody(Submarine sub)
{
this.submarine = sub;
List<Vector2> convexHull = GenerateConvexHull();
HullVertices = convexHull;
for (int i = 0; i < convexHull.Count; i++)
{
convexHull[i] = ConvertUnits.ToSimUnits(convexHull[i]);
}
convexHull.Reverse();
//get farseer 'vertices' from vectors
Vertices shapevertices = new Vertices(convexHull);
AABB hullAABB = shapevertices.GetAABB();
Borders = new Rectangle(
(int)ConvertUnits.ToDisplayUnits(hullAABB.LowerBound.X),
(int)ConvertUnits.ToDisplayUnits(hullAABB.UpperBound.Y),
(int)ConvertUnits.ToDisplayUnits(hullAABB.Extents.X * 2.0f),
(int)ConvertUnits.ToDisplayUnits(hullAABB.Extents.Y * 2.0f));
//var triangulatedVertices = Triangulate.ConvexPartition(shapevertices, TriangulationAlgorithm.Bayazit);
body = BodyFactory.CreateBody(GameMain.World, this);
foreach (Hull hull in Hull.hullList)
{
Rectangle rect = hull.Rect;
foreach (Structure wall in Structure.WallList)
{
if (!Submarine.RectsOverlap(wall.Rect, hull.Rect)) continue;
if (wall.IsHorizontal)
{
if (wall.Rect.Y >= hull.Rect.Y)
{
rect = new Rectangle(rect.X, wall.Rect.Y, rect.Width, rect.Height + (wall.Rect.Y - rect.Y));
}
else
{
rect = new Rectangle(rect.X, rect.Y, rect.Width, rect.Height + (rect.Y - rect.Height - (wall.Rect.Y - wall.Rect.Height)));
}
}
}
FixtureFactory.AttachRectangle(
ConvertUnits.ToSimUnits(rect.Width),
ConvertUnits.ToSimUnits(rect.Height),
5.0f,
ConvertUnits.ToSimUnits(rect.Center.ToVector2()),
body, this);
}
body.BodyType = BodyType.Dynamic;
body.CollisionCategories = Physics.CollisionMisc | Physics.CollisionWall;
body.CollidesWith = Physics.CollisionLevel | Physics.CollisionCharacter;
body.Restitution = Restitution;
body.Friction = Friction;
body.FixedRotation = true;
body.Mass = mass;
body.Awake = true;
body.SleepingAllowed = false;
body.IgnoreGravity = true;
body.OnCollision += OnCollision;
//body.UserData = this;
}
private List<Vector2> GenerateConvexHull()
{
if (!Structure.WallList.Any())
{
return new List<Vector2>() { new Vector2(-1.0f, 1.0f), new Vector2(1.0f, 1.0f), new Vector2(0.0f, -1.0f) };
}
List<Vector2> points = new List<Vector2>();
Vector2 leftMost = Vector2.Zero;
foreach (Structure wall in Structure.WallList)
{
for (int x = -1; x <= 1; x += 2)
{
for (int y = -1; y <= 1; y += 2)
{
Vector2 corner = new Vector2(wall.Rect.X + wall.Rect.Width / 2.0f, wall.Rect.Y - wall.Rect.Height / 2.0f);
corner.X += x * wall.Rect.Width / 2.0f;
corner.Y += y * wall.Rect.Height / 2.0f;
if (points.Contains(corner)) continue;
points.Add(corner);
if (leftMost == Vector2.Zero || corner.X < leftMost.X) leftMost = corner;
}
}
}
List<Vector2> hullPoints = new List<Vector2>();
Vector2 currPoint = leftMost;
Vector2 endPoint;
do
{
hullPoints.Add(currPoint);
endPoint = points[0];
for (int i = 1; i < points.Count; i++)
{
if ((currPoint == endPoint)
|| (MathUtils.VectorOrientation(currPoint, endPoint, points[i]) == -1))
{
endPoint = points[i];
}
}
currPoint = endPoint;
}
while (endPoint != hullPoints[0]);
return hullPoints;
}
public void Update(float deltaTime)
{
if (targetPosition != Vector2.Zero && targetPosition != Position)
{
float dist = Vector2.Distance(targetPosition, Position);
if (dist > 1000.0f)
{
body.SetTransform(ConvertUnits.ToSimUnits(targetPosition), 0.0f);
targetPosition = Vector2.Zero;
}
else if (dist > 50.0f)
{
body.SetTransform((ConvertUnits.ToSimUnits(targetPosition) - body.Position) * 0.01f, 0.0f);
}
}
else
{
targetPosition = Vector2.Zero;
}
//-------------------------
Vector2 totalForce = CalculateBuoyancy();
if (body.LinearVelocity.LengthSquared() > 0.000001f)
{
float dragCoefficient = 0.01f;
float speedLength = (body.LinearVelocity == Vector2.Zero) ? 0.0f : body.LinearVelocity.Length();
float drag = speedLength * speedLength * dragCoefficient * mass;
totalForce += -Vector2.Normalize(body.LinearVelocity) * drag;
}
ApplyForce(totalForce);
UpdateDepthDamage(deltaTime);
}
private Vector2 CalculateBuoyancy()
{
float waterVolume = 0.0f;
float volume = 0.0f;
foreach (Hull hull in Hull.hullList)
{
waterVolume += hull.Volume;
volume += hull.FullVolume;
}
float waterPercentage = waterVolume / volume;
float neutralPercentage = 0.07f;
float buoyancy = Math.Max(neutralPercentage - waterPercentage, -neutralPercentage*2.0f);
buoyancy *= mass;
return new Vector2(0.0f, buoyancy*10.0f);
}
public void ApplyForce(Vector2 force)
{
body.ApplyForce(force);
}
public void SetPosition(Vector2 position)
{
body.SetTransform(ConvertUnits.ToSimUnits(position), 0.0f);
}
private void UpdateDepthDamage(float deltaTime)
{
if (Position.Y > DamageDepth) return;
float depth = DamageDepth - Position.Y;
depth = Math.Min(depth, 40000.0f);
// float prevTimer = depthDamageTimer;
depthDamageTimer -= deltaTime*Math.Min(depth,20000)*PressureDamageMultiplier;
//if (prevTimer>5.0f && depthDamageTimer<=5.0f)
//{
// SoundPlayer.PlayDamageSound(DamageSoundType.Pressure, 50.0f,);
//}
if (depthDamageTimer > 0.0f) return;
Vector2 damagePos = Vector2.Zero;
if (Rand.Int(2)==0)
{
damagePos = new Vector2(
(Rand.Int(2) == 0) ? Borders.X : Borders.X+Borders.Width,
Rand.Range(Borders.Y - Borders.Height, Borders.Y));
}
else
{
damagePos = new Vector2(
Rand.Range(Borders.X, Borders.X + Borders.Width),
(Rand.Int(2) == 0) ? Borders.Y : Borders.Y - Borders.Height);
}
SoundPlayer.PlayDamageSound(DamageSoundType.Pressure, 50.0f, damagePos, 10000.0f);
GameMain.GameScreen.Cam.Shake = depth * PressureDamageMultiplier * 0.1f;
damagePos += submarine.Position + Submarine.HiddenSubPosition;
Explosion.RangedStructureDamage(damagePos, depth * PressureDamageMultiplier * 50.0f, depth * PressureDamageMultiplier);
//SoundPlayer.PlayDamageSound(DamageSoundType.StructureBlunt, Rand.Range(0.0f, 100.0f), damagePos, 5000.0f);
depthDamageTimer = 10.0f;
}
public bool OnCollision(Fixture f1, Fixture f2, Contact contact)
{
VoronoiCell cell = f2.Body.UserData as VoronoiCell;
if (cell == null)
{
Limb limb = f2.Body.UserData as Limb;
if (limb!=null && limb.character.Submarine==null)
{
Vector2 normal2;
FixedArray2<Vector2> points;
contact.GetWorldManifold(out normal2, out points);
if (Submarine.PickBody(
points[0] - limb.LinearVelocity * ((float)Physics.step) - ConvertUnits.ToSimUnits(submarine.Position) - submarine.Velocity * ((float)Physics.step) + normal2,
points[0] - ConvertUnits.ToSimUnits(submarine.Position) - normal2, null, Physics.CollisionWall) != null)
{
return true;
}
var ragdoll = limb.character.AnimController;
ragdoll.FindHull();
return false;
}
return true;
}
Vector2 normal;
FarseerPhysics.Common.FixedArray2<Vector2> worldPoints;
contact.GetWorldManifold(out normal, out worldPoints);
Vector2 lastContactPoint = worldPoints[0];
normal = Vector2.Normalize(ConvertUnits.ToDisplayUnits(body.Position) - cell.Center);
float impact = Vector2.Dot(Velocity, -normal);
//Vector2 u = Vector2.Dot(Velocity, -normal) * normal;
//Vector2 w = (Velocity + u);
//speed = ConvertUnits.ToDisplayUnits(w * (1.0f - Friction) + u * Restitution);
if (impact < 3.0f) return true;
SoundPlayer.PlayDamageSound(DamageSoundType.StructureBlunt, impact * 10.0f, ConvertUnits.ToDisplayUnits(lastContactPoint));
GameMain.GameScreen.Cam.Shake = impact * 2.0f;
Vector2 limbForce = -normal * impact * 0.5f;
float length = limbForce.Length();
if (length > 10.0f) limbForce = (limbForce / length) * 10.0f;
foreach (Character c in Character.CharacterList)
{
if (c.AnimController.CurrentHull == null) continue;
if (impact > 2.0f) c.StartStun((impact - 2.0f) * 0.1f);
foreach (Limb limb in c.AnimController.Limbs)
{
if (c.AnimController.LowestLimb == limb) continue;
limb.body.ApplyLinearImpulse(limb.Mass * limbForce);
}
}
Explosion.RangedStructureDamage(ConvertUnits.ToDisplayUnits(lastContactPoint), impact * 50.0f, impact * DamageMultiplier);
return true;
}
}
}

View File

@@ -134,9 +134,9 @@ namespace Barotrauma
public override void Draw(double deltaTime, GraphicsDevice graphics, SpriteBatch spriteBatch)
{
if (Character.Controlled!=null)
if (Character.Controlled != null)
{
cam.TargetPos = Character.Controlled.Position;
cam.TargetPos = Character.Controlled.WorldPosition;
}
cam.UpdateTransform();

Binary file not shown.

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectView>ProjectFiles</ProjectView>
<ProjectView>ShowAllFiles</ProjectView>
</PropertyGroup>
</Project>