Пример #1
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            try {
                spriteBatch = new SpriteBatch(GraphicsDevice);
                TQMG.Init(graphics, GraphicsDevice, spriteBatch, JCR);
                MousePointer = TQMG.GetImage("Mouse.png"); Assert(MousePointer, JCR6.JERROR);
                Font         = TQMG.GetFont("DosFont.JFBF"); Assert(Font, JCR6.JERROR);
                Back         = TQMG.GetImage("Back.png");
                VoidBack     = TQMG.GetImage("Void.png");
                Stage.GoTo(new Editor());
                foreach (string prj in Config.GetL("Projects"))
                {
                    if (System.IO.Directory.Exists(prj))
                    {
                        Project.ProjMap[prj] = new Project(prj);
                    }
                    else
                    {
                        Confirm.Annoy($"Project directory \"{prj}\" has not been found!");
                    }
                }
                new LexNIL();
            } catch (Exception QuelleCatastrophe) {
#if DEBUG
                FatalError($"Exception Thrown:\n{QuelleCatastrophe.Message}\n\n{QuelleCatastrophe.StackTrace}");
#else
                FatalError($"Exception Thrown:\n{QuelleCatastrophe.Message}");
#endif
            }

            // TODO: use this.Content to load your game content here
        }
Пример #2
0
        public string Load(string file, string assign = "")
        {
            try {
                var tag = assign;
                var at  = 0;
                if (tag == "")
                {
                    do
                    {
                        at++; tag = $"IMAGE:{at}";
                    } while (Images.ContainsKey(tag));
                }
                if (qstr.Suffixed(file.ToLower(), ".jpbf"))
                {
                    Images[tag] = TQMG.GetBundle(file);
                }
                else
                {
                    Images[tag] = TQMG.GetImage(file);
                }
                if (Images[tag] == null)
                {
                    throw new Exception($"Filed loading {file} at {tag}\n{UseJCR6.JCR6.JERROR}");
                }
                return(tag);
            } catch (Exception Catastrophe) {
#if DEBUG
                SBubble.MyError($"Bubble.Graphics.Images.Load(\"{file}\",\"{assign}\")", Catastrophe.Message, $"{SBubble.TraceLua(vm)}\n\n.NET Traceback:\n{Catastrophe.StackTrace}");
#else
                SBubble.MyError($"Bubble.Graphics.Images.Load(\"{file}\",\"{assign}\")", Catastrophe.Message, $"{SBubble.TraceLua(vm)}");
#endif
                return("Il ya une catastrophe");
            }
        }
Пример #3
0
        static public void DrawText(string text, int x, int y)
        {
            var dx = x;
            var dy = y;

            for (int i = 0; i < text.Length; i++)
            {
                var b = (byte)text[i];
                if (b == 32)
                {
                    dx += fw;
                }
                else if (b == 10)
                {
                    dx  = x;
                    dy += fh;
                }
                else if (b > 32 && b < 127)
                {
                    if (!CharPics.ContainsKey(b))
                    {
                        var q = QuickStream.OpenEmbedded($"SysFont.{b}.png");
                        if (q != null)
                        {
                            CharPics[b] = TQMG.GetImage(q);
                            Debug.WriteLine($"Loaded character {b} => {text[i]}");
                        }
                    }
                    if (CharPics.ContainsKey(b))   // NO ELSE! That won't cause the desired effect
                    {
                        try {
                            var cp = CharPics[b];
                            cp.Draw(dx, dy);
                            if (fw < cp.Width)
                            {
                                fw = cp.Width;
                            }
                            if (fh < cp.Height)
                            {
                                fh = cp.Height;
                            }
                            dx += fw;
                            if (dx + fw > TQMG.ScrWidth)
                            {
                                dx  = x;
                                dy += fh;
                            }
                        } catch (Exception E) {
                            Debug.Print($"Caught: {E.Message}");
                        }
                    }
                }
            }
        }
Пример #4
0
 /// <summary>
 /// Allows the game to run logic such as updating the world,
 /// checking for collisions, gathering input, and playing audio.
 /// </summary>
 /// <param name="gameTime">Provides a snapshot of timing values.</param>
 protected override void Update(GameTime gameTime)
 {
     //if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
     if (FilesIDX >= FilesCNT)
     {
         JCRC.Close();
         Exit();
     }
     else
     {
         Original = TQMG.GetImage(Files[FilesIDX].Entry);
         Neg();
         Negative.Save(JCRC, $"{qstr.StripExt(Files[FilesIDX].Entry)}.Negative.png", "lzma", Files[FilesIDX].Author, Files[FilesIDX].Notes);
         FilesIDX++;
     }
     base.Update(gameTime);
 }
