Further separation of client-specific code

Still not done here, just gonna push a commit now so I can pull this from elsewhere.
This commit is contained in:
juanjp600
2017-06-16 16:02:07 -03:00
parent e4a878113f
commit 7168a534ed
64 changed files with 3733 additions and 2954 deletions
@@ -5,7 +5,7 @@ using System.Xml.Linq;
namespace Barotrauma
{
class GameSession
partial class GameSession
{
public enum InfoFrameTab { Crew, Mission, ManagePlayers };
@@ -16,17 +16,13 @@ namespace Barotrauma
//two locations used as the start and end in the MP mode
private Location[] dummyLocations;
private InfoFrameTab selectedTab;
private GUIButton infoButton;
private GUIFrame infoFrame;
private string saveFile;
private Submarine submarine;
#if CLIENT
public CrewManager CrewManager;
private ShiftSummary shiftSummary;
#endif
private Mission currentMission;
@@ -44,16 +40,7 @@ namespace Barotrauma
{
get { return level; }
}
public Map Map
{
get
{
SinglePlayerMode mode = (gameMode as SinglePlayerMode);
return (mode == null) ? null : mode.Map;
}
}
public Location StartLocation
{
get
@@ -94,26 +81,23 @@ namespace Barotrauma
{
get { return saveFile; }
}
public ShiftSummary ShiftSummary
{
get { return shiftSummary; }
}
public GameSession(Submarine submarine, string saveFile, GameModePreset gameModePreset = null, string missionType="")
{
Submarine.MainSub = submarine;
GameMain.GameSession = this;
CrewManager = new CrewManager();
TaskManager = new TaskManager(this);
this.saveFile = saveFile;
#if CLIENT
CrewManager = new CrewManager();
infoButton = new GUIButton(new Rectangle(10, 10, 100, 20), "Info", "", null);
infoButton.OnClicked = ToggleInfoFrame;
#endif
if (gameModePreset != null) gameMode = gameModePreset.Instantiate(missionType);
this.submarine = submarine;
@@ -125,17 +109,19 @@ namespace Barotrauma
Submarine.MainSub = submarine;
GameMain.GameSession = this;
CrewManager = new CrewManager();
selectedSub.Name = ToolBox.GetAttributeString(doc.Root, "submarine", selectedSub.Name);
#if CLIENT
CrewManager = new CrewManager();
foreach (XElement subElement in doc.Root.Elements())
{
if (subElement.Name.ToString().ToLowerInvariant() != "gamemode") continue;
gameMode = new SinglePlayerMode(subElement);
}
#endif
}
private void CreateDummyLocations()
@@ -168,7 +154,9 @@ namespace Barotrauma
public void StartShift(Level level, bool reloadSub = true, bool loadSecondSub = false)
{
#if CLIENT
GameMain.LightManager.LosEnabled = GameMain.NetworkMember == null || GameMain.NetworkMember.CharacterInfo != null;
#endif
this.level = level;
@@ -198,8 +186,10 @@ namespace Barotrauma
level.Generate();
submarine.SetPosition(submarine.FindSpawnPos(level.StartPosition - new Vector2(0.0f, 2000.0f)));
#if CLIENT
GameMain.GameScreen.BackgroundCreatureManager.SpawnSprites(80);
#endif
}
if (gameMode.Mission != null)
@@ -207,8 +197,6 @@ namespace Barotrauma
currentMission = gameMode.Mission;
}
shiftSummary = new ShiftSummary(this);
if (gameMode!=null) gameMode.Start();
if (gameMode.Mission != null) Mission.Start(Level.Loaded);
@@ -219,8 +207,12 @@ namespace Barotrauma
Entity.Spawner = new EntitySpawner();
#if CLIENT
shiftSummary = new ShiftSummary(this);
GameMain.GameScreen.ColorFade(Color.Black, Color.TransparentBlack, 5.0f);
SoundPlayer.SwitchMusic();
#endif
}
public void EndShift(string endMessage)
@@ -238,6 +230,7 @@ namespace Barotrauma
GameMain.LobbyScreen.Select();
}
#if CLIENT
if (shiftSummary != null)
{
GUIFrame summaryFrame = shiftSummary.CreateSummaryFrame(endMessage);
@@ -245,6 +238,7 @@ namespace Barotrauma
var okButton = new GUIButton(new Rectangle(0, 0, 100, 30), "Ok", Alignment.BottomRight, "", summaryFrame.children[0]);
okButton.OnClicked = (GUIButton button, object obj) => { GUIMessageBox.MessageBoxes.Remove(summaryFrame); return true; };
}
#endif
TaskManager.EndShift();
@@ -253,182 +247,19 @@ namespace Barotrauma
StatusEffect.StopAll();
}
public void KillCharacter(Character character)
{
#if CLIENT
CrewManager.KillCharacter(character);
#endif
}
public void ReviveCharacter(Character character)
{
#if CLIENT
CrewManager.ReviveCharacter(character);
#endif
}
public bool LoadPrevious(GUIButton button, object obj)
{
Submarine.Unload();
SaveUtil.LoadGame(saveFile);
GameMain.LobbyScreen.Select();
return true;
}
private bool ToggleInfoFrame(GUIButton button, object obj)
{
if (infoFrame == null)
{
if (CrewManager != null && CrewManager.CrewCommander!= null && CrewManager.CrewCommander.IsOpen)
{
CrewManager.CrewCommander.ToggleGUIFrame();
}
CreateInfoFrame();
SelectInfoFrameTab(null, selectedTab);
}
else
{
infoFrame = null;
}
return true;
}
public void CreateInfoFrame()
{
int width = 600, height = 400;
infoFrame = new GUIFrame(
Rectangle.Empty, Color.Black * 0.8f, null);
var innerFrame = new GUIFrame(
new Rectangle(GameMain.GraphicsWidth / 2 - width / 2, GameMain.GraphicsHeight / 2 - height / 2, width, height), "", infoFrame);
innerFrame.Padding = new Vector4(10.0f, 10.0f, 10.0f, 10.0f);
var crewButton = new GUIButton(new Rectangle(0, -30, 100, 20), "Crew", "", innerFrame);
crewButton.UserData = InfoFrameTab.Crew;
crewButton.OnClicked = SelectInfoFrameTab;
var missionButton = new GUIButton(new Rectangle(100, -30, 100, 20), "Mission", "", innerFrame);
missionButton.UserData = InfoFrameTab.Mission;
missionButton.OnClicked = SelectInfoFrameTab;
if (GameMain.Server != null)
{
var manageButton = new GUIButton(new Rectangle(200, -30, 130, 20), "Manage players", "", innerFrame);
manageButton.UserData = InfoFrameTab.ManagePlayers;
manageButton.OnClicked = SelectInfoFrameTab;
}
var closeButton = new GUIButton(new Rectangle(0, 0, 80, 20), "Close", Alignment.BottomCenter, "", innerFrame);
closeButton.OnClicked = ToggleInfoFrame;
}
private bool SelectInfoFrameTab(GUIButton button, object userData)
{
selectedTab = (InfoFrameTab)userData;
CreateInfoFrame();
switch (selectedTab)
{
case InfoFrameTab.Crew:
CrewManager.CreateCrewFrame(CrewManager.characters, infoFrame.children[0] as GUIFrame);
break;
case InfoFrameTab.Mission:
CreateMissionInfo(infoFrame.children[0] as GUIFrame);
break;
case InfoFrameTab.ManagePlayers:
GameMain.Server.ManagePlayersFrame(infoFrame.children[0] as GUIFrame);
break;
}
return true;
}
private void CreateMissionInfo(GUIFrame infoFrame)
{
if (Mission == null)
{
new GUITextBlock(new Rectangle(0,0,0,50), "No mission", "", infoFrame, true);
return;
}
new GUITextBlock(new Rectangle(0, 0, 0, 40), Mission.Name, "", infoFrame, GUI.LargeFont);
new GUITextBlock(new Rectangle(0, 50, 0, 20), "Reward: "+Mission.Reward, "", infoFrame, true);
new GUITextBlock(new Rectangle(0, 70, 0, 50), Mission.Description, "", infoFrame, true);
}
public void AddToGUIUpdateList()
{
infoButton.AddToGUIUpdateList();
if (gameMode != null) gameMode.AddToGUIUpdateList();
if (infoFrame != null) infoFrame.AddToGUIUpdateList();
}
public void Update(float deltaTime)
{
TaskManager.Update(deltaTime);
if (GUI.DisableHUD) return;
//guiRoot.Update(deltaTime);
infoButton.Update(deltaTime);
if (gameMode != null) gameMode.Update(deltaTime);
if (Mission != null) Mission.Update(deltaTime);
if (infoFrame != null)
{
infoFrame.Update(deltaTime);
if (CrewManager != null && CrewManager.CrewCommander != null && CrewManager.CrewCommander.IsOpen)
{
infoFrame = null;
}
}
}
public void Draw(SpriteBatch spriteBatch)
{
if (GUI.DisableHUD) return;
infoButton.Draw(spriteBatch);
if (gameMode != null) gameMode.Draw(spriteBatch);
if (infoFrame != null) infoFrame.Draw(spriteBatch);
}
public void Save(string filePath)
{
XDocument doc = new XDocument(
new XElement("Gamesession"));
var now = DateTime.Now;
doc.Root.Add(new XAttribute("savetime", now.ToShortTimeString() + ", " + now.ToShortDateString()));
doc.Root.Add(new XAttribute("submarine", submarine==null ? "" : submarine.Name));
doc.Root.Add(new XAttribute("mapseed", Map.Seed));
((SinglePlayerMode)gameMode).Save(doc.Root);
try
{
doc.Save(filePath);
}
catch
{
DebugConsole.ThrowError("Saving gamesession to \"" + filePath + "\" failed!");
}
}
}
}