示例#1
0
        protected override void Init()
        {
            Title = "kRPC Server Info";

            Style.fixedWidth = windowWidth;

            var skin = Skin.DefaultSkin;

            labelStyle        = new GUIStyle(skin.label);
            labelStyle.margin = new RectOffset(0, 0, 0, 0);

            nameLabelStyle            = new GUIStyle(skin.label);
            nameLabelStyle.margin     = new RectOffset(0, 0, 0, 0);
            nameLabelStyle.fixedWidth = 160f;

            valueLabelStyle            = new GUIStyle(skin.label);
            valueLabelStyle.margin     = new RectOffset(0, 0, 0, 0);
            valueLabelStyle.fixedWidth = 120f;

            separatorStyle              = GUILayoutExtensions.SeparatorStyle(new Color(0f, 0f, 0f, 0.25f));
            separatorStyle.fixedHeight  = 2;
            separatorStyle.stretchWidth = true;
            separatorStyle.margin       = new RectOffset(2, 2, 3, 3);

            buttonStyle        = new GUIStyle(skin.button);
            buttonStyle.margin = new RectOffset(0, 0, 0, 0);
        }
示例#2
0
        void DrawClientsList()
        {
            var clients = Server.Clients.ToList();

            // Resize window if number of connected clients changes
            if (clients.Count != numClientsDisplayed)
            {
                numClientsDisplayed = clients.Count;
                resized             = true;
            }
            // Get list of client descriptions
            IDictionary <IClient, string> clientDescriptions = new Dictionary <IClient, string> ();

            if (clients.Count > 0)
            {
                foreach (var client in clients)
                {
                    try {
                        var clientName = client.Name;
                        clientDescriptions [client] = (clientName.Length == 0 ? unknownClientNameText : clientName) + " @ " + client.Address;
                    } catch (ClientDisconnectedException) {
                    }
                }
            }

            // Display the list of clients
            if (clientDescriptions.Any())
            {
                foreach (var entry in clientDescriptions)
                {
                    var client      = entry.Key;
                    var description = entry.Value;
                    GUILayout.BeginHorizontal();
                    GUILayoutExtensions.Light(IsClientActive(client), lightStyle);
                    GUILayout.Label(description, stretchyLabelStyle);
                    if (GUILayout.Button(new GUIContent(Icons.Instance.ButtonDisconnectClient, "Disconnect client"),
                                         buttonStyle, GUILayout.MaxWidth(20), GUILayout.MaxHeight(20)))
                    {
                        if (Config.ConfirmRemoveClient)
                        {
                            ClientDisconnectDialog.Show(client);
                        }
                        else
                        {
                            client.Close();
                        }
                    }
                    GUILayout.EndHorizontal();
                }
            }
            else
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label(noClientsConnectedText, labelStyle);
                GUILayout.EndHorizontal();
            }
        }
示例#3
0
 void DrawAddress()
 {
     if (Server.Running)
     {
         GUILayout.Label(addressLabelText + " " + Server.Address, labelStyle);
     }
     else
     {
         GUILayout.Label(addressLabelText, labelStyle);
         // Get the index of the address in the combo box
         int selected;
         if (!manualAddress && address == IPAddress.Loopback.ToString())
         {
             selected = 0;
         }
         else if (!manualAddress && address == IPAddress.Any.ToString())
         {
             selected = 1;
         }
         else if (!manualAddress && availableAddresses.Contains(address))
         {
             selected = availableAddresses.IndexOf(address);
         }
         else
         {
             selected = availableAddresses.Count - 1;
         }
         // Display the combo box
         selected = GUILayoutExtensions.ComboBox("address", selected, availableAddresses, buttonStyle, comboOptionsStyle, comboOptionStyle);
         // Get the address from the combo box selection
         if (selected == 0)
         {
             address       = IPAddress.Loopback.ToString();
             manualAddress = false;
         }
         else if (selected == 1)
         {
             address       = IPAddress.Any.ToString();
             manualAddress = false;
         }
         else if (selected < availableAddresses.Count - 1)
         {
             address       = availableAddresses [selected];
             manualAddress = false;
         }
         else
         {
             // Display a text field when "Manual" is selected
             address       = GUILayout.TextField(address, addressMaxLength, stretchyTextFieldStyle);
             manualAddress = true;
         }
     }
 }
示例#4
0
 void DrawServerStatus()
 {
     GUILayoutExtensions.Light(Server.Running, lightStyle);
     if (Server.Running)
     {
         GUILayout.Label(serverOnlineText, stretchyLabelStyle);
     }
     else
     {
         GUILayout.Label(serverOfflineText, stretchyLabelStyle);
     }
 }
