Ejemplo n.º 1
0
 public Template GetTemplate(TemplateDoc tmpd)
 {
     if (tmpd == m_tmpdCache)
         return m_tmplCache;
     m_tmpdCache = null;
     m_tmplCache = null;
     m_bmCache = null;
     if (tmpd == null)
         return null;
     Template tmpl = tmpd.FindTemplate(m_strName);
     if (tmpl != null) {
         m_tmpdCache = tmpd;
         m_tmplCache = tmpl;
         m_afOccupancy = tmpl.OccupancyMap;
         return tmpl;
     }
     return null;
 }
Ejemplo n.º 2
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;
        }
Ejemplo n.º 3
0
 static void ScaleTemplate(Template tmpl, Size sizTileSrc, Size sizTileDst)
 {
     bool [,] afOccupancySrc = tmpl.OccupancyMap;
     int ctx = afOccupancySrc.GetLength(1);
     int cty = afOccupancySrc.GetLength(0);
     Bitmap bmDst = new Bitmap(ctx * sizTileDst.Width, cty * sizTileDst.Height);
     Graphics gDst = Graphics.FromImage(bmDst);
     gDst.Clear(Color.FromArgb(255, 0, 255));
     for (int tx = 0; tx < ctx; tx++) {
         for (int ty = 0; ty < cty; ty++) {
             if (!afOccupancySrc[ty, tx])
                 continue;
             Rectangle rcSrc = new Rectangle(new Point(tx * sizTileSrc.Width, ty * sizTileSrc.Height), sizTileSrc);
             Rectangle rcDst = new Rectangle(new Point(tx * sizTileDst.Width, ty * sizTileDst.Height), sizTileDst);
             gDst.DrawImage(tmpl.Bitmap, rcDst, rcSrc, GraphicsUnit.Pixel);
         }
     }
     gDst.Dispose();
     bmDst.MakeTransparent(Color.FromArgb(255, 0, 255));
     tmpl.Bitmap = bmDst;
 }
Ejemplo n.º 4
0
 public void SetBackgroundTemplate(Template tmpl)
 {
     if (m_tmplBackground == tmpl)
         return;
     m_tmplBackground = tmpl;
     if (BackgroundChanged != null)
         BackgroundChanged(this);
     SetModified(true);
 }
        private Bitmap ConstructTerrainBitmap(Template tmpl)
        {
            Bitmap bm = new Bitmap(tmpl.Bitmap);
            Graphics g = Graphics.FromImage(bm);
            int ctx = tmpl.Bitmap.Width / m_sizTile.Width;
            int cty = tmpl.Bitmap.Height / m_sizTile.Height;
            for (int ty = 0; ty < cty; ty++) {
                for (int tx = 0; tx < ctx; tx++) {
                    if (!tmpl.OccupancyMap[ty, tx])
                        continue;
                    int n = (int)tmpl.TerrainMap[ty, tx];
                    g.FillRectangle(m_abr[n], tx * m_sizTile.Width, ty * m_sizTile.Height, m_sizTile.Width, m_sizTile.Height);
                    bm.SetPixel(tx * m_sizTile.Width + m_sizTile.Width / 2, ty * m_sizTile.Height + m_sizTile.Height / 2, Color.White);
                }
            }

            return Misc.TraceEdges(bm, 1, Color.Azure);
        }
Ejemplo n.º 6
0
 public void RemoveTemplates(Template[] atmpl)
 {
     if (atmpl.Length == 0)
         return;
     ArrayList alsNames = new ArrayList();
     foreach (Template tmpl in atmpl) {
         m_alsTemplates.Remove(tmpl);
         alsNames.Add(tmpl.Name);
         if (tmpl == m_tmplBackground)
             SetBackgroundTemplate(null);
     }
     TemplateDocTemplate doct = (TemplateDocTemplate)m_doct;
     doct.OnTemplatesRemoved(this, (string[])alsNames.ToArray(typeof(string)));
     SetModified(true);
 }
Ejemplo n.º 7
0
 public Template GetBackgroundTemplate()
 {
     if (m_tmplBackground == null && m_strNameBackground != null)
         m_tmplBackground = FindTemplate(m_strNameBackground);
     return m_tmplBackground;
 }
Ejemplo n.º 8
0
 public void AddTemplates(Template[] atmpl)
 {
     if (atmpl.Length == 0)
         return;
     ArrayList alsNamesAdded = new ArrayList();
     foreach (Template tmpl in atmpl) {
         m_alsTemplates.Add(tmpl);
         alsNamesAdded.Add(tmpl.Name);
     }
     TemplateDocTemplate doct = (TemplateDocTemplate)m_doct;
     doct.OnTemplatesAdded(this, (string[])alsNamesAdded.ToArray(typeof(string)));
     SetModified(true);
 }
Ejemplo n.º 9
0
 public void AddTemplates(string[] astrFileBitmap)
 {
     ArrayList alsNamesAdded = new ArrayList();
     foreach (string strFileBitmap in astrFileBitmap) {
         Template tmpl = new Template(this, "tmpl" + m_cookie);
         m_cookie++;
         if (tmpl.Import(strFileBitmap)) {
             alsNamesAdded.Add(tmpl.Name);
             m_alsTemplates.Add(tmpl);
         }
     }
     if (alsNamesAdded.Count != 0) {
         TemplateDocTemplate doct = (TemplateDocTemplate)m_doct;
         doct.OnTemplatesAdded(this, (string[])alsNamesAdded.ToArray(typeof(string)));
     }
     SetModified(true);
 }
Ejemplo n.º 10
0
 public TemplatePos(Template tmpl, int txOrigin, int tyOrigin, bool[,] afMapped)
 {
     this.tmpl = tmpl;
     this.txOrigin = txOrigin;
     this.tyOrigin = tyOrigin;
     this.afMapped = afMapped;
 }