Exemple #1
0
        private static void CreateBooleanControl(DisplayNameAttribute control, DescriptionAttribute descriptionAttr, PropertyInfo prop, Vector2 anchorPosition, RectTransform container)
        {
            RectTransform element = Object.Instantiate(checkboxTemplate, container, false);

            SetupUIElement(element, control, descriptionAttr, prop, anchorPosition);
            UIToggle toggle = element.GetComponentInChildren <UIToggle>();

            toggle.toggle.onValueChanged.RemoveAllListeners();
            toggle.toggle.onValueChanged.AddListener((value) => {
                // lock soil setting while in multiplayer game
                if (control.DisplayName == "Sync Soil" && Multiplayer.IsActive)
                {
                    // reset to saved value if needed
                    if (value != (bool)prop.GetValue(tempMultiplayerOptions, null))
                    {
                        toggle.isOn = !value;
                        InGamePopup.ShowInfo("Info", "This setting can only be changed while not in game", "Okay");
                    }
                    return;
                }
                prop.SetValue(tempMultiplayerOptions, value, null);
            });

            tempToUICallbacks[prop.Name] = () =>
            {
                toggle.isOn = (bool)prop.GetValue(tempMultiplayerOptions, null);
            };
        }
Exemple #2
0
        public override void ProcessPacket(HandshakeResponse packet, NebulaConnection conn)
        {
            using (BinaryUtils.Reader p = new BinaryUtils.Reader(packet.ModsSettings))
            {
                for (int i = 0; i < packet.ModsSettingsCount; i++)
                {
                    string     guid = p.BinaryReader.ReadString();
                    PluginInfo info = Chainloader.PluginInfos[guid];
                    if (info.Instance is IMultiplayerModWithSettings mod)
                    {
                        mod.Import(p.BinaryReader);
                    }
                }
            }

            // overwrite local setting with host setting, but dont save it as its a temp setting for this session
            Config.Options.SyncSoil = packet.SyncSoil;

            ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost = false;
            ((LocalPlayer)Multiplayer.Session.LocalPlayer).SetPlayerData(packet.LocalPlayerData, packet.IsNewPlayer);

            Multiplayer.Session.IsInLobby      = false;
            Multiplayer.ShouldReturnToJoinMenu = false;

            GameDesc gameDesc = new GameDesc();

            gameDesc.SetForNewGame(packet.AlgoVersion, packet.GalaxySeed, packet.StarCount, 1, packet.ResourceMultiplier);
            DSPGame.StartGameSkipPrologue(gameDesc);

            InGamePopup.ShowInfo("Loading", "Loading state from server, please wait", null);
        }
Exemple #3
0
 public static bool StarmapChangingToMilkyWay_Prefix(UIGame __instance)
 {
     if (Multiplayer.IsActive)
     {
         InGamePopup.ShowInfo("Access Denied", "Milky Way is disabled in multiplayer game.", "OK");
         return(false);
     }
     return(true);
 }
        public void ProcessPacket(HandshakeResponse packet, NebulaConnection conn)
        {
            GameDesc gameDesc = new GameDesc();

            gameDesc.SetForNewGame(packet.AlgoVersion, packet.GalaxySeed, packet.StarCount, 1, packet.ResourceMultiplier);
            DSPGame.StartGameSkipPrologue(gameDesc);

            LocalPlayer.IsMasterClient = false;
            LocalPlayer.SetPlayerData(packet.LocalPlayerData);

            InGamePopup.ShowInfo("Loading", "Loading state from server, please wait", null);
        }
 public static bool SetViewStar_Prefix(DESelection __instance, ref StarData starData)
 {
     if (Multiplayer.IsActive && Multiplayer.Session.LocalPlayer.IsClient)
     {
         //UIDysonEditor._OnOpen()
         if (!UIRoot.instance.uiGame.dysonEditor.sceneGroup.activeSelf)
         {
             //Request the latest list of existing dyson spheres
             Multiplayer.Session.Network.SendPacket(new DysonSphereLoadRequest(0, DysonSphereRequestEvent.List));
             if (GameMain.localStar == null)
             {
                 //In outer space, set initial viewStar to the one that has dyson sphere
                 for (int i = 0; i < GameMain.data.dysonSpheres.Length; i++)
                 {
                     if (GameMain.data.dysonSpheres[i] != null)
                     {
                         starData = GameMain.data.dysonSpheres[i].starData;
                         return(true);
                     }
                 }
                 //No dyson sphere exist, close the UI
                 UIRoot.instance.uiGame.dysonEditor._Close();
                 return(false);
             }
             else if (GameMain.data.dysonSpheres[starData.index] == null)
             {
                 //Local dyson sphere hasn't loaded yet, close the UI
                 UIRoot.instance.uiGame.dysonEditor._Close();
                 return(false);
             }
         }
         if (starData != null && GameMain.data.dysonSpheres[starData.index] == null)
         {
             if (Multiplayer.Session.DysonSpheres.RequestingIndex == -1)
             {
                 Multiplayer.Session.DysonSpheres.RequestDysonSphere(starData.index);
             }
             else
             {
                 InGamePopup.ShowInfo("Loading", $"Loading Dyson sphere {starData.displayName}, please wait...", null);
             }
             // Restore comboBox back to original star
             UIComboBox dysonBox = UIRoot.instance.uiGame.dysonEditor.controlPanel.topFunction.dysonBox;
             int        index    = dysonBox.ItemsData.FindIndex(x => x == UIRoot.instance.uiGame.dysonEditor.selection.viewStar?.index);
             dysonBox.itemIndex = index >= 0 ? index : 0;
             return(false);
         }
     }
     return(true);
 }
