Exemplo n.º 1
0
 public MyCondition(IMyVariableStorage <T> storage, MyOperation operation, T leftSideValue, string rightSideStorage)
 {
     Debug.Assert(storage != null, "Variable storage must not be null.");
     m_storage          = storage;
     m_operation        = operation;
     m_leftSideStorage  = MyStringId.NullOrEmpty;
     m_rightSideStorage = MyStringId.GetOrCompute(rightSideStorage);
     m_leftSideValue    = leftSideValue;
 }
Exemplo n.º 2
0
        internal void Play()
        {
            for (int cnt = 0; cnt < 50; cnt++)
            {
                var         norm  = MyUtils.GetRandomVector3Normalized();
                PointSpread point = new PointSpread(norm, m_center + Vector3D.Multiply(norm, MyUtils.GetRandomFloat(10, 50)));
                points.Add(point);
            }
            count++;
            if (count < 120)
            {
                foreach (var point in points)
                {
                    var      color = Color.LightBlue.ToVector4();
                    Vector3D vec   = Vector3D.Lerp(point.pos, m_center, count / 120d);
                    var      cnter = Vector3D.Lerp(vec, m_center, 0.2);

                    MySimpleObjectDraw.DrawLine(vec, cnter, MyStringId.GetOrCompute("particle_laser"), ref color, 0.1f);
                }
                if (count == 42 && CoreWarpExplode.instance.isSpecial)
                {
                    cena = new MyEntity3DSoundEmitter(null);
                    cena.SetPosition(m_center);
                    cena.SetVelocity(Vector3.Zero);
                    MySoundPair m_bombExpl = new MySoundPair("ArcWepLrgCENAExpl");
                    cena.CustomMaxDistance = (float)Math.Pow(50, 2);
                    cena.CustomVolume      = 15f;
                    cena.PlaySingleSound(m_bombExpl, true);
                }
            }
            else if (count < 150)
            {
                if (count == 120)
                {
                    emitter = new MyEntity3DSoundEmitter(null);
                    emitter.SetPosition(m_center);
                    emitter.SetVelocity(Vector3.Zero);
                    MySoundPair m_bombExpl = new MySoundPair("ArcWepLrgWarheadExpl");
                    emitter.CustomMaxDistance = (float)Math.Pow(50, 2);
                    emitter.CustomVolume      = 15f;
                    emitter.PlaySingleSound(m_bombExpl, true);
                }

                foreach (var point in points)
                {
                    var      color = Color.LightBlue.ToVector4();
                    Vector3D vec   = Vector3D.Lerp(point.pos, m_center, (120 - count * 4d) / 120d);
                    var      cnter = Vector3D.Lerp(vec, m_center, 0.2);

                    MySimpleObjectDraw.DrawLine(vec, cnter, MyStringId.GetOrCompute("particle_laser"), ref color, 0.1f);
                }
            }
            else
            {
                done = true;
            }
        }
Exemplo n.º 3
0
        public static void DrawOBB(MyOrientedBoundingBoxD obb, Color color, MySimpleObjectRasterizer raster = MySimpleObjectRasterizer.Wireframe, float thickness = 0.01f)
        {
            var material = MyStringId.GetOrCompute("Square");
            var box      = new BoundingBoxD(-obb.HalfExtent, obb.HalfExtent);
            var wm       = MatrixD.CreateFromQuaternion(obb.Orientation);

            wm.Translation = obb.Center;
            MySimpleObjectDraw.DrawTransparentBox(ref wm, ref box, ref color, raster, 1, thickness, material, material);
        }
Exemplo n.º 4
0
        public static void TriggerAnimationEvent(long entityId, string eventName)
        {
            MyCharacter character = MyEntities.GetEntityByIdOrDefault(entityId, null) as MyCharacter;

            if (character != null)
            {
                character.AnimationController.TriggerAction(MyStringId.GetOrCompute(eventName));
            }
        }
