Merge remote-tracking branch 'refs/remotes/barotrauma/master'
Conflicts: Subsurface/Properties/AssemblyInfo.cs Subsurface/Source/Characters/Character.cs Subsurface/Source/GUI/GUI.cs Subsurface/Source/GameMain.cs Subsurface/Source/GameSettings.cs Subsurface/Source/Items/CharacterInventory.cs Subsurface/Source/Items/Components/ItemComponent.cs Subsurface/Source/Items/Components/Machines/Pump.cs Subsurface/Source/Items/Components/Machines/Radar.cs Subsurface/Source/Items/Components/Machines/Steering.cs Subsurface/Source/Items/Components/Power/PowerContainer.cs Subsurface/Source/Items/Inventory.cs Subsurface/Source/Items/Item.cs Subsurface/Source/Items/ItemSpawner.cs Subsurface/Source/Map/Levels/WaterRenderer.cs Subsurface/Source/Map/LinkedSubmarine.cs Subsurface/Source/Map/Map/Map.cs Subsurface/Source/Map/Structure.cs Subsurface/Source/Map/Submarine.cs Subsurface/Source/Map/WayPoint.cs Subsurface/Source/Networking/GameClient.cs Subsurface/Source/Networking/GameServer.cs Subsurface/Source/Physics/PhysicsBody.cs Subsurface/Source/Screens/GameScreen.cs
This commit is contained in:
@@ -110,6 +110,8 @@ namespace Barotrauma
|
||||
|
||||
viewMatrix =
|
||||
Matrix.CreateTranslation(new Vector3(GameMain.GraphicsWidth / 2.0f, GameMain.GraphicsHeight / 2.0f, 0));
|
||||
|
||||
UpdateTransform();
|
||||
}
|
||||
|
||||
public Vector2 TargetPos
|
||||
@@ -193,9 +195,13 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
moveCam = moveCam * deltaTime * 60.0f;
|
||||
moveCam = moveCam * deltaTime * 60.0f;
|
||||
|
||||
Zoom = MathHelper.Clamp(zoom + (PlayerInput.ScrollWheelSpeed / 1000.0f) * zoom, GameMain.DebugDraw ? 0.01f : 0.1f, 2.0f);
|
||||
Vector2 mouseInWorld = ScreenToWorld(PlayerInput.MousePosition);
|
||||
Vector2 diffViewCenter;
|
||||
diffViewCenter = ((mouseInWorld - Position) * Zoom);
|
||||
Zoom = MathHelper.Clamp(zoom + (PlayerInput.ScrollWheelSpeed / 1000.0f) * zoom, GameMain.DebugDraw ? 0.01f : 0.1f, 2.0f);
|
||||
if (!PlayerInput.KeyDown(Keys.F)) Position = mouseInWorld - (diffViewCenter / Zoom);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -341,7 +341,7 @@ namespace Barotrauma
|
||||
{
|
||||
wallAttackPos = Vector2.Zero;
|
||||
limb.AttackTimer = 0.0f;
|
||||
if (Vector2.Distance(limb.SimPosition, attackPosition)<5.0) coolDownTimer = attackCoolDown;
|
||||
coolDownTimer = attackCoolDown;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -180,8 +180,8 @@ namespace Barotrauma
|
||||
{
|
||||
if (selectedAiTarget != null)
|
||||
{
|
||||
GUI.DrawLine(spriteBatch,
|
||||
new Vector2(Character.WorldPosition.X, -Character.WorldPosition.Y),
|
||||
GUI.DrawLine(spriteBatch,
|
||||
new Vector2(Character.DrawPosition.X, -Character.DrawPosition.Y),
|
||||
new Vector2(selectedAiTarget.WorldPosition.X, -selectedAiTarget.WorldPosition.Y), Color.Red);
|
||||
}
|
||||
|
||||
@@ -189,16 +189,16 @@ namespace Barotrauma
|
||||
if (pathSteering == null || pathSteering.CurrentPath == null || pathSteering.CurrentPath.CurrentNode==null) return;
|
||||
|
||||
GUI.DrawLine(spriteBatch,
|
||||
new Vector2(Character.WorldPosition.X, -Character.WorldPosition.Y),
|
||||
new Vector2(pathSteering.CurrentPath.CurrentNode.WorldPosition.X, -pathSteering.CurrentPath.CurrentNode.WorldPosition.Y),
|
||||
new Vector2(Character.DrawPosition.X, -Character.DrawPosition.Y),
|
||||
new Vector2(pathSteering.CurrentPath.CurrentNode.DrawPosition.X, -pathSteering.CurrentPath.CurrentNode.DrawPosition.Y),
|
||||
Color.LightGreen);
|
||||
|
||||
|
||||
for (int i = 1; i < pathSteering.CurrentPath.Nodes.Count; i++)
|
||||
{
|
||||
GUI.DrawLine(spriteBatch,
|
||||
new Vector2(pathSteering.CurrentPath.Nodes[i].WorldPosition.X, -pathSteering.CurrentPath.Nodes[i].WorldPosition.Y),
|
||||
new Vector2(pathSteering.CurrentPath.Nodes[i - 1].WorldPosition.X, -pathSteering.CurrentPath.Nodes[i-1].WorldPosition.Y),
|
||||
new Vector2(pathSteering.CurrentPath.Nodes[i].DrawPosition.X, -pathSteering.CurrentPath.Nodes[i].DrawPosition.Y),
|
||||
new Vector2(pathSteering.CurrentPath.Nodes[i - 1].DrawPosition.X, -pathSteering.CurrentPath.Nodes[i - 1].DrawPosition.Y),
|
||||
Color.LightGreen);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,9 +64,9 @@ namespace Barotrauma
|
||||
aiController.Update(deltaTime);
|
||||
}
|
||||
|
||||
public override void DrawFront(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch)
|
||||
public override void DrawFront(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch,Camera cam)
|
||||
{
|
||||
base.DrawFront(spriteBatch);
|
||||
base.DrawFront(spriteBatch,cam);
|
||||
|
||||
if (GameMain.DebugDraw && !isDead) aiController.DebugDraw(spriteBatch);
|
||||
}
|
||||
|
||||
@@ -426,7 +426,11 @@ namespace Barotrauma
|
||||
float volume = stairs == null ? impact / 5.0f : impact;
|
||||
volume = Math.Min(impact, 1.0f);
|
||||
|
||||
if (impact > 0.8f && l.HitSound != null && l.soundTimer <= 0.0f) l.HitSound.Play(volume, impact * 100.0f, l.WorldPosition);
|
||||
if (impact > 0.5f && l.HitSound != null && l.soundTimer <= 0.0f)
|
||||
{
|
||||
l.soundTimer = Limb.SoundInterval;
|
||||
l.HitSound.Play(volume, impact * 250.0f, l.WorldPosition);
|
||||
}
|
||||
|
||||
if (impact > l.impactTolerance)
|
||||
{
|
||||
@@ -464,7 +468,7 @@ namespace Barotrauma
|
||||
if (limb.pullJoint != null)
|
||||
{
|
||||
Vector2 pos = ConvertUnits.ToDisplayUnits(limb.pullJoint.WorldAnchorA);
|
||||
if (currentHull != null) pos += currentHull.Submarine.Position;
|
||||
if (currentHull != null) pos += currentHull.Submarine.DrawPosition;
|
||||
pos.Y = -pos.Y;
|
||||
GUI.DrawRectangle(spriteBatch, new Rectangle((int)pos.X, (int)pos.Y, 5, 5), Color.Red, true, 0.01f);
|
||||
|
||||
@@ -492,7 +496,7 @@ namespace Barotrauma
|
||||
if (limb.body.TargetPosition != Vector2.Zero)
|
||||
{
|
||||
Vector2 pos = ConvertUnits.ToDisplayUnits(limb.body.TargetPosition);
|
||||
if (currentHull != null) pos += currentHull.Submarine.Position;
|
||||
if (currentHull != null) pos += currentHull.Submarine.DrawPosition;
|
||||
pos.Y = -pos.Y;
|
||||
|
||||
GUI.DrawRectangle(spriteBatch, new Rectangle((int)pos.X - 10, (int)pos.Y - 10, 20, 20), Color.Cyan, false, 0.01f);
|
||||
|
||||
@@ -72,6 +72,9 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
public Hull PreviousHull = null;
|
||||
public Hull CurrentHull = null;
|
||||
|
||||
public readonly bool IsNetworkPlayer;
|
||||
|
||||
private bool networkUpdateSent;
|
||||
@@ -92,7 +95,9 @@ namespace Barotrauma
|
||||
|
||||
private Item selectedConstruction;
|
||||
private Item[] selectedItems;
|
||||
|
||||
|
||||
public byte TeamID = 0;
|
||||
|
||||
public AnimController AnimController;
|
||||
|
||||
private Vector2 cursorPosition;
|
||||
@@ -833,19 +838,39 @@ namespace Barotrauma
|
||||
attackPos,
|
||||
AnimController.Limbs.Select(l => l.body.FarseerBody).ToList(),
|
||||
Physics.CollisionCharacter | Physics.CollisionWall);
|
||||
|
||||
|
||||
IDamageable attackTarget = null;
|
||||
if (body != null)
|
||||
{
|
||||
if (body.UserData is IDamageable)
|
||||
{
|
||||
attackTarget = (IDamageable)body.UserData;
|
||||
}
|
||||
else if (body.UserData is Limb)
|
||||
{
|
||||
attackTarget = ((Limb)body.UserData).character;
|
||||
}
|
||||
attackPos = Submarine.LastPickedPosition;
|
||||
|
||||
if (body != null && body.UserData is Submarine)
|
||||
{
|
||||
var sub = ((Submarine)body.UserData);
|
||||
|
||||
body = Submarine.PickBody(
|
||||
attackLimb.SimPosition - ((Submarine)body.UserData).SimPosition,
|
||||
attackPos - ((Submarine)body.UserData).SimPosition,
|
||||
AnimController.Limbs.Select(l => l.body.FarseerBody).ToList(),
|
||||
Physics.CollisionWall);
|
||||
|
||||
if (body != null)
|
||||
{
|
||||
attackPos = Submarine.LastPickedPosition + sub.SimPosition;
|
||||
attackTarget = body.UserData as IDamageable;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (body.UserData is IDamageable)
|
||||
{
|
||||
attackTarget = (IDamageable)body.UserData;
|
||||
}
|
||||
else if (body.UserData is Limb)
|
||||
{
|
||||
attackTarget = ((Limb)body.UserData).character;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
attackLimb.UpdateAttack(deltaTime, attackPos, attackTarget);
|
||||
@@ -1195,6 +1220,10 @@ namespace Barotrauma
|
||||
{
|
||||
if (!Enabled) return;
|
||||
|
||||
PreviousHull = CurrentHull;
|
||||
CurrentHull = Hull.FindHull(WorldPosition, CurrentHull, true);
|
||||
//if (PreviousHull != CurrentHull && Character.Controlled == this) Hull.DetectItemVisibility(this); //WIP item culling
|
||||
|
||||
speechBubbleTimer = Math.Max(0.0f, speechBubbleTimer - deltaTime);
|
||||
|
||||
obstructVisionAmount = Math.Max(obstructVisionAmount - deltaTime, 0.0f);
|
||||
@@ -1406,7 +1435,7 @@ namespace Barotrauma
|
||||
CharacterHUD.Draw(spriteBatch, this, cam);
|
||||
}
|
||||
|
||||
public virtual void DrawFront(SpriteBatch spriteBatch)
|
||||
public virtual void DrawFront(SpriteBatch spriteBatch, Camera cam)
|
||||
{
|
||||
if (!Enabled) return;
|
||||
|
||||
@@ -1424,9 +1453,15 @@ namespace Barotrauma
|
||||
|
||||
if (info != null)
|
||||
{
|
||||
Vector2 namePos = new Vector2(pos.X, pos.Y - 120.0f) - GUI.Font.MeasureString(Info.Name) * 0.5f;
|
||||
spriteBatch.DrawString(GUI.Font, Info.Name, namePos - new Vector2(1.0f, 1.0f), Color.Black);
|
||||
spriteBatch.DrawString(GUI.Font, Info.Name, namePos, Color.White);
|
||||
Vector2 namePos = new Vector2(pos.X, pos.Y - 110.0f - (5.0f/cam.Zoom)) - GUI.Font.MeasureString(Info.Name) * 0.5f / cam.Zoom;
|
||||
Color nameColor = Color.White;
|
||||
|
||||
if (Character.Controlled != null && TeamID!=Character.Controlled.TeamID)
|
||||
{
|
||||
nameColor = Color.Red;
|
||||
}
|
||||
spriteBatch.DrawString(GUI.Font, Info.Name, namePos + new Vector2(1.0f/cam.Zoom, 1.0f / cam.Zoom), Color.Black, 0.0f,Vector2.Zero, 1.0f / cam.Zoom,SpriteEffects.None,0.001f);
|
||||
spriteBatch.DrawString(GUI.Font, Info.Name, namePos, nameColor, 0.0f, Vector2.Zero, 1.0f/cam.Zoom, SpriteEffects.None, 0.0f);
|
||||
|
||||
if (GameMain.DebugDraw)
|
||||
{
|
||||
|
||||
@@ -462,14 +462,14 @@ namespace Barotrauma
|
||||
Vector2 normal = new Vector2(-line.Y, line.X);
|
||||
normal = Vector2.Normalize(-normal);
|
||||
|
||||
float dragDot = Vector2.Dot(normal, velDir);
|
||||
float dragDot = Math.Abs(Vector2.Dot(normal, velDir));
|
||||
Vector2 dragForce = Vector2.Zero;
|
||||
if (dragDot > 0)
|
||||
{
|
||||
float vel = LinearVelocity.Length()*2.0f;
|
||||
float drag = dragDot * vel * vel
|
||||
* ConvertUnits.ToSimUnits(sprite.size.Y);
|
||||
dragForce = drag * -velDir;
|
||||
dragForce = Math.Min(drag, Mass*1000.0f) * -velDir;
|
||||
//if (dragForce.Length() > 100.0f) { }
|
||||
}
|
||||
|
||||
@@ -499,7 +499,8 @@ namespace Barotrauma
|
||||
float dist = ConvertUnits.ToDisplayUnits(Vector2.Distance(SimPosition, attackPosition));
|
||||
|
||||
AttackTimer += deltaTime;
|
||||
body.ApplyTorque(Mass * character.AnimController.Dir * attack.Torque);
|
||||
|
||||
body.ApplyTorque(Mass * character.AnimController.Dir * attack.Torque);
|
||||
|
||||
if (dist < attack.Range * 0.5f)
|
||||
{
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace Barotrauma
|
||||
Structure,
|
||||
Executable,
|
||||
LocationTypes,
|
||||
LevelGenerationPresets,
|
||||
LevelGenerationParameters,
|
||||
RandomEvents,
|
||||
Missions,
|
||||
BackgroundCreaturePrefabs, BackgroundSpritePrefabs
|
||||
|
||||
@@ -86,7 +86,7 @@ namespace Barotrauma
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
DebugConsole.ThrowError("Coroutine " + handle.Name + " threw an exception: " + e.Message);
|
||||
DebugConsole.ThrowError("Coroutine " + handle.Name + " threw an exception: " + e.Message + "\n" + e.StackTrace.ToString());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -240,7 +240,7 @@ namespace Barotrauma
|
||||
break;
|
||||
case "near":
|
||||
case "close":
|
||||
float closestDist = 0.0f;
|
||||
float closestDist = -1.0f;
|
||||
foreach (WayPoint wp in WayPoint.WayPointList)
|
||||
{
|
||||
if (wp.Submarine != null) continue;
|
||||
@@ -250,25 +250,27 @@ namespace Barotrauma
|
||||
|
||||
float dist = Vector2.Distance(wp.WorldPosition, GameMain.GameScreen.Cam.WorldViewCenter);
|
||||
|
||||
if (spawnPoint == null || dist < closestDist)
|
||||
if (closestDist < 0.0f || dist < closestDist)
|
||||
{
|
||||
spawnPoint = wp;
|
||||
closestDist = dist;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "cursor":
|
||||
spawnPosition = GameMain.GameScreen.Cam.ScreenToWorld(PlayerInput.MousePosition);
|
||||
break;
|
||||
default:
|
||||
spawnPoint = WayPoint.GetRandom(commands[1].ToLowerInvariant()=="human" ? SpawnType.Human : SpawnType.Enemy);
|
||||
spawnPoint = WayPoint.GetRandom(commands[1].ToLowerInvariant() == "human" ? SpawnType.Human : SpawnType.Enemy);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
spawnPoint = WayPoint.GetRandom(commands[1].ToLowerInvariant() == "human" ? SpawnType.Human : SpawnType.Enemy);
|
||||
}
|
||||
|
||||
spawnPosition = spawnPoint == null ? Vector2.Zero : spawnPoint.WorldPosition;
|
||||
if (spawnPoint != null) spawnPosition = spawnPoint.WorldPosition;
|
||||
|
||||
if (commands[1].ToLowerInvariant()=="human")
|
||||
{
|
||||
|
||||
@@ -10,15 +10,14 @@ namespace Barotrauma
|
||||
{
|
||||
class CargoMission : Mission
|
||||
{
|
||||
|
||||
private XElement itemConfig;
|
||||
|
||||
private List<Item> items;
|
||||
|
||||
private int requiredDeliveryAmount;
|
||||
|
||||
public CargoMission(XElement element)
|
||||
: base(element)
|
||||
public CargoMission(XElement element, Location[] locations)
|
||||
: base(element, locations)
|
||||
{
|
||||
itemConfig = element.Element("Items");
|
||||
|
||||
@@ -71,7 +70,7 @@ namespace Barotrauma
|
||||
|
||||
Vector2 position = new Vector2(
|
||||
cargoSpawnPos.Position.X + Rand.Range(-20.0f, 20.0f, false),
|
||||
cargoRoom.Rect.Y - cargoRoom.Rect.Height);
|
||||
cargoRoom.Rect.Y - cargoRoom.Rect.Height + itemPrefab.Size.Y / 2);
|
||||
|
||||
var item = new Item(itemPrefab, position, cargoRoom.Submarine);
|
||||
item.FindHull();
|
||||
|
||||
@@ -0,0 +1,231 @@
|
||||
using Barotrauma.Networking;
|
||||
using Microsoft.Xna.Framework;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
class CombatMission : Mission
|
||||
{
|
||||
private Submarine[] subs;
|
||||
private List<Character>[] crews;
|
||||
|
||||
private int state = 0;
|
||||
private int winner = -1;
|
||||
|
||||
private string[] descriptions;
|
||||
|
||||
private static string[] teamNames;
|
||||
|
||||
public override string Description
|
||||
{
|
||||
get
|
||||
{
|
||||
if (GameMain.NetworkMember==null || GameMain.NetworkMember.Character==null)
|
||||
{
|
||||
//non-team-specific description
|
||||
return descriptions[0];
|
||||
}
|
||||
|
||||
//team specific
|
||||
return descriptions[GameMain.NetworkMember.Character.TeamID];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public override string SuccessMessage
|
||||
{
|
||||
get
|
||||
{
|
||||
if (winner == -1) return "";
|
||||
|
||||
return successMessage
|
||||
.Replace("[loser]", teamNames[1 - winner])
|
||||
.Replace("[winner]", teamNames[winner]);
|
||||
}
|
||||
}
|
||||
|
||||
public CombatMission(XElement element, Location[] locations)
|
||||
: base(element, locations)
|
||||
{
|
||||
descriptions = new string[]
|
||||
{
|
||||
ToolBox.GetAttributeString(element, "descriptionneutral", ""),
|
||||
ToolBox.GetAttributeString(element, "description1", ""),
|
||||
ToolBox.GetAttributeString(element, "description2", "")
|
||||
};
|
||||
|
||||
for (int i = 0; i < descriptions.Length; i++ )
|
||||
{
|
||||
for (int n = 0; n < 2;n++ )
|
||||
{
|
||||
descriptions[i] = descriptions[i].Replace("[location" + (n + 1) + "]", Locations[n]);
|
||||
}
|
||||
}
|
||||
|
||||
teamNames = new string[]
|
||||
{
|
||||
ToolBox.GetAttributeString(element, "teamname1", "Team A"),
|
||||
ToolBox.GetAttributeString(element, "teamname2", "Team B")
|
||||
};
|
||||
}
|
||||
|
||||
public static string GetTeamName(int teamID)
|
||||
{
|
||||
//team IDs start from 1, while teamName array starts from 0
|
||||
teamID--;
|
||||
|
||||
if (teamID < 0 || teamID >= teamNames.Length)
|
||||
{
|
||||
return "Team " + teamID;
|
||||
}
|
||||
|
||||
return teamNames[teamID];
|
||||
}
|
||||
|
||||
public override bool AssignTeamIDs(List<Client> clients, out int hostTeam)
|
||||
{
|
||||
List<Client> randList = new List<Client>(clients);
|
||||
for (int i = 0; i < randList.Count; i++)
|
||||
{
|
||||
Client a = randList[i];
|
||||
int oi = Rand.Range(0, randList.Count - 1);
|
||||
Client b = randList[oi];
|
||||
randList[i] = b;
|
||||
randList[oi] = a;
|
||||
}
|
||||
int halfPlayers = randList.Count / 2;
|
||||
for (int i = 0; i < randList.Count; i++)
|
||||
{
|
||||
if (i < halfPlayers)
|
||||
{
|
||||
randList[i].TeamID = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
randList[i].TeamID = 2;
|
||||
}
|
||||
}
|
||||
if (halfPlayers * 2 == randList.Count)
|
||||
{
|
||||
hostTeam = Rand.Range(1, 2);
|
||||
}
|
||||
else if (halfPlayers * 2 < randList.Count)
|
||||
{
|
||||
hostTeam = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
hostTeam = 2;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void Start(Level level)
|
||||
{
|
||||
if (GameMain.Server != null)
|
||||
{
|
||||
GameMain.Server.AllowRespawn = false;
|
||||
}
|
||||
|
||||
if (GameMain.NetworkMember == null)
|
||||
{
|
||||
DebugConsole.ThrowError("Combat missions cannot be played in the single player mode.");
|
||||
return;
|
||||
}
|
||||
|
||||
Items.Components.Radar.StartMarker = Locations[0];
|
||||
Items.Components.Radar.EndMarker = Locations[1];
|
||||
|
||||
subs = new Submarine[] { Submarine.MainSubs[0], Submarine.MainSubs[1] };
|
||||
subs[1].SetPosition(Level.Loaded.EndPosition - new Vector2(0.0f, 2000.0f));
|
||||
subs[1].FlipX();
|
||||
|
||||
crews = new List<Character>[] { new List<Character>(), new List<Character>() };
|
||||
|
||||
foreach (Submarine submarine in Submarine.Loaded)
|
||||
{
|
||||
//hide all subs from radar to make sneak attacks possible
|
||||
submarine.OnRadar = false;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Update(float deltaTime)
|
||||
{
|
||||
if (crews[0].Count == 0 && crews[1].Count == 0)
|
||||
{
|
||||
if (GameMain.Server != null)
|
||||
{
|
||||
GameMain.Server.AllowRespawn = false;
|
||||
}
|
||||
|
||||
foreach (Character character in Character.CharacterList)
|
||||
{
|
||||
if (character.TeamID == 1)
|
||||
{
|
||||
crews[0].Add(character);
|
||||
}
|
||||
else if (character.TeamID == 2)
|
||||
{
|
||||
crews[1].Add(character);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool[] teamDead =
|
||||
{
|
||||
crews[0].All(c => c.IsDead || c.IsUnconscious),
|
||||
crews[1].All(c => c.IsDead || c.IsUnconscious)
|
||||
};
|
||||
|
||||
if (state == 0)
|
||||
{
|
||||
for (int i = 0; i < teamDead.Length; i++)
|
||||
{
|
||||
if (!teamDead[i] && teamDead[1-i])
|
||||
{
|
||||
//make sure nobody in the other team can be revived because that would be pretty weird
|
||||
crews[1-i].ForEach(c => { if (!c.IsDead) c.Kill(CauseOfDeath.Damage); });
|
||||
|
||||
winner = i;
|
||||
|
||||
ShowMessage(i);
|
||||
state = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (winner>=0 && subs[winner] != null &&
|
||||
(winner == 0 && subs[winner].AtStartPosition) || (winner == 1 && subs[winner].AtEndPosition) &&
|
||||
crews[winner].Any(c => !c.IsDead && c.Submarine == subs[winner]))
|
||||
{
|
||||
GameMain.GameSession.CrewManager.WinningTeam = winner+1;
|
||||
if (GameMain.Server != null) GameMain.Server.EndGame();
|
||||
}
|
||||
}
|
||||
|
||||
if (teamDead[0] && teamDead[1])
|
||||
{
|
||||
GameMain.GameSession.CrewManager.WinningTeam = 0;
|
||||
winner = -1;
|
||||
if (GameMain.Server != null) GameMain.Server.EndGame();
|
||||
}
|
||||
}
|
||||
|
||||
public override void End()
|
||||
{
|
||||
if (GameMain.NetworkMember == null) return;
|
||||
|
||||
if (winner > -1)
|
||||
{
|
||||
GiveReward();
|
||||
completed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,12 +27,14 @@ namespace Barotrauma
|
||||
|
||||
private int reward;
|
||||
|
||||
protected string[] Locations = new string[2];
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return name; }
|
||||
}
|
||||
|
||||
public string Description
|
||||
public virtual string Description
|
||||
{
|
||||
get { return description; }
|
||||
}
|
||||
@@ -57,7 +59,7 @@ namespace Barotrauma
|
||||
get { return Vector2.Zero; }
|
||||
}
|
||||
|
||||
public string SuccessMessage
|
||||
virtual public string SuccessMessage
|
||||
{
|
||||
get { return successMessage; }
|
||||
}
|
||||
@@ -86,7 +88,7 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
public Mission(XElement element)
|
||||
public Mission(XElement element, Location[] locations)
|
||||
{
|
||||
name = ToolBox.GetAttributeString(element, "name", "");
|
||||
|
||||
@@ -109,9 +111,24 @@ namespace Barotrauma
|
||||
headers.Add(ToolBox.GetAttributeString(subElement, "header", ""));
|
||||
messages.Add(ToolBox.GetAttributeString(subElement, "text", ""));
|
||||
}
|
||||
|
||||
|
||||
for (int n = 0; n < 2; n++)
|
||||
{
|
||||
Locations[n] = locations[n].Name;
|
||||
description = description.Replace("[location" + (n + 1) + "]", locations[n].Name);
|
||||
|
||||
successMessage = successMessage.Replace("[location" + (n + 1) + "]", locations[n].Name);
|
||||
failureMessage = failureMessage.Replace("[location" + (n + 1) + "]", locations[n].Name);
|
||||
|
||||
for (int m = 0; m < messages.Count; m++)
|
||||
{
|
||||
messages[m] = messages[m].Replace("[location" + (n + 1) + "]", locations[n].Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Mission LoadRandom(Location[] locations, MTRandom rand, string missionType = "")
|
||||
public static Mission LoadRandom(Location[] locations, MTRandom rand, string missionType = "", bool isSinglePlayer = false)
|
||||
{
|
||||
missionType = missionType.ToLowerInvariant();
|
||||
|
||||
@@ -146,8 +163,15 @@ namespace Barotrauma
|
||||
matchingElements = doc.Root.Elements().ToList().FindAll(m => m.Name.ToString().ToLowerInvariant().Replace("mission", "") == missionType);
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (isSinglePlayer)
|
||||
{
|
||||
matchingElements.RemoveAll(m => ToolBox.GetAttributeBool(m, "multiplayeronly", false));
|
||||
}
|
||||
else
|
||||
{
|
||||
matchingElements.RemoveAll(m => ToolBox.GetAttributeBool(m, "singleplayeronly", false));
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
foreach (XElement element in matchingElements)
|
||||
{
|
||||
@@ -182,22 +206,13 @@ namespace Barotrauma
|
||||
DebugConsole.ThrowError("Error in " + configFile + "! Could not find a mission class of the type \"" + type + "\".");
|
||||
continue;
|
||||
}
|
||||
|
||||
ConstructorInfo constructor = t.GetConstructor(new[] { typeof(XElement) });
|
||||
object instance = constructor.Invoke(new object[] { element });
|
||||
|
||||
ConstructorInfo constructor = t.GetConstructor(new[] { typeof(XElement), typeof(Location[]) });
|
||||
|
||||
object instance = constructor.Invoke(new object[] { element, locations });
|
||||
|
||||
Mission mission = (Mission)instance;
|
||||
|
||||
for (int n = 0; n<2; n++)
|
||||
{
|
||||
mission.description = mission.description.Replace("[location"+(n+1)+"]", locations[n].Name);
|
||||
|
||||
mission.successMessage = mission.successMessage.Replace("[location" + (n + 1) + "]", locations[n].Name);
|
||||
mission.failureMessage = mission.failureMessage.Replace("[location" + (n + 1) + "]", locations[n].Name);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return mission;
|
||||
}
|
||||
|
||||
@@ -212,6 +227,8 @@ namespace Barotrauma
|
||||
|
||||
public virtual void Update(float deltaTime) { }
|
||||
|
||||
public virtual bool AssignTeamIDs(List<Networking.Client> clients,out int hostTeam) { clients.ForEach(client => { client.TeamID = 1; }); hostTeam = 1; return false; }
|
||||
|
||||
public void ShowMessage(int index)
|
||||
{
|
||||
if (index >= headers.Count && index >= messages.Count) return;
|
||||
|
||||
@@ -20,25 +20,15 @@ namespace Barotrauma
|
||||
get { return monster != null && !monster.IsDead ? radarPosition : Vector2.Zero; }
|
||||
}
|
||||
|
||||
public MonsterMission(XElement element)
|
||||
: base(element)
|
||||
public MonsterMission(XElement element, Location[] locations)
|
||||
: base(element, locations)
|
||||
{
|
||||
monsterFile = ToolBox.GetAttributeString(element, "monsterfile", "");
|
||||
}
|
||||
|
||||
public override void Start(Level level)
|
||||
{
|
||||
float minDist = Math.Max(Submarine.MainSub.Borders.Width, Submarine.MainSub.Borders.Height);
|
||||
|
||||
//find a random spawnpos that isn't too close to the main sub
|
||||
int tries = 0;
|
||||
Vector2 spawnPos = Vector2.Zero;
|
||||
do
|
||||
{
|
||||
spawnPos = Level.Loaded.GetRandomInterestingPosition(true, Level.PositionType.MainPath);
|
||||
tries++;
|
||||
} while (tries < 50 && Vector2.Distance(spawnPos, Submarine.MainSub.WorldPosition) < minDist);
|
||||
|
||||
Vector2 spawnPos = Level.Loaded.GetRandomInterestingPosition(true, Level.PositionType.MainPath, true);
|
||||
|
||||
monster = Character.Create(monsterFile, spawnPos, null, GameMain.Client != null);
|
||||
monster.Enabled = false;
|
||||
|
||||
@@ -26,8 +26,8 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
public SalvageMission(XElement element)
|
||||
: base(element)
|
||||
public SalvageMission(XElement element, Location[] locations)
|
||||
: base(element, locations)
|
||||
{
|
||||
string itemName = ToolBox.GetAttributeString(element, "itemname", "");
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using System.Xml.Linq;
|
||||
using Microsoft.Xna.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
@@ -14,6 +16,8 @@ namespace Barotrauma
|
||||
|
||||
private bool spawnDeep;
|
||||
|
||||
private bool disallowed;
|
||||
|
||||
private Level.PositionType spawnPosType;
|
||||
|
||||
public override string ToString()
|
||||
@@ -38,6 +42,16 @@ namespace Barotrauma
|
||||
}
|
||||
|
||||
spawnDeep = ToolBox.GetAttributeBool(element, "spawndeep", false);
|
||||
|
||||
if (GameMain.Server != null)
|
||||
{
|
||||
List<string> monsterNames = GameMain.Server.monsterEnabled.Keys.ToList();
|
||||
string tryKey = monsterNames.Find(s => characterFile.ToLower().Contains(s.ToLower()));
|
||||
if (!string.IsNullOrWhiteSpace(tryKey))
|
||||
{
|
||||
if (!GameMain.Server.monsterEnabled[tryKey]) disallowed = true; //spawn was disallowed by host
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Start()
|
||||
@@ -47,29 +61,18 @@ namespace Barotrauma
|
||||
|
||||
private void SpawnMonsters()
|
||||
{
|
||||
float minDist = Math.Max(Submarine.MainSub.Borders.Width, Submarine.MainSub.Borders.Height);
|
||||
|
||||
//find a random spawnpos that isn't too close to the main sub
|
||||
int tries = 0;
|
||||
Vector2 spawnPos = Vector2.Zero;
|
||||
do
|
||||
{
|
||||
spawnPos = Level.Loaded.GetRandomInterestingPosition(true, spawnPosType);
|
||||
tries++;
|
||||
} while (tries < 50 && Vector2.Distance(spawnPos, Submarine.MainSub.WorldPosition) < minDist);
|
||||
|
||||
if (disallowed) return;
|
||||
|
||||
Vector2 spawnPos = Level.Loaded.GetRandomInterestingPosition(true, spawnPosType, true);
|
||||
|
||||
int amount = Rand.Range(minAmount, maxAmount, false);
|
||||
|
||||
monsters = new Character[amount];
|
||||
|
||||
if (spawnDeep) spawnPos.Y -= Level.Loaded.Size.Y;
|
||||
|
||||
for (int i = 0; i < amount; i++)
|
||||
{
|
||||
if (spawnDeep)
|
||||
{
|
||||
spawnPos.Y -= Level.Loaded.Size.Y;
|
||||
}
|
||||
|
||||
spawnPos.X += Rand.Range(-0.5f, 0.5f, false);
|
||||
spawnPos.Y += Rand.Range(-0.5f, 0.5f, false);
|
||||
monsters[i] = Character.Create(characterFile, spawnPos, null, GameMain.Client != null);
|
||||
@@ -78,6 +81,11 @@ namespace Barotrauma
|
||||
|
||||
public override void Update(float deltaTime)
|
||||
{
|
||||
if (disallowed)
|
||||
{
|
||||
Finished();
|
||||
return;
|
||||
}
|
||||
if (monsters == null) SpawnMonsters();
|
||||
|
||||
//base.Update(deltaTime);
|
||||
|
||||
@@ -65,12 +65,12 @@ namespace Barotrauma
|
||||
while (tries < 5)
|
||||
{
|
||||
ScriptedEvent scriptedEvent = ScriptedEvent.LoadRandom(rand);
|
||||
DebugConsole.Log("Created scripted event "+scriptedEvent.ToString());
|
||||
if (scriptedEvent==null || scriptedEvent.Difficulty > totalDifficulty)
|
||||
{
|
||||
tries++;
|
||||
continue;
|
||||
}
|
||||
DebugConsole.Log("Created scripted event " + scriptedEvent.ToString());
|
||||
|
||||
AddTask(new ScriptedTask(scriptedEvent));
|
||||
totalDifficulty -= scriptedEvent.Difficulty;
|
||||
|
||||
@@ -241,12 +241,22 @@ namespace Barotrauma
|
||||
sb.DrawString(font, text, pos, color);
|
||||
}
|
||||
|
||||
public static void DrawRectangle(SpriteBatch sb, Vector2 start, Vector2 size, Color clr, bool isFilled = false, float depth = 0.0f)
|
||||
public static void DrawRectangle(SpriteBatch sb, Vector2 start, Vector2 size, Color clr, bool isFilled = false, float depth = 0.0f, int thickness = 1)
|
||||
{
|
||||
DrawRectangle(sb, new Rectangle((int)start.X, (int)start.Y, (int)size.X, (int)size.Y), clr, isFilled, depth);
|
||||
if (size.X < 0)
|
||||
{
|
||||
start.X += size.X;
|
||||
size.X = -size.X;
|
||||
}
|
||||
if (size.Y < 0)
|
||||
{
|
||||
start.Y += size.Y;
|
||||
size.Y = -size.Y;
|
||||
}
|
||||
DrawRectangle(sb, new Rectangle((int)start.X, (int)start.Y, (int)size.X, (int)size.Y), clr, isFilled, depth, thickness);
|
||||
}
|
||||
|
||||
public static void DrawRectangle(SpriteBatch sb, Rectangle rect, Color clr, bool isFilled = false, float depth = 0.0f)
|
||||
public static void DrawRectangle(SpriteBatch sb, Rectangle rect, Color clr, bool isFilled = false, float depth = 0.0f, int thickness = 1)
|
||||
{
|
||||
if (isFilled)
|
||||
{
|
||||
@@ -254,10 +264,10 @@ namespace Barotrauma
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.Draw(t, new Rectangle(rect.X, rect.Y, rect.Width, 1), null, clr, 0.0f, Vector2.Zero, SpriteEffects.None, depth);
|
||||
sb.Draw(t, new Rectangle(rect.X, rect.Y+rect.Height-1, rect.Width, 1), null, clr, 0.0f, Vector2.Zero, SpriteEffects.None, depth);
|
||||
sb.Draw(t, new Rectangle(rect.X, rect.Y, 1, rect.Height), null, clr, 0.0f, Vector2.Zero, SpriteEffects.None, depth);
|
||||
sb.Draw(t, new Rectangle(rect.X+rect.Width-1, rect.Y, 1, rect.Height), null, clr, 0.0f, Vector2.Zero, SpriteEffects.None, depth);
|
||||
sb.Draw(t, new Rectangle(rect.X, rect.Y, rect.Width, thickness), null, clr, 0.0f, Vector2.Zero, SpriteEffects.None, depth);
|
||||
sb.Draw(t, new Rectangle(rect.X, rect.Y+rect.Height- thickness, rect.Width, thickness), null, clr, 0.0f, Vector2.Zero, SpriteEffects.None, depth);
|
||||
sb.Draw(t, new Rectangle(rect.X, rect.Y, thickness, rect.Height), null, clr, 0.0f, Vector2.Zero, SpriteEffects.None, depth);
|
||||
sb.Draw(t, new Rectangle(rect.X+rect.Width- thickness, rect.Y, thickness, rect.Height), null, clr, 0.0f, Vector2.Zero, SpriteEffects.None, depth);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -439,6 +449,33 @@ namespace Barotrauma
|
||||
"Sub pos: " + Submarine.MainSub.Position.ToPoint(),
|
||||
new Vector2(10, 50), Color.White);
|
||||
}
|
||||
|
||||
for (int i = 1; i < Sounds.SoundManager.DefaultSourceCount; i++)
|
||||
{
|
||||
Color clr = Color.White;
|
||||
|
||||
string soundStr = i+": ";
|
||||
|
||||
var playingSound = Sounds.SoundManager.GetPlayingSound(i);
|
||||
|
||||
if (playingSound == null)
|
||||
{
|
||||
soundStr+= "none";
|
||||
clr *= 0.5f;
|
||||
}
|
||||
else
|
||||
{
|
||||
soundStr += System.IO.Path.GetFileNameWithoutExtension(playingSound.FilePath);
|
||||
|
||||
if (Sounds.SoundManager.IsLooping(i))
|
||||
{
|
||||
soundStr += " (looping)";
|
||||
clr = Color.Yellow;
|
||||
}
|
||||
}
|
||||
|
||||
GUI.DrawString(spriteBatch, new Vector2(200, i * 15), soundStr, clr, Color.Black * 0.5f, 0, GUI.SmallFont);
|
||||
}
|
||||
}
|
||||
|
||||
if (GameMain.NetworkMember != null) GameMain.NetworkMember.Draw(spriteBatch);
|
||||
@@ -472,12 +509,12 @@ namespace Barotrauma
|
||||
{
|
||||
if (pauseMenuOpen)
|
||||
{
|
||||
pauseMenu.Update(0.016f);
|
||||
pauseMenu.Update(deltaTime);
|
||||
}
|
||||
|
||||
if (settingsMenuOpen)
|
||||
{
|
||||
GameMain.Config.SettingsFrame.Update(0.016f);
|
||||
GameMain.Config.SettingsFrame.Update(deltaTime);
|
||||
}
|
||||
|
||||
if (GUIMessageBox.MessageBoxes.Count > 0)
|
||||
|
||||
@@ -116,6 +116,21 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
public override Rectangle Rect
|
||||
{
|
||||
get
|
||||
{
|
||||
return rect;
|
||||
}
|
||||
set
|
||||
{
|
||||
base.Rect = value;
|
||||
|
||||
frame.Rect = new Rectangle(value.X, value.Y, frame.Rect.Width, frame.Rect.Height);
|
||||
textBlock.Rect = value;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Selected { get; set; }
|
||||
|
||||
public GUIButton(Rectangle rect, string text, GUIStyle style, GUIComponent parent = null)
|
||||
@@ -183,6 +198,25 @@ namespace Barotrauma
|
||||
|
||||
base.Update(deltaTime);
|
||||
|
||||
//Color currColor = color;
|
||||
//if (state == ComponentState.Hover) currColor = hoverColor;
|
||||
//if (state == ComponentState.Selected) currColor = selectedColor;
|
||||
|
||||
//GUI.DrawRectangle(spriteBatch, rect, currColor * alpha, true);
|
||||
|
||||
////spriteBatch.DrawString(HUD.font, text, new Vector2(rect.X+rect.Width/2, rect.Y+rect.Height/2), Color.Black, 0.0f, new Vector2(0.5f,0.5f), 1.0f, SpriteEffects.None, 0.0f);
|
||||
|
||||
//GUI.DrawRectangle(spriteBatch, rect, Color.Black * alpha, false);
|
||||
|
||||
DrawChildren(spriteBatch);
|
||||
|
||||
//if (!Enabled) GUI.DrawRectangle(spriteBatch, rect, Color.Gray*0.5f, true);
|
||||
}
|
||||
|
||||
public override void Update(float deltaTime)
|
||||
{
|
||||
if (!Visible) return;
|
||||
base.Update(deltaTime);
|
||||
if (rect.Contains(PlayerInput.MousePosition) && CanBeSelected && Enabled && (MouseOn == null || MouseOn == this || IsParentOf(MouseOn)))
|
||||
{
|
||||
state = ComponentState.Hover;
|
||||
@@ -196,7 +230,6 @@ namespace Barotrauma
|
||||
else if (PlayerInput.LeftButtonClicked())
|
||||
{
|
||||
GUI.PlayUISound(GUISoundType.Click);
|
||||
|
||||
if (OnClicked != null)
|
||||
{
|
||||
if (OnClicked(this, UserData) && CanBeSelected) state = ComponentState.Selected;
|
||||
@@ -212,7 +245,6 @@ namespace Barotrauma
|
||||
{
|
||||
state = Selected ? ComponentState.Selected : ComponentState.None;
|
||||
}
|
||||
|
||||
frame.State = state;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -286,9 +286,15 @@ namespace Barotrauma
|
||||
toolTipBlock.rect.Height = toolTipBlock.WrappedText.Split('\n').Length * 18;
|
||||
toolTipBlock.Color = Color.Black * 0.7f;
|
||||
toolTipBlock.userData = ToolTip;
|
||||
|
||||
}
|
||||
|
||||
toolTipBlock.rect = new Rectangle(MouseOn.Rect.Center.X, MouseOn.rect.Bottom, toolTipBlock.rect.Width, toolTipBlock.rect.Height);
|
||||
if (toolTipBlock.rect.Right > GameMain.GraphicsWidth - 10)
|
||||
{
|
||||
toolTipBlock.rect.Location -= new Point(toolTipBlock.rect.Right - (GameMain.GraphicsWidth - 10), 0);
|
||||
}
|
||||
|
||||
toolTipBlock.Draw(spriteBatch);
|
||||
}
|
||||
|
||||
|
||||
@@ -103,15 +103,6 @@ namespace Barotrauma
|
||||
get { return scrollBarEnabled; }
|
||||
set
|
||||
{
|
||||
if (value)
|
||||
{
|
||||
if (!scrollBarEnabled && scrollBarHidden) ShowScrollBar();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (scrollBarEnabled && !scrollBarHidden) HideScrollBar();
|
||||
}
|
||||
|
||||
scrollBarEnabled = value;
|
||||
}
|
||||
}
|
||||
@@ -122,7 +113,7 @@ namespace Barotrauma
|
||||
}
|
||||
|
||||
public GUIListBox(Rectangle rect, GUIStyle style, Alignment alignment, GUIComponent parent = null)
|
||||
: this(rect, null, style, parent)
|
||||
: this(rect, null, alignment, style, parent, false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -185,11 +176,101 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateChildrenRect(float deltaTime)
|
||||
{
|
||||
int x = rect.X, y = rect.Y;
|
||||
|
||||
if (!scrollBarHidden)
|
||||
{
|
||||
if (scrollBar.IsHorizontal)
|
||||
{
|
||||
x -= (int)((totalSize - rect.Width) * scrollBar.BarScroll);
|
||||
}
|
||||
else
|
||||
{
|
||||
y -= (int)((totalSize - rect.Height) * scrollBar.BarScroll);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < children.Count; i++)
|
||||
{
|
||||
GUIComponent child = children[i];
|
||||
if (child == frame || !child.Visible) continue;
|
||||
|
||||
child.Rect = new Rectangle(x, y, child.Rect.Width, child.Rect.Height);
|
||||
if (scrollBar.IsHorizontal)
|
||||
{
|
||||
x += child.Rect.Width + spacing;
|
||||
}
|
||||
else
|
||||
{
|
||||
y += child.Rect.Height + spacing;
|
||||
}
|
||||
|
||||
|
||||
if (scrollBar.IsHorizontal)
|
||||
{
|
||||
if (child.Rect.Right < rect.X) continue;
|
||||
if (child.Rect.Right > rect.Right) break;
|
||||
|
||||
if (child.Rect.X < rect.X && child.Rect.Right >= rect.X)
|
||||
{
|
||||
x = rect.X;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (child.Rect.Y + child.Rect.Height < rect.Y) continue;
|
||||
if (child.Rect.Y + child.Rect.Height > rect.Y + rect.Height) break;
|
||||
|
||||
if (child.Rect.Y < rect.Y && child.Rect.Y + child.Rect.Height >= rect.Y)
|
||||
{
|
||||
y = rect.Y;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (deltaTime>0.0f) child.Update(deltaTime);
|
||||
if (enabled && child.CanBeFocused &&
|
||||
(MouseOn == this || (MouseOn != null && this.IsParentOf(MouseOn))) && child.Rect.Contains(PlayerInput.MousePosition))
|
||||
{
|
||||
child.State = ComponentState.Hover;
|
||||
if (PlayerInput.LeftButtonClicked())
|
||||
{
|
||||
Debug.WriteLine("clicked");
|
||||
Select(i);
|
||||
//selected = child;
|
||||
//if (OnSelected != null)
|
||||
//{
|
||||
// if (!OnSelected(selected, child.UserData)) selected = null;
|
||||
//}
|
||||
|
||||
}
|
||||
}
|
||||
else if (selected.Contains(child))
|
||||
{
|
||||
child.State = ComponentState.Selected;
|
||||
|
||||
if (CheckSelected != null)
|
||||
{
|
||||
if (CheckSelected() != child.UserData) selected.Remove(child);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
child.State = ComponentState.None;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void Update(float deltaTime)
|
||||
{
|
||||
if (!Visible) return;
|
||||
|
||||
base.Update(deltaTime);
|
||||
UpdateChildrenRect(deltaTime);
|
||||
|
||||
//base.Update(deltaTime);
|
||||
|
||||
if (scrollBarEnabled && !scrollBarHidden) scrollBar.Update(deltaTime);
|
||||
|
||||
@@ -277,17 +358,28 @@ namespace Barotrauma
|
||||
Math.Max(Math.Min((float)rect.Width / (float)totalSize, 1.0f), 5.0f / rect.Width) :
|
||||
Math.Max(Math.Min((float)rect.Height / (float)totalSize, 1.0f), 5.0f / rect.Height);
|
||||
|
||||
if (scrollBar.BarSize < 1.0f && scrollBarHidden) ShowScrollBar();
|
||||
if (scrollBar.BarSize >= 1.0f && !scrollBarHidden) HideScrollBar();
|
||||
scrollBarHidden = scrollBar.BarSize >= 1.0f;
|
||||
}
|
||||
|
||||
public override void AddChild(GUIComponent child)
|
||||
{
|
||||
//temporarily reduce the size of the rect to prevent the child from expanding over the scrollbar
|
||||
if (scrollBar.IsHorizontal)
|
||||
rect.Height -= scrollBar.Rect.Height;
|
||||
else
|
||||
rect.Width -= scrollBar.Rect.Width;
|
||||
|
||||
base.AddChild(child);
|
||||
|
||||
if (scrollBar.IsHorizontal)
|
||||
rect.Height += scrollBar.Rect.Height;
|
||||
else
|
||||
rect.Width += scrollBar.Rect.Width;
|
||||
|
||||
//float oldScroll = scrollBar.BarScroll;
|
||||
//float oldSize = scrollBar.BarSize;
|
||||
UpdateScrollBarSize();
|
||||
UpdateChildrenRect(0.0f);
|
||||
|
||||
//if (oldSize == 1.0f && scrollBar.BarScroll == 0.0f) scrollBar.BarScroll = 1.0f;
|
||||
|
||||
@@ -312,25 +404,12 @@ namespace Barotrauma
|
||||
|
||||
UpdateScrollBarSize();
|
||||
}
|
||||
|
||||
private void ShowScrollBar()
|
||||
{
|
||||
if (scrollBarHidden && !scrollBar.IsHorizontal) Rect = new Rectangle(rect.X, rect.Y, rect.Width - scrollBar.Rect.Width, rect.Height);
|
||||
scrollBarHidden = false;
|
||||
|
||||
}
|
||||
|
||||
private void HideScrollBar()
|
||||
{
|
||||
if (!scrollBarHidden && !scrollBar.IsHorizontal) Rect = new Rectangle(rect.X, rect.Y, rect.Width + scrollBar.Rect.Width, rect.Height);
|
||||
scrollBarHidden = true;
|
||||
}
|
||||
|
||||
|
||||
public override void Draw(SpriteBatch spriteBatch)
|
||||
{
|
||||
if (!Visible) return;
|
||||
|
||||
base.Draw(spriteBatch);
|
||||
//base.Draw(spriteBatch);
|
||||
|
||||
frame.Draw(spriteBatch);
|
||||
//GUI.DrawRectangle(spriteBatch, rect, color*alpha, true);
|
||||
@@ -355,7 +434,6 @@ namespace Barotrauma
|
||||
GUIComponent child = children[i];
|
||||
if (child == frame || !child.Visible) continue;
|
||||
|
||||
child.Rect = new Rectangle(x, y, child.Rect.Width, child.Rect.Height);
|
||||
if (scrollBar.IsHorizontal)
|
||||
{
|
||||
x += child.Rect.Width + spacing;
|
||||
|
||||
@@ -61,7 +61,12 @@ namespace Barotrauma
|
||||
set
|
||||
{
|
||||
if (base.Rect == value) return;
|
||||
base.Rect = value;
|
||||
foreach (GUIComponent child in children)
|
||||
{
|
||||
child.Rect = new Rectangle(child.Rect.X + value.X - rect.X, child.Rect.Y + value.Y - rect.Y, child.Rect.Width, child.Rect.Height);
|
||||
}
|
||||
|
||||
rect = value;
|
||||
SetTextPos();
|
||||
}
|
||||
}
|
||||
@@ -163,7 +168,7 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
private void SetTextPos()
|
||||
public void SetTextPos()
|
||||
{
|
||||
if (text==null) return;
|
||||
|
||||
|
||||
@@ -40,6 +40,21 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
public override Rectangle Rect
|
||||
{
|
||||
get
|
||||
{
|
||||
return rect;
|
||||
}
|
||||
set
|
||||
{
|
||||
base.Rect = value;
|
||||
|
||||
box.Rect = new Rectangle(value.X,value.Y,box.Rect.Width,box.Rect.Height);
|
||||
text.Rect = new Rectangle(box.Rect.Right + 10, box.Rect.Y + 2, 20, box.Rect.Height);
|
||||
}
|
||||
}
|
||||
|
||||
public GUITickBox(Rectangle rect, string label, Alignment alignment, GUIComponent parent)
|
||||
: this(rect, label, alignment, GUI.Font, parent)
|
||||
{
|
||||
|
||||
@@ -78,7 +78,7 @@ namespace Barotrauma
|
||||
|
||||
//private Stopwatch renderTimer;
|
||||
//public static int renderTimeElapsed;
|
||||
|
||||
|
||||
public Camera Cam
|
||||
{
|
||||
get { return GameScreen.Cam; }
|
||||
@@ -295,21 +295,25 @@ namespace Barotrauma
|
||||
Timing.Accumulator += gameTime.ElapsedGameTime.TotalSeconds;
|
||||
PlayerInput.UpdateVariable();
|
||||
|
||||
bool paused = true;
|
||||
|
||||
while (Timing.Accumulator >= Timing.Step)
|
||||
{
|
||||
fixedTime.IsRunningSlowly = gameTime.IsRunningSlowly;
|
||||
TimeSpan addTime = new TimeSpan(0,0,0,0,16);
|
||||
TimeSpan addTime = new TimeSpan(0, 0, 0, 0, 16);
|
||||
fixedTime.ElapsedGameTime = addTime;
|
||||
fixedTime.TotalGameTime.Add(addTime);
|
||||
base.Update(fixedTime);
|
||||
|
||||
PlayerInput.Update(Timing.Step);
|
||||
|
||||
bool paused = false;
|
||||
|
||||
if (titleScreenOpen)
|
||||
{
|
||||
//TitleScreen.Update();
|
||||
if (TitleScreen.LoadState >= 100.0f &&
|
||||
(!waitForKeyHit || PlayerInput.GetKeyboardState.GetPressedKeys().Length>0 || PlayerInput.LeftButtonClicked()))
|
||||
{
|
||||
titleScreenOpen = false;
|
||||
}
|
||||
}
|
||||
else if (hasLoaded)
|
||||
{
|
||||
@@ -321,7 +325,7 @@ namespace Barotrauma
|
||||
|
||||
paused = (DebugConsole.IsOpen || GUI.PauseMenuOpen || GUI.SettingsMenuOpen) &&
|
||||
(NetworkMember == null || !NetworkMember.GameStarted);
|
||||
|
||||
|
||||
if (!paused)
|
||||
{
|
||||
Screen.Selected.Update(Timing.Step);
|
||||
@@ -334,13 +338,14 @@ namespace Barotrauma
|
||||
|
||||
GUI.Update((float)Timing.Step);
|
||||
}
|
||||
|
||||
|
||||
CoroutineManager.Update((float)Timing.Step, paused ? 0.0f : (float)Timing.Step);
|
||||
|
||||
Timing.Accumulator -= Timing.Step;
|
||||
}
|
||||
|
||||
Timing.Alpha = Timing.Accumulator / Timing.Step;
|
||||
if (!paused) Timing.Alpha = Timing.Accumulator / Timing.Step;
|
||||
}
|
||||
|
||||
|
||||
@@ -349,8 +354,6 @@ namespace Barotrauma
|
||||
/// </summary>
|
||||
protected override void Draw(GameTime gameTime)
|
||||
{
|
||||
//renderTimer.Restart();
|
||||
|
||||
double deltaTime = gameTime.ElapsedGameTime.TotalSeconds;
|
||||
|
||||
FrameCounter.Update(deltaTime);
|
||||
@@ -358,22 +361,11 @@ namespace Barotrauma
|
||||
if (titleScreenOpen)
|
||||
{
|
||||
TitleScreen.Draw(spriteBatch, GraphicsDevice, (float)deltaTime);
|
||||
if (TitleScreen.LoadState>=100.0f &&
|
||||
(!waitForKeyHit || PlayerInput.GetKeyboardState.GetPressedKeys().Length>0 || PlayerInput.LeftButtonClicked()))
|
||||
{
|
||||
titleScreenOpen = false;
|
||||
}
|
||||
}
|
||||
else if (hasLoaded)
|
||||
{
|
||||
Screen.Selected.Draw(deltaTime, GraphicsDevice, spriteBatch);
|
||||
}
|
||||
|
||||
//double elapsed = sw.Elapsed.TotalSeconds;
|
||||
//if (elapsed < Physics.step)
|
||||
//{
|
||||
// System.Threading.Thread.Sleep((int)((Physics.step - elapsed) * 1000.0));
|
||||
//}
|
||||
}
|
||||
|
||||
static bool waitForKeyHit = true;
|
||||
|
||||
@@ -5,14 +5,14 @@ namespace Barotrauma
|
||||
{
|
||||
class CargoManager
|
||||
{
|
||||
private List<MapEntityPrefab> purchasedItems;
|
||||
private List<ItemPrefab> purchasedItems;
|
||||
|
||||
public CargoManager()
|
||||
{
|
||||
purchasedItems = new List<MapEntityPrefab>();
|
||||
purchasedItems = new List<ItemPrefab>();
|
||||
}
|
||||
|
||||
public void AddItem(MapEntityPrefab item)
|
||||
public void AddItem(ItemPrefab item)
|
||||
{
|
||||
purchasedItems.Add(item);
|
||||
}
|
||||
@@ -35,11 +35,11 @@ namespace Barotrauma
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (MapEntityPrefab prefab in purchasedItems)
|
||||
foreach (ItemPrefab prefab in purchasedItems)
|
||||
{
|
||||
Vector2 position = new Vector2(
|
||||
Rand.Range(cargoRoom.Rect.X + 20, cargoRoom.Rect.Right - 20),
|
||||
Rand.Range(cargoRoom.Rect.Y - cargoRoom.Rect.Height, cargoRoom.Rect.Y));
|
||||
cargoRoom.Rect.Y - cargoRoom.Rect.Height + prefab.Size.Y/2);
|
||||
|
||||
new Item(prefab as ItemPrefab, position, wp.Submarine);
|
||||
}
|
||||
|
||||
@@ -12,6 +12,8 @@ namespace Barotrauma
|
||||
{
|
||||
public List<Character> characters;
|
||||
public List<CharacterInfo> characterInfos;
|
||||
|
||||
public int WinningTeam = 1;
|
||||
|
||||
private int money;
|
||||
|
||||
@@ -206,35 +208,48 @@ namespace Barotrauma
|
||||
|
||||
public void CreateCrewFrame(List<Character> crew, GUIFrame crewFrame)
|
||||
{
|
||||
//crewFrame = new GUIFrame(new Rectangle(GameMain.GraphicsWidth / 2 - width / 2, GameMain.GraphicsHeight / 2 - height / 2, width, height), GUI.Style);
|
||||
//crewFrame.Padding = new Vector4(10.0f, 10.0f, 10.0f, 10.0f);
|
||||
List<byte> teamIDs = crew.Select(c => c.TeamID).Distinct().ToList();
|
||||
|
||||
GUIListBox crewList = new GUIListBox(new Rectangle(0, 0, 280, 300), Color.White * 0.7f, GUI.Style, crewFrame);
|
||||
crewList.Padding = new Vector4(10.0f, 10.0f, 10.0f, 10.0f);
|
||||
crewList.OnSelected = SelectCrewCharacter;
|
||||
if (!teamIDs.Any()) teamIDs.Add(0);
|
||||
|
||||
foreach (Character character in crew)
|
||||
int listBoxHeight = 300 / teamIDs.Count;
|
||||
|
||||
int y = 20;
|
||||
for (int i = 0; i < teamIDs.Count; i++)
|
||||
{
|
||||
GUIFrame frame = new GUIFrame(new Rectangle(0, 0, 0, 40), Color.Transparent, null, crewList);
|
||||
frame.UserData = character;
|
||||
frame.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f);
|
||||
frame.Color = (GameMain.NetworkMember != null && GameMain.NetworkMember.Character == character) ? Color.Gold * 0.2f : Color.Transparent;
|
||||
frame.HoverColor = Color.LightGray * 0.5f;
|
||||
frame.SelectedColor = Color.Gold * 0.5f;
|
||||
if (teamIDs.Count > 1)
|
||||
{
|
||||
new GUITextBlock(new Rectangle(0, y - 20, 100, 20), CombatMission.GetTeamName(teamIDs[i]), GUI.Style, crewFrame);
|
||||
}
|
||||
|
||||
GUITextBlock textBlock = new GUITextBlock(
|
||||
new Rectangle(40, 0, 0, 25),
|
||||
character.Info.Name + " (" + character.Info.Job.Name + ")",
|
||||
Color.Transparent, Color.White,
|
||||
Alignment.Left, Alignment.Left,
|
||||
null, frame);
|
||||
textBlock.Padding = new Vector4(5.0f, 0.0f, 5.0f, 0.0f);
|
||||
GUIListBox crewList = new GUIListBox(new Rectangle(0, y, 280, listBoxHeight), Color.White * 0.7f, GUI.Style, crewFrame);
|
||||
crewList.Padding = new Vector4(10.0f, 10.0f, 10.0f, 10.0f);
|
||||
crewList.OnSelected = SelectCrewCharacter;
|
||||
|
||||
foreach (Character character in crew.FindAll(c => c.TeamID == teamIDs[i]))
|
||||
{
|
||||
GUIFrame frame = new GUIFrame(new Rectangle(0, 0, 0, 40), Color.Transparent, null, crewList);
|
||||
frame.UserData = character;
|
||||
frame.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f);
|
||||
frame.Color = (GameMain.NetworkMember != null && GameMain.NetworkMember.Character == character) ? Color.Gold * 0.2f : Color.Transparent;
|
||||
frame.HoverColor = Color.LightGray * 0.5f;
|
||||
frame.SelectedColor = Color.Gold * 0.5f;
|
||||
|
||||
new GUIImage(new Rectangle(-10, 0, 0, 0), character.AnimController.Limbs[0].sprite, Alignment.Left, frame);
|
||||
GUITextBlock textBlock = new GUITextBlock(
|
||||
new Rectangle(40, 0, 0, 25),
|
||||
character.Info.Name + " (" + character.Info.Job.Name + ")",
|
||||
Color.Transparent, Color.White,
|
||||
Alignment.Left, Alignment.Left,
|
||||
null, frame);
|
||||
textBlock.Padding = new Vector4(5.0f, 0.0f, 5.0f, 0.0f);
|
||||
|
||||
new GUIImage(new Rectangle(-10, 0, 0, 0), character.AnimController.Limbs[0].sprite, Alignment.Left, frame);
|
||||
}
|
||||
|
||||
y += crewList.Rect.Height + 30;
|
||||
}
|
||||
|
||||
//var closeButton = new GUIButton(new Rectangle(0, 0, 80, 20), "Close", Alignment.BottomCenter, GUI.Style, crewFrame);
|
||||
//closeButton.OnClicked = ToggleCrewFrame;
|
||||
|
||||
}
|
||||
|
||||
protected virtual bool SelectCrewCharacter(GUIComponent component, object obj)
|
||||
|
||||
@@ -75,6 +75,8 @@ namespace Barotrauma
|
||||
isRunning = true;
|
||||
}
|
||||
|
||||
public virtual void MsgBox() { }
|
||||
|
||||
public virtual void Update(float deltaTime)
|
||||
{
|
||||
//if (!isRunning) return;
|
||||
|
||||
@@ -29,13 +29,12 @@ namespace Barotrauma
|
||||
mission = Mission.LoadRandom(locations, rand, param as string);
|
||||
}
|
||||
|
||||
public override void Start()
|
||||
public override void MsgBox()
|
||||
{
|
||||
base.Start();
|
||||
|
||||
if (mission == null) return;
|
||||
|
||||
new GUIMessageBox(mission.Name, mission.Description, 400, 400);
|
||||
var missionMsg = new GUIMessageBox(mission.Name, mission.Description, 400, 400);
|
||||
missionMsg.UserData = "missionstartmessage";
|
||||
|
||||
Networking.GameServer.Log("Mission: " + mission.Name, Color.Cyan);
|
||||
Networking.GameServer.Log(mission.Description, Color.Cyan);
|
||||
|
||||
@@ -26,6 +26,11 @@ namespace Barotrauma
|
||||
|
||||
private bool savedOnStart;
|
||||
|
||||
private List<Submarine> subsToLeaveBehind;
|
||||
|
||||
private Submarine leavingSub;
|
||||
private bool atEndPosition;
|
||||
|
||||
public override Mission Mission
|
||||
{
|
||||
get
|
||||
@@ -80,18 +85,28 @@ namespace Barotrauma
|
||||
|
||||
public SinglePlayerMode(XElement element)
|
||||
: this(GameModePreset.list.Find(gm => gm.Name == "Single Player"), null)
|
||||
{
|
||||
string mapSeed = ToolBox.GetAttributeString(element, "mapseed", "a");
|
||||
|
||||
GenerateMap(mapSeed);
|
||||
|
||||
Map.SetLocation(ToolBox.GetAttributeInt(element, "currentlocation", 0));
|
||||
|
||||
{
|
||||
foreach (XElement subElement in element.Elements())
|
||||
{
|
||||
if (subElement.Name.ToString().ToLowerInvariant() != "crew") continue;
|
||||
|
||||
GameMain.GameSession.CrewManager = new CrewManager(subElement);
|
||||
switch (subElement.Name.ToString().ToLowerInvariant())
|
||||
{
|
||||
case "crew":
|
||||
GameMain.GameSession.CrewManager = new CrewManager(subElement);
|
||||
break;
|
||||
case "map":
|
||||
Map = Map.Load(subElement);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//backwards compatibility with older save files
|
||||
if (Map==null)
|
||||
{
|
||||
string mapSeed = ToolBox.GetAttributeString(element, "mapseed", "a");
|
||||
|
||||
GenerateMap(mapSeed);
|
||||
|
||||
Map.SetLocation(ToolBox.GetAttributeInt(element, "currentlocation", 0));
|
||||
}
|
||||
|
||||
savedOnStart = true;
|
||||
@@ -198,12 +213,6 @@ namespace Barotrauma
|
||||
}
|
||||
|
||||
endShiftButton.Draw(spriteBatch);
|
||||
//chatBox.Draw(spriteBatch);
|
||||
//textBox.Draw(spriteBatch);
|
||||
|
||||
//timerBar.Draw(spriteBatch);
|
||||
|
||||
//if (Game1.Client == null) endShiftButton.Draw(spriteBatch);
|
||||
}
|
||||
|
||||
public override void Update(float deltaTime)
|
||||
@@ -230,30 +239,33 @@ namespace Barotrauma
|
||||
|
||||
public override void End(string endMessage = "")
|
||||
{
|
||||
|
||||
isRunning = false;
|
||||
|
||||
//if (endMessage != "" || this.endMessage == null) this.endMessage = endMessage;
|
||||
|
||||
bool success = CrewManager.characters.Any(c => !c.IsDead);
|
||||
|
||||
if (success)
|
||||
{
|
||||
if (subsToLeaveBehind == null || leavingSub == null)
|
||||
{
|
||||
DebugConsole.ThrowError("Leaving submarine not selected -> selecting the closest one");
|
||||
|
||||
leavingSub = GetLeavingSub();
|
||||
|
||||
subsToLeaveBehind = GetSubsToLeaveBehind(leavingSub);
|
||||
}
|
||||
}
|
||||
|
||||
GameMain.GameSession.EndShift("");
|
||||
|
||||
if (success)
|
||||
{
|
||||
var leavingSub = GetLeavingSub();
|
||||
|
||||
if (!Submarine.MainSub.AtEndPosition && !Submarine.MainSub.AtStartPosition)
|
||||
if (leavingSub != Submarine.MainSub && !leavingSub.DockedTo.Contains(Submarine.MainSub))
|
||||
{
|
||||
System.Diagnostics.Debug.Assert(leavingSub != Submarine.MainSub);
|
||||
|
||||
Submarine oldMainSub = Submarine.MainSub;
|
||||
Submarine.MainSub = leavingSub;
|
||||
|
||||
GameMain.GameSession.Submarine = leavingSub;
|
||||
|
||||
List<Submarine> subsToLeaveBehind = GetSubsToLeaveBehind(leavingSub);
|
||||
|
||||
|
||||
foreach (Submarine sub in subsToLeaveBehind)
|
||||
{
|
||||
MapEntity.mapEntityList.RemoveAll(e => e.Submarine == sub && e is LinkedSubmarine);
|
||||
@@ -261,13 +273,11 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (Submarine.MainSub.AtEndPosition)
|
||||
if (atEndPosition)
|
||||
{
|
||||
Map.MoveToNextLocation();
|
||||
}
|
||||
|
||||
|
||||
SaveUtil.SaveGame(GameMain.GameSession.SaveFile);
|
||||
}
|
||||
|
||||
@@ -302,18 +312,18 @@ namespace Barotrauma
|
||||
|
||||
private bool TryEndShift(GUIButton button, object obj)
|
||||
{
|
||||
List<Submarine> subsNotDocked = new List<Submarine>();
|
||||
|
||||
var leavingSub = obj as Submarine;
|
||||
leavingSub = obj as Submarine;
|
||||
if (leavingSub != null)
|
||||
{
|
||||
subsNotDocked = GetSubsToLeaveBehind(leavingSub);
|
||||
subsToLeaveBehind = GetSubsToLeaveBehind(leavingSub);
|
||||
}
|
||||
|
||||
if (subsNotDocked.Any())
|
||||
atEndPosition = leavingSub.AtEndPosition;
|
||||
|
||||
if (subsToLeaveBehind.Any())
|
||||
{
|
||||
string msg = "";
|
||||
if (subsNotDocked.Count==1)
|
||||
if (subsToLeaveBehind.Count == 1)
|
||||
{
|
||||
msg = "One of your vessels isn't at the exit yet. Do you want to leave it behind?";
|
||||
}
|
||||
@@ -325,7 +335,7 @@ namespace Barotrauma
|
||||
var msgBox = new GUIMessageBox("Warning", msg, new string[] {"Yes", "No"});
|
||||
msgBox.Buttons[0].OnClicked += EndShift;
|
||||
msgBox.Buttons[0].OnClicked += msgBox.Close;
|
||||
msgBox.Buttons[0].UserData = Submarine.Loaded.FindAll(s => !subsNotDocked.Contains(s));
|
||||
msgBox.Buttons[0].UserData = Submarine.Loaded.FindAll(s => !subsToLeaveBehind.Contains(s));
|
||||
|
||||
msgBox.Buttons[1].OnClicked += msgBox.Close;
|
||||
}
|
||||
@@ -343,7 +353,7 @@ namespace Barotrauma
|
||||
|
||||
List<Submarine> leavingSubs = obj as List<Submarine>;
|
||||
if (leavingSubs == null) leavingSubs = new List<Submarine>() { GetLeavingSub() };
|
||||
|
||||
|
||||
var cinematic = new TransitionCinematic(leavingSubs, GameMain.GameScreen.Cam, 5.0f);
|
||||
|
||||
SoundPlayer.OverrideMusicType = CrewManager.characters.Any(c => !c.IsDead) ? "endshift" : "crewdead";
|
||||
@@ -378,13 +388,14 @@ namespace Barotrauma
|
||||
//element.Add(new XAttribute("day", day));
|
||||
XElement modeElement = new XElement("gamemode");
|
||||
|
||||
modeElement.Add(new XAttribute("currentlocation", Map.CurrentLocationIndex));
|
||||
modeElement.Add(new XAttribute("mapseed", Map.Seed));
|
||||
|
||||
//modeElement.Add(new XAttribute("currentlocation", Map.CurrentLocationIndex));
|
||||
//modeElement.Add(new XAttribute("mapseed", Map.Seed));
|
||||
|
||||
|
||||
CrewManager.Save(modeElement);
|
||||
Map.Save(modeElement);
|
||||
|
||||
element.Add(modeElement);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -283,7 +283,7 @@ namespace Barotrauma.Tutorials
|
||||
|
||||
infoBox = CreateInfoFrame("Steer the submarine downwards, heading further into the cavern.");
|
||||
|
||||
while (Submarine.MainSub.WorldPosition.Y > 24600.0f)
|
||||
while (Submarine.MainSub.WorldPosition.Y > 31900.0f)
|
||||
{
|
||||
yield return CoroutineStatus.Running;
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace Barotrauma.Tutorials
|
||||
GameMain.GameSession = new GameSession(Submarine.MainSub, "", GameModePreset.list.Find(gm => gm.Name.ToLowerInvariant() == "tutorial"));
|
||||
(GameMain.GameSession.gameMode as TutorialMode).tutorialType = this;
|
||||
|
||||
GameMain.GameSession.StartShift("tuto1");
|
||||
GameMain.GameSession.StartShift("tuto2");
|
||||
|
||||
GameMain.GameSession.TaskManager.Tasks.Clear();
|
||||
|
||||
|
||||
@@ -107,14 +107,14 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
public void StartShift(string levelSeed)
|
||||
public void StartShift(string levelSeed, bool loadSecondSub = true)
|
||||
{
|
||||
Level level = Level.CreateRandom(levelSeed);
|
||||
|
||||
StartShift(level);
|
||||
StartShift(level,true,loadSecondSub);
|
||||
}
|
||||
|
||||
public void StartShift(Level level, bool reloadSub = true)
|
||||
public void StartShift(Level level, bool reloadSub = true, bool loadSecondSub = false)
|
||||
{
|
||||
GameMain.LightManager.LosEnabled = (GameMain.Server==null || GameMain.Server.CharacterInfo!=null);
|
||||
|
||||
@@ -128,6 +128,18 @@ namespace Barotrauma
|
||||
|
||||
if (reloadSub || Submarine.MainSub != submarine) submarine.Load(true);
|
||||
Submarine.MainSub = submarine;
|
||||
if (loadSecondSub)
|
||||
{
|
||||
if (Submarine.MainSubs[1] == null)
|
||||
{
|
||||
Submarine.MainSubs[1] = new Submarine(Submarine.MainSub.FilePath,Submarine.MainSub.MD5Hash.Hash,true);
|
||||
Submarine.MainSubs[1].Load(false);
|
||||
}
|
||||
else if (reloadSub)
|
||||
{
|
||||
Submarine.MainSubs[1].Load(false);
|
||||
}
|
||||
}
|
||||
|
||||
//var secondSub = new Submarine(submarine.FilePath, submarine.MD5Hash.Hash);
|
||||
//secondSub.Load(false);
|
||||
@@ -152,10 +164,14 @@ namespace Barotrauma
|
||||
|
||||
if (gameMode!=null) gameMode.Start();
|
||||
|
||||
Items.Components.Radar.StartMarker = "Start";
|
||||
Items.Components.Radar.EndMarker = "End";
|
||||
if (gameMode.Mission != null) Mission.Start(Level.Loaded);
|
||||
|
||||
|
||||
TaskManager.StartShift(level);
|
||||
|
||||
if (gameMode != null) gameMode.MsgBox();
|
||||
|
||||
GameMain.GameScreen.ColorFade(Color.Black, Color.TransparentBlack, 5.0f);
|
||||
SoundPlayer.SwitchMusic();
|
||||
}
|
||||
@@ -303,19 +319,15 @@ namespace Barotrauma
|
||||
|
||||
if (gameMode != null) gameMode.Update(deltaTime);
|
||||
if (Mission != null) Mission.Update(deltaTime);
|
||||
if (infoFrame != null) infoFrame.Update(deltaTime);
|
||||
}
|
||||
|
||||
public void Draw(SpriteBatch spriteBatch)
|
||||
{
|
||||
//guiRoot.Draw(spriteBatch);
|
||||
infoButton.Draw(spriteBatch);
|
||||
|
||||
if (gameMode != null) gameMode.Draw(spriteBatch);
|
||||
if (infoFrame != null)
|
||||
{
|
||||
infoFrame.Update(0.016f);
|
||||
infoFrame.Draw(spriteBatch);
|
||||
}
|
||||
if (infoFrame != null) infoFrame.Draw(spriteBatch);
|
||||
}
|
||||
|
||||
public void Save(string filePath)
|
||||
@@ -324,10 +336,12 @@ namespace Barotrauma
|
||||
new XElement("Gamesession"));
|
||||
|
||||
var now = DateTime.Now;
|
||||
doc.Root.Add(new XAttribute("savetime", now.Hour + ":" + now.Minute + ", " + now.ToShortDateString()));
|
||||
doc.Root.Add(new XAttribute("savetime", now.ToShortTimeString() + ", " + now.ToShortDateString()));
|
||||
|
||||
doc.Root.Add(new XAttribute("submarine", submarine==null ? "" : submarine.Name));
|
||||
|
||||
doc.Root.Add(new XAttribute("mapseed", Map.Seed));
|
||||
|
||||
((SinglePlayerMode)gameMode).Save(doc.Root);
|
||||
|
||||
try
|
||||
|
||||
@@ -66,6 +66,12 @@ namespace Barotrauma
|
||||
int x = 0;
|
||||
foreach (Character character in gameSession.CrewManager.characters)
|
||||
{
|
||||
if (GameMain.GameSession.Mission is CombatMission &&
|
||||
character.TeamID != GameMain.GameSession.CrewManager.WinningTeam)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var characterFrame = new GUIFrame(new Rectangle(x, y, 170, 70), Color.Transparent, GUI.Style, listBox);
|
||||
characterFrame.OutlineColor = Color.Transparent;
|
||||
characterFrame.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f);
|
||||
@@ -74,10 +80,9 @@ namespace Barotrauma
|
||||
character.Info.CreateCharacterFrame(characterFrame,
|
||||
character.Info.Job != null ? (character.Info.Name + '\n' + "(" + character.Info.Job.Name + ")") : character.Info.Name, null);
|
||||
|
||||
|
||||
string statusText = "OK";
|
||||
Color statusColor = Color.DarkGreen;
|
||||
|
||||
|
||||
if (character.IsDead)
|
||||
{
|
||||
statusText = InfoTextManager.GetInfoText("CauseOfDeath." + character.CauseOfDeath.ToString());
|
||||
@@ -85,7 +90,7 @@ namespace Barotrauma
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
|
||||
if (character.IsUnconscious)
|
||||
{
|
||||
statusText = "Unconscious";
|
||||
@@ -96,13 +101,13 @@ namespace Barotrauma
|
||||
statusText = "Injured";
|
||||
statusColor = Color.DarkOrange;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
new GUITextBlock(new Rectangle(0, 0, 0, 20), statusText,
|
||||
GUI.Style, Alignment.BottomLeft, Alignment.TopCenter, characterFrame, true, GUI.SmallFont).Color = statusColor * 0.7f;
|
||||
|
||||
x += characterFrame.Rect.Width + 10;
|
||||
x += characterFrame.Rect.Width + 10;
|
||||
}
|
||||
|
||||
y += 120;
|
||||
|
||||
@@ -25,10 +25,8 @@ namespace Barotrauma
|
||||
|
||||
private KeyOrMouse[] keyMapping;
|
||||
|
||||
|
||||
private bool unsavedSettings;
|
||||
|
||||
|
||||
public GUIFrame SettingsFrame
|
||||
{
|
||||
get
|
||||
@@ -291,7 +289,7 @@ namespace Barotrauma
|
||||
private bool ChangeSoundVolume(GUIScrollBar scrollBar, float barScroll)
|
||||
{
|
||||
UnsavedSettings = true;
|
||||
SoundVolume = MathHelper.Clamp(barScroll, 0.0f, 1.0f);
|
||||
SoundVolume = barScroll;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -299,22 +297,11 @@ namespace Barotrauma
|
||||
private bool ChangeMusicVolume(GUIScrollBar scrollBar, float barScroll)
|
||||
{
|
||||
UnsavedSettings = true;
|
||||
MusicVolume = MathHelper.Clamp(barScroll, 0.0f, 1.0f);
|
||||
MusicVolume = barScroll;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//private bool ToggleFullScreen(object userData)
|
||||
//{
|
||||
// UnsavedSettings = true;
|
||||
// FullScreenEnabled = !FullScreenEnabled;
|
||||
|
||||
// GameMain.Graphics.IsFullScreen = FullScreenEnabled;
|
||||
// GameMain.Graphics.ApplyChanges();
|
||||
|
||||
// return true;
|
||||
//}
|
||||
|
||||
|
||||
public void ResetSettingsFrame()
|
||||
{
|
||||
settingsFrame = null;
|
||||
@@ -381,14 +368,16 @@ namespace Barotrauma
|
||||
y += 70;
|
||||
|
||||
new GUITextBlock(new Rectangle(0, y, 100, 20), "Sound volume:", GUI.Style, settingsFrame);
|
||||
GUIScrollBar soundScrollBar = new GUIScrollBar(new Rectangle(0, y+20, 150, 20), GUI.Style,0.1f, settingsFrame);
|
||||
GUIScrollBar soundScrollBar = new GUIScrollBar(new Rectangle(0, y + 20, 150, 20), GUI.Style, 0.1f, settingsFrame);
|
||||
soundScrollBar.BarScroll = SoundVolume;
|
||||
soundScrollBar.OnMoved = ChangeSoundVolume;
|
||||
soundScrollBar.Step = 0.05f;
|
||||
|
||||
new GUITextBlock(new Rectangle(0, y+40, 100, 20), "Music volume:", GUI.Style, settingsFrame);
|
||||
GUIScrollBar musicScrollBar = new GUIScrollBar(new Rectangle(0, y+60, 150, 20), GUI.Style, 0.1f, settingsFrame);
|
||||
new GUITextBlock(new Rectangle(0, y + 40, 100, 20), "Music volume:", GUI.Style, settingsFrame);
|
||||
GUIScrollBar musicScrollBar = new GUIScrollBar(new Rectangle(0, y + 60, 150, 20), GUI.Style, 0.1f, settingsFrame);
|
||||
musicScrollBar.BarScroll = MusicVolume;
|
||||
musicScrollBar.OnMoved = ChangeMusicVolume;
|
||||
musicScrollBar.Step = 0.05f;
|
||||
|
||||
x = 200;
|
||||
y = 10;
|
||||
|
||||
@@ -310,7 +310,7 @@ namespace Barotrauma
|
||||
MergeSlots();
|
||||
}
|
||||
|
||||
public override void Update(float deltaTime)
|
||||
public override void Update(float deltaTime, bool subInventory = false)
|
||||
{
|
||||
base.Update(deltaTime);
|
||||
|
||||
@@ -339,7 +339,7 @@ namespace Barotrauma
|
||||
//not equipped -> attempt to equip
|
||||
if (IsInLimbSlot(doubleClickedItem, InvSlotType.Any))
|
||||
{
|
||||
TryPutItem(doubleClickedItem, doubleClickedItem.AllowedSlots.FindAll(i => i != InvSlotType.Any));
|
||||
TryPutItem(doubleClickedItem, doubleClickedItem.AllowedSlots.FindAll(i => i != InvSlotType.Any), true);
|
||||
}
|
||||
//equipped -> attempt to unequip
|
||||
else if (doubleClickedItem.AllowedSlots.Contains(InvSlotType.Any))
|
||||
@@ -467,7 +467,7 @@ namespace Barotrauma
|
||||
(draggingItem == null || draggingItem.Container != Items[selectedSlot]))
|
||||
{
|
||||
selectedSlot = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -56,10 +56,15 @@ namespace Barotrauma.Items.Components
|
||||
get
|
||||
{
|
||||
if (linkedGap != null) return linkedGap;
|
||||
|
||||
foreach (MapEntity e in item.linkedTo)
|
||||
{
|
||||
linkedGap = e as Gap;
|
||||
if (linkedGap != null) return linkedGap;
|
||||
linkedGap = e as Gap;
|
||||
if (linkedGap != null)
|
||||
{
|
||||
linkedGap.PassAmbientLight = window != Rectangle.Empty;
|
||||
return linkedGap;
|
||||
}
|
||||
}
|
||||
Rectangle rect = item.Rect;
|
||||
if (isHorizontal)
|
||||
@@ -75,6 +80,7 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
linkedGap = new Gap(rect, Item.Submarine);
|
||||
linkedGap.Submarine = item.Submarine;
|
||||
linkedGap.PassAmbientLight = window != Rectangle.Empty;
|
||||
linkedGap.Open = openState;
|
||||
item.linkedTo.Add(linkedGap);
|
||||
return linkedGap;
|
||||
@@ -95,6 +101,11 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
public Rectangle WindowRect
|
||||
{
|
||||
get { return window; }
|
||||
}
|
||||
|
||||
[Editable, HasDefaultValue(false, true)]
|
||||
public bool IsOpen
|
||||
{
|
||||
|
||||
@@ -585,6 +585,8 @@ namespace Barotrauma.Items.Components
|
||||
return (average+100.0f)/2.0f;
|
||||
}
|
||||
|
||||
public virtual void FlipX() { }
|
||||
|
||||
public bool HasRequiredContainedItems(bool addMessage)
|
||||
{
|
||||
List<RelatedItem> requiredContained = requiredItems.FindAll(ri=> ri.Type == RelatedItem.RelationType.Contained);
|
||||
|
||||
@@ -11,6 +11,12 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
public LimbType limbType;
|
||||
public Vector2 position;
|
||||
|
||||
public LimbPos(LimbType limbType, Vector2 position)
|
||||
{
|
||||
this.limbType = limbType;
|
||||
this.position = position;
|
||||
}
|
||||
}
|
||||
|
||||
class Controller : ItemComponent
|
||||
@@ -243,5 +249,31 @@ namespace Barotrauma.Items.Components
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void FlipX()
|
||||
{
|
||||
if (dir != Direction.None)
|
||||
{
|
||||
dir = dir == Direction.Left ? Direction.Right : Direction.Left;
|
||||
}
|
||||
|
||||
if (userPos != 0.0f)
|
||||
{
|
||||
float diff = (item.Rect.X + UserPos) - item.Rect.Center.X;
|
||||
userPos = item.Rect.Center.X - diff - item.Rect.X;
|
||||
}
|
||||
|
||||
for (int i = 0; i < limbPositions.Count; i++)
|
||||
{
|
||||
float diff = (item.Rect.X + limbPositions[i].position.X) - item.Rect.Center.X;
|
||||
|
||||
Vector2 flippedPos =
|
||||
new Vector2(
|
||||
item.Rect.Center.X - diff - item.Rect.X,
|
||||
limbPositions[i].position.Y);
|
||||
|
||||
limbPositions[i] = new LimbPos(limbPositions[i].limbType, flippedPos);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
private float lastUpdate;
|
||||
|
||||
private Hull hull1;
|
||||
public Hull hull1;
|
||||
|
||||
private GUITickBox isActiveTickBox;
|
||||
|
||||
|
||||
@@ -21,6 +21,9 @@ 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
|
||||
{
|
||||
@@ -100,6 +103,11 @@ namespace Barotrauma.Items.Components
|
||||
return pingState > 1.0f;
|
||||
}
|
||||
|
||||
public override void UpdateHUD(Character character)
|
||||
{
|
||||
GuiFrame.Update((float)Timing.Step);
|
||||
}
|
||||
|
||||
public override void DrawHUD(SpriteBatch spriteBatch, Character character)
|
||||
{
|
||||
GuiFrame.Draw(spriteBatch);
|
||||
@@ -263,11 +271,11 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
|
||||
DrawMarker(spriteBatch,
|
||||
(GameMain.GameSession.Map == null) ? "Start" : GameMain.GameSession.Map.CurrentLocation.Name,
|
||||
(GameMain.GameSession.Map == null) ? StartMarker : GameMain.GameSession.Map.CurrentLocation.Name,
|
||||
(Level.Loaded.StartPosition - item.WorldPosition), displayScale, center, (rect.Width * 0.5f));
|
||||
|
||||
DrawMarker(spriteBatch,
|
||||
(GameMain.GameSession.Map == null) ? "End" : GameMain.GameSession.Map.SelectedLocation.Name,
|
||||
(GameMain.GameSession.Map == null) ? EndMarker : GameMain.GameSession.Map.SelectedLocation.Name,
|
||||
(Level.Loaded.EndPosition - item.WorldPosition), displayScale, center, (rect.Width * 0.5f));
|
||||
|
||||
if (GameMain.GameSession.Mission != null)
|
||||
@@ -284,6 +292,7 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
foreach (Submarine sub in Submarine.Loaded)
|
||||
{
|
||||
if (!sub.OnRadar) continue;
|
||||
if (item.Submarine == sub || sub.DockedTo.Contains(item.Submarine)) continue;
|
||||
if (sub.WorldPosition.Y > Level.Loaded.Size.Y) continue;
|
||||
|
||||
|
||||
@@ -88,6 +88,8 @@ namespace Barotrauma.Items.Components
|
||||
item.body.CollisionCategories = Physics.CollisionProjectile;
|
||||
item.body.CollidesWith = Physics.CollisionCharacter | Physics.CollisionWall | Physics.CollisionLevel;
|
||||
|
||||
IsActive = true;
|
||||
|
||||
if (stickJoint == null || !doesStick) return;
|
||||
|
||||
if (stickTarget != null)
|
||||
@@ -111,6 +113,8 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
public override void Update(float deltaTime, Camera cam)
|
||||
{
|
||||
ApplyStatusEffects(ActionType.OnActive, deltaTime, null);
|
||||
|
||||
if (stickJoint != null && stickJoint.JointTranslation < 0.01f)
|
||||
{
|
||||
if (stickTarget != null)
|
||||
@@ -174,6 +178,8 @@ namespace Barotrauma.Items.Components
|
||||
ApplyStatusEffects(ActionType.OnUse, 1.0f);
|
||||
ApplyStatusEffects(ActionType.OnImpact, 1.0f);
|
||||
|
||||
IsActive = false;
|
||||
|
||||
item.body.FarseerBody.OnCollision -= OnProjectileCollision;
|
||||
|
||||
item.body.FarseerBody.IsBullet = false;
|
||||
|
||||
@@ -122,7 +122,7 @@ namespace Barotrauma.Items.Components
|
||||
base.Update(deltaTime, cam);
|
||||
|
||||
light.ParentSub = item.Submarine;
|
||||
|
||||
|
||||
ApplyStatusEffects(ActionType.OnActive, deltaTime);
|
||||
|
||||
if (item.Container != null)
|
||||
|
||||
@@ -7,6 +7,8 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
private float maxPower;
|
||||
|
||||
private float lastReceivedMessage;
|
||||
|
||||
[Editable, HasDefaultValue(1000.0f, true)]
|
||||
public float MaxPower
|
||||
{
|
||||
@@ -73,13 +75,43 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
else if (connection.Name == "toggle")
|
||||
{
|
||||
IsOn = !IsOn;
|
||||
SetState(!IsOn,false,true);
|
||||
}
|
||||
else if (connection.Name == "set_state")
|
||||
{
|
||||
IsOn = signal != "0";
|
||||
SetState(signal != "0", false, true);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetState(bool on, bool isNetworkMessage, bool sendNetworkMessage = false)
|
||||
{
|
||||
if (GameMain.Client != null && !isNetworkMessage) return;
|
||||
|
||||
IsOn = on;
|
||||
if (sendNetworkMessage)
|
||||
{
|
||||
item.NewComponentEvent(this, false, true);
|
||||
}
|
||||
}
|
||||
|
||||
public override bool FillNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetBuffer message)
|
||||
{
|
||||
message.Write(IsOn);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void ReadNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetIncomingMessage message, float sendingTime)
|
||||
{
|
||||
if (sendingTime < lastReceivedMessage) return;
|
||||
if (GameMain.Server != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
lastReceivedMessage = sendingTime;
|
||||
|
||||
SetState(message.ReadBoolean(), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -470,6 +470,14 @@ namespace Barotrauma.Items.Components
|
||||
wireSprite.Depth + ((item.ID % 100) * 0.00001f));
|
||||
}
|
||||
|
||||
public override void FlipX()
|
||||
{
|
||||
for (int i = 0; i < Nodes.Count; i++)
|
||||
{
|
||||
Nodes[i] = new Vector2(-Nodes[i].X, Nodes[i].Y);
|
||||
}
|
||||
}
|
||||
|
||||
public override XElement Save(XElement parentElement)
|
||||
{
|
||||
XElement componentElement = base.Save(parentElement);
|
||||
|
||||
@@ -347,6 +347,22 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
return projectiles;
|
||||
}
|
||||
|
||||
public override void FlipX()
|
||||
{
|
||||
minRotation = (float)Math.PI - minRotation;
|
||||
maxRotation = (float)Math.PI - maxRotation;
|
||||
|
||||
var temp = minRotation;
|
||||
minRotation = maxRotation;
|
||||
maxRotation = temp;
|
||||
|
||||
while (minRotation < 0)
|
||||
{
|
||||
minRotation += MathHelper.TwoPi;
|
||||
maxRotation += MathHelper.TwoPi;
|
||||
}
|
||||
}
|
||||
|
||||
public override void ReceiveSignal(int stepsTaken, string signal, Connection connection, Item sender, float power)
|
||||
{
|
||||
|
||||
@@ -63,9 +63,10 @@ namespace Barotrauma
|
||||
protected int selectedSlot = -1;
|
||||
|
||||
protected InventorySlot[] slots;
|
||||
|
||||
public Item[] Items;
|
||||
|
||||
private bool isSubInventory;
|
||||
|
||||
public bool Locked;
|
||||
|
||||
public Vector2 CenterPos
|
||||
@@ -232,9 +233,13 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void Update(float deltaTime)
|
||||
public virtual void Update(float deltaTime, bool subInventory = false)
|
||||
{
|
||||
if (slots == null) CreateSlots();
|
||||
if (slots == null || isSubInventory != subInventory)
|
||||
{
|
||||
CreateSlots();
|
||||
isSubInventory = subInventory;
|
||||
}
|
||||
|
||||
for (int i = 0; i < capacity; i++)
|
||||
{
|
||||
@@ -259,17 +264,15 @@ namespace Barotrauma
|
||||
|
||||
}
|
||||
|
||||
public virtual void Draw(SpriteBatch spriteBatch)
|
||||
public virtual void Draw(SpriteBatch spriteBatch, bool subInventory = false)
|
||||
{
|
||||
string toolTip = "";
|
||||
|
||||
if (slots == null) CreateSlots();
|
||||
if (slots == null || isSubInventory != subInventory) return;
|
||||
|
||||
for (int i = 0; i < capacity; i++)
|
||||
{
|
||||
if (slots[i].Disabled) continue;
|
||||
|
||||
//don't draw the slot if dragged an item out of it
|
||||
//don't draw the item if it's being dragged out of the slot
|
||||
bool drawItem = draggingItem == null || draggingItem != Items[i] || slots[i].IsHighlighted;
|
||||
|
||||
DrawSlot(spriteBatch, slots[i], Items[i], drawItem);
|
||||
@@ -288,8 +291,20 @@ namespace Barotrauma
|
||||
|
||||
for (int i = 0; i < capacity; i++)
|
||||
{
|
||||
if (slots[i].IsHighlighted && !slots[i].Disabled)
|
||||
if (slots[i].IsHighlighted && !slots[i].Disabled && Items[i] != null)
|
||||
{
|
||||
string toolTip = "";
|
||||
if (GameMain.DebugDraw)
|
||||
{
|
||||
toolTip = Items[i].ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
toolTip = string.IsNullOrEmpty(Items[i].Description) ?
|
||||
Items[i].Name :
|
||||
Items[i].Name + '\n' + Items[i].Description;
|
||||
}
|
||||
|
||||
DrawToolTip(spriteBatch, toolTip, slots[i].Rect);
|
||||
break;
|
||||
}
|
||||
@@ -371,9 +386,27 @@ namespace Barotrauma
|
||||
|
||||
if (container.Inventory.slots == null) container.Inventory.CreateSlots();
|
||||
|
||||
int itemCapacity = container.Capacity;
|
||||
|
||||
var slot = slots[slotIndex];
|
||||
Rectangle containerRect = new Rectangle(slot.Rect.X - 5, slot.Rect.Y - (40 + 10) * itemCapacity - 5,
|
||||
slot.Rect.Width + 10, slot.Rect.Height + (40 + 10) * itemCapacity + 10);
|
||||
|
||||
Rectangle subRect = slot.Rect;
|
||||
subRect.Height = 40;
|
||||
|
||||
for (int i = 0; i < itemCapacity; i++)
|
||||
{
|
||||
subRect.Y = subRect.Y - subRect.Height - 10;
|
||||
container.Inventory.slots[i].Rect = subRect;
|
||||
}
|
||||
}
|
||||
|
||||
container.Inventory.isSubInventory = true;
|
||||
|
||||
slots[slotIndex].State = GUIComponent.ComponentState.Hover;
|
||||
|
||||
container.Inventory.Update(deltaTime);
|
||||
container.Inventory.Update(deltaTime, true);
|
||||
}
|
||||
|
||||
public void DrawSubInventory(SpriteBatch spriteBatch, int slotIndex)
|
||||
@@ -384,8 +417,7 @@ namespace Barotrauma
|
||||
var container = item.GetComponent<ItemContainer>();
|
||||
if (container == null) return;
|
||||
|
||||
if (container.Inventory.slots == null) container.Inventory.CreateSlots();
|
||||
|
||||
if (container.Inventory.slots == null || !container.Inventory.isSubInventory) return;
|
||||
|
||||
int itemCapacity = container.Capacity;
|
||||
|
||||
@@ -398,20 +430,11 @@ namespace Barotrauma
|
||||
var slot = slots[slotIndex];
|
||||
Rectangle containerRect = new Rectangle(slot.Rect.X - 5, slot.Rect.Y - (40 + 10) * itemCapacity - 5,
|
||||
slot.Rect.Width + 10, slot.Rect.Height + (40 + 10) * itemCapacity + 10);
|
||||
|
||||
Rectangle subRect = slot.Rect;
|
||||
subRect.Height = 40;
|
||||
|
||||
|
||||
GUI.DrawRectangle(spriteBatch, new Rectangle(containerRect.X, containerRect.Y, containerRect.Width, containerRect.Height - slot.Rect.Height - 5), Color.Black * 0.8f, true);
|
||||
GUI.DrawRectangle(spriteBatch, containerRect, Color.White);
|
||||
|
||||
for (int i = 0; i < itemCapacity; i++)
|
||||
{
|
||||
subRect.Y = subRect.Y - subRect.Height - 10;
|
||||
container.Inventory.slots[i].Rect = subRect;
|
||||
}
|
||||
|
||||
container.Inventory.Draw(spriteBatch);
|
||||
container.Inventory.Draw(spriteBatch, true);
|
||||
|
||||
if (!containerRect.Contains(PlayerInput.MousePosition))
|
||||
{
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -58,6 +58,8 @@ namespace Barotrauma
|
||||
private set;
|
||||
}
|
||||
|
||||
private bool canSpriteFlipX;
|
||||
|
||||
//if a matching itemprefab is not found when loading a sub, the game will attempt to find a prefab with a matching alias
|
||||
//(allows changing item names while keeping backwards compatibility with older sub files)
|
||||
public string[] Aliases
|
||||
@@ -116,21 +118,26 @@ namespace Barotrauma
|
||||
private set;
|
||||
}
|
||||
|
||||
public bool CanSpriteFlipX
|
||||
{
|
||||
get { return canSpriteFlipX; }
|
||||
}
|
||||
|
||||
public Vector2 Size
|
||||
{
|
||||
get { return size; }
|
||||
}
|
||||
|
||||
public override void UpdatePlacing(SpriteBatch spriteBatch, Camera cam)
|
||||
public override void UpdatePlacing(Camera cam)
|
||||
{
|
||||
Vector2 position = Submarine.MouseToWorldGrid(cam, Submarine.MainSub);
|
||||
Vector2 position = Submarine.MouseToWorldGrid(cam, Submarine.MainSub);
|
||||
|
||||
if (PlayerInput.RightButtonClicked())
|
||||
{
|
||||
selected = null;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (!resizeHorizontal && !resizeVertical)
|
||||
{
|
||||
if (PlayerInput.LeftButtonClicked())
|
||||
@@ -138,16 +145,14 @@ namespace Barotrauma
|
||||
var item = new Item(new Rectangle((int)position.X, (int)position.Y, (int)sprite.size.X, (int)sprite.size.Y), this, Submarine.MainSub);
|
||||
//constructor.Invoke(lobject);
|
||||
item.Submarine = Submarine.MainSub;
|
||||
item.SetTransform(ConvertUnits.ToSimUnits(Submarine.MainSub==null ? item.Position : item.Position - Submarine.MainSub.Position), 0.0f);
|
||||
item.SetTransform(ConvertUnits.ToSimUnits(Submarine.MainSub == null ? item.Position : item.Position - Submarine.MainSub.Position), 0.0f);
|
||||
item.FindHull();
|
||||
|
||||
placePosition = Vector2.Zero;
|
||||
|
||||
// selected = null;
|
||||
// selected = null;
|
||||
return;
|
||||
}
|
||||
|
||||
sprite.Draw(spriteBatch, new Vector2(position.X + sprite.size.X / 2.0f, -position.Y + sprite.size.Y / 2.0f), SpriteColor);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -172,17 +177,54 @@ namespace Barotrauma
|
||||
item.Submarine = Submarine.MainSub;
|
||||
item.SetTransform(ConvertUnits.ToSimUnits(Submarine.MainSub == null ? item.Position : item.Position - Submarine.MainSub.Position), 0.0f);
|
||||
item.FindHull();
|
||||
|
||||
|
||||
//selected = null;
|
||||
return;
|
||||
}
|
||||
|
||||
position = placePosition;
|
||||
}
|
||||
}
|
||||
|
||||
//if (PlayerInput.GetMouseState.RightButton == ButtonState.Pressed) selected = null;
|
||||
|
||||
}
|
||||
|
||||
public override void DrawPlacing(SpriteBatch spriteBatch,Camera cam)
|
||||
{
|
||||
Vector2 position = Submarine.MouseToWorldGrid(cam, Submarine.MainSub);
|
||||
|
||||
if (PlayerInput.RightButtonClicked())
|
||||
{
|
||||
selected = null;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!resizeHorizontal && !resizeVertical)
|
||||
{
|
||||
sprite.Draw(spriteBatch, new Vector2(position.X + sprite.size.X / 2.0f, -position.Y + sprite.size.Y / 2.0f), SpriteColor);
|
||||
}
|
||||
else
|
||||
{
|
||||
Vector2 placeSize = size;
|
||||
|
||||
if (placePosition == Vector2.Zero)
|
||||
{
|
||||
if (PlayerInput.LeftButtonHeld()) placePosition = position;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (resizeHorizontal)
|
||||
placeSize.X = Math.Max(position.X - placePosition.X, size.X);
|
||||
if (resizeVertical)
|
||||
placeSize.Y = Math.Max(placePosition.Y - position.Y, size.Y);
|
||||
|
||||
position = placePosition;
|
||||
}
|
||||
|
||||
if (sprite != null) sprite.DrawTiled(spriteBatch, new Vector2(position.X, -position.Y), placeSize, SpriteColor);
|
||||
}
|
||||
|
||||
|
||||
//if (PlayerInput.GetMouseState.RightButton == ButtonState.Pressed) selected = null;
|
||||
|
||||
}
|
||||
@@ -270,6 +312,9 @@ namespace Barotrauma
|
||||
DeconstructItems = new List<DeconstructItem>();
|
||||
DeconstructTime = 1.0f;
|
||||
|
||||
tags = new List<string>();
|
||||
tags.AddRange(ToolBox.GetAttributeString(element, "tags", "").Split(','));
|
||||
|
||||
foreach (XElement subElement in element.Elements())
|
||||
{
|
||||
switch (subElement.Name.ToString().ToLowerInvariant())
|
||||
@@ -281,6 +326,8 @@ namespace Barotrauma
|
||||
spriteFolder = Path.GetDirectoryName(filePath);
|
||||
}
|
||||
|
||||
canSpriteFlipX = ToolBox.GetAttributeBool(subElement, "canflipx", true);
|
||||
|
||||
sprite = new Sprite(subElement, spriteFolder);
|
||||
size = sprite.size;
|
||||
break;
|
||||
|
||||
@@ -6,7 +6,35 @@ namespace Barotrauma
|
||||
{
|
||||
class ItemSpawner
|
||||
{
|
||||
private readonly Queue<Pair<ItemPrefab, object>> spawnQueue;
|
||||
class ItemSpawnInfo
|
||||
{
|
||||
public readonly ItemPrefab Prefab;
|
||||
|
||||
public readonly Vector2 Position;
|
||||
public readonly Inventory Inventory;
|
||||
public readonly Submarine Submarine;
|
||||
|
||||
public ItemSpawnInfo(ItemPrefab prefab, Vector2 worldPosition)
|
||||
{
|
||||
Prefab = prefab;
|
||||
Position = worldPosition;
|
||||
}
|
||||
|
||||
public ItemSpawnInfo(ItemPrefab prefab, Vector2 position, Submarine sub)
|
||||
{
|
||||
Prefab = prefab;
|
||||
Position = position;
|
||||
Submarine = sub;
|
||||
}
|
||||
|
||||
public ItemSpawnInfo(ItemPrefab prefab, Inventory inventory)
|
||||
{
|
||||
Prefab = prefab;
|
||||
Inventory = inventory;
|
||||
}
|
||||
}
|
||||
|
||||
private readonly Queue<ItemSpawnInfo> spawnQueue;
|
||||
|
||||
|
||||
public List<Item> spawnItems = new List<Item>();
|
||||
@@ -14,37 +42,31 @@ namespace Barotrauma
|
||||
|
||||
public ItemSpawner()
|
||||
{
|
||||
spawnQueue = new Queue<Pair<ItemPrefab, object>>();
|
||||
spawnQueue = new Queue<ItemSpawnInfo>();
|
||||
}
|
||||
|
||||
public void QueueItem(ItemPrefab itemPrefab, Vector2 worldPosition, bool isNetworkMessage = false)
|
||||
{
|
||||
if (!isNetworkMessage && GameMain.Client != null)
|
||||
{
|
||||
//clients aren't allowed to spawn new items unless the server says so
|
||||
return;
|
||||
}
|
||||
//clients aren't allowed to spawn new items unless the server says so
|
||||
if (!isNetworkMessage && GameMain.Client != null) return;
|
||||
|
||||
spawnQueue.Enqueue(new ItemSpawnInfo(itemPrefab, worldPosition));
|
||||
}
|
||||
|
||||
var itemInfo = new Pair<ItemPrefab, object>();
|
||||
itemInfo.First = itemPrefab;
|
||||
itemInfo.Second = worldPosition;
|
||||
public void QueueItem(ItemPrefab itemPrefab, Vector2 position, Submarine sub, bool isNetworkMessage = false)
|
||||
{
|
||||
//clients aren't allowed to spawn new items unless the server says so
|
||||
if (!isNetworkMessage && GameMain.Client != null) return;
|
||||
|
||||
spawnQueue.Enqueue(itemInfo);
|
||||
spawnQueue.Enqueue(new ItemSpawnInfo(itemPrefab, position, sub));
|
||||
}
|
||||
|
||||
public void QueueItem(ItemPrefab itemPrefab, Inventory inventory, bool isNetworkMessage = false)
|
||||
{
|
||||
if (!isNetworkMessage && GameMain.Client != null)
|
||||
{
|
||||
//clients aren't allowed to spawn new items unless the server says so
|
||||
return;
|
||||
}
|
||||
//clients aren't allowed to spawn new items unless the server says so
|
||||
if (!isNetworkMessage && GameMain.Client != null) return;
|
||||
|
||||
var itemInfo = new Pair<ItemPrefab, object>();
|
||||
itemInfo.First = itemPrefab;
|
||||
itemInfo.Second = inventory;
|
||||
|
||||
spawnQueue.Enqueue(itemInfo);
|
||||
spawnQueue.Enqueue(new ItemSpawnInfo(itemPrefab, inventory));
|
||||
}
|
||||
|
||||
public void Update()
|
||||
@@ -58,23 +80,20 @@ namespace Barotrauma
|
||||
{
|
||||
var itemInfo = spawnQueue.Dequeue();
|
||||
|
||||
if (itemInfo.Second is Vector2)
|
||||
Item spawnedItem = null;
|
||||
|
||||
if (itemInfo.Inventory != null)
|
||||
{
|
||||
var item = new Item(itemInfo.First, (Vector2)itemInfo.Second, null);
|
||||
AddToSpawnedList(item);
|
||||
|
||||
items.Add(item);
|
||||
spawnedItem = new Item(itemInfo.Prefab, Vector2.Zero, null);
|
||||
itemInfo.Inventory.TryPutItem(spawnedItem, spawnedItem.AllowedSlots, false);
|
||||
}
|
||||
else if (itemInfo.Second is Inventory)
|
||||
else
|
||||
{
|
||||
var item = new Item(itemInfo.First, Vector2.Zero, null);
|
||||
AddToSpawnedList(item);
|
||||
|
||||
var inventory = (Inventory)itemInfo.Second;
|
||||
inventory.TryPutItem(item, null);
|
||||
|
||||
items.Add(item);
|
||||
spawnedItem = new Item(itemInfo.Prefab, itemInfo.Position, itemInfo.Submarine);
|
||||
}
|
||||
|
||||
AddToSpawnedList(spawnedItem);
|
||||
items.Add(spawnedItem);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -30,8 +30,13 @@ namespace Barotrauma
|
||||
private float higherSurface;
|
||||
private float lowerSurface;
|
||||
|
||||
private Vector2 lerpedFlowForce;
|
||||
|
||||
//if set to true, hull connections of this gap won't be updated when changes are being done to hulls
|
||||
public bool DisableHullRechecks;
|
||||
|
||||
//can ambient light get through the gap even if it's not open
|
||||
public bool PassAmbientLight;
|
||||
|
||||
public float Open
|
||||
{
|
||||
@@ -48,8 +53,6 @@ namespace Barotrauma
|
||||
get { return lerpedFlowForce; }
|
||||
}
|
||||
|
||||
private Vector2 lerpedFlowForce;
|
||||
|
||||
public Hull FlowTargetHull
|
||||
{
|
||||
get { return flowTargetHull; }
|
||||
@@ -189,7 +192,7 @@ namespace Barotrauma
|
||||
Color clr = (open == 0.0f) ? Color.Red : Color.Cyan;
|
||||
if (isHighlighted) clr = Color.Gold;
|
||||
|
||||
GUI.DrawRectangle(sb, new Rectangle(WorldRect.X, -WorldRect.Y, rect.Width, rect.Height), clr * 0.5f, true);
|
||||
GUI.DrawRectangle(sb, new Rectangle(WorldRect.X, -WorldRect.Y, rect.Width, rect.Height), clr * 0.5f, true,0, (int)Math.Max((1.5f / GameScreen.Selected.Cam.Zoom), 1.0f));
|
||||
|
||||
for (int i = 0; i < linkedTo.Count; i++)
|
||||
{
|
||||
@@ -212,7 +215,10 @@ namespace Barotrauma
|
||||
GUI.DrawRectangle(sb,
|
||||
new Vector2(WorldRect.X - 5, -WorldRect.Y - 5),
|
||||
new Vector2(rect.Width + 10, rect.Height + 10),
|
||||
Color.Red);
|
||||
Color.Red,
|
||||
false,
|
||||
0,
|
||||
(int)Math.Max((1.5f / GameScreen.Selected.Cam.Zoom), 1.0f));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+110
-37
@@ -16,6 +16,13 @@ namespace Barotrauma
|
||||
{
|
||||
public static List<Hull> hullList = new List<Hull>();
|
||||
private static List<EntityGrid> entityGrids = new List<EntityGrid>();
|
||||
public static List<EntityGrid> EntityGrids
|
||||
{
|
||||
get
|
||||
{
|
||||
return entityGrids;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool ShowHulls = true;
|
||||
|
||||
@@ -53,6 +60,8 @@ namespace Barotrauma
|
||||
|
||||
private bool update;
|
||||
|
||||
public bool Visible = true;
|
||||
|
||||
private Sound currentFlowSound;
|
||||
private int soundIndex;
|
||||
private float soundVolume;
|
||||
@@ -65,7 +74,7 @@ namespace Barotrauma
|
||||
|
||||
private float lastSentVolume, lastSentOxygen;
|
||||
private float lastNetworkUpdate;
|
||||
|
||||
|
||||
public List<Gap> ConnectedGaps;
|
||||
|
||||
public override string Name
|
||||
@@ -91,6 +100,9 @@ namespace Barotrauma
|
||||
Item.UpdateHulls();
|
||||
Gap.UpdateHulls();
|
||||
}
|
||||
|
||||
surface = rect.Y - rect.Height + Volume / rect.Width;
|
||||
Pressure = surface;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -248,8 +260,8 @@ namespace Barotrauma
|
||||
|
||||
return rect;
|
||||
}
|
||||
|
||||
public static void GenerateEntityGrid(Submarine submarine)
|
||||
|
||||
public static EntityGrid GenerateEntityGrid(Submarine submarine)
|
||||
{
|
||||
var newGrid = new EntityGrid(submarine, 200.0f);
|
||||
|
||||
@@ -259,6 +271,7 @@ namespace Barotrauma
|
||||
{
|
||||
if (hull.Submarine == submarine) newGrid.InsertEntity(hull);
|
||||
}
|
||||
return newGrid;
|
||||
}
|
||||
|
||||
public void AddToGrid(Submarine submarine)
|
||||
@@ -306,6 +319,9 @@ namespace Barotrauma
|
||||
Item.UpdateHulls();
|
||||
Gap.UpdateHulls();
|
||||
}
|
||||
|
||||
surface = rect.Y - rect.Height + Volume / rect.Width;
|
||||
Pressure = surface;
|
||||
}
|
||||
|
||||
public override void Remove()
|
||||
@@ -388,26 +404,21 @@ namespace Barotrauma
|
||||
float strongestFlow = 0.0f;
|
||||
foreach (Gap gap in ConnectedGaps)
|
||||
{
|
||||
float gapFlow = gap.LerpedFlowForce.Length();
|
||||
|
||||
#if DEBUG
|
||||
var asd = MapEntity.FindEntityByID(gap.ID);
|
||||
|
||||
if (asd != gap)
|
||||
if (gap.IsRoomToRoom)
|
||||
{
|
||||
int adslkmfdlasfk = 9;
|
||||
//only the first linked hull plays the flow sound
|
||||
if (gap.linkedTo[1] == this) continue;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
float gapFlow = gap.LerpedFlowForce.Length();
|
||||
|
||||
if (gapFlow > strongestFlow)
|
||||
{
|
||||
strongestFlow = gapFlow;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (strongestFlow>0.1f)
|
||||
|
||||
if (strongestFlow > 1.0f)
|
||||
{
|
||||
soundVolume = soundVolume + ((strongestFlow < 100.0f) ? -deltaTime * 0.5f : deltaTime * 0.5f);
|
||||
soundVolume = MathHelper.Clamp(soundVolume, 0.0f, 1.0f);
|
||||
@@ -424,8 +435,7 @@ namespace Barotrauma
|
||||
}
|
||||
|
||||
currentFlowSound = flowSound;
|
||||
|
||||
soundIndex = currentFlowSound.Loop(soundIndex, soundVolume, WorldPosition, 2000.0f);
|
||||
soundIndex = currentFlowSound.Loop(soundIndex, soundVolume, WorldPosition, Math.Min(strongestFlow*5.0f, 2000.0f));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -478,11 +488,9 @@ namespace Barotrauma
|
||||
waveVel[i] = waveVel[i] * -0.5f;
|
||||
}
|
||||
|
||||
|
||||
//acceleration
|
||||
float a = -WaveStiffness * waveY[i] - waveVel[i] * WaveDampening;
|
||||
waveVel[i] = waveVel[i] + a;
|
||||
|
||||
}
|
||||
|
||||
for (int j = 0; j < 2; j++)
|
||||
@@ -503,15 +511,21 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
//interpolate the position of the rendered surface towards the "target surface"
|
||||
surface = Math.Max(MathHelper.Lerp(surface, surfaceY, deltaTime*10.0f), rect.Y - rect.Height);
|
||||
|
||||
if (volume < FullVolume)
|
||||
{
|
||||
LethalPressure -= 10.0f * deltaTime;
|
||||
if (Volume == 0.0f)
|
||||
{
|
||||
//wait for the surface to be lerped back to bottom and the waves to settle until disabling update
|
||||
if (surface > rect.Y - rect.Height + 1) return;
|
||||
for (int i = 1; i < waveY.Length - 1; i++)
|
||||
{
|
||||
if (waveY[i] > 0.1f) return;
|
||||
}
|
||||
|
||||
update = false;
|
||||
}
|
||||
}
|
||||
@@ -546,6 +560,18 @@ namespace Barotrauma
|
||||
public override void Draw(SpriteBatch spriteBatch, bool editing, bool back = true)
|
||||
{
|
||||
//if (back) return;
|
||||
Rectangle drawRect;
|
||||
if (!Visible)
|
||||
{
|
||||
drawRect =
|
||||
Submarine == null ? rect : new Rectangle((int)(Submarine.DrawPosition.X + rect.X), (int)(Submarine.DrawPosition.Y + rect.Y), rect.Width, rect.Height);
|
||||
|
||||
GUI.DrawRectangle(spriteBatch,
|
||||
new Vector2(drawRect.X, -drawRect.Y),
|
||||
new Vector2(rect.Width, rect.Height),
|
||||
Color.Black,true,
|
||||
0, (int)Math.Max((1.5f / GameScreen.Selected.Cam.Zoom), 1.0f));
|
||||
}
|
||||
|
||||
if (!ShowHulls && !GameMain.DebugDraw) return;
|
||||
|
||||
@@ -553,17 +579,17 @@ namespace Barotrauma
|
||||
|
||||
if (aiTarget != null) aiTarget.Draw(spriteBatch);
|
||||
|
||||
Rectangle drawRect =
|
||||
drawRect =
|
||||
Submarine == null ? rect : new Rectangle((int)(Submarine.DrawPosition.X + rect.X), (int)(Submarine.DrawPosition.Y + rect.Y), rect.Width, rect.Height);
|
||||
|
||||
GUI.DrawRectangle(spriteBatch,
|
||||
new Vector2(drawRect.X, -drawRect.Y),
|
||||
new Vector2(rect.Width, rect.Height),
|
||||
Color.Blue);
|
||||
Color.Blue, false, 0, (int)Math.Max((1.5f / Screen.Selected.Cam.Zoom), 1.0f));
|
||||
|
||||
GUI.DrawRectangle(spriteBatch,
|
||||
new Rectangle(drawRect.X, -drawRect.Y, rect.Width, rect.Height),
|
||||
Color.Red*((100.0f-OxygenPercentage)/400.0f), true);
|
||||
Color.Red * ((100.0f - OxygenPercentage) / 400.0f), true, 0, (int)Math.Max((1.5f / GameScreen.Selected.Cam.Zoom), 1.0f));
|
||||
|
||||
if (GameMain.DebugDraw)
|
||||
{
|
||||
@@ -578,18 +604,10 @@ namespace Barotrauma
|
||||
GUI.DrawRectangle(spriteBatch,
|
||||
new Vector2(drawRect.X + 5, -drawRect.Y + 5),
|
||||
new Vector2(rect.Width - 10, rect.Height - 10),
|
||||
isHighlighted ? Color.LightBlue*0.5f : Color.Red*0.5f, true);
|
||||
isHighlighted ? Color.LightBlue * 0.5f : Color.Red * 0.5f, true, 0, (int)Math.Max((1.5f / GameScreen.Selected.Cam.Zoom), 1.0f));
|
||||
}
|
||||
}
|
||||
|
||||
private float GetSurfaceY()
|
||||
{
|
||||
float top = rect.Y + Submarine.DrawPosition.Y;
|
||||
float bottom = top - rect.Height;
|
||||
|
||||
return bottom + Volume / rect.Width;
|
||||
}
|
||||
|
||||
|
||||
public void Render(GraphicsDevice graphicsDevice, Camera cam)
|
||||
{
|
||||
if (renderer.PositionInBuffer > renderer.vertices.Length - 6) return;
|
||||
@@ -599,10 +617,7 @@ namespace Barotrauma
|
||||
//calculate where the surface should be based on the water volume
|
||||
float top = rect.Y + submarinePos.Y;
|
||||
float bottom = top - rect.Height;
|
||||
float surfaceY = bottom + Volume / rect.Width;
|
||||
|
||||
//interpolate the position of the rendered surface towards the "target surface"
|
||||
surface = surface + ((surfaceY - submarinePos.Y) - surface) / 10.0f;
|
||||
float drawSurface = surface + submarinePos.Y;
|
||||
|
||||
Matrix transform = cam.Transform * Matrix.CreateOrthographic(GameMain.GraphicsWidth, GameMain.GraphicsHeight, -1, 1) * 0.5f;
|
||||
@@ -703,7 +718,6 @@ namespace Barotrauma
|
||||
}
|
||||
|
||||
var entities = EntityGrid.GetEntities(entityGrids, position, useWorldCoordinates);
|
||||
|
||||
foreach (Hull hull in entities)
|
||||
{
|
||||
if (Submarine.RectContains(useWorldCoordinates ? hull.WorldRect : hull.rect, position)) return hull;
|
||||
@@ -711,7 +725,7 @@ namespace Barotrauma
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
//returns the water block which contains the point (or null if it isn't inside any)
|
||||
public static Hull FindHullOld(Vector2 position, Hull guess = null, bool useWorldCoordinates = true)
|
||||
{
|
||||
@@ -733,6 +747,65 @@ namespace Barotrauma
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void DetectItemVisibility(Character c=null)
|
||||
{
|
||||
if (c==null)
|
||||
{
|
||||
foreach (Item it in Item.ItemList)
|
||||
{
|
||||
it.Visible = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Hull h = c.CurrentHull;
|
||||
hullList.ForEach(j => j.Visible = false);
|
||||
List<Hull> visibleHulls;
|
||||
if (h == null || c.Submarine == null)
|
||||
{
|
||||
visibleHulls = hullList.FindAll(j => j.CanSeeOther(null, false));
|
||||
}
|
||||
else
|
||||
{
|
||||
visibleHulls = hullList.FindAll(j => h.CanSeeOther(j, true));
|
||||
}
|
||||
visibleHulls.ForEach(j => j.Visible = true);
|
||||
foreach (Item it in Item.ItemList)
|
||||
{
|
||||
if (it.CurrentHull == null || visibleHulls.Contains(it.CurrentHull)) it.Visible = true;
|
||||
else it.Visible = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool CanSeeOther(Hull other,bool allowIndirect=true)
|
||||
{
|
||||
if (other == this) return true;
|
||||
|
||||
if (other != null && other.Submarine==Submarine)
|
||||
{
|
||||
bool retVal = false;
|
||||
foreach (Gap g in ConnectedGaps)
|
||||
{
|
||||
if (g.ConnectedWall != null && g.ConnectedWall.CastShadow) continue;
|
||||
List<Hull> otherHulls = Hull.hullList.FindAll(h => h.ConnectedGaps.Contains(g) && h!=this);
|
||||
retVal = otherHulls.Any(h => h == other);
|
||||
if (!retVal && allowIndirect) retVal = otherHulls.Any(h => h.CanSeeOther(other, false));
|
||||
if (retVal) return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (Gap g in ConnectedGaps)
|
||||
{
|
||||
if (g.ConnectedDoor != null && !hullList.Any(h => h.ConnectedGaps.Contains(g) && h!=this)) return true;
|
||||
}
|
||||
List<MapEntity> structures = MapEntity.mapEntityList.FindAll(me => me is Structure && me.Rect.Intersects(Rect));
|
||||
return structures.Any(st => !(st as Structure).CastShadow);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//public List<Gap> FindGaps()
|
||||
//{
|
||||
// List<Gap> gaps = new List<Gap>();
|
||||
|
||||
@@ -185,6 +185,8 @@ namespace Barotrauma
|
||||
|
||||
foreach (GraphEdge ge in graphEdges)
|
||||
{
|
||||
if (ge.point1 == ge.point2) continue;
|
||||
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
Site site = (i == 0) ? ge.site1 : ge.site2;
|
||||
@@ -408,31 +410,29 @@ namespace Barotrauma
|
||||
bodyPoints[i] = ConvertUnits.ToSimUnits(bodyPoints[i]);
|
||||
}
|
||||
|
||||
|
||||
if (cell.CellType == CellType.Empty) continue;
|
||||
|
||||
triangles = MathUtils.TriangulateConvexHull(bodyPoints, cell.Center);
|
||||
triangles = MathUtils.TriangulateConvexHull(bodyPoints, ConvertUnits.ToSimUnits(cell.Center));
|
||||
|
||||
Body edgeBody = new Body(GameMain.World);
|
||||
Body cellBody = new Body(GameMain.World);
|
||||
|
||||
for (int i = 0; i < triangles.Count; i++)
|
||||
{
|
||||
if (triangles[i][0].Y == triangles[i][1].Y && triangles[i][0].Y == triangles[i][2].Y) continue;
|
||||
if (triangles[i][0].X == triangles[i][1].X && triangles[i][0].X == triangles[i][2].X) continue;
|
||||
|
||||
if (Vector2.DistanceSquared(triangles[i][0], triangles[i][1]) < 0.1f) continue;
|
||||
if (Vector2.DistanceSquared(triangles[i][1], triangles[i][2]) < 0.1f) continue;
|
||||
|
||||
Vertices bodyVertices = new Vertices(triangles[i]);
|
||||
FixtureFactory.AttachPolygon(bodyVertices, 5.0f, edgeBody);
|
||||
FixtureFactory.AttachPolygon(bodyVertices, 5.0f, cellBody);
|
||||
}
|
||||
|
||||
edgeBody.UserData = cell;
|
||||
edgeBody.SleepingAllowed = false;
|
||||
edgeBody.BodyType = BodyType.Kinematic;
|
||||
edgeBody.CollisionCategories = Physics.CollisionLevel;
|
||||
cellBody.UserData = cell;
|
||||
cellBody.SleepingAllowed = false;
|
||||
cellBody.BodyType = BodyType.Kinematic;
|
||||
cellBody.CollisionCategories = Physics.CollisionLevel;
|
||||
|
||||
cell.body = edgeBody;
|
||||
bodies.Add(edgeBody);
|
||||
cell.body = cellBody;
|
||||
bodies.Add(cellBody);
|
||||
}
|
||||
|
||||
return bodies;
|
||||
@@ -489,7 +489,7 @@ namespace Barotrauma
|
||||
if (!MathUtils.IsValid(leftNormal))
|
||||
{
|
||||
#if DEBUG
|
||||
DebugConsole.ThrowError("Invalid right normal");
|
||||
DebugConsole.ThrowError("Invalid left normal");
|
||||
#endif
|
||||
if (cell.body != null)
|
||||
{
|
||||
|
||||
@@ -181,7 +181,7 @@ namespace Barotrauma
|
||||
|
||||
backgroundColor = generationParams.BackgroundColor;
|
||||
float avgValue = (backgroundColor.R + backgroundColor.G + backgroundColor.G) / 3;
|
||||
GameMain.LightManager.AmbientLight = new Color(backgroundColor * (60.0f / avgValue), 1.0f);
|
||||
GameMain.LightManager.AmbientLight = new Color(backgroundColor * (10.0f / avgValue), 1.0f);
|
||||
|
||||
float minWidth = Submarine.MainSub == null ? 0.0f : Math.Max(Submarine.MainSub.Borders.Width, Submarine.MainSub.Borders.Height);
|
||||
minWidth = Math.Max(minWidth, 6500.0f);
|
||||
@@ -757,7 +757,7 @@ namespace Barotrauma
|
||||
int tries = 0;
|
||||
do
|
||||
{
|
||||
Vector2 startPos = Level.Loaded.GetRandomInterestingPosition(true, spawnPosType);
|
||||
Vector2 startPos = Level.Loaded.GetRandomInterestingPosition(true, spawnPosType, true);
|
||||
|
||||
startPos += Rand.Vector(Rand.Range(0.0f, randomSpread, false), false);
|
||||
|
||||
@@ -784,11 +784,21 @@ namespace Barotrauma
|
||||
return position;
|
||||
}
|
||||
|
||||
public Vector2 GetRandomInterestingPosition(bool useSyncedRand, PositionType positionType)
|
||||
public Vector2 GetRandomInterestingPosition(bool useSyncedRand, PositionType positionType, bool avoidSubs)
|
||||
{
|
||||
if (!positionsOfInterest.Any()) return Size * 0.5f;
|
||||
|
||||
var matchingPositions = positionsOfInterest.FindAll(p => positionType.HasFlag(p.PositionType));
|
||||
|
||||
if (avoidSubs)
|
||||
{
|
||||
foreach (Submarine sub in Submarine.Loaded)
|
||||
{
|
||||
float minDist = Math.Max(sub.Borders.Width, sub.Borders.Height);
|
||||
matchingPositions.RemoveAll(p => Vector2.Distance(p.Position, sub.WorldPosition) < minDist);
|
||||
}
|
||||
}
|
||||
|
||||
if (!matchingPositions.Any())
|
||||
{
|
||||
return positionsOfInterest[Rand.Int(positionsOfInterest.Count, !useSyncedRand)].Position;
|
||||
@@ -797,13 +807,18 @@ namespace Barotrauma
|
||||
return matchingPositions[Rand.Int(matchingPositions.Count, !useSyncedRand)].Position;
|
||||
}
|
||||
|
||||
public void Update (float deltaTime)
|
||||
public void Update(float deltaTime)
|
||||
{
|
||||
if (Submarine.MainSub != null)
|
||||
{
|
||||
WrappingWall.UpdateWallShift(Submarine.MainSub.WorldPosition, wrappingWalls);
|
||||
}
|
||||
|
||||
if (Hull.renderer != null)
|
||||
{
|
||||
Hull.renderer.ScrollWater((float)deltaTime);
|
||||
}
|
||||
|
||||
renderer.Update(deltaTime);
|
||||
}
|
||||
|
||||
@@ -834,6 +849,11 @@ namespace Barotrauma
|
||||
|
||||
public void DrawBack(GraphicsDevice graphics, SpriteBatch spriteBatch, Camera cam, BackgroundCreatureManager backgroundSpriteManager = null)
|
||||
{
|
||||
float brightness = MathHelper.Clamp(50.0f + (cam.Position.Y - Size.Y) / 2000.0f, 10.0f, 40.0f);
|
||||
|
||||
float avgValue = (backgroundColor.R + backgroundColor.G + backgroundColor.G) / 3;
|
||||
GameMain.LightManager.AmbientLight = new Color(backgroundColor * (brightness / avgValue), 1.0f);
|
||||
|
||||
graphics.Clear(backgroundColor);
|
||||
|
||||
if (renderer == null) return;
|
||||
|
||||
@@ -133,33 +133,7 @@ namespace Barotrauma
|
||||
get { return bottomHoleProbability; }
|
||||
set { bottomHoleProbability = MathHelper.Clamp(value, 0.0f, 1.0f); }
|
||||
}
|
||||
|
||||
//public LevelGenerationParams()
|
||||
//{
|
||||
// Rand.SetSyncedSeed(ToolBox.StringToInt(seed));
|
||||
|
||||
// width = 100000.0f;
|
||||
// height = 50000.0f;
|
||||
|
||||
// voronoiSiteInterval = 2000.0f;
|
||||
// voronoiSiteVariance = new Vector2(voronoiSiteInterval, voronoiSiteInterval) * 0.4f;
|
||||
|
||||
// mainPathNodeIntervalRange = new Vector2(5000.0f, 10000.0f);
|
||||
|
||||
// float brightness = Rand.Range(1.0f, 1.3f, false);
|
||||
// BackgroundColor = Color.Lerp(new Color(11, 18, 26), new Color(50, 46, 20), Rand.Range(0.0f, 1.0f, false)) * brightness;
|
||||
// BackgroundColor = new Color(BackgroundColor, 1.0f);
|
||||
|
||||
// smallTunnelCount = 5;
|
||||
// smallTunnelLengthRange = new Vector2(5000.0f, 10000.0f);
|
||||
|
||||
// ruinCount = 1;
|
||||
|
||||
// bottomHoleProbability = Rand.Range(0.1f, 0.8f, false);
|
||||
|
||||
// BackgroundSpriteAmount = (int)((new Vector2(width, height)).Length() / 100);
|
||||
//}
|
||||
|
||||
|
||||
public static LevelGenerationParams GetRandom(string seed)
|
||||
{
|
||||
Rand.SetSyncedSeed(ToolBox.StringToInt(seed));
|
||||
@@ -194,7 +168,7 @@ namespace Barotrauma
|
||||
{
|
||||
presets = new List<LevelGenerationParams>();
|
||||
|
||||
var files = GameMain.SelectedPackage.GetFilesOfType(ContentType.LevelGenerationPresets);
|
||||
var files = GameMain.SelectedPackage.GetFilesOfType(ContentType.LevelGenerationParameters);
|
||||
if (!files.Any())
|
||||
{
|
||||
files.Add("Content/Map/LevelGenerationParameters.xml");
|
||||
@@ -202,7 +176,6 @@ namespace Barotrauma
|
||||
|
||||
foreach (string file in files)
|
||||
{
|
||||
|
||||
XDocument doc = ToolBox.TryLoadXml(file);
|
||||
if (doc == null || doc.Root == null) return;
|
||||
|
||||
|
||||
@@ -301,17 +301,30 @@ namespace Barotrauma.RuinGeneration
|
||||
{
|
||||
List<RuinShape> shapes = new List<RuinShape>(rooms);
|
||||
shapes.AddRange(corridors);
|
||||
|
||||
//MapEntityPrefab hullPrefab = MapEntityPrefab.list.Find(m => m.Name == "Hull");
|
||||
|
||||
|
||||
foreach (RuinShape leaf in shapes)
|
||||
{
|
||||
RuinStructureType wallType = RuinStructureType.Wall;
|
||||
|
||||
if (!(leaf is BTRoom))
|
||||
{
|
||||
wallType = RuinStructureType.CorridorWall;
|
||||
}
|
||||
//rooms further from the entrance are more likely to have hard-to-break walls
|
||||
else if (Rand.Range(0.0f, leaf.DistanceFromEntrance, false) > 1.5f)
|
||||
{
|
||||
wallType = RuinStructureType.HeavyWall;
|
||||
}
|
||||
|
||||
//generate walls --------------------------------------------------------------
|
||||
foreach (Line wall in leaf.Walls)
|
||||
{
|
||||
var structurePrefab = RuinStructure.GetRandom(leaf is BTRoom ? RuinStructureType.Wall : RuinStructureType.CorridorWall, leaf.GetLineAlignment(wall));
|
||||
var structurePrefab = RuinStructure.GetRandom(wallType, leaf.GetLineAlignment(wall));
|
||||
if (structurePrefab == null) continue;
|
||||
|
||||
float radius = (wall.A.X == wall.B.X) ? (structurePrefab.Prefab as StructurePrefab).Size.X * 0.5f : (structurePrefab.Prefab as StructurePrefab).Size.Y * 0.5f;
|
||||
float radius = (wall.A.X == wall.B.X) ?
|
||||
(structurePrefab.Prefab as StructurePrefab).Size.X * 0.5f :
|
||||
(structurePrefab.Prefab as StructurePrefab).Size.Y * 0.5f;
|
||||
|
||||
Rectangle rect = new Rectangle(
|
||||
(int)(wall.A.X - radius),
|
||||
@@ -331,7 +344,7 @@ namespace Barotrauma.RuinGeneration
|
||||
structure.SetCollisionCategory(Physics.CollisionLevel);
|
||||
}
|
||||
|
||||
|
||||
//generate backgrounds --------------------------------------------------------------
|
||||
var background = RuinStructure.GetRandom(RuinStructureType.Back, Alignment.Center);
|
||||
if (background == null) continue;
|
||||
|
||||
@@ -341,6 +354,7 @@ namespace Barotrauma.RuinGeneration
|
||||
|
||||
}
|
||||
|
||||
//generate props --------------------------------------------------------------
|
||||
for (int i = 0; i < shapes.Count*2; i++ )
|
||||
{
|
||||
Alignment[] alignments = new Alignment[] { Alignment.Top, Alignment.Bottom, Alignment.Right, Alignment.Left, Alignment.Center };
|
||||
@@ -383,9 +397,11 @@ namespace Barotrauma.RuinGeneration
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//generate doors & sensors that close them -------------------------------------------------------------
|
||||
|
||||
var sensorPrefab = ItemPrefab.list.Find(ip => ip.Name == "Alien Motion Sensor") as ItemPrefab;
|
||||
var wirePrefab = ItemPrefab.list.Find(ip => ip.Name == "Wire") as ItemPrefab;
|
||||
|
||||
var wirePrefab = ItemPrefab.list.Find(ip => ip.Name == "Wire") as ItemPrefab;
|
||||
|
||||
foreach (Corridor corridor in corridors)
|
||||
{
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace Barotrauma.RuinGeneration
|
||||
[Flags]
|
||||
enum RuinStructureType
|
||||
{
|
||||
Wall = 1, CorridorWall = 2, Prop = 4, Back = 8, Door=16, Hatch=32
|
||||
Wall = 1, CorridorWall = 2, Prop = 4, Back = 8, Door=16, Hatch=32, HeavyWall=64
|
||||
}
|
||||
|
||||
class RuinStructure
|
||||
@@ -88,7 +88,6 @@ namespace Barotrauma.RuinGeneration
|
||||
|
||||
foreach (RuinStructure ruinStructure in matchingStructures)
|
||||
{
|
||||
|
||||
if (randomNumber <= ruinStructure.commonness)
|
||||
{
|
||||
return ruinStructure;
|
||||
|
||||
@@ -76,8 +76,8 @@ namespace Barotrauma
|
||||
|
||||
public void ScrollWater(float deltaTime)
|
||||
{
|
||||
wavePos.X += 0.006f*deltaTime;
|
||||
wavePos.Y += 0.006f*deltaTime;
|
||||
wavePos.X += 0.006f * deltaTime;
|
||||
wavePos.Y += 0.006f * deltaTime;
|
||||
}
|
||||
|
||||
public void Render(GraphicsDevice graphicsDevice, Camera cam, RenderTarget2D texture, Matrix transform)
|
||||
|
||||
@@ -8,7 +8,9 @@ namespace Barotrauma.Lights
|
||||
{
|
||||
class LightManager
|
||||
{
|
||||
//public static Vector2 ViewPos;
|
||||
private const float AmbientLightUpdateInterval = 0.2f;
|
||||
private const float AmbientLightFalloff = 0.8f;
|
||||
|
||||
private static Entity viewTarget;
|
||||
|
||||
public static Entity ViewTarget
|
||||
@@ -35,12 +37,17 @@ namespace Barotrauma.Lights
|
||||
public bool ObstructVision;
|
||||
|
||||
private Texture2D visionCircle;
|
||||
|
||||
private Dictionary<Hull, Color> hullAmbientLights = new Dictionary<Hull, Color>();
|
||||
private Dictionary<Hull, Color> smoothedHullAmbientLights = new Dictionary<Hull, Color>();
|
||||
|
||||
private float ambientLightUpdateTimer;
|
||||
|
||||
public LightManager(GraphicsDevice graphics)
|
||||
{
|
||||
lights = new List<LightSource>();
|
||||
|
||||
AmbientLight = new Color(60, 60, 60, 255);
|
||||
AmbientLight = new Color(20, 20, 20, 255);
|
||||
|
||||
visionCircle = Sprite.LoadTexture("Content/Lights/visioncircle.png");
|
||||
|
||||
@@ -53,7 +60,10 @@ namespace Barotrauma.Lights
|
||||
|
||||
losTexture = new RenderTarget2D(graphics, GameMain.GraphicsWidth, GameMain.GraphicsHeight);
|
||||
|
||||
if (alphaClearTexture==null)
|
||||
hullAmbientLights = new Dictionary<Hull, Color>();
|
||||
smoothedHullAmbientLights = new Dictionary<Hull, Color>();
|
||||
|
||||
if (alphaClearTexture == null)
|
||||
{
|
||||
alphaClearTexture = TextureLoader.FromFile("Content/Lights/alphaOne.png");
|
||||
}
|
||||
@@ -77,7 +87,38 @@ namespace Barotrauma.Lights
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateLightMap(GraphicsDevice graphics, SpriteBatch spriteBatch, Camera cam)
|
||||
public void Update(float deltaTime)
|
||||
{
|
||||
if (ambientLightUpdateTimer > 0.0f)
|
||||
{
|
||||
ambientLightUpdateTimer -= deltaTime;
|
||||
}
|
||||
else
|
||||
{
|
||||
CalculateAmbientLights();
|
||||
|
||||
ambientLightUpdateTimer = AmbientLightUpdateInterval;
|
||||
}
|
||||
|
||||
foreach (Hull hull in hullAmbientLights.Keys)
|
||||
{
|
||||
if (!smoothedHullAmbientLights.ContainsKey(hull))
|
||||
{
|
||||
smoothedHullAmbientLights.Add(hull, Color.TransparentBlack);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (Hull hull in smoothedHullAmbientLights.Keys.ToList())
|
||||
{
|
||||
Color targetColor = Color.TransparentBlack;
|
||||
|
||||
hullAmbientLights.TryGetValue(hull, out targetColor);
|
||||
|
||||
smoothedHullAmbientLights[hull] = Color.Lerp(smoothedHullAmbientLights[hull], targetColor, deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateLightMap(GraphicsDevice graphics, SpriteBatch spriteBatch, Camera cam, Effect blur)
|
||||
{
|
||||
if (!LightingEnabled) return;
|
||||
|
||||
@@ -94,7 +135,7 @@ namespace Barotrauma.Lights
|
||||
|
||||
foreach (LightSource light in lights)
|
||||
{
|
||||
if (light.Color.A < 0.01f || light.Range < 1.0f || !light.CastShadows) continue;
|
||||
if (light.Color.A < 1 || light.Range < 1.0f || !light.CastShadows) continue;
|
||||
if (!MathUtils.CircleIntersectsRectangle(light.WorldPosition, light.Range, viewRect)) continue;
|
||||
|
||||
//clear alpha to 1
|
||||
@@ -117,8 +158,7 @@ namespace Barotrauma.Lights
|
||||
|
||||
|
||||
ClearAlphaToOne(graphics, spriteBatch);
|
||||
|
||||
|
||||
|
||||
spriteBatch.Begin(SpriteSortMode.Deferred, CustomBlendStates.MultiplyWithAlpha, null, null, null, null, cam.Transform);
|
||||
|
||||
GameMain.ParticleManager.Draw(spriteBatch, false, Particles.ParticleBlendState.Additive);
|
||||
@@ -126,7 +166,7 @@ namespace Barotrauma.Lights
|
||||
|
||||
foreach (LightSource light in lights)
|
||||
{
|
||||
if (light.Color.A < 0.01f || light.Range < 1.0f || light.CastShadows) continue;
|
||||
if (light.Color.A < 1 || light.Range < 1.0f || light.CastShadows) continue;
|
||||
//if (!MathUtils.CircleIntersectsRectangle(light.WorldPosition, light.Range, viewRect)) continue;
|
||||
|
||||
light.Draw(spriteBatch);
|
||||
@@ -147,6 +187,27 @@ namespace Barotrauma.Lights
|
||||
}
|
||||
spriteBatch.End();
|
||||
|
||||
|
||||
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Additive, null, null, null, null, cam.Transform);
|
||||
|
||||
foreach (Hull hull in smoothedHullAmbientLights.Keys)
|
||||
{
|
||||
if (smoothedHullAmbientLights[hull].A < 0.01f) continue;
|
||||
|
||||
var drawRect =
|
||||
hull.Submarine == null ?
|
||||
hull.Rect :
|
||||
new Rectangle((int)(hull.Submarine.DrawPosition.X + hull.Rect.X), (int)(hull.Submarine.DrawPosition.Y + hull.Rect.Y), hull.Rect.Width, hull.Rect.Height);
|
||||
|
||||
GUI.DrawRectangle(spriteBatch,
|
||||
new Vector2(drawRect.X, -drawRect.Y),
|
||||
new Vector2(hull.Rect.Width, hull.Rect.Height),
|
||||
smoothedHullAmbientLights[hull] * 0.5f, true);
|
||||
}
|
||||
|
||||
spriteBatch.End();
|
||||
|
||||
|
||||
//clear alpha, to avoid messing stuff up later
|
||||
ClearAlphaToOne(graphics, spriteBatch);
|
||||
|
||||
@@ -173,8 +234,6 @@ namespace Barotrauma.Lights
|
||||
|
||||
spriteBatch.Draw(visionCircle, new Vector2(ViewTarget.WorldPosition.X, -ViewTarget.WorldPosition.Y), null, Color.White, rotation,
|
||||
new Vector2(LightSource.LightTexture.Width*0.2f, LightSource.LightTexture.Height/2), scale, SpriteEffects.None, 0.0f);
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -209,6 +268,86 @@ namespace Barotrauma.Lights
|
||||
}
|
||||
graphics.SetRenderTarget(null);
|
||||
}
|
||||
|
||||
|
||||
private void CalculateAmbientLights()
|
||||
{
|
||||
hullAmbientLights.Clear();
|
||||
|
||||
foreach (LightSource light in lights)
|
||||
{
|
||||
if (light.Color.A < 1f || light.Range < 1.0f) continue;
|
||||
|
||||
var newAmbientLights = AmbientLightHulls(light);
|
||||
foreach (Hull hull in newAmbientLights.Keys)
|
||||
{
|
||||
if (hullAmbientLights.ContainsKey(hull))
|
||||
{
|
||||
//hull already lit by some other light source -> add the ambient lights up
|
||||
hullAmbientLights[hull] = new Color(
|
||||
hullAmbientLights[hull].R + newAmbientLights[hull].R,
|
||||
hullAmbientLights[hull].G + newAmbientLights[hull].G,
|
||||
hullAmbientLights[hull].B + newAmbientLights[hull].B,
|
||||
hullAmbientLights[hull].A + newAmbientLights[hull].A);
|
||||
}
|
||||
else
|
||||
{
|
||||
hullAmbientLights.Add(hull, newAmbientLights[hull]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add ambient light to the hull the lightsource is inside + all adjacent hulls connected by a gap
|
||||
/// </summary>
|
||||
private Dictionary<Hull, Color> AmbientLightHulls(LightSource light)
|
||||
{
|
||||
Dictionary<Hull, Color> hullAmbientLight = new Dictionary<Hull, Color>();
|
||||
|
||||
var hull = Hull.FindHull(light.WorldPosition);
|
||||
if (hull == null) return hullAmbientLight;
|
||||
|
||||
return AmbientLightHulls(hull, hullAmbientLight, light.Color * (light.Range/2000.0f));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A flood fill algorithm that adds ambient light to all hulls the starting hull is connected to
|
||||
/// </summary>
|
||||
private Dictionary<Hull, Color> AmbientLightHulls(Hull hull, Dictionary<Hull, Color> hullAmbientLight, Color currColor)
|
||||
{
|
||||
if (hullAmbientLight.ContainsKey(hull))
|
||||
{
|
||||
if (hullAmbientLight[hull].A > currColor.A)
|
||||
return hullAmbientLight;
|
||||
else
|
||||
hullAmbientLight[hull] = currColor;
|
||||
}
|
||||
else
|
||||
{
|
||||
hullAmbientLight.Add(hull, currColor);
|
||||
}
|
||||
|
||||
foreach (Gap g in hull.ConnectedGaps)
|
||||
{
|
||||
for (int i = 0; i < g.linkedTo.Count;i++ )
|
||||
{
|
||||
if (g.linkedTo[i] is Hull)
|
||||
{
|
||||
if (g.linkedTo[i] == hull) continue;
|
||||
|
||||
Color nextHullLight = currColor * AmbientLightFalloff;
|
||||
if (!g.PassAmbientLight) nextHullLight *= g.Open;
|
||||
|
||||
if (nextHullLight.A < 10) continue;
|
||||
|
||||
hullAmbientLight = AmbientLightHulls((Hull)g.linkedTo[i], hullAmbientLight, nextHullLight);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return hullAmbientLight;
|
||||
}
|
||||
|
||||
private void ClearAlphaToOne(GraphicsDevice graphics, SpriteBatch spriteBatch)
|
||||
{
|
||||
@@ -217,7 +356,7 @@ namespace Barotrauma.Lights
|
||||
spriteBatch.End();
|
||||
}
|
||||
|
||||
public void DrawLightMap(SpriteBatch spriteBatch, Camera cam, Effect effect)
|
||||
public void DrawLightMap(SpriteBatch spriteBatch, Effect effect)
|
||||
{
|
||||
if (!LightingEnabled) return;
|
||||
|
||||
@@ -227,11 +366,11 @@ namespace Barotrauma.Lights
|
||||
spriteBatch.End();
|
||||
}
|
||||
|
||||
public void DrawLOS(GraphicsDevice graphics, SpriteBatch spriteBatch, Camera cam, Effect effect)
|
||||
public void DrawLOS(SpriteBatch spriteBatch, Effect effect)
|
||||
{
|
||||
if (!LosEnabled || ViewTarget == null) return;
|
||||
|
||||
spriteBatch.Begin(SpriteSortMode.Deferred, CustomBlendStates.Multiplicative, null, null, null);
|
||||
spriteBatch.Begin(SpriteSortMode.Deferred, CustomBlendStates.Multiplicative, null, null, null, effect);
|
||||
spriteBatch.Draw(losTexture, Vector2.Zero, Color.White);
|
||||
spriteBatch.End();
|
||||
|
||||
@@ -264,9 +403,6 @@ namespace Barotrauma.Lights
|
||||
public static BlendState Multiplicative { get; private set; }
|
||||
public static BlendState WriteToAlpha { get; private set; }
|
||||
public static BlendState MultiplyWithAlpha { get; private set; }
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace Barotrauma.Lights
|
||||
|
||||
private Sprite overrideLightTexture;
|
||||
|
||||
public Entity ParentSub;
|
||||
public Submarine ParentSub;
|
||||
|
||||
public bool CastShadows;
|
||||
|
||||
@@ -299,6 +299,11 @@ namespace Barotrauma.Lights
|
||||
|
||||
public void Draw(SpriteBatch spriteBatch)
|
||||
{
|
||||
Vector2 drawPos = position;
|
||||
if (ParentSub != null) drawPos += ParentSub.DrawPosition;
|
||||
|
||||
drawPos.Y = -drawPos.Y;
|
||||
|
||||
if (range > 1.0f)
|
||||
{
|
||||
if (overrideLightTexture == null)
|
||||
@@ -306,20 +311,21 @@ namespace Barotrauma.Lights
|
||||
Vector2 center = new Vector2(LightTexture.Width / 2, LightTexture.Height / 2);
|
||||
float scale = range / (lightTexture.Width / 2.0f);
|
||||
|
||||
spriteBatch.Draw(lightTexture, new Vector2(WorldPosition.X, -WorldPosition.Y), null, color, 0, center, scale, SpriteEffects.None, 1);
|
||||
spriteBatch.Draw(lightTexture, drawPos, null, color * (color.A / 255.0f), 0, center, scale, SpriteEffects.None, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
overrideLightTexture.Draw(spriteBatch,
|
||||
new Vector2(WorldPosition.X, -WorldPosition.Y), Color,
|
||||
overrideLightTexture.Origin, -Rotation,
|
||||
new Vector2(overrideLightTexture.size.X/overrideLightTexture.SourceRect.Width, overrideLightTexture.size.Y/overrideLightTexture.SourceRect.Height));
|
||||
overrideLightTexture.Draw(spriteBatch,
|
||||
drawPos, color * (color.A / 255.0f),
|
||||
overrideLightTexture.Origin, -Rotation,
|
||||
new Vector2(overrideLightTexture.size.X / overrideLightTexture.SourceRect.Width, overrideLightTexture.size.Y / overrideLightTexture.SourceRect.Height));
|
||||
}
|
||||
}
|
||||
|
||||
if (LightSprite != null)
|
||||
{
|
||||
LightSprite.Draw(spriteBatch, new Vector2(WorldPosition.X, -WorldPosition.Y), Color, LightSprite.Origin);
|
||||
LightSprite.Draw(spriteBatch, drawPos, Color, LightSprite.Origin);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,14 @@ namespace Barotrauma
|
||||
private bool loadSub;
|
||||
private Submarine sub;
|
||||
|
||||
public Submarine Sub
|
||||
{
|
||||
get
|
||||
{
|
||||
return sub;
|
||||
}
|
||||
}
|
||||
|
||||
private XElement saveElement;
|
||||
|
||||
public override bool IsLinkable
|
||||
@@ -48,7 +56,7 @@ namespace Barotrauma
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public LinkedSubmarine(Submarine submarine)
|
||||
: base(null, submarine)
|
||||
{
|
||||
@@ -100,7 +108,7 @@ namespace Barotrauma
|
||||
{
|
||||
return Vector2.Distance(position, WorldPosition) < 50.0f;
|
||||
}
|
||||
|
||||
|
||||
public override void Draw(SpriteBatch spriteBatch, bool editing, bool back = true)
|
||||
{
|
||||
if (!editing || wallVertices == null) return;
|
||||
@@ -141,16 +149,15 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
public override void DrawEditing(SpriteBatch spriteBatch, Camera cam)
|
||||
public override void UpdateEditing(Camera cam)
|
||||
{
|
||||
if (editingHUD == null || editingHUD.UserData as LinkedSubmarine != this)
|
||||
{
|
||||
editingHUD = CreateEditingHUD();
|
||||
}
|
||||
|
||||
editingHUD.Update(0.016f);
|
||||
editingHUD.Draw(spriteBatch);
|
||||
|
||||
editingHUD.Update((float)Timing.Step);
|
||||
|
||||
if (!PlayerInput.LeftButtonClicked() || !PlayerInput.KeyDown(Keys.Space)) return;
|
||||
|
||||
Vector2 position = cam.ScreenToWorld(PlayerInput.MousePosition);
|
||||
@@ -170,6 +177,13 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
public override void DrawEditing(SpriteBatch spriteBatch, Camera cam)
|
||||
{
|
||||
if (editingHUD == null) return;
|
||||
|
||||
editingHUD.Draw(spriteBatch);
|
||||
}
|
||||
|
||||
|
||||
private GUIComponent CreateEditingHUD(bool inGame = false)
|
||||
{
|
||||
@@ -204,8 +218,7 @@ namespace Barotrauma
|
||||
}
|
||||
return editingHUD;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private bool Reload(GUIButton button, object obj)
|
||||
{
|
||||
var pathBox = obj as GUITextBox;
|
||||
@@ -386,8 +399,8 @@ namespace Barotrauma
|
||||
{
|
||||
if (!loadSub) return;
|
||||
|
||||
sub = Submarine.Load(saveElement, false);
|
||||
|
||||
sub = Submarine.Load(saveElement, false);
|
||||
|
||||
Vector2 worldPos = ToolBox.GetAttributeVector2(saveElement, "worldpos", Vector2.Zero);
|
||||
if (worldPos != Vector2.Zero)
|
||||
{
|
||||
@@ -399,8 +412,6 @@ namespace Barotrauma
|
||||
sub.Submarine = Submarine;
|
||||
}
|
||||
|
||||
|
||||
|
||||
var linkedItem = linkedTo.FirstOrDefault(lt => (lt is Item) && ((Item)lt).GetComponent<DockingPort>() != null);
|
||||
|
||||
if (linkedItem == null) return;
|
||||
|
||||
@@ -3,6 +3,7 @@ using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
using Voronoi2;
|
||||
|
||||
namespace Barotrauma
|
||||
@@ -28,6 +29,8 @@ namespace Barotrauma
|
||||
private Location currentLocation;
|
||||
private Location selectedLocation;
|
||||
|
||||
private Location highlightedLocation;
|
||||
|
||||
private LocationConnection selectedConnection;
|
||||
|
||||
public Location CurrentLocation
|
||||
@@ -55,6 +58,35 @@ namespace Barotrauma
|
||||
get { return seed; }
|
||||
}
|
||||
|
||||
public static Map Load(XElement element)
|
||||
{
|
||||
string mapSeed = ToolBox.GetAttributeString(element, "seed", "a");
|
||||
|
||||
int size = ToolBox.GetAttributeInt(element, "size", 500);
|
||||
Map map = new Map(mapSeed, size);
|
||||
|
||||
map.SetLocation(ToolBox.GetAttributeInt(element, "currentlocation", 0));
|
||||
|
||||
string discoveredStr = ToolBox.GetAttributeString(element, "discovered", "");
|
||||
|
||||
string[] discoveredStrs = discoveredStr.Split(',');
|
||||
for (int i = 0; i < discoveredStrs.Length; i++ )
|
||||
{
|
||||
int index = -1;
|
||||
if (int.TryParse(discoveredStrs[i], out index)) map.locations[index].Discovered = true;
|
||||
}
|
||||
|
||||
string passedStr = ToolBox.GetAttributeString(element, "passed", "");
|
||||
string[] passedStrs = passedStr.Split(',');
|
||||
for (int i = 0; i < passedStrs.Length; i++)
|
||||
{
|
||||
int index = -1;
|
||||
if (int.TryParse(passedStrs[i], out index)) map.connections[index].Passed = true;
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
public Map(string seed, int size)
|
||||
{
|
||||
this.seed = seed;
|
||||
@@ -67,15 +99,16 @@ namespace Barotrauma
|
||||
|
||||
connections = new List<LocationConnection>();
|
||||
|
||||
if (iceTexture==null) iceTexture = new Sprite("Content/Map/iceSurface.png", Vector2.Zero);
|
||||
if (iceTexture == null) iceTexture = new Sprite("Content/Map/iceSurface.png", Vector2.Zero);
|
||||
if (iceCraters == null) iceCraters = TextureLoader.FromFile("Content/Map/iceCraters.png");
|
||||
if (iceCrack == null) iceCrack = TextureLoader.FromFile("Content/Map/iceCrack.png");
|
||||
if (iceCrack == null) iceCrack = TextureLoader.FromFile("Content/Map/iceCrack.png");
|
||||
|
||||
Rand.SetSyncedSeed(ToolBox.StringToInt(this.seed));
|
||||
|
||||
GenerateLocations();
|
||||
|
||||
currentLocation = locations[locations.Count / 2];
|
||||
currentLocation.Discovered = true;
|
||||
GenerateDifficulties(currentLocation, new List<LocationConnection> (connections), 10.0f);
|
||||
|
||||
foreach (LocationConnection connection in connections)
|
||||
@@ -202,7 +235,10 @@ namespace Barotrauma
|
||||
|
||||
public void MoveToNextLocation()
|
||||
{
|
||||
selectedConnection.Passed = true;
|
||||
|
||||
currentLocation = selectedLocation;
|
||||
currentLocation.Discovered = true;
|
||||
selectedLocation = null;
|
||||
}
|
||||
|
||||
@@ -213,10 +249,11 @@ namespace Barotrauma
|
||||
DebugConsole.ThrowError("Location index out of bounds");
|
||||
return;
|
||||
}
|
||||
|
||||
currentLocation = locations[index];
|
||||
currentLocation.Discovered = true;
|
||||
}
|
||||
|
||||
private Location highlightedLocation;
|
||||
public void Update(float deltaTime, Rectangle rect, float scale = 1.0f)
|
||||
{
|
||||
Vector2 rectCenter = new Vector2(rect.Center.X, rect.Center.Y);
|
||||
@@ -240,7 +277,6 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
foreach (LocationConnection connection in connections)
|
||||
{
|
||||
if (highlightedLocation != currentLocation &&
|
||||
@@ -268,38 +304,68 @@ namespace Barotrauma
|
||||
{
|
||||
Color crackColor = Color.White * Math.Max(connection.Difficulty/100.0f, 1.5f);
|
||||
|
||||
|
||||
if (selectedLocation != currentLocation &&
|
||||
(connection.Locations.Contains(selectedLocation) && connection.Locations.Contains(currentLocation)))
|
||||
{
|
||||
crackColor = Color.Red;
|
||||
}
|
||||
|
||||
foreach (Vector2[] segment in connection.CrackSegments)
|
||||
else if (highlightedLocation != currentLocation &&
|
||||
(connection.Locations.Contains(highlightedLocation) && connection.Locations.Contains(currentLocation)))
|
||||
{
|
||||
Vector2 start = rectCenter + (segment[0] + offset) * scale;
|
||||
Vector2 end = rectCenter + (segment[1] + offset) * scale;
|
||||
|
||||
if (!rect.Contains(start) || !rect.Contains(end)) continue;
|
||||
crackColor = Color.Red * 0.5f;
|
||||
}
|
||||
else if (!connection.Passed)
|
||||
{
|
||||
crackColor *= 0.2f;
|
||||
}
|
||||
|
||||
for (int i = 0; i < connection.CrackSegments.Count; i++ )
|
||||
{
|
||||
var segment = connection.CrackSegments[i];
|
||||
|
||||
Vector2 start = rectCenter + (segment[0] + offset) * scale;
|
||||
Vector2 end = rectCenter + (segment[1] + offset) * scale;
|
||||
|
||||
if (!rect.Contains(start) && !rect.Contains(end))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
Vector2? intersection = MathUtils.GetLineRectangleIntersection(start, end, new Rectangle(rect.X, rect.Y + rect.Height, rect.Width, rect.Height));
|
||||
if (intersection != null)
|
||||
{
|
||||
if (!rect.Contains(start))
|
||||
{
|
||||
start = (Vector2)intersection;
|
||||
}
|
||||
else
|
||||
{
|
||||
end = (Vector2)intersection;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
float dist = Vector2.Distance(start, end);
|
||||
|
||||
int width = (int)(MathHelper.Clamp(connection.Difficulty, 2.0f, 20.0f) * scale);
|
||||
|
||||
spriteBatch.Draw(iceCrack,
|
||||
new Rectangle((int)start.X, (int)start.Y, (int)dist+2, 30),
|
||||
new Rectangle(0, 0, iceCrack.Width, 60), crackColor, MathUtils.VectorToAngle(end -start),
|
||||
new Rectangle((int)start.X, (int)start.Y, (int)dist + 2, width),
|
||||
new Rectangle(0, 0, iceCrack.Width, 60), crackColor, MathUtils.VectorToAngle(end - start),
|
||||
new Vector2(0, 30), SpriteEffects.None, 0.01f);
|
||||
}
|
||||
}
|
||||
|
||||
rect.Inflate(8, 8);
|
||||
GUI.DrawRectangle(spriteBatch, rect, Color.Black, 8);
|
||||
GUI.DrawRectangle(spriteBatch, rect, Color.LightGray);
|
||||
|
||||
for (int i = 0; i < locations.Count; i++)
|
||||
{
|
||||
Location location = locations[i];
|
||||
Vector2 pos = rectCenter + (location.MapPosition + offset) * scale;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Rectangle drawRect = location.Type.Sprite.SourceRect;
|
||||
Rectangle sourceRect = drawRect;
|
||||
drawRect.X = (int)pos.X - drawRect.Width/2;
|
||||
@@ -309,7 +375,7 @@ namespace Barotrauma
|
||||
|
||||
Color color = location.Connections.Find(c => c.Locations.Contains(currentLocation))==null ? Color.White : Color.Green;
|
||||
|
||||
color *= (location.Discovered) ? 0.8f : 0.4f;
|
||||
color *= (location.Discovered) ? 0.8f : 0.2f;
|
||||
|
||||
if (location == currentLocation) color = Color.Orange;
|
||||
|
||||
@@ -349,15 +415,37 @@ namespace Barotrauma
|
||||
if (location == null) continue;
|
||||
|
||||
Vector2 pos = rectCenter + (location.MapPosition + offset) * scale;
|
||||
pos.X = (int)pos.X;
|
||||
pos.Y = (int)pos.Y;
|
||||
if (highlightedLocation == location)
|
||||
{
|
||||
spriteBatch.DrawString(GUI.Font, location.Name, pos + new Vector2(0, 50), Color.DarkRed, 0.0f, GUI.Font.MeasureString(location.Name)/2.0f, 1.0f, SpriteEffects.None, 0.0f);
|
||||
}
|
||||
pos.X = (int)(pos.X + location.Type.Sprite.SourceRect.Width*0.6f);
|
||||
pos.Y = (int)(pos.Y - 10);
|
||||
GUI.DrawString(spriteBatch, pos, location.Name, Color.White, Color.Black * 0.8f, 3);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void Save(XElement element)
|
||||
{
|
||||
XElement mapElement = new XElement("map");
|
||||
|
||||
mapElement.Add(new XAttribute("currentlocation", CurrentLocationIndex));
|
||||
mapElement.Add(new XAttribute("seed", Seed));
|
||||
mapElement.Add(new XAttribute("size", size));
|
||||
|
||||
List<int> discoveredLocations = new List<int>();
|
||||
for (int i = 0; i < locations.Count; i++ )
|
||||
{
|
||||
if (locations[i].Discovered) discoveredLocations.Add(i);
|
||||
}
|
||||
mapElement.Add(new XAttribute("discovered", string.Join(",", discoveredLocations)));
|
||||
|
||||
List<int> passedConnections = new List<int>();
|
||||
for (int i = 0; i < connections.Count; i++)
|
||||
{
|
||||
if (connections[i].Passed) passedConnections.Add(i);
|
||||
}
|
||||
mapElement.Add(new XAttribute("passed", string.Join(",", passedConnections)));
|
||||
|
||||
element.Add(mapElement);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -370,33 +458,33 @@ namespace Barotrauma
|
||||
|
||||
public List<Vector2[]> CrackSegments;
|
||||
|
||||
public bool Passed;
|
||||
|
||||
private int missionsCompleted;
|
||||
|
||||
private Mission mission;
|
||||
public Mission Mission
|
||||
{
|
||||
get
|
||||
{
|
||||
if (mission==null || mission.Completed)
|
||||
{
|
||||
if (mission == null || mission.Completed)
|
||||
{
|
||||
if (mission !=null && mission.Completed) missionsCompleted++;
|
||||
if (mission != null && mission.Completed) missionsCompleted++;
|
||||
|
||||
long seed = (long)locations[0].MapPosition.X + (long)locations[0].MapPosition.Y * 100;
|
||||
seed += (long)locations[1].MapPosition.X*10000 + (long)locations[1].MapPosition.Y * 1000000;
|
||||
seed += (long)locations[1].MapPosition.X * 10000 + (long)locations[1].MapPosition.Y * 1000000;
|
||||
|
||||
MTRandom rand = new MTRandom((int)((seed + missionsCompleted) % int.MaxValue));
|
||||
|
||||
if (rand.NextDouble() < 0.3f) return null;
|
||||
|
||||
mission = Mission.LoadRandom(locations, rand);
|
||||
mission = Mission.LoadRandom(locations, rand, "", true);
|
||||
}
|
||||
|
||||
return mission;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Location[] Locations
|
||||
{
|
||||
get { return locations; }
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace Barotrauma
|
||||
public static List<MapEntity> mapEntityList = new List<MapEntity>();
|
||||
|
||||
//which entities have been selected for editing
|
||||
protected static List<MapEntity> selectedList = new List<MapEntity>();
|
||||
public static List<MapEntity> selectedList = new List<MapEntity>();
|
||||
|
||||
protected static GUIComponent editingHUD;
|
||||
|
||||
@@ -54,7 +54,7 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static bool SelectedAny
|
||||
{
|
||||
get { return selectedList.Count > 0; }
|
||||
@@ -451,7 +451,7 @@ namespace Barotrauma
|
||||
GUI.DrawRectangle(spriteBatch,
|
||||
new Vector2(e.WorldRect.X, -e.WorldRect.Y) + moveAmount,
|
||||
new Vector2(e.rect.Width, e.rect.Height),
|
||||
Color.DarkRed);
|
||||
Color.DarkRed,false,0,(int)Math.Max(1.5f/GameScreen.Selected.Cam.Zoom,1.0f));
|
||||
|
||||
//stop dragging the "selection rectangle"
|
||||
selectionPos = Vector2.Zero;
|
||||
@@ -459,22 +459,19 @@ namespace Barotrauma
|
||||
}
|
||||
if (selectionPos != null && selectionPos != Vector2.Zero)
|
||||
{
|
||||
GUI.DrawRectangle(spriteBatch, new Vector2(selectionPos.X, -selectionPos.Y), selectionSize, Color.DarkRed);
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Call DrawEditing() if only one entity is selected
|
||||
/// </summary>
|
||||
public static void Edit(SpriteBatch spriteBatch, Camera cam)
|
||||
public static void UpdateEditor(Camera cam)
|
||||
{
|
||||
if (selectedList.Count == 1)
|
||||
{
|
||||
selectedList[0].DrawEditing(spriteBatch, cam);
|
||||
selectedList[0].UpdateEditing(cam);
|
||||
|
||||
if (selectedList[0].ResizeHorizontal || selectedList[0].ResizeVertical)
|
||||
{
|
||||
selectedList[0].DrawResizing(spriteBatch, cam);
|
||||
selectedList[0].UpdateResizing(cam);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -493,6 +490,19 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void DeselectAll()
|
||||
{
|
||||
foreach (MapEntity e in selectedList)
|
||||
@@ -510,10 +520,26 @@ namespace Barotrauma
|
||||
entity.isSelected = true;
|
||||
selectedList.Add(entity);
|
||||
}
|
||||
|
||||
|
||||
public virtual void FlipX()
|
||||
{
|
||||
if (Submarine == null)
|
||||
{
|
||||
DebugConsole.ThrowError("Couldn't flip MapEntity \""+Name+"\", submarine==null");
|
||||
return;
|
||||
}
|
||||
|
||||
Vector2 relative = WorldPosition - Submarine.WorldPosition;
|
||||
relative.Y = 0.0f;
|
||||
|
||||
Move(-relative * 2.0f);
|
||||
}
|
||||
|
||||
public virtual void UpdateEditing(Camera cam) { }
|
||||
|
||||
public virtual void DrawEditing(SpriteBatch spriteBatch, Camera cam) {}
|
||||
|
||||
private void DrawResizing(SpriteBatch spriteBatch, Camera cam)
|
||||
private void UpdateResizing(Camera cam)
|
||||
{
|
||||
isHighlighted = true;
|
||||
|
||||
@@ -524,50 +550,43 @@ namespace Barotrauma
|
||||
{
|
||||
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;
|
||||
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);
|
||||
|
||||
if (highlighted)
|
||||
if (highlighted && PlayerInput.LeftButtonDown())
|
||||
{
|
||||
if (PlayerInput.LeftButtonDown())
|
||||
{
|
||||
selectionPos = Vector2.Zero;
|
||||
resizeDirX = x;
|
||||
resizeDirY = y;
|
||||
resizing = true;
|
||||
}
|
||||
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)
|
||||
if (resizeDirX > 0)
|
||||
{
|
||||
mousePos.X = Math.Max(mousePos.X, rect.X + Submarine.GridSize.X);
|
||||
placeSize.X = mousePos.X - placePosition.X;
|
||||
}
|
||||
else if (resizeDirX <0)
|
||||
else if (resizeDirX < 0)
|
||||
{
|
||||
mousePos.X = Math.Min(mousePos.X, rect.Right - Submarine.GridSize.X);
|
||||
|
||||
placeSize.X = (placePosition.X + placeSize.X)-mousePos.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;
|
||||
placeSize.Y = placePosition.Y - mousePos.Y;
|
||||
}
|
||||
else if (resizeDirY > 0)
|
||||
{
|
||||
@@ -589,6 +608,31 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static List<MapEntity> FindMapEntities(Vector2 pos)
|
||||
{
|
||||
List<MapEntity> foundEntities = new List<MapEntity>();
|
||||
|
||||
@@ -18,7 +18,9 @@ namespace Barotrauma
|
||||
public static List<MapEntityPrefab> list = new List<MapEntityPrefab>();
|
||||
|
||||
protected string name;
|
||||
|
||||
|
||||
public List<string> tags;
|
||||
|
||||
protected bool isLinkable;
|
||||
|
||||
public Sprite sprite;
|
||||
@@ -127,18 +129,14 @@ namespace Barotrauma
|
||||
Category = MapEntityCategory.Structure;
|
||||
}
|
||||
|
||||
public virtual void UpdatePlacing(SpriteBatch spriteBatch, Camera cam)
|
||||
public virtual void UpdatePlacing(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);
|
||||
|
||||
GUI.DrawLine(spriteBatch, new Vector2(position.X, -(position.Y - GameMain.GraphicsHeight)), new Vector2(position.X, -(position.Y + GameMain.GraphicsHeight)), Color.White);
|
||||
|
||||
|
||||
if (PlayerInput.LeftButtonHeld()) placePosition = position;
|
||||
}
|
||||
else
|
||||
@@ -165,7 +163,6 @@ namespace Barotrauma
|
||||
}
|
||||
|
||||
newRect.Y = -newRect.Y;
|
||||
GUI.DrawRectangle(spriteBatch, newRect, Color.DarkBlue);
|
||||
}
|
||||
|
||||
if (PlayerInput.RightButtonHeld())
|
||||
@@ -175,6 +172,39 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void CreateInstance(Rectangle rect)
|
||||
{
|
||||
object[] lobject = new object[] { this, rect };
|
||||
|
||||
@@ -52,7 +52,10 @@ namespace Barotrauma
|
||||
List<Body> bodies;
|
||||
|
||||
//sections of the wall that are supposed to be rendered
|
||||
private WallSection[] sections;
|
||||
public WallSection[] sections {
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
bool isHorizontal;
|
||||
|
||||
@@ -62,6 +65,10 @@ namespace Barotrauma
|
||||
get { return netStateID; }
|
||||
}
|
||||
|
||||
public SpriteEffects SpriteEffects = SpriteEffects.None;
|
||||
|
||||
private bool flippedX;
|
||||
|
||||
public override Sprite Sprite
|
||||
{
|
||||
get { return prefab.sprite; }
|
||||
@@ -74,7 +81,8 @@ namespace Barotrauma
|
||||
|
||||
public Direction StairDirection
|
||||
{
|
||||
get { return prefab.StairDirection; }
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public override string Name
|
||||
@@ -139,8 +147,24 @@ namespace Barotrauma
|
||||
}
|
||||
set
|
||||
{
|
||||
Rectangle oldRect = Rect;
|
||||
base.Rect = value;
|
||||
if (prefab.HasBody) CreateSections();
|
||||
else
|
||||
{
|
||||
foreach (WallSection sec in sections)
|
||||
{
|
||||
Rectangle secRect = sec.rect;
|
||||
secRect.X -= oldRect.X; secRect.Y -= oldRect.Y;
|
||||
secRect.X *= value.Width; secRect.X /= oldRect.Width;
|
||||
secRect.Y *= value.Height; secRect.Y /= oldRect.Height;
|
||||
secRect.Width *= value.Width; secRect.Width /= oldRect.Width;
|
||||
secRect.Height *= value.Height; secRect.Height /= oldRect.Height;
|
||||
secRect.X += value.X; secRect.Y += value.Y;
|
||||
sec.rect = secRect;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,6 +204,8 @@ namespace Barotrauma
|
||||
prefab = sp;
|
||||
|
||||
isHorizontal = (rect.Width>rect.Height);
|
||||
|
||||
StairDirection = prefab.StairDirection;
|
||||
|
||||
if (prefab.HasBody)
|
||||
{
|
||||
@@ -211,29 +237,9 @@ namespace Barotrauma
|
||||
sections = new WallSection[1];
|
||||
sections[0] = new WallSection(rect);
|
||||
|
||||
if (StairDirection!=Direction.None)
|
||||
if (StairDirection != Direction.None)
|
||||
{
|
||||
bodies = new List<Body>();
|
||||
|
||||
Body newBody = BodyFactory.CreateRectangle(GameMain.World,
|
||||
ConvertUnits.ToSimUnits(rect.Width * Math.Sqrt(2.0) + Submarine.GridSize.X*3.0f),
|
||||
ConvertUnits.ToSimUnits(10),
|
||||
1.5f);
|
||||
|
||||
newBody.BodyType = BodyType.Static;
|
||||
Vector2 stairPos = new Vector2(Position.X, rect.Y - rect.Height + rect.Width / 2.0f);
|
||||
stairPos += new Vector2(
|
||||
(StairDirection == Direction.Right) ? -Submarine.GridSize.X*1.5f : Submarine.GridSize.X*1.5f,
|
||||
- Submarine.GridSize.Y*2.0f);
|
||||
|
||||
newBody.Position = ConvertUnits.ToSimUnits(stairPos);
|
||||
newBody.Rotation = (StairDirection == Direction.Right) ? MathHelper.PiOver4 : -MathHelper.PiOver4;
|
||||
newBody.Friction = 0.8f;
|
||||
|
||||
newBody.CollisionCategories = Physics.CollisionStairs;
|
||||
|
||||
newBody.UserData = this;
|
||||
bodies.Add(newBody);
|
||||
CreateStairBodies();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -246,11 +252,44 @@ namespace Barotrauma
|
||||
InsertToList();
|
||||
}
|
||||
|
||||
private void CreateStairBodies()
|
||||
{
|
||||
bodies = new List<Body>();
|
||||
|
||||
Body newBody = BodyFactory.CreateRectangle(GameMain.World,
|
||||
ConvertUnits.ToSimUnits(rect.Width * Math.Sqrt(2.0) + Submarine.GridSize.X * 3.0f),
|
||||
ConvertUnits.ToSimUnits(10),
|
||||
1.5f);
|
||||
|
||||
newBody.BodyType = BodyType.Static;
|
||||
Vector2 stairPos = new Vector2(Position.X, rect.Y - rect.Height + rect.Width / 2.0f);
|
||||
stairPos += new Vector2(
|
||||
(StairDirection == Direction.Right) ? -Submarine.GridSize.X * 1.5f : Submarine.GridSize.X * 1.5f,
|
||||
-Submarine.GridSize.Y * 2.0f);
|
||||
|
||||
newBody.Position = ConvertUnits.ToSimUnits(stairPos);
|
||||
newBody.Rotation = (StairDirection == Direction.Right) ? MathHelper.PiOver4 : -MathHelper.PiOver4;
|
||||
newBody.Friction = 0.8f;
|
||||
|
||||
newBody.CollisionCategories = Physics.CollisionStairs;
|
||||
|
||||
newBody.UserData = this;
|
||||
bodies.Add(newBody);
|
||||
}
|
||||
|
||||
private void CreateSections()
|
||||
{
|
||||
int xsections = 1, ysections = 1;
|
||||
int width, height;
|
||||
|
||||
if (!HasBody)
|
||||
{
|
||||
sections = new WallSection[1];
|
||||
sections[0] = new WallSection(rect);
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (isHorizontal)
|
||||
{
|
||||
xsections = (int)Math.Ceiling((float)rect.Width / wallSectionSize);
|
||||
@@ -266,15 +305,33 @@ namespace Barotrauma
|
||||
height = (int)wallSectionSize;
|
||||
}
|
||||
|
||||
|
||||
for (int x = 0; x < xsections; x++)
|
||||
{
|
||||
for (int y = 0; y < ysections; y++)
|
||||
{
|
||||
Rectangle sectionRect = new Rectangle(rect.X + x * width, rect.Y - y * height, width, height);
|
||||
sectionRect.Width -= (int)Math.Max((sectionRect.X + sectionRect.Width) - (rect.X + rect.Width), 0.0f);
|
||||
sectionRect.Height -= (int)Math.Max((rect.Y - rect.Height) - (sectionRect.Y - sectionRect.Height), 0.0f);
|
||||
if (flippedX)
|
||||
{
|
||||
Rectangle sectionRect = new Rectangle(rect.Right - (x + 1) * width, rect.Y - y * height, width, height);
|
||||
|
||||
sections[x + y] = new WallSection(sectionRect);
|
||||
int over = Math.Max(rect.X - sectionRect.X, 0);
|
||||
|
||||
sectionRect.X += over;
|
||||
sectionRect.Width -= over;
|
||||
|
||||
sectionRect.Height -= (int)Math.Max((rect.Y - rect.Height) - (sectionRect.Y - sectionRect.Height), 0.0f);
|
||||
|
||||
sections[xsections - 1 - x + y] = new WallSection(sectionRect);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
Rectangle sectionRect = new Rectangle(rect.X + x * width, rect.Y - y * height, width, height);
|
||||
sectionRect.Width -= (int)Math.Max(sectionRect.Right - rect.Right, 0.0f);
|
||||
sectionRect.Height -= (int)Math.Max((rect.Y - rect.Height) - (sectionRect.Y - sectionRect.Height), 0.0f);
|
||||
|
||||
sections[x + y] = new WallSection(sectionRect);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -428,25 +485,28 @@ namespace Barotrauma
|
||||
if (prefab.BackgroundSprite != null)
|
||||
{
|
||||
prefab.BackgroundSprite.DrawTiled(
|
||||
spriteBatch,
|
||||
new Vector2(rect.X + drawOffset.X, -(rect.Y + drawOffset.Y)),
|
||||
new Vector2(rect.Width, rect.Height),
|
||||
spriteBatch,
|
||||
new Vector2(rect.X + drawOffset.X, -(rect.Y + drawOffset.Y)),
|
||||
new Vector2(rect.Width, rect.Height),
|
||||
Vector2.Zero, color, Point.Zero);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
SpriteEffects oldEffects = prefab.sprite.effects;
|
||||
prefab.sprite.effects ^= SpriteEffects;
|
||||
|
||||
if (back == prefab.sprite.Depth > 0.5f || editing)
|
||||
{
|
||||
foreach (WallSection s in sections)
|
||||
for (int i = 0; i < sections.Length; i++)
|
||||
{
|
||||
if (damageEffect != null)
|
||||
{
|
||||
float newCutoff = Math.Min((s.damage / prefab.MaxHealth), 0.65f);
|
||||
float newCutoff = Math.Min((sections[i].damage / prefab.MaxHealth), 0.65f);
|
||||
|
||||
if (Math.Abs(newCutoff - prevCutoff) > 0.01f)
|
||||
{
|
||||
damageEffect.Parameters["aCutoff"].SetValue(newCutoff);
|
||||
damageEffect.Parameters["cCutoff"].SetValue(newCutoff*1.2f);
|
||||
damageEffect.Parameters["cCutoff"].SetValue(newCutoff * 1.2f);
|
||||
|
||||
damageEffect.CurrentTechnique.Passes[0].Apply();
|
||||
|
||||
@@ -454,10 +514,25 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
Point offset = new Point(Math.Abs(rect.Location.X - s.rect.Location.X), Math.Abs(rect.Location.Y - s.rect.Location.Y));
|
||||
prefab.sprite.DrawTiled(spriteBatch, new Vector2(s.rect.X + drawOffset.X, -(s.rect.Y + drawOffset.Y)), new Vector2(s.rect.Width, s.rect.Height), Vector2.Zero, color, offset);
|
||||
Point textureOffset = new Point(
|
||||
Math.Abs(rect.Location.X - sections[i].rect.Location.X),
|
||||
Math.Abs(rect.Location.Y - sections[i].rect.Location.Y));
|
||||
|
||||
if (flippedX && isHorizontal)
|
||||
{
|
||||
textureOffset.X = rect.Width - textureOffset.X - sections[i].rect.Width;
|
||||
}
|
||||
|
||||
prefab.sprite.DrawTiled(
|
||||
spriteBatch,
|
||||
new Vector2(sections[i].rect.X + drawOffset.X, -(sections[i].rect.Y + drawOffset.Y)),
|
||||
new Vector2(sections[i].rect.Width, sections[i].rect.Height),
|
||||
Vector2.Zero, color,
|
||||
textureOffset);
|
||||
}
|
||||
}
|
||||
|
||||
prefab.sprite.effects = oldEffects;
|
||||
}
|
||||
|
||||
private bool OnWallCollision(Fixture f1, Fixture f2, Contact contact)
|
||||
@@ -563,6 +638,15 @@ namespace Barotrauma
|
||||
|
||||
public int FindSectionIndex(Vector2 displayPos)
|
||||
{
|
||||
if (!sections.Any()) return -1;
|
||||
|
||||
//if the sub has been flipped horizontally, the first section may be smaller than wallSectionSize
|
||||
//and we need to adjust the position accordingly
|
||||
if (sections[0].rect.Width < wallSectionSize)
|
||||
{
|
||||
displayPos.X += wallSectionSize - sections[0].rect.Width;
|
||||
}
|
||||
|
||||
int index = (isHorizontal) ?
|
||||
(int)Math.Floor((displayPos.X - rect.X) / wallSectionSize) :
|
||||
(int)Math.Floor((rect.Y - displayPos.Y) / wallSectionSize);
|
||||
@@ -758,6 +842,27 @@ namespace Barotrauma
|
||||
SetDamage(i, damage);
|
||||
}
|
||||
}
|
||||
public override void FlipX()
|
||||
{
|
||||
base.FlipX();
|
||||
|
||||
flippedX = !flippedX;
|
||||
|
||||
if (prefab.CanSpriteFlipX)
|
||||
{
|
||||
SpriteEffects ^= SpriteEffects.FlipHorizontally;
|
||||
}
|
||||
|
||||
if (StairDirection != Direction.None)
|
||||
{
|
||||
StairDirection = StairDirection == Direction.Left ? Direction.Right : Direction.Left;
|
||||
bodies.ForEach(b => GameMain.World.RemoveBody(b));
|
||||
|
||||
CreateStairBodies();
|
||||
}
|
||||
|
||||
CreateSections();
|
||||
}
|
||||
|
||||
public override XElement Save(XElement parentElement)
|
||||
{
|
||||
|
||||
@@ -17,6 +17,7 @@ namespace Barotrauma
|
||||
|
||||
private bool isPlatform;
|
||||
private Direction stairDirection;
|
||||
private bool canSpriteFlipX;
|
||||
|
||||
private float maxHealth;
|
||||
|
||||
@@ -48,6 +49,11 @@ namespace Barotrauma
|
||||
get { return stairDirection; }
|
||||
}
|
||||
|
||||
public bool CanSpriteFlipX
|
||||
{
|
||||
get { return canSpriteFlipX; }
|
||||
}
|
||||
|
||||
public Vector2 Size
|
||||
{
|
||||
get { return size; }
|
||||
@@ -107,6 +113,8 @@ namespace Barotrauma
|
||||
sp.sprite.effects = SpriteEffects.FlipHorizontally;
|
||||
if (ToolBox.GetAttributeBool(subElement, "flipvertical", false))
|
||||
sp.sprite.effects = SpriteEffects.FlipVertically;
|
||||
|
||||
sp.canSpriteFlipX = ToolBox.GetAttributeBool(subElement, "canflipx", true);
|
||||
|
||||
break;
|
||||
case "backgroundsprite":
|
||||
@@ -154,7 +162,7 @@ namespace Barotrauma
|
||||
return sp;
|
||||
}
|
||||
|
||||
public override void UpdatePlacing(SpriteBatch spriteBatch, Camera cam)
|
||||
public override void UpdatePlacing(Camera cam)
|
||||
{
|
||||
Vector2 position = Submarine.MouseToWorldGrid(cam, Submarine.MainSub);
|
||||
//Vector2 placeSize = size;
|
||||
@@ -175,7 +183,7 @@ namespace Barotrauma
|
||||
else
|
||||
{
|
||||
Vector2 placeSize = size;
|
||||
if (resizeHorizontal) placeSize.X = position.X - placePosition.X;
|
||||
if (resizeHorizontal) placeSize.X = position.X - placePosition.X;
|
||||
if (resizeVertical) placeSize.Y = placePosition.Y - position.Y;
|
||||
|
||||
newRect = Submarine.AbsRect(placePosition, placeSize);
|
||||
@@ -191,13 +199,41 @@ namespace Barotrauma
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (PlayerInput.RightButtonHeld()) selected = null;
|
||||
}
|
||||
|
||||
public override void DrawPlacing(SpriteBatch spriteBatch, Camera cam)
|
||||
{
|
||||
Vector2 position = Submarine.MouseToWorldGrid(cam, Submarine.MainSub);
|
||||
//Vector2 placeSize = size;
|
||||
|
||||
Rectangle newRect = new Rectangle((int)position.X, (int)position.Y, (int)size.X, (int)size.Y);
|
||||
|
||||
|
||||
if (placePosition == Vector2.Zero)
|
||||
{
|
||||
if (PlayerInput.LeftButtonHeld())
|
||||
placePosition = Submarine.MouseToWorldGrid(cam, Submarine.MainSub);
|
||||
|
||||
newRect.X = (int)position.X;
|
||||
newRect.Y = (int)position.Y;
|
||||
|
||||
//sprite.Draw(spriteBatch, new Vector2(position.X, -position.Y), placeSize, Color.White);
|
||||
}
|
||||
else
|
||||
{
|
||||
Vector2 placeSize = size;
|
||||
if (resizeHorizontal) placeSize.X = position.X - placePosition.X;
|
||||
if (resizeVertical) placeSize.Y = placePosition.Y - position.Y;
|
||||
|
||||
newRect = Submarine.AbsRect(placePosition, placeSize);
|
||||
}
|
||||
|
||||
sprite.DrawTiled(spriteBatch, new Vector2(newRect.X, -newRect.Y), new Vector2(newRect.Width, newRect.Height), Color.White);
|
||||
|
||||
GUI.DrawRectangle(spriteBatch, new Rectangle(newRect.X - GameMain.GraphicsWidth, -newRect.Y, newRect.Width + GameMain.GraphicsWidth*2, newRect.Height), Color.White);
|
||||
GUI.DrawRectangle(spriteBatch, new Rectangle(newRect.X, -newRect.Y - GameMain.GraphicsHeight, newRect.Width, newRect.Height + GameMain.GraphicsHeight*2), Color.White);
|
||||
|
||||
if (PlayerInput.RightButtonHeld()) selected = null;
|
||||
GUI.DrawRectangle(spriteBatch, new Rectangle(newRect.X - GameMain.GraphicsWidth, -newRect.Y, newRect.Width + GameMain.GraphicsWidth * 2, newRect.Height), Color.White);
|
||||
GUI.DrawRectangle(spriteBatch, new Rectangle(newRect.X, -newRect.Y - GameMain.GraphicsHeight, newRect.Width, newRect.Height + GameMain.GraphicsHeight * 2), Color.White);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,6 @@ namespace Barotrauma
|
||||
|
||||
class Submarine : Entity, IServerSerializable
|
||||
{
|
||||
|
||||
public static string SavePath = "Submarines";
|
||||
|
||||
public static readonly Vector2 HiddenSubStartPosition = new Vector2(-50000.0f, 80000.0f);
|
||||
@@ -53,7 +52,12 @@ namespace Barotrauma
|
||||
|
||||
public static readonly Vector2 GridSize = new Vector2(16.0f, 16.0f);
|
||||
|
||||
public static Submarine MainSub;
|
||||
public static Submarine[] MainSubs = new Submarine[2];
|
||||
public static Submarine MainSub
|
||||
{
|
||||
get { return MainSubs[0]; }
|
||||
set { MainSubs[0] = value; }
|
||||
}
|
||||
private static List<Submarine> loaded = new List<Submarine>();
|
||||
|
||||
private SubmarineBody subBody;
|
||||
@@ -73,6 +77,8 @@ namespace Barotrauma
|
||||
private Vector2 prevPosition;
|
||||
|
||||
private float lastNetworkUpdate, networkUpdateTimer;
|
||||
|
||||
private EntityGrid entityGrid = null;
|
||||
|
||||
//properties ----------------------------------------------------
|
||||
|
||||
@@ -82,6 +88,8 @@ namespace Barotrauma
|
||||
set { name = value; }
|
||||
}
|
||||
|
||||
public bool OnRadar = true;
|
||||
|
||||
public string Description
|
||||
{
|
||||
get;
|
||||
@@ -325,7 +333,7 @@ namespace Barotrauma
|
||||
|
||||
public void UpdateTransform()
|
||||
{
|
||||
DrawPosition = Timing.Interpolate(prevPosition, Position);
|
||||
DrawPosition = Timing.Interpolate(prevPosition, Position);
|
||||
}
|
||||
|
||||
//math/physics stuff ----------------------------------------------------
|
||||
@@ -477,14 +485,97 @@ namespace Barotrauma
|
||||
lastPickedFraction = closestFraction;
|
||||
return closestBody;
|
||||
}
|
||||
|
||||
|
||||
//movement ----------------------------------------------------
|
||||
|
||||
private bool flippedX = false;
|
||||
public bool FlippedX
|
||||
{
|
||||
get { return flippedX; }
|
||||
}
|
||||
|
||||
public void FlipX(List<Submarine> parents=null)
|
||||
{
|
||||
if (parents == null) parents = new List<Submarine>();
|
||||
parents.Add(this);
|
||||
|
||||
flippedX = !flippedX;
|
||||
|
||||
Item.UpdateHulls();
|
||||
|
||||
List<Item> bodyItems = Item.ItemList.FindAll(it => it.Submarine == this && it.body != null);
|
||||
|
||||
foreach (MapEntity e in MapEntity.mapEntityList)
|
||||
{
|
||||
if (e.MoveWithLevel || e.Submarine != this || e is Item) continue;
|
||||
|
||||
if (e is LinkedSubmarine)
|
||||
{
|
||||
Submarine sub = ((LinkedSubmarine)e).Sub;
|
||||
if (!parents.Contains(sub))
|
||||
{
|
||||
Vector2 relative1 = sub.SubBody.Position - SubBody.Position;
|
||||
relative1.X = -relative1.X;
|
||||
sub.SetPosition(relative1 + SubBody.Position);
|
||||
sub.FlipX(parents);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
e.FlipX();
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < MapEntity.mapEntityList.Count; i++)
|
||||
{
|
||||
if (MapEntity.mapEntityList[i].Submarine != this) continue;
|
||||
MapEntity.mapEntityList[i].Move(-HiddenSubPosition);
|
||||
}
|
||||
|
||||
Vector2 pos = new Vector2(subBody.Position.X, subBody.Position.Y);
|
||||
SubmarineBody newSubBody = new SubmarineBody(this);
|
||||
GameMain.World.RemoveBody(subBody.Body);
|
||||
subBody = newSubBody;
|
||||
SetPosition(pos);
|
||||
|
||||
if (entityGrid != null)
|
||||
{
|
||||
Hull.EntityGrids.Remove(entityGrid);
|
||||
entityGrid = null;
|
||||
}
|
||||
entityGrid = Hull.GenerateEntityGrid(this);
|
||||
|
||||
for (int i = 0; i < MapEntity.mapEntityList.Count; i++)
|
||||
{
|
||||
if (MapEntity.mapEntityList[i].Submarine != this) continue;
|
||||
MapEntity.mapEntityList[i].Move(HiddenSubPosition);
|
||||
}
|
||||
|
||||
foreach (Item item in Item.ItemList)
|
||||
{
|
||||
if (bodyItems.Contains(item))
|
||||
{
|
||||
item.Submarine = this;
|
||||
if (Position == Vector2.Zero) item.Move(-HiddenSubPosition);
|
||||
}
|
||||
else if (item.Submarine != this)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
item.FlipX();
|
||||
}
|
||||
|
||||
Item.UpdateHulls();
|
||||
Gap.UpdateHulls();
|
||||
}
|
||||
|
||||
public void Update(float deltaTime)
|
||||
{
|
||||
if (Level.Loaded == null) return;
|
||||
//if (PlayerInput.KeyHit(InputType.Crouch) && (this == MainSub)) FlipX();
|
||||
|
||||
if (Level.Loaded == null) return;
|
||||
|
||||
if (subBody == null) return;
|
||||
|
||||
subBody.Update(deltaTime);
|
||||
@@ -879,8 +970,13 @@ namespace Barotrauma
|
||||
|
||||
loaded.Add(this);
|
||||
|
||||
Hull.GenerateEntityGrid(this);
|
||||
|
||||
if (entityGrid != null)
|
||||
{
|
||||
Hull.EntityGrids.Remove(entityGrid);
|
||||
entityGrid = null;
|
||||
}
|
||||
entityGrid = Hull.GenerateEntityGrid(this);
|
||||
|
||||
for (int i = 0; i < MapEntity.mapEntityList.Count; i++)
|
||||
{
|
||||
if (MapEntity.mapEntityList[i].Submarine != this) continue;
|
||||
@@ -970,6 +1066,7 @@ namespace Barotrauma
|
||||
subBody = null;
|
||||
|
||||
if (MainSub == this) MainSub = null;
|
||||
if (MainSubs[1] == this) MainSubs[1] = null;
|
||||
|
||||
DockedTo.Clear();
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ namespace Barotrauma
|
||||
|
||||
public Vector2 TargetPosition
|
||||
{
|
||||
//get { return targetPosition; }
|
||||
//get { return targetPosition.Value; }
|
||||
set
|
||||
{
|
||||
if (!MathUtils.IsValid(value)) return;
|
||||
@@ -266,16 +266,22 @@ namespace Barotrauma
|
||||
{
|
||||
Body.SetTransform(Body.Position + ConvertUnits.ToSimUnits(amount), 0.0f);
|
||||
|
||||
if (Character.Controlled != null)
|
||||
bool isClosestSub = false;
|
||||
if (Character.Controlled == null)
|
||||
{
|
||||
Character.Controlled.CursorPosition += amount;
|
||||
isClosestSub = Submarine.GetClosest(GameMain.GameScreen.Cam.WorldViewCenter) == submarine;
|
||||
}
|
||||
else
|
||||
{
|
||||
isClosestSub = Character.Controlled.Submarine == submarine;
|
||||
|
||||
if (Character.Controlled.Submarine == submarine ||
|
||||
(Character.Controlled == null && Submarine.GetClosest(GameMain.GameScreen.Cam.WorldViewCenter) == submarine))
|
||||
{
|
||||
GameMain.GameScreen.Cam.Position += amount;
|
||||
if (GameMain.GameScreen.Cam.TargetPos != Vector2.Zero) GameMain.GameScreen.Cam.TargetPos += amount;
|
||||
}
|
||||
Character.Controlled.CursorPosition += amount;
|
||||
}
|
||||
|
||||
if (isClosestSub)
|
||||
{
|
||||
GameMain.GameScreen.Cam.Position += amount;
|
||||
if (GameMain.GameScreen.Cam.TargetPos != Vector2.Zero) GameMain.GameScreen.Cam.TargetPos += amount;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -171,32 +171,37 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
public override void DrawEditing(SpriteBatch spriteBatch, Camera cam)
|
||||
public override void UpdateEditing(Camera cam)
|
||||
{
|
||||
if (editingHUD == null || editingHUD.UserData != this)
|
||||
{
|
||||
editingHUD = CreateEditingHUD();
|
||||
}
|
||||
|
||||
|
||||
editingHUD.Update((float)Timing.Step);
|
||||
editingHUD.Draw(spriteBatch);
|
||||
|
||||
if (!PlayerInput.LeftButtonClicked()) return;
|
||||
if (PlayerInput.LeftButtonClicked())
|
||||
{
|
||||
Vector2 position = cam.ScreenToWorld(PlayerInput.MousePosition);
|
||||
|
||||
Vector2 position = cam.ScreenToWorld(PlayerInput.MousePosition);
|
||||
foreach (MapEntity e in mapEntityList)
|
||||
{
|
||||
if (e.GetType() != typeof(WayPoint)) continue;
|
||||
if (e == this) continue;
|
||||
|
||||
foreach (MapEntity e in mapEntityList)
|
||||
{
|
||||
if (e.GetType()!=typeof(WayPoint)) continue;
|
||||
if (e == this) continue;
|
||||
if (!Submarine.RectContains(e.Rect, position)) continue;
|
||||
|
||||
if (!Submarine.RectContains(e.Rect, position)) continue;
|
||||
|
||||
linkedTo.Add(e);
|
||||
e.linkedTo.Add(this);
|
||||
linkedTo.Add(e);
|
||||
e.linkedTo.Add(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void DrawEditing(SpriteBatch spriteBatch, Camera cam)
|
||||
{
|
||||
if (editingHUD != null) editingHUD.Draw(spriteBatch);
|
||||
}
|
||||
|
||||
private bool ChangeSpawnType(GUIButton button, object obj)
|
||||
{
|
||||
GUITextBlock spawnTypeText = button.Parent as GUITextBlock;
|
||||
|
||||
@@ -23,6 +23,8 @@ namespace Barotrauma.Networking
|
||||
public string name;
|
||||
public byte ID;
|
||||
|
||||
public byte TeamID = 0;
|
||||
|
||||
public Character Character;
|
||||
public CharacterInfo characterInfo;
|
||||
public NetConnection Connection { get; set; }
|
||||
|
||||
@@ -590,7 +590,7 @@ namespace Barotrauma.Networking
|
||||
Rand.SetSyncedSeed(seed);
|
||||
|
||||
GameMain.GameSession = new GameSession(GameMain.NetLobbyScreen.SelectedSub, "", gameMode, Mission.MissionTypes[missionTypeIndex]);
|
||||
GameMain.GameSession.StartShift(levelSeed);
|
||||
GameMain.GameSession.StartShift(levelSeed,loadSecondSub);
|
||||
|
||||
if (respawnAllowed) respawnManager = new RespawnManager(this, GameMain.NetLobbyScreen.SelectedShuttle);
|
||||
|
||||
|
||||
@@ -199,22 +199,23 @@ namespace Barotrauma.Networking
|
||||
request.AddParameter("password", string.IsNullOrWhiteSpace(password) ? 0 : 1);
|
||||
|
||||
// execute the request
|
||||
RestResponse response = (RestResponse)restClient.Execute(request);
|
||||
|
||||
if (response.StatusCode != System.Net.HttpStatusCode.OK)
|
||||
restClient.ExecuteAsync(request, response =>
|
||||
{
|
||||
DebugConsole.ThrowError("Error while connecting to master server (" +response.StatusCode+": "+response.StatusDescription+")");
|
||||
return;
|
||||
}
|
||||
if (response.StatusCode != System.Net.HttpStatusCode.OK)
|
||||
{
|
||||
DebugConsole.ThrowError("Error while connecting to master server (" + response.StatusCode + ": " + response.StatusDescription + ")");
|
||||
return;
|
||||
}
|
||||
|
||||
if (response != null && !string.IsNullOrWhiteSpace(response.Content))
|
||||
{
|
||||
DebugConsole.ThrowError("Error while connecting to master server (" +response.Content+")");
|
||||
return;
|
||||
}
|
||||
if (response != null && !string.IsNullOrWhiteSpace(response.Content))
|
||||
{
|
||||
DebugConsole.ThrowError("Error while connecting to master server (" + response.Content + ")");
|
||||
return;
|
||||
}
|
||||
|
||||
registeredToMaster = true;
|
||||
refreshMasterTimer = DateTime.Now + refreshMasterInterval;
|
||||
registeredToMaster = true;
|
||||
refreshMasterTimer = DateTime.Now + refreshMasterInterval;
|
||||
});
|
||||
}
|
||||
|
||||
private IEnumerable<object> RefreshMaster()
|
||||
@@ -285,6 +286,8 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
if (ShowNetStats) netStats.Update(deltaTime);
|
||||
if (settingsFrame != null) settingsFrame.Update(deltaTime);
|
||||
if (log.LogFrame != null) log.LogFrame.Update(deltaTime);
|
||||
|
||||
|
||||
if (!started) return;
|
||||
|
||||
@@ -303,8 +306,6 @@ namespace Barotrauma.Networking
|
||||
|
||||
if (gameStarted)
|
||||
{
|
||||
inGameHUD.Update((float)Timing.Step);
|
||||
|
||||
if (respawnManager != null) respawnManager.Update(deltaTime);
|
||||
|
||||
bool isCrewDead =
|
||||
@@ -314,7 +315,7 @@ namespace Barotrauma.Networking
|
||||
//restart if all characters are dead or submarine is at the end of the level
|
||||
if ((autoRestart && isCrewDead)
|
||||
||
|
||||
(EndRoundAtLevelEnd && Submarine.MainSub != null && Submarine.MainSub.AtEndPosition))
|
||||
(EndRoundAtLevelEnd && Submarine.MainSub != null && Submarine.MainSub.AtEndPosition && Submarine.MainSubs[1]==null))
|
||||
{
|
||||
if (AutoRestart && isCrewDead)
|
||||
{
|
||||
@@ -828,13 +829,22 @@ namespace Barotrauma.Networking
|
||||
|
||||
GUIMessageBox.CloseAll();
|
||||
|
||||
//AssignJobs(connectedClients);
|
||||
|
||||
roundStartSeed = DateTime.Now.Millisecond;
|
||||
Rand.SetSyncedSeed(roundStartSeed);
|
||||
|
||||
|
||||
GameMain.GameSession = new GameSession(selectedSub, "", selectedMode, Mission.MissionTypes[GameMain.NetLobbyScreen.MissionTypeIndex]);
|
||||
GameMain.GameSession.StartShift(GameMain.NetLobbyScreen.LevelSeed);
|
||||
|
||||
yield return CoroutineStatus.Running;
|
||||
|
||||
int teamCount = 1;
|
||||
int hostTeam = 1;
|
||||
if (GameMain.GameSession.gameMode.Mission != null &&
|
||||
GameMain.GameSession.gameMode.Mission.AssignTeamIDs(connectedClients,out hostTeam))
|
||||
{
|
||||
teamCount = 2;
|
||||
}
|
||||
|
||||
GameMain.GameSession.StartShift(GameMain.NetLobbyScreen.LevelSeed, teamCount > 1);
|
||||
|
||||
GameServer.Log("Starting a new round...", Color.Cyan);
|
||||
GameServer.Log("Submarine: " + selectedSub.Name, Color.Cyan);
|
||||
@@ -842,6 +852,10 @@ namespace Barotrauma.Networking
|
||||
GameServer.Log("Level seed: " + GameMain.NetLobbyScreen.LevelSeed, Color.Cyan);
|
||||
|
||||
if (AllowRespawn) respawnManager = new RespawnManager(this, selectedShuttle);
|
||||
|
||||
for (int teamID = 1; teamID <= teamCount; teamID++)
|
||||
{
|
||||
List<Client> teamClients = teamCount == 1 ? connectedClients : connectedClients.FindAll(c => c.TeamID == teamID);
|
||||
|
||||
List<CharacterInfo> characterInfos = new List<CharacterInfo>();
|
||||
foreach (Client c in connectedClients)
|
||||
@@ -916,7 +930,8 @@ namespace Barotrauma.Networking
|
||||
|
||||
msg.Write(selectedMode.Name);
|
||||
|
||||
msg.Write(AllowRespawn);
|
||||
msg.Write(AllowRespawn);
|
||||
msg.Write(Submarine.MainSubs[1] != null); //loadSecondSub
|
||||
|
||||
var clientsWithCharacter = clients.FindAll(c => c.Character != null);
|
||||
|
||||
@@ -1134,7 +1149,6 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
else if (log.LogFrame!=null)
|
||||
{
|
||||
log.LogFrame.Update(0.016f);
|
||||
log.LogFrame.Draw(spriteBatch);
|
||||
}
|
||||
|
||||
@@ -1295,13 +1309,13 @@ namespace Barotrauma.Networking
|
||||
sender.jobPreferences = jobPreferences;
|
||||
}
|
||||
|
||||
public void AssignJobs(List<Client> unassigned)
|
||||
public void AssignJobs(List<Client> unassigned, bool assignHost)
|
||||
{
|
||||
unassigned = new List<Client>(unassigned);
|
||||
|
||||
int[] assignedClientCount = new int[JobPrefab.List.Count];
|
||||
|
||||
if (characterInfo!=null)
|
||||
if (characterInfo!=null && assignHost)
|
||||
{
|
||||
assignedClientCount[JobPrefab.List.FindIndex(jp => jp == GameMain.NetLobbyScreen.JobPreferences[0])]=1;
|
||||
}
|
||||
|
||||
@@ -45,6 +45,9 @@ namespace Barotrauma.Networking
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public Dictionary<string, bool> monsterEnabled;
|
||||
public Dictionary<string, int> extraCargo;
|
||||
|
||||
public bool ShowNetStats;
|
||||
|
||||
@@ -250,6 +253,18 @@ namespace Barotrauma.Networking
|
||||
Voting.AllowModeVoting = modeSelectionMode == SelectionMode.Vote;
|
||||
|
||||
showLogButton.Visible = SaveServerLogs;
|
||||
|
||||
List<string> monsterNames = Directory.GetDirectories("Content/Characters").ToList();
|
||||
for (int i=0;i<monsterNames.Count;i++)
|
||||
{
|
||||
monsterNames[i] = monsterNames[i].Replace("Content/Characters", "").Replace("/", "").Replace("\\", "");
|
||||
}
|
||||
monsterEnabled = new Dictionary<string, bool>();
|
||||
foreach (string s in monsterNames)
|
||||
{
|
||||
monsterEnabled.Add(s, true);
|
||||
}
|
||||
extraCargo = new Dictionary<string, int>();
|
||||
}
|
||||
|
||||
private void CreateSettingsFrame()
|
||||
@@ -286,6 +301,8 @@ namespace Barotrauma.Networking
|
||||
|
||||
int y = 0;
|
||||
|
||||
settingsTabs[0].Padding = new Vector4(40.0f, 5.0f, 40.0f, 40.0f);
|
||||
|
||||
new GUITextBlock(new Rectangle(0, y, 100, 20), "Submarine selection:", GUI.Style, settingsTabs[0]);
|
||||
var selectionFrame = new GUIFrame(new Rectangle(0, y + 20, 300, 20), null, settingsTabs[0]);
|
||||
for (int i = 0; i < 3; i++)
|
||||
@@ -314,7 +331,7 @@ namespace Barotrauma.Networking
|
||||
endBox.Selected = EndRoundAtLevelEnd;
|
||||
endBox.OnSelected = (GUITickBox) => { EndRoundAtLevelEnd = GUITickBox.Selected; return true; };
|
||||
|
||||
y += 30;
|
||||
y += 25;
|
||||
|
||||
var endVoteBox = new GUITickBox(new Rectangle(0, y, 20, 20), "End round by voting", Alignment.Left, settingsTabs[0]);
|
||||
endVoteBox.Selected = Voting.AllowEndVoting;
|
||||
@@ -342,7 +359,7 @@ namespace Barotrauma.Networking
|
||||
};
|
||||
votesRequiredSlider.OnMoved(votesRequiredSlider, votesRequiredSlider.BarScroll);
|
||||
|
||||
y += 40;
|
||||
y += 35;
|
||||
|
||||
var respawnBox = new GUITickBox(new Rectangle(0, y, 20, 20), "Allow respawning", Alignment.Left, settingsTabs[0]);
|
||||
respawnBox.Selected = AllowRespawn;
|
||||
@@ -353,9 +370,9 @@ namespace Barotrauma.Networking
|
||||
};
|
||||
|
||||
|
||||
var respawnIntervalText = new GUITextBlock(new Rectangle(20, y + 20, 20, 20), "Respawn interval", GUI.Style, settingsTabs[0], GUI.SmallFont);
|
||||
var respawnIntervalText = new GUITextBlock(new Rectangle(20, y + 18, 20, 20), "Respawn interval", GUI.Style, settingsTabs[0], GUI.SmallFont);
|
||||
|
||||
var respawnIntervalSlider = new GUIScrollBar(new Rectangle(150, y + 22, 100, 10), GUI.Style, 0.1f, settingsTabs[0]);
|
||||
var respawnIntervalSlider = new GUIScrollBar(new Rectangle(150, y + 20, 100, 10), GUI.Style, 0.1f, settingsTabs[0]);
|
||||
respawnIntervalSlider.UserData = respawnIntervalText;
|
||||
respawnIntervalSlider.Step = 0.05f;
|
||||
respawnIntervalSlider.BarScroll = RespawnInterval / 600.0f;
|
||||
@@ -369,12 +386,12 @@ namespace Barotrauma.Networking
|
||||
};
|
||||
respawnIntervalSlider.OnMoved(respawnIntervalSlider, respawnIntervalSlider.BarScroll);
|
||||
|
||||
y += 40;
|
||||
y += 35;
|
||||
|
||||
var minRespawnText = new GUITextBlock(new Rectangle(0, y, 200, 20), "Minimum players to respawn", GUI.Style, settingsTabs[0]);
|
||||
minRespawnText.ToolTip = "What percentage of players has to be dead/spectating until a respawn shuttle is dispatched";
|
||||
|
||||
var minRespawnSlider = new GUIScrollBar(new Rectangle(150, y + 22, 100, 10), GUI.Style, 0.1f, settingsTabs[0]);
|
||||
var minRespawnSlider = new GUIScrollBar(new Rectangle(150, y + 20, 100, 10), GUI.Style, 0.1f, settingsTabs[0]);
|
||||
minRespawnSlider.ToolTip = minRespawnText.ToolTip;
|
||||
minRespawnSlider.UserData = minRespawnText;
|
||||
minRespawnSlider.Step = 0.1f;
|
||||
@@ -389,13 +406,13 @@ namespace Barotrauma.Networking
|
||||
};
|
||||
minRespawnSlider.OnMoved(minRespawnSlider, MinRespawnRatio);
|
||||
|
||||
y += 35;
|
||||
y += 30;
|
||||
|
||||
var respawnDurationText = new GUITextBlock(new Rectangle(0, y, 200, 20), "Duration of respawn transport", GUI.Style, settingsTabs[0]);
|
||||
respawnDurationText.ToolTip = "The amount of time respawned players have to navigate the respawn shuttle to the main submarine. " +
|
||||
"After the duration expires, the shuttle will automatically head back out of the level.";
|
||||
|
||||
var respawnDurationSlider = new GUIScrollBar(new Rectangle(150, y + 22, 100, 10), GUI.Style, 0.1f, settingsTabs[0]);
|
||||
var respawnDurationSlider = new GUIScrollBar(new Rectangle(150, y + 20, 100, 10), GUI.Style, 0.1f, settingsTabs[0]);
|
||||
respawnDurationSlider.ToolTip = minRespawnText.ToolTip;
|
||||
respawnDurationSlider.UserData = respawnDurationText;
|
||||
respawnDurationSlider.Step = 0.1f;
|
||||
@@ -419,8 +436,139 @@ namespace Barotrauma.Networking
|
||||
};
|
||||
respawnDurationSlider.OnMoved(respawnDurationSlider, respawnDurationSlider.BarScroll);
|
||||
|
||||
y += 40;
|
||||
y += 35;
|
||||
|
||||
var monsterButton = new GUIButton(new Rectangle(0, y, 130, 20), "Monster Spawns", GUI.Style, settingsTabs[0]);
|
||||
monsterButton.Enabled = !GameStarted;
|
||||
var monsterFrame = new GUIListBox(new Rectangle(-290, 60, 280, 250), GUI.Style, settingsTabs[0]);
|
||||
monsterFrame.Visible = false;
|
||||
monsterButton.UserData = monsterFrame;
|
||||
monsterButton.OnClicked = (button, obj) =>
|
||||
{
|
||||
if (gameStarted)
|
||||
{
|
||||
((GUIComponent)obj).Visible = false;
|
||||
button.Enabled = false;
|
||||
return true;
|
||||
}
|
||||
((GUIComponent)obj).Visible = !((GUIComponent)obj).Visible;
|
||||
return true;
|
||||
};
|
||||
List<string> monsterNames = monsterEnabled.Keys.ToList();
|
||||
foreach (string s in monsterNames)
|
||||
{
|
||||
GUITextBlock textBlock = new GUITextBlock(
|
||||
new Rectangle(0, 0, 260, 25),
|
||||
s,
|
||||
GUI.Style,
|
||||
Alignment.Left, Alignment.Left, monsterFrame);
|
||||
textBlock.Padding = new Vector4(35.0f, 3.0f, 0.0f, 0.0f);
|
||||
textBlock.UserData = monsterFrame;
|
||||
textBlock.CanBeFocused = false;
|
||||
|
||||
var monsterEnabledBox = new GUITickBox(new Rectangle(-25, 0, 20, 20), "", Alignment.Left, textBlock);
|
||||
monsterEnabledBox.Selected = monsterEnabled[s];
|
||||
monsterEnabledBox.OnSelected = (GUITickBox) =>
|
||||
{
|
||||
if (gameStarted)
|
||||
{
|
||||
monsterFrame.Visible = false;
|
||||
monsterButton.Enabled = false;
|
||||
return true;
|
||||
}
|
||||
monsterEnabled[s] = !monsterEnabled[s];
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
var cargoButton = new GUIButton(new Rectangle(160, y, 130, 20), "Additional Cargo", GUI.Style, settingsTabs[0]);
|
||||
cargoButton.Enabled = !GameStarted;
|
||||
|
||||
var cargoFrame = new GUIListBox(new Rectangle(300, 60, 280, 250), GUI.Style, settingsTabs[0]);
|
||||
cargoFrame.Visible = false;
|
||||
cargoButton.UserData = cargoFrame;
|
||||
cargoButton.OnClicked = (button, obj) =>
|
||||
{
|
||||
if (gameStarted)
|
||||
{
|
||||
((GUIComponent)obj).Visible = false;
|
||||
button.Enabled = false;
|
||||
return true;
|
||||
}
|
||||
((GUIComponent)obj).Visible = !((GUIComponent)obj).Visible;
|
||||
return true;
|
||||
};
|
||||
|
||||
|
||||
foreach (MapEntityPrefab pf in MapEntityPrefab.list)
|
||||
{
|
||||
if (!(pf is ItemPrefab) || (pf.Price <= 0.0f && !pf.tags.Contains("smallitem"))) continue;
|
||||
|
||||
GUITextBlock textBlock = new GUITextBlock(
|
||||
new Rectangle(0, 0, 260, 25),
|
||||
pf.Name,
|
||||
GUI.Style,
|
||||
Alignment.Left, Alignment.Left, cargoFrame);
|
||||
textBlock.Padding = new Vector4(30.0f, 3.0f, 0.0f, 0.0f);
|
||||
textBlock.UserData = cargoFrame;
|
||||
textBlock.CanBeFocused = false;
|
||||
|
||||
if (pf.sprite != null)
|
||||
{
|
||||
float scale = Math.Min(Math.Min(30.0f / pf.sprite.SourceRect.Width, 30.0f / pf.sprite.SourceRect.Height), 1.0f);
|
||||
GUIImage img = new GUIImage(new Rectangle(-15-(int)(pf.sprite.SourceRect.Width*scale*0.5f), 12-(int)(pf.sprite.SourceRect.Height*scale*0.5f), 40, 40), pf.sprite, Alignment.Left, textBlock);
|
||||
img.Color = pf.SpriteColor;
|
||||
img.Scale = scale;
|
||||
}
|
||||
|
||||
int cargoVal = 0;
|
||||
extraCargo.TryGetValue(pf.Name, out cargoVal);
|
||||
var countText = new GUITextBlock(
|
||||
new Rectangle(180, 0, 50, 25),
|
||||
cargoVal.ToString(),
|
||||
GUI.Style,
|
||||
Alignment.Left, Alignment.Center, textBlock);
|
||||
|
||||
var incButton = new GUIButton(new Rectangle(220, 5, 10, 15), ">", GUI.Style, textBlock);
|
||||
incButton.UserData = countText;
|
||||
incButton.OnClicked = (button, obj) =>
|
||||
{
|
||||
int val;
|
||||
if (extraCargo.TryGetValue(pf.Name, out val))
|
||||
{
|
||||
extraCargo[pf.Name]++; val = extraCargo[pf.Name];
|
||||
}
|
||||
else
|
||||
{
|
||||
extraCargo.Add(pf.Name,1); val = 1;
|
||||
}
|
||||
((GUITextBlock)obj).Text = val.ToString();
|
||||
((GUITextBlock)obj).SetTextPos();
|
||||
return true;
|
||||
};
|
||||
|
||||
var decButton = new GUIButton(new Rectangle(180, 5, 10, 15), "<", GUI.Style, textBlock);
|
||||
decButton.UserData = countText;
|
||||
decButton.OnClicked = (button, obj) =>
|
||||
{
|
||||
int val;
|
||||
if (extraCargo.TryGetValue(pf.Name, out val))
|
||||
{
|
||||
extraCargo[pf.Name]--;
|
||||
val = extraCargo[pf.Name];
|
||||
if (val <= 0)
|
||||
{
|
||||
extraCargo.Remove(pf.Name);
|
||||
val = 0;
|
||||
}
|
||||
((GUITextBlock)obj).Text = val.ToString();
|
||||
((GUITextBlock)obj).SetTextPos();
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
// server settings
|
||||
|
||||
@@ -192,8 +192,8 @@ namespace Barotrauma.Networking
|
||||
if (string.IsNullOrWhiteSpace(message)) return false;
|
||||
|
||||
SendChatMessage(message);
|
||||
|
||||
textBox.Deselect();
|
||||
|
||||
if (textBox == chatMsgBox) textBox.Deselect();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -388,12 +388,12 @@ namespace Barotrauma.Networking
|
||||
|
||||
var clients = GetClientsToRespawn();
|
||||
|
||||
server.AssignJobs(clients);
|
||||
clients.ForEach(c => c.characterInfo.Job = new Job(c.assignedJob));
|
||||
|
||||
List<CharacterInfo> characterInfos = clients.Select(c => c.characterInfo).ToList();
|
||||
if (server.Character != null && server.Character.IsDead) characterInfos.Add(server.CharacterInfo);
|
||||
|
||||
server.AssignJobs(clients, server.Character != null && server.Character.IsDead);
|
||||
clients.ForEach(c => c.characterInfo.Job = new Job(c.assignedJob));
|
||||
|
||||
//the spawnpoints where the characters will spawn
|
||||
var shuttleSpawnPoints = WayPoint.SelectCrewSpawnPoints(characterInfos, respawnShuttle);
|
||||
//the spawnpoints where they would spawn if they were spawned inside the main sub
|
||||
|
||||
@@ -15,6 +15,8 @@ namespace Barotrauma.Particles
|
||||
|
||||
public readonly float VelocityMin, VelocityMax;
|
||||
|
||||
public readonly float ScaleMin, ScaleMax;
|
||||
|
||||
public readonly float ParticleAmount;
|
||||
|
||||
public ParticleEmitterPrefab(XElement element)
|
||||
@@ -37,6 +39,17 @@ namespace Barotrauma.Particles
|
||||
AngleMin = MathHelper.ToRadians(AngleMin);
|
||||
AngleMax = MathHelper.ToRadians(AngleMax);
|
||||
|
||||
if (element.Attribute("scalemin")==null)
|
||||
{
|
||||
ScaleMin = 1.0f;
|
||||
ScaleMax = 1.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
ScaleMin = ToolBox.GetAttributeFloat(element,"scalemin",1.0f);
|
||||
ScaleMax = Math.Max(ScaleMin, ToolBox.GetAttributeFloat(element, "scalemax", 1.0f));
|
||||
}
|
||||
|
||||
if (element.Attribute("velocity") == null)
|
||||
{
|
||||
VelocityMin = ToolBox.GetAttributeFloat(element, "velocitymin", 0.0f);
|
||||
@@ -58,7 +71,12 @@ namespace Barotrauma.Particles
|
||||
float angle = Rand.Range(AngleMin, AngleMax);
|
||||
Vector2 velocity = new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle)) * Rand.Range(VelocityMin, VelocityMax);
|
||||
|
||||
GameMain.ParticleManager.CreateParticle(particlePrefab, position, velocity, 0.0f, hullGuess);
|
||||
var particle = GameMain.ParticleManager.CreateParticle(particlePrefab, position, velocity, 0.0f, hullGuess);
|
||||
|
||||
if (particle!=null)
|
||||
{
|
||||
particle.Size *= Rand.Range(ScaleMin, ScaleMax);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace Barotrauma
|
||||
|
||||
private Tutorials.EditorTutorial tutorial;
|
||||
|
||||
public Camera Cam
|
||||
public override Camera Cam
|
||||
{
|
||||
get { return cam; }
|
||||
}
|
||||
@@ -835,6 +835,11 @@ namespace Barotrauma
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (MapEntity me in MapEntity.mapEntityList)
|
||||
{
|
||||
me.IsHighlighted = false;
|
||||
}
|
||||
|
||||
if (dummyCharacter.SelectedConstruction==null)
|
||||
{
|
||||
Vector2 mouseSimPos = FarseerPhysics.ConvertUnits.ToSimUnits(dummyCharacter.CursorPosition);
|
||||
@@ -861,6 +866,13 @@ namespace Barotrauma
|
||||
|
||||
GUIComponent.MouseOn = null;
|
||||
|
||||
if (!characterMode && !wiringMode)
|
||||
{
|
||||
if (MapEntityPrefab.Selected != null) MapEntityPrefab.Selected.UpdatePlacing(cam);
|
||||
|
||||
MapEntity.UpdateEditor(cam);
|
||||
}
|
||||
|
||||
leftPanel.Update((float)deltaTime);
|
||||
topPanel.Update((float)deltaTime);
|
||||
|
||||
@@ -872,7 +884,7 @@ namespace Barotrauma
|
||||
}
|
||||
wiringToolPanel.Update((float)deltaTime);
|
||||
}
|
||||
|
||||
|
||||
if (loadFrame!=null)
|
||||
{
|
||||
loadFrame.Update((float)deltaTime);
|
||||
@@ -887,6 +899,34 @@ namespace Barotrauma
|
||||
GUItabs[selectedTab].Update((float)deltaTime);
|
||||
if (PlayerInput.RightButtonClicked()) selectedTab = -1;
|
||||
}
|
||||
|
||||
|
||||
if ((characterMode || wiringMode) && dummyCharacter != null)
|
||||
{
|
||||
dummyCharacter.AnimController.FindHull(dummyCharacter.CursorWorldPosition, false);
|
||||
|
||||
foreach (Item item in dummyCharacter.SelectedItems)
|
||||
{
|
||||
if (item == null) continue;
|
||||
item.SetTransform(dummyCharacter.SimPosition, 0.0f);
|
||||
|
||||
item.Update(cam, (float)deltaTime);
|
||||
}
|
||||
|
||||
if (dummyCharacter.SelectedConstruction != null)
|
||||
{
|
||||
if (dummyCharacter.SelectedConstruction != null)
|
||||
{
|
||||
dummyCharacter.SelectedConstruction.UpdateHUD(cam, dummyCharacter);
|
||||
}
|
||||
|
||||
if (PlayerInput.KeyHit(InputType.Select) && dummyCharacter.ClosestItem != dummyCharacter.SelectedConstruction) dummyCharacter.SelectedConstruction = null;
|
||||
}
|
||||
|
||||
CharacterHUD.Update((float)deltaTime, dummyCharacter);
|
||||
}
|
||||
|
||||
GUI.Update((float)deltaTime);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -913,7 +953,7 @@ namespace Barotrauma
|
||||
|
||||
if (!characterMode && !wiringMode)
|
||||
{
|
||||
if (MapEntityPrefab.Selected != null) MapEntityPrefab.Selected.UpdatePlacing(spriteBatch, cam);
|
||||
if (MapEntityPrefab.Selected != null) MapEntityPrefab.Selected.DrawPlacing(spriteBatch,cam);
|
||||
|
||||
MapEntity.DrawSelecting(spriteBatch, cam);
|
||||
}
|
||||
@@ -932,28 +972,11 @@ namespace Barotrauma
|
||||
|
||||
if ((characterMode || wiringMode) && dummyCharacter != null)
|
||||
{
|
||||
foreach (MapEntity me in MapEntity.mapEntityList)
|
||||
{
|
||||
me.IsHighlighted = false;
|
||||
}
|
||||
|
||||
dummyCharacter.AnimController.FindHull(dummyCharacter.CursorWorldPosition, false);
|
||||
|
||||
foreach (Item item in dummyCharacter.SelectedItems)
|
||||
{
|
||||
if (item == null) continue;
|
||||
item.SetTransform(dummyCharacter.SimPosition, 0.0f);
|
||||
|
||||
item.Update(cam, (float)deltaTime);
|
||||
}
|
||||
|
||||
if (dummyCharacter.SelectedConstruction != null)
|
||||
{
|
||||
dummyCharacter.SelectedConstruction.DrawHUD(spriteBatch, dummyCharacter);
|
||||
|
||||
if (PlayerInput.KeyHit(InputType.Select) && dummyCharacter.ClosestItem != dummyCharacter.SelectedConstruction) dummyCharacter.SelectedConstruction = null;
|
||||
dummyCharacter.SelectedConstruction.DrawHUD(spriteBatch, cam, dummyCharacter);
|
||||
}
|
||||
|
||||
|
||||
dummyCharacter.DrawHUD(spriteBatch, cam);
|
||||
|
||||
if (wiringMode) wiringToolPanel.Draw(spriteBatch);
|
||||
@@ -973,7 +996,7 @@ namespace Barotrauma
|
||||
GUItabs[selectedTab].Draw(spriteBatch);
|
||||
}
|
||||
|
||||
MapEntity.Edit(spriteBatch, cam);
|
||||
MapEntity.DrawEditor(spriteBatch, cam);
|
||||
}
|
||||
|
||||
if (tutorial != null) tutorial.Draw(spriteBatch);
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace Barotrauma
|
||||
|
||||
public BackgroundCreatureManager BackgroundCreatureManager;
|
||||
|
||||
public Camera Cam
|
||||
public override Camera Cam
|
||||
{
|
||||
get { return cam; }
|
||||
}
|
||||
@@ -46,13 +46,13 @@ namespace Barotrauma
|
||||
|
||||
#if LINUX
|
||||
var blurEffect = content.Load<Effect>("blurshader_opengl");
|
||||
damageEffect = content.Load<Effect>("damageshader_opengl");
|
||||
#else
|
||||
var blurEffect = content.Load<Effect>("blurshader");
|
||||
damageEffect = content.Load<Effect>("damageshader");
|
||||
#endif
|
||||
|
||||
damageStencil = TextureLoader.FromFile("Content/Map/walldamage.png");
|
||||
|
||||
damageEffect = content.Load<Effect>("damageshader");
|
||||
damageEffect.Parameters["xStencil"].SetValue(damageStencil);
|
||||
damageEffect.Parameters["aMultiplier"].SetValue(50.0f);
|
||||
damageEffect.Parameters["cMultiplier"].SetValue(200.0f);
|
||||
@@ -95,6 +95,9 @@ namespace Barotrauma
|
||||
#if DEBUG
|
||||
if (GameMain.GameSession != null && GameMain.GameSession.Level != null && GameMain.GameSession.Submarine != null)
|
||||
{
|
||||
var closestSub = Submarine.GetClosest(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;
|
||||
@@ -102,10 +105,9 @@ namespace Barotrauma
|
||||
if (PlayerInput.KeyDown(Keys.L)) targetMovement.X += 1.0f;
|
||||
|
||||
if (targetMovement != Vector2.Zero)
|
||||
GameMain.GameSession.Submarine.ApplyForce(targetMovement * GameMain.GameSession.Submarine.SubBody.Body.Mass * 100.0f);
|
||||
closestSub.ApplyForce(targetMovement * closestSub.SubBody.Body.Mass * 100.0f);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (GameMain.GameSession != null) GameMain.GameSession.Update((float)deltaTime);
|
||||
|
||||
if (Level.Loaded != null) Level.Loaded.Update((float)deltaTime);
|
||||
@@ -114,12 +116,11 @@ namespace Barotrauma
|
||||
{
|
||||
if (Character.Controlled.SelectedConstruction == Character.Controlled.ClosestItem)
|
||||
{
|
||||
Character.Controlled.SelectedConstruction.UpdateHUD(Character.Controlled);
|
||||
Character.Controlled.SelectedConstruction.UpdateHUD(cam, Character.Controlled);
|
||||
}
|
||||
}
|
||||
Character.UpdateAll(cam, (float)deltaTime);
|
||||
|
||||
|
||||
BackgroundCreatureManager.Update(cam, (float)deltaTime);
|
||||
|
||||
GameMain.ParticleManager.Update((float)deltaTime);
|
||||
@@ -130,6 +131,8 @@ namespace Barotrauma
|
||||
{
|
||||
cam.TargetPos = Lights.LightManager.ViewTarget.WorldPosition;
|
||||
}
|
||||
|
||||
GameMain.LightManager.Update((float)deltaTime);
|
||||
cam.MoveCamera((float)deltaTime);
|
||||
|
||||
foreach (Submarine sub in Submarine.Loaded)
|
||||
@@ -168,10 +171,6 @@ namespace Barotrauma
|
||||
{
|
||||
cam.UpdateTransform(true);
|
||||
|
||||
if (Hull.renderer != null)
|
||||
{
|
||||
Hull.renderer.ScrollWater((float)deltaTime);
|
||||
}
|
||||
DrawMap(graphics, spriteBatch);
|
||||
|
||||
spriteBatch.Begin();
|
||||
@@ -180,7 +179,7 @@ namespace Barotrauma
|
||||
{
|
||||
if (Character.Controlled.SelectedConstruction == Character.Controlled.ClosestItem)
|
||||
{
|
||||
Character.Controlled.SelectedConstruction.DrawHUD(spriteBatch, Character.Controlled);
|
||||
Character.Controlled.SelectedConstruction.DrawHUD(spriteBatch, cam, Character.Controlled);
|
||||
}
|
||||
else if (!Character.Controlled.SelectedConstruction.IsInPickRange(Character.Controlled.WorldPosition))
|
||||
{
|
||||
@@ -211,7 +210,7 @@ namespace Barotrauma
|
||||
|
||||
GameMain.LightManager.ObstructVision = Character.Controlled != null && Character.Controlled.ObstructVision;
|
||||
|
||||
GameMain.LightManager.UpdateLightMap(graphics, spriteBatch, cam);
|
||||
GameMain.LightManager.UpdateLightMap(graphics, spriteBatch, cam, lightBlur.Effect);
|
||||
if (Character.Controlled != null)
|
||||
{
|
||||
GameMain.LightManager.UpdateObstructVision(graphics, spriteBatch, cam, Character.Controlled.CursorWorldPosition);
|
||||
@@ -345,8 +344,7 @@ namespace Barotrauma
|
||||
|
||||
spriteBatch.End();
|
||||
|
||||
|
||||
GameMain.LightManager.DrawLightMap(spriteBatch, cam, lightBlur.Effect);
|
||||
GameMain.LightManager.DrawLightMap(spriteBatch, lightBlur.Effect);
|
||||
|
||||
spriteBatch.Begin(SpriteSortMode.BackToFront,
|
||||
BlendState.AlphaBlend, SamplerState.LinearWrap,
|
||||
@@ -355,13 +353,13 @@ namespace Barotrauma
|
||||
|
||||
if (Level.Loaded != null) Level.Loaded.DrawFront(spriteBatch);
|
||||
|
||||
foreach (Character c in Character.CharacterList) c.DrawFront(spriteBatch);
|
||||
foreach (Character c in Character.CharacterList) c.DrawFront(spriteBatch,cam);
|
||||
|
||||
spriteBatch.End();
|
||||
|
||||
if (Character.Controlled != null)
|
||||
{
|
||||
GameMain.LightManager.DrawLOS(graphics, spriteBatch, cam, lightBlur.Effect);
|
||||
GameMain.LightManager.DrawLOS(spriteBatch, lightBlur.Effect);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace Barotrauma
|
||||
{
|
||||
class LobbyScreen : Screen
|
||||
{
|
||||
enum PanelTab { Crew = 0, Map = 1, CurrentLocation = 2, Store = 3 }
|
||||
enum PanelTab { Crew = 0, Map = 1, Store = 3 }
|
||||
|
||||
private GUIFrame topPanel;
|
||||
private GUIFrame[] bottomPanel;
|
||||
@@ -72,19 +72,15 @@ namespace Barotrauma
|
||||
Alignment.BottomLeft, Alignment.BottomLeft, topPanel);
|
||||
moneyText.TextGetter = GetMoney;
|
||||
|
||||
GUIButton button = new GUIButton(new Rectangle(-360, 0, 100, 30), "Map", null, Alignment.BottomRight, GUI.Style, topPanel);
|
||||
GUIButton button = new GUIButton(new Rectangle(-240, 0, 100, 30), "Map", null, Alignment.BottomRight, GUI.Style, topPanel);
|
||||
button.UserData = PanelTab.Map;
|
||||
button.OnClicked = SelectRightPanel;
|
||||
SelectRightPanel(button, button.UserData);
|
||||
|
||||
button = new GUIButton(new Rectangle(-240, 0, 100, 30), "Crew", null, Alignment.BottomRight, GUI.Style, topPanel);
|
||||
button = new GUIButton(new Rectangle(-120, 0, 100, 30), "Crew", null, Alignment.BottomRight, GUI.Style, topPanel);
|
||||
button.UserData = PanelTab.Crew;
|
||||
button.OnClicked = SelectRightPanel;
|
||||
|
||||
button = new GUIButton(new Rectangle(-120, 0, 100, 30), "Hire", null, Alignment.BottomRight, GUI.Style, topPanel);
|
||||
button.UserData = PanelTab.CurrentLocation;
|
||||
button.OnClicked = SelectRightPanel;
|
||||
|
||||
|
||||
button = new GUIButton(new Rectangle(0, 0, 100, 30), "Store", null, Alignment.BottomRight, GUI.Style, topPanel);
|
||||
button.UserData = PanelTab.Store;
|
||||
button.OnClicked = SelectRightPanel;
|
||||
@@ -106,7 +102,9 @@ namespace Barotrauma
|
||||
//new GUITextBlock(new Rectangle(0, 0, 200, 25), "Crew:", Color.Transparent, Color.White, Alignment.Left, GUI.Style, bottomPanel[(int)PanelTab.Crew]);
|
||||
|
||||
int crewColumnWidth = Math.Min(300, (panelRect.Width - 40) / 2);
|
||||
characterList = new GUIListBox(new Rectangle(0, 0, crewColumnWidth, 0), GUI.Style, bottomPanel[(int)PanelTab.Crew]);
|
||||
|
||||
new GUITextBlock(new Rectangle(0, 0, 100, 20), "Crew:", GUI.Style, bottomPanel[(int)PanelTab.Crew], GUI.LargeFont);
|
||||
characterList = new GUIListBox(new Rectangle(0, 40, crewColumnWidth, 0), GUI.Style, bottomPanel[(int)PanelTab.Crew]);
|
||||
characterList.OnSelected = SelectCharacter;
|
||||
|
||||
//---------------------------------------
|
||||
@@ -118,12 +116,7 @@ namespace Barotrauma
|
||||
Alignment.BottomRight, GUI.Style, bottomPanel[(int)PanelTab.Map]);
|
||||
startButton.OnClicked = StartShift;
|
||||
startButton.Enabled = false;
|
||||
|
||||
//---------------------------------------
|
||||
|
||||
bottomPanel[(int)PanelTab.CurrentLocation] = new GUIFrame(panelRect, GUI.Style);
|
||||
bottomPanel[(int)PanelTab.CurrentLocation].Padding = new Vector4(20.0f, 20.0f, 20.0f, 20.0f);
|
||||
|
||||
|
||||
//---------------------------------------
|
||||
|
||||
bottomPanel[(int)PanelTab.Store] = new GUIFrame(panelRect, GUI.Style);
|
||||
@@ -131,13 +124,13 @@ namespace Barotrauma
|
||||
|
||||
int sellColumnWidth = (panelRect.Width - 40) / 2 - 20;
|
||||
|
||||
selectedItemList = new GUIListBox(new Rectangle(0, 0, sellColumnWidth, 400), Color.White * 0.7f, GUI.Style, bottomPanel[(int)PanelTab.Store]);
|
||||
selectedItemList = new GUIListBox(new Rectangle(0, 30, sellColumnWidth, 400), Color.White * 0.7f, GUI.Style, bottomPanel[(int)PanelTab.Store]);
|
||||
selectedItemList.OnSelected = DeselectItem;
|
||||
|
||||
var costText = new GUITextBlock(new Rectangle(0, 0, 100, 25), "Cost: ", GUI.Style, Alignment.BottomLeft, Alignment.TopLeft, bottomPanel[(int)PanelTab.Store]);
|
||||
costText.TextGetter = CostTextGetter;
|
||||
|
||||
buyButton = new GUIButton(new Rectangle(sellColumnWidth + 20, 0, 100, 25), "Buy", Alignment.Bottom, GUI.Style, bottomPanel[(int)PanelTab.Store]);
|
||||
buyButton = new GUIButton(new Rectangle(selectedItemList.Rect.Width - 100, 0, 100, 25), "Buy", Alignment.Bottom, GUI.Style, bottomPanel[(int)PanelTab.Store]);
|
||||
buyButton.OnClicked = BuyItems;
|
||||
|
||||
storeItemList = new GUIListBox(new Rectangle(0, 30, sellColumnWidth, 400), Color.White * 0.7f, Alignment.TopRight, GUI.Style, bottomPanel[(int)PanelTab.Store]);
|
||||
@@ -158,10 +151,7 @@ namespace Barotrauma
|
||||
SelectItemCategory(categoryButton, category);
|
||||
}
|
||||
x += 110;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public override void Select()
|
||||
@@ -170,49 +160,51 @@ namespace Barotrauma
|
||||
|
||||
gameMode = GameMain.GameSession.gameMode as SinglePlayerMode;
|
||||
|
||||
foreach (GUIComponent component in topPanel.children)
|
||||
{
|
||||
var button = component as GUIButton;
|
||||
if (button == null || button.Text != "Hire") continue;
|
||||
|
||||
button.Enabled = GameMain.GameSession.Map.CurrentLocation.Type.HasHireableCharacters;
|
||||
break;
|
||||
}
|
||||
|
||||
UpdateCharacterLists();
|
||||
}
|
||||
|
||||
private void UpdateLocationTab(Location location)
|
||||
{
|
||||
topPanel.RemoveChild(topPanel.FindChild("locationtitle"));
|
||||
|
||||
topPanel.UserData = location;
|
||||
|
||||
var locationTitle = new GUITextBlock(new Rectangle(0, 0, 200, 25),
|
||||
"Location: "+location.Name, Color.Transparent, Color.White, Alignment.TopLeft, GUI.Style, topPanel);
|
||||
locationTitle.UserData = "locationtitle";
|
||||
locationTitle.Font = GUI.LargeFont;
|
||||
|
||||
bottomPanel[(int)PanelTab.CurrentLocation].ClearChildren();
|
||||
bottomPanel[(int)PanelTab.CurrentLocation].UserData = location;
|
||||
|
||||
if (location.HireManager != null)
|
||||
|
||||
|
||||
if (hireList == null)
|
||||
{
|
||||
hireList = new GUIListBox(new Rectangle(0, 0, 300, 0), GUI.Style, Alignment.Left, bottomPanel[(int)PanelTab.CurrentLocation]);
|
||||
hireList = new GUIListBox(new Rectangle(0, 40, 300, 0), GUI.Style, Alignment.Right, bottomPanel[(int)PanelTab.Crew]);
|
||||
new GUITextBlock(new Rectangle(0, 0, 300, 20), "Hire:", GUI.Style, Alignment.Right, Alignment.Left, bottomPanel[(int)PanelTab.Crew], false, GUI.LargeFont);
|
||||
|
||||
hireList.OnSelected = SelectCharacter;
|
||||
|
||||
hireList.ClearChildren();
|
||||
foreach (CharacterInfo c in location.HireManager.availableCharacters)
|
||||
{
|
||||
var frame = c.CreateCharacterFrame(hireList, c.Name + " (" + c.Job.Name + ")", c);
|
||||
|
||||
new GUITextBlock(
|
||||
new Rectangle(0, 0, 0, 25),
|
||||
c.Salary.ToString(),
|
||||
null, null,
|
||||
Alignment.TopRight, GUI.Style, frame);
|
||||
}
|
||||
}
|
||||
|
||||
if (location.HireManager == null)
|
||||
{
|
||||
hireList.ClearChildren();
|
||||
hireList.Enabled = false;
|
||||
|
||||
new GUITextBlock(new Rectangle(0, 0, 0, 0), "No-one available for hire", Color.Transparent, Color.LightGray, Alignment.Center, Alignment.Center, GUI.Style, hireList);
|
||||
return;
|
||||
}
|
||||
|
||||
hireList.Enabled = true;
|
||||
hireList.ClearChildren();
|
||||
|
||||
foreach (CharacterInfo c in location.HireManager.availableCharacters)
|
||||
{
|
||||
var frame = c.CreateCharacterFrame(hireList, c.Name + " (" + c.Job.Name + ")", c);
|
||||
|
||||
new GUITextBlock(
|
||||
new Rectangle(0, 0, 0, 25),
|
||||
c.Salary.ToString(),
|
||||
null, null,
|
||||
Alignment.TopRight, GUI.Style, frame);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -273,6 +265,8 @@ namespace Barotrauma
|
||||
frame.HoverColor = Color.Gold * 0.2f;
|
||||
frame.SelectedColor = Color.Gold * 0.5f;
|
||||
|
||||
frame.ToolTip = ep.Description;
|
||||
|
||||
SpriteFont font = listBox.Rect.Width < 280 ? GUI.SmallFont : GUI.Font;
|
||||
|
||||
GUITextBlock textBlock = new GUITextBlock(
|
||||
@@ -283,6 +277,7 @@ namespace Barotrauma
|
||||
null, frame);
|
||||
textBlock.Font = font;
|
||||
textBlock.Padding = new Vector4(5.0f, 0.0f, 5.0f, 0.0f);
|
||||
textBlock.ToolTip = ep.Description;
|
||||
|
||||
if (ep.sprite != null)
|
||||
{
|
||||
@@ -297,6 +292,7 @@ namespace Barotrauma
|
||||
null, null, Alignment.TopLeft,
|
||||
Alignment.TopLeft, GUI.Style, frame);
|
||||
textBlock.Font = font;
|
||||
textBlock.ToolTip = ep.Description;
|
||||
|
||||
}
|
||||
|
||||
@@ -334,15 +330,14 @@ namespace Barotrauma
|
||||
{
|
||||
GUIComponent child = selectedItemList.children[i];
|
||||
|
||||
MapEntityPrefab ep = child.UserData as MapEntityPrefab;
|
||||
if (ep == null) continue;
|
||||
ItemPrefab ip = child.UserData as ItemPrefab;
|
||||
if (ip == null) continue;
|
||||
|
||||
gameMode.CargoManager.AddItem(ep);
|
||||
gameMode.CargoManager.AddItem(ip);
|
||||
|
||||
selectedItemList.RemoveChild(child);
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -365,7 +360,6 @@ namespace Barotrauma
|
||||
|
||||
public override void Draw(double deltaTime, GraphicsDevice graphics, SpriteBatch spriteBatch)
|
||||
{
|
||||
|
||||
if (characterList.CountChildren != CrewManager.characterInfos.Count)
|
||||
{
|
||||
UpdateCharacterLists();
|
||||
@@ -431,12 +425,7 @@ namespace Barotrauma
|
||||
|
||||
private bool SelectItemCategory(GUIButton button, object selection)
|
||||
{
|
||||
|
||||
if (!(selection is MapEntityCategory)) return false;
|
||||
//var existingList = bottomPanel[(int)PanelTab.Store].children.Find(c => c is GUIListBox && c.UserData is MapEntityCategory);
|
||||
//if (existingList != null) bottomPanel[(int)PanelTab.Store].RemoveChild(existingList);
|
||||
|
||||
//bottomPanel[(int)PanelTab.Store].AddChild(storeItemLists[(int)selection]);
|
||||
|
||||
storeItemList.ClearChildren();
|
||||
|
||||
@@ -485,27 +474,32 @@ namespace Barotrauma
|
||||
CharacterInfo characterInfo = selection as CharacterInfo;
|
||||
if (characterInfo == null) return false;
|
||||
|
||||
characterList.Deselect();
|
||||
hireList.Deselect();
|
||||
|
||||
if (Character.Controlled != null && characterInfo == Character.Controlled.Info) return false;
|
||||
|
||||
if (previewFrame == null || previewFrame.UserData != characterInfo)
|
||||
{
|
||||
previewFrame = new GUIFrame(new Rectangle(bottomPanel[(int)PanelTab.Crew].Rect.Width/2, 60, Math.Min(300,bottomPanel[(int)PanelTab.Crew].Rect.Width/2 - 40), 300),
|
||||
int width = Math.Min(300, bottomPanel[(int)PanelTab.Crew].Rect.Width - hireList.Rect.Width - characterList.Rect.Width - 50);
|
||||
|
||||
previewFrame = new GUIFrame(new Rectangle(0, 60, width, 300),
|
||||
new Color(0.0f, 0.0f, 0.0f, 0.8f),
|
||||
Alignment.Top, GUI.Style, bottomPanel[selectedRightPanel]);
|
||||
Alignment.TopCenter, GUI.Style, bottomPanel[selectedRightPanel]);
|
||||
previewFrame.Padding = new Vector4(20.0f, 20.0f, 20.0f, 20.0f);
|
||||
previewFrame.UserData = characterInfo;
|
||||
|
||||
characterInfo.CreateInfoFrame(previewFrame);
|
||||
}
|
||||
|
||||
if (selectedRightPanel == (int)PanelTab.CurrentLocation)
|
||||
if (component.Parent == hireList)
|
||||
{
|
||||
GUIButton hireButton = new GUIButton(new Rectangle(0,0, 100, 20), "Hire", Alignment.BottomCenter, GUI.Style, previewFrame);
|
||||
hireButton.UserData = characterInfo;
|
||||
hireButton.OnClicked = HireCharacter;
|
||||
}
|
||||
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool HireCharacter(GUIButton button, object selection)
|
||||
@@ -516,6 +510,8 @@ namespace Barotrauma
|
||||
if (gameMode.TryHireCharacter(GameMain.GameSession.Map.CurrentLocation.HireManager, characterInfo))
|
||||
{
|
||||
UpdateLocationTab(GameMain.GameSession.Map.CurrentLocation);
|
||||
|
||||
SelectCharacter(null,null);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -417,16 +417,7 @@ namespace Barotrauma
|
||||
|
||||
string saveTime = ToolBox.GetAttributeString(doc.Root, "savetime", "unknown");
|
||||
|
||||
XElement modeElement = null;
|
||||
foreach (XElement element in doc.Root.Elements())
|
||||
{
|
||||
if (element.Name.ToString().ToLowerInvariant() != "gamemode") continue;
|
||||
|
||||
modeElement = element;
|
||||
break;
|
||||
}
|
||||
|
||||
string mapseed = ToolBox.GetAttributeString(modeElement, "mapseed", "unknown");
|
||||
string mapseed = ToolBox.GetAttributeString(doc.Root, "mapseed", "unknown");
|
||||
|
||||
GUIFrame saveFileFrame = new GUIFrame(new Rectangle((int)(saveList.Rect.Width + 20), 0, 200, 230), Color.Black*0.4f, GUI.Style, menuTabs[(int)Tab.LoadGame]);
|
||||
saveFileFrame.UserData = "savefileframe";
|
||||
|
||||
@@ -28,6 +28,11 @@ namespace Barotrauma
|
||||
selected = this;
|
||||
}
|
||||
|
||||
public virtual Camera Cam
|
||||
{
|
||||
get { return null; }
|
||||
}
|
||||
|
||||
public virtual void Update(double deltaTime)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -14,6 +14,8 @@ namespace Barotrauma.Sounds
|
||||
private static readonly List<int> alSources = new List<int>();
|
||||
private static readonly int[] alBuffers = new int[DefaultSourceCount];
|
||||
private static int lowpassFilterId;
|
||||
|
||||
private static readonly Sound[] soundsPlaying = new Sound[DefaultSourceCount];
|
||||
|
||||
private static AudioContext AC;
|
||||
|
||||
@@ -47,112 +49,33 @@ namespace Barotrauma.Sounds
|
||||
|
||||
LowPassHFGain = 1.0f;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
//public SoundManager(int bufferCount = DefaultSourceCount)
|
||||
//{
|
||||
// Stopwatch sw = new Stopwatch();
|
||||
// sw.Start();
|
||||
|
||||
// alSourceId = AL.GenSource();
|
||||
// //AL.Source(alSourceId, ALSourcei.Buffer, alBufferId);
|
||||
|
||||
// Volume = 1;
|
||||
|
||||
// if (ALHelper.Efx.IsInitialized)
|
||||
// {
|
||||
// alFilterId = ALHelper.Efx.GenFilter();
|
||||
// ALHelper.Efx.Filter(alFilterId, EfxFilteri.FilterType, (int)EfxFilterType.Lowpass);
|
||||
// ALHelper.Efx.Filter(alFilterId, EfxFilterf.LowpassGain, 1);
|
||||
// LowPassHFGain = 1;
|
||||
// }
|
||||
|
||||
// sw.Stop();
|
||||
// System.Diagnostics.Debug.WriteLine("oggsource: "+sw.ElapsedMilliseconds);
|
||||
|
||||
//}
|
||||
|
||||
// public static int Play(Sound sound, float volume = 1.0f)
|
||||
// {
|
||||
// return Play(sound, volume, new Vector2(0.0f, 0.0f));
|
||||
//}
|
||||
|
||||
public static int Play(Sound sound, float volume = 1.0f)
|
||||
{
|
||||
return Play(sound, Vector2.Zero, volume, 0.0f);
|
||||
//for (int i = 2; i < DefaultSourceCount; i++)
|
||||
//{
|
||||
// AL.SourceStop(alSources[i]);
|
||||
// AL.Source(alSources[i], ALSourceb.Looping, false);
|
||||
// System.Diagnostics.Debug.WriteLine(i + ": " + AL.GetSourceState(alSources[i]));
|
||||
// System.Diagnostics.Debug.WriteLine(AL.GetSourceType(alSources[i]));
|
||||
//}
|
||||
|
||||
//for (int i = 1; i < DefaultSourceCount; i++)
|
||||
//{
|
||||
// //find a source that's free to use (not playing or paused)
|
||||
// if (AL.GetSourceState(alSources[i]) == ALSourceState.Playing
|
||||
// || AL.GetSourceState(alSources[i]) == ALSourceState.Paused) continue;
|
||||
|
||||
// //if (position!=Vector2.Zero)
|
||||
// // position /= 1000.0f;
|
||||
|
||||
// alBuffers[i]=sound.AlBufferId;
|
||||
// AL.Source(alSources[i], ALSourceb.Looping, false);
|
||||
// AL.Source(alSources[i], ALSource3f.Position, 0.0f, 0.0f, 0.0f);
|
||||
// AL.Source(alSources[i], ALSourcei.Buffer, sound.AlBufferId);
|
||||
// AL.Source(alSources[i], ALSourcef.Gain, volume);
|
||||
// //AL.Source(alSources[i], ALSource3f.Position, position.X, position.Y, 0.0f);
|
||||
// AL.SourcePlay(alSources[i]);
|
||||
|
||||
// //sound.sourceIndex = i;
|
||||
|
||||
// return i;
|
||||
//}
|
||||
|
||||
//return -1;
|
||||
}
|
||||
|
||||
public static int Play(Sound sound, Vector2 position, float volume = 1.0f, float lowPassGain = 0.0f, bool loop=false)
|
||||
{
|
||||
//for (int i = 2; i < DefaultSourceCount; i++)
|
||||
//{
|
||||
// AL.SourceStop(alSources[i]);
|
||||
// AL.Source(alSources[i], ALSourceb.Looping, false);
|
||||
// System.Diagnostics.Debug.WriteLine(i + ": " + AL.GetSourceState(alSources[i]));
|
||||
// System.Diagnostics.Debug.WriteLine(AL.GetSourceType(alSources[i]));
|
||||
//}
|
||||
|
||||
|
||||
|
||||
for (int i = 1; i < DefaultSourceCount; i++)
|
||||
{
|
||||
//find a source that's free to use (not playing or paused)
|
||||
if (OpenTK.Audio.OpenAL.AL.GetSourceState(alSources[i]) == OpenTK.Audio.OpenAL.ALSourceState.Playing
|
||||
|| OpenTK.Audio.OpenAL.AL.GetSourceState(alSources[i]) == OpenTK.Audio.OpenAL.ALSourceState.Paused) continue;
|
||||
|
||||
//if (position!=Vector2.Zero)
|
||||
// position /= 1000.0f;
|
||||
soundsPlaying[i] = sound;
|
||||
|
||||
alBuffers[i] = sound.AlBufferId;
|
||||
OpenTK.Audio.OpenAL.AL.Source(alSources[i], OpenTK.Audio.OpenAL.ALSourceb.Looping, loop);
|
||||
|
||||
OpenTK.Audio.OpenAL.AL.Source(alSources[i], OpenTK.Audio.OpenAL.ALSourcei.Buffer, sound.AlBufferId);
|
||||
|
||||
|
||||
|
||||
UpdateSoundPosition(i, position, volume);
|
||||
|
||||
//AL.Source(alSources[i], ALSource3f.Position, position.X, position.Y, 0.0f);
|
||||
OpenTK.Audio.OpenAL.AL.SourcePlay(alSources[i]);
|
||||
|
||||
|
||||
|
||||
|
||||
//sound.sourceIndex = i;
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
@@ -174,44 +97,17 @@ namespace Barotrauma.Sounds
|
||||
if (sourceIndex<1)
|
||||
{
|
||||
sourceIndex = Play(sound, position, volume, 0.0f, true);
|
||||
//if (sourceIndex>0)
|
||||
//{
|
||||
// AL.Source(alSources[sourceIndex], ALSourceb.Looping, true);
|
||||
// AL.Source(alSources[sourceIndex], ALSourcef.Gain, volume);
|
||||
//}
|
||||
}
|
||||
else
|
||||
{
|
||||
UpdateSoundPosition(sourceIndex, position, volume);
|
||||
|
||||
//position /= 1000.0f;
|
||||
|
||||
//OpenTK.Audio.OpenAL.AL.Source(alSources[sourceIndex], OpenTK.Audio.OpenAL.ALSource3f.Position, position.X, position.Y, 0.0f);
|
||||
AL.Source(alSources[sourceIndex], ALSourceb.Looping, true);
|
||||
//AL.Source(alSources[sourceIndex], ALSourcef.Gain, volume);
|
||||
|
||||
}
|
||||
|
||||
ALHelper.Check();
|
||||
return sourceIndex;
|
||||
}
|
||||
|
||||
//public static int Loop(int sourceIndex, float volume = 1.0f)
|
||||
//{
|
||||
|
||||
// if (sourceIndex > 0 && alSources[sourceIndex]>0)
|
||||
// {
|
||||
// ALSourceState state = AL.GetSourceState(alSources[sourceIndex]);
|
||||
// ALHelper.Check();
|
||||
// if (state == ALSourceState.Playing) return sourceIndex;
|
||||
// }
|
||||
|
||||
// int newSourceIndex = Play(sound, volume);
|
||||
// AL.Source(alSources[sourceIndex], ALSourceb.Looping, true);
|
||||
|
||||
// return sourceIndex;
|
||||
//}
|
||||
|
||||
public static void Pause(int sourceIndex)
|
||||
{
|
||||
if (AL.GetSourceState(alSources[sourceIndex]) != ALSourceState.Playing)
|
||||
@@ -239,9 +135,21 @@ namespace Barotrauma.Sounds
|
||||
{
|
||||
AL.SourceStop(alSources[sourceIndex]);
|
||||
AL.Source(alSources[sourceIndex], ALSourceb.Looping, false);
|
||||
|
||||
soundsPlaying[sourceIndex] = null;
|
||||
}
|
||||
}
|
||||
|
||||
public static Sound GetPlayingSound(int sourceIndex)
|
||||
{
|
||||
if (sourceIndex < 1 || sourceIndex>alSources.Count-1) return null;
|
||||
|
||||
if (AL.GetSourceState(alSources[sourceIndex]) != ALSourceState.Playing) return null;
|
||||
|
||||
return soundsPlaying[sourceIndex];
|
||||
}
|
||||
|
||||
|
||||
public static bool IsPlaying(int sourceIndex)
|
||||
{
|
||||
if (sourceIndex < 1 || sourceIndex>alSources.Count-1) return false;
|
||||
@@ -249,14 +157,23 @@ namespace Barotrauma.Sounds
|
||||
return (state == ALSourceState.Playing);
|
||||
}
|
||||
|
||||
public static bool IsLooping(int sourceIndex)
|
||||
{
|
||||
if (sourceIndex < 1 || sourceIndex > alSources.Count - 1) return false;
|
||||
|
||||
bool isLooping;
|
||||
|
||||
OpenTK.Audio.OpenAL.AL.GetSource(alSources[sourceIndex], OpenTK.Audio.OpenAL.ALSourceb.Looping, out isLooping);
|
||||
|
||||
return isLooping;
|
||||
}
|
||||
|
||||
public static void Volume(int sourceIndex, float volume)
|
||||
{
|
||||
AL.Source(alSources[sourceIndex], ALSourcef.Gain, volume * MasterVolume);
|
||||
ALHelper.Check();
|
||||
}
|
||||
|
||||
//int alFilterId;
|
||||
|
||||
static float lowPassHfGain;
|
||||
public static float LowPassHFGain
|
||||
{
|
||||
@@ -281,16 +198,6 @@ namespace Barotrauma.Sounds
|
||||
}
|
||||
}
|
||||
|
||||
//float volume;
|
||||
//public float Volume
|
||||
//{
|
||||
// get { return volume; }
|
||||
// set
|
||||
// {
|
||||
// AL.Source(alSourceId, ALSourcef.Gain, volume = value);
|
||||
// ALHelper.Check();
|
||||
// }
|
||||
//}
|
||||
|
||||
public static void UpdateSoundPosition(int sourceIndex, Vector2 position, float baseVolume = 1.0f)
|
||||
{
|
||||
@@ -301,9 +208,7 @@ namespace Barotrauma.Sounds
|
||||
position = Vector2.Zero;
|
||||
}
|
||||
|
||||
//Resume(sourceIndex);
|
||||
|
||||
position/= 1000.0f;
|
||||
position /= 1000.0f;
|
||||
|
||||
OpenTK.Audio.OpenAL.AL.Source(alSources[sourceIndex], OpenTK.Audio.OpenAL.ALSourcef.Gain, baseVolume * MasterVolume);
|
||||
OpenTK.Audio.OpenAL.AL.Source(alSources[sourceIndex], OpenTK.Audio.OpenAL.ALSource3f.Position, position.X, position.Y, 0.0f);
|
||||
@@ -313,8 +218,6 @@ namespace Barotrauma.Sounds
|
||||
ALHelper.Efx.Filter(lowpassFilterId, OpenTK.Audio.OpenAL.EfxFilterf.LowpassGainHF, lowPassGain);
|
||||
ALHelper.Efx.BindFilterToSource(alSources[sourceIndex], lowpassFilterId);
|
||||
ALHelper.Check();
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static OggStream StartStream(string file, float volume = 1.0f)
|
||||
|
||||
+55
-30
@@ -222,56 +222,81 @@ namespace Barotrauma
|
||||
{
|
||||
DrawTiled(spriteBatch, pos, targetSize, Vector2.Zero, color);
|
||||
}
|
||||
|
||||
public void DrawTiled(SpriteBatch spriteBatch, Vector2 pos, Vector2 targetSize, Vector2 startOffset, Color color, Point offset)
|
||||
{
|
||||
//how many times the texture needs to be drawn on the x-axis
|
||||
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);
|
||||
|
||||
Rectangle texPerspective = sourceRect;
|
||||
|
||||
texPerspective.Location += offset;
|
||||
while (texPerspective.Location.X >= sourceRect.X + sourceRect.Width)
|
||||
texPerspective.X = sourceRect.X + (texPerspective.Location.X - (sourceRect.X + sourceRect.Width));
|
||||
while (texPerspective.Location.Y >= sourceRect.Y + sourceRect.Height)
|
||||
texPerspective.Y = sourceRect.Y + (texPerspective.Location.Y - (sourceRect.Y + sourceRect.Height));
|
||||
|
||||
Rectangle TexPerspective = sourceRect;
|
||||
|
||||
TexPerspective.Location += offset;
|
||||
while (TexPerspective.Location.X >= sourceRect.X + sourceRect.Width)
|
||||
TexPerspective.X = sourceRect.X + (TexPerspective.Location.X - (sourceRect.X + sourceRect.Width));
|
||||
while (TexPerspective.Location.Y >= sourceRect.Y + sourceRect.Height)
|
||||
TexPerspective.Y = sourceRect.Y + (TexPerspective.Location.Y - (sourceRect.Y + sourceRect.Height));
|
||||
TexPerspective.Width = (int)Math.Min(targetSize.X, sourceRect.Width);
|
||||
TexPerspective.Height = (int)Math.Min(targetSize.Y, sourceRect.Height);
|
||||
texPerspective.Width = (int)Math.Min(targetSize.X, sourceRect.Width);
|
||||
texPerspective.Height = (int)Math.Min(targetSize.Y, sourceRect.Height);
|
||||
for (int y = 0; y < yTiles; y++)
|
||||
{
|
||||
TexPerspective.Width = (int)Math.Min(targetSize.X, sourceRect.Width);
|
||||
TexPerspective.Height = (int)Math.Min(targetSize.Y, sourceRect.Height);
|
||||
float top = pos.Y + TexPerspective.Height * y;
|
||||
texPerspective.Width = (int)Math.Min(targetSize.X, sourceRect.Width);
|
||||
texPerspective.Height = (int)Math.Min(targetSize.Y, sourceRect.Height);
|
||||
float top = pos.Y + texPerspective.Height * y;
|
||||
for (int x = 0; x < xTiles; x++)
|
||||
{
|
||||
float left = pos.X + TexPerspective.Width * x;
|
||||
TexPerspective.Width = Math.Min((int)(targetSize.X - TexPerspective.Width * x), TexPerspective.Width);
|
||||
TexPerspective.Height = Math.Min((int)(targetSize.Y - TexPerspective.Height * y), TexPerspective.Height);
|
||||
var movementX = TexPerspective.Width;
|
||||
var movementY = TexPerspective.Height;
|
||||
if (TexPerspective.X+TexPerspective.Width > sourceRect.X + sourceRect.Width)
|
||||
float left = pos.X + texPerspective.Width * x;
|
||||
texPerspective.Width = Math.Min((int)(targetSize.X - texPerspective.Width * x), texPerspective.Width);
|
||||
texPerspective.Height = Math.Min((int)(targetSize.Y - texPerspective.Height * y), texPerspective.Height);
|
||||
|
||||
var movementX = texPerspective.Width;
|
||||
var movementY = texPerspective.Height;
|
||||
if (texPerspective.Right > sourceRect.Right)
|
||||
{
|
||||
float diff = (TexPerspective.X + TexPerspective.Width) - (sourceRect.X + sourceRect.Width);
|
||||
TexPerspective.Width -= (int)diff;
|
||||
spriteBatch.Draw(texture, new Vector2(left+ TexPerspective.Width, top), new Rectangle(sourceRect.X, TexPerspective.Y,(int)diff, TexPerspective.Height), color, rotation, Vector2.Zero, 1.0f, effects, depth);
|
||||
if (effects.HasFlag(SpriteEffects.FlipHorizontally))
|
||||
{
|
||||
int diff = (texPerspective.X + texPerspective.Width) - (sourceRect.Right);
|
||||
|
||||
spriteBatch.Draw(texture,
|
||||
new Vector2(left, top),
|
||||
new Rectangle(sourceRect.X, texPerspective.Y, diff, texPerspective.Height),
|
||||
color, rotation, Vector2.Zero, 1.0f, effects, depth);
|
||||
|
||||
texPerspective.Width -= diff;
|
||||
left += diff;
|
||||
}
|
||||
else
|
||||
{
|
||||
float diff = (texPerspective.X + texPerspective.Width) - (sourceRect.X + sourceRect.Width);
|
||||
texPerspective.Width -= (int)diff;
|
||||
spriteBatch.Draw(texture,
|
||||
new Vector2(left + texPerspective.Width, top),
|
||||
new Rectangle(sourceRect.X, texPerspective.Y, (int)diff, texPerspective.Height),
|
||||
color, rotation, Vector2.Zero, 1.0f, effects, depth);
|
||||
}
|
||||
}
|
||||
else if (TexPerspective.Y + TexPerspective.Height > sourceRect.Y + sourceRect.Height)
|
||||
else if (texPerspective.Bottom > sourceRect.Bottom)
|
||||
{
|
||||
float diff = (TexPerspective.Y + TexPerspective.Height) - (sourceRect.Y + sourceRect.Height);
|
||||
TexPerspective.Height -= (int)diff;
|
||||
spriteBatch.Draw(texture, new Vector2(left, top+ TexPerspective.Height), new Rectangle(TexPerspective.X, sourceRect.Y, TexPerspective.Width, (int)diff), color, rotation, Vector2.Zero, 1.0f, effects, depth);
|
||||
int diff = (texPerspective.Bottom) - (sourceRect.Bottom);
|
||||
texPerspective.Height -= diff;
|
||||
spriteBatch.Draw(texture,
|
||||
new Vector2(left, top + texPerspective.Height),
|
||||
new Rectangle(texPerspective.X, sourceRect.Y, texPerspective.Width, diff),
|
||||
color, rotation, Vector2.Zero, 1.0f, effects, depth);
|
||||
}
|
||||
|
||||
spriteBatch.Draw(texture, new Vector2(left,top),TexPerspective, color, rotation, Vector2.Zero, 1.0f, effects, depth);
|
||||
if (TexPerspective.X+ movementX >= sourceRect.X + sourceRect.Width)
|
||||
TexPerspective.X = sourceRect.X;
|
||||
if (TexPerspective.Y + movementY >= sourceRect.Y + sourceRect.Height)
|
||||
TexPerspective.Y = sourceRect.Y;
|
||||
spriteBatch.Draw(texture, new Vector2(left, top), texPerspective, color, rotation, Vector2.Zero, 1.0f, effects, depth);
|
||||
|
||||
if (texPerspective.X + movementX >= sourceRect.Right)
|
||||
texPerspective.X = sourceRect.X;
|
||||
if (texPerspective.Y + movementY >= sourceRect.Y + sourceRect.Height)
|
||||
texPerspective.Y = sourceRect.Y;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void DrawTiled(SpriteBatch spriteBatch, Vector2 pos, Vector2 targetSize, Vector2 startOffset, Color color)
|
||||
{
|
||||
//pos.X = (int)pos.X;
|
||||
|
||||
@@ -23,21 +23,14 @@ namespace Barotrauma
|
||||
|
||||
string tempPath = Path.Combine(SaveFolder, "temp");
|
||||
|
||||
if (Directory.Exists(tempPath))
|
||||
{
|
||||
Directory.Delete(tempPath, true);
|
||||
}
|
||||
Directory.CreateDirectory(tempPath);
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
|
||||
|
||||
if (Submarine.MainSub != null)
|
||||
{
|
||||
Submarine.MainSub.FilePath = Path.Combine(tempPath, Submarine.MainSub.Name + ".sub");
|
||||
Submarine.MainSub.SaveAs(Submarine.MainSub.FilePath);
|
||||
Submarine.MainSub.SaveAs(Submarine.MainSub.FilePath);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
|
||||
Reference in New Issue
Block a user