示例#5
0
        protected override void Draw()
        {
            update = ((DateTime.Now - lastUpdate).TotalSeconds > updateTime);
            if (update)
            {
                lastUpdate = DateTime.Now;
            }
            var core = Core.Instance;

            GUILayout.BeginVertical();

            GUILayout.Label(networkInfoText, labelStyle);
            DrawInfo(bytesReadText, BytesToString(core.BytesRead));
            DrawInfo(bytesWrittenText, BytesToString(core.BytesWritten));
            DrawInfo(bytesReadRateText, BytesToString((ulong)core.BytesReadRate) + "/s");
            DrawInfo(bytesWrittenRateText, BytesToString((ulong)core.BytesWrittenRate) + "/s");

            GUILayoutExtensions.Separator(separatorStyle);

            GUILayout.Label(rpcInfoText, labelStyle);
            DrawInfo(rpcsExecutedText, core.RPCsExecuted.ToString());
            DrawInfo(rpcRateText, Math.Round(core.RPCRate) + " RPC/s");
            DrawInfo(rpcExecutionMode, core.OneRPCPerUpdate ? singleRPCModeText : (core.AdaptiveRateControl ? adaptiveModeText : staticModeText));
            DrawInfo(maxTimePerUpdateText, core.OneRPCPerUpdate ? notApplicableText : core.MaxTimePerUpdate + " ns");
            DrawInfo(rpcReceiveModeText, core.BlockingRecv ? blockingModeText : nonBlockingModeText);
            DrawInfo(recvTimeoutText, core.BlockingRecv ? core.RecvTimeout + " ns" : notApplicableText);
            DrawInfo(timePerRPCUpdateText, String.Format("{0:F5} s", core.TimePerRPCUpdate));
            DrawInfo(pollTimePerRPCUpdateText, String.Format("{0:F5} s", core.PollTimePerRPCUpdate));
            DrawInfo(execTimePerRPCUpdateText, String.Format("{0:F5} s", core.ExecTimePerRPCUpdate));

            GUILayoutExtensions.Separator(separatorStyle);

            GUILayout.Label(streamInfoText, labelStyle);
            DrawInfo(streamingRPCsText, core.StreamRPCs.ToString());
            DrawInfo(streamingRPCsExecutedText, core.StreamRPCsExecuted.ToString());
            DrawInfo(streamingRPCRateText, Math.Round(core.StreamRPCRate) + " RPC/s");
            DrawInfo(timePerStreamUpdateText, String.Format("{0:F5} s", core.TimePerStreamUpdate));

            GUILayoutExtensions.Separator(separatorStyle);

            GUILayout.BeginHorizontal();
            if (GUILayout.Button(clearStatisticsText, buttonStyle))
            {
                core.ClearStats();
            }
            GUILayout.EndHorizontal();

            GUILayout.EndVertical();
            GUI.DragWindow();
        }
示例#6
0
        void DrawClients(IServer server)
        {
            var clients = server.Clients.ToList();
            IDictionary <IClient, string> clientDescriptions = new Dictionary <IClient, string> ();

            if (clients.Count > 0)
            {
                foreach (var client in clients)
                {
                    try {
                        var clientName = client.Name;
                        clientDescriptions [client] = (clientName.Length == 0 ? unknownClientNameText : clientName) + " @ " + client.Address;
                    } catch (ClientDisconnectedException) {
                    }
                }
            }

            if (clientDescriptions.Any())
            {
                foreach (var entry in clientDescriptions)
                {
                    var client      = entry.Key;
                    var description = entry.Value;
                    GUILayout.BeginHorizontal();
                    GUILayoutExtensions.Light(IsClientActive(client), lightStyle);
                    GUILayout.Label(description, stretchyLabelStyle);
                    if (GUILayout.Button(new GUIContent(Icons.Instance.ButtonDisconnectClient, "Disconnect client"),
                                         buttonStyle, GUILayout.MaxWidth(20), GUILayout.MaxHeight(20)))
                    {
                        if (config.Configuration.ConfirmRemoveClient)
                        {
                            ClientDisconnectDialog.Show(client);
                        }
                        else
                        {
                            client.Close();
                        }
                    }
                    GUILayout.EndHorizontal();
                }
            }
            else
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label(noClientsConnectedText, labelStyle);
                GUILayout.EndHorizontal();
            }
        }