Exemplo n.º 5
0
        //protected static IMyTerminalControlButton SaveButton;
        protected void CreateTerminalControls <T>()
        {
            if (m_ControlsInited.Contains(typeof(T)))
            {
                return;
            }
            m_ControlsInited.Add(typeof(T));
            if (Seperator == null)
            {
                Seperator         = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlSeparator, T>(string.Empty);
                Seperator.Visible = (b) => b.IsRadar();
            }
            MyAPIGateway.TerminalControls.AddControl <T>(Seperator);
            if (RangeControl == null)
            {
                RangeControl         = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlSlider, T>("Draygo.Radar.Range");
                RangeControl.Visible = (b) => b.IsRadar();                // b.IsRadar();
                RangeControl.Enabled = (b) => b.IsRadar();
                RangeControl.Getter  = (b) => b.GameLogic.GetAs <Radar>().Range;
                RangeControl.Writer  = (b, v) => v.AppendFormat("{0:N1} {1}", b.GameLogic.GetAs <Radar>().Range, MyStringId.GetOrCompute("km"));
                RangeControl.Setter  = (b, v) => b.GameLogic.GetAs <Radar>().Range = v;
                RangeControl.Title   = MyStringId.GetOrCompute("Range");
                RangeControl.Tooltip = MyStringId.GetOrCompute("Range in KM");
                RangeControl.SupportsMultipleBlocks = true;
                RangeControl.SetLimits(0.001f, 50.0f);
            }
            MyAPIGateway.TerminalControls.AddControl <T>(RangeControl);
            if (Seperator2 == null)
            {
                Seperator2         = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlSeparator, T>(string.Empty);
                Seperator2.Visible = (b) => b.IsRadar();
            }
            MyAPIGateway.TerminalControls.AddControl <T>(Seperator2);
            //MyAPIGateway.TerminalControls.AddControl<T>(RangeControl);
            //if (PitchCheck == null)
            //{
            //	PitchCheck = MyAPIGateway.TerminalControls.CreateControl<IMyTerminalControlCheckbox, IMyTerminalBlock>("Draygo.ControlSurface.Pitch");
            //	PitchCheck.Visible = (b) => b.IsControlSurface();
            //	PitchCheck.Enabled = (b) => b.IsControlSurface() && b.IsWorking;
            //	PitchCheck.Getter = (b) => b.GameLogic.GetAs<Holo>().Control.EnablePitch;
            //	PitchCheck.Setter = (b, v) => b.GameLogic.GetAs<Holo>().Control.EnablePitch = v;
            //	PitchCheck.Title = MyStringId.GetOrCompute("Pitch");
            //	PitchCheck.Tooltip = MyStringId.GetOrCompute("Enable Pitch Control");
            //	PitchCheck.SupportsMultipleBlocks = true;
            //}
            //MyAPIGateway.TerminalControls.AddControl<T>(PitchCheck);
            var RangeProperty = MyAPIGateway.TerminalControls.CreateProperty <float, T>("Radar.Range");

            if (RangeProperty != null)
            {
                RangeProperty.Enabled = (b) => b.IsRadar();
                RangeProperty.Getter  = (b) => b.GameLogic.GetAs <Radar>().Range;
                RangeProperty.Setter  = (b, v) => b.GameLogic.GetAs <Radar>().Range = v;
                MyAPIGateway.TerminalControls.AddControl <T>(RangeProperty);
            }
        }
Exemplo n.º 6
0
        private void Compile(IEnumerable <string> scriptFiles, string assemblyName, bool zipped)
        {
            Assembly assembly = null;
            var      c        = new MyModContext();

            c.Init(assemblyName, assemblyName);
            if (zipped)
            {
                var tmp = Path.GetTempPath();
                foreach (var file in scriptFiles)
                {
                    try
                    {
                        var newPath = string.Format("{0}{1}", tmp, Path.GetFileName(file));
                        var stream  = MyFileSystem.OpenRead(file);
                        using (var sr = new StreamReader(stream))
                        {
                            stream = MyFileSystem.OpenWrite(newPath);// (newPath);
                            using (var sw = new StreamWriter(stream))
                            {
                                sw.Write(sr.ReadToEnd()); //create file in tmp for debugging
                            }
                        }
                        m_cachedFiles.Add(newPath);
                    }
                    catch (Exception e)
                    {
                        MySandboxGame.Log.WriteLine(e);
                        MyDefinitionErrors.Add(c, string.Format("Cannot load {0}", Path.GetFileName(file)), ErrorSeverity.Error);
                        MyDefinitionErrors.Add(c, e.Message, ErrorSeverity.Error);
                    }
                }
                IlCompiler.CompileFileModAPI(assemblyName, m_cachedFiles.ToArray(), out assembly, m_errors);
            }
            else
            {
                IlCompiler.CompileFileModAPI(assemblyName, scriptFiles.ToArray(), out assembly, m_errors);
            }
            if (assembly != null)
            {
                AddAssembly(MyStringId.GetOrCompute(assemblyName), assembly);
            }
            else
            {
                MyDefinitionErrors.Add(c, string.Format("Compilation of {0} failed:", assemblyName), ErrorSeverity.Error);
                MySandboxGame.Log.IncreaseIndent();
                foreach (var error in m_errors)
                {
                    MyDefinitionErrors.Add(c, error.ToString(), ErrorSeverity.Error);
                    Debug.Assert(false, error.ToString());
                }
                MySandboxGame.Log.DecreaseIndent();
                m_errors.Clear();
            }
            m_cachedFiles.Clear();
        }
