Lights, colored items (only used for wires atm)
6
Launcher/Launcher.csproj.user
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<ProjectView>ShowAllFiles</ProjectView>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
BIN
Subsurface/Content/Items/Electricity/lamp.png
Normal file
|
After Width: | Height: | Size: 2.8 KiB |
24
Subsurface/Content/Items/Electricity/lights.xml
Normal file
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
|
||||
<Items>
|
||||
|
||||
<Item
|
||||
name="Lamp"
|
||||
Tags="smallitem"
|
||||
pickdistance="150">
|
||||
|
||||
<Sprite texture ="lamp.png" sourcerect="0,0,16,32" depth="0.8"/>
|
||||
|
||||
<LightComponent color="1.0,1.0,1.0,1.0" range ="1000.0" powerconsumption="50"/>
|
||||
|
||||
<ConnectionPanel canbeselected = "true" msg="Rewire [Screwdriver]">
|
||||
<requireditem name="Screwdriver,Wire" type="Equipped"/>
|
||||
<input name="power"/>
|
||||
<input name="toggle"/>
|
||||
<input name="set_state"/>
|
||||
</ConnectionPanel>
|
||||
|
||||
</Item>
|
||||
|
||||
</Items>
|
||||
|
||||
@@ -21,7 +21,10 @@
|
||||
<ConnectionPanel canbeselected = "true" msg="Rewire [Screwdriver]">
|
||||
<requireditem name="Screwdriver" type="Equipped"/>
|
||||
<output name="power"/>
|
||||
<output name="signal"/>
|
||||
<output name="signal_0"/>
|
||||
<output name="signal_1"/>
|
||||
<output name="signal_2"/>
|
||||
<output name="signal_3"/>
|
||||
</ConnectionPanel>
|
||||
|
||||
</Item>
|
||||
|
||||
|
Before Width: | Height: | Size: 934 B After Width: | Height: | Size: 1.5 KiB |
|
Before Width: | Height: | Size: 45 KiB After Width: | Height: | Size: 29 KiB |
|
Before Width: | Height: | Size: 241 B After Width: | Height: | Size: 9.1 KiB |
|
Before Width: | Height: | Size: 2.3 KiB After Width: | Height: | Size: 2.2 KiB |
|
Before Width: | Height: | Size: 309 B After Width: | Height: | Size: 301 B |
|
Before Width: | Height: | Size: 248 B After Width: | Height: | Size: 249 B |
BIN
Subsurface/Content/Lights/AlphaOne.dds
Normal file
BIN
Subsurface/Content/Lights/alphaOne.png
Normal file
|
After Width: | Height: | Size: 158 B |
BIN
Subsurface/Content/Lights/light.png
Normal file
|
After Width: | Height: | Size: 136 KiB |
BIN
Subsurface/Content/SmallFont.xnb
Normal file
@@ -216,7 +216,12 @@ namespace Subsurface
|
||||
case "fowenabled":
|
||||
case "fow":
|
||||
case "drawfow":
|
||||
Lights.LightManager.FowEnabled = !Lights.LightManager.FowEnabled;
|
||||
Game1.LightManager.FowEnabled = !Game1.LightManager.FowEnabled;
|
||||
break;
|
||||
case "lighting":
|
||||
case "lightingenabled":
|
||||
case "light":
|
||||
Game1.LightManager.LightingEnabled = !Game1.LightManager.LightingEnabled;
|
||||
break;
|
||||
case "lobbyscreen":
|
||||
case "lobby":
|
||||
|
||||
@@ -24,6 +24,12 @@ namespace Subsurface
|
||||
public delegate bool OnTextChangedHandler(GUITextBox textBox, string text);
|
||||
public OnTextChangedHandler OnTextChanged;
|
||||
|
||||
public GUITextBlock.TextGetterHandler TextGetter
|
||||
{
|
||||
get { return textBlock.TextGetter; }
|
||||
set { textBlock.TextGetter = value; }
|
||||
}
|
||||
|
||||
public bool Wrap
|
||||
{
|
||||
get { return textBlock.Wrap; }
|
||||
@@ -171,15 +177,14 @@ namespace Subsurface
|
||||
public override void Draw(SpriteBatch spriteBatch)
|
||||
{
|
||||
DrawChildren(spriteBatch);
|
||||
|
||||
|
||||
|
||||
Vector2 caretPos = textBlock.CaretPos;
|
||||
|
||||
if (caretVisible && Selected)
|
||||
{
|
||||
GUI.DrawLine(spriteBatch,
|
||||
new Vector2((int)caretPos.X + 2, caretPos.Y + 3),
|
||||
new Vector2((int)caretPos.X + 2, caretPos.Y + Font.MeasureString(Text).Y - 3),
|
||||
new Vector2((int)caretPos.X + 2, caretPos.Y + Font.MeasureString("I").Y - 3),
|
||||
textBlock.TextColor * (textBlock.TextColor.A / 255.0f));
|
||||
}
|
||||
|
||||
|
||||
@@ -33,6 +33,8 @@ namespace Subsurface
|
||||
public static EditMapScreen EditMapScreen;
|
||||
public static EditCharacterScreen EditCharacterScreen;
|
||||
|
||||
public static Lights.LightManager LightManager;
|
||||
|
||||
public static ContentPackage SelectedPackage
|
||||
{
|
||||
get { return Config.SelectedContentPackage; }
|
||||
@@ -160,6 +162,8 @@ namespace Subsurface
|
||||
GUI.Font = Content.Load<SpriteFont>("SpriteFont1");
|
||||
GUI.SmallFont = Content.Load<SpriteFont>("SmallFont");
|
||||
|
||||
LightManager = new Lights.LightManager(GraphicsDevice);
|
||||
|
||||
Hull.renderer = new WaterRenderer(GraphicsDevice);
|
||||
loadState = 1.0f;
|
||||
yield return Status.Running;
|
||||
|
||||
@@ -131,7 +131,7 @@ namespace Subsurface
|
||||
|
||||
public void StartShift(TimeSpan duration, Level level, bool reloadSub = true)
|
||||
{
|
||||
Lights.LightManager.FowEnabled = (Game1.Server==null);
|
||||
Game1.LightManager.FowEnabled = (Game1.Server==null);
|
||||
|
||||
this.level = level;
|
||||
|
||||
|
||||
@@ -141,7 +141,7 @@ namespace Subsurface.Items.Components
|
||||
|
||||
}
|
||||
|
||||
public override void Draw(SpriteBatch spriteBatch)
|
||||
public override void Draw(SpriteBatch spriteBatch, bool editing)
|
||||
{
|
||||
base.Draw(spriteBatch);
|
||||
|
||||
|
||||
@@ -250,8 +250,8 @@ namespace Subsurface.Items.Components
|
||||
linkedGap.Open = 1.0f;
|
||||
if (convexHull2 != null) convexHull2.Enabled = false;
|
||||
}
|
||||
|
||||
public override void Draw(SpriteBatch spriteBatch)
|
||||
|
||||
public override void Draw(SpriteBatch spriteBatch, bool editing)
|
||||
{
|
||||
Color color = (item.IsSelected) ? Color.Green : Color.White;
|
||||
color = color * (item.Condition / 100.0f);
|
||||
|
||||
@@ -81,6 +81,8 @@ namespace Subsurface.Items.Components
|
||||
handlePos[i - 1] = ConvertUnits.ToSimUnits(handlePos[i - 1]);
|
||||
}
|
||||
|
||||
canBePicked = true;
|
||||
|
||||
//holdAngle = ToolBox.GetAttributeFloat(element, "holdangle", 0.0f);
|
||||
//holdAngle = MathHelper.ToRadians(holdAngle);
|
||||
}
|
||||
@@ -160,6 +162,8 @@ namespace Subsurface.Items.Components
|
||||
// return false;
|
||||
//}
|
||||
|
||||
if (attached) return false;
|
||||
|
||||
item.body = body;
|
||||
item.body.Enabled = true;
|
||||
|
||||
|
||||
@@ -173,8 +173,8 @@ namespace Subsurface.Items.Components
|
||||
|
||||
//isActive = true;
|
||||
}
|
||||
|
||||
public override void Draw(SpriteBatch spriteBatch)
|
||||
|
||||
public override void Draw(SpriteBatch spriteBatch, bool editing)
|
||||
{
|
||||
if (!isActive) return;
|
||||
|
||||
|
||||
@@ -293,7 +293,7 @@ namespace Subsurface
|
||||
/// <summary>a character has dropped the item</summary>
|
||||
public virtual void Drop(Character dropper) { }
|
||||
|
||||
public virtual void Draw(SpriteBatch spriteBatch) { }
|
||||
public virtual void Draw(SpriteBatch spriteBatch, bool editing = false) { }
|
||||
|
||||
public virtual void DrawHUD(SpriteBatch spriteBatch, Character character) { }
|
||||
|
||||
|
||||
@@ -281,7 +281,7 @@ namespace Subsurface.Items.Components
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void Draw(SpriteBatch spriteBatch)
|
||||
public override void Draw(SpriteBatch spriteBatch, bool editing)
|
||||
{
|
||||
base.Draw(spriteBatch);
|
||||
|
||||
|
||||
@@ -173,7 +173,7 @@ namespace Subsurface.Items.Components
|
||||
voltage = 0.0f;
|
||||
}
|
||||
|
||||
public override void Draw(SpriteBatch spriteBatch)
|
||||
public override void Draw(SpriteBatch spriteBatch, bool editing)
|
||||
{
|
||||
base.Draw(spriteBatch);
|
||||
|
||||
|
||||
@@ -53,11 +53,6 @@ namespace Subsurface.Items.Components
|
||||
"power", fullPower / Math.Max(fullLoad, 1.0f));
|
||||
if (-pt.currPowerConsumption > pt.powerLoad * 2.0f) pt.item.Condition = 0.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
//p.Power = fullPower;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -61,7 +61,8 @@ namespace Subsurface.Items.Components
|
||||
|
||||
public override void ReceiveSignal(string signal, Connection connection, Item sender, float power)
|
||||
{
|
||||
if (connection.Name=="power_in") voltage = power;
|
||||
if (currPowerConsumption == 0.0f) voltage = 0.0f;
|
||||
if (connection.Name == "power_in" || connection.Name == "power") voltage = power;
|
||||
}
|
||||
|
||||
public override void Update(float deltaTime, Camera cam)
|
||||
|
||||
@@ -239,7 +239,7 @@ namespace Subsurface.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
public override void Draw(SpriteBatch spriteBatch)
|
||||
public override void Draw(SpriteBatch spriteBatch, bool editing)
|
||||
{
|
||||
base.Draw(spriteBatch);
|
||||
|
||||
|
||||
@@ -339,29 +339,31 @@ namespace Subsurface.Items.Components
|
||||
int textX = (int)start.X;
|
||||
float connLength = 10.0f;
|
||||
|
||||
Color color = (wireEquipped) ? Color.Gray : Color.White;
|
||||
float alpha = wireEquipped ? 0.5f : 1.0f;
|
||||
|
||||
//Color color = (wireEquipped) ? wireItem.Color * 0.5f : wireItem.Color;
|
||||
|
||||
if (Math.Abs(end.X-start.X)<connLength*6.0f)
|
||||
{
|
||||
wireVertical.DrawTiled(spriteBatch,
|
||||
new Vector2(end.X - wireVertical.size.X / 2, end.Y + connLength),
|
||||
new Vector2(wireVertical.size.X, (float)Math.Abs(end.Y - start.Y)), color);
|
||||
new Vector2(end.X - wireVertical.size.X / 2, end.Y + connLength),
|
||||
new Vector2(wireVertical.size.X, (float)Math.Abs(end.Y - start.Y)), wireItem.Color * alpha);
|
||||
textX = (int)end.X;
|
||||
connector.Draw(spriteBatch, end, color);
|
||||
connector.Draw(spriteBatch, end, Color.White*alpha);
|
||||
}
|
||||
else
|
||||
{
|
||||
Vector2 pos = new Vector2(start.X, end.Y + wireCorner.size.Y) - wireVertical.size / 2;
|
||||
Vector2 size = new Vector2(wireVertical.size.X, (float)Math.Abs((end.Y + wireCorner.size.Y) - start.Y));
|
||||
wireVertical.DrawTiled(spriteBatch, pos, size, color);
|
||||
wireVertical.DrawTiled(spriteBatch, pos, size, wireItem.Color * alpha);
|
||||
|
||||
Rectangle rect = new Rectangle((int)pos.X, (int)pos.Y, (int)size.X, (int)size.Y);
|
||||
if (!wireEquipped && rect.Contains(PlayerInput.MousePosition)) mouseOn = true;
|
||||
|
||||
float dir = (end.X > start.X) ? -1.0f : 1.0f;
|
||||
|
||||
wireCorner.Draw(spriteBatch,
|
||||
new Vector2(start.X, end.Y), color, 0.0f, 1.0f,
|
||||
wireCorner.Draw(spriteBatch,
|
||||
new Vector2(start.X, end.Y), wireItem.Color * alpha, 0.0f, 1.0f,
|
||||
(end.X > start.X) ? SpriteEffects.None : SpriteEffects.FlipHorizontally);
|
||||
|
||||
float wireStartX = start.X - wireCorner.size.X / 2 * dir;
|
||||
@@ -370,11 +372,11 @@ namespace Subsurface.Items.Components
|
||||
pos = new Vector2(Math.Min(wireStartX,wireEndX), end.Y - wireVertical.size.Y / 2);
|
||||
size = new Vector2(Math.Abs(wireStartX - wireEndX), wireHorizontal.size.Y);
|
||||
|
||||
wireHorizontal.DrawTiled(spriteBatch, pos, size, color);
|
||||
wireHorizontal.DrawTiled(spriteBatch, pos, size, wireItem.Color * alpha);
|
||||
rect = new Rectangle((int)pos.X, (int)pos.Y, (int)size.X, (int)size.Y);
|
||||
if (!wireEquipped && rect.Contains(PlayerInput.MousePosition)) mouseOn = true;
|
||||
|
||||
connector.Draw(spriteBatch, end, color, -MathHelper.PiOver2*dir);
|
||||
connector.Draw(spriteBatch, end, Color.White*alpha, -MathHelper.PiOver2 * dir);
|
||||
}
|
||||
|
||||
if (draggingConnected == null && !wireEquipped)
|
||||
|
||||
@@ -1,13 +1,33 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using FarseerPhysics;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Subsurface.Lights;
|
||||
using System;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Subsurface.Items.Components
|
||||
{
|
||||
class LightComponent : ItemComponent
|
||||
class LightComponent : Powered
|
||||
{
|
||||
private Color lightColor;
|
||||
|
||||
private Sprite sprite;
|
||||
//private Sprite sprite;
|
||||
|
||||
LightSource light;
|
||||
|
||||
float range;
|
||||
|
||||
float lightBrightness;
|
||||
|
||||
[HasDefaultValue(100.0f, true)]
|
||||
public float Range
|
||||
{
|
||||
get { return range; }
|
||||
set
|
||||
{
|
||||
range = MathHelper.Clamp(value, 0.0f, 2048.0f);
|
||||
}
|
||||
}
|
||||
|
||||
[InGameEditable, HasDefaultValue("1.0,1.0,1.0,1.0", true)]
|
||||
public string LightColor
|
||||
@@ -19,27 +39,74 @@ namespace Subsurface.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
public override void Move(Vector2 amount)
|
||||
{
|
||||
light.Position += amount;
|
||||
}
|
||||
|
||||
public LightComponent(Item item, XElement element)
|
||||
: base (item, element)
|
||||
{
|
||||
foreach (XElement subElement in element.Elements())
|
||||
{
|
||||
if (subElement.Name.ToString().ToLower() != "sprite") continue;
|
||||
sprite = new Sprite(subElement);
|
||||
break;
|
||||
}
|
||||
//foreach (XElement subElement in element.Elements())
|
||||
//{
|
||||
// if (subElement.Name.ToString().ToLower() != "sprite") continue;
|
||||
// sprite = new Sprite(subElement);
|
||||
// break;
|
||||
//}
|
||||
|
||||
light = new LightSource(item.Position, 100.0f, Color.White);
|
||||
|
||||
isActive = true;
|
||||
|
||||
//lightColor = new Color(ToolBox.GetAttributeVector4(element, "color", Vector4.One));
|
||||
}
|
||||
|
||||
public override void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch)
|
||||
|
||||
public override void Update(float deltaTime, Camera cam)
|
||||
{
|
||||
if (!isActive || sprite==null) return;
|
||||
sprite.Draw(spriteBatch, new Vector2(item.Position.X, -item.Position.Y), 0.0f, 1.0f, Microsoft.Xna.Framework.Graphics.SpriteEffects.None);
|
||||
base.Update(deltaTime, cam);
|
||||
|
||||
if (item.body != null)
|
||||
{
|
||||
light.Position = ConvertUnits.ToDisplayUnits(item.body.Position);
|
||||
}
|
||||
|
||||
if (powerConsumption == 0.0f)
|
||||
{
|
||||
voltage = 1.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
currPowerConsumption = powerConsumption;
|
||||
}
|
||||
|
||||
if (voltage < Rand.Range(0.0f, minVoltage))
|
||||
{
|
||||
lightBrightness = 0.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
lightBrightness = MathHelper.Lerp(lightBrightness, Math.Min(voltage, 1.0f), 0.1f);
|
||||
}
|
||||
|
||||
light.Color = lightColor * lightBrightness;
|
||||
|
||||
light.Range = range * (float)Math.Sqrt(lightBrightness);
|
||||
|
||||
voltage = 0.0f;
|
||||
}
|
||||
|
||||
public override void Draw(SpriteBatch spriteBatch, bool editing)
|
||||
{
|
||||
if (!isActive)
|
||||
{
|
||||
light.Color = Color.Transparent;
|
||||
}
|
||||
}
|
||||
|
||||
public override void ReceiveSignal(string signal, Connection connection, Item sender, float power=0.0f)
|
||||
{
|
||||
base.ReceiveSignal(signal, connection, sender, power);
|
||||
|
||||
switch (connection.Name)
|
||||
{
|
||||
case "toggle":
|
||||
|
||||
@@ -20,7 +20,9 @@ namespace Subsurface.Items.Components
|
||||
Connection[] connections;
|
||||
|
||||
private Vector2 newNodePos;
|
||||
|
||||
|
||||
private static int? selectedNodeIndex;
|
||||
|
||||
public Wire(Item item, XElement element)
|
||||
: base(item, element)
|
||||
{
|
||||
@@ -34,14 +36,14 @@ namespace Subsurface.Items.Components
|
||||
|
||||
connections = new Connection[2];
|
||||
}
|
||||
|
||||
|
||||
public override void Move(Vector2 amount)
|
||||
{
|
||||
amount = FarseerPhysics.ConvertUnits.ToDisplayUnits(amount);
|
||||
for (int i = 0; i<Nodes.Count; i++)
|
||||
{
|
||||
Nodes[i] += amount;
|
||||
}
|
||||
//for (int i = 0; i<Nodes.Count; i++)
|
||||
//{
|
||||
// Nodes[i] += amount;
|
||||
//}
|
||||
}
|
||||
|
||||
public Connection OtherConnection(Connection connection)
|
||||
@@ -151,7 +153,7 @@ namespace Subsurface.Items.Components
|
||||
position.Y += item.CurrentHull.Rect.Y - item.CurrentHull.Rect.Height;
|
||||
}
|
||||
|
||||
newNodePos = position;
|
||||
newNodePos = RoundNode(item.Position, item.CurrentHull);
|
||||
|
||||
//if (Vector2.Distance(position, nodes[nodes.Count - 1]) > nodeDistance*10)
|
||||
//{
|
||||
@@ -170,14 +172,13 @@ namespace Subsurface.Items.Components
|
||||
|
||||
public override bool Use(float deltaTime, Character character = null)
|
||||
{
|
||||
if (character == Character.Controlled && character.SelectedConstruction != null) return false;
|
||||
|
||||
if (newNodePos!= Vector2.Zero && Nodes.Count>0 && Vector2.Distance(newNodePos, Nodes[Nodes.Count - 1]) > nodeDistance)
|
||||
{
|
||||
Nodes.Add(newNodePos);
|
||||
newNodePos = Vector2.Zero;
|
||||
}
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -213,6 +214,23 @@ namespace Subsurface.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
private Vector2 RoundNode(Vector2 position, Hull hull)
|
||||
{
|
||||
position.X = MathUtils.Round(position.X, nodeDistance);
|
||||
if (hull == null)
|
||||
{
|
||||
position.Y = MathUtils.Round(position.Y, nodeDistance);
|
||||
}
|
||||
else
|
||||
{
|
||||
position.Y -= hull.Rect.Y - hull.Rect.Height;
|
||||
position.Y = Math.Max(MathUtils.Round(position.Y, nodeDistance), heightFromFloor);
|
||||
position.Y += hull.Rect.Y -hull.Rect.Height;
|
||||
}
|
||||
|
||||
return position;
|
||||
}
|
||||
|
||||
private void CleanNodes()
|
||||
{
|
||||
for (int i = Nodes.Count - 2; i > 0; i--)
|
||||
@@ -246,7 +264,7 @@ namespace Subsurface.Items.Components
|
||||
}
|
||||
|
||||
|
||||
public override void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch)
|
||||
public override void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch, bool editing)
|
||||
{
|
||||
if (Nodes.Count == 0) return;
|
||||
|
||||
@@ -257,15 +275,63 @@ namespace Subsurface.Items.Components
|
||||
|
||||
for (int i = 1; i < Nodes.Count; i++)
|
||||
{
|
||||
DrawSection(spriteBatch, Nodes[i], Nodes[i - 1], i, Color.White);
|
||||
DrawSection(spriteBatch, Nodes[i], Nodes[i - 1], i, item.Color);
|
||||
}
|
||||
|
||||
if (isActive && Vector2.Distance(newNodePos, Nodes[Nodes.Count - 1]) > nodeDistance)
|
||||
{
|
||||
DrawSection(spriteBatch, Nodes[Nodes.Count - 1], newNodePos, Nodes.Count, Color.White * 0.5f);
|
||||
DrawSection(spriteBatch, Nodes[Nodes.Count - 1], newNodePos, Nodes.Count, item.Color * 0.5f);
|
||||
//nodes.Add(newNodePos);
|
||||
}
|
||||
|
||||
if (!editing) return;
|
||||
|
||||
for (int i = 1; i < Nodes.Count; i++)
|
||||
{
|
||||
GUI.DrawRectangle(spriteBatch, new Rectangle((int)Nodes[i].X - 3, (int)-Nodes[i].Y -3, 6, 6), Color.Red, true, 0.0f);
|
||||
|
||||
if (Vector2.Distance(Game1.EditMapScreen.Cam.ScreenToWorld(PlayerInput.MousePosition), Nodes[i]) < 20.0f)
|
||||
{
|
||||
GUI.DrawRectangle(spriteBatch, new Rectangle((int)Nodes[i].X - 10, (int)-Nodes[i].Y - 10, 20, 20), Color.Red, false, 0.0f);
|
||||
|
||||
if (selectedNodeIndex==null && selectedNodeIndex>0 && selectedNodeIndex<Nodes.Count-1)
|
||||
{
|
||||
if ( PlayerInput.LeftButtonDown())
|
||||
{
|
||||
MapEntity.SelectEntity(item);
|
||||
selectedNodeIndex = i;
|
||||
}
|
||||
else
|
||||
{
|
||||
Nodes.RemoveAt(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (PlayerInput.LeftButtonDown())
|
||||
{
|
||||
|
||||
if (selectedNodeIndex!=null && item.IsSelected)
|
||||
{
|
||||
MapEntity.DisableSelect = true;
|
||||
Nodes[(int)selectedNodeIndex] = Game1.EditMapScreen.Cam.ScreenToWorld(PlayerInput.MousePosition);
|
||||
|
||||
Vector2 pos = Nodes[(int)selectedNodeIndex];
|
||||
|
||||
|
||||
Nodes[(int)selectedNodeIndex] = RoundNode(Nodes[(int)selectedNodeIndex], Hull.FindHull(Nodes[(int)selectedNodeIndex]));
|
||||
MapEntity.SelectEntity(item);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//if (selectedNodeIndex != null) MapEntity.SelectEntity(item); ;
|
||||
selectedNodeIndex = null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void DrawSection(SpriteBatch spriteBatch, Vector2 start, Vector2 end, int i, Color color)
|
||||
|
||||
@@ -79,7 +79,7 @@ namespace Subsurface.Items.Components
|
||||
ToolBox.GetAttributeVector2(element, "origin", Vector2.Zero));
|
||||
}
|
||||
|
||||
public override void Draw(SpriteBatch spriteBatch)
|
||||
public override void Draw(SpriteBatch spriteBatch, bool editing)
|
||||
{
|
||||
barrelSprite.Draw(spriteBatch, new Vector2(item.Rect.X, -item.Rect.Y) + barrelPos, rotation + MathHelper.PiOver2, 1.0f);
|
||||
}
|
||||
|
||||
@@ -256,14 +256,14 @@ namespace Subsurface
|
||||
|
||||
if (item == null) return;
|
||||
|
||||
item.sprite.Draw(spriteBatch, new Vector2(rect.X + rect.Width / 2, rect.Y + rect.Height / 2), Color.White);
|
||||
item.sprite.Draw(spriteBatch, new Vector2(rect.X + rect.Width / 2, rect.Y + rect.Height / 2), item.Color);
|
||||
|
||||
if (isHighLighted)
|
||||
{
|
||||
Vector2 pos = new Vector2(rect.X + rect.Width / 2, rect.Y - rect.Height + 20) - GUI.Font.MeasureString(item.Name)*0.5f;
|
||||
Vector2 pos = new Vector2(rect.X + rect.Width / 2, rect.Y - rect.Height + 20) - GUI.Font.MeasureString(item.Name) * 0.5f;
|
||||
pos.X = (int)pos.X;
|
||||
pos.Y = (int)pos.Y;
|
||||
spriteBatch.DrawString(GUI.Font, item.Name + " - "+item.ID, pos - new Vector2(1.0f,1.0f), Color.Black);
|
||||
spriteBatch.DrawString(GUI.Font, item.Name + " - " + item.ID, pos - new Vector2(1.0f, 1.0f), Color.Black);
|
||||
spriteBatch.DrawString(GUI.Font, item.Name + " - " + item.ID, pos, Color.White);
|
||||
}
|
||||
|
||||
|
||||
@@ -82,6 +82,21 @@ namespace Subsurface
|
||||
get { return condition; }
|
||||
}
|
||||
|
||||
private Color spriteColor;
|
||||
[Editable, HasDefaultValue("1.0,1.0,1.0,1.0", true)]
|
||||
public string SpriteColor
|
||||
{
|
||||
get { return ToolBox.Vector4ToString(spriteColor.ToVector4()); }
|
||||
set
|
||||
{
|
||||
spriteColor = new Color(ToolBox.ParseToVector4(value));
|
||||
}
|
||||
}
|
||||
|
||||
public Color Color
|
||||
{
|
||||
get { return spriteColor; }
|
||||
}
|
||||
|
||||
[Editable, HasDefaultValue("", true)]
|
||||
public string Tags
|
||||
@@ -497,7 +512,7 @@ namespace Subsurface
|
||||
|
||||
public override void Draw(SpriteBatch spriteBatch, bool editing)
|
||||
{
|
||||
Color color = (isSelected && editing) ? color = Color.Red : Color.White;
|
||||
Color color = (isSelected && editing) ? color = Color.Red : spriteColor;
|
||||
if (isHighlighted) color = Color.Orange;
|
||||
|
||||
if (body==null)
|
||||
@@ -506,10 +521,10 @@ namespace Subsurface
|
||||
}
|
||||
else if (body.Enabled)
|
||||
{
|
||||
body.Draw(spriteBatch, prefab.sprite, color);
|
||||
body.Draw(spriteBatch, prefab.sprite, color);
|
||||
}
|
||||
|
||||
foreach (ItemComponent component in components) component.Draw(spriteBatch);
|
||||
foreach (ItemComponent component in components) component.Draw(spriteBatch, editing);
|
||||
|
||||
if (!editing || (body!=null && !body.Enabled))
|
||||
{
|
||||
@@ -912,8 +927,16 @@ namespace Subsurface
|
||||
XElement element = new XElement("Item");
|
||||
|
||||
element.Add(new XAttribute("name", prefab.Name),
|
||||
new XAttribute("ID", ID),
|
||||
new XAttribute("rect", rect.X + "," + rect.Y+","+rect.Width+","+rect.Height));
|
||||
new XAttribute("ID", ID));
|
||||
|
||||
if (prefab.ResizeHorizontal || prefab.ResizeVertical)
|
||||
{
|
||||
element.Add(new XAttribute("rect", rect.X + "," + rect.Y + "," + rect.Width + "," + rect.Height));
|
||||
}
|
||||
else
|
||||
{
|
||||
element.Add(new XAttribute("rect", rect.X + "," + rect.Y));
|
||||
}
|
||||
|
||||
if (linkedTo != null && linkedTo.Count>0)
|
||||
{
|
||||
@@ -930,32 +953,6 @@ namespace Subsurface
|
||||
|
||||
ObjectProperty.SaveProperties(this, element);
|
||||
|
||||
//var saveProperties = ObjectProperty.GetProperties<Saveable>(this);
|
||||
//foreach (var property in saveProperties)
|
||||
//{
|
||||
// object value = property.GetValue();
|
||||
// if (value == null) continue;
|
||||
|
||||
// bool dontSave=false;
|
||||
// foreach (var ini in property.Attributes.OfType<Initable>())
|
||||
// {
|
||||
// if (ini.defaultValue==value)
|
||||
// {
|
||||
// dontSave = true;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
|
||||
// if (dontSave) continue;
|
||||
|
||||
// element.Add(new XAttribute(property.Name.ToLower(), value));
|
||||
//}
|
||||
|
||||
//if (tags.Count>0)
|
||||
//{
|
||||
// element.Add(new XAttribute("tags",string.Join(", ",tags)));
|
||||
//}
|
||||
|
||||
foreach (ItemComponent ic in components)
|
||||
{
|
||||
ic.Save(element);
|
||||
@@ -970,12 +967,22 @@ namespace Subsurface
|
||||
{
|
||||
string rectString = ToolBox.GetAttributeString(element, "rect", "0,0,0,0");
|
||||
string[] rectValues = rectString.Split(',');
|
||||
Rectangle rect = Rectangle.Empty;
|
||||
if (rectValues.Length==4)
|
||||
{
|
||||
rect = new Rectangle(
|
||||
int.Parse(rectValues[0]),
|
||||
int.Parse(rectValues[1]),
|
||||
int.Parse(rectValues[2]),
|
||||
int.Parse(rectValues[3]));
|
||||
} else
|
||||
{
|
||||
rect = new Rectangle(
|
||||
int.Parse(rectValues[0]),
|
||||
int.Parse(rectValues[1]),
|
||||
0, 0);
|
||||
}
|
||||
|
||||
Rectangle rect = new Rectangle(
|
||||
int.Parse(rectValues[0]),
|
||||
int.Parse(rectValues[1]),
|
||||
int.Parse(rectValues[2]),
|
||||
int.Parse(rectValues[3]));
|
||||
|
||||
string name = element.Attribute("name").Value;
|
||||
|
||||
@@ -986,6 +993,12 @@ namespace Subsurface
|
||||
|
||||
if (ip.Name != name) continue;
|
||||
|
||||
if (rect.Width==0 && rect.Height==0)
|
||||
{
|
||||
rect.Width = (int)ip.Size.X;
|
||||
rect.Height = (int)ip.Size.Y;
|
||||
}
|
||||
|
||||
Item item = new Item(rect, ip);
|
||||
item.ID = int.Parse(element.Attribute("ID").Value);
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace Subsurface
|
||||
{
|
||||
class ItemPrefab : MapEntityPrefab
|
||||
{
|
||||
static string contentFolder = "Content/Items/";
|
||||
//static string contentFolder = "Content/Items/";
|
||||
|
||||
string configFile;
|
||||
|
||||
@@ -55,6 +55,11 @@ namespace Subsurface
|
||||
get { return offsetOnSelected; }
|
||||
}
|
||||
|
||||
public Vector2 Size
|
||||
{
|
||||
get { return size; }
|
||||
}
|
||||
|
||||
public override void UpdatePlacing(SpriteBatch spriteBatch, Camera cam)
|
||||
{
|
||||
Vector2 position = Submarine.MouseToWorldGrid(cam);
|
||||
|
||||
61
Subsurface/Map/Lights/Light.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Subsurface.Lights
|
||||
{
|
||||
class LightSource
|
||||
{
|
||||
|
||||
private static Texture2D lightTexture;
|
||||
|
||||
private Color color;
|
||||
|
||||
private float range;
|
||||
|
||||
private Texture2D texture;
|
||||
|
||||
public Vector2 Position;
|
||||
|
||||
public Color Color
|
||||
{
|
||||
get { return color; }
|
||||
set { color = value; }
|
||||
}
|
||||
|
||||
public float Range
|
||||
{
|
||||
get { return range; }
|
||||
set
|
||||
{
|
||||
range = MathHelper.Clamp(value, 0.0f, 2048.0f);
|
||||
}
|
||||
}
|
||||
|
||||
public LightSource(Vector2 position, float range, Color color)
|
||||
{
|
||||
Position = position;
|
||||
this.range = range;
|
||||
this.color = color;
|
||||
|
||||
if (lightTexture == null)
|
||||
{
|
||||
lightTexture = Game1.TextureLoader.FromFile("Content/Lights/light.png");
|
||||
}
|
||||
|
||||
texture = lightTexture;
|
||||
|
||||
Game1.LightManager.AddLight(this);
|
||||
}
|
||||
|
||||
public void Draw(SpriteBatch spriteBatch)
|
||||
{
|
||||
Vector2 center = new Vector2(lightTexture.Width / 2, lightTexture.Height / 2);
|
||||
float scale = range / ((float)lightTexture.Width / 2.0f);
|
||||
spriteBatch.Draw(lightTexture, new Vector2(Position.X, -Position.Y), null, color, 0, center, scale, SpriteEffects.None, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Subsurface.Lights
|
||||
{
|
||||
@@ -7,16 +8,126 @@ namespace Subsurface.Lights
|
||||
{
|
||||
public static Vector2 ViewPos;
|
||||
|
||||
public static bool FowEnabled = true;
|
||||
public Color AmbientLight;
|
||||
|
||||
public static void DrawFow(GraphicsDevice graphics, Camera cam)
|
||||
RenderTarget2D lightMap;
|
||||
|
||||
private static Texture2D alphaClearTexture;
|
||||
|
||||
private List<LightSource> lights;
|
||||
|
||||
public bool FowEnabled = true;
|
||||
|
||||
public bool LightingEnabled = true;
|
||||
|
||||
public RenderTarget2D LightMap
|
||||
{
|
||||
get { return lightMap; }
|
||||
}
|
||||
|
||||
public LightManager(GraphicsDevice graphics)
|
||||
{
|
||||
lights = new List<LightSource>();
|
||||
|
||||
AmbientLight = new Color(80, 80, 80, 255);
|
||||
|
||||
var pp = graphics.PresentationParameters;
|
||||
|
||||
lightMap = new RenderTarget2D(graphics, Game1.GraphicsWidth, Game1.GraphicsHeight, false,
|
||||
pp.BackBufferFormat, pp.DepthStencilFormat, pp.MultiSampleCount,
|
||||
RenderTargetUsage.DiscardContents);
|
||||
|
||||
|
||||
if (alphaClearTexture==null)
|
||||
{
|
||||
alphaClearTexture = Game1.TextureLoader.FromFile("Content/Lights/alphaOne.png");
|
||||
}
|
||||
}
|
||||
|
||||
public void AddLight(LightSource light)
|
||||
{
|
||||
lights.Add(light);
|
||||
}
|
||||
|
||||
public void RemoveLight(LightSource light)
|
||||
{
|
||||
lights.Remove(light);
|
||||
}
|
||||
|
||||
public void DrawFow(GraphicsDevice graphics, Camera cam, Vector2 pos)
|
||||
{
|
||||
if (!FowEnabled) return;
|
||||
foreach (ConvexHull convexHull in ConvexHull.list)
|
||||
{
|
||||
convexHull.DrawShadows(graphics, cam, ViewPos);
|
||||
convexHull.DrawShadows(graphics, cam, pos);
|
||||
}
|
||||
}
|
||||
|
||||
public void DrawLightmap(GraphicsDevice graphics, SpriteBatch spriteBatch, Camera cam)
|
||||
{
|
||||
graphics.SetRenderTarget(lightMap);
|
||||
|
||||
//clear to some small ambient light
|
||||
graphics.Clear(AmbientLight);
|
||||
|
||||
foreach (LightSource light in lights)
|
||||
{
|
||||
//clear alpha to 1
|
||||
ClearAlphaToOne(graphics, spriteBatch);
|
||||
|
||||
//draw all shadows
|
||||
//write only to the alpha channel, which sets alpha to 0
|
||||
//graphics.RasterizerState = RasterizerState.CullNone;
|
||||
//graphics.BlendState = CustomBlendStates.WriteToAlpha;
|
||||
|
||||
//foreach (ConvexHull ch in ConvexHull.list)
|
||||
//{
|
||||
// //draw shadow
|
||||
// ch.DrawShadows(graphics, cam, light.Position);
|
||||
//}
|
||||
|
||||
//draw the light shape
|
||||
//where Alpha is 0, nothing will be written
|
||||
spriteBatch.Begin(SpriteSortMode.Immediate, CustomBlendStates.MultiplyWithAlpha, null, null, null, null, cam.Transform);
|
||||
light.Draw(spriteBatch);
|
||||
spriteBatch.End();
|
||||
}
|
||||
//clear alpha, to avoid messing stuff up later
|
||||
ClearAlphaToOne(graphics, spriteBatch);
|
||||
graphics.SetRenderTarget(null);
|
||||
}
|
||||
|
||||
private void ClearAlphaToOne(GraphicsDevice graphics, SpriteBatch spriteBatch)
|
||||
{
|
||||
spriteBatch.Begin(SpriteSortMode.Immediate, CustomBlendStates.WriteToAlpha);
|
||||
spriteBatch.Draw(alphaClearTexture, new Rectangle(0, 0,graphics.Viewport.Width, graphics.Viewport.Height), Color.White);
|
||||
spriteBatch.End();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class CustomBlendStates
|
||||
{
|
||||
static CustomBlendStates()
|
||||
{
|
||||
Multiplicative = new BlendState();
|
||||
Multiplicative.ColorSourceBlend = Multiplicative.AlphaSourceBlend = Blend.Zero;
|
||||
Multiplicative.ColorDestinationBlend = Multiplicative.AlphaDestinationBlend = Blend.SourceColor;
|
||||
Multiplicative.ColorBlendFunction = Multiplicative.AlphaBlendFunction = BlendFunction.Add;
|
||||
|
||||
WriteToAlpha = new BlendState();
|
||||
WriteToAlpha.ColorWriteChannels = ColorWriteChannels.Alpha;
|
||||
|
||||
MultiplyWithAlpha = new BlendState();
|
||||
MultiplyWithAlpha.ColorDestinationBlend = MultiplyWithAlpha.AlphaDestinationBlend = Blend.One;
|
||||
MultiplyWithAlpha.ColorSourceBlend = MultiplyWithAlpha.AlphaSourceBlend = Blend.DestinationAlpha;
|
||||
}
|
||||
public static BlendState Multiplicative { get; private set; }
|
||||
public static BlendState WriteToAlpha { get; private set; }
|
||||
public static BlendState MultiplyWithAlpha { get; private set; }
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,9 +22,9 @@ namespace Subsurface
|
||||
private int seed;
|
||||
private int size;
|
||||
|
||||
private Texture2D iceTexture;
|
||||
private Texture2D iceCraters;
|
||||
private Texture2D iceCrack;
|
||||
private static Texture2D iceTexture;
|
||||
private static Texture2D iceCraters;
|
||||
private static Texture2D iceCrack;
|
||||
|
||||
private Location currentLocation;
|
||||
private Location selectedLocation;
|
||||
@@ -61,9 +61,9 @@ namespace Subsurface
|
||||
|
||||
connections = new List<LocationConnection>();
|
||||
|
||||
iceTexture = Game1.TextureLoader.FromFile("Content/Map/iceSurface.png");
|
||||
iceCraters = Game1.TextureLoader.FromFile("Content/Map/iceCraters.png");
|
||||
iceCrack = Game1.TextureLoader.FromFile("Content/Map/iceCrack.png");
|
||||
if (iceTexture==null) iceTexture = Game1.TextureLoader.FromFile("Content/Map/iceSurface.png");
|
||||
if (iceCraters == null) iceCraters = Game1.TextureLoader.FromFile("Content/Map/iceCraters.png");
|
||||
if (iceCrack == null) iceCrack = Game1.TextureLoader.FromFile("Content/Map/iceCrack.png");
|
||||
|
||||
Rand.SetSyncedSeed(this.seed);
|
||||
|
||||
@@ -151,14 +151,16 @@ namespace Subsurface
|
||||
|
||||
for (int i = connections.Count - 1; i >= 0; i--)
|
||||
{
|
||||
i = Math.Min(i, connections.Count - 1);
|
||||
|
||||
LocationConnection connection = connections[i];
|
||||
|
||||
for (int n = i - 1; n >= 0; n--)
|
||||
for (int n = Math.Min(i - 1,connections.Count - 1); n >= 0; n--)
|
||||
{
|
||||
if (connection.Locations.Contains(connections[n].Locations[0])
|
||||
&& connection.Locations.Contains(connections[n].Locations[1]))
|
||||
{
|
||||
connections.RemoveAt(i);
|
||||
connections.RemoveAt(n);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +37,21 @@ namespace Subsurface
|
||||
|
||||
protected bool isSelected;
|
||||
|
||||
private static bool disableSelect;
|
||||
public static bool DisableSelect
|
||||
{
|
||||
get { return disableSelect; }
|
||||
set {
|
||||
disableSelect = value;
|
||||
if (disableSelect==true)
|
||||
{
|
||||
startMovingPos = Vector2.Zero;
|
||||
selectionSize = Vector2.Zero;
|
||||
selectionPos = Vector2.Zero;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool MoveWithLevel
|
||||
{
|
||||
get;
|
||||
@@ -174,6 +189,12 @@ namespace Subsurface
|
||||
{
|
||||
if (GUIComponent.MouseOn != null) return;
|
||||
|
||||
if (DisableSelect)
|
||||
{
|
||||
DisableSelect = false;
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (MapEntity e in mapEntityList)
|
||||
{
|
||||
e.isHighlighted = false;
|
||||
@@ -189,8 +210,7 @@ namespace Subsurface
|
||||
|
||||
if (PlayerInput.GetKeyboardState.IsKeyDown(Keys.Delete))
|
||||
{
|
||||
foreach (MapEntity e in selectedList)
|
||||
e.Remove();
|
||||
foreach (MapEntity e in selectedList) e.Remove();
|
||||
selectedList.Clear();
|
||||
}
|
||||
|
||||
@@ -209,7 +229,7 @@ namespace Subsurface
|
||||
e.isSelected = false;
|
||||
}
|
||||
|
||||
if (highLightedEntity!=null)
|
||||
if (highLightedEntity != null)
|
||||
highLightedEntity.isHighlighted = true;
|
||||
|
||||
foreach (MapEntity e in selectedList)
|
||||
@@ -269,7 +289,6 @@ namespace Subsurface
|
||||
|
||||
foreach (MapEntity e2 in selectedList)
|
||||
{
|
||||
Debug.WriteLine(e.ID+", "+e2.ID);
|
||||
if (e.ID == e2.ID) alreadySelected = true;
|
||||
}
|
||||
|
||||
@@ -359,6 +378,18 @@ namespace Subsurface
|
||||
editingHUD = null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void SelectEntity(MapEntity entity)
|
||||
{
|
||||
foreach (MapEntity e in selectedList)
|
||||
{
|
||||
e.isSelected = false;
|
||||
}
|
||||
selectedList.Clear();
|
||||
|
||||
entity.isSelected = true;
|
||||
selectedList.Add(entity);
|
||||
}
|
||||
|
||||
public virtual void DrawEditing(SpriteBatch spriteBatch, Camera cam) {}
|
||||
|
||||
|
||||
@@ -25,9 +25,7 @@ namespace Subsurface
|
||||
//is it possible to stretch the entity horizontally/vertically
|
||||
protected bool resizeHorizontal;
|
||||
protected bool resizeVertical;
|
||||
|
||||
|
||||
|
||||
|
||||
//which prefab has been selected for placing
|
||||
protected static MapEntityPrefab selected;
|
||||
|
||||
@@ -46,7 +44,15 @@ namespace Subsurface
|
||||
get { return isLinkable; }
|
||||
}
|
||||
|
||||
public bool ResizeHorizontal
|
||||
{
|
||||
get { return resizeHorizontal; }
|
||||
}
|
||||
|
||||
public bool ResizeVertical
|
||||
{
|
||||
get { return resizeVertical; }
|
||||
}
|
||||
|
||||
public static void Init()
|
||||
{
|
||||
|
||||
@@ -825,6 +825,7 @@ namespace Subsurface
|
||||
|
||||
foreach (Item item in Item.itemList)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine(item.ID);
|
||||
foreach (ItemComponent ic in item.components)
|
||||
{
|
||||
ic.OnMapLoaded();
|
||||
|
||||
@@ -74,8 +74,8 @@ namespace Subsurface.Networking
|
||||
// Create new instance of configs. Parameter is "application Id". It has to be same on client and server.
|
||||
NetPeerConfiguration Config = new NetPeerConfiguration("subsurface");
|
||||
|
||||
//Config.SimulatedLoss = 0.2f;
|
||||
//Config.SimulatedMinimumLatency = 0.25f;
|
||||
Config.SimulatedLoss = 0.2f;
|
||||
Config.SimulatedMinimumLatency = 0.25f;
|
||||
|
||||
// Create new client, with previously created configs
|
||||
client = new NetClient(Config);
|
||||
@@ -541,8 +541,8 @@ namespace Subsurface.Networking
|
||||
break;
|
||||
}
|
||||
|
||||
int byteCount = Rand.Int(100);
|
||||
for (int i = 0; i<byteCount; i++)
|
||||
int bitCount = Rand.Int(100);
|
||||
for (int i = 0; i<bitCount; i++)
|
||||
{
|
||||
msg.Write((Rand.Int(2)==0) ? true : false);
|
||||
}
|
||||
|
||||
@@ -56,6 +56,11 @@ namespace Subsurface.Networking
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
if (PlayerInput.KeyDown(Microsoft.Xna.Framework.Input.Keys.K))
|
||||
{
|
||||
SendRandomData();
|
||||
}
|
||||
|
||||
if (gameStarted) inGameHUD.Update((float)Physics.step);
|
||||
|
||||
NetIncomingMessage inc = Server.ReadMessage();
|
||||
@@ -104,7 +109,7 @@ namespace Subsurface.Networking
|
||||
}
|
||||
}
|
||||
|
||||
new NetworkEvent(Submarine.Loaded.ID, false);
|
||||
if (gameStarted) new NetworkEvent(Submarine.Loaded.ID, false);
|
||||
|
||||
sparseUpdateTimer = DateTime.Now + SparseUpdateInterval;
|
||||
}
|
||||
@@ -534,8 +539,6 @@ namespace Subsurface.Networking
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public override void SendChatMessage(string message, ChatMessageType type = ChatMessageType.Server)
|
||||
{
|
||||
AddChatMessage(message, type);
|
||||
@@ -701,6 +704,43 @@ namespace Subsurface.Networking
|
||||
return preferredClient;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// sends some random data to the clients
|
||||
/// use for debugging purposes
|
||||
/// </summary>
|
||||
public void SendRandomData()
|
||||
{
|
||||
NetOutgoingMessage msg = Server.CreateMessage();
|
||||
switch (Rand.Int(5))
|
||||
{
|
||||
case 0:
|
||||
msg.Write((byte)PacketTypes.NetworkEvent);
|
||||
msg.Write((byte)Enum.GetNames(typeof(NetworkEventType)).Length);
|
||||
msg.Write(Rand.Int(MapEntity.mapEntityList.Count));
|
||||
break;
|
||||
case 1:
|
||||
msg.Write((byte)PacketTypes.NetworkEvent);
|
||||
msg.Write((byte)NetworkEventType.UpdateComponent);
|
||||
msg.Write((int)Item.itemList[Rand.Int(Item.itemList.Count)].ID);
|
||||
msg.Write(Rand.Int(8));
|
||||
break;
|
||||
case 2:
|
||||
msg.Write((byte)Enum.GetNames(typeof(PacketTypes)).Length);
|
||||
break;
|
||||
case 3:
|
||||
msg.Write((byte)PacketTypes.UpdateNetLobby);
|
||||
break;
|
||||
}
|
||||
|
||||
int bitCount = Rand.Int(100);
|
||||
for (int i = 0; i < bitCount; i++)
|
||||
{
|
||||
msg.Write((Rand.Int(2) == 0) ? true : false);
|
||||
}
|
||||
SendMessage(msg, (Rand.Int(2) == 0) ? NetDeliveryMethod.ReliableOrdered : NetDeliveryMethod.Unreliable, null);
|
||||
|
||||
}
|
||||
|
||||
public override void Disconnect()
|
||||
{
|
||||
Server.Shutdown("");
|
||||
|
||||
@@ -255,16 +255,28 @@ namespace Subsurface
|
||||
|
||||
if (characterMode)
|
||||
{
|
||||
if (dummyCharacter != null && dummyCharacter.SelectedConstruction != null)
|
||||
if (dummyCharacter != null)
|
||||
{
|
||||
if (dummyCharacter.SelectedConstruction == dummyCharacter.ClosestItem)
|
||||
foreach (Item item in dummyCharacter.SelectedItems)
|
||||
{
|
||||
dummyCharacter.SelectedConstruction.DrawHUD(spriteBatch, dummyCharacter);
|
||||
if (item == null) continue;
|
||||
item.SetTransform(dummyCharacter.SimPosition, 0.0f);
|
||||
|
||||
item.Update(cam, (float)deltaTime);
|
||||
}
|
||||
else
|
||||
|
||||
if (dummyCharacter.SelectedConstruction != null)
|
||||
{
|
||||
dummyCharacter.SelectedConstruction = null;
|
||||
if (dummyCharacter.SelectedConstruction == dummyCharacter.ClosestItem)
|
||||
{
|
||||
dummyCharacter.SelectedConstruction.DrawHUD(spriteBatch, dummyCharacter);
|
||||
}
|
||||
else
|
||||
{
|
||||
dummyCharacter.SelectedConstruction = null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (PlayerInput.GetMouseState.LeftButton != ButtonState.Pressed)
|
||||
|
||||
@@ -147,6 +147,14 @@ namespace Subsurface
|
||||
|
||||
public void DrawMap(GraphicsDevice graphics, SpriteBatch spriteBatch)
|
||||
{
|
||||
|
||||
|
||||
Game1.LightManager.DrawLightmap(graphics, spriteBatch, cam);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
//1. draw the characters and the parts of the map that are behind them
|
||||
//----------------------------------------------------------------------------------------
|
||||
@@ -282,7 +290,17 @@ namespace Subsurface
|
||||
|
||||
if (Game1.Level != null) Game1.Level.Render(graphics, cam);
|
||||
|
||||
LightManager.DrawFow(graphics,cam);
|
||||
if (Game1.LightManager.LightingEnabled)
|
||||
{
|
||||
//multiply scene with lightmap
|
||||
spriteBatch.Begin(SpriteSortMode.Immediate, CustomBlendStates.Multiplicative);
|
||||
spriteBatch.Draw(Game1.LightManager.LightMap, Vector2.Zero, Color.White);
|
||||
spriteBatch.End();
|
||||
}
|
||||
|
||||
|
||||
Game1.LightManager.DrawFow(graphics,cam,LightManager.ViewPos);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,7 +148,7 @@ namespace Subsurface
|
||||
|
||||
public override void Select()
|
||||
{
|
||||
Lights.LightManager.FowEnabled = false;
|
||||
Game1.LightManager.FowEnabled = false;
|
||||
|
||||
infoFrame.ClearChildren();
|
||||
|
||||
@@ -215,21 +215,23 @@ namespace Subsurface
|
||||
seedBox.Enabled = (Game1.Server != null);
|
||||
LevelSeed = ToolBox.RandomSeed(8);
|
||||
|
||||
var serverName = new GUITextBlock(new Rectangle(0, 0, 200, 30),
|
||||
"Server: ", GUI.style, Alignment.Left, Alignment.TopLeft, infoFrame);
|
||||
var serverName = new GUITextBox(new Rectangle(0, 0, 200, 20), null, null, Alignment.TopLeft, Alignment.TopLeft, GUI.style, infoFrame);
|
||||
serverName.TextGetter = GetServerName;
|
||||
serverName.Enabled = Game1.Server != null;
|
||||
serverName.OnTextChanged = ChangeServerName;
|
||||
ServerName = "Server";
|
||||
|
||||
var serverMessage = new GUITextBox(new Rectangle(0, 30, 360, 70),null,null, Alignment.TopLeft, Alignment.TopLeft, GUI.style, infoFrame);
|
||||
serverMessage.Enabled = false;
|
||||
serverMessage.Enabled = Game1.Server != null;
|
||||
serverMessage.Wrap = true;
|
||||
serverMessage.TextGetter = GetServerMessage;
|
||||
serverMessage.OnTextChanged = UpdateServerMessage;
|
||||
|
||||
if (IsServer && Game1.Server != null)
|
||||
{
|
||||
GUIButton startButton = new GUIButton(new Rectangle(0, 0, 200, 30), "Start", Alignment.TopRight, GUI.style, infoFrame);
|
||||
startButton.OnClicked = Game1.Server.StartGame;
|
||||
|
||||
serverMessage.Enabled = true;
|
||||
|
||||
|
||||
//mapList.OnSelected = new GUIListBox.OnSelectedHandler(Game1.server.UpdateNetLobby);
|
||||
modeList.OnSelected = Game1.Server.UpdateNetLobby;
|
||||
durationBar.OnMoved = Game1.Server.UpdateNetLobby;
|
||||
@@ -301,6 +303,24 @@ namespace Subsurface
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool ChangeServerName(GUITextBox textBox, string text)
|
||||
{
|
||||
if (Game1.Server == null) return false;
|
||||
ServerName = text;
|
||||
Game1.Server.UpdateNetLobby(null);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool UpdateServerMessage(GUITextBox textBox, string text)
|
||||
{
|
||||
if (Game1.Server == null) return false;
|
||||
ServerMessage = text;
|
||||
Game1.Server.UpdateNetLobby(null);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public void AddPlayer(Client client)
|
||||
{
|
||||
@@ -539,6 +559,7 @@ namespace Subsurface
|
||||
}
|
||||
|
||||
msg.Write(ServerName);
|
||||
msg.Write(ServerMessage);
|
||||
|
||||
msg.Write(modeList.SelectedIndex-1);
|
||||
msg.Write(durationBar.BarScroll);
|
||||
@@ -558,50 +579,80 @@ namespace Subsurface
|
||||
|
||||
public void ReadData(NetIncomingMessage msg)
|
||||
{
|
||||
string mapName = msg.ReadString();
|
||||
string md5Hash = msg.ReadString();
|
||||
string mapName="", md5Hash="";
|
||||
|
||||
int modeIndex = 0;
|
||||
float durationScroll = 0.0f;
|
||||
string levelSeed = "";
|
||||
|
||||
try
|
||||
{
|
||||
mapName = msg.ReadString();
|
||||
md5Hash = msg.ReadString();
|
||||
|
||||
ServerName = msg.ReadString();
|
||||
ServerMessage = msg.ReadString();
|
||||
|
||||
modeIndex = msg.ReadInt32();
|
||||
|
||||
durationScroll = msg.ReadFloat();
|
||||
|
||||
levelSeed = msg.ReadString();
|
||||
}
|
||||
|
||||
catch
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
TrySelectMap(mapName, md5Hash);
|
||||
|
||||
ServerName = msg.ReadString();
|
||||
modeList.Select(modeIndex);
|
||||
|
||||
//mapList.Select(msg.ReadInt32());
|
||||
modeList.Select(msg.ReadInt32());
|
||||
durationBar.BarScroll = durationScroll;
|
||||
|
||||
durationBar.BarScroll = msg.ReadFloat();
|
||||
LevelSeed = levelSeed;
|
||||
|
||||
LevelSeed = msg.ReadString();
|
||||
|
||||
int playerCount = msg.ReadInt32();
|
||||
for (int i = 0; i < playerCount; i++)
|
||||
try
|
||||
{
|
||||
int clientID = msg.ReadInt32();
|
||||
string jobName = msg.ReadString();
|
||||
|
||||
Client client = null;
|
||||
GUITextBlock textBlock = null;
|
||||
foreach (GUIComponent child in playerList.children)
|
||||
int playerCount = msg.ReadInt32();
|
||||
|
||||
for (int i = 0; i < playerCount; i++)
|
||||
{
|
||||
Client tempClient = child.UserData as Client;
|
||||
if (tempClient == null || tempClient.ID != clientID) continue;
|
||||
|
||||
client = tempClient;
|
||||
textBlock = child as GUITextBlock;
|
||||
break;
|
||||
}
|
||||
if (client == null) continue;
|
||||
int clientID = msg.ReadInt32();
|
||||
string jobName = msg.ReadString();
|
||||
|
||||
client.assignedJob = JobPrefab.List.Find(jp => jp.Name == jobName);
|
||||
Client client = null;
|
||||
GUITextBlock textBlock = null;
|
||||
foreach (GUIComponent child in playerList.children)
|
||||
{
|
||||
Client tempClient = child.UserData as Client;
|
||||
if (tempClient == null || tempClient.ID != clientID) continue;
|
||||
|
||||
client = tempClient;
|
||||
textBlock = child as GUITextBlock;
|
||||
break;
|
||||
}
|
||||
if (client == null) continue;
|
||||
|
||||
client.assignedJob = JobPrefab.List.Find(jp => jp.Name == jobName);
|
||||
|
||||
textBlock.Text = client.name + ((client.assignedJob==null) ? "" : " (" + client.assignedJob.Name + ")");
|
||||
textBlock.Text = client.name + ((client.assignedJob==null) ? "" : " (" + client.assignedJob.Name + ")");
|
||||
|
||||
if (clientID == Game1.Client.ID)
|
||||
{
|
||||
Game1.Client.CharacterInfo.Job = new Job(client.assignedJob);
|
||||
Game1.Client.CharacterInfo.Name = client.name;
|
||||
UpdatePreviewPlayer(Game1.Client.CharacterInfo);
|
||||
if (clientID == Game1.Client.ID)
|
||||
{
|
||||
Game1.Client.CharacterInfo.Job = new Job(client.assignedJob);
|
||||
Game1.Client.CharacterInfo.Name = client.name;
|
||||
UpdatePreviewPlayer(Game1.Client.CharacterInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
catch
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -68,6 +68,7 @@
|
||||
<Compile Include="CoroutineManager.cs" />
|
||||
<Compile Include="GUI\TitleScreen.cs" />
|
||||
<Compile Include="Items\FixRequirement.cs" />
|
||||
<Compile Include="Map\Lights\Light.cs" />
|
||||
<Compile Include="Map\LocationType.cs" />
|
||||
<Compile Include="Utils\Rand.cs" />
|
||||
<Compile Include="Events\PropertyTask.cs" />
|
||||
@@ -272,6 +273,13 @@
|
||||
<Content Include="Content\Characters\Human\torso.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Content\Items\Electricity\lamp.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Content\Items\Electricity\lights.xml">
|
||||
<SubType>Designer</SubType>
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Content\Jobs.xml">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
<SubType>Designer</SubType>
|
||||
@@ -380,6 +388,12 @@
|
||||
<Content Include="Content\Items\Pump\pump.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Content\Lights\alphaOne.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Content\Lights\light.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Content\Map\iceCrack.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
@@ -679,6 +693,10 @@
|
||||
<None Include="Content\Items\Weapons\stunGrenade.ogg">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="Content\Lights\AlphaOne.dds" />
|
||||
<None Include="Content\SmallFont.xnb">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="Content\Sounds\Damage\HitArmor1.ogg">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
@@ -763,6 +781,9 @@
|
||||
<None Include="Content\Sounds\Damage\StructureCrunch3.ogg">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="Content\SpriteFont1.xnb">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="Content\step.ogg">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
|
||||
@@ -9,6 +9,6 @@
|
||||
<ErrorReportUrlHistory />
|
||||
<FallbackCulture>en-US</FallbackCulture>
|
||||
<VerifyUploadedFiles>false</VerifyUploadedFiles>
|
||||
<ProjectView>ProjectFiles</ProjectView>
|
||||
<ProjectView>ShowAllFiles</ProjectView>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
@@ -18,38 +18,19 @@ namespace Subsurface
|
||||
|
||||
public static float Range(float minimum, float maximum, bool local = true)
|
||||
{
|
||||
if (local)
|
||||
{
|
||||
return (float)localRandom.NextDouble() * (maximum - minimum) + minimum;
|
||||
}
|
||||
else
|
||||
{
|
||||
return (float)syncedRandom.NextDouble() * (maximum - minimum) + minimum;
|
||||
}
|
||||
return (float)(local ? localRandom : syncedRandom).NextDouble() * (maximum - minimum) + minimum;
|
||||
|
||||
}
|
||||
|
||||
public static int Range(int minimum, int maximum, bool local = true)
|
||||
{
|
||||
if (local)
|
||||
{
|
||||
return localRandom.Next(maximum - minimum) + minimum;
|
||||
}
|
||||
else
|
||||
{
|
||||
return syncedRandom.Next(maximum - minimum) + minimum;
|
||||
}
|
||||
return (local ? localRandom : syncedRandom).Next(maximum - minimum) + minimum;
|
||||
|
||||
}
|
||||
|
||||
public static int Int(int max = int.MaxValue, bool local = true)
|
||||
{
|
||||
if (local)
|
||||
{
|
||||
return localRandom.Next(max);
|
||||
}
|
||||
else
|
||||
{
|
||||
return syncedRandom.Next(max);
|
||||
}
|
||||
return (local ? localRandom : syncedRandom).Next(max);
|
||||
}
|
||||
|
||||
public static Vector2 Vector(float length = 1.0f, bool local = true)
|
||||
|
||||