Merge remote-tracking branch 'refs/remotes/barotrauma/combat-mission'

Conflicts:
	Subsurface/Source/GUI/GUIListBox.cs
This commit is contained in:
juanjp600
2016-10-04 22:30:29 -03:00
29 changed files with 525 additions and 440 deletions

View File

@@ -168,6 +168,7 @@
<Compile Include="Source\Screens\BlurEffect.cs" />
<Compile Include="Source\Screens\NetLobbyVoting.cs" />
<Compile Include="Source\Screens\ServerListScreen.cs" />
<Compile Include="Source\Timing.cs" />
<Compile Include="Source\Utils\MTRandom.cs" />
<Compile Include="Source\Utils\Rand.cs" />
<Compile Include="Source\Events\PropertyTask.cs" />

View File

@@ -127,9 +127,9 @@ namespace Barotrauma
public void UpdateTransform(bool interpolate = true, bool clampPos = false)
{
Vector2 interpolatedPosition = interpolate ? Physics.Interpolate(prevPosition, position) : position;
Vector2 interpolatedPosition = interpolate ? Timing.Interpolate(prevPosition, position) : position;
float interpolatedZoom = interpolate ? Physics.Interpolate(prevZoom, zoom) : zoom;
float interpolatedZoom = interpolate ? Timing.Interpolate(prevZoom, zoom) : zoom;
worldView.X = (int)(interpolatedPosition.X - worldView.Width / 2.0);
worldView.Y = (int)(interpolatedPosition.Y + worldView.Height / 2.0);

View File

@@ -46,6 +46,19 @@ namespace Barotrauma
if (suicideButton != null && suicideButton.Visible) suicideButton.Update(deltaTime);
if (damageOverlayTimer > 0.0f) damageOverlayTimer -= deltaTime;
if (!character.IsUnconscious && character.Stun <= 0.0f)
{
if (character.Inventory != null && !character.LockHands && character.Stun >= -0.1f)
{
character.Inventory.Update(deltaTime);
}
if (character.SelectedCharacter != null && character.SelectedCharacter.Inventory != null)
{
character.SelectedCharacter.Inventory.Update(deltaTime);
}
}
}
public static void Draw(SpriteBatch spriteBatch, Character character, Camera cam)
@@ -84,12 +97,15 @@ namespace Barotrauma
if (!character.IsUnconscious && character.Stun <= 0.0f)
{
if (character.Inventory != null && !character.LockHands &&
character.Stun >= -0.1f) character.Inventory.DrawOwn(spriteBatch, Vector2.Zero);
if (character.Inventory != null && !character.LockHands && character.Stun >= -0.1f)
{
character.Inventory.DrawOwn(spriteBatch);
}
if (character.SelectedCharacter != null && character.SelectedCharacter.Inventory != null)
{
character.SelectedCharacter.Inventory.DrawOwn(spriteBatch, new Vector2(320.0f, 0.0f));
character.SelectedCharacter.Inventory.DrawOffset = new Vector2(320.0f, 0.0f);
character.SelectedCharacter.Inventory.DrawOwn(spriteBatch);
if (cprButton == null)
{

View File

@@ -472,12 +472,12 @@ namespace Barotrauma
{
if (pauseMenuOpen)
{
pauseMenu.Update(0.016f);
pauseMenu.Update(deltaTime);
}
if (settingsMenuOpen)
{
GameMain.Config.SettingsFrame.Update(0.016f);
GameMain.Config.SettingsFrame.Update(deltaTime);
}
if (GUIMessageBox.MessageBoxes.Count > 0)

View File

@@ -287,6 +287,36 @@ namespace Barotrauma
{
scrollBar.BarScroll -= (PlayerInput.ScrollWheelSpeed / 500.0f) * BarSize;
}
for (int i = 0; i < children.Count; i++)
{
GUIComponent child = children[i];
if (child == frame || !child.Visible) continue;
if (enabled && child.CanBeFocused &&
(MouseOn == this || (MouseOn != null && this.IsParentOf(MouseOn))) && child.Rect.Contains(PlayerInput.MousePosition))
{
child.State = ComponentState.Hover;
if (PlayerInput.LeftButtonClicked())
{
Debug.WriteLine("clicked");
Select(i);
}
}
else if (selected.Contains(child))
{
child.State = ComponentState.Selected;
if (CheckSelected != null)
{
if (CheckSelected() != child.UserData) selected.Remove(child);
}
}
else
{
child.State = ComponentState.None;
}
}
}
public void Select(int childIndex, bool force = false)
@@ -448,7 +478,7 @@ namespace Barotrauma
continue;
}
}
child.Draw(spriteBatch);
}

View File

@@ -217,6 +217,24 @@ namespace Barotrauma
if (flashTimer > 0.0f) flashTimer -= deltaTime;
if (!Enabled) return;
if (rect.Contains(PlayerInput.MousePosition) && Enabled &&
(MouseOn == null || MouseOn == this || IsParentOf(MouseOn) || MouseOn.IsParentOf(this)))
{
state = ComponentState.Hover;
if (PlayerInput.LeftButtonClicked())
{
Select();
if (OnSelected != null) OnSelected(this, Keys.None);
}
}
else
{
state = ComponentState.None;
}
textBlock.State = state;
if (CaretEnabled)
{
caretTimer += deltaTime;
@@ -248,24 +266,6 @@ namespace Barotrauma
{
if (!Visible) return;
if (rect.Contains(PlayerInput.MousePosition) && Enabled &&
(MouseOn == null || MouseOn == this || IsParentOf(MouseOn) || MouseOn.IsParentOf(this)))
{
state = ComponentState.Hover;
if (PlayerInput.LeftButtonClicked())
{
Select();
if (OnSelected != null) OnSelected(this, Keys.None);
}
}
else
{
state = ComponentState.None;
}
textBlock.State = state;
DrawChildren(spriteBatch);
if (!CaretEnabled) return;
@@ -279,7 +279,6 @@ namespace Barotrauma
new Vector2((int)caretPos.X + 2, caretPos.Y + Font.MeasureString("I").Y - 3),
textBlock.TextColor * (textBlock.TextColor.A / 255.0f));
}
}
public void ReceiveTextInput(char inputChar)

View File

