Exemplo n.º 1
0
        public MainWindow(Editor.Editor parent)
        {
            m_parent = parent;

            InitializeComponent();

            // Callbacks added here since the designer enjoys making life miserable
            this.MainPictureBox.MouseEnter += new System.EventHandler(this.MainPictureBox_MouseEnter);

            this.BottomBarGfxCombo.SelectedIndexChanged += new System.EventHandler(this.BottomBarGfxCombo_SelectedIndexChanged);

            this.RightPanelTabControl.Selected += new System.Windows.Forms.TabControlEventHandler(this.RightPanelTabControl_Selected);

            this.PartTreeView.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.PartTreeView_AfterSelect);
            this.BrushesTreeView.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.BrushesTreeView_AfterSelect);
        }
Exemplo n.º 2
0
        public override void GenerateBrushAndAssetMaps(Editor.Editor parent)
        {
            Dictionary<Color, EditorBrush> map = parent.BrushMap;

            foreach (DungeonBrush brush in BlockMap)
            {
                // Populate brush comment
                if (brush.Comment == null)
                {
                    brush.Comment = "no comment defined";
                }

                if (brush.Connector == null)
                {
                    brush.Connector = false;
                }

                // Populate the rules
                if (brush.Rules != null)
                {
                    foreach (string rule in brush.Rules.SelectMany(rulesArray => rulesArray))
                    {
                        brush.BrushRules.Add(rule);
                    }
                }

                // Populate the brushes
                if (brush.Brushes != null)
                {
                    foreach (var brushArray in brush.Brushes)
                    {
                        for (int i = 0; i < brushArray.Count; ++i)
                        {
                            if (!(brushArray[i] is string))
                                continue;

                            string type = (string) brushArray[i];
                            string name = null;

                            if (type == "back")
                            {
                                brush.NeedsBackAsset = true;
                                name = (string) brushArray[i + 1];
                            }

                            else if (type == "front" || type == "object")
                            {
                                brush.NeedsFrontAsset = true;
                                name = (string) brushArray[i + 1];

                                if (type == "object" && brushArray.Count > i + 2 && brushArray[i + 2] is JObject)
                                {
                                    JObject objectParams = (JObject)brushArray[i + 2];
                                    string rawDirection = objectParams.Value<string>("direction");

                                    if (rawDirection == "left")
                                    {
                                        brush.Direction = ObjectDirection.DIRECTION_LEFT;
                                    }
                                    else if (rawDirection == "right")
                                    {
                                        brush.Direction = ObjectDirection.DIRECTION_RIGHT;
                                    }
                                }
                            }

                            // if it is a liquid
                            else if (type == "lava" || type == "water" || type == "acid" ||
                                     type == "liquidtar" || type == "tentaclejuice")
                            {
                                brush.BrushTypes.Add("back");
                                brush.NeedsBackAsset = true;
                                name = type;
                            }

                            // If an asset is needed but we don't have one!
                            if (name == null && (brush.NeedsBackAsset || brush.NeedsFrontAsset))
                                continue;

                            // Add the current asset type to the list of types for this brush
                            brush.BrushTypes.Add(type);

                            // Stop if the brush doesn't need an asset
                            if (!brush.NeedsBackAsset && !brush.NeedsFrontAsset)
                                continue;

                            base.LoadBrushWithBackAsset(brush, parent, name, type);
                            base.LoadBrushWithFrontAsset(brush, parent, name, type);
                        }
                    }
                }

                map[brush.Colour] = brush;
            }

            LoadSpecialBrushes(parent);
        }
