Exemplo n.º 1
0
        public EditTerrainForm(TemplateDoc tmpd)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            m_sizTile = tmpd.TileSize;
            for (int n = 0; n < m_abr.Length; n++)
            {
                m_abr[n] = new SolidBrush(s_aclrTerrain[n]);
            }

            Template[] atmpl = tmpd.GetTemplates();
            panel1.SuspendLayout();
            foreach (Template tmpl in atmpl)
            {
                PictureBox picb = new PictureBox();
                picb.Image      = ConstructTerrainBitmap(tmpl);
                picb.SizeMode   = PictureBoxSizeMode.AutoSize;
                picb.Tag        = (Object)tmpl;
                picb.MouseDown += new MouseEventHandler(PictureBox_MouseDown);
                panel1.Controls.Add(picb);
            }
            panel1.ResumeLayout();
        }
Exemplo n.º 2
0
        private void SuckTemplates()
        {
            // Suck all the tiles in

            Template[] atmpl     = TemplateDoc.GetTemplates();
            int        iTemplate = 0;

            foreach (Template tmpl in atmpl)
            {
                bool[,] afOccupancy = tmpl.OccupancyMap;
                for (int ty = 0; ty < afOccupancy.GetLength(0); ty++)
                {
                    for (int tx = 0; tx < afOccupancy.GetLength(1); tx++)
                    {
                        if (!afOccupancy[ty, tx])
                        {
                            continue;
                        }
                        TileData tdata = new TileData();
                        tdata.iTemplate  = iTemplate;
                        tdata.txTemplate = tx;
                        tdata.tyTemplate = ty;
                        tdata.aclr       = new Color[m_sizTile.Width * m_sizTile.Height];
                        ExtractTilePixels(tmpl.Bitmap, tx, ty, m_sizTile, ref tdata.aclr);
                        tdata.hash = HashTile(tdata.aclr);
                        m_alsTileData.Add(tdata);
                    }
                }
                iTemplate++;
            }
        }
Exemplo n.º 3
0
        public static void ScaleTemplates(TemplateDoc tmpd, Size sizTile)
        {
            // Scale templates

            Template[] atmpl          = tmpd.GetTemplates();
            Template   tmplBackground = tmpd.GetBackgroundTemplate();

            tmpd.RemoveTemplates(atmpl);
            foreach (Template tmpl in atmpl)
            {
                ScaleTemplate(tmpl, tmpd.TileSize, sizTile);
            }
            tmpd.TileSize = sizTile;
            tmpd.AddTemplates(atmpl);
            tmpd.SetBackgroundTemplate(tmplBackground);
        }
Exemplo n.º 4
0
        void TemplateDocTemplate_DocAdded(Document doc)
        {
            TemplateDoc tmpd = (TemplateDoc)doc;

            tmpd.ModifiedChanged += new TemplateDoc.ModifiedChangedHandler(TemplateDoc_ModifiedChanged);
            tmpd.NameChanged     += new TemplateDoc.NameChangedHandler(TemplateDoc_NameChanged);
            ComboItem ci = new ComboItem(tmpd);

            comboDocs.SelectedIndex = comboDocs.Items.Add(ci);
            Template[] atmpl    = tmpd.GetTemplates();
            ArrayList  alsNames = new ArrayList();

            foreach (Template tmpl in atmpl)
            {
                alsNames.Add(tmpl.Name);
            }
            toolTip.RemoveAll();
            TemplateDocTemplate_TemplatesAdded(tmpd, (string[])alsNames.ToArray(typeof(string)));
        }
Exemplo n.º 5
0
        public static void MixMapImportSpecial(Theater theater, TemplateDoc tmpdCopyTerrain, string strFileSave)
        {
            TemplateDoc tmpd24 = (TemplateDoc)DocManager.NewDocument(typeof(TemplateDoc), new Object[] { new Size(24, 24) });

            MixTemplate[] amixt = MixSuck.LoadTemplates(theater);
            MixSuck.ImportTemplates(amixt, tmpd24);

            Template[] atmpl24 = tmpd24.GetTemplates();
            Template[] atmpl16 = tmpdCopyTerrain.GetTemplates();

            for (int n = 0; n < atmpl24.Length; n++)
            {
                Template tmpl24 = atmpl24[n];
                Template tmpl16 = atmpl16[n];
                tmpl24.TerrainMap = tmpl16.TerrainMap;
            }

            tmpd24.SetBackgroundTemplate(atmpl24[0]);
            tmpd24.SaveAs(strFileSave);
        }
