public void CreateEntity(int mX, int mY, TDEEntity mEntity)
        {
            if (!IsValid(mX, mY)) return;

            Entities.Add(mEntity);
            Tiles[mX, mY].AddEntity(mEntity);
            mEntity.Tile = Tiles[mX, mY];

            InvokeOnEntityCreated(mEntity);
        }
Exemple #2
0
        public static void InputParametersBox(string title, TDEEntity mEntity)
        {
            var form = new Form();
            var listBox = new ListBox();
            var buttonExit = new Button();
            var textBox = new TextBox();

            form.Text = title;

            foreach (var parameter in mEntity.Parameters)
                listBox.Items.Add(String.Format("Parameter {0}: {1}", parameter.Name, parameter));

            buttonExit.Text = "Finished";
            buttonExit.DialogResult = DialogResult.Cancel;

            textBox.SetBounds(12, 280, 372, 20);
            listBox.SetBounds(9, 20, 372, 250);
            buttonExit.SetBounds(309, 320, 75, 23);

            listBox.AutoSize = true;
            buttonExit.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;

            form.ClientSize = new Size(396, 615);
            form.Controls.AddRange(new Control[] {listBox, textBox, buttonExit});
            form.ClientSize = new Size(Math.Max(300, listBox.Right + 10), form.ClientSize.Height);
            form.FormBorderStyle = FormBorderStyle.FixedDialog;
            form.StartPosition = FormStartPosition.CenterScreen;
            form.MinimizeBox = false;
            form.MaximizeBox = false;
            listBox.Click += (o, args) =>
                             {
                                 InputParametersBoxChange(mEntity, listBox, textBox.Text);
                                 textBox.Focus();
                             };
            form.CancelButton = buttonExit;

            form.ShowDialog();
        }
Exemple #3
0
        private static void InputParametersBoxChange(TDEEntity mEntity, ListBox mListBox, string mValue)
        {
            var index = mListBox.SelectedIndex;

            if (index != -1)
            {
                var parameter = mEntity.Parameters[index];

                if (parameter.TypeString == "int")
                {
                    int resultValue;
                    var success = int.TryParse(mValue, out resultValue);

                    if (!success) return;

                    parameter.Value = resultValue;
                }
                else if (parameter.TypeString == "bool")
                {
                    bool resultValue;
                    var success = bool.TryParse(mValue, out resultValue);

                    if (!success) return;

                    parameter.Value = resultValue;
                }
                else if (parameter.TypeString == "list<int>")
                {
                    var resultValue = new List<int>();
                    var split = mValue.Split(',');

                    foreach (var splitInt in split)
                    {
                        int splitIntTemp;
                        var success = int.TryParse(splitInt, out splitIntTemp);
                        if (success) resultValue.Add(splitIntTemp);
                    }

                    parameter.Value = resultValue;
                }
                else if (parameter.TypeString == "string")
                {
                    var resultValue = mValue;
                    parameter.Value = resultValue;
                }
            }

            for (var i = 0; i < mEntity.Parameters.Count; i++)
            {
                var parameter = mEntity.Parameters[i];
                mListBox.Items[i] = (String.Format("Parameter {0}: {1}", parameter.Name, parameter));
            }

            mListBox.SelectedIndex = -1;
        }
 private void InvokeOnEntityCreated(TDEEntity mEntity)
 {
     var handler = OnEntityCreated;
     if (handler != null) handler(mEntity);
 }
 public void DeleteEntity(TDEEntity mEntity)
 {
     Entities.Remove(mEntity);
     mEntity.Tile.RemoveEntity(mEntity);
 }
Exemple #6
0
        private void UpdateSelector()
        {
            _common.UpdatePositions();
            _common.SelectionSprite.Texture = _currentOutline.Texture;
            _common.SelectionSprite.TextureRect = _currentOutline.TextureRect;
            _common.SelectionSprite.Color = new Color(255, 255, 255, 100);

            if (_currentTileManager == null) return;
            if (!_currentTileManager.IsValid(_common.TilePosition.X, _common.TilePosition.Y)) return;
            var entity = CurrentTile.OrderedEntities.Find(x => x.Layer == _currentOutline.Layer);
            _currentEntity = entity;

            UpdateRectanglePreview();
        }
