Moved campaign UI logic from LobbyScreen to a separate class

This commit is contained in:
Joonas Rikkonen
2017-08-29 19:32:14 +03:00
parent a75fd12020
commit dc3b9baa0d
5 changed files with 495 additions and 408 deletions

View File

@@ -196,6 +196,7 @@
<Compile Include="Source\PlayerInput.cs" />
<Compile Include="Source\Program.cs" />
<Compile Include="Source\Screens\BlurEffect.cs" />
<Compile Include="Source\Screens\CampaignUI.cs" />
<Compile Include="Source\Screens\EditCharacterScreen.cs" />
<Compile Include="Source\Screens\EditMapScreen.cs" />
<Compile Include="Source\Screens\GameScreen.cs" />

View File

@@ -13,6 +13,8 @@ namespace Barotrauma
private static Texture2D iceCraters;
private static Texture2D iceCrack;
public Action<Location, LocationConnection> OnLocationSelected;
public void Update(float deltaTime, Rectangle rect, float scale = 1.0f)
{
Vector2 rectCenter = new Vector2(rect.Center.X, rect.Center.Y);
@@ -46,7 +48,9 @@ namespace Barotrauma
{
selectedConnection = connection;
selectedLocation = highlightedLocation;
GameMain.LobbyScreen.SelectLocation(highlightedLocation, connection);
OnLocationSelected?.Invoke(selectedLocation, selectedConnection);
//GameMain.LobbyScreen.SelectLocation(highlightedLocation, connection);
}
}

View File