Exemplo n.º 6
0
        public static TemplateDoc CloneTemplateDoc(TemplateDoc tmpdSrc)
        {
            // This should probably be on ICloneable::Clone() on TemplateDoc

            TemplateDoc tmpdDst = (TemplateDoc)DocManager.NewDocument(typeof(TemplateDoc), new Object[] { tmpdSrc.TileSize });

            DocManager.SetActiveDocument(typeof(TemplateDoc), tmpdSrc);

            Template[] atmplSrc          = tmpdSrc.GetTemplates();
            Template   tmplSrcBackground = tmpdSrc.GetBackgroundTemplate();
            Template   tmplDstBackground = null;
            ArrayList  alsTmplDst        = new ArrayList();

            foreach (Template tmplSrc in atmplSrc)
            {
                Template tmplDst = new Template(tmpdDst, tmplSrc.Name);
                tmplDst.OccupancyMap = tmplSrc.OccupancyMap;
                tmplDst.TerrainMap   = tmplSrc.TerrainMap;
                tmplDst.Bitmap       = (Bitmap)tmplSrc.Bitmap.Clone();
                alsTmplDst.Add(tmplDst);
                if (tmplSrc == tmplSrcBackground)
                {
                    tmplDstBackground = tmplDst;
                }
            }
            if (tmplDstBackground != null)
            {
                tmpdDst.SetBackgroundTemplate(tmplDstBackground);
            }
            tmpdDst.AddTemplates((Template[])alsTmplDst.ToArray(typeof(Template)));
            Palette palSrc = tmpdSrc.GetPalette();

            if (palSrc != null)
            {
                tmpdDst.SetPalette(palSrc, false);
            }

            return(tmpdDst);
        }
        public EditTerrainForm(TemplateDoc tmpd)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            m_sizTile = tmpd.TileSize;
            for (int n = 0; n < m_abr.Length; n++)
                m_abr[n] = new SolidBrush(s_aclrTerrain[n]);

            Template[] atmpl = tmpd.GetTemplates();
            panel1.SuspendLayout();
            foreach (Template tmpl in atmpl) {
                PictureBox picb = new PictureBox();
                picb.Image = ConstructTerrainBitmap(tmpl);
                picb.SizeMode = PictureBoxSizeMode.AutoSize;
                picb.Tag = (Object)tmpl;
                picb.MouseDown += new MouseEventHandler(PictureBox_MouseDown);
                panel1.Controls.Add(picb);
            }
            panel1.ResumeLayout();
        }
Exemplo n.º 8
0
        public static void ScaleTemplates(TemplateDoc tmpd, Size sizTile)
        {
            // Scale templates

            Template[] atmpl = tmpd.GetTemplates();
            Template tmplBackground = tmpd.GetBackgroundTemplate();
            tmpd.RemoveTemplates(atmpl);
            foreach (Template tmpl in atmpl)
                ScaleTemplate(tmpl, tmpd.TileSize, sizTile);
            tmpd.TileSize = sizTile;
            tmpd.AddTemplates(atmpl);
            tmpd.SetBackgroundTemplate(tmplBackground);
        }
