private void PrepareAudioForPlayback()
 {
     if (currAudio == null && soundProp != null)
     {
         currAudio = new WzMp3Streamer(soundProp, checkbox_Replay.IsChecked == true);
     }
 }
Example #2
0
 private void PrepareAudioForPlayback()
 {
     if (currAudio == null && soundProp != null)
     {
         currAudio        = new WzMp3Streamer(soundProp, checkbox_Replay.IsChecked == true);
         currAudio.Volume = (float)(slider_volume.Value / 100f);
     }
 }
Example #3
0
        public MapSimulator(Board mapBoard)
        {
            if (Program.InfoManager.BGMs.ContainsKey(mapBoard.MapInfo.bgm))
            {
                audio = new WzMp3Streamer(Program.InfoManager.BGMs[mapBoard.MapInfo.bgm], true);
            }

            mapCenter  = mapBoard.CenterPoint;
            minimapPos = new Point((int)Math.Round((mapBoard.MinimapPosition.X + mapCenter.X) / (double)mapBoard.mag), (int)Math.Round((mapBoard.MinimapPosition.Y + mapCenter.Y) / (double)mapBoard.mag));

            if (mapBoard.VRRectangle == null)
            {
                vr = new Rectangle(0, 0, mapBoard.MapSize.X, mapBoard.MapSize.Y);
            }
            else
            {
                vr = new Rectangle(mapBoard.VRRectangle.X + mapCenter.X, mapBoard.VRRectangle.Y + mapCenter.Y, mapBoard.VRRectangle.Width, mapBoard.VRRectangle.Height);
            }

            SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true);
            InitializeComponent();
            width       = UserSettings.XGAResolution ? 1024 : 800;
            height      = UserSettings.XGAResolution ? 768 : 600;
            this.Width  = width;
            this.Height = height;
#if FULLSCREEN
            pParams.BackBufferWidth    = Math.Max(Width, 1);
            pParams.BackBufferHeight   = Math.Max(Height, 1);
            pParams.BackBufferFormat   = SurfaceFormat.Color;
            pParams.IsFullScreen       = false;
            pParams.DepthStencilFormat = DepthFormat.Depth24;
#else
            pParams.BackBufferWidth    = Math.Max(width, 1);
            pParams.BackBufferHeight   = Math.Max(height, 1);
            pParams.BackBufferFormat   = SurfaceFormat.Color;
            pParams.DepthStencilFormat = DepthFormat.Depth24;
            pParams.DeviceWindowHandle = Handle;
            pParams.IsFullScreen       = false;
#endif
            DxDevice     = MultiBoard.CreateGraphicsDevice(pParams);
            this.minimap = BoardItem.TextureFromBitmap(DxDevice, mapBoard.MiniMap ?? new System.Drawing.Bitmap(1, 1));
            System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(1, 1);
            bmp.SetPixel(0, 0, System.Drawing.Color.White);
            pixel  = BoardItem.TextureFromBitmap(DxDevice, bmp);
            sprite = new SpriteBatch(DxDevice);
        }
Example #4
0
 private void PlayButton_Click(object sender, EventArgs e)
 {
     if (currAudio == null)
     {
         //currSoundFile = Path.GetTempFileName();
         //soundProp.SaveToFile(currSoundFile);
         currAudio       = new WzMp3Streamer(soundProp, LoopBox.Checked);
         TimeBar.Maximum = (int)currAudio.Length;
         TimeBar.Minimum = 0;
         currAudio.Play();
     }
     else
     {
         currAudio.Play();
     }
     AudioTimer.Enabled  = true;
     PlayButton.Visible  = false;
     PauseButton.Visible = true;
 }
