74f32d14d4
commit 2ad9b5de40f128e8413f1ad5f568a4bc006d0971 Author: Joonas Rikkonen <poe.regalis@gmail.com> Date: Wed Feb 6 20:11:41 2019 +0200 v0.8.9.3 commit 2d64da9d1e0d10f9ccb08d6e3fbc45d69fcda368 Author: itchyOwl <lauri.harkanen@gmail.com> Date: Wed Feb 6 18:08:10 2019 +0200 Randomize the races and the heads in the net lobby. TODO: remember the previous heads and check that the next in line is unique (not exactly the same as the current). commit 09f74ab37692291ca070bac5dbc53eef395fb1cf Author: Joonas Rikkonen <poe.regalis@gmail.com> Date: Wed Feb 6 16:30:16 2019 +0200 AI characters can give treatment to characters who aren't unconscious, fixed AI characters attempting to treat dead characters. Closes #1083 commit a8fea2450cf4ef0b80a8fc809aee339bc39b28c6 Author: Joonas Rikkonen <poe.regalis@gmail.com> Date: Wed Feb 6 16:28:23 2019 +0200 Fixed horizontal docking ports failing to find the hull prefab commit dd5a7a4f09195ecfeb82605e1e73ea22607694e7 Author: ezjamsen <ezjames.fi@gmail.com> Date: Wed Feb 6 16:02:52 2019 +0200 halved the hitpoints for baby moloch commit 92ae260558ece991560d83819168ef51d5267a66 Merge: 75fe087d7 8f451825e Author: itchyOwl <lauri.harkanen@gmail.com> Date: Wed Feb 6 15:44:08 2019 +0200 Merge branch 'dev' of https://github.com/Regalis11/Barotrauma into dev commit 75fe087d7263b46611fb0aad5c91c616e22ad41b Author: itchyOwl <lauri.harkanen@gmail.com> Date: Wed Feb 6 15:43:12 2019 +0200 Update the ai block in the moloch boss config file. commit caf11944294dfe66b5d302888baecbfddad7293a Author: itchyOwl <lauri.harkanen@gmail.com> Date: Wed Feb 6 15:42:42 2019 +0200 Remove the lowercase version of the moloch boss config file. commit b422feece1e620c427fa62d41c2b847b6b8837e9 Author: itchyOwl <lauri.harkanen@gmail.com> Date: Wed Feb 6 15:41:40 2019 +0200 Fix molochbaby character name in the config file. commit 913762516dd17921c185de2cb912333f2e5230dd Author: itchyOwl <lauri.harkanen@gmail.com> Date: Wed Feb 6 15:41:22 2019 +0200 Include the baby moloch files in the project. commit 8f451825e95b415b1262f984d83828c379d36ea2 Author: Joonas Rikkonen <poe.regalis@gmail.com> Date: Wed Feb 6 15:36:50 2019 +0200 Added molochbaby to the project file commit 2078307f255f432c19fcbbc0b690acf5655f3c99 Author: itchyOwl <lauri.harkanen@gmail.com> Date: Wed Feb 6 15:33:08 2019 +0200 Disable creating humanoids in the wizard for now, because it can go wrong in so many ways. commit 55a931795ac5f60699033c4ff484a9a2d0ae9b7e Author: itchyOwl <lauri.harkanen@gmail.com> Date: Wed Feb 6 15:32:18 2019 +0200 Unfreeze when adjusting the joint scale, because the limbs are not otherwise updated to the joint positions. commit 2c92373ccbf331c545c830c9780f450b116f0359 Author: Iiro Enges <iiro@fakefish.fi> Date: Wed Feb 6 15:28:22 2019 +0200 Tinted baby moloch to differentiate from the adult version (for testing purposes) commit f05be351cdf8a6073702e988ed1861f665399048 Author: Joonas Rikkonen <poe.regalis@gmail.com> Date: Wed Feb 6 15:26:52 2019 +0200 Fixed automatic temperature control setting turbine output above 100 if the power consumption is higher than what the reactor can generate. Caused "failed to write an event for the entity" errors in MP when the server tried to write the targetTurbineOutput using WriteRangedSingle with a maximum value of 100. Closes #1085 commit 7b737ebbea41fd5b7825a6c6373e578c1b1c91fd Author: ezjamsen <ezjames.fi@gmail.com> Date: Wed Feb 6 15:15:59 2019 +0200 Baby moloch, doo doo doo doo doo doo commit f5d13649915ba761bbc6fe78370c607905e2d5f8 Author: ezjamsen <ezjames.fi@gmail.com> Date: Wed Feb 6 15:15:04 2019 +0200 Small fixes and tweaks to gun performance dependent on skill of user. commit 4bf61738c6da08d771dedf1c96160cc76e0b4dd7 Author: ezjamsen <ezjames.fi@gmail.com> Date: Wed Feb 6 15:14:11 2019 +0200 New staggered swarm medium difficulty event commit 3e593f46850987ba074d9b26d59d08eeeddd1d70 Author: Joonas Rikkonen <poe.regalis@gmail.com> Date: Wed Feb 6 15:05:43 2019 +0200 Removed incorrect item name/description instructions fron EnglishVanilla.xml. Correct instructions are at the beginning of the file. commit ce33a523e440a5b5037b84ca96bebf1f977e0aa8 Author: Joonas Rikkonen <poe.regalis@gmail.com> Date: Wed Feb 6 15:00:48 2019 +0200 Attempt to fix "attempted to move pull joint extremely far" errors (#895). I think they were (at least for the most part) caused by characters switching to simple physics mode and then moving a significant distance, and when the character switched back to normal animation, the pull joints were still somewhere far away and lerping them to the position of the collider failed (because the lerped position triggers the error). commit c8212e3eff6d9272c9d38b833743b0f33b3611a2 Author: Joonas Rikkonen <poe.regalis@gmail.com> Date: Wed Feb 6 13:54:15 2019 +0200 Fixed nullref exception when teleporting from a sub to ruins or vice versa. Closes #1037 commit 0d812394944eb05be4291be7b56593cc4def6d0f Author: Daniel Asteljoki <daniel.asteljoki@gmail.com> Date: Wed Feb 6 13:34:58 2019 +0200 Made regular ruin walls much more durable (500 -> 5000) commit c9a4d9d6f6c9c767ecd8cf34f917db9da852f4bf Author: Daniel Asteljoki <daniel.asteljoki@gmail.com> Date: Wed Feb 6 13:34:26 2019 +0200 Rebalanced Humpback battery grid, added toggles for using backup power commit 47617a6d54f933714dffeca5fa311776e9d0523c Author: itchyOwl <lauri.harkanen@gmail.com> Date: Wed Feb 6 13:17:57 2019 +0200 Remove the lowercase variant of moloch's config file from the source control. commit 640662835684464e4a66b106b1958e5a9fde8a0c Merge: 80e91f96b 7861d00a6 Author: itchyOwl <lauri.harkanen@gmail.com> Date: Wed Feb 6 13:10:00 2019 +0200 Merge branch 'dev' of https://github.com/Regalis11/Barotrauma into dev commit 80e91f96bf5f1e9f89c5a6e4695292298a802b06 Author: itchyOwl <lauri.harkanen@gmail.com> Date: Wed Feb 6 13:09:37 2019 +0200 Fix a null reference exception. commit 91b16aaa7aacc658cb36325ea85944802166ef53 Author: itchyOwl <lauri.harkanen@gmail.com> Date: Wed Feb 6 13:09:26 2019 +0200 Instead of having a bad sight, make the Hammerhead deaf. Add "provocative" priority tag, remove "sonar". Make slightly less aggressive towards weaker. commit a383c136f6f6915163e98c472ec7ba7f575ea479 Author: itchyOwl <lauri.harkanen@gmail.com> Date: Wed Feb 6 13:02:00 2019 +0200 Add "provocative" tag on Moloch and Mudraptor targeting priorities. Tweak moloch priorities a bit. commit 7861d00a609f2555a19f510d72591bd0330f607e Author: Joonas Rikkonen <poe.regalis@gmail.com> Date: Wed Feb 6 12:53:37 2019 +0200 Attempt to fix/diagnose "collection was modified; enumeration operation may not execute" exceptions when using the fixhulls command (see #1011). Haven't been able to reproduce this issue. commit 1d1321c60e8815b3beaffb81bfb9c5f5c2528297 Author: itchyOwl <lauri.harkanen@gmail.com> Date: Wed Feb 6 12:52:29 2019 +0200 Add "provocative" tag that can be used as a red flag for the monsters. Add the tag on the diving scooter. Also add an ai target with sound ranges. commit 8530f4c9e4b1c444687cadbf615a9ade0440262b Author: itchyOwl <lauri.harkanen@gmail.com> Date: Wed Feb 6 12:50:43 2019 +0200 Propulsion can now make sound that attracts the enemies. The sound is on when the propulsion is active. commit 291f12676e5148da1a83d4dd72071381c1ae73e3 Author: itchyOwl <lauri.harkanen@gmail.com> Date: Wed Feb 6 12:49:39 2019 +0200 If a target item is held by a character, attack the character instead. commit 2aeaa9eaa51f3ed3db71f7853efef37bf5998838 Author: itchyOwl <lauri.harkanen@gmail.com> Date: Wed Feb 6 12:46:27 2019 +0200 Allow to define min and max sound ranges. commit 3bf5d2383cbcc33fa862a79c06756e6d9f20a753 Author: itchyOwl <lauri.harkanen@gmail.com> Date: Wed Feb 6 12:42:57 2019 +0200 Adjust the ai debug info. commit 369355ffef340875335c0d81d9a2c9a4bfac898b Author: EdusFF <pitkanen.eetu@gmail.com> Date: Wed Feb 6 12:40:30 2019 +0200 ContextualTutorial Update cleanup commit 101387adc1308ad87e3134ab2960d3032f725735 Author: EdusFF <pitkanen.eetu@gmail.com> Date: Wed Feb 6 12:34:07 2019 +0200 Formatting commit cc44eff21d57d93e4b0a67249af2135e5782e3c3 Merge: 9a338a2d4 33d1cd1be Author: EdusFF <pitkanen.eetu@gmail.com> Date: Wed Feb 6 12:31:54 2019 +0200 Merge branch 'dev' of https://github.com/Regalis11/Barotrauma into dev commit 9a338a2d440ff12426171fe9c3121efb934b6803 Author: EdusFF <pitkanen.eetu@gmail.com> Date: Wed Feb 6 12:31:50 2019 +0200 Modified: ContextualTutorial dismissal logic to use buttons instead of the press any key logic commit 33d1cd1beb61862a91bce16ebeb5090a8969cf1b Author: Joonas Rikkonen <poe.regalis@gmail.com> Date: Wed Feb 6 12:07:21 2019 +0200 Fixed spectate button staying disabled if starting a round fails (due to a missing sub file for example). Closes #1066 commit 8935825146203725759463278e7776a42d84a6a0 Merge: 2cdc96214 9fd3de63b Author: EdusFF <pitkanen.eetu@gmail.com> Date: Wed Feb 6 11:45:06 2019 +0200 Merge branch 'dev' of https://github.com/Regalis11/Barotrauma into dev commit 2cdc96214e2285bfa83a566ed8bc2aed4156c31d Author: EdusFF <pitkanen.eetu@gmail.com> Date: Wed Feb 6 11:44:56 2019 +0200 Added: Saving of the download size to the Workshop.Item, allows displaying the file size for non-downloaded content in SteamWorshopScreen. Closes #1052 commit 9fd3de63bc08e06a924bf5ec8a8b2938a647282f Author: Joonas Rikkonen <poe.regalis@gmail.com> Date: Wed Feb 6 11:34:38 2019 +0200 Watchmen cannot be dragged or grabbed, fixed watchmen imploding continuously if they end up outside. Closes #1072 commit eb3fca43d77e79f04e0ae80daac53b7e2c1e37f7 Author: Joonas Rikkonen <poe.regalis@gmail.com> Date: Wed Feb 6 11:14:06 2019 +0200 Fixed server not sending PowerContainer events until the charge of the PowerContainer has changed by more then 100% (i.e. never). Closes #1068 commit 5b3b71bab75489714f72ce55621f6da7d5ec8d94 Author: Joonas Rikkonen <poe.regalis@gmail.com> Date: Wed Feb 6 10:59:09 2019 +0200 Prevent locations from being generated too close to each other. Closes #1048 commit b032b36a50b60432f565cab0178de749585562ad Author: Joonas Rikkonen <poe.regalis@gmail.com> Date: Wed Feb 6 10:48:43 2019 +0200 Fixed a couple of errors in the translation instructions in EnglishVanilla.xml commit a31b2f257ef863f2cdd1504a3a15356f95262225 Author: itchyOwl <lauri.harkanen@gmail.com> Date: Wed Feb 6 09:34:11 2019 +0200 Show inventory icons in the sprite editor. commit fb7a69d6179824dde0a44d27ce5143a1a25d0147 Author: Roni Kovaniemi <roni.kovaniemi@gmail.com> Date: Wed Feb 6 02:18:44 2019 +0200 Improved background smoke texture commit 888e86a0e7d6e6a70feb2b87ea16cee17adcfd76 Author: Juan Pablo Arce <juanjp600@users.noreply.github.com> Date: Tue Feb 5 11:36:06 2019 -0300 whoops strikes again commit 67e94c6bb9e59b20bc1b9f3cb796780d1c2141f7 Author: itchyOwl <lauri.harkanen@gmail.com> Date: Tue Feb 5 16:32:45 2019 +0200 Adjust the min and max values for the sight range and add a todo note. commit ad0becdf175a66c963b2cbea5259b435c250ffa6 Author: itchyOwl <lauri.harkanen@gmail.com> Date: Tue Feb 5 16:31:47 2019 +0200 Refactor the sound range calculation. It was way off. commit adc0aa96be5426dbb845e4138acab87c44c935ba Author: itchyOwl <lauri.harkanen@gmail.com> Date: Tue Feb 5 16:31:18 2019 +0200 Improve the ai target debug info. commit 9230ba0865896d5740898993ab3389659a4cbb4a Author: Juan Pablo Arce <juanjp600@users.noreply.github.com> Date: Tue Feb 5 10:53:51 2019 -0300 Attempted audio buffer queue fix commit dfbc61628de37a60acbaa208934957a9d892eb99 Author: Eetu <pitkanen.eetu@gmail.com> Date: Tue Feb 5 15:18:34 2019 +0200 Fixed: Rubber ducks not floating like a good duck should commit 8b8523dad99b5c1db271ac13e48975487a7c7c99 Merge: 509c67594 c0156c3d3 Author: Eetu <pitkanen.eetu@gmail.com> Date: Tue Feb 5 14:34:59 2019 +0200 Merge branch 'dev' of https://github.com/Regalis11/Barotrauma into dev commit 509c6759484750d44a154a7f1703f92d0d6e1692 Author: Eetu <pitkanen.eetu@gmail.com> Date: Tue Feb 5 14:34:53 2019 +0200 Fixed: Holdable items retaining their pushing ability even when the user is stunned or unconscious. Closes #1061 commit c0156c3d350b64309c8068f437ddd57765f0b911 Author: itchyOwl <lauri.harkanen@gmail.com> Date: Tue Feb 5 13:46:32 2019 +0200 If no limb is selected, select the limb with the most critical affliction. Re-evaluate when new affliction is received. Sort afflictions so that dmg/sec is prioritized. Implements the feature request #1033. commit 4a056c6e9b78f3d6f43574b1b9ff5493d36565b0 Author: Joonas Rikkonen <poe.regalis@gmail.com> Date: Tue Feb 5 13:25:57 2019 +0200 Fixed order messages not being visible in single player if the character issuing the order has no headset. Closes #1030 commit 357b14fb4f4b1a56a04d192c17a2ce8e0ab7405e Author: ezjamsen <ezjames.fi@gmail.com> Date: Tue Feb 5 12:52:40 2019 +0200 new load tips commit 1f158760e1ed79968f10647c0a2931d2c603281e Author: ezjamsen <ezjames.fi@gmail.com> Date: Tue Feb 5 12:52:20 2019 +0200 minor formatting tweak to xml commit c53438151043174e18fbfe979ac3b3b862d24255 Author: Joonas Rikkonen <poe.regalis@gmail.com> Date: Tue Feb 5 12:48:47 2019 +0200 Stop Steam auth session of a client when they disconnect. Probably fixes servers reporting incorrect player counts (#1049)? commit 2073b170e4fdd5cedd998ff9d01f37842995194b Merge: 9914631c7 9b912a7bf Author: Eetu <pitkanen.eetu@gmail.com> Date: Tue Feb 5 12:43:05 2019 +0200 Merge branch 'dev' of https://github.com/Regalis11/Barotrauma into dev commit 9914631c7eb30c02913cd4ed44f7b7827169ad83 Author: Eetu <pitkanen.eetu@gmail.com> Date: Tue Feb 5 12:42:53 2019 +0200 Fixed: Fabricator allowing new items to be created when the output is not empty, resulting in wasted materials. commit 9b912a7bf16bd121bbe8b7eae20f4a253a9e1eba Author: Joonas Rikkonen <poe.regalis@gmail.com> Date: Tue Feb 5 12:33:00 2019 +0200 Fixed LOS effect not working on ruins when looking at them from inside a sub commit aeaf190c6d3b45d4d12654926acbe223dc4f5888 Author: Joonas Rikkonen <poe.regalis@gmail.com> Date: Tue Feb 5 11:57:17 2019 +0200 Pressing the radio chat hotkey doesn't deselect the chatbox. Closes #1044
1352 lines
58 KiB
C#
1352 lines
58 KiB
C#
using Barotrauma.Extensions;
|
|
using Barotrauma.Items.Components;
|
|
using Barotrauma.Networking;
|
|
using FarseerPhysics;
|
|
using Microsoft.Xna.Framework;
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Xml.Linq;
|
|
|
|
namespace Barotrauma
|
|
{
|
|
partial class CrewManager
|
|
{
|
|
const float ChatMessageFadeTime = 10.0f;
|
|
|
|
/// <summary>
|
|
/// How long the previously selected character waits doing nothing when switching to another character
|
|
/// </summary>
|
|
const float CharacterWaitOnSwitch = 20.0f;
|
|
|
|
|
|
private List<CharacterInfo> characterInfos = new List<CharacterInfo>();
|
|
private List<Character> characters = new List<Character>();
|
|
|
|
private Point screenResolution;
|
|
|
|
public int WinningTeam = 1;
|
|
|
|
|
|
#region UI
|
|
|
|
private GUIFrame guiFrame;
|
|
private GUIFrame crewArea;
|
|
private GUIListBox characterListBox;
|
|
|
|
private GUIComponent reportButtonFrame;
|
|
|
|
private GUIButton scrollButtonUp, scrollButtonDown;
|
|
|
|
private GUIButton toggleCrewButton;
|
|
private float crewAreaOpenState;
|
|
private bool toggleCrewAreaOpen = true;
|
|
private int characterInfoWidth;
|
|
|
|
private ChatBox chatBox;
|
|
|
|
private float prevUIScale;
|
|
|
|
private GUIComponent orderTargetFrame, orderTargetFrameShadow;
|
|
|
|
public bool ToggleCrewAreaOpen
|
|
{
|
|
get { return toggleCrewAreaOpen; }
|
|
set { toggleCrewAreaOpen = value; }
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Constructors
|
|
|
|
public CrewManager(XElement element, bool isSinglePlayer)
|
|
: this(isSinglePlayer)
|
|
{
|
|
foreach (XElement subElement in element.Elements())
|
|
{
|
|
if (subElement.Name.ToString().ToLowerInvariant() != "character") continue;
|
|
|
|
var characterInfo = new CharacterInfo(subElement);
|
|
characterInfos.Add(characterInfo);
|
|
foreach (XElement invElement in subElement.Elements())
|
|
{
|
|
if (invElement.Name.ToString().ToLowerInvariant() != "inventory") continue;
|
|
characterInfo.InventoryData = invElement;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
partial void InitProjectSpecific()
|
|
{
|
|
guiFrame = new GUIFrame(new RectTransform(Vector2.One, GUICanvas.Instance), null, Color.Transparent)
|
|
{
|
|
CanBeFocused = false
|
|
};
|
|
|
|
Point scrollButtonSize = new Point((int)(200 * GUI.Scale), (int)(30 * GUI.Scale));
|
|
|
|
crewArea = new GUIFrame(HUDLayoutSettings.ToRectTransform(HUDLayoutSettings.CrewArea, guiFrame.RectTransform), "", Color.Transparent)
|
|
{
|
|
CanBeFocused = false
|
|
};
|
|
toggleCrewButton = new GUIButton(new RectTransform(new Point((int)(30 * GUI.Scale), HUDLayoutSettings.CrewArea.Height), guiFrame.RectTransform)
|
|
{ AbsoluteOffset = HUDLayoutSettings.CrewArea.Location },
|
|
"", style: "UIToggleButton");
|
|
toggleCrewButton.OnClicked += (GUIButton btn, object userdata) =>
|
|
{
|
|
toggleCrewAreaOpen = !toggleCrewAreaOpen;
|
|
foreach (GUIComponent child in btn.Children)
|
|
{
|
|
child.SpriteEffects = toggleCrewAreaOpen ? SpriteEffects.None : SpriteEffects.FlipHorizontally;
|
|
}
|
|
return true;
|
|
};
|
|
|
|
characterListBox = new GUIListBox(new RectTransform(new Point(100, (int)(crewArea.Rect.Height - scrollButtonSize.Y * 1.6f)), crewArea.RectTransform, Anchor.CenterLeft), false, Color.Transparent, null)
|
|
{
|
|
//Spacing = (int)(3 * GUI.Scale),
|
|
ScrollBarEnabled = false,
|
|
ScrollBarVisible = false,
|
|
CanBeFocused = false
|
|
};
|
|
|
|
scrollButtonUp = new GUIButton(new RectTransform(scrollButtonSize, crewArea.RectTransform, Anchor.TopLeft, Pivot.TopLeft), "", Alignment.Center, "GUIButtonVerticalArrow")
|
|
{
|
|
Visible = false,
|
|
UserData = -1,
|
|
OnClicked = ScrollCharacterList
|
|
};
|
|
scrollButtonDown = new GUIButton(new RectTransform(scrollButtonSize, crewArea.RectTransform, Anchor.BottomLeft, Pivot.BottomLeft), "", Alignment.Center, "GUIButtonVerticalArrow")
|
|
{
|
|
Visible = false,
|
|
UserData = 1,
|
|
OnClicked = ScrollCharacterList
|
|
};
|
|
scrollButtonDown.Children.ForEach(c => c.SpriteEffects = SpriteEffects.FlipVertically);
|
|
|
|
if (isSinglePlayer)
|
|
{
|
|
chatBox = new ChatBox(guiFrame, isSinglePlayer: true)
|
|
{
|
|
OnEnterMessage = (textbox, text) =>
|
|
{
|
|
if (Character.Controlled == null) { return true; }
|
|
|
|
textbox.TextColor = ChatMessage.MessageColor[(int)ChatMessageType.Default];
|
|
|
|
if (!string.IsNullOrWhiteSpace(text))
|
|
{
|
|
string msgCommand = ChatMessage.GetChatMessageCommand(text, out string msg);
|
|
AddSinglePlayerChatMessage(
|
|
Character.Controlled.Info.Name,
|
|
msg,
|
|
((msgCommand == "r" || msgCommand == "radio") && ChatMessage.CanUseRadio(Character.Controlled)) ? ChatMessageType.Radio : ChatMessageType.Default,
|
|
Character.Controlled);
|
|
}
|
|
textbox.Deselect();
|
|
textbox.Text = "";
|
|
return true;
|
|
}
|
|
};
|
|
chatBox.InputBox.OnTextChanged += chatBox.TypingChatMessage;
|
|
}
|
|
|
|
var reports = Order.PrefabList.FindAll(o => o.TargetAllCharacters && o.SymbolSprite != null);
|
|
reportButtonFrame = new GUILayoutGroup(new RectTransform(
|
|
new Point((HUDLayoutSettings.CrewArea.Height - (int)((reports.Count - 1) * 5 * GUI.Scale)) / reports.Count, HUDLayoutSettings.CrewArea.Height), guiFrame.RectTransform))
|
|
{
|
|
AbsoluteSpacing = (int)(5 * GUI.Scale),
|
|
UserData = "reportbuttons",
|
|
CanBeFocused = false
|
|
};
|
|
|
|
//report buttons
|
|
foreach (Order order in reports)
|
|
{
|
|
if (!order.TargetAllCharacters || order.SymbolSprite == null) continue;
|
|
var btn = new GUIButton(new RectTransform(new Point(reportButtonFrame.Rect.Width), reportButtonFrame.RectTransform), style: null)
|
|
{
|
|
OnClicked = (GUIButton button, object userData) =>
|
|
{
|
|
if (Character.Controlled == null || Character.Controlled.SpeechImpediment >= 100.0f) return false;
|
|
SetCharacterOrder(null, order, null, Character.Controlled);
|
|
return true;
|
|
},
|
|
UserData = order,
|
|
ToolTip = order.Name
|
|
};
|
|
|
|
new GUIFrame(new RectTransform(new Vector2(1.5f), btn.RectTransform, Anchor.Center), "OuterGlow")
|
|
{
|
|
Color = Color.Red * 0.8f,
|
|
HoverColor = Color.Red * 1.0f,
|
|
PressedColor = Color.Red * 0.6f,
|
|
UserData = "highlighted",
|
|
CanBeFocused = false,
|
|
Visible = false
|
|
};
|
|
|
|
var img = new GUIImage(new RectTransform(Vector2.One, btn.RectTransform), order.Prefab.SymbolSprite, scaleToFit: true)
|
|
{
|
|
Color = order.Color,
|
|
HoverColor = Color.Lerp(order.Color, Color.White, 0.5f),
|
|
ToolTip = order.Name
|
|
};
|
|
}
|
|
|
|
screenResolution = new Point(GameMain.GraphicsWidth, GameMain.GraphicsHeight);
|
|
|
|
prevUIScale = GUI.Scale;
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
#region Character list management
|
|
|
|
public Rectangle GetCharacterListArea()
|
|
{
|
|
return characterListBox.Rect;
|
|
}
|
|
|
|
public IEnumerable<Character> GetCharacters()
|
|
{
|
|
return characters;
|
|
}
|
|
|
|
public IEnumerable<CharacterInfo> GetCharacterInfos()
|
|
{
|
|
return characterInfos;
|
|
}
|
|
|
|
public void AddCharacter(Character character)
|
|
{
|
|
if (character.Removed)
|
|
{
|
|
DebugConsole.ThrowError("Tried to add a removed character to CrewManager!\n" + Environment.StackTrace);
|
|
return;
|
|
}
|
|
if (character.IsDead)
|
|
{
|
|
DebugConsole.ThrowError("Tried to add a dead character to CrewManager!\n" + Environment.StackTrace);
|
|
return;
|
|
}
|
|
|
|
if (!characters.Contains(character)) characters.Add(character);
|
|
if (!characterInfos.Contains(character.Info))
|
|
{
|
|
characterInfos.Add(character.Info);
|
|
}
|
|
|
|
CreateCharacterFrame(character, characterListBox.Content);
|
|
characterListBox.Content.RectTransform.SortChildren((c1, c2) => { return c2.NonScaledSize.X - c1.NonScaledSize.X; });
|
|
|
|
if (character is AICharacter)
|
|
{
|
|
var ai = character.AIController as HumanAIController;
|
|
if (ai == null)
|
|
{
|
|
DebugConsole.ThrowError("Error in crewmanager - attempted to give orders to a character with no HumanAIController");
|
|
return;
|
|
}
|
|
character.SetOrder(ai.CurrentOrder, "", null, false);
|
|
}
|
|
}
|
|
|
|
public void AddCharacterInfo(CharacterInfo characterInfo)
|
|
{
|
|
if (characterInfos.Contains(characterInfo))
|
|
{
|
|
DebugConsole.ThrowError("Tried to add the same character info to CrewManager twice.\n" + Environment.StackTrace);
|
|
return;
|
|
}
|
|
|
|
characterInfos.Add(characterInfo);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Remove the character from the crew (and crew menus).
|
|
/// </summary>
|
|
/// <param name="character">The character to remove</param>
|
|
/// <param name="removeInfo">If the character info is also removed, the character will not be visible in the round summary.</param>
|
|
public void RemoveCharacter(Character character, bool removeInfo = false)
|
|
{
|
|
if (character == null)
|
|
{
|
|
DebugConsole.ThrowError("Tried to remove a null character from CrewManager.\n" + Environment.StackTrace);
|
|
return;
|
|
}
|
|
characters.Remove(character);
|
|
if (removeInfo) characterInfos.Remove(character.Info);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Remove info of a selected character. The character will not be visible in any menus or the round summary.
|
|
/// </summary>
|
|
/// <param name="characterInfo"></param>
|
|
public void RemoveCharacterInfo(CharacterInfo characterInfo)
|
|
{
|
|
characterInfos.Remove(characterInfo);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Create the UI component that holds the character's portrait and order/report buttons for the character
|
|
/// </summary>
|
|
private GUIComponent CreateCharacterFrame(Character character, GUIComponent parent)
|
|
{
|
|
int correctOrderCount = 0, neutralOrderCount = 0, wrongOrderCount = 0;
|
|
//sort the orders
|
|
// 1. generic orders (follow, wait, etc)
|
|
// 2. orders appropriate for the character's job (captain -> steer, etc)
|
|
// 3. orders inappropriate for the job (captain -> operate reactor, etc)
|
|
List<Order> orders = new List<Order>();
|
|
foreach (Order order in Order.PrefabList)
|
|
{
|
|
if (order.TargetAllCharacters || order.SymbolSprite == null) continue;
|
|
if (order.AppropriateJobs == null || order.AppropriateJobs.Length == 0)
|
|
{
|
|
orders.Insert(0, order);
|
|
correctOrderCount++;
|
|
}
|
|
else if (order.HasAppropriateJob(character))
|
|
{
|
|
orders.Add(order);
|
|
neutralOrderCount++;
|
|
}
|
|
}
|
|
foreach (Order order in Order.PrefabList)
|
|
{
|
|
if (order.SymbolSprite == null) continue;
|
|
if (!order.TargetAllCharacters && !orders.Contains(order))
|
|
{
|
|
orders.Add(order);
|
|
wrongOrderCount++;
|
|
}
|
|
}
|
|
|
|
int spacing = (int)(10 * GUI.Scale);
|
|
int height = (int)(45 * GUI.Scale);
|
|
characterInfoWidth = (int)(170 * GUI.Scale);
|
|
|
|
float charactersPerView = characterListBox.Rect.Height / (float)(height + characterListBox.Spacing);
|
|
|
|
//if we can fit less than 25% of the last character or more than 75%,
|
|
//change the size of the character frame slightly to fit them more nicely in the list box
|
|
if (charactersPerView % 1.0f < 0.25f || charactersPerView % 1.0f > 0.75f)
|
|
{
|
|
height = (int)(characterListBox.Rect.Height / (float)Math.Round(charactersPerView)) - characterListBox.Spacing;
|
|
}
|
|
|
|
int iconSize = (int)(height * 0.8f);
|
|
|
|
var frame = new GUIFrame(new RectTransform(new Point(GameMain.GraphicsWidth, height), parent.RectTransform), style: "InnerFrame")
|
|
{
|
|
UserData = character,
|
|
CanBeFocused = false
|
|
};
|
|
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);
|
|
|
|
//---------------- character area ----------------
|
|
|
|
string characterToolTip = character.Info.Name;
|
|
if (character.Info.Job != null)
|
|
{
|
|
characterToolTip += " (" + character.Info.Job.Name + ")";
|
|
}
|
|
var characterArea = new GUIButton(new RectTransform(new Point(characterInfoWidth, frame.Rect.Height), frame.RectTransform, Anchor.CenterLeft), style: "GUITextBox")
|
|
{
|
|
UserData = character,
|
|
Color = frame.Color,
|
|
SelectedColor = frame.SelectedColor,
|
|
HoverColor = frame.HoverColor,
|
|
ToolTip = characterToolTip
|
|
};
|
|
if (isSinglePlayer)
|
|
{
|
|
characterArea.OnClicked = CharacterClicked;
|
|
}
|
|
else
|
|
{
|
|
characterArea.CanBeFocused = false;
|
|
characterArea.CanBeSelected = false;
|
|
}
|
|
|
|
var characterImage = new GUICustomComponent(new RectTransform(new Point(characterArea.Rect.Height, 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,
|
|
HoverColor = Color.White,
|
|
SelectedColor = Color.White,
|
|
ToolTip = characterToolTip
|
|
};
|
|
|
|
var characterName = new GUITextBlock(new RectTransform(new Point(characterArea.Rect.Width - characterImage.Rect.Width, characterArea.Rect.Height), characterArea.RectTransform, Anchor.CenterRight),
|
|
character.Name, textColor: frame.Color, font: GUI.SmallFont, wrap: true)
|
|
{
|
|
Color = frame.Color,
|
|
HoverColor = Color.Transparent,
|
|
SelectedColor = Color.Transparent,
|
|
CanBeFocused = false,
|
|
ToolTip = characterToolTip,
|
|
AutoScale = true
|
|
};
|
|
|
|
//---------------- order buttons ----------------
|
|
|
|
var orderButtonFrame = new GUILayoutGroup(new RectTransform(new Point(100, frame.Rect.Height), frame.RectTransform)
|
|
{ AbsoluteOffset = new Point(characterInfoWidth + spacing, 0) },
|
|
isHorizontal: true, childAnchor: Anchor.CenterLeft)
|
|
{
|
|
AbsoluteSpacing = (int)(10 * GUI.Scale),
|
|
UserData = "orderbuttons",
|
|
CanBeFocused = false
|
|
};
|
|
|
|
//listbox for holding the orders inappropriate for this character
|
|
//(so we can easily toggle their visibility)
|
|
var wrongOrderList = new GUIListBox(new RectTransform(new Point(50, orderButtonFrame.Rect.Height), orderButtonFrame.RectTransform), isHorizontal: true, style: null)
|
|
{
|
|
ScrollBarEnabled = false,
|
|
ScrollBarVisible = false,
|
|
Enabled = false,
|
|
Spacing = spacing,
|
|
ClampMouseRectToParent = false
|
|
};
|
|
wrongOrderList.Content.ClampMouseRectToParent = false;
|
|
|
|
for (int i = 0; i < orders.Count; i++)
|
|
{
|
|
var order = orders[i];
|
|
if (order.TargetAllCharacters) continue;
|
|
|
|
RectTransform btnParent = (i >= correctOrderCount + neutralOrderCount) ?
|
|
wrongOrderList.Content.RectTransform :
|
|
orderButtonFrame.RectTransform;
|
|
|
|
var btn = new GUIButton(new RectTransform(new Point(iconSize, iconSize), btnParent, Anchor.CenterLeft),
|
|
style: null);
|
|
|
|
new GUIFrame(new RectTransform(new Vector2(1.5f), btn.RectTransform, Anchor.Center), "OuterGlow")
|
|
{
|
|
Color = Color.Lerp(order.Color, frame.Color, 0.5f) * 0.8f,
|
|
HoverColor = Color.Lerp(order.Color, frame.Color, 0.5f) * 1.0f,
|
|
PressedColor = Color.Lerp(order.Color, frame.Color, 0.5f) * 0.6f,
|
|
UserData = "selected",
|
|
CanBeFocused = false,
|
|
Visible = false
|
|
};
|
|
|
|
var img = new GUIImage(new RectTransform(Vector2.One, btn.RectTransform), order.Prefab.SymbolSprite);
|
|
img.Scale = iconSize / (float)img.SourceRect.Width;
|
|
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);
|
|
}
|
|
else
|
|
{
|
|
if (order.ItemComponentType != null || order.ItemIdentifiers.Length > 0 || order.Options.Length > 1)
|
|
{
|
|
CreateOrderTargetFrame(button, character, order);
|
|
}
|
|
else
|
|
{
|
|
SetCharacterOrder(character, order, null, Character.Controlled);
|
|
}
|
|
}
|
|
return true;
|
|
};
|
|
btn.UserData = order;
|
|
btn.ToolTip = order.Name;
|
|
|
|
//divider between different groups of orders
|
|
if (i == correctOrderCount - 1 || i == correctOrderCount + neutralOrderCount - 1)
|
|
{
|
|
//TODO: divider sprite
|
|
new GUIFrame(new RectTransform(new Point(8, iconSize), orderButtonFrame.RectTransform), style: "GUIButton");
|
|
}
|
|
}
|
|
|
|
var toggleWrongOrderBtn = new GUIButton(new RectTransform(new Point((int)(30 * GUI.Scale), wrongOrderList.Rect.Height), wrongOrderList.Content.RectTransform),
|
|
"", style: "UIToggleButton")
|
|
{
|
|
UserData = "togglewrongorder",
|
|
CanBeFocused = false
|
|
};
|
|
|
|
wrongOrderList.RectTransform.NonScaledSize = new Point(
|
|
wrongOrderList.Content.Children.Sum(c => c.Rect.Width + wrongOrderList.Spacing),
|
|
wrongOrderList.RectTransform.NonScaledSize.Y);
|
|
wrongOrderList.RectTransform.SetAsLastChild();
|
|
|
|
new GUIFrame(new RectTransform(new Point(
|
|
wrongOrderList.Rect.Width - toggleWrongOrderBtn.Rect.Width - wrongOrderList.Spacing * 2,
|
|
wrongOrderList.Rect.Height), wrongOrderList.Content.RectTransform),
|
|
style: null)
|
|
{
|
|
CanBeFocused = false
|
|
};
|
|
|
|
//scale to fit the content
|
|
orderButtonFrame.RectTransform.NonScaledSize = new Point(
|
|
orderButtonFrame.Children.Sum(c => c.Rect.Width + orderButtonFrame.AbsoluteSpacing),
|
|
orderButtonFrame.RectTransform.NonScaledSize.Y);
|
|
|
|
frame.RectTransform.NonScaledSize = new Point(
|
|
characterInfoWidth + spacing + (orderButtonFrame.Rect.Width - wrongOrderList.Rect.Width),
|
|
frame.RectTransform.NonScaledSize.Y);
|
|
|
|
characterListBox.RectTransform.NonScaledSize = new Point(
|
|
characterListBox.Content.Children.Max(c => c.Rect.Width) + wrongOrderList.Rect.Width,
|
|
characterListBox.RectTransform.NonScaledSize.Y);
|
|
characterListBox.Content.RectTransform.NonScaledSize = characterListBox.RectTransform.NonScaledSize;
|
|
characterListBox.UpdateScrollBarSize();
|
|
return frame;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sets which character is selected in the crew UI (highlight effect etc)
|
|
/// </summary>
|
|
public bool CharacterClicked(GUIComponent component, object selection)
|
|
{
|
|
Character character = selection as Character;
|
|
if (character == null || character.IsDead || character.IsUnconscious) return false;
|
|
SelectCharacter(character);
|
|
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)
|
|
{
|
|
characterBlock.Parent.RemoveChild(characterBlock);
|
|
}
|
|
if (characterInfos.Contains(revivedCharacter.Info)) AddCharacter(revivedCharacter);
|
|
}
|
|
|
|
public void KillCharacter(Character killedCharacter)
|
|
{
|
|
if (characterListBox.Content.GetChildByUserData(killedCharacter) is GUIComponent characterBlock)
|
|
{
|
|
CoroutineManager.StartCoroutine(KillCharacterAnim(characterBlock));
|
|
}
|
|
RemoveCharacter(killedCharacter);
|
|
}
|
|
|
|
private bool ScrollCharacterList(GUIButton button, object obj)
|
|
{
|
|
if (characterListBox.Content.CountChildren == 0) return false;
|
|
int dir = (int)obj;
|
|
|
|
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;
|
|
}
|
|
|
|
private IEnumerable<object> KillCharacterAnim(GUIComponent component)
|
|
{
|
|
List<GUIComponent> components = component.GetAllChildren().ToList();
|
|
components.Add(component);
|
|
foreach (GUIComponent comp in components)
|
|
{
|
|
comp.Color = Color.DarkRed;
|
|
}
|
|
|
|
yield return new WaitForSeconds(1.0f);
|
|
|
|
float timer = 0.0f;
|
|
float hideDuration = 1.0f;
|
|
while (timer < hideDuration)
|
|
{
|
|
foreach (GUIComponent comp in components)
|
|
{
|
|
comp.Color = Color.Lerp(Color.DarkRed, Color.Transparent, timer / hideDuration);
|
|
comp.RectTransform.LocalScale = new Vector2(comp.RectTransform.LocalScale.X, 1.0f - (timer / hideDuration));
|
|
}
|
|
timer += CoroutineManager.DeltaTime;
|
|
yield return CoroutineStatus.Running;
|
|
}
|
|
component.Parent?.RemoveChild(component);
|
|
characterListBox.UpdateScrollBarSize();
|
|
yield return CoroutineStatus.Success;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Dialog
|
|
|
|
/// <summary>
|
|
/// Adds the message to the single player chatbox.
|
|
/// </summary>
|
|
public void AddSinglePlayerChatMessage(string senderName, string text, ChatMessageType messageType, Character sender)
|
|
{
|
|
if (!isSinglePlayer)
|
|
{
|
|
DebugConsole.ThrowError("Cannot add messages to single player chat box in multiplayer mode!\n" + Environment.StackTrace);
|
|
return;
|
|
}
|
|
|
|
chatBox.AddMessage(ChatMessage.Create(senderName, text, messageType, sender));
|
|
}
|
|
|
|
private WifiComponent GetHeadset(Character character, bool requireEquipped)
|
|
{
|
|
if (character?.Inventory == null) return null;
|
|
|
|
var radioItem = character.Inventory.Items.FirstOrDefault(it => it != null && it.GetComponent<WifiComponent>() != null);
|
|
if (radioItem == null) return null;
|
|
if (requireEquipped && !character.HasEquippedItem(radioItem)) return null;
|
|
|
|
return radioItem.GetComponent<WifiComponent>();
|
|
}
|
|
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// Sets the character's current order (if it's close enough to receive messages from orderGiver) and
|
|
/// displays the order in the crew UI
|
|
/// </summary>
|
|
public void SetCharacterOrder(Character character, Order order, string option, Character orderGiver)
|
|
{
|
|
if (order != null && order.TargetAllCharacters)
|
|
{
|
|
if (orderGiver == null || orderGiver.CurrentHull == null) return;
|
|
AddOrder(new Order(order.Prefab, orderGiver.CurrentHull, null), order.Prefab.FadeOutTime);
|
|
|
|
if (IsSinglePlayer)
|
|
{
|
|
orderGiver.Speak(
|
|
order.GetChatMessage("", orderGiver.CurrentHull?.RoomName), ChatMessageType.Order);
|
|
}
|
|
else
|
|
{
|
|
OrderChatMessage msg = new OrderChatMessage(order, "", orderGiver.CurrentHull, null, orderGiver);
|
|
if (GameMain.Client != null)
|
|
{
|
|
GameMain.Client.SendChatMessage(msg);
|
|
}
|
|
else if (GameMain.Server != null)
|
|
{
|
|
GameMain.Server.SendOrderChatMessage(msg);
|
|
}
|
|
}
|
|
return;
|
|
}
|
|
|
|
character.SetOrder(order, option, orderGiver);
|
|
if (IsSinglePlayer)
|
|
{
|
|
orderGiver?.Speak(
|
|
order.GetChatMessage(character.Name, orderGiver.CurrentHull?.RoomName, option), null);
|
|
}
|
|
else if (orderGiver != null)
|
|
{
|
|
OrderChatMessage msg = new OrderChatMessage(order, option, order.TargetItemComponent?.Item, character, orderGiver);
|
|
if (GameMain.Client != null)
|
|
{
|
|
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.
|
|
/// </summary>
|
|
public void DisplayCharacterOrder(Character character, Order order)
|
|
{
|
|
foreach (GUIComponent characterListElement in characterListBox.Content.Children)
|
|
{
|
|
var characterFrame = characterListElement.FindChild(character);
|
|
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)
|
|
{
|
|
if (child is GUIButton orderBtn)
|
|
{
|
|
orderButtons.Add(orderBtn);
|
|
}
|
|
//the non-character-appropriate orders are in a hideable listbox, we need to go deeper!
|
|
else if (child is GUIListBox listBox)
|
|
{
|
|
foreach (GUIComponent listBoxElement in listBox.Content.Children)
|
|
{
|
|
if (listBoxElement is GUIButton orderBtn2 && listBoxElement.UserData is Order) orderButtons.Add(orderBtn2);
|
|
}
|
|
}
|
|
}
|
|
|
|
foreach (GUIButton button in orderButtons)
|
|
{
|
|
var selectedIndicator = button.GetChildByUserData("selected");
|
|
if (selectedIndicator != null)
|
|
{
|
|
selectedIndicator.Visible = (order != null && ((Order)button.UserData).Prefab == order.Prefab);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 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.MainSub;
|
|
|
|
List<Item> matchingItems = new List<Item>();
|
|
if (order.ItemComponentType != null || order.ItemIdentifiers.Length > 0)
|
|
{
|
|
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));
|
|
|
|
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)
|
|
{
|
|
Rectangle subBorders = submarine.GetDockedBorders();
|
|
|
|
Point frameSize;
|
|
if (subBorders.Width > subBorders.Height)
|
|
{
|
|
//make sure the right side doesn't go over the right side of the screen
|
|
frameSize.X = Math.Min(GameMain.GraphicsWidth / 2, GameMain.GraphicsWidth - orderButton.Rect.Center.X - 50);
|
|
//height depends on the dimensions of the sub
|
|
frameSize.Y = (int)(frameSize.X * (subBorders.Height / (float)subBorders.Width));
|
|
}
|
|
else
|
|
{
|
|
//make sure the bottom side doesn't go over the bottom of the screen
|
|
frameSize.Y = Math.Min((int)(GameMain.GraphicsHeight * 0.6f), GameMain.GraphicsHeight - orderButton.Rect.Center.Y - 50);
|
|
//width depends on the dimensions of the sub
|
|
frameSize.X = (int)(frameSize.Y * (subBorders.Width / (float)subBorders.Height));
|
|
}
|
|
orderTargetFrame = new GUIFrame(new RectTransform(frameSize, GUI.Canvas)
|
|
{ AbsoluteOffset = new Point(orderButton.Rect.Center.X, orderButton.Rect.Bottom) },
|
|
style: "InnerFrame")
|
|
{
|
|
UserData = character
|
|
};
|
|
submarine.CreateMiniMap(orderTargetFrame, matchingItems);
|
|
|
|
new GUICustomComponent(new RectTransform(Vector2.One, orderTargetFrame.RectTransform), DrawMiniMapOverlay)
|
|
{
|
|
CanBeFocused = false,
|
|
UserData = submarine
|
|
};
|
|
|
|
List<GUIComponent> optionFrames = new List<GUIComponent>();
|
|
foreach (Item item in matchingItems)
|
|
{
|
|
var itemTargetFrame = orderTargetFrame.Children.First().FindChild(item);
|
|
if (itemTargetFrame == null) continue;
|
|
|
|
Anchor anchor = Anchor.TopLeft;
|
|
if (itemTargetFrame.RectTransform.RelativeOffset.X < 0.5f && itemTargetFrame.RectTransform.RelativeOffset.Y < 0.5f)
|
|
anchor = Anchor.BottomRight;
|
|
else if (itemTargetFrame.RectTransform.RelativeOffset.X > 0.5f && itemTargetFrame.RectTransform.RelativeOffset.Y < 0.5f)
|
|
anchor = Anchor.BottomLeft;
|
|
else if (itemTargetFrame.RectTransform.RelativeOffset.X < 0.5f && itemTargetFrame.RectTransform.RelativeOffset.Y > 0.5f)
|
|
anchor = Anchor.TopRight;
|
|
|
|
var optionFrame = new GUIFrame(new RectTransform(new Point((int)(250 * GUI.Scale), (int)((40 + order.Options.Length * 40) * GUI.Scale)), itemTargetFrame.RectTransform, anchor),
|
|
style: "InnerFrame");
|
|
optionFrames.Add(optionFrame);
|
|
|
|
var optionContainer = new GUILayoutGroup(new RectTransform(new Vector2(0.9f), optionFrame.RectTransform, Anchor.Center))
|
|
{
|
|
Stretch = true,
|
|
RelativeSpacing = 0.05f
|
|
};
|
|
|
|
new GUITextBlock(new RectTransform(new Vector2(1.0f,0.3f), optionContainer.RectTransform), item != null ? item.Name : order.Name);
|
|
for (int i = 0; i < order.Options.Length; i++)
|
|
{
|
|
string option = order.Options[i];
|
|
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)),
|
|
Font = GUI.SmallFont,
|
|
OnClicked = (btn, userData) =>
|
|
{
|
|
if (Character.Controlled == null) return false;
|
|
SetCharacterOrder(character, userData as Order, option, Character.Controlled);
|
|
orderTargetFrame = null;
|
|
return true;
|
|
}
|
|
};
|
|
}
|
|
}
|
|
|
|
GUI.PreventElementOverlap(optionFrames, null, new Rectangle(10, 10, GameMain.GraphicsWidth - 20, GameMain.GraphicsHeight - 20));
|
|
}
|
|
//only one target (or an order with no particular targets), just show options
|
|
else
|
|
{
|
|
orderTargetFrame = new GUILayoutGroup(new RectTransform(new Vector2(0.2f + order.Options.Length * 0.1f, 0.18f), GUI.Canvas)
|
|
{ AbsoluteOffset = new Point(orderButton.Rect.Center.X, orderButton.Rect.Bottom) },
|
|
isHorizontal: true, childAnchor: Anchor.BottomLeft)
|
|
{
|
|
UserData = character,
|
|
Stretch = true
|
|
};
|
|
//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;
|
|
string option = order.Options[i];
|
|
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)),
|
|
OnClicked = (btn, userData) =>
|
|
{
|
|
if (Character.Controlled == null) return false;
|
|
SetCharacterOrder(character, userData as Order, option, Character.Controlled);
|
|
orderTargetFrame = null;
|
|
return true;
|
|
}
|
|
};
|
|
//lines between the order buttons
|
|
if (i < order.Options.Length - 1)
|
|
{
|
|
//TODO: sprite
|
|
new GUIFrame(new RectTransform(new Vector2(0.1f, 1.0f), orderTargetFrame.RectTransform), style: null);
|
|
}
|
|
}
|
|
}
|
|
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) }, style: "OuterGlow", color: Color.Black * 0.65f);
|
|
}
|
|
|
|
private void DrawMiniMapOverlay(SpriteBatch spriteBatch, GUICustomComponent container)
|
|
{
|
|
Submarine sub = container.UserData as Submarine;
|
|
|
|
if (sub?.HullVertices == null) { return; }
|
|
|
|
var dockedBorders = sub.GetDockedBorders();
|
|
dockedBorders.Location += sub.WorldPosition.ToPoint();
|
|
|
|
float scale = Math.Min(
|
|
container.Rect.Width / (float)dockedBorders.Width,
|
|
container.Rect.Height / (float)dockedBorders.Height) * 0.9f;
|
|
|
|
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);
|
|
start.Y = -start.Y;
|
|
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 (GameMain.GraphicsWidth != screenResolution.X || GameMain.GraphicsHeight != screenResolution.Y ||
|
|
prevUIScale != GUI.Scale)
|
|
{
|
|
var prevCharacterListBox = characterListBox;
|
|
InitProjectSpecific();
|
|
|
|
foreach (GUIComponent c in prevCharacterListBox.Content.Children)
|
|
{
|
|
Character character = c.UserData as Character;
|
|
if (character == null) continue;
|
|
AddCharacter(character);
|
|
DisplayCharacterOrder(character, character.CurrentOrder);
|
|
}
|
|
}
|
|
|
|
guiFrame.AddToGUIUpdateList();
|
|
if (orderTargetFrame != null)
|
|
{
|
|
orderTargetFrameShadow?.AddToGUIUpdateList();
|
|
orderTargetFrame?.AddToGUIUpdateList();
|
|
}
|
|
}
|
|
|
|
public void SelectNextCharacter()
|
|
{
|
|
if (GameMain.IsMultiplayer) { return; }
|
|
if (characters.None()) { return; }
|
|
SelectCharacter(characters[TryAdjustIndex(1)]);
|
|
}
|
|
|
|
public void SelectPreviousCharacter()
|
|
{
|
|
if (GameMain.IsMultiplayer) { return; }
|
|
if (characters.None()) { return; }
|
|
SelectCharacter(characters[TryAdjustIndex(-1)]);
|
|
}
|
|
|
|
private void SelectCharacter(Character character)
|
|
{
|
|
//make the previously selected character wait in place for some time
|
|
//(so they don't immediately start idling and walking away from their station)
|
|
if (Character.Controlled?.AIController?.ObjectiveManager != null)
|
|
{
|
|
Character.Controlled.AIController.ObjectiveManager.WaitTimer = CharacterWaitOnSwitch;
|
|
}
|
|
Character.Controlled = character;
|
|
}
|
|
|
|
private int TryAdjustIndex(int amount)
|
|
{
|
|
int index = Character.Controlled == null ? 0 : characters.IndexOf(Character.Controlled) + amount;
|
|
int lastIndex = characters.Count - 1;
|
|
if (index > lastIndex)
|
|
{
|
|
index = 0;
|
|
}
|
|
if (index < 0)
|
|
{
|
|
index = lastIndex;
|
|
}
|
|
return index;
|
|
}
|
|
|
|
partial void UpdateProjectSpecific(float deltaTime)
|
|
{
|
|
// Quick selection
|
|
if (!GameMain.IsMultiplayer && GUI.KeyboardDispatcher.Subscriber == null)
|
|
{
|
|
if (PlayerInput.KeyHit(InputType.SelectNextCharacter))
|
|
{
|
|
SelectNextCharacter();
|
|
}
|
|
if (PlayerInput.KeyHit(InputType.SelectPreviousCharacter))
|
|
{
|
|
SelectPreviousCharacter();
|
|
}
|
|
}
|
|
|
|
if (GUI.DisableHUD) return;
|
|
if (chatBox != null)
|
|
{
|
|
chatBox.Update(deltaTime);
|
|
chatBox.InputBox.Visible = Character.Controlled != null;
|
|
|
|
if (!DebugConsole.IsOpen && chatBox.InputBox.Visible)
|
|
{
|
|
if (PlayerInput.KeyHit(InputType.Chat))
|
|
{
|
|
if (chatBox.InputBox.Selected)
|
|
{
|
|
chatBox.InputBox.Text = "";
|
|
chatBox.InputBox.Deselect();
|
|
}
|
|
else
|
|
{
|
|
chatBox.InputBox.Select();
|
|
}
|
|
}
|
|
|
|
if (PlayerInput.KeyHit(InputType.RadioChat) && !chatBox.InputBox.Selected)
|
|
{
|
|
chatBox.InputBox.Select();
|
|
chatBox.InputBox.Text = "r; ";
|
|
}
|
|
}
|
|
}
|
|
|
|
crewArea.Visible = characters.Count > 0 && CharacterHealth.OpenHealthWindow == null;
|
|
if (orderTargetFrame != null) orderTargetFrame.Visible = characterListBox.Visible;
|
|
|
|
scrollButtonUp.Visible = characterListBox.BarScroll > 0.01f && characterListBox.BarSize < 1.0f;
|
|
scrollButtonDown.Visible = characterListBox.BarScroll < 0.99 && characterListBox.BarSize < 1.0f;
|
|
|
|
foreach (GUIComponent child in characterListBox.Content.Children)
|
|
{
|
|
child.Visible =
|
|
Character.Controlled == null ||
|
|
(Character.Controlled != ((Character)child.UserData) && Character.Controlled.TeamID == ((Character)child.UserData).TeamID);
|
|
|
|
if (child.Visible)
|
|
{
|
|
GUIListBox wrongOrderList = child.GetChildByUserData("orderbuttons")?.GetChild<GUIListBox>();
|
|
if (wrongOrderList != null)
|
|
{
|
|
Rectangle hoverRect = wrongOrderList.Rect;
|
|
if (wrongOrderList.BarScroll < 0.5f)
|
|
{
|
|
//higher tolerance when the orderlist is open (mouse needs to be moved further before it closes)
|
|
hoverRect.Inflate((int)(50 * GUI.Scale), (int)(50 * GUI.Scale));
|
|
}
|
|
else
|
|
{
|
|
hoverRect.Inflate((int)(30 * GUI.Scale), (int)(0 * GUI.Scale));
|
|
}
|
|
|
|
bool toggleOpen =
|
|
characterListBox.Content.Rect.Contains(PlayerInput.MousePosition) &&
|
|
hoverRect.Contains(PlayerInput.MousePosition);
|
|
wrongOrderList.CanBeFocused = toggleOpen;
|
|
wrongOrderList.Content.CanBeFocused = toggleOpen;
|
|
var wrongOrderBtn = wrongOrderList.GetChildByUserData("togglewrongorderbtn");
|
|
if (wrongOrderBtn != null)
|
|
{
|
|
wrongOrderBtn.CanBeFocused = toggleOpen;
|
|
}
|
|
|
|
//order target frame open on this character, check if we're giving any of the orders in wrongOrderList
|
|
if (!toggleOpen && orderTargetFrame != null && orderTargetFrame.UserData == child.UserData)
|
|
{
|
|
toggleOpen = wrongOrderList.Content.Children.Any(c =>
|
|
c.UserData is Order order &&
|
|
orderTargetFrame.Children.Any(c2 => c2.UserData == c.UserData));
|
|
}
|
|
|
|
float scroll = MathHelper.Clamp(wrongOrderList.BarScroll + (toggleOpen ? -deltaTime * 5.0f : deltaTime * 5.0f), 0.0f, 1.0f);
|
|
if (Math.Abs(wrongOrderList.BarScroll - scroll) > 0.01f) { wrongOrderList.BarScroll = scroll; }
|
|
}
|
|
}
|
|
}
|
|
|
|
crewArea.RectTransform.AbsoluteOffset =
|
|
Vector2.SmoothStep(new Vector2(-crewArea.Rect.Width, 0), new Vector2(toggleCrewButton.Rect.Width, 0), crewAreaOpenState).ToPoint();
|
|
crewAreaOpenState = toggleCrewAreaOpen ?
|
|
Math.Min(crewAreaOpenState + deltaTime * 2.0f, 1.0f) :
|
|
Math.Max(crewAreaOpenState - deltaTime * 2.0f, 0.0f);
|
|
|
|
if (GUI.KeyboardDispatcher.Subscriber == null &&
|
|
PlayerInput.KeyHit(InputType.CrewOrders) &&
|
|
characters.Contains(Character.Controlled))
|
|
{
|
|
//deselect construction unless it's the ladders the character is climbing
|
|
if (Character.Controlled != null &&
|
|
Character.Controlled.SelectedConstruction != null &&
|
|
Character.Controlled.SelectedConstruction.GetComponent<Items.Components.Ladder>() == null)
|
|
{
|
|
Character.Controlled.SelectedConstruction = null;
|
|
}
|
|
toggleCrewAreaOpen = !toggleCrewAreaOpen;
|
|
}
|
|
|
|
UpdateReports(deltaTime);
|
|
UpdateConversations(deltaTime);
|
|
|
|
if (orderTargetFrame != null)
|
|
{
|
|
Rectangle hoverArea = orderTargetFrame.Rect;
|
|
foreach (GUIComponent child in orderTargetFrame.Children.First().Children)
|
|
{
|
|
if (!(child.UserData is Item)) continue;
|
|
foreach (GUIComponent grandChild in child.Children)
|
|
{
|
|
hoverArea = Rectangle.Union(hoverArea, grandChild.Rect);
|
|
}
|
|
}
|
|
hoverArea.Inflate(100, 100);
|
|
|
|
if (!hoverArea.Contains(PlayerInput.MousePosition)) orderTargetFrame = null;
|
|
}
|
|
}
|
|
|
|
#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();
|
|
|
|
if (!teamIDs.Any()) teamIDs.Add(0);
|
|
|
|
int listBoxHeight = 300 / teamIDs.Count;
|
|
|
|
var content = new GUILayoutGroup(new RectTransform(new Vector2(0.5f, 1.0f), crewFrame.RectTransform))
|
|
{
|
|
Stretch = true
|
|
};
|
|
|
|
for (int i = 0; i < teamIDs.Count; i++)
|
|
{
|
|
if (teamIDs.Count > 1)
|
|
{
|
|
new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.1f), content.RectTransform), CombatMission.GetTeamName(teamIDs[i]));
|
|
}
|
|
|
|
GUIListBox crewList = new GUIListBox(new RectTransform(new Vector2(1.0f, 0.5f), content.RectTransform) { RelativeOffset = new Vector2(0.0f, 0.1f) })
|
|
{
|
|
UserData = crewFrame
|
|
};
|
|
crewList.OnSelected = (component, obj) =>
|
|
{
|
|
SelectCrewCharacter(component.UserData as Character, crewList);
|
|
return true;
|
|
};
|
|
|
|
foreach (Character character in crew.Where(c => c.TeamID == teamIDs[i]))
|
|
{
|
|
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
|
|
};
|
|
|
|
var paddedFrame = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.9f), frame.RectTransform, Anchor.Center), isHorizontal: true)
|
|
{
|
|
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()))
|
|
{
|
|
CanBeFocused = false,
|
|
HoverColor = Color.White,
|
|
SelectedColor = Color.White
|
|
};
|
|
|
|
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),
|
|
textColor: character.Info.Job.Prefab.UIColor);
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Select a character from CrewListFrame
|
|
/// </summary>
|
|
protected bool SelectCrewCharacter(Character character, GUIComponent crewList)
|
|
{
|
|
if (character == null) return false;
|
|
|
|
GUIComponent crewFrame = (GUIComponent)crewList.UserData;
|
|
|
|
GUIComponent existingPreview = crewFrame.FindChild("SelectedCharacter");
|
|
if (existingPreview != null) crewFrame.RemoveChild(existingPreview);
|
|
|
|
var previewPlayer = new GUIFrame(new RectTransform(new Vector2(0.4f, 0.8f), crewFrame.RectTransform, Anchor.CenterRight) { RelativeOffset = new Vector2(0.05f, 0.0f) }, style: "InnerFrame")
|
|
{
|
|
UserData = "SelectedCharacter"
|
|
};
|
|
|
|
character.Info.CreateInfoFrame(previewPlayer);
|
|
|
|
if (GameMain.NetworkMember != null) GameMain.NetworkMember.SelectCrewCharacter(character, previewPlayer);
|
|
|
|
return true;
|
|
}
|
|
|
|
#region Reports
|
|
|
|
/// <summary>
|
|
/// Enables/disables report buttons when needed
|
|
/// </summary>
|
|
public void UpdateReports(float deltaTime)
|
|
{
|
|
bool canIssueOrders = false;
|
|
if (Character.Controlled?.CurrentHull != null && Character.Controlled.SpeechImpediment < 100.0f)
|
|
{
|
|
WifiComponent radio = GetHeadset(Character.Controlled, true);
|
|
canIssueOrders = radio != null && radio.CanTransmit();
|
|
}
|
|
|
|
if (canIssueOrders)
|
|
{
|
|
reportButtonFrame.Visible = true;
|
|
|
|
var reportButtonParent = chatBox ?? GameMain.NetworkMember.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);
|
|
|
|
bool hasFires = Character.Controlled.CurrentHull.FireSources.Count > 0;
|
|
ToggleReportButton("reportfire", hasFires);
|
|
|
|
bool hasLeaks = Character.Controlled.CurrentHull.ConnectedGaps.Any(g => !g.IsRoomToRoom && g.Open > 0.0f);
|
|
ToggleReportButton("reportbreach", hasLeaks);
|
|
|
|
bool hasIntruders = Character.CharacterList.Any(c =>
|
|
c.CurrentHull == Character.Controlled.CurrentHull && !c.IsDead &&
|
|
(c.AIController is EnemyAIController || c.TeamID != Character.Controlled.TeamID));
|
|
|
|
ToggleReportButton("reportintruders", hasIntruders);
|
|
|
|
foreach (GUIComponent reportButton in reportButtonFrame.Children)
|
|
{
|
|
var highlight = reportButton.GetChildByUserData("highlighted");
|
|
if (highlight.Visible)
|
|
{
|
|
highlight.RectTransform.LocalScale = new Vector2(1.25f + (float)Math.Sin(Timing.TotalTime * 5.0f) * 0.25f);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
reportButtonFrame.Visible = false;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Should report buttons be visible on the screen atm?
|
|
/// </summary>
|
|
private bool ReportButtonsVisible()
|
|
{
|
|
return CharacterHealth.OpenHealthWindow == null;
|
|
}
|
|
|
|
private bool ReportButtonClicked(GUIButton button, object userData)
|
|
{
|
|
//order targeted to all characters
|
|
Order order = userData as Order;
|
|
if (order.TargetAllCharacters)
|
|
{
|
|
if (Character.Controlled == null || Character.Controlled.CurrentHull == null) return false;
|
|
AddOrder(new Order(order.Prefab, Character.Controlled.CurrentHull, null), order.Prefab.FadeOutTime);
|
|
SetCharacterOrder(null, order, "", Character.Controlled);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
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 &&
|
|
o.First.AITag == orderAiTag))
|
|
{
|
|
enabled = false;
|
|
}*/
|
|
|
|
var reportButton = reportButtonFrame.GetChildByUserData(order);
|
|
if (reportButton != null)
|
|
{
|
|
reportButton.GetChildByUserData("highlighted").Visible = enabled;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
public void InitSinglePlayerRound()
|
|
{
|
|
characterListBox.ClearChildren();
|
|
characters.Clear();
|
|
|
|
WayPoint[] waypoints = WayPoint.SelectCrewSpawnPoints(characterInfos, Submarine.MainSub);
|
|
|
|
for (int i = 0; i < waypoints.Length; i++)
|
|
{
|
|
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)
|
|
{
|
|
character.Info.SpawnInventoryItems(character.Inventory, character.Info.InventoryData);
|
|
}
|
|
|
|
AddCharacter(character);
|
|
if (i == 0)
|
|
{
|
|
Character.Controlled = character;
|
|
}
|
|
}
|
|
|
|
if (characters.Any()) characterListBox.Select(0);
|
|
|
|
conversationTimer = Rand.Range(5.0f, 10.0f);
|
|
}
|
|
|
|
public void EndRound()
|
|
{
|
|
//remove characterinfos whose characters have been removed or killed
|
|
characterInfos.RemoveAll(c => c.Character == null || c.Character.Removed || c.CauseOfDeath != null);
|
|
|
|
characters.Clear();
|
|
characterListBox.ClearChildren();
|
|
}
|
|
|
|
public void Reset()
|
|
{
|
|
characters.Clear();
|
|
characterInfos.Clear();
|
|
characterListBox.ClearChildren();
|
|
}
|
|
|
|
public void Save(XElement parentElement)
|
|
{
|
|
XElement element = new XElement("crew");
|
|
|
|
foreach (CharacterInfo ci in characterInfos)
|
|
{
|
|
var infoElement = ci.Save(element);
|
|
if (ci.InventoryData != null)
|
|
{
|
|
infoElement.Add(ci.InventoryData);
|
|
}
|
|
}
|
|
parentElement.Add(element);
|
|
}
|
|
}
|
|
}
|