void GetLocalScriptNames(bool reload = false)
        {
            if (!Directory.Exists(m_localBlueprintFolder))
            {
                return;
            }
            string[] scriptNames = Directory.GetDirectories(m_localBlueprintFolder);

            foreach (var scriptName in scriptNames)
            {
                string directoryName = Path.GetFileName(scriptName);
                var    info          = new MyScriptItemInfo(MyBlueprintTypeEnum.LOCAL, directoryName);
                var    item          = new MyGuiControlListbox.Item(text: new StringBuilder(directoryName), toolTip: directoryName, userData: info, icon: MyGuiConstants.TEXTURE_ICON_BLUEPRINTS_LOCAL.Normal);
                m_scriptList.Add(item);
            }

            if (m_task.IsComplete && reload)
            {
                GetWorkshopScripts();
            }
            else
            {
                AddWorkshopItemsToList();
            }
        }
Exemplo n.º 2
0
 static void ShareBlueprintRequest(ref ShareBlueprintMsg msg, MyNetworkClient sender)
 {
     if (Sync.IsServer && msg.SendToId != Sync.MyId)
     {
         Sync.Layer.SendMessage(ref msg, msg.SendToId);
     }
     else
     {
         var itemId = msg.WorkshopId;
         var name   = msg.Name;
         var info   = new MyBlueprintItemInfo(MyBlueprintTypeEnum.SHARED, id: itemId);
         var item   = new MyGuiControlListbox.Item(new StringBuilder(name.ToString()), userData: info, icon: MyGuiConstants.TEXTURE_BLUEPRINTS_ARROW.Normal);
         item.ColorMask = new Vector4(0.7f);
         if (!m_recievedBlueprints.Any(item2 => (item2.UserData as MyBlueprintItemInfo).PublishedItemId == (item.UserData as MyBlueprintItemInfo).PublishedItemId))
         {
             m_recievedBlueprints.Add(item);
             m_blueprintList.Add(item);
             if (sender != null)
             {
                 var notification = new MyHudNotificationDebug(sender.DisplayName + " just shared a blueprint with you.", 2500);
                 MyHud.Notifications.Add(notification);
             }
         }
     }
 }
        private void RefreshFactionList()
        {
            var localFaction = MySession.Static.Factions.TryGetPlayerFaction(MySession.Static.LocalPlayerId);

            if (localFaction != null)
            {
                //Add local player faction first
                m_tempStringBuilder.Clear();
                m_tempStringBuilder.Append(localFaction.Name);

                var chatHistory = MyChatSystem.GetFactionChatHistory(MySession.Static.LocalPlayerId, localFaction.FactionId);
                if (chatHistory != null && chatHistory.UnreadMessageCount > 0)
                {
                    m_tempStringBuilder.Append(" (");
                    m_tempStringBuilder.Append(chatHistory.UnreadMessageCount);
                    m_tempStringBuilder.Append(")");
                }

                var item = new MyGuiControlListbox.Item(text: m_tempStringBuilder, userData: localFaction);
                m_factionList.Add(item);

                m_factionList.SetToolTip(string.Empty);
                foreach (var faction in MySession.Static.Factions)
                {
                    //Don't add local player faction twice
                    if (faction.Value != localFaction && faction.Value.AcceptHumans)
                    {
                        m_tempStringBuilder.Clear();
                        m_tempStringBuilder.Append(faction.Value.Name);

                        chatHistory = MyChatSystem.GetFactionChatHistory(MySession.Static.LocalPlayerId, faction.Value.FactionId);
                        if (chatHistory != null && chatHistory.UnreadMessageCount > 0)
                        {
                            m_tempStringBuilder.Append(" (");
                            m_tempStringBuilder.Append(chatHistory.UnreadMessageCount);
                            m_tempStringBuilder.Append(")");
                        }

                        item = new MyGuiControlListbox.Item(text: m_tempStringBuilder, userData: faction.Value);
                        m_factionList.Add(item);
                    }
                }
            }
            else
            {
                m_factionList.SelectedItems.Clear();
                m_factionList.Items.Clear();

                m_factionList.SetToolTip(MyTexts.GetString(MySpaceTexts.TerminalTab_Chat_NoFaction));
            }
        }
Exemplo n.º 4
0
        private void AddGroupToList(MyBlockGroup group, int?position = null)
        {
            foreach (var it in m_blockListbox.Items)
            {
                if (it.UserData == group)
                {
                    return;
                }
            }
            var item = new MyGuiControlListbox.Item(userData: group);

            item.Text.Clear().Append("*").AppendStringBuilder(group.Name).Append("*");
            m_blockListbox.Add(item, position);
        }