@@ -127,9 +127,13 @@ namespace Barotrauma
}
}
spriteBatch.DrawString(GUI.LargeFont, loadText,
new Vector2(GameMain.GraphicsWidth/2.0f - GUI.LargeFont.MeasureString(loadText).X/2.0f, GameMain.GraphicsHeight*0.8f),
Color.White);
if (GUI.LargeFont!=null)
{
spriteBatch.DrawString(GUI.LargeFont, loadText,
new Vector2(GameMain.GraphicsWidth/2.0f - GUI.LargeFont.MeasureString(loadText).X/2.0f, GameMain.GraphicsHeight*0.8f),
Color.White);
}
}
spriteBatch.End();

View File

@@ -72,7 +72,6 @@ namespace Barotrauma
private bool hasLoaded;
private GameTime fixedTime;
private double updatesToMake;
//public static Random localRandom;
//public static Random random;
@@ -142,7 +141,7 @@ namespace Barotrauma
IsFixedTimeStep = false;
//TargetElapsedTime = new TimeSpan(0, 0, 0, 0, 55);
updatesToMake = 0.0;
Timing.Accumulator = 0.0f;
fixedTime = new GameTime();
World = new World(new Vector2(0, -9.82f));
@@ -291,51 +290,59 @@ namespace Barotrauma
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Update(GameTime gameTime)
{
double realDeltaTime = gameTime.ElapsedGameTime.TotalSeconds;
double deltaTime = 0.016;
updatesToMake += realDeltaTime;
Timing.Accumulator += gameTime.ElapsedGameTime.TotalSeconds;
while (updatesToMake > 0.0)
while (Timing.Accumulator >= Timing.Step)
{
fixedTime.IsRunningSlowly = gameTime.IsRunningSlowly;
TimeSpan addTime = new TimeSpan(0, 0, 0, 0, 16);
fixedTime.ElapsedGameTime = addTime;
fixedTime.TotalGameTime.Add(addTime);
base.Update(fixedTime);
PlayerInput.Update(deltaTime);
PlayerInput.Update(Timing.Step);
bool paused = false;
if (hasLoaded && !titleScreenOpen)
if (titleScreenOpen)
{
if (TitleScreen.LoadState >= 100.0f &&
(!waitForKeyHit || PlayerInput.GetKeyboardState.GetPressedKeys().Length>0 || PlayerInput.LeftButtonClicked()))
{
titleScreenOpen = false;
}
}
else if (hasLoaded)
{
SoundPlayer.Update();
if (PlayerInput.KeyHit(Keys.Escape)) GUI.TogglePauseMenu();
DebugConsole.Update(this, (float)deltaTime);
DebugConsole.Update(this, (float)Timing.Step);
paused = (DebugConsole.IsOpen || GUI.PauseMenuOpen || GUI.SettingsMenuOpen) &&
(NetworkMember == null || !NetworkMember.GameStarted);
if (!paused) Screen.Selected.Update(deltaTime);
if (!paused)
{
Screen.Selected.Update(Timing.Step);
}
if (NetworkMember != null)
{
NetworkMember.Update((float)deltaTime);
}
else
{
NetworkEvent.Events.Clear();
NetworkMember.Update((float)Timing.Step);
}
GUI.Update((float)deltaTime);
GUI.Update((float)Timing.Step);
}
CoroutineManager.Update((float)deltaTime, paused ? 0.0f : (float)deltaTime);
CoroutineManager.Update((float)Timing.Step, paused ? 0.0f : (float)Timing.Step);
updatesToMake -= deltaTime;
Timing.Accumulator -= Timing.Step;
}
Timing.Alpha = Timing.Accumulator / Timing.Step;
}
@@ -344,8 +351,6 @@ namespace Barotrauma
/// </summary>
protected override void Draw(GameTime gameTime)
{
//renderTimer.Restart();
double deltaTime = gameTime.ElapsedGameTime.TotalSeconds;
FrameCounter.Update(deltaTime);
@@ -353,22 +358,11 @@ namespace Barotrauma
if (titleScreenOpen)
{
TitleScreen.Draw(spriteBatch, GraphicsDevice, (float)deltaTime);
if (TitleScreen.LoadState>=100.0f &&
(!waitForKeyHit || PlayerInput.GetKeyboardState.GetPressedKeys().Length>0 || PlayerInput.LeftButtonClicked()))
{
titleScreenOpen = false;
}
}
else if (hasLoaded)
{
Screen.Selected.Draw(deltaTime, GraphicsDevice, spriteBatch);
}
//double elapsed = sw.Elapsed.TotalSeconds;
//if (elapsed < Physics.step)
//{
// System.Threading.Thread.Sleep((int)((Physics.step - elapsed) * 1000.0));
//}
}
static bool waitForKeyHit = true;

View File

@@ -317,19 +317,15 @@ namespace Barotrauma
if (gameMode != null) gameMode.Update(deltaTime);
if (Mission != null) Mission.Update(deltaTime);
if (infoFrame != null) infoFrame.Update(deltaTime);
}
public void Draw(SpriteBatch spriteBatch)
{
//guiRoot.Draw(spriteBatch);
infoButton.Draw(spriteBatch);
if (gameMode != null) gameMode.Draw(spriteBatch);
if (infoFrame != null)
{
infoFrame.Update(0.016f);
infoFrame.Draw(spriteBatch);
}
if (infoFrame != null) infoFrame.Draw(spriteBatch);
}
public void Save(string filePath)

View File