Example #5
0
 private void PlayButton_Click(object sender, EventArgs e)
 {
     if (currAudio == null)
     {
         //currSoundFile = Path.GetTempFileName();
         //soundProp.SaveToFile(currSoundFile);
         currAudio = new WzMp3Streamer(soundProp, LoopBox.Checked);
         TimeBar.Maximum = (int)currAudio.Length;
         TimeBar.Minimum = 0;
         currAudio.Play();
     }
     else
     {
         currAudio.Play();
     }
     AudioTimer.Enabled = true;
     PlayButton.Visible = false;
     PauseButton.Visible = true;
 }
        /// <summary>
        /// Load game assets
        /// </summary>
        protected override void LoadContent()
        {
            WzDirectory MapWzFile = Program.WzManager["map"]; // Map.wz
            WzDirectory UIWZFile  = Program.WzManager["ui"];

            // BGM
            if (Program.InfoManager.BGMs.ContainsKey(mapBoard.MapInfo.bgm))
            {
                audio = new WzMp3Streamer(Program.InfoManager.BGMs[mapBoard.MapInfo.bgm], true);
                if (audio != null)
                {
                    audio.Volume = 0.3f;
                    audio.Play();
                }
            }
            if (mapBoard.VRRectangle == null)
            {
                vr_fieldBoundary = new Rectangle(0, 0, mapBoard.MapSize.X, mapBoard.MapSize.Y);
            }
            else
            {
                vr_fieldBoundary = new Rectangle(mapBoard.VRRectangle.X + mapBoard.CenterPoint.X, mapBoard.VRRectangle.Y + mapBoard.CenterPoint.Y, mapBoard.VRRectangle.Width, mapBoard.VRRectangle.Height);
            }
            //SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true);

            // Background and objects
            List <WzObject> usedProps = new List <WzObject>();

            foreach (LayeredItem tileObj in mapBoard.BoardItems.TileObjs)
            {
                WzImageProperty tileParent = (WzImageProperty)tileObj.BaseInfo.ParentObject;

                mapObjects[tileObj.LayerNumber].Add(
                    MapSimulatorLoader.CreateMapItemFromProperty(texturePool, tileParent, tileObj.X, tileObj.Y, mapBoard.CenterPoint, _DxDeviceManager.GraphicsDevice, ref usedProps, tileObj is IFlippable ? ((IFlippable)tileObj).Flip : false));
            }
            foreach (BackgroundInstance background in mapBoard.BoardItems.BackBackgrounds)
            {
                WzImageProperty bgParent = (WzImageProperty)background.BaseInfo.ParentObject;

                backgrounds_back.Add(
                    MapSimulatorLoader.CreateBackgroundFromProperty(texturePool, bgParent, background, _DxDeviceManager.GraphicsDevice, ref usedProps, background.Flip));
            }
            foreach (BackgroundInstance background in mapBoard.BoardItems.FrontBackgrounds)
            {
                WzImageProperty bgParent = (WzImageProperty)background.BaseInfo.ParentObject;

                backgrounds_front.Add(
                    MapSimulatorLoader.CreateBackgroundFromProperty(texturePool, bgParent, background, _DxDeviceManager.GraphicsDevice, ref usedProps, background.Flip));
            }

            // Load reactors
            foreach (ReactorInstance reactor in mapBoard.BoardItems.Reactors)
            {
                //WzImage imageProperty = (WzImage)NPCWZFile[reactorInfo.ID + ".img"];

                ReactorItem reactorItem = MapSimulatorLoader.CreateReactorFromProperty(texturePool, reactor, _DxDeviceManager.GraphicsDevice, ref usedProps);
                mapObjects_Reactors.Add(reactorItem);
            }

            // Load NPCs
            foreach (NpcInstance npc in mapBoard.BoardItems.NPCs)
            {
                //WzImage imageProperty = (WzImage) NPCWZFile[npcInfo.ID + ".img"];

                NpcItem npcItem = MapSimulatorLoader.CreateNpcFromProperty(texturePool, npc, _DxDeviceManager.GraphicsDevice, ref usedProps);
                mapObjects_NPCs.Add(npcItem);
            }
            // Load Mobs
            foreach (MobInstance mob in mapBoard.BoardItems.Mobs)
            {
                //WzImage imageProperty = Program.WzManager.FindMobImage(mobInfo.ID); // Mob.wz Mob2.img Mob001.wz

                MobItem npcItem = MapSimulatorLoader.CreateMobFromProperty(texturePool, mob, _DxDeviceManager.GraphicsDevice, ref usedProps);
                mapObjects_Mobs.Add(npcItem);
            }

            // Load portals
            WzSubProperty portalParent = (WzSubProperty)MapWzFile["MapHelper.img"]["portal"];

            WzSubProperty gameParent = (WzSubProperty)portalParent["game"];

            //WzSubProperty editorParent = (WzSubProperty) portalParent["editor"];

            foreach (PortalInstance portal in mapBoard.BoardItems.Portals)
            {
                PortalItem portalItem = MapSimulatorLoader.CreatePortalFromProperty(texturePool, gameParent, portal, _DxDeviceManager.GraphicsDevice, ref usedProps);
                if (portalItem != null)
                {
                    mapObjects_Portal.Add(portalItem);
                }
            }

            // Load tooltips
            WzSubProperty farmFrameParent = (WzSubProperty)UIWZFile["UIToolTip.img"]?["Item"]?["FarmFrame"];

            foreach (ToolTipInstance tooltip in mapBoard.BoardItems.ToolTips)
            {
                TooltipItem item = MapSimulatorLoader.CreateTooltipFromProperty(texturePool, farmFrameParent, tooltip, _DxDeviceManager.GraphicsDevice);

                mapObjects_tooltips.Add(item);
            }

            // Cursor
            WzImageProperty cursorImageProperty = (WzImageProperty)UIWZFile["Basic.img"]?["Cursor"];

            this.mouseCursor = MapSimulatorLoader.CreateMouseCursorFromProperty(texturePool, cursorImageProperty, 0, 0, _DxDeviceManager.GraphicsDevice, ref usedProps, false);

            // Spine object
            skeletonMeshRenderer = new SkeletonMeshRenderer(GraphicsDevice)
            {
                PremultipliedAlpha = false
            };

            // Minimap
            WzSubProperty minimapFrameProperty = (WzSubProperty)UIWZFile["UIWindow2.img"]?["MiniMap"];

            miniMap = MapSimulatorLoader.CreateMinimapFromProperty(minimapFrameProperty, mapBoard, GraphicsDevice, mapBoard.MapInfo.strMapName, mapBoard.MapInfo.strStreetName);

            //
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // default positioning for character
            SetCameraMoveX(true, true, 0);
            SetCameraMoveY(true, true, 0);

            // cleanup
            // clear used items
            foreach (WzObject obj in usedProps)
            {
                obj.MSTag      = null;
                obj.MSTagSpine = null; // cleanup
            }
            usedProps.Clear();
        }
