Esempio n. 1
0
 void Awake()
 {
     DontDestroyOnLoad(this.gameObject);
     myTM = GameObject.Find("Canvas").GetComponent <TitleMenu>();
     SceneManager.sceneLoaded += newSceneLoaded;
     assignControlIO(controlSchemes.joinIO);
 }
        public static void onUpdate(object sender, EventArgs args)
        {
            try
            {
                if (Multiplayer.mode != Mode.Singleplayer)
                {
                    Multiplayer.update();
                }

                // We need our load menu to be able to do things
                if (Game1.activeClickableMenu is TitleMenu)
                {
                    TitleMenu title = (TitleMenu)Game1.activeClickableMenu;
                    if (DEBUG)
                    {
                        Util.SetInstanceField(typeof(TitleMenu), title, "chuckleFishTimer", 0);
                        Util.SetInstanceField(typeof(TitleMenu), title, "logoFadeTimer", 0);
                        Util.SetInstanceField(typeof(TitleMenu), title, "fadeFromWhiteTimer", 0);
                    }

                    IClickableMenu submenu = (IClickableMenu)Util.GetInstanceField(typeof(TitleMenu), title, "subMenu");
                    if (submenu != null && submenu.GetType() == typeof(LoadGameMenu))
                    {
                        Util.SetInstanceField(typeof(TitleMenu), title, "subMenu", new NewLoadMenu());
                    }
                }
                prevMenu = Game1.activeClickableMenu;
            }
            catch (Exception e)
            {
                Log.Async("Exception during update: " + e);
            }
        }
Esempio n. 3
0
        /****
        ** Methods
        ****/
        /// <summary>Skip the intro if the game is ready.</summary>
        /// <param name="menu">The title menu whose intro to skip.</param>
        /// <returns>Returns whether the intro was skipped successfully.</returns>
        private bool TrySkipIntro(TitleMenu menu)
        {
            // wait until the game is ready
            if (Game1.currentGameTime == null)
            {
                return(false);
            }

            // skip to title screen
            menu.receiveKeyPress(Keys.Escape);
            menu.update(Game1.currentGameTime);

            // skip button transition
            if (!this.Config.SkipToLoadScreen)
            {
                while (this.Helper.Reflection.GetPrivateValue <int>(menu, "buttonsToShow") < TitleMenu.numberOfButtons)
                {
                    menu.update(Game1.currentGameTime);
                }
            }

            // skip to load screen
            if (this.Config.SkipToLoadScreen)
            {
                menu.performButtonAction("Load");
                while (TitleMenu.subMenu == null)
                {
                    menu.update(Game1.currentGameTime);
                }
            }

            return(true);
        }
Esempio n. 4
0
 /// <summary>
 /// 初期化
 /// </summary>
 void IScene.Initialize()
 {
     ManualCanvas.Instance.Initialize();
     titleMenu = UnityEngine.GameObject.FindObjectOfType <TitleMenu>();
     titleMenu.Initialize();
     AudioManager.Instance.FadeIn((int)SceneController.Instance.FadeTime);
     AudioManager.Instance.Play(AudioManager.BGM.Title);
 }
Esempio n. 5
0
 public TitleScreen(GraphicsDevice graphicsDevice, Game game) : base(graphicsDevice, game)
 {
     base.game           = game;
     base.graphicsDevice = graphicsDevice;
     menu            = new TitleMenu(base.graphicsDevice, base.game);
     backgroundImage = new Basic2D("Game/BackgroundImage", new Vector2(GameStateManager.Instance.Dimensions.X / 2, GameStateManager.Instance.Dimensions.Y / 2), GameStateManager.Instance.Dimensions);
     creditsText     = new Text2D(new Vector2(225, 850), "Created by\nJakub Olech", "TitleScreen/CreditsFont", Color.Black);
 }
Esempio n. 6
0
        public override void UnloadContent()
        {
            base.UnloadContent();

            if (TitleMenu != null)
            {
                TitleMenu.UnloadContent();
            }
        }
