void btn_Click(object sender, EventArgs e) { ToolStripButton btn = sender as ToolStripButton; MapToolExtensionNode node = btn.Tag as MapToolExtensionNode; if (currentTool != null) { currentTool.SetInactive(); } currentTool = node.Tool; if (currentTool != null) { currentTool.SetActive(this, node.Tag); } }
void btn_Click(object sender, EventArgs e) { ToolStripButton btn = sender as ToolStripButton; MapToolExtensionNode node = btn.Tag as MapToolExtensionNode; if (currentTool != null) currentTool.SetInactive(); currentTool = node.Tool; if (currentTool != null) currentTool.SetActive(this, node.Tag); }
void Main_Load(object sender, EventArgs e) { Game.Initialize(); Game.SetRenderSystem("OpenTK"); String glyphPath = Game.PathTo("curses_640x300.png"); using (Stream imgstream = File.OpenRead(glyphPath)) { GlyphPalette pal = new GlyphPalette(imgstream, 16, 16); window = Game.RenderSystem.CreateWindow(SharplikeView.Size, pal, SharplikeView); } SharplikeView.Controls[0].MouseDown += new MouseEventHandler(SharplikeView_MouseDown); SharplikeView.Controls[0].MouseUp += new MouseEventHandler(SharplikeView_MouseUp); SharplikeView.Controls[0].MouseMove += new MouseEventHandler(SharplikeView_MouseMove); EntityList.ItemDrag += new ItemDragEventHandler(EntityList_ItemDrag); SharplikeView.Controls[0].AllowDrop = true; SharplikeView.Controls[0].DragDrop += new DragEventHandler(Main_DragDrop); SharplikeView.Controls[0].DragOver += new DragEventHandler(Main_DragOver); SharplikeView.Controls[0].DragEnter += new DragEventHandler(Main_DragEnter); SharplikeView.Controls[0].DragLeave += new EventHandler(Main_DragLeave); //Game.SetInputSystem("OpenTK"); window.Clear(); ReplaceMap(new MapStack(window.Size, 20, 15, "EditorMap", null)); Map.ViewFrom(new Vector3(0, 0, 0), true); Bitmap glyphs = Game.RenderSystem.Window.GlyphPalette.SourceBitmap; ImageList il = new ImageList(); Size glyphSize = Game.RenderSystem.Window.GlyphPalette.GlyphDimensions; for (int y = 0; y < Game.RenderSystem.Window.GlyphPalette.RowCount; ++y) { for (int x = 0; x < Game.RenderSystem.Window.GlyphPalette.ColumnCount; ++x) { Rectangle area = new Rectangle(x * glyphSize.Width, y * glyphSize.Height, glyphSize.Width, glyphSize.Height); Bitmap b = new Bitmap(glyphSize.Width, glyphSize.Height, glyphs.PixelFormat); using (Graphics bg = Graphics.FromImage(b)) { bg.Clear(Color.Black); bg.DrawImageUnscaled(glyphs.Clone(area, glyphs.PixelFormat), new Point(0, 0)); } il.Images.Add(b); } } EntityList.LargeImageList = il; EntityList.SmallImageList = il; SquareList.LargeImageList = il; SquareList.SmallImageList = il; foreach (EditorExtensionNode node in AddinManager.GetExtensionNodes("/Sharplike/Entities")) { ListViewItem i = new ListViewItem(); i.Text = node.Id; i.ToolTipText = node.TooltipText; i.Tag = node; i.ImageIndex = node.GlyphID; EntityList.Items.Add(i); } foreach (EditorExtensionNode node in AddinManager.GetExtensionNodes("/Sharplike/Squares")) { ListViewItem i = new ListViewItem(); i.Text = node.Id; i.ToolTipText = node.TooltipText; i.Tag = node; i.ImageIndex = node.GlyphID; SquareList.Items.Add(i); } foreach (ToolGroupExtensionNode node in AddinManager.GetExtensionNodes("/Sharplike/Editlike/Tools")) { foreach (ExtensionNode mapnode in node.ChildNodes) { if (mapnode.GetType() == typeof(MapToolExtensionNode)) { ToolStripButton btn = new ToolStripButton(); BuildButton(mapnode as MapToolExtensionNode, btn); EditorTools.Items.Add(btn); } else { ToolStripDropDownButton ddbtn = new ToolStripDropDownButton(); ddbtn.DropDown.Width = 200; foreach (MapToolExtensionNode mnode in mapnode.ChildNodes) { ToolStripButton btn = new ToolStripButton(); BuildButton(mnode, btn); if (btn.DisplayStyle == ToolStripItemDisplayStyle.Image) { btn.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText; } Image i = mnode.Icon; btn.Click += delegate(object send, EventArgs ea) { ddbtn.Image = i; ddbtn.Tag = btn; }; ddbtn.DropDownItems.Add(btn); if (ddbtn.Tag == null) { ddbtn.Tag = btn; ddbtn.Image = mnode.Icon; } } ddbtn.Click += delegate(object send, EventArgs ea) { btn_Click(ddbtn.Tag, ea); }; EditorTools.Items.Add(ddbtn); } } EditorTools.Items.Add(new ToolStripSeparator()); } viewTool = new ViewportTool(); viewTool.SetActive(this, ""); Game.Run(); }
void Main_Load(object sender, EventArgs e) { Game.Initialize(); Game.SetRenderSystem("OpenTK"); String glyphPath = Game.PathTo("curses_640x300.png"); using (Stream imgstream = File.OpenRead(glyphPath)) { GlyphPalette pal = new GlyphPalette(imgstream, 16, 16); window = Game.RenderSystem.CreateWindow(SharplikeView.Size, pal, SharplikeView); } SharplikeView.Controls[0].MouseDown += new MouseEventHandler(SharplikeView_MouseDown); SharplikeView.Controls[0].MouseUp += new MouseEventHandler(SharplikeView_MouseUp); SharplikeView.Controls[0].MouseMove += new MouseEventHandler(SharplikeView_MouseMove); EntityList.ItemDrag += new ItemDragEventHandler(EntityList_ItemDrag); SharplikeView.Controls[0].AllowDrop = true; SharplikeView.Controls[0].DragDrop += new DragEventHandler(Main_DragDrop); SharplikeView.Controls[0].DragOver += new DragEventHandler(Main_DragOver); SharplikeView.Controls[0].DragEnter += new DragEventHandler(Main_DragEnter); SharplikeView.Controls[0].DragLeave += new EventHandler(Main_DragLeave); //Game.SetInputSystem("OpenTK"); window.Clear(); ReplaceMap(new MapStack(window.Size, 20, 15, "EditorMap")); Map.ViewFrom(new Vector3(0, 0, 0), true); Bitmap glyphs = Game.RenderSystem.Window.GlyphPalette.SourceBitmap; ImageList il = new ImageList(); Size glyphSize = Game.RenderSystem.Window.GlyphPalette.GlyphDimensions; for (int y = 0; y < Game.RenderSystem.Window.GlyphPalette.RowCount; ++y) { for (int x = 0; x < Game.RenderSystem.Window.GlyphPalette.ColumnCount; ++x) { Rectangle area = new Rectangle(x * glyphSize.Width, y * glyphSize.Height, glyphSize.Width, glyphSize.Height); Bitmap b = new Bitmap(glyphSize.Width, glyphSize.Height, glyphs.PixelFormat); using (Graphics bg = Graphics.FromImage(b)) { bg.Clear(Color.Black); bg.DrawImageUnscaled(glyphs.Clone(area, glyphs.PixelFormat), new Point(0, 0)); } il.Images.Add(b); } } EntityList.LargeImageList = il; EntityList.SmallImageList = il; SquareList.LargeImageList = il; SquareList.SmallImageList = il; foreach (EditorExtensionNode node in AddinManager.GetExtensionNodes("/Sharplike/Entities")) { ListViewItem i = new ListViewItem(); i.Text = node.Id; i.ToolTipText = node.TooltipText; i.Tag = node; i.ImageIndex = node.GlyphID; EntityList.Items.Add(i); } foreach (EditorExtensionNode node in AddinManager.GetExtensionNodes("/Sharplike/Squares")) { ListViewItem i = new ListViewItem(); i.Text = node.Id; i.ToolTipText = node.TooltipText; i.Tag = node; i.ImageIndex = node.GlyphID; SquareList.Items.Add(i); } foreach (ToolGroupExtensionNode node in AddinManager.GetExtensionNodes("/Sharplike/Editlike/Tools")) { foreach (ExtensionNode mapnode in node.ChildNodes) { if (mapnode.GetType() == typeof(MapToolExtensionNode)) { ToolStripButton btn = new ToolStripButton(); BuildButton(mapnode as MapToolExtensionNode, btn); EditorTools.Items.Add(btn); } else { ToolStripDropDownButton ddbtn = new ToolStripDropDownButton(); ddbtn.DropDown.Width = 200; foreach (MapToolExtensionNode mnode in mapnode.ChildNodes) { ToolStripButton btn = new ToolStripButton(); BuildButton(mnode, btn); if (btn.DisplayStyle == ToolStripItemDisplayStyle.Image) btn.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText; Image i = mnode.Icon; btn.Click += delegate(object send, EventArgs ea) { ddbtn.Image = i; ddbtn.Tag = btn; }; ddbtn.DropDownItems.Add(btn); if (ddbtn.Tag == null) { ddbtn.Tag = btn; ddbtn.Image = mnode.Icon; } } ddbtn.Click += delegate(object send, EventArgs ea) { btn_Click(ddbtn.Tag, ea); }; EditorTools.Items.Add(ddbtn); } } EditorTools.Items.Add(new ToolStripSeparator()); } viewTool = new ViewportTool(); viewTool.SetActive(this, ""); Game.Run(); }