Exemplo n.º 3
0
        // This function is one big wall of useless repeated code
        // Fix it at some point
        private void LoadSpecialBrushes(Editor.Editor parent)
        {
            // Get all collision blocks
            foreach (DungeonBrush brush in BlockMap)
            {
                // If this brush is a connector
                if (brush.Connector != null && (bool) brush.Connector)
                {
                    string assetName = brush.Comment + ".INTERNAL";

                    StarboundAsset asset = parent.LoadAsset(assetName, "brush");
                    if (asset == null )
                    {
                        asset = new StarboundAsset();
                        //asset.AssetName = assetName;
                        asset.Image = EditorHelpers.GetGeneratedRectangle(8, 8,
                            brush.Colour.R,
                            brush.Colour.G,
                            brush.Colour.B,
                            brush.Colour.A);
                        //parent.RegisterAsset(assetName, "brush", asset);
                    }

                    brush.NeedsFrontAsset = true;
                    brush.FrontAsset = asset;
                    brush.IsSpecial = true;
                }

                // If this brush is surface foreground
                else if (brush.BrushTypes.Contains("surface"))
                {
                    string assetName = Editor.Editor.Settings.SurfaceForegroundTile;

                    StarboundAsset asset = parent.LoadAsset(assetName, "surface");
                    if (asset == null && assetName.Contains("INTERNAL"))
                    {
                        asset = new StarboundAsset();
                        //asset.AssetName = assetName;
                        asset.Image = EditorHelpers.GetGeneratedRectangle(8, 8,
                            87, 59, 12, 255);
                        //parent.RegisterAsset(assetName, "surface", asset);
                    }

                    brush.FrontAsset = asset;
                    brush.BrushTypes.Add("front");
                    brush.NeedsFrontAsset = true;
                }

                // If this brush is surface background
                else if (brush.BrushTypes.Contains("surfacebackground"))
                {
                    string assetName = Editor.Editor.Settings.SurfaceBackgroundTile;

                    StarboundAsset asset = parent.LoadAsset(assetName, "surfacebackground");
                    if (asset == null && assetName.Contains("INTERNAL"))
                    {
                        asset = new StarboundAsset();
                        //asset.AssetName = assetName;
                        asset.Image = EditorHelpers.GetGeneratedRectangle(8, 8,
                            87, 59, 12, 255);
                        //parent.RegisterAsset(assetName, "surfacebackground", asset);
                    }
                    brush.BackAsset = asset;
                    brush.BrushTypes.Add("back");
                    brush.NeedsBackAsset = true;
                }
            }
        }
Exemplo n.º 4
0
        public override void LoadParts(Editor.Editor parent)
        {
            foreach (DungeonPart part in Parts)
            {
                Editor.Editor.Log.Write("Loading part " + part.Name);

                object imageList = part.Definition[1];

                // If the format isn't strictly correct, assume there's only one layer in this part
                // We must do this because some dungeon authors do not create an array if there
                // is only one layer to their part.
                if (imageList is string)
                {
                    JArray tempArray = new JArray {imageList};
                    imageList = tempArray;
                }

                // For each defined image
                foreach (string fileName in (JArray) imageList)
                {
                    string path = EditorHelpers.ParsePath(Path.GetDirectoryName(FilePath), fileName);

                    if (!File.Exists(path))
                    {
                        Editor.Editor.Log.Write("  Layer image " + fileName + "does not exist");
                        continue;
                    }

                    Image layerImg = EditorHelpers.LoadImageFromFile(path);

                    // Set the width and height of the part to match the blockmap
                    part.Width = layerImg.Width;
                    part.Height = layerImg.Height;

                    part.Layers.Add(new EditorMapLayer(fileName, (Bitmap) layerImg, parent.BrushMap, part));
                    Editor.Editor.Log.Write("  Layer image " + fileName + " loaded");
                }

                // Create the graphics image
                part.GraphicsMap = new Bitmap(part.Width*Editor.Editor.DEFAULT_GRID_FACTOR,
                    part.Height*Editor.Editor.DEFAULT_GRID_FACTOR, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);

                // Update the composite collision map, now that all layers have been loaded
                part.UpdateCompositeCollisionMap();

                part.Parent = this;
                Editor.Editor.Log.Write("Completed loading part " + part.Name);
            }
        }
Exemplo n.º 5
0
        public override void GenerateBrushAndAssetMaps(Editor.Editor parent)
        {
            foreach (ShipBrush brush in BlockMap)
            {
                string backgroundType = null;
                string foregroundType = null;
                string foregroundName = null;
                string backgroundName = null;

                brush.Comment = "";

                // The thing occupying the background layer
                if (brush.BackgroundMat != null)
                {
                    brush.Comment += brush.BackgroundMat + "  ";
                    backgroundType = "back";
                    backgroundName = brush.BackgroundMat;
                    brush.BrushTypes.Add(backgroundType);
                    brush.NeedsBackAsset = true;
                }

                // The thing occupying the foreground layer
                if (brush.ForegroundMat != null)
                {
                    brush.Comment += brush.ForegroundMat;
                    foregroundType = "front";
                    foregroundName = brush.ForegroundMat;
                    brush.BrushTypes.Add(foregroundType);
                    brush.NeedsFrontAsset = true;
                }
                else if (brush.Object != null)
                {
                    brush.Comment += brush.Object;
                    foregroundType = "object";
                    foregroundName = brush.Object;

                    // Add the direction to the asset name
                    if (!String.IsNullOrWhiteSpace(brush.ObjectDirection))
                    {
                        brush.Comment += " " + brush.ObjectDirection;
                    }

                    // Populate the brush with the direction
                    if (brush.ObjectDirection != null)
                    {
                        if (brush.ObjectDirection == "left")
                        {
                            brush.Direction = ObjectDirection.DIRECTION_LEFT;
                        }
                        else if (brush.ObjectDirection == "right")
                        {
                            brush.Direction = ObjectDirection.DIRECTION_RIGHT;
                        }
                    }
                    else
                    {
                        brush.Direction = ObjectDirection.DIRECTION_NONE;
                    }

                    brush.BrushTypes.Add(foregroundType);
                    brush.NeedsFrontAsset = true;
                }

                if (String.IsNullOrWhiteSpace(brush.Comment))
                {
                    brush.Comment = "no comment defined";
                }

                base.LoadBrushWithBackAsset(brush, parent, backgroundName, backgroundType);
                base.LoadBrushWithFrontAsset(brush, parent, foregroundName, foregroundType);

                parent.BrushMap[brush.Colour] = brush;
            }

            LoadSpecialBrushes(parent);
        }