Esempio n. 7
0
        public override void Draw(SpriteBatch spriteBatch)
        {
            base.Draw(spriteBatch);

            if (TitleMenu != null && TitleMenu.Buttons.Any())
            {
                TitleMenu.Draw(spriteBatch);
            }
        }
Esempio n. 8
0
        /// <summary>Perform any logic needed on update while the animation is active.</summary>
        /// <param name="playerAnimationID">The player's current animation ID.</param>
        public override void Update(int playerAnimationID)
        {
            TitleMenu titleMenu    = (TitleMenu)Game1.activeClickableMenu;
            var       isTransition = this.GetIsTransitionField(titleMenu);

            this.ApplySkips(
                run: () => titleMenu.update(Game1.currentGameTime),
                until: () => !isTransition.GetValue()
                );
        }
        /// <summary>Perform any logic needed on update while the animation is active.</summary>
        /// <param name="playerAnimationID">The player's current animation ID.</param>
        public override void Update(int playerAnimationID)
        {
            TitleMenu titleMenu    = (TitleMenu)Game1.activeClickableMenu;
            var       isTransition = this.GetIsTransitionField(titleMenu);

            for (int i = 1; i < this.Multiplier && isTransition.GetValue(); i++)
            {
                titleMenu.update(Game1.currentGameTime);
            }
        }
Esempio n. 10
0
        public static bool Prefix(TitleMenu __instance)
        {
            if (__instance == Game1.activeClickableMenu)
            {
                var o = new ShouldOverrideClick();
                PerformLeftClick?.Invoke(o);

                return(!o.Override);
            }
            return(true);
        }
Esempio n. 11
0
        public void OnModMenuItemClicked(TitleMenu menu, string choice)
        {
            if (choice != "MenuTest")
            {
                return;
            }

            menu.StartMenuTransitioning();
            Game1.playSound("select");
            menu.SetSubmenu(Example);
        }
Esempio n. 12
0
        public MenuScene(IContentChest contentChest, IViewPortManager viewPortManager,
                         CharacterCreationMenu characterCreationMenu,
                         TitleMenu mainTitleMenu, MainOptionsMenu mainOptionsMenu)
        {
            _contentChest          = contentChest;
            _viewPortManager       = viewPortManager;
            _characterCreationMenu = characterCreationMenu;
            _mainTitleMenu         = mainTitleMenu;
            _mainOptionsMenu       = mainOptionsMenu;

            _activeMenu = _mainTitleMenu;
        }
        public AccessLanguageMenu(LanguageSelectionMenu menu, TitleMenu titleMenu) : base(menu)
        {
            foreach (ClickableComponent comp in menu.languages)
            {
                AddItem(MenuItem.MenuItemFromComponent(comp, menu));
            }
            MenuItem menuItem = MenuItem.MenuItemFromComponent(titleMenu.backButton, StardewValley.Game1.activeClickableMenu);

            menuItem.Label        = "back to title";
            menuItem.TextOnAction = AccessTitleMenu.Title();
            AddItem(menuItem);
        }
Esempio n. 14
0
        /// <summary>
        /// Replaces the title screen graphics
        /// </summary>
        /// <param name="titleMenu">The title menu - passed if we're already on the title screen</param>
        private void ReplaceTitleScreen(TitleMenu titleMenu = null)
        {
            _currentLocale = _mod.Helper.Translation.Locale;
            AddReplacement("Minigames/TitleButtons", $"Assets/Minigames/{Globals.GetTranslation("title-graphic")}");
            _mod.Helper.Content.InvalidateCache("Minigames/TitleButtons");

            if (titleMenu != null)
            {
                LanguageCode code = _mod.Helper.Translation.LocaleEnum;
                _mod.Helper.Reflection.GetMethod(titleMenu, "OnLanguageChange", true).Invoke(code);
            }
        }
