private static void ShowAvailableUpgrade(UpgradeRecord upgrade) { GameObject prefab = (GameObject)Resources.Load("Prefabs/SquadBuilder/UpgradePanel", typeof(GameObject)); Transform contentTransform = GameObject.Find("UI/Panels/SelectUpgradePanel/Panel/Scroll View/Viewport/Content").transform; GameObject newUpgradePanel = MonoBehaviour.Instantiate(prefab, contentTransform); string upgradeType = AllUpgrades.Find(n => n.UpgradeName == upgrade.UpgradeName).UpgradeTypeName; GenericUpgrade newUpgrade = (GenericUpgrade)System.Activator.CreateInstance(Type.GetType(upgradeType)); Edition.Current.AdaptUpgradeToRules(newUpgrade); if (newUpgrade is IVariableCost && Edition.Current is SecondEdition) { (newUpgrade as IVariableCost).UpdateCost(CurrentSquadBuilderShip.Instance); } UpgradePanelSquadBuilder script = newUpgradePanel.GetComponent <UpgradePanelSquadBuilder>(); script.Initialize(upgrade.UpgradeName, CurrentUpgradeSlot, newUpgrade, SelectUpgradeClicked, true); int column = availableUpgradesCounter; newUpgradePanel.transform.localPosition = new Vector3(DISTANCE_MEDIUM + (Edition.Current.UpgradeCardSize.x + DISTANCE_MEDIUM) * column, Edition.Current.UpgradeCardSize.y / 2, 0); availableUpgradesCounter++; }
private static void ShowAvailableUpgrade(UpgradeRecord upgrade) { GameObject prefab = (GameObject)Resources.Load("Prefabs/SquadBuilder/UpgradePanel", typeof(GameObject)); Transform contentTransform = GameObject.Find("UI/Panels/SelectUpgradePanel/Panel/Scroll View/Viewport/Content").transform; GameObject newUpgradePanel = MonoBehaviour.Instantiate(prefab, contentTransform); string upgradeType = AllUpgrades.Find(n => n.UpgradeName == upgrade.UpgradeName).UpgradeTypeName; GenericUpgrade newUpgrade = (GenericUpgrade)System.Activator.CreateInstance(Type.GetType(upgradeType)); UpgradePanelSquadBuilder script = newUpgradePanel.GetComponent <UpgradePanelSquadBuilder>(); script.Initialize(upgrade.UpgradeName, CurrentUpgradeSlot, newUpgrade, SelectUpgradeClicked, true); int column = availableUpgradesCounter; newUpgradePanel.transform.localPosition = new Vector3(DISTANCE_MEDIUM + (UPGRADE_CARD_WIDTH + DISTANCE_MEDIUM) * column, UPGRADE_CARD_HEIGHT / 2, 0); availableUpgradesCounter++; }
private void GenerateUpgradesRecords() { List <Type> typelist = Assembly.GetExecutingAssembly().GetTypes() .Where(t => String.Equals(t.Namespace, $"UpgradesList.{Edition.Current.NameShort}", StringComparison.Ordinal)) .ToList(); foreach (Type type in typelist) { if (type.MemberType == MemberTypes.NestedType) { continue; } UpgradeRecord upgradeRecord = new UpgradeRecord(type); if (upgradeRecord.IsAllowedForSquadBuilder) { AllUpgrades.Add(upgradeRecord); } } AllUpgrades = AllUpgrades.OrderBy(n => n.Instance.UpgradeInfo.Name).ToList(); }
private void ShowAvailableUpgrade(UpgradeRecord upgrade) { GameObject prefab = (GameObject)Resources.Load("Prefabs/SquadBuilder/UpgradePanel", typeof(GameObject)); Transform contentTransform = GameObject.Find("UI/Panels/SelectUpgradePanel/Panel/Scroll View/Viewport/Content").transform; GameObject newUpgradePanel = MonoBehaviour.Instantiate(prefab, contentTransform); string upgradeType = Global.SquadBuilder.Database.AllUpgrades.Find(n => n.UpgradeNameCanonical == upgrade.UpgradeNameCanonical && n.UpgradeType == upgrade.UpgradeType).UpgradeTypeName; GenericUpgrade newUpgrade = (GenericUpgrade)System.Activator.CreateInstance(Type.GetType(upgradeType)); if (newUpgrade is IVariableCost && Edition.Current is SecondEdition) { (newUpgrade as IVariableCost).UpdateCost(Global.SquadBuilder.CurrentShip.Instance); if (newUpgrade.UpgradeInfo.Cost == int.MaxValue) { newUpgrade.IsHidden = true; } } Edition.Current.AdaptUpgradeToRules(newUpgrade); UpgradePanelSquadBuilder script = newUpgradePanel.GetComponent <UpgradePanelSquadBuilder>(); script.Initialize(upgrade.UpgradeName, Global.SquadBuilder.CurrentUpgradeSlot, newUpgrade, SelectUpgradeClicked, true); newUpgradePanel.name = upgrade.UpgradeName; }
public static void SetPlayerSquadFromImportedJson(SquadList squad, JSONObject squadJson) { if (squadJson.HasField("name")) { squad.Name = squadJson["name"].str; } string factionNameXws = squadJson["faction"].str; Faction faction = Edition.Current.XwsToFaction(factionNameXws); squad.SquadFaction = faction; if (squadJson.HasField("pilots")) { JSONObject pilotJsons = squadJson["pilots"]; foreach (JSONObject pilotJson in pilotJsons.list) { string shipNameXws = pilotJson["ship"].str; string shipNameGeneral = ""; ShipRecord shipRecord = SquadBuilder.Instance.Database.AllShips.FirstOrDefault(n => n.ShipNameCanonical == shipNameXws); if (shipRecord == null) { Messages.ShowError("Cannot find ship: " + shipNameXws); continue; } shipNameGeneral = shipRecord.ShipName; string pilotNameXws = pilotJson["id"].str; PilotRecord pilotRecord = SquadBuilder.Instance.Database.AllPilots.FirstOrDefault(n => n.PilotNameCanonical == pilotNameXws && n.Ship.ShipName == shipNameGeneral && n.PilotFaction == faction); if (pilotRecord == null) { Messages.ShowError("Cannot find pilot: " + pilotNameXws); continue; } GenericShip newShipInstance = (GenericShip)Activator.CreateInstance(Type.GetType(pilotRecord.PilotTypeName)); Edition.Current.AdaptShipToRules(newShipInstance); SquadListShip newShip = squad.AddPilotToSquad(newShipInstance); Dictionary <string, string> upgradesThatCannotBeInstalled = new Dictionary <string, string>(); if (pilotJson.HasField("upgrades")) { JSONObject upgradeJsons = pilotJson["upgrades"]; if (upgradeJsons.keys != null) { foreach (string upgradeType in upgradeJsons.keys) { JSONObject upgradeNames = upgradeJsons[upgradeType]; foreach (JSONObject upgradeRecord in upgradeNames.list) { UpgradeRecord newUpgradeRecord = SquadBuilder.Instance.Database.AllUpgrades.FirstOrDefault(n => n.UpgradeNameCanonical == upgradeRecord.str); if (newUpgradeRecord == null) { Messages.ShowError("Cannot find upgrade: " + upgradeRecord.str); } bool upgradeInstalledSucessfully = newShip.InstallUpgrade(upgradeRecord.str, Edition.Current.XwsToUpgradeType(upgradeType)); if (!upgradeInstalledSucessfully && !upgradesThatCannotBeInstalled.ContainsKey(upgradeRecord.str)) { upgradesThatCannotBeInstalled.Add(upgradeRecord.str, upgradeType); } } } while (upgradeJsons.Count != 0) { Dictionary <string, string> upgradesThatCannotBeInstalledCopy = new Dictionary <string, string>(upgradesThatCannotBeInstalled); bool wasSuccess = false; foreach (var upgrade in upgradesThatCannotBeInstalledCopy) { bool upgradeInstalledSucessfully = newShip.InstallUpgrade(upgrade.Key, Edition.Current.XwsToUpgradeType(upgrade.Value)); if (upgradeInstalledSucessfully) { wasSuccess = true; upgradesThatCannotBeInstalled.Remove(upgrade.Key); } } if (!wasSuccess) { break; } } } } if (pilotJson.HasField("vendor")) { JSONObject vendorData = pilotJson["vendor"]; if (vendorData.HasField("Sandrem.FlyCasual")) { JSONObject myVendorData = vendorData["Sandrem.FlyCasual"]; if (myVendorData.HasField("skin")) { newShip.Instance.ModelInfo.SkinName = myVendorData["skin"].str; } } } } } else { Messages.ShowError("The squad has no pilots"); } if (squadJson.HasField("obstacles")) { squad.ChosenObstacles.AddRange( new List <GenericObstacle>() { ObstaclesManager.GetPossibleObstacle(squadJson["obstacles"][0].str), ObstaclesManager.GetPossibleObstacle(squadJson["obstacles"][1].str), ObstaclesManager.GetPossibleObstacle(squadJson["obstacles"][2].str) } ); } else { squad.SetDefaultObstacles(); } }