Normalized line endings to CRLF
This commit is contained in:
@@ -1,188 +1,188 @@
|
|||||||
using Barotrauma.Networking;
|
using Barotrauma.Networking;
|
||||||
using Lidgren.Network;
|
using Lidgren.Network;
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace Barotrauma
|
namespace Barotrauma
|
||||||
{
|
{
|
||||||
partial class Voting
|
partial class Voting
|
||||||
{
|
{
|
||||||
public bool AllowSubVoting
|
public bool AllowSubVoting
|
||||||
{
|
{
|
||||||
get { return allowSubVoting; }
|
get { return allowSubVoting; }
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (value == allowSubVoting) return;
|
if (value == allowSubVoting) return;
|
||||||
allowSubVoting = value;
|
allowSubVoting = value;
|
||||||
GameMain.NetLobbyScreen.SubList.Enabled = value || GameMain.Server != null ||
|
GameMain.NetLobbyScreen.SubList.Enabled = value || GameMain.Server != null ||
|
||||||
(GameMain.Client != null && GameMain.Client.HasPermission(ClientPermissions.SelectSub));
|
(GameMain.Client != null && GameMain.Client.HasPermission(ClientPermissions.SelectSub));
|
||||||
GameMain.NetLobbyScreen.InfoFrame.FindChild("subvotes", true).Visible = value;
|
GameMain.NetLobbyScreen.InfoFrame.FindChild("subvotes", true).Visible = value;
|
||||||
|
|
||||||
if (GameMain.Server != null)
|
if (GameMain.Server != null)
|
||||||
{
|
{
|
||||||
UpdateVoteTexts(value ? GameMain.Server.ConnectedClients : null, VoteType.Sub);
|
UpdateVoteTexts(value ? GameMain.Server.ConnectedClients : null, VoteType.Sub);
|
||||||
GameMain.Server.UpdateVoteStatus();
|
GameMain.Server.UpdateVoteStatus();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
UpdateVoteTexts(null, VoteType.Sub);
|
UpdateVoteTexts(null, VoteType.Sub);
|
||||||
GameMain.NetLobbyScreen.SubList.Deselect();
|
GameMain.NetLobbyScreen.SubList.Deselect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public bool AllowModeVoting
|
public bool AllowModeVoting
|
||||||
{
|
{
|
||||||
get { return allowModeVoting; }
|
get { return allowModeVoting; }
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (value == allowModeVoting) return;
|
if (value == allowModeVoting) return;
|
||||||
allowModeVoting = value;
|
allowModeVoting = value;
|
||||||
GameMain.NetLobbyScreen.ModeList.Enabled =
|
GameMain.NetLobbyScreen.ModeList.Enabled =
|
||||||
value || GameMain.Server != null ||
|
value || GameMain.Server != null ||
|
||||||
(GameMain.Client != null && GameMain.Client.HasPermission(ClientPermissions.SelectMode));
|
(GameMain.Client != null && GameMain.Client.HasPermission(ClientPermissions.SelectMode));
|
||||||
|
|
||||||
GameMain.NetLobbyScreen.InfoFrame.FindChild("modevotes", true).Visible = value;
|
GameMain.NetLobbyScreen.InfoFrame.FindChild("modevotes", true).Visible = value;
|
||||||
|
|
||||||
//gray out modes that can't be voted
|
//gray out modes that can't be voted
|
||||||
foreach (GUITextBlock comp in GameMain.NetLobbyScreen.ModeList.children)
|
foreach (GUITextBlock comp in GameMain.NetLobbyScreen.ModeList.children)
|
||||||
{
|
{
|
||||||
comp.TextColor =
|
comp.TextColor =
|
||||||
new Color(comp.TextColor.R, comp.TextColor.G, comp.TextColor.B,
|
new Color(comp.TextColor.R, comp.TextColor.G, comp.TextColor.B,
|
||||||
!allowModeVoting || ((GameModePreset)comp.UserData).Votable ? (byte)255 : (byte)100);
|
!allowModeVoting || ((GameModePreset)comp.UserData).Votable ? (byte)255 : (byte)100);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GameMain.Server != null)
|
if (GameMain.Server != null)
|
||||||
{
|
{
|
||||||
UpdateVoteTexts(value ? GameMain.Server.ConnectedClients : null, VoteType.Mode);
|
UpdateVoteTexts(value ? GameMain.Server.ConnectedClients : null, VoteType.Mode);
|
||||||
GameMain.Server.UpdateVoteStatus();
|
GameMain.Server.UpdateVoteStatus();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
UpdateVoteTexts(null, VoteType.Mode);
|
UpdateVoteTexts(null, VoteType.Mode);
|
||||||
GameMain.NetLobbyScreen.ModeList.Deselect();
|
GameMain.NetLobbyScreen.ModeList.Deselect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateVoteTexts(List<Client> clients, VoteType voteType)
|
public void UpdateVoteTexts(List<Client> clients, VoteType voteType)
|
||||||
{
|
{
|
||||||
GUIListBox listBox = (voteType == VoteType.Sub) ?
|
GUIListBox listBox = (voteType == VoteType.Sub) ?
|
||||||
GameMain.NetLobbyScreen.SubList : GameMain.NetLobbyScreen.ModeList;
|
GameMain.NetLobbyScreen.SubList : GameMain.NetLobbyScreen.ModeList;
|
||||||
|
|
||||||
foreach (GUIComponent comp in listBox.children)
|
foreach (GUIComponent comp in listBox.children)
|
||||||
{
|
{
|
||||||
GUITextBlock voteText = comp.FindChild("votes") as GUITextBlock;
|
GUITextBlock voteText = comp.FindChild("votes") as GUITextBlock;
|
||||||
if (voteText != null) comp.RemoveChild(voteText);
|
if (voteText != null) comp.RemoveChild(voteText);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (clients != null)
|
if (clients != null)
|
||||||
{
|
{
|
||||||
List<Pair<object, int>> voteList = GetVoteList(voteType, clients);
|
List<Pair<object, int>> voteList = GetVoteList(voteType, clients);
|
||||||
foreach (Pair<object, int> votable in voteList)
|
foreach (Pair<object, int> votable in voteList)
|
||||||
{
|
{
|
||||||
SetVoteText(listBox, votable.First, votable.Second);
|
SetVoteText(listBox, votable.First, votable.Second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetVoteText(GUIListBox listBox, object userData, int votes)
|
private void SetVoteText(GUIListBox listBox, object userData, int votes)
|
||||||
{
|
{
|
||||||
if (userData == null) return;
|
if (userData == null) return;
|
||||||
foreach (GUIComponent comp in listBox.children)
|
foreach (GUIComponent comp in listBox.children)
|
||||||
{
|
{
|
||||||
if (comp.UserData != userData) continue;
|
if (comp.UserData != userData) continue;
|
||||||
GUITextBlock voteText = comp.FindChild("votes") as GUITextBlock;
|
GUITextBlock voteText = comp.FindChild("votes") as GUITextBlock;
|
||||||
if (voteText == null)
|
if (voteText == null)
|
||||||
{
|
{
|
||||||
voteText = new GUITextBlock(new Rectangle(0, 0, 30, 0), "", "", Alignment.Right, Alignment.Right, comp);
|
voteText = new GUITextBlock(new Rectangle(0, 0, 30, 0), "", "", Alignment.Right, Alignment.Right, comp);
|
||||||
voteText.UserData = "votes";
|
voteText.UserData = "votes";
|
||||||
}
|
}
|
||||||
|
|
||||||
voteText.Text = votes == 0 ? "" : votes.ToString();
|
voteText.Text = votes == 0 ? "" : votes.ToString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ClientWrite(NetBuffer msg, VoteType voteType, object data)
|
public void ClientWrite(NetBuffer msg, VoteType voteType, object data)
|
||||||
{
|
{
|
||||||
if (GameMain.Server != null) return;
|
if (GameMain.Server != null) return;
|
||||||
|
|
||||||
msg.Write((byte)voteType);
|
msg.Write((byte)voteType);
|
||||||
|
|
||||||
switch (voteType)
|
switch (voteType)
|
||||||
{
|
{
|
||||||
case VoteType.Sub:
|
case VoteType.Sub:
|
||||||
Submarine sub = data as Submarine;
|
Submarine sub = data as Submarine;
|
||||||
if (sub == null) return;
|
if (sub == null) return;
|
||||||
|
|
||||||
msg.Write(sub.Name);
|
msg.Write(sub.Name);
|
||||||
break;
|
break;
|
||||||
case VoteType.Mode:
|
case VoteType.Mode:
|
||||||
GameModePreset gameMode = data as GameModePreset;
|
GameModePreset gameMode = data as GameModePreset;
|
||||||
if (gameMode == null) return;
|
if (gameMode == null) return;
|
||||||
|
|
||||||
msg.Write(gameMode.Name);
|
msg.Write(gameMode.Name);
|
||||||
break;
|
break;
|
||||||
case VoteType.EndRound:
|
case VoteType.EndRound:
|
||||||
if (!(data is bool)) return;
|
if (!(data is bool)) return;
|
||||||
|
|
||||||
msg.Write((bool)data);
|
msg.Write((bool)data);
|
||||||
break;
|
break;
|
||||||
case VoteType.Kick:
|
case VoteType.Kick:
|
||||||
Client votedClient = data as Client;
|
Client votedClient = data as Client;
|
||||||
if (votedClient == null) return;
|
if (votedClient == null) return;
|
||||||
|
|
||||||
msg.Write(votedClient.ID);
|
msg.Write(votedClient.ID);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
msg.WritePadBits();
|
msg.WritePadBits();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ClientRead(NetIncomingMessage inc)
|
public void ClientRead(NetIncomingMessage inc)
|
||||||
{
|
{
|
||||||
if (GameMain.Server != null) return;
|
if (GameMain.Server != null) return;
|
||||||
|
|
||||||
AllowSubVoting = inc.ReadBoolean();
|
AllowSubVoting = inc.ReadBoolean();
|
||||||
if (allowSubVoting)
|
if (allowSubVoting)
|
||||||
{
|
{
|
||||||
UpdateVoteTexts(null, VoteType.Sub);
|
UpdateVoteTexts(null, VoteType.Sub);
|
||||||
int votableCount = inc.ReadByte();
|
int votableCount = inc.ReadByte();
|
||||||
for (int i = 0; i < votableCount; i++)
|
for (int i = 0; i < votableCount; i++)
|
||||||
{
|
{
|
||||||
int votes = inc.ReadByte();
|
int votes = inc.ReadByte();
|
||||||
string subName = inc.ReadString();
|
string subName = inc.ReadString();
|
||||||
List<Submarine> serversubs = new List<Submarine>();
|
List<Submarine> serversubs = new List<Submarine>();
|
||||||
foreach (GUIComponent item in GameMain.NetLobbyScreen?.SubList?.children)
|
foreach (GUIComponent item in GameMain.NetLobbyScreen?.SubList?.children)
|
||||||
{
|
{
|
||||||
if (item.UserData != null && item.UserData is Submarine) serversubs.Add(item.UserData as Submarine);
|
if (item.UserData != null && item.UserData is Submarine) serversubs.Add(item.UserData as Submarine);
|
||||||
}
|
}
|
||||||
Submarine sub = serversubs.FirstOrDefault(sm => sm.Name == subName);
|
Submarine sub = serversubs.FirstOrDefault(sm => sm.Name == subName);
|
||||||
SetVoteText(GameMain.NetLobbyScreen.SubList, sub, votes);
|
SetVoteText(GameMain.NetLobbyScreen.SubList, sub, votes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
AllowModeVoting = inc.ReadBoolean();
|
AllowModeVoting = inc.ReadBoolean();
|
||||||
if (allowModeVoting)
|
if (allowModeVoting)
|
||||||
{
|
{
|
||||||
UpdateVoteTexts(null, VoteType.Mode);
|
UpdateVoteTexts(null, VoteType.Mode);
|
||||||
int votableCount = inc.ReadByte();
|
int votableCount = inc.ReadByte();
|
||||||
for (int i = 0; i < votableCount; i++)
|
for (int i = 0; i < votableCount; i++)
|
||||||
{
|
{
|
||||||
int votes = inc.ReadByte();
|
int votes = inc.ReadByte();
|
||||||
string modeName = inc.ReadString();
|
string modeName = inc.ReadString();
|
||||||
GameModePreset mode = GameModePreset.list.Find(m => m.Name == modeName);
|
GameModePreset mode = GameModePreset.list.Find(m => m.Name == modeName);
|
||||||
SetVoteText(GameMain.NetLobbyScreen.ModeList, mode, votes);
|
SetVoteText(GameMain.NetLobbyScreen.ModeList, mode, votes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
AllowEndVoting = inc.ReadBoolean();
|
AllowEndVoting = inc.ReadBoolean();
|
||||||
if (AllowEndVoting)
|
if (AllowEndVoting)
|
||||||
{
|
{
|
||||||
GameMain.NetworkMember.EndVoteCount = inc.ReadByte();
|
GameMain.NetworkMember.EndVoteCount = inc.ReadByte();
|
||||||
GameMain.NetworkMember.EndVoteMax = inc.ReadByte();
|
GameMain.NetworkMember.EndVoteMax = inc.ReadByte();
|
||||||
}
|
}
|
||||||
AllowVoteKick = inc.ReadBoolean();
|
AllowVoteKick = inc.ReadBoolean();
|
||||||
|
|
||||||
inc.ReadPadBits();
|
inc.ReadPadBits();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,259 +1,259 @@
|
|||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace Barotrauma
|
namespace Barotrauma
|
||||||
{
|
{
|
||||||
class CampaignUI
|
class CampaignUI
|
||||||
{
|
{
|
||||||
public enum Tab { Crew = 0, Map = 1, Store = 2 }
|
public enum Tab { Crew = 0, Map = 1, Store = 2 }
|
||||||
|
|
||||||
private GUIFrame[] tabs;
|
private GUIFrame[] tabs;
|
||||||
|
|
||||||
private GUIButton startButton;
|
private GUIButton startButton;
|
||||||
|
|
||||||
private Tab selectedTab;
|
private Tab selectedTab;
|
||||||
|
|
||||||
private GUIListBox characterList, hireList;
|
private GUIListBox characterList, hireList;
|
||||||
|
|
||||||
private GUIListBox selectedItemList;
|
private GUIListBox selectedItemList;
|
||||||
private GUIListBox storeItemList;
|
private GUIListBox storeItemList;
|
||||||
|
|
||||||
private CampaignMode campaign;
|
private CampaignMode campaign;
|
||||||
|
|
||||||
private GUIFrame characterPreviewFrame;
|
private GUIFrame characterPreviewFrame;
|
||||||
|
|
||||||
private Level selectedLevel;
|
private Level selectedLevel;
|
||||||
|
|
||||||
private float mapZoom = 3.0f;
|
private float mapZoom = 3.0f;
|
||||||
|
|
||||||
public Action StartRound;
|
public Action StartRound;
|
||||||
public Action<Location, LocationConnection> OnLocationSelected;
|
public Action<Location, LocationConnection> OnLocationSelected;
|
||||||
|
|
||||||
public Level SelectedLevel
|
public Level SelectedLevel
|
||||||
{
|
{
|
||||||
get { return selectedLevel; }
|
get { return selectedLevel; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public CampaignMode Campaign
|
public CampaignMode Campaign
|
||||||
{
|
{
|
||||||
get { return campaign; }
|
get { return campaign; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public CampaignUI(CampaignMode campaign, GUIFrame container)
|
public CampaignUI(CampaignMode campaign, GUIFrame container)
|
||||||
{
|
{
|
||||||
this.campaign = campaign;
|
this.campaign = campaign;
|
||||||
|
|
||||||
tabs = new GUIFrame[3];
|
tabs = new GUIFrame[3];
|
||||||
|
|
||||||
tabs[(int)Tab.Crew] = new GUIFrame(Rectangle.Empty, null, container);
|
tabs[(int)Tab.Crew] = new GUIFrame(Rectangle.Empty, null, container);
|
||||||
tabs[(int)Tab.Crew].Padding = Vector4.One * 10.0f;
|
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]);
|
//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);
|
int crewColumnWidth = Math.Min(300, (container.Rect.Width - 40) / 2);
|
||||||
|
|
||||||
new GUITextBlock(new Rectangle(0, 0, 100, 20), TextManager.Get("Crew") + ":", "", tabs[(int)Tab.Crew], GUI.LargeFont);
|
new GUITextBlock(new Rectangle(0, 0, 100, 20), TextManager.Get("Crew") + ":", "", tabs[(int)Tab.Crew], GUI.LargeFont);
|
||||||
characterList = new GUIListBox(new Rectangle(0, 40, crewColumnWidth, 0), "", tabs[(int)Tab.Crew]);
|
characterList = new GUIListBox(new Rectangle(0, 40, crewColumnWidth, 0), "", tabs[(int)Tab.Crew]);
|
||||||
characterList.OnSelected = SelectCharacter;
|
characterList.OnSelected = SelectCharacter;
|
||||||
|
|
||||||
hireList = new GUIListBox(new Rectangle(0, 40, 300, 0), "", Alignment.Right, tabs[(int)Tab.Crew]);
|
hireList = new GUIListBox(new Rectangle(0, 40, 300, 0), "", Alignment.Right, tabs[(int)Tab.Crew]);
|
||||||
new GUITextBlock(new Rectangle(0, 0, 300, 20), TextManager.Get("Hire") + ":", "", Alignment.Right, Alignment.Left, tabs[(int)Tab.Crew], false, GUI.LargeFont);
|
new GUITextBlock(new Rectangle(0, 0, 300, 20), TextManager.Get("Hire") + ":", "", Alignment.Right, Alignment.Left, tabs[(int)Tab.Crew], false, GUI.LargeFont);
|
||||||
hireList.OnSelected = SelectCharacter;
|
hireList.OnSelected = SelectCharacter;
|
||||||
|
|
||||||
//---------------------------------------
|
//---------------------------------------
|
||||||
|
|
||||||
tabs[(int)Tab.Map] = new GUIFrame(Rectangle.Empty, null, container);
|
tabs[(int)Tab.Map] = new GUIFrame(Rectangle.Empty, null, container);
|
||||||
tabs[(int)Tab.Map].Padding = Vector4.One * 10.0f;
|
tabs[(int)Tab.Map].Padding = Vector4.One * 10.0f;
|
||||||
|
|
||||||
if (GameMain.Client == null)
|
if (GameMain.Client == null)
|
||||||
{
|
{
|
||||||
startButton = new GUIButton(new Rectangle(0, 0, 100, 30), TextManager.Get("StartCampaignButton"),
|
startButton = new GUIButton(new Rectangle(0, 0, 100, 30), TextManager.Get("StartCampaignButton"),
|
||||||
Alignment.BottomRight, "", tabs[(int)Tab.Map]);
|
Alignment.BottomRight, "", tabs[(int)Tab.Map]);
|
||||||
startButton.OnClicked = (GUIButton btn, object obj) => { StartRound?.Invoke(); return true; };
|
startButton.OnClicked = (GUIButton btn, object obj) => { StartRound?.Invoke(); return true; };
|
||||||
startButton.Enabled = false;
|
startButton.Enabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------
|
//---------------------------------------
|
||||||
|
|
||||||
tabs[(int)Tab.Store] = new GUIFrame(Rectangle.Empty, null, container);
|
tabs[(int)Tab.Store] = new GUIFrame(Rectangle.Empty, null, container);
|
||||||
tabs[(int)Tab.Store].Padding = Vector4.One * 10.0f;
|
tabs[(int)Tab.Store].Padding = Vector4.One * 10.0f;
|
||||||
|
|
||||||
int sellColumnWidth = (tabs[(int)Tab.Store].Rect.Width - 40) / 2 - 20;
|
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 = new GUIListBox(new Rectangle(0, 30, sellColumnWidth, tabs[(int)Tab.Store].Rect.Height - 80), Color.White * 0.7f, "", tabs[(int)Tab.Store]);
|
||||||
//selectedItemList.OnSelected = SellItem;
|
//selectedItemList.OnSelected = SellItem;
|
||||||
|
|
||||||
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 = 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 = BuyItem;
|
storeItemList.OnSelected = BuyItem;
|
||||||
|
|
||||||
int x = storeItemList.Rect.X - storeItemList.Parent.Rect.X;
|
int x = storeItemList.Rect.X - storeItemList.Parent.Rect.X;
|
||||||
|
|
||||||
List<MapEntityCategory> itemCategories = Enum.GetValues(typeof(MapEntityCategory)).Cast<MapEntityCategory>().ToList();
|
List<MapEntityCategory> itemCategories = Enum.GetValues(typeof(MapEntityCategory)).Cast<MapEntityCategory>().ToList();
|
||||||
//don't show categories with no buyable items
|
//don't show categories with no buyable items
|
||||||
itemCategories.RemoveAll(c => !MapEntityPrefab.List.Any(ep => ep.Price > 0.0f && ep.Category.HasFlag(c)));
|
itemCategories.RemoveAll(c => !MapEntityPrefab.List.Any(ep => ep.Price > 0.0f && ep.Category.HasFlag(c)));
|
||||||
|
|
||||||
int buttonWidth = Math.Min(sellColumnWidth / itemCategories.Count, 100);
|
int buttonWidth = Math.Min(sellColumnWidth / itemCategories.Count, 100);
|
||||||
foreach (MapEntityCategory category in itemCategories)
|
foreach (MapEntityCategory category in itemCategories)
|
||||||
{
|
{
|
||||||
var categoryButton = new GUIButton(new Rectangle(x, 0, buttonWidth, 20), category.ToString(), "", tabs[(int)Tab.Store]);
|
var categoryButton = new GUIButton(new Rectangle(x, 0, buttonWidth, 20), category.ToString(), "", tabs[(int)Tab.Store]);
|
||||||
categoryButton.UserData = category;
|
categoryButton.UserData = category;
|
||||||
categoryButton.OnClicked = SelectItemCategory;
|
categoryButton.OnClicked = SelectItemCategory;
|
||||||
|
|
||||||
if (category == MapEntityCategory.Equipment)
|
if (category == MapEntityCategory.Equipment)
|
||||||
{
|
{
|
||||||
SelectItemCategory(categoryButton, category);
|
SelectItemCategory(categoryButton, category);
|
||||||
}
|
}
|
||||||
x += buttonWidth;
|
x += buttonWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
SelectTab(Tab.Map);
|
SelectTab(Tab.Map);
|
||||||
|
|
||||||
UpdateLocationTab(campaign.Map.CurrentLocation);
|
UpdateLocationTab(campaign.Map.CurrentLocation);
|
||||||
|
|
||||||
campaign.Map.OnLocationSelected += SelectLocation;
|
campaign.Map.OnLocationSelected += SelectLocation;
|
||||||
campaign.Map.OnLocationChanged += (location) => UpdateLocationTab(location);
|
campaign.Map.OnLocationChanged += (location) => UpdateLocationTab(location);
|
||||||
campaign.CargoManager.OnItemsChanged += RefreshItemTab;
|
campaign.CargoManager.OnItemsChanged += RefreshItemTab;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateLocationTab(Location location)
|
private void UpdateLocationTab(Location location)
|
||||||
{
|
{
|
||||||
if (characterPreviewFrame != null)
|
if (characterPreviewFrame != null)
|
||||||
{
|
{
|
||||||
characterPreviewFrame.Parent.RemoveChild(characterPreviewFrame);
|
characterPreviewFrame.Parent.RemoveChild(characterPreviewFrame);
|
||||||
characterPreviewFrame = null;
|
characterPreviewFrame = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (location.HireManager == null)
|
if (location.HireManager == null)
|
||||||
{
|
{
|
||||||
hireList.ClearChildren();
|
hireList.ClearChildren();
|
||||||
hireList.Enabled = false;
|
hireList.Enabled = false;
|
||||||
|
|
||||||
new GUITextBlock(new Rectangle(0, 0, 0, 0), TextManager.Get("HireUnavailable"), Color.Transparent, Color.LightGray, Alignment.Center, Alignment.Center, "", hireList);
|
new GUITextBlock(new Rectangle(0, 0, 0, 0), TextManager.Get("HireUnavailable"), Color.Transparent, Color.LightGray, Alignment.Center, Alignment.Center, "", hireList);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
hireList.Enabled = true;
|
hireList.Enabled = true;
|
||||||
hireList.ClearChildren();
|
hireList.ClearChildren();
|
||||||
|
|
||||||
foreach (CharacterInfo c in location.HireManager.availableCharacters)
|
foreach (CharacterInfo c in location.HireManager.availableCharacters)
|
||||||
{
|
{
|
||||||
var frame = c.CreateCharacterFrame(hireList, c.Name + " (" + c.Job.Name + ")", c);
|
var frame = c.CreateCharacterFrame(hireList, c.Name + " (" + c.Job.Name + ")", c);
|
||||||
|
|
||||||
new GUITextBlock(
|
new GUITextBlock(
|
||||||
new Rectangle(0, 0, 0, 25),
|
new Rectangle(0, 0, 0, 25),
|
||||||
c.Salary.ToString(),
|
c.Salary.ToString(),
|
||||||
null, null,
|
null, null,
|
||||||
Alignment.TopRight, "", frame);
|
Alignment.TopRight, "", frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
RefreshItemTab();
|
RefreshItemTab();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Update(float deltaTime)
|
public void Update(float deltaTime)
|
||||||
{
|
{
|
||||||
mapZoom += PlayerInput.ScrollWheelSpeed / 1000.0f;
|
mapZoom += PlayerInput.ScrollWheelSpeed / 1000.0f;
|
||||||
mapZoom = MathHelper.Clamp(mapZoom, 1.0f, 4.0f);
|
mapZoom = MathHelper.Clamp(mapZoom, 1.0f, 4.0f);
|
||||||
|
|
||||||
if (GameMain.GameSession?.Map != null)
|
if (GameMain.GameSession?.Map != null)
|
||||||
{
|
{
|
||||||
GameMain.GameSession.Map.Update(deltaTime, new Rectangle(
|
GameMain.GameSession.Map.Update(deltaTime, new Rectangle(
|
||||||
tabs[(int)selectedTab].Rect.X + 20,
|
tabs[(int)selectedTab].Rect.X + 20,
|
||||||
tabs[(int)selectedTab].Rect.Y + 20,
|
tabs[(int)selectedTab].Rect.Y + 20,
|
||||||
tabs[(int)selectedTab].Rect.Width - 310,
|
tabs[(int)selectedTab].Rect.Width - 310,
|
||||||
tabs[(int)selectedTab].Rect.Height - 40), mapZoom);
|
tabs[(int)selectedTab].Rect.Height - 40), mapZoom);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Draw(SpriteBatch spriteBatch)
|
public void Draw(SpriteBatch spriteBatch)
|
||||||
{
|
{
|
||||||
if (selectedTab == Tab.Map && GameMain.GameSession?.Map != null)
|
if (selectedTab == Tab.Map && GameMain.GameSession?.Map != null)
|
||||||
{
|
{
|
||||||
GameMain.GameSession.Map.Draw(spriteBatch, new Rectangle(
|
GameMain.GameSession.Map.Draw(spriteBatch, new Rectangle(
|
||||||
tabs[(int)selectedTab].Rect.X + 20,
|
tabs[(int)selectedTab].Rect.X + 20,
|
||||||
tabs[(int)selectedTab].Rect.Y + 20,
|
tabs[(int)selectedTab].Rect.Y + 20,
|
||||||
tabs[(int)selectedTab].Rect.Width - 310,
|
tabs[(int)selectedTab].Rect.Width - 310,
|
||||||
tabs[(int)selectedTab].Rect.Height - 40), mapZoom);
|
tabs[(int)selectedTab].Rect.Height - 40), mapZoom);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateCharacterLists()
|
public void UpdateCharacterLists()
|
||||||
{
|
{
|
||||||
characterList.ClearChildren();
|
characterList.ClearChildren();
|
||||||
foreach (CharacterInfo c in GameMain.GameSession.CrewManager.GetCharacterInfos())
|
foreach (CharacterInfo c in GameMain.GameSession.CrewManager.GetCharacterInfos())
|
||||||
{
|
{
|
||||||
c.CreateCharacterFrame(characterList, c.Name + " (" + c.Job.Name + ") ", c);
|
c.CreateCharacterFrame(characterList, c.Name + " (" + c.Job.Name + ") ", c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SelectLocation(Location location, LocationConnection connection)
|
public void SelectLocation(Location location, LocationConnection connection)
|
||||||
{
|
{
|
||||||
GUIComponent locationPanel = tabs[(int)Tab.Map].GetChild("selectedlocation");
|
GUIComponent locationPanel = tabs[(int)Tab.Map].GetChild("selectedlocation");
|
||||||
|
|
||||||
if (locationPanel != null) tabs[(int)Tab.Map].RemoveChild(locationPanel);
|
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 = new GUIFrame(new Rectangle(0, 0, 250, 190), Color.Transparent, Alignment.TopRight, null, tabs[(int)Tab.Map]);
|
||||||
locationPanel.UserData = "selectedlocation";
|
locationPanel.UserData = "selectedlocation";
|
||||||
|
|
||||||
if (location == null) return;
|
if (location == null) return;
|
||||||
|
|
||||||
var titleText = new GUITextBlock(new Rectangle(0, 0, 250, 0), location.Name, "", Alignment.TopLeft, Alignment.TopCenter, locationPanel, true, GUI.LargeFont);
|
var titleText = 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 (GameMain.GameSession.Map.SelectedConnection != null && GameMain.GameSession.Map.SelectedConnection.Mission != null)
|
||||||
{
|
{
|
||||||
var mission = GameMain.GameSession.Map.SelectedConnection.Mission;
|
var mission = GameMain.GameSession.Map.SelectedConnection.Mission;
|
||||||
|
|
||||||
new GUITextBlock(new Rectangle(0, titleText.Rect.Height + 20, 0, 20), TextManager.Get("Mission") + ": " + mission.Name, "", locationPanel);
|
new GUITextBlock(new Rectangle(0, titleText.Rect.Height + 20, 0, 20), TextManager.Get("Mission") + ": " + mission.Name, "", locationPanel);
|
||||||
new GUITextBlock(new Rectangle(0, titleText.Rect.Height + 40, 0, 20), TextManager.Get("Reward") + ": " + mission.Reward + " " + TextManager.Get("Credits"), "", locationPanel);
|
new GUITextBlock(new Rectangle(0, titleText.Rect.Height + 40, 0, 20), TextManager.Get("Reward") + ": " + mission.Reward + " " + TextManager.Get("Credits"), "", locationPanel);
|
||||||
new GUITextBlock(new Rectangle(0, titleText.Rect.Height + 70, 0, 0), mission.Description, "", Alignment.TopLeft, Alignment.TopLeft, locationPanel, true, GUI.SmallFont);
|
new GUITextBlock(new Rectangle(0, titleText.Rect.Height + 70, 0, 0), mission.Description, "", Alignment.TopLeft, Alignment.TopLeft, locationPanel, true, GUI.SmallFont);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (startButton != null) startButton.Enabled = true;
|
if (startButton != null) startButton.Enabled = true;
|
||||||
|
|
||||||
selectedLevel = connection.Level;
|
selectedLevel = connection.Level;
|
||||||
|
|
||||||
OnLocationSelected?.Invoke(location, connection);
|
OnLocationSelected?.Invoke(location, connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CreateItemFrame(PurchasedItem pi, GUIListBox listBox, int width)
|
private void CreateItemFrame(PurchasedItem pi, GUIListBox listBox, int width)
|
||||||
{
|
{
|
||||||
GUIFrame frame = new GUIFrame(new Rectangle(0, 0, 0, 50), "ListBoxElement", listBox);
|
GUIFrame frame = new GUIFrame(new Rectangle(0, 0, 0, 50), "ListBoxElement", listBox);
|
||||||
frame.UserData = pi;
|
frame.UserData = pi;
|
||||||
frame.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f);
|
frame.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f);
|
||||||
|
|
||||||
frame.ToolTip = pi.itemPrefab.Description;
|
frame.ToolTip = pi.itemPrefab.Description;
|
||||||
|
|
||||||
ScalableFont font = listBox.Rect.Width < 280 ? GUI.SmallFont : GUI.Font;
|
ScalableFont font = listBox.Rect.Width < 280 ? GUI.SmallFont : GUI.Font;
|
||||||
|
|
||||||
GUITextBlock textBlock = new GUITextBlock(
|
GUITextBlock textBlock = new GUITextBlock(
|
||||||
new Rectangle(50, 0, 0, 25),
|
new Rectangle(50, 0, 0, 25),
|
||||||
pi.itemPrefab.Name,
|
pi.itemPrefab.Name,
|
||||||
null, null,
|
null, null,
|
||||||
Alignment.Left, Alignment.CenterX | Alignment.Left,
|
Alignment.Left, Alignment.CenterX | Alignment.Left,
|
||||||
"", frame);
|
"", frame);
|
||||||
textBlock.Font = font;
|
textBlock.Font = font;
|
||||||
textBlock.Padding = new Vector4(5.0f, 0.0f, 5.0f, 0.0f);
|
textBlock.Padding = new Vector4(5.0f, 0.0f, 5.0f, 0.0f);
|
||||||
textBlock.ToolTip = pi.itemPrefab.Description;
|
textBlock.ToolTip = pi.itemPrefab.Description;
|
||||||
|
|
||||||
if (pi.itemPrefab.sprite != null)
|
if (pi.itemPrefab.sprite != null)
|
||||||
{
|
{
|
||||||
GUIImage img = new GUIImage(new Rectangle(0, 0, 40, 40), pi.itemPrefab.sprite, Alignment.CenterLeft, frame);
|
GUIImage img = new GUIImage(new Rectangle(0, 0, 40, 40), pi.itemPrefab.sprite, Alignment.CenterLeft, frame);
|
||||||
img.Color = pi.itemPrefab.SpriteColor;
|
img.Color = pi.itemPrefab.SpriteColor;
|
||||||
img.Scale = Math.Min(Math.Min(40.0f / img.SourceRect.Width, 40.0f / img.SourceRect.Height), 1.0f);
|
img.Scale = Math.Min(Math.Min(40.0f / img.SourceRect.Width, 40.0f / img.SourceRect.Height), 1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
textBlock = new GUITextBlock(
|
textBlock = new GUITextBlock(
|
||||||
new Rectangle(width - 160, 0, 80, 25),
|
new Rectangle(width - 160, 0, 80, 25),
|
||||||
pi.itemPrefab.Price.ToString(),
|
pi.itemPrefab.Price.ToString(),
|
||||||
null, null, Alignment.TopLeft,
|
null, null, Alignment.TopLeft,
|
||||||
Alignment.TopLeft, "", frame);
|
Alignment.TopLeft, "", frame);
|
||||||
textBlock.Font = font;
|
textBlock.Font = font;
|
||||||
textBlock.ToolTip = pi.itemPrefab.Description;
|
textBlock.ToolTip = pi.itemPrefab.Description;
|
||||||
|
|
||||||
//If its the store menu, quantity will always be 0
|
//If its the store menu, quantity will always be 0
|
||||||
if (pi.quantity > 0)
|
if (pi.quantity > 0)
|
||||||
{
|
{
|
||||||
var amountInput = new GUINumberInput(new Rectangle(width - 80, 0, 50, 40), "", GUINumberInput.NumberType.Int, frame);
|
var amountInput = new GUINumberInput(new Rectangle(width - 80, 0, 50, 40), "", GUINumberInput.NumberType.Int, frame);
|
||||||
@@ -261,193 +261,193 @@ namespace Barotrauma
|
|||||||
amountInput.MaxValueInt = 1000;
|
amountInput.MaxValueInt = 1000;
|
||||||
amountInput.UserData = pi;
|
amountInput.UserData = pi;
|
||||||
amountInput.IntValue = pi.quantity;
|
amountInput.IntValue = pi.quantity;
|
||||||
amountInput.OnValueChanged += (numberInput) =>
|
amountInput.OnValueChanged += (numberInput) =>
|
||||||
{
|
{
|
||||||
PurchasedItem purchasedItem = numberInput.UserData as PurchasedItem;
|
PurchasedItem purchasedItem = numberInput.UserData as PurchasedItem;
|
||||||
|
|
||||||
//Attempting to buy
|
//Attempting to buy
|
||||||
if (numberInput.IntValue > purchasedItem.quantity)
|
if (numberInput.IntValue > purchasedItem.quantity)
|
||||||
{
|
{
|
||||||
int quantity = numberInput.IntValue - purchasedItem.quantity;
|
int quantity = numberInput.IntValue - purchasedItem.quantity;
|
||||||
//Cap the numberbox based on the amount we can afford.
|
//Cap the numberbox based on the amount we can afford.
|
||||||
quantity = campaign.Money <= 0 ?
|
quantity = campaign.Money <= 0 ?
|
||||||
0 : Math.Min((int)(Campaign.Money / (float)purchasedItem.itemPrefab.Price), quantity);
|
0 : Math.Min((int)(Campaign.Money / (float)purchasedItem.itemPrefab.Price), quantity);
|
||||||
for (int i = 0; i < quantity; i++)
|
for (int i = 0; i < quantity; i++)
|
||||||
{
|
{
|
||||||
BuyItem(numberInput, purchasedItem);
|
BuyItem(numberInput, purchasedItem);
|
||||||
}
|
}
|
||||||
numberInput.IntValue = purchasedItem.quantity;
|
numberInput.IntValue = purchasedItem.quantity;
|
||||||
}
|
}
|
||||||
//Attempting to sell
|
//Attempting to sell
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int quantity = purchasedItem.quantity - numberInput.IntValue;
|
int quantity = purchasedItem.quantity - numberInput.IntValue;
|
||||||
for (int i = 0; i < quantity; i++)
|
for (int i = 0; i < quantity; i++)
|
||||||
{
|
{
|
||||||
SellItem(numberInput, purchasedItem);
|
SellItem(numberInput, purchasedItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool BuyItem(GUIComponent component, object obj)
|
|
||||||
{
|
|
||||||
PurchasedItem pi = obj as PurchasedItem;
|
|
||||||
if (pi == null || pi.itemPrefab == null) return false;
|
|
||||||
|
|
||||||
if (GameMain.Client != null && !GameMain.Client.HasPermission(Networking.ClientPermissions.ManageCampaign))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pi.itemPrefab.Price > campaign.Money) return false;
|
|
||||||
|
|
||||||
campaign.CargoManager.PurchaseItem(pi.itemPrefab, 1);
|
|
||||||
GameMain.Client?.SendCampaignState();
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool SellItem(GUIComponent component, object obj)
|
|
||||||
{
|
|
||||||
PurchasedItem pi = obj as PurchasedItem;
|
|
||||||
if (pi == null || pi.itemPrefab == null) return false;
|
|
||||||
|
|
||||||
if (GameMain.Client != null && !GameMain.Client.HasPermission(Networking.ClientPermissions.ManageCampaign))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
campaign.CargoManager.SellItem(pi.itemPrefab,1);
|
|
||||||
GameMain.Client?.SendCampaignState();
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void RefreshItemTab()
|
|
||||||
{
|
|
||||||
selectedItemList.ClearChildren();
|
|
||||||
foreach (PurchasedItem pi in campaign.CargoManager.PurchasedItems)
|
|
||||||
{
|
|
||||||
CreateItemFrame(pi, selectedItemList, selectedItemList.Rect.Width);
|
|
||||||
}
|
}
|
||||||
selectedItemList.children.Sort((x, y) => (x.UserData as PurchasedItem).itemPrefab.Name.CompareTo((y.UserData as PurchasedItem).itemPrefab.Name));
|
}
|
||||||
selectedItemList.children.Sort((x, y) => (x.UserData as PurchasedItem).itemPrefab.Category.CompareTo((y.UserData as PurchasedItem).itemPrefab.Category));
|
|
||||||
selectedItemList.UpdateScrollBarSize();
|
private bool BuyItem(GUIComponent component, object obj)
|
||||||
}
|
{
|
||||||
|
PurchasedItem pi = obj as PurchasedItem;
|
||||||
public void SelectTab(Tab tab)
|
if (pi == null || pi.itemPrefab == null) return false;
|
||||||
{
|
|
||||||
selectedTab = tab;
|
if (GameMain.Client != null && !GameMain.Client.HasPermission(Networking.ClientPermissions.ManageCampaign))
|
||||||
for (int i = 0; i< tabs.Length; i++)
|
{
|
||||||
{
|
return false;
|
||||||
tabs[i].Visible = (int)selectedTab == i;
|
}
|
||||||
}
|
|
||||||
}
|
if (pi.itemPrefab.Price > campaign.Money) return false;
|
||||||
|
|
||||||
private bool SelectItemCategory(GUIButton button, object selection)
|
campaign.CargoManager.PurchaseItem(pi.itemPrefab, 1);
|
||||||
{
|
GameMain.Client?.SendCampaignState();
|
||||||
if (!(selection is MapEntityCategory)) return false;
|
|
||||||
|
return false;
|
||||||
storeItemList.ClearChildren();
|
}
|
||||||
|
|
||||||
MapEntityCategory category = (MapEntityCategory)selection;
|
private bool SellItem(GUIComponent component, object obj)
|
||||||
var items = MapEntityPrefab.List.FindAll(ep => ep.Price > 0.0f && ep.Category.HasFlag(category) && ep is ItemPrefab);
|
{
|
||||||
|
PurchasedItem pi = obj as PurchasedItem;
|
||||||
int width = storeItemList.Rect.Width;
|
if (pi == null || pi.itemPrefab == null) return false;
|
||||||
|
|
||||||
foreach (ItemPrefab ep in items)
|
if (GameMain.Client != null && !GameMain.Client.HasPermission(Networking.ClientPermissions.ManageCampaign))
|
||||||
{
|
{
|
||||||
CreateItemFrame(new PurchasedItem((ItemPrefab)ep,0), storeItemList, width);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
storeItemList.children.Sort((x, y) => (x.UserData as PurchasedItem).itemPrefab.Name.CompareTo((y.UserData as PurchasedItem).itemPrefab.Name));
|
campaign.CargoManager.SellItem(pi.itemPrefab,1);
|
||||||
|
GameMain.Client?.SendCampaignState();
|
||||||
foreach (GUIComponent child in button.Parent.children)
|
|
||||||
{
|
return false;
|
||||||
var otherButton = child as GUIButton;
|
}
|
||||||
if (child.UserData is MapEntityCategory && otherButton != button)
|
|
||||||
{
|
private void RefreshItemTab()
|
||||||
otherButton.Selected = false;
|
{
|
||||||
}
|
selectedItemList.ClearChildren();
|
||||||
}
|
foreach (PurchasedItem pi in campaign.CargoManager.PurchasedItems)
|
||||||
|
{
|
||||||
button.Selected = true;
|
CreateItemFrame(pi, selectedItemList, selectedItemList.Rect.Width);
|
||||||
return true;
|
}
|
||||||
}
|
selectedItemList.children.Sort((x, y) => (x.UserData as PurchasedItem).itemPrefab.Name.CompareTo((y.UserData as PurchasedItem).itemPrefab.Name));
|
||||||
|
selectedItemList.children.Sort((x, y) => (x.UserData as PurchasedItem).itemPrefab.Category.CompareTo((y.UserData as PurchasedItem).itemPrefab.Category));
|
||||||
public string GetMoney()
|
selectedItemList.UpdateScrollBarSize();
|
||||||
{
|
}
|
||||||
return TextManager.Get("Credits") + ": " + ((GameMain.GameSession == null) ? "0" : string.Format(CultureInfo.InvariantCulture, "{0:N0}", campaign.Money));
|
|
||||||
}
|
public void SelectTab(Tab tab)
|
||||||
|
{
|
||||||
private bool SelectCharacter(GUIComponent component, object selection)
|
selectedTab = tab;
|
||||||
{
|
for (int i = 0; i< tabs.Length; i++)
|
||||||
GUIComponent prevInfoFrame = null;
|
{
|
||||||
foreach (GUIComponent child in tabs[(int)selectedTab].children)
|
tabs[i].Visible = (int)selectedTab == i;
|
||||||
{
|
}
|
||||||
if (!(child.UserData is CharacterInfo)) continue;
|
}
|
||||||
|
|
||||||
prevInfoFrame = child;
|
private bool SelectItemCategory(GUIButton button, object selection)
|
||||||
}
|
{
|
||||||
|
if (!(selection is MapEntityCategory)) return false;
|
||||||
if (prevInfoFrame != null) tabs[(int)selectedTab].RemoveChild(prevInfoFrame);
|
|
||||||
|
storeItemList.ClearChildren();
|
||||||
CharacterInfo characterInfo = selection as CharacterInfo;
|
|
||||||
if (characterInfo == null) return false;
|
MapEntityCategory category = (MapEntityCategory)selection;
|
||||||
|
var items = MapEntityPrefab.List.FindAll(ep => ep.Price > 0.0f && ep.Category.HasFlag(category) && ep is ItemPrefab);
|
||||||
characterList.Deselect();
|
|
||||||
hireList.Deselect();
|
int width = storeItemList.Rect.Width;
|
||||||
|
|
||||||
if (Character.Controlled != null && characterInfo == Character.Controlled.Info) return false;
|
foreach (ItemPrefab ep in items)
|
||||||
|
{
|
||||||
if (characterPreviewFrame == null || characterPreviewFrame.UserData != characterInfo)
|
CreateItemFrame(new PurchasedItem((ItemPrefab)ep,0), storeItemList, width);
|
||||||
{
|
}
|
||||||
int width = Math.Min(300, tabs[(int)Tab.Crew].Rect.Width - hireList.Rect.Width - characterList.Rect.Width - 50);
|
|
||||||
|
storeItemList.children.Sort((x, y) => (x.UserData as PurchasedItem).itemPrefab.Name.CompareTo((y.UserData as PurchasedItem).itemPrefab.Name));
|
||||||
characterPreviewFrame = new GUIFrame(new Rectangle(0, 60, width, 300),
|
|
||||||
new Color(0.0f, 0.0f, 0.0f, 0.8f),
|
foreach (GUIComponent child in button.Parent.children)
|
||||||
Alignment.TopCenter, "", tabs[(int)selectedTab]);
|
{
|
||||||
characterPreviewFrame.Padding = new Vector4(20.0f, 20.0f, 20.0f, 20.0f);
|
var otherButton = child as GUIButton;
|
||||||
characterPreviewFrame.UserData = characterInfo;
|
if (child.UserData is MapEntityCategory && otherButton != button)
|
||||||
|
{
|
||||||
characterInfo.CreateInfoFrame(characterPreviewFrame);
|
otherButton.Selected = false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (component.Parent == hireList)
|
|
||||||
{
|
button.Selected = true;
|
||||||
GUIButton hireButton = new GUIButton(new Rectangle(0, 0, 100, 20), TextManager.Get("HireButton"), Alignment.BottomCenter, "", characterPreviewFrame);
|
return true;
|
||||||
hireButton.Enabled = campaign.Money >= characterInfo.Salary;
|
}
|
||||||
hireButton.UserData = characterInfo;
|
|
||||||
hireButton.OnClicked = HireCharacter;
|
public string GetMoney()
|
||||||
}
|
{
|
||||||
|
return TextManager.Get("Credits") + ": " + ((GameMain.GameSession == null) ? "0" : string.Format(CultureInfo.InvariantCulture, "{0:N0}", campaign.Money));
|
||||||
return true;
|
}
|
||||||
}
|
|
||||||
|
private bool SelectCharacter(GUIComponent component, object selection)
|
||||||
private bool HireCharacter(GUIButton button, object selection)
|
{
|
||||||
{
|
GUIComponent prevInfoFrame = null;
|
||||||
CharacterInfo characterInfo = selection as CharacterInfo;
|
foreach (GUIComponent child in tabs[(int)selectedTab].children)
|
||||||
if (characterInfo == null) return false;
|
{
|
||||||
|
if (!(child.UserData is CharacterInfo)) continue;
|
||||||
SinglePlayerCampaign spCampaign = campaign as SinglePlayerCampaign;
|
|
||||||
if (spCampaign == null)
|
prevInfoFrame = child;
|
||||||
{
|
}
|
||||||
DebugConsole.ThrowError("Characters can only be hired in the single player campaign.\n" + Environment.StackTrace);
|
|
||||||
return false;
|
if (prevInfoFrame != null) tabs[(int)selectedTab].RemoveChild(prevInfoFrame);
|
||||||
}
|
|
||||||
|
CharacterInfo characterInfo = selection as CharacterInfo;
|
||||||
if (spCampaign.TryHireCharacter(GameMain.GameSession.Map.CurrentLocation.HireManager, characterInfo))
|
if (characterInfo == null) return false;
|
||||||
{
|
|
||||||
UpdateLocationTab(GameMain.GameSession.Map.CurrentLocation);
|
characterList.Deselect();
|
||||||
SelectCharacter(null, null);
|
hireList.Deselect();
|
||||||
UpdateCharacterLists();
|
|
||||||
}
|
if (Character.Controlled != null && characterInfo == Character.Controlled.Info) return false;
|
||||||
|
|
||||||
return false;
|
if (characterPreviewFrame == null || characterPreviewFrame.UserData != characterInfo)
|
||||||
}
|
{
|
||||||
|
int width = Math.Min(300, tabs[(int)Tab.Crew].Rect.Width - hireList.Rect.Width - characterList.Rect.Width - 50);
|
||||||
|
|
||||||
}
|
characterPreviewFrame = new GUIFrame(new Rectangle(0, 60, width, 300),
|
||||||
}
|
new Color(0.0f, 0.0f, 0.0f, 0.8f),
|
||||||
|
Alignment.TopCenter, "", tabs[(int)selectedTab]);
|
||||||
|
characterPreviewFrame.Padding = new Vector4(20.0f, 20.0f, 20.0f, 20.0f);
|
||||||
|
characterPreviewFrame.UserData = characterInfo;
|
||||||
|
|
||||||
|
characterInfo.CreateInfoFrame(characterPreviewFrame);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (component.Parent == hireList)
|
||||||
|
{
|
||||||
|
GUIButton hireButton = new GUIButton(new Rectangle(0, 0, 100, 20), TextManager.Get("HireButton"), Alignment.BottomCenter, "", characterPreviewFrame);
|
||||||
|
hireButton.Enabled = campaign.Money >= characterInfo.Salary;
|
||||||
|
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;
|
||||||
|
|
||||||
|
SinglePlayerCampaign spCampaign = campaign as SinglePlayerCampaign;
|
||||||
|
if (spCampaign == null)
|
||||||
|
{
|
||||||
|
DebugConsole.ThrowError("Characters can only be hired in the single player campaign.\n" + Environment.StackTrace);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (spCampaign.TryHireCharacter(GameMain.GameSession.Map.CurrentLocation.HireManager, characterInfo))
|
||||||
|
{
|
||||||
|
UpdateLocationTab(GameMain.GameSession.Map.CurrentLocation);
|
||||||
|
SelectCharacter(null, null);
|
||||||
|
UpdateCharacterLists();
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,12 +1,12 @@
|
|||||||
using Barotrauma.Items.Components;
|
using Barotrauma.Items.Components;
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace Barotrauma
|
namespace Barotrauma
|
||||||
{
|
{
|
||||||
class PurchasedItem
|
class PurchasedItem
|
||||||
{
|
{
|
||||||
public ItemPrefab itemPrefab;
|
public ItemPrefab itemPrefab;
|
||||||
public int quantity;
|
public int quantity;
|
||||||
@@ -16,140 +16,140 @@ namespace Barotrauma
|
|||||||
this.itemPrefab = itemPrefab;
|
this.itemPrefab = itemPrefab;
|
||||||
this.quantity = quantity;
|
this.quantity = quantity;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class CargoManager
|
class CargoManager
|
||||||
{
|
{
|
||||||
private readonly List<PurchasedItem> purchasedItems;
|
private readonly List<PurchasedItem> purchasedItems;
|
||||||
|
|
||||||
private readonly CampaignMode campaign;
|
private readonly CampaignMode campaign;
|
||||||
|
|
||||||
public Action OnItemsChanged;
|
public Action OnItemsChanged;
|
||||||
|
|
||||||
public List<PurchasedItem> PurchasedItems
|
public List<PurchasedItem> PurchasedItems
|
||||||
{
|
{
|
||||||
get { return purchasedItems; }
|
get { return purchasedItems; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public CargoManager(CampaignMode campaign)
|
public CargoManager(CampaignMode campaign)
|
||||||
{
|
{
|
||||||
purchasedItems = new List<PurchasedItem>();
|
purchasedItems = new List<PurchasedItem>();
|
||||||
this.campaign = campaign;
|
this.campaign = campaign;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetPurchasedItems(List<PurchasedItem> items)
|
public void SetPurchasedItems(List<PurchasedItem> items)
|
||||||
{
|
{
|
||||||
purchasedItems.Clear();
|
purchasedItems.Clear();
|
||||||
purchasedItems.AddRange(items);
|
purchasedItems.AddRange(items);
|
||||||
|
|
||||||
OnItemsChanged?.Invoke();
|
OnItemsChanged?.Invoke();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void PurchaseItem(ItemPrefab item, int Quantity = 1)
|
public void PurchaseItem(ItemPrefab item, int Quantity = 1)
|
||||||
{
|
{
|
||||||
PurchasedItem purchasedItem = PurchasedItems.Find(pi => pi.itemPrefab == item);
|
PurchasedItem purchasedItem = PurchasedItems.Find(pi => pi.itemPrefab == item);
|
||||||
|
|
||||||
if(purchasedItem != null && Quantity == 1)
|
if(purchasedItem != null && Quantity == 1)
|
||||||
{
|
{
|
||||||
campaign.Money -= item.Price;
|
campaign.Money -= item.Price;
|
||||||
purchasedItem.quantity += 1;
|
purchasedItem.quantity += 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
campaign.Money -= (item.Price * Quantity);
|
campaign.Money -= (item.Price * Quantity);
|
||||||
purchasedItem = new PurchasedItem(item, Quantity);
|
purchasedItem = new PurchasedItem(item, Quantity);
|
||||||
purchasedItems.Add(purchasedItem);
|
purchasedItems.Add(purchasedItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
OnItemsChanged?.Invoke();
|
OnItemsChanged?.Invoke();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SellItem(ItemPrefab item, int quantity = 1)
|
public void SellItem(ItemPrefab item, int quantity = 1)
|
||||||
{
|
{
|
||||||
campaign.Money += (item.Price * quantity);
|
campaign.Money += (item.Price * quantity);
|
||||||
PurchasedItem purchasedItem = PurchasedItems.Find(pi => pi.itemPrefab == item);
|
PurchasedItem purchasedItem = PurchasedItems.Find(pi => pi.itemPrefab == item);
|
||||||
if (purchasedItem != null && purchasedItem.quantity - quantity > 0)
|
if (purchasedItem != null && purchasedItem.quantity - quantity > 0)
|
||||||
{
|
{
|
||||||
purchasedItem.quantity -= quantity;
|
purchasedItem.quantity -= quantity;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
PurchasedItems.Remove(purchasedItem);
|
PurchasedItems.Remove(purchasedItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
OnItemsChanged?.Invoke();
|
OnItemsChanged?.Invoke();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int GetTotalItemCost()
|
public int GetTotalItemCost()
|
||||||
{
|
{
|
||||||
return purchasedItems.Sum(i => (i.itemPrefab.Price * i.quantity));
|
return purchasedItems.Sum(i => (i.itemPrefab.Price * i.quantity));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CreateItems()
|
public void CreateItems()
|
||||||
{
|
{
|
||||||
CreateItems(purchasedItems);
|
CreateItems(purchasedItems);
|
||||||
OnItemsChanged?.Invoke();
|
OnItemsChanged?.Invoke();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void CreateItems(List<PurchasedItem> itemsToSpawn)
|
public static void CreateItems(List<PurchasedItem> itemsToSpawn)
|
||||||
{
|
{
|
||||||
WayPoint wp = WayPoint.GetRandom(SpawnType.Cargo, null, Submarine.MainSub);
|
WayPoint wp = WayPoint.GetRandom(SpawnType.Cargo, null, Submarine.MainSub);
|
||||||
|
|
||||||
if (wp == null)
|
if (wp == null)
|
||||||
{
|
{
|
||||||
DebugConsole.ThrowError("The submarine must have a waypoint marked as Cargo for bought items to be placed correctly!");
|
DebugConsole.ThrowError("The submarine must have a waypoint marked as Cargo for bought items to be placed correctly!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Hull cargoRoom = Hull.FindHull(wp.WorldPosition);
|
Hull cargoRoom = Hull.FindHull(wp.WorldPosition);
|
||||||
|
|
||||||
if (cargoRoom == null)
|
if (cargoRoom == null)
|
||||||
{
|
{
|
||||||
DebugConsole.ThrowError("A waypoint marked as Cargo must be placed inside a room!");
|
DebugConsole.ThrowError("A waypoint marked as Cargo must be placed inside a room!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Dictionary<ItemContainer, int> availableContainers = new Dictionary<ItemContainer, int>();
|
Dictionary<ItemContainer, int> availableContainers = new Dictionary<ItemContainer, int>();
|
||||||
ItemPrefab containerPrefab = null;
|
ItemPrefab containerPrefab = null;
|
||||||
foreach (PurchasedItem pi in itemsToSpawn)
|
foreach (PurchasedItem pi in itemsToSpawn)
|
||||||
{
|
{
|
||||||
Vector2 position = new Vector2(
|
Vector2 position = new Vector2(
|
||||||
Rand.Range(cargoRoom.Rect.X + 20, cargoRoom.Rect.Right - 20),
|
Rand.Range(cargoRoom.Rect.X + 20, cargoRoom.Rect.Right - 20),
|
||||||
cargoRoom.Rect.Y - cargoRoom.Rect.Height + pi.itemPrefab.Size.Y / 2);
|
cargoRoom.Rect.Y - cargoRoom.Rect.Height + pi.itemPrefab.Size.Y / 2);
|
||||||
|
|
||||||
ItemContainer itemContainer = null;
|
ItemContainer itemContainer = null;
|
||||||
if (!string.IsNullOrEmpty(pi.itemPrefab.CargoContainerName))
|
if (!string.IsNullOrEmpty(pi.itemPrefab.CargoContainerName))
|
||||||
{
|
{
|
||||||
itemContainer = availableContainers.Keys.ToList().Find(ac =>
|
itemContainer = availableContainers.Keys.ToList().Find(ac =>
|
||||||
ac.Item.Prefab.NameMatches(pi.itemPrefab.CargoContainerName) ||
|
ac.Item.Prefab.NameMatches(pi.itemPrefab.CargoContainerName) ||
|
||||||
ac.Item.Prefab.Tags.Contains(pi.itemPrefab.CargoContainerName.ToLowerInvariant()));
|
ac.Item.Prefab.Tags.Contains(pi.itemPrefab.CargoContainerName.ToLowerInvariant()));
|
||||||
|
|
||||||
if (itemContainer == null)
|
if (itemContainer == null)
|
||||||
{
|
{
|
||||||
containerPrefab = MapEntityPrefab.List.Find(ep =>
|
containerPrefab = MapEntityPrefab.List.Find(ep =>
|
||||||
ep.NameMatches(pi.itemPrefab.CargoContainerName) ||
|
ep.NameMatches(pi.itemPrefab.CargoContainerName) ||
|
||||||
(ep.Tags != null && ep.Tags.Contains(pi.itemPrefab.CargoContainerName.ToLowerInvariant()))) as ItemPrefab;
|
(ep.Tags != null && ep.Tags.Contains(pi.itemPrefab.CargoContainerName.ToLowerInvariant()))) as ItemPrefab;
|
||||||
|
|
||||||
if (containerPrefab == null)
|
if (containerPrefab == null)
|
||||||
{
|
{
|
||||||
DebugConsole.ThrowError("Cargo spawning failed - could not find the item prefab for container \"" + containerPrefab.Name + "\"!");
|
DebugConsole.ThrowError("Cargo spawning failed - could not find the item prefab for container \"" + containerPrefab.Name + "\"!");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Item containerItem = new Item(containerPrefab, position, wp.Submarine);
|
Item containerItem = new Item(containerPrefab, position, wp.Submarine);
|
||||||
itemContainer = containerItem.GetComponent<ItemContainer>();
|
itemContainer = containerItem.GetComponent<ItemContainer>();
|
||||||
if (itemContainer == null)
|
if (itemContainer == null)
|
||||||
{
|
{
|
||||||
DebugConsole.ThrowError("Cargo spawning failed - container \"" + containerItem.Name + "\" does not have an ItemContainer component!");
|
DebugConsole.ThrowError("Cargo spawning failed - container \"" + containerItem.Name + "\" does not have an ItemContainer component!");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
availableContainers.Add(itemContainer, itemContainer.Capacity);
|
availableContainers.Add(itemContainer, itemContainer.Capacity);
|
||||||
if (GameMain.Server != null)
|
if (GameMain.Server != null)
|
||||||
{
|
{
|
||||||
Entity.Spawner.CreateNetworkEvent(itemContainer.Item, false);
|
Entity.Spawner.CreateNetworkEvent(itemContainer.Item, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (int i = 0; i < pi.quantity; i++)
|
for (int i = 0; i < pi.quantity; i++)
|
||||||
{
|
{
|
||||||
if (itemContainer == null)
|
if (itemContainer == null)
|
||||||
@@ -199,9 +199,9 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
availableContainers.Remove(itemContainer);
|
availableContainers.Remove(itemContainer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
itemsToSpawn.Clear();
|
itemsToSpawn.Clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user