Exemplo n.º 7
0
 public static void FillFontComboBoxContent(List <MyTerminalControlComboBoxItem> items)
 {
     foreach (var font in MyDefinitionManager.Static.GetFontDefinitions())
     {
         items.Add(new MyTerminalControlComboBoxItem()
         {
             Key = (long)(font.Id.SubtypeId), Value = MyStringId.GetOrCompute(font.Id.SubtypeName)
         });
     }
 }
Exemplo n.º 8
0
        private void DrawLine(Vector3D startPos, Vector3D endPos, float rad)
        {
            Vector4 baseCol  = Color.LightBlue;
            string  material = "WeaponLaser";
            float   ranf     = MyUtils.GetRandomFloat(0.75f * rad, 1.5f * rad);

            MySimpleObjectDraw.DrawLine(startPos, endPos, MyStringId.GetOrCompute(material), ref baseCol, ranf);
            MySimpleObjectDraw.DrawLine(startPos, endPos, MyStringId.GetOrCompute(material), ref baseCol, ranf * 0.66f);
            MySimpleObjectDraw.DrawLine(startPos, endPos, MyStringId.GetOrCompute(material), ref baseCol, ranf * 0.33f);
        }
Exemplo n.º 9
0
        internal static void CreateCurrentList(IMyTerminalBlock block, List <MyTerminalControlListBoxItem> listItems, List <MyTerminalControlListBoxItem> selectedItems)
        {
            FilteredContainer component = block?.GameLogic?.GetAs <FilteredContainer>();

            foreach (var item in component.FilterController.FilterList)
            {
                var listitem = new MyTerminalControlListBoxItem(MyStringId.GetOrCompute(item.DisplayName), MyStringId.NullOrEmpty, item);
                listItems.Add(listitem);
            }
        }
Exemplo n.º 10
0
        public static void DrawLineToVec(Vector3D fromVec, Vector3D toVec, Vector4 color, float lineWidth)
        {
            var c      = color;
            var lineId = MyStringId.GetOrCompute("Square");

            var v0 = toVec;
            var v1 = fromVec;

            MySimpleObjectDraw.DrawLine(v0, v1, lineId, ref c, lineWidth);
        }
Exemplo n.º 11
0
 public static MyStringId GetStringId(Dictionary <string, string> texts, string key)
 {
     try{
         return(MyStringId.GetOrCompute(texts[key]));
     }
     catch (Exception ex)
     {
         throw new Exception($"GetStringId Failed for Key={key}", ex);
     }
 }
Exemplo n.º 12
0
 private static void ListDirections(List <MyTerminalControlComboBoxItem> list)
 {
     for (int index = 0; index < Base6Directions.EnumDirections.Length; index++)
     {
         list.Add(new MyTerminalControlComboBoxItem()
         {
             Key = index, Value = MyStringId.GetOrCompute(Base6Directions.EnumDirections[index].ToString())
         });
     }
 }
Exemplo n.º 13
0
        public static void DrawSphere(BoundingSphereD sphere, Color color)
        {
            var rangeGridResourceId = MyStringId.GetOrCompute("Build new");
            var radius      = sphere.Radius;
            var transMatrix = MatrixD.CreateTranslation(sphere.Center);

            //var wm = MatrixD.Rescale(transMatrix, radius);

            MySimpleObjectDraw.DrawTransparentSphere(ref transMatrix, (float)radius, ref color, MySimpleObjectRasterizer.Wireframe, 20, null, rangeGridResourceId, -1, -1);
        }
Exemplo n.º 14
0
        public void DrawPackets()
        {
            UpdatePackets();

            foreach (PacketItem packet in _packets)
            {
                //thanks to Digi for showing me how this thing works
                MyTransparentGeometry.AddPointBillboard(MyStringId.GetOrCompute("ShipyardPacket"), Color, packet.Position, 0.3f, packet.Ticks);
            }
        }