Example #7
0
        /// <summary>
        /// Load game assets
        /// </summary>
        protected override void LoadContent()
        {
            WzDirectory MapWzFile   = Program.WzManager["map"]; // Map.wz
            WzDirectory UIWZFile    = Program.WzManager["ui"];
            WzDirectory SoundWZFile = Program.WzManager["sound"];

            this.bBigBangUpdate  = UIWZFile["UIWindow2.img"]?["BigBang!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"] != null; // different rendering for pre and post-bb, to support multiple vers
            this.bBigBang2Update = UIWZFile["UIWindow2.img"]?["BigBang2!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"] != null;

            // BGM
            if (Program.InfoManager.BGMs.ContainsKey(mapBoard.MapInfo.bgm))
            {
                audio = new WzMp3Streamer(Program.InfoManager.BGMs[mapBoard.MapInfo.bgm], true);
                if (audio != null)
                {
                    audio.Volume = 0.3f;
                    audio.Play();
                }
            }
            if (mapBoard.VRRectangle == null)
            {
                vr_fieldBoundary = new Rectangle(0, 0, mapBoard.MapSize.X, mapBoard.MapSize.Y);
            }
            else
            {
                vr_fieldBoundary = new Rectangle(mapBoard.VRRectangle.X + mapBoard.CenterPoint.X, mapBoard.VRRectangle.Y + mapBoard.CenterPoint.Y, mapBoard.VRRectangle.Width, mapBoard.VRRectangle.Height);
            }
            //SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true);

            // test benchmark
#if DEBUG
            var watch = new System.Diagnostics.Stopwatch();
            watch.Start();
#endif

            /////// Background and objects
            List <WzObject> usedProps = new List <WzObject>();

            // Objects
            Task t_tiles = Task.Run(() =>
            {
                foreach (LayeredItem tileObj in mapBoard.BoardItems.TileObjs)
                {
                    WzImageProperty tileParent = (WzImageProperty)tileObj.BaseInfo.ParentObject;

                    mapObjects[tileObj.LayerNumber].Add(
                        MapSimulatorLoader.CreateMapItemFromProperty(texturePool, tileParent, tileObj.X, tileObj.Y, mapBoard.CenterPoint, _DxDeviceManager.GraphicsDevice, ref usedProps, tileObj is IFlippable ? ((IFlippable)tileObj).Flip : false));
                }
            });

            // Background
            Task t_Background = Task.Run(() =>
            {
                foreach (BackgroundInstance background in mapBoard.BoardItems.BackBackgrounds)
                {
                    WzImageProperty bgParent = (WzImageProperty)background.BaseInfo.ParentObject;

                    backgrounds_back.Add(
                        MapSimulatorLoader.CreateBackgroundFromProperty(texturePool, bgParent, background, _DxDeviceManager.GraphicsDevice, ref usedProps, background.Flip));
                }
                foreach (BackgroundInstance background in mapBoard.BoardItems.FrontBackgrounds)
                {
                    WzImageProperty bgParent = (WzImageProperty)background.BaseInfo.ParentObject;

                    backgrounds_front.Add(
                        MapSimulatorLoader.CreateBackgroundFromProperty(texturePool, bgParent, background, _DxDeviceManager.GraphicsDevice, ref usedProps, background.Flip));
                }
            });

            // Reactors
            Task t_reactor = Task.Run(() =>
            {
                foreach (ReactorInstance reactor in mapBoard.BoardItems.Reactors)
                {
                    //WzImage imageProperty = (WzImage)NPCWZFile[reactorInfo.ID + ".img"];

                    ReactorItem reactorItem = MapSimulatorLoader.CreateReactorFromProperty(texturePool, reactor, _DxDeviceManager.GraphicsDevice, ref usedProps);
                    mapObjects_Reactors.Add(reactorItem);
                }
            });

            // NPCs
            Task t_npc = Task.Run(() =>
            {
                foreach (NpcInstance npc in mapBoard.BoardItems.NPCs)
                {
                    //WzImage imageProperty = (WzImage) NPCWZFile[npcInfo.ID + ".img"];
                    if (npc.Hide)
                    {
                        continue;
                    }

                    NpcItem npcItem = MapSimulatorLoader.CreateNpcFromProperty(texturePool, npc, _DxDeviceManager.GraphicsDevice, ref usedProps);
                    mapObjects_NPCs.Add(npcItem);
                }
            });

            // Mobs
            Task t_mobs = Task.Run(() =>
            {
                foreach (MobInstance mob in mapBoard.BoardItems.Mobs)
                {
                    //WzImage imageProperty = Program.WzManager.FindMobImage(mobInfo.ID); // Mob.wz Mob2.img Mob001.wz
                    if (mob.Hide)
                    {
                        continue;
                    }
                    MobItem npcItem = MapSimulatorLoader.CreateMobFromProperty(texturePool, mob, _DxDeviceManager.GraphicsDevice, ref usedProps);
                    mapObjects_Mobs.Add(npcItem);
                }
            });

            // Portals
            Task t_portal = Task.Run(() =>
            {
                WzSubProperty portalParent = (WzSubProperty)MapWzFile["MapHelper.img"]["portal"];

                WzSubProperty gameParent = (WzSubProperty)portalParent["game"];
                //WzSubProperty editorParent = (WzSubProperty) portalParent["editor"];

                foreach (PortalInstance portal in mapBoard.BoardItems.Portals)
                {
                    PortalItem portalItem = MapSimulatorLoader.CreatePortalFromProperty(texturePool, gameParent, portal, _DxDeviceManager.GraphicsDevice, ref usedProps);
                    if (portalItem != null)
                    {
                        mapObjects_Portal.Add(portalItem);
                    }
                }
            });

            // Tooltips
            Task t_tooltips = Task.Run(() =>
            {
                WzSubProperty farmFrameParent = (WzSubProperty)UIWZFile["UIToolTip.img"]?["Item"]?["FarmFrame"];
                foreach (ToolTipInstance tooltip in mapBoard.BoardItems.ToolTips)
                {
                    TooltipItem item = MapSimulatorLoader.CreateTooltipFromProperty(texturePool, UserScreenScaleFactor, farmFrameParent, tooltip, _DxDeviceManager.GraphicsDevice);

                    mapObjects_tooltips.Add(item);
                }
            });

            // Cursor
            Task t_cursor = Task.Run(() =>
            {
                WzImageProperty cursorImageProperty = (WzImageProperty)UIWZFile["Basic.img"]?["Cursor"];
                this.mouseCursor = MapSimulatorLoader.CreateMouseCursorFromProperty(texturePool, cursorImageProperty, 0, 0, _DxDeviceManager.GraphicsDevice, ref usedProps, false);
            });

            // Spine object
            Task t_spine = Task.Run(() =>
            {
                skeletonMeshRenderer = new SkeletonMeshRenderer(GraphicsDevice)
                {
                    PremultipliedAlpha = false,
                };
                skeletonMeshRenderer.Effect.World = this.matrixScale;
            });

            // Minimap
            Task t_minimap = Task.Run(() =>
            {
                if (!mapBoard.MapInfo.hideMinimap)
                {
                    miniMap = MapSimulatorLoader.CreateMinimapFromProperty(UIWZFile, mapBoard, GraphicsDevice, UserScreenScaleFactor, mapBoard.MapInfo.strMapName, mapBoard.MapInfo.strStreetName, SoundWZFile, bBigBangUpdate);
                }
            });

            while (!t_tiles.IsCompleted || !t_Background.IsCompleted || !t_reactor.IsCompleted || !t_npc.IsCompleted || !t_mobs.IsCompleted || !t_portal.IsCompleted ||
                   !t_tooltips.IsCompleted || !t_cursor.IsCompleted || !t_spine.IsCompleted || !t_minimap.IsCompleted)
            {
                Thread.Sleep(100);
            }

#if DEBUG
            // test benchmark
            watch.Stop();
            Debug.WriteLine($"Map WZ files loaded. Execution Time: {watch.ElapsedMilliseconds} ms");
#endif
            //
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // default positioning for character
            SetCameraMoveX(true, true, 0);
            SetCameraMoveY(true, true, 0);

            ///////////// Border
            int leftRightVRDifference = (int)((vr_fieldBoundary.Right - vr_fieldBoundary.Left) * RenderObjectScaling);
            if (leftRightVRDifference < RenderWidth) // viewing range is smaller than the render width..
            {
                this.bDrawVRBorderLeftRight = true;  // flag

                this.texture_vrBoundaryRectLeft   = CreateVRBorder(VR_BORDER_WIDTHHEIGHT, vr_fieldBoundary.Height, _DxDeviceManager.GraphicsDevice);
                this.texture_vrBoundaryRectRight  = CreateVRBorder(VR_BORDER_WIDTHHEIGHT, vr_fieldBoundary.Height, _DxDeviceManager.GraphicsDevice);
                this.texture_vrBoundaryRectTop    = CreateVRBorder(vr_fieldBoundary.Width * 2, VR_BORDER_WIDTHHEIGHT, _DxDeviceManager.GraphicsDevice);
                this.texture_vrBoundaryRectBottom = CreateVRBorder(vr_fieldBoundary.Width * 2, VR_BORDER_WIDTHHEIGHT, _DxDeviceManager.GraphicsDevice);
            }

            /*
             * DXObject leftDXVRObject = new DXObject(
             *  vr_fieldBoundary.Left - VR_BORDER_WIDTHHEIGHT,
             *  vr_fieldBoundary.Top,
             *  texture_vrBoundaryRectLeft);
             * this.leftVRBorderDrawableItem = new BaseDXDrawableItem(leftDXVRObject, false);
             * //new BackgroundItem(int cx, int cy, int rx, int ry, BackgroundType.Regular, 255, true, leftDXVRObject, false, (int) RenderResolution.Res_All);
             *
             * // Right VR
             * DXObject rightDXVRObject = new DXObject(
             *  vr_fieldBoundary.Right,
             *  vr_fieldBoundary.Top,
             *  texture_vrBoundaryRectRight);
             * this.rightVRBorderDrawableItem = new BaseDXDrawableItem(rightDXVRObject, false);
             */
            ///////////// End Border

            // Debug items
            System.Drawing.Bitmap bitmap_debug = new System.Drawing.Bitmap(1, 1);
            bitmap_debug.SetPixel(0, 0, System.Drawing.Color.White);
            texture_debugBoundaryRect = bitmap_debug.ToTexture2D(_DxDeviceManager.GraphicsDevice);

            // cleanup
            // clear used items
            foreach (WzObject obj in usedProps)
            {
                // Spine events
                WzSpineObject spineObj = (WzSpineObject)obj.MSTagSpine;
                if (spineObj != null)
                {
                    spineObj.state.Start    += Start;
                    spineObj.state.End      += End;
                    spineObj.state.Complete += Complete;
                    spineObj.state.Event    += Event;
                }

                obj.MSTag      = null;
                obj.MSTagSpine = null; // cleanup
            }
            usedProps.Clear();
        }
