Functional networkevent validation, functional single player saving, requireditem ui texts, titlescreen & loading

This commit is contained in:
Regalis
2015-07-19 02:44:42 +03:00
parent 237df18765
commit baa207985c
78 changed files with 1237 additions and 596 deletions
@@ -37,17 +37,19 @@ namespace Subsurface.Items.Components
if (picker == null) return false;
if (picker.Inventory == null) return false;
this.picker = picker;
//this.picker = picker;
for (int i = item.linkedTo.Count - 1; i >= 0; i--)
item.linkedTo[i].RemoveLinked(item);
item.linkedTo.Clear();
if (picker.Inventory.TryPutItem(item, allowedSlots))
{
if (!picker.HasSelectedItem(item) && item.body!=null) item.body.Enabled = false;
this.picker = picker;
for (int i = item.linkedTo.Count - 1; i >= 0; i--)
item.linkedTo[i].RemoveLinked(item);
item.linkedTo.Clear();
ApplyStatusEffects(ActionType.OnPicked, 1.0f, picker);
//foreach (StatusEffect effect in item.Prefab.statusEffects)
@@ -94,22 +94,16 @@ namespace Subsurface.Items.Components
projectile.body.ApplyTorque(projectile.body.Mass * Rand.Range(-10.0f, 10.0f));
//recoil
item.body.ApplyLinearImpulse(
new Vector2((float)Math.Cos(projectile.body.Rotation), (float)Math.Sin(projectile.body.Rotation)) * item.body.Mass * -10.0f);
if (Rand.Int(2) == 0)
{
item.Drop(character);
item.body.ApplyTorque(projectile.body.Mass * Rand.Range(-10.0f, 10.0f));
}
//item.body.ApplyLinearImpulse(
// new Vector2((float)Math.Cos(projectile.body.Rotation), (float)Math.Sin(projectile.body.Rotation)) * item.body.Mass * -10.0f);
}
else
{
projectileComponent.ignoredBodies = limbBodies;
//recoil
item.body.ApplyLinearImpulse(
new Vector2((float)Math.Cos(projectile.body.Rotation), (float)Math.Sin(projectile.body.Rotation)) * -item.body.Mass);
//item.body.ApplyLinearImpulse(
// new Vector2((float)Math.Cos(projectile.body.Rotation), (float)Math.Sin(projectile.body.Rotation)) * -item.body.Mass);
}
item.RemoveContained(projectile);
+15 -8
View File
@@ -393,6 +393,7 @@ namespace Subsurface
if (containedItem == null)
{
//if (addMessage && !String.IsNullOrEmpty(ri.Msg)) GUI.AddMessage(ri.Msg, Color.Red);
if (addMessage && !string.IsNullOrEmpty(ri.Msg)) GUI.AddMessage(ri.Msg, Color.Red);
return false;
}
}
@@ -403,9 +404,7 @@ namespace Subsurface
public bool HasRequiredItems(Character character, bool addMessage)
{
if (!requiredItems.Any()) return true;
foreach (RelatedItem ri in requiredItems)
{
if (!ri.Type.HasFlag(RelatedItem.RelationType.Equipped) && !ri.Type.HasFlag(RelatedItem.RelationType.Picked)) continue;
@@ -419,7 +418,11 @@ namespace Subsurface
{
if (character.Inventory.items.FirstOrDefault(x => x!=null && x.Condition>0.0f && ri.MatchesItem(x))!=null) hasItem = true;
}
if (!hasItem) return false;
if (!hasItem)
{
if (addMessage && !string.IsNullOrEmpty(ri.Msg)) GUI.AddMessage(ri.Msg, Color.Red);
return false;
}
}
return true;
@@ -484,7 +487,7 @@ namespace Subsurface
{
if (componentElement == null) return;
bool requiredItemsCleared = false;
foreach (XAttribute attribute in componentElement.Attributes())
{
@@ -494,6 +497,9 @@ namespace Subsurface
property.TrySetValue(attribute.Value);
}
List<RelatedItem> prevRequiredItems = new List<RelatedItem>(requiredItems);
requiredItems.Clear();
foreach (XElement subElement in componentElement.Elements())
{
switch (subElement.Name.ToString().ToLower())
@@ -503,10 +509,11 @@ namespace Subsurface
if (newRequiredItem == null) continue;
if (!requiredItemsCleared)
var prevRequiredItem = prevRequiredItems.Find(ri => ri.JoinedNames == newRequiredItem.JoinedNames);
if (prevRequiredItem!=null)
{
requiredItems.Clear();
requiredItemsCleared = true;
newRequiredItem.statusEffects = prevRequiredItem.statusEffects;
newRequiredItem.Msg = prevRequiredItem.Msg;
}
requiredItems.Add(newRequiredItem);
@@ -87,7 +87,7 @@ namespace Subsurface.Items.Components
//GUI.DrawRectangle(spriteBatch, new Rectangle(x, y, width, height), Color.Black, true);
spriteBatch.DrawString(GUI.font, "Force: " + (int)(targetForce) + " %", new Vector2(GuiFrame.Rect.X + 30, GuiFrame.Rect.Y + 30), Color.White);
spriteBatch.DrawString(GUI.Font, "Force: " + (int)(targetForce) + " %", new Vector2(GuiFrame.Rect.X + 30, GuiFrame.Rect.Y + 30), Color.White);
if (GUI.DrawButton(spriteBatch, new Rectangle(GuiFrame.Rect.X + 280, GuiFrame.Rect.Y + 30, 40, 40), "+", true)) targetForce += 1.0f;
if (GUI.DrawButton(spriteBatch, new Rectangle(GuiFrame.Rect.X + 280, GuiFrame.Rect.Y + 80, 40, 40), "-", true)) targetForce -= 1.0f;
@@ -310,12 +310,12 @@ namespace Subsurface.Items.Components
GUI.DrawRectangle(spriteBatch, new Rectangle(x, y, width, height), Color.Black, true);
spriteBatch.DrawString(GUI.font, "Temperature: " + (int)temperature + " C", new Vector2(x + 30, y + 30), Color.White);
spriteBatch.DrawString(GUI.Font, "Temperature: " + (int)temperature + " C", new Vector2(x + 30, y + 30), Color.White);
DrawGraph(tempGraph, spriteBatch, x + 30, y + 50, 10000.0f, xOffset);
y += 130;
spriteBatch.DrawString(GUI.font, "Fission rate: " + (int)fissionRate + " %", new Vector2(x + 30, y + 30), Color.White);
spriteBatch.DrawString(GUI.Font, "Fission rate: " + (int)fissionRate + " %", new Vector2(x + 30, y + 30), Color.White);
DrawGraph(fissionRateGraph, spriteBatch, x + 30, y + 50, 100.0f, xOffset);
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 280, y + 30, 40, 40), "+", true)) FissionRate += 1.0f;
@@ -323,7 +323,7 @@ namespace Subsurface.Items.Components
y += 130;
spriteBatch.DrawString(GUI.font, "Cooling rate: " + (int)coolingRate + " %", new Vector2(x + 30, y + 30), Color.White);
spriteBatch.DrawString(GUI.Font, "Cooling rate: " + (int)coolingRate + " %", new Vector2(x + 30, y + 30), Color.White);
DrawGraph(coolingRateGraph, spriteBatch, x + 30, y + 50, 100.0f, xOffset);
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 280, y + 30, 40, 40), "+", true)) CoolingRate += 1.0f;
@@ -331,10 +331,10 @@ namespace Subsurface.Items.Components
y = y - 260;
spriteBatch.DrawString(GUI.font, "Autotemp: " + ((autoTemp) ? "ON" : "OFF"), new Vector2(x + 400, y + 30), Color.White);
spriteBatch.DrawString(GUI.Font, "Autotemp: " + ((autoTemp) ? "ON" : "OFF"), new Vector2(x + 400, y + 30), Color.White);
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 400, y + 60, 100, 40), ((autoTemp) ? "TURN OFF" : "TURN ON"))) autoTemp = !autoTemp;
spriteBatch.DrawString(GUI.font, "Max temperature: " + shutDownTemp, new Vector2(x + 400, y + 150), Color.White);
spriteBatch.DrawString(GUI.Font, "Max temperature: " + shutDownTemp, new Vector2(x + 400, y + 150), Color.White);
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 400, y + 180, 40, 40), "+", true)) shutDownTemp += 100.0f;
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 450, y + 180, 40, 40), "-", true)) shutDownTemp -= 100.0f;
@@ -24,6 +24,11 @@ namespace Subsurface.Items.Components
get { return targetVelocity;}
set
{
if (float.IsNaN(value.X) || float.IsNaN(value.Y))
{
targetVelocity = Vector2.Zero;
return;
}
targetVelocity.X = MathHelper.Clamp(value.X, -100.0f, 100.0f);
targetVelocity.Y = MathHelper.Clamp(value.Y, -100.0f, 100.0f);
}
@@ -38,7 +38,11 @@ namespace Subsurface.Items.Components
public float Charge
{
get { return charge; }
set { charge = MathHelper.Clamp(value, 0.0f, capacity); }
set
{
if (float.IsNaN(value)) return;
charge = MathHelper.Clamp(value, 0.0f, capacity);
}
}
@@ -49,12 +53,15 @@ namespace Subsurface.Items.Components
set { capacity = Math.Max(value,1.0f); }
}
//[HasDefaultValue(10.0f, false)]
//public float MaxInput
//{
// get { return maxInput; }
// set { maxInput = value; }
//}
public float RechargeSpeed
{
get { return rechargeSpeed; }
set
{
if (float.IsNaN(value)) return;
rechargeSpeed = MathHelper.Clamp(rechargeSpeed, 0.0f, maxRechargeSpeed);
}
}
[HasDefaultValue(10.0f, false)]
public float MaxRechargeSpeed
@@ -188,16 +195,38 @@ namespace Subsurface.Items.Components
GUI.DrawRectangle(spriteBatch, new Rectangle(x, y, width, height), Color.Black, true);
spriteBatch.DrawString(GUI.font,
spriteBatch.DrawString(GUI.Font,
"Charge: " + (int)charge + "/" + (int)capacity + " (" + (int)((charge / capacity) * 100.0f) + " %)",
new Vector2(x + 30, y + 30), Color.White);
spriteBatch.DrawString(GUI.font, "Recharge rate: " + (rechargeSpeed / maxRechargeSpeed), new Vector2(x + 30, y + 100), Color.White);
spriteBatch.DrawString(GUI.Font, "Recharge rate: " + (rechargeSpeed / maxRechargeSpeed), new Vector2(x + 30, y + 100), Color.White);
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 50, y + 150, 40, 40), "+", true))
rechargeSpeed = Math.Min(rechargeSpeed + 10.0f, maxRechargeSpeed);
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 250, y + 150, 40, 40), "-", true))
rechargeSpeed = Math.Max(rechargeSpeed - 10.0f, 0.0f);
}
public override void FillNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetOutgoingMessage message)
{
message.Write(rechargeSpeed);
message.Write(charge);
}
public override void ReadNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetIncomingMessage message)
{
float newRechargeSpeed = 0.0f;
float newCharge = 0.0f;
try
{
newRechargeSpeed = message.ReadFloat();
newCharge = message.ReadFloat();
}
catch { }
RechargeSpeed = newRechargeSpeed;
Charge = newCharge;
}
}
}
@@ -133,8 +133,8 @@ namespace Subsurface.Items.Components
GUI.DrawRectangle(spriteBatch, new Rectangle(x, y, width, height), Color.Black, true);
spriteBatch.DrawString(GUI.font, "Power: " + (int)(-currPowerConsumption), new Vector2(x + 30, y + 30), Color.White);
spriteBatch.DrawString(GUI.font, "Load: " + (int)powerLoad, new Vector2(x + 30, y + 100), Color.White);
spriteBatch.DrawString(GUI.Font, "Power: " + (int)(-currPowerConsumption), new Vector2(x + 30, y + 30), Color.White);
spriteBatch.DrawString(GUI.Font, "Load: " + (int)powerLoad, new Vector2(x + 30, y + 100), Color.White);
}
public override void ReceiveSignal(string signal, Connection connection, Item sender, float power)
@@ -274,7 +274,7 @@ namespace Subsurface.Items.Components
private void Draw(SpriteBatch spriteBatch, Item item, Vector2 position, Vector2 labelPos, Vector2 wirePosition, bool mouseIn, bool wireEquipped)
{
spriteBatch.DrawString(GUI.font, Name, new Vector2(labelPos.X, labelPos.Y-10), Color.White);
spriteBatch.DrawString(GUI.Font, Name, new Vector2(labelPos.X, labelPos.Y-10), Color.White);
GUI.DrawRectangle(spriteBatch, new Rectangle((int)position.X-10, (int)position.Y-10, 20, 20), Color.White);
@@ -386,11 +386,11 @@ namespace Subsurface.Items.Components
}
}
spriteBatch.DrawString(GUI.font, item.Name,
spriteBatch.DrawString(GUI.Font, item.Name,
new Vector2(textX, start.Y-30),
(mouseOn && !wireEquipped) ? Color.Gold : Color.White,
MathHelper.PiOver2,
GUI.font.MeasureString(item.Name)*0.5f,
GUI.Font.MeasureString(item.Name)*0.5f,
1.0f, SpriteEffects.None, 0.0f);
}