@@ -0,0 +1,431 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Globalization;
using System.Linq;
namespace Barotrauma
{
class CampaignUI
{
public enum Tab { Crew = 0, Map = 1, Store = 2 }
private GUIFrame[] tabs;
private GUIButton startButton;
private Tab selectedTab;
private GUIListBox characterList, hireList;
private GUIListBox selectedItemList;
private GUIListBox storeItemList;
private CampaignMode campaign;
private GUIFrame previewFrame;
private GUIButton buyButton;
private Level selectedLevel;
float mapZoom = 3.0f;
public Action StartRound;
public Action<Location, LocationConnection> OnLocationSelected;
public Level SelectedLevel
{
get { return selectedLevel; }
}
private string CostTextGetter()
{
return "Cost: " + selectedItemCost.ToString() + " credits";
}
private int selectedItemCost
{
get
{
int cost = 0;
foreach (GUIComponent child in selectedItemList.children)
{
MapEntityPrefab ep = child.UserData as MapEntityPrefab;
if (ep == null) continue;
cost += ep.Price;
}
return cost;
}
}
public CampaignUI(CampaignMode campaign, GUIFrame container)
{
this.campaign = campaign;
tabs = new GUIFrame[3];
tabs[(int)Tab.Crew] = new GUIFrame(Rectangle.Empty, null, container);
tabs[(int)Tab.Crew].Padding = Vector4.One * 10.0f;
//new GUITextBlock(new Rectangle(0, 0, 200, 25), "Crew:", Color.Transparent, Color.White, Alignment.Left, "", bottomPanel[(int)PanelTab.Crew]);
int crewColumnWidth = Math.Min(300, (container.Rect.Width - 40) / 2);
new GUITextBlock(new Rectangle(0, 0, 100, 20), "Crew:", "", tabs[(int)Tab.Crew], GUI.LargeFont);
characterList = new GUIListBox(new Rectangle(0, 40, crewColumnWidth, 0), "", tabs[(int)Tab.Crew]);
characterList.OnSelected = SelectCharacter;
hireList = new GUIListBox(new Rectangle(0, 40, 300, 0), "", Alignment.Right, tabs[(int)Tab.Crew]);
new GUITextBlock(new Rectangle(0, 0, 300, 20), "Hire:", "", Alignment.Right, Alignment.Left, tabs[(int)Tab.Crew], false, GUI.LargeFont);
hireList.OnSelected = SelectCharacter;
//---------------------------------------
tabs[(int)Tab.Map] = new GUIFrame(Rectangle.Empty, null, container);
tabs[(int)Tab.Map].Padding = Vector4.One * 10.0f;
startButton = new GUIButton(new Rectangle(0, 0, 100, 30), "Start",
Alignment.BottomRight, "", tabs[(int)Tab.Map]);
startButton.OnClicked = (GUIButton btn, object obj) => { StartRound?.Invoke(); return true; };
startButton.Enabled = false;
//---------------------------------------
tabs[(int)Tab.Store] = new GUIFrame(Rectangle.Empty, null, container);
tabs[(int)Tab.Store].Padding = Vector4.One * 10.0f;
int sellColumnWidth = (tabs[(int)Tab.Store].Rect.Width - 40) / 2 - 20;
selectedItemList = new GUIListBox(new Rectangle(0, 30, sellColumnWidth, tabs[(int)Tab.Store].Rect.Height - 80), Color.White * 0.7f, "", tabs[(int)Tab.Store]);
selectedItemList.OnSelected = DeselectItem;
var costText = new GUITextBlock(new Rectangle(0, 0, 100, 25), "Cost: ", "", Alignment.BottomLeft, Alignment.TopLeft, tabs[(int)Tab.Store]);
costText.TextGetter = CostTextGetter;
buyButton = new GUIButton(new Rectangle(selectedItemList.Rect.Width - 100, 0, 100, 25), "Buy", Alignment.Bottom, "", tabs[(int)Tab.Store]);
buyButton.OnClicked = BuyItems;
storeItemList = new GUIListBox(new Rectangle(0, 30, sellColumnWidth, tabs[(int)Tab.Store].Rect.Height - 80), Color.White * 0.7f, Alignment.TopRight, "", tabs[(int)Tab.Store]);
storeItemList.OnSelected = SelectItem;
int x = selectedItemList.Rect.Width + 40;
foreach (MapEntityCategory category in Enum.GetValues(typeof(MapEntityCategory)))
{
var items = MapEntityPrefab.list.FindAll(ep => ep.Price > 0.0f && ep.Category.HasFlag(category));
if (!items.Any()) continue;
var categoryButton = new GUIButton(new Rectangle(x, 0, 100, 20), category.ToString(), "", tabs[(int)Tab.Store]);
categoryButton.UserData = category;
categoryButton.OnClicked = SelectItemCategory;
if (category == MapEntityCategory.Equipment)
{
SelectItemCategory(categoryButton, category);
}
x += 110;
}
SelectTab(Tab.Crew);
GameMain.GameSession.Map.OnLocationSelected += SelectLocation;
}
private void UpdateLocationTab(Location location)
{
if (location.HireManager == null)
{
hireList.ClearChildren();
hireList.Enabled = false;
new GUITextBlock(new Rectangle(0, 0, 0, 0), "No-one available for hire", Color.Transparent, Color.LightGray, Alignment.Center, Alignment.Center, "", hireList);
return;
}
hireList.Enabled = true;
hireList.ClearChildren();
foreach (CharacterInfo c in location.HireManager.availableCharacters)
{
var frame = c.CreateCharacterFrame(hireList, c.Name + " (" + c.Job.Name + ")", c);
new GUITextBlock(
new Rectangle(0, 0, 0, 25),
c.Salary.ToString(),
null, null,
Alignment.TopRight, "", frame);
}
}
public void Update(float deltaTime)
{
mapZoom += PlayerInput.ScrollWheelSpeed / 1000.0f;
mapZoom = MathHelper.Clamp(mapZoom, 1.0f, 4.0f);
GameMain.GameSession.Map.Update((float)deltaTime, new Rectangle(
tabs[(int)selectedTab].Rect.X + 20,
tabs[(int)selectedTab].Rect.Y + 20,
tabs[(int)selectedTab].Rect.Width - 310,
tabs[(int)selectedTab].Rect.Height - 40), mapZoom);
}
public void Draw(SpriteBatch spriteBatch)
{
/*if (characterList.CountChildren != CrewManager.CharacterInfos.Count)
{
UpdateCharacterLists();
}
spriteBatch.Begin(SpriteSortMode.Immediate, null, null, null, GameMain.ScissorTestEnable);
*/
if (selectedTab == Tab.Map)
{
GameMain.GameSession.Map.Draw(spriteBatch, new Rectangle(
tabs[(int)selectedTab].Rect.X + 20,
tabs[(int)selectedTab].Rect.Y + 20,
tabs[(int)selectedTab].Rect.Width - 310,
tabs[(int)selectedTab].Rect.Height - 40), mapZoom);
}
/*if (topPanel.UserData as Location != GameMain.GameSession.Map.CurrentLocation)
{
UpdateLocationTab(GameMain.GameSession.Map.CurrentLocation);
}
spriteBatch.End();*/
}
public void UpdateCharacterLists()
{
characterList.ClearChildren();
foreach (CharacterInfo c in GameMain.GameSession.CrewManager.CharacterInfos)
{
c.CreateCharacterFrame(characterList, c.Name + " (" + c.Job.Name + ") ", c);
}
}
private void CreateItemFrame(MapEntityPrefab ep, GUIListBox listBox, int width)
{
GUIFrame frame = new GUIFrame(new Rectangle(0, 0, 0, 50), "ListBoxElement", listBox);
frame.UserData = ep;
frame.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f);
frame.ToolTip = ep.Description;
ScalableFont font = listBox.Rect.Width < 280 ? GUI.SmallFont : GUI.Font;
GUITextBlock textBlock = new GUITextBlock(
new Rectangle(50, 0, 0, 25),
ep.Name,
null, null,
Alignment.Left, Alignment.CenterX | Alignment.Left,
"", frame);
textBlock.Font = font;
textBlock.Padding = new Vector4(5.0f, 0.0f, 5.0f, 0.0f);
textBlock.ToolTip = ep.Description;
if (ep.sprite != null)
{
GUIImage img = new GUIImage(new Rectangle(0, 0, 40, 40), ep.sprite, Alignment.CenterLeft, frame);
img.Color = ep.SpriteColor;
img.Scale = Math.Min(Math.Min(40.0f / img.SourceRect.Width, 40.0f / img.SourceRect.Height), 1.0f);
}
textBlock = new GUITextBlock(
new Rectangle(width - 80, 0, 80, 25),
ep.Price.ToString(),
null, null, Alignment.TopLeft,
Alignment.TopLeft, "", frame);
textBlock.Font = font;
textBlock.ToolTip = ep.Description;
}
private bool SelectItem(GUIComponent component, object obj)
{
MapEntityPrefab prefab = obj as MapEntityPrefab;
if (prefab == null) return false;
CreateItemFrame(prefab, selectedItemList, selectedItemList.Rect.Width);
buyButton.Enabled = campaign.Money >= selectedItemCost;
return false;
}
private bool DeselectItem(GUIComponent component, object obj)
{
MapEntityPrefab prefab = obj as MapEntityPrefab;
if (prefab == null) return false;
selectedItemList.RemoveChild(selectedItemList.children.Find(c => c.UserData == obj));
return false;
}
public void SelectLocation(Location location, LocationConnection connection)
{
GUIComponent locationPanel = tabs[(int)Tab.Map].GetChild("selectedlocation");
if (locationPanel != null) tabs[(int)Tab.Map].RemoveChild(locationPanel);
locationPanel = new GUIFrame(new Rectangle(0, 0, 250, 190), Color.Transparent, Alignment.TopRight, null, tabs[(int)Tab.Map]);
locationPanel.UserData = "selectedlocation";
if (location == null) return;
new GUITextBlock(new Rectangle(0, 0, 250, 0), location.Name, "", Alignment.TopLeft, Alignment.TopCenter, locationPanel, true, GUI.LargeFont);
if (GameMain.GameSession.Map.SelectedConnection != null && GameMain.GameSession.Map.SelectedConnection.Mission != null)
{
var mission = GameMain.GameSession.Map.SelectedConnection.Mission;
new GUITextBlock(new Rectangle(0, 80, 0, 20), "Mission: " + mission.Name, "", locationPanel);
new GUITextBlock(new Rectangle(0, 100, 0, 20), "Reward: " + mission.Reward + " credits", "", locationPanel);
new GUITextBlock(new Rectangle(0, 130, 0, 0), mission.Description, "", locationPanel, true);
}
startButton.Enabled = true;
selectedLevel = connection.Level;
OnLocationSelected?.Invoke(location, connection);
}
private bool BuyItems(GUIButton button, object obj)
{
int cost = selectedItemCost;
if (campaign.Money < cost) return false;
campaign.Money -= cost;
for (int i = selectedItemList.children.Count - 1; i >= 0; i--)
{
GUIComponent child = selectedItemList.children[i];
ItemPrefab ip = child.UserData as ItemPrefab;
if (ip == null) continue;
campaign.CargoManager.AddItem(ip);
selectedItemList.RemoveChild(child);
}
return false;
}
public void SelectTab(Tab tab)
{
selectedTab = tab;
for (int i = 0; i< tabs.Length; i++)
{
tabs[i].Visible = (int)selectedTab == i;
}
}
private bool SelectItemCategory(GUIButton button, object selection)
{
if (!(selection is MapEntityCategory)) return false;
storeItemList.ClearChildren();
MapEntityCategory category = (MapEntityCategory)selection;
var items = MapEntityPrefab.list.FindAll(ep => ep.Price > 0.0f && ep.Category.HasFlag(category));
int width = storeItemList.Rect.Width;
foreach (MapEntityPrefab ep in items)
{
CreateItemFrame(ep, storeItemList, width);
}
storeItemList.children.Sort((x, y) => (x.UserData as MapEntityPrefab).Name.CompareTo((y.UserData as MapEntityPrefab).Name));
foreach (GUIComponent child in button.Parent.children)
{
var otherButton = child as GUIButton;
if (child.UserData is MapEntityCategory && otherButton != button)
{
otherButton.Selected = false;
}
}
button.Selected = true;
return true;
}
private string GetMoney()
{
return "Money: " + ((GameMain.GameSession == null) ? "0" : string.Format(CultureInfo.InvariantCulture, "{0:N0}", campaign.Money)) + " credits";
}
private bool SelectCharacter(GUIComponent component, object selection)
{
GUIComponent prevInfoFrame = null;
foreach (GUIComponent child in tabs[(int)selectedTab].children)
{
if (!(child.UserData is CharacterInfo)) continue;
prevInfoFrame = child;
}
if (prevInfoFrame != null) tabs[(int)selectedTab].RemoveChild(prevInfoFrame);
CharacterInfo characterInfo = selection as CharacterInfo;
if (characterInfo == null) return false;
characterList.Deselect();
hireList.Deselect();
if (Character.Controlled != null && characterInfo == Character.Controlled.Info) return false;
if (previewFrame == null || previewFrame.UserData != characterInfo)
{
int width = Math.Min(300, tabs[(int)Tab.Crew].Rect.Width - hireList.Rect.Width - characterList.Rect.Width - 50);
previewFrame = new GUIFrame(new Rectangle(0, 60, width, 300),
new Color(0.0f, 0.0f, 0.0f, 0.8f),
Alignment.TopCenter, "", tabs[(int)selectedTab]);
previewFrame.Padding = new Vector4(20.0f, 20.0f, 20.0f, 20.0f);
previewFrame.UserData = characterInfo;
characterInfo.CreateInfoFrame(previewFrame);
}
if (component.Parent == hireList)
{
GUIButton hireButton = new GUIButton(new Rectangle(0, 0, 100, 20), "Hire", Alignment.BottomCenter, "", previewFrame);
hireButton.UserData = characterInfo;
hireButton.OnClicked = HireCharacter;
}
return true;
}
private bool HireCharacter(GUIButton button, object selection)
{
/*CharacterInfo characterInfo = selection as CharacterInfo;
if (characterInfo == null) return false;
if (campaign.TryHireCharacter(GameMain.GameSession.Map.CurrentLocation.HireManager, characterInfo))
{
UpdateLocationTab(GameMain.GameSession.Map.CurrentLocation);
SelectCharacter(null, null);
}*/
return false;
}
}
}

