GameMode/CrewManager bugfixes, fabricators
BIN
Subsurface/Content/Items/Fabricators/fabricator.png
Normal file
|
After Width: | Height: | Size: 2.1 KiB |
24
Subsurface/Content/Items/Fabricators/fabricators.xml
Normal file
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<Items>
|
||||
<Item
|
||||
name="Fabricator"
|
||||
linkable="true"
|
||||
pickdistance="150">
|
||||
|
||||
<Sprite texture ="fabricator.png" depth="0.8"/>
|
||||
|
||||
<Fabricator canbeselected = "true">
|
||||
<fabricableitem name="Harpoon Gun" requireditems="ID Card, Spear"/>
|
||||
<fabricableitem name="Plasma Cutter" requireditems="Wrench, Spear"/>
|
||||
</Fabricator>
|
||||
|
||||
<ConnectionPanel canbeselected = "true">
|
||||
<requireditem name="Screwdriver" type="Equipped"/>
|
||||
<output name="power_in"/>
|
||||
</ConnectionPanel>
|
||||
|
||||
<ItemContainer capacity="5" canbeselected="true" hideitems="true" hudpos="0.2, 0.7" slotsperrow="1"/>
|
||||
<ItemContainer capacity="5" canbeselected="true" hideitems="true" hudpos="0.8, 0.7" slotsperrow="1"/>
|
||||
</Item>
|
||||
|
||||
</Items>
|
||||
|
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 1.9 KiB |
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
|
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 2.0 KiB |
|
Before Width: | Height: | Size: 3.4 KiB After Width: | Height: | Size: 3.4 KiB |
@@ -133,6 +133,16 @@ namespace Subsurface
|
||||
keyboardDispatcher = new KeyboardDispatcher(window);
|
||||
}
|
||||
|
||||
public T GetChild<T>()
|
||||
{
|
||||
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)
|
||||
|
||||
@@ -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<GameModePreset> presetList = new List<GameModePreset>();
|
||||
|
||||
//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);
|
||||
|
||||
@@ -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))
|
||||
{
|
||||
|
||||
@@ -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<Character> 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)
|
||||
|
||||
@@ -25,6 +25,8 @@ namespace Subsurface
|
||||
|
||||
public override void Update(float deltaTime)
|
||||
{
|
||||
base.Update(deltaTime);
|
||||
|
||||
if (!isRunning) return;
|
||||
|
||||
if (DateTime.Now >= endTime)
|
||||
|
||||
@@ -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<RelatedItem>();
|
||||
|
||||
//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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
216
Subsurface/Items/Components/Fabricator.cs
Normal file
@@ -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<FabricableItem> list = new List<FabricableItem>();
|
||||
|
||||
//public readonly string[] FabricatorTags;
|
||||
|
||||
public readonly ItemPrefab TargetItem;
|
||||
|
||||
public readonly List<ItemPrefab> 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<ItemPrefab>();
|
||||
|
||||
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<FabricableItem> fabricableItems;
|
||||
|
||||
GUIListBox itemList;
|
||||
|
||||
GUIFrame selectedItemFrame;
|
||||
|
||||
FabricableItem fabricatedItem;
|
||||
float timeUntilReady;
|
||||
|
||||
public Fabricator(Item item, XElement element)
|
||||
: base(item, element)
|
||||
{
|
||||
fabricableItems = new List<FabricableItem>();
|
||||
|
||||
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<ItemContainer>();
|
||||
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<GUIButton>().Enabled = true;
|
||||
|
||||
ItemContainer container = item.GetComponent<ItemContainer>();
|
||||
foreach (ItemPrefab ip in targetItem.RequiredItems)
|
||||
{
|
||||
if (Array.Find(container.inventory.items, it => it != null && it.Prefab == ip) != null) continue;
|
||||
selectedItemFrame.GetChild<GUIButton>().Enabled = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
itemList.Update(0.016f);
|
||||
itemList.Draw(spriteBatch);
|
||||
|
||||
if (selectedItemFrame != null)
|
||||
{
|
||||
selectedItemFrame.Update(0.016f);
|
||||
selectedItemFrame.Draw(spriteBatch);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -78,6 +78,7 @@
|
||||
<Compile Include="GUI\GUITickBox.cs" />
|
||||
<Compile Include="IPropertyObject.cs" />
|
||||
<Compile Include="Items\CharacterInventory.cs" />
|
||||
<Compile Include="Items\Components\Fabricator.cs" />
|
||||
<Compile Include="Items\Components\MiniMap.cs" />
|
||||
<Compile Include="Items\Components\Pump.cs" />
|
||||
<Compile Include="Items\Components\Signal\OxygenDetector.cs" />
|
||||
@@ -303,6 +304,13 @@
|
||||
<Content Include="Content\Items\Door\windowedDoor.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Content\Items\Fabricators\fabricator.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Content\Items\Fabricators\fabricators.xml">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
<SubType>Designer</SubType>
|
||||
</Content>
|
||||
<Content Include="Content\Items\Lockers\locker.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
@@ -435,22 +443,22 @@
|
||||
<Content Include="Content\Items\poweritems.xml">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Content\Items\railgun.xml">
|
||||
<Content Include="Content\Items\Weapons\railgun.xml">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Content\Items\railgunbarrel.png">
|
||||
<Content Include="Content\Items\Weapons\railgunbarrel.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Content\Items\railgunbase.png">
|
||||
<Content Include="Content\Items\Weapons\railgunbase.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Content\Items\railguncontroller.png">
|
||||
<Content Include="Content\Items\Weapons\railguncontroller.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Content\Items\railgunloader.png">
|
||||
<Content Include="Content\Items\Weapons\railgunloader.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Content\Items\railgunshell.png">
|
||||
<Content Include="Content\Items\Weapons\railgunshell.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Content\Items\Reactor\reactor.png">
|
||||
@@ -585,7 +593,7 @@
|
||||
<None Include="Content\Items\Weapons\harpoon2.ogg">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="Content\Items\railgun.ogg">
|
||||
<None Include="Content\Items\Weapons\railgun.ogg">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="Content\Items\Weapons\stunGrenade.ogg">
|
||||
|
||||