Round summary screen, GUIMessageBoxes disable other UI elements, renamed quests as missions

This commit is contained in:
Regalis11
2015-12-23 22:18:02 +02:00
parent c7e7b3909f
commit b2d5704f7e
22 changed files with 357 additions and 153 deletions

View File

@@ -22,7 +22,7 @@ namespace Barotrauma
private string endMessage;
public virtual Quest Quest
public virtual Mission Mission
{
get { return null; }
}

View File

@@ -48,7 +48,7 @@ namespace Barotrauma
+ "The rest of the crew will win if they reach the end of the level or kill the traitor "
+ "before the objective is completed.";
mode = new GameModePreset("Quest", typeof(QuestMode), false);
mode = new GameModePreset("Mission", typeof(MissionMode), false);
mode.Description = "The crew must work together to complete a specific task, such as retrieving "
+ "an alien artifact or killing a creature that's terrorizing nearby outposts. The game ends "
+ "when the task is completed or everyone in the crew has died.";

View File

@@ -6,19 +6,19 @@ using System.Text;
namespace Barotrauma
{
class QuestMode : GameMode
class MissionMode : GameMode
{
Quest quest;
Mission mission;
public override Quest Quest
public override Mission Mission
{
get
{
return quest;
return mission;
}
}
public QuestMode(GameModePreset preset)
public MissionMode(GameModePreset preset)
: base(preset)
{
Location[] locations = new Location[2];
@@ -29,14 +29,14 @@ namespace Barotrauma
{
locations[i] = Location.CreateRandom(new Vector2((float)rand.NextDouble() * 10000.0f, (float)rand.NextDouble() * 10000.0f));
}
quest = Quest.LoadRandom(locations, rand);
mission = Mission.LoadRandom(locations, rand);
}
public override void Start()
{
base.Start();
new GUIMessageBox(quest.Name, quest.Description, 400, 400);
new GUIMessageBox(mission.Name, mission.Description, 400, 400);
//quest.Start(Level.Loaded);
}

View File

@@ -18,6 +18,8 @@ namespace Barotrauma
private GUIButton endShiftButton;
public readonly CargoManager CargoManager;
private ShiftSummary shiftSummary;
public Map Map;
@@ -26,11 +28,11 @@ namespace Barotrauma
private bool savedOnStart;
public override Quest Quest
public override Mission Mission
{
get
{
return Map.SelectedConnection.Quest;
return Map.SelectedConnection.Mission;
}
}
@@ -115,6 +117,8 @@ namespace Barotrauma
endTimer = 5.0f;
CrewManager.StartShift();
shiftSummary = new ShiftSummary(GameMain.GameSession);
}
public bool TryHireCharacter(HireManager hireManager, CharacterInfo characterInfo)
@@ -192,41 +196,31 @@ namespace Barotrauma
//if (endMessage != "" || this.endMessage == null) this.endMessage = endMessage;
GUIFrame summaryFrame = shiftSummary.CreateSummaryFrame();
GUIMessageBox.MessageBoxes.Enqueue(summaryFrame);
var okButton = new GUIButton(new Rectangle(0,0,100,30), "Ok", Alignment.BottomRight, GUI.Style, summaryFrame.children[0]);
okButton.OnClicked = (GUIButton button, object obj) => { GUIMessageBox.MessageBoxes.Dequeue(); return true; };
StringBuilder sb = new StringBuilder();
List<Character> casualties = CrewManager.characters.FindAll(c => c.IsDead);
if (casualties.Count == CrewManager.characters.Count)
bool success = CrewManager.characters.Any(c => !c.IsDead);
if (success)
{
sb.Append("Your entire crew has died!");
var msgBox = new GUIMessageBox("", sb.ToString(), new string[] { "Load game", "Quit" });
msgBox.Buttons[0].OnClicked += GameMain.GameSession.LoadPrevious;
msgBox.Buttons[0].OnClicked += msgBox.Close;
msgBox.Buttons[1].OnClicked = GameMain.LobbyScreen.QuitToMainMenu;
msgBox.Buttons[1].OnClicked += msgBox.Close;
}
else
{
if (casualties.Any())
{
sb.Append("Casualties: \n");
foreach (Character c in casualties)
{
sb.Append(" - " + c.Info.Name + "\n");
}
}
else
{
sb.Append("No casualties!");
}
if (Submarine.Loaded.AtEndPosition)
{
Map.MoveToNextLocation();
}
SaveUtil.SaveGame(GameMain.GameSession.SaveFile);
}
else
{
var msgBox = new GUIMessageBox("Game over", "Your entire crew has died!", new string[] { "Load game", "Quit" });
msgBox.Buttons[0].OnClicked += GameMain.GameSession.LoadPrevious;
msgBox.Buttons[0].OnClicked += msgBox.Close;
msgBox.Buttons[1].OnClicked = GameMain.LobbyScreen.QuitToMainMenu;
msgBox.Buttons[1].OnClicked += msgBox.Close;
}
CrewManager.EndShift();

View File

@@ -1,11 +1,6 @@
using System;
using System.IO;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using System.Text;
using System.Collections.Generic;
using System.Xml.Linq;
namespace Barotrauma
@@ -24,11 +19,11 @@ namespace Barotrauma
public CrewManager CrewManager;
public Quest Quest
public Mission Mission
{
get
{
if (gameMode != null) return gameMode.Quest;
if (gameMode != null) return gameMode.Mission;
return null;
}
}
@@ -71,7 +66,7 @@ namespace Barotrauma
guiRoot = new GUIFrame(new Rectangle(0,0,GameMain.GraphicsWidth,GameMain.GraphicsWidth), Color.Transparent);
if (gameModePreset!=null) this.gameMode = gameModePreset.Instantiate();
if (gameModePreset!=null) gameMode = gameModePreset.Instantiate();
this.submarine = submarine;
}
@@ -122,7 +117,7 @@ namespace Barotrauma
GameMain.GameScreen.BackgroundCreatureManager.SpawnSprites(80);
}
if (Quest!=null) Quest.Start(Level.Loaded);
if (Mission!=null) Mission.Start(Level.Loaded);
if (gameMode!=null) gameMode.Start();
@@ -131,7 +126,7 @@ namespace Barotrauma
public void EndShift(string endMessage)
{
if (Quest != null) Quest.End();
if (Mission != null) Mission.End();
if (GameMain.Server!=null)
{
@@ -172,7 +167,7 @@ namespace Barotrauma
guiRoot.Update(deltaTime);
if (gameMode != null) gameMode.Update(deltaTime);
if (Quest != null) Quest.Update(deltaTime);
if (Mission != null) Mission.Update(deltaTime);
}
public void Draw(SpriteBatch spriteBatch)
@@ -185,7 +180,7 @@ namespace Barotrauma
public void Save(string filePath)
{
XDocument doc = new XDocument(
new XElement((XName)"Gamesession"));
new XElement("Gamesession"));
var now = DateTime.Now;
doc.Root.Add(new XAttribute("savetime", now.Hour + ":" + now.Minute + ", " + now.ToShortDateString()));

View File

@@ -0,0 +1,69 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml.Linq;
namespace Barotrauma
{
static class InfoTextManager
{
private static Dictionary<string, List<string>> infoTexts;
static InfoTextManager()
{
LoadInfoTexts(Path.Combine("Content", "InfoTexts.xml"));
}
private static void LoadInfoTexts(string file)
{
infoTexts = new Dictionary<string, List<string>>();
XDocument doc = ToolBox.TryLoadXml(file);
if (doc == null) return;
foreach (XElement subElement in doc.Root.Elements())
{
string infoName = subElement.Name.ToString().ToLower();
List<string> infoList = null;
if (!infoTexts.TryGetValue(infoName, out infoList))
{
infoList = new List<string>();
infoTexts.Add(infoName, infoList);
}
infoList.Add(subElement.ElementInnerText());
}
}
public static string GetInfoText(string infoName)
{
List<string> infoList = null;
if (!infoTexts.TryGetValue(infoName.ToLower(), out infoList) || !infoList.Any())
{
#if DEBUG
return "Info text ''" + infoName + "'' not found";
#else
return "";
#endif
}
string text = infoList[Rand.Int(infoList.Count)];
if (Submarine.Loaded!=null) text = text.Replace("[sub]", Submarine.Loaded.Name);
if (GameMain.GameSession != null && GameMain.GameSession.Map != null)
{
if (GameMain.GameSession.Map.CurrentLocation!=null)
text = text.Replace("[location1]", GameMain.GameSession.Map.CurrentLocation.Name);
if (GameMain.GameSession.Map.SelectedLocation!= null)
text = text.Replace("[location2]", GameMain.GameSession.Map.SelectedLocation.Name);
}
return text;
}
}
}

View File

@@ -0,0 +1,129 @@
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml.Linq;
namespace Barotrauma
{
class ShiftSummary
{
class Casualty
{
public readonly CharacterInfo character;
public readonly CauseOfDeath causeOfDeath;
public readonly string description;
public Casualty(CharacterInfo characterInfo, CauseOfDeath causeOfDeath, string description)
{
this.character = characterInfo;
this.causeOfDeath = causeOfDeath;
this.description = description;
}
}
private Location startLocation, endLocation;
private GameSession gameSession;
private List<Casualty> casualties;
private Mission selectedMission;
public ShiftSummary(GameSession gameSession)
{
this.gameSession = gameSession;
startLocation = gameSession.Map.CurrentLocation;
endLocation = gameSession.Map.SelectedLocation;
casualties = new List<Casualty>();
foreach (Character character in gameSession.CrewManager.characters)
{
character.OnDeath = AddCasualty;
}
selectedMission = gameSession.Mission;
}
public void AddCasualty(Character character, CauseOfDeath causeOfDeath)
{
casualties.Add(new Casualty(character.Info, causeOfDeath, ""));
}
public GUIFrame CreateSummaryFrame()
{
bool gameOver = !gameSession.CrewManager.characters.Any(c => !c.IsDead);
bool progress = Submarine.Loaded.AtEndPosition;
GUIFrame frame = new GUIFrame(new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight), Color.Black * 0.8f);
int width = 700, height = 400;
GUIFrame innerFrame = new GUIFrame(new Rectangle(0,0,width,height), null, Alignment.Center, GUI.Style, frame);
int y = 0;
string summaryText = InfoTextManager.GetInfoText(gameOver ? "gameover" :
(progress ? "progress" : "return"));
var infoText = new GUITextBlock(new Rectangle(0,y,0,50), summaryText, GUI.Style, innerFrame, true);
y += infoText.Rect.Height;
new GUITextBlock(new Rectangle(0,y,0,20), "Crew status:", GUI.Style, innerFrame, GUI.LargeFont);
y += 30;
int x = 0;
foreach (Character character in gameSession.CrewManager.characters)
{
var characterFrame = new GUIFrame(new Rectangle(x,y,170,70), character.IsDead ? Color.DarkRed*0.7f : Color.Transparent, GUI.Style, innerFrame);
characterFrame.Padding = new Vector4(5.0f,5.0f,5.0f,5.0f);
character.Info.CreateCharacterFrame(characterFrame,
character.Info.Job!=null ? (character.Info.Name + '\n'+"("+character.Info.Job.Name+")") : character.Info.Name, null);
string statusText;
var casualty = casualties.Find(c => c.character == character.Info);
if (casualty != null)
{
statusText = InfoTextManager.GetInfoText("CauseOfDeath." + casualty.causeOfDeath.ToString());
}
else
{
statusText = (character.Health / character.MaxHealth > 0.8f) ? "OK" : "Injured";
}
new GUITextBlock(new Rectangle(0,0,0,20), statusText,
GUI.Style, Alignment.BottomLeft, Alignment.TopCenter, characterFrame, true, GUI.SmallFont).Color = Color.Black*0.7f;
x += characterFrame.Rect.Width + 10;
}
y += 80;
if (GameMain.GameSession.Mission != null)
{
new GUITextBlock(new Rectangle(0, y, 0, 20), "Mission: "+GameMain.GameSession.Mission.Name, GUI.Style, innerFrame, GUI.LargeFont);
y += 30;
new GUITextBlock(new Rectangle(0,y,0,30),
(GameMain.GameSession.Mission.Completed) ? GameMain.GameSession.Mission.SuccessMessage : GameMain.GameSession.Mission.FailureMessage,
GUI.Style, innerFrame);
if (GameMain.GameSession.Mission.Completed)
{
new GUITextBlock(new Rectangle(0, y+40, 0, 30), "Reward: "+GameMain.GameSession.Mission.Reward, GUI.Style, innerFrame);
}
}
return frame;
}
}
}