Ejemplo n.º 1
0
 public override AbstractWindow CreateWindow(Size displayDimensions, GlyphPalette palette, Object context)
 {
     if (win == null)
     {
         win = new TKWindow(displayDimensions, palette, context as Control);
     }
     return(win);
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Creates a new Window, or returns the existing one (ignoring input parameters if one already exists).
 /// </summary>
 /// <param name="displayDimensions">Size of the window.</param>
 /// <param name="palette">Glyph settings to use.</param>
 /// <param name="context">Control requesting window?</param>
 /// <returns>A new window the first time it is called, or the existing window on subsequent calls.</returns>
 public override AbstractWindow CreateWindow(Size displayDimensions, GlyphPalette palette, Object context)
 {
     if (_window == null)
     {
         _window = new TKWindow(displayDimensions, palette, context as Control);
         _window.FocusWindow();
     }
     return(_window);
 }
Ejemplo n.º 3
0
        public TKWindow(Size displayDimensions, GlyphPalette palette, Control context)
            : base(displayDimensions, palette)
        {
            if (context == null)
            {
                form              = new TKForm();
                form.ClientSize   = displayDimensions;
                form.FormClosing += new FormClosingEventHandler(Form_FormClosing);
                form.Show();

                context = form;
            }

            context.SuspendLayout();
            Control.Dock      = DockStyle.Fill;
            Control.BackColor = Color.Blue;
            Control.VSync     = false;
            Control.Resize   += new EventHandler(Control_Resize);
            Control.Paint    += new PaintEventHandler(Control_Paint);

            Control.Location = new Point(0, 0);
            Control.Size     = context.ClientSize;

            context.Controls.Add(Control);
            context.ResumeLayout(false);

            paletteId = GL.GenTexture();
            Bitmap bmp = palette.SourceBitmap;

            GL.BindTexture(TextureTarget.Texture2D, paletteId);
            BitmapData bmp_data = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, bmp_data.Width, bmp_data.Height, 0,
                          OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, bmp_data.Scan0);

            bmp.UnlockBits(bmp_data);

            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);

            base.Resize    += new EmptyDelegate(TKWindow_Resize);
            this.WindowSize = Control.Size;

            GL.ClearColor(0.1f, 0.2f, 0.5f, 0.0f);
            GL.Disable(EnableCap.DepthTest);
            GL.Disable(EnableCap.CullFace);
            GL.Enable(EnableCap.Texture2D);

            GL.BindTexture(TextureTarget.Texture2D, paletteId);
            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
        }
Ejemplo n.º 4
0
        static void Main(String[] args)
        {
            AbstractWindow gameWindow;

            Game.Initialize();                  // creates a game object pathed to the
            // executable root

            using (Stream imgStream = File.OpenRead(Game.PathTo("curses_640x300.png")))
            {
                // create the glyph palette; specifies how many rows/cols there are
                GlyphPalette glyphPalette = new GlyphPalette(imgStream, 16, 16);

                // the size, in pixels, of the game window
                Size WindowDimensions = new Size(glyphPalette.GlyphDimensions.Width * WindowSize.Width,
                                                 glyphPalette.GlyphDimensions.Height * WindowSize.Height);
#if !DEBUG
                try
                {
#endif
                Game.SetRenderSystem("OpenTK");                         // no other render systems exist
                gameWindow = Game.RenderSystem.CreateWindow(WindowDimensions, glyphPalette);
                Game.SetInputSystem("OpenTK");
                // Game.SetAudioSystem("OpenTK"); // audio still has trouble starting
#if !DEBUG
            }
            catch (NullReferenceException e)
            {
                Console.WriteLine("Exception in startup: " + e.ToString());
                Console.ReadLine();
                return;
            }
#endif
            }

            // load the INI file with proper game configuration...
            Game.InputSystem.LoadConfiguration(Game.PathTo("commands.ini"));

            gameWindow.Clear();

            // Creates the core game state machine, and gives it the MainMenuState as a start state.
            // When we invoke the state machine, that will be the first state that pops up. The state
            // machine is one of Sharplike's most powerful concepts, and will save you a boatload of
            // time during development.
            StateMachine gameState = new StateMachine(new State.MainMenuState());

            StepwiseGameLoop gameLoop = new StepwiseGameLoop(gameState);
            Game.Run(gameLoop);             // and off we go!
        }
