Split Machines ItemComponents

There's still a lot of work to do before we can get the server to compile
This commit is contained in:
Juan Pablo Arce
2017-06-18 14:36:11 -03:00
parent 7168a534ed
commit 8f37e14917
98 changed files with 5264 additions and 4291 deletions
@@ -1,313 +0,0 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Linq;
using System.Collections.Generic;
namespace Barotrauma
{
class CrewCommander
{
private CrewManager crewManager;
private GUIFrame frame;
//GUIListBox characterList;
private bool infoTextShown;
private int characterFrameBottom;
public GUIFrame Frame
{
get { return IsOpen ? frame : null; }
}
public bool IsOpen
{
get;
private set;
}
public CrewCommander(CrewManager crewManager)
{
this.crewManager = crewManager;
}
public void ToggleGUIFrame()
{
IsOpen = !IsOpen;
if (IsOpen)
{
if (!infoTextShown)
{
GUI.AddMessage("Press " + GameMain.Config.KeyBind(InputType.CrewOrders) + " to open/close the command menu", Color.Cyan, 5.0f);
infoTextShown = true;
}
if (frame == null) CreateGUIFrame();
UpdateCharacters();
}
}
private void CreateGUIFrame()
{
frame = new GUIFrame(Rectangle.Empty, Color.Black * 0.6f, null);
frame.Padding = new Vector4(200.0f, 100.0f, 200.0f, 100.0f);
GUIButton closeButton = new GUIButton(new Rectangle(0, 50, 100, 20), "Close", Alignment.BottomCenter, "", frame);
closeButton.OnClicked = (GUIButton button, object userData) =>
{
ToggleGUIFrame();
return false;
};
//UpdateCharacters();
int buttonWidth = 130;
int spacing = 20;
int y = 50;
for (int n = 0; n<2; n++)
{
List<Order> orders = (n==0) ?
Order.PrefabList.FindAll(o => o.ItemComponentType == null && string.IsNullOrEmpty(o.ItemName)) :
Order.PrefabList.FindAll(o => o.ItemComponentType != null || !string.IsNullOrEmpty(o.ItemName));
int startX = -(buttonWidth * orders.Count + spacing * (orders.Count - 1)) / 2;
int i=0;
foreach (Order order in orders)
{
int x = startX + (buttonWidth + spacing) * (i % orders.Count);
if (order.ItemComponentType!=null || !string.IsNullOrEmpty(order.ItemName))
{
List<Item> matchingItems = !string.IsNullOrEmpty(order.ItemName) ?
Item.ItemList.FindAll(it => it.Name == order.ItemName) :
Item.ItemList.FindAll(it => it.components.Any(ic => ic.GetType() == order.ItemComponentType));
int y2 = y;
foreach (Item it in matchingItems)
{
var newOrder = new Order(order, it.components.Find(ic => ic.GetType() == order.ItemComponentType));
CreateOrderButton(new Rectangle(x + buttonWidth / 2, y2, buttonWidth, 20), newOrder, y2==y);
y2 += 25;
}
}
else
{
CreateOrderButton(new Rectangle(x + buttonWidth / 2, y, buttonWidth, 20), order);
}
i++;
}
y += 100;
}
}
private GUIButton CreateOrderButton(Rectangle rect, Order order, bool createSymbol = true)
{
var orderButton = new GUIButton(rect, order.Name, null, Alignment.TopCenter, Alignment.Center, "GUITextBox", frame);
orderButton.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f);
/*orderButton.TextColor = Color.White;
orderButton.Color = Color.Black * 0.5f;
orderButton.HoverColor = Color.LightGray * 0.5f;
orderButton.OutlineColor = Color.LightGray * 0.8f;*/
orderButton.UserData = order;
orderButton.OnClicked = SetOrder;
if (createSymbol)
{
var symbol = new GUIImage(new Rectangle(0,-60,64,64), order.SymbolSprite, Alignment.TopCenter, orderButton);
symbol.Color = order.Color;
orderButton.children.Insert(0, symbol);
orderButton.children.RemoveAt(orderButton.children.Count-1);
}
return orderButton;
}
public void UpdateCharacters()
{
CreateGUIFrame();
List<GUIComponent> prevCharacterFrames = new List<GUIComponent>();
foreach (GUIComponent child in frame.children)
{
if (!(child.UserData is Character)) continue;
prevCharacterFrames.Add(child);
}
foreach (GUIComponent child in prevCharacterFrames)
{
frame.RemoveChild(child);
}
List<Character> aliveCharacters = crewManager.characters.FindAll(c => !c.IsDead && c.AIController is HumanAIController);
characterFrameBottom = 0;
int charactersPerRow = 4;
int spacing = 5;
int i = 0;
foreach (Character character in aliveCharacters)
{
int rowCharacterCount = Math.Min(charactersPerRow, aliveCharacters.Count);
//if (i >= aliveCharacters.Count - charactersPerRow && aliveCharacters.Count % charactersPerRow > 0) rowCharacterCount = aliveCharacters.Count % charactersPerRow;
// rowCharacterCount = Math.Min(rowCharacterCount, aliveCharacters.Count - i);
int startX = -(150 * rowCharacterCount + spacing * (rowCharacterCount - 1)) / 2;
int x = startX + (150 + spacing) * (i % Math.Min(charactersPerRow, aliveCharacters.Count));
int y = (105 + spacing)*((int)Math.Floor((double)i / charactersPerRow));
GUIButton characterButton = new GUIButton(new Rectangle(x+75, y, 150, 40), "", null, Alignment.TopCenter, "GUITextBox", frame);
characterButton.UserData = character;
characterButton.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f);
characterButton.Color = Character.Controlled == character ? Color.Gold : Color.White;
/*characterButton.HoverColor = Color.LightGray * 0.5f;
characterButton.SelectedColor = Color.Gold * 0.6f;
characterButton.OutlineColor = Color.LightGray * 0.8f;*/
characterFrameBottom = Math.Max(characterFrameBottom, characterButton.Rect.Bottom);
string name = character.Info.Name;
if (character.Info.Job != null) name += '\n' + "(" + character.Info.Job.Name + ")";
GUITextBlock textBlock = new GUITextBlock(
new Rectangle(40, 0, 0, 25),
name,
Color.Transparent, null,
Alignment.Left, Alignment.Left,
"", characterButton, false);
textBlock.Font = GUI.SmallFont;
textBlock.Padding = new Vector4(5.0f, 0.0f, 5.0f, 0.0f);
new GUIImage(new Rectangle(-5, -5, 0, 0), character.AnimController.Limbs[0].sprite, Alignment.Left, characterButton);
var humanAi = character.AIController as HumanAIController;
if (humanAi != null && humanAi.CurrentOrder != null)
{
CreateCharacterOrderFrame(characterButton, humanAi.CurrentOrder, humanAi.CurrentOrderOption);
}
i++;
}
foreach (GUIComponent child in frame.children)
{
if (!(child.UserData is Order)) continue;
Rectangle rect = child.Rect;
rect.Y += characterFrameBottom;
child.Rect = rect;
}
}
public void SelectCharacter(Character character)
{
var characterButton = frame.FindChild(character) as GUIButton;
if (characterButton == null) return;
characterButton.Selected = true;
}
private bool SetOrder(GUIButton button, object userData)
{
Order order = userData as Order;
foreach (GUIComponent child in frame.children)
{
var characterButton = child as GUIButton;
characterButton.State = GUIComponent.ComponentState.None;
if (!characterButton.Selected) continue;
characterButton.Selected = false;
CreateCharacterOrderFrame(characterButton, order, "");
var humanAi = (characterButton.UserData as Character).AIController as HumanAIController;
humanAi.SetOrder(order, "");
}
//characterList.Deselect();
return true;
}
private void CreateCharacterOrderFrame(GUIComponent characterFrame, Order order, string selectedOption)
{
var character = characterFrame.UserData as Character;
if (character == null) return;
var humanAi = character.AIController as HumanAIController;
if (humanAi == null) return;
var existingOrder = characterFrame.children.Find(c => c.UserData is Order);
if (existingOrder != null) characterFrame.RemoveChild(existingOrder);
var orderFrame = new GUIFrame(new Rectangle(-5, characterFrame.Rect.Height, characterFrame.Rect.Width, 30 + order.Options.Length * 15), "InnerFrame", characterFrame);
/*orderFrame.OutlineColor = Color.LightGray * 0.5f;*/
orderFrame.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f);
orderFrame.UserData = order;
var img = new GUIImage(new Rectangle(0, 0, 20, 20), order.SymbolSprite, Alignment.TopLeft, orderFrame);
img.Scale = 20.0f / img.SourceRect.Width;
img.Color = order.Color;
img.CanBeFocused = false;
new GUITextBlock(new Rectangle(img.Rect.Width, 0, 0, 20), order.DoingText, "", Alignment.TopLeft, Alignment.CenterLeft, orderFrame);
var optionList = new GUIListBox(new Rectangle(0, 20, 0, 80), Color.Transparent, null, orderFrame);
optionList.UserData = order;
for (int i = 0; i < order.Options.Length; i++ )
{
var optionBox = new GUITextBlock(new Rectangle(0, 0, 0, 15), order.Options[i], "", Alignment.TopLeft, Alignment.CenterLeft, optionList);
optionBox.Font = GUI.SmallFont;
optionBox.UserData = order.Options[i];
if (selectedOption == order.Options[i])
{
optionList.Select(i);
}
}
optionList.OnSelected = SelectOrderOption;
}
private bool SelectOrderOption(GUIComponent component, object userData)
{
string option = userData.ToString();
Order order = component.Parent.UserData as Order;
Character character = component.Parent.Parent.Parent.UserData as Character;
var humanAi = character.AIController as HumanAIController;
if (humanAi == null) return false;
humanAi.SetOrder(order, option);
return true;
}
public void Draw(SpriteBatch spriteBatch)
{
if (!IsOpen) return;
frame.Draw(spriteBatch);
}
}
}
@@ -3,7 +3,7 @@ using System;
namespace Barotrauma
{
class AICharacter : Character
partial class AICharacter : Character
{
private AIController aiController;
@@ -15,7 +15,9 @@ namespace Barotrauma
public AICharacter(string file, Vector2 position, CharacterInfo characterInfo = null, bool isNetworkPlayer = false)
: base(file, position, characterInfo, isNetworkPlayer)
{
#if CLIENT
soundTimer = Rand.Range(0.0f, soundInterval);
#endif
}
public void SetAI(AIController aiController)
@@ -43,6 +45,7 @@ namespace Barotrauma
if (Controlled == this || !aiController.Enabled) return;
#if CLIENT
if (soundTimer > 0)
{
soundTimer -= deltaTime;
@@ -60,17 +63,11 @@ namespace Barotrauma
}
soundTimer = soundInterval;
}
#endif
aiController.Update(deltaTime);
}
public override void DrawFront(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch,Camera cam)
{
base.DrawFront(spriteBatch,cam);
if (GameMain.DebugDraw && !IsDead) aiController.DebugDraw(spriteBatch);
}
public override void AddDamage(CauseOfDeath causeOfDeath, float amount, IDamageable attacker)
{
base.AddDamage(causeOfDeath, amount, attacker);
@@ -84,9 +84,6 @@ namespace Barotrauma
//the name of the species (e.q. human)
public readonly string SpeciesName;
protected float soundTimer;
protected float soundInterval;
private float bleeding;
private float attackCoolDown;
@@ -562,7 +559,9 @@ namespace Barotrauma
needsAir = ToolBox.GetAttributeBool(doc.Root, "needsair", false);
drowningTime = ToolBox.GetAttributeFloat(doc.Root, "drowningtime", 10.0f);
#if CLIENT
soundInterval = ToolBox.GetAttributeFloat(doc.Root, "soundinterval", 10.0f);
#endif
if (file == humanConfigFile)
{
@@ -1138,6 +1137,7 @@ namespace Barotrauma
Vector2 mouseSimPos = ConvertUnits.ToSimUnits(cursorPosition);
#if CLIENT
if (Lights.LightManager.ViewTarget == this && Vector2.DistanceSquared(AnimController.Limbs[0].SimPosition, mouseSimPos) > 1.0f)
{
Body body = Submarine.PickBody(AnimController.Limbs[0].SimPosition, mouseSimPos);
@@ -1151,6 +1151,7 @@ namespace Barotrauma
}
}
}
#endif
if (!LockHands)
{
@@ -1733,7 +1734,9 @@ namespace Barotrauma
if (AnimController != null) AnimController.Remove();
#if CLIENT
if (Lights.LightManager.ViewTarget == this) Lights.LightManager.ViewTarget = null;
#endif
if (selectedItems[0] != null) selectedItems[0].Drop(this);
if (selectedItems[1] != null) selectedItems[1].Drop(this);
+15 -12
View File
@@ -7,9 +7,11 @@ using Microsoft.Xna.Framework;
//using Microsoft.Xna.Framework.Graphics;
using Barotrauma.Items.Components;
using System.Collections.Generic;
using Barotrauma.Lights;
using System.Linq;
using System.IO;
#if CLIENT
using Barotrauma.Lights;
#endif
namespace Barotrauma
{
@@ -43,8 +45,6 @@ namespace Barotrauma
public FixedMouseJoint pullJoint;
public readonly Lights.LightSource LightSource;
public readonly LimbType type;
public readonly bool ignoreCollisions;
@@ -299,15 +299,15 @@ namespace Barotrauma
}
damagedSprite = new Sprite(subElement, "", damagedSpritePath);
break;
case "lightsource":
LightSource = new LightSource(subElement);
break;
case "attack":
attack = new Attack(subElement);
break;
#if CLIENT
case "lightsource":
LightSource = new LightSource(subElement);
break;
case "sound":
hitSound = Sound.Load(ToolBox.GetAttributeString(subElement, "file", ""));
break;
@@ -411,10 +411,12 @@ namespace Barotrauma
public void Update(float deltaTime)
{
#if CLIENT
if (LightSource != null)
{
LightSource.ParentSub = body.Submarine;
}
#endif
if (!character.IsDead) damage = Math.Max(0.0f, damage-deltaTime*0.1f);
@@ -483,11 +485,7 @@ namespace Barotrauma
sprite.Remove();
sprite = null;
}
if (LightSource != null)
{
LightSource.Remove();
}
if (damagedSprite != null)
{
damagedSprite.Remove();
@@ -506,6 +504,11 @@ namespace Barotrauma
hitSound.Remove();
hitSound = null;
}
if (LightSource != null)
{
LightSource.Remove();
}
#endif
}
}