示例#7
0
        protected override void Draw(bool needRescale)
        {
            if (needRescale)
            {
                int scaledFontSize = Style.fontSize;
                scaledIndentWidth = indentWidth * GameSettings.UI_SCALE;
                Style.fixedWidth  = windowWidth * GameSettings.UI_SCALE;

                labelStyle.fontSize             = scaledFontSize;
                stretchyLabelStyle.fontSize     = scaledFontSize;
                fixedLabelStyle.fontSize        = scaledFontSize;
                fixedLabelStyle.fixedWidth      = fixedLabelWidth * GameSettings.UI_SCALE;
                textFieldStyle.fontSize         = scaledFontSize;
                textFieldStyle.fixedWidth       = textFieldWidth * GameSettings.UI_SCALE;
                longTextFieldStyle.fontSize     = scaledFontSize;
                longTextFieldStyle.fixedWidth   = longTextFieldWidth * GameSettings.UI_SCALE;
                stretchyTextFieldStyle.fontSize = scaledFontSize;
                buttonStyle.fontSize            = scaledFontSize;
                toggleStyle.fontSize            = scaledFontSize;
                separatorStyle.fontSize         = scaledFontSize;
                lightStyle.fontSize             = scaledFontSize;
                errorLabelStyle.fontSize        = scaledFontSize;
                comboOptionsStyle.fontSize      = scaledFontSize;
                GUILayoutExtensions.SetLightStyleSize(lightStyle, Style.lineHeight);
                resized = true;
            }

            // Force window to resize to height of content
            if (resized)
            {
                Position = new Rect(Position.x, Position.y, Position.width, 0f);
                resized  = false;
            }

            var running = Server.Running;

            GUILayout.BeginVertical();

            GUILayout.BeginHorizontal();
            DrawServerStatus();
            DrawStartStopButton();
            GUILayout.EndHorizontal();

            GUILayout.Space(4);

            GUILayout.BeginHorizontal();
            DrawAddress();
            if (running)
            {
                GUILayout.Space(4);
                DrawShowInfoWindow();
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            DrawRPCPort();
            GUILayout.Space(4);
            DrawStreamPort();
            GUILayout.EndHorizontal();

            if (running)
            {
                GUILayout.BeginHorizontal();
                DrawServerInfo();
                GUILayout.EndHorizontal();
                GUILayoutExtensions.Separator(separatorStyle);
                DrawClientsList();
            }
            else
            {
                GUILayout.BeginHorizontal();
                DrawAdvancedToggle();
                GUILayout.EndHorizontal();

                if (advanced)
                {
                    GUILayout.BeginHorizontal();
                    GUILayout.Space(scaledIndentWidth);
                    DrawAutoStartServerToggle();
                    GUILayout.EndHorizontal();

                    GUILayout.BeginHorizontal();
                    GUILayout.Space(scaledIndentWidth);
                    DrawAutoAcceptConnectionsToggle();
                    GUILayout.EndHorizontal();

                    GUILayout.BeginHorizontal();
                    GUILayout.Space(scaledIndentWidth);
                    DrawConfirmRemoveClientToggle();
                    GUILayout.EndHorizontal();

                    GUILayout.BeginHorizontal();
                    GUILayout.Space(scaledIndentWidth);
                    DrawOneRPCPerUpdateToggle();
                    GUILayout.EndHorizontal();

                    GUILayout.BeginHorizontal();
                    GUILayout.Space(scaledIndentWidth);
                    DrawMaxTimePerUpdate();
                    GUILayout.EndHorizontal();

                    GUILayout.BeginHorizontal();
                    GUILayout.Space(scaledIndentWidth);
                    DrawAdaptiveRateControlToggle();
                    GUILayout.EndHorizontal();

                    GUILayout.BeginHorizontal();
                    GUILayout.Space(scaledIndentWidth);
                    DrawBlockingRecvToggle();
                    GUILayout.EndHorizontal();

                    GUILayout.BeginHorizontal();
                    GUILayout.Space(scaledIndentWidth);
                    DrawRecvTimeout();
                    GUILayout.EndHorizontal();
                }

                foreach (var error in Errors)
                {
                    GUILayout.Label(error, errorLabelStyle);
                }
            }
            GUILayout.EndVertical();
            GUI.DragWindow();
        }
示例#8
0
        protected override void Init()
        {
            Title = title;
            Server.OnClientActivity += (s, e) => SawClientActivity(e.Client);

            Style.fixedWidth = windowWidth;

            var skin = Skin.DefaultSkin;

            labelStyle        = new GUIStyle(skin.label);
            labelStyle.margin = new RectOffset(0, 0, 0, 0);

            stretchyLabelStyle              = new GUIStyle(skin.label);
            stretchyLabelStyle.margin       = new RectOffset(0, 0, 0, 0);
            stretchyLabelStyle.stretchWidth = true;

            fixedLabelStyle = new GUIStyle(skin.label);

            textFieldStyle        = new GUIStyle(skin.textField);
            textFieldStyle.margin = new RectOffset(0, 0, 0, 0);

            longTextFieldStyle        = new GUIStyle(skin.textField);
            longTextFieldStyle.margin = new RectOffset(0, 0, 0, 0);

            stretchyTextFieldStyle              = new GUIStyle(skin.textField);
            stretchyTextFieldStyle.margin       = new RectOffset(0, 0, 0, 0);
            stretchyTextFieldStyle.stretchWidth = true;

            buttonStyle        = new GUIStyle(skin.button);
            buttonStyle.margin = new RectOffset(0, 0, 0, 0);

            toggleStyle               = new GUIStyle(skin.toggle);
            toggleStyle.margin        = new RectOffset(0, 0, 0, 0);
            toggleStyle.stretchWidth  = false;
            toggleStyle.contentOffset = new Vector2(4, 0);

            separatorStyle              = GUILayoutExtensions.SeparatorStyle(new Color(0f, 0f, 0f, 0.25f));
            separatorStyle.fixedHeight  = 2;
            separatorStyle.stretchWidth = true;
            separatorStyle.margin       = new RectOffset(2, 2, 3, 3);

            lightStyle = GUILayoutExtensions.LightStyle();

            errorLabelStyle                  = new GUIStyle(skin.label);
            errorLabelStyle.margin           = new RectOffset(0, 0, 0, 0);
            errorLabelStyle.stretchWidth     = true;
            errorLabelStyle.normal.textColor = errorColor;

            comboOptionsStyle = GUILayoutExtensions.ComboOptionsStyle();
            comboOptionStyle  = GUILayoutExtensions.ComboOptionStyle();

            Errors           = new List <string> ();
            address          = Config.Address.ToString();
            rpcPort          = Config.RPCPort.ToString();
            streamPort       = Config.StreamPort.ToString();
            maxTimePerUpdate = Config.MaxTimePerUpdate.ToString();
            recvTimeout      = Config.RecvTimeout.ToString();

            // Get list of available addresses for drop down
            var interfaceAddresses = NetworkInformation.LocalIPAddresses.Select(x => x.ToString()).ToList();

            interfaceAddresses.Remove(IPAddress.Loopback.ToString());
            interfaceAddresses.Remove(IPAddress.Any.ToString());
            availableAddresses = new List <string> (new [] { localhostText, anyText });
            availableAddresses.AddRange(interfaceAddresses);
            availableAddresses.Add(manualText);
        }
示例#9
0
        protected override void Draw()
        {
            // Force window to resize to height of content
            if (resized)
            {
                Position = new Rect(Position.x, Position.y, Position.width, 0f);
                resized  = false;
            }

            GUILayout.BeginVertical();

            GUILayout.BeginHorizontal();
            DrawServerStatus();
            DrawStartStopButton();
            GUILayout.EndHorizontal();

            GUILayout.Space(4);

            GUILayout.BeginHorizontal();
            DrawAddress();
            if (Server.Running)
            {
                GUILayout.Space(4);
                DrawShowInfoWindow();
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            DrawRPCPort();
            GUILayout.Space(4);
            DrawStreamPort();
            GUILayout.EndHorizontal();

            if (Server.Running)
            {
                GUILayout.BeginHorizontal();
                DrawServerInfo();
                GUILayout.EndHorizontal();
                GUILayoutExtensions.Separator(separatorStyle);
                DrawClientsList();
            }
            else
            {
                GUILayout.BeginHorizontal();
                DrawAdvancedToggle();
                GUILayout.EndHorizontal();

                if (advanced)
                {
                    GUILayout.BeginHorizontal();
                    GUILayout.Space(indentWidth);
                    DrawAutoStartServerToggle();
                    GUILayout.EndHorizontal();

                    GUILayout.BeginHorizontal();
                    GUILayout.Space(indentWidth);
                    DrawAutoAcceptConnectionsToggle();
                    GUILayout.EndHorizontal();

                    GUILayout.BeginHorizontal();
                    GUILayout.Space(indentWidth);
                    DrawOneRPCPerUpdateToggle();
                    GUILayout.EndHorizontal();

                    GUILayout.BeginHorizontal();
                    GUILayout.Space(indentWidth);
                    DrawMaxTimePerUpdate();
                    GUILayout.EndHorizontal();

                    GUILayout.BeginHorizontal();
                    GUILayout.Space(indentWidth);
                    DrawAdaptiveRateControlToggle();
                    GUILayout.EndHorizontal();

                    GUILayout.BeginHorizontal();
                    GUILayout.Space(indentWidth);
                    DrawBlockingRecvToggle();
                    GUILayout.EndHorizontal();

                    GUILayout.BeginHorizontal();
                    GUILayout.Space(indentWidth);
                    DrawRecvTimeout();
                    GUILayout.EndHorizontal();
                }

                foreach (var error in Errors)
                {
                    GUILayout.Label(error, errorLabelStyle);
                }
            }
            GUILayout.EndVertical();
            GUI.DragWindow();
        }
示例#10
0
        protected override void Draw()
        {
            update = ((DateTime.Now - lastUpdate).TotalSeconds > updateTime);
            if (update)
            {
                lastUpdate = DateTime.Now;
            }

            // Force window to resize to height of content
            if (running != Server.Running)
            {
                running  = Server.Running;
                Position = new Rect(Position.x, Position.y, Position.width, 0f);
            }

            GUILayout.BeginVertical();

            if (Server.Running)
            {
                GUILayout.Label(networkInfoText, labelStyle);
                DrawInfo(bytesReadText, BytesToString(Server.BytesRead));
                DrawInfo(bytesWrittenText, BytesToString(Server.BytesWritten));
                DrawInfo(bytesReadRateText, BytesToString((ulong)Server.BytesReadRate) + "/s");
                DrawInfo(bytesWrittenRateText, BytesToString((ulong)Server.BytesWrittenRate) + "/s");

                GUILayoutExtensions.Separator(separatorStyle);

                GUILayout.Label(rpcInfoText, labelStyle);
                DrawInfo(rpcsExecutedText, Server.RPCsExecuted.ToString());
                DrawInfo(rpcRateText, Math.Round(Server.RPCRate) + " RPC/s");
                DrawInfo(rpcExecutionMode, Server.OneRPCPerUpdate ? singleRPCModeText : (Server.AdaptiveRateControl ? adaptiveModeText : staticModeText));
                DrawInfo(maxTimePerUpdateText, Server.OneRPCPerUpdate ? notApplicableText : Server.MaxTimePerUpdate + " ns");
                DrawInfo(rpcReceiveModeText, Server.BlockingRecv ? blockingModeText : nonBlockingModeText);
                DrawInfo(recvTimeoutText, Server.BlockingRecv ? Server.RecvTimeout + " ns" : notApplicableText);
                DrawInfo(timePerRPCUpdateText, String.Format("{0:F5} s", Server.TimePerRPCUpdate));
                DrawInfo(pollTimePerRPCUpdateText, String.Format("{0:F5} s", Server.PollTimePerRPCUpdate));
                DrawInfo(execTimePerRPCUpdateText, String.Format("{0:F5} s", Server.ExecTimePerRPCUpdate));

                GUILayoutExtensions.Separator(separatorStyle);

                GUILayout.Label(streamInfoText, labelStyle);
                DrawInfo(streamingRPCsText, Server.StreamRPCs.ToString());
                DrawInfo(streamingRPCsExecutedText, Server.StreamRPCsExecuted.ToString());
                DrawInfo(streamingRPCRateText, Math.Round(Server.StreamRPCRate) + " RPC/s");
                DrawInfo(timePerStreamUpdateText, String.Format("{0:F5} s", Server.TimePerStreamUpdate));

                GUILayoutExtensions.Separator(separatorStyle);

                GUILayout.BeginHorizontal();
                if (GUILayout.Button(clearStatisticsText, buttonStyle))
                {
                    Server.ClearStats();
                }
                GUILayout.EndHorizontal();
            }
            else
            {
                GUILayout.Label("Server not running");
            }
            GUILayout.EndVertical();
            GUI.DragWindow();
        }
示例#11
0
        protected override void Draw(bool needRescale)
        {
            if (needRescale)
            {
                int scaledFontSize = Style.fontSize;
                Style.fixedWidth           = windowWidth * GameSettings.UI_SCALE;
                labelStyle.fontSize        = scaledFontSize;
                nameLabelStyle.fontSize    = scaledFontSize;
                nameLabelStyle.fixedWidth  = 160f * GameSettings.UI_SCALE;
                valueLabelStyle.fontSize   = scaledFontSize;
                valueLabelStyle.fixedWidth = 120f * GameSettings.UI_SCALE;
                buttonStyle.fontSize       = scaledFontSize;

                // Force window to resize to height of content
                Position = new Rect(Position.x, Position.y, Position.width, 0f);
            }

            update = ((DateTime.Now - lastUpdate).TotalSeconds > updateTime);
            if (update)
            {
                lastUpdate = DateTime.Now;
            }
            var core = Core.Instance;

            GUILayout.BeginVertical();

            GUILayout.Label(networkInfoText, labelStyle);
            DrawInfo(bytesReadText, BytesToString(core.BytesRead));
            DrawInfo(bytesWrittenText, BytesToString(core.BytesWritten));
            DrawInfo(bytesReadRateText, BytesToString((ulong)core.BytesReadRate) + "/s");
            DrawInfo(bytesWrittenRateText, BytesToString((ulong)core.BytesWrittenRate) + "/s");

            GUILayoutExtensions.Separator(separatorStyle);

            GUILayout.Label(rpcInfoText, labelStyle);
            DrawInfo(rpcsExecutedText, core.RPCsExecuted.ToString());
            DrawInfo(rpcRateText, Math.Round(core.RPCRate) + " RPC/s");
            DrawInfo(rpcExecutionMode, core.OneRPCPerUpdate ? singleRPCModeText : (core.AdaptiveRateControl ? adaptiveModeText : staticModeText));
            DrawInfo(maxTimePerUpdateText, core.OneRPCPerUpdate ? notApplicableText : core.MaxTimePerUpdate + " ns");
            DrawInfo(rpcReceiveModeText, core.BlockingRecv ? blockingModeText : nonBlockingModeText);
            DrawInfo(recvTimeoutText, core.BlockingRecv ? core.RecvTimeout + " ns" : notApplicableText);
            DrawInfo(timePerRPCUpdateText, string.Format("{0:F5} s", core.TimePerRPCUpdate));
            DrawInfo(pollTimePerRPCUpdateText, string.Format("{0:F5} s", core.PollTimePerRPCUpdate));
            DrawInfo(execTimePerRPCUpdateText, string.Format("{0:F5} s", core.ExecTimePerRPCUpdate));

            GUILayoutExtensions.Separator(separatorStyle);

            GUILayout.Label(streamInfoText, labelStyle);
            DrawInfo(streamingRPCsText, core.StreamRPCs.ToString());
            DrawInfo(streamingRPCsExecutedText, core.StreamRPCsExecuted.ToString());
            DrawInfo(streamingRPCRateText, Math.Round(core.StreamRPCRate) + " RPC/s");
            DrawInfo(timePerStreamUpdateText, string.Format("{0:F5} s", core.TimePerStreamUpdate));

            GUILayoutExtensions.Separator(separatorStyle);

            GUILayout.BeginHorizontal();
            if (GUILayout.Button(clearStatisticsText, buttonStyle))
            {
                core.ClearStats();
            }
            GUILayout.EndHorizontal();

            GUILayout.EndVertical();
            GUI.DragWindow();
        }
示例#12
0
        public void Draw()
        {
            GUILayout.BeginHorizontal();
            GUILayout.Label(protocolLabelText, window.labelStyle);
            protocol = (Protocol)GUILayoutExtensions.ComboBox("protocol", (int)protocol, availableProtocols, window.buttonStyle, window.comboOptionsStyle, window.comboOptionStyle);
            GUILayout.EndHorizontal();

            if (protocol == Protocol.ProtocolBuffersOverTCP ||
                protocol == Protocol.ProtocolBuffersOverWebsockets)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label(addressLabelText, window.labelStyle);
                if (!settings.ContainsKey("address"))
                {
                    settings["address"] = IPAddress.Loopback.ToString();
                }
                var address = settings["address"];
                // Get the index of the address in the combo box
                int addressSelected;
                if (!manualAddress && address == IPAddress.Loopback.ToString())
                {
                    addressSelected = 0;
                }
                else if (!manualAddress && address == IPAddress.Any.ToString())
                {
                    addressSelected = 1;
                }
                else if (!manualAddress && availableAddresses.Contains(address))
                {
                    addressSelected = availableAddresses.IndexOf(address);
                }
                else
                {
                    addressSelected = availableAddresses.Count - 1;
                }
                // Display the combo box
                addressSelected = GUILayoutExtensions.ComboBox("address", addressSelected, availableAddresses, window.buttonStyle, window.comboOptionsStyle, window.comboOptionStyle);
                // Get the address from the combo box selection
                if (addressSelected == 0)
                {
                    address       = IPAddress.Loopback.ToString();
                    manualAddress = false;
                }
                else if (addressSelected == 1)
                {
                    address       = IPAddress.Any.ToString();
                    manualAddress = false;
                }
                else if (addressSelected < availableAddresses.Count - 1)
                {
                    address       = availableAddresses[addressSelected];
                    manualAddress = false;
                }
                else
                {
                    // Display a text field when "Manual" is selected
                    address       = GUILayout.TextField(address, addressMaxLength, window.stretchyTextFieldStyle);
                    manualAddress = true;
                }
                settings["address"] = address;
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label(rpcPortLabelText, window.labelStyle);
                if (!settings.ContainsKey("rpc_port"))
                {
                    settings["rpc_port"] = "50000";
                }
                settings["rpc_port"] = GUILayout.TextField(settings["rpc_port"], portMaxLength, window.longTextFieldStyle);
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label(streamPortLabelText, window.labelStyle);
                if (!settings.ContainsKey("stream_port"))
                {
                    settings["stream_port"] = "50000";
                }
                settings["stream_port"] = GUILayout.TextField(settings["stream_port"], portMaxLength, window.longTextFieldStyle);
                GUILayout.EndHorizontal();
            }
        }
示例#13
0
        public void Draw()
        {
            GUILayout.BeginHorizontal();
            GUILayout.Label(protocolLabelText, window.labelStyle);
            protocol = (Protocol)GUILayoutExtensions.ComboBox("protocol", (int)protocol, availableProtocols, window.buttonStyle, window.comboOptionsStyle, window.comboOptionStyle);
            GUILayout.EndHorizontal();

            if (protocol == Protocol.ProtocolBuffersOverTCP ||
                protocol == Protocol.ProtocolBuffersOverWebsockets)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label(addressLabelText, window.labelStyle);
                if (!settings.ContainsKey("address"))
                {
                    settings["address"] = IPAddress.Loopback.ToString();
                }
                var address = settings["address"];
                // Get the index of the address in the combo box
                int addressSelected;
                if (!manualAddress && address == IPAddress.Loopback.ToString())
                {
                    addressSelected = 0;
                }
                else if (!manualAddress && address == IPAddress.Any.ToString())
                {
                    addressSelected = 1;
                }
                else if (!manualAddress && availableAddresses.Contains(address))
                {
                    addressSelected = availableAddresses.IndexOf(address);
                }
                else
                {
                    addressSelected = availableAddresses.Count - 1;
                }
                // Display the combo box
                addressSelected = GUILayoutExtensions.ComboBox("address", addressSelected, availableAddresses, window.buttonStyle, window.comboOptionsStyle, window.comboOptionStyle);
                // Get the address from the combo box selection
                if (addressSelected == 0)
                {
                    address       = IPAddress.Loopback.ToString();
                    manualAddress = false;
                }
                else if (addressSelected == 1)
                {
                    address       = IPAddress.Any.ToString();
                    manualAddress = false;
                }
                else if (addressSelected < availableAddresses.Count - 1)
                {
                    address       = availableAddresses[addressSelected];
                    manualAddress = false;
                }
                else
                {
                    // Display a text field when "Manual" is selected
                    address       = GUILayout.TextField(address, addressMaxLength, window.stretchyTextFieldStyle);
                    manualAddress = true;
                }
                settings["address"] = address;
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label(rpcPortLabelText, window.labelStyle);
                if (!settings.ContainsKey("rpc_port"))
                {
                    settings["rpc_port"] = "50000";
                }
                settings["rpc_port"] = GUILayout.TextField(settings["rpc_port"], portMaxLength, window.longTextFieldStyle);
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label(streamPortLabelText, window.labelStyle);
                if (!settings.ContainsKey("stream_port"))
                {
                    settings["stream_port"] = "50000";
                }
                settings["stream_port"] = GUILayout.TextField(settings["stream_port"], portMaxLength, window.longTextFieldStyle);
                GUILayout.EndHorizontal();
            }
            else
            {
                if (!settings.ContainsKey("baud_rate"))
                {
                    settings["baud_rate"] = "9600";
                }
                if (!settings.ContainsKey("data_bits"))
                {
                    settings["data_bits"] = "8";
                }

                GUILayout.BeginHorizontal();
                GUILayout.Label(portLabelText, window.labelStyle);
                if (!settings.ContainsKey("port"))
                {
                    settings["port"] = new KRPC.IO.Ports.SerialPort().PortName;
                }
                settings["port"] = GUILayout.TextField(
                    settings["port"], portNameMaxLength, window.longTextFieldStyle);
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label(baudRateLabelText, window.labelStyle);
                if (!settings.ContainsKey("baud_rate"))
                {
                    settings["baud_rate"] = "9600";
                }
                settings["baud_rate"] = GUILayout.TextField(
                    settings["baud_rate"], baudRateMaxLength, window.longTextFieldStyle);
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label(dataBitsLabelText, window.labelStyle);
                if (!settings.ContainsKey("data_bits"))
                {
                    settings["data_bits"] = "8";
                }
                settings["data_bits"] = GUILayout.TextField(
                    settings["data_bits"], dataBitsMaxLength, window.longTextFieldStyle);
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label(parityLabelText, window.labelStyle);
                if (!settings.ContainsKey("parity"))
                {
                    settings["parity"] = "None";
                }
                settings["parity"] = parityOptions [GUILayoutExtensions.ComboBox(
                                                        "parity", parityOptions.IndexOf(settings["parity"]), parityOptions,
                                                        window.buttonStyle, window.comboOptionsStyle, window.comboOptionStyle)];
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label(stopBitsLabelText, window.labelStyle);
                if (!settings.ContainsKey("stop_bits"))
                {
                    settings["stop_bits"] = "One";
                }
                settings["stop_bits"] = stopBitsOptions [GUILayoutExtensions.ComboBox(
                                                             "stop_bits", stopBitsOptions.IndexOf(settings["stop_bits"]), stopBitsOptions,
                                                             window.buttonStyle, window.comboOptionsStyle, window.comboOptionStyle)];
                GUILayout.EndHorizontal();
            }
        }