Example #8
0
        /// <summary>
        /// Load game assets
        /// </summary>
        protected override void LoadContent()
        {
            WzDirectory MapWzFile = Program.WzManager["map"]; // Map.wz
            WzDirectory UIWZFile  = Program.WzManager["ui"];

            // BGM
            if (Program.InfoManager.BGMs.ContainsKey(mapBoard.MapInfo.bgm))
            {
                audio = new WzMp3Streamer(Program.InfoManager.BGMs[mapBoard.MapInfo.bgm], true);
                if (audio != null)
                {
                    audio.Volume = 0.3f;
                    audio.Play();
                }
            }
            if (mapBoard.VRRectangle == null)
            {
                vr_fieldBoundary = new Rectangle(0, 0, mapBoard.MapSize.X, mapBoard.MapSize.Y);
            }
            else
            {
                vr_fieldBoundary = new Rectangle(mapBoard.VRRectangle.X + mapBoard.CenterPoint.X, mapBoard.VRRectangle.Y + mapBoard.CenterPoint.Y, mapBoard.VRRectangle.Width, mapBoard.VRRectangle.Height);
            }
            //SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true);

            // test benchmark
#if DEBUG
            var watch = new System.Diagnostics.Stopwatch();
            watch.Start();
#endif

            /////// Background and objects
            List <WzObject> usedProps = new List <WzObject>();

            // Objects
            Task t_tiles = Task.Run(() =>
            {
                foreach (LayeredItem tileObj in mapBoard.BoardItems.TileObjs)
                {
                    WzImageProperty tileParent = (WzImageProperty)tileObj.BaseInfo.ParentObject;

                    mapObjects[tileObj.LayerNumber].Add(
                        MapSimulatorLoader.CreateMapItemFromProperty(texturePool, tileParent, tileObj.X, tileObj.Y, mapBoard.CenterPoint, _DxDeviceManager.GraphicsDevice, ref usedProps, tileObj is IFlippable ? ((IFlippable)tileObj).Flip : false));
                }
            });

            // Background
            Task t_Background = Task.Run(() =>
            {
                foreach (BackgroundInstance background in mapBoard.BoardItems.BackBackgrounds)
                {
                    WzImageProperty bgParent = (WzImageProperty)background.BaseInfo.ParentObject;

                    backgrounds_back.Add(
                        MapSimulatorLoader.CreateBackgroundFromProperty(texturePool, bgParent, background, _DxDeviceManager.GraphicsDevice, ref usedProps, background.Flip));
                }
                foreach (BackgroundInstance background in mapBoard.BoardItems.FrontBackgrounds)
                {
                    WzImageProperty bgParent = (WzImageProperty)background.BaseInfo.ParentObject;

                    backgrounds_front.Add(
                        MapSimulatorLoader.CreateBackgroundFromProperty(texturePool, bgParent, background, _DxDeviceManager.GraphicsDevice, ref usedProps, background.Flip));
                }
            });

            // Reactors
            Task t_reactor = Task.Run(() =>
            {
                foreach (ReactorInstance reactor in mapBoard.BoardItems.Reactors)
                {
                    //WzImage imageProperty = (WzImage)NPCWZFile[reactorInfo.ID + ".img"];

                    ReactorItem reactorItem = MapSimulatorLoader.CreateReactorFromProperty(texturePool, reactor, _DxDeviceManager.GraphicsDevice, ref usedProps);
                    mapObjects_Reactors.Add(reactorItem);
                }
            });

            // NPCs
            Task t_npc = Task.Run(() =>
            {
                foreach (NpcInstance npc in mapBoard.BoardItems.NPCs)
                {
                    //WzImage imageProperty = (WzImage) NPCWZFile[npcInfo.ID + ".img"];
                    if (npc.Hide)
                    {
                        continue;
                    }

                    NpcItem npcItem = MapSimulatorLoader.CreateNpcFromProperty(texturePool, npc, _DxDeviceManager.GraphicsDevice, ref usedProps);
                    mapObjects_NPCs.Add(npcItem);
                }
            });

            // Mobs
            Task t_mobs = Task.Run(() =>
            {
                foreach (MobInstance mob in mapBoard.BoardItems.Mobs)
                {
                    //WzImage imageProperty = Program.WzManager.FindMobImage(mobInfo.ID); // Mob.wz Mob2.img Mob001.wz
                    if (mob.Hide)
                    {
                        continue;
                    }
                    MobItem npcItem = MapSimulatorLoader.CreateMobFromProperty(texturePool, mob, _DxDeviceManager.GraphicsDevice, ref usedProps);
                    mapObjects_Mobs.Add(npcItem);
                }
            });

            // Portals
            Task t_portal = Task.Run(() =>
            {
                WzSubProperty portalParent = (WzSubProperty)MapWzFile["MapHelper.img"]["portal"];

                WzSubProperty gameParent = (WzSubProperty)portalParent["game"];
                //WzSubProperty editorParent = (WzSubProperty) portalParent["editor"];

                foreach (PortalInstance portal in mapBoard.BoardItems.Portals)
                {
                    PortalItem portalItem = MapSimulatorLoader.CreatePortalFromProperty(texturePool, gameParent, portal, _DxDeviceManager.GraphicsDevice, ref usedProps);
                    if (portalItem != null)
                    {
                        mapObjects_Portal.Add(portalItem);
                    }
                }
            });

            // Tooltips
            Task t_tooltips = Task.Run(() =>
            {
                WzSubProperty farmFrameParent = (WzSubProperty)UIWZFile["UIToolTip.img"]?["Item"]?["FarmFrame"];
                foreach (ToolTipInstance tooltip in mapBoard.BoardItems.ToolTips)
                {
                    TooltipItem item = MapSimulatorLoader.CreateTooltipFromProperty(texturePool, farmFrameParent, tooltip, _DxDeviceManager.GraphicsDevice);

                    mapObjects_tooltips.Add(item);
                }
            });

            // Cursor
            Task t_cursor = Task.Run(() =>
            {
                WzImageProperty cursorImageProperty = (WzImageProperty)UIWZFile["Basic.img"]?["Cursor"];
                this.mouseCursor = MapSimulatorLoader.CreateMouseCursorFromProperty(texturePool, cursorImageProperty, 0, 0, _DxDeviceManager.GraphicsDevice, ref usedProps, false);
            });

            // Spine object
            Task t_spine = Task.Run(() =>
            {
                skeletonMeshRenderer = new SkeletonMeshRenderer(GraphicsDevice)
                {
                    PremultipliedAlpha = false
                };
            });

            // Minimap
            Task t_minimap = Task.Run(() =>
            {
                if (!mapBoard.MapInfo.hideMinimap)
                {
                    WzSubProperty minimapFrameProperty = (WzSubProperty)UIWZFile["UIWindow2.img"]?["MiniMap"];

                    if (minimapFrameProperty == null) // UIWindow2 not available pre-BB.
                    {
                        minimapFrameProperty = (WzSubProperty)UIWZFile["UIWindow.img"]?["MiniMap"];
                    }
                    miniMap = MapSimulatorLoader.CreateMinimapFromProperty(minimapFrameProperty, mapBoard, GraphicsDevice, mapBoard.MapInfo.strMapName, mapBoard.MapInfo.strStreetName);
                }
            });

            while (!t_tiles.IsCompleted || !t_Background.IsCompleted || !t_reactor.IsCompleted || !t_npc.IsCompleted || !t_mobs.IsCompleted || !t_portal.IsCompleted ||
                   !t_tooltips.IsCompleted || !t_cursor.IsCompleted || !t_spine.IsCompleted || !t_minimap.IsCompleted)
            {
                Thread.Sleep(50);
            }

#if DEBUG
            // test benchmark
            watch.Stop();
            Debug.WriteLine($"Map loaded. Execution Time: {watch.ElapsedMilliseconds} ms");
#endif
            //
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // default positioning for character
            SetCameraMoveX(true, true, 0);
            SetCameraMoveY(true, true, 0);

            // Debug items
            System.Drawing.Bitmap bitmap_debug = new System.Drawing.Bitmap(1, 1);
            bitmap_debug.SetPixel(0, 0, System.Drawing.Color.White);
            texture_debugBoundaryRect = bitmap_debug.ToTexture2D(_DxDeviceManager.GraphicsDevice);

            // cleanup
            // clear used items
            foreach (WzObject obj in usedProps)
            {
                obj.MSTag      = null;
                obj.MSTagSpine = null; // cleanup
            }
            usedProps.Clear();
        }
