public static bool ParseModFile(string modFileData)
        {
            if (SystemsContainer.Get <ModSystem>().ModControl == ModControlMode.Disabled)
            {
                return(true);
            }

            SystemsContainer.Get <ModSystem>().LastModFileData = modFileData; //Save mod file so we can recheck it.

            StringBuilder = new StringBuilder();
            ParseRequired.Clear();
            ParseOptional.Clear();
            WhiteList.Clear();
            BlackList.Clear();
            PartsList.Clear();

            SaveCurrentModConfigurationFile();

            ReadModConfigurationFile(modFileData);

            CheckFiles();

            if (!ModCheckOk)
            {
                SystemsContainer.Get <ModSystem>().FailText = StringBuilder.ToString();
                WindowsContainer.Get <ModWindow>().Display  = true;
                return(false);
            }

            SystemsContainer.Get <ModSystem>().AllowedParts = PartsList;
            LunaLog.Log("[LMP]: Mod check passed!");
            return(true);
        }
Exemple #2
0
        public static bool ParseModFile(string modFileData)
        {
            if (SystemsContainer.Get <ModSystem>().ModControl == ModControlMode.Disabled)
            {
                return(true);
            }

            Sb.Length = 0;
            SystemsContainer.Get <ModSystem>().LastModFileData = modFileData; //Save mod file so we can recheck it.

            SaveCurrentModConfigurationFile();

            var modFileInfo = ModFileParser.ReadModFile(modFileData);

            if (!CheckFiles(modFileInfo))
            {
                LunaLog.LogError("[LMP]: Mod check failed!");
                LunaLog.LogError(Sb.ToString());
                SystemsContainer.Get <ModSystem>().FailText = Sb.ToString();
                WindowsContainer.Get <ModWindow>().Display  = true;
                return(false);
            }

            SystemsContainer.Get <ModSystem>().AllowedParts = modFileInfo.PartList;
            LunaLog.Log("[LMP]: Mod check passed!");
            return(true);
        }
 public void UpdateWindowContainer(WindowsContainer windowContainer)
 {
     if (_windowContainer == null)
     {
         _windowContainer = windowContainer;
     }
 }
        public void DrawMaximize(int windowId)
        {
            GUI.DragWindow(MoveRect);
            GUILayout.BeginVertical();
            GUILayout.BeginHorizontal();
            var chatButtonStyle = ButtonStyle;

            if (SystemsContainer.Get <ChatSystem>().ChatButtonHighlighted)
            {
                chatButtonStyle = HighlightStyle;
            }
            WindowsContainer.Get <ChatWindow>().Display    = GUILayout.Toggle(WindowsContainer.Get <ChatWindow>().Display, "C", chatButtonStyle);
            WindowsContainer.Get <DebugWindow>().Display   = GUILayout.Toggle(WindowsContainer.Get <DebugWindow>().Display, "D", ButtonStyle);
            WindowsContainer.Get <OptionsWindow>().Display = GUILayout.Toggle(WindowsContainer.Get <OptionsWindow>().Display, "O", ButtonStyle);
#if DEBUG
            WindowsContainer.Get <SystemsWindow>().Display = GUILayout.Toggle(WindowsContainer.Get <SystemsWindow>().Display, "S", ButtonStyle);
#endif
            if (GUILayout.Button("+", ButtonStyle))
            {
                WindowRect.xMax = MinWindowRect.xMax;
                WindowRect.yMin = MinWindowRect.yMin;
                WindowRect.xMin = MinWindowRect.xMax - WindowWidth;
                WindowRect.yMax = MinWindowRect.yMin + WindowHeight;
                Minmized        = false;
            }
            GUILayout.EndHorizontal();
            GUILayout.EndVertical();
        }
Exemple #5
0
        private void SetWindowSize(float?x = null, float?y = null)
        {
            var sizeChanged = false;

            if (x.HasValue && x <= 800 && x >= 300)
            {
                WindowsContainer.Get <ChatWindow>().WindowWidth = x.Value;
                sizeChanged = true;
            }

            if (y.HasValue && y <= 800 && y >= 300)
            {
                WindowsContainer.Get <ChatWindow>().WindowHeight = y.Value;
                sizeChanged = true;
            }

            if (y.HasValue && (y > 800 || y < 300) || x.HasValue && (x > 800 || x < 300))
            {
                SystemsContainer.Get <ChatSystem>().PrintToSelectedChannel("Size is out of range.");
            }

            if (sizeChanged)
            {
                WindowsContainer.Get <ChatWindow>().SizeChanged();
            }
        }