@@ -278,12 +278,43 @@ namespace Barotrauma
return TryPutItem(item, new List<InvSlotType>() {placeToSlots}, createNetworkEvent);
}
public void DrawOwn(SpriteBatch spriteBatch, Vector2 offset)
{
string toolTip = "";
Rectangle highlightedSlot = Rectangle.Empty;
protected override void PutItem(Item item, int i, bool createNetworkEvent, bool removeItem = true)
{
base.PutItem(item, i, createNetworkEvent, removeItem);
CreateSlots();
}
public override void RemoveItem(Item item)
{
base.RemoveItem(item);
CreateSlots();
}
protected override void CreateSlots()
{
slots = new InventorySlot[capacity];
int rectWidth = 40, rectHeight = 40;
Rectangle slotRect = new Rectangle(0, 0, rectWidth, rectHeight);
for (int i = 0; i < capacity; i++)
{
slotRect.X = (int)(SlotPositions[i].X + DrawOffset.X);
slotRect.Y = (int)(SlotPositions[i].Y + DrawOffset.Y);
slots[i] = new InventorySlot(slotRect);
slots[i].Color = limbSlots[i] == InvSlotType.Any ? Color.White * 0.2f : Color.White * 0.4f;
}
MergeSlots();
}
public override void Update(float deltaTime)
{
base.Update(deltaTime);
if (doubleClickedItem != null)
{
if (doubleClickedItem.ParentInventory != this)
@@ -309,7 +340,7 @@ namespace Barotrauma
//not equipped -> attempt to equip
if (IsInLimbSlot(doubleClickedItem, InvSlotType.Any))
{
TryPutItem(doubleClickedItem, doubleClickedItem.AllowedSlots.FindAll(i => i != InvSlotType.Any), true);
TryPutItem(doubleClickedItem, doubleClickedItem.AllowedSlots.FindAll(i => i != InvSlotType.Any), true);
}
//equipped -> attempt to unequip
else if (doubleClickedItem.AllowedSlots.Contains(InvSlotType.Any))
@@ -319,17 +350,77 @@ namespace Barotrauma
}
}
}
if (selectedSlot > -1)
{
UpdateSubInventory(deltaTime, selectedSlot);
}
if (character == Character.Controlled)
{
for (int i = 0; i < capacity; i++)
{
if (selectedSlot != i &&
Items[i] != null && Items[i].CanUseOnSelf && character.HasSelectedItem(Items[i]))
{
//-3 because selected items are in slots 3 and 4 (hands)
useOnSelfButton[i - 3].Update(deltaTime);
}
}
}
//cancel dragging if too far away from the container of the dragged item
if (draggingItem != null)
{
var rootContainer = draggingItem.GetRootContainer();
var rootInventory = draggingItem.ParentInventory;
if (rootContainer != null)
{
rootInventory = rootContainer.ParentInventory != null ?
rootContainer.ParentInventory : rootContainer.GetComponent<Items.Components.ItemContainer>().Inventory;
}
if (rootInventory != null &&
rootInventory.Owner != Character.Controlled &&
rootInventory.Owner != Character.Controlled.SelectedConstruction &&
rootInventory.Owner != Character.Controlled.SelectedCharacter)
{
draggingItem = null;
}
}
doubleClickedItem = null;
}
const int rectWidth = 40, rectHeight = 40;
Rectangle slotRect = new Rectangle(0, 0, rectWidth, rectHeight);
Rectangle draggingItemSlot = slotRect;
private void MergeSlots()
{
for (int i = 0; i < capacity-1; i++)
{
if (slots[i].Disabled || Items[i] == null) continue;
for (int n = i+1; n < capacity; n++)
{
if (Items[n] == Items[i])
{
slots[i].Rect = Rectangle.Union(slots[i].Rect, slots[n].Rect);
slots[n].Disabled = true;
}
}
}
}
public void DrawOwn(SpriteBatch spriteBatch)
{
if (slots == null) CreateSlots();
Rectangle slotRect = new Rectangle(0, 0, 40, 40);
for (int i = 0; i < capacity; i++)
{
slotRect.X = (int)(SlotPositions[i].X + offset.X);
slotRect.Y = (int)(SlotPositions[i].Y + offset.Y);
slotRect.X = (int)(SlotPositions[i].X + DrawOffset.X);
slotRect.Y = (int)(SlotPositions[i].Y + DrawOffset.Y);
if (i==1) //head
{
@@ -353,149 +444,31 @@ namespace Barotrauma
SpriteEffects.None, 0.1f);
}
}
base.Draw(spriteBatch);
for (int i = 0; i < capacity; i++)
if (character == Character.Controlled)
{
slotRect.X = (int)(SlotPositions[i].X + offset.X);
slotRect.Y = (int)(SlotPositions[i].Y + offset.Y);
bool multiSlot = false;
//skip if the item is in multiple slots
if (Items[i]!=null)
{
for (int n = 0; n < capacity; n++ )
{
if (i==n || Items[n] != Items[i]) continue;
multiSlot = true;
break;
}
}
if (multiSlot) continue;
if (Items[i] != null && slotRect.Contains(PlayerInput.MousePosition) && (selectedSlot == -1 || selectedSlot == i))
for (int i = 0; i < capacity; i++)
{
if (GameMain.DebugDraw)
if (selectedSlot != i &&
Items[i] != null && Items[i].CanUseOnSelf && character.HasSelectedItem(Items[i]))
{
toolTip = Items[i].ToString();
useOnSelfButton[i - 3].Draw(spriteBatch);
}
else
{
toolTip = string.IsNullOrEmpty(Items[i].Description) ? Items[i].Name : Items[i].Name + '\n' + Items[i].Description;
}
highlightedSlot = slotRect;
}
if (selectedSlot == i) highlightedSlot = slotRect;
UpdateSlot(spriteBatch, slotRect, i, Items[i], false, i>5 ? 0.2f : 0.4f);
if (draggingItem!=null && draggingItem == Items[i]) draggingItemSlot = slotRect;
}
for (int i = 0; i < capacity; i++)
{
bool multiSlot = false;
//check if the item is in multiple slots
if (Items[i] != null)
{
slotRect.X = (int)(SlotPositions[i].X + offset.X);
slotRect.Y = (int)(SlotPositions[i].Y + offset.Y);
slotRect.Width = 40;
slotRect.Height = 40;
for (int n = 0; n < capacity; n++)
{
if (Items[n] != Items[i]) continue;
if (!multiSlot && i > n) break;
if (i!=n)
{
multiSlot = true;
slotRect = Rectangle.Union(
new Rectangle((int)(SlotPositions[n].X+offset.X), (int)(SlotPositions[n].Y+offset.Y), rectWidth, rectHeight), slotRect);
}
}
}
if (multiSlot)
{
if (Items[i] != null && slotRect.Contains(PlayerInput.MousePosition) && (selectedSlot==-1 || selectedSlot==i))
{
toolTip = string.IsNullOrEmpty(Items[i].Description) ? Items[i].Name : Items[i].Name + '\n' + Items[i].Description;
highlightedSlot = slotRect;
}
if (selectedSlot == i) highlightedSlot = slotRect;
UpdateSlot(spriteBatch, slotRect, i, Items[i], i > 4);
}
if (character==Character.Controlled && selectedSlot != i &&
Items[i] != null && Items[i].CanUseOnSelf && character.HasSelectedItem(Items[i]))
{
useOnSelfButton[i - 3].Update(0.016f);
useOnSelfButton[i - 3].Draw(spriteBatch);
}
}
if (selectedSlot > -1)
{
DrawSubInventory(spriteBatch, highlightedSlot, selectedSlot);
}
DrawSubInventory(spriteBatch, selectedSlot);
slotRect.Width = rectWidth;
slotRect.Height = rectHeight;
if (!string.IsNullOrWhiteSpace(toolTip))
{
DrawToolTip(spriteBatch, toolTip, highlightedSlot);
}
if (draggingItem == null) return;
var rootContainer = draggingItem.GetRootContainer();
var rootInventory = draggingItem.ParentInventory;
if (rootContainer != null)
{
rootInventory = rootContainer.ParentInventory != null ?
rootContainer.ParentInventory : rootContainer.GetComponent<Items.Components.ItemContainer>().Inventory;
}
if (rootInventory != null &&
rootInventory.Owner != Character.Controlled &&
rootInventory.Owner != Character.Controlled.SelectedConstruction &&
rootInventory.Owner != Character.Controlled.SelectedCharacter)
{
draggingItem = null;
return;
}
if (!draggingItemSlot.Contains(PlayerInput.MousePosition))
{
if (PlayerInput.LeftButtonHeld())
if (selectedSlot > -1 &&
!slots[selectedSlot].IsHighlighted &&
(draggingItem == null || draggingItem.Container != Items[selectedSlot]))
{
slotRect.X = (int)PlayerInput.MousePosition.X - slotRect.Width / 2;
slotRect.Y = (int)PlayerInput.MousePosition.Y - slotRect.Height / 2;
DrawSlot(spriteBatch, slotRect, draggingItem, false, false);
selectedSlot = -1;
}
else
{
DropItem(draggingItem);
new NetworkEvent(NetworkEventType.DropItem, draggingItem.ID, true);
//draggingItem = null;
}
}
}