Example #9
0
        /// <summary>
        /// Load game assets
        /// </summary>
        protected override void LoadContent()
        {
            // BGM
            if (Program.InfoManager.BGMs.ContainsKey(mapBoard.MapInfo.bgm))
            {
                audio = new WzMp3Streamer(Program.InfoManager.BGMs[mapBoard.MapInfo.bgm], true);
                if (audio != null)
                {
                    audio.Volume = 0.3f;
                    audio.Play();
                }
            }
            if (mapBoard.VRRectangle == null)
            {
                vr = new Rectangle(0, 0, mapBoard.MapSize.X, mapBoard.MapSize.Y);
            }
            else
            {
                vr = new Rectangle(mapBoard.VRRectangle.X + mapBoard.CenterPoint.X, mapBoard.VRRectangle.Y + mapBoard.CenterPoint.Y, mapBoard.VRRectangle.Width, mapBoard.VRRectangle.Height);
            }
            //SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true);

            // Background and objects
            List <WzObject> usedProps = new List <WzObject>();

            //WzDirectory MapFile = Program.WzManager["map"]; // Map.wz
            //WzDirectory tileDir = (WzDirectory)MapFile["Tile"];

            foreach (LayeredItem tileObj in mapBoard.BoardItems.TileObjs)
            {
                WzImageProperty tileParent = (WzImageProperty)tileObj.BaseInfo.ParentObject;

                mapObjects[tileObj.LayerNumber].Add(
                    MapSimulatorLoader.CreateMapItemFromProperty(tileParent, tileObj.X, tileObj.Y, mapBoard.CenterPoint, _DxDeviceManager.GraphicsDevice, ref usedProps, tileObj is IFlippable ? ((IFlippable)tileObj).Flip : false));
            }
            foreach (BackgroundInstance background in mapBoard.BoardItems.BackBackgrounds)
            {
                WzImageProperty bgParent = (WzImageProperty)background.BaseInfo.ParentObject;

                backgrounds_back.Add(
                    MapSimulatorLoader.CreateBackgroundFromProperty(bgParent, background, mapBoard.CenterPoint.X, mapBoard.CenterPoint.Y, _DxDeviceManager.GraphicsDevice, ref usedProps, background.Flip));
            }
            foreach (BackgroundInstance background in mapBoard.BoardItems.FrontBackgrounds)
            {
                WzImageProperty bgParent = (WzImageProperty)background.BaseInfo.ParentObject;

                backgrounds_front.Add(
                    MapSimulatorLoader.CreateBackgroundFromProperty(bgParent, background, mapBoard.CenterPoint.X, mapBoard.CenterPoint.Y, _DxDeviceManager.GraphicsDevice, ref usedProps, background.Flip));
            }
            foreach (WzObject obj in usedProps)
            {
                obj.MSTag      = null;
                obj.MSTagSpine = null; // cleanup
            }
            usedProps.Clear();

            // Spine object
            skeletonMeshRenderer = new SkeletonMeshRenderer(GraphicsDevice);
            skeletonMeshRenderer.PremultipliedAlpha = false;

            // Minimap
            minimapPos   = new Point((int)Math.Round((mapBoard.MinimapPosition.X + mapBoard.CenterPoint.X) / (double)mapBoard.mag), (int)Math.Round((mapBoard.MinimapPosition.Y + mapBoard.CenterPoint.Y) / (double)mapBoard.mag));
            this.minimap = BoardItem.TextureFromBitmap(GraphicsDevice, mapBoard.MiniMap);

            //
            System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(1, 1);
            bmp.SetPixel(0, 0, System.Drawing.Color.White);
            pixel = BoardItem.TextureFromBitmap(GraphicsDevice, bmp);

            sprite = new SpriteBatch(GraphicsDevice);
        }