Exemplo n.º 5
0
        public override void RecreateControls(bool contructor)
        {
            base.RecreateControls(contructor);

            // LABEL
            this.Controls.Add(new MyGuiControlLabel(new Vector2(0.0f, -0.46f), text: "Select components to include in entity", originAlign: MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER));


            m_replicableEntityCheckBox             = new MyGuiControlCheckbox();
            m_replicableEntityCheckBox.Position    = new Vector2(0f, -0.42f);
            m_replicableEntityCheckBox.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER;
            this.Controls.Add(m_replicableEntityCheckBox);

            // ENTITY TYPE LABEL
            this.Controls.Add(new MyGuiControlLabel(new Vector2(0.0f, -0.39f), text: "MyEntityReplicable / MyEntity", font: MyFontEnum.White, originAlign: MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER));


            // ADD COMPONENTS LABEL
            this.Controls.Add(new MyGuiControlLabel(new Vector2(0.0f, -0.32f), text: "Select components to add", originAlign: MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER));

            // COMPONENTS ADD SELECTION BOX
            if (m_addComponentsListBox == null)
            {
                m_addComponentsListBox = new MyGuiControlListbox();
            }
            m_addComponentsListBox.ClearItems();
            m_addComponentsListBox.MultiSelect = true;
            m_addComponentsListBox.Name        = "AddComponents";

            List <MyDefinitionId> definitions = new List <MyDefinitionId>();

            MyDefinitionManager.Static.GetDefinedEntityComponents(ref definitions);

            foreach (var id in definitions)
            {
                var text = id.ToString();
                if (text.StartsWith("MyObjectBuilder_"))
                {
                    text = text.Remove(0, "MyObectBuilder_".Length + 1);
                }
                MyGuiControlListbox.Item item = new MyGuiControlListbox.Item(text: new StringBuilder(text), userData: id);
                m_addComponentsListBox.Add(item);
            }
            m_addComponentsListBox.VisibleRowsCount = definitions.Count + 1;
            m_addComponentsListBox.Position         = new Vector2(0.0f, 0f);
            m_addComponentsListBox.OriginAlign      = MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER;
            m_addComponentsListBox.ItemSize         = new Vector2(0.36f, 0.036f);
            m_addComponentsListBox.Size             = new Vector2(0.4f, 0.6f);
            this.Controls.Add(m_addComponentsListBox);

            m_confirmButton = new MyGuiControlButton(new Vector2(0.21f, 0.35f), MyGuiControlButtonStyleEnum.Default, new Vector2(0.2f, 0.05f), null, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, null, new System.Text.StringBuilder("Confirm"));
            m_cancelButton  = new MyGuiControlButton(new Vector2(-0.21f, 0.35f), MyGuiControlButtonStyleEnum.Default, new Vector2(0.2f, 0.05f), null, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, null, new System.Text.StringBuilder("Cancel"));

            this.Controls.Add(m_confirmButton);
            this.Controls.Add(m_cancelButton);

            m_confirmButton.ButtonClicked += confirmButton_OnButtonClick;
            m_cancelButton.ButtonClicked  += cancelButton_OnButtonClick;
        }
Exemplo n.º 6
0
        public override void RecreateControls(bool contructor)
        {
            base.RecreateControls(contructor);

            // LABEL
            this.Controls.Add(new MyGuiControlLabel(new Vector2(0.0f, -0.46f), text: "Select entity to spawn", originAlign: MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER));

            // CONTAINERS
            if (m_containersListBox == null)
            {
                m_containersListBox = new MyGuiControlListbox();
            }
            m_containersListBox.ClearItems();
            m_containersListBox.MultiSelect = false;
            m_containersListBox.Name        = "Containers";

            List <MyDefinitionId> definitions = new List <MyDefinitionId>();

            MyDefinitionManager.Static.GetDefinedEntityContainers(ref definitions);

            foreach (var id in definitions)
            {
                var text = id.ToString();
                if (text.StartsWith("MyObjectBuilder_"))
                {
                    text = text.Remove(0, "MyObectBuilder_".Length + 1);
                }
                MyGuiControlListbox.Item item = new MyGuiControlListbox.Item(text: new StringBuilder(text), userData: id);
                m_containersListBox.Add(item);
            }
            m_containersListBox.VisibleRowsCount = definitions.Count + 1;
            m_containersListBox.Position         = new Vector2(0.0f, 0f);
            m_containersListBox.OriginAlign      = MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER;
            m_containersListBox.ItemSize         = new Vector2(0.36f, 0.036f);
            m_containersListBox.Size             = new Vector2(0.4f, 0.6f);
            this.Controls.Add(m_containersListBox);

            m_confirmButton = new MyGuiControlButton(new Vector2(0.21f, 0.35f), MyGuiControlButtonStyleEnum.Default, new Vector2(0.2f, 0.05f), null, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, null, new System.Text.StringBuilder("Confirm"));
            m_cancelButton  = new MyGuiControlButton(new Vector2(-0.21f, 0.35f), MyGuiControlButtonStyleEnum.Default, new Vector2(0.2f, 0.05f), null, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, null, new System.Text.StringBuilder("Cancel"));

            this.Controls.Add(m_confirmButton);
            this.Controls.Add(m_cancelButton);

            m_confirmButton.ButtonClicked += confirmButton_OnButtonClick;
            m_cancelButton.ButtonClicked  += cancelButton_OnButtonClick;
        }