示例#14
0
        protected override void Init()
        {
            core   = Core.Instance;
            config = ConfigurationFile.Instance;

            var version = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location);

            Title = "kRPC v" + version.FileMajorPart + "." + version.FileMinorPart + "." + version.FileBuildPart;

            core.OnClientActivity += (s, e) => SawClientActivity(e.Client);

            Style.fixedWidth = windowWidth;

            var skin = Skin.DefaultSkin;

            labelStyle        = new GUIStyle(skin.label);
            labelStyle.margin = new RectOffset(0, 0, 0, 0);

            stretchyLabelStyle              = new GUIStyle(skin.label);
            stretchyLabelStyle.margin       = new RectOffset(0, 0, 0, 0);
            stretchyLabelStyle.stretchWidth = true;

            fixedLabelStyle = new GUIStyle(skin.label);

            textFieldStyle        = new GUIStyle(skin.textField);
            textFieldStyle.margin = new RectOffset(0, 0, 0, 0);

            longTextFieldStyle        = new GUIStyle(skin.textField);
            longTextFieldStyle.margin = new RectOffset(0, 0, 0, 0);

            stretchyTextFieldStyle              = new GUIStyle(skin.textField);
            stretchyTextFieldStyle.margin       = new RectOffset(0, 0, 0, 0);
            stretchyTextFieldStyle.stretchWidth = true;

            buttonStyle        = new GUIStyle(skin.button);
            buttonStyle.margin = new RectOffset(0, 0, 0, 0);

            toggleStyle               = new GUIStyle(skin.toggle);
            toggleStyle.margin        = new RectOffset(0, 0, 0, 0);
            toggleStyle.stretchWidth  = false;
            toggleStyle.contentOffset = new Vector2(4, 0);

            expandStyle             = new GUIStyle(skin.button);
            expandStyle.margin      = new RectOffset(0, 0, 0, 0);
            expandStyle.padding     = new RectOffset(0, 0, 0, 0);
            expandStyle.fixedWidth  = 16;
            expandStyle.fixedHeight = 16;

            separatorStyle              = GUILayoutExtensions.SeparatorStyle(new Color(0f, 0f, 0f, 0.25f));
            separatorStyle.fixedHeight  = 2;
            separatorStyle.stretchWidth = true;
            separatorStyle.margin       = new RectOffset(2, 2, 3, 3);

            lightStyle = GUILayoutExtensions.LightStyle();

            errorLabelStyle                  = new GUIStyle(skin.label);
            errorLabelStyle.margin           = new RectOffset(0, 0, 0, 0);
            errorLabelStyle.stretchWidth     = true;
            errorLabelStyle.normal.textColor = errorColor;

            comboOptionsStyle = GUILayoutExtensions.ComboOptionsStyle();
            comboOptionStyle  = GUILayoutExtensions.ComboOptionStyle();

            Errors           = new List <string> ();
            maxTimePerUpdate = config.Configuration.MaxTimePerUpdate.ToString();
            recvTimeout      = config.Configuration.RecvTimeout.ToString();

            core.OnClientActivity += (s, e) => SawClientActivity(e.Client);
            if (core.Servers.Count == 1)
            {
                expandServers.Add(core.Servers [0].Id);
            }
        }