Exemple #6
0
        public static void Initialize(Frame frame)
        {
            Dictionary <string, Type> views = new Dictionary <string, Type>
            {
                { Views.NAVIGATION_PAGE, typeof(NavigationPage) }
            };

            Dictionary <string, Type> dialogs = new Dictionary <string, Type>
            {
                { Dialogs.NAVIGATION_DIALOG, typeof(DialogPage) },
                { Dialogs.MAIN, typeof(MainDialog) }
            };

            var container = WindowsContainer.CreateInstance <Container>(frame, views, dialogs);

            ViewModelsLocator.Initialize(container);
        }
        public void HandleMessage(IMessageData messageData)
        {
            var msgData = messageData as PlayerColorBaseMsgData;

            if (msgData == null)
            {
                return;
            }

            switch (msgData.PlayerColorMessageType)
            {
            case PlayerColorMessageType.Reply:
            {
                var data = (PlayerColorReplyMsgData)messageData;
                System.PlayerColors.Clear();
                for (var i = 0; i < data.Count; i++)
                {
                    var playerName  = data.PlayersColors[i].Key;
                    var playerColor = System.ConvertStringToColor(data.PlayersColors[i].Value);
                    System.PlayerColors.Add(playerName, playerColor);

                    WindowsContainer.Get <StatusWindow>().ColorEventHandled = false;        //Refresh colors in status window
                }
                SystemsContainer.Get <MainSystem>().NetworkState = ClientState.ColorsSynced;
            }
            break;

            case PlayerColorMessageType.Set:
            {
                //Player joined or changed it's color so update his controlled vessel orbit colors
                var data        = (PlayerColorSetMsgData)messageData;
                var playerName  = data.PlayerName;
                var playerColor = System.ConvertStringToColor(data.Color);
                LunaLog.Log($"[LMP]: Color Message, Name: {playerName} , color: {playerColor}");
                System.PlayerColors[playerName] = playerColor;
                UpdateVesselColors(playerName);

                WindowsContainer.Get <StatusWindow>().ColorEventHandled = false;       //Refresh colors in status window
            }
            break;
            }
        }
Exemple #8
0
        public void HandleMessage(IServerMessageBase msg)
        {
            if (!(msg.Data is PlayerColorBaseMsgData msgData))
            {
                return;
            }

            switch (msgData.PlayerColorMessageType)
            {
            case PlayerColorMessageType.Reply:
            {
                var data = (PlayerColorReplyMsgData)msgData;
                System.PlayerColors.Clear();
                for (var i = 0; i < data.PlayerColorsCount; i++)
                {
                    var playerName = data.PlayersColors[i].PlayerName;
                    System.PlayerColors.Add(playerName, data.PlayersColors[i].Color);

                    WindowsContainer.Get <StatusWindow>().ColorEventHandled = false;        //Refresh colors in status window
                }
                MainSystem.NetworkState = ClientState.ColorsSynced;
            }
            break;

            case PlayerColorMessageType.Set:
            {
                //Player joined or changed it's color so update his controlled vessel orbit colors
                var data        = (PlayerColorSetMsgData)msgData;
                var playerName  = data.PlayerColor.PlayerName;
                var playerColor = data.PlayerColor.Color;

                LunaLog.Log($"[LMP]: Color Message, Name: {playerName} , color: {playerColor}");
                System.PlayerColors[playerName] = playerColor;
                UpdateVesselColors(playerName);

                WindowsContainer.Get <StatusWindow>().ColorEventHandled = false;       //Refresh colors in status window
            }
            break;
            }
        }
