private void menuItemScaleDown_Click(object sender, System.EventArgs e) { // If no template doc active, bail if (m_tmpdActive == null) { return; } // Make sure 24 x 24 (could actually allow any sort of conversion...) if (m_tmpdActive.TileSize.Width != 24 && m_tmpdActive.TileSize.Height != 24) { MessageBox.Show(DocManager.GetFrameParent(), "The current template collection must be 24 x 24 tile size"); return; } // Get busy TemplateDoc tmpdDst = TemplateTools.CloneTemplateDoc(m_tmpdActive); TemplateTools.ScaleTemplates(tmpdDst, new Size(16, 16)); TemplateTools.QuantizeTemplates(tmpdDst, null, 0, 0, 0); DocManager.SetActiveDocument(typeof(TemplateDoc), tmpdDst); }
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(); } }
public LevelViewParent() { // This call is required by the Windows.Forms Form Designer. InitializeComponent(); // Default panelShowToolbar.Hide(); panelToolbar.Show(); // Easier than creating a resource file? System.Reflection.Assembly ass = typeof(LevelViewParent).Module.Assembly; Stream stm = ass.GetManifestResourceStream("m.toolstrip.bmp"); imageList1.Images.AddStrip(new Bitmap(stm)); TemplateDocTemplate doct = (TemplateDocTemplate)DocManager.FindDocTemplate(typeof(TemplateDoc)); doct.DocAdded += new DocTemplate.DocAddedHandler(TemplateDocTemplate_DocAdded); doct.DocRemoved += new DocTemplate.DocRemovedHandler(TemplateDocTemplate_DocRemoved); // Combo index 0 FillCombo(); comboDocs.SelectedIndex = 0; UpdateZoomSelection(); view.ScaleChanged += new EventHandler(View_ScaleChanged); }
public static void MakePalette(string[] astr) { // -makepal 16 templates.tc palsize fixpalsize backgroundpalsize fixed.pal out.pal // tile size Size sizTile = new Size(0, 0); sizTile.Width = int.Parse(astr[1]); sizTile.Height = sizTile.Width; // Load template collection TemplateDoc tmpd = (TemplateDoc)DocManager.OpenDocument(astr[2]); // palette size int cPalEntries = int.Parse(astr[3]); // entries fixed int cPalEntriesFixed = int.Parse(astr[4]); // entries for background int cPalEntriesBackground = int.Parse(astr[5]); // fixed palette Palette palFixed = new Palette(astr[6]); // output palette string strFilePalOut = astr[7]; // If this template collection already has a palette it has already been quantized; we don't // want that. if (tmpd.GetPalette() != null) { new Exception("Template collection has already been quantized!"); } // Scale templates if needed if (sizTile.Width != tmpd.TileSize.Width || sizTile.Height != tmpd.TileSize.Height) { TemplateTools.ScaleTemplates(tmpd, sizTile); } // Quantize TemplateTools.QuantizeTemplates(tmpd, palFixed, cPalEntries, cPalEntriesFixed, cPalEntriesBackground); // Save the new palette out Palette palNew = tmpd.GetPalette(); palNew.SaveJasc(strFilePalOut); }
private void buttonModify_Click(object sender, System.EventArgs e) { string str = (string)listBox1.SelectedItem; if (str == null) { return; } SwitchManager swm = ((LevelDoc)DocManager.GetActiveDocument(typeof(LevelDoc))).SwitchManager; Switch sw = swm[str]; string strNew = EditStringForm.DoModal("Modify Switch", "New switch name:", str); if (strNew == null) { return; } if (strNew != str) { sw.Name = strNew; listBox1.Items.Remove(str); int i = listBox1.Items.Add(strNew); listBox1.SelectedIndex = i; // UNDONE: doc is modified } }
private void comboDocs_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e) { if (e.Index < 0 || e.Index >= comboDocs.Items.Count) { return; } string strName; if (e.Index == 0) { Document docActive = DocManager.GetActiveDocument(typeof(TemplateDoc)); if (docActive == null) { strName = "None"; } else { strName = "Active (" + docActive.GetName() + ")"; } m_tmpdCurrent = null; } else { Document doc = (Document)comboDocs.Items[e.Index]; m_tmpdCurrent = (TemplateDoc)doc; strName = doc.GetName(); } e.DrawBackground(); e.Graphics.DrawString(strName, e.Font, new SolidBrush(e.ForeColor), e.Bounds.X, e.Bounds.Y); e.DrawFocusRectangle(); }
public Tile(SerializationInfo info, StreamingContext ctx) : base(info, ctx) { m_strName = null; try { m_strName = info.GetString("Name"); } catch { m_strName = info.GetInt32("Cookie").ToString(); } m_afVisible = (bool[, ])info.GetValue("Visibility", typeof(bool[, ])); try { m_afOccupancy = (bool[, ])info.GetValue("Occupancy", typeof(bool[, ])); } catch { TemplateDoc tmpd = (TemplateDoc)DocManager.GetActiveDocument(typeof(TemplateDoc)); Template tmpl = tmpd.FindTemplate(m_strName); if (tmpl != null) { m_afOccupancy = tmpl.OccupancyMap; } else { m_afOccupancy = new bool[1, 1]; } } InitCommon(); }
Document OpenFinish(Document doc) { // This doc is being opened doc.IncrementOpenCount(); // Doc is not modified doc.SetModified(false); // Make it active SetActiveDocument(doc); // Create a frame window of the desired type. It might already know what // view type to create, but parameterize it just in case if (m_typeFrame != null) { Object[] aobjT = { DocManager.GetFrameParent(), doc, m_typeView }; System.Activator.CreateInstance(m_typeFrame, aobjT); } // The doc is ready to go doc.InitDone(); return(doc); }
Size AskTileSize() { TileSizeForm form = new TileSizeForm(); form.ShowDialog(DocManager.GetFrameParent()); return(form.GetTileSize()); }
protected unsafe override void WndProc(ref Message m) { switch (m.Msg) { // #define WM_WINDOWPOSCHANGED 0x0047 // #define SWP_NOZORDER 0x0004 case 0x47: WINDOWPOS *ppos = (WINDOWPOS *)m.LParam; if (ppos == null || (ppos->flags & 4) == 0) { DocManager.SetActiveDocument(typeof(LevelDoc), m_doc); DocManager.SetCommandTarget(this); } break; // #define WM_NCACTIVATE 0x0086 case 0x86: if (((ushort)m.WParam) != 0) { DocManager.SetCommandTarget(this); } break; } base.WndProc(ref m); }
public Counter GetSelectedCounter() { if (listBox1.SelectedIndex == -1) { return(null); } CounterManager ctrm = ((LevelDoc)DocManager.GetActiveDocument(typeof(LevelDoc))).CounterManager; return(ctrm[(string)listBox1.SelectedItem]); }
public Switch GetSelectedSwitch() { if (listBox1.SelectedIndex == -1) { return(null); } SwitchManager swm = ((LevelDoc)DocManager.GetActiveDocument(typeof(LevelDoc))).SwitchManager; return(swm[(string)listBox1.SelectedItem]); }
static public void ShowIt() { if (s_frm == null) { s_frm = new OutputForm(); s_frm.Owner = DocManager.GetFrameParent(); } s_frm.Show(); s_frm.BringToFront(); }
private void menuItemQuantizeOnly_Click(object sender, System.EventArgs e) { if (m_tmpdActive == null) { return; } TemplateDoc tmpdDst = TemplateTools.CloneTemplateDoc(m_tmpdActive); TemplateTools.QuantizeTemplates(tmpdDst, null, 0, 0, 0); DocManager.SetActiveDocument(typeof(TemplateDoc), tmpdDst); }
void FillCombo() { comboDocs.Items.Clear(); TemplateDocTemplate doct = (TemplateDocTemplate)DocManager.FindDocTemplate(typeof(TemplateDoc)); Document[] adoc = doct.GetDocuments(); comboDocs.Items.Add(""); foreach (Document doc in adoc) { comboDocs.Items.Add(doc); } }
public LevelFrame(Form frmParent, Document doc, Type typeView) { InitializeComponent(); LevelDocTemplate doct = (LevelDocTemplate)DocManager.FindDocTemplate(typeof(LevelDoc)); doct.DocActive += new LevelDocTemplate.DocActiveHandler(LevelDocTemplate_DocActive); m_doc = doc; doc.PathChanged += new Document.PathChangedHandler(Document_PathChanged); doc.ModifiedChanged += new Document.ModifiedChangedHandler(Document_ModifiedChanged); doc.OpenCountChanged += new Document.OpenCountChangedHandler(Document_OpenCountChanged); ((LevelDoc)doc).NameChanged += new LevelDoc.NameChangedHandler(LevelDoc_NameChanged); // Parent this and create panes MdiParent = frmParent; ChangePanes(2); // See if the top most mdi frame is maximized. If so, maximize this too // If no window around, maximize bool fMaximize = true; if (frmParent.ActiveMdiChild != null) { if (frmParent.ActiveMdiChild.WindowState != FormWindowState.Maximized) { fMaximize = false; } } if (fMaximize) { WindowState = FormWindowState.Maximized; } // Set Title s_alsFrames.Add(this); SetTitle(); // If this doc is active, this is the new command target if (m_doc == DocManager.GetActiveDocument(typeof(LevelDoc))) { DocManager.SetCommandTarget(this); } // Show Show(); }
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(); } }
private void menuItemSavePalette_Click(object sender, System.EventArgs e) { if (m_tmpdActive == null) { return; } Palette pal = m_tmpdActive.GetPalette(); if (pal == null) { MessageBox.Show(DocManager.GetFrameParent(), "No palette on this template collection. You need to create one!"); return; } pal.SaveDialog(); }
private void buttonDelete_Click(object sender, System.EventArgs e) { string str = (string)listBox1.SelectedItem; if (str == null) { return; } SwitchManager swm = ((LevelDoc)DocManager.GetActiveDocument(typeof(LevelDoc))).SwitchManager; Switch sw = swm[str]; swm.RemoveSwitch(sw); listBox1.Items.Remove(str); // UNDONE: doc is modified }
private void buttonDelete_Click(object sender, System.EventArgs e) { string str = (string)listBox1.SelectedItem; if (str == null) { return; } CounterManager ctrm = ((LevelDoc)DocManager.GetActiveDocument(typeof(LevelDoc))).CounterManager; Counter ctr = ctrm[str]; ctrm.RemoveCounter(ctr); listBox1.Items.Remove(str); // UNDONE: doc is modified }
private void buttonNew_Click(object sender, System.EventArgs e) { string str = EditStringForm.DoModal("New Counter", "New Counter name:", null); if (str != null) { CounterManager ctrm = ((LevelDoc)DocManager.GetActiveDocument(typeof(LevelDoc))).CounterManager; if (ctrm[str] == null) { ctrm.AddCounter(new Counter(str)); int i = listBox1.Items.Add(str); listBox1.SelectedIndex = i; // UNDONE: doc is modified } } }
private void buttonNew_Click(object sender, System.EventArgs e) { string str = EditStringForm.DoModal("New Switch", "New switch name:", null); if (str != null) { SwitchManager swm = ((LevelDoc)DocManager.GetActiveDocument(typeof(LevelDoc))).SwitchManager; if (swm[str] == null) { swm.AddSwitch(new Switch(str)); int i = listBox1.Items.Add(str); listBox1.SelectedIndex = i; // UNDONE: doc is modified } } }
public static void Main(string[] astr) { new Globals(); new DocManager(); DocManager.AddTemplate(new LevelDocTemplate(null, null)); DocManager.AddTemplate(new TemplateDocTemplate()); switch (astr[0]) { case "-mixmaps": OutputTools.ExportMixMaps(astr); break; case "-levels": OutputTools.ExportLevels(astr, 0); break; case "-images": OutputTools.ExportImages(astr); break; case "-makepal": OutputTools.MakePalette(astr); break; case "-special": char sep = Path.DirectorySeparatorChar; string root = sep + "ht" + sep + "data" + sep; OutputTools.MixMapImportSpecial(Theater.Desert, (TemplateDoc)DocManager.OpenDocument(root + "desert.tc"), root + "desert24.tc"); OutputTools.MixMapImportSpecial(Theater.Temperate, (TemplateDoc)DocManager.OpenDocument(root + "temperate.tc"), root + "temperate24.tc"); break; case "-exporttext": OutputTools.ExportText(astr); break; case "-importtext": OutputTools.ImportText(astr); break; case "-testimport": OutputTools.ImportExportPdbs(astr); break; } }
public static void ImportExportPdbs(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); foreach (string filename in astrFiles) { if (filename.EndsWith(".pdb")) { alsFiles.Add(filename); } } } // Import, then save each pdb foreach (string filename in alsFiles) { try { if (File.Exists(filename + "_new")) { Console.WriteLine("Exists: " + filename + "_new"); continue; } ImportExpansionPdb(filename); LevelDocTemplate doctLevel = (LevelDocTemplate)DocManager.FindDocTemplate(typeof(LevelDoc)); Document[] adoc = doctLevel.GetDocuments(); SaveExpansionPdb(filename + "_new", adoc, "1.1"); foreach (Document doc in adoc) { doc.SetModified(false); } doctLevel.CloseAllDocuments(); } catch { Console.WriteLine("Error loading " + filename + ", skipping"); } } }
private void buttonOK_Click(object sender, System.EventArgs e) { // If custom, validate if (radioButtonCustom.Checked) { int cx = int.Parse(textBoxWidth.Text); int cy = int.Parse(textBoxHeight.Text); if (cx <= 0 || cx > 64 || cy <= 0 || cy > 64) { MessageBox.Show(DocManager.GetFrameParent(), "Invalid custom tile size. Try again."); return; } m_sizTile = new Size(cx, cy); } DialogResult = DialogResult.OK; }
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); }
public TemplatePanel() { // This call is required by the Windows.Forms Form Designer. InitializeComponent(); if (Globals.IsKit()) { Controls.Remove(toolBar); toolBar.Visible = false; } // Easier than creating a resource file? System.Reflection.Assembly ass = typeof(TemplatePanel).Module.Assembly; Stream stm = ass.GetManifestResourceStream("m.toolstrip.bmp"); imageList1.Images.AddStrip(new Bitmap(stm)); // We want to know about changes to template docs TemplateDocTemplate doctTemplate = (TemplateDocTemplate)DocManager.FindDocTemplate(typeof(TemplateDoc)); if (doctTemplate != null) { doctTemplate.DocActive += new TemplateDocTemplate.DocActiveHandler(TemplateDocTemplate_DocActive); doctTemplate.DocAdded += new TemplateDocTemplate.DocAddedHandler(TemplateDocTemplate_DocAdded); doctTemplate.DocRemoved += new TemplateDocTemplate.DocRemovedHandler(TemplateDocTemplate_DocRemoved); doctTemplate.TemplatesAdded += new TemplateDocTemplate.TemplatesAddedHandler(TemplateDocTemplate_TemplatesAdded); doctTemplate.TemplatesRemoved += new TemplateDocTemplate.TemplatesRemovedHandler(TemplateDocTemplate_TemplatesRemoved); doctTemplate.TemplateChanged += new TemplateDocTemplate.TemplateChangedHandler(TemplateDocTemplate_TemplateChanged); } // We want to know when the active level doc changes LevelDocTemplate doctLevel = (LevelDocTemplate)DocManager.FindDocTemplate(typeof(LevelDoc)); if (doctLevel != null) { doctLevel.DocActive += new TemplateDocTemplate.DocActiveHandler(LevelDocTemplate_DocActive); } }
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"); } }
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; } }
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); }