Exemplo n.º 7
0
        private void UpdateTriggerList()
        {
            var itemCollection = m_triggersListBox.Items;

            for (var index = 0; index < itemCollection.Count; index++)
            {
                var areaTrigger = (MyAreaTriggerComponent)itemCollection[index].UserData;
                // Remove all that are not queried
                if (!m_triggerManipulator.CurrentQuery.Contains(areaTrigger))
                {
                    itemCollection.RemoveAtFast(index);
                }
            }

            foreach (var trigger in m_triggerManipulator.CurrentQuery)
            {
                var index = m_triggersListBox.Items.FindIndex(item => (MyTriggerComponent)item.UserData == trigger);
                if (index < 0)
                {
                    // Insert missing trigger
                    var areaTrigger = (MyAreaTriggerComponent)trigger;
                    var itemTextSb  = new StringBuilder("Trigger: ");
                    itemTextSb.Append(areaTrigger.Name).Append(" Entity: ");

                    // For named entities add their name
                    itemTextSb.Append(string.IsNullOrEmpty(areaTrigger.Entity.Name)
                        ? areaTrigger.Entity.DisplayName
                        : areaTrigger.Entity.Name);

                    m_triggersListBox.Add(new MyGuiControlListbox.Item(
                                              itemTextSb,
                                              toolTip: areaTrigger.Name,
                                              userData: areaTrigger
                                              ));
                }
            }
        }
        public bool CreateSpawnMenu(float usableWidth, MyGuiControlParentTableLayout parentTable, MyPluginAdminMenu adminScreen)
        {
            m_parentScreen = adminScreen;

            if (m_fetchedStarSytem == null)
            {
                MyGuiControlRotatingWheel loadingWheel = new MyGuiControlRotatingWheel(position: Vector2.Zero);
                loadingWheel.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER;

                adminScreen.Controls.Add(loadingWheel);

                MyStarSystemGenerator.Static.GetStarSystem(delegate(MyObjectBuilder_SystemData starSystem)
                {
                    m_fetchedStarSytem         = starSystem;
                    adminScreen.ShouldRecreate = true;
                });
                return(true);
            }

            MyGuiControlLabel label = new MyGuiControlLabel(null, null, "Parent objects");

            parentTable.AddTableRow(label);

            m_parentObjectListBox = new MyGuiControlListbox();
            m_parentObjectListBox.Add(new MyGuiControlListbox.Item(new System.Text.StringBuilder("System center"), userData: m_fetchedStarSytem.CenterObject));
            m_parentObjectListBox.VisibleRowsCount = 8;
            m_parentObjectListBox.Size             = new Vector2(usableWidth, m_parentObjectListBox.Size.Y);
            m_parentObjectListBox.SelectAllVisible();
            m_parentObjectListBox.ItemsSelected += OnParentItemClicked;

            foreach (var obj in m_fetchedStarSytem.CenterObject.GetAllChildren())
            {
                if (obj.Type == MySystemObjectType.PLANET || obj.Type == MySystemObjectType.MOON)
                {
                    m_parentObjectListBox.Add(new MyGuiControlListbox.Item(new System.Text.StringBuilder(obj.DisplayName), userData: obj));
                }
            }

            parentTable.AddTableRow(m_parentObjectListBox);

            parentTable.AddTableSeparator();

            m_radiusSlider               = new MyGuiControlClickableSlider(width: usableWidth - 0.1f, minValue: 0, maxValue: 1, labelSuffix: " km", showLabel: true);
            m_radiusSlider.Enabled       = false;
            m_radiusSlider.ValueChanged += delegate
            {
                RenderSpherePreview(GetDataFromGui());
            };

            parentTable.AddTableRow(new MyGuiControlLabel(null, null, "Radius"));
            parentTable.AddTableRow(m_radiusSlider);

            m_widthSlider               = new MyGuiControlClickableSlider(null, 0, 1, usableWidth - 0.1f, 0.5f, showLabel: true, labelSuffix: " km");
            m_widthSlider.Enabled       = false;
            m_widthSlider.ValueChanged += delegate
            {
                RenderSpherePreview(GetDataFromGui());
            };

            parentTable.AddTableRow(new MyGuiControlLabel(null, null, "Width"));
            parentTable.AddTableRow(m_widthSlider);

            m_asteroidSizesSlider         = new MyGuiControlRangedSlider(32, 1024, 32, 1024, true, width: usableWidth - 0.1f, showLabel: true);
            m_asteroidSizesSlider.Enabled = false;

            parentTable.AddTableRow(new MyGuiControlLabel(null, null, "Asteroid size range"));
            parentTable.AddTableRow(m_asteroidSizesSlider);

            m_nameBox      = new MyGuiControlTextbox();
            m_nameBox.Size = new Vector2(usableWidth, m_nameBox.Size.Y);

            parentTable.AddTableRow(new MyGuiControlLabel(null, null, "Name"));
            parentTable.AddTableRow(m_nameBox);

            m_spawnButton = MyPluginGuiHelper.CreateDebugButton(usableWidth, "Spawn sphere", delegate
            {
                StringBuilder name = new StringBuilder();
                m_nameBox.GetText(name);
                if (name.Length < 4)
                {
                    MyPluginGuiHelper.DisplayError("Name must be at least 4 letters long", "Error");
                    return;
                }

                MySystemAsteroids instance;
                MyAsteroidSphereData data;
                GenerateData(out instance, out data);

                if (instance == null || data == null)
                {
                    MyPluginGuiHelper.DisplayError("Could not generate asteroid sphere. No data found.", "Error");
                    return;
                }

                MyAsteroidSphereProvider.Static.AddInstance(instance, data, delegate(bool success)
                {
                    if (!success)
                    {
                        MyPluginGuiHelper.DisplayError("Sphere could not be added, because an object with the same id already exists. This error should not occour, so please try again.", "Error");
                    }
                    else
                    {
                        MyPluginGuiHelper.DisplayMessage("Sphere was created successfully.", "Success");
                        m_parentScreen.ForceFetchStarSystem = true;
                        m_parentScreen.ShouldRecreate       = true;
                    }
                });
            });

            parentTable.AddTableSeparator();

            parentTable.AddTableRow(m_spawnButton);

            return(true);
        }
        /// <summary>
        /// Builds the edit menu
        /// </summary>
        private void BuildEditMenu()
        {
            MyPluginLog.Debug("Adding edit menu");

            if (m_fetchedStarSytem == null || ForceFetchStarSystem)
            {
                MyPluginLog.Debug("Fetching system data");

                MyGuiControlRotatingWheel m_loadingWheel = new MyGuiControlRotatingWheel(position: Vector2.Zero);
                m_loadingWheel.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER;

                Controls.Add(m_loadingWheel);

                MyStarSystemGenerator.Static.GetStarSystem(delegate(MyObjectBuilder_SystemData starSystem)
                {
                    m_fetchedStarSytem   = starSystem;
                    m_selectedObject     = null;
                    ShouldRecreate       = true;
                    ForceFetchStarSystem = false;
                });
                return;
            }

            var     topCombo = GetCombo();
            Vector2 start    = topCombo.Position + new Vector2(0, MARGIN_VERT * 2 + GetCombo().Size.Y);
            Vector2 end      = start + new Vector2(topCombo.Size.X, 0.8f - MARGIN_VERT);

            MyGuiControlLabel systemObjsLabel = new MyGuiControlLabel(null, null, "System Objects");

            systemObjsLabel.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP;
            systemObjsLabel.Position    = start;

            Controls.Add(systemObjsLabel);

            m_systemObjectsBox = new MyGuiControlListbox();
            m_systemObjectsBox.VisibleRowsCount = 8;
            m_systemObjectsBox.Size             = new Vector2(m_usableWidth, m_systemObjectsBox.Size.Y);
            m_systemObjectsBox.Position         = start;
            m_systemObjectsBox.PositionY       += systemObjsLabel.Size.Y + MARGIN_VERT;
            m_systemObjectsBox.OriginAlign      = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP;

            foreach (var obj in m_fetchedStarSytem.GetAllObjects())
            {
                if (obj.Type == MySystemObjectType.EMPTY)
                {
                    continue;
                }
                m_systemObjectsBox.Add(new MyGuiControlListbox.Item(new System.Text.StringBuilder(obj.DisplayName), userData: obj));
            }

            if (m_selectedObject != null)
            {
                m_systemObjectsBox.SelectByUserData(m_selectedObject);
            }
            m_systemObjectsBox.ItemsSelected += OnSystemObjectSelect;


            Controls.Add(m_systemObjectsBox);

            MyGuiControlSeparatorList sep = new MyGuiControlSeparatorList();

            sep.AddHorizontal(new Vector2(m_systemObjectsBox.Position.X, m_systemObjectsBox.Position.Y + m_systemObjectsBox.Size.Y + MARGIN_VERT), m_usableWidth);

            BuildEditingSubMenu();

            sep.AddHorizontal(new Vector2(m_scrollPane.Position.X - m_scrollPane.Size.X / 2, m_scrollPane.Position.Y + m_scrollPane.Size.Y), m_usableWidth);

            Controls.Add(sep);

            MyPluginLog.Debug("Added edit menu");
        }
        private void RefreshPlayerList()
        {
            //Add the global chat log first
            m_globalItem = new MyGuiControlListbox.Item(MyTexts.Get(MySpaceTexts.TerminalTab_Chat_ChatHistory));
            m_playerList.Add(m_globalItem);

            //Comms broadcast history
            m_tempStringBuilder.Clear();
            m_tempStringBuilder.Append(MyTexts.Get(MySpaceTexts.TerminalTab_Chat_GlobalChat));

            MyChatHistory chatHistory;

            if (MySession.Static.ChatHistory.TryGetValue(MySession.Static.LocalPlayerId, out chatHistory) && chatHistory.GlobalChatHistory.UnreadMessageCount > 0)
            {
                m_tempStringBuilder.Append(" (");
                m_tempStringBuilder.Append(chatHistory.GlobalChatHistory.UnreadMessageCount);
                m_tempStringBuilder.Append(")");
            }

            m_broadcastItem = new MyGuiControlListbox.Item(m_tempStringBuilder);
            m_playerList.Add(m_broadcastItem);

            //var allPlayers = MySession.Static.Players.GetAllIdentities();
            var allPlayers = MySession.Static.Players.GetAllPlayers();

            m_tempOnlinePlayers.Clear();
            m_tempOfflinePlayers.Clear();

            foreach (var player in allPlayers)
            {
                var playerIdentity = MySession.Static.Players.TryGetIdentity(MySession.Static.Players.TryGetIdentityId(player.SteamId, player.SerialId));

                if (playerIdentity != null && playerIdentity.IdentityId != MySession.Static.LocalPlayerId && player.SerialId == 0)
                {
                    if (playerIdentity.Character == null)
                    {
                        m_tempOfflinePlayers.Add(playerIdentity);
                    }
                    else
                    {
                        m_tempOnlinePlayers.Add(playerIdentity);
                    }
                }
            }

            foreach (var onlinePlayer in m_tempOnlinePlayers)
            {
                m_tempStringBuilder.Clear();
                m_tempStringBuilder.Append(onlinePlayer.DisplayName);

                var playerChatHistory = MyChatSystem.GetPlayerChatHistory(MySession.Static.LocalPlayerId, onlinePlayer.IdentityId);
                if (playerChatHistory != null && playerChatHistory.UnreadMessageCount > 0)
                {
                    m_tempStringBuilder.Append(" (");
                    m_tempStringBuilder.Append(playerChatHistory.UnreadMessageCount);
                    m_tempStringBuilder.Append(")");
                }

                var item = new MyGuiControlListbox.Item(text: m_tempStringBuilder, userData: onlinePlayer);
                m_playerList.Add(item);
            }

            foreach (var offlinePlayer in m_tempOfflinePlayers)
            {
                m_tempStringBuilder.Clear();
                m_tempStringBuilder.Append(offlinePlayer.DisplayName);
                m_tempStringBuilder.Append(" (");
                m_tempStringBuilder.Append(MyTexts.GetString(MySpaceTexts.TerminalTab_Chat_Offline));
                m_tempStringBuilder.Append(")");

                var playerChatHistory = MyChatSystem.GetPlayerChatHistory(MySession.Static.LocalPlayerId, offlinePlayer.IdentityId);
                if (playerChatHistory != null && playerChatHistory.UnreadMessageCount > 0)
                {
                    m_tempStringBuilder.Append(" (");
                    m_tempStringBuilder.Append(playerChatHistory.UnreadMessageCount);
                    m_tempStringBuilder.Append(")");
                }

                var item = new MyGuiControlListbox.Item(text: m_tempStringBuilder, userData: offlinePlayer, fontOverride: MyFontEnum.DarkBlue);
                m_playerList.Add(item);
            }
        }
        public override void RecreateControls(bool constructor)
        {
            base.RecreateControls(constructor);
            float   hiddenPartTop  = (SCREEN_SIZE.Y - 1.0f) / 2.0f;
            Vector2 controlPadding = new Vector2(0.02f, 0);

            // Position the Caption
            var caption = AddCaption("Scripting Tools", Color.White.ToVector4(), controlPadding + new Vector2(-HIDDEN_PART_RIGHT, hiddenPartTop));

            m_currentPosition.Y = caption.PositionY + caption.Size.Y + ITEM_VERTICAL_PADDING;

            // Position all the controls under the caption
            // Debug draw checkbox
            PositionControls(new MyGuiControlBase[]
            {
                CreateLabel("Disable Transformation"),
                CreateCheckbox(DisableTransformationOnCheckedChanged, m_transformSys.DisableTransformation)
            });
            // Selected entity controls
            m_selectedEntityNameBox = CreateTextbox("");
            PositionControls(new MyGuiControlBase[]
            {
                CreateLabel("Selected Entity: "),
                m_selectedEntityNameBox,
                CreateButton("Rename", RenameSelectedEntityOnClick)
            });
            m_selectedFunctionalBlockNameBox = CreateTextbox("");
            PositionControls(new MyGuiControlBase[]
            {
                CreateLabel("Selected Block: "),
                m_selectedFunctionalBlockNameBox,
                CreateButton("Rename", RenameFunctionalBlockOnClick)
            });
            // Spawn entity button
            PositionControls(new MyGuiControlBase[]
            {
                CreateButton("Spawn Entity", SpawnEntityClicked),
                CreateButton("Delete Entity", DeleteEntityOnClicked)
            });

            // Trigger section
            PositionControl(CreateLabel("Triggers"));

            // Attach new trigger
            PositionControl(CreateButton("Attach to selected entity", AttachTriggerOnClick));

            m_enlargeTriggerButton = CreateButton("+", EnlargeTriggerOnClick);
            m_shrinkTriggerButton  = CreateButton("-", ShrinkTriggerOnClick);
            m_setTriggerSizeButton = CreateButton("Size", SetSizeOnClick);

            // Enlarge, Set size, Shrink
            PositionControls(new MyGuiControlBase[]
            {
                m_enlargeTriggerButton,
                m_setTriggerSizeButton,
                m_shrinkTriggerButton
            });

            // Snap, Select, Delete
            PositionControls(new MyGuiControlBase[]
            {
                CreateButton("Snap", SnapTriggerToCameraOrEntityOnClick),
                CreateButton("Select", SelectTriggerOnClick),
                CreateButton("Delete", DeleteTriggerOnClick)
            }
                             );

            // Selected trigger section
            m_selectedTriggerNameBox = CreateTextbox("Trigger not selected");
            PositionControls(new MyGuiControlBase[] { CreateLabel("Selected Trigger:"), m_selectedTriggerNameBox });

            // Listbox for queried triggers
            m_triggersListBox      = CreateListBox();
            m_triggersListBox.Size = new Vector2(0f, 0.07f);
            m_triggersListBox.ItemDoubleClicked += TriggersListBoxOnItemDoubleClicked;
            PositionControl(m_triggersListBox);
            // Because something is reseting the value
            m_triggersListBox.ItemSize = new Vector2(SCREEN_SIZE.X, ITEM_SIZE.Y);

            // Running Level Scripts
            PositionControl(CreateLabel("Running Level Scripts"));
            m_levelScriptListBox      = CreateListBox();
            m_levelScriptListBox.Size = new Vector2(0f, 0.07f);
            PositionControl(m_levelScriptListBox);
            // Because something is reseting the value
            m_triggersListBox.ItemSize = new Vector2(SCREEN_SIZE.X, ITEM_SIZE.Y);

            // Fill with levelscripts -- they wont change during the process
            foreach (var runningLevelScriptName in m_scriptManager.RunningLevelScriptNames)
            {
                // user data are there to tell if the script already failed or not
                m_levelScriptListBox.Add(new MyGuiControlListbox.Item(new StringBuilder(runningLevelScriptName), userData: false));
            }

            // Running State machines
            PositionControl(CreateLabel("Running state machines"));
            m_smListBox      = CreateListBox();
            m_smListBox.Size = new Vector2(0f, 0.07f);
            PositionControl(m_smListBox);
            // Because something is reseting the value
            m_smListBox.ItemSize = new Vector2(SCREEN_SIZE.X, ITEM_SIZE.Y);
        }
        public override bool Update(bool hasFocus)
        {
            // Enable/Disable cursor
            if (MyCubeBuilder.Static.CubeBuilderState.CurrentBlockDefinition != null || MyInput.Static.IsRightMousePressed())
            {
                DrawMouseCursor = false;
            }
            else
            {
                DrawMouseCursor = true;
            }

            // Update triggers and their GUI
            m_triggerManipulator.CurrentPosition = MyAPIGateway.Session.Camera.Position;
            UpdateTriggerList();

            // Update the level script listbox -- only change can be sudden fail of the script
            for (int index = 0; index < m_scriptManager.FailedLevelScriptExceptionTexts.Length; index++)
            {
                var failedLevelScriptExceptionText = m_scriptManager.FailedLevelScriptExceptionTexts[index];
                if (failedLevelScriptExceptionText != null && (bool)m_levelScriptListBox.Items[index].UserData)
                {
                    m_levelScriptListBox.Items[index].Text.Append(" - failed");
                    m_levelScriptListBox.Items[index].FontOverride = MyFontEnum.Red;
                    m_levelScriptListBox.Items[index].ToolTip.AddToolTip(failedLevelScriptExceptionText, font: MyFontEnum.Red);
                }
            }

            // Update running state machines
            foreach (var stateMachine in m_scriptManager.SMManager.RunningMachines)
            {
                var indexOf = m_smListBox.Items.FindIndex(item => (MyVSStateMachine)item.UserData == stateMachine);
                if (indexOf == -1)
                {
                    // new Entry
                    m_smListBox.Add(new MyGuiControlListbox.Item(new StringBuilder(stateMachine.Name), userData: stateMachine, toolTip: "Cursors:"));
                    indexOf = m_smListBox.Items.Count - 1;
                }

                var listItem = m_smListBox.Items[indexOf];
                // Remove tooltips for missing cursors
                for (int index = listItem.ToolTip.ToolTips.Count - 1; index >= 0; index--)
                {
                    var toolTip = listItem.ToolTip.ToolTips[index];

                    var found = false;
                    foreach (var cursor in stateMachine.ActiveCursors)
                    {
                        if (toolTip.Text.CompareTo(cursor.Node.Name) == 0)
                        {
                            found = true;
                            break;
                        }
                    }

                    if (!found && index != 0)
                    {
                        // remove missing
                        listItem.ToolTip.ToolTips.RemoveAtFast(index);
                    }
                }

                foreach (var cursor in stateMachine.ActiveCursors)
                {
                    var found = false;
                    for (int index = listItem.ToolTip.ToolTips.Count - 1; index >= 0; index--)
                    {
                        var text = listItem.ToolTip.ToolTips[index];
                        if (text.Text.CompareTo(cursor.Node.Name) == 0)
                        {
                            found = true;
                            break;
                        }
                    }

                    if (!found)
                    {
                        // Add missing
                        listItem.ToolTip.AddToolTip(cursor.Node.Name);
                    }
                }
            }

            return(base.Update(hasFocus));
        }