Exemplo n.º 9
0
        public static void QuantizeTemplates(TemplateDoc tmpd, Palette palFixed, int cPalEntries, int cPalEntriesFixed, int cPalEntriesBackground)
        {
            // Load the fixed palette. The result will be 24 bit templates normalized to a palette of 256 colors,
            // the "fixed" palette plus a quantized palette.

            if (palFixed == null) {
                palFixed = Palette.OpenDialog(null);
                if (palFixed == null) {
                    MessageBox.Show(DocManager.GetFrameParent(), "Must have the fixed color palette to continue!");
                    return;
                }

                switch (palFixed.Length) {
                case 16:
                    cPalEntries = 16;
                    cPalEntriesFixed = 16;
                    cPalEntriesBackground = 0;
                    break;

                case 256:
                    cPalEntries = 256;
                    cPalEntriesFixed = 128;
                    cPalEntriesBackground = 32;
                    break;
                }
            }

            // Quantize loop. Designed to make optimal use of the lower 128 fixed colors

            // Quantize background separately from foreground

            Template tmplBackground = tmpd.GetBackgroundTemplate();
            if (tmplBackground != null && cPalEntriesBackground != 0) {
                // Create a despeckled hue map of the background. We'll use this to
                // subtract background from foreground so we can quantize foreground separately

                Bitmap bmHueBackground = MakeHueMap(tmplBackground.Bitmap);
                DespeckleGrayscaleBitmap(bmHueBackground, 9, 50);

                // Calc mean and standard deviation for filtering purposes

                double nMean = CalcGrayscaleMean(bmHueBackground);
                double nStdDev = CalcGrayscaleStandardDeviation(bmHueBackground, nMean);

                // Add extract & quantize the background pixels

                ArrayList alsColorsBackground = new ArrayList();
                AddTemplateColors(alsColorsBackground, tmplBackground.Bitmap);
                palFixed = QuantizeColors(alsColorsBackground, palFixed, cPalEntriesFixed + cPalEntriesBackground, cPalEntriesFixed);
                cPalEntriesFixed += cPalEntriesBackground;

                // Now extract foreground pixels by first subtracting background pixels

                ArrayList alsColorsForeground = new ArrayList();
                Template[] atmpl = tmpd.GetTemplates();
                foreach (Template tmpl in atmpl) {
                    if (tmpl == tmplBackground)
                        continue;
                    Bitmap bmT = MakeHueMap(tmpl.Bitmap);
                    DespeckleGrayscaleBitmap(bmT, 9, 50);
                    SubtractGrayscaleDistribution(bmT, nMean, nStdDev);
                    for (int y = 0; y < bmT.Height; y++) {
                        for (int x = 0; x < bmT.Width; x++) {
                            Color clr = bmT.GetPixel(x, y);
                            if (clr != Color.FromArgb(255, 0, 255))
                                bmT.SetPixel(x, y, tmpl.Bitmap.GetPixel(x, y));
                        }
                    }
                    AddTemplateColors(alsColorsForeground, bmT);
                }

                // Now quantize foreground pixels
                // Set the palette and color match

                Palette palNew = QuantizeColors(alsColorsForeground, palFixed, cPalEntries, cPalEntriesFixed);
                tmpd.SetPalette(palNew, true);
            } else {
                // No background template; just quantize everything together

                Template[] atmpl = tmpd.GetTemplates();
                ArrayList alsColors = new ArrayList();
                foreach (Template tmpl in atmpl)
                    AddTemplateColors(alsColors, tmpl.Bitmap);

                // Now quantize foreground pixels
                // Set the palette and color match

                Palette palNew = QuantizeColors(alsColors, palFixed, cPalEntries, cPalEntriesFixed);
                tmpd.SetPalette(palNew, true);
            }
        }
Exemplo n.º 10
0
        public static TemplateDoc CloneTemplateDoc(TemplateDoc tmpdSrc)
        {
            // This should probably be on ICloneable::Clone() on TemplateDoc

            TemplateDoc tmpdDst = (TemplateDoc)DocManager.NewDocument(typeof(TemplateDoc), new Object[] { tmpdSrc.TileSize });
            DocManager.SetActiveDocument(typeof(TemplateDoc), tmpdSrc);

            Template[] atmplSrc = tmpdSrc.GetTemplates();
            Template tmplSrcBackground = tmpdSrc.GetBackgroundTemplate();
            Template tmplDstBackground = null;
            ArrayList alsTmplDst = new ArrayList();
            foreach (Template tmplSrc in atmplSrc) {
                Template tmplDst = new Template(tmpdDst, tmplSrc.Name);
                tmplDst.OccupancyMap = tmplSrc.OccupancyMap;
                tmplDst.TerrainMap = tmplSrc.TerrainMap;
                tmplDst.Bitmap = (Bitmap)tmplSrc.Bitmap.Clone();
                alsTmplDst.Add(tmplDst);
                if (tmplSrc == tmplSrcBackground)
                    tmplDstBackground = tmplDst;
            }
            if (tmplDstBackground != null)
                tmpdDst.SetBackgroundTemplate(tmplDstBackground);
            tmpdDst.AddTemplates((Template[])alsTmplDst.ToArray(typeof(Template)));
            Palette palSrc = tmpdSrc.GetPalette();
            if (palSrc != null)
                tmpdDst.SetPalette(palSrc, false);

            return tmpdDst;
        }