Пример #5
0
        static public void GoError(string ct, string message, string trace)
        {
            blocked = true;
            BubConsole.WriteLine($"ERROR>{message}", 255, 0, 0);
            Debug.WriteLine($"{ct}: {message}\nTraceback:\n{trace}\n\n");
            if (crashed)
            {
                return;
            }
            crashed = true;
            var s = QuickStream.OpenEmbedded("Death.png");

            if (s == null)
            {
                Debug.WriteLine("ERROR! Trying to read Death resulted into null!");
            }
            s.Position = 0;
            Death      = TQMG.GetImage(s);
            sct        = ct;
            smsg       = message;
            strace     = trace;
            FlowManager.GoHardFlow(new Error(), true);
        }
Пример #6
0
        static BubConsole()
        {
            if (AllowWriteLog)
            {
                try {
                    WriteLine($"Output will be written to {WriteLogFile}", 255, 180, 0);
                    System.IO.Directory.CreateDirectory(qstr.ExtractDir(WriteLogFile));
                    WrLog = QuickStream.WriteFile(WriteLogFile);
                    WrLog.WriteString("<html>\n<head><title>Log from Bubble!</title></head><style>body{ color: white; background-color: black; font-family: courier; font-size:20pt; }</style>\n\n", true);
                } catch (Exception EX) {
                    WriteLine("ERROR!", 255, 0, 0);
                    WriteLine($"{EX.Message}", 255, 0, 0);
                    WriteLine("Due to this error I cannot guarantee the log will work!");
                    Console.Beep();
                }
            }
            WriteLine($"Bubble {MKL.Newest} - (c) Jeroen P. Broks", 255, 255, 0);
            var s = new NLua.Lua();
            var v = (string)s.DoString("return _VERSION")[0];

            WriteLine($"Uses {v} by PUC-Rio", 180, 0, 255);
            WriteLine($"Data folder: {Bubble_Save.SWorkDir}", 180, 255, 0);
            if (SBubble.JCR.Exists("Bubble/Background.png"))
            {
                WriteLine("Loading: Bubble/Background.png", 255, 180, 0);
                BackGround = TQMG.GetImage("Bubble/Console.png");
            }
            else if (SBubble.JCR.Exists("Bubble/Console.jpg"))
            {
                WriteLine("Loading: Bubble/Console.jpg", 255, 180, 0);
                BackGround = TQMG.GetImage("Bubble/Console.jpg");
            }
            else
            {
                WriteLine("No background found", 255, 0, 0);
            }
        }
Пример #7
0
        TQMGImage GetTex(KthuraObject obj)
        {
            var file  = obj.Texture;
            var kind  = obj.kind;
            var lay   = obj.Parent;
            var map   = lay.Parent;
            var mfile = qstr.StripExt(file);

            if (qstr.ExtractExt(file.ToUpper()) == "PNG" && map.TextureJCR.Exists($"{mfile}.frames") && map.TextureJCR.DirExists($"{mfile}.jpbf"))
            {
                var rfile = $"{mfile}.jpbf";
                switch (AutoBundle)
                {
                case TAutoBundle.Off: break;

                case TAutoBundle.AutomaticallyFixObject:
                    obj.Texture = rfile;
                    // Fallthrough... Otherwise not supported in C#, so this is the only way to do it (bad bad Microsoft)
                    goto case TAutoBundle.ReplaceInLoadOnly;

                case TAutoBundle.ReplaceInLoadOnly:
                    file = rfile;
                    break;
                }
            }
            if (map != LastUsedMap)
            {
                Textures.Clear();                     // Only store texture per map. Will take too much RAM otherwise!
            }
            LastUsedMap = map;
            var tag = $"{kind}::{file}";

            if (!Textures.ContainsKey(tag))
            {
                if (qstr.ExtractExt(file.ToUpper()) == "JPBF")
                {
                    Textures[tag] = TQMG.GetBundle(map.TextureJCR, $"{file}/");
                    //Bubble.BubConsole.WriteLine($"KTHURA DRAW DEBUG: Loading Bundle {file}", 255, 255, 0); // debug! (must be on comment when not in use)
                }
                else
                {
                    if (map.TextureJCR == null)
                    {
                        Debug.WriteLine("TextureJCR is null???");
                    }
                    var bt = map.TextureJCR.ReadFile(file);
                    if (bt == null)
                    {
                        if (NoTexture != null)
                        {
                            Textures[tag] = NoTexture; //TQMG.GetImage(NoTexture.GetTex(0));
                            System.Console.Beep();
                            Debug.WriteLine($"Texture {file} for {tag} could not be loaded , so set to alternet picture in stead ({UseJCR6.JCR6.JERROR})");
                            //return NoTexture;
                        }
                        else
                        {
                            CrashOnNoTex?.Invoke($"Couldn't open texture file {file} for {tag}");
                            Debug.WriteLine($"Couldn't open texture file {file} for {tag}");
                            return(null);
                        }
                    }
                    else
                    {
                        Textures[tag] = TQMG.GetImage(bt);
                        if (Textures[tag] == null)
                        {
                            if (NoTexture != null)
                            {
                                Textures[tag] = NoTexture;
                                System.Console.Beep();
                                Debug.WriteLine($"Texture {tag} could not be loaded, so set to alternet picture in stead");
                            }
                            else
                            {
                                CrashOnNoTex?.Invoke($"Texture `{file}` didn't load at all on tag {tag}.\n{UseJCR6.JCR6.JERROR}");
                            }
                        }
                    }
                }
                if (Textures[tag].Frames == 0)
                {
                    CrashOnNoTex?.Invoke($"Texture `{file}` for tag `{tag}` has no frames");
                }
                if (obj.kind == "Obstacle" || obj.kind == "Actor")
                {
                    Textures[tag].HotBottomCenter();
                }
            }
            return(Textures[tag]);
        }
