示例#1
0
        private TooltipContent DrawItem(GameTime gameTime, RenderEnv env, UIWorldMap.Tooltip item)
        {
            var          blocks  = new List <TextBlock>();
            Vector2      size    = Vector2.Zero;
            Vector2      current = Vector2.Zero;
            StringResult sr      = null;

            if (item.MapID != null)
            {
                this.StringLinker?.StringMap.TryGetValue(item.MapID.Value, out sr);
                string title = sr != null?string.Format("{0} : {1}", sr["streetName"], sr["mapName"]) : item.MapID.ToString();

                string desc      = sr?["mapDesc"];
                var    titleFont = string.IsNullOrEmpty(desc) ? env.Fonts.TooltipContentFont : env.Fonts.TooltipTitleFont;
                blocks.Add(PrepareTextLine(titleFont, title, ref current, Color.White, ref size.X));
                if (!string.IsNullOrEmpty(desc))
                {
                    blocks.AddRange(PrepareFormatText(env.Fonts.TooltipContentFont, desc, ref current, 280, ref size.X));
                }
            }

            size.Y = current.Y;
            return(new TooltipContent()
            {
                blocks = blocks, size = size
            });
        }
示例#2
0
            public object GetTooltipTarget(PointF mouseLocation)
            {
                var hitItem = HitTest(mouseLocation);

                if (hitItem is MapSpot)
                {
                    var spot    = (MapSpot)hitItem;
                    var tooltip = new UIWorldMap.Tooltip()
                    {
                        Spot = spot
                    };
                    return(tooltip);
                }
                return(null);
            }
示例#3
0
            public object GetTooltipTarget(PointF mouseLocation)
            {
                var hitItem = HitTest(mouseLocation);

                if (hitItem is MapSpot)
                {
                    var spot    = (MapSpot)hitItem;
                    var tooltip = new UIWorldMap.Tooltip();
                    if (spot.MapNo.Count > 0)
                    {
                        tooltip.MapID = spot.MapNo[0];
                    }
                    return(tooltip);
                }
                return(null);
            }