Exemplo n.º 13
0
        public override void RecreateControls(bool contructor)
        {
            base.RecreateControls(contructor);

            // LABEL
            this.Controls.Add(new MyGuiControlLabel(new Vector2(0.0f, -0.46f), text: "Select components to remove and components to add", originAlign: MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER));

            // ENTITY SELECTION
            if (m_entitiesSelection == null)
            {
                m_entitiesSelection = new MyGuiControlCombobox();
                m_entitiesSelection.ItemSelected += EntitySelected;
            }

            m_entitiesSelection.Position    = new Vector2(0f, -0.42f);
            m_entitiesSelection.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER;

            m_entitiesSelection.ClearItems();
            foreach (var ent in m_entities)
            {
                m_entitiesSelection.AddItem(ent.EntityId, ent.ToString());
            }
            m_entitiesSelection.SelectItemByKey(m_entityId, false);

            this.Controls.Add(m_entitiesSelection);

            // ENTITY ID LABEL
            this.Controls.Add(new MyGuiControlLabel(new Vector2(0.0f, -0.39f), text: String.Format("EntityID = {0}", m_entityId), font: MyFontEnum.White, originAlign: MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER));

            // ENTITY NAME LABEL AND COMPONENTS
            MyEntity entity;

            if (MyEntities.TryGetEntityById(m_entityId, out entity))
            {
                this.Controls.Add(new MyGuiControlLabel(new Vector2(0.0f, -0.36f), text: String.Format("Name: {1}, Type: {0}", entity.GetType().Name, entity.DisplayNameText), font: MyFontEnum.White, originAlign: MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER));
            }

            // REMOVE COMPONENTS LABEL
            this.Controls.Add(new MyGuiControlLabel(new Vector2(-0.21f, -0.32f), text: "Select components to remove", originAlign: MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER));

            // COMPONENTS REMOVE SELECTION BOX
            if (m_removeComponentsListBox == null)
            {
                m_removeComponentsListBox = new MyGuiControlListbox();
            }
            m_removeComponentsListBox.ClearItems();
            m_removeComponentsListBox.MultiSelect = true;
            m_removeComponentsListBox.Name        = "RemoveComponents";
            List <Type> components;

            if (MyComponentContainerExtension.TryGetEntityComponentTypes(m_entityId, out components))
            {
                foreach (var component in components)
                {
                    MyGuiControlListbox.Item item = new MyGuiControlListbox.Item(text: new StringBuilder(component.Name), userData: component);
                    m_removeComponentsListBox.Add(item);
                }
                m_removeComponentsListBox.VisibleRowsCount = components.Count + 1;
            }
            m_removeComponentsListBox.Position    = new Vector2(-0.21f, 0f);
            m_removeComponentsListBox.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER;
            m_removeComponentsListBox.ItemSize    = new Vector2(0.38f, 0.036f);
            m_removeComponentsListBox.Size        = new Vector2(0.4f, 0.6f);
            this.Controls.Add(m_removeComponentsListBox);

            // ADD COMPONENTS LABEL
            this.Controls.Add(new MyGuiControlLabel(new Vector2(0.21f, -0.32f), text: "Select components to add", originAlign: MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER));

            // COMPONENTS ADD SELECTION BOX
            if (m_addComponentsListBox == null)
            {
                m_addComponentsListBox = new MyGuiControlListbox();
            }
            m_addComponentsListBox.ClearItems();
            m_addComponentsListBox.MultiSelect = true;
            m_addComponentsListBox.Name        = "AddComponents";
            components.Clear();

            List <MyDefinitionId> definitions = new List <MyDefinitionId>();

            MyDefinitionManager.Static.GetDefinedEntityComponents(ref definitions);

            foreach (var id in definitions)
            {
                var text = id.ToString();
                if (text.StartsWith("MyObjectBuilder_"))
                {
                    text = text.Remove(0, "MyObectBuilder_".Length + 1);
                }
                MyGuiControlListbox.Item item = new MyGuiControlListbox.Item(text: new StringBuilder(text), userData: id);
                m_addComponentsListBox.Add(item);
            }
            m_addComponentsListBox.VisibleRowsCount = definitions.Count + 1;
            m_addComponentsListBox.Position         = new Vector2(0.21f, 0f);
            m_addComponentsListBox.OriginAlign      = MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER;
            m_addComponentsListBox.ItemSize         = new Vector2(0.36f, 0.036f);
            m_addComponentsListBox.Size             = new Vector2(0.4f, 0.6f);
            this.Controls.Add(m_addComponentsListBox);

            m_confirmButton = new MyGuiControlButton(new Vector2(0.21f, 0.35f), MyGuiControlButtonStyleEnum.Default, new Vector2(0.2f, 0.05f), null, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, null, new System.Text.StringBuilder("Confirm"));
            m_cancelButton  = new MyGuiControlButton(new Vector2(-0.21f, 0.35f), MyGuiControlButtonStyleEnum.Default, new Vector2(0.2f, 0.05f), null, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, null, new System.Text.StringBuilder("Cancel"));

            this.Controls.Add(m_confirmButton);
            this.Controls.Add(m_cancelButton);

            m_confirmButton.ButtonClicked += confirmButton_OnButtonClick;
            m_cancelButton.ButtonClicked  += cancelButton_OnButtonClick;
        }
        public bool CreateSpawnMenu(float usableWidth, MyGuiControlParentTableLayout parentTable, MyPluginAdminMenu adminScreen)
        {
            m_parentScreen            = adminScreen;
            m_offset                  = Vector3D.Zero;
            m_currentSelectedAsteroid = null;

            if (m_fetchedStarSytem == null)
            {
                MyGuiControlRotatingWheel m_loadingWheel = new MyGuiControlRotatingWheel(position: Vector2.Zero);
                m_loadingWheel.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER;

                adminScreen.Controls.Add(m_loadingWheel);

                MyStarSystemGenerator.Static.GetStarSystem(delegate(MyObjectBuilder_SystemData starSystem)
                {
                    m_fetchedStarSytem         = starSystem;
                    adminScreen.ShouldRecreate = true;
                });
                return(true);
            }

            MyGuiControlLabel label = new MyGuiControlLabel(null, null, "Parent objects");

            parentTable.AddTableRow(label);

            m_parentObjectListBox = new MyGuiControlListbox();
            m_parentObjectListBox.Add(new MyGuiControlListbox.Item(new System.Text.StringBuilder("System center"), userData: m_fetchedStarSytem.CenterObject));
            m_parentObjectListBox.VisibleRowsCount = 8;
            m_parentObjectListBox.Size             = new Vector2(usableWidth, m_parentObjectListBox.Size.Y);
            m_parentObjectListBox.SelectAllVisible();
            m_parentObjectListBox.ItemsSelected += OnParentItemClicked;

            foreach (var obj in m_fetchedStarSytem.CenterObject.GetAllChildren())
            {
                if (obj.Type == MySystemObjectType.PLANET || obj.Type == MySystemObjectType.MOON)
                {
                    m_parentObjectListBox.Add(new MyGuiControlListbox.Item(new System.Text.StringBuilder(obj.DisplayName), userData: obj));
                }
            }

            parentTable.AddTableRow(m_parentObjectListBox);

            var row = new MyGuiControlParentTableLayout(2, false, Vector2.Zero);

            m_snapToParentCheck                   = new MyGuiControlCheckbox();
            m_snapToParentCheck.IsChecked         = m_snapToParent;
            m_snapToParentCheck.IsCheckedChanged += delegate
            {
                m_snapToParent         = m_snapToParentCheck.IsChecked;
                m_zoomInButton.Enabled = m_snapToParent;
            };

            row.AddTableRow(m_snapToParentCheck, new MyGuiControlLabel(null, null, "Snap camera to parent"));

            row.ApplyRows();

            parentTable.AddTableRow(row);

            parentTable.AddTableSeparator();

            GenerateRingSettingElements(usableWidth, parentTable);

            m_nameBox      = new MyGuiControlTextbox();
            m_nameBox.Size = new Vector2(usableWidth, m_nameBox.Size.Y);

            parentTable.AddTableRow(new MyGuiControlLabel(null, null, "Name"));
            parentTable.AddTableRow(m_nameBox);

            m_zoomInButton = MyPluginGuiHelper.CreateDebugButton(usableWidth, "Zoom to ring", delegate
            {
                if (m_snapToParent)
                {
                    m_parentScreen.CameraLookAt(GenerateAsteroidRing().CenterPosition, new Vector3D(0, 0, (m_radiusSlider.Value + m_widthSlider.Value) * 2000));
                }
            });

            parentTable.AddTableRow(m_zoomInButton);

            m_offsetToCoordButton = MyPluginGuiHelper.CreateDebugButton(usableWidth, "Offset to coordinate", delegate
            {
                var coordMessage          = new MyGuiScreenDialogCoordinate("Enter coordinate to offset the center of the ring from its parent");
                coordMessage.OnConfirmed += delegate(Vector3D coord)
                {
                    m_offset = coord;
                    UpdateRingVisual(GenerateAsteroidRing());
                };
                MyGuiSandbox.AddScreen(coordMessage);
            });

            parentTable.AddTableRow(m_offsetToCoordButton);

            m_spawnRingButton = MyPluginGuiHelper.CreateDebugButton(usableWidth, "Add ring", delegate
            {
                StringBuilder name = new StringBuilder();
                m_nameBox.GetText(name);
                if (name.Length < 4)
                {
                    MyPluginGuiHelper.DisplayError("Name must be at least 4 letters long", "Error");
                    return;
                }

                MySystemAsteroids instance;
                MyAsteroidRingData ring;
                GenerateAsteroidData(out ring, out instance);

                if (ring == null || instance == null)
                {
                    MyPluginGuiHelper.DisplayError("Could not generate asteroid ring. No data found.", "Error");
                    return;
                }

                MyAsteroidRingProvider.Static.AddInstance(instance, ring, delegate(bool success)
                {
                    if (!success)
                    {
                        MyPluginGuiHelper.DisplayError("Ring could not be added, because an object with the same id already exists. This error should not occour, so please try again.", "Error");
                    }
                    else
                    {
                        MyPluginGuiHelper.DisplayMessage("Ring was created successfully.", "Success");
                        m_parentScreen.ForceFetchStarSystem = true;
                        m_parentScreen.ShouldRecreate       = true;
                    }
                });
            });

            parentTable.AddTableRow(m_spawnRingButton);

            return(true);
        }