Пример #8
0
        static public void TextSizes(string text, ref int w, ref int h, int x = 0)
        {
            var dx = x;
            var dy = 0;
            // Needed due to C#'s primitive nature!
            var tw = w;
            var th = h;

            void update()
            {
                if (dx > tw)
                {
                    tw = dx;
                }
                if (dy > th)
                {
                    th = dy + fh;
                }
            }

            for (int i = 0; i < text.Length; i++)
            {
                var b = (byte)text[i];
                if (b == 32)
                {
                    dx += fw;
                    update();
                }
                else if (b == 10)
                {
                    dx  = x;
                    dy += fh;
                    update();
                }
                else if (b > 32 && b < 127)
                {
                    if (!CharPics.ContainsKey(b))
                    {
                        var q = QuickStream.OpenEmbedded($"SysFont.{b}.png");
                        if (q != null)
                        {
                            CharPics[b] = TQMG.GetImage(q);
                            Debug.WriteLine($"Loaded character {b} => {text[i]}");
                        }
                    }
                    if (CharPics.ContainsKey(b))   // NO ELSE! That won't cause the desired effect
                    {
                        try {
                            var cp = CharPics[b];
                            if (fw < cp.Width)
                            {
                                fw = cp.Width;
                            }
                            if (fh < cp.Height)
                            {
                                fh = cp.Height;
                            }
                            dx += fw;
                            update();
                            if (dx + fw > TQMG.ScrWidth)
                            {
                                dx  = x;
                                dy += fh;
                                update();
                            }
                        } catch (Exception E) {
                            Debug.Print($"Caught: {E.Message}");
                        }
                    }
                }
            }
            w = tw;
            h = th;
        }
        public static void Init()
        {
            Error = "";
            MKL.Version("TeddyBear - TeddyDraw_MonoGame.cs", "19.04.06");
            MKL.Lic("TeddyBear - TeddyDraw_MonoGame.cs", "ZLib License");
            // This item will allow MonoGame to draw tiles in the map
            TeddyDraw.DrawTileItem = delegate(TeddyMap map, string layer, int screenstart_x, int screenstart_y, int scroll_x, int scroll_y, int posx, int posy)
            {
                //TeddyMap map, string layer, int screenstart_x, int screenstart_y, int scroll_x, int scroll_y, int posx, int posy
                Error = "";
                if (!map.Layers.ContainsKey(layer))
                {
                    Error = $"Layer '{layer}' does not exist in this map!"; return;
                }
                if (qstr.Prefixed(layer, "Zone_"))
                {
                    TeddyDraw.DrawZoneItem(map, layer, screenstart_x, screenstart_y, scroll_x, scroll_y, posx, posy); return;
                }
                var b = map.Layers[layer].Get(posx, posy);
                if (b == 0)
                {
                    return;         // 0 stands for nothing and should therefore always be ignored!
                }
                if (map.Texture[b] == null || map.Texture[b] == "")
                {
                    Texture[b] = Unknown; Log($"No texture set on {b}");
                }
                if (Texture[b] == null)
                {
#if !donttry
                    try {
#endif
                    Log($"Loading texture for spot {b} => {map.Texture[b]}");
                    var bt = map.OpenTexture(b);
                    if (bt == null)
                    {
                        Texture[b] = Unknown; Log($"JCR6 failed to open the texture file! {UseJCR6.JCR6.JERROR}"); return;
                    }
                    Texture[b] = TQMG.GetImage(bt);

                    if (Texture[b] == null)
                    {
                        Texture[b] = Unknown; Log($"Texture load failed! {map.Texture[b]}");
                    }
                    else
                    {
                        Log("Texture appears to be loaded succesfully!");
                    }

#if !donttry
                }
                catch (System.Exception er) {
                    Log($"An error happened when loading a texture: {er.Message} >> {er.StackTrace}");
                    Texture[b] = Unknown;
                }
#endif
                }

                if (Texture[b] != null)
                {
                    var modix = 0;
                    var modiy = 0;
                    var dtex  = Texture[b];
                    var dlay  = map.Layers[layer];
                    // X
                    switch (dlay.Hot[1])
                    {
                    case 'L':

                        break;

                    case 'C':

                        modix = (map.GridX / 2) - (dtex.Width / 2);

                        break;

                    case 'R':

                        modix = map.GridX - dtex.Width;

                        break;

                    default:

                        return;     // ERROR!
                    }
                    // Y
                    switch (dlay.Hot[0])
                    {
                    case 'T':

                        break;

                    case 'C':

                        modiy = (map.GridY / 2) - (dtex.Height / 2);

                        break;

                    case 'B':

                        modiy = map.GridY - dtex.Height;

                        break;

                    default:

                        return;     // ERROR!
                    }
                    var dx = ((screenstart_x + (posx * map.GridX)) - scroll_x) + modix;
                    var dy = ((screenstart_y + (posy * map.GridY)) - scroll_y) + modiy;
                    dtex.Draw(dx, dy);
                    //TeddyEdit.UI.font32.DrawText(dlay.Hot, dx, dy); // debug!!!
                }
            };



            // This item will allow MonoGame to draw the zone layer.
            // Basically only required for editors, as zones should be invisible in games.
            TeddyDraw.DrawZoneItem = delegate
            {
                Error = "";
            };



            TeddyDraw.TexReset = delegate(byte b)
            {
                if (b == 0)
                {
                    for (byte i = 255; i > 0; i--)
                    {
                        TeddyDraw.TexReset(i);
                    }
                    return;
                }
                Texture[b] = null;
            };
        }
