コード例 #1
0
        public MyTSSEnergyHydrogen(Sandbox.ModAPI.IMyTextSurface surface, VRage.Game.ModAPI.IMyCubeBlock block, Vector2 size)
            : base((Sandbox.ModAPI.Ingame.IMyTextSurface)surface, (VRage.Game.ModAPI.Ingame.IMyCubeBlock)block, size)
        {
            this.m_innerSize = new Vector2(MyTSSEnergyHydrogen.ASPECT_RATIO, 1f);
            MyTextSurfaceScriptBase.FitRect(size, ref this.m_innerSize);
            this.m_decorationSize = new Vector2(0.012f * this.m_innerSize.X, MyTSSEnergyHydrogen.DECORATION_RATIO * this.m_innerSize.Y);
            this.m_sb.Clear();
            this.m_sb.Append("Power Usage: 00.000");
            Vector2 vector2 = MyGuiManager.MeasureStringRaw(this.m_fontId, this.m_sb, 1f);
            float   val2    = MyTSSEnergyHydrogen.TEXT_RATIO * this.m_innerSize.Y / vector2.Y;

            this.m_fontScale  = Math.Min(this.m_innerSize.X * 0.72f / vector2.X, val2);
            this.m_firstLine  = this.m_halfSize.Y - this.m_decorationSize.Y * 0.55f;
            this.m_secondLine = this.m_halfSize.Y + this.m_decorationSize.Y * 0.55f;
            if (this.m_block == null)
            {
                return;
            }
            this.m_grid = this.m_block.CubeGrid as MyCubeGrid;
            if (this.m_grid == null)
            {
                return;
            }
            this.m_resourceDistributor = this.m_grid.GridSystems.ResourceDistributor;
            this.m_grid.GridSystems.ConveyorSystem.BlockAdded   += new Action <MyCubeBlock>(this.ConveyorSystemOnBlockAdded);
            this.m_grid.GridSystems.ConveyorSystem.BlockRemoved += new Action <MyCubeBlock>(this.ConveyorSystemOnBlockRemoved);
            this.Recalculate();
        }
コード例 #2
0
        public virtual void OnAddedToGroup(MyGridLogicalGroupData group)
        {
            this.TerminalSystem      = group.TerminalSystem;
            this.ResourceDistributor = group.ResourceDistributor;
            this.WeaponSystem        = group.WeaponSystem;
            if (string.IsNullOrEmpty(this.ResourceDistributor.DebugName))
            {
                this.ResourceDistributor.DebugName = this.m_cubeGrid.ToString();
            }
            this.m_cubeGrid.OnFatBlockAdded   += new Action <MyCubeBlock>(this.ResourceDistributor.CubeGrid_OnFatBlockAddedOrRemoved);
            this.m_cubeGrid.OnFatBlockRemoved += new Action <MyCubeBlock>(this.ResourceDistributor.CubeGrid_OnFatBlockAddedOrRemoved);
            this.ResourceDistributor.AddSink(this.GyroSystem.ResourceSink);
            this.ResourceDistributor.AddSink(this.ConveyorSystem.ResourceSink);
            this.ConveyorSystem.ResourceSink.IsPoweredChanged += new Action(this.ResourceDistributor.ConveyorSystem_OnPoweredChanged);
            foreach (MyBlockGroup group2 in this.m_cubeGrid.BlockGroups)
            {
                this.TerminalSystem.AddUpdateGroup(group2, false, false);
            }
            this.TerminalSystem.GroupAdded   += this.m_terminalSystem_GroupAdded;
            this.TerminalSystem.GroupRemoved += this.m_terminalSystem_GroupRemoved;
            foreach (MyCubeBlock block in this.m_cubeGrid.GetFatBlocks())
            {
                if (!block.MarkedForClose)
                {
                    MyTerminalBlock block2 = block as MyTerminalBlock;
                    if (block2 != null)
                    {
                        this.TerminalSystem.Add(block2);
                    }
                    MyResourceSourceComponent source = block.Components.Get <MyResourceSourceComponent>();
                    if (source != null)
                    {
                        this.ResourceDistributor.AddSource(source);
                    }
                    MyResourceSinkComponent sink = block.Components.Get <MyResourceSinkComponent>();
                    if (sink != null)
                    {
                        this.ResourceDistributor.AddSink(sink);
                    }
                    IMyRechargeSocketOwner owner = block as IMyRechargeSocketOwner;
                    if (owner != null)
                    {
                        owner.RechargeSocket.ResourceDistributor = group.ResourceDistributor;
                    }
                    IMyGunObject <MyDeviceBase> gun = block as IMyGunObject <MyDeviceBase>;
                    if (gun != null)
                    {
                        this.WeaponSystem.Register(gun);
                    }
                }
            }
            MyResourceDistributorComponent resourceDistributor = this.ResourceDistributor;

            resourceDistributor.OnPowerGenerationChanged = (Action <bool>)Delegate.Combine(resourceDistributor.OnPowerGenerationChanged, new Action <bool>(this.OnPowerGenerationChanged));
            this.TerminalSystem.BlockManipulationFinishedFunction();
            this.ResourceDistributor.UpdateBeforeSimulation();
        }
