Esempio n. 1
0
 public static MyToolbarItem ToItem(ToolbarItem msgItem)
 {
     MyToolbarItem item = null;
     if (string.IsNullOrEmpty(msgItem.GroupName))
     {
         MyTerminalBlock block;
         if (MyEntities.TryGetEntityById(msgItem.EntityID, out block))
         {
             var builder = MyToolbarItemFactory.TerminalBlockObjectBuilderFromBlock(block);
             builder.Action = msgItem.Action;
             builder.Parameters = msgItem.Parameters;
             item = MyToolbarItemFactory.CreateToolbarItem(builder);
         }
     }
     else
     {
         MyCubeBlock parent;
         if (MyEntities.TryGetEntityById(msgItem.EntityID, out parent))
         {
             var grid = parent.CubeGrid;
             var groupName = msgItem.GroupName;
             var group = grid.GridSystems.TerminalSystem.BlockGroups.Find(x => x.Name.ToString() == groupName);
             if (group != null)
             {
                 var builder = MyToolbarItemFactory.TerminalGroupObjectBuilderFromGroup(@group);
                 builder.Action = msgItem.Action;
                 builder.Parameters = msgItem.Parameters;
                 builder.BlockEntityId = msgItem.EntityID;
                 item = MyToolbarItemFactory.CreateToolbarItem(builder);
             }
         }
     }
     return item;
 }
Esempio n. 2
0
 public static ToolbarItem FromItem(MyToolbarItem item)
 {
     var tItem = new ToolbarItem();
     tItem.EntityID = 0;
     var terminalItem = item as MyToolbarItemTerminalBlock;
     if (terminalItem != null)
     {
         var block = item.GetObjectBuilder() as MyObjectBuilder_ToolbarItemTerminalBlock;
         tItem.EntityID = block.BlockEntityId;
         tItem.Action = block._Action;
         tItem.Parameters = block.Parameters;
     }
     else if (item is MyToolbarItemTerminalGroup)
     {
         var block = item.GetObjectBuilder() as MyObjectBuilder_ToolbarItemTerminalGroup;
         tItem.EntityID = block.BlockEntityId;
         tItem.Action = block._Action;
         tItem.GroupName = block.GroupName;
         tItem.Parameters = block.Parameters;
     }
     else if ( item is MyToolbarItemWeapon)
     {
         var weapon = item.GetObjectBuilder() as MyObjectBuilder_ToolbarItemWeapon;
         tItem.GunId = weapon.DefinitionId;
     }
     return tItem;
 }
Esempio n. 3
0
            public void SendToolbarItemChanged(ToolbarItem item, int index)
            {
                if (m_syncing)
                    return;
                var msg = new ChangeToolbarItemMsg();
                msg.EntityId = m_timer.EntityId;
                msg.Item = item;
                msg.Index = index;

                Sync.Layer.SendMessageToServer(ref msg);
            }
Esempio n. 4
0
 void SendToolbarItemChanged(ToolbarItem sentItem, int index)
 {
     m_syncing = true;
     MyToolbarItem item = null;
     if (sentItem.EntityID != 0)
     {
         item = ToolbarItem.ToItem(sentItem);
     }
     Toolbar.SetItemAtIndex(index, item);
     m_syncing = false;
 }
Esempio n. 5
0
        private void OnToolbarItemChanged(ToolbarItem item, int index, int waypointIndex)
        {
            m_syncing = true;
            MyToolbarItem toolbarItem = null;
            if (item.EntityID != 0)
            {
                if (string.IsNullOrEmpty(item.GroupName))
                {
                    MyTerminalBlock block;
                    if (MyEntities.TryGetEntityById<MyTerminalBlock>(item.EntityID, out block))
                    {
                        var builder = MyToolbarItemFactory.TerminalBlockObjectBuilderFromBlock(block);
                        builder._Action = item.Action;
                        builder.Parameters = item.Parameters;
                        toolbarItem = MyToolbarItemFactory.CreateToolbarItem(builder);
                    }
                }
                else
                {
                    MyRemoteControl parent;
                    if (MyEntities.TryGetEntityById<MyRemoteControl>(item.EntityID, out parent))
                    {
                        var grid = parent.CubeGrid;
                        var groupName = item.GroupName;
                        var group = grid.GridSystems.TerminalSystem.BlockGroups.Find((x) => x.Name.ToString() == groupName);
                        if (group != null)
                        {
                            var builder = MyToolbarItemFactory.TerminalGroupObjectBuilderFromGroup(group);
                            builder._Action = item.Action;
                            builder.BlockEntityId = item.EntityID;
                            builder.Parameters = item.Parameters;
                            toolbarItem = MyToolbarItemFactory.CreateToolbarItem(builder);
                        }
                    }
                }
            }

            var waypoint = m_waypoints[waypointIndex];
            if (waypoint.Actions == null)
            {
                waypoint.InitActions();
            }
            waypoint.Actions[index] = toolbarItem;
            RaisePropertiesChangedRemote();
            m_syncing = false;
        }
Esempio n. 6
0
        void SendToolbarItemChanged(ToolbarItem item, int index, int waypointIndex)
        {
            if (m_syncing)
                return;

            MyMultiplayer.RaiseEvent(this, x => x.OnToolbarItemChanged, item, index, waypointIndex);
        }
