Functional networkevent validation, functional single player saving, requireditem ui texts, titlescreen & loading
This commit is contained in:
@@ -74,7 +74,20 @@ namespace Subsurface
|
||||
//the name of the species (e.q. human)
|
||||
public readonly string SpeciesName;
|
||||
|
||||
public CharacterInfo Info;
|
||||
private CharacterInfo info;
|
||||
|
||||
public CharacterInfo Info
|
||||
{
|
||||
get
|
||||
{
|
||||
return info;
|
||||
}
|
||||
set
|
||||
{
|
||||
info = value;
|
||||
if (info != null) info.Character = this;
|
||||
}
|
||||
}
|
||||
|
||||
protected float soundTimer;
|
||||
protected float soundInterval;
|
||||
@@ -366,6 +379,17 @@ namespace Subsurface
|
||||
}
|
||||
}
|
||||
|
||||
if (Info.PickedItemIDs.Any())
|
||||
{
|
||||
foreach (int id in Info.PickedItemIDs)
|
||||
{
|
||||
Item item = FindEntityByID(id) as Item;
|
||||
if (item == null) continue;
|
||||
|
||||
item.Pick(this);
|
||||
}
|
||||
}
|
||||
|
||||
AnimController.FindHull();
|
||||
|
||||
//if (info.ID >= 0)
|
||||
@@ -525,18 +549,21 @@ namespace Subsurface
|
||||
|
||||
cursorPosition = cam.ScreenToWorld(PlayerInput.MousePosition);
|
||||
Vector2 mouseSimPos = ConvertUnits.ToSimUnits(cursorPosition);
|
||||
|
||||
Body body = Submarine.PickBody(AnimController.limbs[0].SimPosition, mouseSimPos);
|
||||
Structure structure = null;
|
||||
if (body != null) structure = body.UserData as Structure;
|
||||
if (structure!=null)
|
||||
if (Vector2.Distance(AnimController.limbs[0].SimPosition, mouseSimPos)>1.0f)
|
||||
{
|
||||
if (!structure.CastShadow && moveCam)
|
||||
Body body = Submarine.PickBody(AnimController.limbs[0].SimPosition, mouseSimPos);
|
||||
Structure structure = null;
|
||||
if (body != null) structure = body.UserData as Structure;
|
||||
if (structure!=null)
|
||||
{
|
||||
cam.OffsetAmount = MathHelper.Lerp(cam.OffsetAmount, 500.0f, 0.05f);
|
||||
if (!structure.CastShadow && moveCam)
|
||||
{
|
||||
cam.OffsetAmount = MathHelper.Lerp(cam.OffsetAmount, 500.0f, 0.05f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (AnimController.onGround &&
|
||||
!AnimController.InWater &&
|
||||
AnimController.Anim != AnimController.Animation.UsingConstruction)
|
||||
@@ -664,14 +691,19 @@ namespace Subsurface
|
||||
|
||||
if (IsNetworkPlayer)
|
||||
{
|
||||
Vector2 namePos = new Vector2(Position.X, -Position.Y - 80.0f) - GUI.font.MeasureString(Info.Name) * 0.5f;
|
||||
spriteBatch.DrawString(GUI.font, Info.Name, namePos - new Vector2(1.0f, 1.0f), Color.Black);
|
||||
spriteBatch.DrawString(GUI.font, Info.Name, namePos, Color.White);
|
||||
Vector2 namePos = new Vector2(Position.X, -Position.Y - 80.0f) - GUI.Font.MeasureString(Info.Name) * 0.5f;
|
||||
spriteBatch.DrawString(GUI.Font, Info.Name, namePos - new Vector2(1.0f, 1.0f), Color.Black);
|
||||
spriteBatch.DrawString(GUI.Font, Info.Name, namePos, Color.White);
|
||||
|
||||
if (Game1.DebugDraw)
|
||||
{
|
||||
spriteBatch.DrawString(GUI.Font, ID.ToString(), namePos - new Vector2(0.0f, 20.0f), Color.White);
|
||||
}
|
||||
}
|
||||
|
||||
Vector2 pos = ConvertUnits.ToDisplayUnits(AnimController.limbs[0].SimPosition);
|
||||
pos.Y = -pos.Y;
|
||||
spriteBatch.DrawString(GUI.font, ID.ToString(), pos, Color.White);
|
||||
|
||||
|
||||
if (this == Character.controlled) return;
|
||||
|
||||
@@ -714,18 +746,18 @@ namespace Subsurface
|
||||
|
||||
Vector2 textPos = startPos;
|
||||
|
||||
float stringWidth = GUI.font.MeasureString(closestItem.Prefab.Name).X;
|
||||
float stringWidth = GUI.Font.MeasureString(closestItem.Prefab.Name).X;
|
||||
textPos -= new Vector2(stringWidth / 2, 20);
|
||||
spriteBatch.DrawString(GUI.font, closestItem.Prefab.Name, textPos, Color.Black);
|
||||
spriteBatch.DrawString(GUI.font, closestItem.Prefab.Name, textPos + new Vector2(1, -1), Color.Orange);
|
||||
spriteBatch.DrawString(GUI.Font, closestItem.Prefab.Name, textPos, Color.Black);
|
||||
spriteBatch.DrawString(GUI.Font, closestItem.Prefab.Name, textPos + new Vector2(1, -1), Color.Orange);
|
||||
|
||||
textPos.Y += 50.0f;
|
||||
foreach (string text in closestItem.HighlightText)
|
||||
foreach (ColoredText coloredText in closestItem.GetHUDTexts(Controlled))
|
||||
{
|
||||
textPos.X = startPos.X - GUI.font.MeasureString(text).X / 2;
|
||||
textPos.X = startPos.X - GUI.Font.MeasureString(coloredText.text).X / 2;
|
||||
|
||||
spriteBatch.DrawString(GUI.font, text, textPos, Color.Black);
|
||||
spriteBatch.DrawString(GUI.font, text, textPos + new Vector2(1, -1), Color.Orange);
|
||||
spriteBatch.DrawString(GUI.Font, coloredText.text, textPos, Color.Black);
|
||||
spriteBatch.DrawString(GUI.Font, coloredText.text, textPos + new Vector2(1, -1), coloredText.color);
|
||||
|
||||
textPos.Y += 25;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using System.Collections.Generic;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Subsurface
|
||||
@@ -9,12 +10,18 @@ namespace Subsurface
|
||||
{
|
||||
public string Name;
|
||||
|
||||
public Character Character;
|
||||
|
||||
public readonly string File;
|
||||
|
||||
public int HeadSpriteId;
|
||||
|
||||
public Job Job;
|
||||
|
||||
private List<int> pickedItems;
|
||||
|
||||
private Vector2[] headSpriteRange;
|
||||
|
||||
private Gender gender;
|
||||
public Gender Gender
|
||||
{
|
||||
@@ -23,6 +30,17 @@ namespace Subsurface
|
||||
{
|
||||
if (gender == value) return;
|
||||
gender = value;
|
||||
|
||||
int genderIndex = (this.gender == Gender.Female) ? 1 : 0;
|
||||
if (headSpriteRange[genderIndex] != Vector2.Zero)
|
||||
{
|
||||
HeadSpriteId = Rand.Range((int)headSpriteRange[genderIndex].X, (int)headSpriteRange[genderIndex].Y + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
HeadSpriteId = 0;
|
||||
}
|
||||
|
||||
LoadHeadSprite();
|
||||
}
|
||||
}
|
||||
@@ -31,10 +49,10 @@ namespace Subsurface
|
||||
|
||||
public bool StartItemsGiven;
|
||||
|
||||
//public string GenderString()
|
||||
//{
|
||||
// return gender.ToString();
|
||||
//}
|
||||
public List<int> PickedItemIDs
|
||||
{
|
||||
get { return pickedItems; }
|
||||
}
|
||||
|
||||
private Sprite headSprite;
|
||||
public Sprite HeadSprite
|
||||
@@ -50,6 +68,10 @@ namespace Subsurface
|
||||
{
|
||||
this.File = file;
|
||||
|
||||
headSpriteRange = new Vector2[2];
|
||||
|
||||
pickedItems = new List<int>();
|
||||
|
||||
//ID = -1;
|
||||
|
||||
XDocument doc = ToolBox.TryLoadXml(file);
|
||||
@@ -69,19 +91,19 @@ namespace Subsurface
|
||||
this.gender = gender;
|
||||
}
|
||||
}
|
||||
|
||||
Vector2 headSpriteRange = ToolBox.GetAttributeVector2(doc.Root, "headid", Vector2.Zero);
|
||||
if (headSpriteRange == Vector2.Zero)
|
||||
|
||||
headSpriteRange[0] = ToolBox.GetAttributeVector2(doc.Root, "headid", Vector2.Zero);
|
||||
headSpriteRange[1] = headSpriteRange[0];
|
||||
if (headSpriteRange[0] == Vector2.Zero)
|
||||
{
|
||||
headSpriteRange = ToolBox.GetAttributeVector2(
|
||||
doc.Root,
|
||||
this.gender == Gender.Female ? "femaleheadid" : "maleheadid",
|
||||
Vector2.Zero);
|
||||
headSpriteRange[0] = ToolBox.GetAttributeVector2(doc.Root, "maleheadid", Vector2.Zero);
|
||||
headSpriteRange[1] = ToolBox.GetAttributeVector2(doc.Root, "femaleheadid", Vector2.Zero);
|
||||
}
|
||||
|
||||
if (headSpriteRange != Vector2.Zero)
|
||||
int genderIndex = (this.gender == Gender.Female) ? 1 : 0;
|
||||
if (headSpriteRange[genderIndex] != Vector2.Zero)
|
||||
{
|
||||
HeadSpriteId = Rand.Range((int)headSpriteRange.X, (int)headSpriteRange.Y + 1);
|
||||
HeadSpriteId = Rand.Range((int)headSpriteRange[genderIndex].X, (int)headSpriteRange[genderIndex].Y + 1);
|
||||
}
|
||||
|
||||
this.Job = (jobPrefab == null) ? Job.Random() : new Job(jobPrefab);
|
||||
@@ -167,18 +189,40 @@ namespace Subsurface
|
||||
return frame;
|
||||
}
|
||||
|
||||
public void UpdateCharacterItems()
|
||||
{
|
||||
pickedItems.Clear();
|
||||
foreach (Item item in Character.Inventory.items)
|
||||
{
|
||||
if (item == null) continue;
|
||||
pickedItems.Add(item.ID);
|
||||
}
|
||||
}
|
||||
|
||||
public CharacterInfo(XElement element)
|
||||
{
|
||||
Name = ToolBox.GetAttributeString(element, "name", "unnamed");
|
||||
|
||||
string genderStr = ToolBox.GetAttributeString(element, "gender", "male").ToLower();
|
||||
gender = (genderStr == "male") ? Gender.Male : Gender.Female;
|
||||
gender = (genderStr == "m") ? Gender.Male : Gender.Female;
|
||||
|
||||
File = ToolBox.GetAttributeString(element, "file", "");
|
||||
Salary = ToolBox.GetAttributeInt(element, "salary", 1000);
|
||||
HeadSpriteId = ToolBox.GetAttributeInt(element, "headspriteid", 1);
|
||||
StartItemsGiven = ToolBox.GetAttributeBool(element, "startitemsgiven", false);
|
||||
|
||||
pickedItems = new List<int>();
|
||||
|
||||
string pickedItemString = ToolBox.GetAttributeString(element, "items", "");
|
||||
if (!string.IsNullOrEmpty(pickedItemString))
|
||||
{
|
||||
string[] itemIds = pickedItemString.Split(',');
|
||||
foreach (string s in itemIds)
|
||||
{
|
||||
pickedItems.Add(int.Parse(s));
|
||||
}
|
||||
}
|
||||
|
||||
foreach (XElement subElement in element.Elements())
|
||||
{
|
||||
if (subElement.Name.ToString().ToLower() != "job") continue;
|
||||
@@ -195,11 +239,23 @@ namespace Subsurface
|
||||
charElement.Add(
|
||||
new XAttribute("name", Name),
|
||||
new XAttribute("file", File),
|
||||
new XAttribute("gender", gender == Gender.Male ? "male" : "female"),
|
||||
new XAttribute("gender", gender == Gender.Male ? "m" : "f"),
|
||||
new XAttribute("salary", Salary),
|
||||
new XAttribute("headspriteid", HeadSpriteId),
|
||||
new XAttribute("startitemsgiven", StartItemsGiven));
|
||||
|
||||
if (Character!=null && Character.Inventory!=null)
|
||||
{
|
||||
UpdateCharacterItems();
|
||||
}
|
||||
|
||||
if (pickedItems.Count>0)
|
||||
{
|
||||
charElement.Add(new XAttribute("items", string.Join(",", pickedItems)));
|
||||
}
|
||||
|
||||
|
||||
|
||||
Job.Save(charElement);
|
||||
|
||||
parentElement.Add(charElement);
|
||||
|
||||
@@ -336,8 +336,8 @@ namespace Subsurface
|
||||
Limb head = GetLimb(LimbType.Head);
|
||||
Limb tail = GetLimb(LimbType.Tail);
|
||||
|
||||
head.body.ApplyTorque(head.Mass * Dir * 0.1f);
|
||||
tail.body.ApplyTorque(tail.Mass * -Dir * 0.1f);
|
||||
if (head != null) head.body.ApplyTorque(head.Mass * Dir * 0.1f);
|
||||
if (tail != null) tail.body.ApplyTorque(tail.Mass * -Dir * 0.1f);
|
||||
}
|
||||
|
||||
public override void Flip()
|
||||
|
||||
@@ -84,6 +84,7 @@ namespace Subsurface
|
||||
string name = ToolBox.GetAttributeString(element, "name", "").ToLower();
|
||||
prefab = JobPrefab.List.Find(jp => jp.Name.ToLower() == name);
|
||||
|
||||
skills = new Dictionary<string, Skill>();
|
||||
foreach (XElement subElement in element.Elements())
|
||||
{
|
||||
if (subElement.Name.ToString().ToLower() != "skill") continue;
|
||||
|
||||
@@ -67,9 +67,17 @@ namespace Subsurface
|
||||
|
||||
public Vector2 TargetMovement
|
||||
{
|
||||
get { return (correctionMovement == Vector2.Zero) ? targetMovement : correctionMovement; }
|
||||
get
|
||||
{
|
||||
return (correctionMovement == Vector2.Zero) ? targetMovement : correctionMovement;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (float.IsNaN(value.X) || float.IsNaN(value.Y))
|
||||
{
|
||||
targetMovement = Vector2.Zero;
|
||||
return;
|
||||
}
|
||||
targetMovement.X = MathHelper.Clamp(value.X, -3.0f, 3.0f);
|
||||
targetMovement.Y = MathHelper.Clamp(value.Y, -3.0f, 3.0f);
|
||||
}
|
||||
@@ -574,6 +582,7 @@ namespace Subsurface
|
||||
else
|
||||
{
|
||||
correctionMovement = Vector2.Normalize(newMovement) * ((targetMovement == Vector2.Zero) ? 1.0f : targetMovement.Length());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user