Exemplo n.º 6
0
 private void LoadSpecialBrushes(Editor.Editor parent)
 {
 }
Exemplo n.º 7
0
        public override void LoadParts(Editor.Editor parent)
        {
            Editor.Editor.Log.Write("Loading part " + PartImage);

            string path = EditorHelpers.ParsePath(Path.GetDirectoryName(FilePath), PartImage);

            if (!File.Exists(path))
            {
                Editor.Editor.Log.Write("  Part image " + PartImage + "does not exist");
                return;
            }

            Image layerImg = EditorHelpers.LoadImageFromFile(path);

            // Ships don't have parts. Make a dummy one.
            ShipPart part = new ShipPart();
            part.Name = PartImage;
            part.Parent = this;
            part.Width = layerImg.Width;
            part.Height = layerImg.Height;

            part.Layers.Add(new EditorMapLayer(PartImage, (Bitmap) layerImg, parent.BrushMap, part));
            part.GraphicsMap = new Bitmap(part.Width*Editor.Editor.DEFAULT_GRID_FACTOR,
                part.Height*Editor.Editor.DEFAULT_GRID_FACTOR, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);

            part.UpdateCompositeCollisionMap();

            ReadableParts.Add(part);
            LoadOverlays();

            Editor.Editor.Log.Write("Completed loading part " + PartImage);
        }
Exemplo n.º 8
0
        public virtual void LoadBrushWithBackAsset(EditorBrush brush, Editor.Editor parent, string name, string type)
        {
            string extension = EditorHelpers.GetExtensionFromBrushType(type);

            // Objects and NPCs must always be a front asset
            if (!brush.NeedsBackAsset || extension == null || type == "object" || type == "npc")
                return;

            // Load the background tile
            StarboundAsset asset = parent.LoadAsset(name, type);
            if ( asset == null )
            {
                // If this is an internal asset - liquids, etc
                // This is a hack to display liquids until liquid parsing has been implemented
                // (low priority)
                if (name == "lava")
                {
                    asset = new StarboundAsset();
                    //asset.AssetName = name;
                    asset.Image = EditorHelpers.GetGeneratedRectangle(8, 8, 207, 16, 32, 255);
                }
                else if (name == "acid")
                {
                    asset = new StarboundAsset();
                    //asset.AssetName = name;
                    asset.Image = EditorHelpers.GetGeneratedRectangle(8, 8, 107, 141, 63, 255);
                }
                else if (name == "water")
                {
                    asset = new StarboundAsset();
                    //asset.AssetName = name;
                    asset.Image = EditorHelpers.GetGeneratedRectangle(8, 8, 0, 78, 111, 255);
                }
                else if (name == "liquidtar" || name == "tentaclejuice")
                {
                    asset = new StarboundAsset();
                    //asset.AssetName = name;
                    asset.Image = EditorHelpers.GetGeneratedRectangle(8, 8, 200, 191, 231, 255);
                }
                //parent.RegisterAsset(name, type, asset);
            }

            if (asset != null)
                brush.BackAsset = asset;
        }
Exemplo n.º 9
0
 public virtual void GenerateBrushAndAssetMaps(Editor.Editor parent)
 {
 }
Exemplo n.º 10
0
 public virtual void LoadParts(Editor.Editor parent)
 {
 }
Exemplo n.º 11
0
        public virtual void LoadBrushWithFrontAsset(EditorBrush brush, Editor.Editor parent, string name, string type)
        {
            string extension = EditorHelpers.GetExtensionFromBrushType(type);

            if (!brush.NeedsFrontAsset || extension == null)
                return;

            // Load the foreground tile
            StarboundAsset asset = parent.LoadAsset(name, type);
            if (asset != null)
                brush.FrontAsset = asset;
        }