Esempio n. 7
0
        void SendToolbarItemChanged(ToolbarItem sentItem, int index)
        {
            m_syncing = true;
            MyToolbarItem item = null;
            if (sentItem.EntityID != 0)
            {
                if (string.IsNullOrEmpty(sentItem.GroupName))
                {
                    MyTerminalBlock block;
                    if (MyEntities.TryGetEntityById<MyTerminalBlock>(sentItem.EntityID, out block))
                    {
                        var builder = MyToolbarItemFactory.TerminalBlockObjectBuilderFromBlock(block);
                        builder._Action = sentItem.Action;
                        builder.Parameters = sentItem.Parameters;
                        item = MyToolbarItemFactory.CreateToolbarItem(builder);
                    }
                }
                else
                {

                    var grid = CubeGrid;
                    var groupName = sentItem.GroupName;
                    var group = grid.GridSystems.TerminalSystem.BlockGroups.Find((x) => x.Name.ToString() == groupName);
                    if (group != null)
                    {
                        var builder = MyToolbarItemFactory.TerminalGroupObjectBuilderFromGroup(group);
                        builder._Action = sentItem.Action;
                        builder.BlockEntityId = sentItem.EntityID;
                        builder.Parameters = sentItem.Parameters;
                        item = MyToolbarItemFactory.CreateToolbarItem(builder);
                    }
                }
            }

            if (index == 0)
            {
                m_onFullAction = item;
            }
            else
            {
                m_onEmptyAction = item;
            }
            RaisePropertiesChanged();
            m_syncing = false;
        }
Esempio n. 8
0
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            SyncFlag = true;
            base.Init(objectBuilder, cubeGrid);

            m_items = new List <ToolbarItem>(2);
            for (int i = 0; i < 2; i++)
            {
                m_items.Add(new ToolbarItem()
                {
                    EntityID = 0
                });
            }
            Toolbar             = new MyToolbar(MyToolbarType.ButtonPanel, 2, 1);
            Toolbar.DrawNumbers = false;

            var builder = (MyObjectBuilder_SensorBlock)objectBuilder;

            m_fieldMin = Vector3.Clamp(builder.FieldMin, new Vector3(-MaxRange), -Vector3.One);
            m_fieldMax = Vector3.Clamp(builder.FieldMax, Vector3.One, new Vector3(MaxRange));

            PlayProximitySound    = builder.PlaySound;
            DetectPlayers         = builder.DetectPlayers;
            DetectFloatingObjects = builder.DetectFloatingObjects;
            DetectSmallShips      = builder.DetectSmallShips;
            DetectLargeShips      = builder.DetectLargeShips;
            DetectStations        = builder.DetectStations;
            DetectAsteroids       = builder.DetectAsteroids;
            DetectOwner           = builder.DetectOwner;
            DetectFriendly        = builder.DetectFriendly;
            DetectNeutral         = builder.DetectNeutral;
            DetectEnemy           = builder.DetectEnemy;
            m_active = builder.IsActive;

            Toolbar.Init(builder.Toolbar, this);

            for (int i = 0; i < 2; i++)
            {
                var item = Toolbar.GetItemAtIndex(i);
                if (item == null)
                {
                    continue;
                }
                m_items.RemoveAt(i);
                m_items.Insert(i, ToolbarItem.FromItem(item));
            }
            Toolbar.ItemChanged += Toolbar_ItemChanged;

            NeedsUpdate |= MyEntityUpdateEnum.EACH_10TH_FRAME;

            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;

            var sinkComp = new MyResourceSinkComponent();

            sinkComp.Init(
                BlockDefinition.ResourceSinkGroup,
                BlockDefinition.RequiredPowerInput,
                this.CalculateRequiredPowerInput);
            ResourceSink = sinkComp;
            ResourceSink.IsPoweredChanged     += Receiver_IsPoweredChanged;
            ResourceSink.RequiredInputChanged += Receiver_RequiredInputChanged;
            ResourceSink.Update();

            m_fieldShape = GetHkShape();

            OnClose += delegate(MyEntity self)
            {
                m_fieldShape.RemoveReference();
            };
        }
Esempio n. 9
0
 private ToolbarItem GetToolbarItem(MyToolbarItem item)
 {
     var tItem = new ToolbarItem();
     tItem.EntityID = 0;
     if (item is MyToolbarItemTerminalBlock)
     {
         var block = item.GetObjectBuilder() as MyObjectBuilder_ToolbarItemTerminalBlock;
         tItem.EntityID = block.BlockEntityId;
         tItem.Action = block.Action;
     }
     else if (item is MyToolbarItemTerminalGroup)
     {
         var block = item.GetObjectBuilder() as MyObjectBuilder_ToolbarItemTerminalGroup;
         tItem.EntityID = block.BlockEntityId;
         tItem.Action = block.Action;
         tItem.GroupName = block.GroupName;
     }
     return tItem;
 }
Esempio n. 10
0
 private void Toolbar_ItemChanged(MyToolbar self, MyToolbar.IndexArgs index)
 {
     SyncObject.SendToolbarItemChanged(ToolbarItem.FromItem(self.GetItemAtIndex(index.ItemIndex)), index.ItemIndex);
 }
Esempio n. 11
0
            public void SendToolbarItemChanged(ToolbarItem item, int index, int waypointIndex)
            {
                if (m_syncing)
                    return;
                var msg = new ChangeToolbarItemMsg();
                msg.EntityId = m_remoteControl.EntityId;

                msg.Item = item;
                msg.Index = index;
                msg.WaypointIndex = waypointIndex;

                Sync.Layer.SendMessageToServerAndSelf(ref msg);
            }
Esempio n. 12
0
            public void SendToolbarItemChanged(ToolbarItem item, int index)
            {
                var msg = new ChangeToolbarItemMsg();
                msg.EntityId = m_airVent.EntityId;

                msg.Item = item;
                msg.Index = index;

                Sync.Layer.SendMessageToServerAndSelf(ref msg);
            }