Exemple #9
0
        public void DrawContent(int windowId)
        {
            GUILayout.BeginVertical();
            GUI.DragWindow(MoveRect);

            #region Horizontal toolbar

            GUILayout.BeginHorizontal();

            GUILayout.FlexibleSpace();

            var chatButtonStyle = ButtonStyle;
            if (SystemsContainer.Get <ChatSystem>().ChatButtonHighlighted)
            {
                chatButtonStyle = HighlightStyle;
            }
            if (!SettingsSystem.ServerSettings.DropControlOnVesselSwitching)
            {
                if (GUILayout.Button(new GUIContent(StatusTexts.DropCtrlBtnTxt, StatusTexts.DropCtrlBtnTooltip), ButtonStyle))
                {
                    SystemsContainer.Get <VesselLockSystem>().DropAllOtherVesselControlLocks();
                }
            }
            WindowsContainer.Get <ChatWindow>().Display         = GUILayout.Toggle(WindowsContainer.Get <ChatWindow>().Display, StatusTexts.ChatBtnTxt, chatButtonStyle);
            WindowsContainer.Get <CraftLibraryWindow>().Display = GUILayout.Toggle(WindowsContainer.Get <CraftLibraryWindow>().Display, StatusTexts.CraftBtnTxt, ButtonStyle);
            WindowsContainer.Get <DebugWindow>().Display        = GUILayout.Toggle(WindowsContainer.Get <DebugWindow>().Display, StatusTexts.DebugBtnTxt, ButtonStyle);
#if DEBUG
            WindowsContainer.Get <SystemsWindow>().Display = GUILayout.Toggle(WindowsContainer.Get <SystemsWindow>().Display, StatusTexts.SystemsBtnTxt, ButtonStyle);
            WindowsContainer.Get <LocksWindow>().Display   = GUILayout.Toggle(WindowsContainer.Get <LocksWindow>().Display, StatusTexts.LocksBtnTxt, ButtonStyle);
#endif

            GUILayout.EndHorizontal();

            #endregion

            #region Players information

            ScrollPosition = GUILayout.BeginScrollView(ScrollPosition, ScrollStyle);

            //Draw other subspaces
            for (var i = 0; i < SubspaceDisplay.Count; i++)
            {
                if (SubspaceDisplay[i].SubspaceId == -1)
                {
                    //Draw the warping players
                    GUILayout.BeginHorizontal(SubspaceStyle);
                    GUILayout.Label(StatusTexts.WarpingLabelTxt);
                    GUILayout.EndHorizontal();
                }
                else
                {
                    GUILayout.BeginHorizontal(SubspaceStyle);
                    GUILayout.Label(StatusTexts.GetTimeLabel(SubspaceDisplay[i]));
                    GUILayout.FlexibleSpace();
                    if (NotWarpingAndIsFutureSubspace(SubspaceDisplay[i].SubspaceId) && GUILayout.Button(StatusTexts.SyncBtnTxt, ButtonStyle))
                    {
                        WarpSystem.CurrentSubspace = SubspaceDisplay[i].SubspaceId;
                    }
                    GUILayout.EndHorizontal();
                }

                for (var j = 0; j < SubspaceDisplay[i].Players.Count; j++)
                {
                    DrawPlayerEntry(SubspaceDisplay[i].Players[j] == SettingsSystem.CurrentSettings.PlayerName
                        ? SystemsContainer.Get <StatusSystem>().MyPlayerStatus
                        : SystemsContainer.Get <StatusSystem>().GetPlayerStatus(SubspaceDisplay[i].Players[j]));
                }
            }

            GUILayout.EndScrollView();

            #endregion

            GUILayout.FlexibleSpace();
#if DEBUG
            GUILayout.BeginHorizontal();
            DrawDebugSwitches();
            GUILayout.EndHorizontal();
#endif
            GUILayout.BeginHorizontal();
            if (GUILayout.Button(StatusTexts.DisconnectBtnTxt, ButtonStyle))
            {
                DisconnectEventHandled = false;
            }
            WindowsContainer.Get <OptionsWindow>().Display = GUILayout.Toggle(WindowsContainer.Get <OptionsWindow>().Display, StatusTexts.OptionsBtnTxt, ButtonStyle);
            GUILayout.EndHorizontal();

            GUILayout.EndVertical();
        }