View File

@@ -9,49 +9,11 @@ namespace Barotrauma
{
class LobbyScreen : Screen
{
enum PanelTab { Crew = 0, Map = 1, Store = 3 }
private CampaignUI campaignUI;
private GUIFrame topPanel, bottomPanel;
private GUIFrame topPanel;
private GUIFrame[] bottomPanel;
private GUIButton startButton;
private int selectedRightPanel;
private GUIListBox characterList, hireList;
private GUIListBox selectedItemList;
private GUIListBox storeItemList;
private SinglePlayerCampaign gameMode;
private GUIFrame previewFrame;
private GUIButton buyButton;
private Level selectedLevel;
float mapZoom = 3.0f;
private string CostTextGetter()
{
return "Cost: "+selectedItemCost.ToString()+" credits";
}
private int selectedItemCost
{
get
{
int cost = 0;
foreach (GUIComponent child in selectedItemList.children)
{
MapEntityPrefab ep = child.UserData as MapEntityPrefab;
if (ep == null) continue;
cost += ep.Price;
}
return cost;
}
}
private GUITextBlock locationTitle;
private CrewManager CrewManager
{
@@ -68,22 +30,27 @@ namespace Barotrauma
topPanel = new GUIFrame(panelRect, "");
topPanel.Padding = new Vector4(20.0f, 20.0f, 20.0f, 20.0f);
locationTitle = new GUITextBlock(new Rectangle(0, 0, 200, 25),
"", Color.Transparent, Color.White, Alignment.TopLeft, "", topPanel);
locationTitle.Font = GUI.LargeFont;
GUITextBlock moneyText = new GUITextBlock(new Rectangle(0, 0, 0, 25), "", "",
Alignment.BottomLeft, Alignment.BottomLeft, topPanel);
moneyText.TextGetter = GetMoney;
//moneyText.TextGetter = GetMoney;
GUIButton button = new GUIButton(new Rectangle(-240, 0, 100, 30), "Map", null, Alignment.BottomRight, "", topPanel);
button.UserData = PanelTab.Map;
button.OnClicked = SelectRightPanel;
SelectRightPanel(button, button.UserData);
button.UserData = CampaignUI.Tab.Map;
button.OnClicked = SelectTab;
SelectTab(button, button.UserData);
button = new GUIButton(new Rectangle(-120, 0, 100, 30), "Crew", null, Alignment.BottomRight, "", topPanel);
button.UserData = PanelTab.Crew;
button.OnClicked = SelectRightPanel;
button.UserData = CampaignUI.Tab.Crew;
button.OnClicked = SelectTab;
button = new GUIButton(new Rectangle(0, 0, 100, 30), "Store", null, Alignment.BottomRight, "", topPanel);
button.UserData = PanelTab.Store;
button.OnClicked = SelectRightPanel;
button.UserData = CampaignUI.Tab.Store;
button.OnClicked = SelectTab;
//---------------------------------------------------------------
//---------------------------------------------------------------
@@ -94,253 +61,37 @@ namespace Barotrauma
panelRect.Width,
GameMain.GraphicsHeight - 120 - panelRect.Height);
bottomPanel = new GUIFrame[4];
bottomPanel[(int)PanelTab.Crew] = new GUIFrame(panelRect, "");
bottomPanel[(int)PanelTab.Crew].Padding = new Vector4(20.0f, 20.0f, 20.0f, 20.0f);
//new GUITextBlock(new Rectangle(0, 0, 200, 25), "Crew:", Color.Transparent, Color.White, Alignment.Left, "", bottomPanel[(int)PanelTab.Crew]);
int crewColumnWidth = Math.Min(300, (panelRect.Width - 40) / 2);
new GUITextBlock(new Rectangle(0, 0, 100, 20), "Crew:", "", bottomPanel[(int)PanelTab.Crew], GUI.LargeFont);
characterList = new GUIListBox(new Rectangle(0, 40, crewColumnWidth, 0), "", bottomPanel[(int)PanelTab.Crew]);
characterList.OnSelected = SelectCharacter;
//---------------------------------------
bottomPanel[(int)PanelTab.Map] = new GUIFrame(panelRect, "");
bottomPanel[(int)PanelTab.Map].Padding = new Vector4(20.0f, 20.0f, 20.0f, 20.0f);
startButton = new GUIButton(new Rectangle(0, 0, 100, 30), "Start",
Alignment.BottomRight, "", bottomPanel[(int)PanelTab.Map]);
startButton.OnClicked = StartRound;
startButton.Enabled = false;
//---------------------------------------
bottomPanel[(int)PanelTab.Store] = new GUIFrame(panelRect, "");
bottomPanel[(int)PanelTab.Store].Padding = new Vector4(20.0f, 20.0f, 20.0f, 20.0f);
int sellColumnWidth = (panelRect.Width - 40) / 2 - 20;
selectedItemList = new GUIListBox(new Rectangle(0, 30, sellColumnWidth, 400), Color.White * 0.7f, "", bottomPanel[(int)PanelTab.Store]);
selectedItemList.OnSelected = DeselectItem;
var costText = new GUITextBlock(new Rectangle(0, 0, 100, 25), "Cost: ", "", Alignment.BottomLeft, Alignment.TopLeft, bottomPanel[(int)PanelTab.Store]);
costText.TextGetter = CostTextGetter;
buyButton = new GUIButton(new Rectangle(selectedItemList.Rect.Width - 100, 0, 100, 25), "Buy", Alignment.Bottom, "", bottomPanel[(int)PanelTab.Store]);
buyButton.OnClicked = BuyItems;
storeItemList = new GUIListBox(new Rectangle(0, 30, sellColumnWidth, 400), Color.White * 0.7f, Alignment.TopRight, "", bottomPanel[(int)PanelTab.Store]);
storeItemList.OnSelected = SelectItem;
int x = selectedItemList.Rect.Width + 40;
foreach (MapEntityCategory category in Enum.GetValues(typeof(MapEntityCategory)))
{
var items = MapEntityPrefab.list.FindAll(ep => ep.Price>0.0f && ep.Category.HasFlag(category));
if (!items.Any()) continue;
var categoryButton = new GUIButton(new Rectangle(x, 0, 100, 20), category.ToString(), "", bottomPanel[(int)PanelTab.Store]);
categoryButton.UserData = category;
categoryButton.OnClicked = SelectItemCategory;
if (category==MapEntityCategory.Equipment)
{
SelectItemCategory(categoryButton, category);
}
x += 110;
}
bottomPanel = new GUIFrame(panelRect);
}
public override void Select()
{
base.Select();
gameMode = GameMain.GameSession.GameMode as SinglePlayerCampaign;
CampaignMode campaign = GameMain.GameSession.GameMode as CampaignMode;
UpdateCharacterLists();
}
private void UpdateLocationTab(Location location)
{
topPanel.RemoveChild(topPanel.FindChild("locationtitle"));
topPanel.UserData = location;
var locationTitle = new GUITextBlock(new Rectangle(0, 0, 200, 25),
"Location: "+location.Name, Color.Transparent, Color.White, Alignment.TopLeft, "", topPanel);
locationTitle.UserData = "locationtitle";
locationTitle.Font = GUI.LargeFont;
if (hireList == null)
if (campaign == null)
{
hireList = new GUIListBox(new Rectangle(0, 40, 300, 0), "", Alignment.Right, bottomPanel[(int)PanelTab.Crew]);
new GUITextBlock(new Rectangle(0, 0, 300, 20), "Hire:", "", Alignment.Right, Alignment.Left, bottomPanel[(int)PanelTab.Crew], false, GUI.LargeFont);
hireList.OnSelected = SelectCharacter;
}
if (location.HireManager == null)
{
hireList.ClearChildren();
hireList.Enabled = false;
new GUITextBlock(new Rectangle(0, 0, 0, 0), "No-one available for hire", Color.Transparent, Color.LightGray, Alignment.Center, Alignment.Center, "", hireList);
return;
}
hireList.Enabled = true;
hireList.ClearChildren();
foreach (CharacterInfo c in location.HireManager.availableCharacters)
{
var frame = c.CreateCharacterFrame(hireList, c.Name + " (" + c.Job.Name + ")", c);
new GUITextBlock(
new Rectangle(0, 0, 0, 25),
c.Salary.ToString(),
null, null,
Alignment.TopRight, "", frame);
}
locationTitle.Text = "Location: " + campaign.Map.CurrentLocation.Name;
}
public override void Deselect()
{
SelectLocation(null,null);
base.Deselect();
}
public void SelectLocation(Location location, LocationConnection connection)
{
GUIComponent locationPanel = bottomPanel[(int)PanelTab.Map].GetChild("selectedlocation");
if (locationPanel != null) bottomPanel[(int)PanelTab.Map].RemoveChild(locationPanel);
locationPanel = new GUIFrame(new Rectangle(0, 0, 250, 190), Color.Transparent, Alignment.TopRight, null, bottomPanel[(int)PanelTab.Map]);
locationPanel.UserData = "selectedlocation";
if (location == null) return;
new GUITextBlock(new Rectangle(0, 0, 250, 0), location.Name, "", Alignment.TopLeft, Alignment.TopCenter, locationPanel, true, GUI.LargeFont);
if (GameMain.GameSession.Map.SelectedConnection != null && GameMain.GameSession.Map.SelectedConnection.Mission != null)
if (campaignUI == null)
{
var mission = GameMain.GameSession.Map.SelectedConnection.Mission;
new GUITextBlock(new Rectangle(0, 80, 0, 20), "Mission: "+mission.Name, "", locationPanel);
new GUITextBlock(new Rectangle(0, 100, 0, 20), "Reward: " + mission.Reward+" credits", "", locationPanel);
new GUITextBlock(new Rectangle(0, 130, 0, 0), mission.Description, "", locationPanel, true);
campaignUI = new CampaignUI(campaign, bottomPanel);
campaignUI.StartRound = StartRound;
campaignUI.OnLocationSelected = SelectLocation;
}
startButton.Enabled = true;
selectedLevel = connection.Level;
campaignUI.UpdateCharacterLists();
}
private void UpdateCharacterLists()
{
characterList.ClearChildren();
foreach (CharacterInfo c in CrewManager.CharacterInfos)
{
c.CreateCharacterFrame(characterList, c.Name + " ("+c.Job.Name+") ", c);
}
}
private void CreateItemFrame(MapEntityPrefab ep, GUIListBox listBox, int width)
{
GUIFrame frame = new GUIFrame(new Rectangle(0, 0, 0, 50), "ListBoxElement", listBox);
frame.UserData = ep;
frame.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f);
frame.ToolTip = ep.Description;
ScalableFont font = listBox.Rect.Width < 280 ? GUI.SmallFont : GUI.Font;
GUITextBlock textBlock = new GUITextBlock(
new Rectangle(50, 0, 0, 25),
ep.Name,
null,null,
Alignment.Left, Alignment.CenterX | Alignment.Left,
"", frame);
textBlock.Font = font;
textBlock.Padding = new Vector4(5.0f, 0.0f, 5.0f, 0.0f);
textBlock.ToolTip = ep.Description;
if (ep.sprite != null)
{
GUIImage img = new GUIImage(new Rectangle(0, 0, 40, 40), ep.sprite, Alignment.CenterLeft, frame);
img.Color = ep.SpriteColor;
img.Scale = Math.Min(Math.Min(40.0f / img.SourceRect.Width, 40.0f / img.SourceRect.Height), 1.0f);
}
textBlock = new GUITextBlock(
new Rectangle(width - 80, 0, 80, 25),
ep.Price.ToString(),
null, null, Alignment.TopLeft,
Alignment.TopLeft, "", frame);
textBlock.Font = font;
textBlock.ToolTip = ep.Description;
}
private bool SelectItem(GUIComponent component, object obj)
{
MapEntityPrefab prefab = obj as MapEntityPrefab;
if (prefab == null) return false;
CreateItemFrame(prefab, selectedItemList, selectedItemList.Rect.Width);
buyButton.Enabled = gameMode.Money >= selectedItemCost;
return false;
}
private bool DeselectItem(GUIComponent component, object obj)
{
MapEntityPrefab prefab = obj as MapEntityPrefab;
if (prefab == null) return false;
selectedItemList.RemoveChild(selectedItemList.children.Find(c => c.UserData == obj));
return false;
}
private bool BuyItems(GUIButton button, object obj)
{
int cost = selectedItemCost;
if (gameMode.Money < cost) return false;
gameMode.Money -= cost;
for (int i = selectedItemList.children.Count-1; i>=0; i--)
{
GUIComponent child = selectedItemList.children[i];
ItemPrefab ip = child.UserData as ItemPrefab;
if (ip == null) continue;
gameMode.CargoManager.AddItem(ip);
selectedItemList.RemoveChild(child);
}
return false;
}
public override void AddToGUIUpdateList()
{
base.AddToGUIUpdateList();
topPanel.AddToGUIUpdateList();
bottomPanel[selectedRightPanel].AddToGUIUpdateList();
bottomPanel.AddToGUIUpdateList();
}
public override void Update(double deltaTime)
@@ -348,24 +99,26 @@ namespace Barotrauma
base.Update(deltaTime);
topPanel.Update((float)deltaTime);
bottomPanel[selectedRightPanel].Update((float)deltaTime);
bottomPanel.Update((float)deltaTime);
mapZoom += PlayerInput.ScrollWheelSpeed / 1000.0f;
campaignUI.Update((float)deltaTime);
/* mapZoom += PlayerInput.ScrollWheelSpeed / 1000.0f;
mapZoom = MathHelper.Clamp(mapZoom, 1.0f, 4.0f);
GameMain.GameSession.Map.Update((float)deltaTime, new Rectangle(
bottomPanel[selectedRightPanel].Rect.X + 20,
bottomPanel[selectedRightPanel].Rect.Y + 20,
bottomPanel[selectedRightPanel].Rect.Width - 310,
bottomPanel[selectedRightPanel].Rect.Height - 40), mapZoom);
bottomPanel[selectedRightPanel].Rect.Height - 40), mapZoom);*/
}
public override void Draw(double deltaTime, GraphicsDevice graphics, SpriteBatch spriteBatch)
{
if (characterList.CountChildren != CrewManager.CharacterInfos.Count)
/*if (characterList.CountChildren != CrewManager.CharacterInfos.Count)
{
UpdateCharacterLists();
}
}*/
graphics.Clear(Color.Black);
@@ -376,10 +129,11 @@ namespace Barotrauma
Math.Max((float)GameMain.GraphicsWidth / backGround.SourceRect.Width, (float)GameMain.GraphicsHeight / backGround.SourceRect.Height), SpriteEffects.None, 0.0f);
topPanel.Draw(spriteBatch);
bottomPanel.Draw(spriteBatch);
bottomPanel[selectedRightPanel].Draw(spriteBatch);
campaignUI.Draw(spriteBatch);
if (selectedRightPanel == (int)PanelTab.Map)
/* if (selectedRightPanel == (int)PanelTab.Map)
{
GameMain.GameSession.Map.Draw(spriteBatch, new Rectangle(
bottomPanel[selectedRightPanel].Rect.X + 20,
@@ -391,7 +145,7 @@ namespace Barotrauma
if (topPanel.UserData as Location != GameMain.GameSession.Map.CurrentLocation)
{
UpdateLocationTab(GameMain.GameSession.Map.CurrentLocation);
}
}*/
GUI.Draw((float)deltaTime, spriteBatch, null);
@@ -399,138 +153,39 @@ namespace Barotrauma
}
public bool SelectRightPanel(GUIButton button, object selection)
public bool SelectTab(GUIButton button, object selection)
{
try
{
selectedRightPanel = (int)selection;
}
catch { return false; }
if (campaignUI == null) return false;
if (button != null)
{
button.Selected = true;
foreach (GUIComponent child in topPanel.children)
{
GUIButton otherButton = child as GUIButton;
if (otherButton == null || otherButton == button) continue;
otherButton.Selected = false;
}
}
return true;
}
private bool SelectItemCategory(GUIButton button, object selection)
{
if (!(selection is MapEntityCategory)) return false;
storeItemList.ClearChildren();
MapEntityCategory category = (MapEntityCategory)selection;
var items = MapEntityPrefab.list.FindAll(ep => ep.Price > 0.0f && ep.Category.HasFlag(category));
int width = storeItemList.Rect.Width;
foreach (MapEntityPrefab ep in items)
{
CreateItemFrame(ep, storeItemList, width);
}
storeItemList.children.Sort((x, y) => (x.UserData as MapEntityPrefab).Name.CompareTo((y.UserData as MapEntityPrefab).Name));
foreach (GUIComponent child in button.Parent.children)
{
var otherButton = child as GUIButton;
if (child.UserData is MapEntityCategory && otherButton != button)
{
otherButton.Selected = false;
}
}
button.Selected = true;
return true;
}
private string GetMoney()
{
return "Money: " + ((GameMain.GameSession == null) ? "0" : string.Format(CultureInfo.InvariantCulture, "{0:N0}", gameMode.Money)) + " credits";
}
private bool SelectCharacter(GUIComponent component, object selection)
{
GUIComponent prevInfoFrame = null;
foreach (GUIComponent child in bottomPanel[selectedRightPanel].children)
{
if (!(child.UserData is CharacterInfo)) continue;
prevInfoFrame = child;
}
if (prevInfoFrame != null) bottomPanel[selectedRightPanel].RemoveChild(prevInfoFrame);
CharacterInfo characterInfo = selection as CharacterInfo;
if (characterInfo == null) return false;
characterList.Deselect();
hireList.Deselect();
if (Character.Controlled != null && characterInfo == Character.Controlled.Info) return false;
if (previewFrame == null || previewFrame.UserData != characterInfo)
{
int width = Math.Min(300, bottomPanel[(int)PanelTab.Crew].Rect.Width - hireList.Rect.Width - characterList.Rect.Width - 50);
previewFrame = new GUIFrame(new Rectangle(0, 60, width, 300),
new Color(0.0f, 0.0f, 0.0f, 0.8f),
Alignment.TopCenter, "", bottomPanel[selectedRightPanel]);
previewFrame.Padding = new Vector4(20.0f, 20.0f, 20.0f, 20.0f);
previewFrame.UserData = characterInfo;
characterInfo.CreateInfoFrame(previewFrame);
}
if (component.Parent == hireList)
{
GUIButton hireButton = new GUIButton(new Rectangle(0,0, 100, 20), "Hire", Alignment.BottomCenter, "", previewFrame);
hireButton.UserData = characterInfo;
hireButton.OnClicked = HireCharacter;
}
if (button != null)
{
button.Selected = true;
foreach (GUIComponent child in topPanel.children)
{
GUIButton otherButton = child as GUIButton;
if (otherButton == null || otherButton == button) continue;
otherButton.Selected = false;
}
}
campaignUI.SelectTab((CampaignUI.Tab)selection);
return true;
}
private bool HireCharacter(GUIButton button, object selection)
public void SelectLocation(Location location, LocationConnection locationConnection)
{
CharacterInfo characterInfo = selection as CharacterInfo;
if (characterInfo == null) return false;
if (gameMode.TryHireCharacter(GameMain.GameSession.Map.CurrentLocation.HireManager, characterInfo))
{
UpdateLocationTab(GameMain.GameSession.Map.CurrentLocation);
SelectCharacter(null,null);
}
return false;
}
private bool StartRound(GUIButton button, object selection)
private void StartRound()
{
if (GameMain.GameSession.Map.SelectedConnection == null) return false;
if (GameMain.GameSession.Map.SelectedConnection == null) return;
GameMain.Instance.ShowLoading(LoadRound());
return true;
}
private IEnumerable<object> LoadRound()
{
GameMain.GameSession.StartRound(selectedLevel, true);
GameMain.GameSession.StartRound(campaignUI.SelectedLevel, true);
GameMain.GameScreen.Select();
yield return CoroutineStatus.Success;

View File

@@ -37,15 +37,11 @@ namespace Barotrauma
new GameModePreset("Single Player", typeof(SinglePlayerCampaign), true);
new GameModePreset("Tutorial", typeof(TutorialMode), true);
#endif
new GameModePreset("Campaign", typeof(MultiplayerCampaign), false);
var mode = new GameModePreset("SandBox", typeof(GameMode), false);
mode.Description = "A game mode with no specific objectives.";
//mode = new GameModePreset("Traitor", typeof(TraitorMode), false);
//mode.Description = "One of the players is selected as a traitor and given a secret objective. "
// + "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("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 "