It compiles now, but it's probably really broken.
This commit is contained in:
juanjp600
2016-10-11 20:26:41 -03:00
parent 72033a581e
commit f5268c7c6c
23 changed files with 214 additions and 2006 deletions
Binary file not shown.
+1 -22
View File
@@ -191,28 +191,7 @@ namespace Barotrauma
//if (!Enabled) GUI.DrawRectangle(spriteBatch, rect, Color.Gray*0.5f, true); //if (!Enabled) GUI.DrawRectangle(spriteBatch, rect, Color.Gray*0.5f, true);
} }
public override void Update(float deltaTime)
{
if (!Visible) return;
base.Update(deltaTime);
//Color currColor = color;
//if (state == ComponentState.Hover) currColor = hoverColor;
//if (state == ComponentState.Selected) currColor = selectedColor;
//GUI.DrawRectangle(spriteBatch, rect, currColor * alpha, true);
////spriteBatch.DrawString(HUD.font, text, new Vector2(rect.X+rect.Width/2, rect.Y+rect.Height/2), Color.Black, 0.0f, new Vector2(0.5f,0.5f), 1.0f, SpriteEffects.None, 0.0f);
//GUI.DrawRectangle(spriteBatch, rect, Color.Black * alpha, false);
DrawChildren(spriteBatch);
//if (!Enabled) GUI.DrawRectangle(spriteBatch, rect, Color.Gray*0.5f, true);
}
public override void Update(float deltaTime) public override void Update(float deltaTime)
{ {
if (!Visible) return; if (!Visible) return;
@@ -313,7 +313,7 @@ namespace Barotrauma
public override void Update(float deltaTime, bool subInventory = false) public override void Update(float deltaTime, bool subInventory = false)
{ {
base.Update(deltaTime); base.Update(deltaTime);
if (doubleClickedItem != null) if (doubleClickedItem != null)
{ {
if (doubleClickedItem.ParentInventory != this) if (doubleClickedItem.ParentInventory != this)
@@ -339,7 +339,7 @@ namespace Barotrauma
//not equipped -> attempt to equip //not equipped -> attempt to equip
if (IsInLimbSlot(doubleClickedItem, InvSlotType.Any)) if (IsInLimbSlot(doubleClickedItem, InvSlotType.Any))
{ {
TryPutItem(doubleClickedItem, doubleClickedItem.AllowedSlots.FindAll(i => i != InvSlotType.Any), true); TryPutItem(doubleClickedItem, doubleClickedItem.AllowedSlots.FindAll(i => i != InvSlotType.Any));
} }
//equipped -> attempt to unequip //equipped -> attempt to unequip
else if (doubleClickedItem.AllowedSlots.Contains(InvSlotType.Any)) else if (doubleClickedItem.AllowedSlots.Contains(InvSlotType.Any))
@@ -349,7 +349,7 @@ namespace Barotrauma
} }
} }
} }
if (selectedSlot > -1) if (selectedSlot > -1)
{ {
UpdateSubInventory(deltaTime, selectedSlot); UpdateSubInventory(deltaTime, selectedSlot);
@@ -395,9 +395,7 @@ namespace Barotrauma.Items.Components
public void Undock() public void Undock()
{ {
if (dockingTarget == null || !docked) return; if (dockingTarget == null || !docked) return;
item.NewComponentEvent(this, false, true);
PlaySound(ActionType.OnUse, item.WorldPosition); PlaySound(ActionType.OnUse, item.WorldPosition);
dockingTarget.item.Submarine.DockedTo.Remove(item.Submarine); dockingTarget.item.Submarine.DockedTo.Remove(item.Submarine);
@@ -512,8 +510,6 @@ namespace Barotrauma.Items.Components
if (!item.linkedTo.Any(e => e is Hull) && !dockingTarget.item.linkedTo.Any(e => e is Hull)) if (!item.linkedTo.Any(e => e is Hull) && !dockingTarget.item.linkedTo.Any(e => e is Hull))
{ {
CreateHull(); CreateHull();
item.NewComponentEvent(this, false, true);
} }
} }
dockingState = MathHelper.Lerp(dockingState, 0.5f, deltaTime * 10.0f); dockingState = MathHelper.Lerp(dockingState, 0.5f, deltaTime * 10.0f);
+4 -4
View File
@@ -455,11 +455,11 @@ namespace Barotrauma.Items.Components
} }
} }
public override void ReceiveSignal(int stepsTaken, string signal, Connection connection, Item sender, float power=0.0f) public override void ReceiveSignal(int stepsTaken, string signal, Connection connection, Item sender, float power = 0.0f)
{ {
if (isStuck || GameMain.Client != null) return; if (isStuck || GameMain.Client != null) return;
if (connection.Name=="toggle") if (connection.Name == "toggle")
{ {
SetState(!isOpen, false, true); SetState(!isOpen, false, true);
} }
@@ -491,7 +491,7 @@ namespace Barotrauma.Items.Components
public override void ServerWrite(Lidgren.Network.NetOutgoingMessage msg, Barotrauma.Networking.Client c) public override void ServerWrite(Lidgren.Network.NetOutgoingMessage msg, Barotrauma.Networking.Client c)
{ {
msg.Write(isOpen); msg.Write(isOpen);
msg.WriteRangedSingle(stuck, 0.0f, 100.0f, 8); msg.WriteRangedSingle(stuck, 0.0f, 100.0f, 8);
} }
public override void ClientRead(Lidgren.Network.NetIncomingMessage msg) public override void ClientRead(Lidgren.Network.NetIncomingMessage msg)
@@ -499,6 +499,6 @@ namespace Barotrauma.Items.Components
SetState(msg.ReadBoolean(), true); SetState(msg.ReadBoolean(), true);
Stuck = msg.ReadRangedSingle(0.0f, 100.0f, 8); Stuck = msg.ReadRangedSingle(0.0f, 100.0f, 8);
} }
} }
} }
@@ -228,9 +228,7 @@ namespace Barotrauma.Items.Components
Msg = prevMsg; Msg = prevMsg;
attached = true; attached = true;
if (character != null) item.NewComponentEvent(this, true, true);
return true; return true;
} }
@@ -95,9 +95,7 @@ namespace Barotrauma.Items.Components
SetActive(!IsActive); SetActive(!IsActive);
currPowerConsumption = IsActive ? powerConsumption : 0.0f; currPowerConsumption = IsActive ? powerConsumption : 0.0f;
item.NewComponentEvent(this, true, true);
return true; return true;
} }
@@ -53,8 +53,7 @@ namespace Barotrauma.Items.Components
button.OnClicked = (GUIButton btn, object obj) => button.OnClicked = (GUIButton btn, object obj) =>
{ {
targetForce -= 1.0f; targetForce -= 1.0f;
item.NewComponentEvent(this, true, false);
return true; return true;
}; };
@@ -62,8 +61,7 @@ namespace Barotrauma.Items.Components
button.OnClicked = (GUIButton btn, object obj) => button.OnClicked = (GUIButton btn, object obj) =>
{ {
targetForce += 1.0f; targetForce += 1.0f;
item.NewComponentEvent(this, true, false);
return true; return true;
}; };
} }
@@ -240,14 +240,10 @@ namespace Barotrauma.Items.Components
if (fabricatedItem == null) if (fabricatedItem == null)
{ {
StartFabricating(obj as FabricableItem); StartFabricating(obj as FabricableItem);
item.NewComponentEvent(this, true, true);
} }
else else
{ {
CancelFabricating(); CancelFabricating();
item.NewComponentEvent(this, true, true);
} }
return true; return true;
@@ -74,7 +74,6 @@ namespace Barotrauma.Items.Components
targetLevel = null; targetLevel = null;
IsActive = !IsActive; IsActive = !IsActive;
if (!IsActive) currPowerConsumption = 0.0f; if (!IsActive) currPowerConsumption = 0.0f;
item.NewComponentEvent(this, true, true);
return true; return true;
}; };
@@ -83,7 +82,6 @@ namespace Barotrauma.Items.Components
button.OnClicked = (GUIButton btn, object obj) => button.OnClicked = (GUIButton btn, object obj) =>
{ {
FlowPercentage -= 10.0f; FlowPercentage -= 10.0f;
item.NewComponentEvent(this, true, true);
return true; return true;
}; };
@@ -92,7 +90,6 @@ namespace Barotrauma.Items.Components
button.OnClicked = (GUIButton btn, object obj) => button.OnClicked = (GUIButton btn, object obj) =>
{ {
FlowPercentage += 10.0f; FlowPercentage += 10.0f;
item.NewComponentEvent(this, true, true);
return true; return true;
}; };
@@ -60,7 +60,6 @@ namespace Barotrauma.Items.Components
isActiveTickBox.OnSelected = (GUITickBox box) => isActiveTickBox.OnSelected = (GUITickBox box) =>
{ {
IsActive = box.Selected; IsActive = box.Selected;
item.NewComponentEvent(this, true, false);
return true; return true;
}; };
@@ -117,12 +116,7 @@ namespace Barotrauma.Items.Components
int radius = GuiFrame.Rect.Height / 2 - 30; int radius = GuiFrame.Rect.Height / 2 - 30;
DrawRadar(spriteBatch, new Rectangle((int)GuiFrame.Center.X - radius, (int)GuiFrame.Center.Y - radius, radius * 2, radius * 2)); DrawRadar(spriteBatch, new Rectangle((int)GuiFrame.Center.X - radius, (int)GuiFrame.Center.Y - radius, radius * 2, radius * 2));
} }
public override void UpdateHUD(Character character)
{
GuiFrame.Update(1.0f / 60.0f);
}
private void DrawRadar(SpriteBatch spriteBatch, Rectangle rect) private void DrawRadar(SpriteBatch spriteBatch, Rectangle rect)
{ {
Vector2 center = new Vector2(rect.X + rect.Width*0.5f, rect.Center.Y); Vector2 center = new Vector2(rect.X + rect.Width*0.5f, rect.Center.Y);
@@ -324,7 +324,6 @@ namespace Barotrauma.Items.Components
if (unsentChanges && sendUpdateTimer<= 0.0f) if (unsentChanges && sendUpdateTimer<= 0.0f)
{ {
item.NewComponentEvent(this, true, true);
sendUpdateTimer = NetworkUpdateInterval; sendUpdateTimer = NetworkUpdateInterval;
unsentChanges = false; unsentChanges = false;
} }
@@ -128,7 +128,6 @@ namespace Barotrauma.Items.Components
networkUpdateTimer -= deltaTime; networkUpdateTimer -= deltaTime;
if (networkUpdateTimer <= 0.0f) if (networkUpdateTimer <= 0.0f)
{ {
item.NewComponentEvent(this, true, false);
networkUpdateTimer = 0.5f; networkUpdateTimer = 0.5f;
valueChanged = false; valueChanged = false;
} }
@@ -86,7 +86,6 @@ namespace Barotrauma.Items.Components
button.OnClicked = (GUIButton btn, object obj) => button.OnClicked = (GUIButton btn, object obj) =>
{ {
RechargeSpeed = Math.Max(rechargeSpeed - maxRechargeSpeed * 0.1f, 0.0f); RechargeSpeed = Math.Max(rechargeSpeed - maxRechargeSpeed * 0.1f, 0.0f);
item.NewComponentEvent(this, true, false);
return true; return true;
}; };
@@ -95,7 +94,6 @@ namespace Barotrauma.Items.Components
button.OnClicked = (GUIButton btn, object obj) => button.OnClicked = (GUIButton btn, object obj) =>
{ {
RechargeSpeed = Math.Max(rechargeSpeed + maxRechargeSpeed * 0.1f, 0.0f); RechargeSpeed = Math.Max(rechargeSpeed + maxRechargeSpeed * 0.1f, 0.0f);
item.NewComponentEvent(this, true, false);
return true; return true;
}; };
@@ -309,7 +309,6 @@ namespace Barotrauma.Items.Components
if (!PlayerInput.LeftButtonHeld()) if (!PlayerInput.LeftButtonHeld())
{ {
panel.Item.NewComponentEvent(panel, true, true);
//draggingConnected.Drop(Character); //draggingConnected.Drop(Character);
draggingConnected = null; draggingConnected = null;
} }
@@ -75,43 +75,19 @@ namespace Barotrauma.Items.Components
} }
else if (connection.Name == "toggle") else if (connection.Name == "toggle")
{ {
SetState(!IsOn,false,true); SetState(!IsOn);
} }
else if (connection.Name == "set_state") else if (connection.Name == "set_state")
{ {
SetState(signal != "0", false, true); SetState(signal != "0");
} }
} }
public void SetState(bool on, bool isNetworkMessage, bool sendNetworkMessage = false) public void SetState(bool on)
{ {
if (GameMain.Client != null && !isNetworkMessage) return; //if (GameMain.Client != null && !isNetworkMessage) return;
IsOn = on; IsOn = on;
if (sendNetworkMessage)
{
item.NewComponentEvent(this, false, true);
}
}
public override bool FillNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetBuffer message)
{
message.Write(IsOn);
return true;
}
public override void ReadNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetIncomingMessage message, float sendingTime)
{
if (sendingTime < lastReceivedMessage) return;
if (GameMain.Server != null)
{
return;
}
lastReceivedMessage = sendingTime;
SetState(message.ReadBoolean(), true);
} }
} }
} }
@@ -160,9 +160,7 @@ namespace Barotrauma.Items.Components
} }
Drawable = Nodes.Any(); Drawable = Nodes.Any();
if (!loading) Item.NewComponentEvent(this, true, true);
return true; return true;
} }
@@ -255,8 +253,6 @@ namespace Barotrauma.Items.Components
if (Nodes.Count > 1) if (Nodes.Count > 1)
{ {
Nodes.RemoveAt(Nodes.Count - 1); Nodes.RemoveAt(Nodes.Count - 1);
item.NewComponentEvent(this, true, true);
} }
Drawable = Nodes.Any(); Drawable = Nodes.Any();
+1 -2
View File
@@ -400,8 +400,7 @@ namespace Barotrauma
subRect.Y = subRect.Y - subRect.Height - 10; subRect.Y = subRect.Y - subRect.Height - 10;
container.Inventory.slots[i].Rect = subRect; container.Inventory.slots[i].Rect = subRect;
} }
}
container.Inventory.isSubInventory = true; container.Inventory.isSubInventory = true;
slots[slotIndex].State = GUIComponent.ComponentState.Hover; slots[slotIndex].State = GUIComponent.ComponentState.Hover;
File diff suppressed because it is too large Load Diff
+144 -4
View File
@@ -85,7 +85,7 @@ namespace Barotrauma
if (itemInfo.Inventory != null) if (itemInfo.Inventory != null)
{ {
spawnedItem = new Item(itemInfo.Prefab, Vector2.Zero, null); spawnedItem = new Item(itemInfo.Prefab, Vector2.Zero, null);
itemInfo.Inventory.TryPutItem(spawnedItem, spawnedItem.AllowedSlots, false); itemInfo.Inventory.TryPutItem(spawnedItem, spawnedItem.AllowedSlots);
} }
else else
{ {
@@ -95,7 +95,8 @@ namespace Barotrauma
AddToSpawnedList(spawnedItem); AddToSpawnedList(spawnedItem);
items.Add(spawnedItem); items.Add(spawnedItem);
} }
//if (GameMain.Server != null) GameMain.Server.SendItemSpawnMessage(items);
} }
public void AddToSpawnedList(Item item) public void AddToSpawnedList(Item item)
@@ -103,6 +104,121 @@ namespace Barotrauma
spawnItems.Add(item); spawnItems.Add(item);
} }
public void FillNetworkData(Lidgren.Network.NetBuffer message, List<Item> items)
{
message.Write((byte)items.Count);
for (int i = 0; i < items.Count; i++)
{
message.Write(items[i].Prefab.Name);
message.Write(items[i].ID);
if (items[i].ParentInventory == null || items[i].ParentInventory.Owner == null)
{
message.Write((ushort)0);
message.Write(items[i].Position.X);
message.Write(items[i].Position.Y);
message.Write(items[i].Submarine != null ? items[i].Submarine.ID : (ushort)0);
}
else
{
message.Write(items[i].ParentInventory.Owner.ID);
int index = items[i].ParentInventory.FindIndex(items[i]);
message.Write(index < 0 ? (byte)255 : (byte)index);
}
if (items[i].Name == "ID Card")
{
message.Write(items[i].Tags);
}
}
}
public void ReadNetworkData(Lidgren.Network.NetBuffer message)
{
var itemCount = message.ReadByte();
for (int i = 0; i < itemCount; i++)
{
string itemName = message.ReadString();
ushort itemId = message.ReadUInt16();
Vector2 pos = Vector2.Zero;
Submarine sub = null;
ushort inventoryId = message.ReadUInt16();
int inventorySlotIndex = -1;
if (inventoryId > 0)
{
inventorySlotIndex = message.ReadByte();
}
else
{
pos = new Vector2(message.ReadSingle(), message.ReadSingle());
ushort subID = message.ReadUInt16();
if (subID > 0)
{
sub = Submarine.Loaded.Find(s => s.ID == subID);
}
}
string tags = "";
if (itemName == "ID Card")
{
tags = message.ReadString();
}
var prefab = MapEntityPrefab.list.Find(me => me.Name == itemName);
if (prefab == null) continue;
var itemPrefab = prefab as ItemPrefab;
if (itemPrefab == null) continue;
Inventory inventory = null;
var inventoryOwner = Entity.FindEntityByID(inventoryId);
if (inventoryOwner != null)
{
if (inventoryOwner is Character)
{
inventory = (inventoryOwner as Character).Inventory;
}
else if (inventoryOwner is Item)
{
var containers = (inventoryOwner as Item).GetComponents<Items.Components.ItemContainer>();
if (containers!=null && containers.Any())
{
inventory = containers.Last().Inventory;
}
}
}
var item = new Item(itemPrefab, pos, sub);
item.ID = itemId;
if (sub != null)
{
item.CurrentHull = Hull.FindHull(pos + sub.Position, null, true);
item.Submarine = item.CurrentHull == null ? null : item.CurrentHull.Submarine;
}
if (!string.IsNullOrEmpty(tags)) item.Tags = tags;
if (inventory != null)
{
if (inventorySlotIndex >= 0 && inventorySlotIndex < 255 &&
inventory.TryPutItem(item, inventorySlotIndex, false))
{
continue;
}
inventory.TryPutItem(item, item.AllowedSlots);
}
}
}
public void Clear() public void Clear()
{ {
spawnQueue.Clear(); spawnQueue.Clear();
@@ -147,9 +263,33 @@ namespace Barotrauma
items.Add(item); items.Add(item);
} }
//if (GameMain.Server != null) GameMain.Server.SendItemRemoveMessage(items);
} }
public void FillNetworkData(Lidgren.Network.NetBuffer message, List<Item> items)
{
message.Write((byte)items.Count);
foreach (Item item in items)
{
message.Write(item.ID);
}
}
public void ReadNetworkData(Lidgren.Network.NetBuffer message)
{
var itemCount = message.ReadByte();
for (int i = 0; i<itemCount; i++)
{
ushort itemId = message.ReadUInt16();
var item = MapEntity.FindEntityByID(itemId) as Item;
if (item == null) continue;
item.Remove();
}
}
public void Clear() public void Clear()
{ {
removeQueue.Clear(); removeQueue.Clear();
@@ -568,6 +568,7 @@ namespace Barotrauma.Networking
string modeName = inc.ReadString(); string modeName = inc.ReadString();
bool respawnAllowed = inc.ReadBoolean(); bool respawnAllowed = inc.ReadBoolean();
bool loadSecondSub = inc.ReadBoolean();
GameModePreset gameMode = GameModePreset.list.Find(gm => gm.Name == modeName); GameModePreset gameMode = GameModePreset.list.Find(gm => gm.Name == modeName);
@@ -853,10 +853,6 @@ namespace Barotrauma.Networking
if (AllowRespawn) respawnManager = new RespawnManager(this, selectedShuttle); if (AllowRespawn) respawnManager = new RespawnManager(this, selectedShuttle);
for (int teamID = 1; teamID <= teamCount; teamID++)
{
List<Client> teamClients = teamCount == 1 ? connectedClients : connectedClients.FindAll(c => c.TeamID == teamID);
List<CharacterInfo> characterInfos = new List<CharacterInfo>(); List<CharacterInfo> characterInfos = new List<CharacterInfo>();
foreach (Client c in connectedClients) foreach (Client c in connectedClients)
{ {
@@ -237,7 +237,7 @@ namespace Barotrauma.Networking
foreach (Door door in shuttleDoors) foreach (Door door in shuttleDoors)
{ {
if (door.IsOpen) door.SetState(false, false, true); if (door.IsOpen) door.SetState(false,false,true);
} }
var shuttleGaps = Gap.GapList.FindAll(g => g.Submarine == respawnShuttle && g.ConnectedWall != null); var shuttleGaps = Gap.GapList.FindAll(g => g.Submarine == respawnShuttle && g.ConnectedWall != null);