Exemple #10
0
        public void DrawContent(int windowId)
        {
            if (!LoadEventHandled)
            {
                LoadEventHandled = true;
                TempColor        = SettingsSystem.CurrentSettings.PlayerColor;
                NewCacheSize     = SettingsSystem.CurrentSettings.CacheSize.ToString();
            }
            //Player color
            GUILayout.BeginVertical();
            GUI.DragWindow(MoveRect);
            GUILayout.BeginHorizontal();
            GUILayout.Label("Player Name color: ");
            GUILayout.Label(SettingsSystem.CurrentSettings.PlayerName, TempColorLabelStyle);
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            GUILayout.Label("R: ");
            TempColor.r = GUILayout.HorizontalScrollbar(TempColor.r, 0, 0, 1);
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            GUILayout.Label("G: ");
            TempColor.g = GUILayout.HorizontalScrollbar(TempColor.g, 0, 0, 1);
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            GUILayout.Label("B: ");
            TempColor.b = GUILayout.HorizontalScrollbar(TempColor.b, 0, 0, 1);
            GUILayout.EndHorizontal();
            TempColorLabelStyle.active.textColor = TempColor;
            TempColorLabelStyle.normal.textColor = TempColor;
            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Random", ButtonStyle))
            {
                TempColor = PlayerColorSystem.GenerateRandomColor();
            }
            if (GUILayout.Button("Set", ButtonStyle))
            {
                WindowsContainer.Get <StatusWindow>().ColorEventHandled = false;
                SettingsSystem.CurrentSettings.PlayerColor = TempColor;
                SettingsSystem.SaveSettings();
                if (MainSystem.NetworkState == ClientState.Running)
                {
                    SystemsContainer.Get <PlayerColorSystem>().MessageSender.SendPlayerColorToServer();
                }
            }
            GUILayout.EndHorizontal();
            GUILayout.Space(10);
            //Cache
            var enableCache = GUILayout.Toggle(SettingsSystem.CurrentSettings.EnableCache, "Enable cache", ButtonStyle);

            if (enableCache != SettingsSystem.CurrentSettings.EnableCache)
            {
                if (!enableCache)
                {
                    UniverseSyncCache.DeleteCache();               //Remove all cache when deactivating it
                }
                SettingsSystem.CurrentSettings.EnableCache = enableCache;
                SettingsSystem.SaveSettings();
            }
            if (SettingsSystem.CurrentSettings.EnableCache)
            {
                GUILayout.Label("Cache size");
                GUILayout.Label($"Current size: {Math.Round(UniverseSyncCache.CurrentCacheSize / (float)(1024 * 1024), 3)} MB.");
                GUILayout.Label($"Max size: {SettingsSystem.CurrentSettings.CacheSize} MB.");
                NewCacheSize = GUILayout.TextArea(NewCacheSize);
                GUILayout.BeginHorizontal();
                if (GUILayout.Button("Set", ButtonStyle))
                {
                    if (int.TryParse(NewCacheSize, out var tempCacheSize))
                    {
                        if (tempCacheSize < 1)
                        {
                            tempCacheSize = 1;
                            NewCacheSize  = tempCacheSize.ToString();
                        }
                        if (tempCacheSize > 1000)
                        {
                            tempCacheSize = 1000;
                            NewCacheSize  = tempCacheSize.ToString();
                        }
                        SettingsSystem.CurrentSettings.CacheSize = tempCacheSize;
                        SettingsSystem.SaveSettings();
                    }
                    else
                    {
                        NewCacheSize = SettingsSystem.CurrentSettings.CacheSize.ToString();
                    }
                }
                if (GUILayout.Button("Expire cache"))
                {
                    UniverseSyncCache.ExpireCache();
                }
                if (GUILayout.Button("Delete cache"))
                {
                    UniverseSyncCache.DeleteCache();
                }
                GUILayout.EndHorizontal();
            }

            //Key bindings
            GUILayout.Space(10);
            var chatDescription = $"Set chat key (current: {SettingsSystem.CurrentSettings.ChatKey})";

            if (SettingChat)
            {
                chatDescription = "Setting chat key (click to cancel)...";
                if (Event.current.isKey)
                {
                    if (Event.current.keyCode != KeyCode.Escape)
                    {
                        SettingsSystem.CurrentSettings.ChatKey = Event.current.keyCode;
                        SettingsSystem.SaveSettings();
                        SettingChat = false;
                    }
                    else
                    {
                        SettingChat = false;
                    }
                }
            }
            if (GUILayout.Button(chatDescription))
            {
                SettingChat = !SettingChat;
            }
            GUILayout.Space(10);
            GUILayout.Label("Generate a server LMPModControl:");
            if (GUILayout.Button("Generate blacklist LMPModControl.txt"))
            {
                SystemsContainer.Get <ModSystem>().GenerateModControlFile(false);
            }
            if (GUILayout.Button("Generate whitelist LMPModControl.txt"))
            {
                SystemsContainer.Get <ModSystem>().GenerateModControlFile(true);
            }
            WindowsContainer.Get <UniverseConverterWindow>().Display = GUILayout.Toggle(WindowsContainer.Get <UniverseConverterWindow>().Display, "Generate Universe from saved game", ButtonStyle);
            if (GUILayout.Button("Reset disclaimer"))
            {
                SettingsSystem.CurrentSettings.DisclaimerAccepted = false;
                SettingsSystem.SaveSettings();
            }
            var settingCompression = GUILayout.Toggle(SettingsSystem.CurrentSettings.CompressionEnabled, "Enable compression", ButtonStyle);

            if (settingCompression != SettingsSystem.CurrentSettings.CompressionEnabled)
            {
                SettingsSystem.CurrentSettings.CompressionEnabled = settingCompression;
                SettingsSystem.SaveSettings();
            }
            var settingInterpolation = GUILayout.Toggle(SettingsSystem.CurrentSettings.InterpolationEnabled, "Enable interpolation", ButtonStyle);

            if (settingInterpolation != SettingsSystem.CurrentSettings.InterpolationEnabled)
            {
                SettingsSystem.CurrentSettings.InterpolationEnabled = settingInterpolation;
                SettingsSystem.SaveSettings();
            }
            var positionFudge = GUILayout.Toggle(SettingsSystem.CurrentSettings.PositionFudgeEnable, "Enable position fudge", ButtonStyle);

            if (positionFudge != SettingsSystem.CurrentSettings.PositionFudgeEnable)
            {
                SettingsSystem.CurrentSettings.PositionFudgeEnable = positionFudge;
                SettingsSystem.SaveSettings();
            }
            var altPositionSystem = GUILayout.Toggle(SettingsSystem.CurrentSettings.UseAlternativePositionSystem, "Use alterative position system", ButtonStyle);

            if (altPositionSystem != SettingsSystem.CurrentSettings.UseAlternativePositionSystem)
            {
                SettingsSystem.CurrentSettings.UseAlternativePositionSystem = altPositionSystem;
                SettingsSystem.SaveSettings();
            }
            var packOtherVessels = GUILayout.Toggle(SettingsSystem.CurrentSettings.PackOtherControlledVessels, "Pack other vessels", ButtonStyle);

            if (packOtherVessels != SettingsSystem.CurrentSettings.PackOtherControlledVessels)
            {
                SettingsSystem.CurrentSettings.PackOtherControlledVessels = packOtherVessels;
                SettingsSystem.SaveSettings();
            }

            GUILayout.BeginHorizontal();
            GUILayout.Label("Toolbar:", SmallOption);
            if (GUILayout.Button(ToolbarMode, ButtonStyle))
            {
                var newSetting = (int)SettingsSystem.CurrentSettings.ToolbarType + 1;
                //Overflow to 0
                if (!Enum.IsDefined(typeof(LmpToolbarType), newSetting))
                {
                    newSetting = 0;
                }
                SettingsSystem.CurrentSettings.ToolbarType = (LmpToolbarType)newSetting;
                SettingsSystem.SaveSettings();
                UpdateToolbarString();
                SystemsContainer.Get <ToolbarSystem>().ToolbarChanged();
            }
            GUILayout.EndHorizontal();
#if DEBUG
            if (GUILayout.Button("Check Common.dll stock parts"))
            {
                SystemsContainer.Get <ModSystem>().CheckCommonStockParts();
            }
#endif
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Close", ButtonStyle))
            {
                Display = false;
            }
            GUILayout.EndVertical();
        }