示例#15
0
        void DrawServer(Server.Server server, bool forceExpanded = false)
        {
            var running       = server.Running;
            var editingServer = editServers.ContainsKey(server.Id);
            var expanded      = forceExpanded || expandServers.Contains(server.Id);

            GUILayout.BeginHorizontal();
            if (!forceExpanded)
            {
                var icons = Icons.Instance;
                if (GUILayout.Button(new GUIContent(expanded ? icons.ButtonCollapse : icons.ButtonExpand, expanded ? "Collapse" : "Expand"),
                                     expandStyle, GUILayout.MaxWidth(20), GUILayout.MaxHeight(20)))
                {
                    if (expanded)
                    {
                        expandServers.Remove(server.Id);
                    }
                    else
                    {
                        expandServers.Add(server.Id);
                    }
                    expanded = !expanded;
                    Resized  = true;
                }
            }
            GUILayoutExtensions.Light(running, lightStyle);
            if (!editingServer)
            {
                GUILayout.Label(server.Name, labelStyle);
            }
            else
            {
                editServers [server.Id].DrawName();
            }
            GUILayout.EndHorizontal();

            if (editingServer)
            {
                editServers [server.Id].Draw();
            }
            else if (expanded)
            {
                string protocol;
                if (server.Protocol == Protocol.ProtocolBuffersOverTCP)
                {
                    protocol = protobufOverTcpText;
                }
                else if (server.Protocol == Protocol.ProtocolBuffersOverWebsockets)
                {
                    protocol = protobufOverWebSocketsText;
                }
                else
                {
                    protocol = protobufOverSerialIOText;
                }
                GUILayout.Label(protocolText + protocol, labelStyle);
                foreach (var line in server.Address.Split('\n'))
                {
                    GUILayout.Label(line, labelStyle);
                }
                GUILayout.Label(server.Info, labelStyle);
                DrawClients(server);
            }

            GUILayout.BeginHorizontal();
            GUI.enabled = !editingServer;
            if (GUILayout.Button(running ? stopServerText : startServerText, buttonStyle))
            {
                Errors.Clear();
                Resized = true;
                EventHandlerExtensions.Invoke(running ? OnStopServerPressed : OnStartServerPressed, this, new ServerEventArgs(server));
            }
            GUI.enabled = !running;
            if (GUILayout.Button(editingServer ? saveServerText : editServerText, buttonStyle))
            {
                if (editingServer)
                {
                    var newServer = editServers[server.Id].Save();
                    if (newServer != null)
                    {
                        editServers.Remove(server.Id);
                        config.Configuration.ReplaceServer(newServer);
                        config.Save();
                        core.Replace(newServer.Create());
                    }
                }
                else
                {
                    editServers[server.Id] = new EditServer(this, config.Configuration.GetServer(server.Id));
                }
                Resized = true;
            }
            GUI.enabled = !editingServer && !running;
            if (GUILayout.Button(removeServerText, buttonStyle))
            {
                config.Configuration.RemoveServer(server.Id);
                config.Save();
                core.Remove(server.Id);
                Resized = true;
            }
            GUI.enabled = true;
            GUILayout.EndHorizontal();
        }
