Exemplo n.º 1
0
        public CustomBirdTutorial(EntityData data, Vector2 offset)
            : base(data, offset)
        {
            BirdId   = data.Attr("birdId");
            onlyOnce = data.Bool("onlyOnce");
            caw      = data.Bool("caw");
            Facing   = data.Bool("faceLeft") ? Facings.Left : Facings.Right;

            // apply the facing immediately
            Sprite.Scale.X = (float)Facing;

            object info;

            object[] controls;

            // parse the info ("title")
            string infoString = data.Attr("info");

            if (GFX.Gui.Has(infoString))
            {
                info = GFX.Gui[infoString];
            }
            else
            {
                info = Dialog.Clean(infoString);
            }

            int extraAdvance = 0;

            // go ahead and parse the controls. Controls can be textures, VirtualButtons, directions or strings.
            string[] controlsStrings = data.Attr("controls").Split(',');
            controls = new object[controlsStrings.Length];
            for (int i = 0; i < controls.Length; i++)
            {
                string controlString = controlsStrings[i];

                object modCommand = Everest.Events.CustomBirdTutorial.ParseCommand(controlString);
                if (modCommand is ButtonBinding binding)
                {
                    // convert ButtonBinding to VirtualButton for convenience.
                    modCommand = binding.Button;
                }

                if (modCommand != null)
                {
                    // this is a command a mod registered.
                    controls[i] = modCommand;
                }
                else if (controlString.StartsWith("mod:"))
                {
                    // formatted like `mod:MaxHelpingHand/ShowHints`
                    string[]      autoBinding = controlString.Substring(4).Split('/');
                    EverestModule module      = Everest.Modules.FirstOrDefault(m => m.Metadata.Name == autoBinding[0]);
                    if (module?.SettingsType != null)
                    {
                        PropertyInfo  matchingInput = module.SettingsType.GetProperty(autoBinding[1]);
                        ButtonBinding val           = matchingInput?.GetGetMethod()?.Invoke(module._Settings, null) as ButtonBinding;
                        if (val?.Button != null)
                        {
                            controls[i] = val.Button;
                        }
                        else
                        {
                            Logger.Log(LogLevel.Warn, "CustomBird", $"Public ButtonBinding property not found in {module.SettingsType}. ControlString: {controlString}");
                        }
                    }
                    else
                    {
                        Logger.Log(LogLevel.Warn, "CustomBird", "EverestModule or EverestModule.SettingsType not found. ControlString: " + controlString);
                    }
                }
                else if (GFX.Gui.Has(controlString))
                {
                    // this is a texture.
                    controls[i] = GFX.Gui[controlString];
                }
                else if (directions.ContainsKey(controlString))
                {
                    // this is a direction.
                    controls[i] = directions[controlString];
                }
                else
                {
                    FieldInfo matchingInput = typeof(Input).GetField(controlString, BindingFlags.Static | BindingFlags.Public);
                    if (matchingInput?.GetValue(null)?.GetType() == typeof(VirtualButton))
                    {
                        // this is a button.
                        controls[i] = matchingInput.GetValue(null);
                    }
                    else
                    {
                        if (controlString.StartsWith("dialog:"))
                        {
                            // treat that as a dialog key.
                            controls[i] = Dialog.Clean(controlString.Substring("dialog:".Length));
                        }
                        else
                        {
                            // treat that as a plain string.
                            controls[i] = controlString;
                        }
                    }
                }

                if (controls[i] is string)
                {
                    // when BirdTutorialGui renders text, it is offset by 1px on the right.
                    // width computation doesn't take this 1px into account, so we should add it back in.
                    extraAdvance++;
                    if (i == 0)
                    {
                        // as the text is rendered 1px to the right, if the first thing is a string, there will be 1px more padding on the left.
                        // we should add that extra px on the right as well.
                        extraAdvance++;
                    }
                }
            }

            gui = new BirdTutorialGui(this, new Vector2(0f, -16f), info, controls);

            DynData <BirdTutorialGui> guiData = new DynData <BirdTutorialGui>(gui);

            // if there is no first line, resize the bubble accordingly.
            if (string.IsNullOrEmpty(infoString))
            {
                guiData["infoHeight"] = 0f;
            }
            // apply the extra width.
            guiData["controlsWidth"] = guiData.Get <float>("controlsWidth") + extraAdvance;
        }
Exemplo n.º 2
0
        public static void CreateMenu(EverestModule self, TextMenu menu, bool inGame, FMOD.Studio.EventInstance snapshot)
        {
            menu.Add(new TextMenu.OnOff("Enabled", Settings.Enabled).Change((b) => {
                Settings.Enabled = b;
                foreach (TextMenu.Item item in normalOptions)
                {
                    item.Visible = b;
                }
                keyConfigMenu.Visible       = b;
                moreOptionsTextMenu.Visible = b;
                foreach (TextMenu.Item item in hiddenOptions)
                {
                    item.Visible = false;
                }

                if (!b && Settings.ShowHitboxes)
                {
                    ((TextMenu.OnOff)normalOptions.First()).LeftPressed();
                }
            }));

            CreateNormalOptions(menu, inGame);
            foreach (TextMenu.Item item in normalOptions)
            {
                menu.Add(item);
                item.Visible = Settings.Enabled;
            }

            keyConfigMenu = new TextMenu.Button(Dialog.Clean("options_keyconfig")).Pressed(() => {
                menu.Focused = false;
                Engine.Scene.Add(new ModuleSettingsKeyboardConfigUI(self)
                {
                    OnClose = () => menu.Focused = true
                });
                Engine.Scene.OnEndOfFrame += () => Engine.Scene.Entities.UpdateLists();
            });

            moreOptionsTextMenu = new TextMenu.Button("modoptions_celestetas_moreoptions".DialogCleanOrNull() ?? "More Options").Pressed(() => {
                ToggleMoreOptionsMenuItem(menu, true);
                moreOptionsTextMenu.Visible = false;
                menu.Selection += 1;
            });

            menu.Add(keyConfigMenu);
            menu.Add(moreOptionsTextMenu);
            keyConfigMenu.Visible       = Settings.Enabled;
            moreOptionsTextMenu.Visible = Settings.Enabled;

            CreateHiddenOptions(menu, inGame);
            foreach (TextMenu.Item item in hiddenOptions)
            {
                menu.Add(item);
                item.Visible = false;
            }

            menu.Add(new TextMenu.Button("modoptions_celestetas_reload".DialogCleanOrNull() ?? "Reload Settings")
                     .Pressed(() => {
                CelesteTASModule.Instance.LoadSettings();
                Hotkeys.instance.OnInputInitialize();
            }));
        }