Exemple #1
0
    private void ProcessSceneXML(string xml)
    {
        SceneDoc sceneData = XMLHelper.FromXml <SceneDoc> (xml);

        Debug.LogFormat("Levels: {0}", sceneData.Levels.Length);

        if (sceneData.Levels.Length <= 0)
        {
            return;
        }

        if (loadedObject == null)
        {
            Log.Text(label, "Tap 'Load Asset Bundle' first to load prefabs");
            return;
        }

        LevelDoc level = sceneData.Levels [0];

        foreach (PrefabDoc prefab in level.Prefabs)
        {
            prefab.Init();
            Debug.LogFormat("Name: {0} Color: {1} Location: {2} Scale: {3}", prefab.name, prefab.GetColour(), prefab.GetPosition(), prefab.GetScale());
            AddPrefab(prefab.GetPosition(), Quaternion.identity, prefab.GetScale(), prefab.GetColour());
        }
    }
Exemple #2
0
        public static void ExportMixMaps(string[] astr)
        {
            // Expand filespecs
            ArrayList alsFiles = new ArrayList();

            for (int n = 1; n < astr.Length; n++)
            {
                string strFileT = Path.GetFileName(astr[n]);
                string strDirT  = Path.GetDirectoryName(astr[n]);
                if (strDirT == "")
                {
                    strDirT = ".";
                }
                string[] astrFiles = Directory.GetFiles(strDirT, strFileT);
                alsFiles.AddRange(astrFiles);
            }

            foreach (string strFile in alsFiles)
            {
                LevelDoc lvld = (LevelDoc)DocManager.NewDocument(typeof(LevelDoc), null);
                Console.Write("Exporting " + strFile + " as ");
                string strFileExport = MixSuck.ImportExportMixMap(strFile, lvld);
                if (strFileExport == null)
                {
                    Console.Write("Error exporting!\n");
                }
                else
                {
                    Console.Write(strFileExport + "\n");
                }
                lvld.Dispose();
            }
        }
Exemple #3
0
        public void SetDocument(Document doc)
        {
            // This call is required by the Windows.Forms Form Designer.

            InitializeComponent();

            // Add any initialization after the InitForm call

            m_lvld = (LevelDoc)doc;

            // Create the bitmap

            AutoScroll = true;
            VScroll    = true;
            HScroll    = true;
            CreateBitmap();

            // Init view position

            InitPosition();

            // Draw it initially

            m_lvld.Draw(m_bm, null, GetTileSize(), GetTemplateDoc(), m_lyrf);

            // Need to know these events

            m_lvld.ImageChanged += new LevelDoc.ImageChangedHandler(LevelDoc_ImageChanged);
            m_lvld.ItemsRemoved += new LevelDoc.ItemsRemovedHandler(LevelDoc_ItemsRemoved);

            // Check size

            CheckSize();
        }
Exemple #4
0
        static public StringCollection GetAreaNames()
        {
            LevelDoc lvld = (LevelDoc)DocManager.GetActiveDocument(typeof(LevelDoc));

            IMapItem[] ami = lvld.MapItems;
            ArrayList  al  = new ArrayList();

            foreach (IMapItem mi in ami)
            {
                if (!(mi is Area))
                {
                    continue;
                }
                al.Add(((Area)mi).Name);
            }
            al.Add("[LastDiscovery]");
            al.Sort();

            StringCollection strc = new StringCollection();

            foreach (string str in al)
            {
                strc.Add(str);
            }
            return(strc);
        }
Exemple #5
0
        void LevelDocTemplate_DocActive(Document doc)
        {
            LevelDoc lvld = (LevelDoc)doc;

            if (lvld != null)
            {
                SetActiveDoc(lvld.GetTemplateDoc());
            }
        }
