Пример #1
0
        public static void HandleMessage(Entity parent, string text, string name, Hue hue, MessageType type, MessageFont font, bool unicode = false, string lang = null)
        {
            switch (type)
            {
            case MessageType.Focus:
            case MessageType.Whisper:
            case MessageType.Yell:
            case MessageType.Spell:
            case MessageType.Regular:
            case MessageType.Label:

                if (parent == null)
                {
                    break;
                }

                if (parent is Item it && !it.OnGround)
                {
                    Gump gump = Engine.UI.GetByLocalSerial <Gump>(it.Container);

                    if (gump is PaperDollGump paperDoll)
                    {
                        var inter = paperDoll
                                    .FindControls <PaperDollInteractable>()
                                    .FirstOrDefault();

                        var f = inter?.FindControls <ItemGump>()
                                .SingleOrDefault(s => s.Item == it);

                        if (f != null)
                        {
                            f.AddLabel(text, hue, (byte)font, unicode);
                        }
                        else
                        {
                            paperDoll.FindControls <EquipmentSlot>()?
                            .SelectMany(s => s.Children)
                            .OfType <ItemGump>()
                            .SingleOrDefault(s => s.Item == it)?
                            .AddLabel(text, hue, (byte)font, unicode);
                        }
                    }
                    else if (gump is ContainerGump container)
                    {
                        container
                        .FindControls <ItemGump>()?
                        .SingleOrDefault(s => s.Item == it)?
                        .AddLabel(text, hue, (byte)font, unicode);
                    }
                    else
                    {
                        Entity ent = World.Get(it.RootContainer);

                        if (ent == null || ent.IsDestroyed)
                        {
                            break;
                        }

                        gump = Engine.UI.GetByLocalSerial <TradingGump>(ent);
                        if (gump != null)
                        {
                            gump.FindControls <DataBox>()?
                            .SelectMany(s => s.Children)
                            .OfType <ItemGump>()
                            .SingleOrDefault(s => s.Item == it)?
                            .AddLabel(text, hue, (byte)font, unicode);
                        }
                        else
                        {
                            Item item = ent.Items.FirstOrDefault(s => s.Graphic == 0x1E5E);

                            if (item == null)
                            {
                                break;
                            }

                            gump = Engine.UI.Gumps.OfType <TradingGump>().FirstOrDefault(s => s.ID1 == item || s.ID2 == item);

                            if (gump != null)
                            {
                                gump.FindControls <DataBox>()?
                                .SelectMany(s => s.Children)
                                .OfType <ItemGump>()
                                .SingleOrDefault(s => s.Item == it)?
                                .AddLabel(text, hue, (byte)font, unicode);
                            }
                            else
                            {
                                Log.Message(LogTypes.Warning, "Missing label handler for this control: 'UNKNOWN'. Report it!!");
                            }
                        }
                    }
                }
                else
                {
                    parent.AddOverhead(type, text, (byte)font, hue, unicode);
                }
                break;