Esempio n. 15
0
        /****
        ** Methods
        ****/
        /// <summary>Skip the intro if the game is ready.</summary>
        /// <param name="menu">The title menu whose intro to skip.</param>
        /// <returns>Returns whether the intro was skipped successfully.</returns>
        private bool TrySkipIntro(TitleMenu menu)
        {
            // wait until the game is ready
            if (Game1.currentGameTime == null)
            {
                return(false);
            }

            // skip to title screen
            menu.receiveKeyPress(Keys.Escape);
            menu.update(Game1.currentGameTime);

            // skip to other screen
            switch (this.Config.SkipTo)
            {
            case Screen.Title:
                // skip button transition
                while (this.Helper.Reflection.GetField <int>(menu, "buttonsToShow").GetValue() < TitleMenu.numberOfButtons)
                {
                    menu.update(Game1.currentGameTime);
                }
                break;

            case Screen.Load:
                // skip to load screen
                menu.performButtonAction("Load");
                while (TitleMenu.subMenu == null)
                {
                    menu.update(Game1.currentGameTime);
                }
                break;

            case Screen.JoinCoop:
            case Screen.HostCoop:
                // skip to co-op screen
                menu.performButtonAction("Co-op");
                while (TitleMenu.subMenu == null)
                {
                    menu.update(Game1.currentGameTime);
                }

                // skip to host tab
                if (this.Config.SkipTo == Screen.HostCoop && TitleMenu.subMenu is CoopMenu submenu)
                {
                    ClickableComponent hostTab = submenu.hostTab;
                    submenu.receiveLeftClick(hostTab.bounds.X, hostTab.bounds.Y, playSound: false);
                }
                break;
            }

            return(true);
        }
Esempio n. 16
0
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            if (TitleMenu != null && TitleMenu.Buttons.Any())
            {
                foreach (var button in TitleMenu.Buttons)
                {
                    var collRec = new Rectangle((int)button.PositionUpLeft.X - (int)button.Center.X,
                                                (int)button.PositionUpLeft.Y - (int)button.Center.Y,
                                                button.CollisionRectangle.Width, button.CollisionRectangle.Height);
                    if (collRec.Contains(InputManager.Instance.MousePosition()))//we have at least hover
                    {
                        //Transform
                        if (InputManager.Instance.MouseLeftBtnClicked())
                        {
                            switch (button.LinkTo.ToLower())
                            {
                            case "screen":
                            {
                                IsTransitioning = true;
                                NextScreen      = button.LinkName;
                                //ScreenManager.Instance.SwitchScreens(NextScreen);
                            }
                            break;

                            //case "menu":
                            //    //TODO
                            //    break;
                            default: break;
                            }
                        }
                    }

                    TitleMenu.Update(gameTime);
                }

                if (IsTransitioning)
                {
                    Transition(gameTime);
                }
            }
        }
Esempio n. 17
0
 /// <summary>Receives an update tick.</summary>
 /// <param name="sender">The event sender.</param>
 /// <param name="e">The event arguments.</param>
 private void ReceiveUpdateTick(object sender, EventArgs e)
 {
     try
     {
         TitleMenu menu = Game1.activeClickableMenu as TitleMenu;
         if (menu != null)
         {
             if (!this.ApplySkip(menu, this.Step))
             {
                 GameEvents.UpdateTick -= this.ReceiveUpdateTick;
             }
             this.Step++;
         }
     }
     catch (Exception ex)
     {
         this.Monitor.InterceptError(ex, $"skipping the menu (step {this.Step})");
         GameEvents.UpdateTick -= this.ReceiveUpdateTick;
     }
 }
