/// <summary> /// Tooltip /// </summary> /// <param name="texturePool"></param> /// <param name="farmFrameParent"></param> /// <param name="tooltip"></param> /// <param name="device"></param> /// <returns></returns> public static TooltipItem CreateTooltipFromProperty(TexturePool texturePool, WzSubProperty farmFrameParent, ToolTipInstance tooltip, GraphicsDevice device) { // Wz frames System.Drawing.Bitmap c = ((WzCanvasProperty)farmFrameParent?["c"])?.GetLinkedWzCanvasBitmap(); System.Drawing.Bitmap cover = ((WzCanvasProperty)farmFrameParent?["cover"])?.GetLinkedWzCanvasBitmap(); System.Drawing.Bitmap e = ((WzCanvasProperty)farmFrameParent?["e"])?.GetLinkedWzCanvasBitmap(); System.Drawing.Bitmap n = ((WzCanvasProperty)farmFrameParent?["n"])?.GetLinkedWzCanvasBitmap(); System.Drawing.Bitmap s = ((WzCanvasProperty)farmFrameParent?["s"])?.GetLinkedWzCanvasBitmap(); System.Drawing.Bitmap w = ((WzCanvasProperty)farmFrameParent?["w"])?.GetLinkedWzCanvasBitmap(); System.Drawing.Bitmap ne = ((WzCanvasProperty)farmFrameParent?["ne"])?.GetLinkedWzCanvasBitmap(); // top right System.Drawing.Bitmap nw = ((WzCanvasProperty)farmFrameParent?["nw"])?.GetLinkedWzCanvasBitmap(); // top left System.Drawing.Bitmap se = ((WzCanvasProperty)farmFrameParent?["se"])?.GetLinkedWzCanvasBitmap(); // bottom right System.Drawing.Bitmap sw = ((WzCanvasProperty)farmFrameParent?["sw"])?.GetLinkedWzCanvasBitmap(); // bottom left // tooltip property string title = tooltip.Title; string desc = tooltip.Desc; string renderText = string.Format("{0}{1}{2}", title, Environment.NewLine, desc); // Constants const string TOOLTIP_FONT = "Arial"; const float TOOLTIP_FONTSIZE = 9.25f; // thankie willified, ya'll be remembered forever here <3 //System.Drawing.Color color_bgFill = System.Drawing.Color.FromArgb(230, 17, 54, 82); // pre V patch (dark blue theme used post-bb), leave this here in case someone needs it System.Drawing.Color color_bgFill = System.Drawing.Color.FromArgb(255, 17, 17, 17); // post V patch (dark black theme used), use color picker on paint via image extracted from WZ if you need to get it System.Drawing.Color color_foreGround = System.Drawing.Color.White; const int WIDTH_PADDING = 10; const int HEIGHT_PADDING = 6; // Create using (System.Drawing.Font font = new System.Drawing.Font(TOOLTIP_FONT, TOOLTIP_FONTSIZE)) { 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); int effective_width = (int)tooltipSize.Width + WIDTH_PADDING; int effective_height = (int)tooltipSize.Height + HEIGHT_PADDING; System.Drawing.Bitmap bmp_tooltip = new System.Drawing.Bitmap(effective_width, effective_height); using (System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(bmp_tooltip)) { // Frames and background UIFrameHelper.DrawUIFrame(graphics, color_bgFill, ne, nw, se, sw, e, w, n, s, c, effective_width, effective_height); // Text graphics.DrawString(renderText, font, new System.Drawing.SolidBrush(color_foreGround), WIDTH_PADDING / 2, HEIGHT_PADDING / 2); graphics.Flush(); } IDXObject dxObj = new DXObject(tooltip.X, tooltip.Y, bmp_tooltip.ToTexture2D(device), 0); TooltipItem item = new TooltipItem(tooltip, dxObj); return(item); } }
public override void Draw(SpriteBatch sprite, int mapShiftX, int mapShiftY, int centerX, int centerY, int simWidth, int simHeight) { DXObject frame = GetCurrFrame(); int X = CalculateBackgroundPosX(frame, mapShiftX, centerX); int Y = CalculateBackgroundPosY(frame, mapShiftY, centerY); int _cx = cx == 0 ? frame.Width : cx; int _cy = cy == 0 ? frame.Height : cy; switch (type) { default: case BackgroundType.Regular: Draw2D(sprite, X, Y, frame); break; case BackgroundType.HorizontalTiling: DrawHorizontalCopies(sprite, simWidth, X, Y, _cx, frame); break; case BackgroundType.VerticalTiling: DrawVerticalCopies(sprite, simHeight, X, Y, _cy, frame); break; case BackgroundType.HVTiling: DrawHVCopies(sprite, simWidth, simHeight, X, Y, _cx, _cy, frame); break; case BackgroundType.HorizontalMoving: DrawHorizontalCopies(sprite, simWidth, X + (int)bgMoveShiftX, Y, _cx, frame); IncreaseShiftX(_cx); break; case BackgroundType.VerticalMoving: DrawVerticalCopies(sprite, simHeight, X, Y + (int)bgMoveShiftY, _cy, frame); IncreaseShiftY(_cy); break; case BackgroundType.HorizontalMovingHVTiling: DrawHVCopies(sprite, simWidth, simHeight, X + (int)bgMoveShiftX, Y, _cx, _cy, frame); IncreaseShiftX(_cx); break; case BackgroundType.VerticalMovingHVTiling: DrawHVCopies(sprite, simWidth, simHeight, X, Y + (int)bgMoveShiftY, _cx, _cy, frame); IncreaseShiftX(_cy); break; } }
private void DrawHVCopies(SpriteBatch sprite, int x, int y, int cx, int cy, DXObject frame) { int width = frame.Width; DrawVerticalCopies(sprite, x, y, cy, frame); int copyX = x - cx; while (copyX + width > 0) { DrawVerticalCopies(sprite, copyX, y, cy, frame); copyX -= cx; } copyX = x + cx; while (copyX < MapSimulator.width) { DrawVerticalCopies(sprite, copyX, y, cy, frame); copyX += cx; } }
private void DrawVerticalCopies(SpriteBatch sprite, int x, int y, int cy, DXObject frame) { int height = frame.Height; Draw2D(sprite, x, y, frame); int copyY = y - cy; while (copyY + height > 0) { Draw2D(sprite, x, copyY, frame); copyY -= cy; } copyY = y + cy; while (copyY < MapSimulator.height) { Draw2D(sprite, x, copyY, frame); copyY += cy; } }
public BackgroundItem(int cx, int cy, int rx, int ry, BackgroundType type, int a, bool front, DXObject frame0, bool flip) : base(frame0, flip) { LastShiftIncreaseX = Environment.TickCount; LastShiftIncreaseY = Environment.TickCount; this.rx = rx; this.cx = cx; this.ry = ry; this.cy = cy; this.type = type; this.a = a; this.front = front; color = new Color(0xFF, 0xFF, 0xFF, a); }
public MapItem(DXObject frame0, bool flip) { this.frame0 = frame0; notAnimated = true; this.flip = flip; }
/// <summary> /// Background /// </summary> /// <param name="source"></param> /// <param name="bgInstance"></param> /// <param name="mapCenterX"></param> /// <param name="mapCenterY"></param> /// <param name="device"></param> /// <param name="usedProps"></param> /// <param name="flip"></param> /// <returns></returns> public static BackgroundItem CreateBackgroundFromProperty(WzImageProperty source, BackgroundInstance bgInstance, int mapCenterX, int mapCenterY, GraphicsDevice device, ref List <WzObject> usedProps, bool flip) { source = WzInfoTools.GetRealProperty(source); if (source is WzSubProperty && ((WzSubProperty)source).WzProperties.Count == 1) { source = ((WzSubProperty)source).WzProperties[0]; } if (source is WzCanvasProperty) //one-frame { bool bLoadedSpine = LoadSpineMapObjectItem(source, source, device, bgInstance.SpineAni); if (!bLoadedSpine) { if (source.MSTag == null) { source.MSTag = BoardItem.TextureFromBitmap(device, ((WzCanvasProperty)source).GetLinkedWzCanvasBitmap()); } } usedProps.Add(source); if (source.MSTagSpine != null) { WzSpineObject spineObject = (WzSpineObject)source.MSTagSpine; System.Drawing.PointF origin = ((WzCanvasProperty)source).GetCanvasOriginPosition(); DXSpineObject dxobj = new DXSpineObject(spineObject, bgInstance.BaseX - (int)origin.X /* - mapCenterX*/, bgInstance.BaseY - (int)origin.Y /* - mapCenterY*/, origin); return(new BackgroundItem(bgInstance.cx, bgInstance.cy, bgInstance.rx, bgInstance.ry, bgInstance.type, bgInstance.a, bgInstance.front, dxobj, flip, bgInstance.screenMode)); } else if (source.MSTag != null) { Texture2D texture = (Texture2D)source.MSTag; System.Drawing.PointF origin = ((WzCanvasProperty)source).GetCanvasOriginPosition(); DXObject dxobj = new DXObject(bgInstance.BaseX - (int)origin.X /* - mapCenterX*/, bgInstance.BaseY - (int)origin.Y /* - mapCenterY*/, texture); return(new BackgroundItem(bgInstance.cx, bgInstance.cy, bgInstance.rx, bgInstance.ry, bgInstance.type, bgInstance.a, bgInstance.front, dxobj, flip, bgInstance.screenMode)); } else // default fallback if all things fail { Texture2D texture = BoardItem.TextureFromBitmap(device, Properties.Resources.placeholder); System.Drawing.PointF origin = ((WzCanvasProperty)source).GetCanvasOriginPosition(); DXObject dxobj = new DXObject(bgInstance.BaseX - (int)origin.X /* - mapCenterX*/, bgInstance.BaseY - (int)origin.Y /* - mapCenterY*/, texture); return(new BackgroundItem(bgInstance.cx, bgInstance.cy, bgInstance.rx, bgInstance.ry, bgInstance.type, bgInstance.a, bgInstance.front, dxobj, flip, bgInstance.screenMode)); } } else if (source is WzSubProperty) // animated { WzCanvasProperty frameProp; int i = 0; List <IDXObject> frames = new List <IDXObject>(); while ((frameProp = (WzCanvasProperty)WzInfoTools.GetRealProperty(source[(i++).ToString()])) != null) { int delay = (int)InfoTool.GetOptionalInt(frameProp["delay"], 100); bool bLoadedSpine = LoadSpineMapObjectItem((WzImageProperty)frameProp.Parent, frameProp, device, bgInstance.SpineAni); if (!bLoadedSpine) { if (frameProp.MSTag == null) { frameProp.MSTag = BoardItem.TextureFromBitmap(device, frameProp.GetLinkedWzCanvasBitmap()); } } usedProps.Add(source); if (frameProp.MSTagSpine != null) { WzSpineObject spineObject = (WzSpineObject)frameProp.MSTagSpine; System.Drawing.PointF origin = frameProp.GetCanvasOriginPosition(); DXSpineObject dxobj = new DXSpineObject(spineObject, bgInstance.BaseX - (int)origin.X /* - mapCenterX*/, bgInstance.BaseY - (int)origin.Y /* - mapCenterY*/, origin, delay); frames.Add(dxobj); } else if (frameProp.MSTag != null) { Texture2D texture = (Texture2D)frameProp.MSTag; System.Drawing.PointF origin = frameProp.GetCanvasOriginPosition(); DXObject dxObj = new DXObject(bgInstance.BaseX - (int)origin.X /* - mapCenterX*/, bgInstance.BaseY - (int)origin.Y /* - mapCenterY*/, texture, delay); frames.Add(dxObj); } else // default fallback if all things fail { Texture2D texture = BoardItem.TextureFromBitmap(device, Properties.Resources.placeholder); System.Drawing.PointF origin = frameProp.GetCanvasOriginPosition(); DXObject dxObj = new DXObject(bgInstance.BaseX - (int)origin.X /* - mapCenterX*/, bgInstance.BaseY - (int)origin.Y /* - mapCenterY*/, texture, delay); frames.Add(dxObj); } } return(new BackgroundItem(bgInstance.cx, bgInstance.cy, bgInstance.rx, bgInstance.ry, bgInstance.type, bgInstance.a, bgInstance.front, frames, flip, bgInstance.screenMode)); } else { throw new Exception("Unsupported property type in map simulator"); } }
public int CalculateBackgroundPosX(DXObject frame) { return (rx * (MapSimulator.mapShiftX - MapSimulator.mapCenter.X + 400) / 100) + frame.X + 400; }
private void DrawHorizontalCopies(SpriteBatch sprite, int simWidth, int x, int y, int cx, DXObject frame) { int width = frame.Width; Draw2D(sprite, x, y, frame); int copyX = x - cx; while (copyX + width > 0) { Draw2D(sprite, copyX, y, frame); copyX -= cx; } copyX = x + cx; while (copyX < simWidth) { Draw2D(sprite, copyX, y, frame); copyX += cx; } }
/// <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); } }
public int CalculateBackgroundPosY(DXObject frame) { return((ry * (MapSimulator.mapShiftY - MapSimulator.mapCenter.Y + 300) / 100) + frame.Y + 300); }
public int CalculateBackgroundPosX(DXObject frame) { return((rx * (MapSimulator.mapShiftX - MapSimulator.mapCenter.X + 400) / 100) + frame.X + 400); }
public void Draw2D(SpriteBatch sprite, int x, int y, DXObject frame) { frame.Draw(sprite, x, y, Color, flip); }
public int CalculateBackgroundPosY(DXObject frame) { return (ry * (MapSimulator.mapShiftY - MapSimulator.mapCenter.Y + 300) / 100) + frame.Y + 300; }
public int CalculateBackgroundPosX(DXObject frame, int mapShiftX, int centerX) { return((rx * (mapShiftX - centerX + 400) / 100) + frame.X + 400); }
/// <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); } }
public int CalculateBackgroundPosY(DXObject frame, int mapShiftY, int centerY) { return((ry * (mapShiftY - centerY + 300) / 100) + frame.Y + 300); }
/// <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> /// Background /// </summary> /// <param name="source"></param> /// <param name="x"></param> /// <param name="y"></param> /// <param name="rx"></param> /// <param name="ry"></param> /// <param name="cx"></param> /// <param name="cy"></param> /// <param name="a"></param> /// <param name="type"></param> /// <param name="front"></param> /// <param name="mapCenterX"></param> /// <param name="mapCenterY"></param> /// <param name="device"></param> /// <param name="usedProps"></param> /// <param name="flip"></param> /// <returns></returns> public static BackgroundItem CreateBackgroundFromProperty(WzImageProperty source, int x, int y, int rx, int ry, int cx, int cy, int a, BackgroundType type, bool front, int mapCenterX, int mapCenterY, GraphicsDevice device, ref List <WzObject> usedProps, bool flip) { source = WzInfoTools.GetRealProperty(source); if (source is WzSubProperty && ((WzSubProperty)source).WzProperties.Count == 1) { source = ((WzSubProperty)source).WzProperties[0]; } if (source is WzCanvasProperty) //one-frame { if (source.MSTag == null) { source.MSTag = BoardItem.TextureFromBitmap(device, ((WzCanvasProperty)source).GetLinkedWzCanvasBitmap()); usedProps.Add(source); } Texture2D texture = (Texture2D)source.MSTag; if (texture != null) { System.Drawing.PointF origin = ((WzCanvasProperty)source).GetCanvasOriginPosition(); DXObject dxobj = new DXObject(x - (int)origin.X /* - mapCenterX*/, y - (int)origin.Y /* - mapCenterY*/, texture); return(new BackgroundItem(cx, cy, rx, ry, type, a, front, dxobj, flip)); } else { throw new Exception("Texture is null for the background property."); } } else if (source is WzSubProperty) //animooted { WzCanvasProperty frameProp; int i = 0; List <DXObject> frames = new List <DXObject>(); while ((frameProp = (WzCanvasProperty)WzInfoTools.GetRealProperty(source[(i++).ToString()])) != null) { int?delay = InfoTool.GetOptionalInt(frameProp["delay"]); if (delay == null) { delay = 100; } if (frameProp.MSTag == null) { frameProp.MSTag = BoardItem.TextureFromBitmap(device, frameProp.GetLinkedWzCanvasBitmap()); usedProps.Add(frameProp); } Texture2D texture = (Texture2D)frameProp.MSTag; if (texture != null) { System.Drawing.PointF origin = frameProp.GetCanvasOriginPosition(); frames.Add(new DXObject(x - (int)origin.X /* - mapCenterX*/, y - (int)origin.Y /* - mapCenterY*/, texture, (int)delay)); } else { throw new Exception("Texture is null for the animation"); } } return(new BackgroundItem(cx, cy, rx, ry, type, a, front, frames, flip)); } else { throw new Exception("Unsupported property type in map simulator"); } }