Exemple #11
0
        public void DrawContent(int windowId)
        {
            GUILayout.BeginVertical();
            GUI.DragWindow(MoveRect);
            GUILayout.Space(20);
            GUILayout.BeginHorizontal();
            GUILayout.Label("Player Name:", LabelOptions);
            var oldPlayerName = SettingsSystem.CurrentSettings.PlayerName;

            SettingsSystem.CurrentSettings.PlayerName = GUILayout.TextArea(SettingsSystem.CurrentSettings.PlayerName, 32, TextAreaStyle); // Max 32 characters
            if (oldPlayerName != SettingsSystem.CurrentSettings.PlayerName)
            {
                SettingsSystem.CurrentSettings.PlayerName = SettingsSystem.CurrentSettings.PlayerName.Replace("\n", "");
                RenameEventHandled = false;
            }
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            //Draw add button
            var addMode       = SelectedSafe == -1 ? "Add" : "Edit";
            var buttonAddMode = addMode;

            if (AddingServer)
            {
                buttonAddMode = "Cancel";
            }
            AddingServer = GUILayout.Toggle(AddingServer, buttonAddMode, ButtonStyle);
            if (AddingServer && !AddingServerSafe && Selected != -1)
            {
                //Load the existing server settings
                ServerName    = SettingsSystem.CurrentSettings.Servers[Selected].Name;
                ServerAddress = SettingsSystem.CurrentSettings.Servers[Selected].Address;
                ServerPort    = SettingsSystem.CurrentSettings.Servers[Selected].Port.ToString();
            }

            //Draw connect button
            if (SystemsContainer.Get <MainSystem>().NetworkState == ClientState.Disconnected)
            {
                GUI.enabled = SelectedSafe != -1;
                if (GUILayout.Button("Connect", ButtonStyle))
                {
                    ConnectEventHandled = false;
                }
            }
            else
            {
                if (GUILayout.Button("Disconnect", ButtonStyle))
                {
                    DisconnectEventHandled = false;
                }
            }
            //Draw remove button
            if (GUILayout.Button("Remove", ButtonStyle))
            {
                if (RemoveEventHandled)
                {
                    RemoveEventHandled = false;
                }
            }
            GUI.enabled = true;
            WindowsContainer.Get <OptionsWindow>().Display = GUILayout.Toggle(WindowsContainer.Get <OptionsWindow>().Display, "Options", ButtonStyle);
            if (GUILayout.Button("Servers", ButtonStyle))
            {
                WindowsContainer.Get <ServerListWindow>().Display = true;
            }
            if (GUILayout.Button("Close", ButtonStyle))
            {
                Closed = true;
            }
            GUILayout.EndHorizontal();
            if (AddingServerSafe)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label("Name:", LabelOptions);
                ServerName = GUILayout.TextArea(ServerName, TextAreaStyle);
                GUILayout.EndHorizontal();
                GUILayout.BeginHorizontal();
                GUILayout.Label("Address:", LabelOptions);
                ServerAddress = GUILayout.TextArea(ServerAddress, TextAreaStyle).Trim();
                GUILayout.EndHorizontal();
                GUILayout.BeginHorizontal();
                GUILayout.Label("Port:", LabelOptions);
                ServerPort = GUILayout.TextArea(ServerPort, TextAreaStyle).Trim();
                GUILayout.EndHorizontal();
                if (GUILayout.Button($"{addMode} server", ButtonStyle))
                {
                    if (AddEventHandled)
                    {
                        if (Selected == -1)
                        {
                            AddEntry = new ServerEntry
                            {
                                Name    = ServerName,
                                Address = ServerAddress,
                                Port    = 6702
                            };
                            int.TryParse(ServerPort, out AddEntry.Port);
                            AddEventHandled = false;
                        }
                        else
                        {
                            EditEntry = new ServerEntry
                            {
                                Name    = ServerName,
                                Address = ServerAddress,
                                Port    = 6702
                            };
                            int.TryParse(ServerPort, out EditEntry.Port);
                            EditEventHandled = false;
                        }
                    }
                }
            }

            GUILayout.Label("Custom servers:");
            if (SettingsSystem.CurrentSettings.Servers.Count == 0)
            {
                GUILayout.Label("(None - Add a server first)");
            }

            ScrollPos = GUILayout.BeginScrollView(ScrollPos, GUILayout.Width(WindowWidth - 5),
                                                  GUILayout.Height(WindowHeight - 100));

            for (var serverPos = 0; serverPos < SettingsSystem.CurrentSettings.Servers.Count; serverPos++)
            {
                var thisSelected = GUILayout.Toggle(serverPos == SelectedSafe,
                                                    SettingsSystem.CurrentSettings.Servers[serverPos].Name, ButtonStyle);
                if (Selected == SelectedSafe)
                {
                    if (thisSelected)
                    {
                        if (Selected != serverPos)
                        {
                            Selected     = serverPos;
                            AddingServer = false;
                        }
                    }
                    else if (Selected == serverPos)
                    {
                        Selected     = -1;
                        AddingServer = false;
                    }
                }
            }
            GUILayout.EndScrollView();

            //Draw Status Message
            GUILayout.Label(Status, StatusStyle);
            GUILayout.EndVertical();
        }