Exemplo n.º 15
0
        public static void DrawLineToNum(Vector3D[] physicsVerts, int num, Vector3D fromVec, Color color)
        {
            var c      = color.ToVector4();
            var lineId = MyStringId.GetOrCompute("Square");

            var v0 = physicsVerts[num];
            var v1 = fromVec;

            MySimpleObjectDraw.DrawLine(v0, v1, lineId, ref c, 0.35f);
        }
 private MyTerminalControlListBoxItem GetListBoxItem(string name, int r, int g, int b)
 {
     return(new MyTerminalControlListBoxItem(MyStringId.GetOrCompute(name), MyStringId.GetOrCompute(name),
                                             new LightPresetData()
     {
         Falloff = 2f,
         Intensity = 1f,
         LightColor = new Color(r, g, b)
     }));
 }
Exemplo n.º 17
0
        protected override void Init(MyObjectBuilder_DefinitionBase builder)
        {
            base.Init(builder);
            var ob = builder as MyObjectBuilder_ScenarioDefinition;

            AsteroidClustersEnabled = ob.AsteroidClusters.Enabled;
            AsteroidClustersOffset  = ob.AsteroidClusters.Offset;
            CentralClusterEnabled   = ob.AsteroidClusters.CentralCluster;
            CreativeDefaultToolbar  = ob.CreativeDefaultToolbar;
            SurvivalDefaultToolbar  = ob.SurvivalDefaultToolbar;
            MainCharacterModel      = MyStringId.GetOrCompute(ob.MainCharacterModel);

            GameDate = new DateTime(ob.GameDate);

            SunDirection = ob.SunDirection;

            if (ob.PossibleStartingStates != null && ob.PossibleStartingStates.Length > 0)
            {
                PossiblePlayerStarts = new MyWorldGeneratorStartingStateBase[ob.PossibleStartingStates.Length];
                for (int i = 0; i < ob.PossibleStartingStates.Length; ++i)
                {
                    PossiblePlayerStarts[i] = MyWorldGenerator.StartingStateFactory.CreateInstance(ob.PossibleStartingStates[i]);
                }
            }

            if (ob.WorldGeneratorOperations != null && ob.WorldGeneratorOperations.Length > 0)
            {
                WorldGeneratorOperations = new MyWorldGeneratorOperationBase[ob.WorldGeneratorOperations.Length];
                for (int i = 0; i < ob.WorldGeneratorOperations.Length; ++i)
                {
                    WorldGeneratorOperations[i] = MyWorldGenerator.OperationFactory.CreateInstance(ob.WorldGeneratorOperations[i]);
                }
            }

            if (ob.CreativeModeWeapons != null && ob.CreativeModeWeapons.Length > 0)
            {
                CreativeModeWeapons = new MyStringId[ob.CreativeModeWeapons.Length];
                for (int i = 0; i < ob.CreativeModeWeapons.Length; ++i)
                {
                    CreativeModeWeapons[i] = MyStringId.GetOrCompute(ob.CreativeModeWeapons[i]);
                }
            }

            if (ob.SurvivalModeWeapons != null && ob.SurvivalModeWeapons.Length > 0)
            {
                SurvivalModeWeapons = new MyStringId[ob.SurvivalModeWeapons.Length];
                for (int i = 0; i < ob.SurvivalModeWeapons.Length; ++i)
                {
                    SurvivalModeWeapons[i] = MyStringId.GetOrCompute(ob.SurvivalModeWeapons[i]);
                }
            }

            WorldBoundaries.Min = ob.WorldBoundaries.Min;
            WorldBoundaries.Max = ob.WorldBoundaries.Max;
        }
Exemplo n.º 18
0
        // Initialize this animation controller from given object builder.
        // Returns true on success.
        public static bool InitFromDefinition(this VRage.Game.Components.MyAnimationControllerComponent thisController,
                                              MyAnimationControllerDefinition animControllerDefinition)
        {
            bool result = true;

            thisController.Clear();

            thisController.SourceId = animControllerDefinition.Id;

            foreach (var objBuilderLayer in animControllerDefinition.Layers)
            {
                var layer = thisController.Controller.CreateLayer(objBuilderLayer.Name);
                if (layer == null)
                {
                    continue;
                }
                switch (objBuilderLayer.Mode)
                {
                case VRage.Game.ObjectBuilders.MyObjectBuilder_AnimationLayer.MyLayerMode.Add:
                    layer.Mode = VRage.Animations.MyAnimationStateMachine.MyBlendingMode.Add;
                    break;

                case VRage.Game.ObjectBuilders.MyObjectBuilder_AnimationLayer.MyLayerMode.Replace:
                    layer.Mode = VRage.Animations.MyAnimationStateMachine.MyBlendingMode.Replace;
                    break;

                default:
                    Debug.Fail("Unknown layer mode.");
                    layer.Mode = VRage.Animations.MyAnimationStateMachine.MyBlendingMode.Replace;
                    break;
                }
                if (objBuilderLayer.BoneMask != null)
                {
                    string[] boneMaskArray = objBuilderLayer.BoneMask.Split(m_boneListSeparators);
                    foreach (string s in boneMaskArray)
                    {
                        layer.BoneMaskStrIds.Add(MyStringId.GetOrCompute(s));
                    }
                }
                else
                {
                    layer.BoneMaskStrIds.Clear();
                }
                layer.BoneMask = null; // this will build itself in animation controller when we know all character bones
                MyAnimationVirtualNodes virtualNodes = new MyAnimationVirtualNodes();
                result = InitLayerNodes(layer, objBuilderLayer.StateMachine, animControllerDefinition, thisController.Controller, layer.Name + "/", virtualNodes) && result;
                layer.SetState(layer.Name + "/" + objBuilderLayer.InitialSMNode);
                layer.SortTransitions();
            }
            if (result)
            {
                thisController.MarkAsValid();
            }
            return(result);
        }