コード例 #3
0
        public void Reload()
        {
            if (m_groupNames == null && MyResourceDistributorComponent.SinkGroupPrioritiesTotal != -1)
            {
                m_groupNames = new MyStringId[MyResourceDistributorComponent.SinkGroupPrioritiesTotal];

                GroupCount            = m_groupNames.Length;
                m_missingPowerByGroup = new float[GroupCount];
                WorkingGroupCount     = GroupCount;

                m_data = new MyHudNameValueData(GroupCount + 1, showBackgroundFog: true);
            }

            if (m_groupNames == null)
            {
                return;
            }

            MyResourceDistributorComponent.InitializeMappings();
            var distributionGroups = MyDefinitionManager.Static.GetDefinitionsOfType <MyResourceDistributionGroupDefinition>();

            var sinkSubtypesToIndex = MyResourceDistributorComponent.SinkSubtypesToPriority;

            foreach (var distributionGroup in distributionGroups)
            {
                if (!distributionGroup.IsSource)
                {
                    int priorityIndex;
                    if (!sinkSubtypesToIndex.TryGetValue(distributionGroup.Id.SubtypeId, out priorityIndex))
                    {
                        Debug.Fail("Sink subtype " + distributionGroup.Id.SubtypeName + " not found!");
                        continue;
                    }
                    m_groupNames[priorityIndex] = MyStringId.GetOrCompute(distributionGroup.Id.SubtypeName);
                }
            }

            /*      m_groupNames[(int)MyResourceSinkGroupEnum.Charging]     = MySpaceTexts.HudEnergyGroupCharging;
             * m_groupNames[(int)MyResourceSinkGroupEnum.Conveyors]    = MySpaceTexts.HudEnergyGroupConveyors;
             * m_groupNames[(int)MyResourceSinkGroupEnum.Defense]      = MySpaceTexts.HudEnergyGroupDefense;
             * m_groupNames[(int)MyResourceSinkGroupEnum.Doors]        = MySpaceTexts.HudEnergyGroupDoors;
             * m_groupNames[(int)MyResourceSinkGroupEnum.Factory]      = MySpaceTexts.HudEnergyGroupFactory;
             * m_groupNames[(int)MyResourceSinkGroupEnum.Gyro]         = MySpaceTexts.HudEnergyGroupGyroscope;
             * m_groupNames[(int)MyResourceSinkGroupEnum.Thrust]       = MySpaceTexts.HudEnergyGroupThrust;
             * m_groupNames[(int)MyResourceSinkGroupEnum.Utility]      = MySpaceTexts.HudEnergyGroupUtility;
             * m_groupNames[(int)MyResourceSinkGroupEnum.BatteryBlock] = MySpaceTexts.HudEnergyGroupBatteries;*/
            Data[GroupCount].NameFont  = MyFontEnum.Red;
            Data[GroupCount].ValueFont = MyFontEnum.Red;
        }
コード例 #4
0
 public MyGridLogicalGroupData(string debugName)
 {
     ResourceDistributor = new MyResourceDistributorComponent(debugName);
 }