Exemple #12
0
        public void DrawContent(int windowId)
        {
            if (!LoadEventHandled)
            {
                LoadEventHandled = true;
                TempColor        = SettingsSystem.CurrentSettings.PlayerColor;
            }
            //Player color
            GUILayout.BeginVertical();
            GUI.DragWindow(MoveRect);
            GUILayout.BeginHorizontal();
            GUILayout.Label("Player Name color: ");
            GUILayout.Label(SettingsSystem.CurrentSettings.PlayerName, TempColorLabelStyle);
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            GUILayout.Label("R: ", SmallOption);
            TempColor.r = GUILayout.HorizontalScrollbar(TempColor.r, 0, 0, 1);
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            GUILayout.Label("G: ", SmallOption);
            TempColor.g = GUILayout.HorizontalScrollbar(TempColor.g, 0, 0, 1);
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            GUILayout.Label("B: ", SmallOption);
            TempColor.b = GUILayout.HorizontalScrollbar(TempColor.b, 0, 0, 1);
            GUILayout.EndHorizontal();
            TempColorLabelStyle.active.textColor = TempColor;
            TempColorLabelStyle.normal.textColor = TempColor;
            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Random", ButtonStyle))
            {
                TempColor = PlayerColorSystem.GenerateRandomColor();
            }
            if (GUILayout.Button("Set", ButtonStyle))
            {
                WindowsContainer.Get <StatusWindow>().ColorEventHandled = false;
                SettingsSystem.CurrentSettings.PlayerColor = TempColor;
                SettingsSystem.SaveSettings();
                if (MainSystem.NetworkState == ClientState.Running)
                {
                    SystemsContainer.Get <PlayerColorSystem>().MessageSender.SendPlayerColorToServer();
                }
            }
            GUILayout.EndHorizontal();
            GUILayout.Space(10);
            //Key bindings
            var chatDescription = $"Set chat key (current: {SettingsSystem.CurrentSettings.ChatKey})";

            if (SettingChat)
            {
                chatDescription = "Setting chat key (click to cancel)...";
                if (Event.current.isKey)
                {
                    if (Event.current.keyCode != KeyCode.Escape)
                    {
                        SettingsSystem.CurrentSettings.ChatKey = Event.current.keyCode;
                        SettingsSystem.SaveSettings();
                        SettingChat = false;
                    }
                    else
                    {
                        SettingChat = false;
                    }
                }
            }
            if (GUILayout.Button(chatDescription))
            {
                SettingChat = !SettingChat;
            }
            if (GUILayout.Button("Reset disclaimer"))
            {
                SettingsSystem.CurrentSettings.DisclaimerAccepted = false;
                SettingsSystem.SaveSettings();
            }
            var settingInterpolation = GUILayout.Toggle(SettingsSystem.CurrentSettings.InterpolationEnabled, "Enable interpolation", ButtonStyle);

            if (settingInterpolation != SettingsSystem.CurrentSettings.InterpolationEnabled)
            {
                SettingsSystem.CurrentSettings.InterpolationEnabled = settingInterpolation;
                SettingsSystem.SaveSettings();
            }
            var closeBtnInConnectionWindow = GUILayout.Toggle(SettingsSystem.CurrentSettings.CloseBtnInConnectionWindow, "Show \"Close\" button in connection window", ButtonStyle);

            if (closeBtnInConnectionWindow != SettingsSystem.CurrentSettings.CloseBtnInConnectionWindow)
            {
                SettingsSystem.CurrentSettings.CloseBtnInConnectionWindow = closeBtnInConnectionWindow;
                SettingsSystem.SaveSettings();
            }
            GUILayout.Space(10);
            GUILayout.BeginVertical();
            GUILayout.Label("Positioning system:");
            var positionSetting = GUILayout.SelectionGrid(SettingsSystem.CurrentSettings.PositionSystem, new[] { "Dark", "Dagger", "Mixed" }, 3, "toggle");

            if (positionSetting != SettingsSystem.CurrentSettings.PositionSystem)
            {
                SettingsSystem.CurrentSettings.PositionSystem = positionSetting;
                SettingsSystem.SaveSettings();
            }
            GUILayout.EndVertical();
            GUILayout.Space(10);
            GUILayout.Label("Generate a server LMPModControl:");
            if (GUILayout.Button("Generate blacklist LMPModControl.txt"))
            {
                SystemsContainer.Get <ModSystem>().GenerateModControlFile(false);
            }
            if (GUILayout.Button("Generate whitelist LMPModControl.txt"))
            {
                SystemsContainer.Get <ModSystem>().GenerateModControlFile(true);
            }
            WindowsContainer.Get <UniverseConverterWindow>().Display = GUILayout.Toggle(WindowsContainer.Get <UniverseConverterWindow>().Display, "Generate Universe from saved game", ButtonStyle);
            GUILayout.Space(10);
            GUILayout.BeginHorizontal();
            GUILayout.Label("Toolbar:", SmallOption);
            if (GUILayout.Button(ToolbarMode, ButtonStyle))
            {
                var newSetting = (int)SettingsSystem.CurrentSettings.ToolbarType + 1;
                //Overflow to 0
                if (!Enum.IsDefined(typeof(LmpToolbarType), newSetting))
                {
                    newSetting = 0;
                }
                SettingsSystem.CurrentSettings.ToolbarType = (LmpToolbarType)newSetting;
                SettingsSystem.SaveSettings();
                UpdateToolbarString();
                SystemsContainer.Get <ToolbarSystem>().ToolbarChanged();
            }
            GUILayout.EndHorizontal();
#if DEBUG
            DrawAdvancedDebugOptions();
#endif
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Close", ButtonStyle))
            {
                Display = false;
            }
            GUILayout.EndVertical();
        }
        private void HandleWindowEvents()
        {
            if (!WindowsContainer.Get <StatusWindow>().DisconnectEventHandled)
            {
                WindowsContainer.Get <StatusWindow>().DisconnectEventHandled = true;
                ForceQuit = true;
                NetworkConnection.Disconnect("Quit");
                SystemsContainer.Get <ScenarioSystem>().SendScenarioModules(); // Send scenario modules before disconnecting
            }
            if (!ConnectionWindow.RenameEventHandled)
            {
                SystemsContainer.Get <StatusSystem>().MyPlayerStatus.PlayerName = SettingsSystem.CurrentSettings.PlayerName;
                ConnectionWindow.RenameEventHandled = true;
                SettingsSystem.SaveSettings();
            }
            if (!ConnectionWindow.AddEventHandled)
            {
                SettingsSystem.CurrentSettings.Servers.Add(ConnectionWindow.AddEntry);
                ConnectionWindow.AddEntry        = null;
                ConnectionWindow.AddingServer    = false;
                ConnectionWindow.AddEventHandled = true;
                SettingsSystem.SaveSettings();
            }
            if (!ConnectionWindow.EditEventHandled)
            {
                SettingsSystem.CurrentSettings.Servers[ConnectionWindow.Selected].Name    = ConnectionWindow.EditEntry.Name;
                SettingsSystem.CurrentSettings.Servers[ConnectionWindow.Selected].Address = ConnectionWindow.EditEntry.Address;
                SettingsSystem.CurrentSettings.Servers[ConnectionWindow.Selected].Port    = ConnectionWindow.EditEntry.Port;
                ConnectionWindow.EditEntry        = null;
                ConnectionWindow.AddingServer     = false;
                ConnectionWindow.EditEventHandled = true;
                SettingsSystem.SaveSettings();
            }
            if (!ConnectionWindow.RemoveEventHandled)
            {
                SettingsSystem.CurrentSettings.Servers.RemoveAt(ConnectionWindow.Selected);
                ConnectionWindow.Selected           = -1;
                ConnectionWindow.RemoveEventHandled = true;
                SettingsSystem.SaveSettings();
            }
            if (!ConnectionWindow.ConnectEventHandled)
            {
                ConnectionWindow.ConnectEventHandled = true;
                NetworkConnection.ConnectToServer(
                    SettingsSystem.CurrentSettings.Servers[ConnectionWindow.Selected].Address,
                    SettingsSystem.CurrentSettings.Servers[ConnectionWindow.Selected].Port);
            }
            if (CommandLineServer != null && HighLogic.LoadedScene == GameScenes.MAINMENU &&
                Time.timeSinceLevelLoad > 1f)
            {
                NetworkConnection.ConnectToServer(CommandLineServer.Address, CommandLineServer.Port);
                CommandLineServer = null;
            }

            if (!ConnectionWindow.DisconnectEventHandled)
            {
                ConnectionWindow.DisconnectEventHandled = true;
                GameRunning = false;
                FireReset   = true;
                NetworkConnection.Disconnect(NetworkState <= ClientState.Starting
                    ? "Cancelled connection to server"
                    : "Quit");
            }
        }
