Example #1
0
        public MyBlockGroup AddUpdateGroup(MyBlockGroup group)
        {
            //Can happen on split
            //Debug.Assert(group.Blocks.Count > 0, "Empty group should not be added to system.");
            if (group.Blocks.Count == 0)
            {
                return(null);
            }
            bool modified = false;

            for (int index = 0; index < BlockGroups.Count; index++)
            {
                var g = BlockGroups[index];
                if (g.Name.CompareTo(group.Name) == 0)
                {
                    if (group.CubeGrid != null) //change came from grid i.e. destroyed block that was in group
                    {
                        for (int i = 0; i < g.Blocks.Count; i++)
                        {
                            if (g.Blocks[i].CubeGrid == group.CubeGrid)
                            {
                                g.Blocks.RemoveAt(i);
                                i--;
                            }
                        }
                    }
                    else //change came from gui, we clear group and add all blocks that came in
                    {
                        g.Blocks.Clear();
                    }
                    foreach (var b in group.Blocks)
                    {
                        if (g.Blocks.Contains(b))
                        {
                            continue;
                        }
                        g.Blocks.Add(b);
                    }
                    group    = g;
                    modified = true;
                    break;
                }
            }

            if (!modified) //new group
            {
                var g = new MyBlockGroup(null);
                g.Name.Clear().AppendStringBuilder(group.Name);
                g.Blocks.AddList(group.Blocks);
                BlockGroups.Add(g);
                group = g;
            }

            if (GroupAdded != null)
            {
                GroupAdded(group);
            }
            return(group);
        }
        public MyBlockGroup AddUpdateGroup(MyBlockGroup group)
        {
            //Can happen on split
            //Debug.Assert(group.Blocks.Count > 0, "Empty group should not be added to system.");
            if (group.Blocks.Count == 0)
                return null;
            bool modified = false;
            for (int index = 0; index < BlockGroups.Count; index++)
            {
                var g = BlockGroups[index];
                if (g.Name.CompareTo(group.Name) == 0)
                {
                    if (group.CubeGrid != null) //change came from grid i.e. destroyed block that was in group
                    {
                        for (int i = 0; i < g.Blocks.Count; i++)
                        {
                            if (g.Blocks[i].CubeGrid == group.CubeGrid)
                            {
                                g.Blocks.RemoveAt(i);
                                i--;
                            }
                        }
                    }
                    else //change came from gui, we clear group and add all blocks that came in
                    {
                        g.Blocks.Clear();
                    }
                    foreach (var b in group.Blocks)
                    {
                        if (g.Blocks.Contains(b))
                        {
                            continue;
                        }
                        g.Blocks.Add(b);
                    }
                    group = g;
                    modified = true;
                    break;
                }
            }

            if (!modified) //new group
            {
                var g = new MyBlockGroup(null);
                g.Name.Clear().AppendStringBuilder(group.Name);
                g.Blocks.AddList(group.Blocks);
                BlockGroups.Add(g);
                group = g;
            }

            if (GroupAdded != null)
                GroupAdded(group);
            return group;
        }