Exemplo n.º 11
0
        public static void QuantizeTemplates(TemplateDoc tmpd, Palette palFixed, int cPalEntries, int cPalEntriesFixed, int cPalEntriesBackground)
        {
            // Load the fixed palette. The result will be 24 bit templates normalized to a palette of 256 colors,
            // the "fixed" palette plus a quantized palette.

            if (palFixed == null)
            {
                palFixed = Palette.OpenDialog(null);
                if (palFixed == null)
                {
                    MessageBox.Show(DocManager.GetFrameParent(), "Must have the fixed color palette to continue!");
                    return;
                }

                switch (palFixed.Length)
                {
                case 16:
                    cPalEntries           = 16;
                    cPalEntriesFixed      = 16;
                    cPalEntriesBackground = 0;
                    break;

                case 256:
                    cPalEntries           = 256;
                    cPalEntriesFixed      = 128;
                    cPalEntriesBackground = 32;
                    break;
                }
            }

            // Quantize loop. Designed to make optimal use of the lower 128 fixed colors

            // Quantize background separately from foreground

            Template tmplBackground = tmpd.GetBackgroundTemplate();

            if (tmplBackground != null && cPalEntriesBackground != 0)
            {
                // Create a despeckled hue map of the background. We'll use this to
                // subtract background from foreground so we can quantize foreground separately

                Bitmap bmHueBackground = MakeHueMap(tmplBackground.Bitmap);
                DespeckleGrayscaleBitmap(bmHueBackground, 9, 50);

                // Calc mean and standard deviation for filtering purposes

                double nMean   = CalcGrayscaleMean(bmHueBackground);
                double nStdDev = CalcGrayscaleStandardDeviation(bmHueBackground, nMean);

                // Add extract & quantize the background pixels

                ArrayList alsColorsBackground = new ArrayList();
                AddTemplateColors(alsColorsBackground, tmplBackground.Bitmap);
                palFixed          = QuantizeColors(alsColorsBackground, palFixed, cPalEntriesFixed + cPalEntriesBackground, cPalEntriesFixed);
                cPalEntriesFixed += cPalEntriesBackground;

                // Now extract foreground pixels by first subtracting background pixels

                ArrayList  alsColorsForeground = new ArrayList();
                Template[] atmpl = tmpd.GetTemplates();
                foreach (Template tmpl in atmpl)
                {
                    if (tmpl == tmplBackground)
                    {
                        continue;
                    }
                    Bitmap bmT = MakeHueMap(tmpl.Bitmap);
                    DespeckleGrayscaleBitmap(bmT, 9, 50);
                    SubtractGrayscaleDistribution(bmT, nMean, nStdDev);
                    for (int y = 0; y < bmT.Height; y++)
                    {
                        for (int x = 0; x < bmT.Width; x++)
                        {
                            Color clr = bmT.GetPixel(x, y);
                            if (clr != Color.FromArgb(255, 0, 255))
                            {
                                bmT.SetPixel(x, y, tmpl.Bitmap.GetPixel(x, y));
                            }
                        }
                    }
                    AddTemplateColors(alsColorsForeground, bmT);
                }

                // Now quantize foreground pixels
                // Set the palette and color match

                Palette palNew = QuantizeColors(alsColorsForeground, palFixed, cPalEntries, cPalEntriesFixed);
                tmpd.SetPalette(palNew, true);
            }
            else
            {
                // No background template; just quantize everything together

                Template[] atmpl     = tmpd.GetTemplates();
                ArrayList  alsColors = new ArrayList();
                foreach (Template tmpl in atmpl)
                {
                    AddTemplateColors(alsColors, tmpl.Bitmap);
                }

                // Now quantize foreground pixels
                // Set the palette and color match

                Palette palNew = QuantizeColors(alsColors, palFixed, cPalEntries, cPalEntriesFixed);
                tmpd.SetPalette(palNew, true);
            }
        }
