public MyGuiControlScenarioButton(MyScenarioDefinition scenario):
     base(key: MyDefinitionManager.Static.GetScenarioDefinitions().IndexOf(scenario))
 {
     VisualStyle = MyGuiControlRadioButtonStyleEnum.ScenarioButton;
     OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP;
     Scenario = scenario;
     m_titleLabel = new MyGuiControlLabel(text: scenario.DisplayNameText, originAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP);
     m_previewPanel = new MyGuiControlPanel(texture: scenario.Icon, originAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP);
     MyGuiSizedTexture image = new MyGuiSizedTexture() { SizePx = new Vector2(229f, 128f), };
     m_previewPanel.Size = image.SizeGui;
     m_previewPanel.BorderEnabled = true;
     m_previewPanel.BorderColor = MyGuiConstants.THEMED_GUI_LINE_COLOR.ToVector4();
     SetToolTip(scenario.DescriptionText);
     Size = new Vector2(Math.Max(m_titleLabel.Size.X, m_previewPanel.Size.X),
                        m_titleLabel.Size.Y + m_previewPanel.Size.Y);
     Elements.Add(m_titleLabel);
     Elements.Add(m_previewPanel);
 }
Exemplo n.º 2
0
        public static void FillInventoryWithDefaults(MyObjectBuilder_Inventory inventory, MyScenarioDefinition scenario)
        {
            if (inventory.Items == null)
                inventory.Items = new List<MyObjectBuilder_InventoryItem>();
            else
                inventory.Items.Clear();

            if (scenario != null && MySession.Static.Settings.SpawnWithTools)
            {
                MyStringId[] guns;
                if (MySession.Static.CreativeMode)
                    guns = scenario.CreativeModeWeapons;// new string[] { "AngleGrinderItem", "AutomaticRifleItem", "HandDrillItem", "WelderItem" };
                else
                    guns = scenario.SurvivalModeWeapons;// new string[] { "AngleGrinderItem", "HandDrillItem", "WelderItem" };

                uint itemId = 0;
                if (guns != null)
                {
                    foreach (var gun in guns)
                    {
                        var inventoryItem = MyObjectBuilderSerializer.CreateNewObject<MyObjectBuilder_InventoryItem>();
                        inventoryItem.Amount = 1;
                        inventoryItem.PhysicalContent = MyObjectBuilderSerializer.CreateNewObject<MyObjectBuilder_PhysicalGunObject>(gun.ToString());
                        inventoryItem.ItemId = itemId++;
                        inventory.Items.Add(inventoryItem);
                    }
                    inventory.nextItemId = itemId;
                }

                MyScenarioDefinition.StartingItem[] items;
                if (MySession.Static.CreativeMode)
                    items = scenario.CreativeModeComponents;
                else
                    items = scenario.SurvivalModeComponents;

                if (items != null)
                {
                    foreach (var item in items)
                    {
                        var inventoryItem = MyObjectBuilderSerializer.CreateNewObject<MyObjectBuilder_InventoryItem>();
                        inventoryItem.Amount = item.amount;
                        inventoryItem.PhysicalContent = MyObjectBuilderSerializer.CreateNewObject<MyObjectBuilder_Component>(item.itemName.ToString());
                        inventoryItem.ItemId = itemId++;
                        inventory.Items.Add(inventoryItem);
                    }
                    inventory.nextItemId = itemId;
                }

                MyScenarioDefinition.StartingPhysicalItem[] physicalItems;
                if (MySession.Static.CreativeMode)
                    physicalItems = scenario.CreativeModePhysicalItems;
                else
                    physicalItems = scenario.SurvivalModePhysicalItems;

                if (physicalItems != null)
                {
                    foreach (var item in physicalItems)
                    {
                        var inventoryItem = MyObjectBuilderSerializer.CreateNewObject<MyObjectBuilder_InventoryItem>();
                        inventoryItem.Amount = item.amount;
                        if (item.itemType.ToString().Equals("Ore"))
                        {
                            inventoryItem.PhysicalContent = MyObjectBuilderSerializer.CreateNewObject<MyObjectBuilder_Ore>(item.itemName.ToString());
                        }
                        else if (item.itemType.ToString().Equals("Ingot"))
                        {
                            inventoryItem.PhysicalContent = MyObjectBuilderSerializer.CreateNewObject<MyObjectBuilder_Ingot>(item.itemName.ToString());
                        }
                        else if (item.itemType.ToString().Equals("OxygenBottle"))
                        {
                            inventoryItem.Amount = 1;
                            inventoryItem.PhysicalContent = MyObjectBuilderSerializer.CreateNewObject<MyObjectBuilder_OxygenContainerObject>(item.itemName.ToString());
                            (inventoryItem.PhysicalContent as MyObjectBuilder_GasContainerObject).GasLevel = (float)item.amount;
                        }
                        else if (item.itemType.ToString().Equals("GasBottle"))
                        {
                            inventoryItem.Amount = 1;
                            inventoryItem.PhysicalContent = MyObjectBuilderSerializer.CreateNewObject<MyObjectBuilder_GasContainerObject>(item.itemName.ToString());
                            (inventoryItem.PhysicalContent as MyObjectBuilder_GasContainerObject).GasLevel = (float)item.amount;
                        }
                        inventoryItem.ItemId = itemId++;
                        inventory.Items.Add(inventoryItem);
                    }
                    inventory.nextItemId = itemId;
                }

                if (MySession.Static.CreativeMode)
                    items = scenario.CreativeModeAmmoItems;
                else
                    items = scenario.SurvivalModeAmmoItems;

                if (items != null)
                {
                    foreach (var item in items)
                    {
                        var inventoryItem = MyObjectBuilderSerializer.CreateNewObject<MyObjectBuilder_InventoryItem>();
                        inventoryItem.Amount = item.amount;
                        inventoryItem.PhysicalContent = MyObjectBuilderSerializer.CreateNewObject<MyObjectBuilder_AmmoMagazine>(item.itemName.ToString());
                        inventoryItem.ItemId = itemId++;
                        inventory.Items.Add(inventoryItem);
                    }
                    inventory.nextItemId = itemId;
                }

                MyObjectBuilder_InventoryItem[] inventoryItems = MySession.Static.CreativeMode ? scenario.CreativeInventoryItems : scenario.SurvivalInventoryItems;
                if (inventoryItems != null)
                {
                    foreach (var ob in inventoryItems)
                    {
                        var item = ob.Clone() as MyObjectBuilder_InventoryItem;
                        item.ItemId = itemId++;
                        inventory.Items.Add(item);
                    }
                    inventory.nextItemId = itemId;
                }
            }
        }