Example #3
0
        public void RemoveGroup(MyBlockGroup group)
        {
            bool removed = false;

            if (!BlockGroups.Contains(group)) // if you delete from terminal group matches and you delete whole group
            {
                for (int index = 0; index < BlockGroups.Count; index++)
                {
                    var g = BlockGroups[index];
                    if (g.Name.CompareTo(group.Name) == 0)
                    {
                        for (int i = 0; i < g.Blocks.Count; i++)
                        {
                            var b = g.Blocks[i];
                            if (b.CubeGrid == group.CubeGrid) //remove only blocks of that grid from group
                            {
                                g.Blocks.Remove(b);
                                i--;
                            }
                        }
                        if (g.Blocks.Count == 0)
                        {
                            group = g; //group to remove
                        }
                        else
                        {
                            removed = true;
                        }
                        break;
                    }
                }
            }

            if (!removed)
            {
                BlockGroups.Remove(group);
            }

            if (GroupRemoved != null && group.CubeGrid == null)
            {
                GroupRemoved(group);
            }
        }
        public void RemoveGroup(MyBlockGroup group)
        {
            bool removed = false;

            if (!BlockGroups.Contains(group))  // if you delete from terminal group matches and you delete whole group
            {
                foreach (var g in BlockGroups) //removing group from grid side (grid disconnected, or last block from that grid group removed)
                {
                    if (g.Name.CompareTo(group.Name) == 0)
                    {
                        for (int i = 0; i < g.Blocks.Count; i++)
                        {
                            var b = g.Blocks[i];
                            if (b.CubeGrid == group.CubeGrid) //remove only blocks of that grid from group
                            {
                                g.Blocks.Remove(b);
                                i--;
                            }
                        }
                        if (g.Blocks.Count == 0)
                        {
                            group = g; //group to remove
                        }
                        else
                        {
                            removed = true;
                        }
                        break;
                    }
                }
            }

            if (!removed)
            {
                BlockGroups.Remove(group);
            }

            if (GroupRemoved != null)
            {
                GroupRemoved(group);
            }
        }
 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);
 }
        void groupSave_ButtonClicked(MyGuiControlButton obj)
        {
            bool containsEnemyBlock = false;
            foreach (var block in m_tmpGroup.Blocks)
            {
                if (!block.HasLocalPlayerAccess())
                {
                    containsEnemyBlock = true;
                    break;
                }
            }

            if (containsEnemyBlock)
            {
                MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                    buttonType: MyMessageBoxButtonsType.OK,
                    messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError),
                    messageText: MyTexts.Get(MyCommonTexts.MessageBoxTextCannotCreateGroup)
                    ));
            }
            else
            {
                Debug.Assert(!string.IsNullOrEmpty(m_groupName.Text));
                if (m_groupName.Text != "")
                {
                    m_currentGroups.Clear();
                    m_tmpGroup.Name.Clear().Append(m_groupName.Text);
                    m_tmpGroup = m_terminalSystem.AddUpdateGroup(m_tmpGroup);
                    m_currentGroups.Add(m_tmpGroup);
                    m_tmpGroup = new MyBlockGroup(null);
                    CurrentBlocks.AddList(m_currentGroups[0].Blocks);
                    SelectBlocks();
                }
            }
        }
 void TerminalSystem_GroupAdded(MyBlockGroup group)
 {
     Debug.Assert(m_blockListbox != null);
     if (m_blockListbox != null)
         AddGroupToList(group, 0);
 }
 void TerminalSystem_GroupRemoved(MyBlockGroup group)
 {
     Debug.Assert(m_blockListbox != null);
     if (m_blockListbox != null)
         foreach (var item in m_blockListbox.Items)
             if (item.UserData == group)
             {
                 m_blockListbox.Items.Remove(item);
                 break;
             }
 }
 public static MyObjectBuilder_ToolbarItemTerminalGroup TerminalGroupObjectBuilderFromGroup(MyBlockGroup group)
 {
     MyObjectBuilder_ToolbarItemTerminalGroup output = Sandbox.Common.ObjectBuilders.Serializer.MyObjectBuilderSerializer.CreateNewObject<MyObjectBuilder_ToolbarItemTerminalGroup>();
     output.GroupName = group.Name.ToString();
     output.Action = null;
     return output;
 }
Example #10
0
 private void TerminalSystem_GroupRemoved(MyBlockGroup group)
 {
     if (group.CubeGrid != null && group.CubeGrid != m_cubeGrid)
         return;
     foreach (var g in m_cubeGrid.BlockGroups)
         if (g.Name.CompareTo(group.Name) == 0)
         {
             Debug.Assert(g != group, "TerminalSystem should have own group copy");
             g.Blocks.Clear();
             m_cubeGrid.BlockGroups.Remove(g);
             m_cubeGrid.ModifyGroup(g);
             break;
         }
 }
Example #11
0
 public virtual void AddGroup(MyBlockGroup group)
 {
     if (TerminalSystem != null)
     {
         TerminalSystem.GroupAdded -= m_terminalSystem_GroupAdded;
         TerminalSystem.AddUpdateGroup(group);
         TerminalSystem.GroupAdded += m_terminalSystem_GroupAdded;
     }
 }