示例#4
0
        private TooltipContent DrawItem(GameTime gameTime, RenderEnv env, UIWorldMap.Tooltip item)
        {
            var          blocks   = new List <TextBlock>();
            var          textures = new List <TextureBlock>();
            Vector2      size     = Vector2.Zero;
            Vector2      current  = Vector2.Zero;
            StringResult sr       = null;

            var spot = item.Spot;

            if (spot != null)
            {
                //计算属性要求 获取怪物列表和npc列表
                int spotBarrier = 0, spotBarrierArc = 0, spotBarrierAut = 0;
                var mobNames = new List <string>();
                var npcNames = new List <string>();
                int minLevel = 0, maxLevel = 0;

                if (!spot.NoTooltip)
                {
                    HashSet <int> mobs = new HashSet <int>();
                    HashSet <int> npcs = new HashSet <int>();
                    //TODO: caching mobs level.
                    foreach (var mapNo in spot.MapNo)
                    {
                        var mapNode = PluginManager.FindWz(string.Format("Map/Map/Map{0}/{1:D9}.img/info", mapNo / 100000000, mapNo));
                        if (mapNode != null)
                        {
                            int barrier    = mapNode?.Nodes["barrier"].GetValueEx(0) ?? 0;
                            int barrierArc = mapNode?.Nodes["barrierArc"].GetValueEx(0) ?? 0;
                            int barrierAut = mapNode?.Nodes["barrierAut"].GetValueEx(0) ?? 0;
                            spotBarrier    = Math.Max(spotBarrier, barrier);
                            spotBarrierArc = Math.Max(spotBarrierArc, barrierArc);
                            spotBarrierAut = Math.Max(spotBarrierAut, barrierAut);
                        }

                        var mapInfo = PluginManager.FindWz(string.Format("Etc/MapObjectInfo.img/{0}", mapNo));
                        if (mapInfo != null)
                        {
                            var mobNode = mapInfo.Nodes["mob"];
                            if (mobNode != null)
                            {
                                foreach (var valNode in mobNode.Nodes)
                                {
                                    mobs.Add(valNode.GetValue <int>());
                                }
                            }
                            var npcNode = mapInfo.Nodes["npc"];
                            if (npcNode != null)
                            {
                                foreach (var valNode in npcNode.Nodes)
                                {
                                    npcs.Add(valNode.GetValue <int>());
                                }
                            }
                        }
                    }

                    if (mobs.Count > 0)
                    {
                        foreach (var mobID in mobs)
                        {
                            this.StringLinker?.StringMob.TryGetValue(mobID, out sr);
                            var    mobLevel = PluginManager.FindWz(string.Format("Mob/{0:D7}.img/info/level", mobID)).GetValueEx <int>(0);
                            string mobText  = sr != null?string.Format("{0}(Lv.{1})", sr.Name, mobLevel) : mobID.ToString();

                            mobNames.Add(mobText);
                            if (mobLevel > 0)
                            {
                                if (minLevel > 0)
                                {
                                    minLevel = Math.Min(minLevel, mobLevel);
                                }
                                else
                                {
                                    minLevel = mobLevel;
                                }
                                if (maxLevel > 0)
                                {
                                    maxLevel = Math.Max(maxLevel, mobLevel);
                                }
                                else
                                {
                                    maxLevel = mobLevel;
                                }
                            }
                        }
                        minLevel = Math.Max(10, minLevel - 3);
                        maxLevel = Math.Max(10, maxLevel - 2);
                    }
                    if (npcs.Count > 0)
                    {
                        foreach (var npcID in npcs)
                        {
                            this.StringLinker?.StringNpc.TryGetValue(npcID, out sr);
                            string npcText = sr?.Name ?? npcID.ToString();
                            npcNames.Add(npcText);
                        }
                    }
                }

                //预计算宽度
                int partWidth          = 0;
                int?drawNpcColumnWidth = null;
                var font = env.Fonts.TooltipContentFont;
                if (mobNames.Count > 0 || npcNames.Count > 0)
                {
                    float mobWidth = mobNames.Count <= 0 ? 0 : mobNames.Max(text => font.MeasureString(text).X);
                    float npcWidth = npcNames.Count <= 0 ? 0 : npcNames.Max(text => font.MeasureString(text).X);
                    if (npcNames.Count > 0 && mobNames.Count + npcNames.Count > 18)
                    {
                        partWidth          = (int)Math.Max(mobWidth, npcWidth * 2 + 10);
                        drawNpcColumnWidth = (int)npcWidth;
                    }
                    else
                    {
                        partWidth = (int)Math.Max(mobWidth, npcWidth);
                    }
                    partWidth += 15;
                }

                //开始绘制
                //属性要求
                List <object> part1      = null;
                float         part1Width = 0;
                if (spotBarrier > 0 || spotBarrierArc > 0 || spotBarrierAut > 0)
                {
                    part1 = new List <object>();
                    Action <int, Texture2D, Color> addBarrier = (barrier, icon, foreColor) =>
                    {
                        if (icon != null)
                        {
                            var rect = new Rectangle((int)current.X, (int)current.Y + 1, icon.Width, icon.Height);
                            part1.Add(new TextureBlock(icon, rect));
                            current.X += rect.Width + 1;
                        }

                        var textBlock = PrepareTextBlock(env.Fonts.DefaultFont, barrier.ToString(), ref current, foreColor);
                        part1.Add(textBlock);
                    };

                    if (spotBarrier > 0)
                    {
                        var icon = Content.Load <Texture2D>(nameof(MRes.UIWindow_img_ToolTip_WorldMap_StarForce));
                        addBarrier(spotBarrier, icon, new Color(255, 204, 0));
                    }
                    else if (spotBarrierArc > 0)
                    {
                        var icon = Content.Load <Texture2D>(nameof(MRes.UIWindow_img_ToolTip_WorldMap_ArcaneForce));
                        addBarrier(spotBarrierArc, icon, new Color(221, 170, 255));
                    }
                    else if (spotBarrierAut > 0)
                    {
                        var icon = Content.Load <Texture2D>(nameof(MRes.UIWindow_img_ToolTip_WorldMap_AuthenticForce));
                        addBarrier(spotBarrierAut, icon, new Color(221, 170, 255));
                    }

                    part1Width = current.X;
                    size.X     = Math.Max(size.X, current.X);
                    current.X  = 0;
                    current.Y += 15;
                }

                //地图名称
                List <TextBlock> part2      = new List <TextBlock>();
                List <TextBlock> part2_1    = null;
                float            part2Width = 0;
                {
                    int mapID = spot.MapNo[0];
                    this.StringLinker?.StringMap.TryGetValue(mapID, out sr);
                    string title     = spot.Title ?? (sr != null ? string.Format("{0} : {1}", sr["streetName"], sr["mapName"]) : mapID.ToString());
                    string desc      = spot.Desc ?? sr?["mapDesc"];
                    var    titleFont = string.IsNullOrEmpty(desc) ? env.Fonts.TooltipContentFont : env.Fonts.TooltipTitleFont;
                    part2.Add(PrepareTextLine(titleFont, title, ref current, Color.White, ref part2Width));
                    size.X = Math.Max(size.X, part2Width);

                    if (!string.IsNullOrEmpty(desc))
                    {
                        current.Y += 2;
                        part2_1    = new List <TextBlock>();
                        int width = (int)MathHelper2.Max(280, part2Width, size.X, partWidth);
                        part2_1.AddRange(PrepareFormatText(env.Fonts.TooltipContentFont, desc, ref current, width, ref size.X));
                    }

                    current.Y += 4;
                }

                //准备分割线
                List <TextureBlock> lines = new List <TextureBlock>();
                var line = Content.Load <Texture2D>(nameof(MRes.UIWindow_img_ToolTip_WorldMap_Line));

                //绘制怪物
                List <object> part3 = null;
                if (mobNames.Count > 0)
                {
                    part3 = new List <object>();

                    //绘制分割线
                    lines.Add(new TextureBlock(line, new Rectangle(current.ToPoint(), Point.Zero)));
                    current.Y += 8;

                    //推荐等级
                    current.X = 15;
                    part3.Add(PrepareTextBlock(font,
                                               string.Format("推荐等级 : Lv.{0} ~ Lv.{1}", minLevel, maxLevel),
                                               ref current, new Color(119, 204, 255)));
                    size.X     = Math.Max(size.X, current.X);
                    current.X  = 0;
                    current.Y += 18;

                    //绘制分割线
                    lines.Add(new TextureBlock(line, new Rectangle(current.ToPoint(), Point.Zero)));
                    current.Y += 8;

                    //怪物列表
                    Texture2D icon;
                    Color     color;
                    if (spotBarrier > 0 || spotBarrierArc > 0 || spotBarrierAut > 0)
                    {
                        icon  = Content.Load <Texture2D>(nameof(MRes.UIWindow_img_ToolTip_WorldMap_enchantMob));
                        color = new Color(255, 0, 102);
                    }
                    else
                    {
                        icon  = Content.Load <Texture2D>(nameof(MRes.UIWindow_img_ToolTip_WorldMap_Mob));
                        color = new Color(119, 255, 0);
                    }
                    part3.Add(new TextureBlock(icon, new Rectangle(0, (int)current.Y + 1, 0, 0)));
                    foreach (var mobName in mobNames)
                    {
                        part3.Add(new TextBlock()
                        {
                            Font      = font,
                            Text      = mobName,
                            Position  = new Vector2(15, current.Y),
                            ForeColor = color
                        });
                        current.Y += 18;
                    }
                }

                //绘制npc
                List <object> part4 = null;
                if (npcNames.Count > 0)
                {
                    part4 = new List <object>();
                    //绘制分割线
                    lines.Add(new TextureBlock(line, new Rectangle(current.ToPoint(), Point.Zero)));
                    current.Y += 8;

                    //npc列表
                    Texture2D icon  = Content.Load <Texture2D>(nameof(MRes.UIWindow_img_ToolTip_WorldMap_Npc));
                    Color     color = new Color(119, 204, 255);
                    part4.Add(new TextureBlock(icon, new Rectangle(0, (int)current.Y + 1, 0, 0)));
                    for (int i = 0; i < npcNames.Count; i++)
                    {
                        var pos = new Vector2(15, current.Y);
                        if (i % 2 == 1 && drawNpcColumnWidth != null)
                        {
                            pos.X += 10 + drawNpcColumnWidth.Value;
                        }

                        part4.Add(new TextBlock()
                        {
                            Font      = font,
                            Text      = npcNames[i],
                            Position  = pos,
                            ForeColor = color
                        });

                        if (i == npcNames.Count - 1 || drawNpcColumnWidth == null || i % 2 == 1)
                        {
                            current.X  = 0;
                            current.Y += 18;
                        }
                    }
                }

                size.X     = Math.Max(size.X, partWidth);
                current.Y -= 4;

                //合并parts
                //对part1 part2居中
                if (part1 != null)
                {
                    int offset = (int)((size.X - part1Width) / 2);
                    foreach (object obj in part1)
                    {
                        if (obj is TextBlock)
                        {
                            var tb = (TextBlock)obj;
                            tb.Position.X += offset;
                            blocks.Add(tb);
                        }
                        else if (obj is TextureBlock)
                        {
                            var tex = (TextureBlock)obj;
                            tex.Rectangle.X += offset;
                            textures.Add(tex);
                        }
                    }
                }
                if (part2 != null)
                {
                    int offset = (int)((size.X - part2Width) / 2);
                    for (int i = 0; i < part2.Count; i++)
                    {
                        var tb = part2[i];
                        tb.Position.X += offset;
                        blocks.Add(tb);
                    }
                }
                if (part2_1 != null)
                {
                    foreach (var tb in part2_1)
                    {
                        blocks.Add(tb);
                    }
                }
                if (lines != null)
                {
                    for (int i = 0; i < lines.Count; i++)
                    {
                        var tex = lines[i];
                        tex.Rectangle.Width  = (int)size.X;
                        tex.Rectangle.Height = 1;
                        textures.Add(tex);
                    }
                }
                foreach (var _part in new[] { part3, part4 })
                {
                    if (_part != null)
                    {
                        foreach (object obj in _part)
                        {
                            if (obj is TextBlock)
                            {
                                var tb = (TextBlock)obj;
                                blocks.Add(tb);
                            }
                            else if (obj is TextureBlock)
                            {
                                var tex = (TextureBlock)obj;
                                textures.Add(tex);
                            }
                        }
                    }
                }
            }
            size.Y = current.Y;
            return(new TooltipContent()
            {
                blocks = blocks, textures = textures, size = size
            });
        }