Exemplo n.º 19
0
        // Initialize animation tree of the state machine node.
        private static VRage.Animations.MyAnimationTreeNode InitNodeAnimationTree(VRage.Game.ObjectBuilders.MyObjectBuilder_AnimationTreeNode objBuilderNode)
        {
            // ------- tree node track -------
            var objBuilderNodeTrack = objBuilderNode as VRage.Game.ObjectBuilders.MyObjectBuilder_AnimationTreeNodeTrack;

            if (objBuilderNodeTrack != null)
            {
                var     nodeTrack      = new VRage.Animations.AnimationNodes.MyAnimationTreeNodeTrack();
                MyModel modelAnimation = MyModels.GetModelOnlyAnimationData(objBuilderNodeTrack.PathToModel);
                if (modelAnimation != null)
                {
                    VRage.Animations.MyAnimationClip selectedClip = modelAnimation.Animations.Clips.FirstOrDefault(clipItem => clipItem.Name == objBuilderNodeTrack.AnimationName);
                    if (selectedClip == null)
                    {
                        Debug.Fail("File '" + objBuilderNodeTrack.PathToModel + "' does not contain animation clip '"
                                   + objBuilderNodeTrack.AnimationName + "'.");
                    }
                    nodeTrack.SetClip(selectedClip);
                    nodeTrack.Loop        = objBuilderNodeTrack.Loop;
                    nodeTrack.Speed       = objBuilderNodeTrack.Speed;
                    nodeTrack.Interpolate = objBuilderNodeTrack.Interpolate;
                }
                return(nodeTrack);
            }
            // ------ tree node mix -----------------------
            var objBuilderNodeMix1D = objBuilderNode as MyObjectBuilder_AnimationTreeNodeMix1D;

            if (objBuilderNodeMix1D != null)
            {
                var nodeMix1D = new VRage.Animations.AnimationNodes.MyAnimationTreeNodeMix1D();
                if (objBuilderNodeMix1D.Children != null)
                {
                    foreach (var mappingObjBuilder in objBuilderNodeMix1D.Children)
                    {
                        MyAnimationTreeNodeMix1D.MyParameterNodeMapping mapping = new MyAnimationTreeNodeMix1D.MyParameterNodeMapping()
                        {
                            ParamValueBinding = mappingObjBuilder.Param,
                            Child             = InitNodeAnimationTree(mappingObjBuilder.Node)
                        };
                        nodeMix1D.ChildMappings.Add(mapping);
                    }
                    nodeMix1D.ChildMappings.Sort((x, y) => x.ParamValueBinding.CompareTo(y.ParamValueBinding));
                }
                nodeMix1D.ParameterName = MyStringId.GetOrCompute(objBuilderNodeMix1D.ParameterName);
                return(nodeMix1D);
            }
            // ------ tree node add -----------------------
            var objBuilderNodeAdd = objBuilderNode as MyObjectBuilder_AnimationTreeNodeAdd;

            if (objBuilderNodeAdd != null)
            {
                Debug.Fail("Addition node: currently unsupported type of animation tree node.");
            }
            return(null);
        }
