Ejemplo n.º 1
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;
 }
Ejemplo n.º 2
0
        void ToolbarItem_EnabledChanged(MyToolbarItem obj)
        {
            // Do not propagate this event when all enabled states are overriden.
            if (EnabledOverride.HasValue)
            {
                return;
            }

            int index = Array.IndexOf(m_items, obj);

            if (ItemEnabledChanged != null && index != -1)
            {
                int slot = IndexToSlot(index);
                if (IsValidSlot(slot))
                {
                    ItemEnabledChanged(this, new SlotArgs()
                    {
                        SlotNumber = slot
                    });
                }
            }
        }
Ejemplo n.º 3
0
 public void SetItemAtSlot(int slot, MyToolbarItem item)
 {
     SetItemAtIndex(SlotToIndex(slot), item);
 }
Ejemplo n.º 4
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.º 5
0
 private void ExecuteAction(MyToolbarItem action)
 {
     m_actionToolbar.SetItemAtIndex(0, action);
     m_actionToolbar.UpdateItem(0);
     m_actionToolbar.ActivateItemAtSlot(0);
     m_actionToolbar.Clear();
 }
Ejemplo n.º 6
0
 public int GetItemIndex(MyToolbarItem item)
 {
     for (int i = 0; i < m_items.Length; ++i)
     {
         if (m_items[i] == item)
         {
             return i;
         }
     }
     return -1;
 }
Ejemplo n.º 7
0
 public void SetItemAtSlot(int slot, MyToolbarItem item)
 {
     SetItemAtIndex(SlotToIndex(slot), item);
 }
Ejemplo n.º 8
0
 void ToolbarItemUpdated(MyToolbarItem obj, MyToolbarItem.ChangeInfo changed)
 {
     if (ItemUpdated != null)
     {
         int index = Array.IndexOf(m_items, obj);
         if (index != -1)
         {
             ItemUpdated(this, new IndexArgs() { ItemIndex = index }, changed);
         }
     }
 }
Ejemplo n.º 9
0
 private void Toolbar_ItemUpdated(MyToolbar toolbar, MyToolbar.IndexArgs args, MyToolbarItem.ChangeInfo changes)
 {
     // Quicker method if only icon changed
     if (changes == MyToolbarItem.ChangeInfo.Icon)
     {
         UpdateItemIcon(toolbar, args);
     }
     else
     {
         UpdateItemAtIndex(toolbar, args.ItemIndex);
     }
 }
Ejemplo n.º 10
0
 private void SetGridItemAt(int slot, MyToolbarItem item, string icon, string subicon, String tooltip, Sandbox.Graphics.GUI.MyGuiControlGrid.ColoredIcon? symbol = null)
 {
     var gridItem = m_toolbarItemsGrid.GetItemAt(slot);
     if (gridItem == null)
     {
         gridItem = new MyGuiControlGrid.Item(
             icon: icon,
             subicon: subicon,
             toolTip: tooltip,
             userData: item);
         if(DrawNumbers)
             gridItem.AddText(MyToolbarComponent.GetSlotControlText(slot));
         //Ammo amount in toolbar
         if (item != null)
             gridItem.AddText(item.IconText, MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_BOTTOM);
         else
             gridItem.ClearText(MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_BOTTOM);
         gridItem.Enabled = (item != null) ? item.Enabled : true;
         if(symbol.HasValue)
             gridItem.AddIcon(symbol.Value, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP);
         m_toolbarItemsGrid.SetItemAt(slot, gridItem);
     }
     else
     {
         gridItem.UserData = item;
         gridItem.Icon = icon;
         gridItem.SubIcon = subicon;
         if (gridItem.ToolTip == null)
             gridItem.ToolTip = new MyToolTips();
         gridItem.ToolTip.ToolTips.Clear();
         gridItem.ToolTip.AddToolTip(tooltip);
         //Ammo amount in toolbar
         if (item != null)
             gridItem.AddText(item.IconText, MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_BOTTOM);
         else
             gridItem.ClearText(MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_BOTTOM);
         gridItem.Enabled = (item != null) ? item.Enabled : true;
         if (symbol.HasValue)
             gridItem.AddIcon(symbol.Value, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP);
     }
 }
Ejemplo n.º 11
0
 private void SetGridItemAt(int slot, MyToolbarItem item)
 {
     if (item != null)
         SetGridItemAt(slot, item, item.Icon, item.SubIcon, item.DisplayName.ToString(), GetSymbol(slot));
     else
         SetGridItemAt(slot, null, null, null, null, GetSymbol(slot));
 }
