Exemplo n.º 1
0
            public ButtonMenu(InstructionalButton button) : base(Plugin.MenuTitle, "INSTRUCTIONAL BUTTONS: " + button.Text.ToUpper())
            {
                Plugin.Pool.Add(this);

                this.button = button;

                var text = new UIMenuItem("Text", "")
                {
                    Enabled = true
                }
                .WithTextEditing(() => buttonText,
                                 s =>
                {
                    buttonText         = s;
                    this.button.Button = s;
                    InstructionalButtons.Update();
                });

                var control = new UIMenuListScrollerItem <GameControl>("Control", "", (GameControl[])System.Enum.GetValues(typeof(GameControl)))
                {
                    Enabled      = false,
                    SelectedItem = buttonControl
                };

                control.IndexChanged += (s, o, n) =>
                {
                    buttonControl      = control.SelectedItem;
                    this.button.Button = control.SelectedItem;
                    InstructionalButtons.Update();
                };

                var rawId = new UIMenuNumericScrollerItem <uint>("Raw ID", "", 0, 2048, 1)
                {
                    Enabled = false,
                    Value   = buttonRawId
                }.WithTextEditing();

                rawId.IndexChanged += (s, o, n) =>
                {
                    buttonRawId        = rawId.Value;
                    this.button.Button = rawId.Value;
                    InstructionalButtons.Update();
                };

                var instructionalKey = new UIMenuListScrollerItem <InstructionalKey>("Instructional Key", "", ((InstructionalKey[])System.Enum.GetValues(typeof(InstructionalKey))).Distinct())
                {
                    Enabled      = false,
                    SelectedItem = buttonInstructionalKey
                };

                instructionalKey.IndexChanged += (s, o, n) =>
                {
                    buttonInstructionalKey = instructionalKey.SelectedItem;
                    this.button.Button     = instructionalKey.SelectedItem;
                    InstructionalButtons.Update();
                };

                var type = new UIMenuListScrollerItem <string>("Type", "", new[] { "Text", "Control", "Raw ID", "Instructional Key" });

                type.IndexChanged += (s, o, n) =>
                {
                    const int TextIdx = 0, ControlIdx = 1, RawIdIdx = 2, InstructionalKeyIdx = 3;

                    text.Enabled             = n == TextIdx;
                    control.Enabled          = n == ControlIdx;
                    rawId.Enabled            = n == RawIdIdx;
                    instructionalKey.Enabled = n == InstructionalKeyIdx;

                    this.button.Button = n switch
                    {
                        TextIdx => buttonText,
                        ControlIdx => buttonControl,
                        RawIdIdx => buttonRawId,
                        InstructionalKeyIdx => buttonInstructionalKey,
                        _ => buttonText
                    };
                    InstructionalButtons.Update();
                };

                var remove = new UIMenuItem("Remove");

                remove.Activated += (m, s) =>
                {
                    UIMenu     parentMenu = ParentMenu;
                    UIMenuItem parentItem = ParentItem;

                    Close();

                    parentMenu.ReleaseMenuFromItem(parentItem);
                    parentMenu.RemoveItemAt(parentMenu.MenuItems.IndexOf(parentItem));

                    Plugin.Pool.Remove(this);

                    parentMenu.InstructionalButtons.Buttons.Remove(button);
                    parentMenu.InstructionalButtons.Update();
                    foreach (UIMenu child in parentMenu.Children.Values)
                    {
                        child.InstructionalButtons.Buttons.Remove(this.button);
                        child.InstructionalButtons.Update();
                    }
                };

                AddItems(type, text, control, rawId, instructionalKey, remove);
            }
        }
Exemplo n.º 2
0
        public static unsafe string GetId(this InstructionalKey key)
        {
            // special cases
            switch (key)
            {
            case InstructionalKey.ControllerDPadNone: return("b_8");

            case InstructionalKey.ControllerDPadAll: return("b_9");

            case InstructionalKey.ControllerDPadUpDown: return("b_10");

            case InstructionalKey.ControllerDPadLeftRight: return("b_11");

            case InstructionalKey.ControllerLStickRotate: return("b_20");

            case InstructionalKey.ControllerRStickRotate: return("b_29");

            case InstructionalKey.SymbolBusySpinner: return("b_44");

            case InstructionalKey.SymbolPlus: return("b_998");

            case InstructionalKey.SymbolArrowUp: return("b_0");

            case InstructionalKey.SymbolArrowDown: return("b_1");

            case InstructionalKey.SymbolArrowLeft: return("b_2");

            case InstructionalKey.SymbolArrowRight: return("b_3");

            case InstructionalKey.SymbolArrowUpDown: return("b_45");

            case InstructionalKey.SymbolArrowLeftRight: return("b_46");

            case InstructionalKey.SymbolArrowAll: return("b_47");

            case InstructionalKey.Mouse: return("b_114");
            }

            if (!CTextFormat.Available)
            {
                return("b_995"); // button with "???" in red
            }

            // from rage::ioMapperSource enum
            const uint IOMS_KEYBOARD           = 0,
                       IOMS_MOUSE_ABSOLUTEAXIS = 1,
                       IOMS_MOUSE_WHEEL        = 6,
                       IOMS_MOUSE_BUTTON       = 7,
                       IOMS_PAD_DIGITALBUTTON  = 9,
                       IOMS_PAD_AXIS           = 12;

            const uint MouseAxisMask        = 0x200,
                       MouseWheelMask       = 0x400,
                       MouseButtonMask      = 0x800,
                       ControllerAxisMask   = 0x1000,
                       ControllerButtonMask = 0x2000;

            atFixedArray_sIconData_4 icons = default;
            uint parameter = (uint)key;
            uint source    = (parameter & MouseAxisMask) != 0 ? IOMS_MOUSE_ABSOLUTEAXIS :
                             (parameter & MouseWheelMask) != 0 ? IOMS_MOUSE_WHEEL :
                             (parameter & MouseButtonMask) != 0 ? IOMS_MOUSE_BUTTON :
                             (parameter & ControllerAxisMask) != 0 ? IOMS_PAD_AXIS :
                             (parameter & ControllerButtonMask) != 0 ? IOMS_PAD_DIGITALBUTTON :
                             IOMS_KEYBOARD;

            if (source == IOMS_PAD_DIGITALBUTTON)
            {
                parameter = 1u << (int)(parameter & 0xFFu);
            }

            CTextFormat.GetInputSourceIcons(source, parameter, ref icons);

            const int BufferSize = 64;
            byte *    buffer     = stackalloc byte[BufferSize];

            CTextFormat.GetIconListFormatString(ref icons, buffer, BufferSize);

            return(Encoding.UTF8.GetString(buffer, Memory.StrLen(buffer)));
        }