Exemple #6
0
        public static StringCollection GetSwitchNames()
        {
            LevelDoc         lvld = (LevelDoc)DocManager.GetActiveDocument(typeof(LevelDoc));
            StringCollection strc = new StringCollection();

            foreach (Switch sw in lvld.SwitchManager.Items)
            {
                strc.Add(sw.Name);
            }
            return(strc);
        }
        public EditLevelTextForm(LevelDoc lvld)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            m_lvld            = lvld;
            m_strLevelText    = m_lvld.GetLevelText();
            richTextBox1.Text = m_strLevelText;
        }
Exemple #8
0
        public static StringCollection GetCounterNames()
        {
            LevelDoc         lvld = (LevelDoc)DocManager.GetActiveDocument(typeof(LevelDoc));
            StringCollection strc = new StringCollection();

            foreach (Counter ctr in lvld.CounterManager.Items)
            {
                strc.Add(ctr.Name);
            }
            return(strc);
        }
Exemple #9
0
        StringCollection GetUnitGroupNames()
        {
            LevelDoc         lvld = (LevelDoc)DocManager.GetActiveDocument(typeof(LevelDoc));
            StringCollection strc = new StringCollection();

            foreach (UnitGroup ug in lvld.UnitGroupManager.Items)
            {
                strc.Add(ug.Name);
            }
            return(strc);
        }
Exemple #10
0
        public override string FromSaveString(string strArgs, bool fLast)
        {
            Regex    re    = new Regex(@"^(?<index>(-)?\d+)(?<end>.*)$");
            Match    m     = re.Match(strArgs);
            int      index = int.Parse(m.Groups["index"].Value);
            LevelDoc lvld  = (LevelDoc)DocManager.GetActiveDocument(typeof(LevelDoc));

            if (index >= 0 && index < lvld.UnitGroupManager.Items.Count)
            {
                m_ug    = (UnitGroup)lvld.UnitGroupManager.Items[index];
                m_fInit = true;
            }
            return(m.Groups["end"].Value);
        }
Exemple #11
0
 public static void Fixup(LevelDoc lvld)
 {
     foreach (CaTypeSwitch catSwitch in s_alsFixup)
     {
         catSwitch.m_sw = lvld.SwitchManager[catSwitch.m_strName];
         if (catSwitch.m_sw == null)
         {
             catSwitch.m_sw = new Switch(catSwitch.m_strName);
             lvld.SwitchManager.AddSwitch(catSwitch.m_sw);
             catSwitch.m_strName = null;
         }
     }
     s_alsFixup = null;
 }
Exemple #12
0
        public static void ImportText(string[] astr)
        {
            // Expand filespecs
            ArrayList alsFiles = new ArrayList();

            for (int n = 1; n < astr.Length; n++)
            {
                string strFileT = Path.GetFileName(astr[n]);
                string strDirT  = Path.GetDirectoryName(astr[n]);
                if (strDirT == "")
                {
                    strDirT = ".";
                }
                string[] astrFiles = Directory.GetFiles(strDirT, strFileT);
                alsFiles.AddRange(astrFiles);
            }

            Console.WriteLine("Importing text from {0} files", alsFiles.Count);

            // Attempt to process these text files/level docs

            foreach (string strTextFile in alsFiles)
            {
                string strFile = "." + Path.DirectorySeparatorChar + Path.GetFileName(strTextFile).Replace(".txt", ".ld");
                Console.Write("Writing " + strTextFile + " to " + strFile + "...");
                LevelDoc lvld = (LevelDoc)DocManager.OpenDocument(strFile);
                if (lvld == null)
                {
                    throw new Exception("Could not load level doc " + strFile);
                }

                StreamReader stmr = new StreamReader(strTextFile);
                string       str  = stmr.ReadToEnd();
                stmr.Close();
                str = str.Replace("\r\n", "\n");

                int ichErrorPos;
                if (!lvld.SetLevelText(str, out ichErrorPos))
                {
                    Console.WriteLine(" error at char " + ichErrorPos);
                }
                else
                {
                    lvld.Save();
                    Console.WriteLine(" saved");
                }
                lvld.Dispose();
            }
        }