Exemple #14
0
 private void OnDisable()
 {
     _windowContainer = null;
 }
        public void DrawContent(int windowId)
        {
            GUILayout.BeginVertical();
            GUI.DragWindow(MoveRect);

            #region Horizontal toolbar

            GUILayout.BeginHorizontal();

            GUILayout.FlexibleSpace();

            var chatButtonStyle = ButtonStyle;
            if (SystemsContainer.Get <ChatSystem>().ChatButtonHighlighted)
            {
                chatButtonStyle = HighlightStyle;
            }
            if (!SettingsSystem.ServerSettings.DropControlOnVesselSwitching)
            {
                var tooltip = "Drops control of the vessels that you are not controlling so other players can control them";
                if (GUILayout.Button(new GUIContent("DropCtrl", tooltip), ButtonStyle))
                {
                    SystemsContainer.Get <VesselLockSystem>().DropAllOtherVesselControlLocks();
                }
            }
            WindowsContainer.Get <ChatWindow>().Display         = GUILayout.Toggle(WindowsContainer.Get <ChatWindow>().Display, "Chat", chatButtonStyle);
            WindowsContainer.Get <CraftLibraryWindow>().Display = GUILayout.Toggle(WindowsContainer.Get <CraftLibraryWindow>().Display, "Craft", ButtonStyle);
            WindowsContainer.Get <DebugWindow>().Display        = GUILayout.Toggle(WindowsContainer.Get <DebugWindow>().Display, "Debug", ButtonStyle);
#if DEBUG
            WindowsContainer.Get <SystemsWindow>().Display = GUILayout.Toggle(WindowsContainer.Get <SystemsWindow>().Display, "Systems", ButtonStyle);
#endif

            GUILayout.EndHorizontal();

            #endregion

            #region Players information

            ScrollPosition = GUILayout.BeginScrollView(ScrollPosition, ScrollStyle);

            //Draw other subspaces
            foreach (var currentEntry in SubspaceDisplay)
            {
                if (currentEntry.SubspaceId == -1)
                {
                    //Draw the warping players
                    GUILayout.BeginHorizontal(SubspaceStyle);
                    GUILayout.Label("WARPING");
                    GUILayout.EndHorizontal();
                }
                else
                {
                    GUILayout.BeginHorizontal(SubspaceStyle);
                    GUILayout.Label($"T: +{KSPUtil.PrintTimeCompact(WarpSystem.GetSubspaceTime(currentEntry.SubspaceId), false)}");
                    GUILayout.FlexibleSpace();
                    if (NotWarpingAndIsFutureSubspace(currentEntry.SubspaceId) && GUILayout.Button("Sync", ButtonStyle))
                    {
                        WarpSystem.CurrentSubspace = currentEntry.SubspaceId;
                    }
                    GUILayout.EndHorizontal();
                }

                foreach (var currentPlayer in currentEntry.Players)
                {
                    DrawPlayerEntry(currentPlayer == SettingsSystem.CurrentSettings.PlayerName
                        ? SystemsContainer.Get <StatusSystem>().MyPlayerStatus
                        : SystemsContainer.Get <StatusSystem>().GetPlayerStatus(currentPlayer));
                }
            }

            GUILayout.EndScrollView();

            #endregion

            GUILayout.FlexibleSpace();
#if DEBUG
            GUILayout.BeginHorizontal();
            DrawDebugSwitches();
            GUILayout.EndHorizontal();
#endif
            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Disconnect", ButtonStyle))
            {
                DisconnectEventHandled = false;
            }
            WindowsContainer.Get <OptionsWindow>().Display = GUILayout.Toggle(WindowsContainer.Get <OptionsWindow>().Display, "Options", ButtonStyle);
            GUILayout.EndHorizontal();

            GUILayout.EndVertical();
        }