Ejemplo n.º 12
0
        protected virtual void SetGridItemAt(int slot, MyToolbarItem item, string[] icons, string subicon, String tooltip, MyGuiControlGrid.ColoredIcon? symbol = null, bool clear = false)
        {
            var gridItem = m_toolbarItemsGrid.GetItemAt(slot);

            if (gridItem == null)
            {
                gridItem = new MyGuiControlGrid.Item(
                    icons: icons,
                    subicon: subicon,
                    toolTip: tooltip,
                    userData: item);
                //By Gregory: Changed to IconText for weapon check MyToolbarItemWeapon IconText override
                //if (item != null)
                //    gridItem.AddText(item.IconText, MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_BOTTOM);
                //else
                //    gridItem.ClearText(MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_BOTTOM);
                //gridItem.Enabled = (item != null) ? item.Enabled : true;
                //if (symbol.HasValue)
                //    gridItem.AddIcon(symbol.Value, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP);
                m_toolbarItemsGrid.SetItemAt(slot, gridItem);
            }
            else
            {
                gridItem.UserData = item;
                gridItem.Icons = icons;
                gridItem.SubIcon = subicon;
                if (gridItem.ToolTip == null)
                    gridItem.ToolTip = new MyToolTips();
                gridItem.ToolTip.ToolTips.Clear();
                gridItem.ToolTip.AddToolTip(tooltip);
                //By Gregory: Changed to IconText for weapon check MyToolbarItemWeapon IconText override
                //if (item != null)
                //    gridItem.AddText(item.IconText, MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_BOTTOM);
                //else
                //    gridItem.ClearText(MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_BOTTOM);
                //gridItem.Enabled = (item != null) ? item.Enabled : true;
                //if (symbol.HasValue)
                //    gridItem.AddIcon(symbol.Value, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP);
            }

            if (item == null || clear)
                gridItem.ClearAllText();

            if (DrawNumbers)
                gridItem.AddText(MyToolbarComponent.GetSlotControlText(slot));

            if (item != null)
                item.FillGridItem(gridItem);

            gridItem.Enabled = (item != null) ? item.Enabled : true;
            if (symbol.HasValue)
                gridItem.AddIcon(symbol.Value, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP);

        }
 public static MyObjectBuilder_ToolbarItem CreateObjectBuilder(MyToolbarItem item)
 {
     return m_objectFactory.CreateObjectBuilder<MyObjectBuilder_ToolbarItem>(item);
 }
Ejemplo n.º 14
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;
 }
Ejemplo n.º 15
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.º 16
0
 public void SetItemAtIndex(int i, MyToolbarItem item)
 {
     SetItemAtIndexInternal(i, item, false);
 }
Ejemplo n.º 17
0
        private void SetItemAtIndexInternal(int i, MyToolbarItem item, bool initialization = false)
        {
            if (!m_items.IsValidIndex(i))
                return;

			var definitionItem = item as MyToolbarItemDefinition;
			if (definitionItem != null && definitionItem.Definition != null && !definitionItem.Definition.AvailableInSurvival && MySession.Static.SurvivalMode)
				return;
            
            if (item != null && !item.AllowedInToolbarType(m_toolbarType))
                return;

            bool oldEnabledState = true;
            bool newEnabledState = true;

            if (m_items[i] != null)
            {
                oldEnabledState = m_items[i].Enabled;
                m_items[i].OnClose();
            }

            m_items[i] = item;

            if (m_items[i] != null)
            {
                newEnabledState = true;
            }

            if (initialization)
                return;

            UpdateItem(i);
            if (ItemChanged != null)
                ItemChanged(this, new IndexArgs() { ItemIndex = i });

            if (oldEnabledState != newEnabledState)
            {
                int slot = IndexToSlot(i);
                if (IsValidSlot(slot))
                    SlotEnabledChanged(slot);
            }
        }
Ejemplo n.º 18
0
        public static MyToolbarItem CreateToolbarItem(MyObjectBuilder_ToolbarItem data)
        {
            MyToolbarItem item = m_objectFactory.CreateInstance(data.TypeId);

            return(item.Init(data) ? item : null);
        }
Ejemplo n.º 19
0
        void ToolbarItem_EnabledChanged(MyToolbarItem obj)
        {
            // Do not propagate this event when all enabled states are overriden.
            if (EnabledOverride.HasValue)
                return;

            int index = Array.IndexOf(m_items, obj);

            if (ItemEnabledChanged != null && index != -1)
            {
                int slot = IndexToSlot(index);
                if (IsValidSlot(slot))
                {
                    ItemEnabledChanged(this, new SlotArgs() { SlotNumber = slot });
                }
            }
        }