Exemple #13
0
        public override string FromSaveString(string strArgs, bool fLast)
        {
            Regex            re    = new Regex(@"^(?<index>(-)?\d+)(?<end>.*)$");
            Match            m     = re.Match(strArgs);
            int              index = int.Parse(m.Groups["index"].Value);
            StringCollection strc  = GetSwitchNames();

            if (index >= 0 && index < strc.Count)
            {
                LevelDoc lvld = (LevelDoc)DocManager.GetActiveDocument(typeof(LevelDoc));
                m_sw    = lvld.SwitchManager[strc[index]];
                m_fInit = true;
            }
            return(m.Groups["end"].Value);
        }
Exemple #14
0
        public override bool EditProperties()
        {
            StringCollection strc    = GetUnitGroupNames();
            string           strName = m_ug != null ? m_ug.Name : "";
            int n = PickListForm.DoModal("Unit Group", strName, strc);

            if (n == -1)
            {
                return(false);
            }
            LevelDoc lvld = (LevelDoc)DocManager.GetActiveDocument(typeof(LevelDoc));

            m_ug    = (UnitGroup)lvld.UnitGroupManager.Items[n];
            m_fInit = true;
            return(true);
        }
Exemple #15
0
        public override bool EditProperties()
        {
            StringCollection strc    = GetUnitTypeNames();
            string           strName = m_ut != UnitType.kutNone ? Helper.GetDisplayName(typeof(UnitType), m_ut.ToString()) : "";
            int n = PickListForm.DoModal("Unit Type", strName, strc);

            if (n == -1)
            {
                return(false);
            }
            LevelDoc lvld = (LevelDoc)DocManager.GetActiveDocument(typeof(LevelDoc));

            m_ut    = (UnitType)n;
            m_fInit = true;
            return(true);
        }
Exemple #16
0
        public UnitGroupsForm(LevelDoc lvld, UnitGroupManager ugm)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //

            m_ugm  = ugm;
            m_lvld = lvld;
            m_ugm.ClearModified();
            InitUnitGroupsListBox();
            InitSideComboBox();
            InitAggressivenessComboBox();
            InitSpawnAreaComboBox();
        }
Exemple #17
0
        static void ImportWalls(TerrainMap trmap, LevelDoc lvld)
        {
            ArrayList alsmi = new ArrayList();

            for (int ty = 0; ty < trmap.Map.GetLength(0); ty++)
            {
                for (int tx = 0; tx < trmap.Map.GetLength(1); tx++)
                {
                    if (trmap.Map[ty, tx] == TerrainTypes.Wall)
                    {
                        IMapItem mi = new Wall(100, lvld.Bounds.Left + tx, lvld.Bounds.Top + ty);
                        alsmi.Add(mi);
                    }
                }
            }
            lvld.AddMapItems((IMapItem[])alsmi.ToArray(typeof(IMapItem)));
        }
Exemple #18
0
        public static void ExportImages(string[] astr)
        {
            // Get directory
            //string strDir = Path.GetFullPath(astr[1]);
            string strDir    = ".";
            string strPrefix = astr[1];

            // Expand filespecs
            ArrayList alsFiles = new ArrayList();

            for (int n = 2; n < astr.Length; n++)
            {
                string strFileT = Path.GetFileName(astr[n]);
                string strDirT  = Path.GetDirectoryName(astr[n]);
                if (strDirT == "")
                {
                    strDirT = ".";
                }
                string[] astrFiles = Directory.GetFiles(strDirT, strFileT);
                alsFiles.AddRange(astrFiles);
            }

            // Attempt to process these level docs
            foreach (string strFile in alsFiles)
            {
                Console.Write("Map of " + strFile + " -> ");
                LevelDoc lvld = (LevelDoc)DocManager.OpenDocument(strFile);
                if (lvld == null)
                {
                    throw new Exception("Could not load level doc " + strFile);
                }
                string strPng = strDir + Path.DirectorySeparatorChar + strPrefix + Path.GetFileName(strFile).Replace(".ld", ".png");
                Console.Write(strPng + "...");
                TemplateDoc tmpd = lvld.GetTemplateDoc();
                Bitmap      bm   = lvld.GetMapBitmap(tmpd.TileSize, tmpd, true);
                bm.Save(strPng, ImageFormat.Png);
                bm.Dispose();
                lvld.Dispose();
                Console.Write(" Done.\n");
            }
        }
