protected void initBarrack(SceneNode islandNode, float positionOnIsland) { String nameSuffix = tileID.ToString(); installationEntity = sceneMgr.CreateEntity("Barracks" + nameSuffix, "Barracks.mesh"); installationNode = islandNode.CreateChildSceneNode("Barracks" + nameSuffix, new Vector3(0, 0, positionOnIsland - 5.0f)); installationNode.AttachObject(installationEntity); installationNode.Scale(new Vector3(1.0f, 1.2f, 1.0f)); installationNode.Translate(new Vector3(0.0f, levelTile.HitBound.LowestY, 0.0f)); if (LevelView.IsNightScene && EngineConfig.ShadowsQuality == 0) // cienie nie lubia innych zrodel swiatla :/ { InitLightFlare(new ColourValue(1f, 1f, 0.9f), new Vector3(0, 1.9f, -2.6f), new Vector2(1.5f, 1.5f)); } if (EngineConfig.DisplayingMinimap) { minimapItem = new MinimapItem(installationNode, framework.MinimapMgr, "Cube.mesh", new ColourValue(0, 0.8f, 0), installationEntity); minimapItem.ScaleOverride = new Vector2(0, 13); // stala wysokosc bunkra, niezale¿na od bounding box minimapItem.Refresh(); } }
protected override void preInitOnScene() { ammunitionModel = sceneMgr.CreateEntity("Flak" + ammunitionID.ToString(), "FlakBullet.mesh"); ammunitionNode = sceneMgr.RootSceneNode.CreateChildSceneNode("Flak" + ammunitionID.ToString(), hiddenPosition); Vector3 oVector = new Vector3(0, 0, -1); innerNode = ammunitionNode.CreateChildSceneNode("FlakInner" + ammunitionID.ToString(), new Vector3(0, 0, 0)); innerNode.AttachObject(ammunitionModel); innerNode.SetScale(0.7f, 0.7f, 0.7f); missileAnimation = new ConstRotateNodeAnimation(innerNode, 75, oVector, "ConstRot"); missileAnimation.Enabled = true; missileAnimation.Looped = true; if (EngineConfig.DisplayingMinimap) { minimapItem = new MinimapItem(ammunitionNode, framework.MinimapMgr, "Cube.mesh", ColourValue.White, ammunitionModel); minimapItem.ScaleOverride = new Vector2(4, 2); minimapItem.Refresh(); minimapItem.Hide(); } ammunitionNode.SetVisible(false); innerNode.SetVisible(false); }
private void initBunker(SceneNode shipSceneNode, float positionOnShip) { String nameSuffix = tileID.ToString(); installationNode = shipSceneNode.CreateChildSceneNode("GunEmplacement" + nameSuffix); installationNode.Translate(new Vector3(0.0f, UnitConverter.LogicToWorldUnits(new PointD(0, (levelTile.YBegin + levelTile.YEnd) / 2.0f)).y - 0.4f, positionOnShip)); installationEntity = sceneMgr.CreateEntity("ShipFlakBase" + nameSuffix, "ShipFlakBase.mesh"); installationNode.AttachObject(installationEntity); isConcrete = false; if (LevelTile is ConcreteBunkerTile) { isConcrete = true; installationEntity.SetMaterialName("Concrete"); // aby by³ betonowy } flakBarrel = sceneMgr.CreateEntity("ShipFlakBarrel" + nameSuffix, "ShipFlakBarrel.mesh"); gunNode = installationNode.CreateChildSceneNode("ShipFlakBarrelNode" + nameSuffix, new Vector3(0.0f, 0.9f, 0.0f)); gunNode.AttachObject(flakBarrel); if (HasRockets) { for (int i = -1; i <= 1; i += 2) { Entity rocketBayEntity = sceneMgr.CreateEntity("RocketBay" + nameSuffix + "_" + i, "RocketBay.mesh"); SceneNode rocketBayNode = installationNode.CreateChildSceneNode(rocketBayEntity.Name + "Node", new Vector3(2.0f * i, -0.2f, levelTile.ViewXShift)); // rocketBayNode.SetScale(1, 4, 1); rocketBayNode.AttachObject(rocketBayEntity); } } if (EngineConfig.DisplayingMinimap) { minimapItem = new MinimapItem(installationNode, framework.MinimapMgr, "Cube.mesh", ColourValue.Red, installationEntity); minimapItem.MinimapObjectsDepth = 5.0f; minimapItem.ScaleOverride = new Vector2(3, 10); // stala wysokosc dziala, niezale¿na od bounding box minimapItem.Refresh(); } barrelState = flakBarrel.GetAnimationState("manual"); barrelState.Enabled = true; barrelState.Loop = true; animableElements.Add(barrelState); }
private void initBunker(SceneNode islandNode, float positionOnIsland) { if (LevelTile is FlakBunkerTile) { initFlakBunker(islandNode, positionOnIsland); } else { initRegularBunker(islandNode, positionOnIsland); } // init rockets if (HasRockets) { initRockets(islandNode, positionOnIsland); } String nameSuffix = tileID.ToString(); if (EngineConfig.DisplayingMinimap) { ColourValue col = ColourValue.Red; if (isConcrete) { col = new ColourValue(0, 0, 1); } minimapItem = new MinimapItem(gunPlaceNode, framework.MinimapMgr, "Cube.mesh", col, installationEntity); minimapItem.ScaleOverride = new Vector2(0, 13); // stala wysokosc dziala, niezale¿na od bounding box minimapItem.Refresh(); } barrelState = flakBarrel.GetAnimationState("manual"); barrelState.Enabled = true; barrelState.Loop = true; animableElements.Add(barrelState); if ((levelTile as BunkerTile).UsingReflector) { initReflector(); } }
/// <summary> /// /// </summary> /// <param name="minimapFrameProperty">UI.wz/UIWindow2.img/MiniMap</param> /// <param name="mapBoard"></param> /// <param name="device"></param> /// <param name="MapName">The map name. i.e The Hill North</param> /// <param name="StreetName">The street name. i.e Hidden street</param> /// <returns></returns> public static MinimapItem CreateMinimapFromProperty(WzSubProperty minimapFrameProperty, Board mapBoard, GraphicsDevice device, string MapName, string StreetName) { if (mapBoard.MiniMap == null) { return(null); } WzSubProperty maxMapProperty = (WzSubProperty)minimapFrameProperty["MaxMap"]; WzSubProperty miniMapProperty = (WzSubProperty)minimapFrameProperty["MinMap"]; WzSubProperty maxMapMirrorProperty = (WzSubProperty)minimapFrameProperty["MaxMapMirror"]; // for Zero maps WzSubProperty miniMapMirrorProperty = (WzSubProperty)minimapFrameProperty["MinMapMirror"]; // for Zero maps WzSubProperty useFrame; if (mapBoard.MapInfo.zeroSideOnly || MapConstants.IsZerosTemple(mapBoard.MapInfo.id)) // zero's temple { useFrame = maxMapMirrorProperty; } else { useFrame = maxMapProperty; } // Wz frames System.Drawing.Bitmap c = ((WzCanvasProperty)useFrame?["c"])?.GetLinkedWzCanvasBitmap(); System.Drawing.Bitmap e = ((WzCanvasProperty)useFrame?["e"])?.GetLinkedWzCanvasBitmap(); System.Drawing.Bitmap n = ((WzCanvasProperty)useFrame?["n"])?.GetLinkedWzCanvasBitmap(); System.Drawing.Bitmap s = ((WzCanvasProperty)useFrame?["s"])?.GetLinkedWzCanvasBitmap(); System.Drawing.Bitmap w = ((WzCanvasProperty)useFrame?["w"])?.GetLinkedWzCanvasBitmap(); System.Drawing.Bitmap ne = ((WzCanvasProperty)useFrame?["ne"])?.GetLinkedWzCanvasBitmap(); // top right System.Drawing.Bitmap nw = ((WzCanvasProperty)useFrame?["nw"])?.GetLinkedWzCanvasBitmap(); // top left System.Drawing.Bitmap se = ((WzCanvasProperty)useFrame?["se"])?.GetLinkedWzCanvasBitmap(); // bottom right System.Drawing.Bitmap sw = ((WzCanvasProperty)useFrame?["sw"])?.GetLinkedWzCanvasBitmap(); // bottom left // Constants const float TOOLTIP_FONTSIZE = 10f; System.Drawing.Color color_bgFill = System.Drawing.Color.Transparent; System.Drawing.Color color_foreGround = System.Drawing.Color.White; string renderText = string.Format("{0}{1}{2}", StreetName, Environment.NewLine, MapName); // Map background image System.Drawing.Bitmap miniMapImage = mapBoard.MiniMap; // the original minimap image without UI frame overlay int effective_width = miniMapImage.Width + e.Width + w.Width; int effective_height = miniMapImage.Height + n.Height + s.Height; using (System.Drawing.Font font = new System.Drawing.Font(GLOBAL_FONT, TOOLTIP_FONTSIZE)) { // Get the width of the 'streetName' or 'mapName' System.Drawing.Graphics graphics_dummy = System.Drawing.Graphics.FromImage(new System.Drawing.Bitmap(1, 1)); // dummy image just to get the Graphics object for measuring string System.Drawing.SizeF tooltipSize = graphics_dummy.MeasureString(renderText, font); effective_width = Math.Max((int)tooltipSize.Width + nw.Width, effective_width); // set new width System.Drawing.Bitmap miniMapUIImage = new System.Drawing.Bitmap(effective_width, effective_height); int mapDrawPositionX = (effective_width / 2) - nw.Width; // map is on the center. The position relative to the UI using (System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(miniMapUIImage)) { // Frames and background UIFrameHelper.DrawUIFrame(graphics, color_bgFill, ne, nw, se, sw, e, w, n, s, null, effective_width, effective_height); graphics.DrawString( renderText, font, new System.Drawing.SolidBrush(color_foreGround), 50, 20); // Map mark if (Program.InfoManager.MapMarks.ContainsKey(mapBoard.MapInfo.mapMark)) { System.Drawing.Bitmap mapMark = Program.InfoManager.MapMarks[mapBoard.MapInfo.mapMark]; graphics.DrawImage(mapMark.ToImage(), 7, 17); } // Map image graphics.DrawImage(miniMapImage, mapDrawPositionX, // map is on the center n.Height); graphics.Flush(); } // Dots pixel System.Drawing.Bitmap bmp_DotPixel = new System.Drawing.Bitmap(2, 4); using (System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(bmp_DotPixel)) { graphics.FillRectangle(new System.Drawing.SolidBrush(System.Drawing.Color.Yellow), new System.Drawing.RectangleF(0, 0, bmp_DotPixel.Width, bmp_DotPixel.Height)); graphics.Flush(); } IDXObject dxObj_miniMapPixel = new DXObject(0, n.Height, bmp_DotPixel.ToTexture2D(device), 0); BaseDXDrawableItem item_pixelDot = new BaseDXDrawableItem(dxObj_miniMapPixel, false) { Position = new Point( mapDrawPositionX, // map is on the center 0) }; // Map Texture2D texturer_miniMap = miniMapUIImage.ToTexture2D(device); IDXObject dxObj = new DXObject(0, 0, texturer_miniMap, 0); MinimapItem item = new MinimapItem(dxObj, item_pixelDot); return(item); } }
/// <summary> /// /// </summary> /// <param name="minimapFrameProperty">UI.wz/UIWindow2.img/MiniMap</param> /// <param name="mapBoard"></param> /// <param name="device"></param> /// <param name="MapName">The map name. i.e The Hill North</param> /// <param name="StreetName">The street name. i.e Hidden street</param> /// <returns></returns> public static MinimapItem CreateMinimapFromProperty(WzSubProperty minimapFrameProperty, Board mapBoard, GraphicsDevice device, string MapName, string StreetName) { WzSubProperty maxMapProperty = (WzSubProperty)minimapFrameProperty["MaxMap"]; WzSubProperty miniMapProperty = (WzSubProperty)minimapFrameProperty["MinMap"]; WzSubProperty maxMapMirrorProperty = (WzSubProperty)minimapFrameProperty["MaxMapMirror"]; // for Zero maps WzSubProperty miniMapMirrorProperty = (WzSubProperty)minimapFrameProperty["MinMapMirror"]; // for Zero maps WzSubProperty useFrame; if (mapBoard.MapInfo.zeroSideOnly || MapConstants.IsZerosTemple(mapBoard.MapInfo.id)) // zero's temple { useFrame = maxMapMirrorProperty; } else { useFrame = maxMapProperty; } // Wz frames System.Drawing.Bitmap c = ((WzCanvasProperty)useFrame?["c"])?.GetLinkedWzCanvasBitmap(); System.Drawing.Bitmap e = ((WzCanvasProperty)useFrame?["e"])?.GetLinkedWzCanvasBitmap(); System.Drawing.Bitmap n = ((WzCanvasProperty)useFrame?["n"])?.GetLinkedWzCanvasBitmap(); System.Drawing.Bitmap s = ((WzCanvasProperty)useFrame?["s"])?.GetLinkedWzCanvasBitmap(); System.Drawing.Bitmap w = ((WzCanvasProperty)useFrame?["w"])?.GetLinkedWzCanvasBitmap(); System.Drawing.Bitmap ne = ((WzCanvasProperty)useFrame?["ne"])?.GetLinkedWzCanvasBitmap(); // top right System.Drawing.Bitmap nw = ((WzCanvasProperty)useFrame?["nw"])?.GetLinkedWzCanvasBitmap(); // top left System.Drawing.Bitmap se = ((WzCanvasProperty)useFrame?["se"])?.GetLinkedWzCanvasBitmap(); // bottom right System.Drawing.Bitmap sw = ((WzCanvasProperty)useFrame?["sw"])?.GetLinkedWzCanvasBitmap(); // bottom left // Constants const string TOOLTIP_FONT = "Arial"; const float TOOLTIP_FONTSIZE = 10f; System.Drawing.Color color_bgFill = System.Drawing.Color.Transparent; System.Drawing.Color color_foreGround = System.Drawing.Color.White; // Dots pixel System.Drawing.Bitmap bmp_DotPixel = new System.Drawing.Bitmap(2, 4); using (System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(bmp_DotPixel)) { graphics.FillRectangle(new System.Drawing.SolidBrush(System.Drawing.Color.Yellow), new System.Drawing.RectangleF(0, 0, bmp_DotPixel.Width, bmp_DotPixel.Height)); graphics.Flush(); } IDXObject dxObj_miniMapPixel = new DXObject(0, n.Height, bmp_DotPixel.ToTexture2D(device), 0); BaseDXDrawableItem item_pixelDot = new BaseDXDrawableItem(dxObj_miniMapPixel, false); // Map background image System.Drawing.Bitmap miniMapImage = mapBoard.MiniMap; // the original minimap image without UI frame overlay int effective_width = miniMapImage.Width + e.Width + w.Width; int effective_height = miniMapImage.Height + n.Height + s.Height; using (System.Drawing.Font font = new System.Drawing.Font(TOOLTIP_FONT, TOOLTIP_FONTSIZE)) { System.Drawing.Bitmap miniMapUIImage = new System.Drawing.Bitmap(effective_width, effective_height); using (System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(miniMapUIImage)) { // Frames and background UIFrameHelper.DrawUIFrame(graphics, color_bgFill, ne, nw, se, sw, e, w, n, s, null, effective_width, effective_height); graphics.DrawString( string.Format("{0}{1}{2}", StreetName, Environment.NewLine, MapName), font, new System.Drawing.SolidBrush(color_foreGround), 50, 20); // Map mark if (Program.InfoManager.MapMarks.ContainsKey(mapBoard.MapInfo.mapMark)) { System.Drawing.Bitmap mapMark = Program.InfoManager.MapMarks[mapBoard.MapInfo.mapMark]; graphics.DrawImage(mapMark.ToImage(), 7, 17); } // Map image graphics.DrawImage(miniMapImage, 10, n.Height); graphics.Flush(); } Texture2D texturer_miniMap = miniMapUIImage.ToTexture2D(device); IDXObject dxObj = new DXObject(0, 0, texturer_miniMap, 0); MinimapItem item = new MinimapItem(dxObj, item_pixelDot); return(item); } }
/// <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(); }
/// <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(); }
/// <summary> /// Draws the frame and the UI of the minimap. /// TODO: This whole thing needs to be dramatically simplified via further abstraction to keep it noob-proof :( /// </summary> /// <param name="minimapFrameProperty">UI.wz/UIWindow2.img/MiniMap</param> /// <param name="mapBoard"></param> /// <param name="device"></param> /// <param name="MapName">The map name. i.e The Hill North</param> /// <param name="StreetName">The street name. i.e Hidden street</param> /// <returns></returns> public static MinimapItem CreateMinimapFromProperty(WzSubProperty minimapFrameProperty, Board mapBoard, GraphicsDevice device, string MapName, string StreetName, WzDirectory SoundWZFile) { if (mapBoard.MiniMap == null) { return(null); } WzSubProperty maxMapProperty = (WzSubProperty)minimapFrameProperty["MaxMap"]; WzSubProperty miniMapProperty = (WzSubProperty)minimapFrameProperty["MinMap"]; WzSubProperty maxMapMirrorProperty = (WzSubProperty)minimapFrameProperty["MaxMapMirror"]; // for Zero maps WzSubProperty miniMapMirrorProperty = (WzSubProperty)minimapFrameProperty["MinMapMirror"]; // for Zero maps WzSubProperty BtNpc = (WzSubProperty)minimapFrameProperty["BtNpc"]; // npc button WzSubProperty BtMin = (WzSubProperty)minimapFrameProperty["BtMin"]; // mininise button WzSubProperty BtMax = (WzSubProperty)minimapFrameProperty["BtMax"]; // maximise button WzSubProperty BtBig = (WzSubProperty)minimapFrameProperty["BtBig"]; // big button WzSubProperty BtMap = (WzSubProperty)minimapFrameProperty["BtMap"]; // world button WzSubProperty useFrame; if (mapBoard.MapInfo.zeroSideOnly || MapConstants.IsZerosTemple(mapBoard.MapInfo.id)) // zero's temple { useFrame = maxMapMirrorProperty; } else { useFrame = maxMapProperty; } // Wz frames System.Drawing.Bitmap c = ((WzCanvasProperty)useFrame?["c"])?.GetLinkedWzCanvasBitmap(); System.Drawing.Bitmap e = ((WzCanvasProperty)useFrame?["e"])?.GetLinkedWzCanvasBitmap(); System.Drawing.Bitmap n = ((WzCanvasProperty)useFrame?["n"])?.GetLinkedWzCanvasBitmap(); System.Drawing.Bitmap s = ((WzCanvasProperty)useFrame?["s"])?.GetLinkedWzCanvasBitmap(); System.Drawing.Bitmap w = ((WzCanvasProperty)useFrame?["w"])?.GetLinkedWzCanvasBitmap(); System.Drawing.Bitmap ne = ((WzCanvasProperty)useFrame?["ne"])?.GetLinkedWzCanvasBitmap(); // top right System.Drawing.Bitmap nw = ((WzCanvasProperty)useFrame?["nw"])?.GetLinkedWzCanvasBitmap(); // top left System.Drawing.Bitmap se = ((WzCanvasProperty)useFrame?["se"])?.GetLinkedWzCanvasBitmap(); // bottom right System.Drawing.Bitmap sw = ((WzCanvasProperty)useFrame?["sw"])?.GetLinkedWzCanvasBitmap(); // bottom left // Constants const float TOOLTIP_FONTSIZE = 10f; const int MAPMARK_IMAGE_ALIGN_LEFT = 7; // the number of pixels from the left to draw the map mark image const int MAP_IMAGE_PADDING = 2; // the number of pixels from the left to draw the minimap image System.Drawing.Color color_bgFill = System.Drawing.Color.Transparent; System.Drawing.Color color_foreGround = System.Drawing.Color.White; string renderText = string.Format("{0}{1}{2}", StreetName, Environment.NewLine, MapName); // Map background image System.Drawing.Bitmap miniMapImage = mapBoard.MiniMap; // the original minimap image without UI frame overlay int effective_width = miniMapImage.Width + e.Width + w.Width; int effective_height = miniMapImage.Height + n.Height + s.Height; using (System.Drawing.Font font = new System.Drawing.Font(GLOBAL_FONT, TOOLTIP_FONTSIZE)) { // Get the width of the 'streetName' or 'mapName' System.Drawing.Graphics graphics_dummy = System.Drawing.Graphics.FromImage(new System.Drawing.Bitmap(1, 1)); // dummy image just to get the Graphics object for measuring string System.Drawing.SizeF tooltipSize = graphics_dummy.MeasureString(renderText, font); effective_width = Math.Max((int)tooltipSize.Width + nw.Width, effective_width); // set new width int miniMapAlignXFromLeft = MAP_IMAGE_PADDING; if (effective_width > miniMapImage.Width) // if minimap is smaller in size than the (text + frame), minimap will be aligned to the center instead { miniMapAlignXFromLeft = (effective_width - miniMapImage.Width) / 2 /* - miniMapAlignXFromLeft*/; } System.Drawing.Bitmap miniMapUIImage = new System.Drawing.Bitmap(effective_width, effective_height); using (System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(miniMapUIImage)) { // Frames and background UIFrameHelper.DrawUIFrame(graphics, color_bgFill, ne, nw, se, sw, e, w, n, s, null, effective_width, effective_height); // Map name + street name graphics.DrawString( renderText, font, new System.Drawing.SolidBrush(color_foreGround), 50, 20); // Map mark if (Program.InfoManager.MapMarks.ContainsKey(mapBoard.MapInfo.mapMark)) { System.Drawing.Bitmap mapMark = Program.InfoManager.MapMarks[mapBoard.MapInfo.mapMark]; graphics.DrawImage(mapMark.ToImage(), MAPMARK_IMAGE_ALIGN_LEFT, 17); } // Map image graphics.DrawImage(miniMapImage, miniMapAlignXFromLeft, // map is on the center n.Height); graphics.Flush(); } // Dots pixel System.Drawing.Bitmap bmp_DotPixel = new System.Drawing.Bitmap(2, 4); using (System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(bmp_DotPixel)) { graphics.FillRectangle(new System.Drawing.SolidBrush(System.Drawing.Color.Yellow), new System.Drawing.RectangleF(0, 0, bmp_DotPixel.Width, bmp_DotPixel.Height)); graphics.Flush(); } IDXObject dxObj_miniMapPixel = new DXObject(0, n.Height, bmp_DotPixel.ToTexture2D(device), 0); BaseDXDrawableItem item_pixelDot = new BaseDXDrawableItem(dxObj_miniMapPixel, false) { Position = new Point( miniMapAlignXFromLeft, // map is on the center 0) }; // Map Texture2D texturer_miniMap = miniMapUIImage.ToTexture2D(device); IDXObject dxObj = new DXObject(0, 0, texturer_miniMap, 0); MinimapItem minimapItem = new MinimapItem(dxObj, item_pixelDot); ////////////// Minimap buttons//////////////////// // This must be in order. // >>> If aligning from the left to the right. Items at the left must be at the top of the code // >>> If aligning from the right to the left. Items at the right must be at the top of the code with its (x position - parent width). // TODO: probably a wrapper class in the future, such as HorizontalAlignment and VerticalAlignment, or Grid/ StackPanel WzBinaryProperty BtMouseClickSoundProperty = (WzBinaryProperty)SoundWZFile["UI.img"]?["BtMouseClick"]; WzBinaryProperty BtMouseOverSoundProperty = (WzBinaryProperty)SoundWZFile["UI.img"]?["BtMouseOver"]; UIObject objUIBtMap = new UIObject(BtMap, BtMouseClickSoundProperty, BtMouseOverSoundProperty, false, new Point(MAP_IMAGE_PADDING, MAP_IMAGE_PADDING), device); objUIBtMap.X = effective_width - objUIBtMap.CanvasSnapshotWidth - 8; // render at the (width of minimap - obj width) UIObject objUIBtBig = new UIObject(BtBig, BtMouseClickSoundProperty, BtMouseOverSoundProperty, false, new Point(MAP_IMAGE_PADDING, MAP_IMAGE_PADDING), device); objUIBtBig.X = objUIBtMap.X - objUIBtBig.CanvasSnapshotWidth; // render at the (width of minimap - obj width) UIObject objUIBtMax = new UIObject(BtMax, BtMouseClickSoundProperty, BtMouseOverSoundProperty, false, new Point(MAP_IMAGE_PADDING, MAP_IMAGE_PADDING), device); objUIBtMax.X = objUIBtBig.X - objUIBtMax.CanvasSnapshotWidth; // render at the (width of minimap - obj width) UIObject objUIBtMin = new UIObject(BtMin, BtMouseClickSoundProperty, BtMouseOverSoundProperty, false, new Point(MAP_IMAGE_PADDING, MAP_IMAGE_PADDING), device); objUIBtMin.X = objUIBtMax.X - objUIBtMin.CanvasSnapshotWidth; // render at the (width of minimap - obj width) // BaseClickableUIObject objUINpc = new BaseClickableUIObject(BtNpc, false, new Point(objUIBtMap.CanvasSnapshotWidth + objUIBtBig.CanvasSnapshotWidth + objUIBtMax.CanvasSnapshotWidth + objUIBtMin.CanvasSnapshotWidth, MAP_IMAGE_PADDING), device); minimapItem.AddUIButtons(objUIBtMin); minimapItem.AddUIButtons(objUIBtMax); minimapItem.AddUIButtons(objUIBtBig); minimapItem.AddUIButtons(objUIBtMap); ////////////////////////////////////////////////// return(minimapItem); } }
/// <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(); }