コード例 #5
0
 public override void Run()
 {
     base.Run();
     using (MySpriteDrawFrame frame = this.m_surface.DrawFrame())
     {
         this.AddBackground(frame, new Color?(new Color(this.m_foregroundColor, 0.66f)));
         if (this.m_resourceDistributor == null && this.m_grid != null)
         {
             this.m_resourceDistributor = this.m_grid.GridSystems.ResourceDistributor;
         }
         if (this.m_resourceDistributor == null)
         {
             return;
         }
         Color barBgColor = new Color(this.m_foregroundColor, 0.1f);
         float x          = this.m_innerSize.X * 0.5f;
         float num1       = x * 0.06f;
         float max        = this.m_resourceDistributor.MaxAvailableResourceByType(MyResourceDistributorComponent.ElectricityId);
         float num2       = MyMath.Clamp(this.m_resourceDistributor.TotalRequiredInputByType(MyResourceDistributorComponent.ElectricityId), 0.0f, max);
         float ratio1     = (double)max > 0.0 ? num2 / max : 0.0f;
         this.m_sb.Clear();
         this.m_sb.Append("[");
         Vector2 vector2_1 = MyGuiManager.MeasureStringRaw(this.m_fontId, this.m_sb, this.m_decorationSize.Y / MyGuiManager.MeasureStringRaw(this.m_fontId, this.m_sb, 1f).Y);
         this.m_sb.Clear();
         this.m_sb.Append(string.Format("{0:0}", (object)(float)((double)ratio1 * 100.0)));
         Vector2  vector2_2 = MyGuiManager.MeasureStringRaw(this.m_fontId, this.m_sb, this.m_fontScale);
         MySprite sprite1   = new MySprite()
         {
             Position        = new Vector2?(new Vector2(this.m_halfSize.X + x * 0.6f - num1, this.m_firstLine - vector2_2.Y * 0.5f)),
             Size            = new Vector2?(new Vector2(this.m_innerSize.X, this.m_innerSize.Y)),
             Type            = SpriteType.TEXT,
             FontId          = this.m_fontId,
             Alignment       = TextAlignment.LEFT,
             Color           = new Color?(this.m_foregroundColor),
             RotationOrScale = this.m_fontScale,
             Data            = this.m_sb.ToString()
         };
         frame.Add(sprite1);
         MySprite sprite2 = new MySprite(SpriteType.TEXTURE, MyTSSEnergyHydrogen.ENERGY_ICON, new Vector2?(), new Vector2?(), new Color?(this.m_foregroundColor), (string)null, TextAlignment.CENTER, 0.0f)
         {
             Position = new Vector2?(new Vector2(this.m_halfSize.X - x * 0.6f - num1, this.m_firstLine)),
             Size     = new Vector2?(new Vector2(vector2_1.Y * 0.6f))
         };
         frame.Add(sprite2);
         this.AddProgressBar(frame, new Vector2(this.m_halfSize.X - num1, this.m_firstLine), new Vector2(x, vector2_1.Y * 0.4f), ratio1, barBgColor, this.m_foregroundColor, (string)null, (string)null);
         float num3 = 0.0f;
         foreach (Sandbox.Game.Entities.Interfaces.IMyGasTank tankBlock in this.m_tankBlocks)
         {
             num3 += (float)tankBlock.FilledRatio * tankBlock.GasCapacity;
         }
         float ratio2 = (double)this.m_maxHydrogen > 0.0 ? num3 / this.m_maxHydrogen : 0.0f;
         this.m_sb.Clear();
         this.m_sb.Append(string.Format("{0:0}", (object)(float)((double)ratio2 * 100.0)));
         Vector2  vector2_3 = MyGuiManager.MeasureStringRaw(this.m_fontId, this.m_sb, this.m_fontScale);
         MySprite mySprite  = new MySprite();
         mySprite.Position        = new Vector2?(new Vector2(this.m_halfSize.X + x * 0.6f - num1, this.m_secondLine - vector2_3.Y * 0.5f));
         mySprite.Size            = new Vector2?(new Vector2(this.m_innerSize.X, this.m_innerSize.Y));
         mySprite.Type            = SpriteType.TEXT;
         mySprite.FontId          = this.m_fontId;
         mySprite.Alignment       = TextAlignment.LEFT;
         mySprite.Color           = new Color?(this.m_foregroundColor);
         mySprite.RotationOrScale = this.m_fontScale;
         mySprite.Data            = this.m_sb.ToString();
         MySprite sprite3 = mySprite;
         frame.Add(sprite3);
         mySprite          = new MySprite(SpriteType.TEXTURE, MyTSSEnergyHydrogen.HYDROGEN_ICON, new Vector2?(), new Vector2?(), new Color?(this.m_foregroundColor), (string)null, TextAlignment.CENTER, 0.0f);
         mySprite.Position = new Vector2?(new Vector2(this.m_halfSize.X - x * 0.6f - num1, this.m_secondLine));
         mySprite.Size     = new Vector2?(new Vector2(vector2_1.Y * 0.6f));
         MySprite sprite4 = mySprite;
         frame.Add(sprite4);
         this.AddProgressBar(frame, new Vector2(this.m_halfSize.X - num1, this.m_secondLine), new Vector2(x, vector2_1.Y * 0.4f), ratio2, barBgColor, this.m_foregroundColor, (string)null, (string)null);
         float scale = (float)((double)this.m_innerSize.Y / 256.0 * 0.899999976158142);
         this.AddBrackets(frame, new Vector2(64f, 256f), scale);
     }
 }