Ejemplo n.º 20
0
 public static MyObjectBuilder_ToolbarItem CreateObjectBuilder(MyToolbarItem item)
 {
     return(m_objectFactory.CreateObjectBuilder <MyObjectBuilder_ToolbarItem>(item));
 }
Ejemplo n.º 21
0
 public void SetItemAtIndex(int i, MyToolbarItem item)
 {
     SetItemAtIndexInternal(i, item, false);
 }
Ejemplo n.º 22
0
        protected virtual void SetGridItemAt(int slot, MyToolbarItem item, string[] icons, string subicon, String tooltip, MyGuiControlGrid.ColoredIcon?symbol = null, bool clear = false)
        {
            var gridItem = m_toolbarItemsGrid.GetItemAt(slot);

            if (gridItem == null)
            {
                gridItem = new MyGuiControlGrid.Item(
                    icons: icons,
                    subicon: subicon,
                    toolTip: tooltip,
                    userData: item);
                //By Gregory: Changed to IconText for weapon check MyToolbarItemWeapon IconText override
                //if (item != null)
                //    gridItem.AddText(item.IconText, MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_BOTTOM);
                //else
                //    gridItem.ClearText(MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_BOTTOM);
                //gridItem.Enabled = (item != null) ? item.Enabled : true;
                //if (symbol.HasValue)
                //    gridItem.AddIcon(symbol.Value, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP);
                m_toolbarItemsGrid.SetItemAt(slot, gridItem);
            }
            else
            {
                gridItem.UserData = item;
                gridItem.Icons    = icons;
                gridItem.SubIcon  = subicon;
                if (gridItem.ToolTip == null)
                {
                    gridItem.ToolTip = new MyToolTips();
                }
                gridItem.ToolTip.ToolTips.Clear();
                gridItem.ToolTip.AddToolTip(tooltip);
                //By Gregory: Changed to IconText for weapon check MyToolbarItemWeapon IconText override
                //if (item != null)
                //    gridItem.AddText(item.IconText, MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_BOTTOM);
                //else
                //    gridItem.ClearText(MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_BOTTOM);
                //gridItem.Enabled = (item != null) ? item.Enabled : true;
                //if (symbol.HasValue)
                //    gridItem.AddIcon(symbol.Value, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP);
            }

            if (item == null || clear)
            {
                gridItem.ClearAllText();
            }

            if (DrawNumbers)
            {
                gridItem.AddText(MyToolbarComponent.GetSlotControlText(slot));
            }

            if (item != null)
            {
                item.FillGridItem(gridItem);
            }

            gridItem.Enabled = (item != null) ? item.Enabled : true;
            if (symbol.HasValue)
            {
                gridItem.AddIcon(symbol.Value, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP);
            }
        }
Ejemplo n.º 23
0
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            SyncFlag = true;

            base.Init(objectBuilder, cubeGrid);

            var builder = (MyObjectBuilder_AirVent)objectBuilder;

            InitializeConveyorEndpoint();
            NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME;

            SourceComp.Init(BlockDefinition.ResourceSourceGroup, new MyResourceSourceInfo { ResourceTypeId = m_oxygenGasId, DefinedOutput = BlockDefinition.VentilationCapacityPerSecond, ProductionToCapacityMultiplier = 1 });
            SourceComp.OutputChanged += Source_OutputChanged;
            FillSinkInfo();
            var sinkDataList = new List<MyResourceSinkInfo>
	        {
				new MyResourceSinkInfo {ResourceTypeId = MyResourceDistributorComponent.ElectricityId, MaxRequiredInput = BlockDefinition.OperationalPowerConsumption, RequiredInputFunc = ComputeRequiredPower},
	        };

            ResourceSink.Init(
                BlockDefinition.ResourceSinkGroup,
                sinkDataList);
			ResourceSink.IsPoweredChanged += PowerReceiver_IsPoweredChanged;
            ResourceSink.CurrentInputChanged += Sink_CurrentInputChanged;

            m_lastOutputUpdateTime = MySession.Static.GameplayFrameCounter;
            m_lastInputUpdateTime = MySession.Static.GameplayFrameCounter;
            m_nextGasTransfer = 0f;

            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 Sandbox.Game.Components.MyDebugRenderComponentDrawConveyorEndpoint(m_conveyorEndpoint));

            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;
            IsWorkingChanged += MyAirVent_IsWorkingChanged;

            m_isDepressurizing.Value =  builder.IsDepressurizing;

            SetDepressurizing();
        }
Ejemplo n.º 24
0
 void ToolbarItemUpdated(int index, MyToolbarItem.ChangeInfo changed)
 {
     if (m_items.IsValidIndex(index) && ItemUpdated != null)
     {
         ItemUpdated(this, new IndexArgs() { ItemIndex = index }, changed);
     }
 }