Exemplo n.º 20
0
            void ShrinkVMap()
            {
                Vector3I min, max;

                m_selectedVoxel.GetFilledStorageBounds(out min, out max);

                MyVoxelMapStorageDefinition def = null;

                if (m_selectedVoxel.AsteroidName != null)
                {
                    MyDefinitionManager.Static.TryGetVoxelMapStorageDefinition(m_selectedVoxel.AsteroidName, out def);
                }

                var origSize = m_selectedVoxel.Size;

                var tightSize = max - min + 1;

                var storage = new MyOctreeStorage(null, tightSize);

                var offset = (storage.Size - tightSize) / 2 + 1;

                MyStorageData data = new MyStorageData();

                data.Resize(tightSize);

                m_selectedVoxel.Storage.ReadRange(data, MyStorageDataTypeFlags.ContentAndMaterial, 0, min, max);

                min = offset;
                max = offset + tightSize - 1;
                storage.WriteRange(data, MyStorageDataTypeFlags.ContentAndMaterial, ref min, ref max);

                var newMap = MyWorldGenerator.AddVoxelMap(m_selectedVoxel.StorageName, storage, m_selectedVoxel.WorldMatrix);

                m_selectedVoxel.Close();

                newMap.Save = true;

                if (def == null)
                {
                    ShowAlert("Voxel map {0} does not have a definition, the shrunk voxel map will be saved with the world instead.", m_selectedVoxel.StorageName);
                }
                else
                {
                    byte[] cVmapData;
                    newMap.Storage.Save(out cVmapData);

                    using (var ostream = MyFileSystem.OpenWrite(Path.Combine(MyFileSystem.ContentPath, def.StorageFile), FileMode.Open))
                    {
                        ostream.Write(cVmapData, 0, cVmapData.Length);
                    }
                    var notification = new MyHudNotification(MyStringId.GetOrCompute("Voxel prefab {0} updated succesfuly (size changed from {1} to {2})."), 4000);
                    notification.SetTextFormatArguments(def.Id.SubtypeName, origSize, storage.Size);
                    MyHud.Notifications.Add(notification);
                }
            }
        protected override void populate()
        {
            button.Getter = getCurrentValue;
            button.Setter = setValue;

            button.SetLimits(minValue, maxValue);
            button.Writer = displayText;

            button.Title   = MyStringId.GetOrCompute(displayName);
            button.Tooltip = MyStringId.GetOrCompute(tooltip);
        }
        protected override void populate()
        {
            button.Getter = getCurrentValue;
            button.Setter = setValue;

            button.Title   = MyStringId.GetOrCompute(displayName);
            button.Tooltip = MyStringId.GetOrCompute(tooltip);

            button.OffText = MyStringId.GetOrCompute("Off");
            button.OnText  = MyStringId.GetOrCompute("On");
        }
Exemplo n.º 23
0
        private void FillPBComboBoxContent(ICollection <MyTerminalControlComboBoxItem> items)
        {
            MyTerminalControlComboBoxItem item = new MyTerminalControlComboBoxItem {
                Key   = 0L,
                Value = MyCommonTexts.ScreenGraphicsOptions_AntiAliasing_None
            };

            items.Add(item);
            bool flag = false;
            MyFatBlockReader <MyProgrammableBlock> fatBlocks = base.CubeGrid.GetFatBlocks <MyProgrammableBlock>();

            foreach (MyProgrammableBlock block in fatBlocks)
            {
                item = new MyTerminalControlComboBoxItem {
                    Key   = block.EntityId,
                    Value = MyStringId.GetOrCompute(block.CustomName.ToString())
                };
                items.Add(item);
                if (block.EntityId == this.m_attachedPB)
                {
                    flag = true;
                }
            }
            MyGroups <MyCubeGrid, MyGridLogicalGroupData> .Group group = MyCubeGridGroups.Static.Logical.GetGroup(base.CubeGrid);
            if (group != null)
            {
                foreach (MyGroups <MyCubeGrid, MyGridLogicalGroupData> .Node node in group.Nodes)
                {
                    if (node.NodeData != base.CubeGrid)
                    {
                        foreach (MyProgrammableBlock block2 in node.NodeData.GetFatBlocks <MyProgrammableBlock>())
                        {
                            if (!block2.ShowInToolbarConfig)
                            {
                                continue;
                            }
                            item = new MyTerminalControlComboBoxItem {
                                Key   = block2.EntityId,
                                Value = MyStringId.GetOrCompute(block2.CustomName.ToString())
                            };
                            items.Add(item);
                            if (block2.EntityId == this.m_attachedPB)
                            {
                                flag = true;
                            }
                        }
                    }
                }
            }
            if (!flag)
            {
                this.m_attachedPB.Value = 0L;
            }
        }