Exemple #6
0
        private static IEnumerator TryConnectToServer(string ip, int port)
        {
            InGamePopup.ShowInfo("Connecting", $"Connecting to server {ip}:{port}...", null, null);
            multiplayerMenu.gameObject.SetActive(false);

            // We need to wait here to have time to display the Connecting popup since the game freezes during the connection.
            yield return(new WaitForSeconds(0.5f));

            if (!ConnectToServer(ip, port))
            {
                InGamePopup.FadeOut();
                //re-enabling the menu again after failed connect attempt
                InGamePopup.ShowWarning("Connect failed", $"Was not able to connect to {hostIPAdressInput.text}", "OK");
                multiplayerMenu.gameObject.SetActive(true);
            }
            else
            {
                InGamePopup.FadeOut();
            }
        }
        public void ProcessPacket(HandshakeRequest packet, NebulaConnection conn)
        {
            Player player;

            if (!playerManager.PendingPlayers.TryGetValue(conn, out player))
            {
                conn.Disconnect();
                Log.Warn("WARNING: Player tried to handshake without being in the pending list");
                return;
            }

            playerManager.PendingPlayers.Remove(conn);

            if (packet.ProtocolVersion != 0) //TODO: Maybe have a shared constants file somewhere for this
            {
                conn.Disconnect();
            }

            //
            GameMain.Pause();
            InGamePopup.ShowInfo("Loading", "Player joining the game, please wait", null);

            // Make sure that each player that is currently in the game receives that a new player as join so they can create its RemotePlayerCharacter
            foreach (Player activePlayer in playerManager.GetConnectedPlayers())
            {
                activePlayer.SendPacket(new PlayerJoining(player.Data));
            }

            // Add the new player to the list
            playerManager.SyncingPlayers.Add(conn, player);

            // TODO: This should be our actual GameDesc and not an hardcoded value.
            var inGamePlayersIds = playerManager.GetAllPlayerIdsIncludingHost();

            var gameDesc = GameMain.data.gameDesc;

            player.SendPacket(new HandshakeResponse(gameDesc.galaxyAlgo, gameDesc.galaxySeed, gameDesc.starCount, gameDesc.resourceMultiplier, player.Data, inGamePlayersIds.ToArray()));

            SimulatedWorld.SpawnRemotePlayerModel(player.Data);
        }
Exemple #8
0
        public static void _OnOpen_Postfix(UIGalaxySelect __instance)
        {
            if (Multiplayer.IsActive && Multiplayer.Session.LocalPlayer.IsClient)
            {
                RectTransform galaxySelectRect = __instance.gameObject.GetComponent <RectTransform>();

                galaxySelectRect.Find("star-count").gameObject.SetActive(false);
                galaxySelectRect.Find("resource-multiplier").gameObject.SetActive(false);
                galaxySelectRect.Find("galaxy-seed").GetComponentInChildren <InputField>().enabled = false;
                galaxySelectRect.Find("random-button").gameObject.SetActive(false);
                galaxySelectRect.Find("property-multiplier").gameObject.SetActive(false);
                galaxySelectRect.Find("seed-key").gameObject.SetActive(false);
            }
            if (Multiplayer.IsActive)
            {
                // show lobby hints if needed
                if (Config.Options.ShowLobbyHints)
                {
                    InGamePopup.ShowInfo("The Lobby",
                                         "We changed the start of a new multiplayer game a bit and want to give you a quick overview of the new feature.\n\n" +
                                         "Clients can now join while the host is in the galaxy selection screen, and they will also land there if it is their first time connecting to the currently hosted save.\n\n" +
                                         "You can now click on any star to bring up the solar system preview. From there you can click on any planet to bring up its details.\n" +
                                         "Note that when using GalacticScale 2 this process can take a bit longer.\n\n" +
                                         "By clicking a planet while having its detail panel open you will set it as your birth planet.\n\n" +
                                         "By clicking into outer space you will go one detail level up.\n\n" +
                                         "We hope you enjoy this new feature!",
                                         "Okay, cool :)",
                                         CloseLobbyInfo);
                }
                // prepare PlanetModelingManager for the use of its compute thread as we need that for the planet details view in the lobby
                PlanetModelingManager.PrepareWorks();
                // store current star id because entering the solar system details view messes up the main menu background system.
                if (MainMenuStarID == -1)
                {
                    MainMenuStarID = GameMain.localStar.id;
                }
                Button button = GameObject.Find("UI Root/Overlay Canvas/Galaxy Select/start-button").GetComponent <Button>();
                button.interactable = true;
            }
        }
