Ejemplo n.º 1
0
        public void CheckHotSpots(float mapX, float mapY)
        {
            Point tipPos = new Point();

            foreach (var e in events)
            {
                if (!IsActive(e))
                {
                    continue;
                }
                if (e.IsInCooldown)
                {
                    continue;
                }
                if (!e.HotSpot)
                {
                    continue;
                }
                for (int x = e.HotPosX; x < e.HotPosX + e.HotWidth; x++)
                {
                    for (int y = e.HotPosY; y < e.HotPosY + e.HotHeight; y++)
                    {
                        bool           matched = false;
                        bool           isNpc   = false;
                        EventComponent npc     = e.GetComponent(EventComponentType.NPCHotspot);
                        if (npc != null)
                        {
                            isNpc = true;
                            engine.Camera.MapToScreen(x, y, out int pX, out int pY);
                            Point p    = engine.Camera.CenterTile(pX, pY);
                            Rect  dest = new Rect(p.X + npc.MapX, p.Y + npc.MapY, npc.MapWidth, npc.MapHeight);
                            if (dest.Contains(engine.Input.ScaledMouseX, engine.Input.ScaledMouseY))
                            {
                                matched = true;
                                tipPos  = new Point(dest.X + dest.Width / 2, (int)(p.Y - engine.Camera.TileHeight * 1.8f));
                            }
                        }
                        else
                        {
                            engine.Camera.MapToScreen(x, y, out int pX, out int pY);
                            Point p = engine.Camera.CenterTile(pX, pY);
                            foreach (var layer in engine.Map.Layers)
                            {
                                if (layer.Visible)
                                {
                                    var tex = layer.GetTileTexture(x, y);
                                    if (tex != null)
                                    {
                                        Rect dest = new Rect(p.X - tex.OffsetX, p.Y - tex.OffsetY, tex.Width, tex.Height);
                                        if (dest.Contains(engine.Input.ScaledMouseX, engine.Input.ScaledMouseY))
                                        {
                                            matched = true;
                                            engine.Camera.MapToScreen(e.CenterX, e.CenterY, out int tipX, out int tipY);
                                            tipY -= engine.Camera.TileHeight;
                                            //tipY -= tex.Height;
                                            tipPos = new Point(tipX, tipY);
                                        }
                                    }
                                }
                            }
                        }
                        if (matched)
                        {
                            var tt = e.GetComponent(EventComponentType.Tooltip);
                            if (tt != null)
                            {
                                engine.MapScreen.ShowTooltip(tt.StringParam, tipPos);
                            }
                            else
                            {
                                engine.MapScreen.HideTooltip();
                            }
                            if (Utils.CalcDist(mapX, mapY, e.CenterX, e.CenterY) < engine.InteractRange)
                            {
                                if (engine.Camera.MapClicked)
                                {
                                    engine.Camera.MapClickDone = true;
                                    ExecuteEvent(e);
                                }
                            }
                            return;
                        }
                    }
                }
            }
            engine.MapScreen.HideTooltip();
        }
Ejemplo n.º 2
0
 public EventComponent AddComponent(EventComponent ec)
 {
     components.Add(ec);
     return(ec);
 }