Exemplo n.º 12
0
        static void ImportTileMap(TileMap tmap, TileSet tset, TemplateDoc tmpd, LevelDoc lvld)
        {
            // The TileMap is a list of indexes into a tile set. A Tileset is a list of tiles compiled
            // from Templates. Reverse the tilemap into Templates, and set into lvld.

            bool[,] afCellTaken = new bool[64, 64];
            ArrayList alsTemplPos = new ArrayList();

            Template[] atmpl = tmpd.GetTemplates();
            for (int ty = 0; ty < tmap.Height; ty++)
            {
                for (int tx = 0; tx < tmap.Width; tx++)
                {
                    // Cell mapped already?
                    if (afCellTaken[ty, tx])
                    {
                        continue;
                    }

                    // Cell not mapped. Create TemplatePos.
                    int      iTile = tmap.GetTileIndex(tx, ty);
                    TileData tdata = tset.GetTileData(iTile);
                    Template tmpl  = atmpl[tdata.iTemplate];

                    // Don't bother with background tiles
                    if (tmpl == tmpd.GetBackgroundTemplate())
                    {
                        continue;
                    }

                    int txOrigin = tx - tdata.txTemplate;
                    int tyOrigin = ty - tdata.tyTemplate;
                    bool[,] afMapped = new bool[tmpl.Cty, tmpl.Ctx];

                    for (int tyTmpl = 0; tyTmpl < tmpl.Cty; tyTmpl++)
                    {
                        for (int txTmpl = 0; txTmpl < tmpl.Ctx; txTmpl++)
                        {
                            int txT = txOrigin + txTmpl;
                            int tyT = tyOrigin + tyTmpl;
                            if (txT < 0 || txT >= 64 || tyT < 0 || tyT >= 64)
                            {
                                continue;
                            }
                            if (afCellTaken[tyT, txT])
                            {
                                continue;
                            }
                            int iTileT = tmap.GetTileIndex(txT, tyT);
                            if (iTileT != -1)
                            {
                                TileData tdataT = tset.GetTileData(iTileT);
                                if (tdataT.iTemplate != tdata.iTemplate)
                                {
                                    continue;
                                }
                                if (tdataT.txTemplate != txTmpl || tdataT.tyTemplate != tyTmpl)
                                {
                                    continue;
                                }
                            }
                            afMapped[tyTmpl, txTmpl] = true;
                            afCellTaken[tyT, txT]    = true;
                        }
                    }
                    alsTemplPos.Add(new TemplatePos(tmpl, txOrigin, tyOrigin, afMapped));
                }
            }

            // Figure out the bounds.

            Rectangle rcBounds = new Rectangle((64 - tmap.Width) / 2, (64 - tmap.Height) / 2,
                                               tmap.Width, tmap.Height);

            lvld.Bounds = rcBounds;

            // The list of TemplatePos's has been created. Add to LevelDoc.

            ArrayList alsTiles = new ArrayList();

            foreach (TemplatePos tpos in alsTemplPos)
            {
                Tile tile = new Tile(tpos.tmpl.Name,
                                     tpos.txOrigin + rcBounds.Left,
                                     tpos.tyOrigin + rcBounds.Top,
                                     tpos.afMapped, tpos.tmpl.OccupancyMap);
                alsTiles.Add(tile);
            }
            lvld.AddMapItems((IMapItem[])alsTiles.ToArray(typeof(IMapItem)));
        }