Exemple #16
0
        public void ResizeChat(string commandArgs)
        {
            float size = 0;

            var func = commandArgs;

            if (commandArgs.Contains(" "))
            {
                func = commandArgs.Substring(0, commandArgs.IndexOf(" ", StringComparison.Ordinal));
                if (commandArgs.Substring(func.Length).Contains(" "))
                {
                    try
                    {
                        size = Convert.ToSingle(commandArgs.Substring(func.Length + 1));
                    }
                    catch (FormatException)
                    {
                        SystemsContainer.Get <ChatSystem>().PrintToSelectedChannel($"Error: {size} is not a valid number");
                        size = 400f;
                    }
                }
            }

            switch (func)
            {
            default:
                SystemsContainer.Get <ChatSystem>().PrintToSelectedChannel("Undefined function. Usage: /resize [default|medium|large], /resize [x|y] size, or /resize show");
                SystemsContainer.Get <ChatSystem>().PrintToSelectedChannel($"Chat window size is currently: {WindowsContainer.Get<ChatWindow>().WindowWidth}x{WindowsContainer.Get<ChatWindow>().WindowHeight}");
                break;

            case "x":
                SetWindowSize(size);
                break;

            case "y":
                SetWindowSize(null, size);
                break;

            case "default":
                SetWindowSize(400, 300);
                break;

            case "medium":
                SetWindowSize(600, 600);
                break;

            case "large":
                SetWindowSize(800, 800);
                break;

            case "show":
                SystemsContainer.Get <ChatSystem>().PrintToSelectedChannel($"Chat window size is currently: {WindowsContainer.Get<ChatWindow>().WindowWidth}x{WindowsContainer.Get<ChatWindow>().WindowHeight}");
                break;
            }
        }