Example #12
0
        public void ModifyGroup(MyBlockGroup group)
        {
            var msg = new ModifyBlockGroupMsg();

            msg.GridEntityId = Entity.EntityId;
            msg.Name = group.Name.ToString();
            foreach (var block in group.Blocks)
                m_tmpBlockIdList.Add(block.EntityId);
            msg.Blocks = m_tmpBlockIdList.ToArray();
            m_tmpBlockIdList.Clear();

            Sync.Layer.SendMessageToAll(ref msg);
        }
        public void RemoveGroup(MyBlockGroup group)
        {
            bool removed = false;
            if (!BlockGroups.Contains(group)) // if you delete from terminal group matches and you delete whole group
            {
                for (int index = 0; index < BlockGroups.Count; index++)
                {
                    var g = BlockGroups[index];
                    if (g.Name.CompareTo(group.Name) == 0)
                    {
                        for (int i = 0; i < g.Blocks.Count; i++)
                        {
                            var b = g.Blocks[i];
                            if (b.CubeGrid == group.CubeGrid) //remove only blocks of that grid from group
                            {
                                g.Blocks.Remove(b);
                                i--;
                            }
                        }
                        if (g.Blocks.Count == 0)
                        {
                            group = g; //group to remove
                        }
                        else
                        {
                            removed = true;
                        }
                        break;
                    }
                }
            }

            if (!removed)
                BlockGroups.Remove(group);

            if (GroupRemoved != null && group.CubeGrid == null)
                GroupRemoved(group);
        }
        public void RemoveGroup(MyBlockGroup group)
        {
            bool removed = false;
            if(!BlockGroups.Contains(group)) // if you delete from terminal group matches and you delete whole group
                foreach (var g in BlockGroups) //removing group from grid side (grid disconnected, or last block from that grid group removed)
                    if (g.Name.CompareTo(group.Name) == 0)
                    {
                        for (int i = 0; i < g.Blocks.Count; i++ ) 
                        {
                            var b = g.Blocks[i];
                            if (b.CubeGrid == group.CubeGrid) //remove only blocks of that grid from group
                            {
                                g.Blocks.Remove(b);
                                i--;
                            }
                        }
                        if (g.Blocks.Count == 0)
                            group = g; //group to remove
                        else
                            removed = true;
                        break;
                    }

            if (!removed)
                BlockGroups.Remove(group);

            if (GroupRemoved != null && group.CubeGrid == null)
                GroupRemoved(group);
        }
        public void UpdateCubeBlock(MyTerminalBlock block)
        {

            if (block == null)
                return;

            if (m_terminalSystem != null)
            {
                m_terminalSystem.BlockAdded -= TerminalSystem_BlockAdded;
                m_terminalSystem.BlockRemoved -= TerminalSystem_BlockRemoved;
                m_terminalSystem.GroupAdded -= TerminalSystem_GroupAdded;
                m_terminalSystem.GroupRemoved -= TerminalSystem_GroupRemoved;
            }

            var grid = block.CubeGrid;
            m_terminalSystem = grid.GridSystems.TerminalSystem;
            m_tmpGroup = new MyBlockGroup(grid);

            m_terminalSystem.BlockAdded += TerminalSystem_BlockAdded;
            m_terminalSystem.BlockRemoved += TerminalSystem_BlockRemoved;
            m_terminalSystem.GroupAdded += TerminalSystem_GroupAdded;
            m_terminalSystem.GroupRemoved += TerminalSystem_GroupRemoved;

            SelectBlocks(new MyTerminalBlock[] { block });


        }
        public void Init(IMyGuiControlsParent controlsParent, MyPlayer controller, MyCubeGrid grid, MyTerminalBlock currentBlock, MyGridColorHelper colorHelper)
        {
            m_controlsParent = controlsParent;
            m_controller = controller;
            m_colorHelper = colorHelper;

            if (grid == null)
            {
                foreach (var control in controlsParent.Controls)
                    control.Visible = false;

                var label = MyGuiScreenTerminal.CreateErrorLabel(MySpaceTexts.ScreenTerminalError_ShipNotConnected, "ErrorMessage");
                controlsParent.Controls.Add(label);
                return;
            }

            m_terminalSystem = grid.GridSystems.TerminalSystem;
            m_tmpGroup = new MyBlockGroup(grid);

            m_blockSearch = (MyGuiControlTextbox)m_controlsParent.Controls.GetControlByName("FunctionalBlockSearch");
            m_blockSearch.TextChanged += blockSearch_TextChanged;
            m_blockSearchClear = (MyGuiControlButton)m_controlsParent.Controls.GetControlByName("FunctionalBlockSearchClear");
            m_blockSearchClear.ButtonClicked += blockSearchClear_ButtonClicked;
            m_blockListbox = (MyGuiControlListbox)m_controlsParent.Controls.GetControlByName("FunctionalBlockListbox");
            m_blockNameLabel = (MyGuiControlLabel)m_controlsParent.Controls.GetControlByName("BlockNameLabel");
            m_blockNameLabel.Text = "";
            m_groupName = (MyGuiControlTextbox)m_controlsParent.Controls.GetControlByName("GroupName");
            m_groupName.TextChanged += m_groupName_TextChanged;

            m_showAll = (MyGuiControlButton)m_controlsParent.Controls.GetControlByName("ShowAll");
            m_showAll.Selected = m_showAllTerminalBlocks;
            m_showAll.ButtonClicked += showAll_Clicked;
            m_showAll.SetToolTip(MySpaceTexts.Terminal_ShowAllInTerminal);
            m_showAll.IconRotation = 0f;
            m_showAll.Icon = new MyGuiHighlightTexture
                {
                    Normal = @"Textures\GUI\Controls\button_hide.dds",
                    Highlight = @"Textures\GUI\Controls\button_unhide.dds",
                    SizePx = new Vector2(40f, 40f),
                };
            m_showAll.Size = new Vector2(0, 0);

            m_showAll.HighlightType = MyGuiControlHighlightType.FORCED;
            m_showAll.IconOriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP;

            m_groupSave = (MyGuiControlButton)m_controlsParent.Controls.GetControlByName("GroupSave");
            m_groupSave.TextEnum = MySpaceTexts.TerminalButton_GroupSave;
            m_groupSave.TextAlignment = MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER;
            m_groupSave.ButtonClicked += groupSave_ButtonClicked;
            m_groupDelete = (MyGuiControlButton)m_controlsParent.Controls.GetControlByName("GroupDelete");
            m_groupDelete.ButtonClicked += groupDelete_ButtonClicked;
            m_groupDelete.Enabled = false;

            m_blockListbox.ItemsSelected += blockListbox_ItemSelected;

            RefreshBlockList();

            m_terminalSystem.BlockAdded += TerminalSystem_BlockAdded;
            m_terminalSystem.BlockRemoved += TerminalSystem_BlockRemoved;
            m_terminalSystem.GroupAdded += TerminalSystem_GroupAdded;
            m_terminalSystem.GroupRemoved += TerminalSystem_GroupRemoved;
            if (currentBlock != null)
                SelectBlocks(new MyTerminalBlock[] { currentBlock });
        }