Exemplo n.º 13
0
        static void ImportTileMap(TileMap tmap, TileSet tset, TemplateDoc tmpd, LevelDoc lvld)
        {
            // The TileMap is a list of indexes into a tile set. A Tileset is a list of tiles compiled
            // from Templates. Reverse the tilemap into Templates, and set into lvld.

            bool[,] afCellTaken = new bool[64, 64];
            ArrayList alsTemplPos = new ArrayList();
            Template[] atmpl = tmpd.GetTemplates();
            for (int ty = 0; ty < tmap.Height; ty++) {
                for (int tx = 0; tx < tmap.Width; tx++) {
                    // Cell mapped already?
                    if (afCellTaken[ty, tx]) {
                        continue;
                    }

                    // Cell not mapped. Create TemplatePos.
                    int iTile = tmap.GetTileIndex(tx, ty);
                    TileData tdata = tset.GetTileData(iTile);
                    Template tmpl = atmpl[tdata.iTemplate];

                    // Don't bother with background tiles
                    if (tmpl == tmpd.GetBackgroundTemplate()) {
                        continue;
                    }

                    int txOrigin = tx - tdata.txTemplate;
                    int tyOrigin = ty - tdata.tyTemplate;
                    bool[,] afMapped = new bool[tmpl.Cty, tmpl.Ctx];

                    for (int tyTmpl = 0; tyTmpl < tmpl.Cty; tyTmpl++) {
                        for (int txTmpl = 0; txTmpl < tmpl.Ctx; txTmpl++) {
                            int txT = txOrigin + txTmpl;
                            int tyT = tyOrigin + tyTmpl;
                            if (txT < 0 || txT >= 64 || tyT < 0 || tyT >= 64) {
                                continue;
                            }
                            if (afCellTaken[tyT, txT]) {
                                continue;
                            }
                            int iTileT = tmap.GetTileIndex(txT, tyT);
                            if (iTileT != -1) {
                                TileData tdataT = tset.GetTileData(iTileT);
                                if (tdataT.iTemplate != tdata.iTemplate) {
                                    continue;
                                }
                                if (tdataT.txTemplate != txTmpl || tdataT.tyTemplate != tyTmpl) {
                                    continue;
                                }
                            }
                            afMapped[tyTmpl, txTmpl] = true;
                            afCellTaken[tyT, txT] = true;
                        }
                    }
                    alsTemplPos.Add(new TemplatePos(tmpl, txOrigin, tyOrigin, afMapped));
                }
            }

            // Figure out the bounds.

            Rectangle rcBounds = new Rectangle((64 - tmap.Width) / 2, (64 - tmap.Height) / 2,
                    tmap.Width, tmap.Height);
            lvld.Bounds = rcBounds;

            // The list of TemplatePos's has been created. Add to LevelDoc.

            ArrayList alsTiles = new ArrayList();
            foreach (TemplatePos tpos in alsTemplPos) {
                Tile tile = new Tile(tpos.tmpl.Name,
                        tpos.txOrigin + rcBounds.Left,
                        tpos.tyOrigin + rcBounds.Top,
                        tpos.afMapped, tpos.tmpl.OccupancyMap);
                alsTiles.Add(tile);
            }
            lvld.AddMapItems((IMapItem[])alsTiles.ToArray(typeof(IMapItem)));
        }
Exemplo n.º 14
0
        public static void MixMapImportSpecial(Theater theater, TemplateDoc tmpdCopyTerrain, string strFileSave)
        {
            TemplateDoc tmpd24 = (TemplateDoc)DocManager.NewDocument(typeof(TemplateDoc), new Object[] { new Size(24, 24) });
            MixTemplate[] amixt = MixSuck.LoadTemplates(theater);
            MixSuck.ImportTemplates(amixt, tmpd24);

            Template[] atmpl24 = tmpd24.GetTemplates();
            Template[] atmpl16 = tmpdCopyTerrain.GetTemplates();

            for (int n = 0; n < atmpl24.Length; n++) {
                Template tmpl24 = atmpl24[n];
                Template tmpl16 = atmpl16[n];
                tmpl24.TerrainMap = tmpl16.TerrainMap;
            }

            tmpd24.SetBackgroundTemplate(atmpl24[0]);
            tmpd24.SaveAs(strFileSave);
        }