Exemple #19
0
        private void tbcOutput_DoubleClick(object sender, System.EventArgs e)
        {
            LevelDoc lvld = (LevelDoc)DocManager.GetActiveDocument(typeof(LevelDoc));

            if (lvld == null)
            {
                return;
            }

            // scan backwards from the insertion point to the beginning of the line

            string strT = tbcOutput.Text;
            int    i    = tbcOutput.SelectionStart;

            while (i > 0 && strT[i] != '\n')
            {
                i--;
            }
            if (i != 0)
            {
                i++;
            }
            strT = strT.Substring(i, strT.IndexOf('>', i) - i);

            // Select the item with the error

            i = int.Parse(strT);
            LevelError lvle = (LevelError)m_alLevelErrors[i];

            if (lvle.Object is IMapItem)
            {
                ArrayList al = new ArrayList();
                al.Add(lvle.Object);
                lvle.LevelDoc.Selection = al;
            }
            else if (lvle.Object is SideInfo)
            {
                Globals.PropertyGrid.SelectedObject = lvle.Object;
            }
        }
Exemple #20
0
        public void ImportMap(LevelDoc lvld)
        {
            TemplatePos[] atpos    = GetTemplatePositions();
            ArrayList     alsTiles = new ArrayList();

            foreach (TemplatePos tpos in atpos)
            {
                int txOrigin = 64 - tpos.m_mixt.XTileCount - tpos.m_txOrigin;
                int tyOrigin = tpos.m_tyOrigin;
                bool[,] afDraw = new bool[tpos.m_mixt.YTileCount, tpos.m_mixt.XTileCount];
                for (int ty = 0; ty < tpos.m_mixt.YTileCount; ty++)
                {
                    for (int tx = 0; tx < tpos.m_mixt.XTileCount; tx++)
                    {
                        afDraw[ty, tx] = tpos.m_afMapped[ty, tpos.m_mixt.XTileCount - tx - 1];
                    }
                }
                Tile tile = new Tile(tpos.m_mixt.Index.ToString(), txOrigin, tyOrigin, afDraw, null);
                alsTiles.Add(tile);
            }
            lvld.AddMapItems((IMapItem[])alsTiles.ToArray(typeof(IMapItem)));
        }
Exemple #21
0
        public static void ExportText(string[] astr)
        {
            // Expand filespecs
            ArrayList alsFiles = new ArrayList();

            for (int n = 1; n < astr.Length; n++)
            {
                string strFileT = Path.GetFileName(astr[n]);
                string strDirT  = Path.GetDirectoryName(astr[n]);
                if (strDirT == "")
                {
                    strDirT = ".";
                }
                string[] astrFiles = Directory.GetFiles(strDirT, strFileT);
                alsFiles.AddRange(astrFiles);
            }

            Console.WriteLine("Exporting text from {0} files", alsFiles.Count);

            // Attempt to process these level docs

            foreach (string strFile in alsFiles)
            {
                Console.Write("Writing text of " + strFile + "...");
                LevelDoc lvld = (LevelDoc)DocManager.OpenDocument(strFile);
                if (lvld == null)
                {
                    throw new Exception("Could not load level doc " + strFile);
                }
                string strTextFile = "." + Path.DirectorySeparatorChar + Path.GetFileName(strFile).Replace(".ld", ".txt");
                string str         = lvld.GetLevelText();
                str = str.Replace("\n", "\r\n");
                StreamWriter stmw = new StreamWriter(strTextFile);
                stmw.Write(str);
                stmw.Close();
                lvld.Dispose();
                Console.WriteLine(" done");
            }
        }