Example #17
0
 private static void OnModifyGroupSuccess(MySyncGrid sync, ref ModifyBlockGroupMsg msg, MyNetworkClient sender)
 {
     if (msg.Blocks == null || msg.Blocks.Count() == 0)
         foreach (var group in sync.Entity.BlockGroups)
         {
             if (group.Name.ToString().Equals(msg.Name))
             {
                 sync.Entity.RemoveGroup(group);
                 break;
             }
         }
     else
     {
         MyBlockGroup group = new MyBlockGroup(sync.Entity);
         group.Name.Clear().Append(msg.Name);
         foreach (var blockId in msg.Blocks)
         {
             MyTerminalBlock block = null;
             if (MyEntities.TryGetEntityById(blockId, out block))
                 group.Blocks.Add(block);
         }
         sync.Entity.AddGroup(group);
     }
 }
Example #18
0
 public virtual void RemoveGroup(MyBlockGroup group)
 {
     if (TerminalSystem != null)
     {
         TerminalSystem.GroupRemoved -= m_terminalSystem_GroupRemoved;
         TerminalSystem.RemoveGroup(group);
         TerminalSystem.GroupRemoved += m_terminalSystem_GroupRemoved;
     }
 }
        void previewGrid_OnBlockAdded(MySlimBlock obj)
        {
            m_shouldUpdateProjection = true;
            m_shouldUpdateTexts = true; // Text should always be updated, not only when terminal block is added, armor blocks etc also count!

            //Update groups
            if (m_originalGridBuilder == null || !IsProjecting())
            {
                return;
            }

            Vector3I transformed = ProjectedGrid.WorldToGridInteger(CubeGrid.GridIntegerToWorld(obj.Position));

            var terminalBlock = obj.FatBlock as MyTerminalBlock;
            if (terminalBlock != null)
            {
                foreach (var groupBuilder in m_originalGridBuilder.BlockGroups)
                {
                    foreach (var block in groupBuilder.Blocks)
                    {
                        if (transformed == block)
                        {
                            //Search if group already exits and add the terminal block to it
                            bool found = false;
                            for (int i = 0; i < CubeGrid.BlockGroups.Count; i++)
                            {
                                var group = CubeGrid.BlockGroups[i];
                                if (group.Name.ToString() == groupBuilder.Name)
                                {
                                    if (!group.Blocks.Contains(terminalBlock))
                                    {
                                        MyBlockGroup newGroup = new MyBlockGroup(CubeGrid);
                                        newGroup.Name = group.Name;
                                        newGroup.Blocks.Add(terminalBlock);
                                        newGroup.Blocks.AddList(group.Blocks);

                                        CubeGrid.RemoveGroup(group);

                                        CubeGrid.AddGroup(newGroup);
                                    }
                                    found = true;
                                    break;
                                }
                            }

                            //Group was not found
                            if (!found)
                            {
                                MyBlockGroup newGroup = new MyBlockGroup(CubeGrid);
                                newGroup.Name = new StringBuilder(groupBuilder.Name);
                                newGroup.Blocks.Add(terminalBlock);
                                CubeGrid.AddGroup(newGroup);
                            }
                        }
                    }
                }
            }
        }