Exemple #9
0
        public void ProcessPacket(HandshakeResponse packet, NebulaConnection conn)
        {
            if (LocalPlayer.GS2_GSSettings != null && packet.CompressedGS2Settings.Length > 1) // if host does not use GS2 we send a null byte
            {
                LocalPlayer.GS2ApplySettings(packet.CompressedGS2Settings);
            }
            else if (LocalPlayer.GS2_GSSettings != null && packet.CompressedGS2Settings.Length == 1)
            {
                InGamePopup.ShowWarning("Galactic Scale - Server not supported", "The server does not seem to use Galactic Scale. Make sure that your mod configuration matches.", "Close");
                return;
            }

            GameDesc gameDesc = new GameDesc();

            gameDesc.SetForNewGame(packet.AlgoVersion, packet.GalaxySeed, packet.StarCount, 1, packet.ResourceMultiplier);
            DSPGame.StartGameSkipPrologue(gameDesc);

            LocalPlayer.IsMasterClient = false;
            LocalPlayer.SetPlayerData(packet.LocalPlayerData);

            InGamePopup.ShowInfo("Loading", "Loading state from server, please wait", null);
        }
 public void ProcessPacket(PlayerJoining packet, NebulaConnection conn)
 {
     SimulatedWorld.SpawnRemotePlayerModel(packet.PlayerData);
     GameMain.Pause();
     InGamePopup.ShowInfo("Loading", "Player joining the game, please wait", null);
 }
        public override void ProcessPacket(StartGameMessage packet, NebulaConnection conn)
        {
            if (IsHost)
            {
                if (Multiplayer.Session.IsGameLoaded && !GameMain.isFullscreenPaused)
                {
                    INebulaPlayer player;
                    using (playerManager.GetPendingPlayers(out Dictionary <INebulaConnection, INebulaPlayer> pendingPlayers))
                    {
                        if (!pendingPlayers.TryGetValue(conn, out player))
                        {
                            conn.Disconnect(DisconnectionReason.InvalidData);
                            Log.Warn("WARNING: Player tried to enter the game without being in the pending list");
                            return;
                        }

                        pendingPlayers.Remove(conn);
                    }

                    // Add the new player to the list
                    using (playerManager.GetSyncingPlayers(out Dictionary <INebulaConnection, INebulaPlayer> syncingPlayers))
                    {
                        syncingPlayers.Add(conn, player);
                    }

                    Multiplayer.Session.World.OnPlayerJoining(player.Data.Username);
                    NebulaModAPI.OnPlayerJoinedGame?.Invoke(player.Data);

                    // Make sure that each player that is currently in the game receives that a new player as join so they can create its RemotePlayerCharacter
                    PlayerJoining pdata = new PlayerJoining((PlayerData)player.Data.CreateCopyWithoutMechaData(), Multiplayer.Session.NumPlayers); // Remove inventory from mecha data
                    using (playerManager.GetConnectedPlayers(out Dictionary <INebulaConnection, INebulaPlayer> connectedPlayers))
                    {
                        foreach (KeyValuePair <INebulaConnection, INebulaPlayer> kvp in connectedPlayers)
                        {
                            kvp.Value.SendPacket(pdata);
                        }
                    }

                    //Add current tech bonuses to the connecting player based on the Host's mecha
                    ((MechaData)player.Data.Mecha).TechBonuses = new PlayerTechBonuses(GameMain.mainPlayer.mecha);

                    conn.SendPacket(new StartGameMessage(true, (PlayerData)player.Data, Config.Options.SyncSoil));
                }
                else
                {
                    conn.SendPacket(new StartGameMessage(false, null, false));
                }
            }
            else if (packet.IsAllowedToStart)
            {
                // overwrite local setting with host setting, but dont save it as its a temp setting for this session
                Config.Options.SyncSoil = packet.SyncSoil;

                ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost = false;
                ((LocalPlayer)Multiplayer.Session.LocalPlayer).SetPlayerData(packet.LocalPlayerData, true);

                UIRoot.instance.uiGame.planetDetail.gameObject.SetActive(false);
                Multiplayer.Session.IsInLobby      = false;
                Multiplayer.ShouldReturnToJoinMenu = false;

                DSPGame.StartGameSkipPrologue(UIRoot.instance.galaxySelect.gameDesc);

                InGamePopup.ShowInfo("Loading", "Loading state from server, please wait", null);
            }
            else
            {
                InGamePopup.ShowInfo("Please Wait", "The host is not ready to let you in, please wait!", "Okay");
            }
        }