Exemplo n.º 3
0
        public static void FillInventoryWithDefaults(MyObjectBuilder_Inventory inventory, MyScenarioDefinition scenario)
        {
            if (inventory.Items == null)
                inventory.Items = new List<MyObjectBuilder_InventoryItem>(15);
            else
                inventory.Items.Clear();

            if (scenario != null && MySession.Static.Settings.SpawnWithTools)
            {
                MyStringId[] guns;
                if (MySession.Static.CreativeMode)
                    guns = scenario.CreativeModeWeapons;// new string[] { "AngleGrinderItem", "AutomaticRifleItem", "HandDrillItem", "WelderItem" };
                else
                    guns = scenario.SurvivalModeWeapons;// new string[] { "AngleGrinderItem", "HandDrillItem", "WelderItem" };

                if (guns != null)
                {
                    foreach (var gun in guns)
                    {
                        var inventoryItem = MyObjectBuilderSerializer.CreateNewObject<MyObjectBuilder_InventoryItem>();
                        inventoryItem.Amount = 1;
                        inventoryItem.Content = MyObjectBuilderSerializer.CreateNewObject<MyObjectBuilder_PhysicalGunObject>(gun.ToString());
                        inventory.Items.Add(inventoryItem);
                    }
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Starts new session and unloads outdated if theres any.
        /// </summary>
        /// <param name="sessionName">Created session name.</param>
        /// <param name="settings">Session settings OB.</param>
        /// <param name="mods">Mod selection.</param>
        /// <param name="scenarioDefinition">World generator argument.</param>
        /// <param name="asteroidAmount">Hostility settings.</param>
        /// <param name="description">Session description.</param>
        /// <param name="passwd">Session password.</param>
        public static void StartNewSession( string                                      sessionName, 
                                            MyObjectBuilder_SessionSettings             settings, 
                                            List<MyObjectBuilder_Checkpoint.ModItem> mods,
                                            MyScenarioDefinition                        scenarioDefinition = null,
                                            int                                         asteroidAmount = 0, 
                                            string                                      description = "", 
                                            string                                      passwd = "")
        {
            MyLog.Default.WriteLine("StartNewSandbox - Start");

            if (!MySteamWorkshop.CheckLocalModsAllowed(mods, settings.OnlineMode == MyOnlineModeEnum.OFFLINE))
            {
                MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                    messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError),
                    messageText: MyTexts.Get(MyCommonTexts.DialogTextLocalModsDisabledInMultiplayer),
                    buttonType: MyMessageBoxButtonsType.OK));
                MyLog.Default.WriteLine("LoadSession() - End");
                return;
            }

            MySteamWorkshop.DownloadModsAsync(mods, delegate(bool success, string mismatchMods)
            {
                if (success || (settings.OnlineMode == MyOnlineModeEnum.OFFLINE) && MySteamWorkshop.CanRunOffline(mods))
                {
                    CheckMismatchmods(mismatchMods, callback: delegate(ResultEnum val)
                    {
                        MyScreenManager.RemoveAllScreensExcept(null);

                        if (asteroidAmount < 0)
                        {
                            MyWorldGenerator.SetProceduralSettings(asteroidAmount, settings);
                            asteroidAmount = 0;
                        }

                        MyAnalyticsHelper.SetEntry(MyGameEntryEnum.Custom);

                        StartLoading(delegate
                        {
                            MyAnalyticsHelper.SetEntry(MyGameEntryEnum.Custom);

                            MySession.Start(
                                sessionName,
                                description,
                                passwd,
                                settings,
                                mods,
                                new MyWorldGenerator.Args()
                                {
                                    AsteroidAmount = asteroidAmount,
                                    Scenario = scenarioDefinition
                                }
                            );
                        });
                    });
                }
                else
                {
                    if (MySteam.IsOnline)
                    {
                        MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                             messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError),
                             messageText: MyTexts.Get(MyCommonTexts.DialogTextDownloadModsFailed),
                             buttonType: MyMessageBoxButtonsType.OK));
                    }
                    else
                    {
                        MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                                      messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError),
                                                      messageText: MyTexts.Get(MyCommonTexts.DialogTextDownloadModsFailedSteamOffline),
                                                      buttonType: MyMessageBoxButtonsType.OK));
                    }
                }
                MyLog.Default.WriteLine("StartNewSandbox - End");
            });
        }