Esempio n. 18
0
        /****
        ** Methods
        ****/
        /// <summary>Apply the next skip step.</summary>
        /// <param name="menu">The title menu to update.</param>
        /// <param name="step">The step to apply (starting at 0).</param>
        /// <returns>Returns whether there are more skip steps.</returns>
        /// <remarks>The skip logic is applied over several update ticks to let the game update itself smoothly. This prevents a few issues like a long pause before the game window opens, or the title menu not resizing itself for full-screen display.</remarks>
        private bool ApplySkip(TitleMenu menu, int step)
        {
            switch (step)
            {
            // skip to main menu
            case 1:
                menu.receiveKeyPress(Keys.Escape);
                return(true);

            // skip to loading screen
            case 2:
                if (this.Config.SkipToLoadScreen)
                {
                    menu.performButtonAction("Load");
                }
                return(true);

            default:
                return(false);
            }
        }
Esempio n. 19
0
        private void LeftClick(CoopMenu menu, int x, int y)
        {
            if (addServerButton != null && addServerButton.containsPoint(x, y))
            {
                Game1.playSound("bigDeSelect");

                Game1.activeClickableMenu = new TextMenu("Server name?", (serverName) =>
                {
                    Game1.activeClickableMenu = new TextMenu("IP address?", (ipAddress) =>
                    {
                        bookmarks.Bookmarks.Remove(serverName);
                        bookmarks.Bookmarks.Add(serverName, ipAddress);
                        writeData(bookmarks, "Bookmarks.json");

                        var title = new TitleMenu();
                        title.skipToTitleButtons();
                        TitleMenu.subMenu         = new CoopMenu();
                        Game1.activeClickableMenu = title;
                    });
                });
            }
        }
Esempio n. 20
0
        /// <summary>Receives an update tick.</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private void ReceiveUpdateTick(object sender, EventArgs e)
        {
            try
            {
                // get open title screen
                TitleMenu menu = Game1.activeClickableMenu as TitleMenu;
                if (menu == null)
                {
                    GameEvents.UpdateTick -= this.ReceiveUpdateTick;
                    return;
                }

                // skip intro
                if (this.TrySkipIntro(menu))
                {
                    GameEvents.UpdateTick -= this.ReceiveUpdateTick;
                }
            }
            catch (Exception ex)
            {
                this.Monitor.InterceptError(ex, "skipping the intro");
                GameEvents.UpdateTick -= this.ReceiveUpdateTick;
            }
        }
