Lights, colored items (only used for wires atm)

This commit is contained in:
Regalis
2015-07-22 20:22:50 +03:00
parent 9a7eae8ace
commit 4820e55e05
51 changed files with 726 additions and 191 deletions
+6
View 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>
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

@@ -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]"> <ConnectionPanel canbeselected = "true" msg="Rewire [Screwdriver]">
<requireditem name="Screwdriver" type="Equipped"/> <requireditem name="Screwdriver" type="Equipped"/>
<output name="power"/> <output name="power"/>
<output name="signal"/> <output name="signal_0"/>
<output name="signal_1"/>
<output name="signal_2"/>
<output name="signal_3"/>
</ConnectionPanel> </ConnectionPanel>
</Item> </Item>
Binary file not shown.

Before

Width:  |  Height:  |  Size: 934 B

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 45 KiB

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 241 B

After

Width:  |  Height:  |  Size: 9.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 309 B

After

Width:  |  Height:  |  Size: 301 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 248 B

After

Width:  |  Height:  |  Size: 249 B

Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 158 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 136 KiB

Binary file not shown.
Binary file not shown.
+6 -1
View File
@@ -216,7 +216,12 @@ namespace Subsurface
case "fowenabled": case "fowenabled":
case "fow": case "fow":
case "drawfow": 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; break;
case "lobbyscreen": case "lobbyscreen":
case "lobby": case "lobby":
+8 -3
View File
@@ -24,6 +24,12 @@ namespace Subsurface
public delegate bool OnTextChangedHandler(GUITextBox textBox, string text); public delegate bool OnTextChangedHandler(GUITextBox textBox, string text);
public OnTextChangedHandler OnTextChanged; public OnTextChangedHandler OnTextChanged;
public GUITextBlock.TextGetterHandler TextGetter
{
get { return textBlock.TextGetter; }
set { textBlock.TextGetter = value; }
}
public bool Wrap public bool Wrap
{ {
get { return textBlock.Wrap; } get { return textBlock.Wrap; }
@@ -171,15 +177,14 @@ namespace Subsurface
public override void Draw(SpriteBatch spriteBatch) public override void Draw(SpriteBatch spriteBatch)
{ {
DrawChildren(spriteBatch); DrawChildren(spriteBatch);
Vector2 caretPos = textBlock.CaretPos; Vector2 caretPos = textBlock.CaretPos;
if (caretVisible && Selected) if (caretVisible && Selected)
{ {
GUI.DrawLine(spriteBatch, GUI.DrawLine(spriteBatch,
new Vector2((int)caretPos.X + 2, caretPos.Y + 3), 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)); textBlock.TextColor * (textBlock.TextColor.A / 255.0f));
} }
+4
View File
@@ -33,6 +33,8 @@ namespace Subsurface
public static EditMapScreen EditMapScreen; public static EditMapScreen EditMapScreen;
public static EditCharacterScreen EditCharacterScreen; public static EditCharacterScreen EditCharacterScreen;
public static Lights.LightManager LightManager;
public static ContentPackage SelectedPackage public static ContentPackage SelectedPackage
{ {
get { return Config.SelectedContentPackage; } get { return Config.SelectedContentPackage; }
@@ -160,6 +162,8 @@ namespace Subsurface
GUI.Font = Content.Load<SpriteFont>("SpriteFont1"); GUI.Font = Content.Load<SpriteFont>("SpriteFont1");
GUI.SmallFont = Content.Load<SpriteFont>("SmallFont"); GUI.SmallFont = Content.Load<SpriteFont>("SmallFont");
LightManager = new Lights.LightManager(GraphicsDevice);
Hull.renderer = new WaterRenderer(GraphicsDevice); Hull.renderer = new WaterRenderer(GraphicsDevice);
loadState = 1.0f; loadState = 1.0f;
yield return Status.Running; yield return Status.Running;
+1 -1
View File
@@ -131,7 +131,7 @@ namespace Subsurface
public void StartShift(TimeSpan duration, Level level, bool reloadSub = true) 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; this.level = level;
+1 -1
View File
@@ -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); base.Draw(spriteBatch);
+2 -2
View File
@@ -250,8 +250,8 @@ namespace Subsurface.Items.Components
linkedGap.Open = 1.0f; linkedGap.Open = 1.0f;
if (convexHull2 != null) convexHull2.Enabled = false; 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.IsSelected) ? Color.Green : Color.White;
color = color * (item.Condition / 100.0f); color = color * (item.Condition / 100.0f);
@@ -81,6 +81,8 @@ namespace Subsurface.Items.Components
handlePos[i - 1] = ConvertUnits.ToSimUnits(handlePos[i - 1]); handlePos[i - 1] = ConvertUnits.ToSimUnits(handlePos[i - 1]);
} }
canBePicked = true;
//holdAngle = ToolBox.GetAttributeFloat(element, "holdangle", 0.0f); //holdAngle = ToolBox.GetAttributeFloat(element, "holdangle", 0.0f);
//holdAngle = MathHelper.ToRadians(holdAngle); //holdAngle = MathHelper.ToRadians(holdAngle);
} }
@@ -160,6 +162,8 @@ namespace Subsurface.Items.Components
// return false; // return false;
//} //}
if (attached) return false;
item.body = body; item.body = body;
item.body.Enabled = true; item.body.Enabled = true;
@@ -173,8 +173,8 @@ namespace Subsurface.Items.Components
//isActive = true; //isActive = true;
} }
public override void Draw(SpriteBatch spriteBatch) public override void Draw(SpriteBatch spriteBatch, bool editing)
{ {
if (!isActive) return; if (!isActive) return;
+1 -1
View File
@@ -293,7 +293,7 @@ namespace Subsurface
/// <summary>a character has dropped the item</summary> /// <summary>a character has dropped the item</summary>
public virtual void Drop(Character dropper) { } 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) { } public virtual void DrawHUD(SpriteBatch spriteBatch, Character character) { }
@@ -281,7 +281,7 @@ namespace Subsurface.Items.Components
return true; return true;
} }
public override void Draw(SpriteBatch spriteBatch) public override void Draw(SpriteBatch spriteBatch, bool editing)
{ {
base.Draw(spriteBatch); base.Draw(spriteBatch);
@@ -173,7 +173,7 @@ namespace Subsurface.Items.Components
voltage = 0.0f; voltage = 0.0f;
} }
public override void Draw(SpriteBatch spriteBatch) public override void Draw(SpriteBatch spriteBatch, bool editing)
{ {
base.Draw(spriteBatch); base.Draw(spriteBatch);
@@ -53,11 +53,6 @@ namespace Subsurface.Items.Components
"power", fullPower / Math.Max(fullLoad, 1.0f)); "power", fullPower / Math.Max(fullLoad, 1.0f));
if (-pt.currPowerConsumption > pt.powerLoad * 2.0f) pt.item.Condition = 0.0f; if (-pt.currPowerConsumption > pt.powerLoad * 2.0f) pt.item.Condition = 0.0f;
} }
else
{
//p.Power = fullPower;
}
} }
+2 -1
View File
@@ -61,7 +61,8 @@ namespace Subsurface.Items.Components
public override void ReceiveSignal(string signal, Connection connection, Item sender, float power) 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) public override void Update(float deltaTime, Camera cam)
+1 -1
View File
@@ -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); base.Draw(spriteBatch);
@@ -339,29 +339,31 @@ namespace Subsurface.Items.Components
int textX = (int)start.X; int textX = (int)start.X;
float connLength = 10.0f; 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) if (Math.Abs(end.X-start.X)<connLength*6.0f)
{ {
wireVertical.DrawTiled(spriteBatch, wireVertical.DrawTiled(spriteBatch,
new Vector2(end.X - wireVertical.size.X / 2, end.Y + connLength), 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(wireVertical.size.X, (float)Math.Abs(end.Y - start.Y)), wireItem.Color * alpha);
textX = (int)end.X; textX = (int)end.X;
connector.Draw(spriteBatch, end, color); connector.Draw(spriteBatch, end, Color.White*alpha);
} }
else else
{ {
Vector2 pos = new Vector2(start.X, end.Y + wireCorner.size.Y) - wireVertical.size / 2; 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)); 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); Rectangle rect = new Rectangle((int)pos.X, (int)pos.Y, (int)size.X, (int)size.Y);
if (!wireEquipped && rect.Contains(PlayerInput.MousePosition)) mouseOn = true; if (!wireEquipped && rect.Contains(PlayerInput.MousePosition)) mouseOn = true;
float dir = (end.X > start.X) ? -1.0f : 1.0f; float dir = (end.X > start.X) ? -1.0f : 1.0f;
wireCorner.Draw(spriteBatch, wireCorner.Draw(spriteBatch,
new Vector2(start.X, end.Y), color, 0.0f, 1.0f, new Vector2(start.X, end.Y), wireItem.Color * alpha, 0.0f, 1.0f,
(end.X > start.X) ? SpriteEffects.None : SpriteEffects.FlipHorizontally); (end.X > start.X) ? SpriteEffects.None : SpriteEffects.FlipHorizontally);
float wireStartX = start.X - wireCorner.size.X / 2 * dir; 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); pos = new Vector2(Math.Min(wireStartX,wireEndX), end.Y - wireVertical.size.Y / 2);
size = new Vector2(Math.Abs(wireStartX - wireEndX), wireHorizontal.size.Y); 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); rect = new Rectangle((int)pos.X, (int)pos.Y, (int)size.X, (int)size.Y);
if (!wireEquipped && rect.Contains(PlayerInput.MousePosition)) mouseOn = true; 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) 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; using System.Xml.Linq;
namespace Subsurface.Items.Components namespace Subsurface.Items.Components
{ {
class LightComponent : ItemComponent class LightComponent : Powered
{ {
private Color lightColor; 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)] [InGameEditable, HasDefaultValue("1.0,1.0,1.0,1.0", true)]
public string LightColor 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) public LightComponent(Item item, XElement element)
: base (item, element) : base (item, element)
{ {
foreach (XElement subElement in element.Elements()) //foreach (XElement subElement in element.Elements())
{ //{
if (subElement.Name.ToString().ToLower() != "sprite") continue; // if (subElement.Name.ToString().ToLower() != "sprite") continue;
sprite = new Sprite(subElement); // sprite = new Sprite(subElement);
break; // break;
} //}
light = new LightSource(item.Position, 100.0f, Color.White);
isActive = true;
//lightColor = new Color(ToolBox.GetAttributeVector4(element, "color", Vector4.One)); //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; base.Update(deltaTime, cam);
sprite.Draw(spriteBatch, new Vector2(item.Position.X, -item.Position.Y), 0.0f, 1.0f, Microsoft.Xna.Framework.Graphics.SpriteEffects.None);
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) public override void ReceiveSignal(string signal, Connection connection, Item sender, float power=0.0f)
{ {
base.ReceiveSignal(signal, connection, sender, power);
switch (connection.Name) switch (connection.Name)
{ {
case "toggle": case "toggle":
+79 -13
View File
@@ -20,7 +20,9 @@ namespace Subsurface.Items.Components
Connection[] connections; Connection[] connections;
private Vector2 newNodePos; private Vector2 newNodePos;
private static int? selectedNodeIndex;
public Wire(Item item, XElement element) public Wire(Item item, XElement element)
: base(item, element) : base(item, element)
{ {
@@ -34,14 +36,14 @@ namespace Subsurface.Items.Components
connections = new Connection[2]; connections = new Connection[2];
} }
public override void Move(Vector2 amount) public override void Move(Vector2 amount)
{ {
amount = FarseerPhysics.ConvertUnits.ToDisplayUnits(amount); amount = FarseerPhysics.ConvertUnits.ToDisplayUnits(amount);
for (int i = 0; i<Nodes.Count; i++) //for (int i = 0; i<Nodes.Count; i++)
{ //{
Nodes[i] += amount; // Nodes[i] += amount;
} //}
} }
public Connection OtherConnection(Connection connection) public Connection OtherConnection(Connection connection)
@@ -151,7 +153,7 @@ namespace Subsurface.Items.Components
position.Y += item.CurrentHull.Rect.Y - item.CurrentHull.Rect.Height; 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) //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) 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) if (newNodePos!= Vector2.Zero && Nodes.Count>0 && Vector2.Distance(newNodePos, Nodes[Nodes.Count - 1]) > nodeDistance)
{ {
Nodes.Add(newNodePos); Nodes.Add(newNodePos);
newNodePos = Vector2.Zero; newNodePos = Vector2.Zero;
} }
return true; 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() private void CleanNodes()
{ {
for (int i = Nodes.Count - 2; i > 0; i--) 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; if (Nodes.Count == 0) return;
@@ -257,15 +275,63 @@ namespace Subsurface.Items.Components
for (int i = 1; i < Nodes.Count; i++) 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) 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); //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) private void DrawSection(SpriteBatch spriteBatch, Vector2 start, Vector2 end, int i, Color color)
+1 -1
View File
@@ -79,7 +79,7 @@ namespace Subsurface.Items.Components
ToolBox.GetAttributeVector2(element, "origin", Vector2.Zero)); 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); barrelSprite.Draw(spriteBatch, new Vector2(item.Rect.X, -item.Rect.Y) + barrelPos, rotation + MathHelper.PiOver2, 1.0f);
} }
+3 -3
View File
@@ -256,14 +256,14 @@ namespace Subsurface
if (item == null) return; 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) 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.X = (int)pos.X;
pos.Y = (int)pos.Y; 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); spriteBatch.DrawString(GUI.Font, item.Name + " - " + item.ID, pos, Color.White);
} }
+49 -36
View File
@@ -82,6 +82,21 @@ namespace Subsurface
get { return condition; } 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)] [Editable, HasDefaultValue("", true)]
public string Tags public string Tags
@@ -497,7 +512,7 @@ namespace Subsurface
public override void Draw(SpriteBatch spriteBatch, bool editing) 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 (isHighlighted) color = Color.Orange;
if (body==null) if (body==null)
@@ -506,10 +521,10 @@ namespace Subsurface
} }
else if (body.Enabled) 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)) if (!editing || (body!=null && !body.Enabled))
{ {
@@ -912,8 +927,16 @@ namespace Subsurface
XElement element = new XElement("Item"); XElement element = new XElement("Item");
element.Add(new XAttribute("name", prefab.Name), element.Add(new XAttribute("name", prefab.Name),
new XAttribute("ID", ID), new XAttribute("ID", ID));
new XAttribute("rect", rect.X + "," + rect.Y+","+rect.Width+","+rect.Height));
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) if (linkedTo != null && linkedTo.Count>0)
{ {
@@ -930,32 +953,6 @@ namespace Subsurface
ObjectProperty.SaveProperties(this, element); 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) foreach (ItemComponent ic in components)
{ {
ic.Save(element); ic.Save(element);
@@ -970,12 +967,22 @@ namespace Subsurface
{ {
string rectString = ToolBox.GetAttributeString(element, "rect", "0,0,0,0"); string rectString = ToolBox.GetAttributeString(element, "rect", "0,0,0,0");
string[] rectValues = rectString.Split(','); 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; string name = element.Attribute("name").Value;
@@ -986,6 +993,12 @@ namespace Subsurface
if (ip.Name != name) continue; 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 item = new Item(rect, ip);
item.ID = int.Parse(element.Attribute("ID").Value); item.ID = int.Parse(element.Attribute("ID").Value);
+6 -1
View File
@@ -11,7 +11,7 @@ namespace Subsurface
{ {
class ItemPrefab : MapEntityPrefab class ItemPrefab : MapEntityPrefab
{ {
static string contentFolder = "Content/Items/"; //static string contentFolder = "Content/Items/";
string configFile; string configFile;
@@ -55,6 +55,11 @@ namespace Subsurface
get { return offsetOnSelected; } get { return offsetOnSelected; }
} }
public Vector2 Size
{
get { return size; }
}
public override void UpdatePlacing(SpriteBatch spriteBatch, Camera cam) public override void UpdatePlacing(SpriteBatch spriteBatch, Camera cam)
{ {
Vector2 position = Submarine.MouseToWorldGrid(cam); Vector2 position = Submarine.MouseToWorldGrid(cam);
+61
View 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);
}
}
}
+114 -3
View File
@@ -1,5 +1,6 @@
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using System.Collections.Generic;
namespace Subsurface.Lights namespace Subsurface.Lights
{ {
@@ -7,16 +8,126 @@ namespace Subsurface.Lights
{ {
public static Vector2 ViewPos; 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; if (!FowEnabled) return;
foreach (ConvexHull convexHull in ConvexHull.list) 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; }
} }
} }
+10 -8
View File
@@ -22,9 +22,9 @@ namespace Subsurface
private int seed; private int seed;
private int size; private int size;
private Texture2D iceTexture; private static Texture2D iceTexture;
private Texture2D iceCraters; private static Texture2D iceCraters;
private Texture2D iceCrack; private static Texture2D iceCrack;
private Location currentLocation; private Location currentLocation;
private Location selectedLocation; private Location selectedLocation;
@@ -61,9 +61,9 @@ namespace Subsurface
connections = new List<LocationConnection>(); connections = new List<LocationConnection>();
iceTexture = Game1.TextureLoader.FromFile("Content/Map/iceSurface.png"); if (iceTexture==null) iceTexture = Game1.TextureLoader.FromFile("Content/Map/iceSurface.png");
iceCraters = Game1.TextureLoader.FromFile("Content/Map/iceCraters.png"); if (iceCraters == null) iceCraters = Game1.TextureLoader.FromFile("Content/Map/iceCraters.png");
iceCrack = Game1.TextureLoader.FromFile("Content/Map/iceCrack.png"); if (iceCrack == null) iceCrack = Game1.TextureLoader.FromFile("Content/Map/iceCrack.png");
Rand.SetSyncedSeed(this.seed); Rand.SetSyncedSeed(this.seed);
@@ -151,14 +151,16 @@ namespace Subsurface
for (int i = connections.Count - 1; i >= 0; i--) for (int i = connections.Count - 1; i >= 0; i--)
{ {
i = Math.Min(i, connections.Count - 1);
LocationConnection connection = connections[i]; 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]) if (connection.Locations.Contains(connections[n].Locations[0])
&& connection.Locations.Contains(connections[n].Locations[1])) && connection.Locations.Contains(connections[n].Locations[1]))
{ {
connections.RemoveAt(i); connections.RemoveAt(n);
} }
} }
} }
+35 -4
View File
@@ -37,6 +37,21 @@ namespace Subsurface
protected bool isSelected; 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 public bool MoveWithLevel
{ {
get; get;
@@ -174,6 +189,12 @@ namespace Subsurface
{ {
if (GUIComponent.MouseOn != null) return; if (GUIComponent.MouseOn != null) return;
if (DisableSelect)
{
DisableSelect = false;
return;
}
foreach (MapEntity e in mapEntityList) foreach (MapEntity e in mapEntityList)
{ {
e.isHighlighted = false; e.isHighlighted = false;
@@ -189,8 +210,7 @@ namespace Subsurface
if (PlayerInput.GetKeyboardState.IsKeyDown(Keys.Delete)) if (PlayerInput.GetKeyboardState.IsKeyDown(Keys.Delete))
{ {
foreach (MapEntity e in selectedList) foreach (MapEntity e in selectedList) e.Remove();
e.Remove();
selectedList.Clear(); selectedList.Clear();
} }
@@ -209,7 +229,7 @@ namespace Subsurface
e.isSelected = false; e.isSelected = false;
} }
if (highLightedEntity!=null) if (highLightedEntity != null)
highLightedEntity.isHighlighted = true; highLightedEntity.isHighlighted = true;
foreach (MapEntity e in selectedList) foreach (MapEntity e in selectedList)
@@ -269,7 +289,6 @@ namespace Subsurface
foreach (MapEntity e2 in selectedList) foreach (MapEntity e2 in selectedList)
{ {
Debug.WriteLine(e.ID+", "+e2.ID);
if (e.ID == e2.ID) alreadySelected = true; if (e.ID == e2.ID) alreadySelected = true;
} }
@@ -359,6 +378,18 @@ namespace Subsurface
editingHUD = null; 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) {} public virtual void DrawEditing(SpriteBatch spriteBatch, Camera cam) {}
+9 -3
View File
@@ -25,9 +25,7 @@ namespace Subsurface
//is it possible to stretch the entity horizontally/vertically //is it possible to stretch the entity horizontally/vertically
protected bool resizeHorizontal; protected bool resizeHorizontal;
protected bool resizeVertical; protected bool resizeVertical;
//which prefab has been selected for placing //which prefab has been selected for placing
protected static MapEntityPrefab selected; protected static MapEntityPrefab selected;
@@ -46,7 +44,15 @@ namespace Subsurface
get { return isLinkable; } get { return isLinkable; }
} }
public bool ResizeHorizontal
{
get { return resizeHorizontal; }
}
public bool ResizeVertical
{
get { return resizeVertical; }
}
public static void Init() public static void Init()
{ {
+1
View File
@@ -825,6 +825,7 @@ namespace Subsurface
foreach (Item item in Item.itemList) foreach (Item item in Item.itemList)
{ {
System.Diagnostics.Debug.WriteLine(item.ID);
foreach (ItemComponent ic in item.components) foreach (ItemComponent ic in item.components)
{ {
ic.OnMapLoaded(); ic.OnMapLoaded();
+4 -4
View File
@@ -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. // Create new instance of configs. Parameter is "application Id". It has to be same on client and server.
NetPeerConfiguration Config = new NetPeerConfiguration("subsurface"); NetPeerConfiguration Config = new NetPeerConfiguration("subsurface");
//Config.SimulatedLoss = 0.2f; Config.SimulatedLoss = 0.2f;
//Config.SimulatedMinimumLatency = 0.25f; Config.SimulatedMinimumLatency = 0.25f;
// Create new client, with previously created configs // Create new client, with previously created configs
client = new NetClient(Config); client = new NetClient(Config);
@@ -541,8 +541,8 @@ namespace Subsurface.Networking
break; break;
} }
int byteCount = Rand.Int(100); int bitCount = Rand.Int(100);
for (int i = 0; i<byteCount; i++) for (int i = 0; i<bitCount; i++)
{ {
msg.Write((Rand.Int(2)==0) ? true : false); msg.Write((Rand.Int(2)==0) ? true : false);
} }
+43 -3
View File
@@ -56,6 +56,11 @@ namespace Subsurface.Networking
public override void Update() public override void Update()
{ {
if (PlayerInput.KeyDown(Microsoft.Xna.Framework.Input.Keys.K))
{
SendRandomData();
}
if (gameStarted) inGameHUD.Update((float)Physics.step); if (gameStarted) inGameHUD.Update((float)Physics.step);
NetIncomingMessage inc = Server.ReadMessage(); 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; sparseUpdateTimer = DateTime.Now + SparseUpdateInterval;
} }
@@ -534,8 +539,6 @@ namespace Subsurface.Networking
return true; return true;
} }
public override void SendChatMessage(string message, ChatMessageType type = ChatMessageType.Server) public override void SendChatMessage(string message, ChatMessageType type = ChatMessageType.Server)
{ {
AddChatMessage(message, type); AddChatMessage(message, type);
@@ -701,6 +704,43 @@ namespace Subsurface.Networking
return preferredClient; 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() public override void Disconnect()
{ {
Server.Shutdown(""); Server.Shutdown("");
+17 -5
View File
@@ -255,16 +255,28 @@ namespace Subsurface
if (characterMode) 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) if (PlayerInput.GetMouseState.LeftButton != ButtonState.Pressed)
+19 -1
View File
@@ -147,6 +147,14 @@ namespace Subsurface
public void DrawMap(GraphicsDevice graphics, SpriteBatch spriteBatch) 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 //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); 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);
} }
} }
} }
+89 -38
View File
@@ -148,7 +148,7 @@ namespace Subsurface
public override void Select() public override void Select()
{ {
Lights.LightManager.FowEnabled = false; Game1.LightManager.FowEnabled = false;
infoFrame.ClearChildren(); infoFrame.ClearChildren();
@@ -215,21 +215,23 @@ namespace Subsurface
seedBox.Enabled = (Game1.Server != null); seedBox.Enabled = (Game1.Server != null);
LevelSeed = ToolBox.RandomSeed(8); LevelSeed = ToolBox.RandomSeed(8);
var serverName = new GUITextBlock(new Rectangle(0, 0, 200, 30), var serverName = new GUITextBox(new Rectangle(0, 0, 200, 20), null, null, Alignment.TopLeft, Alignment.TopLeft, GUI.style, infoFrame);
"Server: ", GUI.style, Alignment.Left, Alignment.TopLeft, infoFrame);
serverName.TextGetter = GetServerName; 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); 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.Wrap = true;
serverMessage.TextGetter = GetServerMessage;
serverMessage.OnTextChanged = UpdateServerMessage;
if (IsServer && Game1.Server != null) if (IsServer && Game1.Server != null)
{ {
GUIButton startButton = new GUIButton(new Rectangle(0, 0, 200, 30), "Start", Alignment.TopRight, GUI.style, infoFrame); GUIButton startButton = new GUIButton(new Rectangle(0, 0, 200, 30), "Start", Alignment.TopRight, GUI.style, infoFrame);
startButton.OnClicked = Game1.Server.StartGame; startButton.OnClicked = Game1.Server.StartGame;
serverMessage.Enabled = true;
//mapList.OnSelected = new GUIListBox.OnSelectedHandler(Game1.server.UpdateNetLobby); //mapList.OnSelected = new GUIListBox.OnSelectedHandler(Game1.server.UpdateNetLobby);
modeList.OnSelected = Game1.Server.UpdateNetLobby; modeList.OnSelected = Game1.Server.UpdateNetLobby;
durationBar.OnMoved = Game1.Server.UpdateNetLobby; durationBar.OnMoved = Game1.Server.UpdateNetLobby;
@@ -301,6 +303,24 @@ namespace Subsurface
return true; 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) public void AddPlayer(Client client)
{ {
@@ -539,6 +559,7 @@ namespace Subsurface
} }
msg.Write(ServerName); msg.Write(ServerName);
msg.Write(ServerMessage);
msg.Write(modeList.SelectedIndex-1); msg.Write(modeList.SelectedIndex-1);
msg.Write(durationBar.BarScroll); msg.Write(durationBar.BarScroll);
@@ -558,50 +579,80 @@ namespace Subsurface
public void ReadData(NetIncomingMessage msg) public void ReadData(NetIncomingMessage msg)
{ {
string mapName = msg.ReadString(); string mapName="", md5Hash="";
string md5Hash = msg.ReadString();
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); TrySelectMap(mapName, md5Hash);
ServerName = msg.ReadString(); modeList.Select(modeIndex);
//mapList.Select(msg.ReadInt32()); durationBar.BarScroll = durationScroll;
modeList.Select(msg.ReadInt32());
durationBar.BarScroll = msg.ReadFloat(); LevelSeed = levelSeed;
LevelSeed = msg.ReadString(); try
int playerCount = msg.ReadInt32();
for (int i = 0; i < playerCount; i++)
{ {
int clientID = msg.ReadInt32(); int playerCount = msg.ReadInt32();
string jobName = msg.ReadString();
for (int i = 0; i < playerCount; i++)
Client client = null;
GUITextBlock textBlock = null;
foreach (GUIComponent child in playerList.children)
{ {
Client tempClient = child.UserData as Client; int clientID = msg.ReadInt32();
if (tempClient == null || tempClient.ID != clientID) continue; string jobName = msg.ReadString();
client = tempClient;
textBlock = child as GUITextBlock;
break;
}
if (client == null) continue;
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) if (clientID == Game1.Client.ID)
{ {
Game1.Client.CharacterInfo.Job = new Job(client.assignedJob); Game1.Client.CharacterInfo.Job = new Job(client.assignedJob);
Game1.Client.CharacterInfo.Name = client.name; Game1.Client.CharacterInfo.Name = client.name;
UpdatePreviewPlayer(Game1.Client.CharacterInfo); UpdatePreviewPlayer(Game1.Client.CharacterInfo);
}
} }
} }
catch
{
return;
}
} }
} }
+21
View File
@@ -68,6 +68,7 @@
<Compile Include="CoroutineManager.cs" /> <Compile Include="CoroutineManager.cs" />
<Compile Include="GUI\TitleScreen.cs" /> <Compile Include="GUI\TitleScreen.cs" />
<Compile Include="Items\FixRequirement.cs" /> <Compile Include="Items\FixRequirement.cs" />
<Compile Include="Map\Lights\Light.cs" />
<Compile Include="Map\LocationType.cs" /> <Compile Include="Map\LocationType.cs" />
<Compile Include="Utils\Rand.cs" /> <Compile Include="Utils\Rand.cs" />
<Compile Include="Events\PropertyTask.cs" /> <Compile Include="Events\PropertyTask.cs" />
@@ -272,6 +273,13 @@
<Content Include="Content\Characters\Human\torso.png"> <Content Include="Content\Characters\Human\torso.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </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"> <Content Include="Content\Jobs.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<SubType>Designer</SubType> <SubType>Designer</SubType>
@@ -380,6 +388,12 @@
<Content Include="Content\Items\Pump\pump.png"> <Content Include="Content\Items\Pump\pump.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </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"> <Content Include="Content\Map\iceCrack.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
@@ -679,6 +693,10 @@
<None Include="Content\Items\Weapons\stunGrenade.ogg"> <None Include="Content\Items\Weapons\stunGrenade.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
<None Include="Content\Lights\AlphaOne.dds" />
<None Include="Content\SmallFont.xnb">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\Sounds\Damage\HitArmor1.ogg"> <None Include="Content\Sounds\Damage\HitArmor1.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
@@ -763,6 +781,9 @@
<None Include="Content\Sounds\Damage\StructureCrunch3.ogg"> <None Include="Content\Sounds\Damage\StructureCrunch3.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
<None Include="Content\SpriteFont1.xnb">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\step.ogg"> <None Include="Content\step.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
+1 -1
View File
@@ -9,6 +9,6 @@
<ErrorReportUrlHistory /> <ErrorReportUrlHistory />
<FallbackCulture>en-US</FallbackCulture> <FallbackCulture>en-US</FallbackCulture>
<VerifyUploadedFiles>false</VerifyUploadedFiles> <VerifyUploadedFiles>false</VerifyUploadedFiles>
<ProjectView>ProjectFiles</ProjectView> <ProjectView>ShowAllFiles</ProjectView>
</PropertyGroup> </PropertyGroup>
</Project> </Project>
+5 -24
View File
@@ -18,38 +18,19 @@ namespace Subsurface
public static float Range(float minimum, float maximum, bool local = true) public static float Range(float minimum, float maximum, bool local = true)
{ {
if (local) return (float)(local ? localRandom : syncedRandom).NextDouble() * (maximum - minimum) + minimum;
{
return (float)localRandom.NextDouble() * (maximum - minimum) + minimum;
}
else
{
return (float)syncedRandom.NextDouble() * (maximum - minimum) + minimum;
}
} }
public static int Range(int minimum, int maximum, bool local = true) public static int Range(int minimum, int maximum, bool local = true)
{ {
if (local) return (local ? localRandom : syncedRandom).Next(maximum - minimum) + minimum;
{
return localRandom.Next(maximum - minimum) + minimum;
}
else
{
return syncedRandom.Next(maximum - minimum) + minimum;
}
} }
public static int Int(int max = int.MaxValue, bool local = true) public static int Int(int max = int.MaxValue, bool local = true)
{ {
if (local) return (local ? localRandom : syncedRandom).Next(max);
{
return localRandom.Next(max);
}
else
{
return syncedRandom.Next(max);
}
} }
public static Vector2 Vector(float length = 1.0f, bool local = true) public static Vector2 Vector(float length = 1.0f, bool local = true)
Binary file not shown.