public void RefreshContent(List <GuiFaction> guiFactions, List <Color> colorsList, bool isGameAlreadyLaunchedOnce, bool canModifyOwnEmpireSettings, bool guiLocked) { if (this.Session == null || !this.Session.IsOpened) { this.AgeTransform.Enable = false; return; } this.AgeTransform.Enable = true; this.CompetitorIsHuman = (this.EmpireIndex == 0); this.CompetitorIsLocalOwner = false; this.hasGameBeenLaunchedOnce = isGameAlreadyLaunchedOnce; this.canModifyOwnEmpireSettings = canModifyOwnEmpireSettings; string x = string.Format("LockEmpire{0}", this.EmpireIndex); this.empireLocked = this.Session.GetLobbyData <bool>(x, false); this.LockEmpireToggle.AgeTransform.Enable = this.Session.IsHosting; this.LockEmpireToggle.State = this.empireLocked; string text = string.Format("Empire{0}", this.EmpireIndex); string lobbyData = this.Session.GetLobbyData <string>(text, null); if (string.IsNullOrEmpty(lobbyData)) { Diagnostics.LogError("Lobby data is null for 'keyLobbyDataEmpire' (keyLobbyDataEmpire: '{0}').", new object[] { text }); base.GetComponent <AgeTransform>().Enable = false; return; } if (lobbyData.StartsWith("AI")) { this.CompetitorIsHuman = false; this.CompetitorIsLocalOwner = this.Session.IsHosting; } else { this.CompetitorIsHuman = true; } for (int i = 0; i < this.PlayersTitleLabels.Length; i++) { this.PlayersTitleLabels[i].AgeTransform.Visible = false; this.PlayerReadyToggles[i].AgeTransform.Visible = false; this.PlayerKickButtons[i].AgeTransform.Visible = false; this.PlayerHostingIcons[i].AgeTransform.Visible = false; } if (this.CompetitorIsHuman) { this.EmpireType.Text = "%CompetitorEmpireTypeHumanTitle"; this.EmpireType.AgeTransform.AgeTooltip.Content = "%CompetitorEmpireTypeHumanDescription"; string[] array = lobbyData.Split(Amplitude.String.Separators, StringSplitOptions.RemoveEmptyEntries); for (int j = 0; j < array.Length; j++) { this.RefreshPlayerLine(array[j], j); } } else { this.EmpireType.Text = "%CompetitorEmpireTypeComputerTitle"; this.EmpireType.AgeTransform.AgeTooltip.Content = "%CompetitorEmpireTypeComputerDescription"; this.PlayersTitleLabels[0].AgeTransform.Visible = true; this.PlayersTitleLabels[0].Text = "%CompetitorAIPlayerTitle"; this.PlayersTitleLabels[0].AgeTransform.AgeTooltip.Content = "%CompetitorEmpireTypeComputerDescription"; } string x2 = string.Format("_EmpireReserved{0}", this.EmpireIndex); string lobbyData2 = this.Session.GetLobbyData <string>(x2, null); if (!string.IsNullOrEmpty(lobbyData2)) { string[] array2 = lobbyData2.Split(Amplitude.String.Separators, StringSplitOptions.RemoveEmptyEntries); List <Steamworks.SteamID> list = new List <Steamworks.SteamID>(); for (int k = 0; k < array2.Length; k++) { ulong num = Convert.ToUInt64(array2[k], 16); if (num != 0UL) { list.Add(new Steamworks.SteamID(num)); } } if (list.Count > 0) { string text2 = string.Empty; for (int l = 0; l < list.Count; l++) { Steamworks.SteamAPI.SteamFriends.RequestUserInformation(list[l], true); text2 = text2 + ((text2.Length <= 0) ? string.Empty : ",") + Steamworks.SteamAPI.SteamFriends.GetFriendPersonaName(list[l]); } this.EmpireType.Text = string.Format("{0} #A0A0A0#({1})#REVERT#", AgeLocalizer.Instance.LocalizeString(this.EmpireType.Text), text2); } } this.EmpireNumber.Text = (this.EmpireIndex + 1).ToString(); this.guiFactions = new List <GuiFaction>(guiFactions); this.RefreshSelectedFaction(); if (!this.Session.GetLobbyData <bool>("CustomFactions", true)) { for (int m = 0; m < this.guiFactions.Count; m++) { if (this.guiFactions[m].IsCustom) { this.FactionDroplist.EnableItem(m, false); this.FactionDroplist.SetItemTooltip(m, "%CustomFactionsNotAllowed"); } else { this.FactionDroplist.EnableItem(m, true); } } Faction selectedFaction = this.GetSelectedFaction(); if (selectedFaction != null && selectedFaction.IsCustom) { Faction faction = this.guiFactions[0].Faction; IDatabase <Faction> database = Databases.GetDatabase <Faction>(false); if (database != null) { faction = database.FirstOrDefault((Faction iterator) => iterator.IsStandard && !iterator.IsHidden); } this.SelectFaction(faction); this.AgeTransform.Enable = false; return; } } else { Faction selectedFaction2 = this.GetSelectedFaction(); for (int n = 0; n < this.guiFactions.Count; n++) { if (this.guiFactions[n].IsCustom && !GuiFaction.IsValidCustomFaction(this.guiFactions[n].Faction, null)) { this.FactionDroplist.EnableItem(n, false); this.FactionDroplist.SetItemTooltip(n, "%CustomFactionInvalidCustomFactionTitle"); if (selectedFaction2 != null && selectedFaction2.Name == this.guiFactions[n].Faction.Name) { this.SelectFaction(this.guiFactions[0].Faction); } } } } if (this.Session.SessionMode == SessionMode.Single || !this.Session.GetLobbyData <bool>("SpectatorMode", false) || this.Session.GetLobbyData <int>("NumberOfMajorFactions", 0) < 3) { for (int num2 = 0; num2 < this.guiFactions.Count; num2++) { if (this.guiFactions[num2].Faction.Name == "FactionELCPSpectator") { this.FactionDroplist.EnableItem(num2, false); this.FactionDroplist.SetItemTooltip(num2, "%GameOptionSpectatorModeDisabled"); } else { this.FactionDroplist.EnableItem(num2, true); } } if (this.GetSelectedFaction().Name == "FactionELCPSpectator") { Faction faction2 = this.guiFactions[0].Faction; IDatabase <Faction> database2 = Databases.GetDatabase <Faction>(false); if (database2 != null) { faction2 = database2.FirstOrDefault((Faction iterator) => iterator.IsStandard && !iterator.IsHidden && iterator.Name != "FactionELCPSpectator"); } this.SelectFaction(faction2); this.AgeTransform.Enable = false; return; } } IDownloadableContentService service = Services.GetService <IDownloadableContentService>(); if (service != null) { for (int num3 = 0; num3 < this.guiFactions.Count; num3++) { if (this.guiFactions[num3].IsStandard || this.guiFactions[num3].IsCustom) { bool flag = false; if (!service.TryCheckAgainstRestrictions(DownloadableContentRestrictionCategory.LobbyFaction, this.guiFactions[num3].Name, out flag) || !flag) { this.FactionDroplist.EnableItem(num3, false); this.FactionDroplist.SetItemTooltip(num3, "%RestrictedDownloadableContentTitle"); } else if (this.guiFactions[num3].Faction.Affinity != null && (!service.TryCheckAgainstRestrictions(DownloadableContentRestrictionCategory.LobbyFactionAffinity, this.guiFactions[num3].Faction.Affinity, out flag) || !flag)) { this.FactionDroplist.EnableItem(num3, false); this.FactionDroplist.SetItemTooltip(num3, "%RestrictedDownloadableContentTitle"); } else { foreach (FactionTrait factionTrait in Faction.EnumerableTraits(this.guiFactions[num3].Faction)) { if (!service.TryCheckAgainstRestrictions(DownloadableContentRestrictionCategory.LobbyFactionTrait, factionTrait.Name, out flag) || !flag) { this.FactionDroplist.EnableItem(num3, false); this.FactionDroplist.SetItemTooltip(num3, "%RestrictedDownloadableContentTitle"); break; } } } } } } ISessionService service2 = Services.GetService <ISessionService>(); Faction selectedFaction3 = this.GetSelectedFaction(); if (selectedFaction3 != null && this.FactionConstrainedIcon != null) { if (Faction.IsOptionDefinitionConstrained(selectedFaction3, service2.Session)) { this.FactionConstrainedIcon.AgeTransform.Visible = true; } else { this.FactionConstrainedIcon.AgeTransform.Visible = false; } } this.RefreshColorDropList(colorsList); this.RefreshHandicapDroplist(lobbyData); bool flag2 = !this.empireLocked && !guiLocked; if (!this.CompetitorIsHuman && this.Session.SessionMode != SessionMode.Single) { this.JoinButton.AgeTransform.Visible = true; this.NoJoinBackground.Visible = false; this.JoinButton.AgeTransform.Enable = (flag2 && !this.empireLocked); } else { this.JoinButton.AgeTransform.Visible = false; this.NoJoinBackground.Visible = true; } if (this.Session.GetLobbyData <bool>(string.Format("Empire{0}Eliminated", this.EmpireIndex), false)) { if (!this.Session.GetLobbyData <bool>("SpectatorMode", false) || this.CompetitorIsHuman) { this.JoinButton.AgeTransform.Visible = false; this.NoJoinBackground.Visible = true; } else { this.JoinButton.AgeTransform.Visible = true; this.NoJoinBackground.Visible = false; } this.EmpireType.Text = string.Format("{0} #FF0000#({1})#REVERT#", AgeLocalizer.Instance.LocalizeString(this.EmpireType.Text), AgeLocalizer.Instance.LocalizeString("%CompetitorEliminatedTitle")); } this.CurrentPlayerHighlight.Visible = this.IsMySlot; }
private void CreateCustomFaction() { this.Faction.Affinity = new XmlNamedReference(this.selectedAffinity.Name); this.Faction.AffinityMapping = new XmlNamedReference(this.SelectedAffinityMapping.Name); this.Faction.TraitReferences = (from guiTrait in this.selectedGuiTraits select new XmlNamedReference(guiTrait.Name)).ToArray <XmlNamedReference>(); this.Faction.LocalizedName = this.NameTextField.AgePrimitiveLabel.Text.Trim(); this.Faction.LocalizedDescription = this.DescriptionTextField.AgePrimitiveLabel.Text.Trim(); this.Faction.Author = this.AuthorTextField.AgePrimitiveLabel.Text.Trim(); this.Faction.IsCustom = true; this.Faction.IsStandard = false; List <GuiError> list = new List <GuiError>(); if (!GuiFaction.IsValidCustomFaction(this.Faction, list)) { string message = string.Join("\r\n", (from guiError in list select guiError.ToString()).ToArray <string>()); MessagePanel.Instance.Show(message, "%CustomFactionInvalidCustomFactionTitle", MessagePanelButtons.Ok, null, MessagePanelType.WARNING, new MessagePanelButton[0]); this.HandleCancelRequest(); return; } if (string.IsNullOrEmpty(this.Faction.FileName)) { string path = System.IO.Path.Combine(Amplitude.Unity.Framework.Application.GameDirectory, "Custom Factions"); DirectoryInfo directoryInfo = new DirectoryInfo(path); if (!directoryInfo.Exists) { directoryInfo.Create(); } string text = this.Faction.LocalizedName; char[] invalidFileNameChars = System.IO.Path.GetInvalidFileNameChars(); foreach (char oldChar in invalidFileNameChars) { text = text.Replace(oldChar, '@'); } this.Faction.FileName = System.IO.Path.Combine(directoryInfo.FullName, text); this.Faction.FileName = System.IO.Path.ChangeExtension(this.Faction.FileName, ".xml"); } if (!string.IsNullOrEmpty(this.Faction.FileName)) { ISerializationService service = Services.GetService <ISerializationService>(); if (service != null) { XmlSerializer xmlSerializer = service.GetXmlSerializer <Faction>(); if (xmlSerializer != null) { using (Stream stream = File.Open(this.Faction.FileName, FileMode.Create)) { xmlSerializer.Serialize(stream, this.Faction); } } } } IDatabase <Faction> database = Databases.GetDatabase <Faction>(false); database.Touch(this.Faction); base.GuiService.GetGuiPanel <MenuNewGameScreen>().OnCustomFactionChanged(this.Faction); base.GuiService.GetGuiPanel <MenuFactionScreen>().Show(new object[] { this.empireIndex, this.Faction }); this.Faction = null; }
public override void RefreshContent() { base.RefreshContent(); this.FactionsTable.Height = 0f; this.FactionsTable.ReserveChildren(this.guiFactions.Count, this.FactionCardPrefab, "Item"); this.FactionsTable.RefreshChildrenIList <GuiFaction>(this.guiFactions, this.setupGuiFactionDelegate, true, false); this.FactionsTable.ArrangeChildren(); this.FactionsTableScrollView.OnPositionRecomputed(); this.ValidateButton.AgeTransform.Enable = false; this.ValidateButton.AgeTransform.AgeTooltip.Content = null; this.DestroyFactionButton.AgeTransform.Enable = false; this.ModifyFactionButton.AgeTransform.Enable = false; this.CreateFactionButton.AgeTransform.Enable = true; List <FactionCard> children = this.FactionsTable.GetChildren <FactionCard>(true); for (int i = 0; i < children.Count; i++) { children[i].SelectionToggle.State = (this.SelectedGuiFaction != null && children[i].GuiFaction.Faction.Name == this.SelectedGuiFaction.Faction.Name); } if (this.SelectedGuiFaction == null) { this.FactionTitle.AgeTransform.Visible = false; this.FactionTitleUnderline.AgeTransform.Visible = false; this.FactionAuthor.AgeTransform.Visible = false; this.FactionMoodImage.AgeTransform.Visible = false; this.FactionDescriptionScrollView.AgeTransform.Visible = false; this.FactionTraitsScrollView.AgeTransform.Visible = false; this.UnitBodyGroup.Visible = false; return; } this.ValidateButton.AgeTransform.Enable = true; if (this.SelectedGuiFaction.IsCustom) { bool enable = GuiFaction.IsValidCustomFaction(this.SelectedGuiFaction.Faction, null); this.ValidateButton.AgeTransform.Enable = enable; } IDownloadableContentService service = Services.GetService <IDownloadableContentService>(); if (service != null) { bool flag; if (service.TryCheckAgainstRestrictions(DownloadableContentRestrictionCategory.LobbyFaction, this.SelectedGuiFaction.Faction.Name, out flag) && !flag) { this.ValidateButton.AgeTransform.Enable = false; this.ValidateButton.AgeTransform.AgeTooltip.Content = "%RestrictedDownloadableContentTitle"; } if (this.SelectedGuiFaction.Faction.Affinity != null && service.TryCheckAgainstRestrictions(DownloadableContentRestrictionCategory.LobbyFactionAffinity, this.SelectedGuiFaction.Faction.Affinity.Name, out flag) && !flag) { this.ValidateButton.AgeTransform.Enable = false; this.ValidateButton.AgeTransform.AgeTooltip.Content = "%RestrictedDownloadableContentTitle"; } if (this.ValidateButton.AgeTransform.Enable) { foreach (FactionTrait factionTrait in Faction.EnumerableTraits(this.SelectedGuiFaction.Faction)) { if (!service.TryCheckAgainstRestrictions(DownloadableContentRestrictionCategory.LobbyFactionTrait, factionTrait.Name, out flag) || !flag) { this.ValidateButton.AgeTransform.Enable = false; this.ValidateButton.AgeTransform.AgeTooltip.Content = "%RestrictedDownloadableContentTitle"; break; } } } } this.DestroyFactionButton.AgeTransform.Enable = this.SelectedGuiFaction.IsCustom; this.ModifyFactionButton.AgeTransform.Enable = this.SelectedGuiFaction.IsCustom; this.FactionDescriptionScrollView.AgeTransform.Visible = true; this.FactionTitle.AgeTransform.Visible = true; this.FactionTitleUnderline.AgeTransform.Visible = true; this.FactionAuthor.AgeTransform.Visible = true; this.FactionTitle.Text = this.SelectedGuiFaction.Title; this.FactionAuthor.Text = string.Empty; if (this.SelectedGuiFaction.Faction.Author != "AMPLITUDE Studios") { this.FactionAuthor.Text = this.SelectedGuiFaction.Faction.Author; } if (this.diplomaticNegotiationViewport != null) { this.FactionMoodImage.AgeTransform.Visible = false; XmlNamedReference xmlNamedReference = (!this.SelectedGuiFaction.IsRandom) ? this.SelectedGuiFaction.Faction.AffinityMapping : new XmlNamedReference(GuiFaction.FactionRandomMappingName); bool flag2 = this.diplomaticNegotiationViewport.AffinityMapping == null || this.diplomaticNegotiationViewport.AffinityMapping != xmlNamedReference; this.diplomaticNegotiationViewport.SetApparence(xmlNamedReference); if (flag2) { this.diplomaticNegotiationViewport.TriggerAlternativeIdle(0.1f); } } else { this.FactionMoodImage.AgeTransform.Visible = true; this.FactionMoodImage.Image = this.SelectedGuiFaction.GetImageTexture(GuiPanel.IconSize.NegotiationLarge, false); this.FactionDescription.AgeTransform.Height = 0f; } if (this.SelectedGuiFaction.IsRandom || this.SelectedGuiFaction.Name == "FactionELCPSpectator") { this.FactionDescription.Text = this.SelectedGuiFaction.Description; } else { this.FactionDescription.Text = AgeLocalizer.Instance.LocalizeString("%" + this.SelectedGuiFaction.Faction.Affinity.Name + "VictoryType") + "\n \n" + AgeLocalizer.Instance.LocalizeString(this.SelectedGuiFaction.Description); } this.FactionDescriptionScrollView.ResetUp(); if (!this.SelectedGuiFaction.Faction.IsRandom) { this.FactionTraitsScrollView.AgeTransform.Visible = true; this.UnitBodyGroup.Visible = true; this.FactionTraitsContainers.Visible = true; List <GuiFactionTrait> list = (from trait in Faction.EnumerableTraits(this.SelectedGuiFaction.Faction) where !trait.IsHidden && !trait.IsAffinityRelated select new GuiFactionTrait(trait)).ToList <GuiFactionTrait>(); list.Sort(); this.FactionTraitsTable.Height = 0f; this.FactionTraitsTable.ReserveChildren(list.Count, this.FactionTraitPrefab, "Item"); this.FactionTraitsTable.RefreshChildrenIList <GuiFactionTrait>(list, this.setupGuiFactionTraitDelegate, true, false); this.FactionTraitsTable.ArrangeChildren(); this.FactionTraitsScrollView.ResetUp(); this.factionUnitBodies.Clear(); for (int j = 0; j < this.unitBodyDefinitions.Count; j++) { UnitBodyDefinition unitBodyDefinition = this.unitBodyDefinitions[j]; if (!unitBodyDefinition.Tags.Contains("Hidden")) { SimulationDescriptorReference[] simulationDescriptorReferences = unitBodyDefinition.SimulationDescriptorReferences; for (int k = 0; k < simulationDescriptorReferences.Length; k++) { if (simulationDescriptorReferences[k].Name == this.SelectedGuiFaction.Faction.Affinity.Name) { this.factionUnitBodies.Add(unitBodyDefinition); } } } } if (this.currentBody >= this.factionUnitBodies.Count) { this.currentBody = 0; } if (this.currentBody >= 0 && this.currentBody < this.factionUnitBodies.Count) { this.UnitBodyCard.RefreshContent(this.factionUnitBodies[this.currentBody]); } this.RefreshCurrentBody(); return; } this.FactionTraitsScrollView.AgeTransform.Visible = false; this.UnitBodyGroup.Visible = false; this.FactionTraitsContainers.Visible = false; }