示例#16
0
        protected override void Draw(bool needRescale)
        {
            if (needRescale)
            {
                int scaledFontSize = Style.fontSize;
                scaledIndentWidth = indentWidth * GameSettings.UI_SCALE;
                Style.fixedWidth  = windowWidth * GameSettings.UI_SCALE;

                labelStyle.fontSize             = scaledFontSize;
                stretchyLabelStyle.fontSize     = scaledFontSize;
                fixedLabelStyle.fontSize        = scaledFontSize;
                fixedLabelStyle.fixedWidth      = fixedLabelWidth * GameSettings.UI_SCALE;
                textFieldStyle.fontSize         = scaledFontSize;
                textFieldStyle.fixedWidth       = textFieldWidth * GameSettings.UI_SCALE;
                longTextFieldStyle.fontSize     = scaledFontSize;
                longTextFieldStyle.fixedWidth   = longTextFieldWidth * GameSettings.UI_SCALE;
                stretchyTextFieldStyle.fontSize = scaledFontSize;
                buttonStyle.fontSize            = scaledFontSize;
                toggleStyle.fontSize            = scaledFontSize;
                separatorStyle.fontSize         = scaledFontSize;
                lightStyle.fontSize             = scaledFontSize;
                errorLabelStyle.fontSize        = scaledFontSize;
                comboOptionsStyle.fontSize      = scaledFontSize;
                comboOptionStyle.fontSize       = scaledFontSize;
                GUILayoutExtensions.SetLightStyleSize(lightStyle, Style.lineHeight);
                Resized = true;
            }

            // Force window to resize to height of content
            if (Resized)
            {
                Position = new Rect(Position.x, Position.y, Position.width, 0f);
                Resized  = false;
            }

            GUILayout.BeginVertical();

            DrawStartServer();
            GUILayoutExtensions.Separator(separatorStyle);

            var servers = core.Servers.ToList();

            foreach (var server in servers)
            {
                DrawServer(server, servers.Count == 1);
                GUILayoutExtensions.Separator(separatorStyle);
            }

            DrawAddServer();
            GUILayoutExtensions.Separator(separatorStyle);

            if (Errors.Any())
            {
                foreach (var error in Errors)
                {
                    GUILayout.Label(error, errorLabelStyle);
                }
                GUILayoutExtensions.Separator(separatorStyle);
            }

            DrawAdvancedServerOptions();
            DrawShowInfoWindow();
            GUILayout.EndVertical();

            GUI.DragWindow();
        }