View File

@@ -214,10 +214,13 @@ namespace Barotrauma.Items.Components
}
}
public override void UpdateHUD(Character character)
{
Inventory.Update((float)Timing.Step);
}
public override void DrawHUD(SpriteBatch spriteBatch, Character character)
{
if (!drawInventory && false) return;
Inventory.Draw(spriteBatch);
}

View File

@@ -87,7 +87,7 @@ namespace Barotrauma.Items.Components
public override void UpdateHUD(Character character)
{
GuiFrame.Update((float)Physics.step);
GuiFrame.Update((float)Timing.Step);
}
private bool ToggleActive(GUIButton button, object obj)

View File

@@ -350,7 +350,7 @@ namespace Barotrauma.Items.Components
activateButton.Enabled = CanBeFabricated(targetItem, character);
}
GuiFrame.Update((float)Physics.step);
GuiFrame.Update((float)Timing.Step);
}
private bool CanBeFabricated(FabricableItem fabricableItem, Character user)

View File

@@ -366,7 +366,7 @@ namespace Barotrauma.Items.Components
break;
case "trigger_in":
item.Use((float)Physics.step, null);
item.Use((float)Timing.Step, null);
break;
}
}

View File

@@ -202,7 +202,7 @@ namespace Barotrauma
if (frame == null) return;
frame.Update((float)Physics.step);
frame.Update((float)Timing.Step);
}
}
}

View File