Example #10
0
        public MapSimulator(Board mapBoard)
        {
            WzSoundProperty bgm = Program.InfoManager.BGMs[mapBoard.MapInfo.bgm];

            if (bgm != null)
            {
                audio = new WzMp3Streamer(bgm, true);
            }
            MapSimulator.mapCenter = mapBoard.CenterPoint;
            if (mapBoard.MapInfo.VR == null)
            {
                vr = new Rectangle(0, 0, mapBoard.MapSize.X, mapBoard.MapSize.Y);
            }
            else
            {
                vr = new Rectangle(mapBoard.MapInfo.VR.Value.X + mapCenter.X, mapBoard.MapInfo.VR.Value.Y + mapCenter.Y, mapBoard.MapInfo.VR.Value.Width, mapBoard.MapInfo.VR.Value.Height);
            }
            SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true);
            InitializeComponent();
            this.Width  = width;
            this.Height = height;
#if FULLSCREEN
            pParams.BackBufferWidth    = Math.Max(width, 1);
            pParams.BackBufferHeight   = Math.Max(height, 1);
            pParams.BackBufferFormat   = SurfaceFormat.Color;
            pParams.IsFullScreen       = false;
            pParams.DepthStencilFormat = DepthFormat.Depth24;
#else
            pParams.BackBufferWidth    = Math.Max(width, 1);
            pParams.BackBufferHeight   = Math.Max(height, 1);
            pParams.BackBufferFormat   = SurfaceFormat.Color;
            pParams.DepthStencilFormat = DepthFormat.Depth24;
            pParams.DeviceWindowHandle = Handle;
            pParams.IsFullScreen       = false;
