Ejemplo n.º 1
0
        private void SetToolbarItem <T>(int slot, int page, MyDefinitionId id)
            where T : MyObjectBuilder_ToolbarItemDefinition, new()
        {
            var toolbarItemBuilder = MyObjectBuilderSerializer.CreateNewObject <T>();

            toolbarItemBuilder.DefinitionId = id;

            var toolbar = m_session.Character.Toolbar;
            var owner   = toolbar.Owner;

            //toolbar.Owner = m_session.Character;
            toolbar.SwitchToPage(page);
            var item = MyToolbarItemFactory.CreateToolbarItem(toolbarItemBuilder);

            toolbar.SetItemAtSlot(slot, item);
        }
Ejemplo n.º 2
0
            private static void OnToolbarItemChanged(MySyncAirVent sync, ref ChangeToolbarItemMsg msg, MyNetworkClient sender)
            {
                MyToolbarItem item = null;

                if (msg.Item.EntityID != 0)
                {
                    if (string.IsNullOrEmpty(msg.Item.GroupName))
                    {
                        MyTerminalBlock block;
                        if (MyEntities.TryGetEntityById <MyTerminalBlock>(msg.Item.EntityID, out block))
                        {
                            var builder = MyToolbarItemFactory.TerminalBlockObjectBuilderFromBlock(block);
                            builder.Action     = msg.Item.Action;
                            builder.Parameters = msg.Item.Parameters;
                            item = MyToolbarItemFactory.CreateToolbarItem(builder);
                        }
                    }
                    else
                    {
                        MyAirVent parent;
                        if (MyEntities.TryGetEntityById <MyAirVent>(msg.Item.EntityID, out parent))
                        {
                            var grid      = parent.CubeGrid;
                            var groupName = msg.Item.GroupName;
                            var group     = grid.GridSystems.TerminalSystem.BlockGroups.Find((x) => x.Name.ToString() == groupName);
                            if (group != null)
                            {
                                var builder = MyToolbarItemFactory.TerminalGroupObjectBuilderFromGroup(group);
                                builder.Action        = msg.Item.Action;
                                builder.BlockEntityId = msg.Item.EntityID;
                                builder.Parameters    = msg.Item.Parameters;
                                item = MyToolbarItemFactory.CreateToolbarItem(builder);
                            }
                        }
                    }
                }

                if (msg.Index == 0)
                {
                    sync.m_airVent.m_onFullAction = item;
                }
                else
                {
                    sync.m_airVent.m_onEmptyAction = item;
                }
                sync.m_airVent.RaisePropertiesChanged();
            }
Ejemplo n.º 3
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;
        }
Ejemplo n.º 4
0
        static void OnChangeSlotBuilderItemRequest(ref PlayerToolbarChangeSlotBuilderMsg msg, MyNetworkClient sender)
        {
            var playerId = new PlayerId(sender.SteamUserId, msg.PlayerSerialId);

            if (!MySession.Static.Toolbars.ContainsToolbar(playerId))
            {
                return;
            }

            var tItem   = MyToolbarItemFactory.CreateToolbarItem(msg.itemBuilder);
            var toolbar = MySession.Static.Toolbars.TryGetPlayerToolbar(playerId);

            if (toolbar == null)
            {
                return;
            }
            toolbar.SetItemAtIndex(msg.Index, tItem);
        }
Ejemplo n.º 5
0
            private static void OnToolbarItemChanged(MySyncTimerBlock sync, ref ChangeToolbarItemMsg msg, MyNetworkClient sender)
            {
                sync.m_syncing = true;
                MyToolbarItem item = null;

                if (msg.Item.EntityID != 0)
                {
                    if (string.IsNullOrEmpty(msg.Item.GroupName))
                    {
                        MyTerminalBlock block;
                        if (MyEntities.TryGetEntityById <MyTerminalBlock>(msg.Item.EntityID, out block))
                        {
                            var builder = MyToolbarItemFactory.TerminalBlockObjectBuilderFromBlock(block);
                            builder.Action = msg.Item.Action;
                            item           = MyToolbarItemFactory.CreateToolbarItem(builder);
                        }
                    }
                    else
                    {
                        MyTimerBlock parent;
                        if (MyEntities.TryGetEntityById <MyTimerBlock>(msg.Item.EntityID, out parent))
                        {
                            var grid      = parent.CubeGrid;
                            var groupName = msg.Item.GroupName;
                            var group     = grid.GridSystems.TerminalSystem.BlockGroups.Find((x) => x.Name.ToString() == groupName);;
                            if (group != null)
                            {
                                var builder = MyToolbarItemFactory.TerminalGroupObjectBuilderFromGroup(group);
                                builder.Action        = msg.Item.Action;
                                builder.BlockEntityId = msg.Item.EntityID;
                                item = MyToolbarItemFactory.CreateToolbarItem(builder);
                            }
                        }
                    }
                }
                sync.m_timer.Toolbar.SetItemAtIndex(msg.Index, item);
                sync.m_syncing = false;
                if (Sync.IsServer)
                {
                    Sync.Layer.SendMessageToAll(ref msg);
                }
            }
