- TextManager automatically replaces "\n" strings with a newline.

- Removed instantiating traitor start popup from client-side TraitorManager (instead the client receives the start message from the server).
- GUIMessageBoxes don't leave unnecessary empty space for the header if the header text is empty.
- More hard-coded text removal.
This commit is contained in:
Joonas Rikkonen
2017-12-27 16:07:00 +02:00
parent 4f0b190371
commit 3d73f28362
8 changed files with 95 additions and 105 deletions
@@ -103,7 +103,6 @@
<Compile Include="Source\GameSession\CrewManager.cs" /> <Compile Include="Source\GameSession\CrewManager.cs" />
<Compile Include="Source\GameSession\GameMode.cs" /> <Compile Include="Source\GameSession\GameMode.cs" />
<Compile Include="Source\GameSession\GameModes\SinglePlayerCampaign.cs" /> <Compile Include="Source\GameSession\GameModes\SinglePlayerCampaign.cs" />
<Compile Include="Source\GameSession\GameModes\TraitorManager.cs" />
<Compile Include="Source\GameSession\GameModes\Tutorials\BasicTutorial.cs" /> <Compile Include="Source\GameSession\GameModes\Tutorials\BasicTutorial.cs" />
<Compile Include="Source\GameSession\GameModes\Tutorials\EditorTutorial.cs" /> <Compile Include="Source\GameSession\GameModes\Tutorials\EditorTutorial.cs" />
<Compile Include="Source\GameSession\GameModes\Tutorials\TutorialMode.cs" /> <Compile Include="Source\GameSession\GameModes\Tutorials\TutorialMode.cs" />
@@ -43,6 +43,8 @@ namespace Barotrauma
: base(new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight), : base(new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight),
Color.Black * 0.5f, Alignment.TopLeft, null, parent) Color.Black * 0.5f, Alignment.TopLeft, null, parent)
{ {
int headerHeight = 30;
if (height == 0) if (height == 0)
{ {
string wrappedText = ToolBox.WrapText(text, width, GUI.Font); string wrappedText = ToolBox.WrapText(text, width, GUI.Font);
@@ -51,18 +53,18 @@ namespace Barotrauma
{ {
height += (int)GUI.Font.MeasureString(line).Y; height += (int)GUI.Font.MeasureString(line).Y;
} }
height += 220; height += string.IsNullOrWhiteSpace(headerText) ? 220 : 220 - headerHeight;
} }
var frame = new GUIFrame(new Rectangle(0, 0, width, height), null, Alignment.Center, "", this); var frame = new GUIFrame(new Rectangle(0, 0, width, height), null, Alignment.Center, "", this);
GUI.Style.Apply(frame, "", this); GUI.Style.Apply(frame, "", this);
var header = new GUITextBlock(new Rectangle(0, 0, 0, 30), headerText, null, null, textAlignment, "", frame, true); var header = new GUITextBlock(new Rectangle(0, 0, 0, headerHeight), headerText, null, null, textAlignment, "", frame, true);
GUI.Style.Apply(header, "", this); GUI.Style.Apply(header, "", this);
if (!string.IsNullOrWhiteSpace(text)) if (!string.IsNullOrWhiteSpace(text))
{ {
var textBlock = new GUITextBlock(new Rectangle(0, 30, 0, height - 70), text, var textBlock = new GUITextBlock(new Rectangle(0, string.IsNullOrWhiteSpace(headerText) ? 0 : headerHeight, 0, height - 70), text,
null, null, textAlignment, "", frame, true); null, null, textAlignment, "", frame, true);
GUI.Style.Apply(textBlock, "", this); GUI.Style.Apply(textBlock, "", this);
} }
@@ -1,12 +0,0 @@
namespace Barotrauma
{
partial class TraitorManager
{
public static void CreateStartPopUp(string targetName)
{
new GUIMessageBox("You are the Traitor!",
"Your secret task is to assassinate " + targetName + "! Discretion is an utmost concern; sinking the submarine and killing the entire crew "
+ "will arouse suspicion amongst the Fleet. If possible, make the death look like an accident.", 400, 350);
}
}
}
@@ -49,7 +49,7 @@ namespace Barotrauma
frame.Padding = new Vector4(20.0f, 20.0f, 20.0f, 20.0f); frame.Padding = new Vector4(20.0f, 20.0f, 20.0f, 20.0f);
frame.UserData = item; frame.UserData = item;
new GUITextBlock(new Rectangle(0, 0, 200, 20), "Attempting to fix " + item.Name, "", frame); new GUITextBlock(new Rectangle(0, 0, 200, 20), TextManager.Get("FixHeader").Replace("[itemname]", item.Name), "", frame);
y = y + 40; y = y + 40;
foreach (FixRequirement requirement in item.FixRequirements) foreach (FixRequirement requirement in item.FixRequirements)
@@ -60,7 +60,7 @@ namespace Barotrauma
reqFrame.UserData = requirement; reqFrame.UserData = requirement;
var fixButton = new GUIButton(new Rectangle(0, 0, 50, 20), "Fix", "", reqFrame); var fixButton = new GUIButton(new Rectangle(0, 0, 50, 20), TextManager.Get("Fix"), "", reqFrame);
fixButton.OnClicked = FixButtonPressed; fixButton.OnClicked = FixButtonPressed;
fixButton.UserData = requirement; fixButton.UserData = requirement;
@@ -757,11 +757,6 @@ namespace Barotrauma.Networking
if (respawnAllowed) respawnManager = new RespawnManager(this, GameMain.NetLobbyScreen.UsingShuttle ? GameMain.NetLobbyScreen.SelectedShuttle : null); if (respawnAllowed) respawnManager = new RespawnManager(this, GameMain.NetLobbyScreen.UsingShuttle ? GameMain.NetLobbyScreen.SelectedShuttle : null);
if (isTraitor)
{
TraitorManager.CreateStartPopUp(traitorTargetName);
}
gameStarted = true; gameStarted = true;
GameMain.GameScreen.Select(); GameMain.GameScreen.Select();
+18 -1
View File
@@ -154,7 +154,7 @@
<ServerSettingsButton>Settings</ServerSettingsButton> <ServerSettingsButton>Settings</ServerSettingsButton>
<SpectateButton>Spectate</SpectateButton> <SpectateButton>Spectate</SpectateButton>
<Gender>Gender</Gender> <Gender>Gender</Gender>
<JobPreferences>JobPreferences</JobPreferences> <JobPreferences>Job preferences</JobPreferences>
<PlayingAsSpectator>Playing as a spectator</PlayingAsSpectator> <PlayingAsSpectator>Playing as a spectator</PlayingAsSpectator>
<SubNotFound>Submarine not found in your submarine folder</SubNotFound> <SubNotFound>Submarine not found in your submarine folder</SubNotFound>
<SubDoesntMatch>Your version of the submarine doesn't match the servers version</SubDoesntMatch> <SubDoesntMatch>Your version of the submarine doesn't match the servers version</SubDoesntMatch>
@@ -233,6 +233,23 @@
<SpamFilterKicked>You have been kicked by the spam filter.</SpamFilterKicked> <SpamFilterKicked>You have been kicked by the spam filter.</SpamFilterKicked>
<SpamFilterBlocked>You have been blocked by the spam filter. Try again after 10 seconds.</SpamFilterBlocked> <SpamFilterBlocked>You have been blocked by the spam filter. Try again after 10 seconds.</SpamFilterBlocked>
<!-- Item fixing -->
<FixHeader>Attempting to fix [itemname]</FixHeader>
<FixButton>Fix</FixButton>
<!-- Traitors -->
<NewTraitor>New traitor</NewTraitor>
<TraitorStartMessage>You are the Traitor! Your secret task is to assassinate [targetname]! Discretion is an utmost concern; sinking the submarine and killing the entire crew will arouse suspicion amongst the Fleet. If possible, make the death look like an accident.</TraitorStartMessage>
<TraitorMoreAgentsMessage>It is possible that there are other agents on this submarine. You don't know their names, but you do have a method of communication. Use the code words to greet the agent and code response to respond. Disguise such words in a normal-looking phrase so the crew doesn't suspect anything.\n\nThe code words are: [codewords].\nThe code response is: [coderesponse].</TraitorMoreAgentsMessage>
<TraitorStartMessageServer>[traitorname] is the traitor and the target is [targetname].</TraitorStartMessageServer>
<TraitorEndMessageSuccess>[traitorname] was a traitor! [Gendernounpossessive] task was to assassinate [targetname]. The task was successful.</TraitorEndMessageSuccess>
<TraitorEndMessageSuccessTraitorDead>[traitorname] was a traitor! [Gendernounpossessive] task was to assassinate [targetname]. The task was successful, but the traitor did not make it out alive either.</TraitorEndMessageSuccessTraitorDead>
<TraitorEndMessageSuccessTraitorDetained>[traitorname] was a traitor! [Gendernounpossessive] task was to assassinate [targetname]. The task was successful, but the traitor was succesfully detained.</TraitorEndMessageSuccessTraitorDetained>
<TraitorEndMessageFailure>[traitorname] was a traitor! [Gendernounpossessive] task was to assassinate [targetname]. The task was unsuccessful.</TraitorEndMessageFailure>
<TraitorEndMessageFailureTraitorDead>[traitorname] was a traitor! [Gendernounpossessive] task was to assassinate [targetname], but [gendernoun] got [gendernounreflexive] killed before completing it.</TraitorEndMessageFailureTraitorDead>
<TraitorEndMessageFailureTraitorDetained>[traitorname] was a traitor! [Gendernounpossessive] task was to assassinate [targetname]. The task failed - [gendernoun] was successfully detained.</TraitorEndMessageFailureTraitorDetained>
<!-- Causes of death --> <!-- Causes of death -->
<CauseOfDeath.Damage>Succumbed to their injuries</CauseOfDeath.Damage> <CauseOfDeath.Damage>Succumbed to their injuries</CauseOfDeath.Damage>
<CauseOfDeath.Bloodloss>Bled out</CauseOfDeath.Bloodloss> <CauseOfDeath.Bloodloss>Bled out</CauseOfDeath.Bloodloss>
@@ -16,43 +16,39 @@ namespace Barotrauma
public void Greet(GameServer server, string codeWords, string codeResponse) public void Greet(GameServer server, string codeWords, string codeResponse)
{ {
//Greeting messages TODO: Move this to a function in Traitor class string greetingMessage = TextManager.Get("TraitorStartMessage").Replace("[targetname]", TargetCharacter.Name);
string greetingMessage = "You are the Traitor! Your secret task is to assassinate " + TargetCharacter.Name + "! Discretion is an utmost concern; sinking the submarine and killing the entire crew " string moreAgentsMessage = TextManager.Get("TraitorMoreAgentsMessage")
+ "will arouse suspicion amongst the Fleet. If possible, make the death look like an accident."; .Replace("[codewords]", codeWords)
string moreAgentsMessage = "It is possible that there are other agents on this submarine. You don't know their names, but you do have a method of communication. " .Replace("[coderesponse]", codeResponse);
+ "Use the code words to greet the agent and code response to respond. Disguise such words in a normal-looking phrase so the crew doesn't suspect anything.";
moreAgentsMessage += "\nThe code words are: " + codeWords + ".";
moreAgentsMessage += "\nThe code response is: " + codeResponse + ".\n";
if (server.Character != Character) if (server.Character != Character)
{ {
var chatMsg = ChatMessage.Create( var greetingChatMsg = ChatMessage.Create(null, greetingMessage, ChatMessageType.Server, null);
null, var moreAgentsChatMsg = ChatMessage.Create(null, moreAgentsMessage, ChatMessageType.Server, null);
greetingMessage + "\n" + moreAgentsMessage,
(ChatMessageType)ChatMessageType.Server,
null);
var msgBox = ChatMessage.Create( var greetingMsgBox = ChatMessage.Create(null, greetingMessage, ChatMessageType.MessageBox, null);
null, var moreAgentsMsgBox = ChatMessage.Create(null, moreAgentsMessage, ChatMessageType.MessageBox, null);
"There might be other agents. Use these to communicate with them." +
"\nThe code words are: " + codeWords + "." +
"\nThe code response is: " + codeResponse + ".",
(ChatMessageType)ChatMessageType.MessageBox,
null);
Client client = server.ConnectedClients.Find(c => c.Character == Character); Client client = server.ConnectedClients.Find(c => c.Character == Character);
GameMain.Server.SendChatMessage(chatMsg, client); GameMain.Server.SendChatMessage(greetingChatMsg, client);
GameMain.Server.SendChatMessage(msgBox, client); GameMain.Server.SendChatMessage(moreAgentsChatMsg, client);
GameMain.Server.SendChatMessage(greetingMsgBox, client);
GameMain.Server.SendChatMessage(moreAgentsMsgBox, client);
} }
#if CLIENT #if CLIENT
if (server.Character == null) if (server.Character == null)
{ {
new GUIMessageBox("New traitor", Character.Name + " is the traitor and the target is " + TargetCharacter.Name+"."); new GUIMessageBox(
TextManager.Get("NewTraitor"),
TextManager.Get("TraitorStartMessageServer").Replace("[targetname]", TargetCharacter.Name).Replace("[traitorname]", Character.Name));
} }
else if (server.Character == Character) else if (server.Character == Character)
{ {
TraitorManager.CreateStartPopUp(TargetCharacter.Name); new GUIMessageBox("", greetingMessage);
new GUIMessageBox("", moreAgentsMessage);
GameMain.NetworkMember.AddChatMessage(greetingMessage, ChatMessageType.Server);
GameMain.NetworkMember.AddChatMessage(moreAgentsMessage, ChatMessageType.Server); GameMain.NetworkMember.AddChatMessage(moreAgentsMessage, ChatMessageType.Server);
return; return;
} }
@@ -151,72 +147,43 @@ namespace Barotrauma
{ {
Character traitorCharacter = traitor.Character; Character traitorCharacter = traitor.Character;
Character targetCharacter = traitor.TargetCharacter; Character targetCharacter = traitor.TargetCharacter;
endMessage += traitorCharacter.Name + " was a traitor! "; string messageTag;
endMessage += (traitorCharacter.Info.Gender == Gender.Male) ? "His" : "Her";
endMessage += " task was to assassinate " + targetCharacter.Name;
if (targetCharacter.IsDead) //Partial or complete mission success if (targetCharacter.IsDead) //Partial or complete mission success
{ {
endMessage += ". The task was successful";
if (traitorCharacter.IsDead) if (traitorCharacter.IsDead)
{ {
endMessage += ", but luckily the bastard didn't make it out alive either."; messageTag = "TraitorEndMessageSuccessTraitorDead";
} }
else if (traitorCharacter.LockHands) else if (traitorCharacter.LockHands)
{ {
endMessage += ", but "; messageTag = "TraitorEndMessageSuccessTraitorDetained";
endMessage += (traitorCharacter.Info.Gender == Gender.Male) ? "he" : "she";
endMessage += " was successfuly detained.";
} }
else else
endMessage += "."; messageTag = "TraitorEndMessageSuccess";
} }
else //Partial or complete failure else //Partial or complete failure
{ {
if (traitorCharacter.IsDead) if (traitorCharacter.IsDead)
{ {
endMessage += ", but "; messageTag = "TraitorEndMessageFailureTraitorDead";
endMessage += (traitorCharacter.Info.Gender == Gender.Male) ? "he" : "she"; }
endMessage += " got " + ((traitorCharacter.Info.Gender == Gender.Male) ? "himself" : "herself"); else if (traitorCharacter.LockHands)
endMessage += " killed before completing it."; {
messageTag = "TraitorEndMessageFailureTraitorDetained";
} }
else else
{ {
endMessage += ". The task was unsuccessful"; messageTag = "TraitorEndMessageFailure";
if (traitorCharacter.LockHands)
{
endMessage += " - ";
endMessage += (traitorCharacter.Info.Gender == Gender.Male) ? "he" : "she";
endMessage += " was successfuly detained";
}
if (Submarine.MainSub.AtEndPosition)
{
endMessage += (traitorCharacter.LockHands ? " and " : " - ");
endMessage += "the submarine has reached its destination";
}
endMessage += ".";
} }
} }
endMessage += "\n";
endMessage += (TextManager.ReplaceGenderNouns(TextManager.Get(messageTag), traitorCharacter.Info.Gender) + "\n")
.Replace("[traitorname]", traitorCharacter.Name)
.Replace("[targetname]", targetCharacter.Name);
} }
return endMessage; return endMessage;
} }
//public void CharacterLeft(Character character)
//{
// if (character != traitorCharacter && character != targetCharacter) return;
// if (character == traitorCharacter)
// {
// string endMessage = "The traitor has disconnected from the server.";
// End(endMessage);
// }
// else if (character == targetCharacter)
// {
// string endMessage = "The traitor's target has disconnected from the server.";
// End(endMessage);
// }
//}
} }
} }
@@ -8,7 +8,7 @@ namespace Barotrauma
{ {
static class TextManager static class TextManager
{ {
private static Dictionary<string, List<string>> infoTexts; private static Dictionary<string, List<string>> texts;
static TextManager() static TextManager()
{ {
@@ -17,7 +17,7 @@ namespace Barotrauma
private static void Load(string file) private static void Load(string file)
{ {
infoTexts = new Dictionary<string, List<string>>(); texts = new Dictionary<string, List<string>>();
XDocument doc = XMLExtensions.TryLoadXml(file); XDocument doc = XMLExtensions.TryLoadXml(file);
if (doc == null || doc.Root == null) return; if (doc == null || doc.Root == null) return;
@@ -26,26 +26,26 @@ namespace Barotrauma
{ {
string infoName = subElement.Name.ToString().ToLowerInvariant(); string infoName = subElement.Name.ToString().ToLowerInvariant();
List<string> infoList = null; List<string> infoList = null;
if (!infoTexts.TryGetValue(infoName, out infoList)) if (!texts.TryGetValue(infoName, out infoList))
{ {
infoList = new List<string>(); infoList = new List<string>();
infoTexts.Add(infoName, infoList); texts.Add(infoName, infoList);
} }
infoList.Add(subElement.ElementInnerText()); infoList.Add(subElement.ElementInnerText());
} }
} }
public static string Get(string infoName) public static string Get(string textTag)
{ {
List<string> infoList = null; List<string> textList = null;
if (!infoTexts.TryGetValue(infoName.ToLowerInvariant(), out infoList) || !infoList.Any()) if (!texts.TryGetValue(textTag.ToLowerInvariant(), out textList) || !textList.Any())
{ {
DebugConsole.ThrowError("Info text \"" + infoName + "\" not found"); DebugConsole.ThrowError("Text \"" + textTag + "\" not found");
return infoName; return textTag;
} }
string text = infoList[Rand.Int(infoList.Count)]; string text = textList[Rand.Int(textList.Count)].Replace(@"\n", "\n");
//todo: get rid of these and only do where needed? //todo: get rid of these and only do where needed?
#if CLIENT #if CLIENT
@@ -56,5 +56,27 @@ namespace Barotrauma
#endif #endif
return text; return text;
} }
public static string ReplaceGenderNouns(string text, Gender gender)
{
if (gender == Gender.Male)
{
return text.Replace("[gendernoun]", "he")
.Replace("[gendernounpossessive]", "his")
.Replace("[gendernounreflexive]", "himself")
.Replace("[Gendernoun]", "He")
.Replace("[Gendernounpossessive]", "His")
.Replace("[Gendernounreflexive]", "Himself");
}
else
{
return text.Replace("[gendernoun]", "she")
.Replace("[gendernounpossessive]", "her")
.Replace("[gendernounreflexive]", "herself")
.Replace("[Gendernoun]", "She")
.Replace("[Gendernounpossessive]", "Her")
.Replace("[Gendernounreflexive]", "Herself");
}
}
} }
} }