Exemple #7
0
 private void AddDrawEntity(TDEEntity mEntity)
 {
     _drawEntities.Add(mEntity);
     mEntity.Sprite.Position = new Vector2f(mEntity.Tile.X, mEntity.Tile.Y)*TDUtils.TileSize + new Vector2f(TDUtils.TileSize/2f, TDUtils.TileSize/2f);
     mEntity.Sprite.Origin = new Vector2f(mEntity.Sprite.TextureRect.Width/2f, mEntity.Sprite.TextureRect.Height/2f);
     _drawSortRequired = true;
 }
Exemple #8
0
        private void DrawEntitiesSpecialOnOff(Sprite mSprite, TDEEntity mEntity)
        {
            var offParameter = mEntity.Parameters.Find(x => x.Name == "mIsOff");
            var directionParameter = mEntity.Parameters.Find(x => x.Name == "mDirection");

            if (offParameter == null) return;

            if (mEntity.Name.Contains("Door")) return;

            if (directionParameter == null)
                mSprite.TextureRect = (bool) offParameter.Value ? Assets.GetTileset("onofftiles").GetTextureRect("off") : Assets.GetTileset("onofftiles").GetTextureRect("on");
            else
                mSprite.TextureRect = (bool) offParameter.Value ? Assets.GetTileset("onoffdirtiles").GetTextureRect("off_n") : Assets.GetTileset("onoffdirtiles").GetTextureRect("on_n");
        }
Exemple #9
0
        private void DrawEntitySpecialBroken(Sprite mSprite, TDEEntity mEntity)
        {
            var isBrokenParameter = mEntity.Parameters.Find(x => x.Name == "mIsBroken");
            if (isBrokenParameter == null || (!((bool) isBrokenParameter.Value))) return;

            var brokenOverlay = Assets.GetTileset("brokenoverlaytiles").GetSprite(1, 1, Assets.GetTexture(@"environment\brokenoverlay"));
            brokenOverlay.Position = mSprite.Position;
            _common.GameTexture.Draw(brokenOverlay);
        }
Exemple #10
0
        private void DrawEntitiesSpecialIDs(Sprite mSprite, TDEEntity mEntity)
        {
            Text text = null;

            var idsParameter = mEntity.Parameters.Find(x => x.Name == "mIDs");
            if (idsParameter != null)
            {
                var idsString = idsParameter.ToString();
                if (idsString == "-1") return;
                text = new Text(idsString, Font.DefaultFont, 10) {Position = mSprite.Position - mSprite.Origin, Style = Text.Styles.Bold, Color = Color.White};
            }

            var idsTargetParameter = mEntity.Parameters.Find(x => x.Name == "mTargetIDs");
            if (idsTargetParameter != null)
            {
                var idsTargetIDs = idsTargetParameter.ToString();
                if (idsTargetIDs == "-1") return;
                text = new Text(idsTargetIDs, Font.DefaultFont, 10) {Position = mSprite.Position - mSprite.Origin, Style = Text.Styles.Bold, Color = Color.Blue};
            }

            if (text == null) return;

            var textShadow1 = new Text(text) {Position = mSprite.Position - mSprite.Origin + new Vector2f(1, 1), Color = Color.Black};
            var textShadow2 = new Text(text) {Position = mSprite.Position - mSprite.Origin + new Vector2f(-1, 1), Color = Color.Black};
            var textShadow3 = new Text(text) {Position = mSprite.Position - mSprite.Origin + new Vector2f(1, -1), Color = Color.Black};
            var textShadow4 = new Text(text) {Position = mSprite.Position - mSprite.Origin + new Vector2f(-1, -1), Color = Color.Black};
            _common.GameTexture.Draw(textShadow1);
            _common.GameTexture.Draw(textShadow2);
            _common.GameTexture.Draw(textShadow3);
            _common.GameTexture.Draw(textShadow4);
            _common.GameTexture.Draw(text);
        }
Exemple #11
0
        private void CopyEntity()
        {
            if (IsInvalid()) return;

            var entity = CurrentTile.OrderedEntities.Find(x => x.Layer == _currentOutline.Layer);
            if (entity == null) return;

            _copiedEntity = entity.Clone();
        }
Exemple #12
0
 public void RemoveEntity(TDEEntity mEntity)
 {
     OrderedEntities.Remove(mEntity);
 }
Exemple #13
0
 public void AddEntity(TDEEntity mEntity)
 {
     OrderedEntities.Add(mEntity);
     OrderedEntities.Sort((a, b) => a.Layer.CompareTo(b.Layer));
 }
