Esempio n. 1
0
        void OnRightClick(UiRightClickEvent e)
        {
            var member = PartyMember;

            if (member == null)
            {
                return;
            }

            e.Propagating = false;
            var party         = Resolve <IParty>();
            var window        = Resolve <IWindowManager>();
            var settings      = Resolve <ISettings>();
            var cursorManager = Resolve <ICursorManager>();
            var tf            = Resolve <ITextFormatter>();

            var heading = new LiteralText(
                new TextBlock(member.Apparent.GetName(settings.Gameplay.Language))
            {
                Style     = TextStyle.Fat,
                Alignment = TextAlignment.Center
            });

            IText S(TextId textId) => tf.Center().NoWrap().Format(textId);

            var uiPosition = window.PixelToUi(cursorManager.Position);
            var options    = new List <ContextMenuOption>
            {
                new ContextMenuOption(
                    S(Base.SystemText.PartyPopup_CharacterScreen),
                    new InventoryOpenEvent(member.Id),
                    ContextMenuGroup.Actions)
            };

            if (member.Apparent.Magic.SpellStrengths.Any())
            {
                options.Add(new ContextMenuOption(
                                S(Base.SystemText.PartyPopup_UseMagic),
                                null,
                                ContextMenuGroup.Actions));
            }

            if (member.Id != party.Leader.Id)
            {
                options.Add(new ContextMenuOption(
                                S(Base.SystemText.PartyPopup_MakeLeader),
                                new SetPartyLeaderEvent(member.Id),
                                ContextMenuGroup.Actions));
            }

            if (member.Id != Base.PartyMember.Tom)
            {
                options.Add(new ContextMenuOption(
                                S(Base.SystemText.PartyPopup_TalkTo),
                                new StartPartyDialogueEvent(member.Id),
                                ContextMenuGroup.Actions));
            }

            Raise(new ContextMenuEvent(uiPosition, heading, options));
        }
Esempio n. 2
0
        void OnInput(InputEvent e)
        {
            IList <(float, Selection)> hits = new List <(float, Selection)>();

            Raise(new ScreenCoordinateSelectEvent(e.Snapshot.MousePosition, (t, selection) => hits.Add((t, selection))));
            var orderedHits = hits.OrderBy(x => x.Item1).Select(x => x.Item2).ToList();

            // Clicks are targeted, releases are broadcast. e.g. if you click and drag a slider and move outside
            // its hover area, then it should switch to "ClickedBlurred". If you then release the button while
            // still outside its hover area and releases were broadcast, it would never receive the release and
            // it wouldn't be able to transition back to Normal
            if (e.Snapshot.MouseEvents.Any(x => x.MouseButton == MouseButton.Left && x.Down))
            {
                var clickEvent = new UiLeftClickEvent();
                foreach (var hit in orderedHits)
                {
                    if (!clickEvent.Propagating)
                    {
                        break;
                    }
                    var component = hit.Target as IComponent;
                    component?.Receive(clickEvent, this);
                }
            }

            if (e.Snapshot.MouseEvents.Any(x => x.MouseButton == MouseButton.Right && x.Down))
            {
                var clickEvent = new UiRightClickEvent();
                foreach (var hit in orderedHits)
                {
                    if (!clickEvent.Propagating)
                    {
                        break;
                    }
                    var component = hit.Target as IComponent;
                    component?.Receive(clickEvent, this);
                }
            }

            if (e.Snapshot.MouseEvents.Any(x => x.MouseButton == MouseButton.Left && !x.Down))
            {
                Raise(new UiLeftReleaseEvent());
            }

            if (e.Snapshot.MouseEvents.Any(x => x.MouseButton == MouseButton.Right && !x.Down))
            {
                Raise(new UiRightReleaseEvent());
            }
        }