public CampaignUI(CampaignMode campaign, GUIComponent container) { Campaign = campaign; if (campaign.Map == null) { throw new InvalidOperationException("Failed to create campaign UI (campaign map was null)."); } if (campaign.Map.CurrentLocation == null) { throw new InvalidOperationException("Failed to create campaign UI (current location not set)."); } CreateUI(container); campaign.Map.OnLocationSelected += SelectLocation; campaign.Map.OnMissionsSelected += (connection, missions) => { if (missionList?.Content != null) { foreach (GUIComponent missionElement in missionList.Content.Children) { if (missionElement.FindChild(c => c is GUITickBox, recursive: true) is GUITickBox tickBox) { tickBox.Selected = missions.Contains(tickBox.UserData as Mission); } } } }; }
private bool?TryFloat(CampaignMode campaignMode, string value) { if (float.TryParse(value, out float f)) { float target = GetFloat(campaignMode); value1 = target; value2 = f; switch (Operator) { case PropertyConditional.OperatorType.Equals: return(MathUtils.NearlyEqual(target, f)); case PropertyConditional.OperatorType.GreaterThan: return(target > f); case PropertyConditional.OperatorType.GreaterThanEquals: return(target >= f); case PropertyConditional.OperatorType.LessThan: return(target < f); case PropertyConditional.OperatorType.LessThanEquals: return(target <= f); case PropertyConditional.OperatorType.NotEquals: return(!MathUtils.NearlyEqual(target, f)); } } DebugConsole.Log($"{value} != float"); return(null); }
/// <summary> /// Generate a new campaign map from the seed /// </summary> public Map(CampaignMode campaign, string seed) : this() { Seed = seed; Rand.SetSyncedSeed(ToolBox.StringToInt(Seed)); Generate(); if (Locations.Count == 0) { throw new Exception($"Generating a campaign map failed (no locations created). Width: {Width}, height: {Height}"); } for (int i = 0; i < Locations.Count; i++) { Locations[i].Reputation ??= new Reputation(campaign.CampaignMetadata, $"location.{i}", -100, 100, Rand.Range(-10, 10, Rand.RandSync.Server)); } foreach (Location location in Locations) { if (!location.Type.Identifier.Equals("city", StringComparison.OrdinalIgnoreCase) && !location.Type.Identifier.Equals("outpost", StringComparison.OrdinalIgnoreCase)) { continue; } if (CurrentLocation == null || location.MapPosition.X < CurrentLocation.MapPosition.X) { CurrentLocation = StartLocation = furthestDiscoveredLocation = location; } } CurrentLocation.CreateStore(); CurrentLocation.Discovered = true; InitProjectSpecific(); }
protected override float GetFloat(CampaignMode campaignMode) { switch (TargetType) { case ReputationAction.ReputationType.Faction: { Faction?faction = campaignMode.Factions.Find(f => f.Prefab.Identifier.Equals(Identifier, StringComparison.OrdinalIgnoreCase)); if (faction != null) { return(faction.Reputation.Value); } break; } case ReputationAction.ReputationType.Location: { Location?location = campaignMode.Map.CurrentLocation; Debug.Assert(location?.Reputation != null, "location?.Reputation != null"); if (location?.Reputation != null) { return(location.Reputation.Value); } break; } default: { DebugConsole.ThrowError("CheckReputationAction requires a \"TargetType\" but none were specified."); break; } } return(0.0f); }
/// <summary> /// Load a previously saved map from an xml element /// </summary> public static Map Load(CampaignMode campaign, XElement element) { Map map = new Map(campaign, element); map.LoadState(element, false); #if CLIENT map.DrawOffset = -map.CurrentLocation.MapPosition; #endif return(map); }
public CampaignMetadata(CampaignMode campaign, XElement element) { Campaign = campaign; foreach (XElement subElement in element.Elements()) { if (string.Equals(subElement.Name.ToString(), "data", StringComparison.InvariantCultureIgnoreCase)) { string identifier = subElement.GetAttributeString("key", string.Empty).ToLowerInvariant(); string value = subElement.GetAttributeString("value", string.Empty); string valueType = subElement.GetAttributeString("type", string.Empty); if (string.IsNullOrWhiteSpace(identifier) || string.IsNullOrWhiteSpace(value) || string.IsNullOrWhiteSpace(valueType)) { DebugConsole.ThrowError("Unable to load value because one or more of the required attributes are empty.\n" + $"key: \"{identifier}\", value: \"{value}\", type: \"{valueType}\""); continue; } Type?type = Type.GetType(valueType); if (type == null) { DebugConsole.ThrowError($"Type for {identifier} not found ({valueType})."); continue; } if (type == typeof(float)) { if (!float.TryParse(value, NumberStyles.Float, CultureInfo.InvariantCulture, out float floatValue)) { DebugConsole.ThrowError($"Error in campaign metadata: could not parse \"{value}\" as a float."); continue; } data.Add(identifier, floatValue); } else { data.Add(identifier, Convert.ChangeType(value, type)); } } } }
public override void Select() { base.Select(); CampaignMode campaign = GameMain.GameSession.GameMode as CampaignMode; if (campaign == null) { return; } locationTitle.Text = "Location: " + campaign.Map.CurrentLocation.Name; bottomPanel.ClearChildren(); campaignUI = new CampaignUI(campaign, bottomPanel); campaignUI.StartRound = StartRound; campaignUI.OnLocationSelected = SelectLocation; campaignUI.UpdateCharacterLists(); }
public CampaignUI(CampaignMode campaign, GUIComponent container) { Campaign = campaign; if (campaign.Map == null) { throw new InvalidOperationException("Failed to create campaign UI (campaign map was null)."); } if (campaign.Map.CurrentLocation == null) { throw new InvalidOperationException("Failed to create campaign UI (current location not set)."); } CreateUI(container); campaign.Map.OnLocationSelected += SelectLocation; campaign.Map.OnMissionSelected += (connection, mission) => { missionList.Select(mission); }; }
public override void Select() { base.Select(); CampaignMode campaign = GameMain.GameSession.GameMode as CampaignMode; if (campaign == null) { return; } locationTitle.Text = TextManager.Get("Location") + ": " + campaign.Map.CurrentLocation.Name; bottomPanel.ClearChildren(); campaignUI = new CampaignUI(campaign, bottomPanel); campaignUI.StartRound = StartRound; campaignUI.OnLocationSelected = SelectLocation; campaignUI.UpdateCharacterLists(); GameAnalyticsManager.SetCustomDimension01("singleplayer"); }
public override void Select() { base.Select(); CampaignMode campaign = GameMain.GameSession.GameMode as CampaignMode; if (campaign == null) { return; } campaign.Map.SelectLocation(-1); campaignUIContainer.ClearChildren(); campaignUI = new CampaignUI(campaign, campaignUIContainer) { StartRound = StartRound, OnLocationSelected = SelectLocation }; campaignUI.UpdateCharacterLists(); GameAnalyticsManager.SetCustomDimension01("singleplayer"); }
public UpgradeManager(CampaignMode campaign, XElement element, bool isSingleplayer) : this(campaign) { DebugConsole.Log($"Restored upgrade manager from save file, ({element.Elements().Count()} pending upgrades)."); //backwards compatibility: //upgrades used to be saved to a <pendingupgrades> element, now upgrades and item swaps are saved separately under a <upgrademanager> element if (element.Name.LocalName.Equals("pendingupgrades", StringComparison.OrdinalIgnoreCase)) { LoadPendingUpgrades(element, isSingleplayer); } else { foreach (XElement subElement in element.Elements()) { switch (subElement.Name.ToString().ToLowerInvariant()) { case "pendingupgrades": LoadPendingUpgrades(subElement, isSingleplayer); break; } } } }
public static void PlaceIfNeeded(GameMode gameMode) { if (GameMain.NetworkMember != null && !GameMain.NetworkMember.IsServer) { return; } CampaignMode campaign = gameMode as CampaignMode; if (campaign == null || !campaign.InitialSuppliesSpawned) { for (int i = 0; i < Submarine.MainSubs.Length; i++) { if (Submarine.MainSubs[i] == null) { continue; } List <Submarine> subs = new List <Submarine>() { Submarine.MainSubs[i] }; subs.AddRange(Submarine.MainSubs[i].DockedTo.Where(d => !d.Info.IsOutpost)); Place(subs); } if (campaign != null) { campaign.InitialSuppliesSpawned = true; } } foreach (var wreck in Submarine.Loaded) { if (wreck.Info.IsWreck) { Place(wreck.ToEnumerable()); } } }
private bool?TryBoolean(CampaignMode campaignMode, string value) { if (bool.TryParse(value, out bool b)) { bool target = GetBool(campaignMode); value1 = target; value2 = b; switch (Operator) { case PropertyConditional.OperatorType.Equals: return(target == b); case PropertyConditional.OperatorType.NotEquals: return(target != b); default: DebugConsole.Log($"Only \"Equals\" and \"Not equals\" operators are allowed for a boolean (was {Operator} for {value})."); return(false); } } DebugConsole.Log($"{value} != bool"); return(null); }
/// <summary> /// Load a previously saved campaign map from XML /// </summary> private Map(CampaignMode campaign, XElement element) : this() { Seed = element.GetAttributeString("seed", "a"); Rand.SetSyncedSeed(ToolBox.StringToInt(Seed)); foreach (XElement subElement in element.Elements()) { switch (subElement.Name.ToString().ToLowerInvariant()) { case "location": int i = subElement.GetAttributeInt("i", 0); while (Locations.Count <= i) { Locations.Add(null); } Locations[i] = new Location(subElement); break; } } System.Diagnostics.Debug.Assert(!Locations.Contains(null)); for (int i = 0; i < Locations.Count; i++) { Locations[i].Reputation ??= new Reputation(campaign.CampaignMetadata, $"location.{i}", -100, 100, Rand.Range(-10, 10, Rand.RandSync.Server)); } foreach (XElement subElement in element.Elements()) { switch (subElement.Name.ToString().ToLowerInvariant()) { case "connection": Point locationIndices = subElement.GetAttributePoint("locations", new Point(0, 1)); if (locationIndices.X == locationIndices.Y) { continue; } var connection = new LocationConnection(Locations[locationIndices.X], Locations[locationIndices.Y]) { Passed = subElement.GetAttributeBool("passed", false), Difficulty = subElement.GetAttributeFloat("difficulty", 0.0f) }; Locations[locationIndices.X].Connections.Add(connection); Locations[locationIndices.Y].Connections.Add(connection); connection.LevelData = new LevelData(subElement.Element("Level")); string biomeId = subElement.GetAttributeString("biome", ""); connection.Biome = LevelGenerationParams.GetBiomes().FirstOrDefault(b => b.Identifier == biomeId) ?? LevelGenerationParams.GetBiomes().FirstOrDefault(b => b.OldIdentifier == biomeId) ?? LevelGenerationParams.GetBiomes().First(); Connections.Add(connection); break; } } int startLocationindex = element.GetAttributeInt("startlocation", -1); if (startLocationindex > 0 && startLocationindex < Locations.Count) { StartLocation = Locations[startLocationindex]; } else { DebugConsole.AddWarning($"Error while loading the map. Start location index out of bounds (index: {startLocationindex}, location count: {Locations.Count})."); foreach (Location location in Locations) { if (!location.Type.HasOutpost) { continue; } if (StartLocation == null || location.MapPosition.X < StartLocation.MapPosition.X) { StartLocation = location; } } } int endLocationindex = element.GetAttributeInt("endlocation", -1); if (endLocationindex > 0 && endLocationindex < Locations.Count) { EndLocation = Locations[endLocationindex]; } else { DebugConsole.AddWarning($"Error while loading the map. End location index out of bounds (index: {endLocationindex}, location count: {Locations.Count})."); foreach (Location location in Locations) { if (EndLocation == null || location.MapPosition.X > EndLocation.MapPosition.X) { EndLocation = location; } } } InitProjectSpecific(); }
public CargoManager(CampaignMode campaign) { purchasedItems = new List <ItemPrefab>(); this.campaign = campaign; }
public CampaignUI(CampaignMode campaign, GUIFrame container) { this.Campaign = campaign; MapContainer = new GUICustomComponent(new RectTransform(Vector2.One, container.RectTransform), DrawMap, UpdateMap); new GUIFrame(new RectTransform(Vector2.One, MapContainer.RectTransform), style: "InnerGlow", color: Color.Black * 0.9f) { CanBeFocused = false }; // top panel ------------------------------------------------------------------------- topPanel = new GUIFrame(new RectTransform(new Vector2(1.0f, 0.15f), container.RectTransform, Anchor.TopCenter), style: null) { CanBeFocused = false }; var topPanelContent = new GUIFrame(new RectTransform(new Vector2(0.95f, 0.9f), topPanel.RectTransform, Anchor.BottomCenter), style: null) { CanBeFocused = false }; var outpostBtn = new GUIButton(new RectTransform(new Vector2(0.15f, 0.55f), topPanelContent.RectTransform), TextManager.Get("Outpost"), textAlignment: Alignment.Center, style: "GUISlopedHeader") { OnClicked = (btn, userdata) => { SelectTab(Tab.Map); return(true); } }; outpostBtn.TextBlock.Font = GUI.LargeFont; outpostBtn.TextBlock.AutoScale = true; var tabButtonContainer = new GUILayoutGroup(new RectTransform(new Vector2(0.4f, 0.4f), topPanelContent.RectTransform, Anchor.BottomLeft), isHorizontal: true); int i = 0; var tabValues = Enum.GetValues(typeof(Tab)); foreach (Tab tab in tabValues) { var tabButton = new GUIButton(new RectTransform(new Vector2(0.25f, 1.0f), tabButtonContainer.RectTransform), "", style: i == 0 ? "GUISlopedTabButtonLeft" : (i == tabValues.Length - 1 ? "GUISlopedTabButtonRight" : "GUISlopedTabButtonMid")) { UserData = tab, OnClicked = (btn, userdata) => { SelectTab((Tab)userdata); return(true); }, Selected = tab == Tab.Map }; var buttonSprite = tabButton.Style.Sprites[GUIComponent.ComponentState.None][0]; tabButton.RectTransform.MaxSize = new Point( (int)(tabButton.Rect.Height * (buttonSprite.Sprite.size.X / buttonSprite.Sprite.size.Y)), int.MaxValue); //the text needs to be positioned differently in the buttons at the edges due to the "slopes" in the button if (i == 0 || i == tabValues.Length - 1) { new GUITextBlock(new RectTransform(new Vector2(0.8f, 0.9f), tabButton.RectTransform, i == 0 ? Anchor.CenterLeft : Anchor.CenterRight) { RelativeOffset = new Vector2(0.05f, 0.0f) }, TextManager.Get(tab.ToString()), textColor: tabButton.TextColor, font: GUI.LargeFont, textAlignment: Alignment.Center, style: null) { UserData = "buttontext" }; } else { new GUITextBlock(new RectTransform(new Vector2(0.7f, 0.9f), tabButton.RectTransform, Anchor.Center), TextManager.Get(tab.ToString()), textColor: tabButton.TextColor, font: GUI.LargeFont, textAlignment: Alignment.Center, style: null) { UserData = "buttontext" }; } tabButtons.Add(tabButton); i++; } GUITextBlock.AutoScaleAndNormalize(tabButtons.Select(t => t.GetChildByUserData("buttontext") as GUITextBlock)); tabButtons.FirstOrDefault().RectTransform.SizeChanged += () => { GUITextBlock.AutoScaleAndNormalize(tabButtons.Select(t => t.GetChildByUserData("buttontext") as GUITextBlock)); }; // crew tab ------------------------------------------------------------------------- tabs = new GUIFrame[Enum.GetValues(typeof(Tab)).Length]; tabs[(int)Tab.Crew] = new GUIFrame(new RectTransform(new Vector2(0.3f, 0.7f), container.RectTransform, Anchor.TopLeft) { RelativeOffset = new Vector2(0.0f, topPanel.RectTransform.RelativeSize.Y) }, color: Color.Black * 0.9f); new GUIFrame(new RectTransform(new Vector2(1.25f, 1.25f), tabs[(int)Tab.Crew].RectTransform, Anchor.Center), style: "OuterGlow", color: Color.Black * 0.7f) { CanBeFocused = false }; var crewContent = new GUILayoutGroup(new RectTransform(new Vector2(0.9f, 0.95f), tabs[(int)Tab.Crew].RectTransform, Anchor.Center)) { Stretch = true, RelativeSpacing = 0.02f }; new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.1f), crewContent.RectTransform), "", font: GUI.LargeFont) { TextGetter = GetMoney }; characterList = new GUIListBox(new RectTransform(new Vector2(1.0f, 0.9f), crewContent.RectTransform)) { OnSelected = SelectCharacter }; new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.1f), characterList.Content.RectTransform), TextManager.Get("CampaignMenuCrew"), font: GUI.LargeFont) { UserData = "mycrew", CanBeFocused = false, AutoScale = true }; if (campaign is SinglePlayerCampaign) { new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.1f), characterList.Content.RectTransform), TextManager.Get("CampaignMenuHireable"), font: GUI.LargeFont) { UserData = "hire", CanBeFocused = false, AutoScale = true }; } // store tab ------------------------------------------------------------------------- tabs[(int)Tab.Store] = new GUIFrame(new RectTransform(new Vector2(0.5f, 0.7f), container.RectTransform, Anchor.TopLeft) { RelativeOffset = new Vector2(0.1f, topPanel.RectTransform.RelativeSize.Y) }, color: Color.Black * 0.9f); new GUIFrame(new RectTransform(new Vector2(1.25f, 1.25f), tabs[(int)Tab.Store].RectTransform, Anchor.Center), style: "OuterGlow", color: Color.Black * 0.7f) { CanBeFocused = false }; List <MapEntityCategory> itemCategories = Enum.GetValues(typeof(MapEntityCategory)).Cast <MapEntityCategory>().ToList(); //don't show categories with no buyable items itemCategories.RemoveAll(c => !MapEntityPrefab.List.Any(ep => ep.Category.HasFlag(c) && (ep is ItemPrefab) && ((ItemPrefab)ep).CanBeBought)); var storeContent = new GUILayoutGroup(new RectTransform(new Vector2(0.9f, 0.9f), tabs[(int)Tab.Store].RectTransform, Anchor.Center)) { Stretch = true, RelativeSpacing = 0.02f }; var storeContentTop = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.1f), storeContent.RectTransform), isHorizontal: true, childAnchor: Anchor.CenterLeft) { Stretch = true }; new GUITextBlock(new RectTransform(new Vector2(0.5f, 1.0f), storeContentTop.RectTransform), "", font: GUI.LargeFont) { TextGetter = GetMoney }; var filterContainer = new GUILayoutGroup(new RectTransform(new Vector2(0.5f, 0.4f), storeContentTop.RectTransform), isHorizontal: true) { Stretch = true }; var searchTitle = new GUITextBlock(new RectTransform(new Vector2(0.001f, 1.0f), filterContainer.RectTransform), TextManager.Get("serverlog.filter"), textAlignment: Alignment.CenterLeft, font: GUI.Font); searchBox = new GUITextBox(new RectTransform(new Vector2(1.0f, 1.0f), filterContainer.RectTransform), font: GUI.Font); searchBox.OnSelected += (sender, userdata) => { searchTitle.Visible = false; }; searchBox.OnDeselected += (sender, userdata) => { searchTitle.Visible = true; }; searchBox.OnTextChanged += (textBox, text) => { FilterStoreItems(null, text); return(true); }; var clearButton = new GUIButton(new RectTransform(new Vector2(0.1f, 1.0f), filterContainer.RectTransform), "x") { OnClicked = (btn, userdata) => { searchBox.Text = ""; FilterStoreItems(selectedItemCategory, ""); searchBox.Flash(Color.White); return(true); } }; var storeItemLists = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.8f), storeContent.RectTransform), isHorizontal: true) { Stretch = true }; myItemList = new GUIListBox(new RectTransform(new Vector2(0.5f, 1.0f), storeItemLists.RectTransform)); storeItemList = new GUIListBox(new RectTransform(new Vector2(0.5f, 1.0f), storeItemLists.RectTransform)) { OnSelected = BuyItem }; var categoryButtonContainer = new GUILayoutGroup(new RectTransform(new Vector2(0.1f, 0.9f), tabs[(int)Tab.Store].RectTransform, Anchor.CenterLeft, Pivot.CenterRight)) { RelativeSpacing = 0.02f }; foreach (MapEntityCategory category in itemCategories) { var categoryButton = new GUIButton(new RectTransform(new Point(categoryButtonContainer.Rect.Width), categoryButtonContainer.RectTransform), "", style: "ItemCategory" + category.ToString()) { UserData = category, OnClicked = (btn, userdata) => { MapEntityCategory newCategory = (MapEntityCategory)userdata; if (newCategory != selectedItemCategory) { searchBox.Text = ""; } FilterStoreItems((MapEntityCategory)userdata, searchBox.Text); return(true); } }; itemCategoryButtons.Add(categoryButton); new GUITextBlock(new RectTransform(new Vector2(0.9f, 0.25f), categoryButton.RectTransform, Anchor.BottomCenter) { RelativeOffset = new Vector2(0.0f, 0.02f) }, TextManager.Get("MapEntityCategory." + category), textAlignment: Alignment.Center, textColor: categoryButton.TextColor) { Padding = Vector4.Zero, AutoScale = true, Color = Color.Transparent, HoverColor = Color.Transparent, PressedColor = Color.Transparent, SelectedColor = Color.Transparent, CanBeFocused = false }; } FillStoreItemList(); FilterStoreItems(MapEntityCategory.Equipment, ""); // repair tab ------------------------------------------------------------------------- tabs[(int)Tab.Repair] = new GUIFrame(new RectTransform(new Vector2(0.35f, 0.5f), container.RectTransform, Anchor.TopLeft) { RelativeOffset = new Vector2(0.02f, topPanel.RectTransform.RelativeSize.Y) }, color: Color.Black * 0.9f); new GUIFrame(new RectTransform(new Vector2(1.25f, 1.25f), tabs[(int)Tab.Repair].RectTransform, Anchor.Center), style: "OuterGlow", color: Color.Black * 0.7f) { CanBeFocused = false }; var repairContent = new GUILayoutGroup(new RectTransform(new Vector2(0.9f, 0.85f), tabs[(int)Tab.Repair].RectTransform, Anchor.Center)) { RelativeSpacing = 0.05f, Stretch = true }; new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.2f), repairContent.RectTransform), "", font: GUI.LargeFont) { TextGetter = GetMoney }; var repairHullsHolder = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.5f), repairContent.RectTransform), childAnchor: Anchor.TopRight) { RelativeSpacing = 0.05f, Stretch = true }; new GUIImage(new RectTransform(new Vector2(0.3f, 1.0f), repairHullsHolder.RectTransform, Anchor.CenterLeft), "RepairHullButton") { IgnoreLayoutGroups = true, CanBeFocused = false }; new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.3f), repairHullsHolder.RectTransform), TextManager.Get("RepairAllWalls"), textAlignment: Alignment.Right, font: GUI.LargeFont) { ForceUpperCase = true }; new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.3f), repairHullsHolder.RectTransform), "500", textAlignment: Alignment.Right, font: GUI.LargeFont); repairHullsButton = new GUIButton(new RectTransform(new Vector2(0.4f, 0.3f), repairHullsHolder.RectTransform), TextManager.Get("Repair"), style: "GUIButtonLarge") { OnClicked = (btn, userdata) => { if (campaign.PurchasedHullRepairs) { campaign.Money += CampaignMode.HullRepairCost; campaign.PurchasedHullRepairs = false; } else { if (campaign.Money >= CampaignMode.HullRepairCost) { campaign.Money -= CampaignMode.HullRepairCost; campaign.PurchasedHullRepairs = true; } } GameMain.Client?.SendCampaignState(); btn.GetChild <GUITickBox>().Selected = campaign.PurchasedHullRepairs; return(true); } }; new GUITickBox(new RectTransform(new Vector2(0.65f), repairHullsButton.RectTransform, Anchor.CenterLeft) { AbsoluteOffset = new Point(10, 0) }, "") { CanBeFocused = false }; var repairItemsHolder = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.5f), repairContent.RectTransform), childAnchor: Anchor.TopRight) { RelativeSpacing = 0.05f, Stretch = true }; new GUIImage(new RectTransform(new Vector2(0.3f, 1.0f), repairItemsHolder.RectTransform, Anchor.CenterLeft), "RepairItemsButton") { IgnoreLayoutGroups = true, CanBeFocused = false }; new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.3f), repairItemsHolder.RectTransform), TextManager.Get("RepairAllItems"), textAlignment: Alignment.Right, font: GUI.LargeFont) { ForceUpperCase = true }; new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.3f), repairItemsHolder.RectTransform), "500", textAlignment: Alignment.Right, font: GUI.LargeFont); repairItemsButton = new GUIButton(new RectTransform(new Vector2(0.4f, 0.3f), repairItemsHolder.RectTransform), TextManager.Get("Repair"), style: "GUIButtonLarge") { OnClicked = (btn, userdata) => { if (campaign.PurchasedItemRepairs) { campaign.Money += CampaignMode.ItemRepairCost; campaign.PurchasedItemRepairs = false; } else { if (campaign.Money >= CampaignMode.ItemRepairCost) { campaign.Money -= CampaignMode.ItemRepairCost; campaign.PurchasedItemRepairs = true; } } GameMain.Client?.SendCampaignState(); btn.GetChild <GUITickBox>().Selected = campaign.PurchasedItemRepairs; return(true); } }; new GUITickBox(new RectTransform(new Vector2(0.65f), repairItemsButton.RectTransform, Anchor.CenterLeft) { AbsoluteOffset = new Point(10, 0) }, "") { CanBeFocused = false }; // mission info ------------------------------------------------------------------------- missionPanel = new GUIFrame(new RectTransform(new Vector2(0.3f, 0.5f), container.RectTransform, Anchor.TopRight) { RelativeOffset = new Vector2(0.0f, topPanel.RectTransform.RelativeSize.Y) }, color: Color.Black * 0.7f) { Visible = false }; new GUIFrame(new RectTransform(new Vector2(1.25f, 1.25f), missionPanel.RectTransform, Anchor.Center), style: "OuterGlow", color: Color.Black * 0.7f) { CanBeFocused = false }; new GUITextBlock(new RectTransform(new Vector2(0.5f, 0.15f), missionPanel.RectTransform, Anchor.TopRight, Pivot.BottomRight) { RelativeOffset = new Vector2(0.1f, -0.05f) }, TextManager.Get("Mission"), textAlignment: Alignment.Center, font: GUI.LargeFont, style: "GUISlopedHeader") { AutoScale = true }; var missionPanelContent = new GUILayoutGroup(new RectTransform(new Vector2(0.95f, 0.9f), missionPanel.RectTransform, Anchor.Center)) { Stretch = true, RelativeSpacing = 0.05f }; selectedLocationInfo = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.75f), missionPanelContent.RectTransform)) { RelativeSpacing = 0.02f, Stretch = true }; selectedMissionInfo = new GUIListBox(new RectTransform(new Vector2(0.9f, 0.25f), missionPanel.RectTransform, Anchor.BottomRight, Pivot.TopRight)) { Visible = false }; // ------------------------------------------------------------------------- topPanel.RectTransform.SetAsLastChild(); SelectTab(Tab.Map); UpdateLocationView(campaign.Map.CurrentLocation); campaign.Map.OnLocationSelected += SelectLocation; campaign.Map.OnLocationChanged += (prevLocation, newLocation) => UpdateLocationView(newLocation); campaign.Map.OnMissionSelected += (connection, mission) => { var selectedTickBox = missionTickBoxes.Find(tb => tb.UserData == mission); if (selectedTickBox != null) { selectedTickBox.Selected = true; } }; campaign.CargoManager.OnItemsChanged += RefreshMyItems; }
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; if (GameMain.Client == null) { 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 = 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.OnSelected = BuyItem; int x = storeItemList.Rect.X - storeItemList.Parent.Rect.X; List <MapEntityCategory> itemCategories = Enum.GetValues(typeof(MapEntityCategory)).Cast <MapEntityCategory>().ToList(); //don't show categories with no buyable items itemCategories.RemoveAll(c => !MapEntityPrefab.list.Any(ep => ep.Price > 0.0f && ep.Category.HasFlag(c))); int buttonWidth = Math.Min(sellColumnWidth / itemCategories.Count, 100); foreach (MapEntityCategory category in itemCategories) { var categoryButton = new GUIButton(new Rectangle(x, 0, buttonWidth, 20), category.ToString(), "", tabs[(int)Tab.Store]); categoryButton.UserData = category; categoryButton.OnClicked = SelectItemCategory; if (category == MapEntityCategory.Equipment) { SelectItemCategory(categoryButton, category); } x += buttonWidth; } SelectTab(Tab.Map); UpdateLocationTab(campaign.Map.CurrentLocation); campaign.Map.OnLocationSelected += SelectLocation; campaign.Map.OnLocationChanged += (location) => UpdateLocationTab(location); campaign.CargoManager.OnItemsChanged += RefreshItemTab; }
public void CreateReputationInfoPanel(GUIComponent parent, CampaignMode campaignMode) { GUIListBox reputationList = new GUIListBox(new RectTransform(Vector2.One, parent.RectTransform)) { Padding = new Vector4(4, 10, 0, 0) * GUI.Scale }; reputationList.ContentBackground.Color = Color.Transparent; if (startLocation.Type.HasOutpost && startLocation.Reputation != null) { var iconStyle = GUI.Style.GetComponentStyle("LocationReputationIcon"); var locationFrame = CreateReputationElement( reputationList.Content, startLocation.Name, startLocation.Reputation.Value, startLocation.Reputation.NormalizedValue, initialLocationReputation, startLocation.Type.Name, "", iconStyle?.GetDefaultSprite(), startLocation.Type.GetPortrait(0), iconStyle?.Color ?? Color.White); CreatePathUnlockElement(locationFrame, null, startLocation); } foreach (Faction faction in campaignMode.Factions) { float initialReputation = faction.Reputation.Value; if (initialFactionReputations.ContainsKey(faction)) { initialReputation = initialFactionReputations[faction]; } else { DebugConsole.AddWarning($"Could not determine reputation change for faction \"{faction.Prefab.Name}\" (faction was not present at the start of the round)."); } var factionFrame = CreateReputationElement( reputationList.Content, faction.Prefab.Name, faction.Reputation.Value, faction.Reputation.NormalizedValue, initialReputation, faction.Prefab.ShortDescription, faction.Prefab.Description, faction.Prefab.Icon, faction.Prefab.BackgroundPortrait, faction.Prefab.IconColor); CreatePathUnlockElement(factionFrame, faction, null); } float maxDescriptionHeight = 0.0f; foreach (GUIComponent child in reputationList.Content.Children) { var descriptionElement = child.FindChild("description", recursive: true) as GUITextBlock; maxDescriptionHeight = Math.Max(maxDescriptionHeight, descriptionElement.TextSize.Y * 1.1f); } foreach (GUIComponent child in reputationList.Content.Children) { var headerElement = child.FindChild("header", recursive: true) as GUITextBlock; var descriptionElement = child.FindChild("description", recursive: true) as GUITextBlock; descriptionElement.RectTransform.NonScaledSize = new Point(descriptionElement.Rect.Width, (int)maxDescriptionHeight); descriptionElement.RectTransform.IsFixedSize = true; child.RectTransform.NonScaledSize = new Point(child.Rect.Width, headerElement.Rect.Height + descriptionElement.RectTransform.Parent.Children.Sum(c => c.Rect.Height + ((GUILayoutGroup)descriptionElement.Parent).AbsoluteSpacing)); } void CreatePathUnlockElement(GUIComponent reputationFrame, Faction faction, Location location) { if (GameMain.GameSession?.Campaign?.Map != null) { foreach (LocationConnection connection in GameMain.GameSession.Campaign.Map.Connections) { if (!connection.Locked || (!connection.Locations[0].Discovered && !connection.Locations[1].Discovered)) { continue; } var gateLocation = connection.Locations[0].IsGateBetweenBiomes ? connection.Locations[0] : connection.Locations[1]; var unlockEvent = EventSet.PrefabList.Find(ep => ep.UnlockPathEvent && ep.BiomeIdentifier == gateLocation.LevelData.Biome.Identifier) ?? EventSet.PrefabList.Find(ep => ep.UnlockPathEvent && string.IsNullOrEmpty(ep.BiomeIdentifier)); if (unlockEvent == null) { continue; } if (string.IsNullOrEmpty(unlockEvent.UnlockPathFaction) || unlockEvent.UnlockPathFaction.Equals("location", StringComparison.OrdinalIgnoreCase)) { if (location == null || gateLocation != location) { continue; } } else { if (faction == null || !faction.Prefab.Identifier.Equals(unlockEvent.UnlockPathFaction, StringComparison.OrdinalIgnoreCase)) { continue; } } if (unlockEvent != null) { Reputation unlockReputation = gateLocation.Reputation; Faction unlockFaction = null; if (!string.IsNullOrEmpty(unlockEvent.UnlockPathFaction)) { unlockFaction = GameMain.GameSession.Campaign.Factions.Find(f => f.Prefab.Identifier.Equals(unlockEvent.UnlockPathFaction, StringComparison.OrdinalIgnoreCase)); unlockReputation = unlockFaction?.Reputation; } float normalizedUnlockReputation = MathUtils.InverseLerp(unlockReputation.MinReputation, unlockReputation.MaxReputation, unlockEvent.UnlockPathReputation); string unlockText = TextManager.GetWithVariables( "lockedpathreputationrequirement", new string[] { "[reputation]", "[biomename]" }, new string[] { Reputation.GetFormattedReputationText(normalizedUnlockReputation, unlockEvent.UnlockPathReputation, addColorTags: true), $"‖color:gui.orange‖{connection.LevelData.Biome.DisplayName}‖end‖" }); var unlockInfoPanel = new GUITextBlock(new RectTransform(new Vector2(0.8f, 0.0f), reputationFrame.RectTransform, Anchor.BottomCenter) { MinSize = new Point(0, GUI.IntScale(30)), AbsoluteOffset = new Point(0, GUI.IntScale(3)) }, unlockText, style: "GUIButtonRound", textAlignment: Alignment.Center, textColor: GUI.Style.TextColor, parseRichText: true); unlockInfoPanel.Color = Color.Lerp(unlockInfoPanel.Color, Color.Black, 0.8f); if (unlockInfoPanel.TextSize.X > unlockInfoPanel.Rect.Width * 0.7f) { unlockInfoPanel.Font = GUI.SmallFont; } } } } } }
public CampaignMetadata(CampaignMode campaign) { Campaign = campaign; }
public CargoManager(CampaignMode campaign) { this.campaign = campaign; }
protected override bool GetBool(CampaignMode campaignMode) { DebugConsole.ThrowError("Boolean comparison cannot be applied to reputations."); return(false); }
public UpgradeManager(CampaignMode campaign) { DebugConsole.Log("Created brand new upgrade manager."); Campaign = campaign; }
protected virtual bool GetBool(CampaignMode campaignMode) { return(campaignMode.CampaignMetadata.GetBoolean(Identifier)); }
public CampaignUI(CampaignMode campaign, GUIFrame container) { this.Campaign = campaign; MapContainer = new GUICustomComponent(new RectTransform(Vector2.One, container.RectTransform), DrawMap, UpdateMap); new GUIFrame(new RectTransform(Vector2.One, MapContainer.RectTransform), style: "InnerGlow", color: Color.Black * 0.9f) { CanBeFocused = false }; // top panel ------------------------------------------------------------------------- topPanel = new GUIFrame(new RectTransform(new Vector2(1.0f, 0.15f), container.RectTransform, Anchor.TopCenter), style: null) { CanBeFocused = false }; var topPanelContent = new GUIFrame(new RectTransform(new Vector2(0.95f, 0.9f), topPanel.RectTransform, Anchor.BottomCenter), style: null) { CanBeFocused = false }; var outpostBtn = new GUIButton(new RectTransform(new Vector2(0.15f, 0.55f), topPanelContent.RectTransform), TextManager.Get("Outpost"), textAlignment: Alignment.Center, style: "GUISlopedHeader") { OnClicked = (btn, userdata) => { SelectTab(Tab.Map); return(true); } }; outpostBtn.TextBlock.Font = GUI.LargeFont; outpostBtn.TextBlock.AutoScale = true; var tabButtonContainer = new GUILayoutGroup(new RectTransform(new Vector2(0.4f, 0.3f), topPanelContent.RectTransform, Anchor.BottomLeft), isHorizontal: true); int i = 0; var tabValues = Enum.GetValues(typeof(Tab)); foreach (Tab tab in tabValues) { var tabButton = new GUIButton(new RectTransform(new Vector2(0.25f, 1.0f), tabButtonContainer.RectTransform), TextManager.Get(tab.ToString()), textAlignment: Alignment.Center, style: i == 0 ? "GUISlopedTabButtonLeft" : (i == tabValues.Length - 1 ? "GUISlopedTabButtonRight" : "GUISlopedTabButtonMid")) { UserData = tab, OnClicked = (btn, userdata) => { SelectTab((Tab)userdata); return(true); }, Selected = tab == Tab.Map }; var buttonSprite = tabButton.Style.Sprites[GUIComponent.ComponentState.None][0]; tabButton.RectTransform.MaxSize = new Point( (int)(tabButton.Rect.Height * (buttonSprite.Sprite.size.X / buttonSprite.Sprite.size.Y)), int.MaxValue); tabButtons.Add(tabButton); tabButton.Font = GUI.LargeFont; i++; } // crew tab ------------------------------------------------------------------------- tabs = new GUIFrame[Enum.GetValues(typeof(Tab)).Length]; tabs[(int)Tab.Crew] = new GUIFrame(new RectTransform(new Vector2(0.3f, 0.7f), container.RectTransform, Anchor.TopLeft) { RelativeOffset = new Vector2(0.0f, topPanel.RectTransform.RelativeSize.Y) }, color: Color.Black * 0.7f); new GUIFrame(new RectTransform(new Vector2(1.25f, 1.25f), tabs[(int)Tab.Crew].RectTransform, Anchor.Center), style: "OuterGlow", color: Color.Black * 0.7f) { CanBeFocused = false }; characterList = new GUIListBox(new RectTransform(new Vector2(0.9f, 0.95f), tabs[(int)Tab.Crew].RectTransform, Anchor.Center)) { OnSelected = SelectCharacter }; new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.1f), characterList.Content.RectTransform), TextManager.Get("CampaignMenuCrew"), font: GUI.LargeFont) { UserData = "mycrew", CanBeFocused = false, AutoScale = true }; if (campaign is SinglePlayerCampaign) { new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.1f), characterList.Content.RectTransform), TextManager.Get("CampaignMenuHireable"), font: GUI.LargeFont) { UserData = "hire", CanBeFocused = false, AutoScale = true }; } // store tab ------------------------------------------------------------------------- tabs[(int)Tab.Store] = new GUIFrame(new RectTransform(new Vector2(0.5f, 0.7f), container.RectTransform, Anchor.TopLeft) { RelativeOffset = new Vector2(0.1f, topPanel.RectTransform.RelativeSize.Y) }, color: Color.Black * 0.7f); new GUIFrame(new RectTransform(new Vector2(1.25f, 1.25f), tabs[(int)Tab.Store].RectTransform, Anchor.Center), style: "OuterGlow", color: Color.Black * 0.7f) { CanBeFocused = false }; List <MapEntityCategory> itemCategories = Enum.GetValues(typeof(MapEntityCategory)).Cast <MapEntityCategory>().ToList(); //don't show categories with no buyable items itemCategories.RemoveAll(c => !MapEntityPrefab.List.Any(ep => ep.Category.HasFlag(c) && (ep is ItemPrefab) && ((ItemPrefab)ep).CanBeBought)); var storeContent = new GUILayoutGroup(new RectTransform(new Vector2(0.9f, 0.9f), tabs[(int)Tab.Store].RectTransform, Anchor.Center)) { Stretch = true, RelativeSpacing = 0.02f }; new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.1f), storeContent.RectTransform), "", font: GUI.LargeFont) { TextGetter = GetMoney }; var storeItemLists = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.8f), storeContent.RectTransform), isHorizontal: true) { Stretch = true, RelativeSpacing = 0.02f }; myItemList = new GUIListBox(new RectTransform(new Vector2(0.5f, 1.0f), storeItemLists.RectTransform)); storeItemList = new GUIListBox(new RectTransform(new Vector2(0.5f, 1.0f), storeItemLists.RectTransform)) { OnSelected = BuyItem }; var categoryButtonContainer = new GUILayoutGroup(new RectTransform(new Vector2(0.1f, 0.9f), tabs[(int)Tab.Store].RectTransform, Anchor.CenterLeft, Pivot.CenterRight)) { RelativeSpacing = 0.02f }; foreach (MapEntityCategory category in itemCategories) { var categoryButton = new GUIButton(new RectTransform(new Point(categoryButtonContainer.Rect.Width), categoryButtonContainer.RectTransform), "", style: "ItemCategory" + category.ToString()) { UserData = category, OnClicked = (btn, userdata) => { SelectItemCategory((MapEntityCategory)userdata); return(true); } }; itemCategoryButtons.Add(categoryButton); new GUITextBlock(new RectTransform(new Vector2(0.9f, 0.25f), categoryButton.RectTransform, Anchor.BottomCenter), TextManager.Get("MapEntityCategory." + category), textAlignment: Alignment.Center, textColor: categoryButton.TextColor) { AutoScale = true, Color = Color.Transparent, HoverColor = Color.Transparent, PressedColor = Color.Transparent, SelectedColor = Color.Transparent, CanBeFocused = false }; } SelectItemCategory(MapEntityCategory.Equipment); // mission info ------------------------------------------------------------------------- missionPanel = new GUIFrame(new RectTransform(new Vector2(0.3f, 0.5f), container.RectTransform, Anchor.TopRight) { RelativeOffset = new Vector2(0.0f, topPanel.RectTransform.RelativeSize.Y) }, color: Color.Black * 0.7f) { Visible = false }; new GUIFrame(new RectTransform(new Vector2(1.25f, 1.25f), missionPanel.RectTransform, Anchor.Center), style: "OuterGlow", color: Color.Black * 0.7f) { CanBeFocused = false }; new GUITextBlock(new RectTransform(new Vector2(0.5f, 0.15f), missionPanel.RectTransform, Anchor.TopRight, Pivot.BottomRight) { RelativeOffset = new Vector2(0.1f, -0.05f) }, TextManager.Get("Mission"), textAlignment: Alignment.Center, font: GUI.LargeFont, style: "GUISlopedHeader") { AutoScale = true }; var missionPanelContent = new GUILayoutGroup(new RectTransform(new Vector2(0.95f, 0.9f), missionPanel.RectTransform, Anchor.Center)) { Stretch = true, RelativeSpacing = 0.05f }; selectedLocationInfo = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.75f), missionPanelContent.RectTransform)) { RelativeSpacing = 0.02f, Stretch = true }; selectedMissionInfo = new GUIListBox(new RectTransform(new Vector2(0.9f, 0.25f), missionPanel.RectTransform, Anchor.BottomRight, Pivot.TopRight)) { Visible = false }; // ------------------------------------------------------------------------- topPanel.RectTransform.SetAsLastChild(); SelectTab(Tab.Map); UpdateLocationView(campaign.Map.CurrentLocation); campaign.Map.OnLocationSelected += SelectLocation; campaign.Map.OnLocationChanged += (prevLocation, newLocation) => UpdateLocationView(newLocation); campaign.Map.OnMissionSelected += (connection, mission) => { var selectedTickBox = missionTickBoxes.Find(tb => tb.UserData == mission); if (selectedTickBox != null) { selectedTickBox.Selected = true; } }; campaign.CargoManager.OnItemsChanged += RefreshMyItems; }
protected virtual float GetFloat(CampaignMode campaignMode) { return(campaignMode.CampaignMetadata.GetFloat(Identifier)); }
public UpgradeManager(CampaignMode campaign, XElement element, bool isSingleplayer) : this(campaign) { DebugConsole.Log($"Restored upgrade manager from save file, ({element.Elements().Count()} pending upgrades)."); LoadPendingUpgrades(element, isSingleplayer); }
public CampaignUI(CampaignMode campaign, GUIFrame container) { this.campaign = campaign; tabs = new GUIFrame[3]; tabs[(int)Tab.Crew] = new GUIFrame(new RectTransform(new Vector2(0.95f, 0.9f), container.RectTransform, Anchor.Center, Pivot.Center), null); //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 RectTransform(new Vector2(0.3f, 0.05f), tabs[(int)Tab.Crew].RectTransform) { RelativeOffset = new Vector2(0.01f, 0.02f) }, TextManager.Get("Crew") + ":", style: ""); characterList = new GUIListBox(new RectTransform(new Vector2(0.3f, 0.95f), tabs[(int)Tab.Crew].RectTransform, Anchor.CenterLeft, Pivot.CenterLeft) { RelativeOffset = new Vector2(0.01f, 0.05f) }, false, null, ""); characterList.OnSelected = SelectCharacter; new GUITextBlock(new RectTransform(new Vector2(0.3f, 0.05f), tabs[(int)Tab.Crew].RectTransform, Anchor.TopRight, Pivot.TopRight) { RelativeOffset = new Vector2(0.01f, 0.02f) }, TextManager.Get("Hire") + ":", style: ""); hireList = new GUIListBox(new RectTransform(new Vector2(0.3f, 0.95f), tabs[(int)Tab.Crew].RectTransform, Anchor.CenterRight, Pivot.CenterRight) { RelativeOffset = new Vector2(0.01f, 0.05f) }, false, null, ""); hireList.OnSelected = SelectCharacter; //--------------------------------------- tabs[(int)Tab.Map] = new GUIFrame(new RectTransform(new Vector2(0.95f, 0.9f), container.RectTransform, Anchor.Center, Pivot.Center), null); mapContainer = new GUICustomComponent(new RectTransform(new Vector2(0.74f, 1.0f), tabs[(int)Tab.Map].RectTransform), DrawMap, UpdateMap); locationInfoContainer = new GUILayoutGroup(new RectTransform(new Vector2(0.25f, 1.0f), tabs[(int)Tab.Map].RectTransform, Anchor.TopRight)) { AbsoluteSpacing = 5 }; if (GameMain.Client == null) { startButton = new GUIButton(new RectTransform(new Vector2(0.25f, 0.06f), tabs[(int)Tab.Map].RectTransform, Anchor.BottomRight, Pivot.BottomRight) { RelativeOffset = new Vector2(0.01f, 0.03f) }, TextManager.Get("StartCampaignButton"), style: "GUIButtonLarge") { OnClicked = (GUIButton btn, object obj) => { StartRound?.Invoke(); return(true); }, Enabled = false }; } //--------------------------------------- tabs[(int)Tab.Store] = new GUIFrame(new RectTransform(new Vector2(0.95f, 0.9f), container.RectTransform, Anchor.Center, Pivot.Center), null); int sellColumnWidth = (tabs[(int)Tab.Store].Rect.Width - 40) / 2 - 20; selectedItemList = new GUIListBox(new RectTransform(new Vector2(0.45f, 0.95f), tabs[(int)Tab.Store].RectTransform, Anchor.CenterLeft, Pivot.CenterLeft) { RelativeOffset = new Vector2(0.01f, 0.0f) }, false, null, ""); storeItemList = new GUIListBox(new RectTransform(new Vector2(0.45f, 0.95f), tabs[(int)Tab.Store].RectTransform, Anchor.CenterRight, Pivot.CenterRight) { RelativeOffset = new Vector2(0.01f, 0.0f) }, false, null, ""); storeItemList.OnSelected = BuyItem; List <MapEntityCategory> itemCategories = Enum.GetValues(typeof(MapEntityCategory)).Cast <MapEntityCategory>().ToList(); //don't show categories with no buyable items itemCategories.RemoveAll(c => !MapEntityPrefab.List.Any(ep => ep.Category.HasFlag(c) && (ep is ItemPrefab) && ((ItemPrefab)ep).CanBeBought)); int x = 0; int buttonWidth = storeItemList.Rect.Width / itemCategories.Count; foreach (MapEntityCategory category in itemCategories) { var categoryButton = new GUIButton(new RectTransform(new Point(buttonWidth, 30), tabs[(int)Tab.Store].RectTransform, Anchor.CenterRight, Pivot.BottomRight) { AbsoluteOffset = new Point(x, -storeItemList.Rect.Height / 2) }, category.ToString()); categoryButton.UserData = category; categoryButton.OnClicked = SelectItemCategory; if (category == MapEntityCategory.Equipment) { SelectItemCategory(categoryButton, category); } x += buttonWidth; } SelectTab(Tab.Map); UpdateLocationTab(campaign.Map.CurrentLocation); campaign.Map.OnLocationSelected += SelectLocation; campaign.Map.OnLocationChanged += (prevLocation, newLocation) => UpdateLocationTab(newLocation); campaign.CargoManager.OnItemsChanged += RefreshItemTab; }