Esempio n. 21
0
        /// <summary>Skip the intro if the game is ready.</summary>
        /// <param name="menu">The title menu whose intro to skip.</param>
        /// <param name="currentStage">The current step in the mod logic.</param>
        /// <returns>Returns the next step in the skip logic.</returns>
        private Stage Skip(TitleMenu menu, Stage currentStage)
        {
            // wait until the game is ready
            if (Game1.currentGameTime == null)
            {
                return(currentStage);
            }

            // do nothing if a confirmation box is on-screen (e.g. multiplayer disconnect error)
            if (TitleMenu.subMenu is ConfirmationDialog)
            {
                return(Stage.None);
            }

            // apply skip step
            return(currentStage switch
            {
                Stage.SkipIntro => this.SkipToTitle(menu),
                Stage.TransitionToLoad => this.TransitionToLoad(menu),
                Stage.StartTransitionToCoop => this.StartTransitionToCoop(menu),
                Stage.TransitionToCoop => this.TransitionToCoop(menu),
                Stage.TransitionToCoopHost => this.TransitionToCoopHost(),
                _ => Stage.None
            });
Esempio n. 22
0
 public void Awake()
 {
     instance = this;
     titleWindow.UpdateLoadButton();
 }
Esempio n. 23
0
        internal static void SkipIntroUpdateTicked()
        {
            // start intro skip on game launch
            if (Current == Step.Launching)
            {
                // wait until the game is ready
                if (Game1.activeClickableMenu is TitleMenu title && Game1.currentGameTime != null)
                {
                    int[] win = ModMain.Config.TitleWindow;
                    // set title screen resolution
                    if (win.Length >= 2 && win[0] > 1024 && win[1] > 768)
                    {
                        Game1.graphics.PreferredBackBufferWidth  = win[0];
                        Game1.graphics.PreferredBackBufferHeight = win[1];
                        Game1.graphics.ApplyChanges();
                        Game1.updateViewportForScreenSizeChange(false, win[0], win[1]);
                    }
                    // set title window position
                    if (win.Length >= 4 && win[2] > 0 && win[3] > 0)
                    {
                        var form = System.Windows.Forms.Control.FromHandle(Program.gamePtr.Window.Handle).FindForm();
                        form.Location = new System.Drawing.Point(win[2], win[3]);
                    }

                    // Don't pause on focus loss until game is fully loaded.
                    Game1.options.pauseWhenOutOfFocus = false;

                    title.skipToTitleButtons();  // skip intro
                    Current = Step.Skipping;
                }
                return;
            }
            else if (Current == Step.Skipping)
            {
                TitleMenu title = (TitleMenu)Game1.activeClickableMenu;

                // skip to other screen
                if (SkipTo == Screen.Title)
                {
                    // skip button transition
                    while (ModMain.Reflection.GetField <int>(title, "buttonsToShow").GetValue() < TitleMenu.numberOfButtons)
                    {
                        title.update(Game1.currentGameTime);
                    }
                }
                else if (SkipTo == Screen.Load)
                {
                    // skip to load screen
                    title.performButtonAction("Load");
                    while (TitleMenu.subMenu == null)
                    {
                        title.update(Game1.currentGameTime);
                    }
                }
                else if (SkipTo == Screen.Join || SkipTo == Screen.Host)
                {
                    // skip to co-op screen
                    title.performButtonAction("Co-op");
                    while (TitleMenu.subMenu == null)
                    {
                        title.update(Game1.currentGameTime);
                    }

                    if (SkipTo == Screen.Host)
                    {
                        Current = Step.Waiting;
                        return;
                    }
                }
                else if (SkipTo == Screen.AutoLoad || SkipTo == Screen.AutoHost)
                {
                    string lastLoaded = ModMain.Config.LastLoadedSave;      // recall last saved name

                    if (!String.IsNullOrEmpty(lastLoaded) && Directory.Exists(Path.Combine(Constants.SavesPath, lastLoaded)))
                    {
                        title.update(Game1.currentGameTime);

                        if (SkipTo == Screen.AutoHost)
                        {
                            Game1.multiplayerMode = 2;  // server mode
                        }
                        Game1.activeClickableMenu = new AutoLoader(lastLoaded);
                    }
                }
            }
            else if (Current == Step.Waiting)
            {
                // do nothing if a confirmation box is on-screen (e.g. multiplayer disconnect error)
                if (!(TitleMenu.subMenu is ConfirmationDialog) &&
                    (SkipTo == Screen.Host && TitleMenu.subMenu is CoopMenu submenu))
                {
                    if (submenu.hostTab == null) // select host tab
                    {
                        return;                  // not connected yet
                    }
                    submenu.receiveLeftClick(submenu.hostTab.bounds.X, submenu.hostTab.bounds.Y, playSound: false);
                }
            }

            Current = Step.Done;
        }
Esempio n. 24
0
        /// <summary>Skip the intro if the game is ready.</summary>
        /// <param name="menu">The title menu whose intro to skip.</param>
        /// <param name="currentStage">The current step in the mod logic.</param>
        /// <returns>Returns the next step in the skip logic.</returns>
        private Stage Skip(TitleMenu menu, Stage currentStage)
        {
            // wait until the game is ready
            if (Game1.currentGameTime == null)
            {
                return(currentStage);
            }

            // do nothing if a confirmation box is on-screen (e.g. multiplayer disconnect error)
            if (TitleMenu.subMenu is ConfirmationDialog)
            {
                return(Stage.None);
            }

            // main skip logic
            if (currentStage == Stage.SkipIntro)
            {
                if (Constants.TargetPlatform == GamePlatform.Android)
                {
                    // skip to title screen
                    menu.skipToTitleButtons();

                    // skip button transition
                    while (this.Helper.Reflection.GetField <bool>(menu, "isTransitioningButtons").GetValue())
                    {
                        menu.update(Game1.currentGameTime);
                    }
                }
                else
                {
                    // skip to title screen
                    menu.receiveKeyPress(Keys.Escape);
                    menu.update(Game1.currentGameTime);

                    // skip button transition
                    while (this.Helper.Reflection.GetField <int>(menu, "buttonsToShow").GetValue() < TitleMenu.numberOfButtons)
                    {
                        menu.update(Game1.currentGameTime);
                    }
                }

                // skip to next screen
                switch (this.Config.SkipTo)
                {
                case Screen.Title:
                    return(Stage.None);

                case Screen.Load:
                    // skip to load screen
                    menu.performButtonAction("Load");
                    while (TitleMenu.subMenu == null)
                    {
                        menu.update(Game1.currentGameTime);
                    }
                    return(Stage.None);

                case Screen.JoinCoop:
                case Screen.HostCoop:
                    // skip to co-op screen
                    menu.performButtonAction("Co-op");
                    while (TitleMenu.subMenu == null)
                    {
                        menu.update(Game1.currentGameTime);
                    }

                    return(this.Config.SkipTo == Screen.JoinCoop
                            ? Stage.None
                            : Stage.WaitingForConnection);
                }
            }

            // skip to host tab after connection is established
            if (currentStage == Stage.WaitingForConnection)
            {
                // not applicable
                if (this.Config.SkipTo != Screen.HostCoop || !(TitleMenu.subMenu is CoopMenu submenu))
                {
                    return(Stage.None);
                }

                // not connected yet
                if (submenu.hostTab == null)
                {
                    return(currentStage);
                }

                // select host tab
                submenu.receiveLeftClick(submenu.hostTab.bounds.X, submenu.hostTab.bounds.Y, playSound: false);
            }

            // ???
            return(Stage.None);
        }
        internal static void TitleMenuPatch(TitleMenu __instance, bool ___isTransitioningButtons)
        {
            try
            {
                if (___isTransitioningButtons)
                {
                    return;
                }

                string toSpeak = "";

                __instance.buttons.ForEach(component =>
                {
                    if (component.containsPoint(Game1.getMouseX(true), Game1.getMouseY(true)))
                    {
                        string name  = component.name;
                        string label = component.label;
                        toSpeak      = $"{name} {label} Button";
                    }
                });

                if (__instance.muteMusicButton.containsPoint(Game1.getMouseX(true), Game1.getMouseY(true)))
                {
                    toSpeak = "Mute Music Button";
                }

                if (__instance.aboutButton.containsPoint(Game1.getMouseX(true), Game1.getMouseY(true)))
                {
                    toSpeak = "About Button";
                }

                if (__instance.languageButton.containsPoint(Game1.getMouseX(true), Game1.getMouseY(true)))
                {
                    toSpeak = "Language Button";
                }

                if (__instance.windowedButton.containsPoint(Game1.getMouseX(true), Game1.getMouseY(true)))
                {
                    toSpeak = "Fullscreen: " + ((Game1.isFullscreen) ? "enabled" : "disabled");
                }

                if (TitleMenu.subMenu != null && __instance.backButton.containsPoint(Game1.getMouseX(true), Game1.getMouseY(true)))
                {
                    string text = "Back Button";
                    MainClass.ScreenReader.SayWithChecker(text, true);
                }

                // Fix for back button not working using keyboard
                if (TitleMenu.subMenu is CharacterCustomization && ((CharacterCustomization)TitleMenu.subMenu).backButton.containsPoint(Game1.getMouseX(true), Game1.getMouseY(true)))
                {
                    // Perform Left Click
                    if (MainClass.Config.LeftClickMainKey.JustPressed())
                    {
                        __instance.backButtonPressed();
                    }
                }

                if (TitleMenu.subMenu == null && toSpeak != "")
                {
                    MainClass.ScreenReader.SayWithChecker(toSpeak, true);
                }
            }
            catch (Exception e)
            {
                MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}");
            }
        }
 /*********
 ** Private methods
 *********/
 /// <summary>Get the private title menu field which indicates whether it's currently transitioning.</summary>
 /// <param name="menu">The title menu.</param>
 private IReflectedField <bool> GetIsTransitionField(TitleMenu menu)
 {
     return(this.Reflection.GetField <bool>(menu, "isTransitioningButtons"));
 }