#endif

/*            try
 *          {
 *              DxDevice = new GraphicsDevice(GraphicsAdapter.DefaultAdapter, DeviceType.Hardware, Handle, pParams);
 *          }
 *          catch
 *          {
 *              DxDevice = new GraphicsDevice(GraphicsAdapter.DefaultAdapter, DeviceType.NullReference, Handle, pParams);
 *          }*/
            try
            {
                GraphicsProfile profile = GraphicsProfile.Reach;
                if (GraphicsAdapter.DefaultAdapter.IsProfileSupported(GraphicsProfile.HiDef))
                {
                    profile = GraphicsProfile.HiDef;
                }
                else if (!GraphicsAdapter.DefaultAdapter.IsProfileSupported(GraphicsProfile.Reach))
                {
                    throw new NotSupportedException();
                }
                DxDevice = new GraphicsDevice(GraphicsAdapter.DefaultAdapter, profile, pParams);
            }
            catch
            {
                HaRepackerLib.Warning.Error("Graphics adapter is not supported");
                Application.Exit();
            }
            graphicsDeviceService = new GraphicsDeviceService(DxDevice);
            this.minimap          = BoardItem.TextureFromBitmap(DxDevice, mapBoard.MiniMap);
            System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(1, 1);
            bmp.SetPixel(0, 0, System.Drawing.Color.White);
            pixel = BoardItem.TextureFromBitmap(DxDevice, bmp);

            //pixel = BoardItem.TextureFromBitmap(DxDevice, new System.Drawing.Bitmap(1, 1));
            contentMan  = new ContentManager(this);
            defaultFont = contentMan.Load <SpriteFont>("Arial");
            sprite      = new SpriteBatch(DxDevice);
            //character = new Character(400 + mapCenter.X, 300 + mapCenter.Y);
            //character.DoFly();
        }
        public MapSimulator(Board mapBoard)
        {
            InitializeComponent();

            if (Program.InfoManager.BGMs.ContainsKey(mapBoard.MapInfo.bgm))
            {
                audio = new WzMp3Streamer(Program.InfoManager.BGMs[mapBoard.MapInfo.bgm], true);
            }

            mapCenter  = mapBoard.CenterPoint;
            minimapPos = new Point((int)Math.Round((mapBoard.MinimapPosition.X + mapCenter.X) / (double)mapBoard.mag), (int)Math.Round((mapBoard.MinimapPosition.Y + mapCenter.Y) / (double)mapBoard.mag));
            if (mapBoard.VRRectangle == null)
            {
                vr = new Rectangle(0, 0, mapBoard.MapSize.X, mapBoard.MapSize.Y);
            }
            else
            {
                vr = new Rectangle(mapBoard.VRRectangle.X + mapCenter.X, mapBoard.VRRectangle.Y + mapCenter.Y, mapBoard.VRRectangle.Width, mapBoard.VRRectangle.Height);
            }
            SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true);


            switch (UserSettings.SimulateResolution)
            {
            case MapRenderResolution.Res_1024x768:      // 1024x768
                RenderHeight = 768;
                RenderWidth  = 1024;
                break;

            case MapRenderResolution.Res_1280x720:     // 1280x720
                RenderHeight = 720;
                RenderWidth  = 1280;
                break;

            case MapRenderResolution.Res_1366x768:      // 1366x768
                RenderHeight = 768;
                RenderWidth  = 1366;
                break;

            case MapRenderResolution.Res_1920x1080:
                RenderHeight = 1080;
                RenderWidth  = 1920;
                break;

            case MapRenderResolution.Res_800x600:     // 800x600
            default:
                RenderHeight = 600;
                RenderWidth  = 800;
                break;
            }
            double dpi = ScreenDPIUtil.GetScreenScaleFactor();

            // set Form window height & width
            this.Width  = (int)(RenderWidth * dpi);
            this.Height = (int)(RenderHeight * dpi);

