diff --git a/Subsurface/Content/Items/Fabricators/fabricator.png b/Subsurface/Content/Items/Fabricators/fabricator.png
new file mode 100644
index 000000000..e82943efb
Binary files /dev/null and b/Subsurface/Content/Items/Fabricators/fabricator.png differ
diff --git a/Subsurface/Content/Items/Fabricators/fabricators.xml b/Subsurface/Content/Items/Fabricators/fabricators.xml
new file mode 100644
index 000000000..ee84049cd
--- /dev/null
+++ b/Subsurface/Content/Items/Fabricators/fabricators.xml
@@ -0,0 +1,24 @@
+
+
+ -
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Subsurface/Content/Items/railgun.ogg b/Subsurface/Content/Items/Weapons/railgun.ogg
similarity index 100%
rename from Subsurface/Content/Items/railgun.ogg
rename to Subsurface/Content/Items/Weapons/railgun.ogg
diff --git a/Subsurface/Content/Items/railgun.xml b/Subsurface/Content/Items/Weapons/railgun.xml
similarity index 100%
rename from Subsurface/Content/Items/railgun.xml
rename to Subsurface/Content/Items/Weapons/railgun.xml
diff --git a/Subsurface/Content/Items/railgunbarrel.png b/Subsurface/Content/Items/Weapons/railgunbarrel.png
similarity index 100%
rename from Subsurface/Content/Items/railgunbarrel.png
rename to Subsurface/Content/Items/Weapons/railgunbarrel.png
diff --git a/Subsurface/Content/Items/railgunbase.png b/Subsurface/Content/Items/Weapons/railgunbase.png
similarity index 100%
rename from Subsurface/Content/Items/railgunbase.png
rename to Subsurface/Content/Items/Weapons/railgunbase.png
diff --git a/Subsurface/Content/Items/railguncontroller.png b/Subsurface/Content/Items/Weapons/railguncontroller.png
similarity index 100%
rename from Subsurface/Content/Items/railguncontroller.png
rename to Subsurface/Content/Items/Weapons/railguncontroller.png
diff --git a/Subsurface/Content/Items/railgunloader.png b/Subsurface/Content/Items/Weapons/railgunloader.png
similarity index 100%
rename from Subsurface/Content/Items/railgunloader.png
rename to Subsurface/Content/Items/Weapons/railgunloader.png
diff --git a/Subsurface/Content/Items/railgunshell.png b/Subsurface/Content/Items/Weapons/railgunshell.png
similarity index 100%
rename from Subsurface/Content/Items/railgunshell.png
rename to Subsurface/Content/Items/Weapons/railgunshell.png
diff --git a/Subsurface/GUI/GUIComponent.cs b/Subsurface/GUI/GUIComponent.cs
index c21a4dd73..a2fbf255c 100644
--- a/Subsurface/GUI/GUIComponent.cs
+++ b/Subsurface/GUI/GUIComponent.cs
@@ -133,6 +133,16 @@ namespace Subsurface
keyboardDispatcher = new KeyboardDispatcher(window);
}
+ public T GetChild()
+ {
+ foreach (GUIComponent child in children)
+ {
+ if (child is T) return (T)(object)child;
+ }
+
+ return default(T);
+ }
+
public GUIComponent GetChild(object obj)
{
foreach (GUIComponent child in children)
diff --git a/Subsurface/GameSession/GameMode.cs b/Subsurface/GameSession/GameMode.cs
index 45ab79427..5be3b8bfa 100644
--- a/Subsurface/GameSession/GameMode.cs
+++ b/Subsurface/GameSession/GameMode.cs
@@ -1,4 +1,5 @@
-using Microsoft.Xna.Framework.Graphics;
+using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Reflection;
@@ -37,12 +38,17 @@ namespace Subsurface
{
public static List presetList = new List();
- //TimeSpan duration;
+ TimeSpan duration;
protected DateTime startTime;
protected DateTime endTime;
//public readonly bool IsSinglePlayer;
+ private GUIProgressBar timerBar;
+
+
+
+
protected bool isRunning;
//protected string name;
@@ -85,16 +91,25 @@ namespace Subsurface
{
this.preset = preset;
+
//list.Add(this);
}
public virtual void Draw(SpriteBatch spriteBatch)
- { }
+ {
+ if (timerBar != null) timerBar.Draw(spriteBatch);
+ }
public virtual void Start(TimeSpan duration)
{
startTime = DateTime.Now;
- endTime = startTime + duration;
+ if (duration!=TimeSpan.Zero)
+ {
+ endTime = startTime + duration;
+ this.duration = duration;
+
+ timerBar = new GUIProgressBar(new Rectangle(Game1.GraphicsWidth - 120, 20, 100, 25), Color.Gold, 0.0f, null);
+ }
endMessage = "The round has ended!";
@@ -105,10 +120,15 @@ namespace Subsurface
{
if (!isRunning) return;
- if (DateTime.Now >= endTime)
+ if (duration!=TimeSpan.Zero)
{
- End(endMessage);
+ double elapsedTime = (DateTime.Now - startTime).TotalSeconds;
+ timerBar.BarSize = (float)(elapsedTime / duration.TotalSeconds);
}
+ //if (DateTime.Now >= endTime)
+ //{
+ // End(endMessage);
+ //}
}
public virtual void End(string endMessage = "")
@@ -119,7 +139,7 @@ namespace Subsurface
Game1.GameSession.EndShift(null, null);
}
-
+
public static void Init()
{
new GameModePreset("Single Player", typeof(SinglePlayerMode), true);
diff --git a/Subsurface/GameSession/GameSession.cs b/Subsurface/GameSession/GameSession.cs
index a1b98ea42..6762a6f45 100644
--- a/Subsurface/GameSession/GameSession.cs
+++ b/Subsurface/GameSession/GameSession.cs
@@ -15,8 +15,8 @@ namespace Subsurface
public readonly TaskManager taskManager;
- protected DateTime startTime;
- protected DateTime endTime;
+ //protected DateTime startTime;
+ //protected DateTime endTime;
public readonly GameMode gameMode;
@@ -25,23 +25,17 @@ namespace Subsurface
private GUIListBox chatBox;
private GUITextBox textBox;
- private GUIProgressBar timerBar;
-
- private GUIButton endShiftButton;
-
private string savePath;
- private Map selectedMap;
-
-
+ private Map selectedMap;
- public GameSession(Map selectedMap, TimeSpan gameDuration, GameModePreset gameModePreset)
- :this(selectedMap, gameDuration, gameModePreset.Instantiate())
+ public GameSession(Map selectedMap, GameModePreset gameModePreset)
+ :this(selectedMap, gameModePreset.Instantiate())
{
}
- public GameSession(Map selectedMap, TimeSpan gameDuration, GameMode gameMode = null)
+ public GameSession(Map selectedMap, GameMode gameMode = null)
{
taskManager = new TaskManager(this);
@@ -63,23 +57,15 @@ namespace Subsurface
Color.White * 0.5f, Color.Black, Alignment.Bottom, Alignment.Left, guiRoot);
textBox.OnEnter = EnterChatMessage;
}
-
- if (Game1.Client==null)
- {
- endShiftButton = new GUIButton(new Rectangle(Game1.GraphicsWidth - 240, 20, 100, 25), "End shift", Color.White, Alignment.Left | Alignment.Top, guiRoot);
- endShiftButton.OnClicked = EndShift;
- }
-
- timerBar = new GUIProgressBar(new Rectangle(Game1.GraphicsWidth - 120, 20, 100, 25), Color.Gold, 0.0f, guiRoot);
-
+
this.gameMode = gameMode;
//if (gameMode != null && !gameMode.IsSinglePlayer)
//{
// gameMode.Start(Game1.NetLobbyScreen.GameDuration);
//}
- startTime = DateTime.Now;
- endTime = startTime + gameDuration;
+ //startTime = DateTime.Now;
+ //endTime = startTime + gameDuration;
this.selectedMap = selectedMap;
@@ -90,7 +76,7 @@ namespace Subsurface
}
public GameSession(Map selectedMap, string savePath, string filePath)
- : this(selectedMap, new TimeSpan(0,0,0,0))
+ : this(selectedMap)
{
XDocument doc = ToolBox.TryLoadXml(filePath);
if (doc == null) return;
@@ -109,13 +95,13 @@ namespace Subsurface
this.savePath = savePath;
}
- public void StartShift(int scriptedEventCount = 1)
+ public void StartShift(TimeSpan duration, int scriptedEventCount = 1)
{
//if (crewManager.characterInfos.Count == 0) return;
if (Map.Loaded!=selectedMap) selectedMap.Load();
- gameMode.Start(TimeSpan.Zero);
+ if (gameMode!=null) gameMode.Start(duration);
//crewManager.StartShift();
taskManager.StartShift(scriptedEventCount);
@@ -138,7 +124,7 @@ namespace Subsurface
}
taskManager.EndShift();
- gameMode.End();
+ //gameMode.End();
return true;
}
@@ -194,7 +180,7 @@ namespace Subsurface
{
taskManager.Update(deltaTime);
//if (endShiftButton!=null) endShiftButton.Enabled = !taskManager.CriticalTasks;
- endShiftButton.Enabled = true;
+ //endShiftButton.Enabled = true;
guiRoot.Update(deltaTime);
@@ -204,9 +190,9 @@ namespace Subsurface
if (gameMode != null) gameMode.Update(deltaTime);
- double duration = (endTime - startTime).TotalSeconds;
- double elapsedTime = (DateTime.Now-startTime).TotalSeconds;
- timerBar.BarSize = (float)(elapsedTime / Math.Max(duration, 1.0));
+ //double duration = (endTime - startTime).TotalSeconds;
+ //double elapsedTime = (DateTime.Now-startTime).TotalSeconds;
+ //timerBar.BarSize = (float)(elapsedTime / Math.Max(duration, 1.0));
if (PlayerInput.KeyHit(Keys.Tab))
{
diff --git a/Subsurface/GameSession/SinglePlayerMode.cs b/Subsurface/GameSession/SinglePlayerMode.cs
index 678dae8c2..d644d04ae 100644
--- a/Subsurface/GameSession/SinglePlayerMode.cs
+++ b/Subsurface/GameSession/SinglePlayerMode.cs
@@ -1,4 +1,5 @@
-using Microsoft.Xna.Framework.Graphics;
+using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -12,6 +13,8 @@ namespace Subsurface
public readonly CrewManager crewManager;
public readonly HireManager hireManager;
+ private GUIButton endShiftButton;
+
private int day;
public int Day
@@ -28,6 +31,9 @@ namespace Subsurface
crewManager = new CrewManager();
hireManager = new HireManager();
+ endShiftButton = new GUIButton(new Rectangle(Game1.GraphicsWidth - 240, 20, 100, 25), "End shift", Color.White, Alignment.Left | Alignment.Top);
+ endShiftButton.OnClicked = EndShift;
+
hireManager.GenerateCharacters("Content/Characters/Human/human.xml", 10);
day = 1;
@@ -73,8 +79,11 @@ namespace Subsurface
public override void Draw(SpriteBatch spriteBatch)
{
+ base.Draw(spriteBatch);
+
crewManager.Draw(spriteBatch);
+ endShiftButton.Draw(spriteBatch);
//chatBox.Draw(spriteBatch);
//textBox.Draw(spriteBatch);
@@ -85,8 +94,12 @@ namespace Subsurface
public override void Update(float deltaTime)
{
+ base.Update(deltaTime);
+
crewManager.Update(deltaTime);
+ endShiftButton.Update(deltaTime);
+
if (!crewDead)
{
if (crewManager.characters.Find(c => !c.IsDead) == null)
@@ -102,7 +115,7 @@ namespace Subsurface
}
}
- public override void End(string endMessage = "")
+ private bool EndShift(GUIButton button, object obj)
{
StringBuilder sb = new StringBuilder();
List casualties = crewManager.characters.FindAll(c => c.IsDead);
@@ -142,6 +155,10 @@ namespace Subsurface
{
Character.characterList.RemoveAt(i);
}
+
+ Game1.GameSession.EndShift(null, null);
+
+ return true;
}
public void Save(XElement element)
diff --git a/Subsurface/GameSession/TraitorMode.cs b/Subsurface/GameSession/TraitorMode.cs
index c8f1b066b..f93b5e054 100644
--- a/Subsurface/GameSession/TraitorMode.cs
+++ b/Subsurface/GameSession/TraitorMode.cs
@@ -25,6 +25,8 @@ namespace Subsurface
public override void Update(float deltaTime)
{
+ base.Update(deltaTime);
+
if (!isRunning) return;
if (DateTime.Now >= endTime)
diff --git a/Subsurface/Items/Components/Container.cs b/Subsurface/Items/Components/Container.cs
index 288470e32..e3aa1a386 100644
--- a/Subsurface/Items/Components/Container.cs
+++ b/Subsurface/Items/Components/Container.cs
@@ -13,25 +13,13 @@ namespace Subsurface.Items.Components
public ItemInventory inventory;
//how many items can be contained
- private int capacity;
-
- private bool hideItems;
- private bool drawInventory;
-
- //the position of the first item in the container
- private Vector2 itemPos;
-
- //item[i].Pos = itemPos + itemInterval*i
- private Vector2 itemInterval;
-
- private float itemRotation;
-
[HasDefaultValue(5, false)]
public int Capacity
{
get { return capacity; }
set { capacity = Math.Max(value, 1); }
}
+ private int capacity;
[HasDefaultValue(true, false)]
public bool HideItems
@@ -39,6 +27,7 @@ namespace Subsurface.Items.Components
get { return hideItems; }
set { hideItems = value; }
}
+ private bool hideItems;
[HasDefaultValue(false, false)]
public bool DrawInventory
@@ -46,6 +35,25 @@ namespace Subsurface.Items.Components
get { return drawInventory; }
set { drawInventory = value; }
}
+ private bool drawInventory;
+
+ //the position of the first item in the container
+ [HasDefaultValue("0.0,0.0", false)]
+ public string ItemPos
+ {
+ get { return ToolBox.Vector2ToString(itemPos); }
+ set { itemPos = ToolBox.ParseToVector2(value); }
+ }
+ private Vector2 itemPos;
+
+ //item[i].Pos = itemPos + itemInterval*i
+ [HasDefaultValue("0.0,0.0", false)]
+ public string ItemInterval
+ {
+ get { return ToolBox.Vector2ToString(itemInterval); }
+ set { itemInterval = ToolBox.ParseToVector2(value); }
+ }
+ private Vector2 itemInterval;
[HasDefaultValue(0.0f, false)]
public float ItemRotation
@@ -53,25 +61,33 @@ namespace Subsurface.Items.Components
get { return itemRotation; }
set { itemRotation = value; }
}
+ private float itemRotation;
- [HasDefaultValue("0.0,0.0", false)]
- public string ItemPos
- {
- get { return ToolBox.Vector2ToString(itemPos); }
- set { itemPos = ToolBox.ParseToVector2(value); }
- }
- [HasDefaultValue("0.0,0.0", false)]
- public string ItemInterval
+ [HasDefaultValue("0.5,0.9", false)]
+ public string HudPos
{
- get { return ToolBox.Vector2ToString(itemInterval); }
- set { itemInterval = ToolBox.ParseToVector2(value); }
+ get { return ToolBox.Vector2ToString(hudPos); }
+ set
+ {
+ hudPos = ToolBox.ParseToVector2(value);
+ //inventory.CenterPos = hudPos;
+ }
}
-
+ private Vector2 hudPos;
+
+ [HasDefaultValue(5, false)]
+ public int SlotsPerRow
+ {
+ get { return slotsPerRow; }
+ set { slotsPerRow = value; }
+ }
+ private int slotsPerRow;
+
public ItemContainer(Item item, XElement element)
: base (item, element)
{
- inventory = new ItemInventory(this, capacity);
+ inventory = new ItemInventory(this, capacity, hudPos, slotsPerRow);
containableItems = new List();
//itemPos = ToolBox.GetAttributeVector2(element, "ItemPos", Vector2.Zero);
@@ -99,6 +115,7 @@ namespace Subsurface.Items.Components
public bool CanBeContained(Item item)
{
+ if (containableItems.Count == 0) return true;
return (containableItems.Find(x => x.MatchesItem(item)) != null);
}
@@ -182,10 +199,7 @@ namespace Subsurface.Items.Components
public override bool Pick(Character picker)
{
- if (picker == null) return false;
- //picker.SelectedConstruction = item;
-
- return true;
+ return (picker != null);
}
diff --git a/Subsurface/Items/Components/Fabricator.cs b/Subsurface/Items/Components/Fabricator.cs
new file mode 100644
index 000000000..398799724
--- /dev/null
+++ b/Subsurface/Items/Components/Fabricator.cs
@@ -0,0 +1,216 @@
+using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Graphics;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Xml.Linq;
+
+namespace Subsurface.Items.Components
+{
+ class FabricableItem
+ {
+ //public static List list = new List();
+
+ //public readonly string[] FabricatorTags;
+
+ public readonly ItemPrefab TargetItem;
+
+ public readonly List RequiredItems;
+
+ public readonly float RequiredTime;
+
+
+ //ListOrSomething requiredLevels
+
+ public FabricableItem(XElement element)
+ {
+ string name = ToolBox.GetAttributeString(element, "name", "").ToLower();
+
+ TargetItem = ItemPrefab.list.Find(ip => ip.Name.ToLower() == name) as ItemPrefab;
+ if (TargetItem == null)
+ {
+ DebugConsole.ThrowError("Error in Fabricable Item! Item ''" + element.Name + "'' not found.");
+ return;
+ }
+
+ RequiredItems = new List();
+
+ string[] requiredItemNames = ToolBox.GetAttributeString(element, "requireditems", "").Split(',');
+ foreach (string requiredItemName in requiredItemNames)
+ {
+ ItemPrefab requiredItem = ItemPrefab.list.Find(ip => ip.Name.ToLower() == requiredItemName.Trim().ToLower()) as ItemPrefab;
+ if (requiredItem == null) continue;
+ RequiredItems.Add(requiredItem);
+ }
+
+ RequiredTime = ToolBox.GetAttributeFloat(element, "requiredtime", 1.0f);
+ }
+ }
+
+ class Fabricator : ItemComponent
+ {
+ List fabricableItems;
+
+ GUIListBox itemList;
+
+ GUIFrame selectedItemFrame;
+
+ FabricableItem fabricatedItem;
+ float timeUntilReady;
+
+ public Fabricator(Item item, XElement element)
+ : base(item, element)
+ {
+ fabricableItems = new List();
+
+ foreach (XElement subElement in element.Elements())
+ {
+ if (subElement.Name.ToString() != "fabricableitem") continue;
+
+ FabricableItem fabricableItem = new FabricableItem(subElement);
+ if (fabricableItem.TargetItem != null) fabricableItems.Add(fabricableItem);
+
+ }
+
+ int width = 400, height = 300;
+ itemList = new GUIListBox(new Rectangle(Game1.GraphicsWidth / 2 - width / 2, Game1.GraphicsHeight / 2 - height / 2, width, height), Color.White * 0.7f);
+ itemList.OnSelected = SelectItem;
+ //structureList.CheckSelected = MapEntityPrefab.GetSelected;
+
+ foreach (FabricableItem fi in fabricableItems)
+ {
+ Color color = ((itemList.CountChildren % 2) == 0) ? Color.White : Color.LightGray;
+
+ //GUIFrame frame = new GUIFrame(new Rectangle(0, 0, 0, 50), Color.Transparent, itemList);
+ //frame.UserData = fi;
+ //frame.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f);
+ //frame.Color = color;
+ //frame.HoverColor = Color.Gold * 0.2f;
+ //frame.SelectedColor = Color.Gold * 0.5f;
+
+ GUITextBlock textBlock = new GUITextBlock(
+ new Rectangle(0, 0, 0, 25),
+ fi.TargetItem.Name,
+ color, Color.Black,
+ Alignment.Left,
+ Alignment.Left,
+ itemList);
+ textBlock.UserData = fi;
+ textBlock.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f);
+
+ //if (fi.TargetItem.sprite != null)
+ //{
+ // GUIImage img = new GUIImage(new Rectangle(0, 0, 40, 40), fi.TargetItem.sprite, Alignment.Left, frame);
+ // img.Scale = Math.Min(Math.Min(40.0f / img.SourceRect.Width, 40.0f / img.SourceRect.Height), 1.0f);
+ //}
+ }
+ }
+
+ private bool SelectItem(object obj)
+ {
+ FabricableItem targetItem = obj as FabricableItem;
+ if (targetItem == null) return false;
+
+ int width = 200, height = 150;
+ selectedItemFrame = new GUIFrame(new Rectangle(Game1.GraphicsWidth / 2 - width / 2, itemList.Rect.Bottom+20, width, height), Color.Black*0.8f);
+ selectedItemFrame.Padding = GUI.style.smallPadding;
+
+ if (targetItem.TargetItem.sprite != null)
+ {
+ GUIImage img = new GUIImage(new Rectangle(0, 0, 40, 40), targetItem.TargetItem.sprite, Alignment.CenterX, selectedItemFrame);
+ img.Scale = Math.Min(Math.Min(40.0f / img.SourceRect.Width, 40.0f / img.SourceRect.Height), 1.0f);
+
+ string text = targetItem.TargetItem.Name + "\n";
+ text += "Required items:\n";
+ foreach (ItemPrefab ip in targetItem.RequiredItems)
+ {
+ text += " - " + ip.Name + "\n";
+ }
+ text += "Required time: "+targetItem.RequiredTime+" s";
+
+ GUITextBlock textBlock = new GUITextBlock(
+ new Rectangle(0, 0, 0, 25),
+ text,
+ Color.Transparent, Color.White,
+ Alignment.CenterX | Alignment.CenterY,
+ Alignment.Left,
+ selectedItemFrame);
+
+ GUIButton button = new GUIButton(new Rectangle(0,0,100,20), "Create", Color.White, Alignment.CenterX | Alignment.Bottom, selectedItemFrame);
+ button.OnClicked = StartFabricating;
+ button.UserData = targetItem;
+
+
+ }
+
+ return true;
+ }
+
+ public override bool Pick(Character picker)
+ {
+ return (picker != null);
+ }
+
+ private bool StartFabricating(GUIButton button, object obj)
+ {
+ GUIComponent listElement = itemList.GetChild(obj);
+
+ listElement.Color = Color.Green;
+ itemList.Enabled = false;
+
+ fabricatedItem = obj as FabricableItem;
+ isActive = true;
+
+ timeUntilReady = fabricatedItem.RequiredTime;
+
+ return true;
+ }
+
+ public override void Update(float deltaTime, Camera cam)
+ {
+ timeUntilReady -= deltaTime;
+
+ if (timeUntilReady > 0.0f) return;
+
+ ItemContainer container = item.GetComponent();
+ foreach (ItemPrefab ip in fabricatedItem.RequiredItems)
+ {
+ var requiredItem = Array.Find(container.inventory.items, it => it != null && it.Prefab == ip);
+ container.inventory.RemoveItem(requiredItem);
+ }
+
+ new Item(fabricatedItem.TargetItem, item.Position);
+
+ isActive = false;
+ fabricatedItem = null;
+ }
+
+ public override void DrawHUD(SpriteBatch spriteBatch, Character character)
+ {
+ FabricableItem targetItem = itemList.SelectedData as FabricableItem;
+ if (targetItem != null)
+ {
+ selectedItemFrame.GetChild().Enabled = true;
+
+ ItemContainer container = item.GetComponent();
+ foreach (ItemPrefab ip in targetItem.RequiredItems)
+ {
+ if (Array.Find(container.inventory.items, it => it != null && it.Prefab == ip) != null) continue;
+ selectedItemFrame.GetChild().Enabled = false;
+ break;
+ }
+ }
+
+
+ itemList.Update(0.016f);
+ itemList.Draw(spriteBatch);
+
+ if (selectedItemFrame != null)
+ {
+ selectedItemFrame.Update(0.016f);
+ selectedItemFrame.Draw(spriteBatch);
+ }
+ }
+ }
+}
diff --git a/Subsurface/Items/Inventory.cs b/Subsurface/Items/Inventory.cs
index 5893628b7..10d19af36 100644
--- a/Subsurface/Items/Inventory.cs
+++ b/Subsurface/Items/Inventory.cs
@@ -10,20 +10,44 @@ namespace Subsurface
{
class Inventory : Entity
{
+ public static Item draggingItem;
+ public static Item doubleClickedItem;
+
+ private int slotsPerRow;
+
+ public int SlotsPerRow
+ {
+ set { slotsPerRow = Math.Max(1, value); }
+ }
+
protected int capacity;
- public static Item draggingItem;
+ public Vector2 CenterPos
+ {
+ get { return centerPos; }
+ set
+ {
+ centerPos = value;
+ centerPos.X *= Game1.GraphicsWidth;
+ centerPos.Y *= Game1.GraphicsHeight;
+ }
+ }
- public static Item doubleClickedItem;
+ private Vector2 centerPos;
protected int selectedSlot;
public Item[] items;
- public Inventory(int capacity)
+ public Inventory(int capacity, Vector2? centerPos = null, int slotsPerRow=5)
{
this.capacity = capacity;
+
+ this.slotsPerRow = slotsPerRow;
+
items = new Item[capacity];
+
+ CenterPos = (centerPos==null) ? new Vector2(0.5f, 0.5f) : (Vector2)centerPos;
}
public int FindIndex(Item item)
@@ -132,13 +156,11 @@ namespace Subsurface
int rectWidth = 40, rectHeight = 40;
int spacing = 10;
-
- int slotsPerRow = 5;
-
+
int rows = (int)Math.Ceiling((double)capacity / slotsPerRow);
- int startX = Game1.GraphicsWidth / 2 - (rectWidth * slotsPerRow + spacing * (slotsPerRow - 1)) / 2;
- int startY = (int)(Game1.GraphicsHeight * 0.9) - rows*(spacing+rectHeight);
+ int startX = (int)centerPos.X - (rectWidth * slotsPerRow + spacing * (slotsPerRow - 1)) / 2;
+ int startY = (int)centerPos.Y - rows * (spacing + rectHeight);
Rectangle slotRect = new Rectangle(startX, startY, rectWidth, rectHeight);
Rectangle draggingItemSlot = slotRect;
diff --git a/Subsurface/Items/Item.cs b/Subsurface/Items/Item.cs
index f1c69953e..3bb86d37c 100644
--- a/Subsurface/Items/Item.cs
+++ b/Subsurface/Items/Item.cs
@@ -166,6 +166,12 @@ namespace Subsurface
}
+ public Item(ItemPrefab itemPrefab, Vector2 position)
+ : this(new Rectangle((int)position.X, (int)position.Y, (int)itemPrefab.sprite.size.X, (int)itemPrefab.sprite.size.Y), itemPrefab)
+ {
+
+ }
+
public Item(Rectangle newRect, ItemPrefab itemPrefab)
{
prefab = itemPrefab;
diff --git a/Subsurface/Items/ItemInventory.cs b/Subsurface/Items/ItemInventory.cs
index 5cdf85cf7..5fd589516 100644
--- a/Subsurface/Items/ItemInventory.cs
+++ b/Subsurface/Items/ItemInventory.cs
@@ -1,4 +1,5 @@
-using Subsurface.Items.Components;
+using Microsoft.Xna.Framework;
+using Subsurface.Items.Components;
namespace Subsurface
{
@@ -6,8 +7,8 @@ namespace Subsurface
{
ItemContainer container;
- public ItemInventory(ItemContainer container, int capacity)
- : base(capacity)
+ public ItemInventory(ItemContainer container, int capacity, Vector2? centerPos = null, int slotsPerRow = 5)
+ : base(capacity, centerPos, slotsPerRow)
{
this.container = container;
}
diff --git a/Subsurface/Map/Map.cs b/Subsurface/Map/Map.cs
index 05d67c70c..0ac4f41f1 100644
--- a/Subsurface/Map/Map.cs
+++ b/Subsurface/Map/Map.cs
@@ -524,14 +524,10 @@ namespace Subsurface
private void Clear()
{
- filePath = "";
-
if (Game1.GameScreen.Cam != null) Game1.GameScreen.Cam.TargetPos = Vector2.Zero;
Entity.RemoveAll();
- if (Game1.GameSession != null) Game1.GameSession.EndShift(null, null);
-
PhysicsBody.list.Clear();
Ragdoll.list.Clear();
diff --git a/Subsurface/Networking/GameClient.cs b/Subsurface/Networking/GameClient.cs
index eae49a78e..e3108b808 100644
--- a/Subsurface/Networking/GameClient.cs
+++ b/Subsurface/Networking/GameClient.cs
@@ -240,8 +240,8 @@ namespace Subsurface.Networking
TimeSpan duration = new TimeSpan(0,(int)durationMinutes,0);
//int gameModeIndex = inc.ReadInt32();
- Game1.GameSession = new GameSession(Map.Loaded, duration);
- Game1.GameSession.StartShift(1);
+ Game1.GameSession = new GameSession(Map.Loaded);
+ Game1.GameSession.StartShift(duration, 1);
myCharacter = ReadCharacterData(inc);
Character.Controlled = myCharacter;
diff --git a/Subsurface/Networking/GameServer.cs b/Subsurface/Networking/GameServer.cs
index 8704f091b..d57040920 100644
--- a/Subsurface/Networking/GameServer.cs
+++ b/Subsurface/Networking/GameServer.cs
@@ -9,7 +9,6 @@ namespace Subsurface.Networking
{
class GameServer : NetworkMember
{
-
// Server object
NetServer Server;
// Configuration object
@@ -275,8 +274,8 @@ namespace Subsurface.Networking
//selectedMap.Load();
- Game1.GameSession = new GameSession(selectedMap, Game1.NetLobbyScreen.GameDuration, Game1.NetLobbyScreen.SelectedMode);
- Game1.GameSession.StartShift(1);
+ Game1.GameSession = new GameSession(selectedMap, Game1.NetLobbyScreen.SelectedMode);
+ Game1.GameSession.StartShift(Game1.NetLobbyScreen.GameDuration, 1);
//EventManager.SelectEvent(Game1.netLobbyScreen.SelectedEvent);
foreach (Client client in connectedClients)
diff --git a/Subsurface/Screens/LobbyScreen.cs b/Subsurface/Screens/LobbyScreen.cs
index 7b573ff33..508569e85 100644
--- a/Subsurface/Screens/LobbyScreen.cs
+++ b/Subsurface/Screens/LobbyScreen.cs
@@ -3,6 +3,7 @@ using FarseerPhysics.Dynamics;
using FarseerPhysics.Factories;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
+using System;
namespace Subsurface
{
@@ -351,7 +352,7 @@ namespace Subsurface
private bool StartShift(GUIButton button, object selection)
{
- Game1.GameSession.StartShift();
+ Game1.GameSession.StartShift(TimeSpan.Zero);
Game1.GameScreen.Select();
return true;
diff --git a/Subsurface/Screens/MainMenu.cs b/Subsurface/Screens/MainMenu.cs
index da30e75e1..5e442a034 100644
--- a/Subsurface/Screens/MainMenu.cs
+++ b/Subsurface/Screens/MainMenu.cs
@@ -176,7 +176,7 @@ namespace Subsurface
Map selectedMap = mapList.SelectedData as Map;
if (selectedMap == null) return false;
- Game1.GameSession = new GameSession(selectedMap, TimeSpan.Zero, GameModePreset.list.Find(gm => gm.Name == "Single Player"));
+ Game1.GameSession = new GameSession(selectedMap, GameModePreset.list.Find(gm => gm.Name == "Single Player"));
Game1.LobbyScreen.Select();
diff --git a/Subsurface/Subsurface.csproj b/Subsurface/Subsurface.csproj
index 97d8e02d9..19d88f624 100644
--- a/Subsurface/Subsurface.csproj
+++ b/Subsurface/Subsurface.csproj
@@ -78,6 +78,7 @@
+
@@ -303,6 +304,13 @@
PreserveNewest
+
+ PreserveNewest
+
+
+ PreserveNewest
+ Designer
+
PreserveNewest
@@ -435,22 +443,22 @@
PreserveNewest
-
+
PreserveNewest
-
+
PreserveNewest
-
+
PreserveNewest
-
+
PreserveNewest
-
+
PreserveNewest
-
+
PreserveNewest
@@ -585,7 +593,7 @@
PreserveNewest
-
+
PreserveNewest
diff --git a/Subsurface_Solution.v12.suo b/Subsurface_Solution.v12.suo
index 62606192a..dcfebe706 100644
Binary files a/Subsurface_Solution.v12.suo and b/Subsurface_Solution.v12.suo differ