Пример #10
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            ProjectData.InitJCRDrivers();
            ProjectData.SetGame(this);

            #region Screen Size
            //graphics.PreferredBackBufferWidth = GraphicsDevice.DisplayMode.Width;
            //graphics.PreferredBackBufferHeight = GraphicsDevice.DisplayMode.Height;
            graphics.HardwareModeSwitch = false;
            graphics.IsFullScreen       = true;
            graphics.ApplyChanges();
            #endregion

            #region TeddyBear Draw MonoGame Driver
            TeddyBear.TeddyDraw_MonoGame.Init();
            #endregion

            // Sprite Batch
            SB = new SpriteBatch(GraphicsDevice);

            // Mouse Pointer
            MousePointer = ProjectData.GetTex(GraphicsDevice, "MousePointer.png");

            // TQMG
            TQMG.Init(graphics, GraphicsDevice, SB, ProjectData.JCR);
            TQMG.RegLog(ProjectData.Log);

            // Exporter
            TeddyXport.XPort.init();

            // Unknown
            TeddyBear.TeddyDraw_MonoGame.SetUnknown(TQMG.GetImage("Unknown.png"));
            TeddyBear.TeddyDraw_MonoGame.Log = ProjectData.Log;


            // Do we have a project and a map?
#if DEBUG
            if (false)
            {
            }              // just some crap as things are different while debugging.
#else
            if (ProjectData.args.Length < 3)
            {
                Crash.Error(this, "No arguments given!\nUsage: TeddyEdit <project> <map>\n \n If you are not sure how to use this tool, use the launcher in stead!");
            }
#endif
            else
            {
#if DEBUG
                ProjectData.Project = "Test";
#else
                ProjectData.Project = ProjectData.args[1];
#endif
                if (!ProjectData.AllWell)
                {
                    Crash.Error(this, $"Project loading failed! {ProjectData.Project}");
                }
                else
                {
#if DEBUG
                    ProjectData.MapFile = $"{Dirry.AD(ProjectData.ProjectConfig.C("LevelDir"))}/Test Map";
#else
                    ProjectData.MapFile = $"{Dirry.AD(ProjectData.ProjectConfig.C("LevelDir"))}/{ProjectData.args[2]}";
#endif
                }
            }


            // Teddy Save Log
            TeddyBear.TeddySave.SetLog(ProjectData.Log);

            // Final
            base.Initialize();

            if (ProjectData.AllWell)
            {
                SetStage(Main.Me);
            }
        }