2f107db...5202af9

This commit is contained in:
Joonas Rikkonen
2019-03-18 21:42:26 +02:00
parent 58c92888b7
commit 044fd3344b
395 changed files with 27417 additions and 19754 deletions
@@ -4,6 +4,7 @@ using Barotrauma.Networking;
using FarseerPhysics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -25,10 +26,7 @@ namespace Barotrauma
private List<Character> characters = new List<Character>();
private Point screenResolution;
public int WinningTeam = 1;
#region UI
private GUIFrame guiFrame;
@@ -47,7 +45,7 @@ namespace Barotrauma
private ChatBox chatBox;
private float prevUIScale;
private GUIComponent orderTargetFrame, orderTargetFrameShadow;
public bool ToggleCrewAreaOpen
@@ -76,6 +74,20 @@ namespace Barotrauma
break;
}
}
screenResolution = new Point(GameMain.GraphicsWidth, GameMain.GraphicsHeight);
prevUIScale = GUI.Scale;
}
#endregion
#region Character list management
public Rectangle GetCharacterListArea()
{
return characterListBox.Rect;
}
partial void InitProjectSpecific()
@@ -144,11 +156,20 @@ namespace Barotrauma
msg,
((msgCommand == "r" || msgCommand == "radio") && ChatMessage.CanUseRadio(Character.Controlled)) ? ChatMessageType.Radio : ChatMessageType.Default,
Character.Controlled);
var headset = GetHeadset(Character.Controlled, true);
if (headset != null && headset.CanTransmit())
{
headset.TransmitSignal(stepsTaken: 0, signal: msg, source: headset.Item, sender: Character.Controlled, sendToChat: false);
}
}
textbox.Deselect();
textbox.Text = "";
return true;
}
}
};
chatBox.InputBox.OnDeselected += (gui, Keys) =>
{
this.chatBox.InputBox.Text = "";
};
chatBox.InputBox.OnTextChanged += chatBox.TypingChatMessage;
}
@@ -328,7 +349,7 @@ namespace Barotrauma
int spacing = (int)(10 * GUI.Scale);
int height = (int)(45 * GUI.Scale);
characterInfoWidth = (int)(170 * GUI.Scale);
characterInfoWidth = (int)(200 * GUI.Scale);
float charactersPerView = characterListBox.Rect.Height / (float)(height + characterListBox.Spacing);
@@ -341,6 +362,7 @@ namespace Barotrauma
int iconSize = (int)(height * 0.8f);
var frame = new GUIFrame(new RectTransform(new Point(GameMain.GraphicsWidth, height), parent.RectTransform), style: "InnerFrame")
{
UserData = character,
@@ -349,7 +371,16 @@ namespace Barotrauma
frame.Color = character.Info.Job.Prefab.UIColor;
frame.SelectedColor = Color.Lerp(frame.Color, Color.White, 0.5f);
frame.HoverColor = Color.Lerp(frame.Color, Color.White, 0.9f);
new GUIFrame(new RectTransform(new Point(characterInfoWidth, (int)(frame.Rect.Height * 1.3f)), frame.RectTransform, Anchor.CenterLeft), style: "OuterGlow")
{
UserData = "highlight",
Color = frame.SelectedColor,
HoverColor = frame.SelectedColor,
PressedColor = frame.SelectedColor,
SelectedColor = frame.SelectedColor,
CanBeFocused = false
};
//---------------- character area ----------------
string characterToolTip = character.Info.Name;
@@ -365,6 +396,23 @@ namespace Barotrauma
HoverColor = frame.HoverColor,
ToolTip = characterToolTip
};
var soundIcon = new GUIImage(new RectTransform(new Point((int)(characterArea.Rect.Height * 0.5f)), characterArea.RectTransform, Anchor.CenterRight) { AbsoluteOffset = new Point(5, 0) },
"GUISoundIcon")
{
UserData = "soundicon",
CanBeFocused = false,
Visible = true
};
soundIcon.Color = new Color(soundIcon.Color, 0.0f);
new GUIImage(new RectTransform(new Point((int)(characterArea.Rect.Height * 0.5f)), characterArea.RectTransform, Anchor.CenterRight) { AbsoluteOffset = new Point(5, 0) },
"GUISoundIconDisabled")
{
UserData = "soundicondisabled",
CanBeFocused = true,
Visible = false
};
if (isSinglePlayer)
{
characterArea.OnClicked = CharacterClicked;
@@ -375,7 +423,7 @@ namespace Barotrauma
characterArea.CanBeSelected = false;
}
var characterImage = new GUICustomComponent(new RectTransform(new Point(characterArea.Rect.Height, characterArea.Rect.Height), characterArea.RectTransform, Anchor.CenterLeft),
var characterImage = new GUICustomComponent(new RectTransform(new Point(characterArea.Rect.Height), characterArea.RectTransform, Anchor.CenterLeft),
onDraw: (sb, component) => character.Info.DrawIcon(sb, component.Rect.Center.ToVector2(), targetAreaSize: component.Rect.Size.ToVector2()))
{
CanBeFocused = false,
@@ -384,7 +432,8 @@ namespace Barotrauma
ToolTip = characterToolTip
};
var characterName = new GUITextBlock(new RectTransform(new Point(characterArea.Rect.Width - characterImage.Rect.Width, characterArea.Rect.Height), characterArea.RectTransform, Anchor.CenterRight),
var characterName = new GUITextBlock(new RectTransform(new Point(characterArea.Rect.Width - characterImage.Rect.Width - soundIcon.Rect.Width - 10, characterArea.Rect.Height),
characterArea.RectTransform, Anchor.CenterRight) { AbsoluteOffset = new Point(soundIcon.Rect.Width + 10, 0) },
character.Name, textColor: frame.Color, font: GUI.SmallFont, wrap: true)
{
Color = frame.Color,
@@ -423,8 +472,8 @@ namespace Barotrauma
var order = orders[i];
if (order.TargetAllCharacters) continue;
RectTransform btnParent = (i >= correctOrderCount + neutralOrderCount) ?
wrongOrderList.Content.RectTransform :
RectTransform btnParent = (i >= correctOrderCount + neutralOrderCount) ?
wrongOrderList.Content.RectTransform :
orderButtonFrame.RectTransform;
var btn = new GUIButton(new RectTransform(new Point(iconSize, iconSize), btnParent, Anchor.CenterLeft),
@@ -445,11 +494,11 @@ namespace Barotrauma
img.Color = Color.Lerp(order.Color, frame.Color, 0.5f);
img.ToolTip = order.Name;
img.HoverColor = Color.Lerp(img.Color, Color.White, 0.5f);
btn.OnClicked += (GUIButton button, object userData) =>
{
if (Character.Controlled == null || Character.Controlled.SpeechImpediment >= 100.0f) return false;
if (btn.GetChildByUserData("selected").Visible)
{
SetCharacterOrder(character, Order.PrefabList.Find(o => o.AITag == "dismissed"), null, Character.Controlled);
@@ -526,23 +575,6 @@ namespace Barotrauma
return true;
}
/// <summary>
/// Sets which character is selected in the crew UI (highlight effect etc)
/// </summary>
public void SetCharacterSelected(Character character)
{
if (character != null && !characters.Contains(character)) return;
//GUIComponent selectedCharacterFrame = null;
foreach (GUIComponent child in characterListBox.Content.Children)
{
GUIButton button = child.Children.FirstOrDefault(c => c.UserData is Character) as GUIButton;
if (button == null) continue;
child.Visible = (Character)button.UserData != character;
}
}
public void ReviveCharacter(Character revivedCharacter)
{
if (characterListBox.Content.GetChildByUserData(revivedCharacter) is GUIComponent characterBlock)
@@ -566,13 +598,14 @@ namespace Barotrauma
if (characterListBox.Content.CountChildren == 0) return false;
int dir = (int)obj;
float step =
(characterListBox.Content.Children.First().Rect.Height + characterListBox.Spacing) /
float step =
(characterListBox.Content.Children.First().Rect.Height + characterListBox.Spacing) /
(characterListBox.TotalSize - characterListBox.Rect.Height);
characterListBox.BarScroll -= characterListBox.BarScroll % step;
characterListBox.BarScroll += dir * step;
return false;
child.Visible = (Character)button.UserData != character;
}
}
private IEnumerable<object> KillCharacterAnim(GUIComponent component)
@@ -583,6 +616,8 @@ namespace Barotrauma
{
comp.Color = Color.DarkRed;
}
if (characterInfos.Contains(revivedCharacter.Info)) AddCharacter(revivedCharacter);
}
yield return new WaitForSeconds(1.0f);
@@ -606,7 +641,6 @@ namespace Barotrauma
#endregion
#region Dialog
/// <summary>
/// Adds the message to the single player chatbox.
/// </summary>
@@ -617,6 +651,7 @@ namespace Barotrauma
DebugConsole.ThrowError("Cannot add messages to single player chat box in multiplayer mode!\n" + Environment.StackTrace);
return;
}
if (string.IsNullOrEmpty(text)) { return; }
chatBox.AddMessage(ChatMessage.Create(senderName, text, messageType, sender));
}
@@ -632,6 +667,52 @@ namespace Barotrauma
return radioItem.GetComponent<WifiComponent>();
}
partial void CreateRandomConversation()
{
if (GameMain.Client != null)
{
//let the server create random conversations in MP
return;
}
List<Character> availableSpeakers = Character.CharacterList.FindAll(c =>
c.AIController is HumanAIController &&
!c.IsDead &&
c.SpeechImpediment <= 100.0f);
pendingConversationLines.AddRange(NPCConversation.CreateRandom(availableSpeakers));
}
#endregion
#region Voice chat
public void SetPlayerVoiceIconState(Client client, bool muted, bool mutedLocally)
{
if (client?.Character == null) { return; }
var playerFrame = characterListBox.Content.FindChild(client.Character)?.FindChild(client.Character);
if (playerFrame == null) { return; }
var soundIcon = playerFrame.FindChild("soundicon");
var soundIconDisabled = playerFrame.FindChild("soundicondisabled");
if (!soundIcon.Visible)
{
soundIcon.Color = new Color(soundIcon.Color, 0.0f);
}
soundIcon.Visible = !muted && !mutedLocally;
soundIconDisabled.Visible = muted || mutedLocally;
soundIconDisabled.ToolTip = TextManager.Get(mutedLocally ? "MutedLocally" : "MutedGlobally");
}
public void SetPlayerSpeaking(Client client)
{
if (client?.Character == null) { return; }
var playerFrame = characterListBox.Content.FindChild(client.Character)?.FindChild(client.Character);
if (playerFrame == null) { return; }
var soundIcon = playerFrame.FindChild("soundicon");
soundIcon.Color = new Color(soundIcon.Color, 1.0f);
}
#endregion
/// <summary>
@@ -648,7 +729,7 @@ namespace Barotrauma
if (IsSinglePlayer)
{
orderGiver.Speak(
order.GetChatMessage("", orderGiver.CurrentHull?.RoomName), ChatMessageType.Order);
order.GetChatMessage("", orderGiver.CurrentHull?.RoomName, givingOrderToSelf: character == orderGiver), ChatMessageType.Order);
}
else
{
@@ -657,19 +738,15 @@ namespace Barotrauma
{
GameMain.Client.SendChatMessage(msg);
}
else if (GameMain.Server != null)
{
GameMain.Server.SendOrderChatMessage(msg);
}
}
return;
}
character.SetOrder(order, option, orderGiver);
character.SetOrder(order, option, orderGiver, speak: orderGiver != character);
if (IsSinglePlayer)
{
orderGiver?.Speak(
order.GetChatMessage(character.Name, orderGiver.CurrentHull?.RoomName, option), null);
order.GetChatMessage(character.Name, orderGiver.CurrentHull?.RoomName, givingOrderToSelf: character == orderGiver, orderOption: option), null);
}
else if (orderGiver != null)
{
@@ -678,16 +755,12 @@ namespace Barotrauma
{
GameMain.Client.SendChatMessage(msg);
}
else if (GameMain.Server != null)
{
GameMain.Server.SendOrderChatMessage(msg);
}
}
DisplayCharacterOrder(character, order);
}
/// <summary>
/// Displays the specified order in the crew UI next to the character.
/// Displays the specified order in the crew UI next to the character.
/// </summary>
public void DisplayCharacterOrder(Character character, Order order)
{
@@ -697,7 +770,7 @@ namespace Barotrauma
if (characterFrame == null) continue;
var orderButtonFrame = characterListElement.GetChildByUserData("orderbuttons");
//get all order buttons from the frame
List<GUIButton> orderButtons = new List<GUIButton>();
foreach (GUIComponent child in orderButtonFrame.Children)
@@ -728,13 +801,13 @@ namespace Barotrauma
}
/// <summary>
/// Create the UI panel that's used to select the target and options for a given order
/// Create the UI panel that's used to select the target and options for a given order
/// (which railgun to use, whether to power up the reactor or shut it down...)
/// </summary>
private void CreateOrderTargetFrame(GUIComponent orderButton, Character character, Order order)
{
Submarine submarine = Character.Controlled != null && Character.Controlled.TeamID > 1 && Submarine.MainSubs.Length > 1 ?
Submarine.MainSubs[1] :
Submarine submarine = Character.Controlled != null && Character.Controlled.TeamID == Character.TeamType.Team2 && Submarine.MainSubs.Length > 1 ?
Submarine.MainSubs[1] :
Submarine.MainSub;
List<Item> matchingItems = new List<Item>();
@@ -742,12 +815,12 @@ namespace Barotrauma
{
matchingItems = order.ItemIdentifiers.Length > 0 ?
Item.ItemList.FindAll(it => order.ItemIdentifiers.Contains(it.Prefab.Identifier) || it.HasTag(order.ItemIdentifiers)) :
Item.ItemList.FindAll(it => it.components.Any(ic => ic.GetType() == order.ItemComponentType));
Item.ItemList.FindAll(it => it.Components.Any(ic => ic.GetType() == order.ItemComponentType));
matchingItems.RemoveAll(it => it.Submarine != submarine && !submarine.DockedTo.Contains(it.Submarine));
matchingItems.RemoveAll(it => it.Submarine != null && it.Submarine.IsOutpost);
}
//more than one target item -> create a minimap-like selection with a pic of the sub
if (matchingItems.Count > 1)
{
@@ -819,7 +892,7 @@ namespace Barotrauma
var optionButton = new GUIButton(new RectTransform(new Vector2(1.0f, 0.2f), optionContainer.RectTransform),
order.OptionNames[i], style: "GUITextBox")
{
UserData = item == null ? order : new Order(order, item, item.components.Find(ic => ic.GetType() == order.ItemComponentType)),
UserData = item == null ? order : new Order(order, item, item.Components.FirstOrDefault(ic => ic.GetType() == order.ItemComponentType)),
Font = GUI.SmallFont,
OnClicked = (btn, userData) =>
{
@@ -847,7 +920,7 @@ namespace Barotrauma
//line connecting the order button to the option buttons
//TODO: sprite
new GUIFrame(new RectTransform(new Vector2(0.5f, 1.0f), orderTargetFrame.RectTransform), style: null);
for (int i = 0; i < order.Options.Length; i++)
{
Item item = matchingItems.Count > 0 ? matchingItems[0] : null;
@@ -855,7 +928,7 @@ namespace Barotrauma
var optionButton = new GUIButton(new RectTransform(new Vector2(0.5f, 0.5f), orderTargetFrame.RectTransform),
order.OptionNames[i], style: "GUITextBox")
{
UserData = item == null ? order : new Order(order, item, item.components.Find(ic => ic.GetType() == order.ItemComponentType)),
UserData = item == null ? order : new Order(order, item, item.Components.FirstOrDefault(ic => ic.GetType() == order.ItemComponentType)),
OnClicked = (btn, userData) =>
{
if (Character.Controlled == null) return false;
@@ -874,11 +947,13 @@ namespace Barotrauma
}
int shadowSize = (int)(200 * GUI.Scale);
orderTargetFrameShadow = new GUIFrame(new RectTransform(orderTargetFrame.Rect.Size + new Point(shadowSize * 2), GUI.Canvas)
{ AbsoluteOffset = orderTargetFrame.Rect.Location - new Point(shadowSize) },
{ AbsoluteOffset = orderTargetFrame.Rect.Location - new Point(shadowSize) },
style: "OuterGlow",
color: matchingItems.Count > 1 ? Color.Black * 0.9f : Color.Black * 0.7f);
}
#region Updating and drawing the UI
private void DrawMiniMapOverlay(SpriteBatch spriteBatch, GUICustomComponent container)
{
Submarine sub = container.UserData as Submarine;
@@ -895,7 +970,7 @@ namespace Barotrauma
float displayScale = ConvertUnits.ToDisplayUnits(scale);
Vector2 offset = (sub.WorldPosition - new Vector2(dockedBorders.Center.X, dockedBorders.Y - dockedBorders.Height / 2)) * scale;
Vector2 center = container.Rect.Center.ToVector2();
for (int i = 0; i < sub.HullVertices.Count; i++)
{
Vector2 start = (sub.HullVertices[i] * displayScale + offset);
@@ -903,14 +978,12 @@ namespace Barotrauma
Vector2 end = (sub.HullVertices[(i + 1) % sub.HullVertices.Count] * displayScale + offset);
end.Y = -end.Y;
GUI.DrawLine(spriteBatch, center + start, center + end, Color.DarkCyan * Rand.Range(0.3f, 0.35f), width: 10);
}
}
}
#region Updating and drawing the UI
public void AddToGUIUpdateList()
{
if (GUI.DisableHUD) return;
if (GUI.DisableHUD || GUI.DisableUpperHUD) return;
if (GameMain.GraphicsWidth != screenResolution.X || GameMain.GraphicsHeight != screenResolution.Y ||
prevUIScale != GUI.Scale)
{
@@ -989,7 +1062,7 @@ namespace Barotrauma
}
}
if (GUI.DisableHUD) return;
if (GUI.DisableHUD || GUI.DisableUpperHUD) return;
if (chatBox != null)
{
chatBox.Update(deltaTime);
@@ -997,23 +1070,17 @@ namespace Barotrauma
if (!DebugConsole.IsOpen && chatBox.InputBox.Visible)
{
if (PlayerInput.KeyHit(InputType.Chat))
if (PlayerInput.KeyHit(InputType.Chat) && !chatBox.InputBox.Selected)
{
if (chatBox.InputBox.Selected)
{
chatBox.InputBox.Text = "";
chatBox.InputBox.Deselect();
}
else
{
chatBox.InputBox.Select();
}
chatBox.GUIFrame.Flash(Color.DarkGreen, 0.5f);
chatBox.InputBox.Select();
}
if (PlayerInput.KeyHit(InputType.RadioChat) && !chatBox.InputBox.Selected)
{
chatBox.GUIFrame.Flash(Color.YellowGreen, 0.5f);
chatBox.InputBox.Select();
chatBox.InputBox.Text = "r; ";
chatBox.InputBox.Text = "r; ";
}
}
}
@@ -1026,12 +1093,22 @@ namespace Barotrauma
foreach (GUIComponent child in characterListBox.Content.Children)
{
child.Visible =
Character.Controlled == null ||
(Character.Controlled != ((Character)child.UserData) && Character.Controlled.TeamID == ((Character)child.UserData).TeamID);
Character character = (Character)child.UserData;
child.Visible =
Character.Controlled == null ||
(Character.Controlled.TeamID == character.TeamID);
if (child.Visible)
{
child.GetChildByUserData("highlight").Visible = character == Character.Controlled;
var soundIcon = child.FindChild(character)?.FindChild("soundicon");
if (soundIcon != null)
{
soundIcon.Color = new Color(soundIcon.Color, (soundIcon.Color.A / 255.0f) - deltaTime);
}
GUIListBox wrongOrderList = child.GetChildByUserData("orderbuttons")?.GetChild<GUIListBox>();
if (wrongOrderList != null)
{
@@ -1046,8 +1123,8 @@ namespace Barotrauma
hoverRect.Inflate((int)(30 * GUI.Scale), (int)(0 * GUI.Scale));
}
bool toggleOpen =
characterListBox.Content.Rect.Contains(PlayerInput.MousePosition) &&
bool toggleOpen =
characterListBox.Content.Rect.Contains(PlayerInput.MousePosition) &&
hoverRect.Contains(PlayerInput.MousePosition);
wrongOrderList.CanBeFocused = toggleOpen;
wrongOrderList.Content.CanBeFocused = toggleOpen;
@@ -1092,7 +1169,6 @@ namespace Barotrauma
}
UpdateReports(deltaTime);
UpdateConversations(deltaTime);
if (orderTargetFrame != null)
{
@@ -1111,16 +1187,16 @@ namespace Barotrauma
}
}
#endregion
#endregion
/// <summary>
/// Creates a listbox that includes all the characters in the crew, can be used externally (round info menus etc)
/// </summary>
public void CreateCrewListFrame(IEnumerable<Character> crew, GUIFrame crewFrame)
{
List<byte> teamIDs = crew.Select(c => c.TeamID).Distinct().ToList();
List<Character.TeamType> teamIDs = crew.Select(c => c.TeamID).Distinct().ToList();
if (!teamIDs.Any()) teamIDs.Add(0);
if (!teamIDs.Any()) teamIDs.Add(Character.TeamType.None);
int listBoxHeight = 300 / teamIDs.Count;
@@ -1151,7 +1227,7 @@ namespace Barotrauma
GUIFrame frame = new GUIFrame(new RectTransform(new Vector2(1.0f, 0.15f), crewList.Content.RectTransform), style: "ListBoxElement")
{
UserData = character,
Color = (GameMain.NetworkMember != null && GameMain.NetworkMember.Character == character) ? Color.Gold * 0.2f : Color.Transparent
Color = (GameMain.NetworkMember != null && GameMain.Client.Character == character) ? Color.Gold * 0.2f : Color.Transparent
};
var paddedFrame = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.9f), frame.RectTransform, Anchor.Center), isHorizontal: true)
@@ -1159,7 +1235,7 @@ namespace Barotrauma
RelativeSpacing = 0.05f,
Stretch = true
};
new GUICustomComponent(new RectTransform(new Vector2(0.2f, 1.0f), paddedFrame.RectTransform, Anchor.CenterLeft),
onDraw: (sb, component) => character.Info.DrawIcon(sb, component.Rect.Center.ToVector2(), targetAreaSize: component.Rect.Size.ToVector2()))
{
@@ -1169,7 +1245,7 @@ namespace Barotrauma
};
GUITextBlock textBlock = new GUITextBlock(new RectTransform(Vector2.One, paddedFrame.RectTransform),
ToolBox.LimitString(character.Info.Name + " (" + character.Info.Job.Name + ")", GUI.Font, paddedFrame.Rect.Width - paddedFrame.Rect.Height),
ToolBox.LimitString(character.Info.Name + " (" + character.Info.Job.Name + ")", GUI.Font, paddedFrame.Rect.Width - paddedFrame.Rect.Height),
textColor: character.Info.Job.Prefab.UIColor);
}
}
@@ -1194,12 +1270,12 @@ namespace Barotrauma
character.Info.CreateInfoFrame(previewPlayer);
if (GameMain.NetworkMember != null) GameMain.NetworkMember.SelectCrewCharacter(character, previewPlayer);
if (GameMain.NetworkMember != null) GameMain.Client.SelectCrewCharacter(character, previewPlayer);
return true;
}
#region Reports
#region Reports
/// <summary>
/// Enables/disables report buttons when needed
@@ -1217,7 +1293,7 @@ namespace Barotrauma
{
reportButtonFrame.Visible = true;
var reportButtonParent = chatBox ?? GameMain.NetworkMember.ChatBox;
var reportButtonParent = chatBox ?? GameMain.Client.ChatBox;
reportButtonFrame.RectTransform.AbsoluteOffset = new Point(
Math.Min(reportButtonParent.GUIFrame.Rect.X, reportButtonParent.ToggleButton.Rect.X) - reportButtonFrame.Rect.Width - (int)(10 * GUI.Scale),
reportButtonParent.GUIFrame.Rect.Y);
@@ -1230,7 +1306,7 @@ namespace Barotrauma
bool hasIntruders = Character.CharacterList.Any(c =>
c.CurrentHull == Character.Controlled.CurrentHull && !c.IsDead &&
(c.AIController is EnemyAIController || c.TeamID != Character.Controlled.TeamID));
(c.AIController is EnemyAIController || (c.TeamID != Character.Controlled.TeamID && c.TeamID != Character.TeamType.FriendlyNPC)));
ToggleReportButton("reportintruders", hasIntruders);
@@ -1240,7 +1316,7 @@ namespace Barotrauma
if (highlight.Visible)
{
highlight.RectTransform.LocalScale = new Vector2(1.25f + (float)Math.Sin(Timing.TotalTime * 5.0f) * 0.25f);
}
}
}
}
else
@@ -1256,7 +1332,7 @@ namespace Barotrauma
{
return CharacterHealth.OpenHealthWindow == null;
}
private bool ReportButtonClicked(GUIButton button, object userData)
{
//order targeted to all characters
@@ -1273,7 +1349,7 @@ namespace Barotrauma
private void ToggleReportButton(string orderAiTag, bool enabled)
{
Order order = Order.PrefabList.Find(o => o.AITag == orderAiTag);
//already reported, disable the button
/*if (GameMain.GameSession.CrewManager.ActiveOrders.Any(o =>
o.First.TargetEntity == Character.Controlled.CurrentHull &&
@@ -1286,10 +1362,10 @@ namespace Barotrauma
if (reportButton != null)
{
reportButton.GetChildByUserData("highlighted").Visible = enabled;
}
}
}
#endregion
#endregion
public void InitSinglePlayerRound()
{
@@ -1300,13 +1376,13 @@ namespace Barotrauma
for (int i = 0; i < waypoints.Length; i++)
{
Character character;
Character character;
character = Character.Create(characterInfos[i], waypoints[i].WorldPosition, characterInfos[i].Name);
if (character.Info != null && !character.Info.StartItemsGiven)
{
character.GiveJobItems(waypoints[i]);
character.Info.StartItemsGiven = true;
}
}
if (character.Info?.InventoryData != null)
{
@@ -3,12 +3,15 @@ using Lidgren.Network;
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Barotrauma
{
partial class MultiPlayerCampaign : CampaignMode
{
public static GUIComponent StartCampaignSetup()
private UInt16 startWatchmanID, endWatchmanID;
public static GUIComponent StartCampaignSetup(IEnumerable<string> saveFiles)
{
GUIFrame background = new GUIFrame(new RectTransform(Vector2.One, GUI.Canvas), style: "GUIBackgroundBlocker");
@@ -31,7 +34,7 @@ namespace Barotrauma
var newCampaignContainer = new GUIFrame(new RectTransform(Vector2.One, campaignContainer.RectTransform, Anchor.BottomLeft), style: null);
var loadCampaignContainer = new GUIFrame(new RectTransform(Vector2.One, campaignContainer.RectTransform, Anchor.BottomLeft), style: null);
var campaignSetupUI = new CampaignSetupUI(true, newCampaignContainer, loadCampaignContainer);
var campaignSetupUI = new CampaignSetupUI(true, newCampaignContainer, loadCampaignContainer, saveFiles);
var newCampaignButton = new GUIButton(new RectTransform(new Vector2(0.3f, 1.0f), buttonContainer.RectTransform),
TextManager.Get("NewCampaign"))
@@ -56,55 +59,16 @@ namespace Barotrauma
};
loadCampaignContainer.Visible = false;
campaignSetupUI.StartNewGame = (Submarine sub, string saveName, string mapSeed) =>
{
GameMain.GameSession = new GameSession(new Submarine(sub.FilePath, ""), saveName,
GameModePreset.List.Find(g => g.Identifier == "multiplayercampaign"));
var campaign = ((MultiPlayerCampaign)GameMain.GameSession.GameMode);
campaign.GenerateMap(mapSeed);
campaign.SetDelegates();
background.Visible = false;
GameMain.NetLobbyScreen.ToggleCampaignMode(true);
campaign.Map.SelectRandomLocation(true);
SaveUtil.SaveGame(GameMain.GameSession.SavePath);
campaign.LastSaveID++;
};
campaignSetupUI.LoadGame = (string fileName) =>
{
SaveUtil.LoadGame(fileName);
if (!(GameMain.GameSession.GameMode is MultiPlayerCampaign))
{
DebugConsole.ThrowError("Failed to load the campaign. The save file appears to be for a single player campaign.");
return;
}
var campaign = ((MultiPlayerCampaign)GameMain.GameSession.GameMode);
campaign.LastSaveID++;
background.Visible = false;
GameMain.NetLobbyScreen.ToggleCampaignMode(true);
campaign.Map.SelectRandomLocation(true);
};
campaignSetupUI.StartNewGame = GameMain.Client.SetupNewCampaign;
campaignSetupUI.LoadGame = GameMain.Client.SetupLoadCampaign;
var cancelButton = new GUIButton(new RectTransform(new Vector2(0.2f, 0.05f), paddedFrame.RectTransform, Anchor.BottomLeft), TextManager.Get("Cancel"))
{
OnClicked = (btn, obj) =>
{
//find the first mode that's not multiplayer campaign and switch to that
background.Visible = false;
int otherModeIndex = 0;
for (otherModeIndex = 0; otherModeIndex < GameMain.NetLobbyScreen.ModeList.Content.CountChildren; otherModeIndex++)
{
if (GameMain.NetLobbyScreen.ModeList.Content.GetChild(otherModeIndex).UserData is MultiPlayerCampaign) continue;
break;
}
GameMain.NetLobbyScreen.SelectMode(otherModeIndex);
return true;
}
};
@@ -112,6 +76,56 @@ namespace Barotrauma
return background;
}
public override void Update(float deltaTime)
{
base.Update(deltaTime);
if (startWatchmanID > 0 && startWatchman == null)
{
startWatchman = Entity.FindEntityByID(startWatchmanID) as Character;
if (startWatchman != null) { InitializeWatchman(startWatchman); }
}
if (endWatchmanID > 0 && endWatchman == null)
{
endWatchman = Entity.FindEntityByID(endWatchmanID) as Character;
if (endWatchman != null) { InitializeWatchman(endWatchman); }
}
}
protected override void WatchmanInteract(Character watchman, Character interactor)
{
if ((watchman.Submarine == Level.Loaded.StartOutpost && !Submarine.MainSub.AtStartPosition) ||
(watchman.Submarine == Level.Loaded.EndOutpost && !Submarine.MainSub.AtEndPosition))
{
return;
}
if (GUIMessageBox.MessageBoxes.Any(mbox => mbox.UserData as string == "watchmanprompt"))
{
return;
}
if (GameMain.Client != null && interactor == Character.Controlled &&
(GameMain.Client.HasPermission(ClientPermissions.ManageRound) || GameMain.Client.HasPermission(ClientPermissions.ManageCampaign)))
{
var msgBox = new GUIMessageBox("", TextManager.Get("CampaignEnterOutpostPrompt")
.Replace("[locationname]", Submarine.MainSub.AtStartPosition ? Map.CurrentLocation.Name : Map.SelectedLocation.Name),
new string[] { TextManager.Get("Yes"), TextManager.Get("No") })
{
UserData = "watchmanprompt"
};
msgBox.Buttons[0].OnClicked = (btn, userdata) =>
{
GameMain.Client.RequestRoundEnd();
return true;
};
msgBox.Buttons[0].OnClicked += msgBox.Close;
msgBox.Buttons[1].OnClicked += msgBox.Close;
}
}
public void ClientWrite(NetBuffer msg)
{
System.Diagnostics.Debug.Assert(map.Locations.Count < UInt16.MaxValue);
@@ -138,6 +152,9 @@ namespace Barotrauma
UInt16 selectedLocIndex = msg.ReadUInt16();
byte selectedMissionIndex = msg.ReadByte();
UInt16 startWatchmanID = msg.ReadUInt16();
UInt16 endWatchmanID = msg.ReadUInt16();
int money = msg.ReadInt32();
UInt16 purchasedItemCount = msg.ReadUInt16();
@@ -167,10 +184,9 @@ namespace Barotrauma
campaign = ((MultiPlayerCampaign)GameMain.GameSession.GameMode);
campaign.CampaignID = campaignID;
campaign.GenerateMap(mapSeed);
GameMain.NetLobbyScreen.ToggleCampaignMode(true);
}
GameMain.NetLobbyScreen.ToggleCampaignMode(true);
if (NetIdUtils.IdMoreRecent(campaign.lastUpdateID, updateID)) return;
//server has a newer save file
if (NetIdUtils.IdMoreRecent(saveID, campaign.PendingSaveID))
@@ -187,19 +203,22 @@ namespace Barotrauma
GameMain.Client.RequestFile(FileTransferType.CampaignSave, null, null);*/
campaign.PendingSaveID = saveID;
}
//we've got the latest save file
else if (!NetIdUtils.IdMoreRecent(saveID, campaign.lastSaveID))
if (NetIdUtils.IdMoreRecent(updateID, campaign.lastUpdateID))
{
campaign.Map.SetLocation(currentLocIndex == UInt16.MaxValue ? -1 : currentLocIndex);
campaign.Map.SelectLocation(selectedLocIndex == UInt16.MaxValue ? -1 : selectedLocIndex);
campaign.Map.SelectMission(selectedMissionIndex);
campaign.startWatchmanID = startWatchmanID;
campaign.endWatchmanID = endWatchmanID;
campaign.Money = money;
campaign.CargoManager.SetPurchasedItems(purchasedItems);
if (myCharacterInfo != null)
{
GameMain.NetworkMember.CharacterInfo = myCharacterInfo;
GameMain.Client.CharacterInfo = myCharacterInfo;
GameMain.NetLobbyScreen.SetCampaignCharacterInfo(myCharacterInfo);
}
else
@@ -38,7 +38,7 @@ namespace Barotrauma
{
for (int i = 0; i < jobPrefab.InitialCount; i++)
{
CrewManager.AddCharacterInfo(new CharacterInfo(Character.HumanConfigFile, "", Gender.None, jobPrefab));
CrewManager.AddCharacterInfo(new CharacterInfo(Character.HumanConfigFile, "", jobPrefab));
}
}
@@ -128,7 +128,7 @@ namespace Barotrauma
public override void Draw(SpriteBatch spriteBatch)
{
if (!isRunning|| GUI.DisableHUD) return;
if (!isRunning|| GUI.DisableHUD || GUI.DisableUpperHUD) return;
if (Submarine.MainSub == null) return;
@@ -180,7 +180,7 @@ namespace Barotrauma
ContextualTutorial.Update(deltaTime);
}
if (!GUI.DisableHUD)
if (!GUI.DisableHUD && !GUI.DisableUpperHUD)
{
endRoundButton.UpdateManually(deltaTime);
}
@@ -206,11 +206,19 @@ namespace Barotrauma
return;
}
CreateDialog(new List<Character> { watchman }, "WatchmanInteract", 1.0f);
if (GUIMessageBox.MessageBoxes.Any(mbox => mbox.UserData as string == "watchmanprompt"))
{
return;
}
var msgBox = new GUIMessageBox("", TextManager.Get("CampaignEnterOutpostPrompt")
.Replace("[locationname]", leavingSub.AtStartPosition ? Map.CurrentLocation.Name : Map.SelectedLocation.Name),
new string[] { TextManager.Get("Yes"), TextManager.Get("No") });
new string[] { TextManager.Get("Yes"), TextManager.Get("No") })
{
UserData = "watchmanprompt"
};
msgBox.Buttons[0].OnClicked = (btn, userdata) =>
{
if (!isRunning) { return true; }
@@ -584,7 +584,7 @@ namespace Barotrauma.Tutorials
}
}
if (brokenBox != null && brokenBox.Condition > 50.0f && pump.Voltage < pump.MinVoltage)
if (brokenBox != null && brokenBox.Condition > brokenBox.Prefab.Health / 2.0f && pump.Voltage < pump.MinVoltage)
{
yield return new WaitForSeconds(1.0f);
@@ -152,7 +152,6 @@ namespace Barotrauma.Tutorials
if (!Initialized) return;
PreloadVideoContent();
Completed = true; // Trigger completed at start to prevent the contextual tutorial from automatically activating on starting new campaigns after this one
base.Start();
@@ -194,6 +193,7 @@ namespace Barotrauma.Tutorials
}
crew = GameMain.GameSession.CrewManager.GetCharacters().ToList();
Completed = true; // Trigger completed at start to prevent the contextual tutorial from automatically activating on starting new campaigns after this one
started = true;
}
@@ -325,7 +325,7 @@ namespace Barotrauma.Tutorials
foreach (Item item in Item.ItemList)
{
if (!item.Repairables.Any() || item.Condition > 50.0f) continue;
if (!item.Repairables.Any() || item.Condition > item.Prefab.Health / 2.0f) continue;
degradedEquipmentFound = true;
break;
}
@@ -464,7 +464,7 @@ namespace Barotrauma.Tutorials
spriteSheetPlayer.LoadContent(playableContentPath, activeSegment.Content, activeSegment.Name, true, true, CurrentSegmentStopCallback);
break;
case ContentTypes.Text:
infoBox = CreateInfoFrame(TextManager.Get(activeSegment.Name), TextManager.Get(activeSegment.Content.GetAttributeString("tag", ""), false, args),
infoBox = CreateInfoFrame(TextManager.Get(activeSegment.Name), TextManager.GetFormatted(activeSegment.Content.GetAttributeString("tag", ""), false, args),
activeSegment.Content.GetAttributeInt("width", 300),
activeSegment.Content.GetAttributeInt("height", 80),
activeSegment.Content.GetAttributeString("anchor", "Center"), true, CurrentSegmentStopCallback);
@@ -36,7 +36,7 @@ namespace Barotrauma.Tutorials
}
CharacterInfo charInfo = configElement.Element("Character") == null ?
new CharacterInfo(Character.HumanConfigFile, "", Gender.None, JobPrefab.List.Find(jp => jp.Identifier == "engineer")) :
new CharacterInfo(Character.HumanConfigFile, "", JobPrefab.List.Find(jp => jp.Identifier == "engineer")) :
new CharacterInfo(configElement.Element("Character"));
character = Character.Create(charInfo, wayPoint.WorldPosition, "", false, false);
@@ -101,7 +101,7 @@ namespace Barotrauma.Tutorials
messageBox.Buttons[0].OnClicked += messageBox.Close;
messageBox.Buttons[1].OnClicked = GameMain.MainMenuScreen.SelectTab;
messageBox.Buttons[1].OnClicked = GameMain.MainMenuScreen.ReturnToMainMenu;
messageBox.Buttons[1].OnClicked += messageBox.Close;
yield return CoroutineStatus.Success;
@@ -31,7 +31,7 @@ namespace Barotrauma.Tutorials
{
if (completed == value) return;
completed = value;
GameMain.Config.Save();
GameMain.Config.SaveNewPlayerConfig();
}
}
@@ -105,7 +105,7 @@ namespace Barotrauma.Tutorials
{
configElement = element;
Name = element.GetAttributeString("name", "Unnamed");
Completed = GameMain.Config.CompletedTutorialNames.Contains(Name);
completed = GameMain.Config.CompletedTutorialNames.Contains(Name);
Enum.TryParse(element.GetAttributeString("tutorialtype", "Scenario"), true, out tutorialType);
}
@@ -167,7 +167,7 @@ namespace Barotrauma.Tutorials
};
}
GUI.PlayUISound(GUISoundType.Message);
GUI.PlayUISound(GUISoundType.UIMessage);
return infoBlock;
}
@@ -211,7 +211,7 @@ namespace Barotrauma.Tutorials
};
}
GUI.PlayUISound(GUISoundType.Message);
GUI.PlayUISound(GUISoundType.UIMessage);
return infoBlock;
}
@@ -6,8 +6,11 @@ namespace Barotrauma
partial class GameSession
{
private InfoFrameTab selectedTab;
private GUIButton infoButton;
private GUIButton infoFrame;
/// <summary>
/// Determines whether the hotkey for the info button was held down in the previous frame.
/// </summary>
private bool prevInfoKey;
private GUIFrame infoFrameContent;
@@ -17,7 +20,12 @@ namespace Barotrauma
get { return roundSummary; }
}
private bool ToggleInfoFrame(GUIButton button, object obj)
partial void InitProjSpecific()
{
prevInfoKey = false;
}
private bool ToggleInfoFrame()
{
if (infoFrame == null)
{
@@ -36,10 +44,7 @@ namespace Barotrauma
{
int width = 600, height = 400;
infoFrame = new GUIButton(new RectTransform(Vector2.One, GUI.Canvas), style: "GUIBackgroundBlocker")
{
OnClicked = (btn, userdata) => { if (GUI.MouseOn == btn || GUI.MouseOn == btn.TextBlock) ToggleInfoFrame(btn, userdata); return true; }
};
infoFrame = new GUIButton(new RectTransform(Vector2.One, GUI.Canvas), style: "GUIBackgroundBlocker");
var innerFrame = new GUIFrame(new RectTransform(new Vector2(0.3f, 0.35f), infoFrame.RectTransform, Anchor.Center) { MinSize = new Point(width,height) });
@@ -63,6 +68,7 @@ namespace Barotrauma
OnClicked = SelectInfoFrameTab
};
/*TODO: fix
if (GameMain.Server != null)
{
var manageButton = new GUIButton(new RectTransform(new Vector2(0.2f, 1.0f), buttonArea.RectTransform), TextManager.Get("ManagePlayers"))
@@ -70,12 +76,7 @@ namespace Barotrauma
UserData = InfoFrameTab.ManagePlayers,
OnClicked = SelectInfoFrameTab
};
}
var closeButton = new GUIButton(new RectTransform(new Vector2(0.25f, 0.08f), paddedFrame.RectTransform, Anchor.BottomRight), TextManager.Get("Close"))
{
OnClicked = ToggleInfoFrame
};
}*/
}
@@ -94,7 +95,8 @@ namespace Barotrauma
CreateMissionInfo(infoFrameContent);
break;
case InfoFrameTab.ManagePlayers:
GameMain.Server.ManagePlayersFrame(infoFrameContent);
//TODO: fix
//GameMain.Server.ManagePlayersFrame(infoFrameContent);
break;
}
@@ -125,7 +127,6 @@ namespace Barotrauma
public void AddToGUIUpdateList()
{
if (GUI.DisableHUD) return;
infoButton.AddToGUIUpdateList();
GameMode?.AddToGUIUpdateList();
infoFrame?.AddToGUIUpdateList();
}
@@ -133,8 +134,13 @@ namespace Barotrauma
partial void UpdateProjSpecific(float deltaTime)
{
if (GUI.DisableHUD) return;
infoButton?.UpdateManually(deltaTime);
if (prevInfoKey != (PlayerInput.KeyDown(InputType.InfoTab) && GUI.KeyboardDispatcher.Subscriber == null))
{
ToggleInfoFrame();
prevInfoKey = PlayerInput.KeyDown(InputType.InfoTab);
}
infoFrame?.UpdateManually(deltaTime);
}
@@ -142,8 +148,6 @@ namespace Barotrauma
{
if (GUI.DisableHUD) return;
infoButton.DrawManually(spriteBatch);
GameMode?.Draw(spriteBatch);
infoFrame?.DrawManually(spriteBatch);
}
@@ -1,44 +0,0 @@
using System.Collections.Generic;
namespace Barotrauma
{
class HireManager
{
private List<CharacterInfo> availableCharacters;
public IEnumerable<CharacterInfo> AvailableCharacters
{
get { return availableCharacters; }
}
public const int MaxAvailableCharacters = 10;
public HireManager()
{
availableCharacters = new List<CharacterInfo>();
}
public void RemoveCharacter(CharacterInfo character)
{
availableCharacters.Remove(character);
}
public void GenerateCharacters(Location location, int amount)
{
availableCharacters.ForEach(c => c.Remove());
availableCharacters.Clear();
for (int i = 0; i < amount; i++)
{
JobPrefab job = location.Type.GetRandomHireable();
if (job == null) { return; }
availableCharacters.Add(new CharacterInfo(Character.HumanConfigFile, "", Gender.None, job));
}
}
public void Remove()
{
availableCharacters.ForEach(c => c.Remove());
availableCharacters.Clear();
}
}
}
@@ -71,21 +71,17 @@ namespace Barotrauma
var missionInfo = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), infoTextBox.Content.RectTransform),
GameMain.GameSession.Mission.Completed ? GameMain.GameSession.Mission.SuccessMessage : GameMain.GameSession.Mission.FailureMessage,
wrap: true);
if (GameMain.GameSession.Mission.Completed)
{
GameMain.Server?.ConnectedClients.ForEach(c => c.Karma += 0.1f);
}
if (GameMain.GameSession.Mission.Completed && singleplayer)
{
var missionReward = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), infoTextBox.Content.RectTransform),
TextManager.Get("MissionReward").Replace("[reward]", GameMain.GameSession.Mission.Reward.ToString()));
}
}
else
foreach (GUIComponent child in infoTextBox.Content.Children)
{
GameMain.Server?.ConnectedClients.ForEach(c => c.Karma += 0.1f);
child.CanBeFocused = false;
}
foreach (GUIComponent child in infoTextBox.Content.Children)
{
@@ -100,7 +96,7 @@ namespace Barotrauma
foreach (CharacterInfo characterInfo in gameSession.CrewManager.GetCharacterInfos())
{
if (GameMain.GameSession.Mission is CombatMission &&
characterInfo.TeamID != GameMain.GameSession.CrewManager.WinningTeam)
characterInfo.TeamID != GameMain.GameSession.WinningTeam)
{
continue;
}