Exemple #14
0
        public static TDSControl LoadFromFile(string mPath)
        {
            var result = new TDSControl();
            var filePath = mPath;

            var streamReader = File.OpenText(filePath);

            var holdHeaderTitle = streamReader.ReadLine();
            var holdHeaderVersion = streamReader.ReadLine();

            var holdName = streamReader.ReadLine();
            var hold = TDSControl.CreateHold(result, holdName);

            var levelString = streamReader.ReadLine();

            while (!string.IsNullOrEmpty(levelString))
            {
                var levelSplit = levelString.Split(LevelSeparator, StringSplitOptions.None);
                var levelName = levelSplit[0];
                var levelRoomWidth = int.Parse(levelSplit[1]);
                var levelRoomHeight = int.Parse(levelSplit[2]);
                var levelRoomsString = levelSplit[3];

                var level = TDSControl.CreateLevel(hold, levelName, levelRoomWidth, levelRoomHeight);

                var rooms = levelRoomsString.Split(RoomManagerEndSeparator, StringSplitOptions.None);

                foreach (var roomString in rooms)
                {
                    if (string.IsNullOrEmpty(roomString)) continue;

                    var roomStringSplit = roomString.Split(new[] {RoomManagerStartSeparator[0], RoomUnrequiredSeparator[0], RoomSecretSeparator[0]}, StringSplitOptions.None);
                    var roomDimensionsString = roomStringSplit[0];
                    var roomManagerString = roomStringSplit[1];

                    var roomDimensionsSplit = roomDimensionsString.Split(RoomDimensionSeparator, StringSplitOptions.None);
                    var roomX = int.Parse(roomDimensionsSplit[0]);
                    var roomY = int.Parse(roomDimensionsSplit[1]);

                    var isRequired = roomStringSplit.Count() < 3;
                    var isSecret = roomStringSplit.Count() > 3;

                    var room = TDSControl.CreateRoom(level, roomX, roomY, isRequired, isSecret);
                    var manager = new TDETileManager(level.RoomWidth, level.RoomHeight);
                    room.TileManager = manager;

                    var roomManagerSplit = roomManagerString.Split(TileSeparationSeparator, StringSplitOptions.None);

                    foreach (var tile in roomManagerSplit)
                    {
                        if (string.IsNullOrEmpty(tile)) continue;

                        var tileStrings = tile.Split(TileEntitySeparator, StringSplitOptions.None);
                        var tilePositionString = tileStrings[0].Split(TileDimensionSeparator, StringSplitOptions.None);

                        var tileX = int.Parse(tilePositionString[0]);
                        var tileY = int.Parse(tilePositionString[1]);

                        for (var j = 1; j < tileStrings.GetLength(0); j++)
                        {
                            var entityString = tileStrings[j];

                            if (string.IsNullOrEmpty(entityString)) continue;

                            var elementSplit = entityString.Split(EntityParametersSeparator, StringSplitOptions.None);
                            var uid = int.Parse(elementSplit[0]);

                            var parameters = new List<TDEEntityParameter>();

                            for (var i = 1; i < elementSplit.Count(); i++)
                            {
                                var parameterSplit = elementSplit[i].Split(ParameterSeparationSeparator, StringSplitOptions.None);
                                var parameterName = parameterSplit[0];
                                var parameterTypeName = parameterSplit[1];

                                Type parameterType = null;
                                object parameterValue = null;

                                if (parameterTypeName == "int")
                                {
                                    parameterType = typeof (int);
                                    parameterValue = int.Parse(parameterSplit[2]);
                                }
                                else if (parameterTypeName == "bool")
                                {
                                    parameterType = typeof (bool);
                                    parameterValue = bool.Parse(parameterSplit[2]);
                                }
                                else if (parameterTypeName == "list<int>")
                                {
                                    parameterType = typeof (List<int>);

                                    var split = parameterSplit[2].Split(',');
                                    var resultValue = split.Select(int.Parse).ToList();

                                    parameterValue = resultValue;
                                }
                                else if (parameterTypeName == "string")
                                {
                                    parameterType = typeof (string);
                                    parameterValue = parameterSplit[2];
                                }

                                parameters.Add(new TDEEntityParameter(parameterName, parameterType) {Value = parameterValue});
                            }

                            var entity = new TDEEntity(TDEOutlines.GetOutlineByUID(uid)) {Parameters = new List<TDEEntityParameter>(parameters)};

                            manager.CreateEntity(tileX, tileY, entity);
                        }
                    }
                }

                levelString = streamReader.ReadLine();
            }

            streamReader.Close();

            return result;
        }