@@ -6,12 +6,43 @@ using Microsoft.Xna.Framework.Input;
using Barotrauma.Networking;
using System;
using System.Collections.Generic;
using Barotrauma.Items.Components;
namespace Barotrauma
{
class InventorySlot
{
public Rectangle Rect;
public GUIComponent.ComponentState State;
public bool Disabled;
public bool IsHighlighted
{
get
{
return State == GUIComponent.ComponentState.Hover;
}
}
public Color Color;
public InventorySlot(Rectangle rect)
{
Rect = rect;
State = GUIComponent.ComponentState.None;
Color = Color.White * 0.4f;
}
}
class Inventory
{
public static InventorySlot draggingSlot;
public static Item draggingItem;
public static Item doubleClickedItem;
public readonly Entity Owner;
@@ -31,6 +62,8 @@ namespace Barotrauma
protected int selectedSlot = -1;
protected InventorySlot[] slots;
public Item[] Items;
public bool Locked;
@@ -46,6 +79,23 @@ namespace Barotrauma
}
}
private Vector2 drawOffset;
public Vector2 DrawOffset
{
get
{
return drawOffset;
}
set
{
if (value == drawOffset) return;
drawOffset = value;
CreateSlots();
}
}
public Inventory(Entity owner, int capacity, Vector2? centerPos = null, int slotsPerRow=5)
{
this.capacity = capacity;
@@ -116,7 +166,7 @@ namespace Barotrauma
}
}
protected void PutItem(Item item, int i, bool createNetworkEvent, bool removeItem = true)
protected virtual void PutItem(Item item, int i, bool createNetworkEvent, bool removeItem = true)
{
if (Owner == null) return;
@@ -143,7 +193,7 @@ namespace Barotrauma
return Items.FirstOrDefault(i => i != null && (i.Name == itemName || i.HasTag(itemName)));
}
public void RemoveItem(Item item)
public virtual void RemoveItem(Item item)
{
if (item == null) return;
@@ -161,72 +211,90 @@ namespace Barotrauma
item.Drop(null, false);
return;
}
//public void DropItem(int i)
//{
// items[i].Drop();
// items[i] = null;
//}
public virtual void Draw(SpriteBatch spriteBatch)
protected virtual void CreateSlots()
{
string toolTip = "";
slots = new InventorySlot[capacity];
int rectWidth = 40, rectHeight = 40;
Rectangle highlightedSlot = Rectangle.Empty;
int spacing = 10;
int rows = (int)Math.Ceiling((double)capacity / slotsPerRow);
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;
selectedSlot = -1;
for (int i = 0; i < capacity; i++)
{
slotRect.X = startX + (rectWidth + spacing) * (i % slotsPerRow);
slotRect.Y = startY + (rectHeight + spacing) * ((int)Math.Floor((double)i / slotsPerRow));
slotRect.X = startX + (rectWidth + spacing) * (i % slotsPerRow) + (int)DrawOffset.X;
slotRect.Y = startY + (rectHeight + spacing) * ((int)Math.Floor((double)i / slotsPerRow)) + (int)DrawOffset.Y;
if (draggingItem == Items[i]) draggingItemSlot = slotRect;
slots[i] = new InventorySlot(slotRect);
}
}
UpdateSlot(spriteBatch, slotRect, i, Items[i], false);
if (slotRect.Contains(PlayerInput.MousePosition) && Items[i] != null)
{
highlightedSlot = slotRect;
toolTip = GameMain.DebugDraw ? Items[i].ToString() : Items[i].Name;
}
public virtual void Update(float deltaTime)
{
if (slots == null) CreateSlots();
for (int i = 0; i < capacity; i++)
{
if (slots[i].Disabled) continue;
UpdateSlot(slots[i], i, Items[i], false);
}
if (draggingItem != null && !draggingItemSlot.Contains(PlayerInput.MousePosition) && draggingItem.Container == this.Owner)
{
if (PlayerInput.LeftButtonHeld())
{
slotRect.X = (int)PlayerInput.MousePosition.X - slotRect.Width / 2;
slotRect.Y = (int)PlayerInput.MousePosition.Y - slotRect.Height / 2;
//GUI.DrawRectangle(spriteBatch, rect, Color.White, true);
//draggingItem.sprite.Draw(spriteBatch, new Vector2(rect.X + rect.Width / 2, rect.Y + rect.Height / 2), Color.White);
DrawSlot(spriteBatch, slotRect, draggingItem, false, false);
}
else
if (draggingItem != null && !draggingSlot.Rect.Contains(PlayerInput.MousePosition) && draggingItem.ParentInventory == this)
{
if (!PlayerInput.LeftButtonHeld())
{
if (Owner!=null)
if (Owner != null)
{
new NetworkEvent(NetworkEventType.InventoryUpdate, Owner.ID, true);
}
DropItem(draggingItem);
//draggingItem = null;
}
}
if (!string.IsNullOrWhiteSpace(toolTip))
}
public virtual void Draw(SpriteBatch spriteBatch)
{
string toolTip = "";
if (slots == null) CreateSlots();
for (int i = 0; i < capacity; i++)
{
DrawToolTip(spriteBatch, toolTip, highlightedSlot);
if (slots[i].Disabled) continue;
//don't draw the slot if dragged an item out of it
bool drawItem = draggingItem == null || draggingItem != Items[i] || slots[i].IsHighlighted;
DrawSlot(spriteBatch, slots[i], Items[i], drawItem);
}
if (draggingItem != null &&
!draggingSlot.Rect.Contains(PlayerInput.MousePosition) &&
draggingItem.ParentInventory == this)
{
Rectangle dragRect = new Rectangle(
(int)PlayerInput.MousePosition.X - 10,
(int)PlayerInput.MousePosition.Y - 10,
40, 40);
DrawSlot(spriteBatch, new InventorySlot(dragRect), draggingItem);
}
for (int i = 0; i < capacity; i++)
{
if (slots[i].IsHighlighted && !slots[i].Disabled)
{
DrawToolTip(spriteBatch, toolTip, slots[i].Rect);
break;
}
}
}
@@ -251,12 +319,21 @@ namespace Barotrauma
1.0f, SpriteEffects.None, 0.0f);
}
protected void UpdateSlot(SpriteBatch spriteBatch, Rectangle rect, int slotIndex, Item item, bool isSubSlot, float alpha = 0.4f, bool drawItem=true)
protected void UpdateSlot(InventorySlot slot, int slotIndex, Item item, bool isSubSlot)
{
bool mouseOn = rect.Contains(PlayerInput.MousePosition) && !Locked;
bool mouseOn = slot.Rect.Contains(PlayerInput.MousePosition) && !Locked;
if (mouseOn)
slot.State = GUIComponent.ComponentState.None;
if (!(this is CharacterInventory) && !mouseOn && selectedSlot==slotIndex)
{
selectedSlot = -1;
}
if (mouseOn &&
(draggingItem!=null || selectedSlot==slotIndex || selectedSlot==-1))
{
slot.State = GUIComponent.ComponentState.Hover;
if (!isSubSlot && selectedSlot == -1)
{
@@ -265,9 +342,10 @@ namespace Barotrauma
if (draggingItem == null)
{
if (PlayerInput.LeftButtonHeld() && selectedSlot == slotIndex)
if (PlayerInput.LeftButtonHeld())
{
draggingItem = item;
draggingItem = Items[slotIndex];
draggingSlot = slot;
}
}
else if (PlayerInput.LeftButtonReleased())
@@ -280,22 +358,38 @@ namespace Barotrauma
//selectedSlot = slotIndex;
TryPutItem(draggingItem, slotIndex, true, true);
draggingItem = null;
draggingSlot = null;
}
}
DrawSlot(spriteBatch, rect, (draggingItem == item && !mouseOn) ? null : item, mouseOn && selectedSlot == slotIndex, isSubSlot, alpha, drawItem);
}
public void DrawSubInventory(SpriteBatch spriteBatch, Rectangle rect, int slotIndex)
public void UpdateSubInventory(float deltaTime, int slotIndex)
{
var item = Items[slotIndex];
if (item == null) return;
selectedSlot = -1;
var container = item.GetComponent<ItemContainer>();
if (container == null) return;
int itemCapacity = item == null ? 0 : item.Capacity;
if (itemCapacity == 0) return;
if (container.Inventory.slots == null) container.Inventory.CreateSlots();
slots[slotIndex].State = GUIComponent.ComponentState.Hover;
container.Inventory.Update(deltaTime);
}
public void DrawSubInventory(SpriteBatch spriteBatch, int slotIndex)
{
var item = Items[slotIndex];
if (item == null) return;
var container = item.GetComponent<ItemContainer>();
if (container == null) return;
if (container.Inventory.slots == null) container.Inventory.CreateSlots();
int itemCapacity = container.Capacity;
#if DEBUG
System.Diagnostics.Debug.Assert(slotIndex >= 0 && slotIndex < Items.Length);
@@ -303,59 +397,37 @@ namespace Barotrauma
if (slotIndex < 0 || slotIndex >= Items.Length) return;
#endif
Rectangle containerRect = new Rectangle(rect.X - 5, rect.Y - (40 + 10) * itemCapacity - 5,
rect.Width + 10, rect.Height + (40 + 10) * itemCapacity + 10);
var slot = slots[slotIndex];
Rectangle containerRect = new Rectangle(slot.Rect.X - 5, slot.Rect.Y - (40 + 10) * itemCapacity - 5,
slot.Rect.Width + 10, slot.Rect.Height + (40 + 10) * itemCapacity + 10);
Rectangle subRect = rect;
Rectangle subRect = slot.Rect;
subRect.Height = 40;
selectedSlot = containerRect.Contains(PlayerInput.MousePosition) && !Locked ? slotIndex : -1;
GUI.DrawRectangle(spriteBatch, new Rectangle(containerRect.X, containerRect.Y, containerRect.Width, containerRect.Height - 50), Color.Black * 0.8f, true);
GUI.DrawRectangle(spriteBatch, new Rectangle(containerRect.X, containerRect.Y, containerRect.Width, containerRect.Height - slot.Rect.Height - 5), Color.Black * 0.8f, true);
GUI.DrawRectangle(spriteBatch, containerRect, Color.White);
Item[] containedItems = null;
if (Items[slotIndex] != null) containedItems = Items[slotIndex].ContainedItems;
string toolTip = "";
Rectangle highlightedRect = Rectangle.Empty;
if (containedItems != null)
for (int i = 0; i < itemCapacity; i++)
{
for (int i = 0; i < itemCapacity; i++)
{
subRect.Y = subRect.Y - subRect.Height - 10;
highlightedRect = subRect;
UpdateSlot(spriteBatch, subRect, selectedSlot, i < containedItems.Length ? containedItems[i] : null, true);
if (i >= containedItems.Length || containedItems[i] == null) continue;
if (highlightedRect.Contains(PlayerInput.MousePosition))
{
if (GameMain.DebugDraw)
{
toolTip = containedItems[i].ToString();
}
else
{
toolTip = string.IsNullOrEmpty(containedItems[i].Description) ?
containedItems[i].Name :
containedItems[i].Name + '\n' + containedItems[i].Description;
}
}
}
subRect.Y = subRect.Y - subRect.Height - 10;
container.Inventory.slots[i].Rect = subRect;
}
if (!string.IsNullOrWhiteSpace(toolTip)) DrawToolTip(spriteBatch, toolTip, highlightedRect);
container.Inventory.Draw(spriteBatch);
if (!containerRect.Contains(PlayerInput.MousePosition))
{
if (draggingItem == null || draggingItem.Container != item) selectedSlot = -1;
}
}
protected void DrawSlot(SpriteBatch spriteBatch, Rectangle rect, Item item, bool isHighLighted, bool isSubSlot, float alpha=0.4f, bool drawItem=true)
protected void DrawSlot(SpriteBatch spriteBatch, InventorySlot slot, Item item, bool drawItem=true)
{
GUI.DrawRectangle(spriteBatch, rect, (isHighLighted ? Color.Red : Color.White) * alpha*0.75f, true);
Rectangle rect = slot.Rect;
GUI.DrawRectangle(spriteBatch, rect, (slot.IsHighlighted ? Color.Red * 0.4f : slot.Color), true);
if (item != null)
if (item != null && drawItem)
{
if (item.Condition < 100.0f)
{
@@ -365,21 +437,17 @@ namespace Barotrauma
Color.Lerp(Color.Red, Color.Green, item.Condition / 100.0f)*0.8f, true);
}
if (!isHighLighted)
var containedItems = item.ContainedItems;
if (containedItems != null && containedItems.Length == 1 && containedItems[0].Condition < 100.0f)
{
var containedItems = item.ContainedItems;
if (containedItems != null && containedItems.Length == 1 && containedItems[0].Condition < 100.0f)
{
GUI.DrawRectangle(spriteBatch, new Rectangle(rect.X, rect.Y, rect.Width, 8), Color.Black*0.8f, true);
GUI.DrawRectangle(spriteBatch,
new Rectangle(rect.X, rect.Y, (int)(rect.Width * containedItems[0].Condition / 100.0f), 8),
Color.Lerp(Color.Red, Color.Green, containedItems[0].Condition / 100.0f)*0.8f, true);
}
}
GUI.DrawRectangle(spriteBatch, new Rectangle(rect.X, rect.Y, rect.Width, 8), Color.Black*0.8f, true);
GUI.DrawRectangle(spriteBatch,
new Rectangle(rect.X, rect.Y, (int)(rect.Width * containedItems[0].Condition / 100.0f), 8),
Color.Lerp(Color.Red, Color.Green, containedItems[0].Condition / 100.0f)*0.8f, true);
}
}
GUI.DrawRectangle(spriteBatch, rect, (isHighLighted ? Color.Red : Color.White) * alpha, false);
GUI.DrawRectangle(spriteBatch, rect, (slot.IsHighlighted ? Color.Red * 0.4f : slot.Color), false);
if (item == null || !drawItem) return;