Esempio n. 27
0
 void Awake()
 {
     DontDestroyOnLoad(this.gameObject);
     myTM = GameObject.Find("Canvas").GetComponent <TitleMenu>();
 }
Esempio n. 28
0
        async Task DelayForLobbyData(CSteamID steamID, GalaxyID galaxyID, int serverI, Func <CSteamID, BrowserSlot> getServerSlot, Action <CSteamID> removeSlot)
        {
            var mm = GalaxyInstance.Matchmaking();

            BrowserSlot slot = null;

            for (int i = 0; i < 20; i++)
            {
                slot = getServerSlot(steamID);
                if (slot == null)
                {
                    await Task.Delay(500);
                }
                else
                {
                    Console.WriteLine("Got slot ID");
                    break;
                }
            }

            if (slot == null)
            {
                Console.WriteLine($"Failed to find slot for {steamID}");
                return;
            }

            for (int i = 0; i < 10; i++)
            {
                string getData(string key) => mm.GetLobbyData(galaxyID, key);

                string farmName = getData("farmName");

                if (string.IsNullOrEmpty(farmName))
                {
                    Console.WriteLine($"Get lobby data fail number {i}");
                    await Task.Delay(1000);

                    continue;
                }

                string serverMessage        = getData("serverMessage");
                string numberOfPlayers      = getData("numberOfPlayers");
                string numberOfPlayerSlots  = getData("numberOfPlayerSlots");
                string freeCabins           = getData("freeCabins");
                string requiredMods         = getData("requiredMods");
                string serversInstalledMods = getData("serverMods");
                string password             = getData("password");

                string passwordYesNo = string.IsNullOrEmpty(password) ? "No" : "Yes";
                Monitor.Log($"Server {serverI} - '{farmName}'\nPlayers online = {numberOfPlayers}. Total slots = {numberOfPlayerSlots}. Empty cabins = {freeCabins}.\nPassword protected = {passwordYesNo}.\nRequired mods = {requiredMods}\nServer's installed mods = {serversInstalledMods}\n\nServer message:\n{serverMessage}\n", LogLevel.Info);

                slot.FarmName          = farmName;
                slot.ServerDescription = serverMessage;
                int intPlayersOnline = int.TryParse(numberOfPlayers, out int x) ? x : -1;
                slot.PlayersOnline = intPlayersOnline;
                int intPlayerSlots = int.TryParse(numberOfPlayerSlots, out int y) ? y : -1;
                slot.PlayerSlots          = intPlayerSlots;
                slot.CabinCountText       = freeCabins;
                slot.ShowPasswordLockIcon = !string.IsNullOrEmpty(password);

                var sq = SearchOptions.SearchQuery.ToLower();

                if (
                    (!SearchOptions.ShowPasswordProtectedSerers && !string.IsNullOrEmpty(password))
                    ||
                    (!SearchOptions.ShowFullServers && intPlayersOnline == intPlayerSlots)
                    ||
                    (!SearchOptions.ShowFullCabinServers && freeCabins == "0" || freeCabins == "-1")
                    ||
                    (!string.IsNullOrWhiteSpace(sq) && !farmName.ToLower().Contains(sq) && !serverMessage.Contains(sq))
                    )
                {
                    removeSlot(steamID);
                    return;
                }

                slot.CallBack = delegate
                {
                    var browswer = Game1.activeClickableMenu;

                    Game1.activeClickableMenu = new ServerPage(25, 25, Game1.viewport.Width - 25 * 2, Game1.viewport.Height - 25 * 2, requiredMods, serversInstalledMods, delegate
                    {
                        var browser = Game1.activeClickableMenu;

                        void connect()
                        {
                            Console.WriteLine($"Connecting to steam server {steamID}");

                            //JoinLobby only works if you are at the title screen
                            var title = new TitleMenu();
                            title.skipToTitleButtons();
                            Game1.activeClickableMenu = title;

                            try
                            {
                                SteamMatchmaking.JoinLobby(steamID);
                                lastLobbyJoined = steamID;
                            }
                            catch (Exception e)
                            {
                                Monitor.Log("Error while connecting to server: " + e.Message, LogLevel.Error);
                            }
                        }

                        if (!string.IsNullOrEmpty(password))
                        {
                            Console.WriteLine("Showing password box");
                            Game1.activeClickableMenu = new TextMenu("Please enter this server's password", true, (passwordInput) =>
                            {
                                if (password != passwordInput)
                                {
                                    Console.WriteLine("Entered wrong password");
                                    Game1.activeClickableMenu = browser;
                                    return;
                                }
                                else
                                {
                                    connect();
                                }
                            }, () => Game1.activeClickableMenu = browser);
                        }
                        else
                        {
                            connect();
                        }
                    },
Esempio n. 29
0
        private void OnReceiveSteamServers(LobbyMatchList_t x, bool bIOFailure)
        {
            if (bIOFailure)
            {
                Monitor.Log("IO Failure!", LogLevel.Error);
                return;
            }

            Console.WriteLine($"STEAM RECEIVE SERVER LIST, COUNT={x.m_nLobbiesMatching}");

            if (lastLobbyJoined.m_SteamID != 0)
            {
                Console.WriteLine("Disconnecting from last joined lobby");

                try
                {
                    GalaxyInstance.Matchmaking().LeaveLobby(GalaxyIDFromSteamID(lastLobbyJoined));
                }
                catch (Exception)
                {
                    Console.WriteLine("  was not connected to any lobby");
                }
            }

            List <CSteamID> servers = new List <CSteamID>();

            BrowserMenu browser = null;

            int serverI = 0;

            while (true)
            {
                CSteamID steamID = SteamMatchmaking.GetLobbyByIndex(serverI);
                if (!steamID.IsValid() || steamID.m_SteamID == 0)
                {
                    break;
                }

                Console.WriteLine($"DISCOVERED SERVERID={steamID.m_SteamID}");

                var galaxyID = GalaxyIDFromSteamID(steamID);

                Console.WriteLine($"Received galaxy ID = {galaxyID?.ToString() ?? "NULL"}");

                if (galaxyID != null)
                {
                    servers.Add(steamID);

                    var mm = GalaxyInstance.Matchmaking();

                    var unkown = mm.RequestLobbyData(galaxyID);
                    Console.WriteLine($"Request lobby data output = {unkown}");

                    Task task = DelayForLobbyData(steamID, galaxyID, serverI, id => browser?.GetSlot(id), id => browser?.RemoveSlot(id));
                }

                serverI++;
            }
            if (servers.Count == 0)
            {
                Monitor.Log("Couldn't find any servers!", LogLevel.Info);
            }

            var blankTitle = new TitleMenu();

            blankTitle.skipToTitleButtons();
            TitleMenu.subMenu = new CoopMenu();

            //Game1.viewport.Height - 50 * 2
            browser = new BrowserMenu(25, 25, Game1.viewport.Width - 25 * 2, Game1.viewport.Height, servers, blankTitle);
            Game1.activeClickableMenu = browser;
        }
 private void Awake()
 {
     Instance = this;
     TitleMenu.Show();
 }