Exemplo n.º 24
0
        private static void Add(uint ID, string materialName, int sectionIndex, Color outlineColor, float thickness)
        {
            if (!m_outlines.ContainsKey(ID))
            {
                m_outlines[ID] = new List <MyOutlineDesc>();
            }

            m_outlines[ID].Add(new MyOutlineDesc {
                Material = MyStringId.GetOrCompute(materialName), SectionIndex = sectionIndex, Color = outlineColor, Thickness = thickness
            });
        }
 private void ConditionalTranslateInternal(MyObjectBuilder_VisualDefinitionBase ob)
 {
     if (ob.DisplayName != null && ob.DisplayName.StartsWith("DisplayName_"))
     {
         ob.DisplayName = _displayNameTranslator(MyTexts.Get(MyStringId.GetOrCompute(ob.DisplayName)).ToString());
     }
     else
     {
         ob.DisplayName = _displayNameTranslator(ob.DisplayName);
     }
 }
        static MyLoadingScreenQuote()
        {
            m_quotes = new MyLoadingScreenQuote[MyPerGameSettings.LoadingScreenQuoteCount];

            for (int i = 0; i < MyPerGameSettings.LoadingScreenQuoteCount; ++i)
            {
                var text   = MyStringId.GetOrCompute(string.Format("Quote{0:00}Text", i));
                var author = MyStringId.GetOrCompute(string.Format("Quote{0:00}Author", i));
                m_quotes[i] = new MyLoadingScreenQuote(text, author);
            }
        }
        public static IMyTerminalControl CallbackList <T>() where T : IMyTerminalBlock
        {
            var callbackList = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlListbox, T>(string.Empty);

            callbackList.Title            = MyStringId.GetOrCompute("Callback");
            callbackList.Tooltip          = MyStringId.GetOrCompute("PB: Run with message passed as argument\nTimer: Trigger the timer\nNone: Pass message to queue");
            callbackList.VisibleRowsCount = 5;
            callbackList.Multiselect      = false;
            callbackList.ListContent      = (b, v, v2) =>
            {
                if (b.CubeGrid != null)
                {
                    var properties = Config.GetProperties(b.EntityId);
                    var blocks     = new List <IMyTerminalBlock>();
                    var timers     = new List <IMyTerminalBlock>();
                    var gts        = MyAPIGateway.TerminalActionsHelper.GetTerminalSystemForGrid(b.CubeGrid);
                    gts.GetBlocksOfType <IMyProgrammableBlock>(blocks);
                    gts.GetBlocksOfType <IMyTimerBlock>(timers);

                    blocks.AddRange(timers);

                    foreach (var block in blocks)
                    {
                        if (block.HasPlayerAccess(b.OwnerId))
                        {
                            var item = new MyTerminalControlListBoxItem(MyStringId.GetOrCompute(block.CustomName), default(MyStringId), block);
                            if (block.EntityId == properties.CallbackId)
                            {
                                v.Insert(0, item);
                                v2.Add(item);
                            }
                            else
                            {
                                v.Add(item);
                            }
                        }
                    }
                }
            };
            callbackList.ItemSelected = (b, v) =>
            {
                if ((v.Count > 0) && (v[0].UserData != null))
                {
                    var properties = Config.GetProperties(b.EntityId);
                    var pb         = (IMyTerminalBlock)v[0].UserData;
                    if (pb.HasPlayerAccess(b.OwnerId))
                    {
                        properties.CallbackId = pb.EntityId;
                        Config.SendSynced(properties);
                    }
                }
            };
            return(callbackList);
        }