Example #20
0
 private void TerminalSystem_GroupAdded(MyBlockGroup group)
 {
     foreach (var g in m_cubeGrid.BlockGroups)
         if (g.Name.CompareTo(group.Name) == 0)
         {
             var oldCount = g.Blocks.Count;
             g.Blocks.Clear();
             foreach (var b in group.Blocks)
                 if (b.CubeGrid == m_cubeGrid)
                     g.Blocks.Add(b);
             if (oldCount != g.Blocks.Count)
                 m_cubeGrid.ModifyGroup(g);
             if (g.Blocks.Count == 0)
                 m_cubeGrid.BlockGroups.Remove(g);
             return;
         }
     var gr = new MyBlockGroup(m_cubeGrid);
     gr.Name.AppendStringBuilder(group.Name);
     foreach (var b in group.Blocks)
         if (b.CubeGrid == m_cubeGrid)
             gr.Blocks.Add(b);
     if (gr.Blocks.Count > 0)
     {
         m_cubeGrid.BlockGroups.Add(gr);
         m_cubeGrid.ModifyGroup(gr);
     }
 }
        public static string GetIconForTerminalGroup(MyBlockGroup group)
        {
            string output = "Textures\\GUI\\Icons\\GroupIcon.dds";
            bool genericType = false;
            var blocks = group.Blocks;
            if (blocks == null || blocks.Count == 0)
                return output;

            MyDefinitionBase def = blocks[0].BlockDefinition;
            foreach (var block in blocks)
            {
                if (!block.BlockDefinition.Equals(def))
                {
                    genericType = true;
                    break;
                }
            }
            if (!genericType)
                output = def.Icon;

            return output;
        }