Exemple #22
0
 void LevelDoc_NameChanged(LevelDoc lvld)
 {
     SetTitle();
 }
Exemple #23
0
        static public void Error(LevelDoc lvld, object ob, string strFormat, params object[] aob)
        {
            string str = String.Format(strFormat, aob);

            s_frm.AddError(lvld, ob, str);
        }
Exemple #24
0
        public void AddError(LevelDoc lvld, object ob, string str)
        {
            int i = m_alLevelErrors.Add(new LevelError(lvld, ob));

            tbcOutput.AppendText(i.ToString() + "> " + str);
        }
Exemple #25
0
 public LevelError(LevelDoc lvld, object ob)
 {
     m_lvld = lvld;
     m_ob   = ob;
 }
Exemple #26
0
 public LevelView()
 {
     m_lvld = null;
 }
Exemple #27
0
        public static void ImportExpansionPdb(string strFile)
        {
            PdbPacker pdbp = new PdbPacker(strFile);

            ArrayList alsTileSets = new ArrayList();

            for (int i = 0; i < pdbp.Count; i++)
            {
                PdbPacker.File file = pdbp[i];
                if (!file.str.EndsWith(".lvl"))
                {
                    continue;
                }

                // Load up the pieces

                Ini     ini = Ini.LoadBinary(new MemoryStream(file.ab));
                string  strTileMapFilename = ini["General"]["TileMap"].Value;
                TileMap tmap = TileMap.Load(new MemoryStream(pdbp[strTileMapFilename].ab));


                // First, tell the active LevelDoc not to switch its templates based on the following
                // template load

                LevelDoc lvldActive = (LevelDoc)DocManager.GetActiveDocument(typeof(LevelDoc));
                if (lvldActive != null)
                {
                    lvldActive.SwitchTemplatesEnabled = false;
                }

                // If the TileSet for this level is not yet available, load it now

                TemplateDoc tmpd = (TemplateDoc)DocManager.OpenDocument(tmap.Filename.Replace(".tset", ".tc"));
                TileSet     tset = null;
                foreach (TileSet tsetT in alsTileSets)
                {
                    if (tsetT.FileName == tmap.Filename)
                    {
                        tset = tsetT;
                        break;
                    }
                }
                if (tset == null)
                {
                    tset = new TileSet(tmpd, tmap.Filename);
                    alsTileSets.Add(tset);
                }

                // Re-enable template switching

                if (lvldActive != null)
                {
                    lvldActive.SwitchTemplatesEnabled = true;
                }

                // Create a new level description, and deduce which templates are in it, with what visibility

                LevelDoc lvld = (LevelDoc)DocManager.NewDocument(typeof(LevelDoc), null);
                lvld.OutputFilename = file.str;
                ImportTileMap(tmap, tset, tmpd, lvld);

                // Walls are stored in the terrain map. Load them.
                string     strTrmapFilename = ini["General"]["TerrainMap"].Value;
                TerrainMap trmap            = TerrainMap.Load(new MemoryStream(pdbp[strTrmapFilename].ab));
                ImportWalls(trmap, lvld);

                // Load everything else
                lvld.LoadIni(ini);
            }
        }
		public static void Fixup(LevelDoc lvld) {
			foreach (CaTypeSwitch catSwitch in s_alsFixup) {
				catSwitch.m_sw = lvld.SwitchManager[catSwitch.m_strName];
				if (catSwitch.m_sw == null) {
					catSwitch.m_sw = new Switch(catSwitch.m_strName);
					lvld.SwitchManager.AddSwitch(catSwitch.m_sw);
					catSwitch.m_strName = null;
				}
			}
			s_alsFixup = null;			
		}