Exemplo n.º 28
0
        public static string GetResourceName(string value)
        {
            if (value == null)
            {
                return(null);
            }

            MyStringId stringId = MyStringId.GetOrCompute(value);

            return(MyTexts.GetString(stringId));
        }
        /// <summary>
        /// Draws the hollow cylinder into the gameworld by creating a wireframe mesh of the cylinder.
        /// </summary>
        public void Draw()
        {
            Vector3D outVertexUp  = Vector3D.Zero;
            Vector3D inVertexUp   = Vector3D.Zero;
            Vector3D outVertexLow = Vector3D.Zero;
            Vector3D inVertexLow  = Vector3D.Zero;

            Vector3D outPrevUp  = Vector3D.Zero;
            Vector3D inPrevUp   = Vector3D.Zero;
            Vector3D outPrevLow = Vector3D.Zero;
            Vector3D inPrevLow  = Vector3D.Zero;

            for (int i = 0; i <= 360; i++)
            {
                outVertexUp.X = (float)(m_radius * Math.Cos(MathHelper.ToRadians(i)));
                outVertexUp.Y = m_height;
                outVertexUp.Z = (float)(m_radius * Math.Sin(MathHelper.ToRadians(i)));

                outVertexLow.X = (float)(m_radius * Math.Cos(MathHelper.ToRadians(i)));
                outVertexLow.Y = -m_height;
                outVertexLow.Z = (float)(m_radius * Math.Sin(MathHelper.ToRadians(i)));

                inVertexUp.X = (float)(m_innerRadius * Math.Cos(MathHelper.ToRadians(i)));
                inVertexUp.Y = m_height;
                inVertexUp.Z = (float)(m_innerRadius * Math.Sin(MathHelper.ToRadians(i)));

                inVertexLow.X = (float)(m_innerRadius * Math.Cos(MathHelper.ToRadians(i)));
                inVertexLow.Y = -m_height;
                inVertexLow.Z = (float)(m_innerRadius * Math.Sin(MathHelper.ToRadians(i)));

                outVertexUp  = Vector3D.Transform(outVertexUp, m_worldMatrix);
                outVertexLow = Vector3D.Transform(outVertexLow, m_worldMatrix);
                inVertexUp   = Vector3D.Transform(inVertexUp, m_worldMatrix);
                inVertexLow  = Vector3D.Transform(inVertexLow, m_worldMatrix);

                if (i > 0)
                {
                    MySimpleObjectDraw.DrawLine(outPrevUp, outVertexUp, MyStringId.GetOrCompute("GizmoDrawLine"), ref m_color, m_thickness);
                    MySimpleObjectDraw.DrawLine(outPrevLow, outVertexLow, MyStringId.GetOrCompute("GizmoDrawLine"), ref m_color, m_thickness);
                    MySimpleObjectDraw.DrawLine(inPrevUp, inVertexUp, MyStringId.GetOrCompute("GizmoDrawLine"), ref m_color, m_thickness);
                    MySimpleObjectDraw.DrawLine(inPrevLow, inVertexLow, MyStringId.GetOrCompute("GizmoDrawLine"), ref m_color, m_thickness);
                }

                MySimpleObjectDraw.DrawLine(outVertexUp, inVertexUp, MyStringId.GetOrCompute("GizmoDrawLine"), ref m_color, m_thickness);
                MySimpleObjectDraw.DrawLine(outVertexLow, inVertexLow, MyStringId.GetOrCompute("GizmoDrawLine"), ref m_color, m_thickness);
                MySimpleObjectDraw.DrawLine(outVertexUp, outVertexLow, MyStringId.GetOrCompute("GizmoDrawLine"), ref m_color, m_thickness);
                MySimpleObjectDraw.DrawLine(inVertexUp, inVertexLow, MyStringId.GetOrCompute("GizmoDrawLine"), ref m_color, m_thickness);

                outPrevUp  = outVertexUp;
                outPrevLow = outVertexLow;
                inPrevUp   = inVertexUp;
                inPrevLow  = inVertexLow;
            }
        }
Exemplo n.º 30
0
        public override void OnUpdate(MyStateMachine stateMachine)
        {
            if (m_instance == null)
            {
                foreach (var transitionNamesToVariableStorage in m_transitionNamesToVariableStorages.Values)
                {
                    transitionNamesToVariableStorage.SetValue(MyStringId.GetOrCompute("Left"), true);
                }
                return;
            }

            if (string.IsNullOrEmpty(m_instance.TransitionTo))
            {
                m_instance.Update();
            }
            // trigger transition when script triggers complete method
            if (!string.IsNullOrEmpty(m_instance.TransitionTo))
            {
                // Correct way to clear a cursor
                if (OutTransitions.Count == 0)
                {
                    // Read the first cursor member
                    var enumerator = Cursors.GetEnumerator();
                    enumerator.MoveNext();
                    var cursor = enumerator.Current;
                    stateMachine.DeleteCursor(cursor.Id);
                }
                else
                {
                    bool found = false;
                    var  sId   = MyStringId.GetOrCompute(m_instance.TransitionTo);
                    foreach (var outTransition in OutTransitions)
                    {
                        if (outTransition.Name == sId)
                        {
                            found = true;
                            break;
                        }
                    }

                    Debug.Assert(found, "State with outgoing transitions triggered non existent transition! Fix your scripts (or mission machines)!");
                    IMyVariableStorage <bool> storage;
                    // unblock one of the transitions
                    if (m_transitionNamesToVariableStorages.TryGetValue(MyStringId.GetOrCompute(m_instance.TransitionTo), out storage))
                    {
                        storage.SetValue(MyStringId.GetOrCompute("Left"), true);
                    }
                    else
                    {
                        Debug.Fail("Transition was not found.");
                    }
                }
            }
        }