View File

@@ -923,7 +923,7 @@ namespace Barotrauma
}
editingHUD.Draw(spriteBatch);
editingHUD.Update((float)Physics.step);
editingHUD.Update((float)Timing.Step);
if (!prefab.IsLinkable) return;
@@ -951,7 +951,7 @@ namespace Barotrauma
if (editingHUD.Rect.Height > 60)
{
editingHUD.Update((float)Physics.step);
editingHUD.Update((float)Timing.Step);
editingHUD.Draw(spriteBatch);
}
}

View File

@@ -156,8 +156,8 @@ namespace Barotrauma
editingHUD = CreateEditingHUD();
}
editingHUD.Update(0.016f);
editingHUD.Draw(spriteBatch);
editingHUD.Update((float)Physics.step);
if (!PlayerInput.LeftButtonClicked() || !PlayerInput.KeyDown(Keys.Space)) return;

View File

@@ -254,20 +254,18 @@ namespace Barotrauma
currentLocation.Discovered = true;
}
public void Draw(SpriteBatch spriteBatch, Rectangle rect, float scale = 1.0f)
public void Update(float deltaTime, Rectangle rect, float scale = 1.0f)
{
Vector2 rectCenter = new Vector2(rect.Center.X, rect.Center.Y);
Vector2 offset = -currentLocation.MapPosition;
iceTexture.DrawTiled(spriteBatch, new Vector2(rect.X, rect.Y), new Vector2(rect.Width, rect.Height), Vector2.Zero, Color.White*0.8f);
float maxDist = 20.0f;
float closestDist = 0.0f;
highlightedLocation = null;
for (int i = 0; i < locations.Count;i++ )
for (int i = 0; i < locations.Count; i++)
{
Location location = locations[i];
Vector2 pos = rectCenter + (location.MapPosition+offset) * scale;
Vector2 pos = rectCenter + (location.MapPosition + offset) * scale;
if (!rect.Contains(pos)) continue;
@@ -281,21 +279,30 @@ namespace Barotrauma
foreach (LocationConnection connection in connections)
{
Color crackColor = Color.White * Math.Max(connection.Difficulty/100.0f, 1.5f);
if (highlightedLocation != currentLocation &&
connection.Locations.Contains(highlightedLocation) && connection.Locations.Contains(currentLocation))
{
crackColor = Color.Red;
if (PlayerInput.LeftButtonClicked()&&
if (PlayerInput.LeftButtonClicked() &&
selectedLocation != highlightedLocation && highlightedLocation != null)
{
selectedConnection = connection;
selectedLocation = highlightedLocation;
GameMain.LobbyScreen.SelectLocation(highlightedLocation, connection);
}
selectedLocation = highlightedLocation;
GameMain.LobbyScreen.SelectLocation(highlightedLocation, connection);
}
}
}
}
public void Draw(SpriteBatch spriteBatch, Rectangle rect, float scale = 1.0f)
{
Vector2 rectCenter = new Vector2(rect.Center.X, rect.Center.Y);
Vector2 offset = -currentLocation.MapPosition;
iceTexture.DrawTiled(spriteBatch, new Vector2(rect.X, rect.Y), new Vector2(rect.Width, rect.Height), Vector2.Zero, Color.White*0.8f);
foreach (LocationConnection connection in connections)
{
Color crackColor = Color.White * Math.Max(connection.Difficulty/100.0f, 1.5f);
if (selectedLocation != currentLocation &&
(connection.Locations.Contains(selectedLocation) && connection.Locations.Contains(currentLocation)))

View File

@@ -323,7 +323,7 @@ namespace Barotrauma
public void UpdateTransform()
{
DrawPosition = Physics.Interpolate(prevPosition, Position);
DrawPosition = Timing.Interpolate(prevPosition, Position);
}
//math/physics stuff ----------------------------------------------------

View File

@@ -178,7 +178,7 @@ namespace Barotrauma
editingHUD = CreateEditingHUD();
}
editingHUD.Update((float)Physics.step);
editingHUD.Update((float)Timing.Step);
editingHUD.Draw(spriteBatch);
if (!PlayerInput.LeftButtonClicked()) return;

View File

@@ -284,6 +284,8 @@ namespace Barotrauma.Networking
{
if (ShowNetStats) netStats.Update(deltaTime);
if (settingsFrame != null) settingsFrame.Update(deltaTime);
if (log.LogFrame != null) log.LogFrame.Update(deltaTime);
if (!started) return;
@@ -302,8 +304,6 @@ namespace Barotrauma.Networking
if (gameStarted)
{
//inGameHUD.Update((float)Physics.step);
if (respawnManager != null) respawnManager.Update(deltaTime);
bool isCrewDead =
@@ -1336,7 +1336,6 @@ namespace Barotrauma.Networking
}
else if (log.LogFrame!=null)
{
log.LogFrame.Update(0.016f);
log.LogFrame.Draw(spriteBatch);
}

View File

@@ -301,8 +301,8 @@ namespace Barotrauma.Particles
public void UpdateDrawPos()
{
drawPosition = Physics.Interpolate(prevPosition, position);
drawRotation = Physics.Interpolate(prevRotation, rotation);
drawPosition = Timing.Interpolate(prevPosition, position);
drawRotation = Timing.Interpolate(prevRotation, rotation);
prevPosition = position;
prevRotation = rotation;

View File

@@ -20,33 +20,6 @@ namespace Barotrauma
public static float DisplayToRealWorldRatio = 1.0f / 80.0f;
public static double accumulator;
public static double step = 1.0/60.0;
public const float DisplayToSimRation = 100.0f;
public static double Alpha
{
get { return alpha; }
set { alpha = Math.Min(Math.Max(value, 0.0), 1.0); }
}
public static double Interpolate(double previous, double current)
{
return current * alpha + previous * (1.0 - alpha);
}
public static float Interpolate(float previous, float current)
{
return current * (float)alpha + previous * (1.0f - (float)alpha);
}
public static Vector2 Interpolate(Vector2 previous, Vector2 current)
{
return new Vector2(
Interpolate(previous.X, current.X),
Interpolate(previous.Y, current.Y));
}
public const float DisplayToSimRation = 100.0f;
}
}

View File

@@ -330,10 +330,10 @@ namespace Barotrauma
public void UpdateDrawPosition()
{
drawPosition = Physics.Interpolate(prevPosition, body.Position) - offsetFromTargetPos;
drawPosition = Timing.Interpolate(prevPosition, body.Position) - offsetFromTargetPos;
drawPosition = ConvertUnits.ToDisplayUnits(drawPosition);
drawRotation = Physics.Interpolate(prevRotation, body.Rotation);
drawRotation = Timing.Interpolate(prevRotation, body.Rotation);
if (offsetFromTargetPos == Vector2.Zero) return;
@@ -370,7 +370,7 @@ namespace Barotrauma
/// </summary>
public void SmoothRotate(float targetRotation, float force = 10.0f)
{
float nextAngle = body.Rotation + body.AngularVelocity * (float)Physics.step;
float nextAngle = body.Rotation + body.AngularVelocity * (float)Timing.Step;
float angle = MathUtils.GetShortestAngle(nextAngle, targetRotation);

View File

@@ -98,26 +98,15 @@ namespace Barotrauma
/// <param name="gameTime">Provides a snapshot of timing values.</param>
public override void Update(double deltaTime)
{
Physics.accumulator += deltaTime;
//cam.Zoom += Math.Sign(PlayerInput.GetMouseState.ScrollWheelValue - PlayerInput.GetOldMouseState.ScrollWheelValue)*0.1f;
cam.MoveCamera((float)deltaTime);
if (physicsEnabled)
{
Physics.accumulator = Math.Min(Physics.accumulator, Physics.step * 4);
while (Physics.accumulator >= Physics.step)
{
Character.UpdateAnimAll((float)Physics.step * 1000.0f);
Character.UpdateAnimAll((float)deltaTime);
Ragdoll.UpdateAll(cam, (float)Physics.step);
Ragdoll.UpdateAll(cam, (float)deltaTime);
GameMain.World.Step((float)Physics.step);
Physics.accumulator -= Physics.step;
}
Physics.Alpha = Physics.accumulator / Physics.step;
GameMain.World.Step((float)deltaTime);
}
}

View File

@@ -91,9 +91,6 @@ namespace Barotrauma
/// <param name="gameTime">Provides a snapshot of timing values.</param>
public override void Update(double deltaTime)
{
//the accumulator code is based on this article:
//http://gafferongames.com/game-physics/fix-your-timestep/
Physics.accumulator += deltaTime;
#if DEBUG
if (GameMain.GameSession != null && GameMain.GameSession.Level != null && GameMain.GameSession.Submarine != null)
@@ -112,8 +109,6 @@ namespace Barotrauma
if (Level.Loaded != null) Level.Loaded.Update((float)deltaTime);
Character.UpdateAll(cam, (float)deltaTime);
if (Character.Controlled != null && Character.Controlled.SelectedConstruction != null)
{
if (Character.Controlled.SelectedConstruction == Character.Controlled.ClosestItem)
@@ -121,54 +116,49 @@ namespace Barotrauma
Character.Controlled.SelectedConstruction.UpdateHUD(Character.Controlled);
}
}
Character.UpdateAll(cam, (float)deltaTime);
BackgroundCreatureManager.Update(cam, (float)deltaTime);
Physics.accumulator = Math.Min(Physics.accumulator, Physics.step * 6);
//Physics.accumulator = Physics.step;
while (Physics.accumulator >= Physics.step)
GameMain.ParticleManager.Update((float)deltaTime);
StatusEffect.UpdateAll((float)deltaTime);
if (Character.Controlled != null && Lights.LightManager.ViewTarget != null)
{
BackgroundCreatureManager.Update(cam, (float)Physics.step);
GameMain.ParticleManager.Update((float)Physics.step);
StatusEffect.UpdateAll((float)Physics.step);
if (Character.Controlled != null && Lights.LightManager.ViewTarget != null)
{
cam.TargetPos = Lights.LightManager.ViewTarget.WorldPosition;
//Lights.LightManager.ViewPos = Character.Controlled.WorldPosition;
}
cam.MoveCamera((float)Physics.step);
cam.TargetPos = Lights.LightManager.ViewTarget.WorldPosition;
}
cam.MoveCamera((float)deltaTime);
foreach (Submarine sub in Submarine.Loaded)
{
sub.SetPrevTransform(sub.Position);
}
foreach (PhysicsBody pb in PhysicsBody.list)
{
pb.SetPrevTransform(pb.SimPosition, pb.Rotation);
}
MapEntity.UpdateAll(cam, (float)Physics.step);
Character.UpdateAnimAll((float)Physics.step);
Ragdoll.UpdateAll(cam, (float)Physics.step);
foreach (Submarine sub in Submarine.Loaded)
{
sub.Update((float)Physics.step);
}
GameMain.World.Step((float)Physics.step);
//Level.AfterWorldStep();
Physics.accumulator -= Physics.step;
foreach (Submarine sub in Submarine.Loaded)
{
sub.SetPrevTransform(sub.Position);
}
foreach (PhysicsBody pb in PhysicsBody.list)
{
pb.SetPrevTransform(pb.SimPosition, pb.Rotation);
}
Physics.Alpha = Physics.accumulator / Physics.step;
MapEntity.UpdateAll(cam, (float)deltaTime);
Character.UpdateAnimAll((float)deltaTime);
Ragdoll.UpdateAll(cam, (float)deltaTime);
foreach (Submarine sub in Submarine.Loaded)
{
sub.Update((float)deltaTime);
}
GameMain.World.Step((float)deltaTime);
if (!PlayerInput.LeftButtonHeld())
{
Inventory.draggingSlot = null;
Inventory.draggingItem = null;
}
}
@@ -207,8 +197,6 @@ namespace Barotrauma
GUI.Draw((float)deltaTime, spriteBatch, cam);
if (!PlayerInput.LeftButtonHeld()) Inventory.draggingItem = null;
spriteBatch.End();
}

View File

@@ -350,7 +350,12 @@ namespace Barotrauma
mapZoom += PlayerInput.ScrollWheelSpeed / 1000.0f;
mapZoom = MathHelper.Clamp(mapZoom, 1.0f, 4.0f);
//shiftPanel.Update((float)deltaTime);
GameMain.GameSession.Map.Update((float)deltaTime, new Rectangle(
bottomPanel[selectedRightPanel].Rect.X + 20,
bottomPanel[selectedRightPanel].Rect.Y + 20,
bottomPanel[selectedRightPanel].Rect.Width - 310,
bottomPanel[selectedRightPanel].Rect.Height - 40), mapZoom);
}
public override void Draw(double deltaTime, GraphicsDevice graphics, SpriteBatch spriteBatch)

View File

@@ -0,0 +1,40 @@
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Barotrauma
{
static class Timing
{
private static double alpha;
public static double Accumulator;
public static double Step = 1.0 / 60.0;
public static double Alpha
{
get { return alpha; }
set { alpha = Math.Min(Math.Max(value, 0.0), 1.0); }
}
public static double Interpolate(double previous, double current)
{
return current * alpha + previous * (1.0 - alpha);
}
public static float Interpolate(float previous, float current)
{
return current * (float)alpha + previous * (1.0f - (float)alpha);
}
public static Vector2 Interpolate(Vector2 previous, Vector2 current)
{
return new Vector2(
Interpolate(previous.X, current.X),
Interpolate(previous.Y, current.Y));
}
}
}