Ejemplo n.º 5
0
        static void Main()
        {
            Game.Initialize();

            AbstractWindow gwin;
            Assembly       ea = Assembly.GetExecutingAssembly();


            using (Stream imgstream = ea.GetManifestResourceStream("Sharplike.Tests.TKTest.curses_640x300.png"))
            {
                GlyphPalette pal = new GlyphPalette(imgstream, 16, 16);

                Int32 width  = 80 * pal.GlyphDimensions.Width;
                Int32 height = 25 * pal.GlyphDimensions.Height;

                try
                {
                    //game.SetAudioSystem("OpenTK");
                    Game.SetRenderSystem("OpenTK");
                    gwin = Game.RenderSystem.CreateWindow(new Size(width, height), pal);
                    Game.SetInputSystem("OpenTK");
                }
                catch (System.NullReferenceException e)
                {
                    Console.WriteLine("Error when loading plugin: " + e.Message + "\n" + e.Source);
                    return;
                }
            }

            //Game.Scripting.Run(Game.PathTo("Test.py"));
            //game.Scripting.Run(game.PathTo("Test.rb"));

            Game.InputSystem.LoadConfiguration(Game.PathTo("commands.ini"));
            Game.InputSystem.SaveConfiguration(Game.PathTo("commands.out.ini"));


            gwin.Clear();

            //ac.Play();
            Game.GameProcessing += new EventHandler <EventArgs>(game_GameProcessing);
            Game.InputSystem.Command.CommandTriggered += new EventHandler <CommandEventArgs>(Command_CommandTriggered);
            StepwiseGameLoop loop = new StepwiseGameLoop(RunGame);

            Game.Run(loop);

            Game.Terminate();
        }
Ejemplo n.º 6
0
        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();
        }
Ejemplo n.º 7
0
        static void Main()
        {
            Game.Initialize(".");

            AbstractWindow gwin;

            String glyphPath = Game.PathTo("curses_640x300.png");

            using (Stream imgstream = File.OpenRead(glyphPath))
            {
                GlyphPalette pal = new GlyphPalette(imgstream, 16, 16);

                Int32 width  = 80 * pal.GlyphDimensions.Width;
                Int32 height = 25 * pal.GlyphDimensions.Height;

                try
                {
                    Game.SetRenderSystem("OpenTK");
                    gwin = Game.RenderSystem.CreateWindow(new Size(width, height), pal);

                    Game.SetInputSystem("OpenTK");
                }
                catch (System.NullReferenceException e)
                {
                    Console.WriteLine("Error when loading plugin: " + e.Message + "\n" + e.Source);
                    return;
                }
            }

            Game.InputSystem.LoadConfiguration(Game.PathTo("commands.ini"));

            gwin.Clear();

            map = new MapStack(Game.RenderSystem.Window.WindowSize, 20, 15, "SandboxMap");
            map.AddPage(new YellowWallPage(map.PageSize), new Vector3(0, 0, 0));
            map.AddPage(new YellowWallPage(map.PageSize), new Vector3(1, 0, 0));
            map.AddPage(new YellowWallPage(map.PageSize), new Vector3(0, 1, 0));
            map.AddPage(new YellowWallPage(map.PageSize), new Vector3(1, 1, 0));
            map.AddPage(new YellowWallPage(map.PageSize), new Vector3(-1, 0, 0));
            map.AddPage(new YellowWallPage(map.PageSize), new Vector3(1, 1, 1));
            map.AddPage(new YellowWallPage(map.PageSize), new Vector3(-1, 0, 1));

            cache = new ZColdCachingAlgorithm(map);

            ent          = new WanderingEntity();
            ent.Location = new Vector3(2, 2, 0);
            ent.Map      = map;


            gwin.AddRegion(map);

            Sharplike.UI.Controls.Label l = new UI.Controls.Label(new Size(50, 1), new Point(0, 0));
            l.Text = "Label on the map.";
            map.AddRegion(l);

            Sharplike.UI.Controls.Window win = new UI.Controls.Window(new Size(20, 10), new Point(5, 5));
            win.Title           = "Dialog Window";
            win.BackgroundColor = Color.FromArgb(100, 0, 0, 200);
            map.AddRegion(win);

            Game.OnGameInitialization += new EventHandler <EventArgs>(game_OnGameInitialization);
            Game.GameProcessing       += new EventHandler <EventArgs>(game_GameProcessing);
            StepwiseGameLoop loop = new StepwiseGameLoop(RunGame);

            Game.Run(loop);

            Game.Terminate();
        }