Ejemplo n.º 6
0
        static void OnChangeSlotBuilderItemRequest(int playerSerialId, int index,
                                                   [Serialize(MyObjectFlags.Dynamic, DynamicSerializerType = typeof(MyObjectBuilderDynamicSerializer))] MyObjectBuilder_ToolbarItem itemBuilder)
        {
            ulong senderId = GetSenderIdSafe();
            var   playerId = new PlayerId(senderId, playerSerialId);

            if (!MySession.Static.Toolbars.ContainsToolbar(playerId))
            {
                return;
            }

            var tItem   = MyToolbarItemFactory.CreateToolbarItem(itemBuilder);
            var toolbar = MySession.Static.Toolbars.TryGetPlayerToolbar(playerId);

            if (toolbar == null)
            {
                return;
            }
            toolbar.SetItemAtIndex(index, tItem);
        }
Ejemplo n.º 7
0
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            SyncFlag = true;

            base.Init(objectBuilder, cubeGrid);

            var builder = (MyObjectBuilder_AirVent)objectBuilder;

            m_isDepressurizing = builder.IsDepressurizing;

            InitializeConveyorEndpoint();
            NeedsUpdate = MyEntityUpdateEnum.EACH_10TH_FRAME | MyEntityUpdateEnum.EACH_100TH_FRAME;

            PowerReceiver = new MyPowerReceiver(
                MyConsumerGroupEnum.Factory,
                false,
                BlockDefinition.OperationalPowerConsumption,
                ComputeRequiredPower);
            PowerReceiver.IsPoweredChanged += PowerReceiver_IsPoweredChanged;
            PowerReceiver.Update();

            m_actionToolbar             = new MyToolbar(MyToolbarType.ButtonPanel, 2, 1);
            m_actionToolbar.DrawNumbers = false;
            m_actionToolbar.Init(null, this);

            if (builder.OnFullAction != null)
            {
                m_onFullAction = MyToolbarItemFactory.CreateToolbarItem(builder.OnFullAction);
            }
            if (builder.OnEmptyAction != null)
            {
                m_onEmptyAction = MyToolbarItemFactory.CreateToolbarItem(builder.OnEmptyAction);
            }

            UpdateEmissivity();
            UdpateTexts();

            AddDebugRenderComponent(new Components.MyDebugRenderComponentDrawConveyorEndpoint(m_conveyorEndpoint));

            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;
        }
Ejemplo n.º 8
0
        public static MyToolbarItem ToItem(ToolbarItem msgItem)
        {
            MyToolbarItem item = null;

            if (msgItem.GunId.HasValue)
            {
                MyObjectBuilder_ToolbarItemWeapon builder = MyToolbarItemFactory.WeaponObjectBuilder();
                builder.defId = msgItem.GunId.Value;
                item          = MyToolbarItemFactory.CreateToolbarItem(builder);
            }
            else 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);
        }
Ejemplo n.º 9
0
        public static MyToolbarItem ToItem(ToolbarItem msgItem)
        {
            MyToolbarItem item = null;

            if (msgItem.GunId != null)
            {
                MyObjectBuilder_ToolbarItemWeapon data = MyToolbarItemFactory.WeaponObjectBuilder();
                data.defId = msgItem.GunId.Value;
                item       = MyToolbarItemFactory.CreateToolbarItem(data);
            }
            else if (string.IsNullOrEmpty(msgItem.GroupName))
            {
                MyTerminalBlock block;
                if (Sandbox.Game.Entities.MyEntities.TryGetEntityById <MyTerminalBlock>(msgItem.EntityID, out block, false))
                {
                    MyObjectBuilder_ToolbarItemTerminalBlock data = MyToolbarItemFactory.TerminalBlockObjectBuilderFromBlock(block);
                    data._Action    = msgItem.Action;
                    data.Parameters = msgItem.Parameters;
                    item            = MyToolbarItemFactory.CreateToolbarItem(data);
                }
            }
            else
            {
                MyCubeBlock block2;
                if (Sandbox.Game.Entities.MyEntities.TryGetEntityById <MyCubeBlock>(msgItem.EntityID, out block2, false))
                {
                    string       groupName = msgItem.GroupName;
                    MyBlockGroup group     = block2.CubeGrid.GridSystems.TerminalSystem.BlockGroups.Find(x => x.Name.ToString() == groupName);
                    if (group != null)
                    {
                        MyObjectBuilder_ToolbarItemTerminalGroup data = MyToolbarItemFactory.TerminalGroupObjectBuilderFromGroup(group);
                        data._Action       = msgItem.Action;
                        data.Parameters    = msgItem.Parameters;
                        data.BlockEntityId = msgItem.EntityID;
                        item = MyToolbarItemFactory.CreateToolbarItem(data);
                    }
                }
            }
            return(item);
        }