Exemple #29
0
        public override string ToSaveString()
        {
            LevelDoc lvld = (LevelDoc)DocManager.GetActiveDocument(typeof(LevelDoc));

            return(lvld.UnitGroupManager.Items.IndexOf(m_ug).ToString());
        }
Exemple #30
0
        public static string ImportExportMixMap(string strFile, LevelDoc lvld)
        {
            // Load ini
            Ini ini = new Ini(strFile);

            // Get name of level
            String strName = strFile;

            Ini.Section secBasic = ini["Basic"];
            if (secBasic != null)
            {
                Ini.Property propName = secBasic["Name"];
                if (propName != null)
                {
                    strName = propName.Value;
                }
                else
                {
                    Ini.Property propBrief = secBasic["Brief"];
                    if (propBrief != null)
                    {
                        strName = propBrief.Value;
                    }
                }
            }

            // Get theater
            Ini.Section secMap = ini["MAP"];
            if (secMap == null)
            {
                MessageBox.Show("Could not load " + strFile);
                return(null);
            }
            Theater theater;

            switch (secMap["Theater"].Value)
            {
            case "DESERT":
                theater = Theater.Desert;
                break;

            case "TEMPERATE":
                theater = Theater.Temperate;
                break;

            case "WINTER":
                theater = Theater.Winter;
                break;

            default:
                MessageBox.Show("Could not load " + strFile);
                return(null);
            }

            // Get bounds & invert
            int       xLeft    = Int32.Parse(secMap["X"].Value);
            int       yTop     = Int32.Parse(secMap["Y"].Value);
            int       cxWidth  = Int32.Parse(secMap["Width"].Value);
            int       cyHeight = Int32.Parse(secMap["Height"].Value);
            Rectangle rcBounds = new Rectangle(64 - (xLeft + cxWidth), yTop, cxWidth, cyHeight);

            // We're ready to go
            lvld.Title = strName;
            //fixme
            //lvld.TileCollectionFileName = theater.ToString() + ".tc";
            lvld.Bounds = rcBounds;

            // Load up
            MixTemplate[] amixt = MixSuck.LoadTemplates(theater);
            MixSuck.ImportTemplates(amixt, lvld.GetTemplateDoc());
            Stream stm = (Stream) new FileStream(strFile.ToLower().Replace(".ini", ".bin"), FileMode.Open, FileAccess.Read, FileShare.Read);
            MixMap map = MixSuck.LoadMap(stm, amixt);

            stm.Close();
            map.ImportMap(lvld);
            //fixme
            //lvld.SetBackgroundTemplate(lvld.GetTemplateDoc()FindTemplate(0));

            // Save

            string strFileLvld = strName + "_" + Path.GetFileName(strFile).Replace(".ini", ".ld");

            lvld.SaveAs(strFileLvld);

            // Also save a scaled image for reference
            TemplateDoc tmpd = lvld.GetTemplateDoc();
            Bitmap      bm   = lvld.GetMapBitmap(tmpd.TileSize, tmpd, true);
            int         cx;
            int         cy;

            if (bm.Width > bm.Height)
            {
                cx = 128;
                cy = bm.Height * 128 / bm.Width;
            }
            else
            {
                cx = bm.Width * 128 / bm.Height;
                cy = 128;
            }
            bm = (Bitmap)bm.GetThumbnailImage(cx, cy, null, IntPtr.Zero);
            bm.Save(strFileLvld.Replace(".ld", ".png"), ImageFormat.Png);
            bm.Dispose();

            // Save a full 24x24 original map image for reference
            map.SaveMapBitmap("cc_" + strFileLvld.Replace(".ld", ".png"));

            return(strFileLvld);
        }
Exemple #31
0
        public override string ToSaveString()
        {
            LevelDoc lvld = (LevelDoc)DocManager.GetActiveDocument(typeof(LevelDoc));

            return(lvld.CounterManager.Items.IndexOf(m_ctr).ToString());
        }