diff --git a/Subsurface/Characters/Jobs/JobPrefab.cs b/Subsurface/Characters/Jobs/JobPrefab.cs index dea51ca85..673a4627a 100644 --- a/Subsurface/Characters/Jobs/JobPrefab.cs +++ b/Subsurface/Characters/Jobs/JobPrefab.cs @@ -81,6 +81,11 @@ namespace Subsurface } } + public static JobPrefab Random() + { + return List[Rand.Int(List.Count)]; + } + private void LoadSkills(XElement element) { foreach (XElement subElement in element.Elements()) diff --git a/Subsurface/Content/Map/locationTypes.xml b/Subsurface/Content/Map/locationTypes.xml index 777e1cffe..540b41de8 100644 --- a/Subsurface/Content/Map/locationTypes.xml +++ b/Subsurface/Content/Map/locationTypes.xml @@ -9,7 +9,8 @@ + commonness="3" + hireablecharacters="true"> + commonness="1" + hireablecharacters="true"> + commonness="1" + hireablecharacters="true"> Load() { - GUI.Font = Content.Load("SpriteFont1"); - GUI.SmallFont = Content.Load("SmallFont"); + GUI.Font = ToolBox.TryLoadFont("SpriteFont1", Content); + GUI.SmallFont = ToolBox.TryLoadFont("SmallFont", Content); + + sw = new Stopwatch(); LightManager = new Lights.LightManager(GraphicsDevice); @@ -246,7 +248,7 @@ namespace Subsurface double deltaTime = gameTime.ElapsedGameTime.TotalSeconds; PlayerInput.Update(deltaTime); - if (loadState>=100.0f && !titleScreenOpen) + if (loadState >= 100.0f && !titleScreenOpen) { //if (PlayerInput.KeyDown(Keys.Escape)) Quit(); @@ -289,14 +291,21 @@ namespace Subsurface titleScreenOpen = false; } } - else if (loadState>=100.0f) + else if (loadState >= 100.0f) { Screen.Selected.Draw(deltaTime, GraphicsDevice, spriteBatch); } //renderTimeElapsed = (int)renderTimer.Elapsed.Ticks; //renderTimer.Stop(); + if (sw.Elapsed.TotalSeconds < Physics.step) + { + System.Threading.Thread.Sleep((int)((Physics.step - sw.Elapsed.TotalSeconds)*1000.0)); + } + sw.Restart(); } + Stopwatch sw; + protected override void OnExiting(object sender, EventArgs args) { if (NetworkMember != null) NetworkMember.Disconnect(); diff --git a/Subsurface/GameSession/HireManager.cs b/Subsurface/GameSession/HireManager.cs index 5877c0964..1e5b52f36 100644 --- a/Subsurface/GameSession/HireManager.cs +++ b/Subsurface/GameSession/HireManager.cs @@ -15,6 +15,7 @@ namespace Subsurface public void GenerateCharacters(string file, int amount) { + for (int i = 0 ; i gm.Name == "Single Player")) + : this(GameModePreset.list.Find(gm => gm.Name == "Single Player"), false) { //day = ToolBox.GetAttributeInt(element,"day",1); @@ -85,7 +90,7 @@ namespace Subsurface crewManager.StartShift(); } - public bool TryHireCharacter(CharacterInfo characterInfo) + public bool TryHireCharacter(HireManager hireManager, CharacterInfo characterInfo) { if (crewManager.Money < characterInfo.Salary) return false; diff --git a/Subsurface/Settings.cs b/Subsurface/GameSettings.cs similarity index 100% rename from Subsurface/Settings.cs rename to Subsurface/GameSettings.cs diff --git a/Subsurface/Map/Location.cs b/Subsurface/Map/Location.cs index 0eb31e44d..ccfc0ddda 100644 --- a/Subsurface/Map/Location.cs +++ b/Subsurface/Map/Location.cs @@ -9,13 +9,15 @@ namespace Subsurface class Location { - string name; + private string name; - Vector2 mapPosition; + private Vector2 mapPosition; - LocationType type; + private LocationType type; - public List connections; + private HireManager hireManager; + + public List Connections; public string Name { @@ -27,13 +29,32 @@ namespace Subsurface get { return mapPosition; } } + + public LocationType Type + { + get { return type; } + } + + public HireManager HireManager + { + get { return hireManager; } + } + public Location(Vector2 mapPosition) { - this.name = RandomName(LocationType.Random()); + this.type = LocationType.Random(); + + this.name = RandomName(type); this.mapPosition = mapPosition; - connections = new List(); + if (type.HasHireableCharacters) + { + hireManager = new HireManager(); + hireManager.GenerateCharacters(Character.HumanConfigFile, 10); + } + + Connections = new List(); } public static Location CreateRandom(Vector2 position) diff --git a/Subsurface/Map/LocationType.cs b/Subsurface/Map/LocationType.cs index 453e23dff..028dfa131 100644 --- a/Subsurface/Map/LocationType.cs +++ b/Subsurface/Map/LocationType.cs @@ -13,17 +13,23 @@ namespace Subsurface //sum of the commonness-values of each location type private static int totalWeight; - string name; + private string name; private int commonness; - List nameFormats; + private List nameFormats; + public bool HasHireableCharacters + { + get; + private set; + } + public string Name { get { return name; } } - + public List NameFormats { get { return nameFormats; } @@ -36,6 +42,8 @@ namespace Subsurface commonness = ToolBox.GetAttributeInt(element, "commonness", 1); totalWeight += commonness; + HasHireableCharacters = ToolBox.GetAttributeBool(element, "hireablecharacters", false); + nameFormats = new List(); foreach (XAttribute nameFormat in element.Element("nameformats").Attributes()) { diff --git a/Subsurface/Map/Map.cs b/Subsurface/Map/Map.cs index fb91ecd1f..67dd8b5ed 100644 --- a/Subsurface/Map/Map.cs +++ b/Subsurface/Map/Map.cs @@ -145,8 +145,8 @@ namespace Subsurface foreach (LocationConnection connection in connections) { - connection.Locations[0].connections.Add(connection); - connection.Locations[1].connections.Add(connection); + connection.Locations[0].Connections.Add(connection); + connection.Locations[1].Connections.Add(connection); } for (int i = connections.Count - 1; i >= 0; i--) @@ -181,7 +181,7 @@ namespace Subsurface currDifficulty += Rand.Range(difficultyIncrease.X, difficultyIncrease.Y, false); if (currDifficulty > Rand.Range(difficultyCutoff.X, difficultyCutoff.Y, false)) currDifficulty = 10.0f; - foreach (LocationConnection connection in start.connections) + foreach (LocationConnection connection in start.Connections) { if (!locations.Contains(connection)) continue; diff --git a/Subsurface/Screens/LobbyScreen.cs b/Subsurface/Screens/LobbyScreen.cs index 49e1438fe..a78d00011 100644 --- a/Subsurface/Screens/LobbyScreen.cs +++ b/Subsurface/Screens/LobbyScreen.cs @@ -9,7 +9,7 @@ namespace Subsurface { class LobbyScreen : Screen { - enum PanelTab { Crew = 0, Map = 1, Hire = 2 } + enum PanelTab { Crew = 0, Map = 1, CurrentLocation = 2 } GUIFrame leftPanel; GUIFrame[] rightPanel; @@ -52,8 +52,8 @@ namespace Subsurface button.UserData = PanelTab.Crew; button.OnClicked = SelectRightPanel; - button = new GUIButton(new Rectangle(0, 140, 100, 30), "Hire", null, Alignment.Left, GUI.style, leftPanel); - button.UserData = PanelTab.Hire; + button = new GUIButton(new Rectangle(0, 140, 100, 30), "Location", null, Alignment.Left, GUI.style, leftPanel); + button.UserData = PanelTab.CurrentLocation; button.OnClicked = SelectRightPanel; //--------------------------------------------------------------- @@ -87,11 +87,15 @@ namespace Subsurface //--------------------------------------- - rightPanel[(int)PanelTab.Hire] = new GUIFrame(panelRect, GUI.style); + rightPanel[(int)PanelTab.CurrentLocation] = new GUIFrame(panelRect, GUI.style); //rightPanel[(int)PanelTab.Hire].Padding = GUI.style.smallPadding; - hireList = new GUIListBox(new Rectangle(0, 30, 300, 0), GUI.style, Alignment.Left, rightPanel[(int)PanelTab.Hire]); - hireList.OnSelected = HireCharacter; + + //new GUITextBlock(new Rectangle(0, 0, 200, 25), "Location: ", Color.Transparent, Color.White, Alignment.Left, GUI.style, rightPanel[(int)PanelTab.CurrentLocation]); + + + //hireList = new GUIListBox(new Rectangle(0, 30, 300, 0), GUI.style, Alignment.Left, rightPanel[(int)PanelTab.CurrentLocation]); + //hireList.OnSelected = HireCharacter; } public override void Select() @@ -105,6 +109,45 @@ namespace Subsurface UpdateCharacterLists(); } + private void UpdateLocationTab(Location location) + { + rightPanel[(int)PanelTab.CurrentLocation] = new GUIFrame(rightPanel[(int)PanelTab.CurrentLocation].Rect, GUI.style); + rightPanel[(int)PanelTab.CurrentLocation].UserData = location; + //rightPanel[(int)PanelTab.Hire].Padding = GUI.style.smallPadding; + + new GUITextBlock(new Rectangle(0, 0, 200, 25), + "Location: "+location.Name, GUI.style, rightPanel[(int)PanelTab.CurrentLocation]); + new GUITextBlock(new Rectangle(0, 0, 200, 25), + "("+location.Type+")", GUI.style, rightPanel[(int)PanelTab.CurrentLocation]); + + if (location.HireManager != null) + { + hireList = new GUIListBox(new Rectangle(0, 30, 300, 0), GUI.style, Alignment.Left, rightPanel[(int)PanelTab.CurrentLocation]); + hireList.OnSelected = HireCharacter; + + hireList.ClearChildren(); + foreach (CharacterInfo c in location.HireManager.availableCharacters) + { + //GUIFrame frame = new GUIFrame( + // new Rectangle(0, 0, 0, 25), Color.Transparent, null, hireList); + //frame.UserData = c; + //frame.Padding = new Vector4(10.0f, 0.0f, 10.0f, 0.0f); + + GUITextBlock textBlock = new GUITextBlock( + new Rectangle(0, 0, 0, 25), + c.Name + " (" + c.Job.Name + ")", GUI.style, hireList); + textBlock.UserData = c; + + textBlock = new GUITextBlock( + new Rectangle(0, 0, 0, 25), + c.Salary.ToString(), + null, null, + Alignment.TopRight, GUI.style, textBlock); + } + } + } + + public override void Deselect() { base.Deselect(); @@ -192,25 +235,6 @@ namespace Subsurface textBlock.UserData = c; } - hireList.ClearChildren(); - foreach (CharacterInfo c in gameMode.hireManager.availableCharacters) - { - //GUIFrame frame = new GUIFrame( - // new Rectangle(0, 0, 0, 25), Color.Transparent, null, hireList); - //frame.UserData = c; - //frame.Padding = new Vector4(10.0f, 0.0f, 10.0f, 0.0f); - - GUITextBlock textBlock = new GUITextBlock( - new Rectangle(0, 0, 0, 25), - c.Name + " (" + c.Job.Name + ")", GUI.style, hireList); - textBlock.UserData = c; - - textBlock = new GUITextBlock( - new Rectangle(0, 0, 0, 25), - c.Salary.ToString(), - null, null, - Alignment.TopRight, GUI.style, textBlock); - } } public override void Update(double deltaTime) @@ -225,8 +249,7 @@ namespace Subsurface public override void Draw(double deltaTime, GraphicsDevice graphics, SpriteBatch spriteBatch) { - if (characterList.CountChildren != gameMode.crewManager.characterInfos.Count - || hireList.CountChildren != gameMode.hireManager.availableCharacters.Count) + if (characterList.CountChildren != gameMode.crewManager.characterInfos.Count) { UpdateCharacterLists(); } @@ -247,7 +270,12 @@ namespace Subsurface rightPanel[selectedRightPanel].Rect.Right - 20 - 400, rightPanel[selectedRightPanel].Rect.Y + 20, 400, 400)); - } + } + + if (rightPanel[(int)selectedRightPanel].UserData as Location != Game1.GameSession.Map.CurrentLocation) + { + UpdateLocationTab(Game1.GameSession.Map.CurrentLocation); + } GUI.Draw((float)deltaTime, spriteBatch, null); @@ -350,7 +378,7 @@ namespace Subsurface CharacterInfo characterInfo = selection as CharacterInfo; if (characterInfo == null) return false; - gameMode.TryHireCharacter(characterInfo); + gameMode.TryHireCharacter(Game1.GameSession.Map.CurrentLocation.HireManager, characterInfo); return false; } diff --git a/Subsurface/Subsurface.csproj b/Subsurface/Subsurface.csproj index baa86edad..ae6f44c0b 100644 --- a/Subsurface/Subsurface.csproj +++ b/Subsurface/Subsurface.csproj @@ -194,7 +194,7 @@ - + diff --git a/Subsurface/Utils/ToolBox.cs b/Subsurface/Utils/ToolBox.cs index 24f412f47..f64c02bdd 100644 --- a/Subsurface/Utils/ToolBox.cs +++ b/Subsurface/Utils/ToolBox.cs @@ -29,6 +29,21 @@ namespace Subsurface return doc; } + public static SpriteFont TryLoadFont(string file, Microsoft.Xna.Framework.Content.ContentManager contentManager) + { + SpriteFont font = null; + try + { + font = contentManager.Load(file); + } + catch + { + DebugConsole.ThrowError("Loading font ''"+file+"'' failed"); + } + + return font; + } + public static object GetAttributeObject(XElement element, string name) { if (element.Attribute(name) == null) return null; diff --git a/Subsurface_Solution.v12.suo b/Subsurface_Solution.v12.suo index 49ca8b7ad..9977e1e32 100644 Binary files a/Subsurface_Solution.v12.suo and b/Subsurface_Solution.v12.suo differ