#if FULLSCREEN
            pParams.BackBufferWidth    = Math.Max(Width, 1);
            pParams.BackBufferHeight   = Math.Max(Height, 1);
            pParams.BackBufferFormat   = SurfaceFormat.Color;
            pParams.IsFullScreen       = false;
            pParams.DepthStencilFormat = DepthFormat.Depth24;
#else
            pParams.BackBufferWidth    = Math.Max(RenderWidth, 1);
            pParams.BackBufferHeight   = Math.Max(RenderHeight, 1);
            pParams.BackBufferFormat   = SurfaceFormat.Color;
            pParams.DepthStencilFormat = DepthFormat.Depth24Stencil8;
            pParams.DeviceWindowHandle = Handle;
            pParams.IsFullScreen       = false;
#endif

            // default center
            mapShiftX = vr.Left;
            mapShiftY = vr.Top;


            DxDevice     = MultiBoard.CreateGraphicsDevice(pParams);
            this.minimap = BoardItem.TextureFromBitmap(DxDevice, mapBoard.MiniMap);
            System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(1, 1);
            bmp.SetPixel(0, 0, System.Drawing.Color.White);
            pixel = BoardItem.TextureFromBitmap(DxDevice, bmp);

            sprite = new SpriteBatch(DxDevice);
        }